3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $searchtext = $cgi->param('s');
478 if (defined $searchtext) {
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
605 hash_parent_base
=> "hpb",
610 snapshot_format
=> "sf",
611 extra_options
=> "opt",
613 my %mapping = @mapping;
615 if ($params{-replay
}) {
616 while (my ($name, $symbol) = each %mapping) {
617 if (!exists $params{$name}) {
618 # to allow for multivalued params we use arrayref form
619 $params{$name} = [ $cgi->param($symbol) ];
624 $params{'project'} = $project unless exists $params{'project'};
626 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
628 # use PATH_INFO for project name
629 $href .= "/$params{'project'}" if defined $params{'project'};
630 delete $params{'project'};
632 # Summary just uses the project path URL
633 if (defined $params{'action'} && $params{'action'} eq 'summary') {
634 delete $params{'action'};
638 # now encode the parameters explicitly
640 for (my $i = 0; $i < @mapping; $i += 2) {
641 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
642 if (defined $params{$name}) {
643 if (ref($params{$name}) eq "ARRAY") {
644 foreach my $par (@{$params{$name}}) {
645 push @result, $symbol . "=" . esc_param
($par);
648 push @result, $symbol . "=" . esc_param
($params{$name});
652 $href .= "?" . join(';', @result) if scalar @result;
658 ## ======================================================================
659 ## validation, quoting/unquoting and escaping
661 sub validate_pathname
{
662 my $input = shift || return undef;
664 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
665 # at the beginning, at the end, and between slashes.
666 # also this catches doubled slashes
667 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
671 if ($input =~ m!\0!) {
677 sub validate_refname
{
678 my $input = shift || return undef;
680 # textual hashes are O.K.
681 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
684 # it must be correct pathname
685 $input = validate_pathname
($input)
687 # restrictions on ref name according to git-check-ref-format
688 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
694 # decode sequences of octets in utf8 into Perl's internal form,
695 # which is utf-8 with utf8 flag set if needed. gitweb writes out
696 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
700 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
704 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
708 # quote unsafe chars, but keep the slash, even when it's not
709 # correct, but quoted slashes look too horrible in bookmarks
712 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
718 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
721 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
727 # replace invalid utf8 character with SUBSTITUTION sequence
732 $str = to_utf8
($str);
733 $str = $cgi->escapeHTML($str);
734 if ($opts{'-nbsp'}) {
735 $str =~ s/ / /g;
737 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
741 # quote control characters and escape filename to HTML
746 $str = to_utf8
($str);
747 $str = $cgi->escapeHTML($str);
748 if ($opts{'-nbsp'}) {
749 $str =~ s/ / /g;
751 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
755 # Make control characters "printable", using character escape codes (CEC)
758 my %es = ( # character escape codes, aka escape sequences
759 "\t" => '\t', # tab (HT)
760 "\n" => '\n', # line feed (LF)
761 "\r" => '\r', # carrige return (CR)
762 "\f" => '\f', # form feed (FF)
763 "\b" => '\b', # backspace (BS)
764 "\a" => '\a', # alarm (bell) (BEL)
765 "\e" => '\e', # escape (ESC)
766 "\013" => '\v', # vertical tab (VT)
767 "\000" => '\0', # nul character (NUL)
769 my $chr = ( (exists $es{$cntrl})
771 : sprintf('\%03o', ord($cntrl)) );
772 return "<span class=\"cntrl\">$chr</span>";
775 # Alternatively use unicode control pictures codepoints,
776 # Unicode "printable representation" (PR)
779 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
780 return "<span class=\"cntrl\">$chr</span>";
783 # git may return quoted and escaped filenames
789 my %es = ( # character escape codes, aka escape sequences
790 't' => "\t", # tab (HT, TAB)
791 'n' => "\n", # newline (NL)
792 'r' => "\r", # return (CR)
793 'f' => "\f", # form feed (FF)
794 'b' => "\b", # backspace (BS)
795 'a' => "\a", # alarm (bell) (BEL)
796 'e' => "\e", # escape (ESC)
797 'v' => "\013", # vertical tab (VT)
800 if ($seq =~ m/^[0-7]{1,3}$/) {
801 # octal char sequence
802 return chr(oct($seq));
803 } elsif (exists $es{$seq}) {
804 # C escape sequence, aka character escape code
807 # quoted ordinary character
811 if ($str =~ m/^"(.*)"$/) {
814 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
819 # escape tabs (convert tabs to spaces)
823 while ((my $pos = index($line, "\t")) != -1) {
824 if (my $count = (8 - ($pos % 8))) {
825 my $spaces = ' ' x
$count;
826 $line =~ s/\t/$spaces/;
833 sub project_in_list
{
835 my @list = git_get_projects_list
();
836 return @list && scalar(grep { $_->{'path'} eq $project } @list);
839 ## ----------------------------------------------------------------------
840 ## HTML aware string manipulation
845 my $add_len = shift || 10;
847 # allow only $len chars, but don't cut a word if it would fit in $add_len
848 # if it doesn't fit, cut it if it's still longer than the dots we would add
849 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
852 if (length($tail) > 4) {
854 $body =~ s/&[^;]*$//; # remove chopped character entities
859 # takes the same arguments as chop_str, but also wraps a <span> around the
860 # result with a title attribute if it does get chopped. Additionally, the
861 # string is HTML-escaped.
862 sub chop_and_escape_str
{
865 my $add_len = shift || 10;
867 my $chopped = chop_str
($str, $len, $add_len);
868 if ($chopped eq $str) {
869 return esc_html
($chopped);
871 return qq{<span title="} . esc_html
($str) . qq{">} .
872 esc_html
($chopped) . qq{</span>};
876 ## ----------------------------------------------------------------------
877 ## functions returning short strings
879 # CSS class for given age value (in seconds)
885 } elsif ($age < 60*60*2) {
887 } elsif ($age < 60*60*24*2) {
894 # convert age in seconds to "nn units ago" string
899 if ($age > 60*60*24*365*2) {
900 $age_str = (int $age/60/60/24/365);
901 $age_str .= " years ago";
902 } elsif ($age > 60*60*24*(365/12)*2) {
903 $age_str = int $age/60/60/24/(365/12);
904 $age_str .= " months ago";
905 } elsif ($age > 60*60*24*7*2) {
906 $age_str = int $age/60/60/24/7;
907 $age_str .= " weeks ago";
908 } elsif ($age > 60*60*24*2) {
909 $age_str = int $age/60/60/24;
910 $age_str .= " days ago";
911 } elsif ($age > 60*60*2) {
912 $age_str = int $age/60/60;
913 $age_str .= " hours ago";
914 } elsif ($age > 60*2) {
915 $age_str = int $age/60;
916 $age_str .= " min ago";
919 $age_str .= " sec ago";
921 $age_str .= " right now";
927 S_IFINVALID
=> 0030000,
928 S_IFGITLINK
=> 0160000,
931 # submodule/subproject, a commit object reference
935 return (($mode & S_IFMT
) == S_IFGITLINK
)
938 # convert file mode in octal to symbolic file mode string
940 my $mode = oct shift;
942 if (S_ISGITLINK
($mode)) {
944 } elsif (S_ISDIR
($mode & S_IFMT
)) {
946 } elsif (S_ISLNK
($mode)) {
948 } elsif (S_ISREG
($mode)) {
949 # git cares only about the executable bit
950 if ($mode & S_IXUSR
) {
960 # convert file mode in octal to file type string
964 if ($mode !~ m/^[0-7]+$/) {
970 if (S_ISGITLINK
($mode)) {
972 } elsif (S_ISDIR
($mode & S_IFMT
)) {
974 } elsif (S_ISLNK
($mode)) {
976 } elsif (S_ISREG
($mode)) {
983 # convert file mode in octal to file type description string
987 if ($mode !~ m/^[0-7]+$/) {
993 if (S_ISGITLINK
($mode)) {
995 } elsif (S_ISDIR
($mode & S_IFMT
)) {
997 } elsif (S_ISLNK
($mode)) {
999 } elsif (S_ISREG
($mode)) {
1000 if ($mode & S_IXUSR
) {
1001 return "executable";
1011 ## ----------------------------------------------------------------------
1012 ## functions returning short HTML fragments, or transforming HTML fragments
1013 ## which don't belong to other sections
1015 # format line of commit message.
1016 sub format_log_line_html
{
1019 $line = esc_html
($line, -nbsp
=>1);
1020 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1023 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1024 -class => "text"}, $hash_text);
1025 $line =~ s/$hash_text/$link/;
1030 # format marker of refs pointing to given object
1031 sub format_ref_marker
{
1032 my ($refs, $id) = @_;
1035 if (defined $refs->{$id}) {
1036 foreach my $ref (@{$refs->{$id}}) {
1037 my ($type, $name) = qw();
1038 # e.g. tags/v2.6.11 or heads/next
1039 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1047 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1048 esc_html
($name) . "</span>";
1053 return ' <span class="refs">'. $markers . '</span>';
1059 # format, perhaps shortened and with markers, title line
1060 sub format_subject_html
{
1061 my ($long, $short, $href, $extra) = @_;
1062 $extra = '' unless defined($extra);
1064 if (length($short) < length($long)) {
1065 return $cgi->a({-href
=> $href, -class => "list subject",
1066 -title
=> to_utf8
($long)},
1067 esc_html
($short) . $extra);
1069 return $cgi->a({-href
=> $href, -class => "list subject"},
1070 esc_html
($long) . $extra);
1074 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1075 sub format_git_diff_header_line
{
1077 my $diffinfo = shift;
1078 my ($from, $to) = @_;
1080 if ($diffinfo->{'nparents'}) {
1082 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1083 if ($to->{'href'}) {
1084 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1085 esc_path
($to->{'file'}));
1086 } else { # file was deleted (no href)
1087 $line .= esc_path
($to->{'file'});
1091 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1092 if ($from->{'href'}) {
1093 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1094 'a/' . esc_path
($from->{'file'}));
1095 } else { # file was added (no href)
1096 $line .= 'a/' . esc_path
($from->{'file'});
1099 if ($to->{'href'}) {
1100 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1101 'b/' . esc_path
($to->{'file'}));
1102 } else { # file was deleted
1103 $line .= 'b/' . esc_path
($to->{'file'});
1107 return "<div class=\"diff header\">$line</div>\n";
1110 # format extended diff header line, before patch itself
1111 sub format_extended_diff_header_line
{
1113 my $diffinfo = shift;
1114 my ($from, $to) = @_;
1117 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1118 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1119 esc_path
($from->{'file'}));
1121 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1122 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1123 esc_path
($to->{'file'}));
1125 # match single <mode>
1126 if ($line =~ m/\s(\d{6})$/) {
1127 $line .= '<span class="info"> (' .
1128 file_type_long
($1) .
1132 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1133 # can match only for combined diff
1135 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1136 if ($from->{'href'}[$i]) {
1137 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1139 substr($diffinfo->{'from_id'}[$i],0,7));
1144 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1147 if ($to->{'href'}) {
1148 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1149 substr($diffinfo->{'to_id'},0,7));
1154 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1155 # can match only for ordinary diff
1156 my ($from_link, $to_link);
1157 if ($from->{'href'}) {
1158 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1159 substr($diffinfo->{'from_id'},0,7));
1161 $from_link = '0' x
7;
1163 if ($to->{'href'}) {
1164 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1165 substr($diffinfo->{'to_id'},0,7));
1169 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1170 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1173 return $line . "<br/>\n";
1176 # format from-file/to-file diff header
1177 sub format_diff_from_to_header
{
1178 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1183 #assert($line =~ m/^---/) if DEBUG;
1184 # no extra formatting for "^--- /dev/null"
1185 if (! $diffinfo->{'nparents'}) {
1186 # ordinary (single parent) diff
1187 if ($line =~ m!^--- "?a/!) {
1188 if ($from->{'href'}) {
1190 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1191 esc_path
($from->{'file'}));
1194 esc_path
($from->{'file'});
1197 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1200 # combined diff (merge commit)
1201 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1202 if ($from->{'href'}[$i]) {
1204 $cgi->a({-href
=>href
(action
=>"blobdiff",
1205 hash_parent
=>$diffinfo->{'from_id'}[$i],
1206 hash_parent_base
=>$parents[$i],
1207 file_parent
=>$from->{'file'}[$i],
1208 hash
=>$diffinfo->{'to_id'},
1210 file_name
=>$to->{'file'}),
1212 -title
=>"diff" . ($i+1)},
1215 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1216 esc_path
($from->{'file'}[$i]));
1218 $line = '--- /dev/null';
1220 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1225 #assert($line =~ m/^\+\+\+/) if DEBUG;
1226 # no extra formatting for "^+++ /dev/null"
1227 if ($line =~ m!^\+\+\+ "?b/!) {
1228 if ($to->{'href'}) {
1230 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1231 esc_path
($to->{'file'}));
1234 esc_path
($to->{'file'});
1237 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1242 # create note for patch simplified by combined diff
1243 sub format_diff_cc_simplified
{
1244 my ($diffinfo, @parents) = @_;
1247 $result .= "<div class=\"diff header\">" .
1249 if (!is_deleted
($diffinfo)) {
1250 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1252 hash
=>$diffinfo->{'to_id'},
1253 file_name
=>$diffinfo->{'to_file'}),
1255 esc_path
($diffinfo->{'to_file'}));
1257 $result .= esc_path
($diffinfo->{'to_file'});
1259 $result .= "</div>\n" . # class="diff header"
1260 "<div class=\"diff nodifferences\">" .
1262 "</div>\n"; # class="diff nodifferences"
1267 # format patch (diff) line (not to be used for diff headers)
1268 sub format_diff_line
{
1270 my ($from, $to) = @_;
1271 my $diff_class = "";
1275 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1277 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1278 if ($line =~ m/^\@{3}/) {
1279 $diff_class = " chunk_header";
1280 } elsif ($line =~ m/^\\/) {
1281 $diff_class = " incomplete";
1282 } elsif ($prefix =~ tr/+/+/) {
1283 $diff_class = " add";
1284 } elsif ($prefix =~ tr/-/-/) {
1285 $diff_class = " rem";
1288 # assume ordinary diff
1289 my $char = substr($line, 0, 1);
1291 $diff_class = " add";
1292 } elsif ($char eq '-') {
1293 $diff_class = " rem";
1294 } elsif ($char eq '@') {
1295 $diff_class = " chunk_header";
1296 } elsif ($char eq "\\") {
1297 $diff_class = " incomplete";
1300 $line = untabify
($line);
1301 if ($from && $to && $line =~ m/^\@{2} /) {
1302 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1303 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1305 $from_lines = 0 unless defined $from_lines;
1306 $to_lines = 0 unless defined $to_lines;
1308 if ($from->{'href'}) {
1309 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1310 -class=>"list"}, $from_text);
1312 if ($to->{'href'}) {
1313 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1314 -class=>"list"}, $to_text);
1316 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1317 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1318 return "<div class=\"diff$diff_class\">$line</div>\n";
1319 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1320 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1321 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1323 @from_text = split(' ', $ranges);
1324 for (my $i = 0; $i < @from_text; ++$i) {
1325 ($from_start[$i], $from_nlines[$i]) =
1326 (split(',', substr($from_text[$i], 1)), 0);
1329 $to_text = pop @from_text;
1330 $to_start = pop @from_start;
1331 $to_nlines = pop @from_nlines;
1333 $line = "<span class=\"chunk_info\">$prefix ";
1334 for (my $i = 0; $i < @from_text; ++$i) {
1335 if ($from->{'href'}[$i]) {
1336 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1337 -class=>"list"}, $from_text[$i]);
1339 $line .= $from_text[$i];
1343 if ($to->{'href'}) {
1344 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1345 -class=>"list"}, $to_text);
1349 $line .= " $prefix</span>" .
1350 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1351 return "<div class=\"diff$diff_class\">$line</div>\n";
1353 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1356 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1357 # linked. Pass the hash of the tree/commit to snapshot.
1358 sub format_snapshot_links
{
1360 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1361 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1362 my $num_fmts = @snapshot_fmts;
1363 if ($num_fmts > 1) {
1364 # A parenthesized list of links bearing format names.
1365 # e.g. "snapshot (_tar.gz_ _zip_)"
1366 return "snapshot (" . join(' ', map
1373 }, $known_snapshot_formats{$_}{'display'})
1374 , @snapshot_fmts) . ")";
1375 } elsif ($num_fmts == 1) {
1376 # A single "snapshot" link whose tooltip bears the format name.
1378 my ($fmt) = @snapshot_fmts;
1384 snapshot_format
=>$fmt
1386 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1388 } else { # $num_fmts == 0
1393 ## ----------------------------------------------------------------------
1394 ## git utility subroutines, invoking git commands
1396 # returns path to the core git executable and the --git-dir parameter as list
1398 return $GIT, '--git-dir='.$git_dir;
1401 # returns path to the core git executable and the --git-dir parameter as string
1403 return join(' ', git_cmd
());
1406 # get HEAD ref of given project as hash
1407 sub git_get_head_hash
{
1408 my $project = shift;
1409 my $o_git_dir = $git_dir;
1411 $git_dir = "$projectroot/$project";
1412 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1415 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1419 if (defined $o_git_dir) {
1420 $git_dir = $o_git_dir;
1425 # get type of given object
1429 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1431 close $fd or return;
1436 sub git_get_project_config
{
1437 my ($key, $type) = @_;
1439 return unless ($key);
1440 $key =~ s/^gitweb\.//;
1441 return if ($key =~ m/\W/);
1443 my @x = (git_cmd
(), 'config');
1444 if (defined $type) { push @x, $type; }
1446 push @x, "gitweb.$key";
1452 # get hash of given path at given ref
1453 sub git_get_hash_by_path
{
1455 my $path = shift || return undef;
1460 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1461 or die_error
(undef, "Open git-ls-tree failed");
1463 close $fd or return undef;
1465 if (!defined $line) {
1466 # there is no tree or hash given by $path at $base
1470 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1471 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1472 if (defined $type && $type ne $2) {
1473 # type doesn't match
1479 # get path of entry with given hash at given tree-ish (ref)
1480 # used to get 'from' filename for combined diff (merge commit) for renames
1481 sub git_get_path_by_hash
{
1482 my $base = shift || return;
1483 my $hash = shift || return;
1487 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1489 while (my $line = <$fd>) {
1492 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1493 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1494 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1503 ## ......................................................................
1504 ## git utility functions, directly accessing git repository
1506 sub git_get_project_description
{
1509 open my $fd, "$projectroot/$path/description" or return undef;
1512 if (defined $descr) {
1518 sub git_get_project_url_list
{
1521 open my $fd, "$projectroot/$path/cloneurl" or return;
1522 my @git_project_url_list = map { chomp; $_ } <$fd>;
1525 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1528 sub git_get_projects_list
{
1533 $filter =~ s/\.git$//;
1535 my ($check_forks) = gitweb_check_feature
('forks');
1537 if (-d
$projects_list) {
1538 # search in directory
1539 my $dir = $projects_list . ($filter ? "/$filter" : '');
1540 # remove the trailing "/"
1542 my $pfxlen = length("$dir");
1543 my $pfxdepth = ($dir =~ tr!/!!);
1546 follow_fast
=> 1, # follow symbolic links
1547 follow_skip
=> 2, # ignore duplicates
1548 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1550 # skip project-list toplevel, if we get it.
1551 return if (m!^[/.]$!);
1552 # only directories can be git repositories
1553 return unless (-d
$_);
1554 # don't traverse too deep (Find is super slow on os x)
1555 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1556 $File::Find
::prune
= 1;
1560 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1561 # we check related file in $projectroot
1562 if ($check_forks and $subdir =~ m
#/.#) {
1563 $File::Find
::prune
= 1;
1564 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1565 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1566 $File::Find
::prune
= 1;
1571 } elsif (-f
$projects_list) {
1572 # read from file(url-encoded):
1573 # 'git%2Fgit.git Linus+Torvalds'
1574 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1575 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1577 open my ($fd), $projects_list or return;
1579 while (my $line = <$fd>) {
1581 my ($path, $owner) = split ' ', $line;
1582 $path = unescape
($path);
1583 $owner = unescape
($owner);
1584 if (!defined $path) {
1587 if ($filter ne '') {
1588 # looking for forks;
1589 my $pfx = substr($path, 0, length($filter));
1590 if ($pfx ne $filter) {
1593 my $sfx = substr($path, length($filter));
1594 if ($sfx !~ /^\/.*\
.git
$/) {
1597 } elsif ($check_forks) {
1599 foreach my $filter (keys %paths) {
1600 # looking for forks;
1601 my $pfx = substr($path, 0, length($filter));
1602 if ($pfx ne $filter) {
1605 my $sfx = substr($path, length($filter));
1606 if ($sfx !~ /^\/.*\
.git
$/) {
1609 # is a fork, don't include it in
1614 if (check_export_ok
("$projectroot/$path")) {
1617 owner
=> to_utf8
($owner),
1620 (my $forks_path = $path) =~ s/\.git$//;
1621 $paths{$forks_path}++;
1629 our $gitweb_project_owner = undef;
1630 sub git_get_project_list_from_file
{
1632 return if (defined $gitweb_project_owner);
1634 $gitweb_project_owner = {};
1635 # read from file (url-encoded):
1636 # 'git%2Fgit.git Linus+Torvalds'
1637 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1638 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1639 if (-f
$projects_list) {
1640 open (my $fd , $projects_list);
1641 while (my $line = <$fd>) {
1643 my ($pr, $ow) = split ' ', $line;
1644 $pr = unescape
($pr);
1645 $ow = unescape
($ow);
1646 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1652 sub git_get_project_owner
{
1653 my $project = shift;
1656 return undef unless $project;
1658 if (!defined $gitweb_project_owner) {
1659 git_get_project_list_from_file
();
1662 if (exists $gitweb_project_owner->{$project}) {
1663 $owner = $gitweb_project_owner->{$project};
1665 if (!defined $owner) {
1666 $owner = get_file_owner
("$projectroot/$project");
1672 sub git_get_last_activity
{
1676 $git_dir = "$projectroot/$path";
1677 open($fd, "-|", git_cmd
(), 'for-each-ref',
1678 '--format=%(committer)',
1679 '--sort=-committerdate',
1681 'refs/heads') or return;
1682 my $most_recent = <$fd>;
1683 close $fd or return;
1684 if (defined $most_recent &&
1685 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1687 my $age = time - $timestamp;
1688 return ($age, age_string
($age));
1690 return (undef, undef);
1693 sub git_get_references
{
1694 my $type = shift || "";
1696 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1697 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1698 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1699 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1702 while (my $line = <$fd>) {
1704 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1705 if (defined $refs{$1}) {
1706 push @{$refs{$1}}, $2;
1712 close $fd or return;
1716 sub git_get_rev_name_tags
{
1717 my $hash = shift || return undef;
1719 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1721 my $name_rev = <$fd>;
1724 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1727 # catches also '$hash undefined' output
1732 ## ----------------------------------------------------------------------
1733 ## parse to hash functions
1737 my $tz = shift || "-0000";
1740 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1741 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1742 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1743 $date{'hour'} = $hour;
1744 $date{'minute'} = $min;
1745 $date{'mday'} = $mday;
1746 $date{'day'} = $days[$wday];
1747 $date{'month'} = $months[$mon];
1748 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1749 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1750 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1751 $mday, $months[$mon], $hour ,$min;
1752 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1753 1900+$year, $mon, $mday, $hour ,$min, $sec;
1755 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1756 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1757 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1758 $date{'hour_local'} = $hour;
1759 $date{'minute_local'} = $min;
1760 $date{'tz_local'} = $tz;
1761 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1762 1900+$year, $mon+1, $mday,
1763 $hour, $min, $sec, $tz);
1772 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1773 $tag{'id'} = $tag_id;
1774 while (my $line = <$fd>) {
1776 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1777 $tag{'object'} = $1;
1778 } elsif ($line =~ m/^type (.+)$/) {
1780 } elsif ($line =~ m/^tag (.+)$/) {
1782 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1783 $tag{'author'} = $1;
1786 } elsif ($line =~ m/--BEGIN/) {
1787 push @comment, $line;
1789 } elsif ($line eq "") {
1793 push @comment, <$fd>;
1794 $tag{'comment'} = \
@comment;
1795 close $fd or return;
1796 if (!defined $tag{'name'}) {
1802 sub parse_commit_text
{
1803 my ($commit_text, $withparents) = @_;
1804 my @commit_lines = split '\n', $commit_text;
1807 pop @commit_lines; # Remove '\0'
1809 if (! @commit_lines) {
1813 my $header = shift @commit_lines;
1814 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1817 ($co{'id'}, my @parents) = split ' ', $header;
1818 while (my $line = shift @commit_lines) {
1819 last if $line eq "\n";
1820 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1822 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1824 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1826 $co{'author_epoch'} = $2;
1827 $co{'author_tz'} = $3;
1828 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1829 $co{'author_name'} = $1;
1830 $co{'author_email'} = $2;
1832 $co{'author_name'} = $co{'author'};
1834 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1835 $co{'committer'} = $1;
1836 $co{'committer_epoch'} = $2;
1837 $co{'committer_tz'} = $3;
1838 $co{'committer_name'} = $co{'committer'};
1839 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1840 $co{'committer_name'} = $1;
1841 $co{'committer_email'} = $2;
1843 $co{'committer_name'} = $co{'committer'};
1847 if (!defined $co{'tree'}) {
1850 $co{'parents'} = \
@parents;
1851 $co{'parent'} = $parents[0];
1853 foreach my $title (@commit_lines) {
1856 $co{'title'} = chop_str
($title, 80, 5);
1857 # remove leading stuff of merges to make the interesting part visible
1858 if (length($title) > 50) {
1859 $title =~ s/^Automatic //;
1860 $title =~ s/^merge (of|with) /Merge ... /i;
1861 if (length($title) > 50) {
1862 $title =~ s/(http|rsync):\/\///;
1864 if (length($title) > 50) {
1865 $title =~ s/(master|www|rsync)\.//;
1867 if (length($title) > 50) {
1868 $title =~ s/kernel.org:?//;
1870 if (length($title) > 50) {
1871 $title =~ s/\/pub\/scm//;
1874 $co{'title_short'} = chop_str
($title, 50, 5);
1878 if ($co{'title'} eq "") {
1879 $co{'title'} = $co{'title_short'} = '(no commit message)';
1881 # remove added spaces
1882 foreach my $line (@commit_lines) {
1885 $co{'comment'} = \
@commit_lines;
1887 my $age = time - $co{'committer_epoch'};
1889 $co{'age_string'} = age_string
($age);
1890 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1891 if ($age > 60*60*24*7*2) {
1892 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1893 $co{'age_string_age'} = $co{'age_string'};
1895 $co{'age_string_date'} = $co{'age_string'};
1896 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1902 my ($commit_id) = @_;
1907 open my $fd, "-|", git_cmd
(), "rev-list",
1913 or die_error
(undef, "Open git-rev-list failed");
1914 %co = parse_commit_text
(<$fd>, 1);
1921 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1929 open my $fd, "-|", git_cmd
(), "rev-list",
1931 ($arg ? ($arg) : ()),
1932 ("--max-count=" . $maxcount),
1933 ("--skip=" . $skip),
1937 ($filename ? ($filename) : ())
1938 or die_error
(undef, "Open git-rev-list failed");
1939 while (my $line = <$fd>) {
1940 my %co = parse_commit_text
($line);
1945 return wantarray ? @cos : \
@cos;
1948 # parse ref from ref_file, given by ref_id, with given type
1950 my $ref_file = shift;
1952 my $type = shift || git_get_type
($ref_id);
1955 $ref_item{'type'} = $type;
1956 $ref_item{'id'} = $ref_id;
1957 $ref_item{'epoch'} = 0;
1958 $ref_item{'age'} = "unknown";
1959 if ($type eq "tag") {
1960 my %tag = parse_tag
($ref_id);
1961 $ref_item{'comment'} = $tag{'comment'};
1962 if ($tag{'type'} eq "commit") {
1963 my %co = parse_commit
($tag{'object'});
1964 $ref_item{'epoch'} = $co{'committer_epoch'};
1965 $ref_item{'age'} = $co{'age_string'};
1966 } elsif (defined($tag{'epoch'})) {
1967 my $age = time - $tag{'epoch'};
1968 $ref_item{'epoch'} = $tag{'epoch'};
1969 $ref_item{'age'} = age_string
($age);
1971 $ref_item{'reftype'} = $tag{'type'};
1972 $ref_item{'name'} = $tag{'name'};
1973 $ref_item{'refid'} = $tag{'object'};
1974 } elsif ($type eq "commit"){
1975 my %co = parse_commit
($ref_id);
1976 $ref_item{'reftype'} = "commit";
1977 $ref_item{'name'} = $ref_file;
1978 $ref_item{'title'} = $co{'title'};
1979 $ref_item{'refid'} = $ref_id;
1980 $ref_item{'epoch'} = $co{'committer_epoch'};
1981 $ref_item{'age'} = $co{'age_string'};
1983 $ref_item{'reftype'} = $type;
1984 $ref_item{'name'} = $ref_file;
1985 $ref_item{'refid'} = $ref_id;
1991 # parse line of git-diff-tree "raw" output
1992 sub parse_difftree_raw_line
{
1996 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1997 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1998 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1999 $res{'from_mode'} = $1;
2000 $res{'to_mode'} = $2;
2001 $res{'from_id'} = $3;
2003 $res{'status'} = $res{'status_str'} = $5;
2004 $res{'similarity'} = $6;
2005 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2006 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2008 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2011 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2012 # combined diff (for merge commit)
2013 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2014 $res{'nparents'} = length($1);
2015 $res{'from_mode'} = [ split(' ', $2) ];
2016 $res{'to_mode'} = pop @{$res{'from_mode'}};
2017 $res{'from_id'} = [ split(' ', $3) ];
2018 $res{'to_id'} = pop @{$res{'from_id'}};
2019 $res{'status_str'} = $4;
2020 $res{'status'} = [ split('', $4) ];
2021 $res{'to_file'} = unquote
($5);
2023 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2024 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2025 $res{'commit'} = $1;
2028 return wantarray ? %res : \
%res;
2031 # wrapper: return parsed line of git-diff-tree "raw" output
2032 # (the argument might be raw line, or parsed info)
2033 sub parsed_difftree_line
{
2034 my $line_or_ref = shift;
2036 if (ref($line_or_ref) eq "HASH") {
2037 # pre-parsed (or generated by hand)
2038 return $line_or_ref;
2040 return parse_difftree_raw_line
($line_or_ref);
2044 # parse line of git-ls-tree output
2045 sub parse_ls_tree_line
($;%) {
2050 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2051 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2059 $res{'name'} = unquote
($4);
2062 return wantarray ? %res : \
%res;
2065 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2066 sub parse_from_to_diffinfo
{
2067 my ($diffinfo, $from, $to, @parents) = @_;
2069 if ($diffinfo->{'nparents'}) {
2071 $from->{'file'} = [];
2072 $from->{'href'} = [];
2073 fill_from_file_info
($diffinfo, @parents)
2074 unless exists $diffinfo->{'from_file'};
2075 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2076 $from->{'file'}[$i] =
2077 defined $diffinfo->{'from_file'}[$i] ?
2078 $diffinfo->{'from_file'}[$i] :
2079 $diffinfo->{'to_file'};
2080 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2081 $from->{'href'}[$i] = href
(action
=>"blob",
2082 hash_base
=>$parents[$i],
2083 hash
=>$diffinfo->{'from_id'}[$i],
2084 file_name
=>$from->{'file'}[$i]);
2086 $from->{'href'}[$i] = undef;
2090 # ordinary (not combined) diff
2091 $from->{'file'} = $diffinfo->{'from_file'};
2092 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2093 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2094 hash
=>$diffinfo->{'from_id'},
2095 file_name
=>$from->{'file'});
2097 delete $from->{'href'};
2101 $to->{'file'} = $diffinfo->{'to_file'};
2102 if (!is_deleted
($diffinfo)) { # file exists in result
2103 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2104 hash
=>$diffinfo->{'to_id'},
2105 file_name
=>$to->{'file'});
2107 delete $to->{'href'};
2111 ## ......................................................................
2112 ## parse to array of hashes functions
2114 sub git_get_heads_list
{
2118 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2119 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2120 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2123 while (my $line = <$fd>) {
2127 my ($refinfo, $committerinfo) = split(/\0/, $line);
2128 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2129 my ($committer, $epoch, $tz) =
2130 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2131 $name =~ s!^refs/heads/!!;
2133 $ref_item{'name'} = $name;
2134 $ref_item{'id'} = $hash;
2135 $ref_item{'title'} = $title || '(no commit message)';
2136 $ref_item{'epoch'} = $epoch;
2138 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2140 $ref_item{'age'} = "unknown";
2143 push @headslist, \
%ref_item;
2147 return wantarray ? @headslist : \
@headslist;
2150 sub git_get_tags_list
{
2154 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2155 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2156 '--format=%(objectname) %(objecttype) %(refname) '.
2157 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2160 while (my $line = <$fd>) {
2164 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2165 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2166 my ($creator, $epoch, $tz) =
2167 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2168 $name =~ s!^refs/tags/!!;
2170 $ref_item{'type'} = $type;
2171 $ref_item{'id'} = $id;
2172 $ref_item{'name'} = $name;
2173 if ($type eq "tag") {
2174 $ref_item{'subject'} = $title;
2175 $ref_item{'reftype'} = $reftype;
2176 $ref_item{'refid'} = $refid;
2178 $ref_item{'reftype'} = $type;
2179 $ref_item{'refid'} = $id;
2182 if ($type eq "tag" || $type eq "commit") {
2183 $ref_item{'epoch'} = $epoch;
2185 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2187 $ref_item{'age'} = "unknown";
2191 push @tagslist, \
%ref_item;
2195 return wantarray ? @tagslist : \
@tagslist;
2198 ## ----------------------------------------------------------------------
2199 ## filesystem-related functions
2201 sub get_file_owner
{
2204 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2205 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2206 if (!defined $gcos) {
2210 $owner =~ s/[,;].*$//;
2211 return to_utf8
($owner);
2214 ## ......................................................................
2215 ## mimetype related functions
2217 sub mimetype_guess_file
{
2218 my $filename = shift;
2219 my $mimemap = shift;
2220 -r
$mimemap or return undef;
2223 open(MIME
, $mimemap) or return undef;
2225 next if m/^#/; # skip comments
2226 my ($mime, $exts) = split(/\t+/);
2227 if (defined $exts) {
2228 my @exts = split(/\s+/, $exts);
2229 foreach my $ext (@exts) {
2230 $mimemap{$ext} = $mime;
2236 $filename =~ /\.([^.]*)$/;
2237 return $mimemap{$1};
2240 sub mimetype_guess
{
2241 my $filename = shift;
2243 $filename =~ /\./ or return undef;
2245 if ($mimetypes_file) {
2246 my $file = $mimetypes_file;
2247 if ($file !~ m!^/!) { # if it is relative path
2248 # it is relative to project
2249 $file = "$projectroot/$project/$file";
2251 $mime = mimetype_guess_file
($filename, $file);
2253 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2259 my $filename = shift;
2262 my $mime = mimetype_guess
($filename);
2263 $mime and return $mime;
2267 return $default_blob_plain_mimetype unless $fd;
2270 return 'text/plain' .
2271 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2272 } elsif (! $filename) {
2273 return 'application/octet-stream';
2274 } elsif ($filename =~ m/\.png$/i) {
2276 } elsif ($filename =~ m/\.gif$/i) {
2278 } elsif ($filename =~ m/\.jpe?g$/i) {
2279 return 'image/jpeg';
2281 return 'application/octet-stream';
2285 ## ======================================================================
2286 ## functions printing HTML: header, footer, error page
2288 sub git_header_html
{
2289 my $status = shift || "200 OK";
2290 my $expires = shift;
2292 my $title = "$site_name";
2293 if (defined $project) {
2294 $title .= " - " . to_utf8
($project);
2295 if (defined $action) {
2296 $title .= "/$action";
2297 if (defined $file_name) {
2298 $title .= " - " . esc_path
($file_name);
2299 if ($action eq "tree" && $file_name !~ m
|/$|) {
2306 # require explicit support from the UA if we are to send the page as
2307 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2308 # we have to do this because MSIE sometimes globs '*/*', pretending to
2309 # support xhtml+xml but choking when it gets what it asked for.
2310 if (defined $cgi->http('HTTP_ACCEPT') &&
2311 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2312 $cgi->Accept('application/xhtml+xml') != 0) {
2313 $content_type = 'application/xhtml+xml';
2315 $content_type = 'text/html';
2317 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2318 -status
=> $status, -expires
=> $expires);
2319 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2321 <?xml version="1.0" encoding="utf-8"?>
2322 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2323 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2324 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2325 <!-- git core binaries version $git_version -->
2327 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2328 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2329 <meta name="robots" content="index, nofollow"/>
2330 <title>$title</title>
2332 # print out each stylesheet that exist
2333 if (defined $stylesheet) {
2334 #provides backwards capability for those people who define style sheet in a config file
2335 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2337 foreach my $stylesheet (@stylesheets) {
2338 next unless $stylesheet;
2339 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2342 if (defined $project) {
2343 printf('<link rel="alternate" title="%s log RSS feed" '.
2344 'href="%s" type="application/rss+xml" />'."\n",
2345 esc_param
($project), href
(action
=>"rss"));
2346 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2347 'href="%s" type="application/rss+xml" />'."\n",
2348 esc_param
($project), href
(action
=>"rss",
2349 extra_options
=>"--no-merges"));
2350 printf('<link rel="alternate" title="%s log Atom feed" '.
2351 'href="%s" type="application/atom+xml" />'."\n",
2352 esc_param
($project), href
(action
=>"atom"));
2353 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2354 'href="%s" type="application/atom+xml" />'."\n",
2355 esc_param
($project), href
(action
=>"atom",
2356 extra_options
=>"--no-merges"));
2358 printf('<link rel="alternate" title="%s projects list" '.
2359 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2360 $site_name, href
(project
=>undef, action
=>"project_index"));
2361 printf('<link rel="alternate" title="%s projects feeds" '.
2362 'href="%s" type="text/x-opml"/>'."\n",
2363 $site_name, href
(project
=>undef, action
=>"opml"));
2365 if (defined $favicon) {
2366 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2372 if (-f
$site_header) {
2373 open (my $fd, $site_header);
2378 print "<div class=\"page_header\">\n" .
2379 $cgi->a({-href
=> esc_url
($logo_url),
2380 -title
=> $logo_label},
2381 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2382 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2383 if (defined $project) {
2384 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2385 if (defined $action) {
2392 my ($have_search) = gitweb_check_feature
('search');
2393 if ((defined $project) && ($have_search)) {
2394 if (!defined $searchtext) {
2398 if (defined $hash_base) {
2399 $search_hash = $hash_base;
2400 } elsif (defined $hash) {
2401 $search_hash = $hash;
2403 $search_hash = "HEAD";
2405 my $action = $my_uri;
2406 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2407 if ($use_pathinfo) {
2408 $action .= "/$project";
2410 $cgi->param("p", $project);
2412 $cgi->param("a", "search");
2413 $cgi->param("h", $search_hash);
2414 print $cgi->startform(-method => "get", -action
=> $action) .
2415 "<div class=\"search\">\n" .
2416 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2417 $cgi->hidden(-name
=> "a") . "\n" .
2418 $cgi->hidden(-name
=> "h") . "\n" .
2419 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2420 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2421 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2423 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2425 $cgi->end_form() . "\n";
2429 sub git_footer_html
{
2430 print "<div class=\"page_footer\">\n";
2431 if (defined $project) {
2432 my $descr = git_get_project_description
($project);
2433 if (defined $descr) {
2434 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2436 print $cgi->a({-href
=> href
(action
=>"rss"),
2437 -class => "rss_logo"}, "RSS") . " ";
2438 print $cgi->a({-href
=> href
(action
=>"atom"),
2439 -class => "rss_logo"}, "Atom") . "\n";
2441 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2442 -class => "rss_logo"}, "OPML") . " ";
2443 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2444 -class => "rss_logo"}, "TXT") . "\n";
2448 if (-f
$site_footer) {
2449 open (my $fd, $site_footer);
2459 my $status = shift || "403 Forbidden";
2460 my $error = shift || "Malformed query, file missing or permission denied";
2462 git_header_html
($status);
2464 <div class="page_body">
2474 ## ----------------------------------------------------------------------
2475 ## functions printing or outputting HTML: navigation
2477 sub git_print_page_nav
{
2478 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2479 $extra = '' if !defined $extra; # pager or formats
2481 my @navs = qw(summary shortlog log commit commitdiff tree);
2483 @navs = grep { $_ ne $suppress } @navs;
2486 my %arg = map { $_ => {action
=>$_} } @navs;
2487 if (defined $head) {
2488 for (qw(commit commitdiff)) {
2489 $arg{$_}{'hash'} = $head;
2491 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2492 for (qw(shortlog log)) {
2493 $arg{$_}{'hash'} = $head;
2497 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2498 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2500 print "<div class=\"page_nav\">\n" .
2502 map { $_ eq $current ?
2503 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2505 print "<br/>\n$extra<br/>\n" .
2509 sub format_paging_nav
{
2510 my ($action, $hash, $head, $page, $nrevs) = @_;
2514 if ($hash ne $head || $page) {
2515 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2517 $paging_nav .= "HEAD";
2521 $paging_nav .= " ⋅ " .
2522 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2523 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2525 $paging_nav .= " ⋅ prev";
2528 if ($nrevs >= (100 * ($page+1)-1)) {
2529 $paging_nav .= " ⋅ " .
2530 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2531 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2533 $paging_nav .= " ⋅ next";
2539 ## ......................................................................
2540 ## functions printing or outputting HTML: div
2542 sub git_print_header_div
{
2543 my ($action, $title, $hash, $hash_base) = @_;
2546 $args{'action'} = $action;
2547 $args{'hash'} = $hash if $hash;
2548 $args{'hash_base'} = $hash_base if $hash_base;
2550 print "<div class=\"header\">\n" .
2551 $cgi->a({-href
=> href
(%args), -class => "title"},
2552 $title ? $title : $action) .
2556 #sub git_print_authorship (\%) {
2557 sub git_print_authorship
{
2560 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2561 print "<div class=\"author_date\">" .
2562 esc_html
($co->{'author_name'}) .
2564 if ($ad{'hour_local'} < 6) {
2565 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2566 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2568 printf(" (%02d:%02d %s)",
2569 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2574 sub git_print_page_path
{
2580 print "<div class=\"page_path\">";
2581 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2582 -title
=> 'tree root'}, to_utf8
("[$project]"));
2584 if (defined $name) {
2585 my @dirname = split '/', $name;
2586 my $basename = pop @dirname;
2589 foreach my $dir (@dirname) {
2590 $fullname .= ($fullname ? '/' : '') . $dir;
2591 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2593 -title
=> $fullname}, esc_path
($dir));
2596 if (defined $type && $type eq 'blob') {
2597 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2599 -title
=> $name}, esc_path
($basename));
2600 } elsif (defined $type && $type eq 'tree') {
2601 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2603 -title
=> $name}, esc_path
($basename));
2606 print esc_path
($basename);
2609 print "<br/></div>\n";
2612 # sub git_print_log (\@;%) {
2613 sub git_print_log
($;%) {
2617 if ($opts{'-remove_title'}) {
2618 # remove title, i.e. first line of log
2621 # remove leading empty lines
2622 while (defined $log->[0] && $log->[0] eq "") {
2629 foreach my $line (@$log) {
2630 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2633 if (! $opts{'-remove_signoff'}) {
2634 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2637 # remove signoff lines
2644 # print only one empty line
2645 # do not print empty line after signoff
2647 next if ($empty || $signoff);
2653 print format_log_line_html
($line) . "<br/>\n";
2656 if ($opts{'-final_empty_line'}) {
2657 # end with single empty line
2658 print "<br/>\n" unless $empty;
2662 # return link target (what link points to)
2663 sub git_get_link_target
{
2668 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2672 $link_target = <$fd>;
2677 return $link_target;
2680 # given link target, and the directory (basedir) the link is in,
2681 # return target of link relative to top directory (top tree);
2682 # return undef if it is not possible (including absolute links).
2683 sub normalize_link_target
{
2684 my ($link_target, $basedir, $hash_base) = @_;
2686 # we can normalize symlink target only if $hash_base is provided
2687 return unless $hash_base;
2689 # absolute symlinks (beginning with '/') cannot be normalized
2690 return if (substr($link_target, 0, 1) eq '/');
2692 # normalize link target to path from top (root) tree (dir)
2695 $path = $basedir . '/' . $link_target;
2697 # we are in top (root) tree (dir)
2698 $path = $link_target;
2701 # remove //, /./, and /../
2703 foreach my $part (split('/', $path)) {
2704 # discard '.' and ''
2705 next if (!$part || $part eq '.');
2707 if ($part eq '..') {
2711 # link leads outside repository (outside top dir)
2715 push @path_parts, $part;
2718 $path = join('/', @path_parts);
2723 # print tree entry (row of git_tree), but without encompassing <tr> element
2724 sub git_print_tree_entry
{
2725 my ($t, $basedir, $hash_base, $have_blame) = @_;
2728 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2730 # The format of a table row is: mode list link. Where mode is
2731 # the mode of the entry, list is the name of the entry, an href,
2732 # and link is the action links of the entry.
2734 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2735 if ($t->{'type'} eq "blob") {
2736 print "<td class=\"list\">" .
2737 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2738 file_name
=>"$basedir$t->{'name'}", %base_key),
2739 -class => "list"}, esc_path
($t->{'name'}));
2740 if (S_ISLNK
(oct $t->{'mode'})) {
2741 my $link_target = git_get_link_target
($t->{'hash'});
2743 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2744 if (defined $norm_target) {
2746 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2747 file_name
=>$norm_target),
2748 -title
=> $norm_target}, esc_path
($link_target));
2750 print " -> " . esc_path
($link_target);
2755 print "<td class=\"link\">";
2756 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2757 file_name
=>"$basedir$t->{'name'}", %base_key)},
2761 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2762 file_name
=>"$basedir$t->{'name'}", %base_key)},
2765 if (defined $hash_base) {
2767 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2768 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2772 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2773 file_name
=>"$basedir$t->{'name'}")},
2777 } elsif ($t->{'type'} eq "tree") {
2778 print "<td class=\"list\">";
2779 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2780 file_name
=>"$basedir$t->{'name'}", %base_key)},
2781 esc_path
($t->{'name'}));
2783 print "<td class=\"link\">";
2784 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2785 file_name
=>"$basedir$t->{'name'}", %base_key)},
2787 if (defined $hash_base) {
2789 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2790 file_name
=>"$basedir$t->{'name'}")},
2795 # unknown object: we can only present history for it
2796 # (this includes 'commit' object, i.e. submodule support)
2797 print "<td class=\"list\">" .
2798 esc_path
($t->{'name'}) .
2800 print "<td class=\"link\">";
2801 if (defined $hash_base) {
2802 print $cgi->a({-href
=> href
(action
=>"history",
2803 hash_base
=>$hash_base,
2804 file_name
=>"$basedir$t->{'name'}")},
2811 ## ......................................................................
2812 ## functions printing large fragments of HTML
2814 # get pre-image filenames for merge (combined) diff
2815 sub fill_from_file_info
{
2816 my ($diff, @parents) = @_;
2818 $diff->{'from_file'} = [ ];
2819 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2820 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2821 if ($diff->{'status'}[$i] eq 'R' ||
2822 $diff->{'status'}[$i] eq 'C') {
2823 $diff->{'from_file'}[$i] =
2824 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2831 # is current raw difftree line of file deletion
2833 my $diffinfo = shift;
2835 return $diffinfo->{'status_str'} =~ /D/;
2838 # does patch correspond to [previous] difftree raw line
2839 # $diffinfo - hashref of parsed raw diff format
2840 # $patchinfo - hashref of parsed patch diff format
2841 # (the same keys as in $diffinfo)
2842 sub is_patch_split
{
2843 my ($diffinfo, $patchinfo) = @_;
2845 return defined $diffinfo && defined $patchinfo
2846 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2850 sub git_difftree_body
{
2851 my ($difftree, $hash, @parents) = @_;
2852 my ($parent) = $parents[0];
2853 my ($have_blame) = gitweb_check_feature
('blame');
2854 print "<div class=\"list_head\">\n";
2855 if ($#{$difftree} > 10) {
2856 print(($#{$difftree} + 1) . " files changed:\n");
2860 print "<table class=\"" .
2861 (@parents > 1 ? "combined " : "") .
2864 # header only for combined diff in 'commitdiff' view
2865 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2868 print "<thead><tr>\n" .
2869 "<th></th><th></th>\n"; # filename, patchN link
2870 for (my $i = 0; $i < @parents; $i++) {
2871 my $par = $parents[$i];
2873 $cgi->a({-href
=> href
(action
=>"commitdiff",
2874 hash
=>$hash, hash_parent
=>$par),
2875 -title
=> 'commitdiff to parent number ' .
2876 ($i+1) . ': ' . substr($par,0,7)},
2880 print "</tr></thead>\n<tbody>\n";
2885 foreach my $line (@{$difftree}) {
2886 my $diff = parsed_difftree_line
($line);
2889 print "<tr class=\"dark\">\n";
2891 print "<tr class=\"light\">\n";
2895 if (exists $diff->{'nparents'}) { # combined diff
2897 fill_from_file_info
($diff, @parents)
2898 unless exists $diff->{'from_file'};
2900 if (!is_deleted
($diff)) {
2901 # file exists in the result (child) commit
2903 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2904 file_name
=>$diff->{'to_file'},
2906 -class => "list"}, esc_path
($diff->{'to_file'})) .
2910 esc_path
($diff->{'to_file'}) .
2914 if ($action eq 'commitdiff') {
2917 print "<td class=\"link\">" .
2918 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2923 my $has_history = 0;
2924 my $not_deleted = 0;
2925 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2926 my $hash_parent = $parents[$i];
2927 my $from_hash = $diff->{'from_id'}[$i];
2928 my $from_path = $diff->{'from_file'}[$i];
2929 my $status = $diff->{'status'}[$i];
2931 $has_history ||= ($status ne 'A');
2932 $not_deleted ||= ($status ne 'D');
2934 if ($status eq 'A') {
2935 print "<td class=\"link\" align=\"right\"> | </td>\n";
2936 } elsif ($status eq 'D') {
2937 print "<td class=\"link\">" .
2938 $cgi->a({-href
=> href
(action
=>"blob",
2941 file_name
=>$from_path)},
2945 if ($diff->{'to_id'} eq $from_hash) {
2946 print "<td class=\"link nochange\">";
2948 print "<td class=\"link\">";
2950 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2951 hash
=>$diff->{'to_id'},
2952 hash_parent
=>$from_hash,
2954 hash_parent_base
=>$hash_parent,
2955 file_name
=>$diff->{'to_file'},
2956 file_parent
=>$from_path)},
2962 print "<td class=\"link\">";
2964 print $cgi->a({-href
=> href
(action
=>"blob",
2965 hash
=>$diff->{'to_id'},
2966 file_name
=>$diff->{'to_file'},
2969 print " | " if ($has_history);
2972 print $cgi->a({-href
=> href
(action
=>"history",
2973 file_name
=>$diff->{'to_file'},
2980 next; # instead of 'else' clause, to avoid extra indent
2982 # else ordinary diff
2984 my ($to_mode_oct, $to_mode_str, $to_file_type);
2985 my ($from_mode_oct, $from_mode_str, $from_file_type);
2986 if ($diff->{'to_mode'} ne ('0' x
6)) {
2987 $to_mode_oct = oct $diff->{'to_mode'};
2988 if (S_ISREG
($to_mode_oct)) { # only for regular file
2989 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2991 $to_file_type = file_type
($diff->{'to_mode'});
2993 if ($diff->{'from_mode'} ne ('0' x
6)) {
2994 $from_mode_oct = oct $diff->{'from_mode'};
2995 if (S_ISREG
($to_mode_oct)) { # only for regular file
2996 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2998 $from_file_type = file_type
($diff->{'from_mode'});
3001 if ($diff->{'status'} eq "A") { # created
3002 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3003 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3004 $mode_chng .= "]</span>";
3006 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3007 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3008 -class => "list"}, esc_path
($diff->{'file'}));
3010 print "<td>$mode_chng</td>\n";
3011 print "<td class=\"link\">";
3012 if ($action eq 'commitdiff') {
3015 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3018 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3019 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3023 } elsif ($diff->{'status'} eq "D") { # deleted
3024 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3026 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3027 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3028 -class => "list"}, esc_path
($diff->{'file'}));
3030 print "<td>$mode_chng</td>\n";
3031 print "<td class=\"link\">";
3032 if ($action eq 'commitdiff') {
3035 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3038 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3039 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3042 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3043 file_name
=>$diff->{'file'})},
3046 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3047 file_name
=>$diff->{'file'})},
3051 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3052 my $mode_chnge = "";
3053 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3054 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3055 if ($from_file_type ne $to_file_type) {
3056 $mode_chnge .= " from $from_file_type to $to_file_type";
3058 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3059 if ($from_mode_str && $to_mode_str) {
3060 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3061 } elsif ($to_mode_str) {
3062 $mode_chnge .= " mode: $to_mode_str";
3065 $mode_chnge .= "]</span>\n";
3068 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3069 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3070 -class => "list"}, esc_path
($diff->{'file'}));
3072 print "<td>$mode_chnge</td>\n";
3073 print "<td class=\"link\">";
3074 if ($action eq 'commitdiff') {
3077 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3079 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3080 # "commit" view and modified file (not onlu mode changed)
3081 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3082 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3083 hash_base
=>$hash, hash_parent_base
=>$parent,
3084 file_name
=>$diff->{'file'})},
3088 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3089 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3092 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3093 file_name
=>$diff->{'file'})},
3096 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3097 file_name
=>$diff->{'file'})},
3101 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3102 my %status_name = ('R' => 'moved', 'C' => 'copied');
3103 my $nstatus = $status_name{$diff->{'status'}};
3105 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3106 # mode also for directories, so we cannot use $to_mode_str
3107 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3110 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3111 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3112 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3113 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3114 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3115 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3116 -class => "list"}, esc_path
($diff->{'from_file'})) .
3117 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3118 "<td class=\"link\">";
3119 if ($action eq 'commitdiff') {
3122 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3124 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3125 # "commit" view and modified file (not only pure rename or copy)
3126 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3127 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3128 hash_base
=>$hash, hash_parent_base
=>$parent,
3129 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3133 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3134 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3137 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3138 file_name
=>$diff->{'to_file'})},
3141 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3142 file_name
=>$diff->{'to_file'})},
3146 } # we should not encounter Unmerged (U) or Unknown (X) status
3149 print "</tbody>" if $has_header;
3153 sub git_patchset_body
{
3154 my ($fd, $difftree, $hash, @hash_parents) = @_;
3155 my ($hash_parent) = $hash_parents[0];
3157 my $is_combined = (@hash_parents > 1);
3159 my $patch_number = 0;
3165 print "<div class=\"patchset\">\n";
3167 # skip to first patch
3168 while ($patch_line = <$fd>) {
3171 last if ($patch_line =~ m/^diff /);
3175 while ($patch_line) {
3177 # parse "git diff" header line
3178 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3179 # $1 is from_name, which we do not use
3180 $to_name = unquote
($2);
3181 $to_name =~ s!^b/!!;
3182 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3183 # $1 is 'cc' or 'combined', which we do not use
3184 $to_name = unquote
($2);
3189 # check if current patch belong to current raw line
3190 # and parse raw git-diff line if needed
3191 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3192 # this is continuation of a split patch
3193 print "<div class=\"patch cont\">\n";
3195 # advance raw git-diff output if needed
3196 $patch_idx++ if defined $diffinfo;
3198 # read and prepare patch information
3199 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3201 # compact combined diff output can have some patches skipped
3202 # find which patch (using pathname of result) we are at now;
3204 while ($to_name ne $diffinfo->{'to_file'}) {
3205 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3206 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3207 "</div>\n"; # class="patch"
3212 last if $patch_idx > $#$difftree;
3213 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3217 # modifies %from, %to hashes
3218 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3220 # this is first patch for raw difftree line with $patch_idx index
3221 # we index @$difftree array from 0, but number patches from 1
3222 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3226 #assert($patch_line =~ m/^diff /) if DEBUG;
3227 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3229 # print "git diff" header
3230 print format_git_diff_header_line
($patch_line, $diffinfo,
3233 # print extended diff header
3234 print "<div class=\"diff extended_header\">\n";
3236 while ($patch_line = <$fd>) {
3239 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3241 print format_extended_diff_header_line
($patch_line, $diffinfo,
3244 print "</div>\n"; # class="diff extended_header"
3246 # from-file/to-file diff header
3247 if (! $patch_line) {
3248 print "</div>\n"; # class="patch"
3251 next PATCH
if ($patch_line =~ m/^diff /);
3252 #assert($patch_line =~ m/^---/) if DEBUG;
3254 my $last_patch_line = $patch_line;
3255 $patch_line = <$fd>;
3257 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3259 print format_diff_from_to_header
($last_patch_line, $patch_line,
3260 $diffinfo, \
%from, \
%to,
3265 while ($patch_line = <$fd>) {
3268 next PATCH
if ($patch_line =~ m/^diff /);
3270 print format_diff_line
($patch_line, \
%from, \
%to);
3274 print "</div>\n"; # class="patch"
3277 # for compact combined (--cc) format, with chunk and patch simpliciaction
3278 # patchset might be empty, but there might be unprocessed raw lines
3279 for (++$patch_idx if $patch_number > 0;
3280 $patch_idx < @$difftree;
3282 # read and prepare patch information
3283 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3285 # generate anchor for "patch" links in difftree / whatchanged part
3286 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3287 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3288 "</div>\n"; # class="patch"
3293 if ($patch_number == 0) {
3294 if (@hash_parents > 1) {
3295 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3297 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3301 print "</div>\n"; # class="patchset"
3304 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3306 sub git_project_list_body
{
3307 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3309 my ($check_forks) = gitweb_check_feature
('forks');
3312 foreach my $pr (@$projlist) {
3313 my (@aa) = git_get_last_activity
($pr->{'path'});
3317 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3318 if (!defined $pr->{'descr'}) {
3319 my $descr = git_get_project_description
($pr->{'path'}) || "";
3320 $pr->{'descr_long'} = to_utf8
($descr);
3321 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3323 if (!defined $pr->{'owner'}) {
3324 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3327 my $pname = $pr->{'path'};
3328 if (($pname =~ s/\.git$//) &&
3329 ($pname !~ /\/$/) &&
3330 (-d
"$projectroot/$pname")) {
3331 $pr->{'forks'} = "-d $projectroot/$pname";
3337 push @projects, $pr;
3340 $order ||= $default_projects_order;
3341 $from = 0 unless defined $from;
3342 $to = $#projects if (!defined $to || $#projects < $to);
3344 print "<table class=\"project_list\">\n";
3345 unless ($no_header) {
3348 print "<th></th>\n";
3350 if ($order eq "project") {
3351 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3352 print "<th>Project</th>\n";
3355 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3356 -class => "header"}, "Project") .
3359 if ($order eq "descr") {
3360 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3361 print "<th>Description</th>\n";
3364 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3365 -class => "header"}, "Description") .
3368 if ($order eq "owner") {
3369 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3370 print "<th>Owner</th>\n";
3373 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3374 -class => "header"}, "Owner") .
3377 if ($order eq "age") {
3378 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3379 print "<th>Last Change</th>\n";
3382 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3383 -class => "header"}, "Last Change") .
3386 print "<th></th>\n" .
3390 for (my $i = $from; $i <= $to; $i++) {
3391 my $pr = $projects[$i];
3393 print "<tr class=\"dark\">\n";
3395 print "<tr class=\"light\">\n";
3400 if ($pr->{'forks'}) {
3401 print "<!-- $pr->{'forks'} -->\n";
3402 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3406 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3407 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3408 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3409 -class => "list", -title
=> $pr->{'descr_long'}},
3410 esc_html
($pr->{'descr'})) . "</td>\n" .
3411 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3412 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3413 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3414 "<td class=\"link\">" .
3415 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3416 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3417 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3418 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3419 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3423 if (defined $extra) {
3426 print "<td></td>\n";
3428 print "<td colspan=\"5\">$extra</td>\n" .
3434 sub git_shortlog_body
{
3435 # uses global variable $project
3436 my ($commitlist, $from, $to, $refs, $extra) = @_;
3438 $from = 0 unless defined $from;
3439 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3441 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3443 for (my $i = $from; $i <= $to; $i++) {
3444 my %co = %{$commitlist->[$i]};
3445 my $commit = $co{'id'};
3446 my $ref = format_ref_marker
($refs, $commit);
3448 print "<tr class=\"dark\">\n";
3450 print "<tr class=\"light\">\n";
3453 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3454 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3455 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3456 "<td><i>" . $author . "</i></td>\n" .
3458 print format_subject_html
($co{'title'}, $co{'title_short'},
3459 href
(action
=>"commit", hash
=>$commit), $ref);
3461 "<td class=\"link\">" .
3462 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3463 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3464 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3465 my $snapshot_links = format_snapshot_links
($commit);
3466 if (defined $snapshot_links) {
3467 print " | " . $snapshot_links;
3472 if (defined $extra) {
3474 "<td colspan=\"4\">$extra</td>\n" .
3480 sub git_history_body
{
3481 # Warning: assumes constant type (blob or tree) during history
3482 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3484 $from = 0 unless defined $from;
3485 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3487 print "<table class=\"history\" cellspacing=\"0\">\n";
3489 for (my $i = $from; $i <= $to; $i++) {
3490 my %co = %{$commitlist->[$i]};
3494 my $commit = $co{'id'};
3496 my $ref = format_ref_marker
($refs, $commit);
3499 print "<tr class=\"dark\">\n";
3501 print "<tr class=\"light\">\n";
3504 # shortlog uses chop_str($co{'author_name'}, 10)
3505 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3506 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3507 "<td><i>" . $author . "</i></td>\n" .
3509 # originally git_history used chop_str($co{'title'}, 50)
3510 print format_subject_html
($co{'title'}, $co{'title_short'},
3511 href
(action
=>"commit", hash
=>$commit), $ref);
3513 "<td class=\"link\">" .
3514 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3515 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3517 if ($ftype eq 'blob') {
3518 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3519 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3520 if (defined $blob_current && defined $blob_parent &&
3521 $blob_current ne $blob_parent) {
3523 $cgi->a({-href
=> href
(action
=>"blobdiff",
3524 hash
=>$blob_current, hash_parent
=>$blob_parent,
3525 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3526 file_name
=>$file_name)},
3533 if (defined $extra) {
3535 "<td colspan=\"4\">$extra</td>\n" .
3542 # uses global variable $project
3543 my ($taglist, $from, $to, $extra) = @_;
3544 $from = 0 unless defined $from;
3545 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3547 print "<table class=\"tags\" cellspacing=\"0\">\n";
3549 for (my $i = $from; $i <= $to; $i++) {
3550 my $entry = $taglist->[$i];
3552 my $comment = $tag{'subject'};
3554 if (defined $comment) {
3555 $comment_short = chop_str
($comment, 30, 5);
3558 print "<tr class=\"dark\">\n";
3560 print "<tr class=\"light\">\n";
3563 if (defined $tag{'age'}) {
3564 print "<td><i>$tag{'age'}</i></td>\n";
3566 print "<td></td>\n";
3569 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3570 -class => "list name"}, esc_html
($tag{'name'})) .
3573 if (defined $comment) {
3574 print format_subject_html
($comment, $comment_short,
3575 href
(action
=>"tag", hash
=>$tag{'id'}));
3578 "<td class=\"selflink\">";
3579 if ($tag{'type'} eq "tag") {
3580 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3585 "<td class=\"link\">" . " | " .
3586 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3587 if ($tag{'reftype'} eq "commit") {
3588 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3589 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3590 } elsif ($tag{'reftype'} eq "blob") {
3591 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3596 if (defined $extra) {
3598 "<td colspan=\"5\">$extra</td>\n" .
3604 sub git_heads_body
{
3605 # uses global variable $project
3606 my ($headlist, $head, $from, $to, $extra) = @_;
3607 $from = 0 unless defined $from;
3608 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3610 print "<table class=\"heads\" cellspacing=\"0\">\n";
3612 for (my $i = $from; $i <= $to; $i++) {
3613 my $entry = $headlist->[$i];
3615 my $curr = $ref{'id'} eq $head;
3617 print "<tr class=\"dark\">\n";
3619 print "<tr class=\"light\">\n";
3622 print "<td><i>$ref{'age'}</i></td>\n" .
3623 ($curr ? "<td class=\"current_head\">" : "<td>") .
3624 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3625 -class => "list name"},esc_html
($ref{'name'})) .
3627 "<td class=\"link\">" .
3628 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3629 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3630 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3634 if (defined $extra) {
3636 "<td colspan=\"3\">$extra</td>\n" .
3642 sub git_search_grep_body
{
3643 my ($commitlist, $from, $to, $extra) = @_;
3644 $from = 0 unless defined $from;
3645 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3647 print "<table class=\"grep\" cellspacing=\"0\">\n";
3649 for (my $i = $from; $i <= $to; $i++) {
3650 my %co = %{$commitlist->[$i]};
3654 my $commit = $co{'id'};
3656 print "<tr class=\"dark\">\n";
3658 print "<tr class=\"light\">\n";
3661 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3662 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3663 "<td><i>" . $author . "</i></td>\n" .
3665 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3666 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3667 my $comment = $co{'comment'};
3668 foreach my $line (@$comment) {
3669 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3670 my $lead = esc_html
($1) || "";
3671 $lead = chop_str
($lead, 30, 10);
3672 my $match = esc_html
($2) || "";
3673 my $trail = esc_html
($3) || "";
3674 $trail = chop_str
($trail, 30, 10);
3675 my $text = "$lead<span class=\"match\">$match</span>$trail";
3676 print chop_str
($text, 80, 5) . "<br/>\n";
3680 "<td class=\"link\">" .
3681 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3683 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3687 if (defined $extra) {
3689 "<td colspan=\"3\">$extra</td>\n" .
3695 ## ======================================================================
3696 ## ======================================================================
3699 sub git_project_list
{
3700 my $order = $cgi->param('o');
3701 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3702 die_error
(undef, "Unknown order parameter");
3705 my @list = git_get_projects_list
();
3707 die_error
(undef, "No projects found");
3711 if (-f
$home_text) {
3712 print "<div class=\"index_include\">\n";
3713 open (my $fd, $home_text);
3718 git_project_list_body
(\
@list, $order);
3723 my $order = $cgi->param('o');
3724 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3725 die_error
(undef, "Unknown order parameter");
3728 my @list = git_get_projects_list
($project);
3730 die_error
(undef, "No forks found");
3734 git_print_page_nav
('','');
3735 git_print_header_div
('summary', "$project forks");
3736 git_project_list_body
(\
@list, $order);
3740 sub git_project_index
{
3741 my @projects = git_get_projects_list
($project);
3744 -type
=> 'text/plain',
3745 -charset
=> 'utf-8',
3746 -content_disposition
=> 'inline; filename="index.aux"');
3748 foreach my $pr (@projects) {
3749 if (!exists $pr->{'owner'}) {
3750 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3753 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3754 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3755 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3756 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3760 print "$path $owner\n";
3765 my $descr = git_get_project_description
($project) || "none";
3766 my %co = parse_commit
("HEAD");
3767 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3768 my $head = $co{'id'};
3770 my $owner = git_get_project_owner
($project);
3772 my $refs = git_get_references
();
3773 # These get_*_list functions return one more to allow us to see if
3774 # there are more ...
3775 my @taglist = git_get_tags_list
(16);
3776 my @headlist = git_get_heads_list
(16);
3778 my ($check_forks) = gitweb_check_feature
('forks');
3781 @forklist = git_get_projects_list
($project);
3785 git_print_page_nav
('summary','', $head);
3787 print "<div class=\"title\"> </div>\n";
3788 print "<table cellspacing=\"0\">\n" .
3789 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3790 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3791 if (defined $cd{'rfc2822'}) {
3792 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3795 # use per project git URL list in $projectroot/$project/cloneurl
3796 # or make project git URL from git base URL and project name
3797 my $url_tag = "URL";
3798 my @url_list = git_get_project_url_list
($project);
3799 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3800 foreach my $git_url (@url_list) {
3801 next unless $git_url;
3802 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3807 if (-s
"$projectroot/$project/README.html") {
3808 if (open my $fd, "$projectroot/$project/README.html") {
3809 print "<div class=\"title\">readme</div>\n";
3810 print $_ while (<$fd>);
3815 # we need to request one more than 16 (0..15) to check if
3817 my @commitlist = $head ? parse_commits
($head, 17) : ();
3819 git_print_header_div
('shortlog');
3820 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3821 $#commitlist <= 15 ? undef :
3822 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3826 git_print_header_div
('tags');
3827 git_tags_body
(\
@taglist, 0, 15,
3828 $#taglist <= 15 ? undef :
3829 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3833 git_print_header_div
('heads');
3834 git_heads_body
(\
@headlist, $head, 0, 15,
3835 $#headlist <= 15 ? undef :
3836 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3840 git_print_header_div
('forks');
3841 git_project_list_body
(\
@forklist, undef, 0, 15,
3842 $#forklist <= 15 ? undef :
3843 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3851 my $head = git_get_head_hash
($project);
3853 git_print_page_nav
('','', $head,undef,$head);
3854 my %tag = parse_tag
($hash);
3857 die_error
(undef, "Unknown tag object");
3860 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3861 print "<div class=\"title_text\">\n" .
3862 "<table cellspacing=\"0\">\n" .
3864 "<td>object</td>\n" .
3865 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3866 $tag{'object'}) . "</td>\n" .
3867 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3868 $tag{'type'}) . "</td>\n" .
3870 if (defined($tag{'author'})) {
3871 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3872 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3873 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3874 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3877 print "</table>\n\n" .
3879 print "<div class=\"page_body\">";
3880 my $comment = $tag{'comment'};
3881 foreach my $line (@$comment) {
3883 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3893 my ($have_blame) = gitweb_check_feature
('blame');
3895 die_error
('403 Permission denied', "Permission denied");
3897 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3898 $hash_base ||= git_get_head_hash
($project);
3899 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3900 my %co = parse_commit
($hash_base)
3901 or die_error
(undef, "Reading commit failed");
3902 if (!defined $hash) {
3903 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3904 or die_error
(undef, "Error looking up file");
3906 $ftype = git_get_type
($hash);
3907 if ($ftype !~ "blob") {
3908 die_error
('400 Bad Request', "Object is not a blob");
3910 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3911 $file_name, $hash_base)
3912 or die_error
(undef, "Open git-blame failed");
3915 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3918 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3921 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3923 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3924 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3925 git_print_page_path
($file_name, $ftype, $hash_base);
3926 my @rev_color = (qw(light2 dark2));
3927 my $num_colors = scalar(@rev_color);
3928 my $current_color = 0;
3931 <div class="page_body">
3932 <table class="blame">
3933 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3938 last unless defined $_;
3939 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3940 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3941 if (!exists $metainfo{$full_rev}) {
3942 $metainfo{$full_rev} = {};
3944 my $meta = $metainfo{$full_rev};
3947 if (/^(\S+) (.*)$/) {
3953 my $rev = substr($full_rev, 0, 8);
3954 my $author = $meta->{'author'};
3955 my %date = parse_date
($meta->{'author-time'},
3956 $meta->{'author-tz'});
3957 my $date = $date{'iso-tz'};
3959 $current_color = ++$current_color % $num_colors;
3961 print "<tr class=\"$rev_color[$current_color]\">\n";
3963 print "<td class=\"sha1\"";
3964 print " title=\"". esc_html
($author) . ", $date\"";
3965 print " rowspan=\"$group_size\"" if ($group_size > 1);
3967 print $cgi->a({-href
=> href
(action
=>"commit",
3969 file_name
=>$file_name)},
3973 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3974 or die_error
(undef, "Open git-rev-parse failed");
3975 my $parent_commit = <$dd>;
3977 chomp($parent_commit);
3978 my $blamed = href
(action
=> 'blame',
3979 file_name
=> $meta->{'filename'},
3980 hash_base
=> $parent_commit);
3981 print "<td class=\"linenr\">";
3982 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3984 -class => "linenr" },
3987 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3993 or print "Reading blob failed\n";
4000 my ($have_blame) = gitweb_check_feature
('blame');
4002 die_error
('403 Permission denied', "Permission denied");
4004 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4005 $hash_base ||= git_get_head_hash
($project);
4006 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4007 my %co = parse_commit
($hash_base)
4008 or die_error
(undef, "Reading commit failed");
4009 if (!defined $hash) {
4010 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4011 or die_error
(undef, "Error lookup file");
4013 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4014 or die_error
(undef, "Open git-annotate failed");
4017 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4020 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4023 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4025 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4026 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4027 git_print_page_path
($file_name, 'blob', $hash_base);
4028 print "<div class=\"page_body\">\n";
4030 <table class="blame">
4039 my @line_class = (qw(light dark));
4040 my $line_class_len = scalar (@line_class);
4041 my $line_class_num = $#line_class;
4042 while (my $line = <$fd>) {
4054 $line_class_num = ($line_class_num + 1) % $line_class_len;
4056 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4063 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4066 $short_rev = substr ($long_rev, 0, 8);
4067 $age = time () - $time;
4068 $age_str = age_string
($age);
4069 $age_str =~ s/ / /g;
4070 $age_class = age_class
($age);
4071 $author = esc_html
($author);
4072 $author =~ s/ / /g;
4074 $data = untabify
($data);
4075 $data = esc_html
($data);
4078 <tr class="$line_class[$line_class_num]">
4079 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4080 <td class="$age_class">$age_str</td>
4082 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4083 <td class="pre">$data</td>
4086 } # while (my $line = <$fd>)
4087 print "</table>\n\n";
4089 or print "Reading blob failed.\n";
4095 my $head = git_get_head_hash
($project);
4097 git_print_page_nav
('','', $head,undef,$head);
4098 git_print_header_div
('summary', $project);
4100 my @tagslist = git_get_tags_list
();
4102 git_tags_body
(\
@tagslist);
4108 my $head = git_get_head_hash
($project);
4110 git_print_page_nav
('','', $head,undef,$head);
4111 git_print_header_div
('summary', $project);
4113 my @headslist = git_get_heads_list
();
4115 git_heads_body
(\
@headslist, $head);
4120 sub git_blob_plain
{
4123 if (!defined $hash) {
4124 if (defined $file_name) {
4125 my $base = $hash_base || git_get_head_hash
($project);
4126 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4127 or die_error
(undef, "Error lookup file");
4129 die_error
(undef, "No file name defined");
4131 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4132 # blobs defined by non-textual hash id's can be cached
4137 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4138 or die_error
(undef, "Couldn't cat $file_name, $hash");
4140 $type ||= blob_mimetype
($fd, $file_name);
4142 # save as filename, even when no $file_name is given
4143 my $save_as = "$hash";
4144 if (defined $file_name) {
4145 $save_as = $file_name;
4146 } elsif ($type =~ m/^text\//) {
4153 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4155 binmode STDOUT
, ':raw';
4157 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4165 if (!defined $hash) {
4166 if (defined $file_name) {
4167 my $base = $hash_base || git_get_head_hash
($project);
4168 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4169 or die_error
(undef, "Error lookup file");
4171 die_error
(undef, "No file name defined");
4173 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4174 # blobs defined by non-textual hash id's can be cached
4178 my ($have_blame) = gitweb_check_feature
('blame');
4179 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4180 or die_error
(undef, "Couldn't cat $file_name, $hash");
4181 my $mimetype = blob_mimetype
($fd, $file_name);
4182 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4184 return git_blob_plain
($mimetype);
4186 # we can have blame only for text/* mimetype
4187 $have_blame &&= ($mimetype =~ m!^text/!);
4189 git_header_html
(undef, $expires);
4190 my $formats_nav = '';
4191 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4192 if (defined $file_name) {
4195 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4196 hash
=>$hash, file_name
=>$file_name)},
4201 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4202 hash
=>$hash, file_name
=>$file_name)},
4205 $cgi->a({-href
=> href
(action
=>"blob_plain",
4206 hash
=>$hash, file_name
=>$file_name)},
4209 $cgi->a({-href
=> href
(action
=>"blob",
4210 hash_base
=>"HEAD", file_name
=>$file_name)},
4214 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4216 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4217 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4219 print "<div class=\"page_nav\">\n" .
4220 "<br/><br/></div>\n" .
4221 "<div class=\"title\">$hash</div>\n";
4223 git_print_page_path
($file_name, "blob", $hash_base);
4224 print "<div class=\"page_body\">\n";
4225 if ($mimetype =~ m!^text/!) {
4227 while (my $line = <$fd>) {
4230 $line = untabify
($line);
4231 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4232 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4234 } elsif ($mimetype =~ m!^image/!) {
4235 print qq
!<img type
="$mimetype"!;
4237 print qq
! alt
="$file_name" title
="$file_name"!;
4240 href(action=>"blob_plain
", hash=>$hash,
4241 hash_base=>$hash_base, file_name=>$file_name) .
4245 or print "Reading blob failed.\n";
4251 if (!defined $hash_base) {
4252 $hash_base = "HEAD";
4254 if (!defined $hash) {
4255 if (defined $file_name) {
4256 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4262 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4263 or die_error
(undef, "Open git-ls-tree failed");
4264 my @entries = map { chomp; $_ } <$fd>;
4265 close $fd or die_error
(undef, "Reading tree failed");
4268 my $refs = git_get_references
();
4269 my $ref = format_ref_marker
($refs, $hash_base);
4272 my ($have_blame) = gitweb_check_feature
('blame');
4273 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4275 if (defined $file_name) {
4277 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4278 hash
=>$hash, file_name
=>$file_name)},
4280 $cgi->a({-href
=> href
(action
=>"tree",
4281 hash_base
=>"HEAD", file_name
=>$file_name)},
4284 my $snapshot_links = format_snapshot_links
($hash);
4285 if (defined $snapshot_links) {
4286 # FIXME: Should be available when we have no hash base as well.
4287 push @views_nav, $snapshot_links;
4289 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4290 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4293 print "<div class=\"page_nav\">\n";
4294 print "<br/><br/></div>\n";
4295 print "<div class=\"title\">$hash</div>\n";
4297 if (defined $file_name) {
4298 $basedir = $file_name;
4299 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4303 git_print_page_path
($file_name, 'tree', $hash_base);
4304 print "<div class=\"page_body\">\n";
4305 print "<table cellspacing=\"0\">\n";
4307 # '..' (top directory) link if possible
4308 if (defined $hash_base &&
4309 defined $file_name && $file_name =~ m![^/]+$!) {
4311 print "<tr class=\"dark\">\n";
4313 print "<tr class=\"light\">\n";
4317 my $up = $file_name;
4318 $up =~ s!/?[^/]+$!!;
4319 undef $up unless $up;
4320 # based on git_print_tree_entry
4321 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4322 print '<td class="list">';
4323 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4327 print "<td class=\"link\"></td>\n";
4331 foreach my $line (@entries) {
4332 my %t = parse_ls_tree_line
($line, -z
=> 1);
4335 print "<tr class=\"dark\">\n";
4337 print "<tr class=\"light\">\n";
4341 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4345 print "</table>\n" .
4351 my @supported_fmts = gitweb_check_feature
('snapshot');
4352 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4354 my $format = $cgi->param('sf');
4355 if (!@supported_fmts) {
4356 die_error
('403 Permission denied', "Permission denied");
4358 # default to first supported snapshot format
4359 $format ||= $supported_fmts[0];
4360 if ($format !~ m/^[a-z0-9]+$/) {
4361 die_error
(undef, "Invalid snapshot format parameter");
4362 } elsif (!exists($known_snapshot_formats{$format})) {
4363 die_error
(undef, "Unknown snapshot format");
4364 } elsif (!grep($_ eq $format, @supported_fmts)) {
4365 die_error
(undef, "Unsupported snapshot format");
4368 if (!defined $hash) {
4369 $hash = git_get_head_hash
($project);
4372 my $git_command = git_cmd_str
();
4373 my $name = $project;
4374 $name =~ s
,([^/])/*\
.git
$,$1,;
4375 $name = basename
($name);
4376 my $filename = to_utf8
($name);
4377 $name =~ s/\047/\047\\\047\047/g;
4379 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4380 $cmd = "$git_command archive " .
4381 "--format=$known_snapshot_formats{$format}{'format'} " .
4382 "--prefix=\'$name\'/ $hash";
4383 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4384 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4388 -type
=> $known_snapshot_formats{$format}{'type'},
4389 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4390 -status
=> '200 OK');
4392 open my $fd, "-|", $cmd
4393 or die_error
(undef, "Execute git-archive failed");
4394 binmode STDOUT
, ':raw';
4396 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4401 my $head = git_get_head_hash
($project);
4402 if (!defined $hash) {
4405 if (!defined $page) {
4408 my $refs = git_get_references
();
4410 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4412 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4415 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4418 my %co = parse_commit
($hash);
4420 git_print_header_div
('summary', $project);
4421 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4423 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4424 for (my $i = 0; $i <= $to; $i++) {
4425 my %co = %{$commitlist[$i]};
4427 my $commit = $co{'id'};
4428 my $ref = format_ref_marker
($refs, $commit);
4429 my %ad = parse_date
($co{'author_epoch'});
4430 git_print_header_div
('commit',
4431 "<span class=\"age\">$co{'age_string'}</span>" .
4432 esc_html
($co{'title'}) . $ref,
4434 print "<div class=\"title_text\">\n" .
4435 "<div class=\"log_link\">\n" .
4436 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4438 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4440 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4443 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4446 print "<div class=\"log_body\">\n";
4447 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4450 if ($#commitlist >= 100) {
4451 print "<div class=\"page_nav\">\n";
4452 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4453 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4460 $hash ||= $hash_base || "HEAD";
4461 my %co = parse_commit
($hash);
4463 die_error
(undef, "Unknown commit object");
4465 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4466 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4468 my $parent = $co{'parent'};
4469 my $parents = $co{'parents'}; # listref
4471 # we need to prepare $formats_nav before any parameter munging
4473 if (!defined $parent) {
4475 $formats_nav .= '(initial)';
4476 } elsif (@$parents == 1) {
4477 # single parent commit
4480 $cgi->a({-href
=> href
(action
=>"commit",
4482 esc_html
(substr($parent, 0, 7))) .
4489 $cgi->a({-href
=> href
(action
=>"commit",
4491 esc_html
(substr($_, 0, 7)));
4496 if (!defined $parent) {
4500 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4502 (@$parents <= 1 ? $parent : '-c'),
4504 or die_error
(undef, "Open git-diff-tree failed");
4505 @difftree = map { chomp; $_ } <$fd>;
4506 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4508 # non-textual hash id's can be cached
4510 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4513 my $refs = git_get_references
();
4514 my $ref = format_ref_marker
($refs, $co{'id'});
4516 git_header_html
(undef, $expires);
4517 git_print_page_nav
('commit', '',
4518 $hash, $co{'tree'}, $hash,
4521 if (defined $co{'parent'}) {
4522 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4524 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4526 print "<div class=\"title_text\">\n" .
4527 "<table cellspacing=\"0\">\n";
4528 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4530 "<td></td><td> $ad{'rfc2822'}";
4531 if ($ad{'hour_local'} < 6) {
4532 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4533 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4535 printf(" (%02d:%02d %s)",
4536 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4540 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4541 print "<tr><td></td><td> $cd{'rfc2822'}" .
4542 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4544 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4547 "<td class=\"sha1\">" .
4548 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4549 class => "list"}, $co{'tree'}) .
4551 "<td class=\"link\">" .
4552 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4554 my $snapshot_links = format_snapshot_links
($hash);
4555 if (defined $snapshot_links) {
4556 print " | " . $snapshot_links;
4561 foreach my $par (@$parents) {
4564 "<td class=\"sha1\">" .
4565 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4566 class => "list"}, $par) .
4568 "<td class=\"link\">" .
4569 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4571 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4578 print "<div class=\"page_body\">\n";
4579 git_print_log
($co{'comment'});
4582 git_difftree_body
(\
@difftree, $hash, @$parents);
4588 # object is defined by:
4589 # - hash or hash_base alone
4590 # - hash_base and file_name
4593 # - hash or hash_base alone
4594 if ($hash || ($hash_base && !defined $file_name)) {
4595 my $object_id = $hash || $hash_base;
4597 my $git_command = git_cmd_str
();
4598 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4599 or die_error
('404 Not Found', "Object does not exist");
4603 or die_error
('404 Not Found', "Object does not exist");
4605 # - hash_base and file_name
4606 } elsif ($hash_base && defined $file_name) {
4607 $file_name =~ s
,/+$,,;
4609 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4610 or die_error
('404 Not Found', "Base object does not exist");
4612 # here errors should not hapen
4613 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4614 or die_error
(undef, "Open git-ls-tree failed");
4618 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4619 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4620 die_error
('404 Not Found', "File or directory for given base does not exist");
4625 die_error
('404 Not Found', "Not enough information to find object");
4628 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4629 hash
=>$hash, hash_base
=>$hash_base,
4630 file_name
=>$file_name),
4631 -status
=> '302 Found');
4635 my $format = shift || 'html';
4642 # preparing $fd and %diffinfo for git_patchset_body
4644 if (defined $hash_base && defined $hash_parent_base) {
4645 if (defined $file_name) {
4647 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4648 $hash_parent_base, $hash_base,
4649 "--", (defined $file_parent ? $file_parent : ()), $file_name
4650 or die_error
(undef, "Open git-diff-tree failed");
4651 @difftree = map { chomp; $_ } <$fd>;
4653 or die_error
(undef, "Reading git-diff-tree failed");
4655 or die_error
('404 Not Found', "Blob diff not found");
4657 } elsif (defined $hash &&
4658 $hash =~ /[0-9a-fA-F]{40}/) {
4659 # try to find filename from $hash
4661 # read filtered raw output
4662 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4663 $hash_parent_base, $hash_base, "--"
4664 or die_error
(undef, "Open git-diff-tree failed");
4666 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4668 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4669 map { chomp; $_ } <$fd>;
4671 or die_error
(undef, "Reading git-diff-tree failed");
4673 or die_error
('404 Not Found', "Blob diff not found");
4676 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4679 if (@difftree > 1) {
4680 die_error
('404 Not Found', "Ambiguous blob diff specification");
4683 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4684 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4685 $file_name ||= $diffinfo{'to_file'};
4687 $hash_parent ||= $diffinfo{'from_id'};
4688 $hash ||= $diffinfo{'to_id'};
4690 # non-textual hash id's can be cached
4691 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4692 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4697 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4698 '-p', ($format eq 'html' ? "--full-index" : ()),
4699 $hash_parent_base, $hash_base,
4700 "--", (defined $file_parent ? $file_parent : ()), $file_name
4701 or die_error
(undef, "Open git-diff-tree failed");
4704 # old/legacy style URI
4705 if (!%diffinfo && # if new style URI failed
4706 defined $hash && defined $hash_parent) {
4707 # fake git-diff-tree raw output
4708 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4709 $diffinfo{'from_id'} = $hash_parent;
4710 $diffinfo{'to_id'} = $hash;
4711 if (defined $file_name) {
4712 if (defined $file_parent) {
4713 $diffinfo{'status'} = '2';
4714 $diffinfo{'from_file'} = $file_parent;
4715 $diffinfo{'to_file'} = $file_name;
4716 } else { # assume not renamed
4717 $diffinfo{'status'} = '1';
4718 $diffinfo{'from_file'} = $file_name;
4719 $diffinfo{'to_file'} = $file_name;
4721 } else { # no filename given
4722 $diffinfo{'status'} = '2';
4723 $diffinfo{'from_file'} = $hash_parent;
4724 $diffinfo{'to_file'} = $hash;
4727 # non-textual hash id's can be cached
4728 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4729 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4734 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4735 '-p', ($format eq 'html' ? "--full-index" : ()),
4736 $hash_parent, $hash, "--"
4737 or die_error
(undef, "Open git-diff failed");
4739 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4744 if ($format eq 'html') {
4746 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4747 hash
=>$hash, hash_parent
=>$hash_parent,
4748 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4749 file_name
=>$file_name, file_parent
=>$file_parent)},
4751 git_header_html
(undef, $expires);
4752 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4753 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4754 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4756 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4757 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4759 if (defined $file_name) {
4760 git_print_page_path
($file_name, "blob", $hash_base);
4762 print "<div class=\"page_path\"></div>\n";
4765 } elsif ($format eq 'plain') {
4767 -type
=> 'text/plain',
4768 -charset
=> 'utf-8',
4769 -expires
=> $expires,
4770 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4772 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4775 die_error
(undef, "Unknown blobdiff format");
4779 if ($format eq 'html') {
4780 print "<div class=\"page_body\">\n";
4782 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4785 print "</div>\n"; # class="page_body"
4789 while (my $line = <$fd>) {
4790 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4791 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4795 last if $line =~ m!^\+\+\+!;
4803 sub git_blobdiff_plain
{
4804 git_blobdiff
('plain');
4807 sub git_commitdiff
{
4808 my $format = shift || 'html';
4809 $hash ||= $hash_base || "HEAD";
4810 my %co = parse_commit
($hash);
4812 die_error
(undef, "Unknown commit object");
4815 # choose format for commitdiff for merge
4816 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4817 $hash_parent = '--cc';
4819 # we need to prepare $formats_nav before almost any parameter munging
4821 if ($format eq 'html') {
4823 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4824 hash
=>$hash, hash_parent
=>$hash_parent)},
4827 if (defined $hash_parent &&
4828 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4829 # commitdiff with two commits given
4830 my $hash_parent_short = $hash_parent;
4831 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4832 $hash_parent_short = substr($hash_parent, 0, 7);
4836 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4837 if ($co{'parents'}[$i] eq $hash_parent) {
4838 $formats_nav .= ' parent ' . ($i+1);
4842 $formats_nav .= ': ' .
4843 $cgi->a({-href
=> href
(action
=>"commitdiff",
4844 hash
=>$hash_parent)},
4845 esc_html
($hash_parent_short)) .
4847 } elsif (!$co{'parent'}) {
4849 $formats_nav .= ' (initial)';
4850 } elsif (scalar @{$co{'parents'}} == 1) {
4851 # single parent commit
4854 $cgi->a({-href
=> href
(action
=>"commitdiff",
4855 hash
=>$co{'parent'})},
4856 esc_html
(substr($co{'parent'}, 0, 7))) .
4860 if ($hash_parent eq '--cc') {
4861 $formats_nav .= ' | ' .
4862 $cgi->a({-href
=> href
(action
=>"commitdiff",
4863 hash
=>$hash, hash_parent
=>'-c')},
4865 } else { # $hash_parent eq '-c'
4866 $formats_nav .= ' | ' .
4867 $cgi->a({-href
=> href
(action
=>"commitdiff",
4868 hash
=>$hash, hash_parent
=>'--cc')},
4874 $cgi->a({-href
=> href
(action
=>"commitdiff",
4876 esc_html
(substr($_, 0, 7)));
4877 } @{$co{'parents'}} ) .
4882 my $hash_parent_param = $hash_parent;
4883 if (!defined $hash_parent_param) {
4884 # --cc for multiple parents, --root for parentless
4885 $hash_parent_param =
4886 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4892 if ($format eq 'html') {
4893 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4894 "--no-commit-id", "--patch-with-raw", "--full-index",
4895 $hash_parent_param, $hash, "--"
4896 or die_error
(undef, "Open git-diff-tree failed");
4898 while (my $line = <$fd>) {
4900 # empty line ends raw part of diff-tree output
4902 push @difftree, scalar parse_difftree_raw_line
($line);
4905 } elsif ($format eq 'plain') {
4906 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4907 '-p', $hash_parent_param, $hash, "--"
4908 or die_error
(undef, "Open git-diff-tree failed");
4911 die_error
(undef, "Unknown commitdiff format");
4914 # non-textual hash id's can be cached
4916 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4920 # write commit message
4921 if ($format eq 'html') {
4922 my $refs = git_get_references
();
4923 my $ref = format_ref_marker
($refs, $co{'id'});
4925 git_header_html
(undef, $expires);
4926 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4927 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4928 git_print_authorship
(\
%co);
4929 print "<div class=\"page_body\">\n";
4930 if (@{$co{'comment'}} > 1) {
4931 print "<div class=\"log\">\n";
4932 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4933 print "</div>\n"; # class="log"
4936 } elsif ($format eq 'plain') {
4937 my $refs = git_get_references
("tags");
4938 my $tagname = git_get_rev_name_tags
($hash);
4939 my $filename = basename
($project) . "-$hash.patch";
4942 -type
=> 'text/plain',
4943 -charset
=> 'utf-8',
4944 -expires
=> $expires,
4945 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4946 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4949 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4950 Subject: $co{'title'}
4952 print "X-Git-Tag: $tagname\n" if $tagname;
4953 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4955 foreach my $line (@{$co{'comment'}}) {
4962 if ($format eq 'html') {
4963 my $use_parents = !defined $hash_parent ||
4964 $hash_parent eq '-c' || $hash_parent eq '--cc';
4965 git_difftree_body
(\
@difftree, $hash,
4966 $use_parents ? @{$co{'parents'}} : $hash_parent);
4969 git_patchset_body
($fd, \
@difftree, $hash,
4970 $use_parents ? @{$co{'parents'}} : $hash_parent);
4972 print "</div>\n"; # class="page_body"
4975 } elsif ($format eq 'plain') {
4979 or print "Reading git-diff-tree failed\n";
4983 sub git_commitdiff_plain
{
4984 git_commitdiff
('plain');
4988 if (!defined $hash_base) {
4989 $hash_base = git_get_head_hash
($project);
4991 if (!defined $page) {
4995 my %co = parse_commit
($hash_base);
4997 die_error
(undef, "Unknown commit object");
5000 my $refs = git_get_references
();
5001 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5003 if (!defined $hash && defined $file_name) {
5004 $hash = git_get_hash_by_path
($hash_base, $file_name);
5006 if (defined $hash) {
5007 $ftype = git_get_type
($hash);
5010 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5012 my $paging_nav = '';
5015 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5016 file_name
=>$file_name)},
5018 $paging_nav .= " ⋅ " .
5019 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5020 file_name
=>$file_name, page
=>$page-1),
5021 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5023 $paging_nav .= "first";
5024 $paging_nav .= " ⋅ prev";
5026 if ($#commitlist >= 100) {
5027 $paging_nav .= " ⋅ " .
5028 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5029 file_name
=>$file_name, page
=>$page+1),
5030 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5032 $paging_nav .= " ⋅ next";
5035 if ($#commitlist >= 100) {
5037 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5038 file_name
=>$file_name, page
=>$page+1),
5039 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5043 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5044 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5045 git_print_page_path
($file_name, $ftype, $hash_base);
5047 git_history_body
(\
@commitlist, 0, 99,
5048 $refs, $hash_base, $ftype, $next_link);
5054 my ($have_search) = gitweb_check_feature
('search');
5055 if (!$have_search) {
5056 die_error
('403 Permission denied', "Permission denied");
5058 if (!defined $searchtext) {
5059 die_error
(undef, "Text field empty");
5061 if (!defined $hash) {
5062 $hash = git_get_head_hash
($project);
5064 my %co = parse_commit
($hash);
5066 die_error
(undef, "Unknown commit object");
5068 if (!defined $page) {
5072 $searchtype ||= 'commit';
5073 if ($searchtype eq 'pickaxe') {
5074 # pickaxe may take all resources of your box and run for several minutes
5075 # with every query - so decide by yourself how public you make this feature
5076 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5077 if (!$have_pickaxe) {
5078 die_error
('403 Permission denied', "Permission denied");
5081 if ($searchtype eq 'grep') {
5082 my ($have_grep) = gitweb_check_feature
('grep');
5084 die_error
('403 Permission denied', "Permission denied");
5090 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5092 if ($searchtype eq 'commit') {
5093 $greptype = "--grep=";
5094 } elsif ($searchtype eq 'author') {
5095 $greptype = "--author=";
5096 } elsif ($searchtype eq 'committer') {
5097 $greptype = "--committer=";
5099 $greptype .= $search_regexp;
5100 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5102 my $paging_nav = '';
5105 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5106 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5108 $paging_nav .= " ⋅ " .
5109 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5110 searchtext
=>$searchtext, searchtype
=>$searchtype,
5112 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5114 $paging_nav .= "first";
5115 $paging_nav .= " ⋅ prev";
5117 if ($#commitlist >= 100) {
5118 $paging_nav .= " ⋅ " .
5119 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5120 searchtext
=>$searchtext, searchtype
=>$searchtype,
5122 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5124 $paging_nav .= " ⋅ next";
5127 if ($#commitlist >= 100) {
5129 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5130 searchtext
=>$searchtext, searchtype
=>$searchtype,
5132 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5135 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5136 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5137 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5140 if ($searchtype eq 'pickaxe') {
5141 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5142 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5144 print "<table cellspacing=\"0\">\n";
5147 my $git_command = git_cmd_str
();
5148 my $searchqtext = $searchtext;
5149 $searchqtext =~ s/'/'\\''/;
5150 open my $fd, "-|", "$git_command rev-list $hash | " .
5151 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5154 while (my $line = <$fd>) {
5155 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5158 $set{'from_id'} = $3;
5160 $set{'id'} = $set{'to_id'};
5161 if ($set{'id'} =~ m/0{40}/) {
5162 $set{'id'} = $set{'from_id'};
5164 if ($set{'id'} =~ m/0{40}/) {
5168 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5171 print "<tr class=\"dark\">\n";
5173 print "<tr class=\"light\">\n";
5176 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5177 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5178 "<td><i>" . $author . "</i></td>\n" .
5180 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5181 -class => "list subject"},
5182 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5183 while (my $setref = shift @files) {
5185 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5186 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5188 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5192 "<td class=\"link\">" .
5193 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5195 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5199 %co = parse_commit
($1);
5207 if ($searchtype eq 'grep') {
5208 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5209 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5211 print "<table cellspacing=\"0\">\n";
5215 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5217 while (my $line = <$fd>) {
5219 my ($file, $lno, $ltext, $binary);
5220 last if ($matches++ > 1000);
5221 if ($line =~ /^Binary file (.+) matches$/) {
5225 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5227 if ($file ne $lastfile) {
5228 $lastfile and print "</td></tr>\n";
5230 print "<tr class=\"dark\">\n";
5232 print "<tr class=\"light\">\n";
5234 print "<td class=\"list\">".
5235 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5236 file_name
=>"$file"),
5237 -class => "list"}, esc_path
($file));
5238 print "</td><td>\n";
5242 print "<div class=\"binary\">Binary file</div>\n";
5244 $ltext = untabify
($ltext);
5245 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5246 $ltext = esc_html
($1, -nbsp
=>1);
5247 $ltext .= '<span class="match">';
5248 $ltext .= esc_html
($2, -nbsp
=>1);
5249 $ltext .= '</span>';
5250 $ltext .= esc_html
($3, -nbsp
=>1);
5252 $ltext = esc_html
($ltext, -nbsp
=>1);
5254 print "<div class=\"pre\">" .
5255 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5256 file_name
=>"$file").'#l'.$lno,
5257 -class => "linenr"}, sprintf('%4i', $lno))
5258 . ' ' . $ltext . "</div>\n";
5262 print "</td></tr>\n";
5263 if ($matches > 1000) {
5264 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5267 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5276 sub git_search_help
{
5278 git_print_page_nav
('','', $hash,$hash,$hash);
5281 <dt><b>commit</b></dt>
5282 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5284 my ($have_grep) = gitweb_check_feature
('grep');
5287 <dt><b>grep</b></dt>
5288 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5289 a different one) are searched for the given
5290 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5291 (POSIX extended) and the matches are listed. On large
5292 trees, this search can take a while and put some strain on the server, so please use it with
5293 some consideration.</dd>
5297 <dt><b>author</b></dt>
5298 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5299 <dt><b>committer</b></dt>
5300 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5302 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5303 if ($have_pickaxe) {
5305 <dt><b>pickaxe</b></dt>
5306 <dd>All commits that caused the string to appear or disappear from any file (changes that
5307 added, removed or "modified" the string) will be listed. This search can take a while and
5308 takes a lot of strain on the server, so please use it wisely.</dd>
5316 my $head = git_get_head_hash
($project);
5317 if (!defined $hash) {
5320 if (!defined $page) {
5323 my $refs = git_get_references
();
5325 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5327 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5329 if ($#commitlist >= 100) {
5331 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5332 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5336 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5337 git_print_header_div
('summary', $project);
5339 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5344 ## ......................................................................
5345 ## feeds (RSS, Atom; OPML)
5348 my $format = shift || 'atom';
5349 my ($have_blame) = gitweb_check_feature
('blame');
5351 # Atom: http://www.atomenabled.org/developers/syndication/
5352 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5353 if ($format ne 'rss' && $format ne 'atom') {
5354 die_error
(undef, "Unknown web feed format");
5357 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5358 my $head = $hash || 'HEAD';
5359 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5363 my $content_type = "application/$format+xml";
5364 if (defined $cgi->http('HTTP_ACCEPT') &&
5365 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5366 # browser (feed reader) prefers text/xml
5367 $content_type = 'text/xml';
5369 if (defined($commitlist[0])) {
5370 %latest_commit = %{$commitlist[0]};
5371 %latest_date = parse_date
($latest_commit{'author_epoch'});
5373 -type
=> $content_type,
5374 -charset
=> 'utf-8',
5375 -last_modified
=> $latest_date{'rfc2822'});
5378 -type
=> $content_type,
5379 -charset
=> 'utf-8');
5382 # Optimization: skip generating the body if client asks only
5383 # for Last-Modified date.
5384 return if ($cgi->request_method() eq 'HEAD');
5387 my $title = "$site_name - $project/$action";
5388 my $feed_type = 'log';
5389 if (defined $hash) {
5390 $title .= " - '$hash'";
5391 $feed_type = 'branch log';
5392 if (defined $file_name) {
5393 $title .= " :: $file_name";
5394 $feed_type = 'history';
5396 } elsif (defined $file_name) {
5397 $title .= " - $file_name";
5398 $feed_type = 'history';
5400 $title .= " $feed_type";
5401 my $descr = git_get_project_description
($project);
5402 if (defined $descr) {
5403 $descr = esc_html
($descr);
5405 $descr = "$project " .
5406 ($format eq 'rss' ? 'RSS' : 'Atom') .
5409 my $owner = git_get_project_owner
($project);
5410 $owner = esc_html
($owner);
5414 if (defined $file_name) {
5415 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5416 } elsif (defined $hash) {
5417 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5419 $alt_url = href
(-full
=>1, action
=>"summary");
5421 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5422 if ($format eq 'rss') {
5424 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5427 print "<title>$title</title>\n" .
5428 "<link>$alt_url</link>\n" .
5429 "<description>$descr</description>\n" .
5430 "<language>en</language>\n";
5431 } elsif ($format eq 'atom') {
5433 <feed xmlns="http://www.w3.org/2005/Atom">
5435 print "<title>$title</title>\n" .
5436 "<subtitle>$descr</subtitle>\n" .
5437 '<link rel="alternate" type="text/html" href="' .
5438 $alt_url . '" />' . "\n" .
5439 '<link rel="self" type="' . $content_type . '" href="' .
5440 $cgi->self_url() . '" />' . "\n" .
5441 "<id>" . href
(-full
=>1) . "</id>\n" .
5442 # use project owner for feed author
5443 "<author><name>$owner</name></author>\n";
5444 if (defined $favicon) {
5445 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5447 if (defined $logo_url) {
5448 # not twice as wide as tall: 72 x 27 pixels
5449 print "<logo>" . esc_url
($logo) . "</logo>\n";
5451 if (! %latest_date) {
5452 # dummy date to keep the feed valid until commits trickle in:
5453 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5455 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5460 for (my $i = 0; $i <= $#commitlist; $i++) {
5461 my %co = %{$commitlist[$i]};
5462 my $commit = $co{'id'};
5463 # we read 150, we always show 30 and the ones more recent than 48 hours
5464 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5467 my %cd = parse_date
($co{'author_epoch'});
5469 # get list of changed files
5470 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5471 $co{'parent'} || "--root",
5472 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5474 my @difftree = map { chomp; $_ } <$fd>;
5478 # print element (entry, item)
5479 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5480 if ($format eq 'rss') {
5482 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5483 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5484 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5485 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5486 "<link>$co_url</link>\n" .
5487 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5488 "<content:encoded>" .
5490 } elsif ($format eq 'atom') {
5492 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5493 "<updated>$cd{'iso-8601'}</updated>\n" .
5495 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5496 if ($co{'author_email'}) {
5497 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5499 print "</author>\n" .
5500 # use committer for contributor
5502 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5503 if ($co{'committer_email'}) {
5504 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5506 print "</contributor>\n" .
5507 "<published>$cd{'iso-8601'}</published>\n" .
5508 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5509 "<id>$co_url</id>\n" .
5510 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5511 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5513 my $comment = $co{'comment'};
5515 foreach my $line (@$comment) {
5516 $line = esc_html
($line);
5519 print "</pre><ul>\n";
5520 foreach my $difftree_line (@difftree) {
5521 my %difftree = parse_difftree_raw_line
($difftree_line);
5522 next if !$difftree{'from_id'};
5524 my $file = $difftree{'file'} || $difftree{'to_file'};
5528 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5529 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5530 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5531 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5532 -title
=> "diff"}, 'D');
5534 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5535 file_name
=>$file, hash_base
=>$commit),
5536 -title
=> "blame"}, 'B');
5538 # if this is not a feed of a file history
5539 if (!defined $file_name || $file_name ne $file) {
5540 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5541 file_name
=>$file, hash
=>$commit),
5542 -title
=> "history"}, 'H');
5544 $file = esc_path
($file);
5548 if ($format eq 'rss') {
5549 print "</ul>]]>\n" .
5550 "</content:encoded>\n" .
5552 } elsif ($format eq 'atom') {
5553 print "</ul>\n</div>\n" .
5560 if ($format eq 'rss') {
5561 print "</channel>\n</rss>\n";
5562 } elsif ($format eq 'atom') {
5576 my @list = git_get_projects_list
();
5578 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5580 <?xml version="1.0" encoding="utf-8"?>
5581 <opml version="1.0">
5583 <title>$site_name OPML Export</title>
5586 <outline text="git RSS feeds">
5589 foreach my $pr (@list) {
5591 my $head = git_get_head_hash
($proj{'path'});
5592 if (!defined $head) {
5595 $git_dir = "$projectroot/$proj{'path'}";
5596 my %co = parse_commit
($head);
5601 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5602 my $rss = "$my_url?p=$proj{'path'};a=rss";
5603 my $html = "$my_url?p=$proj{'path'};a=summary";
5604 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";