3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $searchtext = $cgi->param('s');
478 if (defined $searchtext) {
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
605 hash_parent_base
=> "hpb",
610 snapshot_format
=> "sf",
611 extra_options
=> "opt",
613 my %mapping = @mapping;
615 if ($params{-replay
}) {
616 while (my ($name, $symbol) = each %mapping) {
617 if (!exists $params{$name}) {
618 # to allow for multivalued params we use arrayref form
619 $params{$name} = [ $cgi->param($symbol) ];
624 $params{'project'} = $project unless exists $params{'project'};
626 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
628 # use PATH_INFO for project name
629 $href .= "/$params{'project'}" if defined $params{'project'};
630 delete $params{'project'};
632 # Summary just uses the project path URL
633 if (defined $params{'action'} && $params{'action'} eq 'summary') {
634 delete $params{'action'};
638 # now encode the parameters explicitly
640 for (my $i = 0; $i < @mapping; $i += 2) {
641 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
642 if (defined $params{$name}) {
643 if (ref($params{$name}) eq "ARRAY") {
644 foreach my $par (@{$params{$name}}) {
645 push @result, $symbol . "=" . esc_param
($par);
648 push @result, $symbol . "=" . esc_param
($params{$name});
652 $href .= "?" . join(';', @result) if scalar @result;
658 ## ======================================================================
659 ## validation, quoting/unquoting and escaping
661 sub validate_pathname
{
662 my $input = shift || return undef;
664 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
665 # at the beginning, at the end, and between slashes.
666 # also this catches doubled slashes
667 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
671 if ($input =~ m!\0!) {
677 sub validate_refname
{
678 my $input = shift || return undef;
680 # textual hashes are O.K.
681 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
684 # it must be correct pathname
685 $input = validate_pathname
($input)
687 # restrictions on ref name according to git-check-ref-format
688 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
694 # decode sequences of octets in utf8 into Perl's internal form,
695 # which is utf-8 with utf8 flag set if needed. gitweb writes out
696 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
700 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
704 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
708 # quote unsafe chars, but keep the slash, even when it's not
709 # correct, but quoted slashes look too horrible in bookmarks
712 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
718 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
721 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
727 # replace invalid utf8 character with SUBSTITUTION sequence
732 $str = to_utf8
($str);
733 $str = $cgi->escapeHTML($str);
734 if ($opts{'-nbsp'}) {
735 $str =~ s/ / /g;
737 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
741 # quote control characters and escape filename to HTML
746 $str = to_utf8
($str);
747 $str = $cgi->escapeHTML($str);
748 if ($opts{'-nbsp'}) {
749 $str =~ s/ / /g;
751 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
755 # Make control characters "printable", using character escape codes (CEC)
758 my %es = ( # character escape codes, aka escape sequences
759 "\t" => '\t', # tab (HT)
760 "\n" => '\n', # line feed (LF)
761 "\r" => '\r', # carrige return (CR)
762 "\f" => '\f', # form feed (FF)
763 "\b" => '\b', # backspace (BS)
764 "\a" => '\a', # alarm (bell) (BEL)
765 "\e" => '\e', # escape (ESC)
766 "\013" => '\v', # vertical tab (VT)
767 "\000" => '\0', # nul character (NUL)
769 my $chr = ( (exists $es{$cntrl})
771 : sprintf('\%03o', ord($cntrl)) );
772 return "<span class=\"cntrl\">$chr</span>";
775 # Alternatively use unicode control pictures codepoints,
776 # Unicode "printable representation" (PR)
779 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
780 return "<span class=\"cntrl\">$chr</span>";
783 # git may return quoted and escaped filenames
789 my %es = ( # character escape codes, aka escape sequences
790 't' => "\t", # tab (HT, TAB)
791 'n' => "\n", # newline (NL)
792 'r' => "\r", # return (CR)
793 'f' => "\f", # form feed (FF)
794 'b' => "\b", # backspace (BS)
795 'a' => "\a", # alarm (bell) (BEL)
796 'e' => "\e", # escape (ESC)
797 'v' => "\013", # vertical tab (VT)
800 if ($seq =~ m/^[0-7]{1,3}$/) {
801 # octal char sequence
802 return chr(oct($seq));
803 } elsif (exists $es{$seq}) {
804 # C escape sequence, aka character escape code
807 # quoted ordinary character
811 if ($str =~ m/^"(.*)"$/) {
814 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
819 # escape tabs (convert tabs to spaces)
823 while ((my $pos = index($line, "\t")) != -1) {
824 if (my $count = (8 - ($pos % 8))) {
825 my $spaces = ' ' x
$count;
826 $line =~ s/\t/$spaces/;
833 sub project_in_list
{
835 my @list = git_get_projects_list
();
836 return @list && scalar(grep { $_->{'path'} eq $project } @list);
839 ## ----------------------------------------------------------------------
840 ## HTML aware string manipulation
845 my $add_len = shift || 10;
847 # allow only $len chars, but don't cut a word if it would fit in $add_len
848 # if it doesn't fit, cut it if it's still longer than the dots we would add
849 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
852 if (length($tail) > 4) {
854 $body =~ s/&[^;]*$//; # remove chopped character entities
859 # takes the same arguments as chop_str, but also wraps a <span> around the
860 # result with a title attribute if it does get chopped. Additionally, the
861 # string is HTML-escaped.
862 sub chop_and_escape_str
{
865 my $add_len = shift || 10;
867 my $chopped = chop_str
($str, $len, $add_len);
868 if ($chopped eq $str) {
869 return esc_html
($chopped);
871 return qq{<span title="} . esc_html
($str) . qq{">} .
872 esc_html
($chopped) . qq{</span>};
876 ## ----------------------------------------------------------------------
877 ## functions returning short strings
879 # CSS class for given age value (in seconds)
885 } elsif ($age < 60*60*2) {
887 } elsif ($age < 60*60*24*2) {
894 # convert age in seconds to "nn units ago" string
899 if ($age > 60*60*24*365*2) {
900 $age_str = (int $age/60/60/24/365);
901 $age_str .= " years ago";
902 } elsif ($age > 60*60*24*(365/12)*2) {
903 $age_str = int $age/60/60/24/(365/12);
904 $age_str .= " months ago";
905 } elsif ($age > 60*60*24*7*2) {
906 $age_str = int $age/60/60/24/7;
907 $age_str .= " weeks ago";
908 } elsif ($age > 60*60*24*2) {
909 $age_str = int $age/60/60/24;
910 $age_str .= " days ago";
911 } elsif ($age > 60*60*2) {
912 $age_str = int $age/60/60;
913 $age_str .= " hours ago";
914 } elsif ($age > 60*2) {
915 $age_str = int $age/60;
916 $age_str .= " min ago";
919 $age_str .= " sec ago";
921 $age_str .= " right now";
927 S_IFINVALID
=> 0030000,
928 S_IFGITLINK
=> 0160000,
931 # submodule/subproject, a commit object reference
935 return (($mode & S_IFMT
) == S_IFGITLINK
)
938 # convert file mode in octal to symbolic file mode string
940 my $mode = oct shift;
942 if (S_ISGITLINK
($mode)) {
944 } elsif (S_ISDIR
($mode & S_IFMT
)) {
946 } elsif (S_ISLNK
($mode)) {
948 } elsif (S_ISREG
($mode)) {
949 # git cares only about the executable bit
950 if ($mode & S_IXUSR
) {
960 # convert file mode in octal to file type string
964 if ($mode !~ m/^[0-7]+$/) {
970 if (S_ISGITLINK
($mode)) {
972 } elsif (S_ISDIR
($mode & S_IFMT
)) {
974 } elsif (S_ISLNK
($mode)) {
976 } elsif (S_ISREG
($mode)) {
983 # convert file mode in octal to file type description string
987 if ($mode !~ m/^[0-7]+$/) {
993 if (S_ISGITLINK
($mode)) {
995 } elsif (S_ISDIR
($mode & S_IFMT
)) {
997 } elsif (S_ISLNK
($mode)) {
999 } elsif (S_ISREG
($mode)) {
1000 if ($mode & S_IXUSR
) {
1001 return "executable";
1011 ## ----------------------------------------------------------------------
1012 ## functions returning short HTML fragments, or transforming HTML fragments
1013 ## which don't belong to other sections
1015 # format line of commit message.
1016 sub format_log_line_html
{
1019 $line = esc_html
($line, -nbsp
=>1);
1020 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1023 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1024 -class => "text"}, $hash_text);
1025 $line =~ s/$hash_text/$link/;
1030 # format marker of refs pointing to given object
1031 sub format_ref_marker
{
1032 my ($refs, $id) = @_;
1035 if (defined $refs->{$id}) {
1036 foreach my $ref (@{$refs->{$id}}) {
1037 my ($type, $name) = qw();
1038 # e.g. tags/v2.6.11 or heads/next
1039 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1047 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1048 esc_html
($name) . "</span>";
1053 return ' <span class="refs">'. $markers . '</span>';
1059 # format, perhaps shortened and with markers, title line
1060 sub format_subject_html
{
1061 my ($long, $short, $href, $extra) = @_;
1062 $extra = '' unless defined($extra);
1064 if (length($short) < length($long)) {
1065 return $cgi->a({-href
=> $href, -class => "list subject",
1066 -title
=> to_utf8
($long)},
1067 esc_html
($short) . $extra);
1069 return $cgi->a({-href
=> $href, -class => "list subject"},
1070 esc_html
($long) . $extra);
1074 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1075 sub format_git_diff_header_line
{
1077 my $diffinfo = shift;
1078 my ($from, $to) = @_;
1080 if ($diffinfo->{'nparents'}) {
1082 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1083 if ($to->{'href'}) {
1084 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1085 esc_path
($to->{'file'}));
1086 } else { # file was deleted (no href)
1087 $line .= esc_path
($to->{'file'});
1091 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1092 if ($from->{'href'}) {
1093 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1094 'a/' . esc_path
($from->{'file'}));
1095 } else { # file was added (no href)
1096 $line .= 'a/' . esc_path
($from->{'file'});
1099 if ($to->{'href'}) {
1100 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1101 'b/' . esc_path
($to->{'file'}));
1102 } else { # file was deleted
1103 $line .= 'b/' . esc_path
($to->{'file'});
1107 return "<div class=\"diff header\">$line</div>\n";
1110 # format extended diff header line, before patch itself
1111 sub format_extended_diff_header_line
{
1113 my $diffinfo = shift;
1114 my ($from, $to) = @_;
1117 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1118 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1119 esc_path
($from->{'file'}));
1121 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1122 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1123 esc_path
($to->{'file'}));
1125 # match single <mode>
1126 if ($line =~ m/\s(\d{6})$/) {
1127 $line .= '<span class="info"> (' .
1128 file_type_long
($1) .
1132 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1133 # can match only for combined diff
1135 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1136 if ($from->{'href'}[$i]) {
1137 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1139 substr($diffinfo->{'from_id'}[$i],0,7));
1144 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1147 if ($to->{'href'}) {
1148 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1149 substr($diffinfo->{'to_id'},0,7));
1154 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1155 # can match only for ordinary diff
1156 my ($from_link, $to_link);
1157 if ($from->{'href'}) {
1158 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1159 substr($diffinfo->{'from_id'},0,7));
1161 $from_link = '0' x
7;
1163 if ($to->{'href'}) {
1164 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1165 substr($diffinfo->{'to_id'},0,7));
1169 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1170 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1173 return $line . "<br/>\n";
1176 # format from-file/to-file diff header
1177 sub format_diff_from_to_header
{
1178 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1183 #assert($line =~ m/^---/) if DEBUG;
1184 # no extra formatting for "^--- /dev/null"
1185 if (! $diffinfo->{'nparents'}) {
1186 # ordinary (single parent) diff
1187 if ($line =~ m!^--- "?a/!) {
1188 if ($from->{'href'}) {
1190 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1191 esc_path
($from->{'file'}));
1194 esc_path
($from->{'file'});
1197 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1200 # combined diff (merge commit)
1201 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1202 if ($from->{'href'}[$i]) {
1204 $cgi->a({-href
=>href
(action
=>"blobdiff",
1205 hash_parent
=>$diffinfo->{'from_id'}[$i],
1206 hash_parent_base
=>$parents[$i],
1207 file_parent
=>$from->{'file'}[$i],
1208 hash
=>$diffinfo->{'to_id'},
1210 file_name
=>$to->{'file'}),
1212 -title
=>"diff" . ($i+1)},
1215 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1216 esc_path
($from->{'file'}[$i]));
1218 $line = '--- /dev/null';
1220 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1225 #assert($line =~ m/^\+\+\+/) if DEBUG;
1226 # no extra formatting for "^+++ /dev/null"
1227 if ($line =~ m!^\+\+\+ "?b/!) {
1228 if ($to->{'href'}) {
1230 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1231 esc_path
($to->{'file'}));
1234 esc_path
($to->{'file'});
1237 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1242 # create note for patch simplified by combined diff
1243 sub format_diff_cc_simplified
{
1244 my ($diffinfo, @parents) = @_;
1247 $result .= "<div class=\"diff header\">" .
1249 if (!is_deleted
($diffinfo)) {
1250 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1252 hash
=>$diffinfo->{'to_id'},
1253 file_name
=>$diffinfo->{'to_file'}),
1255 esc_path
($diffinfo->{'to_file'}));
1257 $result .= esc_path
($diffinfo->{'to_file'});
1259 $result .= "</div>\n" . # class="diff header"
1260 "<div class=\"diff nodifferences\">" .
1262 "</div>\n"; # class="diff nodifferences"
1267 # format patch (diff) line (not to be used for diff headers)
1268 sub format_diff_line
{
1270 my ($from, $to) = @_;
1271 my $diff_class = "";
1275 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1277 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1278 if ($line =~ m/^\@{3}/) {
1279 $diff_class = " chunk_header";
1280 } elsif ($line =~ m/^\\/) {
1281 $diff_class = " incomplete";
1282 } elsif ($prefix =~ tr/+/+/) {
1283 $diff_class = " add";
1284 } elsif ($prefix =~ tr/-/-/) {
1285 $diff_class = " rem";
1288 # assume ordinary diff
1289 my $char = substr($line, 0, 1);
1291 $diff_class = " add";
1292 } elsif ($char eq '-') {
1293 $diff_class = " rem";
1294 } elsif ($char eq '@') {
1295 $diff_class = " chunk_header";
1296 } elsif ($char eq "\\") {
1297 $diff_class = " incomplete";
1300 $line = untabify
($line);
1301 if ($from && $to && $line =~ m/^\@{2} /) {
1302 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1303 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1305 $from_lines = 0 unless defined $from_lines;
1306 $to_lines = 0 unless defined $to_lines;
1308 if ($from->{'href'}) {
1309 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1310 -class=>"list"}, $from_text);
1312 if ($to->{'href'}) {
1313 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1314 -class=>"list"}, $to_text);
1316 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1317 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1318 return "<div class=\"diff$diff_class\">$line</div>\n";
1319 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1320 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1321 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1323 @from_text = split(' ', $ranges);
1324 for (my $i = 0; $i < @from_text; ++$i) {
1325 ($from_start[$i], $from_nlines[$i]) =
1326 (split(',', substr($from_text[$i], 1)), 0);
1329 $to_text = pop @from_text;
1330 $to_start = pop @from_start;
1331 $to_nlines = pop @from_nlines;
1333 $line = "<span class=\"chunk_info\">$prefix ";
1334 for (my $i = 0; $i < @from_text; ++$i) {
1335 if ($from->{'href'}[$i]) {
1336 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1337 -class=>"list"}, $from_text[$i]);
1339 $line .= $from_text[$i];
1343 if ($to->{'href'}) {
1344 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1345 -class=>"list"}, $to_text);
1349 $line .= " $prefix</span>" .
1350 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1351 return "<div class=\"diff$diff_class\">$line</div>\n";
1353 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1356 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1357 # linked. Pass the hash of the tree/commit to snapshot.
1358 sub format_snapshot_links
{
1360 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1361 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1362 my $num_fmts = @snapshot_fmts;
1363 if ($num_fmts > 1) {
1364 # A parenthesized list of links bearing format names.
1365 # e.g. "snapshot (_tar.gz_ _zip_)"
1366 return "snapshot (" . join(' ', map
1373 }, $known_snapshot_formats{$_}{'display'})
1374 , @snapshot_fmts) . ")";
1375 } elsif ($num_fmts == 1) {
1376 # A single "snapshot" link whose tooltip bears the format name.
1378 my ($fmt) = @snapshot_fmts;
1384 snapshot_format
=>$fmt
1386 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1388 } else { # $num_fmts == 0
1393 ## ----------------------------------------------------------------------
1394 ## git utility subroutines, invoking git commands
1396 # returns path to the core git executable and the --git-dir parameter as list
1398 return $GIT, '--git-dir='.$git_dir;
1401 # returns path to the core git executable and the --git-dir parameter as string
1403 return join(' ', git_cmd
());
1406 # get HEAD ref of given project as hash
1407 sub git_get_head_hash
{
1408 my $project = shift;
1409 my $o_git_dir = $git_dir;
1411 $git_dir = "$projectroot/$project";
1412 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1415 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1419 if (defined $o_git_dir) {
1420 $git_dir = $o_git_dir;
1425 # get type of given object
1429 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1431 close $fd or return;
1436 # repository configuration
1437 our $config_file = '';
1440 # store multiple values for single key as anonymous array reference
1441 # single values stored directly in the hash, not as [ <value> ]
1442 sub hash_set_multi
{
1443 my ($hash, $key, $value) = @_;
1445 if (!exists $hash->{$key}) {
1446 $hash->{$key} = $value;
1447 } elsif (!ref $hash->{$key}) {
1448 $hash->{$key} = [ $hash->{$key}, $value ];
1450 push @{$hash->{$key}}, $value;
1454 # return hash of git project configuration
1455 # optionally limited to some section, e.g. 'gitweb'
1456 sub git_parse_project_config
{
1457 my $section_regexp = shift;
1462 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1465 while (my $keyval = <$fh>) {
1467 my ($key, $value) = split(/\n/, $keyval, 2);
1469 hash_set_multi
(\
%config, $key, $value)
1470 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1477 # convert config value to boolean, 'true' or 'false'
1478 # no value, number > 0, 'true' and 'yes' values are true
1479 # rest of values are treated as false (never as error)
1480 sub config_to_bool
{
1483 # strip leading and trailing whitespace
1487 return (!defined $val || # section.key
1488 ($val =~ /^\d+$/ && $val) || # section.key = 1
1489 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1492 # convert config value to simple decimal number
1493 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1494 # to be multiplied by 1024, 1048576, or 1073741824
1498 # strip leading and trailing whitespace
1502 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1504 # unknown unit is treated as 1
1505 return $num * ($unit eq 'g' ? 1073741824 :
1506 $unit eq 'm' ? 1048576 :
1507 $unit eq 'k' ? 1024 : 1);
1512 # convert config value to array reference, if needed
1513 sub config_to_multi
{
1516 return ref($val) ? $val : [ $val ];
1519 sub git_get_project_config
{
1520 my ($key, $type) = @_;
1523 return unless ($key);
1524 $key =~ s/^gitweb\.//;
1525 return if ($key =~ m/\W/);
1528 if (defined $type) {
1531 unless ($type eq 'bool' || $type eq 'int');
1535 if (!defined $config_file ||
1536 $config_file ne "$git_dir/config") {
1537 %config = git_parse_project_config
('gitweb');
1538 $config_file = "$git_dir/config";
1542 if (!defined $type) {
1543 return $config{"gitweb.$key"};
1544 } elsif ($type eq 'bool') {
1545 # backward compatibility: 'git config --bool' returns true/false
1546 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1547 } elsif ($type eq 'int') {
1548 return config_to_int
($config{"gitweb.$key"});
1550 return $config{"gitweb.$key"};
1553 # get hash of given path at given ref
1554 sub git_get_hash_by_path
{
1556 my $path = shift || return undef;
1561 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1562 or die_error
(undef, "Open git-ls-tree failed");
1564 close $fd or return undef;
1566 if (!defined $line) {
1567 # there is no tree or hash given by $path at $base
1571 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1572 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1573 if (defined $type && $type ne $2) {
1574 # type doesn't match
1580 # get path of entry with given hash at given tree-ish (ref)
1581 # used to get 'from' filename for combined diff (merge commit) for renames
1582 sub git_get_path_by_hash
{
1583 my $base = shift || return;
1584 my $hash = shift || return;
1588 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1590 while (my $line = <$fd>) {
1593 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1594 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1595 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1604 ## ......................................................................
1605 ## git utility functions, directly accessing git repository
1607 sub git_get_project_description
{
1610 $git_dir = "$projectroot/$path";
1611 open my $fd, "$projectroot/$path/description"
1612 or return git_get_project_config
('description');
1615 if (defined $descr) {
1621 sub git_get_project_url_list
{
1624 $git_dir = "$projectroot/$path";
1625 open my $fd, "$projectroot/$path/cloneurl"
1626 or return wantarray ?
1627 @{ config_to_multi
(git_get_project_config
('url')) } :
1628 config_to_multi
(git_get_project_config
('url'));
1629 my @git_project_url_list = map { chomp; $_ } <$fd>;
1632 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1635 sub git_get_projects_list
{
1640 $filter =~ s/\.git$//;
1642 my ($check_forks) = gitweb_check_feature
('forks');
1644 if (-d
$projects_list) {
1645 # search in directory
1646 my $dir = $projects_list . ($filter ? "/$filter" : '');
1647 # remove the trailing "/"
1649 my $pfxlen = length("$dir");
1650 my $pfxdepth = ($dir =~ tr!/!!);
1653 follow_fast
=> 1, # follow symbolic links
1654 follow_skip
=> 2, # ignore duplicates
1655 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1657 # skip project-list toplevel, if we get it.
1658 return if (m!^[/.]$!);
1659 # only directories can be git repositories
1660 return unless (-d
$_);
1661 # don't traverse too deep (Find is super slow on os x)
1662 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1663 $File::Find
::prune
= 1;
1667 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1668 # we check related file in $projectroot
1669 if ($check_forks and $subdir =~ m
#/.#) {
1670 $File::Find
::prune
= 1;
1671 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1672 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1673 $File::Find
::prune
= 1;
1678 } elsif (-f
$projects_list) {
1679 # read from file(url-encoded):
1680 # 'git%2Fgit.git Linus+Torvalds'
1681 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1682 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1684 open my ($fd), $projects_list or return;
1686 while (my $line = <$fd>) {
1688 my ($path, $owner) = split ' ', $line;
1689 $path = unescape
($path);
1690 $owner = unescape
($owner);
1691 if (!defined $path) {
1694 if ($filter ne '') {
1695 # looking for forks;
1696 my $pfx = substr($path, 0, length($filter));
1697 if ($pfx ne $filter) {
1700 my $sfx = substr($path, length($filter));
1701 if ($sfx !~ /^\/.*\
.git
$/) {
1704 } elsif ($check_forks) {
1706 foreach my $filter (keys %paths) {
1707 # looking for forks;
1708 my $pfx = substr($path, 0, length($filter));
1709 if ($pfx ne $filter) {
1712 my $sfx = substr($path, length($filter));
1713 if ($sfx !~ /^\/.*\
.git
$/) {
1716 # is a fork, don't include it in
1721 if (check_export_ok
("$projectroot/$path")) {
1724 owner
=> to_utf8
($owner),
1727 (my $forks_path = $path) =~ s/\.git$//;
1728 $paths{$forks_path}++;
1736 our $gitweb_project_owner = undef;
1737 sub git_get_project_list_from_file
{
1739 return if (defined $gitweb_project_owner);
1741 $gitweb_project_owner = {};
1742 # read from file (url-encoded):
1743 # 'git%2Fgit.git Linus+Torvalds'
1744 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1745 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1746 if (-f
$projects_list) {
1747 open (my $fd , $projects_list);
1748 while (my $line = <$fd>) {
1750 my ($pr, $ow) = split ' ', $line;
1751 $pr = unescape
($pr);
1752 $ow = unescape
($ow);
1753 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1759 sub git_get_project_owner
{
1760 my $project = shift;
1763 return undef unless $project;
1765 if (!defined $gitweb_project_owner) {
1766 git_get_project_list_from_file
();
1769 if (exists $gitweb_project_owner->{$project}) {
1770 $owner = $gitweb_project_owner->{$project};
1772 if (!defined $owner) {
1773 $owner = get_file_owner
("$projectroot/$project");
1779 sub git_get_last_activity
{
1783 $git_dir = "$projectroot/$path";
1784 open($fd, "-|", git_cmd
(), 'for-each-ref',
1785 '--format=%(committer)',
1786 '--sort=-committerdate',
1788 'refs/heads') or return;
1789 my $most_recent = <$fd>;
1790 close $fd or return;
1791 if (defined $most_recent &&
1792 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1794 my $age = time - $timestamp;
1795 return ($age, age_string
($age));
1797 return (undef, undef);
1800 sub git_get_references
{
1801 my $type = shift || "";
1803 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1804 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1805 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1806 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1809 while (my $line = <$fd>) {
1811 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1812 if (defined $refs{$1}) {
1813 push @{$refs{$1}}, $2;
1819 close $fd or return;
1823 sub git_get_rev_name_tags
{
1824 my $hash = shift || return undef;
1826 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1828 my $name_rev = <$fd>;
1831 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1834 # catches also '$hash undefined' output
1839 ## ----------------------------------------------------------------------
1840 ## parse to hash functions
1844 my $tz = shift || "-0000";
1847 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1848 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1849 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1850 $date{'hour'} = $hour;
1851 $date{'minute'} = $min;
1852 $date{'mday'} = $mday;
1853 $date{'day'} = $days[$wday];
1854 $date{'month'} = $months[$mon];
1855 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1856 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1857 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1858 $mday, $months[$mon], $hour ,$min;
1859 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1860 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1862 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1863 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1864 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1865 $date{'hour_local'} = $hour;
1866 $date{'minute_local'} = $min;
1867 $date{'tz_local'} = $tz;
1868 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1869 1900+$year, $mon+1, $mday,
1870 $hour, $min, $sec, $tz);
1879 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1880 $tag{'id'} = $tag_id;
1881 while (my $line = <$fd>) {
1883 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1884 $tag{'object'} = $1;
1885 } elsif ($line =~ m/^type (.+)$/) {
1887 } elsif ($line =~ m/^tag (.+)$/) {
1889 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1890 $tag{'author'} = $1;
1893 } elsif ($line =~ m/--BEGIN/) {
1894 push @comment, $line;
1896 } elsif ($line eq "") {
1900 push @comment, <$fd>;
1901 $tag{'comment'} = \
@comment;
1902 close $fd or return;
1903 if (!defined $tag{'name'}) {
1909 sub parse_commit_text
{
1910 my ($commit_text, $withparents) = @_;
1911 my @commit_lines = split '\n', $commit_text;
1914 pop @commit_lines; # Remove '\0'
1916 if (! @commit_lines) {
1920 my $header = shift @commit_lines;
1921 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1924 ($co{'id'}, my @parents) = split ' ', $header;
1925 while (my $line = shift @commit_lines) {
1926 last if $line eq "\n";
1927 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1929 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1931 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1933 $co{'author_epoch'} = $2;
1934 $co{'author_tz'} = $3;
1935 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1936 $co{'author_name'} = $1;
1937 $co{'author_email'} = $2;
1939 $co{'author_name'} = $co{'author'};
1941 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1942 $co{'committer'} = $1;
1943 $co{'committer_epoch'} = $2;
1944 $co{'committer_tz'} = $3;
1945 $co{'committer_name'} = $co{'committer'};
1946 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1947 $co{'committer_name'} = $1;
1948 $co{'committer_email'} = $2;
1950 $co{'committer_name'} = $co{'committer'};
1954 if (!defined $co{'tree'}) {
1957 $co{'parents'} = \
@parents;
1958 $co{'parent'} = $parents[0];
1960 foreach my $title (@commit_lines) {
1963 $co{'title'} = chop_str
($title, 80, 5);
1964 # remove leading stuff of merges to make the interesting part visible
1965 if (length($title) > 50) {
1966 $title =~ s/^Automatic //;
1967 $title =~ s/^merge (of|with) /Merge ... /i;
1968 if (length($title) > 50) {
1969 $title =~ s/(http|rsync):\/\///;
1971 if (length($title) > 50) {
1972 $title =~ s/(master|www|rsync)\.//;
1974 if (length($title) > 50) {
1975 $title =~ s/kernel.org:?//;
1977 if (length($title) > 50) {
1978 $title =~ s/\/pub\/scm//;
1981 $co{'title_short'} = chop_str
($title, 50, 5);
1985 if ($co{'title'} eq "") {
1986 $co{'title'} = $co{'title_short'} = '(no commit message)';
1988 # remove added spaces
1989 foreach my $line (@commit_lines) {
1992 $co{'comment'} = \
@commit_lines;
1994 my $age = time - $co{'committer_epoch'};
1996 $co{'age_string'} = age_string
($age);
1997 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1998 if ($age > 60*60*24*7*2) {
1999 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2000 $co{'age_string_age'} = $co{'age_string'};
2002 $co{'age_string_date'} = $co{'age_string'};
2003 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2009 my ($commit_id) = @_;
2014 open my $fd, "-|", git_cmd
(), "rev-list",
2020 or die_error
(undef, "Open git-rev-list failed");
2021 %co = parse_commit_text
(<$fd>, 1);
2028 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
2036 open my $fd, "-|", git_cmd
(), "rev-list",
2038 ($arg ? ($arg) : ()),
2039 ("--max-count=" . $maxcount),
2040 ("--skip=" . $skip),
2044 ($filename ? ($filename) : ())
2045 or die_error
(undef, "Open git-rev-list failed");
2046 while (my $line = <$fd>) {
2047 my %co = parse_commit_text
($line);
2052 return wantarray ? @cos : \
@cos;
2055 # parse ref from ref_file, given by ref_id, with given type
2057 my $ref_file = shift;
2059 my $type = shift || git_get_type
($ref_id);
2062 $ref_item{'type'} = $type;
2063 $ref_item{'id'} = $ref_id;
2064 $ref_item{'epoch'} = 0;
2065 $ref_item{'age'} = "unknown";
2066 if ($type eq "tag") {
2067 my %tag = parse_tag
($ref_id);
2068 $ref_item{'comment'} = $tag{'comment'};
2069 if ($tag{'type'} eq "commit") {
2070 my %co = parse_commit
($tag{'object'});
2071 $ref_item{'epoch'} = $co{'committer_epoch'};
2072 $ref_item{'age'} = $co{'age_string'};
2073 } elsif (defined($tag{'epoch'})) {
2074 my $age = time - $tag{'epoch'};
2075 $ref_item{'epoch'} = $tag{'epoch'};
2076 $ref_item{'age'} = age_string
($age);
2078 $ref_item{'reftype'} = $tag{'type'};
2079 $ref_item{'name'} = $tag{'name'};
2080 $ref_item{'refid'} = $tag{'object'};
2081 } elsif ($type eq "commit"){
2082 my %co = parse_commit
($ref_id);
2083 $ref_item{'reftype'} = "commit";
2084 $ref_item{'name'} = $ref_file;
2085 $ref_item{'title'} = $co{'title'};
2086 $ref_item{'refid'} = $ref_id;
2087 $ref_item{'epoch'} = $co{'committer_epoch'};
2088 $ref_item{'age'} = $co{'age_string'};
2090 $ref_item{'reftype'} = $type;
2091 $ref_item{'name'} = $ref_file;
2092 $ref_item{'refid'} = $ref_id;
2098 # parse line of git-diff-tree "raw" output
2099 sub parse_difftree_raw_line
{
2103 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2104 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2105 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2106 $res{'from_mode'} = $1;
2107 $res{'to_mode'} = $2;
2108 $res{'from_id'} = $3;
2110 $res{'status'} = $res{'status_str'} = $5;
2111 $res{'similarity'} = $6;
2112 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2113 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2115 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2118 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2119 # combined diff (for merge commit)
2120 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2121 $res{'nparents'} = length($1);
2122 $res{'from_mode'} = [ split(' ', $2) ];
2123 $res{'to_mode'} = pop @{$res{'from_mode'}};
2124 $res{'from_id'} = [ split(' ', $3) ];
2125 $res{'to_id'} = pop @{$res{'from_id'}};
2126 $res{'status_str'} = $4;
2127 $res{'status'} = [ split('', $4) ];
2128 $res{'to_file'} = unquote
($5);
2130 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2131 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2132 $res{'commit'} = $1;
2135 return wantarray ? %res : \
%res;
2138 # wrapper: return parsed line of git-diff-tree "raw" output
2139 # (the argument might be raw line, or parsed info)
2140 sub parsed_difftree_line
{
2141 my $line_or_ref = shift;
2143 if (ref($line_or_ref) eq "HASH") {
2144 # pre-parsed (or generated by hand)
2145 return $line_or_ref;
2147 return parse_difftree_raw_line
($line_or_ref);
2151 # parse line of git-ls-tree output
2152 sub parse_ls_tree_line
($;%) {
2157 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2158 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2166 $res{'name'} = unquote
($4);
2169 return wantarray ? %res : \
%res;
2172 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2173 sub parse_from_to_diffinfo
{
2174 my ($diffinfo, $from, $to, @parents) = @_;
2176 if ($diffinfo->{'nparents'}) {
2178 $from->{'file'} = [];
2179 $from->{'href'} = [];
2180 fill_from_file_info
($diffinfo, @parents)
2181 unless exists $diffinfo->{'from_file'};
2182 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2183 $from->{'file'}[$i] =
2184 defined $diffinfo->{'from_file'}[$i] ?
2185 $diffinfo->{'from_file'}[$i] :
2186 $diffinfo->{'to_file'};
2187 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2188 $from->{'href'}[$i] = href
(action
=>"blob",
2189 hash_base
=>$parents[$i],
2190 hash
=>$diffinfo->{'from_id'}[$i],
2191 file_name
=>$from->{'file'}[$i]);
2193 $from->{'href'}[$i] = undef;
2197 # ordinary (not combined) diff
2198 $from->{'file'} = $diffinfo->{'from_file'};
2199 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2200 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2201 hash
=>$diffinfo->{'from_id'},
2202 file_name
=>$from->{'file'});
2204 delete $from->{'href'};
2208 $to->{'file'} = $diffinfo->{'to_file'};
2209 if (!is_deleted
($diffinfo)) { # file exists in result
2210 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2211 hash
=>$diffinfo->{'to_id'},
2212 file_name
=>$to->{'file'});
2214 delete $to->{'href'};
2218 ## ......................................................................
2219 ## parse to array of hashes functions
2221 sub git_get_heads_list
{
2225 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2226 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2227 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2230 while (my $line = <$fd>) {
2234 my ($refinfo, $committerinfo) = split(/\0/, $line);
2235 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2236 my ($committer, $epoch, $tz) =
2237 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2238 $name =~ s!^refs/heads/!!;
2240 $ref_item{'name'} = $name;
2241 $ref_item{'id'} = $hash;
2242 $ref_item{'title'} = $title || '(no commit message)';
2243 $ref_item{'epoch'} = $epoch;
2245 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2247 $ref_item{'age'} = "unknown";
2250 push @headslist, \
%ref_item;
2254 return wantarray ? @headslist : \
@headslist;
2257 sub git_get_tags_list
{
2261 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2262 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2263 '--format=%(objectname) %(objecttype) %(refname) '.
2264 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2267 while (my $line = <$fd>) {
2271 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2272 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2273 my ($creator, $epoch, $tz) =
2274 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2275 $name =~ s!^refs/tags/!!;
2277 $ref_item{'type'} = $type;
2278 $ref_item{'id'} = $id;
2279 $ref_item{'name'} = $name;
2280 if ($type eq "tag") {
2281 $ref_item{'subject'} = $title;
2282 $ref_item{'reftype'} = $reftype;
2283 $ref_item{'refid'} = $refid;
2285 $ref_item{'reftype'} = $type;
2286 $ref_item{'refid'} = $id;
2289 if ($type eq "tag" || $type eq "commit") {
2290 $ref_item{'epoch'} = $epoch;
2292 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2294 $ref_item{'age'} = "unknown";
2298 push @tagslist, \
%ref_item;
2302 return wantarray ? @tagslist : \
@tagslist;
2305 ## ----------------------------------------------------------------------
2306 ## filesystem-related functions
2308 sub get_file_owner
{
2311 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2312 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2313 if (!defined $gcos) {
2317 $owner =~ s/[,;].*$//;
2318 return to_utf8
($owner);
2321 ## ......................................................................
2322 ## mimetype related functions
2324 sub mimetype_guess_file
{
2325 my $filename = shift;
2326 my $mimemap = shift;
2327 -r
$mimemap or return undef;
2330 open(MIME
, $mimemap) or return undef;
2332 next if m/^#/; # skip comments
2333 my ($mime, $exts) = split(/\t+/);
2334 if (defined $exts) {
2335 my @exts = split(/\s+/, $exts);
2336 foreach my $ext (@exts) {
2337 $mimemap{$ext} = $mime;
2343 $filename =~ /\.([^.]*)$/;
2344 return $mimemap{$1};
2347 sub mimetype_guess
{
2348 my $filename = shift;
2350 $filename =~ /\./ or return undef;
2352 if ($mimetypes_file) {
2353 my $file = $mimetypes_file;
2354 if ($file !~ m!^/!) { # if it is relative path
2355 # it is relative to project
2356 $file = "$projectroot/$project/$file";
2358 $mime = mimetype_guess_file
($filename, $file);
2360 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2366 my $filename = shift;
2369 my $mime = mimetype_guess
($filename);
2370 $mime and return $mime;
2374 return $default_blob_plain_mimetype unless $fd;
2377 return 'text/plain' .
2378 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2379 } elsif (! $filename) {
2380 return 'application/octet-stream';
2381 } elsif ($filename =~ m/\.png$/i) {
2383 } elsif ($filename =~ m/\.gif$/i) {
2385 } elsif ($filename =~ m/\.jpe?g$/i) {
2386 return 'image/jpeg';
2388 return 'application/octet-stream';
2392 ## ======================================================================
2393 ## functions printing HTML: header, footer, error page
2395 sub git_header_html
{
2396 my $status = shift || "200 OK";
2397 my $expires = shift;
2399 my $title = "$site_name";
2400 if (defined $project) {
2401 $title .= " - " . to_utf8
($project);
2402 if (defined $action) {
2403 $title .= "/$action";
2404 if (defined $file_name) {
2405 $title .= " - " . esc_path
($file_name);
2406 if ($action eq "tree" && $file_name !~ m
|/$|) {
2413 # require explicit support from the UA if we are to send the page as
2414 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2415 # we have to do this because MSIE sometimes globs '*/*', pretending to
2416 # support xhtml+xml but choking when it gets what it asked for.
2417 if (defined $cgi->http('HTTP_ACCEPT') &&
2418 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2419 $cgi->Accept('application/xhtml+xml') != 0) {
2420 $content_type = 'application/xhtml+xml';
2422 $content_type = 'text/html';
2424 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2425 -status
=> $status, -expires
=> $expires);
2426 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2428 <?xml version="1.0" encoding="utf-8"?>
2429 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2430 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2431 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2432 <!-- git core binaries version $git_version -->
2434 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2435 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2436 <meta name="robots" content="index, nofollow"/>
2437 <title>$title</title>
2439 # print out each stylesheet that exist
2440 if (defined $stylesheet) {
2441 #provides backwards capability for those people who define style sheet in a config file
2442 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2444 foreach my $stylesheet (@stylesheets) {
2445 next unless $stylesheet;
2446 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2449 if (defined $project) {
2450 printf('<link rel="alternate" title="%s log RSS feed" '.
2451 'href="%s" type="application/rss+xml" />'."\n",
2452 esc_param
($project), href
(action
=>"rss"));
2453 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2454 'href="%s" type="application/rss+xml" />'."\n",
2455 esc_param
($project), href
(action
=>"rss",
2456 extra_options
=>"--no-merges"));
2457 printf('<link rel="alternate" title="%s log Atom feed" '.
2458 'href="%s" type="application/atom+xml" />'."\n",
2459 esc_param
($project), href
(action
=>"atom"));
2460 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2461 'href="%s" type="application/atom+xml" />'."\n",
2462 esc_param
($project), href
(action
=>"atom",
2463 extra_options
=>"--no-merges"));
2465 printf('<link rel="alternate" title="%s projects list" '.
2466 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2467 $site_name, href
(project
=>undef, action
=>"project_index"));
2468 printf('<link rel="alternate" title="%s projects feeds" '.
2469 'href="%s" type="text/x-opml"/>'."\n",
2470 $site_name, href
(project
=>undef, action
=>"opml"));
2472 if (defined $favicon) {
2473 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2479 if (-f
$site_header) {
2480 open (my $fd, $site_header);
2485 print "<div class=\"page_header\">\n" .
2486 $cgi->a({-href
=> esc_url
($logo_url),
2487 -title
=> $logo_label},
2488 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2489 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2490 if (defined $project) {
2491 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2492 if (defined $action) {
2499 my ($have_search) = gitweb_check_feature
('search');
2500 if ((defined $project) && ($have_search)) {
2501 if (!defined $searchtext) {
2505 if (defined $hash_base) {
2506 $search_hash = $hash_base;
2507 } elsif (defined $hash) {
2508 $search_hash = $hash;
2510 $search_hash = "HEAD";
2512 my $action = $my_uri;
2513 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2514 if ($use_pathinfo) {
2515 $action .= "/$project";
2517 $cgi->param("p", $project);
2519 $cgi->param("a", "search");
2520 $cgi->param("h", $search_hash);
2521 print $cgi->startform(-method => "get", -action
=> $action) .
2522 "<div class=\"search\">\n" .
2523 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2524 $cgi->hidden(-name
=> "a") . "\n" .
2525 $cgi->hidden(-name
=> "h") . "\n" .
2526 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2527 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2528 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2530 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2532 $cgi->end_form() . "\n";
2536 sub git_footer_html
{
2537 print "<div class=\"page_footer\">\n";
2538 if (defined $project) {
2539 my $descr = git_get_project_description
($project);
2540 if (defined $descr) {
2541 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2543 print $cgi->a({-href
=> href
(action
=>"rss"),
2544 -class => "rss_logo"}, "RSS") . " ";
2545 print $cgi->a({-href
=> href
(action
=>"atom"),
2546 -class => "rss_logo"}, "Atom") . "\n";
2548 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2549 -class => "rss_logo"}, "OPML") . " ";
2550 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2551 -class => "rss_logo"}, "TXT") . "\n";
2555 if (-f
$site_footer) {
2556 open (my $fd, $site_footer);
2566 my $status = shift || "403 Forbidden";
2567 my $error = shift || "Malformed query, file missing or permission denied";
2569 git_header_html
($status);
2571 <div class="page_body">
2581 ## ----------------------------------------------------------------------
2582 ## functions printing or outputting HTML: navigation
2584 sub git_print_page_nav
{
2585 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2586 $extra = '' if !defined $extra; # pager or formats
2588 my @navs = qw(summary shortlog log commit commitdiff tree);
2590 @navs = grep { $_ ne $suppress } @navs;
2593 my %arg = map { $_ => {action
=>$_} } @navs;
2594 if (defined $head) {
2595 for (qw(commit commitdiff)) {
2596 $arg{$_}{'hash'} = $head;
2598 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2599 for (qw(shortlog log)) {
2600 $arg{$_}{'hash'} = $head;
2604 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2605 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2607 print "<div class=\"page_nav\">\n" .
2609 map { $_ eq $current ?
2610 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2612 print "<br/>\n$extra<br/>\n" .
2616 sub format_paging_nav
{
2617 my ($action, $hash, $head, $page, $nrevs) = @_;
2621 if ($hash ne $head || $page) {
2622 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2624 $paging_nav .= "HEAD";
2628 $paging_nav .= " ⋅ " .
2629 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2630 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2632 $paging_nav .= " ⋅ prev";
2635 if ($nrevs >= (100 * ($page+1)-1)) {
2636 $paging_nav .= " ⋅ " .
2637 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2638 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2640 $paging_nav .= " ⋅ next";
2646 ## ......................................................................
2647 ## functions printing or outputting HTML: div
2649 sub git_print_header_div
{
2650 my ($action, $title, $hash, $hash_base) = @_;
2653 $args{'action'} = $action;
2654 $args{'hash'} = $hash if $hash;
2655 $args{'hash_base'} = $hash_base if $hash_base;
2657 print "<div class=\"header\">\n" .
2658 $cgi->a({-href
=> href
(%args), -class => "title"},
2659 $title ? $title : $action) .
2663 #sub git_print_authorship (\%) {
2664 sub git_print_authorship
{
2667 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2668 print "<div class=\"author_date\">" .
2669 esc_html
($co->{'author_name'}) .
2671 if ($ad{'hour_local'} < 6) {
2672 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2673 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2675 printf(" (%02d:%02d %s)",
2676 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2681 sub git_print_page_path
{
2687 print "<div class=\"page_path\">";
2688 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2689 -title
=> 'tree root'}, to_utf8
("[$project]"));
2691 if (defined $name) {
2692 my @dirname = split '/', $name;
2693 my $basename = pop @dirname;
2696 foreach my $dir (@dirname) {
2697 $fullname .= ($fullname ? '/' : '') . $dir;
2698 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2700 -title
=> $fullname}, esc_path
($dir));
2703 if (defined $type && $type eq 'blob') {
2704 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2706 -title
=> $name}, esc_path
($basename));
2707 } elsif (defined $type && $type eq 'tree') {
2708 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2710 -title
=> $name}, esc_path
($basename));
2713 print esc_path
($basename);
2716 print "<br/></div>\n";
2719 # sub git_print_log (\@;%) {
2720 sub git_print_log
($;%) {
2724 if ($opts{'-remove_title'}) {
2725 # remove title, i.e. first line of log
2728 # remove leading empty lines
2729 while (defined $log->[0] && $log->[0] eq "") {
2736 foreach my $line (@$log) {
2737 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2740 if (! $opts{'-remove_signoff'}) {
2741 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2744 # remove signoff lines
2751 # print only one empty line
2752 # do not print empty line after signoff
2754 next if ($empty || $signoff);
2760 print format_log_line_html
($line) . "<br/>\n";
2763 if ($opts{'-final_empty_line'}) {
2764 # end with single empty line
2765 print "<br/>\n" unless $empty;
2769 # return link target (what link points to)
2770 sub git_get_link_target
{
2775 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2779 $link_target = <$fd>;
2784 return $link_target;
2787 # given link target, and the directory (basedir) the link is in,
2788 # return target of link relative to top directory (top tree);
2789 # return undef if it is not possible (including absolute links).
2790 sub normalize_link_target
{
2791 my ($link_target, $basedir, $hash_base) = @_;
2793 # we can normalize symlink target only if $hash_base is provided
2794 return unless $hash_base;
2796 # absolute symlinks (beginning with '/') cannot be normalized
2797 return if (substr($link_target, 0, 1) eq '/');
2799 # normalize link target to path from top (root) tree (dir)
2802 $path = $basedir . '/' . $link_target;
2804 # we are in top (root) tree (dir)
2805 $path = $link_target;
2808 # remove //, /./, and /../
2810 foreach my $part (split('/', $path)) {
2811 # discard '.' and ''
2812 next if (!$part || $part eq '.');
2814 if ($part eq '..') {
2818 # link leads outside repository (outside top dir)
2822 push @path_parts, $part;
2825 $path = join('/', @path_parts);
2830 # print tree entry (row of git_tree), but without encompassing <tr> element
2831 sub git_print_tree_entry
{
2832 my ($t, $basedir, $hash_base, $have_blame) = @_;
2835 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2837 # The format of a table row is: mode list link. Where mode is
2838 # the mode of the entry, list is the name of the entry, an href,
2839 # and link is the action links of the entry.
2841 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2842 if ($t->{'type'} eq "blob") {
2843 print "<td class=\"list\">" .
2844 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2845 file_name
=>"$basedir$t->{'name'}", %base_key),
2846 -class => "list"}, esc_path
($t->{'name'}));
2847 if (S_ISLNK
(oct $t->{'mode'})) {
2848 my $link_target = git_get_link_target
($t->{'hash'});
2850 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2851 if (defined $norm_target) {
2853 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2854 file_name
=>$norm_target),
2855 -title
=> $norm_target}, esc_path
($link_target));
2857 print " -> " . esc_path
($link_target);
2862 print "<td class=\"link\">";
2863 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2864 file_name
=>"$basedir$t->{'name'}", %base_key)},
2868 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2869 file_name
=>"$basedir$t->{'name'}", %base_key)},
2872 if (defined $hash_base) {
2874 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2875 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2879 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2880 file_name
=>"$basedir$t->{'name'}")},
2884 } elsif ($t->{'type'} eq "tree") {
2885 print "<td class=\"list\">";
2886 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2887 file_name
=>"$basedir$t->{'name'}", %base_key)},
2888 esc_path
($t->{'name'}));
2890 print "<td class=\"link\">";
2891 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2892 file_name
=>"$basedir$t->{'name'}", %base_key)},
2894 if (defined $hash_base) {
2896 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2897 file_name
=>"$basedir$t->{'name'}")},
2902 # unknown object: we can only present history for it
2903 # (this includes 'commit' object, i.e. submodule support)
2904 print "<td class=\"list\">" .
2905 esc_path
($t->{'name'}) .
2907 print "<td class=\"link\">";
2908 if (defined $hash_base) {
2909 print $cgi->a({-href
=> href
(action
=>"history",
2910 hash_base
=>$hash_base,
2911 file_name
=>"$basedir$t->{'name'}")},
2918 ## ......................................................................
2919 ## functions printing large fragments of HTML
2921 # get pre-image filenames for merge (combined) diff
2922 sub fill_from_file_info
{
2923 my ($diff, @parents) = @_;
2925 $diff->{'from_file'} = [ ];
2926 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2927 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2928 if ($diff->{'status'}[$i] eq 'R' ||
2929 $diff->{'status'}[$i] eq 'C') {
2930 $diff->{'from_file'}[$i] =
2931 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2938 # is current raw difftree line of file deletion
2940 my $diffinfo = shift;
2942 return $diffinfo->{'status_str'} =~ /D/;
2945 # does patch correspond to [previous] difftree raw line
2946 # $diffinfo - hashref of parsed raw diff format
2947 # $patchinfo - hashref of parsed patch diff format
2948 # (the same keys as in $diffinfo)
2949 sub is_patch_split
{
2950 my ($diffinfo, $patchinfo) = @_;
2952 return defined $diffinfo && defined $patchinfo
2953 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2957 sub git_difftree_body
{
2958 my ($difftree, $hash, @parents) = @_;
2959 my ($parent) = $parents[0];
2960 my ($have_blame) = gitweb_check_feature
('blame');
2961 print "<div class=\"list_head\">\n";
2962 if ($#{$difftree} > 10) {
2963 print(($#{$difftree} + 1) . " files changed:\n");
2967 print "<table class=\"" .
2968 (@parents > 1 ? "combined " : "") .
2971 # header only for combined diff in 'commitdiff' view
2972 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2975 print "<thead><tr>\n" .
2976 "<th></th><th></th>\n"; # filename, patchN link
2977 for (my $i = 0; $i < @parents; $i++) {
2978 my $par = $parents[$i];
2980 $cgi->a({-href
=> href
(action
=>"commitdiff",
2981 hash
=>$hash, hash_parent
=>$par),
2982 -title
=> 'commitdiff to parent number ' .
2983 ($i+1) . ': ' . substr($par,0,7)},
2987 print "</tr></thead>\n<tbody>\n";
2992 foreach my $line (@{$difftree}) {
2993 my $diff = parsed_difftree_line
($line);
2996 print "<tr class=\"dark\">\n";
2998 print "<tr class=\"light\">\n";
3002 if (exists $diff->{'nparents'}) { # combined diff
3004 fill_from_file_info
($diff, @parents)
3005 unless exists $diff->{'from_file'};
3007 if (!is_deleted
($diff)) {
3008 # file exists in the result (child) commit
3010 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3011 file_name
=>$diff->{'to_file'},
3013 -class => "list"}, esc_path
($diff->{'to_file'})) .
3017 esc_path
($diff->{'to_file'}) .
3021 if ($action eq 'commitdiff') {
3024 print "<td class=\"link\">" .
3025 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3030 my $has_history = 0;
3031 my $not_deleted = 0;
3032 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3033 my $hash_parent = $parents[$i];
3034 my $from_hash = $diff->{'from_id'}[$i];
3035 my $from_path = $diff->{'from_file'}[$i];
3036 my $status = $diff->{'status'}[$i];
3038 $has_history ||= ($status ne 'A');
3039 $not_deleted ||= ($status ne 'D');
3041 if ($status eq 'A') {
3042 print "<td class=\"link\" align=\"right\"> | </td>\n";
3043 } elsif ($status eq 'D') {
3044 print "<td class=\"link\">" .
3045 $cgi->a({-href
=> href
(action
=>"blob",
3048 file_name
=>$from_path)},
3052 if ($diff->{'to_id'} eq $from_hash) {
3053 print "<td class=\"link nochange\">";
3055 print "<td class=\"link\">";
3057 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3058 hash
=>$diff->{'to_id'},
3059 hash_parent
=>$from_hash,
3061 hash_parent_base
=>$hash_parent,
3062 file_name
=>$diff->{'to_file'},
3063 file_parent
=>$from_path)},
3069 print "<td class=\"link\">";
3071 print $cgi->a({-href
=> href
(action
=>"blob",
3072 hash
=>$diff->{'to_id'},
3073 file_name
=>$diff->{'to_file'},
3076 print " | " if ($has_history);
3079 print $cgi->a({-href
=> href
(action
=>"history",
3080 file_name
=>$diff->{'to_file'},
3087 next; # instead of 'else' clause, to avoid extra indent
3089 # else ordinary diff
3091 my ($to_mode_oct, $to_mode_str, $to_file_type);
3092 my ($from_mode_oct, $from_mode_str, $from_file_type);
3093 if ($diff->{'to_mode'} ne ('0' x
6)) {
3094 $to_mode_oct = oct $diff->{'to_mode'};
3095 if (S_ISREG
($to_mode_oct)) { # only for regular file
3096 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3098 $to_file_type = file_type
($diff->{'to_mode'});
3100 if ($diff->{'from_mode'} ne ('0' x
6)) {
3101 $from_mode_oct = oct $diff->{'from_mode'};
3102 if (S_ISREG
($to_mode_oct)) { # only for regular file
3103 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3105 $from_file_type = file_type
($diff->{'from_mode'});
3108 if ($diff->{'status'} eq "A") { # created
3109 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3110 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3111 $mode_chng .= "]</span>";
3113 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3114 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3115 -class => "list"}, esc_path
($diff->{'file'}));
3117 print "<td>$mode_chng</td>\n";
3118 print "<td class=\"link\">";
3119 if ($action eq 'commitdiff') {
3122 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3125 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3126 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3130 } elsif ($diff->{'status'} eq "D") { # deleted
3131 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3133 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3134 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3135 -class => "list"}, esc_path
($diff->{'file'}));
3137 print "<td>$mode_chng</td>\n";
3138 print "<td class=\"link\">";
3139 if ($action eq 'commitdiff') {
3142 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3145 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3146 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3149 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3150 file_name
=>$diff->{'file'})},
3153 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3154 file_name
=>$diff->{'file'})},
3158 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3159 my $mode_chnge = "";
3160 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3161 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3162 if ($from_file_type ne $to_file_type) {
3163 $mode_chnge .= " from $from_file_type to $to_file_type";
3165 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3166 if ($from_mode_str && $to_mode_str) {
3167 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3168 } elsif ($to_mode_str) {
3169 $mode_chnge .= " mode: $to_mode_str";
3172 $mode_chnge .= "]</span>\n";
3175 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3176 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3177 -class => "list"}, esc_path
($diff->{'file'}));
3179 print "<td>$mode_chnge</td>\n";
3180 print "<td class=\"link\">";
3181 if ($action eq 'commitdiff') {
3184 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3186 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3187 # "commit" view and modified file (not onlu mode changed)
3188 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3189 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3190 hash_base
=>$hash, hash_parent_base
=>$parent,
3191 file_name
=>$diff->{'file'})},
3195 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3196 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3199 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3200 file_name
=>$diff->{'file'})},
3203 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3204 file_name
=>$diff->{'file'})},
3208 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3209 my %status_name = ('R' => 'moved', 'C' => 'copied');
3210 my $nstatus = $status_name{$diff->{'status'}};
3212 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3213 # mode also for directories, so we cannot use $to_mode_str
3214 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3217 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3218 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3219 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3220 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3221 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3222 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3223 -class => "list"}, esc_path
($diff->{'from_file'})) .
3224 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3225 "<td class=\"link\">";
3226 if ($action eq 'commitdiff') {
3229 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3231 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3232 # "commit" view and modified file (not only pure rename or copy)
3233 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3234 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3235 hash_base
=>$hash, hash_parent_base
=>$parent,
3236 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3240 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3241 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3244 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3245 file_name
=>$diff->{'to_file'})},
3248 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3249 file_name
=>$diff->{'to_file'})},
3253 } # we should not encounter Unmerged (U) or Unknown (X) status
3256 print "</tbody>" if $has_header;
3260 sub git_patchset_body
{
3261 my ($fd, $difftree, $hash, @hash_parents) = @_;
3262 my ($hash_parent) = $hash_parents[0];
3264 my $is_combined = (@hash_parents > 1);
3266 my $patch_number = 0;
3272 print "<div class=\"patchset\">\n";
3274 # skip to first patch
3275 while ($patch_line = <$fd>) {
3278 last if ($patch_line =~ m/^diff /);
3282 while ($patch_line) {
3284 # parse "git diff" header line
3285 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3286 # $1 is from_name, which we do not use
3287 $to_name = unquote
($2);
3288 $to_name =~ s!^b/!!;
3289 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3290 # $1 is 'cc' or 'combined', which we do not use
3291 $to_name = unquote
($2);
3296 # check if current patch belong to current raw line
3297 # and parse raw git-diff line if needed
3298 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3299 # this is continuation of a split patch
3300 print "<div class=\"patch cont\">\n";
3302 # advance raw git-diff output if needed
3303 $patch_idx++ if defined $diffinfo;
3305 # read and prepare patch information
3306 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3308 # compact combined diff output can have some patches skipped
3309 # find which patch (using pathname of result) we are at now;
3311 while ($to_name ne $diffinfo->{'to_file'}) {
3312 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3313 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3314 "</div>\n"; # class="patch"
3319 last if $patch_idx > $#$difftree;
3320 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3324 # modifies %from, %to hashes
3325 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3327 # this is first patch for raw difftree line with $patch_idx index
3328 # we index @$difftree array from 0, but number patches from 1
3329 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3333 #assert($patch_line =~ m/^diff /) if DEBUG;
3334 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3336 # print "git diff" header
3337 print format_git_diff_header_line
($patch_line, $diffinfo,
3340 # print extended diff header
3341 print "<div class=\"diff extended_header\">\n";
3343 while ($patch_line = <$fd>) {
3346 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3348 print format_extended_diff_header_line
($patch_line, $diffinfo,
3351 print "</div>\n"; # class="diff extended_header"
3353 # from-file/to-file diff header
3354 if (! $patch_line) {
3355 print "</div>\n"; # class="patch"
3358 next PATCH
if ($patch_line =~ m/^diff /);
3359 #assert($patch_line =~ m/^---/) if DEBUG;
3361 my $last_patch_line = $patch_line;
3362 $patch_line = <$fd>;
3364 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3366 print format_diff_from_to_header
($last_patch_line, $patch_line,
3367 $diffinfo, \
%from, \
%to,
3372 while ($patch_line = <$fd>) {
3375 next PATCH
if ($patch_line =~ m/^diff /);
3377 print format_diff_line
($patch_line, \
%from, \
%to);
3381 print "</div>\n"; # class="patch"
3384 # for compact combined (--cc) format, with chunk and patch simpliciaction
3385 # patchset might be empty, but there might be unprocessed raw lines
3386 for (++$patch_idx if $patch_number > 0;
3387 $patch_idx < @$difftree;
3389 # read and prepare patch information
3390 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3392 # generate anchor for "patch" links in difftree / whatchanged part
3393 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3394 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3395 "</div>\n"; # class="patch"
3400 if ($patch_number == 0) {
3401 if (@hash_parents > 1) {
3402 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3404 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3408 print "</div>\n"; # class="patchset"
3411 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3413 sub git_project_list_body
{
3414 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3416 my ($check_forks) = gitweb_check_feature
('forks');
3419 foreach my $pr (@$projlist) {
3420 my (@aa) = git_get_last_activity
($pr->{'path'});
3424 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3425 if (!defined $pr->{'descr'}) {
3426 my $descr = git_get_project_description
($pr->{'path'}) || "";
3427 $pr->{'descr_long'} = to_utf8
($descr);
3428 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3430 if (!defined $pr->{'owner'}) {
3431 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3434 my $pname = $pr->{'path'};
3435 if (($pname =~ s/\.git$//) &&
3436 ($pname !~ /\/$/) &&
3437 (-d
"$projectroot/$pname")) {
3438 $pr->{'forks'} = "-d $projectroot/$pname";
3444 push @projects, $pr;
3447 $order ||= $default_projects_order;
3448 $from = 0 unless defined $from;
3449 $to = $#projects if (!defined $to || $#projects < $to);
3451 print "<table class=\"project_list\">\n";
3452 unless ($no_header) {
3455 print "<th></th>\n";
3457 if ($order eq "project") {
3458 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3459 print "<th>Project</th>\n";
3462 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3463 -class => "header"}, "Project") .
3466 if ($order eq "descr") {
3467 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3468 print "<th>Description</th>\n";
3471 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3472 -class => "header"}, "Description") .
3475 if ($order eq "owner") {
3476 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3477 print "<th>Owner</th>\n";
3480 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3481 -class => "header"}, "Owner") .
3484 if ($order eq "age") {
3485 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3486 print "<th>Last Change</th>\n";
3489 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3490 -class => "header"}, "Last Change") .
3493 print "<th></th>\n" .
3497 for (my $i = $from; $i <= $to; $i++) {
3498 my $pr = $projects[$i];
3500 print "<tr class=\"dark\">\n";
3502 print "<tr class=\"light\">\n";
3507 if ($pr->{'forks'}) {
3508 print "<!-- $pr->{'forks'} -->\n";
3509 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3513 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3514 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3515 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3516 -class => "list", -title
=> $pr->{'descr_long'}},
3517 esc_html
($pr->{'descr'})) . "</td>\n" .
3518 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3519 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3520 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3521 "<td class=\"link\">" .
3522 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3523 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3524 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3525 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3526 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3530 if (defined $extra) {
3533 print "<td></td>\n";
3535 print "<td colspan=\"5\">$extra</td>\n" .
3541 sub git_shortlog_body
{
3542 # uses global variable $project
3543 my ($commitlist, $from, $to, $refs, $extra) = @_;
3545 $from = 0 unless defined $from;
3546 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3548 print "<table class=\"shortlog\">\n";
3550 for (my $i = $from; $i <= $to; $i++) {
3551 my %co = %{$commitlist->[$i]};
3552 my $commit = $co{'id'};
3553 my $ref = format_ref_marker
($refs, $commit);
3555 print "<tr class=\"dark\">\n";
3557 print "<tr class=\"light\">\n";
3560 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3561 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3562 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3563 "<td><i>" . $author . "</i></td>\n" .
3565 print format_subject_html
($co{'title'}, $co{'title_short'},
3566 href
(action
=>"commit", hash
=>$commit), $ref);
3568 "<td class=\"link\">" .
3569 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3570 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3571 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3572 my $snapshot_links = format_snapshot_links
($commit);
3573 if (defined $snapshot_links) {
3574 print " | " . $snapshot_links;
3579 if (defined $extra) {
3581 "<td colspan=\"4\">$extra</td>\n" .
3587 sub git_history_body
{
3588 # Warning: assumes constant type (blob or tree) during history
3589 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3591 $from = 0 unless defined $from;
3592 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3594 print "<table class=\"history\">\n";
3596 for (my $i = $from; $i <= $to; $i++) {
3597 my %co = %{$commitlist->[$i]};
3601 my $commit = $co{'id'};
3603 my $ref = format_ref_marker
($refs, $commit);
3606 print "<tr class=\"dark\">\n";
3608 print "<tr class=\"light\">\n";
3611 # shortlog uses chop_str($co{'author_name'}, 10)
3612 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3613 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3614 "<td><i>" . $author . "</i></td>\n" .
3616 # originally git_history used chop_str($co{'title'}, 50)
3617 print format_subject_html
($co{'title'}, $co{'title_short'},
3618 href
(action
=>"commit", hash
=>$commit), $ref);
3620 "<td class=\"link\">" .
3621 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3622 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3624 if ($ftype eq 'blob') {
3625 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3626 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3627 if (defined $blob_current && defined $blob_parent &&
3628 $blob_current ne $blob_parent) {
3630 $cgi->a({-href
=> href
(action
=>"blobdiff",
3631 hash
=>$blob_current, hash_parent
=>$blob_parent,
3632 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3633 file_name
=>$file_name)},
3640 if (defined $extra) {
3642 "<td colspan=\"4\">$extra</td>\n" .
3649 # uses global variable $project
3650 my ($taglist, $from, $to, $extra) = @_;
3651 $from = 0 unless defined $from;
3652 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3654 print "<table class=\"tags\">\n";
3656 for (my $i = $from; $i <= $to; $i++) {
3657 my $entry = $taglist->[$i];
3659 my $comment = $tag{'subject'};
3661 if (defined $comment) {
3662 $comment_short = chop_str
($comment, 30, 5);
3665 print "<tr class=\"dark\">\n";
3667 print "<tr class=\"light\">\n";
3670 if (defined $tag{'age'}) {
3671 print "<td><i>$tag{'age'}</i></td>\n";
3673 print "<td></td>\n";
3676 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3677 -class => "list name"}, esc_html
($tag{'name'})) .
3680 if (defined $comment) {
3681 print format_subject_html
($comment, $comment_short,
3682 href
(action
=>"tag", hash
=>$tag{'id'}));
3685 "<td class=\"selflink\">";
3686 if ($tag{'type'} eq "tag") {
3687 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3692 "<td class=\"link\">" . " | " .
3693 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3694 if ($tag{'reftype'} eq "commit") {
3695 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3696 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3697 } elsif ($tag{'reftype'} eq "blob") {
3698 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3703 if (defined $extra) {
3705 "<td colspan=\"5\">$extra</td>\n" .
3711 sub git_heads_body
{
3712 # uses global variable $project
3713 my ($headlist, $head, $from, $to, $extra) = @_;
3714 $from = 0 unless defined $from;
3715 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3717 print "<table class=\"heads\">\n";
3719 for (my $i = $from; $i <= $to; $i++) {
3720 my $entry = $headlist->[$i];
3722 my $curr = $ref{'id'} eq $head;
3724 print "<tr class=\"dark\">\n";
3726 print "<tr class=\"light\">\n";
3729 print "<td><i>$ref{'age'}</i></td>\n" .
3730 ($curr ? "<td class=\"current_head\">" : "<td>") .
3731 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3732 -class => "list name"},esc_html
($ref{'name'})) .
3734 "<td class=\"link\">" .
3735 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3736 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3737 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3741 if (defined $extra) {
3743 "<td colspan=\"3\">$extra</td>\n" .
3749 sub git_search_grep_body
{
3750 my ($commitlist, $from, $to, $extra) = @_;
3751 $from = 0 unless defined $from;
3752 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3754 print "<table class=\"commit_search\">\n";
3756 for (my $i = $from; $i <= $to; $i++) {
3757 my %co = %{$commitlist->[$i]};
3761 my $commit = $co{'id'};
3763 print "<tr class=\"dark\">\n";
3765 print "<tr class=\"light\">\n";
3768 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3769 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3770 "<td><i>" . $author . "</i></td>\n" .
3772 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3773 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3774 my $comment = $co{'comment'};
3775 foreach my $line (@$comment) {
3776 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3777 my $lead = esc_html
($1) || "";
3778 $lead = chop_str
($lead, 30, 10);
3779 my $match = esc_html
($2) || "";
3780 my $trail = esc_html
($3) || "";
3781 $trail = chop_str
($trail, 30, 10);
3782 my $text = "$lead<span class=\"match\">$match</span>$trail";
3783 print chop_str
($text, 80, 5) . "<br/>\n";
3787 "<td class=\"link\">" .
3788 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3790 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3794 if (defined $extra) {
3796 "<td colspan=\"3\">$extra</td>\n" .
3802 ## ======================================================================
3803 ## ======================================================================
3806 sub git_project_list
{
3807 my $order = $cgi->param('o');
3808 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3809 die_error
(undef, "Unknown order parameter");
3812 my @list = git_get_projects_list
();
3814 die_error
(undef, "No projects found");
3818 if (-f
$home_text) {
3819 print "<div class=\"index_include\">\n";
3820 open (my $fd, $home_text);
3825 git_project_list_body
(\
@list, $order);
3830 my $order = $cgi->param('o');
3831 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3832 die_error
(undef, "Unknown order parameter");
3835 my @list = git_get_projects_list
($project);
3837 die_error
(undef, "No forks found");
3841 git_print_page_nav
('','');
3842 git_print_header_div
('summary', "$project forks");
3843 git_project_list_body
(\
@list, $order);
3847 sub git_project_index
{
3848 my @projects = git_get_projects_list
($project);
3851 -type
=> 'text/plain',
3852 -charset
=> 'utf-8',
3853 -content_disposition
=> 'inline; filename="index.aux"');
3855 foreach my $pr (@projects) {
3856 if (!exists $pr->{'owner'}) {
3857 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3860 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3861 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3862 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3863 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3867 print "$path $owner\n";
3872 my $descr = git_get_project_description
($project) || "none";
3873 my %co = parse_commit
("HEAD");
3874 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3875 my $head = $co{'id'};
3877 my $owner = git_get_project_owner
($project);
3879 my $refs = git_get_references
();
3880 # These get_*_list functions return one more to allow us to see if
3881 # there are more ...
3882 my @taglist = git_get_tags_list
(16);
3883 my @headlist = git_get_heads_list
(16);
3885 my ($check_forks) = gitweb_check_feature
('forks');
3888 @forklist = git_get_projects_list
($project);
3892 git_print_page_nav
('summary','', $head);
3894 print "<div class=\"title\"> </div>\n";
3895 print "<table class=\"projects_list\">\n" .
3896 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3897 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3898 if (defined $cd{'rfc2822'}) {
3899 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3902 # use per project git URL list in $projectroot/$project/cloneurl
3903 # or make project git URL from git base URL and project name
3904 my $url_tag = "URL";
3905 my @url_list = git_get_project_url_list
($project);
3906 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3907 foreach my $git_url (@url_list) {
3908 next unless $git_url;
3909 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3914 if (-s
"$projectroot/$project/README.html") {
3915 if (open my $fd, "$projectroot/$project/README.html") {
3916 print "<div class=\"title\">readme</div>\n" .
3917 "<div class=\"readme\">\n";
3918 print $_ while (<$fd>);
3919 print "\n</div>\n"; # class="readme"
3924 # we need to request one more than 16 (0..15) to check if
3926 my @commitlist = $head ? parse_commits
($head, 17) : ();
3928 git_print_header_div
('shortlog');
3929 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3930 $#commitlist <= 15 ? undef :
3931 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3935 git_print_header_div
('tags');
3936 git_tags_body
(\
@taglist, 0, 15,
3937 $#taglist <= 15 ? undef :
3938 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3942 git_print_header_div
('heads');
3943 git_heads_body
(\
@headlist, $head, 0, 15,
3944 $#headlist <= 15 ? undef :
3945 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3949 git_print_header_div
('forks');
3950 git_project_list_body
(\
@forklist, undef, 0, 15,
3951 $#forklist <= 15 ? undef :
3952 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3960 my $head = git_get_head_hash
($project);
3962 git_print_page_nav
('','', $head,undef,$head);
3963 my %tag = parse_tag
($hash);
3966 die_error
(undef, "Unknown tag object");
3969 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3970 print "<div class=\"title_text\">\n" .
3971 "<table class=\"object_header\">\n" .
3973 "<td>object</td>\n" .
3974 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3975 $tag{'object'}) . "</td>\n" .
3976 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3977 $tag{'type'}) . "</td>\n" .
3979 if (defined($tag{'author'})) {
3980 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3981 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3982 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3983 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3986 print "</table>\n\n" .
3988 print "<div class=\"page_body\">";
3989 my $comment = $tag{'comment'};
3990 foreach my $line (@$comment) {
3992 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4002 my ($have_blame) = gitweb_check_feature
('blame');
4004 die_error
('403 Permission denied', "Permission denied");
4006 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4007 $hash_base ||= git_get_head_hash
($project);
4008 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4009 my %co = parse_commit
($hash_base)
4010 or die_error
(undef, "Reading commit failed");
4011 if (!defined $hash) {
4012 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4013 or die_error
(undef, "Error looking up file");
4015 $ftype = git_get_type
($hash);
4016 if ($ftype !~ "blob") {
4017 die_error
('400 Bad Request', "Object is not a blob");
4019 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4020 $file_name, $hash_base)
4021 or die_error
(undef, "Open git-blame failed");
4024 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4027 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4030 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4032 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4033 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4034 git_print_page_path
($file_name, $ftype, $hash_base);
4035 my @rev_color = (qw(light2 dark2));
4036 my $num_colors = scalar(@rev_color);
4037 my $current_color = 0;
4040 <div class="page_body">
4041 <table class="blame">
4042 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4047 last unless defined $_;
4048 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4049 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4050 if (!exists $metainfo{$full_rev}) {
4051 $metainfo{$full_rev} = {};
4053 my $meta = $metainfo{$full_rev};
4056 if (/^(\S+) (.*)$/) {
4062 my $rev = substr($full_rev, 0, 8);
4063 my $author = $meta->{'author'};
4064 my %date = parse_date
($meta->{'author-time'},
4065 $meta->{'author-tz'});
4066 my $date = $date{'iso-tz'};
4068 $current_color = ++$current_color % $num_colors;
4070 print "<tr class=\"$rev_color[$current_color]\">\n";
4072 print "<td class=\"sha1\"";
4073 print " title=\"". esc_html
($author) . ", $date\"";
4074 print " rowspan=\"$group_size\"" if ($group_size > 1);
4076 print $cgi->a({-href
=> href
(action
=>"commit",
4078 file_name
=>$file_name)},
4082 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4083 or die_error
(undef, "Open git-rev-parse failed");
4084 my $parent_commit = <$dd>;
4086 chomp($parent_commit);
4087 my $blamed = href
(action
=> 'blame',
4088 file_name
=> $meta->{'filename'},
4089 hash_base
=> $parent_commit);
4090 print "<td class=\"linenr\">";
4091 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4093 -class => "linenr" },
4096 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4102 or print "Reading blob failed\n";
4109 my ($have_blame) = gitweb_check_feature
('blame');
4111 die_error
('403 Permission denied', "Permission denied");
4113 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4114 $hash_base ||= git_get_head_hash
($project);
4115 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4116 my %co = parse_commit
($hash_base)
4117 or die_error
(undef, "Reading commit failed");
4118 if (!defined $hash) {
4119 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4120 or die_error
(undef, "Error lookup file");
4122 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4123 or die_error
(undef, "Open git-annotate failed");
4126 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4129 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4132 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4134 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4135 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4136 git_print_page_path
($file_name, 'blob', $hash_base);
4137 print "<div class=\"page_body\">\n";
4139 <table class="blame">
4148 my @line_class = (qw(light dark));
4149 my $line_class_len = scalar (@line_class);
4150 my $line_class_num = $#line_class;
4151 while (my $line = <$fd>) {
4163 $line_class_num = ($line_class_num + 1) % $line_class_len;
4165 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4172 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4175 $short_rev = substr ($long_rev, 0, 8);
4176 $age = time () - $time;
4177 $age_str = age_string
($age);
4178 $age_str =~ s/ / /g;
4179 $age_class = age_class
($age);
4180 $author = esc_html
($author);
4181 $author =~ s/ / /g;
4183 $data = untabify
($data);
4184 $data = esc_html
($data);
4187 <tr class="$line_class[$line_class_num]">
4188 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4189 <td class="$age_class">$age_str</td>
4191 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4192 <td class="pre">$data</td>
4195 } # while (my $line = <$fd>)
4196 print "</table>\n\n";
4198 or print "Reading blob failed.\n";
4204 my $head = git_get_head_hash
($project);
4206 git_print_page_nav
('','', $head,undef,$head);
4207 git_print_header_div
('summary', $project);
4209 my @tagslist = git_get_tags_list
();
4211 git_tags_body
(\
@tagslist);
4217 my $head = git_get_head_hash
($project);
4219 git_print_page_nav
('','', $head,undef,$head);
4220 git_print_header_div
('summary', $project);
4222 my @headslist = git_get_heads_list
();
4224 git_heads_body
(\
@headslist, $head);
4229 sub git_blob_plain
{
4232 if (!defined $hash) {
4233 if (defined $file_name) {
4234 my $base = $hash_base || git_get_head_hash
($project);
4235 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4236 or die_error
(undef, "Error lookup file");
4238 die_error
(undef, "No file name defined");
4240 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4241 # blobs defined by non-textual hash id's can be cached
4246 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4247 or die_error
(undef, "Couldn't cat $file_name, $hash");
4249 $type ||= blob_mimetype
($fd, $file_name);
4251 # save as filename, even when no $file_name is given
4252 my $save_as = "$hash";
4253 if (defined $file_name) {
4254 $save_as = $file_name;
4255 } elsif ($type =~ m/^text\//) {
4262 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4264 binmode STDOUT
, ':raw';
4266 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4274 if (!defined $hash) {
4275 if (defined $file_name) {
4276 my $base = $hash_base || git_get_head_hash
($project);
4277 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4278 or die_error
(undef, "Error lookup file");
4280 die_error
(undef, "No file name defined");
4282 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4283 # blobs defined by non-textual hash id's can be cached
4287 my ($have_blame) = gitweb_check_feature
('blame');
4288 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4289 or die_error
(undef, "Couldn't cat $file_name, $hash");
4290 my $mimetype = blob_mimetype
($fd, $file_name);
4291 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4293 return git_blob_plain
($mimetype);
4295 # we can have blame only for text/* mimetype
4296 $have_blame &&= ($mimetype =~ m!^text/!);
4298 git_header_html
(undef, $expires);
4299 my $formats_nav = '';
4300 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4301 if (defined $file_name) {
4304 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4309 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4312 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4315 $cgi->a({-href
=> href
(action
=>"blob",
4316 hash_base
=>"HEAD", file_name
=>$file_name)},
4320 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4323 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4324 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4326 print "<div class=\"page_nav\">\n" .
4327 "<br/><br/></div>\n" .
4328 "<div class=\"title\">$hash</div>\n";
4330 git_print_page_path
($file_name, "blob", $hash_base);
4331 print "<div class=\"page_body\">\n";
4332 if ($mimetype =~ m!^text/!) {
4334 while (my $line = <$fd>) {
4337 $line = untabify
($line);
4338 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4339 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4341 } elsif ($mimetype =~ m!^image/!) {
4342 print qq
!<img type
="$mimetype"!;
4344 print qq
! alt
="$file_name" title
="$file_name"!;
4347 href(action=>"blob_plain
", hash=>$hash,
4348 hash_base=>$hash_base, file_name=>$file_name) .
4352 or print "Reading blob failed.\n";
4358 if (!defined $hash_base) {
4359 $hash_base = "HEAD";
4361 if (!defined $hash) {
4362 if (defined $file_name) {
4363 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4369 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4370 or die_error
(undef, "Open git-ls-tree failed");
4371 my @entries = map { chomp; $_ } <$fd>;
4372 close $fd or die_error
(undef, "Reading tree failed");
4375 my $refs = git_get_references
();
4376 my $ref = format_ref_marker
($refs, $hash_base);
4379 my ($have_blame) = gitweb_check_feature
('blame');
4380 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4382 if (defined $file_name) {
4384 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4386 $cgi->a({-href
=> href
(action
=>"tree",
4387 hash_base
=>"HEAD", file_name
=>$file_name)},
4390 my $snapshot_links = format_snapshot_links
($hash);
4391 if (defined $snapshot_links) {
4392 # FIXME: Should be available when we have no hash base as well.
4393 push @views_nav, $snapshot_links;
4395 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4396 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4399 print "<div class=\"page_nav\">\n";
4400 print "<br/><br/></div>\n";
4401 print "<div class=\"title\">$hash</div>\n";
4403 if (defined $file_name) {
4404 $basedir = $file_name;
4405 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4409 git_print_page_path
($file_name, 'tree', $hash_base);
4410 print "<div class=\"page_body\">\n";
4411 print "<table class=\"tree\">\n";
4413 # '..' (top directory) link if possible
4414 if (defined $hash_base &&
4415 defined $file_name && $file_name =~ m![^/]+$!) {
4417 print "<tr class=\"dark\">\n";
4419 print "<tr class=\"light\">\n";
4423 my $up = $file_name;
4424 $up =~ s!/?[^/]+$!!;
4425 undef $up unless $up;
4426 # based on git_print_tree_entry
4427 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4428 print '<td class="list">';
4429 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4433 print "<td class=\"link\"></td>\n";
4437 foreach my $line (@entries) {
4438 my %t = parse_ls_tree_line
($line, -z
=> 1);
4441 print "<tr class=\"dark\">\n";
4443 print "<tr class=\"light\">\n";
4447 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4451 print "</table>\n" .
4457 my @supported_fmts = gitweb_check_feature
('snapshot');
4458 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4460 my $format = $cgi->param('sf');
4461 if (!@supported_fmts) {
4462 die_error
('403 Permission denied', "Permission denied");
4464 # default to first supported snapshot format
4465 $format ||= $supported_fmts[0];
4466 if ($format !~ m/^[a-z0-9]+$/) {
4467 die_error
(undef, "Invalid snapshot format parameter");
4468 } elsif (!exists($known_snapshot_formats{$format})) {
4469 die_error
(undef, "Unknown snapshot format");
4470 } elsif (!grep($_ eq $format, @supported_fmts)) {
4471 die_error
(undef, "Unsupported snapshot format");
4474 if (!defined $hash) {
4475 $hash = git_get_head_hash
($project);
4478 my $git_command = git_cmd_str
();
4479 my $name = $project;
4480 $name =~ s
,([^/])/*\
.git
$,$1,;
4481 $name = basename
($name);
4482 my $filename = to_utf8
($name);
4483 $name =~ s/\047/\047\\\047\047/g;
4485 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4486 $cmd = "$git_command archive " .
4487 "--format=$known_snapshot_formats{$format}{'format'} " .
4488 "--prefix=\'$name\'/ $hash";
4489 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4490 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4494 -type
=> $known_snapshot_formats{$format}{'type'},
4495 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4496 -status
=> '200 OK');
4498 open my $fd, "-|", $cmd
4499 or die_error
(undef, "Execute git-archive failed");
4500 binmode STDOUT
, ':raw';
4502 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4507 my $head = git_get_head_hash
($project);
4508 if (!defined $hash) {
4511 if (!defined $page) {
4514 my $refs = git_get_references
();
4516 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4518 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4521 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4524 my %co = parse_commit
($hash);
4526 git_print_header_div
('summary', $project);
4527 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4529 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4530 for (my $i = 0; $i <= $to; $i++) {
4531 my %co = %{$commitlist[$i]};
4533 my $commit = $co{'id'};
4534 my $ref = format_ref_marker
($refs, $commit);
4535 my %ad = parse_date
($co{'author_epoch'});
4536 git_print_header_div
('commit',
4537 "<span class=\"age\">$co{'age_string'}</span>" .
4538 esc_html
($co{'title'}) . $ref,
4540 print "<div class=\"title_text\">\n" .
4541 "<div class=\"log_link\">\n" .
4542 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4544 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4546 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4549 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4552 print "<div class=\"log_body\">\n";
4553 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4556 if ($#commitlist >= 100) {
4557 print "<div class=\"page_nav\">\n";
4558 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4559 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4566 $hash ||= $hash_base || "HEAD";
4567 my %co = parse_commit
($hash);
4569 die_error
(undef, "Unknown commit object");
4571 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4572 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4574 my $parent = $co{'parent'};
4575 my $parents = $co{'parents'}; # listref
4577 # we need to prepare $formats_nav before any parameter munging
4579 if (!defined $parent) {
4581 $formats_nav .= '(initial)';
4582 } elsif (@$parents == 1) {
4583 # single parent commit
4586 $cgi->a({-href
=> href
(action
=>"commit",
4588 esc_html
(substr($parent, 0, 7))) .
4595 $cgi->a({-href
=> href
(action
=>"commit",
4597 esc_html
(substr($_, 0, 7)));
4602 if (!defined $parent) {
4606 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4608 (@$parents <= 1 ? $parent : '-c'),
4610 or die_error
(undef, "Open git-diff-tree failed");
4611 @difftree = map { chomp; $_ } <$fd>;
4612 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4614 # non-textual hash id's can be cached
4616 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4619 my $refs = git_get_references
();
4620 my $ref = format_ref_marker
($refs, $co{'id'});
4622 git_header_html
(undef, $expires);
4623 git_print_page_nav
('commit', '',
4624 $hash, $co{'tree'}, $hash,
4627 if (defined $co{'parent'}) {
4628 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4630 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4632 print "<div class=\"title_text\">\n" .
4633 "<table class=\"object_header\">\n";
4634 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4636 "<td></td><td> $ad{'rfc2822'}";
4637 if ($ad{'hour_local'} < 6) {
4638 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4639 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4641 printf(" (%02d:%02d %s)",
4642 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4646 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4647 print "<tr><td></td><td> $cd{'rfc2822'}" .
4648 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4650 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4653 "<td class=\"sha1\">" .
4654 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4655 class => "list"}, $co{'tree'}) .
4657 "<td class=\"link\">" .
4658 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4660 my $snapshot_links = format_snapshot_links
($hash);
4661 if (defined $snapshot_links) {
4662 print " | " . $snapshot_links;
4667 foreach my $par (@$parents) {
4670 "<td class=\"sha1\">" .
4671 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4672 class => "list"}, $par) .
4674 "<td class=\"link\">" .
4675 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4677 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4684 print "<div class=\"page_body\">\n";
4685 git_print_log
($co{'comment'});
4688 git_difftree_body
(\
@difftree, $hash, @$parents);
4694 # object is defined by:
4695 # - hash or hash_base alone
4696 # - hash_base and file_name
4699 # - hash or hash_base alone
4700 if ($hash || ($hash_base && !defined $file_name)) {
4701 my $object_id = $hash || $hash_base;
4703 my $git_command = git_cmd_str
();
4704 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4705 or die_error
('404 Not Found', "Object does not exist");
4709 or die_error
('404 Not Found', "Object does not exist");
4711 # - hash_base and file_name
4712 } elsif ($hash_base && defined $file_name) {
4713 $file_name =~ s
,/+$,,;
4715 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4716 or die_error
('404 Not Found', "Base object does not exist");
4718 # here errors should not hapen
4719 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4720 or die_error
(undef, "Open git-ls-tree failed");
4724 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4725 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4726 die_error
('404 Not Found', "File or directory for given base does not exist");
4731 die_error
('404 Not Found', "Not enough information to find object");
4734 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4735 hash
=>$hash, hash_base
=>$hash_base,
4736 file_name
=>$file_name),
4737 -status
=> '302 Found');
4741 my $format = shift || 'html';
4748 # preparing $fd and %diffinfo for git_patchset_body
4750 if (defined $hash_base && defined $hash_parent_base) {
4751 if (defined $file_name) {
4753 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4754 $hash_parent_base, $hash_base,
4755 "--", (defined $file_parent ? $file_parent : ()), $file_name
4756 or die_error
(undef, "Open git-diff-tree failed");
4757 @difftree = map { chomp; $_ } <$fd>;
4759 or die_error
(undef, "Reading git-diff-tree failed");
4761 or die_error
('404 Not Found', "Blob diff not found");
4763 } elsif (defined $hash &&
4764 $hash =~ /[0-9a-fA-F]{40}/) {
4765 # try to find filename from $hash
4767 # read filtered raw output
4768 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4769 $hash_parent_base, $hash_base, "--"
4770 or die_error
(undef, "Open git-diff-tree failed");
4772 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4774 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4775 map { chomp; $_ } <$fd>;
4777 or die_error
(undef, "Reading git-diff-tree failed");
4779 or die_error
('404 Not Found', "Blob diff not found");
4782 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4785 if (@difftree > 1) {
4786 die_error
('404 Not Found', "Ambiguous blob diff specification");
4789 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4790 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4791 $file_name ||= $diffinfo{'to_file'};
4793 $hash_parent ||= $diffinfo{'from_id'};
4794 $hash ||= $diffinfo{'to_id'};
4796 # non-textual hash id's can be cached
4797 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4798 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4803 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4804 '-p', ($format eq 'html' ? "--full-index" : ()),
4805 $hash_parent_base, $hash_base,
4806 "--", (defined $file_parent ? $file_parent : ()), $file_name
4807 or die_error
(undef, "Open git-diff-tree failed");
4810 # old/legacy style URI
4811 if (!%diffinfo && # if new style URI failed
4812 defined $hash && defined $hash_parent) {
4813 # fake git-diff-tree raw output
4814 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4815 $diffinfo{'from_id'} = $hash_parent;
4816 $diffinfo{'to_id'} = $hash;
4817 if (defined $file_name) {
4818 if (defined $file_parent) {
4819 $diffinfo{'status'} = '2';
4820 $diffinfo{'from_file'} = $file_parent;
4821 $diffinfo{'to_file'} = $file_name;
4822 } else { # assume not renamed
4823 $diffinfo{'status'} = '1';
4824 $diffinfo{'from_file'} = $file_name;
4825 $diffinfo{'to_file'} = $file_name;
4827 } else { # no filename given
4828 $diffinfo{'status'} = '2';
4829 $diffinfo{'from_file'} = $hash_parent;
4830 $diffinfo{'to_file'} = $hash;
4833 # non-textual hash id's can be cached
4834 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4835 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4840 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4841 '-p', ($format eq 'html' ? "--full-index" : ()),
4842 $hash_parent, $hash, "--"
4843 or die_error
(undef, "Open git-diff failed");
4845 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4850 if ($format eq 'html') {
4852 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4854 git_header_html
(undef, $expires);
4855 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4856 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4857 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4859 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4860 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4862 if (defined $file_name) {
4863 git_print_page_path
($file_name, "blob", $hash_base);
4865 print "<div class=\"page_path\"></div>\n";
4868 } elsif ($format eq 'plain') {
4870 -type
=> 'text/plain',
4871 -charset
=> 'utf-8',
4872 -expires
=> $expires,
4873 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4875 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4878 die_error
(undef, "Unknown blobdiff format");
4882 if ($format eq 'html') {
4883 print "<div class=\"page_body\">\n";
4885 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4888 print "</div>\n"; # class="page_body"
4892 while (my $line = <$fd>) {
4893 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4894 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4898 last if $line =~ m!^\+\+\+!;
4906 sub git_blobdiff_plain
{
4907 git_blobdiff
('plain');
4910 sub git_commitdiff
{
4911 my $format = shift || 'html';
4912 $hash ||= $hash_base || "HEAD";
4913 my %co = parse_commit
($hash);
4915 die_error
(undef, "Unknown commit object");
4918 # choose format for commitdiff for merge
4919 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4920 $hash_parent = '--cc';
4922 # we need to prepare $formats_nav before almost any parameter munging
4924 if ($format eq 'html') {
4926 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4929 if (defined $hash_parent &&
4930 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4931 # commitdiff with two commits given
4932 my $hash_parent_short = $hash_parent;
4933 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4934 $hash_parent_short = substr($hash_parent, 0, 7);
4938 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4939 if ($co{'parents'}[$i] eq $hash_parent) {
4940 $formats_nav .= ' parent ' . ($i+1);
4944 $formats_nav .= ': ' .
4945 $cgi->a({-href
=> href
(action
=>"commitdiff",
4946 hash
=>$hash_parent)},
4947 esc_html
($hash_parent_short)) .
4949 } elsif (!$co{'parent'}) {
4951 $formats_nav .= ' (initial)';
4952 } elsif (scalar @{$co{'parents'}} == 1) {
4953 # single parent commit
4956 $cgi->a({-href
=> href
(action
=>"commitdiff",
4957 hash
=>$co{'parent'})},
4958 esc_html
(substr($co{'parent'}, 0, 7))) .
4962 if ($hash_parent eq '--cc') {
4963 $formats_nav .= ' | ' .
4964 $cgi->a({-href
=> href
(action
=>"commitdiff",
4965 hash
=>$hash, hash_parent
=>'-c')},
4967 } else { # $hash_parent eq '-c'
4968 $formats_nav .= ' | ' .
4969 $cgi->a({-href
=> href
(action
=>"commitdiff",
4970 hash
=>$hash, hash_parent
=>'--cc')},
4976 $cgi->a({-href
=> href
(action
=>"commitdiff",
4978 esc_html
(substr($_, 0, 7)));
4979 } @{$co{'parents'}} ) .
4984 my $hash_parent_param = $hash_parent;
4985 if (!defined $hash_parent_param) {
4986 # --cc for multiple parents, --root for parentless
4987 $hash_parent_param =
4988 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4994 if ($format eq 'html') {
4995 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4996 "--no-commit-id", "--patch-with-raw", "--full-index",
4997 $hash_parent_param, $hash, "--"
4998 or die_error
(undef, "Open git-diff-tree failed");
5000 while (my $line = <$fd>) {
5002 # empty line ends raw part of diff-tree output
5004 push @difftree, scalar parse_difftree_raw_line
($line);
5007 } elsif ($format eq 'plain') {
5008 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5009 '-p', $hash_parent_param, $hash, "--"
5010 or die_error
(undef, "Open git-diff-tree failed");
5013 die_error
(undef, "Unknown commitdiff format");
5016 # non-textual hash id's can be cached
5018 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5022 # write commit message
5023 if ($format eq 'html') {
5024 my $refs = git_get_references
();
5025 my $ref = format_ref_marker
($refs, $co{'id'});
5027 git_header_html
(undef, $expires);
5028 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5029 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5030 git_print_authorship
(\
%co);
5031 print "<div class=\"page_body\">\n";
5032 if (@{$co{'comment'}} > 1) {
5033 print "<div class=\"log\">\n";
5034 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5035 print "</div>\n"; # class="log"
5038 } elsif ($format eq 'plain') {
5039 my $refs = git_get_references
("tags");
5040 my $tagname = git_get_rev_name_tags
($hash);
5041 my $filename = basename
($project) . "-$hash.patch";
5044 -type
=> 'text/plain',
5045 -charset
=> 'utf-8',
5046 -expires
=> $expires,
5047 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5048 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5051 Date: $ad{'rfc2822'} ($ad{'tz_local'})
5052 Subject: $co{'title'}
5054 print "X-Git-Tag: $tagname\n" if $tagname;
5055 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5057 foreach my $line (@{$co{'comment'}}) {
5064 if ($format eq 'html') {
5065 my $use_parents = !defined $hash_parent ||
5066 $hash_parent eq '-c' || $hash_parent eq '--cc';
5067 git_difftree_body
(\
@difftree, $hash,
5068 $use_parents ? @{$co{'parents'}} : $hash_parent);
5071 git_patchset_body
($fd, \
@difftree, $hash,
5072 $use_parents ? @{$co{'parents'}} : $hash_parent);
5074 print "</div>\n"; # class="page_body"
5077 } elsif ($format eq 'plain') {
5081 or print "Reading git-diff-tree failed\n";
5085 sub git_commitdiff_plain
{
5086 git_commitdiff
('plain');
5090 if (!defined $hash_base) {
5091 $hash_base = git_get_head_hash
($project);
5093 if (!defined $page) {
5097 my %co = parse_commit
($hash_base);
5099 die_error
(undef, "Unknown commit object");
5102 my $refs = git_get_references
();
5103 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5105 if (!defined $hash && defined $file_name) {
5106 $hash = git_get_hash_by_path
($hash_base, $file_name);
5108 if (defined $hash) {
5109 $ftype = git_get_type
($hash);
5112 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5114 my $paging_nav = '';
5117 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5118 file_name
=>$file_name)},
5120 $paging_nav .= " ⋅ " .
5121 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5122 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5124 $paging_nav .= "first";
5125 $paging_nav .= " ⋅ prev";
5128 if ($#commitlist >= 100) {
5130 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5131 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5132 $paging_nav .= " ⋅ $next_link";
5134 $paging_nav .= " ⋅ next";
5138 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5139 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5140 git_print_page_path
($file_name, $ftype, $hash_base);
5142 git_history_body
(\
@commitlist, 0, 99,
5143 $refs, $hash_base, $ftype, $next_link);
5149 my ($have_search) = gitweb_check_feature
('search');
5150 if (!$have_search) {
5151 die_error
('403 Permission denied', "Permission denied");
5153 if (!defined $searchtext) {
5154 die_error
(undef, "Text field empty");
5156 if (!defined $hash) {
5157 $hash = git_get_head_hash
($project);
5159 my %co = parse_commit
($hash);
5161 die_error
(undef, "Unknown commit object");
5163 if (!defined $page) {
5167 $searchtype ||= 'commit';
5168 if ($searchtype eq 'pickaxe') {
5169 # pickaxe may take all resources of your box and run for several minutes
5170 # with every query - so decide by yourself how public you make this feature
5171 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5172 if (!$have_pickaxe) {
5173 die_error
('403 Permission denied', "Permission denied");
5176 if ($searchtype eq 'grep') {
5177 my ($have_grep) = gitweb_check_feature
('grep');
5179 die_error
('403 Permission denied', "Permission denied");
5185 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5187 if ($searchtype eq 'commit') {
5188 $greptype = "--grep=";
5189 } elsif ($searchtype eq 'author') {
5190 $greptype = "--author=";
5191 } elsif ($searchtype eq 'committer') {
5192 $greptype = "--committer=";
5194 $greptype .= $search_regexp;
5195 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5197 my $paging_nav = '';
5200 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5201 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5203 $paging_nav .= " ⋅ " .
5204 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5205 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5207 $paging_nav .= "first";
5208 $paging_nav .= " ⋅ prev";
5211 if ($#commitlist >= 100) {
5213 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5214 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5215 $paging_nav .= " ⋅ $next_link";
5217 $paging_nav .= " ⋅ next";
5220 if ($#commitlist >= 100) {
5223 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5224 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5225 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5228 if ($searchtype eq 'pickaxe') {
5229 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5230 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5232 print "<table class=\"pickaxe search\">\n";
5235 my $git_command = git_cmd_str
();
5236 my $searchqtext = $searchtext;
5237 $searchqtext =~ s/'/'\\''/;
5238 open my $fd, "-|", "$git_command rev-list $hash | " .
5239 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5242 while (my $line = <$fd>) {
5243 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5246 $set{'from_id'} = $3;
5248 $set{'id'} = $set{'to_id'};
5249 if ($set{'id'} =~ m/0{40}/) {
5250 $set{'id'} = $set{'from_id'};
5252 if ($set{'id'} =~ m/0{40}/) {
5256 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5259 print "<tr class=\"dark\">\n";
5261 print "<tr class=\"light\">\n";
5264 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5265 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5266 "<td><i>" . $author . "</i></td>\n" .
5268 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5269 -class => "list subject"},
5270 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5271 while (my $setref = shift @files) {
5273 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5274 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5276 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5280 "<td class=\"link\">" .
5281 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5283 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5287 %co = parse_commit
($1);
5295 if ($searchtype eq 'grep') {
5296 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5297 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5299 print "<table class=\"grep_search\">\n";
5303 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5305 while (my $line = <$fd>) {
5307 my ($file, $lno, $ltext, $binary);
5308 last if ($matches++ > 1000);
5309 if ($line =~ /^Binary file (.+) matches$/) {
5313 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5315 if ($file ne $lastfile) {
5316 $lastfile and print "</td></tr>\n";
5318 print "<tr class=\"dark\">\n";
5320 print "<tr class=\"light\">\n";
5322 print "<td class=\"list\">".
5323 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5324 file_name
=>"$file"),
5325 -class => "list"}, esc_path
($file));
5326 print "</td><td>\n";
5330 print "<div class=\"binary\">Binary file</div>\n";
5332 $ltext = untabify
($ltext);
5333 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5334 $ltext = esc_html
($1, -nbsp
=>1);
5335 $ltext .= '<span class="match">';
5336 $ltext .= esc_html
($2, -nbsp
=>1);
5337 $ltext .= '</span>';
5338 $ltext .= esc_html
($3, -nbsp
=>1);
5340 $ltext = esc_html
($ltext, -nbsp
=>1);
5342 print "<div class=\"pre\">" .
5343 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5344 file_name
=>"$file").'#l'.$lno,
5345 -class => "linenr"}, sprintf('%4i', $lno))
5346 . ' ' . $ltext . "</div>\n";
5350 print "</td></tr>\n";
5351 if ($matches > 1000) {
5352 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5355 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5364 sub git_search_help
{
5366 git_print_page_nav
('','', $hash,$hash,$hash);
5369 <dt><b>commit</b></dt>
5370 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5372 my ($have_grep) = gitweb_check_feature
('grep');
5375 <dt><b>grep</b></dt>
5376 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5377 a different one) are searched for the given
5378 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5379 (POSIX extended) and the matches are listed. On large
5380 trees, this search can take a while and put some strain on the server, so please use it with
5381 some consideration.</dd>
5385 <dt><b>author</b></dt>
5386 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5387 <dt><b>committer</b></dt>
5388 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5390 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5391 if ($have_pickaxe) {
5393 <dt><b>pickaxe</b></dt>
5394 <dd>All commits that caused the string to appear or disappear from any file (changes that
5395 added, removed or "modified" the string) will be listed. This search can take a while and
5396 takes a lot of strain on the server, so please use it wisely.</dd>
5404 my $head = git_get_head_hash
($project);
5405 if (!defined $hash) {
5408 if (!defined $page) {
5411 my $refs = git_get_references
();
5413 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5415 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5417 if ($#commitlist >= 100) {
5419 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5420 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5424 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5425 git_print_header_div
('summary', $project);
5427 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5432 ## ......................................................................
5433 ## feeds (RSS, Atom; OPML)
5436 my $format = shift || 'atom';
5437 my ($have_blame) = gitweb_check_feature
('blame');
5439 # Atom: http://www.atomenabled.org/developers/syndication/
5440 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5441 if ($format ne 'rss' && $format ne 'atom') {
5442 die_error
(undef, "Unknown web feed format");
5445 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5446 my $head = $hash || 'HEAD';
5447 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5451 my $content_type = "application/$format+xml";
5452 if (defined $cgi->http('HTTP_ACCEPT') &&
5453 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5454 # browser (feed reader) prefers text/xml
5455 $content_type = 'text/xml';
5457 if (defined($commitlist[0])) {
5458 %latest_commit = %{$commitlist[0]};
5459 %latest_date = parse_date
($latest_commit{'author_epoch'});
5461 -type
=> $content_type,
5462 -charset
=> 'utf-8',
5463 -last_modified
=> $latest_date{'rfc2822'});
5466 -type
=> $content_type,
5467 -charset
=> 'utf-8');
5470 # Optimization: skip generating the body if client asks only
5471 # for Last-Modified date.
5472 return if ($cgi->request_method() eq 'HEAD');
5475 my $title = "$site_name - $project/$action";
5476 my $feed_type = 'log';
5477 if (defined $hash) {
5478 $title .= " - '$hash'";
5479 $feed_type = 'branch log';
5480 if (defined $file_name) {
5481 $title .= " :: $file_name";
5482 $feed_type = 'history';
5484 } elsif (defined $file_name) {
5485 $title .= " - $file_name";
5486 $feed_type = 'history';
5488 $title .= " $feed_type";
5489 my $descr = git_get_project_description
($project);
5490 if (defined $descr) {
5491 $descr = esc_html
($descr);
5493 $descr = "$project " .
5494 ($format eq 'rss' ? 'RSS' : 'Atom') .
5497 my $owner = git_get_project_owner
($project);
5498 $owner = esc_html
($owner);
5502 if (defined $file_name) {
5503 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5504 } elsif (defined $hash) {
5505 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5507 $alt_url = href
(-full
=>1, action
=>"summary");
5509 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5510 if ($format eq 'rss') {
5512 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5515 print "<title>$title</title>\n" .
5516 "<link>$alt_url</link>\n" .
5517 "<description>$descr</description>\n" .
5518 "<language>en</language>\n";
5519 } elsif ($format eq 'atom') {
5521 <feed xmlns="http://www.w3.org/2005/Atom">
5523 print "<title>$title</title>\n" .
5524 "<subtitle>$descr</subtitle>\n" .
5525 '<link rel="alternate" type="text/html" href="' .
5526 $alt_url . '" />' . "\n" .
5527 '<link rel="self" type="' . $content_type . '" href="' .
5528 $cgi->self_url() . '" />' . "\n" .
5529 "<id>" . href
(-full
=>1) . "</id>\n" .
5530 # use project owner for feed author
5531 "<author><name>$owner</name></author>\n";
5532 if (defined $favicon) {
5533 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5535 if (defined $logo_url) {
5536 # not twice as wide as tall: 72 x 27 pixels
5537 print "<logo>" . esc_url
($logo) . "</logo>\n";
5539 if (! %latest_date) {
5540 # dummy date to keep the feed valid until commits trickle in:
5541 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5543 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5548 for (my $i = 0; $i <= $#commitlist; $i++) {
5549 my %co = %{$commitlist[$i]};
5550 my $commit = $co{'id'};
5551 # we read 150, we always show 30 and the ones more recent than 48 hours
5552 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5555 my %cd = parse_date
($co{'author_epoch'});
5557 # get list of changed files
5558 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5559 $co{'parent'} || "--root",
5560 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5562 my @difftree = map { chomp; $_ } <$fd>;
5566 # print element (entry, item)
5567 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5568 if ($format eq 'rss') {
5570 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5571 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5572 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5573 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5574 "<link>$co_url</link>\n" .
5575 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5576 "<content:encoded>" .
5578 } elsif ($format eq 'atom') {
5580 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5581 "<updated>$cd{'iso-8601'}</updated>\n" .
5583 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5584 if ($co{'author_email'}) {
5585 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5587 print "</author>\n" .
5588 # use committer for contributor
5590 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5591 if ($co{'committer_email'}) {
5592 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5594 print "</contributor>\n" .
5595 "<published>$cd{'iso-8601'}</published>\n" .
5596 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5597 "<id>$co_url</id>\n" .
5598 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5599 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5601 my $comment = $co{'comment'};
5603 foreach my $line (@$comment) {
5604 $line = esc_html
($line);
5607 print "</pre><ul>\n";
5608 foreach my $difftree_line (@difftree) {
5609 my %difftree = parse_difftree_raw_line
($difftree_line);
5610 next if !$difftree{'from_id'};
5612 my $file = $difftree{'file'} || $difftree{'to_file'};
5616 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5617 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5618 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5619 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5620 -title
=> "diff"}, 'D');
5622 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5623 file_name
=>$file, hash_base
=>$commit),
5624 -title
=> "blame"}, 'B');
5626 # if this is not a feed of a file history
5627 if (!defined $file_name || $file_name ne $file) {
5628 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5629 file_name
=>$file, hash
=>$commit),
5630 -title
=> "history"}, 'H');
5632 $file = esc_path
($file);
5636 if ($format eq 'rss') {
5637 print "</ul>]]>\n" .
5638 "</content:encoded>\n" .
5640 } elsif ($format eq 'atom') {
5641 print "</ul>\n</div>\n" .
5648 if ($format eq 'rss') {
5649 print "</channel>\n</rss>\n";
5650 } elsif ($format eq 'atom') {
5664 my @list = git_get_projects_list
();
5666 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5668 <?xml version="1.0" encoding="utf-8"?>
5669 <opml version="1.0">
5671 <title>$site_name OPML Export</title>
5674 <outline text="git RSS feeds">
5677 foreach my $pr (@list) {
5679 my $head = git_get_head_hash
($proj{'path'});
5680 if (!defined $head) {
5683 $git_dir = "$projectroot/$proj{'path'}";
5684 my %co = parse_commit
($head);
5689 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5690 my $rss = "$my_url?p=$proj{'path'};a=rss";
5691 my $html = "$my_url?p=$proj{'path'};a=summary";
5692 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";