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);
311 @fmts = grep { defined } map {
312 exists $known_snapshot_format_aliases{$_} ?
313 $known_snapshot_format_aliases{$_} : $_ } @fmts;
314 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
361 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
363 # version of the core git binary
364 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
366 $projects_list ||= $projectroot;
368 # ======================================================================
369 # input validation and dispatch
370 our $action = $cgi->param('a');
371 if (defined $action) {
372 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
373 die_error
(undef, "Invalid action parameter");
377 # parameters which are pathnames
378 our $project = $cgi->param('p');
379 if (defined $project) {
380 if (!validate_pathname
($project) ||
381 !(-d
"$projectroot/$project") ||
382 !check_head_link
("$projectroot/$project") ||
383 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
384 ($strict_export && !project_in_list
($project))) {
386 die_error
(undef, "No such project");
390 our $file_name = $cgi->param('f');
391 if (defined $file_name) {
392 if (!validate_pathname
($file_name)) {
393 die_error
(undef, "Invalid file parameter");
397 our $file_parent = $cgi->param('fp');
398 if (defined $file_parent) {
399 if (!validate_pathname
($file_parent)) {
400 die_error
(undef, "Invalid file parent parameter");
404 # parameters which are refnames
405 our $hash = $cgi->param('h');
407 if (!validate_refname
($hash)) {
408 die_error
(undef, "Invalid hash parameter");
412 our $hash_parent = $cgi->param('hp');
413 if (defined $hash_parent) {
414 if (!validate_refname
($hash_parent)) {
415 die_error
(undef, "Invalid hash parent parameter");
419 our $hash_base = $cgi->param('hb');
420 if (defined $hash_base) {
421 if (!validate_refname
($hash_base)) {
422 die_error
(undef, "Invalid hash base parameter");
426 my %allowed_options = (
427 "--no-merges" => [ qw(rss atom log shortlog history) ],
430 our @extra_options = $cgi->param('opt');
431 if (defined @extra_options) {
432 foreach(@extra_options)
434 if (not grep(/^$_$/, keys %allowed_options)) {
435 die_error
(undef, "Invalid option parameter");
437 if (not grep(/^$action$/, @{$allowed_options{$_}})) {
438 die_error
(undef, "Invalid option parameter for this action");
443 our $hash_parent_base = $cgi->param('hpb');
444 if (defined $hash_parent_base) {
445 if (!validate_refname
($hash_parent_base)) {
446 die_error
(undef, "Invalid hash parent base parameter");
451 our $page = $cgi->param('pg');
453 if ($page =~ m/[^0-9]/) {
454 die_error
(undef, "Invalid page parameter");
458 our $searchtype = $cgi->param('st');
459 if (defined $searchtype) {
460 if ($searchtype =~ m/[^a-z]/) {
461 die_error
(undef, "Invalid searchtype parameter");
465 our $searchtext = $cgi->param('s');
467 if (defined $searchtext) {
468 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
469 die_error
(undef, "Invalid search parameter");
471 if (length($searchtext) < 2) {
472 die_error
(undef, "At least two characters are required for search parameter");
474 $search_regexp = quotemeta $searchtext;
477 # now read PATH_INFO and use it as alternative to parameters
478 sub evaluate_path_info
{
479 return if defined $project;
480 my $path_info = $ENV{"PATH_INFO"};
481 return if !$path_info;
482 $path_info =~ s
,^/+,,;
483 return if !$path_info;
484 # find which part of PATH_INFO is project
485 $project = $path_info;
487 while ($project && !check_head_link
("$projectroot/$project")) {
488 $project =~ s
,/*[^/]*$,,;
491 $project = validate_pathname
($project);
493 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
494 ($strict_export && !project_in_list
($project))) {
498 # do not change any parameters if an action is given using the query string
500 $path_info =~ s
,^$project/*,,;
501 my ($refname, $pathname) = split(/:/, $path_info, 2);
502 if (defined $pathname) {
503 # we got "project.git/branch:filename" or "project.git/branch:dir/"
504 # we could use git_get_type(branch:pathname), but it needs $git_dir
505 $pathname =~ s
,^/+,,;
506 if (!$pathname || substr($pathname, -1) eq "/") {
510 $action ||= "blob_plain";
512 $hash_base ||= validate_refname
($refname);
513 $file_name ||= validate_pathname
($pathname);
514 } elsif (defined $refname) {
515 # we got "project.git/branch"
516 $action ||= "shortlog";
517 $hash ||= validate_refname
($refname);
520 evaluate_path_info
();
522 # path to the current git repository
524 $git_dir = "$projectroot/$project" if $project;
528 "blame" => \
&git_blame2
,
529 "blobdiff" => \
&git_blobdiff
,
530 "blobdiff_plain" => \
&git_blobdiff_plain
,
531 "blob" => \
&git_blob
,
532 "blob_plain" => \
&git_blob_plain
,
533 "commitdiff" => \
&git_commitdiff
,
534 "commitdiff_plain" => \
&git_commitdiff_plain
,
535 "commit" => \
&git_commit
,
536 "forks" => \
&git_forks
,
537 "heads" => \
&git_heads
,
538 "history" => \
&git_history
,
541 "atom" => \
&git_atom
,
542 "search" => \
&git_search
,
543 "search_help" => \
&git_search_help
,
544 "shortlog" => \
&git_shortlog
,
545 "summary" => \
&git_summary
,
547 "tags" => \
&git_tags
,
548 "tree" => \
&git_tree
,
549 "snapshot" => \
&git_snapshot
,
550 "object" => \
&git_object
,
551 # those below don't need $project
552 "opml" => \
&git_opml
,
553 "project_list" => \
&git_project_list
,
554 "project_index" => \
&git_project_index
,
557 if (!defined $action) {
559 $action = git_get_type
($hash);
560 } elsif (defined $hash_base && defined $file_name) {
561 $action = git_get_type
("$hash_base:$file_name");
562 } elsif (defined $project) {
565 $action = 'project_list';
568 if (!defined($actions{$action})) {
569 die_error
(undef, "Unknown action");
571 if ($action !~ m/^(opml|project_list|project_index)$/ &&
573 die_error
(undef, "Project needed");
575 $actions{$action}->();
578 ## ======================================================================
583 # default is to use -absolute url() i.e. $my_uri
584 my $href = $params{-full
} ? $my_url : $my_uri;
586 # XXX: Warning: If you touch this, check the search form for updating,
594 extra_options
=> "opt",
598 hash_parent_base
=> "hpb",
603 snapshot_format
=> "sf",
605 my %mapping = @mapping;
607 $params{'project'} = $project unless exists $params{'project'};
609 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
611 # use PATH_INFO for project name
612 $href .= "/$params{'project'}" if defined $params{'project'};
613 delete $params{'project'};
615 # Summary just uses the project path URL
616 if (defined $params{'action'} && $params{'action'} eq 'summary') {
617 delete $params{'action'};
621 # now encode the parameters explicitly
623 for (my $i = 0; $i < @mapping; $i += 2) {
624 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
625 if (defined $params{$name}) {
626 push @result, $symbol . "=" . esc_param
($params{$name});
629 $href .= "?" . join(';', @result) if scalar @result;
635 ## ======================================================================
636 ## validation, quoting/unquoting and escaping
638 sub validate_pathname
{
639 my $input = shift || return undef;
641 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
642 # at the beginning, at the end, and between slashes.
643 # also this catches doubled slashes
644 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
648 if ($input =~ m!\0!) {
654 sub validate_refname
{
655 my $input = shift || return undef;
657 # textual hashes are O.K.
658 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
661 # it must be correct pathname
662 $input = validate_pathname
($input)
664 # restrictions on ref name according to git-check-ref-format
665 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
671 # decode sequences of octets in utf8 into Perl's internal form,
672 # which is utf-8 with utf8 flag set if needed. gitweb writes out
673 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
677 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
681 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
685 # quote unsafe chars, but keep the slash, even when it's not
686 # correct, but quoted slashes look too horrible in bookmarks
689 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
695 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
698 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
704 # replace invalid utf8 character with SUBSTITUTION sequence
709 $str = to_utf8
($str);
710 $str = $cgi->escapeHTML($str);
711 if ($opts{'-nbsp'}) {
712 $str =~ s/ / /g;
714 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
718 # quote control characters and escape filename to HTML
723 $str = to_utf8
($str);
724 $str = $cgi->escapeHTML($str);
725 if ($opts{'-nbsp'}) {
726 $str =~ s/ / /g;
728 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
732 # Make control characters "printable", using character escape codes (CEC)
735 my %es = ( # character escape codes, aka escape sequences
736 "\t" => '\t', # tab (HT)
737 "\n" => '\n', # line feed (LF)
738 "\r" => '\r', # carrige return (CR)
739 "\f" => '\f', # form feed (FF)
740 "\b" => '\b', # backspace (BS)
741 "\a" => '\a', # alarm (bell) (BEL)
742 "\e" => '\e', # escape (ESC)
743 "\013" => '\v', # vertical tab (VT)
744 "\000" => '\0', # nul character (NUL)
746 my $chr = ( (exists $es{$cntrl})
748 : sprintf('\%03o', ord($cntrl)) );
749 return "<span class=\"cntrl\">$chr</span>";
752 # Alternatively use unicode control pictures codepoints,
753 # Unicode "printable representation" (PR)
756 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
757 return "<span class=\"cntrl\">$chr</span>";
760 # git may return quoted and escaped filenames
766 my %es = ( # character escape codes, aka escape sequences
767 't' => "\t", # tab (HT, TAB)
768 'n' => "\n", # newline (NL)
769 'r' => "\r", # return (CR)
770 'f' => "\f", # form feed (FF)
771 'b' => "\b", # backspace (BS)
772 'a' => "\a", # alarm (bell) (BEL)
773 'e' => "\e", # escape (ESC)
774 'v' => "\013", # vertical tab (VT)
777 if ($seq =~ m/^[0-7]{1,3}$/) {
778 # octal char sequence
779 return chr(oct($seq));
780 } elsif (exists $es{$seq}) {
781 # C escape sequence, aka character escape code
784 # quoted ordinary character
788 if ($str =~ m/^"(.*)"$/) {
791 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
796 # escape tabs (convert tabs to spaces)
800 while ((my $pos = index($line, "\t")) != -1) {
801 if (my $count = (8 - ($pos % 8))) {
802 my $spaces = ' ' x
$count;
803 $line =~ s/\t/$spaces/;
810 sub project_in_list
{
812 my @list = git_get_projects_list
();
813 return @list && scalar(grep { $_->{'path'} eq $project } @list);
816 ## ----------------------------------------------------------------------
817 ## HTML aware string manipulation
822 my $add_len = shift || 10;
824 # allow only $len chars, but don't cut a word if it would fit in $add_len
825 # if it doesn't fit, cut it if it's still longer than the dots we would add
826 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
829 if (length($tail) > 4) {
831 $body =~ s/&[^;]*$//; # remove chopped character entities
836 ## ----------------------------------------------------------------------
837 ## functions returning short strings
839 # CSS class for given age value (in seconds)
845 } elsif ($age < 60*60*2) {
847 } elsif ($age < 60*60*24*2) {
854 # convert age in seconds to "nn units ago" string
859 if ($age > 60*60*24*365*2) {
860 $age_str = (int $age/60/60/24/365);
861 $age_str .= " years ago";
862 } elsif ($age > 60*60*24*(365/12)*2) {
863 $age_str = int $age/60/60/24/(365/12);
864 $age_str .= " months ago";
865 } elsif ($age > 60*60*24*7*2) {
866 $age_str = int $age/60/60/24/7;
867 $age_str .= " weeks ago";
868 } elsif ($age > 60*60*24*2) {
869 $age_str = int $age/60/60/24;
870 $age_str .= " days ago";
871 } elsif ($age > 60*60*2) {
872 $age_str = int $age/60/60;
873 $age_str .= " hours ago";
874 } elsif ($age > 60*2) {
875 $age_str = int $age/60;
876 $age_str .= " min ago";
879 $age_str .= " sec ago";
881 $age_str .= " right now";
886 # convert file mode in octal to symbolic file mode string
888 my $mode = oct shift;
890 if (S_ISDIR
($mode & S_IFMT
)) {
892 } elsif (S_ISLNK
($mode)) {
894 } elsif (S_ISREG
($mode)) {
895 # git cares only about the executable bit
896 if ($mode & S_IXUSR
) {
906 # convert file mode in octal to file type string
910 if ($mode !~ m/^[0-7]+$/) {
916 if (S_ISDIR
($mode & S_IFMT
)) {
918 } elsif (S_ISLNK
($mode)) {
920 } elsif (S_ISREG
($mode)) {
927 # convert file mode in octal to file type description string
931 if ($mode !~ m/^[0-7]+$/) {
937 if (S_ISDIR
($mode & S_IFMT
)) {
939 } elsif (S_ISLNK
($mode)) {
941 } elsif (S_ISREG
($mode)) {
942 if ($mode & S_IXUSR
) {
953 ## ----------------------------------------------------------------------
954 ## functions returning short HTML fragments, or transforming HTML fragments
955 ## which don't belong to other sections
957 # format line of commit message.
958 sub format_log_line_html
{
961 $line = esc_html
($line, -nbsp
=>1);
962 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
965 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
966 -class => "text"}, $hash_text);
967 $line =~ s/$hash_text/$link/;
972 # format marker of refs pointing to given object
973 sub format_ref_marker
{
974 my ($refs, $id) = @_;
977 if (defined $refs->{$id}) {
978 foreach my $ref (@{$refs->{$id}}) {
979 my ($type, $name) = qw();
980 # e.g. tags/v2.6.11 or heads/next
981 if ($ref =~ m!^(.*?)s?/(.*)$!) {
989 $markers .= " <span class=\"$type\" title=\"$ref\">" .
990 esc_html
($name) . "</span>";
995 return ' <span class="refs">'. $markers . '</span>';
1001 # format, perhaps shortened and with markers, title line
1002 sub format_subject_html
{
1003 my ($long, $short, $href, $extra) = @_;
1004 $extra = '' unless defined($extra);
1006 if (length($short) < length($long)) {
1007 return $cgi->a({-href
=> $href, -class => "list subject",
1008 -title
=> to_utf8
($long)},
1009 esc_html
($short) . $extra);
1011 return $cgi->a({-href
=> $href, -class => "list subject"},
1012 esc_html
($long) . $extra);
1016 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1017 sub format_git_diff_header_line
{
1019 my $diffinfo = shift;
1020 my ($from, $to) = @_;
1022 if ($diffinfo->{'nparents'}) {
1024 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1025 if ($to->{'href'}) {
1026 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1027 esc_path
($to->{'file'}));
1028 } else { # file was deleted (no href)
1029 $line .= esc_path
($to->{'file'});
1033 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1034 if ($from->{'href'}) {
1035 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1036 'a/' . esc_path
($from->{'file'}));
1037 } else { # file was added (no href)
1038 $line .= 'a/' . esc_path
($from->{'file'});
1041 if ($to->{'href'}) {
1042 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1043 'b/' . esc_path
($to->{'file'}));
1044 } else { # file was deleted
1045 $line .= 'b/' . esc_path
($to->{'file'});
1049 return "<div class=\"diff header\">$line</div>\n";
1052 # format extended diff header line, before patch itself
1053 sub format_extended_diff_header_line
{
1055 my $diffinfo = shift;
1056 my ($from, $to) = @_;
1059 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1060 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1061 esc_path
($from->{'file'}));
1063 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1064 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1065 esc_path
($to->{'file'}));
1067 # match single <mode>
1068 if ($line =~ m/\s(\d{6})$/) {
1069 $line .= '<span class="info"> (' .
1070 file_type_long
($1) .
1074 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1075 # can match only for combined diff
1077 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1078 if ($from->{'href'}[$i]) {
1079 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1081 substr($diffinfo->{'from_id'}[$i],0,7));
1086 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1089 if ($to->{'href'}) {
1090 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1091 substr($diffinfo->{'to_id'},0,7));
1096 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1097 # can match only for ordinary diff
1098 my ($from_link, $to_link);
1099 if ($from->{'href'}) {
1100 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1101 substr($diffinfo->{'from_id'},0,7));
1103 $from_link = '0' x
7;
1105 if ($to->{'href'}) {
1106 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1107 substr($diffinfo->{'to_id'},0,7));
1111 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1112 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1115 return $line . "<br/>\n";
1118 # format from-file/to-file diff header
1119 sub format_diff_from_to_header
{
1120 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1125 #assert($line =~ m/^---/) if DEBUG;
1126 # no extra formatting for "^--- /dev/null"
1127 if (! $diffinfo->{'nparents'}) {
1128 # ordinary (single parent) diff
1129 if ($line =~ m!^--- "?a/!) {
1130 if ($from->{'href'}) {
1132 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1133 esc_path
($from->{'file'}));
1136 esc_path
($from->{'file'});
1139 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1142 # combined diff (merge commit)
1143 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1144 if ($from->{'href'}[$i]) {
1146 $cgi->a({-href
=>href
(action
=>"blobdiff",
1147 hash_parent
=>$diffinfo->{'from_id'}[$i],
1148 hash_parent_base
=>$parents[$i],
1149 file_parent
=>$from->{'file'}[$i],
1150 hash
=>$diffinfo->{'to_id'},
1152 file_name
=>$to->{'file'}),
1154 -title
=>"diff" . ($i+1)},
1157 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1158 esc_path
($from->{'file'}[$i]));
1160 $line = '--- /dev/null';
1162 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1167 #assert($line =~ m/^\+\+\+/) if DEBUG;
1168 # no extra formatting for "^+++ /dev/null"
1169 if ($line =~ m!^\+\+\+ "?b/!) {
1170 if ($to->{'href'}) {
1172 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1173 esc_path
($to->{'file'}));
1176 esc_path
($to->{'file'});
1179 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1184 # create note for patch simplified by combined diff
1185 sub format_diff_cc_simplified
{
1186 my ($diffinfo, @parents) = @_;
1189 $result .= "<div class=\"diff header\">" .
1191 if (!is_deleted
($diffinfo)) {
1192 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1194 hash
=>$diffinfo->{'to_id'},
1195 file_name
=>$diffinfo->{'to_file'}),
1197 esc_path
($diffinfo->{'to_file'}));
1199 $result .= esc_path
($diffinfo->{'to_file'});
1201 $result .= "</div>\n" . # class="diff header"
1202 "<div class=\"diff nodifferences\">" .
1204 "</div>\n"; # class="diff nodifferences"
1209 # format patch (diff) line (not to be used for diff headers)
1210 sub format_diff_line
{
1212 my ($from, $to) = @_;
1213 my $diff_class = "";
1217 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1219 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1220 if ($line =~ m/^\@{3}/) {
1221 $diff_class = " chunk_header";
1222 } elsif ($line =~ m/^\\/) {
1223 $diff_class = " incomplete";
1224 } elsif ($prefix =~ tr/+/+/) {
1225 $diff_class = " add";
1226 } elsif ($prefix =~ tr/-/-/) {
1227 $diff_class = " rem";
1230 # assume ordinary diff
1231 my $char = substr($line, 0, 1);
1233 $diff_class = " add";
1234 } elsif ($char eq '-') {
1235 $diff_class = " rem";
1236 } elsif ($char eq '@') {
1237 $diff_class = " chunk_header";
1238 } elsif ($char eq "\\") {
1239 $diff_class = " incomplete";
1242 $line = untabify
($line);
1243 if ($from && $to && $line =~ m/^\@{2} /) {
1244 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1245 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1247 $from_lines = 0 unless defined $from_lines;
1248 $to_lines = 0 unless defined $to_lines;
1250 if ($from->{'href'}) {
1251 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1252 -class=>"list"}, $from_text);
1254 if ($to->{'href'}) {
1255 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1256 -class=>"list"}, $to_text);
1258 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1259 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1260 return "<div class=\"diff$diff_class\">$line</div>\n";
1261 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1262 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1263 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1265 @from_text = split(' ', $ranges);
1266 for (my $i = 0; $i < @from_text; ++$i) {
1267 ($from_start[$i], $from_nlines[$i]) =
1268 (split(',', substr($from_text[$i], 1)), 0);
1271 $to_text = pop @from_text;
1272 $to_start = pop @from_start;
1273 $to_nlines = pop @from_nlines;
1275 $line = "<span class=\"chunk_info\">$prefix ";
1276 for (my $i = 0; $i < @from_text; ++$i) {
1277 if ($from->{'href'}[$i]) {
1278 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1279 -class=>"list"}, $from_text[$i]);
1281 $line .= $from_text[$i];
1285 if ($to->{'href'}) {
1286 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1287 -class=>"list"}, $to_text);
1291 $line .= " $prefix</span>" .
1292 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1293 return "<div class=\"diff$diff_class\">$line</div>\n";
1295 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1298 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1299 # linked. Pass the hash of the tree/commit to snapshot.
1300 sub format_snapshot_links
{
1302 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1303 my $num_fmts = @snapshot_fmts;
1304 if ($num_fmts > 1) {
1305 # A parenthesized list of links bearing format names.
1306 return "snapshot (" . join(' ', map
1313 }, $known_snapshot_formats{$_}{'display'})
1314 , @snapshot_fmts) . ")";
1315 } elsif ($num_fmts == 1) {
1316 # A single "snapshot" link whose tooltip bears the format name.
1317 my ($fmt) = @snapshot_fmts;
1322 snapshot_format
=>$fmt
1324 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1326 } else { # $num_fmts == 0
1331 ## ----------------------------------------------------------------------
1332 ## git utility subroutines, invoking git commands
1334 # returns path to the core git executable and the --git-dir parameter as list
1336 return $GIT, '--git-dir='.$git_dir;
1339 # returns path to the core git executable and the --git-dir parameter as string
1341 return join(' ', git_cmd
());
1344 # get HEAD ref of given project as hash
1345 sub git_get_head_hash
{
1346 my $project = shift;
1347 my $o_git_dir = $git_dir;
1349 $git_dir = "$projectroot/$project";
1350 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1353 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1357 if (defined $o_git_dir) {
1358 $git_dir = $o_git_dir;
1363 # get type of given object
1367 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1369 close $fd or return;
1374 sub git_get_project_config
{
1375 my ($key, $type) = @_;
1377 return unless ($key);
1378 $key =~ s/^gitweb\.//;
1379 return if ($key =~ m/\W/);
1381 my @x = (git_cmd
(), 'config');
1382 if (defined $type) { push @x, $type; }
1384 push @x, "gitweb.$key";
1390 # get hash of given path at given ref
1391 sub git_get_hash_by_path
{
1393 my $path = shift || return undef;
1398 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1399 or die_error
(undef, "Open git-ls-tree failed");
1401 close $fd or return undef;
1403 if (!defined $line) {
1404 # there is no tree or hash given by $path at $base
1408 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1409 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1410 if (defined $type && $type ne $2) {
1411 # type doesn't match
1417 # get path of entry with given hash at given tree-ish (ref)
1418 # used to get 'from' filename for combined diff (merge commit) for renames
1419 sub git_get_path_by_hash
{
1420 my $base = shift || return;
1421 my $hash = shift || return;
1425 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1427 while (my $line = <$fd>) {
1430 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1431 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1432 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1441 ## ......................................................................
1442 ## git utility functions, directly accessing git repository
1444 sub git_get_project_description
{
1447 open my $fd, "$projectroot/$path/description" or return undef;
1450 if (defined $descr) {
1456 sub git_get_project_url_list
{
1459 open my $fd, "$projectroot/$path/cloneurl" or return;
1460 my @git_project_url_list = map { chomp; $_ } <$fd>;
1463 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1466 sub git_get_projects_list
{
1471 $filter =~ s/\.git$//;
1473 my ($check_forks) = gitweb_check_feature
('forks');
1475 if (-d
$projects_list) {
1476 # search in directory
1477 my $dir = $projects_list . ($filter ? "/$filter" : '');
1478 # remove the trailing "/"
1480 my $pfxlen = length("$dir");
1483 follow_fast
=> 1, # follow symbolic links
1484 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1486 # skip project-list toplevel, if we get it.
1487 return if (m!^[/.]$!);
1488 # only directories can be git repositories
1489 return unless (-d
$_);
1491 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1492 # we check related file in $projectroot
1493 if ($check_forks and $subdir =~ m
#/.#) {
1494 $File::Find
::prune
= 1;
1495 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1496 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1497 $File::Find
::prune
= 1;
1502 } elsif (-f
$projects_list) {
1503 # read from file(url-encoded):
1504 # 'git%2Fgit.git Linus+Torvalds'
1505 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1506 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1508 open my ($fd), $projects_list or return;
1510 while (my $line = <$fd>) {
1512 my ($path, $owner) = split ' ', $line;
1513 $path = unescape
($path);
1514 $owner = unescape
($owner);
1515 if (!defined $path) {
1518 if ($filter ne '') {
1519 # looking for forks;
1520 my $pfx = substr($path, 0, length($filter));
1521 if ($pfx ne $filter) {
1524 my $sfx = substr($path, length($filter));
1525 if ($sfx !~ /^\/.*\
.git
$/) {
1528 } elsif ($check_forks) {
1530 foreach my $filter (keys %paths) {
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 # is a fork, don't include it in
1545 if (check_export_ok
("$projectroot/$path")) {
1548 owner
=> to_utf8
($owner),
1551 (my $forks_path = $path) =~ s/\.git$//;
1552 $paths{$forks_path}++;
1560 our $gitweb_project_owner = undef;
1561 sub git_get_project_list_from_file
{
1563 return if (defined $gitweb_project_owner);
1565 $gitweb_project_owner = {};
1566 # read from file (url-encoded):
1567 # 'git%2Fgit.git Linus+Torvalds'
1568 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1569 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1570 if (-f
$projects_list) {
1571 open (my $fd , $projects_list);
1572 while (my $line = <$fd>) {
1574 my ($pr, $ow) = split ' ', $line;
1575 $pr = unescape
($pr);
1576 $ow = unescape
($ow);
1577 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1583 sub git_get_project_owner
{
1584 my $project = shift;
1587 return undef unless $project;
1589 if (!defined $gitweb_project_owner) {
1590 git_get_project_list_from_file
();
1593 if (exists $gitweb_project_owner->{$project}) {
1594 $owner = $gitweb_project_owner->{$project};
1596 if (!defined $owner) {
1597 $owner = get_file_owner
("$projectroot/$project");
1603 sub git_get_last_activity
{
1607 $git_dir = "$projectroot/$path";
1608 open($fd, "-|", git_cmd
(), 'for-each-ref',
1609 '--format=%(committer)',
1610 '--sort=-committerdate',
1612 'refs/heads') or return;
1613 my $most_recent = <$fd>;
1614 close $fd or return;
1615 if (defined $most_recent &&
1616 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1618 my $age = time - $timestamp;
1619 return ($age, age_string
($age));
1621 return (undef, undef);
1624 sub git_get_references
{
1625 my $type = shift || "";
1627 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1628 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1629 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1630 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1633 while (my $line = <$fd>) {
1635 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1636 if (defined $refs{$1}) {
1637 push @{$refs{$1}}, $2;
1643 close $fd or return;
1647 sub git_get_rev_name_tags
{
1648 my $hash = shift || return undef;
1650 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1652 my $name_rev = <$fd>;
1655 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1658 # catches also '$hash undefined' output
1663 ## ----------------------------------------------------------------------
1664 ## parse to hash functions
1668 my $tz = shift || "-0000";
1671 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1672 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1673 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1674 $date{'hour'} = $hour;
1675 $date{'minute'} = $min;
1676 $date{'mday'} = $mday;
1677 $date{'day'} = $days[$wday];
1678 $date{'month'} = $months[$mon];
1679 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1680 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1681 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1682 $mday, $months[$mon], $hour ,$min;
1683 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1684 1900+$year, $mon, $mday, $hour ,$min, $sec;
1686 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1687 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1688 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1689 $date{'hour_local'} = $hour;
1690 $date{'minute_local'} = $min;
1691 $date{'tz_local'} = $tz;
1692 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1693 1900+$year, $mon+1, $mday,
1694 $hour, $min, $sec, $tz);
1703 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1704 $tag{'id'} = $tag_id;
1705 while (my $line = <$fd>) {
1707 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1708 $tag{'object'} = $1;
1709 } elsif ($line =~ m/^type (.+)$/) {
1711 } elsif ($line =~ m/^tag (.+)$/) {
1713 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1714 $tag{'author'} = $1;
1717 } elsif ($line =~ m/--BEGIN/) {
1718 push @comment, $line;
1720 } elsif ($line eq "") {
1724 push @comment, <$fd>;
1725 $tag{'comment'} = \
@comment;
1726 close $fd or return;
1727 if (!defined $tag{'name'}) {
1733 sub parse_commit_text
{
1734 my ($commit_text, $withparents) = @_;
1735 my @commit_lines = split '\n', $commit_text;
1738 pop @commit_lines; # Remove '\0'
1740 if (! @commit_lines) {
1744 my $header = shift @commit_lines;
1745 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1748 ($co{'id'}, my @parents) = split ' ', $header;
1749 while (my $line = shift @commit_lines) {
1750 last if $line eq "\n";
1751 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1753 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1755 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1757 $co{'author_epoch'} = $2;
1758 $co{'author_tz'} = $3;
1759 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1760 $co{'author_name'} = $1;
1761 $co{'author_email'} = $2;
1763 $co{'author_name'} = $co{'author'};
1765 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1766 $co{'committer'} = $1;
1767 $co{'committer_epoch'} = $2;
1768 $co{'committer_tz'} = $3;
1769 $co{'committer_name'} = $co{'committer'};
1770 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1771 $co{'committer_name'} = $1;
1772 $co{'committer_email'} = $2;
1774 $co{'committer_name'} = $co{'committer'};
1778 if (!defined $co{'tree'}) {
1781 $co{'parents'} = \
@parents;
1782 $co{'parent'} = $parents[0];
1784 foreach my $title (@commit_lines) {
1787 $co{'title'} = chop_str
($title, 80, 5);
1788 # remove leading stuff of merges to make the interesting part visible
1789 if (length($title) > 50) {
1790 $title =~ s/^Automatic //;
1791 $title =~ s/^merge (of|with) /Merge ... /i;
1792 if (length($title) > 50) {
1793 $title =~ s/(http|rsync):\/\///;
1795 if (length($title) > 50) {
1796 $title =~ s/(master|www|rsync)\.//;
1798 if (length($title) > 50) {
1799 $title =~ s/kernel.org:?//;
1801 if (length($title) > 50) {
1802 $title =~ s/\/pub\/scm//;
1805 $co{'title_short'} = chop_str
($title, 50, 5);
1809 if ($co{'title'} eq "") {
1810 $co{'title'} = $co{'title_short'} = '(no commit message)';
1812 # remove added spaces
1813 foreach my $line (@commit_lines) {
1816 $co{'comment'} = \
@commit_lines;
1818 my $age = time - $co{'committer_epoch'};
1820 $co{'age_string'} = age_string
($age);
1821 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1822 if ($age > 60*60*24*7*2) {
1823 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1824 $co{'age_string_age'} = $co{'age_string'};
1826 $co{'age_string_date'} = $co{'age_string'};
1827 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1833 my ($commit_id) = @_;
1838 open my $fd, "-|", git_cmd
(), "rev-list",
1844 or die_error
(undef, "Open git-rev-list failed");
1845 %co = parse_commit_text
(<$fd>, 1);
1852 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1860 open my $fd, "-|", git_cmd
(), "rev-list",
1862 ($arg ? ($arg) : ()),
1863 ("--max-count=" . $maxcount),
1864 ("--skip=" . $skip),
1868 ($filename ? ($filename) : ())
1869 or die_error
(undef, "Open git-rev-list failed");
1870 while (my $line = <$fd>) {
1871 my %co = parse_commit_text
($line);
1876 return wantarray ? @cos : \
@cos;
1879 # parse ref from ref_file, given by ref_id, with given type
1881 my $ref_file = shift;
1883 my $type = shift || git_get_type
($ref_id);
1886 $ref_item{'type'} = $type;
1887 $ref_item{'id'} = $ref_id;
1888 $ref_item{'epoch'} = 0;
1889 $ref_item{'age'} = "unknown";
1890 if ($type eq "tag") {
1891 my %tag = parse_tag
($ref_id);
1892 $ref_item{'comment'} = $tag{'comment'};
1893 if ($tag{'type'} eq "commit") {
1894 my %co = parse_commit
($tag{'object'});
1895 $ref_item{'epoch'} = $co{'committer_epoch'};
1896 $ref_item{'age'} = $co{'age_string'};
1897 } elsif (defined($tag{'epoch'})) {
1898 my $age = time - $tag{'epoch'};
1899 $ref_item{'epoch'} = $tag{'epoch'};
1900 $ref_item{'age'} = age_string
($age);
1902 $ref_item{'reftype'} = $tag{'type'};
1903 $ref_item{'name'} = $tag{'name'};
1904 $ref_item{'refid'} = $tag{'object'};
1905 } elsif ($type eq "commit"){
1906 my %co = parse_commit
($ref_id);
1907 $ref_item{'reftype'} = "commit";
1908 $ref_item{'name'} = $ref_file;
1909 $ref_item{'title'} = $co{'title'};
1910 $ref_item{'refid'} = $ref_id;
1911 $ref_item{'epoch'} = $co{'committer_epoch'};
1912 $ref_item{'age'} = $co{'age_string'};
1914 $ref_item{'reftype'} = $type;
1915 $ref_item{'name'} = $ref_file;
1916 $ref_item{'refid'} = $ref_id;
1922 # parse line of git-diff-tree "raw" output
1923 sub parse_difftree_raw_line
{
1927 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1928 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1929 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1930 $res{'from_mode'} = $1;
1931 $res{'to_mode'} = $2;
1932 $res{'from_id'} = $3;
1934 $res{'status'} = $5;
1935 $res{'similarity'} = $6;
1936 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1937 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1939 $res{'file'} = unquote
($7);
1942 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1943 # combined diff (for merge commit)
1944 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1945 $res{'nparents'} = length($1);
1946 $res{'from_mode'} = [ split(' ', $2) ];
1947 $res{'to_mode'} = pop @{$res{'from_mode'}};
1948 $res{'from_id'} = [ split(' ', $3) ];
1949 $res{'to_id'} = pop @{$res{'from_id'}};
1950 $res{'status'} = [ split('', $4) ];
1951 $res{'to_file'} = unquote
($5);
1953 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1954 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1955 $res{'commit'} = $1;
1958 return wantarray ? %res : \
%res;
1961 # parse line of git-ls-tree output
1962 sub parse_ls_tree_line
($;%) {
1967 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1968 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1976 $res{'name'} = unquote
($4);
1979 return wantarray ? %res : \
%res;
1982 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1983 sub parse_from_to_diffinfo
{
1984 my ($diffinfo, $from, $to, @parents) = @_;
1986 if ($diffinfo->{'nparents'}) {
1988 $from->{'file'} = [];
1989 $from->{'href'} = [];
1990 fill_from_file_info
($diffinfo, @parents)
1991 unless exists $diffinfo->{'from_file'};
1992 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1993 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1994 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1995 $from->{'href'}[$i] = href
(action
=>"blob",
1996 hash_base
=>$parents[$i],
1997 hash
=>$diffinfo->{'from_id'}[$i],
1998 file_name
=>$from->{'file'}[$i]);
2000 $from->{'href'}[$i] = undef;
2004 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2005 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2006 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2007 hash
=>$diffinfo->{'from_id'},
2008 file_name
=>$from->{'file'});
2010 delete $from->{'href'};
2014 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2015 if (!is_deleted
($diffinfo)) { # file exists in result
2016 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2017 hash
=>$diffinfo->{'to_id'},
2018 file_name
=>$to->{'file'});
2020 delete $to->{'href'};
2024 ## ......................................................................
2025 ## parse to array of hashes functions
2027 sub git_get_heads_list
{
2031 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2032 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2033 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2036 while (my $line = <$fd>) {
2040 my ($refinfo, $committerinfo) = split(/\0/, $line);
2041 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2042 my ($committer, $epoch, $tz) =
2043 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2044 $name =~ s!^refs/heads/!!;
2046 $ref_item{'name'} = $name;
2047 $ref_item{'id'} = $hash;
2048 $ref_item{'title'} = $title || '(no commit message)';
2049 $ref_item{'epoch'} = $epoch;
2051 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2053 $ref_item{'age'} = "unknown";
2056 push @headslist, \
%ref_item;
2060 return wantarray ? @headslist : \
@headslist;
2063 sub git_get_tags_list
{
2067 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2068 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2069 '--format=%(objectname) %(objecttype) %(refname) '.
2070 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2073 while (my $line = <$fd>) {
2077 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2078 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2079 my ($creator, $epoch, $tz) =
2080 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2081 $name =~ s!^refs/tags/!!;
2083 $ref_item{'type'} = $type;
2084 $ref_item{'id'} = $id;
2085 $ref_item{'name'} = $name;
2086 if ($type eq "tag") {
2087 $ref_item{'subject'} = $title;
2088 $ref_item{'reftype'} = $reftype;
2089 $ref_item{'refid'} = $refid;
2091 $ref_item{'reftype'} = $type;
2092 $ref_item{'refid'} = $id;
2095 if ($type eq "tag" || $type eq "commit") {
2096 $ref_item{'epoch'} = $epoch;
2098 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2100 $ref_item{'age'} = "unknown";
2104 push @tagslist, \
%ref_item;
2108 return wantarray ? @tagslist : \
@tagslist;
2111 ## ----------------------------------------------------------------------
2112 ## filesystem-related functions
2114 sub get_file_owner
{
2117 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2118 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2119 if (!defined $gcos) {
2123 $owner =~ s/[,;].*$//;
2124 return to_utf8
($owner);
2127 ## ......................................................................
2128 ## mimetype related functions
2130 sub mimetype_guess_file
{
2131 my $filename = shift;
2132 my $mimemap = shift;
2133 -r
$mimemap or return undef;
2136 open(MIME
, $mimemap) or return undef;
2138 next if m/^#/; # skip comments
2139 my ($mime, $exts) = split(/\t+/);
2140 if (defined $exts) {
2141 my @exts = split(/\s+/, $exts);
2142 foreach my $ext (@exts) {
2143 $mimemap{$ext} = $mime;
2149 $filename =~ /\.([^.]*)$/;
2150 return $mimemap{$1};
2153 sub mimetype_guess
{
2154 my $filename = shift;
2156 $filename =~ /\./ or return undef;
2158 if ($mimetypes_file) {
2159 my $file = $mimetypes_file;
2160 if ($file !~ m!^/!) { # if it is relative path
2161 # it is relative to project
2162 $file = "$projectroot/$project/$file";
2164 $mime = mimetype_guess_file
($filename, $file);
2166 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2172 my $filename = shift;
2175 my $mime = mimetype_guess
($filename);
2176 $mime and return $mime;
2180 return $default_blob_plain_mimetype unless $fd;
2183 return 'text/plain' .
2184 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2185 } elsif (! $filename) {
2186 return 'application/octet-stream';
2187 } elsif ($filename =~ m/\.png$/i) {
2189 } elsif ($filename =~ m/\.gif$/i) {
2191 } elsif ($filename =~ m/\.jpe?g$/i) {
2192 return 'image/jpeg';
2194 return 'application/octet-stream';
2198 ## ======================================================================
2199 ## functions printing HTML: header, footer, error page
2201 sub git_header_html
{
2202 my $status = shift || "200 OK";
2203 my $expires = shift;
2205 my $title = "$site_name";
2206 if (defined $project) {
2207 $title .= " - " . to_utf8
($project);
2208 if (defined $action) {
2209 $title .= "/$action";
2210 if (defined $file_name) {
2211 $title .= " - " . esc_path
($file_name);
2212 if ($action eq "tree" && $file_name !~ m
|/$|) {
2219 # require explicit support from the UA if we are to send the page as
2220 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2221 # we have to do this because MSIE sometimes globs '*/*', pretending to
2222 # support xhtml+xml but choking when it gets what it asked for.
2223 if (defined $cgi->http('HTTP_ACCEPT') &&
2224 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2225 $cgi->Accept('application/xhtml+xml') != 0) {
2226 $content_type = 'application/xhtml+xml';
2228 $content_type = 'text/html';
2230 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2231 -status
=> $status, -expires
=> $expires);
2232 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2234 <?xml version="1.0" encoding="utf-8"?>
2235 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2236 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2237 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2238 <!-- git core binaries version $git_version -->
2240 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2241 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2242 <meta name="robots" content="index, nofollow"/>
2243 <title>$title</title>
2245 # print out each stylesheet that exist
2246 if (defined $stylesheet) {
2247 #provides backwards capability for those people who define style sheet in a config file
2248 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2250 foreach my $stylesheet (@stylesheets) {
2251 next unless $stylesheet;
2252 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2255 if (defined $project) {
2256 printf('<link rel="alternate" title="%s log RSS feed" '.
2257 'href="%s" type="application/rss+xml" />'."\n",
2258 esc_param
($project), href
(action
=>"rss"));
2259 printf('<link rel="alternate" title="%s log Atom feed" '.
2260 'href="%s" type="application/atom+xml" />'."\n",
2261 esc_param
($project), href
(action
=>"atom"));
2263 printf('<link rel="alternate" title="%s projects list" '.
2264 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2265 $site_name, href
(project
=>undef, action
=>"project_index"));
2266 printf('<link rel="alternate" title="%s projects feeds" '.
2267 'href="%s" type="text/x-opml"/>'."\n",
2268 $site_name, href
(project
=>undef, action
=>"opml"));
2270 if (defined $favicon) {
2271 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2277 if (-f
$site_header) {
2278 open (my $fd, $site_header);
2283 print "<div class=\"page_header\">\n" .
2284 $cgi->a({-href
=> esc_url
($logo_url),
2285 -title
=> $logo_label},
2286 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2287 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2288 if (defined $project) {
2289 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2290 if (defined $action) {
2297 my ($have_search) = gitweb_check_feature
('search');
2298 if ((defined $project) && ($have_search)) {
2299 if (!defined $searchtext) {
2303 if (defined $hash_base) {
2304 $search_hash = $hash_base;
2305 } elsif (defined $hash) {
2306 $search_hash = $hash;
2308 $search_hash = "HEAD";
2310 my $action = $my_uri;
2311 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2312 if ($use_pathinfo) {
2313 $action .= "/$project";
2315 $cgi->param("p", $project);
2317 $cgi->param("a", "search");
2318 $cgi->param("h", $search_hash);
2319 print $cgi->startform(-method => "get", -action
=> $action) .
2320 "<div class=\"search\">\n" .
2321 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2322 $cgi->hidden(-name
=> "a") . "\n" .
2323 $cgi->hidden(-name
=> "h") . "\n" .
2324 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2325 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2326 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2328 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2330 $cgi->end_form() . "\n";
2334 sub git_footer_html
{
2335 print "<div class=\"page_footer\">\n";
2336 if (defined $project) {
2337 my $descr = git_get_project_description
($project);
2338 if (defined $descr) {
2339 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2341 print $cgi->a({-href
=> href
(action
=>"rss"),
2342 -class => "rss_logo"}, "RSS") . " ";
2343 print $cgi->a({-href
=> href
(action
=>"atom"),
2344 -class => "rss_logo"}, "Atom") . "\n";
2346 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2347 -class => "rss_logo"}, "OPML") . " ";
2348 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2349 -class => "rss_logo"}, "TXT") . "\n";
2353 if (-f
$site_footer) {
2354 open (my $fd, $site_footer);
2364 my $status = shift || "403 Forbidden";
2365 my $error = shift || "Malformed query, file missing or permission denied";
2367 git_header_html
($status);
2369 <div class="page_body">
2379 ## ----------------------------------------------------------------------
2380 ## functions printing or outputting HTML: navigation
2382 sub git_print_page_nav
{
2383 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2384 $extra = '' if !defined $extra; # pager or formats
2386 my @navs = qw(summary shortlog log commit commitdiff tree);
2388 @navs = grep { $_ ne $suppress } @navs;
2391 my %arg = map { $_ => {action
=>$_} } @navs;
2392 if (defined $head) {
2393 for (qw(commit commitdiff)) {
2394 $arg{$_}{'hash'} = $head;
2396 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2397 for (qw(shortlog log)) {
2398 $arg{$_}{'hash'} = $head;
2402 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2403 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2405 print "<div class=\"page_nav\">\n" .
2407 map { $_ eq $current ?
2408 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2410 print "<br/>\n$extra<br/>\n" .
2414 sub format_paging_nav
{
2415 my ($action, $hash, $head, $page, $nrevs) = @_;
2419 if ($hash ne $head || $page) {
2420 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2422 $paging_nav .= "HEAD";
2426 $paging_nav .= " ⋅ " .
2427 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2428 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2430 $paging_nav .= " ⋅ prev";
2433 if ($nrevs >= (100 * ($page+1)-1)) {
2434 $paging_nav .= " ⋅ " .
2435 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2436 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2438 $paging_nav .= " ⋅ next";
2444 ## ......................................................................
2445 ## functions printing or outputting HTML: div
2447 sub git_print_header_div
{
2448 my ($action, $title, $hash, $hash_base) = @_;
2451 $args{'action'} = $action;
2452 $args{'hash'} = $hash if $hash;
2453 $args{'hash_base'} = $hash_base if $hash_base;
2455 print "<div class=\"header\">\n" .
2456 $cgi->a({-href
=> href
(%args), -class => "title"},
2457 $title ? $title : $action) .
2461 #sub git_print_authorship (\%) {
2462 sub git_print_authorship
{
2465 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2466 print "<div class=\"author_date\">" .
2467 esc_html
($co->{'author_name'}) .
2469 if ($ad{'hour_local'} < 6) {
2470 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2471 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2473 printf(" (%02d:%02d %s)",
2474 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2479 sub git_print_page_path
{
2485 print "<div class=\"page_path\">";
2486 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2487 -title
=> 'tree root'}, to_utf8
("[$project]"));
2489 if (defined $name) {
2490 my @dirname = split '/', $name;
2491 my $basename = pop @dirname;
2494 foreach my $dir (@dirname) {
2495 $fullname .= ($fullname ? '/' : '') . $dir;
2496 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2498 -title
=> $fullname}, esc_path
($dir));
2501 if (defined $type && $type eq 'blob') {
2502 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2504 -title
=> $name}, esc_path
($basename));
2505 } elsif (defined $type && $type eq 'tree') {
2506 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2508 -title
=> $name}, esc_path
($basename));
2511 print esc_path
($basename);
2514 print "<br/></div>\n";
2517 # sub git_print_log (\@;%) {
2518 sub git_print_log
($;%) {
2522 if ($opts{'-remove_title'}) {
2523 # remove title, i.e. first line of log
2526 # remove leading empty lines
2527 while (defined $log->[0] && $log->[0] eq "") {
2534 foreach my $line (@$log) {
2535 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2538 if (! $opts{'-remove_signoff'}) {
2539 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2542 # remove signoff lines
2549 # print only one empty line
2550 # do not print empty line after signoff
2552 next if ($empty || $signoff);
2558 print format_log_line_html
($line) . "<br/>\n";
2561 if ($opts{'-final_empty_line'}) {
2562 # end with single empty line
2563 print "<br/>\n" unless $empty;
2567 # return link target (what link points to)
2568 sub git_get_link_target
{
2573 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2577 $link_target = <$fd>;
2582 return $link_target;
2585 # given link target, and the directory (basedir) the link is in,
2586 # return target of link relative to top directory (top tree);
2587 # return undef if it is not possible (including absolute links).
2588 sub normalize_link_target
{
2589 my ($link_target, $basedir, $hash_base) = @_;
2591 # we can normalize symlink target only if $hash_base is provided
2592 return unless $hash_base;
2594 # absolute symlinks (beginning with '/') cannot be normalized
2595 return if (substr($link_target, 0, 1) eq '/');
2597 # normalize link target to path from top (root) tree (dir)
2600 $path = $basedir . '/' . $link_target;
2602 # we are in top (root) tree (dir)
2603 $path = $link_target;
2606 # remove //, /./, and /../
2608 foreach my $part (split('/', $path)) {
2609 # discard '.' and ''
2610 next if (!$part || $part eq '.');
2612 if ($part eq '..') {
2616 # link leads outside repository (outside top dir)
2620 push @path_parts, $part;
2623 $path = join('/', @path_parts);
2628 # print tree entry (row of git_tree), but without encompassing <tr> element
2629 sub git_print_tree_entry
{
2630 my ($t, $basedir, $hash_base, $have_blame) = @_;
2633 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2635 # The format of a table row is: mode list link. Where mode is
2636 # the mode of the entry, list is the name of the entry, an href,
2637 # and link is the action links of the entry.
2639 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2640 if ($t->{'type'} eq "blob") {
2641 print "<td class=\"list\">" .
2642 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2643 file_name
=>"$basedir$t->{'name'}", %base_key),
2644 -class => "list"}, esc_path
($t->{'name'}));
2645 if (S_ISLNK
(oct $t->{'mode'})) {
2646 my $link_target = git_get_link_target
($t->{'hash'});
2648 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2649 if (defined $norm_target) {
2651 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2652 file_name
=>$norm_target),
2653 -title
=> $norm_target}, esc_path
($link_target));
2655 print " -> " . esc_path
($link_target);
2660 print "<td class=\"link\">";
2661 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2662 file_name
=>"$basedir$t->{'name'}", %base_key)},
2666 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2667 file_name
=>"$basedir$t->{'name'}", %base_key)},
2670 if (defined $hash_base) {
2672 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2673 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2677 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2678 file_name
=>"$basedir$t->{'name'}")},
2682 } elsif ($t->{'type'} eq "tree") {
2683 print "<td class=\"list\">";
2684 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2685 file_name
=>"$basedir$t->{'name'}", %base_key)},
2686 esc_path
($t->{'name'}));
2688 print "<td class=\"link\">";
2689 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2690 file_name
=>"$basedir$t->{'name'}", %base_key)},
2692 if (defined $hash_base) {
2694 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2695 file_name
=>"$basedir$t->{'name'}")},
2702 ## ......................................................................
2703 ## functions printing large fragments of HTML
2705 sub fill_from_file_info
{
2706 my ($diff, @parents) = @_;
2708 $diff->{'from_file'} = [ ];
2709 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2710 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2711 if ($diff->{'status'}[$i] eq 'R' ||
2712 $diff->{'status'}[$i] eq 'C') {
2713 $diff->{'from_file'}[$i] =
2714 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2721 # parameters can be strings, or references to arrays of strings
2725 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2726 for (my $i = 0; $i < @$a; ++$i) {
2727 return 0 unless ($a->[$i] eq $b->[$i]);
2730 } elsif (!ref($a) && !ref($b)) {
2738 my $diffinfo = shift;
2740 return $diffinfo->{'to_id'} eq ('0' x
40);
2743 sub git_difftree_body
{
2744 my ($difftree, $hash, @parents) = @_;
2745 my ($parent) = $parents[0];
2746 my ($have_blame) = gitweb_check_feature
('blame');
2747 print "<div class=\"list_head\">\n";
2748 if ($#{$difftree} > 10) {
2749 print(($#{$difftree} + 1) . " files changed:\n");
2753 print "<table class=\"" .
2754 (@parents > 1 ? "combined " : "") .
2757 # header only for combined diff in 'commitdiff' view
2758 my $has_header = @parents > 1 && $action eq 'commitdiff';
2761 print "<thead><tr>\n" .
2762 "<th></th><th></th>\n"; # filename, patchN link
2763 for (my $i = 0; $i < @parents; $i++) {
2764 my $par = $parents[$i];
2766 $cgi->a({-href
=> href
(action
=>"commitdiff",
2767 hash
=>$hash, hash_parent
=>$par),
2768 -title
=> 'commitdiff to parent number ' .
2769 ($i+1) . ': ' . substr($par,0,7)},
2773 print "</tr></thead>\n<tbody>\n";
2778 foreach my $line (@{$difftree}) {
2780 if (ref($line) eq "HASH") {
2781 # pre-parsed (or generated by hand)
2784 $diff = parse_difftree_raw_line
($line);
2788 print "<tr class=\"dark\">\n";
2790 print "<tr class=\"light\">\n";
2794 if (exists $diff->{'nparents'}) { # combined diff
2796 fill_from_file_info
($diff, @parents)
2797 unless exists $diff->{'from_file'};
2799 if (!is_deleted
($diff)) {
2800 # file exists in the result (child) commit
2802 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2803 file_name
=>$diff->{'to_file'},
2805 -class => "list"}, esc_path
($diff->{'to_file'})) .
2809 esc_path
($diff->{'to_file'}) .
2813 if ($action eq 'commitdiff') {
2816 print "<td class=\"link\">" .
2817 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2822 my $has_history = 0;
2823 my $not_deleted = 0;
2824 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2825 my $hash_parent = $parents[$i];
2826 my $from_hash = $diff->{'from_id'}[$i];
2827 my $from_path = $diff->{'from_file'}[$i];
2828 my $status = $diff->{'status'}[$i];
2830 $has_history ||= ($status ne 'A');
2831 $not_deleted ||= ($status ne 'D');
2833 if ($status eq 'A') {
2834 print "<td class=\"link\" align=\"right\"> | </td>\n";
2835 } elsif ($status eq 'D') {
2836 print "<td class=\"link\">" .
2837 $cgi->a({-href
=> href
(action
=>"blob",
2840 file_name
=>$from_path)},
2844 if ($diff->{'to_id'} eq $from_hash) {
2845 print "<td class=\"link nochange\">";
2847 print "<td class=\"link\">";
2849 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2850 hash
=>$diff->{'to_id'},
2851 hash_parent
=>$from_hash,
2853 hash_parent_base
=>$hash_parent,
2854 file_name
=>$diff->{'to_file'},
2855 file_parent
=>$from_path)},
2861 print "<td class=\"link\">";
2863 print $cgi->a({-href
=> href
(action
=>"blob",
2864 hash
=>$diff->{'to_id'},
2865 file_name
=>$diff->{'to_file'},
2868 print " | " if ($has_history);
2871 print $cgi->a({-href
=> href
(action
=>"history",
2872 file_name
=>$diff->{'to_file'},
2879 next; # instead of 'else' clause, to avoid extra indent
2881 # else ordinary diff
2883 my ($to_mode_oct, $to_mode_str, $to_file_type);
2884 my ($from_mode_oct, $from_mode_str, $from_file_type);
2885 if ($diff->{'to_mode'} ne ('0' x
6)) {
2886 $to_mode_oct = oct $diff->{'to_mode'};
2887 if (S_ISREG
($to_mode_oct)) { # only for regular file
2888 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2890 $to_file_type = file_type
($diff->{'to_mode'});
2892 if ($diff->{'from_mode'} ne ('0' x
6)) {
2893 $from_mode_oct = oct $diff->{'from_mode'};
2894 if (S_ISREG
($to_mode_oct)) { # only for regular file
2895 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2897 $from_file_type = file_type
($diff->{'from_mode'});
2900 if ($diff->{'status'} eq "A") { # created
2901 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2902 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2903 $mode_chng .= "]</span>";
2905 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2906 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2907 -class => "list"}, esc_path
($diff->{'file'}));
2909 print "<td>$mode_chng</td>\n";
2910 print "<td class=\"link\">";
2911 if ($action eq 'commitdiff') {
2914 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2917 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2918 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2922 } elsif ($diff->{'status'} eq "D") { # deleted
2923 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2925 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2926 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2927 -class => "list"}, esc_path
($diff->{'file'}));
2929 print "<td>$mode_chng</td>\n";
2930 print "<td class=\"link\">";
2931 if ($action eq 'commitdiff') {
2934 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2937 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2938 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2941 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2942 file_name
=>$diff->{'file'})},
2945 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2946 file_name
=>$diff->{'file'})},
2950 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2951 my $mode_chnge = "";
2952 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2953 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2954 if ($from_file_type ne $to_file_type) {
2955 $mode_chnge .= " from $from_file_type to $to_file_type";
2957 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2958 if ($from_mode_str && $to_mode_str) {
2959 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2960 } elsif ($to_mode_str) {
2961 $mode_chnge .= " mode: $to_mode_str";
2964 $mode_chnge .= "]</span>\n";
2967 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2968 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2969 -class => "list"}, esc_path
($diff->{'file'}));
2971 print "<td>$mode_chnge</td>\n";
2972 print "<td class=\"link\">";
2973 if ($action eq 'commitdiff') {
2976 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2978 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2979 # "commit" view and modified file (not onlu mode changed)
2980 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2981 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2982 hash_base
=>$hash, hash_parent_base
=>$parent,
2983 file_name
=>$diff->{'file'})},
2987 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2988 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2991 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2992 file_name
=>$diff->{'file'})},
2995 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2996 file_name
=>$diff->{'file'})},
3000 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3001 my %status_name = ('R' => 'moved', 'C' => 'copied');
3002 my $nstatus = $status_name{$diff->{'status'}};
3004 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3005 # mode also for directories, so we cannot use $to_mode_str
3006 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3009 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3010 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3011 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3012 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3013 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3014 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3015 -class => "list"}, esc_path
($diff->{'from_file'})) .
3016 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3017 "<td class=\"link\">";
3018 if ($action eq 'commitdiff') {
3021 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3023 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3024 # "commit" view and modified file (not only pure rename or copy)
3025 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3026 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3027 hash_base
=>$hash, hash_parent_base
=>$parent,
3028 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3032 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3033 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3036 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3037 file_name
=>$diff->{'to_file'})},
3040 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3041 file_name
=>$diff->{'to_file'})},
3045 } # we should not encounter Unmerged (U) or Unknown (X) status
3048 print "</tbody>" if $has_header;
3052 sub git_patchset_body
{
3053 my ($fd, $difftree, $hash, @hash_parents) = @_;
3054 my ($hash_parent) = $hash_parents[0];
3057 my $patch_number = 0;
3062 print "<div class=\"patchset\">\n";
3064 # skip to first patch
3065 while ($patch_line = <$fd>) {
3068 last if ($patch_line =~ m/^diff /);
3072 while ($patch_line) {
3074 my ($from_id, $to_id);
3077 #assert($patch_line =~ m/^diff /) if DEBUG;
3078 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3080 push @diff_header, $patch_line;
3082 # extended diff header
3084 while ($patch_line = <$fd>) {
3087 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3089 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3092 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3093 $from_id = [ split(',', $1) ];
3097 push @diff_header, $patch_line;
3099 my $last_patch_line = $patch_line;
3101 # check if current patch belong to current raw line
3102 # and parse raw git-diff line if needed
3103 if (defined $diffinfo &&
3104 defined $from_id && defined $to_id &&
3105 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3106 $diffinfo->{'to_id'} eq $to_id) {
3107 # this is continuation of a split patch
3108 print "<div class=\"patch cont\">\n";
3110 # advance raw git-diff output if needed
3111 $patch_idx++ if defined $diffinfo;
3113 # compact combined diff output can have some patches skipped
3114 # find which patch (using pathname of result) we are at now
3116 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3121 # read and prepare patch information
3122 if (ref($difftree->[$patch_idx]) eq "HASH") {
3123 # pre-parsed (or generated by hand)
3124 $diffinfo = $difftree->[$patch_idx];
3126 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3129 # check if current raw line has no patch (it got simplified)
3130 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3131 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3132 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3133 "</div>\n"; # class="patch"
3138 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3139 $patch_idx > $#$difftree);
3140 # modifies %from, %to hashes
3141 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3142 if ($diffinfo->{'nparents'}) {
3146 fill_from_file_info
($diffinfo, @hash_parents)
3147 unless exists $diffinfo->{'from_file'};
3148 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3149 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3150 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3151 $from{'href'}[$i] = href
(action
=>"blob",
3152 hash_base
=>$hash_parents[$i],
3153 hash
=>$diffinfo->{'from_id'}[$i],
3154 file_name
=>$from{'file'}[$i]);
3156 $from{'href'}[$i] = undef;
3160 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3161 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3162 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3163 hash
=>$diffinfo->{'from_id'},
3164 file_name
=>$from{'file'});
3166 delete $from{'href'};
3170 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3171 if (!is_deleted
($diffinfo)) { # file exists in result
3172 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3173 hash
=>$diffinfo->{'to_id'},
3174 file_name
=>$to{'file'});
3178 # this is first patch for raw difftree line with $patch_idx index
3179 # we index @$difftree array from 0, but number patches from 1
3180 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3183 # print "git diff" header
3184 $patch_line = shift @diff_header;
3185 print format_git_diff_header_line
($patch_line, $diffinfo,
3188 # print extended diff header
3189 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3191 foreach $patch_line (@diff_header) {
3192 print format_extended_diff_header_line
($patch_line, $diffinfo,
3195 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3197 # from-file/to-file diff header
3198 $patch_line = $last_patch_line;
3199 if (! $patch_line) {
3200 print "</div>\n"; # class="patch"
3203 next PATCH
if ($patch_line =~ m/^diff /);
3204 #assert($patch_line =~ m/^---/) if DEBUG;
3205 #assert($patch_line eq $last_patch_line) if DEBUG;
3207 $patch_line = <$fd>;
3209 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3211 print format_diff_from_to_header
($last_patch_line, $patch_line,
3212 $diffinfo, \
%from, \
%to,
3217 while ($patch_line = <$fd>) {
3220 next PATCH
if ($patch_line =~ m/^diff /);
3222 print format_diff_line
($patch_line, \
%from, \
%to);
3226 print "</div>\n"; # class="patch"
3229 # for compact combined (--cc) format, with chunk and patch simpliciaction
3230 # patchset might be empty, but there might be unprocessed raw lines
3231 for ($patch_idx++ if $patch_number > 0;
3232 $patch_idx < @$difftree;
3234 # read and prepare patch information
3235 if (ref($difftree->[$patch_idx]) eq "HASH") {
3236 # pre-parsed (or generated by hand)
3237 $diffinfo = $difftree->[$patch_idx];
3239 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3242 # generate anchor for "patch" links in difftree / whatchanged part
3243 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3244 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3245 "</div>\n"; # class="patch"
3250 if ($patch_number == 0) {
3251 if (@hash_parents > 1) {
3252 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3254 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3258 print "</div>\n"; # class="patchset"
3261 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3263 sub git_project_list_body
{
3264 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3266 my ($check_forks) = gitweb_check_feature
('forks');
3269 foreach my $pr (@$projlist) {
3270 my (@aa) = git_get_last_activity
($pr->{'path'});
3274 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3275 if (!defined $pr->{'descr'}) {
3276 my $descr = git_get_project_description
($pr->{'path'}) || "";
3277 $pr->{'descr_long'} = to_utf8
($descr);
3278 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3280 if (!defined $pr->{'owner'}) {
3281 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3284 my $pname = $pr->{'path'};
3285 if (($pname =~ s/\.git$//) &&
3286 ($pname !~ /\/$/) &&
3287 (-d
"$projectroot/$pname")) {
3288 $pr->{'forks'} = "-d $projectroot/$pname";
3294 push @projects, $pr;
3297 $order ||= $default_projects_order;
3298 $from = 0 unless defined $from;
3299 $to = $#projects if (!defined $to || $#projects < $to);
3301 print "<table class=\"project_list\">\n";
3302 unless ($no_header) {
3305 print "<th></th>\n";
3307 if ($order eq "project") {
3308 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3309 print "<th>Project</th>\n";
3312 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3313 -class => "header"}, "Project") .
3316 if ($order eq "descr") {
3317 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3318 print "<th>Description</th>\n";
3321 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3322 -class => "header"}, "Description") .
3325 if ($order eq "owner") {
3326 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3327 print "<th>Owner</th>\n";
3330 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3331 -class => "header"}, "Owner") .
3334 if ($order eq "age") {
3335 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3336 print "<th>Last Change</th>\n";
3339 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3340 -class => "header"}, "Last Change") .
3343 print "<th></th>\n" .
3347 for (my $i = $from; $i <= $to; $i++) {
3348 my $pr = $projects[$i];
3350 print "<tr class=\"dark\">\n";
3352 print "<tr class=\"light\">\n";
3357 if ($pr->{'forks'}) {
3358 print "<!-- $pr->{'forks'} -->\n";
3359 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3363 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3364 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3365 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3366 -class => "list", -title
=> $pr->{'descr_long'}},
3367 esc_html
($pr->{'descr'})) . "</td>\n" .
3368 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3369 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3370 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3371 "<td class=\"link\">" .
3372 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3373 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3374 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3375 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3376 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3380 if (defined $extra) {
3383 print "<td></td>\n";
3385 print "<td colspan=\"5\">$extra</td>\n" .
3391 sub git_shortlog_body
{
3392 # uses global variable $project
3393 my ($commitlist, $from, $to, $refs, $extra) = @_;
3395 $from = 0 unless defined $from;
3396 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3398 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3400 for (my $i = $from; $i <= $to; $i++) {
3401 my %co = %{$commitlist->[$i]};
3402 my $commit = $co{'id'};
3403 my $ref = format_ref_marker
($refs, $commit);
3405 print "<tr class=\"dark\">\n";
3407 print "<tr class=\"light\">\n";
3410 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3411 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3412 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3414 print format_subject_html
($co{'title'}, $co{'title_short'},
3415 href
(action
=>"commit", hash
=>$commit), $ref);
3417 "<td class=\"link\">" .
3418 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3419 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3420 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3421 my $snapshot_links = format_snapshot_links
($commit);
3422 if (defined $snapshot_links) {
3423 print " | " . $snapshot_links;
3428 if (defined $extra) {
3430 "<td colspan=\"4\">$extra</td>\n" .
3436 sub git_history_body
{
3437 # Warning: assumes constant type (blob or tree) during history
3438 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3440 $from = 0 unless defined $from;
3441 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3443 print "<table class=\"history\" cellspacing=\"0\">\n";
3445 for (my $i = $from; $i <= $to; $i++) {
3446 my %co = %{$commitlist->[$i]};
3450 my $commit = $co{'id'};
3452 my $ref = format_ref_marker
($refs, $commit);
3455 print "<tr class=\"dark\">\n";
3457 print "<tr class=\"light\">\n";
3460 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3461 # shortlog uses chop_str($co{'author_name'}, 10)
3462 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3464 # originally git_history used chop_str($co{'title'}, 50)
3465 print format_subject_html
($co{'title'}, $co{'title_short'},
3466 href
(action
=>"commit", hash
=>$commit), $ref);
3468 "<td class=\"link\">" .
3469 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3470 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3472 if ($ftype eq 'blob') {
3473 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3474 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3475 if (defined $blob_current && defined $blob_parent &&
3476 $blob_current ne $blob_parent) {
3478 $cgi->a({-href
=> href
(action
=>"blobdiff",
3479 hash
=>$blob_current, hash_parent
=>$blob_parent,
3480 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3481 file_name
=>$file_name)},
3488 if (defined $extra) {
3490 "<td colspan=\"4\">$extra</td>\n" .
3497 # uses global variable $project
3498 my ($taglist, $from, $to, $extra) = @_;
3499 $from = 0 unless defined $from;
3500 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3502 print "<table class=\"tags\" cellspacing=\"0\">\n";
3504 for (my $i = $from; $i <= $to; $i++) {
3505 my $entry = $taglist->[$i];
3507 my $comment = $tag{'subject'};
3509 if (defined $comment) {
3510 $comment_short = chop_str
($comment, 30, 5);
3513 print "<tr class=\"dark\">\n";
3515 print "<tr class=\"light\">\n";
3518 if (defined $tag{'age'}) {
3519 print "<td><i>$tag{'age'}</i></td>\n";
3521 print "<td></td>\n";
3524 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3525 -class => "list name"}, esc_html
($tag{'name'})) .
3528 if (defined $comment) {
3529 print format_subject_html
($comment, $comment_short,
3530 href
(action
=>"tag", hash
=>$tag{'id'}));
3533 "<td class=\"selflink\">";
3534 if ($tag{'type'} eq "tag") {
3535 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3540 "<td class=\"link\">" . " | " .
3541 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3542 if ($tag{'reftype'} eq "commit") {
3543 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3544 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3545 } elsif ($tag{'reftype'} eq "blob") {
3546 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3551 if (defined $extra) {
3553 "<td colspan=\"5\">$extra</td>\n" .
3559 sub git_heads_body
{
3560 # uses global variable $project
3561 my ($headlist, $head, $from, $to, $extra) = @_;
3562 $from = 0 unless defined $from;
3563 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3565 print "<table class=\"heads\" cellspacing=\"0\">\n";
3567 for (my $i = $from; $i <= $to; $i++) {
3568 my $entry = $headlist->[$i];
3570 my $curr = $ref{'id'} eq $head;
3572 print "<tr class=\"dark\">\n";
3574 print "<tr class=\"light\">\n";
3577 print "<td><i>$ref{'age'}</i></td>\n" .
3578 ($curr ? "<td class=\"current_head\">" : "<td>") .
3579 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3580 -class => "list name"},esc_html
($ref{'name'})) .
3582 "<td class=\"link\">" .
3583 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3584 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3585 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3589 if (defined $extra) {
3591 "<td colspan=\"3\">$extra</td>\n" .
3597 sub git_search_grep_body
{
3598 my ($commitlist, $from, $to, $extra) = @_;
3599 $from = 0 unless defined $from;
3600 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3602 print "<table class=\"grep\" cellspacing=\"0\">\n";
3604 for (my $i = $from; $i <= $to; $i++) {
3605 my %co = %{$commitlist->[$i]};
3609 my $commit = $co{'id'};
3611 print "<tr class=\"dark\">\n";
3613 print "<tr class=\"light\">\n";
3616 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3617 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3619 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3620 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3621 my $comment = $co{'comment'};
3622 foreach my $line (@$comment) {
3623 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3624 my $lead = esc_html
($1) || "";
3625 $lead = chop_str
($lead, 30, 10);
3626 my $match = esc_html
($2) || "";
3627 my $trail = esc_html
($3) || "";
3628 $trail = chop_str
($trail, 30, 10);
3629 my $text = "$lead<span class=\"match\">$match</span>$trail";
3630 print chop_str
($text, 80, 5) . "<br/>\n";
3634 "<td class=\"link\">" .
3635 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3637 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3641 if (defined $extra) {
3643 "<td colspan=\"3\">$extra</td>\n" .
3649 ## ======================================================================
3650 ## ======================================================================
3653 sub git_project_list
{
3654 my $order = $cgi->param('o');
3655 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3656 die_error
(undef, "Unknown order parameter");
3659 my @list = git_get_projects_list
();
3661 die_error
(undef, "No projects found");
3665 if (-f
$home_text) {
3666 print "<div class=\"index_include\">\n";
3667 open (my $fd, $home_text);
3672 git_project_list_body
(\
@list, $order);
3677 my $order = $cgi->param('o');
3678 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3679 die_error
(undef, "Unknown order parameter");
3682 my @list = git_get_projects_list
($project);
3684 die_error
(undef, "No forks found");
3688 git_print_page_nav
('','');
3689 git_print_header_div
('summary', "$project forks");
3690 git_project_list_body
(\
@list, $order);
3694 sub git_project_index
{
3695 my @projects = git_get_projects_list
($project);
3698 -type
=> 'text/plain',
3699 -charset
=> 'utf-8',
3700 -content_disposition
=> 'inline; filename="index.aux"');
3702 foreach my $pr (@projects) {
3703 if (!exists $pr->{'owner'}) {
3704 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3707 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3708 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3709 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3710 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3714 print "$path $owner\n";
3719 my $descr = git_get_project_description
($project) || "none";
3720 my %co = parse_commit
("HEAD");
3721 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3722 my $head = $co{'id'};
3724 my $owner = git_get_project_owner
($project);
3726 my $refs = git_get_references
();
3727 # These get_*_list functions return one more to allow us to see if
3728 # there are more ...
3729 my @taglist = git_get_tags_list
(16);
3730 my @headlist = git_get_heads_list
(16);
3732 my ($check_forks) = gitweb_check_feature
('forks');
3735 @forklist = git_get_projects_list
($project);
3739 git_print_page_nav
('summary','', $head);
3741 print "<div class=\"title\"> </div>\n";
3742 print "<table cellspacing=\"0\">\n" .
3743 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3744 "<tr><td>owner</td><td>$owner</td></tr>\n";
3745 if (defined $cd{'rfc2822'}) {
3746 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3749 # use per project git URL list in $projectroot/$project/cloneurl
3750 # or make project git URL from git base URL and project name
3751 my $url_tag = "URL";
3752 my @url_list = git_get_project_url_list
($project);
3753 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3754 foreach my $git_url (@url_list) {
3755 next unless $git_url;
3756 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3761 if (-s
"$projectroot/$project/README.html") {
3762 if (open my $fd, "$projectroot/$project/README.html") {
3763 print "<div class=\"title\">readme</div>\n";
3764 print $_ while (<$fd>);
3769 # we need to request one more than 16 (0..15) to check if
3771 my @commitlist = $head ? parse_commits
($head, 17) : ();
3773 git_print_header_div
('shortlog');
3774 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3775 $#commitlist <= 15 ? undef :
3776 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3780 git_print_header_div
('tags');
3781 git_tags_body
(\
@taglist, 0, 15,
3782 $#taglist <= 15 ? undef :
3783 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3787 git_print_header_div
('heads');
3788 git_heads_body
(\
@headlist, $head, 0, 15,
3789 $#headlist <= 15 ? undef :
3790 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3794 git_print_header_div
('forks');
3795 git_project_list_body
(\
@forklist, undef, 0, 15,
3796 $#forklist <= 15 ? undef :
3797 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3805 my $head = git_get_head_hash
($project);
3807 git_print_page_nav
('','', $head,undef,$head);
3808 my %tag = parse_tag
($hash);
3811 die_error
(undef, "Unknown tag object");
3814 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3815 print "<div class=\"title_text\">\n" .
3816 "<table cellspacing=\"0\">\n" .
3818 "<td>object</td>\n" .
3819 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3820 $tag{'object'}) . "</td>\n" .
3821 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3822 $tag{'type'}) . "</td>\n" .
3824 if (defined($tag{'author'})) {
3825 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3826 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3827 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3828 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3831 print "</table>\n\n" .
3833 print "<div class=\"page_body\">";
3834 my $comment = $tag{'comment'};
3835 foreach my $line (@$comment) {
3837 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3847 my ($have_blame) = gitweb_check_feature
('blame');
3849 die_error
('403 Permission denied', "Permission denied");
3851 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3852 $hash_base ||= git_get_head_hash
($project);
3853 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3854 my %co = parse_commit
($hash_base)
3855 or die_error
(undef, "Reading commit failed");
3856 if (!defined $hash) {
3857 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3858 or die_error
(undef, "Error looking up file");
3860 $ftype = git_get_type
($hash);
3861 if ($ftype !~ "blob") {
3862 die_error
('400 Bad Request', "Object is not a blob");
3864 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3865 $file_name, $hash_base)
3866 or die_error
(undef, "Open git-blame failed");
3869 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3872 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3875 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3877 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3878 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3879 git_print_page_path
($file_name, $ftype, $hash_base);
3880 my @rev_color = (qw(light2 dark2));
3881 my $num_colors = scalar(@rev_color);
3882 my $current_color = 0;
3885 <div class="page_body">
3886 <table class="blame">
3887 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3892 last unless defined $_;
3893 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3894 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3895 if (!exists $metainfo{$full_rev}) {
3896 $metainfo{$full_rev} = {};
3898 my $meta = $metainfo{$full_rev};
3901 if (/^(\S+) (.*)$/) {
3907 my $rev = substr($full_rev, 0, 8);
3908 my $author = $meta->{'author'};
3909 my %date = parse_date
($meta->{'author-time'},
3910 $meta->{'author-tz'});
3911 my $date = $date{'iso-tz'};
3913 $current_color = ++$current_color % $num_colors;
3915 print "<tr class=\"$rev_color[$current_color]\">\n";
3917 print "<td class=\"sha1\"";
3918 print " title=\"". esc_html
($author) . ", $date\"";
3919 print " rowspan=\"$group_size\"" if ($group_size > 1);
3921 print $cgi->a({-href
=> href
(action
=>"commit",
3923 file_name
=>$file_name)},
3927 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3928 or die_error
(undef, "Open git-rev-parse failed");
3929 my $parent_commit = <$dd>;
3931 chomp($parent_commit);
3932 my $blamed = href
(action
=> 'blame',
3933 file_name
=> $meta->{'filename'},
3934 hash_base
=> $parent_commit);
3935 print "<td class=\"linenr\">";
3936 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3938 -class => "linenr" },
3941 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3947 or print "Reading blob failed\n";
3954 my ($have_blame) = gitweb_check_feature
('blame');
3956 die_error
('403 Permission denied', "Permission denied");
3958 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3959 $hash_base ||= git_get_head_hash
($project);
3960 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3961 my %co = parse_commit
($hash_base)
3962 or die_error
(undef, "Reading commit failed");
3963 if (!defined $hash) {
3964 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3965 or die_error
(undef, "Error lookup file");
3967 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3968 or die_error
(undef, "Open git-annotate failed");
3971 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3974 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3977 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3979 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3980 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3981 git_print_page_path
($file_name, 'blob', $hash_base);
3982 print "<div class=\"page_body\">\n";
3984 <table class="blame">
3993 my @line_class = (qw(light dark));
3994 my $line_class_len = scalar (@line_class);
3995 my $line_class_num = $#line_class;
3996 while (my $line = <$fd>) {
4008 $line_class_num = ($line_class_num + 1) % $line_class_len;
4010 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4017 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4020 $short_rev = substr ($long_rev, 0, 8);
4021 $age = time () - $time;
4022 $age_str = age_string
($age);
4023 $age_str =~ s/ / /g;
4024 $age_class = age_class
($age);
4025 $author = esc_html
($author);
4026 $author =~ s/ / /g;
4028 $data = untabify
($data);
4029 $data = esc_html
($data);
4032 <tr class="$line_class[$line_class_num]">
4033 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4034 <td class="$age_class">$age_str</td>
4036 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4037 <td class="pre">$data</td>
4040 } # while (my $line = <$fd>)
4041 print "</table>\n\n";
4043 or print "Reading blob failed.\n";
4049 my $head = git_get_head_hash
($project);
4051 git_print_page_nav
('','', $head,undef,$head);
4052 git_print_header_div
('summary', $project);
4054 my @tagslist = git_get_tags_list
();
4056 git_tags_body
(\
@tagslist);
4062 my $head = git_get_head_hash
($project);
4064 git_print_page_nav
('','', $head,undef,$head);
4065 git_print_header_div
('summary', $project);
4067 my @headslist = git_get_heads_list
();
4069 git_heads_body
(\
@headslist, $head);
4074 sub git_blob_plain
{
4077 if (!defined $hash) {
4078 if (defined $file_name) {
4079 my $base = $hash_base || git_get_head_hash
($project);
4080 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4081 or die_error
(undef, "Error lookup file");
4083 die_error
(undef, "No file name defined");
4085 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4086 # blobs defined by non-textual hash id's can be cached
4091 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4092 or die_error
(undef, "Couldn't cat $file_name, $hash");
4094 $type ||= blob_mimetype
($fd, $file_name);
4096 # save as filename, even when no $file_name is given
4097 my $save_as = "$hash";
4098 if (defined $file_name) {
4099 $save_as = $file_name;
4100 } elsif ($type =~ m/^text\//) {
4107 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4109 binmode STDOUT
, ':raw';
4111 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4119 if (!defined $hash) {
4120 if (defined $file_name) {
4121 my $base = $hash_base || git_get_head_hash
($project);
4122 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4123 or die_error
(undef, "Error lookup file");
4125 die_error
(undef, "No file name defined");
4127 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4128 # blobs defined by non-textual hash id's can be cached
4132 my ($have_blame) = gitweb_check_feature
('blame');
4133 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4134 or die_error
(undef, "Couldn't cat $file_name, $hash");
4135 my $mimetype = blob_mimetype
($fd, $file_name);
4136 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4138 return git_blob_plain
($mimetype);
4140 # we can have blame only for text/* mimetype
4141 $have_blame &&= ($mimetype =~ m!^text/!);
4143 git_header_html
(undef, $expires);
4144 my $formats_nav = '';
4145 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4146 if (defined $file_name) {
4149 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4150 hash
=>$hash, file_name
=>$file_name)},
4155 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4156 hash
=>$hash, file_name
=>$file_name)},
4159 $cgi->a({-href
=> href
(action
=>"blob_plain",
4160 hash
=>$hash, file_name
=>$file_name)},
4163 $cgi->a({-href
=> href
(action
=>"blob",
4164 hash_base
=>"HEAD", file_name
=>$file_name)},
4168 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4170 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4171 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4173 print "<div class=\"page_nav\">\n" .
4174 "<br/><br/></div>\n" .
4175 "<div class=\"title\">$hash</div>\n";
4177 git_print_page_path
($file_name, "blob", $hash_base);
4178 print "<div class=\"page_body\">\n";
4179 if ($mimetype =~ m!^text/!) {
4181 while (my $line = <$fd>) {
4184 $line = untabify
($line);
4185 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4186 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4188 } elsif ($mimetype =~ m!^image/!) {
4189 print qq
!<img type
="$mimetype"!;
4191 print qq
! alt
="$file_name" title
="$file_name"!;
4194 href(action=>"blob_plain
", hash=>$hash,
4195 hash_base=>$hash_base, file_name=>$file_name) .
4199 or print "Reading blob failed.\n";
4205 if (!defined $hash_base) {
4206 $hash_base = "HEAD";
4208 if (!defined $hash) {
4209 if (defined $file_name) {
4210 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4216 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4217 or die_error
(undef, "Open git-ls-tree failed");
4218 my @entries = map { chomp; $_ } <$fd>;
4219 close $fd or die_error
(undef, "Reading tree failed");
4222 my $refs = git_get_references
();
4223 my $ref = format_ref_marker
($refs, $hash_base);
4226 my ($have_blame) = gitweb_check_feature
('blame');
4227 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4229 if (defined $file_name) {
4231 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4232 hash
=>$hash, file_name
=>$file_name)},
4234 $cgi->a({-href
=> href
(action
=>"tree",
4235 hash_base
=>"HEAD", file_name
=>$file_name)},
4238 my $snapshot_links = format_snapshot_links
($hash);
4239 if (defined $snapshot_links) {
4240 # FIXME: Should be available when we have no hash base as well.
4241 push @views_nav, $snapshot_links;
4243 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4244 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4247 print "<div class=\"page_nav\">\n";
4248 print "<br/><br/></div>\n";
4249 print "<div class=\"title\">$hash</div>\n";
4251 if (defined $file_name) {
4252 $basedir = $file_name;
4253 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4257 git_print_page_path
($file_name, 'tree', $hash_base);
4258 print "<div class=\"page_body\">\n";
4259 print "<table cellspacing=\"0\">\n";
4261 # '..' (top directory) link if possible
4262 if (defined $hash_base &&
4263 defined $file_name && $file_name =~ m![^/]+$!) {
4265 print "<tr class=\"dark\">\n";
4267 print "<tr class=\"light\">\n";
4271 my $up = $file_name;
4272 $up =~ s!/?[^/]+$!!;
4273 undef $up unless $up;
4274 # based on git_print_tree_entry
4275 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4276 print '<td class="list">';
4277 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4281 print "<td class=\"link\"></td>\n";
4285 foreach my $line (@entries) {
4286 my %t = parse_ls_tree_line
($line, -z
=> 1);
4289 print "<tr class=\"dark\">\n";
4291 print "<tr class=\"light\">\n";
4295 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4299 print "</table>\n" .
4305 my @supported_fmts = gitweb_check_feature
('snapshot');
4307 my $format = $cgi->param('sf');
4308 unless ($format =~ m/[a-z0-9]+/
4309 && exists($known_snapshot_formats{$format})
4310 && grep($_ eq $format, @supported_fmts)) {
4311 die_error
(undef, "Unsupported snapshot format");
4314 if (!defined $hash) {
4315 $hash = git_get_head_hash
($project);
4318 my $git_command = git_cmd_str
();
4319 my $name = $project;
4320 $name =~ s
,([^/])/*\
.git
$,$1,;
4321 $name = basename
($name);
4322 my $filename = to_utf8
($name);
4323 $name =~ s/\047/\047\\\047\047/g;
4325 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4326 $cmd = "$git_command archive " .
4327 "--format=$known_snapshot_formats{$format}{'format'}" .
4328 "--prefix=\'$name\'/ $hash";
4329 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4330 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4334 -type
=> $known_snapshot_formats{$format}{'type'},
4335 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4336 -status
=> '200 OK');
4338 open my $fd, "-|", $cmd
4339 or die_error
(undef, "Execute git-archive failed");
4340 binmode STDOUT
, ':raw';
4342 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4347 my $head = git_get_head_hash
($project);
4348 if (!defined $hash) {
4351 if (!defined $page) {
4354 my $refs = git_get_references
();
4356 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4358 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4361 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4364 my %co = parse_commit
($hash);
4366 git_print_header_div
('summary', $project);
4367 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4369 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4370 for (my $i = 0; $i <= $to; $i++) {
4371 my %co = %{$commitlist[$i]};
4373 my $commit = $co{'id'};
4374 my $ref = format_ref_marker
($refs, $commit);
4375 my %ad = parse_date
($co{'author_epoch'});
4376 git_print_header_div
('commit',
4377 "<span class=\"age\">$co{'age_string'}</span>" .
4378 esc_html
($co{'title'}) . $ref,
4380 print "<div class=\"title_text\">\n" .
4381 "<div class=\"log_link\">\n" .
4382 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4384 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4386 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4389 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4392 print "<div class=\"log_body\">\n";
4393 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4396 if ($#commitlist >= 100) {
4397 print "<div class=\"page_nav\">\n";
4398 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4399 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4406 $hash ||= $hash_base || "HEAD";
4407 my %co = parse_commit
($hash);
4409 die_error
(undef, "Unknown commit object");
4411 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4412 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4414 my $parent = $co{'parent'};
4415 my $parents = $co{'parents'}; # listref
4417 # we need to prepare $formats_nav before any parameter munging
4419 if (!defined $parent) {
4421 $formats_nav .= '(initial)';
4422 } elsif (@$parents == 1) {
4423 # single parent commit
4426 $cgi->a({-href
=> href
(action
=>"commit",
4428 esc_html
(substr($parent, 0, 7))) .
4435 $cgi->a({-href
=> href
(action
=>"commit",
4437 esc_html
(substr($_, 0, 7)));
4442 if (!defined $parent) {
4446 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4448 (@$parents <= 1 ? $parent : '-c'),
4450 or die_error
(undef, "Open git-diff-tree failed");
4451 @difftree = map { chomp; $_ } <$fd>;
4452 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4454 # non-textual hash id's can be cached
4456 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4459 my $refs = git_get_references
();
4460 my $ref = format_ref_marker
($refs, $co{'id'});
4462 git_header_html
(undef, $expires);
4463 git_print_page_nav
('commit', '',
4464 $hash, $co{'tree'}, $hash,
4467 if (defined $co{'parent'}) {
4468 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4470 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4472 print "<div class=\"title_text\">\n" .
4473 "<table cellspacing=\"0\">\n";
4474 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4476 "<td></td><td> $ad{'rfc2822'}";
4477 if ($ad{'hour_local'} < 6) {
4478 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4479 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4481 printf(" (%02d:%02d %s)",
4482 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4486 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4487 print "<tr><td></td><td> $cd{'rfc2822'}" .
4488 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4490 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4493 "<td class=\"sha1\">" .
4494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4495 class => "list"}, $co{'tree'}) .
4497 "<td class=\"link\">" .
4498 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4500 my $snapshot_links = format_snapshot_links
($hash);
4501 if (defined $snapshot_links) {
4502 print " | " . $snapshot_links;
4507 foreach my $par (@$parents) {
4510 "<td class=\"sha1\">" .
4511 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4512 class => "list"}, $par) .
4514 "<td class=\"link\">" .
4515 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4517 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4524 print "<div class=\"page_body\">\n";
4525 git_print_log
($co{'comment'});
4528 git_difftree_body
(\
@difftree, $hash, @$parents);
4534 # object is defined by:
4535 # - hash or hash_base alone
4536 # - hash_base and file_name
4539 # - hash or hash_base alone
4540 if ($hash || ($hash_base && !defined $file_name)) {
4541 my $object_id = $hash || $hash_base;
4543 my $git_command = git_cmd_str
();
4544 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4545 or die_error
('404 Not Found', "Object does not exist");
4549 or die_error
('404 Not Found', "Object does not exist");
4551 # - hash_base and file_name
4552 } elsif ($hash_base && defined $file_name) {
4553 $file_name =~ s
,/+$,,;
4555 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4556 or die_error
('404 Not Found', "Base object does not exist");
4558 # here errors should not hapen
4559 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4560 or die_error
(undef, "Open git-ls-tree failed");
4564 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4565 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4566 die_error
('404 Not Found', "File or directory for given base does not exist");
4571 die_error
('404 Not Found', "Not enough information to find object");
4574 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4575 hash
=>$hash, hash_base
=>$hash_base,
4576 file_name
=>$file_name),
4577 -status
=> '302 Found');
4581 my $format = shift || 'html';
4588 # preparing $fd and %diffinfo for git_patchset_body
4590 if (defined $hash_base && defined $hash_parent_base) {
4591 if (defined $file_name) {
4593 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4594 $hash_parent_base, $hash_base,
4595 "--", (defined $file_parent ? $file_parent : ()), $file_name
4596 or die_error
(undef, "Open git-diff-tree failed");
4597 @difftree = map { chomp; $_ } <$fd>;
4599 or die_error
(undef, "Reading git-diff-tree failed");
4601 or die_error
('404 Not Found', "Blob diff not found");
4603 } elsif (defined $hash &&
4604 $hash =~ /[0-9a-fA-F]{40}/) {
4605 # try to find filename from $hash
4607 # read filtered raw output
4608 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4609 $hash_parent_base, $hash_base, "--"
4610 or die_error
(undef, "Open git-diff-tree failed");
4612 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4614 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4615 map { chomp; $_ } <$fd>;
4617 or die_error
(undef, "Reading git-diff-tree failed");
4619 or die_error
('404 Not Found', "Blob diff not found");
4622 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4625 if (@difftree > 1) {
4626 die_error
('404 Not Found', "Ambiguous blob diff specification");
4629 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4630 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4631 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4633 $hash_parent ||= $diffinfo{'from_id'};
4634 $hash ||= $diffinfo{'to_id'};
4636 # non-textual hash id's can be cached
4637 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4638 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4643 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4644 '-p', ($format eq 'html' ? "--full-index" : ()),
4645 $hash_parent_base, $hash_base,
4646 "--", (defined $file_parent ? $file_parent : ()), $file_name
4647 or die_error
(undef, "Open git-diff-tree failed");
4650 # old/legacy style URI
4651 if (!%diffinfo && # if new style URI failed
4652 defined $hash && defined $hash_parent) {
4653 # fake git-diff-tree raw output
4654 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4655 $diffinfo{'from_id'} = $hash_parent;
4656 $diffinfo{'to_id'} = $hash;
4657 if (defined $file_name) {
4658 if (defined $file_parent) {
4659 $diffinfo{'status'} = '2';
4660 $diffinfo{'from_file'} = $file_parent;
4661 $diffinfo{'to_file'} = $file_name;
4662 } else { # assume not renamed
4663 $diffinfo{'status'} = '1';
4664 $diffinfo{'from_file'} = $file_name;
4665 $diffinfo{'to_file'} = $file_name;
4667 } else { # no filename given
4668 $diffinfo{'status'} = '2';
4669 $diffinfo{'from_file'} = $hash_parent;
4670 $diffinfo{'to_file'} = $hash;
4673 # non-textual hash id's can be cached
4674 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4675 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4680 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4681 '-p', ($format eq 'html' ? "--full-index" : ()),
4682 $hash_parent, $hash, "--"
4683 or die_error
(undef, "Open git-diff failed");
4685 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4690 if ($format eq 'html') {
4692 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4693 hash
=>$hash, hash_parent
=>$hash_parent,
4694 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4695 file_name
=>$file_name, file_parent
=>$file_parent)},
4697 git_header_html
(undef, $expires);
4698 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4699 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4700 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4702 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4703 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4705 if (defined $file_name) {
4706 git_print_page_path
($file_name, "blob", $hash_base);
4708 print "<div class=\"page_path\"></div>\n";
4711 } elsif ($format eq 'plain') {
4713 -type
=> 'text/plain',
4714 -charset
=> 'utf-8',
4715 -expires
=> $expires,
4716 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4718 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4721 die_error
(undef, "Unknown blobdiff format");
4725 if ($format eq 'html') {
4726 print "<div class=\"page_body\">\n";
4728 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4731 print "</div>\n"; # class="page_body"
4735 while (my $line = <$fd>) {
4736 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4737 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4741 last if $line =~ m!^\+\+\+!;
4749 sub git_blobdiff_plain
{
4750 git_blobdiff
('plain');
4753 sub git_commitdiff
{
4754 my $format = shift || 'html';
4755 $hash ||= $hash_base || "HEAD";
4756 my %co = parse_commit
($hash);
4758 die_error
(undef, "Unknown commit object");
4761 # choose format for commitdiff for merge
4762 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4763 $hash_parent = '--cc';
4765 # we need to prepare $formats_nav before almost any parameter munging
4767 if ($format eq 'html') {
4769 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4770 hash
=>$hash, hash_parent
=>$hash_parent)},
4773 if (defined $hash_parent &&
4774 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4775 # commitdiff with two commits given
4776 my $hash_parent_short = $hash_parent;
4777 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4778 $hash_parent_short = substr($hash_parent, 0, 7);
4782 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4783 if ($co{'parents'}[$i] eq $hash_parent) {
4784 $formats_nav .= ' parent ' . ($i+1);
4788 $formats_nav .= ': ' .
4789 $cgi->a({-href
=> href
(action
=>"commitdiff",
4790 hash
=>$hash_parent)},
4791 esc_html
($hash_parent_short)) .
4793 } elsif (!$co{'parent'}) {
4795 $formats_nav .= ' (initial)';
4796 } elsif (scalar @{$co{'parents'}} == 1) {
4797 # single parent commit
4800 $cgi->a({-href
=> href
(action
=>"commitdiff",
4801 hash
=>$co{'parent'})},
4802 esc_html
(substr($co{'parent'}, 0, 7))) .
4806 if ($hash_parent eq '--cc') {
4807 $formats_nav .= ' | ' .
4808 $cgi->a({-href
=> href
(action
=>"commitdiff",
4809 hash
=>$hash, hash_parent
=>'-c')},
4811 } else { # $hash_parent eq '-c'
4812 $formats_nav .= ' | ' .
4813 $cgi->a({-href
=> href
(action
=>"commitdiff",
4814 hash
=>$hash, hash_parent
=>'--cc')},
4820 $cgi->a({-href
=> href
(action
=>"commitdiff",
4822 esc_html
(substr($_, 0, 7)));
4823 } @{$co{'parents'}} ) .
4828 my $hash_parent_param = $hash_parent;
4829 if (!defined $hash_parent_param) {
4830 # --cc for multiple parents, --root for parentless
4831 $hash_parent_param =
4832 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4838 if ($format eq 'html') {
4839 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4840 "--no-commit-id", "--patch-with-raw", "--full-index",
4841 $hash_parent_param, $hash, "--"
4842 or die_error
(undef, "Open git-diff-tree failed");
4844 while (my $line = <$fd>) {
4846 # empty line ends raw part of diff-tree output
4848 push @difftree, scalar parse_difftree_raw_line
($line);
4851 } elsif ($format eq 'plain') {
4852 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4853 '-p', $hash_parent_param, $hash, "--"
4854 or die_error
(undef, "Open git-diff-tree failed");
4857 die_error
(undef, "Unknown commitdiff format");
4860 # non-textual hash id's can be cached
4862 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4866 # write commit message
4867 if ($format eq 'html') {
4868 my $refs = git_get_references
();
4869 my $ref = format_ref_marker
($refs, $co{'id'});
4871 git_header_html
(undef, $expires);
4872 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4873 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4874 git_print_authorship
(\
%co);
4875 print "<div class=\"page_body\">\n";
4876 if (@{$co{'comment'}} > 1) {
4877 print "<div class=\"log\">\n";
4878 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4879 print "</div>\n"; # class="log"
4882 } elsif ($format eq 'plain') {
4883 my $refs = git_get_references
("tags");
4884 my $tagname = git_get_rev_name_tags
($hash);
4885 my $filename = basename
($project) . "-$hash.patch";
4888 -type
=> 'text/plain',
4889 -charset
=> 'utf-8',
4890 -expires
=> $expires,
4891 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4892 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4895 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4896 Subject: $co{'title'}
4898 print "X-Git-Tag: $tagname\n" if $tagname;
4899 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4901 foreach my $line (@{$co{'comment'}}) {
4908 if ($format eq 'html') {
4909 my $use_parents = !defined $hash_parent ||
4910 $hash_parent eq '-c' || $hash_parent eq '--cc';
4911 git_difftree_body
(\
@difftree, $hash,
4912 $use_parents ? @{$co{'parents'}} : $hash_parent);
4915 git_patchset_body
($fd, \
@difftree, $hash,
4916 $use_parents ? @{$co{'parents'}} : $hash_parent);
4918 print "</div>\n"; # class="page_body"
4921 } elsif ($format eq 'plain') {
4925 or print "Reading git-diff-tree failed\n";
4929 sub git_commitdiff_plain
{
4930 git_commitdiff
('plain');
4934 if (!defined $hash_base) {
4935 $hash_base = git_get_head_hash
($project);
4937 if (!defined $page) {
4941 my %co = parse_commit
($hash_base);
4943 die_error
(undef, "Unknown commit object");
4946 my $refs = git_get_references
();
4947 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4949 if (!defined $hash && defined $file_name) {
4950 $hash = git_get_hash_by_path
($hash_base, $file_name);
4952 if (defined $hash) {
4953 $ftype = git_get_type
($hash);
4956 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4958 my $paging_nav = '';
4961 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4962 file_name
=>$file_name)},
4964 $paging_nav .= " ⋅ " .
4965 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4966 file_name
=>$file_name, page
=>$page-1),
4967 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4969 $paging_nav .= "first";
4970 $paging_nav .= " ⋅ prev";
4972 if ($#commitlist >= 100) {
4973 $paging_nav .= " ⋅ " .
4974 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4975 file_name
=>$file_name, page
=>$page+1),
4976 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4978 $paging_nav .= " ⋅ next";
4981 if ($#commitlist >= 100) {
4983 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4984 file_name
=>$file_name, page
=>$page+1),
4985 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4989 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4990 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4991 git_print_page_path
($file_name, $ftype, $hash_base);
4993 git_history_body
(\
@commitlist, 0, 99,
4994 $refs, $hash_base, $ftype, $next_link);
5000 my ($have_search) = gitweb_check_feature
('search');
5001 if (!$have_search) {
5002 die_error
('403 Permission denied', "Permission denied");
5004 if (!defined $searchtext) {
5005 die_error
(undef, "Text field empty");
5007 if (!defined $hash) {
5008 $hash = git_get_head_hash
($project);
5010 my %co = parse_commit
($hash);
5012 die_error
(undef, "Unknown commit object");
5014 if (!defined $page) {
5018 $searchtype ||= 'commit';
5019 if ($searchtype eq 'pickaxe') {
5020 # pickaxe may take all resources of your box and run for several minutes
5021 # with every query - so decide by yourself how public you make this feature
5022 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5023 if (!$have_pickaxe) {
5024 die_error
('403 Permission denied', "Permission denied");
5027 if ($searchtype eq 'grep') {
5028 my ($have_grep) = gitweb_check_feature
('grep');
5030 die_error
('403 Permission denied', "Permission denied");
5036 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5038 if ($searchtype eq 'commit') {
5039 $greptype = "--grep=";
5040 } elsif ($searchtype eq 'author') {
5041 $greptype = "--author=";
5042 } elsif ($searchtype eq 'committer') {
5043 $greptype = "--committer=";
5045 $greptype .= $search_regexp;
5046 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5048 my $paging_nav = '';
5051 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5052 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5054 $paging_nav .= " ⋅ " .
5055 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5056 searchtext
=>$searchtext, searchtype
=>$searchtype,
5058 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5060 $paging_nav .= "first";
5061 $paging_nav .= " ⋅ prev";
5063 if ($#commitlist >= 100) {
5064 $paging_nav .= " ⋅ " .
5065 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5066 searchtext
=>$searchtext, searchtype
=>$searchtype,
5068 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5070 $paging_nav .= " ⋅ next";
5073 if ($#commitlist >= 100) {
5075 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5076 searchtext
=>$searchtext, searchtype
=>$searchtype,
5078 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5081 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5082 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5083 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5086 if ($searchtype eq 'pickaxe') {
5087 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5088 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5090 print "<table cellspacing=\"0\">\n";
5093 my $git_command = git_cmd_str
();
5094 my $searchqtext = $searchtext;
5095 $searchqtext =~ s/'/'\\''/;
5096 open my $fd, "-|", "$git_command rev-list $hash | " .
5097 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5100 while (my $line = <$fd>) {
5101 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5104 $set{'from_id'} = $3;
5106 $set{'id'} = $set{'to_id'};
5107 if ($set{'id'} =~ m/0{40}/) {
5108 $set{'id'} = $set{'from_id'};
5110 if ($set{'id'} =~ m/0{40}/) {
5114 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5117 print "<tr class=\"dark\">\n";
5119 print "<tr class=\"light\">\n";
5122 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5123 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5125 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5126 -class => "list subject"},
5127 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5128 while (my $setref = shift @files) {
5130 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5131 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5133 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5137 "<td class=\"link\">" .
5138 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5140 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5144 %co = parse_commit
($1);
5152 if ($searchtype eq 'grep') {
5153 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5154 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5156 print "<table cellspacing=\"0\">\n";
5160 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5162 while (my $line = <$fd>) {
5164 my ($file, $lno, $ltext, $binary);
5165 last if ($matches++ > 1000);
5166 if ($line =~ /^Binary file (.+) matches$/) {
5170 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5172 if ($file ne $lastfile) {
5173 $lastfile and print "</td></tr>\n";
5175 print "<tr class=\"dark\">\n";
5177 print "<tr class=\"light\">\n";
5179 print "<td class=\"list\">".
5180 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5181 file_name
=>"$file"),
5182 -class => "list"}, esc_path
($file));
5183 print "</td><td>\n";
5187 print "<div class=\"binary\">Binary file</div>\n";
5189 $ltext = untabify
($ltext);
5190 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5191 $ltext = esc_html
($1, -nbsp
=>1);
5192 $ltext .= '<span class="match">';
5193 $ltext .= esc_html
($2, -nbsp
=>1);
5194 $ltext .= '</span>';
5195 $ltext .= esc_html
($3, -nbsp
=>1);
5197 $ltext = esc_html
($ltext, -nbsp
=>1);
5199 print "<div class=\"pre\">" .
5200 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5201 file_name
=>"$file").'#l'.$lno,
5202 -class => "linenr"}, sprintf('%4i', $lno))
5203 . ' ' . $ltext . "</div>\n";
5207 print "</td></tr>\n";
5208 if ($matches > 1000) {
5209 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5212 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5221 sub git_search_help
{
5223 git_print_page_nav
('','', $hash,$hash,$hash);
5226 <dt><b>commit</b></dt>
5227 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5229 my ($have_grep) = gitweb_check_feature
('grep');
5232 <dt><b>grep</b></dt>
5233 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5234 a different one) are searched for the given
5235 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5236 (POSIX extended) and the matches are listed. On large
5237 trees, this search can take a while and put some strain on the server, so please use it with
5238 some consideration.</dd>
5242 <dt><b>author</b></dt>
5243 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5244 <dt><b>committer</b></dt>
5245 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5247 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5248 if ($have_pickaxe) {
5250 <dt><b>pickaxe</b></dt>
5251 <dd>All commits that caused the string to appear or disappear from any file (changes that
5252 added, removed or "modified" the string) will be listed. This search can take a while and
5253 takes a lot of strain on the server, so please use it wisely.</dd>
5261 my $head = git_get_head_hash
($project);
5262 if (!defined $hash) {
5265 if (!defined $page) {
5268 my $refs = git_get_references
();
5270 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5272 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5274 if ($#commitlist >= 100) {
5276 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5277 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5281 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5282 git_print_header_div
('summary', $project);
5284 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5289 ## ......................................................................
5290 ## feeds (RSS, Atom; OPML)
5293 my $format = shift || 'atom';
5294 my ($have_blame) = gitweb_check_feature
('blame');
5296 # Atom: http://www.atomenabled.org/developers/syndication/
5297 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5298 if ($format ne 'rss' && $format ne 'atom') {
5299 die_error
(undef, "Unknown web feed format");
5302 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5303 my $head = $hash || 'HEAD';
5304 my @commitlist = parse_commits
($head, 150);
5308 my $content_type = "application/$format+xml";
5309 if (defined $cgi->http('HTTP_ACCEPT') &&
5310 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5311 # browser (feed reader) prefers text/xml
5312 $content_type = 'text/xml';
5314 if (defined($commitlist[0])) {
5315 %latest_commit = %{$commitlist[0]};
5316 %latest_date = parse_date
($latest_commit{'author_epoch'});
5318 -type
=> $content_type,
5319 -charset
=> 'utf-8',
5320 -last_modified
=> $latest_date{'rfc2822'});
5323 -type
=> $content_type,
5324 -charset
=> 'utf-8');
5327 # Optimization: skip generating the body if client asks only
5328 # for Last-Modified date.
5329 return if ($cgi->request_method() eq 'HEAD');
5332 my $title = "$site_name - $project/$action";
5333 my $feed_type = 'log';
5334 if (defined $hash) {
5335 $title .= " - '$hash'";
5336 $feed_type = 'branch log';
5337 if (defined $file_name) {
5338 $title .= " :: $file_name";
5339 $feed_type = 'history';
5341 } elsif (defined $file_name) {
5342 $title .= " - $file_name";
5343 $feed_type = 'history';
5345 $title .= " $feed_type";
5346 my $descr = git_get_project_description
($project);
5347 if (defined $descr) {
5348 $descr = esc_html
($descr);
5350 $descr = "$project " .
5351 ($format eq 'rss' ? 'RSS' : 'Atom') .
5354 my $owner = git_get_project_owner
($project);
5355 $owner = esc_html
($owner);
5359 if (defined $file_name) {
5360 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5361 } elsif (defined $hash) {
5362 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5364 $alt_url = href
(-full
=>1, action
=>"summary");
5366 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5367 if ($format eq 'rss') {
5369 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5372 print "<title>$title</title>\n" .
5373 "<link>$alt_url</link>\n" .
5374 "<description>$descr</description>\n" .
5375 "<language>en</language>\n";
5376 } elsif ($format eq 'atom') {
5378 <feed xmlns="http://www.w3.org/2005/Atom">
5380 print "<title>$title</title>\n" .
5381 "<subtitle>$descr</subtitle>\n" .
5382 '<link rel="alternate" type="text/html" href="' .
5383 $alt_url . '" />' . "\n" .
5384 '<link rel="self" type="' . $content_type . '" href="' .
5385 $cgi->self_url() . '" />' . "\n" .
5386 "<id>" . href
(-full
=>1) . "</id>\n" .
5387 # use project owner for feed author
5388 "<author><name>$owner</name></author>\n";
5389 if (defined $favicon) {
5390 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5392 if (defined $logo_url) {
5393 # not twice as wide as tall: 72 x 27 pixels
5394 print "<logo>" . esc_url
($logo) . "</logo>\n";
5396 if (! %latest_date) {
5397 # dummy date to keep the feed valid until commits trickle in:
5398 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5400 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5405 for (my $i = 0; $i <= $#commitlist; $i++) {
5406 my %co = %{$commitlist[$i]};
5407 my $commit = $co{'id'};
5408 # we read 150, we always show 30 and the ones more recent than 48 hours
5409 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5412 my %cd = parse_date
($co{'author_epoch'});
5414 # get list of changed files
5415 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5416 $co{'parent'} || "--root",
5417 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5419 my @difftree = map { chomp; $_ } <$fd>;
5423 # print element (entry, item)
5424 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5425 if ($format eq 'rss') {
5427 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5428 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5429 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5430 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5431 "<link>$co_url</link>\n" .
5432 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5433 "<content:encoded>" .
5435 } elsif ($format eq 'atom') {
5437 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5438 "<updated>$cd{'iso-8601'}</updated>\n" .
5440 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5441 if ($co{'author_email'}) {
5442 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5444 print "</author>\n" .
5445 # use committer for contributor
5447 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5448 if ($co{'committer_email'}) {
5449 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5451 print "</contributor>\n" .
5452 "<published>$cd{'iso-8601'}</published>\n" .
5453 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5454 "<id>$co_url</id>\n" .
5455 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5456 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5458 my $comment = $co{'comment'};
5460 foreach my $line (@$comment) {
5461 $line = esc_html
($line);
5464 print "</pre><ul>\n";
5465 foreach my $difftree_line (@difftree) {
5466 my %difftree = parse_difftree_raw_line
($difftree_line);
5467 next if !$difftree{'from_id'};
5469 my $file = $difftree{'file'} || $difftree{'to_file'};
5473 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5474 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5475 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5476 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5477 -title
=> "diff"}, 'D');
5479 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5480 file_name
=>$file, hash_base
=>$commit),
5481 -title
=> "blame"}, 'B');
5483 # if this is not a feed of a file history
5484 if (!defined $file_name || $file_name ne $file) {
5485 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5486 file_name
=>$file, hash
=>$commit),
5487 -title
=> "history"}, 'H');
5489 $file = esc_path
($file);
5493 if ($format eq 'rss') {
5494 print "</ul>]]>\n" .
5495 "</content:encoded>\n" .
5497 } elsif ($format eq 'atom') {
5498 print "</ul>\n</div>\n" .
5505 if ($format eq 'rss') {
5506 print "</channel>\n</rss>\n";
5507 } elsif ($format eq 'atom') {
5521 my @list = git_get_projects_list
();
5523 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5525 <?xml version="1.0" encoding="utf-8"?>
5526 <opml version="1.0">
5528 <title>$site_name OPML Export</title>
5531 <outline text="git RSS feeds">
5534 foreach my $pr (@list) {
5536 my $head = git_get_head_hash
($proj{'path'});
5537 if (!defined $head) {
5540 $git_dir = "$projectroot/$proj{'path'}";
5541 my %co = parse_commit
($head);
5546 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5547 my $rss = "$my_url?p=$proj{'path'};a=rss";
5548 my $html = "$my_url?p=$proj{'path'};a=summary";
5549 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";