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 = "1.5.4.2";
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 = "/usr/bin/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "/pub/git";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = 2007;
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 # hcoop-change: Customize.
47 our $home_link_str = "HCoop";
49 # name of your site or organization to appear in page titles
50 # replace this with something more descriptive for clearer bookmarks
51 # hcoop-change: Customize.
52 our $site_name = "HCoop Git"
53 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
55 # filename of html text to include at top of each page
56 our $site_header = "";
57 # html text to include at home page
58 our $home_text = "indextext.html";
59 # filename of html text to include at bottom of each page
60 our $site_footer = "";
63 our @stylesheets = ("gitweb.css");
64 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
65 our $stylesheet = undef;
66 # URI of GIT logo (72x27 size)
67 our $logo = "git-logo.png";
68 # URI of GIT favicon, assumed to be image/png type
69 our $favicon = "git-favicon.png";
71 # URI and label (title) of GIT logo link
72 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
73 #our $logo_label = "git documentation";
74 our $logo_url = "http://git.or.cz/";
75 our $logo_label = "git homepage";
77 # source of projects list
78 our $projects_list = "";
80 # the width (in characters) of the projects list "Description" column
81 our $projects_list_description_width = 25;
83 # default order of projects list
84 # valid values are none, project, descr, owner, and age
85 our $default_projects_order = "project";
87 # show repository only if this file exists
88 # (only effective if this variable evaluates to true)
91 # only allow viewing of repositories also shown on the overview page
92 our $strict_export = "";
94 # list of git base URLs used for URL to where fetch project from,
95 # i.e. full URL is "$git_base_url/$project"
96 # hcoop-change: We like several URLs.
97 #our @git_base_url_list = grep { $_ ne '' } ("");
98 our @git_base_url_list = ('git://git.hcoop.net/git',
99 'http://git.hcoop.net/git');
101 # default blob_plain mimetype and default charset for text/plain blob
102 our $default_blob_plain_mimetype = 'text/plain';
103 our $default_text_plain_charset = undef;
105 # file to use for guessing MIME types before trying /etc/mime.types
106 # (relative to the current git repository)
107 our $mimetypes_file = undef;
109 # assume this charset if line contains non-UTF-8 characters;
110 # it should be valid encoding (see Encoding::Supported(3pm) for list),
111 # for which encoding all byte sequences are valid, for example
112 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
113 # could be even 'utf-8' for the old behavior)
114 our $fallback_encoding = 'latin1';
116 # rename detection options for git-diff and git-diff-tree
117 # - default is '-M', with the cost proportional to
118 # (number of removed files) * (number of new files).
119 # - more costly is '-C' (which implies '-M'), with the cost proportional to
120 # (number of changed files + number of removed files) * (number of new files)
121 # - even more costly is '-C', '--find-copies-harder' with cost
122 # (number of files in the original tree) * (number of new files)
123 # - one might want to include '-B' option, e.g. '-B', '-M'
124 our @diff_opts = ('-M'); # taken from git_commit
126 # information about snapshot formats that gitweb is capable of serving
127 our %known_snapshot_formats = (
129 # 'display' => display name,
130 # 'type' => mime type,
131 # 'suffix' => filename suffix,
132 # 'format' => --format for git-archive,
133 # 'compressor' => [compressor command and arguments]
134 # (array reference, optional)}
137 'display' => 'tar.gz',
138 'type' => 'application/x-gzip',
139 'suffix' => '.tar.gz',
141 'compressor' => ['gzip']},
144 'display' => 'tar.bz2',
145 'type' => 'application/x-bzip2',
146 'suffix' => '.tar.bz2',
148 'compressor' => ['bzip2']},
152 'type' => 'application/x-zip',
157 # Aliases so we understand old gitweb.snapshot values in repository
159 our %known_snapshot_format_aliases = (
163 # backward compatibility: legacy gitweb config support
164 'x-gzip' => undef, 'gz' => undef,
165 'x-bzip2' => undef, 'bz2' => undef,
166 'x-zip' => undef, '' => undef,
169 # You define site-wide feature defaults here; override them with
170 # $GITWEB_CONFIG as necessary.
173 # 'sub' => feature-sub (subroutine),
174 # 'override' => allow-override (boolean),
175 # 'default' => [ default options...] (array reference)}
177 # if feature is overridable (it means that allow-override has true value),
178 # then feature-sub will be called with default options as parameters;
179 # return value of feature-sub indicates if to enable specified feature
181 # if there is no 'sub' key (no feature-sub), then feature cannot be
184 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
186 # Enable the 'blame' blob view, showing the last commit that modified
187 # each line in the file. This can be very CPU-intensive.
189 # To enable system wide have in $GITWEB_CONFIG
190 # $feature{'blame'}{'default'} = [1];
191 # To have project specific config enable override in $GITWEB_CONFIG
192 # $feature{'blame'}{'override'} = 1;
193 # and in project config gitweb.blame = 0|1;
195 'sub' => \
&feature_blame
,
199 # Enable the 'snapshot' link, providing a compressed archive of any
200 # tree. This can potentially generate high traffic if you have large
203 # Value is a list of formats defined in %known_snapshot_formats that
205 # To disable system wide have in $GITWEB_CONFIG
206 # $feature{'snapshot'}{'default'} = [];
207 # To have project specific config enable override in $GITWEB_CONFIG
208 # $feature{'snapshot'}{'override'} = 1;
209 # and in project config, a comma-separated list of formats or "none"
210 # to disable. Example: gitweb.snapshot = tbz2,zip;
212 'sub' => \
&feature_snapshot
,
214 'default' => ['tgz']},
216 # Enable text search, which will list the commits which match author,
217 # committer or commit text to a given string. Enabled by default.
218 # Project specific override is not supported.
223 # Enable grep search, which will list the files in currently selected
224 # tree containing the given string. Enabled by default. This can be
225 # potentially CPU-intensive, of course.
227 # To enable system wide have in $GITWEB_CONFIG
228 # $feature{'grep'}{'default'} = [1];
229 # To have project specific config enable override in $GITWEB_CONFIG
230 # $feature{'grep'}{'override'} = 1;
231 # and in project config gitweb.grep = 0|1;
236 # Enable the pickaxe search, which will list the commits that modified
237 # a given string in a file. This can be practical and quite faster
238 # alternative to 'blame', but still potentially CPU-intensive.
240 # To enable system wide have in $GITWEB_CONFIG
241 # $feature{'pickaxe'}{'default'} = [1];
242 # To have project specific config enable override in $GITWEB_CONFIG
243 # $feature{'pickaxe'}{'override'} = 1;
244 # and in project config gitweb.pickaxe = 0|1;
246 'sub' => \
&feature_pickaxe
,
250 # Make gitweb use an alternative format of the URLs which can be
251 # more readable and natural-looking: project name is embedded
252 # directly in the path and the query string contains other
253 # auxiliary information. All gitweb installations recognize
254 # URL in either format; this configures in which formats gitweb
257 # To enable system wide have in $GITWEB_CONFIG
258 # $feature{'pathinfo'}{'default'} = [1];
259 # Project specific override is not supported.
261 # Note that you will need to change the default location of CSS,
262 # favicon, logo and possibly other files to an absolute URL. Also,
263 # if gitweb.cgi serves as your indexfile, you will need to force
264 # $my_uri to contain the script name in your $GITWEB_CONFIG.
269 # Make gitweb consider projects in project root subdirectories
270 # to be forks of existing projects. Given project $projname.git,
271 # projects matching $projname/*.git will not be shown in the main
272 # projects list, instead a '+' mark will be added to $projname
273 # there and a 'forks' view will be enabled for the project, listing
274 # all the forks. If project list is taken from a file, forks have
275 # to be listed after the main project.
277 # To enable system wide have in $GITWEB_CONFIG
278 # $feature{'forks'}{'default'} = [1];
279 # Project specific override is not supported.
285 sub gitweb_check_feature
{
287 return unless exists $feature{$name};
288 my ($sub, $override, @defaults) = (
289 $feature{$name}{'sub'},
290 $feature{$name}{'override'},
291 @
{$feature{$name}{'default'}});
292 if (!$override) { return @defaults; }
294 warn "feature $name is not overrideable";
297 return $sub->(@defaults);
301 my ($val) = git_get_project_config
('blame', '--bool');
303 if ($val eq 'true') {
305 } elsif ($val eq 'false') {
312 sub feature_snapshot
{
315 my ($val) = git_get_project_config
('snapshot');
318 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
325 my ($val) = git_get_project_config
('grep', '--bool');
327 if ($val eq 'true') {
329 } elsif ($val eq 'false') {
336 sub feature_pickaxe
{
337 my ($val) = git_get_project_config
('pickaxe', '--bool');
339 if ($val eq 'true') {
341 } elsif ($val eq 'false') {
348 # checking HEAD file with -e is fragile if the repository was
349 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
351 sub check_head_link
{
353 my $headfile = "$dir/HEAD";
354 return ((-e
$headfile) ||
355 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
358 sub check_export_ok
{
360 return (check_head_link
($dir) &&
361 (!$export_ok || -e
"$dir/$export_ok"));
364 # process alternate names for backward compatibility
365 # filter out unsupported (unknown) snapshot formats
366 sub filter_snapshot_fmts
{
370 exists $known_snapshot_format_aliases{$_} ?
371 $known_snapshot_format_aliases{$_} : $_} @fmts;
372 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
376 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "/etc/gitweb.conf";
377 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
379 # version of the core git binary
380 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
382 $projects_list ||= $projectroot;
384 # ======================================================================
385 # input validation and dispatch
386 our $action = $cgi->param('a');
387 if (defined $action) {
388 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
389 die_error
(undef, "Invalid action parameter");
393 # parameters which are pathnames
394 our $project = $cgi->param('p');
395 if (defined $project) {
396 if (!validate_pathname
($project) ||
397 !(-d
"$projectroot/$project") ||
398 !check_head_link
("$projectroot/$project") ||
399 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
400 ($strict_export && !project_in_list
($project))) {
402 die_error
(undef, "No such project");
406 our $file_name = $cgi->param('f');
407 if (defined $file_name) {
408 if (!validate_pathname
($file_name)) {
409 die_error
(undef, "Invalid file parameter");
413 our $file_parent = $cgi->param('fp');
414 if (defined $file_parent) {
415 if (!validate_pathname
($file_parent)) {
416 die_error
(undef, "Invalid file parent parameter");
420 # parameters which are refnames
421 our $hash = $cgi->param('h');
423 if (!validate_refname
($hash)) {
424 die_error
(undef, "Invalid hash parameter");
428 our $hash_parent = $cgi->param('hp');
429 if (defined $hash_parent) {
430 if (!validate_refname
($hash_parent)) {
431 die_error
(undef, "Invalid hash parent parameter");
435 our $hash_base = $cgi->param('hb');
436 if (defined $hash_base) {
437 if (!validate_refname
($hash_base)) {
438 die_error
(undef, "Invalid hash base parameter");
442 my %allowed_options = (
443 "--no-merges" => [ qw(rss atom log shortlog history) ],
446 our @extra_options = $cgi->param('opt');
447 if (defined @extra_options) {
448 foreach my $opt (@extra_options) {
449 if (not exists $allowed_options{$opt}) {
450 die_error
(undef, "Invalid option parameter");
452 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
453 die_error
(undef, "Invalid option parameter for this action");
458 our $hash_parent_base = $cgi->param('hpb');
459 if (defined $hash_parent_base) {
460 if (!validate_refname
($hash_parent_base)) {
461 die_error
(undef, "Invalid hash parent base parameter");
466 our $page = $cgi->param('pg');
468 if ($page =~ m/[^0-9]/) {
469 die_error
(undef, "Invalid page parameter");
473 our $searchtype = $cgi->param('st');
474 if (defined $searchtype) {
475 if ($searchtype =~ m/[^a-z]/) {
476 die_error
(undef, "Invalid searchtype parameter");
480 our $searchtext = $cgi->param('s');
482 if (defined $searchtext) {
483 if (length($searchtext) < 2) {
484 die_error
(undef, "At least two characters are required for search parameter");
486 $search_regexp = quotemeta $searchtext;
489 # now read PATH_INFO and use it as alternative to parameters
490 sub evaluate_path_info
{
491 return if defined $project;
492 my $path_info = $ENV{"PATH_INFO"};
493 return if !$path_info;
494 $path_info =~ s
,^/+,,;
495 return if !$path_info;
496 # find which part of PATH_INFO is project
497 $project = $path_info;
499 while ($project && !check_head_link
("$projectroot/$project")) {
500 $project =~ s
,/*[^/]*$,,;
503 $project = validate_pathname
($project);
505 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
506 ($strict_export && !project_in_list
($project))) {
510 # do not change any parameters if an action is given using the query string
512 $path_info =~ s
,^$project/*,,;
513 my ($refname, $pathname) = split(/:/, $path_info, 2);
514 if (defined $pathname) {
515 # we got "project.git/branch:filename" or "project.git/branch:dir/"
516 # we could use git_get_type(branch:pathname), but it needs $git_dir
517 $pathname =~ s
,^/+,,;
518 if (!$pathname || substr($pathname, -1) eq "/") {
522 $action ||= "blob_plain";
524 $hash_base ||= validate_refname
($refname);
525 $file_name ||= validate_pathname
($pathname);
526 } elsif (defined $refname) {
527 # we got "project.git/branch"
528 $action ||= "shortlog";
529 $hash ||= validate_refname
($refname);
532 evaluate_path_info
();
534 # path to the current git repository
536 $git_dir = "$projectroot/$project" if $project;
540 "blame" => \
&git_blame2
,
541 "blobdiff" => \
&git_blobdiff
,
542 "blobdiff_plain" => \
&git_blobdiff_plain
,
543 "blob" => \
&git_blob
,
544 "blob_plain" => \
&git_blob_plain
,
545 "commitdiff" => \
&git_commitdiff
,
546 "commitdiff_plain" => \
&git_commitdiff_plain
,
547 "commit" => \
&git_commit
,
548 "forks" => \
&git_forks
,
549 "heads" => \
&git_heads
,
550 "history" => \
&git_history
,
553 "atom" => \
&git_atom
,
554 "search" => \
&git_search
,
555 "search_help" => \
&git_search_help
,
556 "shortlog" => \
&git_shortlog
,
557 "summary" => \
&git_summary
,
559 "tags" => \
&git_tags
,
560 "tree" => \
&git_tree
,
561 "snapshot" => \
&git_snapshot
,
562 "object" => \
&git_object
,
563 # those below don't need $project
564 "opml" => \
&git_opml
,
565 "project_list" => \
&git_project_list
,
566 "project_index" => \
&git_project_index
,
569 if (!defined $action) {
571 $action = git_get_type
($hash);
572 } elsif (defined $hash_base && defined $file_name) {
573 $action = git_get_type
("$hash_base:$file_name");
574 } elsif (defined $project) {
577 $action = 'project_list';
580 if (!defined($actions{$action})) {
581 die_error
(undef, "Unknown action");
583 if ($action !~ m/^(opml|project_list|project_index)$/ &&
585 die_error
(undef, "Project needed");
587 $actions{$action}->();
590 ## ======================================================================
595 # default is to use -absolute url() i.e. $my_uri
596 my $href = $params{-full
} ?
$my_url : $my_uri;
598 # XXX: Warning: If you touch this, check the search form for updating,
609 hash_parent_base
=> "hpb",
614 snapshot_format
=> "sf",
615 extra_options
=> "opt",
617 my %mapping = @mapping;
619 if ($params{-replay
}) {
620 while (my ($name, $symbol) = each %mapping) {
621 if (!exists $params{$name}) {
622 # to allow for multivalued params we use arrayref form
623 $params{$name} = [ $cgi->param($symbol) ];
628 $params{'project'} = $project unless exists $params{'project'};
630 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
632 # use PATH_INFO for project name
633 $href .= "/$params{'project'}" if defined $params{'project'};
634 delete $params{'project'};
636 # Summary just uses the project path URL
637 if (defined $params{'action'} && $params{'action'} eq 'summary') {
638 delete $params{'action'};
642 # now encode the parameters explicitly
644 for (my $i = 0; $i < @mapping; $i += 2) {
645 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
646 if (defined $params{$name}) {
647 if (ref($params{$name}) eq "ARRAY") {
648 foreach my $par (@
{$params{$name}}) {
649 push @result, $symbol . "=" . esc_param
($par);
652 push @result, $symbol . "=" . esc_param
($params{$name});
656 $href .= "?" . join(';', @result) if scalar @result;
662 ## ======================================================================
663 ## validation, quoting/unquoting and escaping
665 sub validate_pathname
{
666 my $input = shift || return undef;
668 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
669 # at the beginning, at the end, and between slashes.
670 # also this catches doubled slashes
671 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
675 if ($input =~ m!\0!) {
681 sub validate_refname
{
682 my $input = shift || return undef;
684 # textual hashes are O.K.
685 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
688 # it must be correct pathname
689 $input = validate_pathname
($input)
691 # restrictions on ref name according to git-check-ref-format
692 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
698 # decode sequences of octets in utf8 into Perl's internal form,
699 # which is utf-8 with utf8 flag set if needed. gitweb writes out
700 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
703 if (utf8
::valid
($str)) {
707 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
711 # quote unsafe chars, but keep the slash, even when it's not
712 # correct, but quoted slashes look too horrible in bookmarks
715 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
721 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
724 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
730 # replace invalid utf8 character with SUBSTITUTION sequence
735 $str = to_utf8
($str);
736 $str = $cgi->escapeHTML($str);
737 if ($opts{'-nbsp'}) {
738 $str =~ s/ / /g;
740 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
744 # quote control characters and escape filename to HTML
749 $str = to_utf8
($str);
750 $str = $cgi->escapeHTML($str);
751 if ($opts{'-nbsp'}) {
752 $str =~ s/ / /g;
754 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
758 # Make control characters "printable", using character escape codes (CEC)
761 my %es = ( # character escape codes, aka escape sequences
762 "\t" => '\t', # tab (HT)
763 "\n" => '\n', # line feed (LF)
764 "\r" => '\r', # carrige return (CR)
765 "\f" => '\f', # form feed (FF)
766 "\b" => '\b', # backspace (BS)
767 "\a" => '\a', # alarm (bell) (BEL)
768 "\e" => '\e', # escape (ESC)
769 "\013" => '\v', # vertical tab (VT)
770 "\000" => '\0', # nul character (NUL)
772 my $chr = ( (exists $es{$cntrl})
774 : sprintf('\%03o', ord($cntrl)) );
775 return "<span class=\"cntrl\">$chr</span>";
778 # Alternatively use unicode control pictures codepoints,
779 # Unicode "printable representation" (PR)
782 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
783 return "<span class=\"cntrl\">$chr</span>";
786 # git may return quoted and escaped filenames
792 my %es = ( # character escape codes, aka escape sequences
793 't' => "\t", # tab (HT, TAB)
794 'n' => "\n", # newline (NL)
795 'r' => "\r", # return (CR)
796 'f' => "\f", # form feed (FF)
797 'b' => "\b", # backspace (BS)
798 'a' => "\a", # alarm (bell) (BEL)
799 'e' => "\e", # escape (ESC)
800 'v' => "\013", # vertical tab (VT)
803 if ($seq =~ m/^[0-7]{1,3}$/) {
804 # octal char sequence
805 return chr(oct($seq));
806 } elsif (exists $es{$seq}) {
807 # C escape sequence, aka character escape code
810 # quoted ordinary character
814 if ($str =~ m/^"(.*)"$/) {
817 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
822 # escape tabs (convert tabs to spaces)
826 while ((my $pos = index($line, "\t")) != -1) {
827 if (my $count = (8 - ($pos % 8))) {
828 my $spaces = ' ' x
$count;
829 $line =~ s/\t/$spaces/;
836 sub project_in_list
{
838 my @list = git_get_projects_list
();
839 return @list && scalar(grep { $_->{'path'} eq $project } @list);
842 ## ----------------------------------------------------------------------
843 ## HTML aware string manipulation
848 my $add_len = shift || 10;
850 # allow only $len chars, but don't cut a word if it would fit in $add_len
851 # if it doesn't fit, cut it if it's still longer than the dots we would add
852 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
855 if (length($tail) > 4) {
857 $body =~ s/&[^;]*$//; # remove chopped character entities
862 # takes the same arguments as chop_str, but also wraps a <span> around the
863 # result with a title attribute if it does get chopped. Additionally, the
864 # string is HTML-escaped.
865 sub chop_and_escape_str
{
868 my $add_len = shift || 10;
870 my $chopped = chop_str
($str, $len, $add_len);
871 if ($chopped eq $str) {
872 return esc_html
($chopped);
874 return qq{<span title
="} . esc_html($str) . qq{">} .
875 esc_html
($chopped) . qq{</span
>};
879 ## ----------------------------------------------------------------------
880 ## functions returning short strings
882 # CSS class for given age value (in seconds)
888 } elsif ($age < 60*60*2) {
890 } elsif ($age < 60*60*24*2) {
897 # convert age in seconds to "nn units ago" string
902 if ($age > 60*60*24*365*2) {
903 $age_str = (int $age/60/60/24/365);
904 $age_str .= " years ago";
905 } elsif ($age > 60*60*24*(365/12)*2) {
906 $age_str = int $age/60/60/24/(365/12);
907 $age_str .= " months ago";
908 } elsif ($age > 60*60*24*7*2) {
909 $age_str = int $age/60/60/24/7;
910 $age_str .= " weeks ago";
911 } elsif ($age > 60*60*24*2) {
912 $age_str = int $age/60/60/24;
913 $age_str .= " days ago";
914 } elsif ($age > 60*60*2) {
915 $age_str = int $age/60/60;
916 $age_str .= " hours ago";
917 } elsif ($age > 60*2) {
918 $age_str = int $age/60;
919 $age_str .= " min ago";
922 $age_str .= " sec ago";
924 $age_str .= " right now";
930 S_IFINVALID
=> 0030000,
931 S_IFGITLINK
=> 0160000,
934 # submodule/subproject, a commit object reference
938 return (($mode & S_IFMT
) == S_IFGITLINK
)
941 # convert file mode in octal to symbolic file mode string
943 my $mode = oct shift;
945 if (S_ISGITLINK
($mode)) {
947 } elsif (S_ISDIR
($mode & S_IFMT
)) {
949 } elsif (S_ISLNK
($mode)) {
951 } elsif (S_ISREG
($mode)) {
952 # git cares only about the executable bit
953 if ($mode & S_IXUSR
) {
963 # convert file mode in octal to file type string
967 if ($mode !~ m/^[0-7]+$/) {
973 if (S_ISGITLINK
($mode)) {
975 } elsif (S_ISDIR
($mode & S_IFMT
)) {
977 } elsif (S_ISLNK
($mode)) {
979 } elsif (S_ISREG
($mode)) {
986 # convert file mode in octal to file type description string
990 if ($mode !~ m/^[0-7]+$/) {
996 if (S_ISGITLINK
($mode)) {
998 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1000 } elsif (S_ISLNK
($mode)) {
1002 } elsif (S_ISREG
($mode)) {
1003 if ($mode & S_IXUSR
) {
1004 return "executable";
1014 ## ----------------------------------------------------------------------
1015 ## functions returning short HTML fragments, or transforming HTML fragments
1016 ## which don't belong to other sections
1018 # format line of commit message.
1019 sub format_log_line_html
{
1022 $line = esc_html
($line, -nbsp
=>1);
1023 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1026 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1027 -class => "text"}, $hash_text);
1028 $line =~ s/$hash_text/$link/;
1033 # format marker of refs pointing to given object
1034 sub format_ref_marker
{
1035 my ($refs, $id) = @_;
1038 if (defined $refs->{$id}) {
1039 foreach my $ref (@
{$refs->{$id}}) {
1040 my ($type, $name) = qw();
1041 # e.g. tags/v2.6.11 or heads/next
1042 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1050 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1051 esc_html
($name) . "</span>";
1056 return ' <span class="refs">'. $markers . '</span>';
1062 # format, perhaps shortened and with markers, title line
1063 sub format_subject_html
{
1064 my ($long, $short, $href, $extra) = @_;
1065 $extra = '' unless defined($extra);
1067 if (length($short) < length($long)) {
1068 return $cgi->a({-href
=> $href, -class => "list subject",
1069 -title
=> to_utf8
($long)},
1070 esc_html
($short) . $extra);
1072 return $cgi->a({-href
=> $href, -class => "list subject"},
1073 esc_html
($long) . $extra);
1077 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1078 sub format_git_diff_header_line
{
1080 my $diffinfo = shift;
1081 my ($from, $to) = @_;
1083 if ($diffinfo->{'nparents'}) {
1085 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1086 if ($to->{'href'}) {
1087 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1088 esc_path
($to->{'file'}));
1089 } else { # file was deleted (no href)
1090 $line .= esc_path
($to->{'file'});
1094 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1095 if ($from->{'href'}) {
1096 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1097 'a/' . esc_path
($from->{'file'}));
1098 } else { # file was added (no href)
1099 $line .= 'a/' . esc_path
($from->{'file'});
1102 if ($to->{'href'}) {
1103 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1104 'b/' . esc_path
($to->{'file'}));
1105 } else { # file was deleted
1106 $line .= 'b/' . esc_path
($to->{'file'});
1110 return "<div class=\"diff header\">$line</div>\n";
1113 # format extended diff header line, before patch itself
1114 sub format_extended_diff_header_line
{
1116 my $diffinfo = shift;
1117 my ($from, $to) = @_;
1120 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1121 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1122 esc_path
($from->{'file'}));
1124 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1125 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1126 esc_path
($to->{'file'}));
1128 # match single <mode>
1129 if ($line =~ m/\s(\d{6})$/) {
1130 $line .= '<span class="info"> (' .
1131 file_type_long
($1) .
1135 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1136 # can match only for combined diff
1138 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1139 if ($from->{'href'}[$i]) {
1140 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1142 substr($diffinfo->{'from_id'}[$i],0,7));
1147 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1150 if ($to->{'href'}) {
1151 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1152 substr($diffinfo->{'to_id'},0,7));
1157 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1158 # can match only for ordinary diff
1159 my ($from_link, $to_link);
1160 if ($from->{'href'}) {
1161 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1162 substr($diffinfo->{'from_id'},0,7));
1164 $from_link = '0' x
7;
1166 if ($to->{'href'}) {
1167 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1168 substr($diffinfo->{'to_id'},0,7));
1172 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1173 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1176 return $line . "<br/>\n";
1179 # format from-file/to-file diff header
1180 sub format_diff_from_to_header
{
1181 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1186 #assert($line =~ m/^---/) if DEBUG;
1187 # no extra formatting for "^--- /dev/null"
1188 if (! $diffinfo->{'nparents'}) {
1189 # ordinary (single parent) diff
1190 if ($line =~ m!^--- "?a/!) {
1191 if ($from->{'href'}) {
1193 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1194 esc_path
($from->{'file'}));
1197 esc_path
($from->{'file'});
1200 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1203 # combined diff (merge commit)
1204 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1205 if ($from->{'href'}[$i]) {
1207 $cgi->a({-href
=>href
(action
=>"blobdiff",
1208 hash_parent
=>$diffinfo->{'from_id'}[$i],
1209 hash_parent_base
=>$parents[$i],
1210 file_parent
=>$from->{'file'}[$i],
1211 hash
=>$diffinfo->{'to_id'},
1213 file_name
=>$to->{'file'}),
1215 -title
=>"diff" . ($i+1)},
1218 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1219 esc_path
($from->{'file'}[$i]));
1221 $line = '--- /dev/null';
1223 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1228 #assert($line =~ m/^\+\+\+/) if DEBUG;
1229 # no extra formatting for "^+++ /dev/null"
1230 if ($line =~ m!^\+\+\+ "?b/!) {
1231 if ($to->{'href'}) {
1233 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1234 esc_path
($to->{'file'}));
1237 esc_path
($to->{'file'});
1240 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1245 # create note for patch simplified by combined diff
1246 sub format_diff_cc_simplified
{
1247 my ($diffinfo, @parents) = @_;
1250 $result .= "<div class=\"diff header\">" .
1252 if (!is_deleted
($diffinfo)) {
1253 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1255 hash
=>$diffinfo->{'to_id'},
1256 file_name
=>$diffinfo->{'to_file'}),
1258 esc_path
($diffinfo->{'to_file'}));
1260 $result .= esc_path
($diffinfo->{'to_file'});
1262 $result .= "</div>\n" . # class="diff header"
1263 "<div class=\"diff nodifferences\">" .
1265 "</div>\n"; # class="diff nodifferences"
1270 # format patch (diff) line (not to be used for diff headers)
1271 sub format_diff_line
{
1273 my ($from, $to) = @_;
1274 my $diff_class = "";
1278 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1280 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1281 if ($line =~ m/^\@{3}/) {
1282 $diff_class = " chunk_header";
1283 } elsif ($line =~ m/^\\/) {
1284 $diff_class = " incomplete";
1285 } elsif ($prefix =~ tr/+/+/) {
1286 $diff_class = " add";
1287 } elsif ($prefix =~ tr/-/-/) {
1288 $diff_class = " rem";
1291 # assume ordinary diff
1292 my $char = substr($line, 0, 1);
1294 $diff_class = " add";
1295 } elsif ($char eq '-') {
1296 $diff_class = " rem";
1297 } elsif ($char eq '@') {
1298 $diff_class = " chunk_header";
1299 } elsif ($char eq "\\") {
1300 $diff_class = " incomplete";
1303 $line = untabify
($line);
1304 if ($from && $to && $line =~ m/^\@{2} /) {
1305 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1306 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1308 $from_lines = 0 unless defined $from_lines;
1309 $to_lines = 0 unless defined $to_lines;
1311 if ($from->{'href'}) {
1312 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1313 -class=>"list"}, $from_text);
1315 if ($to->{'href'}) {
1316 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1317 -class=>"list"}, $to_text);
1319 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1320 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1321 return "<div class=\"diff$diff_class\">$line</div>\n";
1322 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1323 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1324 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1326 @from_text = split(' ', $ranges);
1327 for (my $i = 0; $i < @from_text; ++$i) {
1328 ($from_start[$i], $from_nlines[$i]) =
1329 (split(',', substr($from_text[$i], 1)), 0);
1332 $to_text = pop @from_text;
1333 $to_start = pop @from_start;
1334 $to_nlines = pop @from_nlines;
1336 $line = "<span class=\"chunk_info\">$prefix ";
1337 for (my $i = 0; $i < @from_text; ++$i) {
1338 if ($from->{'href'}[$i]) {
1339 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1340 -class=>"list"}, $from_text[$i]);
1342 $line .= $from_text[$i];
1346 if ($to->{'href'}) {
1347 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1348 -class=>"list"}, $to_text);
1352 $line .= " $prefix</span>" .
1353 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1354 return "<div class=\"diff$diff_class\">$line</div>\n";
1356 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1359 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1360 # linked. Pass the hash of the tree/commit to snapshot.
1361 sub format_snapshot_links
{
1363 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1364 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1365 my $num_fmts = @snapshot_fmts;
1366 if ($num_fmts > 1) {
1367 # A parenthesized list of links bearing format names.
1368 # e.g. "snapshot (_tar.gz_ _zip_)"
1369 return "snapshot (" . join(' ', map
1376 }, $known_snapshot_formats{$_}{'display'})
1377 , @snapshot_fmts) . ")";
1378 } elsif ($num_fmts == 1) {
1379 # A single "snapshot" link whose tooltip bears the format name.
1381 my ($fmt) = @snapshot_fmts;
1387 snapshot_format
=>$fmt
1389 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1391 } else { # $num_fmts == 0
1396 ## ----------------------------------------------------------------------
1397 ## git utility subroutines, invoking git commands
1399 # returns path to the core git executable and the --git-dir parameter as list
1401 return $GIT, '--git-dir='.$git_dir;
1404 # returns path to the core git executable and the --git-dir parameter as string
1406 return join(' ', git_cmd
());
1409 # get HEAD ref of given project as hash
1410 sub git_get_head_hash
{
1411 my $project = shift;
1412 my $o_git_dir = $git_dir;
1414 $git_dir = "$projectroot/$project";
1415 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1418 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1422 if (defined $o_git_dir) {
1423 $git_dir = $o_git_dir;
1428 # get type of given object
1432 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1434 close $fd or return;
1439 # repository configuration
1440 our $config_file = '';
1443 # store multiple values for single key as anonymous array reference
1444 # single values stored directly in the hash, not as [ <value> ]
1445 sub hash_set_multi
{
1446 my ($hash, $key, $value) = @_;
1448 if (!exists $hash->{$key}) {
1449 $hash->{$key} = $value;
1450 } elsif (!ref $hash->{$key}) {
1451 $hash->{$key} = [ $hash->{$key}, $value ];
1453 push @
{$hash->{$key}}, $value;
1457 # return hash of git project configuration
1458 # optionally limited to some section, e.g. 'gitweb'
1459 sub git_parse_project_config
{
1460 my $section_regexp = shift;
1465 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1468 while (my $keyval = <$fh>) {
1470 my ($key, $value) = split(/\n/, $keyval, 2);
1472 hash_set_multi
(\
%config, $key, $value)
1473 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1480 # convert config value to boolean, 'true' or 'false'
1481 # no value, number > 0, 'true' and 'yes' values are true
1482 # rest of values are treated as false (never as error)
1483 sub config_to_bool
{
1486 # strip leading and trailing whitespace
1490 return (!defined $val || # section.key
1491 ($val =~ /^\d+$/ && $val) || # section.key = 1
1492 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1495 # convert config value to simple decimal number
1496 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1497 # to be multiplied by 1024, 1048576, or 1073741824
1501 # strip leading and trailing whitespace
1505 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1507 # unknown unit is treated as 1
1508 return $num * ($unit eq 'g' ?
1073741824 :
1509 $unit eq 'm' ?
1048576 :
1510 $unit eq 'k' ?
1024 : 1);
1515 # convert config value to array reference, if needed
1516 sub config_to_multi
{
1519 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1522 sub git_get_project_config
{
1523 my ($key, $type) = @_;
1526 return unless ($key);
1527 $key =~ s/^gitweb\.//;
1528 return if ($key =~ m/\W/);
1531 if (defined $type) {
1534 unless ($type eq 'bool' || $type eq 'int');
1538 if (!defined $config_file ||
1539 $config_file ne "$git_dir/config") {
1540 %config = git_parse_project_config
('gitweb');
1541 $config_file = "$git_dir/config";
1545 if (!defined $type) {
1546 return $config{"gitweb.$key"};
1547 } elsif ($type eq 'bool') {
1548 # backward compatibility: 'git config --bool' returns true/false
1549 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1550 } elsif ($type eq 'int') {
1551 return config_to_int
($config{"gitweb.$key"});
1553 return $config{"gitweb.$key"};
1556 # get hash of given path at given ref
1557 sub git_get_hash_by_path
{
1559 my $path = shift || return undef;
1564 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1565 or die_error
(undef, "Open git-ls-tree failed");
1567 close $fd or return undef;
1569 if (!defined $line) {
1570 # there is no tree or hash given by $path at $base
1574 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1575 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1576 if (defined $type && $type ne $2) {
1577 # type doesn't match
1583 # get path of entry with given hash at given tree-ish (ref)
1584 # used to get 'from' filename for combined diff (merge commit) for renames
1585 sub git_get_path_by_hash
{
1586 my $base = shift || return;
1587 my $hash = shift || return;
1591 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1593 while (my $line = <$fd>) {
1596 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1597 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1598 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1607 ## ......................................................................
1608 ## git utility functions, directly accessing git repository
1610 sub git_get_project_description
{
1613 $git_dir = "$projectroot/$path";
1614 open my $fd, "$git_dir/description"
1615 or return git_get_project_config
('description');
1618 if (defined $descr) {
1624 sub git_get_project_url_list
{
1627 $git_dir = "$projectroot/$path";
1628 open my $fd, "$projectroot/$path/cloneurl"
1629 or return wantarray ?
1630 @
{ config_to_multi
(git_get_project_config
('url')) } :
1631 config_to_multi
(git_get_project_config
('url'));
1632 my @git_project_url_list = map { chomp; $_ } <$fd>;
1635 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1638 sub git_get_projects_list
{
1643 $filter =~ s/\.git$//;
1645 my ($check_forks) = gitweb_check_feature
('forks');
1647 if (-d
$projects_list) {
1648 # search in directory
1649 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1650 # remove the trailing "/"
1652 my $pfxlen = length("$dir");
1653 my $pfxdepth = ($dir =~ tr!/!!);
1656 follow_fast
=> 1, # follow symbolic links
1657 follow_skip
=> 2, # ignore duplicates
1658 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1660 # skip project-list toplevel, if we get it.
1661 return if (m!^[/.]$!);
1662 # only directories can be git repositories
1663 return unless (-d
$_);
1664 # don't traverse too deep (Find is super slow on os x)
1665 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1666 $File::Find
::prune
= 1;
1670 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1671 # we check related file in $projectroot
1672 if ($check_forks and $subdir =~ m
#/.#) {
1673 $File::Find
::prune
= 1;
1674 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1675 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1676 $File::Find
::prune
= 1;
1681 } elsif (-f
$projects_list) {
1682 # read from file(url-encoded):
1683 # 'git%2Fgit.git Linus+Torvalds'
1684 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1685 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1687 open my ($fd), $projects_list or return;
1689 while (my $line = <$fd>) {
1691 my ($path, $owner) = split ' ', $line;
1692 $path = unescape
($path);
1693 $owner = unescape
($owner);
1694 if (!defined $path) {
1697 if ($filter ne '') {
1698 # looking for forks;
1699 my $pfx = substr($path, 0, length($filter));
1700 if ($pfx ne $filter) {
1703 my $sfx = substr($path, length($filter));
1704 if ($sfx !~ /^\/.*\
.git
$/) {
1707 } elsif ($check_forks) {
1709 foreach my $filter (keys %paths) {
1710 # looking for forks;
1711 my $pfx = substr($path, 0, length($filter));
1712 if ($pfx ne $filter) {
1715 my $sfx = substr($path, length($filter));
1716 if ($sfx !~ /^\/.*\
.git
$/) {
1719 # is a fork, don't include it in
1724 if (check_export_ok
("$projectroot/$path")) {
1727 owner
=> to_utf8
($owner),
1730 (my $forks_path = $path) =~ s/\.git$//;
1731 $paths{$forks_path}++;
1739 our $gitweb_project_owner = undef;
1740 sub git_get_project_list_from_file
{
1742 return if (defined $gitweb_project_owner);
1744 $gitweb_project_owner = {};
1745 # read from file (url-encoded):
1746 # 'git%2Fgit.git Linus+Torvalds'
1747 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1748 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1749 if (-f
$projects_list) {
1750 open (my $fd , $projects_list);
1751 while (my $line = <$fd>) {
1753 my ($pr, $ow) = split ' ', $line;
1754 $pr = unescape
($pr);
1755 $ow = unescape
($ow);
1756 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1762 sub git_get_project_owner
{
1763 my $project = shift;
1766 return undef unless $project;
1768 if (!defined $gitweb_project_owner) {
1769 git_get_project_list_from_file
();
1772 if (exists $gitweb_project_owner->{$project}) {
1773 $owner = $gitweb_project_owner->{$project};
1775 if (!defined $owner) {
1776 $owner = get_file_owner
("$projectroot/$project");
1782 sub git_get_last_activity
{
1786 $git_dir = "$projectroot/$path";
1787 open($fd, "-|", git_cmd
(), 'for-each-ref',
1788 '--format=%(committer)',
1789 '--sort=-committerdate',
1791 'refs/heads') or return;
1792 my $most_recent = <$fd>;
1793 close $fd or return;
1794 if (defined $most_recent &&
1795 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1797 my $age = time - $timestamp;
1798 return ($age, age_string
($age));
1800 return (undef, undef);
1803 sub git_get_references
{
1804 my $type = shift || "";
1806 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1807 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1808 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1809 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1812 while (my $line = <$fd>) {
1814 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1815 if (defined $refs{$1}) {
1816 push @
{$refs{$1}}, $2;
1822 close $fd or return;
1826 sub git_get_rev_name_tags
{
1827 my $hash = shift || return undef;
1829 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1831 my $name_rev = <$fd>;
1834 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1837 # catches also '$hash undefined' output
1842 ## ----------------------------------------------------------------------
1843 ## parse to hash functions
1847 my $tz = shift || "-0000";
1850 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1851 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1852 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1853 $date{'hour'} = $hour;
1854 $date{'minute'} = $min;
1855 $date{'mday'} = $mday;
1856 $date{'day'} = $days[$wday];
1857 $date{'month'} = $months[$mon];
1858 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1859 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1860 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1861 $mday, $months[$mon], $hour ,$min;
1862 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1863 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1865 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1866 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1867 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1868 $date{'hour_local'} = $hour;
1869 $date{'minute_local'} = $min;
1870 $date{'tz_local'} = $tz;
1871 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1872 1900+$year, $mon+1, $mday,
1873 $hour, $min, $sec, $tz);
1882 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1883 $tag{'id'} = $tag_id;
1884 while (my $line = <$fd>) {
1886 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1887 $tag{'object'} = $1;
1888 } elsif ($line =~ m/^type (.+)$/) {
1890 } elsif ($line =~ m/^tag (.+)$/) {
1892 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1893 $tag{'author'} = $1;
1896 } elsif ($line =~ m/--BEGIN/) {
1897 push @comment, $line;
1899 } elsif ($line eq "") {
1903 push @comment, <$fd>;
1904 $tag{'comment'} = \
@comment;
1905 close $fd or return;
1906 if (!defined $tag{'name'}) {
1912 sub parse_commit_text
{
1913 my ($commit_text, $withparents) = @_;
1914 my @commit_lines = split '\n', $commit_text;
1917 pop @commit_lines; # Remove '\0'
1919 if (! @commit_lines) {
1923 my $header = shift @commit_lines;
1924 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1927 ($co{'id'}, my @parents) = split ' ', $header;
1928 while (my $line = shift @commit_lines) {
1929 last if $line eq "\n";
1930 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1932 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1934 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1936 $co{'author_epoch'} = $2;
1937 $co{'author_tz'} = $3;
1938 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1939 $co{'author_name'} = $1;
1940 $co{'author_email'} = $2;
1942 $co{'author_name'} = $co{'author'};
1944 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1945 $co{'committer'} = $1;
1946 $co{'committer_epoch'} = $2;
1947 $co{'committer_tz'} = $3;
1948 $co{'committer_name'} = $co{'committer'};
1949 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1950 $co{'committer_name'} = $1;
1951 $co{'committer_email'} = $2;
1953 $co{'committer_name'} = $co{'committer'};
1957 if (!defined $co{'tree'}) {
1960 $co{'parents'} = \
@parents;
1961 $co{'parent'} = $parents[0];
1963 foreach my $title (@commit_lines) {
1966 $co{'title'} = chop_str
($title, 80, 5);
1967 # remove leading stuff of merges to make the interesting part visible
1968 if (length($title) > 50) {
1969 $title =~ s/^Automatic //;
1970 $title =~ s/^merge (of|with) /Merge ... /i;
1971 if (length($title) > 50) {
1972 $title =~ s/(http|rsync):\/\///;
1974 if (length($title) > 50) {
1975 $title =~ s/(master|www|rsync)\.//;
1977 if (length($title) > 50) {
1978 $title =~ s/kernel.org:?//;
1980 if (length($title) > 50) {
1981 $title =~ s/\/pub\/scm//;
1984 $co{'title_short'} = chop_str
($title, 50, 5);
1988 if ($co{'title'} eq "") {
1989 $co{'title'} = $co{'title_short'} = '(no commit message)';
1991 # remove added spaces
1992 foreach my $line (@commit_lines) {
1995 $co{'comment'} = \
@commit_lines;
1997 my $age = time - $co{'committer_epoch'};
1999 $co{'age_string'} = age_string
($age);
2000 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2001 if ($age > 60*60*24*7*2) {
2002 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2003 $co{'age_string_age'} = $co{'age_string'};
2005 $co{'age_string_date'} = $co{'age_string'};
2006 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2012 my ($commit_id) = @_;
2017 open my $fd, "-|", git_cmd
(), "rev-list",
2023 or die_error
(undef, "Open git-rev-list failed");
2024 %co = parse_commit_text
(<$fd>, 1);
2031 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
2039 open my $fd, "-|", git_cmd
(), "rev-list",
2041 ($arg ?
($arg) : ()),
2042 ("--max-count=" . $maxcount),
2043 ("--skip=" . $skip),
2047 ($filename ?
($filename) : ())
2048 or die_error
(undef, "Open git-rev-list failed");
2049 while (my $line = <$fd>) {
2050 my %co = parse_commit_text
($line);
2055 return wantarray ?
@cos : \
@cos;
2058 # parse ref from ref_file, given by ref_id, with given type
2060 my $ref_file = shift;
2062 my $type = shift || git_get_type
($ref_id);
2065 $ref_item{'type'} = $type;
2066 $ref_item{'id'} = $ref_id;
2067 $ref_item{'epoch'} = 0;
2068 $ref_item{'age'} = "unknown";
2069 if ($type eq "tag") {
2070 my %tag = parse_tag
($ref_id);
2071 $ref_item{'comment'} = $tag{'comment'};
2072 if ($tag{'type'} eq "commit") {
2073 my %co = parse_commit
($tag{'object'});
2074 $ref_item{'epoch'} = $co{'committer_epoch'};
2075 $ref_item{'age'} = $co{'age_string'};
2076 } elsif (defined($tag{'epoch'})) {
2077 my $age = time - $tag{'epoch'};
2078 $ref_item{'epoch'} = $tag{'epoch'};
2079 $ref_item{'age'} = age_string
($age);
2081 $ref_item{'reftype'} = $tag{'type'};
2082 $ref_item{'name'} = $tag{'name'};
2083 $ref_item{'refid'} = $tag{'object'};
2084 } elsif ($type eq "commit"){
2085 my %co = parse_commit
($ref_id);
2086 $ref_item{'reftype'} = "commit";
2087 $ref_item{'name'} = $ref_file;
2088 $ref_item{'title'} = $co{'title'};
2089 $ref_item{'refid'} = $ref_id;
2090 $ref_item{'epoch'} = $co{'committer_epoch'};
2091 $ref_item{'age'} = $co{'age_string'};
2093 $ref_item{'reftype'} = $type;
2094 $ref_item{'name'} = $ref_file;
2095 $ref_item{'refid'} = $ref_id;
2101 # parse line of git-diff-tree "raw" output
2102 sub parse_difftree_raw_line
{
2106 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2107 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2108 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2109 $res{'from_mode'} = $1;
2110 $res{'to_mode'} = $2;
2111 $res{'from_id'} = $3;
2113 $res{'status'} = $res{'status_str'} = $5;
2114 $res{'similarity'} = $6;
2115 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2116 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2118 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2121 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2122 # combined diff (for merge commit)
2123 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2124 $res{'nparents'} = length($1);
2125 $res{'from_mode'} = [ split(' ', $2) ];
2126 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2127 $res{'from_id'} = [ split(' ', $3) ];
2128 $res{'to_id'} = pop @
{$res{'from_id'}};
2129 $res{'status_str'} = $4;
2130 $res{'status'} = [ split('', $4) ];
2131 $res{'to_file'} = unquote
($5);
2133 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2134 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2135 $res{'commit'} = $1;
2138 return wantarray ?
%res : \
%res;
2141 # wrapper: return parsed line of git-diff-tree "raw" output
2142 # (the argument might be raw line, or parsed info)
2143 sub parsed_difftree_line
{
2144 my $line_or_ref = shift;
2146 if (ref($line_or_ref) eq "HASH") {
2147 # pre-parsed (or generated by hand)
2148 return $line_or_ref;
2150 return parse_difftree_raw_line
($line_or_ref);
2154 # parse line of git-ls-tree output
2155 sub parse_ls_tree_line
($;%) {
2160 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2161 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2169 $res{'name'} = unquote
($4);
2172 return wantarray ?
%res : \
%res;
2175 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2176 sub parse_from_to_diffinfo
{
2177 my ($diffinfo, $from, $to, @parents) = @_;
2179 if ($diffinfo->{'nparents'}) {
2181 $from->{'file'} = [];
2182 $from->{'href'} = [];
2183 fill_from_file_info
($diffinfo, @parents)
2184 unless exists $diffinfo->{'from_file'};
2185 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2186 $from->{'file'}[$i] =
2187 defined $diffinfo->{'from_file'}[$i] ?
2188 $diffinfo->{'from_file'}[$i] :
2189 $diffinfo->{'to_file'};
2190 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2191 $from->{'href'}[$i] = href
(action
=>"blob",
2192 hash_base
=>$parents[$i],
2193 hash
=>$diffinfo->{'from_id'}[$i],
2194 file_name
=>$from->{'file'}[$i]);
2196 $from->{'href'}[$i] = undef;
2200 # ordinary (not combined) diff
2201 $from->{'file'} = $diffinfo->{'from_file'};
2202 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2203 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2204 hash
=>$diffinfo->{'from_id'},
2205 file_name
=>$from->{'file'});
2207 delete $from->{'href'};
2211 $to->{'file'} = $diffinfo->{'to_file'};
2212 if (!is_deleted
($diffinfo)) { # file exists in result
2213 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2214 hash
=>$diffinfo->{'to_id'},
2215 file_name
=>$to->{'file'});
2217 delete $to->{'href'};
2221 ## ......................................................................
2222 ## parse to array of hashes functions
2224 sub git_get_heads_list
{
2228 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2229 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2230 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2233 while (my $line = <$fd>) {
2237 my ($refinfo, $committerinfo) = split(/\0/, $line);
2238 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2239 my ($committer, $epoch, $tz) =
2240 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2241 $ref_item{'fullname'} = $name;
2242 $name =~ s!^refs/heads/!!;
2244 $ref_item{'name'} = $name;
2245 $ref_item{'id'} = $hash;
2246 $ref_item{'title'} = $title || '(no commit message)';
2247 $ref_item{'epoch'} = $epoch;
2249 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2251 $ref_item{'age'} = "unknown";
2254 push @headslist, \
%ref_item;
2258 return wantarray ?
@headslist : \
@headslist;
2261 sub git_get_tags_list
{
2265 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2266 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2267 '--format=%(objectname) %(objecttype) %(refname) '.
2268 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2271 while (my $line = <$fd>) {
2275 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2276 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2277 my ($creator, $epoch, $tz) =
2278 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2279 $ref_item{'fullname'} = $name;
2280 $name =~ s!^refs/tags/!!;
2282 $ref_item{'type'} = $type;
2283 $ref_item{'id'} = $id;
2284 $ref_item{'name'} = $name;
2285 if ($type eq "tag") {
2286 $ref_item{'subject'} = $title;
2287 $ref_item{'reftype'} = $reftype;
2288 $ref_item{'refid'} = $refid;
2290 $ref_item{'reftype'} = $type;
2291 $ref_item{'refid'} = $id;
2294 if ($type eq "tag" || $type eq "commit") {
2295 $ref_item{'epoch'} = $epoch;
2297 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2299 $ref_item{'age'} = "unknown";
2303 push @tagslist, \
%ref_item;
2307 return wantarray ?
@tagslist : \
@tagslist;
2310 ## ----------------------------------------------------------------------
2311 ## filesystem-related functions
2313 sub get_file_owner
{
2316 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2317 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2318 if (!defined $gcos) {
2322 $owner =~ s/[,;].*$//;
2323 return to_utf8
($owner);
2326 ## ......................................................................
2327 ## mimetype related functions
2329 sub mimetype_guess_file
{
2330 my $filename = shift;
2331 my $mimemap = shift;
2332 -r
$mimemap or return undef;
2335 open(MIME
, $mimemap) or return undef;
2337 next if m/^#/; # skip comments
2338 my ($mime, $exts) = split(/\t+/);
2339 if (defined $exts) {
2340 my @exts = split(/\s+/, $exts);
2341 foreach my $ext (@exts) {
2342 $mimemap{$ext} = $mime;
2348 $filename =~ /\.([^.]*)$/;
2349 return $mimemap{$1};
2352 sub mimetype_guess
{
2353 my $filename = shift;
2355 $filename =~ /\./ or return undef;
2357 if ($mimetypes_file) {
2358 my $file = $mimetypes_file;
2359 if ($file !~ m!^/!) { # if it is relative path
2360 # it is relative to project
2361 $file = "$projectroot/$project/$file";
2363 $mime = mimetype_guess_file
($filename, $file);
2365 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2371 my $filename = shift;
2374 my $mime = mimetype_guess
($filename);
2375 $mime and return $mime;
2379 return $default_blob_plain_mimetype unless $fd;
2382 return 'text/plain' .
2383 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2384 } elsif (! $filename) {
2385 return 'application/octet-stream';
2386 } elsif ($filename =~ m/\.png$/i) {
2388 } elsif ($filename =~ m/\.gif$/i) {
2390 } elsif ($filename =~ m/\.jpe?g$/i) {
2391 return 'image/jpeg';
2393 return 'application/octet-stream';
2397 ## ======================================================================
2398 ## functions printing HTML: header, footer, error page
2400 sub git_header_html
{
2401 my $status = shift || "200 OK";
2402 my $expires = shift;
2404 my $title = "$site_name";
2405 if (defined $project) {
2406 $title .= " - " . to_utf8
($project);
2407 if (defined $action) {
2408 $title .= "/$action";
2409 if (defined $file_name) {
2410 $title .= " - " . esc_path
($file_name);
2411 if ($action eq "tree" && $file_name !~ m
|/$|) {
2418 # require explicit support from the UA if we are to send the page as
2419 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2420 # we have to do this because MSIE sometimes globs '*/*', pretending to
2421 # support xhtml+xml but choking when it gets what it asked for.
2422 if (defined $cgi->http('HTTP_ACCEPT') &&
2423 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2424 $cgi->Accept('application/xhtml+xml') != 0) {
2425 $content_type = 'application/xhtml+xml';
2427 $content_type = 'text/html';
2429 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2430 -status
=> $status, -expires
=> $expires);
2431 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2433 <?xml version="1.0" encoding="utf-8"?>
2434 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2435 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2436 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2437 <!-- git core binaries version $git_version -->
2439 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2440 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2441 <meta name="robots" content="index, nofollow"/>
2442 <title>$title</title>
2444 # print out each stylesheet that exist
2445 if (defined $stylesheet) {
2446 #provides backwards capability for those people who define style sheet in a config file
2447 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2449 foreach my $stylesheet (@stylesheets) {
2450 next unless $stylesheet;
2451 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2454 if (defined $project) {
2455 printf('<link rel="alternate" title="%s log RSS feed" '.
2456 'href="%s" type="application/rss+xml" />'."\n",
2457 esc_param
($project), href
(action
=>"rss"));
2458 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2459 'href="%s" type="application/rss+xml" />'."\n",
2460 esc_param
($project), href
(action
=>"rss",
2461 extra_options
=>"--no-merges"));
2462 printf('<link rel="alternate" title="%s log Atom feed" '.
2463 'href="%s" type="application/atom+xml" />'."\n",
2464 esc_param
($project), href
(action
=>"atom"));
2465 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2466 'href="%s" type="application/atom+xml" />'."\n",
2467 esc_param
($project), href
(action
=>"atom",
2468 extra_options
=>"--no-merges"));
2470 printf('<link rel="alternate" title="%s projects list" '.
2471 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2472 $site_name, href
(project
=>undef, action
=>"project_index"));
2473 printf('<link rel="alternate" title="%s projects feeds" '.
2474 'href="%s" type="text/x-opml"/>'."\n",
2475 $site_name, href
(project
=>undef, action
=>"opml"));
2477 if (defined $favicon) {
2478 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2484 if (-f
$site_header) {
2485 open (my $fd, $site_header);
2490 print "<div class=\"page_header\">\n" .
2491 $cgi->a({-href
=> esc_url
($logo_url),
2492 -title
=> $logo_label},
2493 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2494 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2495 if (defined $project) {
2496 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2497 if (defined $action) {
2504 my ($have_search) = gitweb_check_feature
('search');
2505 if ((defined $project) && ($have_search)) {
2506 if (!defined $searchtext) {
2510 if (defined $hash_base) {
2511 $search_hash = $hash_base;
2512 } elsif (defined $hash) {
2513 $search_hash = $hash;
2515 $search_hash = "HEAD";
2517 my $action = $my_uri;
2518 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2519 if ($use_pathinfo) {
2520 $action .= "/$project";
2522 $cgi->param("p", $project);
2524 $cgi->param("a", "search");
2525 $cgi->param("h", $search_hash);
2526 print $cgi->startform(-method
=> "get", -action
=> $action) .
2527 "<div class=\"search\">\n" .
2528 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2529 $cgi->hidden(-name
=> "a") . "\n" .
2530 $cgi->hidden(-name
=> "h") . "\n" .
2531 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2532 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2533 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2535 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2537 $cgi->end_form() . "\n";
2541 sub git_footer_html
{
2542 print "<div class=\"page_footer\">\n";
2543 if (defined $project) {
2544 my $descr = git_get_project_description
($project);
2545 if (defined $descr) {
2546 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2548 print $cgi->a({-href
=> href
(action
=>"rss"),
2549 -class => "rss_logo"}, "RSS") . " ";
2550 print $cgi->a({-href
=> href
(action
=>"atom"),
2551 -class => "rss_logo"}, "Atom") . "\n";
2553 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2554 -class => "rss_logo"}, "OPML") . " ";
2555 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2556 -class => "rss_logo"}, "TXT") . "\n";
2560 if (-f
$site_footer) {
2561 open (my $fd, $site_footer);
2571 my $status = shift || "403 Forbidden";
2572 my $error = shift || "Malformed query, file missing or permission denied";
2574 git_header_html
($status);
2576 <div class="page_body">
2586 ## ----------------------------------------------------------------------
2587 ## functions printing or outputting HTML: navigation
2589 sub git_print_page_nav
{
2590 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2591 $extra = '' if !defined $extra; # pager or formats
2593 my @navs = qw(summary shortlog log commit commitdiff tree);
2595 @navs = grep { $_ ne $suppress } @navs;
2598 my %arg = map { $_ => {action
=>$_} } @navs;
2599 if (defined $head) {
2600 for (qw(commit commitdiff)) {
2601 $arg{$_}{'hash'} = $head;
2603 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2604 for (qw(shortlog log)) {
2605 $arg{$_}{'hash'} = $head;
2609 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2610 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2612 print "<div class=\"page_nav\">\n" .
2614 map { $_ eq $current ?
2615 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2617 print "<br/>\n$extra<br/>\n" .
2621 sub format_paging_nav
{
2622 my ($action, $hash, $head, $page, $nrevs) = @_;
2626 if ($hash ne $head || $page) {
2627 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2629 $paging_nav .= "HEAD";
2633 $paging_nav .= " ⋅ " .
2634 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2635 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2637 $paging_nav .= " ⋅ prev";
2640 if ($nrevs >= (100 * ($page+1)-1)) {
2641 $paging_nav .= " ⋅ " .
2642 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2643 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2645 $paging_nav .= " ⋅ next";
2651 ## ......................................................................
2652 ## functions printing or outputting HTML: div
2654 sub git_print_header_div
{
2655 my ($action, $title, $hash, $hash_base) = @_;
2658 $args{'action'} = $action;
2659 $args{'hash'} = $hash if $hash;
2660 $args{'hash_base'} = $hash_base if $hash_base;
2662 print "<div class=\"header\">\n" .
2663 $cgi->a({-href
=> href
(%args), -class => "title"},
2664 $title ?
$title : $action) .
2668 #sub git_print_authorship (\%) {
2669 sub git_print_authorship
{
2672 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2673 print "<div class=\"author_date\">" .
2674 esc_html
($co->{'author_name'}) .
2676 if ($ad{'hour_local'} < 6) {
2677 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2678 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2680 printf(" (%02d:%02d %s)",
2681 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2686 sub git_print_page_path
{
2692 print "<div class=\"page_path\">";
2693 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2694 -title
=> 'tree root'}, to_utf8
("[$project]"));
2696 if (defined $name) {
2697 my @dirname = split '/', $name;
2698 my $basename = pop @dirname;
2701 foreach my $dir (@dirname) {
2702 $fullname .= ($fullname ?
'/' : '') . $dir;
2703 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2705 -title
=> $fullname}, esc_path
($dir));
2708 if (defined $type && $type eq 'blob') {
2709 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2711 -title
=> $name}, esc_path
($basename));
2712 } elsif (defined $type && $type eq 'tree') {
2713 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2715 -title
=> $name}, esc_path
($basename));
2718 print esc_path
($basename);
2721 print "<br/></div>\n";
2724 # sub git_print_log (\@;%) {
2725 sub git_print_log
($;%) {
2729 if ($opts{'-remove_title'}) {
2730 # remove title, i.e. first line of log
2733 # remove leading empty lines
2734 while (defined $log->[0] && $log->[0] eq "") {
2741 foreach my $line (@
$log) {
2742 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2745 if (! $opts{'-remove_signoff'}) {
2746 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2749 # remove signoff lines
2756 # print only one empty line
2757 # do not print empty line after signoff
2759 next if ($empty || $signoff);
2765 print format_log_line_html
($line) . "<br/>\n";
2768 if ($opts{'-final_empty_line'}) {
2769 # end with single empty line
2770 print "<br/>\n" unless $empty;
2774 # return link target (what link points to)
2775 sub git_get_link_target
{
2780 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2784 $link_target = <$fd>;
2789 return $link_target;
2792 # given link target, and the directory (basedir) the link is in,
2793 # return target of link relative to top directory (top tree);
2794 # return undef if it is not possible (including absolute links).
2795 sub normalize_link_target
{
2796 my ($link_target, $basedir, $hash_base) = @_;
2798 # we can normalize symlink target only if $hash_base is provided
2799 return unless $hash_base;
2801 # absolute symlinks (beginning with '/') cannot be normalized
2802 return if (substr($link_target, 0, 1) eq '/');
2804 # normalize link target to path from top (root) tree (dir)
2807 $path = $basedir . '/' . $link_target;
2809 # we are in top (root) tree (dir)
2810 $path = $link_target;
2813 # remove //, /./, and /../
2815 foreach my $part (split('/', $path)) {
2816 # discard '.' and ''
2817 next if (!$part || $part eq '.');
2819 if ($part eq '..') {
2823 # link leads outside repository (outside top dir)
2827 push @path_parts, $part;
2830 $path = join('/', @path_parts);
2835 # print tree entry (row of git_tree), but without encompassing <tr> element
2836 sub git_print_tree_entry
{
2837 my ($t, $basedir, $hash_base, $have_blame) = @_;
2840 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2842 # The format of a table row is: mode list link. Where mode is
2843 # the mode of the entry, list is the name of the entry, an href,
2844 # and link is the action links of the entry.
2846 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2847 if ($t->{'type'} eq "blob") {
2848 print "<td class=\"list\">" .
2849 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2850 file_name
=>"$basedir$t->{'name'}", %base_key),
2851 -class => "list"}, esc_path
($t->{'name'}));
2852 if (S_ISLNK
(oct $t->{'mode'})) {
2853 my $link_target = git_get_link_target
($t->{'hash'});
2855 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2856 if (defined $norm_target) {
2858 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2859 file_name
=>$norm_target),
2860 -title
=> $norm_target}, esc_path
($link_target));
2862 print " -> " . esc_path
($link_target);
2867 print "<td class=\"link\">";
2868 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2869 file_name
=>"$basedir$t->{'name'}", %base_key)},
2873 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2874 file_name
=>"$basedir$t->{'name'}", %base_key)},
2877 if (defined $hash_base) {
2879 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2880 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2884 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2885 file_name
=>"$basedir$t->{'name'}")},
2889 } elsif ($t->{'type'} eq "tree") {
2890 print "<td class=\"list\">";
2891 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2892 file_name
=>"$basedir$t->{'name'}", %base_key)},
2893 esc_path
($t->{'name'}));
2895 print "<td class=\"link\">";
2896 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2897 file_name
=>"$basedir$t->{'name'}", %base_key)},
2899 if (defined $hash_base) {
2901 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2902 file_name
=>"$basedir$t->{'name'}")},
2907 # unknown object: we can only present history for it
2908 # (this includes 'commit' object, i.e. submodule support)
2909 print "<td class=\"list\">" .
2910 esc_path
($t->{'name'}) .
2912 print "<td class=\"link\">";
2913 if (defined $hash_base) {
2914 print $cgi->a({-href
=> href
(action
=>"history",
2915 hash_base
=>$hash_base,
2916 file_name
=>"$basedir$t->{'name'}")},
2923 ## ......................................................................
2924 ## functions printing large fragments of HTML
2926 # get pre-image filenames for merge (combined) diff
2927 sub fill_from_file_info
{
2928 my ($diff, @parents) = @_;
2930 $diff->{'from_file'} = [ ];
2931 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2932 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2933 if ($diff->{'status'}[$i] eq 'R' ||
2934 $diff->{'status'}[$i] eq 'C') {
2935 $diff->{'from_file'}[$i] =
2936 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2943 # is current raw difftree line of file deletion
2945 my $diffinfo = shift;
2947 return $diffinfo->{'status_str'} =~ /D/;
2950 # does patch correspond to [previous] difftree raw line
2951 # $diffinfo - hashref of parsed raw diff format
2952 # $patchinfo - hashref of parsed patch diff format
2953 # (the same keys as in $diffinfo)
2954 sub is_patch_split
{
2955 my ($diffinfo, $patchinfo) = @_;
2957 return defined $diffinfo && defined $patchinfo
2958 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
2962 sub git_difftree_body
{
2963 my ($difftree, $hash, @parents) = @_;
2964 my ($parent) = $parents[0];
2965 my ($have_blame) = gitweb_check_feature
('blame');
2966 print "<div class=\"list_head\">\n";
2967 if ($#{$difftree} > 10) {
2968 print(($#{$difftree} + 1) . " files changed:\n");
2972 print "<table class=\"" .
2973 (@parents > 1 ?
"combined " : "") .
2976 # header only for combined diff in 'commitdiff' view
2977 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
2980 print "<thead><tr>\n" .
2981 "<th></th><th></th>\n"; # filename, patchN link
2982 for (my $i = 0; $i < @parents; $i++) {
2983 my $par = $parents[$i];
2985 $cgi->a({-href
=> href
(action
=>"commitdiff",
2986 hash
=>$hash, hash_parent
=>$par),
2987 -title
=> 'commitdiff to parent number ' .
2988 ($i+1) . ': ' . substr($par,0,7)},
2992 print "</tr></thead>\n<tbody>\n";
2997 foreach my $line (@
{$difftree}) {
2998 my $diff = parsed_difftree_line
($line);
3001 print "<tr class=\"dark\">\n";
3003 print "<tr class=\"light\">\n";
3007 if (exists $diff->{'nparents'}) { # combined diff
3009 fill_from_file_info
($diff, @parents)
3010 unless exists $diff->{'from_file'};
3012 if (!is_deleted
($diff)) {
3013 # file exists in the result (child) commit
3015 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3016 file_name
=>$diff->{'to_file'},
3018 -class => "list"}, esc_path
($diff->{'to_file'})) .
3022 esc_path
($diff->{'to_file'}) .
3026 if ($action eq 'commitdiff') {
3029 print "<td class=\"link\">" .
3030 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3035 my $has_history = 0;
3036 my $not_deleted = 0;
3037 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3038 my $hash_parent = $parents[$i];
3039 my $from_hash = $diff->{'from_id'}[$i];
3040 my $from_path = $diff->{'from_file'}[$i];
3041 my $status = $diff->{'status'}[$i];
3043 $has_history ||= ($status ne 'A');
3044 $not_deleted ||= ($status ne 'D');
3046 if ($status eq 'A') {
3047 print "<td class=\"link\" align=\"right\"> | </td>\n";
3048 } elsif ($status eq 'D') {
3049 print "<td class=\"link\">" .
3050 $cgi->a({-href
=> href
(action
=>"blob",
3053 file_name
=>$from_path)},
3057 if ($diff->{'to_id'} eq $from_hash) {
3058 print "<td class=\"link nochange\">";
3060 print "<td class=\"link\">";
3062 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3063 hash
=>$diff->{'to_id'},
3064 hash_parent
=>$from_hash,
3066 hash_parent_base
=>$hash_parent,
3067 file_name
=>$diff->{'to_file'},
3068 file_parent
=>$from_path)},
3074 print "<td class=\"link\">";
3076 print $cgi->a({-href
=> href
(action
=>"blob",
3077 hash
=>$diff->{'to_id'},
3078 file_name
=>$diff->{'to_file'},
3081 print " | " if ($has_history);
3084 print $cgi->a({-href
=> href
(action
=>"history",
3085 file_name
=>$diff->{'to_file'},
3092 next; # instead of 'else' clause, to avoid extra indent
3094 # else ordinary diff
3096 my ($to_mode_oct, $to_mode_str, $to_file_type);
3097 my ($from_mode_oct, $from_mode_str, $from_file_type);
3098 if ($diff->{'to_mode'} ne ('0' x
6)) {
3099 $to_mode_oct = oct $diff->{'to_mode'};
3100 if (S_ISREG
($to_mode_oct)) { # only for regular file
3101 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3103 $to_file_type = file_type
($diff->{'to_mode'});
3105 if ($diff->{'from_mode'} ne ('0' x
6)) {
3106 $from_mode_oct = oct $diff->{'from_mode'};
3107 if (S_ISREG
($to_mode_oct)) { # only for regular file
3108 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3110 $from_file_type = file_type
($diff->{'from_mode'});
3113 if ($diff->{'status'} eq "A") { # created
3114 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3115 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3116 $mode_chng .= "]</span>";
3118 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3119 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3120 -class => "list"}, esc_path
($diff->{'file'}));
3122 print "<td>$mode_chng</td>\n";
3123 print "<td class=\"link\">";
3124 if ($action eq 'commitdiff') {
3127 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3130 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3131 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3135 } elsif ($diff->{'status'} eq "D") { # deleted
3136 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3138 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3139 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3140 -class => "list"}, esc_path
($diff->{'file'}));
3142 print "<td>$mode_chng</td>\n";
3143 print "<td class=\"link\">";
3144 if ($action eq 'commitdiff') {
3147 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3150 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3151 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3154 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3155 file_name
=>$diff->{'file'})},
3158 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3159 file_name
=>$diff->{'file'})},
3163 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3164 my $mode_chnge = "";
3165 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3166 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3167 if ($from_file_type ne $to_file_type) {
3168 $mode_chnge .= " from $from_file_type to $to_file_type";
3170 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3171 if ($from_mode_str && $to_mode_str) {
3172 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3173 } elsif ($to_mode_str) {
3174 $mode_chnge .= " mode: $to_mode_str";
3177 $mode_chnge .= "]</span>\n";
3180 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3181 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3182 -class => "list"}, esc_path
($diff->{'file'}));
3184 print "<td>$mode_chnge</td>\n";
3185 print "<td class=\"link\">";
3186 if ($action eq 'commitdiff') {
3189 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3191 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3192 # "commit" view and modified file (not onlu mode changed)
3193 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3194 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3195 hash_base
=>$hash, hash_parent_base
=>$parent,
3196 file_name
=>$diff->{'file'})},
3200 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3201 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3204 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3205 file_name
=>$diff->{'file'})},
3208 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3209 file_name
=>$diff->{'file'})},
3213 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3214 my %status_name = ('R' => 'moved', 'C' => 'copied');
3215 my $nstatus = $status_name{$diff->{'status'}};
3217 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3218 # mode also for directories, so we cannot use $to_mode_str
3219 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3222 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3223 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3224 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3225 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3226 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3227 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3228 -class => "list"}, esc_path
($diff->{'from_file'})) .
3229 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3230 "<td class=\"link\">";
3231 if ($action eq 'commitdiff') {
3234 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3236 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3237 # "commit" view and modified file (not only pure rename or copy)
3238 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3239 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3240 hash_base
=>$hash, hash_parent_base
=>$parent,
3241 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3245 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3246 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3249 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3250 file_name
=>$diff->{'to_file'})},
3253 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3254 file_name
=>$diff->{'to_file'})},
3258 } # we should not encounter Unmerged (U) or Unknown (X) status
3261 print "</tbody>" if $has_header;
3265 sub git_patchset_body
{
3266 my ($fd, $difftree, $hash, @hash_parents) = @_;
3267 my ($hash_parent) = $hash_parents[0];
3269 my $is_combined = (@hash_parents > 1);
3271 my $patch_number = 0;
3277 print "<div class=\"patchset\">\n";
3279 # skip to first patch
3280 while ($patch_line = <$fd>) {
3283 last if ($patch_line =~ m/^diff /);
3287 while ($patch_line) {
3289 # parse "git diff" header line
3290 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3291 # $1 is from_name, which we do not use
3292 $to_name = unquote
($2);
3293 $to_name =~ s!^b/!!;
3294 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3295 # $1 is 'cc' or 'combined', which we do not use
3296 $to_name = unquote
($2);
3301 # check if current patch belong to current raw line
3302 # and parse raw git-diff line if needed
3303 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3304 # this is continuation of a split patch
3305 print "<div class=\"patch cont\">\n";
3307 # advance raw git-diff output if needed
3308 $patch_idx++ if defined $diffinfo;
3310 # read and prepare patch information
3311 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3313 # compact combined diff output can have some patches skipped
3314 # find which patch (using pathname of result) we are at now;
3316 while ($to_name ne $diffinfo->{'to_file'}) {
3317 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3318 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3319 "</div>\n"; # class="patch"
3324 last if $patch_idx > $#$difftree;
3325 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3329 # modifies %from, %to hashes
3330 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3332 # this is first patch for raw difftree line with $patch_idx index
3333 # we index @$difftree array from 0, but number patches from 1
3334 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3338 #assert($patch_line =~ m/^diff /) if DEBUG;
3339 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3341 # print "git diff" header
3342 print format_git_diff_header_line
($patch_line, $diffinfo,
3345 # print extended diff header
3346 print "<div class=\"diff extended_header\">\n";
3348 while ($patch_line = <$fd>) {
3351 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3353 print format_extended_diff_header_line
($patch_line, $diffinfo,
3356 print "</div>\n"; # class="diff extended_header"
3358 # from-file/to-file diff header
3359 if (! $patch_line) {
3360 print "</div>\n"; # class="patch"
3363 next PATCH
if ($patch_line =~ m/^diff /);
3364 #assert($patch_line =~ m/^---/) if DEBUG;
3366 my $last_patch_line = $patch_line;
3367 $patch_line = <$fd>;
3369 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3371 print format_diff_from_to_header
($last_patch_line, $patch_line,
3372 $diffinfo, \
%from, \
%to,
3377 while ($patch_line = <$fd>) {
3380 next PATCH
if ($patch_line =~ m/^diff /);
3382 print format_diff_line
($patch_line, \
%from, \
%to);
3386 print "</div>\n"; # class="patch"
3389 # for compact combined (--cc) format, with chunk and patch simpliciaction
3390 # patchset might be empty, but there might be unprocessed raw lines
3391 for (++$patch_idx if $patch_number > 0;
3392 $patch_idx < @
$difftree;
3394 # read and prepare patch information
3395 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3397 # generate anchor for "patch" links in difftree / whatchanged part
3398 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3399 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3400 "</div>\n"; # class="patch"
3405 if ($patch_number == 0) {
3406 if (@hash_parents > 1) {
3407 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3409 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3413 print "</div>\n"; # class="patchset"
3416 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3418 sub git_project_list_body
{
3419 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3421 my ($check_forks) = gitweb_check_feature
('forks');
3424 foreach my $pr (@
$projlist) {
3425 my (@aa) = git_get_last_activity
($pr->{'path'});
3429 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3430 if (!defined $pr->{'descr'}) {
3431 my $descr = git_get_project_description
($pr->{'path'}) || "";
3432 $pr->{'descr_long'} = to_utf8
($descr);
3433 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3435 if (!defined $pr->{'owner'}) {
3436 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3439 my $pname = $pr->{'path'};
3440 if (($pname =~ s/\.git$//) &&
3441 ($pname !~ /\/$/) &&
3442 (-d
"$projectroot/$pname")) {
3443 $pr->{'forks'} = "-d $projectroot/$pname";
3449 push @projects, $pr;
3452 $order ||= $default_projects_order;
3453 $from = 0 unless defined $from;
3454 $to = $#projects if (!defined $to || $#projects < $to);
3456 print "<table class=\"project_list\">\n";
3457 unless ($no_header) {
3460 print "<th></th>\n";
3462 if ($order eq "project") {
3463 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3464 print "<th>Project</th>\n";
3467 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3468 -class => "header"}, "Project") .
3471 if ($order eq "descr") {
3472 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3473 print "<th>Description</th>\n";
3476 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3477 -class => "header"}, "Description") .
3480 if ($order eq "owner") {
3481 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3482 print "<th>Owner</th>\n";
3485 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3486 -class => "header"}, "Owner") .
3489 if ($order eq "age") {
3490 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3491 print "<th>Last Change</th>\n";
3494 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3495 -class => "header"}, "Last Change") .
3498 print "<th></th>\n" .
3502 for (my $i = $from; $i <= $to; $i++) {
3503 my $pr = $projects[$i];
3505 print "<tr class=\"dark\">\n";
3507 print "<tr class=\"light\">\n";
3512 if ($pr->{'forks'}) {
3513 print "<!-- $pr->{'forks'} -->\n";
3514 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3518 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3519 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3520 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3521 -class => "list", -title
=> $pr->{'descr_long'}},
3522 esc_html
($pr->{'descr'})) . "</td>\n" .
3523 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3524 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3525 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3526 "<td class=\"link\">" .
3527 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3528 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3529 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3530 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3531 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3535 if (defined $extra) {
3538 print "<td></td>\n";
3540 print "<td colspan=\"5\">$extra</td>\n" .
3546 sub git_shortlog_body
{
3547 # uses global variable $project
3548 my ($commitlist, $from, $to, $refs, $extra) = @_;
3550 $from = 0 unless defined $from;
3551 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3553 print "<table class=\"shortlog\">\n";
3555 for (my $i = $from; $i <= $to; $i++) {
3556 my %co = %{$commitlist->[$i]};
3557 my $commit = $co{'id'};
3558 my $ref = format_ref_marker
($refs, $commit);
3560 print "<tr class=\"dark\">\n";
3562 print "<tr class=\"light\">\n";
3565 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3566 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3567 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3568 "<td><i>" . $author . "</i></td>\n" .
3570 print format_subject_html
($co{'title'}, $co{'title_short'},
3571 href
(action
=>"commit", hash
=>$commit), $ref);
3573 "<td class=\"link\">" .
3574 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3575 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3576 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3577 my $snapshot_links = format_snapshot_links
($commit);
3578 if (defined $snapshot_links) {
3579 print " | " . $snapshot_links;
3584 if (defined $extra) {
3586 "<td colspan=\"4\">$extra</td>\n" .
3592 sub git_history_body
{
3593 # Warning: assumes constant type (blob or tree) during history
3594 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3596 $from = 0 unless defined $from;
3597 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3599 print "<table class=\"history\">\n";
3601 for (my $i = $from; $i <= $to; $i++) {
3602 my %co = %{$commitlist->[$i]};
3606 my $commit = $co{'id'};
3608 my $ref = format_ref_marker
($refs, $commit);
3611 print "<tr class=\"dark\">\n";
3613 print "<tr class=\"light\">\n";
3616 # shortlog uses chop_str($co{'author_name'}, 10)
3617 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3618 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3619 "<td><i>" . $author . "</i></td>\n" .
3621 # originally git_history used chop_str($co{'title'}, 50)
3622 print format_subject_html
($co{'title'}, $co{'title_short'},
3623 href
(action
=>"commit", hash
=>$commit), $ref);
3625 "<td class=\"link\">" .
3626 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3627 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3629 if ($ftype eq 'blob') {
3630 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3631 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3632 if (defined $blob_current && defined $blob_parent &&
3633 $blob_current ne $blob_parent) {
3635 $cgi->a({-href
=> href
(action
=>"blobdiff",
3636 hash
=>$blob_current, hash_parent
=>$blob_parent,
3637 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3638 file_name
=>$file_name)},
3645 if (defined $extra) {
3647 "<td colspan=\"4\">$extra</td>\n" .
3654 # uses global variable $project
3655 my ($taglist, $from, $to, $extra) = @_;
3656 $from = 0 unless defined $from;
3657 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3659 print "<table class=\"tags\">\n";
3661 for (my $i = $from; $i <= $to; $i++) {
3662 my $entry = $taglist->[$i];
3664 my $comment = $tag{'subject'};
3666 if (defined $comment) {
3667 $comment_short = chop_str
($comment, 30, 5);
3670 print "<tr class=\"dark\">\n";
3672 print "<tr class=\"light\">\n";
3675 if (defined $tag{'age'}) {
3676 print "<td><i>$tag{'age'}</i></td>\n";
3678 print "<td></td>\n";
3681 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3682 -class => "list name"}, esc_html
($tag{'name'})) .
3685 if (defined $comment) {
3686 print format_subject_html
($comment, $comment_short,
3687 href
(action
=>"tag", hash
=>$tag{'id'}));
3690 "<td class=\"selflink\">";
3691 if ($tag{'type'} eq "tag") {
3692 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3697 "<td class=\"link\">" . " | " .
3698 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3699 if ($tag{'reftype'} eq "commit") {
3700 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3701 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3702 } elsif ($tag{'reftype'} eq "blob") {
3703 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3708 if (defined $extra) {
3710 "<td colspan=\"5\">$extra</td>\n" .
3716 sub git_heads_body
{
3717 # uses global variable $project
3718 my ($headlist, $head, $from, $to, $extra) = @_;
3719 $from = 0 unless defined $from;
3720 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3722 print "<table class=\"heads\">\n";
3724 for (my $i = $from; $i <= $to; $i++) {
3725 my $entry = $headlist->[$i];
3727 my $curr = $ref{'id'} eq $head;
3729 print "<tr class=\"dark\">\n";
3731 print "<tr class=\"light\">\n";
3734 print "<td><i>$ref{'age'}</i></td>\n" .
3735 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3736 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3737 -class => "list name"},esc_html
($ref{'name'})) .
3739 "<td class=\"link\">" .
3740 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3741 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3742 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3746 if (defined $extra) {
3748 "<td colspan=\"3\">$extra</td>\n" .
3754 sub git_search_grep_body
{
3755 my ($commitlist, $from, $to, $extra) = @_;
3756 $from = 0 unless defined $from;
3757 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3759 print "<table class=\"commit_search\">\n";
3761 for (my $i = $from; $i <= $to; $i++) {
3762 my %co = %{$commitlist->[$i]};
3766 my $commit = $co{'id'};
3768 print "<tr class=\"dark\">\n";
3770 print "<tr class=\"light\">\n";
3773 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3774 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3775 "<td><i>" . $author . "</i></td>\n" .
3777 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3778 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3779 my $comment = $co{'comment'};
3780 foreach my $line (@
$comment) {
3781 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3782 my $lead = esc_html
($1) || "";
3783 $lead = chop_str
($lead, 30, 10);
3784 my $match = esc_html
($2) || "";
3785 my $trail = esc_html
($3) || "";
3786 $trail = chop_str
($trail, 30, 10);
3787 my $text = "$lead<span class=\"match\">$match</span>$trail";
3788 print chop_str
($text, 80, 5) . "<br/>\n";
3792 "<td class=\"link\">" .
3793 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3795 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3797 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3801 if (defined $extra) {
3803 "<td colspan=\"3\">$extra</td>\n" .
3809 ## ======================================================================
3810 ## ======================================================================
3813 sub git_project_list
{
3814 my $order = $cgi->param('o');
3815 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3816 die_error
(undef, "Unknown order parameter");
3819 my @list = git_get_projects_list
();
3821 die_error
(undef, "No projects found");
3825 if (-f
$home_text) {
3826 print "<div class=\"index_include\">\n";
3827 open (my $fd, $home_text);
3832 git_project_list_body
(\
@list, $order);
3837 my $order = $cgi->param('o');
3838 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3839 die_error
(undef, "Unknown order parameter");
3842 my @list = git_get_projects_list
($project);
3844 die_error
(undef, "No forks found");
3848 git_print_page_nav
('','');
3849 git_print_header_div
('summary', "$project forks");
3850 git_project_list_body
(\
@list, $order);
3854 sub git_project_index
{
3855 my @projects = git_get_projects_list
($project);
3858 -type
=> 'text/plain',
3859 -charset
=> 'utf-8',
3860 -content_disposition
=> 'inline; filename="index.aux"');
3862 foreach my $pr (@projects) {
3863 if (!exists $pr->{'owner'}) {
3864 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3867 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3868 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3869 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3870 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3874 print "$path $owner\n";
3879 my $descr = git_get_project_description
($project) || "none";
3880 my %co = parse_commit
("HEAD");
3881 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3882 my $head = $co{'id'};
3884 my $owner = git_get_project_owner
($project);
3886 my $refs = git_get_references
();
3887 # These get_*_list functions return one more to allow us to see if
3888 # there are more ...
3889 my @taglist = git_get_tags_list
(16);
3890 my @headlist = git_get_heads_list
(16);
3892 my ($check_forks) = gitweb_check_feature
('forks');
3895 @forklist = git_get_projects_list
($project);
3899 git_print_page_nav
('summary','', $head);
3901 print "<div class=\"title\"> </div>\n";
3902 print "<table class=\"projects_list\">\n" .
3903 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3904 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3905 if (defined $cd{'rfc2822'}) {
3906 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3909 # use per project git URL list in $projectroot/$project/cloneurl
3910 # or make project git URL from git base URL and project name
3911 my $url_tag = "URL";
3912 my @url_list = git_get_project_url_list
($project);
3913 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3914 foreach my $git_url (@url_list) {
3915 next unless $git_url;
3916 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3921 if (-s
"$projectroot/$project/README.html") {
3922 if (open my $fd, "$projectroot/$project/README.html") {
3923 print "<div class=\"title\">readme</div>\n" .
3924 "<div class=\"readme\">\n";
3925 print $_ while (<$fd>);
3926 print "\n</div>\n"; # class="readme"
3931 # we need to request one more than 16 (0..15) to check if
3933 my @commitlist = $head ? parse_commits
($head, 17) : ();
3935 git_print_header_div
('shortlog');
3936 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3937 $#commitlist <= 15 ?
undef :
3938 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3942 git_print_header_div
('tags');
3943 git_tags_body
(\
@taglist, 0, 15,
3944 $#taglist <= 15 ?
undef :
3945 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3949 git_print_header_div
('heads');
3950 git_heads_body
(\
@headlist, $head, 0, 15,
3951 $#headlist <= 15 ?
undef :
3952 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3956 git_print_header_div
('forks');
3957 git_project_list_body
(\
@forklist, undef, 0, 15,
3958 $#forklist <= 15 ?
undef :
3959 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3967 my $head = git_get_head_hash
($project);
3969 git_print_page_nav
('','', $head,undef,$head);
3970 my %tag = parse_tag
($hash);
3973 die_error
(undef, "Unknown tag object");
3976 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3977 print "<div class=\"title_text\">\n" .
3978 "<table class=\"object_header\">\n" .
3980 "<td>object</td>\n" .
3981 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3982 $tag{'object'}) . "</td>\n" .
3983 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3984 $tag{'type'}) . "</td>\n" .
3986 if (defined($tag{'author'})) {
3987 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3988 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3989 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3990 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3993 print "</table>\n\n" .
3995 print "<div class=\"page_body\">";
3996 my $comment = $tag{'comment'};
3997 foreach my $line (@
$comment) {
3999 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4009 my ($have_blame) = gitweb_check_feature
('blame');
4011 die_error
('403 Permission denied', "Permission denied");
4013 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4014 $hash_base ||= git_get_head_hash
($project);
4015 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4016 my %co = parse_commit
($hash_base)
4017 or die_error
(undef, "Reading commit failed");
4018 if (!defined $hash) {
4019 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4020 or die_error
(undef, "Error looking up file");
4022 $ftype = git_get_type
($hash);
4023 if ($ftype !~ "blob") {
4024 die_error
('400 Bad Request', "Object is not a blob");
4026 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4027 $file_name, $hash_base)
4028 or die_error
(undef, "Open git-blame failed");
4031 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4034 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4037 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4039 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4040 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4041 git_print_page_path
($file_name, $ftype, $hash_base);
4042 my @rev_color = (qw(light2 dark2));
4043 my $num_colors = scalar(@rev_color);
4044 my $current_color = 0;
4047 <div class="page_body">
4048 <table class="blame">
4049 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4054 last unless defined $_;
4055 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4056 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4057 if (!exists $metainfo{$full_rev}) {
4058 $metainfo{$full_rev} = {};
4060 my $meta = $metainfo{$full_rev};
4063 if (/^(\S+) (.*)$/) {
4069 my $rev = substr($full_rev, 0, 8);
4070 my $author = $meta->{'author'};
4071 my %date = parse_date
($meta->{'author-time'},
4072 $meta->{'author-tz'});
4073 my $date = $date{'iso-tz'};
4075 $current_color = ++$current_color % $num_colors;
4077 print "<tr class=\"$rev_color[$current_color]\">\n";
4079 print "<td class=\"sha1\"";
4080 print " title=\"". esc_html
($author) . ", $date\"";
4081 print " rowspan=\"$group_size\"" if ($group_size > 1);
4083 print $cgi->a({-href
=> href
(action
=>"commit",
4085 file_name
=>$file_name)},
4089 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4090 or die_error
(undef, "Open git-rev-parse failed");
4091 my $parent_commit = <$dd>;
4093 chomp($parent_commit);
4094 my $blamed = href
(action
=> 'blame',
4095 file_name
=> $meta->{'filename'},
4096 hash_base
=> $parent_commit);
4097 print "<td class=\"linenr\">";
4098 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4100 -class => "linenr" },
4103 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4109 or print "Reading blob failed\n";
4116 my ($have_blame) = gitweb_check_feature
('blame');
4118 die_error
('403 Permission denied', "Permission denied");
4120 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4121 $hash_base ||= git_get_head_hash
($project);
4122 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4123 my %co = parse_commit
($hash_base)
4124 or die_error
(undef, "Reading commit failed");
4125 if (!defined $hash) {
4126 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4127 or die_error
(undef, "Error lookup file");
4129 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4130 or die_error
(undef, "Open git-annotate failed");
4133 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4136 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4139 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
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);
4143 git_print_page_path
($file_name, 'blob', $hash_base);
4144 print "<div class=\"page_body\">\n";
4146 <table class="blame">
4155 my @line_class = (qw(light dark));
4156 my $line_class_len = scalar (@line_class);
4157 my $line_class_num = $#line_class;
4158 while (my $line = <$fd>) {
4170 $line_class_num = ($line_class_num + 1) % $line_class_len;
4172 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4179 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4182 $short_rev = substr ($long_rev, 0, 8);
4183 $age = time () - $time;
4184 $age_str = age_string
($age);
4185 $age_str =~ s/ / /g;
4186 $age_class = age_class
($age);
4187 $author = esc_html
($author);
4188 $author =~ s/ / /g;
4190 $data = untabify
($data);
4191 $data = esc_html
($data);
4194 <tr class="$line_class[$line_class_num]">
4195 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4196 <td class="$age_class">$age_str</td>
4198 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4199 <td class="pre">$data</td>
4202 } # while (my $line = <$fd>)
4203 print "</table>\n\n";
4205 or print "Reading blob failed.\n";
4211 my $head = git_get_head_hash
($project);
4213 git_print_page_nav
('','', $head,undef,$head);
4214 git_print_header_div
('summary', $project);
4216 my @tagslist = git_get_tags_list
();
4218 git_tags_body
(\
@tagslist);
4224 my $head = git_get_head_hash
($project);
4226 git_print_page_nav
('','', $head,undef,$head);
4227 git_print_header_div
('summary', $project);
4229 my @headslist = git_get_heads_list
();
4231 git_heads_body
(\
@headslist, $head);
4236 sub git_blob_plain
{
4239 if (!defined $hash) {
4240 if (defined $file_name) {
4241 my $base = $hash_base || git_get_head_hash
($project);
4242 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4243 or die_error
(undef, "Error lookup file");
4245 die_error
(undef, "No file name defined");
4247 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4248 # blobs defined by non-textual hash id's can be cached
4253 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4254 or die_error
(undef, "Couldn't cat $file_name, $hash");
4256 $type ||= blob_mimetype
($fd, $file_name);
4258 # save as filename, even when no $file_name is given
4259 my $save_as = "$hash";
4260 if (defined $file_name) {
4261 $save_as = $file_name;
4262 } elsif ($type =~ m/^text\//) {
4269 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4271 binmode STDOUT
, ':raw';
4273 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4281 if (!defined $hash) {
4282 if (defined $file_name) {
4283 my $base = $hash_base || git_get_head_hash
($project);
4284 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4285 or die_error
(undef, "Error lookup file");
4287 die_error
(undef, "No file name defined");
4289 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4290 # blobs defined by non-textual hash id's can be cached
4294 my ($have_blame) = gitweb_check_feature
('blame');
4295 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4296 or die_error
(undef, "Couldn't cat $file_name, $hash");
4297 my $mimetype = blob_mimetype
($fd, $file_name);
4298 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4300 return git_blob_plain
($mimetype);
4302 # we can have blame only for text/* mimetype
4303 $have_blame &&= ($mimetype =~ m!^text/!);
4305 git_header_html
(undef, $expires);
4306 my $formats_nav = '';
4307 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4308 if (defined $file_name) {
4311 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4316 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4319 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4322 $cgi->a({-href
=> href
(action
=>"blob",
4323 hash_base
=>"HEAD", file_name
=>$file_name)},
4327 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4330 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4331 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4333 print "<div class=\"page_nav\">\n" .
4334 "<br/><br/></div>\n" .
4335 "<div class=\"title\">$hash</div>\n";
4337 git_print_page_path
($file_name, "blob", $hash_base);
4338 print "<div class=\"page_body\">\n";
4339 if ($mimetype =~ m!^image/!) {
4340 print qq!<img type
="$mimetype"!;
4342 print qq! alt
="$file_name" title
="$file_name"!;
4345 href(action=>"blob_plain
", hash=>$hash,
4346 hash_base=>$hash_base, file_name=>$file_name) .
4350 while (my $line = <$fd>) {
4353 $line = untabify
($line);
4354 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4355 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4359 or print "Reading blob failed.\n";
4365 if (!defined $hash_base) {
4366 $hash_base = "HEAD";
4368 if (!defined $hash) {
4369 if (defined $file_name) {
4370 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4376 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4377 or die_error
(undef, "Open git-ls-tree failed");
4378 my @entries = map { chomp; $_ } <$fd>;
4379 close $fd or die_error
(undef, "Reading tree failed");
4382 my $refs = git_get_references
();
4383 my $ref = format_ref_marker
($refs, $hash_base);
4386 my ($have_blame) = gitweb_check_feature
('blame');
4387 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4389 if (defined $file_name) {
4391 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4393 $cgi->a({-href
=> href
(action
=>"tree",
4394 hash_base
=>"HEAD", file_name
=>$file_name)},
4397 my $snapshot_links = format_snapshot_links
($hash);
4398 if (defined $snapshot_links) {
4399 # FIXME: Should be available when we have no hash base as well.
4400 push @views_nav, $snapshot_links;
4402 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4403 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4406 print "<div class=\"page_nav\">\n";
4407 print "<br/><br/></div>\n";
4408 print "<div class=\"title\">$hash</div>\n";
4410 if (defined $file_name) {
4411 $basedir = $file_name;
4412 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4416 git_print_page_path
($file_name, 'tree', $hash_base);
4417 print "<div class=\"page_body\">\n";
4418 print "<table class=\"tree\">\n";
4420 # '..' (top directory) link if possible
4421 if (defined $hash_base &&
4422 defined $file_name && $file_name =~ m![^/]+$!) {
4424 print "<tr class=\"dark\">\n";
4426 print "<tr class=\"light\">\n";
4430 my $up = $file_name;
4431 $up =~ s!/?[^/]+$!!;
4432 undef $up unless $up;
4433 # based on git_print_tree_entry
4434 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4435 print '<td class="list">';
4436 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4440 print "<td class=\"link\"></td>\n";
4444 foreach my $line (@entries) {
4445 my %t = parse_ls_tree_line
($line, -z
=> 1);
4448 print "<tr class=\"dark\">\n";
4450 print "<tr class=\"light\">\n";
4454 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4458 print "</table>\n" .
4464 my @supported_fmts = gitweb_check_feature
('snapshot');
4465 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4467 my $format = $cgi->param('sf');
4468 if (!@supported_fmts) {
4469 die_error
('403 Permission denied', "Permission denied");
4471 # default to first supported snapshot format
4472 $format ||= $supported_fmts[0];
4473 if ($format !~ m/^[a-z0-9]+$/) {
4474 die_error
(undef, "Invalid snapshot format parameter");
4475 } elsif (!exists($known_snapshot_formats{$format})) {
4476 die_error
(undef, "Unknown snapshot format");
4477 } elsif (!grep($_ eq $format, @supported_fmts)) {
4478 die_error
(undef, "Unsupported snapshot format");
4481 if (!defined $hash) {
4482 $hash = git_get_head_hash
($project);
4485 my $git_command = git_cmd_str
();
4486 my $name = $project;
4487 $name =~ s
,([^/])/*\
.git
$,$1,;
4488 $name = basename
($name);
4489 my $filename = to_utf8
($name);
4490 $name =~ s/\047/\047\\\047\047/g;
4492 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4493 $cmd = "$git_command archive " .
4494 "--format=$known_snapshot_formats{$format}{'format'} " .
4495 "--prefix=\'$name\'/ $hash";
4496 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4497 $cmd .= ' | ' . join ' ', @
{$known_snapshot_formats{$format}{'compressor'}};
4501 -type
=> $known_snapshot_formats{$format}{'type'},
4502 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4503 -status
=> '200 OK');
4505 open my $fd, "-|", $cmd
4506 or die_error
(undef, "Execute git-archive failed");
4507 binmode STDOUT
, ':raw';
4509 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4514 my $head = git_get_head_hash
($project);
4515 if (!defined $hash) {
4518 if (!defined $page) {
4521 my $refs = git_get_references
();
4523 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4525 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4528 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4531 my %co = parse_commit
($hash);
4533 git_print_header_div
('summary', $project);
4534 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4536 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4537 for (my $i = 0; $i <= $to; $i++) {
4538 my %co = %{$commitlist[$i]};
4540 my $commit = $co{'id'};
4541 my $ref = format_ref_marker
($refs, $commit);
4542 my %ad = parse_date
($co{'author_epoch'});
4543 git_print_header_div
('commit',
4544 "<span class=\"age\">$co{'age_string'}</span>" .
4545 esc_html
($co{'title'}) . $ref,
4547 print "<div class=\"title_text\">\n" .
4548 "<div class=\"log_link\">\n" .
4549 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4551 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4553 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4556 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4559 print "<div class=\"log_body\">\n";
4560 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4563 if ($#commitlist >= 100) {
4564 print "<div class=\"page_nav\">\n";
4565 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4566 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4573 $hash ||= $hash_base || "HEAD";
4574 my %co = parse_commit
($hash);
4576 die_error
(undef, "Unknown commit object");
4578 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4579 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4581 my $parent = $co{'parent'};
4582 my $parents = $co{'parents'}; # listref
4584 # we need to prepare $formats_nav before any parameter munging
4586 if (!defined $parent) {
4588 $formats_nav .= '(initial)';
4589 } elsif (@
$parents == 1) {
4590 # single parent commit
4593 $cgi->a({-href
=> href
(action
=>"commit",
4595 esc_html
(substr($parent, 0, 7))) .
4602 $cgi->a({-href
=> href
(action
=>"commit",
4604 esc_html
(substr($_, 0, 7)));
4609 if (!defined $parent) {
4613 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4615 (@
$parents <= 1 ?
$parent : '-c'),
4617 or die_error
(undef, "Open git-diff-tree failed");
4618 @difftree = map { chomp; $_ } <$fd>;
4619 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4621 # non-textual hash id's can be cached
4623 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4626 my $refs = git_get_references
();
4627 my $ref = format_ref_marker
($refs, $co{'id'});
4629 git_header_html
(undef, $expires);
4630 git_print_page_nav
('commit', '',
4631 $hash, $co{'tree'}, $hash,
4634 if (defined $co{'parent'}) {
4635 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4637 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4639 print "<div class=\"title_text\">\n" .
4640 "<table class=\"object_header\">\n";
4641 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4643 "<td></td><td> $ad{'rfc2822'}";
4644 if ($ad{'hour_local'} < 6) {
4645 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4646 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4648 printf(" (%02d:%02d %s)",
4649 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4653 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4654 print "<tr><td></td><td> $cd{'rfc2822'}" .
4655 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4657 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4660 "<td class=\"sha1\">" .
4661 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4662 class => "list"}, $co{'tree'}) .
4664 "<td class=\"link\">" .
4665 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4667 my $snapshot_links = format_snapshot_links
($hash);
4668 if (defined $snapshot_links) {
4669 print " | " . $snapshot_links;
4674 foreach my $par (@
$parents) {
4677 "<td class=\"sha1\">" .
4678 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4679 class => "list"}, $par) .
4681 "<td class=\"link\">" .
4682 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4684 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4691 print "<div class=\"page_body\">\n";
4692 git_print_log
($co{'comment'});
4695 git_difftree_body
(\
@difftree, $hash, @
$parents);
4701 # object is defined by:
4702 # - hash or hash_base alone
4703 # - hash_base and file_name
4706 # - hash or hash_base alone
4707 if ($hash || ($hash_base && !defined $file_name)) {
4708 my $object_id = $hash || $hash_base;
4710 my $git_command = git_cmd_str
();
4711 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4712 or die_error
('404 Not Found', "Object does not exist");
4716 or die_error
('404 Not Found', "Object does not exist");
4718 # - hash_base and file_name
4719 } elsif ($hash_base && defined $file_name) {
4720 $file_name =~ s
,/+$,,;
4722 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4723 or die_error
('404 Not Found', "Base object does not exist");
4725 # here errors should not hapen
4726 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4727 or die_error
(undef, "Open git-ls-tree failed");
4731 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4732 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4733 die_error
('404 Not Found', "File or directory for given base does not exist");
4738 die_error
('404 Not Found', "Not enough information to find object");
4741 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4742 hash
=>$hash, hash_base
=>$hash_base,
4743 file_name
=>$file_name),
4744 -status
=> '302 Found');
4748 my $format = shift || 'html';
4755 # preparing $fd and %diffinfo for git_patchset_body
4757 if (defined $hash_base && defined $hash_parent_base) {
4758 if (defined $file_name) {
4760 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4761 $hash_parent_base, $hash_base,
4762 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4763 or die_error
(undef, "Open git-diff-tree failed");
4764 @difftree = map { chomp; $_ } <$fd>;
4766 or die_error
(undef, "Reading git-diff-tree failed");
4768 or die_error
('404 Not Found', "Blob diff not found");
4770 } elsif (defined $hash &&
4771 $hash =~ /[0-9a-fA-F]{40}/) {
4772 # try to find filename from $hash
4774 # read filtered raw output
4775 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4776 $hash_parent_base, $hash_base, "--"
4777 or die_error
(undef, "Open git-diff-tree failed");
4779 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4781 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4782 map { chomp; $_ } <$fd>;
4784 or die_error
(undef, "Reading git-diff-tree failed");
4786 or die_error
('404 Not Found', "Blob diff not found");
4789 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4792 if (@difftree > 1) {
4793 die_error
('404 Not Found', "Ambiguous blob diff specification");
4796 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4797 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4798 $file_name ||= $diffinfo{'to_file'};
4800 $hash_parent ||= $diffinfo{'from_id'};
4801 $hash ||= $diffinfo{'to_id'};
4803 # non-textual hash id's can be cached
4804 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4805 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4810 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4811 '-p', ($format eq 'html' ?
"--full-index" : ()),
4812 $hash_parent_base, $hash_base,
4813 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4814 or die_error
(undef, "Open git-diff-tree failed");
4817 # old/legacy style URI
4818 if (!%diffinfo && # if new style URI failed
4819 defined $hash && defined $hash_parent) {
4820 # fake git-diff-tree raw output
4821 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4822 $diffinfo{'from_id'} = $hash_parent;
4823 $diffinfo{'to_id'} = $hash;
4824 if (defined $file_name) {
4825 if (defined $file_parent) {
4826 $diffinfo{'status'} = '2';
4827 $diffinfo{'from_file'} = $file_parent;
4828 $diffinfo{'to_file'} = $file_name;
4829 } else { # assume not renamed
4830 $diffinfo{'status'} = '1';
4831 $diffinfo{'from_file'} = $file_name;
4832 $diffinfo{'to_file'} = $file_name;
4834 } else { # no filename given
4835 $diffinfo{'status'} = '2';
4836 $diffinfo{'from_file'} = $hash_parent;
4837 $diffinfo{'to_file'} = $hash;
4840 # non-textual hash id's can be cached
4841 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4842 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4847 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4848 '-p', ($format eq 'html' ?
"--full-index" : ()),
4849 $hash_parent, $hash, "--"
4850 or die_error
(undef, "Open git-diff failed");
4852 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4857 if ($format eq 'html') {
4859 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4861 git_header_html
(undef, $expires);
4862 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4863 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4864 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4866 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4867 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4869 if (defined $file_name) {
4870 git_print_page_path
($file_name, "blob", $hash_base);
4872 print "<div class=\"page_path\"></div>\n";
4875 } elsif ($format eq 'plain') {
4877 -type
=> 'text/plain',
4878 -charset
=> 'utf-8',
4879 -expires
=> $expires,
4880 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4882 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4885 die_error
(undef, "Unknown blobdiff format");
4889 if ($format eq 'html') {
4890 print "<div class=\"page_body\">\n";
4892 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4895 print "</div>\n"; # class="page_body"
4899 while (my $line = <$fd>) {
4900 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4901 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4905 last if $line =~ m!^\+\+\+!;
4913 sub git_blobdiff_plain
{
4914 git_blobdiff
('plain');
4917 sub git_commitdiff
{
4918 my $format = shift || 'html';
4919 $hash ||= $hash_base || "HEAD";
4920 my %co = parse_commit
($hash);
4922 die_error
(undef, "Unknown commit object");
4925 # choose format for commitdiff for merge
4926 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4927 $hash_parent = '--cc';
4929 # we need to prepare $formats_nav before almost any parameter munging
4931 if ($format eq 'html') {
4933 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4936 if (defined $hash_parent &&
4937 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4938 # commitdiff with two commits given
4939 my $hash_parent_short = $hash_parent;
4940 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4941 $hash_parent_short = substr($hash_parent, 0, 7);
4945 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4946 if ($co{'parents'}[$i] eq $hash_parent) {
4947 $formats_nav .= ' parent ' . ($i+1);
4951 $formats_nav .= ': ' .
4952 $cgi->a({-href
=> href
(action
=>"commitdiff",
4953 hash
=>$hash_parent)},
4954 esc_html
($hash_parent_short)) .
4956 } elsif (!$co{'parent'}) {
4958 $formats_nav .= ' (initial)';
4959 } elsif (scalar @
{$co{'parents'}} == 1) {
4960 # single parent commit
4963 $cgi->a({-href
=> href
(action
=>"commitdiff",
4964 hash
=>$co{'parent'})},
4965 esc_html
(substr($co{'parent'}, 0, 7))) .
4969 if ($hash_parent eq '--cc') {
4970 $formats_nav .= ' | ' .
4971 $cgi->a({-href
=> href
(action
=>"commitdiff",
4972 hash
=>$hash, hash_parent
=>'-c')},
4974 } else { # $hash_parent eq '-c'
4975 $formats_nav .= ' | ' .
4976 $cgi->a({-href
=> href
(action
=>"commitdiff",
4977 hash
=>$hash, hash_parent
=>'--cc')},
4983 $cgi->a({-href
=> href
(action
=>"commitdiff",
4985 esc_html
(substr($_, 0, 7)));
4986 } @
{$co{'parents'}} ) .
4991 my $hash_parent_param = $hash_parent;
4992 if (!defined $hash_parent_param) {
4993 # --cc for multiple parents, --root for parentless
4994 $hash_parent_param =
4995 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5001 if ($format eq 'html') {
5002 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5003 "--no-commit-id", "--patch-with-raw", "--full-index",
5004 $hash_parent_param, $hash, "--"
5005 or die_error
(undef, "Open git-diff-tree failed");
5007 while (my $line = <$fd>) {
5009 # empty line ends raw part of diff-tree output
5011 push @difftree, scalar parse_difftree_raw_line
($line);
5014 } elsif ($format eq 'plain') {
5015 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5016 '-p', $hash_parent_param, $hash, "--"
5017 or die_error
(undef, "Open git-diff-tree failed");
5020 die_error
(undef, "Unknown commitdiff format");
5023 # non-textual hash id's can be cached
5025 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5029 # write commit message
5030 if ($format eq 'html') {
5031 my $refs = git_get_references
();
5032 my $ref = format_ref_marker
($refs, $co{'id'});
5034 git_header_html
(undef, $expires);
5035 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5036 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5037 git_print_authorship
(\
%co);
5038 print "<div class=\"page_body\">\n";
5039 if (@
{$co{'comment'}} > 1) {
5040 print "<div class=\"log\">\n";
5041 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5042 print "</div>\n"; # class="log"
5045 } elsif ($format eq 'plain') {
5046 my $refs = git_get_references
("tags");
5047 my $tagname = git_get_rev_name_tags
($hash);
5048 my $filename = basename
($project) . "-$hash.patch";
5051 -type
=> 'text/plain',
5052 -charset
=> 'utf-8',
5053 -expires
=> $expires,
5054 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5055 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5056 print "From: " . to_utf8
($co{'author'}) . "\n";
5057 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5058 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5060 print "X-Git-Tag: $tagname\n" if $tagname;
5061 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5063 foreach my $line (@
{$co{'comment'}}) {
5064 print to_utf8
($line) . "\n";
5070 if ($format eq 'html') {
5071 my $use_parents = !defined $hash_parent ||
5072 $hash_parent eq '-c' || $hash_parent eq '--cc';
5073 git_difftree_body
(\
@difftree, $hash,
5074 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5077 git_patchset_body
($fd, \
@difftree, $hash,
5078 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5080 print "</div>\n"; # class="page_body"
5083 } elsif ($format eq 'plain') {
5087 or print "Reading git-diff-tree failed\n";
5091 sub git_commitdiff_plain
{
5092 git_commitdiff
('plain');
5096 if (!defined $hash_base) {
5097 $hash_base = git_get_head_hash
($project);
5099 if (!defined $page) {
5103 my %co = parse_commit
($hash_base);
5105 die_error
(undef, "Unknown commit object");
5108 my $refs = git_get_references
();
5109 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5111 if (!defined $hash && defined $file_name) {
5112 $hash = git_get_hash_by_path
($hash_base, $file_name);
5114 if (defined $hash) {
5115 $ftype = git_get_type
($hash);
5118 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
5120 my $paging_nav = '';
5123 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5124 file_name
=>$file_name)},
5126 $paging_nav .= " ⋅ " .
5127 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5128 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5130 $paging_nav .= "first";
5131 $paging_nav .= " ⋅ prev";
5134 if ($#commitlist >= 100) {
5136 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5137 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5138 $paging_nav .= " ⋅ $next_link";
5140 $paging_nav .= " ⋅ next";
5144 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5145 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5146 git_print_page_path
($file_name, $ftype, $hash_base);
5148 git_history_body
(\
@commitlist, 0, 99,
5149 $refs, $hash_base, $ftype, $next_link);
5155 my ($have_search) = gitweb_check_feature
('search');
5156 if (!$have_search) {
5157 die_error
('403 Permission denied', "Permission denied");
5159 if (!defined $searchtext) {
5160 die_error
(undef, "Text field empty");
5162 if (!defined $hash) {
5163 $hash = git_get_head_hash
($project);
5165 my %co = parse_commit
($hash);
5167 die_error
(undef, "Unknown commit object");
5169 if (!defined $page) {
5173 $searchtype ||= 'commit';
5174 if ($searchtype eq 'pickaxe') {
5175 # pickaxe may take all resources of your box and run for several minutes
5176 # with every query - so decide by yourself how public you make this feature
5177 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5178 if (!$have_pickaxe) {
5179 die_error
('403 Permission denied', "Permission denied");
5182 if ($searchtype eq 'grep') {
5183 my ($have_grep) = gitweb_check_feature
('grep');
5185 die_error
('403 Permission denied', "Permission denied");
5191 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5193 if ($searchtype eq 'commit') {
5194 $greptype = "--grep=";
5195 } elsif ($searchtype eq 'author') {
5196 $greptype = "--author=";
5197 } elsif ($searchtype eq 'committer') {
5198 $greptype = "--committer=";
5200 $greptype .= $search_regexp;
5201 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
5203 my $paging_nav = '';
5206 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5207 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5209 $paging_nav .= " ⋅ " .
5210 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5211 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5213 $paging_nav .= "first";
5214 $paging_nav .= " ⋅ prev";
5217 if ($#commitlist >= 100) {
5219 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5220 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5221 $paging_nav .= " ⋅ $next_link";
5223 $paging_nav .= " ⋅ next";
5226 if ($#commitlist >= 100) {
5229 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5230 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5231 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5234 if ($searchtype eq 'pickaxe') {
5235 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5236 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5238 print "<table class=\"pickaxe search\">\n";
5241 my $git_command = git_cmd_str
();
5242 my $searchqtext = $searchtext;
5243 $searchqtext =~ s/'/'\\''/;
5244 open my $fd, "-|", "$git_command rev-list $hash | " .
5245 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5248 while (my $line = <$fd>) {
5249 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5252 $set{'from_id'} = $3;
5254 $set{'id'} = $set{'to_id'};
5255 if ($set{'id'} =~ m/0{40}/) {
5256 $set{'id'} = $set{'from_id'};
5258 if ($set{'id'} =~ m/0{40}/) {
5262 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5265 print "<tr class=\"dark\">\n";
5267 print "<tr class=\"light\">\n";
5270 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5271 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5272 "<td><i>" . $author . "</i></td>\n" .
5274 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5275 -class => "list subject"},
5276 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5277 while (my $setref = shift @files) {
5279 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5280 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5282 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5286 "<td class=\"link\">" .
5287 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5289 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5293 %co = parse_commit
($1);
5301 if ($searchtype eq 'grep') {
5302 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5303 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5305 print "<table class=\"grep_search\">\n";
5309 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5311 while (my $line = <$fd>) {
5313 my ($file, $lno, $ltext, $binary);
5314 last if ($matches++ > 1000);
5315 if ($line =~ /^Binary file (.+) matches$/) {
5319 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5321 if ($file ne $lastfile) {
5322 $lastfile and print "</td></tr>\n";
5324 print "<tr class=\"dark\">\n";
5326 print "<tr class=\"light\">\n";
5328 print "<td class=\"list\">".
5329 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5330 file_name
=>"$file"),
5331 -class => "list"}, esc_path
($file));
5332 print "</td><td>\n";
5336 print "<div class=\"binary\">Binary file</div>\n";
5338 $ltext = untabify
($ltext);
5339 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5340 $ltext = esc_html
($1, -nbsp
=>1);
5341 $ltext .= '<span class="match">';
5342 $ltext .= esc_html
($2, -nbsp
=>1);
5343 $ltext .= '</span>';
5344 $ltext .= esc_html
($3, -nbsp
=>1);
5346 $ltext = esc_html
($ltext, -nbsp
=>1);
5348 print "<div class=\"pre\">" .
5349 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5350 file_name
=>"$file").'#l'.$lno,
5351 -class => "linenr"}, sprintf('%4i', $lno))
5352 . ' ' . $ltext . "</div>\n";
5356 print "</td></tr>\n";
5357 if ($matches > 1000) {
5358 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5361 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5370 sub git_search_help
{
5372 git_print_page_nav
('','', $hash,$hash,$hash);
5375 <dt><b>commit</b></dt>
5376 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5378 my ($have_grep) = gitweb_check_feature
('grep');
5381 <dt><b>grep</b></dt>
5382 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5383 a different one) are searched for the given
5384 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5385 (POSIX extended) and the matches are listed. On large
5386 trees, this search can take a while and put some strain on the server, so please use it with
5387 some consideration.</dd>
5391 <dt><b>author</b></dt>
5392 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5393 <dt><b>committer</b></dt>
5394 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5396 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5397 if ($have_pickaxe) {
5399 <dt><b>pickaxe</b></dt>
5400 <dd>All commits that caused the string to appear or disappear from any file (changes that
5401 added, removed or "modified" the string) will be listed. This search can take a while and
5402 takes a lot of strain on the server, so please use it wisely.</dd>
5410 my $head = git_get_head_hash
($project);
5411 if (!defined $hash) {
5414 if (!defined $page) {
5417 my $refs = git_get_references
();
5419 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5421 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5423 if ($#commitlist >= 100) {
5425 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5426 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5430 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5431 git_print_header_div
('summary', $project);
5433 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5438 ## ......................................................................
5439 ## feeds (RSS, Atom; OPML)
5442 my $format = shift || 'atom';
5443 my ($have_blame) = gitweb_check_feature
('blame');
5445 # Atom: http://www.atomenabled.org/developers/syndication/
5446 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5447 if ($format ne 'rss' && $format ne 'atom') {
5448 die_error
(undef, "Unknown web feed format");
5451 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5452 my $head = $hash || 'HEAD';
5453 my @commitlist = parse_commits
($head, 150, 0, undef, $file_name);
5457 my $content_type = "application/$format+xml";
5458 if (defined $cgi->http('HTTP_ACCEPT') &&
5459 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5460 # browser (feed reader) prefers text/xml
5461 $content_type = 'text/xml';
5463 if (defined($commitlist[0])) {
5464 %latest_commit = %{$commitlist[0]};
5465 %latest_date = parse_date
($latest_commit{'author_epoch'});
5467 -type
=> $content_type,
5468 -charset
=> 'utf-8',
5469 -last_modified
=> $latest_date{'rfc2822'});
5472 -type
=> $content_type,
5473 -charset
=> 'utf-8');
5476 # Optimization: skip generating the body if client asks only
5477 # for Last-Modified date.
5478 return if ($cgi->request_method() eq 'HEAD');
5481 my $title = "$site_name - $project/$action";
5482 my $feed_type = 'log';
5483 if (defined $hash) {
5484 $title .= " - '$hash'";
5485 $feed_type = 'branch log';
5486 if (defined $file_name) {
5487 $title .= " :: $file_name";
5488 $feed_type = 'history';
5490 } elsif (defined $file_name) {
5491 $title .= " - $file_name";
5492 $feed_type = 'history';
5494 $title .= " $feed_type";
5495 my $descr = git_get_project_description
($project);
5496 if (defined $descr) {
5497 $descr = esc_html
($descr);
5499 $descr = "$project " .
5500 ($format eq 'rss' ?
'RSS' : 'Atom') .
5503 my $owner = git_get_project_owner
($project);
5504 $owner = esc_html
($owner);
5508 if (defined $file_name) {
5509 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5510 } elsif (defined $hash) {
5511 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5513 $alt_url = href
(-full
=>1, action
=>"summary");
5515 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5516 if ($format eq 'rss') {
5518 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5521 print "<title>$title</title>\n" .
5522 "<link>$alt_url</link>\n" .
5523 "<description>$descr</description>\n" .
5524 "<language>en</language>\n";
5525 } elsif ($format eq 'atom') {
5527 <feed xmlns="http://www.w3.org/2005/Atom">
5529 print "<title>$title</title>\n" .
5530 "<subtitle>$descr</subtitle>\n" .
5531 '<link rel="alternate" type="text/html" href="' .
5532 $alt_url . '" />' . "\n" .
5533 '<link rel="self" type="' . $content_type . '" href="' .
5534 $cgi->self_url() . '" />' . "\n" .
5535 "<id>" . href
(-full
=>1) . "</id>\n" .
5536 # use project owner for feed author
5537 "<author><name>$owner</name></author>\n";
5538 if (defined $favicon) {
5539 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5541 if (defined $logo_url) {
5542 # not twice as wide as tall: 72 x 27 pixels
5543 print "<logo>" . esc_url
($logo) . "</logo>\n";
5545 if (! %latest_date) {
5546 # dummy date to keep the feed valid until commits trickle in:
5547 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5549 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5554 for (my $i = 0; $i <= $#commitlist; $i++) {
5555 my %co = %{$commitlist[$i]};
5556 my $commit = $co{'id'};
5557 # we read 150, we always show 30 and the ones more recent than 48 hours
5558 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5561 my %cd = parse_date
($co{'author_epoch'});
5563 # get list of changed files
5564 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5565 $co{'parent'} || "--root",
5566 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5568 my @difftree = map { chomp; $_ } <$fd>;
5572 # print element (entry, item)
5573 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5574 if ($format eq 'rss') {
5576 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5577 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5578 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5579 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5580 "<link>$co_url</link>\n" .
5581 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5582 "<content:encoded>" .
5584 } elsif ($format eq 'atom') {
5586 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5587 "<updated>$cd{'iso-8601'}</updated>\n" .
5589 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5590 if ($co{'author_email'}) {
5591 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5593 print "</author>\n" .
5594 # use committer for contributor
5596 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5597 if ($co{'committer_email'}) {
5598 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5600 print "</contributor>\n" .
5601 "<published>$cd{'iso-8601'}</published>\n" .
5602 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5603 "<id>$co_url</id>\n" .
5604 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5605 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5607 my $comment = $co{'comment'};
5609 foreach my $line (@
$comment) {
5610 $line = esc_html
($line);
5613 print "</pre><ul>\n";
5614 foreach my $difftree_line (@difftree) {
5615 my %difftree = parse_difftree_raw_line
($difftree_line);
5616 next if !$difftree{'from_id'};
5618 my $file = $difftree{'file'} || $difftree{'to_file'};
5622 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5623 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5624 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5625 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5626 -title
=> "diff"}, 'D');
5628 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5629 file_name
=>$file, hash_base
=>$commit),
5630 -title
=> "blame"}, 'B');
5632 # if this is not a feed of a file history
5633 if (!defined $file_name || $file_name ne $file) {
5634 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5635 file_name
=>$file, hash
=>$commit),
5636 -title
=> "history"}, 'H');
5638 $file = esc_path
($file);
5642 if ($format eq 'rss') {
5643 print "</ul>]]>\n" .
5644 "</content:encoded>\n" .
5646 } elsif ($format eq 'atom') {
5647 print "</ul>\n</div>\n" .
5654 if ($format eq 'rss') {
5655 print "</channel>\n</rss>\n";
5656 } elsif ($format eq 'atom') {
5670 my @list = git_get_projects_list
();
5672 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5674 <?xml version="1.0" encoding="utf-8"?>
5675 <opml version="1.0">
5677 <title>$site_name OPML Export</title>
5680 <outline text="git RSS feeds">
5683 foreach my $pr (@list) {
5685 my $head = git_get_head_hash
($proj{'path'});
5686 if (!defined $head) {
5689 $git_dir = "$projectroot/$proj{'path'}";
5690 my %co = parse_commit
($head);
5695 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5696 my $rss = "$my_url?p=$proj{'path'};a=rss";
5697 my $html = "$my_url?p=$proj{'path'};a=summary";
5698 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";