3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $search_use_regexp = $cgi->param('sr');
478 our $searchtext = $cgi->param('s');
480 if (defined $searchtext) {
481 if (length($searchtext) < 2) {
482 die_error
(undef, "At least two characters are required for search parameter");
484 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
487 # now read PATH_INFO and use it as alternative to parameters
488 sub evaluate_path_info
{
489 return if defined $project;
490 my $path_info = $ENV{"PATH_INFO"};
491 return if !$path_info;
492 $path_info =~ s
,^/+,,;
493 return if !$path_info;
494 # find which part of PATH_INFO is project
495 $project = $path_info;
497 while ($project && !check_head_link
("$projectroot/$project")) {
498 $project =~ s
,/*[^/]*$,,;
501 $project = validate_pathname
($project);
503 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
504 ($strict_export && !project_in_list
($project))) {
508 # do not change any parameters if an action is given using the query string
510 $path_info =~ s
,^$project/*,,;
511 my ($refname, $pathname) = split(/:/, $path_info, 2);
512 if (defined $pathname) {
513 # we got "project.git/branch:filename" or "project.git/branch:dir/"
514 # we could use git_get_type(branch:pathname), but it needs $git_dir
515 $pathname =~ s
,^/+,,;
516 if (!$pathname || substr($pathname, -1) eq "/") {
520 $action ||= "blob_plain";
522 $hash_base ||= validate_refname
($refname);
523 $file_name ||= validate_pathname
($pathname);
524 } elsif (defined $refname) {
525 # we got "project.git/branch"
526 $action ||= "shortlog";
527 $hash ||= validate_refname
($refname);
530 evaluate_path_info
();
532 # path to the current git repository
534 $git_dir = "$projectroot/$project" if $project;
538 "blame" => \
&git_blame2
,
539 "blobdiff" => \
&git_blobdiff
,
540 "blobdiff_plain" => \
&git_blobdiff_plain
,
541 "blob" => \
&git_blob
,
542 "blob_plain" => \
&git_blob_plain
,
543 "commitdiff" => \
&git_commitdiff
,
544 "commitdiff_plain" => \
&git_commitdiff_plain
,
545 "commit" => \
&git_commit
,
546 "forks" => \
&git_forks
,
547 "heads" => \
&git_heads
,
548 "history" => \
&git_history
,
551 "atom" => \
&git_atom
,
552 "search" => \
&git_search
,
553 "search_help" => \
&git_search_help
,
554 "shortlog" => \
&git_shortlog
,
555 "summary" => \
&git_summary
,
557 "tags" => \
&git_tags
,
558 "tree" => \
&git_tree
,
559 "snapshot" => \
&git_snapshot
,
560 "object" => \
&git_object
,
561 # those below don't need $project
562 "opml" => \
&git_opml
,
563 "project_list" => \
&git_project_list
,
564 "project_index" => \
&git_project_index
,
567 if (!defined $action) {
569 $action = git_get_type
($hash);
570 } elsif (defined $hash_base && defined $file_name) {
571 $action = git_get_type
("$hash_base:$file_name");
572 } elsif (defined $project) {
575 $action = 'project_list';
578 if (!defined($actions{$action})) {
579 die_error
(undef, "Unknown action");
581 if ($action !~ m/^(opml|project_list|project_index)$/ &&
583 die_error
(undef, "Project needed");
585 $actions{$action}->();
588 ## ======================================================================
593 # default is to use -absolute url() i.e. $my_uri
594 my $href = $params{-full
} ? $my_url : $my_uri;
596 # XXX: Warning: If you touch this, check the search form for updating,
607 hash_parent_base
=> "hpb",
612 snapshot_format
=> "sf",
613 extra_options
=> "opt",
614 search_use_regexp
=> "sr",
616 my %mapping = @mapping;
618 $params{'project'} = $project unless exists $params{'project'};
620 if ($params{-replay
}) {
621 while (my ($name, $symbol) = each %mapping) {
622 if (!exists $params{$name}) {
623 # to allow for multivalued params we use arrayref form
624 $params{$name} = [ $cgi->param($symbol) ];
629 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
631 # use PATH_INFO for project name
632 $href .= "/$params{'project'}" if defined $params{'project'};
633 delete $params{'project'};
635 # Summary just uses the project path URL
636 if (defined $params{'action'} && $params{'action'} eq 'summary') {
637 delete $params{'action'};
641 # now encode the parameters explicitly
643 for (my $i = 0; $i < @mapping; $i += 2) {
644 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
645 if (defined $params{$name}) {
646 if (ref($params{$name}) eq "ARRAY") {
647 foreach my $par (@{$params{$name}}) {
648 push @result, $symbol . "=" . esc_param
($par);
651 push @result, $symbol . "=" . esc_param
($params{$name});
655 $href .= "?" . join(';', @result) if scalar @result;
661 ## ======================================================================
662 ## validation, quoting/unquoting and escaping
664 sub validate_pathname
{
665 my $input = shift || return undef;
667 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
668 # at the beginning, at the end, and between slashes.
669 # also this catches doubled slashes
670 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
674 if ($input =~ m!\0!) {
680 sub validate_refname
{
681 my $input = shift || return undef;
683 # textual hashes are O.K.
684 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
687 # it must be correct pathname
688 $input = validate_pathname
($input)
690 # restrictions on ref name according to git-check-ref-format
691 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
697 # decode sequences of octets in utf8 into Perl's internal form,
698 # which is utf-8 with utf8 flag set if needed. gitweb writes out
699 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
702 if (utf8
::valid
($str)) {
706 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
710 # quote unsafe chars, but keep the slash, even when it's not
711 # correct, but quoted slashes look too horrible in bookmarks
714 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
720 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
723 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
729 # replace invalid utf8 character with SUBSTITUTION sequence
734 $str = to_utf8
($str);
735 $str = $cgi->escapeHTML($str);
736 if ($opts{'-nbsp'}) {
737 $str =~ s/ / /g;
739 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
743 # quote control characters and escape filename to HTML
748 $str = to_utf8
($str);
749 $str = $cgi->escapeHTML($str);
750 if ($opts{'-nbsp'}) {
751 $str =~ s/ / /g;
753 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
757 # Make control characters "printable", using character escape codes (CEC)
761 my %es = ( # character escape codes, aka escape sequences
762 "\t" => '\t', # tab (HT)
763 "\n" => '\n', # line feed (LF)
764 "\r" => '\r', # carrige return (CR)
765 "\f" => '\f', # form feed (FF)
766 "\b" => '\b', # backspace (BS)
767 "\a" => '\a', # alarm (bell) (BEL)
768 "\e" => '\e', # escape (ESC)
769 "\013" => '\v', # vertical tab (VT)
770 "\000" => '\0', # nul character (NUL)
772 my $chr = ( (exists $es{$cntrl})
774 : sprintf('\%03o', ord($cntrl)) );
775 if ($opts{-nohtml
}) {
778 return "<span class=\"cntrl\">$chr</span>";
782 # Alternatively use unicode control pictures codepoints,
783 # Unicode "printable representation" (PR)
788 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
789 if ($opts{-nohtml
}) {
792 return "<span class=\"cntrl\">$chr</span>";
796 # git may return quoted and escaped filenames
802 my %es = ( # character escape codes, aka escape sequences
803 't' => "\t", # tab (HT, TAB)
804 'n' => "\n", # newline (NL)
805 'r' => "\r", # return (CR)
806 'f' => "\f", # form feed (FF)
807 'b' => "\b", # backspace (BS)
808 'a' => "\a", # alarm (bell) (BEL)
809 'e' => "\e", # escape (ESC)
810 'v' => "\013", # vertical tab (VT)
813 if ($seq =~ m/^[0-7]{1,3}$/) {
814 # octal char sequence
815 return chr(oct($seq));
816 } elsif (exists $es{$seq}) {
817 # C escape sequence, aka character escape code
820 # quoted ordinary character
824 if ($str =~ m/^"(.*)"$/) {
827 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
832 # escape tabs (convert tabs to spaces)
836 while ((my $pos = index($line, "\t")) != -1) {
837 if (my $count = (8 - ($pos % 8))) {
838 my $spaces = ' ' x
$count;
839 $line =~ s/\t/$spaces/;
846 sub project_in_list
{
848 my @list = git_get_projects_list
();
849 return @list && scalar(grep { $_->{'path'} eq $project } @list);
852 ## ----------------------------------------------------------------------
853 ## HTML aware string manipulation
855 # Try to chop given string on a word boundary between position
856 # $len and $len+$add_len. If there is no word boundary there,
857 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
858 # (marking chopped part) would be longer than given string.
862 my $add_len = shift || 10;
863 my $where = shift || 'right'; # 'left' | 'center' | 'right'
865 # allow only $len chars, but don't cut a word if it would fit in $add_len
866 # if it doesn't fit, cut it if it's still longer than the dots we would add
867 # remove chopped character entities entirely
869 # when chopping in the middle, distribute $len into left and right part
870 # return early if chopping wouldn't make string shorter
871 if ($where eq 'center') {
872 return $str if ($len + 5 >= length($str)); # filler is length 5
875 return $str if ($len + 4 >= length($str)); # filler is length 4
878 # regexps: ending and beginning with word part up to $add_len
879 my $endre = qr/.{$len}\w{0,$add_len}/;
880 my $begre = qr/\w{0,$add_len}.{$len}/;
882 if ($where eq 'left') {
883 $str =~ m/^(.*?)($begre)$/;
884 my ($lead, $body) = ($1, $2);
885 if (length($lead) > 4) {
886 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
891 } elsif ($where eq 'center') {
892 $str =~ m/^($endre)(.*)$/;
893 my ($left, $str) = ($1, $2);
894 $str =~ m/^(.*?)($begre)$/;
895 my ($mid, $right) = ($1, $2);
896 if (length($mid) > 5) {
897 $left =~ s/&[^;]*$//;
898 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
901 return "$left$mid$right";
904 $str =~ m/^($endre)(.*)$/;
907 if (length($tail) > 4) {
908 $body =~ s/&[^;]*$//;
915 # takes the same arguments as chop_str, but also wraps a <span> around the
916 # result with a title attribute if it does get chopped. Additionally, the
917 # string is HTML-escaped.
918 sub chop_and_escape_str
{
921 my $chopped = chop_str
(@_);
922 if ($chopped eq $str) {
923 return esc_html
($chopped);
925 $str =~ s/([[:cntrl:]])/?/g;
926 return $cgi->span({-title
=>$str}, esc_html
($chopped));
930 ## ----------------------------------------------------------------------
931 ## functions returning short strings
933 # CSS class for given age value (in seconds)
939 } elsif ($age < 60*60*2) {
941 } elsif ($age < 60*60*24*2) {
948 # convert age in seconds to "nn units ago" string
953 if ($age > 60*60*24*365*2) {
954 $age_str = (int $age/60/60/24/365);
955 $age_str .= " years ago";
956 } elsif ($age > 60*60*24*(365/12)*2) {
957 $age_str = int $age/60/60/24/(365/12);
958 $age_str .= " months ago";
959 } elsif ($age > 60*60*24*7*2) {
960 $age_str = int $age/60/60/24/7;
961 $age_str .= " weeks ago";
962 } elsif ($age > 60*60*24*2) {
963 $age_str = int $age/60/60/24;
964 $age_str .= " days ago";
965 } elsif ($age > 60*60*2) {
966 $age_str = int $age/60/60;
967 $age_str .= " hours ago";
968 } elsif ($age > 60*2) {
969 $age_str = int $age/60;
970 $age_str .= " min ago";
973 $age_str .= " sec ago";
975 $age_str .= " right now";
981 S_IFINVALID
=> 0030000,
982 S_IFGITLINK
=> 0160000,
985 # submodule/subproject, a commit object reference
989 return (($mode & S_IFMT
) == S_IFGITLINK
)
992 # convert file mode in octal to symbolic file mode string
994 my $mode = oct shift;
996 if (S_ISGITLINK
($mode)) {
998 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1000 } elsif (S_ISLNK
($mode)) {
1001 return 'lrwxrwxrwx';
1002 } elsif (S_ISREG
($mode)) {
1003 # git cares only about the executable bit
1004 if ($mode & S_IXUSR
) {
1005 return '-rwxr-xr-x';
1007 return '-rw-r--r--';
1010 return '----------';
1014 # convert file mode in octal to file type string
1018 if ($mode !~ m/^[0-7]+$/) {
1024 if (S_ISGITLINK
($mode)) {
1026 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1028 } elsif (S_ISLNK
($mode)) {
1030 } elsif (S_ISREG
($mode)) {
1037 # convert file mode in octal to file type description string
1038 sub file_type_long
{
1041 if ($mode !~ m/^[0-7]+$/) {
1047 if (S_ISGITLINK
($mode)) {
1049 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1051 } elsif (S_ISLNK
($mode)) {
1053 } elsif (S_ISREG
($mode)) {
1054 if ($mode & S_IXUSR
) {
1055 return "executable";
1065 ## ----------------------------------------------------------------------
1066 ## functions returning short HTML fragments, or transforming HTML fragments
1067 ## which don't belong to other sections
1069 # format line of commit message.
1070 sub format_log_line_html
{
1073 $line = esc_html
($line, -nbsp
=>1);
1074 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1077 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1078 -class => "text"}, $hash_text);
1079 $line =~ s/$hash_text/$link/;
1084 # format marker of refs pointing to given object
1085 sub format_ref_marker
{
1086 my ($refs, $id) = @_;
1089 if (defined $refs->{$id}) {
1090 foreach my $ref (@{$refs->{$id}}) {
1091 my ($type, $name) = qw();
1092 # e.g. tags/v2.6.11 or heads/next
1093 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1101 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1102 esc_html
($name) . "</span>";
1107 return ' <span class="refs">'. $markers . '</span>';
1113 # format, perhaps shortened and with markers, title line
1114 sub format_subject_html
{
1115 my ($long, $short, $href, $extra) = @_;
1116 $extra = '' unless defined($extra);
1118 if (length($short) < length($long)) {
1119 return $cgi->a({-href
=> $href, -class => "list subject",
1120 -title
=> to_utf8
($long)},
1121 esc_html
($short) . $extra);
1123 return $cgi->a({-href
=> $href, -class => "list subject"},
1124 esc_html
($long) . $extra);
1128 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1129 sub format_git_diff_header_line
{
1131 my $diffinfo = shift;
1132 my ($from, $to) = @_;
1134 if ($diffinfo->{'nparents'}) {
1136 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1137 if ($to->{'href'}) {
1138 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1139 esc_path
($to->{'file'}));
1140 } else { # file was deleted (no href)
1141 $line .= esc_path
($to->{'file'});
1145 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1146 if ($from->{'href'}) {
1147 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1148 'a/' . esc_path
($from->{'file'}));
1149 } else { # file was added (no href)
1150 $line .= 'a/' . esc_path
($from->{'file'});
1153 if ($to->{'href'}) {
1154 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1155 'b/' . esc_path
($to->{'file'}));
1156 } else { # file was deleted
1157 $line .= 'b/' . esc_path
($to->{'file'});
1161 return "<div class=\"diff header\">$line</div>\n";
1164 # format extended diff header line, before patch itself
1165 sub format_extended_diff_header_line
{
1167 my $diffinfo = shift;
1168 my ($from, $to) = @_;
1171 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1172 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1173 esc_path
($from->{'file'}));
1175 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1176 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1177 esc_path
($to->{'file'}));
1179 # match single <mode>
1180 if ($line =~ m/\s(\d{6})$/) {
1181 $line .= '<span class="info"> (' .
1182 file_type_long
($1) .
1186 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1187 # can match only for combined diff
1189 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1190 if ($from->{'href'}[$i]) {
1191 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1193 substr($diffinfo->{'from_id'}[$i],0,7));
1198 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1201 if ($to->{'href'}) {
1202 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1203 substr($diffinfo->{'to_id'},0,7));
1208 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1209 # can match only for ordinary diff
1210 my ($from_link, $to_link);
1211 if ($from->{'href'}) {
1212 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1213 substr($diffinfo->{'from_id'},0,7));
1215 $from_link = '0' x
7;
1217 if ($to->{'href'}) {
1218 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1219 substr($diffinfo->{'to_id'},0,7));
1223 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1224 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1227 return $line . "<br/>\n";
1230 # format from-file/to-file diff header
1231 sub format_diff_from_to_header
{
1232 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1237 #assert($line =~ m/^---/) if DEBUG;
1238 # no extra formatting for "^--- /dev/null"
1239 if (! $diffinfo->{'nparents'}) {
1240 # ordinary (single parent) diff
1241 if ($line =~ m!^--- "?a/!) {
1242 if ($from->{'href'}) {
1244 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1245 esc_path
($from->{'file'}));
1248 esc_path
($from->{'file'});
1251 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1254 # combined diff (merge commit)
1255 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1256 if ($from->{'href'}[$i]) {
1258 $cgi->a({-href
=>href
(action
=>"blobdiff",
1259 hash_parent
=>$diffinfo->{'from_id'}[$i],
1260 hash_parent_base
=>$parents[$i],
1261 file_parent
=>$from->{'file'}[$i],
1262 hash
=>$diffinfo->{'to_id'},
1264 file_name
=>$to->{'file'}),
1266 -title
=>"diff" . ($i+1)},
1269 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1270 esc_path
($from->{'file'}[$i]));
1272 $line = '--- /dev/null';
1274 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1279 #assert($line =~ m/^\+\+\+/) if DEBUG;
1280 # no extra formatting for "^+++ /dev/null"
1281 if ($line =~ m!^\+\+\+ "?b/!) {
1282 if ($to->{'href'}) {
1284 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1285 esc_path
($to->{'file'}));
1288 esc_path
($to->{'file'});
1291 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1296 # create note for patch simplified by combined diff
1297 sub format_diff_cc_simplified
{
1298 my ($diffinfo, @parents) = @_;
1301 $result .= "<div class=\"diff header\">" .
1303 if (!is_deleted
($diffinfo)) {
1304 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1306 hash
=>$diffinfo->{'to_id'},
1307 file_name
=>$diffinfo->{'to_file'}),
1309 esc_path
($diffinfo->{'to_file'}));
1311 $result .= esc_path
($diffinfo->{'to_file'});
1313 $result .= "</div>\n" . # class="diff header"
1314 "<div class=\"diff nodifferences\">" .
1316 "</div>\n"; # class="diff nodifferences"
1321 # format patch (diff) line (not to be used for diff headers)
1322 sub format_diff_line
{
1324 my ($from, $to) = @_;
1325 my $diff_class = "";
1329 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1331 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1332 if ($line =~ m/^\@{3}/) {
1333 $diff_class = " chunk_header";
1334 } elsif ($line =~ m/^\\/) {
1335 $diff_class = " incomplete";
1336 } elsif ($prefix =~ tr/+/+/) {
1337 $diff_class = " add";
1338 } elsif ($prefix =~ tr/-/-/) {
1339 $diff_class = " rem";
1342 # assume ordinary diff
1343 my $char = substr($line, 0, 1);
1345 $diff_class = " add";
1346 } elsif ($char eq '-') {
1347 $diff_class = " rem";
1348 } elsif ($char eq '@') {
1349 $diff_class = " chunk_header";
1350 } elsif ($char eq "\\") {
1351 $diff_class = " incomplete";
1354 $line = untabify
($line);
1355 if ($from && $to && $line =~ m/^\@{2} /) {
1356 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1357 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1359 $from_lines = 0 unless defined $from_lines;
1360 $to_lines = 0 unless defined $to_lines;
1362 if ($from->{'href'}) {
1363 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1364 -class=>"list"}, $from_text);
1366 if ($to->{'href'}) {
1367 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1368 -class=>"list"}, $to_text);
1370 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1371 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1372 return "<div class=\"diff$diff_class\">$line</div>\n";
1373 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1374 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1375 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1377 @from_text = split(' ', $ranges);
1378 for (my $i = 0; $i < @from_text; ++$i) {
1379 ($from_start[$i], $from_nlines[$i]) =
1380 (split(',', substr($from_text[$i], 1)), 0);
1383 $to_text = pop @from_text;
1384 $to_start = pop @from_start;
1385 $to_nlines = pop @from_nlines;
1387 $line = "<span class=\"chunk_info\">$prefix ";
1388 for (my $i = 0; $i < @from_text; ++$i) {
1389 if ($from->{'href'}[$i]) {
1390 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1391 -class=>"list"}, $from_text[$i]);
1393 $line .= $from_text[$i];
1397 if ($to->{'href'}) {
1398 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1399 -class=>"list"}, $to_text);
1403 $line .= " $prefix</span>" .
1404 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1405 return "<div class=\"diff$diff_class\">$line</div>\n";
1407 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1410 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1411 # linked. Pass the hash of the tree/commit to snapshot.
1412 sub format_snapshot_links
{
1414 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1415 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1416 my $num_fmts = @snapshot_fmts;
1417 if ($num_fmts > 1) {
1418 # A parenthesized list of links bearing format names.
1419 # e.g. "snapshot (_tar.gz_ _zip_)"
1420 return "snapshot (" . join(' ', map
1427 }, $known_snapshot_formats{$_}{'display'})
1428 , @snapshot_fmts) . ")";
1429 } elsif ($num_fmts == 1) {
1430 # A single "snapshot" link whose tooltip bears the format name.
1432 my ($fmt) = @snapshot_fmts;
1438 snapshot_format
=>$fmt
1440 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1442 } else { # $num_fmts == 0
1447 ## ----------------------------------------------------------------------
1448 ## git utility subroutines, invoking git commands
1450 # returns path to the core git executable and the --git-dir parameter as list
1452 return $GIT, '--git-dir='.$git_dir;
1455 # returns path to the core git executable and the --git-dir parameter as string
1457 return join(' ', git_cmd
());
1460 # get HEAD ref of given project as hash
1461 sub git_get_head_hash
{
1462 my $project = shift;
1463 my $o_git_dir = $git_dir;
1465 $git_dir = "$projectroot/$project";
1466 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1469 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1473 if (defined $o_git_dir) {
1474 $git_dir = $o_git_dir;
1479 # get type of given object
1483 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1485 close $fd or return;
1490 # repository configuration
1491 our $config_file = '';
1494 # store multiple values for single key as anonymous array reference
1495 # single values stored directly in the hash, not as [ <value> ]
1496 sub hash_set_multi
{
1497 my ($hash, $key, $value) = @_;
1499 if (!exists $hash->{$key}) {
1500 $hash->{$key} = $value;
1501 } elsif (!ref $hash->{$key}) {
1502 $hash->{$key} = [ $hash->{$key}, $value ];
1504 push @{$hash->{$key}}, $value;
1508 # return hash of git project configuration
1509 # optionally limited to some section, e.g. 'gitweb'
1510 sub git_parse_project_config
{
1511 my $section_regexp = shift;
1516 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1519 while (my $keyval = <$fh>) {
1521 my ($key, $value) = split(/\n/, $keyval, 2);
1523 hash_set_multi
(\
%config, $key, $value)
1524 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1531 # convert config value to boolean, 'true' or 'false'
1532 # no value, number > 0, 'true' and 'yes' values are true
1533 # rest of values are treated as false (never as error)
1534 sub config_to_bool
{
1537 # strip leading and trailing whitespace
1541 return (!defined $val || # section.key
1542 ($val =~ /^\d+$/ && $val) || # section.key = 1
1543 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1546 # convert config value to simple decimal number
1547 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1548 # to be multiplied by 1024, 1048576, or 1073741824
1552 # strip leading and trailing whitespace
1556 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1558 # unknown unit is treated as 1
1559 return $num * ($unit eq 'g' ? 1073741824 :
1560 $unit eq 'm' ? 1048576 :
1561 $unit eq 'k' ? 1024 : 1);
1566 # convert config value to array reference, if needed
1567 sub config_to_multi
{
1570 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1573 sub git_get_project_config
{
1574 my ($key, $type) = @_;
1577 return unless ($key);
1578 $key =~ s/^gitweb\.//;
1579 return if ($key =~ m/\W/);
1582 if (defined $type) {
1585 unless ($type eq 'bool' || $type eq 'int');
1589 if (!defined $config_file ||
1590 $config_file ne "$git_dir/config") {
1591 %config = git_parse_project_config
('gitweb');
1592 $config_file = "$git_dir/config";
1596 if (!defined $type) {
1597 return $config{"gitweb.$key"};
1598 } elsif ($type eq 'bool') {
1599 # backward compatibility: 'git config --bool' returns true/false
1600 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1601 } elsif ($type eq 'int') {
1602 return config_to_int
($config{"gitweb.$key"});
1604 return $config{"gitweb.$key"};
1607 # get hash of given path at given ref
1608 sub git_get_hash_by_path
{
1610 my $path = shift || return undef;
1615 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1616 or die_error
(undef, "Open git-ls-tree failed");
1618 close $fd or return undef;
1620 if (!defined $line) {
1621 # there is no tree or hash given by $path at $base
1625 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1626 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1627 if (defined $type && $type ne $2) {
1628 # type doesn't match
1634 # get path of entry with given hash at given tree-ish (ref)
1635 # used to get 'from' filename for combined diff (merge commit) for renames
1636 sub git_get_path_by_hash
{
1637 my $base = shift || return;
1638 my $hash = shift || return;
1642 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1644 while (my $line = <$fd>) {
1647 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1648 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1649 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1658 ## ......................................................................
1659 ## git utility functions, directly accessing git repository
1661 sub git_get_project_description
{
1664 $git_dir = "$projectroot/$path";
1665 open my $fd, "$git_dir/description"
1666 or return git_get_project_config
('description');
1669 if (defined $descr) {
1675 sub git_get_project_url_list
{
1678 $git_dir = "$projectroot/$path";
1679 open my $fd, "$git_dir/cloneurl"
1680 or return wantarray ?
1681 @{ config_to_multi
(git_get_project_config
('url')) } :
1682 config_to_multi
(git_get_project_config
('url'));
1683 my @git_project_url_list = map { chomp; $_ } <$fd>;
1686 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1689 sub git_get_projects_list
{
1694 $filter =~ s/\.git$//;
1696 my ($check_forks) = gitweb_check_feature
('forks');
1698 if (-d
$projects_list) {
1699 # search in directory
1700 my $dir = $projects_list . ($filter ? "/$filter" : '');
1701 # remove the trailing "/"
1703 my $pfxlen = length("$dir");
1704 my $pfxdepth = ($dir =~ tr!/!!);
1707 follow_fast
=> 1, # follow symbolic links
1708 follow_skip
=> 2, # ignore duplicates
1709 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1711 # skip project-list toplevel, if we get it.
1712 return if (m!^[/.]$!);
1713 # only directories can be git repositories
1714 return unless (-d
$_);
1715 # don't traverse too deep (Find is super slow on os x)
1716 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1717 $File::Find
::prune
= 1;
1721 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1722 # we check related file in $projectroot
1723 if ($check_forks and $subdir =~ m
#/.#) {
1724 $File::Find
::prune
= 1;
1725 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1726 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1727 $File::Find
::prune
= 1;
1732 } elsif (-f
$projects_list) {
1733 # read from file(url-encoded):
1734 # 'git%2Fgit.git Linus+Torvalds'
1735 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1736 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1738 open my ($fd), $projects_list or return;
1740 while (my $line = <$fd>) {
1742 my ($path, $owner) = split ' ', $line;
1743 $path = unescape
($path);
1744 $owner = unescape
($owner);
1745 if (!defined $path) {
1748 if ($filter ne '') {
1749 # looking for forks;
1750 my $pfx = substr($path, 0, length($filter));
1751 if ($pfx ne $filter) {
1754 my $sfx = substr($path, length($filter));
1755 if ($sfx !~ /^\/.*\
.git
$/) {
1758 } elsif ($check_forks) {
1760 foreach my $filter (keys %paths) {
1761 # looking for forks;
1762 my $pfx = substr($path, 0, length($filter));
1763 if ($pfx ne $filter) {
1766 my $sfx = substr($path, length($filter));
1767 if ($sfx !~ /^\/.*\
.git
$/) {
1770 # is a fork, don't include it in
1775 if (check_export_ok
("$projectroot/$path")) {
1778 owner
=> to_utf8
($owner),
1781 (my $forks_path = $path) =~ s/\.git$//;
1782 $paths{$forks_path}++;
1790 our $gitweb_project_owner = undef;
1791 sub git_get_project_list_from_file
{
1793 return if (defined $gitweb_project_owner);
1795 $gitweb_project_owner = {};
1796 # read from file (url-encoded):
1797 # 'git%2Fgit.git Linus+Torvalds'
1798 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1799 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1800 if (-f
$projects_list) {
1801 open (my $fd , $projects_list);
1802 while (my $line = <$fd>) {
1804 my ($pr, $ow) = split ' ', $line;
1805 $pr = unescape
($pr);
1806 $ow = unescape
($ow);
1807 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1813 sub git_get_project_owner
{
1814 my $project = shift;
1817 return undef unless $project;
1818 $git_dir = "$projectroot/$project";
1820 if (!defined $gitweb_project_owner) {
1821 git_get_project_list_from_file
();
1824 if (exists $gitweb_project_owner->{$project}) {
1825 $owner = $gitweb_project_owner->{$project};
1827 if (!defined $owner){
1828 $owner = git_get_project_config
('owner');
1830 if (!defined $owner) {
1831 $owner = get_file_owner
("$git_dir");
1837 sub git_get_last_activity
{
1841 $git_dir = "$projectroot/$path";
1842 open($fd, "-|", git_cmd
(), 'for-each-ref',
1843 '--format=%(committer)',
1844 '--sort=-committerdate',
1846 'refs/heads') or return;
1847 my $most_recent = <$fd>;
1848 close $fd or return;
1849 if (defined $most_recent &&
1850 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1852 my $age = time - $timestamp;
1853 return ($age, age_string
($age));
1855 return (undef, undef);
1858 sub git_get_references
{
1859 my $type = shift || "";
1861 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1862 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1863 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1864 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1867 while (my $line = <$fd>) {
1869 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1870 if (defined $refs{$1}) {
1871 push @{$refs{$1}}, $2;
1877 close $fd or return;
1881 sub git_get_rev_name_tags
{
1882 my $hash = shift || return undef;
1884 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1886 my $name_rev = <$fd>;
1889 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1892 # catches also '$hash undefined' output
1897 ## ----------------------------------------------------------------------
1898 ## parse to hash functions
1902 my $tz = shift || "-0000";
1905 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1906 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1907 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1908 $date{'hour'} = $hour;
1909 $date{'minute'} = $min;
1910 $date{'mday'} = $mday;
1911 $date{'day'} = $days[$wday];
1912 $date{'month'} = $months[$mon];
1913 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1914 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1915 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1916 $mday, $months[$mon], $hour ,$min;
1917 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1918 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1920 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1921 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1922 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1923 $date{'hour_local'} = $hour;
1924 $date{'minute_local'} = $min;
1925 $date{'tz_local'} = $tz;
1926 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1927 1900+$year, $mon+1, $mday,
1928 $hour, $min, $sec, $tz);
1937 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1938 $tag{'id'} = $tag_id;
1939 while (my $line = <$fd>) {
1941 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1942 $tag{'object'} = $1;
1943 } elsif ($line =~ m/^type (.+)$/) {
1945 } elsif ($line =~ m/^tag (.+)$/) {
1947 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1948 $tag{'author'} = $1;
1951 } elsif ($line =~ m/--BEGIN/) {
1952 push @comment, $line;
1954 } elsif ($line eq "") {
1958 push @comment, <$fd>;
1959 $tag{'comment'} = \
@comment;
1960 close $fd or return;
1961 if (!defined $tag{'name'}) {
1967 sub parse_commit_text
{
1968 my ($commit_text, $withparents) = @_;
1969 my @commit_lines = split '\n', $commit_text;
1972 pop @commit_lines; # Remove '\0'
1974 if (! @commit_lines) {
1978 my $header = shift @commit_lines;
1979 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1982 ($co{'id'}, my @parents) = split ' ', $header;
1983 while (my $line = shift @commit_lines) {
1984 last if $line eq "\n";
1985 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1987 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1989 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1991 $co{'author_epoch'} = $2;
1992 $co{'author_tz'} = $3;
1993 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1994 $co{'author_name'} = $1;
1995 $co{'author_email'} = $2;
1997 $co{'author_name'} = $co{'author'};
1999 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2000 $co{'committer'} = $1;
2001 $co{'committer_epoch'} = $2;
2002 $co{'committer_tz'} = $3;
2003 $co{'committer_name'} = $co{'committer'};
2004 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2005 $co{'committer_name'} = $1;
2006 $co{'committer_email'} = $2;
2008 $co{'committer_name'} = $co{'committer'};
2012 if (!defined $co{'tree'}) {
2015 $co{'parents'} = \
@parents;
2016 $co{'parent'} = $parents[0];
2018 foreach my $title (@commit_lines) {
2021 $co{'title'} = chop_str
($title, 80, 5);
2022 # remove leading stuff of merges to make the interesting part visible
2023 if (length($title) > 50) {
2024 $title =~ s/^Automatic //;
2025 $title =~ s/^merge (of|with) /Merge ... /i;
2026 if (length($title) > 50) {
2027 $title =~ s/(http|rsync):\/\///;
2029 if (length($title) > 50) {
2030 $title =~ s/(master|www|rsync)\.//;
2032 if (length($title) > 50) {
2033 $title =~ s/kernel.org:?//;
2035 if (length($title) > 50) {
2036 $title =~ s/\/pub\/scm//;
2039 $co{'title_short'} = chop_str
($title, 50, 5);
2043 if ($co{'title'} eq "") {
2044 $co{'title'} = $co{'title_short'} = '(no commit message)';
2046 # remove added spaces
2047 foreach my $line (@commit_lines) {
2050 $co{'comment'} = \
@commit_lines;
2052 my $age = time - $co{'committer_epoch'};
2054 $co{'age_string'} = age_string
($age);
2055 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2056 if ($age > 60*60*24*7*2) {
2057 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2058 $co{'age_string_age'} = $co{'age_string'};
2060 $co{'age_string_date'} = $co{'age_string'};
2061 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2067 my ($commit_id) = @_;
2072 open my $fd, "-|", git_cmd
(), "rev-list",
2078 or die_error
(undef, "Open git-rev-list failed");
2079 %co = parse_commit_text
(<$fd>, 1);
2086 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2094 open my $fd, "-|", git_cmd
(), "rev-list",
2097 ("--max-count=" . $maxcount),
2098 ("--skip=" . $skip),
2102 ($filename ? ($filename) : ())
2103 or die_error
(undef, "Open git-rev-list failed");
2104 while (my $line = <$fd>) {
2105 my %co = parse_commit_text
($line);
2110 return wantarray ? @cos : \
@cos;
2113 # parse ref from ref_file, given by ref_id, with given type
2115 my $ref_file = shift;
2117 my $type = shift || git_get_type
($ref_id);
2120 $ref_item{'type'} = $type;
2121 $ref_item{'id'} = $ref_id;
2122 $ref_item{'epoch'} = 0;
2123 $ref_item{'age'} = "unknown";
2124 if ($type eq "tag") {
2125 my %tag = parse_tag
($ref_id);
2126 $ref_item{'comment'} = $tag{'comment'};
2127 if ($tag{'type'} eq "commit") {
2128 my %co = parse_commit
($tag{'object'});
2129 $ref_item{'epoch'} = $co{'committer_epoch'};
2130 $ref_item{'age'} = $co{'age_string'};
2131 } elsif (defined($tag{'epoch'})) {
2132 my $age = time - $tag{'epoch'};
2133 $ref_item{'epoch'} = $tag{'epoch'};
2134 $ref_item{'age'} = age_string
($age);
2136 $ref_item{'reftype'} = $tag{'type'};
2137 $ref_item{'name'} = $tag{'name'};
2138 $ref_item{'refid'} = $tag{'object'};
2139 } elsif ($type eq "commit"){
2140 my %co = parse_commit
($ref_id);
2141 $ref_item{'reftype'} = "commit";
2142 $ref_item{'name'} = $ref_file;
2143 $ref_item{'title'} = $co{'title'};
2144 $ref_item{'refid'} = $ref_id;
2145 $ref_item{'epoch'} = $co{'committer_epoch'};
2146 $ref_item{'age'} = $co{'age_string'};
2148 $ref_item{'reftype'} = $type;
2149 $ref_item{'name'} = $ref_file;
2150 $ref_item{'refid'} = $ref_id;
2156 # parse line of git-diff-tree "raw" output
2157 sub parse_difftree_raw_line
{
2161 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2162 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2163 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2164 $res{'from_mode'} = $1;
2165 $res{'to_mode'} = $2;
2166 $res{'from_id'} = $3;
2168 $res{'status'} = $res{'status_str'} = $5;
2169 $res{'similarity'} = $6;
2170 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2171 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2173 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2176 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2177 # combined diff (for merge commit)
2178 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2179 $res{'nparents'} = length($1);
2180 $res{'from_mode'} = [ split(' ', $2) ];
2181 $res{'to_mode'} = pop @{$res{'from_mode'}};
2182 $res{'from_id'} = [ split(' ', $3) ];
2183 $res{'to_id'} = pop @{$res{'from_id'}};
2184 $res{'status_str'} = $4;
2185 $res{'status'} = [ split('', $4) ];
2186 $res{'to_file'} = unquote
($5);
2188 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2189 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2190 $res{'commit'} = $1;
2193 return wantarray ? %res : \
%res;
2196 # wrapper: return parsed line of git-diff-tree "raw" output
2197 # (the argument might be raw line, or parsed info)
2198 sub parsed_difftree_line
{
2199 my $line_or_ref = shift;
2201 if (ref($line_or_ref) eq "HASH") {
2202 # pre-parsed (or generated by hand)
2203 return $line_or_ref;
2205 return parse_difftree_raw_line
($line_or_ref);
2209 # parse line of git-ls-tree output
2210 sub parse_ls_tree_line
($;%) {
2215 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2216 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2224 $res{'name'} = unquote
($4);
2227 return wantarray ? %res : \
%res;
2230 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2231 sub parse_from_to_diffinfo
{
2232 my ($diffinfo, $from, $to, @parents) = @_;
2234 if ($diffinfo->{'nparents'}) {
2236 $from->{'file'} = [];
2237 $from->{'href'} = [];
2238 fill_from_file_info
($diffinfo, @parents)
2239 unless exists $diffinfo->{'from_file'};
2240 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2241 $from->{'file'}[$i] =
2242 defined $diffinfo->{'from_file'}[$i] ?
2243 $diffinfo->{'from_file'}[$i] :
2244 $diffinfo->{'to_file'};
2245 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2246 $from->{'href'}[$i] = href
(action
=>"blob",
2247 hash_base
=>$parents[$i],
2248 hash
=>$diffinfo->{'from_id'}[$i],
2249 file_name
=>$from->{'file'}[$i]);
2251 $from->{'href'}[$i] = undef;
2255 # ordinary (not combined) diff
2256 $from->{'file'} = $diffinfo->{'from_file'};
2257 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2258 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2259 hash
=>$diffinfo->{'from_id'},
2260 file_name
=>$from->{'file'});
2262 delete $from->{'href'};
2266 $to->{'file'} = $diffinfo->{'to_file'};
2267 if (!is_deleted
($diffinfo)) { # file exists in result
2268 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2269 hash
=>$diffinfo->{'to_id'},
2270 file_name
=>$to->{'file'});
2272 delete $to->{'href'};
2276 ## ......................................................................
2277 ## parse to array of hashes functions
2279 sub git_get_heads_list
{
2283 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2284 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2285 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2288 while (my $line = <$fd>) {
2292 my ($refinfo, $committerinfo) = split(/\0/, $line);
2293 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2294 my ($committer, $epoch, $tz) =
2295 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2296 $ref_item{'fullname'} = $name;
2297 $name =~ s!^refs/heads/!!;
2299 $ref_item{'name'} = $name;
2300 $ref_item{'id'} = $hash;
2301 $ref_item{'title'} = $title || '(no commit message)';
2302 $ref_item{'epoch'} = $epoch;
2304 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2306 $ref_item{'age'} = "unknown";
2309 push @headslist, \
%ref_item;
2313 return wantarray ? @headslist : \
@headslist;
2316 sub git_get_tags_list
{
2320 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2321 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2322 '--format=%(objectname) %(objecttype) %(refname) '.
2323 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2326 while (my $line = <$fd>) {
2330 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2331 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2332 my ($creator, $epoch, $tz) =
2333 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2334 $ref_item{'fullname'} = $name;
2335 $name =~ s!^refs/tags/!!;
2337 $ref_item{'type'} = $type;
2338 $ref_item{'id'} = $id;
2339 $ref_item{'name'} = $name;
2340 if ($type eq "tag") {
2341 $ref_item{'subject'} = $title;
2342 $ref_item{'reftype'} = $reftype;
2343 $ref_item{'refid'} = $refid;
2345 $ref_item{'reftype'} = $type;
2346 $ref_item{'refid'} = $id;
2349 if ($type eq "tag" || $type eq "commit") {
2350 $ref_item{'epoch'} = $epoch;
2352 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2354 $ref_item{'age'} = "unknown";
2358 push @tagslist, \
%ref_item;
2362 return wantarray ? @tagslist : \
@tagslist;
2365 ## ----------------------------------------------------------------------
2366 ## filesystem-related functions
2368 sub get_file_owner
{
2371 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2372 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2373 if (!defined $gcos) {
2377 $owner =~ s/[,;].*$//;
2378 return to_utf8
($owner);
2381 ## ......................................................................
2382 ## mimetype related functions
2384 sub mimetype_guess_file
{
2385 my $filename = shift;
2386 my $mimemap = shift;
2387 -r
$mimemap or return undef;
2390 open(MIME
, $mimemap) or return undef;
2392 next if m/^#/; # skip comments
2393 my ($mime, $exts) = split(/\t+/);
2394 if (defined $exts) {
2395 my @exts = split(/\s+/, $exts);
2396 foreach my $ext (@exts) {
2397 $mimemap{$ext} = $mime;
2403 $filename =~ /\.([^.]*)$/;
2404 return $mimemap{$1};
2407 sub mimetype_guess
{
2408 my $filename = shift;
2410 $filename =~ /\./ or return undef;
2412 if ($mimetypes_file) {
2413 my $file = $mimetypes_file;
2414 if ($file !~ m!^/!) { # if it is relative path
2415 # it is relative to project
2416 $file = "$projectroot/$project/$file";
2418 $mime = mimetype_guess_file
($filename, $file);
2420 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2426 my $filename = shift;
2429 my $mime = mimetype_guess
($filename);
2430 $mime and return $mime;
2434 return $default_blob_plain_mimetype unless $fd;
2437 return 'text/plain' .
2438 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2439 } elsif (! $filename) {
2440 return 'application/octet-stream';
2441 } elsif ($filename =~ m/\.png$/i) {
2443 } elsif ($filename =~ m/\.gif$/i) {
2445 } elsif ($filename =~ m/\.jpe?g$/i) {
2446 return 'image/jpeg';
2448 return 'application/octet-stream';
2452 ## ======================================================================
2453 ## functions printing HTML: header, footer, error page
2455 sub git_header_html
{
2456 my $status = shift || "200 OK";
2457 my $expires = shift;
2459 my $title = "$site_name";
2460 if (defined $project) {
2461 $title .= " - " . to_utf8
($project);
2462 if (defined $action) {
2463 $title .= "/$action";
2464 if (defined $file_name) {
2465 $title .= " - " . esc_path
($file_name);
2466 if ($action eq "tree" && $file_name !~ m
|/$|) {
2473 # require explicit support from the UA if we are to send the page as
2474 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2475 # we have to do this because MSIE sometimes globs '*/*', pretending to
2476 # support xhtml+xml but choking when it gets what it asked for.
2477 if (defined $cgi->http('HTTP_ACCEPT') &&
2478 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2479 $cgi->Accept('application/xhtml+xml') != 0) {
2480 $content_type = 'application/xhtml+xml';
2482 $content_type = 'text/html';
2484 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2485 -status
=> $status, -expires
=> $expires);
2486 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2488 <?xml version="1.0" encoding="utf-8"?>
2489 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2490 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2491 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2492 <!-- git core binaries version $git_version -->
2494 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2495 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2496 <meta name="robots" content="index, nofollow"/>
2497 <title>$title</title>
2499 # print out each stylesheet that exist
2500 if (defined $stylesheet) {
2501 #provides backwards capability for those people who define style sheet in a config file
2502 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2504 foreach my $stylesheet (@stylesheets) {
2505 next unless $stylesheet;
2506 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2509 if (defined $project) {
2510 printf('<link rel="alternate" title="%s log RSS feed" '.
2511 'href="%s" type="application/rss+xml" />'."\n",
2512 esc_param
($project), href
(action
=>"rss"));
2513 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2514 'href="%s" type="application/rss+xml" />'."\n",
2515 esc_param
($project), href
(action
=>"rss",
2516 extra_options
=>"--no-merges"));
2517 printf('<link rel="alternate" title="%s log Atom feed" '.
2518 'href="%s" type="application/atom+xml" />'."\n",
2519 esc_param
($project), href
(action
=>"atom"));
2520 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2521 'href="%s" type="application/atom+xml" />'."\n",
2522 esc_param
($project), href
(action
=>"atom",
2523 extra_options
=>"--no-merges"));
2525 printf('<link rel="alternate" title="%s projects list" '.
2526 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2527 $site_name, href
(project
=>undef, action
=>"project_index"));
2528 printf('<link rel="alternate" title="%s projects feeds" '.
2529 'href="%s" type="text/x-opml"/>'."\n",
2530 $site_name, href
(project
=>undef, action
=>"opml"));
2532 if (defined $favicon) {
2533 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2539 if (-f
$site_header) {
2540 open (my $fd, $site_header);
2545 print "<div class=\"page_header\">\n" .
2546 $cgi->a({-href
=> esc_url
($logo_url),
2547 -title
=> $logo_label},
2548 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2549 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2550 if (defined $project) {
2551 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2552 if (defined $action) {
2559 my ($have_search) = gitweb_check_feature
('search');
2560 if ((defined $project) && ($have_search)) {
2561 if (!defined $searchtext) {
2565 if (defined $hash_base) {
2566 $search_hash = $hash_base;
2567 } elsif (defined $hash) {
2568 $search_hash = $hash;
2570 $search_hash = "HEAD";
2572 my $action = $my_uri;
2573 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2574 if ($use_pathinfo) {
2575 $action .= "/$project";
2577 $cgi->param("p", $project);
2579 $cgi->param("a", "search");
2580 $cgi->param("h", $search_hash);
2581 print $cgi->startform(-method => "get", -action
=> $action) .
2582 "<div class=\"search\">\n" .
2583 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2584 $cgi->hidden(-name
=> "a") . "\n" .
2585 $cgi->hidden(-name
=> "h") . "\n" .
2586 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2587 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2588 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2590 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2591 "<span title=\"Extended regular expression\">" .
2592 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2593 -checked
=> $search_use_regexp) .
2596 $cgi->end_form() . "\n";
2600 sub git_footer_html
{
2601 print "<div class=\"page_footer\">\n";
2602 if (defined $project) {
2603 my $descr = git_get_project_description
($project);
2604 if (defined $descr) {
2605 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2607 print $cgi->a({-href
=> href
(action
=>"rss"),
2608 -class => "rss_logo"}, "RSS") . " ";
2609 print $cgi->a({-href
=> href
(action
=>"atom"),
2610 -class => "rss_logo"}, "Atom") . "\n";
2612 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2613 -class => "rss_logo"}, "OPML") . " ";
2614 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2615 -class => "rss_logo"}, "TXT") . "\n";
2619 if (-f
$site_footer) {
2620 open (my $fd, $site_footer);
2630 my $status = shift || "403 Forbidden";
2631 my $error = shift || "Malformed query, file missing or permission denied";
2633 git_header_html
($status);
2635 <div class="page_body">
2645 ## ----------------------------------------------------------------------
2646 ## functions printing or outputting HTML: navigation
2648 sub git_print_page_nav
{
2649 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2650 $extra = '' if !defined $extra; # pager or formats
2652 my @navs = qw(summary shortlog log commit commitdiff tree);
2654 @navs = grep { $_ ne $suppress } @navs;
2657 my %arg = map { $_ => {action
=>$_} } @navs;
2658 if (defined $head) {
2659 for (qw(commit commitdiff)) {
2660 $arg{$_}{'hash'} = $head;
2662 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2663 for (qw(shortlog log)) {
2664 $arg{$_}{'hash'} = $head;
2668 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2669 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2671 print "<div class=\"page_nav\">\n" .
2673 map { $_ eq $current ?
2674 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2676 print "<br/>\n$extra<br/>\n" .
2680 sub format_paging_nav
{
2681 my ($action, $hash, $head, $page, $nrevs) = @_;
2685 if ($hash ne $head || $page) {
2686 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2688 $paging_nav .= "HEAD";
2692 $paging_nav .= " ⋅ " .
2693 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2694 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2696 $paging_nav .= " ⋅ prev";
2699 if ($nrevs >= (100 * ($page+1)-1)) {
2700 $paging_nav .= " ⋅ " .
2701 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2702 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2704 $paging_nav .= " ⋅ next";
2710 ## ......................................................................
2711 ## functions printing or outputting HTML: div
2713 sub git_print_header_div
{
2714 my ($action, $title, $hash, $hash_base) = @_;
2717 $args{'action'} = $action;
2718 $args{'hash'} = $hash if $hash;
2719 $args{'hash_base'} = $hash_base if $hash_base;
2721 print "<div class=\"header\">\n" .
2722 $cgi->a({-href
=> href
(%args), -class => "title"},
2723 $title ? $title : $action) .
2727 #sub git_print_authorship (\%) {
2728 sub git_print_authorship
{
2731 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2732 print "<div class=\"author_date\">" .
2733 esc_html
($co->{'author_name'}) .
2735 if ($ad{'hour_local'} < 6) {
2736 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2737 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2739 printf(" (%02d:%02d %s)",
2740 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2745 sub git_print_page_path
{
2751 print "<div class=\"page_path\">";
2752 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2753 -title
=> 'tree root'}, to_utf8
("[$project]"));
2755 if (defined $name) {
2756 my @dirname = split '/', $name;
2757 my $basename = pop @dirname;
2760 foreach my $dir (@dirname) {
2761 $fullname .= ($fullname ? '/' : '') . $dir;
2762 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2764 -title
=> $fullname}, esc_path
($dir));
2767 if (defined $type && $type eq 'blob') {
2768 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2770 -title
=> $name}, esc_path
($basename));
2771 } elsif (defined $type && $type eq 'tree') {
2772 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2774 -title
=> $name}, esc_path
($basename));
2777 print esc_path
($basename);
2780 print "<br/></div>\n";
2783 # sub git_print_log (\@;%) {
2784 sub git_print_log
($;%) {
2788 if ($opts{'-remove_title'}) {
2789 # remove title, i.e. first line of log
2792 # remove leading empty lines
2793 while (defined $log->[0] && $log->[0] eq "") {
2800 foreach my $line (@$log) {
2801 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2804 if (! $opts{'-remove_signoff'}) {
2805 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2808 # remove signoff lines
2815 # print only one empty line
2816 # do not print empty line after signoff
2818 next if ($empty || $signoff);
2824 print format_log_line_html
($line) . "<br/>\n";
2827 if ($opts{'-final_empty_line'}) {
2828 # end with single empty line
2829 print "<br/>\n" unless $empty;
2833 # return link target (what link points to)
2834 sub git_get_link_target
{
2839 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2843 $link_target = <$fd>;
2848 return $link_target;
2851 # given link target, and the directory (basedir) the link is in,
2852 # return target of link relative to top directory (top tree);
2853 # return undef if it is not possible (including absolute links).
2854 sub normalize_link_target
{
2855 my ($link_target, $basedir, $hash_base) = @_;
2857 # we can normalize symlink target only if $hash_base is provided
2858 return unless $hash_base;
2860 # absolute symlinks (beginning with '/') cannot be normalized
2861 return if (substr($link_target, 0, 1) eq '/');
2863 # normalize link target to path from top (root) tree (dir)
2866 $path = $basedir . '/' . $link_target;
2868 # we are in top (root) tree (dir)
2869 $path = $link_target;
2872 # remove //, /./, and /../
2874 foreach my $part (split('/', $path)) {
2875 # discard '.' and ''
2876 next if (!$part || $part eq '.');
2878 if ($part eq '..') {
2882 # link leads outside repository (outside top dir)
2886 push @path_parts, $part;
2889 $path = join('/', @path_parts);
2894 # print tree entry (row of git_tree), but without encompassing <tr> element
2895 sub git_print_tree_entry
{
2896 my ($t, $basedir, $hash_base, $have_blame) = @_;
2899 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2901 # The format of a table row is: mode list link. Where mode is
2902 # the mode of the entry, list is the name of the entry, an href,
2903 # and link is the action links of the entry.
2905 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2906 if ($t->{'type'} eq "blob") {
2907 print "<td class=\"list\">" .
2908 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2909 file_name
=>"$basedir$t->{'name'}", %base_key),
2910 -class => "list"}, esc_path
($t->{'name'}));
2911 if (S_ISLNK
(oct $t->{'mode'})) {
2912 my $link_target = git_get_link_target
($t->{'hash'});
2914 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2915 if (defined $norm_target) {
2917 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2918 file_name
=>$norm_target),
2919 -title
=> $norm_target}, esc_path
($link_target));
2921 print " -> " . esc_path
($link_target);
2926 print "<td class=\"link\">";
2927 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2928 file_name
=>"$basedir$t->{'name'}", %base_key)},
2932 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2933 file_name
=>"$basedir$t->{'name'}", %base_key)},
2936 if (defined $hash_base) {
2938 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2939 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2943 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2944 file_name
=>"$basedir$t->{'name'}")},
2948 } elsif ($t->{'type'} eq "tree") {
2949 print "<td class=\"list\">";
2950 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2951 file_name
=>"$basedir$t->{'name'}", %base_key)},
2952 esc_path
($t->{'name'}));
2954 print "<td class=\"link\">";
2955 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2956 file_name
=>"$basedir$t->{'name'}", %base_key)},
2958 if (defined $hash_base) {
2960 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2961 file_name
=>"$basedir$t->{'name'}")},
2966 # unknown object: we can only present history for it
2967 # (this includes 'commit' object, i.e. submodule support)
2968 print "<td class=\"list\">" .
2969 esc_path
($t->{'name'}) .
2971 print "<td class=\"link\">";
2972 if (defined $hash_base) {
2973 print $cgi->a({-href
=> href
(action
=>"history",
2974 hash_base
=>$hash_base,
2975 file_name
=>"$basedir$t->{'name'}")},
2982 ## ......................................................................
2983 ## functions printing large fragments of HTML
2985 # get pre-image filenames for merge (combined) diff
2986 sub fill_from_file_info
{
2987 my ($diff, @parents) = @_;
2989 $diff->{'from_file'} = [ ];
2990 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2991 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2992 if ($diff->{'status'}[$i] eq 'R' ||
2993 $diff->{'status'}[$i] eq 'C') {
2994 $diff->{'from_file'}[$i] =
2995 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3002 # is current raw difftree line of file deletion
3004 my $diffinfo = shift;
3006 return $diffinfo->{'status_str'} =~ /D/;
3009 # does patch correspond to [previous] difftree raw line
3010 # $diffinfo - hashref of parsed raw diff format
3011 # $patchinfo - hashref of parsed patch diff format
3012 # (the same keys as in $diffinfo)
3013 sub is_patch_split
{
3014 my ($diffinfo, $patchinfo) = @_;
3016 return defined $diffinfo && defined $patchinfo
3017 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3021 sub git_difftree_body
{
3022 my ($difftree, $hash, @parents) = @_;
3023 my ($parent) = $parents[0];
3024 my ($have_blame) = gitweb_check_feature
('blame');
3025 print "<div class=\"list_head\">\n";
3026 if ($#{$difftree} > 10) {
3027 print(($#{$difftree} + 1) . " files changed:\n");
3031 print "<table class=\"" .
3032 (@parents > 1 ? "combined " : "") .
3035 # header only for combined diff in 'commitdiff' view
3036 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3039 print "<thead><tr>\n" .
3040 "<th></th><th></th>\n"; # filename, patchN link
3041 for (my $i = 0; $i < @parents; $i++) {
3042 my $par = $parents[$i];
3044 $cgi->a({-href
=> href
(action
=>"commitdiff",
3045 hash
=>$hash, hash_parent
=>$par),
3046 -title
=> 'commitdiff to parent number ' .
3047 ($i+1) . ': ' . substr($par,0,7)},
3051 print "</tr></thead>\n<tbody>\n";
3056 foreach my $line (@{$difftree}) {
3057 my $diff = parsed_difftree_line
($line);
3060 print "<tr class=\"dark\">\n";
3062 print "<tr class=\"light\">\n";
3066 if (exists $diff->{'nparents'}) { # combined diff
3068 fill_from_file_info
($diff, @parents)
3069 unless exists $diff->{'from_file'};
3071 if (!is_deleted
($diff)) {
3072 # file exists in the result (child) commit
3074 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3075 file_name
=>$diff->{'to_file'},
3077 -class => "list"}, esc_path
($diff->{'to_file'})) .
3081 esc_path
($diff->{'to_file'}) .
3085 if ($action eq 'commitdiff') {
3088 print "<td class=\"link\">" .
3089 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3094 my $has_history = 0;
3095 my $not_deleted = 0;
3096 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3097 my $hash_parent = $parents[$i];
3098 my $from_hash = $diff->{'from_id'}[$i];
3099 my $from_path = $diff->{'from_file'}[$i];
3100 my $status = $diff->{'status'}[$i];
3102 $has_history ||= ($status ne 'A');
3103 $not_deleted ||= ($status ne 'D');
3105 if ($status eq 'A') {
3106 print "<td class=\"link\" align=\"right\"> | </td>\n";
3107 } elsif ($status eq 'D') {
3108 print "<td class=\"link\">" .
3109 $cgi->a({-href
=> href
(action
=>"blob",
3112 file_name
=>$from_path)},
3116 if ($diff->{'to_id'} eq $from_hash) {
3117 print "<td class=\"link nochange\">";
3119 print "<td class=\"link\">";
3121 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3122 hash
=>$diff->{'to_id'},
3123 hash_parent
=>$from_hash,
3125 hash_parent_base
=>$hash_parent,
3126 file_name
=>$diff->{'to_file'},
3127 file_parent
=>$from_path)},
3133 print "<td class=\"link\">";
3135 print $cgi->a({-href
=> href
(action
=>"blob",
3136 hash
=>$diff->{'to_id'},
3137 file_name
=>$diff->{'to_file'},
3140 print " | " if ($has_history);
3143 print $cgi->a({-href
=> href
(action
=>"history",
3144 file_name
=>$diff->{'to_file'},
3151 next; # instead of 'else' clause, to avoid extra indent
3153 # else ordinary diff
3155 my ($to_mode_oct, $to_mode_str, $to_file_type);
3156 my ($from_mode_oct, $from_mode_str, $from_file_type);
3157 if ($diff->{'to_mode'} ne ('0' x
6)) {
3158 $to_mode_oct = oct $diff->{'to_mode'};
3159 if (S_ISREG
($to_mode_oct)) { # only for regular file
3160 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3162 $to_file_type = file_type
($diff->{'to_mode'});
3164 if ($diff->{'from_mode'} ne ('0' x
6)) {
3165 $from_mode_oct = oct $diff->{'from_mode'};
3166 if (S_ISREG
($to_mode_oct)) { # only for regular file
3167 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3169 $from_file_type = file_type
($diff->{'from_mode'});
3172 if ($diff->{'status'} eq "A") { # created
3173 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3174 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3175 $mode_chng .= "]</span>";
3177 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3178 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3179 -class => "list"}, esc_path
($diff->{'file'}));
3181 print "<td>$mode_chng</td>\n";
3182 print "<td class=\"link\">";
3183 if ($action eq 'commitdiff') {
3186 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3189 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3190 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3194 } elsif ($diff->{'status'} eq "D") { # deleted
3195 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3197 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3198 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3199 -class => "list"}, esc_path
($diff->{'file'}));
3201 print "<td>$mode_chng</td>\n";
3202 print "<td class=\"link\">";
3203 if ($action eq 'commitdiff') {
3206 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3209 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3210 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3213 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3214 file_name
=>$diff->{'file'})},
3217 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3218 file_name
=>$diff->{'file'})},
3222 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3223 my $mode_chnge = "";
3224 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3225 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3226 if ($from_file_type ne $to_file_type) {
3227 $mode_chnge .= " from $from_file_type to $to_file_type";
3229 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3230 if ($from_mode_str && $to_mode_str) {
3231 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3232 } elsif ($to_mode_str) {
3233 $mode_chnge .= " mode: $to_mode_str";
3236 $mode_chnge .= "]</span>\n";
3239 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3240 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3241 -class => "list"}, esc_path
($diff->{'file'}));
3243 print "<td>$mode_chnge</td>\n";
3244 print "<td class=\"link\">";
3245 if ($action eq 'commitdiff') {
3248 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3250 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3251 # "commit" view and modified file (not onlu mode changed)
3252 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3253 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3254 hash_base
=>$hash, hash_parent_base
=>$parent,
3255 file_name
=>$diff->{'file'})},
3259 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3260 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3263 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3264 file_name
=>$diff->{'file'})},
3267 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3268 file_name
=>$diff->{'file'})},
3272 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3273 my %status_name = ('R' => 'moved', 'C' => 'copied');
3274 my $nstatus = $status_name{$diff->{'status'}};
3276 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3277 # mode also for directories, so we cannot use $to_mode_str
3278 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3281 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3282 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3283 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3284 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3285 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3286 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3287 -class => "list"}, esc_path
($diff->{'from_file'})) .
3288 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3289 "<td class=\"link\">";
3290 if ($action eq 'commitdiff') {
3293 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3295 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3296 # "commit" view and modified file (not only pure rename or copy)
3297 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3298 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3299 hash_base
=>$hash, hash_parent_base
=>$parent,
3300 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3304 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3305 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3308 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3309 file_name
=>$diff->{'to_file'})},
3312 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3313 file_name
=>$diff->{'to_file'})},
3317 } # we should not encounter Unmerged (U) or Unknown (X) status
3320 print "</tbody>" if $has_header;
3324 sub git_patchset_body
{
3325 my ($fd, $difftree, $hash, @hash_parents) = @_;
3326 my ($hash_parent) = $hash_parents[0];
3328 my $is_combined = (@hash_parents > 1);
3330 my $patch_number = 0;
3336 print "<div class=\"patchset\">\n";
3338 # skip to first patch
3339 while ($patch_line = <$fd>) {
3342 last if ($patch_line =~ m/^diff /);
3346 while ($patch_line) {
3348 # parse "git diff" header line
3349 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3350 # $1 is from_name, which we do not use
3351 $to_name = unquote
($2);
3352 $to_name =~ s!^b/!!;
3353 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3354 # $1 is 'cc' or 'combined', which we do not use
3355 $to_name = unquote
($2);
3360 # check if current patch belong to current raw line
3361 # and parse raw git-diff line if needed
3362 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3363 # this is continuation of a split patch
3364 print "<div class=\"patch cont\">\n";
3366 # advance raw git-diff output if needed
3367 $patch_idx++ if defined $diffinfo;
3369 # read and prepare patch information
3370 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3372 # compact combined diff output can have some patches skipped
3373 # find which patch (using pathname of result) we are at now;
3375 while ($to_name ne $diffinfo->{'to_file'}) {
3376 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3377 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3378 "</div>\n"; # class="patch"
3383 last if $patch_idx > $#$difftree;
3384 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3388 # modifies %from, %to hashes
3389 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3391 # this is first patch for raw difftree line with $patch_idx index
3392 # we index @$difftree array from 0, but number patches from 1
3393 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3397 #assert($patch_line =~ m/^diff /) if DEBUG;
3398 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3400 # print "git diff" header
3401 print format_git_diff_header_line
($patch_line, $diffinfo,
3404 # print extended diff header
3405 print "<div class=\"diff extended_header\">\n";
3407 while ($patch_line = <$fd>) {
3410 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3412 print format_extended_diff_header_line
($patch_line, $diffinfo,
3415 print "</div>\n"; # class="diff extended_header"
3417 # from-file/to-file diff header
3418 if (! $patch_line) {
3419 print "</div>\n"; # class="patch"
3422 next PATCH
if ($patch_line =~ m/^diff /);
3423 #assert($patch_line =~ m/^---/) if DEBUG;
3425 my $last_patch_line = $patch_line;
3426 $patch_line = <$fd>;
3428 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3430 print format_diff_from_to_header
($last_patch_line, $patch_line,
3431 $diffinfo, \
%from, \
%to,
3436 while ($patch_line = <$fd>) {
3439 next PATCH
if ($patch_line =~ m/^diff /);
3441 print format_diff_line
($patch_line, \
%from, \
%to);
3445 print "</div>\n"; # class="patch"
3448 # for compact combined (--cc) format, with chunk and patch simpliciaction
3449 # patchset might be empty, but there might be unprocessed raw lines
3450 for (++$patch_idx if $patch_number > 0;
3451 $patch_idx < @$difftree;
3453 # read and prepare patch information
3454 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3456 # generate anchor for "patch" links in difftree / whatchanged part
3457 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3458 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3459 "</div>\n"; # class="patch"
3464 if ($patch_number == 0) {
3465 if (@hash_parents > 1) {
3466 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3468 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3472 print "</div>\n"; # class="patchset"
3475 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3477 sub git_project_list_body
{
3478 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3480 my ($check_forks) = gitweb_check_feature
('forks');
3483 foreach my $pr (@$projlist) {
3484 my (@aa) = git_get_last_activity
($pr->{'path'});
3488 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3489 if (!defined $pr->{'descr'}) {
3490 my $descr = git_get_project_description
($pr->{'path'}) || "";
3491 $pr->{'descr_long'} = to_utf8
($descr);
3492 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3494 if (!defined $pr->{'owner'}) {
3495 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3498 my $pname = $pr->{'path'};
3499 if (($pname =~ s/\.git$//) &&
3500 ($pname !~ /\/$/) &&
3501 (-d
"$projectroot/$pname")) {
3502 $pr->{'forks'} = "-d $projectroot/$pname";
3508 push @projects, $pr;
3511 $order ||= $default_projects_order;
3512 $from = 0 unless defined $from;
3513 $to = $#projects if (!defined $to || $#projects < $to);
3515 print "<table class=\"project_list\">\n";
3516 unless ($no_header) {
3519 print "<th></th>\n";
3521 if ($order eq "project") {
3522 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3523 print "<th>Project</th>\n";
3526 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3527 -class => "header"}, "Project") .
3530 if ($order eq "descr") {
3531 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3532 print "<th>Description</th>\n";
3535 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3536 -class => "header"}, "Description") .
3539 if ($order eq "owner") {
3540 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3541 print "<th>Owner</th>\n";
3544 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3545 -class => "header"}, "Owner") .
3548 if ($order eq "age") {
3549 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3550 print "<th>Last Change</th>\n";
3553 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3554 -class => "header"}, "Last Change") .
3557 print "<th></th>\n" .
3561 for (my $i = $from; $i <= $to; $i++) {
3562 my $pr = $projects[$i];
3564 print "<tr class=\"dark\">\n";
3566 print "<tr class=\"light\">\n";
3571 if ($pr->{'forks'}) {
3572 print "<!-- $pr->{'forks'} -->\n";
3573 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3577 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3578 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3579 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3580 -class => "list", -title
=> $pr->{'descr_long'}},
3581 esc_html
($pr->{'descr'})) . "</td>\n" .
3582 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3583 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3584 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3585 "<td class=\"link\">" .
3586 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3587 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3588 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3589 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3590 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3594 if (defined $extra) {
3597 print "<td></td>\n";
3599 print "<td colspan=\"5\">$extra</td>\n" .
3605 sub git_shortlog_body
{
3606 # uses global variable $project
3607 my ($commitlist, $from, $to, $refs, $extra) = @_;
3609 $from = 0 unless defined $from;
3610 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3612 print "<table class=\"shortlog\">\n";
3614 for (my $i = $from; $i <= $to; $i++) {
3615 my %co = %{$commitlist->[$i]};
3616 my $commit = $co{'id'};
3617 my $ref = format_ref_marker
($refs, $commit);
3619 print "<tr class=\"dark\">\n";
3621 print "<tr class=\"light\">\n";
3624 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3625 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3626 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3627 "<td><i>" . $author . "</i></td>\n" .
3629 print format_subject_html
($co{'title'}, $co{'title_short'},
3630 href
(action
=>"commit", hash
=>$commit), $ref);
3632 "<td class=\"link\">" .
3633 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3634 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3635 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3636 my $snapshot_links = format_snapshot_links
($commit);
3637 if (defined $snapshot_links) {
3638 print " | " . $snapshot_links;
3643 if (defined $extra) {
3645 "<td colspan=\"4\">$extra</td>\n" .
3651 sub git_history_body
{
3652 # Warning: assumes constant type (blob or tree) during history
3653 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3655 $from = 0 unless defined $from;
3656 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3658 print "<table class=\"history\">\n";
3660 for (my $i = $from; $i <= $to; $i++) {
3661 my %co = %{$commitlist->[$i]};
3665 my $commit = $co{'id'};
3667 my $ref = format_ref_marker
($refs, $commit);
3670 print "<tr class=\"dark\">\n";
3672 print "<tr class=\"light\">\n";
3675 # shortlog uses chop_str($co{'author_name'}, 10)
3676 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3677 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3678 "<td><i>" . $author . "</i></td>\n" .
3680 # originally git_history used chop_str($co{'title'}, 50)
3681 print format_subject_html
($co{'title'}, $co{'title_short'},
3682 href
(action
=>"commit", hash
=>$commit), $ref);
3684 "<td class=\"link\">" .
3685 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3686 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3688 if ($ftype eq 'blob') {
3689 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3690 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3691 if (defined $blob_current && defined $blob_parent &&
3692 $blob_current ne $blob_parent) {
3694 $cgi->a({-href
=> href
(action
=>"blobdiff",
3695 hash
=>$blob_current, hash_parent
=>$blob_parent,
3696 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3697 file_name
=>$file_name)},
3704 if (defined $extra) {
3706 "<td colspan=\"4\">$extra</td>\n" .
3713 # uses global variable $project
3714 my ($taglist, $from, $to, $extra) = @_;
3715 $from = 0 unless defined $from;
3716 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3718 print "<table class=\"tags\">\n";
3720 for (my $i = $from; $i <= $to; $i++) {
3721 my $entry = $taglist->[$i];
3723 my $comment = $tag{'subject'};
3725 if (defined $comment) {
3726 $comment_short = chop_str
($comment, 30, 5);
3729 print "<tr class=\"dark\">\n";
3731 print "<tr class=\"light\">\n";
3734 if (defined $tag{'age'}) {
3735 print "<td><i>$tag{'age'}</i></td>\n";
3737 print "<td></td>\n";
3740 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3741 -class => "list name"}, esc_html
($tag{'name'})) .
3744 if (defined $comment) {
3745 print format_subject_html
($comment, $comment_short,
3746 href
(action
=>"tag", hash
=>$tag{'id'}));
3749 "<td class=\"selflink\">";
3750 if ($tag{'type'} eq "tag") {
3751 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3756 "<td class=\"link\">" . " | " .
3757 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3758 if ($tag{'reftype'} eq "commit") {
3759 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3760 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3761 } elsif ($tag{'reftype'} eq "blob") {
3762 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3767 if (defined $extra) {
3769 "<td colspan=\"5\">$extra</td>\n" .
3775 sub git_heads_body
{
3776 # uses global variable $project
3777 my ($headlist, $head, $from, $to, $extra) = @_;
3778 $from = 0 unless defined $from;
3779 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3781 print "<table class=\"heads\">\n";
3783 for (my $i = $from; $i <= $to; $i++) {
3784 my $entry = $headlist->[$i];
3786 my $curr = $ref{'id'} eq $head;
3788 print "<tr class=\"dark\">\n";
3790 print "<tr class=\"light\">\n";
3793 print "<td><i>$ref{'age'}</i></td>\n" .
3794 ($curr ? "<td class=\"current_head\">" : "<td>") .
3795 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3796 -class => "list name"},esc_html
($ref{'name'})) .
3798 "<td class=\"link\">" .
3799 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3800 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3801 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3805 if (defined $extra) {
3807 "<td colspan=\"3\">$extra</td>\n" .
3813 sub git_search_grep_body
{
3814 my ($commitlist, $from, $to, $extra) = @_;
3815 $from = 0 unless defined $from;
3816 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3818 print "<table class=\"commit_search\">\n";
3820 for (my $i = $from; $i <= $to; $i++) {
3821 my %co = %{$commitlist->[$i]};
3825 my $commit = $co{'id'};
3827 print "<tr class=\"dark\">\n";
3829 print "<tr class=\"light\">\n";
3832 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3833 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3834 "<td><i>" . $author . "</i></td>\n" .
3836 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3837 -class => "list subject"},
3838 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3839 my $comment = $co{'comment'};
3840 foreach my $line (@$comment) {
3841 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3842 my ($lead, $match, $trail) = ($1, $2, $3);
3843 $match = chop_str
($match, 70, 5, 'center');
3844 my $contextlen = int((80 - length($match))/2);
3845 $contextlen = 30 if ($contextlen > 30);
3846 $lead = chop_str
($lead, $contextlen, 10, 'left');
3847 $trail = chop_str
($trail, $contextlen, 10, 'right');
3849 $lead = esc_html
($lead);
3850 $match = esc_html
($match);
3851 $trail = esc_html
($trail);
3853 print "$lead<span class=\"match\">$match</span>$trail<br />";
3857 "<td class=\"link\">" .
3858 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3860 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3862 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3866 if (defined $extra) {
3868 "<td colspan=\"3\">$extra</td>\n" .
3874 ## ======================================================================
3875 ## ======================================================================
3878 sub git_project_list
{
3879 my $order = $cgi->param('o');
3880 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3881 die_error
(undef, "Unknown order parameter");
3884 my @list = git_get_projects_list
();
3886 die_error
(undef, "No projects found");
3890 if (-f
$home_text) {
3891 print "<div class=\"index_include\">\n";
3892 open (my $fd, $home_text);
3897 git_project_list_body
(\
@list, $order);
3902 my $order = $cgi->param('o');
3903 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3904 die_error
(undef, "Unknown order parameter");
3907 my @list = git_get_projects_list
($project);
3909 die_error
(undef, "No forks found");
3913 git_print_page_nav
('','');
3914 git_print_header_div
('summary', "$project forks");
3915 git_project_list_body
(\
@list, $order);
3919 sub git_project_index
{
3920 my @projects = git_get_projects_list
($project);
3923 -type
=> 'text/plain',
3924 -charset
=> 'utf-8',
3925 -content_disposition
=> 'inline; filename="index.aux"');
3927 foreach my $pr (@projects) {
3928 if (!exists $pr->{'owner'}) {
3929 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3932 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3933 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3934 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3935 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3939 print "$path $owner\n";
3944 my $descr = git_get_project_description
($project) || "none";
3945 my %co = parse_commit
("HEAD");
3946 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3947 my $head = $co{'id'};
3949 my $owner = git_get_project_owner
($project);
3951 my $refs = git_get_references
();
3952 # These get_*_list functions return one more to allow us to see if
3953 # there are more ...
3954 my @taglist = git_get_tags_list
(16);
3955 my @headlist = git_get_heads_list
(16);
3957 my ($check_forks) = gitweb_check_feature
('forks');
3960 @forklist = git_get_projects_list
($project);
3964 git_print_page_nav
('summary','', $head);
3966 print "<div class=\"title\"> </div>\n";
3967 print "<table class=\"projects_list\">\n" .
3968 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3969 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3970 if (defined $cd{'rfc2822'}) {
3971 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3974 # use per project git URL list in $projectroot/$project/cloneurl
3975 # or make project git URL from git base URL and project name
3976 my $url_tag = "URL";
3977 my @url_list = git_get_project_url_list
($project);
3978 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3979 foreach my $git_url (@url_list) {
3980 next unless $git_url;
3981 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3986 if (-s
"$projectroot/$project/README.html") {
3987 if (open my $fd, "$projectroot/$project/README.html") {
3988 print "<div class=\"title\">readme</div>\n" .
3989 "<div class=\"readme\">\n";
3990 print $_ while (<$fd>);
3991 print "\n</div>\n"; # class="readme"
3996 # we need to request one more than 16 (0..15) to check if
3998 my @commitlist = $head ? parse_commits
($head, 17) : ();
4000 git_print_header_div
('shortlog');
4001 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4002 $#commitlist <= 15 ? undef :
4003 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4007 git_print_header_div
('tags');
4008 git_tags_body
(\
@taglist, 0, 15,
4009 $#taglist <= 15 ? undef :
4010 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4014 git_print_header_div
('heads');
4015 git_heads_body
(\
@headlist, $head, 0, 15,
4016 $#headlist <= 15 ? undef :
4017 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4021 git_print_header_div
('forks');
4022 git_project_list_body
(\
@forklist, undef, 0, 15,
4023 $#forklist <= 15 ? undef :
4024 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4032 my $head = git_get_head_hash
($project);
4034 git_print_page_nav
('','', $head,undef,$head);
4035 my %tag = parse_tag
($hash);
4038 die_error
(undef, "Unknown tag object");
4041 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4042 print "<div class=\"title_text\">\n" .
4043 "<table class=\"object_header\">\n" .
4045 "<td>object</td>\n" .
4046 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4047 $tag{'object'}) . "</td>\n" .
4048 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4049 $tag{'type'}) . "</td>\n" .
4051 if (defined($tag{'author'})) {
4052 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4053 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4054 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4055 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4058 print "</table>\n\n" .
4060 print "<div class=\"page_body\">";
4061 my $comment = $tag{'comment'};
4062 foreach my $line (@$comment) {
4064 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4074 my ($have_blame) = gitweb_check_feature
('blame');
4076 die_error
('403 Permission denied', "Permission denied");
4078 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4079 $hash_base ||= git_get_head_hash
($project);
4080 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4081 my %co = parse_commit
($hash_base)
4082 or die_error
(undef, "Reading commit failed");
4083 if (!defined $hash) {
4084 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4085 or die_error
(undef, "Error looking up file");
4087 $ftype = git_get_type
($hash);
4088 if ($ftype !~ "blob") {
4089 die_error
('400 Bad Request', "Object is not a blob");
4091 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4092 $file_name, $hash_base)
4093 or die_error
(undef, "Open git-blame failed");
4096 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4099 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4102 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4104 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4105 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4106 git_print_page_path
($file_name, $ftype, $hash_base);
4107 my @rev_color = (qw(light2 dark2));
4108 my $num_colors = scalar(@rev_color);
4109 my $current_color = 0;
4112 <div class="page_body">
4113 <table class="blame">
4114 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4119 last unless defined $_;
4120 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4121 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4122 if (!exists $metainfo{$full_rev}) {
4123 $metainfo{$full_rev} = {};
4125 my $meta = $metainfo{$full_rev};
4128 if (/^(\S+) (.*)$/) {
4134 my $rev = substr($full_rev, 0, 8);
4135 my $author = $meta->{'author'};
4136 my %date = parse_date
($meta->{'author-time'},
4137 $meta->{'author-tz'});
4138 my $date = $date{'iso-tz'};
4140 $current_color = ++$current_color % $num_colors;
4142 print "<tr class=\"$rev_color[$current_color]\">\n";
4144 print "<td class=\"sha1\"";
4145 print " title=\"". esc_html
($author) . ", $date\"";
4146 print " rowspan=\"$group_size\"" if ($group_size > 1);
4148 print $cgi->a({-href
=> href
(action
=>"commit",
4150 file_name
=>$file_name)},
4154 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4155 or die_error
(undef, "Open git-rev-parse failed");
4156 my $parent_commit = <$dd>;
4158 chomp($parent_commit);
4159 my $blamed = href
(action
=> 'blame',
4160 file_name
=> $meta->{'filename'},
4161 hash_base
=> $parent_commit);
4162 print "<td class=\"linenr\">";
4163 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4165 -class => "linenr" },
4168 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4174 or print "Reading blob failed\n";
4181 my ($have_blame) = gitweb_check_feature
('blame');
4183 die_error
('403 Permission denied', "Permission denied");
4185 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4186 $hash_base ||= git_get_head_hash
($project);
4187 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4188 my %co = parse_commit
($hash_base)
4189 or die_error
(undef, "Reading commit failed");
4190 if (!defined $hash) {
4191 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4192 or die_error
(undef, "Error lookup file");
4194 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4195 or die_error
(undef, "Open git-annotate failed");
4198 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4201 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4204 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4206 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4207 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4208 git_print_page_path
($file_name, 'blob', $hash_base);
4209 print "<div class=\"page_body\">\n";
4211 <table class="blame">
4220 my @line_class = (qw(light dark));
4221 my $line_class_len = scalar (@line_class);
4222 my $line_class_num = $#line_class;
4223 while (my $line = <$fd>) {
4235 $line_class_num = ($line_class_num + 1) % $line_class_len;
4237 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4244 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4247 $short_rev = substr ($long_rev, 0, 8);
4248 $age = time () - $time;
4249 $age_str = age_string
($age);
4250 $age_str =~ s/ / /g;
4251 $age_class = age_class
($age);
4252 $author = esc_html
($author);
4253 $author =~ s/ / /g;
4255 $data = untabify
($data);
4256 $data = esc_html
($data);
4259 <tr class="$line_class[$line_class_num]">
4260 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4261 <td class="$age_class">$age_str</td>
4263 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4264 <td class="pre">$data</td>
4267 } # while (my $line = <$fd>)
4268 print "</table>\n\n";
4270 or print "Reading blob failed.\n";
4276 my $head = git_get_head_hash
($project);
4278 git_print_page_nav
('','', $head,undef,$head);
4279 git_print_header_div
('summary', $project);
4281 my @tagslist = git_get_tags_list
();
4283 git_tags_body
(\
@tagslist);
4289 my $head = git_get_head_hash
($project);
4291 git_print_page_nav
('','', $head,undef,$head);
4292 git_print_header_div
('summary', $project);
4294 my @headslist = git_get_heads_list
();
4296 git_heads_body
(\
@headslist, $head);
4301 sub git_blob_plain
{
4304 if (!defined $hash) {
4305 if (defined $file_name) {
4306 my $base = $hash_base || git_get_head_hash
($project);
4307 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4308 or die_error
(undef, "Error lookup file");
4310 die_error
(undef, "No file name defined");
4312 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4313 # blobs defined by non-textual hash id's can be cached
4318 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4319 or die_error
(undef, "Couldn't cat $file_name, $hash");
4321 $type ||= blob_mimetype
($fd, $file_name);
4323 # save as filename, even when no $file_name is given
4324 my $save_as = "$hash";
4325 if (defined $file_name) {
4326 $save_as = $file_name;
4327 } elsif ($type =~ m/^text\//) {
4334 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4336 binmode STDOUT
, ':raw';
4338 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4346 if (!defined $hash) {
4347 if (defined $file_name) {
4348 my $base = $hash_base || git_get_head_hash
($project);
4349 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4350 or die_error
(undef, "Error lookup file");
4352 die_error
(undef, "No file name defined");
4354 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4355 # blobs defined by non-textual hash id's can be cached
4359 my ($have_blame) = gitweb_check_feature
('blame');
4360 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4361 or die_error
(undef, "Couldn't cat $file_name, $hash");
4362 my $mimetype = blob_mimetype
($fd, $file_name);
4363 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4365 return git_blob_plain
($mimetype);
4367 # we can have blame only for text/* mimetype
4368 $have_blame &&= ($mimetype =~ m!^text/!);
4370 git_header_html
(undef, $expires);
4371 my $formats_nav = '';
4372 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4373 if (defined $file_name) {
4376 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4381 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4384 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4387 $cgi->a({-href
=> href
(action
=>"blob",
4388 hash_base
=>"HEAD", file_name
=>$file_name)},
4392 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4395 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4396 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4398 print "<div class=\"page_nav\">\n" .
4399 "<br/><br/></div>\n" .
4400 "<div class=\"title\">$hash</div>\n";
4402 git_print_page_path
($file_name, "blob", $hash_base);
4403 print "<div class=\"page_body\">\n";
4404 if ($mimetype =~ m!^image/!) {
4405 print qq
!<img type
="$mimetype"!;
4407 print qq
! alt
="$file_name" title
="$file_name"!;
4410 href(action=>"blob_plain
", hash=>$hash,
4411 hash_base=>$hash_base, file_name=>$file_name) .
4415 while (my $line = <$fd>) {
4418 $line = untabify
($line);
4419 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4420 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4424 or print "Reading blob failed.\n";
4430 if (!defined $hash_base) {
4431 $hash_base = "HEAD";
4433 if (!defined $hash) {
4434 if (defined $file_name) {
4435 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4441 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4442 or die_error
(undef, "Open git-ls-tree failed");
4443 my @entries = map { chomp; $_ } <$fd>;
4444 close $fd or die_error
(undef, "Reading tree failed");
4447 my $refs = git_get_references
();
4448 my $ref = format_ref_marker
($refs, $hash_base);
4451 my ($have_blame) = gitweb_check_feature
('blame');
4452 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4454 if (defined $file_name) {
4456 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4458 $cgi->a({-href
=> href
(action
=>"tree",
4459 hash_base
=>"HEAD", file_name
=>$file_name)},
4462 my $snapshot_links = format_snapshot_links
($hash);
4463 if (defined $snapshot_links) {
4464 # FIXME: Should be available when we have no hash base as well.
4465 push @views_nav, $snapshot_links;
4467 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4468 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4471 print "<div class=\"page_nav\">\n";
4472 print "<br/><br/></div>\n";
4473 print "<div class=\"title\">$hash</div>\n";
4475 if (defined $file_name) {
4476 $basedir = $file_name;
4477 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4481 git_print_page_path
($file_name, 'tree', $hash_base);
4482 print "<div class=\"page_body\">\n";
4483 print "<table class=\"tree\">\n";
4485 # '..' (top directory) link if possible
4486 if (defined $hash_base &&
4487 defined $file_name && $file_name =~ m![^/]+$!) {
4489 print "<tr class=\"dark\">\n";
4491 print "<tr class=\"light\">\n";
4495 my $up = $file_name;
4496 $up =~ s!/?[^/]+$!!;
4497 undef $up unless $up;
4498 # based on git_print_tree_entry
4499 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4500 print '<td class="list">';
4501 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4505 print "<td class=\"link\"></td>\n";
4509 foreach my $line (@entries) {
4510 my %t = parse_ls_tree_line
($line, -z
=> 1);
4513 print "<tr class=\"dark\">\n";
4515 print "<tr class=\"light\">\n";
4519 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4523 print "</table>\n" .
4529 my @supported_fmts = gitweb_check_feature
('snapshot');
4530 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4532 my $format = $cgi->param('sf');
4533 if (!@supported_fmts) {
4534 die_error
('403 Permission denied', "Permission denied");
4536 # default to first supported snapshot format
4537 $format ||= $supported_fmts[0];
4538 if ($format !~ m/^[a-z0-9]+$/) {
4539 die_error
(undef, "Invalid snapshot format parameter");
4540 } elsif (!exists($known_snapshot_formats{$format})) {
4541 die_error
(undef, "Unknown snapshot format");
4542 } elsif (!grep($_ eq $format, @supported_fmts)) {
4543 die_error
(undef, "Unsupported snapshot format");
4546 if (!defined $hash) {
4547 $hash = git_get_head_hash
($project);
4550 my $git_command = git_cmd_str
();
4551 my $name = $project;
4552 $name =~ s
,([^/])/*\
.git
$,$1,;
4553 $name = basename
($name);
4554 my $filename = to_utf8
($name);
4555 $name =~ s/\047/\047\\\047\047/g;
4557 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4558 $cmd = "$git_command archive " .
4559 "--format=$known_snapshot_formats{$format}{'format'} " .
4560 "--prefix=\'$name\'/ $hash";
4561 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4562 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4566 -type
=> $known_snapshot_formats{$format}{'type'},
4567 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4568 -status
=> '200 OK');
4570 open my $fd, "-|", $cmd
4571 or die_error
(undef, "Execute git-archive failed");
4572 binmode STDOUT
, ':raw';
4574 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4579 my $head = git_get_head_hash
($project);
4580 if (!defined $hash) {
4583 if (!defined $page) {
4586 my $refs = git_get_references
();
4588 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4590 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4593 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4596 my %co = parse_commit
($hash);
4598 git_print_header_div
('summary', $project);
4599 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4601 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4602 for (my $i = 0; $i <= $to; $i++) {
4603 my %co = %{$commitlist[$i]};
4605 my $commit = $co{'id'};
4606 my $ref = format_ref_marker
($refs, $commit);
4607 my %ad = parse_date
($co{'author_epoch'});
4608 git_print_header_div
('commit',
4609 "<span class=\"age\">$co{'age_string'}</span>" .
4610 esc_html
($co{'title'}) . $ref,
4612 print "<div class=\"title_text\">\n" .
4613 "<div class=\"log_link\">\n" .
4614 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4616 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4618 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4621 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4624 print "<div class=\"log_body\">\n";
4625 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4628 if ($#commitlist >= 100) {
4629 print "<div class=\"page_nav\">\n";
4630 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4631 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4638 $hash ||= $hash_base || "HEAD";
4639 my %co = parse_commit
($hash);
4641 die_error
(undef, "Unknown commit object");
4643 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4644 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4646 my $parent = $co{'parent'};
4647 my $parents = $co{'parents'}; # listref
4649 # we need to prepare $formats_nav before any parameter munging
4651 if (!defined $parent) {
4653 $formats_nav .= '(initial)';
4654 } elsif (@$parents == 1) {
4655 # single parent commit
4658 $cgi->a({-href
=> href
(action
=>"commit",
4660 esc_html
(substr($parent, 0, 7))) .
4667 $cgi->a({-href
=> href
(action
=>"commit",
4669 esc_html
(substr($_, 0, 7)));
4674 if (!defined $parent) {
4678 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4680 (@$parents <= 1 ? $parent : '-c'),
4682 or die_error
(undef, "Open git-diff-tree failed");
4683 @difftree = map { chomp; $_ } <$fd>;
4684 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4686 # non-textual hash id's can be cached
4688 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4691 my $refs = git_get_references
();
4692 my $ref = format_ref_marker
($refs, $co{'id'});
4694 git_header_html
(undef, $expires);
4695 git_print_page_nav
('commit', '',
4696 $hash, $co{'tree'}, $hash,
4699 if (defined $co{'parent'}) {
4700 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4702 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4704 print "<div class=\"title_text\">\n" .
4705 "<table class=\"object_header\">\n";
4706 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4708 "<td></td><td> $ad{'rfc2822'}";
4709 if ($ad{'hour_local'} < 6) {
4710 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4711 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4713 printf(" (%02d:%02d %s)",
4714 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4718 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4719 print "<tr><td></td><td> $cd{'rfc2822'}" .
4720 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4722 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4725 "<td class=\"sha1\">" .
4726 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4727 class => "list"}, $co{'tree'}) .
4729 "<td class=\"link\">" .
4730 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4732 my $snapshot_links = format_snapshot_links
($hash);
4733 if (defined $snapshot_links) {
4734 print " | " . $snapshot_links;
4739 foreach my $par (@$parents) {
4742 "<td class=\"sha1\">" .
4743 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4744 class => "list"}, $par) .
4746 "<td class=\"link\">" .
4747 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4749 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4756 print "<div class=\"page_body\">\n";
4757 git_print_log
($co{'comment'});
4760 git_difftree_body
(\
@difftree, $hash, @$parents);
4766 # object is defined by:
4767 # - hash or hash_base alone
4768 # - hash_base and file_name
4771 # - hash or hash_base alone
4772 if ($hash || ($hash_base && !defined $file_name)) {
4773 my $object_id = $hash || $hash_base;
4775 my $git_command = git_cmd_str
();
4776 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4777 or die_error
('404 Not Found', "Object does not exist");
4781 or die_error
('404 Not Found', "Object does not exist");
4783 # - hash_base and file_name
4784 } elsif ($hash_base && defined $file_name) {
4785 $file_name =~ s
,/+$,,;
4787 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4788 or die_error
('404 Not Found', "Base object does not exist");
4790 # here errors should not hapen
4791 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4792 or die_error
(undef, "Open git-ls-tree failed");
4796 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4797 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4798 die_error
('404 Not Found', "File or directory for given base does not exist");
4803 die_error
('404 Not Found', "Not enough information to find object");
4806 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4807 hash
=>$hash, hash_base
=>$hash_base,
4808 file_name
=>$file_name),
4809 -status
=> '302 Found');
4813 my $format = shift || 'html';
4820 # preparing $fd and %diffinfo for git_patchset_body
4822 if (defined $hash_base && defined $hash_parent_base) {
4823 if (defined $file_name) {
4825 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4826 $hash_parent_base, $hash_base,
4827 "--", (defined $file_parent ? $file_parent : ()), $file_name
4828 or die_error
(undef, "Open git-diff-tree failed");
4829 @difftree = map { chomp; $_ } <$fd>;
4831 or die_error
(undef, "Reading git-diff-tree failed");
4833 or die_error
('404 Not Found', "Blob diff not found");
4835 } elsif (defined $hash &&
4836 $hash =~ /[0-9a-fA-F]{40}/) {
4837 # try to find filename from $hash
4839 # read filtered raw output
4840 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4841 $hash_parent_base, $hash_base, "--"
4842 or die_error
(undef, "Open git-diff-tree failed");
4844 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4846 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4847 map { chomp; $_ } <$fd>;
4849 or die_error
(undef, "Reading git-diff-tree failed");
4851 or die_error
('404 Not Found', "Blob diff not found");
4854 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4857 if (@difftree > 1) {
4858 die_error
('404 Not Found', "Ambiguous blob diff specification");
4861 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4862 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4863 $file_name ||= $diffinfo{'to_file'};
4865 $hash_parent ||= $diffinfo{'from_id'};
4866 $hash ||= $diffinfo{'to_id'};
4868 # non-textual hash id's can be cached
4869 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4870 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4875 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4876 '-p', ($format eq 'html' ? "--full-index" : ()),
4877 $hash_parent_base, $hash_base,
4878 "--", (defined $file_parent ? $file_parent : ()), $file_name
4879 or die_error
(undef, "Open git-diff-tree failed");
4882 # old/legacy style URI
4883 if (!%diffinfo && # if new style URI failed
4884 defined $hash && defined $hash_parent) {
4885 # fake git-diff-tree raw output
4886 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4887 $diffinfo{'from_id'} = $hash_parent;
4888 $diffinfo{'to_id'} = $hash;
4889 if (defined $file_name) {
4890 if (defined $file_parent) {
4891 $diffinfo{'status'} = '2';
4892 $diffinfo{'from_file'} = $file_parent;
4893 $diffinfo{'to_file'} = $file_name;
4894 } else { # assume not renamed
4895 $diffinfo{'status'} = '1';
4896 $diffinfo{'from_file'} = $file_name;
4897 $diffinfo{'to_file'} = $file_name;
4899 } else { # no filename given
4900 $diffinfo{'status'} = '2';
4901 $diffinfo{'from_file'} = $hash_parent;
4902 $diffinfo{'to_file'} = $hash;
4905 # non-textual hash id's can be cached
4906 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4907 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4912 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4913 '-p', ($format eq 'html' ? "--full-index" : ()),
4914 $hash_parent, $hash, "--"
4915 or die_error
(undef, "Open git-diff failed");
4917 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4922 if ($format eq 'html') {
4924 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4926 git_header_html
(undef, $expires);
4927 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4928 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4929 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4931 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4932 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4934 if (defined $file_name) {
4935 git_print_page_path
($file_name, "blob", $hash_base);
4937 print "<div class=\"page_path\"></div>\n";
4940 } elsif ($format eq 'plain') {
4942 -type
=> 'text/plain',
4943 -charset
=> 'utf-8',
4944 -expires
=> $expires,
4945 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4947 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4950 die_error
(undef, "Unknown blobdiff format");
4954 if ($format eq 'html') {
4955 print "<div class=\"page_body\">\n";
4957 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4960 print "</div>\n"; # class="page_body"
4964 while (my $line = <$fd>) {
4965 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4966 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4970 last if $line =~ m!^\+\+\+!;
4978 sub git_blobdiff_plain
{
4979 git_blobdiff
('plain');
4982 sub git_commitdiff
{
4983 my $format = shift || 'html';
4984 $hash ||= $hash_base || "HEAD";
4985 my %co = parse_commit
($hash);
4987 die_error
(undef, "Unknown commit object");
4990 # choose format for commitdiff for merge
4991 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4992 $hash_parent = '--cc';
4994 # we need to prepare $formats_nav before almost any parameter munging
4996 if ($format eq 'html') {
4998 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5001 if (defined $hash_parent &&
5002 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5003 # commitdiff with two commits given
5004 my $hash_parent_short = $hash_parent;
5005 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5006 $hash_parent_short = substr($hash_parent, 0, 7);
5010 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5011 if ($co{'parents'}[$i] eq $hash_parent) {
5012 $formats_nav .= ' parent ' . ($i+1);
5016 $formats_nav .= ': ' .
5017 $cgi->a({-href
=> href
(action
=>"commitdiff",
5018 hash
=>$hash_parent)},
5019 esc_html
($hash_parent_short)) .
5021 } elsif (!$co{'parent'}) {
5023 $formats_nav .= ' (initial)';
5024 } elsif (scalar @{$co{'parents'}} == 1) {
5025 # single parent commit
5028 $cgi->a({-href
=> href
(action
=>"commitdiff",
5029 hash
=>$co{'parent'})},
5030 esc_html
(substr($co{'parent'}, 0, 7))) .
5034 if ($hash_parent eq '--cc') {
5035 $formats_nav .= ' | ' .
5036 $cgi->a({-href
=> href
(action
=>"commitdiff",
5037 hash
=>$hash, hash_parent
=>'-c')},
5039 } else { # $hash_parent eq '-c'
5040 $formats_nav .= ' | ' .
5041 $cgi->a({-href
=> href
(action
=>"commitdiff",
5042 hash
=>$hash, hash_parent
=>'--cc')},
5048 $cgi->a({-href
=> href
(action
=>"commitdiff",
5050 esc_html
(substr($_, 0, 7)));
5051 } @{$co{'parents'}} ) .
5056 my $hash_parent_param = $hash_parent;
5057 if (!defined $hash_parent_param) {
5058 # --cc for multiple parents, --root for parentless
5059 $hash_parent_param =
5060 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5066 if ($format eq 'html') {
5067 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5068 "--no-commit-id", "--patch-with-raw", "--full-index",
5069 $hash_parent_param, $hash, "--"
5070 or die_error
(undef, "Open git-diff-tree failed");
5072 while (my $line = <$fd>) {
5074 # empty line ends raw part of diff-tree output
5076 push @difftree, scalar parse_difftree_raw_line
($line);
5079 } elsif ($format eq 'plain') {
5080 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5081 '-p', $hash_parent_param, $hash, "--"
5082 or die_error
(undef, "Open git-diff-tree failed");
5085 die_error
(undef, "Unknown commitdiff format");
5088 # non-textual hash id's can be cached
5090 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5094 # write commit message
5095 if ($format eq 'html') {
5096 my $refs = git_get_references
();
5097 my $ref = format_ref_marker
($refs, $co{'id'});
5099 git_header_html
(undef, $expires);
5100 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5101 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5102 git_print_authorship
(\
%co);
5103 print "<div class=\"page_body\">\n";
5104 if (@{$co{'comment'}} > 1) {
5105 print "<div class=\"log\">\n";
5106 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5107 print "</div>\n"; # class="log"
5110 } elsif ($format eq 'plain') {
5111 my $refs = git_get_references
("tags");
5112 my $tagname = git_get_rev_name_tags
($hash);
5113 my $filename = basename
($project) . "-$hash.patch";
5116 -type
=> 'text/plain',
5117 -charset
=> 'utf-8',
5118 -expires
=> $expires,
5119 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5120 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5121 print "From: " . to_utf8
($co{'author'}) . "\n";
5122 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5123 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5125 print "X-Git-Tag: $tagname\n" if $tagname;
5126 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5128 foreach my $line (@{$co{'comment'}}) {
5129 print to_utf8
($line) . "\n";
5135 if ($format eq 'html') {
5136 my $use_parents = !defined $hash_parent ||
5137 $hash_parent eq '-c' || $hash_parent eq '--cc';
5138 git_difftree_body
(\
@difftree, $hash,
5139 $use_parents ? @{$co{'parents'}} : $hash_parent);
5142 git_patchset_body
($fd, \
@difftree, $hash,
5143 $use_parents ? @{$co{'parents'}} : $hash_parent);
5145 print "</div>\n"; # class="page_body"
5148 } elsif ($format eq 'plain') {
5152 or print "Reading git-diff-tree failed\n";
5156 sub git_commitdiff_plain
{
5157 git_commitdiff
('plain');
5161 if (!defined $hash_base) {
5162 $hash_base = git_get_head_hash
($project);
5164 if (!defined $page) {
5168 my %co = parse_commit
($hash_base);
5170 die_error
(undef, "Unknown commit object");
5173 my $refs = git_get_references
();
5174 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5176 if (!defined $hash && defined $file_name) {
5177 $hash = git_get_hash_by_path
($hash_base, $file_name);
5179 if (defined $hash) {
5180 $ftype = git_get_type
($hash);
5183 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), $file_name, "--full-history");
5185 my $paging_nav = '';
5188 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5189 file_name
=>$file_name)},
5191 $paging_nav .= " ⋅ " .
5192 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5193 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5195 $paging_nav .= "first";
5196 $paging_nav .= " ⋅ prev";
5199 if ($#commitlist >= 100) {
5201 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5202 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5203 $paging_nav .= " ⋅ $next_link";
5205 $paging_nav .= " ⋅ next";
5209 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5210 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5211 git_print_page_path
($file_name, $ftype, $hash_base);
5213 git_history_body
(\
@commitlist, 0, 99,
5214 $refs, $hash_base, $ftype, $next_link);
5220 my ($have_search) = gitweb_check_feature
('search');
5221 if (!$have_search) {
5222 die_error
('403 Permission denied', "Permission denied");
5224 if (!defined $searchtext) {
5225 die_error
(undef, "Text field empty");
5227 if (!defined $hash) {
5228 $hash = git_get_head_hash
($project);
5230 my %co = parse_commit
($hash);
5232 die_error
(undef, "Unknown commit object");
5234 if (!defined $page) {
5238 $searchtype ||= 'commit';
5239 if ($searchtype eq 'pickaxe') {
5240 # pickaxe may take all resources of your box and run for several minutes
5241 # with every query - so decide by yourself how public you make this feature
5242 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5243 if (!$have_pickaxe) {
5244 die_error
('403 Permission denied', "Permission denied");
5247 if ($searchtype eq 'grep') {
5248 my ($have_grep) = gitweb_check_feature
('grep');
5250 die_error
('403 Permission denied', "Permission denied");
5256 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5258 if ($searchtype eq 'commit') {
5259 $greptype = "--grep=";
5260 } elsif ($searchtype eq 'author') {
5261 $greptype = "--author=";
5262 } elsif ($searchtype eq 'committer') {
5263 $greptype = "--committer=";
5265 $greptype .= $searchtext;
5266 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5267 $greptype, '--regexp-ignore-case',
5268 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5270 my $paging_nav = '';
5273 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5274 searchtext
=>$searchtext,
5275 searchtype
=>$searchtype)},
5277 $paging_nav .= " ⋅ " .
5278 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5279 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5281 $paging_nav .= "first";
5282 $paging_nav .= " ⋅ prev";
5285 if ($#commitlist >= 100) {
5287 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5288 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5289 $paging_nav .= " ⋅ $next_link";
5291 $paging_nav .= " ⋅ next";
5294 if ($#commitlist >= 100) {
5297 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5298 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5299 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5302 if ($searchtype eq 'pickaxe') {
5303 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5304 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5306 print "<table class=\"pickaxe search\">\n";
5309 my $git_command = git_cmd_str
();
5310 my $searchqtext = $searchtext;
5311 $searchqtext =~ s/'/'\\''/;
5312 my $pickaxe_flags = $search_use_regexp ? '--pickaxe-regex' : '';
5313 open my $fd, "-|", "$git_command rev-list $hash | " .
5314 "$git_command diff-tree -r --stdin -S\'$searchqtext\' $pickaxe_flags";
5317 while (my $line = <$fd>) {
5318 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5321 $set{'from_id'} = $3;
5323 $set{'id'} = $set{'to_id'};
5324 if ($set{'id'} =~ m/0{40}/) {
5325 $set{'id'} = $set{'from_id'};
5327 if ($set{'id'} =~ m/0{40}/) {
5331 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5334 print "<tr class=\"dark\">\n";
5336 print "<tr class=\"light\">\n";
5339 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5340 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5341 "<td><i>" . $author . "</i></td>\n" .
5343 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5344 -class => "list subject"},
5345 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5346 while (my $setref = shift @files) {
5348 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5349 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5351 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5355 "<td class=\"link\">" .
5356 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5358 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5362 %co = parse_commit
($1);
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";