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 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # the width (in characters) of the projects list "Description" column
76 our $projects_list_description_width = 25;
78 # default order of projects list
79 # valid values are none, project, descr, owner, and age
80 our $default_projects_order = "project";
82 # show repository only if this file exists
83 # (only effective if this variable evaluates to true)
84 our $export_ok = "++GITWEB_EXPORT_OK++";
86 # only allow viewing of repositories also shown on the overview page
87 our $strict_export = "++GITWEB_STRICT_EXPORT++";
89 # list of git base URLs used for URL to where fetch project from,
90 # i.e. full URL is "$git_base_url/$project"
91 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
93 # default blob_plain mimetype and default charset for text/plain blob
94 our $default_blob_plain_mimetype = 'text/plain';
95 our $default_text_plain_charset = undef;
97 # file to use for guessing MIME types before trying /etc/mime.types
98 # (relative to the current git repository)
99 our $mimetypes_file = undef;
101 # assume this charset if line contains non-UTF-8 characters;
102 # it should be valid encoding (see Encoding::Supported(3pm) for list),
103 # for which encoding all byte sequences are valid, for example
104 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
105 # could be even 'utf-8' for the old behavior)
106 our $fallback_encoding = 'latin1';
108 # rename detection options for git-diff and git-diff-tree
109 # - default is '-M', with the cost proportional to
110 # (number of removed files) * (number of new files).
111 # - more costly is '-C' (which implies '-M'), with the cost proportional to
112 # (number of changed files + number of removed files) * (number of new files)
113 # - even more costly is '-C', '--find-copies-harder' with cost
114 # (number of files in the original tree) * (number of new files)
115 # - one might want to include '-B' option, e.g. '-B', '-M'
116 our @diff_opts = ('-M'); # taken from git_commit
118 # information about snapshot formats that gitweb is capable of serving
119 our %known_snapshot_formats = (
121 # 'display' => display name,
122 # 'type' => mime type,
123 # 'suffix' => filename suffix,
124 # 'format' => --format for git-archive,
125 # 'compressor' => [compressor command and arguments]
126 # (array reference, optional)}
129 'display' => 'tar.gz',
130 'type' => 'application/x-gzip',
131 'suffix' => '.tar.gz',
133 'compressor' => ['gzip']},
136 'display' => 'tar.bz2',
137 'type' => 'application/x-bzip2',
138 'suffix' => '.tar.bz2',
140 'compressor' => ['bzip2']},
144 'type' => 'application/x-zip',
149 # Aliases so we understand old gitweb.snapshot values in repository
151 our %known_snapshot_format_aliases = (
155 # backward compatibility: legacy gitweb config support
156 'x-gzip' => undef, 'gz' => undef,
157 'x-bzip2' => undef, 'bz2' => undef,
158 'x-zip' => undef, '' => undef,
161 # You define site-wide feature defaults here; override them with
162 # $GITWEB_CONFIG as necessary.
165 # 'sub' => feature-sub (subroutine),
166 # 'override' => allow-override (boolean),
167 # 'default' => [ default options...] (array reference)}
169 # if feature is overridable (it means that allow-override has true value),
170 # then feature-sub will be called with default options as parameters;
171 # return value of feature-sub indicates if to enable specified feature
173 # if there is no 'sub' key (no feature-sub), then feature cannot be
176 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
178 # Enable the 'blame' blob view, showing the last commit that modified
179 # each line in the file. This can be very CPU-intensive.
181 # To enable system wide have in $GITWEB_CONFIG
182 # $feature{'blame'}{'default'} = [1];
183 # To have project specific config enable override in $GITWEB_CONFIG
184 # $feature{'blame'}{'override'} = 1;
185 # and in project config gitweb.blame = 0|1;
187 'sub' => \
&feature_blame
,
191 # Enable the 'snapshot' link, providing a compressed archive of any
192 # tree. This can potentially generate high traffic if you have large
195 # Value is a list of formats defined in %known_snapshot_formats that
197 # To disable system wide have in $GITWEB_CONFIG
198 # $feature{'snapshot'}{'default'} = [];
199 # To have project specific config enable override in $GITWEB_CONFIG
200 # $feature{'snapshot'}{'override'} = 1;
201 # and in project config, a comma-separated list of formats or "none"
202 # to disable. Example: gitweb.snapshot = tbz2,zip;
204 'sub' => \
&feature_snapshot
,
206 'default' => ['tgz']},
208 # Enable text search, which will list the commits which match author,
209 # committer or commit text to a given string. Enabled by default.
210 # Project specific override is not supported.
215 # Enable grep search, which will list the files in currently selected
216 # tree containing the given string. Enabled by default. This can be
217 # potentially CPU-intensive, of course.
219 # To enable system wide have in $GITWEB_CONFIG
220 # $feature{'grep'}{'default'} = [1];
221 # To have project specific config enable override in $GITWEB_CONFIG
222 # $feature{'grep'}{'override'} = 1;
223 # and in project config gitweb.grep = 0|1;
228 # Enable the pickaxe search, which will list the commits that modified
229 # a given string in a file. This can be practical and quite faster
230 # alternative to 'blame', but still potentially CPU-intensive.
232 # To enable system wide have in $GITWEB_CONFIG
233 # $feature{'pickaxe'}{'default'} = [1];
234 # To have project specific config enable override in $GITWEB_CONFIG
235 # $feature{'pickaxe'}{'override'} = 1;
236 # and in project config gitweb.pickaxe = 0|1;
238 'sub' => \
&feature_pickaxe
,
242 # Make gitweb use an alternative format of the URLs which can be
243 # more readable and natural-looking: project name is embedded
244 # directly in the path and the query string contains other
245 # auxiliary information. All gitweb installations recognize
246 # URL in either format; this configures in which formats gitweb
249 # To enable system wide have in $GITWEB_CONFIG
250 # $feature{'pathinfo'}{'default'} = [1];
251 # Project specific override is not supported.
253 # Note that you will need to change the default location of CSS,
254 # favicon, logo and possibly other files to an absolute URL. Also,
255 # if gitweb.cgi serves as your indexfile, you will need to force
256 # $my_uri to contain the script name in your $GITWEB_CONFIG.
261 # Make gitweb consider projects in project root subdirectories
262 # to be forks of existing projects. Given project $projname.git,
263 # projects matching $projname/*.git will not be shown in the main
264 # projects list, instead a '+' mark will be added to $projname
265 # there and a 'forks' view will be enabled for the project, listing
266 # all the forks. If project list is taken from a file, forks have
267 # to be listed after the main project.
269 # To enable system wide have in $GITWEB_CONFIG
270 # $feature{'forks'}{'default'} = [1];
271 # Project specific override is not supported.
277 sub gitweb_check_feature
{
279 return unless exists $feature{$name};
280 my ($sub, $override, @defaults) = (
281 $feature{$name}{'sub'},
282 $feature{$name}{'override'},
283 @{$feature{$name}{'default'}});
284 if (!$override) { return @defaults; }
286 warn "feature $name is not overrideable";
289 return $sub->(@defaults);
293 my ($val) = git_get_project_config
('blame', '--bool');
295 if ($val eq 'true') {
297 } elsif ($val eq 'false') {
304 sub feature_snapshot
{
307 my ($val) = git_get_project_config
('snapshot');
310 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
317 my ($val) = git_get_project_config
('grep', '--bool');
319 if ($val eq 'true') {
321 } elsif ($val eq 'false') {
328 sub feature_pickaxe
{
329 my ($val) = git_get_project_config
('pickaxe', '--bool');
331 if ($val eq 'true') {
333 } elsif ($val eq 'false') {
340 # checking HEAD file with -e is fragile if the repository was
341 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
343 sub check_head_link
{
345 my $headfile = "$dir/HEAD";
346 return ((-e
$headfile) ||
347 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
350 sub check_export_ok
{
352 return (check_head_link
($dir) &&
353 (!$export_ok || -e
"$dir/$export_ok"));
356 # process alternate names for backward compatibility
357 # filter out unsupported (unknown) snapshot formats
358 sub filter_snapshot_fmts
{
362 exists $known_snapshot_format_aliases{$_} ?
363 $known_snapshot_format_aliases{$_} : $_} @fmts;
364 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
368 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
369 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
371 # version of the core git binary
372 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
374 $projects_list ||= $projectroot;
376 # ======================================================================
377 # input validation and dispatch
378 our $action = $cgi->param('a');
379 if (defined $action) {
380 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
381 die_error
(undef, "Invalid action parameter");
385 # parameters which are pathnames
386 our $project = $cgi->param('p');
387 if (defined $project) {
388 if (!validate_pathname
($project) ||
389 !(-d
"$projectroot/$project") ||
390 !check_head_link
("$projectroot/$project") ||
391 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
392 ($strict_export && !project_in_list
($project))) {
394 die_error
(undef, "No such project");
398 our $file_name = $cgi->param('f');
399 if (defined $file_name) {
400 if (!validate_pathname
($file_name)) {
401 die_error
(undef, "Invalid file parameter");
405 our $file_parent = $cgi->param('fp');
406 if (defined $file_parent) {
407 if (!validate_pathname
($file_parent)) {
408 die_error
(undef, "Invalid file parent parameter");
412 # parameters which are refnames
413 our $hash = $cgi->param('h');
415 if (!validate_refname
($hash)) {
416 die_error
(undef, "Invalid hash parameter");
420 our $hash_parent = $cgi->param('hp');
421 if (defined $hash_parent) {
422 if (!validate_refname
($hash_parent)) {
423 die_error
(undef, "Invalid hash parent parameter");
427 our $hash_base = $cgi->param('hb');
428 if (defined $hash_base) {
429 if (!validate_refname
($hash_base)) {
430 die_error
(undef, "Invalid hash base parameter");
434 my %allowed_options = (
435 "--no-merges" => [ qw(rss atom log shortlog history) ],
438 our @extra_options = $cgi->param('opt');
439 if (defined @extra_options) {
440 foreach(@extra_options)
442 if (not grep(/^$_$/, keys %allowed_options)) {
443 die_error
(undef, "Invalid option parameter");
445 if (not grep(/^$action$/, @{$allowed_options{$_}})) {
446 die_error
(undef, "Invalid option parameter for this action");
451 our $hash_parent_base = $cgi->param('hpb');
452 if (defined $hash_parent_base) {
453 if (!validate_refname
($hash_parent_base)) {
454 die_error
(undef, "Invalid hash parent base parameter");
459 our $page = $cgi->param('pg');
461 if ($page =~ m/[^0-9]/) {
462 die_error
(undef, "Invalid page parameter");
466 our $searchtype = $cgi->param('st');
467 if (defined $searchtype) {
468 if ($searchtype =~ m/[^a-z]/) {
469 die_error
(undef, "Invalid searchtype parameter");
473 our $searchtext = $cgi->param('s');
475 if (defined $searchtext) {
476 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
477 die_error
(undef, "Invalid search parameter");
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
602 extra_options
=> "opt",
606 hash_parent_base
=> "hpb",
611 snapshot_format
=> "sf",
613 my %mapping = @mapping;
615 $params{'project'} = $project unless exists $params{'project'};
617 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
619 # use PATH_INFO for project name
620 $href .= "/$params{'project'}" if defined $params{'project'};
621 delete $params{'project'};
623 # Summary just uses the project path URL
624 if (defined $params{'action'} && $params{'action'} eq 'summary') {
625 delete $params{'action'};
629 # now encode the parameters explicitly
631 for (my $i = 0; $i < @mapping; $i += 2) {
632 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
633 if (defined $params{$name}) {
634 push @result, $symbol . "=" . esc_param
($params{$name});
637 $href .= "?" . join(';', @result) if scalar @result;
643 ## ======================================================================
644 ## validation, quoting/unquoting and escaping
646 sub validate_pathname
{
647 my $input = shift || return undef;
649 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
650 # at the beginning, at the end, and between slashes.
651 # also this catches doubled slashes
652 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
656 if ($input =~ m!\0!) {
662 sub validate_refname
{
663 my $input = shift || return undef;
665 # textual hashes are O.K.
666 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
669 # it must be correct pathname
670 $input = validate_pathname
($input)
672 # restrictions on ref name according to git-check-ref-format
673 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
679 # decode sequences of octets in utf8 into Perl's internal form,
680 # which is utf-8 with utf8 flag set if needed. gitweb writes out
681 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
685 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
689 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
693 # quote unsafe chars, but keep the slash, even when it's not
694 # correct, but quoted slashes look too horrible in bookmarks
697 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
703 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
706 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
712 # replace invalid utf8 character with SUBSTITUTION sequence
717 $str = to_utf8
($str);
718 $str = $cgi->escapeHTML($str);
719 if ($opts{'-nbsp'}) {
720 $str =~ s/ / /g;
722 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
726 # quote control characters and escape filename to HTML
731 $str = to_utf8
($str);
732 $str = $cgi->escapeHTML($str);
733 if ($opts{'-nbsp'}) {
734 $str =~ s/ / /g;
736 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
740 # Make control characters "printable", using character escape codes (CEC)
743 my %es = ( # character escape codes, aka escape sequences
744 "\t" => '\t', # tab (HT)
745 "\n" => '\n', # line feed (LF)
746 "\r" => '\r', # carrige return (CR)
747 "\f" => '\f', # form feed (FF)
748 "\b" => '\b', # backspace (BS)
749 "\a" => '\a', # alarm (bell) (BEL)
750 "\e" => '\e', # escape (ESC)
751 "\013" => '\v', # vertical tab (VT)
752 "\000" => '\0', # nul character (NUL)
754 my $chr = ( (exists $es{$cntrl})
756 : sprintf('\%03o', ord($cntrl)) );
757 return "<span class=\"cntrl\">$chr</span>";
760 # Alternatively use unicode control pictures codepoints,
761 # Unicode "printable representation" (PR)
764 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
765 return "<span class=\"cntrl\">$chr</span>";
768 # git may return quoted and escaped filenames
774 my %es = ( # character escape codes, aka escape sequences
775 't' => "\t", # tab (HT, TAB)
776 'n' => "\n", # newline (NL)
777 'r' => "\r", # return (CR)
778 'f' => "\f", # form feed (FF)
779 'b' => "\b", # backspace (BS)
780 'a' => "\a", # alarm (bell) (BEL)
781 'e' => "\e", # escape (ESC)
782 'v' => "\013", # vertical tab (VT)
785 if ($seq =~ m/^[0-7]{1,3}$/) {
786 # octal char sequence
787 return chr(oct($seq));
788 } elsif (exists $es{$seq}) {
789 # C escape sequence, aka character escape code
792 # quoted ordinary character
796 if ($str =~ m/^"(.*)"$/) {
799 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
804 # escape tabs (convert tabs to spaces)
808 while ((my $pos = index($line, "\t")) != -1) {
809 if (my $count = (8 - ($pos % 8))) {
810 my $spaces = ' ' x
$count;
811 $line =~ s/\t/$spaces/;
818 sub project_in_list
{
820 my @list = git_get_projects_list
();
821 return @list && scalar(grep { $_->{'path'} eq $project } @list);
824 ## ----------------------------------------------------------------------
825 ## HTML aware string manipulation
830 my $add_len = shift || 10;
832 # allow only $len chars, but don't cut a word if it would fit in $add_len
833 # if it doesn't fit, cut it if it's still longer than the dots we would add
834 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
837 if (length($tail) > 4) {
839 $body =~ s/&[^;]*$//; # remove chopped character entities
844 ## ----------------------------------------------------------------------
845 ## functions returning short strings
847 # CSS class for given age value (in seconds)
853 } elsif ($age < 60*60*2) {
855 } elsif ($age < 60*60*24*2) {
862 # convert age in seconds to "nn units ago" string
867 if ($age > 60*60*24*365*2) {
868 $age_str = (int $age/60/60/24/365);
869 $age_str .= " years ago";
870 } elsif ($age > 60*60*24*(365/12)*2) {
871 $age_str = int $age/60/60/24/(365/12);
872 $age_str .= " months ago";
873 } elsif ($age > 60*60*24*7*2) {
874 $age_str = int $age/60/60/24/7;
875 $age_str .= " weeks ago";
876 } elsif ($age > 60*60*24*2) {
877 $age_str = int $age/60/60/24;
878 $age_str .= " days ago";
879 } elsif ($age > 60*60*2) {
880 $age_str = int $age/60/60;
881 $age_str .= " hours ago";
882 } elsif ($age > 60*2) {
883 $age_str = int $age/60;
884 $age_str .= " min ago";
887 $age_str .= " sec ago";
889 $age_str .= " right now";
895 S_IFINVALID
=> 0030000,
896 S_IFGITLINK
=> 0160000,
899 # submodule/subproject, a commit object reference
903 return (($mode & S_IFMT
) == S_IFGITLINK
)
906 # convert file mode in octal to symbolic file mode string
908 my $mode = oct shift;
910 if (S_ISGITLINK
($mode)) {
912 } elsif (S_ISDIR
($mode & S_IFMT
)) {
914 } elsif (S_ISLNK
($mode)) {
916 } elsif (S_ISREG
($mode)) {
917 # git cares only about the executable bit
918 if ($mode & S_IXUSR
) {
928 # convert file mode in octal to file type string
932 if ($mode !~ m/^[0-7]+$/) {
938 if (S_ISGITLINK
($mode)) {
940 } elsif (S_ISDIR
($mode & S_IFMT
)) {
942 } elsif (S_ISLNK
($mode)) {
944 } elsif (S_ISREG
($mode)) {
951 # convert file mode in octal to file type description string
955 if ($mode !~ m/^[0-7]+$/) {
961 if (S_ISGITLINK
($mode)) {
963 } elsif (S_ISDIR
($mode & S_IFMT
)) {
965 } elsif (S_ISLNK
($mode)) {
967 } elsif (S_ISREG
($mode)) {
968 if ($mode & S_IXUSR
) {
979 ## ----------------------------------------------------------------------
980 ## functions returning short HTML fragments, or transforming HTML fragments
981 ## which don't belong to other sections
983 # format line of commit message.
984 sub format_log_line_html
{
987 $line = esc_html
($line, -nbsp
=>1);
988 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
991 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
992 -class => "text"}, $hash_text);
993 $line =~ s/$hash_text/$link/;
998 # format marker of refs pointing to given object
999 sub format_ref_marker
{
1000 my ($refs, $id) = @_;
1003 if (defined $refs->{$id}) {
1004 foreach my $ref (@{$refs->{$id}}) {
1005 my ($type, $name) = qw();
1006 # e.g. tags/v2.6.11 or heads/next
1007 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1015 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1016 esc_html
($name) . "</span>";
1021 return ' <span class="refs">'. $markers . '</span>';
1027 # format, perhaps shortened and with markers, title line
1028 sub format_subject_html
{
1029 my ($long, $short, $href, $extra) = @_;
1030 $extra = '' unless defined($extra);
1032 if (length($short) < length($long)) {
1033 return $cgi->a({-href
=> $href, -class => "list subject",
1034 -title
=> to_utf8
($long)},
1035 esc_html
($short) . $extra);
1037 return $cgi->a({-href
=> $href, -class => "list subject"},
1038 esc_html
($long) . $extra);
1042 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1043 sub format_git_diff_header_line
{
1045 my $diffinfo = shift;
1046 my ($from, $to) = @_;
1048 if ($diffinfo->{'nparents'}) {
1050 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1051 if ($to->{'href'}) {
1052 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1053 esc_path
($to->{'file'}));
1054 } else { # file was deleted (no href)
1055 $line .= esc_path
($to->{'file'});
1059 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1060 if ($from->{'href'}) {
1061 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1062 'a/' . esc_path
($from->{'file'}));
1063 } else { # file was added (no href)
1064 $line .= 'a/' . esc_path
($from->{'file'});
1067 if ($to->{'href'}) {
1068 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1069 'b/' . esc_path
($to->{'file'}));
1070 } else { # file was deleted
1071 $line .= 'b/' . esc_path
($to->{'file'});
1075 return "<div class=\"diff header\">$line</div>\n";
1078 # format extended diff header line, before patch itself
1079 sub format_extended_diff_header_line
{
1081 my $diffinfo = shift;
1082 my ($from, $to) = @_;
1085 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1086 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1087 esc_path
($from->{'file'}));
1089 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1090 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1091 esc_path
($to->{'file'}));
1093 # match single <mode>
1094 if ($line =~ m/\s(\d{6})$/) {
1095 $line .= '<span class="info"> (' .
1096 file_type_long
($1) .
1100 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1101 # can match only for combined diff
1103 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1104 if ($from->{'href'}[$i]) {
1105 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1107 substr($diffinfo->{'from_id'}[$i],0,7));
1112 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1115 if ($to->{'href'}) {
1116 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1117 substr($diffinfo->{'to_id'},0,7));
1122 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1123 # can match only for ordinary diff
1124 my ($from_link, $to_link);
1125 if ($from->{'href'}) {
1126 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1127 substr($diffinfo->{'from_id'},0,7));
1129 $from_link = '0' x
7;
1131 if ($to->{'href'}) {
1132 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1133 substr($diffinfo->{'to_id'},0,7));
1137 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1138 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1141 return $line . "<br/>\n";
1144 # format from-file/to-file diff header
1145 sub format_diff_from_to_header
{
1146 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1151 #assert($line =~ m/^---/) if DEBUG;
1152 # no extra formatting for "^--- /dev/null"
1153 if (! $diffinfo->{'nparents'}) {
1154 # ordinary (single parent) diff
1155 if ($line =~ m!^--- "?a/!) {
1156 if ($from->{'href'}) {
1158 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1159 esc_path
($from->{'file'}));
1162 esc_path
($from->{'file'});
1165 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1168 # combined diff (merge commit)
1169 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1170 if ($from->{'href'}[$i]) {
1172 $cgi->a({-href
=>href
(action
=>"blobdiff",
1173 hash_parent
=>$diffinfo->{'from_id'}[$i],
1174 hash_parent_base
=>$parents[$i],
1175 file_parent
=>$from->{'file'}[$i],
1176 hash
=>$diffinfo->{'to_id'},
1178 file_name
=>$to->{'file'}),
1180 -title
=>"diff" . ($i+1)},
1183 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1184 esc_path
($from->{'file'}[$i]));
1186 $line = '--- /dev/null';
1188 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1193 #assert($line =~ m/^\+\+\+/) if DEBUG;
1194 # no extra formatting for "^+++ /dev/null"
1195 if ($line =~ m!^\+\+\+ "?b/!) {
1196 if ($to->{'href'}) {
1198 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1199 esc_path
($to->{'file'}));
1202 esc_path
($to->{'file'});
1205 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1210 # create note for patch simplified by combined diff
1211 sub format_diff_cc_simplified
{
1212 my ($diffinfo, @parents) = @_;
1215 $result .= "<div class=\"diff header\">" .
1217 if (!is_deleted
($diffinfo)) {
1218 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1220 hash
=>$diffinfo->{'to_id'},
1221 file_name
=>$diffinfo->{'to_file'}),
1223 esc_path
($diffinfo->{'to_file'}));
1225 $result .= esc_path
($diffinfo->{'to_file'});
1227 $result .= "</div>\n" . # class="diff header"
1228 "<div class=\"diff nodifferences\">" .
1230 "</div>\n"; # class="diff nodifferences"
1235 # format patch (diff) line (not to be used for diff headers)
1236 sub format_diff_line
{
1238 my ($from, $to) = @_;
1239 my $diff_class = "";
1243 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1245 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1246 if ($line =~ m/^\@{3}/) {
1247 $diff_class = " chunk_header";
1248 } elsif ($line =~ m/^\\/) {
1249 $diff_class = " incomplete";
1250 } elsif ($prefix =~ tr/+/+/) {
1251 $diff_class = " add";
1252 } elsif ($prefix =~ tr/-/-/) {
1253 $diff_class = " rem";
1256 # assume ordinary diff
1257 my $char = substr($line, 0, 1);
1259 $diff_class = " add";
1260 } elsif ($char eq '-') {
1261 $diff_class = " rem";
1262 } elsif ($char eq '@') {
1263 $diff_class = " chunk_header";
1264 } elsif ($char eq "\\") {
1265 $diff_class = " incomplete";
1268 $line = untabify
($line);
1269 if ($from && $to && $line =~ m/^\@{2} /) {
1270 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1271 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1273 $from_lines = 0 unless defined $from_lines;
1274 $to_lines = 0 unless defined $to_lines;
1276 if ($from->{'href'}) {
1277 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1278 -class=>"list"}, $from_text);
1280 if ($to->{'href'}) {
1281 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1282 -class=>"list"}, $to_text);
1284 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1285 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1286 return "<div class=\"diff$diff_class\">$line</div>\n";
1287 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1288 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1289 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1291 @from_text = split(' ', $ranges);
1292 for (my $i = 0; $i < @from_text; ++$i) {
1293 ($from_start[$i], $from_nlines[$i]) =
1294 (split(',', substr($from_text[$i], 1)), 0);
1297 $to_text = pop @from_text;
1298 $to_start = pop @from_start;
1299 $to_nlines = pop @from_nlines;
1301 $line = "<span class=\"chunk_info\">$prefix ";
1302 for (my $i = 0; $i < @from_text; ++$i) {
1303 if ($from->{'href'}[$i]) {
1304 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1305 -class=>"list"}, $from_text[$i]);
1307 $line .= $from_text[$i];
1311 if ($to->{'href'}) {
1312 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1313 -class=>"list"}, $to_text);
1317 $line .= " $prefix</span>" .
1318 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1319 return "<div class=\"diff$diff_class\">$line</div>\n";
1321 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1324 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1325 # linked. Pass the hash of the tree/commit to snapshot.
1326 sub format_snapshot_links
{
1328 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1329 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1330 my $num_fmts = @snapshot_fmts;
1331 if ($num_fmts > 1) {
1332 # A parenthesized list of links bearing format names.
1333 # e.g. "snapshot (_tar.gz_ _zip_)"
1334 return "snapshot (" . join(' ', map
1341 }, $known_snapshot_formats{$_}{'display'})
1342 , @snapshot_fmts) . ")";
1343 } elsif ($num_fmts == 1) {
1344 # A single "snapshot" link whose tooltip bears the format name.
1346 my ($fmt) = @snapshot_fmts;
1352 snapshot_format
=>$fmt
1354 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1356 } else { # $num_fmts == 0
1361 ## ----------------------------------------------------------------------
1362 ## git utility subroutines, invoking git commands
1364 # returns path to the core git executable and the --git-dir parameter as list
1366 return $GIT, '--git-dir='.$git_dir;
1369 # returns path to the core git executable and the --git-dir parameter as string
1371 return join(' ', git_cmd
());
1374 # get HEAD ref of given project as hash
1375 sub git_get_head_hash
{
1376 my $project = shift;
1377 my $o_git_dir = $git_dir;
1379 $git_dir = "$projectroot/$project";
1380 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1383 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1387 if (defined $o_git_dir) {
1388 $git_dir = $o_git_dir;
1393 # get type of given object
1397 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1399 close $fd or return;
1404 sub git_get_project_config
{
1405 my ($key, $type) = @_;
1407 return unless ($key);
1408 $key =~ s/^gitweb\.//;
1409 return if ($key =~ m/\W/);
1411 my @x = (git_cmd
(), 'config');
1412 if (defined $type) { push @x, $type; }
1414 push @x, "gitweb.$key";
1420 # get hash of given path at given ref
1421 sub git_get_hash_by_path
{
1423 my $path = shift || return undef;
1428 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1429 or die_error
(undef, "Open git-ls-tree failed");
1431 close $fd or return undef;
1433 if (!defined $line) {
1434 # there is no tree or hash given by $path at $base
1438 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1439 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1440 if (defined $type && $type ne $2) {
1441 # type doesn't match
1447 # get path of entry with given hash at given tree-ish (ref)
1448 # used to get 'from' filename for combined diff (merge commit) for renames
1449 sub git_get_path_by_hash
{
1450 my $base = shift || return;
1451 my $hash = shift || return;
1455 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1457 while (my $line = <$fd>) {
1460 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1461 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1462 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1471 ## ......................................................................
1472 ## git utility functions, directly accessing git repository
1474 sub git_get_project_description
{
1477 open my $fd, "$projectroot/$path/description" or return undef;
1480 if (defined $descr) {
1486 sub git_get_project_url_list
{
1489 open my $fd, "$projectroot/$path/cloneurl" or return;
1490 my @git_project_url_list = map { chomp; $_ } <$fd>;
1493 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1496 sub git_get_projects_list
{
1501 $filter =~ s/\.git$//;
1503 my ($check_forks) = gitweb_check_feature
('forks');
1505 if (-d
$projects_list) {
1506 # search in directory
1507 my $dir = $projects_list . ($filter ? "/$filter" : '');
1508 # remove the trailing "/"
1510 my $pfxlen = length("$dir");
1513 follow_fast
=> 1, # follow symbolic links
1514 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1516 # skip project-list toplevel, if we get it.
1517 return if (m!^[/.]$!);
1518 # only directories can be git repositories
1519 return unless (-d
$_);
1521 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1522 # we check related file in $projectroot
1523 if ($check_forks and $subdir =~ m
#/.#) {
1524 $File::Find
::prune
= 1;
1525 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1526 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1527 $File::Find
::prune
= 1;
1532 } elsif (-f
$projects_list) {
1533 # read from file(url-encoded):
1534 # 'git%2Fgit.git Linus+Torvalds'
1535 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1536 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1538 open my ($fd), $projects_list or return;
1540 while (my $line = <$fd>) {
1542 my ($path, $owner) = split ' ', $line;
1543 $path = unescape
($path);
1544 $owner = unescape
($owner);
1545 if (!defined $path) {
1548 if ($filter ne '') {
1549 # looking for forks;
1550 my $pfx = substr($path, 0, length($filter));
1551 if ($pfx ne $filter) {
1554 my $sfx = substr($path, length($filter));
1555 if ($sfx !~ /^\/.*\
.git
$/) {
1558 } elsif ($check_forks) {
1560 foreach my $filter (keys %paths) {
1561 # looking for forks;
1562 my $pfx = substr($path, 0, length($filter));
1563 if ($pfx ne $filter) {
1566 my $sfx = substr($path, length($filter));
1567 if ($sfx !~ /^\/.*\
.git
$/) {
1570 # is a fork, don't include it in
1575 if (check_export_ok
("$projectroot/$path")) {
1578 owner
=> to_utf8
($owner),
1581 (my $forks_path = $path) =~ s/\.git$//;
1582 $paths{$forks_path}++;
1590 our $gitweb_project_owner = undef;
1591 sub git_get_project_list_from_file
{
1593 return if (defined $gitweb_project_owner);
1595 $gitweb_project_owner = {};
1596 # read from file (url-encoded):
1597 # 'git%2Fgit.git Linus+Torvalds'
1598 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1599 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1600 if (-f
$projects_list) {
1601 open (my $fd , $projects_list);
1602 while (my $line = <$fd>) {
1604 my ($pr, $ow) = split ' ', $line;
1605 $pr = unescape
($pr);
1606 $ow = unescape
($ow);
1607 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1613 sub git_get_project_owner
{
1614 my $project = shift;
1617 return undef unless $project;
1619 if (!defined $gitweb_project_owner) {
1620 git_get_project_list_from_file
();
1623 if (exists $gitweb_project_owner->{$project}) {
1624 $owner = $gitweb_project_owner->{$project};
1626 if (!defined $owner) {
1627 $owner = get_file_owner
("$projectroot/$project");
1633 sub git_get_last_activity
{
1637 $git_dir = "$projectroot/$path";
1638 open($fd, "-|", git_cmd
(), 'for-each-ref',
1639 '--format=%(committer)',
1640 '--sort=-committerdate',
1642 'refs/heads') or return;
1643 my $most_recent = <$fd>;
1644 close $fd or return;
1645 if (defined $most_recent &&
1646 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1648 my $age = time - $timestamp;
1649 return ($age, age_string
($age));
1651 return (undef, undef);
1654 sub git_get_references
{
1655 my $type = shift || "";
1657 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1658 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1659 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1660 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1663 while (my $line = <$fd>) {
1665 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1666 if (defined $refs{$1}) {
1667 push @{$refs{$1}}, $2;
1673 close $fd or return;
1677 sub git_get_rev_name_tags
{
1678 my $hash = shift || return undef;
1680 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1682 my $name_rev = <$fd>;
1685 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1688 # catches also '$hash undefined' output
1693 ## ----------------------------------------------------------------------
1694 ## parse to hash functions
1698 my $tz = shift || "-0000";
1701 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1702 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1703 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1704 $date{'hour'} = $hour;
1705 $date{'minute'} = $min;
1706 $date{'mday'} = $mday;
1707 $date{'day'} = $days[$wday];
1708 $date{'month'} = $months[$mon];
1709 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1710 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1711 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1712 $mday, $months[$mon], $hour ,$min;
1713 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1714 1900+$year, $mon, $mday, $hour ,$min, $sec;
1716 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1717 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1718 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1719 $date{'hour_local'} = $hour;
1720 $date{'minute_local'} = $min;
1721 $date{'tz_local'} = $tz;
1722 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1723 1900+$year, $mon+1, $mday,
1724 $hour, $min, $sec, $tz);
1733 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1734 $tag{'id'} = $tag_id;
1735 while (my $line = <$fd>) {
1737 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1738 $tag{'object'} = $1;
1739 } elsif ($line =~ m/^type (.+)$/) {
1741 } elsif ($line =~ m/^tag (.+)$/) {
1743 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1744 $tag{'author'} = $1;
1747 } elsif ($line =~ m/--BEGIN/) {
1748 push @comment, $line;
1750 } elsif ($line eq "") {
1754 push @comment, <$fd>;
1755 $tag{'comment'} = \
@comment;
1756 close $fd or return;
1757 if (!defined $tag{'name'}) {
1763 sub parse_commit_text
{
1764 my ($commit_text, $withparents) = @_;
1765 my @commit_lines = split '\n', $commit_text;
1768 pop @commit_lines; # Remove '\0'
1770 if (! @commit_lines) {
1774 my $header = shift @commit_lines;
1775 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1778 ($co{'id'}, my @parents) = split ' ', $header;
1779 while (my $line = shift @commit_lines) {
1780 last if $line eq "\n";
1781 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1783 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1785 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1787 $co{'author_epoch'} = $2;
1788 $co{'author_tz'} = $3;
1789 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1790 $co{'author_name'} = $1;
1791 $co{'author_email'} = $2;
1793 $co{'author_name'} = $co{'author'};
1795 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1796 $co{'committer'} = $1;
1797 $co{'committer_epoch'} = $2;
1798 $co{'committer_tz'} = $3;
1799 $co{'committer_name'} = $co{'committer'};
1800 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1801 $co{'committer_name'} = $1;
1802 $co{'committer_email'} = $2;
1804 $co{'committer_name'} = $co{'committer'};
1808 if (!defined $co{'tree'}) {
1811 $co{'parents'} = \
@parents;
1812 $co{'parent'} = $parents[0];
1814 foreach my $title (@commit_lines) {
1817 $co{'title'} = chop_str
($title, 80, 5);
1818 # remove leading stuff of merges to make the interesting part visible
1819 if (length($title) > 50) {
1820 $title =~ s/^Automatic //;
1821 $title =~ s/^merge (of|with) /Merge ... /i;
1822 if (length($title) > 50) {
1823 $title =~ s/(http|rsync):\/\///;
1825 if (length($title) > 50) {
1826 $title =~ s/(master|www|rsync)\.//;
1828 if (length($title) > 50) {
1829 $title =~ s/kernel.org:?//;
1831 if (length($title) > 50) {
1832 $title =~ s/\/pub\/scm//;
1835 $co{'title_short'} = chop_str
($title, 50, 5);
1839 if ($co{'title'} eq "") {
1840 $co{'title'} = $co{'title_short'} = '(no commit message)';
1842 # remove added spaces
1843 foreach my $line (@commit_lines) {
1846 $co{'comment'} = \
@commit_lines;
1848 my $age = time - $co{'committer_epoch'};
1850 $co{'age_string'} = age_string
($age);
1851 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1852 if ($age > 60*60*24*7*2) {
1853 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1854 $co{'age_string_age'} = $co{'age_string'};
1856 $co{'age_string_date'} = $co{'age_string'};
1857 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1863 my ($commit_id) = @_;
1868 open my $fd, "-|", git_cmd
(), "rev-list",
1874 or die_error
(undef, "Open git-rev-list failed");
1875 %co = parse_commit_text
(<$fd>, 1);
1882 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1890 open my $fd, "-|", git_cmd
(), "rev-list",
1892 ($arg ? ($arg) : ()),
1893 ("--max-count=" . $maxcount),
1894 ("--skip=" . $skip),
1898 ($filename ? ($filename) : ())
1899 or die_error
(undef, "Open git-rev-list failed");
1900 while (my $line = <$fd>) {
1901 my %co = parse_commit_text
($line);
1906 return wantarray ? @cos : \
@cos;
1909 # parse ref from ref_file, given by ref_id, with given type
1911 my $ref_file = shift;
1913 my $type = shift || git_get_type
($ref_id);
1916 $ref_item{'type'} = $type;
1917 $ref_item{'id'} = $ref_id;
1918 $ref_item{'epoch'} = 0;
1919 $ref_item{'age'} = "unknown";
1920 if ($type eq "tag") {
1921 my %tag = parse_tag
($ref_id);
1922 $ref_item{'comment'} = $tag{'comment'};
1923 if ($tag{'type'} eq "commit") {
1924 my %co = parse_commit
($tag{'object'});
1925 $ref_item{'epoch'} = $co{'committer_epoch'};
1926 $ref_item{'age'} = $co{'age_string'};
1927 } elsif (defined($tag{'epoch'})) {
1928 my $age = time - $tag{'epoch'};
1929 $ref_item{'epoch'} = $tag{'epoch'};
1930 $ref_item{'age'} = age_string
($age);
1932 $ref_item{'reftype'} = $tag{'type'};
1933 $ref_item{'name'} = $tag{'name'};
1934 $ref_item{'refid'} = $tag{'object'};
1935 } elsif ($type eq "commit"){
1936 my %co = parse_commit
($ref_id);
1937 $ref_item{'reftype'} = "commit";
1938 $ref_item{'name'} = $ref_file;
1939 $ref_item{'title'} = $co{'title'};
1940 $ref_item{'refid'} = $ref_id;
1941 $ref_item{'epoch'} = $co{'committer_epoch'};
1942 $ref_item{'age'} = $co{'age_string'};
1944 $ref_item{'reftype'} = $type;
1945 $ref_item{'name'} = $ref_file;
1946 $ref_item{'refid'} = $ref_id;
1952 # parse line of git-diff-tree "raw" output
1953 sub parse_difftree_raw_line
{
1957 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1958 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1959 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1960 $res{'from_mode'} = $1;
1961 $res{'to_mode'} = $2;
1962 $res{'from_id'} = $3;
1964 $res{'status'} = $5;
1965 $res{'similarity'} = $6;
1966 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1967 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1969 $res{'file'} = unquote
($7);
1972 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1973 # combined diff (for merge commit)
1974 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1975 $res{'nparents'} = length($1);
1976 $res{'from_mode'} = [ split(' ', $2) ];
1977 $res{'to_mode'} = pop @{$res{'from_mode'}};
1978 $res{'from_id'} = [ split(' ', $3) ];
1979 $res{'to_id'} = pop @{$res{'from_id'}};
1980 $res{'status'} = [ split('', $4) ];
1981 $res{'to_file'} = unquote
($5);
1983 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1984 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1985 $res{'commit'} = $1;
1988 return wantarray ? %res : \
%res;
1991 # parse line of git-ls-tree output
1992 sub parse_ls_tree_line
($;%) {
1997 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1998 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2006 $res{'name'} = unquote
($4);
2009 return wantarray ? %res : \
%res;
2012 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2013 sub parse_from_to_diffinfo
{
2014 my ($diffinfo, $from, $to, @parents) = @_;
2016 if ($diffinfo->{'nparents'}) {
2018 $from->{'file'} = [];
2019 $from->{'href'} = [];
2020 fill_from_file_info
($diffinfo, @parents)
2021 unless exists $diffinfo->{'from_file'};
2022 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2023 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2024 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2025 $from->{'href'}[$i] = href
(action
=>"blob",
2026 hash_base
=>$parents[$i],
2027 hash
=>$diffinfo->{'from_id'}[$i],
2028 file_name
=>$from->{'file'}[$i]);
2030 $from->{'href'}[$i] = undef;
2034 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2035 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2036 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2037 hash
=>$diffinfo->{'from_id'},
2038 file_name
=>$from->{'file'});
2040 delete $from->{'href'};
2044 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2045 if (!is_deleted
($diffinfo)) { # file exists in result
2046 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2047 hash
=>$diffinfo->{'to_id'},
2048 file_name
=>$to->{'file'});
2050 delete $to->{'href'};
2054 ## ......................................................................
2055 ## parse to array of hashes functions
2057 sub git_get_heads_list
{
2061 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2062 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2063 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2066 while (my $line = <$fd>) {
2070 my ($refinfo, $committerinfo) = split(/\0/, $line);
2071 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2072 my ($committer, $epoch, $tz) =
2073 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2074 $name =~ s!^refs/heads/!!;
2076 $ref_item{'name'} = $name;
2077 $ref_item{'id'} = $hash;
2078 $ref_item{'title'} = $title || '(no commit message)';
2079 $ref_item{'epoch'} = $epoch;
2081 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2083 $ref_item{'age'} = "unknown";
2086 push @headslist, \
%ref_item;
2090 return wantarray ? @headslist : \
@headslist;
2093 sub git_get_tags_list
{
2097 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2098 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2099 '--format=%(objectname) %(objecttype) %(refname) '.
2100 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2103 while (my $line = <$fd>) {
2107 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2108 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2109 my ($creator, $epoch, $tz) =
2110 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2111 $name =~ s!^refs/tags/!!;
2113 $ref_item{'type'} = $type;
2114 $ref_item{'id'} = $id;
2115 $ref_item{'name'} = $name;
2116 if ($type eq "tag") {
2117 $ref_item{'subject'} = $title;
2118 $ref_item{'reftype'} = $reftype;
2119 $ref_item{'refid'} = $refid;
2121 $ref_item{'reftype'} = $type;
2122 $ref_item{'refid'} = $id;
2125 if ($type eq "tag" || $type eq "commit") {
2126 $ref_item{'epoch'} = $epoch;
2128 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2130 $ref_item{'age'} = "unknown";
2134 push @tagslist, \
%ref_item;
2138 return wantarray ? @tagslist : \
@tagslist;
2141 ## ----------------------------------------------------------------------
2142 ## filesystem-related functions
2144 sub get_file_owner
{
2147 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2148 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2149 if (!defined $gcos) {
2153 $owner =~ s/[,;].*$//;
2154 return to_utf8
($owner);
2157 ## ......................................................................
2158 ## mimetype related functions
2160 sub mimetype_guess_file
{
2161 my $filename = shift;
2162 my $mimemap = shift;
2163 -r
$mimemap or return undef;
2166 open(MIME
, $mimemap) or return undef;
2168 next if m/^#/; # skip comments
2169 my ($mime, $exts) = split(/\t+/);
2170 if (defined $exts) {
2171 my @exts = split(/\s+/, $exts);
2172 foreach my $ext (@exts) {
2173 $mimemap{$ext} = $mime;
2179 $filename =~ /\.([^.]*)$/;
2180 return $mimemap{$1};
2183 sub mimetype_guess
{
2184 my $filename = shift;
2186 $filename =~ /\./ or return undef;
2188 if ($mimetypes_file) {
2189 my $file = $mimetypes_file;
2190 if ($file !~ m!^/!) { # if it is relative path
2191 # it is relative to project
2192 $file = "$projectroot/$project/$file";
2194 $mime = mimetype_guess_file
($filename, $file);
2196 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2202 my $filename = shift;
2205 my $mime = mimetype_guess
($filename);
2206 $mime and return $mime;
2210 return $default_blob_plain_mimetype unless $fd;
2213 return 'text/plain' .
2214 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2215 } elsif (! $filename) {
2216 return 'application/octet-stream';
2217 } elsif ($filename =~ m/\.png$/i) {
2219 } elsif ($filename =~ m/\.gif$/i) {
2221 } elsif ($filename =~ m/\.jpe?g$/i) {
2222 return 'image/jpeg';
2224 return 'application/octet-stream';
2228 ## ======================================================================
2229 ## functions printing HTML: header, footer, error page
2231 sub git_header_html
{
2232 my $status = shift || "200 OK";
2233 my $expires = shift;
2235 my $title = "$site_name";
2236 if (defined $project) {
2237 $title .= " - " . to_utf8
($project);
2238 if (defined $action) {
2239 $title .= "/$action";
2240 if (defined $file_name) {
2241 $title .= " - " . esc_path
($file_name);
2242 if ($action eq "tree" && $file_name !~ m
|/$|) {
2249 # require explicit support from the UA if we are to send the page as
2250 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2251 # we have to do this because MSIE sometimes globs '*/*', pretending to
2252 # support xhtml+xml but choking when it gets what it asked for.
2253 if (defined $cgi->http('HTTP_ACCEPT') &&
2254 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2255 $cgi->Accept('application/xhtml+xml') != 0) {
2256 $content_type = 'application/xhtml+xml';
2258 $content_type = 'text/html';
2260 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2261 -status
=> $status, -expires
=> $expires);
2262 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2264 <?xml version="1.0" encoding="utf-8"?>
2265 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2266 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2267 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2268 <!-- git core binaries version $git_version -->
2270 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2271 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2272 <meta name="robots" content="index, nofollow"/>
2273 <title>$title</title>
2275 # print out each stylesheet that exist
2276 if (defined $stylesheet) {
2277 #provides backwards capability for those people who define style sheet in a config file
2278 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2280 foreach my $stylesheet (@stylesheets) {
2281 next unless $stylesheet;
2282 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2285 if (defined $project) {
2286 printf('<link rel="alternate" title="%s log RSS feed" '.
2287 'href="%s" type="application/rss+xml" />'."\n",
2288 esc_param
($project), href
(action
=>"rss"));
2289 printf('<link rel="alternate" title="%s log Atom feed" '.
2290 'href="%s" type="application/atom+xml" />'."\n",
2291 esc_param
($project), href
(action
=>"atom"));
2293 printf('<link rel="alternate" title="%s projects list" '.
2294 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2295 $site_name, href
(project
=>undef, action
=>"project_index"));
2296 printf('<link rel="alternate" title="%s projects feeds" '.
2297 'href="%s" type="text/x-opml"/>'."\n",
2298 $site_name, href
(project
=>undef, action
=>"opml"));
2300 if (defined $favicon) {
2301 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2307 if (-f
$site_header) {
2308 open (my $fd, $site_header);
2313 print "<div class=\"page_header\">\n" .
2314 $cgi->a({-href
=> esc_url
($logo_url),
2315 -title
=> $logo_label},
2316 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2317 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2318 if (defined $project) {
2319 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2320 if (defined $action) {
2327 my ($have_search) = gitweb_check_feature
('search');
2328 if ((defined $project) && ($have_search)) {
2329 if (!defined $searchtext) {
2333 if (defined $hash_base) {
2334 $search_hash = $hash_base;
2335 } elsif (defined $hash) {
2336 $search_hash = $hash;
2338 $search_hash = "HEAD";
2340 my $action = $my_uri;
2341 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2342 if ($use_pathinfo) {
2343 $action .= "/$project";
2345 $cgi->param("p", $project);
2347 $cgi->param("a", "search");
2348 $cgi->param("h", $search_hash);
2349 print $cgi->startform(-method => "get", -action
=> $action) .
2350 "<div class=\"search\">\n" .
2351 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2352 $cgi->hidden(-name
=> "a") . "\n" .
2353 $cgi->hidden(-name
=> "h") . "\n" .
2354 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2355 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2356 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2358 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2360 $cgi->end_form() . "\n";
2364 sub git_footer_html
{
2365 print "<div class=\"page_footer\">\n";
2366 if (defined $project) {
2367 my $descr = git_get_project_description
($project);
2368 if (defined $descr) {
2369 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2371 print $cgi->a({-href
=> href
(action
=>"rss"),
2372 -class => "rss_logo"}, "RSS") . " ";
2373 print $cgi->a({-href
=> href
(action
=>"atom"),
2374 -class => "rss_logo"}, "Atom") . "\n";
2376 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2377 -class => "rss_logo"}, "OPML") . " ";
2378 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2379 -class => "rss_logo"}, "TXT") . "\n";
2383 if (-f
$site_footer) {
2384 open (my $fd, $site_footer);
2394 my $status = shift || "403 Forbidden";
2395 my $error = shift || "Malformed query, file missing or permission denied";
2397 git_header_html
($status);
2399 <div class="page_body">
2409 ## ----------------------------------------------------------------------
2410 ## functions printing or outputting HTML: navigation
2412 sub git_print_page_nav
{
2413 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2414 $extra = '' if !defined $extra; # pager or formats
2416 my @navs = qw(summary shortlog log commit commitdiff tree);
2418 @navs = grep { $_ ne $suppress } @navs;
2421 my %arg = map { $_ => {action
=>$_} } @navs;
2422 if (defined $head) {
2423 for (qw(commit commitdiff)) {
2424 $arg{$_}{'hash'} = $head;
2426 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2427 for (qw(shortlog log)) {
2428 $arg{$_}{'hash'} = $head;
2432 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2433 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2435 print "<div class=\"page_nav\">\n" .
2437 map { $_ eq $current ?
2438 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2440 print "<br/>\n$extra<br/>\n" .
2444 sub format_paging_nav
{
2445 my ($action, $hash, $head, $page, $nrevs) = @_;
2449 if ($hash ne $head || $page) {
2450 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2452 $paging_nav .= "HEAD";
2456 $paging_nav .= " ⋅ " .
2457 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2458 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2460 $paging_nav .= " ⋅ prev";
2463 if ($nrevs >= (100 * ($page+1)-1)) {
2464 $paging_nav .= " ⋅ " .
2465 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2466 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2468 $paging_nav .= " ⋅ next";
2474 ## ......................................................................
2475 ## functions printing or outputting HTML: div
2477 sub git_print_header_div
{
2478 my ($action, $title, $hash, $hash_base) = @_;
2481 $args{'action'} = $action;
2482 $args{'hash'} = $hash if $hash;
2483 $args{'hash_base'} = $hash_base if $hash_base;
2485 print "<div class=\"header\">\n" .
2486 $cgi->a({-href
=> href
(%args), -class => "title"},
2487 $title ? $title : $action) .
2491 #sub git_print_authorship (\%) {
2492 sub git_print_authorship
{
2495 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2496 print "<div class=\"author_date\">" .
2497 esc_html
($co->{'author_name'}) .
2499 if ($ad{'hour_local'} < 6) {
2500 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2501 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2503 printf(" (%02d:%02d %s)",
2504 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2509 sub git_print_page_path
{
2515 print "<div class=\"page_path\">";
2516 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2517 -title
=> 'tree root'}, to_utf8
("[$project]"));
2519 if (defined $name) {
2520 my @dirname = split '/', $name;
2521 my $basename = pop @dirname;
2524 foreach my $dir (@dirname) {
2525 $fullname .= ($fullname ? '/' : '') . $dir;
2526 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2528 -title
=> $fullname}, esc_path
($dir));
2531 if (defined $type && $type eq 'blob') {
2532 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2534 -title
=> $name}, esc_path
($basename));
2535 } elsif (defined $type && $type eq 'tree') {
2536 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2538 -title
=> $name}, esc_path
($basename));
2541 print esc_path
($basename);
2544 print "<br/></div>\n";
2547 # sub git_print_log (\@;%) {
2548 sub git_print_log
($;%) {
2552 if ($opts{'-remove_title'}) {
2553 # remove title, i.e. first line of log
2556 # remove leading empty lines
2557 while (defined $log->[0] && $log->[0] eq "") {
2564 foreach my $line (@$log) {
2565 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2568 if (! $opts{'-remove_signoff'}) {
2569 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2572 # remove signoff lines
2579 # print only one empty line
2580 # do not print empty line after signoff
2582 next if ($empty || $signoff);
2588 print format_log_line_html
($line) . "<br/>\n";
2591 if ($opts{'-final_empty_line'}) {
2592 # end with single empty line
2593 print "<br/>\n" unless $empty;
2597 # return link target (what link points to)
2598 sub git_get_link_target
{
2603 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2607 $link_target = <$fd>;
2612 return $link_target;
2615 # given link target, and the directory (basedir) the link is in,
2616 # return target of link relative to top directory (top tree);
2617 # return undef if it is not possible (including absolute links).
2618 sub normalize_link_target
{
2619 my ($link_target, $basedir, $hash_base) = @_;
2621 # we can normalize symlink target only if $hash_base is provided
2622 return unless $hash_base;
2624 # absolute symlinks (beginning with '/') cannot be normalized
2625 return if (substr($link_target, 0, 1) eq '/');
2627 # normalize link target to path from top (root) tree (dir)
2630 $path = $basedir . '/' . $link_target;
2632 # we are in top (root) tree (dir)
2633 $path = $link_target;
2636 # remove //, /./, and /../
2638 foreach my $part (split('/', $path)) {
2639 # discard '.' and ''
2640 next if (!$part || $part eq '.');
2642 if ($part eq '..') {
2646 # link leads outside repository (outside top dir)
2650 push @path_parts, $part;
2653 $path = join('/', @path_parts);
2658 # print tree entry (row of git_tree), but without encompassing <tr> element
2659 sub git_print_tree_entry
{
2660 my ($t, $basedir, $hash_base, $have_blame) = @_;
2663 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2665 # The format of a table row is: mode list link. Where mode is
2666 # the mode of the entry, list is the name of the entry, an href,
2667 # and link is the action links of the entry.
2669 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2670 if ($t->{'type'} eq "blob") {
2671 print "<td class=\"list\">" .
2672 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2673 file_name
=>"$basedir$t->{'name'}", %base_key),
2674 -class => "list"}, esc_path
($t->{'name'}));
2675 if (S_ISLNK
(oct $t->{'mode'})) {
2676 my $link_target = git_get_link_target
($t->{'hash'});
2678 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2679 if (defined $norm_target) {
2681 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2682 file_name
=>$norm_target),
2683 -title
=> $norm_target}, esc_path
($link_target));
2685 print " -> " . esc_path
($link_target);
2690 print "<td class=\"link\">";
2691 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2692 file_name
=>"$basedir$t->{'name'}", %base_key)},
2696 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2697 file_name
=>"$basedir$t->{'name'}", %base_key)},
2700 if (defined $hash_base) {
2702 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2703 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2707 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2708 file_name
=>"$basedir$t->{'name'}")},
2712 } elsif ($t->{'type'} eq "tree") {
2713 print "<td class=\"list\">";
2714 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2715 file_name
=>"$basedir$t->{'name'}", %base_key)},
2716 esc_path
($t->{'name'}));
2718 print "<td class=\"link\">";
2719 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2720 file_name
=>"$basedir$t->{'name'}", %base_key)},
2722 if (defined $hash_base) {
2724 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2725 file_name
=>"$basedir$t->{'name'}")},
2730 # unknown object: we can only present history for it
2731 # (this includes 'commit' object, i.e. submodule support)
2732 print "<td class=\"list\">" .
2733 esc_path
($t->{'name'}) .
2735 print "<td class=\"link\">";
2736 if (defined $hash_base) {
2737 print $cgi->a({-href
=> href
(action
=>"history",
2738 hash_base
=>$hash_base,
2739 file_name
=>"$basedir$t->{'name'}")},
2746 ## ......................................................................
2747 ## functions printing large fragments of HTML
2749 sub fill_from_file_info
{
2750 my ($diff, @parents) = @_;
2752 $diff->{'from_file'} = [ ];
2753 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2754 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2755 if ($diff->{'status'}[$i] eq 'R' ||
2756 $diff->{'status'}[$i] eq 'C') {
2757 $diff->{'from_file'}[$i] =
2758 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2765 # parameters can be strings, or references to arrays of strings
2769 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2770 for (my $i = 0; $i < @$a; ++$i) {
2771 return 0 unless ($a->[$i] eq $b->[$i]);
2774 } elsif (!ref($a) && !ref($b)) {
2782 my $diffinfo = shift;
2784 return $diffinfo->{'to_id'} eq ('0' x
40);
2787 sub git_difftree_body
{
2788 my ($difftree, $hash, @parents) = @_;
2789 my ($parent) = $parents[0];
2790 my ($have_blame) = gitweb_check_feature
('blame');
2791 print "<div class=\"list_head\">\n";
2792 if ($#{$difftree} > 10) {
2793 print(($#{$difftree} + 1) . " files changed:\n");
2797 print "<table class=\"" .
2798 (@parents > 1 ? "combined " : "") .
2801 # header only for combined diff in 'commitdiff' view
2802 my $has_header = @parents > 1 && $action eq 'commitdiff';
2805 print "<thead><tr>\n" .
2806 "<th></th><th></th>\n"; # filename, patchN link
2807 for (my $i = 0; $i < @parents; $i++) {
2808 my $par = $parents[$i];
2810 $cgi->a({-href
=> href
(action
=>"commitdiff",
2811 hash
=>$hash, hash_parent
=>$par),
2812 -title
=> 'commitdiff to parent number ' .
2813 ($i+1) . ': ' . substr($par,0,7)},
2817 print "</tr></thead>\n<tbody>\n";
2822 foreach my $line (@{$difftree}) {
2824 if (ref($line) eq "HASH") {
2825 # pre-parsed (or generated by hand)
2828 $diff = parse_difftree_raw_line
($line);
2832 print "<tr class=\"dark\">\n";
2834 print "<tr class=\"light\">\n";
2838 if (exists $diff->{'nparents'}) { # combined diff
2840 fill_from_file_info
($diff, @parents)
2841 unless exists $diff->{'from_file'};
2843 if (!is_deleted
($diff)) {
2844 # file exists in the result (child) commit
2846 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2847 file_name
=>$diff->{'to_file'},
2849 -class => "list"}, esc_path
($diff->{'to_file'})) .
2853 esc_path
($diff->{'to_file'}) .
2857 if ($action eq 'commitdiff') {
2860 print "<td class=\"link\">" .
2861 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2866 my $has_history = 0;
2867 my $not_deleted = 0;
2868 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2869 my $hash_parent = $parents[$i];
2870 my $from_hash = $diff->{'from_id'}[$i];
2871 my $from_path = $diff->{'from_file'}[$i];
2872 my $status = $diff->{'status'}[$i];
2874 $has_history ||= ($status ne 'A');
2875 $not_deleted ||= ($status ne 'D');
2877 if ($status eq 'A') {
2878 print "<td class=\"link\" align=\"right\"> | </td>\n";
2879 } elsif ($status eq 'D') {
2880 print "<td class=\"link\">" .
2881 $cgi->a({-href
=> href
(action
=>"blob",
2884 file_name
=>$from_path)},
2888 if ($diff->{'to_id'} eq $from_hash) {
2889 print "<td class=\"link nochange\">";
2891 print "<td class=\"link\">";
2893 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2894 hash
=>$diff->{'to_id'},
2895 hash_parent
=>$from_hash,
2897 hash_parent_base
=>$hash_parent,
2898 file_name
=>$diff->{'to_file'},
2899 file_parent
=>$from_path)},
2905 print "<td class=\"link\">";
2907 print $cgi->a({-href
=> href
(action
=>"blob",
2908 hash
=>$diff->{'to_id'},
2909 file_name
=>$diff->{'to_file'},
2912 print " | " if ($has_history);
2915 print $cgi->a({-href
=> href
(action
=>"history",
2916 file_name
=>$diff->{'to_file'},
2923 next; # instead of 'else' clause, to avoid extra indent
2925 # else ordinary diff
2927 my ($to_mode_oct, $to_mode_str, $to_file_type);
2928 my ($from_mode_oct, $from_mode_str, $from_file_type);
2929 if ($diff->{'to_mode'} ne ('0' x
6)) {
2930 $to_mode_oct = oct $diff->{'to_mode'};
2931 if (S_ISREG
($to_mode_oct)) { # only for regular file
2932 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2934 $to_file_type = file_type
($diff->{'to_mode'});
2936 if ($diff->{'from_mode'} ne ('0' x
6)) {
2937 $from_mode_oct = oct $diff->{'from_mode'};
2938 if (S_ISREG
($to_mode_oct)) { # only for regular file
2939 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2941 $from_file_type = file_type
($diff->{'from_mode'});
2944 if ($diff->{'status'} eq "A") { # created
2945 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2946 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2947 $mode_chng .= "]</span>";
2949 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2950 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2951 -class => "list"}, esc_path
($diff->{'file'}));
2953 print "<td>$mode_chng</td>\n";
2954 print "<td class=\"link\">";
2955 if ($action eq 'commitdiff') {
2958 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2961 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2962 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2966 } elsif ($diff->{'status'} eq "D") { # deleted
2967 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2969 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2970 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2971 -class => "list"}, esc_path
($diff->{'file'}));
2973 print "<td>$mode_chng</td>\n";
2974 print "<td class=\"link\">";
2975 if ($action eq 'commitdiff') {
2978 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2981 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2982 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2985 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2986 file_name
=>$diff->{'file'})},
2989 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2990 file_name
=>$diff->{'file'})},
2994 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2995 my $mode_chnge = "";
2996 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2997 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2998 if ($from_file_type ne $to_file_type) {
2999 $mode_chnge .= " from $from_file_type to $to_file_type";
3001 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3002 if ($from_mode_str && $to_mode_str) {
3003 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3004 } elsif ($to_mode_str) {
3005 $mode_chnge .= " mode: $to_mode_str";
3008 $mode_chnge .= "]</span>\n";
3011 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3012 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3013 -class => "list"}, esc_path
($diff->{'file'}));
3015 print "<td>$mode_chnge</td>\n";
3016 print "<td class=\"link\">";
3017 if ($action eq 'commitdiff') {
3020 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3022 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3023 # "commit" view and modified file (not onlu mode changed)
3024 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3025 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3026 hash_base
=>$hash, hash_parent_base
=>$parent,
3027 file_name
=>$diff->{'file'})},
3031 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3032 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3035 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3036 file_name
=>$diff->{'file'})},
3039 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3040 file_name
=>$diff->{'file'})},
3044 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3045 my %status_name = ('R' => 'moved', 'C' => 'copied');
3046 my $nstatus = $status_name{$diff->{'status'}};
3048 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3049 # mode also for directories, so we cannot use $to_mode_str
3050 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3053 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3054 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3055 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3056 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3057 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3058 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3059 -class => "list"}, esc_path
($diff->{'from_file'})) .
3060 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3061 "<td class=\"link\">";
3062 if ($action eq 'commitdiff') {
3065 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3067 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3068 # "commit" view and modified file (not only pure rename or copy)
3069 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3070 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3071 hash_base
=>$hash, hash_parent_base
=>$parent,
3072 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3076 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3077 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3080 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3081 file_name
=>$diff->{'to_file'})},
3084 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3085 file_name
=>$diff->{'to_file'})},
3089 } # we should not encounter Unmerged (U) or Unknown (X) status
3092 print "</tbody>" if $has_header;
3096 sub git_patchset_body
{
3097 my ($fd, $difftree, $hash, @hash_parents) = @_;
3098 my ($hash_parent) = $hash_parents[0];
3101 my $patch_number = 0;
3106 print "<div class=\"patchset\">\n";
3108 # skip to first patch
3109 while ($patch_line = <$fd>) {
3112 last if ($patch_line =~ m/^diff /);
3116 while ($patch_line) {
3118 my ($from_id, $to_id);
3121 #assert($patch_line =~ m/^diff /) if DEBUG;
3122 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3124 push @diff_header, $patch_line;
3126 # extended diff header
3128 while ($patch_line = <$fd>) {
3131 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3133 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3136 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3137 $from_id = [ split(',', $1) ];
3141 push @diff_header, $patch_line;
3143 my $last_patch_line = $patch_line;
3145 # check if current patch belong to current raw line
3146 # and parse raw git-diff line if needed
3147 if (defined $diffinfo &&
3148 defined $from_id && defined $to_id &&
3149 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3150 $diffinfo->{'to_id'} eq $to_id) {
3151 # this is continuation of a split patch
3152 print "<div class=\"patch cont\">\n";
3154 # advance raw git-diff output if needed
3155 $patch_idx++ if defined $diffinfo;
3157 # compact combined diff output can have some patches skipped
3158 # find which patch (using pathname of result) we are at now
3160 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3165 # read and prepare patch information
3166 if (ref($difftree->[$patch_idx]) eq "HASH") {
3167 # pre-parsed (or generated by hand)
3168 $diffinfo = $difftree->[$patch_idx];
3170 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3173 # check if current raw line has no patch (it got simplified)
3174 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3175 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3176 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3177 "</div>\n"; # class="patch"
3182 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3183 $patch_idx > $#$difftree);
3184 # modifies %from, %to hashes
3185 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3186 if ($diffinfo->{'nparents'}) {
3190 fill_from_file_info
($diffinfo, @hash_parents)
3191 unless exists $diffinfo->{'from_file'};
3192 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3193 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3194 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3195 $from{'href'}[$i] = href
(action
=>"blob",
3196 hash_base
=>$hash_parents[$i],
3197 hash
=>$diffinfo->{'from_id'}[$i],
3198 file_name
=>$from{'file'}[$i]);
3200 $from{'href'}[$i] = undef;
3204 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3205 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3206 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3207 hash
=>$diffinfo->{'from_id'},
3208 file_name
=>$from{'file'});
3210 delete $from{'href'};
3214 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3215 if (!is_deleted
($diffinfo)) { # file exists in result
3216 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3217 hash
=>$diffinfo->{'to_id'},
3218 file_name
=>$to{'file'});
3222 # this is first patch for raw difftree line with $patch_idx index
3223 # we index @$difftree array from 0, but number patches from 1
3224 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3227 # print "git diff" header
3228 $patch_line = shift @diff_header;
3229 print format_git_diff_header_line
($patch_line, $diffinfo,
3232 # print extended diff header
3233 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3235 foreach $patch_line (@diff_header) {
3236 print format_extended_diff_header_line
($patch_line, $diffinfo,
3239 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3241 # from-file/to-file diff header
3242 $patch_line = $last_patch_line;
3243 if (! $patch_line) {
3244 print "</div>\n"; # class="patch"
3247 next PATCH
if ($patch_line =~ m/^diff /);
3248 #assert($patch_line =~ m/^---/) if DEBUG;
3249 #assert($patch_line eq $last_patch_line) if DEBUG;
3251 $patch_line = <$fd>;
3253 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3255 print format_diff_from_to_header
($last_patch_line, $patch_line,
3256 $diffinfo, \
%from, \
%to,
3261 while ($patch_line = <$fd>) {
3264 next PATCH
if ($patch_line =~ m/^diff /);
3266 print format_diff_line
($patch_line, \
%from, \
%to);
3270 print "</div>\n"; # class="patch"
3273 # for compact combined (--cc) format, with chunk and patch simpliciaction
3274 # patchset might be empty, but there might be unprocessed raw lines
3275 for ($patch_idx++ if $patch_number > 0;
3276 $patch_idx < @$difftree;
3278 # read and prepare patch information
3279 if (ref($difftree->[$patch_idx]) eq "HASH") {
3280 # pre-parsed (or generated by hand)
3281 $diffinfo = $difftree->[$patch_idx];
3283 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3286 # generate anchor for "patch" links in difftree / whatchanged part
3287 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3288 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3289 "</div>\n"; # class="patch"
3294 if ($patch_number == 0) {
3295 if (@hash_parents > 1) {
3296 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3298 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3302 print "</div>\n"; # class="patchset"
3305 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3307 sub git_project_list_body
{
3308 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3310 my ($check_forks) = gitweb_check_feature
('forks');
3313 foreach my $pr (@$projlist) {
3314 my (@aa) = git_get_last_activity
($pr->{'path'});
3318 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3319 if (!defined $pr->{'descr'}) {
3320 my $descr = git_get_project_description
($pr->{'path'}) || "";
3321 $pr->{'descr_long'} = to_utf8
($descr);
3322 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3324 if (!defined $pr->{'owner'}) {
3325 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3328 my $pname = $pr->{'path'};
3329 if (($pname =~ s/\.git$//) &&
3330 ($pname !~ /\/$/) &&
3331 (-d
"$projectroot/$pname")) {
3332 $pr->{'forks'} = "-d $projectroot/$pname";
3338 push @projects, $pr;
3341 $order ||= $default_projects_order;
3342 $from = 0 unless defined $from;
3343 $to = $#projects if (!defined $to || $#projects < $to);
3345 print "<table class=\"project_list\">\n";
3346 unless ($no_header) {
3349 print "<th></th>\n";
3351 if ($order eq "project") {
3352 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3353 print "<th>Project</th>\n";
3356 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3357 -class => "header"}, "Project") .
3360 if ($order eq "descr") {
3361 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3362 print "<th>Description</th>\n";
3365 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3366 -class => "header"}, "Description") .
3369 if ($order eq "owner") {
3370 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3371 print "<th>Owner</th>\n";
3374 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3375 -class => "header"}, "Owner") .
3378 if ($order eq "age") {
3379 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3380 print "<th>Last Change</th>\n";
3383 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3384 -class => "header"}, "Last Change") .
3387 print "<th></th>\n" .
3391 for (my $i = $from; $i <= $to; $i++) {
3392 my $pr = $projects[$i];
3394 print "<tr class=\"dark\">\n";
3396 print "<tr class=\"light\">\n";
3401 if ($pr->{'forks'}) {
3402 print "<!-- $pr->{'forks'} -->\n";
3403 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3407 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3408 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3409 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3410 -class => "list", -title
=> $pr->{'descr_long'}},
3411 esc_html
($pr->{'descr'})) . "</td>\n" .
3412 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3413 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3414 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3415 "<td class=\"link\">" .
3416 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3417 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3418 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3419 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3420 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3424 if (defined $extra) {
3427 print "<td></td>\n";
3429 print "<td colspan=\"5\">$extra</td>\n" .
3435 sub git_shortlog_body
{
3436 # uses global variable $project
3437 my ($commitlist, $from, $to, $refs, $extra) = @_;
3439 $from = 0 unless defined $from;
3440 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3442 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3444 for (my $i = $from; $i <= $to; $i++) {
3445 my %co = %{$commitlist->[$i]};
3446 my $commit = $co{'id'};
3447 my $ref = format_ref_marker
($refs, $commit);
3449 print "<tr class=\"dark\">\n";
3451 print "<tr class=\"light\">\n";
3454 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3455 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3456 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3458 print format_subject_html
($co{'title'}, $co{'title_short'},
3459 href
(action
=>"commit", hash
=>$commit), $ref);
3461 "<td class=\"link\">" .
3462 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3463 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3464 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3465 my $snapshot_links = format_snapshot_links
($commit);
3466 if (defined $snapshot_links) {
3467 print " | " . $snapshot_links;
3472 if (defined $extra) {
3474 "<td colspan=\"4\">$extra</td>\n" .
3480 sub git_history_body
{
3481 # Warning: assumes constant type (blob or tree) during history
3482 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3484 $from = 0 unless defined $from;
3485 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3487 print "<table class=\"history\" cellspacing=\"0\">\n";
3489 for (my $i = $from; $i <= $to; $i++) {
3490 my %co = %{$commitlist->[$i]};
3494 my $commit = $co{'id'};
3496 my $ref = format_ref_marker
($refs, $commit);
3499 print "<tr class=\"dark\">\n";
3501 print "<tr class=\"light\">\n";
3504 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3505 # shortlog uses chop_str($co{'author_name'}, 10)
3506 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3508 # originally git_history used chop_str($co{'title'}, 50)
3509 print format_subject_html
($co{'title'}, $co{'title_short'},
3510 href
(action
=>"commit", hash
=>$commit), $ref);
3512 "<td class=\"link\">" .
3513 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3514 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3516 if ($ftype eq 'blob') {
3517 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3518 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3519 if (defined $blob_current && defined $blob_parent &&
3520 $blob_current ne $blob_parent) {
3522 $cgi->a({-href
=> href
(action
=>"blobdiff",
3523 hash
=>$blob_current, hash_parent
=>$blob_parent,
3524 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3525 file_name
=>$file_name)},
3532 if (defined $extra) {
3534 "<td colspan=\"4\">$extra</td>\n" .
3541 # uses global variable $project
3542 my ($taglist, $from, $to, $extra) = @_;
3543 $from = 0 unless defined $from;
3544 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3546 print "<table class=\"tags\" cellspacing=\"0\">\n";
3548 for (my $i = $from; $i <= $to; $i++) {
3549 my $entry = $taglist->[$i];
3551 my $comment = $tag{'subject'};
3553 if (defined $comment) {
3554 $comment_short = chop_str
($comment, 30, 5);
3557 print "<tr class=\"dark\">\n";
3559 print "<tr class=\"light\">\n";
3562 if (defined $tag{'age'}) {
3563 print "<td><i>$tag{'age'}</i></td>\n";
3565 print "<td></td>\n";
3568 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3569 -class => "list name"}, esc_html
($tag{'name'})) .
3572 if (defined $comment) {
3573 print format_subject_html
($comment, $comment_short,
3574 href
(action
=>"tag", hash
=>$tag{'id'}));
3577 "<td class=\"selflink\">";
3578 if ($tag{'type'} eq "tag") {
3579 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3584 "<td class=\"link\">" . " | " .
3585 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3586 if ($tag{'reftype'} eq "commit") {
3587 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3588 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3589 } elsif ($tag{'reftype'} eq "blob") {
3590 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3595 if (defined $extra) {
3597 "<td colspan=\"5\">$extra</td>\n" .
3603 sub git_heads_body
{
3604 # uses global variable $project
3605 my ($headlist, $head, $from, $to, $extra) = @_;
3606 $from = 0 unless defined $from;
3607 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3609 print "<table class=\"heads\" cellspacing=\"0\">\n";
3611 for (my $i = $from; $i <= $to; $i++) {
3612 my $entry = $headlist->[$i];
3614 my $curr = $ref{'id'} eq $head;
3616 print "<tr class=\"dark\">\n";
3618 print "<tr class=\"light\">\n";
3621 print "<td><i>$ref{'age'}</i></td>\n" .
3622 ($curr ? "<td class=\"current_head\">" : "<td>") .
3623 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3624 -class => "list name"},esc_html
($ref{'name'})) .
3626 "<td class=\"link\">" .
3627 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3628 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3629 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3633 if (defined $extra) {
3635 "<td colspan=\"3\">$extra</td>\n" .
3641 sub git_search_grep_body
{
3642 my ($commitlist, $from, $to, $extra) = @_;
3643 $from = 0 unless defined $from;
3644 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3646 print "<table class=\"grep\" cellspacing=\"0\">\n";
3648 for (my $i = $from; $i <= $to; $i++) {
3649 my %co = %{$commitlist->[$i]};
3653 my $commit = $co{'id'};
3655 print "<tr class=\"dark\">\n";
3657 print "<tr class=\"light\">\n";
3660 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3661 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3663 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3664 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3665 my $comment = $co{'comment'};
3666 foreach my $line (@$comment) {
3667 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3668 my $lead = esc_html
($1) || "";
3669 $lead = chop_str
($lead, 30, 10);
3670 my $match = esc_html
($2) || "";
3671 my $trail = esc_html
($3) || "";
3672 $trail = chop_str
($trail, 30, 10);
3673 my $text = "$lead<span class=\"match\">$match</span>$trail";
3674 print chop_str
($text, 80, 5) . "<br/>\n";
3678 "<td class=\"link\">" .
3679 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3681 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3685 if (defined $extra) {
3687 "<td colspan=\"3\">$extra</td>\n" .
3693 ## ======================================================================
3694 ## ======================================================================
3697 sub git_project_list
{
3698 my $order = $cgi->param('o');
3699 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3700 die_error
(undef, "Unknown order parameter");
3703 my @list = git_get_projects_list
();
3705 die_error
(undef, "No projects found");
3709 if (-f
$home_text) {
3710 print "<div class=\"index_include\">\n";
3711 open (my $fd, $home_text);
3716 git_project_list_body
(\
@list, $order);
3721 my $order = $cgi->param('o');
3722 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3723 die_error
(undef, "Unknown order parameter");
3726 my @list = git_get_projects_list
($project);
3728 die_error
(undef, "No forks found");
3732 git_print_page_nav
('','');
3733 git_print_header_div
('summary', "$project forks");
3734 git_project_list_body
(\
@list, $order);
3738 sub git_project_index
{
3739 my @projects = git_get_projects_list
($project);
3742 -type
=> 'text/plain',
3743 -charset
=> 'utf-8',
3744 -content_disposition
=> 'inline; filename="index.aux"');
3746 foreach my $pr (@projects) {
3747 if (!exists $pr->{'owner'}) {
3748 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3751 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3752 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3753 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3754 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3758 print "$path $owner\n";
3763 my $descr = git_get_project_description
($project) || "none";
3764 my %co = parse_commit
("HEAD");
3765 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3766 my $head = $co{'id'};
3768 my $owner = git_get_project_owner
($project);
3770 my $refs = git_get_references
();
3771 # These get_*_list functions return one more to allow us to see if
3772 # there are more ...
3773 my @taglist = git_get_tags_list
(16);
3774 my @headlist = git_get_heads_list
(16);
3776 my ($check_forks) = gitweb_check_feature
('forks');
3779 @forklist = git_get_projects_list
($project);
3783 git_print_page_nav
('summary','', $head);
3785 print "<div class=\"title\"> </div>\n";
3786 print "<table cellspacing=\"0\">\n" .
3787 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3788 "<tr><td>owner</td><td>$owner</td></tr>\n";
3789 if (defined $cd{'rfc2822'}) {
3790 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3793 # use per project git URL list in $projectroot/$project/cloneurl
3794 # or make project git URL from git base URL and project name
3795 my $url_tag = "URL";
3796 my @url_list = git_get_project_url_list
($project);
3797 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3798 foreach my $git_url (@url_list) {
3799 next unless $git_url;
3800 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3805 if (-s
"$projectroot/$project/README.html") {
3806 if (open my $fd, "$projectroot/$project/README.html") {
3807 print "<div class=\"title\">readme</div>\n";
3808 print $_ while (<$fd>);
3813 # we need to request one more than 16 (0..15) to check if
3815 my @commitlist = $head ? parse_commits
($head, 17) : ();
3817 git_print_header_div
('shortlog');
3818 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3819 $#commitlist <= 15 ? undef :
3820 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3824 git_print_header_div
('tags');
3825 git_tags_body
(\
@taglist, 0, 15,
3826 $#taglist <= 15 ? undef :
3827 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3831 git_print_header_div
('heads');
3832 git_heads_body
(\
@headlist, $head, 0, 15,
3833 $#headlist <= 15 ? undef :
3834 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3838 git_print_header_div
('forks');
3839 git_project_list_body
(\
@forklist, undef, 0, 15,
3840 $#forklist <= 15 ? undef :
3841 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3849 my $head = git_get_head_hash
($project);
3851 git_print_page_nav
('','', $head,undef,$head);
3852 my %tag = parse_tag
($hash);
3855 die_error
(undef, "Unknown tag object");
3858 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3859 print "<div class=\"title_text\">\n" .
3860 "<table cellspacing=\"0\">\n" .
3862 "<td>object</td>\n" .
3863 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3864 $tag{'object'}) . "</td>\n" .
3865 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3866 $tag{'type'}) . "</td>\n" .
3868 if (defined($tag{'author'})) {
3869 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3870 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3871 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3872 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3875 print "</table>\n\n" .
3877 print "<div class=\"page_body\">";
3878 my $comment = $tag{'comment'};
3879 foreach my $line (@$comment) {
3881 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3891 my ($have_blame) = gitweb_check_feature
('blame');
3893 die_error
('403 Permission denied', "Permission denied");
3895 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3896 $hash_base ||= git_get_head_hash
($project);
3897 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3898 my %co = parse_commit
($hash_base)
3899 or die_error
(undef, "Reading commit failed");
3900 if (!defined $hash) {
3901 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3902 or die_error
(undef, "Error looking up file");
3904 $ftype = git_get_type
($hash);
3905 if ($ftype !~ "blob") {
3906 die_error
('400 Bad Request', "Object is not a blob");
3908 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3909 $file_name, $hash_base)
3910 or die_error
(undef, "Open git-blame failed");
3913 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3916 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3919 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3921 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3922 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3923 git_print_page_path
($file_name, $ftype, $hash_base);
3924 my @rev_color = (qw(light2 dark2));
3925 my $num_colors = scalar(@rev_color);
3926 my $current_color = 0;
3929 <div class="page_body">
3930 <table class="blame">
3931 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3936 last unless defined $_;
3937 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3938 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3939 if (!exists $metainfo{$full_rev}) {
3940 $metainfo{$full_rev} = {};
3942 my $meta = $metainfo{$full_rev};
3945 if (/^(\S+) (.*)$/) {
3951 my $rev = substr($full_rev, 0, 8);
3952 my $author = $meta->{'author'};
3953 my %date = parse_date
($meta->{'author-time'},
3954 $meta->{'author-tz'});
3955 my $date = $date{'iso-tz'};
3957 $current_color = ++$current_color % $num_colors;
3959 print "<tr class=\"$rev_color[$current_color]\">\n";
3961 print "<td class=\"sha1\"";
3962 print " title=\"". esc_html
($author) . ", $date\"";
3963 print " rowspan=\"$group_size\"" if ($group_size > 1);
3965 print $cgi->a({-href
=> href
(action
=>"commit",
3967 file_name
=>$file_name)},
3971 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3972 or die_error
(undef, "Open git-rev-parse failed");
3973 my $parent_commit = <$dd>;
3975 chomp($parent_commit);
3976 my $blamed = href
(action
=> 'blame',
3977 file_name
=> $meta->{'filename'},
3978 hash_base
=> $parent_commit);
3979 print "<td class=\"linenr\">";
3980 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3982 -class => "linenr" },
3985 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3991 or print "Reading blob failed\n";
3998 my ($have_blame) = gitweb_check_feature
('blame');
4000 die_error
('403 Permission denied', "Permission denied");
4002 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4003 $hash_base ||= git_get_head_hash
($project);
4004 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4005 my %co = parse_commit
($hash_base)
4006 or die_error
(undef, "Reading commit failed");
4007 if (!defined $hash) {
4008 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4009 or die_error
(undef, "Error lookup file");
4011 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4012 or die_error
(undef, "Open git-annotate failed");
4015 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4018 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4021 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4023 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4024 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4025 git_print_page_path
($file_name, 'blob', $hash_base);
4026 print "<div class=\"page_body\">\n";
4028 <table class="blame">
4037 my @line_class = (qw(light dark));
4038 my $line_class_len = scalar (@line_class);
4039 my $line_class_num = $#line_class;
4040 while (my $line = <$fd>) {
4052 $line_class_num = ($line_class_num + 1) % $line_class_len;
4054 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4061 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4064 $short_rev = substr ($long_rev, 0, 8);
4065 $age = time () - $time;
4066 $age_str = age_string
($age);
4067 $age_str =~ s/ / /g;
4068 $age_class = age_class
($age);
4069 $author = esc_html
($author);
4070 $author =~ s/ / /g;
4072 $data = untabify
($data);
4073 $data = esc_html
($data);
4076 <tr class="$line_class[$line_class_num]">
4077 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4078 <td class="$age_class">$age_str</td>
4080 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4081 <td class="pre">$data</td>
4084 } # while (my $line = <$fd>)
4085 print "</table>\n\n";
4087 or print "Reading blob failed.\n";
4093 my $head = git_get_head_hash
($project);
4095 git_print_page_nav
('','', $head,undef,$head);
4096 git_print_header_div
('summary', $project);
4098 my @tagslist = git_get_tags_list
();
4100 git_tags_body
(\
@tagslist);
4106 my $head = git_get_head_hash
($project);
4108 git_print_page_nav
('','', $head,undef,$head);
4109 git_print_header_div
('summary', $project);
4111 my @headslist = git_get_heads_list
();
4113 git_heads_body
(\
@headslist, $head);
4118 sub git_blob_plain
{
4121 if (!defined $hash) {
4122 if (defined $file_name) {
4123 my $base = $hash_base || git_get_head_hash
($project);
4124 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4125 or die_error
(undef, "Error lookup file");
4127 die_error
(undef, "No file name defined");
4129 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4130 # blobs defined by non-textual hash id's can be cached
4135 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4136 or die_error
(undef, "Couldn't cat $file_name, $hash");
4138 $type ||= blob_mimetype
($fd, $file_name);
4140 # save as filename, even when no $file_name is given
4141 my $save_as = "$hash";
4142 if (defined $file_name) {
4143 $save_as = $file_name;
4144 } elsif ($type =~ m/^text\//) {
4151 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4153 binmode STDOUT
, ':raw';
4155 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4163 if (!defined $hash) {
4164 if (defined $file_name) {
4165 my $base = $hash_base || git_get_head_hash
($project);
4166 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4167 or die_error
(undef, "Error lookup file");
4169 die_error
(undef, "No file name defined");
4171 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4172 # blobs defined by non-textual hash id's can be cached
4176 my ($have_blame) = gitweb_check_feature
('blame');
4177 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4178 or die_error
(undef, "Couldn't cat $file_name, $hash");
4179 my $mimetype = blob_mimetype
($fd, $file_name);
4180 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4182 return git_blob_plain
($mimetype);
4184 # we can have blame only for text/* mimetype
4185 $have_blame &&= ($mimetype =~ m!^text/!);
4187 git_header_html
(undef, $expires);
4188 my $formats_nav = '';
4189 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4190 if (defined $file_name) {
4193 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4194 hash
=>$hash, file_name
=>$file_name)},
4199 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4200 hash
=>$hash, file_name
=>$file_name)},
4203 $cgi->a({-href
=> href
(action
=>"blob_plain",
4204 hash
=>$hash, file_name
=>$file_name)},
4207 $cgi->a({-href
=> href
(action
=>"blob",
4208 hash_base
=>"HEAD", file_name
=>$file_name)},
4212 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4214 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4215 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4217 print "<div class=\"page_nav\">\n" .
4218 "<br/><br/></div>\n" .
4219 "<div class=\"title\">$hash</div>\n";
4221 git_print_page_path
($file_name, "blob", $hash_base);
4222 print "<div class=\"page_body\">\n";
4223 if ($mimetype =~ m!^text/!) {
4225 while (my $line = <$fd>) {
4228 $line = untabify
($line);
4229 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4230 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4232 } elsif ($mimetype =~ m!^image/!) {
4233 print qq
!<img type
="$mimetype"!;
4235 print qq
! alt
="$file_name" title
="$file_name"!;
4238 href(action=>"blob_plain
", hash=>$hash,
4239 hash_base=>$hash_base, file_name=>$file_name) .
4243 or print "Reading blob failed.\n";
4249 if (!defined $hash_base) {
4250 $hash_base = "HEAD";
4252 if (!defined $hash) {
4253 if (defined $file_name) {
4254 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4260 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4261 or die_error
(undef, "Open git-ls-tree failed");
4262 my @entries = map { chomp; $_ } <$fd>;
4263 close $fd or die_error
(undef, "Reading tree failed");
4266 my $refs = git_get_references
();
4267 my $ref = format_ref_marker
($refs, $hash_base);
4270 my ($have_blame) = gitweb_check_feature
('blame');
4271 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4273 if (defined $file_name) {
4275 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4276 hash
=>$hash, file_name
=>$file_name)},
4278 $cgi->a({-href
=> href
(action
=>"tree",
4279 hash_base
=>"HEAD", file_name
=>$file_name)},
4282 my $snapshot_links = format_snapshot_links
($hash);
4283 if (defined $snapshot_links) {
4284 # FIXME: Should be available when we have no hash base as well.
4285 push @views_nav, $snapshot_links;
4287 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4288 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4291 print "<div class=\"page_nav\">\n";
4292 print "<br/><br/></div>\n";
4293 print "<div class=\"title\">$hash</div>\n";
4295 if (defined $file_name) {
4296 $basedir = $file_name;
4297 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4301 git_print_page_path
($file_name, 'tree', $hash_base);
4302 print "<div class=\"page_body\">\n";
4303 print "<table cellspacing=\"0\">\n";
4305 # '..' (top directory) link if possible
4306 if (defined $hash_base &&
4307 defined $file_name && $file_name =~ m![^/]+$!) {
4309 print "<tr class=\"dark\">\n";
4311 print "<tr class=\"light\">\n";
4315 my $up = $file_name;
4316 $up =~ s!/?[^/]+$!!;
4317 undef $up unless $up;
4318 # based on git_print_tree_entry
4319 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4320 print '<td class="list">';
4321 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4325 print "<td class=\"link\"></td>\n";
4329 foreach my $line (@entries) {
4330 my %t = parse_ls_tree_line
($line, -z
=> 1);
4333 print "<tr class=\"dark\">\n";
4335 print "<tr class=\"light\">\n";
4339 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4343 print "</table>\n" .
4349 my @supported_fmts = gitweb_check_feature
('snapshot');
4350 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4352 my $format = $cgi->param('sf');
4353 if (!@supported_fmts) {
4354 die_error
('403 Permission denied', "Permission denied");
4356 # default to first supported snapshot format
4357 $format ||= $supported_fmts[0];
4358 if ($format !~ m/^[a-z0-9]+$/) {
4359 die_error
(undef, "Invalid snapshot format parameter");
4360 } elsif (!exists($known_snapshot_formats{$format})) {
4361 die_error
(undef, "Unknown snapshot format");
4362 } elsif (!grep($_ eq $format, @supported_fmts)) {
4363 die_error
(undef, "Unsupported snapshot format");
4366 if (!defined $hash) {
4367 $hash = git_get_head_hash
($project);
4370 my $git_command = git_cmd_str
();
4371 my $name = $project;
4372 $name =~ s
,([^/])/*\
.git
$,$1,;
4373 $name = basename
($name);
4374 my $filename = to_utf8
($name);
4375 $name =~ s/\047/\047\\\047\047/g;
4377 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4378 $cmd = "$git_command archive " .
4379 "--format=$known_snapshot_formats{$format}{'format'} " .
4380 "--prefix=\'$name\'/ $hash";
4381 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4382 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4386 -type
=> $known_snapshot_formats{$format}{'type'},
4387 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4388 -status
=> '200 OK');
4390 open my $fd, "-|", $cmd
4391 or die_error
(undef, "Execute git-archive failed");
4392 binmode STDOUT
, ':raw';
4394 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4399 my $head = git_get_head_hash
($project);
4400 if (!defined $hash) {
4403 if (!defined $page) {
4406 my $refs = git_get_references
();
4408 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4410 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4413 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4416 my %co = parse_commit
($hash);
4418 git_print_header_div
('summary', $project);
4419 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4421 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4422 for (my $i = 0; $i <= $to; $i++) {
4423 my %co = %{$commitlist[$i]};
4425 my $commit = $co{'id'};
4426 my $ref = format_ref_marker
($refs, $commit);
4427 my %ad = parse_date
($co{'author_epoch'});
4428 git_print_header_div
('commit',
4429 "<span class=\"age\">$co{'age_string'}</span>" .
4430 esc_html
($co{'title'}) . $ref,
4432 print "<div class=\"title_text\">\n" .
4433 "<div class=\"log_link\">\n" .
4434 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4436 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4438 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4441 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4444 print "<div class=\"log_body\">\n";
4445 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4448 if ($#commitlist >= 100) {
4449 print "<div class=\"page_nav\">\n";
4450 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4451 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4458 $hash ||= $hash_base || "HEAD";
4459 my %co = parse_commit
($hash);
4461 die_error
(undef, "Unknown commit object");
4463 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4464 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4466 my $parent = $co{'parent'};
4467 my $parents = $co{'parents'}; # listref
4469 # we need to prepare $formats_nav before any parameter munging
4471 if (!defined $parent) {
4473 $formats_nav .= '(initial)';
4474 } elsif (@$parents == 1) {
4475 # single parent commit
4478 $cgi->a({-href
=> href
(action
=>"commit",
4480 esc_html
(substr($parent, 0, 7))) .
4487 $cgi->a({-href
=> href
(action
=>"commit",
4489 esc_html
(substr($_, 0, 7)));
4494 if (!defined $parent) {
4498 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4500 (@$parents <= 1 ? $parent : '-c'),
4502 or die_error
(undef, "Open git-diff-tree failed");
4503 @difftree = map { chomp; $_ } <$fd>;
4504 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4506 # non-textual hash id's can be cached
4508 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4511 my $refs = git_get_references
();
4512 my $ref = format_ref_marker
($refs, $co{'id'});
4514 git_header_html
(undef, $expires);
4515 git_print_page_nav
('commit', '',
4516 $hash, $co{'tree'}, $hash,
4519 if (defined $co{'parent'}) {
4520 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4522 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4524 print "<div class=\"title_text\">\n" .
4525 "<table cellspacing=\"0\">\n";
4526 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4528 "<td></td><td> $ad{'rfc2822'}";
4529 if ($ad{'hour_local'} < 6) {
4530 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4531 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4533 printf(" (%02d:%02d %s)",
4534 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4538 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4539 print "<tr><td></td><td> $cd{'rfc2822'}" .
4540 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4542 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4545 "<td class=\"sha1\">" .
4546 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4547 class => "list"}, $co{'tree'}) .
4549 "<td class=\"link\">" .
4550 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4552 my $snapshot_links = format_snapshot_links
($hash);
4553 if (defined $snapshot_links) {
4554 print " | " . $snapshot_links;
4559 foreach my $par (@$parents) {
4562 "<td class=\"sha1\">" .
4563 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4564 class => "list"}, $par) .
4566 "<td class=\"link\">" .
4567 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4569 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4576 print "<div class=\"page_body\">\n";
4577 git_print_log
($co{'comment'});
4580 git_difftree_body
(\
@difftree, $hash, @$parents);
4586 # object is defined by:
4587 # - hash or hash_base alone
4588 # - hash_base and file_name
4591 # - hash or hash_base alone
4592 if ($hash || ($hash_base && !defined $file_name)) {
4593 my $object_id = $hash || $hash_base;
4595 my $git_command = git_cmd_str
();
4596 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4597 or die_error
('404 Not Found', "Object does not exist");
4601 or die_error
('404 Not Found', "Object does not exist");
4603 # - hash_base and file_name
4604 } elsif ($hash_base && defined $file_name) {
4605 $file_name =~ s
,/+$,,;
4607 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4608 or die_error
('404 Not Found', "Base object does not exist");
4610 # here errors should not hapen
4611 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4612 or die_error
(undef, "Open git-ls-tree failed");
4616 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4617 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4618 die_error
('404 Not Found', "File or directory for given base does not exist");
4623 die_error
('404 Not Found', "Not enough information to find object");
4626 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4627 hash
=>$hash, hash_base
=>$hash_base,
4628 file_name
=>$file_name),
4629 -status
=> '302 Found');
4633 my $format = shift || 'html';
4640 # preparing $fd and %diffinfo for git_patchset_body
4642 if (defined $hash_base && defined $hash_parent_base) {
4643 if (defined $file_name) {
4645 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4646 $hash_parent_base, $hash_base,
4647 "--", (defined $file_parent ? $file_parent : ()), $file_name
4648 or die_error
(undef, "Open git-diff-tree failed");
4649 @difftree = map { chomp; $_ } <$fd>;
4651 or die_error
(undef, "Reading git-diff-tree failed");
4653 or die_error
('404 Not Found', "Blob diff not found");
4655 } elsif (defined $hash &&
4656 $hash =~ /[0-9a-fA-F]{40}/) {
4657 # try to find filename from $hash
4659 # read filtered raw output
4660 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4661 $hash_parent_base, $hash_base, "--"
4662 or die_error
(undef, "Open git-diff-tree failed");
4664 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4666 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4667 map { chomp; $_ } <$fd>;
4669 or die_error
(undef, "Reading git-diff-tree failed");
4671 or die_error
('404 Not Found', "Blob diff not found");
4674 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4677 if (@difftree > 1) {
4678 die_error
('404 Not Found', "Ambiguous blob diff specification");
4681 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4682 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4683 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4685 $hash_parent ||= $diffinfo{'from_id'};
4686 $hash ||= $diffinfo{'to_id'};
4688 # non-textual hash id's can be cached
4689 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4690 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4695 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4696 '-p', ($format eq 'html' ? "--full-index" : ()),
4697 $hash_parent_base, $hash_base,
4698 "--", (defined $file_parent ? $file_parent : ()), $file_name
4699 or die_error
(undef, "Open git-diff-tree failed");
4702 # old/legacy style URI
4703 if (!%diffinfo && # if new style URI failed
4704 defined $hash && defined $hash_parent) {
4705 # fake git-diff-tree raw output
4706 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4707 $diffinfo{'from_id'} = $hash_parent;
4708 $diffinfo{'to_id'} = $hash;
4709 if (defined $file_name) {
4710 if (defined $file_parent) {
4711 $diffinfo{'status'} = '2';
4712 $diffinfo{'from_file'} = $file_parent;
4713 $diffinfo{'to_file'} = $file_name;
4714 } else { # assume not renamed
4715 $diffinfo{'status'} = '1';
4716 $diffinfo{'from_file'} = $file_name;
4717 $diffinfo{'to_file'} = $file_name;
4719 } else { # no filename given
4720 $diffinfo{'status'} = '2';
4721 $diffinfo{'from_file'} = $hash_parent;
4722 $diffinfo{'to_file'} = $hash;
4725 # non-textual hash id's can be cached
4726 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4727 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4732 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4733 '-p', ($format eq 'html' ? "--full-index" : ()),
4734 $hash_parent, $hash, "--"
4735 or die_error
(undef, "Open git-diff failed");
4737 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4742 if ($format eq 'html') {
4744 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4745 hash
=>$hash, hash_parent
=>$hash_parent,
4746 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4747 file_name
=>$file_name, file_parent
=>$file_parent)},
4749 git_header_html
(undef, $expires);
4750 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4751 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4752 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4754 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4755 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4757 if (defined $file_name) {
4758 git_print_page_path
($file_name, "blob", $hash_base);
4760 print "<div class=\"page_path\"></div>\n";
4763 } elsif ($format eq 'plain') {
4765 -type
=> 'text/plain',
4766 -charset
=> 'utf-8',
4767 -expires
=> $expires,
4768 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4770 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4773 die_error
(undef, "Unknown blobdiff format");
4777 if ($format eq 'html') {
4778 print "<div class=\"page_body\">\n";
4780 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4783 print "</div>\n"; # class="page_body"
4787 while (my $line = <$fd>) {
4788 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4789 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4793 last if $line =~ m!^\+\+\+!;
4801 sub git_blobdiff_plain
{
4802 git_blobdiff
('plain');
4805 sub git_commitdiff
{
4806 my $format = shift || 'html';
4807 $hash ||= $hash_base || "HEAD";
4808 my %co = parse_commit
($hash);
4810 die_error
(undef, "Unknown commit object");
4813 # choose format for commitdiff for merge
4814 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4815 $hash_parent = '--cc';
4817 # we need to prepare $formats_nav before almost any parameter munging
4819 if ($format eq 'html') {
4821 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4822 hash
=>$hash, hash_parent
=>$hash_parent)},
4825 if (defined $hash_parent &&
4826 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4827 # commitdiff with two commits given
4828 my $hash_parent_short = $hash_parent;
4829 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4830 $hash_parent_short = substr($hash_parent, 0, 7);
4834 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4835 if ($co{'parents'}[$i] eq $hash_parent) {
4836 $formats_nav .= ' parent ' . ($i+1);
4840 $formats_nav .= ': ' .
4841 $cgi->a({-href
=> href
(action
=>"commitdiff",
4842 hash
=>$hash_parent)},
4843 esc_html
($hash_parent_short)) .
4845 } elsif (!$co{'parent'}) {
4847 $formats_nav .= ' (initial)';
4848 } elsif (scalar @{$co{'parents'}} == 1) {
4849 # single parent commit
4852 $cgi->a({-href
=> href
(action
=>"commitdiff",
4853 hash
=>$co{'parent'})},
4854 esc_html
(substr($co{'parent'}, 0, 7))) .
4858 if ($hash_parent eq '--cc') {
4859 $formats_nav .= ' | ' .
4860 $cgi->a({-href
=> href
(action
=>"commitdiff",
4861 hash
=>$hash, hash_parent
=>'-c')},
4863 } else { # $hash_parent eq '-c'
4864 $formats_nav .= ' | ' .
4865 $cgi->a({-href
=> href
(action
=>"commitdiff",
4866 hash
=>$hash, hash_parent
=>'--cc')},
4872 $cgi->a({-href
=> href
(action
=>"commitdiff",
4874 esc_html
(substr($_, 0, 7)));
4875 } @{$co{'parents'}} ) .
4880 my $hash_parent_param = $hash_parent;
4881 if (!defined $hash_parent_param) {
4882 # --cc for multiple parents, --root for parentless
4883 $hash_parent_param =
4884 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4890 if ($format eq 'html') {
4891 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4892 "--no-commit-id", "--patch-with-raw", "--full-index",
4893 $hash_parent_param, $hash, "--"
4894 or die_error
(undef, "Open git-diff-tree failed");
4896 while (my $line = <$fd>) {
4898 # empty line ends raw part of diff-tree output
4900 push @difftree, scalar parse_difftree_raw_line
($line);
4903 } elsif ($format eq 'plain') {
4904 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4905 '-p', $hash_parent_param, $hash, "--"
4906 or die_error
(undef, "Open git-diff-tree failed");
4909 die_error
(undef, "Unknown commitdiff format");
4912 # non-textual hash id's can be cached
4914 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4918 # write commit message
4919 if ($format eq 'html') {
4920 my $refs = git_get_references
();
4921 my $ref = format_ref_marker
($refs, $co{'id'});
4923 git_header_html
(undef, $expires);
4924 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4925 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4926 git_print_authorship
(\
%co);
4927 print "<div class=\"page_body\">\n";
4928 if (@{$co{'comment'}} > 1) {
4929 print "<div class=\"log\">\n";
4930 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4931 print "</div>\n"; # class="log"
4934 } elsif ($format eq 'plain') {
4935 my $refs = git_get_references
("tags");
4936 my $tagname = git_get_rev_name_tags
($hash);
4937 my $filename = basename
($project) . "-$hash.patch";
4940 -type
=> 'text/plain',
4941 -charset
=> 'utf-8',
4942 -expires
=> $expires,
4943 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4944 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4947 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4948 Subject: $co{'title'}
4950 print "X-Git-Tag: $tagname\n" if $tagname;
4951 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4953 foreach my $line (@{$co{'comment'}}) {
4960 if ($format eq 'html') {
4961 my $use_parents = !defined $hash_parent ||
4962 $hash_parent eq '-c' || $hash_parent eq '--cc';
4963 git_difftree_body
(\
@difftree, $hash,
4964 $use_parents ? @{$co{'parents'}} : $hash_parent);
4967 git_patchset_body
($fd, \
@difftree, $hash,
4968 $use_parents ? @{$co{'parents'}} : $hash_parent);
4970 print "</div>\n"; # class="page_body"
4973 } elsif ($format eq 'plain') {
4977 or print "Reading git-diff-tree failed\n";
4981 sub git_commitdiff_plain
{
4982 git_commitdiff
('plain');
4986 if (!defined $hash_base) {
4987 $hash_base = git_get_head_hash
($project);
4989 if (!defined $page) {
4993 my %co = parse_commit
($hash_base);
4995 die_error
(undef, "Unknown commit object");
4998 my $refs = git_get_references
();
4999 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5001 if (!defined $hash && defined $file_name) {
5002 $hash = git_get_hash_by_path
($hash_base, $file_name);
5004 if (defined $hash) {
5005 $ftype = git_get_type
($hash);
5008 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5010 my $paging_nav = '';
5013 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5014 file_name
=>$file_name)},
5016 $paging_nav .= " ⋅ " .
5017 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5018 file_name
=>$file_name, page
=>$page-1),
5019 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5021 $paging_nav .= "first";
5022 $paging_nav .= " ⋅ prev";
5024 if ($#commitlist >= 100) {
5025 $paging_nav .= " ⋅ " .
5026 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5027 file_name
=>$file_name, page
=>$page+1),
5028 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5030 $paging_nav .= " ⋅ next";
5033 if ($#commitlist >= 100) {
5035 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5036 file_name
=>$file_name, page
=>$page+1),
5037 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5041 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5042 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5043 git_print_page_path
($file_name, $ftype, $hash_base);
5045 git_history_body
(\
@commitlist, 0, 99,
5046 $refs, $hash_base, $ftype, $next_link);
5052 my ($have_search) = gitweb_check_feature
('search');
5053 if (!$have_search) {
5054 die_error
('403 Permission denied', "Permission denied");
5056 if (!defined $searchtext) {
5057 die_error
(undef, "Text field empty");
5059 if (!defined $hash) {
5060 $hash = git_get_head_hash
($project);
5062 my %co = parse_commit
($hash);
5064 die_error
(undef, "Unknown commit object");
5066 if (!defined $page) {
5070 $searchtype ||= 'commit';
5071 if ($searchtype eq 'pickaxe') {
5072 # pickaxe may take all resources of your box and run for several minutes
5073 # with every query - so decide by yourself how public you make this feature
5074 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5075 if (!$have_pickaxe) {
5076 die_error
('403 Permission denied', "Permission denied");
5079 if ($searchtype eq 'grep') {
5080 my ($have_grep) = gitweb_check_feature
('grep');
5082 die_error
('403 Permission denied', "Permission denied");
5088 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5090 if ($searchtype eq 'commit') {
5091 $greptype = "--grep=";
5092 } elsif ($searchtype eq 'author') {
5093 $greptype = "--author=";
5094 } elsif ($searchtype eq 'committer') {
5095 $greptype = "--committer=";
5097 $greptype .= $search_regexp;
5098 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5100 my $paging_nav = '';
5103 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5104 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5106 $paging_nav .= " ⋅ " .
5107 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5108 searchtext
=>$searchtext, searchtype
=>$searchtype,
5110 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5112 $paging_nav .= "first";
5113 $paging_nav .= " ⋅ prev";
5115 if ($#commitlist >= 100) {
5116 $paging_nav .= " ⋅ " .
5117 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5118 searchtext
=>$searchtext, searchtype
=>$searchtype,
5120 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5122 $paging_nav .= " ⋅ next";
5125 if ($#commitlist >= 100) {
5127 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5128 searchtext
=>$searchtext, searchtype
=>$searchtype,
5130 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5133 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5134 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5135 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5138 if ($searchtype eq 'pickaxe') {
5139 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5140 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5142 print "<table cellspacing=\"0\">\n";
5145 my $git_command = git_cmd_str
();
5146 my $searchqtext = $searchtext;
5147 $searchqtext =~ s/'/'\\''/;
5148 open my $fd, "-|", "$git_command rev-list $hash | " .
5149 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5152 while (my $line = <$fd>) {
5153 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5156 $set{'from_id'} = $3;
5158 $set{'id'} = $set{'to_id'};
5159 if ($set{'id'} =~ m/0{40}/) {
5160 $set{'id'} = $set{'from_id'};
5162 if ($set{'id'} =~ m/0{40}/) {
5166 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5169 print "<tr class=\"dark\">\n";
5171 print "<tr class=\"light\">\n";
5174 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5175 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5177 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5178 -class => "list subject"},
5179 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5180 while (my $setref = shift @files) {
5182 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5183 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5185 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5189 "<td class=\"link\">" .
5190 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5192 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5196 %co = parse_commit
($1);
5204 if ($searchtype eq 'grep') {
5205 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5206 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5208 print "<table cellspacing=\"0\">\n";
5212 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5214 while (my $line = <$fd>) {
5216 my ($file, $lno, $ltext, $binary);
5217 last if ($matches++ > 1000);
5218 if ($line =~ /^Binary file (.+) matches$/) {
5222 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5224 if ($file ne $lastfile) {
5225 $lastfile and print "</td></tr>\n";
5227 print "<tr class=\"dark\">\n";
5229 print "<tr class=\"light\">\n";
5231 print "<td class=\"list\">".
5232 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5233 file_name
=>"$file"),
5234 -class => "list"}, esc_path
($file));
5235 print "</td><td>\n";
5239 print "<div class=\"binary\">Binary file</div>\n";
5241 $ltext = untabify
($ltext);
5242 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5243 $ltext = esc_html
($1, -nbsp
=>1);
5244 $ltext .= '<span class="match">';
5245 $ltext .= esc_html
($2, -nbsp
=>1);
5246 $ltext .= '</span>';
5247 $ltext .= esc_html
($3, -nbsp
=>1);
5249 $ltext = esc_html
($ltext, -nbsp
=>1);
5251 print "<div class=\"pre\">" .
5252 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5253 file_name
=>"$file").'#l'.$lno,
5254 -class => "linenr"}, sprintf('%4i', $lno))
5255 . ' ' . $ltext . "</div>\n";
5259 print "</td></tr>\n";
5260 if ($matches > 1000) {
5261 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5264 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5273 sub git_search_help
{
5275 git_print_page_nav
('','', $hash,$hash,$hash);
5278 <dt><b>commit</b></dt>
5279 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5281 my ($have_grep) = gitweb_check_feature
('grep');
5284 <dt><b>grep</b></dt>
5285 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5286 a different one) are searched for the given
5287 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5288 (POSIX extended) and the matches are listed. On large
5289 trees, this search can take a while and put some strain on the server, so please use it with
5290 some consideration.</dd>
5294 <dt><b>author</b></dt>
5295 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5296 <dt><b>committer</b></dt>
5297 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5299 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5300 if ($have_pickaxe) {
5302 <dt><b>pickaxe</b></dt>
5303 <dd>All commits that caused the string to appear or disappear from any file (changes that
5304 added, removed or "modified" the string) will be listed. This search can take a while and
5305 takes a lot of strain on the server, so please use it wisely.</dd>
5313 my $head = git_get_head_hash
($project);
5314 if (!defined $hash) {
5317 if (!defined $page) {
5320 my $refs = git_get_references
();
5322 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5324 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5326 if ($#commitlist >= 100) {
5328 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5329 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5333 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5334 git_print_header_div
('summary', $project);
5336 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5341 ## ......................................................................
5342 ## feeds (RSS, Atom; OPML)
5345 my $format = shift || 'atom';
5346 my ($have_blame) = gitweb_check_feature
('blame');
5348 # Atom: http://www.atomenabled.org/developers/syndication/
5349 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5350 if ($format ne 'rss' && $format ne 'atom') {
5351 die_error
(undef, "Unknown web feed format");
5354 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5355 my $head = $hash || 'HEAD';
5356 my @commitlist = parse_commits
($head, 150);
5360 my $content_type = "application/$format+xml";
5361 if (defined $cgi->http('HTTP_ACCEPT') &&
5362 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5363 # browser (feed reader) prefers text/xml
5364 $content_type = 'text/xml';
5366 if (defined($commitlist[0])) {
5367 %latest_commit = %{$commitlist[0]};
5368 %latest_date = parse_date
($latest_commit{'author_epoch'});
5370 -type
=> $content_type,
5371 -charset
=> 'utf-8',
5372 -last_modified
=> $latest_date{'rfc2822'});
5375 -type
=> $content_type,
5376 -charset
=> 'utf-8');
5379 # Optimization: skip generating the body if client asks only
5380 # for Last-Modified date.
5381 return if ($cgi->request_method() eq 'HEAD');
5384 my $title = "$site_name - $project/$action";
5385 my $feed_type = 'log';
5386 if (defined $hash) {
5387 $title .= " - '$hash'";
5388 $feed_type = 'branch log';
5389 if (defined $file_name) {
5390 $title .= " :: $file_name";
5391 $feed_type = 'history';
5393 } elsif (defined $file_name) {
5394 $title .= " - $file_name";
5395 $feed_type = 'history';
5397 $title .= " $feed_type";
5398 my $descr = git_get_project_description
($project);
5399 if (defined $descr) {
5400 $descr = esc_html
($descr);
5402 $descr = "$project " .
5403 ($format eq 'rss' ? 'RSS' : 'Atom') .
5406 my $owner = git_get_project_owner
($project);
5407 $owner = esc_html
($owner);
5411 if (defined $file_name) {
5412 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5413 } elsif (defined $hash) {
5414 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5416 $alt_url = href
(-full
=>1, action
=>"summary");
5418 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5419 if ($format eq 'rss') {
5421 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5424 print "<title>$title</title>\n" .
5425 "<link>$alt_url</link>\n" .
5426 "<description>$descr</description>\n" .
5427 "<language>en</language>\n";
5428 } elsif ($format eq 'atom') {
5430 <feed xmlns="http://www.w3.org/2005/Atom">
5432 print "<title>$title</title>\n" .
5433 "<subtitle>$descr</subtitle>\n" .
5434 '<link rel="alternate" type="text/html" href="' .
5435 $alt_url . '" />' . "\n" .
5436 '<link rel="self" type="' . $content_type . '" href="' .
5437 $cgi->self_url() . '" />' . "\n" .
5438 "<id>" . href
(-full
=>1) . "</id>\n" .
5439 # use project owner for feed author
5440 "<author><name>$owner</name></author>\n";
5441 if (defined $favicon) {
5442 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5444 if (defined $logo_url) {
5445 # not twice as wide as tall: 72 x 27 pixels
5446 print "<logo>" . esc_url
($logo) . "</logo>\n";
5448 if (! %latest_date) {
5449 # dummy date to keep the feed valid until commits trickle in:
5450 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5452 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5457 for (my $i = 0; $i <= $#commitlist; $i++) {
5458 my %co = %{$commitlist[$i]};
5459 my $commit = $co{'id'};
5460 # we read 150, we always show 30 and the ones more recent than 48 hours
5461 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5464 my %cd = parse_date
($co{'author_epoch'});
5466 # get list of changed files
5467 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5468 $co{'parent'} || "--root",
5469 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5471 my @difftree = map { chomp; $_ } <$fd>;
5475 # print element (entry, item)
5476 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5477 if ($format eq 'rss') {
5479 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5480 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5481 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5482 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5483 "<link>$co_url</link>\n" .
5484 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5485 "<content:encoded>" .
5487 } elsif ($format eq 'atom') {
5489 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5490 "<updated>$cd{'iso-8601'}</updated>\n" .
5492 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5493 if ($co{'author_email'}) {
5494 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5496 print "</author>\n" .
5497 # use committer for contributor
5499 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5500 if ($co{'committer_email'}) {
5501 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5503 print "</contributor>\n" .
5504 "<published>$cd{'iso-8601'}</published>\n" .
5505 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5506 "<id>$co_url</id>\n" .
5507 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5508 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5510 my $comment = $co{'comment'};
5512 foreach my $line (@$comment) {
5513 $line = esc_html
($line);
5516 print "</pre><ul>\n";
5517 foreach my $difftree_line (@difftree) {
5518 my %difftree = parse_difftree_raw_line
($difftree_line);
5519 next if !$difftree{'from_id'};
5521 my $file = $difftree{'file'} || $difftree{'to_file'};
5525 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5526 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5527 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5528 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5529 -title
=> "diff"}, 'D');
5531 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5532 file_name
=>$file, hash_base
=>$commit),
5533 -title
=> "blame"}, 'B');
5535 # if this is not a feed of a file history
5536 if (!defined $file_name || $file_name ne $file) {
5537 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5538 file_name
=>$file, hash
=>$commit),
5539 -title
=> "history"}, 'H');
5541 $file = esc_path
($file);
5545 if ($format eq 'rss') {
5546 print "</ul>]]>\n" .
5547 "</content:encoded>\n" .
5549 } elsif ($format eq 'atom') {
5550 print "</ul>\n</div>\n" .
5557 if ($format eq 'rss') {
5558 print "</channel>\n</rss>\n";
5559 } elsif ($format eq 'atom') {
5573 my @list = git_get_projects_list
();
5575 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5577 <?xml version="1.0" encoding="utf-8"?>
5578 <opml version="1.0">
5580 <title>$site_name OPML Export</title>
5583 <outline text="git RSS feeds">
5586 foreach my $pr (@list) {
5588 my $head = git_get_head_hash
($proj{'path'});
5589 if (!defined $head) {
5592 $git_dir = "$projectroot/$proj{'path'}";
5593 my %co = parse_commit
($head);
5598 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5599 my $rss = "$my_url?p=$proj{'path'};a=rss";
5600 my $html = "$my_url?p=$proj{'path'};a=summary";
5601 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";