3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
64 # URI of GIT logo (72x27 size)
65 our $logo = "++GITWEB_LOGO++";
66 # URI of GIT favicon, assumed to be image/png type
67 our $favicon = "++GITWEB_FAVICON++";
69 our $gitwebjs = "++GITWEB_GITWEBJS++";
71 # URI and label (title) of GIT logo link
72 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
73 #our $logo_label = "git documentation";
74 our $logo_url = "http://git.or.cz/";
75 our $logo_label = "git homepage";
77 # source of projects list
78 our $projects_list = "++GITWEB_LIST++";
80 # the width (in characters) of the projects list "Description" column
81 our $projects_list_description_width = 25;
83 # default order of projects list
84 # valid values are none, project, descr, owner, and age
85 our $default_projects_order = "project";
87 # show repository only if this file exists
88 # (only effective if this variable evaluates to true)
89 our $export_ok = "++GITWEB_EXPORT_OK++";
91 # only allow viewing of repositories also shown on the overview page
92 our $strict_export = "++GITWEB_STRICT_EXPORT++";
94 # list of git base URLs used for URL to where fetch project from,
95 # i.e. full URL is "$git_base_url/$project"
96 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
98 # default blob_plain mimetype and default charset for text/plain blob
99 our $default_blob_plain_mimetype = 'text/plain';
100 our $default_text_plain_charset = undef;
102 # file to use for guessing MIME types before trying /etc/mime.types
103 # (relative to the current git repository)
104 our $mimetypes_file = undef;
106 # assume this charset if line contains non-UTF-8 characters;
107 # it should be valid encoding (see Encoding::Supported(3pm) for list),
108 # for which encoding all byte sequences are valid, for example
109 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
110 # could be even 'utf-8' for the old behavior)
111 our $fallback_encoding = 'latin1';
113 # rename detection options for git-diff and git-diff-tree
114 # - default is '-M', with the cost proportional to
115 # (number of removed files) * (number of new files).
116 # - more costly is '-C' (which implies '-M'), with the cost proportional to
117 # (number of changed files + number of removed files) * (number of new files)
118 # - even more costly is '-C', '--find-copies-harder' with cost
119 # (number of files in the original tree) * (number of new files)
120 # - one might want to include '-B' option, e.g. '-B', '-M'
121 our @diff_opts = ('-M'); # taken from git_commit
123 # information about snapshot formats that gitweb is capable of serving
124 our %known_snapshot_formats = (
126 # 'display' => display name,
127 # 'type' => mime type,
128 # 'suffix' => filename suffix,
129 # 'format' => --format for git-archive,
130 # 'compressor' => [compressor command and arguments]
131 # (array reference, optional)}
134 'display' => 'tar.gz',
135 'type' => 'application/x-gzip',
136 'suffix' => '.tar.gz',
138 'compressor' => ['gzip']},
141 'display' => 'tar.bz2',
142 'type' => 'application/x-bzip2',
143 'suffix' => '.tar.bz2',
145 'compressor' => ['bzip2']},
149 'type' => 'application/x-zip',
154 # Aliases so we understand old gitweb.snapshot values in repository
156 our %known_snapshot_format_aliases = (
160 # backward compatibility: legacy gitweb config support
161 'x-gzip' => undef, 'gz' => undef,
162 'x-bzip2' => undef, 'bz2' => undef,
163 'x-zip' => undef, '' => undef,
166 # You define site-wide feature defaults here; override them with
167 # $GITWEB_CONFIG as necessary.
170 # 'sub' => feature-sub (subroutine),
171 # 'override' => allow-override (boolean),
172 # 'default' => [ default options...] (array reference)}
174 # if feature is overridable (it means that allow-override has true value),
175 # then feature-sub will be called with default options as parameters;
176 # return value of feature-sub indicates if to enable specified feature
178 # if there is no 'sub' key (no feature-sub), then feature cannot be
181 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
183 # Enable the 'blame' blob view, showing the last commit that modified
184 # each line in the file. This can be very CPU-intensive.
186 # To enable system wide have in $GITWEB_CONFIG
187 # $feature{'blame'}{'default'} = [1];
188 # To have project specific config enable override in $GITWEB_CONFIG
189 # $feature{'blame'}{'override'} = 1;
190 # and in project config gitweb.blame = 0|1;
192 'sub' => \
&feature_blame
,
196 # Enable the 'snapshot' link, providing a compressed archive of any
197 # tree. This can potentially generate high traffic if you have large
200 # Value is a list of formats defined in %known_snapshot_formats that
202 # To disable system wide have in $GITWEB_CONFIG
203 # $feature{'snapshot'}{'default'} = [];
204 # To have project specific config enable override in $GITWEB_CONFIG
205 # $feature{'snapshot'}{'override'} = 1;
206 # and in project config, a comma-separated list of formats or "none"
207 # to disable. Example: gitweb.snapshot = tbz2,zip;
209 'sub' => \
&feature_snapshot
,
211 'default' => ['tgz']},
213 # Enable text search, which will list the commits which match author,
214 # committer or commit text to a given string. Enabled by default.
215 # Project specific override is not supported.
220 # Enable grep search, which will list the files in currently selected
221 # tree containing the given string. Enabled by default. This can be
222 # potentially CPU-intensive, of course.
224 # To enable system wide have in $GITWEB_CONFIG
225 # $feature{'grep'}{'default'} = [1];
226 # To have project specific config enable override in $GITWEB_CONFIG
227 # $feature{'grep'}{'override'} = 1;
228 # and in project config gitweb.grep = 0|1;
233 # Enable the pickaxe search, which will list the commits that modified
234 # a given string in a file. This can be practical and quite faster
235 # alternative to 'blame', but still potentially CPU-intensive.
237 # To enable system wide have in $GITWEB_CONFIG
238 # $feature{'pickaxe'}{'default'} = [1];
239 # To have project specific config enable override in $GITWEB_CONFIG
240 # $feature{'pickaxe'}{'override'} = 1;
241 # and in project config gitweb.pickaxe = 0|1;
243 'sub' => \
&feature_pickaxe
,
247 # Make gitweb use an alternative format of the URLs which can be
248 # more readable and natural-looking: project name is embedded
249 # directly in the path and the query string contains other
250 # auxiliary information. All gitweb installations recognize
251 # URL in either format; this configures in which formats gitweb
254 # To enable system wide have in $GITWEB_CONFIG
255 # $feature{'pathinfo'}{'default'} = [1];
256 # Project specific override is not supported.
258 # Note that you will need to change the default location of CSS,
259 # favicon, logo and possibly other files to an absolute URL. Also,
260 # if gitweb.cgi serves as your indexfile, you will need to force
261 # $my_uri to contain the script name in your $GITWEB_CONFIG.
266 # Make gitweb consider projects in project root subdirectories
267 # to be forks of existing projects. Given project $projname.git,
268 # projects matching $projname/*.git will not be shown in the main
269 # projects list, instead a '+' mark will be added to $projname
270 # there and a 'forks' view will be enabled for the project, listing
271 # all the forks. If project list is taken from a file, forks have
272 # to be listed after the main project.
274 # To enable system wide have in $GITWEB_CONFIG
275 # $feature{'forks'}{'default'} = [1];
276 # Project specific override is not supported.
282 sub gitweb_check_feature
{
284 return unless exists $feature{$name};
285 my ($sub, $override, @defaults) = (
286 $feature{$name}{'sub'},
287 $feature{$name}{'override'},
288 @
{$feature{$name}{'default'}});
289 if (!$override) { return @defaults; }
291 warn "feature $name is not overrideable";
294 return $sub->(@defaults);
298 my ($val) = git_get_project_config
('blame', '--bool');
300 if ($val eq 'true') {
302 } elsif ($val eq 'false') {
309 sub feature_snapshot
{
312 my ($val) = git_get_project_config
('snapshot');
315 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
322 my ($val) = git_get_project_config
('grep', '--bool');
324 if ($val eq 'true') {
326 } elsif ($val eq 'false') {
333 sub feature_pickaxe
{
334 my ($val) = git_get_project_config
('pickaxe', '--bool');
336 if ($val eq 'true') {
338 } elsif ($val eq 'false') {
345 # checking HEAD file with -e is fragile if the repository was
346 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
348 sub check_head_link
{
350 my $headfile = "$dir/HEAD";
351 return ((-e
$headfile) ||
352 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
355 sub check_export_ok
{
357 return (check_head_link
($dir) &&
358 (!$export_ok || -e
"$dir/$export_ok"));
361 # process alternate names for backward compatibility
362 # filter out unsupported (unknown) snapshot formats
363 sub filter_snapshot_fmts
{
367 exists $known_snapshot_format_aliases{$_} ?
368 $known_snapshot_format_aliases{$_} : $_} @fmts;
369 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
373 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
374 if (-e
$GITWEB_CONFIG) {
377 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
378 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
381 # version of the core git binary
382 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
384 $projects_list ||= $projectroot;
386 # ======================================================================
387 # input validation and dispatch
388 our $action = $cgi->param('a');
389 if (defined $action) {
390 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
391 die_error
(400, "Invalid action parameter");
395 # parameters which are pathnames
396 our $project = $cgi->param('p');
397 if (defined $project) {
398 if (!validate_pathname
($project) ||
399 !(-d
"$projectroot/$project") ||
400 !check_head_link
("$projectroot/$project") ||
401 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
402 ($strict_export && !project_in_list
($project))) {
404 die_error
(404, "No such project");
408 our $file_name = $cgi->param('f');
409 if (defined $file_name) {
410 if (!validate_pathname
($file_name)) {
411 die_error
(400, "Invalid file parameter");
415 our $file_parent = $cgi->param('fp');
416 if (defined $file_parent) {
417 if (!validate_pathname
($file_parent)) {
418 die_error
(400, "Invalid file parent parameter");
422 # parameters which are refnames
423 our $hash = $cgi->param('h');
425 if (!validate_refname
($hash)) {
426 die_error
(400, "Invalid hash parameter");
430 our $hash_parent = $cgi->param('hp');
431 if (defined $hash_parent) {
432 if (!validate_refname
($hash_parent)) {
433 die_error
(400, "Invalid hash parent parameter");
437 our $hash_base = $cgi->param('hb');
438 if (defined $hash_base) {
439 if (!validate_refname
($hash_base)) {
440 die_error
(400, "Invalid hash base parameter");
444 my %allowed_options = (
445 "--no-merges" => [ qw(rss atom log shortlog history) ],
448 our @extra_options = $cgi->param('opt');
449 if (defined @extra_options) {
450 foreach my $opt (@extra_options) {
451 if (not exists $allowed_options{$opt}) {
452 die_error
(400, "Invalid option parameter");
454 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
455 die_error
(400, "Invalid option parameter for this action");
460 our $hash_parent_base = $cgi->param('hpb');
461 if (defined $hash_parent_base) {
462 if (!validate_refname
($hash_parent_base)) {
463 die_error
(400, "Invalid hash parent base parameter");
468 our $page = $cgi->param('pg');
470 if ($page =~ m/[^0-9]/) {
471 die_error
(400, "Invalid page parameter");
475 our $searchtype = $cgi->param('st');
476 if (defined $searchtype) {
477 if ($searchtype =~ m/[^a-z]/) {
478 die_error
(400, "Invalid searchtype parameter");
482 our $search_use_regexp = $cgi->param('sr');
484 our $searchtext = $cgi->param('s');
486 if (defined $searchtext) {
487 if (length($searchtext) < 2) {
488 die_error
(403, "At least two characters are required for search parameter");
490 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
493 # now read PATH_INFO and use it as alternative to parameters
494 sub evaluate_path_info
{
495 return if defined $project;
496 my $path_info = $ENV{"PATH_INFO"};
497 return if !$path_info;
498 $path_info =~ s
,^/+,,;
499 return if !$path_info;
500 # find which part of PATH_INFO is project
501 $project = $path_info;
503 while ($project && !check_head_link
("$projectroot/$project")) {
504 $project =~ s
,/*[^/]*$,,;
507 $project = validate_pathname
($project);
509 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
510 ($strict_export && !project_in_list
($project))) {
514 # do not change any parameters if an action is given using the query string
516 $path_info =~ s
,^\Q
$project\E
/*,,;
517 my ($refname, $pathname) = split(/:/, $path_info, 2);
518 if (defined $pathname) {
519 # we got "project.git/branch:filename" or "project.git/branch:dir/"
520 # we could use git_get_type(branch:pathname), but it needs $git_dir
521 $pathname =~ s
,^/+,,;
522 if (!$pathname || substr($pathname, -1) eq "/") {
526 $action ||= "blob_plain";
528 $hash_base ||= validate_refname
($refname);
529 $file_name ||= validate_pathname
($pathname);
530 } elsif (defined $refname) {
531 # we got "project.git/branch"
532 $action ||= "shortlog";
533 $hash ||= validate_refname
($refname);
536 evaluate_path_info
();
538 # path to the current git repository
540 $git_dir = "$projectroot/$project" if $project;
544 "blame" => \
&git_blame
,
545 "blobdiff" => \
&git_blobdiff
,
546 "blobdiff_plain" => \
&git_blobdiff_plain
,
547 "blob" => \
&git_blob
,
548 "blob_plain" => \
&git_blob_plain
,
549 "commitdiff" => \
&git_commitdiff
,
550 "commitdiff_plain" => \
&git_commitdiff_plain
,
551 "commit" => \
&git_commit
,
552 "forks" => \
&git_forks
,
553 "heads" => \
&git_heads
,
554 "history" => \
&git_history
,
557 "atom" => \
&git_atom
,
558 "search" => \
&git_search
,
559 "search_help" => \
&git_search_help
,
560 "shortlog" => \
&git_shortlog
,
561 "summary" => \
&git_summary
,
563 "tags" => \
&git_tags
,
564 "tree" => \
&git_tree
,
565 "snapshot" => \
&git_snapshot
,
566 "object" => \
&git_object
,
567 # those below don't need $project
568 "opml" => \
&git_opml
,
569 "project_list" => \
&git_project_list
,
570 "project_index" => \
&git_project_index
,
573 if (!defined $action) {
575 $action = git_get_type
($hash);
576 } elsif (defined $hash_base && defined $file_name) {
577 $action = git_get_type
("$hash_base:$file_name");
578 } elsif (defined $project) {
581 $action = 'project_list';
584 if (!defined($actions{$action})) {
585 die_error
(400, "Unknown action");
587 if ($action !~ m/^(opml|project_list|project_index)$/ &&
589 die_error
(400, "Project needed");
591 $actions{$action}->();
594 ## ======================================================================
599 # default is to use -absolute url() i.e. $my_uri
600 my $href = $params{-full
} ?
$my_url : $my_uri;
602 # XXX: Warning: If you touch this, check the search form for updating,
613 hash_parent_base
=> "hpb",
618 snapshot_format
=> "sf",
619 extra_options
=> "opt",
620 search_use_regexp
=> "sr",
622 my %mapping = @mapping;
624 $params{'project'} = $project unless exists $params{'project'};
626 if ($params{-replay
}) {
627 while (my ($name, $symbol) = each %mapping) {
628 if (!exists $params{$name}) {
629 # to allow for multivalued params we use arrayref form
630 $params{$name} = [ $cgi->param($symbol) ];
635 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
637 # use PATH_INFO for project name
638 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
639 delete $params{'project'};
641 # Summary just uses the project path URL
642 if (defined $params{'action'} && $params{'action'} eq 'summary') {
643 delete $params{'action'};
647 # now encode the parameters explicitly
649 for (my $i = 0; $i < @mapping; $i += 2) {
650 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
651 if (defined $params{$name}) {
652 if (ref($params{$name}) eq "ARRAY") {
653 foreach my $par (@
{$params{$name}}) {
654 push @result, $symbol . "=" . esc_param
($par);
657 push @result, $symbol . "=" . esc_param
($params{$name});
661 $href .= "?" . join(';', @result) if scalar @result;
667 ## ======================================================================
668 ## validation, quoting/unquoting and escaping
670 sub validate_pathname
{
671 my $input = shift || return undef;
673 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
674 # at the beginning, at the end, and between slashes.
675 # also this catches doubled slashes
676 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
680 if ($input =~ m!\0!) {
686 sub validate_refname
{
687 my $input = shift || return undef;
689 # textual hashes are O.K.
690 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
693 # it must be correct pathname
694 $input = validate_pathname
($input)
696 # restrictions on ref name according to git-check-ref-format
697 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
703 # decode sequences of octets in utf8 into Perl's internal form,
704 # which is utf-8 with utf8 flag set if needed. gitweb writes out
705 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
708 if (utf8
::valid
($str)) {
712 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
716 # quote unsafe chars, but keep the slash, even when it's not
717 # correct, but quoted slashes look too horrible in bookmarks
720 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
726 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
729 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
735 # replace invalid utf8 character with SUBSTITUTION sequence
740 $str = to_utf8
($str);
741 $str = $cgi->escapeHTML($str);
742 if ($opts{'-nbsp'}) {
743 $str =~ s/ / /g;
745 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
749 # quote control characters and escape filename to HTML
754 $str = to_utf8
($str);
755 $str = $cgi->escapeHTML($str);
756 if ($opts{'-nbsp'}) {
757 $str =~ s/ / /g;
759 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
763 # Make control characters "printable", using character escape codes (CEC)
767 my %es = ( # character escape codes, aka escape sequences
768 "\t" => '\t', # tab (HT)
769 "\n" => '\n', # line feed (LF)
770 "\r" => '\r', # carrige return (CR)
771 "\f" => '\f', # form feed (FF)
772 "\b" => '\b', # backspace (BS)
773 "\a" => '\a', # alarm (bell) (BEL)
774 "\e" => '\e', # escape (ESC)
775 "\013" => '\v', # vertical tab (VT)
776 "\000" => '\0', # nul character (NUL)
778 my $chr = ( (exists $es{$cntrl})
780 : sprintf('\%03o', ord($cntrl)) );
781 if ($opts{-nohtml
}) {
784 return "<span class=\"cntrl\">$chr</span>";
788 # Alternatively use unicode control pictures codepoints,
789 # Unicode "printable representation" (PR)
794 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
795 if ($opts{-nohtml
}) {
798 return "<span class=\"cntrl\">$chr</span>";
802 # git may return quoted and escaped filenames
808 my %es = ( # character escape codes, aka escape sequences
809 't' => "\t", # tab (HT, TAB)
810 'n' => "\n", # newline (NL)
811 'r' => "\r", # return (CR)
812 'f' => "\f", # form feed (FF)
813 'b' => "\b", # backspace (BS)
814 'a' => "\a", # alarm (bell) (BEL)
815 'e' => "\e", # escape (ESC)
816 'v' => "\013", # vertical tab (VT)
819 if ($seq =~ m/^[0-7]{1,3}$/) {
820 # octal char sequence
821 return chr(oct($seq));
822 } elsif (exists $es{$seq}) {
823 # C escape sequence, aka character escape code
826 # quoted ordinary character
830 if ($str =~ m/^"(.*)"$/) {
833 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
838 # escape tabs (convert tabs to spaces)
842 while ((my $pos = index($line, "\t")) != -1) {
843 if (my $count = (8 - ($pos % 8))) {
844 my $spaces = ' ' x
$count;
845 $line =~ s/\t/$spaces/;
852 sub project_in_list
{
854 my @list = git_get_projects_list
();
855 return @list && scalar(grep { $_->{'path'} eq $project } @list);
858 ## ----------------------------------------------------------------------
859 ## HTML aware string manipulation
861 # Try to chop given string on a word boundary between position
862 # $len and $len+$add_len. If there is no word boundary there,
863 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
864 # (marking chopped part) would be longer than given string.
868 my $add_len = shift || 10;
869 my $where = shift || 'right'; # 'left' | 'center' | 'right'
871 # Make sure perl knows it is utf8 encoded so we don't
872 # cut in the middle of a utf8 multibyte char.
873 $str = to_utf8
($str);
875 # allow only $len chars, but don't cut a word if it would fit in $add_len
876 # if it doesn't fit, cut it if it's still longer than the dots we would add
877 # remove chopped character entities entirely
879 # when chopping in the middle, distribute $len into left and right part
880 # return early if chopping wouldn't make string shorter
881 if ($where eq 'center') {
882 return $str if ($len + 5 >= length($str)); # filler is length 5
885 return $str if ($len + 4 >= length($str)); # filler is length 4
888 # regexps: ending and beginning with word part up to $add_len
889 my $endre = qr/.{$len}\w{0,$add_len}/;
890 my $begre = qr/\w{0,$add_len}.{$len}/;
892 if ($where eq 'left') {
893 $str =~ m/^(.*?)($begre)$/;
894 my ($lead, $body) = ($1, $2);
895 if (length($lead) > 4) {
896 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
901 } elsif ($where eq 'center') {
902 $str =~ m/^($endre)(.*)$/;
903 my ($left, $str) = ($1, $2);
904 $str =~ m/^(.*?)($begre)$/;
905 my ($mid, $right) = ($1, $2);
906 if (length($mid) > 5) {
907 $left =~ s/&[^;]*$//;
908 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
911 return "$left$mid$right";
914 $str =~ m/^($endre)(.*)$/;
917 if (length($tail) > 4) {
918 $body =~ s/&[^;]*$//;
925 # takes the same arguments as chop_str, but also wraps a <span> around the
926 # result with a title attribute if it does get chopped. Additionally, the
927 # string is HTML-escaped.
928 sub chop_and_escape_str
{
931 my $chopped = chop_str
(@_);
932 if ($chopped eq $str) {
933 return esc_html
($chopped);
935 $str =~ s/([[:cntrl:]])/?/g;
936 return $cgi->span({-title
=>$str}, esc_html
($chopped));
940 ## ----------------------------------------------------------------------
941 ## functions returning short strings
943 # CSS class for given age value (in seconds)
949 } elsif ($age < 60*60*2) {
951 } elsif ($age < 60*60*24*2) {
958 # convert age in seconds to "nn units ago" string
963 if ($age > 60*60*24*365*2) {
964 $age_str = (int $age/60/60/24/365);
965 $age_str .= " years ago";
966 } elsif ($age > 60*60*24*(365/12)*2) {
967 $age_str = int $age/60/60/24/(365/12);
968 $age_str .= " months ago";
969 } elsif ($age > 60*60*24*7*2) {
970 $age_str = int $age/60/60/24/7;
971 $age_str .= " weeks ago";
972 } elsif ($age > 60*60*24*2) {
973 $age_str = int $age/60/60/24;
974 $age_str .= " days ago";
975 } elsif ($age > 60*60*2) {
976 $age_str = int $age/60/60;
977 $age_str .= " hours ago";
978 } elsif ($age > 60*2) {
979 $age_str = int $age/60;
980 $age_str .= " min ago";
983 $age_str .= " sec ago";
985 $age_str .= " right now";
991 S_IFINVALID
=> 0030000,
992 S_IFGITLINK
=> 0160000,
995 # submodule/subproject, a commit object reference
999 return (($mode & S_IFMT
) == S_IFGITLINK
)
1002 # convert file mode in octal to symbolic file mode string
1004 my $mode = oct shift;
1006 if (S_ISGITLINK
($mode)) {
1007 return 'm---------';
1008 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1009 return 'drwxr-xr-x';
1010 } elsif (S_ISLNK
($mode)) {
1011 return 'lrwxrwxrwx';
1012 } elsif (S_ISREG
($mode)) {
1013 # git cares only about the executable bit
1014 if ($mode & S_IXUSR
) {
1015 return '-rwxr-xr-x';
1017 return '-rw-r--r--';
1020 return '----------';
1024 # convert file mode in octal to file type string
1028 if ($mode !~ m/^[0-7]+$/) {
1034 if (S_ISGITLINK
($mode)) {
1036 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1038 } elsif (S_ISLNK
($mode)) {
1040 } elsif (S_ISREG
($mode)) {
1047 # convert file mode in octal to file type description string
1048 sub file_type_long
{
1051 if ($mode !~ m/^[0-7]+$/) {
1057 if (S_ISGITLINK
($mode)) {
1059 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1061 } elsif (S_ISLNK
($mode)) {
1063 } elsif (S_ISREG
($mode)) {
1064 if ($mode & S_IXUSR
) {
1065 return "executable";
1075 ## ----------------------------------------------------------------------
1076 ## functions returning short HTML fragments, or transforming HTML fragments
1077 ## which don't belong to other sections
1079 # format line of commit message.
1080 sub format_log_line_html
{
1083 $line = esc_html
($line, -nbsp
=>1);
1084 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1087 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1088 -class => "text"}, $hash_text);
1089 $line =~ s/$hash_text/$link/;
1094 # format marker of refs pointing to given object
1095 sub format_ref_marker
{
1096 my ($refs, $id) = @_;
1099 if (defined $refs->{$id}) {
1100 foreach my $ref (@
{$refs->{$id}}) {
1101 my ($type, $name) = qw();
1102 # e.g. tags/v2.6.11 or heads/next
1103 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1111 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1112 esc_html
($name) . "</span>";
1117 return ' <span class="refs">'. $markers . '</span>';
1123 # format, perhaps shortened and with markers, title line
1124 sub format_subject_html
{
1125 my ($long, $short, $href, $extra) = @_;
1126 $extra = '' unless defined($extra);
1128 if (length($short) < length($long)) {
1129 return $cgi->a({-href
=> $href, -class => "list subject",
1130 -title
=> to_utf8
($long)},
1131 esc_html
($short) . $extra);
1133 return $cgi->a({-href
=> $href, -class => "list subject"},
1134 esc_html
($long) . $extra);
1138 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1139 sub format_git_diff_header_line
{
1141 my $diffinfo = shift;
1142 my ($from, $to) = @_;
1144 if ($diffinfo->{'nparents'}) {
1146 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1147 if ($to->{'href'}) {
1148 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1149 esc_path
($to->{'file'}));
1150 } else { # file was deleted (no href)
1151 $line .= esc_path
($to->{'file'});
1155 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1156 if ($from->{'href'}) {
1157 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1158 'a/' . esc_path
($from->{'file'}));
1159 } else { # file was added (no href)
1160 $line .= 'a/' . esc_path
($from->{'file'});
1163 if ($to->{'href'}) {
1164 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1165 'b/' . esc_path
($to->{'file'}));
1166 } else { # file was deleted
1167 $line .= 'b/' . esc_path
($to->{'file'});
1171 return "<div class=\"diff header\">$line</div>\n";
1174 # format extended diff header line, before patch itself
1175 sub format_extended_diff_header_line
{
1177 my $diffinfo = shift;
1178 my ($from, $to) = @_;
1181 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1182 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1183 esc_path
($from->{'file'}));
1185 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1186 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1187 esc_path
($to->{'file'}));
1189 # match single <mode>
1190 if ($line =~ m/\s(\d{6})$/) {
1191 $line .= '<span class="info"> (' .
1192 file_type_long
($1) .
1196 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1197 # can match only for combined diff
1199 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1200 if ($from->{'href'}[$i]) {
1201 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1203 substr($diffinfo->{'from_id'}[$i],0,7));
1208 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1211 if ($to->{'href'}) {
1212 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1213 substr($diffinfo->{'to_id'},0,7));
1218 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1219 # can match only for ordinary diff
1220 my ($from_link, $to_link);
1221 if ($from->{'href'}) {
1222 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1223 substr($diffinfo->{'from_id'},0,7));
1225 $from_link = '0' x
7;
1227 if ($to->{'href'}) {
1228 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1229 substr($diffinfo->{'to_id'},0,7));
1233 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1234 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1237 return $line . "<br/>\n";
1240 # format from-file/to-file diff header
1241 sub format_diff_from_to_header
{
1242 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1247 #assert($line =~ m/^---/) if DEBUG;
1248 # no extra formatting for "^--- /dev/null"
1249 if (! $diffinfo->{'nparents'}) {
1250 # ordinary (single parent) diff
1251 if ($line =~ m!^--- "?a/!) {
1252 if ($from->{'href'}) {
1254 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1255 esc_path
($from->{'file'}));
1258 esc_path
($from->{'file'});
1261 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1264 # combined diff (merge commit)
1265 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1266 if ($from->{'href'}[$i]) {
1268 $cgi->a({-href
=>href
(action
=>"blobdiff",
1269 hash_parent
=>$diffinfo->{'from_id'}[$i],
1270 hash_parent_base
=>$parents[$i],
1271 file_parent
=>$from->{'file'}[$i],
1272 hash
=>$diffinfo->{'to_id'},
1274 file_name
=>$to->{'file'}),
1276 -title
=>"diff" . ($i+1)},
1279 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1280 esc_path
($from->{'file'}[$i]));
1282 $line = '--- /dev/null';
1284 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1289 #assert($line =~ m/^\+\+\+/) if DEBUG;
1290 # no extra formatting for "^+++ /dev/null"
1291 if ($line =~ m!^\+\+\+ "?b/!) {
1292 if ($to->{'href'}) {
1294 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1295 esc_path
($to->{'file'}));
1298 esc_path
($to->{'file'});
1301 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1306 # create note for patch simplified by combined diff
1307 sub format_diff_cc_simplified
{
1308 my ($diffinfo, @parents) = @_;
1311 $result .= "<div class=\"diff header\">" .
1313 if (!is_deleted
($diffinfo)) {
1314 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1316 hash
=>$diffinfo->{'to_id'},
1317 file_name
=>$diffinfo->{'to_file'}),
1319 esc_path
($diffinfo->{'to_file'}));
1321 $result .= esc_path
($diffinfo->{'to_file'});
1323 $result .= "</div>\n" . # class="diff header"
1324 "<div class=\"diff nodifferences\">" .
1326 "</div>\n"; # class="diff nodifferences"
1331 # format patch (diff) line (not to be used for diff headers)
1332 sub format_diff_line
{
1334 my ($from, $to) = @_;
1335 my $diff_class = "";
1339 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1341 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1342 if ($line =~ m/^\@{3}/) {
1343 $diff_class = " chunk_header";
1344 } elsif ($line =~ m/^\\/) {
1345 $diff_class = " incomplete";
1346 } elsif ($prefix =~ tr/+/+/) {
1347 $diff_class = " add";
1348 } elsif ($prefix =~ tr/-/-/) {
1349 $diff_class = " rem";
1352 # assume ordinary diff
1353 my $char = substr($line, 0, 1);
1355 $diff_class = " add";
1356 } elsif ($char eq '-') {
1357 $diff_class = " rem";
1358 } elsif ($char eq '@') {
1359 $diff_class = " chunk_header";
1360 } elsif ($char eq "\\") {
1361 $diff_class = " incomplete";
1364 $line = untabify
($line);
1365 if ($from && $to && $line =~ m/^\@{2} /) {
1366 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1367 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1369 $from_lines = 0 unless defined $from_lines;
1370 $to_lines = 0 unless defined $to_lines;
1372 if ($from->{'href'}) {
1373 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1374 -class=>"list"}, $from_text);
1376 if ($to->{'href'}) {
1377 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1378 -class=>"list"}, $to_text);
1380 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1381 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1382 return "<div class=\"diff$diff_class\">$line</div>\n";
1383 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1384 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1385 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1387 @from_text = split(' ', $ranges);
1388 for (my $i = 0; $i < @from_text; ++$i) {
1389 ($from_start[$i], $from_nlines[$i]) =
1390 (split(',', substr($from_text[$i], 1)), 0);
1393 $to_text = pop @from_text;
1394 $to_start = pop @from_start;
1395 $to_nlines = pop @from_nlines;
1397 $line = "<span class=\"chunk_info\">$prefix ";
1398 for (my $i = 0; $i < @from_text; ++$i) {
1399 if ($from->{'href'}[$i]) {
1400 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1401 -class=>"list"}, $from_text[$i]);
1403 $line .= $from_text[$i];
1407 if ($to->{'href'}) {
1408 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1409 -class=>"list"}, $to_text);
1413 $line .= " $prefix</span>" .
1414 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1415 return "<div class=\"diff$diff_class\">$line</div>\n";
1417 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1420 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1421 # linked. Pass the hash of the tree/commit to snapshot.
1422 sub format_snapshot_links
{
1424 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1425 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1426 my $num_fmts = @snapshot_fmts;
1427 if ($num_fmts > 1) {
1428 # A parenthesized list of links bearing format names.
1429 # e.g. "snapshot (_tar.gz_ _zip_)"
1430 return "snapshot (" . join(' ', map
1437 }, $known_snapshot_formats{$_}{'display'})
1438 , @snapshot_fmts) . ")";
1439 } elsif ($num_fmts == 1) {
1440 # A single "snapshot" link whose tooltip bears the format name.
1442 my ($fmt) = @snapshot_fmts;
1448 snapshot_format
=>$fmt
1450 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1452 } else { # $num_fmts == 0
1457 ## ......................................................................
1458 ## functions returning values to be passed, perhaps after some
1459 ## transformation, to other functions; e.g. returning arguments to href()
1461 # returns hash to be passed to href to generate gitweb URL
1462 # in -title key it returns description of link
1464 my $format = shift || 'Atom';
1465 my %res = (action
=> lc($format));
1467 # feed links are possible only for project views
1468 return unless (defined $project);
1469 # some views should link to OPML, or to generic project feed,
1470 # or don't have specific feed yet (so they should use generic)
1471 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1474 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1475 # from tag links; this also makes possible to detect branch links
1476 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1477 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1480 # find log type for feed description (title)
1482 if (defined $file_name) {
1483 $type = "history of $file_name";
1484 $type .= "/" if ($action eq 'tree');
1485 $type .= " on '$branch'" if (defined $branch);
1487 $type = "log of $branch" if (defined $branch);
1490 $res{-title
} = $type;
1491 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1492 $res{'file_name'} = $file_name;
1497 ## ----------------------------------------------------------------------
1498 ## git utility subroutines, invoking git commands
1500 # returns path to the core git executable and the --git-dir parameter as list
1502 return $GIT, '--git-dir='.$git_dir;
1505 # quote the given arguments for passing them to the shell
1506 # quote_command("command", "arg 1", "arg with ' and ! characters")
1507 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1508 # Try to avoid using this function wherever possible.
1511 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1514 # get HEAD ref of given project as hash
1515 sub git_get_head_hash
{
1516 my $project = shift;
1517 my $o_git_dir = $git_dir;
1519 $git_dir = "$projectroot/$project";
1520 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1523 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1527 if (defined $o_git_dir) {
1528 $git_dir = $o_git_dir;
1533 # get type of given object
1537 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1539 close $fd or return;
1544 # repository configuration
1545 our $config_file = '';
1548 # store multiple values for single key as anonymous array reference
1549 # single values stored directly in the hash, not as [ <value> ]
1550 sub hash_set_multi
{
1551 my ($hash, $key, $value) = @_;
1553 if (!exists $hash->{$key}) {
1554 $hash->{$key} = $value;
1555 } elsif (!ref $hash->{$key}) {
1556 $hash->{$key} = [ $hash->{$key}, $value ];
1558 push @
{$hash->{$key}}, $value;
1562 # return hash of git project configuration
1563 # optionally limited to some section, e.g. 'gitweb'
1564 sub git_parse_project_config
{
1565 my $section_regexp = shift;
1570 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1573 while (my $keyval = <$fh>) {
1575 my ($key, $value) = split(/\n/, $keyval, 2);
1577 hash_set_multi
(\
%config, $key, $value)
1578 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1585 # convert config value to boolean, 'true' or 'false'
1586 # no value, number > 0, 'true' and 'yes' values are true
1587 # rest of values are treated as false (never as error)
1588 sub config_to_bool
{
1591 # strip leading and trailing whitespace
1595 return (!defined $val || # section.key
1596 ($val =~ /^\d+$/ && $val) || # section.key = 1
1597 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1600 # convert config value to simple decimal number
1601 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1602 # to be multiplied by 1024, 1048576, or 1073741824
1606 # strip leading and trailing whitespace
1610 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1612 # unknown unit is treated as 1
1613 return $num * ($unit eq 'g' ?
1073741824 :
1614 $unit eq 'm' ?
1048576 :
1615 $unit eq 'k' ?
1024 : 1);
1620 # convert config value to array reference, if needed
1621 sub config_to_multi
{
1624 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1627 sub git_get_project_config
{
1628 my ($key, $type) = @_;
1631 return unless ($key);
1632 $key =~ s/^gitweb\.//;
1633 return if ($key =~ m/\W/);
1636 if (defined $type) {
1639 unless ($type eq 'bool' || $type eq 'int');
1643 if (!defined $config_file ||
1644 $config_file ne "$git_dir/config") {
1645 %config = git_parse_project_config
('gitweb');
1646 $config_file = "$git_dir/config";
1650 if (!defined $type) {
1651 return $config{"gitweb.$key"};
1652 } elsif ($type eq 'bool') {
1653 # backward compatibility: 'git config --bool' returns true/false
1654 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1655 } elsif ($type eq 'int') {
1656 return config_to_int
($config{"gitweb.$key"});
1658 return $config{"gitweb.$key"};
1661 # get hash of given path at given ref
1662 sub git_get_hash_by_path
{
1664 my $path = shift || return undef;
1669 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1670 or die_error
(500, "Open git-ls-tree failed");
1672 close $fd or return undef;
1674 if (!defined $line) {
1675 # there is no tree or hash given by $path at $base
1679 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1680 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1681 if (defined $type && $type ne $2) {
1682 # type doesn't match
1688 # get path of entry with given hash at given tree-ish (ref)
1689 # used to get 'from' filename for combined diff (merge commit) for renames
1690 sub git_get_path_by_hash
{
1691 my $base = shift || return;
1692 my $hash = shift || return;
1696 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1698 while (my $line = <$fd>) {
1701 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1702 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1703 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1712 ## ......................................................................
1713 ## git utility functions, directly accessing git repository
1715 sub git_get_project_description
{
1718 $git_dir = "$projectroot/$path";
1719 open my $fd, "$git_dir/description"
1720 or return git_get_project_config
('description');
1723 if (defined $descr) {
1729 sub git_get_project_url_list
{
1732 $git_dir = "$projectroot/$path";
1733 open my $fd, "$git_dir/cloneurl"
1734 or return wantarray ?
1735 @
{ config_to_multi
(git_get_project_config
('url')) } :
1736 config_to_multi
(git_get_project_config
('url'));
1737 my @git_project_url_list = map { chomp; $_ } <$fd>;
1740 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1743 sub git_get_projects_list
{
1748 $filter =~ s/\.git$//;
1750 my ($check_forks) = gitweb_check_feature
('forks');
1752 if (-d
$projects_list) {
1753 # search in directory
1754 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1755 # remove the trailing "/"
1757 my $pfxlen = length("$dir");
1758 my $pfxdepth = ($dir =~ tr!/!!);
1761 follow_fast
=> 1, # follow symbolic links
1762 follow_skip
=> 2, # ignore duplicates
1763 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1765 # skip project-list toplevel, if we get it.
1766 return if (m!^[/.]$!);
1767 # only directories can be git repositories
1768 return unless (-d
$_);
1769 # don't traverse too deep (Find is super slow on os x)
1770 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1771 $File::Find
::prune
= 1;
1775 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1776 # we check related file in $projectroot
1777 if ($check_forks and $subdir =~ m
#/.#) {
1778 $File::Find
::prune
= 1;
1779 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1780 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1781 $File::Find
::prune
= 1;
1786 } elsif (-f
$projects_list) {
1787 # read from file(url-encoded):
1788 # 'git%2Fgit.git Linus+Torvalds'
1789 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1790 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1792 open my ($fd), $projects_list or return;
1794 while (my $line = <$fd>) {
1796 my ($path, $owner) = split ' ', $line;
1797 $path = unescape
($path);
1798 $owner = unescape
($owner);
1799 if (!defined $path) {
1802 if ($filter ne '') {
1803 # looking for forks;
1804 my $pfx = substr($path, 0, length($filter));
1805 if ($pfx ne $filter) {
1808 my $sfx = substr($path, length($filter));
1809 if ($sfx !~ /^\/.*\
.git
$/) {
1812 } elsif ($check_forks) {
1814 foreach my $filter (keys %paths) {
1815 # looking for forks;
1816 my $pfx = substr($path, 0, length($filter));
1817 if ($pfx ne $filter) {
1820 my $sfx = substr($path, length($filter));
1821 if ($sfx !~ /^\/.*\
.git
$/) {
1824 # is a fork, don't include it in
1829 if (check_export_ok
("$projectroot/$path")) {
1832 owner
=> to_utf8
($owner),
1835 (my $forks_path = $path) =~ s/\.git$//;
1836 $paths{$forks_path}++;
1844 our $gitweb_project_owner = undef;
1845 sub git_get_project_list_from_file
{
1847 return if (defined $gitweb_project_owner);
1849 $gitweb_project_owner = {};
1850 # read from file (url-encoded):
1851 # 'git%2Fgit.git Linus+Torvalds'
1852 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1853 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1854 if (-f
$projects_list) {
1855 open (my $fd , $projects_list);
1856 while (my $line = <$fd>) {
1858 my ($pr, $ow) = split ' ', $line;
1859 $pr = unescape
($pr);
1860 $ow = unescape
($ow);
1861 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1867 sub git_get_project_owner
{
1868 my $project = shift;
1871 return undef unless $project;
1872 $git_dir = "$projectroot/$project";
1874 if (!defined $gitweb_project_owner) {
1875 git_get_project_list_from_file
();
1878 if (exists $gitweb_project_owner->{$project}) {
1879 $owner = $gitweb_project_owner->{$project};
1881 if (!defined $owner){
1882 $owner = git_get_project_config
('owner');
1884 if (!defined $owner) {
1885 $owner = get_file_owner
("$git_dir");
1891 sub git_get_last_activity
{
1895 $git_dir = "$projectroot/$path";
1896 open($fd, "-|", git_cmd
(), 'for-each-ref',
1897 '--format=%(committer)',
1898 '--sort=-committerdate',
1900 'refs/heads') or return;
1901 my $most_recent = <$fd>;
1902 close $fd or return;
1903 if (defined $most_recent &&
1904 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1906 my $age = time - $timestamp;
1907 return ($age, age_string
($age));
1909 return (undef, undef);
1912 sub git_get_references
{
1913 my $type = shift || "";
1915 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1916 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1917 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1918 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1921 while (my $line = <$fd>) {
1923 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1924 if (defined $refs{$1}) {
1925 push @
{$refs{$1}}, $2;
1931 close $fd or return;
1935 sub git_get_rev_name_tags
{
1936 my $hash = shift || return undef;
1938 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1940 my $name_rev = <$fd>;
1943 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1946 # catches also '$hash undefined' output
1951 ## ----------------------------------------------------------------------
1952 ## parse to hash functions
1956 my $tz = shift || "-0000";
1959 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1960 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1961 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1962 $date{'hour'} = $hour;
1963 $date{'minute'} = $min;
1964 $date{'mday'} = $mday;
1965 $date{'day'} = $days[$wday];
1966 $date{'month'} = $months[$mon];
1967 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1968 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1969 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1970 $mday, $months[$mon], $hour ,$min;
1971 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1972 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1974 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1975 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1976 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1977 $date{'hour_local'} = $hour;
1978 $date{'minute_local'} = $min;
1979 $date{'tz_local'} = $tz;
1980 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1981 1900+$year, $mon+1, $mday,
1982 $hour, $min, $sec, $tz);
1991 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1992 $tag{'id'} = $tag_id;
1993 while (my $line = <$fd>) {
1995 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1996 $tag{'object'} = $1;
1997 } elsif ($line =~ m/^type (.+)$/) {
1999 } elsif ($line =~ m/^tag (.+)$/) {
2001 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2002 $tag{'author'} = $1;
2005 } elsif ($line =~ m/--BEGIN/) {
2006 push @comment, $line;
2008 } elsif ($line eq "") {
2012 push @comment, <$fd>;
2013 $tag{'comment'} = \
@comment;
2014 close $fd or return;
2015 if (!defined $tag{'name'}) {
2021 sub parse_commit_text
{
2022 my ($commit_text, $withparents) = @_;
2023 my @commit_lines = split '\n', $commit_text;
2026 pop @commit_lines; # Remove '\0'
2028 if (! @commit_lines) {
2032 my $header = shift @commit_lines;
2033 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2036 ($co{'id'}, my @parents) = split ' ', $header;
2037 while (my $line = shift @commit_lines) {
2038 last if $line eq "\n";
2039 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2041 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2043 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2045 $co{'author_epoch'} = $2;
2046 $co{'author_tz'} = $3;
2047 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2048 $co{'author_name'} = $1;
2049 $co{'author_email'} = $2;
2051 $co{'author_name'} = $co{'author'};
2053 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2054 $co{'committer'} = $1;
2055 $co{'committer_epoch'} = $2;
2056 $co{'committer_tz'} = $3;
2057 $co{'committer_name'} = $co{'committer'};
2058 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2059 $co{'committer_name'} = $1;
2060 $co{'committer_email'} = $2;
2062 $co{'committer_name'} = $co{'committer'};
2066 if (!defined $co{'tree'}) {
2069 $co{'parents'} = \
@parents;
2070 $co{'parent'} = $parents[0];
2072 foreach my $title (@commit_lines) {
2075 $co{'title'} = chop_str
($title, 80, 5);
2076 # remove leading stuff of merges to make the interesting part visible
2077 if (length($title) > 50) {
2078 $title =~ s/^Automatic //;
2079 $title =~ s/^merge (of|with) /Merge ... /i;
2080 if (length($title) > 50) {
2081 $title =~ s/(http|rsync):\/\///;
2083 if (length($title) > 50) {
2084 $title =~ s/(master|www|rsync)\.//;
2086 if (length($title) > 50) {
2087 $title =~ s/kernel.org:?//;
2089 if (length($title) > 50) {
2090 $title =~ s/\/pub\/scm//;
2093 $co{'title_short'} = chop_str
($title, 50, 5);
2097 if ($co{'title'} eq "") {
2098 $co{'title'} = $co{'title_short'} = '(no commit message)';
2100 # remove added spaces
2101 foreach my $line (@commit_lines) {
2104 $co{'comment'} = \
@commit_lines;
2106 my $age = time - $co{'committer_epoch'};
2108 $co{'age_string'} = age_string
($age);
2109 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2110 if ($age > 60*60*24*7*2) {
2111 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2112 $co{'age_string_age'} = $co{'age_string'};
2114 $co{'age_string_date'} = $co{'age_string'};
2115 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2121 my ($commit_id) = @_;
2126 open my $fd, "-|", git_cmd
(), "rev-list",
2132 or die_error
(500, "Open git-rev-list failed");
2133 %co = parse_commit_text
(<$fd>, 1);
2140 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2148 open my $fd, "-|", git_cmd
(), "rev-list",
2151 ("--max-count=" . $maxcount),
2152 ("--skip=" . $skip),
2156 ($filename ?
($filename) : ())
2157 or die_error
(500, "Open git-rev-list failed");
2158 while (my $line = <$fd>) {
2159 my %co = parse_commit_text
($line);
2164 return wantarray ?
@cos : \
@cos;
2167 # parse line of git-diff-tree "raw" output
2168 sub parse_difftree_raw_line
{
2172 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2173 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2174 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2175 $res{'from_mode'} = $1;
2176 $res{'to_mode'} = $2;
2177 $res{'from_id'} = $3;
2179 $res{'status'} = $5;
2180 $res{'similarity'} = $6;
2181 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2182 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2184 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2187 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2188 # combined diff (for merge commit)
2189 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2190 $res{'nparents'} = length($1);
2191 $res{'from_mode'} = [ split(' ', $2) ];
2192 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2193 $res{'from_id'} = [ split(' ', $3) ];
2194 $res{'to_id'} = pop @
{$res{'from_id'}};
2195 $res{'status'} = [ split('', $4) ];
2196 $res{'to_file'} = unquote
($5);
2198 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2199 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2200 $res{'commit'} = $1;
2203 return wantarray ?
%res : \
%res;
2206 # wrapper: return parsed line of git-diff-tree "raw" output
2207 # (the argument might be raw line, or parsed info)
2208 sub parsed_difftree_line
{
2209 my $line_or_ref = shift;
2211 if (ref($line_or_ref) eq "HASH") {
2212 # pre-parsed (or generated by hand)
2213 return $line_or_ref;
2215 return parse_difftree_raw_line
($line_or_ref);
2219 # parse line of git-ls-tree output
2220 sub parse_ls_tree_line
($;%) {
2225 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2226 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2234 $res{'name'} = unquote
($4);
2237 return wantarray ?
%res : \
%res;
2240 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2241 sub parse_from_to_diffinfo
{
2242 my ($diffinfo, $from, $to, @parents) = @_;
2244 if ($diffinfo->{'nparents'}) {
2246 $from->{'file'} = [];
2247 $from->{'href'} = [];
2248 fill_from_file_info
($diffinfo, @parents)
2249 unless exists $diffinfo->{'from_file'};
2250 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2251 $from->{'file'}[$i] =
2252 defined $diffinfo->{'from_file'}[$i] ?
2253 $diffinfo->{'from_file'}[$i] :
2254 $diffinfo->{'to_file'};
2255 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2256 $from->{'href'}[$i] = href
(action
=>"blob",
2257 hash_base
=>$parents[$i],
2258 hash
=>$diffinfo->{'from_id'}[$i],
2259 file_name
=>$from->{'file'}[$i]);
2261 $from->{'href'}[$i] = undef;
2265 # ordinary (not combined) diff
2266 $from->{'file'} = $diffinfo->{'from_file'};
2267 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2268 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2269 hash
=>$diffinfo->{'from_id'},
2270 file_name
=>$from->{'file'});
2272 delete $from->{'href'};
2276 $to->{'file'} = $diffinfo->{'to_file'};
2277 if (!is_deleted
($diffinfo)) { # file exists in result
2278 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2279 hash
=>$diffinfo->{'to_id'},
2280 file_name
=>$to->{'file'});
2282 delete $to->{'href'};
2286 ## ......................................................................
2287 ## parse to array of hashes functions
2289 sub git_get_heads_list
{
2293 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2294 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2295 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2298 while (my $line = <$fd>) {
2302 my ($refinfo, $committerinfo) = split(/\0/, $line);
2303 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2304 my ($committer, $epoch, $tz) =
2305 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2306 $ref_item{'fullname'} = $name;
2307 $name =~ s!^refs/heads/!!;
2309 $ref_item{'name'} = $name;
2310 $ref_item{'id'} = $hash;
2311 $ref_item{'title'} = $title || '(no commit message)';
2312 $ref_item{'epoch'} = $epoch;
2314 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2316 $ref_item{'age'} = "unknown";
2319 push @headslist, \
%ref_item;
2323 return wantarray ?
@headslist : \
@headslist;
2326 sub git_get_tags_list
{
2330 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2331 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2332 '--format=%(objectname) %(objecttype) %(refname) '.
2333 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2336 while (my $line = <$fd>) {
2340 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2341 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2342 my ($creator, $epoch, $tz) =
2343 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2344 $ref_item{'fullname'} = $name;
2345 $name =~ s!^refs/tags/!!;
2347 $ref_item{'type'} = $type;
2348 $ref_item{'id'} = $id;
2349 $ref_item{'name'} = $name;
2350 if ($type eq "tag") {
2351 $ref_item{'subject'} = $title;
2352 $ref_item{'reftype'} = $reftype;
2353 $ref_item{'refid'} = $refid;
2355 $ref_item{'reftype'} = $type;
2356 $ref_item{'refid'} = $id;
2359 if ($type eq "tag" || $type eq "commit") {
2360 $ref_item{'epoch'} = $epoch;
2362 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2364 $ref_item{'age'} = "unknown";
2368 push @tagslist, \
%ref_item;
2372 return wantarray ?
@tagslist : \
@tagslist;
2375 ## ----------------------------------------------------------------------
2376 ## filesystem-related functions
2378 sub get_file_owner
{
2381 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2382 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2383 if (!defined $gcos) {
2387 $owner =~ s/[,;].*$//;
2388 return to_utf8
($owner);
2391 ## ......................................................................
2392 ## mimetype related functions
2394 sub mimetype_guess_file
{
2395 my $filename = shift;
2396 my $mimemap = shift;
2397 -r
$mimemap or return undef;
2400 open(MIME
, $mimemap) or return undef;
2402 next if m/^#/; # skip comments
2403 my ($mime, $exts) = split(/\t+/);
2404 if (defined $exts) {
2405 my @exts = split(/\s+/, $exts);
2406 foreach my $ext (@exts) {
2407 $mimemap{$ext} = $mime;
2413 $filename =~ /\.([^.]*)$/;
2414 return $mimemap{$1};
2417 sub mimetype_guess
{
2418 my $filename = shift;
2420 $filename =~ /\./ or return undef;
2422 if ($mimetypes_file) {
2423 my $file = $mimetypes_file;
2424 if ($file !~ m!^/!) { # if it is relative path
2425 # it is relative to project
2426 $file = "$projectroot/$project/$file";
2428 $mime = mimetype_guess_file
($filename, $file);
2430 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2436 my $filename = shift;
2439 my $mime = mimetype_guess
($filename);
2440 $mime and return $mime;
2444 return $default_blob_plain_mimetype unless $fd;
2447 return 'text/plain';
2448 } elsif (! $filename) {
2449 return 'application/octet-stream';
2450 } elsif ($filename =~ m/\.png$/i) {
2452 } elsif ($filename =~ m/\.gif$/i) {
2454 } elsif ($filename =~ m/\.jpe?g$/i) {
2455 return 'image/jpeg';
2457 return 'application/octet-stream';
2461 sub blob_contenttype
{
2462 my ($fd, $file_name, $type) = @_;
2464 $type ||= blob_mimetype
($fd, $file_name);
2465 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2466 $type .= "; charset=$default_text_plain_charset";
2472 ## ======================================================================
2473 ## functions printing HTML: header, footer, error page
2475 sub git_header_html
{
2476 my $status = shift || "200 OK";
2477 my $expires = shift;
2479 my $title = "$site_name";
2480 if (defined $project) {
2481 $title .= " - " . to_utf8
($project);
2482 if (defined $action) {
2483 $title .= "/$action";
2484 if (defined $file_name) {
2485 $title .= " - " . esc_path
($file_name);
2486 if ($action eq "tree" && $file_name !~ m
|/$|) {
2493 # require explicit support from the UA if we are to send the page as
2494 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2495 # we have to do this because MSIE sometimes globs '*/*', pretending to
2496 # support xhtml+xml but choking when it gets what it asked for.
2497 if (defined $cgi->http('HTTP_ACCEPT') &&
2498 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2499 $cgi->Accept('application/xhtml+xml') != 0) {
2500 $content_type = 'application/xhtml+xml';
2502 $content_type = 'text/html';
2504 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2505 -status
=> $status, -expires
=> $expires);
2506 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2508 <?xml version="1.0" encoding="utf-8"?>
2509 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2510 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2511 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2512 <!-- git core binaries version $git_version -->
2514 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2515 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2516 <meta name="robots" content="index, nofollow"/>
2517 <title>$title</title>
2519 # print out each stylesheet that exist
2520 if (defined $stylesheet) {
2521 #provides backwards capability for those people who define style sheet in a config file
2522 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2524 foreach my $stylesheet (@stylesheets) {
2525 next unless $stylesheet;
2526 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2529 if (defined $project) {
2530 my %href_params = get_feed_info
();
2531 if (!exists $href_params{'-title'}) {
2532 $href_params{'-title'} = 'log';
2535 foreach my $format qw(RSS Atom) {
2536 my $type = lc($format);
2538 '-rel' => 'alternate',
2539 '-title' => "$project - $href_params{'-title'} - $format feed",
2540 '-type' => "application/$type+xml"
2543 $href_params{'action'} = $type;
2544 $link_attr{'-href'} = href
(%href_params);
2546 "rel=\"$link_attr{'-rel'}\" ".
2547 "title=\"$link_attr{'-title'}\" ".
2548 "href=\"$link_attr{'-href'}\" ".
2549 "type=\"$link_attr{'-type'}\" ".
2552 $href_params{'extra_options'} = '--no-merges';
2553 $link_attr{'-href'} = href
(%href_params);
2554 $link_attr{'-title'} .= ' (no merges)';
2556 "rel=\"$link_attr{'-rel'}\" ".
2557 "title=\"$link_attr{'-title'}\" ".
2558 "href=\"$link_attr{'-href'}\" ".
2559 "type=\"$link_attr{'-type'}\" ".
2564 printf('<link rel="alternate" title="%s projects list" '.
2565 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2566 $site_name, href
(project
=>undef, action
=>"project_index"));
2567 printf('<link rel="alternate" title="%s projects feeds" '.
2568 'href="%s" type="text/x-opml" />'."\n",
2569 $site_name, href
(project
=>undef, action
=>"opml"));
2571 if (defined $favicon) {
2572 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2575 if (defined $gitwebjs) {
2576 print qq(<script src
="$gitwebjs" type
="text/javascript"></script
>\n);
2582 if (-f
$site_header) {
2583 open (my $fd, $site_header);
2588 print "<div class=\"page_header\">\n" .
2589 $cgi->a({-href
=> esc_url
($logo_url),
2590 -title
=> $logo_label},
2591 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2592 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2593 if (defined $project) {
2594 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2595 if (defined $action) {
2602 my ($have_search) = gitweb_check_feature
('search');
2603 if (defined $project && $have_search) {
2604 if (!defined $searchtext) {
2608 if (defined $hash_base) {
2609 $search_hash = $hash_base;
2610 } elsif (defined $hash) {
2611 $search_hash = $hash;
2613 $search_hash = "HEAD";
2615 my $action = $my_uri;
2616 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2617 if ($use_pathinfo) {
2618 $action .= "/".esc_url
($project);
2620 print $cgi->startform(-method
=> "get", -action
=> $action) .
2621 "<div class=\"search\">\n" .
2623 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2624 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2625 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2626 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2627 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2628 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2630 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2631 "<span title=\"Extended regular expression\">" .
2632 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2633 -checked
=> $search_use_regexp) .
2636 $cgi->end_form() . "\n";
2640 sub git_footer_html
{
2641 my $feed_class = 'rss_logo';
2643 print "<div class=\"page_footer\">\n";
2644 if (defined $project) {
2645 my $descr = git_get_project_description
($project);
2646 if (defined $descr) {
2647 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2650 my %href_params = get_feed_info
();
2651 if (!%href_params) {
2652 $feed_class .= ' generic';
2654 $href_params{'-title'} ||= 'log';
2656 foreach my $format qw(RSS Atom) {
2657 $href_params{'action'} = lc($format);
2658 print $cgi->a({-href
=> href
(%href_params),
2659 -title
=> "$href_params{'-title'} $format feed",
2660 -class => $feed_class}, $format)."\n";
2664 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2665 -class => $feed_class}, "OPML") . " ";
2666 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2667 -class => $feed_class}, "TXT") . "\n";
2669 print "</div>\n"; # class="page_footer"
2671 if (-f
$site_footer) {
2672 open (my $fd, $site_footer);
2681 # die_error(<http_status_code>, <error_message>)
2682 # Example: die_error(404, 'Hash not found')
2683 # By convention, use the following status codes (as defined in RFC 2616):
2684 # 400: Invalid or missing CGI parameters, or
2685 # requested object exists but has wrong type.
2686 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2687 # this server or project.
2688 # 404: Requested object/revision/project doesn't exist.
2689 # 500: The server isn't configured properly, or
2690 # an internal error occurred (e.g. failed assertions caused by bugs), or
2691 # an unknown error occurred (e.g. the git binary died unexpectedly).
2693 my $status = shift || 500;
2694 my $error = shift || "Internal server error";
2696 my %http_responses = (400 => '400 Bad Request',
2697 403 => '403 Forbidden',
2698 404 => '404 Not Found',
2699 500 => '500 Internal Server Error');
2700 git_header_html
($http_responses{$status});
2702 <div class="page_body">
2712 ## ----------------------------------------------------------------------
2713 ## functions printing or outputting HTML: navigation
2715 sub git_print_page_nav
{
2716 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2717 $extra = '' if !defined $extra; # pager or formats
2719 my @navs = qw(summary shortlog log commit commitdiff tree);
2721 @navs = grep { $_ ne $suppress } @navs;
2724 my %arg = map { $_ => {action
=>$_} } @navs;
2725 if (defined $head) {
2726 for (qw(commit commitdiff)) {
2727 $arg{$_}{'hash'} = $head;
2729 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2730 for (qw(shortlog log)) {
2731 $arg{$_}{'hash'} = $head;
2735 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2736 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2738 print "<div class=\"page_nav\">\n" .
2740 map { $_ eq $current ?
2741 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2743 print "<br/>\n$extra<br/>\n" .
2747 sub format_paging_nav
{
2748 my ($action, $hash, $head, $page, $has_next_link) = @_;
2752 if ($hash ne $head || $page) {
2753 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2755 $paging_nav .= "HEAD";
2759 $paging_nav .= " ⋅ " .
2760 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2761 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2763 $paging_nav .= " ⋅ prev";
2766 if ($has_next_link) {
2767 $paging_nav .= " ⋅ " .
2768 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2769 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2771 $paging_nav .= " ⋅ next";
2777 ## ......................................................................
2778 ## functions printing or outputting HTML: div
2780 sub git_print_header_div
{
2781 my ($action, $title, $hash, $hash_base) = @_;
2784 $args{'action'} = $action;
2785 $args{'hash'} = $hash if $hash;
2786 $args{'hash_base'} = $hash_base if $hash_base;
2788 print "<div class=\"header\">\n" .
2789 $cgi->a({-href
=> href
(%args), -class => "title"},
2790 $title ?
$title : $action) .
2794 #sub git_print_authorship (\%) {
2795 sub git_print_authorship
{
2798 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2799 print "<div class=\"author_date\">" .
2800 esc_html
($co->{'author_name'}) .
2802 if ($ad{'hour_local'} < 6) {
2803 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2804 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2806 printf(" (%02d:%02d %s)",
2807 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2812 sub git_print_page_path
{
2818 print "<div class=\"page_path\">";
2819 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2820 -title
=> 'tree root'}, to_utf8
("[$project]"));
2822 if (defined $name) {
2823 my @dirname = split '/', $name;
2824 my $basename = pop @dirname;
2827 foreach my $dir (@dirname) {
2828 $fullname .= ($fullname ?
'/' : '') . $dir;
2829 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2831 -title
=> $fullname}, esc_path
($dir));
2834 if (defined $type && $type eq 'blob') {
2835 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2837 -title
=> $name}, esc_path
($basename));
2838 } elsif (defined $type && $type eq 'tree') {
2839 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2841 -title
=> $name}, esc_path
($basename));
2844 print esc_path
($basename);
2847 print "<br/></div>\n";
2850 # sub git_print_log (\@;%) {
2851 sub git_print_log
($;%) {
2855 if ($opts{'-remove_title'}) {
2856 # remove title, i.e. first line of log
2859 # remove leading empty lines
2860 while (defined $log->[0] && $log->[0] eq "") {
2867 foreach my $line (@
$log) {
2868 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2871 if (! $opts{'-remove_signoff'}) {
2872 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2875 # remove signoff lines
2882 # print only one empty line
2883 # do not print empty line after signoff
2885 next if ($empty || $signoff);
2891 print format_log_line_html
($line) . "<br/>\n";
2894 if ($opts{'-final_empty_line'}) {
2895 # end with single empty line
2896 print "<br/>\n" unless $empty;
2900 # return link target (what link points to)
2901 sub git_get_link_target
{
2906 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2910 $link_target = <$fd>;
2915 return $link_target;
2918 # given link target, and the directory (basedir) the link is in,
2919 # return target of link relative to top directory (top tree);
2920 # return undef if it is not possible (including absolute links).
2921 sub normalize_link_target
{
2922 my ($link_target, $basedir, $hash_base) = @_;
2924 # we can normalize symlink target only if $hash_base is provided
2925 return unless $hash_base;
2927 # absolute symlinks (beginning with '/') cannot be normalized
2928 return if (substr($link_target, 0, 1) eq '/');
2930 # normalize link target to path from top (root) tree (dir)
2933 $path = $basedir . '/' . $link_target;
2935 # we are in top (root) tree (dir)
2936 $path = $link_target;
2939 # remove //, /./, and /../
2941 foreach my $part (split('/', $path)) {
2942 # discard '.' and ''
2943 next if (!$part || $part eq '.');
2945 if ($part eq '..') {
2949 # link leads outside repository (outside top dir)
2953 push @path_parts, $part;
2956 $path = join('/', @path_parts);
2961 # print tree entry (row of git_tree), but without encompassing <tr> element
2962 sub git_print_tree_entry
{
2963 my ($t, $basedir, $hash_base, $have_blame) = @_;
2966 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2968 # The format of a table row is: mode list link. Where mode is
2969 # the mode of the entry, list is the name of the entry, an href,
2970 # and link is the action links of the entry.
2972 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2973 if ($t->{'type'} eq "blob") {
2974 print "<td class=\"list\">" .
2975 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2976 file_name
=>"$basedir$t->{'name'}", %base_key),
2977 -class => "list"}, esc_path
($t->{'name'}));
2978 if (S_ISLNK
(oct $t->{'mode'})) {
2979 my $link_target = git_get_link_target
($t->{'hash'});
2981 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2982 if (defined $norm_target) {
2984 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2985 file_name
=>$norm_target),
2986 -title
=> $norm_target}, esc_path
($link_target));
2988 print " -> " . esc_path
($link_target);
2993 print "<td class=\"link\">";
2994 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2995 file_name
=>"$basedir$t->{'name'}", %base_key)},
2999 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3000 file_name
=>"$basedir$t->{'name'}", %base_key)},
3003 if (defined $hash_base) {
3005 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3006 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3010 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3011 file_name
=>"$basedir$t->{'name'}")},
3015 } elsif ($t->{'type'} eq "tree") {
3016 print "<td class=\"list\">";
3017 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3018 file_name
=>"$basedir$t->{'name'}", %base_key)},
3019 esc_path
($t->{'name'}));
3021 print "<td class=\"link\">";
3022 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3023 file_name
=>"$basedir$t->{'name'}", %base_key)},
3025 if (defined $hash_base) {
3027 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3028 file_name
=>"$basedir$t->{'name'}")},
3033 # unknown object: we can only present history for it
3034 # (this includes 'commit' object, i.e. submodule support)
3035 print "<td class=\"list\">" .
3036 esc_path
($t->{'name'}) .
3038 print "<td class=\"link\">";
3039 if (defined $hash_base) {
3040 print $cgi->a({-href
=> href
(action
=>"history",
3041 hash_base
=>$hash_base,
3042 file_name
=>"$basedir$t->{'name'}")},
3049 ## ......................................................................
3050 ## functions printing large fragments of HTML
3052 # get pre-image filenames for merge (combined) diff
3053 sub fill_from_file_info
{
3054 my ($diff, @parents) = @_;
3056 $diff->{'from_file'} = [ ];
3057 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3058 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3059 if ($diff->{'status'}[$i] eq 'R' ||
3060 $diff->{'status'}[$i] eq 'C') {
3061 $diff->{'from_file'}[$i] =
3062 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3069 # is current raw difftree line of file deletion
3071 my $diffinfo = shift;
3073 return $diffinfo->{'to_id'} eq ('0' x
40);
3076 # does patch correspond to [previous] difftree raw line
3077 # $diffinfo - hashref of parsed raw diff format
3078 # $patchinfo - hashref of parsed patch diff format
3079 # (the same keys as in $diffinfo)
3080 sub is_patch_split
{
3081 my ($diffinfo, $patchinfo) = @_;
3083 return defined $diffinfo && defined $patchinfo
3084 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3088 sub git_difftree_body
{
3089 my ($difftree, $hash, @parents) = @_;
3090 my ($parent) = $parents[0];
3091 my ($have_blame) = gitweb_check_feature
('blame');
3092 print "<div class=\"list_head\">\n";
3093 if ($#{$difftree} > 10) {
3094 print(($#{$difftree} + 1) . " files changed:\n");
3098 print "<table class=\"" .
3099 (@parents > 1 ?
"combined " : "") .
3102 # header only for combined diff in 'commitdiff' view
3103 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3106 print "<thead><tr>\n" .
3107 "<th></th><th></th>\n"; # filename, patchN link
3108 for (my $i = 0; $i < @parents; $i++) {
3109 my $par = $parents[$i];
3111 $cgi->a({-href
=> href
(action
=>"commitdiff",
3112 hash
=>$hash, hash_parent
=>$par),
3113 -title
=> 'commitdiff to parent number ' .
3114 ($i+1) . ': ' . substr($par,0,7)},
3118 print "</tr></thead>\n<tbody>\n";
3123 foreach my $line (@
{$difftree}) {
3124 my $diff = parsed_difftree_line
($line);
3127 print "<tr class=\"dark\">\n";
3129 print "<tr class=\"light\">\n";
3133 if (exists $diff->{'nparents'}) { # combined diff
3135 fill_from_file_info
($diff, @parents)
3136 unless exists $diff->{'from_file'};
3138 if (!is_deleted
($diff)) {
3139 # file exists in the result (child) commit
3141 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3142 file_name
=>$diff->{'to_file'},
3144 -class => "list"}, esc_path
($diff->{'to_file'})) .
3148 esc_path
($diff->{'to_file'}) .
3152 if ($action eq 'commitdiff') {
3155 print "<td class=\"link\">" .
3156 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3161 my $has_history = 0;
3162 my $not_deleted = 0;
3163 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3164 my $hash_parent = $parents[$i];
3165 my $from_hash = $diff->{'from_id'}[$i];
3166 my $from_path = $diff->{'from_file'}[$i];
3167 my $status = $diff->{'status'}[$i];
3169 $has_history ||= ($status ne 'A');
3170 $not_deleted ||= ($status ne 'D');
3172 if ($status eq 'A') {
3173 print "<td class=\"link\" align=\"right\"> | </td>\n";
3174 } elsif ($status eq 'D') {
3175 print "<td class=\"link\">" .
3176 $cgi->a({-href
=> href
(action
=>"blob",
3179 file_name
=>$from_path)},
3183 if ($diff->{'to_id'} eq $from_hash) {
3184 print "<td class=\"link nochange\">";
3186 print "<td class=\"link\">";
3188 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3189 hash
=>$diff->{'to_id'},
3190 hash_parent
=>$from_hash,
3192 hash_parent_base
=>$hash_parent,
3193 file_name
=>$diff->{'to_file'},
3194 file_parent
=>$from_path)},
3200 print "<td class=\"link\">";
3202 print $cgi->a({-href
=> href
(action
=>"blob",
3203 hash
=>$diff->{'to_id'},
3204 file_name
=>$diff->{'to_file'},
3207 print " | " if ($has_history);
3210 print $cgi->a({-href
=> href
(action
=>"history",
3211 file_name
=>$diff->{'to_file'},
3218 next; # instead of 'else' clause, to avoid extra indent
3220 # else ordinary diff
3222 my ($to_mode_oct, $to_mode_str, $to_file_type);
3223 my ($from_mode_oct, $from_mode_str, $from_file_type);
3224 if ($diff->{'to_mode'} ne ('0' x
6)) {
3225 $to_mode_oct = oct $diff->{'to_mode'};
3226 if (S_ISREG
($to_mode_oct)) { # only for regular file
3227 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3229 $to_file_type = file_type
($diff->{'to_mode'});
3231 if ($diff->{'from_mode'} ne ('0' x
6)) {
3232 $from_mode_oct = oct $diff->{'from_mode'};
3233 if (S_ISREG
($to_mode_oct)) { # only for regular file
3234 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3236 $from_file_type = file_type
($diff->{'from_mode'});
3239 if ($diff->{'status'} eq "A") { # created
3240 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3241 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3242 $mode_chng .= "]</span>";
3244 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3245 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3246 -class => "list"}, esc_path
($diff->{'file'}));
3248 print "<td>$mode_chng</td>\n";
3249 print "<td class=\"link\">";
3250 if ($action eq 'commitdiff') {
3253 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3256 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3257 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3261 } elsif ($diff->{'status'} eq "D") { # deleted
3262 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3264 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3265 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3266 -class => "list"}, esc_path
($diff->{'file'}));
3268 print "<td>$mode_chng</td>\n";
3269 print "<td class=\"link\">";
3270 if ($action eq 'commitdiff') {
3273 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3276 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3277 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3280 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3281 file_name
=>$diff->{'file'})},
3284 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3285 file_name
=>$diff->{'file'})},
3289 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3290 my $mode_chnge = "";
3291 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3292 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3293 if ($from_file_type ne $to_file_type) {
3294 $mode_chnge .= " from $from_file_type to $to_file_type";
3296 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3297 if ($from_mode_str && $to_mode_str) {
3298 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3299 } elsif ($to_mode_str) {
3300 $mode_chnge .= " mode: $to_mode_str";
3303 $mode_chnge .= "]</span>\n";
3306 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3307 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3308 -class => "list"}, esc_path
($diff->{'file'}));
3310 print "<td>$mode_chnge</td>\n";
3311 print "<td class=\"link\">";
3312 if ($action eq 'commitdiff') {
3315 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3317 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3318 # "commit" view and modified file (not onlu mode changed)
3319 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3320 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3321 hash_base
=>$hash, hash_parent_base
=>$parent,
3322 file_name
=>$diff->{'file'})},
3326 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3327 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3330 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3331 file_name
=>$diff->{'file'})},
3334 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3335 file_name
=>$diff->{'file'})},
3339 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3340 my %status_name = ('R' => 'moved', 'C' => 'copied');
3341 my $nstatus = $status_name{$diff->{'status'}};
3343 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3344 # mode also for directories, so we cannot use $to_mode_str
3345 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3348 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3349 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3350 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3351 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3352 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3353 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3354 -class => "list"}, esc_path
($diff->{'from_file'})) .
3355 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3356 "<td class=\"link\">";
3357 if ($action eq 'commitdiff') {
3360 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3362 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3363 # "commit" view and modified file (not only pure rename or copy)
3364 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3365 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3366 hash_base
=>$hash, hash_parent_base
=>$parent,
3367 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3371 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3372 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3375 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3376 file_name
=>$diff->{'to_file'})},
3379 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3380 file_name
=>$diff->{'to_file'})},
3384 } # we should not encounter Unmerged (U) or Unknown (X) status
3387 print "</tbody>" if $has_header;
3391 sub git_patchset_body
{
3392 my ($fd, $difftree, $hash, @hash_parents) = @_;
3393 my ($hash_parent) = $hash_parents[0];
3395 my $is_combined = (@hash_parents > 1);
3397 my $patch_number = 0;
3403 print "<div class=\"patchset\">\n";
3405 # skip to first patch
3406 while ($patch_line = <$fd>) {
3409 last if ($patch_line =~ m/^diff /);
3413 while ($patch_line) {
3415 # parse "git diff" header line
3416 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3417 # $1 is from_name, which we do not use
3418 $to_name = unquote
($2);
3419 $to_name =~ s!^b/!!;
3420 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3421 # $1 is 'cc' or 'combined', which we do not use
3422 $to_name = unquote
($2);
3427 # check if current patch belong to current raw line
3428 # and parse raw git-diff line if needed
3429 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3430 # this is continuation of a split patch
3431 print "<div class=\"patch cont\">\n";
3433 # advance raw git-diff output if needed
3434 $patch_idx++ if defined $diffinfo;
3436 # read and prepare patch information
3437 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3439 # compact combined diff output can have some patches skipped
3440 # find which patch (using pathname of result) we are at now;
3442 while ($to_name ne $diffinfo->{'to_file'}) {
3443 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3444 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3445 "</div>\n"; # class="patch"
3450 last if $patch_idx > $#$difftree;
3451 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3455 # modifies %from, %to hashes
3456 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3458 # this is first patch for raw difftree line with $patch_idx index
3459 # we index @$difftree array from 0, but number patches from 1
3460 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3464 #assert($patch_line =~ m/^diff /) if DEBUG;
3465 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3467 # print "git diff" header
3468 print format_git_diff_header_line
($patch_line, $diffinfo,
3471 # print extended diff header
3472 print "<div class=\"diff extended_header\">\n";
3474 while ($patch_line = <$fd>) {
3477 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3479 print format_extended_diff_header_line
($patch_line, $diffinfo,
3482 print "</div>\n"; # class="diff extended_header"
3484 # from-file/to-file diff header
3485 if (! $patch_line) {
3486 print "</div>\n"; # class="patch"
3489 next PATCH
if ($patch_line =~ m/^diff /);
3490 #assert($patch_line =~ m/^---/) if DEBUG;
3492 my $last_patch_line = $patch_line;
3493 $patch_line = <$fd>;
3495 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3497 print format_diff_from_to_header
($last_patch_line, $patch_line,
3498 $diffinfo, \
%from, \
%to,
3503 while ($patch_line = <$fd>) {
3506 next PATCH
if ($patch_line =~ m/^diff /);
3508 print format_diff_line
($patch_line, \
%from, \
%to);
3512 print "</div>\n"; # class="patch"
3515 # for compact combined (--cc) format, with chunk and patch simpliciaction
3516 # patchset might be empty, but there might be unprocessed raw lines
3517 for (++$patch_idx if $patch_number > 0;
3518 $patch_idx < @
$difftree;
3520 # read and prepare patch information
3521 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3523 # generate anchor for "patch" links in difftree / whatchanged part
3524 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3525 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3526 "</div>\n"; # class="patch"
3531 if ($patch_number == 0) {
3532 if (@hash_parents > 1) {
3533 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3535 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3539 print "</div>\n"; # class="patchset"
3542 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3544 # fills project list info (age, description, owner, forks) for each
3545 # project in the list, removing invalid projects from returned list
3546 # NOTE: modifies $projlist, but does not remove entries from it
3547 sub fill_project_list_info
{
3548 my ($projlist, $check_forks) = @_;
3552 foreach my $pr (@
$projlist) {
3553 my (@activity) = git_get_last_activity
($pr->{'path'});
3554 unless (@activity) {
3557 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3558 if (!defined $pr->{'descr'}) {
3559 my $descr = git_get_project_description
($pr->{'path'}) || "";
3560 $descr = to_utf8
($descr);
3561 $pr->{'descr_long'} = $descr;
3562 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3564 if (!defined $pr->{'owner'}) {
3565 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3568 my $pname = $pr->{'path'};
3569 if (($pname =~ s/\.git$//) &&
3570 ($pname !~ /\/$/) &&
3571 (-d
"$projectroot/$pname")) {
3572 $pr->{'forks'} = "-d $projectroot/$pname";
3577 push @projects, $pr;
3583 # print 'sort by' <th> element, either sorting by $key if $name eq $order
3584 # (changing $list), or generating 'sort by $name' replay link otherwise
3586 my ($str_sort, $name, $order, $key, $header, $list) = @_;
3588 $header ||= ucfirst($name);
3590 if ($order eq $name) {
3592 @
$list = sort {$a->{$key} cmp $b->{$key}} @
$list;
3594 @
$list = sort {$a->{$key} <=> $b->{$key}} @
$list;
3596 print "<th>$header</th>\n";
3599 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3600 -class => "header"}, $header) .
3605 sub print_sort_th_str
{
3606 print_sort_th
(1, @_);
3609 sub print_sort_th_num
{
3610 print_sort_th
(0, @_);
3613 sub git_project_list_body
{
3614 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3616 my ($check_forks) = gitweb_check_feature
('forks');
3617 my @projects = fill_project_list_info
($projlist, $check_forks);
3619 $order ||= $default_projects_order;
3620 $from = 0 unless defined $from;
3621 $to = $#projects if (!defined $to || $#projects < $to);
3623 print "<table class=\"project_list\">\n";
3624 unless ($no_header) {
3627 print "<th></th>\n";
3629 print_sort_th_str
('project', $order, 'path',
3630 'Project', \
@projects);
3631 print_sort_th_str
('descr', $order, 'descr_long',
3632 'Description', \
@projects);
3633 print_sort_th_str
('owner', $order, 'owner',
3634 'Owner', \
@projects);
3635 print_sort_th_num
('age', $order, 'age',
3636 'Last Change', \
@projects);
3637 print "<th></th>\n" . # for links
3641 for (my $i = $from; $i <= $to; $i++) {
3642 my $pr = $projects[$i];
3644 print "<tr class=\"dark\">\n";
3646 print "<tr class=\"light\">\n";
3651 if ($pr->{'forks'}) {
3652 print "<!-- $pr->{'forks'} -->\n";
3653 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3657 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3658 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3659 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3660 -class => "list", -title
=> $pr->{'descr_long'}},
3661 esc_html
($pr->{'descr'})) . "</td>\n" .
3662 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3663 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3664 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3665 "<td class=\"link\">" .
3666 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3667 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3668 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3669 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3670 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3674 if (defined $extra) {
3677 print "<td></td>\n";
3679 print "<td colspan=\"5\">$extra</td>\n" .
3685 sub git_shortlog_body
{
3686 # uses global variable $project
3687 my ($commitlist, $from, $to, $refs, $extra) = @_;
3689 $from = 0 unless defined $from;
3690 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3692 print "<table class=\"shortlog\">\n";
3694 for (my $i = $from; $i <= $to; $i++) {
3695 my %co = %{$commitlist->[$i]};
3696 my $commit = $co{'id'};
3697 my $ref = format_ref_marker
($refs, $commit);
3699 print "<tr class=\"dark\">\n";
3701 print "<tr class=\"light\">\n";
3704 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3705 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3706 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3707 "<td><i>" . $author . "</i></td>\n" .
3709 print format_subject_html
($co{'title'}, $co{'title_short'},
3710 href
(action
=>"commit", hash
=>$commit), $ref);
3712 "<td class=\"link\">" .
3713 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3714 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3715 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3716 my $snapshot_links = format_snapshot_links
($commit);
3717 if (defined $snapshot_links) {
3718 print " | " . $snapshot_links;
3723 if (defined $extra) {
3725 "<td colspan=\"4\">$extra</td>\n" .
3731 sub git_history_body
{
3732 # Warning: assumes constant type (blob or tree) during history
3733 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3735 $from = 0 unless defined $from;
3736 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3738 print "<table class=\"history\">\n";
3740 for (my $i = $from; $i <= $to; $i++) {
3741 my %co = %{$commitlist->[$i]};
3745 my $commit = $co{'id'};
3747 my $ref = format_ref_marker
($refs, $commit);
3750 print "<tr class=\"dark\">\n";
3752 print "<tr class=\"light\">\n";
3755 # shortlog uses chop_str($co{'author_name'}, 10)
3756 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3757 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3758 "<td><i>" . $author . "</i></td>\n" .
3760 # originally git_history used chop_str($co{'title'}, 50)
3761 print format_subject_html
($co{'title'}, $co{'title_short'},
3762 href
(action
=>"commit", hash
=>$commit), $ref);
3764 "<td class=\"link\">" .
3765 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3766 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3768 if ($ftype eq 'blob') {
3769 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3770 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3771 if (defined $blob_current && defined $blob_parent &&
3772 $blob_current ne $blob_parent) {
3774 $cgi->a({-href
=> href
(action
=>"blobdiff",
3775 hash
=>$blob_current, hash_parent
=>$blob_parent,
3776 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3777 file_name
=>$file_name)},
3784 if (defined $extra) {
3786 "<td colspan=\"4\">$extra</td>\n" .
3793 # uses global variable $project
3794 my ($taglist, $from, $to, $extra) = @_;
3795 $from = 0 unless defined $from;
3796 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3798 print "<table class=\"tags\">\n";
3800 for (my $i = $from; $i <= $to; $i++) {
3801 my $entry = $taglist->[$i];
3803 my $comment = $tag{'subject'};
3805 if (defined $comment) {
3806 $comment_short = chop_str
($comment, 30, 5);
3809 print "<tr class=\"dark\">\n";
3811 print "<tr class=\"light\">\n";
3814 if (defined $tag{'age'}) {
3815 print "<td><i>$tag{'age'}</i></td>\n";
3817 print "<td></td>\n";
3820 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3821 -class => "list name"}, esc_html
($tag{'name'})) .
3824 if (defined $comment) {
3825 print format_subject_html
($comment, $comment_short,
3826 href
(action
=>"tag", hash
=>$tag{'id'}));
3829 "<td class=\"selflink\">";
3830 if ($tag{'type'} eq "tag") {
3831 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3836 "<td class=\"link\">" . " | " .
3837 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3838 if ($tag{'reftype'} eq "commit") {
3839 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3840 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3841 } elsif ($tag{'reftype'} eq "blob") {
3842 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3847 if (defined $extra) {
3849 "<td colspan=\"5\">$extra</td>\n" .
3855 sub git_heads_body
{
3856 # uses global variable $project
3857 my ($headlist, $head, $from, $to, $extra) = @_;
3858 $from = 0 unless defined $from;
3859 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3861 print "<table class=\"heads\">\n";
3863 for (my $i = $from; $i <= $to; $i++) {
3864 my $entry = $headlist->[$i];
3866 my $curr = $ref{'id'} eq $head;
3868 print "<tr class=\"dark\">\n";
3870 print "<tr class=\"light\">\n";
3873 print "<td><i>$ref{'age'}</i></td>\n" .
3874 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3875 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3876 -class => "list name"},esc_html
($ref{'name'})) .
3878 "<td class=\"link\">" .
3879 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3880 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3881 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3885 if (defined $extra) {
3887 "<td colspan=\"3\">$extra</td>\n" .
3893 sub git_search_grep_body
{
3894 my ($commitlist, $from, $to, $extra) = @_;
3895 $from = 0 unless defined $from;
3896 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3898 print "<table class=\"commit_search\">\n";
3900 for (my $i = $from; $i <= $to; $i++) {
3901 my %co = %{$commitlist->[$i]};
3905 my $commit = $co{'id'};
3907 print "<tr class=\"dark\">\n";
3909 print "<tr class=\"light\">\n";
3912 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3913 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3914 "<td><i>" . $author . "</i></td>\n" .
3916 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3917 -class => "list subject"},
3918 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3919 my $comment = $co{'comment'};
3920 foreach my $line (@
$comment) {
3921 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3922 my ($lead, $match, $trail) = ($1, $2, $3);
3923 $match = chop_str
($match, 70, 5, 'center');
3924 my $contextlen = int((80 - length($match))/2);
3925 $contextlen = 30 if ($contextlen > 30);
3926 $lead = chop_str
($lead, $contextlen, 10, 'left');
3927 $trail = chop_str
($trail, $contextlen, 10, 'right');
3929 $lead = esc_html
($lead);
3930 $match = esc_html
($match);
3931 $trail = esc_html
($trail);
3933 print "$lead<span class=\"match\">$match</span>$trail<br />";
3937 "<td class=\"link\">" .
3938 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3940 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3942 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3946 if (defined $extra) {
3948 "<td colspan=\"3\">$extra</td>\n" .
3954 ## ======================================================================
3955 ## ======================================================================
3958 sub git_project_list
{
3959 my $order = $cgi->param('o');
3960 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3961 die_error
(400, "Unknown order parameter");
3964 my @list = git_get_projects_list
();
3966 die_error
(404, "No projects found");
3970 if (-f
$home_text) {
3971 print "<div class=\"index_include\">\n";
3972 open (my $fd, $home_text);
3977 git_project_list_body
(\
@list, $order);
3982 my $order = $cgi->param('o');
3983 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3984 die_error
(400, "Unknown order parameter");
3987 my @list = git_get_projects_list
($project);
3989 die_error
(404, "No forks found");
3993 git_print_page_nav
('','');
3994 git_print_header_div
('summary', "$project forks");
3995 git_project_list_body
(\
@list, $order);
3999 sub git_project_index
{
4000 my @projects = git_get_projects_list
($project);
4003 -type
=> 'text/plain',
4004 -charset
=> 'utf-8',
4005 -content_disposition
=> 'inline; filename="index.aux"');
4007 foreach my $pr (@projects) {
4008 if (!exists $pr->{'owner'}) {
4009 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4012 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4013 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4014 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4015 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4019 print "$path $owner\n";
4024 my $descr = git_get_project_description
($project) || "none";
4025 my %co = parse_commit
("HEAD");
4026 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4027 my $head = $co{'id'};
4029 my $owner = git_get_project_owner
($project);
4031 my $refs = git_get_references
();
4032 # These get_*_list functions return one more to allow us to see if
4033 # there are more ...
4034 my @taglist = git_get_tags_list
(16);
4035 my @headlist = git_get_heads_list
(16);
4037 my ($check_forks) = gitweb_check_feature
('forks');
4040 @forklist = git_get_projects_list
($project);
4044 git_print_page_nav
('summary','', $head);
4046 print "<div class=\"title\"> </div>\n";
4047 print "<table class=\"projects_list\">\n" .
4048 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4049 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4050 if (defined $cd{'rfc2822'}) {
4051 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4054 # use per project git URL list in $projectroot/$project/cloneurl
4055 # or make project git URL from git base URL and project name
4056 my $url_tag = "URL";
4057 my @url_list = git_get_project_url_list
($project);
4058 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4059 foreach my $git_url (@url_list) {
4060 next unless $git_url;
4061 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4066 if (-s
"$projectroot/$project/README.html") {
4067 if (open my $fd, "$projectroot/$project/README.html") {
4068 print "<div class=\"title\">readme</div>\n" .
4069 "<div class=\"readme\">\n";
4070 print $_ while (<$fd>);
4071 print "\n</div>\n"; # class="readme"
4076 # we need to request one more than 16 (0..15) to check if
4078 my @commitlist = $head ? parse_commits
($head, 17) : ();
4080 git_print_header_div
('shortlog');
4081 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4082 $#commitlist <= 15 ?
undef :
4083 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4087 git_print_header_div
('tags');
4088 git_tags_body
(\
@taglist, 0, 15,
4089 $#taglist <= 15 ?
undef :
4090 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4094 git_print_header_div
('heads');
4095 git_heads_body
(\
@headlist, $head, 0, 15,
4096 $#headlist <= 15 ?
undef :
4097 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4101 git_print_header_div
('forks');
4102 git_project_list_body
(\
@forklist, undef, 0, 15,
4103 $#forklist <= 15 ?
undef :
4104 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4112 my $head = git_get_head_hash
($project);
4114 git_print_page_nav
('','', $head,undef,$head);
4115 my %tag = parse_tag
($hash);
4118 die_error
(404, "Unknown tag object");
4121 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4122 print "<div class=\"title_text\">\n" .
4123 "<table class=\"object_header\">\n" .
4125 "<td>object</td>\n" .
4126 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4127 $tag{'object'}) . "</td>\n" .
4128 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4129 $tag{'type'}) . "</td>\n" .
4131 if (defined($tag{'author'})) {
4132 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4133 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4134 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4135 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4138 print "</table>\n\n" .
4140 print "<div class=\"page_body\">";
4141 my $comment = $tag{'comment'};
4142 foreach my $line (@
$comment) {
4144 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4154 gitweb_check_feature
('blame')
4155 or die_error
(403, "Blame view not allowed");
4157 die_error
(400, "No file name given") unless $file_name;
4158 $hash_base ||= git_get_head_hash
($project);
4159 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4160 my %co = parse_commit
($hash_base)
4161 or die_error
(404, "Commit not found");
4162 if (!defined $hash) {
4163 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4164 or die_error
(404, "Error looking up file");
4166 $ftype = git_get_type
($hash);
4167 if ($ftype !~ "blob") {
4168 die_error
(400, "Object is not a blob");
4170 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4171 $file_name, $hash_base)
4172 or die_error
(500, "Open git-blame failed");
4175 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4178 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4181 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4183 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4184 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4185 git_print_page_path
($file_name, $ftype, $hash_base);
4186 my @rev_color = (qw(light2 dark2));
4187 my $num_colors = scalar(@rev_color);
4188 my $current_color = 0;
4191 <div class="page_body">
4192 <table class="blame">
4193 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4198 last unless defined $_;
4199 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4200 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4201 if (!exists $metainfo{$full_rev}) {
4202 $metainfo{$full_rev} = {};
4204 my $meta = $metainfo{$full_rev};
4207 if (/^(\S+) (.*)$/) {
4213 my $rev = substr($full_rev, 0, 8);
4214 my $author = $meta->{'author'};
4215 my %date = parse_date
($meta->{'author-time'},
4216 $meta->{'author-tz'});
4217 my $date = $date{'iso-tz'};
4219 $current_color = ++$current_color % $num_colors;
4221 print "<tr class=\"$rev_color[$current_color]\">\n";
4223 print "<td class=\"sha1\"";
4224 print " title=\"". esc_html
($author) . ", $date\"";
4225 print " rowspan=\"$group_size\"" if ($group_size > 1);
4227 print $cgi->a({-href
=> href
(action
=>"commit",
4229 file_name
=>$file_name)},
4233 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4234 or die_error
(500, "Open git-rev-parse failed");
4235 my $parent_commit = <$dd>;
4237 chomp($parent_commit);
4238 my $blamed = href
(action
=> 'blame',
4239 file_name
=> $meta->{'filename'},
4240 hash_base
=> $parent_commit);
4241 print "<td class=\"linenr\">";
4242 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4244 -class => "linenr" },
4247 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4253 or print "Reading blob failed\n";
4258 my $head = git_get_head_hash
($project);
4260 git_print_page_nav
('','', $head,undef,$head);
4261 git_print_header_div
('summary', $project);
4263 my @tagslist = git_get_tags_list
();
4265 git_tags_body
(\
@tagslist);
4271 my $head = git_get_head_hash
($project);
4273 git_print_page_nav
('','', $head,undef,$head);
4274 git_print_header_div
('summary', $project);
4276 my @headslist = git_get_heads_list
();
4278 git_heads_body
(\
@headslist, $head);
4283 sub git_blob_plain
{
4287 if (!defined $hash) {
4288 if (defined $file_name) {
4289 my $base = $hash_base || git_get_head_hash
($project);
4290 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4291 or die_error
(404, "Cannot find file");
4293 die_error
(400, "No file name defined");
4295 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4296 # blobs defined by non-textual hash id's can be cached
4300 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4301 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4303 # content-type (can include charset)
4304 $type = blob_contenttype
($fd, $file_name, $type);
4306 # "save as" filename, even when no $file_name is given
4307 my $save_as = "$hash";
4308 if (defined $file_name) {
4309 $save_as = $file_name;
4310 } elsif ($type =~ m/^text\//) {
4316 -expires
=> $expires,
4317 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4319 binmode STDOUT
, ':raw';
4321 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4329 if (!defined $hash) {
4330 if (defined $file_name) {
4331 my $base = $hash_base || git_get_head_hash
($project);
4332 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4333 or die_error
(404, "Cannot find file");
4335 die_error
(400, "No file name defined");
4337 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4338 # blobs defined by non-textual hash id's can be cached
4342 my ($have_blame) = gitweb_check_feature
('blame');
4343 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4344 or die_error
(500, "Couldn't cat $file_name, $hash");
4345 my $mimetype = blob_mimetype
($fd, $file_name);
4346 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4348 return git_blob_plain
($mimetype);
4350 # we can have blame only for text/* mimetype
4351 $have_blame &&= ($mimetype =~ m!^text/!);
4353 git_header_html
(undef, $expires);
4354 my $formats_nav = '';
4355 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4356 if (defined $file_name) {
4359 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4364 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4367 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4370 $cgi->a({-href
=> href
(action
=>"blob",
4371 hash_base
=>"HEAD", file_name
=>$file_name)},
4375 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4378 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4379 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4381 print "<div class=\"page_nav\">\n" .
4382 "<br/><br/></div>\n" .
4383 "<div class=\"title\">$hash</div>\n";
4385 git_print_page_path
($file_name, "blob", $hash_base);
4386 print "<div class=\"page_body\">\n";
4387 if ($mimetype =~ m!^image/!) {
4388 print qq!<img type
="$mimetype"!;
4390 print qq! alt
="$file_name" title
="$file_name"!;
4393 href(action=>"blob_plain
", hash=>$hash,
4394 hash_base=>$hash_base, file_name=>$file_name) .
4398 while (my $line = <$fd>) {
4401 $line = untabify
($line);
4402 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4403 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4407 or print "Reading blob failed.\n";
4413 if (!defined $hash_base) {
4414 $hash_base = "HEAD";
4416 if (!defined $hash) {
4417 if (defined $file_name) {
4418 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4424 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4425 or die_error
(500, "Open git-ls-tree failed");
4426 my @entries = map { chomp; $_ } <$fd>;
4427 close $fd or die_error
(404, "Reading tree failed");
4430 my $refs = git_get_references
();
4431 my $ref = format_ref_marker
($refs, $hash_base);
4434 my ($have_blame) = gitweb_check_feature
('blame');
4435 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4437 if (defined $file_name) {
4439 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4441 $cgi->a({-href
=> href
(action
=>"tree",
4442 hash_base
=>"HEAD", file_name
=>$file_name)},
4445 my $snapshot_links = format_snapshot_links
($hash);
4446 if (defined $snapshot_links) {
4447 # FIXME: Should be available when we have no hash base as well.
4448 push @views_nav, $snapshot_links;
4450 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4451 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4454 print "<div class=\"page_nav\">\n";
4455 print "<br/><br/></div>\n";
4456 print "<div class=\"title\">$hash</div>\n";
4458 if (defined $file_name) {
4459 $basedir = $file_name;
4460 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4464 git_print_page_path
($file_name, 'tree', $hash_base);
4465 print "<div class=\"page_body\">\n";
4466 print "<table class=\"tree\">\n";
4468 # '..' (top directory) link if possible
4469 if (defined $hash_base &&
4470 defined $file_name && $file_name =~ m![^/]+$!) {
4472 print "<tr class=\"dark\">\n";
4474 print "<tr class=\"light\">\n";
4478 my $up = $file_name;
4479 $up =~ s!/?[^/]+$!!;
4480 undef $up unless $up;
4481 # based on git_print_tree_entry
4482 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4483 print '<td class="list">';
4484 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4488 print "<td class=\"link\"></td>\n";
4492 foreach my $line (@entries) {
4493 my %t = parse_ls_tree_line
($line, -z
=> 1);
4496 print "<tr class=\"dark\">\n";
4498 print "<tr class=\"light\">\n";
4502 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4506 print "</table>\n" .
4512 my @supported_fmts = gitweb_check_feature
('snapshot');
4513 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4515 my $format = $cgi->param('sf');
4516 if (!@supported_fmts) {
4517 die_error
(403, "Snapshots not allowed");
4519 # default to first supported snapshot format
4520 $format ||= $supported_fmts[0];
4521 if ($format !~ m/^[a-z0-9]+$/) {
4522 die_error
(400, "Invalid snapshot format parameter");
4523 } elsif (!exists($known_snapshot_formats{$format})) {
4524 die_error
(400, "Unknown snapshot format");
4525 } elsif (!grep($_ eq $format, @supported_fmts)) {
4526 die_error
(403, "Unsupported snapshot format");
4529 if (!defined $hash) {
4530 $hash = git_get_head_hash
($project);
4533 my $name = $project;
4534 $name =~ s
,([^/])/*\
.git
$,$1,;
4535 $name = basename
($name);
4536 my $filename = to_utf8
($name);
4537 $name =~ s/\047/\047\\\047\047/g;
4539 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4540 $cmd = quote_command
(
4541 git_cmd
(), 'archive',
4542 "--format=$known_snapshot_formats{$format}{'format'}",
4543 "--prefix=$name/", $hash);
4544 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4545 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4549 -type
=> $known_snapshot_formats{$format}{'type'},
4550 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4551 -status
=> '200 OK');
4553 open my $fd, "-|", $cmd
4554 or die_error
(500, "Execute git-archive failed");
4555 binmode STDOUT
, ':raw';
4557 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4562 my $head = git_get_head_hash
($project);
4563 if (!defined $hash) {
4566 if (!defined $page) {
4569 my $refs = git_get_references
();
4571 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4573 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4576 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4579 my %co = parse_commit
($hash);
4581 git_print_header_div
('summary', $project);
4582 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4584 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4585 for (my $i = 0; $i <= $to; $i++) {
4586 my %co = %{$commitlist[$i]};
4588 my $commit = $co{'id'};
4589 my $ref = format_ref_marker
($refs, $commit);
4590 my %ad = parse_date
($co{'author_epoch'});
4591 git_print_header_div
('commit',
4592 "<span class=\"age\">$co{'age_string'}</span>" .
4593 esc_html
($co{'title'}) . $ref,
4595 print "<div class=\"title_text\">\n" .
4596 "<div class=\"log_link\">\n" .
4597 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4599 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4601 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4604 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4607 print "<div class=\"log_body\">\n";
4608 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4611 if ($#commitlist >= 100) {
4612 print "<div class=\"page_nav\">\n";
4613 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4614 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4621 $hash ||= $hash_base || "HEAD";
4622 my %co = parse_commit
($hash)
4623 or die_error
(404, "Unknown commit object");
4624 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4625 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4627 my $parent = $co{'parent'};
4628 my $parents = $co{'parents'}; # listref
4630 # we need to prepare $formats_nav before any parameter munging
4632 if (!defined $parent) {
4634 $formats_nav .= '(initial)';
4635 } elsif (@
$parents == 1) {
4636 # single parent commit
4639 $cgi->a({-href
=> href
(action
=>"commit",
4641 esc_html
(substr($parent, 0, 7))) .
4648 $cgi->a({-href
=> href
(action
=>"commit",
4650 esc_html
(substr($_, 0, 7)));
4655 if (!defined $parent) {
4659 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4661 (@
$parents <= 1 ?
$parent : '-c'),
4663 or die_error
(500, "Open git-diff-tree failed");
4664 @difftree = map { chomp; $_ } <$fd>;
4665 close $fd or die_error
(404, "Reading git-diff-tree failed");
4667 # non-textual hash id's can be cached
4669 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4672 my $refs = git_get_references
();
4673 my $ref = format_ref_marker
($refs, $co{'id'});
4675 git_header_html
(undef, $expires);
4676 git_print_page_nav
('commit', '',
4677 $hash, $co{'tree'}, $hash,
4680 if (defined $co{'parent'}) {
4681 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4683 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4685 print "<div class=\"title_text\">\n" .
4686 "<table class=\"object_header\">\n";
4687 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4689 "<td></td><td> $ad{'rfc2822'}";
4690 if ($ad{'hour_local'} < 6) {
4691 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4692 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4694 printf(" (%02d:%02d %s)",
4695 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4699 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4700 print "<tr><td></td><td> $cd{'rfc2822'}" .
4701 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4703 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4706 "<td class=\"sha1\">" .
4707 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4708 class => "list"}, $co{'tree'}) .
4710 "<td class=\"link\">" .
4711 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4713 my $snapshot_links = format_snapshot_links
($hash);
4714 if (defined $snapshot_links) {
4715 print " | " . $snapshot_links;
4720 foreach my $par (@
$parents) {
4723 "<td class=\"sha1\">" .
4724 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4725 class => "list"}, $par) .
4727 "<td class=\"link\">" .
4728 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4730 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4737 print "<div class=\"page_body\">\n";
4738 git_print_log
($co{'comment'});
4741 git_difftree_body
(\
@difftree, $hash, @
$parents);
4747 # object is defined by:
4748 # - hash or hash_base alone
4749 # - hash_base and file_name
4752 # - hash or hash_base alone
4753 if ($hash || ($hash_base && !defined $file_name)) {
4754 my $object_id = $hash || $hash_base;
4756 open my $fd, "-|", quote_command
(
4757 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4758 or die_error
(404, "Object does not exist");
4762 or die_error
(404, "Object does not exist");
4764 # - hash_base and file_name
4765 } elsif ($hash_base && defined $file_name) {
4766 $file_name =~ s
,/+$,,;
4768 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4769 or die_error
(404, "Base object does not exist");
4771 # here errors should not hapen
4772 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4773 or die_error
(500, "Open git-ls-tree failed");
4777 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4778 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4779 die_error
(404, "File or directory for given base does not exist");
4784 die_error
(400, "Not enough information to find object");
4787 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4788 hash
=>$hash, hash_base
=>$hash_base,
4789 file_name
=>$file_name),
4790 -status
=> '302 Found');
4794 my $format = shift || 'html';
4801 # preparing $fd and %diffinfo for git_patchset_body
4803 if (defined $hash_base && defined $hash_parent_base) {
4804 if (defined $file_name) {
4806 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4807 $hash_parent_base, $hash_base,
4808 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4809 or die_error
(500, "Open git-diff-tree failed");
4810 @difftree = map { chomp; $_ } <$fd>;
4812 or die_error
(404, "Reading git-diff-tree failed");
4814 or die_error
(404, "Blob diff not found");
4816 } elsif (defined $hash &&
4817 $hash =~ /[0-9a-fA-F]{40}/) {
4818 # try to find filename from $hash
4820 # read filtered raw output
4821 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4822 $hash_parent_base, $hash_base, "--"
4823 or die_error
(500, "Open git-diff-tree failed");
4825 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4827 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4828 map { chomp; $_ } <$fd>;
4830 or die_error
(404, "Reading git-diff-tree failed");
4832 or die_error
(404, "Blob diff not found");
4835 die_error
(400, "Missing one of the blob diff parameters");
4838 if (@difftree > 1) {
4839 die_error
(400, "Ambiguous blob diff specification");
4842 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4843 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4844 $file_name ||= $diffinfo{'to_file'};
4846 $hash_parent ||= $diffinfo{'from_id'};
4847 $hash ||= $diffinfo{'to_id'};
4849 # non-textual hash id's can be cached
4850 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4851 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4856 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4857 '-p', ($format eq 'html' ?
"--full-index" : ()),
4858 $hash_parent_base, $hash_base,
4859 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4860 or die_error
(500, "Open git-diff-tree failed");
4863 # old/legacy style URI
4864 if (!%diffinfo && # if new style URI failed
4865 defined $hash && defined $hash_parent) {
4866 # fake git-diff-tree raw output
4867 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4868 $diffinfo{'from_id'} = $hash_parent;
4869 $diffinfo{'to_id'} = $hash;
4870 if (defined $file_name) {
4871 if (defined $file_parent) {
4872 $diffinfo{'status'} = '2';
4873 $diffinfo{'from_file'} = $file_parent;
4874 $diffinfo{'to_file'} = $file_name;
4875 } else { # assume not renamed
4876 $diffinfo{'status'} = '1';
4877 $diffinfo{'from_file'} = $file_name;
4878 $diffinfo{'to_file'} = $file_name;
4880 } else { # no filename given
4881 $diffinfo{'status'} = '2';
4882 $diffinfo{'from_file'} = $hash_parent;
4883 $diffinfo{'to_file'} = $hash;
4886 # non-textual hash id's can be cached
4887 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4888 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4893 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4894 '-p', ($format eq 'html' ?
"--full-index" : ()),
4895 $hash_parent, $hash, "--"
4896 or die_error
(500, "Open git-diff failed");
4898 die_error
(400, "Missing one of the blob diff parameters")
4903 if ($format eq 'html') {
4905 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4907 git_header_html
(undef, $expires);
4908 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4909 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4910 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4912 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4913 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4915 if (defined $file_name) {
4916 git_print_page_path
($file_name, "blob", $hash_base);
4918 print "<div class=\"page_path\"></div>\n";
4921 } elsif ($format eq 'plain') {
4923 -type
=> 'text/plain',
4924 -charset
=> 'utf-8',
4925 -expires
=> $expires,
4926 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4928 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4931 die_error
(400, "Unknown blobdiff format");
4935 if ($format eq 'html') {
4936 print "<div class=\"page_body\">\n";
4938 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4941 print "</div>\n"; # class="page_body"
4945 while (my $line = <$fd>) {
4946 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4947 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4951 last if $line =~ m!^\+\+\+!;
4959 sub git_blobdiff_plain
{
4960 git_blobdiff
('plain');
4963 sub git_commitdiff
{
4964 my $format = shift || 'html';
4965 $hash ||= $hash_base || "HEAD";
4966 my %co = parse_commit
($hash)
4967 or die_error
(404, "Unknown commit object");
4969 # choose format for commitdiff for merge
4970 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
4971 $hash_parent = '--cc';
4973 # we need to prepare $formats_nav before almost any parameter munging
4975 if ($format eq 'html') {
4977 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4980 if (defined $hash_parent &&
4981 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4982 # commitdiff with two commits given
4983 my $hash_parent_short = $hash_parent;
4984 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4985 $hash_parent_short = substr($hash_parent, 0, 7);
4989 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
4990 if ($co{'parents'}[$i] eq $hash_parent) {
4991 $formats_nav .= ' parent ' . ($i+1);
4995 $formats_nav .= ': ' .
4996 $cgi->a({-href
=> href
(action
=>"commitdiff",
4997 hash
=>$hash_parent)},
4998 esc_html
($hash_parent_short)) .
5000 } elsif (!$co{'parent'}) {
5002 $formats_nav .= ' (initial)';
5003 } elsif (scalar @
{$co{'parents'}} == 1) {
5004 # single parent commit
5007 $cgi->a({-href
=> href
(action
=>"commitdiff",
5008 hash
=>$co{'parent'})},
5009 esc_html
(substr($co{'parent'}, 0, 7))) .
5013 if ($hash_parent eq '--cc') {
5014 $formats_nav .= ' | ' .
5015 $cgi->a({-href
=> href
(action
=>"commitdiff",
5016 hash
=>$hash, hash_parent
=>'-c')},
5018 } else { # $hash_parent eq '-c'
5019 $formats_nav .= ' | ' .
5020 $cgi->a({-href
=> href
(action
=>"commitdiff",
5021 hash
=>$hash, hash_parent
=>'--cc')},
5027 $cgi->a({-href
=> href
(action
=>"commitdiff",
5029 esc_html
(substr($_, 0, 7)));
5030 } @
{$co{'parents'}} ) .
5035 my $hash_parent_param = $hash_parent;
5036 if (!defined $hash_parent_param) {
5037 # --cc for multiple parents, --root for parentless
5038 $hash_parent_param =
5039 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5045 if ($format eq 'html') {
5046 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5047 "--no-commit-id", "--patch-with-raw", "--full-index",
5048 $hash_parent_param, $hash, "--"
5049 or die_error
(500, "Open git-diff-tree failed");
5051 while (my $line = <$fd>) {
5053 # empty line ends raw part of diff-tree output
5055 push @difftree, scalar parse_difftree_raw_line
($line);
5058 } elsif ($format eq 'plain') {
5059 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5060 '-p', $hash_parent_param, $hash, "--"
5061 or die_error
(500, "Open git-diff-tree failed");
5064 die_error
(400, "Unknown commitdiff format");
5067 # non-textual hash id's can be cached
5069 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5073 # write commit message
5074 if ($format eq 'html') {
5075 my $refs = git_get_references
();
5076 my $ref = format_ref_marker
($refs, $co{'id'});
5078 git_header_html
(undef, $expires);
5079 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5080 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5081 git_print_authorship
(\
%co);
5082 print "<div class=\"page_body\">\n";
5083 if (@
{$co{'comment'}} > 1) {
5084 print "<div class=\"log\">\n";
5085 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5086 print "</div>\n"; # class="log"
5089 } elsif ($format eq 'plain') {
5090 my $refs = git_get_references
("tags");
5091 my $tagname = git_get_rev_name_tags
($hash);
5092 my $filename = basename
($project) . "-$hash.patch";
5095 -type
=> 'text/plain',
5096 -charset
=> 'utf-8',
5097 -expires
=> $expires,
5098 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5099 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5100 print "From: " . to_utf8
($co{'author'}) . "\n";
5101 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5102 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5104 print "X-Git-Tag: $tagname\n" if $tagname;
5105 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5107 foreach my $line (@
{$co{'comment'}}) {
5108 print to_utf8
($line) . "\n";
5114 if ($format eq 'html') {
5115 my $use_parents = !defined $hash_parent ||
5116 $hash_parent eq '-c' || $hash_parent eq '--cc';
5117 git_difftree_body
(\
@difftree, $hash,
5118 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5121 git_patchset_body
($fd, \
@difftree, $hash,
5122 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5124 print "</div>\n"; # class="page_body"
5127 } elsif ($format eq 'plain') {
5131 or print "Reading git-diff-tree failed\n";
5135 sub git_commitdiff_plain
{
5136 git_commitdiff
('plain');
5140 if (!defined $hash_base) {
5141 $hash_base = git_get_head_hash
($project);
5143 if (!defined $page) {
5147 my %co = parse_commit
($hash_base)
5148 or die_error
(404, "Unknown commit object");
5150 my $refs = git_get_references
();
5151 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5153 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5154 $file_name, "--full-history")
5155 or die_error
(404, "No such file or directory on given branch");
5157 if (!defined $hash && defined $file_name) {
5158 # some commits could have deleted file in question,
5159 # and not have it in tree, but one of them has to have it
5160 for (my $i = 0; $i <= @commitlist; $i++) {
5161 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5162 last if defined $hash;
5165 if (defined $hash) {
5166 $ftype = git_get_type
($hash);
5168 if (!defined $ftype) {
5169 die_error
(500, "Unknown type of object");
5172 my $paging_nav = '';
5175 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5176 file_name
=>$file_name)},
5178 $paging_nav .= " ⋅ " .
5179 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5180 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5182 $paging_nav .= "first";
5183 $paging_nav .= " ⋅ prev";
5186 if ($#commitlist >= 100) {
5188 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5189 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5190 $paging_nav .= " ⋅ $next_link";
5192 $paging_nav .= " ⋅ next";
5196 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5197 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5198 git_print_page_path
($file_name, $ftype, $hash_base);
5200 git_history_body
(\
@commitlist, 0, 99,
5201 $refs, $hash_base, $ftype, $next_link);
5207 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5208 if (!defined $searchtext) {
5209 die_error
(400, "Text field is empty");
5211 if (!defined $hash) {
5212 $hash = git_get_head_hash
($project);
5214 my %co = parse_commit
($hash);
5216 die_error
(404, "Unknown commit object");
5218 if (!defined $page) {
5222 $searchtype ||= 'commit';
5223 if ($searchtype eq 'pickaxe') {
5224 # pickaxe may take all resources of your box and run for several minutes
5225 # with every query - so decide by yourself how public you make this feature
5226 gitweb_check_feature
('pickaxe')
5227 or die_error
(403, "Pickaxe is disabled");
5229 if ($searchtype eq 'grep') {
5230 gitweb_check_feature
('grep')
5231 or die_error
(403, "Grep is disabled");
5236 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5238 if ($searchtype eq 'commit') {
5239 $greptype = "--grep=";
5240 } elsif ($searchtype eq 'author') {
5241 $greptype = "--author=";
5242 } elsif ($searchtype eq 'committer') {
5243 $greptype = "--committer=";
5245 $greptype .= $searchtext;
5246 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5247 $greptype, '--regexp-ignore-case',
5248 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5250 my $paging_nav = '';
5253 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5254 searchtext
=>$searchtext,
5255 searchtype
=>$searchtype)},
5257 $paging_nav .= " ⋅ " .
5258 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5259 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5261 $paging_nav .= "first";
5262 $paging_nav .= " ⋅ prev";
5265 if ($#commitlist >= 100) {
5267 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5268 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5269 $paging_nav .= " ⋅ $next_link";
5271 $paging_nav .= " ⋅ next";
5274 if ($#commitlist >= 100) {
5277 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5278 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5279 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5282 if ($searchtype eq 'pickaxe') {
5283 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5284 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5286 print "<table class=\"pickaxe search\">\n";
5289 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5290 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5291 ($search_use_regexp ?
'--pickaxe-regex' : ());
5294 while (my $line = <$fd>) {
5298 my %set = parse_difftree_raw_line
($line);
5299 if (defined $set{'commit'}) {
5300 # finish previous commit
5303 "<td class=\"link\">" .
5304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5306 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5312 print "<tr class=\"dark\">\n";
5314 print "<tr class=\"light\">\n";
5317 %co = parse_commit
($set{'commit'});
5318 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5319 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5320 "<td><i>$author</i></td>\n" .
5322 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5323 -class => "list subject"},
5324 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5325 } elsif (defined $set{'to_id'}) {
5326 next if ($set{'to_id'} =~ m/^0{40}$/);
5328 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5329 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5331 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5337 # finish last commit (warning: repetition!)
5340 "<td class=\"link\">" .
5341 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5343 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5351 if ($searchtype eq 'grep') {
5352 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5353 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5355 print "<table class=\"grep_search\">\n";
5359 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5360 $search_use_regexp ?
('-E', '-i') : '-F',
5361 $searchtext, $co{'tree'};
5363 while (my $line = <$fd>) {
5365 my ($file, $lno, $ltext, $binary);
5366 last if ($matches++ > 1000);
5367 if ($line =~ /^Binary file (.+) matches$/) {
5371 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5373 if ($file ne $lastfile) {
5374 $lastfile and print "</td></tr>\n";
5376 print "<tr class=\"dark\">\n";
5378 print "<tr class=\"light\">\n";
5380 print "<td class=\"list\">".
5381 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5382 file_name
=>"$file"),
5383 -class => "list"}, esc_path
($file));
5384 print "</td><td>\n";
5388 print "<div class=\"binary\">Binary file</div>\n";
5390 $ltext = untabify
($ltext);
5391 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5392 $ltext = esc_html
($1, -nbsp
=>1);
5393 $ltext .= '<span class="match">';
5394 $ltext .= esc_html
($2, -nbsp
=>1);
5395 $ltext .= '</span>';
5396 $ltext .= esc_html
($3, -nbsp
=>1);
5398 $ltext = esc_html
($ltext, -nbsp
=>1);
5400 print "<div class=\"pre\">" .
5401 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5402 file_name
=>"$file").'#l'.$lno,
5403 -class => "linenr"}, sprintf('%4i', $lno))
5404 . ' ' . $ltext . "</div>\n";
5408 print "</td></tr>\n";
5409 if ($matches > 1000) {
5410 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5413 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5422 sub git_search_help
{
5424 git_print_page_nav
('','', $hash,$hash,$hash);
5426 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5427 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5428 the pattern entered is recognized as the POSIX extended
5429 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5432 <dt><b>commit</b></dt>
5433 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5435 my ($have_grep) = gitweb_check_feature
('grep');
5438 <dt><b>grep</b></dt>
5439 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5440 a different one) are searched for the given pattern. On large trees, this search can take
5441 a while and put some strain on the server, so please use it with some consideration. Note that
5442 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5443 case-sensitive.</dd>
5447 <dt><b>author</b></dt>
5448 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5449 <dt><b>committer</b></dt>
5450 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5452 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5453 if ($have_pickaxe) {
5455 <dt><b>pickaxe</b></dt>
5456 <dd>All commits that caused the string to appear or disappear from any file (changes that
5457 added, removed or "modified" the string) will be listed. This search can take a while and
5458 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5459 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5467 my $head = git_get_head_hash
($project);
5468 if (!defined $hash) {
5471 if (!defined $page) {
5474 my $refs = git_get_references
();
5476 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5478 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5480 if ($#commitlist >= 100) {
5482 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5483 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5487 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5488 git_print_header_div
('summary', $project);
5490 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5495 ## ......................................................................
5496 ## feeds (RSS, Atom; OPML)
5499 my $format = shift || 'atom';
5500 my ($have_blame) = gitweb_check_feature
('blame');
5502 # Atom: http://www.atomenabled.org/developers/syndication/
5503 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5504 if ($format ne 'rss' && $format ne 'atom') {
5505 die_error
(400, "Unknown web feed format");
5508 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5509 my $head = $hash || 'HEAD';
5510 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5514 my $content_type = "application/$format+xml";
5515 if (defined $cgi->http('HTTP_ACCEPT') &&
5516 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5517 # browser (feed reader) prefers text/xml
5518 $content_type = 'text/xml';
5520 if (defined($commitlist[0])) {
5521 %latest_commit = %{$commitlist[0]};
5522 %latest_date = parse_date
($latest_commit{'author_epoch'});
5524 -type
=> $content_type,
5525 -charset
=> 'utf-8',
5526 -last_modified
=> $latest_date{'rfc2822'});
5529 -type
=> $content_type,
5530 -charset
=> 'utf-8');
5533 # Optimization: skip generating the body if client asks only
5534 # for Last-Modified date.
5535 return if ($cgi->request_method() eq 'HEAD');
5538 my $title = "$site_name - $project/$action";
5539 my $feed_type = 'log';
5540 if (defined $hash) {
5541 $title .= " - '$hash'";
5542 $feed_type = 'branch log';
5543 if (defined $file_name) {
5544 $title .= " :: $file_name";
5545 $feed_type = 'history';
5547 } elsif (defined $file_name) {
5548 $title .= " - $file_name";
5549 $feed_type = 'history';
5551 $title .= " $feed_type";
5552 my $descr = git_get_project_description
($project);
5553 if (defined $descr) {
5554 $descr = esc_html
($descr);
5556 $descr = "$project " .
5557 ($format eq 'rss' ?
'RSS' : 'Atom') .
5560 my $owner = git_get_project_owner
($project);
5561 $owner = esc_html
($owner);
5565 if (defined $file_name) {
5566 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5567 } elsif (defined $hash) {
5568 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5570 $alt_url = href
(-full
=>1, action
=>"summary");
5572 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5573 if ($format eq 'rss') {
5575 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5578 print "<title>$title</title>\n" .
5579 "<link>$alt_url</link>\n" .
5580 "<description>$descr</description>\n" .
5581 "<language>en</language>\n";
5582 } elsif ($format eq 'atom') {
5584 <feed xmlns="http://www.w3.org/2005/Atom">
5586 print "<title>$title</title>\n" .
5587 "<subtitle>$descr</subtitle>\n" .
5588 '<link rel="alternate" type="text/html" href="' .
5589 $alt_url . '" />' . "\n" .
5590 '<link rel="self" type="' . $content_type . '" href="' .
5591 $cgi->self_url() . '" />' . "\n" .
5592 "<id>" . href
(-full
=>1) . "</id>\n" .
5593 # use project owner for feed author
5594 "<author><name>$owner</name></author>\n";
5595 if (defined $favicon) {
5596 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5598 if (defined $logo_url) {
5599 # not twice as wide as tall: 72 x 27 pixels
5600 print "<logo>" . esc_url
($logo) . "</logo>\n";
5602 if (! %latest_date) {
5603 # dummy date to keep the feed valid until commits trickle in:
5604 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5606 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5611 for (my $i = 0; $i <= $#commitlist; $i++) {
5612 my %co = %{$commitlist[$i]};
5613 my $commit = $co{'id'};
5614 # we read 150, we always show 30 and the ones more recent than 48 hours
5615 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5618 my %cd = parse_date
($co{'author_epoch'});
5620 # get list of changed files
5621 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5622 $co{'parent'} || "--root",
5623 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5625 my @difftree = map { chomp; $_ } <$fd>;
5629 # print element (entry, item)
5630 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5631 if ($format eq 'rss') {
5633 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5634 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5635 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5636 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5637 "<link>$co_url</link>\n" .
5638 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5639 "<content:encoded>" .
5641 } elsif ($format eq 'atom') {
5643 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5644 "<updated>$cd{'iso-8601'}</updated>\n" .
5646 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5647 if ($co{'author_email'}) {
5648 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5650 print "</author>\n" .
5651 # use committer for contributor
5653 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5654 if ($co{'committer_email'}) {
5655 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5657 print "</contributor>\n" .
5658 "<published>$cd{'iso-8601'}</published>\n" .
5659 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5660 "<id>$co_url</id>\n" .
5661 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5662 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5664 my $comment = $co{'comment'};
5666 foreach my $line (@
$comment) {
5667 $line = esc_html
($line);
5670 print "</pre><ul>\n";
5671 foreach my $difftree_line (@difftree) {
5672 my %difftree = parse_difftree_raw_line
($difftree_line);
5673 next if !$difftree{'from_id'};
5675 my $file = $difftree{'file'} || $difftree{'to_file'};
5679 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5680 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5681 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5682 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5683 -title
=> "diff"}, 'D');
5685 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5686 file_name
=>$file, hash_base
=>$commit),
5687 -title
=> "blame"}, 'B');
5689 # if this is not a feed of a file history
5690 if (!defined $file_name || $file_name ne $file) {
5691 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5692 file_name
=>$file, hash
=>$commit),
5693 -title
=> "history"}, 'H');
5695 $file = esc_path
($file);
5699 if ($format eq 'rss') {
5700 print "</ul>]]>\n" .
5701 "</content:encoded>\n" .
5703 } elsif ($format eq 'atom') {
5704 print "</ul>\n</div>\n" .
5711 if ($format eq 'rss') {
5712 print "</channel>\n</rss>\n";
5713 } elsif ($format eq 'atom') {
5727 my @list = git_get_projects_list
();
5729 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5731 <?xml version="1.0" encoding="utf-8"?>
5732 <opml version="1.0">
5734 <title>$site_name OPML Export</title>
5737 <outline text="git RSS feeds">
5740 foreach my $pr (@list) {
5742 my $head = git_get_head_hash
($proj{'path'});
5743 if (!defined $head) {
5746 $git_dir = "$projectroot/$proj{'path'}";
5747 my %co = parse_commit
($head);
5752 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5753 my $rss = "$my_url?p=$proj{'path'};a=rss";
5754 my $html = "$my_url?p=$proj{'path'};a=summary";
5755 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";