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(@extra_options)
442 if (not grep(/^$_$/, keys %allowed_options)) {
443 die_error
(undef, "Invalid option parameter");
445 if (not grep(/^$action$/, @{$allowed_options{$_}})) {
446 die_error
(undef, "Invalid option parameter for this action");
451 our $hash_parent_base = $cgi->param('hpb');
452 if (defined $hash_parent_base) {
453 if (!validate_refname
($hash_parent_base)) {
454 die_error
(undef, "Invalid hash parent base parameter");
459 our $page = $cgi->param('pg');
461 if ($page =~ m/[^0-9]/) {
462 die_error
(undef, "Invalid page parameter");
466 our $searchtype = $cgi->param('st');
467 if (defined $searchtype) {
468 if ($searchtype =~ m/[^a-z]/) {
469 die_error
(undef, "Invalid searchtype parameter");
473 our $searchtext = $cgi->param('s');
475 if (defined $searchtext) {
476 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
477 die_error
(undef, "Invalid search parameter");
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
602 extra_options
=> "opt",
606 hash_parent_base
=> "hpb",
611 snapshot_format
=> "sf",
613 my %mapping = @mapping;
615 $params{'project'} = $project unless exists $params{'project'};
617 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
619 # use PATH_INFO for project name
620 $href .= "/$params{'project'}" if defined $params{'project'};
621 delete $params{'project'};
623 # Summary just uses the project path URL
624 if (defined $params{'action'} && $params{'action'} eq 'summary') {
625 delete $params{'action'};
629 # now encode the parameters explicitly
631 for (my $i = 0; $i < @mapping; $i += 2) {
632 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
633 if (defined $params{$name}) {
634 push @result, $symbol . "=" . esc_param
($params{$name});
637 $href .= "?" . join(';', @result) if scalar @result;
643 ## ======================================================================
644 ## validation, quoting/unquoting and escaping
646 sub validate_pathname
{
647 my $input = shift || return undef;
649 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
650 # at the beginning, at the end, and between slashes.
651 # also this catches doubled slashes
652 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
656 if ($input =~ m!\0!) {
662 sub validate_refname
{
663 my $input = shift || return undef;
665 # textual hashes are O.K.
666 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
669 # it must be correct pathname
670 $input = validate_pathname
($input)
672 # restrictions on ref name according to git-check-ref-format
673 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
679 # decode sequences of octets in utf8 into Perl's internal form,
680 # which is utf-8 with utf8 flag set if needed. gitweb writes out
681 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
685 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
689 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
693 # quote unsafe chars, but keep the slash, even when it's not
694 # correct, but quoted slashes look too horrible in bookmarks
697 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
703 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
706 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
712 # replace invalid utf8 character with SUBSTITUTION sequence
717 $str = to_utf8
($str);
718 $str = $cgi->escapeHTML($str);
719 if ($opts{'-nbsp'}) {
720 $str =~ s/ / /g;
722 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
726 # quote control characters and escape filename to HTML
731 $str = to_utf8
($str);
732 $str = $cgi->escapeHTML($str);
733 if ($opts{'-nbsp'}) {
734 $str =~ s/ / /g;
736 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
740 # Make control characters "printable", using character escape codes (CEC)
743 my %es = ( # character escape codes, aka escape sequences
744 "\t" => '\t', # tab (HT)
745 "\n" => '\n', # line feed (LF)
746 "\r" => '\r', # carrige return (CR)
747 "\f" => '\f', # form feed (FF)
748 "\b" => '\b', # backspace (BS)
749 "\a" => '\a', # alarm (bell) (BEL)
750 "\e" => '\e', # escape (ESC)
751 "\013" => '\v', # vertical tab (VT)
752 "\000" => '\0', # nul character (NUL)
754 my $chr = ( (exists $es{$cntrl})
756 : sprintf('\%03o', ord($cntrl)) );
757 return "<span class=\"cntrl\">$chr</span>";
760 # Alternatively use unicode control pictures codepoints,
761 # Unicode "printable representation" (PR)
764 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
765 return "<span class=\"cntrl\">$chr</span>";
768 # git may return quoted and escaped filenames
774 my %es = ( # character escape codes, aka escape sequences
775 't' => "\t", # tab (HT, TAB)
776 'n' => "\n", # newline (NL)
777 'r' => "\r", # return (CR)
778 'f' => "\f", # form feed (FF)
779 'b' => "\b", # backspace (BS)
780 'a' => "\a", # alarm (bell) (BEL)
781 'e' => "\e", # escape (ESC)
782 'v' => "\013", # vertical tab (VT)
785 if ($seq =~ m/^[0-7]{1,3}$/) {
786 # octal char sequence
787 return chr(oct($seq));
788 } elsif (exists $es{$seq}) {
789 # C escape sequence, aka character escape code
792 # quoted ordinary character
796 if ($str =~ m/^"(.*)"$/) {
799 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
804 # escape tabs (convert tabs to spaces)
808 while ((my $pos = index($line, "\t")) != -1) {
809 if (my $count = (8 - ($pos % 8))) {
810 my $spaces = ' ' x
$count;
811 $line =~ s/\t/$spaces/;
818 sub project_in_list
{
820 my @list = git_get_projects_list
();
821 return @list && scalar(grep { $_->{'path'} eq $project } @list);
824 ## ----------------------------------------------------------------------
825 ## HTML aware string manipulation
830 my $add_len = shift || 10;
832 # allow only $len chars, but don't cut a word if it would fit in $add_len
833 # if it doesn't fit, cut it if it's still longer than the dots we would add
834 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
837 if (length($tail) > 4) {
839 $body =~ s/&[^;]*$//; # remove chopped character entities
844 ## ----------------------------------------------------------------------
845 ## functions returning short strings
847 # CSS class for given age value (in seconds)
853 } elsif ($age < 60*60*2) {
855 } elsif ($age < 60*60*24*2) {
862 # convert age in seconds to "nn units ago" string
867 if ($age > 60*60*24*365*2) {
868 $age_str = (int $age/60/60/24/365);
869 $age_str .= " years ago";
870 } elsif ($age > 60*60*24*(365/12)*2) {
871 $age_str = int $age/60/60/24/(365/12);
872 $age_str .= " months ago";
873 } elsif ($age > 60*60*24*7*2) {
874 $age_str = int $age/60/60/24/7;
875 $age_str .= " weeks ago";
876 } elsif ($age > 60*60*24*2) {
877 $age_str = int $age/60/60/24;
878 $age_str .= " days ago";
879 } elsif ($age > 60*60*2) {
880 $age_str = int $age/60/60;
881 $age_str .= " hours ago";
882 } elsif ($age > 60*2) {
883 $age_str = int $age/60;
884 $age_str .= " min ago";
887 $age_str .= " sec ago";
889 $age_str .= " right now";
894 # convert file mode in octal to symbolic file mode string
896 my $mode = oct shift;
898 if (S_ISDIR
($mode & S_IFMT
)) {
900 } elsif (S_ISLNK
($mode)) {
902 } elsif (S_ISREG
($mode)) {
903 # git cares only about the executable bit
904 if ($mode & S_IXUSR
) {
914 # convert file mode in octal to file type string
918 if ($mode !~ m/^[0-7]+$/) {
924 if (S_ISDIR
($mode & S_IFMT
)) {
926 } elsif (S_ISLNK
($mode)) {
928 } elsif (S_ISREG
($mode)) {
935 # convert file mode in octal to file type description string
939 if ($mode !~ m/^[0-7]+$/) {
945 if (S_ISDIR
($mode & S_IFMT
)) {
947 } elsif (S_ISLNK
($mode)) {
949 } elsif (S_ISREG
($mode)) {
950 if ($mode & S_IXUSR
) {
961 ## ----------------------------------------------------------------------
962 ## functions returning short HTML fragments, or transforming HTML fragments
963 ## which don't belong to other sections
965 # format line of commit message.
966 sub format_log_line_html
{
969 $line = esc_html
($line, -nbsp
=>1);
970 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
973 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
974 -class => "text"}, $hash_text);
975 $line =~ s/$hash_text/$link/;
980 # format marker of refs pointing to given object
981 sub format_ref_marker
{
982 my ($refs, $id) = @_;
985 if (defined $refs->{$id}) {
986 foreach my $ref (@{$refs->{$id}}) {
987 my ($type, $name) = qw();
988 # e.g. tags/v2.6.11 or heads/next
989 if ($ref =~ m!^(.*?)s?/(.*)$!) {
997 $markers .= " <span class=\"$type\" title=\"$ref\">" .
998 esc_html
($name) . "</span>";
1003 return ' <span class="refs">'. $markers . '</span>';
1009 # format, perhaps shortened and with markers, title line
1010 sub format_subject_html
{
1011 my ($long, $short, $href, $extra) = @_;
1012 $extra = '' unless defined($extra);
1014 if (length($short) < length($long)) {
1015 return $cgi->a({-href
=> $href, -class => "list subject",
1016 -title
=> to_utf8
($long)},
1017 esc_html
($short) . $extra);
1019 return $cgi->a({-href
=> $href, -class => "list subject"},
1020 esc_html
($long) . $extra);
1024 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1025 sub format_git_diff_header_line
{
1027 my $diffinfo = shift;
1028 my ($from, $to) = @_;
1030 if ($diffinfo->{'nparents'}) {
1032 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1033 if ($to->{'href'}) {
1034 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1035 esc_path
($to->{'file'}));
1036 } else { # file was deleted (no href)
1037 $line .= esc_path
($to->{'file'});
1041 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1042 if ($from->{'href'}) {
1043 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1044 'a/' . esc_path
($from->{'file'}));
1045 } else { # file was added (no href)
1046 $line .= 'a/' . esc_path
($from->{'file'});
1049 if ($to->{'href'}) {
1050 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1051 'b/' . esc_path
($to->{'file'}));
1052 } else { # file was deleted
1053 $line .= 'b/' . esc_path
($to->{'file'});
1057 return "<div class=\"diff header\">$line</div>\n";
1060 # format extended diff header line, before patch itself
1061 sub format_extended_diff_header_line
{
1063 my $diffinfo = shift;
1064 my ($from, $to) = @_;
1067 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1068 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1069 esc_path
($from->{'file'}));
1071 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1072 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1073 esc_path
($to->{'file'}));
1075 # match single <mode>
1076 if ($line =~ m/\s(\d{6})$/) {
1077 $line .= '<span class="info"> (' .
1078 file_type_long
($1) .
1082 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1083 # can match only for combined diff
1085 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1086 if ($from->{'href'}[$i]) {
1087 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1089 substr($diffinfo->{'from_id'}[$i],0,7));
1094 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1097 if ($to->{'href'}) {
1098 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1099 substr($diffinfo->{'to_id'},0,7));
1104 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1105 # can match only for ordinary diff
1106 my ($from_link, $to_link);
1107 if ($from->{'href'}) {
1108 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1109 substr($diffinfo->{'from_id'},0,7));
1111 $from_link = '0' x
7;
1113 if ($to->{'href'}) {
1114 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1115 substr($diffinfo->{'to_id'},0,7));
1119 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1120 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1123 return $line . "<br/>\n";
1126 # format from-file/to-file diff header
1127 sub format_diff_from_to_header
{
1128 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1133 #assert($line =~ m/^---/) if DEBUG;
1134 # no extra formatting for "^--- /dev/null"
1135 if (! $diffinfo->{'nparents'}) {
1136 # ordinary (single parent) diff
1137 if ($line =~ m!^--- "?a/!) {
1138 if ($from->{'href'}) {
1140 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1141 esc_path
($from->{'file'}));
1144 esc_path
($from->{'file'});
1147 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1150 # combined diff (merge commit)
1151 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1152 if ($from->{'href'}[$i]) {
1154 $cgi->a({-href
=>href
(action
=>"blobdiff",
1155 hash_parent
=>$diffinfo->{'from_id'}[$i],
1156 hash_parent_base
=>$parents[$i],
1157 file_parent
=>$from->{'file'}[$i],
1158 hash
=>$diffinfo->{'to_id'},
1160 file_name
=>$to->{'file'}),
1162 -title
=>"diff" . ($i+1)},
1165 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1166 esc_path
($from->{'file'}[$i]));
1168 $line = '--- /dev/null';
1170 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1175 #assert($line =~ m/^\+\+\+/) if DEBUG;
1176 # no extra formatting for "^+++ /dev/null"
1177 if ($line =~ m!^\+\+\+ "?b/!) {
1178 if ($to->{'href'}) {
1180 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1181 esc_path
($to->{'file'}));
1184 esc_path
($to->{'file'});
1187 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1192 # create note for patch simplified by combined diff
1193 sub format_diff_cc_simplified
{
1194 my ($diffinfo, @parents) = @_;
1197 $result .= "<div class=\"diff header\">" .
1199 if (!is_deleted
($diffinfo)) {
1200 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1202 hash
=>$diffinfo->{'to_id'},
1203 file_name
=>$diffinfo->{'to_file'}),
1205 esc_path
($diffinfo->{'to_file'}));
1207 $result .= esc_path
($diffinfo->{'to_file'});
1209 $result .= "</div>\n" . # class="diff header"
1210 "<div class=\"diff nodifferences\">" .
1212 "</div>\n"; # class="diff nodifferences"
1217 # format patch (diff) line (not to be used for diff headers)
1218 sub format_diff_line
{
1220 my ($from, $to) = @_;
1221 my $diff_class = "";
1225 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1227 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1228 if ($line =~ m/^\@{3}/) {
1229 $diff_class = " chunk_header";
1230 } elsif ($line =~ m/^\\/) {
1231 $diff_class = " incomplete";
1232 } elsif ($prefix =~ tr/+/+/) {
1233 $diff_class = " add";
1234 } elsif ($prefix =~ tr/-/-/) {
1235 $diff_class = " rem";
1238 # assume ordinary diff
1239 my $char = substr($line, 0, 1);
1241 $diff_class = " add";
1242 } elsif ($char eq '-') {
1243 $diff_class = " rem";
1244 } elsif ($char eq '@') {
1245 $diff_class = " chunk_header";
1246 } elsif ($char eq "\\") {
1247 $diff_class = " incomplete";
1250 $line = untabify
($line);
1251 if ($from && $to && $line =~ m/^\@{2} /) {
1252 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1253 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1255 $from_lines = 0 unless defined $from_lines;
1256 $to_lines = 0 unless defined $to_lines;
1258 if ($from->{'href'}) {
1259 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1260 -class=>"list"}, $from_text);
1262 if ($to->{'href'}) {
1263 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1264 -class=>"list"}, $to_text);
1266 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1267 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1268 return "<div class=\"diff$diff_class\">$line</div>\n";
1269 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1270 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1271 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1273 @from_text = split(' ', $ranges);
1274 for (my $i = 0; $i < @from_text; ++$i) {
1275 ($from_start[$i], $from_nlines[$i]) =
1276 (split(',', substr($from_text[$i], 1)), 0);
1279 $to_text = pop @from_text;
1280 $to_start = pop @from_start;
1281 $to_nlines = pop @from_nlines;
1283 $line = "<span class=\"chunk_info\">$prefix ";
1284 for (my $i = 0; $i < @from_text; ++$i) {
1285 if ($from->{'href'}[$i]) {
1286 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1287 -class=>"list"}, $from_text[$i]);
1289 $line .= $from_text[$i];
1293 if ($to->{'href'}) {
1294 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1295 -class=>"list"}, $to_text);
1299 $line .= " $prefix</span>" .
1300 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1301 return "<div class=\"diff$diff_class\">$line</div>\n";
1303 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1306 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1307 # linked. Pass the hash of the tree/commit to snapshot.
1308 sub format_snapshot_links
{
1310 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1311 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1312 my $num_fmts = @snapshot_fmts;
1313 if ($num_fmts > 1) {
1314 # A parenthesized list of links bearing format names.
1315 # e.g. "snapshot (_tar.gz_ _zip_)"
1316 return "snapshot (" . join(' ', map
1323 }, $known_snapshot_formats{$_}{'display'})
1324 , @snapshot_fmts) . ")";
1325 } elsif ($num_fmts == 1) {
1326 # A single "snapshot" link whose tooltip bears the format name.
1328 my ($fmt) = @snapshot_fmts;
1334 snapshot_format
=>$fmt
1336 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1338 } else { # $num_fmts == 0
1343 ## ----------------------------------------------------------------------
1344 ## git utility subroutines, invoking git commands
1346 # returns path to the core git executable and the --git-dir parameter as list
1348 return $GIT, '--git-dir='.$git_dir;
1351 # returns path to the core git executable and the --git-dir parameter as string
1353 return join(' ', git_cmd
());
1356 # get HEAD ref of given project as hash
1357 sub git_get_head_hash
{
1358 my $project = shift;
1359 my $o_git_dir = $git_dir;
1361 $git_dir = "$projectroot/$project";
1362 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1365 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1369 if (defined $o_git_dir) {
1370 $git_dir = $o_git_dir;
1375 # get type of given object
1379 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1381 close $fd or return;
1386 sub git_get_project_config
{
1387 my ($key, $type) = @_;
1389 return unless ($key);
1390 $key =~ s/^gitweb\.//;
1391 return if ($key =~ m/\W/);
1393 my @x = (git_cmd
(), 'config');
1394 if (defined $type) { push @x, $type; }
1396 push @x, "gitweb.$key";
1402 # get hash of given path at given ref
1403 sub git_get_hash_by_path
{
1405 my $path = shift || return undef;
1410 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1411 or die_error
(undef, "Open git-ls-tree failed");
1413 close $fd or return undef;
1415 if (!defined $line) {
1416 # there is no tree or hash given by $path at $base
1420 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1421 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1422 if (defined $type && $type ne $2) {
1423 # type doesn't match
1429 # get path of entry with given hash at given tree-ish (ref)
1430 # used to get 'from' filename for combined diff (merge commit) for renames
1431 sub git_get_path_by_hash
{
1432 my $base = shift || return;
1433 my $hash = shift || return;
1437 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1439 while (my $line = <$fd>) {
1442 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1443 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1444 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1453 ## ......................................................................
1454 ## git utility functions, directly accessing git repository
1456 sub git_get_project_description
{
1459 open my $fd, "$projectroot/$path/description" or return undef;
1462 if (defined $descr) {
1468 sub git_get_project_url_list
{
1471 open my $fd, "$projectroot/$path/cloneurl" or return;
1472 my @git_project_url_list = map { chomp; $_ } <$fd>;
1475 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1478 sub git_get_projects_list
{
1483 $filter =~ s/\.git$//;
1485 my ($check_forks) = gitweb_check_feature
('forks');
1487 if (-d
$projects_list) {
1488 # search in directory
1489 my $dir = $projects_list . ($filter ? "/$filter" : '');
1490 # remove the trailing "/"
1492 my $pfxlen = length("$dir");
1495 follow_fast
=> 1, # follow symbolic links
1496 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1498 # skip project-list toplevel, if we get it.
1499 return if (m!^[/.]$!);
1500 # only directories can be git repositories
1501 return unless (-d
$_);
1503 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1504 # we check related file in $projectroot
1505 if ($check_forks and $subdir =~ m
#/.#) {
1506 $File::Find
::prune
= 1;
1507 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1508 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1509 $File::Find
::prune
= 1;
1514 } elsif (-f
$projects_list) {
1515 # read from file(url-encoded):
1516 # 'git%2Fgit.git Linus+Torvalds'
1517 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1518 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1520 open my ($fd), $projects_list or return;
1522 while (my $line = <$fd>) {
1524 my ($path, $owner) = split ' ', $line;
1525 $path = unescape
($path);
1526 $owner = unescape
($owner);
1527 if (!defined $path) {
1530 if ($filter ne '') {
1531 # looking for forks;
1532 my $pfx = substr($path, 0, length($filter));
1533 if ($pfx ne $filter) {
1536 my $sfx = substr($path, length($filter));
1537 if ($sfx !~ /^\/.*\
.git
$/) {
1540 } elsif ($check_forks) {
1542 foreach my $filter (keys %paths) {
1543 # looking for forks;
1544 my $pfx = substr($path, 0, length($filter));
1545 if ($pfx ne $filter) {
1548 my $sfx = substr($path, length($filter));
1549 if ($sfx !~ /^\/.*\
.git
$/) {
1552 # is a fork, don't include it in
1557 if (check_export_ok
("$projectroot/$path")) {
1560 owner
=> to_utf8
($owner),
1563 (my $forks_path = $path) =~ s/\.git$//;
1564 $paths{$forks_path}++;
1572 our $gitweb_project_owner = undef;
1573 sub git_get_project_list_from_file
{
1575 return if (defined $gitweb_project_owner);
1577 $gitweb_project_owner = {};
1578 # read from file (url-encoded):
1579 # 'git%2Fgit.git Linus+Torvalds'
1580 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1581 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1582 if (-f
$projects_list) {
1583 open (my $fd , $projects_list);
1584 while (my $line = <$fd>) {
1586 my ($pr, $ow) = split ' ', $line;
1587 $pr = unescape
($pr);
1588 $ow = unescape
($ow);
1589 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1595 sub git_get_project_owner
{
1596 my $project = shift;
1599 return undef unless $project;
1601 if (!defined $gitweb_project_owner) {
1602 git_get_project_list_from_file
();
1605 if (exists $gitweb_project_owner->{$project}) {
1606 $owner = $gitweb_project_owner->{$project};
1608 if (!defined $owner) {
1609 $owner = get_file_owner
("$projectroot/$project");
1615 sub git_get_last_activity
{
1619 $git_dir = "$projectroot/$path";
1620 open($fd, "-|", git_cmd
(), 'for-each-ref',
1621 '--format=%(committer)',
1622 '--sort=-committerdate',
1624 'refs/heads') or return;
1625 my $most_recent = <$fd>;
1626 close $fd or return;
1627 if (defined $most_recent &&
1628 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1630 my $age = time - $timestamp;
1631 return ($age, age_string
($age));
1633 return (undef, undef);
1636 sub git_get_references
{
1637 my $type = shift || "";
1639 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1640 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1641 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1642 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1645 while (my $line = <$fd>) {
1647 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1648 if (defined $refs{$1}) {
1649 push @{$refs{$1}}, $2;
1655 close $fd or return;
1659 sub git_get_rev_name_tags
{
1660 my $hash = shift || return undef;
1662 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1664 my $name_rev = <$fd>;
1667 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1670 # catches also '$hash undefined' output
1675 ## ----------------------------------------------------------------------
1676 ## parse to hash functions
1680 my $tz = shift || "-0000";
1683 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1684 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1685 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1686 $date{'hour'} = $hour;
1687 $date{'minute'} = $min;
1688 $date{'mday'} = $mday;
1689 $date{'day'} = $days[$wday];
1690 $date{'month'} = $months[$mon];
1691 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1692 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1693 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1694 $mday, $months[$mon], $hour ,$min;
1695 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1696 1900+$year, $mon, $mday, $hour ,$min, $sec;
1698 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1699 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1700 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1701 $date{'hour_local'} = $hour;
1702 $date{'minute_local'} = $min;
1703 $date{'tz_local'} = $tz;
1704 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1705 1900+$year, $mon+1, $mday,
1706 $hour, $min, $sec, $tz);
1715 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1716 $tag{'id'} = $tag_id;
1717 while (my $line = <$fd>) {
1719 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1720 $tag{'object'} = $1;
1721 } elsif ($line =~ m/^type (.+)$/) {
1723 } elsif ($line =~ m/^tag (.+)$/) {
1725 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1726 $tag{'author'} = $1;
1729 } elsif ($line =~ m/--BEGIN/) {
1730 push @comment, $line;
1732 } elsif ($line eq "") {
1736 push @comment, <$fd>;
1737 $tag{'comment'} = \
@comment;
1738 close $fd or return;
1739 if (!defined $tag{'name'}) {
1745 sub parse_commit_text
{
1746 my ($commit_text, $withparents) = @_;
1747 my @commit_lines = split '\n', $commit_text;
1750 pop @commit_lines; # Remove '\0'
1752 if (! @commit_lines) {
1756 my $header = shift @commit_lines;
1757 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1760 ($co{'id'}, my @parents) = split ' ', $header;
1761 while (my $line = shift @commit_lines) {
1762 last if $line eq "\n";
1763 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1765 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1767 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1769 $co{'author_epoch'} = $2;
1770 $co{'author_tz'} = $3;
1771 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1772 $co{'author_name'} = $1;
1773 $co{'author_email'} = $2;
1775 $co{'author_name'} = $co{'author'};
1777 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1778 $co{'committer'} = $1;
1779 $co{'committer_epoch'} = $2;
1780 $co{'committer_tz'} = $3;
1781 $co{'committer_name'} = $co{'committer'};
1782 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1783 $co{'committer_name'} = $1;
1784 $co{'committer_email'} = $2;
1786 $co{'committer_name'} = $co{'committer'};
1790 if (!defined $co{'tree'}) {
1793 $co{'parents'} = \
@parents;
1794 $co{'parent'} = $parents[0];
1796 foreach my $title (@commit_lines) {
1799 $co{'title'} = chop_str
($title, 80, 5);
1800 # remove leading stuff of merges to make the interesting part visible
1801 if (length($title) > 50) {
1802 $title =~ s/^Automatic //;
1803 $title =~ s/^merge (of|with) /Merge ... /i;
1804 if (length($title) > 50) {
1805 $title =~ s/(http|rsync):\/\///;
1807 if (length($title) > 50) {
1808 $title =~ s/(master|www|rsync)\.//;
1810 if (length($title) > 50) {
1811 $title =~ s/kernel.org:?//;
1813 if (length($title) > 50) {
1814 $title =~ s/\/pub\/scm//;
1817 $co{'title_short'} = chop_str
($title, 50, 5);
1821 if ($co{'title'} eq "") {
1822 $co{'title'} = $co{'title_short'} = '(no commit message)';
1824 # remove added spaces
1825 foreach my $line (@commit_lines) {
1828 $co{'comment'} = \
@commit_lines;
1830 my $age = time - $co{'committer_epoch'};
1832 $co{'age_string'} = age_string
($age);
1833 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1834 if ($age > 60*60*24*7*2) {
1835 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1836 $co{'age_string_age'} = $co{'age_string'};
1838 $co{'age_string_date'} = $co{'age_string'};
1839 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1845 my ($commit_id) = @_;
1850 open my $fd, "-|", git_cmd
(), "rev-list",
1856 or die_error
(undef, "Open git-rev-list failed");
1857 %co = parse_commit_text
(<$fd>, 1);
1864 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1872 open my $fd, "-|", git_cmd
(), "rev-list",
1874 ($arg ? ($arg) : ()),
1875 ("--max-count=" . $maxcount),
1876 ("--skip=" . $skip),
1880 ($filename ? ($filename) : ())
1881 or die_error
(undef, "Open git-rev-list failed");
1882 while (my $line = <$fd>) {
1883 my %co = parse_commit_text
($line);
1888 return wantarray ? @cos : \
@cos;
1891 # parse ref from ref_file, given by ref_id, with given type
1893 my $ref_file = shift;
1895 my $type = shift || git_get_type
($ref_id);
1898 $ref_item{'type'} = $type;
1899 $ref_item{'id'} = $ref_id;
1900 $ref_item{'epoch'} = 0;
1901 $ref_item{'age'} = "unknown";
1902 if ($type eq "tag") {
1903 my %tag = parse_tag
($ref_id);
1904 $ref_item{'comment'} = $tag{'comment'};
1905 if ($tag{'type'} eq "commit") {
1906 my %co = parse_commit
($tag{'object'});
1907 $ref_item{'epoch'} = $co{'committer_epoch'};
1908 $ref_item{'age'} = $co{'age_string'};
1909 } elsif (defined($tag{'epoch'})) {
1910 my $age = time - $tag{'epoch'};
1911 $ref_item{'epoch'} = $tag{'epoch'};
1912 $ref_item{'age'} = age_string
($age);
1914 $ref_item{'reftype'} = $tag{'type'};
1915 $ref_item{'name'} = $tag{'name'};
1916 $ref_item{'refid'} = $tag{'object'};
1917 } elsif ($type eq "commit"){
1918 my %co = parse_commit
($ref_id);
1919 $ref_item{'reftype'} = "commit";
1920 $ref_item{'name'} = $ref_file;
1921 $ref_item{'title'} = $co{'title'};
1922 $ref_item{'refid'} = $ref_id;
1923 $ref_item{'epoch'} = $co{'committer_epoch'};
1924 $ref_item{'age'} = $co{'age_string'};
1926 $ref_item{'reftype'} = $type;
1927 $ref_item{'name'} = $ref_file;
1928 $ref_item{'refid'} = $ref_id;
1934 # parse line of git-diff-tree "raw" output
1935 sub parse_difftree_raw_line
{
1939 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1940 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1941 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1942 $res{'from_mode'} = $1;
1943 $res{'to_mode'} = $2;
1944 $res{'from_id'} = $3;
1946 $res{'status'} = $5;
1947 $res{'similarity'} = $6;
1948 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1949 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1951 $res{'file'} = unquote
($7);
1954 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1955 # combined diff (for merge commit)
1956 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1957 $res{'nparents'} = length($1);
1958 $res{'from_mode'} = [ split(' ', $2) ];
1959 $res{'to_mode'} = pop @{$res{'from_mode'}};
1960 $res{'from_id'} = [ split(' ', $3) ];
1961 $res{'to_id'} = pop @{$res{'from_id'}};
1962 $res{'status'} = [ split('', $4) ];
1963 $res{'to_file'} = unquote
($5);
1965 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1966 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1967 $res{'commit'} = $1;
1970 return wantarray ? %res : \
%res;
1973 # parse line of git-ls-tree output
1974 sub parse_ls_tree_line
($;%) {
1979 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1980 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1988 $res{'name'} = unquote
($4);
1991 return wantarray ? %res : \
%res;
1994 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1995 sub parse_from_to_diffinfo
{
1996 my ($diffinfo, $from, $to, @parents) = @_;
1998 if ($diffinfo->{'nparents'}) {
2000 $from->{'file'} = [];
2001 $from->{'href'} = [];
2002 fill_from_file_info
($diffinfo, @parents)
2003 unless exists $diffinfo->{'from_file'};
2004 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2005 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2006 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2007 $from->{'href'}[$i] = href
(action
=>"blob",
2008 hash_base
=>$parents[$i],
2009 hash
=>$diffinfo->{'from_id'}[$i],
2010 file_name
=>$from->{'file'}[$i]);
2012 $from->{'href'}[$i] = undef;
2016 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2017 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2018 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2019 hash
=>$diffinfo->{'from_id'},
2020 file_name
=>$from->{'file'});
2022 delete $from->{'href'};
2026 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2027 if (!is_deleted
($diffinfo)) { # file exists in result
2028 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2029 hash
=>$diffinfo->{'to_id'},
2030 file_name
=>$to->{'file'});
2032 delete $to->{'href'};
2036 ## ......................................................................
2037 ## parse to array of hashes functions
2039 sub git_get_heads_list
{
2043 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2044 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2045 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2048 while (my $line = <$fd>) {
2052 my ($refinfo, $committerinfo) = split(/\0/, $line);
2053 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2054 my ($committer, $epoch, $tz) =
2055 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2056 $name =~ s!^refs/heads/!!;
2058 $ref_item{'name'} = $name;
2059 $ref_item{'id'} = $hash;
2060 $ref_item{'title'} = $title || '(no commit message)';
2061 $ref_item{'epoch'} = $epoch;
2063 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2065 $ref_item{'age'} = "unknown";
2068 push @headslist, \
%ref_item;
2072 return wantarray ? @headslist : \
@headslist;
2075 sub git_get_tags_list
{
2079 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2080 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2081 '--format=%(objectname) %(objecttype) %(refname) '.
2082 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2085 while (my $line = <$fd>) {
2089 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2090 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2091 my ($creator, $epoch, $tz) =
2092 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2093 $name =~ s!^refs/tags/!!;
2095 $ref_item{'type'} = $type;
2096 $ref_item{'id'} = $id;
2097 $ref_item{'name'} = $name;
2098 if ($type eq "tag") {
2099 $ref_item{'subject'} = $title;
2100 $ref_item{'reftype'} = $reftype;
2101 $ref_item{'refid'} = $refid;
2103 $ref_item{'reftype'} = $type;
2104 $ref_item{'refid'} = $id;
2107 if ($type eq "tag" || $type eq "commit") {
2108 $ref_item{'epoch'} = $epoch;
2110 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2112 $ref_item{'age'} = "unknown";
2116 push @tagslist, \
%ref_item;
2120 return wantarray ? @tagslist : \
@tagslist;
2123 ## ----------------------------------------------------------------------
2124 ## filesystem-related functions
2126 sub get_file_owner
{
2129 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2130 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2131 if (!defined $gcos) {
2135 $owner =~ s/[,;].*$//;
2136 return to_utf8
($owner);
2139 ## ......................................................................
2140 ## mimetype related functions
2142 sub mimetype_guess_file
{
2143 my $filename = shift;
2144 my $mimemap = shift;
2145 -r
$mimemap or return undef;
2148 open(MIME
, $mimemap) or return undef;
2150 next if m/^#/; # skip comments
2151 my ($mime, $exts) = split(/\t+/);
2152 if (defined $exts) {
2153 my @exts = split(/\s+/, $exts);
2154 foreach my $ext (@exts) {
2155 $mimemap{$ext} = $mime;
2161 $filename =~ /\.([^.]*)$/;
2162 return $mimemap{$1};
2165 sub mimetype_guess
{
2166 my $filename = shift;
2168 $filename =~ /\./ or return undef;
2170 if ($mimetypes_file) {
2171 my $file = $mimetypes_file;
2172 if ($file !~ m!^/!) { # if it is relative path
2173 # it is relative to project
2174 $file = "$projectroot/$project/$file";
2176 $mime = mimetype_guess_file
($filename, $file);
2178 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2184 my $filename = shift;
2187 my $mime = mimetype_guess
($filename);
2188 $mime and return $mime;
2192 return $default_blob_plain_mimetype unless $fd;
2195 return 'text/plain' .
2196 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2197 } elsif (! $filename) {
2198 return 'application/octet-stream';
2199 } elsif ($filename =~ m/\.png$/i) {
2201 } elsif ($filename =~ m/\.gif$/i) {
2203 } elsif ($filename =~ m/\.jpe?g$/i) {
2204 return 'image/jpeg';
2206 return 'application/octet-stream';
2210 ## ======================================================================
2211 ## functions printing HTML: header, footer, error page
2213 sub git_header_html
{
2214 my $status = shift || "200 OK";
2215 my $expires = shift;
2217 my $title = "$site_name";
2218 if (defined $project) {
2219 $title .= " - " . to_utf8
($project);
2220 if (defined $action) {
2221 $title .= "/$action";
2222 if (defined $file_name) {
2223 $title .= " - " . esc_path
($file_name);
2224 if ($action eq "tree" && $file_name !~ m
|/$|) {
2231 # require explicit support from the UA if we are to send the page as
2232 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2233 # we have to do this because MSIE sometimes globs '*/*', pretending to
2234 # support xhtml+xml but choking when it gets what it asked for.
2235 if (defined $cgi->http('HTTP_ACCEPT') &&
2236 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2237 $cgi->Accept('application/xhtml+xml') != 0) {
2238 $content_type = 'application/xhtml+xml';
2240 $content_type = 'text/html';
2242 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2243 -status
=> $status, -expires
=> $expires);
2244 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2246 <?xml version="1.0" encoding="utf-8"?>
2247 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2248 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2249 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2250 <!-- git core binaries version $git_version -->
2252 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2253 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2254 <meta name="robots" content="index, nofollow"/>
2255 <title>$title</title>
2257 # print out each stylesheet that exist
2258 if (defined $stylesheet) {
2259 #provides backwards capability for those people who define style sheet in a config file
2260 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2262 foreach my $stylesheet (@stylesheets) {
2263 next unless $stylesheet;
2264 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2267 if (defined $project) {
2268 printf('<link rel="alternate" title="%s log RSS feed" '.
2269 'href="%s" type="application/rss+xml" />'."\n",
2270 esc_param
($project), href
(action
=>"rss"));
2271 printf('<link rel="alternate" title="%s log Atom feed" '.
2272 'href="%s" type="application/atom+xml" />'."\n",
2273 esc_param
($project), href
(action
=>"atom"));
2275 printf('<link rel="alternate" title="%s projects list" '.
2276 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2277 $site_name, href
(project
=>undef, action
=>"project_index"));
2278 printf('<link rel="alternate" title="%s projects feeds" '.
2279 'href="%s" type="text/x-opml"/>'."\n",
2280 $site_name, href
(project
=>undef, action
=>"opml"));
2282 if (defined $favicon) {
2283 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2289 if (-f
$site_header) {
2290 open (my $fd, $site_header);
2295 print "<div class=\"page_header\">\n" .
2296 $cgi->a({-href
=> esc_url
($logo_url),
2297 -title
=> $logo_label},
2298 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2299 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2300 if (defined $project) {
2301 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2302 if (defined $action) {
2309 my ($have_search) = gitweb_check_feature
('search');
2310 if ((defined $project) && ($have_search)) {
2311 if (!defined $searchtext) {
2315 if (defined $hash_base) {
2316 $search_hash = $hash_base;
2317 } elsif (defined $hash) {
2318 $search_hash = $hash;
2320 $search_hash = "HEAD";
2322 my $action = $my_uri;
2323 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2324 if ($use_pathinfo) {
2325 $action .= "/$project";
2327 $cgi->param("p", $project);
2329 $cgi->param("a", "search");
2330 $cgi->param("h", $search_hash);
2331 print $cgi->startform(-method => "get", -action
=> $action) .
2332 "<div class=\"search\">\n" .
2333 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2334 $cgi->hidden(-name
=> "a") . "\n" .
2335 $cgi->hidden(-name
=> "h") . "\n" .
2336 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2337 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2338 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2340 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2342 $cgi->end_form() . "\n";
2346 sub git_footer_html
{
2347 print "<div class=\"page_footer\">\n";
2348 if (defined $project) {
2349 my $descr = git_get_project_description
($project);
2350 if (defined $descr) {
2351 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2353 print $cgi->a({-href
=> href
(action
=>"rss"),
2354 -class => "rss_logo"}, "RSS") . " ";
2355 print $cgi->a({-href
=> href
(action
=>"atom"),
2356 -class => "rss_logo"}, "Atom") . "\n";
2358 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2359 -class => "rss_logo"}, "OPML") . " ";
2360 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2361 -class => "rss_logo"}, "TXT") . "\n";
2365 if (-f
$site_footer) {
2366 open (my $fd, $site_footer);
2376 my $status = shift || "403 Forbidden";
2377 my $error = shift || "Malformed query, file missing or permission denied";
2379 git_header_html
($status);
2381 <div class="page_body">
2391 ## ----------------------------------------------------------------------
2392 ## functions printing or outputting HTML: navigation
2394 sub git_print_page_nav
{
2395 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2396 $extra = '' if !defined $extra; # pager or formats
2398 my @navs = qw(summary shortlog log commit commitdiff tree);
2400 @navs = grep { $_ ne $suppress } @navs;
2403 my %arg = map { $_ => {action
=>$_} } @navs;
2404 if (defined $head) {
2405 for (qw(commit commitdiff)) {
2406 $arg{$_}{'hash'} = $head;
2408 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2409 for (qw(shortlog log)) {
2410 $arg{$_}{'hash'} = $head;
2414 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2415 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2417 print "<div class=\"page_nav\">\n" .
2419 map { $_ eq $current ?
2420 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2422 print "<br/>\n$extra<br/>\n" .
2426 sub format_paging_nav
{
2427 my ($action, $hash, $head, $page, $nrevs) = @_;
2431 if ($hash ne $head || $page) {
2432 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2434 $paging_nav .= "HEAD";
2438 $paging_nav .= " ⋅ " .
2439 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2440 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2442 $paging_nav .= " ⋅ prev";
2445 if ($nrevs >= (100 * ($page+1)-1)) {
2446 $paging_nav .= " ⋅ " .
2447 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2448 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2450 $paging_nav .= " ⋅ next";
2456 ## ......................................................................
2457 ## functions printing or outputting HTML: div
2459 sub git_print_header_div
{
2460 my ($action, $title, $hash, $hash_base) = @_;
2463 $args{'action'} = $action;
2464 $args{'hash'} = $hash if $hash;
2465 $args{'hash_base'} = $hash_base if $hash_base;
2467 print "<div class=\"header\">\n" .
2468 $cgi->a({-href
=> href
(%args), -class => "title"},
2469 $title ? $title : $action) .
2473 #sub git_print_authorship (\%) {
2474 sub git_print_authorship
{
2477 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2478 print "<div class=\"author_date\">" .
2479 esc_html
($co->{'author_name'}) .
2481 if ($ad{'hour_local'} < 6) {
2482 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2483 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2485 printf(" (%02d:%02d %s)",
2486 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2491 sub git_print_page_path
{
2497 print "<div class=\"page_path\">";
2498 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2499 -title
=> 'tree root'}, to_utf8
("[$project]"));
2501 if (defined $name) {
2502 my @dirname = split '/', $name;
2503 my $basename = pop @dirname;
2506 foreach my $dir (@dirname) {
2507 $fullname .= ($fullname ? '/' : '') . $dir;
2508 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2510 -title
=> $fullname}, esc_path
($dir));
2513 if (defined $type && $type eq 'blob') {
2514 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2516 -title
=> $name}, esc_path
($basename));
2517 } elsif (defined $type && $type eq 'tree') {
2518 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2520 -title
=> $name}, esc_path
($basename));
2523 print esc_path
($basename);
2526 print "<br/></div>\n";
2529 # sub git_print_log (\@;%) {
2530 sub git_print_log
($;%) {
2534 if ($opts{'-remove_title'}) {
2535 # remove title, i.e. first line of log
2538 # remove leading empty lines
2539 while (defined $log->[0] && $log->[0] eq "") {
2546 foreach my $line (@$log) {
2547 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2550 if (! $opts{'-remove_signoff'}) {
2551 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2554 # remove signoff lines
2561 # print only one empty line
2562 # do not print empty line after signoff
2564 next if ($empty || $signoff);
2570 print format_log_line_html
($line) . "<br/>\n";
2573 if ($opts{'-final_empty_line'}) {
2574 # end with single empty line
2575 print "<br/>\n" unless $empty;
2579 # return link target (what link points to)
2580 sub git_get_link_target
{
2585 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2589 $link_target = <$fd>;
2594 return $link_target;
2597 # given link target, and the directory (basedir) the link is in,
2598 # return target of link relative to top directory (top tree);
2599 # return undef if it is not possible (including absolute links).
2600 sub normalize_link_target
{
2601 my ($link_target, $basedir, $hash_base) = @_;
2603 # we can normalize symlink target only if $hash_base is provided
2604 return unless $hash_base;
2606 # absolute symlinks (beginning with '/') cannot be normalized
2607 return if (substr($link_target, 0, 1) eq '/');
2609 # normalize link target to path from top (root) tree (dir)
2612 $path = $basedir . '/' . $link_target;
2614 # we are in top (root) tree (dir)
2615 $path = $link_target;
2618 # remove //, /./, and /../
2620 foreach my $part (split('/', $path)) {
2621 # discard '.' and ''
2622 next if (!$part || $part eq '.');
2624 if ($part eq '..') {
2628 # link leads outside repository (outside top dir)
2632 push @path_parts, $part;
2635 $path = join('/', @path_parts);
2640 # print tree entry (row of git_tree), but without encompassing <tr> element
2641 sub git_print_tree_entry
{
2642 my ($t, $basedir, $hash_base, $have_blame) = @_;
2645 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2647 # The format of a table row is: mode list link. Where mode is
2648 # the mode of the entry, list is the name of the entry, an href,
2649 # and link is the action links of the entry.
2651 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2652 if ($t->{'type'} eq "blob") {
2653 print "<td class=\"list\">" .
2654 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2655 file_name
=>"$basedir$t->{'name'}", %base_key),
2656 -class => "list"}, esc_path
($t->{'name'}));
2657 if (S_ISLNK
(oct $t->{'mode'})) {
2658 my $link_target = git_get_link_target
($t->{'hash'});
2660 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2661 if (defined $norm_target) {
2663 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2664 file_name
=>$norm_target),
2665 -title
=> $norm_target}, esc_path
($link_target));
2667 print " -> " . esc_path
($link_target);
2672 print "<td class=\"link\">";
2673 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2674 file_name
=>"$basedir$t->{'name'}", %base_key)},
2678 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2679 file_name
=>"$basedir$t->{'name'}", %base_key)},
2682 if (defined $hash_base) {
2684 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2685 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2689 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2690 file_name
=>"$basedir$t->{'name'}")},
2694 } elsif ($t->{'type'} eq "tree") {
2695 print "<td class=\"list\">";
2696 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2697 file_name
=>"$basedir$t->{'name'}", %base_key)},
2698 esc_path
($t->{'name'}));
2700 print "<td class=\"link\">";
2701 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2702 file_name
=>"$basedir$t->{'name'}", %base_key)},
2704 if (defined $hash_base) {
2706 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2707 file_name
=>"$basedir$t->{'name'}")},
2714 ## ......................................................................
2715 ## functions printing large fragments of HTML
2717 sub fill_from_file_info
{
2718 my ($diff, @parents) = @_;
2720 $diff->{'from_file'} = [ ];
2721 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2722 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2723 if ($diff->{'status'}[$i] eq 'R' ||
2724 $diff->{'status'}[$i] eq 'C') {
2725 $diff->{'from_file'}[$i] =
2726 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2733 # parameters can be strings, or references to arrays of strings
2737 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2738 for (my $i = 0; $i < @$a; ++$i) {
2739 return 0 unless ($a->[$i] eq $b->[$i]);
2742 } elsif (!ref($a) && !ref($b)) {
2750 my $diffinfo = shift;
2752 return $diffinfo->{'to_id'} eq ('0' x
40);
2755 sub git_difftree_body
{
2756 my ($difftree, $hash, @parents) = @_;
2757 my ($parent) = $parents[0];
2758 my ($have_blame) = gitweb_check_feature
('blame');
2759 print "<div class=\"list_head\">\n";
2760 if ($#{$difftree} > 10) {
2761 print(($#{$difftree} + 1) . " files changed:\n");
2765 print "<table class=\"" .
2766 (@parents > 1 ? "combined " : "") .
2769 # header only for combined diff in 'commitdiff' view
2770 my $has_header = @parents > 1 && $action eq 'commitdiff';
2773 print "<thead><tr>\n" .
2774 "<th></th><th></th>\n"; # filename, patchN link
2775 for (my $i = 0; $i < @parents; $i++) {
2776 my $par = $parents[$i];
2778 $cgi->a({-href
=> href
(action
=>"commitdiff",
2779 hash
=>$hash, hash_parent
=>$par),
2780 -title
=> 'commitdiff to parent number ' .
2781 ($i+1) . ': ' . substr($par,0,7)},
2785 print "</tr></thead>\n<tbody>\n";
2790 foreach my $line (@{$difftree}) {
2792 if (ref($line) eq "HASH") {
2793 # pre-parsed (or generated by hand)
2796 $diff = parse_difftree_raw_line
($line);
2800 print "<tr class=\"dark\">\n";
2802 print "<tr class=\"light\">\n";
2806 if (exists $diff->{'nparents'}) { # combined diff
2808 fill_from_file_info
($diff, @parents)
2809 unless exists $diff->{'from_file'};
2811 if (!is_deleted
($diff)) {
2812 # file exists in the result (child) commit
2814 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2815 file_name
=>$diff->{'to_file'},
2817 -class => "list"}, esc_path
($diff->{'to_file'})) .
2821 esc_path
($diff->{'to_file'}) .
2825 if ($action eq 'commitdiff') {
2828 print "<td class=\"link\">" .
2829 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2834 my $has_history = 0;
2835 my $not_deleted = 0;
2836 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2837 my $hash_parent = $parents[$i];
2838 my $from_hash = $diff->{'from_id'}[$i];
2839 my $from_path = $diff->{'from_file'}[$i];
2840 my $status = $diff->{'status'}[$i];
2842 $has_history ||= ($status ne 'A');
2843 $not_deleted ||= ($status ne 'D');
2845 if ($status eq 'A') {
2846 print "<td class=\"link\" align=\"right\"> | </td>\n";
2847 } elsif ($status eq 'D') {
2848 print "<td class=\"link\">" .
2849 $cgi->a({-href
=> href
(action
=>"blob",
2852 file_name
=>$from_path)},
2856 if ($diff->{'to_id'} eq $from_hash) {
2857 print "<td class=\"link nochange\">";
2859 print "<td class=\"link\">";
2861 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2862 hash
=>$diff->{'to_id'},
2863 hash_parent
=>$from_hash,
2865 hash_parent_base
=>$hash_parent,
2866 file_name
=>$diff->{'to_file'},
2867 file_parent
=>$from_path)},
2873 print "<td class=\"link\">";
2875 print $cgi->a({-href
=> href
(action
=>"blob",
2876 hash
=>$diff->{'to_id'},
2877 file_name
=>$diff->{'to_file'},
2880 print " | " if ($has_history);
2883 print $cgi->a({-href
=> href
(action
=>"history",
2884 file_name
=>$diff->{'to_file'},
2891 next; # instead of 'else' clause, to avoid extra indent
2893 # else ordinary diff
2895 my ($to_mode_oct, $to_mode_str, $to_file_type);
2896 my ($from_mode_oct, $from_mode_str, $from_file_type);
2897 if ($diff->{'to_mode'} ne ('0' x
6)) {
2898 $to_mode_oct = oct $diff->{'to_mode'};
2899 if (S_ISREG
($to_mode_oct)) { # only for regular file
2900 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2902 $to_file_type = file_type
($diff->{'to_mode'});
2904 if ($diff->{'from_mode'} ne ('0' x
6)) {
2905 $from_mode_oct = oct $diff->{'from_mode'};
2906 if (S_ISREG
($to_mode_oct)) { # only for regular file
2907 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2909 $from_file_type = file_type
($diff->{'from_mode'});
2912 if ($diff->{'status'} eq "A") { # created
2913 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2914 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2915 $mode_chng .= "]</span>";
2917 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2918 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2919 -class => "list"}, esc_path
($diff->{'file'}));
2921 print "<td>$mode_chng</td>\n";
2922 print "<td class=\"link\">";
2923 if ($action eq 'commitdiff') {
2926 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2929 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2930 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2934 } elsif ($diff->{'status'} eq "D") { # deleted
2935 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2937 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2938 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2939 -class => "list"}, esc_path
($diff->{'file'}));
2941 print "<td>$mode_chng</td>\n";
2942 print "<td class=\"link\">";
2943 if ($action eq 'commitdiff') {
2946 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2949 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2950 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2953 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2954 file_name
=>$diff->{'file'})},
2957 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2958 file_name
=>$diff->{'file'})},
2962 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2963 my $mode_chnge = "";
2964 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2965 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2966 if ($from_file_type ne $to_file_type) {
2967 $mode_chnge .= " from $from_file_type to $to_file_type";
2969 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2970 if ($from_mode_str && $to_mode_str) {
2971 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2972 } elsif ($to_mode_str) {
2973 $mode_chnge .= " mode: $to_mode_str";
2976 $mode_chnge .= "]</span>\n";
2979 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2980 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2981 -class => "list"}, esc_path
($diff->{'file'}));
2983 print "<td>$mode_chnge</td>\n";
2984 print "<td class=\"link\">";
2985 if ($action eq 'commitdiff') {
2988 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2990 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2991 # "commit" view and modified file (not onlu mode changed)
2992 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2993 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2994 hash_base
=>$hash, hash_parent_base
=>$parent,
2995 file_name
=>$diff->{'file'})},
2999 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3000 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3003 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3004 file_name
=>$diff->{'file'})},
3007 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3008 file_name
=>$diff->{'file'})},
3012 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3013 my %status_name = ('R' => 'moved', 'C' => 'copied');
3014 my $nstatus = $status_name{$diff->{'status'}};
3016 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3017 # mode also for directories, so we cannot use $to_mode_str
3018 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3021 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3022 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3023 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3024 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3025 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3026 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3027 -class => "list"}, esc_path
($diff->{'from_file'})) .
3028 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3029 "<td class=\"link\">";
3030 if ($action eq 'commitdiff') {
3033 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3035 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3036 # "commit" view and modified file (not only pure rename or copy)
3037 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3038 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3039 hash_base
=>$hash, hash_parent_base
=>$parent,
3040 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3044 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3045 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3048 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3049 file_name
=>$diff->{'to_file'})},
3052 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3053 file_name
=>$diff->{'to_file'})},
3057 } # we should not encounter Unmerged (U) or Unknown (X) status
3060 print "</tbody>" if $has_header;
3064 sub git_patchset_body
{
3065 my ($fd, $difftree, $hash, @hash_parents) = @_;
3066 my ($hash_parent) = $hash_parents[0];
3069 my $patch_number = 0;
3074 print "<div class=\"patchset\">\n";
3076 # skip to first patch
3077 while ($patch_line = <$fd>) {
3080 last if ($patch_line =~ m/^diff /);
3084 while ($patch_line) {
3086 my ($from_id, $to_id);
3089 #assert($patch_line =~ m/^diff /) if DEBUG;
3090 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3092 push @diff_header, $patch_line;
3094 # extended diff header
3096 while ($patch_line = <$fd>) {
3099 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3101 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3104 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3105 $from_id = [ split(',', $1) ];
3109 push @diff_header, $patch_line;
3111 my $last_patch_line = $patch_line;
3113 # check if current patch belong to current raw line
3114 # and parse raw git-diff line if needed
3115 if (defined $diffinfo &&
3116 defined $from_id && defined $to_id &&
3117 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3118 $diffinfo->{'to_id'} eq $to_id) {
3119 # this is continuation of a split patch
3120 print "<div class=\"patch cont\">\n";
3122 # advance raw git-diff output if needed
3123 $patch_idx++ if defined $diffinfo;
3125 # compact combined diff output can have some patches skipped
3126 # find which patch (using pathname of result) we are at now
3128 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3133 # read and prepare patch information
3134 if (ref($difftree->[$patch_idx]) eq "HASH") {
3135 # pre-parsed (or generated by hand)
3136 $diffinfo = $difftree->[$patch_idx];
3138 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3141 # check if current raw line has no patch (it got simplified)
3142 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3143 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3144 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3145 "</div>\n"; # class="patch"
3150 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3151 $patch_idx > $#$difftree);
3152 # modifies %from, %to hashes
3153 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3154 if ($diffinfo->{'nparents'}) {
3158 fill_from_file_info
($diffinfo, @hash_parents)
3159 unless exists $diffinfo->{'from_file'};
3160 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3161 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3162 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3163 $from{'href'}[$i] = href
(action
=>"blob",
3164 hash_base
=>$hash_parents[$i],
3165 hash
=>$diffinfo->{'from_id'}[$i],
3166 file_name
=>$from{'file'}[$i]);
3168 $from{'href'}[$i] = undef;
3172 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3173 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3174 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3175 hash
=>$diffinfo->{'from_id'},
3176 file_name
=>$from{'file'});
3178 delete $from{'href'};
3182 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3183 if (!is_deleted
($diffinfo)) { # file exists in result
3184 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3185 hash
=>$diffinfo->{'to_id'},
3186 file_name
=>$to{'file'});
3190 # this is first patch for raw difftree line with $patch_idx index
3191 # we index @$difftree array from 0, but number patches from 1
3192 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3195 # print "git diff" header
3196 $patch_line = shift @diff_header;
3197 print format_git_diff_header_line
($patch_line, $diffinfo,
3200 # print extended diff header
3201 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3203 foreach $patch_line (@diff_header) {
3204 print format_extended_diff_header_line
($patch_line, $diffinfo,
3207 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3209 # from-file/to-file diff header
3210 $patch_line = $last_patch_line;
3211 if (! $patch_line) {
3212 print "</div>\n"; # class="patch"
3215 next PATCH
if ($patch_line =~ m/^diff /);
3216 #assert($patch_line =~ m/^---/) if DEBUG;
3217 #assert($patch_line eq $last_patch_line) if DEBUG;
3219 $patch_line = <$fd>;
3221 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3223 print format_diff_from_to_header
($last_patch_line, $patch_line,
3224 $diffinfo, \
%from, \
%to,
3229 while ($patch_line = <$fd>) {
3232 next PATCH
if ($patch_line =~ m/^diff /);
3234 print format_diff_line
($patch_line, \
%from, \
%to);
3238 print "</div>\n"; # class="patch"
3241 # for compact combined (--cc) format, with chunk and patch simpliciaction
3242 # patchset might be empty, but there might be unprocessed raw lines
3243 for ($patch_idx++ if $patch_number > 0;
3244 $patch_idx < @$difftree;
3246 # read and prepare patch information
3247 if (ref($difftree->[$patch_idx]) eq "HASH") {
3248 # pre-parsed (or generated by hand)
3249 $diffinfo = $difftree->[$patch_idx];
3251 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3254 # generate anchor for "patch" links in difftree / whatchanged part
3255 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3256 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3257 "</div>\n"; # class="patch"
3262 if ($patch_number == 0) {
3263 if (@hash_parents > 1) {
3264 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3266 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3270 print "</div>\n"; # class="patchset"
3273 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3275 sub git_project_list_body
{
3276 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3278 my ($check_forks) = gitweb_check_feature
('forks');
3281 foreach my $pr (@$projlist) {
3282 my (@aa) = git_get_last_activity
($pr->{'path'});
3286 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3287 if (!defined $pr->{'descr'}) {
3288 my $descr = git_get_project_description
($pr->{'path'}) || "";
3289 $pr->{'descr_long'} = to_utf8
($descr);
3290 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3292 if (!defined $pr->{'owner'}) {
3293 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3296 my $pname = $pr->{'path'};
3297 if (($pname =~ s/\.git$//) &&
3298 ($pname !~ /\/$/) &&
3299 (-d
"$projectroot/$pname")) {
3300 $pr->{'forks'} = "-d $projectroot/$pname";
3306 push @projects, $pr;
3309 $order ||= $default_projects_order;
3310 $from = 0 unless defined $from;
3311 $to = $#projects if (!defined $to || $#projects < $to);
3313 print "<table class=\"project_list\">\n";
3314 unless ($no_header) {
3317 print "<th></th>\n";
3319 if ($order eq "project") {
3320 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3321 print "<th>Project</th>\n";
3324 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3325 -class => "header"}, "Project") .
3328 if ($order eq "descr") {
3329 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3330 print "<th>Description</th>\n";
3333 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3334 -class => "header"}, "Description") .
3337 if ($order eq "owner") {
3338 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3339 print "<th>Owner</th>\n";
3342 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3343 -class => "header"}, "Owner") .
3346 if ($order eq "age") {
3347 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3348 print "<th>Last Change</th>\n";
3351 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3352 -class => "header"}, "Last Change") .
3355 print "<th></th>\n" .
3359 for (my $i = $from; $i <= $to; $i++) {
3360 my $pr = $projects[$i];
3362 print "<tr class=\"dark\">\n";
3364 print "<tr class=\"light\">\n";
3369 if ($pr->{'forks'}) {
3370 print "<!-- $pr->{'forks'} -->\n";
3371 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3375 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3376 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3377 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3378 -class => "list", -title
=> $pr->{'descr_long'}},
3379 esc_html
($pr->{'descr'})) . "</td>\n" .
3380 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3381 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3382 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3383 "<td class=\"link\">" .
3384 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3385 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3386 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3387 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3388 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3392 if (defined $extra) {
3395 print "<td></td>\n";
3397 print "<td colspan=\"5\">$extra</td>\n" .
3403 sub git_shortlog_body
{
3404 # uses global variable $project
3405 my ($commitlist, $from, $to, $refs, $extra) = @_;
3407 $from = 0 unless defined $from;
3408 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3410 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3412 for (my $i = $from; $i <= $to; $i++) {
3413 my %co = %{$commitlist->[$i]};
3414 my $commit = $co{'id'};
3415 my $ref = format_ref_marker
($refs, $commit);
3417 print "<tr class=\"dark\">\n";
3419 print "<tr class=\"light\">\n";
3422 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3423 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3424 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3426 print format_subject_html
($co{'title'}, $co{'title_short'},
3427 href
(action
=>"commit", hash
=>$commit), $ref);
3429 "<td class=\"link\">" .
3430 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3431 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3432 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3433 my $snapshot_links = format_snapshot_links
($commit);
3434 if (defined $snapshot_links) {
3435 print " | " . $snapshot_links;
3440 if (defined $extra) {
3442 "<td colspan=\"4\">$extra</td>\n" .
3448 sub git_history_body
{
3449 # Warning: assumes constant type (blob or tree) during history
3450 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3452 $from = 0 unless defined $from;
3453 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3455 print "<table class=\"history\" cellspacing=\"0\">\n";
3457 for (my $i = $from; $i <= $to; $i++) {
3458 my %co = %{$commitlist->[$i]};
3462 my $commit = $co{'id'};
3464 my $ref = format_ref_marker
($refs, $commit);
3467 print "<tr class=\"dark\">\n";
3469 print "<tr class=\"light\">\n";
3472 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3473 # shortlog uses chop_str($co{'author_name'}, 10)
3474 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3476 # originally git_history used chop_str($co{'title'}, 50)
3477 print format_subject_html
($co{'title'}, $co{'title_short'},
3478 href
(action
=>"commit", hash
=>$commit), $ref);
3480 "<td class=\"link\">" .
3481 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3482 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3484 if ($ftype eq 'blob') {
3485 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3486 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3487 if (defined $blob_current && defined $blob_parent &&
3488 $blob_current ne $blob_parent) {
3490 $cgi->a({-href
=> href
(action
=>"blobdiff",
3491 hash
=>$blob_current, hash_parent
=>$blob_parent,
3492 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3493 file_name
=>$file_name)},
3500 if (defined $extra) {
3502 "<td colspan=\"4\">$extra</td>\n" .
3509 # uses global variable $project
3510 my ($taglist, $from, $to, $extra) = @_;
3511 $from = 0 unless defined $from;
3512 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3514 print "<table class=\"tags\" cellspacing=\"0\">\n";
3516 for (my $i = $from; $i <= $to; $i++) {
3517 my $entry = $taglist->[$i];
3519 my $comment = $tag{'subject'};
3521 if (defined $comment) {
3522 $comment_short = chop_str
($comment, 30, 5);
3525 print "<tr class=\"dark\">\n";
3527 print "<tr class=\"light\">\n";
3530 if (defined $tag{'age'}) {
3531 print "<td><i>$tag{'age'}</i></td>\n";
3533 print "<td></td>\n";
3536 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3537 -class => "list name"}, esc_html
($tag{'name'})) .
3540 if (defined $comment) {
3541 print format_subject_html
($comment, $comment_short,
3542 href
(action
=>"tag", hash
=>$tag{'id'}));
3545 "<td class=\"selflink\">";
3546 if ($tag{'type'} eq "tag") {
3547 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3552 "<td class=\"link\">" . " | " .
3553 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3554 if ($tag{'reftype'} eq "commit") {
3555 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3556 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3557 } elsif ($tag{'reftype'} eq "blob") {
3558 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3563 if (defined $extra) {
3565 "<td colspan=\"5\">$extra</td>\n" .
3571 sub git_heads_body
{
3572 # uses global variable $project
3573 my ($headlist, $head, $from, $to, $extra) = @_;
3574 $from = 0 unless defined $from;
3575 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3577 print "<table class=\"heads\" cellspacing=\"0\">\n";
3579 for (my $i = $from; $i <= $to; $i++) {
3580 my $entry = $headlist->[$i];
3582 my $curr = $ref{'id'} eq $head;
3584 print "<tr class=\"dark\">\n";
3586 print "<tr class=\"light\">\n";
3589 print "<td><i>$ref{'age'}</i></td>\n" .
3590 ($curr ? "<td class=\"current_head\">" : "<td>") .
3591 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3592 -class => "list name"},esc_html
($ref{'name'})) .
3594 "<td class=\"link\">" .
3595 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3596 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3597 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3601 if (defined $extra) {
3603 "<td colspan=\"3\">$extra</td>\n" .
3609 sub git_search_grep_body
{
3610 my ($commitlist, $from, $to, $extra) = @_;
3611 $from = 0 unless defined $from;
3612 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3614 print "<table class=\"grep\" cellspacing=\"0\">\n";
3616 for (my $i = $from; $i <= $to; $i++) {
3617 my %co = %{$commitlist->[$i]};
3621 my $commit = $co{'id'};
3623 print "<tr class=\"dark\">\n";
3625 print "<tr class=\"light\">\n";
3628 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3629 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3631 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3632 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3633 my $comment = $co{'comment'};
3634 foreach my $line (@$comment) {
3635 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3636 my $lead = esc_html
($1) || "";
3637 $lead = chop_str
($lead, 30, 10);
3638 my $match = esc_html
($2) || "";
3639 my $trail = esc_html
($3) || "";
3640 $trail = chop_str
($trail, 30, 10);
3641 my $text = "$lead<span class=\"match\">$match</span>$trail";
3642 print chop_str
($text, 80, 5) . "<br/>\n";
3646 "<td class=\"link\">" .
3647 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3649 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3653 if (defined $extra) {
3655 "<td colspan=\"3\">$extra</td>\n" .
3661 ## ======================================================================
3662 ## ======================================================================
3665 sub git_project_list
{
3666 my $order = $cgi->param('o');
3667 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3668 die_error
(undef, "Unknown order parameter");
3671 my @list = git_get_projects_list
();
3673 die_error
(undef, "No projects found");
3677 if (-f
$home_text) {
3678 print "<div class=\"index_include\">\n";
3679 open (my $fd, $home_text);
3684 git_project_list_body
(\
@list, $order);
3689 my $order = $cgi->param('o');
3690 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3691 die_error
(undef, "Unknown order parameter");
3694 my @list = git_get_projects_list
($project);
3696 die_error
(undef, "No forks found");
3700 git_print_page_nav
('','');
3701 git_print_header_div
('summary', "$project forks");
3702 git_project_list_body
(\
@list, $order);
3706 sub git_project_index
{
3707 my @projects = git_get_projects_list
($project);
3710 -type
=> 'text/plain',
3711 -charset
=> 'utf-8',
3712 -content_disposition
=> 'inline; filename="index.aux"');
3714 foreach my $pr (@projects) {
3715 if (!exists $pr->{'owner'}) {
3716 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3719 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3720 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3721 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3722 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3726 print "$path $owner\n";
3731 my $descr = git_get_project_description
($project) || "none";
3732 my %co = parse_commit
("HEAD");
3733 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3734 my $head = $co{'id'};
3736 my $owner = git_get_project_owner
($project);
3738 my $refs = git_get_references
();
3739 # These get_*_list functions return one more to allow us to see if
3740 # there are more ...
3741 my @taglist = git_get_tags_list
(16);
3742 my @headlist = git_get_heads_list
(16);
3744 my ($check_forks) = gitweb_check_feature
('forks');
3747 @forklist = git_get_projects_list
($project);
3751 git_print_page_nav
('summary','', $head);
3753 print "<div class=\"title\"> </div>\n";
3754 print "<table cellspacing=\"0\">\n" .
3755 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3756 "<tr><td>owner</td><td>$owner</td></tr>\n";
3757 if (defined $cd{'rfc2822'}) {
3758 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3761 # use per project git URL list in $projectroot/$project/cloneurl
3762 # or make project git URL from git base URL and project name
3763 my $url_tag = "URL";
3764 my @url_list = git_get_project_url_list
($project);
3765 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3766 foreach my $git_url (@url_list) {
3767 next unless $git_url;
3768 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3773 if (-s
"$projectroot/$project/README.html") {
3774 if (open my $fd, "$projectroot/$project/README.html") {
3775 print "<div class=\"title\">readme</div>\n";
3776 print $_ while (<$fd>);
3781 # we need to request one more than 16 (0..15) to check if
3783 my @commitlist = $head ? parse_commits
($head, 17) : ();
3785 git_print_header_div
('shortlog');
3786 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3787 $#commitlist <= 15 ? undef :
3788 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3792 git_print_header_div
('tags');
3793 git_tags_body
(\
@taglist, 0, 15,
3794 $#taglist <= 15 ? undef :
3795 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3799 git_print_header_div
('heads');
3800 git_heads_body
(\
@headlist, $head, 0, 15,
3801 $#headlist <= 15 ? undef :
3802 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3806 git_print_header_div
('forks');
3807 git_project_list_body
(\
@forklist, undef, 0, 15,
3808 $#forklist <= 15 ? undef :
3809 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3817 my $head = git_get_head_hash
($project);
3819 git_print_page_nav
('','', $head,undef,$head);
3820 my %tag = parse_tag
($hash);
3823 die_error
(undef, "Unknown tag object");
3826 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3827 print "<div class=\"title_text\">\n" .
3828 "<table cellspacing=\"0\">\n" .
3830 "<td>object</td>\n" .
3831 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3832 $tag{'object'}) . "</td>\n" .
3833 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3834 $tag{'type'}) . "</td>\n" .
3836 if (defined($tag{'author'})) {
3837 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3838 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3839 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3840 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3843 print "</table>\n\n" .
3845 print "<div class=\"page_body\">";
3846 my $comment = $tag{'comment'};
3847 foreach my $line (@$comment) {
3849 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3859 my ($have_blame) = gitweb_check_feature
('blame');
3861 die_error
('403 Permission denied', "Permission denied");
3863 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3864 $hash_base ||= git_get_head_hash
($project);
3865 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3866 my %co = parse_commit
($hash_base)
3867 or die_error
(undef, "Reading commit failed");
3868 if (!defined $hash) {
3869 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3870 or die_error
(undef, "Error looking up file");
3872 $ftype = git_get_type
($hash);
3873 if ($ftype !~ "blob") {
3874 die_error
('400 Bad Request', "Object is not a blob");
3876 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3877 $file_name, $hash_base)
3878 or die_error
(undef, "Open git-blame failed");
3881 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3884 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3887 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3889 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3890 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3891 git_print_page_path
($file_name, $ftype, $hash_base);
3892 my @rev_color = (qw(light2 dark2));
3893 my $num_colors = scalar(@rev_color);
3894 my $current_color = 0;
3897 <div class="page_body">
3898 <table class="blame">
3899 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3904 last unless defined $_;
3905 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3906 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3907 if (!exists $metainfo{$full_rev}) {
3908 $metainfo{$full_rev} = {};
3910 my $meta = $metainfo{$full_rev};
3913 if (/^(\S+) (.*)$/) {
3919 my $rev = substr($full_rev, 0, 8);
3920 my $author = $meta->{'author'};
3921 my %date = parse_date
($meta->{'author-time'},
3922 $meta->{'author-tz'});
3923 my $date = $date{'iso-tz'};
3925 $current_color = ++$current_color % $num_colors;
3927 print "<tr class=\"$rev_color[$current_color]\">\n";
3929 print "<td class=\"sha1\"";
3930 print " title=\"". esc_html
($author) . ", $date\"";
3931 print " rowspan=\"$group_size\"" if ($group_size > 1);
3933 print $cgi->a({-href
=> href
(action
=>"commit",
3935 file_name
=>$file_name)},
3939 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3940 or die_error
(undef, "Open git-rev-parse failed");
3941 my $parent_commit = <$dd>;
3943 chomp($parent_commit);
3944 my $blamed = href
(action
=> 'blame',
3945 file_name
=> $meta->{'filename'},
3946 hash_base
=> $parent_commit);
3947 print "<td class=\"linenr\">";
3948 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3950 -class => "linenr" },
3953 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3959 or print "Reading blob failed\n";
3966 my ($have_blame) = gitweb_check_feature
('blame');
3968 die_error
('403 Permission denied', "Permission denied");
3970 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3971 $hash_base ||= git_get_head_hash
($project);
3972 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3973 my %co = parse_commit
($hash_base)
3974 or die_error
(undef, "Reading commit failed");
3975 if (!defined $hash) {
3976 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3977 or die_error
(undef, "Error lookup file");
3979 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3980 or die_error
(undef, "Open git-annotate failed");
3983 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3986 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3989 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3991 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3992 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3993 git_print_page_path
($file_name, 'blob', $hash_base);
3994 print "<div class=\"page_body\">\n";
3996 <table class="blame">
4005 my @line_class = (qw(light dark));
4006 my $line_class_len = scalar (@line_class);
4007 my $line_class_num = $#line_class;
4008 while (my $line = <$fd>) {
4020 $line_class_num = ($line_class_num + 1) % $line_class_len;
4022 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4029 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4032 $short_rev = substr ($long_rev, 0, 8);
4033 $age = time () - $time;
4034 $age_str = age_string
($age);
4035 $age_str =~ s/ / /g;
4036 $age_class = age_class
($age);
4037 $author = esc_html
($author);
4038 $author =~ s/ / /g;
4040 $data = untabify
($data);
4041 $data = esc_html
($data);
4044 <tr class="$line_class[$line_class_num]">
4045 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4046 <td class="$age_class">$age_str</td>
4048 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4049 <td class="pre">$data</td>
4052 } # while (my $line = <$fd>)
4053 print "</table>\n\n";
4055 or print "Reading blob failed.\n";
4061 my $head = git_get_head_hash
($project);
4063 git_print_page_nav
('','', $head,undef,$head);
4064 git_print_header_div
('summary', $project);
4066 my @tagslist = git_get_tags_list
();
4068 git_tags_body
(\
@tagslist);
4074 my $head = git_get_head_hash
($project);
4076 git_print_page_nav
('','', $head,undef,$head);
4077 git_print_header_div
('summary', $project);
4079 my @headslist = git_get_heads_list
();
4081 git_heads_body
(\
@headslist, $head);
4086 sub git_blob_plain
{
4089 if (!defined $hash) {
4090 if (defined $file_name) {
4091 my $base = $hash_base || git_get_head_hash
($project);
4092 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4093 or die_error
(undef, "Error lookup file");
4095 die_error
(undef, "No file name defined");
4097 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4098 # blobs defined by non-textual hash id's can be cached
4103 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4104 or die_error
(undef, "Couldn't cat $file_name, $hash");
4106 $type ||= blob_mimetype
($fd, $file_name);
4108 # save as filename, even when no $file_name is given
4109 my $save_as = "$hash";
4110 if (defined $file_name) {
4111 $save_as = $file_name;
4112 } elsif ($type =~ m/^text\//) {
4119 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4121 binmode STDOUT
, ':raw';
4123 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4131 if (!defined $hash) {
4132 if (defined $file_name) {
4133 my $base = $hash_base || git_get_head_hash
($project);
4134 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4135 or die_error
(undef, "Error lookup file");
4137 die_error
(undef, "No file name defined");
4139 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4140 # blobs defined by non-textual hash id's can be cached
4144 my ($have_blame) = gitweb_check_feature
('blame');
4145 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4146 or die_error
(undef, "Couldn't cat $file_name, $hash");
4147 my $mimetype = blob_mimetype
($fd, $file_name);
4148 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4150 return git_blob_plain
($mimetype);
4152 # we can have blame only for text/* mimetype
4153 $have_blame &&= ($mimetype =~ m!^text/!);
4155 git_header_html
(undef, $expires);
4156 my $formats_nav = '';
4157 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4158 if (defined $file_name) {
4161 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4162 hash
=>$hash, file_name
=>$file_name)},
4167 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4168 hash
=>$hash, file_name
=>$file_name)},
4171 $cgi->a({-href
=> href
(action
=>"blob_plain",
4172 hash
=>$hash, file_name
=>$file_name)},
4175 $cgi->a({-href
=> href
(action
=>"blob",
4176 hash_base
=>"HEAD", file_name
=>$file_name)},
4180 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4182 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4183 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4185 print "<div class=\"page_nav\">\n" .
4186 "<br/><br/></div>\n" .
4187 "<div class=\"title\">$hash</div>\n";
4189 git_print_page_path
($file_name, "blob", $hash_base);
4190 print "<div class=\"page_body\">\n";
4191 if ($mimetype =~ m!^text/!) {
4193 while (my $line = <$fd>) {
4196 $line = untabify
($line);
4197 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4198 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4200 } elsif ($mimetype =~ m!^image/!) {
4201 print qq
!<img type
="$mimetype"!;
4203 print qq
! alt
="$file_name" title
="$file_name"!;
4206 href(action=>"blob_plain
", hash=>$hash,
4207 hash_base=>$hash_base, file_name=>$file_name) .
4211 or print "Reading blob failed.\n";
4217 if (!defined $hash_base) {
4218 $hash_base = "HEAD";
4220 if (!defined $hash) {
4221 if (defined $file_name) {
4222 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4228 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4229 or die_error
(undef, "Open git-ls-tree failed");
4230 my @entries = map { chomp; $_ } <$fd>;
4231 close $fd or die_error
(undef, "Reading tree failed");
4234 my $refs = git_get_references
();
4235 my $ref = format_ref_marker
($refs, $hash_base);
4238 my ($have_blame) = gitweb_check_feature
('blame');
4239 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4241 if (defined $file_name) {
4243 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4244 hash
=>$hash, file_name
=>$file_name)},
4246 $cgi->a({-href
=> href
(action
=>"tree",
4247 hash_base
=>"HEAD", file_name
=>$file_name)},
4250 my $snapshot_links = format_snapshot_links
($hash);
4251 if (defined $snapshot_links) {
4252 # FIXME: Should be available when we have no hash base as well.
4253 push @views_nav, $snapshot_links;
4255 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4256 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4259 print "<div class=\"page_nav\">\n";
4260 print "<br/><br/></div>\n";
4261 print "<div class=\"title\">$hash</div>\n";
4263 if (defined $file_name) {
4264 $basedir = $file_name;
4265 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4269 git_print_page_path
($file_name, 'tree', $hash_base);
4270 print "<div class=\"page_body\">\n";
4271 print "<table cellspacing=\"0\">\n";
4273 # '..' (top directory) link if possible
4274 if (defined $hash_base &&
4275 defined $file_name && $file_name =~ m![^/]+$!) {
4277 print "<tr class=\"dark\">\n";
4279 print "<tr class=\"light\">\n";
4283 my $up = $file_name;
4284 $up =~ s!/?[^/]+$!!;
4285 undef $up unless $up;
4286 # based on git_print_tree_entry
4287 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4288 print '<td class="list">';
4289 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4293 print "<td class=\"link\"></td>\n";
4297 foreach my $line (@entries) {
4298 my %t = parse_ls_tree_line
($line, -z
=> 1);
4301 print "<tr class=\"dark\">\n";
4303 print "<tr class=\"light\">\n";
4307 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4311 print "</table>\n" .
4317 my @supported_fmts = gitweb_check_feature
('snapshot');
4318 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4320 my $format = $cgi->param('sf');
4321 unless ($format =~ m/[a-z0-9]+/
4322 && exists($known_snapshot_formats{$format})
4323 && grep($_ eq $format, @supported_fmts)) {
4324 die_error
(undef, "Unsupported snapshot format");
4327 if (!defined $hash) {
4328 $hash = git_get_head_hash
($project);
4331 my $git_command = git_cmd_str
();
4332 my $name = $project;
4333 $name =~ s
,([^/])/*\
.git
$,$1,;
4334 $name = basename
($name);
4335 my $filename = to_utf8
($name);
4336 $name =~ s/\047/\047\\\047\047/g;
4338 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4339 $cmd = "$git_command archive " .
4340 "--format=$known_snapshot_formats{$format}{'format'}" .
4341 "--prefix=\'$name\'/ $hash";
4342 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4343 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4347 -type
=> $known_snapshot_formats{$format}{'type'},
4348 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4349 -status
=> '200 OK');
4351 open my $fd, "-|", $cmd
4352 or die_error
(undef, "Execute git-archive failed");
4353 binmode STDOUT
, ':raw';
4355 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4360 my $head = git_get_head_hash
($project);
4361 if (!defined $hash) {
4364 if (!defined $page) {
4367 my $refs = git_get_references
();
4369 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4371 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4374 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4377 my %co = parse_commit
($hash);
4379 git_print_header_div
('summary', $project);
4380 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4382 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4383 for (my $i = 0; $i <= $to; $i++) {
4384 my %co = %{$commitlist[$i]};
4386 my $commit = $co{'id'};
4387 my $ref = format_ref_marker
($refs, $commit);
4388 my %ad = parse_date
($co{'author_epoch'});
4389 git_print_header_div
('commit',
4390 "<span class=\"age\">$co{'age_string'}</span>" .
4391 esc_html
($co{'title'}) . $ref,
4393 print "<div class=\"title_text\">\n" .
4394 "<div class=\"log_link\">\n" .
4395 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4397 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4399 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4402 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4405 print "<div class=\"log_body\">\n";
4406 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4409 if ($#commitlist >= 100) {
4410 print "<div class=\"page_nav\">\n";
4411 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4412 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4419 $hash ||= $hash_base || "HEAD";
4420 my %co = parse_commit
($hash);
4422 die_error
(undef, "Unknown commit object");
4424 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4425 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4427 my $parent = $co{'parent'};
4428 my $parents = $co{'parents'}; # listref
4430 # we need to prepare $formats_nav before any parameter munging
4432 if (!defined $parent) {
4434 $formats_nav .= '(initial)';
4435 } elsif (@$parents == 1) {
4436 # single parent commit
4439 $cgi->a({-href
=> href
(action
=>"commit",
4441 esc_html
(substr($parent, 0, 7))) .
4448 $cgi->a({-href
=> href
(action
=>"commit",
4450 esc_html
(substr($_, 0, 7)));
4455 if (!defined $parent) {
4459 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4461 (@$parents <= 1 ? $parent : '-c'),
4463 or die_error
(undef, "Open git-diff-tree failed");
4464 @difftree = map { chomp; $_ } <$fd>;
4465 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4467 # non-textual hash id's can be cached
4469 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4472 my $refs = git_get_references
();
4473 my $ref = format_ref_marker
($refs, $co{'id'});
4475 git_header_html
(undef, $expires);
4476 git_print_page_nav
('commit', '',
4477 $hash, $co{'tree'}, $hash,
4480 if (defined $co{'parent'}) {
4481 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4483 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4485 print "<div class=\"title_text\">\n" .
4486 "<table cellspacing=\"0\">\n";
4487 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4489 "<td></td><td> $ad{'rfc2822'}";
4490 if ($ad{'hour_local'} < 6) {
4491 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4492 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4494 printf(" (%02d:%02d %s)",
4495 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4499 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4500 print "<tr><td></td><td> $cd{'rfc2822'}" .
4501 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4503 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4506 "<td class=\"sha1\">" .
4507 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4508 class => "list"}, $co{'tree'}) .
4510 "<td class=\"link\">" .
4511 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4513 my $snapshot_links = format_snapshot_links
($hash);
4514 if (defined $snapshot_links) {
4515 print " | " . $snapshot_links;
4520 foreach my $par (@$parents) {
4523 "<td class=\"sha1\">" .
4524 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4525 class => "list"}, $par) .
4527 "<td class=\"link\">" .
4528 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4530 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4537 print "<div class=\"page_body\">\n";
4538 git_print_log
($co{'comment'});
4541 git_difftree_body
(\
@difftree, $hash, @$parents);
4547 # object is defined by:
4548 # - hash or hash_base alone
4549 # - hash_base and file_name
4552 # - hash or hash_base alone
4553 if ($hash || ($hash_base && !defined $file_name)) {
4554 my $object_id = $hash || $hash_base;
4556 my $git_command = git_cmd_str
();
4557 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4558 or die_error
('404 Not Found', "Object does not exist");
4562 or die_error
('404 Not Found', "Object does not exist");
4564 # - hash_base and file_name
4565 } elsif ($hash_base && defined $file_name) {
4566 $file_name =~ s
,/+$,,;
4568 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4569 or die_error
('404 Not Found', "Base object does not exist");
4571 # here errors should not hapen
4572 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4573 or die_error
(undef, "Open git-ls-tree failed");
4577 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4578 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4579 die_error
('404 Not Found', "File or directory for given base does not exist");
4584 die_error
('404 Not Found', "Not enough information to find object");
4587 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4588 hash
=>$hash, hash_base
=>$hash_base,
4589 file_name
=>$file_name),
4590 -status
=> '302 Found');
4594 my $format = shift || 'html';
4601 # preparing $fd and %diffinfo for git_patchset_body
4603 if (defined $hash_base && defined $hash_parent_base) {
4604 if (defined $file_name) {
4606 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4607 $hash_parent_base, $hash_base,
4608 "--", (defined $file_parent ? $file_parent : ()), $file_name
4609 or die_error
(undef, "Open git-diff-tree failed");
4610 @difftree = map { chomp; $_ } <$fd>;
4612 or die_error
(undef, "Reading git-diff-tree failed");
4614 or die_error
('404 Not Found', "Blob diff not found");
4616 } elsif (defined $hash &&
4617 $hash =~ /[0-9a-fA-F]{40}/) {
4618 # try to find filename from $hash
4620 # read filtered raw output
4621 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4622 $hash_parent_base, $hash_base, "--"
4623 or die_error
(undef, "Open git-diff-tree failed");
4625 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4627 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4628 map { chomp; $_ } <$fd>;
4630 or die_error
(undef, "Reading git-diff-tree failed");
4632 or die_error
('404 Not Found', "Blob diff not found");
4635 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4638 if (@difftree > 1) {
4639 die_error
('404 Not Found', "Ambiguous blob diff specification");
4642 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4643 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4644 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4646 $hash_parent ||= $diffinfo{'from_id'};
4647 $hash ||= $diffinfo{'to_id'};
4649 # non-textual hash id's can be cached
4650 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4651 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4656 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4657 '-p', ($format eq 'html' ? "--full-index" : ()),
4658 $hash_parent_base, $hash_base,
4659 "--", (defined $file_parent ? $file_parent : ()), $file_name
4660 or die_error
(undef, "Open git-diff-tree failed");
4663 # old/legacy style URI
4664 if (!%diffinfo && # if new style URI failed
4665 defined $hash && defined $hash_parent) {
4666 # fake git-diff-tree raw output
4667 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4668 $diffinfo{'from_id'} = $hash_parent;
4669 $diffinfo{'to_id'} = $hash;
4670 if (defined $file_name) {
4671 if (defined $file_parent) {
4672 $diffinfo{'status'} = '2';
4673 $diffinfo{'from_file'} = $file_parent;
4674 $diffinfo{'to_file'} = $file_name;
4675 } else { # assume not renamed
4676 $diffinfo{'status'} = '1';
4677 $diffinfo{'from_file'} = $file_name;
4678 $diffinfo{'to_file'} = $file_name;
4680 } else { # no filename given
4681 $diffinfo{'status'} = '2';
4682 $diffinfo{'from_file'} = $hash_parent;
4683 $diffinfo{'to_file'} = $hash;
4686 # non-textual hash id's can be cached
4687 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4688 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4693 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4694 '-p', ($format eq 'html' ? "--full-index" : ()),
4695 $hash_parent, $hash, "--"
4696 or die_error
(undef, "Open git-diff failed");
4698 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4703 if ($format eq 'html') {
4705 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4706 hash
=>$hash, hash_parent
=>$hash_parent,
4707 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4708 file_name
=>$file_name, file_parent
=>$file_parent)},
4710 git_header_html
(undef, $expires);
4711 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4712 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4713 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4715 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4716 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4718 if (defined $file_name) {
4719 git_print_page_path
($file_name, "blob", $hash_base);
4721 print "<div class=\"page_path\"></div>\n";
4724 } elsif ($format eq 'plain') {
4726 -type
=> 'text/plain',
4727 -charset
=> 'utf-8',
4728 -expires
=> $expires,
4729 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4731 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4734 die_error
(undef, "Unknown blobdiff format");
4738 if ($format eq 'html') {
4739 print "<div class=\"page_body\">\n";
4741 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4744 print "</div>\n"; # class="page_body"
4748 while (my $line = <$fd>) {
4749 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4750 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4754 last if $line =~ m!^\+\+\+!;
4762 sub git_blobdiff_plain
{
4763 git_blobdiff
('plain');
4766 sub git_commitdiff
{
4767 my $format = shift || 'html';
4768 $hash ||= $hash_base || "HEAD";
4769 my %co = parse_commit
($hash);
4771 die_error
(undef, "Unknown commit object");
4774 # choose format for commitdiff for merge
4775 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4776 $hash_parent = '--cc';
4778 # we need to prepare $formats_nav before almost any parameter munging
4780 if ($format eq 'html') {
4782 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4783 hash
=>$hash, hash_parent
=>$hash_parent)},
4786 if (defined $hash_parent &&
4787 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4788 # commitdiff with two commits given
4789 my $hash_parent_short = $hash_parent;
4790 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4791 $hash_parent_short = substr($hash_parent, 0, 7);
4795 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4796 if ($co{'parents'}[$i] eq $hash_parent) {
4797 $formats_nav .= ' parent ' . ($i+1);
4801 $formats_nav .= ': ' .
4802 $cgi->a({-href
=> href
(action
=>"commitdiff",
4803 hash
=>$hash_parent)},
4804 esc_html
($hash_parent_short)) .
4806 } elsif (!$co{'parent'}) {
4808 $formats_nav .= ' (initial)';
4809 } elsif (scalar @{$co{'parents'}} == 1) {
4810 # single parent commit
4813 $cgi->a({-href
=> href
(action
=>"commitdiff",
4814 hash
=>$co{'parent'})},
4815 esc_html
(substr($co{'parent'}, 0, 7))) .
4819 if ($hash_parent eq '--cc') {
4820 $formats_nav .= ' | ' .
4821 $cgi->a({-href
=> href
(action
=>"commitdiff",
4822 hash
=>$hash, hash_parent
=>'-c')},
4824 } else { # $hash_parent eq '-c'
4825 $formats_nav .= ' | ' .
4826 $cgi->a({-href
=> href
(action
=>"commitdiff",
4827 hash
=>$hash, hash_parent
=>'--cc')},
4833 $cgi->a({-href
=> href
(action
=>"commitdiff",
4835 esc_html
(substr($_, 0, 7)));
4836 } @{$co{'parents'}} ) .
4841 my $hash_parent_param = $hash_parent;
4842 if (!defined $hash_parent_param) {
4843 # --cc for multiple parents, --root for parentless
4844 $hash_parent_param =
4845 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4851 if ($format eq 'html') {
4852 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4853 "--no-commit-id", "--patch-with-raw", "--full-index",
4854 $hash_parent_param, $hash, "--"
4855 or die_error
(undef, "Open git-diff-tree failed");
4857 while (my $line = <$fd>) {
4859 # empty line ends raw part of diff-tree output
4861 push @difftree, scalar parse_difftree_raw_line
($line);
4864 } elsif ($format eq 'plain') {
4865 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4866 '-p', $hash_parent_param, $hash, "--"
4867 or die_error
(undef, "Open git-diff-tree failed");
4870 die_error
(undef, "Unknown commitdiff format");
4873 # non-textual hash id's can be cached
4875 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4879 # write commit message
4880 if ($format eq 'html') {
4881 my $refs = git_get_references
();
4882 my $ref = format_ref_marker
($refs, $co{'id'});
4884 git_header_html
(undef, $expires);
4885 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4886 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4887 git_print_authorship
(\
%co);
4888 print "<div class=\"page_body\">\n";
4889 if (@{$co{'comment'}} > 1) {
4890 print "<div class=\"log\">\n";
4891 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4892 print "</div>\n"; # class="log"
4895 } elsif ($format eq 'plain') {
4896 my $refs = git_get_references
("tags");
4897 my $tagname = git_get_rev_name_tags
($hash);
4898 my $filename = basename
($project) . "-$hash.patch";
4901 -type
=> 'text/plain',
4902 -charset
=> 'utf-8',
4903 -expires
=> $expires,
4904 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4905 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4908 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4909 Subject: $co{'title'}
4911 print "X-Git-Tag: $tagname\n" if $tagname;
4912 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4914 foreach my $line (@{$co{'comment'}}) {
4921 if ($format eq 'html') {
4922 my $use_parents = !defined $hash_parent ||
4923 $hash_parent eq '-c' || $hash_parent eq '--cc';
4924 git_difftree_body
(\
@difftree, $hash,
4925 $use_parents ? @{$co{'parents'}} : $hash_parent);
4928 git_patchset_body
($fd, \
@difftree, $hash,
4929 $use_parents ? @{$co{'parents'}} : $hash_parent);
4931 print "</div>\n"; # class="page_body"
4934 } elsif ($format eq 'plain') {
4938 or print "Reading git-diff-tree failed\n";
4942 sub git_commitdiff_plain
{
4943 git_commitdiff
('plain');
4947 if (!defined $hash_base) {
4948 $hash_base = git_get_head_hash
($project);
4950 if (!defined $page) {
4954 my %co = parse_commit
($hash_base);
4956 die_error
(undef, "Unknown commit object");
4959 my $refs = git_get_references
();
4960 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4962 if (!defined $hash && defined $file_name) {
4963 $hash = git_get_hash_by_path
($hash_base, $file_name);
4965 if (defined $hash) {
4966 $ftype = git_get_type
($hash);
4969 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4971 my $paging_nav = '';
4974 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4975 file_name
=>$file_name)},
4977 $paging_nav .= " ⋅ " .
4978 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4979 file_name
=>$file_name, page
=>$page-1),
4980 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4982 $paging_nav .= "first";
4983 $paging_nav .= " ⋅ prev";
4985 if ($#commitlist >= 100) {
4986 $paging_nav .= " ⋅ " .
4987 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4988 file_name
=>$file_name, page
=>$page+1),
4989 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4991 $paging_nav .= " ⋅ next";
4994 if ($#commitlist >= 100) {
4996 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4997 file_name
=>$file_name, page
=>$page+1),
4998 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5002 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5003 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5004 git_print_page_path
($file_name, $ftype, $hash_base);
5006 git_history_body
(\
@commitlist, 0, 99,
5007 $refs, $hash_base, $ftype, $next_link);
5013 my ($have_search) = gitweb_check_feature
('search');
5014 if (!$have_search) {
5015 die_error
('403 Permission denied', "Permission denied");
5017 if (!defined $searchtext) {
5018 die_error
(undef, "Text field empty");
5020 if (!defined $hash) {
5021 $hash = git_get_head_hash
($project);
5023 my %co = parse_commit
($hash);
5025 die_error
(undef, "Unknown commit object");
5027 if (!defined $page) {
5031 $searchtype ||= 'commit';
5032 if ($searchtype eq 'pickaxe') {
5033 # pickaxe may take all resources of your box and run for several minutes
5034 # with every query - so decide by yourself how public you make this feature
5035 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5036 if (!$have_pickaxe) {
5037 die_error
('403 Permission denied', "Permission denied");
5040 if ($searchtype eq 'grep') {
5041 my ($have_grep) = gitweb_check_feature
('grep');
5043 die_error
('403 Permission denied', "Permission denied");
5049 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5051 if ($searchtype eq 'commit') {
5052 $greptype = "--grep=";
5053 } elsif ($searchtype eq 'author') {
5054 $greptype = "--author=";
5055 } elsif ($searchtype eq 'committer') {
5056 $greptype = "--committer=";
5058 $greptype .= $search_regexp;
5059 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5061 my $paging_nav = '';
5064 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5065 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5067 $paging_nav .= " ⋅ " .
5068 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5069 searchtext
=>$searchtext, searchtype
=>$searchtype,
5071 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5073 $paging_nav .= "first";
5074 $paging_nav .= " ⋅ prev";
5076 if ($#commitlist >= 100) {
5077 $paging_nav .= " ⋅ " .
5078 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5079 searchtext
=>$searchtext, searchtype
=>$searchtype,
5081 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5083 $paging_nav .= " ⋅ next";
5086 if ($#commitlist >= 100) {
5088 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5089 searchtext
=>$searchtext, searchtype
=>$searchtype,
5091 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5094 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5095 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5096 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5099 if ($searchtype eq 'pickaxe') {
5100 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5101 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5103 print "<table cellspacing=\"0\">\n";
5106 my $git_command = git_cmd_str
();
5107 my $searchqtext = $searchtext;
5108 $searchqtext =~ s/'/'\\''/;
5109 open my $fd, "-|", "$git_command rev-list $hash | " .
5110 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5113 while (my $line = <$fd>) {
5114 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5117 $set{'from_id'} = $3;
5119 $set{'id'} = $set{'to_id'};
5120 if ($set{'id'} =~ m/0{40}/) {
5121 $set{'id'} = $set{'from_id'};
5123 if ($set{'id'} =~ m/0{40}/) {
5127 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5130 print "<tr class=\"dark\">\n";
5132 print "<tr class=\"light\">\n";
5135 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5136 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5138 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5139 -class => "list subject"},
5140 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5141 while (my $setref = shift @files) {
5143 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5144 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5146 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5150 "<td class=\"link\">" .
5151 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5153 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5157 %co = parse_commit
($1);
5165 if ($searchtype eq 'grep') {
5166 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5167 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5169 print "<table cellspacing=\"0\">\n";
5173 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5175 while (my $line = <$fd>) {
5177 my ($file, $lno, $ltext, $binary);
5178 last if ($matches++ > 1000);
5179 if ($line =~ /^Binary file (.+) matches$/) {
5183 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5185 if ($file ne $lastfile) {
5186 $lastfile and print "</td></tr>\n";
5188 print "<tr class=\"dark\">\n";
5190 print "<tr class=\"light\">\n";
5192 print "<td class=\"list\">".
5193 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5194 file_name
=>"$file"),
5195 -class => "list"}, esc_path
($file));
5196 print "</td><td>\n";
5200 print "<div class=\"binary\">Binary file</div>\n";
5202 $ltext = untabify
($ltext);
5203 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5204 $ltext = esc_html
($1, -nbsp
=>1);
5205 $ltext .= '<span class="match">';
5206 $ltext .= esc_html
($2, -nbsp
=>1);
5207 $ltext .= '</span>';
5208 $ltext .= esc_html
($3, -nbsp
=>1);
5210 $ltext = esc_html
($ltext, -nbsp
=>1);
5212 print "<div class=\"pre\">" .
5213 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5214 file_name
=>"$file").'#l'.$lno,
5215 -class => "linenr"}, sprintf('%4i', $lno))
5216 . ' ' . $ltext . "</div>\n";
5220 print "</td></tr>\n";
5221 if ($matches > 1000) {
5222 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5225 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5234 sub git_search_help
{
5236 git_print_page_nav
('','', $hash,$hash,$hash);
5239 <dt><b>commit</b></dt>
5240 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5242 my ($have_grep) = gitweb_check_feature
('grep');
5245 <dt><b>grep</b></dt>
5246 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5247 a different one) are searched for the given
5248 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5249 (POSIX extended) and the matches are listed. On large
5250 trees, this search can take a while and put some strain on the server, so please use it with
5251 some consideration.</dd>
5255 <dt><b>author</b></dt>
5256 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5257 <dt><b>committer</b></dt>
5258 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5260 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5261 if ($have_pickaxe) {
5263 <dt><b>pickaxe</b></dt>
5264 <dd>All commits that caused the string to appear or disappear from any file (changes that
5265 added, removed or "modified" the string) will be listed. This search can take a while and
5266 takes a lot of strain on the server, so please use it wisely.</dd>
5274 my $head = git_get_head_hash
($project);
5275 if (!defined $hash) {
5278 if (!defined $page) {
5281 my $refs = git_get_references
();
5283 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5285 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5287 if ($#commitlist >= 100) {
5289 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5290 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5294 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5295 git_print_header_div
('summary', $project);
5297 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5302 ## ......................................................................
5303 ## feeds (RSS, Atom; OPML)
5306 my $format = shift || 'atom';
5307 my ($have_blame) = gitweb_check_feature
('blame');
5309 # Atom: http://www.atomenabled.org/developers/syndication/
5310 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5311 if ($format ne 'rss' && $format ne 'atom') {
5312 die_error
(undef, "Unknown web feed format");
5315 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5316 my $head = $hash || 'HEAD';
5317 my @commitlist = parse_commits
($head, 150);
5321 my $content_type = "application/$format+xml";
5322 if (defined $cgi->http('HTTP_ACCEPT') &&
5323 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5324 # browser (feed reader) prefers text/xml
5325 $content_type = 'text/xml';
5327 if (defined($commitlist[0])) {
5328 %latest_commit = %{$commitlist[0]};
5329 %latest_date = parse_date
($latest_commit{'author_epoch'});
5331 -type
=> $content_type,
5332 -charset
=> 'utf-8',
5333 -last_modified
=> $latest_date{'rfc2822'});
5336 -type
=> $content_type,
5337 -charset
=> 'utf-8');
5340 # Optimization: skip generating the body if client asks only
5341 # for Last-Modified date.
5342 return if ($cgi->request_method() eq 'HEAD');
5345 my $title = "$site_name - $project/$action";
5346 my $feed_type = 'log';
5347 if (defined $hash) {
5348 $title .= " - '$hash'";
5349 $feed_type = 'branch log';
5350 if (defined $file_name) {
5351 $title .= " :: $file_name";
5352 $feed_type = 'history';
5354 } elsif (defined $file_name) {
5355 $title .= " - $file_name";
5356 $feed_type = 'history';
5358 $title .= " $feed_type";
5359 my $descr = git_get_project_description
($project);
5360 if (defined $descr) {
5361 $descr = esc_html
($descr);
5363 $descr = "$project " .
5364 ($format eq 'rss' ? 'RSS' : 'Atom') .
5367 my $owner = git_get_project_owner
($project);
5368 $owner = esc_html
($owner);
5372 if (defined $file_name) {
5373 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5374 } elsif (defined $hash) {
5375 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5377 $alt_url = href
(-full
=>1, action
=>"summary");
5379 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5380 if ($format eq 'rss') {
5382 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5385 print "<title>$title</title>\n" .
5386 "<link>$alt_url</link>\n" .
5387 "<description>$descr</description>\n" .
5388 "<language>en</language>\n";
5389 } elsif ($format eq 'atom') {
5391 <feed xmlns="http://www.w3.org/2005/Atom">
5393 print "<title>$title</title>\n" .
5394 "<subtitle>$descr</subtitle>\n" .
5395 '<link rel="alternate" type="text/html" href="' .
5396 $alt_url . '" />' . "\n" .
5397 '<link rel="self" type="' . $content_type . '" href="' .
5398 $cgi->self_url() . '" />' . "\n" .
5399 "<id>" . href
(-full
=>1) . "</id>\n" .
5400 # use project owner for feed author
5401 "<author><name>$owner</name></author>\n";
5402 if (defined $favicon) {
5403 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5405 if (defined $logo_url) {
5406 # not twice as wide as tall: 72 x 27 pixels
5407 print "<logo>" . esc_url
($logo) . "</logo>\n";
5409 if (! %latest_date) {
5410 # dummy date to keep the feed valid until commits trickle in:
5411 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5413 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5418 for (my $i = 0; $i <= $#commitlist; $i++) {
5419 my %co = %{$commitlist[$i]};
5420 my $commit = $co{'id'};
5421 # we read 150, we always show 30 and the ones more recent than 48 hours
5422 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5425 my %cd = parse_date
($co{'author_epoch'});
5427 # get list of changed files
5428 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5429 $co{'parent'} || "--root",
5430 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5432 my @difftree = map { chomp; $_ } <$fd>;
5436 # print element (entry, item)
5437 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5438 if ($format eq 'rss') {
5440 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5441 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5442 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5443 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5444 "<link>$co_url</link>\n" .
5445 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5446 "<content:encoded>" .
5448 } elsif ($format eq 'atom') {
5450 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5451 "<updated>$cd{'iso-8601'}</updated>\n" .
5453 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5454 if ($co{'author_email'}) {
5455 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5457 print "</author>\n" .
5458 # use committer for contributor
5460 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5461 if ($co{'committer_email'}) {
5462 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5464 print "</contributor>\n" .
5465 "<published>$cd{'iso-8601'}</published>\n" .
5466 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5467 "<id>$co_url</id>\n" .
5468 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5469 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5471 my $comment = $co{'comment'};
5473 foreach my $line (@$comment) {
5474 $line = esc_html
($line);
5477 print "</pre><ul>\n";
5478 foreach my $difftree_line (@difftree) {
5479 my %difftree = parse_difftree_raw_line
($difftree_line);
5480 next if !$difftree{'from_id'};
5482 my $file = $difftree{'file'} || $difftree{'to_file'};
5486 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5487 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5488 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5489 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5490 -title
=> "diff"}, 'D');
5492 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5493 file_name
=>$file, hash_base
=>$commit),
5494 -title
=> "blame"}, 'B');
5496 # if this is not a feed of a file history
5497 if (!defined $file_name || $file_name ne $file) {
5498 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5499 file_name
=>$file, hash
=>$commit),
5500 -title
=> "history"}, 'H');
5502 $file = esc_path
($file);
5506 if ($format eq 'rss') {
5507 print "</ul>]]>\n" .
5508 "</content:encoded>\n" .
5510 } elsif ($format eq 'atom') {
5511 print "</ul>\n</div>\n" .
5518 if ($format eq 'rss') {
5519 print "</channel>\n</rss>\n";
5520 } elsif ($format eq 'atom') {
5534 my @list = git_get_projects_list
();
5536 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5538 <?xml version="1.0" encoding="utf-8"?>
5539 <opml version="1.0">
5541 <title>$site_name OPML Export</title>
5544 <outline text="git RSS feeds">
5547 foreach my $pr (@list) {
5549 my $head = git_get_head_hash
($proj{'path'});
5550 if (!defined $head) {
5553 $git_dir = "$projectroot/$proj{'path'}";
5554 my %co = parse_commit
($head);
5559 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5560 my $rss = "$my_url?p=$proj{'path'};a=rss";
5561 my $html = "$my_url?p=$proj{'path'};a=summary";
5562 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";