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 $params{'project'} = $project unless exists $params{'project'};
617 if ($params{-replay
}) {
618 while (my ($name, $symbol) = each %mapping) {
619 if (!exists $params{$name}) {
620 # to allow for multivalued params we use arrayref form
621 $params{$name} = [ $cgi->param($symbol) ];
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
699 if (utf8
::valid
($str)) {
703 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
707 # quote unsafe chars, but keep the slash, even when it's not
708 # correct, but quoted slashes look too horrible in bookmarks
711 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
717 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
720 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
726 # replace invalid utf8 character with SUBSTITUTION sequence
731 $str = to_utf8
($str);
732 $str = $cgi->escapeHTML($str);
733 if ($opts{'-nbsp'}) {
734 $str =~ s/ / /g;
736 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
740 # quote control characters and escape filename to HTML
745 $str = to_utf8
($str);
746 $str = $cgi->escapeHTML($str);
747 if ($opts{'-nbsp'}) {
748 $str =~ s/ / /g;
750 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
754 # 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 if ($opts{-nohtml
}) {
775 return "<span class=\"cntrl\">$chr</span>";
779 # Alternatively use unicode control pictures codepoints,
780 # Unicode "printable representation" (PR)
785 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
786 if ($opts{-nohtml
}) {
789 return "<span class=\"cntrl\">$chr</span>";
793 # git may return quoted and escaped filenames
799 my %es = ( # character escape codes, aka escape sequences
800 't' => "\t", # tab (HT, TAB)
801 'n' => "\n", # newline (NL)
802 'r' => "\r", # return (CR)
803 'f' => "\f", # form feed (FF)
804 'b' => "\b", # backspace (BS)
805 'a' => "\a", # alarm (bell) (BEL)
806 'e' => "\e", # escape (ESC)
807 'v' => "\013", # vertical tab (VT)
810 if ($seq =~ m/^[0-7]{1,3}$/) {
811 # octal char sequence
812 return chr(oct($seq));
813 } elsif (exists $es{$seq}) {
814 # C escape sequence, aka character escape code
817 # quoted ordinary character
821 if ($str =~ m/^"(.*)"$/) {
824 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
829 # escape tabs (convert tabs to spaces)
833 while ((my $pos = index($line, "\t")) != -1) {
834 if (my $count = (8 - ($pos % 8))) {
835 my $spaces = ' ' x
$count;
836 $line =~ s/\t/$spaces/;
843 sub project_in_list
{
845 my @list = git_get_projects_list
();
846 return @list && scalar(grep { $_->{'path'} eq $project } @list);
849 ## ----------------------------------------------------------------------
850 ## HTML aware string manipulation
855 my $add_len = shift || 10;
857 # allow only $len chars, but don't cut a word if it would fit in $add_len
858 # if it doesn't fit, cut it if it's still longer than the dots we would add
859 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
862 if (length($tail) > 4) {
864 $body =~ s/&[^;]*$//; # remove chopped character entities
869 # takes the same arguments as chop_str, but also wraps a <span> around the
870 # result with a title attribute if it does get chopped. Additionally, the
871 # string is HTML-escaped.
872 sub chop_and_escape_str
{
875 my $add_len = shift || 10;
877 my $chopped = chop_str
($str, $len, $add_len);
878 if ($chopped eq $str) {
879 return esc_html
($chopped);
881 $str =~ s/([[:cntrl:]])/?/g;
882 return $cgi->span({-title
=>$str}, esc_html
($chopped));
886 ## ----------------------------------------------------------------------
887 ## functions returning short strings
889 # CSS class for given age value (in seconds)
895 } elsif ($age < 60*60*2) {
897 } elsif ($age < 60*60*24*2) {
904 # convert age in seconds to "nn units ago" string
909 if ($age > 60*60*24*365*2) {
910 $age_str = (int $age/60/60/24/365);
911 $age_str .= " years ago";
912 } elsif ($age > 60*60*24*(365/12)*2) {
913 $age_str = int $age/60/60/24/(365/12);
914 $age_str .= " months ago";
915 } elsif ($age > 60*60*24*7*2) {
916 $age_str = int $age/60/60/24/7;
917 $age_str .= " weeks ago";
918 } elsif ($age > 60*60*24*2) {
919 $age_str = int $age/60/60/24;
920 $age_str .= " days ago";
921 } elsif ($age > 60*60*2) {
922 $age_str = int $age/60/60;
923 $age_str .= " hours ago";
924 } elsif ($age > 60*2) {
925 $age_str = int $age/60;
926 $age_str .= " min ago";
929 $age_str .= " sec ago";
931 $age_str .= " right now";
937 S_IFINVALID
=> 0030000,
938 S_IFGITLINK
=> 0160000,
941 # submodule/subproject, a commit object reference
945 return (($mode & S_IFMT
) == S_IFGITLINK
)
948 # convert file mode in octal to symbolic file mode string
950 my $mode = oct shift;
952 if (S_ISGITLINK
($mode)) {
954 } elsif (S_ISDIR
($mode & S_IFMT
)) {
956 } elsif (S_ISLNK
($mode)) {
958 } elsif (S_ISREG
($mode)) {
959 # git cares only about the executable bit
960 if ($mode & S_IXUSR
) {
970 # convert file mode in octal to file type string
974 if ($mode !~ m/^[0-7]+$/) {
980 if (S_ISGITLINK
($mode)) {
982 } elsif (S_ISDIR
($mode & S_IFMT
)) {
984 } elsif (S_ISLNK
($mode)) {
986 } elsif (S_ISREG
($mode)) {
993 # convert file mode in octal to file type description string
997 if ($mode !~ m/^[0-7]+$/) {
1003 if (S_ISGITLINK
($mode)) {
1005 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1007 } elsif (S_ISLNK
($mode)) {
1009 } elsif (S_ISREG
($mode)) {
1010 if ($mode & S_IXUSR
) {
1011 return "executable";
1021 ## ----------------------------------------------------------------------
1022 ## functions returning short HTML fragments, or transforming HTML fragments
1023 ## which don't belong to other sections
1025 # format line of commit message.
1026 sub format_log_line_html
{
1029 $line = esc_html
($line, -nbsp
=>1);
1030 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1033 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1034 -class => "text"}, $hash_text);
1035 $line =~ s/$hash_text/$link/;
1040 # format marker of refs pointing to given object
1041 sub format_ref_marker
{
1042 my ($refs, $id) = @_;
1045 if (defined $refs->{$id}) {
1046 foreach my $ref (@{$refs->{$id}}) {
1047 my ($type, $name) = qw();
1048 # e.g. tags/v2.6.11 or heads/next
1049 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1057 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1058 esc_html
($name) . "</span>";
1063 return ' <span class="refs">'. $markers . '</span>';
1069 # format, perhaps shortened and with markers, title line
1070 sub format_subject_html
{
1071 my ($long, $short, $href, $extra) = @_;
1072 $extra = '' unless defined($extra);
1074 if (length($short) < length($long)) {
1075 return $cgi->a({-href
=> $href, -class => "list subject",
1076 -title
=> to_utf8
($long)},
1077 esc_html
($short) . $extra);
1079 return $cgi->a({-href
=> $href, -class => "list subject"},
1080 esc_html
($long) . $extra);
1084 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1085 sub format_git_diff_header_line
{
1087 my $diffinfo = shift;
1088 my ($from, $to) = @_;
1090 if ($diffinfo->{'nparents'}) {
1092 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1093 if ($to->{'href'}) {
1094 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1095 esc_path
($to->{'file'}));
1096 } else { # file was deleted (no href)
1097 $line .= esc_path
($to->{'file'});
1101 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1102 if ($from->{'href'}) {
1103 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1104 'a/' . esc_path
($from->{'file'}));
1105 } else { # file was added (no href)
1106 $line .= 'a/' . esc_path
($from->{'file'});
1109 if ($to->{'href'}) {
1110 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1111 'b/' . esc_path
($to->{'file'}));
1112 } else { # file was deleted
1113 $line .= 'b/' . esc_path
($to->{'file'});
1117 return "<div class=\"diff header\">$line</div>\n";
1120 # format extended diff header line, before patch itself
1121 sub format_extended_diff_header_line
{
1123 my $diffinfo = shift;
1124 my ($from, $to) = @_;
1127 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1128 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1129 esc_path
($from->{'file'}));
1131 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1132 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1133 esc_path
($to->{'file'}));
1135 # match single <mode>
1136 if ($line =~ m/\s(\d{6})$/) {
1137 $line .= '<span class="info"> (' .
1138 file_type_long
($1) .
1142 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1143 # can match only for combined diff
1145 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1146 if ($from->{'href'}[$i]) {
1147 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1149 substr($diffinfo->{'from_id'}[$i],0,7));
1154 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1157 if ($to->{'href'}) {
1158 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1159 substr($diffinfo->{'to_id'},0,7));
1164 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1165 # can match only for ordinary diff
1166 my ($from_link, $to_link);
1167 if ($from->{'href'}) {
1168 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1169 substr($diffinfo->{'from_id'},0,7));
1171 $from_link = '0' x
7;
1173 if ($to->{'href'}) {
1174 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1175 substr($diffinfo->{'to_id'},0,7));
1179 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1180 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1183 return $line . "<br/>\n";
1186 # format from-file/to-file diff header
1187 sub format_diff_from_to_header
{
1188 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1193 #assert($line =~ m/^---/) if DEBUG;
1194 # no extra formatting for "^--- /dev/null"
1195 if (! $diffinfo->{'nparents'}) {
1196 # ordinary (single parent) diff
1197 if ($line =~ m!^--- "?a/!) {
1198 if ($from->{'href'}) {
1200 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1201 esc_path
($from->{'file'}));
1204 esc_path
($from->{'file'});
1207 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1210 # combined diff (merge commit)
1211 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1212 if ($from->{'href'}[$i]) {
1214 $cgi->a({-href
=>href
(action
=>"blobdiff",
1215 hash_parent
=>$diffinfo->{'from_id'}[$i],
1216 hash_parent_base
=>$parents[$i],
1217 file_parent
=>$from->{'file'}[$i],
1218 hash
=>$diffinfo->{'to_id'},
1220 file_name
=>$to->{'file'}),
1222 -title
=>"diff" . ($i+1)},
1225 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1226 esc_path
($from->{'file'}[$i]));
1228 $line = '--- /dev/null';
1230 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1235 #assert($line =~ m/^\+\+\+/) if DEBUG;
1236 # no extra formatting for "^+++ /dev/null"
1237 if ($line =~ m!^\+\+\+ "?b/!) {
1238 if ($to->{'href'}) {
1240 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1241 esc_path
($to->{'file'}));
1244 esc_path
($to->{'file'});
1247 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1252 # create note for patch simplified by combined diff
1253 sub format_diff_cc_simplified
{
1254 my ($diffinfo, @parents) = @_;
1257 $result .= "<div class=\"diff header\">" .
1259 if (!is_deleted
($diffinfo)) {
1260 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1262 hash
=>$diffinfo->{'to_id'},
1263 file_name
=>$diffinfo->{'to_file'}),
1265 esc_path
($diffinfo->{'to_file'}));
1267 $result .= esc_path
($diffinfo->{'to_file'});
1269 $result .= "</div>\n" . # class="diff header"
1270 "<div class=\"diff nodifferences\">" .
1272 "</div>\n"; # class="diff nodifferences"
1277 # format patch (diff) line (not to be used for diff headers)
1278 sub format_diff_line
{
1280 my ($from, $to) = @_;
1281 my $diff_class = "";
1285 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1287 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1288 if ($line =~ m/^\@{3}/) {
1289 $diff_class = " chunk_header";
1290 } elsif ($line =~ m/^\\/) {
1291 $diff_class = " incomplete";
1292 } elsif ($prefix =~ tr/+/+/) {
1293 $diff_class = " add";
1294 } elsif ($prefix =~ tr/-/-/) {
1295 $diff_class = " rem";
1298 # assume ordinary diff
1299 my $char = substr($line, 0, 1);
1301 $diff_class = " add";
1302 } elsif ($char eq '-') {
1303 $diff_class = " rem";
1304 } elsif ($char eq '@') {
1305 $diff_class = " chunk_header";
1306 } elsif ($char eq "\\") {
1307 $diff_class = " incomplete";
1310 $line = untabify
($line);
1311 if ($from && $to && $line =~ m/^\@{2} /) {
1312 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1313 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1315 $from_lines = 0 unless defined $from_lines;
1316 $to_lines = 0 unless defined $to_lines;
1318 if ($from->{'href'}) {
1319 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1320 -class=>"list"}, $from_text);
1322 if ($to->{'href'}) {
1323 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1324 -class=>"list"}, $to_text);
1326 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1327 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1328 return "<div class=\"diff$diff_class\">$line</div>\n";
1329 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1330 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1331 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1333 @from_text = split(' ', $ranges);
1334 for (my $i = 0; $i < @from_text; ++$i) {
1335 ($from_start[$i], $from_nlines[$i]) =
1336 (split(',', substr($from_text[$i], 1)), 0);
1339 $to_text = pop @from_text;
1340 $to_start = pop @from_start;
1341 $to_nlines = pop @from_nlines;
1343 $line = "<span class=\"chunk_info\">$prefix ";
1344 for (my $i = 0; $i < @from_text; ++$i) {
1345 if ($from->{'href'}[$i]) {
1346 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1347 -class=>"list"}, $from_text[$i]);
1349 $line .= $from_text[$i];
1353 if ($to->{'href'}) {
1354 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1355 -class=>"list"}, $to_text);
1359 $line .= " $prefix</span>" .
1360 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1361 return "<div class=\"diff$diff_class\">$line</div>\n";
1363 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1366 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1367 # linked. Pass the hash of the tree/commit to snapshot.
1368 sub format_snapshot_links
{
1370 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1371 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1372 my $num_fmts = @snapshot_fmts;
1373 if ($num_fmts > 1) {
1374 # A parenthesized list of links bearing format names.
1375 # e.g. "snapshot (_tar.gz_ _zip_)"
1376 return "snapshot (" . join(' ', map
1383 }, $known_snapshot_formats{$_}{'display'})
1384 , @snapshot_fmts) . ")";
1385 } elsif ($num_fmts == 1) {
1386 # A single "snapshot" link whose tooltip bears the format name.
1388 my ($fmt) = @snapshot_fmts;
1394 snapshot_format
=>$fmt
1396 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1398 } else { # $num_fmts == 0
1403 ## ----------------------------------------------------------------------
1404 ## git utility subroutines, invoking git commands
1406 # returns path to the core git executable and the --git-dir parameter as list
1408 return $GIT, '--git-dir='.$git_dir;
1411 # returns path to the core git executable and the --git-dir parameter as string
1413 return join(' ', git_cmd
());
1416 # get HEAD ref of given project as hash
1417 sub git_get_head_hash
{
1418 my $project = shift;
1419 my $o_git_dir = $git_dir;
1421 $git_dir = "$projectroot/$project";
1422 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1425 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1429 if (defined $o_git_dir) {
1430 $git_dir = $o_git_dir;
1435 # get type of given object
1439 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1441 close $fd or return;
1446 # repository configuration
1447 our $config_file = '';
1450 # store multiple values for single key as anonymous array reference
1451 # single values stored directly in the hash, not as [ <value> ]
1452 sub hash_set_multi
{
1453 my ($hash, $key, $value) = @_;
1455 if (!exists $hash->{$key}) {
1456 $hash->{$key} = $value;
1457 } elsif (!ref $hash->{$key}) {
1458 $hash->{$key} = [ $hash->{$key}, $value ];
1460 push @{$hash->{$key}}, $value;
1464 # return hash of git project configuration
1465 # optionally limited to some section, e.g. 'gitweb'
1466 sub git_parse_project_config
{
1467 my $section_regexp = shift;
1472 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1475 while (my $keyval = <$fh>) {
1477 my ($key, $value) = split(/\n/, $keyval, 2);
1479 hash_set_multi
(\
%config, $key, $value)
1480 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1487 # convert config value to boolean, 'true' or 'false'
1488 # no value, number > 0, 'true' and 'yes' values are true
1489 # rest of values are treated as false (never as error)
1490 sub config_to_bool
{
1493 # strip leading and trailing whitespace
1497 return (!defined $val || # section.key
1498 ($val =~ /^\d+$/ && $val) || # section.key = 1
1499 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1502 # convert config value to simple decimal number
1503 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1504 # to be multiplied by 1024, 1048576, or 1073741824
1508 # strip leading and trailing whitespace
1512 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1514 # unknown unit is treated as 1
1515 return $num * ($unit eq 'g' ? 1073741824 :
1516 $unit eq 'm' ? 1048576 :
1517 $unit eq 'k' ? 1024 : 1);
1522 # convert config value to array reference, if needed
1523 sub config_to_multi
{
1526 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1529 sub git_get_project_config
{
1530 my ($key, $type) = @_;
1533 return unless ($key);
1534 $key =~ s/^gitweb\.//;
1535 return if ($key =~ m/\W/);
1538 if (defined $type) {
1541 unless ($type eq 'bool' || $type eq 'int');
1545 if (!defined $config_file ||
1546 $config_file ne "$git_dir/config") {
1547 %config = git_parse_project_config
('gitweb');
1548 $config_file = "$git_dir/config";
1552 if (!defined $type) {
1553 return $config{"gitweb.$key"};
1554 } elsif ($type eq 'bool') {
1555 # backward compatibility: 'git config --bool' returns true/false
1556 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1557 } elsif ($type eq 'int') {
1558 return config_to_int
($config{"gitweb.$key"});
1560 return $config{"gitweb.$key"};
1563 # get hash of given path at given ref
1564 sub git_get_hash_by_path
{
1566 my $path = shift || return undef;
1571 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1572 or die_error
(undef, "Open git-ls-tree failed");
1574 close $fd or return undef;
1576 if (!defined $line) {
1577 # there is no tree or hash given by $path at $base
1581 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1582 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1583 if (defined $type && $type ne $2) {
1584 # type doesn't match
1590 # get path of entry with given hash at given tree-ish (ref)
1591 # used to get 'from' filename for combined diff (merge commit) for renames
1592 sub git_get_path_by_hash
{
1593 my $base = shift || return;
1594 my $hash = shift || return;
1598 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1600 while (my $line = <$fd>) {
1603 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1604 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1605 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1614 ## ......................................................................
1615 ## git utility functions, directly accessing git repository
1617 sub git_get_project_description
{
1620 $git_dir = "$projectroot/$path";
1621 open my $fd, "$git_dir/description"
1622 or return git_get_project_config
('description');
1625 if (defined $descr) {
1631 sub git_get_project_url_list
{
1634 $git_dir = "$projectroot/$path";
1635 open my $fd, "$git_dir/cloneurl"
1636 or return wantarray ?
1637 @{ config_to_multi
(git_get_project_config
('url')) } :
1638 config_to_multi
(git_get_project_config
('url'));
1639 my @git_project_url_list = map { chomp; $_ } <$fd>;
1642 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1645 sub git_get_projects_list
{
1650 $filter =~ s/\.git$//;
1652 my ($check_forks) = gitweb_check_feature
('forks');
1654 if (-d
$projects_list) {
1655 # search in directory
1656 my $dir = $projects_list . ($filter ? "/$filter" : '');
1657 # remove the trailing "/"
1659 my $pfxlen = length("$dir");
1660 my $pfxdepth = ($dir =~ tr!/!!);
1663 follow_fast
=> 1, # follow symbolic links
1664 follow_skip
=> 2, # ignore duplicates
1665 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1667 # skip project-list toplevel, if we get it.
1668 return if (m!^[/.]$!);
1669 # only directories can be git repositories
1670 return unless (-d
$_);
1671 # don't traverse too deep (Find is super slow on os x)
1672 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1673 $File::Find
::prune
= 1;
1677 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1678 # we check related file in $projectroot
1679 if ($check_forks and $subdir =~ m
#/.#) {
1680 $File::Find
::prune
= 1;
1681 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1682 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1683 $File::Find
::prune
= 1;
1688 } elsif (-f
$projects_list) {
1689 # read from file(url-encoded):
1690 # 'git%2Fgit.git Linus+Torvalds'
1691 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1692 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1694 open my ($fd), $projects_list or return;
1696 while (my $line = <$fd>) {
1698 my ($path, $owner) = split ' ', $line;
1699 $path = unescape
($path);
1700 $owner = unescape
($owner);
1701 if (!defined $path) {
1704 if ($filter ne '') {
1705 # looking for forks;
1706 my $pfx = substr($path, 0, length($filter));
1707 if ($pfx ne $filter) {
1710 my $sfx = substr($path, length($filter));
1711 if ($sfx !~ /^\/.*\
.git
$/) {
1714 } elsif ($check_forks) {
1716 foreach my $filter (keys %paths) {
1717 # looking for forks;
1718 my $pfx = substr($path, 0, length($filter));
1719 if ($pfx ne $filter) {
1722 my $sfx = substr($path, length($filter));
1723 if ($sfx !~ /^\/.*\
.git
$/) {
1726 # is a fork, don't include it in
1731 if (check_export_ok
("$projectroot/$path")) {
1734 owner
=> to_utf8
($owner),
1737 (my $forks_path = $path) =~ s/\.git$//;
1738 $paths{$forks_path}++;
1746 our $gitweb_project_owner = undef;
1747 sub git_get_project_list_from_file
{
1749 return if (defined $gitweb_project_owner);
1751 $gitweb_project_owner = {};
1752 # read from file (url-encoded):
1753 # 'git%2Fgit.git Linus+Torvalds'
1754 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1755 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1756 if (-f
$projects_list) {
1757 open (my $fd , $projects_list);
1758 while (my $line = <$fd>) {
1760 my ($pr, $ow) = split ' ', $line;
1761 $pr = unescape
($pr);
1762 $ow = unescape
($ow);
1763 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1769 sub git_get_project_owner
{
1770 my $project = shift;
1773 return undef unless $project;
1774 $git_dir = "$projectroot/$project";
1776 if (!defined $gitweb_project_owner) {
1777 git_get_project_list_from_file
();
1780 if (exists $gitweb_project_owner->{$project}) {
1781 $owner = $gitweb_project_owner->{$project};
1783 if (!defined $owner){
1784 $owner = git_get_project_config
('owner');
1786 if (!defined $owner) {
1787 $owner = get_file_owner
("$git_dir");
1793 sub git_get_last_activity
{
1797 $git_dir = "$projectroot/$path";
1798 open($fd, "-|", git_cmd
(), 'for-each-ref',
1799 '--format=%(committer)',
1800 '--sort=-committerdate',
1802 'refs/heads') or return;
1803 my $most_recent = <$fd>;
1804 close $fd or return;
1805 if (defined $most_recent &&
1806 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1808 my $age = time - $timestamp;
1809 return ($age, age_string
($age));
1811 return (undef, undef);
1814 sub git_get_references
{
1815 my $type = shift || "";
1817 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1818 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1819 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1820 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1823 while (my $line = <$fd>) {
1825 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1826 if (defined $refs{$1}) {
1827 push @{$refs{$1}}, $2;
1833 close $fd or return;
1837 sub git_get_rev_name_tags
{
1838 my $hash = shift || return undef;
1840 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1842 my $name_rev = <$fd>;
1845 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1848 # catches also '$hash undefined' output
1853 ## ----------------------------------------------------------------------
1854 ## parse to hash functions
1858 my $tz = shift || "-0000";
1861 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1862 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1863 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1864 $date{'hour'} = $hour;
1865 $date{'minute'} = $min;
1866 $date{'mday'} = $mday;
1867 $date{'day'} = $days[$wday];
1868 $date{'month'} = $months[$mon];
1869 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1870 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1871 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1872 $mday, $months[$mon], $hour ,$min;
1873 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1874 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1876 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1877 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1878 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1879 $date{'hour_local'} = $hour;
1880 $date{'minute_local'} = $min;
1881 $date{'tz_local'} = $tz;
1882 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1883 1900+$year, $mon+1, $mday,
1884 $hour, $min, $sec, $tz);
1893 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1894 $tag{'id'} = $tag_id;
1895 while (my $line = <$fd>) {
1897 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1898 $tag{'object'} = $1;
1899 } elsif ($line =~ m/^type (.+)$/) {
1901 } elsif ($line =~ m/^tag (.+)$/) {
1903 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1904 $tag{'author'} = $1;
1907 } elsif ($line =~ m/--BEGIN/) {
1908 push @comment, $line;
1910 } elsif ($line eq "") {
1914 push @comment, <$fd>;
1915 $tag{'comment'} = \
@comment;
1916 close $fd or return;
1917 if (!defined $tag{'name'}) {
1923 sub parse_commit_text
{
1924 my ($commit_text, $withparents) = @_;
1925 my @commit_lines = split '\n', $commit_text;
1928 pop @commit_lines; # Remove '\0'
1930 if (! @commit_lines) {
1934 my $header = shift @commit_lines;
1935 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1938 ($co{'id'}, my @parents) = split ' ', $header;
1939 while (my $line = shift @commit_lines) {
1940 last if $line eq "\n";
1941 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1943 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1945 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1947 $co{'author_epoch'} = $2;
1948 $co{'author_tz'} = $3;
1949 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1950 $co{'author_name'} = $1;
1951 $co{'author_email'} = $2;
1953 $co{'author_name'} = $co{'author'};
1955 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1956 $co{'committer'} = $1;
1957 $co{'committer_epoch'} = $2;
1958 $co{'committer_tz'} = $3;
1959 $co{'committer_name'} = $co{'committer'};
1960 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1961 $co{'committer_name'} = $1;
1962 $co{'committer_email'} = $2;
1964 $co{'committer_name'} = $co{'committer'};
1968 if (!defined $co{'tree'}) {
1971 $co{'parents'} = \
@parents;
1972 $co{'parent'} = $parents[0];
1974 foreach my $title (@commit_lines) {
1977 $co{'title'} = chop_str
($title, 80, 5);
1978 # remove leading stuff of merges to make the interesting part visible
1979 if (length($title) > 50) {
1980 $title =~ s/^Automatic //;
1981 $title =~ s/^merge (of|with) /Merge ... /i;
1982 if (length($title) > 50) {
1983 $title =~ s/(http|rsync):\/\///;
1985 if (length($title) > 50) {
1986 $title =~ s/(master|www|rsync)\.//;
1988 if (length($title) > 50) {
1989 $title =~ s/kernel.org:?//;
1991 if (length($title) > 50) {
1992 $title =~ s/\/pub\/scm//;
1995 $co{'title_short'} = chop_str
($title, 50, 5);
1999 if ($co{'title'} eq "") {
2000 $co{'title'} = $co{'title_short'} = '(no commit message)';
2002 # remove added spaces
2003 foreach my $line (@commit_lines) {
2006 $co{'comment'} = \
@commit_lines;
2008 my $age = time - $co{'committer_epoch'};
2010 $co{'age_string'} = age_string
($age);
2011 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2012 if ($age > 60*60*24*7*2) {
2013 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2014 $co{'age_string_age'} = $co{'age_string'};
2016 $co{'age_string_date'} = $co{'age_string'};
2017 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2023 my ($commit_id) = @_;
2028 open my $fd, "-|", git_cmd
(), "rev-list",
2034 or die_error
(undef, "Open git-rev-list failed");
2035 %co = parse_commit_text
(<$fd>, 1);
2042 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
2050 open my $fd, "-|", git_cmd
(), "rev-list",
2052 ($arg ? ($arg) : ()),
2053 ("--max-count=" . $maxcount),
2054 ("--skip=" . $skip),
2058 ($filename ? ($filename) : ())
2059 or die_error
(undef, "Open git-rev-list failed");
2060 while (my $line = <$fd>) {
2061 my %co = parse_commit_text
($line);
2066 return wantarray ? @cos : \
@cos;
2069 # parse ref from ref_file, given by ref_id, with given type
2071 my $ref_file = shift;
2073 my $type = shift || git_get_type
($ref_id);
2076 $ref_item{'type'} = $type;
2077 $ref_item{'id'} = $ref_id;
2078 $ref_item{'epoch'} = 0;
2079 $ref_item{'age'} = "unknown";
2080 if ($type eq "tag") {
2081 my %tag = parse_tag
($ref_id);
2082 $ref_item{'comment'} = $tag{'comment'};
2083 if ($tag{'type'} eq "commit") {
2084 my %co = parse_commit
($tag{'object'});
2085 $ref_item{'epoch'} = $co{'committer_epoch'};
2086 $ref_item{'age'} = $co{'age_string'};
2087 } elsif (defined($tag{'epoch'})) {
2088 my $age = time - $tag{'epoch'};
2089 $ref_item{'epoch'} = $tag{'epoch'};
2090 $ref_item{'age'} = age_string
($age);
2092 $ref_item{'reftype'} = $tag{'type'};
2093 $ref_item{'name'} = $tag{'name'};
2094 $ref_item{'refid'} = $tag{'object'};
2095 } elsif ($type eq "commit"){
2096 my %co = parse_commit
($ref_id);
2097 $ref_item{'reftype'} = "commit";
2098 $ref_item{'name'} = $ref_file;
2099 $ref_item{'title'} = $co{'title'};
2100 $ref_item{'refid'} = $ref_id;
2101 $ref_item{'epoch'} = $co{'committer_epoch'};
2102 $ref_item{'age'} = $co{'age_string'};
2104 $ref_item{'reftype'} = $type;
2105 $ref_item{'name'} = $ref_file;
2106 $ref_item{'refid'} = $ref_id;
2112 # parse line of git-diff-tree "raw" output
2113 sub parse_difftree_raw_line
{
2117 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2118 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2119 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2120 $res{'from_mode'} = $1;
2121 $res{'to_mode'} = $2;
2122 $res{'from_id'} = $3;
2124 $res{'status'} = $res{'status_str'} = $5;
2125 $res{'similarity'} = $6;
2126 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2127 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2129 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2132 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2133 # combined diff (for merge commit)
2134 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2135 $res{'nparents'} = length($1);
2136 $res{'from_mode'} = [ split(' ', $2) ];
2137 $res{'to_mode'} = pop @{$res{'from_mode'}};
2138 $res{'from_id'} = [ split(' ', $3) ];
2139 $res{'to_id'} = pop @{$res{'from_id'}};
2140 $res{'status_str'} = $4;
2141 $res{'status'} = [ split('', $4) ];
2142 $res{'to_file'} = unquote
($5);
2144 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2145 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2146 $res{'commit'} = $1;
2149 return wantarray ? %res : \
%res;
2152 # wrapper: return parsed line of git-diff-tree "raw" output
2153 # (the argument might be raw line, or parsed info)
2154 sub parsed_difftree_line
{
2155 my $line_or_ref = shift;
2157 if (ref($line_or_ref) eq "HASH") {
2158 # pre-parsed (or generated by hand)
2159 return $line_or_ref;
2161 return parse_difftree_raw_line
($line_or_ref);
2165 # parse line of git-ls-tree output
2166 sub parse_ls_tree_line
($;%) {
2171 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2172 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2180 $res{'name'} = unquote
($4);
2183 return wantarray ? %res : \
%res;
2186 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2187 sub parse_from_to_diffinfo
{
2188 my ($diffinfo, $from, $to, @parents) = @_;
2190 if ($diffinfo->{'nparents'}) {
2192 $from->{'file'} = [];
2193 $from->{'href'} = [];
2194 fill_from_file_info
($diffinfo, @parents)
2195 unless exists $diffinfo->{'from_file'};
2196 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2197 $from->{'file'}[$i] =
2198 defined $diffinfo->{'from_file'}[$i] ?
2199 $diffinfo->{'from_file'}[$i] :
2200 $diffinfo->{'to_file'};
2201 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2202 $from->{'href'}[$i] = href
(action
=>"blob",
2203 hash_base
=>$parents[$i],
2204 hash
=>$diffinfo->{'from_id'}[$i],
2205 file_name
=>$from->{'file'}[$i]);
2207 $from->{'href'}[$i] = undef;
2211 # ordinary (not combined) diff
2212 $from->{'file'} = $diffinfo->{'from_file'};
2213 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2214 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2215 hash
=>$diffinfo->{'from_id'},
2216 file_name
=>$from->{'file'});
2218 delete $from->{'href'};
2222 $to->{'file'} = $diffinfo->{'to_file'};
2223 if (!is_deleted
($diffinfo)) { # file exists in result
2224 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2225 hash
=>$diffinfo->{'to_id'},
2226 file_name
=>$to->{'file'});
2228 delete $to->{'href'};
2232 ## ......................................................................
2233 ## parse to array of hashes functions
2235 sub git_get_heads_list
{
2239 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2240 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2241 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2244 while (my $line = <$fd>) {
2248 my ($refinfo, $committerinfo) = split(/\0/, $line);
2249 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2250 my ($committer, $epoch, $tz) =
2251 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2252 $ref_item{'fullname'} = $name;
2253 $name =~ s!^refs/heads/!!;
2255 $ref_item{'name'} = $name;
2256 $ref_item{'id'} = $hash;
2257 $ref_item{'title'} = $title || '(no commit message)';
2258 $ref_item{'epoch'} = $epoch;
2260 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2262 $ref_item{'age'} = "unknown";
2265 push @headslist, \
%ref_item;
2269 return wantarray ? @headslist : \
@headslist;
2272 sub git_get_tags_list
{
2276 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2277 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2278 '--format=%(objectname) %(objecttype) %(refname) '.
2279 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2282 while (my $line = <$fd>) {
2286 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2287 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2288 my ($creator, $epoch, $tz) =
2289 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2290 $ref_item{'fullname'} = $name;
2291 $name =~ s!^refs/tags/!!;
2293 $ref_item{'type'} = $type;
2294 $ref_item{'id'} = $id;
2295 $ref_item{'name'} = $name;
2296 if ($type eq "tag") {
2297 $ref_item{'subject'} = $title;
2298 $ref_item{'reftype'} = $reftype;
2299 $ref_item{'refid'} = $refid;
2301 $ref_item{'reftype'} = $type;
2302 $ref_item{'refid'} = $id;
2305 if ($type eq "tag" || $type eq "commit") {
2306 $ref_item{'epoch'} = $epoch;
2308 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2310 $ref_item{'age'} = "unknown";
2314 push @tagslist, \
%ref_item;
2318 return wantarray ? @tagslist : \
@tagslist;
2321 ## ----------------------------------------------------------------------
2322 ## filesystem-related functions
2324 sub get_file_owner
{
2327 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2328 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2329 if (!defined $gcos) {
2333 $owner =~ s/[,;].*$//;
2334 return to_utf8
($owner);
2337 ## ......................................................................
2338 ## mimetype related functions
2340 sub mimetype_guess_file
{
2341 my $filename = shift;
2342 my $mimemap = shift;
2343 -r
$mimemap or return undef;
2346 open(MIME
, $mimemap) or return undef;
2348 next if m/^#/; # skip comments
2349 my ($mime, $exts) = split(/\t+/);
2350 if (defined $exts) {
2351 my @exts = split(/\s+/, $exts);
2352 foreach my $ext (@exts) {
2353 $mimemap{$ext} = $mime;
2359 $filename =~ /\.([^.]*)$/;
2360 return $mimemap{$1};
2363 sub mimetype_guess
{
2364 my $filename = shift;
2366 $filename =~ /\./ or return undef;
2368 if ($mimetypes_file) {
2369 my $file = $mimetypes_file;
2370 if ($file !~ m!^/!) { # if it is relative path
2371 # it is relative to project
2372 $file = "$projectroot/$project/$file";
2374 $mime = mimetype_guess_file
($filename, $file);
2376 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2382 my $filename = shift;
2385 my $mime = mimetype_guess
($filename);
2386 $mime and return $mime;
2390 return $default_blob_plain_mimetype unless $fd;
2393 return 'text/plain' .
2394 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2395 } elsif (! $filename) {
2396 return 'application/octet-stream';
2397 } elsif ($filename =~ m/\.png$/i) {
2399 } elsif ($filename =~ m/\.gif$/i) {
2401 } elsif ($filename =~ m/\.jpe?g$/i) {
2402 return 'image/jpeg';
2404 return 'application/octet-stream';
2408 ## ======================================================================
2409 ## functions printing HTML: header, footer, error page
2411 sub git_header_html
{
2412 my $status = shift || "200 OK";
2413 my $expires = shift;
2415 my $title = "$site_name";
2416 if (defined $project) {
2417 $title .= " - " . to_utf8
($project);
2418 if (defined $action) {
2419 $title .= "/$action";
2420 if (defined $file_name) {
2421 $title .= " - " . esc_path
($file_name);
2422 if ($action eq "tree" && $file_name !~ m
|/$|) {
2429 # require explicit support from the UA if we are to send the page as
2430 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2431 # we have to do this because MSIE sometimes globs '*/*', pretending to
2432 # support xhtml+xml but choking when it gets what it asked for.
2433 if (defined $cgi->http('HTTP_ACCEPT') &&
2434 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2435 $cgi->Accept('application/xhtml+xml') != 0) {
2436 $content_type = 'application/xhtml+xml';
2438 $content_type = 'text/html';
2440 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2441 -status
=> $status, -expires
=> $expires);
2442 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2444 <?xml version="1.0" encoding="utf-8"?>
2445 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2446 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2447 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2448 <!-- git core binaries version $git_version -->
2450 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2451 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2452 <meta name="robots" content="index, nofollow"/>
2453 <title>$title</title>
2455 # print out each stylesheet that exist
2456 if (defined $stylesheet) {
2457 #provides backwards capability for those people who define style sheet in a config file
2458 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2460 foreach my $stylesheet (@stylesheets) {
2461 next unless $stylesheet;
2462 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2465 if (defined $project) {
2466 printf('<link rel="alternate" title="%s log RSS feed" '.
2467 'href="%s" type="application/rss+xml" />'."\n",
2468 esc_param
($project), href
(action
=>"rss"));
2469 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2470 'href="%s" type="application/rss+xml" />'."\n",
2471 esc_param
($project), href
(action
=>"rss",
2472 extra_options
=>"--no-merges"));
2473 printf('<link rel="alternate" title="%s log Atom feed" '.
2474 'href="%s" type="application/atom+xml" />'."\n",
2475 esc_param
($project), href
(action
=>"atom"));
2476 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2477 'href="%s" type="application/atom+xml" />'."\n",
2478 esc_param
($project), href
(action
=>"atom",
2479 extra_options
=>"--no-merges"));
2481 printf('<link rel="alternate" title="%s projects list" '.
2482 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2483 $site_name, href
(project
=>undef, action
=>"project_index"));
2484 printf('<link rel="alternate" title="%s projects feeds" '.
2485 'href="%s" type="text/x-opml"/>'."\n",
2486 $site_name, href
(project
=>undef, action
=>"opml"));
2488 if (defined $favicon) {
2489 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2495 if (-f
$site_header) {
2496 open (my $fd, $site_header);
2501 print "<div class=\"page_header\">\n" .
2502 $cgi->a({-href
=> esc_url
($logo_url),
2503 -title
=> $logo_label},
2504 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2505 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2506 if (defined $project) {
2507 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2508 if (defined $action) {
2515 my ($have_search) = gitweb_check_feature
('search');
2516 if ((defined $project) && ($have_search)) {
2517 if (!defined $searchtext) {
2521 if (defined $hash_base) {
2522 $search_hash = $hash_base;
2523 } elsif (defined $hash) {
2524 $search_hash = $hash;
2526 $search_hash = "HEAD";
2528 my $action = $my_uri;
2529 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2530 if ($use_pathinfo) {
2531 $action .= "/$project";
2533 $cgi->param("p", $project);
2535 $cgi->param("a", "search");
2536 $cgi->param("h", $search_hash);
2537 print $cgi->startform(-method => "get", -action
=> $action) .
2538 "<div class=\"search\">\n" .
2539 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2540 $cgi->hidden(-name
=> "a") . "\n" .
2541 $cgi->hidden(-name
=> "h") . "\n" .
2542 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2543 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2544 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2546 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2548 $cgi->end_form() . "\n";
2552 sub git_footer_html
{
2553 print "<div class=\"page_footer\">\n";
2554 if (defined $project) {
2555 my $descr = git_get_project_description
($project);
2556 if (defined $descr) {
2557 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2559 print $cgi->a({-href
=> href
(action
=>"rss"),
2560 -class => "rss_logo"}, "RSS") . " ";
2561 print $cgi->a({-href
=> href
(action
=>"atom"),
2562 -class => "rss_logo"}, "Atom") . "\n";
2564 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2565 -class => "rss_logo"}, "OPML") . " ";
2566 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2567 -class => "rss_logo"}, "TXT") . "\n";
2571 if (-f
$site_footer) {
2572 open (my $fd, $site_footer);
2582 my $status = shift || "403 Forbidden";
2583 my $error = shift || "Malformed query, file missing or permission denied";
2585 git_header_html
($status);
2587 <div class="page_body">
2597 ## ----------------------------------------------------------------------
2598 ## functions printing or outputting HTML: navigation
2600 sub git_print_page_nav
{
2601 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2602 $extra = '' if !defined $extra; # pager or formats
2604 my @navs = qw(summary shortlog log commit commitdiff tree);
2606 @navs = grep { $_ ne $suppress } @navs;
2609 my %arg = map { $_ => {action
=>$_} } @navs;
2610 if (defined $head) {
2611 for (qw(commit commitdiff)) {
2612 $arg{$_}{'hash'} = $head;
2614 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2615 for (qw(shortlog log)) {
2616 $arg{$_}{'hash'} = $head;
2620 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2621 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2623 print "<div class=\"page_nav\">\n" .
2625 map { $_ eq $current ?
2626 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2628 print "<br/>\n$extra<br/>\n" .
2632 sub format_paging_nav
{
2633 my ($action, $hash, $head, $page, $nrevs) = @_;
2637 if ($hash ne $head || $page) {
2638 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2640 $paging_nav .= "HEAD";
2644 $paging_nav .= " ⋅ " .
2645 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2646 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2648 $paging_nav .= " ⋅ prev";
2651 if ($nrevs >= (100 * ($page+1)-1)) {
2652 $paging_nav .= " ⋅ " .
2653 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2654 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2656 $paging_nav .= " ⋅ next";
2662 ## ......................................................................
2663 ## functions printing or outputting HTML: div
2665 sub git_print_header_div
{
2666 my ($action, $title, $hash, $hash_base) = @_;
2669 $args{'action'} = $action;
2670 $args{'hash'} = $hash if $hash;
2671 $args{'hash_base'} = $hash_base if $hash_base;
2673 print "<div class=\"header\">\n" .
2674 $cgi->a({-href
=> href
(%args), -class => "title"},
2675 $title ? $title : $action) .
2679 #sub git_print_authorship (\%) {
2680 sub git_print_authorship
{
2683 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2684 print "<div class=\"author_date\">" .
2685 esc_html
($co->{'author_name'}) .
2687 if ($ad{'hour_local'} < 6) {
2688 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2689 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2691 printf(" (%02d:%02d %s)",
2692 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2697 sub git_print_page_path
{
2703 print "<div class=\"page_path\">";
2704 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2705 -title
=> 'tree root'}, to_utf8
("[$project]"));
2707 if (defined $name) {
2708 my @dirname = split '/', $name;
2709 my $basename = pop @dirname;
2712 foreach my $dir (@dirname) {
2713 $fullname .= ($fullname ? '/' : '') . $dir;
2714 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2716 -title
=> $fullname}, esc_path
($dir));
2719 if (defined $type && $type eq 'blob') {
2720 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2722 -title
=> $name}, esc_path
($basename));
2723 } elsif (defined $type && $type eq 'tree') {
2724 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2726 -title
=> $name}, esc_path
($basename));
2729 print esc_path
($basename);
2732 print "<br/></div>\n";
2735 # sub git_print_log (\@;%) {
2736 sub git_print_log
($;%) {
2740 if ($opts{'-remove_title'}) {
2741 # remove title, i.e. first line of log
2744 # remove leading empty lines
2745 while (defined $log->[0] && $log->[0] eq "") {
2752 foreach my $line (@$log) {
2753 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2756 if (! $opts{'-remove_signoff'}) {
2757 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2760 # remove signoff lines
2767 # print only one empty line
2768 # do not print empty line after signoff
2770 next if ($empty || $signoff);
2776 print format_log_line_html
($line) . "<br/>\n";
2779 if ($opts{'-final_empty_line'}) {
2780 # end with single empty line
2781 print "<br/>\n" unless $empty;
2785 # return link target (what link points to)
2786 sub git_get_link_target
{
2791 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2795 $link_target = <$fd>;
2800 return $link_target;
2803 # given link target, and the directory (basedir) the link is in,
2804 # return target of link relative to top directory (top tree);
2805 # return undef if it is not possible (including absolute links).
2806 sub normalize_link_target
{
2807 my ($link_target, $basedir, $hash_base) = @_;
2809 # we can normalize symlink target only if $hash_base is provided
2810 return unless $hash_base;
2812 # absolute symlinks (beginning with '/') cannot be normalized
2813 return if (substr($link_target, 0, 1) eq '/');
2815 # normalize link target to path from top (root) tree (dir)
2818 $path = $basedir . '/' . $link_target;
2820 # we are in top (root) tree (dir)
2821 $path = $link_target;
2824 # remove //, /./, and /../
2826 foreach my $part (split('/', $path)) {
2827 # discard '.' and ''
2828 next if (!$part || $part eq '.');
2830 if ($part eq '..') {
2834 # link leads outside repository (outside top dir)
2838 push @path_parts, $part;
2841 $path = join('/', @path_parts);
2846 # print tree entry (row of git_tree), but without encompassing <tr> element
2847 sub git_print_tree_entry
{
2848 my ($t, $basedir, $hash_base, $have_blame) = @_;
2851 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2853 # The format of a table row is: mode list link. Where mode is
2854 # the mode of the entry, list is the name of the entry, an href,
2855 # and link is the action links of the entry.
2857 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2858 if ($t->{'type'} eq "blob") {
2859 print "<td class=\"list\">" .
2860 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2861 file_name
=>"$basedir$t->{'name'}", %base_key),
2862 -class => "list"}, esc_path
($t->{'name'}));
2863 if (S_ISLNK
(oct $t->{'mode'})) {
2864 my $link_target = git_get_link_target
($t->{'hash'});
2866 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2867 if (defined $norm_target) {
2869 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2870 file_name
=>$norm_target),
2871 -title
=> $norm_target}, esc_path
($link_target));
2873 print " -> " . esc_path
($link_target);
2878 print "<td class=\"link\">";
2879 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2880 file_name
=>"$basedir$t->{'name'}", %base_key)},
2884 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2885 file_name
=>"$basedir$t->{'name'}", %base_key)},
2888 if (defined $hash_base) {
2890 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2891 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2895 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2896 file_name
=>"$basedir$t->{'name'}")},
2900 } elsif ($t->{'type'} eq "tree") {
2901 print "<td class=\"list\">";
2902 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2903 file_name
=>"$basedir$t->{'name'}", %base_key)},
2904 esc_path
($t->{'name'}));
2906 print "<td class=\"link\">";
2907 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2908 file_name
=>"$basedir$t->{'name'}", %base_key)},
2910 if (defined $hash_base) {
2912 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2913 file_name
=>"$basedir$t->{'name'}")},
2918 # unknown object: we can only present history for it
2919 # (this includes 'commit' object, i.e. submodule support)
2920 print "<td class=\"list\">" .
2921 esc_path
($t->{'name'}) .
2923 print "<td class=\"link\">";
2924 if (defined $hash_base) {
2925 print $cgi->a({-href
=> href
(action
=>"history",
2926 hash_base
=>$hash_base,
2927 file_name
=>"$basedir$t->{'name'}")},
2934 ## ......................................................................
2935 ## functions printing large fragments of HTML
2937 # get pre-image filenames for merge (combined) diff
2938 sub fill_from_file_info
{
2939 my ($diff, @parents) = @_;
2941 $diff->{'from_file'} = [ ];
2942 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2943 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2944 if ($diff->{'status'}[$i] eq 'R' ||
2945 $diff->{'status'}[$i] eq 'C') {
2946 $diff->{'from_file'}[$i] =
2947 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2954 # is current raw difftree line of file deletion
2956 my $diffinfo = shift;
2958 return $diffinfo->{'status_str'} =~ /D/;
2961 # does patch correspond to [previous] difftree raw line
2962 # $diffinfo - hashref of parsed raw diff format
2963 # $patchinfo - hashref of parsed patch diff format
2964 # (the same keys as in $diffinfo)
2965 sub is_patch_split
{
2966 my ($diffinfo, $patchinfo) = @_;
2968 return defined $diffinfo && defined $patchinfo
2969 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2973 sub git_difftree_body
{
2974 my ($difftree, $hash, @parents) = @_;
2975 my ($parent) = $parents[0];
2976 my ($have_blame) = gitweb_check_feature
('blame');
2977 print "<div class=\"list_head\">\n";
2978 if ($#{$difftree} > 10) {
2979 print(($#{$difftree} + 1) . " files changed:\n");
2983 print "<table class=\"" .
2984 (@parents > 1 ? "combined " : "") .
2987 # header only for combined diff in 'commitdiff' view
2988 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2991 print "<thead><tr>\n" .
2992 "<th></th><th></th>\n"; # filename, patchN link
2993 for (my $i = 0; $i < @parents; $i++) {
2994 my $par = $parents[$i];
2996 $cgi->a({-href
=> href
(action
=>"commitdiff",
2997 hash
=>$hash, hash_parent
=>$par),
2998 -title
=> 'commitdiff to parent number ' .
2999 ($i+1) . ': ' . substr($par,0,7)},
3003 print "</tr></thead>\n<tbody>\n";
3008 foreach my $line (@{$difftree}) {
3009 my $diff = parsed_difftree_line
($line);
3012 print "<tr class=\"dark\">\n";
3014 print "<tr class=\"light\">\n";
3018 if (exists $diff->{'nparents'}) { # combined diff
3020 fill_from_file_info
($diff, @parents)
3021 unless exists $diff->{'from_file'};
3023 if (!is_deleted
($diff)) {
3024 # file exists in the result (child) commit
3026 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3027 file_name
=>$diff->{'to_file'},
3029 -class => "list"}, esc_path
($diff->{'to_file'})) .
3033 esc_path
($diff->{'to_file'}) .
3037 if ($action eq 'commitdiff') {
3040 print "<td class=\"link\">" .
3041 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3046 my $has_history = 0;
3047 my $not_deleted = 0;
3048 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3049 my $hash_parent = $parents[$i];
3050 my $from_hash = $diff->{'from_id'}[$i];
3051 my $from_path = $diff->{'from_file'}[$i];
3052 my $status = $diff->{'status'}[$i];
3054 $has_history ||= ($status ne 'A');
3055 $not_deleted ||= ($status ne 'D');
3057 if ($status eq 'A') {
3058 print "<td class=\"link\" align=\"right\"> | </td>\n";
3059 } elsif ($status eq 'D') {
3060 print "<td class=\"link\">" .
3061 $cgi->a({-href
=> href
(action
=>"blob",
3064 file_name
=>$from_path)},
3068 if ($diff->{'to_id'} eq $from_hash) {
3069 print "<td class=\"link nochange\">";
3071 print "<td class=\"link\">";
3073 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3074 hash
=>$diff->{'to_id'},
3075 hash_parent
=>$from_hash,
3077 hash_parent_base
=>$hash_parent,
3078 file_name
=>$diff->{'to_file'},
3079 file_parent
=>$from_path)},
3085 print "<td class=\"link\">";
3087 print $cgi->a({-href
=> href
(action
=>"blob",
3088 hash
=>$diff->{'to_id'},
3089 file_name
=>$diff->{'to_file'},
3092 print " | " if ($has_history);
3095 print $cgi->a({-href
=> href
(action
=>"history",
3096 file_name
=>$diff->{'to_file'},
3103 next; # instead of 'else' clause, to avoid extra indent
3105 # else ordinary diff
3107 my ($to_mode_oct, $to_mode_str, $to_file_type);
3108 my ($from_mode_oct, $from_mode_str, $from_file_type);
3109 if ($diff->{'to_mode'} ne ('0' x
6)) {
3110 $to_mode_oct = oct $diff->{'to_mode'};
3111 if (S_ISREG
($to_mode_oct)) { # only for regular file
3112 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3114 $to_file_type = file_type
($diff->{'to_mode'});
3116 if ($diff->{'from_mode'} ne ('0' x
6)) {
3117 $from_mode_oct = oct $diff->{'from_mode'};
3118 if (S_ISREG
($to_mode_oct)) { # only for regular file
3119 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3121 $from_file_type = file_type
($diff->{'from_mode'});
3124 if ($diff->{'status'} eq "A") { # created
3125 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3126 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3127 $mode_chng .= "]</span>";
3129 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3130 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3131 -class => "list"}, esc_path
($diff->{'file'}));
3133 print "<td>$mode_chng</td>\n";
3134 print "<td class=\"link\">";
3135 if ($action eq 'commitdiff') {
3138 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3141 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3142 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3146 } elsif ($diff->{'status'} eq "D") { # deleted
3147 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3149 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3150 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3151 -class => "list"}, esc_path
($diff->{'file'}));
3153 print "<td>$mode_chng</td>\n";
3154 print "<td class=\"link\">";
3155 if ($action eq 'commitdiff') {
3158 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3161 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3162 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3165 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3166 file_name
=>$diff->{'file'})},
3169 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3170 file_name
=>$diff->{'file'})},
3174 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3175 my $mode_chnge = "";
3176 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3177 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3178 if ($from_file_type ne $to_file_type) {
3179 $mode_chnge .= " from $from_file_type to $to_file_type";
3181 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3182 if ($from_mode_str && $to_mode_str) {
3183 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3184 } elsif ($to_mode_str) {
3185 $mode_chnge .= " mode: $to_mode_str";
3188 $mode_chnge .= "]</span>\n";
3191 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3192 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3193 -class => "list"}, esc_path
($diff->{'file'}));
3195 print "<td>$mode_chnge</td>\n";
3196 print "<td class=\"link\">";
3197 if ($action eq 'commitdiff') {
3200 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3202 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3203 # "commit" view and modified file (not onlu mode changed)
3204 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3205 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3206 hash_base
=>$hash, hash_parent_base
=>$parent,
3207 file_name
=>$diff->{'file'})},
3211 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3212 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3215 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3216 file_name
=>$diff->{'file'})},
3219 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3220 file_name
=>$diff->{'file'})},
3224 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3225 my %status_name = ('R' => 'moved', 'C' => 'copied');
3226 my $nstatus = $status_name{$diff->{'status'}};
3228 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3229 # mode also for directories, so we cannot use $to_mode_str
3230 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3233 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3234 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3235 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3236 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3237 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3238 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3239 -class => "list"}, esc_path
($diff->{'from_file'})) .
3240 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3241 "<td class=\"link\">";
3242 if ($action eq 'commitdiff') {
3245 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3247 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3248 # "commit" view and modified file (not only pure rename or copy)
3249 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3250 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3251 hash_base
=>$hash, hash_parent_base
=>$parent,
3252 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3256 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3257 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3260 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3261 file_name
=>$diff->{'to_file'})},
3264 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3265 file_name
=>$diff->{'to_file'})},
3269 } # we should not encounter Unmerged (U) or Unknown (X) status
3272 print "</tbody>" if $has_header;
3276 sub git_patchset_body
{
3277 my ($fd, $difftree, $hash, @hash_parents) = @_;
3278 my ($hash_parent) = $hash_parents[0];
3280 my $is_combined = (@hash_parents > 1);
3282 my $patch_number = 0;
3288 print "<div class=\"patchset\">\n";
3290 # skip to first patch
3291 while ($patch_line = <$fd>) {
3294 last if ($patch_line =~ m/^diff /);
3298 while ($patch_line) {
3300 # parse "git diff" header line
3301 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3302 # $1 is from_name, which we do not use
3303 $to_name = unquote
($2);
3304 $to_name =~ s!^b/!!;
3305 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3306 # $1 is 'cc' or 'combined', which we do not use
3307 $to_name = unquote
($2);
3312 # check if current patch belong to current raw line
3313 # and parse raw git-diff line if needed
3314 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3315 # this is continuation of a split patch
3316 print "<div class=\"patch cont\">\n";
3318 # advance raw git-diff output if needed
3319 $patch_idx++ if defined $diffinfo;
3321 # read and prepare patch information
3322 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3324 # compact combined diff output can have some patches skipped
3325 # find which patch (using pathname of result) we are at now;
3327 while ($to_name ne $diffinfo->{'to_file'}) {
3328 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3329 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3330 "</div>\n"; # class="patch"
3335 last if $patch_idx > $#$difftree;
3336 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3340 # modifies %from, %to hashes
3341 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3343 # this is first patch for raw difftree line with $patch_idx index
3344 # we index @$difftree array from 0, but number patches from 1
3345 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3349 #assert($patch_line =~ m/^diff /) if DEBUG;
3350 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3352 # print "git diff" header
3353 print format_git_diff_header_line
($patch_line, $diffinfo,
3356 # print extended diff header
3357 print "<div class=\"diff extended_header\">\n";
3359 while ($patch_line = <$fd>) {
3362 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3364 print format_extended_diff_header_line
($patch_line, $diffinfo,
3367 print "</div>\n"; # class="diff extended_header"
3369 # from-file/to-file diff header
3370 if (! $patch_line) {
3371 print "</div>\n"; # class="patch"
3374 next PATCH
if ($patch_line =~ m/^diff /);
3375 #assert($patch_line =~ m/^---/) if DEBUG;
3377 my $last_patch_line = $patch_line;
3378 $patch_line = <$fd>;
3380 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3382 print format_diff_from_to_header
($last_patch_line, $patch_line,
3383 $diffinfo, \
%from, \
%to,
3388 while ($patch_line = <$fd>) {
3391 next PATCH
if ($patch_line =~ m/^diff /);
3393 print format_diff_line
($patch_line, \
%from, \
%to);
3397 print "</div>\n"; # class="patch"
3400 # for compact combined (--cc) format, with chunk and patch simpliciaction
3401 # patchset might be empty, but there might be unprocessed raw lines
3402 for (++$patch_idx if $patch_number > 0;
3403 $patch_idx < @$difftree;
3405 # read and prepare patch information
3406 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3408 # generate anchor for "patch" links in difftree / whatchanged part
3409 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3410 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3411 "</div>\n"; # class="patch"
3416 if ($patch_number == 0) {
3417 if (@hash_parents > 1) {
3418 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3420 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3424 print "</div>\n"; # class="patchset"
3427 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3429 sub git_project_list_body
{
3430 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3432 my ($check_forks) = gitweb_check_feature
('forks');
3435 foreach my $pr (@$projlist) {
3436 my (@aa) = git_get_last_activity
($pr->{'path'});
3440 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3441 if (!defined $pr->{'descr'}) {
3442 my $descr = git_get_project_description
($pr->{'path'}) || "";
3443 $pr->{'descr_long'} = to_utf8
($descr);
3444 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3446 if (!defined $pr->{'owner'}) {
3447 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3450 my $pname = $pr->{'path'};
3451 if (($pname =~ s/\.git$//) &&
3452 ($pname !~ /\/$/) &&
3453 (-d
"$projectroot/$pname")) {
3454 $pr->{'forks'} = "-d $projectroot/$pname";
3460 push @projects, $pr;
3463 $order ||= $default_projects_order;
3464 $from = 0 unless defined $from;
3465 $to = $#projects if (!defined $to || $#projects < $to);
3467 print "<table class=\"project_list\">\n";
3468 unless ($no_header) {
3471 print "<th></th>\n";
3473 if ($order eq "project") {
3474 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3475 print "<th>Project</th>\n";
3478 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3479 -class => "header"}, "Project") .
3482 if ($order eq "descr") {
3483 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3484 print "<th>Description</th>\n";
3487 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3488 -class => "header"}, "Description") .
3491 if ($order eq "owner") {
3492 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3493 print "<th>Owner</th>\n";
3496 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3497 -class => "header"}, "Owner") .
3500 if ($order eq "age") {
3501 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3502 print "<th>Last Change</th>\n";
3505 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3506 -class => "header"}, "Last Change") .
3509 print "<th></th>\n" .
3513 for (my $i = $from; $i <= $to; $i++) {
3514 my $pr = $projects[$i];
3516 print "<tr class=\"dark\">\n";
3518 print "<tr class=\"light\">\n";
3523 if ($pr->{'forks'}) {
3524 print "<!-- $pr->{'forks'} -->\n";
3525 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3529 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3530 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3531 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3532 -class => "list", -title
=> $pr->{'descr_long'}},
3533 esc_html
($pr->{'descr'})) . "</td>\n" .
3534 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3535 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3536 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3537 "<td class=\"link\">" .
3538 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3539 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3540 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3541 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3542 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3546 if (defined $extra) {
3549 print "<td></td>\n";
3551 print "<td colspan=\"5\">$extra</td>\n" .
3557 sub git_shortlog_body
{
3558 # uses global variable $project
3559 my ($commitlist, $from, $to, $refs, $extra) = @_;
3561 $from = 0 unless defined $from;
3562 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3564 print "<table class=\"shortlog\">\n";
3566 for (my $i = $from; $i <= $to; $i++) {
3567 my %co = %{$commitlist->[$i]};
3568 my $commit = $co{'id'};
3569 my $ref = format_ref_marker
($refs, $commit);
3571 print "<tr class=\"dark\">\n";
3573 print "<tr class=\"light\">\n";
3576 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3577 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3578 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3579 "<td><i>" . $author . "</i></td>\n" .
3581 print format_subject_html
($co{'title'}, $co{'title_short'},
3582 href
(action
=>"commit", hash
=>$commit), $ref);
3584 "<td class=\"link\">" .
3585 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3586 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3587 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3588 my $snapshot_links = format_snapshot_links
($commit);
3589 if (defined $snapshot_links) {
3590 print " | " . $snapshot_links;
3595 if (defined $extra) {
3597 "<td colspan=\"4\">$extra</td>\n" .
3603 sub git_history_body
{
3604 # Warning: assumes constant type (blob or tree) during history
3605 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3607 $from = 0 unless defined $from;
3608 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3610 print "<table class=\"history\">\n";
3612 for (my $i = $from; $i <= $to; $i++) {
3613 my %co = %{$commitlist->[$i]};
3617 my $commit = $co{'id'};
3619 my $ref = format_ref_marker
($refs, $commit);
3622 print "<tr class=\"dark\">\n";
3624 print "<tr class=\"light\">\n";
3627 # shortlog uses chop_str($co{'author_name'}, 10)
3628 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3629 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3630 "<td><i>" . $author . "</i></td>\n" .
3632 # originally git_history used chop_str($co{'title'}, 50)
3633 print format_subject_html
($co{'title'}, $co{'title_short'},
3634 href
(action
=>"commit", hash
=>$commit), $ref);
3636 "<td class=\"link\">" .
3637 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3638 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3640 if ($ftype eq 'blob') {
3641 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3642 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3643 if (defined $blob_current && defined $blob_parent &&
3644 $blob_current ne $blob_parent) {
3646 $cgi->a({-href
=> href
(action
=>"blobdiff",
3647 hash
=>$blob_current, hash_parent
=>$blob_parent,
3648 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3649 file_name
=>$file_name)},
3656 if (defined $extra) {
3658 "<td colspan=\"4\">$extra</td>\n" .
3665 # uses global variable $project
3666 my ($taglist, $from, $to, $extra) = @_;
3667 $from = 0 unless defined $from;
3668 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3670 print "<table class=\"tags\">\n";
3672 for (my $i = $from; $i <= $to; $i++) {
3673 my $entry = $taglist->[$i];
3675 my $comment = $tag{'subject'};
3677 if (defined $comment) {
3678 $comment_short = chop_str
($comment, 30, 5);
3681 print "<tr class=\"dark\">\n";
3683 print "<tr class=\"light\">\n";
3686 if (defined $tag{'age'}) {
3687 print "<td><i>$tag{'age'}</i></td>\n";
3689 print "<td></td>\n";
3692 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3693 -class => "list name"}, esc_html
($tag{'name'})) .
3696 if (defined $comment) {
3697 print format_subject_html
($comment, $comment_short,
3698 href
(action
=>"tag", hash
=>$tag{'id'}));
3701 "<td class=\"selflink\">";
3702 if ($tag{'type'} eq "tag") {
3703 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3708 "<td class=\"link\">" . " | " .
3709 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3710 if ($tag{'reftype'} eq "commit") {
3711 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3712 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3713 } elsif ($tag{'reftype'} eq "blob") {
3714 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3719 if (defined $extra) {
3721 "<td colspan=\"5\">$extra</td>\n" .
3727 sub git_heads_body
{
3728 # uses global variable $project
3729 my ($headlist, $head, $from, $to, $extra) = @_;
3730 $from = 0 unless defined $from;
3731 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3733 print "<table class=\"heads\">\n";
3735 for (my $i = $from; $i <= $to; $i++) {
3736 my $entry = $headlist->[$i];
3738 my $curr = $ref{'id'} eq $head;
3740 print "<tr class=\"dark\">\n";
3742 print "<tr class=\"light\">\n";
3745 print "<td><i>$ref{'age'}</i></td>\n" .
3746 ($curr ? "<td class=\"current_head\">" : "<td>") .
3747 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3748 -class => "list name"},esc_html
($ref{'name'})) .
3750 "<td class=\"link\">" .
3751 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3752 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3753 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3757 if (defined $extra) {
3759 "<td colspan=\"3\">$extra</td>\n" .
3765 sub git_search_grep_body
{
3766 my ($commitlist, $from, $to, $extra) = @_;
3767 $from = 0 unless defined $from;
3768 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3770 print "<table class=\"commit_search\">\n";
3772 for (my $i = $from; $i <= $to; $i++) {
3773 my %co = %{$commitlist->[$i]};
3777 my $commit = $co{'id'};
3779 print "<tr class=\"dark\">\n";
3781 print "<tr class=\"light\">\n";
3784 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3785 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3786 "<td><i>" . $author . "</i></td>\n" .
3788 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3789 -class => "list subject"},
3790 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3791 my $comment = $co{'comment'};
3792 foreach my $line (@$comment) {
3793 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3794 my ($lead, $match, $trail) = ($1, $2, $3);
3795 $match = chop_str
($match, 70, 5); # in case match is very long
3796 my $contextlen = (80 - len
($match))/2; # is left for the remainder
3797 $contextlen = 30 if ($contextlen > 30); # but not too much
3798 $lead = chop_str
($lead, $contextlen, 10);
3799 $trail = chop_str
($trail, $contextlen, 10);
3801 $lead = esc_html
($lead);
3802 $match = esc_html
($match);
3803 $trail = esc_html
($trail);
3805 print "$lead<span class=\"match\">$match</span>$trail<br />";
3809 "<td class=\"link\">" .
3810 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3812 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3814 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3818 if (defined $extra) {
3820 "<td colspan=\"3\">$extra</td>\n" .
3826 ## ======================================================================
3827 ## ======================================================================
3830 sub git_project_list
{
3831 my $order = $cgi->param('o');
3832 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3833 die_error
(undef, "Unknown order parameter");
3836 my @list = git_get_projects_list
();
3838 die_error
(undef, "No projects found");
3842 if (-f
$home_text) {
3843 print "<div class=\"index_include\">\n";
3844 open (my $fd, $home_text);
3849 git_project_list_body
(\
@list, $order);
3854 my $order = $cgi->param('o');
3855 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3856 die_error
(undef, "Unknown order parameter");
3859 my @list = git_get_projects_list
($project);
3861 die_error
(undef, "No forks found");
3865 git_print_page_nav
('','');
3866 git_print_header_div
('summary', "$project forks");
3867 git_project_list_body
(\
@list, $order);
3871 sub git_project_index
{
3872 my @projects = git_get_projects_list
($project);
3875 -type
=> 'text/plain',
3876 -charset
=> 'utf-8',
3877 -content_disposition
=> 'inline; filename="index.aux"');
3879 foreach my $pr (@projects) {
3880 if (!exists $pr->{'owner'}) {
3881 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3884 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3885 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3886 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3887 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3891 print "$path $owner\n";
3896 my $descr = git_get_project_description
($project) || "none";
3897 my %co = parse_commit
("HEAD");
3898 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3899 my $head = $co{'id'};
3901 my $owner = git_get_project_owner
($project);
3903 my $refs = git_get_references
();
3904 # These get_*_list functions return one more to allow us to see if
3905 # there are more ...
3906 my @taglist = git_get_tags_list
(16);
3907 my @headlist = git_get_heads_list
(16);
3909 my ($check_forks) = gitweb_check_feature
('forks');
3912 @forklist = git_get_projects_list
($project);
3916 git_print_page_nav
('summary','', $head);
3918 print "<div class=\"title\"> </div>\n";
3919 print "<table class=\"projects_list\">\n" .
3920 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3921 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3922 if (defined $cd{'rfc2822'}) {
3923 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3926 # use per project git URL list in $projectroot/$project/cloneurl
3927 # or make project git URL from git base URL and project name
3928 my $url_tag = "URL";
3929 my @url_list = git_get_project_url_list
($project);
3930 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3931 foreach my $git_url (@url_list) {
3932 next unless $git_url;
3933 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3938 if (-s
"$projectroot/$project/README.html") {
3939 if (open my $fd, "$projectroot/$project/README.html") {
3940 print "<div class=\"title\">readme</div>\n" .
3941 "<div class=\"readme\">\n";
3942 print $_ while (<$fd>);
3943 print "\n</div>\n"; # class="readme"
3948 # we need to request one more than 16 (0..15) to check if
3950 my @commitlist = $head ? parse_commits
($head, 17) : ();
3952 git_print_header_div
('shortlog');
3953 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3954 $#commitlist <= 15 ? undef :
3955 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3959 git_print_header_div
('tags');
3960 git_tags_body
(\
@taglist, 0, 15,
3961 $#taglist <= 15 ? undef :
3962 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3966 git_print_header_div
('heads');
3967 git_heads_body
(\
@headlist, $head, 0, 15,
3968 $#headlist <= 15 ? undef :
3969 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3973 git_print_header_div
('forks');
3974 git_project_list_body
(\
@forklist, undef, 0, 15,
3975 $#forklist <= 15 ? undef :
3976 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3984 my $head = git_get_head_hash
($project);
3986 git_print_page_nav
('','', $head,undef,$head);
3987 my %tag = parse_tag
($hash);
3990 die_error
(undef, "Unknown tag object");
3993 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3994 print "<div class=\"title_text\">\n" .
3995 "<table class=\"object_header\">\n" .
3997 "<td>object</td>\n" .
3998 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3999 $tag{'object'}) . "</td>\n" .
4000 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4001 $tag{'type'}) . "</td>\n" .
4003 if (defined($tag{'author'})) {
4004 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4005 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4006 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4007 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4010 print "</table>\n\n" .
4012 print "<div class=\"page_body\">";
4013 my $comment = $tag{'comment'};
4014 foreach my $line (@$comment) {
4016 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4026 my ($have_blame) = gitweb_check_feature
('blame');
4028 die_error
('403 Permission denied', "Permission denied");
4030 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4031 $hash_base ||= git_get_head_hash
($project);
4032 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4033 my %co = parse_commit
($hash_base)
4034 or die_error
(undef, "Reading commit failed");
4035 if (!defined $hash) {
4036 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4037 or die_error
(undef, "Error looking up file");
4039 $ftype = git_get_type
($hash);
4040 if ($ftype !~ "blob") {
4041 die_error
('400 Bad Request', "Object is not a blob");
4043 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4044 $file_name, $hash_base)
4045 or die_error
(undef, "Open git-blame failed");
4048 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4051 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4054 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4056 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4057 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4058 git_print_page_path
($file_name, $ftype, $hash_base);
4059 my @rev_color = (qw(light2 dark2));
4060 my $num_colors = scalar(@rev_color);
4061 my $current_color = 0;
4064 <div class="page_body">
4065 <table class="blame">
4066 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4071 last unless defined $_;
4072 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4073 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4074 if (!exists $metainfo{$full_rev}) {
4075 $metainfo{$full_rev} = {};
4077 my $meta = $metainfo{$full_rev};
4080 if (/^(\S+) (.*)$/) {
4086 my $rev = substr($full_rev, 0, 8);
4087 my $author = $meta->{'author'};
4088 my %date = parse_date
($meta->{'author-time'},
4089 $meta->{'author-tz'});
4090 my $date = $date{'iso-tz'};
4092 $current_color = ++$current_color % $num_colors;
4094 print "<tr class=\"$rev_color[$current_color]\">\n";
4096 print "<td class=\"sha1\"";
4097 print " title=\"". esc_html
($author) . ", $date\"";
4098 print " rowspan=\"$group_size\"" if ($group_size > 1);
4100 print $cgi->a({-href
=> href
(action
=>"commit",
4102 file_name
=>$file_name)},
4106 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4107 or die_error
(undef, "Open git-rev-parse failed");
4108 my $parent_commit = <$dd>;
4110 chomp($parent_commit);
4111 my $blamed = href
(action
=> 'blame',
4112 file_name
=> $meta->{'filename'},
4113 hash_base
=> $parent_commit);
4114 print "<td class=\"linenr\">";
4115 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4117 -class => "linenr" },
4120 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4126 or print "Reading blob failed\n";
4133 my ($have_blame) = gitweb_check_feature
('blame');
4135 die_error
('403 Permission denied', "Permission denied");
4137 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4138 $hash_base ||= git_get_head_hash
($project);
4139 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4140 my %co = parse_commit
($hash_base)
4141 or die_error
(undef, "Reading commit failed");
4142 if (!defined $hash) {
4143 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4144 or die_error
(undef, "Error lookup file");
4146 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4147 or die_error
(undef, "Open git-annotate failed");
4150 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4153 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4156 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4158 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4159 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4160 git_print_page_path
($file_name, 'blob', $hash_base);
4161 print "<div class=\"page_body\">\n";
4163 <table class="blame">
4172 my @line_class = (qw(light dark));
4173 my $line_class_len = scalar (@line_class);
4174 my $line_class_num = $#line_class;
4175 while (my $line = <$fd>) {
4187 $line_class_num = ($line_class_num + 1) % $line_class_len;
4189 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4196 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4199 $short_rev = substr ($long_rev, 0, 8);
4200 $age = time () - $time;
4201 $age_str = age_string
($age);
4202 $age_str =~ s/ / /g;
4203 $age_class = age_class
($age);
4204 $author = esc_html
($author);
4205 $author =~ s/ / /g;
4207 $data = untabify
($data);
4208 $data = esc_html
($data);
4211 <tr class="$line_class[$line_class_num]">
4212 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4213 <td class="$age_class">$age_str</td>
4215 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4216 <td class="pre">$data</td>
4219 } # while (my $line = <$fd>)
4220 print "</table>\n\n";
4222 or print "Reading blob failed.\n";
4228 my $head = git_get_head_hash
($project);
4230 git_print_page_nav
('','', $head,undef,$head);
4231 git_print_header_div
('summary', $project);
4233 my @tagslist = git_get_tags_list
();
4235 git_tags_body
(\
@tagslist);
4241 my $head = git_get_head_hash
($project);
4243 git_print_page_nav
('','', $head,undef,$head);
4244 git_print_header_div
('summary', $project);
4246 my @headslist = git_get_heads_list
();
4248 git_heads_body
(\
@headslist, $head);
4253 sub git_blob_plain
{
4256 if (!defined $hash) {
4257 if (defined $file_name) {
4258 my $base = $hash_base || git_get_head_hash
($project);
4259 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4260 or die_error
(undef, "Error lookup file");
4262 die_error
(undef, "No file name defined");
4264 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4265 # blobs defined by non-textual hash id's can be cached
4270 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4271 or die_error
(undef, "Couldn't cat $file_name, $hash");
4273 $type ||= blob_mimetype
($fd, $file_name);
4275 # save as filename, even when no $file_name is given
4276 my $save_as = "$hash";
4277 if (defined $file_name) {
4278 $save_as = $file_name;
4279 } elsif ($type =~ m/^text\//) {
4286 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4288 binmode STDOUT
, ':raw';
4290 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4298 if (!defined $hash) {
4299 if (defined $file_name) {
4300 my $base = $hash_base || git_get_head_hash
($project);
4301 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4302 or die_error
(undef, "Error lookup file");
4304 die_error
(undef, "No file name defined");
4306 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4307 # blobs defined by non-textual hash id's can be cached
4311 my ($have_blame) = gitweb_check_feature
('blame');
4312 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4313 or die_error
(undef, "Couldn't cat $file_name, $hash");
4314 my $mimetype = blob_mimetype
($fd, $file_name);
4315 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4317 return git_blob_plain
($mimetype);
4319 # we can have blame only for text/* mimetype
4320 $have_blame &&= ($mimetype =~ m!^text/!);
4322 git_header_html
(undef, $expires);
4323 my $formats_nav = '';
4324 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4325 if (defined $file_name) {
4328 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4333 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4336 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4339 $cgi->a({-href
=> href
(action
=>"blob",
4340 hash_base
=>"HEAD", file_name
=>$file_name)},
4344 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4347 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4348 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4350 print "<div class=\"page_nav\">\n" .
4351 "<br/><br/></div>\n" .
4352 "<div class=\"title\">$hash</div>\n";
4354 git_print_page_path
($file_name, "blob", $hash_base);
4355 print "<div class=\"page_body\">\n";
4356 if ($mimetype =~ m!^image/!) {
4357 print qq
!<img type
="$mimetype"!;
4359 print qq
! alt
="$file_name" title
="$file_name"!;
4362 href(action=>"blob_plain
", hash=>$hash,
4363 hash_base=>$hash_base, file_name=>$file_name) .
4367 while (my $line = <$fd>) {
4370 $line = untabify
($line);
4371 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4372 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4376 or print "Reading blob failed.\n";
4382 if (!defined $hash_base) {
4383 $hash_base = "HEAD";
4385 if (!defined $hash) {
4386 if (defined $file_name) {
4387 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4393 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4394 or die_error
(undef, "Open git-ls-tree failed");
4395 my @entries = map { chomp; $_ } <$fd>;
4396 close $fd or die_error
(undef, "Reading tree failed");
4399 my $refs = git_get_references
();
4400 my $ref = format_ref_marker
($refs, $hash_base);
4403 my ($have_blame) = gitweb_check_feature
('blame');
4404 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4406 if (defined $file_name) {
4408 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4410 $cgi->a({-href
=> href
(action
=>"tree",
4411 hash_base
=>"HEAD", file_name
=>$file_name)},
4414 my $snapshot_links = format_snapshot_links
($hash);
4415 if (defined $snapshot_links) {
4416 # FIXME: Should be available when we have no hash base as well.
4417 push @views_nav, $snapshot_links;
4419 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4420 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4423 print "<div class=\"page_nav\">\n";
4424 print "<br/><br/></div>\n";
4425 print "<div class=\"title\">$hash</div>\n";
4427 if (defined $file_name) {
4428 $basedir = $file_name;
4429 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4433 git_print_page_path
($file_name, 'tree', $hash_base);
4434 print "<div class=\"page_body\">\n";
4435 print "<table class=\"tree\">\n";
4437 # '..' (top directory) link if possible
4438 if (defined $hash_base &&
4439 defined $file_name && $file_name =~ m![^/]+$!) {
4441 print "<tr class=\"dark\">\n";
4443 print "<tr class=\"light\">\n";
4447 my $up = $file_name;
4448 $up =~ s!/?[^/]+$!!;
4449 undef $up unless $up;
4450 # based on git_print_tree_entry
4451 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4452 print '<td class="list">';
4453 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4457 print "<td class=\"link\"></td>\n";
4461 foreach my $line (@entries) {
4462 my %t = parse_ls_tree_line
($line, -z
=> 1);
4465 print "<tr class=\"dark\">\n";
4467 print "<tr class=\"light\">\n";
4471 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4475 print "</table>\n" .
4481 my @supported_fmts = gitweb_check_feature
('snapshot');
4482 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4484 my $format = $cgi->param('sf');
4485 if (!@supported_fmts) {
4486 die_error
('403 Permission denied', "Permission denied");
4488 # default to first supported snapshot format
4489 $format ||= $supported_fmts[0];
4490 if ($format !~ m/^[a-z0-9]+$/) {
4491 die_error
(undef, "Invalid snapshot format parameter");
4492 } elsif (!exists($known_snapshot_formats{$format})) {
4493 die_error
(undef, "Unknown snapshot format");
4494 } elsif (!grep($_ eq $format, @supported_fmts)) {
4495 die_error
(undef, "Unsupported snapshot format");
4498 if (!defined $hash) {
4499 $hash = git_get_head_hash
($project);
4502 my $git_command = git_cmd_str
();
4503 my $name = $project;
4504 $name =~ s
,([^/])/*\
.git
$,$1,;
4505 $name = basename
($name);
4506 my $filename = to_utf8
($name);
4507 $name =~ s/\047/\047\\\047\047/g;
4509 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4510 $cmd = "$git_command archive " .
4511 "--format=$known_snapshot_formats{$format}{'format'} " .
4512 "--prefix=\'$name\'/ $hash";
4513 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4514 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4518 -type
=> $known_snapshot_formats{$format}{'type'},
4519 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4520 -status
=> '200 OK');
4522 open my $fd, "-|", $cmd
4523 or die_error
(undef, "Execute git-archive failed");
4524 binmode STDOUT
, ':raw';
4526 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4531 my $head = git_get_head_hash
($project);
4532 if (!defined $hash) {
4535 if (!defined $page) {
4538 my $refs = git_get_references
();
4540 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4542 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4545 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4548 my %co = parse_commit
($hash);
4550 git_print_header_div
('summary', $project);
4551 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4553 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4554 for (my $i = 0; $i <= $to; $i++) {
4555 my %co = %{$commitlist[$i]};
4557 my $commit = $co{'id'};
4558 my $ref = format_ref_marker
($refs, $commit);
4559 my %ad = parse_date
($co{'author_epoch'});
4560 git_print_header_div
('commit',
4561 "<span class=\"age\">$co{'age_string'}</span>" .
4562 esc_html
($co{'title'}) . $ref,
4564 print "<div class=\"title_text\">\n" .
4565 "<div class=\"log_link\">\n" .
4566 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4568 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4570 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4573 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4576 print "<div class=\"log_body\">\n";
4577 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4580 if ($#commitlist >= 100) {
4581 print "<div class=\"page_nav\">\n";
4582 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4583 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4590 $hash ||= $hash_base || "HEAD";
4591 my %co = parse_commit
($hash);
4593 die_error
(undef, "Unknown commit object");
4595 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4596 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4598 my $parent = $co{'parent'};
4599 my $parents = $co{'parents'}; # listref
4601 # we need to prepare $formats_nav before any parameter munging
4603 if (!defined $parent) {
4605 $formats_nav .= '(initial)';
4606 } elsif (@$parents == 1) {
4607 # single parent commit
4610 $cgi->a({-href
=> href
(action
=>"commit",
4612 esc_html
(substr($parent, 0, 7))) .
4619 $cgi->a({-href
=> href
(action
=>"commit",
4621 esc_html
(substr($_, 0, 7)));
4626 if (!defined $parent) {
4630 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4632 (@$parents <= 1 ? $parent : '-c'),
4634 or die_error
(undef, "Open git-diff-tree failed");
4635 @difftree = map { chomp; $_ } <$fd>;
4636 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4638 # non-textual hash id's can be cached
4640 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4643 my $refs = git_get_references
();
4644 my $ref = format_ref_marker
($refs, $co{'id'});
4646 git_header_html
(undef, $expires);
4647 git_print_page_nav
('commit', '',
4648 $hash, $co{'tree'}, $hash,
4651 if (defined $co{'parent'}) {
4652 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4654 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4656 print "<div class=\"title_text\">\n" .
4657 "<table class=\"object_header\">\n";
4658 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4660 "<td></td><td> $ad{'rfc2822'}";
4661 if ($ad{'hour_local'} < 6) {
4662 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4663 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4665 printf(" (%02d:%02d %s)",
4666 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4670 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4671 print "<tr><td></td><td> $cd{'rfc2822'}" .
4672 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4674 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4677 "<td class=\"sha1\">" .
4678 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4679 class => "list"}, $co{'tree'}) .
4681 "<td class=\"link\">" .
4682 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4684 my $snapshot_links = format_snapshot_links
($hash);
4685 if (defined $snapshot_links) {
4686 print " | " . $snapshot_links;
4691 foreach my $par (@$parents) {
4694 "<td class=\"sha1\">" .
4695 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4696 class => "list"}, $par) .
4698 "<td class=\"link\">" .
4699 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4701 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4708 print "<div class=\"page_body\">\n";
4709 git_print_log
($co{'comment'});
4712 git_difftree_body
(\
@difftree, $hash, @$parents);
4718 # object is defined by:
4719 # - hash or hash_base alone
4720 # - hash_base and file_name
4723 # - hash or hash_base alone
4724 if ($hash || ($hash_base && !defined $file_name)) {
4725 my $object_id = $hash || $hash_base;
4727 my $git_command = git_cmd_str
();
4728 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4729 or die_error
('404 Not Found', "Object does not exist");
4733 or die_error
('404 Not Found', "Object does not exist");
4735 # - hash_base and file_name
4736 } elsif ($hash_base && defined $file_name) {
4737 $file_name =~ s
,/+$,,;
4739 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4740 or die_error
('404 Not Found', "Base object does not exist");
4742 # here errors should not hapen
4743 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4744 or die_error
(undef, "Open git-ls-tree failed");
4748 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4749 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4750 die_error
('404 Not Found', "File or directory for given base does not exist");
4755 die_error
('404 Not Found', "Not enough information to find object");
4758 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4759 hash
=>$hash, hash_base
=>$hash_base,
4760 file_name
=>$file_name),
4761 -status
=> '302 Found');
4765 my $format = shift || 'html';
4772 # preparing $fd and %diffinfo for git_patchset_body
4774 if (defined $hash_base && defined $hash_parent_base) {
4775 if (defined $file_name) {
4777 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4778 $hash_parent_base, $hash_base,
4779 "--", (defined $file_parent ? $file_parent : ()), $file_name
4780 or die_error
(undef, "Open git-diff-tree failed");
4781 @difftree = map { chomp; $_ } <$fd>;
4783 or die_error
(undef, "Reading git-diff-tree failed");
4785 or die_error
('404 Not Found', "Blob diff not found");
4787 } elsif (defined $hash &&
4788 $hash =~ /[0-9a-fA-F]{40}/) {
4789 # try to find filename from $hash
4791 # read filtered raw output
4792 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4793 $hash_parent_base, $hash_base, "--"
4794 or die_error
(undef, "Open git-diff-tree failed");
4796 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4798 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4799 map { chomp; $_ } <$fd>;
4801 or die_error
(undef, "Reading git-diff-tree failed");
4803 or die_error
('404 Not Found', "Blob diff not found");
4806 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4809 if (@difftree > 1) {
4810 die_error
('404 Not Found', "Ambiguous blob diff specification");
4813 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4814 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4815 $file_name ||= $diffinfo{'to_file'};
4817 $hash_parent ||= $diffinfo{'from_id'};
4818 $hash ||= $diffinfo{'to_id'};
4820 # non-textual hash id's can be cached
4821 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4822 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4827 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4828 '-p', ($format eq 'html' ? "--full-index" : ()),
4829 $hash_parent_base, $hash_base,
4830 "--", (defined $file_parent ? $file_parent : ()), $file_name
4831 or die_error
(undef, "Open git-diff-tree failed");
4834 # old/legacy style URI
4835 if (!%diffinfo && # if new style URI failed
4836 defined $hash && defined $hash_parent) {
4837 # fake git-diff-tree raw output
4838 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4839 $diffinfo{'from_id'} = $hash_parent;
4840 $diffinfo{'to_id'} = $hash;
4841 if (defined $file_name) {
4842 if (defined $file_parent) {
4843 $diffinfo{'status'} = '2';
4844 $diffinfo{'from_file'} = $file_parent;
4845 $diffinfo{'to_file'} = $file_name;
4846 } else { # assume not renamed
4847 $diffinfo{'status'} = '1';
4848 $diffinfo{'from_file'} = $file_name;
4849 $diffinfo{'to_file'} = $file_name;
4851 } else { # no filename given
4852 $diffinfo{'status'} = '2';
4853 $diffinfo{'from_file'} = $hash_parent;
4854 $diffinfo{'to_file'} = $hash;
4857 # non-textual hash id's can be cached
4858 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4859 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4864 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4865 '-p', ($format eq 'html' ? "--full-index" : ()),
4866 $hash_parent, $hash, "--"
4867 or die_error
(undef, "Open git-diff failed");
4869 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4874 if ($format eq 'html') {
4876 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4878 git_header_html
(undef, $expires);
4879 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4880 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4881 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4883 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4884 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4886 if (defined $file_name) {
4887 git_print_page_path
($file_name, "blob", $hash_base);
4889 print "<div class=\"page_path\"></div>\n";
4892 } elsif ($format eq 'plain') {
4894 -type
=> 'text/plain',
4895 -charset
=> 'utf-8',
4896 -expires
=> $expires,
4897 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4899 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4902 die_error
(undef, "Unknown blobdiff format");
4906 if ($format eq 'html') {
4907 print "<div class=\"page_body\">\n";
4909 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4912 print "</div>\n"; # class="page_body"
4916 while (my $line = <$fd>) {
4917 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4918 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4922 last if $line =~ m!^\+\+\+!;
4930 sub git_blobdiff_plain
{
4931 git_blobdiff
('plain');
4934 sub git_commitdiff
{
4935 my $format = shift || 'html';
4936 $hash ||= $hash_base || "HEAD";
4937 my %co = parse_commit
($hash);
4939 die_error
(undef, "Unknown commit object");
4942 # choose format for commitdiff for merge
4943 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4944 $hash_parent = '--cc';
4946 # we need to prepare $formats_nav before almost any parameter munging
4948 if ($format eq 'html') {
4950 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4953 if (defined $hash_parent &&
4954 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4955 # commitdiff with two commits given
4956 my $hash_parent_short = $hash_parent;
4957 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4958 $hash_parent_short = substr($hash_parent, 0, 7);
4962 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4963 if ($co{'parents'}[$i] eq $hash_parent) {
4964 $formats_nav .= ' parent ' . ($i+1);
4968 $formats_nav .= ': ' .
4969 $cgi->a({-href
=> href
(action
=>"commitdiff",
4970 hash
=>$hash_parent)},
4971 esc_html
($hash_parent_short)) .
4973 } elsif (!$co{'parent'}) {
4975 $formats_nav .= ' (initial)';
4976 } elsif (scalar @{$co{'parents'}} == 1) {
4977 # single parent commit
4980 $cgi->a({-href
=> href
(action
=>"commitdiff",
4981 hash
=>$co{'parent'})},
4982 esc_html
(substr($co{'parent'}, 0, 7))) .
4986 if ($hash_parent eq '--cc') {
4987 $formats_nav .= ' | ' .
4988 $cgi->a({-href
=> href
(action
=>"commitdiff",
4989 hash
=>$hash, hash_parent
=>'-c')},
4991 } else { # $hash_parent eq '-c'
4992 $formats_nav .= ' | ' .
4993 $cgi->a({-href
=> href
(action
=>"commitdiff",
4994 hash
=>$hash, hash_parent
=>'--cc')},
5000 $cgi->a({-href
=> href
(action
=>"commitdiff",
5002 esc_html
(substr($_, 0, 7)));
5003 } @{$co{'parents'}} ) .
5008 my $hash_parent_param = $hash_parent;
5009 if (!defined $hash_parent_param) {
5010 # --cc for multiple parents, --root for parentless
5011 $hash_parent_param =
5012 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5018 if ($format eq 'html') {
5019 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5020 "--no-commit-id", "--patch-with-raw", "--full-index",
5021 $hash_parent_param, $hash, "--"
5022 or die_error
(undef, "Open git-diff-tree failed");
5024 while (my $line = <$fd>) {
5026 # empty line ends raw part of diff-tree output
5028 push @difftree, scalar parse_difftree_raw_line
($line);
5031 } elsif ($format eq 'plain') {
5032 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5033 '-p', $hash_parent_param, $hash, "--"
5034 or die_error
(undef, "Open git-diff-tree failed");
5037 die_error
(undef, "Unknown commitdiff format");
5040 # non-textual hash id's can be cached
5042 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5046 # write commit message
5047 if ($format eq 'html') {
5048 my $refs = git_get_references
();
5049 my $ref = format_ref_marker
($refs, $co{'id'});
5051 git_header_html
(undef, $expires);
5052 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5053 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5054 git_print_authorship
(\
%co);
5055 print "<div class=\"page_body\">\n";
5056 if (@{$co{'comment'}} > 1) {
5057 print "<div class=\"log\">\n";
5058 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5059 print "</div>\n"; # class="log"
5062 } elsif ($format eq 'plain') {
5063 my $refs = git_get_references
("tags");
5064 my $tagname = git_get_rev_name_tags
($hash);
5065 my $filename = basename
($project) . "-$hash.patch";
5068 -type
=> 'text/plain',
5069 -charset
=> 'utf-8',
5070 -expires
=> $expires,
5071 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5072 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5073 print "From: " . to_utf8
($co{'author'}) . "\n";
5074 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5075 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5077 print "X-Git-Tag: $tagname\n" if $tagname;
5078 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5080 foreach my $line (@{$co{'comment'}}) {
5081 print to_utf8
($line) . "\n";
5087 if ($format eq 'html') {
5088 my $use_parents = !defined $hash_parent ||
5089 $hash_parent eq '-c' || $hash_parent eq '--cc';
5090 git_difftree_body
(\
@difftree, $hash,
5091 $use_parents ? @{$co{'parents'}} : $hash_parent);
5094 git_patchset_body
($fd, \
@difftree, $hash,
5095 $use_parents ? @{$co{'parents'}} : $hash_parent);
5097 print "</div>\n"; # class="page_body"
5100 } elsif ($format eq 'plain') {
5104 or print "Reading git-diff-tree failed\n";
5108 sub git_commitdiff_plain
{
5109 git_commitdiff
('plain');
5113 if (!defined $hash_base) {
5114 $hash_base = git_get_head_hash
($project);
5116 if (!defined $page) {
5120 my %co = parse_commit
($hash_base);
5122 die_error
(undef, "Unknown commit object");
5125 my $refs = git_get_references
();
5126 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5128 if (!defined $hash && defined $file_name) {
5129 $hash = git_get_hash_by_path
($hash_base, $file_name);
5131 if (defined $hash) {
5132 $ftype = git_get_type
($hash);
5135 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5137 my $paging_nav = '';
5140 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5141 file_name
=>$file_name)},
5143 $paging_nav .= " ⋅ " .
5144 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5145 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5147 $paging_nav .= "first";
5148 $paging_nav .= " ⋅ prev";
5151 if ($#commitlist >= 100) {
5153 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5154 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5155 $paging_nav .= " ⋅ $next_link";
5157 $paging_nav .= " ⋅ next";
5161 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5162 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5163 git_print_page_path
($file_name, $ftype, $hash_base);
5165 git_history_body
(\
@commitlist, 0, 99,
5166 $refs, $hash_base, $ftype, $next_link);
5172 my ($have_search) = gitweb_check_feature
('search');
5173 if (!$have_search) {
5174 die_error
('403 Permission denied', "Permission denied");
5176 if (!defined $searchtext) {
5177 die_error
(undef, "Text field empty");
5179 if (!defined $hash) {
5180 $hash = git_get_head_hash
($project);
5182 my %co = parse_commit
($hash);
5184 die_error
(undef, "Unknown commit object");
5186 if (!defined $page) {
5190 $searchtype ||= 'commit';
5191 if ($searchtype eq 'pickaxe') {
5192 # pickaxe may take all resources of your box and run for several minutes
5193 # with every query - so decide by yourself how public you make this feature
5194 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5195 if (!$have_pickaxe) {
5196 die_error
('403 Permission denied', "Permission denied");
5199 if ($searchtype eq 'grep') {
5200 my ($have_grep) = gitweb_check_feature
('grep');
5202 die_error
('403 Permission denied', "Permission denied");
5208 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5210 if ($searchtype eq 'commit') {
5211 $greptype = "--grep=";
5212 } elsif ($searchtype eq 'author') {
5213 $greptype = "--author=";
5214 } elsif ($searchtype eq 'committer') {
5215 $greptype = "--committer=";
5217 $greptype .= $search_regexp;
5218 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5220 my $paging_nav = '';
5223 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5224 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5226 $paging_nav .= " ⋅ " .
5227 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5228 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5230 $paging_nav .= "first";
5231 $paging_nav .= " ⋅ prev";
5234 if ($#commitlist >= 100) {
5236 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5237 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5238 $paging_nav .= " ⋅ $next_link";
5240 $paging_nav .= " ⋅ next";
5243 if ($#commitlist >= 100) {
5246 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5247 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5248 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5251 if ($searchtype eq 'pickaxe') {
5252 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5253 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5255 print "<table class=\"pickaxe search\">\n";
5258 my $git_command = git_cmd_str
();
5259 my $searchqtext = $searchtext;
5260 $searchqtext =~ s/'/'\\''/;
5261 open my $fd, "-|", "$git_command rev-list $hash | " .
5262 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5265 while (my $line = <$fd>) {
5266 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5269 $set{'from_id'} = $3;
5271 $set{'id'} = $set{'to_id'};
5272 if ($set{'id'} =~ m/0{40}/) {
5273 $set{'id'} = $set{'from_id'};
5275 if ($set{'id'} =~ m/0{40}/) {
5279 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5282 print "<tr class=\"dark\">\n";
5284 print "<tr class=\"light\">\n";
5287 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5288 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5289 "<td><i>" . $author . "</i></td>\n" .
5291 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5292 -class => "list subject"},
5293 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5294 while (my $setref = shift @files) {
5296 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5297 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5299 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5303 "<td class=\"link\">" .
5304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5306 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5310 %co = parse_commit
($1);
5318 if ($searchtype eq 'grep') {
5319 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5320 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5322 print "<table class=\"grep_search\">\n";
5326 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5328 while (my $line = <$fd>) {
5330 my ($file, $lno, $ltext, $binary);
5331 last if ($matches++ > 1000);
5332 if ($line =~ /^Binary file (.+) matches$/) {
5336 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5338 if ($file ne $lastfile) {
5339 $lastfile and print "</td></tr>\n";
5341 print "<tr class=\"dark\">\n";
5343 print "<tr class=\"light\">\n";
5345 print "<td class=\"list\">".
5346 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5347 file_name
=>"$file"),
5348 -class => "list"}, esc_path
($file));
5349 print "</td><td>\n";
5353 print "<div class=\"binary\">Binary file</div>\n";
5355 $ltext = untabify
($ltext);
5356 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5357 $ltext = esc_html
($1, -nbsp
=>1);
5358 $ltext .= '<span class="match">';
5359 $ltext .= esc_html
($2, -nbsp
=>1);
5360 $ltext .= '</span>';
5361 $ltext .= esc_html
($3, -nbsp
=>1);
5363 $ltext = esc_html
($ltext, -nbsp
=>1);
5365 print "<div class=\"pre\">" .
5366 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5367 file_name
=>"$file").'#l'.$lno,
5368 -class => "linenr"}, sprintf('%4i', $lno))
5369 . ' ' . $ltext . "</div>\n";
5373 print "</td></tr>\n";
5374 if ($matches > 1000) {
5375 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5378 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5387 sub git_search_help
{
5389 git_print_page_nav
('','', $hash,$hash,$hash);
5392 <dt><b>commit</b></dt>
5393 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5395 my ($have_grep) = gitweb_check_feature
('grep');
5398 <dt><b>grep</b></dt>
5399 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5400 a different one) are searched for the given
5401 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5402 (POSIX extended) and the matches are listed. On large
5403 trees, this search can take a while and put some strain on the server, so please use it with
5404 some consideration.</dd>
5408 <dt><b>author</b></dt>
5409 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5410 <dt><b>committer</b></dt>
5411 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5413 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5414 if ($have_pickaxe) {
5416 <dt><b>pickaxe</b></dt>
5417 <dd>All commits that caused the string to appear or disappear from any file (changes that
5418 added, removed or "modified" the string) will be listed. This search can take a while and
5419 takes a lot of strain on the server, so please use it wisely.</dd>
5427 my $head = git_get_head_hash
($project);
5428 if (!defined $hash) {
5431 if (!defined $page) {
5434 my $refs = git_get_references
();
5436 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5438 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5440 if ($#commitlist >= 100) {
5442 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5443 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5447 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5448 git_print_header_div
('summary', $project);
5450 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5455 ## ......................................................................
5456 ## feeds (RSS, Atom; OPML)
5459 my $format = shift || 'atom';
5460 my ($have_blame) = gitweb_check_feature
('blame');
5462 # Atom: http://www.atomenabled.org/developers/syndication/
5463 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5464 if ($format ne 'rss' && $format ne 'atom') {
5465 die_error
(undef, "Unknown web feed format");
5468 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5469 my $head = $hash || 'HEAD';
5470 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5474 my $content_type = "application/$format+xml";
5475 if (defined $cgi->http('HTTP_ACCEPT') &&
5476 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5477 # browser (feed reader) prefers text/xml
5478 $content_type = 'text/xml';
5480 if (defined($commitlist[0])) {
5481 %latest_commit = %{$commitlist[0]};
5482 %latest_date = parse_date
($latest_commit{'author_epoch'});
5484 -type
=> $content_type,
5485 -charset
=> 'utf-8',
5486 -last_modified
=> $latest_date{'rfc2822'});
5489 -type
=> $content_type,
5490 -charset
=> 'utf-8');
5493 # Optimization: skip generating the body if client asks only
5494 # for Last-Modified date.
5495 return if ($cgi->request_method() eq 'HEAD');
5498 my $title = "$site_name - $project/$action";
5499 my $feed_type = 'log';
5500 if (defined $hash) {
5501 $title .= " - '$hash'";
5502 $feed_type = 'branch log';
5503 if (defined $file_name) {
5504 $title .= " :: $file_name";
5505 $feed_type = 'history';
5507 } elsif (defined $file_name) {
5508 $title .= " - $file_name";
5509 $feed_type = 'history';
5511 $title .= " $feed_type";
5512 my $descr = git_get_project_description
($project);
5513 if (defined $descr) {
5514 $descr = esc_html
($descr);
5516 $descr = "$project " .
5517 ($format eq 'rss' ? 'RSS' : 'Atom') .
5520 my $owner = git_get_project_owner
($project);
5521 $owner = esc_html
($owner);
5525 if (defined $file_name) {
5526 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5527 } elsif (defined $hash) {
5528 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5530 $alt_url = href
(-full
=>1, action
=>"summary");
5532 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5533 if ($format eq 'rss') {
5535 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5538 print "<title>$title</title>\n" .
5539 "<link>$alt_url</link>\n" .
5540 "<description>$descr</description>\n" .
5541 "<language>en</language>\n";
5542 } elsif ($format eq 'atom') {
5544 <feed xmlns="http://www.w3.org/2005/Atom">
5546 print "<title>$title</title>\n" .
5547 "<subtitle>$descr</subtitle>\n" .
5548 '<link rel="alternate" type="text/html" href="' .
5549 $alt_url . '" />' . "\n" .
5550 '<link rel="self" type="' . $content_type . '" href="' .
5551 $cgi->self_url() . '" />' . "\n" .
5552 "<id>" . href
(-full
=>1) . "</id>\n" .
5553 # use project owner for feed author
5554 "<author><name>$owner</name></author>\n";
5555 if (defined $favicon) {
5556 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5558 if (defined $logo_url) {
5559 # not twice as wide as tall: 72 x 27 pixels
5560 print "<logo>" . esc_url
($logo) . "</logo>\n";
5562 if (! %latest_date) {
5563 # dummy date to keep the feed valid until commits trickle in:
5564 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5566 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5571 for (my $i = 0; $i <= $#commitlist; $i++) {
5572 my %co = %{$commitlist[$i]};
5573 my $commit = $co{'id'};
5574 # we read 150, we always show 30 and the ones more recent than 48 hours
5575 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5578 my %cd = parse_date
($co{'author_epoch'});
5580 # get list of changed files
5581 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5582 $co{'parent'} || "--root",
5583 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5585 my @difftree = map { chomp; $_ } <$fd>;
5589 # print element (entry, item)
5590 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5591 if ($format eq 'rss') {
5593 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5594 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5595 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5596 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5597 "<link>$co_url</link>\n" .
5598 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5599 "<content:encoded>" .
5601 } elsif ($format eq 'atom') {
5603 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5604 "<updated>$cd{'iso-8601'}</updated>\n" .
5606 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5607 if ($co{'author_email'}) {
5608 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5610 print "</author>\n" .
5611 # use committer for contributor
5613 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5614 if ($co{'committer_email'}) {
5615 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5617 print "</contributor>\n" .
5618 "<published>$cd{'iso-8601'}</published>\n" .
5619 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5620 "<id>$co_url</id>\n" .
5621 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5622 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5624 my $comment = $co{'comment'};
5626 foreach my $line (@$comment) {
5627 $line = esc_html
($line);
5630 print "</pre><ul>\n";
5631 foreach my $difftree_line (@difftree) {
5632 my %difftree = parse_difftree_raw_line
($difftree_line);
5633 next if !$difftree{'from_id'};
5635 my $file = $difftree{'file'} || $difftree{'to_file'};
5639 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5640 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5641 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5642 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5643 -title
=> "diff"}, 'D');
5645 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5646 file_name
=>$file, hash_base
=>$commit),
5647 -title
=> "blame"}, 'B');
5649 # if this is not a feed of a file history
5650 if (!defined $file_name || $file_name ne $file) {
5651 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5652 file_name
=>$file, hash
=>$commit),
5653 -title
=> "history"}, 'H');
5655 $file = esc_path
($file);
5659 if ($format eq 'rss') {
5660 print "</ul>]]>\n" .
5661 "</content:encoded>\n" .
5663 } elsif ($format eq 'atom') {
5664 print "</ul>\n</div>\n" .
5671 if ($format eq 'rss') {
5672 print "</channel>\n</rss>\n";
5673 } elsif ($format eq 'atom') {
5687 my @list = git_get_projects_list
();
5689 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5691 <?xml version="1.0" encoding="utf-8"?>
5692 <opml version="1.0">
5694 <title>$site_name OPML Export</title>
5697 <outline text="git RSS feeds">
5700 foreach my $pr (@list) {
5702 my $head = git_get_head_hash
($proj{'path'});
5703 if (!defined $head) {
5706 $git_dir = "$projectroot/$proj{'path'}";
5707 my %co = parse_commit
($head);
5712 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5713 my $rss = "$my_url?p=$proj{'path'};a=rss";
5714 my $html = "$my_url?p=$proj{'path'};a=summary";
5715 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";