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 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # the width (in characters) of the projects list "Description" column
76 our $projects_list_description_width = 25;
78 # default order of projects list
79 # valid values are none, project, descr, owner, and age
80 our $default_projects_order = "project";
82 # show repository only if this file exists
83 # (only effective if this variable evaluates to true)
84 our $export_ok = "++GITWEB_EXPORT_OK++";
86 # only allow viewing of repositories also shown on the overview page
87 our $strict_export = "++GITWEB_STRICT_EXPORT++";
89 # list of git base URLs used for URL to where fetch project from,
90 # i.e. full URL is "$git_base_url/$project"
91 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
93 # default blob_plain mimetype and default charset for text/plain blob
94 our $default_blob_plain_mimetype = 'text/plain';
95 our $default_text_plain_charset = undef;
97 # file to use for guessing MIME types before trying /etc/mime.types
98 # (relative to the current git repository)
99 our $mimetypes_file = undef;
101 # assume this charset if line contains non-UTF-8 characters;
102 # it should be valid encoding (see Encoding::Supported(3pm) for list),
103 # for which encoding all byte sequences are valid, for example
104 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
105 # could be even 'utf-8' for the old behavior)
106 our $fallback_encoding = 'latin1';
108 # rename detection options for git-diff and git-diff-tree
109 # - default is '-M', with the cost proportional to
110 # (number of removed files) * (number of new files).
111 # - more costly is '-C' (which implies '-M'), with the cost proportional to
112 # (number of changed files + number of removed files) * (number of new files)
113 # - even more costly is '-C', '--find-copies-harder' with cost
114 # (number of files in the original tree) * (number of new files)
115 # - one might want to include '-B' option, e.g. '-B', '-M'
116 our @diff_opts = ('-M'); # taken from git_commit
118 # information about snapshot formats that gitweb is capable of serving
119 our %known_snapshot_formats = (
121 # 'display' => display name,
122 # 'type' => mime type,
123 # 'suffix' => filename suffix,
124 # 'format' => --format for git-archive,
125 # 'compressor' => [compressor command and arguments]
126 # (array reference, optional)}
129 'display' => 'tar.gz',
130 'type' => 'application/x-gzip',
131 'suffix' => '.tar.gz',
133 'compressor' => ['gzip']},
136 'display' => 'tar.bz2',
137 'type' => 'application/x-bzip2',
138 'suffix' => '.tar.bz2',
140 'compressor' => ['bzip2']},
144 'type' => 'application/x-zip',
149 # Aliases so we understand old gitweb.snapshot values in repository
151 our %known_snapshot_format_aliases = (
155 # backward compatibility: legacy gitweb config support
156 'x-gzip' => undef, 'gz' => undef,
157 'x-bzip2' => undef, 'bz2' => undef,
158 'x-zip' => undef, '' => undef,
161 # You define site-wide feature defaults here; override them with
162 # $GITWEB_CONFIG as necessary.
165 # 'sub' => feature-sub (subroutine),
166 # 'override' => allow-override (boolean),
167 # 'default' => [ default options...] (array reference)}
169 # if feature is overridable (it means that allow-override has true value),
170 # then feature-sub will be called with default options as parameters;
171 # return value of feature-sub indicates if to enable specified feature
173 # if there is no 'sub' key (no feature-sub), then feature cannot be
176 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
178 # Enable the 'blame' blob view, showing the last commit that modified
179 # each line in the file. This can be very CPU-intensive.
181 # To enable system wide have in $GITWEB_CONFIG
182 # $feature{'blame'}{'default'} = [1];
183 # To have project specific config enable override in $GITWEB_CONFIG
184 # $feature{'blame'}{'override'} = 1;
185 # and in project config gitweb.blame = 0|1;
187 'sub' => \
&feature_blame
,
191 # Enable the 'snapshot' link, providing a compressed archive of any
192 # tree. This can potentially generate high traffic if you have large
195 # Value is a list of formats defined in %known_snapshot_formats that
197 # To disable system wide have in $GITWEB_CONFIG
198 # $feature{'snapshot'}{'default'} = [];
199 # To have project specific config enable override in $GITWEB_CONFIG
200 # $feature{'snapshot'}{'override'} = 1;
201 # and in project config, a comma-separated list of formats or "none"
202 # to disable. Example: gitweb.snapshot = tbz2,zip;
204 'sub' => \
&feature_snapshot
,
206 'default' => ['tgz']},
208 # Enable text search, which will list the commits which match author,
209 # committer or commit text to a given string. Enabled by default.
210 # Project specific override is not supported.
215 # Enable grep search, which will list the files in currently selected
216 # tree containing the given string. Enabled by default. This can be
217 # potentially CPU-intensive, of course.
219 # To enable system wide have in $GITWEB_CONFIG
220 # $feature{'grep'}{'default'} = [1];
221 # To have project specific config enable override in $GITWEB_CONFIG
222 # $feature{'grep'}{'override'} = 1;
223 # and in project config gitweb.grep = 0|1;
228 # Enable the pickaxe search, which will list the commits that modified
229 # a given string in a file. This can be practical and quite faster
230 # alternative to 'blame', but still potentially CPU-intensive.
232 # To enable system wide have in $GITWEB_CONFIG
233 # $feature{'pickaxe'}{'default'} = [1];
234 # To have project specific config enable override in $GITWEB_CONFIG
235 # $feature{'pickaxe'}{'override'} = 1;
236 # and in project config gitweb.pickaxe = 0|1;
238 'sub' => \
&feature_pickaxe
,
242 # Make gitweb use an alternative format of the URLs which can be
243 # more readable and natural-looking: project name is embedded
244 # directly in the path and the query string contains other
245 # auxiliary information. All gitweb installations recognize
246 # URL in either format; this configures in which formats gitweb
249 # To enable system wide have in $GITWEB_CONFIG
250 # $feature{'pathinfo'}{'default'} = [1];
251 # Project specific override is not supported.
253 # Note that you will need to change the default location of CSS,
254 # favicon, logo and possibly other files to an absolute URL. Also,
255 # if gitweb.cgi serves as your indexfile, you will need to force
256 # $my_uri to contain the script name in your $GITWEB_CONFIG.
261 # Make gitweb consider projects in project root subdirectories
262 # to be forks of existing projects. Given project $projname.git,
263 # projects matching $projname/*.git will not be shown in the main
264 # projects list, instead a '+' mark will be added to $projname
265 # there and a 'forks' view will be enabled for the project, listing
266 # all the forks. If project list is taken from a file, forks have
267 # to be listed after the main project.
269 # To enable system wide have in $GITWEB_CONFIG
270 # $feature{'forks'}{'default'} = [1];
271 # Project specific override is not supported.
277 sub gitweb_check_feature
{
279 return unless exists $feature{$name};
280 my ($sub, $override, @defaults) = (
281 $feature{$name}{'sub'},
282 $feature{$name}{'override'},
283 @{$feature{$name}{'default'}});
284 if (!$override) { return @defaults; }
286 warn "feature $name is not overrideable";
289 return $sub->(@defaults);
293 my ($val) = git_get_project_config
('blame', '--bool');
295 if ($val eq 'true') {
297 } elsif ($val eq 'false') {
304 sub feature_snapshot
{
307 my ($val) = git_get_project_config
('snapshot');
310 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
317 my ($val) = git_get_project_config
('grep', '--bool');
319 if ($val eq 'true') {
321 } elsif ($val eq 'false') {
328 sub feature_pickaxe
{
329 my ($val) = git_get_project_config
('pickaxe', '--bool');
331 if ($val eq 'true') {
333 } elsif ($val eq 'false') {
340 # checking HEAD file with -e is fragile if the repository was
341 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
343 sub check_head_link
{
345 my $headfile = "$dir/HEAD";
346 return ((-e
$headfile) ||
347 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
350 sub check_export_ok
{
352 return (check_head_link
($dir) &&
353 (!$export_ok || -e
"$dir/$export_ok"));
356 # process alternate names for backward compatibility
357 # filter out unsupported (unknown) snapshot formats
358 sub filter_snapshot_fmts
{
362 exists $known_snapshot_format_aliases{$_} ?
363 $known_snapshot_format_aliases{$_} : $_} @fmts;
364 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
368 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
369 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
371 # version of the core git binary
372 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
374 $projects_list ||= $projectroot;
376 # ======================================================================
377 # input validation and dispatch
378 our $action = $cgi->param('a');
379 if (defined $action) {
380 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
381 die_error
(undef, "Invalid action parameter");
385 # parameters which are pathnames
386 our $project = $cgi->param('p');
387 if (defined $project) {
388 if (!validate_pathname
($project) ||
389 !(-d
"$projectroot/$project") ||
390 !check_head_link
("$projectroot/$project") ||
391 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
392 ($strict_export && !project_in_list
($project))) {
394 die_error
(undef, "No such project");
398 our $file_name = $cgi->param('f');
399 if (defined $file_name) {
400 if (!validate_pathname
($file_name)) {
401 die_error
(undef, "Invalid file parameter");
405 our $file_parent = $cgi->param('fp');
406 if (defined $file_parent) {
407 if (!validate_pathname
($file_parent)) {
408 die_error
(undef, "Invalid file parent parameter");
412 # parameters which are refnames
413 our $hash = $cgi->param('h');
415 if (!validate_refname
($hash)) {
416 die_error
(undef, "Invalid hash parameter");
420 our $hash_parent = $cgi->param('hp');
421 if (defined $hash_parent) {
422 if (!validate_refname
($hash_parent)) {
423 die_error
(undef, "Invalid hash parent parameter");
427 our $hash_base = $cgi->param('hb');
428 if (defined $hash_base) {
429 if (!validate_refname
($hash_base)) {
430 die_error
(undef, "Invalid hash base parameter");
434 my %allowed_options = (
435 "--no-merges" => [ qw(rss atom log shortlog history) ],
438 our @extra_options = $cgi->param('opt');
439 if (defined @extra_options) {
440 foreach my $opt (@extra_options) {
441 if (not exists $allowed_options{$opt}) {
442 die_error
(undef, "Invalid option parameter");
444 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
445 die_error
(undef, "Invalid option parameter for this action");
450 our $hash_parent_base = $cgi->param('hpb');
451 if (defined $hash_parent_base) {
452 if (!validate_refname
($hash_parent_base)) {
453 die_error
(undef, "Invalid hash parent base parameter");
458 our $page = $cgi->param('pg');
460 if ($page =~ m/[^0-9]/) {
461 die_error
(undef, "Invalid page parameter");
465 our $searchtype = $cgi->param('st');
466 if (defined $searchtype) {
467 if ($searchtype =~ m/[^a-z]/) {
468 die_error
(undef, "Invalid searchtype parameter");
472 our $searchtext = $cgi->param('s');
474 if (defined $searchtext) {
475 if (length($searchtext) < 2) {
476 die_error
(undef, "At least two characters are required for search parameter");
478 $search_regexp = quotemeta $searchtext;
481 # now read PATH_INFO and use it as alternative to parameters
482 sub evaluate_path_info
{
483 return if defined $project;
484 my $path_info = $ENV{"PATH_INFO"};
485 return if !$path_info;
486 $path_info =~ s
,^/+,,;
487 return if !$path_info;
488 # find which part of PATH_INFO is project
489 $project = $path_info;
491 while ($project && !check_head_link
("$projectroot/$project")) {
492 $project =~ s
,/*[^/]*$,,;
495 $project = validate_pathname
($project);
497 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
498 ($strict_export && !project_in_list
($project))) {
502 # do not change any parameters if an action is given using the query string
504 $path_info =~ s
,^$project/*,,;
505 my ($refname, $pathname) = split(/:/, $path_info, 2);
506 if (defined $pathname) {
507 # we got "project.git/branch:filename" or "project.git/branch:dir/"
508 # we could use git_get_type(branch:pathname), but it needs $git_dir
509 $pathname =~ s
,^/+,,;
510 if (!$pathname || substr($pathname, -1) eq "/") {
514 $action ||= "blob_plain";
516 $hash_base ||= validate_refname
($refname);
517 $file_name ||= validate_pathname
($pathname);
518 } elsif (defined $refname) {
519 # we got "project.git/branch"
520 $action ||= "shortlog";
521 $hash ||= validate_refname
($refname);
524 evaluate_path_info
();
526 # path to the current git repository
528 $git_dir = "$projectroot/$project" if $project;
532 "blame" => \
&git_blame2
,
533 "blobdiff" => \
&git_blobdiff
,
534 "blobdiff_plain" => \
&git_blobdiff_plain
,
535 "blob" => \
&git_blob
,
536 "blob_plain" => \
&git_blob_plain
,
537 "commitdiff" => \
&git_commitdiff
,
538 "commitdiff_plain" => \
&git_commitdiff_plain
,
539 "commit" => \
&git_commit
,
540 "forks" => \
&git_forks
,
541 "heads" => \
&git_heads
,
542 "history" => \
&git_history
,
545 "atom" => \
&git_atom
,
546 "search" => \
&git_search
,
547 "search_help" => \
&git_search_help
,
548 "shortlog" => \
&git_shortlog
,
549 "summary" => \
&git_summary
,
551 "tags" => \
&git_tags
,
552 "tree" => \
&git_tree
,
553 "snapshot" => \
&git_snapshot
,
554 "object" => \
&git_object
,
555 # those below don't need $project
556 "opml" => \
&git_opml
,
557 "project_list" => \
&git_project_list
,
558 "project_index" => \
&git_project_index
,
561 if (!defined $action) {
563 $action = git_get_type
($hash);
564 } elsif (defined $hash_base && defined $file_name) {
565 $action = git_get_type
("$hash_base:$file_name");
566 } elsif (defined $project) {
569 $action = 'project_list';
572 if (!defined($actions{$action})) {
573 die_error
(undef, "Unknown action");
575 if ($action !~ m/^(opml|project_list|project_index)$/ &&
577 die_error
(undef, "Project needed");
579 $actions{$action}->();
582 ## ======================================================================
587 # default is to use -absolute url() i.e. $my_uri
588 my $href = $params{-full
} ? $my_url : $my_uri;
590 # XXX: Warning: If you touch this, check the search form for updating,
601 hash_parent_base
=> "hpb",
606 snapshot_format
=> "sf",
607 extra_options
=> "opt",
609 my %mapping = @mapping;
611 $params{'project'} = $project unless exists $params{'project'};
613 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
615 # use PATH_INFO for project name
616 $href .= "/$params{'project'}" if defined $params{'project'};
617 delete $params{'project'};
619 # Summary just uses the project path URL
620 if (defined $params{'action'} && $params{'action'} eq 'summary') {
621 delete $params{'action'};
625 # now encode the parameters explicitly
627 for (my $i = 0; $i < @mapping; $i += 2) {
628 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
629 if (defined $params{$name}) {
630 if (ref($params{$name}) eq "ARRAY") {
631 foreach my $par (@{$params{$name}}) {
632 push @result, $symbol . "=" . esc_param
($par);
635 push @result, $symbol . "=" . esc_param
($params{$name});
639 $href .= "?" . join(';', @result) if scalar @result;
645 ## ======================================================================
646 ## validation, quoting/unquoting and escaping
648 sub validate_pathname
{
649 my $input = shift || return undef;
651 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
652 # at the beginning, at the end, and between slashes.
653 # also this catches doubled slashes
654 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
658 if ($input =~ m!\0!) {
664 sub validate_refname
{
665 my $input = shift || return undef;
667 # textual hashes are O.K.
668 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
671 # it must be correct pathname
672 $input = validate_pathname
($input)
674 # restrictions on ref name according to git-check-ref-format
675 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
681 # decode sequences of octets in utf8 into Perl's internal form,
682 # which is utf-8 with utf8 flag set if needed. gitweb writes out
683 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
687 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
691 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
695 # quote unsafe chars, but keep the slash, even when it's not
696 # correct, but quoted slashes look too horrible in bookmarks
699 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
705 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
708 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
714 # replace invalid utf8 character with SUBSTITUTION sequence
719 $str = to_utf8
($str);
720 $str = $cgi->escapeHTML($str);
721 if ($opts{'-nbsp'}) {
722 $str =~ s/ / /g;
724 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
728 # quote control characters and escape filename to HTML
733 $str = to_utf8
($str);
734 $str = $cgi->escapeHTML($str);
735 if ($opts{'-nbsp'}) {
736 $str =~ s/ / /g;
738 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
742 # Make control characters "printable", using character escape codes (CEC)
745 my %es = ( # character escape codes, aka escape sequences
746 "\t" => '\t', # tab (HT)
747 "\n" => '\n', # line feed (LF)
748 "\r" => '\r', # carrige return (CR)
749 "\f" => '\f', # form feed (FF)
750 "\b" => '\b', # backspace (BS)
751 "\a" => '\a', # alarm (bell) (BEL)
752 "\e" => '\e', # escape (ESC)
753 "\013" => '\v', # vertical tab (VT)
754 "\000" => '\0', # nul character (NUL)
756 my $chr = ( (exists $es{$cntrl})
758 : sprintf('\%03o', ord($cntrl)) );
759 return "<span class=\"cntrl\">$chr</span>";
762 # Alternatively use unicode control pictures codepoints,
763 # Unicode "printable representation" (PR)
766 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
767 return "<span class=\"cntrl\">$chr</span>";
770 # git may return quoted and escaped filenames
776 my %es = ( # character escape codes, aka escape sequences
777 't' => "\t", # tab (HT, TAB)
778 'n' => "\n", # newline (NL)
779 'r' => "\r", # return (CR)
780 'f' => "\f", # form feed (FF)
781 'b' => "\b", # backspace (BS)
782 'a' => "\a", # alarm (bell) (BEL)
783 'e' => "\e", # escape (ESC)
784 'v' => "\013", # vertical tab (VT)
787 if ($seq =~ m/^[0-7]{1,3}$/) {
788 # octal char sequence
789 return chr(oct($seq));
790 } elsif (exists $es{$seq}) {
791 # C escape sequence, aka character escape code
794 # quoted ordinary character
798 if ($str =~ m/^"(.*)"$/) {
801 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
806 # escape tabs (convert tabs to spaces)
810 while ((my $pos = index($line, "\t")) != -1) {
811 if (my $count = (8 - ($pos % 8))) {
812 my $spaces = ' ' x
$count;
813 $line =~ s/\t/$spaces/;
820 sub project_in_list
{
822 my @list = git_get_projects_list
();
823 return @list && scalar(grep { $_->{'path'} eq $project } @list);
826 ## ----------------------------------------------------------------------
827 ## HTML aware string manipulation
832 my $add_len = shift || 10;
834 # allow only $len chars, but don't cut a word if it would fit in $add_len
835 # if it doesn't fit, cut it if it's still longer than the dots we would add
836 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
839 if (length($tail) > 4) {
841 $body =~ s/&[^;]*$//; # remove chopped character entities
846 ## ----------------------------------------------------------------------
847 ## functions returning short strings
849 # CSS class for given age value (in seconds)
855 } elsif ($age < 60*60*2) {
857 } elsif ($age < 60*60*24*2) {
864 # convert age in seconds to "nn units ago" string
869 if ($age > 60*60*24*365*2) {
870 $age_str = (int $age/60/60/24/365);
871 $age_str .= " years ago";
872 } elsif ($age > 60*60*24*(365/12)*2) {
873 $age_str = int $age/60/60/24/(365/12);
874 $age_str .= " months ago";
875 } elsif ($age > 60*60*24*7*2) {
876 $age_str = int $age/60/60/24/7;
877 $age_str .= " weeks ago";
878 } elsif ($age > 60*60*24*2) {
879 $age_str = int $age/60/60/24;
880 $age_str .= " days ago";
881 } elsif ($age > 60*60*2) {
882 $age_str = int $age/60/60;
883 $age_str .= " hours ago";
884 } elsif ($age > 60*2) {
885 $age_str = int $age/60;
886 $age_str .= " min ago";
889 $age_str .= " sec ago";
891 $age_str .= " right now";
897 S_IFINVALID
=> 0030000,
898 S_IFGITLINK
=> 0160000,
901 # submodule/subproject, a commit object reference
905 return (($mode & S_IFMT
) == S_IFGITLINK
)
908 # convert file mode in octal to symbolic file mode string
910 my $mode = oct shift;
912 if (S_ISGITLINK
($mode)) {
914 } elsif (S_ISDIR
($mode & S_IFMT
)) {
916 } elsif (S_ISLNK
($mode)) {
918 } elsif (S_ISREG
($mode)) {
919 # git cares only about the executable bit
920 if ($mode & S_IXUSR
) {
930 # convert file mode in octal to file type string
934 if ($mode !~ m/^[0-7]+$/) {
940 if (S_ISGITLINK
($mode)) {
942 } elsif (S_ISDIR
($mode & S_IFMT
)) {
944 } elsif (S_ISLNK
($mode)) {
946 } elsif (S_ISREG
($mode)) {
953 # convert file mode in octal to file type description string
957 if ($mode !~ m/^[0-7]+$/) {
963 if (S_ISGITLINK
($mode)) {
965 } elsif (S_ISDIR
($mode & S_IFMT
)) {
967 } elsif (S_ISLNK
($mode)) {
969 } elsif (S_ISREG
($mode)) {
970 if ($mode & S_IXUSR
) {
981 ## ----------------------------------------------------------------------
982 ## functions returning short HTML fragments, or transforming HTML fragments
983 ## which don't belong to other sections
985 # format line of commit message.
986 sub format_log_line_html
{
989 $line = esc_html
($line, -nbsp
=>1);
990 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
993 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
994 -class => "text"}, $hash_text);
995 $line =~ s/$hash_text/$link/;
1000 # format marker of refs pointing to given object
1001 sub format_ref_marker
{
1002 my ($refs, $id) = @_;
1005 if (defined $refs->{$id}) {
1006 foreach my $ref (@{$refs->{$id}}) {
1007 my ($type, $name) = qw();
1008 # e.g. tags/v2.6.11 or heads/next
1009 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1017 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1018 esc_html
($name) . "</span>";
1023 return ' <span class="refs">'. $markers . '</span>';
1029 # format, perhaps shortened and with markers, title line
1030 sub format_subject_html
{
1031 my ($long, $short, $href, $extra) = @_;
1032 $extra = '' unless defined($extra);
1034 if (length($short) < length($long)) {
1035 return $cgi->a({-href
=> $href, -class => "list subject",
1036 -title
=> to_utf8
($long)},
1037 esc_html
($short) . $extra);
1039 return $cgi->a({-href
=> $href, -class => "list subject"},
1040 esc_html
($long) . $extra);
1044 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1045 sub format_git_diff_header_line
{
1047 my $diffinfo = shift;
1048 my ($from, $to) = @_;
1050 if ($diffinfo->{'nparents'}) {
1052 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1053 if ($to->{'href'}) {
1054 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1055 esc_path
($to->{'file'}));
1056 } else { # file was deleted (no href)
1057 $line .= esc_path
($to->{'file'});
1061 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1062 if ($from->{'href'}) {
1063 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1064 'a/' . esc_path
($from->{'file'}));
1065 } else { # file was added (no href)
1066 $line .= 'a/' . esc_path
($from->{'file'});
1069 if ($to->{'href'}) {
1070 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1071 'b/' . esc_path
($to->{'file'}));
1072 } else { # file was deleted
1073 $line .= 'b/' . esc_path
($to->{'file'});
1077 return "<div class=\"diff header\">$line</div>\n";
1080 # format extended diff header line, before patch itself
1081 sub format_extended_diff_header_line
{
1083 my $diffinfo = shift;
1084 my ($from, $to) = @_;
1087 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1088 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1089 esc_path
($from->{'file'}));
1091 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1092 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1093 esc_path
($to->{'file'}));
1095 # match single <mode>
1096 if ($line =~ m/\s(\d{6})$/) {
1097 $line .= '<span class="info"> (' .
1098 file_type_long
($1) .
1102 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1103 # can match only for combined diff
1105 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1106 if ($from->{'href'}[$i]) {
1107 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1109 substr($diffinfo->{'from_id'}[$i],0,7));
1114 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1117 if ($to->{'href'}) {
1118 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1119 substr($diffinfo->{'to_id'},0,7));
1124 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1125 # can match only for ordinary diff
1126 my ($from_link, $to_link);
1127 if ($from->{'href'}) {
1128 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1129 substr($diffinfo->{'from_id'},0,7));
1131 $from_link = '0' x
7;
1133 if ($to->{'href'}) {
1134 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1135 substr($diffinfo->{'to_id'},0,7));
1139 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1140 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1143 return $line . "<br/>\n";
1146 # format from-file/to-file diff header
1147 sub format_diff_from_to_header
{
1148 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1153 #assert($line =~ m/^---/) if DEBUG;
1154 # no extra formatting for "^--- /dev/null"
1155 if (! $diffinfo->{'nparents'}) {
1156 # ordinary (single parent) diff
1157 if ($line =~ m!^--- "?a/!) {
1158 if ($from->{'href'}) {
1160 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1161 esc_path
($from->{'file'}));
1164 esc_path
($from->{'file'});
1167 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1170 # combined diff (merge commit)
1171 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1172 if ($from->{'href'}[$i]) {
1174 $cgi->a({-href
=>href
(action
=>"blobdiff",
1175 hash_parent
=>$diffinfo->{'from_id'}[$i],
1176 hash_parent_base
=>$parents[$i],
1177 file_parent
=>$from->{'file'}[$i],
1178 hash
=>$diffinfo->{'to_id'},
1180 file_name
=>$to->{'file'}),
1182 -title
=>"diff" . ($i+1)},
1185 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1186 esc_path
($from->{'file'}[$i]));
1188 $line = '--- /dev/null';
1190 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1195 #assert($line =~ m/^\+\+\+/) if DEBUG;
1196 # no extra formatting for "^+++ /dev/null"
1197 if ($line =~ m!^\+\+\+ "?b/!) {
1198 if ($to->{'href'}) {
1200 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1201 esc_path
($to->{'file'}));
1204 esc_path
($to->{'file'});
1207 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1212 # create note for patch simplified by combined diff
1213 sub format_diff_cc_simplified
{
1214 my ($diffinfo, @parents) = @_;
1217 $result .= "<div class=\"diff header\">" .
1219 if (!is_deleted
($diffinfo)) {
1220 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1222 hash
=>$diffinfo->{'to_id'},
1223 file_name
=>$diffinfo->{'to_file'}),
1225 esc_path
($diffinfo->{'to_file'}));
1227 $result .= esc_path
($diffinfo->{'to_file'});
1229 $result .= "</div>\n" . # class="diff header"
1230 "<div class=\"diff nodifferences\">" .
1232 "</div>\n"; # class="diff nodifferences"
1237 # format patch (diff) line (not to be used for diff headers)
1238 sub format_diff_line
{
1240 my ($from, $to) = @_;
1241 my $diff_class = "";
1245 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1247 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1248 if ($line =~ m/^\@{3}/) {
1249 $diff_class = " chunk_header";
1250 } elsif ($line =~ m/^\\/) {
1251 $diff_class = " incomplete";
1252 } elsif ($prefix =~ tr/+/+/) {
1253 $diff_class = " add";
1254 } elsif ($prefix =~ tr/-/-/) {
1255 $diff_class = " rem";
1258 # assume ordinary diff
1259 my $char = substr($line, 0, 1);
1261 $diff_class = " add";
1262 } elsif ($char eq '-') {
1263 $diff_class = " rem";
1264 } elsif ($char eq '@') {
1265 $diff_class = " chunk_header";
1266 } elsif ($char eq "\\") {
1267 $diff_class = " incomplete";
1270 $line = untabify
($line);
1271 if ($from && $to && $line =~ m/^\@{2} /) {
1272 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1273 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1275 $from_lines = 0 unless defined $from_lines;
1276 $to_lines = 0 unless defined $to_lines;
1278 if ($from->{'href'}) {
1279 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1280 -class=>"list"}, $from_text);
1282 if ($to->{'href'}) {
1283 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1284 -class=>"list"}, $to_text);
1286 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1287 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1288 return "<div class=\"diff$diff_class\">$line</div>\n";
1289 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1290 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1291 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1293 @from_text = split(' ', $ranges);
1294 for (my $i = 0; $i < @from_text; ++$i) {
1295 ($from_start[$i], $from_nlines[$i]) =
1296 (split(',', substr($from_text[$i], 1)), 0);
1299 $to_text = pop @from_text;
1300 $to_start = pop @from_start;
1301 $to_nlines = pop @from_nlines;
1303 $line = "<span class=\"chunk_info\">$prefix ";
1304 for (my $i = 0; $i < @from_text; ++$i) {
1305 if ($from->{'href'}[$i]) {
1306 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1307 -class=>"list"}, $from_text[$i]);
1309 $line .= $from_text[$i];
1313 if ($to->{'href'}) {
1314 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1315 -class=>"list"}, $to_text);
1319 $line .= " $prefix</span>" .
1320 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1321 return "<div class=\"diff$diff_class\">$line</div>\n";
1323 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1326 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1327 # linked. Pass the hash of the tree/commit to snapshot.
1328 sub format_snapshot_links
{
1330 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1331 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1332 my $num_fmts = @snapshot_fmts;
1333 if ($num_fmts > 1) {
1334 # A parenthesized list of links bearing format names.
1335 # e.g. "snapshot (_tar.gz_ _zip_)"
1336 return "snapshot (" . join(' ', map
1343 }, $known_snapshot_formats{$_}{'display'})
1344 , @snapshot_fmts) . ")";
1345 } elsif ($num_fmts == 1) {
1346 # A single "snapshot" link whose tooltip bears the format name.
1348 my ($fmt) = @snapshot_fmts;
1354 snapshot_format
=>$fmt
1356 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1358 } else { # $num_fmts == 0
1363 ## ----------------------------------------------------------------------
1364 ## git utility subroutines, invoking git commands
1366 # returns path to the core git executable and the --git-dir parameter as list
1368 return $GIT, '--git-dir='.$git_dir;
1371 # returns path to the core git executable and the --git-dir parameter as string
1373 return join(' ', git_cmd
());
1376 # get HEAD ref of given project as hash
1377 sub git_get_head_hash
{
1378 my $project = shift;
1379 my $o_git_dir = $git_dir;
1381 $git_dir = "$projectroot/$project";
1382 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1385 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1389 if (defined $o_git_dir) {
1390 $git_dir = $o_git_dir;
1395 # get type of given object
1399 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1401 close $fd or return;
1406 sub git_get_project_config
{
1407 my ($key, $type) = @_;
1409 return unless ($key);
1410 $key =~ s/^gitweb\.//;
1411 return if ($key =~ m/\W/);
1413 my @x = (git_cmd
(), 'config');
1414 if (defined $type) { push @x, $type; }
1416 push @x, "gitweb.$key";
1422 # get hash of given path at given ref
1423 sub git_get_hash_by_path
{
1425 my $path = shift || return undef;
1430 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1431 or die_error
(undef, "Open git-ls-tree failed");
1433 close $fd or return undef;
1435 if (!defined $line) {
1436 # there is no tree or hash given by $path at $base
1440 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1441 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1442 if (defined $type && $type ne $2) {
1443 # type doesn't match
1449 # get path of entry with given hash at given tree-ish (ref)
1450 # used to get 'from' filename for combined diff (merge commit) for renames
1451 sub git_get_path_by_hash
{
1452 my $base = shift || return;
1453 my $hash = shift || return;
1457 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1459 while (my $line = <$fd>) {
1462 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1463 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1464 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1473 ## ......................................................................
1474 ## git utility functions, directly accessing git repository
1476 sub git_get_project_description
{
1479 open my $fd, "$projectroot/$path/description" or return undef;
1482 if (defined $descr) {
1488 sub git_get_project_url_list
{
1491 open my $fd, "$projectroot/$path/cloneurl" or return;
1492 my @git_project_url_list = map { chomp; $_ } <$fd>;
1495 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1498 sub git_get_projects_list
{
1503 $filter =~ s/\.git$//;
1505 my ($check_forks) = gitweb_check_feature
('forks');
1507 if (-d
$projects_list) {
1508 # search in directory
1509 my $dir = $projects_list . ($filter ? "/$filter" : '');
1510 # remove the trailing "/"
1512 my $pfxlen = length("$dir");
1515 follow_fast
=> 1, # follow symbolic links
1516 follow_skip
=> 2, # ignore duplicates
1517 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1519 # skip project-list toplevel, if we get it.
1520 return if (m!^[/.]$!);
1521 # only directories can be git repositories
1522 return unless (-d
$_);
1524 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1525 # we check related file in $projectroot
1526 if ($check_forks and $subdir =~ m
#/.#) {
1527 $File::Find
::prune
= 1;
1528 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1529 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1530 $File::Find
::prune
= 1;
1535 } elsif (-f
$projects_list) {
1536 # read from file(url-encoded):
1537 # 'git%2Fgit.git Linus+Torvalds'
1538 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1539 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1541 open my ($fd), $projects_list or return;
1543 while (my $line = <$fd>) {
1545 my ($path, $owner) = split ' ', $line;
1546 $path = unescape
($path);
1547 $owner = unescape
($owner);
1548 if (!defined $path) {
1551 if ($filter ne '') {
1552 # looking for forks;
1553 my $pfx = substr($path, 0, length($filter));
1554 if ($pfx ne $filter) {
1557 my $sfx = substr($path, length($filter));
1558 if ($sfx !~ /^\/.*\
.git
$/) {
1561 } elsif ($check_forks) {
1563 foreach my $filter (keys %paths) {
1564 # looking for forks;
1565 my $pfx = substr($path, 0, length($filter));
1566 if ($pfx ne $filter) {
1569 my $sfx = substr($path, length($filter));
1570 if ($sfx !~ /^\/.*\
.git
$/) {
1573 # is a fork, don't include it in
1578 if (check_export_ok
("$projectroot/$path")) {
1581 owner
=> to_utf8
($owner),
1584 (my $forks_path = $path) =~ s/\.git$//;
1585 $paths{$forks_path}++;
1593 our $gitweb_project_owner = undef;
1594 sub git_get_project_list_from_file
{
1596 return if (defined $gitweb_project_owner);
1598 $gitweb_project_owner = {};
1599 # read from file (url-encoded):
1600 # 'git%2Fgit.git Linus+Torvalds'
1601 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1602 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1603 if (-f
$projects_list) {
1604 open (my $fd , $projects_list);
1605 while (my $line = <$fd>) {
1607 my ($pr, $ow) = split ' ', $line;
1608 $pr = unescape
($pr);
1609 $ow = unescape
($ow);
1610 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1616 sub git_get_project_owner
{
1617 my $project = shift;
1620 return undef unless $project;
1622 if (!defined $gitweb_project_owner) {
1623 git_get_project_list_from_file
();
1626 if (exists $gitweb_project_owner->{$project}) {
1627 $owner = $gitweb_project_owner->{$project};
1629 if (!defined $owner) {
1630 $owner = get_file_owner
("$projectroot/$project");
1636 sub git_get_last_activity
{
1640 $git_dir = "$projectroot/$path";
1641 open($fd, "-|", git_cmd
(), 'for-each-ref',
1642 '--format=%(committer)',
1643 '--sort=-committerdate',
1645 'refs/heads') or return;
1646 my $most_recent = <$fd>;
1647 close $fd or return;
1648 if (defined $most_recent &&
1649 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1651 my $age = time - $timestamp;
1652 return ($age, age_string
($age));
1654 return (undef, undef);
1657 sub git_get_references
{
1658 my $type = shift || "";
1660 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1661 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1662 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1663 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1666 while (my $line = <$fd>) {
1668 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1669 if (defined $refs{$1}) {
1670 push @{$refs{$1}}, $2;
1676 close $fd or return;
1680 sub git_get_rev_name_tags
{
1681 my $hash = shift || return undef;
1683 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1685 my $name_rev = <$fd>;
1688 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1691 # catches also '$hash undefined' output
1696 ## ----------------------------------------------------------------------
1697 ## parse to hash functions
1701 my $tz = shift || "-0000";
1704 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1705 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1706 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1707 $date{'hour'} = $hour;
1708 $date{'minute'} = $min;
1709 $date{'mday'} = $mday;
1710 $date{'day'} = $days[$wday];
1711 $date{'month'} = $months[$mon];
1712 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1713 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1714 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1715 $mday, $months[$mon], $hour ,$min;
1716 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1717 1900+$year, $mon, $mday, $hour ,$min, $sec;
1719 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1720 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1721 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1722 $date{'hour_local'} = $hour;
1723 $date{'minute_local'} = $min;
1724 $date{'tz_local'} = $tz;
1725 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1726 1900+$year, $mon+1, $mday,
1727 $hour, $min, $sec, $tz);
1736 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1737 $tag{'id'} = $tag_id;
1738 while (my $line = <$fd>) {
1740 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1741 $tag{'object'} = $1;
1742 } elsif ($line =~ m/^type (.+)$/) {
1744 } elsif ($line =~ m/^tag (.+)$/) {
1746 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1747 $tag{'author'} = $1;
1750 } elsif ($line =~ m/--BEGIN/) {
1751 push @comment, $line;
1753 } elsif ($line eq "") {
1757 push @comment, <$fd>;
1758 $tag{'comment'} = \
@comment;
1759 close $fd or return;
1760 if (!defined $tag{'name'}) {
1766 sub parse_commit_text
{
1767 my ($commit_text, $withparents) = @_;
1768 my @commit_lines = split '\n', $commit_text;
1771 pop @commit_lines; # Remove '\0'
1773 if (! @commit_lines) {
1777 my $header = shift @commit_lines;
1778 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1781 ($co{'id'}, my @parents) = split ' ', $header;
1782 while (my $line = shift @commit_lines) {
1783 last if $line eq "\n";
1784 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1786 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1788 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1790 $co{'author_epoch'} = $2;
1791 $co{'author_tz'} = $3;
1792 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1793 $co{'author_name'} = $1;
1794 $co{'author_email'} = $2;
1796 $co{'author_name'} = $co{'author'};
1798 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1799 $co{'committer'} = $1;
1800 $co{'committer_epoch'} = $2;
1801 $co{'committer_tz'} = $3;
1802 $co{'committer_name'} = $co{'committer'};
1803 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1804 $co{'committer_name'} = $1;
1805 $co{'committer_email'} = $2;
1807 $co{'committer_name'} = $co{'committer'};
1811 if (!defined $co{'tree'}) {
1814 $co{'parents'} = \
@parents;
1815 $co{'parent'} = $parents[0];
1817 foreach my $title (@commit_lines) {
1820 $co{'title'} = chop_str
($title, 80, 5);
1821 # remove leading stuff of merges to make the interesting part visible
1822 if (length($title) > 50) {
1823 $title =~ s/^Automatic //;
1824 $title =~ s/^merge (of|with) /Merge ... /i;
1825 if (length($title) > 50) {
1826 $title =~ s/(http|rsync):\/\///;
1828 if (length($title) > 50) {
1829 $title =~ s/(master|www|rsync)\.//;
1831 if (length($title) > 50) {
1832 $title =~ s/kernel.org:?//;
1834 if (length($title) > 50) {
1835 $title =~ s/\/pub\/scm//;
1838 $co{'title_short'} = chop_str
($title, 50, 5);
1842 if ($co{'title'} eq "") {
1843 $co{'title'} = $co{'title_short'} = '(no commit message)';
1845 # remove added spaces
1846 foreach my $line (@commit_lines) {
1849 $co{'comment'} = \
@commit_lines;
1851 my $age = time - $co{'committer_epoch'};
1853 $co{'age_string'} = age_string
($age);
1854 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1855 if ($age > 60*60*24*7*2) {
1856 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1857 $co{'age_string_age'} = $co{'age_string'};
1859 $co{'age_string_date'} = $co{'age_string'};
1860 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1866 my ($commit_id) = @_;
1871 open my $fd, "-|", git_cmd
(), "rev-list",
1877 or die_error
(undef, "Open git-rev-list failed");
1878 %co = parse_commit_text
(<$fd>, 1);
1885 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1893 open my $fd, "-|", git_cmd
(), "rev-list",
1895 ($arg ? ($arg) : ()),
1896 ("--max-count=" . $maxcount),
1897 ("--skip=" . $skip),
1901 ($filename ? ($filename) : ())
1902 or die_error
(undef, "Open git-rev-list failed");
1903 while (my $line = <$fd>) {
1904 my %co = parse_commit_text
($line);
1909 return wantarray ? @cos : \
@cos;
1912 # parse ref from ref_file, given by ref_id, with given type
1914 my $ref_file = shift;
1916 my $type = shift || git_get_type
($ref_id);
1919 $ref_item{'type'} = $type;
1920 $ref_item{'id'} = $ref_id;
1921 $ref_item{'epoch'} = 0;
1922 $ref_item{'age'} = "unknown";
1923 if ($type eq "tag") {
1924 my %tag = parse_tag
($ref_id);
1925 $ref_item{'comment'} = $tag{'comment'};
1926 if ($tag{'type'} eq "commit") {
1927 my %co = parse_commit
($tag{'object'});
1928 $ref_item{'epoch'} = $co{'committer_epoch'};
1929 $ref_item{'age'} = $co{'age_string'};
1930 } elsif (defined($tag{'epoch'})) {
1931 my $age = time - $tag{'epoch'};
1932 $ref_item{'epoch'} = $tag{'epoch'};
1933 $ref_item{'age'} = age_string
($age);
1935 $ref_item{'reftype'} = $tag{'type'};
1936 $ref_item{'name'} = $tag{'name'};
1937 $ref_item{'refid'} = $tag{'object'};
1938 } elsif ($type eq "commit"){
1939 my %co = parse_commit
($ref_id);
1940 $ref_item{'reftype'} = "commit";
1941 $ref_item{'name'} = $ref_file;
1942 $ref_item{'title'} = $co{'title'};
1943 $ref_item{'refid'} = $ref_id;
1944 $ref_item{'epoch'} = $co{'committer_epoch'};
1945 $ref_item{'age'} = $co{'age_string'};
1947 $ref_item{'reftype'} = $type;
1948 $ref_item{'name'} = $ref_file;
1949 $ref_item{'refid'} = $ref_id;
1955 # parse line of git-diff-tree "raw" output
1956 sub parse_difftree_raw_line
{
1960 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1961 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1962 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1963 $res{'from_mode'} = $1;
1964 $res{'to_mode'} = $2;
1965 $res{'from_id'} = $3;
1967 $res{'status'} = $5;
1968 $res{'similarity'} = $6;
1969 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1970 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1972 $res{'file'} = unquote
($7);
1975 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1976 # combined diff (for merge commit)
1977 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1978 $res{'nparents'} = length($1);
1979 $res{'from_mode'} = [ split(' ', $2) ];
1980 $res{'to_mode'} = pop @{$res{'from_mode'}};
1981 $res{'from_id'} = [ split(' ', $3) ];
1982 $res{'to_id'} = pop @{$res{'from_id'}};
1983 $res{'status'} = [ split('', $4) ];
1984 $res{'to_file'} = unquote
($5);
1986 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1987 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1988 $res{'commit'} = $1;
1991 return wantarray ? %res : \
%res;
1994 # parse line of git-ls-tree output
1995 sub parse_ls_tree_line
($;%) {
2000 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2001 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2009 $res{'name'} = unquote
($4);
2012 return wantarray ? %res : \
%res;
2015 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2016 sub parse_from_to_diffinfo
{
2017 my ($diffinfo, $from, $to, @parents) = @_;
2019 if ($diffinfo->{'nparents'}) {
2021 $from->{'file'} = [];
2022 $from->{'href'} = [];
2023 fill_from_file_info
($diffinfo, @parents)
2024 unless exists $diffinfo->{'from_file'};
2025 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2026 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2027 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2028 $from->{'href'}[$i] = href
(action
=>"blob",
2029 hash_base
=>$parents[$i],
2030 hash
=>$diffinfo->{'from_id'}[$i],
2031 file_name
=>$from->{'file'}[$i]);
2033 $from->{'href'}[$i] = undef;
2037 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2038 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2039 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2040 hash
=>$diffinfo->{'from_id'},
2041 file_name
=>$from->{'file'});
2043 delete $from->{'href'};
2047 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2048 if (!is_deleted
($diffinfo)) { # file exists in result
2049 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2050 hash
=>$diffinfo->{'to_id'},
2051 file_name
=>$to->{'file'});
2053 delete $to->{'href'};
2057 ## ......................................................................
2058 ## parse to array of hashes functions
2060 sub git_get_heads_list
{
2064 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2065 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2066 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2069 while (my $line = <$fd>) {
2073 my ($refinfo, $committerinfo) = split(/\0/, $line);
2074 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2075 my ($committer, $epoch, $tz) =
2076 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2077 $name =~ s!^refs/heads/!!;
2079 $ref_item{'name'} = $name;
2080 $ref_item{'id'} = $hash;
2081 $ref_item{'title'} = $title || '(no commit message)';
2082 $ref_item{'epoch'} = $epoch;
2084 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2086 $ref_item{'age'} = "unknown";
2089 push @headslist, \
%ref_item;
2093 return wantarray ? @headslist : \
@headslist;
2096 sub git_get_tags_list
{
2100 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2101 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2102 '--format=%(objectname) %(objecttype) %(refname) '.
2103 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2106 while (my $line = <$fd>) {
2110 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2111 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2112 my ($creator, $epoch, $tz) =
2113 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2114 $name =~ s!^refs/tags/!!;
2116 $ref_item{'type'} = $type;
2117 $ref_item{'id'} = $id;
2118 $ref_item{'name'} = $name;
2119 if ($type eq "tag") {
2120 $ref_item{'subject'} = $title;
2121 $ref_item{'reftype'} = $reftype;
2122 $ref_item{'refid'} = $refid;
2124 $ref_item{'reftype'} = $type;
2125 $ref_item{'refid'} = $id;
2128 if ($type eq "tag" || $type eq "commit") {
2129 $ref_item{'epoch'} = $epoch;
2131 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2133 $ref_item{'age'} = "unknown";
2137 push @tagslist, \
%ref_item;
2141 return wantarray ? @tagslist : \
@tagslist;
2144 ## ----------------------------------------------------------------------
2145 ## filesystem-related functions
2147 sub get_file_owner
{
2150 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2151 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2152 if (!defined $gcos) {
2156 $owner =~ s/[,;].*$//;
2157 return to_utf8
($owner);
2160 ## ......................................................................
2161 ## mimetype related functions
2163 sub mimetype_guess_file
{
2164 my $filename = shift;
2165 my $mimemap = shift;
2166 -r
$mimemap or return undef;
2169 open(MIME
, $mimemap) or return undef;
2171 next if m/^#/; # skip comments
2172 my ($mime, $exts) = split(/\t+/);
2173 if (defined $exts) {
2174 my @exts = split(/\s+/, $exts);
2175 foreach my $ext (@exts) {
2176 $mimemap{$ext} = $mime;
2182 $filename =~ /\.([^.]*)$/;
2183 return $mimemap{$1};
2186 sub mimetype_guess
{
2187 my $filename = shift;
2189 $filename =~ /\./ or return undef;
2191 if ($mimetypes_file) {
2192 my $file = $mimetypes_file;
2193 if ($file !~ m!^/!) { # if it is relative path
2194 # it is relative to project
2195 $file = "$projectroot/$project/$file";
2197 $mime = mimetype_guess_file
($filename, $file);
2199 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2205 my $filename = shift;
2208 my $mime = mimetype_guess
($filename);
2209 $mime and return $mime;
2213 return $default_blob_plain_mimetype unless $fd;
2216 return 'text/plain' .
2217 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2218 } elsif (! $filename) {
2219 return 'application/octet-stream';
2220 } elsif ($filename =~ m/\.png$/i) {
2222 } elsif ($filename =~ m/\.gif$/i) {
2224 } elsif ($filename =~ m/\.jpe?g$/i) {
2225 return 'image/jpeg';
2227 return 'application/octet-stream';
2231 ## ======================================================================
2232 ## functions printing HTML: header, footer, error page
2234 sub git_header_html
{
2235 my $status = shift || "200 OK";
2236 my $expires = shift;
2238 my $title = "$site_name";
2239 if (defined $project) {
2240 $title .= " - " . to_utf8
($project);
2241 if (defined $action) {
2242 $title .= "/$action";
2243 if (defined $file_name) {
2244 $title .= " - " . esc_path
($file_name);
2245 if ($action eq "tree" && $file_name !~ m
|/$|) {
2252 # require explicit support from the UA if we are to send the page as
2253 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2254 # we have to do this because MSIE sometimes globs '*/*', pretending to
2255 # support xhtml+xml but choking when it gets what it asked for.
2256 if (defined $cgi->http('HTTP_ACCEPT') &&
2257 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2258 $cgi->Accept('application/xhtml+xml') != 0) {
2259 $content_type = 'application/xhtml+xml';
2261 $content_type = 'text/html';
2263 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2264 -status
=> $status, -expires
=> $expires);
2265 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2267 <?xml version="1.0" encoding="utf-8"?>
2268 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2269 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2270 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2271 <!-- git core binaries version $git_version -->
2273 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2274 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2275 <meta name="robots" content="index, nofollow"/>
2276 <title>$title</title>
2278 # print out each stylesheet that exist
2279 if (defined $stylesheet) {
2280 #provides backwards capability for those people who define style sheet in a config file
2281 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2283 foreach my $stylesheet (@stylesheets) {
2284 next unless $stylesheet;
2285 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2288 if (defined $project) {
2289 printf('<link rel="alternate" title="%s log RSS feed" '.
2290 'href="%s" type="application/rss+xml" />'."\n",
2291 esc_param
($project), href
(action
=>"rss"));
2292 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2293 'href="%s" type="application/rss+xml" />'."\n",
2294 esc_param
($project), href
(action
=>"rss",
2295 extra_options
=>"--no-merges"));
2296 printf('<link rel="alternate" title="%s log Atom feed" '.
2297 'href="%s" type="application/atom+xml" />'."\n",
2298 esc_param
($project), href
(action
=>"atom"));
2299 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2300 'href="%s" type="application/atom+xml" />'."\n",
2301 esc_param
($project), href
(action
=>"atom",
2302 extra_options
=>"--no-merges"));
2304 printf('<link rel="alternate" title="%s projects list" '.
2305 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2306 $site_name, href
(project
=>undef, action
=>"project_index"));
2307 printf('<link rel="alternate" title="%s projects feeds" '.
2308 'href="%s" type="text/x-opml"/>'."\n",
2309 $site_name, href
(project
=>undef, action
=>"opml"));
2311 if (defined $favicon) {
2312 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2318 if (-f
$site_header) {
2319 open (my $fd, $site_header);
2324 print "<div class=\"page_header\">\n" .
2325 $cgi->a({-href
=> esc_url
($logo_url),
2326 -title
=> $logo_label},
2327 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2328 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2329 if (defined $project) {
2330 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2331 if (defined $action) {
2338 my ($have_search) = gitweb_check_feature
('search');
2339 if ((defined $project) && ($have_search)) {
2340 if (!defined $searchtext) {
2344 if (defined $hash_base) {
2345 $search_hash = $hash_base;
2346 } elsif (defined $hash) {
2347 $search_hash = $hash;
2349 $search_hash = "HEAD";
2351 my $action = $my_uri;
2352 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2353 if ($use_pathinfo) {
2354 $action .= "/$project";
2356 $cgi->param("p", $project);
2358 $cgi->param("a", "search");
2359 $cgi->param("h", $search_hash);
2360 print $cgi->startform(-method => "get", -action
=> $action) .
2361 "<div class=\"search\">\n" .
2362 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2363 $cgi->hidden(-name
=> "a") . "\n" .
2364 $cgi->hidden(-name
=> "h") . "\n" .
2365 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2366 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2367 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2369 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2371 $cgi->end_form() . "\n";
2375 sub git_footer_html
{
2376 print "<div class=\"page_footer\">\n";
2377 if (defined $project) {
2378 my $descr = git_get_project_description
($project);
2379 if (defined $descr) {
2380 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2382 print $cgi->a({-href
=> href
(action
=>"rss"),
2383 -class => "rss_logo"}, "RSS") . " ";
2384 print $cgi->a({-href
=> href
(action
=>"atom"),
2385 -class => "rss_logo"}, "Atom") . "\n";
2387 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2388 -class => "rss_logo"}, "OPML") . " ";
2389 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2390 -class => "rss_logo"}, "TXT") . "\n";
2394 if (-f
$site_footer) {
2395 open (my $fd, $site_footer);
2405 my $status = shift || "403 Forbidden";
2406 my $error = shift || "Malformed query, file missing or permission denied";
2408 git_header_html
($status);
2410 <div class="page_body">
2420 ## ----------------------------------------------------------------------
2421 ## functions printing or outputting HTML: navigation
2423 sub git_print_page_nav
{
2424 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2425 $extra = '' if !defined $extra; # pager or formats
2427 my @navs = qw(summary shortlog log commit commitdiff tree);
2429 @navs = grep { $_ ne $suppress } @navs;
2432 my %arg = map { $_ => {action
=>$_} } @navs;
2433 if (defined $head) {
2434 for (qw(commit commitdiff)) {
2435 $arg{$_}{'hash'} = $head;
2437 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2438 for (qw(shortlog log)) {
2439 $arg{$_}{'hash'} = $head;
2443 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2444 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2446 print "<div class=\"page_nav\">\n" .
2448 map { $_ eq $current ?
2449 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2451 print "<br/>\n$extra<br/>\n" .
2455 sub format_paging_nav
{
2456 my ($action, $hash, $head, $page, $nrevs) = @_;
2460 if ($hash ne $head || $page) {
2461 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2463 $paging_nav .= "HEAD";
2467 $paging_nav .= " ⋅ " .
2468 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2469 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2471 $paging_nav .= " ⋅ prev";
2474 if ($nrevs >= (100 * ($page+1)-1)) {
2475 $paging_nav .= " ⋅ " .
2476 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2477 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2479 $paging_nav .= " ⋅ next";
2485 ## ......................................................................
2486 ## functions printing or outputting HTML: div
2488 sub git_print_header_div
{
2489 my ($action, $title, $hash, $hash_base) = @_;
2492 $args{'action'} = $action;
2493 $args{'hash'} = $hash if $hash;
2494 $args{'hash_base'} = $hash_base if $hash_base;
2496 print "<div class=\"header\">\n" .
2497 $cgi->a({-href
=> href
(%args), -class => "title"},
2498 $title ? $title : $action) .
2502 #sub git_print_authorship (\%) {
2503 sub git_print_authorship
{
2506 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2507 print "<div class=\"author_date\">" .
2508 esc_html
($co->{'author_name'}) .
2510 if ($ad{'hour_local'} < 6) {
2511 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2512 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2514 printf(" (%02d:%02d %s)",
2515 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2520 sub git_print_page_path
{
2526 print "<div class=\"page_path\">";
2527 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2528 -title
=> 'tree root'}, to_utf8
("[$project]"));
2530 if (defined $name) {
2531 my @dirname = split '/', $name;
2532 my $basename = pop @dirname;
2535 foreach my $dir (@dirname) {
2536 $fullname .= ($fullname ? '/' : '') . $dir;
2537 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2539 -title
=> $fullname}, esc_path
($dir));
2542 if (defined $type && $type eq 'blob') {
2543 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2545 -title
=> $name}, esc_path
($basename));
2546 } elsif (defined $type && $type eq 'tree') {
2547 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2549 -title
=> $name}, esc_path
($basename));
2552 print esc_path
($basename);
2555 print "<br/></div>\n";
2558 # sub git_print_log (\@;%) {
2559 sub git_print_log
($;%) {
2563 if ($opts{'-remove_title'}) {
2564 # remove title, i.e. first line of log
2567 # remove leading empty lines
2568 while (defined $log->[0] && $log->[0] eq "") {
2575 foreach my $line (@$log) {
2576 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2579 if (! $opts{'-remove_signoff'}) {
2580 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2583 # remove signoff lines
2590 # print only one empty line
2591 # do not print empty line after signoff
2593 next if ($empty || $signoff);
2599 print format_log_line_html
($line) . "<br/>\n";
2602 if ($opts{'-final_empty_line'}) {
2603 # end with single empty line
2604 print "<br/>\n" unless $empty;
2608 # return link target (what link points to)
2609 sub git_get_link_target
{
2614 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2618 $link_target = <$fd>;
2623 return $link_target;
2626 # given link target, and the directory (basedir) the link is in,
2627 # return target of link relative to top directory (top tree);
2628 # return undef if it is not possible (including absolute links).
2629 sub normalize_link_target
{
2630 my ($link_target, $basedir, $hash_base) = @_;
2632 # we can normalize symlink target only if $hash_base is provided
2633 return unless $hash_base;
2635 # absolute symlinks (beginning with '/') cannot be normalized
2636 return if (substr($link_target, 0, 1) eq '/');
2638 # normalize link target to path from top (root) tree (dir)
2641 $path = $basedir . '/' . $link_target;
2643 # we are in top (root) tree (dir)
2644 $path = $link_target;
2647 # remove //, /./, and /../
2649 foreach my $part (split('/', $path)) {
2650 # discard '.' and ''
2651 next if (!$part || $part eq '.');
2653 if ($part eq '..') {
2657 # link leads outside repository (outside top dir)
2661 push @path_parts, $part;
2664 $path = join('/', @path_parts);
2669 # print tree entry (row of git_tree), but without encompassing <tr> element
2670 sub git_print_tree_entry
{
2671 my ($t, $basedir, $hash_base, $have_blame) = @_;
2674 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2676 # The format of a table row is: mode list link. Where mode is
2677 # the mode of the entry, list is the name of the entry, an href,
2678 # and link is the action links of the entry.
2680 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2681 if ($t->{'type'} eq "blob") {
2682 print "<td class=\"list\">" .
2683 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2684 file_name
=>"$basedir$t->{'name'}", %base_key),
2685 -class => "list"}, esc_path
($t->{'name'}));
2686 if (S_ISLNK
(oct $t->{'mode'})) {
2687 my $link_target = git_get_link_target
($t->{'hash'});
2689 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2690 if (defined $norm_target) {
2692 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2693 file_name
=>$norm_target),
2694 -title
=> $norm_target}, esc_path
($link_target));
2696 print " -> " . esc_path
($link_target);
2701 print "<td class=\"link\">";
2702 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2703 file_name
=>"$basedir$t->{'name'}", %base_key)},
2707 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2708 file_name
=>"$basedir$t->{'name'}", %base_key)},
2711 if (defined $hash_base) {
2713 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2714 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2718 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2719 file_name
=>"$basedir$t->{'name'}")},
2723 } elsif ($t->{'type'} eq "tree") {
2724 print "<td class=\"list\">";
2725 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2726 file_name
=>"$basedir$t->{'name'}", %base_key)},
2727 esc_path
($t->{'name'}));
2729 print "<td class=\"link\">";
2730 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2731 file_name
=>"$basedir$t->{'name'}", %base_key)},
2733 if (defined $hash_base) {
2735 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2736 file_name
=>"$basedir$t->{'name'}")},
2741 # unknown object: we can only present history for it
2742 # (this includes 'commit' object, i.e. submodule support)
2743 print "<td class=\"list\">" .
2744 esc_path
($t->{'name'}) .
2746 print "<td class=\"link\">";
2747 if (defined $hash_base) {
2748 print $cgi->a({-href
=> href
(action
=>"history",
2749 hash_base
=>$hash_base,
2750 file_name
=>"$basedir$t->{'name'}")},
2757 ## ......................................................................
2758 ## functions printing large fragments of HTML
2760 sub fill_from_file_info
{
2761 my ($diff, @parents) = @_;
2763 $diff->{'from_file'} = [ ];
2764 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2765 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2766 if ($diff->{'status'}[$i] eq 'R' ||
2767 $diff->{'status'}[$i] eq 'C') {
2768 $diff->{'from_file'}[$i] =
2769 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2776 # parameters can be strings, or references to arrays of strings
2780 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2781 for (my $i = 0; $i < @$a; ++$i) {
2782 return 0 unless ($a->[$i] eq $b->[$i]);
2785 } elsif (!ref($a) && !ref($b)) {
2793 my $diffinfo = shift;
2795 return $diffinfo->{'to_id'} eq ('0' x
40);
2798 sub git_difftree_body
{
2799 my ($difftree, $hash, @parents) = @_;
2800 my ($parent) = $parents[0];
2801 my ($have_blame) = gitweb_check_feature
('blame');
2802 print "<div class=\"list_head\">\n";
2803 if ($#{$difftree} > 10) {
2804 print(($#{$difftree} + 1) . " files changed:\n");
2808 print "<table class=\"" .
2809 (@parents > 1 ? "combined " : "") .
2812 # header only for combined diff in 'commitdiff' view
2813 my $has_header = @parents > 1 && $action eq 'commitdiff';
2816 print "<thead><tr>\n" .
2817 "<th></th><th></th>\n"; # filename, patchN link
2818 for (my $i = 0; $i < @parents; $i++) {
2819 my $par = $parents[$i];
2821 $cgi->a({-href
=> href
(action
=>"commitdiff",
2822 hash
=>$hash, hash_parent
=>$par),
2823 -title
=> 'commitdiff to parent number ' .
2824 ($i+1) . ': ' . substr($par,0,7)},
2828 print "</tr></thead>\n<tbody>\n";
2833 foreach my $line (@{$difftree}) {
2835 if (ref($line) eq "HASH") {
2836 # pre-parsed (or generated by hand)
2839 $diff = parse_difftree_raw_line
($line);
2843 print "<tr class=\"dark\">\n";
2845 print "<tr class=\"light\">\n";
2849 if (exists $diff->{'nparents'}) { # combined diff
2851 fill_from_file_info
($diff, @parents)
2852 unless exists $diff->{'from_file'};
2854 if (!is_deleted
($diff)) {
2855 # file exists in the result (child) commit
2857 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2858 file_name
=>$diff->{'to_file'},
2860 -class => "list"}, esc_path
($diff->{'to_file'})) .
2864 esc_path
($diff->{'to_file'}) .
2868 if ($action eq 'commitdiff') {
2871 print "<td class=\"link\">" .
2872 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2877 my $has_history = 0;
2878 my $not_deleted = 0;
2879 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2880 my $hash_parent = $parents[$i];
2881 my $from_hash = $diff->{'from_id'}[$i];
2882 my $from_path = $diff->{'from_file'}[$i];
2883 my $status = $diff->{'status'}[$i];
2885 $has_history ||= ($status ne 'A');
2886 $not_deleted ||= ($status ne 'D');
2888 if ($status eq 'A') {
2889 print "<td class=\"link\" align=\"right\"> | </td>\n";
2890 } elsif ($status eq 'D') {
2891 print "<td class=\"link\">" .
2892 $cgi->a({-href
=> href
(action
=>"blob",
2895 file_name
=>$from_path)},
2899 if ($diff->{'to_id'} eq $from_hash) {
2900 print "<td class=\"link nochange\">";
2902 print "<td class=\"link\">";
2904 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2905 hash
=>$diff->{'to_id'},
2906 hash_parent
=>$from_hash,
2908 hash_parent_base
=>$hash_parent,
2909 file_name
=>$diff->{'to_file'},
2910 file_parent
=>$from_path)},
2916 print "<td class=\"link\">";
2918 print $cgi->a({-href
=> href
(action
=>"blob",
2919 hash
=>$diff->{'to_id'},
2920 file_name
=>$diff->{'to_file'},
2923 print " | " if ($has_history);
2926 print $cgi->a({-href
=> href
(action
=>"history",
2927 file_name
=>$diff->{'to_file'},
2934 next; # instead of 'else' clause, to avoid extra indent
2936 # else ordinary diff
2938 my ($to_mode_oct, $to_mode_str, $to_file_type);
2939 my ($from_mode_oct, $from_mode_str, $from_file_type);
2940 if ($diff->{'to_mode'} ne ('0' x
6)) {
2941 $to_mode_oct = oct $diff->{'to_mode'};
2942 if (S_ISREG
($to_mode_oct)) { # only for regular file
2943 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2945 $to_file_type = file_type
($diff->{'to_mode'});
2947 if ($diff->{'from_mode'} ne ('0' x
6)) {
2948 $from_mode_oct = oct $diff->{'from_mode'};
2949 if (S_ISREG
($to_mode_oct)) { # only for regular file
2950 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2952 $from_file_type = file_type
($diff->{'from_mode'});
2955 if ($diff->{'status'} eq "A") { # created
2956 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2957 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2958 $mode_chng .= "]</span>";
2960 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2961 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2962 -class => "list"}, esc_path
($diff->{'file'}));
2964 print "<td>$mode_chng</td>\n";
2965 print "<td class=\"link\">";
2966 if ($action eq 'commitdiff') {
2969 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2972 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2973 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2977 } elsif ($diff->{'status'} eq "D") { # deleted
2978 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2980 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2981 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2982 -class => "list"}, esc_path
($diff->{'file'}));
2984 print "<td>$mode_chng</td>\n";
2985 print "<td class=\"link\">";
2986 if ($action eq 'commitdiff') {
2989 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2992 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2993 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2996 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2997 file_name
=>$diff->{'file'})},
3000 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3001 file_name
=>$diff->{'file'})},
3005 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3006 my $mode_chnge = "";
3007 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3008 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3009 if ($from_file_type ne $to_file_type) {
3010 $mode_chnge .= " from $from_file_type to $to_file_type";
3012 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3013 if ($from_mode_str && $to_mode_str) {
3014 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3015 } elsif ($to_mode_str) {
3016 $mode_chnge .= " mode: $to_mode_str";
3019 $mode_chnge .= "]</span>\n";
3022 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3023 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3024 -class => "list"}, esc_path
($diff->{'file'}));
3026 print "<td>$mode_chnge</td>\n";
3027 print "<td class=\"link\">";
3028 if ($action eq 'commitdiff') {
3031 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3033 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3034 # "commit" view and modified file (not onlu mode changed)
3035 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3036 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3037 hash_base
=>$hash, hash_parent_base
=>$parent,
3038 file_name
=>$diff->{'file'})},
3042 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3043 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3046 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3047 file_name
=>$diff->{'file'})},
3050 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3051 file_name
=>$diff->{'file'})},
3055 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3056 my %status_name = ('R' => 'moved', 'C' => 'copied');
3057 my $nstatus = $status_name{$diff->{'status'}};
3059 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3060 # mode also for directories, so we cannot use $to_mode_str
3061 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3064 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3065 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3066 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3067 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3068 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3069 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3070 -class => "list"}, esc_path
($diff->{'from_file'})) .
3071 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3072 "<td class=\"link\">";
3073 if ($action eq 'commitdiff') {
3076 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3078 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3079 # "commit" view and modified file (not only pure rename or copy)
3080 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3081 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3082 hash_base
=>$hash, hash_parent_base
=>$parent,
3083 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3087 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3088 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3091 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3092 file_name
=>$diff->{'to_file'})},
3095 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3096 file_name
=>$diff->{'to_file'})},
3100 } # we should not encounter Unmerged (U) or Unknown (X) status
3103 print "</tbody>" if $has_header;
3107 sub git_patchset_body
{
3108 my ($fd, $difftree, $hash, @hash_parents) = @_;
3109 my ($hash_parent) = $hash_parents[0];
3112 my $patch_number = 0;
3117 print "<div class=\"patchset\">\n";
3119 # skip to first patch
3120 while ($patch_line = <$fd>) {
3123 last if ($patch_line =~ m/^diff /);
3127 while ($patch_line) {
3129 my ($from_id, $to_id);
3132 #assert($patch_line =~ m/^diff /) if DEBUG;
3133 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3135 push @diff_header, $patch_line;
3137 # extended diff header
3139 while ($patch_line = <$fd>) {
3142 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3144 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3147 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3148 $from_id = [ split(',', $1) ];
3152 push @diff_header, $patch_line;
3154 my $last_patch_line = $patch_line;
3156 # check if current patch belong to current raw line
3157 # and parse raw git-diff line if needed
3158 if (defined $diffinfo &&
3159 defined $from_id && defined $to_id &&
3160 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3161 $diffinfo->{'to_id'} eq $to_id) {
3162 # this is continuation of a split patch
3163 print "<div class=\"patch cont\">\n";
3165 # advance raw git-diff output if needed
3166 $patch_idx++ if defined $diffinfo;
3168 # compact combined diff output can have some patches skipped
3169 # find which patch (using pathname of result) we are at now
3171 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3176 # read and prepare patch information
3177 if (ref($difftree->[$patch_idx]) eq "HASH") {
3178 # pre-parsed (or generated by hand)
3179 $diffinfo = $difftree->[$patch_idx];
3181 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3184 # check if current raw line has no patch (it got simplified)
3185 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3186 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3187 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3188 "</div>\n"; # class="patch"
3193 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3194 $patch_idx > $#$difftree);
3195 # modifies %from, %to hashes
3196 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3197 if ($diffinfo->{'nparents'}) {
3201 fill_from_file_info
($diffinfo, @hash_parents)
3202 unless exists $diffinfo->{'from_file'};
3203 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3204 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3205 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3206 $from{'href'}[$i] = href
(action
=>"blob",
3207 hash_base
=>$hash_parents[$i],
3208 hash
=>$diffinfo->{'from_id'}[$i],
3209 file_name
=>$from{'file'}[$i]);
3211 $from{'href'}[$i] = undef;
3215 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3216 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3217 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3218 hash
=>$diffinfo->{'from_id'},
3219 file_name
=>$from{'file'});
3221 delete $from{'href'};
3225 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3226 if (!is_deleted
($diffinfo)) { # file exists in result
3227 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3228 hash
=>$diffinfo->{'to_id'},
3229 file_name
=>$to{'file'});
3233 # this is first patch for raw difftree line with $patch_idx index
3234 # we index @$difftree array from 0, but number patches from 1
3235 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3238 # print "git diff" header
3239 $patch_line = shift @diff_header;
3240 print format_git_diff_header_line
($patch_line, $diffinfo,
3243 # print extended diff header
3244 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3246 foreach $patch_line (@diff_header) {
3247 print format_extended_diff_header_line
($patch_line, $diffinfo,
3250 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3252 # from-file/to-file diff header
3253 $patch_line = $last_patch_line;
3254 if (! $patch_line) {
3255 print "</div>\n"; # class="patch"
3258 next PATCH
if ($patch_line =~ m/^diff /);
3259 #assert($patch_line =~ m/^---/) if DEBUG;
3260 #assert($patch_line eq $last_patch_line) if DEBUG;
3262 $patch_line = <$fd>;
3264 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3266 print format_diff_from_to_header
($last_patch_line, $patch_line,
3267 $diffinfo, \
%from, \
%to,
3272 while ($patch_line = <$fd>) {
3275 next PATCH
if ($patch_line =~ m/^diff /);
3277 print format_diff_line
($patch_line, \
%from, \
%to);
3281 print "</div>\n"; # class="patch"
3284 # for compact combined (--cc) format, with chunk and patch simpliciaction
3285 # patchset might be empty, but there might be unprocessed raw lines
3286 for ($patch_idx++ if $patch_number > 0;
3287 $patch_idx < @$difftree;
3289 # read and prepare patch information
3290 if (ref($difftree->[$patch_idx]) eq "HASH") {
3291 # pre-parsed (or generated by hand)
3292 $diffinfo = $difftree->[$patch_idx];
3294 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3297 # generate anchor for "patch" links in difftree / whatchanged part
3298 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3299 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3300 "</div>\n"; # class="patch"
3305 if ($patch_number == 0) {
3306 if (@hash_parents > 1) {
3307 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3309 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3313 print "</div>\n"; # class="patchset"
3316 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3318 sub git_project_list_body
{
3319 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3321 my ($check_forks) = gitweb_check_feature
('forks');
3324 foreach my $pr (@$projlist) {
3325 my (@aa) = git_get_last_activity
($pr->{'path'});
3329 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3330 if (!defined $pr->{'descr'}) {
3331 my $descr = git_get_project_description
($pr->{'path'}) || "";
3332 $pr->{'descr_long'} = to_utf8
($descr);
3333 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3335 if (!defined $pr->{'owner'}) {
3336 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3339 my $pname = $pr->{'path'};
3340 if (($pname =~ s/\.git$//) &&
3341 ($pname !~ /\/$/) &&
3342 (-d
"$projectroot/$pname")) {
3343 $pr->{'forks'} = "-d $projectroot/$pname";
3349 push @projects, $pr;
3352 $order ||= $default_projects_order;
3353 $from = 0 unless defined $from;
3354 $to = $#projects if (!defined $to || $#projects < $to);
3356 print "<table class=\"project_list\">\n";
3357 unless ($no_header) {
3360 print "<th></th>\n";
3362 if ($order eq "project") {
3363 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3364 print "<th>Project</th>\n";
3367 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3368 -class => "header"}, "Project") .
3371 if ($order eq "descr") {
3372 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3373 print "<th>Description</th>\n";
3376 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3377 -class => "header"}, "Description") .
3380 if ($order eq "owner") {
3381 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3382 print "<th>Owner</th>\n";
3385 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3386 -class => "header"}, "Owner") .
3389 if ($order eq "age") {
3390 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3391 print "<th>Last Change</th>\n";
3394 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3395 -class => "header"}, "Last Change") .
3398 print "<th></th>\n" .
3402 for (my $i = $from; $i <= $to; $i++) {
3403 my $pr = $projects[$i];
3405 print "<tr class=\"dark\">\n";
3407 print "<tr class=\"light\">\n";
3412 if ($pr->{'forks'}) {
3413 print "<!-- $pr->{'forks'} -->\n";
3414 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3418 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3419 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3420 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3421 -class => "list", -title
=> $pr->{'descr_long'}},
3422 esc_html
($pr->{'descr'})) . "</td>\n" .
3423 "<td><i>" . esc_html
(chop_str
($pr->{'owner'}, 15)) . "</i></td>\n";
3424 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3425 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3426 "<td class=\"link\">" .
3427 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3428 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3429 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3430 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3431 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3435 if (defined $extra) {
3438 print "<td></td>\n";
3440 print "<td colspan=\"5\">$extra</td>\n" .
3446 sub git_shortlog_body
{
3447 # uses global variable $project
3448 my ($commitlist, $from, $to, $refs, $extra) = @_;
3450 $from = 0 unless defined $from;
3451 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3453 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3455 for (my $i = $from; $i <= $to; $i++) {
3456 my %co = %{$commitlist->[$i]};
3457 my $commit = $co{'id'};
3458 my $ref = format_ref_marker
($refs, $commit);
3460 print "<tr class=\"dark\">\n";
3462 print "<tr class=\"light\">\n";
3465 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3466 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3467 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3469 print format_subject_html
($co{'title'}, $co{'title_short'},
3470 href
(action
=>"commit", hash
=>$commit), $ref);
3472 "<td class=\"link\">" .
3473 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3474 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3475 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3476 my $snapshot_links = format_snapshot_links
($commit);
3477 if (defined $snapshot_links) {
3478 print " | " . $snapshot_links;
3483 if (defined $extra) {
3485 "<td colspan=\"4\">$extra</td>\n" .
3491 sub git_history_body
{
3492 # Warning: assumes constant type (blob or tree) during history
3493 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3495 $from = 0 unless defined $from;
3496 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3498 print "<table class=\"history\" cellspacing=\"0\">\n";
3500 for (my $i = $from; $i <= $to; $i++) {
3501 my %co = %{$commitlist->[$i]};
3505 my $commit = $co{'id'};
3507 my $ref = format_ref_marker
($refs, $commit);
3510 print "<tr class=\"dark\">\n";
3512 print "<tr class=\"light\">\n";
3515 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3516 # shortlog uses chop_str($co{'author_name'}, 10)
3517 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3519 # originally git_history used chop_str($co{'title'}, 50)
3520 print format_subject_html
($co{'title'}, $co{'title_short'},
3521 href
(action
=>"commit", hash
=>$commit), $ref);
3523 "<td class=\"link\">" .
3524 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3525 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3527 if ($ftype eq 'blob') {
3528 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3529 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3530 if (defined $blob_current && defined $blob_parent &&
3531 $blob_current ne $blob_parent) {
3533 $cgi->a({-href
=> href
(action
=>"blobdiff",
3534 hash
=>$blob_current, hash_parent
=>$blob_parent,
3535 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3536 file_name
=>$file_name)},
3543 if (defined $extra) {
3545 "<td colspan=\"4\">$extra</td>\n" .
3552 # uses global variable $project
3553 my ($taglist, $from, $to, $extra) = @_;
3554 $from = 0 unless defined $from;
3555 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3557 print "<table class=\"tags\" cellspacing=\"0\">\n";
3559 for (my $i = $from; $i <= $to; $i++) {
3560 my $entry = $taglist->[$i];
3562 my $comment = $tag{'subject'};
3564 if (defined $comment) {
3565 $comment_short = chop_str
($comment, 30, 5);
3568 print "<tr class=\"dark\">\n";
3570 print "<tr class=\"light\">\n";
3573 if (defined $tag{'age'}) {
3574 print "<td><i>$tag{'age'}</i></td>\n";
3576 print "<td></td>\n";
3579 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3580 -class => "list name"}, esc_html
($tag{'name'})) .
3583 if (defined $comment) {
3584 print format_subject_html
($comment, $comment_short,
3585 href
(action
=>"tag", hash
=>$tag{'id'}));
3588 "<td class=\"selflink\">";
3589 if ($tag{'type'} eq "tag") {
3590 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3595 "<td class=\"link\">" . " | " .
3596 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3597 if ($tag{'reftype'} eq "commit") {
3598 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3599 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3600 } elsif ($tag{'reftype'} eq "blob") {
3601 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3606 if (defined $extra) {
3608 "<td colspan=\"5\">$extra</td>\n" .
3614 sub git_heads_body
{
3615 # uses global variable $project
3616 my ($headlist, $head, $from, $to, $extra) = @_;
3617 $from = 0 unless defined $from;
3618 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3620 print "<table class=\"heads\" cellspacing=\"0\">\n";
3622 for (my $i = $from; $i <= $to; $i++) {
3623 my $entry = $headlist->[$i];
3625 my $curr = $ref{'id'} eq $head;
3627 print "<tr class=\"dark\">\n";
3629 print "<tr class=\"light\">\n";
3632 print "<td><i>$ref{'age'}</i></td>\n" .
3633 ($curr ? "<td class=\"current_head\">" : "<td>") .
3634 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3635 -class => "list name"},esc_html
($ref{'name'})) .
3637 "<td class=\"link\">" .
3638 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3639 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3640 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3644 if (defined $extra) {
3646 "<td colspan=\"3\">$extra</td>\n" .
3652 sub git_search_grep_body
{
3653 my ($commitlist, $from, $to, $extra) = @_;
3654 $from = 0 unless defined $from;
3655 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3657 print "<table class=\"grep\" cellspacing=\"0\">\n";
3659 for (my $i = $from; $i <= $to; $i++) {
3660 my %co = %{$commitlist->[$i]};
3664 my $commit = $co{'id'};
3666 print "<tr class=\"dark\">\n";
3668 print "<tr class=\"light\">\n";
3671 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3672 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3674 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3675 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3676 my $comment = $co{'comment'};
3677 foreach my $line (@$comment) {
3678 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3679 my $lead = esc_html
($1) || "";
3680 $lead = chop_str
($lead, 30, 10);
3681 my $match = esc_html
($2) || "";
3682 my $trail = esc_html
($3) || "";
3683 $trail = chop_str
($trail, 30, 10);
3684 my $text = "$lead<span class=\"match\">$match</span>$trail";
3685 print chop_str
($text, 80, 5) . "<br/>\n";
3689 "<td class=\"link\">" .
3690 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3692 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3696 if (defined $extra) {
3698 "<td colspan=\"3\">$extra</td>\n" .
3704 ## ======================================================================
3705 ## ======================================================================
3708 sub git_project_list
{
3709 my $order = $cgi->param('o');
3710 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3711 die_error
(undef, "Unknown order parameter");
3714 my @list = git_get_projects_list
();
3716 die_error
(undef, "No projects found");
3720 if (-f
$home_text) {
3721 print "<div class=\"index_include\">\n";
3722 open (my $fd, $home_text);
3727 git_project_list_body
(\
@list, $order);
3732 my $order = $cgi->param('o');
3733 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3734 die_error
(undef, "Unknown order parameter");
3737 my @list = git_get_projects_list
($project);
3739 die_error
(undef, "No forks found");
3743 git_print_page_nav
('','');
3744 git_print_header_div
('summary', "$project forks");
3745 git_project_list_body
(\
@list, $order);
3749 sub git_project_index
{
3750 my @projects = git_get_projects_list
($project);
3753 -type
=> 'text/plain',
3754 -charset
=> 'utf-8',
3755 -content_disposition
=> 'inline; filename="index.aux"');
3757 foreach my $pr (@projects) {
3758 if (!exists $pr->{'owner'}) {
3759 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3762 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3763 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3764 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3765 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3769 print "$path $owner\n";
3774 my $descr = git_get_project_description
($project) || "none";
3775 my %co = parse_commit
("HEAD");
3776 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3777 my $head = $co{'id'};
3779 my $owner = git_get_project_owner
($project);
3781 my $refs = git_get_references
();
3782 # These get_*_list functions return one more to allow us to see if
3783 # there are more ...
3784 my @taglist = git_get_tags_list
(16);
3785 my @headlist = git_get_heads_list
(16);
3787 my ($check_forks) = gitweb_check_feature
('forks');
3790 @forklist = git_get_projects_list
($project);
3794 git_print_page_nav
('summary','', $head);
3796 print "<div class=\"title\"> </div>\n";
3797 print "<table cellspacing=\"0\">\n" .
3798 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3799 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3800 if (defined $cd{'rfc2822'}) {
3801 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3804 # use per project git URL list in $projectroot/$project/cloneurl
3805 # or make project git URL from git base URL and project name
3806 my $url_tag = "URL";
3807 my @url_list = git_get_project_url_list
($project);
3808 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3809 foreach my $git_url (@url_list) {
3810 next unless $git_url;
3811 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3816 if (-s
"$projectroot/$project/README.html") {
3817 if (open my $fd, "$projectroot/$project/README.html") {
3818 print "<div class=\"title\">readme</div>\n";
3819 print $_ while (<$fd>);
3824 # we need to request one more than 16 (0..15) to check if
3826 my @commitlist = $head ? parse_commits
($head, 17) : ();
3828 git_print_header_div
('shortlog');
3829 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3830 $#commitlist <= 15 ? undef :
3831 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3835 git_print_header_div
('tags');
3836 git_tags_body
(\
@taglist, 0, 15,
3837 $#taglist <= 15 ? undef :
3838 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3842 git_print_header_div
('heads');
3843 git_heads_body
(\
@headlist, $head, 0, 15,
3844 $#headlist <= 15 ? undef :
3845 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3849 git_print_header_div
('forks');
3850 git_project_list_body
(\
@forklist, undef, 0, 15,
3851 $#forklist <= 15 ? undef :
3852 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3860 my $head = git_get_head_hash
($project);
3862 git_print_page_nav
('','', $head,undef,$head);
3863 my %tag = parse_tag
($hash);
3866 die_error
(undef, "Unknown tag object");
3869 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3870 print "<div class=\"title_text\">\n" .
3871 "<table cellspacing=\"0\">\n" .
3873 "<td>object</td>\n" .
3874 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3875 $tag{'object'}) . "</td>\n" .
3876 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3877 $tag{'type'}) . "</td>\n" .
3879 if (defined($tag{'author'})) {
3880 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3881 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3882 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3883 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3886 print "</table>\n\n" .
3888 print "<div class=\"page_body\">";
3889 my $comment = $tag{'comment'};
3890 foreach my $line (@$comment) {
3892 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3902 my ($have_blame) = gitweb_check_feature
('blame');
3904 die_error
('403 Permission denied', "Permission denied");
3906 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3907 $hash_base ||= git_get_head_hash
($project);
3908 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3909 my %co = parse_commit
($hash_base)
3910 or die_error
(undef, "Reading commit failed");
3911 if (!defined $hash) {
3912 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3913 or die_error
(undef, "Error looking up file");
3915 $ftype = git_get_type
($hash);
3916 if ($ftype !~ "blob") {
3917 die_error
('400 Bad Request', "Object is not a blob");
3919 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3920 $file_name, $hash_base)
3921 or die_error
(undef, "Open git-blame failed");
3924 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3927 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3930 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3932 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3933 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3934 git_print_page_path
($file_name, $ftype, $hash_base);
3935 my @rev_color = (qw(light2 dark2));
3936 my $num_colors = scalar(@rev_color);
3937 my $current_color = 0;
3940 <div class="page_body">
3941 <table class="blame">
3942 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3947 last unless defined $_;
3948 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3949 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3950 if (!exists $metainfo{$full_rev}) {
3951 $metainfo{$full_rev} = {};
3953 my $meta = $metainfo{$full_rev};
3956 if (/^(\S+) (.*)$/) {
3962 my $rev = substr($full_rev, 0, 8);
3963 my $author = $meta->{'author'};
3964 my %date = parse_date
($meta->{'author-time'},
3965 $meta->{'author-tz'});
3966 my $date = $date{'iso-tz'};
3968 $current_color = ++$current_color % $num_colors;
3970 print "<tr class=\"$rev_color[$current_color]\">\n";
3972 print "<td class=\"sha1\"";
3973 print " title=\"". esc_html
($author) . ", $date\"";
3974 print " rowspan=\"$group_size\"" if ($group_size > 1);
3976 print $cgi->a({-href
=> href
(action
=>"commit",
3978 file_name
=>$file_name)},
3982 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3983 or die_error
(undef, "Open git-rev-parse failed");
3984 my $parent_commit = <$dd>;
3986 chomp($parent_commit);
3987 my $blamed = href
(action
=> 'blame',
3988 file_name
=> $meta->{'filename'},
3989 hash_base
=> $parent_commit);
3990 print "<td class=\"linenr\">";
3991 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3993 -class => "linenr" },
3996 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4002 or print "Reading blob failed\n";
4009 my ($have_blame) = gitweb_check_feature
('blame');
4011 die_error
('403 Permission denied', "Permission denied");
4013 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4014 $hash_base ||= git_get_head_hash
($project);
4015 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4016 my %co = parse_commit
($hash_base)
4017 or die_error
(undef, "Reading commit failed");
4018 if (!defined $hash) {
4019 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4020 or die_error
(undef, "Error lookup file");
4022 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4023 or die_error
(undef, "Open git-annotate failed");
4026 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4029 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4032 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4034 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4035 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4036 git_print_page_path
($file_name, 'blob', $hash_base);
4037 print "<div class=\"page_body\">\n";
4039 <table class="blame">
4048 my @line_class = (qw(light dark));
4049 my $line_class_len = scalar (@line_class);
4050 my $line_class_num = $#line_class;
4051 while (my $line = <$fd>) {
4063 $line_class_num = ($line_class_num + 1) % $line_class_len;
4065 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4072 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4075 $short_rev = substr ($long_rev, 0, 8);
4076 $age = time () - $time;
4077 $age_str = age_string
($age);
4078 $age_str =~ s/ / /g;
4079 $age_class = age_class
($age);
4080 $author = esc_html
($author);
4081 $author =~ s/ / /g;
4083 $data = untabify
($data);
4084 $data = esc_html
($data);
4087 <tr class="$line_class[$line_class_num]">
4088 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4089 <td class="$age_class">$age_str</td>
4091 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4092 <td class="pre">$data</td>
4095 } # while (my $line = <$fd>)
4096 print "</table>\n\n";
4098 or print "Reading blob failed.\n";
4104 my $head = git_get_head_hash
($project);
4106 git_print_page_nav
('','', $head,undef,$head);
4107 git_print_header_div
('summary', $project);
4109 my @tagslist = git_get_tags_list
();
4111 git_tags_body
(\
@tagslist);
4117 my $head = git_get_head_hash
($project);
4119 git_print_page_nav
('','', $head,undef,$head);
4120 git_print_header_div
('summary', $project);
4122 my @headslist = git_get_heads_list
();
4124 git_heads_body
(\
@headslist, $head);
4129 sub git_blob_plain
{
4132 if (!defined $hash) {
4133 if (defined $file_name) {
4134 my $base = $hash_base || git_get_head_hash
($project);
4135 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4136 or die_error
(undef, "Error lookup file");
4138 die_error
(undef, "No file name defined");
4140 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4141 # blobs defined by non-textual hash id's can be cached
4146 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4147 or die_error
(undef, "Couldn't cat $file_name, $hash");
4149 $type ||= blob_mimetype
($fd, $file_name);
4151 # save as filename, even when no $file_name is given
4152 my $save_as = "$hash";
4153 if (defined $file_name) {
4154 $save_as = $file_name;
4155 } elsif ($type =~ m/^text\//) {
4162 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4164 binmode STDOUT
, ':raw';
4166 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4174 if (!defined $hash) {
4175 if (defined $file_name) {
4176 my $base = $hash_base || git_get_head_hash
($project);
4177 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4178 or die_error
(undef, "Error lookup file");
4180 die_error
(undef, "No file name defined");
4182 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4183 # blobs defined by non-textual hash id's can be cached
4187 my ($have_blame) = gitweb_check_feature
('blame');
4188 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4189 or die_error
(undef, "Couldn't cat $file_name, $hash");
4190 my $mimetype = blob_mimetype
($fd, $file_name);
4191 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4193 return git_blob_plain
($mimetype);
4195 # we can have blame only for text/* mimetype
4196 $have_blame &&= ($mimetype =~ m!^text/!);
4198 git_header_html
(undef, $expires);
4199 my $formats_nav = '';
4200 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4201 if (defined $file_name) {
4204 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4205 hash
=>$hash, file_name
=>$file_name)},
4210 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4211 hash
=>$hash, file_name
=>$file_name)},
4214 $cgi->a({-href
=> href
(action
=>"blob_plain",
4215 hash
=>$hash, file_name
=>$file_name)},
4218 $cgi->a({-href
=> href
(action
=>"blob",
4219 hash_base
=>"HEAD", file_name
=>$file_name)},
4223 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4225 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4226 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4228 print "<div class=\"page_nav\">\n" .
4229 "<br/><br/></div>\n" .
4230 "<div class=\"title\">$hash</div>\n";
4232 git_print_page_path
($file_name, "blob", $hash_base);
4233 print "<div class=\"page_body\">\n";
4234 if ($mimetype =~ m!^text/!) {
4236 while (my $line = <$fd>) {
4239 $line = untabify
($line);
4240 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4241 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4243 } elsif ($mimetype =~ m!^image/!) {
4244 print qq
!<img type
="$mimetype"!;
4246 print qq
! alt
="$file_name" title
="$file_name"!;
4249 href(action=>"blob_plain
", hash=>$hash,
4250 hash_base=>$hash_base, file_name=>$file_name) .
4254 or print "Reading blob failed.\n";
4260 if (!defined $hash_base) {
4261 $hash_base = "HEAD";
4263 if (!defined $hash) {
4264 if (defined $file_name) {
4265 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4271 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4272 or die_error
(undef, "Open git-ls-tree failed");
4273 my @entries = map { chomp; $_ } <$fd>;
4274 close $fd or die_error
(undef, "Reading tree failed");
4277 my $refs = git_get_references
();
4278 my $ref = format_ref_marker
($refs, $hash_base);
4281 my ($have_blame) = gitweb_check_feature
('blame');
4282 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4284 if (defined $file_name) {
4286 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4287 hash
=>$hash, file_name
=>$file_name)},
4289 $cgi->a({-href
=> href
(action
=>"tree",
4290 hash_base
=>"HEAD", file_name
=>$file_name)},
4293 my $snapshot_links = format_snapshot_links
($hash);
4294 if (defined $snapshot_links) {
4295 # FIXME: Should be available when we have no hash base as well.
4296 push @views_nav, $snapshot_links;
4298 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4299 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4302 print "<div class=\"page_nav\">\n";
4303 print "<br/><br/></div>\n";
4304 print "<div class=\"title\">$hash</div>\n";
4306 if (defined $file_name) {
4307 $basedir = $file_name;
4308 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4312 git_print_page_path
($file_name, 'tree', $hash_base);
4313 print "<div class=\"page_body\">\n";
4314 print "<table cellspacing=\"0\">\n";
4316 # '..' (top directory) link if possible
4317 if (defined $hash_base &&
4318 defined $file_name && $file_name =~ m![^/]+$!) {
4320 print "<tr class=\"dark\">\n";
4322 print "<tr class=\"light\">\n";
4326 my $up = $file_name;
4327 $up =~ s!/?[^/]+$!!;
4328 undef $up unless $up;
4329 # based on git_print_tree_entry
4330 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4331 print '<td class="list">';
4332 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4336 print "<td class=\"link\"></td>\n";
4340 foreach my $line (@entries) {
4341 my %t = parse_ls_tree_line
($line, -z
=> 1);
4344 print "<tr class=\"dark\">\n";
4346 print "<tr class=\"light\">\n";
4350 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4354 print "</table>\n" .
4360 my @supported_fmts = gitweb_check_feature
('snapshot');
4361 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4363 my $format = $cgi->param('sf');
4364 if (!@supported_fmts) {
4365 die_error
('403 Permission denied', "Permission denied");
4367 # default to first supported snapshot format
4368 $format ||= $supported_fmts[0];
4369 if ($format !~ m/^[a-z0-9]+$/) {
4370 die_error
(undef, "Invalid snapshot format parameter");
4371 } elsif (!exists($known_snapshot_formats{$format})) {
4372 die_error
(undef, "Unknown snapshot format");
4373 } elsif (!grep($_ eq $format, @supported_fmts)) {
4374 die_error
(undef, "Unsupported snapshot format");
4377 if (!defined $hash) {
4378 $hash = git_get_head_hash
($project);
4381 my $git_command = git_cmd_str
();
4382 my $name = $project;
4383 $name =~ s
,([^/])/*\
.git
$,$1,;
4384 $name = basename
($name);
4385 my $filename = to_utf8
($name);
4386 $name =~ s/\047/\047\\\047\047/g;
4388 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4389 $cmd = "$git_command archive " .
4390 "--format=$known_snapshot_formats{$format}{'format'} " .
4391 "--prefix=\'$name\'/ $hash";
4392 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4393 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4397 -type
=> $known_snapshot_formats{$format}{'type'},
4398 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4399 -status
=> '200 OK');
4401 open my $fd, "-|", $cmd
4402 or die_error
(undef, "Execute git-archive failed");
4403 binmode STDOUT
, ':raw';
4405 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4410 my $head = git_get_head_hash
($project);
4411 if (!defined $hash) {
4414 if (!defined $page) {
4417 my $refs = git_get_references
();
4419 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4421 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4424 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4427 my %co = parse_commit
($hash);
4429 git_print_header_div
('summary', $project);
4430 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4432 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4433 for (my $i = 0; $i <= $to; $i++) {
4434 my %co = %{$commitlist[$i]};
4436 my $commit = $co{'id'};
4437 my $ref = format_ref_marker
($refs, $commit);
4438 my %ad = parse_date
($co{'author_epoch'});
4439 git_print_header_div
('commit',
4440 "<span class=\"age\">$co{'age_string'}</span>" .
4441 esc_html
($co{'title'}) . $ref,
4443 print "<div class=\"title_text\">\n" .
4444 "<div class=\"log_link\">\n" .
4445 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4447 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4449 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4452 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4455 print "<div class=\"log_body\">\n";
4456 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4459 if ($#commitlist >= 100) {
4460 print "<div class=\"page_nav\">\n";
4461 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4462 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4469 $hash ||= $hash_base || "HEAD";
4470 my %co = parse_commit
($hash);
4472 die_error
(undef, "Unknown commit object");
4474 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4475 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4477 my $parent = $co{'parent'};
4478 my $parents = $co{'parents'}; # listref
4480 # we need to prepare $formats_nav before any parameter munging
4482 if (!defined $parent) {
4484 $formats_nav .= '(initial)';
4485 } elsif (@$parents == 1) {
4486 # single parent commit
4489 $cgi->a({-href
=> href
(action
=>"commit",
4491 esc_html
(substr($parent, 0, 7))) .
4498 $cgi->a({-href
=> href
(action
=>"commit",
4500 esc_html
(substr($_, 0, 7)));
4505 if (!defined $parent) {
4509 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4511 (@$parents <= 1 ? $parent : '-c'),
4513 or die_error
(undef, "Open git-diff-tree failed");
4514 @difftree = map { chomp; $_ } <$fd>;
4515 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4517 # non-textual hash id's can be cached
4519 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4522 my $refs = git_get_references
();
4523 my $ref = format_ref_marker
($refs, $co{'id'});
4525 git_header_html
(undef, $expires);
4526 git_print_page_nav
('commit', '',
4527 $hash, $co{'tree'}, $hash,
4530 if (defined $co{'parent'}) {
4531 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4533 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4535 print "<div class=\"title_text\">\n" .
4536 "<table cellspacing=\"0\">\n";
4537 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4539 "<td></td><td> $ad{'rfc2822'}";
4540 if ($ad{'hour_local'} < 6) {
4541 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4542 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4544 printf(" (%02d:%02d %s)",
4545 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4549 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4550 print "<tr><td></td><td> $cd{'rfc2822'}" .
4551 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4553 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4556 "<td class=\"sha1\">" .
4557 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4558 class => "list"}, $co{'tree'}) .
4560 "<td class=\"link\">" .
4561 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4563 my $snapshot_links = format_snapshot_links
($hash);
4564 if (defined $snapshot_links) {
4565 print " | " . $snapshot_links;
4570 foreach my $par (@$parents) {
4573 "<td class=\"sha1\">" .
4574 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4575 class => "list"}, $par) .
4577 "<td class=\"link\">" .
4578 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4580 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4587 print "<div class=\"page_body\">\n";
4588 git_print_log
($co{'comment'});
4591 git_difftree_body
(\
@difftree, $hash, @$parents);
4597 # object is defined by:
4598 # - hash or hash_base alone
4599 # - hash_base and file_name
4602 # - hash or hash_base alone
4603 if ($hash || ($hash_base && !defined $file_name)) {
4604 my $object_id = $hash || $hash_base;
4606 my $git_command = git_cmd_str
();
4607 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4608 or die_error
('404 Not Found', "Object does not exist");
4612 or die_error
('404 Not Found', "Object does not exist");
4614 # - hash_base and file_name
4615 } elsif ($hash_base && defined $file_name) {
4616 $file_name =~ s
,/+$,,;
4618 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4619 or die_error
('404 Not Found', "Base object does not exist");
4621 # here errors should not hapen
4622 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4623 or die_error
(undef, "Open git-ls-tree failed");
4627 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4628 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4629 die_error
('404 Not Found', "File or directory for given base does not exist");
4634 die_error
('404 Not Found', "Not enough information to find object");
4637 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4638 hash
=>$hash, hash_base
=>$hash_base,
4639 file_name
=>$file_name),
4640 -status
=> '302 Found');
4644 my $format = shift || 'html';
4651 # preparing $fd and %diffinfo for git_patchset_body
4653 if (defined $hash_base && defined $hash_parent_base) {
4654 if (defined $file_name) {
4656 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4657 $hash_parent_base, $hash_base,
4658 "--", (defined $file_parent ? $file_parent : ()), $file_name
4659 or die_error
(undef, "Open git-diff-tree failed");
4660 @difftree = map { chomp; $_ } <$fd>;
4662 or die_error
(undef, "Reading git-diff-tree failed");
4664 or die_error
('404 Not Found', "Blob diff not found");
4666 } elsif (defined $hash &&
4667 $hash =~ /[0-9a-fA-F]{40}/) {
4668 # try to find filename from $hash
4670 # read filtered raw output
4671 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4672 $hash_parent_base, $hash_base, "--"
4673 or die_error
(undef, "Open git-diff-tree failed");
4675 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4677 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4678 map { chomp; $_ } <$fd>;
4680 or die_error
(undef, "Reading git-diff-tree failed");
4682 or die_error
('404 Not Found', "Blob diff not found");
4685 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4688 if (@difftree > 1) {
4689 die_error
('404 Not Found', "Ambiguous blob diff specification");
4692 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4693 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4694 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4696 $hash_parent ||= $diffinfo{'from_id'};
4697 $hash ||= $diffinfo{'to_id'};
4699 # non-textual hash id's can be cached
4700 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4701 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4706 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4707 '-p', ($format eq 'html' ? "--full-index" : ()),
4708 $hash_parent_base, $hash_base,
4709 "--", (defined $file_parent ? $file_parent : ()), $file_name
4710 or die_error
(undef, "Open git-diff-tree failed");
4713 # old/legacy style URI
4714 if (!%diffinfo && # if new style URI failed
4715 defined $hash && defined $hash_parent) {
4716 # fake git-diff-tree raw output
4717 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4718 $diffinfo{'from_id'} = $hash_parent;
4719 $diffinfo{'to_id'} = $hash;
4720 if (defined $file_name) {
4721 if (defined $file_parent) {
4722 $diffinfo{'status'} = '2';
4723 $diffinfo{'from_file'} = $file_parent;
4724 $diffinfo{'to_file'} = $file_name;
4725 } else { # assume not renamed
4726 $diffinfo{'status'} = '1';
4727 $diffinfo{'from_file'} = $file_name;
4728 $diffinfo{'to_file'} = $file_name;
4730 } else { # no filename given
4731 $diffinfo{'status'} = '2';
4732 $diffinfo{'from_file'} = $hash_parent;
4733 $diffinfo{'to_file'} = $hash;
4736 # non-textual hash id's can be cached
4737 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4738 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4743 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4744 '-p', ($format eq 'html' ? "--full-index" : ()),
4745 $hash_parent, $hash, "--"
4746 or die_error
(undef, "Open git-diff failed");
4748 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4753 if ($format eq 'html') {
4755 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4756 hash
=>$hash, hash_parent
=>$hash_parent,
4757 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4758 file_name
=>$file_name, file_parent
=>$file_parent)},
4760 git_header_html
(undef, $expires);
4761 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4762 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4763 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4765 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4766 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4768 if (defined $file_name) {
4769 git_print_page_path
($file_name, "blob", $hash_base);
4771 print "<div class=\"page_path\"></div>\n";
4774 } elsif ($format eq 'plain') {
4776 -type
=> 'text/plain',
4777 -charset
=> 'utf-8',
4778 -expires
=> $expires,
4779 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4781 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4784 die_error
(undef, "Unknown blobdiff format");
4788 if ($format eq 'html') {
4789 print "<div class=\"page_body\">\n";
4791 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4794 print "</div>\n"; # class="page_body"
4798 while (my $line = <$fd>) {
4799 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4800 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4804 last if $line =~ m!^\+\+\+!;
4812 sub git_blobdiff_plain
{
4813 git_blobdiff
('plain');
4816 sub git_commitdiff
{
4817 my $format = shift || 'html';
4818 $hash ||= $hash_base || "HEAD";
4819 my %co = parse_commit
($hash);
4821 die_error
(undef, "Unknown commit object");
4824 # choose format for commitdiff for merge
4825 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4826 $hash_parent = '--cc';
4828 # we need to prepare $formats_nav before almost any parameter munging
4830 if ($format eq 'html') {
4832 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4833 hash
=>$hash, hash_parent
=>$hash_parent)},
4836 if (defined $hash_parent &&
4837 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4838 # commitdiff with two commits given
4839 my $hash_parent_short = $hash_parent;
4840 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4841 $hash_parent_short = substr($hash_parent, 0, 7);
4845 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4846 if ($co{'parents'}[$i] eq $hash_parent) {
4847 $formats_nav .= ' parent ' . ($i+1);
4851 $formats_nav .= ': ' .
4852 $cgi->a({-href
=> href
(action
=>"commitdiff",
4853 hash
=>$hash_parent)},
4854 esc_html
($hash_parent_short)) .
4856 } elsif (!$co{'parent'}) {
4858 $formats_nav .= ' (initial)';
4859 } elsif (scalar @{$co{'parents'}} == 1) {
4860 # single parent commit
4863 $cgi->a({-href
=> href
(action
=>"commitdiff",
4864 hash
=>$co{'parent'})},
4865 esc_html
(substr($co{'parent'}, 0, 7))) .
4869 if ($hash_parent eq '--cc') {
4870 $formats_nav .= ' | ' .
4871 $cgi->a({-href
=> href
(action
=>"commitdiff",
4872 hash
=>$hash, hash_parent
=>'-c')},
4874 } else { # $hash_parent eq '-c'
4875 $formats_nav .= ' | ' .
4876 $cgi->a({-href
=> href
(action
=>"commitdiff",
4877 hash
=>$hash, hash_parent
=>'--cc')},
4883 $cgi->a({-href
=> href
(action
=>"commitdiff",
4885 esc_html
(substr($_, 0, 7)));
4886 } @{$co{'parents'}} ) .
4891 my $hash_parent_param = $hash_parent;
4892 if (!defined $hash_parent_param) {
4893 # --cc for multiple parents, --root for parentless
4894 $hash_parent_param =
4895 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4901 if ($format eq 'html') {
4902 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4903 "--no-commit-id", "--patch-with-raw", "--full-index",
4904 $hash_parent_param, $hash, "--"
4905 or die_error
(undef, "Open git-diff-tree failed");
4907 while (my $line = <$fd>) {
4909 # empty line ends raw part of diff-tree output
4911 push @difftree, scalar parse_difftree_raw_line
($line);
4914 } elsif ($format eq 'plain') {
4915 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4916 '-p', $hash_parent_param, $hash, "--"
4917 or die_error
(undef, "Open git-diff-tree failed");
4920 die_error
(undef, "Unknown commitdiff format");
4923 # non-textual hash id's can be cached
4925 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4929 # write commit message
4930 if ($format eq 'html') {
4931 my $refs = git_get_references
();
4932 my $ref = format_ref_marker
($refs, $co{'id'});
4934 git_header_html
(undef, $expires);
4935 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4936 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4937 git_print_authorship
(\
%co);
4938 print "<div class=\"page_body\">\n";
4939 if (@{$co{'comment'}} > 1) {
4940 print "<div class=\"log\">\n";
4941 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4942 print "</div>\n"; # class="log"
4945 } elsif ($format eq 'plain') {
4946 my $refs = git_get_references
("tags");
4947 my $tagname = git_get_rev_name_tags
($hash);
4948 my $filename = basename
($project) . "-$hash.patch";
4951 -type
=> 'text/plain',
4952 -charset
=> 'utf-8',
4953 -expires
=> $expires,
4954 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4955 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4958 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4959 Subject: $co{'title'}
4961 print "X-Git-Tag: $tagname\n" if $tagname;
4962 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4964 foreach my $line (@{$co{'comment'}}) {
4971 if ($format eq 'html') {
4972 my $use_parents = !defined $hash_parent ||
4973 $hash_parent eq '-c' || $hash_parent eq '--cc';
4974 git_difftree_body
(\
@difftree, $hash,
4975 $use_parents ? @{$co{'parents'}} : $hash_parent);
4978 git_patchset_body
($fd, \
@difftree, $hash,
4979 $use_parents ? @{$co{'parents'}} : $hash_parent);
4981 print "</div>\n"; # class="page_body"
4984 } elsif ($format eq 'plain') {
4988 or print "Reading git-diff-tree failed\n";
4992 sub git_commitdiff_plain
{
4993 git_commitdiff
('plain');
4997 if (!defined $hash_base) {
4998 $hash_base = git_get_head_hash
($project);
5000 if (!defined $page) {
5004 my %co = parse_commit
($hash_base);
5006 die_error
(undef, "Unknown commit object");
5009 my $refs = git_get_references
();
5010 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5012 if (!defined $hash && defined $file_name) {
5013 $hash = git_get_hash_by_path
($hash_base, $file_name);
5015 if (defined $hash) {
5016 $ftype = git_get_type
($hash);
5019 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5021 my $paging_nav = '';
5024 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5025 file_name
=>$file_name)},
5027 $paging_nav .= " ⋅ " .
5028 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5029 file_name
=>$file_name, page
=>$page-1),
5030 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5032 $paging_nav .= "first";
5033 $paging_nav .= " ⋅ prev";
5035 if ($#commitlist >= 100) {
5036 $paging_nav .= " ⋅ " .
5037 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5038 file_name
=>$file_name, page
=>$page+1),
5039 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5041 $paging_nav .= " ⋅ next";
5044 if ($#commitlist >= 100) {
5046 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5047 file_name
=>$file_name, page
=>$page+1),
5048 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5052 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5053 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5054 git_print_page_path
($file_name, $ftype, $hash_base);
5056 git_history_body
(\
@commitlist, 0, 99,
5057 $refs, $hash_base, $ftype, $next_link);
5063 my ($have_search) = gitweb_check_feature
('search');
5064 if (!$have_search) {
5065 die_error
('403 Permission denied', "Permission denied");
5067 if (!defined $searchtext) {
5068 die_error
(undef, "Text field empty");
5070 if (!defined $hash) {
5071 $hash = git_get_head_hash
($project);
5073 my %co = parse_commit
($hash);
5075 die_error
(undef, "Unknown commit object");
5077 if (!defined $page) {
5081 $searchtype ||= 'commit';
5082 if ($searchtype eq 'pickaxe') {
5083 # pickaxe may take all resources of your box and run for several minutes
5084 # with every query - so decide by yourself how public you make this feature
5085 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5086 if (!$have_pickaxe) {
5087 die_error
('403 Permission denied', "Permission denied");
5090 if ($searchtype eq 'grep') {
5091 my ($have_grep) = gitweb_check_feature
('grep');
5093 die_error
('403 Permission denied', "Permission denied");
5099 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5101 if ($searchtype eq 'commit') {
5102 $greptype = "--grep=";
5103 } elsif ($searchtype eq 'author') {
5104 $greptype = "--author=";
5105 } elsif ($searchtype eq 'committer') {
5106 $greptype = "--committer=";
5108 $greptype .= $search_regexp;
5109 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5111 my $paging_nav = '';
5114 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5115 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5117 $paging_nav .= " ⋅ " .
5118 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5119 searchtext
=>$searchtext, searchtype
=>$searchtype,
5121 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5123 $paging_nav .= "first";
5124 $paging_nav .= " ⋅ prev";
5126 if ($#commitlist >= 100) {
5127 $paging_nav .= " ⋅ " .
5128 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5129 searchtext
=>$searchtext, searchtype
=>$searchtype,
5131 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5133 $paging_nav .= " ⋅ next";
5136 if ($#commitlist >= 100) {
5138 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5139 searchtext
=>$searchtext, searchtype
=>$searchtype,
5141 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5144 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5145 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5146 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5149 if ($searchtype eq 'pickaxe') {
5150 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5151 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5153 print "<table cellspacing=\"0\">\n";
5156 my $git_command = git_cmd_str
();
5157 my $searchqtext = $searchtext;
5158 $searchqtext =~ s/'/'\\''/;
5159 open my $fd, "-|", "$git_command rev-list $hash | " .
5160 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5163 while (my $line = <$fd>) {
5164 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5167 $set{'from_id'} = $3;
5169 $set{'id'} = $set{'to_id'};
5170 if ($set{'id'} =~ m/0{40}/) {
5171 $set{'id'} = $set{'from_id'};
5173 if ($set{'id'} =~ m/0{40}/) {
5177 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5180 print "<tr class=\"dark\">\n";
5182 print "<tr class=\"light\">\n";
5185 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5186 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5188 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5189 -class => "list subject"},
5190 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5191 while (my $setref = shift @files) {
5193 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5194 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5196 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5200 "<td class=\"link\">" .
5201 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5203 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5207 %co = parse_commit
($1);
5215 if ($searchtype eq 'grep') {
5216 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5217 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5219 print "<table cellspacing=\"0\">\n";
5223 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5225 while (my $line = <$fd>) {
5227 my ($file, $lno, $ltext, $binary);
5228 last if ($matches++ > 1000);
5229 if ($line =~ /^Binary file (.+) matches$/) {
5233 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5235 if ($file ne $lastfile) {
5236 $lastfile and print "</td></tr>\n";
5238 print "<tr class=\"dark\">\n";
5240 print "<tr class=\"light\">\n";
5242 print "<td class=\"list\">".
5243 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5244 file_name
=>"$file"),
5245 -class => "list"}, esc_path
($file));
5246 print "</td><td>\n";
5250 print "<div class=\"binary\">Binary file</div>\n";
5252 $ltext = untabify
($ltext);
5253 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5254 $ltext = esc_html
($1, -nbsp
=>1);
5255 $ltext .= '<span class="match">';
5256 $ltext .= esc_html
($2, -nbsp
=>1);
5257 $ltext .= '</span>';
5258 $ltext .= esc_html
($3, -nbsp
=>1);
5260 $ltext = esc_html
($ltext, -nbsp
=>1);
5262 print "<div class=\"pre\">" .
5263 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5264 file_name
=>"$file").'#l'.$lno,
5265 -class => "linenr"}, sprintf('%4i', $lno))
5266 . ' ' . $ltext . "</div>\n";
5270 print "</td></tr>\n";
5271 if ($matches > 1000) {
5272 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5275 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5284 sub git_search_help
{
5286 git_print_page_nav
('','', $hash,$hash,$hash);
5289 <dt><b>commit</b></dt>
5290 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5292 my ($have_grep) = gitweb_check_feature
('grep');
5295 <dt><b>grep</b></dt>
5296 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5297 a different one) are searched for the given
5298 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5299 (POSIX extended) and the matches are listed. On large
5300 trees, this search can take a while and put some strain on the server, so please use it with
5301 some consideration.</dd>
5305 <dt><b>author</b></dt>
5306 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5307 <dt><b>committer</b></dt>
5308 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5310 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5311 if ($have_pickaxe) {
5313 <dt><b>pickaxe</b></dt>
5314 <dd>All commits that caused the string to appear or disappear from any file (changes that
5315 added, removed or "modified" the string) will be listed. This search can take a while and
5316 takes a lot of strain on the server, so please use it wisely.</dd>
5324 my $head = git_get_head_hash
($project);
5325 if (!defined $hash) {
5328 if (!defined $page) {
5331 my $refs = git_get_references
();
5333 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5335 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5337 if ($#commitlist >= 100) {
5339 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5340 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5344 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5345 git_print_header_div
('summary', $project);
5347 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5352 ## ......................................................................
5353 ## feeds (RSS, Atom; OPML)
5356 my $format = shift || 'atom';
5357 my ($have_blame) = gitweb_check_feature
('blame');
5359 # Atom: http://www.atomenabled.org/developers/syndication/
5360 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5361 if ($format ne 'rss' && $format ne 'atom') {
5362 die_error
(undef, "Unknown web feed format");
5365 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5366 my $head = $hash || 'HEAD';
5367 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5371 my $content_type = "application/$format+xml";
5372 if (defined $cgi->http('HTTP_ACCEPT') &&
5373 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5374 # browser (feed reader) prefers text/xml
5375 $content_type = 'text/xml';
5377 if (defined($commitlist[0])) {
5378 %latest_commit = %{$commitlist[0]};
5379 %latest_date = parse_date
($latest_commit{'author_epoch'});
5381 -type
=> $content_type,
5382 -charset
=> 'utf-8',
5383 -last_modified
=> $latest_date{'rfc2822'});
5386 -type
=> $content_type,
5387 -charset
=> 'utf-8');
5390 # Optimization: skip generating the body if client asks only
5391 # for Last-Modified date.
5392 return if ($cgi->request_method() eq 'HEAD');
5395 my $title = "$site_name - $project/$action";
5396 my $feed_type = 'log';
5397 if (defined $hash) {
5398 $title .= " - '$hash'";
5399 $feed_type = 'branch log';
5400 if (defined $file_name) {
5401 $title .= " :: $file_name";
5402 $feed_type = 'history';
5404 } elsif (defined $file_name) {
5405 $title .= " - $file_name";
5406 $feed_type = 'history';
5408 $title .= " $feed_type";
5409 my $descr = git_get_project_description
($project);
5410 if (defined $descr) {
5411 $descr = esc_html
($descr);
5413 $descr = "$project " .
5414 ($format eq 'rss' ? 'RSS' : 'Atom') .
5417 my $owner = git_get_project_owner
($project);
5418 $owner = esc_html
($owner);
5422 if (defined $file_name) {
5423 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5424 } elsif (defined $hash) {
5425 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5427 $alt_url = href
(-full
=>1, action
=>"summary");
5429 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5430 if ($format eq 'rss') {
5432 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5435 print "<title>$title</title>\n" .
5436 "<link>$alt_url</link>\n" .
5437 "<description>$descr</description>\n" .
5438 "<language>en</language>\n";
5439 } elsif ($format eq 'atom') {
5441 <feed xmlns="http://www.w3.org/2005/Atom">
5443 print "<title>$title</title>\n" .
5444 "<subtitle>$descr</subtitle>\n" .
5445 '<link rel="alternate" type="text/html" href="' .
5446 $alt_url . '" />' . "\n" .
5447 '<link rel="self" type="' . $content_type . '" href="' .
5448 $cgi->self_url() . '" />' . "\n" .
5449 "<id>" . href
(-full
=>1) . "</id>\n" .
5450 # use project owner for feed author
5451 "<author><name>$owner</name></author>\n";
5452 if (defined $favicon) {
5453 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5455 if (defined $logo_url) {
5456 # not twice as wide as tall: 72 x 27 pixels
5457 print "<logo>" . esc_url
($logo) . "</logo>\n";
5459 if (! %latest_date) {
5460 # dummy date to keep the feed valid until commits trickle in:
5461 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5463 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5468 for (my $i = 0; $i <= $#commitlist; $i++) {
5469 my %co = %{$commitlist[$i]};
5470 my $commit = $co{'id'};
5471 # we read 150, we always show 30 and the ones more recent than 48 hours
5472 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5475 my %cd = parse_date
($co{'author_epoch'});
5477 # get list of changed files
5478 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5479 $co{'parent'} || "--root",
5480 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5482 my @difftree = map { chomp; $_ } <$fd>;
5486 # print element (entry, item)
5487 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5488 if ($format eq 'rss') {
5490 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5491 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5492 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5493 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5494 "<link>$co_url</link>\n" .
5495 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5496 "<content:encoded>" .
5498 } elsif ($format eq 'atom') {
5500 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5501 "<updated>$cd{'iso-8601'}</updated>\n" .
5503 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5504 if ($co{'author_email'}) {
5505 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5507 print "</author>\n" .
5508 # use committer for contributor
5510 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5511 if ($co{'committer_email'}) {
5512 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5514 print "</contributor>\n" .
5515 "<published>$cd{'iso-8601'}</published>\n" .
5516 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5517 "<id>$co_url</id>\n" .
5518 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5519 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5521 my $comment = $co{'comment'};
5523 foreach my $line (@$comment) {
5524 $line = esc_html
($line);
5527 print "</pre><ul>\n";
5528 foreach my $difftree_line (@difftree) {
5529 my %difftree = parse_difftree_raw_line
($difftree_line);
5530 next if !$difftree{'from_id'};
5532 my $file = $difftree{'file'} || $difftree{'to_file'};
5536 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5537 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5538 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5539 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5540 -title
=> "diff"}, 'D');
5542 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5543 file_name
=>$file, hash_base
=>$commit),
5544 -title
=> "blame"}, 'B');
5546 # if this is not a feed of a file history
5547 if (!defined $file_name || $file_name ne $file) {
5548 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5549 file_name
=>$file, hash
=>$commit),
5550 -title
=> "history"}, 'H');
5552 $file = esc_path
($file);
5556 if ($format eq 'rss') {
5557 print "</ul>]]>\n" .
5558 "</content:encoded>\n" .
5560 } elsif ($format eq 'atom') {
5561 print "</ul>\n</div>\n" .
5568 if ($format eq 'rss') {
5569 print "</channel>\n</rss>\n";
5570 } elsif ($format eq 'atom') {
5584 my @list = git_get_projects_list
();
5586 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5588 <?xml version="1.0" encoding="utf-8"?>
5589 <opml version="1.0">
5591 <title>$site_name OPML Export</title>
5594 <outline text="git RSS feeds">
5597 foreach my $pr (@list) {
5599 my $head = git_get_head_hash
($proj{'path'});
5600 if (!defined $head) {
5603 $git_dir = "$projectroot/$proj{'path'}";
5604 my %co = parse_commit
($head);
5609 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5610 my $rss = "$my_url?p=$proj{'path'};a=rss";
5611 my $html = "$my_url?p=$proj{'path'};a=summary";
5612 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";