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 if ($params{-replay
}) {
617 while (my ($name, $symbol) = each %mapping) {
618 if (!exists $params{$name}) {
619 # to allow for multivalued params we use arrayref form
620 $params{$name} = [ $cgi->param($symbol) ];
625 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
627 # use PATH_INFO for project name
628 $href .= "/$params{'project'}" if defined $params{'project'};
629 delete $params{'project'};
631 # Summary just uses the project path URL
632 if (defined $params{'action'} && $params{'action'} eq 'summary') {
633 delete $params{'action'};
637 # now encode the parameters explicitly
639 for (my $i = 0; $i < @mapping; $i += 2) {
640 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
641 if (defined $params{$name}) {
642 if (ref($params{$name}) eq "ARRAY") {
643 foreach my $par (@
{$params{$name}}) {
644 push @result, $symbol . "=" . esc_param
($par);
647 push @result, $symbol . "=" . esc_param
($params{$name});
651 $href .= "?" . join(';', @result) if scalar @result;
657 ## ======================================================================
658 ## validation, quoting/unquoting and escaping
660 sub validate_pathname
{
661 my $input = shift || return undef;
663 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
664 # at the beginning, at the end, and between slashes.
665 # also this catches doubled slashes
666 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
670 if ($input =~ m!\0!) {
676 sub validate_refname
{
677 my $input = shift || return undef;
679 # textual hashes are O.K.
680 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
683 # it must be correct pathname
684 $input = validate_pathname
($input)
686 # restrictions on ref name according to git-check-ref-format
687 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
693 # decode sequences of octets in utf8 into Perl's internal form,
694 # which is utf-8 with utf8 flag set if needed. gitweb writes out
695 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
698 if (utf8
::valid
($str)) {
702 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
706 # quote unsafe chars, but keep the slash, even when it's not
707 # correct, but quoted slashes look too horrible in bookmarks
710 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
716 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
719 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
725 # replace invalid utf8 character with SUBSTITUTION sequence
730 $str = to_utf8
($str);
731 $str = $cgi->escapeHTML($str);
732 if ($opts{'-nbsp'}) {
733 $str =~ s/ / /g;
735 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
739 # quote control characters and escape filename to HTML
744 $str = to_utf8
($str);
745 $str = $cgi->escapeHTML($str);
746 if ($opts{'-nbsp'}) {
747 $str =~ s/ / /g;
749 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
753 # Make control characters "printable", using character escape codes (CEC)
757 my %es = ( # character escape codes, aka escape sequences
758 "\t" => '\t', # tab (HT)
759 "\n" => '\n', # line feed (LF)
760 "\r" => '\r', # carrige return (CR)
761 "\f" => '\f', # form feed (FF)
762 "\b" => '\b', # backspace (BS)
763 "\a" => '\a', # alarm (bell) (BEL)
764 "\e" => '\e', # escape (ESC)
765 "\013" => '\v', # vertical tab (VT)
766 "\000" => '\0', # nul character (NUL)
768 my $chr = ( (exists $es{$cntrl})
770 : sprintf('\%03o', ord($cntrl)) );
771 if ($opts{-nohtml
}) {
774 return "<span class=\"cntrl\">$chr</span>";
778 # Alternatively use unicode control pictures codepoints,
779 # Unicode "printable representation" (PR)
784 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
785 if ($opts{-nohtml
}) {
788 return "<span class=\"cntrl\">$chr</span>";
792 # git may return quoted and escaped filenames
798 my %es = ( # character escape codes, aka escape sequences
799 't' => "\t", # tab (HT, TAB)
800 'n' => "\n", # newline (NL)
801 'r' => "\r", # return (CR)
802 'f' => "\f", # form feed (FF)
803 'b' => "\b", # backspace (BS)
804 'a' => "\a", # alarm (bell) (BEL)
805 'e' => "\e", # escape (ESC)
806 'v' => "\013", # vertical tab (VT)
809 if ($seq =~ m/^[0-7]{1,3}$/) {
810 # octal char sequence
811 return chr(oct($seq));
812 } elsif (exists $es{$seq}) {
813 # C escape sequence, aka character escape code
816 # quoted ordinary character
820 if ($str =~ m/^"(.*)"$/) {
823 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
828 # escape tabs (convert tabs to spaces)
832 while ((my $pos = index($line, "\t")) != -1) {
833 if (my $count = (8 - ($pos % 8))) {
834 my $spaces = ' ' x
$count;
835 $line =~ s/\t/$spaces/;
842 sub project_in_list
{
844 my @list = git_get_projects_list
();
845 return @list && scalar(grep { $_->{'path'} eq $project } @list);
848 ## ----------------------------------------------------------------------
849 ## HTML aware string manipulation
851 # Try to chop given string on a word boundary between position
852 # $len and $len+$add_len. If there is no word boundary there,
853 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
854 # (marking chopped part) would be longer than given string.
858 my $add_len = shift || 10;
859 my $where = shift || 'right'; # 'left' | 'center' | 'right'
861 # allow only $len chars, but don't cut a word if it would fit in $add_len
862 # if it doesn't fit, cut it if it's still longer than the dots we would add
863 # remove chopped character entities entirely
865 # when chopping in the middle, distribute $len into left and right part
866 # return early if chopping wouldn't make string shorter
867 if ($where eq 'center') {
868 return $str if ($len + 5 >= length($str)); # filler is length 5
871 return $str if ($len + 4 >= length($str)); # filler is length 4
874 # regexps: ending and beginning with word part up to $add_len
875 my $endre = qr/.{$len}\w{0,$add_len}/;
876 my $begre = qr/\w{0,$add_len}.{$len}/;
878 if ($where eq 'left') {
879 $str =~ m/^(.*?)($begre)$/;
880 my ($lead, $body) = ($1, $2);
881 if (length($lead) > 4) {
882 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
887 } elsif ($where eq 'center') {
888 $str =~ m/^($endre)(.*)$/;
889 my ($left, $str) = ($1, $2);
890 $str =~ m/^(.*?)($begre)$/;
891 my ($mid, $right) = ($1, $2);
892 if (length($mid) > 5) {
893 $left =~ s/&[^;]*$//;
894 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
897 return "$left$mid$right";
900 $str =~ m/^($endre)(.*)$/;
903 if (length($tail) > 4) {
904 $body =~ s/&[^;]*$//;
911 # takes the same arguments as chop_str, but also wraps a <span> around the
912 # result with a title attribute if it does get chopped. Additionally, the
913 # string is HTML-escaped.
914 sub chop_and_escape_str
{
917 my $chopped = chop_str
(@_);
918 if ($chopped eq $str) {
919 return esc_html
($chopped);
921 $str =~ s/([[:cntrl:]])/?/g;
922 return $cgi->span({-title
=>$str}, esc_html
($chopped));
926 ## ----------------------------------------------------------------------
927 ## functions returning short strings
929 # CSS class for given age value (in seconds)
935 } elsif ($age < 60*60*2) {
937 } elsif ($age < 60*60*24*2) {
944 # convert age in seconds to "nn units ago" string
949 if ($age > 60*60*24*365*2) {
950 $age_str = (int $age/60/60/24/365);
951 $age_str .= " years ago";
952 } elsif ($age > 60*60*24*(365/12)*2) {
953 $age_str = int $age/60/60/24/(365/12);
954 $age_str .= " months ago";
955 } elsif ($age > 60*60*24*7*2) {
956 $age_str = int $age/60/60/24/7;
957 $age_str .= " weeks ago";
958 } elsif ($age > 60*60*24*2) {
959 $age_str = int $age/60/60/24;
960 $age_str .= " days ago";
961 } elsif ($age > 60*60*2) {
962 $age_str = int $age/60/60;
963 $age_str .= " hours ago";
964 } elsif ($age > 60*2) {
965 $age_str = int $age/60;
966 $age_str .= " min ago";
969 $age_str .= " sec ago";
971 $age_str .= " right now";
977 S_IFINVALID
=> 0030000,
978 S_IFGITLINK
=> 0160000,
981 # submodule/subproject, a commit object reference
985 return (($mode & S_IFMT
) == S_IFGITLINK
)
988 # convert file mode in octal to symbolic file mode string
990 my $mode = oct shift;
992 if (S_ISGITLINK
($mode)) {
994 } elsif (S_ISDIR
($mode & S_IFMT
)) {
996 } elsif (S_ISLNK
($mode)) {
998 } elsif (S_ISREG
($mode)) {
999 # git cares only about the executable bit
1000 if ($mode & S_IXUSR
) {
1001 return '-rwxr-xr-x';
1003 return '-rw-r--r--';
1006 return '----------';
1010 # convert file mode in octal to file type string
1014 if ($mode !~ m/^[0-7]+$/) {
1020 if (S_ISGITLINK
($mode)) {
1022 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1024 } elsif (S_ISLNK
($mode)) {
1026 } elsif (S_ISREG
($mode)) {
1033 # convert file mode in octal to file type description string
1034 sub file_type_long
{
1037 if ($mode !~ m/^[0-7]+$/) {
1043 if (S_ISGITLINK
($mode)) {
1045 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1047 } elsif (S_ISLNK
($mode)) {
1049 } elsif (S_ISREG
($mode)) {
1050 if ($mode & S_IXUSR
) {
1051 return "executable";
1061 ## ----------------------------------------------------------------------
1062 ## functions returning short HTML fragments, or transforming HTML fragments
1063 ## which don't belong to other sections
1065 # format line of commit message.
1066 sub format_log_line_html
{
1069 $line = esc_html
($line, -nbsp
=>1);
1070 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1073 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1074 -class => "text"}, $hash_text);
1075 $line =~ s/$hash_text/$link/;
1080 # format marker of refs pointing to given object
1081 sub format_ref_marker
{
1082 my ($refs, $id) = @_;
1085 if (defined $refs->{$id}) {
1086 foreach my $ref (@
{$refs->{$id}}) {
1087 my ($type, $name) = qw();
1088 # e.g. tags/v2.6.11 or heads/next
1089 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1097 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1098 esc_html
($name) . "</span>";
1103 return ' <span class="refs">'. $markers . '</span>';
1109 # format, perhaps shortened and with markers, title line
1110 sub format_subject_html
{
1111 my ($long, $short, $href, $extra) = @_;
1112 $extra = '' unless defined($extra);
1114 if (length($short) < length($long)) {
1115 return $cgi->a({-href
=> $href, -class => "list subject",
1116 -title
=> to_utf8
($long)},
1117 esc_html
($short) . $extra);
1119 return $cgi->a({-href
=> $href, -class => "list subject"},
1120 esc_html
($long) . $extra);
1124 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1125 sub format_git_diff_header_line
{
1127 my $diffinfo = shift;
1128 my ($from, $to) = @_;
1130 if ($diffinfo->{'nparents'}) {
1132 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1133 if ($to->{'href'}) {
1134 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1135 esc_path
($to->{'file'}));
1136 } else { # file was deleted (no href)
1137 $line .= esc_path
($to->{'file'});
1141 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1142 if ($from->{'href'}) {
1143 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1144 'a/' . esc_path
($from->{'file'}));
1145 } else { # file was added (no href)
1146 $line .= 'a/' . esc_path
($from->{'file'});
1149 if ($to->{'href'}) {
1150 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1151 'b/' . esc_path
($to->{'file'}));
1152 } else { # file was deleted
1153 $line .= 'b/' . esc_path
($to->{'file'});
1157 return "<div class=\"diff header\">$line</div>\n";
1160 # format extended diff header line, before patch itself
1161 sub format_extended_diff_header_line
{
1163 my $diffinfo = shift;
1164 my ($from, $to) = @_;
1167 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1168 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1169 esc_path
($from->{'file'}));
1171 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1172 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1173 esc_path
($to->{'file'}));
1175 # match single <mode>
1176 if ($line =~ m/\s(\d{6})$/) {
1177 $line .= '<span class="info"> (' .
1178 file_type_long
($1) .
1182 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1183 # can match only for combined diff
1185 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1186 if ($from->{'href'}[$i]) {
1187 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1189 substr($diffinfo->{'from_id'}[$i],0,7));
1194 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1197 if ($to->{'href'}) {
1198 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1199 substr($diffinfo->{'to_id'},0,7));
1204 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1205 # can match only for ordinary diff
1206 my ($from_link, $to_link);
1207 if ($from->{'href'}) {
1208 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1209 substr($diffinfo->{'from_id'},0,7));
1211 $from_link = '0' x
7;
1213 if ($to->{'href'}) {
1214 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1215 substr($diffinfo->{'to_id'},0,7));
1219 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1220 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1223 return $line . "<br/>\n";
1226 # format from-file/to-file diff header
1227 sub format_diff_from_to_header
{
1228 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1233 #assert($line =~ m/^---/) if DEBUG;
1234 # no extra formatting for "^--- /dev/null"
1235 if (! $diffinfo->{'nparents'}) {
1236 # ordinary (single parent) diff
1237 if ($line =~ m!^--- "?a/!) {
1238 if ($from->{'href'}) {
1240 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1241 esc_path
($from->{'file'}));
1244 esc_path
($from->{'file'});
1247 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1250 # combined diff (merge commit)
1251 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1252 if ($from->{'href'}[$i]) {
1254 $cgi->a({-href
=>href
(action
=>"blobdiff",
1255 hash_parent
=>$diffinfo->{'from_id'}[$i],
1256 hash_parent_base
=>$parents[$i],
1257 file_parent
=>$from->{'file'}[$i],
1258 hash
=>$diffinfo->{'to_id'},
1260 file_name
=>$to->{'file'}),
1262 -title
=>"diff" . ($i+1)},
1265 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1266 esc_path
($from->{'file'}[$i]));
1268 $line = '--- /dev/null';
1270 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1275 #assert($line =~ m/^\+\+\+/) if DEBUG;
1276 # no extra formatting for "^+++ /dev/null"
1277 if ($line =~ m!^\+\+\+ "?b/!) {
1278 if ($to->{'href'}) {
1280 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1281 esc_path
($to->{'file'}));
1284 esc_path
($to->{'file'});
1287 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1292 # create note for patch simplified by combined diff
1293 sub format_diff_cc_simplified
{
1294 my ($diffinfo, @parents) = @_;
1297 $result .= "<div class=\"diff header\">" .
1299 if (!is_deleted
($diffinfo)) {
1300 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1302 hash
=>$diffinfo->{'to_id'},
1303 file_name
=>$diffinfo->{'to_file'}),
1305 esc_path
($diffinfo->{'to_file'}));
1307 $result .= esc_path
($diffinfo->{'to_file'});
1309 $result .= "</div>\n" . # class="diff header"
1310 "<div class=\"diff nodifferences\">" .
1312 "</div>\n"; # class="diff nodifferences"
1317 # format patch (diff) line (not to be used for diff headers)
1318 sub format_diff_line
{
1320 my ($from, $to) = @_;
1321 my $diff_class = "";
1325 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1327 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1328 if ($line =~ m/^\@{3}/) {
1329 $diff_class = " chunk_header";
1330 } elsif ($line =~ m/^\\/) {
1331 $diff_class = " incomplete";
1332 } elsif ($prefix =~ tr/+/+/) {
1333 $diff_class = " add";
1334 } elsif ($prefix =~ tr/-/-/) {
1335 $diff_class = " rem";
1338 # assume ordinary diff
1339 my $char = substr($line, 0, 1);
1341 $diff_class = " add";
1342 } elsif ($char eq '-') {
1343 $diff_class = " rem";
1344 } elsif ($char eq '@') {
1345 $diff_class = " chunk_header";
1346 } elsif ($char eq "\\") {
1347 $diff_class = " incomplete";
1350 $line = untabify
($line);
1351 if ($from && $to && $line =~ m/^\@{2} /) {
1352 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1353 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1355 $from_lines = 0 unless defined $from_lines;
1356 $to_lines = 0 unless defined $to_lines;
1358 if ($from->{'href'}) {
1359 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1360 -class=>"list"}, $from_text);
1362 if ($to->{'href'}) {
1363 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1364 -class=>"list"}, $to_text);
1366 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1367 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1368 return "<div class=\"diff$diff_class\">$line</div>\n";
1369 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1370 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1371 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1373 @from_text = split(' ', $ranges);
1374 for (my $i = 0; $i < @from_text; ++$i) {
1375 ($from_start[$i], $from_nlines[$i]) =
1376 (split(',', substr($from_text[$i], 1)), 0);
1379 $to_text = pop @from_text;
1380 $to_start = pop @from_start;
1381 $to_nlines = pop @from_nlines;
1383 $line = "<span class=\"chunk_info\">$prefix ";
1384 for (my $i = 0; $i < @from_text; ++$i) {
1385 if ($from->{'href'}[$i]) {
1386 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1387 -class=>"list"}, $from_text[$i]);
1389 $line .= $from_text[$i];
1393 if ($to->{'href'}) {
1394 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1395 -class=>"list"}, $to_text);
1399 $line .= " $prefix</span>" .
1400 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1401 return "<div class=\"diff$diff_class\">$line</div>\n";
1403 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1406 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1407 # linked. Pass the hash of the tree/commit to snapshot.
1408 sub format_snapshot_links
{
1410 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1411 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1412 my $num_fmts = @snapshot_fmts;
1413 if ($num_fmts > 1) {
1414 # A parenthesized list of links bearing format names.
1415 # e.g. "snapshot (_tar.gz_ _zip_)"
1416 return "snapshot (" . join(' ', map
1423 }, $known_snapshot_formats{$_}{'display'})
1424 , @snapshot_fmts) . ")";
1425 } elsif ($num_fmts == 1) {
1426 # A single "snapshot" link whose tooltip bears the format name.
1428 my ($fmt) = @snapshot_fmts;
1434 snapshot_format
=>$fmt
1436 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1438 } else { # $num_fmts == 0
1443 ## ----------------------------------------------------------------------
1444 ## git utility subroutines, invoking git commands
1446 # returns path to the core git executable and the --git-dir parameter as list
1448 return $GIT, '--git-dir='.$git_dir;
1451 # returns path to the core git executable and the --git-dir parameter as string
1453 return join(' ', git_cmd
());
1456 # get HEAD ref of given project as hash
1457 sub git_get_head_hash
{
1458 my $project = shift;
1459 my $o_git_dir = $git_dir;
1461 $git_dir = "$projectroot/$project";
1462 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1465 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1469 if (defined $o_git_dir) {
1470 $git_dir = $o_git_dir;
1475 # get type of given object
1479 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1481 close $fd or return;
1486 # repository configuration
1487 our $config_file = '';
1490 # store multiple values for single key as anonymous array reference
1491 # single values stored directly in the hash, not as [ <value> ]
1492 sub hash_set_multi
{
1493 my ($hash, $key, $value) = @_;
1495 if (!exists $hash->{$key}) {
1496 $hash->{$key} = $value;
1497 } elsif (!ref $hash->{$key}) {
1498 $hash->{$key} = [ $hash->{$key}, $value ];
1500 push @
{$hash->{$key}}, $value;
1504 # return hash of git project configuration
1505 # optionally limited to some section, e.g. 'gitweb'
1506 sub git_parse_project_config
{
1507 my $section_regexp = shift;
1512 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1515 while (my $keyval = <$fh>) {
1517 my ($key, $value) = split(/\n/, $keyval, 2);
1519 hash_set_multi
(\
%config, $key, $value)
1520 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1527 # convert config value to boolean, 'true' or 'false'
1528 # no value, number > 0, 'true' and 'yes' values are true
1529 # rest of values are treated as false (never as error)
1530 sub config_to_bool
{
1533 # strip leading and trailing whitespace
1537 return (!defined $val || # section.key
1538 ($val =~ /^\d+$/ && $val) || # section.key = 1
1539 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1542 # convert config value to simple decimal number
1543 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1544 # to be multiplied by 1024, 1048576, or 1073741824
1548 # strip leading and trailing whitespace
1552 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1554 # unknown unit is treated as 1
1555 return $num * ($unit eq 'g' ?
1073741824 :
1556 $unit eq 'm' ?
1048576 :
1557 $unit eq 'k' ?
1024 : 1);
1562 # convert config value to array reference, if needed
1563 sub config_to_multi
{
1566 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1569 sub git_get_project_config
{
1570 my ($key, $type) = @_;
1573 return unless ($key);
1574 $key =~ s/^gitweb\.//;
1575 return if ($key =~ m/\W/);
1578 if (defined $type) {
1581 unless ($type eq 'bool' || $type eq 'int');
1585 if (!defined $config_file ||
1586 $config_file ne "$git_dir/config") {
1587 %config = git_parse_project_config
('gitweb');
1588 $config_file = "$git_dir/config";
1592 if (!defined $type) {
1593 return $config{"gitweb.$key"};
1594 } elsif ($type eq 'bool') {
1595 # backward compatibility: 'git config --bool' returns true/false
1596 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1597 } elsif ($type eq 'int') {
1598 return config_to_int
($config{"gitweb.$key"});
1600 return $config{"gitweb.$key"};
1603 # get hash of given path at given ref
1604 sub git_get_hash_by_path
{
1606 my $path = shift || return undef;
1611 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1612 or die_error
(undef, "Open git-ls-tree failed");
1614 close $fd or return undef;
1616 if (!defined $line) {
1617 # there is no tree or hash given by $path at $base
1621 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1622 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1623 if (defined $type && $type ne $2) {
1624 # type doesn't match
1630 # get path of entry with given hash at given tree-ish (ref)
1631 # used to get 'from' filename for combined diff (merge commit) for renames
1632 sub git_get_path_by_hash
{
1633 my $base = shift || return;
1634 my $hash = shift || return;
1638 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1640 while (my $line = <$fd>) {
1643 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1644 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1645 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1654 ## ......................................................................
1655 ## git utility functions, directly accessing git repository
1657 sub git_get_project_description
{
1660 $git_dir = "$projectroot/$path";
1661 open my $fd, "$git_dir/description"
1662 or return git_get_project_config
('description');
1665 if (defined $descr) {
1671 sub git_get_project_url_list
{
1674 $git_dir = "$projectroot/$path";
1675 open my $fd, "$git_dir/cloneurl"
1676 or return wantarray ?
1677 @
{ config_to_multi
(git_get_project_config
('url')) } :
1678 config_to_multi
(git_get_project_config
('url'));
1679 my @git_project_url_list = map { chomp; $_ } <$fd>;
1682 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1685 sub git_get_projects_list
{
1690 $filter =~ s/\.git$//;
1692 my ($check_forks) = gitweb_check_feature
('forks');
1694 if (-d
$projects_list) {
1695 # search in directory
1696 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1697 # remove the trailing "/"
1699 my $pfxlen = length("$dir");
1700 my $pfxdepth = ($dir =~ tr!/!!);
1703 follow_fast
=> 1, # follow symbolic links
1704 follow_skip
=> 2, # ignore duplicates
1705 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1707 # skip project-list toplevel, if we get it.
1708 return if (m!^[/.]$!);
1709 # only directories can be git repositories
1710 return unless (-d
$_);
1711 # don't traverse too deep (Find is super slow on os x)
1712 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1713 $File::Find
::prune
= 1;
1717 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1718 # we check related file in $projectroot
1719 if ($check_forks and $subdir =~ m
#/.#) {
1720 $File::Find
::prune
= 1;
1721 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1722 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1723 $File::Find
::prune
= 1;
1728 } elsif (-f
$projects_list) {
1729 # read from file(url-encoded):
1730 # 'git%2Fgit.git Linus+Torvalds'
1731 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1732 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1734 open my ($fd), $projects_list or return;
1736 while (my $line = <$fd>) {
1738 my ($path, $owner) = split ' ', $line;
1739 $path = unescape
($path);
1740 $owner = unescape
($owner);
1741 if (!defined $path) {
1744 if ($filter ne '') {
1745 # looking for forks;
1746 my $pfx = substr($path, 0, length($filter));
1747 if ($pfx ne $filter) {
1750 my $sfx = substr($path, length($filter));
1751 if ($sfx !~ /^\/.*\
.git
$/) {
1754 } elsif ($check_forks) {
1756 foreach my $filter (keys %paths) {
1757 # looking for forks;
1758 my $pfx = substr($path, 0, length($filter));
1759 if ($pfx ne $filter) {
1762 my $sfx = substr($path, length($filter));
1763 if ($sfx !~ /^\/.*\
.git
$/) {
1766 # is a fork, don't include it in
1771 if (check_export_ok
("$projectroot/$path")) {
1774 owner
=> to_utf8
($owner),
1777 (my $forks_path = $path) =~ s/\.git$//;
1778 $paths{$forks_path}++;
1786 our $gitweb_project_owner = undef;
1787 sub git_get_project_list_from_file
{
1789 return if (defined $gitweb_project_owner);
1791 $gitweb_project_owner = {};
1792 # read from file (url-encoded):
1793 # 'git%2Fgit.git Linus+Torvalds'
1794 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1795 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1796 if (-f
$projects_list) {
1797 open (my $fd , $projects_list);
1798 while (my $line = <$fd>) {
1800 my ($pr, $ow) = split ' ', $line;
1801 $pr = unescape
($pr);
1802 $ow = unescape
($ow);
1803 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1809 sub git_get_project_owner
{
1810 my $project = shift;
1813 return undef unless $project;
1814 $git_dir = "$projectroot/$project";
1816 if (!defined $gitweb_project_owner) {
1817 git_get_project_list_from_file
();
1820 if (exists $gitweb_project_owner->{$project}) {
1821 $owner = $gitweb_project_owner->{$project};
1823 if (!defined $owner){
1824 $owner = git_get_project_config
('owner');
1826 if (!defined $owner) {
1827 $owner = get_file_owner
("$git_dir");
1833 sub git_get_last_activity
{
1837 $git_dir = "$projectroot/$path";
1838 open($fd, "-|", git_cmd
(), 'for-each-ref',
1839 '--format=%(committer)',
1840 '--sort=-committerdate',
1842 'refs/heads') or return;
1843 my $most_recent = <$fd>;
1844 close $fd or return;
1845 if (defined $most_recent &&
1846 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1848 my $age = time - $timestamp;
1849 return ($age, age_string
($age));
1851 return (undef, undef);
1854 sub git_get_references
{
1855 my $type = shift || "";
1857 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1858 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1859 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1860 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1863 while (my $line = <$fd>) {
1865 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1866 if (defined $refs{$1}) {
1867 push @
{$refs{$1}}, $2;
1873 close $fd or return;
1877 sub git_get_rev_name_tags
{
1878 my $hash = shift || return undef;
1880 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1882 my $name_rev = <$fd>;
1885 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1888 # catches also '$hash undefined' output
1893 ## ----------------------------------------------------------------------
1894 ## parse to hash functions
1898 my $tz = shift || "-0000";
1901 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1902 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1903 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1904 $date{'hour'} = $hour;
1905 $date{'minute'} = $min;
1906 $date{'mday'} = $mday;
1907 $date{'day'} = $days[$wday];
1908 $date{'month'} = $months[$mon];
1909 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1910 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1911 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1912 $mday, $months[$mon], $hour ,$min;
1913 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1914 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1916 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1917 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1918 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1919 $date{'hour_local'} = $hour;
1920 $date{'minute_local'} = $min;
1921 $date{'tz_local'} = $tz;
1922 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1923 1900+$year, $mon+1, $mday,
1924 $hour, $min, $sec, $tz);
1933 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1934 $tag{'id'} = $tag_id;
1935 while (my $line = <$fd>) {
1937 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1938 $tag{'object'} = $1;
1939 } elsif ($line =~ m/^type (.+)$/) {
1941 } elsif ($line =~ m/^tag (.+)$/) {
1943 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1944 $tag{'author'} = $1;
1947 } elsif ($line =~ m/--BEGIN/) {
1948 push @comment, $line;
1950 } elsif ($line eq "") {
1954 push @comment, <$fd>;
1955 $tag{'comment'} = \
@comment;
1956 close $fd or return;
1957 if (!defined $tag{'name'}) {
1963 sub parse_commit_text
{
1964 my ($commit_text, $withparents) = @_;
1965 my @commit_lines = split '\n', $commit_text;
1968 pop @commit_lines; # Remove '\0'
1970 if (! @commit_lines) {
1974 my $header = shift @commit_lines;
1975 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1978 ($co{'id'}, my @parents) = split ' ', $header;
1979 while (my $line = shift @commit_lines) {
1980 last if $line eq "\n";
1981 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1983 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1985 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1987 $co{'author_epoch'} = $2;
1988 $co{'author_tz'} = $3;
1989 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1990 $co{'author_name'} = $1;
1991 $co{'author_email'} = $2;
1993 $co{'author_name'} = $co{'author'};
1995 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1996 $co{'committer'} = $1;
1997 $co{'committer_epoch'} = $2;
1998 $co{'committer_tz'} = $3;
1999 $co{'committer_name'} = $co{'committer'};
2000 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2001 $co{'committer_name'} = $1;
2002 $co{'committer_email'} = $2;
2004 $co{'committer_name'} = $co{'committer'};
2008 if (!defined $co{'tree'}) {
2011 $co{'parents'} = \
@parents;
2012 $co{'parent'} = $parents[0];
2014 foreach my $title (@commit_lines) {
2017 $co{'title'} = chop_str
($title, 80, 5);
2018 # remove leading stuff of merges to make the interesting part visible
2019 if (length($title) > 50) {
2020 $title =~ s/^Automatic //;
2021 $title =~ s/^merge (of|with) /Merge ... /i;
2022 if (length($title) > 50) {
2023 $title =~ s/(http|rsync):\/\///;
2025 if (length($title) > 50) {
2026 $title =~ s/(master|www|rsync)\.//;
2028 if (length($title) > 50) {
2029 $title =~ s/kernel.org:?//;
2031 if (length($title) > 50) {
2032 $title =~ s/\/pub\/scm//;
2035 $co{'title_short'} = chop_str
($title, 50, 5);
2039 if ($co{'title'} eq "") {
2040 $co{'title'} = $co{'title_short'} = '(no commit message)';
2042 # remove added spaces
2043 foreach my $line (@commit_lines) {
2046 $co{'comment'} = \
@commit_lines;
2048 my $age = time - $co{'committer_epoch'};
2050 $co{'age_string'} = age_string
($age);
2051 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2052 if ($age > 60*60*24*7*2) {
2053 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2054 $co{'age_string_age'} = $co{'age_string'};
2056 $co{'age_string_date'} = $co{'age_string'};
2057 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2063 my ($commit_id) = @_;
2068 open my $fd, "-|", git_cmd
(), "rev-list",
2074 or die_error
(undef, "Open git-rev-list failed");
2075 %co = parse_commit_text
(<$fd>, 1);
2082 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2090 open my $fd, "-|", git_cmd
(), "rev-list",
2093 ("--max-count=" . $maxcount),
2094 ("--skip=" . $skip),
2098 ($filename ?
($filename) : ())
2099 or die_error
(undef, "Open git-rev-list failed");
2100 while (my $line = <$fd>) {
2101 my %co = parse_commit_text
($line);
2106 return wantarray ?
@cos : \
@cos;
2109 # parse ref from ref_file, given by ref_id, with given type
2111 my $ref_file = shift;
2113 my $type = shift || git_get_type
($ref_id);
2116 $ref_item{'type'} = $type;
2117 $ref_item{'id'} = $ref_id;
2118 $ref_item{'epoch'} = 0;
2119 $ref_item{'age'} = "unknown";
2120 if ($type eq "tag") {
2121 my %tag = parse_tag
($ref_id);
2122 $ref_item{'comment'} = $tag{'comment'};
2123 if ($tag{'type'} eq "commit") {
2124 my %co = parse_commit
($tag{'object'});
2125 $ref_item{'epoch'} = $co{'committer_epoch'};
2126 $ref_item{'age'} = $co{'age_string'};
2127 } elsif (defined($tag{'epoch'})) {
2128 my $age = time - $tag{'epoch'};
2129 $ref_item{'epoch'} = $tag{'epoch'};
2130 $ref_item{'age'} = age_string
($age);
2132 $ref_item{'reftype'} = $tag{'type'};
2133 $ref_item{'name'} = $tag{'name'};
2134 $ref_item{'refid'} = $tag{'object'};
2135 } elsif ($type eq "commit"){
2136 my %co = parse_commit
($ref_id);
2137 $ref_item{'reftype'} = "commit";
2138 $ref_item{'name'} = $ref_file;
2139 $ref_item{'title'} = $co{'title'};
2140 $ref_item{'refid'} = $ref_id;
2141 $ref_item{'epoch'} = $co{'committer_epoch'};
2142 $ref_item{'age'} = $co{'age_string'};
2144 $ref_item{'reftype'} = $type;
2145 $ref_item{'name'} = $ref_file;
2146 $ref_item{'refid'} = $ref_id;
2152 # parse line of git-diff-tree "raw" output
2153 sub parse_difftree_raw_line
{
2157 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2158 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2159 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2160 $res{'from_mode'} = $1;
2161 $res{'to_mode'} = $2;
2162 $res{'from_id'} = $3;
2164 $res{'status'} = $res{'status_str'} = $5;
2165 $res{'similarity'} = $6;
2166 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2167 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2169 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2172 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2173 # combined diff (for merge commit)
2174 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2175 $res{'nparents'} = length($1);
2176 $res{'from_mode'} = [ split(' ', $2) ];
2177 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2178 $res{'from_id'} = [ split(' ', $3) ];
2179 $res{'to_id'} = pop @
{$res{'from_id'}};
2180 $res{'status_str'} = $4;
2181 $res{'status'} = [ split('', $4) ];
2182 $res{'to_file'} = unquote
($5);
2184 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2185 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2186 $res{'commit'} = $1;
2189 return wantarray ?
%res : \
%res;
2192 # wrapper: return parsed line of git-diff-tree "raw" output
2193 # (the argument might be raw line, or parsed info)
2194 sub parsed_difftree_line
{
2195 my $line_or_ref = shift;
2197 if (ref($line_or_ref) eq "HASH") {
2198 # pre-parsed (or generated by hand)
2199 return $line_or_ref;
2201 return parse_difftree_raw_line
($line_or_ref);
2205 # parse line of git-ls-tree output
2206 sub parse_ls_tree_line
($;%) {
2211 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2212 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2220 $res{'name'} = unquote
($4);
2223 return wantarray ?
%res : \
%res;
2226 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2227 sub parse_from_to_diffinfo
{
2228 my ($diffinfo, $from, $to, @parents) = @_;
2230 if ($diffinfo->{'nparents'}) {
2232 $from->{'file'} = [];
2233 $from->{'href'} = [];
2234 fill_from_file_info
($diffinfo, @parents)
2235 unless exists $diffinfo->{'from_file'};
2236 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2237 $from->{'file'}[$i] =
2238 defined $diffinfo->{'from_file'}[$i] ?
2239 $diffinfo->{'from_file'}[$i] :
2240 $diffinfo->{'to_file'};
2241 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2242 $from->{'href'}[$i] = href
(action
=>"blob",
2243 hash_base
=>$parents[$i],
2244 hash
=>$diffinfo->{'from_id'}[$i],
2245 file_name
=>$from->{'file'}[$i]);
2247 $from->{'href'}[$i] = undef;
2251 # ordinary (not combined) diff
2252 $from->{'file'} = $diffinfo->{'from_file'};
2253 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2254 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2255 hash
=>$diffinfo->{'from_id'},
2256 file_name
=>$from->{'file'});
2258 delete $from->{'href'};
2262 $to->{'file'} = $diffinfo->{'to_file'};
2263 if (!is_deleted
($diffinfo)) { # file exists in result
2264 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2265 hash
=>$diffinfo->{'to_id'},
2266 file_name
=>$to->{'file'});
2268 delete $to->{'href'};
2272 ## ......................................................................
2273 ## parse to array of hashes functions
2275 sub git_get_heads_list
{
2279 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2280 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2281 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2284 while (my $line = <$fd>) {
2288 my ($refinfo, $committerinfo) = split(/\0/, $line);
2289 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2290 my ($committer, $epoch, $tz) =
2291 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2292 $ref_item{'fullname'} = $name;
2293 $name =~ s!^refs/heads/!!;
2295 $ref_item{'name'} = $name;
2296 $ref_item{'id'} = $hash;
2297 $ref_item{'title'} = $title || '(no commit message)';
2298 $ref_item{'epoch'} = $epoch;
2300 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2302 $ref_item{'age'} = "unknown";
2305 push @headslist, \
%ref_item;
2309 return wantarray ?
@headslist : \
@headslist;
2312 sub git_get_tags_list
{
2316 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2317 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2318 '--format=%(objectname) %(objecttype) %(refname) '.
2319 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2322 while (my $line = <$fd>) {
2326 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2327 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2328 my ($creator, $epoch, $tz) =
2329 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2330 $ref_item{'fullname'} = $name;
2331 $name =~ s!^refs/tags/!!;
2333 $ref_item{'type'} = $type;
2334 $ref_item{'id'} = $id;
2335 $ref_item{'name'} = $name;
2336 if ($type eq "tag") {
2337 $ref_item{'subject'} = $title;
2338 $ref_item{'reftype'} = $reftype;
2339 $ref_item{'refid'} = $refid;
2341 $ref_item{'reftype'} = $type;
2342 $ref_item{'refid'} = $id;
2345 if ($type eq "tag" || $type eq "commit") {
2346 $ref_item{'epoch'} = $epoch;
2348 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2350 $ref_item{'age'} = "unknown";
2354 push @tagslist, \
%ref_item;
2358 return wantarray ?
@tagslist : \
@tagslist;
2361 ## ----------------------------------------------------------------------
2362 ## filesystem-related functions
2364 sub get_file_owner
{
2367 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2368 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2369 if (!defined $gcos) {
2373 $owner =~ s/[,;].*$//;
2374 return to_utf8
($owner);
2377 ## ......................................................................
2378 ## mimetype related functions
2380 sub mimetype_guess_file
{
2381 my $filename = shift;
2382 my $mimemap = shift;
2383 -r
$mimemap or return undef;
2386 open(MIME
, $mimemap) or return undef;
2388 next if m/^#/; # skip comments
2389 my ($mime, $exts) = split(/\t+/);
2390 if (defined $exts) {
2391 my @exts = split(/\s+/, $exts);
2392 foreach my $ext (@exts) {
2393 $mimemap{$ext} = $mime;
2399 $filename =~ /\.([^.]*)$/;
2400 return $mimemap{$1};
2403 sub mimetype_guess
{
2404 my $filename = shift;
2406 $filename =~ /\./ or return undef;
2408 if ($mimetypes_file) {
2409 my $file = $mimetypes_file;
2410 if ($file !~ m!^/!) { # if it is relative path
2411 # it is relative to project
2412 $file = "$projectroot/$project/$file";
2414 $mime = mimetype_guess_file
($filename, $file);
2416 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2422 my $filename = shift;
2425 my $mime = mimetype_guess
($filename);
2426 $mime and return $mime;
2430 return $default_blob_plain_mimetype unless $fd;
2433 return 'text/plain' .
2434 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2435 } elsif (! $filename) {
2436 return 'application/octet-stream';
2437 } elsif ($filename =~ m/\.png$/i) {
2439 } elsif ($filename =~ m/\.gif$/i) {
2441 } elsif ($filename =~ m/\.jpe?g$/i) {
2442 return 'image/jpeg';
2444 return 'application/octet-stream';
2448 ## ======================================================================
2449 ## functions printing HTML: header, footer, error page
2451 sub git_header_html
{
2452 my $status = shift || "200 OK";
2453 my $expires = shift;
2455 my $title = "$site_name";
2456 if (defined $project) {
2457 $title .= " - " . to_utf8
($project);
2458 if (defined $action) {
2459 $title .= "/$action";
2460 if (defined $file_name) {
2461 $title .= " - " . esc_path
($file_name);
2462 if ($action eq "tree" && $file_name !~ m
|/$|) {
2469 # require explicit support from the UA if we are to send the page as
2470 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2471 # we have to do this because MSIE sometimes globs '*/*', pretending to
2472 # support xhtml+xml but choking when it gets what it asked for.
2473 if (defined $cgi->http('HTTP_ACCEPT') &&
2474 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2475 $cgi->Accept('application/xhtml+xml') != 0) {
2476 $content_type = 'application/xhtml+xml';
2478 $content_type = 'text/html';
2480 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2481 -status
=> $status, -expires
=> $expires);
2482 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2484 <?xml version="1.0" encoding="utf-8"?>
2485 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2486 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2487 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2488 <!-- git core binaries version $git_version -->
2490 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2491 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2492 <meta name="robots" content="index, nofollow"/>
2493 <title>$title</title>
2495 # print out each stylesheet that exist
2496 if (defined $stylesheet) {
2497 #provides backwards capability for those people who define style sheet in a config file
2498 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2500 foreach my $stylesheet (@stylesheets) {
2501 next unless $stylesheet;
2502 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2505 if (defined $project) {
2506 printf('<link rel="alternate" title="%s log RSS feed" '.
2507 'href="%s" type="application/rss+xml" />'."\n",
2508 esc_param
($project), href
(action
=>"rss"));
2509 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2510 'href="%s" type="application/rss+xml" />'."\n",
2511 esc_param
($project), href
(action
=>"rss",
2512 extra_options
=>"--no-merges"));
2513 printf('<link rel="alternate" title="%s log Atom feed" '.
2514 'href="%s" type="application/atom+xml" />'."\n",
2515 esc_param
($project), href
(action
=>"atom"));
2516 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2517 'href="%s" type="application/atom+xml" />'."\n",
2518 esc_param
($project), href
(action
=>"atom",
2519 extra_options
=>"--no-merges"));
2521 printf('<link rel="alternate" title="%s projects list" '.
2522 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2523 $site_name, href
(project
=>undef, action
=>"project_index"));
2524 printf('<link rel="alternate" title="%s projects feeds" '.
2525 'href="%s" type="text/x-opml"/>'."\n",
2526 $site_name, href
(project
=>undef, action
=>"opml"));
2528 if (defined $favicon) {
2529 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2535 if (-f
$site_header) {
2536 open (my $fd, $site_header);
2541 print "<div class=\"page_header\">\n" .
2542 $cgi->a({-href
=> esc_url
($logo_url),
2543 -title
=> $logo_label},
2544 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2545 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2546 if (defined $project) {
2547 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2548 if (defined $action) {
2555 my ($have_search) = gitweb_check_feature
('search');
2556 if ((defined $project) && ($have_search)) {
2557 if (!defined $searchtext) {
2561 if (defined $hash_base) {
2562 $search_hash = $hash_base;
2563 } elsif (defined $hash) {
2564 $search_hash = $hash;
2566 $search_hash = "HEAD";
2568 my $action = $my_uri;
2569 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2570 if ($use_pathinfo) {
2571 $action .= "/$project";
2573 $cgi->param("p", $project);
2575 $cgi->param("a", "search");
2576 $cgi->param("h", $search_hash);
2577 print $cgi->startform(-method
=> "get", -action
=> $action) .
2578 "<div class=\"search\">\n" .
2579 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2580 $cgi->hidden(-name
=> "a") . "\n" .
2581 $cgi->hidden(-name
=> "h") . "\n" .
2582 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2583 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2584 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2586 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2588 $cgi->end_form() . "\n";
2592 sub git_footer_html
{
2593 print "<div class=\"page_footer\">\n";
2594 if (defined $project) {
2595 my $descr = git_get_project_description
($project);
2596 if (defined $descr) {
2597 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2599 print $cgi->a({-href
=> href
(action
=>"rss"),
2600 -class => "rss_logo"}, "RSS") . " ";
2601 print $cgi->a({-href
=> href
(action
=>"atom"),
2602 -class => "rss_logo"}, "Atom") . "\n";
2604 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2605 -class => "rss_logo"}, "OPML") . " ";
2606 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2607 -class => "rss_logo"}, "TXT") . "\n";
2611 if (-f
$site_footer) {
2612 open (my $fd, $site_footer);
2622 my $status = shift || "403 Forbidden";
2623 my $error = shift || "Malformed query, file missing or permission denied";
2625 git_header_html
($status);
2627 <div class="page_body">
2637 ## ----------------------------------------------------------------------
2638 ## functions printing or outputting HTML: navigation
2640 sub git_print_page_nav
{
2641 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2642 $extra = '' if !defined $extra; # pager or formats
2644 my @navs = qw(summary shortlog log commit commitdiff tree);
2646 @navs = grep { $_ ne $suppress } @navs;
2649 my %arg = map { $_ => {action
=>$_} } @navs;
2650 if (defined $head) {
2651 for (qw(commit commitdiff)) {
2652 $arg{$_}{'hash'} = $head;
2654 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2655 for (qw(shortlog log)) {
2656 $arg{$_}{'hash'} = $head;
2660 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2661 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2663 print "<div class=\"page_nav\">\n" .
2665 map { $_ eq $current ?
2666 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2668 print "<br/>\n$extra<br/>\n" .
2672 sub format_paging_nav
{
2673 my ($action, $hash, $head, $page, $nrevs) = @_;
2677 if ($hash ne $head || $page) {
2678 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2680 $paging_nav .= "HEAD";
2684 $paging_nav .= " ⋅ " .
2685 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2686 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2688 $paging_nav .= " ⋅ prev";
2691 if ($nrevs >= (100 * ($page+1)-1)) {
2692 $paging_nav .= " ⋅ " .
2693 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2694 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2696 $paging_nav .= " ⋅ next";
2702 ## ......................................................................
2703 ## functions printing or outputting HTML: div
2705 sub git_print_header_div
{
2706 my ($action, $title, $hash, $hash_base) = @_;
2709 $args{'action'} = $action;
2710 $args{'hash'} = $hash if $hash;
2711 $args{'hash_base'} = $hash_base if $hash_base;
2713 print "<div class=\"header\">\n" .
2714 $cgi->a({-href
=> href
(%args), -class => "title"},
2715 $title ?
$title : $action) .
2719 #sub git_print_authorship (\%) {
2720 sub git_print_authorship
{
2723 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2724 print "<div class=\"author_date\">" .
2725 esc_html
($co->{'author_name'}) .
2727 if ($ad{'hour_local'} < 6) {
2728 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2729 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2731 printf(" (%02d:%02d %s)",
2732 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2737 sub git_print_page_path
{
2743 print "<div class=\"page_path\">";
2744 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2745 -title
=> 'tree root'}, to_utf8
("[$project]"));
2747 if (defined $name) {
2748 my @dirname = split '/', $name;
2749 my $basename = pop @dirname;
2752 foreach my $dir (@dirname) {
2753 $fullname .= ($fullname ?
'/' : '') . $dir;
2754 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2756 -title
=> $fullname}, esc_path
($dir));
2759 if (defined $type && $type eq 'blob') {
2760 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2762 -title
=> $name}, esc_path
($basename));
2763 } elsif (defined $type && $type eq 'tree') {
2764 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2766 -title
=> $name}, esc_path
($basename));
2769 print esc_path
($basename);
2772 print "<br/></div>\n";
2775 # sub git_print_log (\@;%) {
2776 sub git_print_log
($;%) {
2780 if ($opts{'-remove_title'}) {
2781 # remove title, i.e. first line of log
2784 # remove leading empty lines
2785 while (defined $log->[0] && $log->[0] eq "") {
2792 foreach my $line (@
$log) {
2793 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2796 if (! $opts{'-remove_signoff'}) {
2797 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2800 # remove signoff lines
2807 # print only one empty line
2808 # do not print empty line after signoff
2810 next if ($empty || $signoff);
2816 print format_log_line_html
($line) . "<br/>\n";
2819 if ($opts{'-final_empty_line'}) {
2820 # end with single empty line
2821 print "<br/>\n" unless $empty;
2825 # return link target (what link points to)
2826 sub git_get_link_target
{
2831 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2835 $link_target = <$fd>;
2840 return $link_target;
2843 # given link target, and the directory (basedir) the link is in,
2844 # return target of link relative to top directory (top tree);
2845 # return undef if it is not possible (including absolute links).
2846 sub normalize_link_target
{
2847 my ($link_target, $basedir, $hash_base) = @_;
2849 # we can normalize symlink target only if $hash_base is provided
2850 return unless $hash_base;
2852 # absolute symlinks (beginning with '/') cannot be normalized
2853 return if (substr($link_target, 0, 1) eq '/');
2855 # normalize link target to path from top (root) tree (dir)
2858 $path = $basedir . '/' . $link_target;
2860 # we are in top (root) tree (dir)
2861 $path = $link_target;
2864 # remove //, /./, and /../
2866 foreach my $part (split('/', $path)) {
2867 # discard '.' and ''
2868 next if (!$part || $part eq '.');
2870 if ($part eq '..') {
2874 # link leads outside repository (outside top dir)
2878 push @path_parts, $part;
2881 $path = join('/', @path_parts);
2886 # print tree entry (row of git_tree), but without encompassing <tr> element
2887 sub git_print_tree_entry
{
2888 my ($t, $basedir, $hash_base, $have_blame) = @_;
2891 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2893 # The format of a table row is: mode list link. Where mode is
2894 # the mode of the entry, list is the name of the entry, an href,
2895 # and link is the action links of the entry.
2897 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2898 if ($t->{'type'} eq "blob") {
2899 print "<td class=\"list\">" .
2900 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2901 file_name
=>"$basedir$t->{'name'}", %base_key),
2902 -class => "list"}, esc_path
($t->{'name'}));
2903 if (S_ISLNK
(oct $t->{'mode'})) {
2904 my $link_target = git_get_link_target
($t->{'hash'});
2906 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2907 if (defined $norm_target) {
2909 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2910 file_name
=>$norm_target),
2911 -title
=> $norm_target}, esc_path
($link_target));
2913 print " -> " . esc_path
($link_target);
2918 print "<td class=\"link\">";
2919 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2920 file_name
=>"$basedir$t->{'name'}", %base_key)},
2924 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2925 file_name
=>"$basedir$t->{'name'}", %base_key)},
2928 if (defined $hash_base) {
2930 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2931 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2935 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2936 file_name
=>"$basedir$t->{'name'}")},
2940 } elsif ($t->{'type'} eq "tree") {
2941 print "<td class=\"list\">";
2942 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2943 file_name
=>"$basedir$t->{'name'}", %base_key)},
2944 esc_path
($t->{'name'}));
2946 print "<td class=\"link\">";
2947 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2948 file_name
=>"$basedir$t->{'name'}", %base_key)},
2950 if (defined $hash_base) {
2952 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2953 file_name
=>"$basedir$t->{'name'}")},
2958 # unknown object: we can only present history for it
2959 # (this includes 'commit' object, i.e. submodule support)
2960 print "<td class=\"list\">" .
2961 esc_path
($t->{'name'}) .
2963 print "<td class=\"link\">";
2964 if (defined $hash_base) {
2965 print $cgi->a({-href
=> href
(action
=>"history",
2966 hash_base
=>$hash_base,
2967 file_name
=>"$basedir$t->{'name'}")},
2974 ## ......................................................................
2975 ## functions printing large fragments of HTML
2977 # get pre-image filenames for merge (combined) diff
2978 sub fill_from_file_info
{
2979 my ($diff, @parents) = @_;
2981 $diff->{'from_file'} = [ ];
2982 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2983 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2984 if ($diff->{'status'}[$i] eq 'R' ||
2985 $diff->{'status'}[$i] eq 'C') {
2986 $diff->{'from_file'}[$i] =
2987 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2994 # is current raw difftree line of file deletion
2996 my $diffinfo = shift;
2998 return $diffinfo->{'status_str'} =~ /D/;
3001 # does patch correspond to [previous] difftree raw line
3002 # $diffinfo - hashref of parsed raw diff format
3003 # $patchinfo - hashref of parsed patch diff format
3004 # (the same keys as in $diffinfo)
3005 sub is_patch_split
{
3006 my ($diffinfo, $patchinfo) = @_;
3008 return defined $diffinfo && defined $patchinfo
3009 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3013 sub git_difftree_body
{
3014 my ($difftree, $hash, @parents) = @_;
3015 my ($parent) = $parents[0];
3016 my ($have_blame) = gitweb_check_feature
('blame');
3017 print "<div class=\"list_head\">\n";
3018 if ($#{$difftree} > 10) {
3019 print(($#{$difftree} + 1) . " files changed:\n");
3023 print "<table class=\"" .
3024 (@parents > 1 ?
"combined " : "") .
3027 # header only for combined diff in 'commitdiff' view
3028 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3031 print "<thead><tr>\n" .
3032 "<th></th><th></th>\n"; # filename, patchN link
3033 for (my $i = 0; $i < @parents; $i++) {
3034 my $par = $parents[$i];
3036 $cgi->a({-href
=> href
(action
=>"commitdiff",
3037 hash
=>$hash, hash_parent
=>$par),
3038 -title
=> 'commitdiff to parent number ' .
3039 ($i+1) . ': ' . substr($par,0,7)},
3043 print "</tr></thead>\n<tbody>\n";
3048 foreach my $line (@
{$difftree}) {
3049 my $diff = parsed_difftree_line
($line);
3052 print "<tr class=\"dark\">\n";
3054 print "<tr class=\"light\">\n";
3058 if (exists $diff->{'nparents'}) { # combined diff
3060 fill_from_file_info
($diff, @parents)
3061 unless exists $diff->{'from_file'};
3063 if (!is_deleted
($diff)) {
3064 # file exists in the result (child) commit
3066 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3067 file_name
=>$diff->{'to_file'},
3069 -class => "list"}, esc_path
($diff->{'to_file'})) .
3073 esc_path
($diff->{'to_file'}) .
3077 if ($action eq 'commitdiff') {
3080 print "<td class=\"link\">" .
3081 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3086 my $has_history = 0;
3087 my $not_deleted = 0;
3088 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3089 my $hash_parent = $parents[$i];
3090 my $from_hash = $diff->{'from_id'}[$i];
3091 my $from_path = $diff->{'from_file'}[$i];
3092 my $status = $diff->{'status'}[$i];
3094 $has_history ||= ($status ne 'A');
3095 $not_deleted ||= ($status ne 'D');
3097 if ($status eq 'A') {
3098 print "<td class=\"link\" align=\"right\"> | </td>\n";
3099 } elsif ($status eq 'D') {
3100 print "<td class=\"link\">" .
3101 $cgi->a({-href
=> href
(action
=>"blob",
3104 file_name
=>$from_path)},
3108 if ($diff->{'to_id'} eq $from_hash) {
3109 print "<td class=\"link nochange\">";
3111 print "<td class=\"link\">";
3113 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3114 hash
=>$diff->{'to_id'},
3115 hash_parent
=>$from_hash,
3117 hash_parent_base
=>$hash_parent,
3118 file_name
=>$diff->{'to_file'},
3119 file_parent
=>$from_path)},
3125 print "<td class=\"link\">";
3127 print $cgi->a({-href
=> href
(action
=>"blob",
3128 hash
=>$diff->{'to_id'},
3129 file_name
=>$diff->{'to_file'},
3132 print " | " if ($has_history);
3135 print $cgi->a({-href
=> href
(action
=>"history",
3136 file_name
=>$diff->{'to_file'},
3143 next; # instead of 'else' clause, to avoid extra indent
3145 # else ordinary diff
3147 my ($to_mode_oct, $to_mode_str, $to_file_type);
3148 my ($from_mode_oct, $from_mode_str, $from_file_type);
3149 if ($diff->{'to_mode'} ne ('0' x
6)) {
3150 $to_mode_oct = oct $diff->{'to_mode'};
3151 if (S_ISREG
($to_mode_oct)) { # only for regular file
3152 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3154 $to_file_type = file_type
($diff->{'to_mode'});
3156 if ($diff->{'from_mode'} ne ('0' x
6)) {
3157 $from_mode_oct = oct $diff->{'from_mode'};
3158 if (S_ISREG
($to_mode_oct)) { # only for regular file
3159 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3161 $from_file_type = file_type
($diff->{'from_mode'});
3164 if ($diff->{'status'} eq "A") { # created
3165 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3166 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3167 $mode_chng .= "]</span>";
3169 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3170 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3171 -class => "list"}, esc_path
($diff->{'file'}));
3173 print "<td>$mode_chng</td>\n";
3174 print "<td class=\"link\">";
3175 if ($action eq 'commitdiff') {
3178 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3181 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3182 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3186 } elsif ($diff->{'status'} eq "D") { # deleted
3187 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3189 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3190 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3191 -class => "list"}, esc_path
($diff->{'file'}));
3193 print "<td>$mode_chng</td>\n";
3194 print "<td class=\"link\">";
3195 if ($action eq 'commitdiff') {
3198 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3201 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3202 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3205 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3206 file_name
=>$diff->{'file'})},
3209 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3210 file_name
=>$diff->{'file'})},
3214 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3215 my $mode_chnge = "";
3216 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3217 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3218 if ($from_file_type ne $to_file_type) {
3219 $mode_chnge .= " from $from_file_type to $to_file_type";
3221 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3222 if ($from_mode_str && $to_mode_str) {
3223 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3224 } elsif ($to_mode_str) {
3225 $mode_chnge .= " mode: $to_mode_str";
3228 $mode_chnge .= "]</span>\n";
3231 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3232 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3233 -class => "list"}, esc_path
($diff->{'file'}));
3235 print "<td>$mode_chnge</td>\n";
3236 print "<td class=\"link\">";
3237 if ($action eq 'commitdiff') {
3240 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3242 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3243 # "commit" view and modified file (not onlu mode changed)
3244 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3245 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3246 hash_base
=>$hash, hash_parent_base
=>$parent,
3247 file_name
=>$diff->{'file'})},
3251 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3252 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3255 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3256 file_name
=>$diff->{'file'})},
3259 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3260 file_name
=>$diff->{'file'})},
3264 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3265 my %status_name = ('R' => 'moved', 'C' => 'copied');
3266 my $nstatus = $status_name{$diff->{'status'}};
3268 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3269 # mode also for directories, so we cannot use $to_mode_str
3270 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3273 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3274 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3275 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3276 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3277 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3278 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3279 -class => "list"}, esc_path
($diff->{'from_file'})) .
3280 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3281 "<td class=\"link\">";
3282 if ($action eq 'commitdiff') {
3285 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3287 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3288 # "commit" view and modified file (not only pure rename or copy)
3289 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3290 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3291 hash_base
=>$hash, hash_parent_base
=>$parent,
3292 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3296 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3297 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3300 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3301 file_name
=>$diff->{'to_file'})},
3304 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3305 file_name
=>$diff->{'to_file'})},
3309 } # we should not encounter Unmerged (U) or Unknown (X) status
3312 print "</tbody>" if $has_header;
3316 sub git_patchset_body
{
3317 my ($fd, $difftree, $hash, @hash_parents) = @_;
3318 my ($hash_parent) = $hash_parents[0];
3320 my $is_combined = (@hash_parents > 1);
3322 my $patch_number = 0;
3328 print "<div class=\"patchset\">\n";
3330 # skip to first patch
3331 while ($patch_line = <$fd>) {
3334 last if ($patch_line =~ m/^diff /);
3338 while ($patch_line) {
3340 # parse "git diff" header line
3341 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3342 # $1 is from_name, which we do not use
3343 $to_name = unquote
($2);
3344 $to_name =~ s!^b/!!;
3345 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3346 # $1 is 'cc' or 'combined', which we do not use
3347 $to_name = unquote
($2);
3352 # check if current patch belong to current raw line
3353 # and parse raw git-diff line if needed
3354 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3355 # this is continuation of a split patch
3356 print "<div class=\"patch cont\">\n";
3358 # advance raw git-diff output if needed
3359 $patch_idx++ if defined $diffinfo;
3361 # read and prepare patch information
3362 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3364 # compact combined diff output can have some patches skipped
3365 # find which patch (using pathname of result) we are at now;
3367 while ($to_name ne $diffinfo->{'to_file'}) {
3368 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3369 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3370 "</div>\n"; # class="patch"
3375 last if $patch_idx > $#$difftree;
3376 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3380 # modifies %from, %to hashes
3381 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3383 # this is first patch for raw difftree line with $patch_idx index
3384 # we index @$difftree array from 0, but number patches from 1
3385 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3389 #assert($patch_line =~ m/^diff /) if DEBUG;
3390 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3392 # print "git diff" header
3393 print format_git_diff_header_line
($patch_line, $diffinfo,
3396 # print extended diff header
3397 print "<div class=\"diff extended_header\">\n";
3399 while ($patch_line = <$fd>) {
3402 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3404 print format_extended_diff_header_line
($patch_line, $diffinfo,
3407 print "</div>\n"; # class="diff extended_header"
3409 # from-file/to-file diff header
3410 if (! $patch_line) {
3411 print "</div>\n"; # class="patch"
3414 next PATCH
if ($patch_line =~ m/^diff /);
3415 #assert($patch_line =~ m/^---/) if DEBUG;
3417 my $last_patch_line = $patch_line;
3418 $patch_line = <$fd>;
3420 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3422 print format_diff_from_to_header
($last_patch_line, $patch_line,
3423 $diffinfo, \
%from, \
%to,
3428 while ($patch_line = <$fd>) {
3431 next PATCH
if ($patch_line =~ m/^diff /);
3433 print format_diff_line
($patch_line, \
%from, \
%to);
3437 print "</div>\n"; # class="patch"
3440 # for compact combined (--cc) format, with chunk and patch simpliciaction
3441 # patchset might be empty, but there might be unprocessed raw lines
3442 for (++$patch_idx if $patch_number > 0;
3443 $patch_idx < @
$difftree;
3445 # read and prepare patch information
3446 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3448 # generate anchor for "patch" links in difftree / whatchanged part
3449 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3450 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3451 "</div>\n"; # class="patch"
3456 if ($patch_number == 0) {
3457 if (@hash_parents > 1) {
3458 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3460 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3464 print "</div>\n"; # class="patchset"
3467 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3469 sub git_project_list_body
{
3470 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3472 my ($check_forks) = gitweb_check_feature
('forks');
3475 foreach my $pr (@
$projlist) {
3476 my (@aa) = git_get_last_activity
($pr->{'path'});
3480 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3481 if (!defined $pr->{'descr'}) {
3482 my $descr = git_get_project_description
($pr->{'path'}) || "";
3483 $pr->{'descr_long'} = to_utf8
($descr);
3484 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3486 if (!defined $pr->{'owner'}) {
3487 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3490 my $pname = $pr->{'path'};
3491 if (($pname =~ s/\.git$//) &&
3492 ($pname !~ /\/$/) &&
3493 (-d
"$projectroot/$pname")) {
3494 $pr->{'forks'} = "-d $projectroot/$pname";
3500 push @projects, $pr;
3503 $order ||= $default_projects_order;
3504 $from = 0 unless defined $from;
3505 $to = $#projects if (!defined $to || $#projects < $to);
3507 print "<table class=\"project_list\">\n";
3508 unless ($no_header) {
3511 print "<th></th>\n";
3513 if ($order eq "project") {
3514 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3515 print "<th>Project</th>\n";
3518 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3519 -class => "header"}, "Project") .
3522 if ($order eq "descr") {
3523 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3524 print "<th>Description</th>\n";
3527 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3528 -class => "header"}, "Description") .
3531 if ($order eq "owner") {
3532 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3533 print "<th>Owner</th>\n";
3536 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3537 -class => "header"}, "Owner") .
3540 if ($order eq "age") {
3541 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3542 print "<th>Last Change</th>\n";
3545 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3546 -class => "header"}, "Last Change") .
3549 print "<th></th>\n" .
3553 for (my $i = $from; $i <= $to; $i++) {
3554 my $pr = $projects[$i];
3556 print "<tr class=\"dark\">\n";
3558 print "<tr class=\"light\">\n";
3563 if ($pr->{'forks'}) {
3564 print "<!-- $pr->{'forks'} -->\n";
3565 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3569 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3570 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3571 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3572 -class => "list", -title
=> $pr->{'descr_long'}},
3573 esc_html
($pr->{'descr'})) . "</td>\n" .
3574 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3575 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3576 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3577 "<td class=\"link\">" .
3578 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3579 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3580 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3581 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3582 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3586 if (defined $extra) {
3589 print "<td></td>\n";
3591 print "<td colspan=\"5\">$extra</td>\n" .
3597 sub git_shortlog_body
{
3598 # uses global variable $project
3599 my ($commitlist, $from, $to, $refs, $extra) = @_;
3601 $from = 0 unless defined $from;
3602 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3604 print "<table class=\"shortlog\">\n";
3606 for (my $i = $from; $i <= $to; $i++) {
3607 my %co = %{$commitlist->[$i]};
3608 my $commit = $co{'id'};
3609 my $ref = format_ref_marker
($refs, $commit);
3611 print "<tr class=\"dark\">\n";
3613 print "<tr class=\"light\">\n";
3616 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3617 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3618 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3619 "<td><i>" . $author . "</i></td>\n" .
3621 print format_subject_html
($co{'title'}, $co{'title_short'},
3622 href
(action
=>"commit", hash
=>$commit), $ref);
3624 "<td class=\"link\">" .
3625 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3626 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3627 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3628 my $snapshot_links = format_snapshot_links
($commit);
3629 if (defined $snapshot_links) {
3630 print " | " . $snapshot_links;
3635 if (defined $extra) {
3637 "<td colspan=\"4\">$extra</td>\n" .
3643 sub git_history_body
{
3644 # Warning: assumes constant type (blob or tree) during history
3645 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3647 $from = 0 unless defined $from;
3648 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3650 print "<table class=\"history\">\n";
3652 for (my $i = $from; $i <= $to; $i++) {
3653 my %co = %{$commitlist->[$i]};
3657 my $commit = $co{'id'};
3659 my $ref = format_ref_marker
($refs, $commit);
3662 print "<tr class=\"dark\">\n";
3664 print "<tr class=\"light\">\n";
3667 # shortlog uses chop_str($co{'author_name'}, 10)
3668 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3669 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3670 "<td><i>" . $author . "</i></td>\n" .
3672 # originally git_history used chop_str($co{'title'}, 50)
3673 print format_subject_html
($co{'title'}, $co{'title_short'},
3674 href
(action
=>"commit", hash
=>$commit), $ref);
3676 "<td class=\"link\">" .
3677 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3678 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3680 if ($ftype eq 'blob') {
3681 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3682 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3683 if (defined $blob_current && defined $blob_parent &&
3684 $blob_current ne $blob_parent) {
3686 $cgi->a({-href
=> href
(action
=>"blobdiff",
3687 hash
=>$blob_current, hash_parent
=>$blob_parent,
3688 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3689 file_name
=>$file_name)},
3696 if (defined $extra) {
3698 "<td colspan=\"4\">$extra</td>\n" .
3705 # uses global variable $project
3706 my ($taglist, $from, $to, $extra) = @_;
3707 $from = 0 unless defined $from;
3708 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3710 print "<table class=\"tags\">\n";
3712 for (my $i = $from; $i <= $to; $i++) {
3713 my $entry = $taglist->[$i];
3715 my $comment = $tag{'subject'};
3717 if (defined $comment) {
3718 $comment_short = chop_str
($comment, 30, 5);
3721 print "<tr class=\"dark\">\n";
3723 print "<tr class=\"light\">\n";
3726 if (defined $tag{'age'}) {
3727 print "<td><i>$tag{'age'}</i></td>\n";
3729 print "<td></td>\n";
3732 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3733 -class => "list name"}, esc_html
($tag{'name'})) .
3736 if (defined $comment) {
3737 print format_subject_html
($comment, $comment_short,
3738 href
(action
=>"tag", hash
=>$tag{'id'}));
3741 "<td class=\"selflink\">";
3742 if ($tag{'type'} eq "tag") {
3743 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3748 "<td class=\"link\">" . " | " .
3749 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3750 if ($tag{'reftype'} eq "commit") {
3751 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3752 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3753 } elsif ($tag{'reftype'} eq "blob") {
3754 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3759 if (defined $extra) {
3761 "<td colspan=\"5\">$extra</td>\n" .
3767 sub git_heads_body
{
3768 # uses global variable $project
3769 my ($headlist, $head, $from, $to, $extra) = @_;
3770 $from = 0 unless defined $from;
3771 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3773 print "<table class=\"heads\">\n";
3775 for (my $i = $from; $i <= $to; $i++) {
3776 my $entry = $headlist->[$i];
3778 my $curr = $ref{'id'} eq $head;
3780 print "<tr class=\"dark\">\n";
3782 print "<tr class=\"light\">\n";
3785 print "<td><i>$ref{'age'}</i></td>\n" .
3786 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3787 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3788 -class => "list name"},esc_html
($ref{'name'})) .
3790 "<td class=\"link\">" .
3791 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3792 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3793 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3797 if (defined $extra) {
3799 "<td colspan=\"3\">$extra</td>\n" .
3805 sub git_search_grep_body
{
3806 my ($commitlist, $from, $to, $extra) = @_;
3807 $from = 0 unless defined $from;
3808 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3810 print "<table class=\"commit_search\">\n";
3812 for (my $i = $from; $i <= $to; $i++) {
3813 my %co = %{$commitlist->[$i]};
3817 my $commit = $co{'id'};
3819 print "<tr class=\"dark\">\n";
3821 print "<tr class=\"light\">\n";
3824 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3825 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3826 "<td><i>" . $author . "</i></td>\n" .
3828 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3829 -class => "list subject"},
3830 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3831 my $comment = $co{'comment'};
3832 foreach my $line (@
$comment) {
3833 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3834 my ($lead, $match, $trail) = ($1, $2, $3);
3835 $match = chop_str
($match, 70, 5, 'center');
3836 my $contextlen = int((80 - length($match))/2);
3837 $contextlen = 30 if ($contextlen > 30);
3838 $lead = chop_str
($lead, $contextlen, 10, 'left');
3839 $trail = chop_str
($trail, $contextlen, 10, 'right');
3841 $lead = esc_html
($lead);
3842 $match = esc_html
($match);
3843 $trail = esc_html
($trail);
3845 print "$lead<span class=\"match\">$match</span>$trail<br />";
3849 "<td class=\"link\">" .
3850 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3852 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3854 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3858 if (defined $extra) {
3860 "<td colspan=\"3\">$extra</td>\n" .
3866 ## ======================================================================
3867 ## ======================================================================
3870 sub git_project_list
{
3871 my $order = $cgi->param('o');
3872 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3873 die_error
(undef, "Unknown order parameter");
3876 my @list = git_get_projects_list
();
3878 die_error
(undef, "No projects found");
3882 if (-f
$home_text) {
3883 print "<div class=\"index_include\">\n";
3884 open (my $fd, $home_text);
3889 git_project_list_body
(\
@list, $order);
3894 my $order = $cgi->param('o');
3895 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3896 die_error
(undef, "Unknown order parameter");
3899 my @list = git_get_projects_list
($project);
3901 die_error
(undef, "No forks found");
3905 git_print_page_nav
('','');
3906 git_print_header_div
('summary', "$project forks");
3907 git_project_list_body
(\
@list, $order);
3911 sub git_project_index
{
3912 my @projects = git_get_projects_list
($project);
3915 -type
=> 'text/plain',
3916 -charset
=> 'utf-8',
3917 -content_disposition
=> 'inline; filename="index.aux"');
3919 foreach my $pr (@projects) {
3920 if (!exists $pr->{'owner'}) {
3921 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3924 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3925 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3926 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3927 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3931 print "$path $owner\n";
3936 my $descr = git_get_project_description
($project) || "none";
3937 my %co = parse_commit
("HEAD");
3938 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3939 my $head = $co{'id'};
3941 my $owner = git_get_project_owner
($project);
3943 my $refs = git_get_references
();
3944 # These get_*_list functions return one more to allow us to see if
3945 # there are more ...
3946 my @taglist = git_get_tags_list
(16);
3947 my @headlist = git_get_heads_list
(16);
3949 my ($check_forks) = gitweb_check_feature
('forks');
3952 @forklist = git_get_projects_list
($project);
3956 git_print_page_nav
('summary','', $head);
3958 print "<div class=\"title\"> </div>\n";
3959 print "<table class=\"projects_list\">\n" .
3960 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3961 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3962 if (defined $cd{'rfc2822'}) {
3963 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3966 # use per project git URL list in $projectroot/$project/cloneurl
3967 # or make project git URL from git base URL and project name
3968 my $url_tag = "URL";
3969 my @url_list = git_get_project_url_list
($project);
3970 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3971 foreach my $git_url (@url_list) {
3972 next unless $git_url;
3973 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3978 if (-s
"$projectroot/$project/README.html") {
3979 if (open my $fd, "$projectroot/$project/README.html") {
3980 print "<div class=\"title\">readme</div>\n" .
3981 "<div class=\"readme\">\n";
3982 print $_ while (<$fd>);
3983 print "\n</div>\n"; # class="readme"
3988 # we need to request one more than 16 (0..15) to check if
3990 my @commitlist = $head ? parse_commits
($head, 17) : ();
3992 git_print_header_div
('shortlog');
3993 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3994 $#commitlist <= 15 ?
undef :
3995 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3999 git_print_header_div
('tags');
4000 git_tags_body
(\
@taglist, 0, 15,
4001 $#taglist <= 15 ?
undef :
4002 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4006 git_print_header_div
('heads');
4007 git_heads_body
(\
@headlist, $head, 0, 15,
4008 $#headlist <= 15 ?
undef :
4009 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4013 git_print_header_div
('forks');
4014 git_project_list_body
(\
@forklist, undef, 0, 15,
4015 $#forklist <= 15 ?
undef :
4016 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4024 my $head = git_get_head_hash
($project);
4026 git_print_page_nav
('','', $head,undef,$head);
4027 my %tag = parse_tag
($hash);
4030 die_error
(undef, "Unknown tag object");
4033 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4034 print "<div class=\"title_text\">\n" .
4035 "<table class=\"object_header\">\n" .
4037 "<td>object</td>\n" .
4038 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4039 $tag{'object'}) . "</td>\n" .
4040 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4041 $tag{'type'}) . "</td>\n" .
4043 if (defined($tag{'author'})) {
4044 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4045 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4046 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4047 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4050 print "</table>\n\n" .
4052 print "<div class=\"page_body\">";
4053 my $comment = $tag{'comment'};
4054 foreach my $line (@
$comment) {
4056 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4066 my ($have_blame) = gitweb_check_feature
('blame');
4068 die_error
('403 Permission denied', "Permission denied");
4070 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4071 $hash_base ||= git_get_head_hash
($project);
4072 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4073 my %co = parse_commit
($hash_base)
4074 or die_error
(undef, "Reading commit failed");
4075 if (!defined $hash) {
4076 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4077 or die_error
(undef, "Error looking up file");
4079 $ftype = git_get_type
($hash);
4080 if ($ftype !~ "blob") {
4081 die_error
('400 Bad Request', "Object is not a blob");
4083 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4084 $file_name, $hash_base)
4085 or die_error
(undef, "Open git-blame failed");
4088 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4091 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4094 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4096 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4097 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4098 git_print_page_path
($file_name, $ftype, $hash_base);
4099 my @rev_color = (qw(light2 dark2));
4100 my $num_colors = scalar(@rev_color);
4101 my $current_color = 0;
4104 <div class="page_body">
4105 <table class="blame">
4106 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4111 last unless defined $_;
4112 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4113 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4114 if (!exists $metainfo{$full_rev}) {
4115 $metainfo{$full_rev} = {};
4117 my $meta = $metainfo{$full_rev};
4120 if (/^(\S+) (.*)$/) {
4126 my $rev = substr($full_rev, 0, 8);
4127 my $author = $meta->{'author'};
4128 my %date = parse_date
($meta->{'author-time'},
4129 $meta->{'author-tz'});
4130 my $date = $date{'iso-tz'};
4132 $current_color = ++$current_color % $num_colors;
4134 print "<tr class=\"$rev_color[$current_color]\">\n";
4136 print "<td class=\"sha1\"";
4137 print " title=\"". esc_html
($author) . ", $date\"";
4138 print " rowspan=\"$group_size\"" if ($group_size > 1);
4140 print $cgi->a({-href
=> href
(action
=>"commit",
4142 file_name
=>$file_name)},
4146 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4147 or die_error
(undef, "Open git-rev-parse failed");
4148 my $parent_commit = <$dd>;
4150 chomp($parent_commit);
4151 my $blamed = href
(action
=> 'blame',
4152 file_name
=> $meta->{'filename'},
4153 hash_base
=> $parent_commit);
4154 print "<td class=\"linenr\">";
4155 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4157 -class => "linenr" },
4160 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4166 or print "Reading blob failed\n";
4173 my ($have_blame) = gitweb_check_feature
('blame');
4175 die_error
('403 Permission denied', "Permission denied");
4177 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4178 $hash_base ||= git_get_head_hash
($project);
4179 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4180 my %co = parse_commit
($hash_base)
4181 or die_error
(undef, "Reading commit failed");
4182 if (!defined $hash) {
4183 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4184 or die_error
(undef, "Error lookup file");
4186 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4187 or die_error
(undef, "Open git-annotate failed");
4190 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4193 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4196 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4198 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4199 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4200 git_print_page_path
($file_name, 'blob', $hash_base);
4201 print "<div class=\"page_body\">\n";
4203 <table class="blame">
4212 my @line_class = (qw(light dark));
4213 my $line_class_len = scalar (@line_class);
4214 my $line_class_num = $#line_class;
4215 while (my $line = <$fd>) {
4227 $line_class_num = ($line_class_num + 1) % $line_class_len;
4229 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4236 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4239 $short_rev = substr ($long_rev, 0, 8);
4240 $age = time () - $time;
4241 $age_str = age_string
($age);
4242 $age_str =~ s/ / /g;
4243 $age_class = age_class
($age);
4244 $author = esc_html
($author);
4245 $author =~ s/ / /g;
4247 $data = untabify
($data);
4248 $data = esc_html
($data);
4251 <tr class="$line_class[$line_class_num]">
4252 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4253 <td class="$age_class">$age_str</td>
4255 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4256 <td class="pre">$data</td>
4259 } # while (my $line = <$fd>)
4260 print "</table>\n\n";
4262 or print "Reading blob failed.\n";
4268 my $head = git_get_head_hash
($project);
4270 git_print_page_nav
('','', $head,undef,$head);
4271 git_print_header_div
('summary', $project);
4273 my @tagslist = git_get_tags_list
();
4275 git_tags_body
(\
@tagslist);
4281 my $head = git_get_head_hash
($project);
4283 git_print_page_nav
('','', $head,undef,$head);
4284 git_print_header_div
('summary', $project);
4286 my @headslist = git_get_heads_list
();
4288 git_heads_body
(\
@headslist, $head);
4293 sub git_blob_plain
{
4296 if (!defined $hash) {
4297 if (defined $file_name) {
4298 my $base = $hash_base || git_get_head_hash
($project);
4299 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4300 or die_error
(undef, "Error lookup file");
4302 die_error
(undef, "No file name defined");
4304 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4305 # blobs defined by non-textual hash id's can be cached
4310 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4311 or die_error
(undef, "Couldn't cat $file_name, $hash");
4313 $type ||= blob_mimetype
($fd, $file_name);
4315 # save as filename, even when no $file_name is given
4316 my $save_as = "$hash";
4317 if (defined $file_name) {
4318 $save_as = $file_name;
4319 } elsif ($type =~ m/^text\//) {
4326 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4328 binmode STDOUT
, ':raw';
4330 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4338 if (!defined $hash) {
4339 if (defined $file_name) {
4340 my $base = $hash_base || git_get_head_hash
($project);
4341 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4342 or die_error
(undef, "Error lookup file");
4344 die_error
(undef, "No file name defined");
4346 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4347 # blobs defined by non-textual hash id's can be cached
4351 my ($have_blame) = gitweb_check_feature
('blame');
4352 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4353 or die_error
(undef, "Couldn't cat $file_name, $hash");
4354 my $mimetype = blob_mimetype
($fd, $file_name);
4355 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4357 return git_blob_plain
($mimetype);
4359 # we can have blame only for text/* mimetype
4360 $have_blame &&= ($mimetype =~ m!^text/!);
4362 git_header_html
(undef, $expires);
4363 my $formats_nav = '';
4364 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4365 if (defined $file_name) {
4368 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4373 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4376 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4379 $cgi->a({-href
=> href
(action
=>"blob",
4380 hash_base
=>"HEAD", file_name
=>$file_name)},
4384 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4387 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4388 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4390 print "<div class=\"page_nav\">\n" .
4391 "<br/><br/></div>\n" .
4392 "<div class=\"title\">$hash</div>\n";
4394 git_print_page_path
($file_name, "blob", $hash_base);
4395 print "<div class=\"page_body\">\n";
4396 if ($mimetype =~ m!^image/!) {
4397 print qq!<img type
="$mimetype"!;
4399 print qq! alt
="$file_name" title
="$file_name"!;
4402 href(action=>"blob_plain
", hash=>$hash,
4403 hash_base=>$hash_base, file_name=>$file_name) .
4407 while (my $line = <$fd>) {
4410 $line = untabify
($line);
4411 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4412 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4416 or print "Reading blob failed.\n";
4422 if (!defined $hash_base) {
4423 $hash_base = "HEAD";
4425 if (!defined $hash) {
4426 if (defined $file_name) {
4427 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4433 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4434 or die_error
(undef, "Open git-ls-tree failed");
4435 my @entries = map { chomp; $_ } <$fd>;
4436 close $fd or die_error
(undef, "Reading tree failed");
4439 my $refs = git_get_references
();
4440 my $ref = format_ref_marker
($refs, $hash_base);
4443 my ($have_blame) = gitweb_check_feature
('blame');
4444 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4446 if (defined $file_name) {
4448 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4450 $cgi->a({-href
=> href
(action
=>"tree",
4451 hash_base
=>"HEAD", file_name
=>$file_name)},
4454 my $snapshot_links = format_snapshot_links
($hash);
4455 if (defined $snapshot_links) {
4456 # FIXME: Should be available when we have no hash base as well.
4457 push @views_nav, $snapshot_links;
4459 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4460 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4463 print "<div class=\"page_nav\">\n";
4464 print "<br/><br/></div>\n";
4465 print "<div class=\"title\">$hash</div>\n";
4467 if (defined $file_name) {
4468 $basedir = $file_name;
4469 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4473 git_print_page_path
($file_name, 'tree', $hash_base);
4474 print "<div class=\"page_body\">\n";
4475 print "<table class=\"tree\">\n";
4477 # '..' (top directory) link if possible
4478 if (defined $hash_base &&
4479 defined $file_name && $file_name =~ m![^/]+$!) {
4481 print "<tr class=\"dark\">\n";
4483 print "<tr class=\"light\">\n";
4487 my $up = $file_name;
4488 $up =~ s!/?[^/]+$!!;
4489 undef $up unless $up;
4490 # based on git_print_tree_entry
4491 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4492 print '<td class="list">';
4493 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4497 print "<td class=\"link\"></td>\n";
4501 foreach my $line (@entries) {
4502 my %t = parse_ls_tree_line
($line, -z
=> 1);
4505 print "<tr class=\"dark\">\n";
4507 print "<tr class=\"light\">\n";
4511 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4515 print "</table>\n" .
4521 my @supported_fmts = gitweb_check_feature
('snapshot');
4522 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4524 my $format = $cgi->param('sf');
4525 if (!@supported_fmts) {
4526 die_error
('403 Permission denied', "Permission denied");
4528 # default to first supported snapshot format
4529 $format ||= $supported_fmts[0];
4530 if ($format !~ m/^[a-z0-9]+$/) {
4531 die_error
(undef, "Invalid snapshot format parameter");
4532 } elsif (!exists($known_snapshot_formats{$format})) {
4533 die_error
(undef, "Unknown snapshot format");
4534 } elsif (!grep($_ eq $format, @supported_fmts)) {
4535 die_error
(undef, "Unsupported snapshot format");
4538 if (!defined $hash) {
4539 $hash = git_get_head_hash
($project);
4542 my $git_command = git_cmd_str
();
4543 my $name = $project;
4544 $name =~ s
,([^/])/*\
.git
$,$1,;
4545 $name = basename
($name);
4546 my $filename = to_utf8
($name);
4547 $name =~ s/\047/\047\\\047\047/g;
4549 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4550 $cmd = "$git_command archive " .
4551 "--format=$known_snapshot_formats{$format}{'format'} " .
4552 "--prefix=\'$name\'/ $hash";
4553 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4554 $cmd .= ' | ' . join ' ', @
{$known_snapshot_formats{$format}{'compressor'}};
4558 -type
=> $known_snapshot_formats{$format}{'type'},
4559 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4560 -status
=> '200 OK');
4562 open my $fd, "-|", $cmd
4563 or die_error
(undef, "Execute git-archive failed");
4564 binmode STDOUT
, ':raw';
4566 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4571 my $head = git_get_head_hash
($project);
4572 if (!defined $hash) {
4575 if (!defined $page) {
4578 my $refs = git_get_references
();
4580 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4582 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4585 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4588 my %co = parse_commit
($hash);
4590 git_print_header_div
('summary', $project);
4591 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4593 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4594 for (my $i = 0; $i <= $to; $i++) {
4595 my %co = %{$commitlist[$i]};
4597 my $commit = $co{'id'};
4598 my $ref = format_ref_marker
($refs, $commit);
4599 my %ad = parse_date
($co{'author_epoch'});
4600 git_print_header_div
('commit',
4601 "<span class=\"age\">$co{'age_string'}</span>" .
4602 esc_html
($co{'title'}) . $ref,
4604 print "<div class=\"title_text\">\n" .
4605 "<div class=\"log_link\">\n" .
4606 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4608 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4610 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4613 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4616 print "<div class=\"log_body\">\n";
4617 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4620 if ($#commitlist >= 100) {
4621 print "<div class=\"page_nav\">\n";
4622 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4623 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4630 $hash ||= $hash_base || "HEAD";
4631 my %co = parse_commit
($hash);
4633 die_error
(undef, "Unknown commit object");
4635 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4636 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4638 my $parent = $co{'parent'};
4639 my $parents = $co{'parents'}; # listref
4641 # we need to prepare $formats_nav before any parameter munging
4643 if (!defined $parent) {
4645 $formats_nav .= '(initial)';
4646 } elsif (@
$parents == 1) {
4647 # single parent commit
4650 $cgi->a({-href
=> href
(action
=>"commit",
4652 esc_html
(substr($parent, 0, 7))) .
4659 $cgi->a({-href
=> href
(action
=>"commit",
4661 esc_html
(substr($_, 0, 7)));
4666 if (!defined $parent) {
4670 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4672 (@
$parents <= 1 ?
$parent : '-c'),
4674 or die_error
(undef, "Open git-diff-tree failed");
4675 @difftree = map { chomp; $_ } <$fd>;
4676 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4678 # non-textual hash id's can be cached
4680 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4683 my $refs = git_get_references
();
4684 my $ref = format_ref_marker
($refs, $co{'id'});
4686 git_header_html
(undef, $expires);
4687 git_print_page_nav
('commit', '',
4688 $hash, $co{'tree'}, $hash,
4691 if (defined $co{'parent'}) {
4692 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4694 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4696 print "<div class=\"title_text\">\n" .
4697 "<table class=\"object_header\">\n";
4698 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4700 "<td></td><td> $ad{'rfc2822'}";
4701 if ($ad{'hour_local'} < 6) {
4702 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4703 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4705 printf(" (%02d:%02d %s)",
4706 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4710 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4711 print "<tr><td></td><td> $cd{'rfc2822'}" .
4712 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4714 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4717 "<td class=\"sha1\">" .
4718 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4719 class => "list"}, $co{'tree'}) .
4721 "<td class=\"link\">" .
4722 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4724 my $snapshot_links = format_snapshot_links
($hash);
4725 if (defined $snapshot_links) {
4726 print " | " . $snapshot_links;
4731 foreach my $par (@
$parents) {
4734 "<td class=\"sha1\">" .
4735 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4736 class => "list"}, $par) .
4738 "<td class=\"link\">" .
4739 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4741 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4748 print "<div class=\"page_body\">\n";
4749 git_print_log
($co{'comment'});
4752 git_difftree_body
(\
@difftree, $hash, @
$parents);
4758 # object is defined by:
4759 # - hash or hash_base alone
4760 # - hash_base and file_name
4763 # - hash or hash_base alone
4764 if ($hash || ($hash_base && !defined $file_name)) {
4765 my $object_id = $hash || $hash_base;
4767 my $git_command = git_cmd_str
();
4768 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4769 or die_error
('404 Not Found', "Object does not exist");
4773 or die_error
('404 Not Found', "Object does not exist");
4775 # - hash_base and file_name
4776 } elsif ($hash_base && defined $file_name) {
4777 $file_name =~ s
,/+$,,;
4779 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4780 or die_error
('404 Not Found', "Base object does not exist");
4782 # here errors should not hapen
4783 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4784 or die_error
(undef, "Open git-ls-tree failed");
4788 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4789 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4790 die_error
('404 Not Found', "File or directory for given base does not exist");
4795 die_error
('404 Not Found', "Not enough information to find object");
4798 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4799 hash
=>$hash, hash_base
=>$hash_base,
4800 file_name
=>$file_name),
4801 -status
=> '302 Found');
4805 my $format = shift || 'html';
4812 # preparing $fd and %diffinfo for git_patchset_body
4814 if (defined $hash_base && defined $hash_parent_base) {
4815 if (defined $file_name) {
4817 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4818 $hash_parent_base, $hash_base,
4819 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4820 or die_error
(undef, "Open git-diff-tree failed");
4821 @difftree = map { chomp; $_ } <$fd>;
4823 or die_error
(undef, "Reading git-diff-tree failed");
4825 or die_error
('404 Not Found', "Blob diff not found");
4827 } elsif (defined $hash &&
4828 $hash =~ /[0-9a-fA-F]{40}/) {
4829 # try to find filename from $hash
4831 # read filtered raw output
4832 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4833 $hash_parent_base, $hash_base, "--"
4834 or die_error
(undef, "Open git-diff-tree failed");
4836 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4838 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4839 map { chomp; $_ } <$fd>;
4841 or die_error
(undef, "Reading git-diff-tree failed");
4843 or die_error
('404 Not Found', "Blob diff not found");
4846 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4849 if (@difftree > 1) {
4850 die_error
('404 Not Found', "Ambiguous blob diff specification");
4853 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4854 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4855 $file_name ||= $diffinfo{'to_file'};
4857 $hash_parent ||= $diffinfo{'from_id'};
4858 $hash ||= $diffinfo{'to_id'};
4860 # non-textual hash id's can be cached
4861 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4862 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4867 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4868 '-p', ($format eq 'html' ?
"--full-index" : ()),
4869 $hash_parent_base, $hash_base,
4870 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4871 or die_error
(undef, "Open git-diff-tree failed");
4874 # old/legacy style URI
4875 if (!%diffinfo && # if new style URI failed
4876 defined $hash && defined $hash_parent) {
4877 # fake git-diff-tree raw output
4878 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4879 $diffinfo{'from_id'} = $hash_parent;
4880 $diffinfo{'to_id'} = $hash;
4881 if (defined $file_name) {
4882 if (defined $file_parent) {
4883 $diffinfo{'status'} = '2';
4884 $diffinfo{'from_file'} = $file_parent;
4885 $diffinfo{'to_file'} = $file_name;
4886 } else { # assume not renamed
4887 $diffinfo{'status'} = '1';
4888 $diffinfo{'from_file'} = $file_name;
4889 $diffinfo{'to_file'} = $file_name;
4891 } else { # no filename given
4892 $diffinfo{'status'} = '2';
4893 $diffinfo{'from_file'} = $hash_parent;
4894 $diffinfo{'to_file'} = $hash;
4897 # non-textual hash id's can be cached
4898 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4899 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4904 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4905 '-p', ($format eq 'html' ?
"--full-index" : ()),
4906 $hash_parent, $hash, "--"
4907 or die_error
(undef, "Open git-diff failed");
4909 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4914 if ($format eq 'html') {
4916 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4918 git_header_html
(undef, $expires);
4919 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4920 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4921 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4923 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4924 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4926 if (defined $file_name) {
4927 git_print_page_path
($file_name, "blob", $hash_base);
4929 print "<div class=\"page_path\"></div>\n";
4932 } elsif ($format eq 'plain') {
4934 -type
=> 'text/plain',
4935 -charset
=> 'utf-8',
4936 -expires
=> $expires,
4937 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4939 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4942 die_error
(undef, "Unknown blobdiff format");
4946 if ($format eq 'html') {
4947 print "<div class=\"page_body\">\n";
4949 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4952 print "</div>\n"; # class="page_body"
4956 while (my $line = <$fd>) {
4957 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4958 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4962 last if $line =~ m!^\+\+\+!;
4970 sub git_blobdiff_plain
{
4971 git_blobdiff
('plain');
4974 sub git_commitdiff
{
4975 my $format = shift || 'html';
4976 $hash ||= $hash_base || "HEAD";
4977 my %co = parse_commit
($hash);
4979 die_error
(undef, "Unknown commit object");
4982 # choose format for commitdiff for merge
4983 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4984 $hash_parent = '--cc';
4986 # we need to prepare $formats_nav before almost any parameter munging
4988 if ($format eq 'html') {
4990 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4993 if (defined $hash_parent &&
4994 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4995 # commitdiff with two commits given
4996 my $hash_parent_short = $hash_parent;
4997 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4998 $hash_parent_short = substr($hash_parent, 0, 7);
5002 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5003 if ($co{'parents'}[$i] eq $hash_parent) {
5004 $formats_nav .= ' parent ' . ($i+1);
5008 $formats_nav .= ': ' .
5009 $cgi->a({-href
=> href
(action
=>"commitdiff",
5010 hash
=>$hash_parent)},
5011 esc_html
($hash_parent_short)) .
5013 } elsif (!$co{'parent'}) {
5015 $formats_nav .= ' (initial)';
5016 } elsif (scalar @
{$co{'parents'}} == 1) {
5017 # single parent commit
5020 $cgi->a({-href
=> href
(action
=>"commitdiff",
5021 hash
=>$co{'parent'})},
5022 esc_html
(substr($co{'parent'}, 0, 7))) .
5026 if ($hash_parent eq '--cc') {
5027 $formats_nav .= ' | ' .
5028 $cgi->a({-href
=> href
(action
=>"commitdiff",
5029 hash
=>$hash, hash_parent
=>'-c')},
5031 } else { # $hash_parent eq '-c'
5032 $formats_nav .= ' | ' .
5033 $cgi->a({-href
=> href
(action
=>"commitdiff",
5034 hash
=>$hash, hash_parent
=>'--cc')},
5040 $cgi->a({-href
=> href
(action
=>"commitdiff",
5042 esc_html
(substr($_, 0, 7)));
5043 } @
{$co{'parents'}} ) .
5048 my $hash_parent_param = $hash_parent;
5049 if (!defined $hash_parent_param) {
5050 # --cc for multiple parents, --root for parentless
5051 $hash_parent_param =
5052 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5058 if ($format eq 'html') {
5059 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5060 "--no-commit-id", "--patch-with-raw", "--full-index",
5061 $hash_parent_param, $hash, "--"
5062 or die_error
(undef, "Open git-diff-tree failed");
5064 while (my $line = <$fd>) {
5066 # empty line ends raw part of diff-tree output
5068 push @difftree, scalar parse_difftree_raw_line
($line);
5071 } elsif ($format eq 'plain') {
5072 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5073 '-p', $hash_parent_param, $hash, "--"
5074 or die_error
(undef, "Open git-diff-tree failed");
5077 die_error
(undef, "Unknown commitdiff format");
5080 # non-textual hash id's can be cached
5082 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5086 # write commit message
5087 if ($format eq 'html') {
5088 my $refs = git_get_references
();
5089 my $ref = format_ref_marker
($refs, $co{'id'});
5091 git_header_html
(undef, $expires);
5092 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5093 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5094 git_print_authorship
(\
%co);
5095 print "<div class=\"page_body\">\n";
5096 if (@
{$co{'comment'}} > 1) {
5097 print "<div class=\"log\">\n";
5098 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5099 print "</div>\n"; # class="log"
5102 } elsif ($format eq 'plain') {
5103 my $refs = git_get_references
("tags");
5104 my $tagname = git_get_rev_name_tags
($hash);
5105 my $filename = basename
($project) . "-$hash.patch";
5108 -type
=> 'text/plain',
5109 -charset
=> 'utf-8',
5110 -expires
=> $expires,
5111 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5112 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5113 print "From: " . to_utf8
($co{'author'}) . "\n";
5114 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5115 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5117 print "X-Git-Tag: $tagname\n" if $tagname;
5118 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5120 foreach my $line (@
{$co{'comment'}}) {
5121 print to_utf8
($line) . "\n";
5127 if ($format eq 'html') {
5128 my $use_parents = !defined $hash_parent ||
5129 $hash_parent eq '-c' || $hash_parent eq '--cc';
5130 git_difftree_body
(\
@difftree, $hash,
5131 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5134 git_patchset_body
($fd, \
@difftree, $hash,
5135 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5137 print "</div>\n"; # class="page_body"
5140 } elsif ($format eq 'plain') {
5144 or print "Reading git-diff-tree failed\n";
5148 sub git_commitdiff_plain
{
5149 git_commitdiff
('plain');
5153 if (!defined $hash_base) {
5154 $hash_base = git_get_head_hash
($project);
5156 if (!defined $page) {
5160 my %co = parse_commit
($hash_base);
5162 die_error
(undef, "Unknown commit object");
5165 my $refs = git_get_references
();
5166 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5168 if (!defined $hash && defined $file_name) {
5169 $hash = git_get_hash_by_path
($hash_base, $file_name);
5171 if (defined $hash) {
5172 $ftype = git_get_type
($hash);
5175 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), $file_name, "--full-history");
5177 my $paging_nav = '';
5180 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5181 file_name
=>$file_name)},
5183 $paging_nav .= " ⋅ " .
5184 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5185 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5187 $paging_nav .= "first";
5188 $paging_nav .= " ⋅ prev";
5191 if ($#commitlist >= 100) {
5193 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5194 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5195 $paging_nav .= " ⋅ $next_link";
5197 $paging_nav .= " ⋅ next";
5201 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5202 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5203 git_print_page_path
($file_name, $ftype, $hash_base);
5205 git_history_body
(\
@commitlist, 0, 99,
5206 $refs, $hash_base, $ftype, $next_link);
5212 my ($have_search) = gitweb_check_feature
('search');
5213 if (!$have_search) {
5214 die_error
('403 Permission denied', "Permission denied");
5216 if (!defined $searchtext) {
5217 die_error
(undef, "Text field empty");
5219 if (!defined $hash) {
5220 $hash = git_get_head_hash
($project);
5222 my %co = parse_commit
($hash);
5224 die_error
(undef, "Unknown commit object");
5226 if (!defined $page) {
5230 $searchtype ||= 'commit';
5231 if ($searchtype eq 'pickaxe') {
5232 # pickaxe may take all resources of your box and run for several minutes
5233 # with every query - so decide by yourself how public you make this feature
5234 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5235 if (!$have_pickaxe) {
5236 die_error
('403 Permission denied', "Permission denied");
5239 if ($searchtype eq 'grep') {
5240 my ($have_grep) = gitweb_check_feature
('grep');
5242 die_error
('403 Permission denied', "Permission denied");
5248 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5250 if ($searchtype eq 'commit') {
5251 $greptype = "--grep=";
5252 } elsif ($searchtype eq 'author') {
5253 $greptype = "--author=";
5254 } elsif ($searchtype eq 'committer') {
5255 $greptype = "--committer=";
5257 $greptype .= $searchtext;
5258 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5259 $greptype, '--fixed-strings');
5261 my $paging_nav = '';
5264 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5265 searchtext
=>$searchtext,
5266 searchtype
=>$searchtype)},
5268 $paging_nav .= " ⋅ " .
5269 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5270 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5272 $paging_nav .= "first";
5273 $paging_nav .= " ⋅ prev";
5276 if ($#commitlist >= 100) {
5278 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5279 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5280 $paging_nav .= " ⋅ $next_link";
5282 $paging_nav .= " ⋅ next";
5285 if ($#commitlist >= 100) {
5288 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5289 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5290 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5293 if ($searchtype eq 'pickaxe') {
5294 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5295 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5297 print "<table class=\"pickaxe search\">\n";
5300 my $git_command = git_cmd_str
();
5301 my $searchqtext = $searchtext;
5302 $searchqtext =~ s/'/'\\''/;
5303 open my $fd, "-|", "$git_command rev-list $hash | " .
5304 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5307 while (my $line = <$fd>) {
5308 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5311 $set{'from_id'} = $3;
5313 $set{'id'} = $set{'to_id'};
5314 if ($set{'id'} =~ m/0{40}/) {
5315 $set{'id'} = $set{'from_id'};
5317 if ($set{'id'} =~ m/0{40}/) {
5321 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5324 print "<tr class=\"dark\">\n";
5326 print "<tr class=\"light\">\n";
5329 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5330 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5331 "<td><i>" . $author . "</i></td>\n" .
5333 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5334 -class => "list subject"},
5335 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5336 while (my $setref = shift @files) {
5338 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5339 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5341 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5345 "<td class=\"link\">" .
5346 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5348 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5352 %co = parse_commit
($1);
5360 if ($searchtype eq 'grep') {
5361 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5362 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5364 print "<table class=\"grep_search\">\n";
5368 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5370 while (my $line = <$fd>) {
5372 my ($file, $lno, $ltext, $binary);
5373 last if ($matches++ > 1000);
5374 if ($line =~ /^Binary file (.+) matches$/) {
5378 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5380 if ($file ne $lastfile) {
5381 $lastfile and print "</td></tr>\n";
5383 print "<tr class=\"dark\">\n";
5385 print "<tr class=\"light\">\n";
5387 print "<td class=\"list\">".
5388 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5389 file_name
=>"$file"),
5390 -class => "list"}, esc_path
($file));
5391 print "</td><td>\n";
5395 print "<div class=\"binary\">Binary file</div>\n";
5397 $ltext = untabify
($ltext);
5398 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5399 $ltext = esc_html
($1, -nbsp
=>1);
5400 $ltext .= '<span class="match">';
5401 $ltext .= esc_html
($2, -nbsp
=>1);
5402 $ltext .= '</span>';
5403 $ltext .= esc_html
($3, -nbsp
=>1);
5405 $ltext = esc_html
($ltext, -nbsp
=>1);
5407 print "<div class=\"pre\">" .
5408 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5409 file_name
=>"$file").'#l'.$lno,
5410 -class => "linenr"}, sprintf('%4i', $lno))
5411 . ' ' . $ltext . "</div>\n";
5415 print "</td></tr>\n";
5416 if ($matches > 1000) {
5417 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5420 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5429 sub git_search_help
{
5431 git_print_page_nav
('','', $hash,$hash,$hash);
5434 <dt><b>commit</b></dt>
5435 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5437 my ($have_grep) = gitweb_check_feature
('grep');
5440 <dt><b>grep</b></dt>
5441 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5442 a different one) are searched for the given
5443 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5444 (POSIX extended) and the matches are listed. On large
5445 trees, this search can take a while and put some strain on the server, so please use it with
5446 some consideration.</dd>
5450 <dt><b>author</b></dt>
5451 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5452 <dt><b>committer</b></dt>
5453 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5455 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5456 if ($have_pickaxe) {
5458 <dt><b>pickaxe</b></dt>
5459 <dd>All commits that caused the string to appear or disappear from any file (changes that
5460 added, removed or "modified" the string) will be listed. This search can take a while and
5461 takes a lot of strain on the server, so please use it wisely.</dd>
5469 my $head = git_get_head_hash
($project);
5470 if (!defined $hash) {
5473 if (!defined $page) {
5476 my $refs = git_get_references
();
5478 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5480 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5482 if ($#commitlist >= 100) {
5484 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5485 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5489 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5490 git_print_header_div
('summary', $project);
5492 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5497 ## ......................................................................
5498 ## feeds (RSS, Atom; OPML)
5501 my $format = shift || 'atom';
5502 my ($have_blame) = gitweb_check_feature
('blame');
5504 # Atom: http://www.atomenabled.org/developers/syndication/
5505 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5506 if ($format ne 'rss' && $format ne 'atom') {
5507 die_error
(undef, "Unknown web feed format");
5510 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5511 my $head = $hash || 'HEAD';
5512 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5516 my $content_type = "application/$format+xml";
5517 if (defined $cgi->http('HTTP_ACCEPT') &&
5518 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5519 # browser (feed reader) prefers text/xml
5520 $content_type = 'text/xml';
5522 if (defined($commitlist[0])) {
5523 %latest_commit = %{$commitlist[0]};
5524 %latest_date = parse_date
($latest_commit{'author_epoch'});
5526 -type
=> $content_type,
5527 -charset
=> 'utf-8',
5528 -last_modified
=> $latest_date{'rfc2822'});
5531 -type
=> $content_type,
5532 -charset
=> 'utf-8');
5535 # Optimization: skip generating the body if client asks only
5536 # for Last-Modified date.
5537 return if ($cgi->request_method() eq 'HEAD');
5540 my $title = "$site_name - $project/$action";
5541 my $feed_type = 'log';
5542 if (defined $hash) {
5543 $title .= " - '$hash'";
5544 $feed_type = 'branch log';
5545 if (defined $file_name) {
5546 $title .= " :: $file_name";
5547 $feed_type = 'history';
5549 } elsif (defined $file_name) {
5550 $title .= " - $file_name";
5551 $feed_type = 'history';
5553 $title .= " $feed_type";
5554 my $descr = git_get_project_description
($project);
5555 if (defined $descr) {
5556 $descr = esc_html
($descr);
5558 $descr = "$project " .
5559 ($format eq 'rss' ?
'RSS' : 'Atom') .
5562 my $owner = git_get_project_owner
($project);
5563 $owner = esc_html
($owner);
5567 if (defined $file_name) {
5568 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5569 } elsif (defined $hash) {
5570 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5572 $alt_url = href
(-full
=>1, action
=>"summary");
5574 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5575 if ($format eq 'rss') {
5577 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5580 print "<title>$title</title>\n" .
5581 "<link>$alt_url</link>\n" .
5582 "<description>$descr</description>\n" .
5583 "<language>en</language>\n";
5584 } elsif ($format eq 'atom') {
5586 <feed xmlns="http://www.w3.org/2005/Atom">
5588 print "<title>$title</title>\n" .
5589 "<subtitle>$descr</subtitle>\n" .
5590 '<link rel="alternate" type="text/html" href="' .
5591 $alt_url . '" />' . "\n" .
5592 '<link rel="self" type="' . $content_type . '" href="' .
5593 $cgi->self_url() . '" />' . "\n" .
5594 "<id>" . href
(-full
=>1) . "</id>\n" .
5595 # use project owner for feed author
5596 "<author><name>$owner</name></author>\n";
5597 if (defined $favicon) {
5598 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5600 if (defined $logo_url) {
5601 # not twice as wide as tall: 72 x 27 pixels
5602 print "<logo>" . esc_url
($logo) . "</logo>\n";
5604 if (! %latest_date) {
5605 # dummy date to keep the feed valid until commits trickle in:
5606 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5608 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5613 for (my $i = 0; $i <= $#commitlist; $i++) {
5614 my %co = %{$commitlist[$i]};
5615 my $commit = $co{'id'};
5616 # we read 150, we always show 30 and the ones more recent than 48 hours
5617 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5620 my %cd = parse_date
($co{'author_epoch'});
5622 # get list of changed files
5623 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5624 $co{'parent'} || "--root",
5625 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5627 my @difftree = map { chomp; $_ } <$fd>;
5631 # print element (entry, item)
5632 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5633 if ($format eq 'rss') {
5635 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5636 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5637 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5638 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5639 "<link>$co_url</link>\n" .
5640 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5641 "<content:encoded>" .
5643 } elsif ($format eq 'atom') {
5645 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5646 "<updated>$cd{'iso-8601'}</updated>\n" .
5648 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5649 if ($co{'author_email'}) {
5650 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5652 print "</author>\n" .
5653 # use committer for contributor
5655 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5656 if ($co{'committer_email'}) {
5657 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5659 print "</contributor>\n" .
5660 "<published>$cd{'iso-8601'}</published>\n" .
5661 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5662 "<id>$co_url</id>\n" .
5663 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5664 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5666 my $comment = $co{'comment'};
5668 foreach my $line (@
$comment) {
5669 $line = esc_html
($line);
5672 print "</pre><ul>\n";
5673 foreach my $difftree_line (@difftree) {
5674 my %difftree = parse_difftree_raw_line
($difftree_line);
5675 next if !$difftree{'from_id'};
5677 my $file = $difftree{'file'} || $difftree{'to_file'};
5681 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5682 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5683 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5684 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5685 -title
=> "diff"}, 'D');
5687 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5688 file_name
=>$file, hash_base
=>$commit),
5689 -title
=> "blame"}, 'B');
5691 # if this is not a feed of a file history
5692 if (!defined $file_name || $file_name ne $file) {
5693 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5694 file_name
=>$file, hash
=>$commit),
5695 -title
=> "history"}, 'H');
5697 $file = esc_path
($file);
5701 if ($format eq 'rss') {
5702 print "</ul>]]>\n" .
5703 "</content:encoded>\n" .
5705 } elsif ($format eq 'atom') {
5706 print "</ul>\n</div>\n" .
5713 if ($format eq 'rss') {
5714 print "</channel>\n</rss>\n";
5715 } elsif ($format eq 'atom') {
5729 my @list = git_get_projects_list
();
5731 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5733 <?xml version="1.0" encoding="utf-8"?>
5734 <opml version="1.0">
5736 <title>$site_name OPML Export</title>
5739 <outline text="git RSS feeds">
5742 foreach my $pr (@list) {
5744 my $head = git_get_head_hash
($proj{'path'});
5745 if (!defined $head) {
5748 $git_dir = "$projectroot/$proj{'path'}";
5749 my %co = parse_commit
($head);
5754 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5755 my $rss = "$my_url?p=$proj{'path'};a=rss";
5756 my $html = "$my_url?p=$proj{'path'};a=summary";
5757 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";