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;
64 # URI of GIT logo (72x27 size)
65 our $logo = "++GITWEB_LOGO++";
66 # URI of GIT favicon, assumed to be image/png type
67 our $favicon = "++GITWEB_FAVICON++";
69 # URI and label (title) of GIT logo link
70 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
71 #our $logo_label = "git documentation";
72 our $logo_url = "http://git.or.cz/";
73 our $logo_label = "git homepage";
75 # source of projects list
76 our $projects_list = "++GITWEB_LIST++";
78 # the width (in characters) of the projects list "Description" column
79 our $projects_list_description_width = 25;
81 # default order of projects list
82 # valid values are none, project, descr, owner, and age
83 our $default_projects_order = "project";
85 # show repository only if this file exists
86 # (only effective if this variable evaluates to true)
87 our $export_ok = "++GITWEB_EXPORT_OK++";
89 # only allow viewing of repositories also shown on the overview page
90 our $strict_export = "++GITWEB_STRICT_EXPORT++";
92 # list of git base URLs used for URL to where fetch project from,
93 # i.e. full URL is "$git_base_url/$project"
94 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
96 # default blob_plain mimetype and default charset for text/plain blob
97 our $default_blob_plain_mimetype = 'text/plain';
98 our $default_text_plain_charset = undef;
100 # file to use for guessing MIME types before trying /etc/mime.types
101 # (relative to the current git repository)
102 our $mimetypes_file = undef;
104 # assume this charset if line contains non-UTF-8 characters;
105 # it should be valid encoding (see Encoding::Supported(3pm) for list),
106 # for which encoding all byte sequences are valid, for example
107 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
108 # could be even 'utf-8' for the old behavior)
109 our $fallback_encoding = 'latin1';
111 # rename detection options for git-diff and git-diff-tree
112 # - default is '-M', with the cost proportional to
113 # (number of removed files) * (number of new files).
114 # - more costly is '-C' (which implies '-M'), with the cost proportional to
115 # (number of changed files + number of removed files) * (number of new files)
116 # - even more costly is '-C', '--find-copies-harder' with cost
117 # (number of files in the original tree) * (number of new files)
118 # - one might want to include '-B' option, e.g. '-B', '-M'
119 our @diff_opts = ('-M'); # taken from git_commit
121 # information about snapshot formats that gitweb is capable of serving
122 our %known_snapshot_formats = (
124 # 'display' => display name,
125 # 'type' => mime type,
126 # 'suffix' => filename suffix,
127 # 'format' => --format for git-archive,
128 # 'compressor' => [compressor command and arguments]
129 # (array reference, optional)}
132 'display' => 'tar.gz',
133 'type' => 'application/x-gzip',
134 'suffix' => '.tar.gz',
136 'compressor' => ['gzip']},
139 'display' => 'tar.bz2',
140 'type' => 'application/x-bzip2',
141 'suffix' => '.tar.bz2',
143 'compressor' => ['bzip2']},
147 'type' => 'application/x-zip',
152 # Aliases so we understand old gitweb.snapshot values in repository
154 our %known_snapshot_format_aliases = (
158 # backward compatibility: legacy gitweb config support
159 'x-gzip' => undef, 'gz' => undef,
160 'x-bzip2' => undef, 'bz2' => undef,
161 'x-zip' => undef, '' => undef,
164 # You define site-wide feature defaults here; override them with
165 # $GITWEB_CONFIG as necessary.
168 # 'sub' => feature-sub (subroutine),
169 # 'override' => allow-override (boolean),
170 # 'default' => [ default options...] (array reference)}
172 # if feature is overridable (it means that allow-override has true value),
173 # then feature-sub will be called with default options as parameters;
174 # return value of feature-sub indicates if to enable specified feature
176 # if there is no 'sub' key (no feature-sub), then feature cannot be
179 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
181 # Enable the 'blame' blob view, showing the last commit that modified
182 # each line in the file. This can be very CPU-intensive.
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'blame'}{'default'} = [1];
186 # To have project specific config enable override in $GITWEB_CONFIG
187 # $feature{'blame'}{'override'} = 1;
188 # and in project config gitweb.blame = 0|1;
190 'sub' => \&feature_blame,
194 # Enable the 'snapshot' link, providing a compressed archive of any
195 # tree. This can potentially generate high traffic if you have large
198 # Value is a list of formats defined in %known_snapshot_formats that
200 # To disable system wide have in $GITWEB_CONFIG
201 # $feature{'snapshot'}{'default'} = [];
202 # To have project specific config enable override in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'override'} = 1;
204 # and in project config, a comma-separated list of formats or "none"
205 # to disable. Example: gitweb.snapshot = tbz2,zip;
207 'sub' => \&feature_snapshot,
209 'default' => ['tgz']},
211 # Enable text search, which will list the commits which match author,
212 # committer or commit text to a given string. Enabled by default.
213 # Project specific override is not supported.
218 # Enable grep search, which will list the files in currently selected
219 # tree containing the given string. Enabled by default. This can be
220 # potentially CPU-intensive, of course.
222 # To enable system wide have in $GITWEB_CONFIG
223 # $feature{'grep'}{'default'} = [1];
224 # To have project specific config enable override in $GITWEB_CONFIG
225 # $feature{'grep'}{'override'} = 1;
226 # and in project config gitweb.grep = 0|1;
231 # Enable the pickaxe search, which will list the commits that modified
232 # a given string in a file. This can be practical and quite faster
233 # alternative to 'blame', but still potentially CPU-intensive.
235 # To enable system wide have in $GITWEB_CONFIG
236 # $feature{'pickaxe'}{'default'} = [1];
237 # To have project specific config enable override in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'override'} = 1;
239 # and in project config gitweb.pickaxe = 0|1;
241 'sub' => \&feature_pickaxe,
245 # Make gitweb use an alternative format of the URLs which can be
246 # more readable and natural-looking: project name is embedded
247 # directly in the path and the query string contains other
248 # auxiliary information. All gitweb installations recognize
249 # URL in either format; this configures in which formats gitweb
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'pathinfo'}{'default'} = [1];
254 # Project specific override is not supported.
256 # Note that you will need to change the default location of CSS,
257 # favicon, logo and possibly other files to an absolute URL. Also,
258 # if gitweb.cgi serves as your indexfile, you will need to force
259 # $my_uri to contain the script name in your $GITWEB_CONFIG.
264 # Make gitweb consider projects in project root subdirectories
265 # to be forks of existing projects. Given project $projname.git,
266 # projects matching $projname/*.git will not be shown in the main
267 # projects list, instead a '+' mark will be added to $projname
268 # there and a 'forks' view will be enabled for the project, listing
269 # all the forks. If project list is taken from a file, forks have
270 # to be listed after the main project.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'forks'}{'default'} = [1];
274 # Project specific override is not supported.
280 sub gitweb_check_feature {
282 return unless exists $feature{$name};
283 my ($sub, $override, @defaults) = (
284 $feature{$name}{'sub'},
285 $feature{$name}{'override'},
286 @{$feature{$name}{'default'}});
287 if (!$override) { return @defaults; }
289 warn "feature $name is not overrideable";
292 return $sub->(@defaults);
296 my ($val) = git_get_project_config('blame', '--bool');
298 if ($val eq 'true') {
300 } elsif ($val eq 'false') {
307 sub feature_snapshot {
310 my ($val) = git_get_project_config('snapshot');
313 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
320 my ($val) = git_get_project_config('grep', '--bool');
322 if ($val eq 'true') {
324 } elsif ($val eq 'false') {
331 sub feature_pickaxe {
332 my ($val) = git_get_project_config('pickaxe', '--bool');
334 if ($val eq 'true') {
336 } elsif ($val eq 'false') {
343 # checking HEAD file with -e is fragile if the repository was
344 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
346 sub check_head_link {
348 my $headfile = "$dir/HEAD";
349 return ((-e $headfile) ||
350 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
353 sub check_export_ok {
355 return (check_head_link($dir) &&
356 (!$export_ok || -e "$dir/$export_ok"));
359 # process alternate names for backward compatibility
360 # filter out unsupported (unknown) snapshot formats
361 sub filter_snapshot_fmts {
365 exists $known_snapshot_format_aliases{$_} ?
366 $known_snapshot_format_aliases{$_} : $_} @fmts;
367 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
371 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
372 do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
374 # version of the core git binary
375 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
377 $projects_list ||= $projectroot;
379 # ======================================================================
380 # input validation and dispatch
381 our $action = $cgi->param('a');
382 if (defined $action) {
383 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
384 die_error(undef, "Invalid action parameter");
388 # parameters which are pathnames
389 our $project = $cgi->param('p');
390 if (defined $project) {
391 if (!validate_pathname($project) ||
392 !(-d "$projectroot/$project") ||
393 !check_head_link("$projectroot/$project") ||
394 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
395 ($strict_export && !project_in_list($project))) {
397 die_error(undef, "No such project");
401 our $file_name = $cgi->param('f');
402 if (defined $file_name) {
403 if (!validate_pathname($file_name)) {
404 die_error(undef, "Invalid file parameter");
408 our $file_parent = $cgi->param('fp');
409 if (defined $file_parent) {
410 if (!validate_pathname($file_parent)) {
411 die_error(undef, "Invalid file parent parameter");
415 # parameters which are refnames
416 our $hash = $cgi->param('h');
418 if (!validate_refname($hash)) {
419 die_error(undef, "Invalid hash parameter");
423 our $hash_parent = $cgi->param('hp');
424 if (defined $hash_parent) {
425 if (!validate_refname($hash_parent)) {
426 die_error(undef, "Invalid hash parent parameter");
430 our $hash_base = $cgi->param('hb');
431 if (defined $hash_base) {
432 if (!validate_refname($hash_base)) {
433 die_error(undef, "Invalid hash base parameter");
437 my %allowed_options = (
438 "--no-merges" => [ qw(rss atom log shortlog history) ],
441 our @extra_options = $cgi->param('opt');
442 if (defined @extra_options) {
443 foreach my $opt (@extra_options) {
444 if (not exists $allowed_options{$opt}) {
445 die_error(undef, "Invalid option parameter");
447 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
448 die_error(undef, "Invalid option parameter for this action");
453 our $hash_parent_base = $cgi->param('hpb');
454 if (defined $hash_parent_base) {
455 if (!validate_refname($hash_parent_base)) {
456 die_error(undef, "Invalid hash parent base parameter");
461 our $page = $cgi->param('pg');
463 if ($page =~ m/[^0-9]/) {
464 die_error(undef, "Invalid page parameter");
468 our $searchtype = $cgi->param('st');
469 if (defined $searchtype) {
470 if ($searchtype =~ m/[^a-z]/) {
471 die_error(undef, "Invalid searchtype parameter");
475 our $searchtext = $cgi->param('s');
477 if (defined $searchtext) {
478 if (length($searchtext) < 2) {
479 die_error(undef, "At least two characters are required for search parameter");
481 $search_regexp = quotemeta $searchtext;
484 # now read PATH_INFO and use it as alternative to parameters
485 sub evaluate_path_info {
486 return if defined $project;
487 my $path_info = $ENV{"PATH_INFO"};
488 return if !$path_info;
489 $path_info =~ s,^/+,,;
490 return if !$path_info;
491 # find which part of PATH_INFO is project
492 $project = $path_info;
494 while ($project && !check_head_link("$projectroot/$project")) {
495 $project =~ s,/*[^/]*$,,;
498 $project = validate_pathname($project);
500 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
501 ($strict_export && !project_in_list($project))) {
505 # do not change any parameters if an action is given using the query string
507 $path_info =~ s,^$project/*,,;
508 my ($refname, $pathname) = split(/:/, $path_info, 2);
509 if (defined $pathname) {
510 # we got "project.git/branch:filename" or "project.git/branch:dir/"
511 # we could use git_get_type(branch:pathname), but it needs $git_dir
512 $pathname =~ s,^/+,,;
513 if (!$pathname || substr($pathname, -1) eq "/") {
517 $action ||= "blob_plain";
519 $hash_base ||= validate_refname($refname);
520 $file_name ||= validate_pathname($pathname);
521 } elsif (defined $refname) {
522 # we got "project.git/branch"
523 $action ||= "shortlog";
524 $hash ||= validate_refname($refname);
527 evaluate_path_info();
529 # path to the current git repository
531 $git_dir = "$projectroot/$project" if $project;
535 "blame" => \&git_blame2,
536 "blobdiff" => \&git_blobdiff,
537 "blobdiff_plain" => \&git_blobdiff_plain,
538 "blob" => \&git_blob,
539 "blob_plain" => \&git_blob_plain,
540 "commitdiff" => \&git_commitdiff,
541 "commitdiff_plain" => \&git_commitdiff_plain,
542 "commit" => \&git_commit,
543 "forks" => \&git_forks,
544 "heads" => \&git_heads,
545 "history" => \&git_history,
548 "atom" => \&git_atom,
549 "search" => \&git_search,
550 "search_help" => \&git_search_help,
551 "shortlog" => \&git_shortlog,
552 "summary" => \&git_summary,
554 "tags" => \&git_tags,
555 "tree" => \&git_tree,
556 "snapshot" => \&git_snapshot,
557 "object" => \&git_object,
558 # those below don't need $project
559 "opml" => \&git_opml,
560 "project_list" => \&git_project_list,
561 "project_index" => \&git_project_index,
564 if (!defined $action) {
566 $action = git_get_type($hash);
567 } elsif (defined $hash_base && defined $file_name) {
568 $action = git_get_type("$hash_base:$file_name");
569 } elsif (defined $project) {
572 $action = 'project_list';
575 if (!defined($actions{$action})) {
576 die_error(undef, "Unknown action");
578 if ($action !~ m/^(opml|project_list|project_index)$/ &&
580 die_error(undef, "Project needed");
582 $actions{$action}->();
585 ## ======================================================================
590 # default is to use -absolute url() i.e. $my_uri
591 my $href = $params{-full} ? $my_url : $my_uri;
593 # XXX: Warning: If you touch this, check the search form for updating,
604 hash_parent_base => "hpb",
609 snapshot_format => "sf",
610 extra_options => "opt",
612 my %mapping = @mapping;
614 if ($params{-replay}) {
615 while (my ($name, $symbol) = each %mapping) {
616 if (!exists $params{$name}) {
617 # to allow for multivalued params we use arrayref form
618 $params{$name} = [ $cgi->param($symbol) ];
623 $params{'project'} = $project unless exists $params{'project'};
625 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
627 # use PATH_INFO for project name
628 $href .= "/$params{'project'}" if defined $params{'project'};
629 delete $params{'project'};
631 # Summary just uses the project path URL
632 if (defined $params{'action'} && $params{'action'} eq 'summary') {
633 delete $params{'action'};
637 # now encode the parameters explicitly
639 for (my $i = 0; $i < @mapping; $i += 2) {
640 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
641 if (defined $params{$name}) {
642 if (ref($params{$name}) eq "ARRAY") {
643 foreach my $par (@{$params{$name}}) {
644 push @result, $symbol . "=" . esc_param($par);
647 push @result, $symbol . "=" . esc_param($params{$name});
651 $href .= "?" . join(';', @result) if scalar @result;
657 ## ======================================================================
658 ## validation, quoting/unquoting and escaping
660 sub validate_pathname {
661 my $input = shift || return undef;
663 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
664 # at the beginning, at the end, and between slashes.
665 # also this catches doubled slashes
666 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
670 if ($input =~ m!\0!) {
676 sub validate_refname {
677 my $input = shift || return undef;
679 # textual hashes are O.K.
680 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
683 # it must be correct pathname
684 $input = validate_pathname($input)
686 # restrictions on ref name according to git-check-ref-format
687 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
693 # decode sequences of octets in utf8 into Perl's internal form,
694 # which is utf-8 with utf8 flag set if needed. gitweb writes out
695 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
699 eval { $res = decode_utf8($str, Encode::FB_CROAK); };
703 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
707 # quote unsafe chars, but keep the slash, even when it's not
708 # correct, but quoted slashes look too horrible in bookmarks
711 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
717 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
720 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
726 # replace invalid utf8 character with SUBSTITUTION sequence
731 $str = to_utf8($str);
732 $str = $cgi->escapeHTML($str);
733 if ($opts{'-nbsp'}) {
734 $str =~ s/ / /g;
736 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
740 # quote control characters and escape filename to HTML
745 $str = to_utf8($str);
746 $str = $cgi->escapeHTML($str);
747 if ($opts{'-nbsp'}) {
748 $str =~ s/ / /g;
750 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
754 # Make control characters "printable", using character escape codes (CEC)
757 my %es = ( # character escape codes, aka escape sequences
758 "\t" => '\t', # tab (HT)
759 "\n" => '\n', # line feed (LF)
760 "\r" => '\r', # carrige return (CR)
761 "\f" => '\f', # form feed (FF)
762 "\b" => '\b', # backspace (BS)
763 "\a" => '\a', # alarm (bell) (BEL)
764 "\e" => '\e', # escape (ESC)
765 "\013" => '\v', # vertical tab (VT)
766 "\000" => '\0', # nul character (NUL)
768 my $chr = ( (exists $es{$cntrl})
770 : sprintf('\%03o', ord($cntrl)) );
771 return "<span class=\"cntrl\">$chr</span>";
774 # Alternatively use unicode control pictures codepoints,
775 # Unicode "printable representation" (PR)
778 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
779 return "<span class=\"cntrl\">$chr</span>";
782 # git may return quoted and escaped filenames
788 my %es = ( # character escape codes, aka escape sequences
789 't' => "\t", # tab (HT, TAB)
790 'n' => "\n", # newline (NL)
791 'r' => "\r", # return (CR)
792 'f' => "\f", # form feed (FF)
793 'b' => "\b", # backspace (BS)
794 'a' => "\a", # alarm (bell) (BEL)
795 'e' => "\e", # escape (ESC)
796 'v' => "\013", # vertical tab (VT)
799 if ($seq =~ m/^[0-7]{1,3}$/) {
800 # octal char sequence
801 return chr(oct($seq));
802 } elsif (exists $es{$seq}) {
803 # C escape sequence, aka character escape code
806 # quoted ordinary character
810 if ($str =~ m/^"(.*)"$/) {
813 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
818 # escape tabs (convert tabs to spaces)
822 while ((my $pos = index($line, "\t")) != -1) {
823 if (my $count = (8 - ($pos % 8))) {
824 my $spaces = ' ' x $count;
825 $line =~ s/\t/$spaces/;
832 sub project_in_list {
834 my @list = git_get_projects_list();
835 return @list && scalar(grep { $_->{'path'} eq $project } @list);
838 ## ----------------------------------------------------------------------
839 ## HTML aware string manipulation
844 my $add_len = shift || 10;
846 # allow only $len chars, but don't cut a word if it would fit in $add_len
847 # if it doesn't fit, cut it if it's still longer than the dots we would add
848 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
851 if (length($tail) > 4) {
853 $body =~ s/&[^;]*$//; # remove chopped character entities
858 # takes the same arguments as chop_str, but also wraps a <span> around the
859 # result with a title attribute if it does get chopped. Additionally, the
860 # string is HTML-escaped.
861 sub chop_and_escape_str {
864 my $add_len = shift || 10;
866 my $chopped = chop_str($str, $len, $add_len);
867 if ($chopped eq $str) {
868 return esc_html($chopped);
870 return qq{<span title="} . esc_html($str) . qq{">} .
871 esc_html($chopped) . qq{</span>};
875 ## ----------------------------------------------------------------------
876 ## functions returning short strings
878 # CSS class for given age value (in seconds)
884 } elsif ($age < 60*60*2) {
886 } elsif ($age < 60*60*24*2) {
893 # convert age in seconds to "nn units ago" string
898 if ($age > 60*60*24*365*2) {
899 $age_str = (int $age/60/60/24/365);
900 $age_str .= " years ago";
901 } elsif ($age > 60*60*24*(365/12)*2) {
902 $age_str = int $age/60/60/24/(365/12);
903 $age_str .= " months ago";
904 } elsif ($age > 60*60*24*7*2) {
905 $age_str = int $age/60/60/24/7;
906 $age_str .= " weeks ago";
907 } elsif ($age > 60*60*24*2) {
908 $age_str = int $age/60/60/24;
909 $age_str .= " days ago";
910 } elsif ($age > 60*60*2) {
911 $age_str = int $age/60/60;
912 $age_str .= " hours ago";
913 } elsif ($age > 60*2) {
914 $age_str = int $age/60;
915 $age_str .= " min ago";
918 $age_str .= " sec ago";
920 $age_str .= " right now";
926 S_IFINVALID => 0030000,
927 S_IFGITLINK => 0160000,
930 # submodule/subproject, a commit object reference
934 return (($mode & S_IFMT) == S_IFGITLINK)
937 # convert file mode in octal to symbolic file mode string
939 my $mode = oct shift;
941 if (S_ISGITLINK($mode)) {
943 } elsif (S_ISDIR($mode & S_IFMT)) {
945 } elsif (S_ISLNK($mode)) {
947 } elsif (S_ISREG($mode)) {
948 # git cares only about the executable bit
949 if ($mode & S_IXUSR) {
959 # convert file mode in octal to file type string
963 if ($mode !~ m/^[0-7]+$/) {
969 if (S_ISGITLINK($mode)) {
971 } elsif (S_ISDIR($mode & S_IFMT)) {
973 } elsif (S_ISLNK($mode)) {
975 } elsif (S_ISREG($mode)) {
982 # convert file mode in octal to file type description string
986 if ($mode !~ m/^[0-7]+$/) {
992 if (S_ISGITLINK($mode)) {
994 } elsif (S_ISDIR($mode & S_IFMT)) {
996 } elsif (S_ISLNK($mode)) {
998 } elsif (S_ISREG($mode)) {
999 if ($mode & S_IXUSR) {
1000 return "executable";
1010 ## ----------------------------------------------------------------------
1011 ## functions returning short HTML fragments, or transforming HTML fragments
1012 ## which don't belong to other sections
1014 # format line of commit message.
1015 sub format_log_line_html {
1018 $line = esc_html($line, -nbsp=>1);
1019 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1022 $cgi->a({-href => href(action=>"object", hash=>$hash_text),
1023 -class => "text"}, $hash_text);
1024 $line =~ s/$hash_text/$link/;
1029 # format marker of refs pointing to given object
1030 sub format_ref_marker {
1031 my ($refs, $id) = @_;
1034 if (defined $refs->{$id}) {
1035 foreach my $ref (@{$refs->{$id}}) {
1036 my ($type, $name) = qw();
1037 # e.g. tags/v2.6.11 or heads/next
1038 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1046 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1047 esc_html($name) . "</span>";
1052 return ' <span class="refs">'. $markers . '</span>';
1058 # format, perhaps shortened and with markers, title line
1059 sub format_subject_html {
1060 my ($long, $short, $href, $extra) = @_;
1061 $extra = '' unless defined($extra);
1063 if (length($short) < length($long)) {
1064 return $cgi->a({-href => $href, -class => "list subject",
1065 -title => to_utf8($long)},
1066 esc_html($short) . $extra);
1068 return $cgi->a({-href => $href, -class => "list subject"},
1069 esc_html($long) . $extra);
1073 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1074 sub format_git_diff_header_line {
1076 my $diffinfo = shift;
1077 my ($from, $to) = @_;
1079 if ($diffinfo->{'nparents'}) {
1081 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1082 if ($to->{'href'}) {
1083 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1084 esc_path($to->{'file'}));
1085 } else { # file was deleted (no href)
1086 $line .= esc_path($to->{'file'});
1090 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1091 if ($from->{'href'}) {
1092 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1093 'a/' . esc_path($from->{'file'}));
1094 } else { # file was added (no href)
1095 $line .= 'a/' . esc_path($from->{'file'});
1098 if ($to->{'href'}) {
1099 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1100 'b/' . esc_path($to->{'file'}));
1101 } else { # file was deleted
1102 $line .= 'b/' . esc_path($to->{'file'});
1106 return "<div class=\"diff header\">$line</div>\n";
1109 # format extended diff header line, before patch itself
1110 sub format_extended_diff_header_line {
1112 my $diffinfo = shift;
1113 my ($from, $to) = @_;
1116 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1117 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1118 esc_path($from->{'file'}));
1120 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1121 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1122 esc_path($to->{'file'}));
1124 # match single <mode>
1125 if ($line =~ m/\s(\d{6})$/) {
1126 $line .= '<span class="info"> (' .
1127 file_type_long($1) .
1131 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1132 # can match only for combined diff
1134 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1135 if ($from->{'href'}[$i]) {
1136 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1138 substr($diffinfo->{'from_id'}[$i],0,7));
1143 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1146 if ($to->{'href'}) {
1147 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1148 substr($diffinfo->{'to_id'},0,7));
1153 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1154 # can match only for ordinary diff
1155 my ($from_link, $to_link);
1156 if ($from->{'href'}) {
1157 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1158 substr($diffinfo->{'from_id'},0,7));
1160 $from_link = '0' x 7;
1162 if ($to->{'href'}) {
1163 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1164 substr($diffinfo->{'to_id'},0,7));
1168 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1169 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1172 return $line . "<br/>\n";
1175 # format from-file/to-file diff header
1176 sub format_diff_from_to_header {
1177 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1182 #assert($line =~ m/^---/) if DEBUG;
1183 # no extra formatting for "^--- /dev/null"
1184 if (! $diffinfo->{'nparents'}) {
1185 # ordinary (single parent) diff
1186 if ($line =~ m!^--- "?a/!) {
1187 if ($from->{'href'}) {
1189 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1190 esc_path($from->{'file'}));
1193 esc_path($from->{'file'});
1196 $result .= qq!<div class="diff from_file">$line</div>\n!;
1199 # combined diff (merge commit)
1200 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1201 if ($from->{'href'}[$i]) {
1203 $cgi->a({-href=>href(action=>"blobdiff",
1204 hash_parent=>$diffinfo->{'from_id'}[$i],
1205 hash_parent_base=>$parents[$i],
1206 file_parent=>$from->{'file'}[$i],
1207 hash=>$diffinfo->{'to_id'},
1209 file_name=>$to->{'file'}),
1211 -title=>"diff" . ($i+1)},
1214 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1215 esc_path($from->{'file'}[$i]));
1217 $line = '--- /dev/null';
1219 $result .= qq!<div class="diff from_file">$line</div>\n!;
1224 #assert($line =~ m/^\+\+\+/) if DEBUG;
1225 # no extra formatting for "^+++ /dev/null"
1226 if ($line =~ m!^\+\+\+ "?b/!) {
1227 if ($to->{'href'}) {
1229 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1230 esc_path($to->{'file'}));
1233 esc_path($to->{'file'});
1236 $result .= qq!<div class="diff to_file">$line</div>\n!;
1241 # create note for patch simplified by combined diff
1242 sub format_diff_cc_simplified {
1243 my ($diffinfo, @parents) = @_;
1246 $result .= "<div class=\"diff header\">" .
1248 if (!is_deleted($diffinfo)) {
1249 $result .= $cgi->a({-href => href(action=>"blob",
1251 hash=>$diffinfo->{'to_id'},
1252 file_name=>$diffinfo->{'to_file'}),
1254 esc_path($diffinfo->{'to_file'}));
1256 $result .= esc_path($diffinfo->{'to_file'});
1258 $result .= "</div>\n" . # class="diff header"
1259 "<div class=\"diff nodifferences\">" .
1261 "</div>\n"; # class="diff nodifferences"
1266 # format patch (diff) line (not to be used for diff headers)
1267 sub format_diff_line {
1269 my ($from, $to) = @_;
1270 my $diff_class = "";
1274 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1276 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1277 if ($line =~ m/^\@{3}/) {
1278 $diff_class = " chunk_header";
1279 } elsif ($line =~ m/^\\/) {
1280 $diff_class = " incomplete";
1281 } elsif ($prefix =~ tr/+/+/) {
1282 $diff_class = " add";
1283 } elsif ($prefix =~ tr/-/-/) {
1284 $diff_class = " rem";
1287 # assume ordinary diff
1288 my $char = substr($line, 0, 1);
1290 $diff_class = " add";
1291 } elsif ($char eq '-') {
1292 $diff_class = " rem";
1293 } elsif ($char eq '@') {
1294 $diff_class = " chunk_header";
1295 } elsif ($char eq "\\") {
1296 $diff_class = " incomplete";
1299 $line = untabify($line);
1300 if ($from && $to && $line =~ m/^\@{2} /) {
1301 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1302 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1304 $from_lines = 0 unless defined $from_lines;
1305 $to_lines = 0 unless defined $to_lines;
1307 if ($from->{'href'}) {
1308 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1309 -class=>"list"}, $from_text);
1311 if ($to->{'href'}) {
1312 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1313 -class=>"list"}, $to_text);
1315 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1316 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1317 return "<div class=\"diff$diff_class\">$line</div>\n";
1318 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1319 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1320 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1322 @from_text = split(' ', $ranges);
1323 for (my $i = 0; $i < @from_text; ++$i) {
1324 ($from_start[$i], $from_nlines[$i]) =
1325 (split(',', substr($from_text[$i], 1)), 0);
1328 $to_text = pop @from_text;
1329 $to_start = pop @from_start;
1330 $to_nlines = pop @from_nlines;
1332 $line = "<span class=\"chunk_info\">$prefix ";
1333 for (my $i = 0; $i < @from_text; ++$i) {
1334 if ($from->{'href'}[$i]) {
1335 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1336 -class=>"list"}, $from_text[$i]);
1338 $line .= $from_text[$i];
1342 if ($to->{'href'}) {
1343 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1344 -class=>"list"}, $to_text);
1348 $line .= " $prefix</span>" .
1349 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1350 return "<div class=\"diff$diff_class\">$line</div>\n";
1352 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1355 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1356 # linked. Pass the hash of the tree/commit to snapshot.
1357 sub format_snapshot_links {
1359 my @snapshot_fmts = gitweb_check_feature('snapshot');
1360 @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
1361 my $num_fmts = @snapshot_fmts;
1362 if ($num_fmts > 1) {
1363 # A parenthesized list of links bearing format names.
1364 # e.g. "snapshot (_tar.gz_ _zip_)"
1365 return "snapshot (" . join(' ', map
1372 }, $known_snapshot_formats{$_}{'display'})
1373 , @snapshot_fmts) . ")";
1374 } elsif ($num_fmts == 1) {
1375 # A single "snapshot" link whose tooltip bears the format name.
1377 my ($fmt) = @snapshot_fmts;
1383 snapshot_format=>$fmt
1385 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1387 } else { # $num_fmts == 0
1392 ## ----------------------------------------------------------------------
1393 ## git utility subroutines, invoking git commands
1395 # returns path to the core git executable and the --git-dir parameter as list
1397 return $GIT, '--git-dir='.$git_dir;
1400 # returns path to the core git executable and the --git-dir parameter as string
1402 return join(' ', git_cmd());
1405 # get HEAD ref of given project as hash
1406 sub git_get_head_hash {
1407 my $project = shift;
1408 my $o_git_dir = $git_dir;
1410 $git_dir = "$projectroot/$project";
1411 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1414 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1418 if (defined $o_git_dir) {
1419 $git_dir = $o_git_dir;
1424 # get type of given object
1428 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1430 close $fd or return;
1435 # repository configuration
1436 our $config_file = '';
1439 # store multiple values for single key as anonymous array reference
1440 # single values stored directly in the hash, not as [ <value> ]
1441 sub hash_set_multi {
1442 my ($hash, $key, $value) = @_;
1444 if (!exists $hash->{$key}) {
1445 $hash->{$key} = $value;
1446 } elsif (!ref $hash->{$key}) {
1447 $hash->{$key} = [ $hash->{$key}, $value ];
1449 push @{$hash->{$key}}, $value;
1453 # return hash of git project configuration
1454 # optionally limited to some section, e.g. 'gitweb'
1455 sub git_parse_project_config {
1456 my $section_regexp = shift;
1461 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
1464 while (my $keyval = <$fh>) {
1466 my ($key, $value) = split(/\n/, $keyval, 2);
1468 hash_set_multi(\%config, $key, $value)
1469 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1476 # convert config value to boolean, 'true' or 'false'
1477 # no value, number > 0, 'true' and 'yes' values are true
1478 # rest of values are treated as false (never as error)
1479 sub config_to_bool {
1482 # strip leading and trailing whitespace
1486 return (!defined $val || # section.key
1487 ($val =~ /^\d+$/ && $val) || # section.key = 1
1488 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1491 # convert config value to simple decimal number
1492 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1493 # to be multiplied by 1024, 1048576, or 1073741824
1497 # strip leading and trailing whitespace
1501 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1503 # unknown unit is treated as 1
1504 return $num * ($unit eq 'g' ? 1073741824 :
1505 $unit eq 'm' ? 1048576 :
1506 $unit eq 'k' ? 1024 : 1);
1511 # convert config value to array reference, if needed
1512 sub config_to_multi {
1515 return ref($val) ? $val : [ $val ];
1518 sub git_get_project_config {
1519 my ($key, $type) = @_;
1522 return unless ($key);
1523 $key =~ s/^gitweb\.//;
1524 return if ($key =~ m/\W/);
1527 if (defined $type) {
1530 unless ($type eq 'bool' || $type eq 'int');
1534 if (!defined $config_file ||
1535 $config_file ne "$git_dir/config") {
1536 %config = git_parse_project_config('gitweb');
1537 $config_file = "$git_dir/config";
1541 if (!defined $type) {
1542 return $config{"gitweb.$key"};
1543 } elsif ($type eq 'bool') {
1544 # backward compatibility: 'git config --bool' returns true/false
1545 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
1546 } elsif ($type eq 'int') {
1547 return config_to_int($config{"gitweb.$key"});
1549 return $config{"gitweb.$key"};
1552 # get hash of given path at given ref
1553 sub git_get_hash_by_path {
1555 my $path = shift || return undef;
1560 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
1561 or die_error(undef, "Open git-ls-tree failed");
1563 close $fd or return undef;
1565 if (!defined $line) {
1566 # there is no tree or hash given by $path at $base
1570 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1571 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1572 if (defined $type && $type ne $2) {
1573 # type doesn't match
1579 # get path of entry with given hash at given tree-ish (ref)
1580 # used to get 'from' filename for combined diff (merge commit) for renames
1581 sub git_get_path_by_hash {
1582 my $base = shift || return;
1583 my $hash = shift || return;
1587 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
1589 while (my $line = <$fd>) {
1592 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1593 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1594 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1603 ## ......................................................................
1604 ## git utility functions, directly accessing git repository
1606 sub git_get_project_description {
1609 open my $fd, "$projectroot/$path/description" or return undef;
1612 if (defined $descr) {
1618 sub git_get_project_url_list {
1621 open my $fd, "$projectroot/$path/cloneurl" or return;
1622 my @git_project_url_list = map { chomp; $_ } <$fd>;
1625 return wantarray ? @git_project_url_list : \@git_project_url_list;
1628 sub git_get_projects_list {
1633 $filter =~ s/\.git$//;
1635 my ($check_forks) = gitweb_check_feature('forks');
1637 if (-d $projects_list) {
1638 # search in directory
1639 my $dir = $projects_list . ($filter ? "/$filter" : '');
1640 # remove the trailing "/"
1642 my $pfxlen = length("$dir");
1643 my $pfxdepth = ($dir =~ tr!/!!);
1646 follow_fast => 1, # follow symbolic links
1647 follow_skip => 2, # ignore duplicates
1648 dangling_symlinks => 0, # ignore dangling symlinks, silently
1650 # skip project-list toplevel, if we get it.
1651 return if (m!^[/.]$!);
1652 # only directories can be git repositories
1653 return unless (-d $_);
1654 # don't traverse too deep (Find is super slow on os x)
1655 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1656 $File::Find::prune = 1;
1660 my $subdir = substr($File::Find::name, $pfxlen + 1);
1661 # we check related file in $projectroot
1662 if ($check_forks and $subdir =~ m#/.#) {
1663 $File::Find::prune = 1;
1664 } elsif (check_export_ok("$projectroot/$filter/$subdir")) {
1665 push @list, { path => ($filter ? "$filter/" : '') . $subdir };
1666 $File::Find::prune = 1;
1671 } elsif (-f $projects_list) {
1672 # read from file(url-encoded):
1673 # 'git%2Fgit.git Linus+Torvalds'
1674 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1675 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1677 open my ($fd), $projects_list or return;
1679 while (my $line = <$fd>) {
1681 my ($path, $owner) = split ' ', $line;
1682 $path = unescape($path);
1683 $owner = unescape($owner);
1684 if (!defined $path) {
1687 if ($filter ne '') {
1688 # looking for forks;
1689 my $pfx = substr($path, 0, length($filter));
1690 if ($pfx ne $filter) {
1693 my $sfx = substr($path, length($filter));
1694 if ($sfx !~ /^\/.*\.git$/) {
1697 } elsif ($check_forks) {
1699 foreach my $filter (keys %paths) {
1700 # looking for forks;
1701 my $pfx = substr($path, 0, length($filter));
1702 if ($pfx ne $filter) {
1705 my $sfx = substr($path, length($filter));
1706 if ($sfx !~ /^\/.*\.git$/) {
1709 # is a fork, don't include it in
1714 if (check_export_ok("$projectroot/$path")) {
1717 owner => to_utf8($owner),
1720 (my $forks_path = $path) =~ s/\.git$//;
1721 $paths{$forks_path}++;
1729 our $gitweb_project_owner = undef;
1730 sub git_get_project_list_from_file {
1732 return if (defined $gitweb_project_owner);
1734 $gitweb_project_owner = {};
1735 # read from file (url-encoded):
1736 # 'git%2Fgit.git Linus+Torvalds'
1737 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1738 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1739 if (-f $projects_list) {
1740 open (my $fd , $projects_list);
1741 while (my $line = <$fd>) {
1743 my ($pr, $ow) = split ' ', $line;
1744 $pr = unescape($pr);
1745 $ow = unescape($ow);
1746 $gitweb_project_owner->{$pr} = to_utf8($ow);
1752 sub git_get_project_owner {
1753 my $project = shift;
1756 return undef unless $project;
1758 if (!defined $gitweb_project_owner) {
1759 git_get_project_list_from_file();
1762 if (exists $gitweb_project_owner->{$project}) {
1763 $owner = $gitweb_project_owner->{$project};
1765 if (!defined $owner) {
1766 $owner = get_file_owner("$projectroot/$project");
1772 sub git_get_last_activity {
1776 $git_dir = "$projectroot/$path";
1777 open($fd, "-|", git_cmd(), 'for-each-ref',
1778 '--format=%(committer)',
1779 '--sort=-committerdate',
1781 'refs/heads') or return;
1782 my $most_recent = <$fd>;
1783 close $fd or return;
1784 if (defined $most_recent &&
1785 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1787 my $age = time - $timestamp;
1788 return ($age, age_string($age));
1790 return (undef, undef);
1793 sub git_get_references {
1794 my $type = shift || "";
1796 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1797 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1798 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
1799 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1802 while (my $line = <$fd>) {
1804 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1805 if (defined $refs{$1}) {
1806 push @{$refs{$1}}, $2;
1812 close $fd or return;
1816 sub git_get_rev_name_tags {
1817 my $hash = shift || return undef;
1819 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
1821 my $name_rev = <$fd>;
1824 if ($name_rev =~ m|^$hash tags/(.*)$|) {
1827 # catches also '$hash undefined' output
1832 ## ----------------------------------------------------------------------
1833 ## parse to hash functions
1837 my $tz = shift || "-0000";
1840 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1841 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1842 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1843 $date{'hour'} = $hour;
1844 $date{'minute'} = $min;
1845 $date{'mday'} = $mday;
1846 $date{'day'} = $days[$wday];
1847 $date{'month'} = $months[$mon];
1848 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1849 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1850 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1851 $mday, $months[$mon], $hour ,$min;
1852 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1853 1900+$year, $mon, $mday, $hour ,$min, $sec;
1855 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1856 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1857 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1858 $date{'hour_local'} = $hour;
1859 $date{'minute_local'} = $min;
1860 $date{'tz_local'} = $tz;
1861 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1862 1900+$year, $mon+1, $mday,
1863 $hour, $min, $sec, $tz);
1872 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
1873 $tag{'id'} = $tag_id;
1874 while (my $line = <$fd>) {
1876 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1877 $tag{'object'} = $1;
1878 } elsif ($line =~ m/^type (.+)$/) {
1880 } elsif ($line =~ m/^tag (.+)$/) {
1882 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1883 $tag{'author'} = $1;
1886 } elsif ($line =~ m/--BEGIN/) {
1887 push @comment, $line;
1889 } elsif ($line eq "") {
1893 push @comment, <$fd>;
1894 $tag{'comment'} = \@comment;
1895 close $fd or return;
1896 if (!defined $tag{'name'}) {
1902 sub parse_commit_text {
1903 my ($commit_text, $withparents) = @_;
1904 my @commit_lines = split '\n', $commit_text;
1907 pop @commit_lines; # Remove '\0'
1909 if (! @commit_lines) {
1913 my $header = shift @commit_lines;
1914 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1917 ($co{'id'}, my @parents) = split ' ', $header;
1918 while (my $line = shift @commit_lines) {
1919 last if $line eq "\n";
1920 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1922 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1924 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1926 $co{'author_epoch'} = $2;
1927 $co{'author_tz'} = $3;
1928 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1929 $co{'author_name'} = $1;
1930 $co{'author_email'} = $2;
1932 $co{'author_name'} = $co{'author'};
1934 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1935 $co{'committer'} = $1;
1936 $co{'committer_epoch'} = $2;
1937 $co{'committer_tz'} = $3;
1938 $co{'committer_name'} = $co{'committer'};
1939 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1940 $co{'committer_name'} = $1;
1941 $co{'committer_email'} = $2;
1943 $co{'committer_name'} = $co{'committer'};
1947 if (!defined $co{'tree'}) {
1950 $co{'parents'} = \@parents;
1951 $co{'parent'} = $parents[0];
1953 foreach my $title (@commit_lines) {
1956 $co{'title'} = chop_str($title, 80, 5);
1957 # remove leading stuff of merges to make the interesting part visible
1958 if (length($title) > 50) {
1959 $title =~ s/^Automatic //;
1960 $title =~ s/^merge (of|with) /Merge ... /i;
1961 if (length($title) > 50) {
1962 $title =~ s/(http|rsync):\/\///;
1964 if (length($title) > 50) {
1965 $title =~ s/(master|www|rsync)\.//;
1967 if (length($title) > 50) {
1968 $title =~ s/kernel.org:?//;
1970 if (length($title) > 50) {
1971 $title =~ s/\/pub\/scm//;
1974 $co{'title_short'} = chop_str($title, 50, 5);
1978 if ($co{'title'} eq "") {
1979 $co{'title'} = $co{'title_short'} = '(no commit message)';
1981 # remove added spaces
1982 foreach my $line (@commit_lines) {
1985 $co{'comment'} = \@commit_lines;
1987 my $age = time - $co{'committer_epoch'};
1989 $co{'age_string'} = age_string($age);
1990 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1991 if ($age > 60*60*24*7*2) {
1992 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1993 $co{'age_string_age'} = $co{'age_string'};
1995 $co{'age_string_date'} = $co{'age_string'};
1996 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2002 my ($commit_id) = @_;
2007 open my $fd, "-|", git_cmd(), "rev-list",
2013 or die_error(undef, "Open git-rev-list failed");
2014 %co = parse_commit_text(<$fd>, 1);
2021 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
2029 open my $fd, "-|", git_cmd(), "rev-list",
2031 ($arg ? ($arg) : ()),
2032 ("--max-count=" . $maxcount),
2033 ("--skip=" . $skip),
2037 ($filename ? ($filename) : ())
2038 or die_error(undef, "Open git-rev-list failed");
2039 while (my $line = <$fd>) {
2040 my %co = parse_commit_text($line);
2045 return wantarray ? @cos : \@cos;
2048 # parse ref from ref_file, given by ref_id, with given type
2050 my $ref_file = shift;
2052 my $type = shift || git_get_type($ref_id);
2055 $ref_item{'type'} = $type;
2056 $ref_item{'id'} = $ref_id;
2057 $ref_item{'epoch'} = 0;
2058 $ref_item{'age'} = "unknown";
2059 if ($type eq "tag") {
2060 my %tag = parse_tag($ref_id);
2061 $ref_item{'comment'} = $tag{'comment'};
2062 if ($tag{'type'} eq "commit") {
2063 my %co = parse_commit($tag{'object'});
2064 $ref_item{'epoch'} = $co{'committer_epoch'};
2065 $ref_item{'age'} = $co{'age_string'};
2066 } elsif (defined($tag{'epoch'})) {
2067 my $age = time - $tag{'epoch'};
2068 $ref_item{'epoch'} = $tag{'epoch'};
2069 $ref_item{'age'} = age_string($age);
2071 $ref_item{'reftype'} = $tag{'type'};
2072 $ref_item{'name'} = $tag{'name'};
2073 $ref_item{'refid'} = $tag{'object'};
2074 } elsif ($type eq "commit"){
2075 my %co = parse_commit($ref_id);
2076 $ref_item{'reftype'} = "commit";
2077 $ref_item{'name'} = $ref_file;
2078 $ref_item{'title'} = $co{'title'};
2079 $ref_item{'refid'} = $ref_id;
2080 $ref_item{'epoch'} = $co{'committer_epoch'};
2081 $ref_item{'age'} = $co{'age_string'};
2083 $ref_item{'reftype'} = $type;
2084 $ref_item{'name'} = $ref_file;
2085 $ref_item{'refid'} = $ref_id;
2091 # parse line of git-diff-tree "raw" output
2092 sub parse_difftree_raw_line {
2096 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2097 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2098 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2099 $res{'from_mode'} = $1;
2100 $res{'to_mode'} = $2;
2101 $res{'from_id'} = $3;
2103 $res{'status'} = $res{'status_str'} = $5;
2104 $res{'similarity'} = $6;
2105 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2106 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2108 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2111 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2112 # combined diff (for merge commit)
2113 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2114 $res{'nparents'} = length($1);
2115 $res{'from_mode'} = [ split(' ', $2) ];
2116 $res{'to_mode'} = pop @{$res{'from_mode'}};
2117 $res{'from_id'} = [ split(' ', $3) ];
2118 $res{'to_id'} = pop @{$res{'from_id'}};
2119 $res{'status_str'} = $4;
2120 $res{'status'} = [ split('', $4) ];
2121 $res{'to_file'} = unquote($5);
2123 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2124 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2125 $res{'commit'} = $1;
2128 return wantarray ? %res : \%res;
2131 # wrapper: return parsed line of git-diff-tree "raw" output
2132 # (the argument might be raw line, or parsed info)
2133 sub parsed_difftree_line {
2134 my $line_or_ref = shift;
2136 if (ref($line_or_ref) eq "HASH") {
2137 # pre-parsed (or generated by hand)
2138 return $line_or_ref;
2140 return parse_difftree_raw_line($line_or_ref);
2144 # parse line of git-ls-tree output
2145 sub parse_ls_tree_line ($;%) {
2150 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2151 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2159 $res{'name'} = unquote($4);
2162 return wantarray ? %res : \%res;
2165 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2166 sub parse_from_to_diffinfo {
2167 my ($diffinfo, $from, $to, @parents) = @_;
2169 if ($diffinfo->{'nparents'}) {
2171 $from->{'file'} = [];
2172 $from->{'href'} = [];
2173 fill_from_file_info($diffinfo, @parents)
2174 unless exists $diffinfo->{'from_file'};
2175 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2176 $from->{'file'}[$i] =
2177 defined $diffinfo->{'from_file'}[$i] ?
2178 $diffinfo->{'from_file'}[$i] :
2179 $diffinfo->{'to_file'};
2180 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2181 $from->{'href'}[$i] = href(action=>"blob",
2182 hash_base=>$parents[$i],
2183 hash=>$diffinfo->{'from_id'}[$i],
2184 file_name=>$from->{'file'}[$i]);
2186 $from->{'href'}[$i] = undef;
2190 # ordinary (not combined) diff
2191 $from->{'file'} = $diffinfo->{'from_file'};
2192 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2193 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2194 hash=>$diffinfo->{'from_id'},
2195 file_name=>$from->{'file'});
2197 delete $from->{'href'};
2201 $to->{'file'} = $diffinfo->{'to_file'};
2202 if (!is_deleted($diffinfo)) { # file exists in result
2203 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2204 hash=>$diffinfo->{'to_id'},
2205 file_name=>$to->{'file'});
2207 delete $to->{'href'};
2211 ## ......................................................................
2212 ## parse to array of hashes functions
2214 sub git_get_heads_list {
2218 open my $fd, '-|', git_cmd(), 'for-each-ref',
2219 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2220 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2223 while (my $line = <$fd>) {
2227 my ($refinfo, $committerinfo) = split(/\0/, $line);
2228 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2229 my ($committer, $epoch, $tz) =
2230 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2231 $name =~ s!^refs/heads/!!;
2233 $ref_item{'name'} = $name;
2234 $ref_item{'id'} = $hash;
2235 $ref_item{'title'} = $title || '(no commit message)';
2236 $ref_item{'epoch'} = $epoch;
2238 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2240 $ref_item{'age'} = "unknown";
2243 push @headslist, \%ref_item;
2247 return wantarray ? @headslist : \@headslist;
2250 sub git_get_tags_list {
2254 open my $fd, '-|', git_cmd(), 'for-each-ref',
2255 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2256 '--format=%(objectname) %(objecttype) %(refname) '.
2257 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2260 while (my $line = <$fd>) {
2264 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2265 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2266 my ($creator, $epoch, $tz) =
2267 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2268 $name =~ s!^refs/tags/!!;
2270 $ref_item{'type'} = $type;
2271 $ref_item{'id'} = $id;
2272 $ref_item{'name'} = $name;
2273 if ($type eq "tag") {
2274 $ref_item{'subject'} = $title;
2275 $ref_item{'reftype'} = $reftype;
2276 $ref_item{'refid'} = $refid;
2278 $ref_item{'reftype'} = $type;
2279 $ref_item{'refid'} = $id;
2282 if ($type eq "tag" || $type eq "commit") {
2283 $ref_item{'epoch'} = $epoch;
2285 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2287 $ref_item{'age'} = "unknown";
2291 push @tagslist, \%ref_item;
2295 return wantarray ? @tagslist : \@tagslist;
2298 ## ----------------------------------------------------------------------
2299 ## filesystem-related functions
2301 sub get_file_owner {
2304 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2305 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2306 if (!defined $gcos) {
2310 $owner =~ s/[,;].*$//;
2311 return to_utf8($owner);
2314 ## ......................................................................
2315 ## mimetype related functions
2317 sub mimetype_guess_file {
2318 my $filename = shift;
2319 my $mimemap = shift;
2320 -r $mimemap or return undef;
2323 open(MIME, $mimemap) or return undef;
2325 next if m/^#/; # skip comments
2326 my ($mime, $exts) = split(/\t+/);
2327 if (defined $exts) {
2328 my @exts = split(/\s+/, $exts);
2329 foreach my $ext (@exts) {
2330 $mimemap{$ext} = $mime;
2336 $filename =~ /\.([^.]*)$/;
2337 return $mimemap{$1};
2340 sub mimetype_guess {
2341 my $filename = shift;
2343 $filename =~ /\./ or return undef;
2345 if ($mimetypes_file) {
2346 my $file = $mimetypes_file;
2347 if ($file !~ m!^/!) { # if it is relative path
2348 # it is relative to project
2349 $file = "$projectroot/$project/$file";
2351 $mime = mimetype_guess_file($filename, $file);
2353 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2359 my $filename = shift;
2362 my $mime = mimetype_guess($filename);
2363 $mime and return $mime;
2367 return $default_blob_plain_mimetype unless $fd;
2370 return 'text/plain' .
2371 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2372 } elsif (! $filename) {
2373 return 'application/octet-stream';
2374 } elsif ($filename =~ m/\.png$/i) {
2376 } elsif ($filename =~ m/\.gif$/i) {
2378 } elsif ($filename =~ m/\.jpe?g$/i) {
2379 return 'image/jpeg';
2381 return 'application/octet-stream';
2385 ## ======================================================================
2386 ## functions printing HTML: header, footer, error page
2388 sub git_header_html {
2389 my $status = shift || "200 OK";
2390 my $expires = shift;
2392 my $title = "$site_name";
2393 if (defined $project) {
2394 $title .= " - " . to_utf8($project);
2395 if (defined $action) {
2396 $title .= "/$action";
2397 if (defined $file_name) {
2398 $title .= " - " . esc_path($file_name);
2399 if ($action eq "tree" && $file_name !~ m|/$|) {
2406 # require explicit support from the UA if we are to send the page as
2407 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2408 # we have to do this because MSIE sometimes globs '*/*', pretending to
2409 # support xhtml+xml but choking when it gets what it asked for.
2410 if (defined $cgi->http('HTTP_ACCEPT') &&
2411 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
2412 $cgi->Accept('application/xhtml+xml') != 0) {
2413 $content_type = 'application/xhtml+xml';
2415 $content_type = 'text/html';
2417 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
2418 -status=> $status, -expires => $expires);
2419 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2421 <?xml version="1.0" encoding="utf-8"?>
2422 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2423 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2424 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2425 <!-- git core binaries version $git_version -->
2427 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2428 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2429 <meta name="robots" content="index, nofollow"/>
2430 <title>$title</title>
2432 # print out each stylesheet that exist
2433 if (defined $stylesheet) {
2434 #provides backwards capability for those people who define style sheet in a config file
2435 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2437 foreach my $stylesheet (@stylesheets) {
2438 next unless $stylesheet;
2439 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2442 if (defined $project) {
2443 printf('<link rel="alternate" title="%s log RSS feed" '.
2444 'href="%s" type="application/rss+xml" />'."\n",
2445 esc_param($project), href(action=>"rss"));
2446 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2447 'href="%s" type="application/rss+xml" />'."\n",
2448 esc_param($project), href(action=>"rss",
2449 extra_options=>"--no-merges"));
2450 printf('<link rel="alternate" title="%s log Atom feed" '.
2451 'href="%s" type="application/atom+xml" />'."\n",
2452 esc_param($project), href(action=>"atom"));
2453 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2454 'href="%s" type="application/atom+xml" />'."\n",
2455 esc_param($project), href(action=>"atom",
2456 extra_options=>"--no-merges"));
2458 printf('<link rel="alternate" title="%s projects list" '.
2459 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2460 $site_name, href(project=>undef, action=>"project_index"));
2461 printf('<link rel="alternate" title="%s projects feeds" '.
2462 'href="%s" type="text/x-opml"/>'."\n",
2463 $site_name, href(project=>undef, action=>"opml"));
2465 if (defined $favicon) {
2466 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2472 if (-f $site_header) {
2473 open (my $fd, $site_header);
2478 print "<div class=\"page_header\">\n" .
2479 $cgi->a({-href => esc_url($logo_url),
2480 -title => $logo_label},
2481 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2482 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
2483 if (defined $project) {
2484 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
2485 if (defined $action) {
2492 my ($have_search) = gitweb_check_feature('search');
2493 if ((defined $project) && ($have_search)) {
2494 if (!defined $searchtext) {
2498 if (defined $hash_base) {
2499 $search_hash = $hash_base;
2500 } elsif (defined $hash) {
2501 $search_hash = $hash;
2503 $search_hash = "HEAD";
2505 my $action = $my_uri;
2506 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
2507 if ($use_pathinfo) {
2508 $action .= "/$project";
2510 $cgi->param("p", $project);
2512 $cgi->param("a", "search");
2513 $cgi->param("h", $search_hash);
2514 print $cgi->startform(-method => "get", -action => $action) .
2515 "<div class=\"search\">\n" .
2516 (!$use_pathinfo && $cgi->hidden(-name => "p") . "\n") .
2517 $cgi->hidden(-name => "a") . "\n" .
2518 $cgi->hidden(-name => "h") . "\n" .
2519 $cgi->popup_menu(-name => 'st', -default => 'commit',
2520 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2521 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
2523 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
2525 $cgi->end_form() . "\n";
2529 sub git_footer_html {
2530 print "<div class=\"page_footer\">\n";
2531 if (defined $project) {
2532 my $descr = git_get_project_description($project);
2533 if (defined $descr) {
2534 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
2536 print $cgi->a({-href => href(action=>"rss"),
2537 -class => "rss_logo"}, "RSS") . " ";
2538 print $cgi->a({-href => href(action=>"atom"),
2539 -class => "rss_logo"}, "Atom") . "\n";
2541 print $cgi->a({-href => href(project=>undef, action=>"opml"),
2542 -class => "rss_logo"}, "OPML") . " ";
2543 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
2544 -class => "rss_logo"}, "TXT") . "\n";
2548 if (-f $site_footer) {
2549 open (my $fd, $site_footer);
2559 my $status = shift || "403 Forbidden";
2560 my $error = shift || "Malformed query, file missing or permission denied";
2562 git_header_html($status);
2564 <div class="page_body">
2574 ## ----------------------------------------------------------------------
2575 ## functions printing or outputting HTML: navigation
2577 sub git_print_page_nav {
2578 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2579 $extra = '' if !defined $extra; # pager or formats
2581 my @navs = qw(summary shortlog log commit commitdiff tree);
2583 @navs = grep { $_ ne $suppress } @navs;
2586 my %arg = map { $_ => {action=>$_} } @navs;
2587 if (defined $head) {
2588 for (qw(commit commitdiff)) {
2589 $arg{$_}{'hash'} = $head;
2591 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2592 for (qw(shortlog log)) {
2593 $arg{$_}{'hash'} = $head;
2597 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2598 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2600 print "<div class=\"page_nav\">\n" .
2602 map { $_ eq $current ?
2603 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
2605 print "<br/>\n$extra<br/>\n" .
2609 sub format_paging_nav {
2610 my ($action, $hash, $head, $page, $nrevs) = @_;
2614 if ($hash ne $head || $page) {
2615 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
2617 $paging_nav .= "HEAD";
2621 $paging_nav .= " ⋅ " .
2622 $cgi->a({-href => href(-replay=>1, page=>$page-1),
2623 -accesskey => "p", -title => "Alt-p"}, "prev");
2625 $paging_nav .= " ⋅ prev";
2628 if ($nrevs >= (100 * ($page+1)-1)) {
2629 $paging_nav .= " ⋅ " .
2630 $cgi->a({-href => href(-replay=>1, page=>$page+1),
2631 -accesskey => "n", -title => "Alt-n"}, "next");
2633 $paging_nav .= " ⋅ next";
2639 ## ......................................................................
2640 ## functions printing or outputting HTML: div
2642 sub git_print_header_div {
2643 my ($action, $title, $hash, $hash_base) = @_;
2646 $args{'action'} = $action;
2647 $args{'hash'} = $hash if $hash;
2648 $args{'hash_base'} = $hash_base if $hash_base;
2650 print "<div class=\"header\">\n" .
2651 $cgi->a({-href => href(%args), -class => "title"},
2652 $title ? $title : $action) .
2656 #sub git_print_authorship (\%) {
2657 sub git_print_authorship {
2660 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
2661 print "<div class=\"author_date\">" .
2662 esc_html($co->{'author_name'}) .
2664 if ($ad{'hour_local'} < 6) {
2665 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2666 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2668 printf(" (%02d:%02d %s)",
2669 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2674 sub git_print_page_path {
2680 print "<div class=\"page_path\">";
2681 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
2682 -title => 'tree root'}, to_utf8("[$project]"));
2684 if (defined $name) {
2685 my @dirname = split '/', $name;
2686 my $basename = pop @dirname;
2689 foreach my $dir (@dirname) {
2690 $fullname .= ($fullname ? '/' : '') . $dir;
2691 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
2693 -title => $fullname}, esc_path($dir));
2696 if (defined $type && $type eq 'blob') {
2697 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
2699 -title => $name}, esc_path($basename));
2700 } elsif (defined $type && $type eq 'tree') {
2701 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
2703 -title => $name}, esc_path($basename));
2706 print esc_path($basename);
2709 print "<br/></div>\n";
2712 # sub git_print_log (\@;%) {
2713 sub git_print_log ($;%) {
2717 if ($opts{'-remove_title'}) {
2718 # remove title, i.e. first line of log
2721 # remove leading empty lines
2722 while (defined $log->[0] && $log->[0] eq "") {
2729 foreach my $line (@$log) {
2730 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2733 if (! $opts{'-remove_signoff'}) {
2734 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
2737 # remove signoff lines
2744 # print only one empty line
2745 # do not print empty line after signoff
2747 next if ($empty || $signoff);
2753 print format_log_line_html($line) . "<br/>\n";
2756 if ($opts{'-final_empty_line'}) {
2757 # end with single empty line
2758 print "<br/>\n" unless $empty;
2762 # return link target (what link points to)
2763 sub git_get_link_target {
2768 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2772 $link_target = <$fd>;
2777 return $link_target;
2780 # given link target, and the directory (basedir) the link is in,
2781 # return target of link relative to top directory (top tree);
2782 # return undef if it is not possible (including absolute links).
2783 sub normalize_link_target {
2784 my ($link_target, $basedir, $hash_base) = @_;
2786 # we can normalize symlink target only if $hash_base is provided
2787 return unless $hash_base;
2789 # absolute symlinks (beginning with '/') cannot be normalized
2790 return if (substr($link_target, 0, 1) eq '/');
2792 # normalize link target to path from top (root) tree (dir)
2795 $path = $basedir . '/' . $link_target;
2797 # we are in top (root) tree (dir)
2798 $path = $link_target;
2801 # remove //, /./, and /../
2803 foreach my $part (split('/', $path)) {
2804 # discard '.' and ''
2805 next if (!$part || $part eq '.');
2807 if ($part eq '..') {
2811 # link leads outside repository (outside top dir)
2815 push @path_parts, $part;
2818 $path = join('/', @path_parts);
2823 # print tree entry (row of git_tree), but without encompassing <tr> element
2824 sub git_print_tree_entry {
2825 my ($t, $basedir, $hash_base, $have_blame) = @_;
2828 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2830 # The format of a table row is: mode list link. Where mode is
2831 # the mode of the entry, list is the name of the entry, an href,
2832 # and link is the action links of the entry.
2834 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
2835 if ($t->{'type'} eq "blob") {
2836 print "<td class=\"list\">" .
2837 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2838 file_name=>"$basedir$t->{'name'}", %base_key),
2839 -class => "list"}, esc_path($t->{'name'}));
2840 if (S_ISLNK(oct $t->{'mode'})) {
2841 my $link_target = git_get_link_target($t->{'hash'});
2843 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
2844 if (defined $norm_target) {
2846 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
2847 file_name=>$norm_target),
2848 -title => $norm_target}, esc_path($link_target));
2850 print " -> " . esc_path($link_target);
2855 print "<td class=\"link\">";
2856 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2857 file_name=>"$basedir$t->{'name'}", %base_key)},
2861 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
2862 file_name=>"$basedir$t->{'name'}", %base_key)},
2865 if (defined $hash_base) {
2867 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2868 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
2872 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
2873 file_name=>"$basedir$t->{'name'}")},
2877 } elsif ($t->{'type'} eq "tree") {
2878 print "<td class=\"list\">";
2879 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
2880 file_name=>"$basedir$t->{'name'}", %base_key)},
2881 esc_path($t->{'name'}));
2883 print "<td class=\"link\">";
2884 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
2885 file_name=>"$basedir$t->{'name'}", %base_key)},
2887 if (defined $hash_base) {
2889 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
2890 file_name=>"$basedir$t->{'name'}")},
2895 # unknown object: we can only present history for it
2896 # (this includes 'commit' object, i.e. submodule support)
2897 print "<td class=\"list\">" .
2898 esc_path($t->{'name'}) .
2900 print "<td class=\"link\">";
2901 if (defined $hash_base) {
2902 print $cgi->a({-href => href(action=>"history",
2903 hash_base=>$hash_base,
2904 file_name=>"$basedir$t->{'name'}")},
2911 ## ......................................................................
2912 ## functions printing large fragments of HTML
2914 # get pre-image filenames for merge (combined) diff
2915 sub fill_from_file_info {
2916 my ($diff, @parents) = @_;
2918 $diff->{'from_file'} = [ ];
2919 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2920 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2921 if ($diff->{'status'}[$i] eq 'R' ||
2922 $diff->{'status'}[$i] eq 'C') {
2923 $diff->{'from_file'}[$i] =
2924 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
2931 # is current raw difftree line of file deletion
2933 my $diffinfo = shift;
2935 return $diffinfo->{'status_str'} =~ /D/;
2938 # does patch correspond to [previous] difftree raw line
2939 # $diffinfo - hashref of parsed raw diff format
2940 # $patchinfo - hashref of parsed patch diff format
2941 # (the same keys as in $diffinfo)
2942 sub is_patch_split {
2943 my ($diffinfo, $patchinfo) = @_;
2945 return defined $diffinfo && defined $patchinfo
2946 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2950 sub git_difftree_body {
2951 my ($difftree, $hash, @parents) = @_;
2952 my ($parent) = $parents[0];
2953 my ($have_blame) = gitweb_check_feature('blame');
2954 print "<div class=\"list_head\">\n";
2955 if ($#{$difftree} > 10) {
2956 print(($#{$difftree} + 1) . " files changed:\n");
2960 print "<table class=\"" .
2961 (@parents > 1 ? "combined " : "") .
2964 # header only for combined diff in 'commitdiff' view
2965 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2968 print "<thead><tr>\n" .
2969 "<th></th><th></th>\n"; # filename, patchN link
2970 for (my $i = 0; $i < @parents; $i++) {
2971 my $par = $parents[$i];
2973 $cgi->a({-href => href(action=>"commitdiff",
2974 hash=>$hash, hash_parent=>$par),
2975 -title => 'commitdiff to parent number ' .
2976 ($i+1) . ': ' . substr($par,0,7)},
2980 print "</tr></thead>\n<tbody>\n";
2985 foreach my $line (@{$difftree}) {
2986 my $diff = parsed_difftree_line($line);
2989 print "<tr class=\"dark\">\n";
2991 print "<tr class=\"light\">\n";
2995 if (exists $diff->{'nparents'}) { # combined diff
2997 fill_from_file_info($diff, @parents)
2998 unless exists $diff->{'from_file'};
3000 if (!is_deleted($diff)) {
3001 # file exists in the result (child) commit
3003 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3004 file_name=>$diff->{'to_file'},
3006 -class => "list"}, esc_path($diff->{'to_file'})) .
3010 esc_path($diff->{'to_file'}) .
3014 if ($action eq 'commitdiff') {
3017 print "<td class=\"link\">" .
3018 $cgi->a({-href => "#patch$patchno"}, "patch") .
3023 my $has_history = 0;
3024 my $not_deleted = 0;
3025 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3026 my $hash_parent = $parents[$i];
3027 my $from_hash = $diff->{'from_id'}[$i];
3028 my $from_path = $diff->{'from_file'}[$i];
3029 my $status = $diff->{'status'}[$i];
3031 $has_history ||= ($status ne 'A');
3032 $not_deleted ||= ($status ne 'D');
3034 if ($status eq 'A') {
3035 print "<td class=\"link\" align=\"right\"> | </td>\n";
3036 } elsif ($status eq 'D') {
3037 print "<td class=\"link\">" .
3038 $cgi->a({-href => href(action=>"blob",
3041 file_name=>$from_path)},
3045 if ($diff->{'to_id'} eq $from_hash) {
3046 print "<td class=\"link nochange\">";
3048 print "<td class=\"link\">";
3050 print $cgi->a({-href => href(action=>"blobdiff",
3051 hash=>$diff->{'to_id'},
3052 hash_parent=>$from_hash,
3054 hash_parent_base=>$hash_parent,
3055 file_name=>$diff->{'to_file'},
3056 file_parent=>$from_path)},
3062 print "<td class=\"link\">";
3064 print $cgi->a({-href => href(action=>"blob",
3065 hash=>$diff->{'to_id'},
3066 file_name=>$diff->{'to_file'},
3069 print " | " if ($has_history);
3072 print $cgi->a({-href => href(action=>"history",
3073 file_name=>$diff->{'to_file'},
3080 next; # instead of 'else' clause, to avoid extra indent
3082 # else ordinary diff
3084 my ($to_mode_oct, $to_mode_str, $to_file_type);
3085 my ($from_mode_oct, $from_mode_str, $from_file_type);
3086 if ($diff->{'to_mode'} ne ('0' x 6)) {
3087 $to_mode_oct = oct $diff->{'to_mode'};
3088 if (S_ISREG($to_mode_oct)) { # only for regular file
3089 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3091 $to_file_type = file_type($diff->{'to_mode'});
3093 if ($diff->{'from_mode'} ne ('0' x 6)) {
3094 $from_mode_oct = oct $diff->{'from_mode'};
3095 if (S_ISREG($to_mode_oct)) { # only for regular file
3096 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3098 $from_file_type = file_type($diff->{'from_mode'});
3101 if ($diff->{'status'} eq "A") { # created
3102 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3103 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3104 $mode_chng .= "]</span>";
3106 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3107 hash_base=>$hash, file_name=>$diff->{'file'}),
3108 -class => "list"}, esc_path($diff->{'file'}));
3110 print "<td>$mode_chng</td>\n";
3111 print "<td class=\"link\">";
3112 if ($action eq 'commitdiff') {
3115 print $cgi->a({-href => "#patch$patchno"}, "patch");
3118 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3119 hash_base=>$hash, file_name=>$diff->{'file'})},
3123 } elsif ($diff->{'status'} eq "D") { # deleted
3124 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3126 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3127 hash_base=>$parent, file_name=>$diff->{'file'}),
3128 -class => "list"}, esc_path($diff->{'file'}));
3130 print "<td>$mode_chng</td>\n";
3131 print "<td class=\"link\">";
3132 if ($action eq 'commitdiff') {
3135 print $cgi->a({-href => "#patch$patchno"}, "patch");
3138 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3139 hash_base=>$parent, file_name=>$diff->{'file'})},
3142 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3143 file_name=>$diff->{'file'})},
3146 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3147 file_name=>$diff->{'file'})},
3151 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3152 my $mode_chnge = "";
3153 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3154 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3155 if ($from_file_type ne $to_file_type) {
3156 $mode_chnge .= " from $from_file_type to $to_file_type";
3158 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3159 if ($from_mode_str && $to_mode_str) {
3160 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3161 } elsif ($to_mode_str) {
3162 $mode_chnge .= " mode: $to_mode_str";
3165 $mode_chnge .= "]</span>\n";
3168 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3169 hash_base=>$hash, file_name=>$diff->{'file'}),
3170 -class => "list"}, esc_path($diff->{'file'}));
3172 print "<td>$mode_chnge</td>\n";
3173 print "<td class=\"link\">";
3174 if ($action eq 'commitdiff') {
3177 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3179 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3180 # "commit" view and modified file (not onlu mode changed)
3181 print $cgi->a({-href => href(action=>"blobdiff",
3182 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3183 hash_base=>$hash, hash_parent_base=>$parent,
3184 file_name=>$diff->{'file'})},
3188 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3189 hash_base=>$hash, file_name=>$diff->{'file'})},
3192 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3193 file_name=>$diff->{'file'})},
3196 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3197 file_name=>$diff->{'file'})},
3201 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3202 my %status_name = ('R' => 'moved', 'C' => 'copied');
3203 my $nstatus = $status_name{$diff->{'status'}};
3205 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3206 # mode also for directories, so we cannot use $to_mode_str
3207 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3210 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3211 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3212 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3213 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3214 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3215 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3216 -class => "list"}, esc_path($diff->{'from_file'})) .
3217 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3218 "<td class=\"link\">";
3219 if ($action eq 'commitdiff') {
3222 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3224 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3225 # "commit" view and modified file (not only pure rename or copy)
3226 print $cgi->a({-href => href(action=>"blobdiff",
3227 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3228 hash_base=>$hash, hash_parent_base=>$parent,
3229 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3233 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3234 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3237 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3238 file_name=>$diff->{'to_file'})},
3241 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3242 file_name=>$diff->{'to_file'})},
3246 } # we should not encounter Unmerged (U) or Unknown (X) status
3249 print "</tbody>" if $has_header;
3253 sub git_patchset_body {
3254 my ($fd, $difftree, $hash, @hash_parents) = @_;
3255 my ($hash_parent) = $hash_parents[0];
3257 my $is_combined = (@hash_parents > 1);
3259 my $patch_number = 0;
3265 print "<div class=\"patchset\">\n";
3267 # skip to first patch
3268 while ($patch_line = <$fd>) {
3271 last if ($patch_line =~ m/^diff /);
3275 while ($patch_line) {
3277 # parse "git diff" header line
3278 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3279 # $1 is from_name, which we do not use
3280 $to_name = unquote($2);
3281 $to_name =~ s!^b/!!;
3282 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3283 # $1 is 'cc' or 'combined', which we do not use
3284 $to_name = unquote($2);
3289 # check if current patch belong to current raw line
3290 # and parse raw git-diff line if needed
3291 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
3292 # this is continuation of a split patch
3293 print "<div class=\"patch cont\">\n";
3295 # advance raw git-diff output if needed
3296 $patch_idx++ if defined $diffinfo;
3298 # read and prepare patch information
3299 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3301 # compact combined diff output can have some patches skipped
3302 # find which patch (using pathname of result) we are at now;
3304 while ($to_name ne $diffinfo->{'to_file'}) {
3305 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3306 format_diff_cc_simplified($diffinfo, @hash_parents) .
3307 "</div>\n"; # class="patch"
3312 last if $patch_idx > $#$difftree;
3313 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3317 # modifies %from, %to hashes
3318 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3320 # this is first patch for raw difftree line with $patch_idx index
3321 # we index @$difftree array from 0, but number patches from 1
3322 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3326 #assert($patch_line =~ m/^diff /) if DEBUG;
3327 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3329 # print "git diff" header
3330 print format_git_diff_header_line($patch_line, $diffinfo,
3333 # print extended diff header
3334 print "<div class=\"diff extended_header\">\n";
3336 while ($patch_line = <$fd>) {
3339 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
3341 print format_extended_diff_header_line($patch_line, $diffinfo,
3344 print "</div>\n"; # class="diff extended_header"
3346 # from-file/to-file diff header
3347 if (! $patch_line) {
3348 print "</div>\n"; # class="patch"
3351 next PATCH if ($patch_line =~ m/^diff /);
3352 #assert($patch_line =~ m/^---/) if DEBUG;
3354 my $last_patch_line = $patch_line;
3355 $patch_line = <$fd>;
3357 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3359 print format_diff_from_to_header($last_patch_line, $patch_line,
3360 $diffinfo, \%from, \%to,
3365 while ($patch_line = <$fd>) {
3368 next PATCH if ($patch_line =~ m/^diff /);
3370 print format_diff_line($patch_line, \%from, \%to);
3374 print "</div>\n"; # class="patch"
3377 # for compact combined (--cc) format, with chunk and patch simpliciaction
3378 # patchset might be empty, but there might be unprocessed raw lines
3379 for (++$patch_idx if $patch_number > 0;
3380 $patch_idx < @$difftree;
3382 # read and prepare patch information
3383 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3385 # generate anchor for "patch" links in difftree / whatchanged part
3386 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3387 format_diff_cc_simplified($diffinfo, @hash_parents) .
3388 "</div>\n"; # class="patch"
3393 if ($patch_number == 0) {
3394 if (@hash_parents > 1) {
3395 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3397 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3401 print "</div>\n"; # class="patchset"
3404 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3406 sub git_project_list_body {
3407 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3409 my ($check_forks) = gitweb_check_feature('forks');
3412 foreach my $pr (@$projlist) {
3413 my (@aa) = git_get_last_activity($pr->{'path'});
3417 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3418 if (!defined $pr->{'descr'}) {
3419 my $descr = git_get_project_description($pr->{'path'}) || "";
3420 $pr->{'descr_long'} = to_utf8($descr);
3421 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3423 if (!defined $pr->{'owner'}) {
3424 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
3427 my $pname = $pr->{'path'};
3428 if (($pname =~ s/\.git$//) &&
3429 ($pname !~ /\/$/) &&
3430 (-d "$projectroot/$pname")) {
3431 $pr->{'forks'} = "-d $projectroot/$pname";
3437 push @projects, $pr;
3440 $order ||= $default_projects_order;
3441 $from = 0 unless defined $from;
3442 $to = $#projects if (!defined $to || $#projects < $to);
3444 print "<table class=\"project_list\">\n";
3445 unless ($no_header) {
3448 print "<th></th>\n";
3450 if ($order eq "project") {
3451 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3452 print "<th>Project</th>\n";
3455 $cgi->a({-href => href(project=>undef, order=>'project'),
3456 -class => "header"}, "Project") .
3459 if ($order eq "descr") {
3460 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3461 print "<th>Description</th>\n";
3464 $cgi->a({-href => href(project=>undef, order=>'descr'),
3465 -class => "header"}, "Description") .
3468 if ($order eq "owner") {
3469 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3470 print "<th>Owner</th>\n";
3473 $cgi->a({-href => href(project=>undef, order=>'owner'),
3474 -class => "header"}, "Owner") .
3477 if ($order eq "age") {
3478 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3479 print "<th>Last Change</th>\n";
3482 $cgi->a({-href => href(project=>undef, order=>'age'),
3483 -class => "header"}, "Last Change") .
3486 print "<th></th>\n" .
3490 for (my $i = $from; $i <= $to; $i++) {
3491 my $pr = $projects[$i];
3493 print "<tr class=\"dark\">\n";
3495 print "<tr class=\"light\">\n";
3500 if ($pr->{'forks'}) {
3501 print "<!-- $pr->{'forks'} -->\n";
3502 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
3506 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
3507 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
3508 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
3509 -class => "list", -title => $pr->{'descr_long'}},
3510 esc_html($pr->{'descr'})) . "</td>\n" .
3511 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
3512 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
3513 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3514 "<td class=\"link\">" .
3515 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
3516 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
3517 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
3518 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
3519 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
3523 if (defined $extra) {
3526 print "<td></td>\n";
3528 print "<td colspan=\"5\">$extra</td>\n" .
3534 sub git_shortlog_body {
3535 # uses global variable $project
3536 my ($commitlist, $from, $to, $refs, $extra) = @_;
3538 $from = 0 unless defined $from;
3539 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3541 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3543 for (my $i = $from; $i <= $to; $i++) {
3544 my %co = %{$commitlist->[$i]};
3545 my $commit = $co{'id'};
3546 my $ref = format_ref_marker($refs, $commit);
3548 print "<tr class=\"dark\">\n";
3550 print "<tr class=\"light\">\n";
3553 my $author = chop_and_escape_str($co{'author_name'}, 10);
3554 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3555 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3556 "<td><i>" . $author . "</i></td>\n" .
3558 print format_subject_html($co{'title'}, $co{'title_short'},
3559 href(action=>"commit", hash=>$commit), $ref);
3561 "<td class=\"link\">" .
3562 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
3563 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
3564 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
3565 my $snapshot_links = format_snapshot_links($commit);
3566 if (defined $snapshot_links) {
3567 print " | " . $snapshot_links;
3572 if (defined $extra) {
3574 "<td colspan=\"4\">$extra</td>\n" .
3580 sub git_history_body {
3581 # Warning: assumes constant type (blob or tree) during history
3582 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3584 $from = 0 unless defined $from;
3585 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3587 print "<table class=\"history\" cellspacing=\"0\">\n";
3589 for (my $i = $from; $i <= $to; $i++) {
3590 my %co = %{$commitlist->[$i]};
3594 my $commit = $co{'id'};
3596 my $ref = format_ref_marker($refs, $commit);
3599 print "<tr class=\"dark\">\n";
3601 print "<tr class=\"light\">\n";
3604 # shortlog uses chop_str($co{'author_name'}, 10)
3605 my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
3606 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3607 "<td><i>" . $author . "</i></td>\n" .
3609 # originally git_history used chop_str($co{'title'}, 50)
3610 print format_subject_html($co{'title'}, $co{'title_short'},
3611 href(action=>"commit", hash=>$commit), $ref);
3613 "<td class=\"link\">" .
3614 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
3615 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
3617 if ($ftype eq 'blob') {
3618 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
3619 my $blob_parent = git_get_hash_by_path($commit, $file_name);
3620 if (defined $blob_current && defined $blob_parent &&
3621 $blob_current ne $blob_parent) {
3623 $cgi->a({-href => href(action=>"blobdiff",
3624 hash=>$blob_current, hash_parent=>$blob_parent,
3625 hash_base=>$hash_base, hash_parent_base=>$commit,
3626 file_name=>$file_name)},
3633 if (defined $extra) {
3635 "<td colspan=\"4\">$extra</td>\n" .
3642 # uses global variable $project
3643 my ($taglist, $from, $to, $extra) = @_;
3644 $from = 0 unless defined $from;
3645 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3647 print "<table class=\"tags\" cellspacing=\"0\">\n";
3649 for (my $i = $from; $i <= $to; $i++) {
3650 my $entry = $taglist->[$i];
3652 my $comment = $tag{'subject'};
3654 if (defined $comment) {
3655 $comment_short = chop_str($comment, 30, 5);
3658 print "<tr class=\"dark\">\n";
3660 print "<tr class=\"light\">\n";
3663 if (defined $tag{'age'}) {
3664 print "<td><i>$tag{'age'}</i></td>\n";
3666 print "<td></td>\n";
3669 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
3670 -class => "list name"}, esc_html($tag{'name'})) .
3673 if (defined $comment) {
3674 print format_subject_html($comment, $comment_short,
3675 href(action=>"tag", hash=>$tag{'id'}));
3678 "<td class=\"selflink\">";
3679 if ($tag{'type'} eq "tag") {
3680 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
3685 "<td class=\"link\">" . " | " .
3686 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
3687 if ($tag{'reftype'} eq "commit") {
3688 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") .
3689 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log");
3690 } elsif ($tag{'reftype'} eq "blob") {
3691 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
3696 if (defined $extra) {
3698 "<td colspan=\"5\">$extra</td>\n" .
3704 sub git_heads_body {
3705 # uses global variable $project
3706 my ($headlist, $head, $from, $to, $extra) = @_;
3707 $from = 0 unless defined $from;
3708 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3710 print "<table class=\"heads\" cellspacing=\"0\">\n";
3712 for (my $i = $from; $i <= $to; $i++) {
3713 my $entry = $headlist->[$i];
3715 my $curr = $ref{'id'} eq $head;
3717 print "<tr class=\"dark\">\n";
3719 print "<tr class=\"light\">\n";
3722 print "<td><i>$ref{'age'}</i></td>\n" .
3723 ($curr ? "<td class=\"current_head\">" : "<td>") .
3724 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'}),
3725 -class => "list name"},esc_html($ref{'name'})) .
3727 "<td class=\"link\">" .
3728 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'})}, "shortlog") . " | " .
3729 $cgi->a({-href => href(action=>"log", hash=>$ref{'name'})}, "log") . " | " .
3730 $cgi->a({-href => href(action=>"tree", hash=>$ref{'name'}, hash_base=>$ref{'name'})}, "tree") .
3734 if (defined $extra) {
3736 "<td colspan=\"3\">$extra</td>\n" .
3742 sub git_search_grep_body {
3743 my ($commitlist, $from, $to, $extra) = @_;
3744 $from = 0 unless defined $from;
3745 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3747 print "<table class=\"grep\" cellspacing=\"0\">\n";
3749 for (my $i = $from; $i <= $to; $i++) {
3750 my %co = %{$commitlist->[$i]};
3754 my $commit = $co{'id'};
3756 print "<tr class=\"dark\">\n";
3758 print "<tr class=\"light\">\n";
3761 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
3762 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3763 "<td><i>" . $author . "</i></td>\n" .
3765 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
3766 chop_and_escape_str($co{'title'}, 50) . "<br/>");
3767 my $comment = $co{'comment'};
3768 foreach my $line (@$comment) {
3769 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3770 my $lead = esc_html($1) || "";
3771 $lead = chop_str($lead, 30, 10);
3772 my $match = esc_html($2) || "";
3773 my $trail = esc_html($3) || "";
3774 $trail = chop_str($trail, 30, 10);
3775 my $text = "$lead<span class=\"match\">$match</span>$trail";
3776 print chop_str($text, 80, 5) . "<br/>\n";
3780 "<td class=\"link\">" .
3781 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3783 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3787 if (defined $extra) {
3789 "<td colspan=\"3\">$extra</td>\n" .
3795 ## ======================================================================
3796 ## ======================================================================
3799 sub git_project_list {
3800 my $order = $cgi->param('o');
3801 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3802 die_error(undef, "Unknown order parameter");
3805 my @list = git_get_projects_list();
3807 die_error(undef, "No projects found");
3811 if (-f $home_text) {
3812 print "<div class=\"index_include\">\n";
3813 open (my $fd, $home_text);
3818 git_project_list_body(\@list, $order);
3823 my $order = $cgi->param('o');
3824 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3825 die_error(undef, "Unknown order parameter");
3828 my @list = git_get_projects_list($project);
3830 die_error(undef, "No forks found");
3834 git_print_page_nav('','');
3835 git_print_header_div('summary', "$project forks");
3836 git_project_list_body(\@list, $order);
3840 sub git_project_index {
3841 my @projects = git_get_projects_list($project);
3844 -type => 'text/plain',
3845 -charset => 'utf-8',
3846 -content_disposition => 'inline; filename="index.aux"');
3848 foreach my $pr (@projects) {
3849 if (!exists $pr->{'owner'}) {
3850 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
3853 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3854 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3855 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
3856 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
3860 print "$path $owner\n";
3865 my $descr = git_get_project_description($project) || "none";
3866 my %co = parse_commit("HEAD");
3867 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3868 my $head = $co{'id'};
3870 my $owner = git_get_project_owner($project);
3872 my $refs = git_get_references();
3873 # These get_*_list functions return one more to allow us to see if
3874 # there are more ...
3875 my @taglist = git_get_tags_list(16);
3876 my @headlist = git_get_heads_list(16);
3878 my ($check_forks) = gitweb_check_feature('forks');
3881 @forklist = git_get_projects_list($project);
3885 git_print_page_nav('summary','', $head);
3887 print "<div class=\"title\"> </div>\n";
3888 print "<table cellspacing=\"0\">\n" .
3889 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
3890 "<tr><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
3891 if (defined $cd{'rfc2822'}) {
3892 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3895 # use per project git URL list in $projectroot/$project/cloneurl
3896 # or make project git URL from git base URL and project name
3897 my $url_tag = "URL";
3898 my @url_list = git_get_project_url_list($project);
3899 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3900 foreach my $git_url (@url_list) {
3901 next unless $git_url;
3902 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3907 if (-s "$projectroot/$project/README.html") {
3908 if (open my $fd, "$projectroot/$project/README.html") {
3909 print "<div class=\"title\">readme</div>\n";
3910 print $_ while (<$fd>);
3915 # we need to request one more than 16 (0..15) to check if
3917 my @commitlist = $head ? parse_commits($head, 17) : ();
3919 git_print_header_div('shortlog');
3920 git_shortlog_body(\@commitlist, 0, 15, $refs,
3921 $#commitlist <= 15 ? undef :
3922 $cgi->a({-href => href(action=>"shortlog")}, "..."));
3926 git_print_header_div('tags');
3927 git_tags_body(\@taglist, 0, 15,
3928 $#taglist <= 15 ? undef :
3929 $cgi->a({-href => href(action=>"tags")}, "..."));
3933 git_print_header_div('heads');
3934 git_heads_body(\@headlist, $head, 0, 15,
3935 $#headlist <= 15 ? undef :
3936 $cgi->a({-href => href(action=>"heads")}, "..."));
3940 git_print_header_div('forks');
3941 git_project_list_body(\@forklist, undef, 0, 15,
3942 $#forklist <= 15 ? undef :
3943 $cgi->a({-href => href(action=>"forks")}, "..."),
3951 my $head = git_get_head_hash($project);
3953 git_print_page_nav('','', $head,undef,$head);
3954 my %tag = parse_tag($hash);
3957 die_error(undef, "Unknown tag object");
3960 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
3961 print "<div class=\"title_text\">\n" .
3962 "<table cellspacing=\"0\">\n" .
3964 "<td>object</td>\n" .
3965 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
3966 $tag{'object'}) . "</td>\n" .
3967 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
3968 $tag{'type'}) . "</td>\n" .
3970 if (defined($tag{'author'})) {
3971 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
3972 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
3973 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3974 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3977 print "</table>\n\n" .
3979 print "<div class=\"page_body\">";
3980 my $comment = $tag{'comment'};
3981 foreach my $line (@$comment) {
3983 print esc_html($line, -nbsp=>1) . "<br/>\n";
3993 my ($have_blame) = gitweb_check_feature('blame');
3995 die_error('403 Permission denied', "Permission denied");
3997 die_error('404 Not Found', "File name not defined") if (!$file_name);
3998 $hash_base ||= git_get_head_hash($project);
3999 die_error(undef, "Couldn't find base commit") unless ($hash_base);
4000 my %co = parse_commit($hash_base)
4001 or die_error(undef, "Reading commit failed");
4002 if (!defined $hash) {
4003 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4004 or die_error(undef, "Error looking up file");
4006 $ftype = git_get_type($hash);
4007 if ($ftype !~ "blob") {
4008 die_error('400 Bad Request', "Object is not a blob");
4010 open ($fd, "-|", git_cmd(), "blame", '-p', '--',
4011 $file_name, $hash_base)
4012 or die_error(undef, "Open git-blame failed");
4015 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4018 $cgi->a({-href => href(action=>"history", -replay=>1)},
4021 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4023 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4024 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4025 git_print_page_path($file_name, $ftype, $hash_base);
4026 my @rev_color = (qw(light2 dark2));
4027 my $num_colors = scalar(@rev_color);
4028 my $current_color = 0;
4031 <div class="page_body">
4032 <table class="blame">
4033 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4038 last unless defined $_;
4039 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4040 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4041 if (!exists $metainfo{$full_rev}) {
4042 $metainfo{$full_rev} = {};
4044 my $meta = $metainfo{$full_rev};
4047 if (/^(\S+) (.*)$/) {
4053 my $rev = substr($full_rev, 0, 8);
4054 my $author = $meta->{'author'};
4055 my %date = parse_date($meta->{'author-time'},
4056 $meta->{'author-tz'});
4057 my $date = $date{'iso-tz'};
4059 $current_color = ++$current_color % $num_colors;
4061 print "<tr class=\"$rev_color[$current_color]\">\n";
4063 print "<td class=\"sha1\"";
4064 print " title=\"". esc_html($author) . ", $date\"";
4065 print " rowspan=\"$group_size\"" if ($group_size > 1);
4067 print $cgi->a({-href => href(action=>"commit",
4069 file_name=>$file_name)},
4073 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4074 or die_error(undef, "Open git-rev-parse failed");
4075 my $parent_commit = <$dd>;
4077 chomp($parent_commit);
4078 my $blamed = href(action => 'blame',
4079 file_name => $meta->{'filename'},
4080 hash_base => $parent_commit);
4081 print "<td class=\"linenr\">";
4082 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4084 -class => "linenr" },
4087 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4093 or print "Reading blob failed\n";
4100 my ($have_blame) = gitweb_check_feature('blame');
4102 die_error('403 Permission denied', "Permission denied");
4104 die_error('404 Not Found', "File name not defined") if (!$file_name);
4105 $hash_base ||= git_get_head_hash($project);
4106 die_error(undef, "Couldn't find base commit") unless ($hash_base);
4107 my %co = parse_commit($hash_base)
4108 or die_error(undef, "Reading commit failed");
4109 if (!defined $hash) {
4110 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4111 or die_error(undef, "Error lookup file");
4113 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4114 or die_error(undef, "Open git-annotate failed");
4117 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
4120 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
4123 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4125 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4126 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4127 git_print_page_path($file_name, 'blob', $hash_base);
4128 print "<div class=\"page_body\">\n";
4130 <table class="blame">
4139 my @line_class = (qw(light dark));
4140 my $line_class_len = scalar (@line_class);
4141 my $line_class_num = $#line_class;
4142 while (my $line = <$fd>) {
4154 $line_class_num = ($line_class_num + 1) % $line_class_len;
4156 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4163 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4166 $short_rev = substr ($long_rev, 0, 8);
4167 $age = time () - $time;
4168 $age_str = age_string ($age);
4169 $age_str =~ s/ / /g;
4170 $age_class = age_class($age);
4171 $author = esc_html ($author);
4172 $author =~ s/ / /g;
4174 $data = untabify($data);
4175 $data = esc_html ($data);
4178 <tr class="$line_class[$line_class_num]">
4179 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4180 <td class="$age_class">$age_str</td>
4182 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4183 <td class="pre">$data</td>
4186 } # while (my $line = <$fd>)
4187 print "</table>\n\n";
4189 or print "Reading blob failed.\n";
4195 my $head = git_get_head_hash($project);
4197 git_print_page_nav('','', $head,undef,$head);
4198 git_print_header_div('summary', $project);
4200 my @tagslist = git_get_tags_list();
4202 git_tags_body(\@tagslist);
4208 my $head = git_get_head_hash($project);
4210 git_print_page_nav('','', $head,undef,$head);
4211 git_print_header_div('summary', $project);
4213 my @headslist = git_get_heads_list();
4215 git_heads_body(\@headslist, $head);
4220 sub git_blob_plain {
4223 if (!defined $hash) {
4224 if (defined $file_name) {
4225 my $base = $hash_base || git_get_head_hash($project);
4226 $hash = git_get_hash_by_path($base, $file_name, "blob")
4227 or die_error(undef, "Error lookup file");
4229 die_error(undef, "No file name defined");
4231 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4232 # blobs defined by non-textual hash id's can be cached
4237 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4238 or die_error(undef, "Couldn't cat $file_name, $hash");
4240 $type ||= blob_mimetype($fd, $file_name);
4242 # save as filename, even when no $file_name is given
4243 my $save_as = "$hash";
4244 if (defined $file_name) {
4245 $save_as = $file_name;
4246 } elsif ($type =~ m/^text\//) {
4253 -content_disposition => 'inline; filename="' . "$save_as" . '"');
4255 binmode STDOUT, ':raw';
4257 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4265 if (!defined $hash) {
4266 if (defined $file_name) {
4267 my $base = $hash_base || git_get_head_hash($project);
4268 $hash = git_get_hash_by_path($base, $file_name, "blob")
4269 or die_error(undef, "Error lookup file");
4271 die_error(undef, "No file name defined");
4273 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4274 # blobs defined by non-textual hash id's can be cached
4278 my ($have_blame) = gitweb_check_feature('blame');
4279 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4280 or die_error(undef, "Couldn't cat $file_name, $hash");
4281 my $mimetype = blob_mimetype($fd, $file_name);
4282 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4284 return git_blob_plain($mimetype);
4286 # we can have blame only for text/* mimetype
4287 $have_blame &&= ($mimetype =~ m!^text/!);
4289 git_header_html(undef, $expires);
4290 my $formats_nav = '';
4291 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4292 if (defined $file_name) {
4295 $cgi->a({-href => href(action=>"blame", -replay=>1)},
4300 $cgi->a({-href => href(action=>"history", -replay=>1)},
4303 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4306 $cgi->a({-href => href(action=>"blob",
4307 hash_base=>"HEAD", file_name=>$file_name)},
4311 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4314 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4315 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4317 print "<div class=\"page_nav\">\n" .
4318 "<br/><br/></div>\n" .
4319 "<div class=\"title\">$hash</div>\n";
4321 git_print_page_path($file_name, "blob", $hash_base);
4322 print "<div class=\"page_body\">\n";
4323 if ($mimetype =~ m!^text/!) {
4325 while (my $line = <$fd>) {
4328 $line = untabify($line);
4329 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4330 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
4332 } elsif ($mimetype =~ m!^image/!) {
4333 print qq!<img type="$mimetype"!;
4335 print qq! alt="$file_name" title="$file_name"!;
4338 href(action=>"blob_plain", hash=>$hash,
4339 hash_base=>$hash_base, file_name=>$file_name) .
4343 or print "Reading blob failed.\n";
4349 if (!defined $hash_base) {
4350 $hash_base = "HEAD";
4352 if (!defined $hash) {
4353 if (defined $file_name) {
4354 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
4360 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4361 or die_error(undef, "Open git-ls-tree failed");
4362 my @entries = map { chomp; $_ } <$fd>;
4363 close $fd or die_error(undef, "Reading tree failed");
4366 my $refs = git_get_references();
4367 my $ref = format_ref_marker($refs, $hash_base);
4370 my ($have_blame) = gitweb_check_feature('blame');
4371 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4373 if (defined $file_name) {
4375 $cgi->a({-href => href(action=>"history", -replay=>1)},
4377 $cgi->a({-href => href(action=>"tree",
4378 hash_base=>"HEAD", file_name=>$file_name)},
4381 my $snapshot_links = format_snapshot_links($hash);
4382 if (defined $snapshot_links) {
4383 # FIXME: Should be available when we have no hash base as well.
4384 push @views_nav, $snapshot_links;
4386 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4387 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
4390 print "<div class=\"page_nav\">\n";
4391 print "<br/><br/></div>\n";
4392 print "<div class=\"title\">$hash</div>\n";
4394 if (defined $file_name) {
4395 $basedir = $file_name;
4396 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4400 git_print_page_path($file_name, 'tree', $hash_base);
4401 print "<div class=\"page_body\">\n";
4402 print "<table cellspacing=\"0\">\n";
4404 # '..' (top directory) link if possible
4405 if (defined $hash_base &&
4406 defined $file_name && $file_name =~ m![^/]+$!) {
4408 print "<tr class=\"dark\">\n";
4410 print "<tr class=\"light\">\n";
4414 my $up = $file_name;
4415 $up =~ s!/?[^/]+$!!;
4416 undef $up unless $up;
4417 # based on git_print_tree_entry
4418 print '<td class="mode">' . mode_str('040000') . "</td>\n";
4419 print '<td class="list">';
4420 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
4424 print "<td class=\"link\"></td>\n";
4428 foreach my $line (@entries) {
4429 my %t = parse_ls_tree_line($line, -z => 1);
4432 print "<tr class=\"dark\">\n";
4434 print "<tr class=\"light\">\n";
4438 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
4442 print "</table>\n" .
4448 my @supported_fmts = gitweb_check_feature('snapshot');
4449 @supported_fmts = filter_snapshot_fmts(@supported_fmts);
4451 my $format = $cgi->param('sf');
4452 if (!@supported_fmts) {
4453 die_error('403 Permission denied', "Permission denied");
4455 # default to first supported snapshot format
4456 $format ||= $supported_fmts[0];
4457 if ($format !~ m/^[a-z0-9]+$/) {
4458 die_error(undef, "Invalid snapshot format parameter");
4459 } elsif (!exists($known_snapshot_formats{$format})) {
4460 die_error(undef, "Unknown snapshot format");
4461 } elsif (!grep($_ eq $format, @supported_fmts)) {
4462 die_error(undef, "Unsupported snapshot format");
4465 if (!defined $hash) {
4466 $hash = git_get_head_hash($project);
4469 my $git_command = git_cmd_str();
4470 my $name = $project;
4471 $name =~ s,([^/])/*\.git$,$1,;
4472 $name = basename($name);
4473 my $filename = to_utf8($name);
4474 $name =~ s/\047/\047\\\047\047/g;
4476 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4477 $cmd = "$git_command archive " .
4478 "--format=$known_snapshot_formats{$format}{'format'} " .
4479 "--prefix=\'$name\'/ $hash";
4480 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4481 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4485 -type => $known_snapshot_formats{$format}{'type'},
4486 -content_disposition => 'inline; filename="' . "$filename" . '"',
4487 -status => '200 OK');
4489 open my $fd, "-|", $cmd
4490 or die_error(undef, "Execute git-archive failed");
4491 binmode STDOUT, ':raw';
4493 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4498 my $head = git_get_head_hash($project);
4499 if (!defined $hash) {
4502 if (!defined $page) {
4505 my $refs = git_get_references();
4507 my @commitlist = parse_commits($hash, 101, (100 * $page));
4509 my $paging_nav = format_paging_nav('log', $hash, $head, $page, (100 * ($page+1)));
4512 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
4515 my %co = parse_commit($hash);
4517 git_print_header_div('summary', $project);
4518 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4520 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4521 for (my $i = 0; $i <= $to; $i++) {
4522 my %co = %{$commitlist[$i]};
4524 my $commit = $co{'id'};
4525 my $ref = format_ref_marker($refs, $commit);
4526 my %ad = parse_date($co{'author_epoch'});
4527 git_print_header_div('commit',
4528 "<span class=\"age\">$co{'age_string'}</span>" .
4529 esc_html($co{'title'}) . $ref,
4531 print "<div class=\"title_text\">\n" .
4532 "<div class=\"log_link\">\n" .
4533 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
4535 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
4537 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
4540 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4543 print "<div class=\"log_body\">\n";
4544 git_print_log($co{'comment'}, -final_empty_line=> 1);
4547 if ($#commitlist >= 100) {
4548 print "<div class=\"page_nav\">\n";
4549 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
4550 -accesskey => "n", -title => "Alt-n"}, "next");
4557 $hash ||= $hash_base || "HEAD";
4558 my %co = parse_commit($hash);
4560 die_error(undef, "Unknown commit object");
4562 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
4563 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
4565 my $parent = $co{'parent'};
4566 my $parents = $co{'parents'}; # listref
4568 # we need to prepare $formats_nav before any parameter munging
4570 if (!defined $parent) {
4572 $formats_nav .= '(initial)';
4573 } elsif (@$parents == 1) {
4574 # single parent commit
4577 $cgi->a({-href => href(action=>"commit",
4579 esc_html(substr($parent, 0, 7))) .
4586 $cgi->a({-href => href(action=>"commit",
4588 esc_html(substr($_, 0, 7)));
4593 if (!defined $parent) {
4597 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
4599 (@$parents <= 1 ? $parent : '-c'),
4601 or die_error(undef, "Open git-diff-tree failed");
4602 @difftree = map { chomp; $_ } <$fd>;
4603 close $fd or die_error(undef, "Reading git-diff-tree failed");
4605 # non-textual hash id's can be cached
4607 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4610 my $refs = git_get_references();
4611 my $ref = format_ref_marker($refs, $co{'id'});
4613 git_header_html(undef, $expires);
4614 git_print_page_nav('commit', '',
4615 $hash, $co{'tree'}, $hash,
4618 if (defined $co{'parent'}) {
4619 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
4621 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
4623 print "<div class=\"title_text\">\n" .
4624 "<table cellspacing=\"0\">\n";
4625 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
4627 "<td></td><td> $ad{'rfc2822'}";
4628 if ($ad{'hour_local'} < 6) {
4629 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4630 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4632 printf(" (%02d:%02d %s)",
4633 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4637 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
4638 print "<tr><td></td><td> $cd{'rfc2822'}" .
4639 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4641 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4644 "<td class=\"sha1\">" .
4645 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
4646 class => "list"}, $co{'tree'}) .
4648 "<td class=\"link\">" .
4649 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
4651 my $snapshot_links = format_snapshot_links($hash);
4652 if (defined $snapshot_links) {
4653 print " | " . $snapshot_links;
4658 foreach my $par (@$parents) {
4661 "<td class=\"sha1\">" .
4662 $cgi->a({-href => href(action=>"commit", hash=>$par),
4663 class => "list"}, $par) .
4665 "<td class=\"link\">" .
4666 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
4668 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
4675 print "<div class=\"page_body\">\n";
4676 git_print_log($co{'comment'});
4679 git_difftree_body(\@difftree, $hash, @$parents);
4685 # object is defined by:
4686 # - hash or hash_base alone
4687 # - hash_base and file_name
4690 # - hash or hash_base alone
4691 if ($hash || ($hash_base && !defined $file_name)) {
4692 my $object_id = $hash || $hash_base;
4694 my $git_command = git_cmd_str();
4695 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4696 or die_error('404 Not Found', "Object does not exist");
4700 or die_error('404 Not Found', "Object does not exist");
4702 # - hash_base and file_name
4703 } elsif ($hash_base && defined $file_name) {
4704 $file_name =~ s,/+$,,;
4706 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
4707 or die_error('404 Not Found', "Base object does not exist");
4709 # here errors should not hapen
4710 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
4711 or die_error(undef, "Open git-ls-tree failed");
4715 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4716 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4717 die_error('404 Not Found', "File or directory for given base does not exist");
4722 die_error('404 Not Found', "Not enough information to find object");
4725 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
4726 hash=>$hash, hash_base=>$hash_base,
4727 file_name=>$file_name),
4728 -status => '302 Found');
4732 my $format = shift || 'html';
4739 # preparing $fd and %diffinfo for git_patchset_body
4741 if (defined $hash_base && defined $hash_parent_base) {
4742 if (defined $file_name) {
4744 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4745 $hash_parent_base, $hash_base,
4746 "--", (defined $file_parent ? $file_parent : ()), $file_name
4747 or die_error(undef, "Open git-diff-tree failed");
4748 @difftree = map { chomp; $_ } <$fd>;
4750 or die_error(undef, "Reading git-diff-tree failed");
4752 or die_error('404 Not Found', "Blob diff not found");
4754 } elsif (defined $hash &&
4755 $hash =~ /[0-9a-fA-F]{40}/) {
4756 # try to find filename from $hash
4758 # read filtered raw output
4759 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4760 $hash_parent_base, $hash_base, "--"
4761 or die_error(undef, "Open git-diff-tree failed");
4763 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4765 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4766 map { chomp; $_ } <$fd>;
4768 or die_error(undef, "Reading git-diff-tree failed");
4770 or die_error('404 Not Found', "Blob diff not found");
4773 die_error('404 Not Found', "Missing one of the blob diff parameters");
4776 if (@difftree > 1) {
4777 die_error('404 Not Found', "Ambiguous blob diff specification");
4780 %diffinfo = parse_difftree_raw_line($difftree[0]);
4781 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4782 $file_name ||= $diffinfo{'to_file'};
4784 $hash_parent ||= $diffinfo{'from_id'};
4785 $hash ||= $diffinfo{'to_id'};
4787 # non-textual hash id's can be cached
4788 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4789 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4794 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4795 '-p', ($format eq 'html' ? "--full-index" : ()),
4796 $hash_parent_base, $hash_base,
4797 "--", (defined $file_parent ? $file_parent : ()), $file_name
4798 or die_error(undef, "Open git-diff-tree failed");
4801 # old/legacy style URI
4802 if (!%diffinfo && # if new style URI failed
4803 defined $hash && defined $hash_parent) {
4804 # fake git-diff-tree raw output
4805 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4806 $diffinfo{'from_id'} = $hash_parent;
4807 $diffinfo{'to_id'} = $hash;
4808 if (defined $file_name) {
4809 if (defined $file_parent) {
4810 $diffinfo{'status'} = '2';
4811 $diffinfo{'from_file'} = $file_parent;
4812 $diffinfo{'to_file'} = $file_name;
4813 } else { # assume not renamed
4814 $diffinfo{'status'} = '1';
4815 $diffinfo{'from_file'} = $file_name;
4816 $diffinfo{'to_file'} = $file_name;
4818 } else { # no filename given
4819 $diffinfo{'status'} = '2';
4820 $diffinfo{'from_file'} = $hash_parent;
4821 $diffinfo{'to_file'} = $hash;
4824 # non-textual hash id's can be cached
4825 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4826 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4831 open $fd, "-|", git_cmd(), "diff", @diff_opts,
4832 '-p', ($format eq 'html' ? "--full-index" : ()),
4833 $hash_parent, $hash, "--"
4834 or die_error(undef, "Open git-diff failed");
4836 die_error('404 Not Found', "Missing one of the blob diff parameters")
4841 if ($format eq 'html') {
4843 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
4845 git_header_html(undef, $expires);
4846 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4847 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4848 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4850 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4851 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4853 if (defined $file_name) {
4854 git_print_page_path($file_name, "blob", $hash_base);
4856 print "<div class=\"page_path\"></div>\n";
4859 } elsif ($format eq 'plain') {
4861 -type => 'text/plain',
4862 -charset => 'utf-8',
4863 -expires => $expires,
4864 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
4866 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4869 die_error(undef, "Unknown blobdiff format");
4873 if ($format eq 'html') {
4874 print "<div class=\"page_body\">\n";
4876 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
4879 print "</div>\n"; # class="page_body"
4883 while (my $line = <$fd>) {
4884 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4885 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4889 last if $line =~ m!^\+\+\+!;
4897 sub git_blobdiff_plain {
4898 git_blobdiff('plain');
4901 sub git_commitdiff {
4902 my $format = shift || 'html';
4903 $hash ||= $hash_base || "HEAD";
4904 my %co = parse_commit($hash);
4906 die_error(undef, "Unknown commit object");
4909 # choose format for commitdiff for merge
4910 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4911 $hash_parent = '--cc';
4913 # we need to prepare $formats_nav before almost any parameter munging
4915 if ($format eq 'html') {
4917 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
4920 if (defined $hash_parent &&
4921 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4922 # commitdiff with two commits given
4923 my $hash_parent_short = $hash_parent;
4924 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4925 $hash_parent_short = substr($hash_parent, 0, 7);
4929 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4930 if ($co{'parents'}[$i] eq $hash_parent) {
4931 $formats_nav .= ' parent ' . ($i+1);
4935 $formats_nav .= ': ' .
4936 $cgi->a({-href => href(action=>"commitdiff",
4937 hash=>$hash_parent)},
4938 esc_html($hash_parent_short)) .
4940 } elsif (!$co{'parent'}) {
4942 $formats_nav .= ' (initial)';
4943 } elsif (scalar @{$co{'parents'}} == 1) {
4944 # single parent commit
4947 $cgi->a({-href => href(action=>"commitdiff",
4948 hash=>$co{'parent'})},
4949 esc_html(substr($co{'parent'}, 0, 7))) .
4953 if ($hash_parent eq '--cc') {
4954 $formats_nav .= ' | ' .
4955 $cgi->a({-href => href(action=>"commitdiff",
4956 hash=>$hash, hash_parent=>'-c')},
4958 } else { # $hash_parent eq '-c'
4959 $formats_nav .= ' | ' .
4960 $cgi->a({-href => href(action=>"commitdiff",
4961 hash=>$hash, hash_parent=>'--cc')},
4967 $cgi->a({-href => href(action=>"commitdiff",
4969 esc_html(substr($_, 0, 7)));
4970 } @{$co{'parents'}} ) .
4975 my $hash_parent_param = $hash_parent;
4976 if (!defined $hash_parent_param) {
4977 # --cc for multiple parents, --root for parentless
4978 $hash_parent_param =
4979 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4985 if ($format eq 'html') {
4986 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4987 "--no-commit-id", "--patch-with-raw", "--full-index",
4988 $hash_parent_param, $hash, "--"
4989 or die_error(undef, "Open git-diff-tree failed");
4991 while (my $line = <$fd>) {
4993 # empty line ends raw part of diff-tree output
4995 push @difftree, scalar parse_difftree_raw_line($line);
4998 } elsif ($format eq 'plain') {
4999 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5000 '-p', $hash_parent_param, $hash, "--"
5001 or die_error(undef, "Open git-diff-tree failed");
5004 die_error(undef, "Unknown commitdiff format");
5007 # non-textual hash id's can be cached
5009 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5013 # write commit message
5014 if ($format eq 'html') {
5015 my $refs = git_get_references();
5016 my $ref = format_ref_marker($refs, $co{'id'});
5018 git_header_html(undef, $expires);
5019 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5020 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5021 git_print_authorship(\%co);
5022 print "<div class=\"page_body\">\n";
5023 if (@{$co{'comment'}} > 1) {
5024 print "<div class=\"log\">\n";
5025 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5026 print "</div>\n"; # class="log"
5029 } elsif ($format eq 'plain') {
5030 my $refs = git_get_references("tags");
5031 my $tagname = git_get_rev_name_tags($hash);
5032 my $filename = basename($project) . "-$hash.patch";
5035 -type => 'text/plain',
5036 -charset => 'utf-8',
5037 -expires => $expires,
5038 -content_disposition => 'inline; filename="' . "$filename" . '"');
5039 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5042 Date: $ad{'rfc2822'} ($ad{'tz_local'})
5043 Subject: $co{'title'}
5045 print "X-Git-Tag: $tagname\n" if $tagname;
5046 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5048 foreach my $line (@{$co{'comment'}}) {
5055 if ($format eq 'html') {
5056 my $use_parents = !defined $hash_parent ||
5057 $hash_parent eq '-c' || $hash_parent eq '--cc';
5058 git_difftree_body(\@difftree, $hash,
5059 $use_parents ? @{$co{'parents'}} : $hash_parent);
5062 git_patchset_body($fd, \@difftree, $hash,
5063 $use_parents ? @{$co{'parents'}} : $hash_parent);
5065 print "</div>\n"; # class="page_body"
5068 } elsif ($format eq 'plain') {
5072 or print "Reading git-diff-tree failed\n";
5076 sub git_commitdiff_plain {
5077 git_commitdiff('plain');
5081 if (!defined $hash_base) {
5082 $hash_base = git_get_head_hash($project);
5084 if (!defined $page) {
5088 my %co = parse_commit($hash_base);
5090 die_error(undef, "Unknown commit object");
5093 my $refs = git_get_references();
5094 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5096 if (!defined $hash && defined $file_name) {
5097 $hash = git_get_hash_by_path($hash_base, $file_name);
5099 if (defined $hash) {
5100 $ftype = git_get_type($hash);
5103 my @commitlist = parse_commits($hash_base, 101, (100 * $page), "--full-history", $file_name);
5105 my $paging_nav = '';
5108 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5109 file_name=>$file_name)},
5111 $paging_nav .= " ⋅ " .
5112 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5113 -accesskey => "p", -title => "Alt-p"}, "prev");
5115 $paging_nav .= "first";
5116 $paging_nav .= " ⋅ prev";
5119 if ($#commitlist >= 100) {
5121 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5122 -accesskey => "n", -title => "Alt-n"}, "next");
5123 $paging_nav .= " ⋅ $next_link";
5125 $paging_nav .= " ⋅ next";
5129 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5130 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5131 git_print_page_path($file_name, $ftype, $hash_base);
5133 git_history_body(\@commitlist, 0, 99,
5134 $refs, $hash_base, $ftype, $next_link);
5140 my ($have_search) = gitweb_check_feature('search');
5141 if (!$have_search) {
5142 die_error('403 Permission denied', "Permission denied");
5144 if (!defined $searchtext) {
5145 die_error(undef, "Text field empty");
5147 if (!defined $hash) {
5148 $hash = git_get_head_hash($project);
5150 my %co = parse_commit($hash);
5152 die_error(undef, "Unknown commit object");
5154 if (!defined $page) {
5158 $searchtype ||= 'commit';
5159 if ($searchtype eq 'pickaxe') {
5160 # pickaxe may take all resources of your box and run for several minutes
5161 # with every query - so decide by yourself how public you make this feature
5162 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5163 if (!$have_pickaxe) {
5164 die_error('403 Permission denied', "Permission denied");
5167 if ($searchtype eq 'grep') {
5168 my ($have_grep) = gitweb_check_feature('grep');
5170 die_error('403 Permission denied', "Permission denied");
5176 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5178 if ($searchtype eq 'commit') {
5179 $greptype = "--grep=";
5180 } elsif ($searchtype eq 'author') {
5181 $greptype = "--author=";
5182 } elsif ($searchtype eq 'committer') {
5183 $greptype = "--committer=";
5185 $greptype .= $search_regexp;
5186 my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);
5188 my $paging_nav = '';
5191 $cgi->a({-href => href(action=>"search", hash=>$hash,
5192 searchtext=>$searchtext, searchtype=>$searchtype)},
5194 $paging_nav .= " ⋅ " .
5195 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5196 -accesskey => "p", -title => "Alt-p"}, "prev");
5198 $paging_nav .= "first";
5199 $paging_nav .= " ⋅ prev";
5202 if ($#commitlist >= 100) {
5204 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5205 -accesskey => "n", -title => "Alt-n"}, "next");
5206 $paging_nav .= " ⋅ $next_link";
5208 $paging_nav .= " ⋅ next";
5211 if ($#commitlist >= 100) {
5214 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5215 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5216 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5219 if ($searchtype eq 'pickaxe') {
5220 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5221 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5223 print "<table cellspacing=\"0\">\n";
5226 my $git_command = git_cmd_str();
5227 my $searchqtext = $searchtext;
5228 $searchqtext =~ s/'/'\\''/;
5229 open my $fd, "-|", "$git_command rev-list $hash | " .
5230 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5233 while (my $line = <$fd>) {
5234 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5237 $set{'from_id'} = $3;
5239 $set{'id'} = $set{'to_id'};
5240 if ($set{'id'} =~ m/0{40}/) {
5241 $set{'id'} = $set{'from_id'};
5243 if ($set{'id'} =~ m/0{40}/) {
5247 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5250 print "<tr class=\"dark\">\n";
5252 print "<tr class=\"light\">\n";
5255 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5256 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5257 "<td><i>" . $author . "</i></td>\n" .
5259 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
5260 -class => "list subject"},
5261 chop_and_escape_str($co{'title'}, 50) . "<br/>");
5262 while (my $setref = shift @files) {
5264 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
5265 hash=>$set{'id'}, file_name=>$set{'file'}),
5267 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
5271 "<td class=\"link\">" .
5272 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5274 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5278 %co = parse_commit($1);
5286 if ($searchtype eq 'grep') {
5287 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5288 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5290 print "<table cellspacing=\"0\">\n";
5294 open my $fd, "-|", git_cmd(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5296 while (my $line = <$fd>) {
5298 my ($file, $lno, $ltext, $binary);
5299 last if ($matches++ > 1000);
5300 if ($line =~ /^Binary file (.+) matches$/) {
5304 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5306 if ($file ne $lastfile) {
5307 $lastfile and print "</td></tr>\n";
5309 print "<tr class=\"dark\">\n";
5311 print "<tr class=\"light\">\n";
5313 print "<td class=\"list\">".
5314 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5315 file_name=>"$file"),
5316 -class => "list"}, esc_path($file));
5317 print "</td><td>\n";
5321 print "<div class=\"binary\">Binary file</div>\n";
5323 $ltext = untabify($ltext);
5324 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5325 $ltext = esc_html($1, -nbsp=>1);
5326 $ltext .= '<span class="match">';
5327 $ltext .= esc_html($2, -nbsp=>1);
5328 $ltext .= '</span>';
5329 $ltext .= esc_html($3, -nbsp=>1);
5331 $ltext = esc_html($ltext, -nbsp=>1);
5333 print "<div class=\"pre\">" .
5334 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5335 file_name=>"$file").'#l'.$lno,
5336 -class => "linenr"}, sprintf('%4i', $lno))
5337 . ' ' . $ltext . "</div>\n";
5341 print "</td></tr>\n";
5342 if ($matches > 1000) {
5343 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5346 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5355 sub git_search_help {
5357 git_print_page_nav('','', $hash,$hash,$hash);
5360 <dt><b>commit</b></dt>
5361 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5363 my ($have_grep) = gitweb_check_feature('grep');
5366 <dt><b>grep</b></dt>
5367 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5368 a different one) are searched for the given
5369 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5370 (POSIX extended) and the matches are listed. On large
5371 trees, this search can take a while and put some strain on the server, so please use it with
5372 some consideration.</dd>
5376 <dt><b>author</b></dt>
5377 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5378 <dt><b>committer</b></dt>
5379 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5381 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5382 if ($have_pickaxe) {
5384 <dt><b>pickaxe</b></dt>
5385 <dd>All commits that caused the string to appear or disappear from any file (changes that
5386 added, removed or "modified" the string) will be listed. This search can take a while and
5387 takes a lot of strain on the server, so please use it wisely.</dd>
5395 my $head = git_get_head_hash($project);
5396 if (!defined $hash) {
5399 if (!defined $page) {
5402 my $refs = git_get_references();
5404 my @commitlist = parse_commits($hash, 101, (100 * $page));
5406 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, (100 * ($page+1)));
5408 if ($#commitlist >= 100) {
5410 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5411 -accesskey => "n", -title => "Alt-n"}, "next");
5415 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
5416 git_print_header_div('summary', $project);
5418 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
5423 ## ......................................................................
5424 ## feeds (RSS, Atom; OPML)
5427 my $format = shift || 'atom';
5428 my ($have_blame) = gitweb_check_feature('blame');
5430 # Atom: http://www.atomenabled.org/developers/syndication/
5431 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5432 if ($format ne 'rss' && $format ne 'atom') {
5433 die_error(undef, "Unknown web feed format");
5436 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5437 my $head = $hash || 'HEAD';
5438 my @commitlist = parse_commits($head, 150, 0, undef, $file_name);
5442 my $content_type = "application/$format+xml";
5443 if (defined $cgi->http('HTTP_ACCEPT') &&
5444 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5445 # browser (feed reader) prefers text/xml
5446 $content_type = 'text/xml';
5448 if (defined($commitlist[0])) {
5449 %latest_commit = %{$commitlist[0]};
5450 %latest_date = parse_date($latest_commit{'author_epoch'});
5452 -type => $content_type,
5453 -charset => 'utf-8',
5454 -last_modified => $latest_date{'rfc2822'});
5457 -type => $content_type,
5458 -charset => 'utf-8');
5461 # Optimization: skip generating the body if client asks only
5462 # for Last-Modified date.
5463 return if ($cgi->request_method() eq 'HEAD');
5466 my $title = "$site_name - $project/$action";
5467 my $feed_type = 'log';
5468 if (defined $hash) {
5469 $title .= " - '$hash'";
5470 $feed_type = 'branch log';
5471 if (defined $file_name) {
5472 $title .= " :: $file_name";
5473 $feed_type = 'history';
5475 } elsif (defined $file_name) {
5476 $title .= " - $file_name";
5477 $feed_type = 'history';
5479 $title .= " $feed_type";
5480 my $descr = git_get_project_description($project);
5481 if (defined $descr) {
5482 $descr = esc_html($descr);
5484 $descr = "$project " .
5485 ($format eq 'rss' ? 'RSS' : 'Atom') .
5488 my $owner = git_get_project_owner($project);
5489 $owner = esc_html($owner);
5493 if (defined $file_name) {
5494 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
5495 } elsif (defined $hash) {
5496 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
5498 $alt_url = href(-full=>1, action=>"summary");
5500 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
5501 if ($format eq 'rss') {
5503 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5506 print "<title>$title</title>\n" .
5507 "<link>$alt_url</link>\n" .
5508 "<description>$descr</description>\n" .
5509 "<language>en</language>\n";
5510 } elsif ($format eq 'atom') {
5512 <feed xmlns="http://www.w3.org/2005/Atom">
5514 print "<title>$title</title>\n" .
5515 "<subtitle>$descr</subtitle>\n" .
5516 '<link rel="alternate" type="text/html" href="' .
5517 $alt_url . '" />' . "\n" .
5518 '<link rel="self" type="' . $content_type . '" href="' .
5519 $cgi->self_url() . '" />' . "\n" .
5520 "<id>" . href(-full=>1) . "</id>\n" .
5521 # use project owner for feed author
5522 "<author><name>$owner</name></author>\n";
5523 if (defined $favicon) {
5524 print "<icon>" . esc_url($favicon) . "</icon>\n";
5526 if (defined $logo_url) {
5527 # not twice as wide as tall: 72 x 27 pixels
5528 print "<logo>" . esc_url($logo) . "</logo>\n";
5530 if (! %latest_date) {
5531 # dummy date to keep the feed valid until commits trickle in:
5532 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5534 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5539 for (my $i = 0; $i <= $#commitlist; $i++) {
5540 my %co = %{$commitlist[$i]};
5541 my $commit = $co{'id'};
5542 # we read 150, we always show 30 and the ones more recent than 48 hours
5543 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5546 my %cd = parse_date($co{'author_epoch'});
5548 # get list of changed files
5549 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5550 $co{'parent'} || "--root",
5551 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5553 my @difftree = map { chomp; $_ } <$fd>;
5557 # print element (entry, item)
5558 my $co_url = href(-full=>1, action=>"commit", hash=>$commit);
5559 if ($format eq 'rss') {
5561 "<title>" . esc_html($co{'title'}) . "</title>\n" .
5562 "<author>" . esc_html($co{'author'}) . "</author>\n" .
5563 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5564 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5565 "<link>$co_url</link>\n" .
5566 "<description>" . esc_html($co{'title'}) . "</description>\n" .
5567 "<content:encoded>" .
5569 } elsif ($format eq 'atom') {
5571 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
5572 "<updated>$cd{'iso-8601'}</updated>\n" .
5574 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
5575 if ($co{'author_email'}) {
5576 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
5578 print "</author>\n" .
5579 # use committer for contributor
5581 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
5582 if ($co{'committer_email'}) {
5583 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
5585 print "</contributor>\n" .
5586 "<published>$cd{'iso-8601'}</published>\n" .
5587 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5588 "<id>$co_url</id>\n" .
5589 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
5590 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5592 my $comment = $co{'comment'};
5594 foreach my $line (@$comment) {
5595 $line = esc_html($line);
5598 print "</pre><ul>\n";
5599 foreach my $difftree_line (@difftree) {
5600 my %difftree = parse_difftree_raw_line($difftree_line);
5601 next if !$difftree{'from_id'};
5603 my $file = $difftree{'file'} || $difftree{'to_file'};
5607 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
5608 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
5609 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
5610 file_name=>$file, file_parent=>$difftree{'from_file'}),
5611 -title => "diff"}, 'D');
5613 print $cgi->a({-href => href(-full=>1, action=>"blame",
5614 file_name=>$file, hash_base=>$commit),
5615 -title => "blame"}, 'B');
5617 # if this is not a feed of a file history
5618 if (!defined $file_name || $file_name ne $file) {
5619 print $cgi->a({-href => href(-full=>1, action=>"history",
5620 file_name=>$file, hash=>$commit),
5621 -title => "history"}, 'H');
5623 $file = esc_path($file);
5627 if ($format eq 'rss') {
5628 print "</ul>]]>\n" .
5629 "</content:encoded>\n" .
5631 } elsif ($format eq 'atom') {
5632 print "</ul>\n</div>\n" .
5639 if ($format eq 'rss') {
5640 print "</channel>\n</rss>\n";
5641 } elsif ($format eq 'atom') {
5655 my @list = git_get_projects_list();
5657 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
5659 <?xml version="1.0" encoding="utf-8"?>
5660 <opml version="1.0">
5662 <title>$site_name OPML Export</title>
5665 <outline text="git RSS feeds">
5668 foreach my $pr (@list) {
5670 my $head = git_get_head_hash($proj{'path'});
5671 if (!defined $head) {
5674 $git_dir = "$projectroot/$proj{'path'}";
5675 my %co = parse_commit($head);
5680 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
5681 my $rss = "$my_url?p=$proj{'path'};a=rss";
5682 my $html = "$my_url?p=$proj{'path'};a=summary";
5683 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";