3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $searchtext = $cgi->param('s');
478 if (defined $searchtext) {
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
605 hash_parent_base
=> "hpb",
610 snapshot_format
=> "sf",
611 extra_options
=> "opt",
613 my %mapping = @mapping;
615 $params{'project'} = $project unless exists $params{'project'};
617 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 if (ref($params{$name}) eq "ARRAY") {
635 foreach my $par (@{$params{$name}}) {
636 push @result, $symbol . "=" . esc_param
($par);
639 push @result, $symbol . "=" . esc_param
($params{$name});
643 $href .= "?" . join(';', @result) if scalar @result;
649 ## ======================================================================
650 ## validation, quoting/unquoting and escaping
652 sub validate_pathname
{
653 my $input = shift || return undef;
655 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
656 # at the beginning, at the end, and between slashes.
657 # also this catches doubled slashes
658 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
662 if ($input =~ m!\0!) {
668 sub validate_refname
{
669 my $input = shift || return undef;
671 # textual hashes are O.K.
672 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
675 # it must be correct pathname
676 $input = validate_pathname
($input)
678 # restrictions on ref name according to git-check-ref-format
679 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
685 # decode sequences of octets in utf8 into Perl's internal form,
686 # which is utf-8 with utf8 flag set if needed. gitweb writes out
687 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
691 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
695 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
699 # quote unsafe chars, but keep the slash, even when it's not
700 # correct, but quoted slashes look too horrible in bookmarks
703 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
709 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
712 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
718 # replace invalid utf8 character with SUBSTITUTION sequence
723 $str = to_utf8
($str);
724 $str = $cgi->escapeHTML($str);
725 if ($opts{'-nbsp'}) {
726 $str =~ s/ / /g;
728 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
732 # quote control characters and escape filename to HTML
737 $str = to_utf8
($str);
738 $str = $cgi->escapeHTML($str);
739 if ($opts{'-nbsp'}) {
740 $str =~ s/ / /g;
742 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
746 # Make control characters "printable", using character escape codes (CEC)
749 my %es = ( # character escape codes, aka escape sequences
750 "\t" => '\t', # tab (HT)
751 "\n" => '\n', # line feed (LF)
752 "\r" => '\r', # carrige return (CR)
753 "\f" => '\f', # form feed (FF)
754 "\b" => '\b', # backspace (BS)
755 "\a" => '\a', # alarm (bell) (BEL)
756 "\e" => '\e', # escape (ESC)
757 "\013" => '\v', # vertical tab (VT)
758 "\000" => '\0', # nul character (NUL)
760 my $chr = ( (exists $es{$cntrl})
762 : sprintf('\%03o', ord($cntrl)) );
763 return "<span class=\"cntrl\">$chr</span>";
766 # Alternatively use unicode control pictures codepoints,
767 # Unicode "printable representation" (PR)
770 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
771 return "<span class=\"cntrl\">$chr</span>";
774 # git may return quoted and escaped filenames
780 my %es = ( # character escape codes, aka escape sequences
781 't' => "\t", # tab (HT, TAB)
782 'n' => "\n", # newline (NL)
783 'r' => "\r", # return (CR)
784 'f' => "\f", # form feed (FF)
785 'b' => "\b", # backspace (BS)
786 'a' => "\a", # alarm (bell) (BEL)
787 'e' => "\e", # escape (ESC)
788 'v' => "\013", # vertical tab (VT)
791 if ($seq =~ m/^[0-7]{1,3}$/) {
792 # octal char sequence
793 return chr(oct($seq));
794 } elsif (exists $es{$seq}) {
795 # C escape sequence, aka character escape code
798 # quoted ordinary character
802 if ($str =~ m/^"(.*)"$/) {
805 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
810 # escape tabs (convert tabs to spaces)
814 while ((my $pos = index($line, "\t")) != -1) {
815 if (my $count = (8 - ($pos % 8))) {
816 my $spaces = ' ' x
$count;
817 $line =~ s/\t/$spaces/;
824 sub project_in_list
{
826 my @list = git_get_projects_list
();
827 return @list && scalar(grep { $_->{'path'} eq $project } @list);
830 ## ----------------------------------------------------------------------
831 ## HTML aware string manipulation
836 my $add_len = shift || 10;
838 # allow only $len chars, but don't cut a word if it would fit in $add_len
839 # if it doesn't fit, cut it if it's still longer than the dots we would add
840 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
843 if (length($tail) > 4) {
845 $body =~ s/&[^;]*$//; # remove chopped character entities
850 # takes the same arguments as chop_str, but also wraps a <span> around the
851 # result with a title attribute if it does get chopped. Additionally, the
852 # string is HTML-escaped.
853 sub chop_and_escape_str
{
856 my $add_len = shift || 10;
858 my $chopped = chop_str
($str, $len, $add_len);
859 if ($chopped eq $str) {
860 return esc_html
($chopped);
862 return qq{<span title="} . esc_html
($str) . qq{">} .
863 esc_html
($chopped) . qq{</span>};
867 ## ----------------------------------------------------------------------
868 ## functions returning short strings
870 # CSS class for given age value (in seconds)
876 } elsif ($age < 60*60*2) {
878 } elsif ($age < 60*60*24*2) {
885 # convert age in seconds to "nn units ago" string
890 if ($age > 60*60*24*365*2) {
891 $age_str = (int $age/60/60/24/365);
892 $age_str .= " years ago";
893 } elsif ($age > 60*60*24*(365/12)*2) {
894 $age_str = int $age/60/60/24/(365/12);
895 $age_str .= " months ago";
896 } elsif ($age > 60*60*24*7*2) {
897 $age_str = int $age/60/60/24/7;
898 $age_str .= " weeks ago";
899 } elsif ($age > 60*60*24*2) {
900 $age_str = int $age/60/60/24;
901 $age_str .= " days ago";
902 } elsif ($age > 60*60*2) {
903 $age_str = int $age/60/60;
904 $age_str .= " hours ago";
905 } elsif ($age > 60*2) {
906 $age_str = int $age/60;
907 $age_str .= " min ago";
910 $age_str .= " sec ago";
912 $age_str .= " right now";
918 S_IFINVALID
=> 0030000,
919 S_IFGITLINK
=> 0160000,
922 # submodule/subproject, a commit object reference
926 return (($mode & S_IFMT
) == S_IFGITLINK
)
929 # convert file mode in octal to symbolic file mode string
931 my $mode = oct shift;
933 if (S_ISGITLINK
($mode)) {
935 } elsif (S_ISDIR
($mode & S_IFMT
)) {
937 } elsif (S_ISLNK
($mode)) {
939 } elsif (S_ISREG
($mode)) {
940 # git cares only about the executable bit
941 if ($mode & S_IXUSR
) {
951 # convert file mode in octal to file type 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)) {
974 # convert file mode in octal to file type description string
978 if ($mode !~ m/^[0-7]+$/) {
984 if (S_ISGITLINK
($mode)) {
986 } elsif (S_ISDIR
($mode & S_IFMT
)) {
988 } elsif (S_ISLNK
($mode)) {
990 } elsif (S_ISREG
($mode)) {
991 if ($mode & S_IXUSR
) {
1002 ## ----------------------------------------------------------------------
1003 ## functions returning short HTML fragments, or transforming HTML fragments
1004 ## which don't belong to other sections
1006 # format line of commit message.
1007 sub format_log_line_html
{
1010 $line = esc_html
($line, -nbsp
=>1);
1011 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1014 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1015 -class => "text"}, $hash_text);
1016 $line =~ s/$hash_text/$link/;
1021 # format marker of refs pointing to given object
1022 sub format_ref_marker
{
1023 my ($refs, $id) = @_;
1026 if (defined $refs->{$id}) {
1027 foreach my $ref (@{$refs->{$id}}) {
1028 my ($type, $name) = qw();
1029 # e.g. tags/v2.6.11 or heads/next
1030 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1038 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1039 esc_html
($name) . "</span>";
1044 return ' <span class="refs">'. $markers . '</span>';
1050 # format, perhaps shortened and with markers, title line
1051 sub format_subject_html
{
1052 my ($long, $short, $href, $extra) = @_;
1053 $extra = '' unless defined($extra);
1055 if (length($short) < length($long)) {
1056 return $cgi->a({-href
=> $href, -class => "list subject",
1057 -title
=> to_utf8
($long)},
1058 esc_html
($short) . $extra);
1060 return $cgi->a({-href
=> $href, -class => "list subject"},
1061 esc_html
($long) . $extra);
1065 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1066 sub format_git_diff_header_line
{
1068 my $diffinfo = shift;
1069 my ($from, $to) = @_;
1071 if ($diffinfo->{'nparents'}) {
1073 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1074 if ($to->{'href'}) {
1075 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1076 esc_path
($to->{'file'}));
1077 } else { # file was deleted (no href)
1078 $line .= esc_path
($to->{'file'});
1082 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1083 if ($from->{'href'}) {
1084 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1085 'a/' . esc_path
($from->{'file'}));
1086 } else { # file was added (no href)
1087 $line .= 'a/' . esc_path
($from->{'file'});
1090 if ($to->{'href'}) {
1091 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1092 'b/' . esc_path
($to->{'file'}));
1093 } else { # file was deleted
1094 $line .= 'b/' . esc_path
($to->{'file'});
1098 return "<div class=\"diff header\">$line</div>\n";
1101 # format extended diff header line, before patch itself
1102 sub format_extended_diff_header_line
{
1104 my $diffinfo = shift;
1105 my ($from, $to) = @_;
1108 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1109 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1110 esc_path
($from->{'file'}));
1112 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1113 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1114 esc_path
($to->{'file'}));
1116 # match single <mode>
1117 if ($line =~ m/\s(\d{6})$/) {
1118 $line .= '<span class="info"> (' .
1119 file_type_long
($1) .
1123 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1124 # can match only for combined diff
1126 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1127 if ($from->{'href'}[$i]) {
1128 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1130 substr($diffinfo->{'from_id'}[$i],0,7));
1135 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1138 if ($to->{'href'}) {
1139 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1140 substr($diffinfo->{'to_id'},0,7));
1145 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1146 # can match only for ordinary diff
1147 my ($from_link, $to_link);
1148 if ($from->{'href'}) {
1149 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1150 substr($diffinfo->{'from_id'},0,7));
1152 $from_link = '0' x
7;
1154 if ($to->{'href'}) {
1155 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1156 substr($diffinfo->{'to_id'},0,7));
1160 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1161 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1164 return $line . "<br/>\n";
1167 # format from-file/to-file diff header
1168 sub format_diff_from_to_header
{
1169 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1174 #assert($line =~ m/^---/) if DEBUG;
1175 # no extra formatting for "^--- /dev/null"
1176 if (! $diffinfo->{'nparents'}) {
1177 # ordinary (single parent) diff
1178 if ($line =~ m!^--- "?a/!) {
1179 if ($from->{'href'}) {
1181 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1182 esc_path
($from->{'file'}));
1185 esc_path
($from->{'file'});
1188 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1191 # combined diff (merge commit)
1192 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1193 if ($from->{'href'}[$i]) {
1195 $cgi->a({-href
=>href
(action
=>"blobdiff",
1196 hash_parent
=>$diffinfo->{'from_id'}[$i],
1197 hash_parent_base
=>$parents[$i],
1198 file_parent
=>$from->{'file'}[$i],
1199 hash
=>$diffinfo->{'to_id'},
1201 file_name
=>$to->{'file'}),
1203 -title
=>"diff" . ($i+1)},
1206 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1207 esc_path
($from->{'file'}[$i]));
1209 $line = '--- /dev/null';
1211 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1216 #assert($line =~ m/^\+\+\+/) if DEBUG;
1217 # no extra formatting for "^+++ /dev/null"
1218 if ($line =~ m!^\+\+\+ "?b/!) {
1219 if ($to->{'href'}) {
1221 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1222 esc_path
($to->{'file'}));
1225 esc_path
($to->{'file'});
1228 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1233 # create note for patch simplified by combined diff
1234 sub format_diff_cc_simplified
{
1235 my ($diffinfo, @parents) = @_;
1238 $result .= "<div class=\"diff header\">" .
1240 if (!is_deleted
($diffinfo)) {
1241 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1243 hash
=>$diffinfo->{'to_id'},
1244 file_name
=>$diffinfo->{'to_file'}),
1246 esc_path
($diffinfo->{'to_file'}));
1248 $result .= esc_path
($diffinfo->{'to_file'});
1250 $result .= "</div>\n" . # class="diff header"
1251 "<div class=\"diff nodifferences\">" .
1253 "</div>\n"; # class="diff nodifferences"
1258 # format patch (diff) line (not to be used for diff headers)
1259 sub format_diff_line
{
1261 my ($from, $to) = @_;
1262 my $diff_class = "";
1266 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1268 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1269 if ($line =~ m/^\@{3}/) {
1270 $diff_class = " chunk_header";
1271 } elsif ($line =~ m/^\\/) {
1272 $diff_class = " incomplete";
1273 } elsif ($prefix =~ tr/+/+/) {
1274 $diff_class = " add";
1275 } elsif ($prefix =~ tr/-/-/) {
1276 $diff_class = " rem";
1279 # assume ordinary diff
1280 my $char = substr($line, 0, 1);
1282 $diff_class = " add";
1283 } elsif ($char eq '-') {
1284 $diff_class = " rem";
1285 } elsif ($char eq '@') {
1286 $diff_class = " chunk_header";
1287 } elsif ($char eq "\\") {
1288 $diff_class = " incomplete";
1291 $line = untabify
($line);
1292 if ($from && $to && $line =~ m/^\@{2} /) {
1293 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1294 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1296 $from_lines = 0 unless defined $from_lines;
1297 $to_lines = 0 unless defined $to_lines;
1299 if ($from->{'href'}) {
1300 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1301 -class=>"list"}, $from_text);
1303 if ($to->{'href'}) {
1304 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1305 -class=>"list"}, $to_text);
1307 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1308 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1309 return "<div class=\"diff$diff_class\">$line</div>\n";
1310 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1311 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1312 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1314 @from_text = split(' ', $ranges);
1315 for (my $i = 0; $i < @from_text; ++$i) {
1316 ($from_start[$i], $from_nlines[$i]) =
1317 (split(',', substr($from_text[$i], 1)), 0);
1320 $to_text = pop @from_text;
1321 $to_start = pop @from_start;
1322 $to_nlines = pop @from_nlines;
1324 $line = "<span class=\"chunk_info\">$prefix ";
1325 for (my $i = 0; $i < @from_text; ++$i) {
1326 if ($from->{'href'}[$i]) {
1327 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1328 -class=>"list"}, $from_text[$i]);
1330 $line .= $from_text[$i];
1334 if ($to->{'href'}) {
1335 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1336 -class=>"list"}, $to_text);
1340 $line .= " $prefix</span>" .
1341 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1342 return "<div class=\"diff$diff_class\">$line</div>\n";
1344 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1347 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1348 # linked. Pass the hash of the tree/commit to snapshot.
1349 sub format_snapshot_links
{
1351 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1352 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1353 my $num_fmts = @snapshot_fmts;
1354 if ($num_fmts > 1) {
1355 # A parenthesized list of links bearing format names.
1356 # e.g. "snapshot (_tar.gz_ _zip_)"
1357 return "snapshot (" . join(' ', map
1364 }, $known_snapshot_formats{$_}{'display'})
1365 , @snapshot_fmts) . ")";
1366 } elsif ($num_fmts == 1) {
1367 # A single "snapshot" link whose tooltip bears the format name.
1369 my ($fmt) = @snapshot_fmts;
1375 snapshot_format
=>$fmt
1377 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1379 } else { # $num_fmts == 0
1384 ## ----------------------------------------------------------------------
1385 ## git utility subroutines, invoking git commands
1387 # returns path to the core git executable and the --git-dir parameter as list
1389 return $GIT, '--git-dir='.$git_dir;
1392 # returns path to the core git executable and the --git-dir parameter as string
1394 return join(' ', git_cmd
());
1397 # get HEAD ref of given project as hash
1398 sub git_get_head_hash
{
1399 my $project = shift;
1400 my $o_git_dir = $git_dir;
1402 $git_dir = "$projectroot/$project";
1403 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1406 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1410 if (defined $o_git_dir) {
1411 $git_dir = $o_git_dir;
1416 # get type of given object
1420 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1422 close $fd or return;
1427 sub git_get_project_config
{
1428 my ($key, $type) = @_;
1430 return unless ($key);
1431 $key =~ s/^gitweb\.//;
1432 return if ($key =~ m/\W/);
1434 my @x = (git_cmd
(), 'config');
1435 if (defined $type) { push @x, $type; }
1437 push @x, "gitweb.$key";
1443 # get hash of given path at given ref
1444 sub git_get_hash_by_path
{
1446 my $path = shift || return undef;
1451 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1452 or die_error
(undef, "Open git-ls-tree failed");
1454 close $fd or return undef;
1456 if (!defined $line) {
1457 # there is no tree or hash given by $path at $base
1461 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1462 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1463 if (defined $type && $type ne $2) {
1464 # type doesn't match
1470 # get path of entry with given hash at given tree-ish (ref)
1471 # used to get 'from' filename for combined diff (merge commit) for renames
1472 sub git_get_path_by_hash
{
1473 my $base = shift || return;
1474 my $hash = shift || return;
1478 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1480 while (my $line = <$fd>) {
1483 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1484 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1485 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1494 ## ......................................................................
1495 ## git utility functions, directly accessing git repository
1497 sub git_get_project_description
{
1500 open my $fd, "$projectroot/$path/description" or return undef;
1503 if (defined $descr) {
1509 sub git_get_project_url_list
{
1512 open my $fd, "$projectroot/$path/cloneurl" or return;
1513 my @git_project_url_list = map { chomp; $_ } <$fd>;
1516 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1519 sub git_get_projects_list
{
1524 $filter =~ s/\.git$//;
1526 my ($check_forks) = gitweb_check_feature
('forks');
1528 if (-d
$projects_list) {
1529 # search in directory
1530 my $dir = $projects_list . ($filter ? "/$filter" : '');
1531 # remove the trailing "/"
1533 my $pfxlen = length("$dir");
1534 my $pfxdepth = ($dir =~ tr!/!!);
1537 follow_fast
=> 1, # follow symbolic links
1538 follow_skip
=> 2, # ignore duplicates
1539 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1541 # skip project-list toplevel, if we get it.
1542 return if (m!^[/.]$!);
1543 # only directories can be git repositories
1544 return unless (-d
$_);
1545 # don't traverse too deep (Find is super slow on os x)
1546 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1547 $File::Find
::prune
= 1;
1551 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1552 # we check related file in $projectroot
1553 if ($check_forks and $subdir =~ m
#/.#) {
1554 $File::Find
::prune
= 1;
1555 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1556 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1557 $File::Find
::prune
= 1;
1562 } elsif (-f
$projects_list) {
1563 # read from file(url-encoded):
1564 # 'git%2Fgit.git Linus+Torvalds'
1565 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1566 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1568 open my ($fd), $projects_list or return;
1570 while (my $line = <$fd>) {
1572 my ($path, $owner) = split ' ', $line;
1573 $path = unescape
($path);
1574 $owner = unescape
($owner);
1575 if (!defined $path) {
1578 if ($filter ne '') {
1579 # looking for forks;
1580 my $pfx = substr($path, 0, length($filter));
1581 if ($pfx ne $filter) {
1584 my $sfx = substr($path, length($filter));
1585 if ($sfx !~ /^\/.*\
.git
$/) {
1588 } elsif ($check_forks) {
1590 foreach my $filter (keys %paths) {
1591 # looking for forks;
1592 my $pfx = substr($path, 0, length($filter));
1593 if ($pfx ne $filter) {
1596 my $sfx = substr($path, length($filter));
1597 if ($sfx !~ /^\/.*\
.git
$/) {
1600 # is a fork, don't include it in
1605 if (check_export_ok
("$projectroot/$path")) {
1608 owner
=> to_utf8
($owner),
1611 (my $forks_path = $path) =~ s/\.git$//;
1612 $paths{$forks_path}++;
1620 our $gitweb_project_owner = undef;
1621 sub git_get_project_list_from_file
{
1623 return if (defined $gitweb_project_owner);
1625 $gitweb_project_owner = {};
1626 # read from file (url-encoded):
1627 # 'git%2Fgit.git Linus+Torvalds'
1628 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1629 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1630 if (-f
$projects_list) {
1631 open (my $fd , $projects_list);
1632 while (my $line = <$fd>) {
1634 my ($pr, $ow) = split ' ', $line;
1635 $pr = unescape
($pr);
1636 $ow = unescape
($ow);
1637 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1643 sub git_get_project_owner
{
1644 my $project = shift;
1647 return undef unless $project;
1649 if (!defined $gitweb_project_owner) {
1650 git_get_project_list_from_file
();
1653 if (exists $gitweb_project_owner->{$project}) {
1654 $owner = $gitweb_project_owner->{$project};
1656 if (!defined $owner) {
1657 $owner = get_file_owner
("$projectroot/$project");
1663 sub git_get_last_activity
{
1667 $git_dir = "$projectroot/$path";
1668 open($fd, "-|", git_cmd
(), 'for-each-ref',
1669 '--format=%(committer)',
1670 '--sort=-committerdate',
1672 'refs/heads') or return;
1673 my $most_recent = <$fd>;
1674 close $fd or return;
1675 if (defined $most_recent &&
1676 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1678 my $age = time - $timestamp;
1679 return ($age, age_string
($age));
1681 return (undef, undef);
1684 sub git_get_references
{
1685 my $type = shift || "";
1687 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1688 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1689 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1690 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1693 while (my $line = <$fd>) {
1695 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1696 if (defined $refs{$1}) {
1697 push @{$refs{$1}}, $2;
1703 close $fd or return;
1707 sub git_get_rev_name_tags
{
1708 my $hash = shift || return undef;
1710 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1712 my $name_rev = <$fd>;
1715 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1718 # catches also '$hash undefined' output
1723 ## ----------------------------------------------------------------------
1724 ## parse to hash functions
1728 my $tz = shift || "-0000";
1731 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1732 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1733 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1734 $date{'hour'} = $hour;
1735 $date{'minute'} = $min;
1736 $date{'mday'} = $mday;
1737 $date{'day'} = $days[$wday];
1738 $date{'month'} = $months[$mon];
1739 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1740 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1741 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1742 $mday, $months[$mon], $hour ,$min;
1743 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1744 1900+$year, $mon, $mday, $hour ,$min, $sec;
1746 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1747 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1748 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1749 $date{'hour_local'} = $hour;
1750 $date{'minute_local'} = $min;
1751 $date{'tz_local'} = $tz;
1752 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1753 1900+$year, $mon+1, $mday,
1754 $hour, $min, $sec, $tz);
1763 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1764 $tag{'id'} = $tag_id;
1765 while (my $line = <$fd>) {
1767 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1768 $tag{'object'} = $1;
1769 } elsif ($line =~ m/^type (.+)$/) {
1771 } elsif ($line =~ m/^tag (.+)$/) {
1773 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1774 $tag{'author'} = $1;
1777 } elsif ($line =~ m/--BEGIN/) {
1778 push @comment, $line;
1780 } elsif ($line eq "") {
1784 push @comment, <$fd>;
1785 $tag{'comment'} = \
@comment;
1786 close $fd or return;
1787 if (!defined $tag{'name'}) {
1793 sub parse_commit_text
{
1794 my ($commit_text, $withparents) = @_;
1795 my @commit_lines = split '\n', $commit_text;
1798 pop @commit_lines; # Remove '\0'
1800 if (! @commit_lines) {
1804 my $header = shift @commit_lines;
1805 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1808 ($co{'id'}, my @parents) = split ' ', $header;
1809 while (my $line = shift @commit_lines) {
1810 last if $line eq "\n";
1811 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1813 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1815 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1817 $co{'author_epoch'} = $2;
1818 $co{'author_tz'} = $3;
1819 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1820 $co{'author_name'} = $1;
1821 $co{'author_email'} = $2;
1823 $co{'author_name'} = $co{'author'};
1825 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1826 $co{'committer'} = $1;
1827 $co{'committer_epoch'} = $2;
1828 $co{'committer_tz'} = $3;
1829 $co{'committer_name'} = $co{'committer'};
1830 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1831 $co{'committer_name'} = $1;
1832 $co{'committer_email'} = $2;
1834 $co{'committer_name'} = $co{'committer'};
1838 if (!defined $co{'tree'}) {
1841 $co{'parents'} = \
@parents;
1842 $co{'parent'} = $parents[0];
1844 foreach my $title (@commit_lines) {
1847 $co{'title'} = chop_str
($title, 80, 5);
1848 # remove leading stuff of merges to make the interesting part visible
1849 if (length($title) > 50) {
1850 $title =~ s/^Automatic //;
1851 $title =~ s/^merge (of|with) /Merge ... /i;
1852 if (length($title) > 50) {
1853 $title =~ s/(http|rsync):\/\///;
1855 if (length($title) > 50) {
1856 $title =~ s/(master|www|rsync)\.//;
1858 if (length($title) > 50) {
1859 $title =~ s/kernel.org:?//;
1861 if (length($title) > 50) {
1862 $title =~ s/\/pub\/scm//;
1865 $co{'title_short'} = chop_str
($title, 50, 5);
1869 if ($co{'title'} eq "") {
1870 $co{'title'} = $co{'title_short'} = '(no commit message)';
1872 # remove added spaces
1873 foreach my $line (@commit_lines) {
1876 $co{'comment'} = \
@commit_lines;
1878 my $age = time - $co{'committer_epoch'};
1880 $co{'age_string'} = age_string
($age);
1881 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1882 if ($age > 60*60*24*7*2) {
1883 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1884 $co{'age_string_age'} = $co{'age_string'};
1886 $co{'age_string_date'} = $co{'age_string'};
1887 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1893 my ($commit_id) = @_;
1898 open my $fd, "-|", git_cmd
(), "rev-list",
1904 or die_error
(undef, "Open git-rev-list failed");
1905 %co = parse_commit_text
(<$fd>, 1);
1912 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1920 open my $fd, "-|", git_cmd
(), "rev-list",
1922 ($arg ? ($arg) : ()),
1923 ("--max-count=" . $maxcount),
1924 ("--skip=" . $skip),
1928 ($filename ? ($filename) : ())
1929 or die_error
(undef, "Open git-rev-list failed");
1930 while (my $line = <$fd>) {
1931 my %co = parse_commit_text
($line);
1936 return wantarray ? @cos : \
@cos;
1939 # parse ref from ref_file, given by ref_id, with given type
1941 my $ref_file = shift;
1943 my $type = shift || git_get_type
($ref_id);
1946 $ref_item{'type'} = $type;
1947 $ref_item{'id'} = $ref_id;
1948 $ref_item{'epoch'} = 0;
1949 $ref_item{'age'} = "unknown";
1950 if ($type eq "tag") {
1951 my %tag = parse_tag
($ref_id);
1952 $ref_item{'comment'} = $tag{'comment'};
1953 if ($tag{'type'} eq "commit") {
1954 my %co = parse_commit
($tag{'object'});
1955 $ref_item{'epoch'} = $co{'committer_epoch'};
1956 $ref_item{'age'} = $co{'age_string'};
1957 } elsif (defined($tag{'epoch'})) {
1958 my $age = time - $tag{'epoch'};
1959 $ref_item{'epoch'} = $tag{'epoch'};
1960 $ref_item{'age'} = age_string
($age);
1962 $ref_item{'reftype'} = $tag{'type'};
1963 $ref_item{'name'} = $tag{'name'};
1964 $ref_item{'refid'} = $tag{'object'};
1965 } elsif ($type eq "commit"){
1966 my %co = parse_commit
($ref_id);
1967 $ref_item{'reftype'} = "commit";
1968 $ref_item{'name'} = $ref_file;
1969 $ref_item{'title'} = $co{'title'};
1970 $ref_item{'refid'} = $ref_id;
1971 $ref_item{'epoch'} = $co{'committer_epoch'};
1972 $ref_item{'age'} = $co{'age_string'};
1974 $ref_item{'reftype'} = $type;
1975 $ref_item{'name'} = $ref_file;
1976 $ref_item{'refid'} = $ref_id;
1982 # parse line of git-diff-tree "raw" output
1983 sub parse_difftree_raw_line
{
1987 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1988 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1989 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1990 $res{'from_mode'} = $1;
1991 $res{'to_mode'} = $2;
1992 $res{'from_id'} = $3;
1994 $res{'status'} = $5;
1995 $res{'similarity'} = $6;
1996 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1997 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1999 $res{'file'} = unquote
($7);
2002 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2003 # combined diff (for merge commit)
2004 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2005 $res{'nparents'} = length($1);
2006 $res{'from_mode'} = [ split(' ', $2) ];
2007 $res{'to_mode'} = pop @{$res{'from_mode'}};
2008 $res{'from_id'} = [ split(' ', $3) ];
2009 $res{'to_id'} = pop @{$res{'from_id'}};
2010 $res{'status'} = [ split('', $4) ];
2011 $res{'to_file'} = unquote
($5);
2013 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2014 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2015 $res{'commit'} = $1;
2018 return wantarray ? %res : \
%res;
2021 # parse line of git-ls-tree output
2022 sub parse_ls_tree_line
($;%) {
2027 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2028 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2036 $res{'name'} = unquote
($4);
2039 return wantarray ? %res : \
%res;
2042 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2043 sub parse_from_to_diffinfo
{
2044 my ($diffinfo, $from, $to, @parents) = @_;
2046 if ($diffinfo->{'nparents'}) {
2048 $from->{'file'} = [];
2049 $from->{'href'} = [];
2050 fill_from_file_info
($diffinfo, @parents)
2051 unless exists $diffinfo->{'from_file'};
2052 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2053 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2054 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2055 $from->{'href'}[$i] = href
(action
=>"blob",
2056 hash_base
=>$parents[$i],
2057 hash
=>$diffinfo->{'from_id'}[$i],
2058 file_name
=>$from->{'file'}[$i]);
2060 $from->{'href'}[$i] = undef;
2064 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2065 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2066 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2067 hash
=>$diffinfo->{'from_id'},
2068 file_name
=>$from->{'file'});
2070 delete $from->{'href'};
2074 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2075 if (!is_deleted
($diffinfo)) { # file exists in result
2076 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2077 hash
=>$diffinfo->{'to_id'},
2078 file_name
=>$to->{'file'});
2080 delete $to->{'href'};
2084 ## ......................................................................
2085 ## parse to array of hashes functions
2087 sub git_get_heads_list
{
2091 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2092 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2093 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2096 while (my $line = <$fd>) {
2100 my ($refinfo, $committerinfo) = split(/\0/, $line);
2101 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2102 my ($committer, $epoch, $tz) =
2103 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2104 $name =~ s!^refs/heads/!!;
2106 $ref_item{'name'} = $name;
2107 $ref_item{'id'} = $hash;
2108 $ref_item{'title'} = $title || '(no commit message)';
2109 $ref_item{'epoch'} = $epoch;
2111 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2113 $ref_item{'age'} = "unknown";
2116 push @headslist, \
%ref_item;
2120 return wantarray ? @headslist : \
@headslist;
2123 sub git_get_tags_list
{
2127 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2128 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2129 '--format=%(objectname) %(objecttype) %(refname) '.
2130 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2133 while (my $line = <$fd>) {
2137 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2138 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2139 my ($creator, $epoch, $tz) =
2140 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2141 $name =~ s!^refs/tags/!!;
2143 $ref_item{'type'} = $type;
2144 $ref_item{'id'} = $id;
2145 $ref_item{'name'} = $name;
2146 if ($type eq "tag") {
2147 $ref_item{'subject'} = $title;
2148 $ref_item{'reftype'} = $reftype;
2149 $ref_item{'refid'} = $refid;
2151 $ref_item{'reftype'} = $type;
2152 $ref_item{'refid'} = $id;
2155 if ($type eq "tag" || $type eq "commit") {
2156 $ref_item{'epoch'} = $epoch;
2158 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2160 $ref_item{'age'} = "unknown";
2164 push @tagslist, \
%ref_item;
2168 return wantarray ? @tagslist : \
@tagslist;
2171 ## ----------------------------------------------------------------------
2172 ## filesystem-related functions
2174 sub get_file_owner
{
2177 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2178 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2179 if (!defined $gcos) {
2183 $owner =~ s/[,;].*$//;
2184 return to_utf8
($owner);
2187 ## ......................................................................
2188 ## mimetype related functions
2190 sub mimetype_guess_file
{
2191 my $filename = shift;
2192 my $mimemap = shift;
2193 -r
$mimemap or return undef;
2196 open(MIME
, $mimemap) or return undef;
2198 next if m/^#/; # skip comments
2199 my ($mime, $exts) = split(/\t+/);
2200 if (defined $exts) {
2201 my @exts = split(/\s+/, $exts);
2202 foreach my $ext (@exts) {
2203 $mimemap{$ext} = $mime;
2209 $filename =~ /\.([^.]*)$/;
2210 return $mimemap{$1};
2213 sub mimetype_guess
{
2214 my $filename = shift;
2216 $filename =~ /\./ or return undef;
2218 if ($mimetypes_file) {
2219 my $file = $mimetypes_file;
2220 if ($file !~ m!^/!) { # if it is relative path
2221 # it is relative to project
2222 $file = "$projectroot/$project/$file";
2224 $mime = mimetype_guess_file
($filename, $file);
2226 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2232 my $filename = shift;
2235 my $mime = mimetype_guess
($filename);
2236 $mime and return $mime;
2240 return $default_blob_plain_mimetype unless $fd;
2243 return 'text/plain' .
2244 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2245 } elsif (! $filename) {
2246 return 'application/octet-stream';
2247 } elsif ($filename =~ m/\.png$/i) {
2249 } elsif ($filename =~ m/\.gif$/i) {
2251 } elsif ($filename =~ m/\.jpe?g$/i) {
2252 return 'image/jpeg';
2254 return 'application/octet-stream';
2258 ## ======================================================================
2259 ## functions printing HTML: header, footer, error page
2261 sub git_header_html
{
2262 my $status = shift || "200 OK";
2263 my $expires = shift;
2265 my $title = "$site_name";
2266 if (defined $project) {
2267 $title .= " - " . to_utf8
($project);
2268 if (defined $action) {
2269 $title .= "/$action";
2270 if (defined $file_name) {
2271 $title .= " - " . esc_path
($file_name);
2272 if ($action eq "tree" && $file_name !~ m
|/$|) {
2279 # require explicit support from the UA if we are to send the page as
2280 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2281 # we have to do this because MSIE sometimes globs '*/*', pretending to
2282 # support xhtml+xml but choking when it gets what it asked for.
2283 if (defined $cgi->http('HTTP_ACCEPT') &&
2284 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2285 $cgi->Accept('application/xhtml+xml') != 0) {
2286 $content_type = 'application/xhtml+xml';
2288 $content_type = 'text/html';
2290 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2291 -status
=> $status, -expires
=> $expires);
2292 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2294 <?xml version="1.0" encoding="utf-8"?>
2295 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2296 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2297 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2298 <!-- git core binaries version $git_version -->
2300 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2301 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2302 <meta name="robots" content="index, nofollow"/>
2303 <title>$title</title>
2305 # print out each stylesheet that exist
2306 if (defined $stylesheet) {
2307 #provides backwards capability for those people who define style sheet in a config file
2308 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2310 foreach my $stylesheet (@stylesheets) {
2311 next unless $stylesheet;
2312 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2315 if (defined $project) {
2316 printf('<link rel="alternate" title="%s log RSS feed" '.
2317 'href="%s" type="application/rss+xml" />'."\n",
2318 esc_param
($project), href
(action
=>"rss"));
2319 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2320 'href="%s" type="application/rss+xml" />'."\n",
2321 esc_param
($project), href
(action
=>"rss",
2322 extra_options
=>"--no-merges"));
2323 printf('<link rel="alternate" title="%s log Atom feed" '.
2324 'href="%s" type="application/atom+xml" />'."\n",
2325 esc_param
($project), href
(action
=>"atom"));
2326 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2327 'href="%s" type="application/atom+xml" />'."\n",
2328 esc_param
($project), href
(action
=>"atom",
2329 extra_options
=>"--no-merges"));
2331 printf('<link rel="alternate" title="%s projects list" '.
2332 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2333 $site_name, href
(project
=>undef, action
=>"project_index"));
2334 printf('<link rel="alternate" title="%s projects feeds" '.
2335 'href="%s" type="text/x-opml"/>'."\n",
2336 $site_name, href
(project
=>undef, action
=>"opml"));
2338 if (defined $favicon) {
2339 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2345 if (-f
$site_header) {
2346 open (my $fd, $site_header);
2351 print "<div class=\"page_header\">\n" .
2352 $cgi->a({-href
=> esc_url
($logo_url),
2353 -title
=> $logo_label},
2354 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2355 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2356 if (defined $project) {
2357 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2358 if (defined $action) {
2365 my ($have_search) = gitweb_check_feature
('search');
2366 if ((defined $project) && ($have_search)) {
2367 if (!defined $searchtext) {
2371 if (defined $hash_base) {
2372 $search_hash = $hash_base;
2373 } elsif (defined $hash) {
2374 $search_hash = $hash;
2376 $search_hash = "HEAD";
2378 my $action = $my_uri;
2379 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2380 if ($use_pathinfo) {
2381 $action .= "/$project";
2383 $cgi->param("p", $project);
2385 $cgi->param("a", "search");
2386 $cgi->param("h", $search_hash);
2387 print $cgi->startform(-method => "get", -action
=> $action) .
2388 "<div class=\"search\">\n" .
2389 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2390 $cgi->hidden(-name
=> "a") . "\n" .
2391 $cgi->hidden(-name
=> "h") . "\n" .
2392 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2393 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2394 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2396 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2398 $cgi->end_form() . "\n";
2402 sub git_footer_html
{
2403 print "<div class=\"page_footer\">\n";
2404 if (defined $project) {
2405 my $descr = git_get_project_description
($project);
2406 if (defined $descr) {
2407 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2409 print $cgi->a({-href
=> href
(action
=>"rss"),
2410 -class => "rss_logo"}, "RSS") . " ";
2411 print $cgi->a({-href
=> href
(action
=>"atom"),
2412 -class => "rss_logo"}, "Atom") . "\n";
2414 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2415 -class => "rss_logo"}, "OPML") . " ";
2416 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2417 -class => "rss_logo"}, "TXT") . "\n";
2421 if (-f
$site_footer) {
2422 open (my $fd, $site_footer);
2432 my $status = shift || "403 Forbidden";
2433 my $error = shift || "Malformed query, file missing or permission denied";
2435 git_header_html
($status);
2437 <div class="page_body">
2447 ## ----------------------------------------------------------------------
2448 ## functions printing or outputting HTML: navigation
2450 sub git_print_page_nav
{
2451 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2452 $extra = '' if !defined $extra; # pager or formats
2454 my @navs = qw(summary shortlog log commit commitdiff tree);
2456 @navs = grep { $_ ne $suppress } @navs;
2459 my %arg = map { $_ => {action
=>$_} } @navs;
2460 if (defined $head) {
2461 for (qw(commit commitdiff)) {
2462 $arg{$_}{'hash'} = $head;
2464 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2465 for (qw(shortlog log)) {
2466 $arg{$_}{'hash'} = $head;
2470 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2471 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2473 print "<div class=\"page_nav\">\n" .
2475 map { $_ eq $current ?
2476 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2478 print "<br/>\n$extra<br/>\n" .
2482 sub format_paging_nav
{
2483 my ($action, $hash, $head, $page, $nrevs) = @_;
2487 if ($hash ne $head || $page) {
2488 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2490 $paging_nav .= "HEAD";
2494 $paging_nav .= " ⋅ " .
2495 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2496 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2498 $paging_nav .= " ⋅ prev";
2501 if ($nrevs >= (100 * ($page+1)-1)) {
2502 $paging_nav .= " ⋅ " .
2503 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2504 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2506 $paging_nav .= " ⋅ next";
2512 ## ......................................................................
2513 ## functions printing or outputting HTML: div
2515 sub git_print_header_div
{
2516 my ($action, $title, $hash, $hash_base) = @_;
2519 $args{'action'} = $action;
2520 $args{'hash'} = $hash if $hash;
2521 $args{'hash_base'} = $hash_base if $hash_base;
2523 print "<div class=\"header\">\n" .
2524 $cgi->a({-href
=> href
(%args), -class => "title"},
2525 $title ? $title : $action) .
2529 #sub git_print_authorship (\%) {
2530 sub git_print_authorship
{
2533 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2534 print "<div class=\"author_date\">" .
2535 esc_html
($co->{'author_name'}) .
2537 if ($ad{'hour_local'} < 6) {
2538 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2539 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2541 printf(" (%02d:%02d %s)",
2542 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2547 sub git_print_page_path
{
2553 print "<div class=\"page_path\">";
2554 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2555 -title
=> 'tree root'}, to_utf8
("[$project]"));
2557 if (defined $name) {
2558 my @dirname = split '/', $name;
2559 my $basename = pop @dirname;
2562 foreach my $dir (@dirname) {
2563 $fullname .= ($fullname ? '/' : '') . $dir;
2564 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2566 -title
=> $fullname}, esc_path
($dir));
2569 if (defined $type && $type eq 'blob') {
2570 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2572 -title
=> $name}, esc_path
($basename));
2573 } elsif (defined $type && $type eq 'tree') {
2574 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2576 -title
=> $name}, esc_path
($basename));
2579 print esc_path
($basename);
2582 print "<br/></div>\n";
2585 # sub git_print_log (\@;%) {
2586 sub git_print_log
($;%) {
2590 if ($opts{'-remove_title'}) {
2591 # remove title, i.e. first line of log
2594 # remove leading empty lines
2595 while (defined $log->[0] && $log->[0] eq "") {
2602 foreach my $line (@$log) {
2603 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2606 if (! $opts{'-remove_signoff'}) {
2607 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2610 # remove signoff lines
2617 # print only one empty line
2618 # do not print empty line after signoff
2620 next if ($empty || $signoff);
2626 print format_log_line_html
($line) . "<br/>\n";
2629 if ($opts{'-final_empty_line'}) {
2630 # end with single empty line
2631 print "<br/>\n" unless $empty;
2635 # return link target (what link points to)
2636 sub git_get_link_target
{
2641 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2645 $link_target = <$fd>;
2650 return $link_target;
2653 # given link target, and the directory (basedir) the link is in,
2654 # return target of link relative to top directory (top tree);
2655 # return undef if it is not possible (including absolute links).
2656 sub normalize_link_target
{
2657 my ($link_target, $basedir, $hash_base) = @_;
2659 # we can normalize symlink target only if $hash_base is provided
2660 return unless $hash_base;
2662 # absolute symlinks (beginning with '/') cannot be normalized
2663 return if (substr($link_target, 0, 1) eq '/');
2665 # normalize link target to path from top (root) tree (dir)
2668 $path = $basedir . '/' . $link_target;
2670 # we are in top (root) tree (dir)
2671 $path = $link_target;
2674 # remove //, /./, and /../
2676 foreach my $part (split('/', $path)) {
2677 # discard '.' and ''
2678 next if (!$part || $part eq '.');
2680 if ($part eq '..') {
2684 # link leads outside repository (outside top dir)
2688 push @path_parts, $part;
2691 $path = join('/', @path_parts);
2696 # print tree entry (row of git_tree), but without encompassing <tr> element
2697 sub git_print_tree_entry
{
2698 my ($t, $basedir, $hash_base, $have_blame) = @_;
2701 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2703 # The format of a table row is: mode list link. Where mode is
2704 # the mode of the entry, list is the name of the entry, an href,
2705 # and link is the action links of the entry.
2707 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2708 if ($t->{'type'} eq "blob") {
2709 print "<td class=\"list\">" .
2710 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2711 file_name
=>"$basedir$t->{'name'}", %base_key),
2712 -class => "list"}, esc_path
($t->{'name'}));
2713 if (S_ISLNK
(oct $t->{'mode'})) {
2714 my $link_target = git_get_link_target
($t->{'hash'});
2716 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2717 if (defined $norm_target) {
2719 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2720 file_name
=>$norm_target),
2721 -title
=> $norm_target}, esc_path
($link_target));
2723 print " -> " . esc_path
($link_target);
2728 print "<td class=\"link\">";
2729 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2730 file_name
=>"$basedir$t->{'name'}", %base_key)},
2734 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2735 file_name
=>"$basedir$t->{'name'}", %base_key)},
2738 if (defined $hash_base) {
2740 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2741 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2745 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2746 file_name
=>"$basedir$t->{'name'}")},
2750 } elsif ($t->{'type'} eq "tree") {
2751 print "<td class=\"list\">";
2752 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2753 file_name
=>"$basedir$t->{'name'}", %base_key)},
2754 esc_path
($t->{'name'}));
2756 print "<td class=\"link\">";
2757 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2758 file_name
=>"$basedir$t->{'name'}", %base_key)},
2760 if (defined $hash_base) {
2762 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2763 file_name
=>"$basedir$t->{'name'}")},
2768 # unknown object: we can only present history for it
2769 # (this includes 'commit' object, i.e. submodule support)
2770 print "<td class=\"list\">" .
2771 esc_path
($t->{'name'}) .
2773 print "<td class=\"link\">";
2774 if (defined $hash_base) {
2775 print $cgi->a({-href
=> href
(action
=>"history",
2776 hash_base
=>$hash_base,
2777 file_name
=>"$basedir$t->{'name'}")},
2784 ## ......................................................................
2785 ## functions printing large fragments of HTML
2787 sub fill_from_file_info
{
2788 my ($diff, @parents) = @_;
2790 $diff->{'from_file'} = [ ];
2791 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2792 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2793 if ($diff->{'status'}[$i] eq 'R' ||
2794 $diff->{'status'}[$i] eq 'C') {
2795 $diff->{'from_file'}[$i] =
2796 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2803 # parameters can be strings, or references to arrays of strings
2807 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2808 for (my $i = 0; $i < @$a; ++$i) {
2809 return 0 unless ($a->[$i] eq $b->[$i]);
2812 } elsif (!ref($a) && !ref($b)) {
2820 my $diffinfo = shift;
2822 return $diffinfo->{'to_id'} eq ('0' x
40);
2825 sub git_difftree_body
{
2826 my ($difftree, $hash, @parents) = @_;
2827 my ($parent) = $parents[0];
2828 my ($have_blame) = gitweb_check_feature
('blame');
2829 print "<div class=\"list_head\">\n";
2830 if ($#{$difftree} > 10) {
2831 print(($#{$difftree} + 1) . " files changed:\n");
2835 print "<table class=\"" .
2836 (@parents > 1 ? "combined " : "") .
2839 # header only for combined diff in 'commitdiff' view
2840 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
2843 print "<thead><tr>\n" .
2844 "<th></th><th></th>\n"; # filename, patchN link
2845 for (my $i = 0; $i < @parents; $i++) {
2846 my $par = $parents[$i];
2848 $cgi->a({-href
=> href
(action
=>"commitdiff",
2849 hash
=>$hash, hash_parent
=>$par),
2850 -title
=> 'commitdiff to parent number ' .
2851 ($i+1) . ': ' . substr($par,0,7)},
2855 print "</tr></thead>\n<tbody>\n";
2860 foreach my $line (@{$difftree}) {
2862 if (ref($line) eq "HASH") {
2863 # pre-parsed (or generated by hand)
2866 $diff = parse_difftree_raw_line
($line);
2870 print "<tr class=\"dark\">\n";
2872 print "<tr class=\"light\">\n";
2876 if (exists $diff->{'nparents'}) { # combined diff
2878 fill_from_file_info
($diff, @parents)
2879 unless exists $diff->{'from_file'};
2881 if (!is_deleted
($diff)) {
2882 # file exists in the result (child) commit
2884 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2885 file_name
=>$diff->{'to_file'},
2887 -class => "list"}, esc_path
($diff->{'to_file'})) .
2891 esc_path
($diff->{'to_file'}) .
2895 if ($action eq 'commitdiff') {
2898 print "<td class=\"link\">" .
2899 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2904 my $has_history = 0;
2905 my $not_deleted = 0;
2906 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2907 my $hash_parent = $parents[$i];
2908 my $from_hash = $diff->{'from_id'}[$i];
2909 my $from_path = $diff->{'from_file'}[$i];
2910 my $status = $diff->{'status'}[$i];
2912 $has_history ||= ($status ne 'A');
2913 $not_deleted ||= ($status ne 'D');
2915 if ($status eq 'A') {
2916 print "<td class=\"link\" align=\"right\"> | </td>\n";
2917 } elsif ($status eq 'D') {
2918 print "<td class=\"link\">" .
2919 $cgi->a({-href
=> href
(action
=>"blob",
2922 file_name
=>$from_path)},
2926 if ($diff->{'to_id'} eq $from_hash) {
2927 print "<td class=\"link nochange\">";
2929 print "<td class=\"link\">";
2931 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2932 hash
=>$diff->{'to_id'},
2933 hash_parent
=>$from_hash,
2935 hash_parent_base
=>$hash_parent,
2936 file_name
=>$diff->{'to_file'},
2937 file_parent
=>$from_path)},
2943 print "<td class=\"link\">";
2945 print $cgi->a({-href
=> href
(action
=>"blob",
2946 hash
=>$diff->{'to_id'},
2947 file_name
=>$diff->{'to_file'},
2950 print " | " if ($has_history);
2953 print $cgi->a({-href
=> href
(action
=>"history",
2954 file_name
=>$diff->{'to_file'},
2961 next; # instead of 'else' clause, to avoid extra indent
2963 # else ordinary diff
2965 my ($to_mode_oct, $to_mode_str, $to_file_type);
2966 my ($from_mode_oct, $from_mode_str, $from_file_type);
2967 if ($diff->{'to_mode'} ne ('0' x
6)) {
2968 $to_mode_oct = oct $diff->{'to_mode'};
2969 if (S_ISREG
($to_mode_oct)) { # only for regular file
2970 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2972 $to_file_type = file_type
($diff->{'to_mode'});
2974 if ($diff->{'from_mode'} ne ('0' x
6)) {
2975 $from_mode_oct = oct $diff->{'from_mode'};
2976 if (S_ISREG
($to_mode_oct)) { # only for regular file
2977 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2979 $from_file_type = file_type
($diff->{'from_mode'});
2982 if ($diff->{'status'} eq "A") { # created
2983 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2984 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2985 $mode_chng .= "]</span>";
2987 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2988 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2989 -class => "list"}, esc_path
($diff->{'file'}));
2991 print "<td>$mode_chng</td>\n";
2992 print "<td class=\"link\">";
2993 if ($action eq 'commitdiff') {
2996 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2999 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3000 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3004 } elsif ($diff->{'status'} eq "D") { # deleted
3005 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3007 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3008 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3009 -class => "list"}, esc_path
($diff->{'file'}));
3011 print "<td>$mode_chng</td>\n";
3012 print "<td class=\"link\">";
3013 if ($action eq 'commitdiff') {
3016 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3019 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3020 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3023 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3024 file_name
=>$diff->{'file'})},
3027 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3028 file_name
=>$diff->{'file'})},
3032 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3033 my $mode_chnge = "";
3034 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3035 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3036 if ($from_file_type ne $to_file_type) {
3037 $mode_chnge .= " from $from_file_type to $to_file_type";
3039 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3040 if ($from_mode_str && $to_mode_str) {
3041 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3042 } elsif ($to_mode_str) {
3043 $mode_chnge .= " mode: $to_mode_str";
3046 $mode_chnge .= "]</span>\n";
3049 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3050 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3051 -class => "list"}, esc_path
($diff->{'file'}));
3053 print "<td>$mode_chnge</td>\n";
3054 print "<td class=\"link\">";
3055 if ($action eq 'commitdiff') {
3058 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3060 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3061 # "commit" view and modified file (not onlu mode changed)
3062 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3063 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3064 hash_base
=>$hash, hash_parent_base
=>$parent,
3065 file_name
=>$diff->{'file'})},
3069 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3070 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3073 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3074 file_name
=>$diff->{'file'})},
3077 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3078 file_name
=>$diff->{'file'})},
3082 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3083 my %status_name = ('R' => 'moved', 'C' => 'copied');
3084 my $nstatus = $status_name{$diff->{'status'}};
3086 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3087 # mode also for directories, so we cannot use $to_mode_str
3088 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3091 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3092 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3093 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3094 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3095 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3096 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3097 -class => "list"}, esc_path
($diff->{'from_file'})) .
3098 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3099 "<td class=\"link\">";
3100 if ($action eq 'commitdiff') {
3103 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3105 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3106 # "commit" view and modified file (not only pure rename or copy)
3107 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3108 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3109 hash_base
=>$hash, hash_parent_base
=>$parent,
3110 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3114 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3115 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3118 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3119 file_name
=>$diff->{'to_file'})},
3122 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3123 file_name
=>$diff->{'to_file'})},
3127 } # we should not encounter Unmerged (U) or Unknown (X) status
3130 print "</tbody>" if $has_header;
3134 sub git_patchset_body
{
3135 my ($fd, $difftree, $hash, @hash_parents) = @_;
3136 my ($hash_parent) = $hash_parents[0];
3139 my $patch_number = 0;
3144 print "<div class=\"patchset\">\n";
3146 # skip to first patch
3147 while ($patch_line = <$fd>) {
3150 last if ($patch_line =~ m/^diff /);
3154 while ($patch_line) {
3156 my ($from_id, $to_id);
3159 #assert($patch_line =~ m/^diff /) if DEBUG;
3160 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3162 push @diff_header, $patch_line;
3164 # extended diff header
3166 while ($patch_line = <$fd>) {
3169 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3171 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3174 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3175 $from_id = [ split(',', $1) ];
3179 push @diff_header, $patch_line;
3181 my $last_patch_line = $patch_line;
3183 # check if current patch belong to current raw line
3184 # and parse raw git-diff line if needed
3185 if (defined $diffinfo &&
3186 defined $from_id && defined $to_id &&
3187 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3188 $diffinfo->{'to_id'} eq $to_id) {
3189 # this is continuation of a split patch
3190 print "<div class=\"patch cont\">\n";
3192 # advance raw git-diff output if needed
3193 $patch_idx++ if defined $diffinfo;
3195 # compact combined diff output can have some patches skipped
3196 # find which patch (using pathname of result) we are at now
3198 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3203 # read and prepare patch information
3204 if (ref($difftree->[$patch_idx]) eq "HASH") {
3205 # pre-parsed (or generated by hand)
3206 $diffinfo = $difftree->[$patch_idx];
3208 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3211 # check if current raw line has no patch (it got simplified)
3212 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3213 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3214 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3215 "</div>\n"; # class="patch"
3220 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3221 $patch_idx > $#$difftree);
3223 # modifies %from, %to hashes
3224 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3226 # this is first patch for raw difftree line with $patch_idx index
3227 # we index @$difftree array from 0, but number patches from 1
3228 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3231 # print "git diff" header
3232 $patch_line = shift @diff_header;
3233 print format_git_diff_header_line
($patch_line, $diffinfo,
3236 # print extended diff header
3237 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3239 foreach $patch_line (@diff_header) {
3240 print format_extended_diff_header_line
($patch_line, $diffinfo,
3243 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3245 # from-file/to-file diff header
3246 $patch_line = $last_patch_line;
3247 if (! $patch_line) {
3248 print "</div>\n"; # class="patch"
3251 next PATCH
if ($patch_line =~ m/^diff /);
3252 #assert($patch_line =~ m/^---/) if DEBUG;
3253 #assert($patch_line eq $last_patch_line) if DEBUG;
3255 $patch_line = <$fd>;
3257 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3259 print format_diff_from_to_header
($last_patch_line, $patch_line,
3260 $diffinfo, \
%from, \
%to,
3265 while ($patch_line = <$fd>) {
3268 next PATCH
if ($patch_line =~ m/^diff /);
3270 print format_diff_line
($patch_line, \
%from, \
%to);
3274 print "</div>\n"; # class="patch"
3277 # for compact combined (--cc) format, with chunk and patch simpliciaction
3278 # patchset might be empty, but there might be unprocessed raw lines
3279 for ($patch_idx++ if $patch_number > 0;
3280 $patch_idx < @$difftree;
3282 # read and prepare patch information
3283 if (ref($difftree->[$patch_idx]) eq "HASH") {
3284 # pre-parsed (or generated by hand)
3285 $diffinfo = $difftree->[$patch_idx];
3287 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3290 # generate anchor for "patch" links in difftree / whatchanged part
3291 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3292 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3293 "</div>\n"; # class="patch"
3298 if ($patch_number == 0) {
3299 if (@hash_parents > 1) {
3300 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3302 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3306 print "</div>\n"; # class="patchset"
3309 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3311 sub git_project_list_body
{
3312 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3314 my ($check_forks) = gitweb_check_feature
('forks');
3317 foreach my $pr (@$projlist) {
3318 my (@aa) = git_get_last_activity
($pr->{'path'});
3322 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3323 if (!defined $pr->{'descr'}) {
3324 my $descr = git_get_project_description
($pr->{'path'}) || "";
3325 $pr->{'descr_long'} = to_utf8
($descr);
3326 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3328 if (!defined $pr->{'owner'}) {
3329 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3332 my $pname = $pr->{'path'};
3333 if (($pname =~ s/\.git$//) &&
3334 ($pname !~ /\/$/) &&
3335 (-d
"$projectroot/$pname")) {
3336 $pr->{'forks'} = "-d $projectroot/$pname";
3342 push @projects, $pr;
3345 $order ||= $default_projects_order;
3346 $from = 0 unless defined $from;
3347 $to = $#projects if (!defined $to || $#projects < $to);
3349 print "<table class=\"project_list\">\n";
3350 unless ($no_header) {
3353 print "<th></th>\n";
3355 if ($order eq "project") {
3356 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3357 print "<th>Project</th>\n";
3360 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3361 -class => "header"}, "Project") .
3364 if ($order eq "descr") {
3365 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3366 print "<th>Description</th>\n";
3369 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3370 -class => "header"}, "Description") .
3373 if ($order eq "owner") {
3374 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3375 print "<th>Owner</th>\n";
3378 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3379 -class => "header"}, "Owner") .
3382 if ($order eq "age") {
3383 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3384 print "<th>Last Change</th>\n";
3387 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3388 -class => "header"}, "Last Change") .
3391 print "<th></th>\n" .
3395 for (my $i = $from; $i <= $to; $i++) {
3396 my $pr = $projects[$i];
3398 print "<tr class=\"dark\">\n";
3400 print "<tr class=\"light\">\n";
3405 if ($pr->{'forks'}) {
3406 print "<!-- $pr->{'forks'} -->\n";
3407 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3411 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3412 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3413 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3414 -class => "list", -title
=> $pr->{'descr_long'}},
3415 esc_html
($pr->{'descr'})) . "</td>\n" .
3416 "<td><i>" . esc_html
(chop_str
($pr->{'owner'}, 15)) . "</i></td>\n";
3417 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3418 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3419 "<td class=\"link\">" .
3420 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3421 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3422 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3423 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3424 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3428 if (defined $extra) {
3431 print "<td></td>\n";
3433 print "<td colspan=\"5\">$extra</td>\n" .
3439 sub git_shortlog_body
{
3440 # uses global variable $project
3441 my ($commitlist, $from, $to, $refs, $extra) = @_;
3443 $from = 0 unless defined $from;
3444 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3446 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3448 for (my $i = $from; $i <= $to; $i++) {
3449 my %co = %{$commitlist->[$i]};
3450 my $commit = $co{'id'};
3451 my $ref = format_ref_marker
($refs, $commit);
3453 print "<tr class=\"dark\">\n";
3455 print "<tr class=\"light\">\n";
3458 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3459 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3460 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3461 "<td><i>" . $author . "</i></td>\n" .
3463 print format_subject_html
($co{'title'}, $co{'title_short'},
3464 href
(action
=>"commit", hash
=>$commit), $ref);
3466 "<td class=\"link\">" .
3467 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3468 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3469 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3470 my $snapshot_links = format_snapshot_links
($commit);
3471 if (defined $snapshot_links) {
3472 print " | " . $snapshot_links;
3477 if (defined $extra) {
3479 "<td colspan=\"4\">$extra</td>\n" .
3485 sub git_history_body
{
3486 # Warning: assumes constant type (blob or tree) during history
3487 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3489 $from = 0 unless defined $from;
3490 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3492 print "<table class=\"history\" cellspacing=\"0\">\n";
3494 for (my $i = $from; $i <= $to; $i++) {
3495 my %co = %{$commitlist->[$i]};
3499 my $commit = $co{'id'};
3501 my $ref = format_ref_marker
($refs, $commit);
3504 print "<tr class=\"dark\">\n";
3506 print "<tr class=\"light\">\n";
3509 # shortlog uses chop_str($co{'author_name'}, 10)
3510 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3511 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3512 "<td><i>" . $author . "</i></td>\n" .
3514 # originally git_history used chop_str($co{'title'}, 50)
3515 print format_subject_html
($co{'title'}, $co{'title_short'},
3516 href
(action
=>"commit", hash
=>$commit), $ref);
3518 "<td class=\"link\">" .
3519 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3520 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3522 if ($ftype eq 'blob') {
3523 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3524 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3525 if (defined $blob_current && defined $blob_parent &&
3526 $blob_current ne $blob_parent) {
3528 $cgi->a({-href
=> href
(action
=>"blobdiff",
3529 hash
=>$blob_current, hash_parent
=>$blob_parent,
3530 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3531 file_name
=>$file_name)},
3538 if (defined $extra) {
3540 "<td colspan=\"4\">$extra</td>\n" .
3547 # uses global variable $project
3548 my ($taglist, $from, $to, $extra) = @_;
3549 $from = 0 unless defined $from;
3550 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3552 print "<table class=\"tags\" cellspacing=\"0\">\n";
3554 for (my $i = $from; $i <= $to; $i++) {
3555 my $entry = $taglist->[$i];
3557 my $comment = $tag{'subject'};
3559 if (defined $comment) {
3560 $comment_short = chop_str
($comment, 30, 5);
3563 print "<tr class=\"dark\">\n";
3565 print "<tr class=\"light\">\n";
3568 if (defined $tag{'age'}) {
3569 print "<td><i>$tag{'age'}</i></td>\n";
3571 print "<td></td>\n";
3574 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3575 -class => "list name"}, esc_html
($tag{'name'})) .
3578 if (defined $comment) {
3579 print format_subject_html
($comment, $comment_short,
3580 href
(action
=>"tag", hash
=>$tag{'id'}));
3583 "<td class=\"selflink\">";
3584 if ($tag{'type'} eq "tag") {
3585 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3590 "<td class=\"link\">" . " | " .
3591 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3592 if ($tag{'reftype'} eq "commit") {
3593 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3594 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3595 } elsif ($tag{'reftype'} eq "blob") {
3596 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3601 if (defined $extra) {
3603 "<td colspan=\"5\">$extra</td>\n" .
3609 sub git_heads_body
{
3610 # uses global variable $project
3611 my ($headlist, $head, $from, $to, $extra) = @_;
3612 $from = 0 unless defined $from;
3613 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3615 print "<table class=\"heads\" cellspacing=\"0\">\n";
3617 for (my $i = $from; $i <= $to; $i++) {
3618 my $entry = $headlist->[$i];
3620 my $curr = $ref{'id'} eq $head;
3622 print "<tr class=\"dark\">\n";
3624 print "<tr class=\"light\">\n";
3627 print "<td><i>$ref{'age'}</i></td>\n" .
3628 ($curr ? "<td class=\"current_head\">" : "<td>") .
3629 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3630 -class => "list name"},esc_html
($ref{'name'})) .
3632 "<td class=\"link\">" .
3633 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3634 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3635 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3639 if (defined $extra) {
3641 "<td colspan=\"3\">$extra</td>\n" .
3647 sub git_search_grep_body
{
3648 my ($commitlist, $from, $to, $extra) = @_;
3649 $from = 0 unless defined $from;
3650 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3652 print "<table class=\"grep\" cellspacing=\"0\">\n";
3654 for (my $i = $from; $i <= $to; $i++) {
3655 my %co = %{$commitlist->[$i]};
3659 my $commit = $co{'id'};
3661 print "<tr class=\"dark\">\n";
3663 print "<tr class=\"light\">\n";
3666 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3667 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3668 "<td><i>" . $author . "</i></td>\n" .
3670 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3671 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3672 my $comment = $co{'comment'};
3673 foreach my $line (@$comment) {
3674 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3675 my $lead = esc_html
($1) || "";
3676 $lead = chop_str
($lead, 30, 10);
3677 my $match = esc_html
($2) || "";
3678 my $trail = esc_html
($3) || "";
3679 $trail = chop_str
($trail, 30, 10);
3680 my $text = "$lead<span class=\"match\">$match</span>$trail";
3681 print chop_str
($text, 80, 5) . "<br/>\n";
3685 "<td class=\"link\">" .
3686 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3688 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3692 if (defined $extra) {
3694 "<td colspan=\"3\">$extra</td>\n" .
3700 ## ======================================================================
3701 ## ======================================================================
3704 sub git_project_list
{
3705 my $order = $cgi->param('o');
3706 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3707 die_error
(undef, "Unknown order parameter");
3710 my @list = git_get_projects_list
();
3712 die_error
(undef, "No projects found");
3716 if (-f
$home_text) {
3717 print "<div class=\"index_include\">\n";
3718 open (my $fd, $home_text);
3723 git_project_list_body
(\
@list, $order);
3728 my $order = $cgi->param('o');
3729 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3730 die_error
(undef, "Unknown order parameter");
3733 my @list = git_get_projects_list
($project);
3735 die_error
(undef, "No forks found");
3739 git_print_page_nav
('','');
3740 git_print_header_div
('summary', "$project forks");
3741 git_project_list_body
(\
@list, $order);
3745 sub git_project_index
{
3746 my @projects = git_get_projects_list
($project);
3749 -type
=> 'text/plain',
3750 -charset
=> 'utf-8',
3751 -content_disposition
=> 'inline; filename="index.aux"');
3753 foreach my $pr (@projects) {
3754 if (!exists $pr->{'owner'}) {
3755 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3758 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3759 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3760 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3761 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3765 print "$path $owner\n";
3770 my $descr = git_get_project_description
($project) || "none";
3771 my %co = parse_commit
("HEAD");
3772 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3773 my $head = $co{'id'};
3775 my $owner = git_get_project_owner
($project);
3777 my $refs = git_get_references
();
3778 # These get_*_list functions return one more to allow us to see if
3779 # there are more ...
3780 my @taglist = git_get_tags_list
(16);
3781 my @headlist = git_get_heads_list
(16);
3783 my ($check_forks) = gitweb_check_feature
('forks');
3786 @forklist = git_get_projects_list
($project);
3790 git_print_page_nav
('summary','', $head);
3792 print "<div class=\"title\"> </div>\n";
3793 print "<table cellspacing=\"0\">\n" .
3794 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3795 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3796 if (defined $cd{'rfc2822'}) {
3797 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3800 # use per project git URL list in $projectroot/$project/cloneurl
3801 # or make project git URL from git base URL and project name
3802 my $url_tag = "URL";
3803 my @url_list = git_get_project_url_list
($project);
3804 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3805 foreach my $git_url (@url_list) {
3806 next unless $git_url;
3807 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3812 if (-s
"$projectroot/$project/README.html") {
3813 if (open my $fd, "$projectroot/$project/README.html") {
3814 print "<div class=\"title\">readme</div>\n";
3815 print $_ while (<$fd>);
3820 # we need to request one more than 16 (0..15) to check if
3822 my @commitlist = $head ? parse_commits
($head, 17) : ();
3824 git_print_header_div
('shortlog');
3825 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3826 $#commitlist <= 15 ? undef :
3827 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3831 git_print_header_div
('tags');
3832 git_tags_body
(\
@taglist, 0, 15,
3833 $#taglist <= 15 ? undef :
3834 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3838 git_print_header_div
('heads');
3839 git_heads_body
(\
@headlist, $head, 0, 15,
3840 $#headlist <= 15 ? undef :
3841 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3845 git_print_header_div
('forks');
3846 git_project_list_body
(\
@forklist, undef, 0, 15,
3847 $#forklist <= 15 ? undef :
3848 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3856 my $head = git_get_head_hash
($project);
3858 git_print_page_nav
('','', $head,undef,$head);
3859 my %tag = parse_tag
($hash);
3862 die_error
(undef, "Unknown tag object");
3865 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3866 print "<div class=\"title_text\">\n" .
3867 "<table cellspacing=\"0\">\n" .
3869 "<td>object</td>\n" .
3870 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3871 $tag{'object'}) . "</td>\n" .
3872 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3873 $tag{'type'}) . "</td>\n" .
3875 if (defined($tag{'author'})) {
3876 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3877 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3878 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3879 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3882 print "</table>\n\n" .
3884 print "<div class=\"page_body\">";
3885 my $comment = $tag{'comment'};
3886 foreach my $line (@$comment) {
3888 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3898 my ($have_blame) = gitweb_check_feature
('blame');
3900 die_error
('403 Permission denied', "Permission denied");
3902 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3903 $hash_base ||= git_get_head_hash
($project);
3904 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3905 my %co = parse_commit
($hash_base)
3906 or die_error
(undef, "Reading commit failed");
3907 if (!defined $hash) {
3908 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3909 or die_error
(undef, "Error looking up file");
3911 $ftype = git_get_type
($hash);
3912 if ($ftype !~ "blob") {
3913 die_error
('400 Bad Request', "Object is not a blob");
3915 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3916 $file_name, $hash_base)
3917 or die_error
(undef, "Open git-blame failed");
3920 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3923 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3926 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3928 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3929 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3930 git_print_page_path
($file_name, $ftype, $hash_base);
3931 my @rev_color = (qw(light2 dark2));
3932 my $num_colors = scalar(@rev_color);
3933 my $current_color = 0;
3936 <div class="page_body">
3937 <table class="blame">
3938 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3943 last unless defined $_;
3944 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3945 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3946 if (!exists $metainfo{$full_rev}) {
3947 $metainfo{$full_rev} = {};
3949 my $meta = $metainfo{$full_rev};
3952 if (/^(\S+) (.*)$/) {
3958 my $rev = substr($full_rev, 0, 8);
3959 my $author = $meta->{'author'};
3960 my %date = parse_date
($meta->{'author-time'},
3961 $meta->{'author-tz'});
3962 my $date = $date{'iso-tz'};
3964 $current_color = ++$current_color % $num_colors;
3966 print "<tr class=\"$rev_color[$current_color]\">\n";
3968 print "<td class=\"sha1\"";
3969 print " title=\"". esc_html
($author) . ", $date\"";
3970 print " rowspan=\"$group_size\"" if ($group_size > 1);
3972 print $cgi->a({-href
=> href
(action
=>"commit",
3974 file_name
=>$file_name)},
3978 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3979 or die_error
(undef, "Open git-rev-parse failed");
3980 my $parent_commit = <$dd>;
3982 chomp($parent_commit);
3983 my $blamed = href
(action
=> 'blame',
3984 file_name
=> $meta->{'filename'},
3985 hash_base
=> $parent_commit);
3986 print "<td class=\"linenr\">";
3987 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3989 -class => "linenr" },
3992 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3998 or print "Reading blob failed\n";
4005 my ($have_blame) = gitweb_check_feature
('blame');
4007 die_error
('403 Permission denied', "Permission denied");
4009 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4010 $hash_base ||= git_get_head_hash
($project);
4011 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4012 my %co = parse_commit
($hash_base)
4013 or die_error
(undef, "Reading commit failed");
4014 if (!defined $hash) {
4015 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4016 or die_error
(undef, "Error lookup file");
4018 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4019 or die_error
(undef, "Open git-annotate failed");
4022 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4025 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4028 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4030 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4031 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4032 git_print_page_path
($file_name, 'blob', $hash_base);
4033 print "<div class=\"page_body\">\n";
4035 <table class="blame">
4044 my @line_class = (qw(light dark));
4045 my $line_class_len = scalar (@line_class);
4046 my $line_class_num = $#line_class;
4047 while (my $line = <$fd>) {
4059 $line_class_num = ($line_class_num + 1) % $line_class_len;
4061 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4068 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4071 $short_rev = substr ($long_rev, 0, 8);
4072 $age = time () - $time;
4073 $age_str = age_string
($age);
4074 $age_str =~ s/ / /g;
4075 $age_class = age_class
($age);
4076 $author = esc_html
($author);
4077 $author =~ s/ / /g;
4079 $data = untabify
($data);
4080 $data = esc_html
($data);
4083 <tr class="$line_class[$line_class_num]">
4084 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4085 <td class="$age_class">$age_str</td>
4087 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4088 <td class="pre">$data</td>
4091 } # while (my $line = <$fd>)
4092 print "</table>\n\n";
4094 or print "Reading blob failed.\n";
4100 my $head = git_get_head_hash
($project);
4102 git_print_page_nav
('','', $head,undef,$head);
4103 git_print_header_div
('summary', $project);
4105 my @tagslist = git_get_tags_list
();
4107 git_tags_body
(\
@tagslist);
4113 my $head = git_get_head_hash
($project);
4115 git_print_page_nav
('','', $head,undef,$head);
4116 git_print_header_div
('summary', $project);
4118 my @headslist = git_get_heads_list
();
4120 git_heads_body
(\
@headslist, $head);
4125 sub git_blob_plain
{
4128 if (!defined $hash) {
4129 if (defined $file_name) {
4130 my $base = $hash_base || git_get_head_hash
($project);
4131 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4132 or die_error
(undef, "Error lookup file");
4134 die_error
(undef, "No file name defined");
4136 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4137 # blobs defined by non-textual hash id's can be cached
4142 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4143 or die_error
(undef, "Couldn't cat $file_name, $hash");
4145 $type ||= blob_mimetype
($fd, $file_name);
4147 # save as filename, even when no $file_name is given
4148 my $save_as = "$hash";
4149 if (defined $file_name) {
4150 $save_as = $file_name;
4151 } elsif ($type =~ m/^text\//) {
4158 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4160 binmode STDOUT
, ':raw';
4162 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4170 if (!defined $hash) {
4171 if (defined $file_name) {
4172 my $base = $hash_base || git_get_head_hash
($project);
4173 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4174 or die_error
(undef, "Error lookup file");
4176 die_error
(undef, "No file name defined");
4178 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4179 # blobs defined by non-textual hash id's can be cached
4183 my ($have_blame) = gitweb_check_feature
('blame');
4184 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4185 or die_error
(undef, "Couldn't cat $file_name, $hash");
4186 my $mimetype = blob_mimetype
($fd, $file_name);
4187 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4189 return git_blob_plain
($mimetype);
4191 # we can have blame only for text/* mimetype
4192 $have_blame &&= ($mimetype =~ m!^text/!);
4194 git_header_html
(undef, $expires);
4195 my $formats_nav = '';
4196 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4197 if (defined $file_name) {
4200 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4201 hash
=>$hash, file_name
=>$file_name)},
4206 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4207 hash
=>$hash, file_name
=>$file_name)},
4210 $cgi->a({-href
=> href
(action
=>"blob_plain",
4211 hash
=>$hash, file_name
=>$file_name)},
4214 $cgi->a({-href
=> href
(action
=>"blob",
4215 hash_base
=>"HEAD", file_name
=>$file_name)},
4219 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4221 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4222 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4224 print "<div class=\"page_nav\">\n" .
4225 "<br/><br/></div>\n" .
4226 "<div class=\"title\">$hash</div>\n";
4228 git_print_page_path
($file_name, "blob", $hash_base);
4229 print "<div class=\"page_body\">\n";
4230 if ($mimetype =~ m!^text/!) {
4232 while (my $line = <$fd>) {
4235 $line = untabify
($line);
4236 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4237 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4239 } elsif ($mimetype =~ m!^image/!) {
4240 print qq
!<img type
="$mimetype"!;
4242 print qq
! alt
="$file_name" title
="$file_name"!;
4245 href(action=>"blob_plain
", hash=>$hash,
4246 hash_base=>$hash_base, file_name=>$file_name) .
4250 or print "Reading blob failed.\n";
4256 if (!defined $hash_base) {
4257 $hash_base = "HEAD";
4259 if (!defined $hash) {
4260 if (defined $file_name) {
4261 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4267 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4268 or die_error
(undef, "Open git-ls-tree failed");
4269 my @entries = map { chomp; $_ } <$fd>;
4270 close $fd or die_error
(undef, "Reading tree failed");
4273 my $refs = git_get_references
();
4274 my $ref = format_ref_marker
($refs, $hash_base);
4277 my ($have_blame) = gitweb_check_feature
('blame');
4278 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4280 if (defined $file_name) {
4282 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4283 hash
=>$hash, file_name
=>$file_name)},
4285 $cgi->a({-href
=> href
(action
=>"tree",
4286 hash_base
=>"HEAD", file_name
=>$file_name)},
4289 my $snapshot_links = format_snapshot_links
($hash);
4290 if (defined $snapshot_links) {
4291 # FIXME: Should be available when we have no hash base as well.
4292 push @views_nav, $snapshot_links;
4294 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4295 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4298 print "<div class=\"page_nav\">\n";
4299 print "<br/><br/></div>\n";
4300 print "<div class=\"title\">$hash</div>\n";
4302 if (defined $file_name) {
4303 $basedir = $file_name;
4304 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4308 git_print_page_path
($file_name, 'tree', $hash_base);
4309 print "<div class=\"page_body\">\n";
4310 print "<table cellspacing=\"0\">\n";
4312 # '..' (top directory) link if possible
4313 if (defined $hash_base &&
4314 defined $file_name && $file_name =~ m![^/]+$!) {
4316 print "<tr class=\"dark\">\n";
4318 print "<tr class=\"light\">\n";
4322 my $up = $file_name;
4323 $up =~ s!/?[^/]+$!!;
4324 undef $up unless $up;
4325 # based on git_print_tree_entry
4326 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4327 print '<td class="list">';
4328 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4332 print "<td class=\"link\"></td>\n";
4336 foreach my $line (@entries) {
4337 my %t = parse_ls_tree_line
($line, -z
=> 1);
4340 print "<tr class=\"dark\">\n";
4342 print "<tr class=\"light\">\n";
4346 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4350 print "</table>\n" .
4356 my @supported_fmts = gitweb_check_feature
('snapshot');
4357 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4359 my $format = $cgi->param('sf');
4360 if (!@supported_fmts) {
4361 die_error
('403 Permission denied', "Permission denied");
4363 # default to first supported snapshot format
4364 $format ||= $supported_fmts[0];
4365 if ($format !~ m/^[a-z0-9]+$/) {
4366 die_error
(undef, "Invalid snapshot format parameter");
4367 } elsif (!exists($known_snapshot_formats{$format})) {
4368 die_error
(undef, "Unknown snapshot format");
4369 } elsif (!grep($_ eq $format, @supported_fmts)) {
4370 die_error
(undef, "Unsupported snapshot format");
4373 if (!defined $hash) {
4374 $hash = git_get_head_hash
($project);
4377 my $git_command = git_cmd_str
();
4378 my $name = $project;
4379 $name =~ s
,([^/])/*\
.git
$,$1,;
4380 $name = basename
($name);
4381 my $filename = to_utf8
($name);
4382 $name =~ s/\047/\047\\\047\047/g;
4384 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4385 $cmd = "$git_command archive " .
4386 "--format=$known_snapshot_formats{$format}{'format'} " .
4387 "--prefix=\'$name\'/ $hash";
4388 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4389 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4393 -type
=> $known_snapshot_formats{$format}{'type'},
4394 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4395 -status
=> '200 OK');
4397 open my $fd, "-|", $cmd
4398 or die_error
(undef, "Execute git-archive failed");
4399 binmode STDOUT
, ':raw';
4401 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4406 my $head = git_get_head_hash
($project);
4407 if (!defined $hash) {
4410 if (!defined $page) {
4413 my $refs = git_get_references
();
4415 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4417 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4420 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4423 my %co = parse_commit
($hash);
4425 git_print_header_div
('summary', $project);
4426 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4428 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4429 for (my $i = 0; $i <= $to; $i++) {
4430 my %co = %{$commitlist[$i]};
4432 my $commit = $co{'id'};
4433 my $ref = format_ref_marker
($refs, $commit);
4434 my %ad = parse_date
($co{'author_epoch'});
4435 git_print_header_div
('commit',
4436 "<span class=\"age\">$co{'age_string'}</span>" .
4437 esc_html
($co{'title'}) . $ref,
4439 print "<div class=\"title_text\">\n" .
4440 "<div class=\"log_link\">\n" .
4441 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4443 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4445 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4448 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4451 print "<div class=\"log_body\">\n";
4452 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4455 if ($#commitlist >= 100) {
4456 print "<div class=\"page_nav\">\n";
4457 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4458 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4465 $hash ||= $hash_base || "HEAD";
4466 my %co = parse_commit
($hash);
4468 die_error
(undef, "Unknown commit object");
4470 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4471 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4473 my $parent = $co{'parent'};
4474 my $parents = $co{'parents'}; # listref
4476 # we need to prepare $formats_nav before any parameter munging
4478 if (!defined $parent) {
4480 $formats_nav .= '(initial)';
4481 } elsif (@$parents == 1) {
4482 # single parent commit
4485 $cgi->a({-href
=> href
(action
=>"commit",
4487 esc_html
(substr($parent, 0, 7))) .
4494 $cgi->a({-href
=> href
(action
=>"commit",
4496 esc_html
(substr($_, 0, 7)));
4501 if (!defined $parent) {
4505 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4507 (@$parents <= 1 ? $parent : '-c'),
4509 or die_error
(undef, "Open git-diff-tree failed");
4510 @difftree = map { chomp; $_ } <$fd>;
4511 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4513 # non-textual hash id's can be cached
4515 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4518 my $refs = git_get_references
();
4519 my $ref = format_ref_marker
($refs, $co{'id'});
4521 git_header_html
(undef, $expires);
4522 git_print_page_nav
('commit', '',
4523 $hash, $co{'tree'}, $hash,
4526 if (defined $co{'parent'}) {
4527 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4529 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4531 print "<div class=\"title_text\">\n" .
4532 "<table cellspacing=\"0\">\n";
4533 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4535 "<td></td><td> $ad{'rfc2822'}";
4536 if ($ad{'hour_local'} < 6) {
4537 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4538 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4540 printf(" (%02d:%02d %s)",
4541 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4545 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4546 print "<tr><td></td><td> $cd{'rfc2822'}" .
4547 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4549 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4552 "<td class=\"sha1\">" .
4553 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4554 class => "list"}, $co{'tree'}) .
4556 "<td class=\"link\">" .
4557 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4559 my $snapshot_links = format_snapshot_links
($hash);
4560 if (defined $snapshot_links) {
4561 print " | " . $snapshot_links;
4566 foreach my $par (@$parents) {
4569 "<td class=\"sha1\">" .
4570 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4571 class => "list"}, $par) .
4573 "<td class=\"link\">" .
4574 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4576 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4583 print "<div class=\"page_body\">\n";
4584 git_print_log
($co{'comment'});
4587 git_difftree_body
(\
@difftree, $hash, @$parents);
4593 # object is defined by:
4594 # - hash or hash_base alone
4595 # - hash_base and file_name
4598 # - hash or hash_base alone
4599 if ($hash || ($hash_base && !defined $file_name)) {
4600 my $object_id = $hash || $hash_base;
4602 my $git_command = git_cmd_str
();
4603 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4604 or die_error
('404 Not Found', "Object does not exist");
4608 or die_error
('404 Not Found', "Object does not exist");
4610 # - hash_base and file_name
4611 } elsif ($hash_base && defined $file_name) {
4612 $file_name =~ s
,/+$,,;
4614 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4615 or die_error
('404 Not Found', "Base object does not exist");
4617 # here errors should not hapen
4618 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4619 or die_error
(undef, "Open git-ls-tree failed");
4623 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4624 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4625 die_error
('404 Not Found', "File or directory for given base does not exist");
4630 die_error
('404 Not Found', "Not enough information to find object");
4633 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4634 hash
=>$hash, hash_base
=>$hash_base,
4635 file_name
=>$file_name),
4636 -status
=> '302 Found');
4640 my $format = shift || 'html';
4647 # preparing $fd and %diffinfo for git_patchset_body
4649 if (defined $hash_base && defined $hash_parent_base) {
4650 if (defined $file_name) {
4652 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4653 $hash_parent_base, $hash_base,
4654 "--", (defined $file_parent ? $file_parent : ()), $file_name
4655 or die_error
(undef, "Open git-diff-tree failed");
4656 @difftree = map { chomp; $_ } <$fd>;
4658 or die_error
(undef, "Reading git-diff-tree failed");
4660 or die_error
('404 Not Found', "Blob diff not found");
4662 } elsif (defined $hash &&
4663 $hash =~ /[0-9a-fA-F]{40}/) {
4664 # try to find filename from $hash
4666 # read filtered raw output
4667 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4668 $hash_parent_base, $hash_base, "--"
4669 or die_error
(undef, "Open git-diff-tree failed");
4671 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4673 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4674 map { chomp; $_ } <$fd>;
4676 or die_error
(undef, "Reading git-diff-tree failed");
4678 or die_error
('404 Not Found', "Blob diff not found");
4681 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4684 if (@difftree > 1) {
4685 die_error
('404 Not Found', "Ambiguous blob diff specification");
4688 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4689 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4690 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4692 $hash_parent ||= $diffinfo{'from_id'};
4693 $hash ||= $diffinfo{'to_id'};
4695 # non-textual hash id's can be cached
4696 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4697 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4702 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4703 '-p', ($format eq 'html' ? "--full-index" : ()),
4704 $hash_parent_base, $hash_base,
4705 "--", (defined $file_parent ? $file_parent : ()), $file_name
4706 or die_error
(undef, "Open git-diff-tree failed");
4709 # old/legacy style URI
4710 if (!%diffinfo && # if new style URI failed
4711 defined $hash && defined $hash_parent) {
4712 # fake git-diff-tree raw output
4713 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4714 $diffinfo{'from_id'} = $hash_parent;
4715 $diffinfo{'to_id'} = $hash;
4716 if (defined $file_name) {
4717 if (defined $file_parent) {
4718 $diffinfo{'status'} = '2';
4719 $diffinfo{'from_file'} = $file_parent;
4720 $diffinfo{'to_file'} = $file_name;
4721 } else { # assume not renamed
4722 $diffinfo{'status'} = '1';
4723 $diffinfo{'from_file'} = $file_name;
4724 $diffinfo{'to_file'} = $file_name;
4726 } else { # no filename given
4727 $diffinfo{'status'} = '2';
4728 $diffinfo{'from_file'} = $hash_parent;
4729 $diffinfo{'to_file'} = $hash;
4732 # non-textual hash id's can be cached
4733 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4734 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4739 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4740 '-p', ($format eq 'html' ? "--full-index" : ()),
4741 $hash_parent, $hash, "--"
4742 or die_error
(undef, "Open git-diff failed");
4744 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4749 if ($format eq 'html') {
4751 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4752 hash
=>$hash, hash_parent
=>$hash_parent,
4753 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4754 file_name
=>$file_name, file_parent
=>$file_parent)},
4756 git_header_html
(undef, $expires);
4757 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4758 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4759 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4761 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4762 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4764 if (defined $file_name) {
4765 git_print_page_path
($file_name, "blob", $hash_base);
4767 print "<div class=\"page_path\"></div>\n";
4770 } elsif ($format eq 'plain') {
4772 -type
=> 'text/plain',
4773 -charset
=> 'utf-8',
4774 -expires
=> $expires,
4775 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4777 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4780 die_error
(undef, "Unknown blobdiff format");
4784 if ($format eq 'html') {
4785 print "<div class=\"page_body\">\n";
4787 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4790 print "</div>\n"; # class="page_body"
4794 while (my $line = <$fd>) {
4795 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4796 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4800 last if $line =~ m!^\+\+\+!;
4808 sub git_blobdiff_plain
{
4809 git_blobdiff
('plain');
4812 sub git_commitdiff
{
4813 my $format = shift || 'html';
4814 $hash ||= $hash_base || "HEAD";
4815 my %co = parse_commit
($hash);
4817 die_error
(undef, "Unknown commit object");
4820 # choose format for commitdiff for merge
4821 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4822 $hash_parent = '--cc';
4824 # we need to prepare $formats_nav before almost any parameter munging
4826 if ($format eq 'html') {
4828 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4829 hash
=>$hash, hash_parent
=>$hash_parent)},
4832 if (defined $hash_parent &&
4833 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4834 # commitdiff with two commits given
4835 my $hash_parent_short = $hash_parent;
4836 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4837 $hash_parent_short = substr($hash_parent, 0, 7);
4841 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4842 if ($co{'parents'}[$i] eq $hash_parent) {
4843 $formats_nav .= ' parent ' . ($i+1);
4847 $formats_nav .= ': ' .
4848 $cgi->a({-href
=> href
(action
=>"commitdiff",
4849 hash
=>$hash_parent)},
4850 esc_html
($hash_parent_short)) .
4852 } elsif (!$co{'parent'}) {
4854 $formats_nav .= ' (initial)';
4855 } elsif (scalar @{$co{'parents'}} == 1) {
4856 # single parent commit
4859 $cgi->a({-href
=> href
(action
=>"commitdiff",
4860 hash
=>$co{'parent'})},
4861 esc_html
(substr($co{'parent'}, 0, 7))) .
4865 if ($hash_parent eq '--cc') {
4866 $formats_nav .= ' | ' .
4867 $cgi->a({-href
=> href
(action
=>"commitdiff",
4868 hash
=>$hash, hash_parent
=>'-c')},
4870 } else { # $hash_parent eq '-c'
4871 $formats_nav .= ' | ' .
4872 $cgi->a({-href
=> href
(action
=>"commitdiff",
4873 hash
=>$hash, hash_parent
=>'--cc')},
4879 $cgi->a({-href
=> href
(action
=>"commitdiff",
4881 esc_html
(substr($_, 0, 7)));
4882 } @{$co{'parents'}} ) .
4887 my $hash_parent_param = $hash_parent;
4888 if (!defined $hash_parent_param) {
4889 # --cc for multiple parents, --root for parentless
4890 $hash_parent_param =
4891 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4897 if ($format eq 'html') {
4898 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4899 "--no-commit-id", "--patch-with-raw", "--full-index",
4900 $hash_parent_param, $hash, "--"
4901 or die_error
(undef, "Open git-diff-tree failed");
4903 while (my $line = <$fd>) {
4905 # empty line ends raw part of diff-tree output
4907 push @difftree, scalar parse_difftree_raw_line
($line);
4910 } elsif ($format eq 'plain') {
4911 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4912 '-p', $hash_parent_param, $hash, "--"
4913 or die_error
(undef, "Open git-diff-tree failed");
4916 die_error
(undef, "Unknown commitdiff format");
4919 # non-textual hash id's can be cached
4921 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4925 # write commit message
4926 if ($format eq 'html') {
4927 my $refs = git_get_references
();
4928 my $ref = format_ref_marker
($refs, $co{'id'});
4930 git_header_html
(undef, $expires);
4931 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4932 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4933 git_print_authorship
(\
%co);
4934 print "<div class=\"page_body\">\n";
4935 if (@{$co{'comment'}} > 1) {
4936 print "<div class=\"log\">\n";
4937 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4938 print "</div>\n"; # class="log"
4941 } elsif ($format eq 'plain') {
4942 my $refs = git_get_references
("tags");
4943 my $tagname = git_get_rev_name_tags
($hash);
4944 my $filename = basename
($project) . "-$hash.patch";
4947 -type
=> 'text/plain',
4948 -charset
=> 'utf-8',
4949 -expires
=> $expires,
4950 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4951 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4954 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4955 Subject: $co{'title'}
4957 print "X-Git-Tag: $tagname\n" if $tagname;
4958 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4960 foreach my $line (@{$co{'comment'}}) {
4967 if ($format eq 'html') {
4968 my $use_parents = !defined $hash_parent ||
4969 $hash_parent eq '-c' || $hash_parent eq '--cc';
4970 git_difftree_body
(\
@difftree, $hash,
4971 $use_parents ? @{$co{'parents'}} : $hash_parent);
4974 git_patchset_body
($fd, \
@difftree, $hash,
4975 $use_parents ? @{$co{'parents'}} : $hash_parent);
4977 print "</div>\n"; # class="page_body"
4980 } elsif ($format eq 'plain') {
4984 or print "Reading git-diff-tree failed\n";
4988 sub git_commitdiff_plain
{
4989 git_commitdiff
('plain');
4993 if (!defined $hash_base) {
4994 $hash_base = git_get_head_hash
($project);
4996 if (!defined $page) {
5000 my %co = parse_commit
($hash_base);
5002 die_error
(undef, "Unknown commit object");
5005 my $refs = git_get_references
();
5006 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5008 if (!defined $hash && defined $file_name) {
5009 $hash = git_get_hash_by_path
($hash_base, $file_name);
5011 if (defined $hash) {
5012 $ftype = git_get_type
($hash);
5015 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5017 my $paging_nav = '';
5020 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5021 file_name
=>$file_name)},
5023 $paging_nav .= " ⋅ " .
5024 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5025 file_name
=>$file_name, page
=>$page-1),
5026 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5028 $paging_nav .= "first";
5029 $paging_nav .= " ⋅ prev";
5031 if ($#commitlist >= 100) {
5032 $paging_nav .= " ⋅ " .
5033 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5034 file_name
=>$file_name, page
=>$page+1),
5035 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5037 $paging_nav .= " ⋅ next";
5040 if ($#commitlist >= 100) {
5042 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5043 file_name
=>$file_name, page
=>$page+1),
5044 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5048 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5049 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5050 git_print_page_path
($file_name, $ftype, $hash_base);
5052 git_history_body
(\
@commitlist, 0, 99,
5053 $refs, $hash_base, $ftype, $next_link);
5059 my ($have_search) = gitweb_check_feature
('search');
5060 if (!$have_search) {
5061 die_error
('403 Permission denied', "Permission denied");
5063 if (!defined $searchtext) {
5064 die_error
(undef, "Text field empty");
5066 if (!defined $hash) {
5067 $hash = git_get_head_hash
($project);
5069 my %co = parse_commit
($hash);
5071 die_error
(undef, "Unknown commit object");
5073 if (!defined $page) {
5077 $searchtype ||= 'commit';
5078 if ($searchtype eq 'pickaxe') {
5079 # pickaxe may take all resources of your box and run for several minutes
5080 # with every query - so decide by yourself how public you make this feature
5081 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5082 if (!$have_pickaxe) {
5083 die_error
('403 Permission denied', "Permission denied");
5086 if ($searchtype eq 'grep') {
5087 my ($have_grep) = gitweb_check_feature
('grep');
5089 die_error
('403 Permission denied', "Permission denied");
5095 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5097 if ($searchtype eq 'commit') {
5098 $greptype = "--grep=";
5099 } elsif ($searchtype eq 'author') {
5100 $greptype = "--author=";
5101 } elsif ($searchtype eq 'committer') {
5102 $greptype = "--committer=";
5104 $greptype .= $search_regexp;
5105 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5107 my $paging_nav = '';
5110 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5111 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5113 $paging_nav .= " ⋅ " .
5114 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5115 searchtext
=>$searchtext, searchtype
=>$searchtype,
5117 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5119 $paging_nav .= "first";
5120 $paging_nav .= " ⋅ prev";
5122 if ($#commitlist >= 100) {
5123 $paging_nav .= " ⋅ " .
5124 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5125 searchtext
=>$searchtext, searchtype
=>$searchtype,
5127 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5129 $paging_nav .= " ⋅ next";
5132 if ($#commitlist >= 100) {
5134 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5135 searchtext
=>$searchtext, searchtype
=>$searchtype,
5137 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5140 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5141 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5142 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5145 if ($searchtype eq 'pickaxe') {
5146 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5147 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5149 print "<table cellspacing=\"0\">\n";
5152 my $git_command = git_cmd_str
();
5153 my $searchqtext = $searchtext;
5154 $searchqtext =~ s/'/'\\''/;
5155 open my $fd, "-|", "$git_command rev-list $hash | " .
5156 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5159 while (my $line = <$fd>) {
5160 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5163 $set{'from_id'} = $3;
5165 $set{'id'} = $set{'to_id'};
5166 if ($set{'id'} =~ m/0{40}/) {
5167 $set{'id'} = $set{'from_id'};
5169 if ($set{'id'} =~ m/0{40}/) {
5173 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5176 print "<tr class=\"dark\">\n";
5178 print "<tr class=\"light\">\n";
5181 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5182 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5183 "<td><i>" . $author . "</i></td>\n" .
5185 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5186 -class => "list subject"},
5187 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5188 while (my $setref = shift @files) {
5190 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5191 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5193 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5197 "<td class=\"link\">" .
5198 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5200 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5204 %co = parse_commit
($1);
5212 if ($searchtype eq 'grep') {
5213 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5214 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5216 print "<table cellspacing=\"0\">\n";
5220 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5222 while (my $line = <$fd>) {
5224 my ($file, $lno, $ltext, $binary);
5225 last if ($matches++ > 1000);
5226 if ($line =~ /^Binary file (.+) matches$/) {
5230 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5232 if ($file ne $lastfile) {
5233 $lastfile and print "</td></tr>\n";
5235 print "<tr class=\"dark\">\n";
5237 print "<tr class=\"light\">\n";
5239 print "<td class=\"list\">".
5240 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5241 file_name
=>"$file"),
5242 -class => "list"}, esc_path
($file));
5243 print "</td><td>\n";
5247 print "<div class=\"binary\">Binary file</div>\n";
5249 $ltext = untabify
($ltext);
5250 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5251 $ltext = esc_html
($1, -nbsp
=>1);
5252 $ltext .= '<span class="match">';
5253 $ltext .= esc_html
($2, -nbsp
=>1);
5254 $ltext .= '</span>';
5255 $ltext .= esc_html
($3, -nbsp
=>1);
5257 $ltext = esc_html
($ltext, -nbsp
=>1);
5259 print "<div class=\"pre\">" .
5260 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5261 file_name
=>"$file").'#l'.$lno,
5262 -class => "linenr"}, sprintf('%4i', $lno))
5263 . ' ' . $ltext . "</div>\n";
5267 print "</td></tr>\n";
5268 if ($matches > 1000) {
5269 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5272 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5281 sub git_search_help
{
5283 git_print_page_nav
('','', $hash,$hash,$hash);
5286 <dt><b>commit</b></dt>
5287 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5289 my ($have_grep) = gitweb_check_feature
('grep');
5292 <dt><b>grep</b></dt>
5293 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5294 a different one) are searched for the given
5295 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5296 (POSIX extended) and the matches are listed. On large
5297 trees, this search can take a while and put some strain on the server, so please use it with
5298 some consideration.</dd>
5302 <dt><b>author</b></dt>
5303 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5304 <dt><b>committer</b></dt>
5305 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5307 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5308 if ($have_pickaxe) {
5310 <dt><b>pickaxe</b></dt>
5311 <dd>All commits that caused the string to appear or disappear from any file (changes that
5312 added, removed or "modified" the string) will be listed. This search can take a while and
5313 takes a lot of strain on the server, so please use it wisely.</dd>
5321 my $head = git_get_head_hash
($project);
5322 if (!defined $hash) {
5325 if (!defined $page) {
5328 my $refs = git_get_references
();
5330 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5332 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5334 if ($#commitlist >= 100) {
5336 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5337 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5341 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5342 git_print_header_div
('summary', $project);
5344 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5349 ## ......................................................................
5350 ## feeds (RSS, Atom; OPML)
5353 my $format = shift || 'atom';
5354 my ($have_blame) = gitweb_check_feature
('blame');
5356 # Atom: http://www.atomenabled.org/developers/syndication/
5357 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5358 if ($format ne 'rss' && $format ne 'atom') {
5359 die_error
(undef, "Unknown web feed format");
5362 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5363 my $head = $hash || 'HEAD';
5364 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5368 my $content_type = "application/$format+xml";
5369 if (defined $cgi->http('HTTP_ACCEPT') &&
5370 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5371 # browser (feed reader) prefers text/xml
5372 $content_type = 'text/xml';
5374 if (defined($commitlist[0])) {
5375 %latest_commit = %{$commitlist[0]};
5376 %latest_date = parse_date
($latest_commit{'author_epoch'});
5378 -type
=> $content_type,
5379 -charset
=> 'utf-8',
5380 -last_modified
=> $latest_date{'rfc2822'});
5383 -type
=> $content_type,
5384 -charset
=> 'utf-8');
5387 # Optimization: skip generating the body if client asks only
5388 # for Last-Modified date.
5389 return if ($cgi->request_method() eq 'HEAD');
5392 my $title = "$site_name - $project/$action";
5393 my $feed_type = 'log';
5394 if (defined $hash) {
5395 $title .= " - '$hash'";
5396 $feed_type = 'branch log';
5397 if (defined $file_name) {
5398 $title .= " :: $file_name";
5399 $feed_type = 'history';
5401 } elsif (defined $file_name) {
5402 $title .= " - $file_name";
5403 $feed_type = 'history';
5405 $title .= " $feed_type";
5406 my $descr = git_get_project_description
($project);
5407 if (defined $descr) {
5408 $descr = esc_html
($descr);
5410 $descr = "$project " .
5411 ($format eq 'rss' ? 'RSS' : 'Atom') .
5414 my $owner = git_get_project_owner
($project);
5415 $owner = esc_html
($owner);
5419 if (defined $file_name) {
5420 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5421 } elsif (defined $hash) {
5422 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5424 $alt_url = href
(-full
=>1, action
=>"summary");
5426 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5427 if ($format eq 'rss') {
5429 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5432 print "<title>$title</title>\n" .
5433 "<link>$alt_url</link>\n" .
5434 "<description>$descr</description>\n" .
5435 "<language>en</language>\n";
5436 } elsif ($format eq 'atom') {
5438 <feed xmlns="http://www.w3.org/2005/Atom">
5440 print "<title>$title</title>\n" .
5441 "<subtitle>$descr</subtitle>\n" .
5442 '<link rel="alternate" type="text/html" href="' .
5443 $alt_url . '" />' . "\n" .
5444 '<link rel="self" type="' . $content_type . '" href="' .
5445 $cgi->self_url() . '" />' . "\n" .
5446 "<id>" . href
(-full
=>1) . "</id>\n" .
5447 # use project owner for feed author
5448 "<author><name>$owner</name></author>\n";
5449 if (defined $favicon) {
5450 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5452 if (defined $logo_url) {
5453 # not twice as wide as tall: 72 x 27 pixels
5454 print "<logo>" . esc_url
($logo) . "</logo>\n";
5456 if (! %latest_date) {
5457 # dummy date to keep the feed valid until commits trickle in:
5458 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5460 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5465 for (my $i = 0; $i <= $#commitlist; $i++) {
5466 my %co = %{$commitlist[$i]};
5467 my $commit = $co{'id'};
5468 # we read 150, we always show 30 and the ones more recent than 48 hours
5469 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5472 my %cd = parse_date
($co{'author_epoch'});
5474 # get list of changed files
5475 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5476 $co{'parent'} || "--root",
5477 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5479 my @difftree = map { chomp; $_ } <$fd>;
5483 # print element (entry, item)
5484 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5485 if ($format eq 'rss') {
5487 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5488 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5489 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5490 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5491 "<link>$co_url</link>\n" .
5492 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5493 "<content:encoded>" .
5495 } elsif ($format eq 'atom') {
5497 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5498 "<updated>$cd{'iso-8601'}</updated>\n" .
5500 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5501 if ($co{'author_email'}) {
5502 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5504 print "</author>\n" .
5505 # use committer for contributor
5507 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5508 if ($co{'committer_email'}) {
5509 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5511 print "</contributor>\n" .
5512 "<published>$cd{'iso-8601'}</published>\n" .
5513 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5514 "<id>$co_url</id>\n" .
5515 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5516 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5518 my $comment = $co{'comment'};
5520 foreach my $line (@$comment) {
5521 $line = esc_html
($line);
5524 print "</pre><ul>\n";
5525 foreach my $difftree_line (@difftree) {
5526 my %difftree = parse_difftree_raw_line
($difftree_line);
5527 next if !$difftree{'from_id'};
5529 my $file = $difftree{'file'} || $difftree{'to_file'};
5533 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5534 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5535 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5536 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5537 -title
=> "diff"}, 'D');
5539 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5540 file_name
=>$file, hash_base
=>$commit),
5541 -title
=> "blame"}, 'B');
5543 # if this is not a feed of a file history
5544 if (!defined $file_name || $file_name ne $file) {
5545 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5546 file_name
=>$file, hash
=>$commit),
5547 -title
=> "history"}, 'H');
5549 $file = esc_path
($file);
5553 if ($format eq 'rss') {
5554 print "</ul>]]>\n" .
5555 "</content:encoded>\n" .
5557 } elsif ($format eq 'atom') {
5558 print "</ul>\n</div>\n" .
5565 if ($format eq 'rss') {
5566 print "</channel>\n</rss>\n";
5567 } elsif ($format eq 'atom') {
5581 my @list = git_get_projects_list
();
5583 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5585 <?xml version="1.0" encoding="utf-8"?>
5586 <opml version="1.0">
5588 <title>$site_name OPML Export</title>
5591 <outline text="git RSS feeds">
5594 foreach my $pr (@list) {
5596 my $head = git_get_head_hash
($proj{'path'});
5597 if (!defined $head) {
5600 $git_dir = "$projectroot/$proj{'path'}";
5601 my %co = parse_commit
($head);
5606 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5607 my $rss = "$my_url?p=$proj{'path'};a=rss";
5608 my $html = "$my_url?p=$proj{'path'};a=summary";
5609 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";