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 # if we're called with PATH_INFO, we have to strip that
31 # from the URL to find our real URL
32 if (my $path_info = $ENV{"PATH_INFO"}) {
33 $my_url =~ s
,\Q
$path_info\E
$,,;
34 $my_uri =~ s
,\Q
$path_info\E
$,,;
37 # core git executable to use
38 # this can just be "git" if your webserver has a sensible PATH
39 our $GIT = "++GIT_BINDIR++/git";
41 # absolute fs-path which will be prepended to the project path
42 #our $projectroot = "/pub/scm";
43 our $projectroot = "++GITWEB_PROJECTROOT++";
45 # fs traversing limit for getting project list
46 # the number is relative to the projectroot
47 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
49 # target of the home link on top of all pages
50 our $home_link = $my_uri || "/";
52 # string of the home link on top of all pages
53 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
55 # name of your site or organization to appear in page titles
56 # replace this with something more descriptive for clearer bookmarks
57 our $site_name = "++GITWEB_SITENAME++"
58 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
60 # filename of html text to include at top of each page
61 our $site_header = "++GITWEB_SITE_HEADER++";
62 # html text to include at home page
63 our $home_text = "++GITWEB_HOMETEXT++";
64 # filename of html text to include at bottom of each page
65 our $site_footer = "++GITWEB_SITE_FOOTER++";
68 our @stylesheets = ("++GITWEB_CSS++");
69 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
70 our $stylesheet = undef;
71 # URI of GIT logo (72x27 size)
72 our $logo = "++GITWEB_LOGO++";
73 # URI of GIT favicon, assumed to be image/png type
74 our $favicon = "++GITWEB_FAVICON++";
76 our $gitwebjs = "++GITWEB_GITWEBJS++";
78 # URI and label (title) of GIT logo link
79 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
80 #our $logo_label = "git documentation";
81 our $logo_url = "http://git.or.cz/";
82 our $logo_label = "git homepage";
84 # source of projects list
85 our $projects_list = "++GITWEB_LIST++";
87 # the width (in characters) of the projects list "Description" column
88 our $projects_list_description_width = 25;
90 # default order of projects list
91 # valid values are none, project, descr, owner, and age
92 our $default_projects_order = "project";
94 # show repository only if this file exists
95 # (only effective if this variable evaluates to true)
96 our $export_ok = "++GITWEB_EXPORT_OK++";
98 # only allow viewing of repositories also shown on the overview page
99 our $strict_export = "++GITWEB_STRICT_EXPORT++";
101 # list of git base URLs used for URL to where fetch project from,
102 # i.e. full URL is "$git_base_url/$project"
103 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
105 # default blob_plain mimetype and default charset for text/plain blob
106 our $default_blob_plain_mimetype = 'text/plain';
107 our $default_text_plain_charset = undef;
109 # file to use for guessing MIME types before trying /etc/mime.types
110 # (relative to the current git repository)
111 our $mimetypes_file = undef;
113 # assume this charset if line contains non-UTF-8 characters;
114 # it should be valid encoding (see Encoding::Supported(3pm) for list),
115 # for which encoding all byte sequences are valid, for example
116 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
117 # could be even 'utf-8' for the old behavior)
118 our $fallback_encoding = 'latin1';
120 # rename detection options for git-diff and git-diff-tree
121 # - default is '-M', with the cost proportional to
122 # (number of removed files) * (number of new files).
123 # - more costly is '-C' (which implies '-M'), with the cost proportional to
124 # (number of changed files + number of removed files) * (number of new files)
125 # - even more costly is '-C', '--find-copies-harder' with cost
126 # (number of files in the original tree) * (number of new files)
127 # - one might want to include '-B' option, e.g. '-B', '-M'
128 our @diff_opts = ('-M'); # taken from git_commit
130 # information about snapshot formats that gitweb is capable of serving
131 our %known_snapshot_formats = (
133 # 'display' => display name,
134 # 'type' => mime type,
135 # 'suffix' => filename suffix,
136 # 'format' => --format for git-archive,
137 # 'compressor' => [compressor command and arguments]
138 # (array reference, optional)}
141 'display' => 'tar.gz',
142 'type' => 'application/x-gzip',
143 'suffix' => '.tar.gz',
145 'compressor' => ['gzip']},
148 'display' => 'tar.bz2',
149 'type' => 'application/x-bzip2',
150 'suffix' => '.tar.bz2',
152 'compressor' => ['bzip2']},
156 'type' => 'application/x-zip',
161 # Aliases so we understand old gitweb.snapshot values in repository
163 our %known_snapshot_format_aliases = (
167 # backward compatibility: legacy gitweb config support
168 'x-gzip' => undef, 'gz' => undef,
169 'x-bzip2' => undef, 'bz2' => undef,
170 'x-zip' => undef, '' => undef,
173 # You define site-wide feature defaults here; override them with
174 # $GITWEB_CONFIG as necessary.
177 # 'sub' => feature-sub (subroutine),
178 # 'override' => allow-override (boolean),
179 # 'default' => [ default options...] (array reference)}
181 # if feature is overridable (it means that allow-override has true value),
182 # then feature-sub will be called with default options as parameters;
183 # return value of feature-sub indicates if to enable specified feature
185 # if there is no 'sub' key (no feature-sub), then feature cannot be
188 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
190 # Enable the 'blame' blob view, showing the last commit that modified
191 # each line in the file. This can be very CPU-intensive.
193 # To enable system wide have in $GITWEB_CONFIG
194 # $feature{'blame'}{'default'} = [1];
195 # To have project specific config enable override in $GITWEB_CONFIG
196 # $feature{'blame'}{'override'} = 1;
197 # and in project config gitweb.blame = 0|1;
199 'sub' => \
&feature_blame
,
203 # Enable the 'snapshot' link, providing a compressed archive of any
204 # tree. This can potentially generate high traffic if you have large
207 # Value is a list of formats defined in %known_snapshot_formats that
209 # To disable system wide have in $GITWEB_CONFIG
210 # $feature{'snapshot'}{'default'} = [];
211 # To have project specific config enable override in $GITWEB_CONFIG
212 # $feature{'snapshot'}{'override'} = 1;
213 # and in project config, a comma-separated list of formats or "none"
214 # to disable. Example: gitweb.snapshot = tbz2,zip;
216 'sub' => \
&feature_snapshot
,
218 'default' => ['tgz']},
220 # Enable text search, which will list the commits which match author,
221 # committer or commit text to a given string. Enabled by default.
222 # Project specific override is not supported.
227 # Enable grep search, which will list the files in currently selected
228 # tree containing the given string. Enabled by default. This can be
229 # potentially CPU-intensive, of course.
231 # To enable system wide have in $GITWEB_CONFIG
232 # $feature{'grep'}{'default'} = [1];
233 # To have project specific config enable override in $GITWEB_CONFIG
234 # $feature{'grep'}{'override'} = 1;
235 # and in project config gitweb.grep = 0|1;
240 # Enable the pickaxe search, which will list the commits that modified
241 # a given string in a file. This can be practical and quite faster
242 # alternative to 'blame', but still potentially CPU-intensive.
244 # To enable system wide have in $GITWEB_CONFIG
245 # $feature{'pickaxe'}{'default'} = [1];
246 # To have project specific config enable override in $GITWEB_CONFIG
247 # $feature{'pickaxe'}{'override'} = 1;
248 # and in project config gitweb.pickaxe = 0|1;
250 'sub' => \
&feature_pickaxe
,
254 # Make gitweb use an alternative format of the URLs which can be
255 # more readable and natural-looking: project name is embedded
256 # directly in the path and the query string contains other
257 # auxiliary information. All gitweb installations recognize
258 # URL in either format; this configures in which formats gitweb
261 # To enable system wide have in $GITWEB_CONFIG
262 # $feature{'pathinfo'}{'default'} = [1];
263 # Project specific override is not supported.
265 # Note that you will need to change the default location of CSS,
266 # favicon, logo and possibly other files to an absolute URL. Also,
267 # if gitweb.cgi serves as your indexfile, you will need to force
268 # $my_uri to contain the script name in your $GITWEB_CONFIG.
273 # Make gitweb consider projects in project root subdirectories
274 # to be forks of existing projects. Given project $projname.git,
275 # projects matching $projname/*.git will not be shown in the main
276 # projects list, instead a '+' mark will be added to $projname
277 # there and a 'forks' view will be enabled for the project, listing
278 # all the forks. If project list is taken from a file, forks have
279 # to be listed after the main project.
281 # To enable system wide have in $GITWEB_CONFIG
282 # $feature{'forks'}{'default'} = [1];
283 # Project specific override is not supported.
289 sub gitweb_check_feature
{
291 return unless exists $feature{$name};
292 my ($sub, $override, @defaults) = (
293 $feature{$name}{'sub'},
294 $feature{$name}{'override'},
295 @
{$feature{$name}{'default'}});
296 if (!$override) { return @defaults; }
298 warn "feature $name is not overrideable";
301 return $sub->(@defaults);
305 my ($val) = git_get_project_config
('blame', '--bool');
307 if ($val eq 'true') {
309 } elsif ($val eq 'false') {
316 sub feature_snapshot
{
319 my ($val) = git_get_project_config
('snapshot');
322 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
329 my ($val) = git_get_project_config
('grep', '--bool');
331 if ($val eq 'true') {
333 } elsif ($val eq 'false') {
340 sub feature_pickaxe
{
341 my ($val) = git_get_project_config
('pickaxe', '--bool');
343 if ($val eq 'true') {
345 } elsif ($val eq 'false') {
352 # checking HEAD file with -e is fragile if the repository was
353 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
355 sub check_head_link
{
357 my $headfile = "$dir/HEAD";
358 return ((-e
$headfile) ||
359 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
362 sub check_export_ok
{
364 return (check_head_link
($dir) &&
365 (!$export_ok || -e
"$dir/$export_ok"));
368 # process alternate names for backward compatibility
369 # filter out unsupported (unknown) snapshot formats
370 sub filter_snapshot_fmts
{
374 exists $known_snapshot_format_aliases{$_} ?
375 $known_snapshot_format_aliases{$_} : $_} @fmts;
376 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
380 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
381 if (-e
$GITWEB_CONFIG) {
384 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
385 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
388 # version of the core git binary
389 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
391 $projects_list ||= $projectroot;
393 # ======================================================================
394 # input validation and dispatch
395 our $action = $cgi->param('a');
396 if (defined $action) {
397 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
398 die_error
(400, "Invalid action parameter");
402 # parameters which are pathnames
403 our $project = $cgi->param('p');
404 if (defined $project) {
405 if (!validate_pathname
($project) ||
406 !(-d
"$projectroot/$project") ||
407 !check_head_link
("$projectroot/$project") ||
408 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
409 ($strict_export && !project_in_list
($project))) {
411 die_error
(404, "No such project");
415 our $file_name = $cgi->param('f');
416 if (defined $file_name) {
417 if (!validate_pathname
($file_name)) {
418 die_error
(400, "Invalid file parameter");
422 our $file_parent = $cgi->param('fp');
423 if (defined $file_parent) {
424 if (!validate_pathname
($file_parent)) {
425 die_error
(400, "Invalid file parent parameter");
429 # parameters which are refnames
430 our $hash = $cgi->param('h');
432 if (!validate_refname
($hash)) {
433 die_error
(400, "Invalid hash parameter");
437 our $hash_parent = $cgi->param('hp');
438 if (defined $hash_parent) {
439 if (!validate_refname
($hash_parent)) {
440 die_error
(400, "Invalid hash parent parameter");
444 our $hash_base = $cgi->param('hb');
445 if (defined $hash_base) {
446 if (!validate_refname
($hash_base)) {
447 die_error
(400, "Invalid hash base parameter");
451 my %allowed_options = (
452 "--no-merges" => [ qw(rss atom log shortlog history) ],
455 our @extra_options = $cgi->param('opt');
456 if (defined @extra_options) {
457 foreach my $opt (@extra_options) {
458 if (not exists $allowed_options{$opt}) {
459 die_error
(400, "Invalid option parameter");
461 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
462 die_error
(400, "Invalid option parameter for this action");
467 our $hash_parent_base = $cgi->param('hpb');
468 if (defined $hash_parent_base) {
469 if (!validate_refname
($hash_parent_base)) {
470 die_error
(400, "Invalid hash parent base parameter");
475 our $page = $cgi->param('pg');
477 if ($page =~ m/[^0-9]/) {
478 die_error
(400, "Invalid page parameter");
482 our $searchtype = $cgi->param('st');
483 if (defined $searchtype) {
484 if ($searchtype =~ m/[^a-z]/) {
485 die_error
(400, "Invalid searchtype parameter");
489 our $search_use_regexp = $cgi->param('sr');
491 our $searchtext = $cgi->param('s');
493 if (defined $searchtext) {
494 if (length($searchtext) < 2) {
495 die_error
(403, "At least two characters are required for search parameter");
497 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
500 # now read PATH_INFO and use it as alternative to parameters
501 sub evaluate_path_info
{
502 return if defined $project;
503 my $path_info = $ENV{"PATH_INFO"};
504 return if !$path_info;
505 $path_info =~ s
,^/+,,;
506 return if !$path_info;
507 # find which part of PATH_INFO is project
508 $project = $path_info;
510 while ($project && !check_head_link
("$projectroot/$project")) {
511 $project =~ s
,/*[^/]*$,,;
514 $project = validate_pathname
($project);
516 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
517 ($strict_export && !project_in_list
($project))) {
521 # do not change any parameters if an action is given using the query string
523 $path_info =~ s
,^\Q
$project\E
/*,,;
524 my ($refname, $pathname) = split(/:/, $path_info, 2);
525 if (defined $pathname) {
526 # we got "project.git/branch:filename" or "project.git/branch:dir/"
527 # we could use git_get_type(branch:pathname), but it needs $git_dir
528 $pathname =~ s
,^/+,,;
529 if (!$pathname || substr($pathname, -1) eq "/") {
533 $action ||= "blob_plain";
535 $hash_base ||= validate_refname
($refname);
536 $file_name ||= validate_pathname
($pathname);
537 } elsif (defined $refname) {
538 # we got "project.git/branch"
539 $action ||= "shortlog";
540 $hash ||= validate_refname
($refname);
543 evaluate_path_info
();
545 # path to the current git repository
547 $git_dir = "$projectroot/$project" if $project;
551 "blame" => \
&git_blame
,
552 "blobdiff" => \
&git_blobdiff
,
553 "blobdiff_plain" => \
&git_blobdiff_plain
,
554 "blob" => \
&git_blob
,
555 "blob_plain" => \
&git_blob_plain
,
556 "commitdiff" => \
&git_commitdiff
,
557 "commitdiff_plain" => \
&git_commitdiff_plain
,
558 "commit" => \
&git_commit
,
559 "forks" => \
&git_forks
,
560 "heads" => \
&git_heads
,
561 "history" => \
&git_history
,
564 "atom" => \
&git_atom
,
565 "search" => \
&git_search
,
566 "search_help" => \
&git_search_help
,
567 "shortlog" => \
&git_shortlog
,
568 "summary" => \
&git_summary
,
570 "tags" => \
&git_tags
,
571 "tree" => \
&git_tree
,
572 "snapshot" => \
&git_snapshot
,
573 "object" => \
&git_object
,
574 # those below don't need $project
575 "opml" => \
&git_opml
,
576 "project_list" => \
&git_project_list
,
577 "project_index" => \
&git_project_index
,
580 if (!defined $action) {
582 $action = git_get_type
($hash);
583 } elsif (defined $hash_base && defined $file_name) {
584 $action = git_get_type
("$hash_base:$file_name");
585 } elsif (defined $project) {
588 $action = 'project_list';
591 if (!defined($actions{$action})) {
592 die_error
(400, "Unknown action");
594 if ($action !~ m/^(opml|project_list|project_index)$/ &&
596 die_error
(400, "Project needed");
598 $actions{$action}->();
601 ## ======================================================================
606 # default is to use -absolute url() i.e. $my_uri
607 my $href = $params{-full
} ?
$my_url : $my_uri;
609 # XXX: Warning: If you touch this, check the search form for updating,
620 hash_parent_base
=> "hpb",
625 snapshot_format
=> "sf",
626 extra_options
=> "opt",
627 search_use_regexp
=> "sr",
629 my %mapping = @mapping;
631 $params{'project'} = $project unless exists $params{'project'};
633 if ($params{-replay
}) {
634 while (my ($name, $symbol) = each %mapping) {
635 if (!exists $params{$name}) {
636 # to allow for multivalued params we use arrayref form
637 $params{$name} = [ $cgi->param($symbol) ];
642 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
644 # use PATH_INFO for project name
645 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
646 delete $params{'project'};
648 # Summary just uses the project path URL
649 if (defined $params{'action'} && $params{'action'} eq 'summary') {
650 delete $params{'action'};
654 # now encode the parameters explicitly
656 for (my $i = 0; $i < @mapping; $i += 2) {
657 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
658 if (defined $params{$name}) {
659 if (ref($params{$name}) eq "ARRAY") {
660 foreach my $par (@
{$params{$name}}) {
661 push @result, $symbol . "=" . esc_param
($par);
664 push @result, $symbol . "=" . esc_param
($params{$name});
668 $href .= "?" . join(';', @result) if scalar @result;
674 ## ======================================================================
675 ## validation, quoting/unquoting and escaping
677 sub validate_pathname
{
678 my $input = shift || return undef;
680 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
681 # at the beginning, at the end, and between slashes.
682 # also this catches doubled slashes
683 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
687 if ($input =~ m!\0!) {
693 sub validate_refname
{
694 my $input = shift || return undef;
696 # textual hashes are O.K.
697 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
700 # it must be correct pathname
701 $input = validate_pathname
($input)
703 # restrictions on ref name according to git-check-ref-format
704 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
710 # decode sequences of octets in utf8 into Perl's internal form,
711 # which is utf-8 with utf8 flag set if needed. gitweb writes out
712 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
715 if (utf8
::valid
($str)) {
719 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
723 # quote unsafe chars, but keep the slash, even when it's not
724 # correct, but quoted slashes look too horrible in bookmarks
727 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
733 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
736 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
742 # replace invalid utf8 character with SUBSTITUTION sequence
747 $str = to_utf8
($str);
748 $str = $cgi->escapeHTML($str);
749 if ($opts{'-nbsp'}) {
750 $str =~ s/ / /g;
752 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
756 # quote control characters and escape filename to HTML
761 $str = to_utf8
($str);
762 $str = $cgi->escapeHTML($str);
763 if ($opts{'-nbsp'}) {
764 $str =~ s/ / /g;
766 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
770 # Make control characters "printable", using character escape codes (CEC)
774 my %es = ( # character escape codes, aka escape sequences
775 "\t" => '\t', # tab (HT)
776 "\n" => '\n', # line feed (LF)
777 "\r" => '\r', # carrige return (CR)
778 "\f" => '\f', # form feed (FF)
779 "\b" => '\b', # backspace (BS)
780 "\a" => '\a', # alarm (bell) (BEL)
781 "\e" => '\e', # escape (ESC)
782 "\013" => '\v', # vertical tab (VT)
783 "\000" => '\0', # nul character (NUL)
785 my $chr = ( (exists $es{$cntrl})
787 : sprintf('\%2x', ord($cntrl)) );
788 if ($opts{-nohtml
}) {
791 return "<span class=\"cntrl\">$chr</span>";
795 # Alternatively use unicode control pictures codepoints,
796 # Unicode "printable representation" (PR)
801 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
802 if ($opts{-nohtml
}) {
805 return "<span class=\"cntrl\">$chr</span>";
809 # git may return quoted and escaped filenames
815 my %es = ( # character escape codes, aka escape sequences
816 't' => "\t", # tab (HT, TAB)
817 'n' => "\n", # newline (NL)
818 'r' => "\r", # return (CR)
819 'f' => "\f", # form feed (FF)
820 'b' => "\b", # backspace (BS)
821 'a' => "\a", # alarm (bell) (BEL)
822 'e' => "\e", # escape (ESC)
823 'v' => "\013", # vertical tab (VT)
826 if ($seq =~ m/^[0-7]{1,3}$/) {
827 # octal char sequence
828 return chr(oct($seq));
829 } elsif (exists $es{$seq}) {
830 # C escape sequence, aka character escape code
833 # quoted ordinary character
837 if ($str =~ m/^"(.*)"$/) {
840 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
845 # escape tabs (convert tabs to spaces)
849 while ((my $pos = index($line, "\t")) != -1) {
850 if (my $count = (8 - ($pos % 8))) {
851 my $spaces = ' ' x
$count;
852 $line =~ s/\t/$spaces/;
859 sub project_in_list
{
861 my @list = git_get_projects_list
();
862 return @list && scalar(grep { $_->{'path'} eq $project } @list);
865 ## ----------------------------------------------------------------------
866 ## HTML aware string manipulation
868 # Try to chop given string on a word boundary between position
869 # $len and $len+$add_len. If there is no word boundary there,
870 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
871 # (marking chopped part) would be longer than given string.
875 my $add_len = shift || 10;
876 my $where = shift || 'right'; # 'left' | 'center' | 'right'
878 # Make sure perl knows it is utf8 encoded so we don't
879 # cut in the middle of a utf8 multibyte char.
880 $str = to_utf8
($str);
882 # allow only $len chars, but don't cut a word if it would fit in $add_len
883 # if it doesn't fit, cut it if it's still longer than the dots we would add
884 # remove chopped character entities entirely
886 # when chopping in the middle, distribute $len into left and right part
887 # return early if chopping wouldn't make string shorter
888 if ($where eq 'center') {
889 return $str if ($len + 5 >= length($str)); # filler is length 5
892 return $str if ($len + 4 >= length($str)); # filler is length 4
895 # regexps: ending and beginning with word part up to $add_len
896 my $endre = qr/.{$len}\w{0,$add_len}/;
897 my $begre = qr/\w{0,$add_len}.{$len}/;
899 if ($where eq 'left') {
900 $str =~ m/^(.*?)($begre)$/;
901 my ($lead, $body) = ($1, $2);
902 if (length($lead) > 4) {
903 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
908 } elsif ($where eq 'center') {
909 $str =~ m/^($endre)(.*)$/;
910 my ($left, $str) = ($1, $2);
911 $str =~ m/^(.*?)($begre)$/;
912 my ($mid, $right) = ($1, $2);
913 if (length($mid) > 5) {
914 $left =~ s/&[^;]*$//;
915 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
918 return "$left$mid$right";
921 $str =~ m/^($endre)(.*)$/;
924 if (length($tail) > 4) {
925 $body =~ s/&[^;]*$//;
932 # takes the same arguments as chop_str, but also wraps a <span> around the
933 # result with a title attribute if it does get chopped. Additionally, the
934 # string is HTML-escaped.
935 sub chop_and_escape_str
{
938 my $chopped = chop_str
(@_);
939 if ($chopped eq $str) {
940 return esc_html
($chopped);
942 $str =~ s/([[:cntrl:]])/?/g;
943 return $cgi->span({-title
=>$str}, esc_html
($chopped));
947 ## ----------------------------------------------------------------------
948 ## functions returning short strings
950 # CSS class for given age value (in seconds)
956 } elsif ($age < 60*60*2) {
958 } elsif ($age < 60*60*24*2) {
965 # convert age in seconds to "nn units ago" string
970 if ($age > 60*60*24*365*2) {
971 $age_str = (int $age/60/60/24/365);
972 $age_str .= " years ago";
973 } elsif ($age > 60*60*24*(365/12)*2) {
974 $age_str = int $age/60/60/24/(365/12);
975 $age_str .= " months ago";
976 } elsif ($age > 60*60*24*7*2) {
977 $age_str = int $age/60/60/24/7;
978 $age_str .= " weeks ago";
979 } elsif ($age > 60*60*24*2) {
980 $age_str = int $age/60/60/24;
981 $age_str .= " days ago";
982 } elsif ($age > 60*60*2) {
983 $age_str = int $age/60/60;
984 $age_str .= " hours ago";
985 } elsif ($age > 60*2) {
986 $age_str = int $age/60;
987 $age_str .= " min ago";
990 $age_str .= " sec ago";
992 $age_str .= " right now";
998 S_IFINVALID
=> 0030000,
999 S_IFGITLINK
=> 0160000,
1002 # submodule/subproject, a commit object reference
1003 sub S_ISGITLINK
($) {
1006 return (($mode & S_IFMT
) == S_IFGITLINK
)
1009 # convert file mode in octal to symbolic file mode string
1011 my $mode = oct shift;
1013 if (S_ISGITLINK
($mode)) {
1014 return 'm---------';
1015 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1016 return 'drwxr-xr-x';
1017 } elsif (S_ISLNK
($mode)) {
1018 return 'lrwxrwxrwx';
1019 } elsif (S_ISREG
($mode)) {
1020 # git cares only about the executable bit
1021 if ($mode & S_IXUSR
) {
1022 return '-rwxr-xr-x';
1024 return '-rw-r--r--';
1027 return '----------';
1031 # convert file mode in octal to file type string
1035 if ($mode !~ m/^[0-7]+$/) {
1041 if (S_ISGITLINK
($mode)) {
1043 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1045 } elsif (S_ISLNK
($mode)) {
1047 } elsif (S_ISREG
($mode)) {
1054 # convert file mode in octal to file type description string
1055 sub file_type_long
{
1058 if ($mode !~ m/^[0-7]+$/) {
1064 if (S_ISGITLINK
($mode)) {
1066 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1068 } elsif (S_ISLNK
($mode)) {
1070 } elsif (S_ISREG
($mode)) {
1071 if ($mode & S_IXUSR
) {
1072 return "executable";
1082 ## ----------------------------------------------------------------------
1083 ## functions returning short HTML fragments, or transforming HTML fragments
1084 ## which don't belong to other sections
1086 # format line of commit message.
1087 sub format_log_line_html
{
1090 $line = esc_html
($line, -nbsp
=>1);
1091 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1094 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1095 -class => "text"}, $hash_text);
1096 $line =~ s/$hash_text/$link/;
1101 # format marker of refs pointing to given object
1103 # the destination action is chosen based on object type and current context:
1104 # - for annotated tags, we choose the tag view unless it's the current view
1105 # already, in which case we go to shortlog view
1106 # - for other refs, we keep the current view if we're in history, shortlog or
1107 # log view, and select shortlog otherwise
1108 sub format_ref_marker
{
1109 my ($refs, $id) = @_;
1112 if (defined $refs->{$id}) {
1113 foreach my $ref (@
{$refs->{$id}}) {
1114 # this code exploits the fact that non-lightweight tags are the
1115 # only indirect objects, and that they are the only objects for which
1116 # we want to use tag instead of shortlog as action
1117 my ($type, $name) = qw();
1118 my $indirect = ($ref =~ s/\^\{\}$//);
1119 # e.g. tags/v2.6.11 or heads/next
1120 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1129 $class .= " indirect" if $indirect;
1131 my $dest_action = "shortlog";
1134 $dest_action = "tag" unless $action eq "tag";
1135 } elsif ($action =~ /^(history|(short)?log)$/) {
1136 $dest_action = $action;
1140 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1143 my $link = $cgi->a({
1145 action
=>$dest_action,
1149 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1155 return ' <span class="refs">'. $markers . '</span>';
1161 # format, perhaps shortened and with markers, title line
1162 sub format_subject_html
{
1163 my ($long, $short, $href, $extra) = @_;
1164 $extra = '' unless defined($extra);
1166 if (length($short) < length($long)) {
1167 return $cgi->a({-href
=> $href, -class => "list subject",
1168 -title
=> to_utf8
($long)},
1169 esc_html
($short) . $extra);
1171 return $cgi->a({-href
=> $href, -class => "list subject"},
1172 esc_html
($long) . $extra);
1176 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1177 sub format_git_diff_header_line
{
1179 my $diffinfo = shift;
1180 my ($from, $to) = @_;
1182 if ($diffinfo->{'nparents'}) {
1184 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1185 if ($to->{'href'}) {
1186 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1187 esc_path
($to->{'file'}));
1188 } else { # file was deleted (no href)
1189 $line .= esc_path
($to->{'file'});
1193 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1194 if ($from->{'href'}) {
1195 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1196 'a/' . esc_path
($from->{'file'}));
1197 } else { # file was added (no href)
1198 $line .= 'a/' . esc_path
($from->{'file'});
1201 if ($to->{'href'}) {
1202 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1203 'b/' . esc_path
($to->{'file'}));
1204 } else { # file was deleted
1205 $line .= 'b/' . esc_path
($to->{'file'});
1209 return "<div class=\"diff header\">$line</div>\n";
1212 # format extended diff header line, before patch itself
1213 sub format_extended_diff_header_line
{
1215 my $diffinfo = shift;
1216 my ($from, $to) = @_;
1219 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1220 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1221 esc_path
($from->{'file'}));
1223 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1224 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1225 esc_path
($to->{'file'}));
1227 # match single <mode>
1228 if ($line =~ m/\s(\d{6})$/) {
1229 $line .= '<span class="info"> (' .
1230 file_type_long
($1) .
1234 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1235 # can match only for combined diff
1237 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1238 if ($from->{'href'}[$i]) {
1239 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1241 substr($diffinfo->{'from_id'}[$i],0,7));
1246 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1249 if ($to->{'href'}) {
1250 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1251 substr($diffinfo->{'to_id'},0,7));
1256 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1257 # can match only for ordinary diff
1258 my ($from_link, $to_link);
1259 if ($from->{'href'}) {
1260 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1261 substr($diffinfo->{'from_id'},0,7));
1263 $from_link = '0' x
7;
1265 if ($to->{'href'}) {
1266 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1267 substr($diffinfo->{'to_id'},0,7));
1271 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1272 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1275 return $line . "<br/>\n";
1278 # format from-file/to-file diff header
1279 sub format_diff_from_to_header
{
1280 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1285 #assert($line =~ m/^---/) if DEBUG;
1286 # no extra formatting for "^--- /dev/null"
1287 if (! $diffinfo->{'nparents'}) {
1288 # ordinary (single parent) diff
1289 if ($line =~ m!^--- "?a/!) {
1290 if ($from->{'href'}) {
1292 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1293 esc_path
($from->{'file'}));
1296 esc_path
($from->{'file'});
1299 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1302 # combined diff (merge commit)
1303 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1304 if ($from->{'href'}[$i]) {
1306 $cgi->a({-href
=>href
(action
=>"blobdiff",
1307 hash_parent
=>$diffinfo->{'from_id'}[$i],
1308 hash_parent_base
=>$parents[$i],
1309 file_parent
=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i],
1310 hash
=>$diffinfo->{'to_id'},
1312 file_name
=>$diffinfo->{'to_prefix'}.$to->{'file'}),
1314 -title
=>"diff" . ($i+1)},
1317 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1318 esc_path
($from->{'file'}[$i]));
1320 $line = '--- /dev/null';
1322 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1327 #assert($line =~ m/^\+\+\+/) if DEBUG;
1328 # no extra formatting for "^+++ /dev/null"
1329 if ($line =~ m!^\+\+\+ "?b/!) {
1330 if ($to->{'href'}) {
1332 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1333 esc_path
($to->{'file'}));
1336 esc_path
($to->{'file'});
1339 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1344 # create note for patch simplified by combined diff
1345 sub format_diff_cc_simplified
{
1346 my ($diffinfo, @parents) = @_;
1349 $result .= "<div class=\"diff header\">" .
1351 if (!is_deleted
($diffinfo)) {
1352 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1354 hash
=>$diffinfo->{'to_id'},
1355 file_name
=>$diffinfo->{'to_prefix'}.$diffinfo->{'to_file'}),
1357 esc_path
($diffinfo->{'to_file'}));
1359 $result .= esc_path
($diffinfo->{'to_file'});
1361 $result .= "</div>\n" . # class="diff header"
1362 "<div class=\"diff nodifferences\">" .
1364 "</div>\n"; # class="diff nodifferences"
1369 # format patch (diff) line (not to be used for diff headers)
1370 sub format_diff_line
{
1372 my ($from, $to) = @_;
1373 my $diff_class = "";
1377 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1379 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1380 if ($line =~ m/^\@{3}/) {
1381 $diff_class = " chunk_header";
1382 } elsif ($line =~ m/^\\/) {
1383 $diff_class = " incomplete";
1384 } elsif ($prefix =~ tr/+/+/) {
1385 $diff_class = " add";
1386 } elsif ($prefix =~ tr/-/-/) {
1387 $diff_class = " rem";
1390 # assume ordinary diff
1391 my $char = substr($line, 0, 1);
1393 $diff_class = " add";
1394 } elsif ($char eq '-') {
1395 $diff_class = " rem";
1396 } elsif ($char eq '@') {
1397 $diff_class = " chunk_header";
1398 } elsif ($char eq "\\") {
1399 $diff_class = " incomplete";
1402 $line = untabify
($line);
1403 if ($from && $to && $line =~ m/^\@{2} /) {
1404 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1405 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1407 $from_lines = 0 unless defined $from_lines;
1408 $to_lines = 0 unless defined $to_lines;
1410 if ($from->{'href'}) {
1411 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1412 -class=>"list"}, $from_text);
1414 if ($to->{'href'}) {
1415 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1416 -class=>"list"}, $to_text);
1418 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1419 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1420 return "<div class=\"diff$diff_class\">$line</div>\n";
1421 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1422 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1423 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1425 @from_text = split(' ', $ranges);
1426 for (my $i = 0; $i < @from_text; ++$i) {
1427 ($from_start[$i], $from_nlines[$i]) =
1428 (split(',', substr($from_text[$i], 1)), 0);
1431 $to_text = pop @from_text;
1432 $to_start = pop @from_start;
1433 $to_nlines = pop @from_nlines;
1435 $line = "<span class=\"chunk_info\">$prefix ";
1436 for (my $i = 0; $i < @from_text; ++$i) {
1437 if ($from->{'href'}[$i]) {
1438 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1439 -class=>"list"}, $from_text[$i]);
1441 $line .= $from_text[$i];
1445 if ($to->{'href'}) {
1446 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1447 -class=>"list"}, $to_text);
1451 $line .= " $prefix</span>" .
1452 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1453 return "<div class=\"diff$diff_class\">$line</div>\n";
1455 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1458 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1459 # linked. Pass the hash of the tree/commit to snapshot.
1460 sub format_snapshot_links
{
1462 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1463 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1464 my $num_fmts = @snapshot_fmts;
1465 if ($num_fmts > 1) {
1466 # A parenthesized list of links bearing format names.
1467 # e.g. "snapshot (_tar.gz_ _zip_)"
1468 return "snapshot (" . join(' ', map
1475 }, $known_snapshot_formats{$_}{'display'})
1476 , @snapshot_fmts) . ")";
1477 } elsif ($num_fmts == 1) {
1478 # A single "snapshot" link whose tooltip bears the format name.
1480 my ($fmt) = @snapshot_fmts;
1486 snapshot_format
=>$fmt
1488 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1490 } else { # $num_fmts == 0
1495 ## ......................................................................
1496 ## functions returning values to be passed, perhaps after some
1497 ## transformation, to other functions; e.g. returning arguments to href()
1499 # returns hash to be passed to href to generate gitweb URL
1500 # in -title key it returns description of link
1502 my $format = shift || 'Atom';
1503 my %res = (action
=> lc($format));
1505 # feed links are possible only for project views
1506 return unless (defined $project);
1507 # some views should link to OPML, or to generic project feed,
1508 # or don't have specific feed yet (so they should use generic)
1509 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1512 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1513 # from tag links; this also makes possible to detect branch links
1514 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1515 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1518 # find log type for feed description (title)
1520 if (defined $file_name) {
1521 $type = "history of $file_name";
1522 $type .= "/" if ($action eq 'tree');
1523 $type .= " on '$branch'" if (defined $branch);
1525 $type = "log of $branch" if (defined $branch);
1528 $res{-title
} = $type;
1529 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1530 $res{'file_name'} = $file_name;
1535 ## ----------------------------------------------------------------------
1536 ## git utility subroutines, invoking git commands
1538 # returns path to the core git executable and the --git-dir parameter as list
1540 return $GIT, '--git-dir='.$git_dir;
1543 # quote the given arguments for passing them to the shell
1544 # quote_command("command", "arg 1", "arg with ' and ! characters")
1545 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1546 # Try to avoid using this function wherever possible.
1549 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1552 # get HEAD ref of given project as hash
1553 sub git_get_head_hash
{
1554 my $project = shift;
1555 my $o_git_dir = $git_dir;
1557 $git_dir = "$projectroot/$project";
1558 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1561 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1565 if (defined $o_git_dir) {
1566 $git_dir = $o_git_dir;
1571 # get type of given object
1575 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1577 close $fd or return;
1582 # repository configuration
1583 our $config_file = '';
1586 # store multiple values for single key as anonymous array reference
1587 # single values stored directly in the hash, not as [ <value> ]
1588 sub hash_set_multi
{
1589 my ($hash, $key, $value) = @_;
1591 if (!exists $hash->{$key}) {
1592 $hash->{$key} = $value;
1593 } elsif (!ref $hash->{$key}) {
1594 $hash->{$key} = [ $hash->{$key}, $value ];
1596 push @
{$hash->{$key}}, $value;
1600 # return hash of git project configuration
1601 # optionally limited to some section, e.g. 'gitweb'
1602 sub git_parse_project_config
{
1603 my $section_regexp = shift;
1608 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1611 while (my $keyval = <$fh>) {
1613 my ($key, $value) = split(/\n/, $keyval, 2);
1615 hash_set_multi
(\
%config, $key, $value)
1616 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1623 # convert config value to boolean, 'true' or 'false'
1624 # no value, number > 0, 'true' and 'yes' values are true
1625 # rest of values are treated as false (never as error)
1626 sub config_to_bool
{
1629 # strip leading and trailing whitespace
1633 return (!defined $val || # section.key
1634 ($val =~ /^\d+$/ && $val) || # section.key = 1
1635 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1638 # convert config value to simple decimal number
1639 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1640 # to be multiplied by 1024, 1048576, or 1073741824
1644 # strip leading and trailing whitespace
1648 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1650 # unknown unit is treated as 1
1651 return $num * ($unit eq 'g' ?
1073741824 :
1652 $unit eq 'm' ?
1048576 :
1653 $unit eq 'k' ?
1024 : 1);
1658 # convert config value to array reference, if needed
1659 sub config_to_multi
{
1662 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1665 sub git_get_project_config
{
1666 my ($key, $type) = @_;
1669 return unless ($key);
1670 $key =~ s/^gitweb\.//;
1671 return if ($key =~ m/\W/);
1674 if (defined $type) {
1677 unless ($type eq 'bool' || $type eq 'int');
1681 if (!defined $config_file ||
1682 $config_file ne "$git_dir/config") {
1683 %config = git_parse_project_config
('gitweb');
1684 $config_file = "$git_dir/config";
1688 if (!defined $type) {
1689 return $config{"gitweb.$key"};
1690 } elsif ($type eq 'bool') {
1691 # backward compatibility: 'git config --bool' returns true/false
1692 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1693 } elsif ($type eq 'int') {
1694 return config_to_int
($config{"gitweb.$key"});
1696 return $config{"gitweb.$key"};
1699 # get hash of given path at given ref
1700 sub git_get_hash_by_path
{
1702 my $path = shift || return undef;
1707 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1708 or die_error
(500, "Open git-ls-tree failed");
1710 close $fd or return undef;
1712 if (!defined $line) {
1713 # there is no tree or hash given by $path at $base
1717 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1718 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1719 if (defined $type && $type ne $2) {
1720 # type doesn't match
1726 # get path of entry with given hash at given tree-ish (ref)
1727 # used to get 'from' filename for combined diff (merge commit) for renames
1728 sub git_get_path_by_hash
{
1729 my $base = shift || return;
1730 my $hash = shift || return;
1734 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1736 while (my $line = <$fd>) {
1739 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1740 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1741 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1750 ## ......................................................................
1751 ## git utility functions, directly accessing git repository
1753 sub git_get_project_description
{
1756 $git_dir = "$projectroot/$path";
1757 open my $fd, "$git_dir/description"
1758 or return git_get_project_config
('description');
1761 if (defined $descr) {
1767 sub git_get_project_url_list
{
1770 $git_dir = "$projectroot/$path";
1771 open my $fd, "$git_dir/cloneurl"
1772 or return wantarray ?
1773 @
{ config_to_multi
(git_get_project_config
('url')) } :
1774 config_to_multi
(git_get_project_config
('url'));
1775 my @git_project_url_list = map { chomp; $_ } <$fd>;
1778 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1781 sub git_get_projects_list
{
1786 $filter =~ s/\.git$//;
1788 my ($check_forks) = gitweb_check_feature
('forks');
1790 if (-d
$projects_list) {
1791 # search in directory
1792 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1793 # remove the trailing "/"
1795 my $pfxlen = length("$dir");
1796 my $pfxdepth = ($dir =~ tr!/!!);
1799 follow_fast
=> 1, # follow symbolic links
1800 follow_skip
=> 2, # ignore duplicates
1801 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1803 # skip project-list toplevel, if we get it.
1804 return if (m!^[/.]$!);
1805 # only directories can be git repositories
1806 return unless (-d
$_);
1807 # don't traverse too deep (Find is super slow on os x)
1808 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1809 $File::Find
::prune
= 1;
1813 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1814 # we check related file in $projectroot
1815 if ($check_forks and $subdir =~ m
#/.#) {
1816 $File::Find
::prune
= 1;
1817 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1818 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1819 $File::Find
::prune
= 1;
1824 } elsif (-f
$projects_list) {
1825 # read from file(url-encoded):
1826 # 'git%2Fgit.git Linus+Torvalds'
1827 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1828 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1830 open my ($fd), $projects_list or return;
1832 while (my $line = <$fd>) {
1834 my ($path, $owner) = split ' ', $line;
1835 $path = unescape
($path);
1836 $owner = unescape
($owner);
1837 if (!defined $path) {
1840 if ($filter ne '') {
1841 # looking for forks;
1842 my $pfx = substr($path, 0, length($filter));
1843 if ($pfx ne $filter) {
1846 my $sfx = substr($path, length($filter));
1847 if ($sfx !~ /^\/.*\
.git
$/) {
1850 } elsif ($check_forks) {
1852 foreach my $filter (keys %paths) {
1853 # looking for forks;
1854 my $pfx = substr($path, 0, length($filter));
1855 if ($pfx ne $filter) {
1858 my $sfx = substr($path, length($filter));
1859 if ($sfx !~ /^\/.*\
.git
$/) {
1862 # is a fork, don't include it in
1867 if (check_export_ok
("$projectroot/$path")) {
1870 owner
=> to_utf8
($owner),
1873 (my $forks_path = $path) =~ s/\.git$//;
1874 $paths{$forks_path}++;
1882 our $gitweb_project_owner = undef;
1883 sub git_get_project_list_from_file
{
1885 return if (defined $gitweb_project_owner);
1887 $gitweb_project_owner = {};
1888 # read from file (url-encoded):
1889 # 'git%2Fgit.git Linus+Torvalds'
1890 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1891 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1892 if (-f
$projects_list) {
1893 open (my $fd , $projects_list);
1894 while (my $line = <$fd>) {
1896 my ($pr, $ow) = split ' ', $line;
1897 $pr = unescape
($pr);
1898 $ow = unescape
($ow);
1899 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1905 sub git_get_project_owner
{
1906 my $project = shift;
1909 return undef unless $project;
1910 $git_dir = "$projectroot/$project";
1912 if (!defined $gitweb_project_owner) {
1913 git_get_project_list_from_file
();
1916 if (exists $gitweb_project_owner->{$project}) {
1917 $owner = $gitweb_project_owner->{$project};
1919 if (!defined $owner){
1920 $owner = git_get_project_config
('owner');
1922 if (!defined $owner) {
1923 $owner = get_file_owner
("$git_dir");
1929 sub git_get_last_activity
{
1933 $git_dir = "$projectroot/$path";
1934 open($fd, "-|", git_cmd
(), 'for-each-ref',
1935 '--format=%(committer)',
1936 '--sort=-committerdate',
1938 'refs/heads') or return;
1939 my $most_recent = <$fd>;
1940 close $fd or return;
1941 if (defined $most_recent &&
1942 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1944 my $age = time - $timestamp;
1945 return ($age, age_string
($age));
1947 return (undef, undef);
1950 sub git_get_references
{
1951 my $type = shift || "";
1953 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1954 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1955 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1956 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1959 while (my $line = <$fd>) {
1961 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
1962 if (defined $refs{$1}) {
1963 push @
{$refs{$1}}, $2;
1969 close $fd or return;
1973 sub git_get_rev_name_tags
{
1974 my $hash = shift || return undef;
1976 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1978 my $name_rev = <$fd>;
1981 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1984 # catches also '$hash undefined' output
1989 ## ----------------------------------------------------------------------
1990 ## parse to hash functions
1994 my $tz = shift || "-0000";
1997 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1998 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1999 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2000 $date{'hour'} = $hour;
2001 $date{'minute'} = $min;
2002 $date{'mday'} = $mday;
2003 $date{'day'} = $days[$wday];
2004 $date{'month'} = $months[$mon];
2005 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2006 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2007 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2008 $mday, $months[$mon], $hour ,$min;
2009 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2010 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2012 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2013 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2014 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2015 $date{'hour_local'} = $hour;
2016 $date{'minute_local'} = $min;
2017 $date{'tz_local'} = $tz;
2018 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2019 1900+$year, $mon+1, $mday,
2020 $hour, $min, $sec, $tz);
2029 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2030 $tag{'id'} = $tag_id;
2031 while (my $line = <$fd>) {
2033 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2034 $tag{'object'} = $1;
2035 } elsif ($line =~ m/^type (.+)$/) {
2037 } elsif ($line =~ m/^tag (.+)$/) {
2039 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2040 $tag{'author'} = $1;
2043 } elsif ($line =~ m/--BEGIN/) {
2044 push @comment, $line;
2046 } elsif ($line eq "") {
2050 push @comment, <$fd>;
2051 $tag{'comment'} = \
@comment;
2052 close $fd or return;
2053 if (!defined $tag{'name'}) {
2059 sub parse_commit_text
{
2060 my ($commit_text, $withparents) = @_;
2061 my @commit_lines = split '\n', $commit_text;
2064 pop @commit_lines; # Remove '\0'
2066 if (! @commit_lines) {
2070 my $header = shift @commit_lines;
2071 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2074 ($co{'id'}, my @parents) = split ' ', $header;
2075 while (my $line = shift @commit_lines) {
2076 last if $line eq "\n";
2077 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2079 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2081 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2083 $co{'author_epoch'} = $2;
2084 $co{'author_tz'} = $3;
2085 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2086 $co{'author_name'} = $1;
2087 $co{'author_email'} = $2;
2089 $co{'author_name'} = $co{'author'};
2091 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2092 $co{'committer'} = $1;
2093 $co{'committer_epoch'} = $2;
2094 $co{'committer_tz'} = $3;
2095 $co{'committer_name'} = $co{'committer'};
2096 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2097 $co{'committer_name'} = $1;
2098 $co{'committer_email'} = $2;
2100 $co{'committer_name'} = $co{'committer'};
2104 if (!defined $co{'tree'}) {
2107 $co{'parents'} = \
@parents;
2108 $co{'parent'} = $parents[0];
2110 foreach my $title (@commit_lines) {
2113 $co{'title'} = chop_str
($title, 80, 5);
2114 # remove leading stuff of merges to make the interesting part visible
2115 if (length($title) > 50) {
2116 $title =~ s/^Automatic //;
2117 $title =~ s/^merge (of|with) /Merge ... /i;
2118 if (length($title) > 50) {
2119 $title =~ s/(http|rsync):\/\///;
2121 if (length($title) > 50) {
2122 $title =~ s/(master|www|rsync)\.//;
2124 if (length($title) > 50) {
2125 $title =~ s/kernel.org:?//;
2127 if (length($title) > 50) {
2128 $title =~ s/\/pub\/scm//;
2131 $co{'title_short'} = chop_str
($title, 50, 5);
2135 if (! defined $co{'title'} || $co{'title'} eq "") {
2136 $co{'title'} = $co{'title_short'} = '(no commit message)';
2138 # remove added spaces
2139 foreach my $line (@commit_lines) {
2142 $co{'comment'} = \
@commit_lines;
2144 my $age = time - $co{'committer_epoch'};
2146 $co{'age_string'} = age_string
($age);
2147 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2148 if ($age > 60*60*24*7*2) {
2149 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2150 $co{'age_string_age'} = $co{'age_string'};
2152 $co{'age_string_date'} = $co{'age_string'};
2153 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2159 my ($commit_id) = @_;
2164 open my $fd, "-|", git_cmd
(), "rev-list",
2170 or die_error
(500, "Open git-rev-list failed");
2171 %co = parse_commit_text
(<$fd>, 1);
2178 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2186 open my $fd, "-|", git_cmd
(), "rev-list",
2189 ("--max-count=" . $maxcount),
2190 ("--skip=" . $skip),
2194 ($filename ?
($filename) : ())
2195 or die_error
(500, "Open git-rev-list failed");
2196 while (my $line = <$fd>) {
2197 my %co = parse_commit_text
($line);
2202 return wantarray ?
@cos : \
@cos;
2205 # parse line of git-diff-tree "raw" output
2206 sub parse_difftree_raw_line
{
2210 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2211 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2212 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2213 $res{'from_mode'} = $1;
2214 $res{'to_mode'} = $2;
2215 $res{'from_id'} = $3;
2217 $res{'status'} = $5;
2218 $res{'similarity'} = $6;
2219 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2220 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2222 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2225 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2226 # combined diff (for merge commit)
2227 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2228 $res{'nparents'} = length($1);
2229 $res{'from_mode'} = [ split(' ', $2) ];
2230 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2231 $res{'from_id'} = [ split(' ', $3) ];
2232 $res{'to_id'} = pop @
{$res{'from_id'}};
2233 $res{'status'} = [ split('', $4) ];
2234 $res{'to_file'} = unquote
($5);
2236 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2237 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2238 $res{'commit'} = $1;
2241 return wantarray ?
%res : \
%res;
2244 # wrapper: return parsed line of git-diff-tree "raw" output
2245 # (the argument might be raw line, or parsed info)
2246 sub parsed_difftree_line
{
2247 my $line_or_ref = shift;
2249 if (ref($line_or_ref) eq "HASH") {
2250 # pre-parsed (or generated by hand)
2251 return $line_or_ref;
2253 return parse_difftree_raw_line
($line_or_ref);
2257 # parse line of git-ls-tree output
2258 sub parse_ls_tree_line
($;%) {
2263 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2264 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2272 $res{'name'} = unquote
($4);
2275 return wantarray ?
%res : \
%res;
2278 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2279 sub parse_from_to_diffinfo
{
2280 my ($diffinfo, $from, $to, @parents) = @_;
2282 if ($diffinfo->{'nparents'}) {
2284 $from->{'file'} = [];
2285 $from->{'href'} = [];
2286 fill_from_file_info
($diffinfo, @parents)
2287 unless exists $diffinfo->{'from_file'};
2288 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2289 $from->{'file'}[$i] =
2290 defined $diffinfo->{'from_file'}[$i] ?
2291 $diffinfo->{'from_file'}[$i] :
2292 $diffinfo->{'to_file'};
2293 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2294 $from->{'href'}[$i] = href
(action
=>"blob",
2295 hash_base
=>$parents[$i],
2296 hash
=>$diffinfo->{'from_id'}[$i],
2297 file_name
=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i]);
2299 $from->{'href'}[$i] = undef;
2303 # ordinary (not combined) diff
2304 $from->{'file'} = $diffinfo->{'from_file'};
2305 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2306 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2307 hash
=>$diffinfo->{'from_id'},
2308 file_name
=>$diffinfo->{'from_prefix'}.$from->{'file'});
2310 delete $from->{'href'};
2314 $to->{'file'} = $diffinfo->{'to_file'};
2315 if (!is_deleted
($diffinfo)) { # file exists in result
2316 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2317 hash
=>$diffinfo->{'to_id'},
2318 file_name
=>$diffinfo->{'to_prefix'}.$to->{'file'});
2320 delete $to->{'href'};
2324 ## ......................................................................
2325 ## parse to array of hashes functions
2327 sub git_get_heads_list
{
2331 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2332 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2333 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2336 while (my $line = <$fd>) {
2340 my ($refinfo, $committerinfo) = split(/\0/, $line);
2341 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2342 my ($committer, $epoch, $tz) =
2343 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2344 $ref_item{'fullname'} = $name;
2345 $name =~ s!^refs/heads/!!;
2347 $ref_item{'name'} = $name;
2348 $ref_item{'id'} = $hash;
2349 $ref_item{'title'} = $title || '(no commit message)';
2350 $ref_item{'epoch'} = $epoch;
2352 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2354 $ref_item{'age'} = "unknown";
2357 push @headslist, \
%ref_item;
2361 return wantarray ?
@headslist : \
@headslist;
2364 sub git_get_tags_list
{
2368 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2369 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2370 '--format=%(objectname) %(objecttype) %(refname) '.
2371 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2374 while (my $line = <$fd>) {
2378 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2379 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2380 my ($creator, $epoch, $tz) =
2381 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2382 $ref_item{'fullname'} = $name;
2383 $name =~ s!^refs/tags/!!;
2385 $ref_item{'type'} = $type;
2386 $ref_item{'id'} = $id;
2387 $ref_item{'name'} = $name;
2388 if ($type eq "tag") {
2389 $ref_item{'subject'} = $title;
2390 $ref_item{'reftype'} = $reftype;
2391 $ref_item{'refid'} = $refid;
2393 $ref_item{'reftype'} = $type;
2394 $ref_item{'refid'} = $id;
2397 if ($type eq "tag" || $type eq "commit") {
2398 $ref_item{'epoch'} = $epoch;
2400 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2402 $ref_item{'age'} = "unknown";
2406 push @tagslist, \
%ref_item;
2410 return wantarray ?
@tagslist : \
@tagslist;
2413 ## ----------------------------------------------------------------------
2414 ## filesystem-related functions
2416 sub get_file_owner
{
2419 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2420 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2421 if (!defined $gcos) {
2425 $owner =~ s/[,;].*$//;
2426 return to_utf8
($owner);
2429 ## ......................................................................
2430 ## mimetype related functions
2432 sub mimetype_guess_file
{
2433 my $filename = shift;
2434 my $mimemap = shift;
2435 -r
$mimemap or return undef;
2438 open(MIME
, $mimemap) or return undef;
2440 next if m/^#/; # skip comments
2441 my ($mime, $exts) = split(/\t+/);
2442 if (defined $exts) {
2443 my @exts = split(/\s+/, $exts);
2444 foreach my $ext (@exts) {
2445 $mimemap{$ext} = $mime;
2451 $filename =~ /\.([^.]*)$/;
2452 return $mimemap{$1};
2455 sub mimetype_guess
{
2456 my $filename = shift;
2458 $filename =~ /\./ or return undef;
2460 if ($mimetypes_file) {
2461 my $file = $mimetypes_file;
2462 if ($file !~ m!^/!) { # if it is relative path
2463 # it is relative to project
2464 $file = "$projectroot/$project/$file";
2466 $mime = mimetype_guess_file
($filename, $file);
2468 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2474 my $filename = shift;
2477 my $mime = mimetype_guess
($filename);
2478 $mime and return $mime;
2482 return $default_blob_plain_mimetype unless $fd;
2485 return 'text/plain';
2486 } elsif (! $filename) {
2487 return 'application/octet-stream';
2488 } elsif ($filename =~ m/\.png$/i) {
2490 } elsif ($filename =~ m/\.gif$/i) {
2492 } elsif ($filename =~ m/\.jpe?g$/i) {
2493 return 'image/jpeg';
2495 return 'application/octet-stream';
2499 sub blob_contenttype
{
2500 my ($fd, $file_name, $type) = @_;
2502 $type ||= blob_mimetype
($fd, $file_name);
2503 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2504 $type .= "; charset=$default_text_plain_charset";
2510 ## ======================================================================
2511 ## functions printing HTML: header, footer, error page
2513 sub git_header_html
{
2514 my $status = shift || "200 OK";
2515 my $expires = shift;
2517 my $title = "$site_name";
2518 if (defined $project) {
2519 $title .= " - " . to_utf8
($project);
2520 if (defined $action) {
2521 $title .= "/$action";
2522 if (defined $file_name) {
2523 $title .= " - " . esc_path
($file_name);
2524 if ($action eq "tree" && $file_name !~ m
|/$|) {
2531 # require explicit support from the UA if we are to send the page as
2532 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2533 # we have to do this because MSIE sometimes globs '*/*', pretending to
2534 # support xhtml+xml but choking when it gets what it asked for.
2535 if (defined $cgi->http('HTTP_ACCEPT') &&
2536 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2537 $cgi->Accept('application/xhtml+xml') != 0) {
2538 $content_type = 'application/xhtml+xml';
2540 $content_type = 'text/html';
2542 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2543 -status
=> $status, -expires
=> $expires);
2544 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2546 <?xml version="1.0" encoding="utf-8"?>
2547 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2548 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2549 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2550 <!-- git core binaries version $git_version -->
2552 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2553 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2554 <meta name="robots" content="index, nofollow"/>
2555 <title>$title</title>
2557 # print out each stylesheet that exist
2558 if (defined $stylesheet) {
2559 #provides backwards capability for those people who define style sheet in a config file
2560 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2562 foreach my $stylesheet (@stylesheets) {
2563 next unless $stylesheet;
2564 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2567 if (defined $project) {
2568 my %href_params = get_feed_info
();
2569 if (!exists $href_params{'-title'}) {
2570 $href_params{'-title'} = 'log';
2573 foreach my $format qw(RSS Atom) {
2574 my $type = lc($format);
2576 '-rel' => 'alternate',
2577 '-title' => "$project - $href_params{'-title'} - $format feed",
2578 '-type' => "application/$type+xml"
2581 $href_params{'action'} = $type;
2582 $link_attr{'-href'} = href
(%href_params);
2584 "rel=\"$link_attr{'-rel'}\" ".
2585 "title=\"$link_attr{'-title'}\" ".
2586 "href=\"$link_attr{'-href'}\" ".
2587 "type=\"$link_attr{'-type'}\" ".
2590 $href_params{'extra_options'} = '--no-merges';
2591 $link_attr{'-href'} = href
(%href_params);
2592 $link_attr{'-title'} .= ' (no merges)';
2594 "rel=\"$link_attr{'-rel'}\" ".
2595 "title=\"$link_attr{'-title'}\" ".
2596 "href=\"$link_attr{'-href'}\" ".
2597 "type=\"$link_attr{'-type'}\" ".
2602 printf('<link rel="alternate" title="%s projects list" '.
2603 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2604 $site_name, href
(project
=>undef, action
=>"project_index"));
2605 printf('<link rel="alternate" title="%s projects feeds" '.
2606 'href="%s" type="text/x-opml" />'."\n",
2607 $site_name, href
(project
=>undef, action
=>"opml"));
2609 if (defined $favicon) {
2610 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2613 if (defined $gitwebjs) {
2614 print qq(<script src
="$gitwebjs" type
="text/javascript"></script
>\n);
2620 if (-f
$site_header) {
2621 open (my $fd, $site_header);
2626 print "<div class=\"page_header\">\n" .
2627 $cgi->a({-href
=> esc_url
($logo_url),
2628 -title
=> $logo_label},
2629 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2630 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2631 if (defined $project) {
2632 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2633 if (defined $action) {
2640 my ($have_search) = gitweb_check_feature
('search');
2641 if (defined $project && $have_search) {
2642 if (!defined $searchtext) {
2646 if (defined $hash_base) {
2647 $search_hash = $hash_base;
2648 } elsif (defined $hash) {
2649 $search_hash = $hash;
2651 $search_hash = "HEAD";
2653 my $action = $my_uri;
2654 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2655 if ($use_pathinfo) {
2656 $action .= "/".esc_url
($project);
2658 print $cgi->startform(-method
=> "get", -action
=> $action) .
2659 "<div class=\"search\">\n" .
2661 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2662 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2663 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2664 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2665 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2666 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2668 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2669 "<span title=\"Extended regular expression\">" .
2670 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2671 -checked
=> $search_use_regexp) .
2674 $cgi->end_form() . "\n";
2678 sub git_footer_html
{
2679 my $feed_class = 'rss_logo';
2681 print "<div class=\"page_footer\">\n";
2682 if (defined $project) {
2683 my $descr = git_get_project_description
($project);
2684 if (defined $descr) {
2685 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2688 my %href_params = get_feed_info
();
2689 if (!%href_params) {
2690 $feed_class .= ' generic';
2692 $href_params{'-title'} ||= 'log';
2694 foreach my $format qw(RSS Atom) {
2695 $href_params{'action'} = lc($format);
2696 print $cgi->a({-href
=> href
(%href_params),
2697 -title
=> "$href_params{'-title'} $format feed",
2698 -class => $feed_class}, $format)."\n";
2702 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2703 -class => $feed_class}, "OPML") . " ";
2704 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2705 -class => $feed_class}, "TXT") . "\n";
2707 print "</div>\n"; # class="page_footer"
2709 if (-f
$site_footer) {
2710 open (my $fd, $site_footer);
2719 # die_error(<http_status_code>, <error_message>)
2720 # Example: die_error(404, 'Hash not found')
2721 # By convention, use the following status codes (as defined in RFC 2616):
2722 # 400: Invalid or missing CGI parameters, or
2723 # requested object exists but has wrong type.
2724 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2725 # this server or project.
2726 # 404: Requested object/revision/project doesn't exist.
2727 # 500: The server isn't configured properly, or
2728 # an internal error occurred (e.g. failed assertions caused by bugs), or
2729 # an unknown error occurred (e.g. the git binary died unexpectedly).
2731 my $status = shift || 500;
2732 my $error = shift || "Internal server error";
2734 my %http_responses = (400 => '400 Bad Request',
2735 403 => '403 Forbidden',
2736 404 => '404 Not Found',
2737 500 => '500 Internal Server Error');
2738 git_header_html
($http_responses{$status});
2740 <div class="page_body">
2750 ## ----------------------------------------------------------------------
2751 ## functions printing or outputting HTML: navigation
2753 sub git_print_page_nav
{
2754 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2755 $extra = '' if !defined $extra; # pager or formats
2757 my @navs = qw(summary shortlog log commit commitdiff tree);
2759 @navs = grep { $_ ne $suppress } @navs;
2762 my %arg = map { $_ => {action
=>$_} } @navs;
2763 if (defined $head) {
2764 for (qw(commit commitdiff)) {
2765 $arg{$_}{'hash'} = $head;
2767 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2768 for (qw(shortlog log)) {
2769 $arg{$_}{'hash'} = $head;
2773 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2774 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2776 print "<div class=\"page_nav\">\n" .
2778 map { $_ eq $current ?
2779 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2781 print "<br/>\n$extra<br/>\n" .
2785 sub format_paging_nav
{
2786 my ($action, $hash, $head, $page, $has_next_link) = @_;
2790 if ($hash ne $head || $page) {
2791 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2793 $paging_nav .= "HEAD";
2797 $paging_nav .= " ⋅ " .
2798 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2799 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2801 $paging_nav .= " ⋅ prev";
2804 if ($has_next_link) {
2805 $paging_nav .= " ⋅ " .
2806 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2807 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2809 $paging_nav .= " ⋅ next";
2815 ## ......................................................................
2816 ## functions printing or outputting HTML: div
2818 sub git_print_header_div
{
2819 my ($action, $title, $hash, $hash_base) = @_;
2822 $args{'action'} = $action;
2823 $args{'hash'} = $hash if $hash;
2824 $args{'hash_base'} = $hash_base if $hash_base;
2826 print "<div class=\"header\">\n" .
2827 $cgi->a({-href
=> href
(%args), -class => "title"},
2828 $title ?
$title : $action) .
2832 #sub git_print_authorship (\%) {
2833 sub git_print_authorship
{
2836 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2837 print "<div class=\"author_date\">" .
2838 esc_html
($co->{'author_name'}) .
2840 if ($ad{'hour_local'} < 6) {
2841 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2842 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2844 printf(" (%02d:%02d %s)",
2845 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2850 sub git_print_page_path
{
2856 print "<div class=\"page_path\">";
2857 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2858 -title
=> 'tree root'}, to_utf8
("[$project]"));
2860 if (defined $name) {
2861 my @dirname = split '/', $name;
2862 my $basename = pop @dirname;
2865 foreach my $dir (@dirname) {
2866 $fullname .= ($fullname ?
'/' : '') . $dir;
2867 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2869 -title
=> $fullname}, esc_path
($dir));
2872 if (defined $type && $type eq 'blob') {
2873 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2875 -title
=> $name}, esc_path
($basename));
2876 } elsif (defined $type && $type eq 'tree') {
2877 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2879 -title
=> $name}, esc_path
($basename));
2882 print esc_path
($basename);
2885 print "<br/></div>\n";
2888 # sub git_print_log (\@;%) {
2889 sub git_print_log
($;%) {
2893 if ($opts{'-remove_title'}) {
2894 # remove title, i.e. first line of log
2897 # remove leading empty lines
2898 while (defined $log->[0] && $log->[0] eq "") {
2905 foreach my $line (@
$log) {
2906 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2909 if (! $opts{'-remove_signoff'}) {
2910 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2913 # remove signoff lines
2920 # print only one empty line
2921 # do not print empty line after signoff
2923 next if ($empty || $signoff);
2929 print format_log_line_html
($line) . "<br/>\n";
2932 if ($opts{'-final_empty_line'}) {
2933 # end with single empty line
2934 print "<br/>\n" unless $empty;
2938 # return link target (what link points to)
2939 sub git_get_link_target
{
2944 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2948 $link_target = <$fd>;
2953 return $link_target;
2956 # given link target, and the directory (basedir) the link is in,
2957 # return target of link relative to top directory (top tree);
2958 # return undef if it is not possible (including absolute links).
2959 sub normalize_link_target
{
2960 my ($link_target, $basedir, $hash_base) = @_;
2962 # we can normalize symlink target only if $hash_base is provided
2963 return unless $hash_base;
2965 # absolute symlinks (beginning with '/') cannot be normalized
2966 return if (substr($link_target, 0, 1) eq '/');
2968 # normalize link target to path from top (root) tree (dir)
2971 $path = $basedir . '/' . $link_target;
2973 # we are in top (root) tree (dir)
2974 $path = $link_target;
2977 # remove //, /./, and /../
2979 foreach my $part (split('/', $path)) {
2980 # discard '.' and ''
2981 next if (!$part || $part eq '.');
2983 if ($part eq '..') {
2987 # link leads outside repository (outside top dir)
2991 push @path_parts, $part;
2994 $path = join('/', @path_parts);
2999 # print tree entry (row of git_tree), but without encompassing <tr> element
3000 sub git_print_tree_entry
{
3001 my ($t, $basedir, $hash_base, $have_blame) = @_;
3004 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3006 # The format of a table row is: mode list link. Where mode is
3007 # the mode of the entry, list is the name of the entry, an href,
3008 # and link is the action links of the entry.
3010 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3011 if ($t->{'type'} eq "blob") {
3012 print "<td class=\"list\">" .
3013 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3014 file_name
=>"$basedir$t->{'name'}", %base_key),
3015 -class => "list"}, esc_path
($t->{'name'}));
3016 if (S_ISLNK
(oct $t->{'mode'})) {
3017 my $link_target = git_get_link_target
($t->{'hash'});
3019 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3020 if (defined $norm_target) {
3022 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3023 file_name
=>$norm_target),
3024 -title
=> $norm_target}, esc_path
($link_target));
3026 print " -> " . esc_path
($link_target);
3031 print "<td class=\"link\">";
3032 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3033 file_name
=>"$basedir$t->{'name'}", %base_key)},
3037 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3038 file_name
=>"$basedir$t->{'name'}", %base_key)},
3041 if (defined $hash_base) {
3043 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3044 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3048 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3049 file_name
=>"$basedir$t->{'name'}")},
3053 } elsif ($t->{'type'} eq "tree") {
3054 print "<td class=\"list\">";
3055 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3056 file_name
=>"$basedir$t->{'name'}", %base_key)},
3057 esc_path
($t->{'name'}));
3059 print "<td class=\"link\">";
3060 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3061 file_name
=>"$basedir$t->{'name'}", %base_key)},
3063 if (defined $hash_base) {
3065 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3066 file_name
=>"$basedir$t->{'name'}")},
3071 # unknown object: we can only present history for it
3072 # (this includes 'commit' object, i.e. submodule support)
3073 print "<td class=\"list\">" .
3074 esc_path
($t->{'name'}) .
3076 print "<td class=\"link\">";
3077 if (defined $hash_base) {
3078 print $cgi->a({-href
=> href
(action
=>"history",
3079 hash_base
=>$hash_base,
3080 file_name
=>"$basedir$t->{'name'}")},
3087 ## ......................................................................
3088 ## functions printing large fragments of HTML
3090 # get pre-image filenames for merge (combined) diff
3091 sub fill_from_file_info
{
3092 my ($diff, @parents) = @_;
3094 $diff->{'from_file'} = [ ];
3095 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3096 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3097 if ($diff->{'status'}[$i] eq 'R' ||
3098 $diff->{'status'}[$i] eq 'C') {
3099 $diff->{'from_file'}[$i] =
3100 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3107 # is current raw difftree line of file deletion
3109 my $diffinfo = shift;
3111 return $diffinfo->{'to_id'} eq ('0' x
40);
3114 # does patch correspond to [previous] difftree raw line
3115 # $diffinfo - hashref of parsed raw diff format
3116 # $patchinfo - hashref of parsed patch diff format
3117 # (the same keys as in $diffinfo)
3118 sub is_patch_split
{
3119 my ($diffinfo, $patchinfo) = @_;
3121 return defined $diffinfo && defined $patchinfo
3122 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3126 sub git_difftree_body
{
3127 my ($difftree, $from_prefix, $to_prefix, $hash, @parents) = @_;
3128 my ($parent) = $parents[0];
3129 my ($have_blame) = gitweb_check_feature
('blame');
3131 $from_prefix = !defined $from_prefix ?
'' : $from_prefix.'/';
3132 $to_prefix = !defined $to_prefix ?
'' : $to_prefix . '/';
3134 print "<div class=\"list_head\">\n";
3135 if ($#{$difftree} > 10) {
3136 print(($#{$difftree} + 1) . " files changed:\n");
3140 print "<table class=\"" .
3141 (@parents > 1 ?
"combined " : "") .
3144 # header only for combined diff in 'commitdiff' view
3145 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3148 print "<thead><tr>\n" .
3149 "<th></th><th></th>\n"; # filename, patchN link
3150 for (my $i = 0; $i < @parents; $i++) {
3151 my $par = $parents[$i];
3153 $cgi->a({-href
=> href
(action
=>"commitdiff",
3154 hash
=>$hash, hash_parent
=>$par),
3155 -title
=> 'commitdiff to parent number ' .
3156 ($i+1) . ': ' . substr($par,0,7)},
3160 print "</tr></thead>\n<tbody>\n";
3165 foreach my $line (@
{$difftree}) {
3166 my $diff = parsed_difftree_line
($line);
3169 print "<tr class=\"dark\">\n";
3171 print "<tr class=\"light\">\n";
3175 if (exists $diff->{'nparents'}) { # combined diff
3177 fill_from_file_info
($diff, @parents)
3178 unless exists $diff->{'from_file'};
3180 if (!is_deleted
($diff)) {
3181 # file exists in the result (child) commit
3183 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3184 file_name
=>$to_prefix.$diff->{'to_file'},
3186 -class => "list"}, esc_path
($diff->{'to_file'})) .
3190 esc_path
($diff->{'to_file'}) .
3194 if ($action eq 'commitdiff') {
3197 print "<td class=\"link\">" .
3198 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3203 my $has_history = 0;
3204 my $not_deleted = 0;
3205 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3206 my $hash_parent = $parents[$i];
3207 my $from_hash = $diff->{'from_id'}[$i];
3208 my $from_path = $diff->{'from_file'}[$i];
3209 my $status = $diff->{'status'}[$i];
3211 $has_history ||= ($status ne 'A');
3212 $not_deleted ||= ($status ne 'D');
3214 if ($status eq 'A') {
3215 print "<td class=\"link\" align=\"right\"> | </td>\n";
3216 } elsif ($status eq 'D') {
3217 print "<td class=\"link\">" .
3218 $cgi->a({-href
=> href
(action
=>"blob",
3221 file_name
=>$from_prefix.$from_path)},
3225 if ($diff->{'to_id'} eq $from_hash) {
3226 print "<td class=\"link nochange\">";
3228 print "<td class=\"link\">";
3230 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3231 hash
=>$diff->{'to_id'},
3232 hash_parent
=>$from_hash,
3234 hash_parent_base
=>$hash_parent,
3235 file_name
=>$to_prefix.$diff->{'to_file'},
3236 file_parent
=>$from_prefix.$from_path)},
3242 print "<td class=\"link\">";
3244 print $cgi->a({-href
=> href
(action
=>"blob",
3245 hash
=>$diff->{'to_id'},
3246 file_name
=>$to_prefix.$diff->{'to_file'},
3249 print " | " if ($has_history);
3252 print $cgi->a({-href
=> href
(action
=>"history",
3253 file_name
=>$to_prefix.$diff->{'to_file'},
3260 next; # instead of 'else' clause, to avoid extra indent
3262 # else ordinary diff
3264 my ($to_mode_oct, $to_mode_str, $to_file_type);
3265 my ($from_mode_oct, $from_mode_str, $from_file_type);
3266 if ($diff->{'to_mode'} ne ('0' x
6)) {
3267 $to_mode_oct = oct $diff->{'to_mode'};
3268 if (S_ISREG
($to_mode_oct)) { # only for regular file
3269 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3271 $to_file_type = file_type
($diff->{'to_mode'});
3273 if ($diff->{'from_mode'} ne ('0' x
6)) {
3274 $from_mode_oct = oct $diff->{'from_mode'};
3275 if (S_ISREG
($to_mode_oct)) { # only for regular file
3276 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3278 $from_file_type = file_type
($diff->{'from_mode'});
3281 if ($diff->{'status'} eq "A") { # created
3282 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3283 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3284 $mode_chng .= "]</span>";
3286 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3287 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'}),
3288 -class => "list"}, esc_path
($diff->{'file'}));
3290 print "<td>$mode_chng</td>\n";
3291 print "<td class=\"link\">";
3292 if ($action eq 'commitdiff') {
3295 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3298 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3299 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'})},
3303 } elsif ($diff->{'status'} eq "D") { # deleted
3304 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3306 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3307 hash_base
=>$parent, file_name
=>$from_prefix.$diff->{'file'}),
3308 -class => "list"}, esc_path
($diff->{'file'}));
3310 print "<td>$mode_chng</td>\n";
3311 print "<td class=\"link\">";
3312 if ($action eq 'commitdiff') {
3315 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3318 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3319 hash_base
=>$parent, file_name
=>$from_prefix.$diff->{'file'})},
3322 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3323 file_name
=>$from_prefix.$diff->{'file'}), -class => "blamelink"},
3326 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3327 file_name
=>$from_prefix.$diff->{'file'})},
3331 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3332 my $mode_chnge = "";
3333 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3334 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3335 if ($from_file_type ne $to_file_type) {
3336 $mode_chnge .= " from $from_file_type to $to_file_type";
3338 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3339 if ($from_mode_str && $to_mode_str) {
3340 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3341 } elsif ($to_mode_str) {
3342 $mode_chnge .= " mode: $to_mode_str";
3345 $mode_chnge .= "]</span>\n";
3348 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3349 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'}),
3350 -class => "list"}, esc_path
($diff->{'file'}));
3352 print "<td>$mode_chnge</td>\n";
3353 print "<td class=\"link\">";
3354 if ($action eq 'commitdiff') {
3357 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3359 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3360 # "commit" view and modified file (not onlu mode changed)
3361 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3362 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3363 hash_base
=>$hash, hash_parent_base
=>$parent,
3364 file_name
=>$to_prefix.$diff->{'file'},
3365 file_parent
=>$from_prefix.$diff->{'file'})},
3369 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3370 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'})},
3373 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3374 file_name
=>$diff->{'file'}), -class => "blamelink"},
3377 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3378 file_name
=>$to_prefix.$diff->{'file'})},
3382 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3383 my %status_name = ('R' => 'moved', 'C' => 'copied');
3384 my $nstatus = $status_name{$diff->{'status'}};
3386 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3387 # mode also for directories, so we cannot use $to_mode_str
3388 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3391 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3392 hash
=>$diff->{'to_id'}, file_name
=>$to_prefix.$diff->{'to_file'}),
3393 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3394 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3395 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3396 hash
=>$diff->{'from_id'}, file_name
=>$from_prefix.$diff->{'from_file'}),
3397 -class => "list"}, esc_path
($diff->{'from_file'})) .
3398 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3399 "<td class=\"link\">";
3400 if ($action eq 'commitdiff') {
3403 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3405 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3406 # "commit" view and modified file (not only pure rename or copy)
3407 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3408 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3409 hash_base
=>$hash, hash_parent_base
=>$parent,
3410 file_name
=>$to_prefix.$diff->{'to_file'}, file_parent
=>$from_prefix.$diff->{'from_file'})},
3414 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3415 hash_base
=>$parent, file_name
=>$to_prefix.$diff->{'to_file'})},
3418 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3419 file_name
=>$diff->{'to_file'}), -class => "blamelink"},
3422 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3423 file_name
=>$to_prefix.$diff->{'to_file'})},
3427 } # we should not encounter Unmerged (U) or Unknown (X) status
3430 print "</tbody>" if $has_header;
3434 sub git_patchset_body
{
3435 my ($fd, $difftree, $from_prefix, $to_prefix, $hash, @hash_parents) = @_;
3436 my ($hash_parent) = $hash_parents[0];
3438 my $is_combined = (@hash_parents > 1);
3440 my $patch_number = 0;
3446 $from_prefix = !defined $from_prefix ?
'' : $from_prefix.'/';
3447 $to_prefix = !defined $to_prefix ?
'' : $to_prefix . '/';
3449 print "<div class=\"patchset\">\n";
3451 # skip to first patch
3452 while ($patch_line = <$fd>) {
3455 last if ($patch_line =~ m/^diff /);
3459 while ($patch_line) {
3461 # parse "git diff" header line
3462 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3463 # $1 is from_name, which we do not use
3464 $to_name = unquote
($2);
3465 $to_name =~ s!^b/!!;
3466 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3467 # $1 is 'cc' or 'combined', which we do not use
3468 $to_name = unquote
($2);
3473 # check if current patch belong to current raw line
3474 # and parse raw git-diff line if needed
3475 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3476 # this is continuation of a split patch
3477 print "<div class=\"patch cont\">\n";
3478 $diffinfo->{'from_prefix'} = $from_prefix;
3479 $diffinfo->{'to_prefix'} = $to_prefix;
3481 # advance raw git-diff output if needed
3482 $patch_idx++ if defined $diffinfo;
3484 # read and prepare patch information
3485 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3487 # compact combined diff output can have some patches skipped
3488 # find which patch (using pathname of result) we are at now;
3490 while ($to_name ne $diffinfo->{'to_file'}) {
3491 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3492 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3493 "</div>\n"; # class="patch"
3498 last if $patch_idx > $#$difftree;
3499 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3503 $diffinfo->{'from_prefix'} = $from_prefix;
3504 $diffinfo->{'to_prefix'} = $to_prefix;
3506 # modifies %from, %to hashes
3507 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3508 # this is first patch for raw difftree line with $patch_idx index
3509 # we index @$difftree array from 0, but number patches from 1
3510 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3514 #assert($patch_line =~ m/^diff /) if DEBUG;
3515 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3517 # print "git diff" header
3518 print format_git_diff_header_line
($patch_line, $diffinfo,
3521 # print extended diff header
3522 print "<div class=\"diff extended_header\">\n";
3524 while ($patch_line = <$fd>) {
3527 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3529 print format_extended_diff_header_line
($patch_line, $diffinfo,
3532 print "</div>\n"; # class="diff extended_header"
3534 # from-file/to-file diff header
3535 if (! $patch_line) {
3536 print "</div>\n"; # class="patch"
3539 next PATCH
if ($patch_line =~ m/^diff /);
3540 #assert($patch_line =~ m/^---/) if DEBUG;
3542 my $last_patch_line = $patch_line;
3543 $patch_line = <$fd>;
3545 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3547 print format_diff_from_to_header
($last_patch_line, $patch_line,
3548 $diffinfo, \
%from, \
%to,
3553 while ($patch_line = <$fd>) {
3556 next PATCH
if ($patch_line =~ m/^diff /);
3558 print format_diff_line
($patch_line, \
%from, \
%to);
3562 print "</div>\n"; # class="patch"
3565 # for compact combined (--cc) format, with chunk and patch simpliciaction
3566 # patchset might be empty, but there might be unprocessed raw lines
3567 for (++$patch_idx if $patch_number > 0;
3568 $patch_idx < @
$difftree;
3570 # read and prepare patch information
3571 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3573 # generate anchor for "patch" links in difftree / whatchanged part
3574 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3575 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3576 "</div>\n"; # class="patch"
3581 if ($patch_number == 0) {
3582 if (@hash_parents > 1) {
3583 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3585 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3589 print "</div>\n"; # class="patchset"
3592 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3594 # fills project list info (age, description, owner, forks) for each
3595 # project in the list, removing invalid projects from returned list
3596 # NOTE: modifies $projlist, but does not remove entries from it
3597 sub fill_project_list_info
{
3598 my ($projlist, $check_forks) = @_;
3602 foreach my $pr (@
$projlist) {
3603 my (@activity) = git_get_last_activity
($pr->{'path'});
3604 unless (@activity) {
3607 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3608 if (!defined $pr->{'descr'}) {
3609 my $descr = git_get_project_description
($pr->{'path'}) || "";
3610 $descr = to_utf8
($descr);
3611 $pr->{'descr_long'} = $descr;
3612 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3614 if (!defined $pr->{'owner'}) {
3615 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3618 my $pname = $pr->{'path'};
3619 if (($pname =~ s/\.git$//) &&
3620 ($pname !~ /\/$/) &&
3621 (-d
"$projectroot/$pname")) {
3622 $pr->{'forks'} = "-d $projectroot/$pname";
3627 push @projects, $pr;
3633 # print 'sort by' <th> element, either sorting by $key if $name eq $order
3634 # (changing $list), or generating 'sort by $name' replay link otherwise
3636 my ($str_sort, $name, $order, $key, $header, $list) = @_;
3638 $header ||= ucfirst($name);
3640 if ($order eq $name) {
3642 @
$list = sort {$a->{$key} cmp $b->{$key}} @
$list;
3644 @
$list = sort {$a->{$key} <=> $b->{$key}} @
$list;
3646 print "<th>$header</th>\n";
3649 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3650 -class => "header"}, $header) .
3655 sub print_sort_th_str
{
3656 print_sort_th
(1, @_);
3659 sub print_sort_th_num
{
3660 print_sort_th
(0, @_);
3663 sub git_project_list_body
{
3664 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3666 my ($check_forks) = gitweb_check_feature
('forks');
3667 my @projects = fill_project_list_info
($projlist, $check_forks);
3669 $order ||= $default_projects_order;
3670 $from = 0 unless defined $from;
3671 $to = $#projects if (!defined $to || $#projects < $to);
3673 print "<table class=\"project_list\">\n";
3674 unless ($no_header) {
3677 print "<th></th>\n";
3679 print_sort_th_str
('project', $order, 'path',
3680 'Project', \
@projects);
3681 print_sort_th_str
('descr', $order, 'descr_long',
3682 'Description', \
@projects);
3683 print_sort_th_str
('owner', $order, 'owner',
3684 'Owner', \
@projects);
3685 print_sort_th_num
('age', $order, 'age',
3686 'Last Change', \
@projects);
3687 print "<th></th>\n" . # for links
3691 for (my $i = $from; $i <= $to; $i++) {
3692 my $pr = $projects[$i];
3694 print "<tr class=\"dark\">\n";
3696 print "<tr class=\"light\">\n";
3701 if ($pr->{'forks'}) {
3702 print "<!-- $pr->{'forks'} -->\n";
3703 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3707 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3708 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3709 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3710 -class => "list", -title
=> $pr->{'descr_long'}},
3711 esc_html
($pr->{'descr'})) . "</td>\n" .
3712 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3713 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3714 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3715 "<td class=\"link\">" .
3716 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3717 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3718 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3719 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3720 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3724 if (defined $extra) {
3727 print "<td></td>\n";
3729 print "<td colspan=\"5\">$extra</td>\n" .
3735 sub git_shortlog_body
{
3736 # uses global variable $project
3737 my ($commitlist, $from, $to, $refs, $extra) = @_;
3739 $from = 0 unless defined $from;
3740 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3742 print "<table class=\"shortlog\">\n";
3744 for (my $i = $from; $i <= $to; $i++) {
3745 my %co = %{$commitlist->[$i]};
3746 my $commit = $co{'id'};
3747 my $ref = format_ref_marker
($refs, $commit);
3749 print "<tr class=\"dark\">\n";
3751 print "<tr class=\"light\">\n";
3754 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3755 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3756 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3757 "<td><i>" . $author . "</i></td>\n" .
3759 print format_subject_html
($co{'title'}, $co{'title_short'},
3760 href
(action
=>"commit", hash
=>$commit), $ref);
3762 "<td class=\"link\">" .
3763 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3764 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3765 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3766 my $snapshot_links = format_snapshot_links
($commit);
3767 if (defined $snapshot_links) {
3768 print " | " . $snapshot_links;
3773 if (defined $extra) {
3775 "<td colspan=\"4\">$extra</td>\n" .
3781 sub git_history_body
{
3782 # Warning: assumes constant type (blob or tree) during history
3783 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3785 $from = 0 unless defined $from;
3786 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3788 print "<table class=\"history\">\n";
3790 for (my $i = $from; $i <= $to; $i++) {
3791 my %co = %{$commitlist->[$i]};
3795 my $commit = $co{'id'};
3797 my $ref = format_ref_marker
($refs, $commit);
3800 print "<tr class=\"dark\">\n";
3802 print "<tr class=\"light\">\n";
3805 # shortlog uses chop_str($co{'author_name'}, 10)
3806 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3807 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3808 "<td><i>" . $author . "</i></td>\n" .
3810 # originally git_history used chop_str($co{'title'}, 50)
3811 print format_subject_html
($co{'title'}, $co{'title_short'},
3812 href
(action
=>"commit", hash
=>$commit), $ref);
3814 "<td class=\"link\">" .
3815 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3816 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3818 if ($ftype eq 'blob') {
3819 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3820 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3821 if (defined $blob_current && defined $blob_parent &&
3822 $blob_current ne $blob_parent) {
3824 $cgi->a({-href
=> href
(action
=>"blobdiff",
3825 hash
=>$blob_current, hash_parent
=>$blob_parent,
3826 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3827 file_name
=>$file_name)},
3834 if (defined $extra) {
3836 "<td colspan=\"4\">$extra</td>\n" .
3843 # uses global variable $project
3844 my ($taglist, $from, $to, $extra) = @_;
3845 $from = 0 unless defined $from;
3846 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3848 print "<table class=\"tags\">\n";
3850 for (my $i = $from; $i <= $to; $i++) {
3851 my $entry = $taglist->[$i];
3853 my $comment = $tag{'subject'};
3855 if (defined $comment) {
3856 $comment_short = chop_str
($comment, 30, 5);
3859 print "<tr class=\"dark\">\n";
3861 print "<tr class=\"light\">\n";
3864 if (defined $tag{'age'}) {
3865 print "<td><i>$tag{'age'}</i></td>\n";
3867 print "<td></td>\n";
3870 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3871 -class => "list name"}, esc_html
($tag{'name'})) .
3874 if (defined $comment) {
3875 print format_subject_html
($comment, $comment_short,
3876 href
(action
=>"tag", hash
=>$tag{'id'}));
3879 "<td class=\"selflink\">";
3880 if ($tag{'type'} eq "tag") {
3881 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3886 "<td class=\"link\">" . " | " .
3887 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3888 if ($tag{'reftype'} eq "commit") {
3889 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3890 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3891 } elsif ($tag{'reftype'} eq "blob") {
3892 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3897 if (defined $extra) {
3899 "<td colspan=\"5\">$extra</td>\n" .
3905 sub git_heads_body
{
3906 # uses global variable $project
3907 my ($headlist, $head, $from, $to, $extra) = @_;
3908 $from = 0 unless defined $from;
3909 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3911 print "<table class=\"heads\">\n";
3913 for (my $i = $from; $i <= $to; $i++) {
3914 my $entry = $headlist->[$i];
3916 my $curr = $ref{'id'} eq $head;
3918 print "<tr class=\"dark\">\n";
3920 print "<tr class=\"light\">\n";
3923 print "<td><i>$ref{'age'}</i></td>\n" .
3924 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3925 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3926 -class => "list name"},esc_html
($ref{'name'})) .
3928 "<td class=\"link\">" .
3929 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3930 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3931 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3935 if (defined $extra) {
3937 "<td colspan=\"3\">$extra</td>\n" .
3943 sub git_search_grep_body
{
3944 my ($commitlist, $from, $to, $extra) = @_;
3945 $from = 0 unless defined $from;
3946 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3948 print "<table class=\"commit_search\">\n";
3950 for (my $i = $from; $i <= $to; $i++) {
3951 my %co = %{$commitlist->[$i]};
3955 my $commit = $co{'id'};
3957 print "<tr class=\"dark\">\n";
3959 print "<tr class=\"light\">\n";
3962 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3963 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3964 "<td><i>" . $author . "</i></td>\n" .
3966 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3967 -class => "list subject"},
3968 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3969 my $comment = $co{'comment'};
3970 foreach my $line (@
$comment) {
3971 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3972 my ($lead, $match, $trail) = ($1, $2, $3);
3973 $match = chop_str
($match, 70, 5, 'center');
3974 my $contextlen = int((80 - length($match))/2);
3975 $contextlen = 30 if ($contextlen > 30);
3976 $lead = chop_str
($lead, $contextlen, 10, 'left');
3977 $trail = chop_str
($trail, $contextlen, 10, 'right');
3979 $lead = esc_html
($lead);
3980 $match = esc_html
($match);
3981 $trail = esc_html
($trail);
3983 print "$lead<span class=\"match\">$match</span>$trail<br />";
3987 "<td class=\"link\">" .
3988 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3990 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3992 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3996 if (defined $extra) {
3998 "<td colspan=\"3\">$extra</td>\n" .
4004 ## ======================================================================
4005 ## ======================================================================
4008 sub git_project_list
{
4009 my $order = $cgi->param('o');
4010 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4011 die_error
(400, "Unknown order parameter");
4014 my @list = git_get_projects_list
();
4016 die_error
(404, "No projects found");
4020 if (-f
$home_text) {
4021 print "<div class=\"index_include\">\n";
4022 open (my $fd, $home_text);
4027 git_project_list_body
(\
@list, $order);
4032 my $order = $cgi->param('o');
4033 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4034 die_error
(400, "Unknown order parameter");
4037 my @list = git_get_projects_list
($project);
4039 die_error
(404, "No forks found");
4043 git_print_page_nav
('','');
4044 git_print_header_div
('summary', "$project forks");
4045 git_project_list_body
(\
@list, $order);
4049 sub git_project_index
{
4050 my @projects = git_get_projects_list
($project);
4053 -type
=> 'text/plain',
4054 -charset
=> 'utf-8',
4055 -content_disposition
=> 'inline; filename="index.aux"');
4057 foreach my $pr (@projects) {
4058 if (!exists $pr->{'owner'}) {
4059 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4062 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4063 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4064 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4065 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4069 print "$path $owner\n";
4074 my $descr = git_get_project_description
($project) || "none";
4075 my %co = parse_commit
("HEAD");
4076 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4077 my $head = $co{'id'};
4079 my $owner = git_get_project_owner
($project);
4081 my $refs = git_get_references
();
4082 # These get_*_list functions return one more to allow us to see if
4083 # there are more ...
4084 my @taglist = git_get_tags_list
(16);
4085 my @headlist = git_get_heads_list
(16);
4087 my ($check_forks) = gitweb_check_feature
('forks');
4090 @forklist = git_get_projects_list
($project);
4094 git_print_page_nav
('summary','', $head);
4096 print "<div class=\"title\"> </div>\n";
4097 print "<table class=\"projects_list\">\n" .
4098 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4099 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4100 if (defined $cd{'rfc2822'}) {
4101 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4104 # use per project git URL list in $projectroot/$project/cloneurl
4105 # or make project git URL from git base URL and project name
4106 my $url_tag = "URL";
4107 my @url_list = git_get_project_url_list
($project);
4108 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4109 foreach my $git_url (@url_list) {
4110 next unless $git_url;
4111 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4116 if (-s
"$projectroot/$project/README.html") {
4117 if (open my $fd, "$projectroot/$project/README.html") {
4118 print "<div class=\"title\">readme</div>\n" .
4119 "<div class=\"readme\">\n";
4120 print $_ while (<$fd>);
4121 print "\n</div>\n"; # class="readme"
4126 # we need to request one more than 16 (0..15) to check if
4128 my @commitlist = $head ? parse_commits
($head, 17) : ();
4130 git_print_header_div
('shortlog');
4131 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4132 $#commitlist <= 15 ?
undef :
4133 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4137 git_print_header_div
('tags');
4138 git_tags_body
(\
@taglist, 0, 15,
4139 $#taglist <= 15 ?
undef :
4140 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4144 git_print_header_div
('heads');
4145 git_heads_body
(\
@headlist, $head, 0, 15,
4146 $#headlist <= 15 ?
undef :
4147 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4151 git_print_header_div
('forks');
4152 git_project_list_body
(\
@forklist, undef, 0, 15,
4153 $#forklist <= 15 ?
undef :
4154 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4162 my $head = git_get_head_hash
($project);
4164 git_print_page_nav
('','', $head,undef,$head);
4165 my %tag = parse_tag
($hash);
4168 die_error
(404, "Unknown tag object");
4171 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4172 print "<div class=\"title_text\">\n" .
4173 "<table class=\"object_header\">\n" .
4175 "<td>object</td>\n" .
4176 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4177 $tag{'object'}) . "</td>\n" .
4178 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4179 $tag{'type'}) . "</td>\n" .
4181 if (defined($tag{'author'})) {
4182 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4183 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4184 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4185 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4188 print "</table>\n\n" .
4190 print "<div class=\"page_body\">";
4191 my $comment = $tag{'comment'};
4192 foreach my $line (@
$comment) {
4194 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4204 gitweb_check_feature
('blame')
4205 or die_error
(403, "Blame view not allowed");
4207 die_error
(400, "No file name given") unless $file_name;
4208 $hash_base ||= git_get_head_hash
($project);
4209 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4210 my %co = parse_commit
($hash_base)
4211 or die_error
(404, "Commit not found");
4212 if (!defined $hash) {
4213 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4214 or die_error
(404, "Error looking up file");
4216 $ftype = git_get_type
($hash);
4217 if ($ftype !~ "blob") {
4218 die_error
(400, "Object is not a blob");
4220 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4221 $file_name, $hash_base)
4222 or die_error
(500, "Open git-blame failed");
4225 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4228 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4231 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4233 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4234 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4235 git_print_page_path
($file_name, $ftype, $hash_base);
4236 my @rev_color = (qw(light2 dark2));
4237 my $num_colors = scalar(@rev_color);
4238 my $current_color = 0;
4241 <div class="page_body">
4242 <table class="blame">
4243 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4248 last unless defined $_;
4249 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4250 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4251 if (!exists $metainfo{$full_rev}) {
4252 $metainfo{$full_rev} = {};
4254 my $meta = $metainfo{$full_rev};
4257 if (/^(\S+) (.*)$/) {
4263 my $rev = substr($full_rev, 0, 8);
4264 my $author = $meta->{'author'};
4265 my %date = parse_date
($meta->{'author-time'},
4266 $meta->{'author-tz'});
4267 my $date = $date{'iso-tz'};
4269 $current_color = ++$current_color % $num_colors;
4271 print "<tr class=\"$rev_color[$current_color]\">\n";
4273 print "<td class=\"sha1\"";
4274 print " title=\"". esc_html
($author) . ", $date\"";
4275 print " rowspan=\"$group_size\"" if ($group_size > 1);
4277 print $cgi->a({-href
=> href
(action
=>"commit",
4279 file_name
=>$file_name)},
4283 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4284 or die_error
(500, "Open git-rev-parse failed");
4285 my $parent_commit = <$dd>;
4287 chomp($parent_commit);
4288 my $blamed = href
(action
=> 'blame',
4289 file_name
=> $meta->{'filename'},
4290 hash_base
=> $parent_commit);
4291 print "<td class=\"linenr\">";
4292 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4294 -class => "linenr" },
4297 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4303 or print "Reading blob failed\n";
4308 my $head = git_get_head_hash
($project);
4310 git_print_page_nav
('','', $head,undef,$head);
4311 git_print_header_div
('summary', $project);
4313 my @tagslist = git_get_tags_list
();
4315 git_tags_body
(\
@tagslist);
4321 my $head = git_get_head_hash
($project);
4323 git_print_page_nav
('','', $head,undef,$head);
4324 git_print_header_div
('summary', $project);
4326 my @headslist = git_get_heads_list
();
4328 git_heads_body
(\
@headslist, $head);
4333 sub git_blob_plain
{
4337 if (!defined $hash) {
4338 if (defined $file_name) {
4339 my $base = $hash_base || git_get_head_hash
($project);
4340 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4341 or die_error
(404, "Cannot find file");
4343 die_error
(400, "No file name defined");
4345 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4346 # blobs defined by non-textual hash id's can be cached
4350 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4351 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4353 # content-type (can include charset)
4354 $type = blob_contenttype
($fd, $file_name, $type);
4356 # "save as" filename, even when no $file_name is given
4357 my $save_as = "$hash";
4358 if (defined $file_name) {
4359 $save_as = $file_name;
4360 } elsif ($type =~ m/^text\//) {
4366 -expires
=> $expires,
4367 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4369 binmode STDOUT
, ':raw';
4371 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4379 if (!defined $hash) {
4380 if (defined $file_name) {
4381 my $base = $hash_base || git_get_head_hash
($project);
4382 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4383 or die_error
(404, "Cannot find file");
4385 die_error
(400, "No file name defined");
4387 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4388 # blobs defined by non-textual hash id's can be cached
4392 my ($have_blame) = gitweb_check_feature
('blame');
4393 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4394 or die_error
(500, "Couldn't cat $file_name, $hash");
4395 my $mimetype = blob_mimetype
($fd, $file_name);
4396 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4398 return git_blob_plain
($mimetype);
4400 # we can have blame only for text/* mimetype
4401 $have_blame &&= ($mimetype =~ m!^text/!);
4403 git_header_html
(undef, $expires);
4404 my $formats_nav = '';
4405 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4406 if (defined $file_name) {
4409 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4414 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4417 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4420 $cgi->a({-href
=> href
(action
=>"blob",
4421 hash_base
=>"HEAD", file_name
=>$file_name)},
4425 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4428 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4429 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4431 print "<div class=\"page_nav\">\n" .
4432 "<br/><br/></div>\n" .
4433 "<div class=\"title\">$hash</div>\n";
4435 git_print_page_path
($file_name, "blob", $hash_base);
4436 print "<div class=\"page_body\">\n";
4437 if ($mimetype =~ m!^image/!) {
4438 print qq!<img type
="$mimetype"!;
4440 print qq! alt
="$file_name" title
="$file_name"!;
4443 href(action=>"blob_plain
", hash=>$hash,
4444 hash_base=>$hash_base, file_name=>$file_name) .
4448 while (my $line = <$fd>) {
4451 $line = untabify
($line);
4452 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4453 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4457 or print "Reading blob failed.\n";
4463 if (!defined $hash_base) {
4464 $hash_base = "HEAD";
4466 if (!defined $hash) {
4467 if (defined $file_name) {
4468 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4473 die_error
(404, "No such tree") unless defined($hash);
4475 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4476 or die_error
(500, "Open git-ls-tree failed");
4477 my @entries = map { chomp; $_ } <$fd>;
4478 close $fd or die_error
(404, "Reading tree failed");
4481 my $refs = git_get_references
();
4482 my $ref = format_ref_marker
($refs, $hash_base);
4485 my ($have_blame) = gitweb_check_feature
('blame');
4486 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4488 if (defined $file_name) {
4490 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4492 $cgi->a({-href
=> href
(action
=>"tree",
4493 hash_base
=>"HEAD", file_name
=>$file_name)},
4496 my $snapshot_links = format_snapshot_links
($hash);
4497 if (defined $snapshot_links) {
4498 # FIXME: Should be available when we have no hash base as well.
4499 push @views_nav, $snapshot_links;
4501 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4502 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4505 print "<div class=\"page_nav\">\n";
4506 print "<br/><br/></div>\n";
4507 print "<div class=\"title\">$hash</div>\n";
4509 if (defined $file_name) {
4510 $basedir = $file_name;
4511 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4514 git_print_page_path
($file_name, 'tree', $hash_base);
4516 print "<div class=\"page_body\">\n";
4517 print "<table class=\"tree\">\n";
4519 # '..' (top directory) link if possible
4520 if (defined $hash_base &&
4521 defined $file_name && $file_name =~ m![^/]+$!) {
4523 print "<tr class=\"dark\">\n";
4525 print "<tr class=\"light\">\n";
4529 my $up = $file_name;
4530 $up =~ s!/?[^/]+$!!;
4531 undef $up unless $up;
4532 # based on git_print_tree_entry
4533 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4534 print '<td class="list">';
4535 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4539 print "<td class=\"link\"></td>\n";
4543 foreach my $line (@entries) {
4544 my %t = parse_ls_tree_line
($line, -z
=> 1);
4547 print "<tr class=\"dark\">\n";
4549 print "<tr class=\"light\">\n";
4553 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4557 print "</table>\n" .
4563 my @supported_fmts = gitweb_check_feature
('snapshot');
4564 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4566 my $format = $cgi->param('sf');
4567 if (!@supported_fmts) {
4568 die_error
(403, "Snapshots not allowed");
4570 # default to first supported snapshot format
4571 $format ||= $supported_fmts[0];
4572 if ($format !~ m/^[a-z0-9]+$/) {
4573 die_error
(400, "Invalid snapshot format parameter");
4574 } elsif (!exists($known_snapshot_formats{$format})) {
4575 die_error
(400, "Unknown snapshot format");
4576 } elsif (!grep($_ eq $format, @supported_fmts)) {
4577 die_error
(403, "Unsupported snapshot format");
4580 if (!defined $hash) {
4581 $hash = git_get_head_hash
($project);
4584 my $name = $project;
4585 $name =~ s
,([^/])/*\
.git
$,$1,;
4586 $name = basename
($name);
4587 my $filename = to_utf8
($name);
4588 $name =~ s/\047/\047\\\047\047/g;
4590 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4591 $cmd = quote_command
(
4592 git_cmd
(), 'archive',
4593 "--format=$known_snapshot_formats{$format}{'format'}",
4594 "--prefix=$name/", $hash);
4595 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4596 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4600 -type
=> $known_snapshot_formats{$format}{'type'},
4601 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4602 -status
=> '200 OK');
4604 open my $fd, "-|", $cmd
4605 or die_error
(500, "Execute git-archive failed");
4606 binmode STDOUT
, ':raw';
4608 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4613 my $head = git_get_head_hash
($project);
4614 if (!defined $hash) {
4617 if (!defined $page) {
4620 my $refs = git_get_references
();
4622 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4624 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4627 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4630 my %co = parse_commit
($hash);
4632 git_print_header_div
('summary', $project);
4633 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4635 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4636 for (my $i = 0; $i <= $to; $i++) {
4637 my %co = %{$commitlist[$i]};
4639 my $commit = $co{'id'};
4640 my $ref = format_ref_marker
($refs, $commit);
4641 my %ad = parse_date
($co{'author_epoch'});
4642 git_print_header_div
('commit',
4643 "<span class=\"age\">$co{'age_string'}</span>" .
4644 esc_html
($co{'title'}) . $ref,
4646 print "<div class=\"title_text\">\n" .
4647 "<div class=\"log_link\">\n" .
4648 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4650 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4652 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4655 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4658 print "<div class=\"log_body\">\n";
4659 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4662 if ($#commitlist >= 100) {
4663 print "<div class=\"page_nav\">\n";
4664 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4665 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4672 $hash ||= $hash_base || "HEAD";
4673 my %co = parse_commit
($hash)
4674 or die_error
(404, "Unknown commit object");
4675 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4676 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4678 my $parent = $co{'parent'};
4679 my $parents = $co{'parents'}; # listref
4681 # we need to prepare $formats_nav before any parameter munging
4683 if (!defined $parent) {
4685 $formats_nav .= '(initial)';
4686 } elsif (@
$parents == 1) {
4687 # single parent commit
4690 $cgi->a({-href
=> href
(action
=>"commit",
4692 esc_html
(substr($parent, 0, 7))) .
4699 $cgi->a({-href
=> href
(action
=>"commit",
4701 esc_html
(substr($_, 0, 7)));
4706 if (!defined $parent) {
4710 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4712 (@
$parents <= 1 ?
$parent : '-c'),
4714 or die_error
(500, "Open git-diff-tree failed");
4715 @difftree = map { chomp; $_ } <$fd>;
4716 close $fd or die_error
(404, "Reading git-diff-tree failed");
4718 # non-textual hash id's can be cached
4720 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4723 my $refs = git_get_references
();
4724 my $ref = format_ref_marker
($refs, $co{'id'});
4726 git_header_html
(undef, $expires);
4727 git_print_page_nav
('commit', '',
4728 $hash, $co{'tree'}, $hash,
4731 if (defined $co{'parent'}) {
4732 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4734 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4736 print "<div class=\"title_text\">\n" .
4737 "<table class=\"object_header\">\n";
4738 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4740 "<td></td><td> $ad{'rfc2822'}";
4741 if ($ad{'hour_local'} < 6) {
4742 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4743 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4745 printf(" (%02d:%02d %s)",
4746 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4750 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4751 print "<tr><td></td><td> $cd{'rfc2822'}" .
4752 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4754 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4757 "<td class=\"sha1\">" .
4758 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4759 class => "list"}, $co{'tree'}) .
4761 "<td class=\"link\">" .
4762 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4764 my $snapshot_links = format_snapshot_links
($hash);
4765 if (defined $snapshot_links) {
4766 print " | " . $snapshot_links;
4771 foreach my $par (@
$parents) {
4774 "<td class=\"sha1\">" .
4775 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4776 class => "list"}, $par) .
4778 "<td class=\"link\">" .
4779 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4781 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4788 print "<div class=\"page_body\">\n";
4789 git_print_log
($co{'comment'});
4792 git_difftree_body
(\
@difftree, undef, undef, $hash, @
$parents);
4798 # object is defined by:
4799 # - hash or hash_base alone
4800 # - hash_base and file_name
4803 # - hash or hash_base alone
4804 if ($hash || ($hash_base && !defined $file_name)) {
4805 my $object_id = $hash || $hash_base;
4807 open my $fd, "-|", quote_command
(
4808 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4809 or die_error
(404, "Object does not exist");
4813 or die_error
(404, "Object does not exist");
4815 # - hash_base and file_name
4816 } elsif ($hash_base && defined $file_name) {
4817 $file_name =~ s
,/+$,,;
4819 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4820 or die_error
(404, "Base object does not exist");
4822 # here errors should not hapen
4823 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4824 or die_error
(500, "Open git-ls-tree failed");
4828 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4829 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4830 die_error
(404, "File or directory for given base does not exist");
4835 die_error
(400, "Not enough information to find object");
4838 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4839 hash
=>$hash, hash_base
=>$hash_base,
4840 file_name
=>$file_name),
4841 -status
=> '302 Found');
4845 my $format = shift || 'html';
4850 my $expires = '+1d';
4853 $file_parent ||= $file_name;
4855 # non-textual hash id's can be cached
4856 if (defined $hash && $hash !~ m/^[0-9a-fA-F]{40}$/) {
4858 } elsif (defined $hash_parent && $hash_parent !~ m/^[0-9a-fA-F]{40}$/) {
4860 } elsif (defined $hash_base && $hash_base !~ m/^[0-9a-fA-F]{40}$/) {
4862 } elsif (defined $hash_parent_base && $hash_parent_base !~ m/^[0-9a-fA-F]{40}$/) {
4866 # if hash parameter is missing, read it from the commit.
4867 if (defined $hash_base && defined $file_name && !defined $hash) {
4868 $hash = git_get_hash_by_path
($hash_base, $file_name);
4871 if (defined $hash_parent_base && defined $file_parent && !defined $hash_parent) {
4872 $hash_parent = git_get_hash_by_path
($hash_parent_base, $file_parent);
4875 if (!defined $hash || ! defined $hash_parent) {
4876 die_error
(404, "Missing one of the blob diff parameters");
4879 if (defined $hash_base && defined $file_name) {
4880 $to = $hash_base . ':' . $file_name;
4885 if (defined $hash_parent_base && defined $file_parent) {
4886 $from = $hash_parent_base . ':' . $file_parent;
4888 $from = $hash_parent;
4891 # fake git-diff-tree raw output
4892 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4893 $diffinfo{'from_id'} = $hash_parent;
4894 $diffinfo{'to_id'} = $hash;
4895 if (defined $file_name) {
4896 $diffinfo{'status'} = '2';
4897 $diffinfo{'from_file'} = $file_parent;
4898 $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;
4906 open $fd, "-|", git_cmd
(), "diff", @diff_opts, '-p', "--full-index",
4907 ($format eq 'html' ?
"--raw" : ()), $from, $to, "--"
4908 or die_error
(500, "Open git-diff failed");
4911 if ($format eq 'html') {
4913 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4915 git_header_html
(undef, $expires);
4916 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4917 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4918 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4920 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4921 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4923 if (defined $file_name) {
4924 git_print_page_path
($file_name, "blob", $hash_base);
4926 print "<div class=\"page_path\"></div>\n";
4929 } elsif ($format eq 'plain') {
4930 my $patch_file_name = $file_name || $hash;
4932 -type
=> 'text/plain',
4933 -charset
=> 'utf-8',
4934 -expires
=> $expires,
4935 -content_disposition
=> 'inline; filename="' . "$patch_file_name" . '.patch"');
4937 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4940 die_error
(400, "Unknown blobdiff format");
4944 if ($format eq 'html') {
4945 print "<div class=\"page_body\">\n";
4947 git_patchset_body
($fd, [ \
%diffinfo ], undef, undef, $hash_base, $hash_parent_base);
4950 print "</div>\n"; # class="page_body"
4954 while (my $line = <$fd>) {
4955 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4956 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4960 last if $line =~ m!^\+\+\+!;
4968 sub git_blobdiff_plain
{
4969 git_blobdiff
('plain');
4972 sub git_commitdiff
{
4973 my $format = shift || 'html';
4974 $hash ||= $hash_base || "HEAD";
4975 my %co = parse_commit
($hash)
4976 or die_error
(404, "Unknown commit object");
4978 # choose format for commitdiff for merge
4979 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4980 $hash_parent = '--cc';
4982 # we need to prepare $formats_nav before almost any parameter munging
4984 if ($format eq 'html') {
4986 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4989 if (defined $hash_parent &&
4990 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4991 # commitdiff with two commits given
4992 my $hash_parent_short = $hash_parent;
4993 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4994 $hash_parent_short = substr($hash_parent, 0, 7);
4998 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4999 if ($co{'parents'}[$i] eq $hash_parent) {
5000 $formats_nav .= ' parent ' . ($i+1);
5004 $formats_nav .= ': ' .
5005 $cgi->a({-href
=> href
(action
=>"commitdiff",
5006 hash
=>$hash_parent)},
5007 esc_html
($hash_parent_short)) .
5009 } elsif (!$co{'parent'}) {
5011 $formats_nav .= ' (initial)';
5012 } elsif (scalar @
{$co{'parents'}} == 1) {
5013 # single parent commit
5016 $cgi->a({-href
=> href
(action
=>"commitdiff",
5017 hash
=>$co{'parent'})},
5018 esc_html
(substr($co{'parent'}, 0, 7))) .
5022 if ($hash_parent eq '--cc') {
5023 $formats_nav .= ' | ' .
5024 $cgi->a({-href
=> href
(action
=>"commitdiff",
5025 hash
=>$hash, hash_parent
=>'-c')},
5027 } else { # $hash_parent eq '-c'
5028 $formats_nav .= ' | ' .
5029 $cgi->a({-href
=> href
(action
=>"commitdiff",
5030 hash
=>$hash, hash_parent
=>'--cc')},
5036 $cgi->a({-href
=> href
(action
=>"commitdiff",
5038 esc_html
(substr($_, 0, 7)));
5039 } @
{$co{'parents'}} ) .
5044 my $hash_parent_param = $hash_parent;
5045 if (!defined $hash_parent_param) {
5046 # --cc for multiple parents, --root for parentless
5047 $hash_parent_param =
5048 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5054 if ($format eq 'html') {
5055 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5056 "--no-commit-id", "--patch-with-raw", "--full-index",
5057 $hash_parent_param, $hash, "--"
5058 or die_error
(500, "Open git-diff-tree failed");
5060 while (my $line = <$fd>) {
5062 # empty line ends raw part of diff-tree output
5064 push @difftree, scalar parse_difftree_raw_line
($line);
5067 } elsif ($format eq 'plain') {
5068 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5069 '-p', $hash_parent_param, $hash, "--"
5070 or die_error
(500, "Open git-diff-tree failed");
5073 die_error
(400, "Unknown commitdiff format");
5076 # non-textual hash id's can be cached
5078 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5082 # write commit message
5083 if ($format eq 'html') {
5084 my $refs = git_get_references
();
5085 my $ref = format_ref_marker
($refs, $co{'id'});
5087 git_header_html
(undef, $expires);
5088 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5089 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5090 git_print_authorship
(\
%co);
5091 print "<div class=\"page_body\">\n";
5092 if (@
{$co{'comment'}} > 1) {
5093 print "<div class=\"log\">\n";
5094 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5095 print "</div>\n"; # class="log"
5098 } elsif ($format eq 'plain') {
5099 my $refs = git_get_references
("tags");
5100 my $tagname = git_get_rev_name_tags
($hash);
5101 my $filename = basename
($project) . "-$hash.patch";
5104 -type
=> 'text/plain',
5105 -charset
=> 'utf-8',
5106 -expires
=> $expires,
5107 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5108 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5109 print "From: " . to_utf8
($co{'author'}) . "\n";
5110 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5111 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5113 print "X-Git-Tag: $tagname\n" if $tagname;
5114 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5116 foreach my $line (@
{$co{'comment'}}) {
5117 print to_utf8
($line) . "\n";
5123 if ($format eq 'html') {
5124 my $use_parents = !defined $hash_parent ||
5125 $hash_parent eq '-c' || $hash_parent eq '--cc';
5126 git_difftree_body
(\
@difftree, undef, undef, $hash,
5127 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5130 git_patchset_body
($fd, \
@difftree, undef, undef, $hash,
5131 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5133 print "</div>\n"; # class="page_body"
5136 } elsif ($format eq 'plain') {
5140 or print "Reading git-diff-tree failed\n";
5144 sub git_commitdiff_plain
{
5145 git_commitdiff
('plain');
5149 if (!defined $hash_base) {
5150 $hash_base = git_get_head_hash
($project);
5152 if (!defined $page) {
5156 my %co = parse_commit
($hash_base)
5157 or die_error
(404, "Unknown commit object");
5159 my $refs = git_get_references
();
5160 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5162 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5163 $file_name, "--full-history")
5164 or die_error
(404, "No such file or directory on given branch");
5166 if (!defined $hash && defined $file_name) {
5167 # some commits could have deleted file in question,
5168 # and not have it in tree, but one of them has to have it
5169 for (my $i = 0; $i <= @commitlist; $i++) {
5170 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5171 last if defined $hash;
5174 if (defined $hash) {
5175 $ftype = git_get_type
($hash);
5177 if (!defined $ftype) {
5178 die_error
(500, "Unknown type of object");
5181 my $paging_nav = '';
5184 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5185 file_name
=>$file_name)},
5187 $paging_nav .= " ⋅ " .
5188 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5189 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5191 $paging_nav .= "first";
5192 $paging_nav .= " ⋅ prev";
5195 if ($#commitlist >= 100) {
5197 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5198 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5199 $paging_nav .= " ⋅ $next_link";
5201 $paging_nav .= " ⋅ next";
5205 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5206 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5207 git_print_page_path
($file_name, $ftype, $hash_base);
5209 git_history_body
(\
@commitlist, 0, 99,
5210 $refs, $hash_base, $ftype, $next_link);
5216 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5217 if (!defined $searchtext) {
5218 die_error
(400, "Text field is empty");
5220 if (!defined $hash) {
5221 $hash = git_get_head_hash
($project);
5223 my %co = parse_commit
($hash);
5225 die_error
(404, "Unknown commit object");
5227 if (!defined $page) {
5231 $searchtype ||= 'commit';
5232 if ($searchtype eq 'pickaxe') {
5233 # pickaxe may take all resources of your box and run for several minutes
5234 # with every query - so decide by yourself how public you make this feature
5235 gitweb_check_feature
('pickaxe')
5236 or die_error
(403, "Pickaxe is disabled");
5238 if ($searchtype eq 'grep') {
5239 gitweb_check_feature
('grep')
5240 or die_error
(403, "Grep is disabled");
5245 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5247 if ($searchtype eq 'commit') {
5248 $greptype = "--grep=";
5249 } elsif ($searchtype eq 'author') {
5250 $greptype = "--author=";
5251 } elsif ($searchtype eq 'committer') {
5252 $greptype = "--committer=";
5254 $greptype .= $searchtext;
5255 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5256 $greptype, '--regexp-ignore-case',
5257 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5259 my $paging_nav = '';
5262 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5263 searchtext
=>$searchtext,
5264 searchtype
=>$searchtype)},
5266 $paging_nav .= " ⋅ " .
5267 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5268 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5270 $paging_nav .= "first";
5271 $paging_nav .= " ⋅ prev";
5274 if ($#commitlist >= 100) {
5276 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5277 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5278 $paging_nav .= " ⋅ $next_link";
5280 $paging_nav .= " ⋅ next";
5283 if ($#commitlist >= 100) {
5286 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5287 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5288 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5291 if ($searchtype eq 'pickaxe') {
5292 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5293 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5295 print "<table class=\"pickaxe search\">\n";
5298 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5299 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5300 ($search_use_regexp ?
'--pickaxe-regex' : ());
5303 while (my $line = <$fd>) {
5307 my %set = parse_difftree_raw_line
($line);
5308 if (defined $set{'commit'}) {
5309 # finish previous commit
5312 "<td class=\"link\">" .
5313 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5315 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5321 print "<tr class=\"dark\">\n";
5323 print "<tr class=\"light\">\n";
5326 %co = parse_commit
($set{'commit'});
5327 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5328 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5329 "<td><i>$author</i></td>\n" .
5331 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5332 -class => "list subject"},
5333 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5334 } elsif (defined $set{'to_id'}) {
5335 next if ($set{'to_id'} =~ m/^0{40}$/);
5337 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5338 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5340 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5346 # finish last commit (warning: repetition!)
5349 "<td class=\"link\">" .
5350 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5352 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5360 if ($searchtype eq 'grep') {
5361 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5362 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5364 print "<table class=\"grep_search\">\n";
5368 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5369 $search_use_regexp ?
('-E', '-i') : '-F',
5370 $searchtext, $co{'tree'};
5372 while (my $line = <$fd>) {
5374 my ($file, $lno, $ltext, $binary);
5375 last if ($matches++ > 1000);
5376 if ($line =~ /^Binary file (.+) matches$/) {
5380 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5382 if ($file ne $lastfile) {
5383 $lastfile and print "</td></tr>\n";
5385 print "<tr class=\"dark\">\n";
5387 print "<tr class=\"light\">\n";
5389 print "<td class=\"list\">".
5390 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5391 file_name
=>"$file"),
5392 -class => "list"}, esc_path
($file));
5393 print "</td><td>\n";
5397 print "<div class=\"binary\">Binary file</div>\n";
5399 $ltext = untabify
($ltext);
5400 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5401 $ltext = esc_html
($1, -nbsp
=>1);
5402 $ltext .= '<span class="match">';
5403 $ltext .= esc_html
($2, -nbsp
=>1);
5404 $ltext .= '</span>';
5405 $ltext .= esc_html
($3, -nbsp
=>1);
5407 $ltext = esc_html
($ltext, -nbsp
=>1);
5409 print "<div class=\"pre\">" .
5410 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5411 file_name
=>"$file").'#l'.$lno,
5412 -class => "linenr"}, sprintf('%4i', $lno))
5413 . ' ' . $ltext . "</div>\n";
5417 print "</td></tr>\n";
5418 if ($matches > 1000) {
5419 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5422 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5431 sub git_search_help
{
5433 git_print_page_nav
('','', $hash,$hash,$hash);
5435 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5436 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5437 the pattern entered is recognized as the POSIX extended
5438 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5441 <dt><b>commit</b></dt>
5442 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5444 my ($have_grep) = gitweb_check_feature
('grep');
5447 <dt><b>grep</b></dt>
5448 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5449 a different one) are searched for the given pattern. On large trees, this search can take
5450 a while and put some strain on the server, so please use it with some consideration. Note that
5451 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5452 case-sensitive.</dd>
5456 <dt><b>author</b></dt>
5457 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5458 <dt><b>committer</b></dt>
5459 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5461 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5462 if ($have_pickaxe) {
5464 <dt><b>pickaxe</b></dt>
5465 <dd>All commits that caused the string to appear or disappear from any file (changes that
5466 added, removed or "modified" the string) will be listed. This search can take a while and
5467 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5468 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5476 my $head = git_get_head_hash
($project);
5477 if (!defined $hash) {
5480 if (!defined $page) {
5483 my $refs = git_get_references
();
5485 my $commit_hash = $hash;
5486 if (defined $hash_parent) {
5487 $commit_hash = "$hash_parent..$hash";
5489 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5491 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5493 if ($#commitlist >= 100) {
5495 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5496 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5500 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5501 git_print_header_div
('summary', $project);
5503 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5508 ## ......................................................................
5509 ## feeds (RSS, Atom; OPML)
5512 my $format = shift || 'atom';
5513 my ($have_blame) = gitweb_check_feature
('blame');
5515 # Atom: http://www.atomenabled.org/developers/syndication/
5516 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5517 if ($format ne 'rss' && $format ne 'atom') {
5518 die_error
(400, "Unknown web feed format");
5521 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5522 my $head = $hash || 'HEAD';
5523 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5527 my $content_type = "application/$format+xml";
5528 if (defined $cgi->http('HTTP_ACCEPT') &&
5529 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5530 # browser (feed reader) prefers text/xml
5531 $content_type = 'text/xml';
5533 if (defined($commitlist[0])) {
5534 %latest_commit = %{$commitlist[0]};
5535 %latest_date = parse_date
($latest_commit{'author_epoch'});
5537 -type
=> $content_type,
5538 -charset
=> 'utf-8',
5539 -last_modified
=> $latest_date{'rfc2822'});
5542 -type
=> $content_type,
5543 -charset
=> 'utf-8');
5546 # Optimization: skip generating the body if client asks only
5547 # for Last-Modified date.
5548 return if ($cgi->request_method() eq 'HEAD');
5551 my $title = "$site_name - $project/$action";
5552 my $feed_type = 'log';
5553 if (defined $hash) {
5554 $title .= " - '$hash'";
5555 $feed_type = 'branch log';
5556 if (defined $file_name) {
5557 $title .= " :: $file_name";
5558 $feed_type = 'history';
5560 } elsif (defined $file_name) {
5561 $title .= " - $file_name";
5562 $feed_type = 'history';
5564 $title .= " $feed_type";
5565 my $descr = git_get_project_description
($project);
5566 if (defined $descr) {
5567 $descr = esc_html
($descr);
5569 $descr = "$project " .
5570 ($format eq 'rss' ?
'RSS' : 'Atom') .
5573 my $owner = git_get_project_owner
($project);
5574 $owner = esc_html
($owner);
5578 if (defined $file_name) {
5579 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5580 } elsif (defined $hash) {
5581 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5583 $alt_url = href
(-full
=>1, action
=>"summary");
5585 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5586 if ($format eq 'rss') {
5588 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5591 print "<title>$title</title>\n" .
5592 "<link>$alt_url</link>\n" .
5593 "<description>$descr</description>\n" .
5594 "<language>en</language>\n";
5595 } elsif ($format eq 'atom') {
5597 <feed xmlns="http://www.w3.org/2005/Atom">
5599 print "<title>$title</title>\n" .
5600 "<subtitle>$descr</subtitle>\n" .
5601 '<link rel="alternate" type="text/html" href="' .
5602 $alt_url . '" />' . "\n" .
5603 '<link rel="self" type="' . $content_type . '" href="' .
5604 $cgi->self_url() . '" />' . "\n" .
5605 "<id>" . href
(-full
=>1) . "</id>\n" .
5606 # use project owner for feed author
5607 "<author><name>$owner</name></author>\n";
5608 if (defined $favicon) {
5609 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5611 if (defined $logo_url) {
5612 # not twice as wide as tall: 72 x 27 pixels
5613 print "<logo>" . esc_url
($logo) . "</logo>\n";
5615 if (! %latest_date) {
5616 # dummy date to keep the feed valid until commits trickle in:
5617 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5619 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5624 for (my $i = 0; $i <= $#commitlist; $i++) {
5625 my %co = %{$commitlist[$i]};
5626 my $commit = $co{'id'};
5627 # we read 150, we always show 30 and the ones more recent than 48 hours
5628 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5631 my %cd = parse_date
($co{'author_epoch'});
5633 # get list of changed files
5634 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5635 $co{'parent'} || "--root",
5636 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5638 my @difftree = map { chomp; $_ } <$fd>;
5642 # print element (entry, item)
5643 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5644 if ($format eq 'rss') {
5646 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5647 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5648 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5649 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5650 "<link>$co_url</link>\n" .
5651 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5652 "<content:encoded>" .
5654 } elsif ($format eq 'atom') {
5656 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5657 "<updated>$cd{'iso-8601'}</updated>\n" .
5659 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5660 if ($co{'author_email'}) {
5661 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5663 print "</author>\n" .
5664 # use committer for contributor
5666 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5667 if ($co{'committer_email'}) {
5668 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5670 print "</contributor>\n" .
5671 "<published>$cd{'iso-8601'}</published>\n" .
5672 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5673 "<id>$co_url</id>\n" .
5674 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5675 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5677 my $comment = $co{'comment'};
5679 foreach my $line (@
$comment) {
5680 $line = esc_html
($line);
5683 print "</pre><ul>\n";
5684 foreach my $difftree_line (@difftree) {
5685 my %difftree = parse_difftree_raw_line
($difftree_line);
5686 next if !$difftree{'from_id'};
5688 my $file = $difftree{'file'} || $difftree{'to_file'};
5692 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5693 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5694 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5695 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5696 -title
=> "diff"}, 'D');
5698 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5699 file_name
=>$file, hash_base
=>$commit),
5700 -title
=> "blame"}, 'B');
5702 # if this is not a feed of a file history
5703 if (!defined $file_name || $file_name ne $file) {
5704 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5705 file_name
=>$file, hash
=>$commit),
5706 -title
=> "history"}, 'H');
5708 $file = esc_path
($file);
5712 if ($format eq 'rss') {
5713 print "</ul>]]>\n" .
5714 "</content:encoded>\n" .
5716 } elsif ($format eq 'atom') {
5717 print "</ul>\n</div>\n" .
5724 if ($format eq 'rss') {
5725 print "</channel>\n</rss>\n";
5726 } elsif ($format eq 'atom') {
5740 my @list = git_get_projects_list
();
5742 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5744 <?xml version="1.0" encoding="utf-8"?>
5745 <opml version="1.0">
5747 <title>$site_name OPML Export</title>
5750 <outline text="git RSS feeds">
5753 foreach my $pr (@list) {
5755 my $head = git_get_head_hash
($proj{'path'});
5756 if (!defined $head) {
5759 $git_dir = "$projectroot/$proj{'path'}";
5760 my %co = parse_commit
($head);
5765 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5766 my $rss = "$my_url?p=$proj{'path'};a=rss";
5767 my $html = "$my_url?p=$proj{'path'};a=summary";
5768 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";