3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
64 # URI of GIT logo (72x27 size)
65 our $logo = "++GITWEB_LOGO++";
66 # URI of GIT favicon, assumed to be image/png type
67 our $favicon = "++GITWEB_FAVICON++";
69 # URI and label (title) of GIT logo link
70 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
71 #our $logo_label = "git documentation";
72 our $logo_url = "http://git.or.cz/";
73 our $logo_label = "git homepage";
75 # source of projects list
76 our $projects_list = "++GITWEB_LIST++";
78 # the width (in characters) of the projects list "Description" column
79 our $projects_list_description_width = 25;
81 # default order of projects list
82 # valid values are none, project, descr, owner, and age
83 our $default_projects_order = "project";
85 # show repository only if this file exists
86 # (only effective if this variable evaluates to true)
87 our $export_ok = "++GITWEB_EXPORT_OK++";
89 # only allow viewing of repositories also shown on the overview page
90 our $strict_export = "++GITWEB_STRICT_EXPORT++";
92 # list of git base URLs used for URL to where fetch project from,
93 # i.e. full URL is "$git_base_url/$project"
94 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
96 # default blob_plain mimetype and default charset for text/plain blob
97 our $default_blob_plain_mimetype = 'text/plain';
98 our $default_text_plain_charset = undef;
100 # file to use for guessing MIME types before trying /etc/mime.types
101 # (relative to the current git repository)
102 our $mimetypes_file = undef;
104 # assume this charset if line contains non-UTF-8 characters;
105 # it should be valid encoding (see Encoding::Supported(3pm) for list),
106 # for which encoding all byte sequences are valid, for example
107 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
108 # could be even 'utf-8' for the old behavior)
109 our $fallback_encoding = 'latin1';
111 # rename detection options for git-diff and git-diff-tree
112 # - default is '-M', with the cost proportional to
113 # (number of removed files) * (number of new files).
114 # - more costly is '-C' (which implies '-M'), with the cost proportional to
115 # (number of changed files + number of removed files) * (number of new files)
116 # - even more costly is '-C', '--find-copies-harder' with cost
117 # (number of files in the original tree) * (number of new files)
118 # - one might want to include '-B' option, e.g. '-B', '-M'
119 our @diff_opts = ('-M'); # taken from git_commit
121 # information about snapshot formats that gitweb is capable of serving
122 our %known_snapshot_formats = (
124 # 'display' => display name,
125 # 'type' => mime type,
126 # 'suffix' => filename suffix,
127 # 'format' => --format for git-archive,
128 # 'compressor' => [compressor command and arguments]
129 # (array reference, optional)}
132 'display' => 'tar.gz',
133 'type' => 'application/x-gzip',
134 'suffix' => '.tar.gz',
136 'compressor' => ['gzip']},
139 'display' => 'tar.bz2',
140 'type' => 'application/x-bzip2',
141 'suffix' => '.tar.bz2',
143 'compressor' => ['bzip2']},
147 'type' => 'application/x-zip',
152 # Aliases so we understand old gitweb.snapshot values in repository
154 our %known_snapshot_format_aliases = (
158 # backward compatibility: legacy gitweb config support
159 'x-gzip' => undef, 'gz' => undef,
160 'x-bzip2' => undef, 'bz2' => undef,
161 'x-zip' => undef, '' => undef,
164 # You define site-wide feature defaults here; override them with
165 # $GITWEB_CONFIG as necessary.
168 # 'sub' => feature-sub (subroutine),
169 # 'override' => allow-override (boolean),
170 # 'default' => [ default options...] (array reference)}
172 # if feature is overridable (it means that allow-override has true value),
173 # then feature-sub will be called with default options as parameters;
174 # return value of feature-sub indicates if to enable specified feature
176 # if there is no 'sub' key (no feature-sub), then feature cannot be
179 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
181 # Enable the 'blame' blob view, showing the last commit that modified
182 # each line in the file. This can be very CPU-intensive.
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'blame'}{'default'} = [1];
186 # To have project specific config enable override in $GITWEB_CONFIG
187 # $feature{'blame'}{'override'} = 1;
188 # and in project config gitweb.blame = 0|1;
190 'sub' => \
&feature_blame
,
194 # Enable the 'snapshot' link, providing a compressed archive of any
195 # tree. This can potentially generate high traffic if you have large
198 # Value is a list of formats defined in %known_snapshot_formats that
200 # To disable system wide have in $GITWEB_CONFIG
201 # $feature{'snapshot'}{'default'} = [];
202 # To have project specific config enable override in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'override'} = 1;
204 # and in project config, a comma-separated list of formats or "none"
205 # to disable. Example: gitweb.snapshot = tbz2,zip;
207 'sub' => \
&feature_snapshot
,
209 'default' => ['tgz']},
211 # Enable text search, which will list the commits which match author,
212 # committer or commit text to a given string. Enabled by default.
213 # Project specific override is not supported.
218 # Enable grep search, which will list the files in currently selected
219 # tree containing the given string. Enabled by default. This can be
220 # potentially CPU-intensive, of course.
222 # To enable system wide have in $GITWEB_CONFIG
223 # $feature{'grep'}{'default'} = [1];
224 # To have project specific config enable override in $GITWEB_CONFIG
225 # $feature{'grep'}{'override'} = 1;
226 # and in project config gitweb.grep = 0|1;
231 # Enable the pickaxe search, which will list the commits that modified
232 # a given string in a file. This can be practical and quite faster
233 # alternative to 'blame', but still potentially CPU-intensive.
235 # To enable system wide have in $GITWEB_CONFIG
236 # $feature{'pickaxe'}{'default'} = [1];
237 # To have project specific config enable override in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'override'} = 1;
239 # and in project config gitweb.pickaxe = 0|1;
241 'sub' => \
&feature_pickaxe
,
245 # Make gitweb use an alternative format of the URLs which can be
246 # more readable and natural-looking: project name is embedded
247 # directly in the path and the query string contains other
248 # auxiliary information. All gitweb installations recognize
249 # URL in either format; this configures in which formats gitweb
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'pathinfo'}{'default'} = [1];
254 # Project specific override is not supported.
256 # Note that you will need to change the default location of CSS,
257 # favicon, logo and possibly other files to an absolute URL. Also,
258 # if gitweb.cgi serves as your indexfile, you will need to force
259 # $my_uri to contain the script name in your $GITWEB_CONFIG.
264 # Make gitweb consider projects in project root subdirectories
265 # to be forks of existing projects. Given project $projname.git,
266 # projects matching $projname/*.git will not be shown in the main
267 # projects list, instead a '+' mark will be added to $projname
268 # there and a 'forks' view will be enabled for the project, listing
269 # all the forks. If project list is taken from a file, forks have
270 # to be listed after the main project.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'forks'}{'default'} = [1];
274 # Project specific override is not supported.
280 sub gitweb_check_feature
{
282 return unless exists $feature{$name};
283 my ($sub, $override, @defaults) = (
284 $feature{$name}{'sub'},
285 $feature{$name}{'override'},
286 @
{$feature{$name}{'default'}});
287 if (!$override) { return @defaults; }
289 warn "feature $name is not overrideable";
292 return $sub->(@defaults);
296 my ($val) = git_get_project_config
('blame', '--bool');
298 if ($val eq 'true') {
300 } elsif ($val eq 'false') {
307 sub feature_snapshot
{
310 my ($val) = git_get_project_config
('snapshot');
313 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
320 my ($val) = git_get_project_config
('grep', '--bool');
322 if ($val eq 'true') {
324 } elsif ($val eq 'false') {
331 sub feature_pickaxe
{
332 my ($val) = git_get_project_config
('pickaxe', '--bool');
334 if ($val eq 'true') {
336 } elsif ($val eq 'false') {
343 # checking HEAD file with -e is fragile if the repository was
344 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
346 sub check_head_link
{
348 my $headfile = "$dir/HEAD";
349 return ((-e
$headfile) ||
350 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
353 sub check_export_ok
{
355 return (check_head_link
($dir) &&
356 (!$export_ok || -e
"$dir/$export_ok"));
359 # process alternate names for backward compatibility
360 # filter out unsupported (unknown) snapshot formats
361 sub filter_snapshot_fmts
{
365 exists $known_snapshot_format_aliases{$_} ?
366 $known_snapshot_format_aliases{$_} : $_} @fmts;
367 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
371 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
372 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
374 # version of the core git binary
375 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
377 $projects_list ||= $projectroot;
379 # ======================================================================
380 # input validation and dispatch
381 our $action = $cgi->param('a');
382 if (defined $action) {
383 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
384 die_error
(undef, "Invalid action parameter");
388 # parameters which are pathnames
389 our $project = $cgi->param('p');
390 if (defined $project) {
391 if (!validate_pathname
($project) ||
392 !(-d
"$projectroot/$project") ||
393 !check_head_link
("$projectroot/$project") ||
394 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
395 ($strict_export && !project_in_list
($project))) {
397 die_error
(undef, "No such project");
401 our $file_name = $cgi->param('f');
402 if (defined $file_name) {
403 if (!validate_pathname
($file_name)) {
404 die_error
(undef, "Invalid file parameter");
408 our $file_parent = $cgi->param('fp');
409 if (defined $file_parent) {
410 if (!validate_pathname
($file_parent)) {
411 die_error
(undef, "Invalid file parent parameter");
415 # parameters which are refnames
416 our $hash = $cgi->param('h');
418 if (!validate_refname
($hash)) {
419 die_error
(undef, "Invalid hash parameter");
423 our $hash_parent = $cgi->param('hp');
424 if (defined $hash_parent) {
425 if (!validate_refname
($hash_parent)) {
426 die_error
(undef, "Invalid hash parent parameter");
430 our $hash_base = $cgi->param('hb');
431 if (defined $hash_base) {
432 if (!validate_refname
($hash_base)) {
433 die_error
(undef, "Invalid hash base parameter");
437 my %allowed_options = (
438 "--no-merges" => [ qw(rss atom log shortlog history) ],
441 our @extra_options = $cgi->param('opt');
442 if (defined @extra_options) {
443 foreach my $opt (@extra_options) {
444 if (not exists $allowed_options{$opt}) {
445 die_error
(undef, "Invalid option parameter");
447 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
448 die_error
(undef, "Invalid option parameter for this action");
453 our $hash_parent_base = $cgi->param('hpb');
454 if (defined $hash_parent_base) {
455 if (!validate_refname
($hash_parent_base)) {
456 die_error
(undef, "Invalid hash parent base parameter");
461 our $page = $cgi->param('pg');
463 if ($page =~ m/[^0-9]/) {
464 die_error
(undef, "Invalid page parameter");
468 our $searchtype = $cgi->param('st');
469 if (defined $searchtype) {
470 if ($searchtype =~ m/[^a-z]/) {
471 die_error
(undef, "Invalid searchtype parameter");
475 our $searchtext = $cgi->param('s');
477 if (defined $searchtext) {
478 if (length($searchtext) < 2) {
479 die_error
(undef, "At least two characters are required for search parameter");
481 $search_regexp = quotemeta $searchtext;
484 # now read PATH_INFO and use it as alternative to parameters
485 sub evaluate_path_info
{
486 return if defined $project;
487 my $path_info = $ENV{"PATH_INFO"};
488 return if !$path_info;
489 $path_info =~ s
,^/+,,;
490 return if !$path_info;
491 # find which part of PATH_INFO is project
492 $project = $path_info;
494 while ($project && !check_head_link
("$projectroot/$project")) {
495 $project =~ s
,/*[^/]*$,,;
498 $project = validate_pathname
($project);
500 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
501 ($strict_export && !project_in_list
($project))) {
505 # do not change any parameters if an action is given using the query string
507 $path_info =~ s
,^$project/*,,;
508 my ($refname, $pathname) = split(/:/, $path_info, 2);
509 if (defined $pathname) {
510 # we got "project.git/branch:filename" or "project.git/branch:dir/"
511 # we could use git_get_type(branch:pathname), but it needs $git_dir
512 $pathname =~ s
,^/+,,;
513 if (!$pathname || substr($pathname, -1) eq "/") {
517 $action ||= "blob_plain";
519 $hash_base ||= validate_refname
($refname);
520 $file_name ||= validate_pathname
($pathname);
521 } elsif (defined $refname) {
522 # we got "project.git/branch"
523 $action ||= "shortlog";
524 $hash ||= validate_refname
($refname);
527 evaluate_path_info
();
529 # path to the current git repository
531 $git_dir = "$projectroot/$project" if $project;
535 "blame" => \
&git_blame2
,
536 "blobdiff" => \
&git_blobdiff
,
537 "blobdiff_plain" => \
&git_blobdiff_plain
,
538 "blob" => \
&git_blob
,
539 "blob_plain" => \
&git_blob_plain
,
540 "commitdiff" => \
&git_commitdiff
,
541 "commitdiff_plain" => \
&git_commitdiff_plain
,
542 "commit" => \
&git_commit
,
543 "forks" => \
&git_forks
,
544 "heads" => \
&git_heads
,
545 "history" => \
&git_history
,
548 "atom" => \
&git_atom
,
549 "search" => \
&git_search
,
550 "search_help" => \
&git_search_help
,
551 "shortlog" => \
&git_shortlog
,
552 "summary" => \
&git_summary
,
554 "tags" => \
&git_tags
,
555 "tree" => \
&git_tree
,
556 "snapshot" => \
&git_snapshot
,
557 "object" => \
&git_object
,
558 # those below don't need $project
559 "opml" => \
&git_opml
,
560 "project_list" => \
&git_project_list
,
561 "project_index" => \
&git_project_index
,
564 if (!defined $action) {
566 $action = git_get_type
($hash);
567 } elsif (defined $hash_base && defined $file_name) {
568 $action = git_get_type
("$hash_base:$file_name");
569 } elsif (defined $project) {
572 $action = 'project_list';
575 if (!defined($actions{$action})) {
576 die_error
(undef, "Unknown action");
578 if ($action !~ m/^(opml|project_list|project_index)$/ &&
580 die_error
(undef, "Project needed");
582 $actions{$action}->();
585 ## ======================================================================
590 # default is to use -absolute url() i.e. $my_uri
591 my $href = $params{-full
} ?
$my_url : $my_uri;
593 # XXX: Warning: If you touch this, check the search form for updating,
604 hash_parent_base
=> "hpb",
609 snapshot_format
=> "sf",
610 extra_options
=> "opt",
612 my %mapping = @mapping;
614 $params{'project'} = $project unless exists $params{'project'};
616 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
618 # use PATH_INFO for project name
619 $href .= "/$params{'project'}" if defined $params{'project'};
620 delete $params{'project'};
622 # Summary just uses the project path URL
623 if (defined $params{'action'} && $params{'action'} eq 'summary') {
624 delete $params{'action'};
628 # now encode the parameters explicitly
630 for (my $i = 0; $i < @mapping; $i += 2) {
631 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
632 if (defined $params{$name}) {
633 if (ref($params{$name}) eq "ARRAY") {
634 foreach my $par (@
{$params{$name}}) {
635 push @result, $symbol . "=" . esc_param
($par);
638 push @result, $symbol . "=" . esc_param
($params{$name});
642 $href .= "?" . join(';', @result) if scalar @result;
648 ## ======================================================================
649 ## validation, quoting/unquoting and escaping
651 sub validate_pathname
{
652 my $input = shift || return undef;
654 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
655 # at the beginning, at the end, and between slashes.
656 # also this catches doubled slashes
657 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
661 if ($input =~ m!\0!) {
667 sub validate_refname
{
668 my $input = shift || return undef;
670 # textual hashes are O.K.
671 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
674 # it must be correct pathname
675 $input = validate_pathname
($input)
677 # restrictions on ref name according to git-check-ref-format
678 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
684 # decode sequences of octets in utf8 into Perl's internal form,
685 # which is utf-8 with utf8 flag set if needed. gitweb writes out
686 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
690 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
694 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
698 # quote unsafe chars, but keep the slash, even when it's not
699 # correct, but quoted slashes look too horrible in bookmarks
702 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
708 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
711 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
717 # replace invalid utf8 character with SUBSTITUTION sequence
722 $str = to_utf8
($str);
723 $str = $cgi->escapeHTML($str);
724 if ($opts{'-nbsp'}) {
725 $str =~ s/ / /g;
727 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
731 # quote control characters and escape filename to HTML
736 $str = to_utf8
($str);
737 $str = $cgi->escapeHTML($str);
738 if ($opts{'-nbsp'}) {
739 $str =~ s/ / /g;
741 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
745 # Make control characters "printable", using character escape codes (CEC)
748 my %es = ( # character escape codes, aka escape sequences
749 "\t" => '\t', # tab (HT)
750 "\n" => '\n', # line feed (LF)
751 "\r" => '\r', # carrige return (CR)
752 "\f" => '\f', # form feed (FF)
753 "\b" => '\b', # backspace (BS)
754 "\a" => '\a', # alarm (bell) (BEL)
755 "\e" => '\e', # escape (ESC)
756 "\013" => '\v', # vertical tab (VT)
757 "\000" => '\0', # nul character (NUL)
759 my $chr = ( (exists $es{$cntrl})
761 : sprintf('\%03o', ord($cntrl)) );
762 return "<span class=\"cntrl\">$chr</span>";
765 # Alternatively use unicode control pictures codepoints,
766 # Unicode "printable representation" (PR)
769 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
770 return "<span class=\"cntrl\">$chr</span>";
773 # git may return quoted and escaped filenames
779 my %es = ( # character escape codes, aka escape sequences
780 't' => "\t", # tab (HT, TAB)
781 'n' => "\n", # newline (NL)
782 'r' => "\r", # return (CR)
783 'f' => "\f", # form feed (FF)
784 'b' => "\b", # backspace (BS)
785 'a' => "\a", # alarm (bell) (BEL)
786 'e' => "\e", # escape (ESC)
787 'v' => "\013", # vertical tab (VT)
790 if ($seq =~ m/^[0-7]{1,3}$/) {
791 # octal char sequence
792 return chr(oct($seq));
793 } elsif (exists $es{$seq}) {
794 # C escape sequence, aka character escape code
797 # quoted ordinary character
801 if ($str =~ m/^"(.*)"$/) {
804 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
809 # escape tabs (convert tabs to spaces)
813 while ((my $pos = index($line, "\t")) != -1) {
814 if (my $count = (8 - ($pos % 8))) {
815 my $spaces = ' ' x
$count;
816 $line =~ s/\t/$spaces/;
823 sub project_in_list
{
825 my @list = git_get_projects_list
();
826 return @list && scalar(grep { $_->{'path'} eq $project } @list);
829 ## ----------------------------------------------------------------------
830 ## HTML aware string manipulation
835 my $add_len = shift || 10;
837 # allow only $len chars, but don't cut a word if it would fit in $add_len
838 # if it doesn't fit, cut it if it's still longer than the dots we would add
839 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
842 if (length($tail) > 4) {
844 $body =~ s/&[^;]*$//; # remove chopped character entities
849 ## ----------------------------------------------------------------------
850 ## functions returning short strings
852 # CSS class for given age value (in seconds)
858 } elsif ($age < 60*60*2) {
860 } elsif ($age < 60*60*24*2) {
867 # convert age in seconds to "nn units ago" string
872 if ($age > 60*60*24*365*2) {
873 $age_str = (int $age/60/60/24/365);
874 $age_str .= " years ago";
875 } elsif ($age > 60*60*24*(365/12)*2) {
876 $age_str = int $age/60/60/24/(365/12);
877 $age_str .= " months ago";
878 } elsif ($age > 60*60*24*7*2) {
879 $age_str = int $age/60/60/24/7;
880 $age_str .= " weeks ago";
881 } elsif ($age > 60*60*24*2) {
882 $age_str = int $age/60/60/24;
883 $age_str .= " days ago";
884 } elsif ($age > 60*60*2) {
885 $age_str = int $age/60/60;
886 $age_str .= " hours ago";
887 } elsif ($age > 60*2) {
888 $age_str = int $age/60;
889 $age_str .= " min ago";
892 $age_str .= " sec ago";
894 $age_str .= " right now";
900 S_IFINVALID
=> 0030000,
901 S_IFGITLINK
=> 0160000,
904 # submodule/subproject, a commit object reference
908 return (($mode & S_IFMT
) == S_IFGITLINK
)
911 # convert file mode in octal to symbolic file mode string
913 my $mode = oct shift;
915 if (S_ISGITLINK
($mode)) {
917 } elsif (S_ISDIR
($mode & S_IFMT
)) {
919 } elsif (S_ISLNK
($mode)) {
921 } elsif (S_ISREG
($mode)) {
922 # git cares only about the executable bit
923 if ($mode & S_IXUSR
) {
933 # convert file mode in octal to file type string
937 if ($mode !~ m/^[0-7]+$/) {
943 if (S_ISGITLINK
($mode)) {
945 } elsif (S_ISDIR
($mode & S_IFMT
)) {
947 } elsif (S_ISLNK
($mode)) {
949 } elsif (S_ISREG
($mode)) {
956 # convert file mode in octal to file type description string
960 if ($mode !~ m/^[0-7]+$/) {
966 if (S_ISGITLINK
($mode)) {
968 } elsif (S_ISDIR
($mode & S_IFMT
)) {
970 } elsif (S_ISLNK
($mode)) {
972 } elsif (S_ISREG
($mode)) {
973 if ($mode & S_IXUSR
) {
984 ## ----------------------------------------------------------------------
985 ## functions returning short HTML fragments, or transforming HTML fragments
986 ## which don't belong to other sections
988 # format line of commit message.
989 sub format_log_line_html
{
992 $line = esc_html
($line, -nbsp
=>1);
993 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
996 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
997 -class => "text"}, $hash_text);
998 $line =~ s/$hash_text/$link/;
1003 # format marker of refs pointing to given object
1004 sub format_ref_marker
{
1005 my ($refs, $id) = @_;
1008 if (defined $refs->{$id}) {
1009 foreach my $ref (@
{$refs->{$id}}) {
1010 my ($type, $name) = qw();
1011 # e.g. tags/v2.6.11 or heads/next
1012 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1020 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1021 esc_html
($name) . "</span>";
1026 return ' <span class="refs">'. $markers . '</span>';
1032 # format, perhaps shortened and with markers, title line
1033 sub format_subject_html
{
1034 my ($long, $short, $href, $extra) = @_;
1035 $extra = '' unless defined($extra);
1037 if (length($short) < length($long)) {
1038 return $cgi->a({-href
=> $href, -class => "list subject",
1039 -title
=> to_utf8
($long)},
1040 esc_html
($short) . $extra);
1042 return $cgi->a({-href
=> $href, -class => "list subject"},
1043 esc_html
($long) . $extra);
1047 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1048 sub format_git_diff_header_line
{
1050 my $diffinfo = shift;
1051 my ($from, $to) = @_;
1053 if ($diffinfo->{'nparents'}) {
1055 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1056 if ($to->{'href'}) {
1057 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1058 esc_path
($to->{'file'}));
1059 } else { # file was deleted (no href)
1060 $line .= esc_path
($to->{'file'});
1064 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1065 if ($from->{'href'}) {
1066 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1067 'a/' . esc_path
($from->{'file'}));
1068 } else { # file was added (no href)
1069 $line .= 'a/' . esc_path
($from->{'file'});
1072 if ($to->{'href'}) {
1073 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1074 'b/' . esc_path
($to->{'file'}));
1075 } else { # file was deleted
1076 $line .= 'b/' . esc_path
($to->{'file'});
1080 return "<div class=\"diff header\">$line</div>\n";
1083 # format extended diff header line, before patch itself
1084 sub format_extended_diff_header_line
{
1086 my $diffinfo = shift;
1087 my ($from, $to) = @_;
1090 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1091 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1092 esc_path
($from->{'file'}));
1094 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1095 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1096 esc_path
($to->{'file'}));
1098 # match single <mode>
1099 if ($line =~ m/\s(\d{6})$/) {
1100 $line .= '<span class="info"> (' .
1101 file_type_long
($1) .
1105 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1106 # can match only for combined diff
1108 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1109 if ($from->{'href'}[$i]) {
1110 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1112 substr($diffinfo->{'from_id'}[$i],0,7));
1117 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1120 if ($to->{'href'}) {
1121 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1122 substr($diffinfo->{'to_id'},0,7));
1127 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1128 # can match only for ordinary diff
1129 my ($from_link, $to_link);
1130 if ($from->{'href'}) {
1131 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1132 substr($diffinfo->{'from_id'},0,7));
1134 $from_link = '0' x
7;
1136 if ($to->{'href'}) {
1137 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1138 substr($diffinfo->{'to_id'},0,7));
1142 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1143 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1146 return $line . "<br/>\n";
1149 # format from-file/to-file diff header
1150 sub format_diff_from_to_header
{
1151 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1156 #assert($line =~ m/^---/) if DEBUG;
1157 # no extra formatting for "^--- /dev/null"
1158 if (! $diffinfo->{'nparents'}) {
1159 # ordinary (single parent) diff
1160 if ($line =~ m!^--- "?a/!) {
1161 if ($from->{'href'}) {
1163 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1164 esc_path
($from->{'file'}));
1167 esc_path
($from->{'file'});
1170 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1173 # combined diff (merge commit)
1174 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1175 if ($from->{'href'}[$i]) {
1177 $cgi->a({-href
=>href
(action
=>"blobdiff",
1178 hash_parent
=>$diffinfo->{'from_id'}[$i],
1179 hash_parent_base
=>$parents[$i],
1180 file_parent
=>$from->{'file'}[$i],
1181 hash
=>$diffinfo->{'to_id'},
1183 file_name
=>$to->{'file'}),
1185 -title
=>"diff" . ($i+1)},
1188 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1189 esc_path
($from->{'file'}[$i]));
1191 $line = '--- /dev/null';
1193 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1198 #assert($line =~ m/^\+\+\+/) if DEBUG;
1199 # no extra formatting for "^+++ /dev/null"
1200 if ($line =~ m!^\+\+\+ "?b/!) {
1201 if ($to->{'href'}) {
1203 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1204 esc_path
($to->{'file'}));
1207 esc_path
($to->{'file'});
1210 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1215 # create note for patch simplified by combined diff
1216 sub format_diff_cc_simplified
{
1217 my ($diffinfo, @parents) = @_;
1220 $result .= "<div class=\"diff header\">" .
1222 if (!is_deleted
($diffinfo)) {
1223 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1225 hash
=>$diffinfo->{'to_id'},
1226 file_name
=>$diffinfo->{'to_file'}),
1228 esc_path
($diffinfo->{'to_file'}));
1230 $result .= esc_path
($diffinfo->{'to_file'});
1232 $result .= "</div>\n" . # class="diff header"
1233 "<div class=\"diff nodifferences\">" .
1235 "</div>\n"; # class="diff nodifferences"
1240 # format patch (diff) line (not to be used for diff headers)
1241 sub format_diff_line
{
1243 my ($from, $to) = @_;
1244 my $diff_class = "";
1248 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1250 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1251 if ($line =~ m/^\@{3}/) {
1252 $diff_class = " chunk_header";
1253 } elsif ($line =~ m/^\\/) {
1254 $diff_class = " incomplete";
1255 } elsif ($prefix =~ tr/+/+/) {
1256 $diff_class = " add";
1257 } elsif ($prefix =~ tr/-/-/) {
1258 $diff_class = " rem";
1261 # assume ordinary diff
1262 my $char = substr($line, 0, 1);
1264 $diff_class = " add";
1265 } elsif ($char eq '-') {
1266 $diff_class = " rem";
1267 } elsif ($char eq '@') {
1268 $diff_class = " chunk_header";
1269 } elsif ($char eq "\\") {
1270 $diff_class = " incomplete";
1273 $line = untabify
($line);
1274 if ($from && $to && $line =~ m/^\@{2} /) {
1275 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1276 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1278 $from_lines = 0 unless defined $from_lines;
1279 $to_lines = 0 unless defined $to_lines;
1281 if ($from->{'href'}) {
1282 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1283 -class=>"list"}, $from_text);
1285 if ($to->{'href'}) {
1286 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1287 -class=>"list"}, $to_text);
1289 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1290 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1291 return "<div class=\"diff$diff_class\">$line</div>\n";
1292 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1293 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1294 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1296 @from_text = split(' ', $ranges);
1297 for (my $i = 0; $i < @from_text; ++$i) {
1298 ($from_start[$i], $from_nlines[$i]) =
1299 (split(',', substr($from_text[$i], 1)), 0);
1302 $to_text = pop @from_text;
1303 $to_start = pop @from_start;
1304 $to_nlines = pop @from_nlines;
1306 $line = "<span class=\"chunk_info\">$prefix ";
1307 for (my $i = 0; $i < @from_text; ++$i) {
1308 if ($from->{'href'}[$i]) {
1309 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1310 -class=>"list"}, $from_text[$i]);
1312 $line .= $from_text[$i];
1316 if ($to->{'href'}) {
1317 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1318 -class=>"list"}, $to_text);
1322 $line .= " $prefix</span>" .
1323 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1324 return "<div class=\"diff$diff_class\">$line</div>\n";
1326 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1329 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1330 # linked. Pass the hash of the tree/commit to snapshot.
1331 sub format_snapshot_links
{
1333 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1334 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1335 my $num_fmts = @snapshot_fmts;
1336 if ($num_fmts > 1) {
1337 # A parenthesized list of links bearing format names.
1338 # e.g. "snapshot (_tar.gz_ _zip_)"
1339 return "snapshot (" . join(' ', map
1346 }, $known_snapshot_formats{$_}{'display'})
1347 , @snapshot_fmts) . ")";
1348 } elsif ($num_fmts == 1) {
1349 # A single "snapshot" link whose tooltip bears the format name.
1351 my ($fmt) = @snapshot_fmts;
1357 snapshot_format
=>$fmt
1359 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1361 } else { # $num_fmts == 0
1366 ## ----------------------------------------------------------------------
1367 ## git utility subroutines, invoking git commands
1369 # returns path to the core git executable and the --git-dir parameter as list
1371 return $GIT, '--git-dir='.$git_dir;
1374 # returns path to the core git executable and the --git-dir parameter as string
1376 return join(' ', git_cmd
());
1379 # get HEAD ref of given project as hash
1380 sub git_get_head_hash
{
1381 my $project = shift;
1382 my $o_git_dir = $git_dir;
1384 $git_dir = "$projectroot/$project";
1385 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1388 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1392 if (defined $o_git_dir) {
1393 $git_dir = $o_git_dir;
1398 # get type of given object
1402 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1404 close $fd or return;
1409 sub git_get_project_config
{
1410 my ($key, $type) = @_;
1412 return unless ($key);
1413 $key =~ s/^gitweb\.//;
1414 return if ($key =~ m/\W/);
1416 my @x = (git_cmd
(), 'config');
1417 if (defined $type) { push @x, $type; }
1419 push @x, "gitweb.$key";
1425 # get hash of given path at given ref
1426 sub git_get_hash_by_path
{
1428 my $path = shift || return undef;
1433 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1434 or die_error
(undef, "Open git-ls-tree failed");
1436 close $fd or return undef;
1438 if (!defined $line) {
1439 # there is no tree or hash given by $path at $base
1443 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1444 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1445 if (defined $type && $type ne $2) {
1446 # type doesn't match
1452 # get path of entry with given hash at given tree-ish (ref)
1453 # used to get 'from' filename for combined diff (merge commit) for renames
1454 sub git_get_path_by_hash
{
1455 my $base = shift || return;
1456 my $hash = shift || return;
1460 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1462 while (my $line = <$fd>) {
1465 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1466 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1467 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1476 ## ......................................................................
1477 ## git utility functions, directly accessing git repository
1479 sub git_get_project_description
{
1482 open my $fd, "$projectroot/$path/description" or return undef;
1485 if (defined $descr) {
1491 sub git_get_project_url_list
{
1494 open my $fd, "$projectroot/$path/cloneurl" or return;
1495 my @git_project_url_list = map { chomp; $_ } <$fd>;
1498 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1501 sub git_get_projects_list
{
1506 $filter =~ s/\.git$//;
1508 my ($check_forks) = gitweb_check_feature
('forks');
1510 if (-d
$projects_list) {
1511 # search in directory
1512 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1513 # remove the trailing "/"
1515 my $pfxlen = length("$dir");
1516 my $pfxdepth = ($dir =~ tr!/!!);
1519 follow_fast
=> 1, # follow symbolic links
1520 follow_skip
=> 2, # ignore duplicates
1521 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1524 our $project_maxdepth;
1526 # skip project-list toplevel, if we get it.
1527 return if (m!^[/.]$!);
1528 # only directories can be git repositories
1529 return unless (-d
$_);
1530 # don't traverse too deep (Find is super slow on os x)
1531 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1532 $File::Find
::prune
= 1;
1536 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1537 # we check related file in $projectroot
1538 if ($check_forks and $subdir =~ m
#/.#) {
1539 $File::Find
::prune
= 1;
1540 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1541 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1542 $File::Find
::prune
= 1;
1547 } elsif (-f
$projects_list) {
1548 # read from file(url-encoded):
1549 # 'git%2Fgit.git Linus+Torvalds'
1550 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1551 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1553 open my ($fd), $projects_list or return;
1555 while (my $line = <$fd>) {
1557 my ($path, $owner) = split ' ', $line;
1558 $path = unescape
($path);
1559 $owner = unescape
($owner);
1560 if (!defined $path) {
1563 if ($filter ne '') {
1564 # looking for forks;
1565 my $pfx = substr($path, 0, length($filter));
1566 if ($pfx ne $filter) {
1569 my $sfx = substr($path, length($filter));
1570 if ($sfx !~ /^\/.*\
.git
$/) {
1573 } elsif ($check_forks) {
1575 foreach my $filter (keys %paths) {
1576 # looking for forks;
1577 my $pfx = substr($path, 0, length($filter));
1578 if ($pfx ne $filter) {
1581 my $sfx = substr($path, length($filter));
1582 if ($sfx !~ /^\/.*\
.git
$/) {
1585 # is a fork, don't include it in
1590 if (check_export_ok
("$projectroot/$path")) {
1593 owner
=> to_utf8
($owner),
1596 (my $forks_path = $path) =~ s/\.git$//;
1597 $paths{$forks_path}++;
1605 our $gitweb_project_owner = undef;
1606 sub git_get_project_list_from_file
{
1608 return if (defined $gitweb_project_owner);
1610 $gitweb_project_owner = {};
1611 # read from file (url-encoded):
1612 # 'git%2Fgit.git Linus+Torvalds'
1613 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1614 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1615 if (-f
$projects_list) {
1616 open (my $fd , $projects_list);
1617 while (my $line = <$fd>) {
1619 my ($pr, $ow) = split ' ', $line;
1620 $pr = unescape
($pr);
1621 $ow = unescape
($ow);
1622 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1628 sub git_get_project_owner
{
1629 my $project = shift;
1632 return undef unless $project;
1634 if (!defined $gitweb_project_owner) {
1635 git_get_project_list_from_file
();
1638 if (exists $gitweb_project_owner->{$project}) {
1639 $owner = $gitweb_project_owner->{$project};
1641 if (!defined $owner) {
1642 $owner = get_file_owner
("$projectroot/$project");
1648 sub git_get_last_activity
{
1652 $git_dir = "$projectroot/$path";
1653 open($fd, "-|", git_cmd
(), 'for-each-ref',
1654 '--format=%(committer)',
1655 '--sort=-committerdate',
1657 'refs/heads') or return;
1658 my $most_recent = <$fd>;
1659 close $fd or return;
1660 if (defined $most_recent &&
1661 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1663 my $age = time - $timestamp;
1664 return ($age, age_string
($age));
1666 return (undef, undef);
1669 sub git_get_references
{
1670 my $type = shift || "";
1672 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1673 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1674 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1675 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1678 while (my $line = <$fd>) {
1680 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1681 if (defined $refs{$1}) {
1682 push @
{$refs{$1}}, $2;
1688 close $fd or return;
1692 sub git_get_rev_name_tags
{
1693 my $hash = shift || return undef;
1695 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1697 my $name_rev = <$fd>;
1700 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1703 # catches also '$hash undefined' output
1708 ## ----------------------------------------------------------------------
1709 ## parse to hash functions
1713 my $tz = shift || "-0000";
1716 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1717 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1718 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1719 $date{'hour'} = $hour;
1720 $date{'minute'} = $min;
1721 $date{'mday'} = $mday;
1722 $date{'day'} = $days[$wday];
1723 $date{'month'} = $months[$mon];
1724 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1725 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1726 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1727 $mday, $months[$mon], $hour ,$min;
1728 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1729 1900+$year, $mon, $mday, $hour ,$min, $sec;
1731 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1732 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1733 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1734 $date{'hour_local'} = $hour;
1735 $date{'minute_local'} = $min;
1736 $date{'tz_local'} = $tz;
1737 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1738 1900+$year, $mon+1, $mday,
1739 $hour, $min, $sec, $tz);
1748 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1749 $tag{'id'} = $tag_id;
1750 while (my $line = <$fd>) {
1752 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1753 $tag{'object'} = $1;
1754 } elsif ($line =~ m/^type (.+)$/) {
1756 } elsif ($line =~ m/^tag (.+)$/) {
1758 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1759 $tag{'author'} = $1;
1762 } elsif ($line =~ m/--BEGIN/) {
1763 push @comment, $line;
1765 } elsif ($line eq "") {
1769 push @comment, <$fd>;
1770 $tag{'comment'} = \
@comment;
1771 close $fd or return;
1772 if (!defined $tag{'name'}) {
1778 sub parse_commit_text
{
1779 my ($commit_text, $withparents) = @_;
1780 my @commit_lines = split '\n', $commit_text;
1783 pop @commit_lines; # Remove '\0'
1785 if (! @commit_lines) {
1789 my $header = shift @commit_lines;
1790 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1793 ($co{'id'}, my @parents) = split ' ', $header;
1794 while (my $line = shift @commit_lines) {
1795 last if $line eq "\n";
1796 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1798 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1800 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1802 $co{'author_epoch'} = $2;
1803 $co{'author_tz'} = $3;
1804 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1805 $co{'author_name'} = $1;
1806 $co{'author_email'} = $2;
1808 $co{'author_name'} = $co{'author'};
1810 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1811 $co{'committer'} = $1;
1812 $co{'committer_epoch'} = $2;
1813 $co{'committer_tz'} = $3;
1814 $co{'committer_name'} = $co{'committer'};
1815 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1816 $co{'committer_name'} = $1;
1817 $co{'committer_email'} = $2;
1819 $co{'committer_name'} = $co{'committer'};
1823 if (!defined $co{'tree'}) {
1826 $co{'parents'} = \
@parents;
1827 $co{'parent'} = $parents[0];
1829 foreach my $title (@commit_lines) {
1832 $co{'title'} = chop_str
($title, 80, 5);
1833 # remove leading stuff of merges to make the interesting part visible
1834 if (length($title) > 50) {
1835 $title =~ s/^Automatic //;
1836 $title =~ s/^merge (of|with) /Merge ... /i;
1837 if (length($title) > 50) {
1838 $title =~ s/(http|rsync):\/\///;
1840 if (length($title) > 50) {
1841 $title =~ s/(master|www|rsync)\.//;
1843 if (length($title) > 50) {
1844 $title =~ s/kernel.org:?//;
1846 if (length($title) > 50) {
1847 $title =~ s/\/pub\/scm//;
1850 $co{'title_short'} = chop_str
($title, 50, 5);
1854 if ($co{'title'} eq "") {
1855 $co{'title'} = $co{'title_short'} = '(no commit message)';
1857 # remove added spaces
1858 foreach my $line (@commit_lines) {
1861 $co{'comment'} = \
@commit_lines;
1863 my $age = time - $co{'committer_epoch'};
1865 $co{'age_string'} = age_string
($age);
1866 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1867 if ($age > 60*60*24*7*2) {
1868 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1869 $co{'age_string_age'} = $co{'age_string'};
1871 $co{'age_string_date'} = $co{'age_string'};
1872 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1878 my ($commit_id) = @_;
1883 open my $fd, "-|", git_cmd
(), "rev-list",
1889 or die_error
(undef, "Open git-rev-list failed");
1890 %co = parse_commit_text
(<$fd>, 1);
1897 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1905 open my $fd, "-|", git_cmd
(), "rev-list",
1907 ($arg ?
($arg) : ()),
1908 ("--max-count=" . $maxcount),
1909 ("--skip=" . $skip),
1913 ($filename ?
($filename) : ())
1914 or die_error
(undef, "Open git-rev-list failed");
1915 while (my $line = <$fd>) {
1916 my %co = parse_commit_text
($line);
1921 return wantarray ?
@cos : \
@cos;
1924 # parse ref from ref_file, given by ref_id, with given type
1926 my $ref_file = shift;
1928 my $type = shift || git_get_type
($ref_id);
1931 $ref_item{'type'} = $type;
1932 $ref_item{'id'} = $ref_id;
1933 $ref_item{'epoch'} = 0;
1934 $ref_item{'age'} = "unknown";
1935 if ($type eq "tag") {
1936 my %tag = parse_tag
($ref_id);
1937 $ref_item{'comment'} = $tag{'comment'};
1938 if ($tag{'type'} eq "commit") {
1939 my %co = parse_commit
($tag{'object'});
1940 $ref_item{'epoch'} = $co{'committer_epoch'};
1941 $ref_item{'age'} = $co{'age_string'};
1942 } elsif (defined($tag{'epoch'})) {
1943 my $age = time - $tag{'epoch'};
1944 $ref_item{'epoch'} = $tag{'epoch'};
1945 $ref_item{'age'} = age_string
($age);
1947 $ref_item{'reftype'} = $tag{'type'};
1948 $ref_item{'name'} = $tag{'name'};
1949 $ref_item{'refid'} = $tag{'object'};
1950 } elsif ($type eq "commit"){
1951 my %co = parse_commit
($ref_id);
1952 $ref_item{'reftype'} = "commit";
1953 $ref_item{'name'} = $ref_file;
1954 $ref_item{'title'} = $co{'title'};
1955 $ref_item{'refid'} = $ref_id;
1956 $ref_item{'epoch'} = $co{'committer_epoch'};
1957 $ref_item{'age'} = $co{'age_string'};
1959 $ref_item{'reftype'} = $type;
1960 $ref_item{'name'} = $ref_file;
1961 $ref_item{'refid'} = $ref_id;
1967 # parse line of git-diff-tree "raw" output
1968 sub parse_difftree_raw_line
{
1972 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1973 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1974 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1975 $res{'from_mode'} = $1;
1976 $res{'to_mode'} = $2;
1977 $res{'from_id'} = $3;
1979 $res{'status'} = $5;
1980 $res{'similarity'} = $6;
1981 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1982 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1984 $res{'file'} = unquote
($7);
1987 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1988 # combined diff (for merge commit)
1989 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1990 $res{'nparents'} = length($1);
1991 $res{'from_mode'} = [ split(' ', $2) ];
1992 $res{'to_mode'} = pop @
{$res{'from_mode'}};
1993 $res{'from_id'} = [ split(' ', $3) ];
1994 $res{'to_id'} = pop @
{$res{'from_id'}};
1995 $res{'status'} = [ split('', $4) ];
1996 $res{'to_file'} = unquote
($5);
1998 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1999 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2000 $res{'commit'} = $1;
2003 return wantarray ?
%res : \
%res;
2006 # parse line of git-ls-tree output
2007 sub parse_ls_tree_line
($;%) {
2012 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2013 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2021 $res{'name'} = unquote
($4);
2024 return wantarray ?
%res : \
%res;
2027 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2028 sub parse_from_to_diffinfo
{
2029 my ($diffinfo, $from, $to, @parents) = @_;
2031 if ($diffinfo->{'nparents'}) {
2033 $from->{'file'} = [];
2034 $from->{'href'} = [];
2035 fill_from_file_info
($diffinfo, @parents)
2036 unless exists $diffinfo->{'from_file'};
2037 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2038 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2039 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2040 $from->{'href'}[$i] = href
(action
=>"blob",
2041 hash_base
=>$parents[$i],
2042 hash
=>$diffinfo->{'from_id'}[$i],
2043 file_name
=>$from->{'file'}[$i]);
2045 $from->{'href'}[$i] = undef;
2049 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2050 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2051 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2052 hash
=>$diffinfo->{'from_id'},
2053 file_name
=>$from->{'file'});
2055 delete $from->{'href'};
2059 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2060 if (!is_deleted
($diffinfo)) { # file exists in result
2061 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2062 hash
=>$diffinfo->{'to_id'},
2063 file_name
=>$to->{'file'});
2065 delete $to->{'href'};
2069 ## ......................................................................
2070 ## parse to array of hashes functions
2072 sub git_get_heads_list
{
2076 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2077 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2078 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2081 while (my $line = <$fd>) {
2085 my ($refinfo, $committerinfo) = split(/\0/, $line);
2086 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2087 my ($committer, $epoch, $tz) =
2088 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2089 $name =~ s!^refs/heads/!!;
2091 $ref_item{'name'} = $name;
2092 $ref_item{'id'} = $hash;
2093 $ref_item{'title'} = $title || '(no commit message)';
2094 $ref_item{'epoch'} = $epoch;
2096 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2098 $ref_item{'age'} = "unknown";
2101 push @headslist, \
%ref_item;
2105 return wantarray ?
@headslist : \
@headslist;
2108 sub git_get_tags_list
{
2112 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2113 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2114 '--format=%(objectname) %(objecttype) %(refname) '.
2115 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2118 while (my $line = <$fd>) {
2122 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2123 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2124 my ($creator, $epoch, $tz) =
2125 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2126 $name =~ s!^refs/tags/!!;
2128 $ref_item{'type'} = $type;
2129 $ref_item{'id'} = $id;
2130 $ref_item{'name'} = $name;
2131 if ($type eq "tag") {
2132 $ref_item{'subject'} = $title;
2133 $ref_item{'reftype'} = $reftype;
2134 $ref_item{'refid'} = $refid;
2136 $ref_item{'reftype'} = $type;
2137 $ref_item{'refid'} = $id;
2140 if ($type eq "tag" || $type eq "commit") {
2141 $ref_item{'epoch'} = $epoch;
2143 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2145 $ref_item{'age'} = "unknown";
2149 push @tagslist, \
%ref_item;
2153 return wantarray ?
@tagslist : \
@tagslist;
2156 ## ----------------------------------------------------------------------
2157 ## filesystem-related functions
2159 sub get_file_owner
{
2162 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2163 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2164 if (!defined $gcos) {
2168 $owner =~ s/[,;].*$//;
2169 return to_utf8
($owner);
2172 ## ......................................................................
2173 ## mimetype related functions
2175 sub mimetype_guess_file
{
2176 my $filename = shift;
2177 my $mimemap = shift;
2178 -r
$mimemap or return undef;
2181 open(MIME
, $mimemap) or return undef;
2183 next if m/^#/; # skip comments
2184 my ($mime, $exts) = split(/\t+/);
2185 if (defined $exts) {
2186 my @exts = split(/\s+/, $exts);
2187 foreach my $ext (@exts) {
2188 $mimemap{$ext} = $mime;
2194 $filename =~ /\.([^.]*)$/;
2195 return $mimemap{$1};
2198 sub mimetype_guess
{
2199 my $filename = shift;
2201 $filename =~ /\./ or return undef;
2203 if ($mimetypes_file) {
2204 my $file = $mimetypes_file;
2205 if ($file !~ m!^/!) { # if it is relative path
2206 # it is relative to project
2207 $file = "$projectroot/$project/$file";
2209 $mime = mimetype_guess_file
($filename, $file);
2211 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2217 my $filename = shift;
2220 my $mime = mimetype_guess
($filename);
2221 $mime and return $mime;
2225 return $default_blob_plain_mimetype unless $fd;
2228 return 'text/plain' .
2229 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2230 } elsif (! $filename) {
2231 return 'application/octet-stream';
2232 } elsif ($filename =~ m/\.png$/i) {
2234 } elsif ($filename =~ m/\.gif$/i) {
2236 } elsif ($filename =~ m/\.jpe?g$/i) {
2237 return 'image/jpeg';
2239 return 'application/octet-stream';
2243 ## ======================================================================
2244 ## functions printing HTML: header, footer, error page
2246 sub git_header_html
{
2247 my $status = shift || "200 OK";
2248 my $expires = shift;
2250 my $title = "$site_name";
2251 if (defined $project) {
2252 $title .= " - " . to_utf8
($project);
2253 if (defined $action) {
2254 $title .= "/$action";
2255 if (defined $file_name) {
2256 $title .= " - " . esc_path
($file_name);
2257 if ($action eq "tree" && $file_name !~ m
|/$|) {
2264 # require explicit support from the UA if we are to send the page as
2265 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2266 # we have to do this because MSIE sometimes globs '*/*', pretending to
2267 # support xhtml+xml but choking when it gets what it asked for.
2268 if (defined $cgi->http('HTTP_ACCEPT') &&
2269 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2270 $cgi->Accept('application/xhtml+xml') != 0) {
2271 $content_type = 'application/xhtml+xml';
2273 $content_type = 'text/html';
2275 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2276 -status
=> $status, -expires
=> $expires);
2277 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2279 <?xml version="1.0" encoding="utf-8"?>
2280 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2281 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2282 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2283 <!-- git core binaries version $git_version -->
2285 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2286 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2287 <meta name="robots" content="index, nofollow"/>
2288 <title>$title</title>
2290 # print out each stylesheet that exist
2291 if (defined $stylesheet) {
2292 #provides backwards capability for those people who define style sheet in a config file
2293 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2295 foreach my $stylesheet (@stylesheets) {
2296 next unless $stylesheet;
2297 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2300 if (defined $project) {
2301 printf('<link rel="alternate" title="%s log RSS feed" '.
2302 'href="%s" type="application/rss+xml" />'."\n",
2303 esc_param
($project), href
(action
=>"rss"));
2304 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2305 'href="%s" type="application/rss+xml" />'."\n",
2306 esc_param
($project), href
(action
=>"rss",
2307 extra_options
=>"--no-merges"));
2308 printf('<link rel="alternate" title="%s log Atom feed" '.
2309 'href="%s" type="application/atom+xml" />'."\n",
2310 esc_param
($project), href
(action
=>"atom"));
2311 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2312 'href="%s" type="application/atom+xml" />'."\n",
2313 esc_param
($project), href
(action
=>"atom",
2314 extra_options
=>"--no-merges"));
2316 printf('<link rel="alternate" title="%s projects list" '.
2317 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2318 $site_name, href
(project
=>undef, action
=>"project_index"));
2319 printf('<link rel="alternate" title="%s projects feeds" '.
2320 'href="%s" type="text/x-opml"/>'."\n",
2321 $site_name, href
(project
=>undef, action
=>"opml"));
2323 if (defined $favicon) {
2324 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2330 if (-f
$site_header) {
2331 open (my $fd, $site_header);
2336 print "<div class=\"page_header\">\n" .
2337 $cgi->a({-href
=> esc_url
($logo_url),
2338 -title
=> $logo_label},
2339 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2340 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2341 if (defined $project) {
2342 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2343 if (defined $action) {
2350 my ($have_search) = gitweb_check_feature
('search');
2351 if ((defined $project) && ($have_search)) {
2352 if (!defined $searchtext) {
2356 if (defined $hash_base) {
2357 $search_hash = $hash_base;
2358 } elsif (defined $hash) {
2359 $search_hash = $hash;
2361 $search_hash = "HEAD";
2363 my $action = $my_uri;
2364 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2365 if ($use_pathinfo) {
2366 $action .= "/$project";
2368 $cgi->param("p", $project);
2370 $cgi->param("a", "search");
2371 $cgi->param("h", $search_hash);
2372 print $cgi->startform(-method
=> "get", -action
=> $action) .
2373 "<div class=\"search\">\n" .
2374 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2375 $cgi->hidden(-name
=> "a") . "\n" .
2376 $cgi->hidden(-name
=> "h") . "\n" .
2377 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2378 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2379 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2381 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2383 $cgi->end_form() . "\n";
2387 sub git_footer_html
{
2388 print "<div class=\"page_footer\">\n";
2389 if (defined $project) {
2390 my $descr = git_get_project_description
($project);
2391 if (defined $descr) {
2392 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2394 print $cgi->a({-href
=> href
(action
=>"rss"),
2395 -class => "rss_logo"}, "RSS") . " ";
2396 print $cgi->a({-href
=> href
(action
=>"atom"),
2397 -class => "rss_logo"}, "Atom") . "\n";
2399 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2400 -class => "rss_logo"}, "OPML") . " ";
2401 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2402 -class => "rss_logo"}, "TXT") . "\n";
2406 if (-f
$site_footer) {
2407 open (my $fd, $site_footer);
2417 my $status = shift || "403 Forbidden";
2418 my $error = shift || "Malformed query, file missing or permission denied";
2420 git_header_html
($status);
2422 <div class="page_body">
2432 ## ----------------------------------------------------------------------
2433 ## functions printing or outputting HTML: navigation
2435 sub git_print_page_nav
{
2436 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2437 $extra = '' if !defined $extra; # pager or formats
2439 my @navs = qw(summary shortlog log commit commitdiff tree);
2441 @navs = grep { $_ ne $suppress } @navs;
2444 my %arg = map { $_ => {action
=>$_} } @navs;
2445 if (defined $head) {
2446 for (qw(commit commitdiff)) {
2447 $arg{$_}{'hash'} = $head;
2449 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2450 for (qw(shortlog log)) {
2451 $arg{$_}{'hash'} = $head;
2455 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2456 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2458 print "<div class=\"page_nav\">\n" .
2460 map { $_ eq $current ?
2461 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2463 print "<br/>\n$extra<br/>\n" .
2467 sub format_paging_nav
{
2468 my ($action, $hash, $head, $page, $nrevs) = @_;
2472 if ($hash ne $head || $page) {
2473 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2475 $paging_nav .= "HEAD";
2479 $paging_nav .= " ⋅ " .
2480 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2481 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2483 $paging_nav .= " ⋅ prev";
2486 if ($nrevs >= (100 * ($page+1)-1)) {
2487 $paging_nav .= " ⋅ " .
2488 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2489 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2491 $paging_nav .= " ⋅ next";
2497 ## ......................................................................
2498 ## functions printing or outputting HTML: div
2500 sub git_print_header_div
{
2501 my ($action, $title, $hash, $hash_base) = @_;
2504 $args{'action'} = $action;
2505 $args{'hash'} = $hash if $hash;
2506 $args{'hash_base'} = $hash_base if $hash_base;
2508 print "<div class=\"header\">\n" .
2509 $cgi->a({-href
=> href
(%args), -class => "title"},
2510 $title ?
$title : $action) .
2514 #sub git_print_authorship (\%) {
2515 sub git_print_authorship
{
2518 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2519 print "<div class=\"author_date\">" .
2520 esc_html
($co->{'author_name'}) .
2522 if ($ad{'hour_local'} < 6) {
2523 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2524 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2526 printf(" (%02d:%02d %s)",
2527 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2532 sub git_print_page_path
{
2538 print "<div class=\"page_path\">";
2539 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2540 -title
=> 'tree root'}, to_utf8
("[$project]"));
2542 if (defined $name) {
2543 my @dirname = split '/', $name;
2544 my $basename = pop @dirname;
2547 foreach my $dir (@dirname) {
2548 $fullname .= ($fullname ?
'/' : '') . $dir;
2549 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2551 -title
=> $fullname}, esc_path
($dir));
2554 if (defined $type && $type eq 'blob') {
2555 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2557 -title
=> $name}, esc_path
($basename));
2558 } elsif (defined $type && $type eq 'tree') {
2559 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2561 -title
=> $name}, esc_path
($basename));
2564 print esc_path
($basename);
2567 print "<br/></div>\n";
2570 # sub git_print_log (\@;%) {
2571 sub git_print_log
($;%) {
2575 if ($opts{'-remove_title'}) {
2576 # remove title, i.e. first line of log
2579 # remove leading empty lines
2580 while (defined $log->[0] && $log->[0] eq "") {
2587 foreach my $line (@
$log) {
2588 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2591 if (! $opts{'-remove_signoff'}) {
2592 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2595 # remove signoff lines
2602 # print only one empty line
2603 # do not print empty line after signoff
2605 next if ($empty || $signoff);
2611 print format_log_line_html
($line) . "<br/>\n";
2614 if ($opts{'-final_empty_line'}) {
2615 # end with single empty line
2616 print "<br/>\n" unless $empty;
2620 # return link target (what link points to)
2621 sub git_get_link_target
{
2626 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2630 $link_target = <$fd>;
2635 return $link_target;
2638 # given link target, and the directory (basedir) the link is in,
2639 # return target of link relative to top directory (top tree);
2640 # return undef if it is not possible (including absolute links).
2641 sub normalize_link_target
{
2642 my ($link_target, $basedir, $hash_base) = @_;
2644 # we can normalize symlink target only if $hash_base is provided
2645 return unless $hash_base;
2647 # absolute symlinks (beginning with '/') cannot be normalized
2648 return if (substr($link_target, 0, 1) eq '/');
2650 # normalize link target to path from top (root) tree (dir)
2653 $path = $basedir . '/' . $link_target;
2655 # we are in top (root) tree (dir)
2656 $path = $link_target;
2659 # remove //, /./, and /../
2661 foreach my $part (split('/', $path)) {
2662 # discard '.' and ''
2663 next if (!$part || $part eq '.');
2665 if ($part eq '..') {
2669 # link leads outside repository (outside top dir)
2673 push @path_parts, $part;
2676 $path = join('/', @path_parts);
2681 # print tree entry (row of git_tree), but without encompassing <tr> element
2682 sub git_print_tree_entry
{
2683 my ($t, $basedir, $hash_base, $have_blame) = @_;
2686 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2688 # The format of a table row is: mode list link. Where mode is
2689 # the mode of the entry, list is the name of the entry, an href,
2690 # and link is the action links of the entry.
2692 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2693 if ($t->{'type'} eq "blob") {
2694 print "<td class=\"list\">" .
2695 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2696 file_name
=>"$basedir$t->{'name'}", %base_key),
2697 -class => "list"}, esc_path
($t->{'name'}));
2698 if (S_ISLNK
(oct $t->{'mode'})) {
2699 my $link_target = git_get_link_target
($t->{'hash'});
2701 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2702 if (defined $norm_target) {
2704 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2705 file_name
=>$norm_target),
2706 -title
=> $norm_target}, esc_path
($link_target));
2708 print " -> " . esc_path
($link_target);
2713 print "<td class=\"link\">";
2714 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2715 file_name
=>"$basedir$t->{'name'}", %base_key)},
2719 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2720 file_name
=>"$basedir$t->{'name'}", %base_key)},
2723 if (defined $hash_base) {
2725 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2726 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2730 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2731 file_name
=>"$basedir$t->{'name'}")},
2735 } elsif ($t->{'type'} eq "tree") {
2736 print "<td class=\"list\">";
2737 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2738 file_name
=>"$basedir$t->{'name'}", %base_key)},
2739 esc_path
($t->{'name'}));
2741 print "<td class=\"link\">";
2742 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2743 file_name
=>"$basedir$t->{'name'}", %base_key)},
2745 if (defined $hash_base) {
2747 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2748 file_name
=>"$basedir$t->{'name'}")},
2753 # unknown object: we can only present history for it
2754 # (this includes 'commit' object, i.e. submodule support)
2755 print "<td class=\"list\">" .
2756 esc_path
($t->{'name'}) .
2758 print "<td class=\"link\">";
2759 if (defined $hash_base) {
2760 print $cgi->a({-href
=> href
(action
=>"history",
2761 hash_base
=>$hash_base,
2762 file_name
=>"$basedir$t->{'name'}")},
2769 ## ......................................................................
2770 ## functions printing large fragments of HTML
2772 sub fill_from_file_info
{
2773 my ($diff, @parents) = @_;
2775 $diff->{'from_file'} = [ ];
2776 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2777 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2778 if ($diff->{'status'}[$i] eq 'R' ||
2779 $diff->{'status'}[$i] eq 'C') {
2780 $diff->{'from_file'}[$i] =
2781 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2788 # parameters can be strings, or references to arrays of strings
2792 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @
$a == @
$b) {
2793 for (my $i = 0; $i < @
$a; ++$i) {
2794 return 0 unless ($a->[$i] eq $b->[$i]);
2797 } elsif (!ref($a) && !ref($b)) {
2805 my $diffinfo = shift;
2807 return $diffinfo->{'to_id'} eq ('0' x
40);
2810 sub git_difftree_body
{
2811 my ($difftree, $hash, @parents) = @_;
2812 my ($parent) = $parents[0];
2813 my ($have_blame) = gitweb_check_feature
('blame');
2814 print "<div class=\"list_head\">\n";
2815 if ($#{$difftree} > 10) {
2816 print(($#{$difftree} + 1) . " files changed:\n");
2820 print "<table class=\"" .
2821 (@parents > 1 ?
"combined " : "") .
2824 # header only for combined diff in 'commitdiff' view
2825 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
2828 print "<thead><tr>\n" .
2829 "<th></th><th></th>\n"; # filename, patchN link
2830 for (my $i = 0; $i < @parents; $i++) {
2831 my $par = $parents[$i];
2833 $cgi->a({-href
=> href
(action
=>"commitdiff",
2834 hash
=>$hash, hash_parent
=>$par),
2835 -title
=> 'commitdiff to parent number ' .
2836 ($i+1) . ': ' . substr($par,0,7)},
2840 print "</tr></thead>\n<tbody>\n";
2845 foreach my $line (@
{$difftree}) {
2847 if (ref($line) eq "HASH") {
2848 # pre-parsed (or generated by hand)
2851 $diff = parse_difftree_raw_line
($line);
2855 print "<tr class=\"dark\">\n";
2857 print "<tr class=\"light\">\n";
2861 if (exists $diff->{'nparents'}) { # combined diff
2863 fill_from_file_info
($diff, @parents)
2864 unless exists $diff->{'from_file'};
2866 if (!is_deleted
($diff)) {
2867 # file exists in the result (child) commit
2869 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2870 file_name
=>$diff->{'to_file'},
2872 -class => "list"}, esc_path
($diff->{'to_file'})) .
2876 esc_path
($diff->{'to_file'}) .
2880 if ($action eq 'commitdiff') {
2883 print "<td class=\"link\">" .
2884 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2889 my $has_history = 0;
2890 my $not_deleted = 0;
2891 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2892 my $hash_parent = $parents[$i];
2893 my $from_hash = $diff->{'from_id'}[$i];
2894 my $from_path = $diff->{'from_file'}[$i];
2895 my $status = $diff->{'status'}[$i];
2897 $has_history ||= ($status ne 'A');
2898 $not_deleted ||= ($status ne 'D');
2900 if ($status eq 'A') {
2901 print "<td class=\"link\" align=\"right\"> | </td>\n";
2902 } elsif ($status eq 'D') {
2903 print "<td class=\"link\">" .
2904 $cgi->a({-href
=> href
(action
=>"blob",
2907 file_name
=>$from_path)},
2911 if ($diff->{'to_id'} eq $from_hash) {
2912 print "<td class=\"link nochange\">";
2914 print "<td class=\"link\">";
2916 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2917 hash
=>$diff->{'to_id'},
2918 hash_parent
=>$from_hash,
2920 hash_parent_base
=>$hash_parent,
2921 file_name
=>$diff->{'to_file'},
2922 file_parent
=>$from_path)},
2928 print "<td class=\"link\">";
2930 print $cgi->a({-href
=> href
(action
=>"blob",
2931 hash
=>$diff->{'to_id'},
2932 file_name
=>$diff->{'to_file'},
2935 print " | " if ($has_history);
2938 print $cgi->a({-href
=> href
(action
=>"history",
2939 file_name
=>$diff->{'to_file'},
2946 next; # instead of 'else' clause, to avoid extra indent
2948 # else ordinary diff
2950 my ($to_mode_oct, $to_mode_str, $to_file_type);
2951 my ($from_mode_oct, $from_mode_str, $from_file_type);
2952 if ($diff->{'to_mode'} ne ('0' x
6)) {
2953 $to_mode_oct = oct $diff->{'to_mode'};
2954 if (S_ISREG
($to_mode_oct)) { # only for regular file
2955 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2957 $to_file_type = file_type
($diff->{'to_mode'});
2959 if ($diff->{'from_mode'} ne ('0' x
6)) {
2960 $from_mode_oct = oct $diff->{'from_mode'};
2961 if (S_ISREG
($to_mode_oct)) { # only for regular file
2962 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2964 $from_file_type = file_type
($diff->{'from_mode'});
2967 if ($diff->{'status'} eq "A") { # created
2968 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2969 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2970 $mode_chng .= "]</span>";
2972 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2973 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2974 -class => "list"}, esc_path
($diff->{'file'}));
2976 print "<td>$mode_chng</td>\n";
2977 print "<td class=\"link\">";
2978 if ($action eq 'commitdiff') {
2981 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2984 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2985 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2989 } elsif ($diff->{'status'} eq "D") { # deleted
2990 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2992 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2993 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2994 -class => "list"}, esc_path
($diff->{'file'}));
2996 print "<td>$mode_chng</td>\n";
2997 print "<td class=\"link\">";
2998 if ($action eq 'commitdiff') {
3001 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3004 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3005 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3008 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3009 file_name
=>$diff->{'file'})},
3012 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3013 file_name
=>$diff->{'file'})},
3017 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3018 my $mode_chnge = "";
3019 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3020 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3021 if ($from_file_type ne $to_file_type) {
3022 $mode_chnge .= " from $from_file_type to $to_file_type";
3024 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3025 if ($from_mode_str && $to_mode_str) {
3026 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3027 } elsif ($to_mode_str) {
3028 $mode_chnge .= " mode: $to_mode_str";
3031 $mode_chnge .= "]</span>\n";
3034 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3035 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3036 -class => "list"}, esc_path
($diff->{'file'}));
3038 print "<td>$mode_chnge</td>\n";
3039 print "<td class=\"link\">";
3040 if ($action eq 'commitdiff') {
3043 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3045 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3046 # "commit" view and modified file (not onlu mode changed)
3047 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3048 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3049 hash_base
=>$hash, hash_parent_base
=>$parent,
3050 file_name
=>$diff->{'file'})},
3054 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3055 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3058 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3059 file_name
=>$diff->{'file'})},
3062 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3063 file_name
=>$diff->{'file'})},
3067 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3068 my %status_name = ('R' => 'moved', 'C' => 'copied');
3069 my $nstatus = $status_name{$diff->{'status'}};
3071 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3072 # mode also for directories, so we cannot use $to_mode_str
3073 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3076 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3077 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3078 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3079 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3080 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3081 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3082 -class => "list"}, esc_path
($diff->{'from_file'})) .
3083 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3084 "<td class=\"link\">";
3085 if ($action eq 'commitdiff') {
3088 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3090 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3091 # "commit" view and modified file (not only pure rename or copy)
3092 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3093 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3094 hash_base
=>$hash, hash_parent_base
=>$parent,
3095 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3099 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3100 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3103 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3104 file_name
=>$diff->{'to_file'})},
3107 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3108 file_name
=>$diff->{'to_file'})},
3112 } # we should not encounter Unmerged (U) or Unknown (X) status
3115 print "</tbody>" if $has_header;
3119 sub git_patchset_body
{
3120 my ($fd, $difftree, $hash, @hash_parents) = @_;
3121 my ($hash_parent) = $hash_parents[0];
3124 my $patch_number = 0;
3129 print "<div class=\"patchset\">\n";
3131 # skip to first patch
3132 while ($patch_line = <$fd>) {
3135 last if ($patch_line =~ m/^diff /);
3139 while ($patch_line) {
3141 my ($from_id, $to_id);
3144 #assert($patch_line =~ m/^diff /) if DEBUG;
3145 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3147 push @diff_header, $patch_line;
3149 # extended diff header
3151 while ($patch_line = <$fd>) {
3154 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3156 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3159 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3160 $from_id = [ split(',', $1) ];
3164 push @diff_header, $patch_line;
3166 my $last_patch_line = $patch_line;
3168 # check if current patch belong to current raw line
3169 # and parse raw git-diff line if needed
3170 if (defined $diffinfo &&
3171 defined $from_id && defined $to_id &&
3172 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3173 $diffinfo->{'to_id'} eq $to_id) {
3174 # this is continuation of a split patch
3175 print "<div class=\"patch cont\">\n";
3177 # advance raw git-diff output if needed
3178 $patch_idx++ if defined $diffinfo;
3180 # compact combined diff output can have some patches skipped
3181 # find which patch (using pathname of result) we are at now
3183 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3188 # read and prepare patch information
3189 if (ref($difftree->[$patch_idx]) eq "HASH") {
3190 # pre-parsed (or generated by hand)
3191 $diffinfo = $difftree->[$patch_idx];
3193 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3196 # check if current raw line has no patch (it got simplified)
3197 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3198 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3199 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3200 "</div>\n"; # class="patch"
3205 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3206 $patch_idx > $#$difftree);
3208 # modifies %from, %to hashes
3209 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3211 # this is first patch for raw difftree line with $patch_idx index
3212 # we index @$difftree array from 0, but number patches from 1
3213 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3216 # print "git diff" header
3217 $patch_line = shift @diff_header;
3218 print format_git_diff_header_line
($patch_line, $diffinfo,
3221 # print extended diff header
3222 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3224 foreach $patch_line (@diff_header) {
3225 print format_extended_diff_header_line
($patch_line, $diffinfo,
3228 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3230 # from-file/to-file diff header
3231 $patch_line = $last_patch_line;
3232 if (! $patch_line) {
3233 print "</div>\n"; # class="patch"
3236 next PATCH
if ($patch_line =~ m/^diff /);
3237 #assert($patch_line =~ m/^---/) if DEBUG;
3238 #assert($patch_line eq $last_patch_line) if DEBUG;
3240 $patch_line = <$fd>;
3242 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3244 print format_diff_from_to_header
($last_patch_line, $patch_line,
3245 $diffinfo, \
%from, \
%to,
3250 while ($patch_line = <$fd>) {
3253 next PATCH
if ($patch_line =~ m/^diff /);
3255 print format_diff_line
($patch_line, \
%from, \
%to);
3259 print "</div>\n"; # class="patch"
3262 # for compact combined (--cc) format, with chunk and patch simpliciaction
3263 # patchset might be empty, but there might be unprocessed raw lines
3264 for ($patch_idx++ if $patch_number > 0;
3265 $patch_idx < @
$difftree;
3267 # read and prepare patch information
3268 if (ref($difftree->[$patch_idx]) eq "HASH") {
3269 # pre-parsed (or generated by hand)
3270 $diffinfo = $difftree->[$patch_idx];
3272 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3275 # generate anchor for "patch" links in difftree / whatchanged part
3276 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3277 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3278 "</div>\n"; # class="patch"
3283 if ($patch_number == 0) {
3284 if (@hash_parents > 1) {
3285 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3287 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3291 print "</div>\n"; # class="patchset"
3294 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3296 sub git_project_list_body
{
3297 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3299 my ($check_forks) = gitweb_check_feature
('forks');
3302 foreach my $pr (@
$projlist) {
3303 my (@aa) = git_get_last_activity
($pr->{'path'});
3307 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3308 if (!defined $pr->{'descr'}) {
3309 my $descr = git_get_project_description
($pr->{'path'}) || "";
3310 $pr->{'descr_long'} = to_utf8
($descr);
3311 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3313 if (!defined $pr->{'owner'}) {
3314 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3317 my $pname = $pr->{'path'};
3318 if (($pname =~ s/\.git$//) &&
3319 ($pname !~ /\/$/) &&
3320 (-d
"$projectroot/$pname")) {
3321 $pr->{'forks'} = "-d $projectroot/$pname";
3327 push @projects, $pr;
3330 $order ||= $default_projects_order;
3331 $from = 0 unless defined $from;
3332 $to = $#projects if (!defined $to || $#projects < $to);
3334 print "<table class=\"project_list\">\n";
3335 unless ($no_header) {
3338 print "<th></th>\n";
3340 if ($order eq "project") {
3341 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3342 print "<th>Project</th>\n";
3345 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3346 -class => "header"}, "Project") .
3349 if ($order eq "descr") {
3350 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3351 print "<th>Description</th>\n";
3354 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3355 -class => "header"}, "Description") .
3358 if ($order eq "owner") {
3359 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3360 print "<th>Owner</th>\n";
3363 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3364 -class => "header"}, "Owner") .
3367 if ($order eq "age") {
3368 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3369 print "<th>Last Change</th>\n";
3372 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3373 -class => "header"}, "Last Change") .
3376 print "<th></th>\n" .
3380 for (my $i = $from; $i <= $to; $i++) {
3381 my $pr = $projects[$i];
3383 print "<tr class=\"dark\">\n";
3385 print "<tr class=\"light\">\n";
3390 if ($pr->{'forks'}) {
3391 print "<!-- $pr->{'forks'} -->\n";
3392 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3396 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3397 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3398 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3399 -class => "list", -title
=> $pr->{'descr_long'}},
3400 esc_html
($pr->{'descr'})) . "</td>\n" .
3401 "<td><i>" . esc_html
(chop_str
($pr->{'owner'}, 15)) . "</i></td>\n";
3402 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3403 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3404 "<td class=\"link\">" .
3405 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3406 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3407 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3408 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3409 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3413 if (defined $extra) {
3416 print "<td></td>\n";
3418 print "<td colspan=\"5\">$extra</td>\n" .
3424 sub git_shortlog_body
{
3425 # uses global variable $project
3426 my ($commitlist, $from, $to, $refs, $extra) = @_;
3428 $from = 0 unless defined $from;
3429 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3431 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3433 for (my $i = $from; $i <= $to; $i++) {
3434 my %co = %{$commitlist->[$i]};
3435 my $commit = $co{'id'};
3436 my $ref = format_ref_marker
($refs, $commit);
3438 print "<tr class=\"dark\">\n";
3440 print "<tr class=\"light\">\n";
3443 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3444 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3445 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3447 print format_subject_html
($co{'title'}, $co{'title_short'},
3448 href
(action
=>"commit", hash
=>$commit), $ref);
3450 "<td class=\"link\">" .
3451 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3452 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3453 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3454 my $snapshot_links = format_snapshot_links
($commit);
3455 if (defined $snapshot_links) {
3456 print " | " . $snapshot_links;
3461 if (defined $extra) {
3463 "<td colspan=\"4\">$extra</td>\n" .
3469 sub git_history_body
{
3470 # Warning: assumes constant type (blob or tree) during history
3471 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3473 $from = 0 unless defined $from;
3474 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3476 print "<table class=\"history\" cellspacing=\"0\">\n";
3478 for (my $i = $from; $i <= $to; $i++) {
3479 my %co = %{$commitlist->[$i]};
3483 my $commit = $co{'id'};
3485 my $ref = format_ref_marker
($refs, $commit);
3488 print "<tr class=\"dark\">\n";
3490 print "<tr class=\"light\">\n";
3493 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3494 # shortlog uses chop_str($co{'author_name'}, 10)
3495 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3497 # originally git_history used chop_str($co{'title'}, 50)
3498 print format_subject_html
($co{'title'}, $co{'title_short'},
3499 href
(action
=>"commit", hash
=>$commit), $ref);
3501 "<td class=\"link\">" .
3502 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3503 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3505 if ($ftype eq 'blob') {
3506 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3507 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3508 if (defined $blob_current && defined $blob_parent &&
3509 $blob_current ne $blob_parent) {
3511 $cgi->a({-href
=> href
(action
=>"blobdiff",
3512 hash
=>$blob_current, hash_parent
=>$blob_parent,
3513 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3514 file_name
=>$file_name)},
3521 if (defined $extra) {
3523 "<td colspan=\"4\">$extra</td>\n" .
3530 # uses global variable $project
3531 my ($taglist, $from, $to, $extra) = @_;
3532 $from = 0 unless defined $from;
3533 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3535 print "<table class=\"tags\" cellspacing=\"0\">\n";
3537 for (my $i = $from; $i <= $to; $i++) {
3538 my $entry = $taglist->[$i];
3540 my $comment = $tag{'subject'};
3542 if (defined $comment) {
3543 $comment_short = chop_str
($comment, 30, 5);
3546 print "<tr class=\"dark\">\n";
3548 print "<tr class=\"light\">\n";
3551 if (defined $tag{'age'}) {
3552 print "<td><i>$tag{'age'}</i></td>\n";
3554 print "<td></td>\n";
3557 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3558 -class => "list name"}, esc_html
($tag{'name'})) .
3561 if (defined $comment) {
3562 print format_subject_html
($comment, $comment_short,
3563 href
(action
=>"tag", hash
=>$tag{'id'}));
3566 "<td class=\"selflink\">";
3567 if ($tag{'type'} eq "tag") {
3568 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3573 "<td class=\"link\">" . " | " .
3574 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3575 if ($tag{'reftype'} eq "commit") {
3576 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3577 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3578 } elsif ($tag{'reftype'} eq "blob") {
3579 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3584 if (defined $extra) {
3586 "<td colspan=\"5\">$extra</td>\n" .
3592 sub git_heads_body
{
3593 # uses global variable $project
3594 my ($headlist, $head, $from, $to, $extra) = @_;
3595 $from = 0 unless defined $from;
3596 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3598 print "<table class=\"heads\" cellspacing=\"0\">\n";
3600 for (my $i = $from; $i <= $to; $i++) {
3601 my $entry = $headlist->[$i];
3603 my $curr = $ref{'id'} eq $head;
3605 print "<tr class=\"dark\">\n";
3607 print "<tr class=\"light\">\n";
3610 print "<td><i>$ref{'age'}</i></td>\n" .
3611 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3612 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3613 -class => "list name"},esc_html
($ref{'name'})) .
3615 "<td class=\"link\">" .
3616 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3617 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3618 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3622 if (defined $extra) {
3624 "<td colspan=\"3\">$extra</td>\n" .
3630 sub git_search_grep_body
{
3631 my ($commitlist, $from, $to, $extra) = @_;
3632 $from = 0 unless defined $from;
3633 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3635 print "<table class=\"grep\" cellspacing=\"0\">\n";
3637 for (my $i = $from; $i <= $to; $i++) {
3638 my %co = %{$commitlist->[$i]};
3642 my $commit = $co{'id'};
3644 print "<tr class=\"dark\">\n";
3646 print "<tr class=\"light\">\n";
3649 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3650 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3652 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3653 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3654 my $comment = $co{'comment'};
3655 foreach my $line (@
$comment) {
3656 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3657 my $lead = esc_html
($1) || "";
3658 $lead = chop_str
($lead, 30, 10);
3659 my $match = esc_html
($2) || "";
3660 my $trail = esc_html
($3) || "";
3661 $trail = chop_str
($trail, 30, 10);
3662 my $text = "$lead<span class=\"match\">$match</span>$trail";
3663 print chop_str
($text, 80, 5) . "<br/>\n";
3667 "<td class=\"link\">" .
3668 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3670 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3674 if (defined $extra) {
3676 "<td colspan=\"3\">$extra</td>\n" .
3682 ## ======================================================================
3683 ## ======================================================================
3686 sub git_project_list
{
3687 my $order = $cgi->param('o');
3688 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3689 die_error
(undef, "Unknown order parameter");
3692 my @list = git_get_projects_list
();
3694 die_error
(undef, "No projects found");
3698 if (-f
$home_text) {
3699 print "<div class=\"index_include\">\n";
3700 open (my $fd, $home_text);
3705 git_project_list_body
(\
@list, $order);
3710 my $order = $cgi->param('o');
3711 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3712 die_error
(undef, "Unknown order parameter");
3715 my @list = git_get_projects_list
($project);
3717 die_error
(undef, "No forks found");
3721 git_print_page_nav
('','');
3722 git_print_header_div
('summary', "$project forks");
3723 git_project_list_body
(\
@list, $order);
3727 sub git_project_index
{
3728 my @projects = git_get_projects_list
($project);
3731 -type
=> 'text/plain',
3732 -charset
=> 'utf-8',
3733 -content_disposition
=> 'inline; filename="index.aux"');
3735 foreach my $pr (@projects) {
3736 if (!exists $pr->{'owner'}) {
3737 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3740 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3741 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3742 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3743 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3747 print "$path $owner\n";
3752 my $descr = git_get_project_description
($project) || "none";
3753 my %co = parse_commit
("HEAD");
3754 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3755 my $head = $co{'id'};
3757 my $owner = git_get_project_owner
($project);
3759 my $refs = git_get_references
();
3760 # These get_*_list functions return one more to allow us to see if
3761 # there are more ...
3762 my @taglist = git_get_tags_list
(16);
3763 my @headlist = git_get_heads_list
(16);
3765 my ($check_forks) = gitweb_check_feature
('forks');
3768 @forklist = git_get_projects_list
($project);
3772 git_print_page_nav
('summary','', $head);
3774 print "<div class=\"title\"> </div>\n";
3775 print "<table cellspacing=\"0\">\n" .
3776 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3777 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3778 if (defined $cd{'rfc2822'}) {
3779 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3782 # use per project git URL list in $projectroot/$project/cloneurl
3783 # or make project git URL from git base URL and project name
3784 my $url_tag = "URL";
3785 my @url_list = git_get_project_url_list
($project);
3786 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3787 foreach my $git_url (@url_list) {
3788 next unless $git_url;
3789 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3794 if (-s
"$projectroot/$project/README.html") {
3795 if (open my $fd, "$projectroot/$project/README.html") {
3796 print "<div class=\"title\">readme</div>\n";
3797 print $_ while (<$fd>);
3802 # we need to request one more than 16 (0..15) to check if
3804 my @commitlist = $head ? parse_commits
($head, 17) : ();
3806 git_print_header_div
('shortlog');
3807 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3808 $#commitlist <= 15 ?
undef :
3809 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3813 git_print_header_div
('tags');
3814 git_tags_body
(\
@taglist, 0, 15,
3815 $#taglist <= 15 ?
undef :
3816 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3820 git_print_header_div
('heads');
3821 git_heads_body
(\
@headlist, $head, 0, 15,
3822 $#headlist <= 15 ?
undef :
3823 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3827 git_print_header_div
('forks');
3828 git_project_list_body
(\
@forklist, undef, 0, 15,
3829 $#forklist <= 15 ?
undef :
3830 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3838 my $head = git_get_head_hash
($project);
3840 git_print_page_nav
('','', $head,undef,$head);
3841 my %tag = parse_tag
($hash);
3844 die_error
(undef, "Unknown tag object");
3847 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3848 print "<div class=\"title_text\">\n" .
3849 "<table cellspacing=\"0\">\n" .
3851 "<td>object</td>\n" .
3852 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3853 $tag{'object'}) . "</td>\n" .
3854 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3855 $tag{'type'}) . "</td>\n" .
3857 if (defined($tag{'author'})) {
3858 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3859 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3860 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3861 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3864 print "</table>\n\n" .
3866 print "<div class=\"page_body\">";
3867 my $comment = $tag{'comment'};
3868 foreach my $line (@
$comment) {
3870 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3880 my ($have_blame) = gitweb_check_feature
('blame');
3882 die_error
('403 Permission denied', "Permission denied");
3884 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3885 $hash_base ||= git_get_head_hash
($project);
3886 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3887 my %co = parse_commit
($hash_base)
3888 or die_error
(undef, "Reading commit failed");
3889 if (!defined $hash) {
3890 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3891 or die_error
(undef, "Error looking up file");
3893 $ftype = git_get_type
($hash);
3894 if ($ftype !~ "blob") {
3895 die_error
('400 Bad Request', "Object is not a blob");
3897 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3898 $file_name, $hash_base)
3899 or die_error
(undef, "Open git-blame failed");
3902 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3905 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3908 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3910 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3911 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3912 git_print_page_path
($file_name, $ftype, $hash_base);
3913 my @rev_color = (qw(light2 dark2));
3914 my $num_colors = scalar(@rev_color);
3915 my $current_color = 0;
3918 <div class="page_body">
3919 <table class="blame">
3920 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3925 last unless defined $_;
3926 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3927 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3928 if (!exists $metainfo{$full_rev}) {
3929 $metainfo{$full_rev} = {};
3931 my $meta = $metainfo{$full_rev};
3934 if (/^(\S+) (.*)$/) {
3940 my $rev = substr($full_rev, 0, 8);
3941 my $author = $meta->{'author'};
3942 my %date = parse_date
($meta->{'author-time'},
3943 $meta->{'author-tz'});
3944 my $date = $date{'iso-tz'};
3946 $current_color = ++$current_color % $num_colors;
3948 print "<tr class=\"$rev_color[$current_color]\">\n";
3950 print "<td class=\"sha1\"";
3951 print " title=\"". esc_html
($author) . ", $date\"";
3952 print " rowspan=\"$group_size\"" if ($group_size > 1);
3954 print $cgi->a({-href
=> href
(action
=>"commit",
3956 file_name
=>$file_name)},
3960 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3961 or die_error
(undef, "Open git-rev-parse failed");
3962 my $parent_commit = <$dd>;
3964 chomp($parent_commit);
3965 my $blamed = href
(action
=> 'blame',
3966 file_name
=> $meta->{'filename'},
3967 hash_base
=> $parent_commit);
3968 print "<td class=\"linenr\">";
3969 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3971 -class => "linenr" },
3974 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3980 or print "Reading blob failed\n";
3987 my ($have_blame) = gitweb_check_feature
('blame');
3989 die_error
('403 Permission denied', "Permission denied");
3991 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3992 $hash_base ||= git_get_head_hash
($project);
3993 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3994 my %co = parse_commit
($hash_base)
3995 or die_error
(undef, "Reading commit failed");
3996 if (!defined $hash) {
3997 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3998 or die_error
(undef, "Error lookup file");
4000 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4001 or die_error
(undef, "Open git-annotate failed");
4004 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4007 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4010 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4012 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4013 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4014 git_print_page_path
($file_name, 'blob', $hash_base);
4015 print "<div class=\"page_body\">\n";
4017 <table class="blame">
4026 my @line_class = (qw(light dark));
4027 my $line_class_len = scalar (@line_class);
4028 my $line_class_num = $#line_class;
4029 while (my $line = <$fd>) {
4041 $line_class_num = ($line_class_num + 1) % $line_class_len;
4043 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4050 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4053 $short_rev = substr ($long_rev, 0, 8);
4054 $age = time () - $time;
4055 $age_str = age_string
($age);
4056 $age_str =~ s/ / /g;
4057 $age_class = age_class
($age);
4058 $author = esc_html
($author);
4059 $author =~ s/ / /g;
4061 $data = untabify
($data);
4062 $data = esc_html
($data);
4065 <tr class="$line_class[$line_class_num]">
4066 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4067 <td class="$age_class">$age_str</td>
4069 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4070 <td class="pre">$data</td>
4073 } # while (my $line = <$fd>)
4074 print "</table>\n\n";
4076 or print "Reading blob failed.\n";
4082 my $head = git_get_head_hash
($project);
4084 git_print_page_nav
('','', $head,undef,$head);
4085 git_print_header_div
('summary', $project);
4087 my @tagslist = git_get_tags_list
();
4089 git_tags_body
(\
@tagslist);
4095 my $head = git_get_head_hash
($project);
4097 git_print_page_nav
('','', $head,undef,$head);
4098 git_print_header_div
('summary', $project);
4100 my @headslist = git_get_heads_list
();
4102 git_heads_body
(\
@headslist, $head);
4107 sub git_blob_plain
{
4110 if (!defined $hash) {
4111 if (defined $file_name) {
4112 my $base = $hash_base || git_get_head_hash
($project);
4113 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4114 or die_error
(undef, "Error lookup file");
4116 die_error
(undef, "No file name defined");
4118 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4119 # blobs defined by non-textual hash id's can be cached
4124 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4125 or die_error
(undef, "Couldn't cat $file_name, $hash");
4127 $type ||= blob_mimetype
($fd, $file_name);
4129 # save as filename, even when no $file_name is given
4130 my $save_as = "$hash";
4131 if (defined $file_name) {
4132 $save_as = $file_name;
4133 } elsif ($type =~ m/^text\//) {
4140 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4142 binmode STDOUT
, ':raw';
4144 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4152 if (!defined $hash) {
4153 if (defined $file_name) {
4154 my $base = $hash_base || git_get_head_hash
($project);
4155 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4156 or die_error
(undef, "Error lookup file");
4158 die_error
(undef, "No file name defined");
4160 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4161 # blobs defined by non-textual hash id's can be cached
4165 my ($have_blame) = gitweb_check_feature
('blame');
4166 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4167 or die_error
(undef, "Couldn't cat $file_name, $hash");
4168 my $mimetype = blob_mimetype
($fd, $file_name);
4169 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4171 return git_blob_plain
($mimetype);
4173 # we can have blame only for text/* mimetype
4174 $have_blame &&= ($mimetype =~ m!^text/!);
4176 git_header_html
(undef, $expires);
4177 my $formats_nav = '';
4178 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4179 if (defined $file_name) {
4182 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4183 hash
=>$hash, file_name
=>$file_name)},
4188 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4189 hash
=>$hash, file_name
=>$file_name)},
4192 $cgi->a({-href
=> href
(action
=>"blob_plain",
4193 hash
=>$hash, file_name
=>$file_name)},
4196 $cgi->a({-href
=> href
(action
=>"blob",
4197 hash_base
=>"HEAD", file_name
=>$file_name)},
4201 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4203 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4204 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4206 print "<div class=\"page_nav\">\n" .
4207 "<br/><br/></div>\n" .
4208 "<div class=\"title\">$hash</div>\n";
4210 git_print_page_path
($file_name, "blob", $hash_base);
4211 print "<div class=\"page_body\">\n";
4212 if ($mimetype =~ m!^text/!) {
4214 while (my $line = <$fd>) {
4217 $line = untabify
($line);
4218 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4219 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4221 } elsif ($mimetype =~ m!^image/!) {
4222 print qq!<img type
="$mimetype"!;
4224 print qq! alt
="$file_name" title
="$file_name"!;
4227 href(action=>"blob_plain
", hash=>$hash,
4228 hash_base=>$hash_base, file_name=>$file_name) .
4232 or print "Reading blob failed.\n";
4238 if (!defined $hash_base) {
4239 $hash_base = "HEAD";
4241 if (!defined $hash) {
4242 if (defined $file_name) {
4243 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4249 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4250 or die_error
(undef, "Open git-ls-tree failed");
4251 my @entries = map { chomp; $_ } <$fd>;
4252 close $fd or die_error
(undef, "Reading tree failed");
4255 my $refs = git_get_references
();
4256 my $ref = format_ref_marker
($refs, $hash_base);
4259 my ($have_blame) = gitweb_check_feature
('blame');
4260 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4262 if (defined $file_name) {
4264 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4265 hash
=>$hash, file_name
=>$file_name)},
4267 $cgi->a({-href
=> href
(action
=>"tree",
4268 hash_base
=>"HEAD", file_name
=>$file_name)},
4271 my $snapshot_links = format_snapshot_links
($hash);
4272 if (defined $snapshot_links) {
4273 # FIXME: Should be available when we have no hash base as well.
4274 push @views_nav, $snapshot_links;
4276 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4277 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4280 print "<div class=\"page_nav\">\n";
4281 print "<br/><br/></div>\n";
4282 print "<div class=\"title\">$hash</div>\n";
4284 if (defined $file_name) {
4285 $basedir = $file_name;
4286 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4290 git_print_page_path
($file_name, 'tree', $hash_base);
4291 print "<div class=\"page_body\">\n";
4292 print "<table cellspacing=\"0\">\n";
4294 # '..' (top directory) link if possible
4295 if (defined $hash_base &&
4296 defined $file_name && $file_name =~ m![^/]+$!) {
4298 print "<tr class=\"dark\">\n";
4300 print "<tr class=\"light\">\n";
4304 my $up = $file_name;
4305 $up =~ s!/?[^/]+$!!;
4306 undef $up unless $up;
4307 # based on git_print_tree_entry
4308 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4309 print '<td class="list">';
4310 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4314 print "<td class=\"link\"></td>\n";
4318 foreach my $line (@entries) {
4319 my %t = parse_ls_tree_line
($line, -z
=> 1);
4322 print "<tr class=\"dark\">\n";
4324 print "<tr class=\"light\">\n";
4328 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4332 print "</table>\n" .
4338 my @supported_fmts = gitweb_check_feature
('snapshot');
4339 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4341 my $format = $cgi->param('sf');
4342 if (!@supported_fmts) {
4343 die_error
('403 Permission denied', "Permission denied");
4345 # default to first supported snapshot format
4346 $format ||= $supported_fmts[0];
4347 if ($format !~ m/^[a-z0-9]+$/) {
4348 die_error
(undef, "Invalid snapshot format parameter");
4349 } elsif (!exists($known_snapshot_formats{$format})) {
4350 die_error
(undef, "Unknown snapshot format");
4351 } elsif (!grep($_ eq $format, @supported_fmts)) {
4352 die_error
(undef, "Unsupported snapshot format");
4355 if (!defined $hash) {
4356 $hash = git_get_head_hash
($project);
4359 my $git_command = git_cmd_str
();
4360 my $name = $project;
4361 $name =~ s
,([^/])/*\
.git
$,$1,;
4362 $name = basename
($name);
4363 my $filename = to_utf8
($name);
4364 $name =~ s/\047/\047\\\047\047/g;
4366 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4367 $cmd = "$git_command archive " .
4368 "--format=$known_snapshot_formats{$format}{'format'} " .
4369 "--prefix=\'$name\'/ $hash";
4370 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4371 $cmd .= ' | ' . join ' ', @
{$known_snapshot_formats{$format}{'compressor'}};
4375 -type
=> $known_snapshot_formats{$format}{'type'},
4376 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4377 -status
=> '200 OK');
4379 open my $fd, "-|", $cmd
4380 or die_error
(undef, "Execute git-archive failed");
4381 binmode STDOUT
, ':raw';
4383 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4388 my $head = git_get_head_hash
($project);
4389 if (!defined $hash) {
4392 if (!defined $page) {
4395 my $refs = git_get_references
();
4397 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4399 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4402 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4405 my %co = parse_commit
($hash);
4407 git_print_header_div
('summary', $project);
4408 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4410 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4411 for (my $i = 0; $i <= $to; $i++) {
4412 my %co = %{$commitlist[$i]};
4414 my $commit = $co{'id'};
4415 my $ref = format_ref_marker
($refs, $commit);
4416 my %ad = parse_date
($co{'author_epoch'});
4417 git_print_header_div
('commit',
4418 "<span class=\"age\">$co{'age_string'}</span>" .
4419 esc_html
($co{'title'}) . $ref,
4421 print "<div class=\"title_text\">\n" .
4422 "<div class=\"log_link\">\n" .
4423 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4425 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4427 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4430 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4433 print "<div class=\"log_body\">\n";
4434 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4437 if ($#commitlist >= 100) {
4438 print "<div class=\"page_nav\">\n";
4439 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4440 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4447 $hash ||= $hash_base || "HEAD";
4448 my %co = parse_commit
($hash);
4450 die_error
(undef, "Unknown commit object");
4452 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4453 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4455 my $parent = $co{'parent'};
4456 my $parents = $co{'parents'}; # listref
4458 # we need to prepare $formats_nav before any parameter munging
4460 if (!defined $parent) {
4462 $formats_nav .= '(initial)';
4463 } elsif (@
$parents == 1) {
4464 # single parent commit
4467 $cgi->a({-href
=> href
(action
=>"commit",
4469 esc_html
(substr($parent, 0, 7))) .
4476 $cgi->a({-href
=> href
(action
=>"commit",
4478 esc_html
(substr($_, 0, 7)));
4483 if (!defined $parent) {
4487 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4489 (@
$parents <= 1 ?
$parent : '-c'),
4491 or die_error
(undef, "Open git-diff-tree failed");
4492 @difftree = map { chomp; $_ } <$fd>;
4493 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4495 # non-textual hash id's can be cached
4497 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4500 my $refs = git_get_references
();
4501 my $ref = format_ref_marker
($refs, $co{'id'});
4503 git_header_html
(undef, $expires);
4504 git_print_page_nav
('commit', '',
4505 $hash, $co{'tree'}, $hash,
4508 if (defined $co{'parent'}) {
4509 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4511 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4513 print "<div class=\"title_text\">\n" .
4514 "<table cellspacing=\"0\">\n";
4515 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4517 "<td></td><td> $ad{'rfc2822'}";
4518 if ($ad{'hour_local'} < 6) {
4519 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4520 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4522 printf(" (%02d:%02d %s)",
4523 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4527 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4528 print "<tr><td></td><td> $cd{'rfc2822'}" .
4529 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4531 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4534 "<td class=\"sha1\">" .
4535 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4536 class => "list"}, $co{'tree'}) .
4538 "<td class=\"link\">" .
4539 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4541 my $snapshot_links = format_snapshot_links
($hash);
4542 if (defined $snapshot_links) {
4543 print " | " . $snapshot_links;
4548 foreach my $par (@
$parents) {
4551 "<td class=\"sha1\">" .
4552 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4553 class => "list"}, $par) .
4555 "<td class=\"link\">" .
4556 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4558 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4565 print "<div class=\"page_body\">\n";
4566 git_print_log
($co{'comment'});
4569 git_difftree_body
(\
@difftree, $hash, @
$parents);
4575 # object is defined by:
4576 # - hash or hash_base alone
4577 # - hash_base and file_name
4580 # - hash or hash_base alone
4581 if ($hash || ($hash_base && !defined $file_name)) {
4582 my $object_id = $hash || $hash_base;
4584 my $git_command = git_cmd_str
();
4585 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4586 or die_error
('404 Not Found', "Object does not exist");
4590 or die_error
('404 Not Found', "Object does not exist");
4592 # - hash_base and file_name
4593 } elsif ($hash_base && defined $file_name) {
4594 $file_name =~ s
,/+$,,;
4596 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4597 or die_error
('404 Not Found', "Base object does not exist");
4599 # here errors should not hapen
4600 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4601 or die_error
(undef, "Open git-ls-tree failed");
4605 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4606 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4607 die_error
('404 Not Found', "File or directory for given base does not exist");
4612 die_error
('404 Not Found', "Not enough information to find object");
4615 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4616 hash
=>$hash, hash_base
=>$hash_base,
4617 file_name
=>$file_name),
4618 -status
=> '302 Found');
4622 my $format = shift || 'html';
4629 # preparing $fd and %diffinfo for git_patchset_body
4631 if (defined $hash_base && defined $hash_parent_base) {
4632 if (defined $file_name) {
4634 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4635 $hash_parent_base, $hash_base,
4636 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4637 or die_error
(undef, "Open git-diff-tree failed");
4638 @difftree = map { chomp; $_ } <$fd>;
4640 or die_error
(undef, "Reading git-diff-tree failed");
4642 or die_error
('404 Not Found', "Blob diff not found");
4644 } elsif (defined $hash &&
4645 $hash =~ /[0-9a-fA-F]{40}/) {
4646 # try to find filename from $hash
4648 # read filtered raw output
4649 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4650 $hash_parent_base, $hash_base, "--"
4651 or die_error
(undef, "Open git-diff-tree failed");
4653 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4655 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4656 map { chomp; $_ } <$fd>;
4658 or die_error
(undef, "Reading git-diff-tree failed");
4660 or die_error
('404 Not Found', "Blob diff not found");
4663 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4666 if (@difftree > 1) {
4667 die_error
('404 Not Found', "Ambiguous blob diff specification");
4670 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4671 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4672 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4674 $hash_parent ||= $diffinfo{'from_id'};
4675 $hash ||= $diffinfo{'to_id'};
4677 # non-textual hash id's can be cached
4678 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4679 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4684 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4685 '-p', ($format eq 'html' ?
"--full-index" : ()),
4686 $hash_parent_base, $hash_base,
4687 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4688 or die_error
(undef, "Open git-diff-tree failed");
4691 # old/legacy style URI
4692 if (!%diffinfo && # if new style URI failed
4693 defined $hash && defined $hash_parent) {
4694 # fake git-diff-tree raw output
4695 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4696 $diffinfo{'from_id'} = $hash_parent;
4697 $diffinfo{'to_id'} = $hash;
4698 if (defined $file_name) {
4699 if (defined $file_parent) {
4700 $diffinfo{'status'} = '2';
4701 $diffinfo{'from_file'} = $file_parent;
4702 $diffinfo{'to_file'} = $file_name;
4703 } else { # assume not renamed
4704 $diffinfo{'status'} = '1';
4705 $diffinfo{'from_file'} = $file_name;
4706 $diffinfo{'to_file'} = $file_name;
4708 } else { # no filename given
4709 $diffinfo{'status'} = '2';
4710 $diffinfo{'from_file'} = $hash_parent;
4711 $diffinfo{'to_file'} = $hash;
4714 # non-textual hash id's can be cached
4715 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4716 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4721 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4722 '-p', ($format eq 'html' ?
"--full-index" : ()),
4723 $hash_parent, $hash, "--"
4724 or die_error
(undef, "Open git-diff failed");
4726 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4731 if ($format eq 'html') {
4733 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4734 hash
=>$hash, hash_parent
=>$hash_parent,
4735 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4736 file_name
=>$file_name, file_parent
=>$file_parent)},
4738 git_header_html
(undef, $expires);
4739 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4740 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4741 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4743 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4744 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4746 if (defined $file_name) {
4747 git_print_page_path
($file_name, "blob", $hash_base);
4749 print "<div class=\"page_path\"></div>\n";
4752 } elsif ($format eq 'plain') {
4754 -type
=> 'text/plain',
4755 -charset
=> 'utf-8',
4756 -expires
=> $expires,
4757 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4759 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4762 die_error
(undef, "Unknown blobdiff format");
4766 if ($format eq 'html') {
4767 print "<div class=\"page_body\">\n";
4769 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4772 print "</div>\n"; # class="page_body"
4776 while (my $line = <$fd>) {
4777 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4778 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4782 last if $line =~ m!^\+\+\+!;
4790 sub git_blobdiff_plain
{
4791 git_blobdiff
('plain');
4794 sub git_commitdiff
{
4795 my $format = shift || 'html';
4796 $hash ||= $hash_base || "HEAD";
4797 my %co = parse_commit
($hash);
4799 die_error
(undef, "Unknown commit object");
4802 # choose format for commitdiff for merge
4803 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4804 $hash_parent = '--cc';
4806 # we need to prepare $formats_nav before almost any parameter munging
4808 if ($format eq 'html') {
4810 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4811 hash
=>$hash, hash_parent
=>$hash_parent)},
4814 if (defined $hash_parent &&
4815 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4816 # commitdiff with two commits given
4817 my $hash_parent_short = $hash_parent;
4818 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4819 $hash_parent_short = substr($hash_parent, 0, 7);
4823 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4824 if ($co{'parents'}[$i] eq $hash_parent) {
4825 $formats_nav .= ' parent ' . ($i+1);
4829 $formats_nav .= ': ' .
4830 $cgi->a({-href
=> href
(action
=>"commitdiff",
4831 hash
=>$hash_parent)},
4832 esc_html
($hash_parent_short)) .
4834 } elsif (!$co{'parent'}) {
4836 $formats_nav .= ' (initial)';
4837 } elsif (scalar @
{$co{'parents'}} == 1) {
4838 # single parent commit
4841 $cgi->a({-href
=> href
(action
=>"commitdiff",
4842 hash
=>$co{'parent'})},
4843 esc_html
(substr($co{'parent'}, 0, 7))) .
4847 if ($hash_parent eq '--cc') {
4848 $formats_nav .= ' | ' .
4849 $cgi->a({-href
=> href
(action
=>"commitdiff",
4850 hash
=>$hash, hash_parent
=>'-c')},
4852 } else { # $hash_parent eq '-c'
4853 $formats_nav .= ' | ' .
4854 $cgi->a({-href
=> href
(action
=>"commitdiff",
4855 hash
=>$hash, hash_parent
=>'--cc')},
4861 $cgi->a({-href
=> href
(action
=>"commitdiff",
4863 esc_html
(substr($_, 0, 7)));
4864 } @
{$co{'parents'}} ) .
4869 my $hash_parent_param = $hash_parent;
4870 if (!defined $hash_parent_param) {
4871 # --cc for multiple parents, --root for parentless
4872 $hash_parent_param =
4873 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
4879 if ($format eq 'html') {
4880 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4881 "--no-commit-id", "--patch-with-raw", "--full-index",
4882 $hash_parent_param, $hash, "--"
4883 or die_error
(undef, "Open git-diff-tree failed");
4885 while (my $line = <$fd>) {
4887 # empty line ends raw part of diff-tree output
4889 push @difftree, scalar parse_difftree_raw_line
($line);
4892 } elsif ($format eq 'plain') {
4893 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4894 '-p', $hash_parent_param, $hash, "--"
4895 or die_error
(undef, "Open git-diff-tree failed");
4898 die_error
(undef, "Unknown commitdiff format");
4901 # non-textual hash id's can be cached
4903 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4907 # write commit message
4908 if ($format eq 'html') {
4909 my $refs = git_get_references
();
4910 my $ref = format_ref_marker
($refs, $co{'id'});
4912 git_header_html
(undef, $expires);
4913 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4914 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4915 git_print_authorship
(\
%co);
4916 print "<div class=\"page_body\">\n";
4917 if (@
{$co{'comment'}} > 1) {
4918 print "<div class=\"log\">\n";
4919 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4920 print "</div>\n"; # class="log"
4923 } elsif ($format eq 'plain') {
4924 my $refs = git_get_references
("tags");
4925 my $tagname = git_get_rev_name_tags
($hash);
4926 my $filename = basename
($project) . "-$hash.patch";
4929 -type
=> 'text/plain',
4930 -charset
=> 'utf-8',
4931 -expires
=> $expires,
4932 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4933 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4936 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4937 Subject: $co{'title'}
4939 print "X-Git-Tag: $tagname\n" if $tagname;
4940 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4942 foreach my $line (@
{$co{'comment'}}) {
4949 if ($format eq 'html') {
4950 my $use_parents = !defined $hash_parent ||
4951 $hash_parent eq '-c' || $hash_parent eq '--cc';
4952 git_difftree_body
(\
@difftree, $hash,
4953 $use_parents ? @
{$co{'parents'}} : $hash_parent);
4956 git_patchset_body
($fd, \
@difftree, $hash,
4957 $use_parents ? @
{$co{'parents'}} : $hash_parent);
4959 print "</div>\n"; # class="page_body"
4962 } elsif ($format eq 'plain') {
4966 or print "Reading git-diff-tree failed\n";
4970 sub git_commitdiff_plain
{
4971 git_commitdiff
('plain');
4975 if (!defined $hash_base) {
4976 $hash_base = git_get_head_hash
($project);
4978 if (!defined $page) {
4982 my %co = parse_commit
($hash_base);
4984 die_error
(undef, "Unknown commit object");
4987 my $refs = git_get_references
();
4988 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4990 if (!defined $hash && defined $file_name) {
4991 $hash = git_get_hash_by_path
($hash_base, $file_name);
4993 if (defined $hash) {
4994 $ftype = git_get_type
($hash);
4997 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4999 my $paging_nav = '';
5002 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5003 file_name
=>$file_name)},
5005 $paging_nav .= " ⋅ " .
5006 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5007 file_name
=>$file_name, page
=>$page-1),
5008 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5010 $paging_nav .= "first";
5011 $paging_nav .= " ⋅ prev";
5013 if ($#commitlist >= 100) {
5014 $paging_nav .= " ⋅ " .
5015 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5016 file_name
=>$file_name, page
=>$page+1),
5017 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5019 $paging_nav .= " ⋅ next";
5022 if ($#commitlist >= 100) {
5024 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5025 file_name
=>$file_name, page
=>$page+1),
5026 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5030 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5031 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5032 git_print_page_path
($file_name, $ftype, $hash_base);
5034 git_history_body
(\
@commitlist, 0, 99,
5035 $refs, $hash_base, $ftype, $next_link);
5041 my ($have_search) = gitweb_check_feature
('search');
5042 if (!$have_search) {
5043 die_error
('403 Permission denied', "Permission denied");
5045 if (!defined $searchtext) {
5046 die_error
(undef, "Text field empty");
5048 if (!defined $hash) {
5049 $hash = git_get_head_hash
($project);
5051 my %co = parse_commit
($hash);
5053 die_error
(undef, "Unknown commit object");
5055 if (!defined $page) {
5059 $searchtype ||= 'commit';
5060 if ($searchtype eq 'pickaxe') {
5061 # pickaxe may take all resources of your box and run for several minutes
5062 # with every query - so decide by yourself how public you make this feature
5063 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5064 if (!$have_pickaxe) {
5065 die_error
('403 Permission denied', "Permission denied");
5068 if ($searchtype eq 'grep') {
5069 my ($have_grep) = gitweb_check_feature
('grep');
5071 die_error
('403 Permission denied', "Permission denied");
5077 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5079 if ($searchtype eq 'commit') {
5080 $greptype = "--grep=";
5081 } elsif ($searchtype eq 'author') {
5082 $greptype = "--author=";
5083 } elsif ($searchtype eq 'committer') {
5084 $greptype = "--committer=";
5086 $greptype .= $search_regexp;
5087 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5089 my $paging_nav = '';
5092 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5093 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5095 $paging_nav .= " ⋅ " .
5096 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5097 searchtext
=>$searchtext, searchtype
=>$searchtype,
5099 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5101 $paging_nav .= "first";
5102 $paging_nav .= " ⋅ prev";
5104 if ($#commitlist >= 100) {
5105 $paging_nav .= " ⋅ " .
5106 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5107 searchtext
=>$searchtext, searchtype
=>$searchtype,
5109 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5111 $paging_nav .= " ⋅ next";
5114 if ($#commitlist >= 100) {
5116 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5117 searchtext
=>$searchtext, searchtype
=>$searchtype,
5119 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5122 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5123 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5124 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5127 if ($searchtype eq 'pickaxe') {
5128 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5129 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5131 print "<table cellspacing=\"0\">\n";
5134 my $git_command = git_cmd_str
();
5135 my $searchqtext = $searchtext;
5136 $searchqtext =~ s/'/'\\''/;
5137 open my $fd, "-|", "$git_command rev-list $hash | " .
5138 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5141 while (my $line = <$fd>) {
5142 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5145 $set{'from_id'} = $3;
5147 $set{'id'} = $set{'to_id'};
5148 if ($set{'id'} =~ m/0{40}/) {
5149 $set{'id'} = $set{'from_id'};
5151 if ($set{'id'} =~ m/0{40}/) {
5155 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5158 print "<tr class=\"dark\">\n";
5160 print "<tr class=\"light\">\n";
5163 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5164 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5166 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5167 -class => "list subject"},
5168 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5169 while (my $setref = shift @files) {
5171 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5172 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5174 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5178 "<td class=\"link\">" .
5179 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5181 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5185 %co = parse_commit
($1);
5193 if ($searchtype eq 'grep') {
5194 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5195 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5197 print "<table cellspacing=\"0\">\n";
5201 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5203 while (my $line = <$fd>) {
5205 my ($file, $lno, $ltext, $binary);
5206 last if ($matches++ > 1000);
5207 if ($line =~ /^Binary file (.+) matches$/) {
5211 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5213 if ($file ne $lastfile) {
5214 $lastfile and print "</td></tr>\n";
5216 print "<tr class=\"dark\">\n";
5218 print "<tr class=\"light\">\n";
5220 print "<td class=\"list\">".
5221 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5222 file_name
=>"$file"),
5223 -class => "list"}, esc_path
($file));
5224 print "</td><td>\n";
5228 print "<div class=\"binary\">Binary file</div>\n";
5230 $ltext = untabify
($ltext);
5231 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5232 $ltext = esc_html
($1, -nbsp
=>1);
5233 $ltext .= '<span class="match">';
5234 $ltext .= esc_html
($2, -nbsp
=>1);
5235 $ltext .= '</span>';
5236 $ltext .= esc_html
($3, -nbsp
=>1);
5238 $ltext = esc_html
($ltext, -nbsp
=>1);
5240 print "<div class=\"pre\">" .
5241 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5242 file_name
=>"$file").'#l'.$lno,
5243 -class => "linenr"}, sprintf('%4i', $lno))
5244 . ' ' . $ltext . "</div>\n";
5248 print "</td></tr>\n";
5249 if ($matches > 1000) {
5250 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5253 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5262 sub git_search_help
{
5264 git_print_page_nav
('','', $hash,$hash,$hash);
5267 <dt><b>commit</b></dt>
5268 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5270 my ($have_grep) = gitweb_check_feature
('grep');
5273 <dt><b>grep</b></dt>
5274 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5275 a different one) are searched for the given
5276 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5277 (POSIX extended) and the matches are listed. On large
5278 trees, this search can take a while and put some strain on the server, so please use it with
5279 some consideration.</dd>
5283 <dt><b>author</b></dt>
5284 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5285 <dt><b>committer</b></dt>
5286 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5288 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5289 if ($have_pickaxe) {
5291 <dt><b>pickaxe</b></dt>
5292 <dd>All commits that caused the string to appear or disappear from any file (changes that
5293 added, removed or "modified" the string) will be listed. This search can take a while and
5294 takes a lot of strain on the server, so please use it wisely.</dd>
5302 my $head = git_get_head_hash
($project);
5303 if (!defined $hash) {
5306 if (!defined $page) {
5309 my $refs = git_get_references
();
5311 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5313 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5315 if ($#commitlist >= 100) {
5317 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5318 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5322 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5323 git_print_header_div
('summary', $project);
5325 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5330 ## ......................................................................
5331 ## feeds (RSS, Atom; OPML)
5334 my $format = shift || 'atom';
5335 my ($have_blame) = gitweb_check_feature
('blame');
5337 # Atom: http://www.atomenabled.org/developers/syndication/
5338 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5339 if ($format ne 'rss' && $format ne 'atom') {
5340 die_error
(undef, "Unknown web feed format");
5343 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5344 my $head = $hash || 'HEAD';
5345 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5349 my $content_type = "application/$format+xml";
5350 if (defined $cgi->http('HTTP_ACCEPT') &&
5351 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5352 # browser (feed reader) prefers text/xml
5353 $content_type = 'text/xml';
5355 if (defined($commitlist[0])) {
5356 %latest_commit = %{$commitlist[0]};
5357 %latest_date = parse_date
($latest_commit{'author_epoch'});
5359 -type
=> $content_type,
5360 -charset
=> 'utf-8',
5361 -last_modified
=> $latest_date{'rfc2822'});
5364 -type
=> $content_type,
5365 -charset
=> 'utf-8');
5368 # Optimization: skip generating the body if client asks only
5369 # for Last-Modified date.
5370 return if ($cgi->request_method() eq 'HEAD');
5373 my $title = "$site_name - $project/$action";
5374 my $feed_type = 'log';
5375 if (defined $hash) {
5376 $title .= " - '$hash'";
5377 $feed_type = 'branch log';
5378 if (defined $file_name) {
5379 $title .= " :: $file_name";
5380 $feed_type = 'history';
5382 } elsif (defined $file_name) {
5383 $title .= " - $file_name";
5384 $feed_type = 'history';
5386 $title .= " $feed_type";
5387 my $descr = git_get_project_description
($project);
5388 if (defined $descr) {
5389 $descr = esc_html
($descr);
5391 $descr = "$project " .
5392 ($format eq 'rss' ?
'RSS' : 'Atom') .
5395 my $owner = git_get_project_owner
($project);
5396 $owner = esc_html
($owner);
5400 if (defined $file_name) {
5401 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5402 } elsif (defined $hash) {
5403 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5405 $alt_url = href
(-full
=>1, action
=>"summary");
5407 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5408 if ($format eq 'rss') {
5410 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5413 print "<title>$title</title>\n" .
5414 "<link>$alt_url</link>\n" .
5415 "<description>$descr</description>\n" .
5416 "<language>en</language>\n";
5417 } elsif ($format eq 'atom') {
5419 <feed xmlns="http://www.w3.org/2005/Atom">
5421 print "<title>$title</title>\n" .
5422 "<subtitle>$descr</subtitle>\n" .
5423 '<link rel="alternate" type="text/html" href="' .
5424 $alt_url . '" />' . "\n" .
5425 '<link rel="self" type="' . $content_type . '" href="' .
5426 $cgi->self_url() . '" />' . "\n" .
5427 "<id>" . href
(-full
=>1) . "</id>\n" .
5428 # use project owner for feed author
5429 "<author><name>$owner</name></author>\n";
5430 if (defined $favicon) {
5431 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5433 if (defined $logo_url) {
5434 # not twice as wide as tall: 72 x 27 pixels
5435 print "<logo>" . esc_url
($logo) . "</logo>\n";
5437 if (! %latest_date) {
5438 # dummy date to keep the feed valid until commits trickle in:
5439 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5441 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5446 for (my $i = 0; $i <= $#commitlist; $i++) {
5447 my %co = %{$commitlist[$i]};
5448 my $commit = $co{'id'};
5449 # we read 150, we always show 30 and the ones more recent than 48 hours
5450 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5453 my %cd = parse_date
($co{'author_epoch'});
5455 # get list of changed files
5456 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5457 $co{'parent'} || "--root",
5458 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5460 my @difftree = map { chomp; $_ } <$fd>;
5464 # print element (entry, item)
5465 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5466 if ($format eq 'rss') {
5468 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5469 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5470 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5471 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5472 "<link>$co_url</link>\n" .
5473 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5474 "<content:encoded>" .
5476 } elsif ($format eq 'atom') {
5478 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5479 "<updated>$cd{'iso-8601'}</updated>\n" .
5481 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5482 if ($co{'author_email'}) {
5483 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5485 print "</author>\n" .
5486 # use committer for contributor
5488 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5489 if ($co{'committer_email'}) {
5490 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5492 print "</contributor>\n" .
5493 "<published>$cd{'iso-8601'}</published>\n" .
5494 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5495 "<id>$co_url</id>\n" .
5496 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5497 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5499 my $comment = $co{'comment'};
5501 foreach my $line (@
$comment) {
5502 $line = esc_html
($line);
5505 print "</pre><ul>\n";
5506 foreach my $difftree_line (@difftree) {
5507 my %difftree = parse_difftree_raw_line
($difftree_line);
5508 next if !$difftree{'from_id'};
5510 my $file = $difftree{'file'} || $difftree{'to_file'};
5514 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5515 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5516 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5517 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5518 -title
=> "diff"}, 'D');
5520 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5521 file_name
=>$file, hash_base
=>$commit),
5522 -title
=> "blame"}, 'B');
5524 # if this is not a feed of a file history
5525 if (!defined $file_name || $file_name ne $file) {
5526 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5527 file_name
=>$file, hash
=>$commit),
5528 -title
=> "history"}, 'H');
5530 $file = esc_path
($file);
5534 if ($format eq 'rss') {
5535 print "</ul>]]>\n" .
5536 "</content:encoded>\n" .
5538 } elsif ($format eq 'atom') {
5539 print "</ul>\n</div>\n" .
5546 if ($format eq 'rss') {
5547 print "</channel>\n</rss>\n";
5548 } elsif ($format eq 'atom') {
5562 my @list = git_get_projects_list
();
5564 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5566 <?xml version="1.0" encoding="utf-8"?>
5567 <opml version="1.0">
5569 <title>$site_name OPML Export</title>
5572 <outline text="git RSS feeds">
5575 foreach my $pr (@list) {
5577 my $head = git_get_head_hash
($proj{'path'});
5578 if (!defined $head) {
5581 $git_dir = "$projectroot/$proj{'path'}";
5582 my %co = parse_commit
($head);
5587 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5588 my $rss = "$my_url?p=$proj{'path'};a=rss";
5589 my $html = "$my_url?p=$proj{'path'};a=summary";
5590 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";