3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 if (-e
$GITWEB_CONFIG) {
376 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
377 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
380 # version of the core git binary
381 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
383 $projects_list ||= $projectroot;
385 # ======================================================================
386 # input validation and dispatch
387 our $action = $cgi->param('a');
388 if (defined $action) {
389 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
390 die_error
(400, "Invalid action parameter");
394 # parameters which are pathnames
395 our $project = $cgi->param('p');
396 if (defined $project) {
397 if (!validate_pathname
($project) ||
398 !(-d
"$projectroot/$project") ||
399 !check_head_link
("$projectroot/$project") ||
400 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
401 ($strict_export && !project_in_list
($project))) {
403 die_error
(404, "No such project");
407 our $file_name = $cgi->param('f');
408 if (defined $file_name) {
409 if (!validate_pathname
($file_name)) {
410 die_error
(400, "Invalid file parameter");
414 our $file_parent = $cgi->param('fp');
415 if (defined $file_parent) {
416 if (!validate_pathname
($file_parent)) {
417 die_error
(400, "Invalid file parent parameter");
421 # parameters which are refnames
422 our $hash = $cgi->param('h');
424 if (!validate_refname
($hash)) {
425 die_error
(400, "Invalid hash parameter");
429 our $hash_parent = $cgi->param('hp');
430 if (defined $hash_parent) {
431 if (!validate_refname
($hash_parent)) {
432 die_error
(400, "Invalid hash parent parameter");
436 our $hash_base = $cgi->param('hb');
437 if (defined $hash_base) {
438 if (!validate_refname
($hash_base)) {
439 die_error
(400, "Invalid hash base parameter");
443 my %allowed_options = (
444 "--no-merges" => [ qw(rss atom log shortlog history) ],
447 our @extra_options = $cgi->param('opt');
448 if (defined @extra_options) {
449 foreach my $opt (@extra_options) {
450 if (not exists $allowed_options{$opt}) {
451 die_error
(400, "Invalid option parameter");
453 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
454 die_error
(400, "Invalid option parameter for this action");
459 our $hash_parent_base = $cgi->param('hpb');
460 if (defined $hash_parent_base) {
461 if (!validate_refname
($hash_parent_base)) {
462 die_error
(400, "Invalid hash parent base parameter");
467 our $page = $cgi->param('pg');
469 if ($page =~ m/[^0-9]/) {
470 die_error
(400, "Invalid page parameter");
474 our $searchtype = $cgi->param('st');
475 if (defined $searchtype) {
476 if ($searchtype =~ m/[^a-z]/) {
477 die_error
(400, "Invalid searchtype parameter");
481 our $search_use_regexp = $cgi->param('sr');
483 our $searchtext = $cgi->param('s');
485 if (defined $searchtext) {
486 if (length($searchtext) < 2) {
487 die_error
(403, "At least two characters are required for search parameter");
489 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
492 # now read PATH_INFO and use it as alternative to parameters
493 sub evaluate_path_info
{
494 return if defined $project;
495 my $path_info = $ENV{"PATH_INFO"};
496 return if !$path_info;
497 $path_info =~ s
,^/+,,;
498 return if !$path_info;
499 # find which part of PATH_INFO is project
500 $project = $path_info;
502 while ($project && !check_head_link
("$projectroot/$project")) {
503 $project =~ s
,/*[^/]*$,,;
506 $project = validate_pathname
($project);
508 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
509 ($strict_export && !project_in_list
($project))) {
513 # do not change any parameters if an action is given using the query string
515 $path_info =~ s
,^\Q
$project\E
/*,,;
516 my ($refname, $pathname) = split(/:/, $path_info, 2);
517 if (defined $pathname) {
518 # we got "project.git/branch:filename" or "project.git/branch:dir/"
519 # we could use git_get_type(branch:pathname), but it needs $git_dir
520 $pathname =~ s
,^/+,,;
521 if (!$pathname || substr($pathname, -1) eq "/") {
525 $action ||= "blob_plain";
527 $hash_base ||= validate_refname
($refname);
528 $file_name ||= validate_pathname
($pathname);
529 } elsif (defined $refname) {
530 # we got "project.git/branch"
531 $action ||= "shortlog";
532 $hash ||= validate_refname
($refname);
535 evaluate_path_info
();
537 # path to the current git repository
539 $git_dir = "$projectroot/$project" if $project;
543 "blame" => \
&git_blame
,
544 "blobdiff" => \
&git_blobdiff
,
545 "blobdiff_plain" => \
&git_blobdiff_plain
,
546 "blob" => \
&git_blob
,
547 "blob_plain" => \
&git_blob_plain
,
548 "commitdiff" => \
&git_commitdiff
,
549 "commitdiff_plain" => \
&git_commitdiff_plain
,
550 "commit" => \
&git_commit
,
551 "forks" => \
&git_forks
,
552 "heads" => \
&git_heads
,
553 "history" => \
&git_history
,
556 "atom" => \
&git_atom
,
557 "search" => \
&git_search
,
558 "search_help" => \
&git_search_help
,
559 "shortlog" => \
&git_shortlog
,
560 "summary" => \
&git_summary
,
562 "tags" => \
&git_tags
,
563 "tree" => \
&git_tree
,
564 "snapshot" => \
&git_snapshot
,
565 "object" => \
&git_object
,
566 # those below don't need $project
567 "opml" => \
&git_opml
,
568 "project_list" => \
&git_project_list
,
569 "project_index" => \
&git_project_index
,
572 if (!defined $action) {
574 $action = git_get_type
($hash);
575 } elsif (defined $hash_base && defined $file_name) {
576 $action = git_get_type
("$hash_base:$file_name");
577 } elsif (defined $project) {
580 $action = 'project_list';
583 if (!defined($actions{$action})) {
584 die_error
(400, "Unknown action");
586 if ($action !~ m/^(opml|project_list|project_index)$/ &&
588 die_error
(400, "Project needed");
590 $actions{$action}->();
593 ## ======================================================================
598 # default is to use -absolute url() i.e. $my_uri
599 my $href = $params{-full
} ? $my_url : $my_uri;
601 # XXX: Warning: If you touch this, check the search form for updating,
612 hash_parent_base
=> "hpb",
617 snapshot_format
=> "sf",
618 extra_options
=> "opt",
619 search_use_regexp
=> "sr",
621 my %mapping = @mapping;
623 $params{'project'} = $project unless exists $params{'project'};
625 if ($params{-replay
}) {
626 while (my ($name, $symbol) = each %mapping) {
627 if (!exists $params{$name}) {
628 # to allow for multivalued params we use arrayref form
629 $params{$name} = [ $cgi->param($symbol) ];
634 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
636 # use PATH_INFO for project name
637 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
638 delete $params{'project'};
640 # Summary just uses the project path URL
641 if (defined $params{'action'} && $params{'action'} eq 'summary') {
642 delete $params{'action'};
646 # now encode the parameters explicitly
648 for (my $i = 0; $i < @mapping; $i += 2) {
649 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
650 if (defined $params{$name}) {
651 if (ref($params{$name}) eq "ARRAY") {
652 foreach my $par (@{$params{$name}}) {
653 push @result, $symbol . "=" . esc_param
($par);
656 push @result, $symbol . "=" . esc_param
($params{$name});
660 $href .= "?" . join(';', @result) if scalar @result;
666 ## ======================================================================
667 ## validation, quoting/unquoting and escaping
669 sub validate_pathname
{
670 my $input = shift || return undef;
672 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
673 # at the beginning, at the end, and between slashes.
674 # also this catches doubled slashes
675 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
679 if ($input =~ m!\0!) {
685 sub validate_refname
{
686 my $input = shift || return undef;
688 # textual hashes are O.K.
689 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
692 # it must be correct pathname
693 $input = validate_pathname
($input)
695 # restrictions on ref name according to git-check-ref-format
696 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
702 # decode sequences of octets in utf8 into Perl's internal form,
703 # which is utf-8 with utf8 flag set if needed. gitweb writes out
704 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
707 if (utf8
::valid
($str)) {
711 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
715 # quote unsafe chars, but keep the slash, even when it's not
716 # correct, but quoted slashes look too horrible in bookmarks
719 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
725 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
728 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
734 # replace invalid utf8 character with SUBSTITUTION sequence
739 $str = to_utf8
($str);
740 $str = $cgi->escapeHTML($str);
741 if ($opts{'-nbsp'}) {
742 $str =~ s/ / /g;
744 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
748 # quote control characters and escape filename to HTML
753 $str = to_utf8
($str);
754 $str = $cgi->escapeHTML($str);
755 if ($opts{'-nbsp'}) {
756 $str =~ s/ / /g;
758 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
762 # Make control characters "printable", using character escape codes (CEC)
766 my %es = ( # character escape codes, aka escape sequences
767 "\t" => '\t', # tab (HT)
768 "\n" => '\n', # line feed (LF)
769 "\r" => '\r', # carrige return (CR)
770 "\f" => '\f', # form feed (FF)
771 "\b" => '\b', # backspace (BS)
772 "\a" => '\a', # alarm (bell) (BEL)
773 "\e" => '\e', # escape (ESC)
774 "\013" => '\v', # vertical tab (VT)
775 "\000" => '\0', # nul character (NUL)
777 my $chr = ( (exists $es{$cntrl})
779 : sprintf('\%03o', ord($cntrl)) );
780 if ($opts{-nohtml
}) {
783 return "<span class=\"cntrl\">$chr</span>";
787 # Alternatively use unicode control pictures codepoints,
788 # Unicode "printable representation" (PR)
793 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
794 if ($opts{-nohtml
}) {
797 return "<span class=\"cntrl\">$chr</span>";
801 # git may return quoted and escaped filenames
807 my %es = ( # character escape codes, aka escape sequences
808 't' => "\t", # tab (HT, TAB)
809 'n' => "\n", # newline (NL)
810 'r' => "\r", # return (CR)
811 'f' => "\f", # form feed (FF)
812 'b' => "\b", # backspace (BS)
813 'a' => "\a", # alarm (bell) (BEL)
814 'e' => "\e", # escape (ESC)
815 'v' => "\013", # vertical tab (VT)
818 if ($seq =~ m/^[0-7]{1,3}$/) {
819 # octal char sequence
820 return chr(oct($seq));
821 } elsif (exists $es{$seq}) {
822 # C escape sequence, aka character escape code
825 # quoted ordinary character
829 if ($str =~ m/^"(.*)"$/) {
832 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
837 # escape tabs (convert tabs to spaces)
841 while ((my $pos = index($line, "\t")) != -1) {
842 if (my $count = (8 - ($pos % 8))) {
843 my $spaces = ' ' x
$count;
844 $line =~ s/\t/$spaces/;
851 sub project_in_list
{
853 my @list = git_get_projects_list
();
854 return @list && scalar(grep { $_->{'path'} eq $project } @list);
857 ## ----------------------------------------------------------------------
858 ## HTML aware string manipulation
860 # Try to chop given string on a word boundary between position
861 # $len and $len+$add_len. If there is no word boundary there,
862 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
863 # (marking chopped part) would be longer than given string.
867 my $add_len = shift || 10;
868 my $where = shift || 'right'; # 'left' | 'center' | 'right'
870 # Make sure perl knows it is utf8 encoded so we don't
871 # cut in the middle of a utf8 multibyte char.
872 $str = to_utf8
($str);
874 # allow only $len chars, but don't cut a word if it would fit in $add_len
875 # if it doesn't fit, cut it if it's still longer than the dots we would add
876 # remove chopped character entities entirely
878 # when chopping in the middle, distribute $len into left and right part
879 # return early if chopping wouldn't make string shorter
880 if ($where eq 'center') {
881 return $str if ($len + 5 >= length($str)); # filler is length 5
884 return $str if ($len + 4 >= length($str)); # filler is length 4
887 # regexps: ending and beginning with word part up to $add_len
888 my $endre = qr/.{$len}\w{0,$add_len}/;
889 my $begre = qr/\w{0,$add_len}.{$len}/;
891 if ($where eq 'left') {
892 $str =~ m/^(.*?)($begre)$/;
893 my ($lead, $body) = ($1, $2);
894 if (length($lead) > 4) {
895 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
900 } elsif ($where eq 'center') {
901 $str =~ m/^($endre)(.*)$/;
902 my ($left, $str) = ($1, $2);
903 $str =~ m/^(.*?)($begre)$/;
904 my ($mid, $right) = ($1, $2);
905 if (length($mid) > 5) {
906 $left =~ s/&[^;]*$//;
907 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
910 return "$left$mid$right";
913 $str =~ m/^($endre)(.*)$/;
916 if (length($tail) > 4) {
917 $body =~ s/&[^;]*$//;
924 # takes the same arguments as chop_str, but also wraps a <span> around the
925 # result with a title attribute if it does get chopped. Additionally, the
926 # string is HTML-escaped.
927 sub chop_and_escape_str
{
930 my $chopped = chop_str
(@_);
931 if ($chopped eq $str) {
932 return esc_html
($chopped);
934 $str =~ s/([[:cntrl:]])/?/g;
935 return $cgi->span({-title
=>$str}, esc_html
($chopped));
939 ## ----------------------------------------------------------------------
940 ## functions returning short strings
942 # CSS class for given age value (in seconds)
948 } elsif ($age < 60*60*2) {
950 } elsif ($age < 60*60*24*2) {
957 # convert age in seconds to "nn units ago" string
962 if ($age > 60*60*24*365*2) {
963 $age_str = (int $age/60/60/24/365);
964 $age_str .= " years ago";
965 } elsif ($age > 60*60*24*(365/12)*2) {
966 $age_str = int $age/60/60/24/(365/12);
967 $age_str .= " months ago";
968 } elsif ($age > 60*60*24*7*2) {
969 $age_str = int $age/60/60/24/7;
970 $age_str .= " weeks ago";
971 } elsif ($age > 60*60*24*2) {
972 $age_str = int $age/60/60/24;
973 $age_str .= " days ago";
974 } elsif ($age > 60*60*2) {
975 $age_str = int $age/60/60;
976 $age_str .= " hours ago";
977 } elsif ($age > 60*2) {
978 $age_str = int $age/60;
979 $age_str .= " min ago";
982 $age_str .= " sec ago";
984 $age_str .= " right now";
990 S_IFINVALID
=> 0030000,
991 S_IFGITLINK
=> 0160000,
994 # submodule/subproject, a commit object reference
998 return (($mode & S_IFMT
) == S_IFGITLINK
)
1001 # convert file mode in octal to symbolic file mode string
1003 my $mode = oct shift;
1005 if (S_ISGITLINK
($mode)) {
1006 return 'm---------';
1007 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1008 return 'drwxr-xr-x';
1009 } elsif (S_ISLNK
($mode)) {
1010 return 'lrwxrwxrwx';
1011 } elsif (S_ISREG
($mode)) {
1012 # git cares only about the executable bit
1013 if ($mode & S_IXUSR
) {
1014 return '-rwxr-xr-x';
1016 return '-rw-r--r--';
1019 return '----------';
1023 # convert file mode in octal to file type string
1027 if ($mode !~ m/^[0-7]+$/) {
1033 if (S_ISGITLINK
($mode)) {
1035 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1037 } elsif (S_ISLNK
($mode)) {
1039 } elsif (S_ISREG
($mode)) {
1046 # convert file mode in octal to file type description string
1047 sub file_type_long
{
1050 if ($mode !~ m/^[0-7]+$/) {
1056 if (S_ISGITLINK
($mode)) {
1058 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1060 } elsif (S_ISLNK
($mode)) {
1062 } elsif (S_ISREG
($mode)) {
1063 if ($mode & S_IXUSR
) {
1064 return "executable";
1074 ## ----------------------------------------------------------------------
1075 ## functions returning short HTML fragments, or transforming HTML fragments
1076 ## which don't belong to other sections
1078 # format line of commit message.
1079 sub format_log_line_html
{
1082 $line = esc_html
($line, -nbsp
=>1);
1083 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1086 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1087 -class => "text"}, $hash_text);
1088 $line =~ s/$hash_text/$link/;
1093 # format marker of refs pointing to given object
1095 # the destination action is chosen based on object type and current context:
1096 # - for annotated tags, we choose the tag view unless it's the current view
1097 # already, in which case we go to shortlog view
1098 # - for other refs, we keep the current view if we're in history, shortlog or
1099 # log view, and select shortlog otherwise
1100 sub format_ref_marker
{
1101 my ($refs, $id) = @_;
1104 if (defined $refs->{$id}) {
1105 foreach my $ref (@{$refs->{$id}}) {
1106 # this code exploits the fact that non-lightweight tags are the
1107 # only indirect objects, and that they are the only objects for which
1108 # we want to use tag instead of shortlog as action
1109 my ($type, $name) = qw();
1110 my $indirect = ($ref =~ s/\^\{\}$//);
1111 # e.g. tags/v2.6.11 or heads/next
1112 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1121 $class .= " indirect" if $indirect;
1123 my $dest_action = "shortlog";
1126 $dest_action = "tag" unless $action eq "tag";
1127 } elsif ($action =~ /^(history|(short)?log)$/) {
1128 $dest_action = $action;
1132 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1135 my $link = $cgi->a({
1137 action
=>$dest_action,
1141 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1147 return ' <span class="refs">'. $markers . '</span>';
1153 # format, perhaps shortened and with markers, title line
1154 sub format_subject_html
{
1155 my ($long, $short, $href, $extra) = @_;
1156 $extra = '' unless defined($extra);
1158 if (length($short) < length($long)) {
1159 return $cgi->a({-href
=> $href, -class => "list subject",
1160 -title
=> to_utf8
($long)},
1161 esc_html
($short) . $extra);
1163 return $cgi->a({-href
=> $href, -class => "list subject"},
1164 esc_html
($long) . $extra);
1168 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1169 sub format_git_diff_header_line
{
1171 my $diffinfo = shift;
1172 my ($from, $to) = @_;
1174 if ($diffinfo->{'nparents'}) {
1176 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1177 if ($to->{'href'}) {
1178 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1179 esc_path
($to->{'file'}));
1180 } else { # file was deleted (no href)
1181 $line .= esc_path
($to->{'file'});
1185 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1186 if ($from->{'href'}) {
1187 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1188 'a/' . esc_path
($from->{'file'}));
1189 } else { # file was added (no href)
1190 $line .= 'a/' . esc_path
($from->{'file'});
1193 if ($to->{'href'}) {
1194 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1195 'b/' . esc_path
($to->{'file'}));
1196 } else { # file was deleted
1197 $line .= 'b/' . esc_path
($to->{'file'});
1201 return "<div class=\"diff header\">$line</div>\n";
1204 # format extended diff header line, before patch itself
1205 sub format_extended_diff_header_line
{
1207 my $diffinfo = shift;
1208 my ($from, $to) = @_;
1211 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1212 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1213 esc_path
($from->{'file'}));
1215 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1216 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1217 esc_path
($to->{'file'}));
1219 # match single <mode>
1220 if ($line =~ m/\s(\d{6})$/) {
1221 $line .= '<span class="info"> (' .
1222 file_type_long
($1) .
1226 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1227 # can match only for combined diff
1229 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1230 if ($from->{'href'}[$i]) {
1231 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1233 substr($diffinfo->{'from_id'}[$i],0,7));
1238 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1241 if ($to->{'href'}) {
1242 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1243 substr($diffinfo->{'to_id'},0,7));
1248 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1249 # can match only for ordinary diff
1250 my ($from_link, $to_link);
1251 if ($from->{'href'}) {
1252 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1253 substr($diffinfo->{'from_id'},0,7));
1255 $from_link = '0' x
7;
1257 if ($to->{'href'}) {
1258 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1259 substr($diffinfo->{'to_id'},0,7));
1263 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1264 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1267 return $line . "<br/>\n";
1270 # format from-file/to-file diff header
1271 sub format_diff_from_to_header
{
1272 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1277 #assert($line =~ m/^---/) if DEBUG;
1278 # no extra formatting for "^--- /dev/null"
1279 if (! $diffinfo->{'nparents'}) {
1280 # ordinary (single parent) diff
1281 if ($line =~ m!^--- "?a/!) {
1282 if ($from->{'href'}) {
1284 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1285 esc_path
($from->{'file'}));
1288 esc_path
($from->{'file'});
1291 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1294 # combined diff (merge commit)
1295 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1296 if ($from->{'href'}[$i]) {
1298 $cgi->a({-href
=>href
(action
=>"blobdiff",
1299 hash_parent
=>$diffinfo->{'from_id'}[$i],
1300 hash_parent_base
=>$parents[$i],
1301 file_parent
=>$from->{'file'}[$i],
1302 hash
=>$diffinfo->{'to_id'},
1304 file_name
=>$to->{'file'}),
1306 -title
=>"diff" . ($i+1)},
1309 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1310 esc_path
($from->{'file'}[$i]));
1312 $line = '--- /dev/null';
1314 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1319 #assert($line =~ m/^\+\+\+/) if DEBUG;
1320 # no extra formatting for "^+++ /dev/null"
1321 if ($line =~ m!^\+\+\+ "?b/!) {
1322 if ($to->{'href'}) {
1324 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1325 esc_path
($to->{'file'}));
1328 esc_path
($to->{'file'});
1331 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1336 # create note for patch simplified by combined diff
1337 sub format_diff_cc_simplified
{
1338 my ($diffinfo, @parents) = @_;
1341 $result .= "<div class=\"diff header\">" .
1343 if (!is_deleted
($diffinfo)) {
1344 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1346 hash
=>$diffinfo->{'to_id'},
1347 file_name
=>$diffinfo->{'to_file'}),
1349 esc_path
($diffinfo->{'to_file'}));
1351 $result .= esc_path
($diffinfo->{'to_file'});
1353 $result .= "</div>\n" . # class="diff header"
1354 "<div class=\"diff nodifferences\">" .
1356 "</div>\n"; # class="diff nodifferences"
1361 # format patch (diff) line (not to be used for diff headers)
1362 sub format_diff_line
{
1364 my ($from, $to) = @_;
1365 my $diff_class = "";
1369 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1371 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1372 if ($line =~ m/^\@{3}/) {
1373 $diff_class = " chunk_header";
1374 } elsif ($line =~ m/^\\/) {
1375 $diff_class = " incomplete";
1376 } elsif ($prefix =~ tr/+/+/) {
1377 $diff_class = " add";
1378 } elsif ($prefix =~ tr/-/-/) {
1379 $diff_class = " rem";
1382 # assume ordinary diff
1383 my $char = substr($line, 0, 1);
1385 $diff_class = " add";
1386 } elsif ($char eq '-') {
1387 $diff_class = " rem";
1388 } elsif ($char eq '@') {
1389 $diff_class = " chunk_header";
1390 } elsif ($char eq "\\") {
1391 $diff_class = " incomplete";
1394 $line = untabify
($line);
1395 if ($from && $to && $line =~ m/^\@{2} /) {
1396 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1397 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1399 $from_lines = 0 unless defined $from_lines;
1400 $to_lines = 0 unless defined $to_lines;
1402 if ($from->{'href'}) {
1403 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1404 -class=>"list"}, $from_text);
1406 if ($to->{'href'}) {
1407 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1408 -class=>"list"}, $to_text);
1410 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1411 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1412 return "<div class=\"diff$diff_class\">$line</div>\n";
1413 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1414 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1415 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1417 @from_text = split(' ', $ranges);
1418 for (my $i = 0; $i < @from_text; ++$i) {
1419 ($from_start[$i], $from_nlines[$i]) =
1420 (split(',', substr($from_text[$i], 1)), 0);
1423 $to_text = pop @from_text;
1424 $to_start = pop @from_start;
1425 $to_nlines = pop @from_nlines;
1427 $line = "<span class=\"chunk_info\">$prefix ";
1428 for (my $i = 0; $i < @from_text; ++$i) {
1429 if ($from->{'href'}[$i]) {
1430 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1431 -class=>"list"}, $from_text[$i]);
1433 $line .= $from_text[$i];
1437 if ($to->{'href'}) {
1438 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1439 -class=>"list"}, $to_text);
1443 $line .= " $prefix</span>" .
1444 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1445 return "<div class=\"diff$diff_class\">$line</div>\n";
1447 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1450 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1451 # linked. Pass the hash of the tree/commit to snapshot.
1452 sub format_snapshot_links
{
1454 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1455 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1456 my $num_fmts = @snapshot_fmts;
1457 if ($num_fmts > 1) {
1458 # A parenthesized list of links bearing format names.
1459 # e.g. "snapshot (_tar.gz_ _zip_)"
1460 return "snapshot (" . join(' ', map
1467 }, $known_snapshot_formats{$_}{'display'})
1468 , @snapshot_fmts) . ")";
1469 } elsif ($num_fmts == 1) {
1470 # A single "snapshot" link whose tooltip bears the format name.
1472 my ($fmt) = @snapshot_fmts;
1478 snapshot_format
=>$fmt
1480 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1482 } else { # $num_fmts == 0
1487 ## ......................................................................
1488 ## functions returning values to be passed, perhaps after some
1489 ## transformation, to other functions; e.g. returning arguments to href()
1491 # returns hash to be passed to href to generate gitweb URL
1492 # in -title key it returns description of link
1494 my $format = shift || 'Atom';
1495 my %res = (action
=> lc($format));
1497 # feed links are possible only for project views
1498 return unless (defined $project);
1499 # some views should link to OPML, or to generic project feed,
1500 # or don't have specific feed yet (so they should use generic)
1501 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1504 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1505 # from tag links; this also makes possible to detect branch links
1506 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1507 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1510 # find log type for feed description (title)
1512 if (defined $file_name) {
1513 $type = "history of $file_name";
1514 $type .= "/" if ($action eq 'tree');
1515 $type .= " on '$branch'" if (defined $branch);
1517 $type = "log of $branch" if (defined $branch);
1520 $res{-title
} = $type;
1521 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1522 $res{'file_name'} = $file_name;
1527 ## ----------------------------------------------------------------------
1528 ## git utility subroutines, invoking git commands
1530 # returns path to the core git executable and the --git-dir parameter as list
1532 return $GIT, '--git-dir='.$git_dir;
1535 # quote the given arguments for passing them to the shell
1536 # quote_command("command", "arg 1", "arg with ' and ! characters")
1537 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1538 # Try to avoid using this function wherever possible.
1541 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1544 # get HEAD ref of given project as hash
1545 sub git_get_head_hash
{
1546 my $project = shift;
1547 my $o_git_dir = $git_dir;
1549 $git_dir = "$projectroot/$project";
1550 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1553 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1557 if (defined $o_git_dir) {
1558 $git_dir = $o_git_dir;
1563 # get type of given object
1567 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1569 close $fd or return;
1574 # repository configuration
1575 our $config_file = '';
1578 # store multiple values for single key as anonymous array reference
1579 # single values stored directly in the hash, not as [ <value> ]
1580 sub hash_set_multi
{
1581 my ($hash, $key, $value) = @_;
1583 if (!exists $hash->{$key}) {
1584 $hash->{$key} = $value;
1585 } elsif (!ref $hash->{$key}) {
1586 $hash->{$key} = [ $hash->{$key}, $value ];
1588 push @{$hash->{$key}}, $value;
1592 # return hash of git project configuration
1593 # optionally limited to some section, e.g. 'gitweb'
1594 sub git_parse_project_config
{
1595 my $section_regexp = shift;
1600 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1603 while (my $keyval = <$fh>) {
1605 my ($key, $value) = split(/\n/, $keyval, 2);
1607 hash_set_multi
(\
%config, $key, $value)
1608 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1615 # convert config value to boolean, 'true' or 'false'
1616 # no value, number > 0, 'true' and 'yes' values are true
1617 # rest of values are treated as false (never as error)
1618 sub config_to_bool
{
1621 # strip leading and trailing whitespace
1625 return (!defined $val || # section.key
1626 ($val =~ /^\d+$/ && $val) || # section.key = 1
1627 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1630 # convert config value to simple decimal number
1631 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1632 # to be multiplied by 1024, 1048576, or 1073741824
1636 # strip leading and trailing whitespace
1640 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1642 # unknown unit is treated as 1
1643 return $num * ($unit eq 'g' ? 1073741824 :
1644 $unit eq 'm' ? 1048576 :
1645 $unit eq 'k' ? 1024 : 1);
1650 # convert config value to array reference, if needed
1651 sub config_to_multi
{
1654 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1657 sub git_get_project_config
{
1658 my ($key, $type) = @_;
1661 return unless ($key);
1662 $key =~ s/^gitweb\.//;
1663 return if ($key =~ m/\W/);
1666 if (defined $type) {
1669 unless ($type eq 'bool' || $type eq 'int');
1673 if (!defined $config_file ||
1674 $config_file ne "$git_dir/config") {
1675 %config = git_parse_project_config
('gitweb');
1676 $config_file = "$git_dir/config";
1680 if (!defined $type) {
1681 return $config{"gitweb.$key"};
1682 } elsif ($type eq 'bool') {
1683 # backward compatibility: 'git config --bool' returns true/false
1684 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1685 } elsif ($type eq 'int') {
1686 return config_to_int
($config{"gitweb.$key"});
1688 return $config{"gitweb.$key"};
1691 # get hash of given path at given ref
1692 sub git_get_hash_by_path
{
1694 my $path = shift || return undef;
1699 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1700 or die_error
(500, "Open git-ls-tree failed");
1702 close $fd or return undef;
1704 if (!defined $line) {
1705 # there is no tree or hash given by $path at $base
1709 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1710 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1711 if (defined $type && $type ne $2) {
1712 # type doesn't match
1718 # get path of entry with given hash at given tree-ish (ref)
1719 # used to get 'from' filename for combined diff (merge commit) for renames
1720 sub git_get_path_by_hash
{
1721 my $base = shift || return;
1722 my $hash = shift || return;
1726 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1728 while (my $line = <$fd>) {
1731 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1732 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1733 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1742 ## ......................................................................
1743 ## git utility functions, directly accessing git repository
1745 sub git_get_project_description
{
1748 $git_dir = "$projectroot/$path";
1749 open my $fd, "$git_dir/description"
1750 or return git_get_project_config
('description');
1753 if (defined $descr) {
1759 sub git_get_project_url_list
{
1762 $git_dir = "$projectroot/$path";
1763 open my $fd, "$git_dir/cloneurl"
1764 or return wantarray ?
1765 @{ config_to_multi
(git_get_project_config
('url')) } :
1766 config_to_multi
(git_get_project_config
('url'));
1767 my @git_project_url_list = map { chomp; $_ } <$fd>;
1770 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1773 sub git_get_projects_list
{
1778 $filter =~ s/\.git$//;
1780 my ($check_forks) = gitweb_check_feature
('forks');
1782 if (-d
$projects_list) {
1783 # search in directory
1784 my $dir = $projects_list . ($filter ? "/$filter" : '');
1785 # remove the trailing "/"
1787 my $pfxlen = length("$dir");
1788 my $pfxdepth = ($dir =~ tr!/!!);
1791 follow_fast
=> 1, # follow symbolic links
1792 follow_skip
=> 2, # ignore duplicates
1793 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1795 # skip project-list toplevel, if we get it.
1796 return if (m!^[/.]$!);
1797 # only directories can be git repositories
1798 return unless (-d
$_);
1799 # don't traverse too deep (Find is super slow on os x)
1800 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1801 $File::Find
::prune
= 1;
1805 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1806 # we check related file in $projectroot
1807 if ($check_forks and $subdir =~ m
#/.#) {
1808 $File::Find
::prune
= 1;
1809 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1810 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1811 $File::Find
::prune
= 1;
1816 } elsif (-f
$projects_list) {
1817 # read from file(url-encoded):
1818 # 'git%2Fgit.git Linus+Torvalds'
1819 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1820 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1822 open my ($fd), $projects_list or return;
1824 while (my $line = <$fd>) {
1826 my ($path, $owner) = split ' ', $line;
1827 $path = unescape
($path);
1828 $owner = unescape
($owner);
1829 if (!defined $path) {
1832 if ($filter ne '') {
1833 # looking for forks;
1834 my $pfx = substr($path, 0, length($filter));
1835 if ($pfx ne $filter) {
1838 my $sfx = substr($path, length($filter));
1839 if ($sfx !~ /^\/.*\
.git
$/) {
1842 } elsif ($check_forks) {
1844 foreach my $filter (keys %paths) {
1845 # looking for forks;
1846 my $pfx = substr($path, 0, length($filter));
1847 if ($pfx ne $filter) {
1850 my $sfx = substr($path, length($filter));
1851 if ($sfx !~ /^\/.*\
.git
$/) {
1854 # is a fork, don't include it in
1859 if (check_export_ok
("$projectroot/$path")) {
1862 owner
=> to_utf8
($owner),
1865 (my $forks_path = $path) =~ s/\.git$//;
1866 $paths{$forks_path}++;
1874 our $gitweb_project_owner = undef;
1875 sub git_get_project_list_from_file
{
1877 return if (defined $gitweb_project_owner);
1879 $gitweb_project_owner = {};
1880 # read from file (url-encoded):
1881 # 'git%2Fgit.git Linus+Torvalds'
1882 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1883 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1884 if (-f
$projects_list) {
1885 open (my $fd , $projects_list);
1886 while (my $line = <$fd>) {
1888 my ($pr, $ow) = split ' ', $line;
1889 $pr = unescape
($pr);
1890 $ow = unescape
($ow);
1891 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1897 sub git_get_project_owner
{
1898 my $project = shift;
1901 return undef unless $project;
1902 $git_dir = "$projectroot/$project";
1904 if (!defined $gitweb_project_owner) {
1905 git_get_project_list_from_file
();
1908 if (exists $gitweb_project_owner->{$project}) {
1909 $owner = $gitweb_project_owner->{$project};
1911 if (!defined $owner){
1912 $owner = git_get_project_config
('owner');
1914 if (!defined $owner) {
1915 $owner = get_file_owner
("$git_dir");
1921 sub git_get_last_activity
{
1925 $git_dir = "$projectroot/$path";
1926 open($fd, "-|", git_cmd
(), 'for-each-ref',
1927 '--format=%(committer)',
1928 '--sort=-committerdate',
1930 'refs/heads') or return;
1931 my $most_recent = <$fd>;
1932 close $fd or return;
1933 if (defined $most_recent &&
1934 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1936 my $age = time - $timestamp;
1937 return ($age, age_string
($age));
1939 return (undef, undef);
1942 sub git_get_references
{
1943 my $type = shift || "";
1945 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1946 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1947 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1948 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1951 while (my $line = <$fd>) {
1953 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
1954 if (defined $refs{$1}) {
1955 push @{$refs{$1}}, $2;
1961 close $fd or return;
1965 sub git_get_rev_name_tags
{
1966 my $hash = shift || return undef;
1968 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1970 my $name_rev = <$fd>;
1973 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1976 # catches also '$hash undefined' output
1981 ## ----------------------------------------------------------------------
1982 ## parse to hash functions
1986 my $tz = shift || "-0000";
1989 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1990 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1991 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1992 $date{'hour'} = $hour;
1993 $date{'minute'} = $min;
1994 $date{'mday'} = $mday;
1995 $date{'day'} = $days[$wday];
1996 $date{'month'} = $months[$mon];
1997 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1998 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1999 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2000 $mday, $months[$mon], $hour ,$min;
2001 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2002 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2004 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2005 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2006 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2007 $date{'hour_local'} = $hour;
2008 $date{'minute_local'} = $min;
2009 $date{'tz_local'} = $tz;
2010 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2011 1900+$year, $mon+1, $mday,
2012 $hour, $min, $sec, $tz);
2021 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2022 $tag{'id'} = $tag_id;
2023 while (my $line = <$fd>) {
2025 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2026 $tag{'object'} = $1;
2027 } elsif ($line =~ m/^type (.+)$/) {
2029 } elsif ($line =~ m/^tag (.+)$/) {
2031 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2032 $tag{'author'} = $1;
2035 } elsif ($line =~ m/--BEGIN/) {
2036 push @comment, $line;
2038 } elsif ($line eq "") {
2042 push @comment, <$fd>;
2043 $tag{'comment'} = \
@comment;
2044 close $fd or return;
2045 if (!defined $tag{'name'}) {
2051 sub parse_commit_text
{
2052 my ($commit_text, $withparents) = @_;
2053 my @commit_lines = split '\n', $commit_text;
2056 pop @commit_lines; # Remove '\0'
2058 if (! @commit_lines) {
2062 my $header = shift @commit_lines;
2063 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2066 ($co{'id'}, my @parents) = split ' ', $header;
2067 while (my $line = shift @commit_lines) {
2068 last if $line eq "\n";
2069 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2071 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2073 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2075 $co{'author_epoch'} = $2;
2076 $co{'author_tz'} = $3;
2077 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2078 $co{'author_name'} = $1;
2079 $co{'author_email'} = $2;
2081 $co{'author_name'} = $co{'author'};
2083 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2084 $co{'committer'} = $1;
2085 $co{'committer_epoch'} = $2;
2086 $co{'committer_tz'} = $3;
2087 $co{'committer_name'} = $co{'committer'};
2088 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2089 $co{'committer_name'} = $1;
2090 $co{'committer_email'} = $2;
2092 $co{'committer_name'} = $co{'committer'};
2096 if (!defined $co{'tree'}) {
2099 $co{'parents'} = \
@parents;
2100 $co{'parent'} = $parents[0];
2102 foreach my $title (@commit_lines) {
2105 $co{'title'} = chop_str
($title, 80, 5);
2106 # remove leading stuff of merges to make the interesting part visible
2107 if (length($title) > 50) {
2108 $title =~ s/^Automatic //;
2109 $title =~ s/^merge (of|with) /Merge ... /i;
2110 if (length($title) > 50) {
2111 $title =~ s/(http|rsync):\/\///;
2113 if (length($title) > 50) {
2114 $title =~ s/(master|www|rsync)\.//;
2116 if (length($title) > 50) {
2117 $title =~ s/kernel.org:?//;
2119 if (length($title) > 50) {
2120 $title =~ s/\/pub\/scm//;
2123 $co{'title_short'} = chop_str
($title, 50, 5);
2127 if (! defined $co{'title'} || $co{'title'} eq "") {
2128 $co{'title'} = $co{'title_short'} = '(no commit message)';
2130 # remove added spaces
2131 foreach my $line (@commit_lines) {
2134 $co{'comment'} = \
@commit_lines;
2136 my $age = time - $co{'committer_epoch'};
2138 $co{'age_string'} = age_string
($age);
2139 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2140 if ($age > 60*60*24*7*2) {
2141 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2142 $co{'age_string_age'} = $co{'age_string'};
2144 $co{'age_string_date'} = $co{'age_string'};
2145 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2151 my ($commit_id) = @_;
2156 open my $fd, "-|", git_cmd
(), "rev-list",
2162 or die_error
(500, "Open git-rev-list failed");
2163 %co = parse_commit_text
(<$fd>, 1);
2170 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2178 open my $fd, "-|", git_cmd
(), "rev-list",
2181 ("--max-count=" . $maxcount),
2182 ("--skip=" . $skip),
2186 ($filename ? ($filename) : ())
2187 or die_error
(500, "Open git-rev-list failed");
2188 while (my $line = <$fd>) {
2189 my %co = parse_commit_text
($line);
2194 return wantarray ? @cos : \
@cos;
2197 # parse line of git-diff-tree "raw" output
2198 sub parse_difftree_raw_line
{
2202 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2203 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2204 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2205 $res{'from_mode'} = $1;
2206 $res{'to_mode'} = $2;
2207 $res{'from_id'} = $3;
2209 $res{'status'} = $5;
2210 $res{'similarity'} = $6;
2211 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2212 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2214 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2217 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2218 # combined diff (for merge commit)
2219 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2220 $res{'nparents'} = length($1);
2221 $res{'from_mode'} = [ split(' ', $2) ];
2222 $res{'to_mode'} = pop @{$res{'from_mode'}};
2223 $res{'from_id'} = [ split(' ', $3) ];
2224 $res{'to_id'} = pop @{$res{'from_id'}};
2225 $res{'status'} = [ split('', $4) ];
2226 $res{'to_file'} = unquote
($5);
2228 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2229 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2230 $res{'commit'} = $1;
2233 return wantarray ? %res : \
%res;
2236 # wrapper: return parsed line of git-diff-tree "raw" output
2237 # (the argument might be raw line, or parsed info)
2238 sub parsed_difftree_line
{
2239 my $line_or_ref = shift;
2241 if (ref($line_or_ref) eq "HASH") {
2242 # pre-parsed (or generated by hand)
2243 return $line_or_ref;
2245 return parse_difftree_raw_line
($line_or_ref);
2249 # parse line of git-ls-tree output
2250 sub parse_ls_tree_line
($;%) {
2255 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2256 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2264 $res{'name'} = unquote
($4);
2267 return wantarray ? %res : \
%res;
2270 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2271 sub parse_from_to_diffinfo
{
2272 my ($diffinfo, $from, $to, @parents) = @_;
2274 if ($diffinfo->{'nparents'}) {
2276 $from->{'file'} = [];
2277 $from->{'href'} = [];
2278 fill_from_file_info
($diffinfo, @parents)
2279 unless exists $diffinfo->{'from_file'};
2280 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2281 $from->{'file'}[$i] =
2282 defined $diffinfo->{'from_file'}[$i] ?
2283 $diffinfo->{'from_file'}[$i] :
2284 $diffinfo->{'to_file'};
2285 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2286 $from->{'href'}[$i] = href
(action
=>"blob",
2287 hash_base
=>$parents[$i],
2288 hash
=>$diffinfo->{'from_id'}[$i],
2289 file_name
=>$from->{'file'}[$i]);
2291 $from->{'href'}[$i] = undef;
2295 # ordinary (not combined) diff
2296 $from->{'file'} = $diffinfo->{'from_file'};
2297 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2298 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2299 hash
=>$diffinfo->{'from_id'},
2300 file_name
=>$from->{'file'});
2302 delete $from->{'href'};
2306 $to->{'file'} = $diffinfo->{'to_file'};
2307 if (!is_deleted
($diffinfo)) { # file exists in result
2308 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2309 hash
=>$diffinfo->{'to_id'},
2310 file_name
=>$to->{'file'});
2312 delete $to->{'href'};
2316 ## ......................................................................
2317 ## parse to array of hashes functions
2319 sub git_get_heads_list
{
2323 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2324 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2325 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2328 while (my $line = <$fd>) {
2332 my ($refinfo, $committerinfo) = split(/\0/, $line);
2333 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2334 my ($committer, $epoch, $tz) =
2335 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2336 $ref_item{'fullname'} = $name;
2337 $name =~ s!^refs/heads/!!;
2339 $ref_item{'name'} = $name;
2340 $ref_item{'id'} = $hash;
2341 $ref_item{'title'} = $title || '(no commit message)';
2342 $ref_item{'epoch'} = $epoch;
2344 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2346 $ref_item{'age'} = "unknown";
2349 push @headslist, \
%ref_item;
2353 return wantarray ? @headslist : \
@headslist;
2356 sub git_get_tags_list
{
2360 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2361 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2362 '--format=%(objectname) %(objecttype) %(refname) '.
2363 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2366 while (my $line = <$fd>) {
2370 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2371 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2372 my ($creator, $epoch, $tz) =
2373 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2374 $ref_item{'fullname'} = $name;
2375 $name =~ s!^refs/tags/!!;
2377 $ref_item{'type'} = $type;
2378 $ref_item{'id'} = $id;
2379 $ref_item{'name'} = $name;
2380 if ($type eq "tag") {
2381 $ref_item{'subject'} = $title;
2382 $ref_item{'reftype'} = $reftype;
2383 $ref_item{'refid'} = $refid;
2385 $ref_item{'reftype'} = $type;
2386 $ref_item{'refid'} = $id;
2389 if ($type eq "tag" || $type eq "commit") {
2390 $ref_item{'epoch'} = $epoch;
2392 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2394 $ref_item{'age'} = "unknown";
2398 push @tagslist, \
%ref_item;
2402 return wantarray ? @tagslist : \
@tagslist;
2405 ## ----------------------------------------------------------------------
2406 ## filesystem-related functions
2408 sub get_file_owner
{
2411 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2412 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2413 if (!defined $gcos) {
2417 $owner =~ s/[,;].*$//;
2418 return to_utf8
($owner);
2421 ## ......................................................................
2422 ## mimetype related functions
2424 sub mimetype_guess_file
{
2425 my $filename = shift;
2426 my $mimemap = shift;
2427 -r
$mimemap or return undef;
2430 open(MIME
, $mimemap) or return undef;
2432 next if m/^#/; # skip comments
2433 my ($mime, $exts) = split(/\t+/);
2434 if (defined $exts) {
2435 my @exts = split(/\s+/, $exts);
2436 foreach my $ext (@exts) {
2437 $mimemap{$ext} = $mime;
2443 $filename =~ /\.([^.]*)$/;
2444 return $mimemap{$1};
2447 sub mimetype_guess
{
2448 my $filename = shift;
2450 $filename =~ /\./ or return undef;
2452 if ($mimetypes_file) {
2453 my $file = $mimetypes_file;
2454 if ($file !~ m!^/!) { # if it is relative path
2455 # it is relative to project
2456 $file = "$projectroot/$project/$file";
2458 $mime = mimetype_guess_file
($filename, $file);
2460 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2466 my $filename = shift;
2469 my $mime = mimetype_guess
($filename);
2470 $mime and return $mime;
2474 return $default_blob_plain_mimetype unless $fd;
2477 return 'text/plain';
2478 } elsif (! $filename) {
2479 return 'application/octet-stream';
2480 } elsif ($filename =~ m/\.png$/i) {
2482 } elsif ($filename =~ m/\.gif$/i) {
2484 } elsif ($filename =~ m/\.jpe?g$/i) {
2485 return 'image/jpeg';
2487 return 'application/octet-stream';
2491 sub blob_contenttype
{
2492 my ($fd, $file_name, $type) = @_;
2494 $type ||= blob_mimetype
($fd, $file_name);
2495 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2496 $type .= "; charset=$default_text_plain_charset";
2502 ## ======================================================================
2503 ## functions printing HTML: header, footer, error page
2505 sub git_header_html
{
2506 my $status = shift || "200 OK";
2507 my $expires = shift;
2509 my $title = "$site_name";
2510 if (defined $project) {
2511 $title .= " - " . to_utf8
($project);
2512 if (defined $action) {
2513 $title .= "/$action";
2514 if (defined $file_name) {
2515 $title .= " - " . esc_path
($file_name);
2516 if ($action eq "tree" && $file_name !~ m
|/$|) {
2523 # require explicit support from the UA if we are to send the page as
2524 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2525 # we have to do this because MSIE sometimes globs '*/*', pretending to
2526 # support xhtml+xml but choking when it gets what it asked for.
2527 if (defined $cgi->http('HTTP_ACCEPT') &&
2528 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2529 $cgi->Accept('application/xhtml+xml') != 0) {
2530 $content_type = 'application/xhtml+xml';
2532 $content_type = 'text/html';
2534 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2535 -status
=> $status, -expires
=> $expires);
2536 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2538 <?xml version="1.0" encoding="utf-8"?>
2539 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2540 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2541 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2542 <!-- git core binaries version $git_version -->
2544 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2545 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2546 <meta name="robots" content="index, nofollow"/>
2547 <title>$title</title>
2549 # print out each stylesheet that exist
2550 if (defined $stylesheet) {
2551 #provides backwards capability for those people who define style sheet in a config file
2552 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2554 foreach my $stylesheet (@stylesheets) {
2555 next unless $stylesheet;
2556 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2559 if (defined $project) {
2560 my %href_params = get_feed_info
();
2561 if (!exists $href_params{'-title'}) {
2562 $href_params{'-title'} = 'log';
2565 foreach my $format qw(RSS Atom) {
2566 my $type = lc($format);
2568 '-rel' => 'alternate',
2569 '-title' => "$project - $href_params{'-title'} - $format feed",
2570 '-type' => "application/$type+xml"
2573 $href_params{'action'} = $type;
2574 $link_attr{'-href'} = href
(%href_params);
2576 "rel=\"$link_attr{'-rel'}\" ".
2577 "title=\"$link_attr{'-title'}\" ".
2578 "href=\"$link_attr{'-href'}\" ".
2579 "type=\"$link_attr{'-type'}\" ".
2582 $href_params{'extra_options'} = '--no-merges';
2583 $link_attr{'-href'} = href
(%href_params);
2584 $link_attr{'-title'} .= ' (no merges)';
2586 "rel=\"$link_attr{'-rel'}\" ".
2587 "title=\"$link_attr{'-title'}\" ".
2588 "href=\"$link_attr{'-href'}\" ".
2589 "type=\"$link_attr{'-type'}\" ".
2594 printf('<link rel="alternate" title="%s projects list" '.
2595 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2596 $site_name, href
(project
=>undef, action
=>"project_index"));
2597 printf('<link rel="alternate" title="%s projects feeds" '.
2598 'href="%s" type="text/x-opml" />'."\n",
2599 $site_name, href
(project
=>undef, action
=>"opml"));
2601 if (defined $favicon) {
2602 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2608 if (-f
$site_header) {
2609 open (my $fd, $site_header);
2614 print "<div class=\"page_header\">\n" .
2615 $cgi->a({-href
=> esc_url
($logo_url),
2616 -title
=> $logo_label},
2617 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2618 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2619 if (defined $project) {
2620 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2621 if (defined $action) {
2628 my ($have_search) = gitweb_check_feature
('search');
2629 if (defined $project && $have_search) {
2630 if (!defined $searchtext) {
2634 if (defined $hash_base) {
2635 $search_hash = $hash_base;
2636 } elsif (defined $hash) {
2637 $search_hash = $hash;
2639 $search_hash = "HEAD";
2641 my $action = $my_uri;
2642 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2643 if ($use_pathinfo) {
2644 $action .= "/".esc_url
($project);
2646 print $cgi->startform(-method => "get", -action
=> $action) .
2647 "<div class=\"search\">\n" .
2649 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2650 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2651 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2652 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2653 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2654 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2656 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2657 "<span title=\"Extended regular expression\">" .
2658 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2659 -checked
=> $search_use_regexp) .
2662 $cgi->end_form() . "\n";
2666 sub git_footer_html
{
2667 my $feed_class = 'rss_logo';
2669 print "<div class=\"page_footer\">\n";
2670 if (defined $project) {
2671 my $descr = git_get_project_description
($project);
2672 if (defined $descr) {
2673 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2676 my %href_params = get_feed_info
();
2677 if (!%href_params) {
2678 $feed_class .= ' generic';
2680 $href_params{'-title'} ||= 'log';
2682 foreach my $format qw(RSS Atom) {
2683 $href_params{'action'} = lc($format);
2684 print $cgi->a({-href
=> href
(%href_params),
2685 -title
=> "$href_params{'-title'} $format feed",
2686 -class => $feed_class}, $format)."\n";
2690 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2691 -class => $feed_class}, "OPML") . " ";
2692 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2693 -class => $feed_class}, "TXT") . "\n";
2695 print "</div>\n"; # class="page_footer"
2697 if (-f
$site_footer) {
2698 open (my $fd, $site_footer);
2707 # die_error(<http_status_code>, <error_message>)
2708 # Example: die_error(404, 'Hash not found')
2709 # By convention, use the following status codes (as defined in RFC 2616):
2710 # 400: Invalid or missing CGI parameters, or
2711 # requested object exists but has wrong type.
2712 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2713 # this server or project.
2714 # 404: Requested object/revision/project doesn't exist.
2715 # 500: The server isn't configured properly, or
2716 # an internal error occurred (e.g. failed assertions caused by bugs), or
2717 # an unknown error occurred (e.g. the git binary died unexpectedly).
2719 my $status = shift || 500;
2720 my $error = shift || "Internal server error";
2722 my %http_responses = (400 => '400 Bad Request',
2723 403 => '403 Forbidden',
2724 404 => '404 Not Found',
2725 500 => '500 Internal Server Error');
2726 git_header_html
($http_responses{$status});
2728 <div class="page_body">
2738 ## ----------------------------------------------------------------------
2739 ## functions printing or outputting HTML: navigation
2741 sub git_print_page_nav
{
2742 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2743 $extra = '' if !defined $extra; # pager or formats
2745 my @navs = qw(summary shortlog log commit commitdiff tree);
2747 @navs = grep { $_ ne $suppress } @navs;
2750 my %arg = map { $_ => {action
=>$_} } @navs;
2751 if (defined $head) {
2752 for (qw(commit commitdiff)) {
2753 $arg{$_}{'hash'} = $head;
2755 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2756 for (qw(shortlog log)) {
2757 $arg{$_}{'hash'} = $head;
2761 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2762 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2764 print "<div class=\"page_nav\">\n" .
2766 map { $_ eq $current ?
2767 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2769 print "<br/>\n$extra<br/>\n" .
2773 sub format_paging_nav
{
2774 my ($action, $hash, $head, $page, $has_next_link) = @_;
2778 if ($hash ne $head || $page) {
2779 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2781 $paging_nav .= "HEAD";
2785 $paging_nav .= " ⋅ " .
2786 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2787 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2789 $paging_nav .= " ⋅ prev";
2792 if ($has_next_link) {
2793 $paging_nav .= " ⋅ " .
2794 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2795 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2797 $paging_nav .= " ⋅ next";
2803 ## ......................................................................
2804 ## functions printing or outputting HTML: div
2806 sub git_print_header_div
{
2807 my ($action, $title, $hash, $hash_base) = @_;
2810 $args{'action'} = $action;
2811 $args{'hash'} = $hash if $hash;
2812 $args{'hash_base'} = $hash_base if $hash_base;
2814 print "<div class=\"header\">\n" .
2815 $cgi->a({-href
=> href
(%args), -class => "title"},
2816 $title ? $title : $action) .
2820 #sub git_print_authorship (\%) {
2821 sub git_print_authorship
{
2824 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2825 print "<div class=\"author_date\">" .
2826 esc_html
($co->{'author_name'}) .
2828 if ($ad{'hour_local'} < 6) {
2829 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2830 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2832 printf(" (%02d:%02d %s)",
2833 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2838 sub git_print_page_path
{
2844 print "<div class=\"page_path\">";
2845 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2846 -title
=> 'tree root'}, to_utf8
("[$project]"));
2848 if (defined $name) {
2849 my @dirname = split '/', $name;
2850 my $basename = pop @dirname;
2853 foreach my $dir (@dirname) {
2854 $fullname .= ($fullname ? '/' : '') . $dir;
2855 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2857 -title
=> $fullname}, esc_path
($dir));
2860 if (defined $type && $type eq 'blob') {
2861 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2863 -title
=> $name}, esc_path
($basename));
2864 } elsif (defined $type && $type eq 'tree') {
2865 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2867 -title
=> $name}, esc_path
($basename));
2870 print esc_path
($basename);
2873 print "<br/></div>\n";
2876 # sub git_print_log (\@;%) {
2877 sub git_print_log
($;%) {
2881 if ($opts{'-remove_title'}) {
2882 # remove title, i.e. first line of log
2885 # remove leading empty lines
2886 while (defined $log->[0] && $log->[0] eq "") {
2893 foreach my $line (@$log) {
2894 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2897 if (! $opts{'-remove_signoff'}) {
2898 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2901 # remove signoff lines
2908 # print only one empty line
2909 # do not print empty line after signoff
2911 next if ($empty || $signoff);
2917 print format_log_line_html
($line) . "<br/>\n";
2920 if ($opts{'-final_empty_line'}) {
2921 # end with single empty line
2922 print "<br/>\n" unless $empty;
2926 # return link target (what link points to)
2927 sub git_get_link_target
{
2932 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2936 $link_target = <$fd>;
2941 return $link_target;
2944 # given link target, and the directory (basedir) the link is in,
2945 # return target of link relative to top directory (top tree);
2946 # return undef if it is not possible (including absolute links).
2947 sub normalize_link_target
{
2948 my ($link_target, $basedir, $hash_base) = @_;
2950 # we can normalize symlink target only if $hash_base is provided
2951 return unless $hash_base;
2953 # absolute symlinks (beginning with '/') cannot be normalized
2954 return if (substr($link_target, 0, 1) eq '/');
2956 # normalize link target to path from top (root) tree (dir)
2959 $path = $basedir . '/' . $link_target;
2961 # we are in top (root) tree (dir)
2962 $path = $link_target;
2965 # remove //, /./, and /../
2967 foreach my $part (split('/', $path)) {
2968 # discard '.' and ''
2969 next if (!$part || $part eq '.');
2971 if ($part eq '..') {
2975 # link leads outside repository (outside top dir)
2979 push @path_parts, $part;
2982 $path = join('/', @path_parts);
2987 # print tree entry (row of git_tree), but without encompassing <tr> element
2988 sub git_print_tree_entry
{
2989 my ($t, $basedir, $hash_base, $have_blame) = @_;
2992 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2994 # The format of a table row is: mode list link. Where mode is
2995 # the mode of the entry, list is the name of the entry, an href,
2996 # and link is the action links of the entry.
2998 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2999 if ($t->{'type'} eq "blob") {
3000 print "<td class=\"list\">" .
3001 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3002 file_name
=>"$basedir$t->{'name'}", %base_key),
3003 -class => "list"}, esc_path
($t->{'name'}));
3004 if (S_ISLNK
(oct $t->{'mode'})) {
3005 my $link_target = git_get_link_target
($t->{'hash'});
3007 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3008 if (defined $norm_target) {
3010 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3011 file_name
=>$norm_target),
3012 -title
=> $norm_target}, esc_path
($link_target));
3014 print " -> " . esc_path
($link_target);
3019 print "<td class=\"link\">";
3020 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3021 file_name
=>"$basedir$t->{'name'}", %base_key)},
3025 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3026 file_name
=>"$basedir$t->{'name'}", %base_key)},
3029 if (defined $hash_base) {
3031 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3032 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3036 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3037 file_name
=>"$basedir$t->{'name'}")},
3041 } elsif ($t->{'type'} eq "tree") {
3042 print "<td class=\"list\">";
3043 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3044 file_name
=>"$basedir$t->{'name'}", %base_key)},
3045 esc_path
($t->{'name'}));
3047 print "<td class=\"link\">";
3048 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3049 file_name
=>"$basedir$t->{'name'}", %base_key)},
3051 if (defined $hash_base) {
3053 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3054 file_name
=>"$basedir$t->{'name'}")},
3059 # unknown object: we can only present history for it
3060 # (this includes 'commit' object, i.e. submodule support)
3061 print "<td class=\"list\">" .
3062 esc_path
($t->{'name'}) .
3064 print "<td class=\"link\">";
3065 if (defined $hash_base) {
3066 print $cgi->a({-href
=> href
(action
=>"history",
3067 hash_base
=>$hash_base,
3068 file_name
=>"$basedir$t->{'name'}")},
3075 ## ......................................................................
3076 ## functions printing large fragments of HTML
3078 # get pre-image filenames for merge (combined) diff
3079 sub fill_from_file_info
{
3080 my ($diff, @parents) = @_;
3082 $diff->{'from_file'} = [ ];
3083 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3084 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3085 if ($diff->{'status'}[$i] eq 'R' ||
3086 $diff->{'status'}[$i] eq 'C') {
3087 $diff->{'from_file'}[$i] =
3088 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3095 # is current raw difftree line of file deletion
3097 my $diffinfo = shift;
3099 return $diffinfo->{'to_id'} eq ('0' x
40);
3102 # does patch correspond to [previous] difftree raw line
3103 # $diffinfo - hashref of parsed raw diff format
3104 # $patchinfo - hashref of parsed patch diff format
3105 # (the same keys as in $diffinfo)
3106 sub is_patch_split
{
3107 my ($diffinfo, $patchinfo) = @_;
3109 return defined $diffinfo && defined $patchinfo
3110 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3114 sub git_difftree_body
{
3115 my ($difftree, $hash, @parents) = @_;
3116 my ($parent) = $parents[0];
3117 my ($have_blame) = gitweb_check_feature
('blame');
3118 print "<div class=\"list_head\">\n";
3119 if ($#{$difftree} > 10) {
3120 print(($#{$difftree} + 1) . " files changed:\n");
3124 print "<table class=\"" .
3125 (@parents > 1 ? "combined " : "") .
3128 # header only for combined diff in 'commitdiff' view
3129 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3132 print "<thead><tr>\n" .
3133 "<th></th><th></th>\n"; # filename, patchN link
3134 for (my $i = 0; $i < @parents; $i++) {
3135 my $par = $parents[$i];
3137 $cgi->a({-href
=> href
(action
=>"commitdiff",
3138 hash
=>$hash, hash_parent
=>$par),
3139 -title
=> 'commitdiff to parent number ' .
3140 ($i+1) . ': ' . substr($par,0,7)},
3144 print "</tr></thead>\n<tbody>\n";
3149 foreach my $line (@{$difftree}) {
3150 my $diff = parsed_difftree_line
($line);
3153 print "<tr class=\"dark\">\n";
3155 print "<tr class=\"light\">\n";
3159 if (exists $diff->{'nparents'}) { # combined diff
3161 fill_from_file_info
($diff, @parents)
3162 unless exists $diff->{'from_file'};
3164 if (!is_deleted
($diff)) {
3165 # file exists in the result (child) commit
3167 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3168 file_name
=>$diff->{'to_file'},
3170 -class => "list"}, esc_path
($diff->{'to_file'})) .
3174 esc_path
($diff->{'to_file'}) .
3178 if ($action eq 'commitdiff') {
3181 print "<td class=\"link\">" .
3182 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3187 my $has_history = 0;
3188 my $not_deleted = 0;
3189 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3190 my $hash_parent = $parents[$i];
3191 my $from_hash = $diff->{'from_id'}[$i];
3192 my $from_path = $diff->{'from_file'}[$i];
3193 my $status = $diff->{'status'}[$i];
3195 $has_history ||= ($status ne 'A');
3196 $not_deleted ||= ($status ne 'D');
3198 if ($status eq 'A') {
3199 print "<td class=\"link\" align=\"right\"> | </td>\n";
3200 } elsif ($status eq 'D') {
3201 print "<td class=\"link\">" .
3202 $cgi->a({-href
=> href
(action
=>"blob",
3205 file_name
=>$from_path)},
3209 if ($diff->{'to_id'} eq $from_hash) {
3210 print "<td class=\"link nochange\">";
3212 print "<td class=\"link\">";
3214 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3215 hash
=>$diff->{'to_id'},
3216 hash_parent
=>$from_hash,
3218 hash_parent_base
=>$hash_parent,
3219 file_name
=>$diff->{'to_file'},
3220 file_parent
=>$from_path)},
3226 print "<td class=\"link\">";
3228 print $cgi->a({-href
=> href
(action
=>"blob",
3229 hash
=>$diff->{'to_id'},
3230 file_name
=>$diff->{'to_file'},
3233 print " | " if ($has_history);
3236 print $cgi->a({-href
=> href
(action
=>"history",
3237 file_name
=>$diff->{'to_file'},
3244 next; # instead of 'else' clause, to avoid extra indent
3246 # else ordinary diff
3248 my ($to_mode_oct, $to_mode_str, $to_file_type);
3249 my ($from_mode_oct, $from_mode_str, $from_file_type);
3250 if ($diff->{'to_mode'} ne ('0' x
6)) {
3251 $to_mode_oct = oct $diff->{'to_mode'};
3252 if (S_ISREG
($to_mode_oct)) { # only for regular file
3253 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3255 $to_file_type = file_type
($diff->{'to_mode'});
3257 if ($diff->{'from_mode'} ne ('0' x
6)) {
3258 $from_mode_oct = oct $diff->{'from_mode'};
3259 if (S_ISREG
($to_mode_oct)) { # only for regular file
3260 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3262 $from_file_type = file_type
($diff->{'from_mode'});
3265 if ($diff->{'status'} eq "A") { # created
3266 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3267 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3268 $mode_chng .= "]</span>";
3270 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3271 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3272 -class => "list"}, esc_path
($diff->{'file'}));
3274 print "<td>$mode_chng</td>\n";
3275 print "<td class=\"link\">";
3276 if ($action eq 'commitdiff') {
3279 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3282 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3283 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3287 } elsif ($diff->{'status'} eq "D") { # deleted
3288 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3290 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3291 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3292 -class => "list"}, esc_path
($diff->{'file'}));
3294 print "<td>$mode_chng</td>\n";
3295 print "<td class=\"link\">";
3296 if ($action eq 'commitdiff') {
3299 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3302 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3303 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3306 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3307 file_name
=>$diff->{'file'})},
3310 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3311 file_name
=>$diff->{'file'})},
3315 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3316 my $mode_chnge = "";
3317 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3318 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3319 if ($from_file_type ne $to_file_type) {
3320 $mode_chnge .= " from $from_file_type to $to_file_type";
3322 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3323 if ($from_mode_str && $to_mode_str) {
3324 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3325 } elsif ($to_mode_str) {
3326 $mode_chnge .= " mode: $to_mode_str";
3329 $mode_chnge .= "]</span>\n";
3332 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3333 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3334 -class => "list"}, esc_path
($diff->{'file'}));
3336 print "<td>$mode_chnge</td>\n";
3337 print "<td class=\"link\">";
3338 if ($action eq 'commitdiff') {
3341 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3343 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3344 # "commit" view and modified file (not onlu mode changed)
3345 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3346 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3347 hash_base
=>$hash, hash_parent_base
=>$parent,
3348 file_name
=>$diff->{'file'})},
3352 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3353 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3356 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3357 file_name
=>$diff->{'file'})},
3360 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3361 file_name
=>$diff->{'file'})},
3365 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3366 my %status_name = ('R' => 'moved', 'C' => 'copied');
3367 my $nstatus = $status_name{$diff->{'status'}};
3369 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3370 # mode also for directories, so we cannot use $to_mode_str
3371 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3374 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3375 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3376 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3377 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3378 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3379 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3380 -class => "list"}, esc_path
($diff->{'from_file'})) .
3381 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3382 "<td class=\"link\">";
3383 if ($action eq 'commitdiff') {
3386 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3388 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3389 # "commit" view and modified file (not only pure rename or copy)
3390 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3391 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3392 hash_base
=>$hash, hash_parent_base
=>$parent,
3393 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3397 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3398 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3401 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3402 file_name
=>$diff->{'to_file'})},
3405 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3406 file_name
=>$diff->{'to_file'})},
3410 } # we should not encounter Unmerged (U) or Unknown (X) status
3413 print "</tbody>" if $has_header;
3417 sub git_patchset_body
{
3418 my ($fd, $difftree, $hash, @hash_parents) = @_;
3419 my ($hash_parent) = $hash_parents[0];
3421 my $is_combined = (@hash_parents > 1);
3423 my $patch_number = 0;
3429 print "<div class=\"patchset\">\n";
3431 # skip to first patch
3432 while ($patch_line = <$fd>) {
3435 last if ($patch_line =~ m/^diff /);
3439 while ($patch_line) {
3441 # parse "git diff" header line
3442 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3443 # $1 is from_name, which we do not use
3444 $to_name = unquote
($2);
3445 $to_name =~ s!^b/!!;
3446 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3447 # $1 is 'cc' or 'combined', which we do not use
3448 $to_name = unquote
($2);
3453 # check if current patch belong to current raw line
3454 # and parse raw git-diff line if needed
3455 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3456 # this is continuation of a split patch
3457 print "<div class=\"patch cont\">\n";
3459 # advance raw git-diff output if needed
3460 $patch_idx++ if defined $diffinfo;
3462 # read and prepare patch information
3463 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3465 # compact combined diff output can have some patches skipped
3466 # find which patch (using pathname of result) we are at now;
3468 while ($to_name ne $diffinfo->{'to_file'}) {
3469 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3470 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3471 "</div>\n"; # class="patch"
3476 last if $patch_idx > $#$difftree;
3477 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3481 # modifies %from, %to hashes
3482 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3484 # this is first patch for raw difftree line with $patch_idx index
3485 # we index @$difftree array from 0, but number patches from 1
3486 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3490 #assert($patch_line =~ m/^diff /) if DEBUG;
3491 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3493 # print "git diff" header
3494 print format_git_diff_header_line
($patch_line, $diffinfo,
3497 # print extended diff header
3498 print "<div class=\"diff extended_header\">\n";
3500 while ($patch_line = <$fd>) {
3503 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3505 print format_extended_diff_header_line
($patch_line, $diffinfo,
3508 print "</div>\n"; # class="diff extended_header"
3510 # from-file/to-file diff header
3511 if (! $patch_line) {
3512 print "</div>\n"; # class="patch"
3515 next PATCH
if ($patch_line =~ m/^diff /);
3516 #assert($patch_line =~ m/^---/) if DEBUG;
3518 my $last_patch_line = $patch_line;
3519 $patch_line = <$fd>;
3521 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3523 print format_diff_from_to_header
($last_patch_line, $patch_line,
3524 $diffinfo, \
%from, \
%to,
3529 while ($patch_line = <$fd>) {
3532 next PATCH
if ($patch_line =~ m/^diff /);
3534 print format_diff_line
($patch_line, \
%from, \
%to);
3538 print "</div>\n"; # class="patch"
3541 # for compact combined (--cc) format, with chunk and patch simpliciaction
3542 # patchset might be empty, but there might be unprocessed raw lines
3543 for (++$patch_idx if $patch_number > 0;
3544 $patch_idx < @$difftree;
3546 # read and prepare patch information
3547 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3549 # generate anchor for "patch" links in difftree / whatchanged part
3550 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3551 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3552 "</div>\n"; # class="patch"
3557 if ($patch_number == 0) {
3558 if (@hash_parents > 1) {
3559 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3561 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3565 print "</div>\n"; # class="patchset"
3568 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3570 # fills project list info (age, description, owner, forks) for each
3571 # project in the list, removing invalid projects from returned list
3572 # NOTE: modifies $projlist, but does not remove entries from it
3573 sub fill_project_list_info
{
3574 my ($projlist, $check_forks) = @_;
3578 foreach my $pr (@$projlist) {
3579 my (@activity) = git_get_last_activity
($pr->{'path'});
3580 unless (@activity) {
3583 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3584 if (!defined $pr->{'descr'}) {
3585 my $descr = git_get_project_description
($pr->{'path'}) || "";
3586 $descr = to_utf8
($descr);
3587 $pr->{'descr_long'} = $descr;
3588 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3590 if (!defined $pr->{'owner'}) {
3591 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3594 my $pname = $pr->{'path'};
3595 if (($pname =~ s/\.git$//) &&
3596 ($pname !~ /\/$/) &&
3597 (-d
"$projectroot/$pname")) {
3598 $pr->{'forks'} = "-d $projectroot/$pname";
3603 push @projects, $pr;
3609 # print 'sort by' <th> element, either sorting by $key if $name eq $order
3610 # (changing $list), or generating 'sort by $name' replay link otherwise
3612 my ($str_sort, $name, $order, $key, $header, $list) = @_;
3614 $header ||= ucfirst($name);
3616 if ($order eq $name) {
3618 @$list = sort {$a->{$key} cmp $b->{$key}} @$list;
3620 @$list = sort {$a->{$key} <=> $b->{$key}} @$list;
3622 print "<th>$header</th>\n";
3625 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3626 -class => "header"}, $header) .
3631 sub print_sort_th_str
{
3632 print_sort_th
(1, @_);
3635 sub print_sort_th_num
{
3636 print_sort_th
(0, @_);
3639 sub git_project_list_body
{
3640 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3642 my ($check_forks) = gitweb_check_feature
('forks');
3643 my @projects = fill_project_list_info
($projlist, $check_forks);
3645 $order ||= $default_projects_order;
3646 $from = 0 unless defined $from;
3647 $to = $#projects if (!defined $to || $#projects < $to);
3649 print "<table class=\"project_list\">\n";
3650 unless ($no_header) {
3653 print "<th></th>\n";
3655 print_sort_th_str
('project', $order, 'path',
3656 'Project', \
@projects);
3657 print_sort_th_str
('descr', $order, 'descr_long',
3658 'Description', \
@projects);
3659 print_sort_th_str
('owner', $order, 'owner',
3660 'Owner', \
@projects);
3661 print_sort_th_num
('age', $order, 'age',
3662 'Last Change', \
@projects);
3663 print "<th></th>\n" . # for links
3667 for (my $i = $from; $i <= $to; $i++) {
3668 my $pr = $projects[$i];
3670 print "<tr class=\"dark\">\n";
3672 print "<tr class=\"light\">\n";
3677 if ($pr->{'forks'}) {
3678 print "<!-- $pr->{'forks'} -->\n";
3679 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3683 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3684 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3685 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3686 -class => "list", -title
=> $pr->{'descr_long'}},
3687 esc_html
($pr->{'descr'})) . "</td>\n" .
3688 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3689 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3690 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3691 "<td class=\"link\">" .
3692 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3693 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3694 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3695 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3696 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3700 if (defined $extra) {
3703 print "<td></td>\n";
3705 print "<td colspan=\"5\">$extra</td>\n" .
3711 sub git_shortlog_body
{
3712 # uses global variable $project
3713 my ($commitlist, $from, $to, $refs, $extra) = @_;
3715 $from = 0 unless defined $from;
3716 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3718 print "<table class=\"shortlog\">\n";
3720 for (my $i = $from; $i <= $to; $i++) {
3721 my %co = %{$commitlist->[$i]};
3722 my $commit = $co{'id'};
3723 my $ref = format_ref_marker
($refs, $commit);
3725 print "<tr class=\"dark\">\n";
3727 print "<tr class=\"light\">\n";
3730 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3731 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3732 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3733 "<td><i>" . $author . "</i></td>\n" .
3735 print format_subject_html
($co{'title'}, $co{'title_short'},
3736 href
(action
=>"commit", hash
=>$commit), $ref);
3738 "<td class=\"link\">" .
3739 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3740 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3741 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3742 my $snapshot_links = format_snapshot_links
($commit);
3743 if (defined $snapshot_links) {
3744 print " | " . $snapshot_links;
3749 if (defined $extra) {
3751 "<td colspan=\"4\">$extra</td>\n" .
3757 sub git_history_body
{
3758 # Warning: assumes constant type (blob or tree) during history
3759 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3761 $from = 0 unless defined $from;
3762 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3764 print "<table class=\"history\">\n";
3766 for (my $i = $from; $i <= $to; $i++) {
3767 my %co = %{$commitlist->[$i]};
3771 my $commit = $co{'id'};
3773 my $ref = format_ref_marker
($refs, $commit);
3776 print "<tr class=\"dark\">\n";
3778 print "<tr class=\"light\">\n";
3781 # shortlog uses chop_str($co{'author_name'}, 10)
3782 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3783 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3784 "<td><i>" . $author . "</i></td>\n" .
3786 # originally git_history used chop_str($co{'title'}, 50)
3787 print format_subject_html
($co{'title'}, $co{'title_short'},
3788 href
(action
=>"commit", hash
=>$commit), $ref);
3790 "<td class=\"link\">" .
3791 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3792 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3794 if ($ftype eq 'blob') {
3795 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3796 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3797 if (defined $blob_current && defined $blob_parent &&
3798 $blob_current ne $blob_parent) {
3800 $cgi->a({-href
=> href
(action
=>"blobdiff",
3801 hash
=>$blob_current, hash_parent
=>$blob_parent,
3802 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3803 file_name
=>$file_name)},
3810 if (defined $extra) {
3812 "<td colspan=\"4\">$extra</td>\n" .
3819 # uses global variable $project
3820 my ($taglist, $from, $to, $extra) = @_;
3821 $from = 0 unless defined $from;
3822 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3824 print "<table class=\"tags\">\n";
3826 for (my $i = $from; $i <= $to; $i++) {
3827 my $entry = $taglist->[$i];
3829 my $comment = $tag{'subject'};
3831 if (defined $comment) {
3832 $comment_short = chop_str
($comment, 30, 5);
3835 print "<tr class=\"dark\">\n";
3837 print "<tr class=\"light\">\n";
3840 if (defined $tag{'age'}) {
3841 print "<td><i>$tag{'age'}</i></td>\n";
3843 print "<td></td>\n";
3846 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3847 -class => "list name"}, esc_html
($tag{'name'})) .
3850 if (defined $comment) {
3851 print format_subject_html
($comment, $comment_short,
3852 href
(action
=>"tag", hash
=>$tag{'id'}));
3855 "<td class=\"selflink\">";
3856 if ($tag{'type'} eq "tag") {
3857 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3862 "<td class=\"link\">" . " | " .
3863 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3864 if ($tag{'reftype'} eq "commit") {
3865 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3866 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3867 } elsif ($tag{'reftype'} eq "blob") {
3868 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3873 if (defined $extra) {
3875 "<td colspan=\"5\">$extra</td>\n" .
3881 sub git_heads_body
{
3882 # uses global variable $project
3883 my ($headlist, $head, $from, $to, $extra) = @_;
3884 $from = 0 unless defined $from;
3885 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3887 print "<table class=\"heads\">\n";
3889 for (my $i = $from; $i <= $to; $i++) {
3890 my $entry = $headlist->[$i];
3892 my $curr = $ref{'id'} eq $head;
3894 print "<tr class=\"dark\">\n";
3896 print "<tr class=\"light\">\n";
3899 print "<td><i>$ref{'age'}</i></td>\n" .
3900 ($curr ? "<td class=\"current_head\">" : "<td>") .
3901 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3902 -class => "list name"},esc_html
($ref{'name'})) .
3904 "<td class=\"link\">" .
3905 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3906 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3907 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3911 if (defined $extra) {
3913 "<td colspan=\"3\">$extra</td>\n" .
3919 sub git_search_grep_body
{
3920 my ($commitlist, $from, $to, $extra) = @_;
3921 $from = 0 unless defined $from;
3922 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3924 print "<table class=\"commit_search\">\n";
3926 for (my $i = $from; $i <= $to; $i++) {
3927 my %co = %{$commitlist->[$i]};
3931 my $commit = $co{'id'};
3933 print "<tr class=\"dark\">\n";
3935 print "<tr class=\"light\">\n";
3938 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3939 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3940 "<td><i>" . $author . "</i></td>\n" .
3942 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3943 -class => "list subject"},
3944 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3945 my $comment = $co{'comment'};
3946 foreach my $line (@$comment) {
3947 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3948 my ($lead, $match, $trail) = ($1, $2, $3);
3949 $match = chop_str
($match, 70, 5, 'center');
3950 my $contextlen = int((80 - length($match))/2);
3951 $contextlen = 30 if ($contextlen > 30);
3952 $lead = chop_str
($lead, $contextlen, 10, 'left');
3953 $trail = chop_str
($trail, $contextlen, 10, 'right');
3955 $lead = esc_html
($lead);
3956 $match = esc_html
($match);
3957 $trail = esc_html
($trail);
3959 print "$lead<span class=\"match\">$match</span>$trail<br />";
3963 "<td class=\"link\">" .
3964 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3966 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3968 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3972 if (defined $extra) {
3974 "<td colspan=\"3\">$extra</td>\n" .
3980 ## ======================================================================
3981 ## ======================================================================
3984 sub git_project_list
{
3985 my $order = $cgi->param('o');
3986 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3987 die_error
(400, "Unknown order parameter");
3990 my @list = git_get_projects_list
();
3992 die_error
(404, "No projects found");
3996 if (-f
$home_text) {
3997 print "<div class=\"index_include\">\n";
3998 open (my $fd, $home_text);
4003 git_project_list_body
(\
@list, $order);
4008 my $order = $cgi->param('o');
4009 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4010 die_error
(400, "Unknown order parameter");
4013 my @list = git_get_projects_list
($project);
4015 die_error
(404, "No forks found");
4019 git_print_page_nav
('','');
4020 git_print_header_div
('summary', "$project forks");
4021 git_project_list_body
(\
@list, $order);
4025 sub git_project_index
{
4026 my @projects = git_get_projects_list
($project);
4029 -type
=> 'text/plain',
4030 -charset
=> 'utf-8',
4031 -content_disposition
=> 'inline; filename="index.aux"');
4033 foreach my $pr (@projects) {
4034 if (!exists $pr->{'owner'}) {
4035 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4038 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4039 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4040 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4041 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4045 print "$path $owner\n";
4050 my $descr = git_get_project_description
($project) || "none";
4051 my %co = parse_commit
("HEAD");
4052 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4053 my $head = $co{'id'};
4055 my $owner = git_get_project_owner
($project);
4057 my $refs = git_get_references
();
4058 # These get_*_list functions return one more to allow us to see if
4059 # there are more ...
4060 my @taglist = git_get_tags_list
(16);
4061 my @headlist = git_get_heads_list
(16);
4063 my ($check_forks) = gitweb_check_feature
('forks');
4066 @forklist = git_get_projects_list
($project);
4070 git_print_page_nav
('summary','', $head);
4072 print "<div class=\"title\"> </div>\n";
4073 print "<table class=\"projects_list\">\n" .
4074 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4075 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4076 if (defined $cd{'rfc2822'}) {
4077 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4080 # use per project git URL list in $projectroot/$project/cloneurl
4081 # or make project git URL from git base URL and project name
4082 my $url_tag = "URL";
4083 my @url_list = git_get_project_url_list
($project);
4084 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4085 foreach my $git_url (@url_list) {
4086 next unless $git_url;
4087 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4092 if (-s
"$projectroot/$project/README.html") {
4093 if (open my $fd, "$projectroot/$project/README.html") {
4094 print "<div class=\"title\">readme</div>\n" .
4095 "<div class=\"readme\">\n";
4096 print $_ while (<$fd>);
4097 print "\n</div>\n"; # class="readme"
4102 # we need to request one more than 16 (0..15) to check if
4104 my @commitlist = $head ? parse_commits
($head, 17) : ();
4106 git_print_header_div
('shortlog');
4107 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4108 $#commitlist <= 15 ? undef :
4109 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4113 git_print_header_div
('tags');
4114 git_tags_body
(\
@taglist, 0, 15,
4115 $#taglist <= 15 ? undef :
4116 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4120 git_print_header_div
('heads');
4121 git_heads_body
(\
@headlist, $head, 0, 15,
4122 $#headlist <= 15 ? undef :
4123 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4127 git_print_header_div
('forks');
4128 git_project_list_body
(\
@forklist, undef, 0, 15,
4129 $#forklist <= 15 ? undef :
4130 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4138 my $head = git_get_head_hash
($project);
4140 git_print_page_nav
('','', $head,undef,$head);
4141 my %tag = parse_tag
($hash);
4144 die_error
(404, "Unknown tag object");
4147 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4148 print "<div class=\"title_text\">\n" .
4149 "<table class=\"object_header\">\n" .
4151 "<td>object</td>\n" .
4152 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4153 $tag{'object'}) . "</td>\n" .
4154 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4155 $tag{'type'}) . "</td>\n" .
4157 if (defined($tag{'author'})) {
4158 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4159 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4160 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4161 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4164 print "</table>\n\n" .
4166 print "<div class=\"page_body\">";
4167 my $comment = $tag{'comment'};
4168 foreach my $line (@$comment) {
4170 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4180 gitweb_check_feature
('blame')
4181 or die_error
(403, "Blame view not allowed");
4183 die_error
(400, "No file name given") unless $file_name;
4184 $hash_base ||= git_get_head_hash
($project);
4185 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4186 my %co = parse_commit
($hash_base)
4187 or die_error
(404, "Commit not found");
4188 if (!defined $hash) {
4189 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4190 or die_error
(404, "Error looking up file");
4192 $ftype = git_get_type
($hash);
4193 if ($ftype !~ "blob") {
4194 die_error
(400, "Object is not a blob");
4196 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4197 $file_name, $hash_base)
4198 or die_error
(500, "Open git-blame failed");
4201 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4204 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4207 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4209 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4210 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4211 git_print_page_path
($file_name, $ftype, $hash_base);
4212 my @rev_color = (qw(light2 dark2));
4213 my $num_colors = scalar(@rev_color);
4214 my $current_color = 0;
4217 <div class="page_body">
4218 <table class="blame">
4219 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4224 last unless defined $_;
4225 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4226 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4227 if (!exists $metainfo{$full_rev}) {
4228 $metainfo{$full_rev} = {};
4230 my $meta = $metainfo{$full_rev};
4233 if (/^(\S+) (.*)$/) {
4239 my $rev = substr($full_rev, 0, 8);
4240 my $author = $meta->{'author'};
4241 my %date = parse_date
($meta->{'author-time'},
4242 $meta->{'author-tz'});
4243 my $date = $date{'iso-tz'};
4245 $current_color = ++$current_color % $num_colors;
4247 print "<tr class=\"$rev_color[$current_color]\">\n";
4249 print "<td class=\"sha1\"";
4250 print " title=\"". esc_html
($author) . ", $date\"";
4251 print " rowspan=\"$group_size\"" if ($group_size > 1);
4253 print $cgi->a({-href
=> href
(action
=>"commit",
4255 file_name
=>$file_name)},
4259 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4260 or die_error
(500, "Open git-rev-parse failed");
4261 my $parent_commit = <$dd>;
4263 chomp($parent_commit);
4264 my $blamed = href
(action
=> 'blame',
4265 file_name
=> $meta->{'filename'},
4266 hash_base
=> $parent_commit);
4267 print "<td class=\"linenr\">";
4268 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4270 -class => "linenr" },
4273 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4279 or print "Reading blob failed\n";
4284 my $head = git_get_head_hash
($project);
4286 git_print_page_nav
('','', $head,undef,$head);
4287 git_print_header_div
('summary', $project);
4289 my @tagslist = git_get_tags_list
();
4291 git_tags_body
(\
@tagslist);
4297 my $head = git_get_head_hash
($project);
4299 git_print_page_nav
('','', $head,undef,$head);
4300 git_print_header_div
('summary', $project);
4302 my @headslist = git_get_heads_list
();
4304 git_heads_body
(\
@headslist, $head);
4309 sub git_blob_plain
{
4313 if (!defined $hash) {
4314 if (defined $file_name) {
4315 my $base = $hash_base || git_get_head_hash
($project);
4316 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4317 or die_error
(404, "Cannot find file");
4319 die_error
(400, "No file name defined");
4321 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4322 # blobs defined by non-textual hash id's can be cached
4326 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4327 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4329 # content-type (can include charset)
4330 $type = blob_contenttype
($fd, $file_name, $type);
4332 # "save as" filename, even when no $file_name is given
4333 my $save_as = "$hash";
4334 if (defined $file_name) {
4335 $save_as = $file_name;
4336 } elsif ($type =~ m/^text\//) {
4342 -expires
=> $expires,
4343 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4345 binmode STDOUT
, ':raw';
4347 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4355 if (!defined $hash) {
4356 if (defined $file_name) {
4357 my $base = $hash_base || git_get_head_hash
($project);
4358 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4359 or die_error
(404, "Cannot find file");
4361 die_error
(400, "No file name defined");
4363 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4364 # blobs defined by non-textual hash id's can be cached
4368 my ($have_blame) = gitweb_check_feature
('blame');
4369 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4370 or die_error
(500, "Couldn't cat $file_name, $hash");
4371 my $mimetype = blob_mimetype
($fd, $file_name);
4372 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4374 return git_blob_plain
($mimetype);
4376 # we can have blame only for text/* mimetype
4377 $have_blame &&= ($mimetype =~ m!^text/!);
4379 git_header_html
(undef, $expires);
4380 my $formats_nav = '';
4381 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4382 if (defined $file_name) {
4385 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4390 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4393 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4396 $cgi->a({-href
=> href
(action
=>"blob",
4397 hash_base
=>"HEAD", file_name
=>$file_name)},
4401 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4404 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4405 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4407 print "<div class=\"page_nav\">\n" .
4408 "<br/><br/></div>\n" .
4409 "<div class=\"title\">$hash</div>\n";
4411 git_print_page_path
($file_name, "blob", $hash_base);
4412 print "<div class=\"page_body\">\n";
4413 if ($mimetype =~ m!^image/!) {
4414 print qq
!<img type
="$mimetype"!;
4416 print qq
! alt
="$file_name" title
="$file_name"!;
4419 href(action=>"blob_plain
", hash=>$hash,
4420 hash_base=>$hash_base, file_name=>$file_name) .
4424 while (my $line = <$fd>) {
4427 $line = untabify
($line);
4428 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4429 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4433 or print "Reading blob failed.\n";
4439 if (!defined $hash_base) {
4440 $hash_base = "HEAD";
4442 if (!defined $hash) {
4443 if (defined $file_name) {
4444 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4450 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4451 or die_error
(500, "Open git-ls-tree failed");
4452 my @entries = map { chomp; $_ } <$fd>;
4453 close $fd or die_error
(404, "Reading tree failed");
4456 my $refs = git_get_references
();
4457 my $ref = format_ref_marker
($refs, $hash_base);
4460 my ($have_blame) = gitweb_check_feature
('blame');
4461 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4463 if (defined $file_name) {
4465 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4467 $cgi->a({-href
=> href
(action
=>"tree",
4468 hash_base
=>"HEAD", file_name
=>$file_name)},
4471 my $snapshot_links = format_snapshot_links
($hash);
4472 if (defined $snapshot_links) {
4473 # FIXME: Should be available when we have no hash base as well.
4474 push @views_nav, $snapshot_links;
4476 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4477 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4480 print "<div class=\"page_nav\">\n";
4481 print "<br/><br/></div>\n";
4482 print "<div class=\"title\">$hash</div>\n";
4484 if (defined $file_name) {
4485 $basedir = $file_name;
4486 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4490 git_print_page_path
($file_name, 'tree', $hash_base);
4491 print "<div class=\"page_body\">\n";
4492 print "<table class=\"tree\">\n";
4494 # '..' (top directory) link if possible
4495 if (defined $hash_base &&
4496 defined $file_name && $file_name =~ m![^/]+$!) {
4498 print "<tr class=\"dark\">\n";
4500 print "<tr class=\"light\">\n";
4504 my $up = $file_name;
4505 $up =~ s!/?[^/]+$!!;
4506 undef $up unless $up;
4507 # based on git_print_tree_entry
4508 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4509 print '<td class="list">';
4510 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4514 print "<td class=\"link\"></td>\n";
4518 foreach my $line (@entries) {
4519 my %t = parse_ls_tree_line
($line, -z
=> 1);
4522 print "<tr class=\"dark\">\n";
4524 print "<tr class=\"light\">\n";
4528 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4532 print "</table>\n" .
4538 my @supported_fmts = gitweb_check_feature
('snapshot');
4539 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4541 my $format = $cgi->param('sf');
4542 if (!@supported_fmts) {
4543 die_error
(403, "Snapshots not allowed");
4545 # default to first supported snapshot format
4546 $format ||= $supported_fmts[0];
4547 if ($format !~ m/^[a-z0-9]+$/) {
4548 die_error
(400, "Invalid snapshot format parameter");
4549 } elsif (!exists($known_snapshot_formats{$format})) {
4550 die_error
(400, "Unknown snapshot format");
4551 } elsif (!grep($_ eq $format, @supported_fmts)) {
4552 die_error
(403, "Unsupported snapshot format");
4555 if (!defined $hash) {
4556 $hash = git_get_head_hash
($project);
4559 my $name = $project;
4560 $name =~ s
,([^/])/*\
.git
$,$1,;
4561 $name = basename
($name);
4562 my $filename = to_utf8
($name);
4563 $name =~ s/\047/\047\\\047\047/g;
4565 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4566 $cmd = quote_command
(
4567 git_cmd
(), 'archive',
4568 "--format=$known_snapshot_formats{$format}{'format'}",
4569 "--prefix=$name/", $hash);
4570 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4571 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4575 -type
=> $known_snapshot_formats{$format}{'type'},
4576 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4577 -status
=> '200 OK');
4579 open my $fd, "-|", $cmd
4580 or die_error
(500, "Execute git-archive failed");
4581 binmode STDOUT
, ':raw';
4583 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4588 my $head = git_get_head_hash
($project);
4589 if (!defined $hash) {
4592 if (!defined $page) {
4595 my $refs = git_get_references
();
4597 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4599 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4602 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4605 my %co = parse_commit
($hash);
4607 git_print_header_div
('summary', $project);
4608 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4610 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4611 for (my $i = 0; $i <= $to; $i++) {
4612 my %co = %{$commitlist[$i]};
4614 my $commit = $co{'id'};
4615 my $ref = format_ref_marker
($refs, $commit);
4616 my %ad = parse_date
($co{'author_epoch'});
4617 git_print_header_div
('commit',
4618 "<span class=\"age\">$co{'age_string'}</span>" .
4619 esc_html
($co{'title'}) . $ref,
4621 print "<div class=\"title_text\">\n" .
4622 "<div class=\"log_link\">\n" .
4623 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4625 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4627 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4630 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4633 print "<div class=\"log_body\">\n";
4634 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4637 if ($#commitlist >= 100) {
4638 print "<div class=\"page_nav\">\n";
4639 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4640 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4647 $hash ||= $hash_base || "HEAD";
4648 my %co = parse_commit
($hash)
4649 or die_error
(404, "Unknown commit object");
4650 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4651 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4653 my $parent = $co{'parent'};
4654 my $parents = $co{'parents'}; # listref
4656 # we need to prepare $formats_nav before any parameter munging
4658 if (!defined $parent) {
4660 $formats_nav .= '(initial)';
4661 } elsif (@$parents == 1) {
4662 # single parent commit
4665 $cgi->a({-href
=> href
(action
=>"commit",
4667 esc_html
(substr($parent, 0, 7))) .
4674 $cgi->a({-href
=> href
(action
=>"commit",
4676 esc_html
(substr($_, 0, 7)));
4681 if (!defined $parent) {
4685 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4687 (@$parents <= 1 ? $parent : '-c'),
4689 or die_error
(500, "Open git-diff-tree failed");
4690 @difftree = map { chomp; $_ } <$fd>;
4691 close $fd or die_error
(404, "Reading git-diff-tree failed");
4693 # non-textual hash id's can be cached
4695 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4698 my $refs = git_get_references
();
4699 my $ref = format_ref_marker
($refs, $co{'id'});
4701 git_header_html
(undef, $expires);
4702 git_print_page_nav
('commit', '',
4703 $hash, $co{'tree'}, $hash,
4706 if (defined $co{'parent'}) {
4707 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4709 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4711 print "<div class=\"title_text\">\n" .
4712 "<table class=\"object_header\">\n";
4713 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4715 "<td></td><td> $ad{'rfc2822'}";
4716 if ($ad{'hour_local'} < 6) {
4717 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4718 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4720 printf(" (%02d:%02d %s)",
4721 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4725 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4726 print "<tr><td></td><td> $cd{'rfc2822'}" .
4727 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4729 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4732 "<td class=\"sha1\">" .
4733 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4734 class => "list"}, $co{'tree'}) .
4736 "<td class=\"link\">" .
4737 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4739 my $snapshot_links = format_snapshot_links
($hash);
4740 if (defined $snapshot_links) {
4741 print " | " . $snapshot_links;
4746 foreach my $par (@$parents) {
4749 "<td class=\"sha1\">" .
4750 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4751 class => "list"}, $par) .
4753 "<td class=\"link\">" .
4754 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4756 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4763 print "<div class=\"page_body\">\n";
4764 git_print_log
($co{'comment'});
4767 git_difftree_body
(\
@difftree, $hash, @$parents);
4773 # object is defined by:
4774 # - hash or hash_base alone
4775 # - hash_base and file_name
4778 # - hash or hash_base alone
4779 if ($hash || ($hash_base && !defined $file_name)) {
4780 my $object_id = $hash || $hash_base;
4782 open my $fd, "-|", quote_command
(
4783 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4784 or die_error
(404, "Object does not exist");
4788 or die_error
(404, "Object does not exist");
4790 # - hash_base and file_name
4791 } elsif ($hash_base && defined $file_name) {
4792 $file_name =~ s
,/+$,,;
4794 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4795 or die_error
(404, "Base object does not exist");
4797 # here errors should not hapen
4798 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4799 or die_error
(500, "Open git-ls-tree failed");
4803 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4804 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4805 die_error
(404, "File or directory for given base does not exist");
4810 die_error
(400, "Not enough information to find object");
4813 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4814 hash
=>$hash, hash_base
=>$hash_base,
4815 file_name
=>$file_name),
4816 -status
=> '302 Found');
4820 my $format = shift || 'html';
4827 # preparing $fd and %diffinfo for git_patchset_body
4829 if (defined $hash_base && defined $hash_parent_base) {
4830 if (defined $file_name) {
4832 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4833 $hash_parent_base, $hash_base,
4834 "--", (defined $file_parent ? $file_parent : ()), $file_name
4835 or die_error
(500, "Open git-diff-tree failed");
4836 @difftree = map { chomp; $_ } <$fd>;
4838 or die_error
(404, "Reading git-diff-tree failed");
4840 or die_error
(404, "Blob diff not found");
4842 } elsif (defined $hash &&
4843 $hash =~ /[0-9a-fA-F]{40}/) {
4844 # try to find filename from $hash
4846 # read filtered raw output
4847 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4848 $hash_parent_base, $hash_base, "--"
4849 or die_error
(500, "Open git-diff-tree failed");
4851 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4853 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4854 map { chomp; $_ } <$fd>;
4856 or die_error
(404, "Reading git-diff-tree failed");
4858 or die_error
(404, "Blob diff not found");
4861 die_error
(400, "Missing one of the blob diff parameters");
4864 if (@difftree > 1) {
4865 die_error
(400, "Ambiguous blob diff specification");
4868 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4869 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4870 $file_name ||= $diffinfo{'to_file'};
4872 $hash_parent ||= $diffinfo{'from_id'};
4873 $hash ||= $diffinfo{'to_id'};
4875 # non-textual hash id's can be cached
4876 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4877 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4882 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4883 '-p', ($format eq 'html' ? "--full-index" : ()),
4884 $hash_parent_base, $hash_base,
4885 "--", (defined $file_parent ? $file_parent : ()), $file_name
4886 or die_error
(500, "Open git-diff-tree failed");
4889 # old/legacy style URI
4890 if (!%diffinfo && # if new style URI failed
4891 defined $hash && defined $hash_parent) {
4892 # fake git-diff-tree raw output
4893 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4894 $diffinfo{'from_id'} = $hash_parent;
4895 $diffinfo{'to_id'} = $hash;
4896 if (defined $file_name) {
4897 if (defined $file_parent) {
4898 $diffinfo{'status'} = '2';
4899 $diffinfo{'from_file'} = $file_parent;
4900 $diffinfo{'to_file'} = $file_name;
4901 } else { # assume not renamed
4902 $diffinfo{'status'} = '1';
4903 $diffinfo{'from_file'} = $file_name;
4904 $diffinfo{'to_file'} = $file_name;
4906 } else { # no filename given
4907 $diffinfo{'status'} = '2';
4908 $diffinfo{'from_file'} = $hash_parent;
4909 $diffinfo{'to_file'} = $hash;
4912 # non-textual hash id's can be cached
4913 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4914 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4919 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4920 '-p', ($format eq 'html' ? "--full-index" : ()),
4921 $hash_parent, $hash, "--"
4922 or die_error
(500, "Open git-diff failed");
4924 die_error
(400, "Missing one of the blob diff parameters")
4929 if ($format eq 'html') {
4931 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4933 git_header_html
(undef, $expires);
4934 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4935 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4936 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4938 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4939 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4941 if (defined $file_name) {
4942 git_print_page_path
($file_name, "blob", $hash_base);
4944 print "<div class=\"page_path\"></div>\n";
4947 } elsif ($format eq 'plain') {
4949 -type
=> 'text/plain',
4950 -charset
=> 'utf-8',
4951 -expires
=> $expires,
4952 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4954 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4957 die_error
(400, "Unknown blobdiff format");
4961 if ($format eq 'html') {
4962 print "<div class=\"page_body\">\n";
4964 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4967 print "</div>\n"; # class="page_body"
4971 while (my $line = <$fd>) {
4972 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4973 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4977 last if $line =~ m!^\+\+\+!;
4985 sub git_blobdiff_plain
{
4986 git_blobdiff
('plain');
4989 sub git_commitdiff
{
4990 my $format = shift || 'html';
4991 $hash ||= $hash_base || "HEAD";
4992 my %co = parse_commit
($hash)
4993 or die_error
(404, "Unknown commit object");
4995 # choose format for commitdiff for merge
4996 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4997 $hash_parent = '--cc';
4999 # we need to prepare $formats_nav before almost any parameter munging
5001 if ($format eq 'html') {
5003 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5006 if (defined $hash_parent &&
5007 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5008 # commitdiff with two commits given
5009 my $hash_parent_short = $hash_parent;
5010 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5011 $hash_parent_short = substr($hash_parent, 0, 7);
5015 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5016 if ($co{'parents'}[$i] eq $hash_parent) {
5017 $formats_nav .= ' parent ' . ($i+1);
5021 $formats_nav .= ': ' .
5022 $cgi->a({-href
=> href
(action
=>"commitdiff",
5023 hash
=>$hash_parent)},
5024 esc_html
($hash_parent_short)) .
5026 } elsif (!$co{'parent'}) {
5028 $formats_nav .= ' (initial)';
5029 } elsif (scalar @{$co{'parents'}} == 1) {
5030 # single parent commit
5033 $cgi->a({-href
=> href
(action
=>"commitdiff",
5034 hash
=>$co{'parent'})},
5035 esc_html
(substr($co{'parent'}, 0, 7))) .
5039 if ($hash_parent eq '--cc') {
5040 $formats_nav .= ' | ' .
5041 $cgi->a({-href
=> href
(action
=>"commitdiff",
5042 hash
=>$hash, hash_parent
=>'-c')},
5044 } else { # $hash_parent eq '-c'
5045 $formats_nav .= ' | ' .
5046 $cgi->a({-href
=> href
(action
=>"commitdiff",
5047 hash
=>$hash, hash_parent
=>'--cc')},
5053 $cgi->a({-href
=> href
(action
=>"commitdiff",
5055 esc_html
(substr($_, 0, 7)));
5056 } @{$co{'parents'}} ) .
5061 my $hash_parent_param = $hash_parent;
5062 if (!defined $hash_parent_param) {
5063 # --cc for multiple parents, --root for parentless
5064 $hash_parent_param =
5065 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5071 if ($format eq 'html') {
5072 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5073 "--no-commit-id", "--patch-with-raw", "--full-index",
5074 $hash_parent_param, $hash, "--"
5075 or die_error
(500, "Open git-diff-tree failed");
5077 while (my $line = <$fd>) {
5079 # empty line ends raw part of diff-tree output
5081 push @difftree, scalar parse_difftree_raw_line
($line);
5084 } elsif ($format eq 'plain') {
5085 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5086 '-p', $hash_parent_param, $hash, "--"
5087 or die_error
(500, "Open git-diff-tree failed");
5090 die_error
(400, "Unknown commitdiff format");
5093 # non-textual hash id's can be cached
5095 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5099 # write commit message
5100 if ($format eq 'html') {
5101 my $refs = git_get_references
();
5102 my $ref = format_ref_marker
($refs, $co{'id'});
5104 git_header_html
(undef, $expires);
5105 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5106 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5107 git_print_authorship
(\
%co);
5108 print "<div class=\"page_body\">\n";
5109 if (@{$co{'comment'}} > 1) {
5110 print "<div class=\"log\">\n";
5111 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5112 print "</div>\n"; # class="log"
5115 } elsif ($format eq 'plain') {
5116 my $refs = git_get_references
("tags");
5117 my $tagname = git_get_rev_name_tags
($hash);
5118 my $filename = basename
($project) . "-$hash.patch";
5121 -type
=> 'text/plain',
5122 -charset
=> 'utf-8',
5123 -expires
=> $expires,
5124 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5125 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5126 print "From: " . to_utf8
($co{'author'}) . "\n";
5127 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5128 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5130 print "X-Git-Tag: $tagname\n" if $tagname;
5131 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5133 foreach my $line (@{$co{'comment'}}) {
5134 print to_utf8
($line) . "\n";
5140 if ($format eq 'html') {
5141 my $use_parents = !defined $hash_parent ||
5142 $hash_parent eq '-c' || $hash_parent eq '--cc';
5143 git_difftree_body
(\
@difftree, $hash,
5144 $use_parents ? @{$co{'parents'}} : $hash_parent);
5147 git_patchset_body
($fd, \
@difftree, $hash,
5148 $use_parents ? @{$co{'parents'}} : $hash_parent);
5150 print "</div>\n"; # class="page_body"
5153 } elsif ($format eq 'plain') {
5157 or print "Reading git-diff-tree failed\n";
5161 sub git_commitdiff_plain
{
5162 git_commitdiff
('plain');
5166 if (!defined $hash_base) {
5167 $hash_base = git_get_head_hash
($project);
5169 if (!defined $page) {
5173 my %co = parse_commit
($hash_base)
5174 or die_error
(404, "Unknown commit object");
5176 my $refs = git_get_references
();
5177 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5179 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5180 $file_name, "--full-history")
5181 or die_error
(404, "No such file or directory on given branch");
5183 if (!defined $hash && defined $file_name) {
5184 # some commits could have deleted file in question,
5185 # and not have it in tree, but one of them has to have it
5186 for (my $i = 0; $i <= @commitlist; $i++) {
5187 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5188 last if defined $hash;
5191 if (defined $hash) {
5192 $ftype = git_get_type
($hash);
5194 if (!defined $ftype) {
5195 die_error
(500, "Unknown type of object");
5198 my $paging_nav = '';
5201 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5202 file_name
=>$file_name)},
5204 $paging_nav .= " ⋅ " .
5205 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5206 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5208 $paging_nav .= "first";
5209 $paging_nav .= " ⋅ prev";
5212 if ($#commitlist >= 100) {
5214 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5215 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5216 $paging_nav .= " ⋅ $next_link";
5218 $paging_nav .= " ⋅ next";
5222 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5223 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5224 git_print_page_path
($file_name, $ftype, $hash_base);
5226 git_history_body
(\
@commitlist, 0, 99,
5227 $refs, $hash_base, $ftype, $next_link);
5233 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5234 if (!defined $searchtext) {
5235 die_error
(400, "Text field is empty");
5237 if (!defined $hash) {
5238 $hash = git_get_head_hash
($project);
5240 my %co = parse_commit
($hash);
5242 die_error
(404, "Unknown commit object");
5244 if (!defined $page) {
5248 $searchtype ||= 'commit';
5249 if ($searchtype eq 'pickaxe') {
5250 # pickaxe may take all resources of your box and run for several minutes
5251 # with every query - so decide by yourself how public you make this feature
5252 gitweb_check_feature
('pickaxe')
5253 or die_error
(403, "Pickaxe is disabled");
5255 if ($searchtype eq 'grep') {
5256 gitweb_check_feature
('grep')
5257 or die_error
(403, "Grep is disabled");
5262 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5264 if ($searchtype eq 'commit') {
5265 $greptype = "--grep=";
5266 } elsif ($searchtype eq 'author') {
5267 $greptype = "--author=";
5268 } elsif ($searchtype eq 'committer') {
5269 $greptype = "--committer=";
5271 $greptype .= $searchtext;
5272 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5273 $greptype, '--regexp-ignore-case',
5274 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5276 my $paging_nav = '';
5279 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5280 searchtext
=>$searchtext,
5281 searchtype
=>$searchtype)},
5283 $paging_nav .= " ⋅ " .
5284 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5285 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5287 $paging_nav .= "first";
5288 $paging_nav .= " ⋅ prev";
5291 if ($#commitlist >= 100) {
5293 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5294 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5295 $paging_nav .= " ⋅ $next_link";
5297 $paging_nav .= " ⋅ next";
5300 if ($#commitlist >= 100) {
5303 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5304 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5305 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5308 if ($searchtype eq 'pickaxe') {
5309 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5310 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5312 print "<table class=\"pickaxe search\">\n";
5315 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5316 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5317 ($search_use_regexp ? '--pickaxe-regex' : ());
5320 while (my $line = <$fd>) {
5324 my %set = parse_difftree_raw_line
($line);
5325 if (defined $set{'commit'}) {
5326 # finish previous commit
5329 "<td class=\"link\">" .
5330 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5332 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5338 print "<tr class=\"dark\">\n";
5340 print "<tr class=\"light\">\n";
5343 %co = parse_commit
($set{'commit'});
5344 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5345 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5346 "<td><i>$author</i></td>\n" .
5348 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5349 -class => "list subject"},
5350 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5351 } elsif (defined $set{'to_id'}) {
5352 next if ($set{'to_id'} =~ m/^0{40}$/);
5354 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5355 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5357 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5363 # finish last commit (warning: repetition!)
5366 "<td class=\"link\">" .
5367 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5369 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5377 if ($searchtype eq 'grep') {
5378 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5379 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5381 print "<table class=\"grep_search\">\n";
5385 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5386 $search_use_regexp ? ('-E', '-i') : '-F',
5387 $searchtext, $co{'tree'};
5389 while (my $line = <$fd>) {
5391 my ($file, $lno, $ltext, $binary);
5392 last if ($matches++ > 1000);
5393 if ($line =~ /^Binary file (.+) matches$/) {
5397 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5399 if ($file ne $lastfile) {
5400 $lastfile and print "</td></tr>\n";
5402 print "<tr class=\"dark\">\n";
5404 print "<tr class=\"light\">\n";
5406 print "<td class=\"list\">".
5407 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5408 file_name
=>"$file"),
5409 -class => "list"}, esc_path
($file));
5410 print "</td><td>\n";
5414 print "<div class=\"binary\">Binary file</div>\n";
5416 $ltext = untabify
($ltext);
5417 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5418 $ltext = esc_html
($1, -nbsp
=>1);
5419 $ltext .= '<span class="match">';
5420 $ltext .= esc_html
($2, -nbsp
=>1);
5421 $ltext .= '</span>';
5422 $ltext .= esc_html
($3, -nbsp
=>1);
5424 $ltext = esc_html
($ltext, -nbsp
=>1);
5426 print "<div class=\"pre\">" .
5427 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5428 file_name
=>"$file").'#l'.$lno,
5429 -class => "linenr"}, sprintf('%4i', $lno))
5430 . ' ' . $ltext . "</div>\n";
5434 print "</td></tr>\n";
5435 if ($matches > 1000) {
5436 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5439 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5448 sub git_search_help
{
5450 git_print_page_nav
('','', $hash,$hash,$hash);
5452 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5453 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5454 the pattern entered is recognized as the POSIX extended
5455 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5458 <dt><b>commit</b></dt>
5459 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5461 my ($have_grep) = gitweb_check_feature
('grep');
5464 <dt><b>grep</b></dt>
5465 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5466 a different one) are searched for the given pattern. On large trees, this search can take
5467 a while and put some strain on the server, so please use it with some consideration. Note that
5468 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5469 case-sensitive.</dd>
5473 <dt><b>author</b></dt>
5474 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5475 <dt><b>committer</b></dt>
5476 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5478 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5479 if ($have_pickaxe) {
5481 <dt><b>pickaxe</b></dt>
5482 <dd>All commits that caused the string to appear or disappear from any file (changes that
5483 added, removed or "modified" the string) will be listed. This search can take a while and
5484 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5485 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5493 my $head = git_get_head_hash
($project);
5494 if (!defined $hash) {
5497 if (!defined $page) {
5500 my $refs = git_get_references
();
5502 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5504 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5506 if ($#commitlist >= 100) {
5508 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5509 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5513 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5514 git_print_header_div
('summary', $project);
5516 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5521 ## ......................................................................
5522 ## feeds (RSS, Atom; OPML)
5525 my $format = shift || 'atom';
5526 my ($have_blame) = gitweb_check_feature
('blame');
5528 # Atom: http://www.atomenabled.org/developers/syndication/
5529 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5530 if ($format ne 'rss' && $format ne 'atom') {
5531 die_error
(400, "Unknown web feed format");
5534 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5535 my $head = $hash || 'HEAD';
5536 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5540 my $content_type = "application/$format+xml";
5541 if (defined $cgi->http('HTTP_ACCEPT') &&
5542 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5543 # browser (feed reader) prefers text/xml
5544 $content_type = 'text/xml';
5546 if (defined($commitlist[0])) {
5547 %latest_commit = %{$commitlist[0]};
5548 %latest_date = parse_date
($latest_commit{'author_epoch'});
5550 -type
=> $content_type,
5551 -charset
=> 'utf-8',
5552 -last_modified
=> $latest_date{'rfc2822'});
5555 -type
=> $content_type,
5556 -charset
=> 'utf-8');
5559 # Optimization: skip generating the body if client asks only
5560 # for Last-Modified date.
5561 return if ($cgi->request_method() eq 'HEAD');
5564 my $title = "$site_name - $project/$action";
5565 my $feed_type = 'log';
5566 if (defined $hash) {
5567 $title .= " - '$hash'";
5568 $feed_type = 'branch log';
5569 if (defined $file_name) {
5570 $title .= " :: $file_name";
5571 $feed_type = 'history';
5573 } elsif (defined $file_name) {
5574 $title .= " - $file_name";
5575 $feed_type = 'history';
5577 $title .= " $feed_type";
5578 my $descr = git_get_project_description
($project);
5579 if (defined $descr) {
5580 $descr = esc_html
($descr);
5582 $descr = "$project " .
5583 ($format eq 'rss' ? 'RSS' : 'Atom') .
5586 my $owner = git_get_project_owner
($project);
5587 $owner = esc_html
($owner);
5591 if (defined $file_name) {
5592 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5593 } elsif (defined $hash) {
5594 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5596 $alt_url = href
(-full
=>1, action
=>"summary");
5598 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5599 if ($format eq 'rss') {
5601 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5604 print "<title>$title</title>\n" .
5605 "<link>$alt_url</link>\n" .
5606 "<description>$descr</description>\n" .
5607 "<language>en</language>\n";
5608 } elsif ($format eq 'atom') {
5610 <feed xmlns="http://www.w3.org/2005/Atom">
5612 print "<title>$title</title>\n" .
5613 "<subtitle>$descr</subtitle>\n" .
5614 '<link rel="alternate" type="text/html" href="' .
5615 $alt_url . '" />' . "\n" .
5616 '<link rel="self" type="' . $content_type . '" href="' .
5617 $cgi->self_url() . '" />' . "\n" .
5618 "<id>" . href
(-full
=>1) . "</id>\n" .
5619 # use project owner for feed author
5620 "<author><name>$owner</name></author>\n";
5621 if (defined $favicon) {
5622 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5624 if (defined $logo_url) {
5625 # not twice as wide as tall: 72 x 27 pixels
5626 print "<logo>" . esc_url
($logo) . "</logo>\n";
5628 if (! %latest_date) {
5629 # dummy date to keep the feed valid until commits trickle in:
5630 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5632 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5637 for (my $i = 0; $i <= $#commitlist; $i++) {
5638 my %co = %{$commitlist[$i]};
5639 my $commit = $co{'id'};
5640 # we read 150, we always show 30 and the ones more recent than 48 hours
5641 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5644 my %cd = parse_date
($co{'author_epoch'});
5646 # get list of changed files
5647 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5648 $co{'parent'} || "--root",
5649 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5651 my @difftree = map { chomp; $_ } <$fd>;
5655 # print element (entry, item)
5656 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5657 if ($format eq 'rss') {
5659 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5660 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5661 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5662 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5663 "<link>$co_url</link>\n" .
5664 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5665 "<content:encoded>" .
5667 } elsif ($format eq 'atom') {
5669 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5670 "<updated>$cd{'iso-8601'}</updated>\n" .
5672 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5673 if ($co{'author_email'}) {
5674 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5676 print "</author>\n" .
5677 # use committer for contributor
5679 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5680 if ($co{'committer_email'}) {
5681 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5683 print "</contributor>\n" .
5684 "<published>$cd{'iso-8601'}</published>\n" .
5685 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5686 "<id>$co_url</id>\n" .
5687 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5688 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5690 my $comment = $co{'comment'};
5692 foreach my $line (@$comment) {
5693 $line = esc_html
($line);
5696 print "</pre><ul>\n";
5697 foreach my $difftree_line (@difftree) {
5698 my %difftree = parse_difftree_raw_line
($difftree_line);
5699 next if !$difftree{'from_id'};
5701 my $file = $difftree{'file'} || $difftree{'to_file'};
5705 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5706 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5707 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5708 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5709 -title
=> "diff"}, 'D');
5711 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5712 file_name
=>$file, hash_base
=>$commit),
5713 -title
=> "blame"}, 'B');
5715 # if this is not a feed of a file history
5716 if (!defined $file_name || $file_name ne $file) {
5717 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5718 file_name
=>$file, hash
=>$commit),
5719 -title
=> "history"}, 'H');
5721 $file = esc_path
($file);
5725 if ($format eq 'rss') {
5726 print "</ul>]]>\n" .
5727 "</content:encoded>\n" .
5729 } elsif ($format eq 'atom') {
5730 print "</ul>\n</div>\n" .
5737 if ($format eq 'rss') {
5738 print "</channel>\n</rss>\n";
5739 } elsif ($format eq 'atom') {
5753 my @list = git_get_projects_list
();
5755 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5757 <?xml version="1.0" encoding="utf-8"?>
5758 <opml version="1.0">
5760 <title>$site_name OPML Export</title>
5763 <outline text="git RSS feeds">
5766 foreach my $pr (@list) {
5768 my $head = git_get_head_hash
($proj{'path'});
5769 if (!defined $head) {
5772 $git_dir = "$projectroot/$proj{'path'}";
5773 my %co = parse_commit
($head);
5778 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5779 my $rss = "$my_url?p=$proj{'path'};a=rss";
5780 my $html = "$my_url?p=$proj{'path'};a=summary";
5781 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";