3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
64 # URI of GIT logo (72x27 size)
65 our $logo = "++GITWEB_LOGO++";
66 # URI of GIT favicon, assumed to be image/png type
67 our $favicon = "++GITWEB_FAVICON++";
69 # URI and label (title) of GIT logo link
70 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
71 #our $logo_label = "git documentation";
72 our $logo_url = "http://git.or.cz/";
73 our $logo_label = "git homepage";
75 # source of projects list
76 our $projects_list = "++GITWEB_LIST++";
78 # the width (in characters) of the projects list "Description" column
79 our $projects_list_description_width = 25;
81 # default order of projects list
82 # valid values are none, project, descr, owner, and age
83 our $default_projects_order = "project";
85 # show repository only if this file exists
86 # (only effective if this variable evaluates to true)
87 our $export_ok = "++GITWEB_EXPORT_OK++";
89 # only allow viewing of repositories also shown on the overview page
90 our $strict_export = "++GITWEB_STRICT_EXPORT++";
92 # list of git base URLs used for URL to where fetch project from,
93 # i.e. full URL is "$git_base_url/$project"
94 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
96 # default blob_plain mimetype and default charset for text/plain blob
97 our $default_blob_plain_mimetype = 'text/plain';
98 our $default_text_plain_charset = undef;
100 # file to use for guessing MIME types before trying /etc/mime.types
101 # (relative to the current git repository)
102 our $mimetypes_file = undef;
104 # assume this charset if line contains non-UTF-8 characters;
105 # it should be valid encoding (see Encoding::Supported(3pm) for list),
106 # for which encoding all byte sequences are valid, for example
107 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
108 # could be even 'utf-8' for the old behavior)
109 our $fallback_encoding = 'latin1';
111 # rename detection options for git-diff and git-diff-tree
112 # - default is '-M', with the cost proportional to
113 # (number of removed files) * (number of new files).
114 # - more costly is '-C' (which implies '-M'), with the cost proportional to
115 # (number of changed files + number of removed files) * (number of new files)
116 # - even more costly is '-C', '--find-copies-harder' with cost
117 # (number of files in the original tree) * (number of new files)
118 # - one might want to include '-B' option, e.g. '-B', '-M'
119 our @diff_opts = ('-M'); # taken from git_commit
121 # information about snapshot formats that gitweb is capable of serving
122 our %known_snapshot_formats = (
124 # 'display' => display name,
125 # 'type' => mime type,
126 # 'suffix' => filename suffix,
127 # 'format' => --format for git-archive,
128 # 'compressor' => [compressor command and arguments]
129 # (array reference, optional)}
132 'display' => 'tar.gz',
133 'type' => 'application/x-gzip',
134 'suffix' => '.tar.gz',
136 'compressor' => ['gzip']},
139 'display' => 'tar.bz2',
140 'type' => 'application/x-bzip2',
141 'suffix' => '.tar.bz2',
143 'compressor' => ['bzip2']},
147 'type' => 'application/x-zip',
152 # Aliases so we understand old gitweb.snapshot values in repository
154 our %known_snapshot_format_aliases = (
158 # backward compatibility: legacy gitweb config support
159 'x-gzip' => undef, 'gz' => undef,
160 'x-bzip2' => undef, 'bz2' => undef,
161 'x-zip' => undef, '' => undef,
164 # You define site-wide feature defaults here; override them with
165 # $GITWEB_CONFIG as necessary.
168 # 'sub' => feature-sub (subroutine),
169 # 'override' => allow-override (boolean),
170 # 'default' => [ default options...] (array reference)}
172 # if feature is overridable (it means that allow-override has true value),
173 # then feature-sub will be called with default options as parameters;
174 # return value of feature-sub indicates if to enable specified feature
176 # if there is no 'sub' key (no feature-sub), then feature cannot be
179 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
181 # Enable the 'blame' blob view, showing the last commit that modified
182 # each line in the file. This can be very CPU-intensive.
184 # To enable system wide have in $GITWEB_CONFIG
185 # $feature{'blame'}{'default'} = [1];
186 # To have project specific config enable override in $GITWEB_CONFIG
187 # $feature{'blame'}{'override'} = 1;
188 # and in project config gitweb.blame = 0|1;
190 'sub' => \
&feature_blame
,
194 # Enable the 'snapshot' link, providing a compressed archive of any
195 # tree. This can potentially generate high traffic if you have large
198 # Value is a list of formats defined in %known_snapshot_formats that
200 # To disable system wide have in $GITWEB_CONFIG
201 # $feature{'snapshot'}{'default'} = [];
202 # To have project specific config enable override in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'override'} = 1;
204 # and in project config, a comma-separated list of formats or "none"
205 # to disable. Example: gitweb.snapshot = tbz2,zip;
207 'sub' => \
&feature_snapshot
,
209 'default' => ['tgz']},
211 # Enable text search, which will list the commits which match author,
212 # committer or commit text to a given string. Enabled by default.
213 # Project specific override is not supported.
218 # Enable grep search, which will list the files in currently selected
219 # tree containing the given string. Enabled by default. This can be
220 # potentially CPU-intensive, of course.
222 # To enable system wide have in $GITWEB_CONFIG
223 # $feature{'grep'}{'default'} = [1];
224 # To have project specific config enable override in $GITWEB_CONFIG
225 # $feature{'grep'}{'override'} = 1;
226 # and in project config gitweb.grep = 0|1;
231 # Enable the pickaxe search, which will list the commits that modified
232 # a given string in a file. This can be practical and quite faster
233 # alternative to 'blame', but still potentially CPU-intensive.
235 # To enable system wide have in $GITWEB_CONFIG
236 # $feature{'pickaxe'}{'default'} = [1];
237 # To have project specific config enable override in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'override'} = 1;
239 # and in project config gitweb.pickaxe = 0|1;
241 'sub' => \
&feature_pickaxe
,
245 # Make gitweb use an alternative format of the URLs which can be
246 # more readable and natural-looking: project name is embedded
247 # directly in the path and the query string contains other
248 # auxiliary information. All gitweb installations recognize
249 # URL in either format; this configures in which formats gitweb
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'pathinfo'}{'default'} = [1];
254 # Project specific override is not supported.
256 # Note that you will need to change the default location of CSS,
257 # favicon, logo and possibly other files to an absolute URL. Also,
258 # if gitweb.cgi serves as your indexfile, you will need to force
259 # $my_uri to contain the script name in your $GITWEB_CONFIG.
264 # Make gitweb consider projects in project root subdirectories
265 # to be forks of existing projects. Given project $projname.git,
266 # projects matching $projname/*.git will not be shown in the main
267 # projects list, instead a '+' mark will be added to $projname
268 # there and a 'forks' view will be enabled for the project, listing
269 # all the forks. If project list is taken from a file, forks have
270 # to be listed after the main project.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'forks'}{'default'} = [1];
274 # Project specific override is not supported.
280 sub gitweb_check_feature
{
282 return unless exists $feature{$name};
283 my ($sub, $override, @defaults) = (
284 $feature{$name}{'sub'},
285 $feature{$name}{'override'},
286 @
{$feature{$name}{'default'}});
287 if (!$override) { return @defaults; }
289 warn "feature $name is not overrideable";
292 return $sub->(@defaults);
296 my ($val) = git_get_project_config
('blame', '--bool');
298 if ($val eq 'true') {
300 } elsif ($val eq 'false') {
307 sub feature_snapshot
{
310 my ($val) = git_get_project_config
('snapshot');
313 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
320 my ($val) = git_get_project_config
('grep', '--bool');
322 if ($val eq 'true') {
324 } elsif ($val eq 'false') {
331 sub feature_pickaxe
{
332 my ($val) = git_get_project_config
('pickaxe', '--bool');
334 if ($val eq 'true') {
336 } elsif ($val eq 'false') {
343 # checking HEAD file with -e is fragile if the repository was
344 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
346 sub check_head_link
{
348 my $headfile = "$dir/HEAD";
349 return ((-e
$headfile) ||
350 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
353 sub check_export_ok
{
355 return (check_head_link
($dir) &&
356 (!$export_ok || -e
"$dir/$export_ok"));
359 # process alternate names for backward compatibility
360 # filter out unsupported (unknown) snapshot formats
361 sub filter_snapshot_fmts
{
365 exists $known_snapshot_format_aliases{$_} ?
366 $known_snapshot_format_aliases{$_} : $_} @fmts;
367 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
371 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
372 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
374 # version of the core git binary
375 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
377 $projects_list ||= $projectroot;
379 # ======================================================================
380 # input validation and dispatch
381 our $action = $cgi->param('a');
382 if (defined $action) {
383 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
384 die_error
(undef, "Invalid action parameter");
388 # parameters which are pathnames
389 our $project = $cgi->param('p');
390 if (defined $project) {
391 if (!validate_pathname
($project) ||
392 !(-d
"$projectroot/$project") ||
393 !check_head_link
("$projectroot/$project") ||
394 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
395 ($strict_export && !project_in_list
($project))) {
397 die_error
(undef, "No such project");
401 our $file_name = $cgi->param('f');
402 if (defined $file_name) {
403 if (!validate_pathname
($file_name)) {
404 die_error
(undef, "Invalid file parameter");
408 our $file_parent = $cgi->param('fp');
409 if (defined $file_parent) {
410 if (!validate_pathname
($file_parent)) {
411 die_error
(undef, "Invalid file parent parameter");
415 # parameters which are refnames
416 our $hash = $cgi->param('h');
418 if (!validate_refname
($hash)) {
419 die_error
(undef, "Invalid hash parameter");
423 our $hash_parent = $cgi->param('hp');
424 if (defined $hash_parent) {
425 if (!validate_refname
($hash_parent)) {
426 die_error
(undef, "Invalid hash parent parameter");
430 our $hash_base = $cgi->param('hb');
431 if (defined $hash_base) {
432 if (!validate_refname
($hash_base)) {
433 die_error
(undef, "Invalid hash base parameter");
437 my %allowed_options = (
438 "--no-merges" => [ qw(rss atom log shortlog history) ],
441 our @extra_options = $cgi->param('opt');
442 if (defined @extra_options) {
443 foreach my $opt (@extra_options) {
444 if (not exists $allowed_options{$opt}) {
445 die_error
(undef, "Invalid option parameter");
447 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
448 die_error
(undef, "Invalid option parameter for this action");
453 our $hash_parent_base = $cgi->param('hpb');
454 if (defined $hash_parent_base) {
455 if (!validate_refname
($hash_parent_base)) {
456 die_error
(undef, "Invalid hash parent base parameter");
461 our $page = $cgi->param('pg');
463 if ($page =~ m/[^0-9]/) {
464 die_error
(undef, "Invalid page parameter");
468 our $searchtype = $cgi->param('st');
469 if (defined $searchtype) {
470 if ($searchtype =~ m/[^a-z]/) {
471 die_error
(undef, "Invalid searchtype parameter");
475 our $search_use_regexp = $cgi->param('sr');
477 our $searchtext = $cgi->param('s');
479 if (defined $searchtext) {
480 if (length($searchtext) < 2) {
481 die_error
(undef, "At least two characters are required for search parameter");
483 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
486 # now read PATH_INFO and use it as alternative to parameters
487 sub evaluate_path_info
{
488 return if defined $project;
489 my $path_info = $ENV{"PATH_INFO"};
490 return if !$path_info;
491 $path_info =~ s
,^/+,,;
492 return if !$path_info;
493 # find which part of PATH_INFO is project
494 $project = $path_info;
496 while ($project && !check_head_link
("$projectroot/$project")) {
497 $project =~ s
,/*[^/]*$,,;
500 $project = validate_pathname
($project);
502 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
503 ($strict_export && !project_in_list
($project))) {
507 # do not change any parameters if an action is given using the query string
509 $path_info =~ s
,^$project/*,,;
510 my ($refname, $pathname) = split(/:/, $path_info, 2);
511 if (defined $pathname) {
512 # we got "project.git/branch:filename" or "project.git/branch:dir/"
513 # we could use git_get_type(branch:pathname), but it needs $git_dir
514 $pathname =~ s
,^/+,,;
515 if (!$pathname || substr($pathname, -1) eq "/") {
519 $action ||= "blob_plain";
521 $hash_base ||= validate_refname
($refname);
522 $file_name ||= validate_pathname
($pathname);
523 } elsif (defined $refname) {
524 # we got "project.git/branch"
525 $action ||= "shortlog";
526 $hash ||= validate_refname
($refname);
529 evaluate_path_info
();
531 # path to the current git repository
533 $git_dir = "$projectroot/$project" if $project;
537 "blame" => \
&git_blame2
,
538 "blobdiff" => \
&git_blobdiff
,
539 "blobdiff_plain" => \
&git_blobdiff_plain
,
540 "blob" => \
&git_blob
,
541 "blob_plain" => \
&git_blob_plain
,
542 "commitdiff" => \
&git_commitdiff
,
543 "commitdiff_plain" => \
&git_commitdiff_plain
,
544 "commit" => \
&git_commit
,
545 "forks" => \
&git_forks
,
546 "heads" => \
&git_heads
,
547 "history" => \
&git_history
,
550 "atom" => \
&git_atom
,
551 "search" => \
&git_search
,
552 "search_help" => \
&git_search_help
,
553 "shortlog" => \
&git_shortlog
,
554 "summary" => \
&git_summary
,
556 "tags" => \
&git_tags
,
557 "tree" => \
&git_tree
,
558 "snapshot" => \
&git_snapshot
,
559 "object" => \
&git_object
,
560 # those below don't need $project
561 "opml" => \
&git_opml
,
562 "project_list" => \
&git_project_list
,
563 "project_index" => \
&git_project_index
,
566 if (!defined $action) {
568 $action = git_get_type
($hash);
569 } elsif (defined $hash_base && defined $file_name) {
570 $action = git_get_type
("$hash_base:$file_name");
571 } elsif (defined $project) {
574 $action = 'project_list';
577 if (!defined($actions{$action})) {
578 die_error
(undef, "Unknown action");
580 if ($action !~ m/^(opml|project_list|project_index)$/ &&
582 die_error
(undef, "Project needed");
584 $actions{$action}->();
587 ## ======================================================================
592 # default is to use -absolute url() i.e. $my_uri
593 my $href = $params{-full
} ?
$my_url : $my_uri;
595 # XXX: Warning: If you touch this, check the search form for updating,
606 hash_parent_base
=> "hpb",
611 snapshot_format
=> "sf",
612 extra_options
=> "opt",
613 search_use_regexp
=> "sr",
615 my %mapping = @mapping;
617 $params{'project'} = $project unless exists $params{'project'};
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 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
630 # use PATH_INFO for project name
631 $href .= "/$params{'project'}" if defined $params{'project'};
632 delete $params{'project'};
634 # Summary just uses the project path URL
635 if (defined $params{'action'} && $params{'action'} eq 'summary') {
636 delete $params{'action'};
640 # now encode the parameters explicitly
642 for (my $i = 0; $i < @mapping; $i += 2) {
643 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
644 if (defined $params{$name}) {
645 if (ref($params{$name}) eq "ARRAY") {
646 foreach my $par (@
{$params{$name}}) {
647 push @result, $symbol . "=" . esc_param
($par);
650 push @result, $symbol . "=" . esc_param
($params{$name});
654 $href .= "?" . join(';', @result) if scalar @result;
660 ## ======================================================================
661 ## validation, quoting/unquoting and escaping
663 sub validate_pathname
{
664 my $input = shift || return undef;
666 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
667 # at the beginning, at the end, and between slashes.
668 # also this catches doubled slashes
669 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
673 if ($input =~ m!\0!) {
679 sub validate_refname
{
680 my $input = shift || return undef;
682 # textual hashes are O.K.
683 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
686 # it must be correct pathname
687 $input = validate_pathname
($input)
689 # restrictions on ref name according to git-check-ref-format
690 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
696 # decode sequences of octets in utf8 into Perl's internal form,
697 # which is utf-8 with utf8 flag set if needed. gitweb writes out
698 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
701 if (utf8
::valid
($str)) {
705 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
709 # quote unsafe chars, but keep the slash, even when it's not
710 # correct, but quoted slashes look too horrible in bookmarks
713 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
719 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
722 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
728 # replace invalid utf8 character with SUBSTITUTION sequence
733 $str = to_utf8
($str);
734 $str = $cgi->escapeHTML($str);
735 if ($opts{'-nbsp'}) {
736 $str =~ s/ / /g;
738 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
742 # quote control characters and escape filename to HTML
747 $str = to_utf8
($str);
748 $str = $cgi->escapeHTML($str);
749 if ($opts{'-nbsp'}) {
750 $str =~ s/ / /g;
752 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
756 # Make control characters "printable", using character escape codes (CEC)
760 my %es = ( # character escape codes, aka escape sequences
761 "\t" => '\t', # tab (HT)
762 "\n" => '\n', # line feed (LF)
763 "\r" => '\r', # carrige return (CR)
764 "\f" => '\f', # form feed (FF)
765 "\b" => '\b', # backspace (BS)
766 "\a" => '\a', # alarm (bell) (BEL)
767 "\e" => '\e', # escape (ESC)
768 "\013" => '\v', # vertical tab (VT)
769 "\000" => '\0', # nul character (NUL)
771 my $chr = ( (exists $es{$cntrl})
773 : sprintf('\%03o', ord($cntrl)) );
774 if ($opts{-nohtml
}) {
777 return "<span class=\"cntrl\">$chr</span>";
781 # Alternatively use unicode control pictures codepoints,
782 # Unicode "printable representation" (PR)
787 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
788 if ($opts{-nohtml
}) {
791 return "<span class=\"cntrl\">$chr</span>";
795 # git may return quoted and escaped filenames
801 my %es = ( # character escape codes, aka escape sequences
802 't' => "\t", # tab (HT, TAB)
803 'n' => "\n", # newline (NL)
804 'r' => "\r", # return (CR)
805 'f' => "\f", # form feed (FF)
806 'b' => "\b", # backspace (BS)
807 'a' => "\a", # alarm (bell) (BEL)
808 'e' => "\e", # escape (ESC)
809 'v' => "\013", # vertical tab (VT)
812 if ($seq =~ m/^[0-7]{1,3}$/) {
813 # octal char sequence
814 return chr(oct($seq));
815 } elsif (exists $es{$seq}) {
816 # C escape sequence, aka character escape code
819 # quoted ordinary character
823 if ($str =~ m/^"(.*)"$/) {
826 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
831 # escape tabs (convert tabs to spaces)
835 while ((my $pos = index($line, "\t")) != -1) {
836 if (my $count = (8 - ($pos % 8))) {
837 my $spaces = ' ' x
$count;
838 $line =~ s/\t/$spaces/;
845 sub project_in_list
{
847 my @list = git_get_projects_list
();
848 return @list && scalar(grep { $_->{'path'} eq $project } @list);
851 ## ----------------------------------------------------------------------
852 ## HTML aware string manipulation
854 # Try to chop given string on a word boundary between position
855 # $len and $len+$add_len. If there is no word boundary there,
856 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
857 # (marking chopped part) would be longer than given string.
861 my $add_len = shift || 10;
862 my $where = shift || 'right'; # 'left' | 'center' | 'right'
864 # allow only $len chars, but don't cut a word if it would fit in $add_len
865 # if it doesn't fit, cut it if it's still longer than the dots we would add
866 # remove chopped character entities entirely
868 # when chopping in the middle, distribute $len into left and right part
869 # return early if chopping wouldn't make string shorter
870 if ($where eq 'center') {
871 return $str if ($len + 5 >= length($str)); # filler is length 5
874 return $str if ($len + 4 >= length($str)); # filler is length 4
877 # regexps: ending and beginning with word part up to $add_len
878 my $endre = qr/.{$len}\w{0,$add_len}/;
879 my $begre = qr/\w{0,$add_len}.{$len}/;
881 if ($where eq 'left') {
882 $str =~ m/^(.*?)($begre)$/;
883 my ($lead, $body) = ($1, $2);
884 if (length($lead) > 4) {
885 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
890 } elsif ($where eq 'center') {
891 $str =~ m/^($endre)(.*)$/;
892 my ($left, $str) = ($1, $2);
893 $str =~ m/^(.*?)($begre)$/;
894 my ($mid, $right) = ($1, $2);
895 if (length($mid) > 5) {
896 $left =~ s/&[^;]*$//;
897 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
900 return "$left$mid$right";
903 $str =~ m/^($endre)(.*)$/;
906 if (length($tail) > 4) {
907 $body =~ s/&[^;]*$//;
914 # takes the same arguments as chop_str, but also wraps a <span> around the
915 # result with a title attribute if it does get chopped. Additionally, the
916 # string is HTML-escaped.
917 sub chop_and_escape_str
{
920 my $chopped = chop_str
(@_);
921 if ($chopped eq $str) {
922 return esc_html
($chopped);
924 $str =~ s/([[:cntrl:]])/?/g;
925 return $cgi->span({-title
=>$str}, esc_html
($chopped));
929 ## ----------------------------------------------------------------------
930 ## functions returning short strings
932 # CSS class for given age value (in seconds)
938 } elsif ($age < 60*60*2) {
940 } elsif ($age < 60*60*24*2) {
947 # convert age in seconds to "nn units ago" string
952 if ($age > 60*60*24*365*2) {
953 $age_str = (int $age/60/60/24/365);
954 $age_str .= " years ago";
955 } elsif ($age > 60*60*24*(365/12)*2) {
956 $age_str = int $age/60/60/24/(365/12);
957 $age_str .= " months ago";
958 } elsif ($age > 60*60*24*7*2) {
959 $age_str = int $age/60/60/24/7;
960 $age_str .= " weeks ago";
961 } elsif ($age > 60*60*24*2) {
962 $age_str = int $age/60/60/24;
963 $age_str .= " days ago";
964 } elsif ($age > 60*60*2) {
965 $age_str = int $age/60/60;
966 $age_str .= " hours ago";
967 } elsif ($age > 60*2) {
968 $age_str = int $age/60;
969 $age_str .= " min ago";
972 $age_str .= " sec ago";
974 $age_str .= " right now";
980 S_IFINVALID
=> 0030000,
981 S_IFGITLINK
=> 0160000,
984 # submodule/subproject, a commit object reference
988 return (($mode & S_IFMT
) == S_IFGITLINK
)
991 # convert file mode in octal to symbolic file mode string
993 my $mode = oct shift;
995 if (S_ISGITLINK
($mode)) {
997 } elsif (S_ISDIR
($mode & S_IFMT
)) {
999 } elsif (S_ISLNK
($mode)) {
1000 return 'lrwxrwxrwx';
1001 } elsif (S_ISREG
($mode)) {
1002 # git cares only about the executable bit
1003 if ($mode & S_IXUSR
) {
1004 return '-rwxr-xr-x';
1006 return '-rw-r--r--';
1009 return '----------';
1013 # convert file mode in octal to file type string
1017 if ($mode !~ m/^[0-7]+$/) {
1023 if (S_ISGITLINK
($mode)) {
1025 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1027 } elsif (S_ISLNK
($mode)) {
1029 } elsif (S_ISREG
($mode)) {
1036 # convert file mode in octal to file type description string
1037 sub file_type_long
{
1040 if ($mode !~ m/^[0-7]+$/) {
1046 if (S_ISGITLINK
($mode)) {
1048 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1050 } elsif (S_ISLNK
($mode)) {
1052 } elsif (S_ISREG
($mode)) {
1053 if ($mode & S_IXUSR
) {
1054 return "executable";
1064 ## ----------------------------------------------------------------------
1065 ## functions returning short HTML fragments, or transforming HTML fragments
1066 ## which don't belong to other sections
1068 # format line of commit message.
1069 sub format_log_line_html
{
1072 $line = esc_html
($line, -nbsp
=>1);
1073 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1076 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1077 -class => "text"}, $hash_text);
1078 $line =~ s/$hash_text/$link/;
1083 # format marker of refs pointing to given object
1084 sub format_ref_marker
{
1085 my ($refs, $id) = @_;
1088 if (defined $refs->{$id}) {
1089 foreach my $ref (@
{$refs->{$id}}) {
1090 my ($type, $name) = qw();
1091 # e.g. tags/v2.6.11 or heads/next
1092 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1100 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1101 esc_html
($name) . "</span>";
1106 return ' <span class="refs">'. $markers . '</span>';
1112 # format, perhaps shortened and with markers, title line
1113 sub format_subject_html
{
1114 my ($long, $short, $href, $extra) = @_;
1115 $extra = '' unless defined($extra);
1117 if (length($short) < length($long)) {
1118 return $cgi->a({-href
=> $href, -class => "list subject",
1119 -title
=> to_utf8
($long)},
1120 esc_html
($short) . $extra);
1122 return $cgi->a({-href
=> $href, -class => "list subject"},
1123 esc_html
($long) . $extra);
1127 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1128 sub format_git_diff_header_line
{
1130 my $diffinfo = shift;
1131 my ($from, $to) = @_;
1133 if ($diffinfo->{'nparents'}) {
1135 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1136 if ($to->{'href'}) {
1137 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1138 esc_path
($to->{'file'}));
1139 } else { # file was deleted (no href)
1140 $line .= esc_path
($to->{'file'});
1144 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1145 if ($from->{'href'}) {
1146 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1147 'a/' . esc_path
($from->{'file'}));
1148 } else { # file was added (no href)
1149 $line .= 'a/' . esc_path
($from->{'file'});
1152 if ($to->{'href'}) {
1153 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1154 'b/' . esc_path
($to->{'file'}));
1155 } else { # file was deleted
1156 $line .= 'b/' . esc_path
($to->{'file'});
1160 return "<div class=\"diff header\">$line</div>\n";
1163 # format extended diff header line, before patch itself
1164 sub format_extended_diff_header_line
{
1166 my $diffinfo = shift;
1167 my ($from, $to) = @_;
1170 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1171 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1172 esc_path
($from->{'file'}));
1174 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1175 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1176 esc_path
($to->{'file'}));
1178 # match single <mode>
1179 if ($line =~ m/\s(\d{6})$/) {
1180 $line .= '<span class="info"> (' .
1181 file_type_long
($1) .
1185 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1186 # can match only for combined diff
1188 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1189 if ($from->{'href'}[$i]) {
1190 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1192 substr($diffinfo->{'from_id'}[$i],0,7));
1197 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1200 if ($to->{'href'}) {
1201 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1202 substr($diffinfo->{'to_id'},0,7));
1207 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1208 # can match only for ordinary diff
1209 my ($from_link, $to_link);
1210 if ($from->{'href'}) {
1211 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1212 substr($diffinfo->{'from_id'},0,7));
1214 $from_link = '0' x
7;
1216 if ($to->{'href'}) {
1217 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1218 substr($diffinfo->{'to_id'},0,7));
1222 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1223 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1226 return $line . "<br/>\n";
1229 # format from-file/to-file diff header
1230 sub format_diff_from_to_header
{
1231 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1236 #assert($line =~ m/^---/) if DEBUG;
1237 # no extra formatting for "^--- /dev/null"
1238 if (! $diffinfo->{'nparents'}) {
1239 # ordinary (single parent) diff
1240 if ($line =~ m!^--- "?a/!) {
1241 if ($from->{'href'}) {
1243 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1244 esc_path
($from->{'file'}));
1247 esc_path
($from->{'file'});
1250 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1253 # combined diff (merge commit)
1254 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1255 if ($from->{'href'}[$i]) {
1257 $cgi->a({-href
=>href
(action
=>"blobdiff",
1258 hash_parent
=>$diffinfo->{'from_id'}[$i],
1259 hash_parent_base
=>$parents[$i],
1260 file_parent
=>$from->{'file'}[$i],
1261 hash
=>$diffinfo->{'to_id'},
1263 file_name
=>$to->{'file'}),
1265 -title
=>"diff" . ($i+1)},
1268 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1269 esc_path
($from->{'file'}[$i]));
1271 $line = '--- /dev/null';
1273 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1278 #assert($line =~ m/^\+\+\+/) if DEBUG;
1279 # no extra formatting for "^+++ /dev/null"
1280 if ($line =~ m!^\+\+\+ "?b/!) {
1281 if ($to->{'href'}) {
1283 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1284 esc_path
($to->{'file'}));
1287 esc_path
($to->{'file'});
1290 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1295 # create note for patch simplified by combined diff
1296 sub format_diff_cc_simplified
{
1297 my ($diffinfo, @parents) = @_;
1300 $result .= "<div class=\"diff header\">" .
1302 if (!is_deleted
($diffinfo)) {
1303 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1305 hash
=>$diffinfo->{'to_id'},
1306 file_name
=>$diffinfo->{'to_file'}),
1308 esc_path
($diffinfo->{'to_file'}));
1310 $result .= esc_path
($diffinfo->{'to_file'});
1312 $result .= "</div>\n" . # class="diff header"
1313 "<div class=\"diff nodifferences\">" .
1315 "</div>\n"; # class="diff nodifferences"
1320 # format patch (diff) line (not to be used for diff headers)
1321 sub format_diff_line
{
1323 my ($from, $to) = @_;
1324 my $diff_class = "";
1328 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1330 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1331 if ($line =~ m/^\@{3}/) {
1332 $diff_class = " chunk_header";
1333 } elsif ($line =~ m/^\\/) {
1334 $diff_class = " incomplete";
1335 } elsif ($prefix =~ tr/+/+/) {
1336 $diff_class = " add";
1337 } elsif ($prefix =~ tr/-/-/) {
1338 $diff_class = " rem";
1341 # assume ordinary diff
1342 my $char = substr($line, 0, 1);
1344 $diff_class = " add";
1345 } elsif ($char eq '-') {
1346 $diff_class = " rem";
1347 } elsif ($char eq '@') {
1348 $diff_class = " chunk_header";
1349 } elsif ($char eq "\\") {
1350 $diff_class = " incomplete";
1353 $line = untabify
($line);
1354 if ($from && $to && $line =~ m/^\@{2} /) {
1355 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1356 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1358 $from_lines = 0 unless defined $from_lines;
1359 $to_lines = 0 unless defined $to_lines;
1361 if ($from->{'href'}) {
1362 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1363 -class=>"list"}, $from_text);
1365 if ($to->{'href'}) {
1366 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1367 -class=>"list"}, $to_text);
1369 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1370 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1371 return "<div class=\"diff$diff_class\">$line</div>\n";
1372 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1373 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1374 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1376 @from_text = split(' ', $ranges);
1377 for (my $i = 0; $i < @from_text; ++$i) {
1378 ($from_start[$i], $from_nlines[$i]) =
1379 (split(',', substr($from_text[$i], 1)), 0);
1382 $to_text = pop @from_text;
1383 $to_start = pop @from_start;
1384 $to_nlines = pop @from_nlines;
1386 $line = "<span class=\"chunk_info\">$prefix ";
1387 for (my $i = 0; $i < @from_text; ++$i) {
1388 if ($from->{'href'}[$i]) {
1389 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1390 -class=>"list"}, $from_text[$i]);
1392 $line .= $from_text[$i];
1396 if ($to->{'href'}) {
1397 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1398 -class=>"list"}, $to_text);
1402 $line .= " $prefix</span>" .
1403 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1404 return "<div class=\"diff$diff_class\">$line</div>\n";
1406 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1409 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1410 # linked. Pass the hash of the tree/commit to snapshot.
1411 sub format_snapshot_links
{
1413 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1414 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1415 my $num_fmts = @snapshot_fmts;
1416 if ($num_fmts > 1) {
1417 # A parenthesized list of links bearing format names.
1418 # e.g. "snapshot (_tar.gz_ _zip_)"
1419 return "snapshot (" . join(' ', map
1426 }, $known_snapshot_formats{$_}{'display'})
1427 , @snapshot_fmts) . ")";
1428 } elsif ($num_fmts == 1) {
1429 # A single "snapshot" link whose tooltip bears the format name.
1431 my ($fmt) = @snapshot_fmts;
1437 snapshot_format
=>$fmt
1439 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1441 } else { # $num_fmts == 0
1446 ## ----------------------------------------------------------------------
1447 ## git utility subroutines, invoking git commands
1449 # returns path to the core git executable and the --git-dir parameter as list
1451 return $GIT, '--git-dir='.$git_dir;
1454 # returns path to the core git executable and the --git-dir parameter as string
1456 return join(' ', git_cmd
());
1459 # get HEAD ref of given project as hash
1460 sub git_get_head_hash
{
1461 my $project = shift;
1462 my $o_git_dir = $git_dir;
1464 $git_dir = "$projectroot/$project";
1465 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1468 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1472 if (defined $o_git_dir) {
1473 $git_dir = $o_git_dir;
1478 # get type of given object
1482 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1484 close $fd or return;
1489 # repository configuration
1490 our $config_file = '';
1493 # store multiple values for single key as anonymous array reference
1494 # single values stored directly in the hash, not as [ <value> ]
1495 sub hash_set_multi
{
1496 my ($hash, $key, $value) = @_;
1498 if (!exists $hash->{$key}) {
1499 $hash->{$key} = $value;
1500 } elsif (!ref $hash->{$key}) {
1501 $hash->{$key} = [ $hash->{$key}, $value ];
1503 push @
{$hash->{$key}}, $value;
1507 # return hash of git project configuration
1508 # optionally limited to some section, e.g. 'gitweb'
1509 sub git_parse_project_config
{
1510 my $section_regexp = shift;
1515 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1518 while (my $keyval = <$fh>) {
1520 my ($key, $value) = split(/\n/, $keyval, 2);
1522 hash_set_multi
(\
%config, $key, $value)
1523 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1530 # convert config value to boolean, 'true' or 'false'
1531 # no value, number > 0, 'true' and 'yes' values are true
1532 # rest of values are treated as false (never as error)
1533 sub config_to_bool
{
1536 # strip leading and trailing whitespace
1540 return (!defined $val || # section.key
1541 ($val =~ /^\d+$/ && $val) || # section.key = 1
1542 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1545 # convert config value to simple decimal number
1546 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1547 # to be multiplied by 1024, 1048576, or 1073741824
1551 # strip leading and trailing whitespace
1555 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1557 # unknown unit is treated as 1
1558 return $num * ($unit eq 'g' ?
1073741824 :
1559 $unit eq 'm' ?
1048576 :
1560 $unit eq 'k' ?
1024 : 1);
1565 # convert config value to array reference, if needed
1566 sub config_to_multi
{
1569 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1572 sub git_get_project_config
{
1573 my ($key, $type) = @_;
1576 return unless ($key);
1577 $key =~ s/^gitweb\.//;
1578 return if ($key =~ m/\W/);
1581 if (defined $type) {
1584 unless ($type eq 'bool' || $type eq 'int');
1588 if (!defined $config_file ||
1589 $config_file ne "$git_dir/config") {
1590 %config = git_parse_project_config
('gitweb');
1591 $config_file = "$git_dir/config";
1595 if (!defined $type) {
1596 return $config{"gitweb.$key"};
1597 } elsif ($type eq 'bool') {
1598 # backward compatibility: 'git config --bool' returns true/false
1599 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1600 } elsif ($type eq 'int') {
1601 return config_to_int
($config{"gitweb.$key"});
1603 return $config{"gitweb.$key"};
1606 # get hash of given path at given ref
1607 sub git_get_hash_by_path
{
1609 my $path = shift || return undef;
1614 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1615 or die_error
(undef, "Open git-ls-tree failed");
1617 close $fd or return undef;
1619 if (!defined $line) {
1620 # there is no tree or hash given by $path at $base
1624 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1625 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1626 if (defined $type && $type ne $2) {
1627 # type doesn't match
1633 # get path of entry with given hash at given tree-ish (ref)
1634 # used to get 'from' filename for combined diff (merge commit) for renames
1635 sub git_get_path_by_hash
{
1636 my $base = shift || return;
1637 my $hash = shift || return;
1641 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1643 while (my $line = <$fd>) {
1646 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1647 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1648 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1657 ## ......................................................................
1658 ## git utility functions, directly accessing git repository
1660 sub git_get_project_description
{
1663 $git_dir = "$projectroot/$path";
1664 open my $fd, "$git_dir/description"
1665 or return git_get_project_config
('description');
1668 if (defined $descr) {
1674 sub git_get_project_url_list
{
1677 $git_dir = "$projectroot/$path";
1678 open my $fd, "$git_dir/cloneurl"
1679 or return wantarray ?
1680 @
{ config_to_multi
(git_get_project_config
('url')) } :
1681 config_to_multi
(git_get_project_config
('url'));
1682 my @git_project_url_list = map { chomp; $_ } <$fd>;
1685 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1688 sub git_get_projects_list
{
1693 $filter =~ s/\.git$//;
1695 my ($check_forks) = gitweb_check_feature
('forks');
1697 if (-d
$projects_list) {
1698 # search in directory
1699 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1700 # remove the trailing "/"
1702 my $pfxlen = length("$dir");
1703 my $pfxdepth = ($dir =~ tr!/!!);
1706 follow_fast
=> 1, # follow symbolic links
1707 follow_skip
=> 2, # ignore duplicates
1708 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1710 # skip project-list toplevel, if we get it.
1711 return if (m!^[/.]$!);
1712 # only directories can be git repositories
1713 return unless (-d
$_);
1714 # don't traverse too deep (Find is super slow on os x)
1715 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1716 $File::Find
::prune
= 1;
1720 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1721 # we check related file in $projectroot
1722 if ($check_forks and $subdir =~ m
#/.#) {
1723 $File::Find
::prune
= 1;
1724 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1725 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1726 $File::Find
::prune
= 1;
1731 } elsif (-f
$projects_list) {
1732 # read from file(url-encoded):
1733 # 'git%2Fgit.git Linus+Torvalds'
1734 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1735 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1737 open my ($fd), $projects_list or return;
1739 while (my $line = <$fd>) {
1741 my ($path, $owner) = split ' ', $line;
1742 $path = unescape
($path);
1743 $owner = unescape
($owner);
1744 if (!defined $path) {
1747 if ($filter ne '') {
1748 # looking for forks;
1749 my $pfx = substr($path, 0, length($filter));
1750 if ($pfx ne $filter) {
1753 my $sfx = substr($path, length($filter));
1754 if ($sfx !~ /^\/.*\
.git
$/) {
1757 } elsif ($check_forks) {
1759 foreach my $filter (keys %paths) {
1760 # looking for forks;
1761 my $pfx = substr($path, 0, length($filter));
1762 if ($pfx ne $filter) {
1765 my $sfx = substr($path, length($filter));
1766 if ($sfx !~ /^\/.*\
.git
$/) {
1769 # is a fork, don't include it in
1774 if (check_export_ok
("$projectroot/$path")) {
1777 owner
=> to_utf8
($owner),
1780 (my $forks_path = $path) =~ s/\.git$//;
1781 $paths{$forks_path}++;
1789 our $gitweb_project_owner = undef;
1790 sub git_get_project_list_from_file
{
1792 return if (defined $gitweb_project_owner);
1794 $gitweb_project_owner = {};
1795 # read from file (url-encoded):
1796 # 'git%2Fgit.git Linus+Torvalds'
1797 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1798 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1799 if (-f
$projects_list) {
1800 open (my $fd , $projects_list);
1801 while (my $line = <$fd>) {
1803 my ($pr, $ow) = split ' ', $line;
1804 $pr = unescape
($pr);
1805 $ow = unescape
($ow);
1806 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1812 sub git_get_project_owner
{
1813 my $project = shift;
1816 return undef unless $project;
1817 $git_dir = "$projectroot/$project";
1819 if (!defined $gitweb_project_owner) {
1820 git_get_project_list_from_file
();
1823 if (exists $gitweb_project_owner->{$project}) {
1824 $owner = $gitweb_project_owner->{$project};
1826 if (!defined $owner){
1827 $owner = git_get_project_config
('owner');
1829 if (!defined $owner) {
1830 $owner = get_file_owner
("$git_dir");
1836 sub git_get_last_activity
{
1840 $git_dir = "$projectroot/$path";
1841 open($fd, "-|", git_cmd
(), 'for-each-ref',
1842 '--format=%(committer)',
1843 '--sort=-committerdate',
1845 'refs/heads') or return;
1846 my $most_recent = <$fd>;
1847 close $fd or return;
1848 if (defined $most_recent &&
1849 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1851 my $age = time - $timestamp;
1852 return ($age, age_string
($age));
1854 return (undef, undef);
1857 sub git_get_references
{
1858 my $type = shift || "";
1860 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1861 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1862 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1863 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1866 while (my $line = <$fd>) {
1868 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1869 if (defined $refs{$1}) {
1870 push @
{$refs{$1}}, $2;
1876 close $fd or return;
1880 sub git_get_rev_name_tags
{
1881 my $hash = shift || return undef;
1883 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1885 my $name_rev = <$fd>;
1888 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1891 # catches also '$hash undefined' output
1896 ## ----------------------------------------------------------------------
1897 ## parse to hash functions
1901 my $tz = shift || "-0000";
1904 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1905 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1906 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1907 $date{'hour'} = $hour;
1908 $date{'minute'} = $min;
1909 $date{'mday'} = $mday;
1910 $date{'day'} = $days[$wday];
1911 $date{'month'} = $months[$mon];
1912 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1913 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1914 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1915 $mday, $months[$mon], $hour ,$min;
1916 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1917 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1919 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1920 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1921 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1922 $date{'hour_local'} = $hour;
1923 $date{'minute_local'} = $min;
1924 $date{'tz_local'} = $tz;
1925 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1926 1900+$year, $mon+1, $mday,
1927 $hour, $min, $sec, $tz);
1936 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1937 $tag{'id'} = $tag_id;
1938 while (my $line = <$fd>) {
1940 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1941 $tag{'object'} = $1;
1942 } elsif ($line =~ m/^type (.+)$/) {
1944 } elsif ($line =~ m/^tag (.+)$/) {
1946 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1947 $tag{'author'} = $1;
1950 } elsif ($line =~ m/--BEGIN/) {
1951 push @comment, $line;
1953 } elsif ($line eq "") {
1957 push @comment, <$fd>;
1958 $tag{'comment'} = \
@comment;
1959 close $fd or return;
1960 if (!defined $tag{'name'}) {
1966 sub parse_commit_text
{
1967 my ($commit_text, $withparents) = @_;
1968 my @commit_lines = split '\n', $commit_text;
1971 pop @commit_lines; # Remove '\0'
1973 if (! @commit_lines) {
1977 my $header = shift @commit_lines;
1978 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1981 ($co{'id'}, my @parents) = split ' ', $header;
1982 while (my $line = shift @commit_lines) {
1983 last if $line eq "\n";
1984 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1986 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1988 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1990 $co{'author_epoch'} = $2;
1991 $co{'author_tz'} = $3;
1992 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1993 $co{'author_name'} = $1;
1994 $co{'author_email'} = $2;
1996 $co{'author_name'} = $co{'author'};
1998 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1999 $co{'committer'} = $1;
2000 $co{'committer_epoch'} = $2;
2001 $co{'committer_tz'} = $3;
2002 $co{'committer_name'} = $co{'committer'};
2003 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2004 $co{'committer_name'} = $1;
2005 $co{'committer_email'} = $2;
2007 $co{'committer_name'} = $co{'committer'};
2011 if (!defined $co{'tree'}) {
2014 $co{'parents'} = \
@parents;
2015 $co{'parent'} = $parents[0];
2017 foreach my $title (@commit_lines) {
2020 $co{'title'} = chop_str
($title, 80, 5);
2021 # remove leading stuff of merges to make the interesting part visible
2022 if (length($title) > 50) {
2023 $title =~ s/^Automatic //;
2024 $title =~ s/^merge (of|with) /Merge ... /i;
2025 if (length($title) > 50) {
2026 $title =~ s/(http|rsync):\/\///;
2028 if (length($title) > 50) {
2029 $title =~ s/(master|www|rsync)\.//;
2031 if (length($title) > 50) {
2032 $title =~ s/kernel.org:?//;
2034 if (length($title) > 50) {
2035 $title =~ s/\/pub\/scm//;
2038 $co{'title_short'} = chop_str
($title, 50, 5);
2042 if ($co{'title'} eq "") {
2043 $co{'title'} = $co{'title_short'} = '(no commit message)';
2045 # remove added spaces
2046 foreach my $line (@commit_lines) {
2049 $co{'comment'} = \
@commit_lines;
2051 my $age = time - $co{'committer_epoch'};
2053 $co{'age_string'} = age_string
($age);
2054 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2055 if ($age > 60*60*24*7*2) {
2056 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2057 $co{'age_string_age'} = $co{'age_string'};
2059 $co{'age_string_date'} = $co{'age_string'};
2060 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2066 my ($commit_id) = @_;
2071 open my $fd, "-|", git_cmd
(), "rev-list",
2077 or die_error
(undef, "Open git-rev-list failed");
2078 %co = parse_commit_text
(<$fd>, 1);
2085 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2093 open my $fd, "-|", git_cmd
(), "rev-list",
2096 ("--max-count=" . $maxcount),
2097 ("--skip=" . $skip),
2101 ($filename ?
($filename) : ())
2102 or die_error
(undef, "Open git-rev-list failed");
2103 while (my $line = <$fd>) {
2104 my %co = parse_commit_text
($line);
2109 return wantarray ?
@cos : \
@cos;
2112 # parse ref from ref_file, given by ref_id, with given type
2114 my $ref_file = shift;
2116 my $type = shift || git_get_type
($ref_id);
2119 $ref_item{'type'} = $type;
2120 $ref_item{'id'} = $ref_id;
2121 $ref_item{'epoch'} = 0;
2122 $ref_item{'age'} = "unknown";
2123 if ($type eq "tag") {
2124 my %tag = parse_tag
($ref_id);
2125 $ref_item{'comment'} = $tag{'comment'};
2126 if ($tag{'type'} eq "commit") {
2127 my %co = parse_commit
($tag{'object'});
2128 $ref_item{'epoch'} = $co{'committer_epoch'};
2129 $ref_item{'age'} = $co{'age_string'};
2130 } elsif (defined($tag{'epoch'})) {
2131 my $age = time - $tag{'epoch'};
2132 $ref_item{'epoch'} = $tag{'epoch'};
2133 $ref_item{'age'} = age_string
($age);
2135 $ref_item{'reftype'} = $tag{'type'};
2136 $ref_item{'name'} = $tag{'name'};
2137 $ref_item{'refid'} = $tag{'object'};
2138 } elsif ($type eq "commit"){
2139 my %co = parse_commit
($ref_id);
2140 $ref_item{'reftype'} = "commit";
2141 $ref_item{'name'} = $ref_file;
2142 $ref_item{'title'} = $co{'title'};
2143 $ref_item{'refid'} = $ref_id;
2144 $ref_item{'epoch'} = $co{'committer_epoch'};
2145 $ref_item{'age'} = $co{'age_string'};
2147 $ref_item{'reftype'} = $type;
2148 $ref_item{'name'} = $ref_file;
2149 $ref_item{'refid'} = $ref_id;
2155 # parse line of git-diff-tree "raw" output
2156 sub parse_difftree_raw_line
{
2160 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2161 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2162 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2163 $res{'from_mode'} = $1;
2164 $res{'to_mode'} = $2;
2165 $res{'from_id'} = $3;
2167 $res{'status'} = $res{'status_str'} = $5;
2168 $res{'similarity'} = $6;
2169 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2170 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2172 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2175 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2176 # combined diff (for merge commit)
2177 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2178 $res{'nparents'} = length($1);
2179 $res{'from_mode'} = [ split(' ', $2) ];
2180 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2181 $res{'from_id'} = [ split(' ', $3) ];
2182 $res{'to_id'} = pop @
{$res{'from_id'}};
2183 $res{'status_str'} = $4;
2184 $res{'status'} = [ split('', $4) ];
2185 $res{'to_file'} = unquote
($5);
2187 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2188 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2189 $res{'commit'} = $1;
2192 return wantarray ?
%res : \
%res;
2195 # wrapper: return parsed line of git-diff-tree "raw" output
2196 # (the argument might be raw line, or parsed info)
2197 sub parsed_difftree_line
{
2198 my $line_or_ref = shift;
2200 if (ref($line_or_ref) eq "HASH") {
2201 # pre-parsed (or generated by hand)
2202 return $line_or_ref;
2204 return parse_difftree_raw_line
($line_or_ref);
2208 # parse line of git-ls-tree output
2209 sub parse_ls_tree_line
($;%) {
2214 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2215 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2223 $res{'name'} = unquote
($4);
2226 return wantarray ?
%res : \
%res;
2229 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2230 sub parse_from_to_diffinfo
{
2231 my ($diffinfo, $from, $to, @parents) = @_;
2233 if ($diffinfo->{'nparents'}) {
2235 $from->{'file'} = [];
2236 $from->{'href'} = [];
2237 fill_from_file_info
($diffinfo, @parents)
2238 unless exists $diffinfo->{'from_file'};
2239 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2240 $from->{'file'}[$i] =
2241 defined $diffinfo->{'from_file'}[$i] ?
2242 $diffinfo->{'from_file'}[$i] :
2243 $diffinfo->{'to_file'};
2244 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2245 $from->{'href'}[$i] = href
(action
=>"blob",
2246 hash_base
=>$parents[$i],
2247 hash
=>$diffinfo->{'from_id'}[$i],
2248 file_name
=>$from->{'file'}[$i]);
2250 $from->{'href'}[$i] = undef;
2254 # ordinary (not combined) diff
2255 $from->{'file'} = $diffinfo->{'from_file'};
2256 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2257 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2258 hash
=>$diffinfo->{'from_id'},
2259 file_name
=>$from->{'file'});
2261 delete $from->{'href'};
2265 $to->{'file'} = $diffinfo->{'to_file'};
2266 if (!is_deleted
($diffinfo)) { # file exists in result
2267 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2268 hash
=>$diffinfo->{'to_id'},
2269 file_name
=>$to->{'file'});
2271 delete $to->{'href'};
2275 ## ......................................................................
2276 ## parse to array of hashes functions
2278 sub git_get_heads_list
{
2282 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2283 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2284 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2287 while (my $line = <$fd>) {
2291 my ($refinfo, $committerinfo) = split(/\0/, $line);
2292 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2293 my ($committer, $epoch, $tz) =
2294 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2295 $ref_item{'fullname'} = $name;
2296 $name =~ s!^refs/heads/!!;
2298 $ref_item{'name'} = $name;
2299 $ref_item{'id'} = $hash;
2300 $ref_item{'title'} = $title || '(no commit message)';
2301 $ref_item{'epoch'} = $epoch;
2303 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2305 $ref_item{'age'} = "unknown";
2308 push @headslist, \
%ref_item;
2312 return wantarray ?
@headslist : \
@headslist;
2315 sub git_get_tags_list
{
2319 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2320 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2321 '--format=%(objectname) %(objecttype) %(refname) '.
2322 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2325 while (my $line = <$fd>) {
2329 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2330 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2331 my ($creator, $epoch, $tz) =
2332 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2333 $ref_item{'fullname'} = $name;
2334 $name =~ s!^refs/tags/!!;
2336 $ref_item{'type'} = $type;
2337 $ref_item{'id'} = $id;
2338 $ref_item{'name'} = $name;
2339 if ($type eq "tag") {
2340 $ref_item{'subject'} = $title;
2341 $ref_item{'reftype'} = $reftype;
2342 $ref_item{'refid'} = $refid;
2344 $ref_item{'reftype'} = $type;
2345 $ref_item{'refid'} = $id;
2348 if ($type eq "tag" || $type eq "commit") {
2349 $ref_item{'epoch'} = $epoch;
2351 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2353 $ref_item{'age'} = "unknown";
2357 push @tagslist, \
%ref_item;
2361 return wantarray ?
@tagslist : \
@tagslist;
2364 ## ----------------------------------------------------------------------
2365 ## filesystem-related functions
2367 sub get_file_owner
{
2370 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2371 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2372 if (!defined $gcos) {
2376 $owner =~ s/[,;].*$//;
2377 return to_utf8
($owner);
2380 ## ......................................................................
2381 ## mimetype related functions
2383 sub mimetype_guess_file
{
2384 my $filename = shift;
2385 my $mimemap = shift;
2386 -r
$mimemap or return undef;
2389 open(MIME
, $mimemap) or return undef;
2391 next if m/^#/; # skip comments
2392 my ($mime, $exts) = split(/\t+/);
2393 if (defined $exts) {
2394 my @exts = split(/\s+/, $exts);
2395 foreach my $ext (@exts) {
2396 $mimemap{$ext} = $mime;
2402 $filename =~ /\.([^.]*)$/;
2403 return $mimemap{$1};
2406 sub mimetype_guess
{
2407 my $filename = shift;
2409 $filename =~ /\./ or return undef;
2411 if ($mimetypes_file) {
2412 my $file = $mimetypes_file;
2413 if ($file !~ m!^/!) { # if it is relative path
2414 # it is relative to project
2415 $file = "$projectroot/$project/$file";
2417 $mime = mimetype_guess_file
($filename, $file);
2419 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2425 my $filename = shift;
2428 my $mime = mimetype_guess
($filename);
2429 $mime and return $mime;
2433 return $default_blob_plain_mimetype unless $fd;
2436 return 'text/plain' .
2437 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
2438 } elsif (! $filename) {
2439 return 'application/octet-stream';
2440 } elsif ($filename =~ m/\.png$/i) {
2442 } elsif ($filename =~ m/\.gif$/i) {
2444 } elsif ($filename =~ m/\.jpe?g$/i) {
2445 return 'image/jpeg';
2447 return 'application/octet-stream';
2451 ## ======================================================================
2452 ## functions printing HTML: header, footer, error page
2454 sub git_header_html
{
2455 my $status = shift || "200 OK";
2456 my $expires = shift;
2458 my $title = "$site_name";
2459 if (defined $project) {
2460 $title .= " - " . to_utf8
($project);
2461 if (defined $action) {
2462 $title .= "/$action";
2463 if (defined $file_name) {
2464 $title .= " - " . esc_path
($file_name);
2465 if ($action eq "tree" && $file_name !~ m
|/$|) {
2472 # require explicit support from the UA if we are to send the page as
2473 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2474 # we have to do this because MSIE sometimes globs '*/*', pretending to
2475 # support xhtml+xml but choking when it gets what it asked for.
2476 if (defined $cgi->http('HTTP_ACCEPT') &&
2477 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2478 $cgi->Accept('application/xhtml+xml') != 0) {
2479 $content_type = 'application/xhtml+xml';
2481 $content_type = 'text/html';
2483 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2484 -status
=> $status, -expires
=> $expires);
2485 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2487 <?xml version="1.0" encoding="utf-8"?>
2488 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2489 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2490 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2491 <!-- git core binaries version $git_version -->
2493 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2494 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2495 <meta name="robots" content="index, nofollow"/>
2496 <title>$title</title>
2498 # print out each stylesheet that exist
2499 if (defined $stylesheet) {
2500 #provides backwards capability for those people who define style sheet in a config file
2501 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2503 foreach my $stylesheet (@stylesheets) {
2504 next unless $stylesheet;
2505 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2508 if (defined $project) {
2509 printf('<link rel="alternate" title="%s log RSS feed" '.
2510 'href="%s" type="application/rss+xml" />'."\n",
2511 esc_param
($project), href
(action
=>"rss"));
2512 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2513 'href="%s" type="application/rss+xml" />'."\n",
2514 esc_param
($project), href
(action
=>"rss",
2515 extra_options
=>"--no-merges"));
2516 printf('<link rel="alternate" title="%s log Atom feed" '.
2517 'href="%s" type="application/atom+xml" />'."\n",
2518 esc_param
($project), href
(action
=>"atom"));
2519 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2520 'href="%s" type="application/atom+xml" />'."\n",
2521 esc_param
($project), href
(action
=>"atom",
2522 extra_options
=>"--no-merges"));
2524 printf('<link rel="alternate" title="%s projects list" '.
2525 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2526 $site_name, href
(project
=>undef, action
=>"project_index"));
2527 printf('<link rel="alternate" title="%s projects feeds" '.
2528 'href="%s" type="text/x-opml"/>'."\n",
2529 $site_name, href
(project
=>undef, action
=>"opml"));
2531 if (defined $favicon) {
2532 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
2538 if (-f
$site_header) {
2539 open (my $fd, $site_header);
2544 print "<div class=\"page_header\">\n" .
2545 $cgi->a({-href
=> esc_url
($logo_url),
2546 -title
=> $logo_label},
2547 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2548 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2549 if (defined $project) {
2550 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2551 if (defined $action) {
2558 my ($have_search) = gitweb_check_feature
('search');
2559 if ((defined $project) && ($have_search)) {
2560 if (!defined $searchtext) {
2564 if (defined $hash_base) {
2565 $search_hash = $hash_base;
2566 } elsif (defined $hash) {
2567 $search_hash = $hash;
2569 $search_hash = "HEAD";
2571 my $action = $my_uri;
2572 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2573 if ($use_pathinfo) {
2574 $action .= "/$project";
2576 $cgi->param("p", $project);
2578 $cgi->param("a", "search");
2579 $cgi->param("h", $search_hash);
2580 print $cgi->startform(-method
=> "get", -action
=> $action) .
2581 "<div class=\"search\">\n" .
2582 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2583 $cgi->hidden(-name
=> "a") . "\n" .
2584 $cgi->hidden(-name
=> "h") . "\n" .
2585 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2586 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2587 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2589 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2590 "<span title=\"Extended regular expression\">" .
2591 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2592 -checked
=> $search_use_regexp) .
2595 $cgi->end_form() . "\n";
2599 sub git_footer_html
{
2600 print "<div class=\"page_footer\">\n";
2601 if (defined $project) {
2602 my $descr = git_get_project_description
($project);
2603 if (defined $descr) {
2604 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2606 print $cgi->a({-href
=> href
(action
=>"rss"),
2607 -class => "rss_logo"}, "RSS") . " ";
2608 print $cgi->a({-href
=> href
(action
=>"atom"),
2609 -class => "rss_logo"}, "Atom") . "\n";
2611 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2612 -class => "rss_logo"}, "OPML") . " ";
2613 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2614 -class => "rss_logo"}, "TXT") . "\n";
2618 if (-f
$site_footer) {
2619 open (my $fd, $site_footer);
2629 my $status = shift || "403 Forbidden";
2630 my $error = shift || "Malformed query, file missing or permission denied";
2632 git_header_html
($status);
2634 <div class="page_body">
2644 ## ----------------------------------------------------------------------
2645 ## functions printing or outputting HTML: navigation
2647 sub git_print_page_nav
{
2648 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2649 $extra = '' if !defined $extra; # pager or formats
2651 my @navs = qw(summary shortlog log commit commitdiff tree);
2653 @navs = grep { $_ ne $suppress } @navs;
2656 my %arg = map { $_ => {action
=>$_} } @navs;
2657 if (defined $head) {
2658 for (qw(commit commitdiff)) {
2659 $arg{$_}{'hash'} = $head;
2661 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2662 for (qw(shortlog log)) {
2663 $arg{$_}{'hash'} = $head;
2667 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2668 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2670 print "<div class=\"page_nav\">\n" .
2672 map { $_ eq $current ?
2673 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2675 print "<br/>\n$extra<br/>\n" .
2679 sub format_paging_nav
{
2680 my ($action, $hash, $head, $page, $nrevs) = @_;
2684 if ($hash ne $head || $page) {
2685 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2687 $paging_nav .= "HEAD";
2691 $paging_nav .= " ⋅ " .
2692 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2693 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2695 $paging_nav .= " ⋅ prev";
2698 if ($nrevs >= (100 * ($page+1)-1)) {
2699 $paging_nav .= " ⋅ " .
2700 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2701 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2703 $paging_nav .= " ⋅ next";
2709 ## ......................................................................
2710 ## functions printing or outputting HTML: div
2712 sub git_print_header_div
{
2713 my ($action, $title, $hash, $hash_base) = @_;
2716 $args{'action'} = $action;
2717 $args{'hash'} = $hash if $hash;
2718 $args{'hash_base'} = $hash_base if $hash_base;
2720 print "<div class=\"header\">\n" .
2721 $cgi->a({-href
=> href
(%args), -class => "title"},
2722 $title ?
$title : $action) .
2726 #sub git_print_authorship (\%) {
2727 sub git_print_authorship
{
2730 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2731 print "<div class=\"author_date\">" .
2732 esc_html
($co->{'author_name'}) .
2734 if ($ad{'hour_local'} < 6) {
2735 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2736 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2738 printf(" (%02d:%02d %s)",
2739 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2744 sub git_print_page_path
{
2750 print "<div class=\"page_path\">";
2751 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2752 -title
=> 'tree root'}, to_utf8
("[$project]"));
2754 if (defined $name) {
2755 my @dirname = split '/', $name;
2756 my $basename = pop @dirname;
2759 foreach my $dir (@dirname) {
2760 $fullname .= ($fullname ?
'/' : '') . $dir;
2761 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2763 -title
=> $fullname}, esc_path
($dir));
2766 if (defined $type && $type eq 'blob') {
2767 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2769 -title
=> $name}, esc_path
($basename));
2770 } elsif (defined $type && $type eq 'tree') {
2771 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2773 -title
=> $name}, esc_path
($basename));
2776 print esc_path
($basename);
2779 print "<br/></div>\n";
2782 # sub git_print_log (\@;%) {
2783 sub git_print_log
($;%) {
2787 if ($opts{'-remove_title'}) {
2788 # remove title, i.e. first line of log
2791 # remove leading empty lines
2792 while (defined $log->[0] && $log->[0] eq "") {
2799 foreach my $line (@
$log) {
2800 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2803 if (! $opts{'-remove_signoff'}) {
2804 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2807 # remove signoff lines
2814 # print only one empty line
2815 # do not print empty line after signoff
2817 next if ($empty || $signoff);
2823 print format_log_line_html
($line) . "<br/>\n";
2826 if ($opts{'-final_empty_line'}) {
2827 # end with single empty line
2828 print "<br/>\n" unless $empty;
2832 # return link target (what link points to)
2833 sub git_get_link_target
{
2838 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2842 $link_target = <$fd>;
2847 return $link_target;
2850 # given link target, and the directory (basedir) the link is in,
2851 # return target of link relative to top directory (top tree);
2852 # return undef if it is not possible (including absolute links).
2853 sub normalize_link_target
{
2854 my ($link_target, $basedir, $hash_base) = @_;
2856 # we can normalize symlink target only if $hash_base is provided
2857 return unless $hash_base;
2859 # absolute symlinks (beginning with '/') cannot be normalized
2860 return if (substr($link_target, 0, 1) eq '/');
2862 # normalize link target to path from top (root) tree (dir)
2865 $path = $basedir . '/' . $link_target;
2867 # we are in top (root) tree (dir)
2868 $path = $link_target;
2871 # remove //, /./, and /../
2873 foreach my $part (split('/', $path)) {
2874 # discard '.' and ''
2875 next if (!$part || $part eq '.');
2877 if ($part eq '..') {
2881 # link leads outside repository (outside top dir)
2885 push @path_parts, $part;
2888 $path = join('/', @path_parts);
2893 # print tree entry (row of git_tree), but without encompassing <tr> element
2894 sub git_print_tree_entry
{
2895 my ($t, $basedir, $hash_base, $have_blame) = @_;
2898 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2900 # The format of a table row is: mode list link. Where mode is
2901 # the mode of the entry, list is the name of the entry, an href,
2902 # and link is the action links of the entry.
2904 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2905 if ($t->{'type'} eq "blob") {
2906 print "<td class=\"list\">" .
2907 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2908 file_name
=>"$basedir$t->{'name'}", %base_key),
2909 -class => "list"}, esc_path
($t->{'name'}));
2910 if (S_ISLNK
(oct $t->{'mode'})) {
2911 my $link_target = git_get_link_target
($t->{'hash'});
2913 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2914 if (defined $norm_target) {
2916 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2917 file_name
=>$norm_target),
2918 -title
=> $norm_target}, esc_path
($link_target));
2920 print " -> " . esc_path
($link_target);
2925 print "<td class=\"link\">";
2926 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2927 file_name
=>"$basedir$t->{'name'}", %base_key)},
2931 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2932 file_name
=>"$basedir$t->{'name'}", %base_key)},
2935 if (defined $hash_base) {
2937 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2938 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2942 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2943 file_name
=>"$basedir$t->{'name'}")},
2947 } elsif ($t->{'type'} eq "tree") {
2948 print "<td class=\"list\">";
2949 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2950 file_name
=>"$basedir$t->{'name'}", %base_key)},
2951 esc_path
($t->{'name'}));
2953 print "<td class=\"link\">";
2954 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2955 file_name
=>"$basedir$t->{'name'}", %base_key)},
2957 if (defined $hash_base) {
2959 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2960 file_name
=>"$basedir$t->{'name'}")},
2965 # unknown object: we can only present history for it
2966 # (this includes 'commit' object, i.e. submodule support)
2967 print "<td class=\"list\">" .
2968 esc_path
($t->{'name'}) .
2970 print "<td class=\"link\">";
2971 if (defined $hash_base) {
2972 print $cgi->a({-href
=> href
(action
=>"history",
2973 hash_base
=>$hash_base,
2974 file_name
=>"$basedir$t->{'name'}")},
2981 ## ......................................................................
2982 ## functions printing large fragments of HTML
2984 # get pre-image filenames for merge (combined) diff
2985 sub fill_from_file_info
{
2986 my ($diff, @parents) = @_;
2988 $diff->{'from_file'} = [ ];
2989 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2990 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2991 if ($diff->{'status'}[$i] eq 'R' ||
2992 $diff->{'status'}[$i] eq 'C') {
2993 $diff->{'from_file'}[$i] =
2994 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3001 # is current raw difftree line of file deletion
3003 my $diffinfo = shift;
3005 return $diffinfo->{'status_str'} =~ /D/;
3008 # does patch correspond to [previous] difftree raw line
3009 # $diffinfo - hashref of parsed raw diff format
3010 # $patchinfo - hashref of parsed patch diff format
3011 # (the same keys as in $diffinfo)
3012 sub is_patch_split
{
3013 my ($diffinfo, $patchinfo) = @_;
3015 return defined $diffinfo && defined $patchinfo
3016 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3020 sub git_difftree_body
{
3021 my ($difftree, $hash, @parents) = @_;
3022 my ($parent) = $parents[0];
3023 my ($have_blame) = gitweb_check_feature
('blame');
3024 print "<div class=\"list_head\">\n";
3025 if ($#{$difftree} > 10) {
3026 print(($#{$difftree} + 1) . " files changed:\n");
3030 print "<table class=\"" .
3031 (@parents > 1 ?
"combined " : "") .
3034 # header only for combined diff in 'commitdiff' view
3035 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3038 print "<thead><tr>\n" .
3039 "<th></th><th></th>\n"; # filename, patchN link
3040 for (my $i = 0; $i < @parents; $i++) {
3041 my $par = $parents[$i];
3043 $cgi->a({-href
=> href
(action
=>"commitdiff",
3044 hash
=>$hash, hash_parent
=>$par),
3045 -title
=> 'commitdiff to parent number ' .
3046 ($i+1) . ': ' . substr($par,0,7)},
3050 print "</tr></thead>\n<tbody>\n";
3055 foreach my $line (@
{$difftree}) {
3056 my $diff = parsed_difftree_line
($line);
3059 print "<tr class=\"dark\">\n";
3061 print "<tr class=\"light\">\n";
3065 if (exists $diff->{'nparents'}) { # combined diff
3067 fill_from_file_info
($diff, @parents)
3068 unless exists $diff->{'from_file'};
3070 if (!is_deleted
($diff)) {
3071 # file exists in the result (child) commit
3073 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3074 file_name
=>$diff->{'to_file'},
3076 -class => "list"}, esc_path
($diff->{'to_file'})) .
3080 esc_path
($diff->{'to_file'}) .
3084 if ($action eq 'commitdiff') {
3087 print "<td class=\"link\">" .
3088 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3093 my $has_history = 0;
3094 my $not_deleted = 0;
3095 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3096 my $hash_parent = $parents[$i];
3097 my $from_hash = $diff->{'from_id'}[$i];
3098 my $from_path = $diff->{'from_file'}[$i];
3099 my $status = $diff->{'status'}[$i];
3101 $has_history ||= ($status ne 'A');
3102 $not_deleted ||= ($status ne 'D');
3104 if ($status eq 'A') {
3105 print "<td class=\"link\" align=\"right\"> | </td>\n";
3106 } elsif ($status eq 'D') {
3107 print "<td class=\"link\">" .
3108 $cgi->a({-href
=> href
(action
=>"blob",
3111 file_name
=>$from_path)},
3115 if ($diff->{'to_id'} eq $from_hash) {
3116 print "<td class=\"link nochange\">";
3118 print "<td class=\"link\">";
3120 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3121 hash
=>$diff->{'to_id'},
3122 hash_parent
=>$from_hash,
3124 hash_parent_base
=>$hash_parent,
3125 file_name
=>$diff->{'to_file'},
3126 file_parent
=>$from_path)},
3132 print "<td class=\"link\">";
3134 print $cgi->a({-href
=> href
(action
=>"blob",
3135 hash
=>$diff->{'to_id'},
3136 file_name
=>$diff->{'to_file'},
3139 print " | " if ($has_history);
3142 print $cgi->a({-href
=> href
(action
=>"history",
3143 file_name
=>$diff->{'to_file'},
3150 next; # instead of 'else' clause, to avoid extra indent
3152 # else ordinary diff
3154 my ($to_mode_oct, $to_mode_str, $to_file_type);
3155 my ($from_mode_oct, $from_mode_str, $from_file_type);
3156 if ($diff->{'to_mode'} ne ('0' x
6)) {
3157 $to_mode_oct = oct $diff->{'to_mode'};
3158 if (S_ISREG
($to_mode_oct)) { # only for regular file
3159 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3161 $to_file_type = file_type
($diff->{'to_mode'});
3163 if ($diff->{'from_mode'} ne ('0' x
6)) {
3164 $from_mode_oct = oct $diff->{'from_mode'};
3165 if (S_ISREG
($to_mode_oct)) { # only for regular file
3166 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3168 $from_file_type = file_type
($diff->{'from_mode'});
3171 if ($diff->{'status'} eq "A") { # created
3172 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3173 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3174 $mode_chng .= "]</span>";
3176 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3177 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3178 -class => "list"}, esc_path
($diff->{'file'}));
3180 print "<td>$mode_chng</td>\n";
3181 print "<td class=\"link\">";
3182 if ($action eq 'commitdiff') {
3185 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3188 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3189 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3193 } elsif ($diff->{'status'} eq "D") { # deleted
3194 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3196 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3197 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3198 -class => "list"}, esc_path
($diff->{'file'}));
3200 print "<td>$mode_chng</td>\n";
3201 print "<td class=\"link\">";
3202 if ($action eq 'commitdiff') {
3205 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3208 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3209 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3212 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3213 file_name
=>$diff->{'file'})},
3216 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3217 file_name
=>$diff->{'file'})},
3221 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3222 my $mode_chnge = "";
3223 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3224 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3225 if ($from_file_type ne $to_file_type) {
3226 $mode_chnge .= " from $from_file_type to $to_file_type";
3228 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3229 if ($from_mode_str && $to_mode_str) {
3230 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3231 } elsif ($to_mode_str) {
3232 $mode_chnge .= " mode: $to_mode_str";
3235 $mode_chnge .= "]</span>\n";
3238 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3239 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3240 -class => "list"}, esc_path
($diff->{'file'}));
3242 print "<td>$mode_chnge</td>\n";
3243 print "<td class=\"link\">";
3244 if ($action eq 'commitdiff') {
3247 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3249 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3250 # "commit" view and modified file (not onlu mode changed)
3251 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3252 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3253 hash_base
=>$hash, hash_parent_base
=>$parent,
3254 file_name
=>$diff->{'file'})},
3258 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3259 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3262 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3263 file_name
=>$diff->{'file'})},
3266 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3267 file_name
=>$diff->{'file'})},
3271 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3272 my %status_name = ('R' => 'moved', 'C' => 'copied');
3273 my $nstatus = $status_name{$diff->{'status'}};
3275 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3276 # mode also for directories, so we cannot use $to_mode_str
3277 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3280 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3281 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3282 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3283 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3284 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3285 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3286 -class => "list"}, esc_path
($diff->{'from_file'})) .
3287 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3288 "<td class=\"link\">";
3289 if ($action eq 'commitdiff') {
3292 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3294 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3295 # "commit" view and modified file (not only pure rename or copy)
3296 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3297 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3298 hash_base
=>$hash, hash_parent_base
=>$parent,
3299 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3303 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3304 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3307 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3308 file_name
=>$diff->{'to_file'})},
3311 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3312 file_name
=>$diff->{'to_file'})},
3316 } # we should not encounter Unmerged (U) or Unknown (X) status
3319 print "</tbody>" if $has_header;
3323 sub git_patchset_body
{
3324 my ($fd, $difftree, $hash, @hash_parents) = @_;
3325 my ($hash_parent) = $hash_parents[0];
3327 my $is_combined = (@hash_parents > 1);
3329 my $patch_number = 0;
3335 print "<div class=\"patchset\">\n";
3337 # skip to first patch
3338 while ($patch_line = <$fd>) {
3341 last if ($patch_line =~ m/^diff /);
3345 while ($patch_line) {
3347 # parse "git diff" header line
3348 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3349 # $1 is from_name, which we do not use
3350 $to_name = unquote
($2);
3351 $to_name =~ s!^b/!!;
3352 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3353 # $1 is 'cc' or 'combined', which we do not use
3354 $to_name = unquote
($2);
3359 # check if current patch belong to current raw line
3360 # and parse raw git-diff line if needed
3361 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3362 # this is continuation of a split patch
3363 print "<div class=\"patch cont\">\n";
3365 # advance raw git-diff output if needed
3366 $patch_idx++ if defined $diffinfo;
3368 # read and prepare patch information
3369 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3371 # compact combined diff output can have some patches skipped
3372 # find which patch (using pathname of result) we are at now;
3374 while ($to_name ne $diffinfo->{'to_file'}) {
3375 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3376 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3377 "</div>\n"; # class="patch"
3382 last if $patch_idx > $#$difftree;
3383 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3387 # modifies %from, %to hashes
3388 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3390 # this is first patch for raw difftree line with $patch_idx index
3391 # we index @$difftree array from 0, but number patches from 1
3392 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3396 #assert($patch_line =~ m/^diff /) if DEBUG;
3397 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3399 # print "git diff" header
3400 print format_git_diff_header_line
($patch_line, $diffinfo,
3403 # print extended diff header
3404 print "<div class=\"diff extended_header\">\n";
3406 while ($patch_line = <$fd>) {
3409 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3411 print format_extended_diff_header_line
($patch_line, $diffinfo,
3414 print "</div>\n"; # class="diff extended_header"
3416 # from-file/to-file diff header
3417 if (! $patch_line) {
3418 print "</div>\n"; # class="patch"
3421 next PATCH
if ($patch_line =~ m/^diff /);
3422 #assert($patch_line =~ m/^---/) if DEBUG;
3424 my $last_patch_line = $patch_line;
3425 $patch_line = <$fd>;
3427 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3429 print format_diff_from_to_header
($last_patch_line, $patch_line,
3430 $diffinfo, \
%from, \
%to,
3435 while ($patch_line = <$fd>) {
3438 next PATCH
if ($patch_line =~ m/^diff /);
3440 print format_diff_line
($patch_line, \
%from, \
%to);
3444 print "</div>\n"; # class="patch"
3447 # for compact combined (--cc) format, with chunk and patch simpliciaction
3448 # patchset might be empty, but there might be unprocessed raw lines
3449 for (++$patch_idx if $patch_number > 0;
3450 $patch_idx < @
$difftree;
3452 # read and prepare patch information
3453 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3455 # generate anchor for "patch" links in difftree / whatchanged part
3456 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3457 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3458 "</div>\n"; # class="patch"
3463 if ($patch_number == 0) {
3464 if (@hash_parents > 1) {
3465 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3467 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3471 print "</div>\n"; # class="patchset"
3474 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3476 sub git_project_list_body
{
3477 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3479 my ($check_forks) = gitweb_check_feature
('forks');
3482 foreach my $pr (@
$projlist) {
3483 my (@aa) = git_get_last_activity
($pr->{'path'});
3487 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3488 if (!defined $pr->{'descr'}) {
3489 my $descr = git_get_project_description
($pr->{'path'}) || "";
3490 $pr->{'descr_long'} = to_utf8
($descr);
3491 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3493 if (!defined $pr->{'owner'}) {
3494 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3497 my $pname = $pr->{'path'};
3498 if (($pname =~ s/\.git$//) &&
3499 ($pname !~ /\/$/) &&
3500 (-d
"$projectroot/$pname")) {
3501 $pr->{'forks'} = "-d $projectroot/$pname";
3507 push @projects, $pr;
3510 $order ||= $default_projects_order;
3511 $from = 0 unless defined $from;
3512 $to = $#projects if (!defined $to || $#projects < $to);
3514 print "<table class=\"project_list\">\n";
3515 unless ($no_header) {
3518 print "<th></th>\n";
3520 if ($order eq "project") {
3521 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3522 print "<th>Project</th>\n";
3525 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3526 -class => "header"}, "Project") .
3529 if ($order eq "descr") {
3530 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3531 print "<th>Description</th>\n";
3534 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3535 -class => "header"}, "Description") .
3538 if ($order eq "owner") {
3539 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3540 print "<th>Owner</th>\n";
3543 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3544 -class => "header"}, "Owner") .
3547 if ($order eq "age") {
3548 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3549 print "<th>Last Change</th>\n";
3552 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3553 -class => "header"}, "Last Change") .
3556 print "<th></th>\n" .
3560 for (my $i = $from; $i <= $to; $i++) {
3561 my $pr = $projects[$i];
3563 print "<tr class=\"dark\">\n";
3565 print "<tr class=\"light\">\n";
3570 if ($pr->{'forks'}) {
3571 print "<!-- $pr->{'forks'} -->\n";
3572 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3576 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3577 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3578 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3579 -class => "list", -title
=> $pr->{'descr_long'}},
3580 esc_html
($pr->{'descr'})) . "</td>\n" .
3581 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3582 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3583 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3584 "<td class=\"link\">" .
3585 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3586 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3587 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3588 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3589 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3593 if (defined $extra) {
3596 print "<td></td>\n";
3598 print "<td colspan=\"5\">$extra</td>\n" .
3604 sub git_shortlog_body
{
3605 # uses global variable $project
3606 my ($commitlist, $from, $to, $refs, $extra) = @_;
3608 $from = 0 unless defined $from;
3609 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3611 print "<table class=\"shortlog\">\n";
3613 for (my $i = $from; $i <= $to; $i++) {
3614 my %co = %{$commitlist->[$i]};
3615 my $commit = $co{'id'};
3616 my $ref = format_ref_marker
($refs, $commit);
3618 print "<tr class=\"dark\">\n";
3620 print "<tr class=\"light\">\n";
3623 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3624 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3625 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3626 "<td><i>" . $author . "</i></td>\n" .
3628 print format_subject_html
($co{'title'}, $co{'title_short'},
3629 href
(action
=>"commit", hash
=>$commit), $ref);
3631 "<td class=\"link\">" .
3632 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3633 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3634 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3635 my $snapshot_links = format_snapshot_links
($commit);
3636 if (defined $snapshot_links) {
3637 print " | " . $snapshot_links;
3642 if (defined $extra) {
3644 "<td colspan=\"4\">$extra</td>\n" .
3650 sub git_history_body
{
3651 # Warning: assumes constant type (blob or tree) during history
3652 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3654 $from = 0 unless defined $from;
3655 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3657 print "<table class=\"history\">\n";
3659 for (my $i = $from; $i <= $to; $i++) {
3660 my %co = %{$commitlist->[$i]};
3664 my $commit = $co{'id'};
3666 my $ref = format_ref_marker
($refs, $commit);
3669 print "<tr class=\"dark\">\n";
3671 print "<tr class=\"light\">\n";
3674 # shortlog uses chop_str($co{'author_name'}, 10)
3675 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3676 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3677 "<td><i>" . $author . "</i></td>\n" .
3679 # originally git_history used chop_str($co{'title'}, 50)
3680 print format_subject_html
($co{'title'}, $co{'title_short'},
3681 href
(action
=>"commit", hash
=>$commit), $ref);
3683 "<td class=\"link\">" .
3684 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3685 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3687 if ($ftype eq 'blob') {
3688 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3689 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3690 if (defined $blob_current && defined $blob_parent &&
3691 $blob_current ne $blob_parent) {
3693 $cgi->a({-href
=> href
(action
=>"blobdiff",
3694 hash
=>$blob_current, hash_parent
=>$blob_parent,
3695 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3696 file_name
=>$file_name)},
3703 if (defined $extra) {
3705 "<td colspan=\"4\">$extra</td>\n" .
3712 # uses global variable $project
3713 my ($taglist, $from, $to, $extra) = @_;
3714 $from = 0 unless defined $from;
3715 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3717 print "<table class=\"tags\">\n";
3719 for (my $i = $from; $i <= $to; $i++) {
3720 my $entry = $taglist->[$i];
3722 my $comment = $tag{'subject'};
3724 if (defined $comment) {
3725 $comment_short = chop_str
($comment, 30, 5);
3728 print "<tr class=\"dark\">\n";
3730 print "<tr class=\"light\">\n";
3733 if (defined $tag{'age'}) {
3734 print "<td><i>$tag{'age'}</i></td>\n";
3736 print "<td></td>\n";
3739 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3740 -class => "list name"}, esc_html
($tag{'name'})) .
3743 if (defined $comment) {
3744 print format_subject_html
($comment, $comment_short,
3745 href
(action
=>"tag", hash
=>$tag{'id'}));
3748 "<td class=\"selflink\">";
3749 if ($tag{'type'} eq "tag") {
3750 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3755 "<td class=\"link\">" . " | " .
3756 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3757 if ($tag{'reftype'} eq "commit") {
3758 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3759 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3760 } elsif ($tag{'reftype'} eq "blob") {
3761 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3766 if (defined $extra) {
3768 "<td colspan=\"5\">$extra</td>\n" .
3774 sub git_heads_body
{
3775 # uses global variable $project
3776 my ($headlist, $head, $from, $to, $extra) = @_;
3777 $from = 0 unless defined $from;
3778 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3780 print "<table class=\"heads\">\n";
3782 for (my $i = $from; $i <= $to; $i++) {
3783 my $entry = $headlist->[$i];
3785 my $curr = $ref{'id'} eq $head;
3787 print "<tr class=\"dark\">\n";
3789 print "<tr class=\"light\">\n";
3792 print "<td><i>$ref{'age'}</i></td>\n" .
3793 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3794 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3795 -class => "list name"},esc_html
($ref{'name'})) .
3797 "<td class=\"link\">" .
3798 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3799 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3800 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3804 if (defined $extra) {
3806 "<td colspan=\"3\">$extra</td>\n" .
3812 sub git_search_grep_body
{
3813 my ($commitlist, $from, $to, $extra) = @_;
3814 $from = 0 unless defined $from;
3815 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3817 print "<table class=\"commit_search\">\n";
3819 for (my $i = $from; $i <= $to; $i++) {
3820 my %co = %{$commitlist->[$i]};
3824 my $commit = $co{'id'};
3826 print "<tr class=\"dark\">\n";
3828 print "<tr class=\"light\">\n";
3831 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3832 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3833 "<td><i>" . $author . "</i></td>\n" .
3835 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3836 -class => "list subject"},
3837 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3838 my $comment = $co{'comment'};
3839 foreach my $line (@
$comment) {
3840 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3841 my ($lead, $match, $trail) = ($1, $2, $3);
3842 $match = chop_str
($match, 70, 5, 'center');
3843 my $contextlen = int((80 - length($match))/2);
3844 $contextlen = 30 if ($contextlen > 30);
3845 $lead = chop_str
($lead, $contextlen, 10, 'left');
3846 $trail = chop_str
($trail, $contextlen, 10, 'right');
3848 $lead = esc_html
($lead);
3849 $match = esc_html
($match);
3850 $trail = esc_html
($trail);
3852 print "$lead<span class=\"match\">$match</span>$trail<br />";
3856 "<td class=\"link\">" .
3857 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3859 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3861 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3865 if (defined $extra) {
3867 "<td colspan=\"3\">$extra</td>\n" .
3873 ## ======================================================================
3874 ## ======================================================================
3877 sub git_project_list
{
3878 my $order = $cgi->param('o');
3879 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3880 die_error
(undef, "Unknown order parameter");
3883 my @list = git_get_projects_list
();
3885 die_error
(undef, "No projects found");
3889 if (-f
$home_text) {
3890 print "<div class=\"index_include\">\n";
3891 open (my $fd, $home_text);
3896 git_project_list_body
(\
@list, $order);
3901 my $order = $cgi->param('o');
3902 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3903 die_error
(undef, "Unknown order parameter");
3906 my @list = git_get_projects_list
($project);
3908 die_error
(undef, "No forks found");
3912 git_print_page_nav
('','');
3913 git_print_header_div
('summary', "$project forks");
3914 git_project_list_body
(\
@list, $order);
3918 sub git_project_index
{
3919 my @projects = git_get_projects_list
($project);
3922 -type
=> 'text/plain',
3923 -charset
=> 'utf-8',
3924 -content_disposition
=> 'inline; filename="index.aux"');
3926 foreach my $pr (@projects) {
3927 if (!exists $pr->{'owner'}) {
3928 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3931 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3932 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3933 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3934 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3938 print "$path $owner\n";
3943 my $descr = git_get_project_description
($project) || "none";
3944 my %co = parse_commit
("HEAD");
3945 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3946 my $head = $co{'id'};
3948 my $owner = git_get_project_owner
($project);
3950 my $refs = git_get_references
();
3951 # These get_*_list functions return one more to allow us to see if
3952 # there are more ...
3953 my @taglist = git_get_tags_list
(16);
3954 my @headlist = git_get_heads_list
(16);
3956 my ($check_forks) = gitweb_check_feature
('forks');
3959 @forklist = git_get_projects_list
($project);
3963 git_print_page_nav
('summary','', $head);
3965 print "<div class=\"title\"> </div>\n";
3966 print "<table class=\"projects_list\">\n" .
3967 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3968 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3969 if (defined $cd{'rfc2822'}) {
3970 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3973 # use per project git URL list in $projectroot/$project/cloneurl
3974 # or make project git URL from git base URL and project name
3975 my $url_tag = "URL";
3976 my @url_list = git_get_project_url_list
($project);
3977 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3978 foreach my $git_url (@url_list) {
3979 next unless $git_url;
3980 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3985 if (-s
"$projectroot/$project/README.html") {
3986 if (open my $fd, "$projectroot/$project/README.html") {
3987 print "<div class=\"title\">readme</div>\n" .
3988 "<div class=\"readme\">\n";
3989 print $_ while (<$fd>);
3990 print "\n</div>\n"; # class="readme"
3995 # we need to request one more than 16 (0..15) to check if
3997 my @commitlist = $head ? parse_commits
($head, 17) : ();
3999 git_print_header_div
('shortlog');
4000 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4001 $#commitlist <= 15 ?
undef :
4002 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4006 git_print_header_div
('tags');
4007 git_tags_body
(\
@taglist, 0, 15,
4008 $#taglist <= 15 ?
undef :
4009 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4013 git_print_header_div
('heads');
4014 git_heads_body
(\
@headlist, $head, 0, 15,
4015 $#headlist <= 15 ?
undef :
4016 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4020 git_print_header_div
('forks');
4021 git_project_list_body
(\
@forklist, undef, 0, 15,
4022 $#forklist <= 15 ?
undef :
4023 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4031 my $head = git_get_head_hash
($project);
4033 git_print_page_nav
('','', $head,undef,$head);
4034 my %tag = parse_tag
($hash);
4037 die_error
(undef, "Unknown tag object");
4040 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4041 print "<div class=\"title_text\">\n" .
4042 "<table class=\"object_header\">\n" .
4044 "<td>object</td>\n" .
4045 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4046 $tag{'object'}) . "</td>\n" .
4047 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4048 $tag{'type'}) . "</td>\n" .
4050 if (defined($tag{'author'})) {
4051 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4052 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4053 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4054 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4057 print "</table>\n\n" .
4059 print "<div class=\"page_body\">";
4060 my $comment = $tag{'comment'};
4061 foreach my $line (@
$comment) {
4063 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4073 my ($have_blame) = gitweb_check_feature
('blame');
4075 die_error
('403 Permission denied', "Permission denied");
4077 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4078 $hash_base ||= git_get_head_hash
($project);
4079 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4080 my %co = parse_commit
($hash_base)
4081 or die_error
(undef, "Reading commit failed");
4082 if (!defined $hash) {
4083 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4084 or die_error
(undef, "Error looking up file");
4086 $ftype = git_get_type
($hash);
4087 if ($ftype !~ "blob") {
4088 die_error
('400 Bad Request', "Object is not a blob");
4090 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4091 $file_name, $hash_base)
4092 or die_error
(undef, "Open git-blame failed");
4095 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4098 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4101 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4103 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4104 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4105 git_print_page_path
($file_name, $ftype, $hash_base);
4106 my @rev_color = (qw(light2 dark2));
4107 my $num_colors = scalar(@rev_color);
4108 my $current_color = 0;
4111 <div class="page_body">
4112 <table class="blame">
4113 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4118 last unless defined $_;
4119 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4120 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4121 if (!exists $metainfo{$full_rev}) {
4122 $metainfo{$full_rev} = {};
4124 my $meta = $metainfo{$full_rev};
4127 if (/^(\S+) (.*)$/) {
4133 my $rev = substr($full_rev, 0, 8);
4134 my $author = $meta->{'author'};
4135 my %date = parse_date
($meta->{'author-time'},
4136 $meta->{'author-tz'});
4137 my $date = $date{'iso-tz'};
4139 $current_color = ++$current_color % $num_colors;
4141 print "<tr class=\"$rev_color[$current_color]\">\n";
4143 print "<td class=\"sha1\"";
4144 print " title=\"". esc_html
($author) . ", $date\"";
4145 print " rowspan=\"$group_size\"" if ($group_size > 1);
4147 print $cgi->a({-href
=> href
(action
=>"commit",
4149 file_name
=>$file_name)},
4153 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4154 or die_error
(undef, "Open git-rev-parse failed");
4155 my $parent_commit = <$dd>;
4157 chomp($parent_commit);
4158 my $blamed = href
(action
=> 'blame',
4159 file_name
=> $meta->{'filename'},
4160 hash_base
=> $parent_commit);
4161 print "<td class=\"linenr\">";
4162 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4164 -class => "linenr" },
4167 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4173 or print "Reading blob failed\n";
4180 my ($have_blame) = gitweb_check_feature
('blame');
4182 die_error
('403 Permission denied', "Permission denied");
4184 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4185 $hash_base ||= git_get_head_hash
($project);
4186 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4187 my %co = parse_commit
($hash_base)
4188 or die_error
(undef, "Reading commit failed");
4189 if (!defined $hash) {
4190 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4191 or die_error
(undef, "Error lookup file");
4193 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4194 or die_error
(undef, "Open git-annotate failed");
4197 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4200 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4203 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4205 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4206 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4207 git_print_page_path
($file_name, 'blob', $hash_base);
4208 print "<div class=\"page_body\">\n";
4210 <table class="blame">
4219 my @line_class = (qw(light dark));
4220 my $line_class_len = scalar (@line_class);
4221 my $line_class_num = $#line_class;
4222 while (my $line = <$fd>) {
4234 $line_class_num = ($line_class_num + 1) % $line_class_len;
4236 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4243 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4246 $short_rev = substr ($long_rev, 0, 8);
4247 $age = time () - $time;
4248 $age_str = age_string
($age);
4249 $age_str =~ s/ / /g;
4250 $age_class = age_class
($age);
4251 $author = esc_html
($author);
4252 $author =~ s/ / /g;
4254 $data = untabify
($data);
4255 $data = esc_html
($data);
4258 <tr class="$line_class[$line_class_num]">
4259 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4260 <td class="$age_class">$age_str</td>
4262 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4263 <td class="pre">$data</td>
4266 } # while (my $line = <$fd>)
4267 print "</table>\n\n";
4269 or print "Reading blob failed.\n";
4275 my $head = git_get_head_hash
($project);
4277 git_print_page_nav
('','', $head,undef,$head);
4278 git_print_header_div
('summary', $project);
4280 my @tagslist = git_get_tags_list
();
4282 git_tags_body
(\
@tagslist);
4288 my $head = git_get_head_hash
($project);
4290 git_print_page_nav
('','', $head,undef,$head);
4291 git_print_header_div
('summary', $project);
4293 my @headslist = git_get_heads_list
();
4295 git_heads_body
(\
@headslist, $head);
4300 sub git_blob_plain
{
4303 if (!defined $hash) {
4304 if (defined $file_name) {
4305 my $base = $hash_base || git_get_head_hash
($project);
4306 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4307 or die_error
(undef, "Error lookup file");
4309 die_error
(undef, "No file name defined");
4311 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4312 # blobs defined by non-textual hash id's can be cached
4317 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4318 or die_error
(undef, "Couldn't cat $file_name, $hash");
4320 $type ||= blob_mimetype
($fd, $file_name);
4322 # save as filename, even when no $file_name is given
4323 my $save_as = "$hash";
4324 if (defined $file_name) {
4325 $save_as = $file_name;
4326 } elsif ($type =~ m/^text\//) {
4333 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4335 binmode STDOUT
, ':raw';
4337 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4345 if (!defined $hash) {
4346 if (defined $file_name) {
4347 my $base = $hash_base || git_get_head_hash
($project);
4348 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4349 or die_error
(undef, "Error lookup file");
4351 die_error
(undef, "No file name defined");
4353 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4354 # blobs defined by non-textual hash id's can be cached
4358 my ($have_blame) = gitweb_check_feature
('blame');
4359 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4360 or die_error
(undef, "Couldn't cat $file_name, $hash");
4361 my $mimetype = blob_mimetype
($fd, $file_name);
4362 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4364 return git_blob_plain
($mimetype);
4366 # we can have blame only for text/* mimetype
4367 $have_blame &&= ($mimetype =~ m!^text/!);
4369 git_header_html
(undef, $expires);
4370 my $formats_nav = '';
4371 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4372 if (defined $file_name) {
4375 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4380 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4383 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4386 $cgi->a({-href
=> href
(action
=>"blob",
4387 hash_base
=>"HEAD", file_name
=>$file_name)},
4391 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4394 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4395 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4397 print "<div class=\"page_nav\">\n" .
4398 "<br/><br/></div>\n" .
4399 "<div class=\"title\">$hash</div>\n";
4401 git_print_page_path
($file_name, "blob", $hash_base);
4402 print "<div class=\"page_body\">\n";
4403 if ($mimetype =~ m!^image/!) {
4404 print qq!<img type
="$mimetype"!;
4406 print qq! alt
="$file_name" title
="$file_name"!;
4409 href(action=>"blob_plain
", hash=>$hash,
4410 hash_base=>$hash_base, file_name=>$file_name) .
4414 while (my $line = <$fd>) {
4417 $line = untabify
($line);
4418 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4419 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4423 or print "Reading blob failed.\n";
4429 if (!defined $hash_base) {
4430 $hash_base = "HEAD";
4432 if (!defined $hash) {
4433 if (defined $file_name) {
4434 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4440 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4441 or die_error
(undef, "Open git-ls-tree failed");
4442 my @entries = map { chomp; $_ } <$fd>;
4443 close $fd or die_error
(undef, "Reading tree failed");
4446 my $refs = git_get_references
();
4447 my $ref = format_ref_marker
($refs, $hash_base);
4450 my ($have_blame) = gitweb_check_feature
('blame');
4451 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4453 if (defined $file_name) {
4455 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4457 $cgi->a({-href
=> href
(action
=>"tree",
4458 hash_base
=>"HEAD", file_name
=>$file_name)},
4461 my $snapshot_links = format_snapshot_links
($hash);
4462 if (defined $snapshot_links) {
4463 # FIXME: Should be available when we have no hash base as well.
4464 push @views_nav, $snapshot_links;
4466 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4467 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4470 print "<div class=\"page_nav\">\n";
4471 print "<br/><br/></div>\n";
4472 print "<div class=\"title\">$hash</div>\n";
4474 if (defined $file_name) {
4475 $basedir = $file_name;
4476 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4480 git_print_page_path
($file_name, 'tree', $hash_base);
4481 print "<div class=\"page_body\">\n";
4482 print "<table class=\"tree\">\n";
4484 # '..' (top directory) link if possible
4485 if (defined $hash_base &&
4486 defined $file_name && $file_name =~ m![^/]+$!) {
4488 print "<tr class=\"dark\">\n";
4490 print "<tr class=\"light\">\n";
4494 my $up = $file_name;
4495 $up =~ s!/?[^/]+$!!;
4496 undef $up unless $up;
4497 # based on git_print_tree_entry
4498 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4499 print '<td class="list">';
4500 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4504 print "<td class=\"link\"></td>\n";
4508 foreach my $line (@entries) {
4509 my %t = parse_ls_tree_line
($line, -z
=> 1);
4512 print "<tr class=\"dark\">\n";
4514 print "<tr class=\"light\">\n";
4518 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4522 print "</table>\n" .
4528 my @supported_fmts = gitweb_check_feature
('snapshot');
4529 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4531 my $format = $cgi->param('sf');
4532 if (!@supported_fmts) {
4533 die_error
('403 Permission denied', "Permission denied");
4535 # default to first supported snapshot format
4536 $format ||= $supported_fmts[0];
4537 if ($format !~ m/^[a-z0-9]+$/) {
4538 die_error
(undef, "Invalid snapshot format parameter");
4539 } elsif (!exists($known_snapshot_formats{$format})) {
4540 die_error
(undef, "Unknown snapshot format");
4541 } elsif (!grep($_ eq $format, @supported_fmts)) {
4542 die_error
(undef, "Unsupported snapshot format");
4545 if (!defined $hash) {
4546 $hash = git_get_head_hash
($project);
4549 my $git_command = git_cmd_str
();
4550 my $name = $project;
4551 $name =~ s
,([^/])/*\
.git
$,$1,;
4552 $name = basename
($name);
4553 my $filename = to_utf8
($name);
4554 $name =~ s/\047/\047\\\047\047/g;
4556 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4557 $cmd = "$git_command archive " .
4558 "--format=$known_snapshot_formats{$format}{'format'} " .
4559 "--prefix=\'$name\'/ $hash";
4560 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4561 $cmd .= ' | ' . join ' ', @
{$known_snapshot_formats{$format}{'compressor'}};
4565 -type
=> $known_snapshot_formats{$format}{'type'},
4566 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4567 -status
=> '200 OK');
4569 open my $fd, "-|", $cmd
4570 or die_error
(undef, "Execute git-archive failed");
4571 binmode STDOUT
, ':raw';
4573 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4578 my $head = git_get_head_hash
($project);
4579 if (!defined $hash) {
4582 if (!defined $page) {
4585 my $refs = git_get_references
();
4587 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4589 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4592 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4595 my %co = parse_commit
($hash);
4597 git_print_header_div
('summary', $project);
4598 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4600 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4601 for (my $i = 0; $i <= $to; $i++) {
4602 my %co = %{$commitlist[$i]};
4604 my $commit = $co{'id'};
4605 my $ref = format_ref_marker
($refs, $commit);
4606 my %ad = parse_date
($co{'author_epoch'});
4607 git_print_header_div
('commit',
4608 "<span class=\"age\">$co{'age_string'}</span>" .
4609 esc_html
($co{'title'}) . $ref,
4611 print "<div class=\"title_text\">\n" .
4612 "<div class=\"log_link\">\n" .
4613 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4615 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4617 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4620 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4623 print "<div class=\"log_body\">\n";
4624 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4627 if ($#commitlist >= 100) {
4628 print "<div class=\"page_nav\">\n";
4629 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4630 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4637 $hash ||= $hash_base || "HEAD";
4638 my %co = parse_commit
($hash);
4640 die_error
(undef, "Unknown commit object");
4642 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4643 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4645 my $parent = $co{'parent'};
4646 my $parents = $co{'parents'}; # listref
4648 # we need to prepare $formats_nav before any parameter munging
4650 if (!defined $parent) {
4652 $formats_nav .= '(initial)';
4653 } elsif (@
$parents == 1) {
4654 # single parent commit
4657 $cgi->a({-href
=> href
(action
=>"commit",
4659 esc_html
(substr($parent, 0, 7))) .
4666 $cgi->a({-href
=> href
(action
=>"commit",
4668 esc_html
(substr($_, 0, 7)));
4673 if (!defined $parent) {
4677 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4679 (@
$parents <= 1 ?
$parent : '-c'),
4681 or die_error
(undef, "Open git-diff-tree failed");
4682 @difftree = map { chomp; $_ } <$fd>;
4683 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4685 # non-textual hash id's can be cached
4687 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4690 my $refs = git_get_references
();
4691 my $ref = format_ref_marker
($refs, $co{'id'});
4693 git_header_html
(undef, $expires);
4694 git_print_page_nav
('commit', '',
4695 $hash, $co{'tree'}, $hash,
4698 if (defined $co{'parent'}) {
4699 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4701 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4703 print "<div class=\"title_text\">\n" .
4704 "<table class=\"object_header\">\n";
4705 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4707 "<td></td><td> $ad{'rfc2822'}";
4708 if ($ad{'hour_local'} < 6) {
4709 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4710 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4712 printf(" (%02d:%02d %s)",
4713 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4717 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4718 print "<tr><td></td><td> $cd{'rfc2822'}" .
4719 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4721 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4724 "<td class=\"sha1\">" .
4725 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4726 class => "list"}, $co{'tree'}) .
4728 "<td class=\"link\">" .
4729 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4731 my $snapshot_links = format_snapshot_links
($hash);
4732 if (defined $snapshot_links) {
4733 print " | " . $snapshot_links;
4738 foreach my $par (@
$parents) {
4741 "<td class=\"sha1\">" .
4742 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4743 class => "list"}, $par) .
4745 "<td class=\"link\">" .
4746 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4748 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4755 print "<div class=\"page_body\">\n";
4756 git_print_log
($co{'comment'});
4759 git_difftree_body
(\
@difftree, $hash, @
$parents);
4765 # object is defined by:
4766 # - hash or hash_base alone
4767 # - hash_base and file_name
4770 # - hash or hash_base alone
4771 if ($hash || ($hash_base && !defined $file_name)) {
4772 my $object_id = $hash || $hash_base;
4774 my $git_command = git_cmd_str
();
4775 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4776 or die_error
('404 Not Found', "Object does not exist");
4780 or die_error
('404 Not Found', "Object does not exist");
4782 # - hash_base and file_name
4783 } elsif ($hash_base && defined $file_name) {
4784 $file_name =~ s
,/+$,,;
4786 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4787 or die_error
('404 Not Found', "Base object does not exist");
4789 # here errors should not hapen
4790 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4791 or die_error
(undef, "Open git-ls-tree failed");
4795 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4796 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4797 die_error
('404 Not Found', "File or directory for given base does not exist");
4802 die_error
('404 Not Found', "Not enough information to find object");
4805 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4806 hash
=>$hash, hash_base
=>$hash_base,
4807 file_name
=>$file_name),
4808 -status
=> '302 Found');
4812 my $format = shift || 'html';
4819 # preparing $fd and %diffinfo for git_patchset_body
4821 if (defined $hash_base && defined $hash_parent_base) {
4822 if (defined $file_name) {
4824 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4825 $hash_parent_base, $hash_base,
4826 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4827 or die_error
(undef, "Open git-diff-tree failed");
4828 @difftree = map { chomp; $_ } <$fd>;
4830 or die_error
(undef, "Reading git-diff-tree failed");
4832 or die_error
('404 Not Found', "Blob diff not found");
4834 } elsif (defined $hash &&
4835 $hash =~ /[0-9a-fA-F]{40}/) {
4836 # try to find filename from $hash
4838 # read filtered raw output
4839 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4840 $hash_parent_base, $hash_base, "--"
4841 or die_error
(undef, "Open git-diff-tree failed");
4843 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4845 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4846 map { chomp; $_ } <$fd>;
4848 or die_error
(undef, "Reading git-diff-tree failed");
4850 or die_error
('404 Not Found', "Blob diff not found");
4853 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4856 if (@difftree > 1) {
4857 die_error
('404 Not Found', "Ambiguous blob diff specification");
4860 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4861 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4862 $file_name ||= $diffinfo{'to_file'};
4864 $hash_parent ||= $diffinfo{'from_id'};
4865 $hash ||= $diffinfo{'to_id'};
4867 # non-textual hash id's can be cached
4868 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4869 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4874 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4875 '-p', ($format eq 'html' ?
"--full-index" : ()),
4876 $hash_parent_base, $hash_base,
4877 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4878 or die_error
(undef, "Open git-diff-tree failed");
4881 # old/legacy style URI
4882 if (!%diffinfo && # if new style URI failed
4883 defined $hash && defined $hash_parent) {
4884 # fake git-diff-tree raw output
4885 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4886 $diffinfo{'from_id'} = $hash_parent;
4887 $diffinfo{'to_id'} = $hash;
4888 if (defined $file_name) {
4889 if (defined $file_parent) {
4890 $diffinfo{'status'} = '2';
4891 $diffinfo{'from_file'} = $file_parent;
4892 $diffinfo{'to_file'} = $file_name;
4893 } else { # assume not renamed
4894 $diffinfo{'status'} = '1';
4895 $diffinfo{'from_file'} = $file_name;
4896 $diffinfo{'to_file'} = $file_name;
4898 } else { # no filename given
4899 $diffinfo{'status'} = '2';
4900 $diffinfo{'from_file'} = $hash_parent;
4901 $diffinfo{'to_file'} = $hash;
4904 # non-textual hash id's can be cached
4905 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4906 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4911 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4912 '-p', ($format eq 'html' ?
"--full-index" : ()),
4913 $hash_parent, $hash, "--"
4914 or die_error
(undef, "Open git-diff failed");
4916 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4921 if ($format eq 'html') {
4923 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4925 git_header_html
(undef, $expires);
4926 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4927 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4928 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4930 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4931 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4933 if (defined $file_name) {
4934 git_print_page_path
($file_name, "blob", $hash_base);
4936 print "<div class=\"page_path\"></div>\n";
4939 } elsif ($format eq 'plain') {
4941 -type
=> 'text/plain',
4942 -charset
=> 'utf-8',
4943 -expires
=> $expires,
4944 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4946 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4949 die_error
(undef, "Unknown blobdiff format");
4953 if ($format eq 'html') {
4954 print "<div class=\"page_body\">\n";
4956 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4959 print "</div>\n"; # class="page_body"
4963 while (my $line = <$fd>) {
4964 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4965 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4969 last if $line =~ m!^\+\+\+!;
4977 sub git_blobdiff_plain
{
4978 git_blobdiff
('plain');
4981 sub git_commitdiff
{
4982 my $format = shift || 'html';
4983 $hash ||= $hash_base || "HEAD";
4984 my %co = parse_commit
($hash);
4986 die_error
(undef, "Unknown commit object");
4989 # choose format for commitdiff for merge
4990 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4991 $hash_parent = '--cc';
4993 # we need to prepare $formats_nav before almost any parameter munging
4995 if ($format eq 'html') {
4997 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5000 if (defined $hash_parent &&
5001 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5002 # commitdiff with two commits given
5003 my $hash_parent_short = $hash_parent;
5004 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5005 $hash_parent_short = substr($hash_parent, 0, 7);
5009 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5010 if ($co{'parents'}[$i] eq $hash_parent) {
5011 $formats_nav .= ' parent ' . ($i+1);
5015 $formats_nav .= ': ' .
5016 $cgi->a({-href
=> href
(action
=>"commitdiff",
5017 hash
=>$hash_parent)},
5018 esc_html
($hash_parent_short)) .
5020 } elsif (!$co{'parent'}) {
5022 $formats_nav .= ' (initial)';
5023 } elsif (scalar @
{$co{'parents'}} == 1) {
5024 # single parent commit
5027 $cgi->a({-href
=> href
(action
=>"commitdiff",
5028 hash
=>$co{'parent'})},
5029 esc_html
(substr($co{'parent'}, 0, 7))) .
5033 if ($hash_parent eq '--cc') {
5034 $formats_nav .= ' | ' .
5035 $cgi->a({-href
=> href
(action
=>"commitdiff",
5036 hash
=>$hash, hash_parent
=>'-c')},
5038 } else { # $hash_parent eq '-c'
5039 $formats_nav .= ' | ' .
5040 $cgi->a({-href
=> href
(action
=>"commitdiff",
5041 hash
=>$hash, hash_parent
=>'--cc')},
5047 $cgi->a({-href
=> href
(action
=>"commitdiff",
5049 esc_html
(substr($_, 0, 7)));
5050 } @
{$co{'parents'}} ) .
5055 my $hash_parent_param = $hash_parent;
5056 if (!defined $hash_parent_param) {
5057 # --cc for multiple parents, --root for parentless
5058 $hash_parent_param =
5059 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5065 if ($format eq 'html') {
5066 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5067 "--no-commit-id", "--patch-with-raw", "--full-index",
5068 $hash_parent_param, $hash, "--"
5069 or die_error
(undef, "Open git-diff-tree failed");
5071 while (my $line = <$fd>) {
5073 # empty line ends raw part of diff-tree output
5075 push @difftree, scalar parse_difftree_raw_line
($line);
5078 } elsif ($format eq 'plain') {
5079 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5080 '-p', $hash_parent_param, $hash, "--"
5081 or die_error
(undef, "Open git-diff-tree failed");
5084 die_error
(undef, "Unknown commitdiff format");
5087 # non-textual hash id's can be cached
5089 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5093 # write commit message
5094 if ($format eq 'html') {
5095 my $refs = git_get_references
();
5096 my $ref = format_ref_marker
($refs, $co{'id'});
5098 git_header_html
(undef, $expires);
5099 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5100 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5101 git_print_authorship
(\
%co);
5102 print "<div class=\"page_body\">\n";
5103 if (@
{$co{'comment'}} > 1) {
5104 print "<div class=\"log\">\n";
5105 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5106 print "</div>\n"; # class="log"
5109 } elsif ($format eq 'plain') {
5110 my $refs = git_get_references
("tags");
5111 my $tagname = git_get_rev_name_tags
($hash);
5112 my $filename = basename
($project) . "-$hash.patch";
5115 -type
=> 'text/plain',
5116 -charset
=> 'utf-8',
5117 -expires
=> $expires,
5118 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5119 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5120 print "From: " . to_utf8
($co{'author'}) . "\n";
5121 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5122 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5124 print "X-Git-Tag: $tagname\n" if $tagname;
5125 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5127 foreach my $line (@
{$co{'comment'}}) {
5128 print to_utf8
($line) . "\n";
5134 if ($format eq 'html') {
5135 my $use_parents = !defined $hash_parent ||
5136 $hash_parent eq '-c' || $hash_parent eq '--cc';
5137 git_difftree_body
(\
@difftree, $hash,
5138 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5141 git_patchset_body
($fd, \
@difftree, $hash,
5142 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5144 print "</div>\n"; # class="page_body"
5147 } elsif ($format eq 'plain') {
5151 or print "Reading git-diff-tree failed\n";
5155 sub git_commitdiff_plain
{
5156 git_commitdiff
('plain');
5160 if (!defined $hash_base) {
5161 $hash_base = git_get_head_hash
($project);
5163 if (!defined $page) {
5167 my %co = parse_commit
($hash_base);
5169 die_error
(undef, "Unknown commit object");
5172 my $refs = git_get_references
();
5173 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5175 if (!defined $hash && defined $file_name) {
5176 $hash = git_get_hash_by_path
($hash_base, $file_name);
5178 if (defined $hash) {
5179 $ftype = git_get_type
($hash);
5182 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), $file_name, "--full-history");
5184 my $paging_nav = '';
5187 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5188 file_name
=>$file_name)},
5190 $paging_nav .= " ⋅ " .
5191 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5192 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5194 $paging_nav .= "first";
5195 $paging_nav .= " ⋅ prev";
5198 if ($#commitlist >= 100) {
5200 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5201 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5202 $paging_nav .= " ⋅ $next_link";
5204 $paging_nav .= " ⋅ next";
5208 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5209 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5210 git_print_page_path
($file_name, $ftype, $hash_base);
5212 git_history_body
(\
@commitlist, 0, 99,
5213 $refs, $hash_base, $ftype, $next_link);
5219 my ($have_search) = gitweb_check_feature
('search');
5220 if (!$have_search) {
5221 die_error
('403 Permission denied', "Permission denied");
5223 if (!defined $searchtext) {
5224 die_error
(undef, "Text field empty");
5226 if (!defined $hash) {
5227 $hash = git_get_head_hash
($project);
5229 my %co = parse_commit
($hash);
5231 die_error
(undef, "Unknown commit object");
5233 if (!defined $page) {
5237 $searchtype ||= 'commit';
5238 if ($searchtype eq 'pickaxe') {
5239 # pickaxe may take all resources of your box and run for several minutes
5240 # with every query - so decide by yourself how public you make this feature
5241 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5242 if (!$have_pickaxe) {
5243 die_error
('403 Permission denied', "Permission denied");
5246 if ($searchtype eq 'grep') {
5247 my ($have_grep) = gitweb_check_feature
('grep');
5249 die_error
('403 Permission denied', "Permission denied");
5255 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5257 if ($searchtype eq 'commit') {
5258 $greptype = "--grep=";
5259 } elsif ($searchtype eq 'author') {
5260 $greptype = "--author=";
5261 } elsif ($searchtype eq 'committer') {
5262 $greptype = "--committer=";
5264 $greptype .= $searchtext;
5265 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5266 $greptype, '--regexp-ignore-case',
5267 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5269 my $paging_nav = '';
5272 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5273 searchtext
=>$searchtext,
5274 searchtype
=>$searchtype)},
5276 $paging_nav .= " ⋅ " .
5277 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5278 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5280 $paging_nav .= "first";
5281 $paging_nav .= " ⋅ prev";
5284 if ($#commitlist >= 100) {
5286 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5287 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5288 $paging_nav .= " ⋅ $next_link";
5290 $paging_nav .= " ⋅ next";
5293 if ($#commitlist >= 100) {
5296 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5297 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5298 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5301 if ($searchtype eq 'pickaxe') {
5302 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5303 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5305 print "<table class=\"pickaxe search\">\n";
5308 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5309 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5310 ($search_use_regexp ?
'--pickaxe-regex' : ());
5313 while (my $line = <$fd>) {
5317 my %set = parse_difftree_raw_line
($line);
5318 if (defined $set{'commit'}) {
5319 # finish previous commit
5322 "<td class=\"link\">" .
5323 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5325 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5331 print "<tr class=\"dark\">\n";
5333 print "<tr class=\"light\">\n";
5336 %co = parse_commit
($set{'commit'});
5337 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5338 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5339 "<td><i>$author</i></td>\n" .
5341 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5342 -class => "list subject"},
5343 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5344 } elsif (defined $set{'to_id'}) {
5345 next if ($set{'to_id'} =~ m/^0{40}$/);
5347 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5348 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5350 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5356 # finish last commit (warning: repetition!)
5359 "<td class=\"link\">" .
5360 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5362 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5370 if ($searchtype eq 'grep') {
5371 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5372 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5374 print "<table class=\"grep_search\">\n";
5378 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5379 $search_use_regexp ?
('-E', '-i') : '-F',
5380 $searchtext, $co{'tree'};
5382 while (my $line = <$fd>) {
5384 my ($file, $lno, $ltext, $binary);
5385 last if ($matches++ > 1000);
5386 if ($line =~ /^Binary file (.+) matches$/) {
5390 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5392 if ($file ne $lastfile) {
5393 $lastfile and print "</td></tr>\n";
5395 print "<tr class=\"dark\">\n";
5397 print "<tr class=\"light\">\n";
5399 print "<td class=\"list\">".
5400 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5401 file_name
=>"$file"),
5402 -class => "list"}, esc_path
($file));
5403 print "</td><td>\n";
5407 print "<div class=\"binary\">Binary file</div>\n";
5409 $ltext = untabify
($ltext);
5410 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5411 $ltext = esc_html
($1, -nbsp
=>1);
5412 $ltext .= '<span class="match">';
5413 $ltext .= esc_html
($2, -nbsp
=>1);
5414 $ltext .= '</span>';
5415 $ltext .= esc_html
($3, -nbsp
=>1);
5417 $ltext = esc_html
($ltext, -nbsp
=>1);
5419 print "<div class=\"pre\">" .
5420 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5421 file_name
=>"$file").'#l'.$lno,
5422 -class => "linenr"}, sprintf('%4i', $lno))
5423 . ' ' . $ltext . "</div>\n";
5427 print "</td></tr>\n";
5428 if ($matches > 1000) {
5429 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5432 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5441 sub git_search_help
{
5443 git_print_page_nav
('','', $hash,$hash,$hash);
5445 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5446 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5447 the pattern entered is recognized as the POSIX extended
5448 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5451 <dt><b>commit</b></dt>
5452 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5454 my ($have_grep) = gitweb_check_feature
('grep');
5457 <dt><b>grep</b></dt>
5458 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5459 a different one) are searched for the given pattern. On large trees, this search can take
5460 a while and put some strain on the server, so please use it with some consideration. Note that
5461 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5462 case-sensitive.</dd>
5466 <dt><b>author</b></dt>
5467 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5468 <dt><b>committer</b></dt>
5469 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5471 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5472 if ($have_pickaxe) {
5474 <dt><b>pickaxe</b></dt>
5475 <dd>All commits that caused the string to appear or disappear from any file (changes that
5476 added, removed or "modified" the string) will be listed. This search can take a while and
5477 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5478 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5486 my $head = git_get_head_hash
($project);
5487 if (!defined $hash) {
5490 if (!defined $page) {
5493 my $refs = git_get_references
();
5495 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5497 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5499 if ($#commitlist >= 100) {
5501 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5502 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5506 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5507 git_print_header_div
('summary', $project);
5509 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5514 ## ......................................................................
5515 ## feeds (RSS, Atom; OPML)
5518 my $format = shift || 'atom';
5519 my ($have_blame) = gitweb_check_feature
('blame');
5521 # Atom: http://www.atomenabled.org/developers/syndication/
5522 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5523 if ($format ne 'rss' && $format ne 'atom') {
5524 die_error
(undef, "Unknown web feed format");
5527 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5528 my $head = $hash || 'HEAD';
5529 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5533 my $content_type = "application/$format+xml";
5534 if (defined $cgi->http('HTTP_ACCEPT') &&
5535 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5536 # browser (feed reader) prefers text/xml
5537 $content_type = 'text/xml';
5539 if (defined($commitlist[0])) {
5540 %latest_commit = %{$commitlist[0]};
5541 %latest_date = parse_date
($latest_commit{'author_epoch'});
5543 -type
=> $content_type,
5544 -charset
=> 'utf-8',
5545 -last_modified
=> $latest_date{'rfc2822'});
5548 -type
=> $content_type,
5549 -charset
=> 'utf-8');
5552 # Optimization: skip generating the body if client asks only
5553 # for Last-Modified date.
5554 return if ($cgi->request_method() eq 'HEAD');
5557 my $title = "$site_name - $project/$action";
5558 my $feed_type = 'log';
5559 if (defined $hash) {
5560 $title .= " - '$hash'";
5561 $feed_type = 'branch log';
5562 if (defined $file_name) {
5563 $title .= " :: $file_name";
5564 $feed_type = 'history';
5566 } elsif (defined $file_name) {
5567 $title .= " - $file_name";
5568 $feed_type = 'history';
5570 $title .= " $feed_type";
5571 my $descr = git_get_project_description
($project);
5572 if (defined $descr) {
5573 $descr = esc_html
($descr);
5575 $descr = "$project " .
5576 ($format eq 'rss' ?
'RSS' : 'Atom') .
5579 my $owner = git_get_project_owner
($project);
5580 $owner = esc_html
($owner);
5584 if (defined $file_name) {
5585 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5586 } elsif (defined $hash) {
5587 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5589 $alt_url = href
(-full
=>1, action
=>"summary");
5591 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5592 if ($format eq 'rss') {
5594 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5597 print "<title>$title</title>\n" .
5598 "<link>$alt_url</link>\n" .
5599 "<description>$descr</description>\n" .
5600 "<language>en</language>\n";
5601 } elsif ($format eq 'atom') {
5603 <feed xmlns="http://www.w3.org/2005/Atom">
5605 print "<title>$title</title>\n" .
5606 "<subtitle>$descr</subtitle>\n" .
5607 '<link rel="alternate" type="text/html" href="' .
5608 $alt_url . '" />' . "\n" .
5609 '<link rel="self" type="' . $content_type . '" href="' .
5610 $cgi->self_url() . '" />' . "\n" .
5611 "<id>" . href
(-full
=>1) . "</id>\n" .
5612 # use project owner for feed author
5613 "<author><name>$owner</name></author>\n";
5614 if (defined $favicon) {
5615 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5617 if (defined $logo_url) {
5618 # not twice as wide as tall: 72 x 27 pixels
5619 print "<logo>" . esc_url
($logo) . "</logo>\n";
5621 if (! %latest_date) {
5622 # dummy date to keep the feed valid until commits trickle in:
5623 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5625 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5630 for (my $i = 0; $i <= $#commitlist; $i++) {
5631 my %co = %{$commitlist[$i]};
5632 my $commit = $co{'id'};
5633 # we read 150, we always show 30 and the ones more recent than 48 hours
5634 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5637 my %cd = parse_date
($co{'author_epoch'});
5639 # get list of changed files
5640 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5641 $co{'parent'} || "--root",
5642 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5644 my @difftree = map { chomp; $_ } <$fd>;
5648 # print element (entry, item)
5649 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5650 if ($format eq 'rss') {
5652 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5653 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5654 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5655 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5656 "<link>$co_url</link>\n" .
5657 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5658 "<content:encoded>" .
5660 } elsif ($format eq 'atom') {
5662 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5663 "<updated>$cd{'iso-8601'}</updated>\n" .
5665 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5666 if ($co{'author_email'}) {
5667 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5669 print "</author>\n" .
5670 # use committer for contributor
5672 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5673 if ($co{'committer_email'}) {
5674 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5676 print "</contributor>\n" .
5677 "<published>$cd{'iso-8601'}</published>\n" .
5678 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5679 "<id>$co_url</id>\n" .
5680 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5681 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5683 my $comment = $co{'comment'};
5685 foreach my $line (@
$comment) {
5686 $line = esc_html
($line);
5689 print "</pre><ul>\n";
5690 foreach my $difftree_line (@difftree) {
5691 my %difftree = parse_difftree_raw_line
($difftree_line);
5692 next if !$difftree{'from_id'};
5694 my $file = $difftree{'file'} || $difftree{'to_file'};
5698 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5699 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5700 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5701 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5702 -title
=> "diff"}, 'D');
5704 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5705 file_name
=>$file, hash_base
=>$commit),
5706 -title
=> "blame"}, 'B');
5708 # if this is not a feed of a file history
5709 if (!defined $file_name || $file_name ne $file) {
5710 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5711 file_name
=>$file, hash
=>$commit),
5712 -title
=> "history"}, 'H');
5714 $file = esc_path
($file);
5718 if ($format eq 'rss') {
5719 print "</ul>]]>\n" .
5720 "</content:encoded>\n" .
5722 } elsif ($format eq 'atom') {
5723 print "</ul>\n</div>\n" .
5730 if ($format eq 'rss') {
5731 print "</channel>\n</rss>\n";
5732 } elsif ($format eq 'atom') {
5746 my @list = git_get_projects_list
();
5748 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5750 <?xml version="1.0" encoding="utf-8"?>
5751 <opml version="1.0">
5753 <title>$site_name OPML Export</title>
5756 <outline text="git RSS feeds">
5759 foreach my $pr (@list) {
5761 my $head = git_get_head_hash
($proj{'path'});
5762 if (!defined $head) {
5765 $git_dir = "$projectroot/$proj{'path'}";
5766 my %co = parse_commit
($head);
5771 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5772 my $rss = "$my_url?p=$proj{'path'};a=rss";
5773 my $html = "$my_url?p=$proj{'path'};a=summary";
5774 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";