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;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $searchtext = $cgi->param('s');
478 if (defined $searchtext) {
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
605 hash_parent_base
=> "hpb",
610 snapshot_format
=> "sf",
611 extra_options
=> "opt",
613 my %mapping = @mapping;
615 if ($params{-replay
}) {
616 while (my ($name, $symbol) = each %mapping) {
617 if (!exists $params{$name}) {
618 # to allow for multivalued params we use arrayref form
619 $params{$name} = [ $cgi->param($symbol) ];
624 $params{'project'} = $project unless exists $params{'project'};
626 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
628 # use PATH_INFO for project name
629 $href .= "/$params{'project'}" if defined $params{'project'};
630 delete $params{'project'};
632 # Summary just uses the project path URL
633 if (defined $params{'action'} && $params{'action'} eq 'summary') {
634 delete $params{'action'};
638 # now encode the parameters explicitly
640 for (my $i = 0; $i < @mapping; $i += 2) {
641 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
642 if (defined $params{$name}) {
643 if (ref($params{$name}) eq "ARRAY") {
644 foreach my $par (@{$params{$name}}) {
645 push @result, $symbol . "=" . esc_param
($par);
648 push @result, $symbol . "=" . esc_param
($params{$name});
652 $href .= "?" . join(';', @result) if scalar @result;
658 ## ======================================================================
659 ## validation, quoting/unquoting and escaping
661 sub validate_pathname
{
662 my $input = shift || return undef;
664 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
665 # at the beginning, at the end, and between slashes.
666 # also this catches doubled slashes
667 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
671 if ($input =~ m!\0!) {
677 sub validate_refname
{
678 my $input = shift || return undef;
680 # textual hashes are O.K.
681 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
684 # it must be correct pathname
685 $input = validate_pathname
($input)
687 # restrictions on ref name according to git-check-ref-format
688 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
694 # decode sequences of octets in utf8 into Perl's internal form,
695 # which is utf-8 with utf8 flag set if needed. gitweb writes out
696 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
700 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
704 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
708 # quote unsafe chars, but keep the slash, even when it's not
709 # correct, but quoted slashes look too horrible in bookmarks
712 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
718 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
721 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
727 # replace invalid utf8 character with SUBSTITUTION sequence
732 $str = to_utf8
($str);
733 $str = $cgi->escapeHTML($str);
734 if ($opts{'-nbsp'}) {
735 $str =~ s/ / /g;
737 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
741 # quote control characters and escape filename to HTML
746 $str = to_utf8
($str);
747 $str = $cgi->escapeHTML($str);
748 if ($opts{'-nbsp'}) {
749 $str =~ s/ / /g;
751 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
755 # Make control characters "printable", using character escape codes (CEC)
758 my %es = ( # character escape codes, aka escape sequences
759 "\t" => '\t', # tab (HT)
760 "\n" => '\n', # line feed (LF)
761 "\r" => '\r', # carrige return (CR)
762 "\f" => '\f', # form feed (FF)
763 "\b" => '\b', # backspace (BS)
764 "\a" => '\a', # alarm (bell) (BEL)
765 "\e" => '\e', # escape (ESC)
766 "\013" => '\v', # vertical tab (VT)
767 "\000" => '\0', # nul character (NUL)
769 my $chr = ( (exists $es{$cntrl})
771 : sprintf('\%03o', ord($cntrl)) );
772 return "<span class=\"cntrl\">$chr</span>";
775 # Alternatively use unicode control pictures codepoints,
776 # Unicode "printable representation" (PR)
779 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
780 return "<span class=\"cntrl\">$chr</span>";
783 # git may return quoted and escaped filenames
789 my %es = ( # character escape codes, aka escape sequences
790 't' => "\t", # tab (HT, TAB)
791 'n' => "\n", # newline (NL)
792 'r' => "\r", # return (CR)
793 'f' => "\f", # form feed (FF)
794 'b' => "\b", # backspace (BS)
795 'a' => "\a", # alarm (bell) (BEL)
796 'e' => "\e", # escape (ESC)
797 'v' => "\013", # vertical tab (VT)
800 if ($seq =~ m/^[0-7]{1,3}$/) {
801 # octal char sequence
802 return chr(oct($seq));
803 } elsif (exists $es{$seq}) {
804 # C escape sequence, aka character escape code
807 # quoted ordinary character
811 if ($str =~ m/^"(.*)"$/) {
814 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
819 # escape tabs (convert tabs to spaces)
823 while ((my $pos = index($line, "\t")) != -1) {
824 if (my $count = (8 - ($pos % 8))) {
825 my $spaces = ' ' x
$count;
826 $line =~ s/\t/$spaces/;
833 sub project_in_list
{
835 my @list = git_get_projects_list
();
836 return @list && scalar(grep { $_->{'path'} eq $project } @list);
839 ## ----------------------------------------------------------------------
840 ## HTML aware string manipulation
845 my $add_len = shift || 10;
847 # allow only $len chars, but don't cut a word if it would fit in $add_len
848 # if it doesn't fit, cut it if it's still longer than the dots we would add
849 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
852 if (length($tail) > 4) {
854 $body =~ s/&[^;]*$//; # remove chopped character entities
859 # takes the same arguments as chop_str, but also wraps a <span> around the
860 # result with a title attribute if it does get chopped. Additionally, the
861 # string is HTML-escaped.
862 sub chop_and_escape_str
{
865 my $add_len = shift || 10;
867 my $chopped = chop_str
($str, $len, $add_len);
868 if ($chopped eq $str) {
869 return esc_html
($chopped);
871 return qq{<span title="} . esc_html
($str) . qq{">} .
872 esc_html
($chopped) . qq{</span>};
876 ## ----------------------------------------------------------------------
877 ## functions returning short strings
879 # CSS class for given age value (in seconds)
885 } elsif ($age < 60*60*2) {
887 } elsif ($age < 60*60*24*2) {
894 # convert age in seconds to "nn units ago" string
899 if ($age > 60*60*24*365*2) {
900 $age_str = (int $age/60/60/24/365);
901 $age_str .= " years ago";
902 } elsif ($age > 60*60*24*(365/12)*2) {
903 $age_str = int $age/60/60/24/(365/12);
904 $age_str .= " months ago";
905 } elsif ($age > 60*60*24*7*2) {
906 $age_str = int $age/60/60/24/7;
907 $age_str .= " weeks ago";
908 } elsif ($age > 60*60*24*2) {
909 $age_str = int $age/60/60/24;
910 $age_str .= " days ago";
911 } elsif ($age > 60*60*2) {
912 $age_str = int $age/60/60;
913 $age_str .= " hours ago";
914 } elsif ($age > 60*2) {
915 $age_str = int $age/60;
916 $age_str .= " min ago";
919 $age_str .= " sec ago";
921 $age_str .= " right now";
927 S_IFINVALID
=> 0030000,
928 S_IFGITLINK
=> 0160000,
931 # submodule/subproject, a commit object reference
935 return (($mode & S_IFMT
) == S_IFGITLINK
)
938 # convert file mode in octal to symbolic file mode string
940 my $mode = oct shift;
942 if (S_ISGITLINK
($mode)) {
944 } elsif (S_ISDIR
($mode & S_IFMT
)) {
946 } elsif (S_ISLNK
($mode)) {
948 } elsif (S_ISREG
($mode)) {
949 # git cares only about the executable bit
950 if ($mode & S_IXUSR
) {
960 # convert file mode in octal to file type string
964 if ($mode !~ m/^[0-7]+$/) {
970 if (S_ISGITLINK
($mode)) {
972 } elsif (S_ISDIR
($mode & S_IFMT
)) {
974 } elsif (S_ISLNK
($mode)) {
976 } elsif (S_ISREG
($mode)) {
983 # convert file mode in octal to file type description string
987 if ($mode !~ m/^[0-7]+$/) {
993 if (S_ISGITLINK
($mode)) {
995 } elsif (S_ISDIR
($mode & S_IFMT
)) {
997 } elsif (S_ISLNK
($mode)) {
999 } elsif (S_ISREG
($mode)) {
1000 if ($mode & S_IXUSR
) {
1001 return "executable";
1011 ## ----------------------------------------------------------------------
1012 ## functions returning short HTML fragments, or transforming HTML fragments
1013 ## which don't belong to other sections
1015 # format line of commit message.
1016 sub format_log_line_html
{
1019 $line = esc_html
($line, -nbsp
=>1);
1020 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1023 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1024 -class => "text"}, $hash_text);
1025 $line =~ s/$hash_text/$link/;
1030 # format marker of refs pointing to given object
1031 sub format_ref_marker
{
1032 my ($refs, $id) = @_;
1035 if (defined $refs->{$id}) {
1036 foreach my $ref (@{$refs->{$id}}) {
1037 my ($type, $name) = qw();
1038 # e.g. tags/v2.6.11 or heads/next
1039 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1047 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1048 esc_html
($name) . "</span>";
1053 return ' <span class="refs">'. $markers . '</span>';
1059 # format, perhaps shortened and with markers, title line
1060 sub format_subject_html
{
1061 my ($long, $short, $href, $extra) = @_;
1062 $extra = '' unless defined($extra);
1064 if (length($short) < length($long)) {
1065 return $cgi->a({-href
=> $href, -class => "list subject",
1066 -title
=> to_utf8
($long)},
1067 esc_html
($short) . $extra);
1069 return $cgi->a({-href
=> $href, -class => "list subject"},
1070 esc_html
($long) . $extra);
1074 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1075 sub format_git_diff_header_line
{
1077 my $diffinfo = shift;
1078 my ($from, $to) = @_;
1080 if ($diffinfo->{'nparents'}) {
1082 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1083 if ($to->{'href'}) {
1084 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1085 esc_path
($to->{'file'}));
1086 } else { # file was deleted (no href)
1087 $line .= esc_path
($to->{'file'});
1091 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1092 if ($from->{'href'}) {
1093 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1094 'a/' . esc_path
($from->{'file'}));
1095 } else { # file was added (no href)
1096 $line .= 'a/' . esc_path
($from->{'file'});
1099 if ($to->{'href'}) {
1100 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1101 'b/' . esc_path
($to->{'file'}));
1102 } else { # file was deleted
1103 $line .= 'b/' . esc_path
($to->{'file'});
1107 return "<div class=\"diff header\">$line</div>\n";
1110 # format extended diff header line, before patch itself
1111 sub format_extended_diff_header_line
{
1113 my $diffinfo = shift;
1114 my ($from, $to) = @_;
1117 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1118 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1119 esc_path
($from->{'file'}));
1121 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1122 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1123 esc_path
($to->{'file'}));
1125 # match single <mode>
1126 if ($line =~ m/\s(\d{6})$/) {
1127 $line .= '<span class="info"> (' .
1128 file_type_long
($1) .
1132 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1133 # can match only for combined diff
1135 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1136 if ($from->{'href'}[$i]) {
1137 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1139 substr($diffinfo->{'from_id'}[$i],0,7));
1144 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1147 if ($to->{'href'}) {
1148 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1149 substr($diffinfo->{'to_id'},0,7));
1154 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1155 # can match only for ordinary diff
1156 my ($from_link, $to_link);
1157 if ($from->{'href'}) {
1158 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1159 substr($diffinfo->{'from_id'},0,7));
1161 $from_link = '0' x
7;
1163 if ($to->{'href'}) {
1164 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1165 substr($diffinfo->{'to_id'},0,7));
1169 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1170 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1173 return $line . "<br/>\n";
1176 # format from-file/to-file diff header
1177 sub format_diff_from_to_header
{
1178 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1183 #assert($line =~ m/^---/) if DEBUG;
1184 # no extra formatting for "^--- /dev/null"
1185 if (! $diffinfo->{'nparents'}) {
1186 # ordinary (single parent) diff
1187 if ($line =~ m!^--- "?a/!) {
1188 if ($from->{'href'}) {
1190 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1191 esc_path
($from->{'file'}));
1194 esc_path
($from->{'file'});
1197 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1200 # combined diff (merge commit)
1201 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1202 if ($from->{'href'}[$i]) {
1204 $cgi->a({-href
=>href
(action
=>"blobdiff",
1205 hash_parent
=>$diffinfo->{'from_id'}[$i],
1206 hash_parent_base
=>$parents[$i],
1207 file_parent
=>$from->{'file'}[$i],
1208 hash
=>$diffinfo->{'to_id'},
1210 file_name
=>$to->{'file'}),
1212 -title
=>"diff" . ($i+1)},
1215 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1216 esc_path
($from->{'file'}[$i]));
1218 $line = '--- /dev/null';
1220 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1225 #assert($line =~ m/^\+\+\+/) if DEBUG;
1226 # no extra formatting for "^+++ /dev/null"
1227 if ($line =~ m!^\+\+\+ "?b/!) {
1228 if ($to->{'href'}) {
1230 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1231 esc_path
($to->{'file'}));
1234 esc_path
($to->{'file'});
1237 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1242 # create note for patch simplified by combined diff
1243 sub format_diff_cc_simplified
{
1244 my ($diffinfo, @parents) = @_;
1247 $result .= "<div class=\"diff header\">" .
1249 if (!is_deleted
($diffinfo)) {
1250 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1252 hash
=>$diffinfo->{'to_id'},
1253 file_name
=>$diffinfo->{'to_file'}),
1255 esc_path
($diffinfo->{'to_file'}));
1257 $result .= esc_path
($diffinfo->{'to_file'});
1259 $result .= "</div>\n" . # class="diff header"
1260 "<div class=\"diff nodifferences\">" .
1262 "</div>\n"; # class="diff nodifferences"
1267 # format patch (diff) line (not to be used for diff headers)
1268 sub format_diff_line
{
1270 my ($from, $to) = @_;
1271 my $diff_class = "";
1275 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1277 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1278 if ($line =~ m/^\@{3}/) {
1279 $diff_class = " chunk_header";
1280 } elsif ($line =~ m/^\\/) {
1281 $diff_class = " incomplete";
1282 } elsif ($prefix =~ tr/+/+/) {
1283 $diff_class = " add";
1284 } elsif ($prefix =~ tr/-/-/) {
1285 $diff_class = " rem";
1288 # assume ordinary diff
1289 my $char = substr($line, 0, 1);
1291 $diff_class = " add";
1292 } elsif ($char eq '-') {
1293 $diff_class = " rem";
1294 } elsif ($char eq '@') {
1295 $diff_class = " chunk_header";
1296 } elsif ($char eq "\\") {
1297 $diff_class = " incomplete";
1300 $line = untabify
($line);
1301 if ($from && $to && $line =~ m/^\@{2} /) {
1302 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1303 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1305 $from_lines = 0 unless defined $from_lines;
1306 $to_lines = 0 unless defined $to_lines;
1308 if ($from->{'href'}) {
1309 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1310 -class=>"list"}, $from_text);
1312 if ($to->{'href'}) {
1313 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1314 -class=>"list"}, $to_text);
1316 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1317 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1318 return "<div class=\"diff$diff_class\">$line</div>\n";
1319 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1320 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1321 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1323 @from_text = split(' ', $ranges);
1324 for (my $i = 0; $i < @from_text; ++$i) {
1325 ($from_start[$i], $from_nlines[$i]) =
1326 (split(',', substr($from_text[$i], 1)), 0);
1329 $to_text = pop @from_text;
1330 $to_start = pop @from_start;
1331 $to_nlines = pop @from_nlines;
1333 $line = "<span class=\"chunk_info\">$prefix ";
1334 for (my $i = 0; $i < @from_text; ++$i) {
1335 if ($from->{'href'}[$i]) {
1336 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1337 -class=>"list"}, $from_text[$i]);
1339 $line .= $from_text[$i];
1343 if ($to->{'href'}) {
1344 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1345 -class=>"list"}, $to_text);
1349 $line .= " $prefix</span>" .
1350 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1351 return "<div class=\"diff$diff_class\">$line</div>\n";
1353 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1356 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1357 # linked. Pass the hash of the tree/commit to snapshot.
1358 sub format_snapshot_links
{
1360 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1361 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1362 my $num_fmts = @snapshot_fmts;
1363 if ($num_fmts > 1) {
1364 # A parenthesized list of links bearing format names.
1365 # e.g. "snapshot (_tar.gz_ _zip_)"
1366 return "snapshot (" . join(' ', map
1373 }, $known_snapshot_formats{$_}{'display'})
1374 , @snapshot_fmts) . ")";
1375 } elsif ($num_fmts == 1) {
1376 # A single "snapshot" link whose tooltip bears the format name.
1378 my ($fmt) = @snapshot_fmts;
1384 snapshot_format
=>$fmt
1386 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1388 } else { # $num_fmts == 0
1393 ## ----------------------------------------------------------------------
1394 ## git utility subroutines, invoking git commands
1396 # returns path to the core git executable and the --git-dir parameter as list
1398 return $GIT, '--git-dir='.$git_dir;
1401 # returns path to the core git executable and the --git-dir parameter as string
1403 return join(' ', git_cmd
());
1406 # get HEAD ref of given project as hash
1407 sub git_get_head_hash
{
1408 my $project = shift;
1409 my $o_git_dir = $git_dir;
1411 $git_dir = "$projectroot/$project";
1412 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1415 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1419 if (defined $o_git_dir) {
1420 $git_dir = $o_git_dir;
1425 # get type of given object
1429 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1431 close $fd or return;
1436 # repository configuration
1437 our $config_file = '';
1440 # store multiple values for single key as anonymous array reference
1441 # single values stored directly in the hash, not as [ <value> ]
1442 sub hash_set_multi
{
1443 my ($hash, $key, $value) = @_;
1445 if (!exists $hash->{$key}) {
1446 $hash->{$key} = $value;
1447 } elsif (!ref $hash->{$key}) {
1448 $hash->{$key} = [ $hash->{$key}, $value ];
1450 push @{$hash->{$key}}, $value;
1454 # return hash of git project configuration
1455 # optionally limited to some section, e.g. 'gitweb'
1456 sub git_parse_project_config
{
1457 my $section_regexp = shift;
1462 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1465 while (my $keyval = <$fh>) {
1467 my ($key, $value) = split(/\n/, $keyval, 2);
1469 hash_set_multi
(\
%config, $key, $value)
1470 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1477 # convert config value to boolean, 'true' or 'false'
1478 # no value, number > 0, 'true' and 'yes' values are true
1479 # rest of values are treated as false (never as error)
1480 sub config_to_bool
{
1483 # strip leading and trailing whitespace
1487 return (!defined $val || # section.key
1488 ($val =~ /^\d+$/ && $val) || # section.key = 1
1489 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1492 # convert config value to simple decimal number
1493 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1494 # to be multiplied by 1024, 1048576, or 1073741824
1498 # strip leading and trailing whitespace
1502 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1504 # unknown unit is treated as 1
1505 return $num * ($unit eq 'g' ? 1073741824 :
1506 $unit eq 'm' ? 1048576 :
1507 $unit eq 'k' ? 1024 : 1);
1512 # convert config value to array reference, if needed
1513 sub config_to_multi
{
1516 return ref($val) ? $val : [ $val ];
1519 sub git_get_project_config
{
1520 my ($key, $type) = @_;
1523 return unless ($key);
1524 $key =~ s/^gitweb\.//;
1525 return if ($key =~ m/\W/);
1528 if (defined $type) {
1531 unless ($type eq 'bool' || $type eq 'int');
1535 if (!defined $config_file ||
1536 $config_file ne "$git_dir/config") {
1537 %config = git_parse_project_config
('gitweb');
1538 $config_file = "$git_dir/config";
1542 if (!defined $type) {
1543 return $config{"gitweb.$key"};
1544 } elsif ($type eq 'bool') {
1545 # backward compatibility: 'git config --bool' returns true/false
1546 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1547 } elsif ($type eq 'int') {
1548 return config_to_int
($config{"gitweb.$key"});
1550 return $config{"gitweb.$key"};
1553 # get hash of given path at given ref
1554 sub git_get_hash_by_path
{
1556 my $path = shift || return undef;
1561 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1562 or die_error
(undef, "Open git-ls-tree failed");
1564 close $fd or return undef;
1566 if (!defined $line) {
1567 # there is no tree or hash given by $path at $base
1571 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1572 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1573 if (defined $type && $type ne $2) {
1574 # type doesn't match
1580 # get path of entry with given hash at given tree-ish (ref)
1581 # used to get 'from' filename for combined diff (merge commit) for renames
1582 sub git_get_path_by_hash
{
1583 my $base = shift || return;
1584 my $hash = shift || return;
1588 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1590 while (my $line = <$fd>) {
1593 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1594 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1595 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1604 ## ......................................................................
1605 ## git utility functions, directly accessing git repository
1607 sub git_get_project_description
{
1610 open my $fd, "$projectroot/$path/description" or return undef;
1613 if (defined $descr) {
1619 sub git_get_project_url_list
{
1622 open my $fd, "$projectroot/$path/cloneurl" or return;
1623 my @git_project_url_list = map { chomp; $_ } <$fd>;
1626 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1629 sub git_get_projects_list
{
1634 $filter =~ s/\.git$//;
1636 my ($check_forks) = gitweb_check_feature
('forks');
1638 if (-d
$projects_list) {
1639 # search in directory
1640 my $dir = $projects_list . ($filter ? "/$filter" : '');
1641 # remove the trailing "/"
1643 my $pfxlen = length("$dir");
1644 my $pfxdepth = ($dir =~ tr!/!!);
1647 follow_fast
=> 1, # follow symbolic links
1648 follow_skip
=> 2, # ignore duplicates
1649 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1651 # skip project-list toplevel, if we get it.
1652 return if (m!^[/.]$!);
1653 # only directories can be git repositories
1654 return unless (-d
$_);
1655 # don't traverse too deep (Find is super slow on os x)
1656 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1657 $File::Find
::prune
= 1;
1661 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1662 # we check related file in $projectroot
1663 if ($check_forks and $subdir =~ m
#/.#) {
1664 $File::Find
::prune
= 1;
1665 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1666 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1667 $File::Find
::prune
= 1;
1672 } elsif (-f
$projects_list) {
1673 # read from file(url-encoded):
1674 # 'git%2Fgit.git Linus+Torvalds'
1675 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1676 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1678 open my ($fd), $projects_list or return;
1680 while (my $line = <$fd>) {
1682 my ($path, $owner) = split ' ', $line;
1683 $path = unescape
($path);
1684 $owner = unescape
($owner);
1685 if (!defined $path) {
1688 if ($filter ne '') {
1689 # looking for forks;
1690 my $pfx = substr($path, 0, length($filter));
1691 if ($pfx ne $filter) {
1694 my $sfx = substr($path, length($filter));
1695 if ($sfx !~ /^\/.*\
.git
$/) {
1698 } elsif ($check_forks) {
1700 foreach my $filter (keys %paths) {
1701 # looking for forks;
1702 my $pfx = substr($path, 0, length($filter));
1703 if ($pfx ne $filter) {
1706 my $sfx = substr($path, length($filter));
1707 if ($sfx !~ /^\/.*\
.git
$/) {
1710 # is a fork, don't include it in
1715 if (check_export_ok
("$projectroot/$path")) {
1718 owner
=> to_utf8
($owner),
1721 (my $forks_path = $path) =~ s/\.git$//;
1722 $paths{$forks_path}++;
1730 our $gitweb_project_owner = undef;
1731 sub git_get_project_list_from_file
{
1733 return if (defined $gitweb_project_owner);
1735 $gitweb_project_owner = {};
1736 # read from file (url-encoded):
1737 # 'git%2Fgit.git Linus+Torvalds'
1738 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1739 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1740 if (-f
$projects_list) {
1741 open (my $fd , $projects_list);
1742 while (my $line = <$fd>) {
1744 my ($pr, $ow) = split ' ', $line;
1745 $pr = unescape
($pr);
1746 $ow = unescape
($ow);
1747 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1753 sub git_get_project_owner
{
1754 my $project = shift;
1757 return undef unless $project;
1759 if (!defined $gitweb_project_owner) {
1760 git_get_project_list_from_file
();
1763 if (exists $gitweb_project_owner->{$project}) {
1764 $owner = $gitweb_project_owner->{$project};
1766 if (!defined $owner) {
1767 $owner = get_file_owner
("$projectroot/$project");
1773 sub git_get_last_activity
{
1777 $git_dir = "$projectroot/$path";
1778 open($fd, "-|", git_cmd
(), 'for-each-ref',
1779 '--format=%(committer)',
1780 '--sort=-committerdate',
1782 'refs/heads') or return;
1783 my $most_recent = <$fd>;
1784 close $fd or return;
1785 if (defined $most_recent &&
1786 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1788 my $age = time - $timestamp;
1789 return ($age, age_string
($age));
1791 return (undef, undef);
1794 sub git_get_references
{
1795 my $type = shift || "";
1797 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1798 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1799 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1800 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1803 while (my $line = <$fd>) {
1805 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1806 if (defined $refs{$1}) {
1807 push @{$refs{$1}}, $2;
1813 close $fd or return;
1817 sub git_get_rev_name_tags
{
1818 my $hash = shift || return undef;
1820 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1822 my $name_rev = <$fd>;
1825 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1828 # catches also '$hash undefined' output
1833 ## ----------------------------------------------------------------------
1834 ## parse to hash functions
1838 my $tz = shift || "-0000";
1841 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1842 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1843 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1844 $date{'hour'} = $hour;
1845 $date{'minute'} = $min;
1846 $date{'mday'} = $mday;
1847 $date{'day'} = $days[$wday];
1848 $date{'month'} = $months[$mon];
1849 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1850 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1851 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1852 $mday, $months[$mon], $hour ,$min;
1853 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1854 1900+$year, $mon, $mday, $hour ,$min, $sec;
1856 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1857 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1858 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1859 $date{'hour_local'} = $hour;
1860 $date{'minute_local'} = $min;
1861 $date{'tz_local'} = $tz;
1862 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1863 1900+$year, $mon+1, $mday,
1864 $hour, $min, $sec, $tz);
1873 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1874 $tag{'id'} = $tag_id;
1875 while (my $line = <$fd>) {
1877 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1878 $tag{'object'} = $1;
1879 } elsif ($line =~ m/^type (.+)$/) {
1881 } elsif ($line =~ m/^tag (.+)$/) {
1883 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1884 $tag{'author'} = $1;
1887 } elsif ($line =~ m/--BEGIN/) {
1888 push @comment, $line;
1890 } elsif ($line eq "") {
1894 push @comment, <$fd>;
1895 $tag{'comment'} = \
@comment;
1896 close $fd or return;
1897 if (!defined $tag{'name'}) {
1903 sub parse_commit_text
{
1904 my ($commit_text, $withparents) = @_;
1905 my @commit_lines = split '\n', $commit_text;
1908 pop @commit_lines; # Remove '\0'
1910 if (! @commit_lines) {
1914 my $header = shift @commit_lines;
1915 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1918 ($co{'id'}, my @parents) = split ' ', $header;
1919 while (my $line = shift @commit_lines) {
1920 last if $line eq "\n";
1921 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1923 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1925 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1927 $co{'author_epoch'} = $2;
1928 $co{'author_tz'} = $3;
1929 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1930 $co{'author_name'} = $1;
1931 $co{'author_email'} = $2;
1933 $co{'author_name'} = $co{'author'};
1935 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1936 $co{'committer'} = $1;
1937 $co{'committer_epoch'} = $2;
1938 $co{'committer_tz'} = $3;
1939 $co{'committer_name'} = $co{'committer'};
1940 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1941 $co{'committer_name'} = $1;
1942 $co{'committer_email'} = $2;
1944 $co{'committer_name'} = $co{'committer'};
1948 if (!defined $co{'tree'}) {
1951 $co{'parents'} = \
@parents;
1952 $co{'parent'} = $parents[0];
1954 foreach my $title (@commit_lines) {
1957 $co{'title'} = chop_str
($title, 80, 5);
1958 # remove leading stuff of merges to make the interesting part visible
1959 if (length($title) > 50) {
1960 $title =~ s/^Automatic //;
1961 $title =~ s/^merge (of|with) /Merge ... /i;
1962 if (length($title) > 50) {
1963 $title =~ s/(http|rsync):\/\///;
1965 if (length($title) > 50) {
1966 $title =~ s/(master|www|rsync)\.//;
1968 if (length($title) > 50) {
1969 $title =~ s/kernel.org:?//;
1971 if (length($title) > 50) {
1972 $title =~ s/\/pub\/scm//;
1975 $co{'title_short'} = chop_str
($title, 50, 5);
1979 if ($co{'title'} eq "") {
1980 $co{'title'} = $co{'title_short'} = '(no commit message)';
1982 # remove added spaces
1983 foreach my $line (@commit_lines) {
1986 $co{'comment'} = \
@commit_lines;
1988 my $age = time - $co{'committer_epoch'};
1990 $co{'age_string'} = age_string
($age);
1991 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1992 if ($age > 60*60*24*7*2) {
1993 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1994 $co{'age_string_age'} = $co{'age_string'};
1996 $co{'age_string_date'} = $co{'age_string'};
1997 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2003 my ($commit_id) = @_;
2008 open my $fd, "-|", git_cmd
(), "rev-list",
2014 or die_error
(undef, "Open git-rev-list failed");
2015 %co = parse_commit_text
(<$fd>, 1);
2022 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
2030 open my $fd, "-|", git_cmd
(), "rev-list",
2032 ($arg ? ($arg) : ()),
2033 ("--max-count=" . $maxcount),
2034 ("--skip=" . $skip),
2038 ($filename ? ($filename) : ())
2039 or die_error
(undef, "Open git-rev-list failed");
2040 while (my $line = <$fd>) {
2041 my %co = parse_commit_text
($line);
2046 return wantarray ? @cos : \
@cos;
2049 # parse ref from ref_file, given by ref_id, with given type
2051 my $ref_file = shift;
2053 my $type = shift || git_get_type
($ref_id);
2056 $ref_item{'type'} = $type;
2057 $ref_item{'id'} = $ref_id;
2058 $ref_item{'epoch'} = 0;
2059 $ref_item{'age'} = "unknown";
2060 if ($type eq "tag") {
2061 my %tag = parse_tag
($ref_id);
2062 $ref_item{'comment'} = $tag{'comment'};
2063 if ($tag{'type'} eq "commit") {
2064 my %co = parse_commit
($tag{'object'});
2065 $ref_item{'epoch'} = $co{'committer_epoch'};
2066 $ref_item{'age'} = $co{'age_string'};
2067 } elsif (defined($tag{'epoch'})) {
2068 my $age = time - $tag{'epoch'};
2069 $ref_item{'epoch'} = $tag{'epoch'};
2070 $ref_item{'age'} = age_string
($age);
2072 $ref_item{'reftype'} = $tag{'type'};
2073 $ref_item{'name'} = $tag{'name'};
2074 $ref_item{'refid'} = $tag{'object'};
2075 } elsif ($type eq "commit"){
2076 my %co = parse_commit
($ref_id);
2077 $ref_item{'reftype'} = "commit";
2078 $ref_item{'name'} = $ref_file;
2079 $ref_item{'title'} = $co{'title'};
2080 $ref_item{'refid'} = $ref_id;
2081 $ref_item{'epoch'} = $co{'committer_epoch'};
2082 $ref_item{'age'} = $co{'age_string'};
2084 $ref_item{'reftype'} = $type;
2085 $ref_item{'name'} = $ref_file;
2086 $ref_item{'refid'} = $ref_id;
2092 # parse line of git-diff-tree "raw" output
2093 sub parse_difftree_raw_line
{
2097 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2098 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2099 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2100 $res{'from_mode'} = $1;
2101 $res{'to_mode'} = $2;
2102 $res{'from_id'} = $3;
2104 $res{'status'} = $res{'status_str'} = $5;
2105 $res{'similarity'} = $6;
2106 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2107 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2109 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2112 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2113 # combined diff (for merge commit)
2114 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2115 $res{'nparents'} = length($1);
2116 $res{'from_mode'} = [ split(' ', $2) ];
2117 $res{'to_mode'} = pop @{$res{'from_mode'}};
2118 $res{'from_id'} = [ split(' ', $3) ];
2119 $res{'to_id'} = pop @{$res{'from_id'}};
2120 $res{'status_str'} = $4;
2121 $res{'status'} = [ split('', $4) ];
2122 $res{'to_file'} = unquote
($5);
2124 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2125 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2126 $res{'commit'} = $1;
2129 return wantarray ? %res : \
%res;
2132 # wrapper: return parsed line of git-diff-tree "raw" output
2133 # (the argument might be raw line, or parsed info)
2134 sub parsed_difftree_line
{
2135 my $line_or_ref = shift;
2137 if (ref($line_or_ref) eq "HASH") {
2138 # pre-parsed (or generated by hand)
2139 return $line_or_ref;
2141 return parse_difftree_raw_line
($line_or_ref);
2145 # parse line of git-ls-tree output
2146 sub parse_ls_tree_line
($;%) {
2151 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2152 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2160 $res{'name'} = unquote
($4);
2163 return wantarray ? %res : \
%res;
2166 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2167 sub parse_from_to_diffinfo
{
2168 my ($diffinfo, $from, $to, @parents) = @_;
2170 if ($diffinfo->{'nparents'}) {
2172 $from->{'file'} = [];
2173 $from->{'href'} = [];
2174 fill_from_file_info
($diffinfo, @parents)
2175 unless exists $diffinfo->{'from_file'};
2176 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2177 $from->{'file'}[$i] =
2178 defined $diffinfo->{'from_file'}[$i] ?
2179 $diffinfo->{'from_file'}[$i] :
2180 $diffinfo->{'to_file'};
2181 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2182 $from->{'href'}[$i] = href
(action
=>"blob",
2183 hash_base
=>$parents[$i],
2184 hash
=>$diffinfo->{'from_id'}[$i],
2185 file_name
=>$from->{'file'}[$i]);
2187 $from->{'href'}[$i] = undef;
2191 # ordinary (not combined) diff
2192 $from->{'file'} = $diffinfo->{'from_file'};
2193 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2194 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2195 hash
=>$diffinfo->{'from_id'},
2196 file_name
=>$from->{'file'});
2198 delete $from->{'href'};
2202 $to->{'file'} = $diffinfo->{'to_file'};
2203 if (!is_deleted
($diffinfo)) { # file exists in result
2204 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2205 hash
=>$diffinfo->{'to_id'},
2206 file_name
=>$to->{'file'});
2208 delete $to->{'href'};
2212 ## ......................................................................
2213 ## parse to array of hashes functions
2215 sub git_get_heads_list
{
2219 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2220 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2221 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2224 while (my $line = <$fd>) {
2228 my ($refinfo, $committerinfo) = split(/\0/, $line);
2229 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2230 my ($committer, $epoch, $tz) =
2231 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2232 $name =~ s!^refs/heads/!!;
2234 $ref_item{'name'} = $name;
2235 $ref_item{'id'} = $hash;
2236 $ref_item{'title'} = $title || '(no commit message)';
2237 $ref_item{'epoch'} = $epoch;
2239 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2241 $ref_item{'age'} = "unknown";
2244 push @headslist, \
%ref_item;
2248 return wantarray ? @headslist : \
@headslist;
2251 sub git_get_tags_list
{
2255 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2256 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2257 '--format=%(objectname) %(objecttype) %(refname) '.
2258 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2261 while (my $line = <$fd>) {
2265 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2266 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2267 my ($creator, $epoch, $tz) =
2268 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2269 $name =~ s!^refs/tags/!!;
2271 $ref_item{'type'} = $type;
2272 $ref_item{'id'} = $id;
2273 $ref_item{'name'} = $name;
2274 if ($type eq "tag") {
2275 $ref_item{'subject'} = $title;
2276 $ref_item{'reftype'} = $reftype;
2277 $ref_item{'refid'} = $refid;
2279 $ref_item{'reftype'} = $type;
2280 $ref_item{'refid'} = $id;
2283 if ($type eq "tag" || $type eq "commit") {
2284 $ref_item{'epoch'} = $epoch;
2286 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2288 $ref_item{'age'} = "unknown";
2292 push @tagslist, \
%ref_item;
2296 return wantarray ? @tagslist : \
@tagslist;
2299 ## ----------------------------------------------------------------------
2300 ## filesystem-related functions
2302 sub get_file_owner
{
2305 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2306 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2307 if (!defined $gcos) {
2311 $owner =~ s/[,;].*$//;
2312 return to_utf8
($owner);
2315 ## ......................................................................
2316 ## mimetype related functions
2318 sub mimetype_guess_file
{
2319 my $filename = shift;
2320 my $mimemap = shift;
2321 -r
$mimemap or return undef;
2324 open(MIME
, $mimemap) or return undef;
2326 next if m/^#/; # skip comments
2327 my ($mime, $exts) = split(/\t+/);
2328 if (defined $exts) {
2329 my @exts = split(/\s+/, $exts);
2330 foreach my $ext (@exts) {
2331 $mimemap{$ext} = $mime;
2337 $filename =~ /\.([^.]*)$/;
2338 return $mimemap{$1};
2341 sub mimetype_guess
{
2342 my $filename = shift;
2344 $filename =~ /\./ or return undef;
2346 if ($mimetypes_file) {
2347 my $file = $mimetypes_file;
2348 if ($file !~ m!^/!) { # if it is relative path
2349 # it is relative to project
2350 $file = "$projectroot/$project/$file";
2352 $mime = mimetype_guess_file
($filename, $file);
2354 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2360 my $filename = shift;
2363 my $mime = mimetype_guess
($filename);
2364 $mime and return $mime;
2368 return $default_blob_plain_mimetype unless $fd;
2371 return 'text/plain' .
2372 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2373 } elsif (! $filename) {
2374 return 'application/octet-stream';
2375 } elsif ($filename =~ m/\.png$/i) {
2377 } elsif ($filename =~ m/\.gif$/i) {
2379 } elsif ($filename =~ m/\.jpe?g$/i) {
2380 return 'image/jpeg';
2382 return 'application/octet-stream';
2386 ## ======================================================================
2387 ## functions printing HTML: header, footer, error page
2389 sub git_header_html
{
2390 my $status = shift || "200 OK";
2391 my $expires = shift;
2393 my $title = "$site_name";
2394 if (defined $project) {
2395 $title .= " - " . to_utf8
($project);
2396 if (defined $action) {
2397 $title .= "/$action";
2398 if (defined $file_name) {
2399 $title .= " - " . esc_path
($file_name);
2400 if ($action eq "tree" && $file_name !~ m
|/$|) {
2407 # require explicit support from the UA if we are to send the page as
2408 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2409 # we have to do this because MSIE sometimes globs '*/*', pretending to
2410 # support xhtml+xml but choking when it gets what it asked for.
2411 if (defined $cgi->http('HTTP_ACCEPT') &&
2412 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2413 $cgi->Accept('application/xhtml+xml') != 0) {
2414 $content_type = 'application/xhtml+xml';
2416 $content_type = 'text/html';
2418 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2419 -status
=> $status, -expires
=> $expires);
2420 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2422 <?xml version="1.0" encoding="utf-8"?>
2423 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2424 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2425 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2426 <!-- git core binaries version $git_version -->
2428 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2429 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2430 <meta name="robots" content="index, nofollow"/>
2431 <title>$title</title>
2433 # print out each stylesheet that exist
2434 if (defined $stylesheet) {
2435 #provides backwards capability for those people who define style sheet in a config file
2436 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2438 foreach my $stylesheet (@stylesheets) {
2439 next unless $stylesheet;
2440 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2443 if (defined $project) {
2444 printf('<link rel="alternate" title="%s log RSS feed" '.
2445 'href="%s" type="application/rss+xml" />'."\n",
2446 esc_param
($project), href
(action
=>"rss"));
2447 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2448 'href="%s" type="application/rss+xml" />'."\n",
2449 esc_param
($project), href
(action
=>"rss",
2450 extra_options
=>"--no-merges"));
2451 printf('<link rel="alternate" title="%s log Atom feed" '.
2452 'href="%s" type="application/atom+xml" />'."\n",
2453 esc_param
($project), href
(action
=>"atom"));
2454 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2455 'href="%s" type="application/atom+xml" />'."\n",
2456 esc_param
($project), href
(action
=>"atom",
2457 extra_options
=>"--no-merges"));
2459 printf('<link rel="alternate" title="%s projects list" '.
2460 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2461 $site_name, href
(project
=>undef, action
=>"project_index"));
2462 printf('<link rel="alternate" title="%s projects feeds" '.
2463 'href="%s" type="text/x-opml"/>'."\n",
2464 $site_name, href
(project
=>undef, action
=>"opml"));
2466 if (defined $favicon) {
2467 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2473 if (-f
$site_header) {
2474 open (my $fd, $site_header);
2479 print "<div class=\"page_header\">\n" .
2480 $cgi->a({-href
=> esc_url
($logo_url),
2481 -title
=> $logo_label},
2482 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2483 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2484 if (defined $project) {
2485 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2486 if (defined $action) {
2493 my ($have_search) = gitweb_check_feature
('search');
2494 if ((defined $project) && ($have_search)) {
2495 if (!defined $searchtext) {
2499 if (defined $hash_base) {
2500 $search_hash = $hash_base;
2501 } elsif (defined $hash) {
2502 $search_hash = $hash;
2504 $search_hash = "HEAD";
2506 my $action = $my_uri;
2507 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2508 if ($use_pathinfo) {
2509 $action .= "/$project";
2511 $cgi->param("p", $project);
2513 $cgi->param("a", "search");
2514 $cgi->param("h", $search_hash);
2515 print $cgi->startform(-method => "get", -action
=> $action) .
2516 "<div class=\"search\">\n" .
2517 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2518 $cgi->hidden(-name
=> "a") . "\n" .
2519 $cgi->hidden(-name
=> "h") . "\n" .
2520 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2521 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2522 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2524 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2526 $cgi->end_form() . "\n";
2530 sub git_footer_html
{
2531 print "<div class=\"page_footer\">\n";
2532 if (defined $project) {
2533 my $descr = git_get_project_description
($project);
2534 if (defined $descr) {
2535 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2537 print $cgi->a({-href
=> href
(action
=>"rss"),
2538 -class => "rss_logo"}, "RSS") . " ";
2539 print $cgi->a({-href
=> href
(action
=>"atom"),
2540 -class => "rss_logo"}, "Atom") . "\n";
2542 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2543 -class => "rss_logo"}, "OPML") . " ";
2544 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2545 -class => "rss_logo"}, "TXT") . "\n";
2549 if (-f
$site_footer) {
2550 open (my $fd, $site_footer);
2560 my $status = shift || "403 Forbidden";
2561 my $error = shift || "Malformed query, file missing or permission denied";
2563 git_header_html
($status);
2565 <div class="page_body">
2575 ## ----------------------------------------------------------------------
2576 ## functions printing or outputting HTML: navigation
2578 sub git_print_page_nav
{
2579 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2580 $extra = '' if !defined $extra; # pager or formats
2582 my @navs = qw(summary shortlog log commit commitdiff tree);
2584 @navs = grep { $_ ne $suppress } @navs;
2587 my %arg = map { $_ => {action
=>$_} } @navs;
2588 if (defined $head) {
2589 for (qw(commit commitdiff)) {
2590 $arg{$_}{'hash'} = $head;
2592 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2593 for (qw(shortlog log)) {
2594 $arg{$_}{'hash'} = $head;
2598 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2599 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2601 print "<div class=\"page_nav\">\n" .
2603 map { $_ eq $current ?
2604 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2606 print "<br/>\n$extra<br/>\n" .
2610 sub format_paging_nav
{
2611 my ($action, $hash, $head, $page, $nrevs) = @_;
2615 if ($hash ne $head || $page) {
2616 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2618 $paging_nav .= "HEAD";
2622 $paging_nav .= " ⋅ " .
2623 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2624 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2626 $paging_nav .= " ⋅ prev";
2629 if ($nrevs >= (100 * ($page+1)-1)) {
2630 $paging_nav .= " ⋅ " .
2631 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2632 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2634 $paging_nav .= " ⋅ next";
2640 ## ......................................................................
2641 ## functions printing or outputting HTML: div
2643 sub git_print_header_div
{
2644 my ($action, $title, $hash, $hash_base) = @_;
2647 $args{'action'} = $action;
2648 $args{'hash'} = $hash if $hash;
2649 $args{'hash_base'} = $hash_base if $hash_base;
2651 print "<div class=\"header\">\n" .
2652 $cgi->a({-href
=> href
(%args), -class => "title"},
2653 $title ? $title : $action) .
2657 #sub git_print_authorship (\%) {
2658 sub git_print_authorship
{
2661 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2662 print "<div class=\"author_date\">" .
2663 esc_html
($co->{'author_name'}) .
2665 if ($ad{'hour_local'} < 6) {
2666 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2667 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2669 printf(" (%02d:%02d %s)",
2670 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2675 sub git_print_page_path
{
2681 print "<div class=\"page_path\">";
2682 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2683 -title
=> 'tree root'}, to_utf8
("[$project]"));
2685 if (defined $name) {
2686 my @dirname = split '/', $name;
2687 my $basename = pop @dirname;
2690 foreach my $dir (@dirname) {
2691 $fullname .= ($fullname ? '/' : '') . $dir;
2692 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2694 -title
=> $fullname}, esc_path
($dir));
2697 if (defined $type && $type eq 'blob') {
2698 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2700 -title
=> $name}, esc_path
($basename));
2701 } elsif (defined $type && $type eq 'tree') {
2702 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2704 -title
=> $name}, esc_path
($basename));
2707 print esc_path
($basename);
2710 print "<br/></div>\n";
2713 # sub git_print_log (\@;%) {
2714 sub git_print_log
($;%) {
2718 if ($opts{'-remove_title'}) {
2719 # remove title, i.e. first line of log
2722 # remove leading empty lines
2723 while (defined $log->[0] && $log->[0] eq "") {
2730 foreach my $line (@$log) {
2731 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2734 if (! $opts{'-remove_signoff'}) {
2735 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2738 # remove signoff lines
2745 # print only one empty line
2746 # do not print empty line after signoff
2748 next if ($empty || $signoff);
2754 print format_log_line_html
($line) . "<br/>\n";
2757 if ($opts{'-final_empty_line'}) {
2758 # end with single empty line
2759 print "<br/>\n" unless $empty;
2763 # return link target (what link points to)
2764 sub git_get_link_target
{
2769 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2773 $link_target = <$fd>;
2778 return $link_target;
2781 # given link target, and the directory (basedir) the link is in,
2782 # return target of link relative to top directory (top tree);
2783 # return undef if it is not possible (including absolute links).
2784 sub normalize_link_target
{
2785 my ($link_target, $basedir, $hash_base) = @_;
2787 # we can normalize symlink target only if $hash_base is provided
2788 return unless $hash_base;
2790 # absolute symlinks (beginning with '/') cannot be normalized
2791 return if (substr($link_target, 0, 1) eq '/');
2793 # normalize link target to path from top (root) tree (dir)
2796 $path = $basedir . '/' . $link_target;
2798 # we are in top (root) tree (dir)
2799 $path = $link_target;
2802 # remove //, /./, and /../
2804 foreach my $part (split('/', $path)) {
2805 # discard '.' and ''
2806 next if (!$part || $part eq '.');
2808 if ($part eq '..') {
2812 # link leads outside repository (outside top dir)
2816 push @path_parts, $part;
2819 $path = join('/', @path_parts);
2824 # print tree entry (row of git_tree), but without encompassing <tr> element
2825 sub git_print_tree_entry
{
2826 my ($t, $basedir, $hash_base, $have_blame) = @_;
2829 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2831 # The format of a table row is: mode list link. Where mode is
2832 # the mode of the entry, list is the name of the entry, an href,
2833 # and link is the action links of the entry.
2835 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2836 if ($t->{'type'} eq "blob") {
2837 print "<td class=\"list\">" .
2838 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2839 file_name
=>"$basedir$t->{'name'}", %base_key),
2840 -class => "list"}, esc_path
($t->{'name'}));
2841 if (S_ISLNK
(oct $t->{'mode'})) {
2842 my $link_target = git_get_link_target
($t->{'hash'});
2844 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2845 if (defined $norm_target) {
2847 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2848 file_name
=>$norm_target),
2849 -title
=> $norm_target}, esc_path
($link_target));
2851 print " -> " . esc_path
($link_target);
2856 print "<td class=\"link\">";
2857 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2858 file_name
=>"$basedir$t->{'name'}", %base_key)},
2862 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2863 file_name
=>"$basedir$t->{'name'}", %base_key)},
2866 if (defined $hash_base) {
2868 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2869 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2873 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2874 file_name
=>"$basedir$t->{'name'}")},
2878 } elsif ($t->{'type'} eq "tree") {
2879 print "<td class=\"list\">";
2880 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2881 file_name
=>"$basedir$t->{'name'}", %base_key)},
2882 esc_path
($t->{'name'}));
2884 print "<td class=\"link\">";
2885 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2886 file_name
=>"$basedir$t->{'name'}", %base_key)},
2888 if (defined $hash_base) {
2890 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2891 file_name
=>"$basedir$t->{'name'}")},
2896 # unknown object: we can only present history for it
2897 # (this includes 'commit' object, i.e. submodule support)
2898 print "<td class=\"list\">" .
2899 esc_path
($t->{'name'}) .
2901 print "<td class=\"link\">";
2902 if (defined $hash_base) {
2903 print $cgi->a({-href
=> href
(action
=>"history",
2904 hash_base
=>$hash_base,
2905 file_name
=>"$basedir$t->{'name'}")},
2912 ## ......................................................................
2913 ## functions printing large fragments of HTML
2915 # get pre-image filenames for merge (combined) diff
2916 sub fill_from_file_info
{
2917 my ($diff, @parents) = @_;
2919 $diff->{'from_file'} = [ ];
2920 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2921 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2922 if ($diff->{'status'}[$i] eq 'R' ||
2923 $diff->{'status'}[$i] eq 'C') {
2924 $diff->{'from_file'}[$i] =
2925 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2932 # is current raw difftree line of file deletion
2934 my $diffinfo = shift;
2936 return $diffinfo->{'status_str'} =~ /D/;
2939 # does patch correspond to [previous] difftree raw line
2940 # $diffinfo - hashref of parsed raw diff format
2941 # $patchinfo - hashref of parsed patch diff format
2942 # (the same keys as in $diffinfo)
2943 sub is_patch_split
{
2944 my ($diffinfo, $patchinfo) = @_;
2946 return defined $diffinfo && defined $patchinfo
2947 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2951 sub git_difftree_body
{
2952 my ($difftree, $hash, @parents) = @_;
2953 my ($parent) = $parents[0];
2954 my ($have_blame) = gitweb_check_feature
('blame');
2955 print "<div class=\"list_head\">\n";
2956 if ($#{$difftree} > 10) {
2957 print(($#{$difftree} + 1) . " files changed:\n");
2961 print "<table class=\"" .
2962 (@parents > 1 ? "combined " : "") .
2965 # header only for combined diff in 'commitdiff' view
2966 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2969 print "<thead><tr>\n" .
2970 "<th></th><th></th>\n"; # filename, patchN link
2971 for (my $i = 0; $i < @parents; $i++) {
2972 my $par = $parents[$i];
2974 $cgi->a({-href
=> href
(action
=>"commitdiff",
2975 hash
=>$hash, hash_parent
=>$par),
2976 -title
=> 'commitdiff to parent number ' .
2977 ($i+1) . ': ' . substr($par,0,7)},
2981 print "</tr></thead>\n<tbody>\n";
2986 foreach my $line (@{$difftree}) {
2987 my $diff = parsed_difftree_line
($line);
2990 print "<tr class=\"dark\">\n";
2992 print "<tr class=\"light\">\n";
2996 if (exists $diff->{'nparents'}) { # combined diff
2998 fill_from_file_info
($diff, @parents)
2999 unless exists $diff->{'from_file'};
3001 if (!is_deleted
($diff)) {
3002 # file exists in the result (child) commit
3004 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3005 file_name
=>$diff->{'to_file'},
3007 -class => "list"}, esc_path
($diff->{'to_file'})) .
3011 esc_path
($diff->{'to_file'}) .
3015 if ($action eq 'commitdiff') {
3018 print "<td class=\"link\">" .
3019 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3024 my $has_history = 0;
3025 my $not_deleted = 0;
3026 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3027 my $hash_parent = $parents[$i];
3028 my $from_hash = $diff->{'from_id'}[$i];
3029 my $from_path = $diff->{'from_file'}[$i];
3030 my $status = $diff->{'status'}[$i];
3032 $has_history ||= ($status ne 'A');
3033 $not_deleted ||= ($status ne 'D');
3035 if ($status eq 'A') {
3036 print "<td class=\"link\" align=\"right\"> | </td>\n";
3037 } elsif ($status eq 'D') {
3038 print "<td class=\"link\">" .
3039 $cgi->a({-href
=> href
(action
=>"blob",
3042 file_name
=>$from_path)},
3046 if ($diff->{'to_id'} eq $from_hash) {
3047 print "<td class=\"link nochange\">";
3049 print "<td class=\"link\">";
3051 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3052 hash
=>$diff->{'to_id'},
3053 hash_parent
=>$from_hash,
3055 hash_parent_base
=>$hash_parent,
3056 file_name
=>$diff->{'to_file'},
3057 file_parent
=>$from_path)},
3063 print "<td class=\"link\">";
3065 print $cgi->a({-href
=> href
(action
=>"blob",
3066 hash
=>$diff->{'to_id'},
3067 file_name
=>$diff->{'to_file'},
3070 print " | " if ($has_history);
3073 print $cgi->a({-href
=> href
(action
=>"history",
3074 file_name
=>$diff->{'to_file'},
3081 next; # instead of 'else' clause, to avoid extra indent
3083 # else ordinary diff
3085 my ($to_mode_oct, $to_mode_str, $to_file_type);
3086 my ($from_mode_oct, $from_mode_str, $from_file_type);
3087 if ($diff->{'to_mode'} ne ('0' x
6)) {
3088 $to_mode_oct = oct $diff->{'to_mode'};
3089 if (S_ISREG
($to_mode_oct)) { # only for regular file
3090 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3092 $to_file_type = file_type
($diff->{'to_mode'});
3094 if ($diff->{'from_mode'} ne ('0' x
6)) {
3095 $from_mode_oct = oct $diff->{'from_mode'};
3096 if (S_ISREG
($to_mode_oct)) { # only for regular file
3097 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3099 $from_file_type = file_type
($diff->{'from_mode'});
3102 if ($diff->{'status'} eq "A") { # created
3103 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3104 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3105 $mode_chng .= "]</span>";
3107 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3108 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3109 -class => "list"}, esc_path
($diff->{'file'}));
3111 print "<td>$mode_chng</td>\n";
3112 print "<td class=\"link\">";
3113 if ($action eq 'commitdiff') {
3116 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3119 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3120 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3124 } elsif ($diff->{'status'} eq "D") { # deleted
3125 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3127 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3128 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3129 -class => "list"}, esc_path
($diff->{'file'}));
3131 print "<td>$mode_chng</td>\n";
3132 print "<td class=\"link\">";
3133 if ($action eq 'commitdiff') {
3136 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3139 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3140 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3143 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3144 file_name
=>$diff->{'file'})},
3147 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3148 file_name
=>$diff->{'file'})},
3152 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3153 my $mode_chnge = "";
3154 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3155 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3156 if ($from_file_type ne $to_file_type) {
3157 $mode_chnge .= " from $from_file_type to $to_file_type";
3159 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3160 if ($from_mode_str && $to_mode_str) {
3161 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3162 } elsif ($to_mode_str) {
3163 $mode_chnge .= " mode: $to_mode_str";
3166 $mode_chnge .= "]</span>\n";
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_chnge</td>\n";
3174 print "<td class=\"link\">";
3175 if ($action eq 'commitdiff') {
3178 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3180 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3181 # "commit" view and modified file (not onlu mode changed)
3182 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3183 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3184 hash_base
=>$hash, hash_parent_base
=>$parent,
3185 file_name
=>$diff->{'file'})},
3189 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3190 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3193 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3194 file_name
=>$diff->{'file'})},
3197 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3198 file_name
=>$diff->{'file'})},
3202 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3203 my %status_name = ('R' => 'moved', 'C' => 'copied');
3204 my $nstatus = $status_name{$diff->{'status'}};
3206 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3207 # mode also for directories, so we cannot use $to_mode_str
3208 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3211 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3212 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3213 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3214 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3215 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3216 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3217 -class => "list"}, esc_path
($diff->{'from_file'})) .
3218 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3219 "<td class=\"link\">";
3220 if ($action eq 'commitdiff') {
3223 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3225 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3226 # "commit" view and modified file (not only pure rename or copy)
3227 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3228 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3229 hash_base
=>$hash, hash_parent_base
=>$parent,
3230 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3234 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3235 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3238 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3239 file_name
=>$diff->{'to_file'})},
3242 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3243 file_name
=>$diff->{'to_file'})},
3247 } # we should not encounter Unmerged (U) or Unknown (X) status
3250 print "</tbody>" if $has_header;
3254 sub git_patchset_body
{
3255 my ($fd, $difftree, $hash, @hash_parents) = @_;
3256 my ($hash_parent) = $hash_parents[0];
3258 my $is_combined = (@hash_parents > 1);
3260 my $patch_number = 0;
3266 print "<div class=\"patchset\">\n";
3268 # skip to first patch
3269 while ($patch_line = <$fd>) {
3272 last if ($patch_line =~ m/^diff /);
3276 while ($patch_line) {
3278 # parse "git diff" header line
3279 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3280 # $1 is from_name, which we do not use
3281 $to_name = unquote
($2);
3282 $to_name =~ s!^b/!!;
3283 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3284 # $1 is 'cc' or 'combined', which we do not use
3285 $to_name = unquote
($2);
3290 # check if current patch belong to current raw line
3291 # and parse raw git-diff line if needed
3292 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3293 # this is continuation of a split patch
3294 print "<div class=\"patch cont\">\n";
3296 # advance raw git-diff output if needed
3297 $patch_idx++ if defined $diffinfo;
3299 # read and prepare patch information
3300 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3302 # compact combined diff output can have some patches skipped
3303 # find which patch (using pathname of result) we are at now;
3305 while ($to_name ne $diffinfo->{'to_file'}) {
3306 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3307 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3308 "</div>\n"; # class="patch"
3313 last if $patch_idx > $#$difftree;
3314 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3318 # modifies %from, %to hashes
3319 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3321 # this is first patch for raw difftree line with $patch_idx index
3322 # we index @$difftree array from 0, but number patches from 1
3323 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3327 #assert($patch_line =~ m/^diff /) if DEBUG;
3328 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3330 # print "git diff" header
3331 print format_git_diff_header_line
($patch_line, $diffinfo,
3334 # print extended diff header
3335 print "<div class=\"diff extended_header\">\n";
3337 while ($patch_line = <$fd>) {
3340 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3342 print format_extended_diff_header_line
($patch_line, $diffinfo,
3345 print "</div>\n"; # class="diff extended_header"
3347 # from-file/to-file diff header
3348 if (! $patch_line) {
3349 print "</div>\n"; # class="patch"
3352 next PATCH
if ($patch_line =~ m/^diff /);
3353 #assert($patch_line =~ m/^---/) if DEBUG;
3355 my $last_patch_line = $patch_line;
3356 $patch_line = <$fd>;
3358 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3360 print format_diff_from_to_header
($last_patch_line, $patch_line,
3361 $diffinfo, \
%from, \
%to,
3366 while ($patch_line = <$fd>) {
3369 next PATCH
if ($patch_line =~ m/^diff /);
3371 print format_diff_line
($patch_line, \
%from, \
%to);
3375 print "</div>\n"; # class="patch"
3378 # for compact combined (--cc) format, with chunk and patch simpliciaction
3379 # patchset might be empty, but there might be unprocessed raw lines
3380 for (++$patch_idx if $patch_number > 0;
3381 $patch_idx < @$difftree;
3383 # read and prepare patch information
3384 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3386 # generate anchor for "patch" links in difftree / whatchanged part
3387 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3388 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3389 "</div>\n"; # class="patch"
3394 if ($patch_number == 0) {
3395 if (@hash_parents > 1) {
3396 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3398 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3402 print "</div>\n"; # class="patchset"
3405 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3407 sub git_project_list_body
{
3408 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3410 my ($check_forks) = gitweb_check_feature
('forks');
3413 foreach my $pr (@$projlist) {
3414 my (@aa) = git_get_last_activity
($pr->{'path'});
3418 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3419 if (!defined $pr->{'descr'}) {
3420 my $descr = git_get_project_description
($pr->{'path'}) || "";
3421 $pr->{'descr_long'} = to_utf8
($descr);
3422 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3424 if (!defined $pr->{'owner'}) {
3425 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3428 my $pname = $pr->{'path'};
3429 if (($pname =~ s/\.git$//) &&
3430 ($pname !~ /\/$/) &&
3431 (-d
"$projectroot/$pname")) {
3432 $pr->{'forks'} = "-d $projectroot/$pname";
3438 push @projects, $pr;
3441 $order ||= $default_projects_order;
3442 $from = 0 unless defined $from;
3443 $to = $#projects if (!defined $to || $#projects < $to);
3445 print "<table class=\"project_list\">\n";
3446 unless ($no_header) {
3449 print "<th></th>\n";
3451 if ($order eq "project") {
3452 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3453 print "<th>Project</th>\n";
3456 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3457 -class => "header"}, "Project") .
3460 if ($order eq "descr") {
3461 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3462 print "<th>Description</th>\n";
3465 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3466 -class => "header"}, "Description") .
3469 if ($order eq "owner") {
3470 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3471 print "<th>Owner</th>\n";
3474 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3475 -class => "header"}, "Owner") .
3478 if ($order eq "age") {
3479 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3480 print "<th>Last Change</th>\n";
3483 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3484 -class => "header"}, "Last Change") .
3487 print "<th></th>\n" .
3491 for (my $i = $from; $i <= $to; $i++) {
3492 my $pr = $projects[$i];
3494 print "<tr class=\"dark\">\n";
3496 print "<tr class=\"light\">\n";
3501 if ($pr->{'forks'}) {
3502 print "<!-- $pr->{'forks'} -->\n";
3503 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3507 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3508 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3509 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3510 -class => "list", -title
=> $pr->{'descr_long'}},
3511 esc_html
($pr->{'descr'})) . "</td>\n" .
3512 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3513 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3514 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3515 "<td class=\"link\">" .
3516 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3517 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3518 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3519 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3520 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3524 if (defined $extra) {
3527 print "<td></td>\n";
3529 print "<td colspan=\"5\">$extra</td>\n" .
3535 sub git_shortlog_body
{
3536 # uses global variable $project
3537 my ($commitlist, $from, $to, $refs, $extra) = @_;
3539 $from = 0 unless defined $from;
3540 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3542 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3544 for (my $i = $from; $i <= $to; $i++) {
3545 my %co = %{$commitlist->[$i]};
3546 my $commit = $co{'id'};
3547 my $ref = format_ref_marker
($refs, $commit);
3549 print "<tr class=\"dark\">\n";
3551 print "<tr class=\"light\">\n";
3554 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3555 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3556 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3557 "<td><i>" . $author . "</i></td>\n" .
3559 print format_subject_html
($co{'title'}, $co{'title_short'},
3560 href
(action
=>"commit", hash
=>$commit), $ref);
3562 "<td class=\"link\">" .
3563 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3564 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3565 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3566 my $snapshot_links = format_snapshot_links
($commit);
3567 if (defined $snapshot_links) {
3568 print " | " . $snapshot_links;
3573 if (defined $extra) {
3575 "<td colspan=\"4\">$extra</td>\n" .
3581 sub git_history_body
{
3582 # Warning: assumes constant type (blob or tree) during history
3583 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3585 $from = 0 unless defined $from;
3586 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3588 print "<table class=\"history\" cellspacing=\"0\">\n";
3590 for (my $i = $from; $i <= $to; $i++) {
3591 my %co = %{$commitlist->[$i]};
3595 my $commit = $co{'id'};
3597 my $ref = format_ref_marker
($refs, $commit);
3600 print "<tr class=\"dark\">\n";
3602 print "<tr class=\"light\">\n";
3605 # shortlog uses chop_str($co{'author_name'}, 10)
3606 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3607 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3608 "<td><i>" . $author . "</i></td>\n" .
3610 # originally git_history used chop_str($co{'title'}, 50)
3611 print format_subject_html
($co{'title'}, $co{'title_short'},
3612 href
(action
=>"commit", hash
=>$commit), $ref);
3614 "<td class=\"link\">" .
3615 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3616 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3618 if ($ftype eq 'blob') {
3619 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3620 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3621 if (defined $blob_current && defined $blob_parent &&
3622 $blob_current ne $blob_parent) {
3624 $cgi->a({-href
=> href
(action
=>"blobdiff",
3625 hash
=>$blob_current, hash_parent
=>$blob_parent,
3626 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3627 file_name
=>$file_name)},
3634 if (defined $extra) {
3636 "<td colspan=\"4\">$extra</td>\n" .
3643 # uses global variable $project
3644 my ($taglist, $from, $to, $extra) = @_;
3645 $from = 0 unless defined $from;
3646 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3648 print "<table class=\"tags\" cellspacing=\"0\">\n";
3650 for (my $i = $from; $i <= $to; $i++) {
3651 my $entry = $taglist->[$i];
3653 my $comment = $tag{'subject'};
3655 if (defined $comment) {
3656 $comment_short = chop_str
($comment, 30, 5);
3659 print "<tr class=\"dark\">\n";
3661 print "<tr class=\"light\">\n";
3664 if (defined $tag{'age'}) {
3665 print "<td><i>$tag{'age'}</i></td>\n";
3667 print "<td></td>\n";
3670 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3671 -class => "list name"}, esc_html
($tag{'name'})) .
3674 if (defined $comment) {
3675 print format_subject_html
($comment, $comment_short,
3676 href
(action
=>"tag", hash
=>$tag{'id'}));
3679 "<td class=\"selflink\">";
3680 if ($tag{'type'} eq "tag") {
3681 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3686 "<td class=\"link\">" . " | " .
3687 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3688 if ($tag{'reftype'} eq "commit") {
3689 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3690 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3691 } elsif ($tag{'reftype'} eq "blob") {
3692 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3697 if (defined $extra) {
3699 "<td colspan=\"5\">$extra</td>\n" .
3705 sub git_heads_body
{
3706 # uses global variable $project
3707 my ($headlist, $head, $from, $to, $extra) = @_;
3708 $from = 0 unless defined $from;
3709 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3711 print "<table class=\"heads\" cellspacing=\"0\">\n";
3713 for (my $i = $from; $i <= $to; $i++) {
3714 my $entry = $headlist->[$i];
3716 my $curr = $ref{'id'} eq $head;
3718 print "<tr class=\"dark\">\n";
3720 print "<tr class=\"light\">\n";
3723 print "<td><i>$ref{'age'}</i></td>\n" .
3724 ($curr ? "<td class=\"current_head\">" : "<td>") .
3725 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3726 -class => "list name"},esc_html
($ref{'name'})) .
3728 "<td class=\"link\">" .
3729 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3730 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3731 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3735 if (defined $extra) {
3737 "<td colspan=\"3\">$extra</td>\n" .
3743 sub git_search_grep_body
{
3744 my ($commitlist, $from, $to, $extra) = @_;
3745 $from = 0 unless defined $from;
3746 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3748 print "<table class=\"grep\" cellspacing=\"0\">\n";
3750 for (my $i = $from; $i <= $to; $i++) {
3751 my %co = %{$commitlist->[$i]};
3755 my $commit = $co{'id'};
3757 print "<tr class=\"dark\">\n";
3759 print "<tr class=\"light\">\n";
3762 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3763 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3764 "<td><i>" . $author . "</i></td>\n" .
3766 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3767 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3768 my $comment = $co{'comment'};
3769 foreach my $line (@$comment) {
3770 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3771 my $lead = esc_html
($1) || "";
3772 $lead = chop_str
($lead, 30, 10);
3773 my $match = esc_html
($2) || "";
3774 my $trail = esc_html
($3) || "";
3775 $trail = chop_str
($trail, 30, 10);
3776 my $text = "$lead<span class=\"match\">$match</span>$trail";
3777 print chop_str
($text, 80, 5) . "<br/>\n";
3781 "<td class=\"link\">" .
3782 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3784 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3788 if (defined $extra) {
3790 "<td colspan=\"3\">$extra</td>\n" .
3796 ## ======================================================================
3797 ## ======================================================================
3800 sub git_project_list
{
3801 my $order = $cgi->param('o');
3802 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3803 die_error
(undef, "Unknown order parameter");
3806 my @list = git_get_projects_list
();
3808 die_error
(undef, "No projects found");
3812 if (-f
$home_text) {
3813 print "<div class=\"index_include\">\n";
3814 open (my $fd, $home_text);
3819 git_project_list_body
(\
@list, $order);
3824 my $order = $cgi->param('o');
3825 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3826 die_error
(undef, "Unknown order parameter");
3829 my @list = git_get_projects_list
($project);
3831 die_error
(undef, "No forks found");
3835 git_print_page_nav
('','');
3836 git_print_header_div
('summary', "$project forks");
3837 git_project_list_body
(\
@list, $order);
3841 sub git_project_index
{
3842 my @projects = git_get_projects_list
($project);
3845 -type
=> 'text/plain',
3846 -charset
=> 'utf-8',
3847 -content_disposition
=> 'inline; filename="index.aux"');
3849 foreach my $pr (@projects) {
3850 if (!exists $pr->{'owner'}) {
3851 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3854 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3855 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3856 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3857 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3861 print "$path $owner\n";
3866 my $descr = git_get_project_description
($project) || "none";
3867 my %co = parse_commit
("HEAD");
3868 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3869 my $head = $co{'id'};
3871 my $owner = git_get_project_owner
($project);
3873 my $refs = git_get_references
();
3874 # These get_*_list functions return one more to allow us to see if
3875 # there are more ...
3876 my @taglist = git_get_tags_list
(16);
3877 my @headlist = git_get_heads_list
(16);
3879 my ($check_forks) = gitweb_check_feature
('forks');
3882 @forklist = git_get_projects_list
($project);
3886 git_print_page_nav
('summary','', $head);
3888 print "<div class=\"title\"> </div>\n";
3889 print "<table cellspacing=\"0\">\n" .
3890 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3891 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3892 if (defined $cd{'rfc2822'}) {
3893 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3896 # use per project git URL list in $projectroot/$project/cloneurl
3897 # or make project git URL from git base URL and project name
3898 my $url_tag = "URL";
3899 my @url_list = git_get_project_url_list
($project);
3900 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3901 foreach my $git_url (@url_list) {
3902 next unless $git_url;
3903 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3908 if (-s
"$projectroot/$project/README.html") {
3909 if (open my $fd, "$projectroot/$project/README.html") {
3910 print "<div class=\"title\">readme</div>\n";
3911 print $_ while (<$fd>);
3916 # we need to request one more than 16 (0..15) to check if
3918 my @commitlist = $head ? parse_commits
($head, 17) : ();
3920 git_print_header_div
('shortlog');
3921 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3922 $#commitlist <= 15 ? undef :
3923 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3927 git_print_header_div
('tags');
3928 git_tags_body
(\
@taglist, 0, 15,
3929 $#taglist <= 15 ? undef :
3930 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3934 git_print_header_div
('heads');
3935 git_heads_body
(\
@headlist, $head, 0, 15,
3936 $#headlist <= 15 ? undef :
3937 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3941 git_print_header_div
('forks');
3942 git_project_list_body
(\
@forklist, undef, 0, 15,
3943 $#forklist <= 15 ? undef :
3944 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3952 my $head = git_get_head_hash
($project);
3954 git_print_page_nav
('','', $head,undef,$head);
3955 my %tag = parse_tag
($hash);
3958 die_error
(undef, "Unknown tag object");
3961 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3962 print "<div class=\"title_text\">\n" .
3963 "<table cellspacing=\"0\">\n" .
3965 "<td>object</td>\n" .
3966 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3967 $tag{'object'}) . "</td>\n" .
3968 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3969 $tag{'type'}) . "</td>\n" .
3971 if (defined($tag{'author'})) {
3972 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3973 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3974 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3975 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3978 print "</table>\n\n" .
3980 print "<div class=\"page_body\">";
3981 my $comment = $tag{'comment'};
3982 foreach my $line (@$comment) {
3984 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3994 my ($have_blame) = gitweb_check_feature
('blame');
3996 die_error
('403 Permission denied', "Permission denied");
3998 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3999 $hash_base ||= git_get_head_hash
($project);
4000 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4001 my %co = parse_commit
($hash_base)
4002 or die_error
(undef, "Reading commit failed");
4003 if (!defined $hash) {
4004 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4005 or die_error
(undef, "Error looking up file");
4007 $ftype = git_get_type
($hash);
4008 if ($ftype !~ "blob") {
4009 die_error
('400 Bad Request', "Object is not a blob");
4011 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4012 $file_name, $hash_base)
4013 or die_error
(undef, "Open git-blame failed");
4016 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4019 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4022 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4024 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4025 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4026 git_print_page_path
($file_name, $ftype, $hash_base);
4027 my @rev_color = (qw(light2 dark2));
4028 my $num_colors = scalar(@rev_color);
4029 my $current_color = 0;
4032 <div class="page_body">
4033 <table class="blame">
4034 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4039 last unless defined $_;
4040 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4041 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4042 if (!exists $metainfo{$full_rev}) {
4043 $metainfo{$full_rev} = {};
4045 my $meta = $metainfo{$full_rev};
4048 if (/^(\S+) (.*)$/) {
4054 my $rev = substr($full_rev, 0, 8);
4055 my $author = $meta->{'author'};
4056 my %date = parse_date
($meta->{'author-time'},
4057 $meta->{'author-tz'});
4058 my $date = $date{'iso-tz'};
4060 $current_color = ++$current_color % $num_colors;
4062 print "<tr class=\"$rev_color[$current_color]\">\n";
4064 print "<td class=\"sha1\"";
4065 print " title=\"". esc_html
($author) . ", $date\"";
4066 print " rowspan=\"$group_size\"" if ($group_size > 1);
4068 print $cgi->a({-href
=> href
(action
=>"commit",
4070 file_name
=>$file_name)},
4074 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4075 or die_error
(undef, "Open git-rev-parse failed");
4076 my $parent_commit = <$dd>;
4078 chomp($parent_commit);
4079 my $blamed = href
(action
=> 'blame',
4080 file_name
=> $meta->{'filename'},
4081 hash_base
=> $parent_commit);
4082 print "<td class=\"linenr\">";
4083 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4085 -class => "linenr" },
4088 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4094 or print "Reading blob failed\n";
4101 my ($have_blame) = gitweb_check_feature
('blame');
4103 die_error
('403 Permission denied', "Permission denied");
4105 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4106 $hash_base ||= git_get_head_hash
($project);
4107 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4108 my %co = parse_commit
($hash_base)
4109 or die_error
(undef, "Reading commit failed");
4110 if (!defined $hash) {
4111 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4112 or die_error
(undef, "Error lookup file");
4114 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4115 or die_error
(undef, "Open git-annotate failed");
4118 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4121 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4124 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4126 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4127 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4128 git_print_page_path
($file_name, 'blob', $hash_base);
4129 print "<div class=\"page_body\">\n";
4131 <table class="blame">
4140 my @line_class = (qw(light dark));
4141 my $line_class_len = scalar (@line_class);
4142 my $line_class_num = $#line_class;
4143 while (my $line = <$fd>) {
4155 $line_class_num = ($line_class_num + 1) % $line_class_len;
4157 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4164 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4167 $short_rev = substr ($long_rev, 0, 8);
4168 $age = time () - $time;
4169 $age_str = age_string
($age);
4170 $age_str =~ s/ / /g;
4171 $age_class = age_class
($age);
4172 $author = esc_html
($author);
4173 $author =~ s/ / /g;
4175 $data = untabify
($data);
4176 $data = esc_html
($data);
4179 <tr class="$line_class[$line_class_num]">
4180 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4181 <td class="$age_class">$age_str</td>
4183 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4184 <td class="pre">$data</td>
4187 } # while (my $line = <$fd>)
4188 print "</table>\n\n";
4190 or print "Reading blob failed.\n";
4196 my $head = git_get_head_hash
($project);
4198 git_print_page_nav
('','', $head,undef,$head);
4199 git_print_header_div
('summary', $project);
4201 my @tagslist = git_get_tags_list
();
4203 git_tags_body
(\
@tagslist);
4209 my $head = git_get_head_hash
($project);
4211 git_print_page_nav
('','', $head,undef,$head);
4212 git_print_header_div
('summary', $project);
4214 my @headslist = git_get_heads_list
();
4216 git_heads_body
(\
@headslist, $head);
4221 sub git_blob_plain
{
4224 if (!defined $hash) {
4225 if (defined $file_name) {
4226 my $base = $hash_base || git_get_head_hash
($project);
4227 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4228 or die_error
(undef, "Error lookup file");
4230 die_error
(undef, "No file name defined");
4232 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4233 # blobs defined by non-textual hash id's can be cached
4238 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4239 or die_error
(undef, "Couldn't cat $file_name, $hash");
4241 $type ||= blob_mimetype
($fd, $file_name);
4243 # save as filename, even when no $file_name is given
4244 my $save_as = "$hash";
4245 if (defined $file_name) {
4246 $save_as = $file_name;
4247 } elsif ($type =~ m/^text\//) {
4254 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4256 binmode STDOUT
, ':raw';
4258 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4266 if (!defined $hash) {
4267 if (defined $file_name) {
4268 my $base = $hash_base || git_get_head_hash
($project);
4269 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4270 or die_error
(undef, "Error lookup file");
4272 die_error
(undef, "No file name defined");
4274 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4275 # blobs defined by non-textual hash id's can be cached
4279 my ($have_blame) = gitweb_check_feature
('blame');
4280 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4281 or die_error
(undef, "Couldn't cat $file_name, $hash");
4282 my $mimetype = blob_mimetype
($fd, $file_name);
4283 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4285 return git_blob_plain
($mimetype);
4287 # we can have blame only for text/* mimetype
4288 $have_blame &&= ($mimetype =~ m!^text/!);
4290 git_header_html
(undef, $expires);
4291 my $formats_nav = '';
4292 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4293 if (defined $file_name) {
4296 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4301 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4304 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4307 $cgi->a({-href
=> href
(action
=>"blob",
4308 hash_base
=>"HEAD", file_name
=>$file_name)},
4312 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4315 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4316 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4318 print "<div class=\"page_nav\">\n" .
4319 "<br/><br/></div>\n" .
4320 "<div class=\"title\">$hash</div>\n";
4322 git_print_page_path
($file_name, "blob", $hash_base);
4323 print "<div class=\"page_body\">\n";
4324 if ($mimetype =~ m!^text/!) {
4326 while (my $line = <$fd>) {
4329 $line = untabify
($line);
4330 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4331 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4333 } elsif ($mimetype =~ m!^image/!) {
4334 print qq
!<img type
="$mimetype"!;
4336 print qq
! alt
="$file_name" title
="$file_name"!;
4339 href(action=>"blob_plain
", hash=>$hash,
4340 hash_base=>$hash_base, file_name=>$file_name) .
4344 or print "Reading blob failed.\n";
4350 if (!defined $hash_base) {
4351 $hash_base = "HEAD";
4353 if (!defined $hash) {
4354 if (defined $file_name) {
4355 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4361 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4362 or die_error
(undef, "Open git-ls-tree failed");
4363 my @entries = map { chomp; $_ } <$fd>;
4364 close $fd or die_error
(undef, "Reading tree failed");
4367 my $refs = git_get_references
();
4368 my $ref = format_ref_marker
($refs, $hash_base);
4371 my ($have_blame) = gitweb_check_feature
('blame');
4372 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4374 if (defined $file_name) {
4376 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4378 $cgi->a({-href
=> href
(action
=>"tree",
4379 hash_base
=>"HEAD", file_name
=>$file_name)},
4382 my $snapshot_links = format_snapshot_links
($hash);
4383 if (defined $snapshot_links) {
4384 # FIXME: Should be available when we have no hash base as well.
4385 push @views_nav, $snapshot_links;
4387 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4388 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4391 print "<div class=\"page_nav\">\n";
4392 print "<br/><br/></div>\n";
4393 print "<div class=\"title\">$hash</div>\n";
4395 if (defined $file_name) {
4396 $basedir = $file_name;
4397 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4401 git_print_page_path
($file_name, 'tree', $hash_base);
4402 print "<div class=\"page_body\">\n";
4403 print "<table cellspacing=\"0\">\n";
4405 # '..' (top directory) link if possible
4406 if (defined $hash_base &&
4407 defined $file_name && $file_name =~ m![^/]+$!) {
4409 print "<tr class=\"dark\">\n";
4411 print "<tr class=\"light\">\n";
4415 my $up = $file_name;
4416 $up =~ s!/?[^/]+$!!;
4417 undef $up unless $up;
4418 # based on git_print_tree_entry
4419 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4420 print '<td class="list">';
4421 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4425 print "<td class=\"link\"></td>\n";
4429 foreach my $line (@entries) {
4430 my %t = parse_ls_tree_line
($line, -z
=> 1);
4433 print "<tr class=\"dark\">\n";
4435 print "<tr class=\"light\">\n";
4439 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4443 print "</table>\n" .
4449 my @supported_fmts = gitweb_check_feature
('snapshot');
4450 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4452 my $format = $cgi->param('sf');
4453 if (!@supported_fmts) {
4454 die_error
('403 Permission denied', "Permission denied");
4456 # default to first supported snapshot format
4457 $format ||= $supported_fmts[0];
4458 if ($format !~ m/^[a-z0-9]+$/) {
4459 die_error
(undef, "Invalid snapshot format parameter");
4460 } elsif (!exists($known_snapshot_formats{$format})) {
4461 die_error
(undef, "Unknown snapshot format");
4462 } elsif (!grep($_ eq $format, @supported_fmts)) {
4463 die_error
(undef, "Unsupported snapshot format");
4466 if (!defined $hash) {
4467 $hash = git_get_head_hash
($project);
4470 my $git_command = git_cmd_str
();
4471 my $name = $project;
4472 $name =~ s
,([^/])/*\
.git
$,$1,;
4473 $name = basename
($name);
4474 my $filename = to_utf8
($name);
4475 $name =~ s/\047/\047\\\047\047/g;
4477 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4478 $cmd = "$git_command archive " .
4479 "--format=$known_snapshot_formats{$format}{'format'} " .
4480 "--prefix=\'$name\'/ $hash";
4481 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4482 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4486 -type
=> $known_snapshot_formats{$format}{'type'},
4487 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4488 -status
=> '200 OK');
4490 open my $fd, "-|", $cmd
4491 or die_error
(undef, "Execute git-archive failed");
4492 binmode STDOUT
, ':raw';
4494 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4499 my $head = git_get_head_hash
($project);
4500 if (!defined $hash) {
4503 if (!defined $page) {
4506 my $refs = git_get_references
();
4508 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4510 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4513 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4516 my %co = parse_commit
($hash);
4518 git_print_header_div
('summary', $project);
4519 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4521 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4522 for (my $i = 0; $i <= $to; $i++) {
4523 my %co = %{$commitlist[$i]};
4525 my $commit = $co{'id'};
4526 my $ref = format_ref_marker
($refs, $commit);
4527 my %ad = parse_date
($co{'author_epoch'});
4528 git_print_header_div
('commit',
4529 "<span class=\"age\">$co{'age_string'}</span>" .
4530 esc_html
($co{'title'}) . $ref,
4532 print "<div class=\"title_text\">\n" .
4533 "<div class=\"log_link\">\n" .
4534 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4536 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4538 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4541 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4544 print "<div class=\"log_body\">\n";
4545 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4548 if ($#commitlist >= 100) {
4549 print "<div class=\"page_nav\">\n";
4550 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4551 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4558 $hash ||= $hash_base || "HEAD";
4559 my %co = parse_commit
($hash);
4561 die_error
(undef, "Unknown commit object");
4563 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4564 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4566 my $parent = $co{'parent'};
4567 my $parents = $co{'parents'}; # listref
4569 # we need to prepare $formats_nav before any parameter munging
4571 if (!defined $parent) {
4573 $formats_nav .= '(initial)';
4574 } elsif (@$parents == 1) {
4575 # single parent commit
4578 $cgi->a({-href
=> href
(action
=>"commit",
4580 esc_html
(substr($parent, 0, 7))) .
4587 $cgi->a({-href
=> href
(action
=>"commit",
4589 esc_html
(substr($_, 0, 7)));
4594 if (!defined $parent) {
4598 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4600 (@$parents <= 1 ? $parent : '-c'),
4602 or die_error
(undef, "Open git-diff-tree failed");
4603 @difftree = map { chomp; $_ } <$fd>;
4604 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4606 # non-textual hash id's can be cached
4608 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4611 my $refs = git_get_references
();
4612 my $ref = format_ref_marker
($refs, $co{'id'});
4614 git_header_html
(undef, $expires);
4615 git_print_page_nav
('commit', '',
4616 $hash, $co{'tree'}, $hash,
4619 if (defined $co{'parent'}) {
4620 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4622 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4624 print "<div class=\"title_text\">\n" .
4625 "<table cellspacing=\"0\">\n";
4626 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4628 "<td></td><td> $ad{'rfc2822'}";
4629 if ($ad{'hour_local'} < 6) {
4630 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4631 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4633 printf(" (%02d:%02d %s)",
4634 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4638 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4639 print "<tr><td></td><td> $cd{'rfc2822'}" .
4640 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4642 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4645 "<td class=\"sha1\">" .
4646 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4647 class => "list"}, $co{'tree'}) .
4649 "<td class=\"link\">" .
4650 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4652 my $snapshot_links = format_snapshot_links
($hash);
4653 if (defined $snapshot_links) {
4654 print " | " . $snapshot_links;
4659 foreach my $par (@$parents) {
4662 "<td class=\"sha1\">" .
4663 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4664 class => "list"}, $par) .
4666 "<td class=\"link\">" .
4667 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4669 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4676 print "<div class=\"page_body\">\n";
4677 git_print_log
($co{'comment'});
4680 git_difftree_body
(\
@difftree, $hash, @$parents);
4686 # object is defined by:
4687 # - hash or hash_base alone
4688 # - hash_base and file_name
4691 # - hash or hash_base alone
4692 if ($hash || ($hash_base && !defined $file_name)) {
4693 my $object_id = $hash || $hash_base;
4695 my $git_command = git_cmd_str
();
4696 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4697 or die_error
('404 Not Found', "Object does not exist");
4701 or die_error
('404 Not Found', "Object does not exist");
4703 # - hash_base and file_name
4704 } elsif ($hash_base && defined $file_name) {
4705 $file_name =~ s
,/+$,,;
4707 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4708 or die_error
('404 Not Found', "Base object does not exist");
4710 # here errors should not hapen
4711 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4712 or die_error
(undef, "Open git-ls-tree failed");
4716 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4717 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4718 die_error
('404 Not Found', "File or directory for given base does not exist");
4723 die_error
('404 Not Found', "Not enough information to find object");
4726 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4727 hash
=>$hash, hash_base
=>$hash_base,
4728 file_name
=>$file_name),
4729 -status
=> '302 Found');
4733 my $format = shift || 'html';
4740 # preparing $fd and %diffinfo for git_patchset_body
4742 if (defined $hash_base && defined $hash_parent_base) {
4743 if (defined $file_name) {
4745 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4746 $hash_parent_base, $hash_base,
4747 "--", (defined $file_parent ? $file_parent : ()), $file_name
4748 or die_error
(undef, "Open git-diff-tree failed");
4749 @difftree = map { chomp; $_ } <$fd>;
4751 or die_error
(undef, "Reading git-diff-tree failed");
4753 or die_error
('404 Not Found', "Blob diff not found");
4755 } elsif (defined $hash &&
4756 $hash =~ /[0-9a-fA-F]{40}/) {
4757 # try to find filename from $hash
4759 # read filtered raw output
4760 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4761 $hash_parent_base, $hash_base, "--"
4762 or die_error
(undef, "Open git-diff-tree failed");
4764 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4766 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4767 map { chomp; $_ } <$fd>;
4769 or die_error
(undef, "Reading git-diff-tree failed");
4771 or die_error
('404 Not Found', "Blob diff not found");
4774 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4777 if (@difftree > 1) {
4778 die_error
('404 Not Found', "Ambiguous blob diff specification");
4781 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4782 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4783 $file_name ||= $diffinfo{'to_file'};
4785 $hash_parent ||= $diffinfo{'from_id'};
4786 $hash ||= $diffinfo{'to_id'};
4788 # non-textual hash id's can be cached
4789 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4790 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4795 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4796 '-p', ($format eq 'html' ? "--full-index" : ()),
4797 $hash_parent_base, $hash_base,
4798 "--", (defined $file_parent ? $file_parent : ()), $file_name
4799 or die_error
(undef, "Open git-diff-tree failed");
4802 # old/legacy style URI
4803 if (!%diffinfo && # if new style URI failed
4804 defined $hash && defined $hash_parent) {
4805 # fake git-diff-tree raw output
4806 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4807 $diffinfo{'from_id'} = $hash_parent;
4808 $diffinfo{'to_id'} = $hash;
4809 if (defined $file_name) {
4810 if (defined $file_parent) {
4811 $diffinfo{'status'} = '2';
4812 $diffinfo{'from_file'} = $file_parent;
4813 $diffinfo{'to_file'} = $file_name;
4814 } else { # assume not renamed
4815 $diffinfo{'status'} = '1';
4816 $diffinfo{'from_file'} = $file_name;
4817 $diffinfo{'to_file'} = $file_name;
4819 } else { # no filename given
4820 $diffinfo{'status'} = '2';
4821 $diffinfo{'from_file'} = $hash_parent;
4822 $diffinfo{'to_file'} = $hash;
4825 # non-textual hash id's can be cached
4826 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4827 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4832 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4833 '-p', ($format eq 'html' ? "--full-index" : ()),
4834 $hash_parent, $hash, "--"
4835 or die_error
(undef, "Open git-diff failed");
4837 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4842 if ($format eq 'html') {
4844 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4846 git_header_html
(undef, $expires);
4847 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4848 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4849 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4851 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4852 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4854 if (defined $file_name) {
4855 git_print_page_path
($file_name, "blob", $hash_base);
4857 print "<div class=\"page_path\"></div>\n";
4860 } elsif ($format eq 'plain') {
4862 -type
=> 'text/plain',
4863 -charset
=> 'utf-8',
4864 -expires
=> $expires,
4865 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4867 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4870 die_error
(undef, "Unknown blobdiff format");
4874 if ($format eq 'html') {
4875 print "<div class=\"page_body\">\n";
4877 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4880 print "</div>\n"; # class="page_body"
4884 while (my $line = <$fd>) {
4885 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4886 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4890 last if $line =~ m!^\+\+\+!;
4898 sub git_blobdiff_plain
{
4899 git_blobdiff
('plain');
4902 sub git_commitdiff
{
4903 my $format = shift || 'html';
4904 $hash ||= $hash_base || "HEAD";
4905 my %co = parse_commit
($hash);
4907 die_error
(undef, "Unknown commit object");
4910 # choose format for commitdiff for merge
4911 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4912 $hash_parent = '--cc';
4914 # we need to prepare $formats_nav before almost any parameter munging
4916 if ($format eq 'html') {
4918 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4921 if (defined $hash_parent &&
4922 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4923 # commitdiff with two commits given
4924 my $hash_parent_short = $hash_parent;
4925 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4926 $hash_parent_short = substr($hash_parent, 0, 7);
4930 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4931 if ($co{'parents'}[$i] eq $hash_parent) {
4932 $formats_nav .= ' parent ' . ($i+1);
4936 $formats_nav .= ': ' .
4937 $cgi->a({-href
=> href
(action
=>"commitdiff",
4938 hash
=>$hash_parent)},
4939 esc_html
($hash_parent_short)) .
4941 } elsif (!$co{'parent'}) {
4943 $formats_nav .= ' (initial)';
4944 } elsif (scalar @{$co{'parents'}} == 1) {
4945 # single parent commit
4948 $cgi->a({-href
=> href
(action
=>"commitdiff",
4949 hash
=>$co{'parent'})},
4950 esc_html
(substr($co{'parent'}, 0, 7))) .
4954 if ($hash_parent eq '--cc') {
4955 $formats_nav .= ' | ' .
4956 $cgi->a({-href
=> href
(action
=>"commitdiff",
4957 hash
=>$hash, hash_parent
=>'-c')},
4959 } else { # $hash_parent eq '-c'
4960 $formats_nav .= ' | ' .
4961 $cgi->a({-href
=> href
(action
=>"commitdiff",
4962 hash
=>$hash, hash_parent
=>'--cc')},
4968 $cgi->a({-href
=> href
(action
=>"commitdiff",
4970 esc_html
(substr($_, 0, 7)));
4971 } @{$co{'parents'}} ) .
4976 my $hash_parent_param = $hash_parent;
4977 if (!defined $hash_parent_param) {
4978 # --cc for multiple parents, --root for parentless
4979 $hash_parent_param =
4980 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4986 if ($format eq 'html') {
4987 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4988 "--no-commit-id", "--patch-with-raw", "--full-index",
4989 $hash_parent_param, $hash, "--"
4990 or die_error
(undef, "Open git-diff-tree failed");
4992 while (my $line = <$fd>) {
4994 # empty line ends raw part of diff-tree output
4996 push @difftree, scalar parse_difftree_raw_line
($line);
4999 } elsif ($format eq 'plain') {
5000 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5001 '-p', $hash_parent_param, $hash, "--"
5002 or die_error
(undef, "Open git-diff-tree failed");
5005 die_error
(undef, "Unknown commitdiff format");
5008 # non-textual hash id's can be cached
5010 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5014 # write commit message
5015 if ($format eq 'html') {
5016 my $refs = git_get_references
();
5017 my $ref = format_ref_marker
($refs, $co{'id'});
5019 git_header_html
(undef, $expires);
5020 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5021 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5022 git_print_authorship
(\
%co);
5023 print "<div class=\"page_body\">\n";
5024 if (@{$co{'comment'}} > 1) {
5025 print "<div class=\"log\">\n";
5026 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5027 print "</div>\n"; # class="log"
5030 } elsif ($format eq 'plain') {
5031 my $refs = git_get_references
("tags");
5032 my $tagname = git_get_rev_name_tags
($hash);
5033 my $filename = basename
($project) . "-$hash.patch";
5036 -type
=> 'text/plain',
5037 -charset
=> 'utf-8',
5038 -expires
=> $expires,
5039 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5040 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5043 Date: $ad{'rfc2822'} ($ad{'tz_local'})
5044 Subject: $co{'title'}
5046 print "X-Git-Tag: $tagname\n" if $tagname;
5047 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5049 foreach my $line (@{$co{'comment'}}) {
5056 if ($format eq 'html') {
5057 my $use_parents = !defined $hash_parent ||
5058 $hash_parent eq '-c' || $hash_parent eq '--cc';
5059 git_difftree_body
(\
@difftree, $hash,
5060 $use_parents ? @{$co{'parents'}} : $hash_parent);
5063 git_patchset_body
($fd, \
@difftree, $hash,
5064 $use_parents ? @{$co{'parents'}} : $hash_parent);
5066 print "</div>\n"; # class="page_body"
5069 } elsif ($format eq 'plain') {
5073 or print "Reading git-diff-tree failed\n";
5077 sub git_commitdiff_plain
{
5078 git_commitdiff
('plain');
5082 if (!defined $hash_base) {
5083 $hash_base = git_get_head_hash
($project);
5085 if (!defined $page) {
5089 my %co = parse_commit
($hash_base);
5091 die_error
(undef, "Unknown commit object");
5094 my $refs = git_get_references
();
5095 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5097 if (!defined $hash && defined $file_name) {
5098 $hash = git_get_hash_by_path
($hash_base, $file_name);
5100 if (defined $hash) {
5101 $ftype = git_get_type
($hash);
5104 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5106 my $paging_nav = '';
5109 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5110 file_name
=>$file_name)},
5112 $paging_nav .= " ⋅ " .
5113 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5114 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5116 $paging_nav .= "first";
5117 $paging_nav .= " ⋅ prev";
5120 if ($#commitlist >= 100) {
5122 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5123 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5124 $paging_nav .= " ⋅ $next_link";
5126 $paging_nav .= " ⋅ next";
5130 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5131 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5132 git_print_page_path
($file_name, $ftype, $hash_base);
5134 git_history_body
(\
@commitlist, 0, 99,
5135 $refs, $hash_base, $ftype, $next_link);
5141 my ($have_search) = gitweb_check_feature
('search');
5142 if (!$have_search) {
5143 die_error
('403 Permission denied', "Permission denied");
5145 if (!defined $searchtext) {
5146 die_error
(undef, "Text field empty");
5148 if (!defined $hash) {
5149 $hash = git_get_head_hash
($project);
5151 my %co = parse_commit
($hash);
5153 die_error
(undef, "Unknown commit object");
5155 if (!defined $page) {
5159 $searchtype ||= 'commit';
5160 if ($searchtype eq 'pickaxe') {
5161 # pickaxe may take all resources of your box and run for several minutes
5162 # with every query - so decide by yourself how public you make this feature
5163 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5164 if (!$have_pickaxe) {
5165 die_error
('403 Permission denied', "Permission denied");
5168 if ($searchtype eq 'grep') {
5169 my ($have_grep) = gitweb_check_feature
('grep');
5171 die_error
('403 Permission denied', "Permission denied");
5177 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5179 if ($searchtype eq 'commit') {
5180 $greptype = "--grep=";
5181 } elsif ($searchtype eq 'author') {
5182 $greptype = "--author=";
5183 } elsif ($searchtype eq 'committer') {
5184 $greptype = "--committer=";
5186 $greptype .= $search_regexp;
5187 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5189 my $paging_nav = '';
5192 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5193 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5195 $paging_nav .= " ⋅ " .
5196 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5197 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5199 $paging_nav .= "first";
5200 $paging_nav .= " ⋅ prev";
5203 if ($#commitlist >= 100) {
5205 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5206 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5207 $paging_nav .= " ⋅ $next_link";
5209 $paging_nav .= " ⋅ next";
5212 if ($#commitlist >= 100) {
5215 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5216 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5217 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5220 if ($searchtype eq 'pickaxe') {
5221 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5222 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5224 print "<table cellspacing=\"0\">\n";
5227 my $git_command = git_cmd_str
();
5228 my $searchqtext = $searchtext;
5229 $searchqtext =~ s/'/'\\''/;
5230 open my $fd, "-|", "$git_command rev-list $hash | " .
5231 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5234 while (my $line = <$fd>) {
5235 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5238 $set{'from_id'} = $3;
5240 $set{'id'} = $set{'to_id'};
5241 if ($set{'id'} =~ m/0{40}/) {
5242 $set{'id'} = $set{'from_id'};
5244 if ($set{'id'} =~ m/0{40}/) {
5248 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5251 print "<tr class=\"dark\">\n";
5253 print "<tr class=\"light\">\n";
5256 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5257 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5258 "<td><i>" . $author . "</i></td>\n" .
5260 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5261 -class => "list subject"},
5262 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5263 while (my $setref = shift @files) {
5265 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5266 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5268 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5272 "<td class=\"link\">" .
5273 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5275 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5279 %co = parse_commit
($1);
5287 if ($searchtype eq 'grep') {
5288 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5289 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5291 print "<table cellspacing=\"0\">\n";
5295 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5297 while (my $line = <$fd>) {
5299 my ($file, $lno, $ltext, $binary);
5300 last if ($matches++ > 1000);
5301 if ($line =~ /^Binary file (.+) matches$/) {
5305 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5307 if ($file ne $lastfile) {
5308 $lastfile and print "</td></tr>\n";
5310 print "<tr class=\"dark\">\n";
5312 print "<tr class=\"light\">\n";
5314 print "<td class=\"list\">".
5315 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5316 file_name
=>"$file"),
5317 -class => "list"}, esc_path
($file));
5318 print "</td><td>\n";
5322 print "<div class=\"binary\">Binary file</div>\n";
5324 $ltext = untabify
($ltext);
5325 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5326 $ltext = esc_html
($1, -nbsp
=>1);
5327 $ltext .= '<span class="match">';
5328 $ltext .= esc_html
($2, -nbsp
=>1);
5329 $ltext .= '</span>';
5330 $ltext .= esc_html
($3, -nbsp
=>1);
5332 $ltext = esc_html
($ltext, -nbsp
=>1);
5334 print "<div class=\"pre\">" .
5335 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5336 file_name
=>"$file").'#l'.$lno,
5337 -class => "linenr"}, sprintf('%4i', $lno))
5338 . ' ' . $ltext . "</div>\n";
5342 print "</td></tr>\n";
5343 if ($matches > 1000) {
5344 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5347 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5356 sub git_search_help
{
5358 git_print_page_nav
('','', $hash,$hash,$hash);
5361 <dt><b>commit</b></dt>
5362 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5364 my ($have_grep) = gitweb_check_feature
('grep');
5367 <dt><b>grep</b></dt>
5368 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5369 a different one) are searched for the given
5370 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5371 (POSIX extended) and the matches are listed. On large
5372 trees, this search can take a while and put some strain on the server, so please use it with
5373 some consideration.</dd>
5377 <dt><b>author</b></dt>
5378 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5379 <dt><b>committer</b></dt>
5380 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5382 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5383 if ($have_pickaxe) {
5385 <dt><b>pickaxe</b></dt>
5386 <dd>All commits that caused the string to appear or disappear from any file (changes that
5387 added, removed or "modified" the string) will be listed. This search can take a while and
5388 takes a lot of strain on the server, so please use it wisely.</dd>
5396 my $head = git_get_head_hash
($project);
5397 if (!defined $hash) {
5400 if (!defined $page) {
5403 my $refs = git_get_references
();
5405 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5407 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5409 if ($#commitlist >= 100) {
5411 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5412 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5416 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5417 git_print_header_div
('summary', $project);
5419 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5424 ## ......................................................................
5425 ## feeds (RSS, Atom; OPML)
5428 my $format = shift || 'atom';
5429 my ($have_blame) = gitweb_check_feature
('blame');
5431 # Atom: http://www.atomenabled.org/developers/syndication/
5432 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5433 if ($format ne 'rss' && $format ne 'atom') {
5434 die_error
(undef, "Unknown web feed format");
5437 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5438 my $head = $hash || 'HEAD';
5439 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5443 my $content_type = "application/$format+xml";
5444 if (defined $cgi->http('HTTP_ACCEPT') &&
5445 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5446 # browser (feed reader) prefers text/xml
5447 $content_type = 'text/xml';
5449 if (defined($commitlist[0])) {
5450 %latest_commit = %{$commitlist[0]};
5451 %latest_date = parse_date
($latest_commit{'author_epoch'});
5453 -type
=> $content_type,
5454 -charset
=> 'utf-8',
5455 -last_modified
=> $latest_date{'rfc2822'});
5458 -type
=> $content_type,
5459 -charset
=> 'utf-8');
5462 # Optimization: skip generating the body if client asks only
5463 # for Last-Modified date.
5464 return if ($cgi->request_method() eq 'HEAD');
5467 my $title = "$site_name - $project/$action";
5468 my $feed_type = 'log';
5469 if (defined $hash) {
5470 $title .= " - '$hash'";
5471 $feed_type = 'branch log';
5472 if (defined $file_name) {
5473 $title .= " :: $file_name";
5474 $feed_type = 'history';
5476 } elsif (defined $file_name) {
5477 $title .= " - $file_name";
5478 $feed_type = 'history';
5480 $title .= " $feed_type";
5481 my $descr = git_get_project_description
($project);
5482 if (defined $descr) {
5483 $descr = esc_html
($descr);
5485 $descr = "$project " .
5486 ($format eq 'rss' ? 'RSS' : 'Atom') .
5489 my $owner = git_get_project_owner
($project);
5490 $owner = esc_html
($owner);
5494 if (defined $file_name) {
5495 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5496 } elsif (defined $hash) {
5497 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5499 $alt_url = href
(-full
=>1, action
=>"summary");
5501 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5502 if ($format eq 'rss') {
5504 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5507 print "<title>$title</title>\n" .
5508 "<link>$alt_url</link>\n" .
5509 "<description>$descr</description>\n" .
5510 "<language>en</language>\n";
5511 } elsif ($format eq 'atom') {
5513 <feed xmlns="http://www.w3.org/2005/Atom">
5515 print "<title>$title</title>\n" .
5516 "<subtitle>$descr</subtitle>\n" .
5517 '<link rel="alternate" type="text/html" href="' .
5518 $alt_url . '" />' . "\n" .
5519 '<link rel="self" type="' . $content_type . '" href="' .
5520 $cgi->self_url() . '" />' . "\n" .
5521 "<id>" . href
(-full
=>1) . "</id>\n" .
5522 # use project owner for feed author
5523 "<author><name>$owner</name></author>\n";
5524 if (defined $favicon) {
5525 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5527 if (defined $logo_url) {
5528 # not twice as wide as tall: 72 x 27 pixels
5529 print "<logo>" . esc_url
($logo) . "</logo>\n";
5531 if (! %latest_date) {
5532 # dummy date to keep the feed valid until commits trickle in:
5533 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5535 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5540 for (my $i = 0; $i <= $#commitlist; $i++) {
5541 my %co = %{$commitlist[$i]};
5542 my $commit = $co{'id'};
5543 # we read 150, we always show 30 and the ones more recent than 48 hours
5544 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5547 my %cd = parse_date
($co{'author_epoch'});
5549 # get list of changed files
5550 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5551 $co{'parent'} || "--root",
5552 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5554 my @difftree = map { chomp; $_ } <$fd>;
5558 # print element (entry, item)
5559 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5560 if ($format eq 'rss') {
5562 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5563 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5564 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5565 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5566 "<link>$co_url</link>\n" .
5567 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5568 "<content:encoded>" .
5570 } elsif ($format eq 'atom') {
5572 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5573 "<updated>$cd{'iso-8601'}</updated>\n" .
5575 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5576 if ($co{'author_email'}) {
5577 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5579 print "</author>\n" .
5580 # use committer for contributor
5582 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5583 if ($co{'committer_email'}) {
5584 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5586 print "</contributor>\n" .
5587 "<published>$cd{'iso-8601'}</published>\n" .
5588 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5589 "<id>$co_url</id>\n" .
5590 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5591 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5593 my $comment = $co{'comment'};
5595 foreach my $line (@$comment) {
5596 $line = esc_html
($line);
5599 print "</pre><ul>\n";
5600 foreach my $difftree_line (@difftree) {
5601 my %difftree = parse_difftree_raw_line
($difftree_line);
5602 next if !$difftree{'from_id'};
5604 my $file = $difftree{'file'} || $difftree{'to_file'};
5608 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5609 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5610 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5611 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5612 -title
=> "diff"}, 'D');
5614 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5615 file_name
=>$file, hash_base
=>$commit),
5616 -title
=> "blame"}, 'B');
5618 # if this is not a feed of a file history
5619 if (!defined $file_name || $file_name ne $file) {
5620 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5621 file_name
=>$file, hash
=>$commit),
5622 -title
=> "history"}, 'H');
5624 $file = esc_path
($file);
5628 if ($format eq 'rss') {
5629 print "</ul>]]>\n" .
5630 "</content:encoded>\n" .
5632 } elsif ($format eq 'atom') {
5633 print "</ul>\n</div>\n" .
5640 if ($format eq 'rss') {
5641 print "</channel>\n</rss>\n";
5642 } elsif ($format eq 'atom') {
5656 my @list = git_get_projects_list
();
5658 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5660 <?xml version="1.0" encoding="utf-8"?>
5661 <opml version="1.0">
5663 <title>$site_name OPML Export</title>
5666 <outline text="git RSS feeds">
5669 foreach my $pr (@list) {
5671 my $head = git_get_head_hash
($proj{'path'});
5672 if (!defined $head) {
5675 $git_dir = "$projectroot/$proj{'path'}";
5676 my %co = parse_commit
($head);
5681 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5682 my $rss = "$my_url?p=$proj{'path'};a=rss";
5683 my $html = "$my_url?p=$proj{'path'};a=summary";
5684 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";