3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # You define site-wide feature defaults here; override them with
99 # $GITWEB_CONFIG as necessary.
102 # 'sub' => feature-sub (subroutine),
103 # 'override' => allow-override (boolean),
104 # 'default' => [ default options...] (array reference)}
106 # if feature is overridable (it means that allow-override has true value,
107 # then feature-sub will be called with default options as parameters;
108 # return value of feature-sub indicates if to enable specified feature
110 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
112 # Enable the 'blame' blob view, showing the last commit that modified
113 # each line in the file. This can be very CPU-intensive.
115 # To enable system wide have in $GITWEB_CONFIG
116 # $feature{'blame'}{'default'} = [1];
117 # To have project specific config enable override in $GITWEB_CONFIG
118 # $feature{'blame'}{'override'} = 1;
119 # and in project config gitweb.blame = 0|1;
121 'sub' => \
&feature_blame
,
125 # Enable the 'snapshot' link, providing a compressed tarball of any
126 # tree. This can potentially generate high traffic if you have large
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'snapshot'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2;
135 'sub' => \
&feature_snapshot
,
137 # => [content-encoding, suffix, program]
138 'default' => ['x-gzip', 'gz', 'gzip']},
140 # Enable text search, which will list the commits which match author,
141 # committer or commit text to a given string. Enabled by default.
146 # Enable the pickaxe search, which will list the commits that modified
147 # a given string in a file. This can be practical and quite faster
148 # alternative to 'blame', but still potentially CPU-intensive.
150 # To enable system wide have in $GITWEB_CONFIG
151 # $feature{'pickaxe'}{'default'} = [1];
152 # To have project specific config enable override in $GITWEB_CONFIG
153 # $feature{'pickaxe'}{'override'} = 1;
154 # and in project config gitweb.pickaxe = 0|1;
156 'sub' => \
&feature_pickaxe
,
160 # Make gitweb use an alternative format of the URLs which can be
161 # more readable and natural-looking: project name is embedded
162 # directly in the path and the query string contains other
163 # auxiliary information. All gitweb installations recognize
164 # URL in either format; this configures in which formats gitweb
167 # To enable system wide have in $GITWEB_CONFIG
168 # $feature{'pathinfo'}{'default'} = [1];
169 # Project specific override is not supported.
171 # Note that you will need to change the default location of CSS,
172 # favicon, logo and possibly other files to an absolute URL. Also,
173 # if gitweb.cgi serves as your indexfile, you will need to force
174 # $my_uri to contain the script name in your $GITWEB_CONFIG.
179 # Make gitweb consider projects in project root subdirectories
180 # to be forks of existing projects. Given project $projname.git,
181 # projects matching $projname/*.git will not be shown in the main
182 # projects list, instead a '+' mark will be added to $projname
183 # there and a 'forks' view will be enabled for the project, listing
184 # all the forks. If project list is taken from a file, forks have
185 # to be listed after the main project.
187 # To enable system wide have in $GITWEB_CONFIG
188 # $feature{'forks'}{'default'} = [1];
189 # Project specific override is not supported.
195 sub gitweb_check_feature
{
197 return unless exists $feature{$name};
198 my ($sub, $override, @defaults) = (
199 $feature{$name}{'sub'},
200 $feature{$name}{'override'},
201 @{$feature{$name}{'default'}});
202 if (!$override) { return @defaults; }
204 warn "feature $name is not overrideable";
207 return $sub->(@defaults);
211 my ($val) = git_get_project_config
('blame', '--bool');
213 if ($val eq 'true') {
215 } elsif ($val eq 'false') {
222 sub feature_snapshot
{
223 my ($ctype, $suffix, $command) = @_;
225 my ($val) = git_get_project_config
('snapshot');
227 if ($val eq 'gzip') {
228 return ('x-gzip', 'gz', 'gzip');
229 } elsif ($val eq 'bzip2') {
230 return ('x-bzip2', 'bz2', 'bzip2');
231 } elsif ($val eq 'none') {
235 return ($ctype, $suffix, $command);
238 sub gitweb_have_snapshot
{
239 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
240 my $have_snapshot = (defined $ctype && defined $suffix);
242 return $have_snapshot;
245 sub feature_pickaxe
{
246 my ($val) = git_get_project_config
('pickaxe', '--bool');
248 if ($val eq 'true') {
250 } elsif ($val eq 'false') {
257 # checking HEAD file with -e is fragile if the repository was
258 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
260 sub check_head_link
{
262 my $headfile = "$dir/HEAD";
263 return ((-e
$headfile) ||
264 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
267 sub check_export_ok
{
269 return (check_head_link
($dir) &&
270 (!$export_ok || -e
"$dir/$export_ok"));
273 # rename detection options for git-diff and git-diff-tree
274 # - default is '-M', with the cost proportional to
275 # (number of removed files) * (number of new files).
276 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
277 # (number of changed files + number of removed files) * (number of new files)
278 # - even more costly is '-C', '--find-copies-harder' with cost
279 # (number of files in the original tree) * (number of new files)
280 # - one might want to include '-B' option, e.g. '-B', '-M'
281 our @diff_opts = ('-M'); # taken from git_commit
283 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
284 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
286 # version of the core git binary
287 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
289 $projects_list ||= $projectroot;
291 # ======================================================================
292 # input validation and dispatch
293 our $action = $cgi->param('a');
294 if (defined $action) {
295 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
296 die_error
(undef, "Invalid action parameter");
300 # parameters which are pathnames
301 our $project = $cgi->param('p');
302 if (defined $project) {
303 if (!validate_pathname
($project) ||
304 !(-d
"$projectroot/$project") ||
305 !check_head_link
("$projectroot/$project") ||
306 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
307 ($strict_export && !project_in_list
($project))) {
309 die_error
(undef, "No such project");
313 our $file_name = $cgi->param('f');
314 if (defined $file_name) {
315 if (!validate_pathname
($file_name)) {
316 die_error
(undef, "Invalid file parameter");
320 our $file_parent = $cgi->param('fp');
321 if (defined $file_parent) {
322 if (!validate_pathname
($file_parent)) {
323 die_error
(undef, "Invalid file parent parameter");
327 # parameters which are refnames
328 our $hash = $cgi->param('h');
330 if (!validate_refname
($hash)) {
331 die_error
(undef, "Invalid hash parameter");
335 our $hash_parent = $cgi->param('hp');
336 if (defined $hash_parent) {
337 if (!validate_refname
($hash_parent)) {
338 die_error
(undef, "Invalid hash parent parameter");
342 our $hash_base = $cgi->param('hb');
343 if (defined $hash_base) {
344 if (!validate_refname
($hash_base)) {
345 die_error
(undef, "Invalid hash base parameter");
349 our $hash_parent_base = $cgi->param('hpb');
350 if (defined $hash_parent_base) {
351 if (!validate_refname
($hash_parent_base)) {
352 die_error
(undef, "Invalid hash parent base parameter");
357 our $page = $cgi->param('pg');
359 if ($page =~ m/[^0-9]/) {
360 die_error
(undef, "Invalid page parameter");
364 our $searchtext = $cgi->param('s');
365 if (defined $searchtext) {
366 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
367 die_error
(undef, "Invalid search parameter");
369 if (length($searchtext) < 2) {
370 die_error
(undef, "At least two characters are required for search parameter");
372 $searchtext = quotemeta $searchtext;
375 our $searchtype = $cgi->param('st');
376 if (defined $searchtype) {
377 if ($searchtype =~ m/[^a-z]/) {
378 die_error
(undef, "Invalid searchtype parameter");
382 # now read PATH_INFO and use it as alternative to parameters
383 sub evaluate_path_info
{
384 return if defined $project;
385 my $path_info = $ENV{"PATH_INFO"};
386 return if !$path_info;
387 $path_info =~ s
,^/+,,;
388 return if !$path_info;
389 # find which part of PATH_INFO is project
390 $project = $path_info;
392 while ($project && !check_head_link
("$projectroot/$project")) {
393 $project =~ s
,/*[^/]*$,,;
396 $project = validate_pathname
($project);
398 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
399 ($strict_export && !project_in_list
($project))) {
403 # do not change any parameters if an action is given using the query string
405 $path_info =~ s
,^$project/*,,;
406 my ($refname, $pathname) = split(/:/, $path_info, 2);
407 if (defined $pathname) {
408 # we got "project.git/branch:filename" or "project.git/branch:dir/"
409 # we could use git_get_type(branch:pathname), but it needs $git_dir
410 $pathname =~ s
,^/+,,;
411 if (!$pathname || substr($pathname, -1) eq "/") {
415 $action ||= "blob_plain";
417 $hash_base ||= validate_refname
($refname);
418 $file_name ||= validate_pathname
($pathname);
419 } elsif (defined $refname) {
420 # we got "project.git/branch"
421 $action ||= "shortlog";
422 $hash ||= validate_refname
($refname);
425 evaluate_path_info
();
427 # path to the current git repository
429 $git_dir = "$projectroot/$project" if $project;
433 "blame" => \
&git_blame2
,
434 "blobdiff" => \
&git_blobdiff
,
435 "blobdiff_plain" => \
&git_blobdiff_plain
,
436 "blob" => \
&git_blob
,
437 "blob_plain" => \
&git_blob_plain
,
438 "commitdiff" => \
&git_commitdiff
,
439 "commitdiff_plain" => \
&git_commitdiff_plain
,
440 "commit" => \
&git_commit
,
441 "forks" => \
&git_forks
,
442 "heads" => \
&git_heads
,
443 "history" => \
&git_history
,
446 "atom" => \
&git_atom
,
447 "search" => \
&git_search
,
448 "search_help" => \
&git_search_help
,
449 "shortlog" => \
&git_shortlog
,
450 "summary" => \
&git_summary
,
452 "tags" => \
&git_tags
,
453 "tree" => \
&git_tree
,
454 "snapshot" => \
&git_snapshot
,
455 "object" => \
&git_object
,
456 # those below don't need $project
457 "opml" => \
&git_opml
,
458 "project_list" => \
&git_project_list
,
459 "project_index" => \
&git_project_index
,
462 if (defined $project) {
463 $action ||= 'summary';
465 $action ||= 'project_list';
467 if (!defined($actions{$action})) {
468 die_error
(undef, "Unknown action");
470 if ($action !~ m/^(opml|project_list|project_index)$/ &&
472 die_error
(undef, "Project needed");
474 $actions{$action}->();
477 ## ======================================================================
482 # default is to use -absolute url() i.e. $my_uri
483 my $href = $params{-full
} ? $my_url : $my_uri;
485 # XXX: Warning: If you touch this, check the search form for updating,
496 hash_parent_base
=> "hpb",
502 my %mapping = @mapping;
504 $params{'project'} = $project unless exists $params{'project'};
506 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
508 # use PATH_INFO for project name
509 $href .= "/$params{'project'}" if defined $params{'project'};
510 delete $params{'project'};
512 # Summary just uses the project path URL
513 if (defined $params{'action'} && $params{'action'} eq 'summary') {
514 delete $params{'action'};
518 # now encode the parameters explicitly
520 for (my $i = 0; $i < @mapping; $i += 2) {
521 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
522 if (defined $params{$name}) {
523 push @result, $symbol . "=" . esc_param
($params{$name});
526 $href .= "?" . join(';', @result) if scalar @result;
532 ## ======================================================================
533 ## validation, quoting/unquoting and escaping
535 sub validate_pathname
{
536 my $input = shift || return undef;
538 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
539 # at the beginning, at the end, and between slashes.
540 # also this catches doubled slashes
541 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
545 if ($input =~ m!\0!) {
551 sub validate_refname
{
552 my $input = shift || return undef;
554 # textual hashes are O.K.
555 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
558 # it must be correct pathname
559 $input = validate_pathname
($input)
561 # restrictions on ref name according to git-check-ref-format
562 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
568 # quote unsafe chars, but keep the slash, even when it's not
569 # correct, but quoted slashes look too horrible in bookmarks
572 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
578 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
581 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
587 # replace invalid utf8 character with SUBSTITUTION sequence
592 $str = decode_utf8
($str);
593 $str = $cgi->escapeHTML($str);
594 if ($opts{'-nbsp'}) {
595 $str =~ s/ / /g;
597 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
601 # quote control characters and escape filename to HTML
606 $str = decode_utf8
($str);
607 $str = $cgi->escapeHTML($str);
608 if ($opts{'-nbsp'}) {
609 $str =~ s/ / /g;
611 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
615 # Make control characters "printable", using character escape codes (CEC)
618 my %es = ( # character escape codes, aka escape sequences
619 "\t" => '\t', # tab (HT)
620 "\n" => '\n', # line feed (LF)
621 "\r" => '\r', # carrige return (CR)
622 "\f" => '\f', # form feed (FF)
623 "\b" => '\b', # backspace (BS)
624 "\a" => '\a', # alarm (bell) (BEL)
625 "\e" => '\e', # escape (ESC)
626 "\013" => '\v', # vertical tab (VT)
627 "\000" => '\0', # nul character (NUL)
629 my $chr = ( (exists $es{$cntrl})
631 : sprintf('\%03o', ord($cntrl)) );
632 return "<span class=\"cntrl\">$chr</span>";
635 # Alternatively use unicode control pictures codepoints,
636 # Unicode "printable representation" (PR)
639 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
640 return "<span class=\"cntrl\">$chr</span>";
643 # git may return quoted and escaped filenames
649 my %es = ( # character escape codes, aka escape sequences
650 't' => "\t", # tab (HT, TAB)
651 'n' => "\n", # newline (NL)
652 'r' => "\r", # return (CR)
653 'f' => "\f", # form feed (FF)
654 'b' => "\b", # backspace (BS)
655 'a' => "\a", # alarm (bell) (BEL)
656 'e' => "\e", # escape (ESC)
657 'v' => "\013", # vertical tab (VT)
660 if ($seq =~ m/^[0-7]{1,3}$/) {
661 # octal char sequence
662 return chr(oct($seq));
663 } elsif (exists $es{$seq}) {
664 # C escape sequence, aka character escape code
667 # quoted ordinary character
671 if ($str =~ m/^"(.*)"$/) {
674 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
679 # escape tabs (convert tabs to spaces)
683 while ((my $pos = index($line, "\t")) != -1) {
684 if (my $count = (8 - ($pos % 8))) {
685 my $spaces = ' ' x
$count;
686 $line =~ s/\t/$spaces/;
693 sub project_in_list
{
695 my @list = git_get_projects_list
();
696 return @list && scalar(grep { $_->{'path'} eq $project } @list);
699 ## ----------------------------------------------------------------------
700 ## HTML aware string manipulation
705 my $add_len = shift || 10;
707 # allow only $len chars, but don't cut a word if it would fit in $add_len
708 # if it doesn't fit, cut it if it's still longer than the dots we would add
709 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
712 if (length($tail) > 4) {
714 $body =~ s/&[^;]*$//; # remove chopped character entities
719 ## ----------------------------------------------------------------------
720 ## functions returning short strings
722 # CSS class for given age value (in seconds)
726 if ($age < 60*60*2) {
728 } elsif ($age < 60*60*24*2) {
735 # convert age in seconds to "nn units ago" string
740 if ($age > 60*60*24*365*2) {
741 $age_str = (int $age/60/60/24/365);
742 $age_str .= " years ago";
743 } elsif ($age > 60*60*24*(365/12)*2) {
744 $age_str = int $age/60/60/24/(365/12);
745 $age_str .= " months ago";
746 } elsif ($age > 60*60*24*7*2) {
747 $age_str = int $age/60/60/24/7;
748 $age_str .= " weeks ago";
749 } elsif ($age > 60*60*24*2) {
750 $age_str = int $age/60/60/24;
751 $age_str .= " days ago";
752 } elsif ($age > 60*60*2) {
753 $age_str = int $age/60/60;
754 $age_str .= " hours ago";
755 } elsif ($age > 60*2) {
756 $age_str = int $age/60;
757 $age_str .= " min ago";
760 $age_str .= " sec ago";
762 $age_str .= " right now";
767 # convert file mode in octal to symbolic file mode string
769 my $mode = oct shift;
771 if (S_ISDIR
($mode & S_IFMT
)) {
773 } elsif (S_ISLNK
($mode)) {
775 } elsif (S_ISREG
($mode)) {
776 # git cares only about the executable bit
777 if ($mode & S_IXUSR
) {
787 # convert file mode in octal to file type string
791 if ($mode !~ m/^[0-7]+$/) {
797 if (S_ISDIR
($mode & S_IFMT
)) {
799 } elsif (S_ISLNK
($mode)) {
801 } elsif (S_ISREG
($mode)) {
808 # convert file mode in octal to file type description string
812 if ($mode !~ m/^[0-7]+$/) {
818 if (S_ISDIR
($mode & S_IFMT
)) {
820 } elsif (S_ISLNK
($mode)) {
822 } elsif (S_ISREG
($mode)) {
823 if ($mode & S_IXUSR
) {
834 ## ----------------------------------------------------------------------
835 ## functions returning short HTML fragments, or transforming HTML fragments
836 ## which don't belong to other sections
838 # format line of commit message.
839 sub format_log_line_html
{
842 $line = esc_html
($line, -nbsp
=>1);
843 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
846 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
847 -class => "text"}, $hash_text);
848 $line =~ s/$hash_text/$link/;
853 # format marker of refs pointing to given object
854 sub format_ref_marker
{
855 my ($refs, $id) = @_;
858 if (defined $refs->{$id}) {
859 foreach my $ref (@{$refs->{$id}}) {
860 my ($type, $name) = qw();
861 # e.g. tags/v2.6.11 or heads/next
862 if ($ref =~ m!^(.*?)s?/(.*)$!) {
870 $markers .= " <span class=\"$type\" title=\"$ref\">" .
871 esc_html
($name) . "</span>";
876 return ' <span class="refs">'. $markers . '</span>';
882 # format, perhaps shortened and with markers, title line
883 sub format_subject_html
{
884 my ($long, $short, $href, $extra) = @_;
885 $extra = '' unless defined($extra);
887 if (length($short) < length($long)) {
888 return $cgi->a({-href
=> $href, -class => "list subject",
889 -title
=> decode_utf8
($long)},
890 esc_html
($short) . $extra);
892 return $cgi->a({-href
=> $href, -class => "list subject"},
893 esc_html
($long) . $extra);
897 # format patch (diff) line (rather not to be used for diff headers)
898 sub format_diff_line
{
900 my ($from, $to) = @_;
901 my $char = substr($line, 0, 1);
907 $diff_class = " add";
908 } elsif ($char eq "-") {
909 $diff_class = " rem";
910 } elsif ($char eq "@") {
911 $diff_class = " chunk_header";
912 } elsif ($char eq "\\") {
913 $diff_class = " incomplete";
915 $line = untabify
($line);
916 if ($from && $to && $line =~ m/^\@{2} /) {
917 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
918 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
920 $from_lines = 0 unless defined $from_lines;
921 $to_lines = 0 unless defined $to_lines;
923 if ($from->{'href'}) {
924 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
925 -class=>"list"}, $from_text);
928 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
929 -class=>"list"}, $to_text);
931 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
932 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
933 return "<div class=\"diff$diff_class\">$line</div>\n";
935 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
938 ## ----------------------------------------------------------------------
939 ## git utility subroutines, invoking git commands
941 # returns path to the core git executable and the --git-dir parameter as list
943 return $GIT, '--git-dir='.$git_dir;
946 # returns path to the core git executable and the --git-dir parameter as string
948 return join(' ', git_cmd
());
951 # get HEAD ref of given project as hash
952 sub git_get_head_hash
{
954 my $o_git_dir = $git_dir;
956 $git_dir = "$projectroot/$project";
957 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
960 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
964 if (defined $o_git_dir) {
965 $git_dir = $o_git_dir;
970 # get type of given object
974 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
981 sub git_get_project_config
{
982 my ($key, $type) = @_;
984 return unless ($key);
985 $key =~ s/^gitweb\.//;
986 return if ($key =~ m/\W/);
988 my @x = (git_cmd
(), 'config');
989 if (defined $type) { push @x, $type; }
991 push @x, "gitweb.$key";
997 # get hash of given path at given ref
998 sub git_get_hash_by_path
{
1000 my $path = shift || return undef;
1005 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1006 or die_error
(undef, "Open git-ls-tree failed");
1008 close $fd or return undef;
1010 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1011 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1012 if (defined $type && $type ne $2) {
1013 # type doesn't match
1019 # get path of entry with given hash at given tree-ish (ref)
1020 # used to get 'from' filename for combined diff (merge commit) for renames
1021 sub git_get_path_by_hash
{
1022 my $base = shift || return;
1023 my $hash = shift || return;
1027 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1029 while (my $line = <$fd>) {
1032 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1033 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1034 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1043 ## ......................................................................
1044 ## git utility functions, directly accessing git repository
1046 sub git_get_project_description
{
1049 open my $fd, "$projectroot/$path/description" or return undef;
1056 sub git_get_project_url_list
{
1059 open my $fd, "$projectroot/$path/cloneurl" or return;
1060 my @git_project_url_list = map { chomp; $_ } <$fd>;
1063 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1066 sub git_get_projects_list
{
1071 $filter =~ s/\.git$//;
1073 my ($check_forks) = gitweb_check_feature
('forks');
1075 if (-d
$projects_list) {
1076 # search in directory
1077 my $dir = $projects_list . ($filter ? "/$filter" : '');
1078 # remove the trailing "/"
1080 my $pfxlen = length("$dir");
1083 follow_fast
=> 1, # follow symbolic links
1084 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1086 # skip project-list toplevel, if we get it.
1087 return if (m!^[/.]$!);
1088 # only directories can be git repositories
1089 return unless (-d
$_);
1091 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1092 # we check related file in $projectroot
1093 if ($check_forks and $subdir =~ m
#/.#) {
1094 $File::Find
::prune
= 1;
1095 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1096 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1097 $File::Find
::prune
= 1;
1102 } elsif (-f
$projects_list) {
1103 # read from file(url-encoded):
1104 # 'git%2Fgit.git Linus+Torvalds'
1105 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1106 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1108 open my ($fd), $projects_list or return;
1110 while (my $line = <$fd>) {
1112 my ($path, $owner) = split ' ', $line;
1113 $path = unescape
($path);
1114 $owner = unescape
($owner);
1115 if (!defined $path) {
1118 if ($filter ne '') {
1119 # looking for forks;
1120 my $pfx = substr($path, 0, length($filter));
1121 if ($pfx ne $filter) {
1124 my $sfx = substr($path, length($filter));
1125 if ($sfx !~ /^\/.*\
.git
$/) {
1128 } elsif ($check_forks) {
1130 foreach my $filter (keys %paths) {
1131 # looking for forks;
1132 my $pfx = substr($path, 0, length($filter));
1133 if ($pfx ne $filter) {
1136 my $sfx = substr($path, length($filter));
1137 if ($sfx !~ /^\/.*\
.git
$/) {
1140 # is a fork, don't include it in
1145 if (check_export_ok
("$projectroot/$path")) {
1148 owner
=> decode_utf8
($owner),
1151 (my $forks_path = $path) =~ s/\.git$//;
1152 $paths{$forks_path}++;
1160 sub git_get_project_owner
{
1161 my $project = shift;
1164 return undef unless $project;
1166 # read from file (url-encoded):
1167 # 'git%2Fgit.git Linus+Torvalds'
1168 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1169 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1170 if (-f
$projects_list) {
1171 open (my $fd , $projects_list);
1172 while (my $line = <$fd>) {
1174 my ($pr, $ow) = split ' ', $line;
1175 $pr = unescape
($pr);
1176 $ow = unescape
($ow);
1177 if ($pr eq $project) {
1178 $owner = decode_utf8
($ow);
1184 if (!defined $owner) {
1185 $owner = get_file_owner
("$projectroot/$project");
1191 sub git_get_last_activity
{
1195 $git_dir = "$projectroot/$path";
1196 open($fd, "-|", git_cmd
(), 'for-each-ref',
1197 '--format=%(committer)',
1198 '--sort=-committerdate',
1200 'refs/heads') or return;
1201 my $most_recent = <$fd>;
1202 close $fd or return;
1203 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1205 my $age = time - $timestamp;
1206 return ($age, age_string
($age));
1210 sub git_get_references
{
1211 my $type = shift || "";
1213 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1214 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1215 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1216 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1219 while (my $line = <$fd>) {
1221 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1222 if (defined $refs{$1}) {
1223 push @{$refs{$1}}, $2;
1229 close $fd or return;
1233 sub git_get_rev_name_tags
{
1234 my $hash = shift || return undef;
1236 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1238 my $name_rev = <$fd>;
1241 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1244 # catches also '$hash undefined' output
1249 ## ----------------------------------------------------------------------
1250 ## parse to hash functions
1254 my $tz = shift || "-0000";
1257 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1258 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1259 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1260 $date{'hour'} = $hour;
1261 $date{'minute'} = $min;
1262 $date{'mday'} = $mday;
1263 $date{'day'} = $days[$wday];
1264 $date{'month'} = $months[$mon];
1265 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1266 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1267 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1268 $mday, $months[$mon], $hour ,$min;
1269 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1270 1900+$year, $mon, $mday, $hour ,$min, $sec;
1272 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1273 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1274 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1275 $date{'hour_local'} = $hour;
1276 $date{'minute_local'} = $min;
1277 $date{'tz_local'} = $tz;
1278 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1279 1900+$year, $mon+1, $mday,
1280 $hour, $min, $sec, $tz);
1289 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1290 $tag{'id'} = $tag_id;
1291 while (my $line = <$fd>) {
1293 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1294 $tag{'object'} = $1;
1295 } elsif ($line =~ m/^type (.+)$/) {
1297 } elsif ($line =~ m/^tag (.+)$/) {
1299 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1300 $tag{'author'} = $1;
1303 } elsif ($line =~ m/--BEGIN/) {
1304 push @comment, $line;
1306 } elsif ($line eq "") {
1310 push @comment, <$fd>;
1311 $tag{'comment'} = \
@comment;
1312 close $fd or return;
1313 if (!defined $tag{'name'}) {
1319 sub parse_commit_text
{
1320 my ($commit_text, $withparents) = @_;
1321 my @commit_lines = split '\n', $commit_text;
1324 pop @commit_lines; # Remove '\0'
1326 my $header = shift @commit_lines;
1327 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1330 ($co{'id'}, my @parents) = split ' ', $header;
1331 while (my $line = shift @commit_lines) {
1332 last if $line eq "\n";
1333 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1335 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1337 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1339 $co{'author_epoch'} = $2;
1340 $co{'author_tz'} = $3;
1341 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1342 $co{'author_name'} = $1;
1343 $co{'author_email'} = $2;
1345 $co{'author_name'} = $co{'author'};
1347 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1348 $co{'committer'} = $1;
1349 $co{'committer_epoch'} = $2;
1350 $co{'committer_tz'} = $3;
1351 $co{'committer_name'} = $co{'committer'};
1352 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1353 $co{'committer_name'} = $1;
1354 $co{'committer_email'} = $2;
1356 $co{'committer_name'} = $co{'committer'};
1360 if (!defined $co{'tree'}) {
1363 $co{'parents'} = \
@parents;
1364 $co{'parent'} = $parents[0];
1366 foreach my $title (@commit_lines) {
1369 $co{'title'} = chop_str
($title, 80, 5);
1370 # remove leading stuff of merges to make the interesting part visible
1371 if (length($title) > 50) {
1372 $title =~ s/^Automatic //;
1373 $title =~ s/^merge (of|with) /Merge ... /i;
1374 if (length($title) > 50) {
1375 $title =~ s/(http|rsync):\/\///;
1377 if (length($title) > 50) {
1378 $title =~ s/(master|www|rsync)\.//;
1380 if (length($title) > 50) {
1381 $title =~ s/kernel.org:?//;
1383 if (length($title) > 50) {
1384 $title =~ s/\/pub\/scm//;
1387 $co{'title_short'} = chop_str
($title, 50, 5);
1391 if ($co{'title'} eq "") {
1392 $co{'title'} = $co{'title_short'} = '(no commit message)';
1394 # remove added spaces
1395 foreach my $line (@commit_lines) {
1398 $co{'comment'} = \
@commit_lines;
1400 my $age = time - $co{'committer_epoch'};
1402 $co{'age_string'} = age_string
($age);
1403 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1404 if ($age > 60*60*24*7*2) {
1405 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1406 $co{'age_string_age'} = $co{'age_string'};
1408 $co{'age_string_date'} = $co{'age_string'};
1409 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1415 my ($commit_id) = @_;
1420 open my $fd, "-|", git_cmd
(), "rev-list",
1426 or die_error
(undef, "Open git-rev-list failed");
1427 %co = parse_commit_text
(<$fd>, 1);
1434 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1442 open my $fd, "-|", git_cmd
(), "rev-list",
1444 ($arg ? ($arg) : ()),
1445 ("--max-count=" . $maxcount),
1446 ("--skip=" . $skip),
1449 ($filename ? ($filename) : ())
1450 or die_error
(undef, "Open git-rev-list failed");
1451 while (my $line = <$fd>) {
1452 my %co = parse_commit_text
($line);
1457 return wantarray ? @cos : \
@cos;
1460 # parse ref from ref_file, given by ref_id, with given type
1462 my $ref_file = shift;
1464 my $type = shift || git_get_type
($ref_id);
1467 $ref_item{'type'} = $type;
1468 $ref_item{'id'} = $ref_id;
1469 $ref_item{'epoch'} = 0;
1470 $ref_item{'age'} = "unknown";
1471 if ($type eq "tag") {
1472 my %tag = parse_tag
($ref_id);
1473 $ref_item{'comment'} = $tag{'comment'};
1474 if ($tag{'type'} eq "commit") {
1475 my %co = parse_commit
($tag{'object'});
1476 $ref_item{'epoch'} = $co{'committer_epoch'};
1477 $ref_item{'age'} = $co{'age_string'};
1478 } elsif (defined($tag{'epoch'})) {
1479 my $age = time - $tag{'epoch'};
1480 $ref_item{'epoch'} = $tag{'epoch'};
1481 $ref_item{'age'} = age_string
($age);
1483 $ref_item{'reftype'} = $tag{'type'};
1484 $ref_item{'name'} = $tag{'name'};
1485 $ref_item{'refid'} = $tag{'object'};
1486 } elsif ($type eq "commit"){
1487 my %co = parse_commit
($ref_id);
1488 $ref_item{'reftype'} = "commit";
1489 $ref_item{'name'} = $ref_file;
1490 $ref_item{'title'} = $co{'title'};
1491 $ref_item{'refid'} = $ref_id;
1492 $ref_item{'epoch'} = $co{'committer_epoch'};
1493 $ref_item{'age'} = $co{'age_string'};
1495 $ref_item{'reftype'} = $type;
1496 $ref_item{'name'} = $ref_file;
1497 $ref_item{'refid'} = $ref_id;
1503 # parse line of git-diff-tree "raw" output
1504 sub parse_difftree_raw_line
{
1508 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1509 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1510 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1511 $res{'from_mode'} = $1;
1512 $res{'to_mode'} = $2;
1513 $res{'from_id'} = $3;
1515 $res{'status'} = $5;
1516 $res{'similarity'} = $6;
1517 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1518 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1520 $res{'file'} = unquote
($7);
1523 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1524 # combined diff (for merge commit)
1525 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1526 $res{'nparents'} = length($1);
1527 $res{'from_mode'} = [ split(' ', $2) ];
1528 $res{'to_mode'} = pop @{$res{'from_mode'}};
1529 $res{'from_id'} = [ split(' ', $3) ];
1530 $res{'to_id'} = pop @{$res{'from_id'}};
1531 $res{'status'} = [ split('', $4) ];
1532 $res{'to_file'} = unquote
($5);
1534 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1535 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1536 $res{'commit'} = $1;
1539 return wantarray ? %res : \
%res;
1542 # parse line of git-ls-tree output
1543 sub parse_ls_tree_line
($;%) {
1548 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1549 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1557 $res{'name'} = unquote
($4);
1560 return wantarray ? %res : \
%res;
1563 ## ......................................................................
1564 ## parse to array of hashes functions
1566 sub git_get_heads_list
{
1570 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1571 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1572 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1575 while (my $line = <$fd>) {
1579 my ($refinfo, $committerinfo) = split(/\0/, $line);
1580 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1581 my ($committer, $epoch, $tz) =
1582 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1583 $name =~ s!^refs/heads/!!;
1585 $ref_item{'name'} = $name;
1586 $ref_item{'id'} = $hash;
1587 $ref_item{'title'} = $title || '(no commit message)';
1588 $ref_item{'epoch'} = $epoch;
1590 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1592 $ref_item{'age'} = "unknown";
1595 push @headslist, \
%ref_item;
1599 return wantarray ? @headslist : \
@headslist;
1602 sub git_get_tags_list
{
1606 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1607 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1608 '--format=%(objectname) %(objecttype) %(refname) '.
1609 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1612 while (my $line = <$fd>) {
1616 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1617 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1618 my ($creator, $epoch, $tz) =
1619 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1620 $name =~ s!^refs/tags/!!;
1622 $ref_item{'type'} = $type;
1623 $ref_item{'id'} = $id;
1624 $ref_item{'name'} = $name;
1625 if ($type eq "tag") {
1626 $ref_item{'subject'} = $title;
1627 $ref_item{'reftype'} = $reftype;
1628 $ref_item{'refid'} = $refid;
1630 $ref_item{'reftype'} = $type;
1631 $ref_item{'refid'} = $id;
1634 if ($type eq "tag" || $type eq "commit") {
1635 $ref_item{'epoch'} = $epoch;
1637 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1639 $ref_item{'age'} = "unknown";
1643 push @tagslist, \
%ref_item;
1647 return wantarray ? @tagslist : \
@tagslist;
1650 ## ----------------------------------------------------------------------
1651 ## filesystem-related functions
1653 sub get_file_owner
{
1656 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1657 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1658 if (!defined $gcos) {
1662 $owner =~ s/[,;].*$//;
1663 return decode_utf8
($owner);
1666 ## ......................................................................
1667 ## mimetype related functions
1669 sub mimetype_guess_file
{
1670 my $filename = shift;
1671 my $mimemap = shift;
1672 -r
$mimemap or return undef;
1675 open(MIME
, $mimemap) or return undef;
1677 next if m/^#/; # skip comments
1678 my ($mime, $exts) = split(/\t+/);
1679 if (defined $exts) {
1680 my @exts = split(/\s+/, $exts);
1681 foreach my $ext (@exts) {
1682 $mimemap{$ext} = $mime;
1688 $filename =~ /\.([^.]*)$/;
1689 return $mimemap{$1};
1692 sub mimetype_guess
{
1693 my $filename = shift;
1695 $filename =~ /\./ or return undef;
1697 if ($mimetypes_file) {
1698 my $file = $mimetypes_file;
1699 if ($file !~ m!^/!) { # if it is relative path
1700 # it is relative to project
1701 $file = "$projectroot/$project/$file";
1703 $mime = mimetype_guess_file
($filename, $file);
1705 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1711 my $filename = shift;
1714 my $mime = mimetype_guess
($filename);
1715 $mime and return $mime;
1719 return $default_blob_plain_mimetype unless $fd;
1722 return 'text/plain' .
1723 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1724 } elsif (! $filename) {
1725 return 'application/octet-stream';
1726 } elsif ($filename =~ m/\.png$/i) {
1728 } elsif ($filename =~ m/\.gif$/i) {
1730 } elsif ($filename =~ m/\.jpe?g$/i) {
1731 return 'image/jpeg';
1733 return 'application/octet-stream';
1737 ## ======================================================================
1738 ## functions printing HTML: header, footer, error page
1740 sub git_header_html
{
1741 my $status = shift || "200 OK";
1742 my $expires = shift;
1744 my $title = "$site_name";
1745 if (defined $project) {
1746 $title .= " - " . decode_utf8
($project);
1747 if (defined $action) {
1748 $title .= "/$action";
1749 if (defined $file_name) {
1750 $title .= " - " . esc_path
($file_name);
1751 if ($action eq "tree" && $file_name !~ m
|/$|) {
1758 # require explicit support from the UA if we are to send the page as
1759 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1760 # we have to do this because MSIE sometimes globs '*/*', pretending to
1761 # support xhtml+xml but choking when it gets what it asked for.
1762 if (defined $cgi->http('HTTP_ACCEPT') &&
1763 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1764 $cgi->Accept('application/xhtml+xml') != 0) {
1765 $content_type = 'application/xhtml+xml';
1767 $content_type = 'text/html';
1769 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1770 -status
=> $status, -expires
=> $expires);
1771 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1773 <?xml version="1.0" encoding="utf-8"?>
1774 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1775 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1776 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1777 <!-- git core binaries version $git_version -->
1779 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1780 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1781 <meta name="robots" content="index, nofollow"/>
1782 <title>$title</title>
1784 # print out each stylesheet that exist
1785 if (defined $stylesheet) {
1786 #provides backwards capability for those people who define style sheet in a config file
1787 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1789 foreach my $stylesheet (@stylesheets) {
1790 next unless $stylesheet;
1791 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1794 if (defined $project) {
1795 printf('<link rel="alternate" title="%s log RSS feed" '.
1796 'href="%s" type="application/rss+xml" />'."\n",
1797 esc_param
($project), href
(action
=>"rss"));
1798 printf('<link rel="alternate" title="%s log Atom feed" '.
1799 'href="%s" type="application/atom+xml" />'."\n",
1800 esc_param
($project), href
(action
=>"atom"));
1802 printf('<link rel="alternate" title="%s projects list" '.
1803 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1804 $site_name, href
(project
=>undef, action
=>"project_index"));
1805 printf('<link rel="alternate" title="%s projects feeds" '.
1806 'href="%s" type="text/x-opml"/>'."\n",
1807 $site_name, href
(project
=>undef, action
=>"opml"));
1809 if (defined $favicon) {
1810 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1816 if (-f
$site_header) {
1817 open (my $fd, $site_header);
1822 print "<div class=\"page_header\">\n" .
1823 $cgi->a({-href
=> esc_url
($logo_url),
1824 -title
=> $logo_label},
1825 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1826 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1827 if (defined $project) {
1828 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1829 if (defined $action) {
1834 my ($have_search) = gitweb_check_feature
('search');
1835 if ((defined $project) && ($have_search)) {
1836 if (!defined $searchtext) {
1840 if (defined $hash_base) {
1841 $search_hash = $hash_base;
1842 } elsif (defined $hash) {
1843 $search_hash = $hash;
1845 $search_hash = "HEAD";
1847 $cgi->param("a", "search");
1848 $cgi->param("h", $search_hash);
1849 $cgi->param("p", $project);
1850 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1851 "<div class=\"search\">\n" .
1852 $cgi->hidden(-name
=> "p") . "\n" .
1853 $cgi->hidden(-name
=> "a") . "\n" .
1854 $cgi->hidden(-name
=> "h") . "\n" .
1855 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1856 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1857 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1859 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1861 $cgi->end_form() . "\n";
1866 sub git_footer_html
{
1867 print "<div class=\"page_footer\">\n";
1868 if (defined $project) {
1869 my $descr = git_get_project_description
($project);
1870 if (defined $descr) {
1871 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1873 print $cgi->a({-href
=> href
(action
=>"rss"),
1874 -class => "rss_logo"}, "RSS") . " ";
1875 print $cgi->a({-href
=> href
(action
=>"atom"),
1876 -class => "rss_logo"}, "Atom") . "\n";
1878 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1879 -class => "rss_logo"}, "OPML") . " ";
1880 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1881 -class => "rss_logo"}, "TXT") . "\n";
1885 if (-f
$site_footer) {
1886 open (my $fd, $site_footer);
1896 my $status = shift || "403 Forbidden";
1897 my $error = shift || "Malformed query, file missing or permission denied";
1899 git_header_html
($status);
1901 <div class="page_body">
1911 ## ----------------------------------------------------------------------
1912 ## functions printing or outputting HTML: navigation
1914 sub git_print_page_nav
{
1915 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1916 $extra = '' if !defined $extra; # pager or formats
1918 my @navs = qw(summary shortlog log commit commitdiff tree);
1920 @navs = grep { $_ ne $suppress } @navs;
1923 my %arg = map { $_ => {action
=>$_} } @navs;
1924 if (defined $head) {
1925 for (qw(commit commitdiff)) {
1926 $arg{$_}{'hash'} = $head;
1928 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1929 for (qw(shortlog log)) {
1930 $arg{$_}{'hash'} = $head;
1934 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1935 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1937 print "<div class=\"page_nav\">\n" .
1939 map { $_ eq $current ?
1940 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1942 print "<br/>\n$extra<br/>\n" .
1946 sub format_paging_nav
{
1947 my ($action, $hash, $head, $page, $nrevs) = @_;
1951 if ($hash ne $head || $page) {
1952 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1954 $paging_nav .= "HEAD";
1958 $paging_nav .= " ⋅ " .
1959 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1960 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1962 $paging_nav .= " ⋅ prev";
1965 if ($nrevs >= (100 * ($page+1)-1)) {
1966 $paging_nav .= " ⋅ " .
1967 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1968 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1970 $paging_nav .= " ⋅ next";
1976 ## ......................................................................
1977 ## functions printing or outputting HTML: div
1979 sub git_print_header_div
{
1980 my ($action, $title, $hash, $hash_base) = @_;
1983 $args{'action'} = $action;
1984 $args{'hash'} = $hash if $hash;
1985 $args{'hash_base'} = $hash_base if $hash_base;
1987 print "<div class=\"header\">\n" .
1988 $cgi->a({-href
=> href
(%args), -class => "title"},
1989 $title ? $title : $action) .
1993 #sub git_print_authorship (\%) {
1994 sub git_print_authorship
{
1997 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1998 print "<div class=\"author_date\">" .
1999 esc_html
($co->{'author_name'}) .
2001 if ($ad{'hour_local'} < 6) {
2002 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2003 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2005 printf(" (%02d:%02d %s)",
2006 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2011 sub git_print_page_path
{
2017 print "<div class=\"page_path\">";
2018 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2019 -title
=> 'tree root'}, decode_utf8
("[$project]"));
2021 if (defined $name) {
2022 my @dirname = split '/', $name;
2023 my $basename = pop @dirname;
2026 foreach my $dir (@dirname) {
2027 $fullname .= ($fullname ? '/' : '') . $dir;
2028 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2030 -title
=> $fullname}, esc_path
($dir));
2033 if (defined $type && $type eq 'blob') {
2034 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2036 -title
=> $name}, esc_path
($basename));
2037 } elsif (defined $type && $type eq 'tree') {
2038 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2040 -title
=> $name}, esc_path
($basename));
2043 print esc_path
($basename);
2046 print "<br/></div>\n";
2049 # sub git_print_log (\@;%) {
2050 sub git_print_log
($;%) {
2054 if ($opts{'-remove_title'}) {
2055 # remove title, i.e. first line of log
2058 # remove leading empty lines
2059 while (defined $log->[0] && $log->[0] eq "") {
2066 foreach my $line (@$log) {
2067 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2070 if (! $opts{'-remove_signoff'}) {
2071 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2074 # remove signoff lines
2081 # print only one empty line
2082 # do not print empty line after signoff
2084 next if ($empty || $signoff);
2090 print format_log_line_html
($line) . "<br/>\n";
2093 if ($opts{'-final_empty_line'}) {
2094 # end with single empty line
2095 print "<br/>\n" unless $empty;
2099 # return link target (what link points to)
2100 sub git_get_link_target
{
2105 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2109 $link_target = <$fd>;
2114 return $link_target;
2117 # given link target, and the directory (basedir) the link is in,
2118 # return target of link relative to top directory (top tree);
2119 # return undef if it is not possible (including absolute links).
2120 sub normalize_link_target
{
2121 my ($link_target, $basedir, $hash_base) = @_;
2123 # we can normalize symlink target only if $hash_base is provided
2124 return unless $hash_base;
2126 # absolute symlinks (beginning with '/') cannot be normalized
2127 return if (substr($link_target, 0, 1) eq '/');
2129 # normalize link target to path from top (root) tree (dir)
2132 $path = $basedir . '/' . $link_target;
2134 # we are in top (root) tree (dir)
2135 $path = $link_target;
2138 # remove //, /./, and /../
2140 foreach my $part (split('/', $path)) {
2141 # discard '.' and ''
2142 next if (!$part || $part eq '.');
2144 if ($part eq '..') {
2148 # link leads outside repository (outside top dir)
2152 push @path_parts, $part;
2155 $path = join('/', @path_parts);
2160 # print tree entry (row of git_tree), but without encompassing <tr> element
2161 sub git_print_tree_entry
{
2162 my ($t, $basedir, $hash_base, $have_blame) = @_;
2165 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2167 # The format of a table row is: mode list link. Where mode is
2168 # the mode of the entry, list is the name of the entry, an href,
2169 # and link is the action links of the entry.
2171 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2172 if ($t->{'type'} eq "blob") {
2173 print "<td class=\"list\">" .
2174 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2175 file_name
=>"$basedir$t->{'name'}", %base_key),
2176 -class => "list"}, esc_path
($t->{'name'}));
2177 if (S_ISLNK
(oct $t->{'mode'})) {
2178 my $link_target = git_get_link_target
($t->{'hash'});
2180 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2181 if (defined $norm_target) {
2183 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2184 file_name
=>$norm_target),
2185 -title
=> $norm_target}, esc_path
($link_target));
2187 print " -> " . esc_path
($link_target);
2192 print "<td class=\"link\">";
2193 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2194 file_name
=>"$basedir$t->{'name'}", %base_key)},
2198 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2199 file_name
=>"$basedir$t->{'name'}", %base_key)},
2202 if (defined $hash_base) {
2204 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2205 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2209 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2210 file_name
=>"$basedir$t->{'name'}")},
2214 } elsif ($t->{'type'} eq "tree") {
2215 print "<td class=\"list\">";
2216 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2217 file_name
=>"$basedir$t->{'name'}", %base_key)},
2218 esc_path
($t->{'name'}));
2220 print "<td class=\"link\">";
2221 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2222 file_name
=>"$basedir$t->{'name'}", %base_key)},
2224 if (defined $hash_base) {
2226 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2227 file_name
=>"$basedir$t->{'name'}")},
2234 ## ......................................................................
2235 ## functions printing large fragments of HTML
2237 sub git_difftree_body
{
2238 my ($difftree, $hash, @parents) = @_;
2239 my ($parent) = $parents[0];
2240 my ($have_blame) = gitweb_check_feature
('blame');
2241 print "<div class=\"list_head\">\n";
2242 if ($#{$difftree} > 10) {
2243 print(($#{$difftree} + 1) . " files changed:\n");
2247 print "<table class=\"" .
2248 (@parents > 1 ? "combined " : "") .
2252 foreach my $line (@{$difftree}) {
2253 my %diff = parse_difftree_raw_line
($line);
2256 print "<tr class=\"dark\">\n";
2258 print "<tr class=\"light\">\n";
2262 if (exists $diff{'nparents'}) { # combined diff
2264 if ($diff{'to_id'} ne ('0' x
40)) {
2265 # file exists in the result (child) commit
2267 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2268 file_name
=>$diff{'to_file'},
2270 -class => "list"}, esc_path
($diff{'to_file'})) .
2274 esc_path
($diff{'to_file'}) .
2278 if ($action eq 'commitdiff') {
2281 print "<td class=\"link\">" .
2282 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2287 my $has_history = 0;
2288 my $not_deleted = 0;
2289 for (my $i = 0; $i < $diff{'nparents'}; $i++) {
2290 my $hash_parent = $parents[$i];
2291 my $from_hash = $diff{'from_id'}[$i];
2292 my $from_path = undef;
2293 my $status = $diff{'status'}[$i];
2295 $has_history ||= ($status ne 'A');
2296 $not_deleted ||= ($status ne 'D');
2298 if ($status eq 'R' || $status eq 'C') {
2299 $from_path = git_get_path_by_hash
($hash_parent, $from_hash);
2302 if ($status eq 'A') {
2303 print "<td class=\"link\" align=\"right\"> | </td>\n";
2304 } elsif ($status eq 'D') {
2305 print "<td class=\"link\">" .
2306 $cgi->a({-href
=> href
(action
=>"blob",
2309 file_name
=>$from_path)},
2313 if ($diff{'to_id'} eq $from_hash) {
2314 print "<td class=\"link nochange\">";
2316 print "<td class=\"link\">";
2318 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2319 hash
=>$diff{'to_id'},
2320 hash_parent
=>$from_hash,
2322 hash_parent_base
=>$hash_parent,
2323 file_name
=>$diff{'to_file'},
2324 file_parent
=>$from_path)},
2330 print "<td class=\"link\">";
2332 print $cgi->a({-href
=> href
(action
=>"blob",
2333 hash
=>$diff{'to_id'},
2334 file_name
=>$diff{'to_file'},
2337 print " | " if ($has_history);
2340 print $cgi->a({-href
=> href
(action
=>"history",
2341 file_name
=>$diff{'to_file'},
2348 next; # instead of 'else' clause, to avoid extra indent
2350 # else ordinary diff
2352 my ($to_mode_oct, $to_mode_str, $to_file_type);
2353 my ($from_mode_oct, $from_mode_str, $from_file_type);
2354 if ($diff{'to_mode'} ne ('0' x
6)) {
2355 $to_mode_oct = oct $diff{'to_mode'};
2356 if (S_ISREG
($to_mode_oct)) { # only for regular file
2357 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2359 $to_file_type = file_type
($diff{'to_mode'});
2361 if ($diff{'from_mode'} ne ('0' x
6)) {
2362 $from_mode_oct = oct $diff{'from_mode'};
2363 if (S_ISREG
($to_mode_oct)) { # only for regular file
2364 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2366 $from_file_type = file_type
($diff{'from_mode'});
2369 if ($diff{'status'} eq "A") { # created
2370 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2371 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2372 $mode_chng .= "]</span>";
2374 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2375 hash_base
=>$hash, file_name
=>$diff{'file'}),
2376 -class => "list"}, esc_path
($diff{'file'}));
2378 print "<td>$mode_chng</td>\n";
2379 print "<td class=\"link\">";
2380 if ($action eq 'commitdiff') {
2383 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2386 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2387 hash_base
=>$hash, file_name
=>$diff{'file'})},
2391 } elsif ($diff{'status'} eq "D") { # deleted
2392 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2394 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2395 hash_base
=>$parent, file_name
=>$diff{'file'}),
2396 -class => "list"}, esc_path
($diff{'file'}));
2398 print "<td>$mode_chng</td>\n";
2399 print "<td class=\"link\">";
2400 if ($action eq 'commitdiff') {
2403 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2406 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2407 hash_base
=>$parent, file_name
=>$diff{'file'})},
2410 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2411 file_name
=>$diff{'file'})},
2414 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2415 file_name
=>$diff{'file'})},
2419 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2420 my $mode_chnge = "";
2421 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2422 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2423 if ($from_file_type ne $to_file_type) {
2424 $mode_chnge .= " from $from_file_type to $to_file_type";
2426 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2427 if ($from_mode_str && $to_mode_str) {
2428 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2429 } elsif ($to_mode_str) {
2430 $mode_chnge .= " mode: $to_mode_str";
2433 $mode_chnge .= "]</span>\n";
2436 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2437 hash_base
=>$hash, file_name
=>$diff{'file'}),
2438 -class => "list"}, esc_path
($diff{'file'}));
2440 print "<td>$mode_chnge</td>\n";
2441 print "<td class=\"link\">";
2442 if ($action eq 'commitdiff') {
2445 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2447 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2448 # "commit" view and modified file (not onlu mode changed)
2449 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2450 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2451 hash_base
=>$hash, hash_parent_base
=>$parent,
2452 file_name
=>$diff{'file'})},
2456 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2457 hash_base
=>$hash, file_name
=>$diff{'file'})},
2460 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2461 file_name
=>$diff{'file'})},
2464 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2465 file_name
=>$diff{'file'})},
2469 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2470 my %status_name = ('R' => 'moved', 'C' => 'copied');
2471 my $nstatus = $status_name{$diff{'status'}};
2473 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2474 # mode also for directories, so we cannot use $to_mode_str
2475 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2478 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2479 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2480 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2481 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2482 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2483 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2484 -class => "list"}, esc_path
($diff{'from_file'})) .
2485 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2486 "<td class=\"link\">";
2487 if ($action eq 'commitdiff') {
2490 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2492 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2493 # "commit" view and modified file (not only pure rename or copy)
2494 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2495 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2496 hash_base
=>$hash, hash_parent_base
=>$parent,
2497 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2501 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2502 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2505 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2506 file_name
=>$diff{'to_file'})},
2509 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2510 file_name
=>$diff{'to_file'})},
2514 } # we should not encounter Unmerged (U) or Unknown (X) status
2520 sub git_patchset_body
{
2521 my ($fd, $difftree, $hash, $hash_parent) = @_;
2524 my $patch_number = 0;
2529 print "<div class=\"patchset\">\n";
2531 # skip to first patch
2532 while ($patch_line = <$fd>) {
2535 last if ($patch_line =~ m/^diff /);
2539 while ($patch_line) {
2541 my ($from_id, $to_id);
2544 #assert($patch_line =~ m/^diff /) if DEBUG;
2545 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2547 push @diff_header, $patch_line;
2549 # extended diff header
2551 while ($patch_line = <$fd>) {
2554 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2556 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2561 push @diff_header, $patch_line;
2563 my $last_patch_line = $patch_line;
2565 # check if current patch belong to current raw line
2566 # and parse raw git-diff line if needed
2567 if (defined $diffinfo &&
2568 $diffinfo->{'from_id'} eq $from_id &&
2569 $diffinfo->{'to_id'} eq $to_id) {
2570 # this is split patch
2571 print "<div class=\"patch cont\">\n";
2573 # advance raw git-diff output if needed
2574 $patch_idx++ if defined $diffinfo;
2576 # read and prepare patch information
2577 if (ref($difftree->[$patch_idx]) eq "HASH") {
2578 # pre-parsed (or generated by hand)
2579 $diffinfo = $difftree->[$patch_idx];
2581 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2583 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2584 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2585 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2586 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2587 hash
=>$diffinfo->{'from_id'},
2588 file_name
=>$from{'file'});
2590 delete $from{'href'};
2592 if ($diffinfo->{'status'} ne "D") { # not deleted file
2593 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2594 hash
=>$diffinfo->{'to_id'},
2595 file_name
=>$to{'file'});
2599 # this is first patch for raw difftree line with $patch_idx index
2600 # we index @$difftree array from 0, but number patches from 1
2601 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2604 # print "git diff" header
2605 $patch_line = shift @diff_header;
2606 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2607 if ($from{'href'}) {
2608 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2609 'a/' . esc_path
($from{'file'}));
2610 } else { # file was added
2611 $patch_line .= 'a/' . esc_path
($from{'file'});
2615 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2616 'b/' . esc_path
($to{'file'}));
2617 } else { # file was deleted
2618 $patch_line .= 'b/' . esc_path
($to{'file'});
2620 print "<div class=\"diff header\">$patch_line</div>\n";
2622 # print extended diff header
2623 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2625 foreach $patch_line (@diff_header) {
2627 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2628 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2629 esc_path
($from{'file'}));
2631 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2632 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2633 esc_path
($to{'file'}));
2636 if ($patch_line =~ m/\s(\d{6})$/) {
2637 $patch_line .= '<span class="info"> (' .
2638 file_type_long
($1) .
2642 if ($patch_line =~ m/^index/) {
2643 my ($from_link, $to_link);
2644 if ($from{'href'}) {
2645 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2646 substr($diffinfo->{'from_id'},0,7));
2648 $from_link = '0' x
7;
2651 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2652 substr($diffinfo->{'to_id'},0,7));
2657 # my ($from_hash, $to_hash) =
2658 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2659 # my ($from_id, $to_id) =
2660 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2661 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2663 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2664 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2666 print $patch_line . "<br/>\n";
2668 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2670 # from-file/to-file diff header
2671 $patch_line = $last_patch_line;
2672 if (! $patch_line) {
2673 print "</div>\n"; # class="patch"
2676 next PATCH
if ($patch_line =~ m/^diff /);
2677 #assert($patch_line =~ m/^---/) if DEBUG;
2678 if ($from{'href'} && $patch_line =~ m!^--- "?a/!) {
2679 $patch_line = '--- a/' .
2680 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2681 esc_path
($from{'file'}));
2683 print "<div class=\"diff from_file\">$patch_line</div>\n";
2685 $patch_line = <$fd>;
2688 #assert($patch_line =~ m/^+++/) if DEBUG;
2689 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2690 $patch_line = '+++ b/' .
2691 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2692 esc_path
($to{'file'}));
2694 print "<div class=\"diff to_file\">$patch_line</div>\n";
2698 while ($patch_line = <$fd>) {
2701 next PATCH
if ($patch_line =~ m/^diff /);
2703 print format_diff_line
($patch_line, \
%from, \
%to);
2707 print "</div>\n"; # class="patch"
2709 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2711 print "</div>\n"; # class="patchset"
2714 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2716 sub git_project_list_body
{
2717 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2719 my ($check_forks) = gitweb_check_feature
('forks');
2722 foreach my $pr (@$projlist) {
2723 my (@aa) = git_get_last_activity
($pr->{'path'});
2727 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2728 if (!defined $pr->{'descr'}) {
2729 my $descr = git_get_project_description
($pr->{'path'}) || "";
2730 $pr->{'descr_long'} = decode_utf8
($descr);
2731 $pr->{'descr'} = chop_str
($descr, 25, 5);
2733 if (!defined $pr->{'owner'}) {
2734 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2737 my $pname = $pr->{'path'};
2738 if (($pname =~ s/\.git$//) &&
2739 ($pname !~ /\/$/) &&
2740 (-d
"$projectroot/$pname")) {
2741 $pr->{'forks'} = "-d $projectroot/$pname";
2747 push @projects, $pr;
2750 $order ||= $default_projects_order;
2751 $from = 0 unless defined $from;
2752 $to = $#projects if (!defined $to || $#projects < $to);
2754 print "<table class=\"project_list\">\n";
2755 unless ($no_header) {
2758 print "<th></th>\n";
2760 if ($order eq "project") {
2761 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2762 print "<th>Project</th>\n";
2765 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2766 -class => "header"}, "Project") .
2769 if ($order eq "descr") {
2770 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2771 print "<th>Description</th>\n";
2774 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2775 -class => "header"}, "Description") .
2778 if ($order eq "owner") {
2779 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2780 print "<th>Owner</th>\n";
2783 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2784 -class => "header"}, "Owner") .
2787 if ($order eq "age") {
2788 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2789 print "<th>Last Change</th>\n";
2792 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2793 -class => "header"}, "Last Change") .
2796 print "<th></th>\n" .
2800 for (my $i = $from; $i <= $to; $i++) {
2801 my $pr = $projects[$i];
2803 print "<tr class=\"dark\">\n";
2805 print "<tr class=\"light\">\n";
2810 if ($pr->{'forks'}) {
2811 print "<!-- $pr->{'forks'} -->\n";
2812 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2816 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2817 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2818 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2819 -class => "list", -title
=> $pr->{'descr_long'}},
2820 esc_html
($pr->{'descr'})) . "</td>\n" .
2821 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2822 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2823 $pr->{'age_string'} . "</td>\n" .
2824 "<td class=\"link\">" .
2825 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2826 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2827 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2828 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2829 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2833 if (defined $extra) {
2836 print "<td></td>\n";
2838 print "<td colspan=\"5\">$extra</td>\n" .
2844 sub git_shortlog_body
{
2845 # uses global variable $project
2846 my ($commitlist, $from, $to, $refs, $extra) = @_;
2848 my $have_snapshot = gitweb_have_snapshot
();
2850 $from = 0 unless defined $from;
2851 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2853 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2855 for (my $i = $from; $i <= $to; $i++) {
2856 my %co = %{$commitlist->[$i]};
2857 my $commit = $co{'id'};
2858 my $ref = format_ref_marker
($refs, $commit);
2860 print "<tr class=\"dark\">\n";
2862 print "<tr class=\"light\">\n";
2865 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2866 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2867 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2869 print format_subject_html
($co{'title'}, $co{'title_short'},
2870 href
(action
=>"commit", hash
=>$commit), $ref);
2872 "<td class=\"link\">" .
2873 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2874 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2875 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2876 if ($have_snapshot) {
2877 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2882 if (defined $extra) {
2884 "<td colspan=\"4\">$extra</td>\n" .
2890 sub git_history_body
{
2891 # Warning: assumes constant type (blob or tree) during history
2892 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2894 $from = 0 unless defined $from;
2895 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2897 print "<table class=\"history\" cellspacing=\"0\">\n";
2899 for (my $i = $from; $i <= $to; $i++) {
2900 my %co = %{$commitlist->[$i]};
2904 my $commit = $co{'id'};
2906 my $ref = format_ref_marker
($refs, $commit);
2909 print "<tr class=\"dark\">\n";
2911 print "<tr class=\"light\">\n";
2914 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2915 # shortlog uses chop_str($co{'author_name'}, 10)
2916 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2918 # originally git_history used chop_str($co{'title'}, 50)
2919 print format_subject_html
($co{'title'}, $co{'title_short'},
2920 href
(action
=>"commit", hash
=>$commit), $ref);
2922 "<td class=\"link\">" .
2923 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2924 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2926 if ($ftype eq 'blob') {
2927 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2928 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2929 if (defined $blob_current && defined $blob_parent &&
2930 $blob_current ne $blob_parent) {
2932 $cgi->a({-href
=> href
(action
=>"blobdiff",
2933 hash
=>$blob_current, hash_parent
=>$blob_parent,
2934 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2935 file_name
=>$file_name)},
2942 if (defined $extra) {
2944 "<td colspan=\"4\">$extra</td>\n" .
2951 # uses global variable $project
2952 my ($taglist, $from, $to, $extra) = @_;
2953 $from = 0 unless defined $from;
2954 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2956 print "<table class=\"tags\" cellspacing=\"0\">\n";
2958 for (my $i = $from; $i <= $to; $i++) {
2959 my $entry = $taglist->[$i];
2961 my $comment = $tag{'subject'};
2963 if (defined $comment) {
2964 $comment_short = chop_str
($comment, 30, 5);
2967 print "<tr class=\"dark\">\n";
2969 print "<tr class=\"light\">\n";
2972 if (defined $tag{'age'}) {
2973 print "<td><i>$tag{'age'}</i></td>\n";
2975 print "<td></td>\n";
2978 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2979 -class => "list name"}, esc_html
($tag{'name'})) .
2982 if (defined $comment) {
2983 print format_subject_html
($comment, $comment_short,
2984 href
(action
=>"tag", hash
=>$tag{'id'}));
2987 "<td class=\"selflink\">";
2988 if ($tag{'type'} eq "tag") {
2989 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2994 "<td class=\"link\">" . " | " .
2995 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2996 if ($tag{'reftype'} eq "commit") {
2997 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2998 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2999 } elsif ($tag{'reftype'} eq "blob") {
3000 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3005 if (defined $extra) {
3007 "<td colspan=\"5\">$extra</td>\n" .
3013 sub git_heads_body
{
3014 # uses global variable $project
3015 my ($headlist, $head, $from, $to, $extra) = @_;
3016 $from = 0 unless defined $from;
3017 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3019 print "<table class=\"heads\" cellspacing=\"0\">\n";
3021 for (my $i = $from; $i <= $to; $i++) {
3022 my $entry = $headlist->[$i];
3024 my $curr = $ref{'id'} eq $head;
3026 print "<tr class=\"dark\">\n";
3028 print "<tr class=\"light\">\n";
3031 print "<td><i>$ref{'age'}</i></td>\n" .
3032 ($curr ? "<td class=\"current_head\">" : "<td>") .
3033 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3034 -class => "list name"},esc_html
($ref{'name'})) .
3036 "<td class=\"link\">" .
3037 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3038 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3039 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3043 if (defined $extra) {
3045 "<td colspan=\"3\">$extra</td>\n" .
3051 sub git_search_grep_body
{
3052 my ($commitlist, $from, $to, $extra) = @_;
3053 $from = 0 unless defined $from;
3054 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3056 print "<table class=\"grep\" cellspacing=\"0\">\n";
3058 for (my $i = $from; $i <= $to; $i++) {
3059 my %co = %{$commitlist->[$i]};
3063 my $commit = $co{'id'};
3065 print "<tr class=\"dark\">\n";
3067 print "<tr class=\"light\">\n";
3070 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3071 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3073 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3074 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3075 my $comment = $co{'comment'};
3076 foreach my $line (@$comment) {
3077 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3078 my $lead = esc_html
($1) || "";
3079 $lead = chop_str
($lead, 30, 10);
3080 my $match = esc_html
($2) || "";
3081 my $trail = esc_html
($3) || "";
3082 $trail = chop_str
($trail, 30, 10);
3083 my $text = "$lead<span class=\"match\">$match</span>$trail";
3084 print chop_str
($text, 80, 5) . "<br/>\n";
3088 "<td class=\"link\">" .
3089 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3091 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3095 if (defined $extra) {
3097 "<td colspan=\"3\">$extra</td>\n" .
3103 ## ======================================================================
3104 ## ======================================================================
3107 sub git_project_list
{
3108 my $order = $cgi->param('o');
3109 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3110 die_error
(undef, "Unknown order parameter");
3113 my @list = git_get_projects_list
();
3115 die_error
(undef, "No projects found");
3119 if (-f
$home_text) {
3120 print "<div class=\"index_include\">\n";
3121 open (my $fd, $home_text);
3126 git_project_list_body
(\
@list, $order);
3131 my $order = $cgi->param('o');
3132 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3133 die_error
(undef, "Unknown order parameter");
3136 my @list = git_get_projects_list
($project);
3138 die_error
(undef, "No forks found");
3142 git_print_page_nav
('','');
3143 git_print_header_div
('summary', "$project forks");
3144 git_project_list_body
(\
@list, $order);
3148 sub git_project_index
{
3149 my @projects = git_get_projects_list
($project);
3152 -type
=> 'text/plain',
3153 -charset
=> 'utf-8',
3154 -content_disposition
=> 'inline; filename="index.aux"');
3156 foreach my $pr (@projects) {
3157 if (!exists $pr->{'owner'}) {
3158 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3161 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3162 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3163 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3164 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3168 print "$path $owner\n";
3173 my $descr = git_get_project_description
($project) || "none";
3174 my %co = parse_commit
("HEAD");
3175 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3176 my $head = $co{'id'};
3178 my $owner = git_get_project_owner
($project);
3180 my $refs = git_get_references
();
3181 # These get_*_list functions return one more to allow us to see if
3182 # there are more ...
3183 my @taglist = git_get_tags_list
(16);
3184 my @headlist = git_get_heads_list
(16);
3186 my ($check_forks) = gitweb_check_feature
('forks');
3189 @forklist = git_get_projects_list
($project);
3193 git_print_page_nav
('summary','', $head);
3195 print "<div class=\"title\"> </div>\n";
3196 print "<table cellspacing=\"0\">\n" .
3197 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3198 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3199 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3200 # use per project git URL list in $projectroot/$project/cloneurl
3201 # or make project git URL from git base URL and project name
3202 my $url_tag = "URL";
3203 my @url_list = git_get_project_url_list
($project);
3204 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3205 foreach my $git_url (@url_list) {
3206 next unless $git_url;
3207 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3212 if (-s
"$projectroot/$project/README.html") {
3213 if (open my $fd, "$projectroot/$project/README.html") {
3214 print "<div class=\"title\">readme</div>\n";
3215 print $_ while (<$fd>);
3220 # we need to request one more than 16 (0..15) to check if
3222 my @commitlist = parse_commits
($head, 17);
3223 git_print_header_div
('shortlog');
3224 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3225 $#commitlist <= 15 ? undef :
3226 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3229 git_print_header_div
('tags');
3230 git_tags_body
(\
@taglist, 0, 15,
3231 $#taglist <= 15 ? undef :
3232 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3236 git_print_header_div
('heads');
3237 git_heads_body
(\
@headlist, $head, 0, 15,
3238 $#headlist <= 15 ? undef :
3239 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3243 git_print_header_div
('forks');
3244 git_project_list_body
(\
@forklist, undef, 0, 15,
3245 $#forklist <= 15 ? undef :
3246 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3254 my $head = git_get_head_hash
($project);
3256 git_print_page_nav
('','', $head,undef,$head);
3257 my %tag = parse_tag
($hash);
3258 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3259 print "<div class=\"title_text\">\n" .
3260 "<table cellspacing=\"0\">\n" .
3262 "<td>object</td>\n" .
3263 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3264 $tag{'object'}) . "</td>\n" .
3265 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3266 $tag{'type'}) . "</td>\n" .
3268 if (defined($tag{'author'})) {
3269 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3270 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3271 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3272 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3275 print "</table>\n\n" .
3277 print "<div class=\"page_body\">";
3278 my $comment = $tag{'comment'};
3279 foreach my $line (@$comment) {
3281 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3291 my ($have_blame) = gitweb_check_feature
('blame');
3293 die_error
('403 Permission denied', "Permission denied");
3295 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3296 $hash_base ||= git_get_head_hash
($project);
3297 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3298 my %co = parse_commit
($hash_base)
3299 or die_error
(undef, "Reading commit failed");
3300 if (!defined $hash) {
3301 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3302 or die_error
(undef, "Error looking up file");
3304 $ftype = git_get_type
($hash);
3305 if ($ftype !~ "blob") {
3306 die_error
('400 Bad Request', "Object is not a blob");
3308 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3309 $file_name, $hash_base)
3310 or die_error
(undef, "Open git-blame failed");
3313 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3316 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3319 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3321 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3322 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3323 git_print_page_path
($file_name, $ftype, $hash_base);
3324 my @rev_color = (qw(light2 dark2));
3325 my $num_colors = scalar(@rev_color);
3326 my $current_color = 0;
3329 <div class="page_body">
3330 <table class="blame">
3331 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3336 last unless defined $_;
3337 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3338 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3339 if (!exists $metainfo{$full_rev}) {
3340 $metainfo{$full_rev} = {};
3342 my $meta = $metainfo{$full_rev};
3345 if (/^(\S+) (.*)$/) {
3351 my $rev = substr($full_rev, 0, 8);
3352 my $author = $meta->{'author'};
3353 my %date = parse_date
($meta->{'author-time'},
3354 $meta->{'author-tz'});
3355 my $date = $date{'iso-tz'};
3357 $current_color = ++$current_color % $num_colors;
3359 print "<tr class=\"$rev_color[$current_color]\">\n";
3361 print "<td class=\"sha1\"";
3362 print " title=\"". esc_html
($author) . ", $date\"";
3363 print " rowspan=\"$group_size\"" if ($group_size > 1);
3365 print $cgi->a({-href
=> href
(action
=>"commit",
3367 file_name
=>$file_name)},
3371 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3372 or die_error
(undef, "Open git-rev-parse failed");
3373 my $parent_commit = <$dd>;
3375 chomp($parent_commit);
3376 my $blamed = href
(action
=> 'blame',
3377 file_name
=> $meta->{'filename'},
3378 hash_base
=> $parent_commit);
3379 print "<td class=\"linenr\">";
3380 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3382 -class => "linenr" },
3385 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3391 or print "Reading blob failed\n";
3398 my ($have_blame) = gitweb_check_feature
('blame');
3400 die_error
('403 Permission denied', "Permission denied");
3402 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3403 $hash_base ||= git_get_head_hash
($project);
3404 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3405 my %co = parse_commit
($hash_base)
3406 or die_error
(undef, "Reading commit failed");
3407 if (!defined $hash) {
3408 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3409 or die_error
(undef, "Error lookup file");
3411 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3412 or die_error
(undef, "Open git-annotate failed");
3415 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3418 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3421 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3423 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3424 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3425 git_print_page_path
($file_name, 'blob', $hash_base);
3426 print "<div class=\"page_body\">\n";
3428 <table class="blame">
3437 my @line_class = (qw(light dark));
3438 my $line_class_len = scalar (@line_class);
3439 my $line_class_num = $#line_class;
3440 while (my $line = <$fd>) {
3452 $line_class_num = ($line_class_num + 1) % $line_class_len;
3454 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3461 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3464 $short_rev = substr ($long_rev, 0, 8);
3465 $age = time () - $time;
3466 $age_str = age_string
($age);
3467 $age_str =~ s/ / /g;
3468 $age_class = age_class
($age);
3469 $author = esc_html
($author);
3470 $author =~ s/ / /g;
3472 $data = untabify
($data);
3473 $data = esc_html
($data);
3476 <tr class="$line_class[$line_class_num]">
3477 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3478 <td class="$age_class">$age_str</td>
3480 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3481 <td class="pre">$data</td>
3484 } # while (my $line = <$fd>)
3485 print "</table>\n\n";
3487 or print "Reading blob failed.\n";
3493 my $head = git_get_head_hash
($project);
3495 git_print_page_nav
('','', $head,undef,$head);
3496 git_print_header_div
('summary', $project);
3498 my @tagslist = git_get_tags_list
();
3500 git_tags_body
(\
@tagslist);
3506 my $head = git_get_head_hash
($project);
3508 git_print_page_nav
('','', $head,undef,$head);
3509 git_print_header_div
('summary', $project);
3511 my @headslist = git_get_heads_list
();
3513 git_heads_body
(\
@headslist, $head);
3518 sub git_blob_plain
{
3521 if (!defined $hash) {
3522 if (defined $file_name) {
3523 my $base = $hash_base || git_get_head_hash
($project);
3524 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3525 or die_error
(undef, "Error lookup file");
3527 die_error
(undef, "No file name defined");
3529 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3530 # blobs defined by non-textual hash id's can be cached
3535 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3536 or die_error
(undef, "Couldn't cat $file_name, $hash");
3538 $type ||= blob_mimetype
($fd, $file_name);
3540 # save as filename, even when no $file_name is given
3541 my $save_as = "$hash";
3542 if (defined $file_name) {
3543 $save_as = $file_name;
3544 } elsif ($type =~ m/^text\//) {
3551 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3553 binmode STDOUT
, ':raw';
3555 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3563 if (!defined $hash) {
3564 if (defined $file_name) {
3565 my $base = $hash_base || git_get_head_hash
($project);
3566 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3567 or die_error
(undef, "Error lookup file");
3569 die_error
(undef, "No file name defined");
3571 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3572 # blobs defined by non-textual hash id's can be cached
3576 my ($have_blame) = gitweb_check_feature
('blame');
3577 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3578 or die_error
(undef, "Couldn't cat $file_name, $hash");
3579 my $mimetype = blob_mimetype
($fd, $file_name);
3580 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3582 return git_blob_plain
($mimetype);
3584 # we can have blame only for text/* mimetype
3585 $have_blame &&= ($mimetype =~ m!^text/!);
3587 git_header_html
(undef, $expires);
3588 my $formats_nav = '';
3589 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3590 if (defined $file_name) {
3593 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3594 hash
=>$hash, file_name
=>$file_name)},
3599 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3600 hash
=>$hash, file_name
=>$file_name)},
3603 $cgi->a({-href
=> href
(action
=>"blob_plain",
3604 hash
=>$hash, file_name
=>$file_name)},
3607 $cgi->a({-href
=> href
(action
=>"blob",
3608 hash_base
=>"HEAD", file_name
=>$file_name)},
3612 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3614 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3615 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3617 print "<div class=\"page_nav\">\n" .
3618 "<br/><br/></div>\n" .
3619 "<div class=\"title\">$hash</div>\n";
3621 git_print_page_path
($file_name, "blob", $hash_base);
3622 print "<div class=\"page_body\">\n";
3623 if ($mimetype =~ m!^text/!) {
3625 while (my $line = <$fd>) {
3628 $line = untabify
($line);
3629 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3630 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3632 } elsif ($mimetype =~ m!^image/!) {
3633 print qq
!<img type
="$mimetype"!;
3635 print qq
! alt
="$file_name" title
="$file_name"!;
3638 href(action=>"blob_plain
", hash=>$hash,
3639 hash_base=>$hash_base, file_name=>$file_name) .
3643 or print "Reading blob failed.\n";
3649 my $have_snapshot = gitweb_have_snapshot
();
3651 if (!defined $hash_base) {
3652 $hash_base = "HEAD";
3654 if (!defined $hash) {
3655 if (defined $file_name) {
3656 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3662 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3663 or die_error
(undef, "Open git-ls-tree failed");
3664 my @entries = map { chomp; $_ } <$fd>;
3665 close $fd or die_error
(undef, "Reading tree failed");
3668 my $refs = git_get_references
();
3669 my $ref = format_ref_marker
($refs, $hash_base);
3672 my ($have_blame) = gitweb_check_feature
('blame');
3673 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3675 if (defined $file_name) {
3677 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3678 hash
=>$hash, file_name
=>$file_name)},
3680 $cgi->a({-href
=> href
(action
=>"tree",
3681 hash_base
=>"HEAD", file_name
=>$file_name)},
3684 if ($have_snapshot) {
3685 # FIXME: Should be available when we have no hash base as well.
3687 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3690 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3691 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3694 print "<div class=\"page_nav\">\n";
3695 print "<br/><br/></div>\n";
3696 print "<div class=\"title\">$hash</div>\n";
3698 if (defined $file_name) {
3699 $basedir = $file_name;
3700 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3704 git_print_page_path
($file_name, 'tree', $hash_base);
3705 print "<div class=\"page_body\">\n";
3706 print "<table cellspacing=\"0\">\n";
3708 # '..' (top directory) link if possible
3709 if (defined $hash_base &&
3710 defined $file_name && $file_name =~ m![^/]+$!) {
3712 print "<tr class=\"dark\">\n";
3714 print "<tr class=\"light\">\n";
3718 my $up = $file_name;
3719 $up =~ s!/?[^/]+$!!;
3720 undef $up unless $up;
3721 # based on git_print_tree_entry
3722 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3723 print '<td class="list">';
3724 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3728 print "<td class=\"link\"></td>\n";
3732 foreach my $line (@entries) {
3733 my %t = parse_ls_tree_line
($line, -z
=> 1);
3736 print "<tr class=\"dark\">\n";
3738 print "<tr class=\"light\">\n";
3742 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3746 print "</table>\n" .
3752 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3753 my $have_snapshot = (defined $ctype && defined $suffix);
3754 if (!$have_snapshot) {
3755 die_error
('403 Permission denied', "Permission denied");
3758 if (!defined $hash) {
3759 $hash = git_get_head_hash
($project);
3762 my $filename = decode_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3765 -type
=> "application/$ctype",
3766 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3767 -status
=> '200 OK');
3769 my $git = git_cmd_str
();
3770 my $name = $project;
3771 $name =~ s/\047/\047\\\047\047/g;
3773 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3774 or die_error
(undef, "Execute git-tar-tree failed");
3775 binmode STDOUT
, ':raw';
3777 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3783 my $head = git_get_head_hash
($project);
3784 if (!defined $hash) {
3787 if (!defined $page) {
3790 my $refs = git_get_references
();
3792 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3794 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3797 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3800 my %co = parse_commit
($hash);
3802 git_print_header_div
('summary', $project);
3803 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3805 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3806 for (my $i = 0; $i <= $to; $i++) {
3807 my %co = %{$commitlist[$i]};
3809 my $commit = $co{'id'};
3810 my $ref = format_ref_marker
($refs, $commit);
3811 my %ad = parse_date
($co{'author_epoch'});
3812 git_print_header_div
('commit',
3813 "<span class=\"age\">$co{'age_string'}</span>" .
3814 esc_html
($co{'title'}) . $ref,
3816 print "<div class=\"title_text\">\n" .
3817 "<div class=\"log_link\">\n" .
3818 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3820 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3822 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3825 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3828 print "<div class=\"log_body\">\n";
3829 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3832 if ($#commitlist >= 100) {
3833 print "<div class=\"page_nav\">\n";
3834 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3835 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3842 $hash ||= $hash_base || "HEAD";
3843 my %co = parse_commit
($hash);
3845 die_error
(undef, "Unknown commit object");
3847 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3848 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3850 my $parent = $co{'parent'};
3851 my $parents = $co{'parents'}; # listref
3853 # we need to prepare $formats_nav before any parameter munging
3855 if (!defined $parent) {
3857 $formats_nav .= '(initial)';
3858 } elsif (@$parents == 1) {
3859 # single parent commit
3862 $cgi->a({-href
=> href
(action
=>"commit",
3864 esc_html
(substr($parent, 0, 7))) .
3871 $cgi->a({-href
=> href
(action
=>"commit",
3873 esc_html
(substr($_, 0, 7)));
3878 if (!defined $parent) {
3882 if (@$parents <= 1) {
3883 # difftree output is not printed for merges
3884 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3885 @diff_opts, $parent, $hash, "--"
3886 or die_error
(undef, "Open git-diff-tree failed");
3887 @difftree = map { chomp; $_ } <$fd>;
3888 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3891 # non-textual hash id's can be cached
3893 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3896 my $refs = git_get_references
();
3897 my $ref = format_ref_marker
($refs, $co{'id'});
3899 my $have_snapshot = gitweb_have_snapshot
();
3901 git_header_html
(undef, $expires);
3902 git_print_page_nav
('commit', '',
3903 $hash, $co{'tree'}, $hash,
3906 if (defined $co{'parent'}) {
3907 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3909 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3911 print "<div class=\"title_text\">\n" .
3912 "<table cellspacing=\"0\">\n";
3913 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3915 "<td></td><td> $ad{'rfc2822'}";
3916 if ($ad{'hour_local'} < 6) {
3917 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3918 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3920 printf(" (%02d:%02d %s)",
3921 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3925 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3926 print "<tr><td></td><td> $cd{'rfc2822'}" .
3927 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3929 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3932 "<td class=\"sha1\">" .
3933 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3934 class => "list"}, $co{'tree'}) .
3936 "<td class=\"link\">" .
3937 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3939 if ($have_snapshot) {
3941 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3946 foreach my $par (@$parents) {
3949 "<td class=\"sha1\">" .
3950 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3951 class => "list"}, $par) .
3953 "<td class=\"link\">" .
3954 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3956 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3963 print "<div class=\"page_body\">\n";
3964 git_print_log
($co{'comment'});
3967 if (@$parents <= 1) {
3968 # do not output difftree/whatchanged for merges
3969 git_difftree_body
(\
@difftree, $hash, $parent);
3976 # object is defined by:
3977 # - hash or hash_base alone
3978 # - hash_base and file_name
3981 # - hash or hash_base alone
3982 if ($hash || ($hash_base && !defined $file_name)) {
3983 my $object_id = $hash || $hash_base;
3985 my $git_command = git_cmd_str
();
3986 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3987 or die_error
('404 Not Found', "Object does not exist");
3991 or die_error
('404 Not Found', "Object does not exist");
3993 # - hash_base and file_name
3994 } elsif ($hash_base && defined $file_name) {
3995 $file_name =~ s
,/+$,,;
3997 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3998 or die_error
('404 Not Found', "Base object does not exist");
4000 # here errors should not hapen
4001 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4002 or die_error
(undef, "Open git-ls-tree failed");
4006 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4007 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4008 die_error
('404 Not Found', "File or directory for given base does not exist");
4013 die_error
('404 Not Found', "Not enough information to find object");
4016 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4017 hash
=>$hash, hash_base
=>$hash_base,
4018 file_name
=>$file_name),
4019 -status
=> '302 Found');
4023 my $format = shift || 'html';
4030 # preparing $fd and %diffinfo for git_patchset_body
4032 if (defined $hash_base && defined $hash_parent_base) {
4033 if (defined $file_name) {
4035 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4036 $hash_parent_base, $hash_base,
4037 "--", (defined $file_parent ? $file_parent : ()), $file_name
4038 or die_error
(undef, "Open git-diff-tree failed");
4039 @difftree = map { chomp; $_ } <$fd>;
4041 or die_error
(undef, "Reading git-diff-tree failed");
4043 or die_error
('404 Not Found', "Blob diff not found");
4045 } elsif (defined $hash &&
4046 $hash =~ /[0-9a-fA-F]{40}/) {
4047 # try to find filename from $hash
4049 # read filtered raw output
4050 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4051 $hash_parent_base, $hash_base, "--"
4052 or die_error
(undef, "Open git-diff-tree failed");
4054 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4056 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4057 map { chomp; $_ } <$fd>;
4059 or die_error
(undef, "Reading git-diff-tree failed");
4061 or die_error
('404 Not Found', "Blob diff not found");
4064 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4067 if (@difftree > 1) {
4068 die_error
('404 Not Found', "Ambiguous blob diff specification");
4071 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4072 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4073 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4075 $hash_parent ||= $diffinfo{'from_id'};
4076 $hash ||= $diffinfo{'to_id'};
4078 # non-textual hash id's can be cached
4079 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4080 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4085 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4086 '-p', ($format eq 'html' ? "--full-index" : ()),
4087 $hash_parent_base, $hash_base,
4088 "--", (defined $file_parent ? $file_parent : ()), $file_name
4089 or die_error
(undef, "Open git-diff-tree failed");
4092 # old/legacy style URI
4093 if (!%diffinfo && # if new style URI failed
4094 defined $hash && defined $hash_parent) {
4095 # fake git-diff-tree raw output
4096 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4097 $diffinfo{'from_id'} = $hash_parent;
4098 $diffinfo{'to_id'} = $hash;
4099 if (defined $file_name) {
4100 if (defined $file_parent) {
4101 $diffinfo{'status'} = '2';
4102 $diffinfo{'from_file'} = $file_parent;
4103 $diffinfo{'to_file'} = $file_name;
4104 } else { # assume not renamed
4105 $diffinfo{'status'} = '1';
4106 $diffinfo{'from_file'} = $file_name;
4107 $diffinfo{'to_file'} = $file_name;
4109 } else { # no filename given
4110 $diffinfo{'status'} = '2';
4111 $diffinfo{'from_file'} = $hash_parent;
4112 $diffinfo{'to_file'} = $hash;
4115 # non-textual hash id's can be cached
4116 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4117 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4122 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4123 '-p', ($format eq 'html' ? "--full-index" : ()),
4124 $hash_parent, $hash, "--"
4125 or die_error
(undef, "Open git-diff failed");
4127 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4132 if ($format eq 'html') {
4134 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4135 hash
=>$hash, hash_parent
=>$hash_parent,
4136 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4137 file_name
=>$file_name, file_parent
=>$file_parent)},
4139 git_header_html
(undef, $expires);
4140 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4141 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4142 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4144 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4145 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4147 if (defined $file_name) {
4148 git_print_page_path
($file_name, "blob", $hash_base);
4150 print "<div class=\"page_path\"></div>\n";
4153 } elsif ($format eq 'plain') {
4155 -type
=> 'text/plain',
4156 -charset
=> 'utf-8',
4157 -expires
=> $expires,
4158 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4160 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4163 die_error
(undef, "Unknown blobdiff format");
4167 if ($format eq 'html') {
4168 print "<div class=\"page_body\">\n";
4170 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4173 print "</div>\n"; # class="page_body"
4177 while (my $line = <$fd>) {
4178 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4179 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4183 last if $line =~ m!^\+\+\+!;
4191 sub git_blobdiff_plain
{
4192 git_blobdiff
('plain');
4195 sub git_commitdiff
{
4196 my $format = shift || 'html';
4197 $hash ||= $hash_base || "HEAD";
4198 my %co = parse_commit
($hash);
4200 die_error
(undef, "Unknown commit object");
4203 # we need to prepare $formats_nav before any parameter munging
4205 if ($format eq 'html') {
4207 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4208 hash
=>$hash, hash_parent
=>$hash_parent)},
4211 if (defined $hash_parent) {
4212 # commitdiff with two commits given
4213 my $hash_parent_short = $hash_parent;
4214 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4215 $hash_parent_short = substr($hash_parent, 0, 7);
4219 $cgi->a({-href
=> href
(action
=>"commitdiff",
4220 hash
=>$hash_parent)},
4221 esc_html
($hash_parent_short)) .
4223 } elsif (!$co{'parent'}) {
4225 $formats_nav .= ' (initial)';
4226 } elsif (scalar @{$co{'parents'}} == 1) {
4227 # single parent commit
4230 $cgi->a({-href
=> href
(action
=>"commitdiff",
4231 hash
=>$co{'parent'})},
4232 esc_html
(substr($co{'parent'}, 0, 7))) .
4239 $cgi->a({-href
=> href
(action
=>"commitdiff",
4241 esc_html
(substr($_, 0, 7)));
4242 } @{$co{'parents'}} ) .
4247 if (!defined $hash_parent) {
4248 $hash_parent = $co{'parent'} || '--root';
4254 if ($format eq 'html') {
4255 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4256 "--no-commit-id", "--patch-with-raw", "--full-index",
4257 $hash_parent, $hash, "--"
4258 or die_error
(undef, "Open git-diff-tree failed");
4260 while (my $line = <$fd>) {
4262 # empty line ends raw part of diff-tree output
4264 push @difftree, $line;
4267 } elsif ($format eq 'plain') {
4268 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4269 '-p', $hash_parent, $hash, "--"
4270 or die_error
(undef, "Open git-diff-tree failed");
4273 die_error
(undef, "Unknown commitdiff format");
4276 # non-textual hash id's can be cached
4278 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4282 # write commit message
4283 if ($format eq 'html') {
4284 my $refs = git_get_references
();
4285 my $ref = format_ref_marker
($refs, $co{'id'});
4287 git_header_html
(undef, $expires);
4288 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4289 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4290 git_print_authorship
(\
%co);
4291 print "<div class=\"page_body\">\n";
4292 if (@{$co{'comment'}} > 1) {
4293 print "<div class=\"log\">\n";
4294 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4295 print "</div>\n"; # class="log"
4298 } elsif ($format eq 'plain') {
4299 my $refs = git_get_references
("tags");
4300 my $tagname = git_get_rev_name_tags
($hash);
4301 my $filename = basename
($project) . "-$hash.patch";
4304 -type
=> 'text/plain',
4305 -charset
=> 'utf-8',
4306 -expires
=> $expires,
4307 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4308 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4311 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4312 Subject: $co{'title'}
4314 print "X-Git-Tag: $tagname\n" if $tagname;
4315 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4317 foreach my $line (@{$co{'comment'}}) {
4324 if ($format eq 'html') {
4325 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4328 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4330 print "</div>\n"; # class="page_body"
4333 } elsif ($format eq 'plain') {
4337 or print "Reading git-diff-tree failed\n";
4341 sub git_commitdiff_plain
{
4342 git_commitdiff
('plain');
4346 if (!defined $hash_base) {
4347 $hash_base = git_get_head_hash
($project);
4349 if (!defined $page) {
4353 my %co = parse_commit
($hash_base);
4355 die_error
(undef, "Unknown commit object");
4358 my $refs = git_get_references
();
4359 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4361 if (!defined $hash && defined $file_name) {
4362 $hash = git_get_hash_by_path
($hash_base, $file_name);
4364 if (defined $hash) {
4365 $ftype = git_get_type
($hash);
4368 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4370 my $paging_nav = '';
4373 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4374 file_name
=>$file_name)},
4376 $paging_nav .= " ⋅ " .
4377 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4378 file_name
=>$file_name, page
=>$page-1),
4379 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4381 $paging_nav .= "first";
4382 $paging_nav .= " ⋅ prev";
4384 if ($#commitlist >= 100) {
4385 $paging_nav .= " ⋅ " .
4386 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4387 file_name
=>$file_name, page
=>$page+1),
4388 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4390 $paging_nav .= " ⋅ next";
4393 if ($#commitlist >= 100) {
4395 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4396 file_name
=>$file_name, page
=>$page+1),
4397 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4401 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4402 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4403 git_print_page_path
($file_name, $ftype, $hash_base);
4405 git_history_body
(\
@commitlist, 0, 99,
4406 $refs, $hash_base, $ftype, $next_link);
4412 my ($have_search) = gitweb_check_feature
('search');
4413 if (!$have_search) {
4414 die_error
('403 Permission denied', "Permission denied");
4416 if (!defined $searchtext) {
4417 die_error
(undef, "Text field empty");
4419 if (!defined $hash) {
4420 $hash = git_get_head_hash
($project);
4422 my %co = parse_commit
($hash);
4424 die_error
(undef, "Unknown commit object");
4426 if (!defined $page) {
4430 $searchtype ||= 'commit';
4431 if ($searchtype eq 'pickaxe') {
4432 # pickaxe may take all resources of your box and run for several minutes
4433 # with every query - so decide by yourself how public you make this feature
4434 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4435 if (!$have_pickaxe) {
4436 die_error
('403 Permission denied', "Permission denied");
4442 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4444 if ($searchtype eq 'commit') {
4445 $greptype = "--grep=";
4446 } elsif ($searchtype eq 'author') {
4447 $greptype = "--author=";
4448 } elsif ($searchtype eq 'committer') {
4449 $greptype = "--committer=";
4451 $greptype .= $searchtext;
4452 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4454 my $paging_nav = '';
4457 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4458 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4460 $paging_nav .= " ⋅ " .
4461 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4462 searchtext
=>$searchtext, searchtype
=>$searchtype,
4464 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4466 $paging_nav .= "first";
4467 $paging_nav .= " ⋅ prev";
4469 if ($#commitlist >= 100) {
4470 $paging_nav .= " ⋅ " .
4471 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4472 searchtext
=>$searchtext, searchtype
=>$searchtype,
4474 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4476 $paging_nav .= " ⋅ next";
4479 if ($#commitlist >= 100) {
4481 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4482 searchtext
=>$searchtext, searchtype
=>$searchtype,
4484 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4487 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4488 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4489 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4492 if ($searchtype eq 'pickaxe') {
4493 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4494 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4496 print "<table cellspacing=\"0\">\n";
4499 my $git_command = git_cmd_str
();
4500 open my $fd, "-|", "$git_command rev-list $hash | " .
4501 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4504 while (my $line = <$fd>) {
4505 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4508 $set{'from_id'} = $3;
4510 $set{'id'} = $set{'to_id'};
4511 if ($set{'id'} =~ m/0{40}/) {
4512 $set{'id'} = $set{'from_id'};
4514 if ($set{'id'} =~ m/0{40}/) {
4518 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4521 print "<tr class=\"dark\">\n";
4523 print "<tr class=\"light\">\n";
4526 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4527 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4529 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4530 -class => "list subject"},
4531 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4532 while (my $setref = shift @files) {
4534 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4535 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4537 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4541 "<td class=\"link\">" .
4542 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4544 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4548 %co = parse_commit
($1);
4558 sub git_search_help
{
4560 git_print_page_nav
('','', $hash,$hash,$hash);
4563 <dt><b>commit</b></dt>
4564 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4565 <dt><b>author</b></dt>
4566 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4567 <dt><b>committer</b></dt>
4568 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4570 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4571 if ($have_pickaxe) {
4573 <dt><b>pickaxe</b></dt>
4574 <dd>All commits that caused the string to appear or disappear from any file (changes that
4575 added, removed or "modified" the string) will be listed. This search can take a while and
4576 takes a lot of strain on the server, so please use it wisely.</dd>
4584 my $head = git_get_head_hash
($project);
4585 if (!defined $hash) {
4588 if (!defined $page) {
4591 my $refs = git_get_references
();
4593 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4595 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4597 if ($#commitlist >= 100) {
4599 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4600 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4604 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4605 git_print_header_div
('summary', $project);
4607 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4612 ## ......................................................................
4613 ## feeds (RSS, Atom; OPML)
4616 my $format = shift || 'atom';
4617 my ($have_blame) = gitweb_check_feature
('blame');
4619 # Atom: http://www.atomenabled.org/developers/syndication/
4620 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4621 if ($format ne 'rss' && $format ne 'atom') {
4622 die_error
(undef, "Unknown web feed format");
4625 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4626 my $head = $hash || 'HEAD';
4627 my @commitlist = parse_commits
($head, 150);
4631 my $content_type = "application/$format+xml";
4632 if (defined $cgi->http('HTTP_ACCEPT') &&
4633 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4634 # browser (feed reader) prefers text/xml
4635 $content_type = 'text/xml';
4637 if (defined($commitlist[0])) {
4638 %latest_commit = %{$commitlist[0]};
4639 %latest_date = parse_date
($latest_commit{'author_epoch'});
4641 -type
=> $content_type,
4642 -charset
=> 'utf-8',
4643 -last_modified
=> $latest_date{'rfc2822'});
4646 -type
=> $content_type,
4647 -charset
=> 'utf-8');
4650 # Optimization: skip generating the body if client asks only
4651 # for Last-Modified date.
4652 return if ($cgi->request_method() eq 'HEAD');
4655 my $title = "$site_name - $project/$action";
4656 my $feed_type = 'log';
4657 if (defined $hash) {
4658 $title .= " - '$hash'";
4659 $feed_type = 'branch log';
4660 if (defined $file_name) {
4661 $title .= " :: $file_name";
4662 $feed_type = 'history';
4664 } elsif (defined $file_name) {
4665 $title .= " - $file_name";
4666 $feed_type = 'history';
4668 $title .= " $feed_type";
4669 my $descr = git_get_project_description
($project);
4670 if (defined $descr) {
4671 $descr = esc_html
($descr);
4673 $descr = "$project " .
4674 ($format eq 'rss' ? 'RSS' : 'Atom') .
4677 my $owner = git_get_project_owner
($project);
4678 $owner = esc_html
($owner);
4682 if (defined $file_name) {
4683 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4684 } elsif (defined $hash) {
4685 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4687 $alt_url = href
(-full
=>1, action
=>"summary");
4689 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4690 if ($format eq 'rss') {
4692 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4695 print "<title>$title</title>\n" .
4696 "<link>$alt_url</link>\n" .
4697 "<description>$descr</description>\n" .
4698 "<language>en</language>\n";
4699 } elsif ($format eq 'atom') {
4701 <feed xmlns="http://www.w3.org/2005/Atom">
4703 print "<title>$title</title>\n" .
4704 "<subtitle>$descr</subtitle>\n" .
4705 '<link rel="alternate" type="text/html" href="' .
4706 $alt_url . '" />' . "\n" .
4707 '<link rel="self" type="' . $content_type . '" href="' .
4708 $cgi->self_url() . '" />' . "\n" .
4709 "<id>" . href
(-full
=>1) . "</id>\n" .
4710 # use project owner for feed author
4711 "<author><name>$owner</name></author>\n";
4712 if (defined $favicon) {
4713 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4715 if (defined $logo_url) {
4716 # not twice as wide as tall: 72 x 27 pixels
4717 print "<logo>" . esc_url
($logo) . "</logo>\n";
4719 if (! %latest_date) {
4720 # dummy date to keep the feed valid until commits trickle in:
4721 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4723 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4728 for (my $i = 0; $i <= $#commitlist; $i++) {
4729 my %co = %{$commitlist[$i]};
4730 my $commit = $co{'id'};
4731 # we read 150, we always show 30 and the ones more recent than 48 hours
4732 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4735 my %cd = parse_date
($co{'author_epoch'});
4737 # get list of changed files
4738 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4739 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4741 my @difftree = map { chomp; $_ } <$fd>;
4745 # print element (entry, item)
4746 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4747 if ($format eq 'rss') {
4749 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4750 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4751 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4752 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4753 "<link>$co_url</link>\n" .
4754 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4755 "<content:encoded>" .
4757 } elsif ($format eq 'atom') {
4759 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4760 "<updated>$cd{'iso-8601'}</updated>\n" .
4762 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4763 if ($co{'author_email'}) {
4764 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4766 print "</author>\n" .
4767 # use committer for contributor
4769 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4770 if ($co{'committer_email'}) {
4771 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4773 print "</contributor>\n" .
4774 "<published>$cd{'iso-8601'}</published>\n" .
4775 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4776 "<id>$co_url</id>\n" .
4777 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4778 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4780 my $comment = $co{'comment'};
4782 foreach my $line (@$comment) {
4783 $line = esc_html
($line);
4786 print "</pre><ul>\n";
4787 foreach my $difftree_line (@difftree) {
4788 my %difftree = parse_difftree_raw_line
($difftree_line);
4789 next if !$difftree{'from_id'};
4791 my $file = $difftree{'file'} || $difftree{'to_file'};
4795 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4796 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4797 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4798 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4799 -title
=> "diff"}, 'D');
4801 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4802 file_name
=>$file, hash_base
=>$commit),
4803 -title
=> "blame"}, 'B');
4805 # if this is not a feed of a file history
4806 if (!defined $file_name || $file_name ne $file) {
4807 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4808 file_name
=>$file, hash
=>$commit),
4809 -title
=> "history"}, 'H');
4811 $file = esc_path
($file);
4815 if ($format eq 'rss') {
4816 print "</ul>]]>\n" .
4817 "</content:encoded>\n" .
4819 } elsif ($format eq 'atom') {
4820 print "</ul>\n</div>\n" .
4827 if ($format eq 'rss') {
4828 print "</channel>\n</rss>\n";
4829 } elsif ($format eq 'atom') {
4843 my @list = git_get_projects_list
();
4845 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4847 <?xml version="1.0" encoding="utf-8"?>
4848 <opml version="1.0">
4850 <title>$site_name OPML Export</title>
4853 <outline text="git RSS feeds">
4856 foreach my $pr (@list) {
4858 my $head = git_get_head_hash
($proj{'path'});
4859 if (!defined $head) {
4862 $git_dir = "$projectroot/$proj{'path'}";
4863 my %co = parse_commit
($head);
4868 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4869 my $rss = "$my_url?p=$proj{'path'};a=rss";
4870 my $html = "$my_url?p=$proj{'path'};a=summary";
4871 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";