3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
64 # URI of GIT logo (72x27 size)
65 our $logo = "++GITWEB_LOGO++";
66 # URI of GIT favicon, assumed to be image/png type
67 our $favicon = "++GITWEB_FAVICON++";
69 # URI and label (title) of GIT logo link
70 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
71 #our $logo_label = "git documentation";
72 our $logo_url = "http://git.or.cz/";
73 our $logo_label = "git homepage";
75 # source of projects list
76 our $projects_list = "++GITWEB_LIST++";
78 # the width (in characters) of the projects list "Description" column
79 our $projects_list_description_width = 25;
81 # default order of projects list
82 # valid values are none, project, descr, owner, and age
83 our $default_projects_order = "project";
85 # show repository only if this file exists
86 # (only effective if this variable evaluates to true)
87 our $export_ok = "++GITWEB_EXPORT_OK++";
89 # only allow viewing of repositories also shown on the overview page
90 our $strict_export = "++GITWEB_STRICT_EXPORT++";
92 # list of git base URLs used for URL to where fetch project from,
93 # i.e. full URL is "$git_base_url/$project"
94 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
96 # default blob_plain mimetype and default charset for text/plain blob
97 our $default_blob_plain_mimetype = 'text/plain';
98 our $default_text_plain_charset = undef;
100 # file to use for guessing MIME types before trying /etc/mime.types
101 # (relative to the current git repository)
102 our $mimetypes_file = undef;
104 # assume this charset if line contains non-UTF-8 characters;
105 # it should be valid encoding (see Encoding::Supported(3pm) for list),
106 # for which encoding all byte sequences are valid, for example
107 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
108 # could be even 'utf-8' for the old behavior)
109 our $fallback_encoding = 'latin1';
111 # rename detection options for git-diff and git-diff-tree
112 # - default is '-M', with the cost proportional to
113 # (number of removed files) * (number of new files).
114 # - more costly is '-C' (which implies '-M'), with the cost proportional to
115 # (number of changed files + number of removed files) * (number of new files)
116 # - even more costly is '-C', '--find-copies-harder' with cost
117 # (number of files in the original tree) * (number of new files)
118 # - one might want to include '-B' option, e.g. '-B', '-M'
119 our @diff_opts = ('-M'); # taken from git_commit
121 # information about snapshot formats that gitweb is capable of serving
122 our %known_snapshot_formats = (
124 # 'display' => display name,
125 # 'type' => mime type,
126 # 'suffix' => filename suffix,
127 # 'format' => --format for git-archive,
128 # 'compressor' => [compressor command and arguments]
129 # (array reference, optional)}
132 'display' => 'tar.gz',
133 'type' => 'application/x-gzip',
134 'suffix' => '.tar.gz',
136 'compressor' => ['gzip']},
139 'display' => 'tar.bz2',
140 'type' => 'application/x-bzip2',
141 'suffix' => '.tar.bz2',
143 'compressor' => ['bzip2']},
147 'type' => 'application/x-zip',
152 # Aliases so we understand old gitweb.snapshot values in repository
154 our %known_snapshot_format_aliases = (
158 # backward compatibility: legacy gitweb config support
159 'x-gzip' => undef, 'gz' => undef,
160 'x-bzip2' => undef, 'bz2' => undef,
161 'x-zip' => undef, '' => undef,
164 # You define site-wide feature defaults here; override them with
165 # $GITWEB_CONFIG as necessary.
168 # 'sub' => feature-sub (subroutine),
169 # 'override' => allow-override (boolean),
170 # 'default' => [ default options...] (array reference)}
172 # if feature is overridable (it means that allow-override has true value),
173 # then feature-sub will be called with default options as parameters;
174 # return value of feature-sub indicates if to enable specified feature
176 # if there is no 'sub' key (no feature-sub), then feature cannot be
179 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
181 # Enable the 'blame' blob view, showing the last commit that modified
182 # each line in the file. This can be very CPU-intensive.
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'blame'}{'default'} = [1];
186 # To have project specific config enable override in $GITWEB_CONFIG
187 # $feature{'blame'}{'override'} = 1;
188 # and in project config gitweb.blame = 0|1;
190 'sub' => \
&feature_blame
,
194 # Enable the 'snapshot' link, providing a compressed archive of any
195 # tree. This can potentially generate high traffic if you have large
198 # Value is a list of formats defined in %known_snapshot_formats that
200 # To disable system wide have in $GITWEB_CONFIG
201 # $feature{'snapshot'}{'default'} = [];
202 # To have project specific config enable override in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'override'} = 1;
204 # and in project config, a comma-separated list of formats or "none"
205 # to disable. Example: gitweb.snapshot = tbz2,zip;
207 'sub' => \
&feature_snapshot
,
209 'default' => ['tgz']},
211 # Enable text search, which will list the commits which match author,
212 # committer or commit text to a given string. Enabled by default.
213 # Project specific override is not supported.
218 # Enable grep search, which will list the files in currently selected
219 # tree containing the given string. Enabled by default. This can be
220 # potentially CPU-intensive, of course.
222 # To enable system wide have in $GITWEB_CONFIG
223 # $feature{'grep'}{'default'} = [1];
224 # To have project specific config enable override in $GITWEB_CONFIG
225 # $feature{'grep'}{'override'} = 1;
226 # and in project config gitweb.grep = 0|1;
231 # Enable the pickaxe search, which will list the commits that modified
232 # a given string in a file. This can be practical and quite faster
233 # alternative to 'blame', but still potentially CPU-intensive.
235 # To enable system wide have in $GITWEB_CONFIG
236 # $feature{'pickaxe'}{'default'} = [1];
237 # To have project specific config enable override in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'override'} = 1;
239 # and in project config gitweb.pickaxe = 0|1;
241 'sub' => \
&feature_pickaxe
,
245 # Make gitweb use an alternative format of the URLs which can be
246 # more readable and natural-looking: project name is embedded
247 # directly in the path and the query string contains other
248 # auxiliary information. All gitweb installations recognize
249 # URL in either format; this configures in which formats gitweb
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'pathinfo'}{'default'} = [1];
254 # Project specific override is not supported.
256 # Note that you will need to change the default location of CSS,
257 # favicon, logo and possibly other files to an absolute URL. Also,
258 # if gitweb.cgi serves as your indexfile, you will need to force
259 # $my_uri to contain the script name in your $GITWEB_CONFIG.
264 # Make gitweb consider projects in project root subdirectories
265 # to be forks of existing projects. Given project $projname.git,
266 # projects matching $projname/*.git will not be shown in the main
267 # projects list, instead a '+' mark will be added to $projname
268 # there and a 'forks' view will be enabled for the project, listing
269 # all the forks. If project list is taken from a file, forks have
270 # to be listed after the main project.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'forks'}{'default'} = [1];
274 # Project specific override is not supported.
280 sub gitweb_check_feature
{
282 return unless exists $feature{$name};
283 my ($sub, $override, @defaults) = (
284 $feature{$name}{'sub'},
285 $feature{$name}{'override'},
286 @
{$feature{$name}{'default'}});
287 if (!$override) { return @defaults; }
289 warn "feature $name is not overrideable";
292 return $sub->(@defaults);
296 my ($val) = git_get_project_config
('blame', '--bool');
298 if ($val eq 'true') {
300 } elsif ($val eq 'false') {
307 sub feature_snapshot
{
310 my ($val) = git_get_project_config
('snapshot');
313 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
320 my ($val) = git_get_project_config
('grep', '--bool');
322 if ($val eq 'true') {
324 } elsif ($val eq 'false') {
331 sub feature_pickaxe
{
332 my ($val) = git_get_project_config
('pickaxe', '--bool');
334 if ($val eq 'true') {
336 } elsif ($val eq 'false') {
343 # checking HEAD file with -e is fragile if the repository was
344 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
346 sub check_head_link
{
348 my $headfile = "$dir/HEAD";
349 return ((-e
$headfile) ||
350 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
353 sub check_export_ok
{
355 return (check_head_link
($dir) &&
356 (!$export_ok || -e
"$dir/$export_ok"));
359 # process alternate names for backward compatibility
360 # filter out unsupported (unknown) snapshot formats
361 sub filter_snapshot_fmts
{
365 exists $known_snapshot_format_aliases{$_} ?
366 $known_snapshot_format_aliases{$_} : $_} @fmts;
367 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
371 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
372 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
374 # version of the core git binary
375 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
377 $projects_list ||= $projectroot;
379 # ======================================================================
380 # input validation and dispatch
381 our $action = $cgi->param('a');
382 if (defined $action) {
383 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
384 die_error
(undef, "Invalid action parameter");
388 # parameters which are pathnames
389 our $project = $cgi->param('p');
390 if (defined $project) {
391 if (!validate_pathname
($project) ||
392 !(-d
"$projectroot/$project") ||
393 !check_head_link
("$projectroot/$project") ||
394 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
395 ($strict_export && !project_in_list
($project))) {
397 die_error
(undef, "No such project");
401 our $file_name = $cgi->param('f');
402 if (defined $file_name) {
403 if (!validate_pathname
($file_name)) {
404 die_error
(undef, "Invalid file parameter");
408 our $file_parent = $cgi->param('fp');
409 if (defined $file_parent) {
410 if (!validate_pathname
($file_parent)) {
411 die_error
(undef, "Invalid file parent parameter");
415 # parameters which are refnames
416 our $hash = $cgi->param('h');
418 if (!validate_refname
($hash)) {
419 die_error
(undef, "Invalid hash parameter");
423 our $hash_parent = $cgi->param('hp');
424 if (defined $hash_parent) {
425 if (!validate_refname
($hash_parent)) {
426 die_error
(undef, "Invalid hash parent parameter");
430 our $hash_base = $cgi->param('hb');
431 if (defined $hash_base) {
432 if (!validate_refname
($hash_base)) {
433 die_error
(undef, "Invalid hash base parameter");
437 my %allowed_options = (
438 "--no-merges" => [ qw(rss atom log shortlog history) ],
441 our @extra_options = $cgi->param('opt');
442 if (defined @extra_options) {
443 foreach my $opt (@extra_options) {
444 if (not exists $allowed_options{$opt}) {
445 die_error
(undef, "Invalid option parameter");
447 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
448 die_error
(undef, "Invalid option parameter for this action");
453 our $hash_parent_base = $cgi->param('hpb');
454 if (defined $hash_parent_base) {
455 if (!validate_refname
($hash_parent_base)) {
456 die_error
(undef, "Invalid hash parent base parameter");
461 our $page = $cgi->param('pg');
463 if ($page =~ m/[^0-9]/) {
464 die_error
(undef, "Invalid page parameter");
468 our $searchtype = $cgi->param('st');
469 if (defined $searchtype) {
470 if ($searchtype =~ m/[^a-z]/) {
471 die_error
(undef, "Invalid searchtype parameter");
475 our $searchtext = $cgi->param('s');
477 if (defined $searchtext) {
478 if (length($searchtext) < 2) {
479 die_error
(undef, "At least two characters are required for search parameter");
481 $search_regexp = quotemeta $searchtext;
484 # now read PATH_INFO and use it as alternative to parameters
485 sub evaluate_path_info
{
486 return if defined $project;
487 my $path_info = $ENV{"PATH_INFO"};
488 return if !$path_info;
489 $path_info =~ s
,^/+,,;
490 return if !$path_info;
491 # find which part of PATH_INFO is project
492 $project = $path_info;
494 while ($project && !check_head_link
("$projectroot/$project")) {
495 $project =~ s
,/*[^/]*$,,;
498 $project = validate_pathname
($project);
500 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
501 ($strict_export && !project_in_list
($project))) {
505 # do not change any parameters if an action is given using the query string
507 $path_info =~ s
,^$project/*,,;
508 my ($refname, $pathname) = split(/:/, $path_info, 2);
509 if (defined $pathname) {
510 # we got "project.git/branch:filename" or "project.git/branch:dir/"
511 # we could use git_get_type(branch:pathname), but it needs $git_dir
512 $pathname =~ s
,^/+,,;
513 if (!$pathname || substr($pathname, -1) eq "/") {
517 $action ||= "blob_plain";
519 $hash_base ||= validate_refname
($refname);
520 $file_name ||= validate_pathname
($pathname);
521 } elsif (defined $refname) {
522 # we got "project.git/branch"
523 $action ||= "shortlog";
524 $hash ||= validate_refname
($refname);
527 evaluate_path_info
();
529 # path to the current git repository
531 $git_dir = "$projectroot/$project" if $project;
535 "blame" => \
&git_blame2
,
536 "blobdiff" => \
&git_blobdiff
,
537 "blobdiff_plain" => \
&git_blobdiff_plain
,
538 "blob" => \
&git_blob
,
539 "blob_plain" => \
&git_blob_plain
,
540 "commitdiff" => \
&git_commitdiff
,
541 "commitdiff_plain" => \
&git_commitdiff_plain
,
542 "commit" => \
&git_commit
,
543 "forks" => \
&git_forks
,
544 "heads" => \
&git_heads
,
545 "history" => \
&git_history
,
548 "atom" => \
&git_atom
,
549 "search" => \
&git_search
,
550 "search_help" => \
&git_search_help
,
551 "shortlog" => \
&git_shortlog
,
552 "summary" => \
&git_summary
,
554 "tags" => \
&git_tags
,
555 "tree" => \
&git_tree
,
556 "snapshot" => \
&git_snapshot
,
557 "object" => \
&git_object
,
558 # those below don't need $project
559 "opml" => \
&git_opml
,
560 "project_list" => \
&git_project_list
,
561 "project_index" => \
&git_project_index
,
564 if (!defined $action) {
566 $action = git_get_type
($hash);
567 } elsif (defined $hash_base && defined $file_name) {
568 $action = git_get_type
("$hash_base:$file_name");
569 } elsif (defined $project) {
572 $action = 'project_list';
575 if (!defined($actions{$action})) {
576 die_error
(undef, "Unknown action");
578 if ($action !~ m/^(opml|project_list|project_index)$/ &&
580 die_error
(undef, "Project needed");
582 $actions{$action}->();
585 ## ======================================================================
590 # default is to use -absolute url() i.e. $my_uri
591 my $href = $params{-full
} ?
$my_url : $my_uri;
593 # XXX: Warning: If you touch this, check the search form for updating,
604 hash_parent_base
=> "hpb",
609 snapshot_format
=> "sf",
610 extra_options
=> "opt",
612 my %mapping = @mapping;
614 $params{'project'} = $project unless exists $params{'project'};
616 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
618 # use PATH_INFO for project name
619 $href .= "/$params{'project'}" if defined $params{'project'};
620 delete $params{'project'};
622 # Summary just uses the project path URL
623 if (defined $params{'action'} && $params{'action'} eq 'summary') {
624 delete $params{'action'};
628 # now encode the parameters explicitly
630 for (my $i = 0; $i < @mapping; $i += 2) {
631 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
632 if (defined $params{$name}) {
633 if (ref($params{$name}) eq "ARRAY") {
634 foreach my $par (@
{$params{$name}}) {
635 push @result, $symbol . "=" . esc_param
($par);
638 push @result, $symbol . "=" . esc_param
($params{$name});
642 $href .= "?" . join(';', @result) if scalar @result;
648 ## ======================================================================
649 ## validation, quoting/unquoting and escaping
651 sub validate_pathname
{
652 my $input = shift || return undef;
654 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
655 # at the beginning, at the end, and between slashes.
656 # also this catches doubled slashes
657 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
661 if ($input =~ m!\0!) {
667 sub validate_refname
{
668 my $input = shift || return undef;
670 # textual hashes are O.K.
671 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
674 # it must be correct pathname
675 $input = validate_pathname
($input)
677 # restrictions on ref name according to git-check-ref-format
678 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
684 # decode sequences of octets in utf8 into Perl's internal form,
685 # which is utf-8 with utf8 flag set if needed. gitweb writes out
686 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
690 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
694 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
698 # quote unsafe chars, but keep the slash, even when it's not
699 # correct, but quoted slashes look too horrible in bookmarks
702 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
708 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
711 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
717 # replace invalid utf8 character with SUBSTITUTION sequence
722 $str = to_utf8
($str);
723 $str = $cgi->escapeHTML($str);
724 if ($opts{'-nbsp'}) {
725 $str =~ s/ / /g;
727 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
731 # quote control characters and escape filename to HTML
736 $str = to_utf8
($str);
737 $str = $cgi->escapeHTML($str);
738 if ($opts{'-nbsp'}) {
739 $str =~ s/ / /g;
741 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
745 # Make control characters "printable", using character escape codes (CEC)
748 my %es = ( # character escape codes, aka escape sequences
749 "\t" => '\t', # tab (HT)
750 "\n" => '\n', # line feed (LF)
751 "\r" => '\r', # carrige return (CR)
752 "\f" => '\f', # form feed (FF)
753 "\b" => '\b', # backspace (BS)
754 "\a" => '\a', # alarm (bell) (BEL)
755 "\e" => '\e', # escape (ESC)
756 "\013" => '\v', # vertical tab (VT)
757 "\000" => '\0', # nul character (NUL)
759 my $chr = ( (exists $es{$cntrl})
761 : sprintf('\%03o', ord($cntrl)) );
762 return "<span class=\"cntrl\">$chr</span>";
765 # Alternatively use unicode control pictures codepoints,
766 # Unicode "printable representation" (PR)
769 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
770 return "<span class=\"cntrl\">$chr</span>";
773 # git may return quoted and escaped filenames
779 my %es = ( # character escape codes, aka escape sequences
780 't' => "\t", # tab (HT, TAB)
781 'n' => "\n", # newline (NL)
782 'r' => "\r", # return (CR)
783 'f' => "\f", # form feed (FF)
784 'b' => "\b", # backspace (BS)
785 'a' => "\a", # alarm (bell) (BEL)
786 'e' => "\e", # escape (ESC)
787 'v' => "\013", # vertical tab (VT)
790 if ($seq =~ m/^[0-7]{1,3}$/) {
791 # octal char sequence
792 return chr(oct($seq));
793 } elsif (exists $es{$seq}) {
794 # C escape sequence, aka character escape code
797 # quoted ordinary character
801 if ($str =~ m/^"(.*)"$/) {
804 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
809 # escape tabs (convert tabs to spaces)
813 while ((my $pos = index($line, "\t")) != -1) {
814 if (my $count = (8 - ($pos % 8))) {
815 my $spaces = ' ' x
$count;
816 $line =~ s/\t/$spaces/;
823 sub project_in_list
{
825 my @list = git_get_projects_list
();
826 return @list && scalar(grep { $_->{'path'} eq $project } @list);
829 ## ----------------------------------------------------------------------
830 ## HTML aware string manipulation
835 my $add_len = shift || 10;
837 # allow only $len chars, but don't cut a word if it would fit in $add_len
838 # if it doesn't fit, cut it if it's still longer than the dots we would add
839 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
842 if (length($tail) > 4) {
844 $body =~ s/&[^;]*$//; # remove chopped character entities
849 # takes the same arguments as chop_str, but also wraps a <span> around the
850 # result with a title attribute if it does get chopped. Additionally, the
851 # string is HTML-escaped.
852 sub chop_and_escape_str
{
855 my $add_len = shift || 10;
857 my $chopped = chop_str
($str, $len, $add_len);
858 if ($chopped eq $str) {
859 return esc_html
($chopped);
861 return qq{<span title
="} . esc_html($str) . qq{">} .
862 esc_html
($chopped) . qq{</span
>};
866 ## ----------------------------------------------------------------------
867 ## functions returning short strings
869 # CSS class for given age value (in seconds)
875 } elsif ($age < 60*60*2) {
877 } elsif ($age < 60*60*24*2) {
884 # convert age in seconds to "nn units ago" string
889 if ($age > 60*60*24*365*2) {
890 $age_str = (int $age/60/60/24/365);
891 $age_str .= " years ago";
892 } elsif ($age > 60*60*24*(365/12)*2) {
893 $age_str = int $age/60/60/24/(365/12);
894 $age_str .= " months ago";
895 } elsif ($age > 60*60*24*7*2) {
896 $age_str = int $age/60/60/24/7;
897 $age_str .= " weeks ago";
898 } elsif ($age > 60*60*24*2) {
899 $age_str = int $age/60/60/24;
900 $age_str .= " days ago";
901 } elsif ($age > 60*60*2) {
902 $age_str = int $age/60/60;
903 $age_str .= " hours ago";
904 } elsif ($age > 60*2) {
905 $age_str = int $age/60;
906 $age_str .= " min ago";
909 $age_str .= " sec ago";
911 $age_str .= " right now";
917 S_IFINVALID
=> 0030000,
918 S_IFGITLINK
=> 0160000,
921 # submodule/subproject, a commit object reference
925 return (($mode & S_IFMT
) == S_IFGITLINK
)
928 # convert file mode in octal to symbolic file mode string
930 my $mode = oct shift;
932 if (S_ISGITLINK
($mode)) {
934 } elsif (S_ISDIR
($mode & S_IFMT
)) {
936 } elsif (S_ISLNK
($mode)) {
938 } elsif (S_ISREG
($mode)) {
939 # git cares only about the executable bit
940 if ($mode & S_IXUSR
) {
950 # convert file mode in octal to file type string
954 if ($mode !~ m/^[0-7]+$/) {
960 if (S_ISGITLINK
($mode)) {
962 } elsif (S_ISDIR
($mode & S_IFMT
)) {
964 } elsif (S_ISLNK
($mode)) {
966 } elsif (S_ISREG
($mode)) {
973 # convert file mode in octal to file type description string
977 if ($mode !~ m/^[0-7]+$/) {
983 if (S_ISGITLINK
($mode)) {
985 } elsif (S_ISDIR
($mode & S_IFMT
)) {
987 } elsif (S_ISLNK
($mode)) {
989 } elsif (S_ISREG
($mode)) {
990 if ($mode & S_IXUSR
) {
1001 ## ----------------------------------------------------------------------
1002 ## functions returning short HTML fragments, or transforming HTML fragments
1003 ## which don't belong to other sections
1005 # format line of commit message.
1006 sub format_log_line_html
{
1009 $line = esc_html
($line, -nbsp
=>1);
1010 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1013 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1014 -class => "text"}, $hash_text);
1015 $line =~ s/$hash_text/$link/;
1020 # format marker of refs pointing to given object
1021 sub format_ref_marker
{
1022 my ($refs, $id) = @_;
1025 if (defined $refs->{$id}) {
1026 foreach my $ref (@
{$refs->{$id}}) {
1027 my ($type, $name) = qw();
1028 # e.g. tags/v2.6.11 or heads/next
1029 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1037 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1038 esc_html
($name) . "</span>";
1043 return ' <span class="refs">'. $markers . '</span>';
1049 # format, perhaps shortened and with markers, title line
1050 sub format_subject_html
{
1051 my ($long, $short, $href, $extra) = @_;
1052 $extra = '' unless defined($extra);
1054 if (length($short) < length($long)) {
1055 return $cgi->a({-href
=> $href, -class => "list subject",
1056 -title
=> to_utf8
($long)},
1057 esc_html
($short) . $extra);
1059 return $cgi->a({-href
=> $href, -class => "list subject"},
1060 esc_html
($long) . $extra);
1064 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1065 sub format_git_diff_header_line
{
1067 my $diffinfo = shift;
1068 my ($from, $to) = @_;
1070 if ($diffinfo->{'nparents'}) {
1072 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1073 if ($to->{'href'}) {
1074 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1075 esc_path
($to->{'file'}));
1076 } else { # file was deleted (no href)
1077 $line .= esc_path
($to->{'file'});
1081 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1082 if ($from->{'href'}) {
1083 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1084 'a/' . esc_path
($from->{'file'}));
1085 } else { # file was added (no href)
1086 $line .= 'a/' . esc_path
($from->{'file'});
1089 if ($to->{'href'}) {
1090 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1091 'b/' . esc_path
($to->{'file'}));
1092 } else { # file was deleted
1093 $line .= 'b/' . esc_path
($to->{'file'});
1097 return "<div class=\"diff header\">$line</div>\n";
1100 # format extended diff header line, before patch itself
1101 sub format_extended_diff_header_line
{
1103 my $diffinfo = shift;
1104 my ($from, $to) = @_;
1107 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1108 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1109 esc_path
($from->{'file'}));
1111 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1112 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1113 esc_path
($to->{'file'}));
1115 # match single <mode>
1116 if ($line =~ m/\s(\d{6})$/) {
1117 $line .= '<span class="info"> (' .
1118 file_type_long
($1) .
1122 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1123 # can match only for combined diff
1125 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1126 if ($from->{'href'}[$i]) {
1127 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1129 substr($diffinfo->{'from_id'}[$i],0,7));
1134 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1137 if ($to->{'href'}) {
1138 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1139 substr($diffinfo->{'to_id'},0,7));
1144 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1145 # can match only for ordinary diff
1146 my ($from_link, $to_link);
1147 if ($from->{'href'}) {
1148 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1149 substr($diffinfo->{'from_id'},0,7));
1151 $from_link = '0' x
7;
1153 if ($to->{'href'}) {
1154 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1155 substr($diffinfo->{'to_id'},0,7));
1159 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1160 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1163 return $line . "<br/>\n";
1166 # format from-file/to-file diff header
1167 sub format_diff_from_to_header
{
1168 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1173 #assert($line =~ m/^---/) if DEBUG;
1174 # no extra formatting for "^--- /dev/null"
1175 if (! $diffinfo->{'nparents'}) {
1176 # ordinary (single parent) diff
1177 if ($line =~ m!^--- "?a/!) {
1178 if ($from->{'href'}) {
1180 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1181 esc_path
($from->{'file'}));
1184 esc_path
($from->{'file'});
1187 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1190 # combined diff (merge commit)
1191 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1192 if ($from->{'href'}[$i]) {
1194 $cgi->a({-href
=>href
(action
=>"blobdiff",
1195 hash_parent
=>$diffinfo->{'from_id'}[$i],
1196 hash_parent_base
=>$parents[$i],
1197 file_parent
=>$from->{'file'}[$i],
1198 hash
=>$diffinfo->{'to_id'},
1200 file_name
=>$to->{'file'}),
1202 -title
=>"diff" . ($i+1)},
1205 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1206 esc_path
($from->{'file'}[$i]));
1208 $line = '--- /dev/null';
1210 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1215 #assert($line =~ m/^\+\+\+/) if DEBUG;
1216 # no extra formatting for "^+++ /dev/null"
1217 if ($line =~ m!^\+\+\+ "?b/!) {
1218 if ($to->{'href'}) {
1220 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1221 esc_path
($to->{'file'}));
1224 esc_path
($to->{'file'});
1227 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1232 # create note for patch simplified by combined diff
1233 sub format_diff_cc_simplified
{
1234 my ($diffinfo, @parents) = @_;
1237 $result .= "<div class=\"diff header\">" .
1239 if (!is_deleted
($diffinfo)) {
1240 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1242 hash
=>$diffinfo->{'to_id'},
1243 file_name
=>$diffinfo->{'to_file'}),
1245 esc_path
($diffinfo->{'to_file'}));
1247 $result .= esc_path
($diffinfo->{'to_file'});
1249 $result .= "</div>\n" . # class="diff header"
1250 "<div class=\"diff nodifferences\">" .
1252 "</div>\n"; # class="diff nodifferences"
1257 # format patch (diff) line (not to be used for diff headers)
1258 sub format_diff_line
{
1260 my ($from, $to) = @_;
1261 my $diff_class = "";
1265 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1267 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1268 if ($line =~ m/^\@{3}/) {
1269 $diff_class = " chunk_header";
1270 } elsif ($line =~ m/^\\/) {
1271 $diff_class = " incomplete";
1272 } elsif ($prefix =~ tr/+/+/) {
1273 $diff_class = " add";
1274 } elsif ($prefix =~ tr/-/-/) {
1275 $diff_class = " rem";
1278 # assume ordinary diff
1279 my $char = substr($line, 0, 1);
1281 $diff_class = " add";
1282 } elsif ($char eq '-') {
1283 $diff_class = " rem";
1284 } elsif ($char eq '@') {
1285 $diff_class = " chunk_header";
1286 } elsif ($char eq "\\") {
1287 $diff_class = " incomplete";
1290 $line = untabify
($line);
1291 if ($from && $to && $line =~ m/^\@{2} /) {
1292 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1293 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1295 $from_lines = 0 unless defined $from_lines;
1296 $to_lines = 0 unless defined $to_lines;
1298 if ($from->{'href'}) {
1299 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1300 -class=>"list"}, $from_text);
1302 if ($to->{'href'}) {
1303 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1304 -class=>"list"}, $to_text);
1306 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1307 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1308 return "<div class=\"diff$diff_class\">$line</div>\n";
1309 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1310 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1311 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1313 @from_text = split(' ', $ranges);
1314 for (my $i = 0; $i < @from_text; ++$i) {
1315 ($from_start[$i], $from_nlines[$i]) =
1316 (split(',', substr($from_text[$i], 1)), 0);
1319 $to_text = pop @from_text;
1320 $to_start = pop @from_start;
1321 $to_nlines = pop @from_nlines;
1323 $line = "<span class=\"chunk_info\">$prefix ";
1324 for (my $i = 0; $i < @from_text; ++$i) {
1325 if ($from->{'href'}[$i]) {
1326 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1327 -class=>"list"}, $from_text[$i]);
1329 $line .= $from_text[$i];
1333 if ($to->{'href'}) {
1334 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1335 -class=>"list"}, $to_text);
1339 $line .= " $prefix</span>" .
1340 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1341 return "<div class=\"diff$diff_class\">$line</div>\n";
1343 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1346 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1347 # linked. Pass the hash of the tree/commit to snapshot.
1348 sub format_snapshot_links
{
1350 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1351 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1352 my $num_fmts = @snapshot_fmts;
1353 if ($num_fmts > 1) {
1354 # A parenthesized list of links bearing format names.
1355 # e.g. "snapshot (_tar.gz_ _zip_)"
1356 return "snapshot (" . join(' ', map
1363 }, $known_snapshot_formats{$_}{'display'})
1364 , @snapshot_fmts) . ")";
1365 } elsif ($num_fmts == 1) {
1366 # A single "snapshot" link whose tooltip bears the format name.
1368 my ($fmt) = @snapshot_fmts;
1374 snapshot_format
=>$fmt
1376 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1378 } else { # $num_fmts == 0
1383 ## ----------------------------------------------------------------------
1384 ## git utility subroutines, invoking git commands
1386 # returns path to the core git executable and the --git-dir parameter as list
1388 return $GIT, '--git-dir='.$git_dir;
1391 # returns path to the core git executable and the --git-dir parameter as string
1393 return join(' ', git_cmd
());
1396 # get HEAD ref of given project as hash
1397 sub git_get_head_hash
{
1398 my $project = shift;
1399 my $o_git_dir = $git_dir;
1401 $git_dir = "$projectroot/$project";
1402 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1405 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1409 if (defined $o_git_dir) {
1410 $git_dir = $o_git_dir;
1415 # get type of given object
1419 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1421 close $fd or return;
1426 sub git_get_project_config
{
1427 my ($key, $type) = @_;
1429 return unless ($key);
1430 $key =~ s/^gitweb\.//;
1431 return if ($key =~ m/\W/);
1433 my @x = (git_cmd
(), 'config');
1434 if (defined $type) { push @x, $type; }
1436 push @x, "gitweb.$key";
1442 # get hash of given path at given ref
1443 sub git_get_hash_by_path
{
1445 my $path = shift || return undef;
1450 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1451 or die_error
(undef, "Open git-ls-tree failed");
1453 close $fd or return undef;
1455 if (!defined $line) {
1456 # there is no tree or hash given by $path at $base
1460 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1461 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1462 if (defined $type && $type ne $2) {
1463 # type doesn't match
1469 # get path of entry with given hash at given tree-ish (ref)
1470 # used to get 'from' filename for combined diff (merge commit) for renames
1471 sub git_get_path_by_hash
{
1472 my $base = shift || return;
1473 my $hash = shift || return;
1477 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1479 while (my $line = <$fd>) {
1482 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1483 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1484 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1493 ## ......................................................................
1494 ## git utility functions, directly accessing git repository
1496 sub git_get_project_description
{
1499 open my $fd, "$projectroot/$path/description" or return undef;
1502 if (defined $descr) {
1508 sub git_get_project_url_list
{
1511 open my $fd, "$projectroot/$path/cloneurl" or return;
1512 my @git_project_url_list = map { chomp; $_ } <$fd>;
1515 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1518 sub git_get_projects_list
{
1523 $filter =~ s/\.git$//;
1525 my ($check_forks) = gitweb_check_feature
('forks');
1527 if (-d
$projects_list) {
1528 # search in directory
1529 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1530 # remove the trailing "/"
1532 my $pfxlen = length("$dir");
1533 my $pfxdepth = ($dir =~ tr!/!!);
1536 follow_fast
=> 1, # follow symbolic links
1537 follow_skip
=> 2, # ignore duplicates
1538 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1540 # skip project-list toplevel, if we get it.
1541 return if (m!^[/.]$!);
1542 # only directories can be git repositories
1543 return unless (-d
$_);
1544 # don't traverse too deep (Find is super slow on os x)
1545 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1546 $File::Find
::prune
= 1;
1550 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1551 # we check related file in $projectroot
1552 if ($check_forks and $subdir =~ m
#/.#) {
1553 $File::Find
::prune
= 1;
1554 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1555 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1556 $File::Find
::prune
= 1;
1561 } elsif (-f
$projects_list) {
1562 # read from file(url-encoded):
1563 # 'git%2Fgit.git Linus+Torvalds'
1564 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1565 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1567 open my ($fd), $projects_list or return;
1569 while (my $line = <$fd>) {
1571 my ($path, $owner) = split ' ', $line;
1572 $path = unescape
($path);
1573 $owner = unescape
($owner);
1574 if (!defined $path) {
1577 if ($filter ne '') {
1578 # looking for forks;
1579 my $pfx = substr($path, 0, length($filter));
1580 if ($pfx ne $filter) {
1583 my $sfx = substr($path, length($filter));
1584 if ($sfx !~ /^\/.*\
.git
$/) {
1587 } elsif ($check_forks) {
1589 foreach my $filter (keys %paths) {
1590 # looking for forks;
1591 my $pfx = substr($path, 0, length($filter));
1592 if ($pfx ne $filter) {
1595 my $sfx = substr($path, length($filter));
1596 if ($sfx !~ /^\/.*\
.git
$/) {
1599 # is a fork, don't include it in
1604 if (check_export_ok
("$projectroot/$path")) {
1607 owner
=> to_utf8
($owner),
1610 (my $forks_path = $path) =~ s/\.git$//;
1611 $paths{$forks_path}++;
1619 our $gitweb_project_owner = undef;
1620 sub git_get_project_list_from_file
{
1622 return if (defined $gitweb_project_owner);
1624 $gitweb_project_owner = {};
1625 # read from file (url-encoded):
1626 # 'git%2Fgit.git Linus+Torvalds'
1627 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1628 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1629 if (-f
$projects_list) {
1630 open (my $fd , $projects_list);
1631 while (my $line = <$fd>) {
1633 my ($pr, $ow) = split ' ', $line;
1634 $pr = unescape
($pr);
1635 $ow = unescape
($ow);
1636 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1642 sub git_get_project_owner
{
1643 my $project = shift;
1646 return undef unless $project;
1648 if (!defined $gitweb_project_owner) {
1649 git_get_project_list_from_file
();
1652 if (exists $gitweb_project_owner->{$project}) {
1653 $owner = $gitweb_project_owner->{$project};
1655 if (!defined $owner) {
1656 $owner = get_file_owner
("$projectroot/$project");
1662 sub git_get_last_activity
{
1666 $git_dir = "$projectroot/$path";
1667 open($fd, "-|", git_cmd
(), 'for-each-ref',
1668 '--format=%(committer)',
1669 '--sort=-committerdate',
1671 'refs/heads') or return;
1672 my $most_recent = <$fd>;
1673 close $fd or return;
1674 if (defined $most_recent &&
1675 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1677 my $age = time - $timestamp;
1678 return ($age, age_string
($age));
1680 return (undef, undef);
1683 sub git_get_references
{
1684 my $type = shift || "";
1686 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1687 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1688 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1689 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1692 while (my $line = <$fd>) {
1694 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1695 if (defined $refs{$1}) {
1696 push @
{$refs{$1}}, $2;
1702 close $fd or return;
1706 sub git_get_rev_name_tags
{
1707 my $hash = shift || return undef;
1709 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1711 my $name_rev = <$fd>;
1714 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1717 # catches also '$hash undefined' output
1722 ## ----------------------------------------------------------------------
1723 ## parse to hash functions
1727 my $tz = shift || "-0000";
1730 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1731 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1732 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1733 $date{'hour'} = $hour;
1734 $date{'minute'} = $min;
1735 $date{'mday'} = $mday;
1736 $date{'day'} = $days[$wday];
1737 $date{'month'} = $months[$mon];
1738 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1739 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1740 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1741 $mday, $months[$mon], $hour ,$min;
1742 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1743 1900+$year, $mon, $mday, $hour ,$min, $sec;
1745 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1746 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1747 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1748 $date{'hour_local'} = $hour;
1749 $date{'minute_local'} = $min;
1750 $date{'tz_local'} = $tz;
1751 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1752 1900+$year, $mon+1, $mday,
1753 $hour, $min, $sec, $tz);
1762 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1763 $tag{'id'} = $tag_id;
1764 while (my $line = <$fd>) {
1766 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1767 $tag{'object'} = $1;
1768 } elsif ($line =~ m/^type (.+)$/) {
1770 } elsif ($line =~ m/^tag (.+)$/) {
1772 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1773 $tag{'author'} = $1;
1776 } elsif ($line =~ m/--BEGIN/) {
1777 push @comment, $line;
1779 } elsif ($line eq "") {
1783 push @comment, <$fd>;
1784 $tag{'comment'} = \
@comment;
1785 close $fd or return;
1786 if (!defined $tag{'name'}) {
1792 sub parse_commit_text
{
1793 my ($commit_text, $withparents) = @_;
1794 my @commit_lines = split '\n', $commit_text;
1797 pop @commit_lines; # Remove '\0'
1799 if (! @commit_lines) {
1803 my $header = shift @commit_lines;
1804 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1807 ($co{'id'}, my @parents) = split ' ', $header;
1808 while (my $line = shift @commit_lines) {
1809 last if $line eq "\n";
1810 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1812 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1814 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1816 $co{'author_epoch'} = $2;
1817 $co{'author_tz'} = $3;
1818 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1819 $co{'author_name'} = $1;
1820 $co{'author_email'} = $2;
1822 $co{'author_name'} = $co{'author'};
1824 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1825 $co{'committer'} = $1;
1826 $co{'committer_epoch'} = $2;
1827 $co{'committer_tz'} = $3;
1828 $co{'committer_name'} = $co{'committer'};
1829 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1830 $co{'committer_name'} = $1;
1831 $co{'committer_email'} = $2;
1833 $co{'committer_name'} = $co{'committer'};
1837 if (!defined $co{'tree'}) {
1840 $co{'parents'} = \
@parents;
1841 $co{'parent'} = $parents[0];
1843 foreach my $title (@commit_lines) {
1846 $co{'title'} = chop_str
($title, 80, 5);
1847 # remove leading stuff of merges to make the interesting part visible
1848 if (length($title) > 50) {
1849 $title =~ s/^Automatic //;
1850 $title =~ s/^merge (of|with) /Merge ... /i;
1851 if (length($title) > 50) {
1852 $title =~ s/(http|rsync):\/\///;
1854 if (length($title) > 50) {
1855 $title =~ s/(master|www|rsync)\.//;
1857 if (length($title) > 50) {
1858 $title =~ s/kernel.org:?//;
1860 if (length($title) > 50) {
1861 $title =~ s/\/pub\/scm//;
1864 $co{'title_short'} = chop_str
($title, 50, 5);
1868 if ($co{'title'} eq "") {
1869 $co{'title'} = $co{'title_short'} = '(no commit message)';
1871 # remove added spaces
1872 foreach my $line (@commit_lines) {
1875 $co{'comment'} = \
@commit_lines;
1877 my $age = time - $co{'committer_epoch'};
1879 $co{'age_string'} = age_string
($age);
1880 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1881 if ($age > 60*60*24*7*2) {
1882 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1883 $co{'age_string_age'} = $co{'age_string'};
1885 $co{'age_string_date'} = $co{'age_string'};
1886 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1892 my ($commit_id) = @_;
1897 open my $fd, "-|", git_cmd
(), "rev-list",
1903 or die_error
(undef, "Open git-rev-list failed");
1904 %co = parse_commit_text
(<$fd>, 1);
1911 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1919 open my $fd, "-|", git_cmd
(), "rev-list",
1921 ($arg ?
($arg) : ()),
1922 ("--max-count=" . $maxcount),
1923 ("--skip=" . $skip),
1927 ($filename ?
($filename) : ())
1928 or die_error
(undef, "Open git-rev-list failed");
1929 while (my $line = <$fd>) {
1930 my %co = parse_commit_text
($line);
1935 return wantarray ?
@cos : \
@cos;
1938 # parse ref from ref_file, given by ref_id, with given type
1940 my $ref_file = shift;
1942 my $type = shift || git_get_type
($ref_id);
1945 $ref_item{'type'} = $type;
1946 $ref_item{'id'} = $ref_id;
1947 $ref_item{'epoch'} = 0;
1948 $ref_item{'age'} = "unknown";
1949 if ($type eq "tag") {
1950 my %tag = parse_tag
($ref_id);
1951 $ref_item{'comment'} = $tag{'comment'};
1952 if ($tag{'type'} eq "commit") {
1953 my %co = parse_commit
($tag{'object'});
1954 $ref_item{'epoch'} = $co{'committer_epoch'};
1955 $ref_item{'age'} = $co{'age_string'};
1956 } elsif (defined($tag{'epoch'})) {
1957 my $age = time - $tag{'epoch'};
1958 $ref_item{'epoch'} = $tag{'epoch'};
1959 $ref_item{'age'} = age_string
($age);
1961 $ref_item{'reftype'} = $tag{'type'};
1962 $ref_item{'name'} = $tag{'name'};
1963 $ref_item{'refid'} = $tag{'object'};
1964 } elsif ($type eq "commit"){
1965 my %co = parse_commit
($ref_id);
1966 $ref_item{'reftype'} = "commit";
1967 $ref_item{'name'} = $ref_file;
1968 $ref_item{'title'} = $co{'title'};
1969 $ref_item{'refid'} = $ref_id;
1970 $ref_item{'epoch'} = $co{'committer_epoch'};
1971 $ref_item{'age'} = $co{'age_string'};
1973 $ref_item{'reftype'} = $type;
1974 $ref_item{'name'} = $ref_file;
1975 $ref_item{'refid'} = $ref_id;
1981 # parse line of git-diff-tree "raw" output
1982 sub parse_difftree_raw_line
{
1986 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1987 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1988 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1989 $res{'from_mode'} = $1;
1990 $res{'to_mode'} = $2;
1991 $res{'from_id'} = $3;
1993 $res{'status'} = $res{'status_str'} = $5;
1994 $res{'similarity'} = $6;
1995 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1996 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1998 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2001 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2002 # combined diff (for merge commit)
2003 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2004 $res{'nparents'} = length($1);
2005 $res{'from_mode'} = [ split(' ', $2) ];
2006 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2007 $res{'from_id'} = [ split(' ', $3) ];
2008 $res{'to_id'} = pop @
{$res{'from_id'}};
2009 $res{'status_str'} = $4;
2010 $res{'status'} = [ split('', $4) ];
2011 $res{'to_file'} = unquote
($5);
2013 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2014 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2015 $res{'commit'} = $1;
2018 return wantarray ?
%res : \
%res;
2021 # wrapper: return parsed line of git-diff-tree "raw" output
2022 # (the argument might be raw line, or parsed info)
2023 sub parsed_difftree_line
{
2024 my $line_or_ref = shift;
2026 if (ref($line_or_ref) eq "HASH") {
2027 # pre-parsed (or generated by hand)
2028 return $line_or_ref;
2030 return parse_difftree_raw_line
($line_or_ref);
2034 # parse line of git-ls-tree output
2035 sub parse_ls_tree_line
($;%) {
2040 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2041 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2049 $res{'name'} = unquote
($4);
2052 return wantarray ?
%res : \
%res;
2055 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2056 sub parse_from_to_diffinfo
{
2057 my ($diffinfo, $from, $to, @parents) = @_;
2059 if ($diffinfo->{'nparents'}) {
2061 $from->{'file'} = [];
2062 $from->{'href'} = [];
2063 fill_from_file_info
($diffinfo, @parents)
2064 unless exists $diffinfo->{'from_file'};
2065 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2066 $from->{'file'}[$i] =
2067 defined $diffinfo->{'from_file'}[$i] ?
2068 $diffinfo->{'from_file'}[$i] :
2069 $diffinfo->{'to_file'};
2070 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2071 $from->{'href'}[$i] = href
(action
=>"blob",
2072 hash_base
=>$parents[$i],
2073 hash
=>$diffinfo->{'from_id'}[$i],
2074 file_name
=>$from->{'file'}[$i]);
2076 $from->{'href'}[$i] = undef;
2080 # ordinary (not combined) diff
2081 $from->{'file'} = $diffinfo->{'from_file'};
2082 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2083 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2084 hash
=>$diffinfo->{'from_id'},
2085 file_name
=>$from->{'file'});
2087 delete $from->{'href'};
2091 $to->{'file'} = $diffinfo->{'to_file'};
2092 if (!is_deleted
($diffinfo)) { # file exists in result
2093 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2094 hash
=>$diffinfo->{'to_id'},
2095 file_name
=>$to->{'file'});
2097 delete $to->{'href'};
2101 ## ......................................................................
2102 ## parse to array of hashes functions
2104 sub git_get_heads_list
{
2108 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2109 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2110 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2113 while (my $line = <$fd>) {
2117 my ($refinfo, $committerinfo) = split(/\0/, $line);
2118 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2119 my ($committer, $epoch, $tz) =
2120 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2121 $name =~ s!^refs/heads/!!;
2123 $ref_item{'name'} = $name;
2124 $ref_item{'id'} = $hash;
2125 $ref_item{'title'} = $title || '(no commit message)';
2126 $ref_item{'epoch'} = $epoch;
2128 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2130 $ref_item{'age'} = "unknown";
2133 push @headslist, \
%ref_item;
2137 return wantarray ?
@headslist : \
@headslist;
2140 sub git_get_tags_list
{
2144 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2145 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2146 '--format=%(objectname) %(objecttype) %(refname) '.
2147 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2150 while (my $line = <$fd>) {
2154 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2155 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2156 my ($creator, $epoch, $tz) =
2157 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2158 $name =~ s!^refs/tags/!!;
2160 $ref_item{'type'} = $type;
2161 $ref_item{'id'} = $id;
2162 $ref_item{'name'} = $name;
2163 if ($type eq "tag") {
2164 $ref_item{'subject'} = $title;
2165 $ref_item{'reftype'} = $reftype;
2166 $ref_item{'refid'} = $refid;
2168 $ref_item{'reftype'} = $type;
2169 $ref_item{'refid'} = $id;
2172 if ($type eq "tag" || $type eq "commit") {
2173 $ref_item{'epoch'} = $epoch;
2175 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2177 $ref_item{'age'} = "unknown";
2181 push @tagslist, \
%ref_item;
2185 return wantarray ?
@tagslist : \
@tagslist;
2188 ## ----------------------------------------------------------------------
2189 ## filesystem-related functions
2191 sub get_file_owner
{
2194 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2195 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2196 if (!defined $gcos) {
2200 $owner =~ s/[,;].*$//;
2201 return to_utf8
($owner);
2204 ## ......................................................................
2205 ## mimetype related functions
2207 sub mimetype_guess_file
{
2208 my $filename = shift;
2209 my $mimemap = shift;
2210 -r
$mimemap or return undef;
2213 open(MIME
, $mimemap) or return undef;
2215 next if m/^#/; # skip comments
2216 my ($mime, $exts) = split(/\t+/);
2217 if (defined $exts) {
2218 my @exts = split(/\s+/, $exts);
2219 foreach my $ext (@exts) {
2220 $mimemap{$ext} = $mime;
2226 $filename =~ /\.([^.]*)$/;
2227 return $mimemap{$1};
2230 sub mimetype_guess
{
2231 my $filename = shift;
2233 $filename =~ /\./ or return undef;
2235 if ($mimetypes_file) {
2236 my $file = $mimetypes_file;
2237 if ($file !~ m!^/!) { # if it is relative path
2238 # it is relative to project
2239 $file = "$projectroot/$project/$file";
2241 $mime = mimetype_guess_file
($filename, $file);
2243 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2249 my $filename = shift;
2252 my $mime = mimetype_guess
($filename);
2253 $mime and return $mime;
2257 return $default_blob_plain_mimetype unless $fd;
2260 return 'text/plain' .
2261 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2262 } elsif (! $filename) {
2263 return 'application/octet-stream';
2264 } elsif ($filename =~ m/\.png$/i) {
2266 } elsif ($filename =~ m/\.gif$/i) {
2268 } elsif ($filename =~ m/\.jpe?g$/i) {
2269 return 'image/jpeg';
2271 return 'application/octet-stream';
2275 ## ======================================================================
2276 ## functions printing HTML: header, footer, error page
2278 sub git_header_html
{
2279 my $status = shift || "200 OK";
2280 my $expires = shift;
2282 my $title = "$site_name";
2283 if (defined $project) {
2284 $title .= " - " . to_utf8
($project);
2285 if (defined $action) {
2286 $title .= "/$action";
2287 if (defined $file_name) {
2288 $title .= " - " . esc_path
($file_name);
2289 if ($action eq "tree" && $file_name !~ m
|/$|) {
2296 # require explicit support from the UA if we are to send the page as
2297 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2298 # we have to do this because MSIE sometimes globs '*/*', pretending to
2299 # support xhtml+xml but choking when it gets what it asked for.
2300 if (defined $cgi->http('HTTP_ACCEPT') &&
2301 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2302 $cgi->Accept('application/xhtml+xml') != 0) {
2303 $content_type = 'application/xhtml+xml';
2305 $content_type = 'text/html';
2307 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2308 -status
=> $status, -expires
=> $expires);
2309 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2311 <?xml version="1.0" encoding="utf-8"?>
2312 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2313 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2314 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2315 <!-- git core binaries version $git_version -->
2317 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2318 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2319 <meta name="robots" content="index, nofollow"/>
2320 <title>$title</title>
2322 # print out each stylesheet that exist
2323 if (defined $stylesheet) {
2324 #provides backwards capability for those people who define style sheet in a config file
2325 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2327 foreach my $stylesheet (@stylesheets) {
2328 next unless $stylesheet;
2329 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2332 if (defined $project) {
2333 printf('<link rel="alternate" title="%s log RSS feed" '.
2334 'href="%s" type="application/rss+xml" />'."\n",
2335 esc_param
($project), href
(action
=>"rss"));
2336 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2337 'href="%s" type="application/rss+xml" />'."\n",
2338 esc_param
($project), href
(action
=>"rss",
2339 extra_options
=>"--no-merges"));
2340 printf('<link rel="alternate" title="%s log Atom feed" '.
2341 'href="%s" type="application/atom+xml" />'."\n",
2342 esc_param
($project), href
(action
=>"atom"));
2343 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2344 'href="%s" type="application/atom+xml" />'."\n",
2345 esc_param
($project), href
(action
=>"atom",
2346 extra_options
=>"--no-merges"));
2348 printf('<link rel="alternate" title="%s projects list" '.
2349 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2350 $site_name, href
(project
=>undef, action
=>"project_index"));
2351 printf('<link rel="alternate" title="%s projects feeds" '.
2352 'href="%s" type="text/x-opml"/>'."\n",
2353 $site_name, href
(project
=>undef, action
=>"opml"));
2355 if (defined $favicon) {
2356 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2362 if (-f
$site_header) {
2363 open (my $fd, $site_header);
2368 print "<div class=\"page_header\">\n" .
2369 $cgi->a({-href
=> esc_url
($logo_url),
2370 -title
=> $logo_label},
2371 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2372 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2373 if (defined $project) {
2374 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2375 if (defined $action) {
2382 my ($have_search) = gitweb_check_feature
('search');
2383 if ((defined $project) && ($have_search)) {
2384 if (!defined $searchtext) {
2388 if (defined $hash_base) {
2389 $search_hash = $hash_base;
2390 } elsif (defined $hash) {
2391 $search_hash = $hash;
2393 $search_hash = "HEAD";
2395 my $action = $my_uri;
2396 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2397 if ($use_pathinfo) {
2398 $action .= "/$project";
2400 $cgi->param("p", $project);
2402 $cgi->param("a", "search");
2403 $cgi->param("h", $search_hash);
2404 print $cgi->startform(-method
=> "get", -action
=> $action) .
2405 "<div class=\"search\">\n" .
2406 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2407 $cgi->hidden(-name
=> "a") . "\n" .
2408 $cgi->hidden(-name
=> "h") . "\n" .
2409 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2410 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2411 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2413 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2415 $cgi->end_form() . "\n";
2419 sub git_footer_html
{
2420 print "<div class=\"page_footer\">\n";
2421 if (defined $project) {
2422 my $descr = git_get_project_description
($project);
2423 if (defined $descr) {
2424 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2426 print $cgi->a({-href
=> href
(action
=>"rss"),
2427 -class => "rss_logo"}, "RSS") . " ";
2428 print $cgi->a({-href
=> href
(action
=>"atom"),
2429 -class => "rss_logo"}, "Atom") . "\n";
2431 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2432 -class => "rss_logo"}, "OPML") . " ";
2433 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2434 -class => "rss_logo"}, "TXT") . "\n";
2438 if (-f
$site_footer) {
2439 open (my $fd, $site_footer);
2449 my $status = shift || "403 Forbidden";
2450 my $error = shift || "Malformed query, file missing or permission denied";
2452 git_header_html
($status);
2454 <div class="page_body">
2464 ## ----------------------------------------------------------------------
2465 ## functions printing or outputting HTML: navigation
2467 sub git_print_page_nav
{
2468 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2469 $extra = '' if !defined $extra; # pager or formats
2471 my @navs = qw(summary shortlog log commit commitdiff tree);
2473 @navs = grep { $_ ne $suppress } @navs;
2476 my %arg = map { $_ => {action
=>$_} } @navs;
2477 if (defined $head) {
2478 for (qw(commit commitdiff)) {
2479 $arg{$_}{'hash'} = $head;
2481 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2482 for (qw(shortlog log)) {
2483 $arg{$_}{'hash'} = $head;
2487 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2488 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2490 print "<div class=\"page_nav\">\n" .
2492 map { $_ eq $current ?
2493 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2495 print "<br/>\n$extra<br/>\n" .
2499 sub format_paging_nav
{
2500 my ($action, $hash, $head, $page, $nrevs) = @_;
2504 if ($hash ne $head || $page) {
2505 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2507 $paging_nav .= "HEAD";
2511 $paging_nav .= " ⋅ " .
2512 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2513 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2515 $paging_nav .= " ⋅ prev";
2518 if ($nrevs >= (100 * ($page+1)-1)) {
2519 $paging_nav .= " ⋅ " .
2520 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2521 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2523 $paging_nav .= " ⋅ next";
2529 ## ......................................................................
2530 ## functions printing or outputting HTML: div
2532 sub git_print_header_div
{
2533 my ($action, $title, $hash, $hash_base) = @_;
2536 $args{'action'} = $action;
2537 $args{'hash'} = $hash if $hash;
2538 $args{'hash_base'} = $hash_base if $hash_base;
2540 print "<div class=\"header\">\n" .
2541 $cgi->a({-href
=> href
(%args), -class => "title"},
2542 $title ?
$title : $action) .
2546 #sub git_print_authorship (\%) {
2547 sub git_print_authorship
{
2550 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2551 print "<div class=\"author_date\">" .
2552 esc_html
($co->{'author_name'}) .
2554 if ($ad{'hour_local'} < 6) {
2555 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2556 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2558 printf(" (%02d:%02d %s)",
2559 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2564 sub git_print_page_path
{
2570 print "<div class=\"page_path\">";
2571 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2572 -title
=> 'tree root'}, to_utf8
("[$project]"));
2574 if (defined $name) {
2575 my @dirname = split '/', $name;
2576 my $basename = pop @dirname;
2579 foreach my $dir (@dirname) {
2580 $fullname .= ($fullname ?
'/' : '') . $dir;
2581 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2583 -title
=> $fullname}, esc_path
($dir));
2586 if (defined $type && $type eq 'blob') {
2587 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2589 -title
=> $name}, esc_path
($basename));
2590 } elsif (defined $type && $type eq 'tree') {
2591 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2593 -title
=> $name}, esc_path
($basename));
2596 print esc_path
($basename);
2599 print "<br/></div>\n";
2602 # sub git_print_log (\@;%) {
2603 sub git_print_log
($;%) {
2607 if ($opts{'-remove_title'}) {
2608 # remove title, i.e. first line of log
2611 # remove leading empty lines
2612 while (defined $log->[0] && $log->[0] eq "") {
2619 foreach my $line (@
$log) {
2620 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2623 if (! $opts{'-remove_signoff'}) {
2624 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2627 # remove signoff lines
2634 # print only one empty line
2635 # do not print empty line after signoff
2637 next if ($empty || $signoff);
2643 print format_log_line_html
($line) . "<br/>\n";
2646 if ($opts{'-final_empty_line'}) {
2647 # end with single empty line
2648 print "<br/>\n" unless $empty;
2652 # return link target (what link points to)
2653 sub git_get_link_target
{
2658 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2662 $link_target = <$fd>;
2667 return $link_target;
2670 # given link target, and the directory (basedir) the link is in,
2671 # return target of link relative to top directory (top tree);
2672 # return undef if it is not possible (including absolute links).
2673 sub normalize_link_target
{
2674 my ($link_target, $basedir, $hash_base) = @_;
2676 # we can normalize symlink target only if $hash_base is provided
2677 return unless $hash_base;
2679 # absolute symlinks (beginning with '/') cannot be normalized
2680 return if (substr($link_target, 0, 1) eq '/');
2682 # normalize link target to path from top (root) tree (dir)
2685 $path = $basedir . '/' . $link_target;
2687 # we are in top (root) tree (dir)
2688 $path = $link_target;
2691 # remove //, /./, and /../
2693 foreach my $part (split('/', $path)) {
2694 # discard '.' and ''
2695 next if (!$part || $part eq '.');
2697 if ($part eq '..') {
2701 # link leads outside repository (outside top dir)
2705 push @path_parts, $part;
2708 $path = join('/', @path_parts);
2713 # print tree entry (row of git_tree), but without encompassing <tr> element
2714 sub git_print_tree_entry
{
2715 my ($t, $basedir, $hash_base, $have_blame) = @_;
2718 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2720 # The format of a table row is: mode list link. Where mode is
2721 # the mode of the entry, list is the name of the entry, an href,
2722 # and link is the action links of the entry.
2724 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2725 if ($t->{'type'} eq "blob") {
2726 print "<td class=\"list\">" .
2727 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2728 file_name
=>"$basedir$t->{'name'}", %base_key),
2729 -class => "list"}, esc_path
($t->{'name'}));
2730 if (S_ISLNK
(oct $t->{'mode'})) {
2731 my $link_target = git_get_link_target
($t->{'hash'});
2733 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2734 if (defined $norm_target) {
2736 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2737 file_name
=>$norm_target),
2738 -title
=> $norm_target}, esc_path
($link_target));
2740 print " -> " . esc_path
($link_target);
2745 print "<td class=\"link\">";
2746 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2747 file_name
=>"$basedir$t->{'name'}", %base_key)},
2751 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2752 file_name
=>"$basedir$t->{'name'}", %base_key)},
2755 if (defined $hash_base) {
2757 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2758 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2762 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2763 file_name
=>"$basedir$t->{'name'}")},
2767 } elsif ($t->{'type'} eq "tree") {
2768 print "<td class=\"list\">";
2769 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2770 file_name
=>"$basedir$t->{'name'}", %base_key)},
2771 esc_path
($t->{'name'}));
2773 print "<td class=\"link\">";
2774 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2775 file_name
=>"$basedir$t->{'name'}", %base_key)},
2777 if (defined $hash_base) {
2779 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2780 file_name
=>"$basedir$t->{'name'}")},
2785 # unknown object: we can only present history for it
2786 # (this includes 'commit' object, i.e. submodule support)
2787 print "<td class=\"list\">" .
2788 esc_path
($t->{'name'}) .
2790 print "<td class=\"link\">";
2791 if (defined $hash_base) {
2792 print $cgi->a({-href
=> href
(action
=>"history",
2793 hash_base
=>$hash_base,
2794 file_name
=>"$basedir$t->{'name'}")},
2801 ## ......................................................................
2802 ## functions printing large fragments of HTML
2804 # get pre-image filenames for merge (combined) diff
2805 sub fill_from_file_info
{
2806 my ($diff, @parents) = @_;
2808 $diff->{'from_file'} = [ ];
2809 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2810 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2811 if ($diff->{'status'}[$i] eq 'R' ||
2812 $diff->{'status'}[$i] eq 'C') {
2813 $diff->{'from_file'}[$i] =
2814 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2821 # is current raw difftree line of file deletion
2823 my $diffinfo = shift;
2825 return $diffinfo->{'status_str'} =~ /D/;
2828 # does patch correspond to [previous] difftree raw line
2829 # $diffinfo - hashref of parsed raw diff format
2830 # $patchinfo - hashref of parsed patch diff format
2831 # (the same keys as in $diffinfo)
2832 sub is_patch_split
{
2833 my ($diffinfo, $patchinfo) = @_;
2835 return defined $diffinfo && defined $patchinfo
2836 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2840 sub git_difftree_body
{
2841 my ($difftree, $hash, @parents) = @_;
2842 my ($parent) = $parents[0];
2843 my ($have_blame) = gitweb_check_feature
('blame');
2844 print "<div class=\"list_head\">\n";
2845 if ($#{$difftree} > 10) {
2846 print(($#{$difftree} + 1) . " files changed:\n");
2850 print "<table class=\"" .
2851 (@parents > 1 ?
"combined " : "") .
2854 # header only for combined diff in 'commitdiff' view
2855 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
2858 print "<thead><tr>\n" .
2859 "<th></th><th></th>\n"; # filename, patchN link
2860 for (my $i = 0; $i < @parents; $i++) {
2861 my $par = $parents[$i];
2863 $cgi->a({-href
=> href
(action
=>"commitdiff",
2864 hash
=>$hash, hash_parent
=>$par),
2865 -title
=> 'commitdiff to parent number ' .
2866 ($i+1) . ': ' . substr($par,0,7)},
2870 print "</tr></thead>\n<tbody>\n";
2875 foreach my $line (@
{$difftree}) {
2876 my $diff = parsed_difftree_line
($line);
2879 print "<tr class=\"dark\">\n";
2881 print "<tr class=\"light\">\n";
2885 if (exists $diff->{'nparents'}) { # combined diff
2887 fill_from_file_info
($diff, @parents)
2888 unless exists $diff->{'from_file'};
2890 if (!is_deleted
($diff)) {
2891 # file exists in the result (child) commit
2893 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2894 file_name
=>$diff->{'to_file'},
2896 -class => "list"}, esc_path
($diff->{'to_file'})) .
2900 esc_path
($diff->{'to_file'}) .
2904 if ($action eq 'commitdiff') {
2907 print "<td class=\"link\">" .
2908 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2913 my $has_history = 0;
2914 my $not_deleted = 0;
2915 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2916 my $hash_parent = $parents[$i];
2917 my $from_hash = $diff->{'from_id'}[$i];
2918 my $from_path = $diff->{'from_file'}[$i];
2919 my $status = $diff->{'status'}[$i];
2921 $has_history ||= ($status ne 'A');
2922 $not_deleted ||= ($status ne 'D');
2924 if ($status eq 'A') {
2925 print "<td class=\"link\" align=\"right\"> | </td>\n";
2926 } elsif ($status eq 'D') {
2927 print "<td class=\"link\">" .
2928 $cgi->a({-href
=> href
(action
=>"blob",
2931 file_name
=>$from_path)},
2935 if ($diff->{'to_id'} eq $from_hash) {
2936 print "<td class=\"link nochange\">";
2938 print "<td class=\"link\">";
2940 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2941 hash
=>$diff->{'to_id'},
2942 hash_parent
=>$from_hash,
2944 hash_parent_base
=>$hash_parent,
2945 file_name
=>$diff->{'to_file'},
2946 file_parent
=>$from_path)},
2952 print "<td class=\"link\">";
2954 print $cgi->a({-href
=> href
(action
=>"blob",
2955 hash
=>$diff->{'to_id'},
2956 file_name
=>$diff->{'to_file'},
2959 print " | " if ($has_history);
2962 print $cgi->a({-href
=> href
(action
=>"history",
2963 file_name
=>$diff->{'to_file'},
2970 next; # instead of 'else' clause, to avoid extra indent
2972 # else ordinary diff
2974 my ($to_mode_oct, $to_mode_str, $to_file_type);
2975 my ($from_mode_oct, $from_mode_str, $from_file_type);
2976 if ($diff->{'to_mode'} ne ('0' x
6)) {
2977 $to_mode_oct = oct $diff->{'to_mode'};
2978 if (S_ISREG
($to_mode_oct)) { # only for regular file
2979 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2981 $to_file_type = file_type
($diff->{'to_mode'});
2983 if ($diff->{'from_mode'} ne ('0' x
6)) {
2984 $from_mode_oct = oct $diff->{'from_mode'};
2985 if (S_ISREG
($to_mode_oct)) { # only for regular file
2986 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2988 $from_file_type = file_type
($diff->{'from_mode'});
2991 if ($diff->{'status'} eq "A") { # created
2992 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2993 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2994 $mode_chng .= "]</span>";
2996 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2997 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2998 -class => "list"}, esc_path
($diff->{'file'}));
3000 print "<td>$mode_chng</td>\n";
3001 print "<td class=\"link\">";
3002 if ($action eq 'commitdiff') {
3005 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3008 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3009 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3013 } elsif ($diff->{'status'} eq "D") { # deleted
3014 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3016 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3017 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3018 -class => "list"}, esc_path
($diff->{'file'}));
3020 print "<td>$mode_chng</td>\n";
3021 print "<td class=\"link\">";
3022 if ($action eq 'commitdiff') {
3025 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3028 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3029 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3032 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3033 file_name
=>$diff->{'file'})},
3036 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3037 file_name
=>$diff->{'file'})},
3041 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3042 my $mode_chnge = "";
3043 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3044 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3045 if ($from_file_type ne $to_file_type) {
3046 $mode_chnge .= " from $from_file_type to $to_file_type";
3048 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3049 if ($from_mode_str && $to_mode_str) {
3050 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3051 } elsif ($to_mode_str) {
3052 $mode_chnge .= " mode: $to_mode_str";
3055 $mode_chnge .= "]</span>\n";
3058 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3059 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3060 -class => "list"}, esc_path
($diff->{'file'}));
3062 print "<td>$mode_chnge</td>\n";
3063 print "<td class=\"link\">";
3064 if ($action eq 'commitdiff') {
3067 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3069 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3070 # "commit" view and modified file (not onlu mode changed)
3071 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3072 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3073 hash_base
=>$hash, hash_parent_base
=>$parent,
3074 file_name
=>$diff->{'file'})},
3078 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3079 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3082 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3083 file_name
=>$diff->{'file'})},
3086 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3087 file_name
=>$diff->{'file'})},
3091 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3092 my %status_name = ('R' => 'moved', 'C' => 'copied');
3093 my $nstatus = $status_name{$diff->{'status'}};
3095 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3096 # mode also for directories, so we cannot use $to_mode_str
3097 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3100 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3101 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3102 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3103 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3104 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3105 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3106 -class => "list"}, esc_path
($diff->{'from_file'})) .
3107 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3108 "<td class=\"link\">";
3109 if ($action eq 'commitdiff') {
3112 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3114 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3115 # "commit" view and modified file (not only pure rename or copy)
3116 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3117 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3118 hash_base
=>$hash, hash_parent_base
=>$parent,
3119 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3123 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3124 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3127 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3128 file_name
=>$diff->{'to_file'})},
3131 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3132 file_name
=>$diff->{'to_file'})},
3136 } # we should not encounter Unmerged (U) or Unknown (X) status
3139 print "</tbody>" if $has_header;
3143 sub git_patchset_body
{
3144 my ($fd, $difftree, $hash, @hash_parents) = @_;
3145 my ($hash_parent) = $hash_parents[0];
3147 my $is_combined = (@hash_parents > 1);
3149 my $patch_number = 0;
3155 print "<div class=\"patchset\">\n";
3157 # skip to first patch
3158 while ($patch_line = <$fd>) {
3161 last if ($patch_line =~ m/^diff /);
3165 while ($patch_line) {
3167 # parse "git diff" header line
3168 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3169 # $1 is from_name, which we do not use
3170 $to_name = unquote
($2);
3171 $to_name =~ s!^b/!!;
3172 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3173 # $1 is 'cc' or 'combined', which we do not use
3174 $to_name = unquote
($2);
3179 # check if current patch belong to current raw line
3180 # and parse raw git-diff line if needed
3181 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3182 # this is continuation of a split patch
3183 print "<div class=\"patch cont\">\n";
3185 # advance raw git-diff output if needed
3186 $patch_idx++ if defined $diffinfo;
3188 # read and prepare patch information
3189 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3191 # compact combined diff output can have some patches skipped
3192 # find which patch (using pathname of result) we are at now;
3194 while ($to_name ne $diffinfo->{'to_file'}) {
3195 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3196 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3197 "</div>\n"; # class="patch"
3202 last if $patch_idx > $#$difftree;
3203 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3207 # modifies %from, %to hashes
3208 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3210 # this is first patch for raw difftree line with $patch_idx index
3211 # we index @$difftree array from 0, but number patches from 1
3212 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3216 #assert($patch_line =~ m/^diff /) if DEBUG;
3217 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3219 # print "git diff" header
3220 print format_git_diff_header_line
($patch_line, $diffinfo,
3223 # print extended diff header
3224 print "<div class=\"diff extended_header\">\n";
3226 while ($patch_line = <$fd>) {
3229 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3231 print format_extended_diff_header_line
($patch_line, $diffinfo,
3234 print "</div>\n"; # class="diff extended_header"
3236 # from-file/to-file diff header
3237 if (! $patch_line) {
3238 print "</div>\n"; # class="patch"
3241 next PATCH
if ($patch_line =~ m/^diff /);
3242 #assert($patch_line =~ m/^---/) if DEBUG;
3244 my $last_patch_line = $patch_line;
3245 $patch_line = <$fd>;
3247 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3249 print format_diff_from_to_header
($last_patch_line, $patch_line,
3250 $diffinfo, \
%from, \
%to,
3255 while ($patch_line = <$fd>) {
3258 next PATCH
if ($patch_line =~ m/^diff /);
3260 print format_diff_line
($patch_line, \
%from, \
%to);
3264 print "</div>\n"; # class="patch"
3267 # for compact combined (--cc) format, with chunk and patch simpliciaction
3268 # patchset might be empty, but there might be unprocessed raw lines
3269 for (++$patch_idx if $patch_number > 0;
3270 $patch_idx < @
$difftree;
3272 # read and prepare patch information
3273 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3275 # generate anchor for "patch" links in difftree / whatchanged part
3276 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3277 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3278 "</div>\n"; # class="patch"
3283 if ($patch_number == 0) {
3284 if (@hash_parents > 1) {
3285 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3287 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3291 print "</div>\n"; # class="patchset"
3294 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3296 sub git_project_list_body
{
3297 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3299 my ($check_forks) = gitweb_check_feature
('forks');
3302 foreach my $pr (@
$projlist) {
3303 my (@aa) = git_get_last_activity
($pr->{'path'});
3307 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3308 if (!defined $pr->{'descr'}) {
3309 my $descr = git_get_project_description
($pr->{'path'}) || "";
3310 $pr->{'descr_long'} = to_utf8
($descr);
3311 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3313 if (!defined $pr->{'owner'}) {
3314 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3317 my $pname = $pr->{'path'};
3318 if (($pname =~ s/\.git$//) &&
3319 ($pname !~ /\/$/) &&
3320 (-d
"$projectroot/$pname")) {
3321 $pr->{'forks'} = "-d $projectroot/$pname";
3327 push @projects, $pr;
3330 $order ||= $default_projects_order;
3331 $from = 0 unless defined $from;
3332 $to = $#projects if (!defined $to || $#projects < $to);
3334 print "<table class=\"project_list\">\n";
3335 unless ($no_header) {
3338 print "<th></th>\n";
3340 if ($order eq "project") {
3341 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3342 print "<th>Project</th>\n";
3345 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3346 -class => "header"}, "Project") .
3349 if ($order eq "descr") {
3350 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3351 print "<th>Description</th>\n";
3354 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3355 -class => "header"}, "Description") .
3358 if ($order eq "owner") {
3359 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3360 print "<th>Owner</th>\n";
3363 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3364 -class => "header"}, "Owner") .
3367 if ($order eq "age") {
3368 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3369 print "<th>Last Change</th>\n";
3372 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3373 -class => "header"}, "Last Change") .
3376 print "<th></th>\n" .
3380 for (my $i = $from; $i <= $to; $i++) {
3381 my $pr = $projects[$i];
3383 print "<tr class=\"dark\">\n";
3385 print "<tr class=\"light\">\n";
3390 if ($pr->{'forks'}) {
3391 print "<!-- $pr->{'forks'} -->\n";
3392 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3396 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3397 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3398 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3399 -class => "list", -title
=> $pr->{'descr_long'}},
3400 esc_html
($pr->{'descr'})) . "</td>\n" .
3401 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3402 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3403 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3404 "<td class=\"link\">" .
3405 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3406 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3407 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3408 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3409 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3413 if (defined $extra) {
3416 print "<td></td>\n";
3418 print "<td colspan=\"5\">$extra</td>\n" .
3424 sub git_shortlog_body
{
3425 # uses global variable $project
3426 my ($commitlist, $from, $to, $refs, $extra) = @_;
3428 $from = 0 unless defined $from;
3429 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3431 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3433 for (my $i = $from; $i <= $to; $i++) {
3434 my %co = %{$commitlist->[$i]};
3435 my $commit = $co{'id'};
3436 my $ref = format_ref_marker
($refs, $commit);
3438 print "<tr class=\"dark\">\n";
3440 print "<tr class=\"light\">\n";
3443 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3444 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3445 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3446 "<td><i>" . $author . "</i></td>\n" .
3448 print format_subject_html
($co{'title'}, $co{'title_short'},
3449 href
(action
=>"commit", hash
=>$commit), $ref);
3451 "<td class=\"link\">" .
3452 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3453 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3454 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3455 my $snapshot_links = format_snapshot_links
($commit);
3456 if (defined $snapshot_links) {
3457 print " | " . $snapshot_links;
3462 if (defined $extra) {
3464 "<td colspan=\"4\">$extra</td>\n" .
3470 sub git_history_body
{
3471 # Warning: assumes constant type (blob or tree) during history
3472 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3474 $from = 0 unless defined $from;
3475 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3477 print "<table class=\"history\" cellspacing=\"0\">\n";
3479 for (my $i = $from; $i <= $to; $i++) {
3480 my %co = %{$commitlist->[$i]};
3484 my $commit = $co{'id'};
3486 my $ref = format_ref_marker
($refs, $commit);
3489 print "<tr class=\"dark\">\n";
3491 print "<tr class=\"light\">\n";
3494 # shortlog uses chop_str($co{'author_name'}, 10)
3495 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3496 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3497 "<td><i>" . $author . "</i></td>\n" .
3499 # originally git_history used chop_str($co{'title'}, 50)
3500 print format_subject_html
($co{'title'}, $co{'title_short'},
3501 href
(action
=>"commit", hash
=>$commit), $ref);
3503 "<td class=\"link\">" .
3504 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3505 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3507 if ($ftype eq 'blob') {
3508 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3509 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3510 if (defined $blob_current && defined $blob_parent &&
3511 $blob_current ne $blob_parent) {
3513 $cgi->a({-href
=> href
(action
=>"blobdiff",
3514 hash
=>$blob_current, hash_parent
=>$blob_parent,
3515 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3516 file_name
=>$file_name)},
3523 if (defined $extra) {
3525 "<td colspan=\"4\">$extra</td>\n" .
3532 # uses global variable $project
3533 my ($taglist, $from, $to, $extra) = @_;
3534 $from = 0 unless defined $from;
3535 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3537 print "<table class=\"tags\" cellspacing=\"0\">\n";
3539 for (my $i = $from; $i <= $to; $i++) {
3540 my $entry = $taglist->[$i];
3542 my $comment = $tag{'subject'};
3544 if (defined $comment) {
3545 $comment_short = chop_str
($comment, 30, 5);
3548 print "<tr class=\"dark\">\n";
3550 print "<tr class=\"light\">\n";
3553 if (defined $tag{'age'}) {
3554 print "<td><i>$tag{'age'}</i></td>\n";
3556 print "<td></td>\n";
3559 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3560 -class => "list name"}, esc_html
($tag{'name'})) .
3563 if (defined $comment) {
3564 print format_subject_html
($comment, $comment_short,
3565 href
(action
=>"tag", hash
=>$tag{'id'}));
3568 "<td class=\"selflink\">";
3569 if ($tag{'type'} eq "tag") {
3570 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3575 "<td class=\"link\">" . " | " .
3576 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3577 if ($tag{'reftype'} eq "commit") {
3578 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3579 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3580 } elsif ($tag{'reftype'} eq "blob") {
3581 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3586 if (defined $extra) {
3588 "<td colspan=\"5\">$extra</td>\n" .
3594 sub git_heads_body
{
3595 # uses global variable $project
3596 my ($headlist, $head, $from, $to, $extra) = @_;
3597 $from = 0 unless defined $from;
3598 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3600 print "<table class=\"heads\" cellspacing=\"0\">\n";
3602 for (my $i = $from; $i <= $to; $i++) {
3603 my $entry = $headlist->[$i];
3605 my $curr = $ref{'id'} eq $head;
3607 print "<tr class=\"dark\">\n";
3609 print "<tr class=\"light\">\n";
3612 print "<td><i>$ref{'age'}</i></td>\n" .
3613 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3614 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3615 -class => "list name"},esc_html
($ref{'name'})) .
3617 "<td class=\"link\">" .
3618 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3619 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3620 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3624 if (defined $extra) {
3626 "<td colspan=\"3\">$extra</td>\n" .
3632 sub git_search_grep_body
{
3633 my ($commitlist, $from, $to, $extra) = @_;
3634 $from = 0 unless defined $from;
3635 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3637 print "<table class=\"grep\" cellspacing=\"0\">\n";
3639 for (my $i = $from; $i <= $to; $i++) {
3640 my %co = %{$commitlist->[$i]};
3644 my $commit = $co{'id'};
3646 print "<tr class=\"dark\">\n";
3648 print "<tr class=\"light\">\n";
3651 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3652 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3653 "<td><i>" . $author . "</i></td>\n" .
3655 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3656 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3657 my $comment = $co{'comment'};
3658 foreach my $line (@
$comment) {
3659 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3660 my $lead = esc_html
($1) || "";
3661 $lead = chop_str
($lead, 30, 10);
3662 my $match = esc_html
($2) || "";
3663 my $trail = esc_html
($3) || "";
3664 $trail = chop_str
($trail, 30, 10);
3665 my $text = "$lead<span class=\"match\">$match</span>$trail";
3666 print chop_str
($text, 80, 5) . "<br/>\n";
3670 "<td class=\"link\">" .
3671 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3673 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3677 if (defined $extra) {
3679 "<td colspan=\"3\">$extra</td>\n" .
3685 ## ======================================================================
3686 ## ======================================================================
3689 sub git_project_list
{
3690 my $order = $cgi->param('o');
3691 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3692 die_error
(undef, "Unknown order parameter");
3695 my @list = git_get_projects_list
();
3697 die_error
(undef, "No projects found");
3701 if (-f
$home_text) {
3702 print "<div class=\"index_include\">\n";
3703 open (my $fd, $home_text);
3708 git_project_list_body
(\
@list, $order);
3713 my $order = $cgi->param('o');
3714 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3715 die_error
(undef, "Unknown order parameter");
3718 my @list = git_get_projects_list
($project);
3720 die_error
(undef, "No forks found");
3724 git_print_page_nav
('','');
3725 git_print_header_div
('summary', "$project forks");
3726 git_project_list_body
(\
@list, $order);
3730 sub git_project_index
{
3731 my @projects = git_get_projects_list
($project);
3734 -type
=> 'text/plain',
3735 -charset
=> 'utf-8',
3736 -content_disposition
=> 'inline; filename="index.aux"');
3738 foreach my $pr (@projects) {
3739 if (!exists $pr->{'owner'}) {
3740 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3743 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3744 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3745 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3746 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3750 print "$path $owner\n";
3755 my $descr = git_get_project_description
($project) || "none";
3756 my %co = parse_commit
("HEAD");
3757 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3758 my $head = $co{'id'};
3760 my $owner = git_get_project_owner
($project);
3762 my $refs = git_get_references
();
3763 # These get_*_list functions return one more to allow us to see if
3764 # there are more ...
3765 my @taglist = git_get_tags_list
(16);
3766 my @headlist = git_get_heads_list
(16);
3768 my ($check_forks) = gitweb_check_feature
('forks');
3771 @forklist = git_get_projects_list
($project);
3775 git_print_page_nav
('summary','', $head);
3777 print "<div class=\"title\"> </div>\n";
3778 print "<table cellspacing=\"0\">\n" .
3779 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3780 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3781 if (defined $cd{'rfc2822'}) {
3782 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3785 # use per project git URL list in $projectroot/$project/cloneurl
3786 # or make project git URL from git base URL and project name
3787 my $url_tag = "URL";
3788 my @url_list = git_get_project_url_list
($project);
3789 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3790 foreach my $git_url (@url_list) {
3791 next unless $git_url;
3792 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3797 if (-s
"$projectroot/$project/README.html") {
3798 if (open my $fd, "$projectroot/$project/README.html") {
3799 print "<div class=\"title\">readme</div>\n";
3800 print $_ while (<$fd>);
3805 # we need to request one more than 16 (0..15) to check if
3807 my @commitlist = $head ? parse_commits
($head, 17) : ();
3809 git_print_header_div
('shortlog');
3810 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3811 $#commitlist <= 15 ?
undef :
3812 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3816 git_print_header_div
('tags');
3817 git_tags_body
(\
@taglist, 0, 15,
3818 $#taglist <= 15 ?
undef :
3819 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3823 git_print_header_div
('heads');
3824 git_heads_body
(\
@headlist, $head, 0, 15,
3825 $#headlist <= 15 ?
undef :
3826 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3830 git_print_header_div
('forks');
3831 git_project_list_body
(\
@forklist, undef, 0, 15,
3832 $#forklist <= 15 ?
undef :
3833 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3841 my $head = git_get_head_hash
($project);
3843 git_print_page_nav
('','', $head,undef,$head);
3844 my %tag = parse_tag
($hash);
3847 die_error
(undef, "Unknown tag object");
3850 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3851 print "<div class=\"title_text\">\n" .
3852 "<table cellspacing=\"0\">\n" .
3854 "<td>object</td>\n" .
3855 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3856 $tag{'object'}) . "</td>\n" .
3857 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3858 $tag{'type'}) . "</td>\n" .
3860 if (defined($tag{'author'})) {
3861 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3862 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3863 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3864 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3867 print "</table>\n\n" .
3869 print "<div class=\"page_body\">";
3870 my $comment = $tag{'comment'};
3871 foreach my $line (@
$comment) {
3873 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3883 my ($have_blame) = gitweb_check_feature
('blame');
3885 die_error
('403 Permission denied', "Permission denied");
3887 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3888 $hash_base ||= git_get_head_hash
($project);
3889 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3890 my %co = parse_commit
($hash_base)
3891 or die_error
(undef, "Reading commit failed");
3892 if (!defined $hash) {
3893 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3894 or die_error
(undef, "Error looking up file");
3896 $ftype = git_get_type
($hash);
3897 if ($ftype !~ "blob") {
3898 die_error
('400 Bad Request', "Object is not a blob");
3900 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3901 $file_name, $hash_base)
3902 or die_error
(undef, "Open git-blame failed");
3905 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3908 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3911 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3913 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3914 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3915 git_print_page_path
($file_name, $ftype, $hash_base);
3916 my @rev_color = (qw(light2 dark2));
3917 my $num_colors = scalar(@rev_color);
3918 my $current_color = 0;
3921 <div class="page_body">
3922 <table class="blame">
3923 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3928 last unless defined $_;
3929 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3930 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3931 if (!exists $metainfo{$full_rev}) {
3932 $metainfo{$full_rev} = {};
3934 my $meta = $metainfo{$full_rev};
3937 if (/^(\S+) (.*)$/) {
3943 my $rev = substr($full_rev, 0, 8);
3944 my $author = $meta->{'author'};
3945 my %date = parse_date
($meta->{'author-time'},
3946 $meta->{'author-tz'});
3947 my $date = $date{'iso-tz'};
3949 $current_color = ++$current_color % $num_colors;
3951 print "<tr class=\"$rev_color[$current_color]\">\n";
3953 print "<td class=\"sha1\"";
3954 print " title=\"". esc_html
($author) . ", $date\"";
3955 print " rowspan=\"$group_size\"" if ($group_size > 1);
3957 print $cgi->a({-href
=> href
(action
=>"commit",
3959 file_name
=>$file_name)},
3963 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3964 or die_error
(undef, "Open git-rev-parse failed");
3965 my $parent_commit = <$dd>;
3967 chomp($parent_commit);
3968 my $blamed = href
(action
=> 'blame',
3969 file_name
=> $meta->{'filename'},
3970 hash_base
=> $parent_commit);
3971 print "<td class=\"linenr\">";
3972 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3974 -class => "linenr" },
3977 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3983 or print "Reading blob failed\n";
3990 my ($have_blame) = gitweb_check_feature
('blame');
3992 die_error
('403 Permission denied', "Permission denied");
3994 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3995 $hash_base ||= git_get_head_hash
($project);
3996 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3997 my %co = parse_commit
($hash_base)
3998 or die_error
(undef, "Reading commit failed");
3999 if (!defined $hash) {
4000 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4001 or die_error
(undef, "Error lookup file");
4003 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4004 or die_error
(undef, "Open git-annotate failed");
4007 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4010 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4013 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4015 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4016 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4017 git_print_page_path
($file_name, 'blob', $hash_base);
4018 print "<div class=\"page_body\">\n";
4020 <table class="blame">
4029 my @line_class = (qw(light dark));
4030 my $line_class_len = scalar (@line_class);
4031 my $line_class_num = $#line_class;
4032 while (my $line = <$fd>) {
4044 $line_class_num = ($line_class_num + 1) % $line_class_len;
4046 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4053 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4056 $short_rev = substr ($long_rev, 0, 8);
4057 $age = time () - $time;
4058 $age_str = age_string
($age);
4059 $age_str =~ s/ / /g;
4060 $age_class = age_class
($age);
4061 $author = esc_html
($author);
4062 $author =~ s/ / /g;
4064 $data = untabify
($data);
4065 $data = esc_html
($data);
4068 <tr class="$line_class[$line_class_num]">
4069 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4070 <td class="$age_class">$age_str</td>
4072 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4073 <td class="pre">$data</td>
4076 } # while (my $line = <$fd>)
4077 print "</table>\n\n";
4079 or print "Reading blob failed.\n";
4085 my $head = git_get_head_hash
($project);
4087 git_print_page_nav
('','', $head,undef,$head);
4088 git_print_header_div
('summary', $project);
4090 my @tagslist = git_get_tags_list
();
4092 git_tags_body
(\
@tagslist);
4098 my $head = git_get_head_hash
($project);
4100 git_print_page_nav
('','', $head,undef,$head);
4101 git_print_header_div
('summary', $project);
4103 my @headslist = git_get_heads_list
();
4105 git_heads_body
(\
@headslist, $head);
4110 sub git_blob_plain
{
4113 if (!defined $hash) {
4114 if (defined $file_name) {
4115 my $base = $hash_base || git_get_head_hash
($project);
4116 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4117 or die_error
(undef, "Error lookup file");
4119 die_error
(undef, "No file name defined");
4121 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4122 # blobs defined by non-textual hash id's can be cached
4127 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4128 or die_error
(undef, "Couldn't cat $file_name, $hash");
4130 $type ||= blob_mimetype
($fd, $file_name);
4132 # save as filename, even when no $file_name is given
4133 my $save_as = "$hash";
4134 if (defined $file_name) {
4135 $save_as = $file_name;
4136 } elsif ($type =~ m/^text\//) {
4143 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4145 binmode STDOUT
, ':raw';
4147 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4155 if (!defined $hash) {
4156 if (defined $file_name) {
4157 my $base = $hash_base || git_get_head_hash
($project);
4158 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4159 or die_error
(undef, "Error lookup file");
4161 die_error
(undef, "No file name defined");
4163 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4164 # blobs defined by non-textual hash id's can be cached
4168 my ($have_blame) = gitweb_check_feature
('blame');
4169 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4170 or die_error
(undef, "Couldn't cat $file_name, $hash");
4171 my $mimetype = blob_mimetype
($fd, $file_name);
4172 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4174 return git_blob_plain
($mimetype);
4176 # we can have blame only for text/* mimetype
4177 $have_blame &&= ($mimetype =~ m!^text/!);
4179 git_header_html
(undef, $expires);
4180 my $formats_nav = '';
4181 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4182 if (defined $file_name) {
4185 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4186 hash
=>$hash, file_name
=>$file_name)},
4191 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4192 hash
=>$hash, file_name
=>$file_name)},
4195 $cgi->a({-href
=> href
(action
=>"blob_plain",
4196 hash
=>$hash, file_name
=>$file_name)},
4199 $cgi->a({-href
=> href
(action
=>"blob",
4200 hash_base
=>"HEAD", file_name
=>$file_name)},
4204 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4206 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4207 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4209 print "<div class=\"page_nav\">\n" .
4210 "<br/><br/></div>\n" .
4211 "<div class=\"title\">$hash</div>\n";
4213 git_print_page_path
($file_name, "blob", $hash_base);
4214 print "<div class=\"page_body\">\n";
4215 if ($mimetype =~ m!^text/!) {
4217 while (my $line = <$fd>) {
4220 $line = untabify
($line);
4221 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4222 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4224 } elsif ($mimetype =~ m!^image/!) {
4225 print qq!<img type
="$mimetype"!;
4227 print qq! alt
="$file_name" title
="$file_name"!;
4230 href(action=>"blob_plain
", hash=>$hash,
4231 hash_base=>$hash_base, file_name=>$file_name) .
4235 or print "Reading blob failed.\n";
4241 if (!defined $hash_base) {
4242 $hash_base = "HEAD";
4244 if (!defined $hash) {
4245 if (defined $file_name) {
4246 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4252 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4253 or die_error
(undef, "Open git-ls-tree failed");
4254 my @entries = map { chomp; $_ } <$fd>;
4255 close $fd or die_error
(undef, "Reading tree failed");
4258 my $refs = git_get_references
();
4259 my $ref = format_ref_marker
($refs, $hash_base);
4262 my ($have_blame) = gitweb_check_feature
('blame');
4263 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4265 if (defined $file_name) {
4267 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4268 hash
=>$hash, file_name
=>$file_name)},
4270 $cgi->a({-href
=> href
(action
=>"tree",
4271 hash_base
=>"HEAD", file_name
=>$file_name)},
4274 my $snapshot_links = format_snapshot_links
($hash);
4275 if (defined $snapshot_links) {
4276 # FIXME: Should be available when we have no hash base as well.
4277 push @views_nav, $snapshot_links;
4279 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4280 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4283 print "<div class=\"page_nav\">\n";
4284 print "<br/><br/></div>\n";
4285 print "<div class=\"title\">$hash</div>\n";
4287 if (defined $file_name) {
4288 $basedir = $file_name;
4289 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4293 git_print_page_path
($file_name, 'tree', $hash_base);
4294 print "<div class=\"page_body\">\n";
4295 print "<table cellspacing=\"0\">\n";
4297 # '..' (top directory) link if possible
4298 if (defined $hash_base &&
4299 defined $file_name && $file_name =~ m![^/]+$!) {
4301 print "<tr class=\"dark\">\n";
4303 print "<tr class=\"light\">\n";
4307 my $up = $file_name;
4308 $up =~ s!/?[^/]+$!!;
4309 undef $up unless $up;
4310 # based on git_print_tree_entry
4311 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4312 print '<td class="list">';
4313 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4317 print "<td class=\"link\"></td>\n";
4321 foreach my $line (@entries) {
4322 my %t = parse_ls_tree_line
($line, -z
=> 1);
4325 print "<tr class=\"dark\">\n";
4327 print "<tr class=\"light\">\n";
4331 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4335 print "</table>\n" .
4341 my @supported_fmts = gitweb_check_feature
('snapshot');
4342 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4344 my $format = $cgi->param('sf');
4345 if (!@supported_fmts) {
4346 die_error
('403 Permission denied', "Permission denied");
4348 # default to first supported snapshot format
4349 $format ||= $supported_fmts[0];
4350 if ($format !~ m/^[a-z0-9]+$/) {
4351 die_error
(undef, "Invalid snapshot format parameter");
4352 } elsif (!exists($known_snapshot_formats{$format})) {
4353 die_error
(undef, "Unknown snapshot format");
4354 } elsif (!grep($_ eq $format, @supported_fmts)) {
4355 die_error
(undef, "Unsupported snapshot format");
4358 if (!defined $hash) {
4359 $hash = git_get_head_hash
($project);
4362 my $git_command = git_cmd_str
();
4363 my $name = $project;
4364 $name =~ s
,([^/])/*\
.git
$,$1,;
4365 $name = basename
($name);
4366 my $filename = to_utf8
($name);
4367 $name =~ s/\047/\047\\\047\047/g;
4369 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4370 $cmd = "$git_command archive " .
4371 "--format=$known_snapshot_formats{$format}{'format'} " .
4372 "--prefix=\'$name\'/ $hash";
4373 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4374 $cmd .= ' | ' . join ' ', @
{$known_snapshot_formats{$format}{'compressor'}};
4378 -type
=> $known_snapshot_formats{$format}{'type'},
4379 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4380 -status
=> '200 OK');
4382 open my $fd, "-|", $cmd
4383 or die_error
(undef, "Execute git-archive failed");
4384 binmode STDOUT
, ':raw';
4386 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4391 my $head = git_get_head_hash
($project);
4392 if (!defined $hash) {
4395 if (!defined $page) {
4398 my $refs = git_get_references
();
4400 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4402 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4405 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4408 my %co = parse_commit
($hash);
4410 git_print_header_div
('summary', $project);
4411 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4413 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4414 for (my $i = 0; $i <= $to; $i++) {
4415 my %co = %{$commitlist[$i]};
4417 my $commit = $co{'id'};
4418 my $ref = format_ref_marker
($refs, $commit);
4419 my %ad = parse_date
($co{'author_epoch'});
4420 git_print_header_div
('commit',
4421 "<span class=\"age\">$co{'age_string'}</span>" .
4422 esc_html
($co{'title'}) . $ref,
4424 print "<div class=\"title_text\">\n" .
4425 "<div class=\"log_link\">\n" .
4426 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4428 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4430 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4433 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4436 print "<div class=\"log_body\">\n";
4437 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4440 if ($#commitlist >= 100) {
4441 print "<div class=\"page_nav\">\n";
4442 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4443 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4450 $hash ||= $hash_base || "HEAD";
4451 my %co = parse_commit
($hash);
4453 die_error
(undef, "Unknown commit object");
4455 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4456 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4458 my $parent = $co{'parent'};
4459 my $parents = $co{'parents'}; # listref
4461 # we need to prepare $formats_nav before any parameter munging
4463 if (!defined $parent) {
4465 $formats_nav .= '(initial)';
4466 } elsif (@
$parents == 1) {
4467 # single parent commit
4470 $cgi->a({-href
=> href
(action
=>"commit",
4472 esc_html
(substr($parent, 0, 7))) .
4479 $cgi->a({-href
=> href
(action
=>"commit",
4481 esc_html
(substr($_, 0, 7)));
4486 if (!defined $parent) {
4490 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4492 (@
$parents <= 1 ?
$parent : '-c'),
4494 or die_error
(undef, "Open git-diff-tree failed");
4495 @difftree = map { chomp; $_ } <$fd>;
4496 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4498 # non-textual hash id's can be cached
4500 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4503 my $refs = git_get_references
();
4504 my $ref = format_ref_marker
($refs, $co{'id'});
4506 git_header_html
(undef, $expires);
4507 git_print_page_nav
('commit', '',
4508 $hash, $co{'tree'}, $hash,
4511 if (defined $co{'parent'}) {
4512 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4514 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4516 print "<div class=\"title_text\">\n" .
4517 "<table cellspacing=\"0\">\n";
4518 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4520 "<td></td><td> $ad{'rfc2822'}";
4521 if ($ad{'hour_local'} < 6) {
4522 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4523 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4525 printf(" (%02d:%02d %s)",
4526 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4530 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4531 print "<tr><td></td><td> $cd{'rfc2822'}" .
4532 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4534 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4537 "<td class=\"sha1\">" .
4538 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4539 class => "list"}, $co{'tree'}) .
4541 "<td class=\"link\">" .
4542 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4544 my $snapshot_links = format_snapshot_links
($hash);
4545 if (defined $snapshot_links) {
4546 print " | " . $snapshot_links;
4551 foreach my $par (@
$parents) {
4554 "<td class=\"sha1\">" .
4555 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4556 class => "list"}, $par) .
4558 "<td class=\"link\">" .
4559 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4561 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4568 print "<div class=\"page_body\">\n";
4569 git_print_log
($co{'comment'});
4572 git_difftree_body
(\
@difftree, $hash, @
$parents);
4578 # object is defined by:
4579 # - hash or hash_base alone
4580 # - hash_base and file_name
4583 # - hash or hash_base alone
4584 if ($hash || ($hash_base && !defined $file_name)) {
4585 my $object_id = $hash || $hash_base;
4587 my $git_command = git_cmd_str
();
4588 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4589 or die_error
('404 Not Found', "Object does not exist");
4593 or die_error
('404 Not Found', "Object does not exist");
4595 # - hash_base and file_name
4596 } elsif ($hash_base && defined $file_name) {
4597 $file_name =~ s
,/+$,,;
4599 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4600 or die_error
('404 Not Found', "Base object does not exist");
4602 # here errors should not hapen
4603 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4604 or die_error
(undef, "Open git-ls-tree failed");
4608 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4609 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4610 die_error
('404 Not Found', "File or directory for given base does not exist");
4615 die_error
('404 Not Found', "Not enough information to find object");
4618 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4619 hash
=>$hash, hash_base
=>$hash_base,
4620 file_name
=>$file_name),
4621 -status
=> '302 Found');
4625 my $format = shift || 'html';
4632 # preparing $fd and %diffinfo for git_patchset_body
4634 if (defined $hash_base && defined $hash_parent_base) {
4635 if (defined $file_name) {
4637 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4638 $hash_parent_base, $hash_base,
4639 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4640 or die_error
(undef, "Open git-diff-tree failed");
4641 @difftree = map { chomp; $_ } <$fd>;
4643 or die_error
(undef, "Reading git-diff-tree failed");
4645 or die_error
('404 Not Found', "Blob diff not found");
4647 } elsif (defined $hash &&
4648 $hash =~ /[0-9a-fA-F]{40}/) {
4649 # try to find filename from $hash
4651 # read filtered raw output
4652 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4653 $hash_parent_base, $hash_base, "--"
4654 or die_error
(undef, "Open git-diff-tree failed");
4656 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4658 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4659 map { chomp; $_ } <$fd>;
4661 or die_error
(undef, "Reading git-diff-tree failed");
4663 or die_error
('404 Not Found', "Blob diff not found");
4666 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4669 if (@difftree > 1) {
4670 die_error
('404 Not Found', "Ambiguous blob diff specification");
4673 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4674 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4675 $file_name ||= $diffinfo{'to_file'};
4677 $hash_parent ||= $diffinfo{'from_id'};
4678 $hash ||= $diffinfo{'to_id'};
4680 # non-textual hash id's can be cached
4681 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4682 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4687 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4688 '-p', ($format eq 'html' ?
"--full-index" : ()),
4689 $hash_parent_base, $hash_base,
4690 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4691 or die_error
(undef, "Open git-diff-tree failed");
4694 # old/legacy style URI
4695 if (!%diffinfo && # if new style URI failed
4696 defined $hash && defined $hash_parent) {
4697 # fake git-diff-tree raw output
4698 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4699 $diffinfo{'from_id'} = $hash_parent;
4700 $diffinfo{'to_id'} = $hash;
4701 if (defined $file_name) {
4702 if (defined $file_parent) {
4703 $diffinfo{'status'} = '2';
4704 $diffinfo{'from_file'} = $file_parent;
4705 $diffinfo{'to_file'} = $file_name;
4706 } else { # assume not renamed
4707 $diffinfo{'status'} = '1';
4708 $diffinfo{'from_file'} = $file_name;
4709 $diffinfo{'to_file'} = $file_name;
4711 } else { # no filename given
4712 $diffinfo{'status'} = '2';
4713 $diffinfo{'from_file'} = $hash_parent;
4714 $diffinfo{'to_file'} = $hash;
4717 # non-textual hash id's can be cached
4718 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4719 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4724 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4725 '-p', ($format eq 'html' ?
"--full-index" : ()),
4726 $hash_parent, $hash, "--"
4727 or die_error
(undef, "Open git-diff failed");
4729 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4734 if ($format eq 'html') {
4736 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4737 hash
=>$hash, hash_parent
=>$hash_parent,
4738 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4739 file_name
=>$file_name, file_parent
=>$file_parent)},
4741 git_header_html
(undef, $expires);
4742 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4743 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4744 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4746 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4747 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4749 if (defined $file_name) {
4750 git_print_page_path
($file_name, "blob", $hash_base);
4752 print "<div class=\"page_path\"></div>\n";
4755 } elsif ($format eq 'plain') {
4757 -type
=> 'text/plain',
4758 -charset
=> 'utf-8',
4759 -expires
=> $expires,
4760 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4762 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4765 die_error
(undef, "Unknown blobdiff format");
4769 if ($format eq 'html') {
4770 print "<div class=\"page_body\">\n";
4772 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4775 print "</div>\n"; # class="page_body"
4779 while (my $line = <$fd>) {
4780 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4781 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4785 last if $line =~ m!^\+\+\+!;
4793 sub git_blobdiff_plain
{
4794 git_blobdiff
('plain');
4797 sub git_commitdiff
{
4798 my $format = shift || 'html';
4799 $hash ||= $hash_base || "HEAD";
4800 my %co = parse_commit
($hash);
4802 die_error
(undef, "Unknown commit object");
4805 # choose format for commitdiff for merge
4806 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4807 $hash_parent = '--cc';
4809 # we need to prepare $formats_nav before almost any parameter munging
4811 if ($format eq 'html') {
4813 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4814 hash
=>$hash, hash_parent
=>$hash_parent)},
4817 if (defined $hash_parent &&
4818 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4819 # commitdiff with two commits given
4820 my $hash_parent_short = $hash_parent;
4821 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4822 $hash_parent_short = substr($hash_parent, 0, 7);
4826 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4827 if ($co{'parents'}[$i] eq $hash_parent) {
4828 $formats_nav .= ' parent ' . ($i+1);
4832 $formats_nav .= ': ' .
4833 $cgi->a({-href
=> href
(action
=>"commitdiff",
4834 hash
=>$hash_parent)},
4835 esc_html
($hash_parent_short)) .
4837 } elsif (!$co{'parent'}) {
4839 $formats_nav .= ' (initial)';
4840 } elsif (scalar @
{$co{'parents'}} == 1) {
4841 # single parent commit
4844 $cgi->a({-href
=> href
(action
=>"commitdiff",
4845 hash
=>$co{'parent'})},
4846 esc_html
(substr($co{'parent'}, 0, 7))) .
4850 if ($hash_parent eq '--cc') {
4851 $formats_nav .= ' | ' .
4852 $cgi->a({-href
=> href
(action
=>"commitdiff",
4853 hash
=>$hash, hash_parent
=>'-c')},
4855 } else { # $hash_parent eq '-c'
4856 $formats_nav .= ' | ' .
4857 $cgi->a({-href
=> href
(action
=>"commitdiff",
4858 hash
=>$hash, hash_parent
=>'--cc')},
4864 $cgi->a({-href
=> href
(action
=>"commitdiff",
4866 esc_html
(substr($_, 0, 7)));
4867 } @
{$co{'parents'}} ) .
4872 my $hash_parent_param = $hash_parent;
4873 if (!defined $hash_parent_param) {
4874 # --cc for multiple parents, --root for parentless
4875 $hash_parent_param =
4876 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
4882 if ($format eq 'html') {
4883 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4884 "--no-commit-id", "--patch-with-raw", "--full-index",
4885 $hash_parent_param, $hash, "--"
4886 or die_error
(undef, "Open git-diff-tree failed");
4888 while (my $line = <$fd>) {
4890 # empty line ends raw part of diff-tree output
4892 push @difftree, scalar parse_difftree_raw_line
($line);
4895 } elsif ($format eq 'plain') {
4896 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4897 '-p', $hash_parent_param, $hash, "--"
4898 or die_error
(undef, "Open git-diff-tree failed");
4901 die_error
(undef, "Unknown commitdiff format");
4904 # non-textual hash id's can be cached
4906 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4910 # write commit message
4911 if ($format eq 'html') {
4912 my $refs = git_get_references
();
4913 my $ref = format_ref_marker
($refs, $co{'id'});
4915 git_header_html
(undef, $expires);
4916 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4917 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4918 git_print_authorship
(\
%co);
4919 print "<div class=\"page_body\">\n";
4920 if (@
{$co{'comment'}} > 1) {
4921 print "<div class=\"log\">\n";
4922 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4923 print "</div>\n"; # class="log"
4926 } elsif ($format eq 'plain') {
4927 my $refs = git_get_references
("tags");
4928 my $tagname = git_get_rev_name_tags
($hash);
4929 my $filename = basename
($project) . "-$hash.patch";
4932 -type
=> 'text/plain',
4933 -charset
=> 'utf-8',
4934 -expires
=> $expires,
4935 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4936 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4939 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4940 Subject: $co{'title'}
4942 print "X-Git-Tag: $tagname\n" if $tagname;
4943 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4945 foreach my $line (@
{$co{'comment'}}) {
4952 if ($format eq 'html') {
4953 my $use_parents = !defined $hash_parent ||
4954 $hash_parent eq '-c' || $hash_parent eq '--cc';
4955 git_difftree_body
(\
@difftree, $hash,
4956 $use_parents ? @
{$co{'parents'}} : $hash_parent);
4959 git_patchset_body
($fd, \
@difftree, $hash,
4960 $use_parents ? @
{$co{'parents'}} : $hash_parent);
4962 print "</div>\n"; # class="page_body"
4965 } elsif ($format eq 'plain') {
4969 or print "Reading git-diff-tree failed\n";
4973 sub git_commitdiff_plain
{
4974 git_commitdiff
('plain');
4978 if (!defined $hash_base) {
4979 $hash_base = git_get_head_hash
($project);
4981 if (!defined $page) {
4985 my %co = parse_commit
($hash_base);
4987 die_error
(undef, "Unknown commit object");
4990 my $refs = git_get_references
();
4991 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4993 if (!defined $hash && defined $file_name) {
4994 $hash = git_get_hash_by_path
($hash_base, $file_name);
4996 if (defined $hash) {
4997 $ftype = git_get_type
($hash);
5000 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5002 my $paging_nav = '';
5005 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5006 file_name
=>$file_name)},
5008 $paging_nav .= " ⋅ " .
5009 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5010 file_name
=>$file_name, page
=>$page-1),
5011 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5013 $paging_nav .= "first";
5014 $paging_nav .= " ⋅ prev";
5016 if ($#commitlist >= 100) {
5017 $paging_nav .= " ⋅ " .
5018 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5019 file_name
=>$file_name, page
=>$page+1),
5020 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5022 $paging_nav .= " ⋅ next";
5025 if ($#commitlist >= 100) {
5027 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5028 file_name
=>$file_name, page
=>$page+1),
5029 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5033 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5034 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5035 git_print_page_path
($file_name, $ftype, $hash_base);
5037 git_history_body
(\
@commitlist, 0, 99,
5038 $refs, $hash_base, $ftype, $next_link);
5044 my ($have_search) = gitweb_check_feature
('search');
5045 if (!$have_search) {
5046 die_error
('403 Permission denied', "Permission denied");
5048 if (!defined $searchtext) {
5049 die_error
(undef, "Text field empty");
5051 if (!defined $hash) {
5052 $hash = git_get_head_hash
($project);
5054 my %co = parse_commit
($hash);
5056 die_error
(undef, "Unknown commit object");
5058 if (!defined $page) {
5062 $searchtype ||= 'commit';
5063 if ($searchtype eq 'pickaxe') {
5064 # pickaxe may take all resources of your box and run for several minutes
5065 # with every query - so decide by yourself how public you make this feature
5066 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5067 if (!$have_pickaxe) {
5068 die_error
('403 Permission denied', "Permission denied");
5071 if ($searchtype eq 'grep') {
5072 my ($have_grep) = gitweb_check_feature
('grep');
5074 die_error
('403 Permission denied', "Permission denied");
5080 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5082 if ($searchtype eq 'commit') {
5083 $greptype = "--grep=";
5084 } elsif ($searchtype eq 'author') {
5085 $greptype = "--author=";
5086 } elsif ($searchtype eq 'committer') {
5087 $greptype = "--committer=";
5089 $greptype .= $search_regexp;
5090 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5092 my $paging_nav = '';
5095 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5096 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5098 $paging_nav .= " ⋅ " .
5099 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5100 searchtext
=>$searchtext, searchtype
=>$searchtype,
5102 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5104 $paging_nav .= "first";
5105 $paging_nav .= " ⋅ prev";
5107 if ($#commitlist >= 100) {
5108 $paging_nav .= " ⋅ " .
5109 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5110 searchtext
=>$searchtext, searchtype
=>$searchtype,
5112 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5114 $paging_nav .= " ⋅ next";
5117 if ($#commitlist >= 100) {
5119 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5120 searchtext
=>$searchtext, searchtype
=>$searchtype,
5122 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5125 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5126 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5127 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5130 if ($searchtype eq 'pickaxe') {
5131 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5132 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5134 print "<table cellspacing=\"0\">\n";
5137 my $git_command = git_cmd_str
();
5138 my $searchqtext = $searchtext;
5139 $searchqtext =~ s/'/'\\''/;
5140 open my $fd, "-|", "$git_command rev-list $hash | " .
5141 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5144 while (my $line = <$fd>) {
5145 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5148 $set{'from_id'} = $3;
5150 $set{'id'} = $set{'to_id'};
5151 if ($set{'id'} =~ m/0{40}/) {
5152 $set{'id'} = $set{'from_id'};
5154 if ($set{'id'} =~ m/0{40}/) {
5158 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5161 print "<tr class=\"dark\">\n";
5163 print "<tr class=\"light\">\n";
5166 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5167 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5168 "<td><i>" . $author . "</i></td>\n" .
5170 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5171 -class => "list subject"},
5172 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5173 while (my $setref = shift @files) {
5175 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5176 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5178 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5182 "<td class=\"link\">" .
5183 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5185 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5189 %co = parse_commit
($1);
5197 if ($searchtype eq 'grep') {
5198 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5199 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5201 print "<table cellspacing=\"0\">\n";
5205 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5207 while (my $line = <$fd>) {
5209 my ($file, $lno, $ltext, $binary);
5210 last if ($matches++ > 1000);
5211 if ($line =~ /^Binary file (.+) matches$/) {
5215 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5217 if ($file ne $lastfile) {
5218 $lastfile and print "</td></tr>\n";
5220 print "<tr class=\"dark\">\n";
5222 print "<tr class=\"light\">\n";
5224 print "<td class=\"list\">".
5225 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5226 file_name
=>"$file"),
5227 -class => "list"}, esc_path
($file));
5228 print "</td><td>\n";
5232 print "<div class=\"binary\">Binary file</div>\n";
5234 $ltext = untabify
($ltext);
5235 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5236 $ltext = esc_html
($1, -nbsp
=>1);
5237 $ltext .= '<span class="match">';
5238 $ltext .= esc_html
($2, -nbsp
=>1);
5239 $ltext .= '</span>';
5240 $ltext .= esc_html
($3, -nbsp
=>1);
5242 $ltext = esc_html
($ltext, -nbsp
=>1);
5244 print "<div class=\"pre\">" .
5245 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5246 file_name
=>"$file").'#l'.$lno,
5247 -class => "linenr"}, sprintf('%4i', $lno))
5248 . ' ' . $ltext . "</div>\n";
5252 print "</td></tr>\n";
5253 if ($matches > 1000) {
5254 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5257 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5266 sub git_search_help
{
5268 git_print_page_nav
('','', $hash,$hash,$hash);
5271 <dt><b>commit</b></dt>
5272 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5274 my ($have_grep) = gitweb_check_feature
('grep');
5277 <dt><b>grep</b></dt>
5278 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5279 a different one) are searched for the given
5280 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5281 (POSIX extended) and the matches are listed. On large
5282 trees, this search can take a while and put some strain on the server, so please use it with
5283 some consideration.</dd>
5287 <dt><b>author</b></dt>
5288 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5289 <dt><b>committer</b></dt>
5290 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5292 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5293 if ($have_pickaxe) {
5295 <dt><b>pickaxe</b></dt>
5296 <dd>All commits that caused the string to appear or disappear from any file (changes that
5297 added, removed or "modified" the string) will be listed. This search can take a while and
5298 takes a lot of strain on the server, so please use it wisely.</dd>
5306 my $head = git_get_head_hash
($project);
5307 if (!defined $hash) {
5310 if (!defined $page) {
5313 my $refs = git_get_references
();
5315 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5317 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5319 if ($#commitlist >= 100) {
5321 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5322 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5326 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5327 git_print_header_div
('summary', $project);
5329 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5334 ## ......................................................................
5335 ## feeds (RSS, Atom; OPML)
5338 my $format = shift || 'atom';
5339 my ($have_blame) = gitweb_check_feature
('blame');
5341 # Atom: http://www.atomenabled.org/developers/syndication/
5342 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5343 if ($format ne 'rss' && $format ne 'atom') {
5344 die_error
(undef, "Unknown web feed format");
5347 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5348 my $head = $hash || 'HEAD';
5349 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5353 my $content_type = "application/$format+xml";
5354 if (defined $cgi->http('HTTP_ACCEPT') &&
5355 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5356 # browser (feed reader) prefers text/xml
5357 $content_type = 'text/xml';
5359 if (defined($commitlist[0])) {
5360 %latest_commit = %{$commitlist[0]};
5361 %latest_date = parse_date
($latest_commit{'author_epoch'});
5363 -type
=> $content_type,
5364 -charset
=> 'utf-8',
5365 -last_modified
=> $latest_date{'rfc2822'});
5368 -type
=> $content_type,
5369 -charset
=> 'utf-8');
5372 # Optimization: skip generating the body if client asks only
5373 # for Last-Modified date.
5374 return if ($cgi->request_method() eq 'HEAD');
5377 my $title = "$site_name - $project/$action";
5378 my $feed_type = 'log';
5379 if (defined $hash) {
5380 $title .= " - '$hash'";
5381 $feed_type = 'branch log';
5382 if (defined $file_name) {
5383 $title .= " :: $file_name";
5384 $feed_type = 'history';
5386 } elsif (defined $file_name) {
5387 $title .= " - $file_name";
5388 $feed_type = 'history';
5390 $title .= " $feed_type";
5391 my $descr = git_get_project_description
($project);
5392 if (defined $descr) {
5393 $descr = esc_html
($descr);
5395 $descr = "$project " .
5396 ($format eq 'rss' ?
'RSS' : 'Atom') .
5399 my $owner = git_get_project_owner
($project);
5400 $owner = esc_html
($owner);
5404 if (defined $file_name) {
5405 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5406 } elsif (defined $hash) {
5407 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5409 $alt_url = href
(-full
=>1, action
=>"summary");
5411 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5412 if ($format eq 'rss') {
5414 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5417 print "<title>$title</title>\n" .
5418 "<link>$alt_url</link>\n" .
5419 "<description>$descr</description>\n" .
5420 "<language>en</language>\n";
5421 } elsif ($format eq 'atom') {
5423 <feed xmlns="http://www.w3.org/2005/Atom">
5425 print "<title>$title</title>\n" .
5426 "<subtitle>$descr</subtitle>\n" .
5427 '<link rel="alternate" type="text/html" href="' .
5428 $alt_url . '" />' . "\n" .
5429 '<link rel="self" type="' . $content_type . '" href="' .
5430 $cgi->self_url() . '" />' . "\n" .
5431 "<id>" . href
(-full
=>1) . "</id>\n" .
5432 # use project owner for feed author
5433 "<author><name>$owner</name></author>\n";
5434 if (defined $favicon) {
5435 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5437 if (defined $logo_url) {
5438 # not twice as wide as tall: 72 x 27 pixels
5439 print "<logo>" . esc_url
($logo) . "</logo>\n";
5441 if (! %latest_date) {
5442 # dummy date to keep the feed valid until commits trickle in:
5443 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5445 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5450 for (my $i = 0; $i <= $#commitlist; $i++) {
5451 my %co = %{$commitlist[$i]};
5452 my $commit = $co{'id'};
5453 # we read 150, we always show 30 and the ones more recent than 48 hours
5454 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5457 my %cd = parse_date
($co{'author_epoch'});
5459 # get list of changed files
5460 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5461 $co{'parent'} || "--root",
5462 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5464 my @difftree = map { chomp; $_ } <$fd>;
5468 # print element (entry, item)
5469 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5470 if ($format eq 'rss') {
5472 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5473 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5474 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5475 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5476 "<link>$co_url</link>\n" .
5477 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5478 "<content:encoded>" .
5480 } elsif ($format eq 'atom') {
5482 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5483 "<updated>$cd{'iso-8601'}</updated>\n" .
5485 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5486 if ($co{'author_email'}) {
5487 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5489 print "</author>\n" .
5490 # use committer for contributor
5492 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5493 if ($co{'committer_email'}) {
5494 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5496 print "</contributor>\n" .
5497 "<published>$cd{'iso-8601'}</published>\n" .
5498 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5499 "<id>$co_url</id>\n" .
5500 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5501 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5503 my $comment = $co{'comment'};
5505 foreach my $line (@
$comment) {
5506 $line = esc_html
($line);
5509 print "</pre><ul>\n";
5510 foreach my $difftree_line (@difftree) {
5511 my %difftree = parse_difftree_raw_line
($difftree_line);
5512 next if !$difftree{'from_id'};
5514 my $file = $difftree{'file'} || $difftree{'to_file'};
5518 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5519 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5520 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5521 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5522 -title
=> "diff"}, 'D');
5524 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5525 file_name
=>$file, hash_base
=>$commit),
5526 -title
=> "blame"}, 'B');
5528 # if this is not a feed of a file history
5529 if (!defined $file_name || $file_name ne $file) {
5530 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5531 file_name
=>$file, hash
=>$commit),
5532 -title
=> "history"}, 'H');
5534 $file = esc_path
($file);
5538 if ($format eq 'rss') {
5539 print "</ul>]]>\n" .
5540 "</content:encoded>\n" .
5542 } elsif ($format eq 'atom') {
5543 print "</ul>\n</div>\n" .
5550 if ($format eq 'rss') {
5551 print "</channel>\n</rss>\n";
5552 } elsif ($format eq 'atom') {
5566 my @list = git_get_projects_list
();
5568 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5570 <?xml version="1.0" encoding="utf-8"?>
5571 <opml version="1.0">
5573 <title>$site_name OPML Export</title>
5576 <outline text="git RSS feeds">
5579 foreach my $pr (@list) {
5581 my $head = git_get_head_hash
($proj{'path'});
5582 if (!defined $head) {
5585 $git_dir = "$projectroot/$proj{'path'}";
5586 my %co = parse_commit
($head);
5591 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5592 my $rss = "$my_url?p=$proj{'path'};a=rss";
5593 my $html = "$my_url?p=$proj{'path'};a=summary";
5594 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";