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, generating 'sort by $name' replay link
3610 # if that order is not selected
3612 my ($name, $order, $header) = @_;
3613 $header ||= ucfirst($name);
3615 if ($order eq $name) {
3616 print "<th>$header</th>\n";
3619 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3620 -class => "header"}, $header) .
3625 sub git_project_list_body
{
3626 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3628 my ($check_forks) = gitweb_check_feature
('forks');
3629 my @projects = fill_project_list_info
($projlist, $check_forks);
3631 $order ||= $default_projects_order;
3632 $from = 0 unless defined $from;
3633 $to = $#projects if (!defined $to || $#projects < $to);
3636 project
=> { key
=> 'path', type
=> 'str' },
3637 descr
=> { key
=> 'descr_long', type
=> 'str' },
3638 owner
=> { key
=> 'owner', type
=> 'str' },
3639 age
=> { key
=> 'age', type
=> 'num' }
3641 my $oi = $order_info{$order};
3642 if ($oi->{'type'} eq 'str') {
3643 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3645 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3648 print "<table class=\"project_list\">\n";
3649 unless ($no_header) {
3652 print "<th></th>\n";
3654 print_sort_th
('project', $order, 'Project');
3655 print_sort_th
('descr', $order, 'Description');
3656 print_sort_th
('owner', $order, 'Owner');
3657 print_sort_th
('age', $order, 'Last Change');
3658 print "<th></th>\n" . # for links
3662 for (my $i = $from; $i <= $to; $i++) {
3663 my $pr = $projects[$i];
3665 print "<tr class=\"dark\">\n";
3667 print "<tr class=\"light\">\n";
3672 if ($pr->{'forks'}) {
3673 print "<!-- $pr->{'forks'} -->\n";
3674 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3678 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3679 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3680 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3681 -class => "list", -title
=> $pr->{'descr_long'}},
3682 esc_html
($pr->{'descr'})) . "</td>\n" .
3683 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3684 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3685 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3686 "<td class=\"link\">" .
3687 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3688 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3689 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3690 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3691 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3695 if (defined $extra) {
3698 print "<td></td>\n";
3700 print "<td colspan=\"5\">$extra</td>\n" .
3706 sub git_shortlog_body
{
3707 # uses global variable $project
3708 my ($commitlist, $from, $to, $refs, $extra) = @_;
3710 $from = 0 unless defined $from;
3711 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3713 print "<table class=\"shortlog\">\n";
3715 for (my $i = $from; $i <= $to; $i++) {
3716 my %co = %{$commitlist->[$i]};
3717 my $commit = $co{'id'};
3718 my $ref = format_ref_marker
($refs, $commit);
3720 print "<tr class=\"dark\">\n";
3722 print "<tr class=\"light\">\n";
3725 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3726 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3727 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3728 "<td><i>" . $author . "</i></td>\n" .
3730 print format_subject_html
($co{'title'}, $co{'title_short'},
3731 href
(action
=>"commit", hash
=>$commit), $ref);
3733 "<td class=\"link\">" .
3734 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3735 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3736 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3737 my $snapshot_links = format_snapshot_links
($commit);
3738 if (defined $snapshot_links) {
3739 print " | " . $snapshot_links;
3744 if (defined $extra) {
3746 "<td colspan=\"4\">$extra</td>\n" .
3752 sub git_history_body
{
3753 # Warning: assumes constant type (blob or tree) during history
3754 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3756 $from = 0 unless defined $from;
3757 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3759 print "<table class=\"history\">\n";
3761 for (my $i = $from; $i <= $to; $i++) {
3762 my %co = %{$commitlist->[$i]};
3766 my $commit = $co{'id'};
3768 my $ref = format_ref_marker
($refs, $commit);
3771 print "<tr class=\"dark\">\n";
3773 print "<tr class=\"light\">\n";
3776 # shortlog uses chop_str($co{'author_name'}, 10)
3777 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3778 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3779 "<td><i>" . $author . "</i></td>\n" .
3781 # originally git_history used chop_str($co{'title'}, 50)
3782 print format_subject_html
($co{'title'}, $co{'title_short'},
3783 href
(action
=>"commit", hash
=>$commit), $ref);
3785 "<td class=\"link\">" .
3786 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3787 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3789 if ($ftype eq 'blob') {
3790 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3791 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3792 if (defined $blob_current && defined $blob_parent &&
3793 $blob_current ne $blob_parent) {
3795 $cgi->a({-href
=> href
(action
=>"blobdiff",
3796 hash
=>$blob_current, hash_parent
=>$blob_parent,
3797 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3798 file_name
=>$file_name)},
3805 if (defined $extra) {
3807 "<td colspan=\"4\">$extra</td>\n" .
3814 # uses global variable $project
3815 my ($taglist, $from, $to, $extra) = @_;
3816 $from = 0 unless defined $from;
3817 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3819 print "<table class=\"tags\">\n";
3821 for (my $i = $from; $i <= $to; $i++) {
3822 my $entry = $taglist->[$i];
3824 my $comment = $tag{'subject'};
3826 if (defined $comment) {
3827 $comment_short = chop_str
($comment, 30, 5);
3830 print "<tr class=\"dark\">\n";
3832 print "<tr class=\"light\">\n";
3835 if (defined $tag{'age'}) {
3836 print "<td><i>$tag{'age'}</i></td>\n";
3838 print "<td></td>\n";
3841 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3842 -class => "list name"}, esc_html
($tag{'name'})) .
3845 if (defined $comment) {
3846 print format_subject_html
($comment, $comment_short,
3847 href
(action
=>"tag", hash
=>$tag{'id'}));
3850 "<td class=\"selflink\">";
3851 if ($tag{'type'} eq "tag") {
3852 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3857 "<td class=\"link\">" . " | " .
3858 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3859 if ($tag{'reftype'} eq "commit") {
3860 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3861 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3862 } elsif ($tag{'reftype'} eq "blob") {
3863 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3868 if (defined $extra) {
3870 "<td colspan=\"5\">$extra</td>\n" .
3876 sub git_heads_body
{
3877 # uses global variable $project
3878 my ($headlist, $head, $from, $to, $extra) = @_;
3879 $from = 0 unless defined $from;
3880 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3882 print "<table class=\"heads\">\n";
3884 for (my $i = $from; $i <= $to; $i++) {
3885 my $entry = $headlist->[$i];
3887 my $curr = $ref{'id'} eq $head;
3889 print "<tr class=\"dark\">\n";
3891 print "<tr class=\"light\">\n";
3894 print "<td><i>$ref{'age'}</i></td>\n" .
3895 ($curr ? "<td class=\"current_head\">" : "<td>") .
3896 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3897 -class => "list name"},esc_html
($ref{'name'})) .
3899 "<td class=\"link\">" .
3900 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3901 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3902 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3906 if (defined $extra) {
3908 "<td colspan=\"3\">$extra</td>\n" .
3914 sub git_search_grep_body
{
3915 my ($commitlist, $from, $to, $extra) = @_;
3916 $from = 0 unless defined $from;
3917 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3919 print "<table class=\"commit_search\">\n";
3921 for (my $i = $from; $i <= $to; $i++) {
3922 my %co = %{$commitlist->[$i]};
3926 my $commit = $co{'id'};
3928 print "<tr class=\"dark\">\n";
3930 print "<tr class=\"light\">\n";
3933 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3934 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3935 "<td><i>" . $author . "</i></td>\n" .
3937 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3938 -class => "list subject"},
3939 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3940 my $comment = $co{'comment'};
3941 foreach my $line (@$comment) {
3942 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3943 my ($lead, $match, $trail) = ($1, $2, $3);
3944 $match = chop_str
($match, 70, 5, 'center');
3945 my $contextlen = int((80 - length($match))/2);
3946 $contextlen = 30 if ($contextlen > 30);
3947 $lead = chop_str
($lead, $contextlen, 10, 'left');
3948 $trail = chop_str
($trail, $contextlen, 10, 'right');
3950 $lead = esc_html
($lead);
3951 $match = esc_html
($match);
3952 $trail = esc_html
($trail);
3954 print "$lead<span class=\"match\">$match</span>$trail<br />";
3958 "<td class=\"link\">" .
3959 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3961 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3963 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3967 if (defined $extra) {
3969 "<td colspan=\"3\">$extra</td>\n" .
3975 ## ======================================================================
3976 ## ======================================================================
3979 sub git_project_list
{
3980 my $order = $cgi->param('o');
3981 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3982 die_error
(400, "Unknown order parameter");
3985 my @list = git_get_projects_list
();
3987 die_error
(404, "No projects found");
3991 if (-f
$home_text) {
3992 print "<div class=\"index_include\">\n";
3993 open (my $fd, $home_text);
3998 git_project_list_body
(\
@list, $order);
4003 my $order = $cgi->param('o');
4004 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4005 die_error
(400, "Unknown order parameter");
4008 my @list = git_get_projects_list
($project);
4010 die_error
(404, "No forks found");
4014 git_print_page_nav
('','');
4015 git_print_header_div
('summary', "$project forks");
4016 git_project_list_body
(\
@list, $order);
4020 sub git_project_index
{
4021 my @projects = git_get_projects_list
($project);
4024 -type
=> 'text/plain',
4025 -charset
=> 'utf-8',
4026 -content_disposition
=> 'inline; filename="index.aux"');
4028 foreach my $pr (@projects) {
4029 if (!exists $pr->{'owner'}) {
4030 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4033 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4034 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4035 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4036 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4040 print "$path $owner\n";
4045 my $descr = git_get_project_description
($project) || "none";
4046 my %co = parse_commit
("HEAD");
4047 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4048 my $head = $co{'id'};
4050 my $owner = git_get_project_owner
($project);
4052 my $refs = git_get_references
();
4053 # These get_*_list functions return one more to allow us to see if
4054 # there are more ...
4055 my @taglist = git_get_tags_list
(16);
4056 my @headlist = git_get_heads_list
(16);
4058 my ($check_forks) = gitweb_check_feature
('forks');
4061 @forklist = git_get_projects_list
($project);
4065 git_print_page_nav
('summary','', $head);
4067 print "<div class=\"title\"> </div>\n";
4068 print "<table class=\"projects_list\">\n" .
4069 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4070 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4071 if (defined $cd{'rfc2822'}) {
4072 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4075 # use per project git URL list in $projectroot/$project/cloneurl
4076 # or make project git URL from git base URL and project name
4077 my $url_tag = "URL";
4078 my @url_list = git_get_project_url_list
($project);
4079 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4080 foreach my $git_url (@url_list) {
4081 next unless $git_url;
4082 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4087 if (-s
"$projectroot/$project/README.html") {
4088 if (open my $fd, "$projectroot/$project/README.html") {
4089 print "<div class=\"title\">readme</div>\n" .
4090 "<div class=\"readme\">\n";
4091 print $_ while (<$fd>);
4092 print "\n</div>\n"; # class="readme"
4097 # we need to request one more than 16 (0..15) to check if
4099 my @commitlist = $head ? parse_commits
($head, 17) : ();
4101 git_print_header_div
('shortlog');
4102 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4103 $#commitlist <= 15 ? undef :
4104 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4108 git_print_header_div
('tags');
4109 git_tags_body
(\
@taglist, 0, 15,
4110 $#taglist <= 15 ? undef :
4111 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4115 git_print_header_div
('heads');
4116 git_heads_body
(\
@headlist, $head, 0, 15,
4117 $#headlist <= 15 ? undef :
4118 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4122 git_print_header_div
('forks');
4123 git_project_list_body
(\
@forklist, undef, 0, 15,
4124 $#forklist <= 15 ? undef :
4125 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4133 my $head = git_get_head_hash
($project);
4135 git_print_page_nav
('','', $head,undef,$head);
4136 my %tag = parse_tag
($hash);
4139 die_error
(404, "Unknown tag object");
4142 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4143 print "<div class=\"title_text\">\n" .
4144 "<table class=\"object_header\">\n" .
4146 "<td>object</td>\n" .
4147 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4148 $tag{'object'}) . "</td>\n" .
4149 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4150 $tag{'type'}) . "</td>\n" .
4152 if (defined($tag{'author'})) {
4153 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4154 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4155 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4156 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4159 print "</table>\n\n" .
4161 print "<div class=\"page_body\">";
4162 my $comment = $tag{'comment'};
4163 foreach my $line (@$comment) {
4165 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4175 gitweb_check_feature
('blame')
4176 or die_error
(403, "Blame view not allowed");
4178 die_error
(400, "No file name given") unless $file_name;
4179 $hash_base ||= git_get_head_hash
($project);
4180 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4181 my %co = parse_commit
($hash_base)
4182 or die_error
(404, "Commit not found");
4183 if (!defined $hash) {
4184 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4185 or die_error
(404, "Error looking up file");
4187 $ftype = git_get_type
($hash);
4188 if ($ftype !~ "blob") {
4189 die_error
(400, "Object is not a blob");
4191 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4192 $file_name, $hash_base)
4193 or die_error
(500, "Open git-blame failed");
4196 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4199 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4202 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4204 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4205 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4206 git_print_page_path
($file_name, $ftype, $hash_base);
4207 my @rev_color = (qw(light2 dark2));
4208 my $num_colors = scalar(@rev_color);
4209 my $current_color = 0;
4212 <div class="page_body">
4213 <table class="blame">
4214 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4219 last unless defined $_;
4220 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4221 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4222 if (!exists $metainfo{$full_rev}) {
4223 $metainfo{$full_rev} = {};
4225 my $meta = $metainfo{$full_rev};
4228 if (/^(\S+) (.*)$/) {
4234 my $rev = substr($full_rev, 0, 8);
4235 my $author = $meta->{'author'};
4236 my %date = parse_date
($meta->{'author-time'},
4237 $meta->{'author-tz'});
4238 my $date = $date{'iso-tz'};
4240 $current_color = ++$current_color % $num_colors;
4242 print "<tr class=\"$rev_color[$current_color]\">\n";
4244 print "<td class=\"sha1\"";
4245 print " title=\"". esc_html
($author) . ", $date\"";
4246 print " rowspan=\"$group_size\"" if ($group_size > 1);
4248 print $cgi->a({-href
=> href
(action
=>"commit",
4250 file_name
=>$file_name)},
4254 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4255 or die_error
(500, "Open git-rev-parse failed");
4256 my $parent_commit = <$dd>;
4258 chomp($parent_commit);
4259 my $blamed = href
(action
=> 'blame',
4260 file_name
=> $meta->{'filename'},
4261 hash_base
=> $parent_commit);
4262 print "<td class=\"linenr\">";
4263 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4265 -class => "linenr" },
4268 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4274 or print "Reading blob failed\n";
4279 my $head = git_get_head_hash
($project);
4281 git_print_page_nav
('','', $head,undef,$head);
4282 git_print_header_div
('summary', $project);
4284 my @tagslist = git_get_tags_list
();
4286 git_tags_body
(\
@tagslist);
4292 my $head = git_get_head_hash
($project);
4294 git_print_page_nav
('','', $head,undef,$head);
4295 git_print_header_div
('summary', $project);
4297 my @headslist = git_get_heads_list
();
4299 git_heads_body
(\
@headslist, $head);
4304 sub git_blob_plain
{
4308 if (!defined $hash) {
4309 if (defined $file_name) {
4310 my $base = $hash_base || git_get_head_hash
($project);
4311 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4312 or die_error
(404, "Cannot find file");
4314 die_error
(400, "No file name defined");
4316 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4317 # blobs defined by non-textual hash id's can be cached
4321 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4322 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4324 # content-type (can include charset)
4325 $type = blob_contenttype
($fd, $file_name, $type);
4327 # "save as" filename, even when no $file_name is given
4328 my $save_as = "$hash";
4329 if (defined $file_name) {
4330 $save_as = $file_name;
4331 } elsif ($type =~ m/^text\//) {
4337 -expires
=> $expires,
4338 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4340 binmode STDOUT
, ':raw';
4342 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4350 if (!defined $hash) {
4351 if (defined $file_name) {
4352 my $base = $hash_base || git_get_head_hash
($project);
4353 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4354 or die_error
(404, "Cannot find file");
4356 die_error
(400, "No file name defined");
4358 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4359 # blobs defined by non-textual hash id's can be cached
4363 my ($have_blame) = gitweb_check_feature
('blame');
4364 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4365 or die_error
(500, "Couldn't cat $file_name, $hash");
4366 my $mimetype = blob_mimetype
($fd, $file_name);
4367 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4369 return git_blob_plain
($mimetype);
4371 # we can have blame only for text/* mimetype
4372 $have_blame &&= ($mimetype =~ m!^text/!);
4374 git_header_html
(undef, $expires);
4375 my $formats_nav = '';
4376 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4377 if (defined $file_name) {
4380 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4385 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4388 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4391 $cgi->a({-href
=> href
(action
=>"blob",
4392 hash_base
=>"HEAD", file_name
=>$file_name)},
4396 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4399 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4400 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4402 print "<div class=\"page_nav\">\n" .
4403 "<br/><br/></div>\n" .
4404 "<div class=\"title\">$hash</div>\n";
4406 git_print_page_path
($file_name, "blob", $hash_base);
4407 print "<div class=\"page_body\">\n";
4408 if ($mimetype =~ m!^image/!) {
4409 print qq
!<img type
="$mimetype"!;
4411 print qq
! alt
="$file_name" title
="$file_name"!;
4414 href(action=>"blob_plain
", hash=>$hash,
4415 hash_base=>$hash_base, file_name=>$file_name) .
4419 while (my $line = <$fd>) {
4422 $line = untabify
($line);
4423 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4424 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4428 or print "Reading blob failed.\n";
4434 if (!defined $hash_base) {
4435 $hash_base = "HEAD";
4437 if (!defined $hash) {
4438 if (defined $file_name) {
4439 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4445 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4446 or die_error
(500, "Open git-ls-tree failed");
4447 my @entries = map { chomp; $_ } <$fd>;
4448 close $fd or die_error
(404, "Reading tree failed");
4451 my $refs = git_get_references
();
4452 my $ref = format_ref_marker
($refs, $hash_base);
4455 my ($have_blame) = gitweb_check_feature
('blame');
4456 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4458 if (defined $file_name) {
4460 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4462 $cgi->a({-href
=> href
(action
=>"tree",
4463 hash_base
=>"HEAD", file_name
=>$file_name)},
4466 my $snapshot_links = format_snapshot_links
($hash);
4467 if (defined $snapshot_links) {
4468 # FIXME: Should be available when we have no hash base as well.
4469 push @views_nav, $snapshot_links;
4471 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4472 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4475 print "<div class=\"page_nav\">\n";
4476 print "<br/><br/></div>\n";
4477 print "<div class=\"title\">$hash</div>\n";
4479 if (defined $file_name) {
4480 $basedir = $file_name;
4481 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4485 git_print_page_path
($file_name, 'tree', $hash_base);
4486 print "<div class=\"page_body\">\n";
4487 print "<table class=\"tree\">\n";
4489 # '..' (top directory) link if possible
4490 if (defined $hash_base &&
4491 defined $file_name && $file_name =~ m![^/]+$!) {
4493 print "<tr class=\"dark\">\n";
4495 print "<tr class=\"light\">\n";
4499 my $up = $file_name;
4500 $up =~ s!/?[^/]+$!!;
4501 undef $up unless $up;
4502 # based on git_print_tree_entry
4503 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4504 print '<td class="list">';
4505 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4509 print "<td class=\"link\"></td>\n";
4513 foreach my $line (@entries) {
4514 my %t = parse_ls_tree_line
($line, -z
=> 1);
4517 print "<tr class=\"dark\">\n";
4519 print "<tr class=\"light\">\n";
4523 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4527 print "</table>\n" .
4533 my @supported_fmts = gitweb_check_feature
('snapshot');
4534 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4536 my $format = $cgi->param('sf');
4537 if (!@supported_fmts) {
4538 die_error
(403, "Snapshots not allowed");
4540 # default to first supported snapshot format
4541 $format ||= $supported_fmts[0];
4542 if ($format !~ m/^[a-z0-9]+$/) {
4543 die_error
(400, "Invalid snapshot format parameter");
4544 } elsif (!exists($known_snapshot_formats{$format})) {
4545 die_error
(400, "Unknown snapshot format");
4546 } elsif (!grep($_ eq $format, @supported_fmts)) {
4547 die_error
(403, "Unsupported snapshot format");
4550 if (!defined $hash) {
4551 $hash = git_get_head_hash
($project);
4554 my $name = $project;
4555 $name =~ s
,([^/])/*\
.git
$,$1,;
4556 $name = basename
($name);
4557 my $filename = to_utf8
($name);
4558 $name =~ s/\047/\047\\\047\047/g;
4560 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4561 $cmd = quote_command
(
4562 git_cmd
(), 'archive',
4563 "--format=$known_snapshot_formats{$format}{'format'}",
4564 "--prefix=$name/", $hash);
4565 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4566 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4570 -type
=> $known_snapshot_formats{$format}{'type'},
4571 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4572 -status
=> '200 OK');
4574 open my $fd, "-|", $cmd
4575 or die_error
(500, "Execute git-archive failed");
4576 binmode STDOUT
, ':raw';
4578 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4583 my $head = git_get_head_hash
($project);
4584 if (!defined $hash) {
4587 if (!defined $page) {
4590 my $refs = git_get_references
();
4592 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4594 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4597 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4600 my %co = parse_commit
($hash);
4602 git_print_header_div
('summary', $project);
4603 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4605 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4606 for (my $i = 0; $i <= $to; $i++) {
4607 my %co = %{$commitlist[$i]};
4609 my $commit = $co{'id'};
4610 my $ref = format_ref_marker
($refs, $commit);
4611 my %ad = parse_date
($co{'author_epoch'});
4612 git_print_header_div
('commit',
4613 "<span class=\"age\">$co{'age_string'}</span>" .
4614 esc_html
($co{'title'}) . $ref,
4616 print "<div class=\"title_text\">\n" .
4617 "<div class=\"log_link\">\n" .
4618 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4620 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4622 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4625 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4628 print "<div class=\"log_body\">\n";
4629 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4632 if ($#commitlist >= 100) {
4633 print "<div class=\"page_nav\">\n";
4634 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4635 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4642 $hash ||= $hash_base || "HEAD";
4643 my %co = parse_commit
($hash)
4644 or die_error
(404, "Unknown commit object");
4645 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4646 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4648 my $parent = $co{'parent'};
4649 my $parents = $co{'parents'}; # listref
4651 # we need to prepare $formats_nav before any parameter munging
4653 if (!defined $parent) {
4655 $formats_nav .= '(initial)';
4656 } elsif (@$parents == 1) {
4657 # single parent commit
4660 $cgi->a({-href
=> href
(action
=>"commit",
4662 esc_html
(substr($parent, 0, 7))) .
4669 $cgi->a({-href
=> href
(action
=>"commit",
4671 esc_html
(substr($_, 0, 7)));
4676 if (!defined $parent) {
4680 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4682 (@$parents <= 1 ? $parent : '-c'),
4684 or die_error
(500, "Open git-diff-tree failed");
4685 @difftree = map { chomp; $_ } <$fd>;
4686 close $fd or die_error
(404, "Reading git-diff-tree failed");
4688 # non-textual hash id's can be cached
4690 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4693 my $refs = git_get_references
();
4694 my $ref = format_ref_marker
($refs, $co{'id'});
4696 git_header_html
(undef, $expires);
4697 git_print_page_nav
('commit', '',
4698 $hash, $co{'tree'}, $hash,
4701 if (defined $co{'parent'}) {
4702 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4704 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4706 print "<div class=\"title_text\">\n" .
4707 "<table class=\"object_header\">\n";
4708 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4710 "<td></td><td> $ad{'rfc2822'}";
4711 if ($ad{'hour_local'} < 6) {
4712 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4713 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4715 printf(" (%02d:%02d %s)",
4716 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4720 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4721 print "<tr><td></td><td> $cd{'rfc2822'}" .
4722 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4724 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4727 "<td class=\"sha1\">" .
4728 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4729 class => "list"}, $co{'tree'}) .
4731 "<td class=\"link\">" .
4732 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4734 my $snapshot_links = format_snapshot_links
($hash);
4735 if (defined $snapshot_links) {
4736 print " | " . $snapshot_links;
4741 foreach my $par (@$parents) {
4744 "<td class=\"sha1\">" .
4745 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4746 class => "list"}, $par) .
4748 "<td class=\"link\">" .
4749 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4751 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4758 print "<div class=\"page_body\">\n";
4759 git_print_log
($co{'comment'});
4762 git_difftree_body
(\
@difftree, $hash, @$parents);
4768 # object is defined by:
4769 # - hash or hash_base alone
4770 # - hash_base and file_name
4773 # - hash or hash_base alone
4774 if ($hash || ($hash_base && !defined $file_name)) {
4775 my $object_id = $hash || $hash_base;
4777 open my $fd, "-|", quote_command
(
4778 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4779 or die_error
(404, "Object does not exist");
4783 or die_error
(404, "Object does not exist");
4785 # - hash_base and file_name
4786 } elsif ($hash_base && defined $file_name) {
4787 $file_name =~ s
,/+$,,;
4789 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4790 or die_error
(404, "Base object does not exist");
4792 # here errors should not hapen
4793 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4794 or die_error
(500, "Open git-ls-tree failed");
4798 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4799 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4800 die_error
(404, "File or directory for given base does not exist");
4805 die_error
(400, "Not enough information to find object");
4808 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4809 hash
=>$hash, hash_base
=>$hash_base,
4810 file_name
=>$file_name),
4811 -status
=> '302 Found');
4815 my $format = shift || 'html';
4822 # preparing $fd and %diffinfo for git_patchset_body
4824 if (defined $hash_base && defined $hash_parent_base) {
4825 if (defined $file_name) {
4827 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4828 $hash_parent_base, $hash_base,
4829 "--", (defined $file_parent ? $file_parent : ()), $file_name
4830 or die_error
(500, "Open git-diff-tree failed");
4831 @difftree = map { chomp; $_ } <$fd>;
4833 or die_error
(404, "Reading git-diff-tree failed");
4835 or die_error
(404, "Blob diff not found");
4837 } elsif (defined $hash &&
4838 $hash =~ /[0-9a-fA-F]{40}/) {
4839 # try to find filename from $hash
4841 # read filtered raw output
4842 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4843 $hash_parent_base, $hash_base, "--"
4844 or die_error
(500, "Open git-diff-tree failed");
4846 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4848 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4849 map { chomp; $_ } <$fd>;
4851 or die_error
(404, "Reading git-diff-tree failed");
4853 or die_error
(404, "Blob diff not found");
4856 die_error
(400, "Missing one of the blob diff parameters");
4859 if (@difftree > 1) {
4860 die_error
(400, "Ambiguous blob diff specification");
4863 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4864 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4865 $file_name ||= $diffinfo{'to_file'};
4867 $hash_parent ||= $diffinfo{'from_id'};
4868 $hash ||= $diffinfo{'to_id'};
4870 # non-textual hash id's can be cached
4871 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4872 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4877 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4878 '-p', ($format eq 'html' ? "--full-index" : ()),
4879 $hash_parent_base, $hash_base,
4880 "--", (defined $file_parent ? $file_parent : ()), $file_name
4881 or die_error
(500, "Open git-diff-tree failed");
4884 # old/legacy style URI
4885 if (!%diffinfo && # if new style URI failed
4886 defined $hash && defined $hash_parent) {
4887 # fake git-diff-tree raw output
4888 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4889 $diffinfo{'from_id'} = $hash_parent;
4890 $diffinfo{'to_id'} = $hash;
4891 if (defined $file_name) {
4892 if (defined $file_parent) {
4893 $diffinfo{'status'} = '2';
4894 $diffinfo{'from_file'} = $file_parent;
4895 $diffinfo{'to_file'} = $file_name;
4896 } else { # assume not renamed
4897 $diffinfo{'status'} = '1';
4898 $diffinfo{'from_file'} = $file_name;
4899 $diffinfo{'to_file'} = $file_name;
4901 } else { # no filename given
4902 $diffinfo{'status'} = '2';
4903 $diffinfo{'from_file'} = $hash_parent;
4904 $diffinfo{'to_file'} = $hash;
4907 # non-textual hash id's can be cached
4908 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4909 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4914 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4915 '-p', ($format eq 'html' ? "--full-index" : ()),
4916 $hash_parent, $hash, "--"
4917 or die_error
(500, "Open git-diff failed");
4919 die_error
(400, "Missing one of the blob diff parameters")
4924 if ($format eq 'html') {
4926 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4928 git_header_html
(undef, $expires);
4929 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4930 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4931 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4933 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4934 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4936 if (defined $file_name) {
4937 git_print_page_path
($file_name, "blob", $hash_base);
4939 print "<div class=\"page_path\"></div>\n";
4942 } elsif ($format eq 'plain') {
4944 -type
=> 'text/plain',
4945 -charset
=> 'utf-8',
4946 -expires
=> $expires,
4947 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4949 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4952 die_error
(400, "Unknown blobdiff format");
4956 if ($format eq 'html') {
4957 print "<div class=\"page_body\">\n";
4959 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4962 print "</div>\n"; # class="page_body"
4966 while (my $line = <$fd>) {
4967 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4968 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4972 last if $line =~ m!^\+\+\+!;
4980 sub git_blobdiff_plain
{
4981 git_blobdiff
('plain');
4984 sub git_commitdiff
{
4985 my $format = shift || 'html';
4986 $hash ||= $hash_base || "HEAD";
4987 my %co = parse_commit
($hash)
4988 or die_error
(404, "Unknown commit object");
4990 # choose format for commitdiff for merge
4991 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4992 $hash_parent = '--cc';
4994 # we need to prepare $formats_nav before almost any parameter munging
4996 if ($format eq 'html') {
4998 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5001 if (defined $hash_parent &&
5002 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5003 # commitdiff with two commits given
5004 my $hash_parent_short = $hash_parent;
5005 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5006 $hash_parent_short = substr($hash_parent, 0, 7);
5010 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5011 if ($co{'parents'}[$i] eq $hash_parent) {
5012 $formats_nav .= ' parent ' . ($i+1);
5016 $formats_nav .= ': ' .
5017 $cgi->a({-href
=> href
(action
=>"commitdiff",
5018 hash
=>$hash_parent)},
5019 esc_html
($hash_parent_short)) .
5021 } elsif (!$co{'parent'}) {
5023 $formats_nav .= ' (initial)';
5024 } elsif (scalar @{$co{'parents'}} == 1) {
5025 # single parent commit
5028 $cgi->a({-href
=> href
(action
=>"commitdiff",
5029 hash
=>$co{'parent'})},
5030 esc_html
(substr($co{'parent'}, 0, 7))) .
5034 if ($hash_parent eq '--cc') {
5035 $formats_nav .= ' | ' .
5036 $cgi->a({-href
=> href
(action
=>"commitdiff",
5037 hash
=>$hash, hash_parent
=>'-c')},
5039 } else { # $hash_parent eq '-c'
5040 $formats_nav .= ' | ' .
5041 $cgi->a({-href
=> href
(action
=>"commitdiff",
5042 hash
=>$hash, hash_parent
=>'--cc')},
5048 $cgi->a({-href
=> href
(action
=>"commitdiff",
5050 esc_html
(substr($_, 0, 7)));
5051 } @{$co{'parents'}} ) .
5056 my $hash_parent_param = $hash_parent;
5057 if (!defined $hash_parent_param) {
5058 # --cc for multiple parents, --root for parentless
5059 $hash_parent_param =
5060 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5066 if ($format eq 'html') {
5067 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5068 "--no-commit-id", "--patch-with-raw", "--full-index",
5069 $hash_parent_param, $hash, "--"
5070 or die_error
(500, "Open git-diff-tree failed");
5072 while (my $line = <$fd>) {
5074 # empty line ends raw part of diff-tree output
5076 push @difftree, scalar parse_difftree_raw_line
($line);
5079 } elsif ($format eq 'plain') {
5080 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5081 '-p', $hash_parent_param, $hash, "--"
5082 or die_error
(500, "Open git-diff-tree failed");
5085 die_error
(400, "Unknown commitdiff format");
5088 # non-textual hash id's can be cached
5090 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5094 # write commit message
5095 if ($format eq 'html') {
5096 my $refs = git_get_references
();
5097 my $ref = format_ref_marker
($refs, $co{'id'});
5099 git_header_html
(undef, $expires);
5100 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5101 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5102 git_print_authorship
(\
%co);
5103 print "<div class=\"page_body\">\n";
5104 if (@{$co{'comment'}} > 1) {
5105 print "<div class=\"log\">\n";
5106 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5107 print "</div>\n"; # class="log"
5110 } elsif ($format eq 'plain') {
5111 my $refs = git_get_references
("tags");
5112 my $tagname = git_get_rev_name_tags
($hash);
5113 my $filename = basename
($project) . "-$hash.patch";
5116 -type
=> 'text/plain',
5117 -charset
=> 'utf-8',
5118 -expires
=> $expires,
5119 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5120 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5121 print "From: " . to_utf8
($co{'author'}) . "\n";
5122 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5123 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5125 print "X-Git-Tag: $tagname\n" if $tagname;
5126 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5128 foreach my $line (@{$co{'comment'}}) {
5129 print to_utf8
($line) . "\n";
5135 if ($format eq 'html') {
5136 my $use_parents = !defined $hash_parent ||
5137 $hash_parent eq '-c' || $hash_parent eq '--cc';
5138 git_difftree_body
(\
@difftree, $hash,
5139 $use_parents ? @{$co{'parents'}} : $hash_parent);
5142 git_patchset_body
($fd, \
@difftree, $hash,
5143 $use_parents ? @{$co{'parents'}} : $hash_parent);
5145 print "</div>\n"; # class="page_body"
5148 } elsif ($format eq 'plain') {
5152 or print "Reading git-diff-tree failed\n";
5156 sub git_commitdiff_plain
{
5157 git_commitdiff
('plain');
5161 if (!defined $hash_base) {
5162 $hash_base = git_get_head_hash
($project);
5164 if (!defined $page) {
5168 my %co = parse_commit
($hash_base)
5169 or die_error
(404, "Unknown commit object");
5171 my $refs = git_get_references
();
5172 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5174 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5175 $file_name, "--full-history")
5176 or die_error
(404, "No such file or directory on given branch");
5178 if (!defined $hash && defined $file_name) {
5179 # some commits could have deleted file in question,
5180 # and not have it in tree, but one of them has to have it
5181 for (my $i = 0; $i <= @commitlist; $i++) {
5182 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5183 last if defined $hash;
5186 if (defined $hash) {
5187 $ftype = git_get_type
($hash);
5189 if (!defined $ftype) {
5190 die_error
(500, "Unknown type of object");
5193 my $paging_nav = '';
5196 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5197 file_name
=>$file_name)},
5199 $paging_nav .= " ⋅ " .
5200 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5201 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5203 $paging_nav .= "first";
5204 $paging_nav .= " ⋅ prev";
5207 if ($#commitlist >= 100) {
5209 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5210 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5211 $paging_nav .= " ⋅ $next_link";
5213 $paging_nav .= " ⋅ next";
5217 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5218 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5219 git_print_page_path
($file_name, $ftype, $hash_base);
5221 git_history_body
(\
@commitlist, 0, 99,
5222 $refs, $hash_base, $ftype, $next_link);
5228 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5229 if (!defined $searchtext) {
5230 die_error
(400, "Text field is empty");
5232 if (!defined $hash) {
5233 $hash = git_get_head_hash
($project);
5235 my %co = parse_commit
($hash);
5237 die_error
(404, "Unknown commit object");
5239 if (!defined $page) {
5243 $searchtype ||= 'commit';
5244 if ($searchtype eq 'pickaxe') {
5245 # pickaxe may take all resources of your box and run for several minutes
5246 # with every query - so decide by yourself how public you make this feature
5247 gitweb_check_feature
('pickaxe')
5248 or die_error
(403, "Pickaxe is disabled");
5250 if ($searchtype eq 'grep') {
5251 gitweb_check_feature
('grep')
5252 or die_error
(403, "Grep is disabled");
5257 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5259 if ($searchtype eq 'commit') {
5260 $greptype = "--grep=";
5261 } elsif ($searchtype eq 'author') {
5262 $greptype = "--author=";
5263 } elsif ($searchtype eq 'committer') {
5264 $greptype = "--committer=";
5266 $greptype .= $searchtext;
5267 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5268 $greptype, '--regexp-ignore-case',
5269 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5271 my $paging_nav = '';
5274 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5275 searchtext
=>$searchtext,
5276 searchtype
=>$searchtype)},
5278 $paging_nav .= " ⋅ " .
5279 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5280 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5282 $paging_nav .= "first";
5283 $paging_nav .= " ⋅ prev";
5286 if ($#commitlist >= 100) {
5288 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5289 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5290 $paging_nav .= " ⋅ $next_link";
5292 $paging_nav .= " ⋅ next";
5295 if ($#commitlist >= 100) {
5298 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5299 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5300 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5303 if ($searchtype eq 'pickaxe') {
5304 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5305 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5307 print "<table class=\"pickaxe search\">\n";
5310 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5311 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5312 ($search_use_regexp ? '--pickaxe-regex' : ());
5315 while (my $line = <$fd>) {
5319 my %set = parse_difftree_raw_line
($line);
5320 if (defined $set{'commit'}) {
5321 # finish previous commit
5324 "<td class=\"link\">" .
5325 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5327 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5333 print "<tr class=\"dark\">\n";
5335 print "<tr class=\"light\">\n";
5338 %co = parse_commit
($set{'commit'});
5339 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5340 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5341 "<td><i>$author</i></td>\n" .
5343 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5344 -class => "list subject"},
5345 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5346 } elsif (defined $set{'to_id'}) {
5347 next if ($set{'to_id'} =~ m/^0{40}$/);
5349 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5350 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5352 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5358 # finish last commit (warning: repetition!)
5361 "<td class=\"link\">" .
5362 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5364 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5372 if ($searchtype eq 'grep') {
5373 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5374 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5376 print "<table class=\"grep_search\">\n";
5380 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5381 $search_use_regexp ? ('-E', '-i') : '-F',
5382 $searchtext, $co{'tree'};
5384 while (my $line = <$fd>) {
5386 my ($file, $lno, $ltext, $binary);
5387 last if ($matches++ > 1000);
5388 if ($line =~ /^Binary file (.+) matches$/) {
5392 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5394 if ($file ne $lastfile) {
5395 $lastfile and print "</td></tr>\n";
5397 print "<tr class=\"dark\">\n";
5399 print "<tr class=\"light\">\n";
5401 print "<td class=\"list\">".
5402 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5403 file_name
=>"$file"),
5404 -class => "list"}, esc_path
($file));
5405 print "</td><td>\n";
5409 print "<div class=\"binary\">Binary file</div>\n";
5411 $ltext = untabify
($ltext);
5412 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5413 $ltext = esc_html
($1, -nbsp
=>1);
5414 $ltext .= '<span class="match">';
5415 $ltext .= esc_html
($2, -nbsp
=>1);
5416 $ltext .= '</span>';
5417 $ltext .= esc_html
($3, -nbsp
=>1);
5419 $ltext = esc_html
($ltext, -nbsp
=>1);
5421 print "<div class=\"pre\">" .
5422 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5423 file_name
=>"$file").'#l'.$lno,
5424 -class => "linenr"}, sprintf('%4i', $lno))
5425 . ' ' . $ltext . "</div>\n";
5429 print "</td></tr>\n";
5430 if ($matches > 1000) {
5431 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5434 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5443 sub git_search_help
{
5445 git_print_page_nav
('','', $hash,$hash,$hash);
5447 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5448 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5449 the pattern entered is recognized as the POSIX extended
5450 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5453 <dt><b>commit</b></dt>
5454 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5456 my ($have_grep) = gitweb_check_feature
('grep');
5459 <dt><b>grep</b></dt>
5460 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5461 a different one) are searched for the given pattern. On large trees, this search can take
5462 a while and put some strain on the server, so please use it with some consideration. Note that
5463 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5464 case-sensitive.</dd>
5468 <dt><b>author</b></dt>
5469 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5470 <dt><b>committer</b></dt>
5471 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5473 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5474 if ($have_pickaxe) {
5476 <dt><b>pickaxe</b></dt>
5477 <dd>All commits that caused the string to appear or disappear from any file (changes that
5478 added, removed or "modified" the string) will be listed. This search can take a while and
5479 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5480 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5488 my $head = git_get_head_hash
($project);
5489 if (!defined $hash) {
5492 if (!defined $page) {
5495 my $refs = git_get_references
();
5497 my $commit_hash = $hash;
5498 if (defined $hash_parent) {
5499 $commit_hash = "$hash_parent..$hash";
5501 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5503 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5505 if ($#commitlist >= 100) {
5507 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5508 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5512 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5513 git_print_header_div
('summary', $project);
5515 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5520 ## ......................................................................
5521 ## feeds (RSS, Atom; OPML)
5524 my $format = shift || 'atom';
5525 my ($have_blame) = gitweb_check_feature
('blame');
5527 # Atom: http://www.atomenabled.org/developers/syndication/
5528 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5529 if ($format ne 'rss' && $format ne 'atom') {
5530 die_error
(400, "Unknown web feed format");
5533 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5534 my $head = $hash || 'HEAD';
5535 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5539 my $content_type = "application/$format+xml";
5540 if (defined $cgi->http('HTTP_ACCEPT') &&
5541 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5542 # browser (feed reader) prefers text/xml
5543 $content_type = 'text/xml';
5545 if (defined($commitlist[0])) {
5546 %latest_commit = %{$commitlist[0]};
5547 %latest_date = parse_date
($latest_commit{'author_epoch'});
5549 -type
=> $content_type,
5550 -charset
=> 'utf-8',
5551 -last_modified
=> $latest_date{'rfc2822'});
5554 -type
=> $content_type,
5555 -charset
=> 'utf-8');
5558 # Optimization: skip generating the body if client asks only
5559 # for Last-Modified date.
5560 return if ($cgi->request_method() eq 'HEAD');
5563 my $title = "$site_name - $project/$action";
5564 my $feed_type = 'log';
5565 if (defined $hash) {
5566 $title .= " - '$hash'";
5567 $feed_type = 'branch log';
5568 if (defined $file_name) {
5569 $title .= " :: $file_name";
5570 $feed_type = 'history';
5572 } elsif (defined $file_name) {
5573 $title .= " - $file_name";
5574 $feed_type = 'history';
5576 $title .= " $feed_type";
5577 my $descr = git_get_project_description
($project);
5578 if (defined $descr) {
5579 $descr = esc_html
($descr);
5581 $descr = "$project " .
5582 ($format eq 'rss' ? 'RSS' : 'Atom') .
5585 my $owner = git_get_project_owner
($project);
5586 $owner = esc_html
($owner);
5590 if (defined $file_name) {
5591 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5592 } elsif (defined $hash) {
5593 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5595 $alt_url = href
(-full
=>1, action
=>"summary");
5597 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5598 if ($format eq 'rss') {
5600 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5603 print "<title>$title</title>\n" .
5604 "<link>$alt_url</link>\n" .
5605 "<description>$descr</description>\n" .
5606 "<language>en</language>\n";
5607 } elsif ($format eq 'atom') {
5609 <feed xmlns="http://www.w3.org/2005/Atom">
5611 print "<title>$title</title>\n" .
5612 "<subtitle>$descr</subtitle>\n" .
5613 '<link rel="alternate" type="text/html" href="' .
5614 $alt_url . '" />' . "\n" .
5615 '<link rel="self" type="' . $content_type . '" href="' .
5616 $cgi->self_url() . '" />' . "\n" .
5617 "<id>" . href
(-full
=>1) . "</id>\n" .
5618 # use project owner for feed author
5619 "<author><name>$owner</name></author>\n";
5620 if (defined $favicon) {
5621 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5623 if (defined $logo_url) {
5624 # not twice as wide as tall: 72 x 27 pixels
5625 print "<logo>" . esc_url
($logo) . "</logo>\n";
5627 if (! %latest_date) {
5628 # dummy date to keep the feed valid until commits trickle in:
5629 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5631 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5636 for (my $i = 0; $i <= $#commitlist; $i++) {
5637 my %co = %{$commitlist[$i]};
5638 my $commit = $co{'id'};
5639 # we read 150, we always show 30 and the ones more recent than 48 hours
5640 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5643 my %cd = parse_date
($co{'author_epoch'});
5645 # get list of changed files
5646 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5647 $co{'parent'} || "--root",
5648 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5650 my @difftree = map { chomp; $_ } <$fd>;
5654 # print element (entry, item)
5655 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5656 if ($format eq 'rss') {
5658 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5659 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5660 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5661 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5662 "<link>$co_url</link>\n" .
5663 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5664 "<content:encoded>" .
5666 } elsif ($format eq 'atom') {
5668 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5669 "<updated>$cd{'iso-8601'}</updated>\n" .
5671 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5672 if ($co{'author_email'}) {
5673 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5675 print "</author>\n" .
5676 # use committer for contributor
5678 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5679 if ($co{'committer_email'}) {
5680 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5682 print "</contributor>\n" .
5683 "<published>$cd{'iso-8601'}</published>\n" .
5684 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5685 "<id>$co_url</id>\n" .
5686 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5687 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5689 my $comment = $co{'comment'};
5691 foreach my $line (@$comment) {
5692 $line = esc_html
($line);
5695 print "</pre><ul>\n";
5696 foreach my $difftree_line (@difftree) {
5697 my %difftree = parse_difftree_raw_line
($difftree_line);
5698 next if !$difftree{'from_id'};
5700 my $file = $difftree{'file'} || $difftree{'to_file'};
5704 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5705 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5706 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5707 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5708 -title
=> "diff"}, 'D');
5710 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5711 file_name
=>$file, hash_base
=>$commit),
5712 -title
=> "blame"}, 'B');
5714 # if this is not a feed of a file history
5715 if (!defined $file_name || $file_name ne $file) {
5716 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5717 file_name
=>$file, hash
=>$commit),
5718 -title
=> "history"}, 'H');
5720 $file = esc_path
($file);
5724 if ($format eq 'rss') {
5725 print "</ul>]]>\n" .
5726 "</content:encoded>\n" .
5728 } elsif ($format eq 'atom') {
5729 print "</ul>\n</div>\n" .
5736 if ($format eq 'rss') {
5737 print "</channel>\n</rss>\n";
5738 } elsif ($format eq 'atom') {
5752 my @list = git_get_projects_list
();
5754 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5756 <?xml version="1.0" encoding="utf-8"?>
5757 <opml version="1.0">
5759 <title>$site_name OPML Export</title>
5762 <outline text="git RSS feeds">
5765 foreach my $pr (@list) {
5767 my $head = git_get_head_hash
($proj{'path'});
5768 if (!defined $head) {
5771 $git_dir = "$projectroot/$proj{'path'}";
5772 my %co = parse_commit
($head);
5777 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5778 my $rss = "$my_url?p=$proj{'path'};a=rss";
5779 my $html = "$my_url?p=$proj{'path'};a=summary";
5780 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";