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 if (-e $GITWEB_CONFIG) {
375 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
376 do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
379 # version of the core git binary
380 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
382 $projects_list ||= $projectroot;
384 # ======================================================================
385 # input validation and dispatch
386 our $action = $cgi->param('a');
387 if (defined $action) {
388 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
389 die_error(undef, "Invalid action parameter");
393 # parameters which are pathnames
394 our $project = $cgi->param('p');
395 if (defined $project) {
396 if (!validate_pathname($project) ||
397 !(-d "$projectroot/$project") ||
398 !check_head_link("$projectroot/$project") ||
399 ($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
400 ($strict_export && !project_in_list($project))) {
402 die_error(undef, "No such project");
406 our $file_name = $cgi->param('f');
407 if (defined $file_name) {
408 if (!validate_pathname($file_name)) {
409 die_error(undef, "Invalid file parameter");
413 our $file_parent = $cgi->param('fp');
414 if (defined $file_parent) {
415 if (!validate_pathname($file_parent)) {
416 die_error(undef, "Invalid file parent parameter");
420 # parameters which are refnames
421 our $hash = $cgi->param('h');
423 if (!validate_refname($hash)) {
424 die_error(undef, "Invalid hash parameter");
428 our $hash_parent = $cgi->param('hp');
429 if (defined $hash_parent) {
430 if (!validate_refname($hash_parent)) {
431 die_error(undef, "Invalid hash parent parameter");
435 our $hash_base = $cgi->param('hb');
436 if (defined $hash_base) {
437 if (!validate_refname($hash_base)) {
438 die_error(undef, "Invalid hash base parameter");
442 my %allowed_options = (
443 "--no-merges" => [ qw(rss atom log shortlog history) ],
446 our @extra_options = $cgi->param('opt');
447 if (defined @extra_options) {
448 foreach my $opt (@extra_options) {
449 if (not exists $allowed_options{$opt}) {
450 die_error(undef, "Invalid option parameter");
452 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
453 die_error(undef, "Invalid option parameter for this action");
458 our $hash_parent_base = $cgi->param('hpb');
459 if (defined $hash_parent_base) {
460 if (!validate_refname($hash_parent_base)) {
461 die_error(undef, "Invalid hash parent base parameter");
466 our $page = $cgi->param('pg');
468 if ($page =~ m/[^0-9]/) {
469 die_error(undef, "Invalid page parameter");
473 our $searchtype = $cgi->param('st');
474 if (defined $searchtype) {
475 if ($searchtype =~ m/[^a-z]/) {
476 die_error(undef, "Invalid searchtype parameter");
480 our $search_use_regexp = $cgi->param('sr');
482 our $searchtext = $cgi->param('s');
484 if (defined $searchtext) {
485 if (length($searchtext) < 2) {
486 die_error(undef, "At least two characters are required for search parameter");
488 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
491 # now read PATH_INFO and use it as alternative to parameters
492 sub evaluate_path_info {
493 return if defined $project;
494 my $path_info = $ENV{"PATH_INFO"};
495 return if !$path_info;
496 $path_info =~ s,^/+,,;
497 return if !$path_info;
498 # find which part of PATH_INFO is project
499 $project = $path_info;
501 while ($project && !check_head_link("$projectroot/$project")) {
502 $project =~ s,/*[^/]*$,,;
505 $project = validate_pathname($project);
507 ($export_ok && !-e "$projectroot/$project/$export_ok") ||
508 ($strict_export && !project_in_list($project))) {
512 # do not change any parameters if an action is given using the query string
514 $path_info =~ s,^\Q$project\E/*,,;
515 my ($refname, $pathname) = split(/:/, $path_info, 2);
516 if (defined $pathname) {
517 # we got "project.git/branch:filename" or "project.git/branch:dir/"
518 # we could use git_get_type(branch:pathname), but it needs $git_dir
519 $pathname =~ s,^/+,,;
520 if (!$pathname || substr($pathname, -1) eq "/") {
524 $action ||= "blob_plain";
526 $hash_base ||= validate_refname($refname);
527 $file_name ||= validate_pathname($pathname);
528 } elsif (defined $refname) {
529 # we got "project.git/branch"
530 $action ||= "shortlog";
531 $hash ||= validate_refname($refname);
534 evaluate_path_info();
536 # path to the current git repository
538 $git_dir = "$projectroot/$project" if $project;
542 "blame" => \&git_blame2,
543 "blobdiff" => \&git_blobdiff,
544 "blobdiff_plain" => \&git_blobdiff_plain,
545 "blob" => \&git_blob,
546 "blob_plain" => \&git_blob_plain,
547 "commitdiff" => \&git_commitdiff,
548 "commitdiff_plain" => \&git_commitdiff_plain,
549 "commit" => \&git_commit,
550 "forks" => \&git_forks,
551 "heads" => \&git_heads,
552 "history" => \&git_history,
555 "atom" => \&git_atom,
556 "search" => \&git_search,
557 "search_help" => \&git_search_help,
558 "shortlog" => \&git_shortlog,
559 "summary" => \&git_summary,
561 "tags" => \&git_tags,
562 "tree" => \&git_tree,
563 "snapshot" => \&git_snapshot,
564 "object" => \&git_object,
565 # those below don't need $project
566 "opml" => \&git_opml,
567 "project_list" => \&git_project_list,
568 "project_index" => \&git_project_index,
571 if (!defined $action) {
573 $action = git_get_type($hash);
574 } elsif (defined $hash_base && defined $file_name) {
575 $action = git_get_type("$hash_base:$file_name");
576 } elsif (defined $project) {
579 $action = 'project_list';
582 if (!defined($actions{$action})) {
583 die_error(undef, "Unknown action");
585 if ($action !~ m/^(opml|project_list|project_index)$/ &&
587 die_error(undef, "Project needed");
589 $actions{$action}->();
592 ## ======================================================================
597 # default is to use -absolute url() i.e. $my_uri
598 my $href = $params{-full} ? $my_url : $my_uri;
600 # XXX: Warning: If you touch this, check the search form for updating,
611 hash_parent_base => "hpb",
616 snapshot_format => "sf",
617 extra_options => "opt",
618 search_use_regexp => "sr",
620 my %mapping = @mapping;
622 $params{'project'} = $project unless exists $params{'project'};
624 if ($params{-replay}) {
625 while (my ($name, $symbol) = each %mapping) {
626 if (!exists $params{$name}) {
627 # to allow for multivalued params we use arrayref form
628 $params{$name} = [ $cgi->param($symbol) ];
633 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
635 # use PATH_INFO for project name
636 $href .= "/".esc_url($params{'project'}) if defined $params{'project'};
637 delete $params{'project'};
639 # Summary just uses the project path URL
640 if (defined $params{'action'} && $params{'action'} eq 'summary') {
641 delete $params{'action'};
645 # now encode the parameters explicitly
647 for (my $i = 0; $i < @mapping; $i += 2) {
648 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
649 if (defined $params{$name}) {
650 if (ref($params{$name}) eq "ARRAY") {
651 foreach my $par (@{$params{$name}}) {
652 push @result, $symbol . "=" . esc_param($par);
655 push @result, $symbol . "=" . esc_param($params{$name});
659 $href .= "?" . join(';', @result) if scalar @result;
665 ## ======================================================================
666 ## validation, quoting/unquoting and escaping
668 sub validate_pathname {
669 my $input = shift || return undef;
671 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
672 # at the beginning, at the end, and between slashes.
673 # also this catches doubled slashes
674 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
678 if ($input =~ m!\0!) {
684 sub validate_refname {
685 my $input = shift || return undef;
687 # textual hashes are O.K.
688 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
691 # it must be correct pathname
692 $input = validate_pathname($input)
694 # restrictions on ref name according to git-check-ref-format
695 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
701 # decode sequences of octets in utf8 into Perl's internal form,
702 # which is utf-8 with utf8 flag set if needed. gitweb writes out
703 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
706 if (utf8::valid($str)) {
710 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
714 # quote unsafe chars, but keep the slash, even when it's not
715 # correct, but quoted slashes look too horrible in bookmarks
718 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
724 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
727 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
733 # replace invalid utf8 character with SUBSTITUTION sequence
738 $str = to_utf8($str);
739 $str = $cgi->escapeHTML($str);
740 if ($opts{'-nbsp'}) {
741 $str =~ s/ / /g;
743 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
747 # quote control characters and escape filename to HTML
752 $str = to_utf8($str);
753 $str = $cgi->escapeHTML($str);
754 if ($opts{'-nbsp'}) {
755 $str =~ s/ / /g;
757 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
761 # Make control characters "printable", using character escape codes (CEC)
765 my %es = ( # character escape codes, aka escape sequences
766 "\t" => '\t', # tab (HT)
767 "\n" => '\n', # line feed (LF)
768 "\r" => '\r', # carrige return (CR)
769 "\f" => '\f', # form feed (FF)
770 "\b" => '\b', # backspace (BS)
771 "\a" => '\a', # alarm (bell) (BEL)
772 "\e" => '\e', # escape (ESC)
773 "\013" => '\v', # vertical tab (VT)
774 "\000" => '\0', # nul character (NUL)
776 my $chr = ( (exists $es{$cntrl})
778 : sprintf('\%03o', ord($cntrl)) );
779 if ($opts{-nohtml}) {
782 return "<span class=\"cntrl\">$chr</span>";
786 # Alternatively use unicode control pictures codepoints,
787 # Unicode "printable representation" (PR)
792 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
793 if ($opts{-nohtml}) {
796 return "<span class=\"cntrl\">$chr</span>";
800 # git may return quoted and escaped filenames
806 my %es = ( # character escape codes, aka escape sequences
807 't' => "\t", # tab (HT, TAB)
808 'n' => "\n", # newline (NL)
809 'r' => "\r", # return (CR)
810 'f' => "\f", # form feed (FF)
811 'b' => "\b", # backspace (BS)
812 'a' => "\a", # alarm (bell) (BEL)
813 'e' => "\e", # escape (ESC)
814 'v' => "\013", # vertical tab (VT)
817 if ($seq =~ m/^[0-7]{1,3}$/) {
818 # octal char sequence
819 return chr(oct($seq));
820 } elsif (exists $es{$seq}) {
821 # C escape sequence, aka character escape code
824 # quoted ordinary character
828 if ($str =~ m/^"(.*)"$/) {
831 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
836 # escape tabs (convert tabs to spaces)
840 while ((my $pos = index($line, "\t")) != -1) {
841 if (my $count = (8 - ($pos % 8))) {
842 my $spaces = ' ' x $count;
843 $line =~ s/\t/$spaces/;
850 sub project_in_list {
852 my @list = git_get_projects_list();
853 return @list && scalar(grep { $_->{'path'} eq $project } @list);
856 ## ----------------------------------------------------------------------
857 ## HTML aware string manipulation
859 # Try to chop given string on a word boundary between position
860 # $len and $len+$add_len. If there is no word boundary there,
861 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
862 # (marking chopped part) would be longer than given string.
866 my $add_len = shift || 10;
867 my $where = shift || 'right'; # 'left' | 'center' | 'right'
869 # Make sure perl knows it is utf8 encoded so we don't
870 # cut in the middle of a utf8 multibyte char.
871 $str = to_utf8($str);
873 # allow only $len chars, but don't cut a word if it would fit in $add_len
874 # if it doesn't fit, cut it if it's still longer than the dots we would add
875 # remove chopped character entities entirely
877 # when chopping in the middle, distribute $len into left and right part
878 # return early if chopping wouldn't make string shorter
879 if ($where eq 'center') {
880 return $str if ($len + 5 >= length($str)); # filler is length 5
883 return $str if ($len + 4 >= length($str)); # filler is length 4
886 # regexps: ending and beginning with word part up to $add_len
887 my $endre = qr/.{$len}\w{0,$add_len}/;
888 my $begre = qr/\w{0,$add_len}.{$len}/;
890 if ($where eq 'left') {
891 $str =~ m/^(.*?)($begre)$/;
892 my ($lead, $body) = ($1, $2);
893 if (length($lead) > 4) {
894 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
899 } elsif ($where eq 'center') {
900 $str =~ m/^($endre)(.*)$/;
901 my ($left, $str) = ($1, $2);
902 $str =~ m/^(.*?)($begre)$/;
903 my ($mid, $right) = ($1, $2);
904 if (length($mid) > 5) {
905 $left =~ s/&[^;]*$//;
906 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
909 return "$left$mid$right";
912 $str =~ m/^($endre)(.*)$/;
915 if (length($tail) > 4) {
916 $body =~ s/&[^;]*$//;
923 # takes the same arguments as chop_str, but also wraps a <span> around the
924 # result with a title attribute if it does get chopped. Additionally, the
925 # string is HTML-escaped.
926 sub chop_and_escape_str {
929 my $chopped = chop_str(@_);
930 if ($chopped eq $str) {
931 return esc_html($chopped);
933 $str =~ s/([[:cntrl:]])/?/g;
934 return $cgi->span({-title=>$str}, esc_html($chopped));
938 ## ----------------------------------------------------------------------
939 ## functions returning short strings
941 # CSS class for given age value (in seconds)
947 } elsif ($age < 60*60*2) {
949 } elsif ($age < 60*60*24*2) {
956 # convert age in seconds to "nn units ago" string
961 if ($age > 60*60*24*365*2) {
962 $age_str = (int $age/60/60/24/365);
963 $age_str .= " years ago";
964 } elsif ($age > 60*60*24*(365/12)*2) {
965 $age_str = int $age/60/60/24/(365/12);
966 $age_str .= " months ago";
967 } elsif ($age > 60*60*24*7*2) {
968 $age_str = int $age/60/60/24/7;
969 $age_str .= " weeks ago";
970 } elsif ($age > 60*60*24*2) {
971 $age_str = int $age/60/60/24;
972 $age_str .= " days ago";
973 } elsif ($age > 60*60*2) {
974 $age_str = int $age/60/60;
975 $age_str .= " hours ago";
976 } elsif ($age > 60*2) {
977 $age_str = int $age/60;
978 $age_str .= " min ago";
981 $age_str .= " sec ago";
983 $age_str .= " right now";
989 S_IFINVALID => 0030000,
990 S_IFGITLINK => 0160000,
993 # submodule/subproject, a commit object reference
997 return (($mode & S_IFMT) == S_IFGITLINK)
1000 # convert file mode in octal to symbolic file mode string
1002 my $mode = oct shift;
1004 if (S_ISGITLINK($mode)) {
1005 return 'm---------';
1006 } elsif (S_ISDIR($mode & S_IFMT)) {
1007 return 'drwxr-xr-x';
1008 } elsif (S_ISLNK($mode)) {
1009 return 'lrwxrwxrwx';
1010 } elsif (S_ISREG($mode)) {
1011 # git cares only about the executable bit
1012 if ($mode & S_IXUSR) {
1013 return '-rwxr-xr-x';
1015 return '-rw-r--r--';
1018 return '----------';
1022 # convert file mode in octal to file type string
1026 if ($mode !~ m/^[0-7]+$/) {
1032 if (S_ISGITLINK($mode)) {
1034 } elsif (S_ISDIR($mode & S_IFMT)) {
1036 } elsif (S_ISLNK($mode)) {
1038 } elsif (S_ISREG($mode)) {
1045 # convert file mode in octal to file type description string
1046 sub file_type_long {
1049 if ($mode !~ m/^[0-7]+$/) {
1055 if (S_ISGITLINK($mode)) {
1057 } elsif (S_ISDIR($mode & S_IFMT)) {
1059 } elsif (S_ISLNK($mode)) {
1061 } elsif (S_ISREG($mode)) {
1062 if ($mode & S_IXUSR) {
1063 return "executable";
1073 ## ----------------------------------------------------------------------
1074 ## functions returning short HTML fragments, or transforming HTML fragments
1075 ## which don't belong to other sections
1077 # format line of commit message.
1078 sub format_log_line_html {
1081 $line = esc_html($line, -nbsp=>1);
1082 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1085 $cgi->a({-href => href(action=>"object", hash=>$hash_text),
1086 -class => "text"}, $hash_text);
1087 $line =~ s/$hash_text/$link/;
1092 # format marker of refs pointing to given object
1093 sub format_ref_marker {
1094 my ($refs, $id) = @_;
1097 if (defined $refs->{$id}) {
1098 foreach my $ref (@{$refs->{$id}}) {
1099 my ($type, $name) = qw();
1100 # e.g. tags/v2.6.11 or heads/next
1101 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1109 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1110 esc_html($name) . "</span>";
1115 return ' <span class="refs">'. $markers . '</span>';
1121 # format, perhaps shortened and with markers, title line
1122 sub format_subject_html {
1123 my ($long, $short, $href, $extra) = @_;
1124 $extra = '' unless defined($extra);
1126 if (length($short) < length($long)) {
1127 return $cgi->a({-href => $href, -class => "list subject",
1128 -title => to_utf8($long)},
1129 esc_html($short) . $extra);
1131 return $cgi->a({-href => $href, -class => "list subject"},
1132 esc_html($long) . $extra);
1136 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1137 sub format_git_diff_header_line {
1139 my $diffinfo = shift;
1140 my ($from, $to) = @_;
1142 if ($diffinfo->{'nparents'}) {
1144 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1145 if ($to->{'href'}) {
1146 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1147 esc_path($to->{'file'}));
1148 } else { # file was deleted (no href)
1149 $line .= esc_path($to->{'file'});
1153 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1154 if ($from->{'href'}) {
1155 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1156 'a/' . esc_path($from->{'file'}));
1157 } else { # file was added (no href)
1158 $line .= 'a/' . esc_path($from->{'file'});
1161 if ($to->{'href'}) {
1162 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1163 'b/' . esc_path($to->{'file'}));
1164 } else { # file was deleted
1165 $line .= 'b/' . esc_path($to->{'file'});
1169 return "<div class=\"diff header\">$line</div>\n";
1172 # format extended diff header line, before patch itself
1173 sub format_extended_diff_header_line {
1175 my $diffinfo = shift;
1176 my ($from, $to) = @_;
1179 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1180 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1181 esc_path($from->{'file'}));
1183 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1184 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1185 esc_path($to->{'file'}));
1187 # match single <mode>
1188 if ($line =~ m/\s(\d{6})$/) {
1189 $line .= '<span class="info"> (' .
1190 file_type_long($1) .
1194 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1195 # can match only for combined diff
1197 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1198 if ($from->{'href'}[$i]) {
1199 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1201 substr($diffinfo->{'from_id'}[$i],0,7));
1206 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1209 if ($to->{'href'}) {
1210 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1211 substr($diffinfo->{'to_id'},0,7));
1216 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1217 # can match only for ordinary diff
1218 my ($from_link, $to_link);
1219 if ($from->{'href'}) {
1220 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1221 substr($diffinfo->{'from_id'},0,7));
1223 $from_link = '0' x 7;
1225 if ($to->{'href'}) {
1226 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1227 substr($diffinfo->{'to_id'},0,7));
1231 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1232 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1235 return $line . "<br/>\n";
1238 # format from-file/to-file diff header
1239 sub format_diff_from_to_header {
1240 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1245 #assert($line =~ m/^---/) if DEBUG;
1246 # no extra formatting for "^--- /dev/null"
1247 if (! $diffinfo->{'nparents'}) {
1248 # ordinary (single parent) diff
1249 if ($line =~ m!^--- "?a/!) {
1250 if ($from->{'href'}) {
1252 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1253 esc_path($from->{'file'}));
1256 esc_path($from->{'file'});
1259 $result .= qq!<div class="diff from_file">$line</div>\n!;
1262 # combined diff (merge commit)
1263 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1264 if ($from->{'href'}[$i]) {
1266 $cgi->a({-href=>href(action=>"blobdiff",
1267 hash_parent=>$diffinfo->{'from_id'}[$i],
1268 hash_parent_base=>$parents[$i],
1269 file_parent=>$from->{'file'}[$i],
1270 hash=>$diffinfo->{'to_id'},
1272 file_name=>$to->{'file'}),
1274 -title=>"diff" . ($i+1)},
1277 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1278 esc_path($from->{'file'}[$i]));
1280 $line = '--- /dev/null';
1282 $result .= qq!<div class="diff from_file">$line</div>\n!;
1287 #assert($line =~ m/^\+\+\+/) if DEBUG;
1288 # no extra formatting for "^+++ /dev/null"
1289 if ($line =~ m!^\+\+\+ "?b/!) {
1290 if ($to->{'href'}) {
1292 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1293 esc_path($to->{'file'}));
1296 esc_path($to->{'file'});
1299 $result .= qq!<div class="diff to_file">$line</div>\n!;
1304 # create note for patch simplified by combined diff
1305 sub format_diff_cc_simplified {
1306 my ($diffinfo, @parents) = @_;
1309 $result .= "<div class=\"diff header\">" .
1311 if (!is_deleted($diffinfo)) {
1312 $result .= $cgi->a({-href => href(action=>"blob",
1314 hash=>$diffinfo->{'to_id'},
1315 file_name=>$diffinfo->{'to_file'}),
1317 esc_path($diffinfo->{'to_file'}));
1319 $result .= esc_path($diffinfo->{'to_file'});
1321 $result .= "</div>\n" . # class="diff header"
1322 "<div class=\"diff nodifferences\">" .
1324 "</div>\n"; # class="diff nodifferences"
1329 # format patch (diff) line (not to be used for diff headers)
1330 sub format_diff_line {
1332 my ($from, $to) = @_;
1333 my $diff_class = "";
1337 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1339 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1340 if ($line =~ m/^\@{3}/) {
1341 $diff_class = " chunk_header";
1342 } elsif ($line =~ m/^\\/) {
1343 $diff_class = " incomplete";
1344 } elsif ($prefix =~ tr/+/+/) {
1345 $diff_class = " add";
1346 } elsif ($prefix =~ tr/-/-/) {
1347 $diff_class = " rem";
1350 # assume ordinary diff
1351 my $char = substr($line, 0, 1);
1353 $diff_class = " add";
1354 } elsif ($char eq '-') {
1355 $diff_class = " rem";
1356 } elsif ($char eq '@') {
1357 $diff_class = " chunk_header";
1358 } elsif ($char eq "\\") {
1359 $diff_class = " incomplete";
1362 $line = untabify($line);
1363 if ($from && $to && $line =~ m/^\@{2} /) {
1364 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1365 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1367 $from_lines = 0 unless defined $from_lines;
1368 $to_lines = 0 unless defined $to_lines;
1370 if ($from->{'href'}) {
1371 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1372 -class=>"list"}, $from_text);
1374 if ($to->{'href'}) {
1375 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1376 -class=>"list"}, $to_text);
1378 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1379 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1380 return "<div class=\"diff$diff_class\">$line</div>\n";
1381 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1382 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1383 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1385 @from_text = split(' ', $ranges);
1386 for (my $i = 0; $i < @from_text; ++$i) {
1387 ($from_start[$i], $from_nlines[$i]) =
1388 (split(',', substr($from_text[$i], 1)), 0);
1391 $to_text = pop @from_text;
1392 $to_start = pop @from_start;
1393 $to_nlines = pop @from_nlines;
1395 $line = "<span class=\"chunk_info\">$prefix ";
1396 for (my $i = 0; $i < @from_text; ++$i) {
1397 if ($from->{'href'}[$i]) {
1398 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1399 -class=>"list"}, $from_text[$i]);
1401 $line .= $from_text[$i];
1405 if ($to->{'href'}) {
1406 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1407 -class=>"list"}, $to_text);
1411 $line .= " $prefix</span>" .
1412 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1413 return "<div class=\"diff$diff_class\">$line</div>\n";
1415 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1418 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1419 # linked. Pass the hash of the tree/commit to snapshot.
1420 sub format_snapshot_links {
1422 my @snapshot_fmts = gitweb_check_feature('snapshot');
1423 @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
1424 my $num_fmts = @snapshot_fmts;
1425 if ($num_fmts > 1) {
1426 # A parenthesized list of links bearing format names.
1427 # e.g. "snapshot (_tar.gz_ _zip_)"
1428 return "snapshot (" . join(' ', map
1435 }, $known_snapshot_formats{$_}{'display'})
1436 , @snapshot_fmts) . ")";
1437 } elsif ($num_fmts == 1) {
1438 # A single "snapshot" link whose tooltip bears the format name.
1440 my ($fmt) = @snapshot_fmts;
1446 snapshot_format=>$fmt
1448 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1450 } else { # $num_fmts == 0
1455 ## ......................................................................
1456 ## functions returning values to be passed, perhaps after some
1457 ## transformation, to other functions; e.g. returning arguments to href()
1459 # returns hash to be passed to href to generate gitweb URL
1460 # in -title key it returns description of link
1462 my $format = shift || 'Atom';
1463 my %res = (action => lc($format));
1465 # feed links are possible only for project views
1466 return unless (defined $project);
1467 # some views should link to OPML, or to generic project feed,
1468 # or don't have specific feed yet (so they should use generic)
1469 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1472 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1473 # from tag links; this also makes possible to detect branch links
1474 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1475 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1478 # find log type for feed description (title)
1480 if (defined $file_name) {
1481 $type = "history of $file_name";
1482 $type .= "/" if ($action eq 'tree');
1483 $type .= " on '$branch'" if (defined $branch);
1485 $type = "log of $branch" if (defined $branch);
1488 $res{-title} = $type;
1489 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1490 $res{'file_name'} = $file_name;
1495 ## ----------------------------------------------------------------------
1496 ## git utility subroutines, invoking git commands
1498 # returns path to the core git executable and the --git-dir parameter as list
1500 return $GIT, '--git-dir='.$git_dir;
1503 # returns path to the core git executable and the --git-dir parameter as string
1505 return join(' ', git_cmd());
1508 # get HEAD ref of given project as hash
1509 sub git_get_head_hash {
1510 my $project = shift;
1511 my $o_git_dir = $git_dir;
1513 $git_dir = "$projectroot/$project";
1514 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1517 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1521 if (defined $o_git_dir) {
1522 $git_dir = $o_git_dir;
1527 # get type of given object
1531 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1533 close $fd or return;
1538 # repository configuration
1539 our $config_file = '';
1542 # store multiple values for single key as anonymous array reference
1543 # single values stored directly in the hash, not as [ <value> ]
1544 sub hash_set_multi {
1545 my ($hash, $key, $value) = @_;
1547 if (!exists $hash->{$key}) {
1548 $hash->{$key} = $value;
1549 } elsif (!ref $hash->{$key}) {
1550 $hash->{$key} = [ $hash->{$key}, $value ];
1552 push @{$hash->{$key}}, $value;
1556 # return hash of git project configuration
1557 # optionally limited to some section, e.g. 'gitweb'
1558 sub git_parse_project_config {
1559 my $section_regexp = shift;
1564 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
1567 while (my $keyval = <$fh>) {
1569 my ($key, $value) = split(/\n/, $keyval, 2);
1571 hash_set_multi(\%config, $key, $value)
1572 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1579 # convert config value to boolean, 'true' or 'false'
1580 # no value, number > 0, 'true' and 'yes' values are true
1581 # rest of values are treated as false (never as error)
1582 sub config_to_bool {
1585 # strip leading and trailing whitespace
1589 return (!defined $val || # section.key
1590 ($val =~ /^\d+$/ && $val) || # section.key = 1
1591 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1594 # convert config value to simple decimal number
1595 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1596 # to be multiplied by 1024, 1048576, or 1073741824
1600 # strip leading and trailing whitespace
1604 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1606 # unknown unit is treated as 1
1607 return $num * ($unit eq 'g' ? 1073741824 :
1608 $unit eq 'm' ? 1048576 :
1609 $unit eq 'k' ? 1024 : 1);
1614 # convert config value to array reference, if needed
1615 sub config_to_multi {
1618 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1621 sub git_get_project_config {
1622 my ($key, $type) = @_;
1625 return unless ($key);
1626 $key =~ s/^gitweb\.//;
1627 return if ($key =~ m/\W/);
1630 if (defined $type) {
1633 unless ($type eq 'bool' || $type eq 'int');
1637 if (!defined $config_file ||
1638 $config_file ne "$git_dir/config") {
1639 %config = git_parse_project_config('gitweb');
1640 $config_file = "$git_dir/config";
1644 if (!defined $type) {
1645 return $config{"gitweb.$key"};
1646 } elsif ($type eq 'bool') {
1647 # backward compatibility: 'git config --bool' returns true/false
1648 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
1649 } elsif ($type eq 'int') {
1650 return config_to_int($config{"gitweb.$key"});
1652 return $config{"gitweb.$key"};
1655 # get hash of given path at given ref
1656 sub git_get_hash_by_path {
1658 my $path = shift || return undef;
1663 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
1664 or die_error(undef, "Open git-ls-tree failed");
1666 close $fd or return undef;
1668 if (!defined $line) {
1669 # there is no tree or hash given by $path at $base
1673 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1674 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1675 if (defined $type && $type ne $2) {
1676 # type doesn't match
1682 # get path of entry with given hash at given tree-ish (ref)
1683 # used to get 'from' filename for combined diff (merge commit) for renames
1684 sub git_get_path_by_hash {
1685 my $base = shift || return;
1686 my $hash = shift || return;
1690 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
1692 while (my $line = <$fd>) {
1695 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1696 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1697 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1706 ## ......................................................................
1707 ## git utility functions, directly accessing git repository
1709 sub git_get_project_description {
1712 $git_dir = "$projectroot/$path";
1713 open my $fd, "$git_dir/description"
1714 or return git_get_project_config('description');
1717 if (defined $descr) {
1723 sub git_get_project_url_list {
1726 $git_dir = "$projectroot/$path";
1727 open my $fd, "$git_dir/cloneurl"
1728 or return wantarray ?
1729 @{ config_to_multi(git_get_project_config('url')) } :
1730 config_to_multi(git_get_project_config('url'));
1731 my @git_project_url_list = map { chomp; $_ } <$fd>;
1734 return wantarray ? @git_project_url_list : \@git_project_url_list;
1737 sub git_get_projects_list {
1742 $filter =~ s/\.git$//;
1744 my ($check_forks) = gitweb_check_feature('forks');
1746 if (-d $projects_list) {
1747 # search in directory
1748 my $dir = $projects_list . ($filter ? "/$filter" : '');
1749 # remove the trailing "/"
1751 my $pfxlen = length("$dir");
1752 my $pfxdepth = ($dir =~ tr!/!!);
1755 follow_fast => 1, # follow symbolic links
1756 follow_skip => 2, # ignore duplicates
1757 dangling_symlinks => 0, # ignore dangling symlinks, silently
1759 # skip project-list toplevel, if we get it.
1760 return if (m!^[/.]$!);
1761 # only directories can be git repositories
1762 return unless (-d $_);
1763 # don't traverse too deep (Find is super slow on os x)
1764 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1765 $File::Find::prune = 1;
1769 my $subdir = substr($File::Find::name, $pfxlen + 1);
1770 # we check related file in $projectroot
1771 if ($check_forks and $subdir =~ m#/.#) {
1772 $File::Find::prune = 1;
1773 } elsif (check_export_ok("$projectroot/$filter/$subdir")) {
1774 push @list, { path => ($filter ? "$filter/" : '') . $subdir };
1775 $File::Find::prune = 1;
1780 } elsif (-f $projects_list) {
1781 # read from file(url-encoded):
1782 # 'git%2Fgit.git Linus+Torvalds'
1783 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1784 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1786 open my ($fd), $projects_list or return;
1788 while (my $line = <$fd>) {
1790 my ($path, $owner) = split ' ', $line;
1791 $path = unescape($path);
1792 $owner = unescape($owner);
1793 if (!defined $path) {
1796 if ($filter ne '') {
1797 # looking for forks;
1798 my $pfx = substr($path, 0, length($filter));
1799 if ($pfx ne $filter) {
1802 my $sfx = substr($path, length($filter));
1803 if ($sfx !~ /^\/.*\.git$/) {
1806 } elsif ($check_forks) {
1808 foreach my $filter (keys %paths) {
1809 # looking for forks;
1810 my $pfx = substr($path, 0, length($filter));
1811 if ($pfx ne $filter) {
1814 my $sfx = substr($path, length($filter));
1815 if ($sfx !~ /^\/.*\.git$/) {
1818 # is a fork, don't include it in
1823 if (check_export_ok("$projectroot/$path")) {
1826 owner => to_utf8($owner),
1829 (my $forks_path = $path) =~ s/\.git$//;
1830 $paths{$forks_path}++;
1838 our $gitweb_project_owner = undef;
1839 sub git_get_project_list_from_file {
1841 return if (defined $gitweb_project_owner);
1843 $gitweb_project_owner = {};
1844 # read from file (url-encoded):
1845 # 'git%2Fgit.git Linus+Torvalds'
1846 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1847 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1848 if (-f $projects_list) {
1849 open (my $fd , $projects_list);
1850 while (my $line = <$fd>) {
1852 my ($pr, $ow) = split ' ', $line;
1853 $pr = unescape($pr);
1854 $ow = unescape($ow);
1855 $gitweb_project_owner->{$pr} = to_utf8($ow);
1861 sub git_get_project_owner {
1862 my $project = shift;
1865 return undef unless $project;
1866 $git_dir = "$projectroot/$project";
1868 if (!defined $gitweb_project_owner) {
1869 git_get_project_list_from_file();
1872 if (exists $gitweb_project_owner->{$project}) {
1873 $owner = $gitweb_project_owner->{$project};
1875 if (!defined $owner){
1876 $owner = git_get_project_config('owner');
1878 if (!defined $owner) {
1879 $owner = get_file_owner("$git_dir");
1885 sub git_get_last_activity {
1889 $git_dir = "$projectroot/$path";
1890 open($fd, "-|", git_cmd(), 'for-each-ref',
1891 '--format=%(committer)',
1892 '--sort=-committerdate',
1894 'refs/heads') or return;
1895 my $most_recent = <$fd>;
1896 close $fd or return;
1897 if (defined $most_recent &&
1898 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1900 my $age = time - $timestamp;
1901 return ($age, age_string($age));
1903 return (undef, undef);
1906 sub git_get_references {
1907 my $type = shift || "";
1909 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1910 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1911 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
1912 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1915 while (my $line = <$fd>) {
1917 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1918 if (defined $refs{$1}) {
1919 push @{$refs{$1}}, $2;
1925 close $fd or return;
1929 sub git_get_rev_name_tags {
1930 my $hash = shift || return undef;
1932 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
1934 my $name_rev = <$fd>;
1937 if ($name_rev =~ m|^$hash tags/(.*)$|) {
1940 # catches also '$hash undefined' output
1945 ## ----------------------------------------------------------------------
1946 ## parse to hash functions
1950 my $tz = shift || "-0000";
1953 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1954 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1955 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1956 $date{'hour'} = $hour;
1957 $date{'minute'} = $min;
1958 $date{'mday'} = $mday;
1959 $date{'day'} = $days[$wday];
1960 $date{'month'} = $months[$mon];
1961 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1962 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1963 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1964 $mday, $months[$mon], $hour ,$min;
1965 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1966 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1968 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1969 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1970 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1971 $date{'hour_local'} = $hour;
1972 $date{'minute_local'} = $min;
1973 $date{'tz_local'} = $tz;
1974 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1975 1900+$year, $mon+1, $mday,
1976 $hour, $min, $sec, $tz);
1985 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
1986 $tag{'id'} = $tag_id;
1987 while (my $line = <$fd>) {
1989 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1990 $tag{'object'} = $1;
1991 } elsif ($line =~ m/^type (.+)$/) {
1993 } elsif ($line =~ m/^tag (.+)$/) {
1995 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1996 $tag{'author'} = $1;
1999 } elsif ($line =~ m/--BEGIN/) {
2000 push @comment, $line;
2002 } elsif ($line eq "") {
2006 push @comment, <$fd>;
2007 $tag{'comment'} = \@comment;
2008 close $fd or return;
2009 if (!defined $tag{'name'}) {
2015 sub parse_commit_text {
2016 my ($commit_text, $withparents) = @_;
2017 my @commit_lines = split '\n', $commit_text;
2020 pop @commit_lines; # Remove '\0'
2022 if (! @commit_lines) {
2026 my $header = shift @commit_lines;
2027 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2030 ($co{'id'}, my @parents) = split ' ', $header;
2031 while (my $line = shift @commit_lines) {
2032 last if $line eq "\n";
2033 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2035 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2037 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2039 $co{'author_epoch'} = $2;
2040 $co{'author_tz'} = $3;
2041 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2042 $co{'author_name'} = $1;
2043 $co{'author_email'} = $2;
2045 $co{'author_name'} = $co{'author'};
2047 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2048 $co{'committer'} = $1;
2049 $co{'committer_epoch'} = $2;
2050 $co{'committer_tz'} = $3;
2051 $co{'committer_name'} = $co{'committer'};
2052 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2053 $co{'committer_name'} = $1;
2054 $co{'committer_email'} = $2;
2056 $co{'committer_name'} = $co{'committer'};
2060 if (!defined $co{'tree'}) {
2063 $co{'parents'} = \@parents;
2064 $co{'parent'} = $parents[0];
2066 foreach my $title (@commit_lines) {
2069 $co{'title'} = chop_str($title, 80, 5);
2070 # remove leading stuff of merges to make the interesting part visible
2071 if (length($title) > 50) {
2072 $title =~ s/^Automatic //;
2073 $title =~ s/^merge (of|with) /Merge ... /i;
2074 if (length($title) > 50) {
2075 $title =~ s/(http|rsync):\/\///;
2077 if (length($title) > 50) {
2078 $title =~ s/(master|www|rsync)\.//;
2080 if (length($title) > 50) {
2081 $title =~ s/kernel.org:?//;
2083 if (length($title) > 50) {
2084 $title =~ s/\/pub\/scm//;
2087 $co{'title_short'} = chop_str($title, 50, 5);
2091 if ($co{'title'} eq "") {
2092 $co{'title'} = $co{'title_short'} = '(no commit message)';
2094 # remove added spaces
2095 foreach my $line (@commit_lines) {
2098 $co{'comment'} = \@commit_lines;
2100 my $age = time - $co{'committer_epoch'};
2102 $co{'age_string'} = age_string($age);
2103 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2104 if ($age > 60*60*24*7*2) {
2105 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2106 $co{'age_string_age'} = $co{'age_string'};
2108 $co{'age_string_date'} = $co{'age_string'};
2109 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2115 my ($commit_id) = @_;
2120 open my $fd, "-|", git_cmd(), "rev-list",
2126 or die_error(undef, "Open git-rev-list failed");
2127 %co = parse_commit_text(<$fd>, 1);
2134 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2142 open my $fd, "-|", git_cmd(), "rev-list",
2145 ("--max-count=" . $maxcount),
2146 ("--skip=" . $skip),
2150 ($filename ? ($filename) : ())
2151 or die_error(undef, "Open git-rev-list failed");
2152 while (my $line = <$fd>) {
2153 my %co = parse_commit_text($line);
2158 return wantarray ? @cos : \@cos;
2161 # parse ref from ref_file, given by ref_id, with given type
2163 my $ref_file = shift;
2165 my $type = shift || git_get_type($ref_id);
2168 $ref_item{'type'} = $type;
2169 $ref_item{'id'} = $ref_id;
2170 $ref_item{'epoch'} = 0;
2171 $ref_item{'age'} = "unknown";
2172 if ($type eq "tag") {
2173 my %tag = parse_tag($ref_id);
2174 $ref_item{'comment'} = $tag{'comment'};
2175 if ($tag{'type'} eq "commit") {
2176 my %co = parse_commit($tag{'object'});
2177 $ref_item{'epoch'} = $co{'committer_epoch'};
2178 $ref_item{'age'} = $co{'age_string'};
2179 } elsif (defined($tag{'epoch'})) {
2180 my $age = time - $tag{'epoch'};
2181 $ref_item{'epoch'} = $tag{'epoch'};
2182 $ref_item{'age'} = age_string($age);
2184 $ref_item{'reftype'} = $tag{'type'};
2185 $ref_item{'name'} = $tag{'name'};
2186 $ref_item{'refid'} = $tag{'object'};
2187 } elsif ($type eq "commit"){
2188 my %co = parse_commit($ref_id);
2189 $ref_item{'reftype'} = "commit";
2190 $ref_item{'name'} = $ref_file;
2191 $ref_item{'title'} = $co{'title'};
2192 $ref_item{'refid'} = $ref_id;
2193 $ref_item{'epoch'} = $co{'committer_epoch'};
2194 $ref_item{'age'} = $co{'age_string'};
2196 $ref_item{'reftype'} = $type;
2197 $ref_item{'name'} = $ref_file;
2198 $ref_item{'refid'} = $ref_id;
2204 # parse line of git-diff-tree "raw" output
2205 sub parse_difftree_raw_line {
2209 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2210 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2211 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2212 $res{'from_mode'} = $1;
2213 $res{'to_mode'} = $2;
2214 $res{'from_id'} = $3;
2216 $res{'status'} = $5;
2217 $res{'similarity'} = $6;
2218 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2219 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2221 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2224 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2225 # combined diff (for merge commit)
2226 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2227 $res{'nparents'} = length($1);
2228 $res{'from_mode'} = [ split(' ', $2) ];
2229 $res{'to_mode'} = pop @{$res{'from_mode'}};
2230 $res{'from_id'} = [ split(' ', $3) ];
2231 $res{'to_id'} = pop @{$res{'from_id'}};
2232 $res{'status'} = [ split('', $4) ];
2233 $res{'to_file'} = unquote($5);
2235 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2236 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2237 $res{'commit'} = $1;
2240 return wantarray ? %res : \%res;
2243 # wrapper: return parsed line of git-diff-tree "raw" output
2244 # (the argument might be raw line, or parsed info)
2245 sub parsed_difftree_line {
2246 my $line_or_ref = shift;
2248 if (ref($line_or_ref) eq "HASH") {
2249 # pre-parsed (or generated by hand)
2250 return $line_or_ref;
2252 return parse_difftree_raw_line($line_or_ref);
2256 # parse line of git-ls-tree output
2257 sub parse_ls_tree_line ($;%) {
2262 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2263 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2271 $res{'name'} = unquote($4);
2274 return wantarray ? %res : \%res;
2277 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2278 sub parse_from_to_diffinfo {
2279 my ($diffinfo, $from, $to, @parents) = @_;
2281 if ($diffinfo->{'nparents'}) {
2283 $from->{'file'} = [];
2284 $from->{'href'} = [];
2285 fill_from_file_info($diffinfo, @parents)
2286 unless exists $diffinfo->{'from_file'};
2287 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2288 $from->{'file'}[$i] =
2289 defined $diffinfo->{'from_file'}[$i] ?
2290 $diffinfo->{'from_file'}[$i] :
2291 $diffinfo->{'to_file'};
2292 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2293 $from->{'href'}[$i] = href(action=>"blob",
2294 hash_base=>$parents[$i],
2295 hash=>$diffinfo->{'from_id'}[$i],
2296 file_name=>$from->{'file'}[$i]);
2298 $from->{'href'}[$i] = undef;
2302 # ordinary (not combined) diff
2303 $from->{'file'} = $diffinfo->{'from_file'};
2304 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2305 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2306 hash=>$diffinfo->{'from_id'},
2307 file_name=>$from->{'file'});
2309 delete $from->{'href'};
2313 $to->{'file'} = $diffinfo->{'to_file'};
2314 if (!is_deleted($diffinfo)) { # file exists in result
2315 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2316 hash=>$diffinfo->{'to_id'},
2317 file_name=>$to->{'file'});
2319 delete $to->{'href'};
2323 ## ......................................................................
2324 ## parse to array of hashes functions
2326 sub git_get_heads_list {
2330 open my $fd, '-|', git_cmd(), 'for-each-ref',
2331 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2332 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2335 while (my $line = <$fd>) {
2339 my ($refinfo, $committerinfo) = split(/\0/, $line);
2340 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2341 my ($committer, $epoch, $tz) =
2342 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2343 $ref_item{'fullname'} = $name;
2344 $name =~ s!^refs/heads/!!;
2346 $ref_item{'name'} = $name;
2347 $ref_item{'id'} = $hash;
2348 $ref_item{'title'} = $title || '(no commit message)';
2349 $ref_item{'epoch'} = $epoch;
2351 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2353 $ref_item{'age'} = "unknown";
2356 push @headslist, \%ref_item;
2360 return wantarray ? @headslist : \@headslist;
2363 sub git_get_tags_list {
2367 open my $fd, '-|', git_cmd(), 'for-each-ref',
2368 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2369 '--format=%(objectname) %(objecttype) %(refname) '.
2370 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2373 while (my $line = <$fd>) {
2377 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2378 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2379 my ($creator, $epoch, $tz) =
2380 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2381 $ref_item{'fullname'} = $name;
2382 $name =~ s!^refs/tags/!!;
2384 $ref_item{'type'} = $type;
2385 $ref_item{'id'} = $id;
2386 $ref_item{'name'} = $name;
2387 if ($type eq "tag") {
2388 $ref_item{'subject'} = $title;
2389 $ref_item{'reftype'} = $reftype;
2390 $ref_item{'refid'} = $refid;
2392 $ref_item{'reftype'} = $type;
2393 $ref_item{'refid'} = $id;
2396 if ($type eq "tag" || $type eq "commit") {
2397 $ref_item{'epoch'} = $epoch;
2399 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2401 $ref_item{'age'} = "unknown";
2405 push @tagslist, \%ref_item;
2409 return wantarray ? @tagslist : \@tagslist;
2412 ## ----------------------------------------------------------------------
2413 ## filesystem-related functions
2415 sub get_file_owner {
2418 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2419 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2420 if (!defined $gcos) {
2424 $owner =~ s/[,;].*$//;
2425 return to_utf8($owner);
2428 ## ......................................................................
2429 ## mimetype related functions
2431 sub mimetype_guess_file {
2432 my $filename = shift;
2433 my $mimemap = shift;
2434 -r $mimemap or return undef;
2437 open(MIME, $mimemap) or return undef;
2439 next if m/^#/; # skip comments
2440 my ($mime, $exts) = split(/\t+/);
2441 if (defined $exts) {
2442 my @exts = split(/\s+/, $exts);
2443 foreach my $ext (@exts) {
2444 $mimemap{$ext} = $mime;
2450 $filename =~ /\.([^.]*)$/;
2451 return $mimemap{$1};
2454 sub mimetype_guess {
2455 my $filename = shift;
2457 $filename =~ /\./ or return undef;
2459 if ($mimetypes_file) {
2460 my $file = $mimetypes_file;
2461 if ($file !~ m!^/!) { # if it is relative path
2462 # it is relative to project
2463 $file = "$projectroot/$project/$file";
2465 $mime = mimetype_guess_file($filename, $file);
2467 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2473 my $filename = shift;
2476 my $mime = mimetype_guess($filename);
2477 $mime and return $mime;
2481 return $default_blob_plain_mimetype unless $fd;
2484 return 'text/plain' .
2485 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2486 } elsif (! $filename) {
2487 return 'application/octet-stream';
2488 } elsif ($filename =~ m/\.png$/i) {
2490 } elsif ($filename =~ m/\.gif$/i) {
2492 } elsif ($filename =~ m/\.jpe?g$/i) {
2493 return 'image/jpeg';
2495 return 'application/octet-stream';
2499 ## ======================================================================
2500 ## functions printing HTML: header, footer, error page
2502 sub git_header_html {
2503 my $status = shift || "200 OK";
2504 my $expires = shift;
2506 my $title = "$site_name";
2507 if (defined $project) {
2508 $title .= " - " . to_utf8($project);
2509 if (defined $action) {
2510 $title .= "/$action";
2511 if (defined $file_name) {
2512 $title .= " - " . esc_path($file_name);
2513 if ($action eq "tree" && $file_name !~ m|/$|) {
2520 # require explicit support from the UA if we are to send the page as
2521 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2522 # we have to do this because MSIE sometimes globs '*/*', pretending to
2523 # support xhtml+xml but choking when it gets what it asked for.
2524 if (defined $cgi->http('HTTP_ACCEPT') &&
2525 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
2526 $cgi->Accept('application/xhtml+xml') != 0) {
2527 $content_type = 'application/xhtml+xml';
2529 $content_type = 'text/html';
2531 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
2532 -status=> $status, -expires => $expires);
2533 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2535 <?xml version="1.0" encoding="utf-8"?>
2536 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2537 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2538 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2539 <!-- git core binaries version $git_version -->
2541 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2542 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2543 <meta name="robots" content="index, nofollow"/>
2544 <title>$title</title>
2546 # print out each stylesheet that exist
2547 if (defined $stylesheet) {
2548 #provides backwards capability for those people who define style sheet in a config file
2549 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2551 foreach my $stylesheet (@stylesheets) {
2552 next unless $stylesheet;
2553 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2556 if (defined $project) {
2557 my %href_params = get_feed_info();
2558 if (!exists $href_params{'-title'}) {
2559 $href_params{'-title'} = 'log';
2562 foreach my $format qw(RSS Atom) {
2563 my $type = lc($format);
2565 '-rel' => 'alternate',
2566 '-title' => "$project - $href_params{'-title'} - $format feed",
2567 '-type' => "application/$type+xml"
2570 $href_params{'action'} = $type;
2571 $link_attr{'-href'} = href(%href_params);
2573 "rel=\"$link_attr{'-rel'}\" ".
2574 "title=\"$link_attr{'-title'}\" ".
2575 "href=\"$link_attr{'-href'}\" ".
2576 "type=\"$link_attr{'-type'}\" ".
2579 $href_params{'extra_options'} = '--no-merges';
2580 $link_attr{'-href'} = href(%href_params);
2581 $link_attr{'-title'} .= ' (no merges)';
2583 "rel=\"$link_attr{'-rel'}\" ".
2584 "title=\"$link_attr{'-title'}\" ".
2585 "href=\"$link_attr{'-href'}\" ".
2586 "type=\"$link_attr{'-type'}\" ".
2591 printf('<link rel="alternate" title="%s projects list" '.
2592 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2593 $site_name, href(project=>undef, action=>"project_index"));
2594 printf('<link rel="alternate" title="%s projects feeds" '.
2595 'href="%s" type="text/x-opml" />'."\n",
2596 $site_name, href(project=>undef, action=>"opml"));
2598 if (defined $favicon) {
2599 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2605 if (-f $site_header) {
2606 open (my $fd, $site_header);
2611 print "<div class=\"page_header\">\n" .
2612 $cgi->a({-href => esc_url($logo_url),
2613 -title => $logo_label},
2614 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2615 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
2616 if (defined $project) {
2617 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
2618 if (defined $action) {
2625 my ($have_search) = gitweb_check_feature('search');
2626 if ((defined $project) && ($have_search)) {
2627 if (!defined $searchtext) {
2631 if (defined $hash_base) {
2632 $search_hash = $hash_base;
2633 } elsif (defined $hash) {
2634 $search_hash = $hash;
2636 $search_hash = "HEAD";
2638 my $action = $my_uri;
2639 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
2640 if ($use_pathinfo) {
2641 $action .= "/".esc_url($project);
2643 $cgi->param("p", $project);
2645 $cgi->param("a", "search");
2646 $cgi->param("h", $search_hash);
2647 print $cgi->startform(-method => "get", -action => $action) .
2648 "<div class=\"search\">\n" .
2649 (!$use_pathinfo && $cgi->hidden(-name => "p") . "\n") .
2650 $cgi->hidden(-name => "a") . "\n" .
2651 $cgi->hidden(-name => "h") . "\n" .
2652 $cgi->popup_menu(-name => 'st', -default => 'commit',
2653 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2654 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
2656 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
2657 "<span title=\"Extended regular expression\">" .
2658 $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
2659 -checked => $search_use_regexp) .
2662 $cgi->end_form() . "\n";
2666 sub git_footer_html {
2667 my $feed_class = 'rss_logo';
2669 print "<div class=\"page_footer\">\n";
2670 if (defined $project) {
2671 my $descr = git_get_project_description($project);
2672 if (defined $descr) {
2673 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
2676 my %href_params = get_feed_info();
2677 if (!%href_params) {
2678 $feed_class .= ' generic';
2680 $href_params{'-title'} ||= 'log';
2682 foreach my $format qw(RSS Atom) {
2683 $href_params{'action'} = lc($format);
2684 print $cgi->a({-href => href(%href_params),
2685 -title => "$href_params{'-title'} $format feed",
2686 -class => $feed_class}, $format)."\n";
2690 print $cgi->a({-href => href(project=>undef, action=>"opml"),
2691 -class => $feed_class}, "OPML") . " ";
2692 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
2693 -class => $feed_class}, "TXT") . "\n";
2695 print "</div>\n"; # class="page_footer"
2697 if (-f $site_footer) {
2698 open (my $fd, $site_footer);
2708 my $status = shift || "403 Forbidden";
2709 my $error = shift || "Malformed query, file missing or permission denied";
2711 git_header_html($status);
2713 <div class="page_body">
2723 ## ----------------------------------------------------------------------
2724 ## functions printing or outputting HTML: navigation
2726 sub git_print_page_nav {
2727 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2728 $extra = '' if !defined $extra; # pager or formats
2730 my @navs = qw(summary shortlog log commit commitdiff tree);
2732 @navs = grep { $_ ne $suppress } @navs;
2735 my %arg = map { $_ => {action=>$_} } @navs;
2736 if (defined $head) {
2737 for (qw(commit commitdiff)) {
2738 $arg{$_}{'hash'} = $head;
2740 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2741 for (qw(shortlog log)) {
2742 $arg{$_}{'hash'} = $head;
2746 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2747 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2749 print "<div class=\"page_nav\">\n" .
2751 map { $_ eq $current ?
2752 $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
2754 print "<br/>\n$extra<br/>\n" .
2758 sub format_paging_nav {
2759 my ($action, $hash, $head, $page, $nrevs) = @_;
2763 if ($hash ne $head || $page) {
2764 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
2766 $paging_nav .= "HEAD";
2770 $paging_nav .= " ⋅ " .
2771 $cgi->a({-href => href(-replay=>1, page=>$page-1),
2772 -accesskey => "p", -title => "Alt-p"}, "prev");
2774 $paging_nav .= " ⋅ prev";
2777 if ($nrevs >= (100 * ($page+1)-1)) {
2778 $paging_nav .= " ⋅ " .
2779 $cgi->a({-href => href(-replay=>1, page=>$page+1),
2780 -accesskey => "n", -title => "Alt-n"}, "next");
2782 $paging_nav .= " ⋅ next";
2788 ## ......................................................................
2789 ## functions printing or outputting HTML: div
2791 sub git_print_header_div {
2792 my ($action, $title, $hash, $hash_base) = @_;
2795 $args{'action'} = $action;
2796 $args{'hash'} = $hash if $hash;
2797 $args{'hash_base'} = $hash_base if $hash_base;
2799 print "<div class=\"header\">\n" .
2800 $cgi->a({-href => href(%args), -class => "title"},
2801 $title ? $title : $action) .
2805 #sub git_print_authorship (\%) {
2806 sub git_print_authorship {
2809 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
2810 print "<div class=\"author_date\">" .
2811 esc_html($co->{'author_name'}) .
2813 if ($ad{'hour_local'} < 6) {
2814 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2815 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2817 printf(" (%02d:%02d %s)",
2818 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2823 sub git_print_page_path {
2829 print "<div class=\"page_path\">";
2830 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
2831 -title => 'tree root'}, to_utf8("[$project]"));
2833 if (defined $name) {
2834 my @dirname = split '/', $name;
2835 my $basename = pop @dirname;
2838 foreach my $dir (@dirname) {
2839 $fullname .= ($fullname ? '/' : '') . $dir;
2840 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
2842 -title => $fullname}, esc_path($dir));
2845 if (defined $type && $type eq 'blob') {
2846 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
2848 -title => $name}, esc_path($basename));
2849 } elsif (defined $type && $type eq 'tree') {
2850 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
2852 -title => $name}, esc_path($basename));
2855 print esc_path($basename);
2858 print "<br/></div>\n";
2861 # sub git_print_log (\@;%) {
2862 sub git_print_log ($;%) {
2866 if ($opts{'-remove_title'}) {
2867 # remove title, i.e. first line of log
2870 # remove leading empty lines
2871 while (defined $log->[0] && $log->[0] eq "") {
2878 foreach my $line (@$log) {
2879 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2882 if (! $opts{'-remove_signoff'}) {
2883 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
2886 # remove signoff lines
2893 # print only one empty line
2894 # do not print empty line after signoff
2896 next if ($empty || $signoff);
2902 print format_log_line_html($line) . "<br/>\n";
2905 if ($opts{'-final_empty_line'}) {
2906 # end with single empty line
2907 print "<br/>\n" unless $empty;
2911 # return link target (what link points to)
2912 sub git_get_link_target {
2917 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
2921 $link_target = <$fd>;
2926 return $link_target;
2929 # given link target, and the directory (basedir) the link is in,
2930 # return target of link relative to top directory (top tree);
2931 # return undef if it is not possible (including absolute links).
2932 sub normalize_link_target {
2933 my ($link_target, $basedir, $hash_base) = @_;
2935 # we can normalize symlink target only if $hash_base is provided
2936 return unless $hash_base;
2938 # absolute symlinks (beginning with '/') cannot be normalized
2939 return if (substr($link_target, 0, 1) eq '/');
2941 # normalize link target to path from top (root) tree (dir)
2944 $path = $basedir . '/' . $link_target;
2946 # we are in top (root) tree (dir)
2947 $path = $link_target;
2950 # remove //, /./, and /../
2952 foreach my $part (split('/', $path)) {
2953 # discard '.' and ''
2954 next if (!$part || $part eq '.');
2956 if ($part eq '..') {
2960 # link leads outside repository (outside top dir)
2964 push @path_parts, $part;
2967 $path = join('/', @path_parts);
2972 # print tree entry (row of git_tree), but without encompassing <tr> element
2973 sub git_print_tree_entry {
2974 my ($t, $basedir, $hash_base, $have_blame) = @_;
2977 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2979 # The format of a table row is: mode list link. Where mode is
2980 # the mode of the entry, list is the name of the entry, an href,
2981 # and link is the action links of the entry.
2983 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
2984 if ($t->{'type'} eq "blob") {
2985 print "<td class=\"list\">" .
2986 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2987 file_name=>"$basedir$t->{'name'}", %base_key),
2988 -class => "list"}, esc_path($t->{'name'}));
2989 if (S_ISLNK(oct $t->{'mode'})) {
2990 my $link_target = git_get_link_target($t->{'hash'});
2992 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
2993 if (defined $norm_target) {
2995 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
2996 file_name=>$norm_target),
2997 -title => $norm_target}, esc_path($link_target));
2999 print " -> " . esc_path($link_target);
3004 print "<td class=\"link\">";
3005 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3006 file_name=>"$basedir$t->{'name'}", %base_key)},
3010 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
3011 file_name=>"$basedir$t->{'name'}", %base_key)},
3014 if (defined $hash_base) {
3016 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3017 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
3021 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
3022 file_name=>"$basedir$t->{'name'}")},
3026 } elsif ($t->{'type'} eq "tree") {
3027 print "<td class=\"list\">";
3028 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3029 file_name=>"$basedir$t->{'name'}", %base_key)},
3030 esc_path($t->{'name'}));
3032 print "<td class=\"link\">";
3033 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3034 file_name=>"$basedir$t->{'name'}", %base_key)},
3036 if (defined $hash_base) {
3038 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3039 file_name=>"$basedir$t->{'name'}")},
3044 # unknown object: we can only present history for it
3045 # (this includes 'commit' object, i.e. submodule support)
3046 print "<td class=\"list\">" .
3047 esc_path($t->{'name'}) .
3049 print "<td class=\"link\">";
3050 if (defined $hash_base) {
3051 print $cgi->a({-href => href(action=>"history",
3052 hash_base=>$hash_base,
3053 file_name=>"$basedir$t->{'name'}")},
3060 ## ......................................................................
3061 ## functions printing large fragments of HTML
3063 # get pre-image filenames for merge (combined) diff
3064 sub fill_from_file_info {
3065 my ($diff, @parents) = @_;
3067 $diff->{'from_file'} = [ ];
3068 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3069 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3070 if ($diff->{'status'}[$i] eq 'R' ||
3071 $diff->{'status'}[$i] eq 'C') {
3072 $diff->{'from_file'}[$i] =
3073 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
3080 # is current raw difftree line of file deletion
3082 my $diffinfo = shift;
3084 return $diffinfo->{'to_id'} eq ('0' x 40);
3087 # does patch correspond to [previous] difftree raw line
3088 # $diffinfo - hashref of parsed raw diff format
3089 # $patchinfo - hashref of parsed patch diff format
3090 # (the same keys as in $diffinfo)
3091 sub is_patch_split {
3092 my ($diffinfo, $patchinfo) = @_;
3094 return defined $diffinfo && defined $patchinfo
3095 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3099 sub git_difftree_body {
3100 my ($difftree, $hash, @parents) = @_;
3101 my ($parent) = $parents[0];
3102 my ($have_blame) = gitweb_check_feature('blame');
3103 print "<div class=\"list_head\">\n";
3104 if ($#{$difftree} > 10) {
3105 print(($#{$difftree} + 1) . " files changed:\n");
3109 print "<table class=\"" .
3110 (@parents > 1 ? "combined " : "") .
3113 # header only for combined diff in 'commitdiff' view
3114 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3117 print "<thead><tr>\n" .
3118 "<th></th><th></th>\n"; # filename, patchN link
3119 for (my $i = 0; $i < @parents; $i++) {
3120 my $par = $parents[$i];
3122 $cgi->a({-href => href(action=>"commitdiff",
3123 hash=>$hash, hash_parent=>$par),
3124 -title => 'commitdiff to parent number ' .
3125 ($i+1) . ': ' . substr($par,0,7)},
3129 print "</tr></thead>\n<tbody>\n";
3134 foreach my $line (@{$difftree}) {
3135 my $diff = parsed_difftree_line($line);
3138 print "<tr class=\"dark\">\n";
3140 print "<tr class=\"light\">\n";
3144 if (exists $diff->{'nparents'}) { # combined diff
3146 fill_from_file_info($diff, @parents)
3147 unless exists $diff->{'from_file'};
3149 if (!is_deleted($diff)) {
3150 # file exists in the result (child) commit
3152 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3153 file_name=>$diff->{'to_file'},
3155 -class => "list"}, esc_path($diff->{'to_file'})) .
3159 esc_path($diff->{'to_file'}) .
3163 if ($action eq 'commitdiff') {
3166 print "<td class=\"link\">" .
3167 $cgi->a({-href => "#patch$patchno"}, "patch") .
3172 my $has_history = 0;
3173 my $not_deleted = 0;
3174 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3175 my $hash_parent = $parents[$i];
3176 my $from_hash = $diff->{'from_id'}[$i];
3177 my $from_path = $diff->{'from_file'}[$i];
3178 my $status = $diff->{'status'}[$i];
3180 $has_history ||= ($status ne 'A');
3181 $not_deleted ||= ($status ne 'D');
3183 if ($status eq 'A') {
3184 print "<td class=\"link\" align=\"right\"> | </td>\n";
3185 } elsif ($status eq 'D') {
3186 print "<td class=\"link\">" .
3187 $cgi->a({-href => href(action=>"blob",
3190 file_name=>$from_path)},
3194 if ($diff->{'to_id'} eq $from_hash) {
3195 print "<td class=\"link nochange\">";
3197 print "<td class=\"link\">";
3199 print $cgi->a({-href => href(action=>"blobdiff",
3200 hash=>$diff->{'to_id'},
3201 hash_parent=>$from_hash,
3203 hash_parent_base=>$hash_parent,
3204 file_name=>$diff->{'to_file'},
3205 file_parent=>$from_path)},
3211 print "<td class=\"link\">";
3213 print $cgi->a({-href => href(action=>"blob",
3214 hash=>$diff->{'to_id'},
3215 file_name=>$diff->{'to_file'},
3218 print " | " if ($has_history);
3221 print $cgi->a({-href => href(action=>"history",
3222 file_name=>$diff->{'to_file'},
3229 next; # instead of 'else' clause, to avoid extra indent
3231 # else ordinary diff
3233 my ($to_mode_oct, $to_mode_str, $to_file_type);
3234 my ($from_mode_oct, $from_mode_str, $from_file_type);
3235 if ($diff->{'to_mode'} ne ('0' x 6)) {
3236 $to_mode_oct = oct $diff->{'to_mode'};
3237 if (S_ISREG($to_mode_oct)) { # only for regular file
3238 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3240 $to_file_type = file_type($diff->{'to_mode'});
3242 if ($diff->{'from_mode'} ne ('0' x 6)) {
3243 $from_mode_oct = oct $diff->{'from_mode'};
3244 if (S_ISREG($to_mode_oct)) { # only for regular file
3245 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3247 $from_file_type = file_type($diff->{'from_mode'});
3250 if ($diff->{'status'} eq "A") { # created
3251 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3252 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3253 $mode_chng .= "]</span>";
3255 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3256 hash_base=>$hash, file_name=>$diff->{'file'}),
3257 -class => "list"}, esc_path($diff->{'file'}));
3259 print "<td>$mode_chng</td>\n";
3260 print "<td class=\"link\">";
3261 if ($action eq 'commitdiff') {
3264 print $cgi->a({-href => "#patch$patchno"}, "patch");
3267 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3268 hash_base=>$hash, file_name=>$diff->{'file'})},
3272 } elsif ($diff->{'status'} eq "D") { # deleted
3273 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3275 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3276 hash_base=>$parent, file_name=>$diff->{'file'}),
3277 -class => "list"}, esc_path($diff->{'file'}));
3279 print "<td>$mode_chng</td>\n";
3280 print "<td class=\"link\">";
3281 if ($action eq 'commitdiff') {
3284 print $cgi->a({-href => "#patch$patchno"}, "patch");
3287 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3288 hash_base=>$parent, file_name=>$diff->{'file'})},
3291 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3292 file_name=>$diff->{'file'})},
3295 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3296 file_name=>$diff->{'file'})},
3300 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3301 my $mode_chnge = "";
3302 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3303 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3304 if ($from_file_type ne $to_file_type) {
3305 $mode_chnge .= " from $from_file_type to $to_file_type";
3307 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3308 if ($from_mode_str && $to_mode_str) {
3309 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3310 } elsif ($to_mode_str) {
3311 $mode_chnge .= " mode: $to_mode_str";
3314 $mode_chnge .= "]</span>\n";
3317 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3318 hash_base=>$hash, file_name=>$diff->{'file'}),
3319 -class => "list"}, esc_path($diff->{'file'}));
3321 print "<td>$mode_chnge</td>\n";
3322 print "<td class=\"link\">";
3323 if ($action eq 'commitdiff') {
3326 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3328 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3329 # "commit" view and modified file (not onlu mode changed)
3330 print $cgi->a({-href => href(action=>"blobdiff",
3331 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3332 hash_base=>$hash, hash_parent_base=>$parent,
3333 file_name=>$diff->{'file'})},
3337 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3338 hash_base=>$hash, file_name=>$diff->{'file'})},
3341 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3342 file_name=>$diff->{'file'})},
3345 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3346 file_name=>$diff->{'file'})},
3350 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3351 my %status_name = ('R' => 'moved', 'C' => 'copied');
3352 my $nstatus = $status_name{$diff->{'status'}};
3354 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3355 # mode also for directories, so we cannot use $to_mode_str
3356 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3359 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3360 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3361 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3362 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3363 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3364 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3365 -class => "list"}, esc_path($diff->{'from_file'})) .
3366 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3367 "<td class=\"link\">";
3368 if ($action eq 'commitdiff') {
3371 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3373 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3374 # "commit" view and modified file (not only pure rename or copy)
3375 print $cgi->a({-href => href(action=>"blobdiff",
3376 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3377 hash_base=>$hash, hash_parent_base=>$parent,
3378 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3382 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3383 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3386 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3387 file_name=>$diff->{'to_file'})},
3390 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3391 file_name=>$diff->{'to_file'})},
3395 } # we should not encounter Unmerged (U) or Unknown (X) status
3398 print "</tbody>" if $has_header;
3402 sub git_patchset_body {
3403 my ($fd, $difftree, $hash, @hash_parents) = @_;
3404 my ($hash_parent) = $hash_parents[0];
3406 my $is_combined = (@hash_parents > 1);
3408 my $patch_number = 0;
3414 print "<div class=\"patchset\">\n";
3416 # skip to first patch
3417 while ($patch_line = <$fd>) {
3420 last if ($patch_line =~ m/^diff /);
3424 while ($patch_line) {
3426 # parse "git diff" header line
3427 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3428 # $1 is from_name, which we do not use
3429 $to_name = unquote($2);
3430 $to_name =~ s!^b/!!;
3431 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3432 # $1 is 'cc' or 'combined', which we do not use
3433 $to_name = unquote($2);
3438 # check if current patch belong to current raw line
3439 # and parse raw git-diff line if needed
3440 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
3441 # this is continuation of a split patch
3442 print "<div class=\"patch cont\">\n";
3444 # advance raw git-diff output if needed
3445 $patch_idx++ if defined $diffinfo;
3447 # read and prepare patch information
3448 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3450 # compact combined diff output can have some patches skipped
3451 # find which patch (using pathname of result) we are at now;
3453 while ($to_name ne $diffinfo->{'to_file'}) {
3454 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3455 format_diff_cc_simplified($diffinfo, @hash_parents) .
3456 "</div>\n"; # class="patch"
3461 last if $patch_idx > $#$difftree;
3462 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3466 # modifies %from, %to hashes
3467 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3469 # this is first patch for raw difftree line with $patch_idx index
3470 # we index @$difftree array from 0, but number patches from 1
3471 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3475 #assert($patch_line =~ m/^diff /) if DEBUG;
3476 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3478 # print "git diff" header
3479 print format_git_diff_header_line($patch_line, $diffinfo,
3482 # print extended diff header
3483 print "<div class=\"diff extended_header\">\n";
3485 while ($patch_line = <$fd>) {
3488 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
3490 print format_extended_diff_header_line($patch_line, $diffinfo,
3493 print "</div>\n"; # class="diff extended_header"
3495 # from-file/to-file diff header
3496 if (! $patch_line) {
3497 print "</div>\n"; # class="patch"
3500 next PATCH if ($patch_line =~ m/^diff /);
3501 #assert($patch_line =~ m/^---/) if DEBUG;
3503 my $last_patch_line = $patch_line;
3504 $patch_line = <$fd>;
3506 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3508 print format_diff_from_to_header($last_patch_line, $patch_line,
3509 $diffinfo, \%from, \%to,
3514 while ($patch_line = <$fd>) {
3517 next PATCH if ($patch_line =~ m/^diff /);
3519 print format_diff_line($patch_line, \%from, \%to);
3523 print "</div>\n"; # class="patch"
3526 # for compact combined (--cc) format, with chunk and patch simpliciaction
3527 # patchset might be empty, but there might be unprocessed raw lines
3528 for (++$patch_idx if $patch_number > 0;
3529 $patch_idx < @$difftree;
3531 # read and prepare patch information
3532 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3534 # generate anchor for "patch" links in difftree / whatchanged part
3535 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3536 format_diff_cc_simplified($diffinfo, @hash_parents) .
3537 "</div>\n"; # class="patch"
3542 if ($patch_number == 0) {
3543 if (@hash_parents > 1) {
3544 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3546 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3550 print "</div>\n"; # class="patchset"
3553 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3555 sub git_project_list_body {
3556 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3558 my ($check_forks) = gitweb_check_feature('forks');
3561 foreach my $pr (@$projlist) {
3562 my (@aa) = git_get_last_activity($pr->{'path'});
3566 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3567 if (!defined $pr->{'descr'}) {
3568 my $descr = git_get_project_description($pr->{'path'}) || "";
3569 $pr->{'descr_long'} = to_utf8($descr);
3570 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3572 if (!defined $pr->{'owner'}) {
3573 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
3576 my $pname = $pr->{'path'};
3577 if (($pname =~ s/\.git$//) &&
3578 ($pname !~ /\/$/) &&
3579 (-d "$projectroot/$pname")) {
3580 $pr->{'forks'} = "-d $projectroot/$pname";
3586 push @projects, $pr;
3589 $order ||= $default_projects_order;
3590 $from = 0 unless defined $from;
3591 $to = $#projects if (!defined $to || $#projects < $to);
3593 print "<table class=\"project_list\">\n";
3594 unless ($no_header) {
3597 print "<th></th>\n";
3599 if ($order eq "project") {
3600 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3601 print "<th>Project</th>\n";
3604 $cgi->a({-href => href(project=>undef, order=>'project'),
3605 -class => "header"}, "Project") .
3608 if ($order eq "descr") {
3609 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3610 print "<th>Description</th>\n";
3613 $cgi->a({-href => href(project=>undef, order=>'descr'),
3614 -class => "header"}, "Description") .
3617 if ($order eq "owner") {
3618 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3619 print "<th>Owner</th>\n";
3622 $cgi->a({-href => href(project=>undef, order=>'owner'),
3623 -class => "header"}, "Owner") .
3626 if ($order eq "age") {
3627 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3628 print "<th>Last Change</th>\n";
3631 $cgi->a({-href => href(project=>undef, order=>'age'),
3632 -class => "header"}, "Last Change") .
3635 print "<th></th>\n" .
3639 for (my $i = $from; $i <= $to; $i++) {
3640 my $pr = $projects[$i];
3642 print "<tr class=\"dark\">\n";
3644 print "<tr class=\"light\">\n";
3649 if ($pr->{'forks'}) {
3650 print "<!-- $pr->{'forks'} -->\n";
3651 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
3655 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
3656 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
3657 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
3658 -class => "list", -title => $pr->{'descr_long'}},
3659 esc_html($pr->{'descr'})) . "</td>\n" .
3660 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
3661 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
3662 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3663 "<td class=\"link\">" .
3664 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
3665 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
3666 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
3667 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
3668 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
3672 if (defined $extra) {
3675 print "<td></td>\n";
3677 print "<td colspan=\"5\">$extra</td>\n" .
3683 sub git_shortlog_body {
3684 # uses global variable $project
3685 my ($commitlist, $from, $to, $refs, $extra) = @_;
3687 $from = 0 unless defined $from;
3688 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3690 print "<table class=\"shortlog\">\n";
3692 for (my $i = $from; $i <= $to; $i++) {
3693 my %co = %{$commitlist->[$i]};
3694 my $commit = $co{'id'};
3695 my $ref = format_ref_marker($refs, $commit);
3697 print "<tr class=\"dark\">\n";
3699 print "<tr class=\"light\">\n";
3702 my $author = chop_and_escape_str($co{'author_name'}, 10);
3703 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3704 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3705 "<td><i>" . $author . "</i></td>\n" .
3707 print format_subject_html($co{'title'}, $co{'title_short'},
3708 href(action=>"commit", hash=>$commit), $ref);
3710 "<td class=\"link\">" .
3711 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
3712 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
3713 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
3714 my $snapshot_links = format_snapshot_links($commit);
3715 if (defined $snapshot_links) {
3716 print " | " . $snapshot_links;
3721 if (defined $extra) {
3723 "<td colspan=\"4\">$extra</td>\n" .
3729 sub git_history_body {
3730 # Warning: assumes constant type (blob or tree) during history
3731 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3733 $from = 0 unless defined $from;
3734 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3736 print "<table class=\"history\">\n";
3738 for (my $i = $from; $i <= $to; $i++) {
3739 my %co = %{$commitlist->[$i]};
3743 my $commit = $co{'id'};
3745 my $ref = format_ref_marker($refs, $commit);
3748 print "<tr class=\"dark\">\n";
3750 print "<tr class=\"light\">\n";
3753 # shortlog uses chop_str($co{'author_name'}, 10)
3754 my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
3755 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3756 "<td><i>" . $author . "</i></td>\n" .
3758 # originally git_history used chop_str($co{'title'}, 50)
3759 print format_subject_html($co{'title'}, $co{'title_short'},
3760 href(action=>"commit", hash=>$commit), $ref);
3762 "<td class=\"link\">" .
3763 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
3764 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
3766 if ($ftype eq 'blob') {
3767 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
3768 my $blob_parent = git_get_hash_by_path($commit, $file_name);
3769 if (defined $blob_current && defined $blob_parent &&
3770 $blob_current ne $blob_parent) {
3772 $cgi->a({-href => href(action=>"blobdiff",
3773 hash=>$blob_current, hash_parent=>$blob_parent,
3774 hash_base=>$hash_base, hash_parent_base=>$commit,
3775 file_name=>$file_name)},
3782 if (defined $extra) {
3784 "<td colspan=\"4\">$extra</td>\n" .
3791 # uses global variable $project
3792 my ($taglist, $from, $to, $extra) = @_;
3793 $from = 0 unless defined $from;
3794 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3796 print "<table class=\"tags\">\n";
3798 for (my $i = $from; $i <= $to; $i++) {
3799 my $entry = $taglist->[$i];
3801 my $comment = $tag{'subject'};
3803 if (defined $comment) {
3804 $comment_short = chop_str($comment, 30, 5);
3807 print "<tr class=\"dark\">\n";
3809 print "<tr class=\"light\">\n";
3812 if (defined $tag{'age'}) {
3813 print "<td><i>$tag{'age'}</i></td>\n";
3815 print "<td></td>\n";
3818 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
3819 -class => "list name"}, esc_html($tag{'name'})) .
3822 if (defined $comment) {
3823 print format_subject_html($comment, $comment_short,
3824 href(action=>"tag", hash=>$tag{'id'}));
3827 "<td class=\"selflink\">";
3828 if ($tag{'type'} eq "tag") {
3829 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
3834 "<td class=\"link\">" . " | " .
3835 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
3836 if ($tag{'reftype'} eq "commit") {
3837 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
3838 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
3839 } elsif ($tag{'reftype'} eq "blob") {
3840 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
3845 if (defined $extra) {
3847 "<td colspan=\"5\">$extra</td>\n" .
3853 sub git_heads_body {
3854 # uses global variable $project
3855 my ($headlist, $head, $from, $to, $extra) = @_;
3856 $from = 0 unless defined $from;
3857 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3859 print "<table class=\"heads\">\n";
3861 for (my $i = $from; $i <= $to; $i++) {
3862 my $entry = $headlist->[$i];
3864 my $curr = $ref{'id'} eq $head;
3866 print "<tr class=\"dark\">\n";
3868 print "<tr class=\"light\">\n";
3871 print "<td><i>$ref{'age'}</i></td>\n" .
3872 ($curr ? "<td class=\"current_head\">" : "<td>") .
3873 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),
3874 -class => "list name"},esc_html($ref{'name'})) .
3876 "<td class=\"link\">" .
3877 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
3878 $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
3879 $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
3883 if (defined $extra) {
3885 "<td colspan=\"3\">$extra</td>\n" .
3891 sub git_search_grep_body {
3892 my ($commitlist, $from, $to, $extra) = @_;
3893 $from = 0 unless defined $from;
3894 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3896 print "<table class=\"commit_search\">\n";
3898 for (my $i = $from; $i <= $to; $i++) {
3899 my %co = %{$commitlist->[$i]};
3903 my $commit = $co{'id'};
3905 print "<tr class=\"dark\">\n";
3907 print "<tr class=\"light\">\n";
3910 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
3911 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3912 "<td><i>" . $author . "</i></td>\n" .
3914 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
3915 -class => "list subject"},
3916 chop_and_escape_str($co{'title'}, 50) . "<br/>");
3917 my $comment = $co{'comment'};
3918 foreach my $line (@$comment) {
3919 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3920 my ($lead, $match, $trail) = ($1, $2, $3);
3921 $match = chop_str($match, 70, 5, 'center');
3922 my $contextlen = int((80 - length($match))/2);
3923 $contextlen = 30 if ($contextlen > 30);
3924 $lead = chop_str($lead, $contextlen, 10, 'left');
3925 $trail = chop_str($trail, $contextlen, 10, 'right');
3927 $lead = esc_html($lead);
3928 $match = esc_html($match);
3929 $trail = esc_html($trail);
3931 print "$lead<span class=\"match\">$match</span>$trail<br />";
3935 "<td class=\"link\">" .
3936 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
3938 $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") .
3940 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
3944 if (defined $extra) {
3946 "<td colspan=\"3\">$extra</td>\n" .
3952 ## ======================================================================
3953 ## ======================================================================
3956 sub git_project_list {
3957 my $order = $cgi->param('o');
3958 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3959 die_error(undef, "Unknown order parameter");
3962 my @list = git_get_projects_list();
3964 die_error(undef, "No projects found");
3968 if (-f $home_text) {
3969 print "<div class=\"index_include\">\n";
3970 open (my $fd, $home_text);
3975 git_project_list_body(\@list, $order);
3980 my $order = $cgi->param('o');
3981 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3982 die_error(undef, "Unknown order parameter");
3985 my @list = git_get_projects_list($project);
3987 die_error(undef, "No forks found");
3991 git_print_page_nav('','');
3992 git_print_header_div('summary', "$project forks");
3993 git_project_list_body(\@list, $order);
3997 sub git_project_index {
3998 my @projects = git_get_projects_list($project);
4001 -type => 'text/plain',
4002 -charset => 'utf-8',
4003 -content_disposition => 'inline; filename="index.aux"');
4005 foreach my $pr (@projects) {
4006 if (!exists $pr->{'owner'}) {
4007 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
4010 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4011 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4012 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4013 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4017 print "$path $owner\n";
4022 my $descr = git_get_project_description($project) || "none";
4023 my %co = parse_commit("HEAD");
4024 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4025 my $head = $co{'id'};
4027 my $owner = git_get_project_owner($project);
4029 my $refs = git_get_references();
4030 # These get_*_list functions return one more to allow us to see if
4031 # there are more ...
4032 my @taglist = git_get_tags_list(16);
4033 my @headlist = git_get_heads_list(16);
4035 my ($check_forks) = gitweb_check_feature('forks');
4038 @forklist = git_get_projects_list($project);
4042 git_print_page_nav('summary','', $head);
4044 print "<div class=\"title\"> </div>\n";
4045 print "<table class=\"projects_list\">\n" .
4046 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
4047 "<tr><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
4048 if (defined $cd{'rfc2822'}) {
4049 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4052 # use per project git URL list in $projectroot/$project/cloneurl
4053 # or make project git URL from git base URL and project name
4054 my $url_tag = "URL";
4055 my @url_list = git_get_project_url_list($project);
4056 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4057 foreach my $git_url (@url_list) {
4058 next unless $git_url;
4059 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4064 if (-s "$projectroot/$project/README.html") {
4065 if (open my $fd, "$projectroot/$project/README.html") {
4066 print "<div class=\"title\">readme</div>\n" .
4067 "<div class=\"readme\">\n";
4068 print $_ while (<$fd>);
4069 print "\n</div>\n"; # class="readme"
4074 # we need to request one more than 16 (0..15) to check if
4076 my @commitlist = $head ? parse_commits($head, 17) : ();
4078 git_print_header_div('shortlog');
4079 git_shortlog_body(\@commitlist, 0, 15, $refs,
4080 $#commitlist <= 15 ? undef :
4081 $cgi->a({-href => href(action=>"shortlog")}, "..."));
4085 git_print_header_div('tags');
4086 git_tags_body(\@taglist, 0, 15,
4087 $#taglist <= 15 ? undef :
4088 $cgi->a({-href => href(action=>"tags")}, "..."));
4092 git_print_header_div('heads');
4093 git_heads_body(\@headlist, $head, 0, 15,
4094 $#headlist <= 15 ? undef :
4095 $cgi->a({-href => href(action=>"heads")}, "..."));
4099 git_print_header_div('forks');
4100 git_project_list_body(\@forklist, undef, 0, 15,
4101 $#forklist <= 15 ? undef :
4102 $cgi->a({-href => href(action=>"forks")}, "..."),
4110 my $head = git_get_head_hash($project);
4112 git_print_page_nav('','', $head,undef,$head);
4113 my %tag = parse_tag($hash);
4116 die_error(undef, "Unknown tag object");
4119 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
4120 print "<div class=\"title_text\">\n" .
4121 "<table class=\"object_header\">\n" .
4123 "<td>object</td>\n" .
4124 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4125 $tag{'object'}) . "</td>\n" .
4126 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4127 $tag{'type'}) . "</td>\n" .
4129 if (defined($tag{'author'})) {
4130 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
4131 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
4132 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4133 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4136 print "</table>\n\n" .
4138 print "<div class=\"page_body\">";
4139 my $comment = $tag{'comment'};
4140 foreach my $line (@$comment) {
4142 print esc_html($line, -nbsp=>1) . "<br/>\n";
4152 my ($have_blame) = gitweb_check_feature('blame');
4154 die_error('403 Permission denied', "Permission denied");
4156 die_error('404 Not Found', "File name not defined") if (!$file_name);
4157 $hash_base ||= git_get_head_hash($project);
4158 die_error(undef, "Couldn't find base commit") unless ($hash_base);
4159 my %co = parse_commit($hash_base)
4160 or die_error(undef, "Reading commit failed");
4161 if (!defined $hash) {
4162 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4163 or die_error(undef, "Error looking up file");
4165 $ftype = git_get_type($hash);
4166 if ($ftype !~ "blob") {
4167 die_error('400 Bad Request', "Object is not a blob");
4169 open ($fd, "-|", git_cmd(), "blame", '-p', '--',
4170 $file_name, $hash_base)
4171 or die_error(undef, "Open git-blame failed");
4174 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4177 $cgi->a({-href => href(action=>"history", -replay=>1)},
4180 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4182 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4183 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4184 git_print_page_path($file_name, $ftype, $hash_base);
4185 my @rev_color = (qw(light2 dark2));
4186 my $num_colors = scalar(@rev_color);
4187 my $current_color = 0;
4190 <div class="page_body">
4191 <table class="blame">
4192 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4197 last unless defined $_;
4198 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4199 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4200 if (!exists $metainfo{$full_rev}) {
4201 $metainfo{$full_rev} = {};
4203 my $meta = $metainfo{$full_rev};
4206 if (/^(\S+) (.*)$/) {
4212 my $rev = substr($full_rev, 0, 8);
4213 my $author = $meta->{'author'};
4214 my %date = parse_date($meta->{'author-time'},
4215 $meta->{'author-tz'});
4216 my $date = $date{'iso-tz'};
4218 $current_color = ++$current_color % $num_colors;
4220 print "<tr class=\"$rev_color[$current_color]\">\n";
4222 print "<td class=\"sha1\"";
4223 print " title=\"". esc_html($author) . ", $date\"";
4224 print " rowspan=\"$group_size\"" if ($group_size > 1);
4226 print $cgi->a({-href => href(action=>"commit",
4228 file_name=>$file_name)},
4232 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4233 or die_error(undef, "Open git-rev-parse failed");
4234 my $parent_commit = <$dd>;
4236 chomp($parent_commit);
4237 my $blamed = href(action => 'blame',
4238 file_name => $meta->{'filename'},
4239 hash_base => $parent_commit);
4240 print "<td class=\"linenr\">";
4241 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4243 -class => "linenr" },
4246 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4252 or print "Reading blob failed\n";
4259 my ($have_blame) = gitweb_check_feature('blame');
4261 die_error('403 Permission denied', "Permission denied");
4263 die_error('404 Not Found', "File name not defined") if (!$file_name);
4264 $hash_base ||= git_get_head_hash($project);
4265 die_error(undef, "Couldn't find base commit") unless ($hash_base);
4266 my %co = parse_commit($hash_base)
4267 or die_error(undef, "Reading commit failed");
4268 if (!defined $hash) {
4269 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4270 or die_error(undef, "Error lookup file");
4272 open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4273 or die_error(undef, "Open git-annotate failed");
4276 $cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
4279 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
4282 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4284 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4285 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4286 git_print_page_path($file_name, 'blob', $hash_base);
4287 print "<div class=\"page_body\">\n";
4289 <table class="blame">
4298 my @line_class = (qw(light dark));
4299 my $line_class_len = scalar (@line_class);
4300 my $line_class_num = $#line_class;
4301 while (my $line = <$fd>) {
4313 $line_class_num = ($line_class_num + 1) % $line_class_len;
4315 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4322 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4325 $short_rev = substr ($long_rev, 0, 8);
4326 $age = time () - $time;
4327 $age_str = age_string ($age);
4328 $age_str =~ s/ / /g;
4329 $age_class = age_class($age);
4330 $author = esc_html ($author);
4331 $author =~ s/ / /g;
4333 $data = untabify($data);
4334 $data = esc_html ($data);
4337 <tr class="$line_class[$line_class_num]">
4338 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4339 <td class="$age_class">$age_str</td>
4341 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4342 <td class="pre">$data</td>
4345 } # while (my $line = <$fd>)
4346 print "</table>\n\n";
4348 or print "Reading blob failed.\n";
4354 my $head = git_get_head_hash($project);
4356 git_print_page_nav('','', $head,undef,$head);
4357 git_print_header_div('summary', $project);
4359 my @tagslist = git_get_tags_list();
4361 git_tags_body(\@tagslist);
4367 my $head = git_get_head_hash($project);
4369 git_print_page_nav('','', $head,undef,$head);
4370 git_print_header_div('summary', $project);
4372 my @headslist = git_get_heads_list();
4374 git_heads_body(\@headslist, $head);
4379 sub git_blob_plain {
4382 if (!defined $hash) {
4383 if (defined $file_name) {
4384 my $base = $hash_base || git_get_head_hash($project);
4385 $hash = git_get_hash_by_path($base, $file_name, "blob")
4386 or die_error(undef, "Error lookup file");
4388 die_error(undef, "No file name defined");
4390 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4391 # blobs defined by non-textual hash id's can be cached
4396 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4397 or die_error(undef, "Couldn't cat $file_name, $hash");
4399 $type ||= blob_mimetype($fd, $file_name);
4401 # save as filename, even when no $file_name is given
4402 my $save_as = "$hash";
4403 if (defined $file_name) {
4404 $save_as = $file_name;
4405 } elsif ($type =~ m/^text\//) {
4412 -content_disposition => 'inline; filename="' . "$save_as" . '"');
4414 binmode STDOUT, ':raw';
4416 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4424 if (!defined $hash) {
4425 if (defined $file_name) {
4426 my $base = $hash_base || git_get_head_hash($project);
4427 $hash = git_get_hash_by_path($base, $file_name, "blob")
4428 or die_error(undef, "Error lookup file");
4430 die_error(undef, "No file name defined");
4432 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4433 # blobs defined by non-textual hash id's can be cached
4437 my ($have_blame) = gitweb_check_feature('blame');
4438 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4439 or die_error(undef, "Couldn't cat $file_name, $hash");
4440 my $mimetype = blob_mimetype($fd, $file_name);
4441 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4443 return git_blob_plain($mimetype);
4445 # we can have blame only for text/* mimetype
4446 $have_blame &&= ($mimetype =~ m!^text/!);
4448 git_header_html(undef, $expires);
4449 my $formats_nav = '';
4450 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4451 if (defined $file_name) {
4454 $cgi->a({-href => href(action=>"blame", -replay=>1)},
4459 $cgi->a({-href => href(action=>"history", -replay=>1)},
4462 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4465 $cgi->a({-href => href(action=>"blob",
4466 hash_base=>"HEAD", file_name=>$file_name)},
4470 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4473 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4474 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4476 print "<div class=\"page_nav\">\n" .
4477 "<br/><br/></div>\n" .
4478 "<div class=\"title\">$hash</div>\n";
4480 git_print_page_path($file_name, "blob", $hash_base);
4481 print "<div class=\"page_body\">\n";
4482 if ($mimetype =~ m!^image/!) {
4483 print qq!<img type="$mimetype"!;
4485 print qq! alt="$file_name" title="$file_name"!;
4488 href(action=>"blob_plain", hash=>$hash,
4489 hash_base=>$hash_base, file_name=>$file_name) .
4493 while (my $line = <$fd>) {
4496 $line = untabify($line);
4497 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4498 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
4502 or print "Reading blob failed.\n";
4508 if (!defined $hash_base) {
4509 $hash_base = "HEAD";
4511 if (!defined $hash) {
4512 if (defined $file_name) {
4513 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
4519 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4520 or die_error(undef, "Open git-ls-tree failed");
4521 my @entries = map { chomp; $_ } <$fd>;
4522 close $fd or die_error(undef, "Reading tree failed");
4525 my $refs = git_get_references();
4526 my $ref = format_ref_marker($refs, $hash_base);
4529 my ($have_blame) = gitweb_check_feature('blame');
4530 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4532 if (defined $file_name) {
4534 $cgi->a({-href => href(action=>"history", -replay=>1)},
4536 $cgi->a({-href => href(action=>"tree",
4537 hash_base=>"HEAD", file_name=>$file_name)},
4540 my $snapshot_links = format_snapshot_links($hash);
4541 if (defined $snapshot_links) {
4542 # FIXME: Should be available when we have no hash base as well.
4543 push @views_nav, $snapshot_links;
4545 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4546 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
4549 print "<div class=\"page_nav\">\n";
4550 print "<br/><br/></div>\n";
4551 print "<div class=\"title\">$hash</div>\n";
4553 if (defined $file_name) {
4554 $basedir = $file_name;
4555 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4559 git_print_page_path($file_name, 'tree', $hash_base);
4560 print "<div class=\"page_body\">\n";
4561 print "<table class=\"tree\">\n";
4563 # '..' (top directory) link if possible
4564 if (defined $hash_base &&
4565 defined $file_name && $file_name =~ m![^/]+$!) {
4567 print "<tr class=\"dark\">\n";
4569 print "<tr class=\"light\">\n";
4573 my $up = $file_name;
4574 $up =~ s!/?[^/]+$!!;
4575 undef $up unless $up;
4576 # based on git_print_tree_entry
4577 print '<td class="mode">' . mode_str('040000') . "</td>\n";
4578 print '<td class="list">';
4579 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
4583 print "<td class=\"link\"></td>\n";
4587 foreach my $line (@entries) {
4588 my %t = parse_ls_tree_line($line, -z => 1);
4591 print "<tr class=\"dark\">\n";
4593 print "<tr class=\"light\">\n";
4597 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
4601 print "</table>\n" .
4607 my @supported_fmts = gitweb_check_feature('snapshot');
4608 @supported_fmts = filter_snapshot_fmts(@supported_fmts);
4610 my $format = $cgi->param('sf');
4611 if (!@supported_fmts) {
4612 die_error('403 Permission denied', "Permission denied");
4614 # default to first supported snapshot format
4615 $format ||= $supported_fmts[0];
4616 if ($format !~ m/^[a-z0-9]+$/) {
4617 die_error(undef, "Invalid snapshot format parameter");
4618 } elsif (!exists($known_snapshot_formats{$format})) {
4619 die_error(undef, "Unknown snapshot format");
4620 } elsif (!grep($_ eq $format, @supported_fmts)) {
4621 die_error(undef, "Unsupported snapshot format");
4624 if (!defined $hash) {
4625 $hash = git_get_head_hash($project);
4628 my $git_command = git_cmd_str();
4629 my $name = $project;
4630 $name =~ s,([^/])/*\.git$,$1,;
4631 $name = basename($name);
4632 my $filename = to_utf8($name);
4633 $name =~ s/\047/\047\\\047\047/g;
4635 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4636 $cmd = "$git_command archive " .
4637 "--format=$known_snapshot_formats{$format}{'format'} " .
4638 "--prefix=\'$name\'/ $hash";
4639 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4640 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4644 -type => $known_snapshot_formats{$format}{'type'},
4645 -content_disposition => 'inline; filename="' . "$filename" . '"',
4646 -status => '200 OK');
4648 open my $fd, "-|", $cmd
4649 or die_error(undef, "Execute git-archive failed");
4650 binmode STDOUT, ':raw';
4652 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4657 my $head = git_get_head_hash($project);
4658 if (!defined $hash) {
4661 if (!defined $page) {
4664 my $refs = git_get_references();
4666 my @commitlist = parse_commits($hash, 101, (100 * $page));
4668 my $paging_nav = format_paging_nav('log', $hash, $head, $page, (100 * ($page+1)));
4671 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
4674 my %co = parse_commit($hash);
4676 git_print_header_div('summary', $project);
4677 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4679 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4680 for (my $i = 0; $i <= $to; $i++) {
4681 my %co = %{$commitlist[$i]};
4683 my $commit = $co{'id'};
4684 my $ref = format_ref_marker($refs, $commit);
4685 my %ad = parse_date($co{'author_epoch'});
4686 git_print_header_div('commit',
4687 "<span class=\"age\">$co{'age_string'}</span>" .
4688 esc_html($co{'title'}) . $ref,
4690 print "<div class=\"title_text\">\n" .
4691 "<div class=\"log_link\">\n" .
4692 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
4694 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
4696 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
4699 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4702 print "<div class=\"log_body\">\n";
4703 git_print_log($co{'comment'}, -final_empty_line=> 1);
4706 if ($#commitlist >= 100) {
4707 print "<div class=\"page_nav\">\n";
4708 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
4709 -accesskey => "n", -title => "Alt-n"}, "next");
4716 $hash ||= $hash_base || "HEAD";
4717 my %co = parse_commit($hash);
4719 die_error(undef, "Unknown commit object");
4721 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
4722 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
4724 my $parent = $co{'parent'};
4725 my $parents = $co{'parents'}; # listref
4727 # we need to prepare $formats_nav before any parameter munging
4729 if (!defined $parent) {
4731 $formats_nav .= '(initial)';
4732 } elsif (@$parents == 1) {
4733 # single parent commit
4736 $cgi->a({-href => href(action=>"commit",
4738 esc_html(substr($parent, 0, 7))) .
4745 $cgi->a({-href => href(action=>"commit",
4747 esc_html(substr($_, 0, 7)));
4752 if (!defined $parent) {
4756 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
4758 (@$parents <= 1 ? $parent : '-c'),
4760 or die_error(undef, "Open git-diff-tree failed");
4761 @difftree = map { chomp; $_ } <$fd>;
4762 close $fd or die_error(undef, "Reading git-diff-tree failed");
4764 # non-textual hash id's can be cached
4766 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4769 my $refs = git_get_references();
4770 my $ref = format_ref_marker($refs, $co{'id'});
4772 git_header_html(undef, $expires);
4773 git_print_page_nav('commit', '',
4774 $hash, $co{'tree'}, $hash,
4777 if (defined $co{'parent'}) {
4778 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
4780 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
4782 print "<div class=\"title_text\">\n" .
4783 "<table class=\"object_header\">\n";
4784 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
4786 "<td></td><td> $ad{'rfc2822'}";
4787 if ($ad{'hour_local'} < 6) {
4788 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4789 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4791 printf(" (%02d:%02d %s)",
4792 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4796 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
4797 print "<tr><td></td><td> $cd{'rfc2822'}" .
4798 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4800 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4803 "<td class=\"sha1\">" .
4804 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
4805 class => "list"}, $co{'tree'}) .
4807 "<td class=\"link\">" .
4808 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
4810 my $snapshot_links = format_snapshot_links($hash);
4811 if (defined $snapshot_links) {
4812 print " | " . $snapshot_links;
4817 foreach my $par (@$parents) {
4820 "<td class=\"sha1\">" .
4821 $cgi->a({-href => href(action=>"commit", hash=>$par),
4822 class => "list"}, $par) .
4824 "<td class=\"link\">" .
4825 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
4827 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
4834 print "<div class=\"page_body\">\n";
4835 git_print_log($co{'comment'});
4838 git_difftree_body(\@difftree, $hash, @$parents);
4844 # object is defined by:
4845 # - hash or hash_base alone
4846 # - hash_base and file_name
4849 # - hash or hash_base alone
4850 if ($hash || ($hash_base && !defined $file_name)) {
4851 my $object_id = $hash || $hash_base;
4853 my $git_command = git_cmd_str();
4854 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4855 or die_error('404 Not Found', "Object does not exist");
4859 or die_error('404 Not Found', "Object does not exist");
4861 # - hash_base and file_name
4862 } elsif ($hash_base && defined $file_name) {
4863 $file_name =~ s,/+$,,;
4865 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
4866 or die_error('404 Not Found', "Base object does not exist");
4868 # here errors should not hapen
4869 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
4870 or die_error(undef, "Open git-ls-tree failed");
4874 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4875 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4876 die_error('404 Not Found', "File or directory for given base does not exist");
4881 die_error('404 Not Found', "Not enough information to find object");
4884 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
4885 hash=>$hash, hash_base=>$hash_base,
4886 file_name=>$file_name),
4887 -status => '302 Found');
4891 my $format = shift || 'html';
4898 # preparing $fd and %diffinfo for git_patchset_body
4900 if (defined $hash_base && defined $hash_parent_base) {
4901 if (defined $file_name) {
4903 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4904 $hash_parent_base, $hash_base,
4905 "--", (defined $file_parent ? $file_parent : ()), $file_name
4906 or die_error(undef, "Open git-diff-tree failed");
4907 @difftree = map { chomp; $_ } <$fd>;
4909 or die_error(undef, "Reading git-diff-tree failed");
4911 or die_error('404 Not Found', "Blob diff not found");
4913 } elsif (defined $hash &&
4914 $hash =~ /[0-9a-fA-F]{40}/) {
4915 # try to find filename from $hash
4917 # read filtered raw output
4918 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4919 $hash_parent_base, $hash_base, "--"
4920 or die_error(undef, "Open git-diff-tree failed");
4922 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4924 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4925 map { chomp; $_ } <$fd>;
4927 or die_error(undef, "Reading git-diff-tree failed");
4929 or die_error('404 Not Found', "Blob diff not found");
4932 die_error('404 Not Found', "Missing one of the blob diff parameters");
4935 if (@difftree > 1) {
4936 die_error('404 Not Found', "Ambiguous blob diff specification");
4939 %diffinfo = parse_difftree_raw_line($difftree[0]);
4940 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4941 $file_name ||= $diffinfo{'to_file'};
4943 $hash_parent ||= $diffinfo{'from_id'};
4944 $hash ||= $diffinfo{'to_id'};
4946 # non-textual hash id's can be cached
4947 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4948 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4953 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
4954 '-p', ($format eq 'html' ? "--full-index" : ()),
4955 $hash_parent_base, $hash_base,
4956 "--", (defined $file_parent ? $file_parent : ()), $file_name
4957 or die_error(undef, "Open git-diff-tree failed");
4960 # old/legacy style URI
4961 if (!%diffinfo && # if new style URI failed
4962 defined $hash && defined $hash_parent) {
4963 # fake git-diff-tree raw output
4964 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4965 $diffinfo{'from_id'} = $hash_parent;
4966 $diffinfo{'to_id'} = $hash;
4967 if (defined $file_name) {
4968 if (defined $file_parent) {
4969 $diffinfo{'status'} = '2';
4970 $diffinfo{'from_file'} = $file_parent;
4971 $diffinfo{'to_file'} = $file_name;
4972 } else { # assume not renamed
4973 $diffinfo{'status'} = '1';
4974 $diffinfo{'from_file'} = $file_name;
4975 $diffinfo{'to_file'} = $file_name;
4977 } else { # no filename given
4978 $diffinfo{'status'} = '2';
4979 $diffinfo{'from_file'} = $hash_parent;
4980 $diffinfo{'to_file'} = $hash;
4983 # non-textual hash id's can be cached
4984 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4985 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4990 open $fd, "-|", git_cmd(), "diff", @diff_opts,
4991 '-p', ($format eq 'html' ? "--full-index" : ()),
4992 $hash_parent, $hash, "--"
4993 or die_error(undef, "Open git-diff failed");
4995 die_error('404 Not Found', "Missing one of the blob diff parameters")
5000 if ($format eq 'html') {
5002 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
5004 git_header_html(undef, $expires);
5005 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5006 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5007 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5009 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5010 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5012 if (defined $file_name) {
5013 git_print_page_path($file_name, "blob", $hash_base);
5015 print "<div class=\"page_path\"></div>\n";
5018 } elsif ($format eq 'plain') {
5020 -type => 'text/plain',
5021 -charset => 'utf-8',
5022 -expires => $expires,
5023 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
5025 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5028 die_error(undef, "Unknown blobdiff format");
5032 if ($format eq 'html') {
5033 print "<div class=\"page_body\">\n";
5035 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
5038 print "</div>\n"; # class="page_body"
5042 while (my $line = <$fd>) {
5043 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5044 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5048 last if $line =~ m!^\+\+\+!;
5056 sub git_blobdiff_plain {
5057 git_blobdiff('plain');
5060 sub git_commitdiff {
5061 my $format = shift || 'html';
5062 $hash ||= $hash_base || "HEAD";
5063 my %co = parse_commit($hash);
5065 die_error(undef, "Unknown commit object");
5068 # choose format for commitdiff for merge
5069 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5070 $hash_parent = '--cc';
5072 # we need to prepare $formats_nav before almost any parameter munging
5074 if ($format eq 'html') {
5076 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
5079 if (defined $hash_parent &&
5080 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5081 # commitdiff with two commits given
5082 my $hash_parent_short = $hash_parent;
5083 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5084 $hash_parent_short = substr($hash_parent, 0, 7);
5088 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5089 if ($co{'parents'}[$i] eq $hash_parent) {
5090 $formats_nav .= ' parent ' . ($i+1);
5094 $formats_nav .= ': ' .
5095 $cgi->a({-href => href(action=>"commitdiff",
5096 hash=>$hash_parent)},
5097 esc_html($hash_parent_short)) .
5099 } elsif (!$co{'parent'}) {
5101 $formats_nav .= ' (initial)';
5102 } elsif (scalar @{$co{'parents'}} == 1) {
5103 # single parent commit
5106 $cgi->a({-href => href(action=>"commitdiff",
5107 hash=>$co{'parent'})},
5108 esc_html(substr($co{'parent'}, 0, 7))) .
5112 if ($hash_parent eq '--cc') {
5113 $formats_nav .= ' | ' .
5114 $cgi->a({-href => href(action=>"commitdiff",
5115 hash=>$hash, hash_parent=>'-c')},
5117 } else { # $hash_parent eq '-c'
5118 $formats_nav .= ' | ' .
5119 $cgi->a({-href => href(action=>"commitdiff",
5120 hash=>$hash, hash_parent=>'--cc')},
5126 $cgi->a({-href => href(action=>"commitdiff",
5128 esc_html(substr($_, 0, 7)));
5129 } @{$co{'parents'}} ) .
5134 my $hash_parent_param = $hash_parent;
5135 if (!defined $hash_parent_param) {
5136 # --cc for multiple parents, --root for parentless
5137 $hash_parent_param =
5138 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5144 if ($format eq 'html') {
5145 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5146 "--no-commit-id", "--patch-with-raw", "--full-index",
5147 $hash_parent_param, $hash, "--"
5148 or die_error(undef, "Open git-diff-tree failed");
5150 while (my $line = <$fd>) {
5152 # empty line ends raw part of diff-tree output
5154 push @difftree, scalar parse_difftree_raw_line($line);
5157 } elsif ($format eq 'plain') {
5158 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5159 '-p', $hash_parent_param, $hash, "--"
5160 or die_error(undef, "Open git-diff-tree failed");
5163 die_error(undef, "Unknown commitdiff format");
5166 # non-textual hash id's can be cached
5168 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5172 # write commit message
5173 if ($format eq 'html') {
5174 my $refs = git_get_references();
5175 my $ref = format_ref_marker($refs, $co{'id'});
5177 git_header_html(undef, $expires);
5178 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5179 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5180 git_print_authorship(\%co);
5181 print "<div class=\"page_body\">\n";
5182 if (@{$co{'comment'}} > 1) {
5183 print "<div class=\"log\">\n";
5184 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5185 print "</div>\n"; # class="log"
5188 } elsif ($format eq 'plain') {
5189 my $refs = git_get_references("tags");
5190 my $tagname = git_get_rev_name_tags($hash);
5191 my $filename = basename($project) . "-$hash.patch";
5194 -type => 'text/plain',
5195 -charset => 'utf-8',
5196 -expires => $expires,
5197 -content_disposition => 'inline; filename="' . "$filename" . '"');
5198 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5199 print "From: " . to_utf8($co{'author'}) . "\n";
5200 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5201 print "Subject: " . to_utf8($co{'title'}) . "\n";
5203 print "X-Git-Tag: $tagname\n" if $tagname;
5204 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5206 foreach my $line (@{$co{'comment'}}) {
5207 print to_utf8($line) . "\n";
5213 if ($format eq 'html') {
5214 my $use_parents = !defined $hash_parent ||
5215 $hash_parent eq '-c' || $hash_parent eq '--cc';
5216 git_difftree_body(\@difftree, $hash,
5217 $use_parents ? @{$co{'parents'}} : $hash_parent);
5220 git_patchset_body($fd, \@difftree, $hash,
5221 $use_parents ? @{$co{'parents'}} : $hash_parent);
5223 print "</div>\n"; # class="page_body"
5226 } elsif ($format eq 'plain') {
5230 or print "Reading git-diff-tree failed\n";
5234 sub git_commitdiff_plain {
5235 git_commitdiff('plain');
5239 if (!defined $hash_base) {
5240 $hash_base = git_get_head_hash($project);
5242 if (!defined $page) {
5246 my %co = parse_commit($hash_base);
5248 die_error(undef, "Unknown commit object");
5251 my $refs = git_get_references();
5252 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5254 my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5255 $file_name, "--full-history");
5257 die_error('404 Not Found', "No such file or directory on given branch");
5260 if (!defined $hash && defined $file_name) {
5261 # some commits could have deleted file in question,
5262 # and not have it in tree, but one of them has to have it
5263 for (my $i = 0; $i <= @commitlist; $i++) {
5264 $hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5265 last if defined $hash;
5268 if (defined $hash) {
5269 $ftype = git_get_type($hash);
5271 if (!defined $ftype) {
5272 die_error(undef, "Unknown type of object");
5275 my $paging_nav = '';
5278 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5279 file_name=>$file_name)},
5281 $paging_nav .= " ⋅ " .
5282 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5283 -accesskey => "p", -title => "Alt-p"}, "prev");
5285 $paging_nav .= "first";
5286 $paging_nav .= " ⋅ prev";
5289 if ($#commitlist >= 100) {
5291 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5292 -accesskey => "n", -title => "Alt-n"}, "next");
5293 $paging_nav .= " ⋅ $next_link";
5295 $paging_nav .= " ⋅ next";
5299 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5300 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5301 git_print_page_path($file_name, $ftype, $hash_base);
5303 git_history_body(\@commitlist, 0, 99,
5304 $refs, $hash_base, $ftype, $next_link);
5310 my ($have_search) = gitweb_check_feature('search');
5311 if (!$have_search) {
5312 die_error('403 Permission denied', "Permission denied");
5314 if (!defined $searchtext) {
5315 die_error(undef, "Text field empty");
5317 if (!defined $hash) {
5318 $hash = git_get_head_hash($project);
5320 my %co = parse_commit($hash);
5322 die_error(undef, "Unknown commit object");
5324 if (!defined $page) {
5328 $searchtype ||= 'commit';
5329 if ($searchtype eq 'pickaxe') {
5330 # pickaxe may take all resources of your box and run for several minutes
5331 # with every query - so decide by yourself how public you make this feature
5332 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5333 if (!$have_pickaxe) {
5334 die_error('403 Permission denied', "Permission denied");
5337 if ($searchtype eq 'grep') {
5338 my ($have_grep) = gitweb_check_feature('grep');
5340 die_error('403 Permission denied', "Permission denied");
5346 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5348 if ($searchtype eq 'commit') {
5349 $greptype = "--grep=";
5350 } elsif ($searchtype eq 'author') {
5351 $greptype = "--author=";
5352 } elsif ($searchtype eq 'committer') {
5353 $greptype = "--committer=";
5355 $greptype .= $searchtext;
5356 my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5357 $greptype, '--regexp-ignore-case',
5358 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5360 my $paging_nav = '';
5363 $cgi->a({-href => href(action=>"search", hash=>$hash,
5364 searchtext=>$searchtext,
5365 searchtype=>$searchtype)},
5367 $paging_nav .= " ⋅ " .
5368 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5369 -accesskey => "p", -title => "Alt-p"}, "prev");
5371 $paging_nav .= "first";
5372 $paging_nav .= " ⋅ prev";
5375 if ($#commitlist >= 100) {
5377 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5378 -accesskey => "n", -title => "Alt-n"}, "next");
5379 $paging_nav .= " ⋅ $next_link";
5381 $paging_nav .= " ⋅ next";
5384 if ($#commitlist >= 100) {
5387 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5388 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5389 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5392 if ($searchtype eq 'pickaxe') {
5393 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5394 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5396 print "<table class=\"pickaxe search\">\n";
5399 open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
5400 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5401 ($search_use_regexp ? '--pickaxe-regex' : ());
5404 while (my $line = <$fd>) {
5408 my %set = parse_difftree_raw_line($line);
5409 if (defined $set{'commit'}) {
5410 # finish previous commit
5413 "<td class=\"link\">" .
5414 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5416 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5422 print "<tr class=\"dark\">\n";
5424 print "<tr class=\"light\">\n";
5427 %co = parse_commit($set{'commit'});
5428 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5429 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5430 "<td><i>$author</i></td>\n" .
5432 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
5433 -class => "list subject"},
5434 chop_and_escape_str($co{'title'}, 50) . "<br/>");
5435 } elsif (defined $set{'to_id'}) {
5436 next if ($set{'to_id'} =~ m/^0{40}$/);
5438 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
5439 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),
5441 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
5447 # finish last commit (warning: repetition!)
5450 "<td class=\"link\">" .
5451 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5453 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5461 if ($searchtype eq 'grep') {
5462 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5463 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5465 print "<table class=\"grep_search\">\n";
5469 open my $fd, "-|", git_cmd(), 'grep', '-n',
5470 $search_use_regexp ? ('-E', '-i') : '-F',
5471 $searchtext, $co{'tree'};
5473 while (my $line = <$fd>) {
5475 my ($file, $lno, $ltext, $binary);
5476 last if ($matches++ > 1000);
5477 if ($line =~ /^Binary file (.+) matches$/) {
5481 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5483 if ($file ne $lastfile) {
5484 $lastfile and print "</td></tr>\n";
5486 print "<tr class=\"dark\">\n";
5488 print "<tr class=\"light\">\n";
5490 print "<td class=\"list\">".
5491 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5492 file_name=>"$file"),
5493 -class => "list"}, esc_path($file));
5494 print "</td><td>\n";
5498 print "<div class=\"binary\">Binary file</div>\n";
5500 $ltext = untabify($ltext);
5501 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5502 $ltext = esc_html($1, -nbsp=>1);
5503 $ltext .= '<span class="match">';
5504 $ltext .= esc_html($2, -nbsp=>1);
5505 $ltext .= '</span>';
5506 $ltext .= esc_html($3, -nbsp=>1);
5508 $ltext = esc_html($ltext, -nbsp=>1);
5510 print "<div class=\"pre\">" .
5511 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5512 file_name=>"$file").'#l'.$lno,
5513 -class => "linenr"}, sprintf('%4i', $lno))
5514 . ' ' . $ltext . "</div>\n";
5518 print "</td></tr>\n";
5519 if ($matches > 1000) {
5520 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5523 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5532 sub git_search_help {
5534 git_print_page_nav('','', $hash,$hash,$hash);
5536 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5537 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5538 the pattern entered is recognized as the POSIX extended
5539 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5542 <dt><b>commit</b></dt>
5543 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5545 my ($have_grep) = gitweb_check_feature('grep');
5548 <dt><b>grep</b></dt>
5549 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5550 a different one) are searched for the given pattern. On large trees, this search can take
5551 a while and put some strain on the server, so please use it with some consideration. Note that
5552 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5553 case-sensitive.</dd>
5557 <dt><b>author</b></dt>
5558 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5559 <dt><b>committer</b></dt>
5560 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5562 my ($have_pickaxe) = gitweb_check_feature('pickaxe');
5563 if ($have_pickaxe) {
5565 <dt><b>pickaxe</b></dt>
5566 <dd>All commits that caused the string to appear or disappear from any file (changes that
5567 added, removed or "modified" the string) will be listed. This search can take a while and
5568 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5569 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5577 my $head = git_get_head_hash($project);
5578 if (!defined $hash) {
5581 if (!defined $page) {
5584 my $refs = git_get_references();
5586 my @commitlist = parse_commits($hash, 101, (100 * $page));
5588 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, (100 * ($page+1)));
5590 if ($#commitlist >= 100) {
5592 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5593 -accesskey => "n", -title => "Alt-n"}, "next");
5597 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
5598 git_print_header_div('summary', $project);
5600 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
5605 ## ......................................................................
5606 ## feeds (RSS, Atom; OPML)
5609 my $format = shift || 'atom';
5610 my ($have_blame) = gitweb_check_feature('blame');
5612 # Atom: http://www.atomenabled.org/developers/syndication/
5613 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5614 if ($format ne 'rss' && $format ne 'atom') {
5615 die_error(undef, "Unknown web feed format");
5618 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5619 my $head = $hash || 'HEAD';
5620 my @commitlist = parse_commits($head, 150, 0, $file_name);
5624 my $content_type = "application/$format+xml";
5625 if (defined $cgi->http('HTTP_ACCEPT') &&
5626 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5627 # browser (feed reader) prefers text/xml
5628 $content_type = 'text/xml';
5630 if (defined($commitlist[0])) {
5631 %latest_commit = %{$commitlist[0]};
5632 %latest_date = parse_date($latest_commit{'author_epoch'});
5634 -type => $content_type,
5635 -charset => 'utf-8',
5636 -last_modified => $latest_date{'rfc2822'});
5639 -type => $content_type,
5640 -charset => 'utf-8');
5643 # Optimization: skip generating the body if client asks only
5644 # for Last-Modified date.
5645 return if ($cgi->request_method() eq 'HEAD');
5648 my $title = "$site_name - $project/$action";
5649 my $feed_type = 'log';
5650 if (defined $hash) {
5651 $title .= " - '$hash'";
5652 $feed_type = 'branch log';
5653 if (defined $file_name) {
5654 $title .= " :: $file_name";
5655 $feed_type = 'history';
5657 } elsif (defined $file_name) {
5658 $title .= " - $file_name";
5659 $feed_type = 'history';
5661 $title .= " $feed_type";
5662 my $descr = git_get_project_description($project);
5663 if (defined $descr) {
5664 $descr = esc_html($descr);
5666 $descr = "$project " .
5667 ($format eq 'rss' ? 'RSS' : 'Atom') .
5670 my $owner = git_get_project_owner($project);
5671 $owner = esc_html($owner);
5675 if (defined $file_name) {
5676 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
5677 } elsif (defined $hash) {
5678 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
5680 $alt_url = href(-full=>1, action=>"summary");
5682 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
5683 if ($format eq 'rss') {
5685 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5688 print "<title>$title</title>\n" .
5689 "<link>$alt_url</link>\n" .
5690 "<description>$descr</description>\n" .
5691 "<language>en</language>\n";
5692 } elsif ($format eq 'atom') {
5694 <feed xmlns="http://www.w3.org/2005/Atom">
5696 print "<title>$title</title>\n" .
5697 "<subtitle>$descr</subtitle>\n" .
5698 '<link rel="alternate" type="text/html" href="' .
5699 $alt_url . '" />' . "\n" .
5700 '<link rel="self" type="' . $content_type . '" href="' .
5701 $cgi->self_url() . '" />' . "\n" .
5702 "<id>" . href(-full=>1) . "</id>\n" .
5703 # use project owner for feed author
5704 "<author><name>$owner</name></author>\n";
5705 if (defined $favicon) {
5706 print "<icon>" . esc_url($favicon) . "</icon>\n";
5708 if (defined $logo_url) {
5709 # not twice as wide as tall: 72 x 27 pixels
5710 print "<logo>" . esc_url($logo) . "</logo>\n";
5712 if (! %latest_date) {
5713 # dummy date to keep the feed valid until commits trickle in:
5714 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5716 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5721 for (my $i = 0; $i <= $#commitlist; $i++) {
5722 my %co = %{$commitlist[$i]};
5723 my $commit = $co{'id'};
5724 # we read 150, we always show 30 and the ones more recent than 48 hours
5725 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5728 my %cd = parse_date($co{'author_epoch'});
5730 # get list of changed files
5731 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5732 $co{'parent'} || "--root",
5733 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5735 my @difftree = map { chomp; $_ } <$fd>;
5739 # print element (entry, item)
5740 my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
5741 if ($format eq 'rss') {
5743 "<title>" . esc_html($co{'title'}) . "</title>\n" .
5744 "<author>" . esc_html($co{'author'}) . "</author>\n" .
5745 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5746 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5747 "<link>$co_url</link>\n" .
5748 "<description>" . esc_html($co{'title'}) . "</description>\n" .
5749 "<content:encoded>" .
5751 } elsif ($format eq 'atom') {
5753 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
5754 "<updated>$cd{'iso-8601'}</updated>\n" .
5756 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
5757 if ($co{'author_email'}) {
5758 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
5760 print "</author>\n" .
5761 # use committer for contributor
5763 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
5764 if ($co{'committer_email'}) {
5765 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
5767 print "</contributor>\n" .
5768 "<published>$cd{'iso-8601'}</published>\n" .
5769 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5770 "<id>$co_url</id>\n" .
5771 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
5772 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5774 my $comment = $co{'comment'};
5776 foreach my $line (@$comment) {
5777 $line = esc_html($line);
5780 print "</pre><ul>\n";
5781 foreach my $difftree_line (@difftree) {
5782 my %difftree = parse_difftree_raw_line($difftree_line);
5783 next if !$difftree{'from_id'};
5785 my $file = $difftree{'file'} || $difftree{'to_file'};
5789 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
5790 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
5791 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
5792 file_name=>$file, file_parent=>$difftree{'from_file'}),
5793 -title => "diff"}, 'D');
5795 print $cgi->a({-href => href(-full=>1, action=>"blame",
5796 file_name=>$file, hash_base=>$commit),
5797 -title => "blame"}, 'B');
5799 # if this is not a feed of a file history
5800 if (!defined $file_name || $file_name ne $file) {
5801 print $cgi->a({-href => href(-full=>1, action=>"history",
5802 file_name=>$file, hash=>$commit),
5803 -title => "history"}, 'H');
5805 $file = esc_path($file);
5809 if ($format eq 'rss') {
5810 print "</ul>]]>\n" .
5811 "</content:encoded>\n" .
5813 } elsif ($format eq 'atom') {
5814 print "</ul>\n</div>\n" .
5821 if ($format eq 'rss') {
5822 print "</channel>\n</rss>\n";
5823 } elsif ($format eq 'atom') {
5837 my @list = git_get_projects_list();
5839 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
5841 <?xml version="1.0" encoding="utf-8"?>
5842 <opml version="1.0">
5844 <title>$site_name OPML Export</title>
5847 <outline text="git RSS feeds">
5850 foreach my $pr (@list) {
5852 my $head = git_get_head_hash($proj{'path'});
5853 if (!defined $head) {
5856 $git_dir = "$projectroot/$proj{'path'}";
5857 my %co = parse_commit($head);
5862 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
5863 my $rss = "$my_url?p=$proj{'path'};a=rss";
5864 my $html = "$my_url?p=$proj{'path'};a=summary";
5865 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";