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
(undef, "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
(undef, "No such project");
407 our $file_name = $cgi->param('f');
408 if (defined $file_name) {
409 if (!validate_pathname
($file_name)) {
410 die_error
(undef, "Invalid file parameter");
414 our $file_parent = $cgi->param('fp');
415 if (defined $file_parent) {
416 if (!validate_pathname
($file_parent)) {
417 die_error
(undef, "Invalid file parent parameter");
421 # parameters which are refnames
422 our $hash = $cgi->param('h');
424 if (!validate_refname
($hash)) {
425 die_error
(undef, "Invalid hash parameter");
429 our $hash_parent = $cgi->param('hp');
430 if (defined $hash_parent) {
431 if (!validate_refname
($hash_parent)) {
432 die_error
(undef, "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
(undef, "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
(undef, "Invalid option parameter");
453 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
454 die_error
(undef, "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
(undef, "Invalid hash parent base parameter");
467 our $page = $cgi->param('pg');
469 if ($page =~ m/[^0-9]/) {
470 die_error
(undef, "Invalid page parameter");
474 our $searchtype = $cgi->param('st');
475 if (defined $searchtype) {
476 if ($searchtype =~ m/[^a-z]/) {
477 die_error
(undef, "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
(undef, "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
,^$project/*,,;
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_blame2
,
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
(undef, "Unknown action");
586 if ($action !~ m/^(opml|project_list|project_index)$/ &&
588 die_error
(undef, "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 .= "/$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 # allow only $len chars, but don't cut a word if it would fit in $add_len
871 # if it doesn't fit, cut it if it's still longer than the dots we would add
872 # remove chopped character entities entirely
874 # when chopping in the middle, distribute $len into left and right part
875 # return early if chopping wouldn't make string shorter
876 if ($where eq 'center') {
877 return $str if ($len + 5 >= length($str)); # filler is length 5
880 return $str if ($len + 4 >= length($str)); # filler is length 4
883 # regexps: ending and beginning with word part up to $add_len
884 my $endre = qr/.{$len}\w{0,$add_len}/;
885 my $begre = qr/\w{0,$add_len}.{$len}/;
887 if ($where eq 'left') {
888 $str =~ m/^(.*?)($begre)$/;
889 my ($lead, $body) = ($1, $2);
890 if (length($lead) > 4) {
891 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
896 } elsif ($where eq 'center') {
897 $str =~ m/^($endre)(.*)$/;
898 my ($left, $str) = ($1, $2);
899 $str =~ m/^(.*?)($begre)$/;
900 my ($mid, $right) = ($1, $2);
901 if (length($mid) > 5) {
902 $left =~ s/&[^;]*$//;
903 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
906 return "$left$mid$right";
909 $str =~ m/^($endre)(.*)$/;
912 if (length($tail) > 4) {
913 $body =~ s/&[^;]*$//;
920 # takes the same arguments as chop_str, but also wraps a <span> around the
921 # result with a title attribute if it does get chopped. Additionally, the
922 # string is HTML-escaped.
923 sub chop_and_escape_str
{
926 my $chopped = chop_str
(@_);
927 if ($chopped eq $str) {
928 return esc_html
($chopped);
930 $str =~ s/([[:cntrl:]])/?/g;
931 return $cgi->span({-title
=>$str}, esc_html
($chopped));
935 ## ----------------------------------------------------------------------
936 ## functions returning short strings
938 # CSS class for given age value (in seconds)
944 } elsif ($age < 60*60*2) {
946 } elsif ($age < 60*60*24*2) {
953 # convert age in seconds to "nn units ago" string
958 if ($age > 60*60*24*365*2) {
959 $age_str = (int $age/60/60/24/365);
960 $age_str .= " years ago";
961 } elsif ($age > 60*60*24*(365/12)*2) {
962 $age_str = int $age/60/60/24/(365/12);
963 $age_str .= " months ago";
964 } elsif ($age > 60*60*24*7*2) {
965 $age_str = int $age/60/60/24/7;
966 $age_str .= " weeks ago";
967 } elsif ($age > 60*60*24*2) {
968 $age_str = int $age/60/60/24;
969 $age_str .= " days ago";
970 } elsif ($age > 60*60*2) {
971 $age_str = int $age/60/60;
972 $age_str .= " hours ago";
973 } elsif ($age > 60*2) {
974 $age_str = int $age/60;
975 $age_str .= " min ago";
978 $age_str .= " sec ago";
980 $age_str .= " right now";
986 S_IFINVALID
=> 0030000,
987 S_IFGITLINK
=> 0160000,
990 # submodule/subproject, a commit object reference
994 return (($mode & S_IFMT
) == S_IFGITLINK
)
997 # convert file mode in octal to symbolic file mode string
999 my $mode = oct shift;
1001 if (S_ISGITLINK
($mode)) {
1002 return 'm---------';
1003 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1004 return 'drwxr-xr-x';
1005 } elsif (S_ISLNK
($mode)) {
1006 return 'lrwxrwxrwx';
1007 } elsif (S_ISREG
($mode)) {
1008 # git cares only about the executable bit
1009 if ($mode & S_IXUSR
) {
1010 return '-rwxr-xr-x';
1012 return '-rw-r--r--';
1015 return '----------';
1019 # convert file mode in octal to file type string
1023 if ($mode !~ m/^[0-7]+$/) {
1029 if (S_ISGITLINK
($mode)) {
1031 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1033 } elsif (S_ISLNK
($mode)) {
1035 } elsif (S_ISREG
($mode)) {
1042 # convert file mode in octal to file type description string
1043 sub file_type_long
{
1046 if ($mode !~ m/^[0-7]+$/) {
1052 if (S_ISGITLINK
($mode)) {
1054 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1056 } elsif (S_ISLNK
($mode)) {
1058 } elsif (S_ISREG
($mode)) {
1059 if ($mode & S_IXUSR
) {
1060 return "executable";
1070 ## ----------------------------------------------------------------------
1071 ## functions returning short HTML fragments, or transforming HTML fragments
1072 ## which don't belong to other sections
1074 # format line of commit message.
1075 sub format_log_line_html
{
1078 $line = esc_html
($line, -nbsp
=>1);
1079 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1082 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1083 -class => "text"}, $hash_text);
1084 $line =~ s/$hash_text/$link/;
1089 # format marker of refs pointing to given object
1090 sub format_ref_marker
{
1091 my ($refs, $id) = @_;
1094 if (defined $refs->{$id}) {
1095 foreach my $ref (@{$refs->{$id}}) {
1096 my ($type, $name) = qw();
1097 # e.g. tags/v2.6.11 or heads/next
1098 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1106 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1107 esc_html
($name) . "</span>";
1112 return ' <span class="refs">'. $markers . '</span>';
1118 # format, perhaps shortened and with markers, title line
1119 sub format_subject_html
{
1120 my ($long, $short, $href, $extra) = @_;
1121 $extra = '' unless defined($extra);
1123 if (length($short) < length($long)) {
1124 return $cgi->a({-href
=> $href, -class => "list subject",
1125 -title
=> to_utf8
($long)},
1126 esc_html
($short) . $extra);
1128 return $cgi->a({-href
=> $href, -class => "list subject"},
1129 esc_html
($long) . $extra);
1133 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1134 sub format_git_diff_header_line
{
1136 my $diffinfo = shift;
1137 my ($from, $to) = @_;
1139 if ($diffinfo->{'nparents'}) {
1141 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1142 if ($to->{'href'}) {
1143 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1144 esc_path
($to->{'file'}));
1145 } else { # file was deleted (no href)
1146 $line .= esc_path
($to->{'file'});
1150 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1151 if ($from->{'href'}) {
1152 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1153 'a/' . esc_path
($from->{'file'}));
1154 } else { # file was added (no href)
1155 $line .= 'a/' . esc_path
($from->{'file'});
1158 if ($to->{'href'}) {
1159 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1160 'b/' . esc_path
($to->{'file'}));
1161 } else { # file was deleted
1162 $line .= 'b/' . esc_path
($to->{'file'});
1166 return "<div class=\"diff header\">$line</div>\n";
1169 # format extended diff header line, before patch itself
1170 sub format_extended_diff_header_line
{
1172 my $diffinfo = shift;
1173 my ($from, $to) = @_;
1176 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1177 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1178 esc_path
($from->{'file'}));
1180 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1181 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1182 esc_path
($to->{'file'}));
1184 # match single <mode>
1185 if ($line =~ m/\s(\d{6})$/) {
1186 $line .= '<span class="info"> (' .
1187 file_type_long
($1) .
1191 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1192 # can match only for combined diff
1194 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1195 if ($from->{'href'}[$i]) {
1196 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1198 substr($diffinfo->{'from_id'}[$i],0,7));
1203 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1206 if ($to->{'href'}) {
1207 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1208 substr($diffinfo->{'to_id'},0,7));
1213 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1214 # can match only for ordinary diff
1215 my ($from_link, $to_link);
1216 if ($from->{'href'}) {
1217 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1218 substr($diffinfo->{'from_id'},0,7));
1220 $from_link = '0' x
7;
1222 if ($to->{'href'}) {
1223 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1224 substr($diffinfo->{'to_id'},0,7));
1228 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1229 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1232 return $line . "<br/>\n";
1235 # format from-file/to-file diff header
1236 sub format_diff_from_to_header
{
1237 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1242 #assert($line =~ m/^---/) if DEBUG;
1243 # no extra formatting for "^--- /dev/null"
1244 if (! $diffinfo->{'nparents'}) {
1245 # ordinary (single parent) diff
1246 if ($line =~ m!^--- "?a/!) {
1247 if ($from->{'href'}) {
1249 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1250 esc_path
($from->{'file'}));
1253 esc_path
($from->{'file'});
1256 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1259 # combined diff (merge commit)
1260 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1261 if ($from->{'href'}[$i]) {
1263 $cgi->a({-href
=>href
(action
=>"blobdiff",
1264 hash_parent
=>$diffinfo->{'from_id'}[$i],
1265 hash_parent_base
=>$parents[$i],
1266 file_parent
=>$from->{'file'}[$i],
1267 hash
=>$diffinfo->{'to_id'},
1269 file_name
=>$to->{'file'}),
1271 -title
=>"diff" . ($i+1)},
1274 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1275 esc_path
($from->{'file'}[$i]));
1277 $line = '--- /dev/null';
1279 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1284 #assert($line =~ m/^\+\+\+/) if DEBUG;
1285 # no extra formatting for "^+++ /dev/null"
1286 if ($line =~ m!^\+\+\+ "?b/!) {
1287 if ($to->{'href'}) {
1289 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1290 esc_path
($to->{'file'}));
1293 esc_path
($to->{'file'});
1296 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1301 # create note for patch simplified by combined diff
1302 sub format_diff_cc_simplified
{
1303 my ($diffinfo, @parents) = @_;
1306 $result .= "<div class=\"diff header\">" .
1308 if (!is_deleted
($diffinfo)) {
1309 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1311 hash
=>$diffinfo->{'to_id'},
1312 file_name
=>$diffinfo->{'to_file'}),
1314 esc_path
($diffinfo->{'to_file'}));
1316 $result .= esc_path
($diffinfo->{'to_file'});
1318 $result .= "</div>\n" . # class="diff header"
1319 "<div class=\"diff nodifferences\">" .
1321 "</div>\n"; # class="diff nodifferences"
1326 # format patch (diff) line (not to be used for diff headers)
1327 sub format_diff_line
{
1329 my ($from, $to) = @_;
1330 my $diff_class = "";
1334 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1336 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1337 if ($line =~ m/^\@{3}/) {
1338 $diff_class = " chunk_header";
1339 } elsif ($line =~ m/^\\/) {
1340 $diff_class = " incomplete";
1341 } elsif ($prefix =~ tr/+/+/) {
1342 $diff_class = " add";
1343 } elsif ($prefix =~ tr/-/-/) {
1344 $diff_class = " rem";
1347 # assume ordinary diff
1348 my $char = substr($line, 0, 1);
1350 $diff_class = " add";
1351 } elsif ($char eq '-') {
1352 $diff_class = " rem";
1353 } elsif ($char eq '@') {
1354 $diff_class = " chunk_header";
1355 } elsif ($char eq "\\") {
1356 $diff_class = " incomplete";
1359 $line = untabify
($line);
1360 if ($from && $to && $line =~ m/^\@{2} /) {
1361 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1362 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1364 $from_lines = 0 unless defined $from_lines;
1365 $to_lines = 0 unless defined $to_lines;
1367 if ($from->{'href'}) {
1368 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1369 -class=>"list"}, $from_text);
1371 if ($to->{'href'}) {
1372 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1373 -class=>"list"}, $to_text);
1375 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1376 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1377 return "<div class=\"diff$diff_class\">$line</div>\n";
1378 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1379 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1380 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1382 @from_text = split(' ', $ranges);
1383 for (my $i = 0; $i < @from_text; ++$i) {
1384 ($from_start[$i], $from_nlines[$i]) =
1385 (split(',', substr($from_text[$i], 1)), 0);
1388 $to_text = pop @from_text;
1389 $to_start = pop @from_start;
1390 $to_nlines = pop @from_nlines;
1392 $line = "<span class=\"chunk_info\">$prefix ";
1393 for (my $i = 0; $i < @from_text; ++$i) {
1394 if ($from->{'href'}[$i]) {
1395 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1396 -class=>"list"}, $from_text[$i]);
1398 $line .= $from_text[$i];
1402 if ($to->{'href'}) {
1403 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1404 -class=>"list"}, $to_text);
1408 $line .= " $prefix</span>" .
1409 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1410 return "<div class=\"diff$diff_class\">$line</div>\n";
1412 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1415 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1416 # linked. Pass the hash of the tree/commit to snapshot.
1417 sub format_snapshot_links
{
1419 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1420 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1421 my $num_fmts = @snapshot_fmts;
1422 if ($num_fmts > 1) {
1423 # A parenthesized list of links bearing format names.
1424 # e.g. "snapshot (_tar.gz_ _zip_)"
1425 return "snapshot (" . join(' ', map
1432 }, $known_snapshot_formats{$_}{'display'})
1433 , @snapshot_fmts) . ")";
1434 } elsif ($num_fmts == 1) {
1435 # A single "snapshot" link whose tooltip bears the format name.
1437 my ($fmt) = @snapshot_fmts;
1443 snapshot_format
=>$fmt
1445 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1447 } else { # $num_fmts == 0
1452 ## ----------------------------------------------------------------------
1453 ## git utility subroutines, invoking git commands
1455 # returns path to the core git executable and the --git-dir parameter as list
1457 return $GIT, '--git-dir='.$git_dir;
1460 # returns path to the core git executable and the --git-dir parameter as string
1462 return join(' ', git_cmd
());
1465 # get HEAD ref of given project as hash
1466 sub git_get_head_hash
{
1467 my $project = shift;
1468 my $o_git_dir = $git_dir;
1470 $git_dir = "$projectroot/$project";
1471 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1474 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1478 if (defined $o_git_dir) {
1479 $git_dir = $o_git_dir;
1484 # get type of given object
1488 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1490 close $fd or return;
1495 # repository configuration
1496 our $config_file = '';
1499 # store multiple values for single key as anonymous array reference
1500 # single values stored directly in the hash, not as [ <value> ]
1501 sub hash_set_multi
{
1502 my ($hash, $key, $value) = @_;
1504 if (!exists $hash->{$key}) {
1505 $hash->{$key} = $value;
1506 } elsif (!ref $hash->{$key}) {
1507 $hash->{$key} = [ $hash->{$key}, $value ];
1509 push @{$hash->{$key}}, $value;
1513 # return hash of git project configuration
1514 # optionally limited to some section, e.g. 'gitweb'
1515 sub git_parse_project_config
{
1516 my $section_regexp = shift;
1521 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1524 while (my $keyval = <$fh>) {
1526 my ($key, $value) = split(/\n/, $keyval, 2);
1528 hash_set_multi
(\
%config, $key, $value)
1529 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1536 # convert config value to boolean, 'true' or 'false'
1537 # no value, number > 0, 'true' and 'yes' values are true
1538 # rest of values are treated as false (never as error)
1539 sub config_to_bool
{
1542 # strip leading and trailing whitespace
1546 return (!defined $val || # section.key
1547 ($val =~ /^\d+$/ && $val) || # section.key = 1
1548 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1551 # convert config value to simple decimal number
1552 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1553 # to be multiplied by 1024, 1048576, or 1073741824
1557 # strip leading and trailing whitespace
1561 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1563 # unknown unit is treated as 1
1564 return $num * ($unit eq 'g' ? 1073741824 :
1565 $unit eq 'm' ? 1048576 :
1566 $unit eq 'k' ? 1024 : 1);
1571 # convert config value to array reference, if needed
1572 sub config_to_multi
{
1575 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1578 sub git_get_project_config
{
1579 my ($key, $type) = @_;
1582 return unless ($key);
1583 $key =~ s/^gitweb\.//;
1584 return if ($key =~ m/\W/);
1587 if (defined $type) {
1590 unless ($type eq 'bool' || $type eq 'int');
1594 if (!defined $config_file ||
1595 $config_file ne "$git_dir/config") {
1596 %config = git_parse_project_config
('gitweb');
1597 $config_file = "$git_dir/config";
1601 if (!defined $type) {
1602 return $config{"gitweb.$key"};
1603 } elsif ($type eq 'bool') {
1604 # backward compatibility: 'git config --bool' returns true/false
1605 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1606 } elsif ($type eq 'int') {
1607 return config_to_int
($config{"gitweb.$key"});
1609 return $config{"gitweb.$key"};
1612 # get hash of given path at given ref
1613 sub git_get_hash_by_path
{
1615 my $path = shift || return undef;
1620 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1621 or die_error
(undef, "Open git-ls-tree failed");
1623 close $fd or return undef;
1625 if (!defined $line) {
1626 # there is no tree or hash given by $path at $base
1630 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1631 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1632 if (defined $type && $type ne $2) {
1633 # type doesn't match
1639 # get path of entry with given hash at given tree-ish (ref)
1640 # used to get 'from' filename for combined diff (merge commit) for renames
1641 sub git_get_path_by_hash
{
1642 my $base = shift || return;
1643 my $hash = shift || return;
1647 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1649 while (my $line = <$fd>) {
1652 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1653 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1654 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1663 ## ......................................................................
1664 ## git utility functions, directly accessing git repository
1666 sub git_get_project_description
{
1669 $git_dir = "$projectroot/$path";
1670 open my $fd, "$git_dir/description"
1671 or return git_get_project_config
('description');
1674 if (defined $descr) {
1680 sub git_get_project_url_list
{
1683 $git_dir = "$projectroot/$path";
1684 open my $fd, "$git_dir/cloneurl"
1685 or return wantarray ?
1686 @{ config_to_multi
(git_get_project_config
('url')) } :
1687 config_to_multi
(git_get_project_config
('url'));
1688 my @git_project_url_list = map { chomp; $_ } <$fd>;
1691 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1694 sub git_get_projects_list
{
1699 $filter =~ s/\.git$//;
1701 my ($check_forks) = gitweb_check_feature
('forks');
1703 if (-d
$projects_list) {
1704 # search in directory
1705 my $dir = $projects_list . ($filter ? "/$filter" : '');
1706 # remove the trailing "/"
1708 my $pfxlen = length("$dir");
1709 my $pfxdepth = ($dir =~ tr!/!!);
1712 follow_fast
=> 1, # follow symbolic links
1713 follow_skip
=> 2, # ignore duplicates
1714 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1716 # skip project-list toplevel, if we get it.
1717 return if (m!^[/.]$!);
1718 # only directories can be git repositories
1719 return unless (-d
$_);
1720 # don't traverse too deep (Find is super slow on os x)
1721 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1722 $File::Find
::prune
= 1;
1726 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1727 # we check related file in $projectroot
1728 if ($check_forks and $subdir =~ m
#/.#) {
1729 $File::Find
::prune
= 1;
1730 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1731 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1732 $File::Find
::prune
= 1;
1737 } elsif (-f
$projects_list) {
1738 # read from file(url-encoded):
1739 # 'git%2Fgit.git Linus+Torvalds'
1740 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1741 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1743 open my ($fd), $projects_list or return;
1745 while (my $line = <$fd>) {
1747 my ($path, $owner) = split ' ', $line;
1748 $path = unescape
($path);
1749 $owner = unescape
($owner);
1750 if (!defined $path) {
1753 if ($filter ne '') {
1754 # looking for forks;
1755 my $pfx = substr($path, 0, length($filter));
1756 if ($pfx ne $filter) {
1759 my $sfx = substr($path, length($filter));
1760 if ($sfx !~ /^\/.*\
.git
$/) {
1763 } elsif ($check_forks) {
1765 foreach my $filter (keys %paths) {
1766 # looking for forks;
1767 my $pfx = substr($path, 0, length($filter));
1768 if ($pfx ne $filter) {
1771 my $sfx = substr($path, length($filter));
1772 if ($sfx !~ /^\/.*\
.git
$/) {
1775 # is a fork, don't include it in
1780 if (check_export_ok
("$projectroot/$path")) {
1783 owner
=> to_utf8
($owner),
1786 (my $forks_path = $path) =~ s/\.git$//;
1787 $paths{$forks_path}++;
1795 our $gitweb_project_owner = undef;
1796 sub git_get_project_list_from_file
{
1798 return if (defined $gitweb_project_owner);
1800 $gitweb_project_owner = {};
1801 # read from file (url-encoded):
1802 # 'git%2Fgit.git Linus+Torvalds'
1803 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1804 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1805 if (-f
$projects_list) {
1806 open (my $fd , $projects_list);
1807 while (my $line = <$fd>) {
1809 my ($pr, $ow) = split ' ', $line;
1810 $pr = unescape
($pr);
1811 $ow = unescape
($ow);
1812 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1818 sub git_get_project_owner
{
1819 my $project = shift;
1822 return undef unless $project;
1823 $git_dir = "$projectroot/$project";
1825 if (!defined $gitweb_project_owner) {
1826 git_get_project_list_from_file
();
1829 if (exists $gitweb_project_owner->{$project}) {
1830 $owner = $gitweb_project_owner->{$project};
1832 if (!defined $owner){
1833 $owner = git_get_project_config
('owner');
1835 if (!defined $owner) {
1836 $owner = get_file_owner
("$git_dir");
1842 sub git_get_last_activity
{
1846 $git_dir = "$projectroot/$path";
1847 open($fd, "-|", git_cmd
(), 'for-each-ref',
1848 '--format=%(committer)',
1849 '--sort=-committerdate',
1851 'refs/heads') or return;
1852 my $most_recent = <$fd>;
1853 close $fd or return;
1854 if (defined $most_recent &&
1855 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1857 my $age = time - $timestamp;
1858 return ($age, age_string
($age));
1860 return (undef, undef);
1863 sub git_get_references
{
1864 my $type = shift || "";
1866 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1867 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1868 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1869 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1872 while (my $line = <$fd>) {
1874 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1875 if (defined $refs{$1}) {
1876 push @{$refs{$1}}, $2;
1882 close $fd or return;
1886 sub git_get_rev_name_tags
{
1887 my $hash = shift || return undef;
1889 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1891 my $name_rev = <$fd>;
1894 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1897 # catches also '$hash undefined' output
1902 ## ----------------------------------------------------------------------
1903 ## parse to hash functions
1907 my $tz = shift || "-0000";
1910 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1911 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1912 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1913 $date{'hour'} = $hour;
1914 $date{'minute'} = $min;
1915 $date{'mday'} = $mday;
1916 $date{'day'} = $days[$wday];
1917 $date{'month'} = $months[$mon];
1918 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1919 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1920 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1921 $mday, $months[$mon], $hour ,$min;
1922 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1923 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1925 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1926 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1927 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1928 $date{'hour_local'} = $hour;
1929 $date{'minute_local'} = $min;
1930 $date{'tz_local'} = $tz;
1931 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1932 1900+$year, $mon+1, $mday,
1933 $hour, $min, $sec, $tz);
1942 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1943 $tag{'id'} = $tag_id;
1944 while (my $line = <$fd>) {
1946 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1947 $tag{'object'} = $1;
1948 } elsif ($line =~ m/^type (.+)$/) {
1950 } elsif ($line =~ m/^tag (.+)$/) {
1952 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1953 $tag{'author'} = $1;
1956 } elsif ($line =~ m/--BEGIN/) {
1957 push @comment, $line;
1959 } elsif ($line eq "") {
1963 push @comment, <$fd>;
1964 $tag{'comment'} = \
@comment;
1965 close $fd or return;
1966 if (!defined $tag{'name'}) {
1972 sub parse_commit_text
{
1973 my ($commit_text, $withparents) = @_;
1974 my @commit_lines = split '\n', $commit_text;
1977 pop @commit_lines; # Remove '\0'
1979 if (! @commit_lines) {
1983 my $header = shift @commit_lines;
1984 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1987 ($co{'id'}, my @parents) = split ' ', $header;
1988 while (my $line = shift @commit_lines) {
1989 last if $line eq "\n";
1990 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1992 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1994 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1996 $co{'author_epoch'} = $2;
1997 $co{'author_tz'} = $3;
1998 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1999 $co{'author_name'} = $1;
2000 $co{'author_email'} = $2;
2002 $co{'author_name'} = $co{'author'};
2004 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2005 $co{'committer'} = $1;
2006 $co{'committer_epoch'} = $2;
2007 $co{'committer_tz'} = $3;
2008 $co{'committer_name'} = $co{'committer'};
2009 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2010 $co{'committer_name'} = $1;
2011 $co{'committer_email'} = $2;
2013 $co{'committer_name'} = $co{'committer'};
2017 if (!defined $co{'tree'}) {
2020 $co{'parents'} = \
@parents;
2021 $co{'parent'} = $parents[0];
2023 foreach my $title (@commit_lines) {
2026 $co{'title'} = chop_str
($title, 80, 5);
2027 # remove leading stuff of merges to make the interesting part visible
2028 if (length($title) > 50) {
2029 $title =~ s/^Automatic //;
2030 $title =~ s/^merge (of|with) /Merge ... /i;
2031 if (length($title) > 50) {
2032 $title =~ s/(http|rsync):\/\///;
2034 if (length($title) > 50) {
2035 $title =~ s/(master|www|rsync)\.//;
2037 if (length($title) > 50) {
2038 $title =~ s/kernel.org:?//;
2040 if (length($title) > 50) {
2041 $title =~ s/\/pub\/scm//;
2044 $co{'title_short'} = chop_str
($title, 50, 5);
2048 if ($co{'title'} eq "") {
2049 $co{'title'} = $co{'title_short'} = '(no commit message)';
2051 # remove added spaces
2052 foreach my $line (@commit_lines) {
2055 $co{'comment'} = \
@commit_lines;
2057 my $age = time - $co{'committer_epoch'};
2059 $co{'age_string'} = age_string
($age);
2060 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2061 if ($age > 60*60*24*7*2) {
2062 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2063 $co{'age_string_age'} = $co{'age_string'};
2065 $co{'age_string_date'} = $co{'age_string'};
2066 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2072 my ($commit_id) = @_;
2077 open my $fd, "-|", git_cmd
(), "rev-list",
2083 or die_error
(undef, "Open git-rev-list failed");
2084 %co = parse_commit_text
(<$fd>, 1);
2091 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2099 open my $fd, "-|", git_cmd
(), "rev-list",
2102 ("--max-count=" . $maxcount),
2103 ("--skip=" . $skip),
2107 ($filename ? ($filename) : ())
2108 or die_error
(undef, "Open git-rev-list failed");
2109 while (my $line = <$fd>) {
2110 my %co = parse_commit_text
($line);
2115 return wantarray ? @cos : \
@cos;
2118 # parse ref from ref_file, given by ref_id, with given type
2120 my $ref_file = shift;
2122 my $type = shift || git_get_type
($ref_id);
2125 $ref_item{'type'} = $type;
2126 $ref_item{'id'} = $ref_id;
2127 $ref_item{'epoch'} = 0;
2128 $ref_item{'age'} = "unknown";
2129 if ($type eq "tag") {
2130 my %tag = parse_tag
($ref_id);
2131 $ref_item{'comment'} = $tag{'comment'};
2132 if ($tag{'type'} eq "commit") {
2133 my %co = parse_commit
($tag{'object'});
2134 $ref_item{'epoch'} = $co{'committer_epoch'};
2135 $ref_item{'age'} = $co{'age_string'};
2136 } elsif (defined($tag{'epoch'})) {
2137 my $age = time - $tag{'epoch'};
2138 $ref_item{'epoch'} = $tag{'epoch'};
2139 $ref_item{'age'} = age_string
($age);
2141 $ref_item{'reftype'} = $tag{'type'};
2142 $ref_item{'name'} = $tag{'name'};
2143 $ref_item{'refid'} = $tag{'object'};
2144 } elsif ($type eq "commit"){
2145 my %co = parse_commit
($ref_id);
2146 $ref_item{'reftype'} = "commit";
2147 $ref_item{'name'} = $ref_file;
2148 $ref_item{'title'} = $co{'title'};
2149 $ref_item{'refid'} = $ref_id;
2150 $ref_item{'epoch'} = $co{'committer_epoch'};
2151 $ref_item{'age'} = $co{'age_string'};
2153 $ref_item{'reftype'} = $type;
2154 $ref_item{'name'} = $ref_file;
2155 $ref_item{'refid'} = $ref_id;
2161 # parse line of git-diff-tree "raw" output
2162 sub parse_difftree_raw_line
{
2166 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2167 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2168 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2169 $res{'from_mode'} = $1;
2170 $res{'to_mode'} = $2;
2171 $res{'from_id'} = $3;
2173 $res{'status'} = $res{'status_str'} = $5;
2174 $res{'similarity'} = $6;
2175 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2176 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2178 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2181 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2182 # combined diff (for merge commit)
2183 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2184 $res{'nparents'} = length($1);
2185 $res{'from_mode'} = [ split(' ', $2) ];
2186 $res{'to_mode'} = pop @{$res{'from_mode'}};
2187 $res{'from_id'} = [ split(' ', $3) ];
2188 $res{'to_id'} = pop @{$res{'from_id'}};
2189 $res{'status_str'} = $4;
2190 $res{'status'} = [ split('', $4) ];
2191 $res{'to_file'} = unquote
($5);
2193 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2194 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2195 $res{'commit'} = $1;
2198 return wantarray ? %res : \
%res;
2201 # wrapper: return parsed line of git-diff-tree "raw" output
2202 # (the argument might be raw line, or parsed info)
2203 sub parsed_difftree_line
{
2204 my $line_or_ref = shift;
2206 if (ref($line_or_ref) eq "HASH") {
2207 # pre-parsed (or generated by hand)
2208 return $line_or_ref;
2210 return parse_difftree_raw_line
($line_or_ref);
2214 # parse line of git-ls-tree output
2215 sub parse_ls_tree_line
($;%) {
2220 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2221 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2229 $res{'name'} = unquote
($4);
2232 return wantarray ? %res : \
%res;
2235 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2236 sub parse_from_to_diffinfo
{
2237 my ($diffinfo, $from, $to, @parents) = @_;
2239 if ($diffinfo->{'nparents'}) {
2241 $from->{'file'} = [];
2242 $from->{'href'} = [];
2243 fill_from_file_info
($diffinfo, @parents)
2244 unless exists $diffinfo->{'from_file'};
2245 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2246 $from->{'file'}[$i] =
2247 defined $diffinfo->{'from_file'}[$i] ?
2248 $diffinfo->{'from_file'}[$i] :
2249 $diffinfo->{'to_file'};
2250 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2251 $from->{'href'}[$i] = href
(action
=>"blob",
2252 hash_base
=>$parents[$i],
2253 hash
=>$diffinfo->{'from_id'}[$i],
2254 file_name
=>$from->{'file'}[$i]);
2256 $from->{'href'}[$i] = undef;
2260 # ordinary (not combined) diff
2261 $from->{'file'} = $diffinfo->{'from_file'};
2262 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2263 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2264 hash
=>$diffinfo->{'from_id'},
2265 file_name
=>$from->{'file'});
2267 delete $from->{'href'};
2271 $to->{'file'} = $diffinfo->{'to_file'};
2272 if (!is_deleted
($diffinfo)) { # file exists in result
2273 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2274 hash
=>$diffinfo->{'to_id'},
2275 file_name
=>$to->{'file'});
2277 delete $to->{'href'};
2281 ## ......................................................................
2282 ## parse to array of hashes functions
2284 sub git_get_heads_list
{
2288 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2289 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2290 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2293 while (my $line = <$fd>) {
2297 my ($refinfo, $committerinfo) = split(/\0/, $line);
2298 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2299 my ($committer, $epoch, $tz) =
2300 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2301 $ref_item{'fullname'} = $name;
2302 $name =~ s!^refs/heads/!!;
2304 $ref_item{'name'} = $name;
2305 $ref_item{'id'} = $hash;
2306 $ref_item{'title'} = $title || '(no commit message)';
2307 $ref_item{'epoch'} = $epoch;
2309 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2311 $ref_item{'age'} = "unknown";
2314 push @headslist, \
%ref_item;
2318 return wantarray ? @headslist : \
@headslist;
2321 sub git_get_tags_list
{
2325 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2326 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2327 '--format=%(objectname) %(objecttype) %(refname) '.
2328 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2331 while (my $line = <$fd>) {
2335 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2336 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2337 my ($creator, $epoch, $tz) =
2338 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2339 $ref_item{'fullname'} = $name;
2340 $name =~ s!^refs/tags/!!;
2342 $ref_item{'type'} = $type;
2343 $ref_item{'id'} = $id;
2344 $ref_item{'name'} = $name;
2345 if ($type eq "tag") {
2346 $ref_item{'subject'} = $title;
2347 $ref_item{'reftype'} = $reftype;
2348 $ref_item{'refid'} = $refid;
2350 $ref_item{'reftype'} = $type;
2351 $ref_item{'refid'} = $id;
2354 if ($type eq "tag" || $type eq "commit") {
2355 $ref_item{'epoch'} = $epoch;
2357 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2359 $ref_item{'age'} = "unknown";
2363 push @tagslist, \
%ref_item;
2367 return wantarray ? @tagslist : \
@tagslist;
2370 ## ----------------------------------------------------------------------
2371 ## filesystem-related functions
2373 sub get_file_owner
{
2376 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2377 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2378 if (!defined $gcos) {
2382 $owner =~ s/[,;].*$//;
2383 return to_utf8
($owner);
2386 ## ......................................................................
2387 ## mimetype related functions
2389 sub mimetype_guess_file
{
2390 my $filename = shift;
2391 my $mimemap = shift;
2392 -r
$mimemap or return undef;
2395 open(MIME
, $mimemap) or return undef;
2397 next if m/^#/; # skip comments
2398 my ($mime, $exts) = split(/\t+/);
2399 if (defined $exts) {
2400 my @exts = split(/\s+/, $exts);
2401 foreach my $ext (@exts) {
2402 $mimemap{$ext} = $mime;
2408 $filename =~ /\.([^.]*)$/;
2409 return $mimemap{$1};
2412 sub mimetype_guess
{
2413 my $filename = shift;
2415 $filename =~ /\./ or return undef;
2417 if ($mimetypes_file) {
2418 my $file = $mimetypes_file;
2419 if ($file !~ m!^/!) { # if it is relative path
2420 # it is relative to project
2421 $file = "$projectroot/$project/$file";
2423 $mime = mimetype_guess_file
($filename, $file);
2425 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2431 my $filename = shift;
2434 my $mime = mimetype_guess
($filename);
2435 $mime and return $mime;
2439 return $default_blob_plain_mimetype unless $fd;
2442 return 'text/plain' .
2443 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2444 } elsif (! $filename) {
2445 return 'application/octet-stream';
2446 } elsif ($filename =~ m/\.png$/i) {
2448 } elsif ($filename =~ m/\.gif$/i) {
2450 } elsif ($filename =~ m/\.jpe?g$/i) {
2451 return 'image/jpeg';
2453 return 'application/octet-stream';
2457 ## ======================================================================
2458 ## functions printing HTML: header, footer, error page
2460 sub git_header_html
{
2461 my $status = shift || "200 OK";
2462 my $expires = shift;
2464 my $title = "$site_name";
2465 if (defined $project) {
2466 $title .= " - " . to_utf8
($project);
2467 if (defined $action) {
2468 $title .= "/$action";
2469 if (defined $file_name) {
2470 $title .= " - " . esc_path
($file_name);
2471 if ($action eq "tree" && $file_name !~ m
|/$|) {
2478 # require explicit support from the UA if we are to send the page as
2479 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2480 # we have to do this because MSIE sometimes globs '*/*', pretending to
2481 # support xhtml+xml but choking when it gets what it asked for.
2482 if (defined $cgi->http('HTTP_ACCEPT') &&
2483 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2484 $cgi->Accept('application/xhtml+xml') != 0) {
2485 $content_type = 'application/xhtml+xml';
2487 $content_type = 'text/html';
2489 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2490 -status
=> $status, -expires
=> $expires);
2491 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2493 <?xml version="1.0" encoding="utf-8"?>
2494 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2495 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2496 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2497 <!-- git core binaries version $git_version -->
2499 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2500 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2501 <meta name="robots" content="index, nofollow"/>
2502 <title>$title</title>
2504 # print out each stylesheet that exist
2505 if (defined $stylesheet) {
2506 #provides backwards capability for those people who define style sheet in a config file
2507 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2509 foreach my $stylesheet (@stylesheets) {
2510 next unless $stylesheet;
2511 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2514 if (defined $project) {
2515 printf('<link rel="alternate" title="%s log RSS feed" '.
2516 'href="%s" type="application/rss+xml" />'."\n",
2517 esc_param
($project), href
(action
=>"rss"));
2518 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2519 'href="%s" type="application/rss+xml" />'."\n",
2520 esc_param
($project), href
(action
=>"rss",
2521 extra_options
=>"--no-merges"));
2522 printf('<link rel="alternate" title="%s log Atom feed" '.
2523 'href="%s" type="application/atom+xml" />'."\n",
2524 esc_param
($project), href
(action
=>"atom"));
2525 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2526 'href="%s" type="application/atom+xml" />'."\n",
2527 esc_param
($project), href
(action
=>"atom",
2528 extra_options
=>"--no-merges"));
2530 printf('<link rel="alternate" title="%s projects list" '.
2531 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2532 $site_name, href
(project
=>undef, action
=>"project_index"));
2533 printf('<link rel="alternate" title="%s projects feeds" '.
2534 'href="%s" type="text/x-opml"/>'."\n",
2535 $site_name, href
(project
=>undef, action
=>"opml"));
2537 if (defined $favicon) {
2538 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2544 if (-f
$site_header) {
2545 open (my $fd, $site_header);
2550 print "<div class=\"page_header\">\n" .
2551 $cgi->a({-href
=> esc_url
($logo_url),
2552 -title
=> $logo_label},
2553 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2554 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2555 if (defined $project) {
2556 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2557 if (defined $action) {
2564 my ($have_search) = gitweb_check_feature
('search');
2565 if ((defined $project) && ($have_search)) {
2566 if (!defined $searchtext) {
2570 if (defined $hash_base) {
2571 $search_hash = $hash_base;
2572 } elsif (defined $hash) {
2573 $search_hash = $hash;
2575 $search_hash = "HEAD";
2577 my $action = $my_uri;
2578 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2579 if ($use_pathinfo) {
2580 $action .= "/$project";
2582 $cgi->param("p", $project);
2584 $cgi->param("a", "search");
2585 $cgi->param("h", $search_hash);
2586 print $cgi->startform(-method => "get", -action
=> $action) .
2587 "<div class=\"search\">\n" .
2588 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2589 $cgi->hidden(-name
=> "a") . "\n" .
2590 $cgi->hidden(-name
=> "h") . "\n" .
2591 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2592 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2593 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2595 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2596 "<span title=\"Extended regular expression\">" .
2597 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2598 -checked
=> $search_use_regexp) .
2601 $cgi->end_form() . "\n";
2605 sub git_footer_html
{
2606 print "<div class=\"page_footer\">\n";
2607 if (defined $project) {
2608 my $descr = git_get_project_description
($project);
2609 if (defined $descr) {
2610 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2612 print $cgi->a({-href
=> href
(action
=>"rss"),
2613 -class => "rss_logo"}, "RSS") . " ";
2614 print $cgi->a({-href
=> href
(action
=>"atom"),
2615 -class => "rss_logo"}, "Atom") . "\n";
2617 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2618 -class => "rss_logo"}, "OPML") . " ";
2619 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2620 -class => "rss_logo"}, "TXT") . "\n";
2624 if (-f
$site_footer) {
2625 open (my $fd, $site_footer);
2635 my $status = shift || "403 Forbidden";
2636 my $error = shift || "Malformed query, file missing or permission denied";
2638 git_header_html
($status);
2640 <div class="page_body">
2650 ## ----------------------------------------------------------------------
2651 ## functions printing or outputting HTML: navigation
2653 sub git_print_page_nav
{
2654 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2655 $extra = '' if !defined $extra; # pager or formats
2657 my @navs = qw(summary shortlog log commit commitdiff tree);
2659 @navs = grep { $_ ne $suppress } @navs;
2662 my %arg = map { $_ => {action
=>$_} } @navs;
2663 if (defined $head) {
2664 for (qw(commit commitdiff)) {
2665 $arg{$_}{'hash'} = $head;
2667 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2668 for (qw(shortlog log)) {
2669 $arg{$_}{'hash'} = $head;
2673 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2674 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2676 print "<div class=\"page_nav\">\n" .
2678 map { $_ eq $current ?
2679 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2681 print "<br/>\n$extra<br/>\n" .
2685 sub format_paging_nav
{
2686 my ($action, $hash, $head, $page, $nrevs) = @_;
2690 if ($hash ne $head || $page) {
2691 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2693 $paging_nav .= "HEAD";
2697 $paging_nav .= " ⋅ " .
2698 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2699 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2701 $paging_nav .= " ⋅ prev";
2704 if ($nrevs >= (100 * ($page+1)-1)) {
2705 $paging_nav .= " ⋅ " .
2706 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2707 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2709 $paging_nav .= " ⋅ next";
2715 ## ......................................................................
2716 ## functions printing or outputting HTML: div
2718 sub git_print_header_div
{
2719 my ($action, $title, $hash, $hash_base) = @_;
2722 $args{'action'} = $action;
2723 $args{'hash'} = $hash if $hash;
2724 $args{'hash_base'} = $hash_base if $hash_base;
2726 print "<div class=\"header\">\n" .
2727 $cgi->a({-href
=> href
(%args), -class => "title"},
2728 $title ? $title : $action) .
2732 #sub git_print_authorship (\%) {
2733 sub git_print_authorship
{
2736 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2737 print "<div class=\"author_date\">" .
2738 esc_html
($co->{'author_name'}) .
2740 if ($ad{'hour_local'} < 6) {
2741 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2742 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2744 printf(" (%02d:%02d %s)",
2745 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2750 sub git_print_page_path
{
2756 print "<div class=\"page_path\">";
2757 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2758 -title
=> 'tree root'}, to_utf8
("[$project]"));
2760 if (defined $name) {
2761 my @dirname = split '/', $name;
2762 my $basename = pop @dirname;
2765 foreach my $dir (@dirname) {
2766 $fullname .= ($fullname ? '/' : '') . $dir;
2767 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2769 -title
=> $fullname}, esc_path
($dir));
2772 if (defined $type && $type eq 'blob') {
2773 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2775 -title
=> $name}, esc_path
($basename));
2776 } elsif (defined $type && $type eq 'tree') {
2777 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2779 -title
=> $name}, esc_path
($basename));
2782 print esc_path
($basename);
2785 print "<br/></div>\n";
2788 # sub git_print_log (\@;%) {
2789 sub git_print_log
($;%) {
2793 if ($opts{'-remove_title'}) {
2794 # remove title, i.e. first line of log
2797 # remove leading empty lines
2798 while (defined $log->[0] && $log->[0] eq "") {
2805 foreach my $line (@$log) {
2806 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2809 if (! $opts{'-remove_signoff'}) {
2810 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2813 # remove signoff lines
2820 # print only one empty line
2821 # do not print empty line after signoff
2823 next if ($empty || $signoff);
2829 print format_log_line_html
($line) . "<br/>\n";
2832 if ($opts{'-final_empty_line'}) {
2833 # end with single empty line
2834 print "<br/>\n" unless $empty;
2838 # return link target (what link points to)
2839 sub git_get_link_target
{
2844 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2848 $link_target = <$fd>;
2853 return $link_target;
2856 # given link target, and the directory (basedir) the link is in,
2857 # return target of link relative to top directory (top tree);
2858 # return undef if it is not possible (including absolute links).
2859 sub normalize_link_target
{
2860 my ($link_target, $basedir, $hash_base) = @_;
2862 # we can normalize symlink target only if $hash_base is provided
2863 return unless $hash_base;
2865 # absolute symlinks (beginning with '/') cannot be normalized
2866 return if (substr($link_target, 0, 1) eq '/');
2868 # normalize link target to path from top (root) tree (dir)
2871 $path = $basedir . '/' . $link_target;
2873 # we are in top (root) tree (dir)
2874 $path = $link_target;
2877 # remove //, /./, and /../
2879 foreach my $part (split('/', $path)) {
2880 # discard '.' and ''
2881 next if (!$part || $part eq '.');
2883 if ($part eq '..') {
2887 # link leads outside repository (outside top dir)
2891 push @path_parts, $part;
2894 $path = join('/', @path_parts);
2899 # print tree entry (row of git_tree), but without encompassing <tr> element
2900 sub git_print_tree_entry
{
2901 my ($t, $basedir, $hash_base, $have_blame) = @_;
2904 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2906 # The format of a table row is: mode list link. Where mode is
2907 # the mode of the entry, list is the name of the entry, an href,
2908 # and link is the action links of the entry.
2910 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2911 if ($t->{'type'} eq "blob") {
2912 print "<td class=\"list\">" .
2913 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2914 file_name
=>"$basedir$t->{'name'}", %base_key),
2915 -class => "list"}, esc_path
($t->{'name'}));
2916 if (S_ISLNK
(oct $t->{'mode'})) {
2917 my $link_target = git_get_link_target
($t->{'hash'});
2919 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2920 if (defined $norm_target) {
2922 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2923 file_name
=>$norm_target),
2924 -title
=> $norm_target}, esc_path
($link_target));
2926 print " -> " . esc_path
($link_target);
2931 print "<td class=\"link\">";
2932 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2933 file_name
=>"$basedir$t->{'name'}", %base_key)},
2937 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2938 file_name
=>"$basedir$t->{'name'}", %base_key)},
2941 if (defined $hash_base) {
2943 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2944 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2948 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2949 file_name
=>"$basedir$t->{'name'}")},
2953 } elsif ($t->{'type'} eq "tree") {
2954 print "<td class=\"list\">";
2955 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2956 file_name
=>"$basedir$t->{'name'}", %base_key)},
2957 esc_path
($t->{'name'}));
2959 print "<td class=\"link\">";
2960 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2961 file_name
=>"$basedir$t->{'name'}", %base_key)},
2963 if (defined $hash_base) {
2965 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2966 file_name
=>"$basedir$t->{'name'}")},
2971 # unknown object: we can only present history for it
2972 # (this includes 'commit' object, i.e. submodule support)
2973 print "<td class=\"list\">" .
2974 esc_path
($t->{'name'}) .
2976 print "<td class=\"link\">";
2977 if (defined $hash_base) {
2978 print $cgi->a({-href
=> href
(action
=>"history",
2979 hash_base
=>$hash_base,
2980 file_name
=>"$basedir$t->{'name'}")},
2987 ## ......................................................................
2988 ## functions printing large fragments of HTML
2990 # get pre-image filenames for merge (combined) diff
2991 sub fill_from_file_info
{
2992 my ($diff, @parents) = @_;
2994 $diff->{'from_file'} = [ ];
2995 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2996 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2997 if ($diff->{'status'}[$i] eq 'R' ||
2998 $diff->{'status'}[$i] eq 'C') {
2999 $diff->{'from_file'}[$i] =
3000 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3007 # is current raw difftree line of file deletion
3009 my $diffinfo = shift;
3011 return $diffinfo->{'status_str'} =~ /D/;
3014 # does patch correspond to [previous] difftree raw line
3015 # $diffinfo - hashref of parsed raw diff format
3016 # $patchinfo - hashref of parsed patch diff format
3017 # (the same keys as in $diffinfo)
3018 sub is_patch_split
{
3019 my ($diffinfo, $patchinfo) = @_;
3021 return defined $diffinfo && defined $patchinfo
3022 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3026 sub git_difftree_body
{
3027 my ($difftree, $hash, @parents) = @_;
3028 my ($parent) = $parents[0];
3029 my ($have_blame) = gitweb_check_feature
('blame');
3030 print "<div class=\"list_head\">\n";
3031 if ($#{$difftree} > 10) {
3032 print(($#{$difftree} + 1) . " files changed:\n");
3036 print "<table class=\"" .
3037 (@parents > 1 ? "combined " : "") .
3040 # header only for combined diff in 'commitdiff' view
3041 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3044 print "<thead><tr>\n" .
3045 "<th></th><th></th>\n"; # filename, patchN link
3046 for (my $i = 0; $i < @parents; $i++) {
3047 my $par = $parents[$i];
3049 $cgi->a({-href
=> href
(action
=>"commitdiff",
3050 hash
=>$hash, hash_parent
=>$par),
3051 -title
=> 'commitdiff to parent number ' .
3052 ($i+1) . ': ' . substr($par,0,7)},
3056 print "</tr></thead>\n<tbody>\n";
3061 foreach my $line (@{$difftree}) {
3062 my $diff = parsed_difftree_line
($line);
3065 print "<tr class=\"dark\">\n";
3067 print "<tr class=\"light\">\n";
3071 if (exists $diff->{'nparents'}) { # combined diff
3073 fill_from_file_info
($diff, @parents)
3074 unless exists $diff->{'from_file'};
3076 if (!is_deleted
($diff)) {
3077 # file exists in the result (child) commit
3079 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3080 file_name
=>$diff->{'to_file'},
3082 -class => "list"}, esc_path
($diff->{'to_file'})) .
3086 esc_path
($diff->{'to_file'}) .
3090 if ($action eq 'commitdiff') {
3093 print "<td class=\"link\">" .
3094 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3099 my $has_history = 0;
3100 my $not_deleted = 0;
3101 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3102 my $hash_parent = $parents[$i];
3103 my $from_hash = $diff->{'from_id'}[$i];
3104 my $from_path = $diff->{'from_file'}[$i];
3105 my $status = $diff->{'status'}[$i];
3107 $has_history ||= ($status ne 'A');
3108 $not_deleted ||= ($status ne 'D');
3110 if ($status eq 'A') {
3111 print "<td class=\"link\" align=\"right\"> | </td>\n";
3112 } elsif ($status eq 'D') {
3113 print "<td class=\"link\">" .
3114 $cgi->a({-href
=> href
(action
=>"blob",
3117 file_name
=>$from_path)},
3121 if ($diff->{'to_id'} eq $from_hash) {
3122 print "<td class=\"link nochange\">";
3124 print "<td class=\"link\">";
3126 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3127 hash
=>$diff->{'to_id'},
3128 hash_parent
=>$from_hash,
3130 hash_parent_base
=>$hash_parent,
3131 file_name
=>$diff->{'to_file'},
3132 file_parent
=>$from_path)},
3138 print "<td class=\"link\">";
3140 print $cgi->a({-href
=> href
(action
=>"blob",
3141 hash
=>$diff->{'to_id'},
3142 file_name
=>$diff->{'to_file'},
3145 print " | " if ($has_history);
3148 print $cgi->a({-href
=> href
(action
=>"history",
3149 file_name
=>$diff->{'to_file'},
3156 next; # instead of 'else' clause, to avoid extra indent
3158 # else ordinary diff
3160 my ($to_mode_oct, $to_mode_str, $to_file_type);
3161 my ($from_mode_oct, $from_mode_str, $from_file_type);
3162 if ($diff->{'to_mode'} ne ('0' x
6)) {
3163 $to_mode_oct = oct $diff->{'to_mode'};
3164 if (S_ISREG
($to_mode_oct)) { # only for regular file
3165 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3167 $to_file_type = file_type
($diff->{'to_mode'});
3169 if ($diff->{'from_mode'} ne ('0' x
6)) {
3170 $from_mode_oct = oct $diff->{'from_mode'};
3171 if (S_ISREG
($to_mode_oct)) { # only for regular file
3172 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3174 $from_file_type = file_type
($diff->{'from_mode'});
3177 if ($diff->{'status'} eq "A") { # created
3178 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3179 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3180 $mode_chng .= "]</span>";
3182 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3183 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3184 -class => "list"}, esc_path
($diff->{'file'}));
3186 print "<td>$mode_chng</td>\n";
3187 print "<td class=\"link\">";
3188 if ($action eq 'commitdiff') {
3191 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3194 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3195 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3199 } elsif ($diff->{'status'} eq "D") { # deleted
3200 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3202 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3203 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3204 -class => "list"}, esc_path
($diff->{'file'}));
3206 print "<td>$mode_chng</td>\n";
3207 print "<td class=\"link\">";
3208 if ($action eq 'commitdiff') {
3211 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3214 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3215 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3218 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3219 file_name
=>$diff->{'file'})},
3222 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3223 file_name
=>$diff->{'file'})},
3227 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3228 my $mode_chnge = "";
3229 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3230 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3231 if ($from_file_type ne $to_file_type) {
3232 $mode_chnge .= " from $from_file_type to $to_file_type";
3234 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3235 if ($from_mode_str && $to_mode_str) {
3236 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3237 } elsif ($to_mode_str) {
3238 $mode_chnge .= " mode: $to_mode_str";
3241 $mode_chnge .= "]</span>\n";
3244 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3245 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3246 -class => "list"}, esc_path
($diff->{'file'}));
3248 print "<td>$mode_chnge</td>\n";
3249 print "<td class=\"link\">";
3250 if ($action eq 'commitdiff') {
3253 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3255 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3256 # "commit" view and modified file (not onlu mode changed)
3257 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3258 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3259 hash_base
=>$hash, hash_parent_base
=>$parent,
3260 file_name
=>$diff->{'file'})},
3264 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3265 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3268 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3269 file_name
=>$diff->{'file'})},
3272 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3273 file_name
=>$diff->{'file'})},
3277 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3278 my %status_name = ('R' => 'moved', 'C' => 'copied');
3279 my $nstatus = $status_name{$diff->{'status'}};
3281 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3282 # mode also for directories, so we cannot use $to_mode_str
3283 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3286 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3287 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3288 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3289 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3290 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3291 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3292 -class => "list"}, esc_path
($diff->{'from_file'})) .
3293 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3294 "<td class=\"link\">";
3295 if ($action eq 'commitdiff') {
3298 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3300 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3301 # "commit" view and modified file (not only pure rename or copy)
3302 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3303 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3304 hash_base
=>$hash, hash_parent_base
=>$parent,
3305 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3309 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3310 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3313 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3314 file_name
=>$diff->{'to_file'})},
3317 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3318 file_name
=>$diff->{'to_file'})},
3322 } # we should not encounter Unmerged (U) or Unknown (X) status
3325 print "</tbody>" if $has_header;
3329 sub git_patchset_body
{
3330 my ($fd, $difftree, $hash, @hash_parents) = @_;
3331 my ($hash_parent) = $hash_parents[0];
3333 my $is_combined = (@hash_parents > 1);
3335 my $patch_number = 0;
3341 print "<div class=\"patchset\">\n";
3343 # skip to first patch
3344 while ($patch_line = <$fd>) {
3347 last if ($patch_line =~ m/^diff /);
3351 while ($patch_line) {
3353 # parse "git diff" header line
3354 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3355 # $1 is from_name, which we do not use
3356 $to_name = unquote
($2);
3357 $to_name =~ s!^b/!!;
3358 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3359 # $1 is 'cc' or 'combined', which we do not use
3360 $to_name = unquote
($2);
3365 # check if current patch belong to current raw line
3366 # and parse raw git-diff line if needed
3367 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3368 # this is continuation of a split patch
3369 print "<div class=\"patch cont\">\n";
3371 # advance raw git-diff output if needed
3372 $patch_idx++ if defined $diffinfo;
3374 # read and prepare patch information
3375 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3377 # compact combined diff output can have some patches skipped
3378 # find which patch (using pathname of result) we are at now;
3380 while ($to_name ne $diffinfo->{'to_file'}) {
3381 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3382 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3383 "</div>\n"; # class="patch"
3388 last if $patch_idx > $#$difftree;
3389 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3393 # modifies %from, %to hashes
3394 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3396 # this is first patch for raw difftree line with $patch_idx index
3397 # we index @$difftree array from 0, but number patches from 1
3398 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3402 #assert($patch_line =~ m/^diff /) if DEBUG;
3403 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3405 # print "git diff" header
3406 print format_git_diff_header_line
($patch_line, $diffinfo,
3409 # print extended diff header
3410 print "<div class=\"diff extended_header\">\n";
3412 while ($patch_line = <$fd>) {
3415 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3417 print format_extended_diff_header_line
($patch_line, $diffinfo,
3420 print "</div>\n"; # class="diff extended_header"
3422 # from-file/to-file diff header
3423 if (! $patch_line) {
3424 print "</div>\n"; # class="patch"
3427 next PATCH
if ($patch_line =~ m/^diff /);
3428 #assert($patch_line =~ m/^---/) if DEBUG;
3430 my $last_patch_line = $patch_line;
3431 $patch_line = <$fd>;
3433 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3435 print format_diff_from_to_header
($last_patch_line, $patch_line,
3436 $diffinfo, \
%from, \
%to,
3441 while ($patch_line = <$fd>) {
3444 next PATCH
if ($patch_line =~ m/^diff /);
3446 print format_diff_line
($patch_line, \
%from, \
%to);
3450 print "</div>\n"; # class="patch"
3453 # for compact combined (--cc) format, with chunk and patch simpliciaction
3454 # patchset might be empty, but there might be unprocessed raw lines
3455 for (++$patch_idx if $patch_number > 0;
3456 $patch_idx < @$difftree;
3458 # read and prepare patch information
3459 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3461 # generate anchor for "patch" links in difftree / whatchanged part
3462 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3463 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3464 "</div>\n"; # class="patch"
3469 if ($patch_number == 0) {
3470 if (@hash_parents > 1) {
3471 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3473 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3477 print "</div>\n"; # class="patchset"
3480 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3482 sub git_project_list_body
{
3483 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3485 my ($check_forks) = gitweb_check_feature
('forks');
3488 foreach my $pr (@$projlist) {
3489 my (@aa) = git_get_last_activity
($pr->{'path'});
3493 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3494 if (!defined $pr->{'descr'}) {
3495 my $descr = git_get_project_description
($pr->{'path'}) || "";
3496 $pr->{'descr_long'} = to_utf8
($descr);
3497 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3499 if (!defined $pr->{'owner'}) {
3500 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3503 my $pname = $pr->{'path'};
3504 if (($pname =~ s/\.git$//) &&
3505 ($pname !~ /\/$/) &&
3506 (-d
"$projectroot/$pname")) {
3507 $pr->{'forks'} = "-d $projectroot/$pname";
3513 push @projects, $pr;
3516 $order ||= $default_projects_order;
3517 $from = 0 unless defined $from;
3518 $to = $#projects if (!defined $to || $#projects < $to);
3520 print "<table class=\"project_list\">\n";
3521 unless ($no_header) {
3524 print "<th></th>\n";
3526 if ($order eq "project") {
3527 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3528 print "<th>Project</th>\n";
3531 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3532 -class => "header"}, "Project") .
3535 if ($order eq "descr") {
3536 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3537 print "<th>Description</th>\n";
3540 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3541 -class => "header"}, "Description") .
3544 if ($order eq "owner") {
3545 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3546 print "<th>Owner</th>\n";
3549 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3550 -class => "header"}, "Owner") .
3553 if ($order eq "age") {
3554 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3555 print "<th>Last Change</th>\n";
3558 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3559 -class => "header"}, "Last Change") .
3562 print "<th></th>\n" .
3566 for (my $i = $from; $i <= $to; $i++) {
3567 my $pr = $projects[$i];
3569 print "<tr class=\"dark\">\n";
3571 print "<tr class=\"light\">\n";
3576 if ($pr->{'forks'}) {
3577 print "<!-- $pr->{'forks'} -->\n";
3578 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3582 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3583 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3584 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3585 -class => "list", -title
=> $pr->{'descr_long'}},
3586 esc_html
($pr->{'descr'})) . "</td>\n" .
3587 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3588 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3589 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3590 "<td class=\"link\">" .
3591 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3592 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3593 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3594 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3595 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3599 if (defined $extra) {
3602 print "<td></td>\n";
3604 print "<td colspan=\"5\">$extra</td>\n" .
3610 sub git_shortlog_body
{
3611 # uses global variable $project
3612 my ($commitlist, $from, $to, $refs, $extra) = @_;
3614 $from = 0 unless defined $from;
3615 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3617 print "<table class=\"shortlog\">\n";
3619 for (my $i = $from; $i <= $to; $i++) {
3620 my %co = %{$commitlist->[$i]};
3621 my $commit = $co{'id'};
3622 my $ref = format_ref_marker
($refs, $commit);
3624 print "<tr class=\"dark\">\n";
3626 print "<tr class=\"light\">\n";
3629 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3630 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3631 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3632 "<td><i>" . $author . "</i></td>\n" .
3634 print format_subject_html
($co{'title'}, $co{'title_short'},
3635 href
(action
=>"commit", hash
=>$commit), $ref);
3637 "<td class=\"link\">" .
3638 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3639 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3640 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3641 my $snapshot_links = format_snapshot_links
($commit);
3642 if (defined $snapshot_links) {
3643 print " | " . $snapshot_links;
3648 if (defined $extra) {
3650 "<td colspan=\"4\">$extra</td>\n" .
3656 sub git_history_body
{
3657 # Warning: assumes constant type (blob or tree) during history
3658 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3660 $from = 0 unless defined $from;
3661 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3663 print "<table class=\"history\">\n";
3665 for (my $i = $from; $i <= $to; $i++) {
3666 my %co = %{$commitlist->[$i]};
3670 my $commit = $co{'id'};
3672 my $ref = format_ref_marker
($refs, $commit);
3675 print "<tr class=\"dark\">\n";
3677 print "<tr class=\"light\">\n";
3680 # shortlog uses chop_str($co{'author_name'}, 10)
3681 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3682 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3683 "<td><i>" . $author . "</i></td>\n" .
3685 # originally git_history used chop_str($co{'title'}, 50)
3686 print format_subject_html
($co{'title'}, $co{'title_short'},
3687 href
(action
=>"commit", hash
=>$commit), $ref);
3689 "<td class=\"link\">" .
3690 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3691 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3693 if ($ftype eq 'blob') {
3694 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3695 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3696 if (defined $blob_current && defined $blob_parent &&
3697 $blob_current ne $blob_parent) {
3699 $cgi->a({-href
=> href
(action
=>"blobdiff",
3700 hash
=>$blob_current, hash_parent
=>$blob_parent,
3701 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3702 file_name
=>$file_name)},
3709 if (defined $extra) {
3711 "<td colspan=\"4\">$extra</td>\n" .
3718 # uses global variable $project
3719 my ($taglist, $from, $to, $extra) = @_;
3720 $from = 0 unless defined $from;
3721 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3723 print "<table class=\"tags\">\n";
3725 for (my $i = $from; $i <= $to; $i++) {
3726 my $entry = $taglist->[$i];
3728 my $comment = $tag{'subject'};
3730 if (defined $comment) {
3731 $comment_short = chop_str
($comment, 30, 5);
3734 print "<tr class=\"dark\">\n";
3736 print "<tr class=\"light\">\n";
3739 if (defined $tag{'age'}) {
3740 print "<td><i>$tag{'age'}</i></td>\n";
3742 print "<td></td>\n";
3745 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3746 -class => "list name"}, esc_html
($tag{'name'})) .
3749 if (defined $comment) {
3750 print format_subject_html
($comment, $comment_short,
3751 href
(action
=>"tag", hash
=>$tag{'id'}));
3754 "<td class=\"selflink\">";
3755 if ($tag{'type'} eq "tag") {
3756 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3761 "<td class=\"link\">" . " | " .
3762 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3763 if ($tag{'reftype'} eq "commit") {
3764 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3765 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3766 } elsif ($tag{'reftype'} eq "blob") {
3767 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3772 if (defined $extra) {
3774 "<td colspan=\"5\">$extra</td>\n" .
3780 sub git_heads_body
{
3781 # uses global variable $project
3782 my ($headlist, $head, $from, $to, $extra) = @_;
3783 $from = 0 unless defined $from;
3784 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3786 print "<table class=\"heads\">\n";
3788 for (my $i = $from; $i <= $to; $i++) {
3789 my $entry = $headlist->[$i];
3791 my $curr = $ref{'id'} eq $head;
3793 print "<tr class=\"dark\">\n";
3795 print "<tr class=\"light\">\n";
3798 print "<td><i>$ref{'age'}</i></td>\n" .
3799 ($curr ? "<td class=\"current_head\">" : "<td>") .
3800 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3801 -class => "list name"},esc_html
($ref{'name'})) .
3803 "<td class=\"link\">" .
3804 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3805 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3806 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3810 if (defined $extra) {
3812 "<td colspan=\"3\">$extra</td>\n" .
3818 sub git_search_grep_body
{
3819 my ($commitlist, $from, $to, $extra) = @_;
3820 $from = 0 unless defined $from;
3821 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3823 print "<table class=\"commit_search\">\n";
3825 for (my $i = $from; $i <= $to; $i++) {
3826 my %co = %{$commitlist->[$i]};
3830 my $commit = $co{'id'};
3832 print "<tr class=\"dark\">\n";
3834 print "<tr class=\"light\">\n";
3837 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3838 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3839 "<td><i>" . $author . "</i></td>\n" .
3841 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3842 -class => "list subject"},
3843 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3844 my $comment = $co{'comment'};
3845 foreach my $line (@$comment) {
3846 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3847 my ($lead, $match, $trail) = ($1, $2, $3);
3848 $match = chop_str
($match, 70, 5, 'center');
3849 my $contextlen = int((80 - length($match))/2);
3850 $contextlen = 30 if ($contextlen > 30);
3851 $lead = chop_str
($lead, $contextlen, 10, 'left');
3852 $trail = chop_str
($trail, $contextlen, 10, 'right');
3854 $lead = esc_html
($lead);
3855 $match = esc_html
($match);
3856 $trail = esc_html
($trail);
3858 print "$lead<span class=\"match\">$match</span>$trail<br />";
3862 "<td class=\"link\">" .
3863 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3865 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3867 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3871 if (defined $extra) {
3873 "<td colspan=\"3\">$extra</td>\n" .
3879 ## ======================================================================
3880 ## ======================================================================
3883 sub git_project_list
{
3884 my $order = $cgi->param('o');
3885 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3886 die_error
(undef, "Unknown order parameter");
3889 my @list = git_get_projects_list
();
3891 die_error
(undef, "No projects found");
3895 if (-f
$home_text) {
3896 print "<div class=\"index_include\">\n";
3897 open (my $fd, $home_text);
3902 git_project_list_body
(\
@list, $order);
3907 my $order = $cgi->param('o');
3908 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3909 die_error
(undef, "Unknown order parameter");
3912 my @list = git_get_projects_list
($project);
3914 die_error
(undef, "No forks found");
3918 git_print_page_nav
('','');
3919 git_print_header_div
('summary', "$project forks");
3920 git_project_list_body
(\
@list, $order);
3924 sub git_project_index
{
3925 my @projects = git_get_projects_list
($project);
3928 -type
=> 'text/plain',
3929 -charset
=> 'utf-8',
3930 -content_disposition
=> 'inline; filename="index.aux"');
3932 foreach my $pr (@projects) {
3933 if (!exists $pr->{'owner'}) {
3934 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3937 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3938 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3939 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3940 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3944 print "$path $owner\n";
3949 my $descr = git_get_project_description
($project) || "none";
3950 my %co = parse_commit
("HEAD");
3951 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3952 my $head = $co{'id'};
3954 my $owner = git_get_project_owner
($project);
3956 my $refs = git_get_references
();
3957 # These get_*_list functions return one more to allow us to see if
3958 # there are more ...
3959 my @taglist = git_get_tags_list
(16);
3960 my @headlist = git_get_heads_list
(16);
3962 my ($check_forks) = gitweb_check_feature
('forks');
3965 @forklist = git_get_projects_list
($project);
3969 git_print_page_nav
('summary','', $head);
3971 print "<div class=\"title\"> </div>\n";
3972 print "<table class=\"projects_list\">\n" .
3973 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3974 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3975 if (defined $cd{'rfc2822'}) {
3976 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3979 # use per project git URL list in $projectroot/$project/cloneurl
3980 # or make project git URL from git base URL and project name
3981 my $url_tag = "URL";
3982 my @url_list = git_get_project_url_list
($project);
3983 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3984 foreach my $git_url (@url_list) {
3985 next unless $git_url;
3986 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3991 if (-s
"$projectroot/$project/README.html") {
3992 if (open my $fd, "$projectroot/$project/README.html") {
3993 print "<div class=\"title\">readme</div>\n" .
3994 "<div class=\"readme\">\n";
3995 print $_ while (<$fd>);
3996 print "\n</div>\n"; # class="readme"
4001 # we need to request one more than 16 (0..15) to check if
4003 my @commitlist = $head ? parse_commits
($head, 17) : ();
4005 git_print_header_div
('shortlog');
4006 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4007 $#commitlist <= 15 ? undef :
4008 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4012 git_print_header_div
('tags');
4013 git_tags_body
(\
@taglist, 0, 15,
4014 $#taglist <= 15 ? undef :
4015 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4019 git_print_header_div
('heads');
4020 git_heads_body
(\
@headlist, $head, 0, 15,
4021 $#headlist <= 15 ? undef :
4022 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4026 git_print_header_div
('forks');
4027 git_project_list_body
(\
@forklist, undef, 0, 15,
4028 $#forklist <= 15 ? undef :
4029 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4037 my $head = git_get_head_hash
($project);
4039 git_print_page_nav
('','', $head,undef,$head);
4040 my %tag = parse_tag
($hash);
4043 die_error
(undef, "Unknown tag object");
4046 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4047 print "<div class=\"title_text\">\n" .
4048 "<table class=\"object_header\">\n" .
4050 "<td>object</td>\n" .
4051 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4052 $tag{'object'}) . "</td>\n" .
4053 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4054 $tag{'type'}) . "</td>\n" .
4056 if (defined($tag{'author'})) {
4057 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4058 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4059 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4060 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4063 print "</table>\n\n" .
4065 print "<div class=\"page_body\">";
4066 my $comment = $tag{'comment'};
4067 foreach my $line (@$comment) {
4069 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4079 my ($have_blame) = gitweb_check_feature
('blame');
4081 die_error
('403 Permission denied', "Permission denied");
4083 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4084 $hash_base ||= git_get_head_hash
($project);
4085 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4086 my %co = parse_commit
($hash_base)
4087 or die_error
(undef, "Reading commit failed");
4088 if (!defined $hash) {
4089 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4090 or die_error
(undef, "Error looking up file");
4092 $ftype = git_get_type
($hash);
4093 if ($ftype !~ "blob") {
4094 die_error
('400 Bad Request', "Object is not a blob");
4096 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4097 $file_name, $hash_base)
4098 or die_error
(undef, "Open git-blame failed");
4101 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4104 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4107 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4109 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4110 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4111 git_print_page_path
($file_name, $ftype, $hash_base);
4112 my @rev_color = (qw(light2 dark2));
4113 my $num_colors = scalar(@rev_color);
4114 my $current_color = 0;
4117 <div class="page_body">
4118 <table class="blame">
4119 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4124 last unless defined $_;
4125 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4126 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4127 if (!exists $metainfo{$full_rev}) {
4128 $metainfo{$full_rev} = {};
4130 my $meta = $metainfo{$full_rev};
4133 if (/^(\S+) (.*)$/) {
4139 my $rev = substr($full_rev, 0, 8);
4140 my $author = $meta->{'author'};
4141 my %date = parse_date
($meta->{'author-time'},
4142 $meta->{'author-tz'});
4143 my $date = $date{'iso-tz'};
4145 $current_color = ++$current_color % $num_colors;
4147 print "<tr class=\"$rev_color[$current_color]\">\n";
4149 print "<td class=\"sha1\"";
4150 print " title=\"". esc_html
($author) . ", $date\"";
4151 print " rowspan=\"$group_size\"" if ($group_size > 1);
4153 print $cgi->a({-href
=> href
(action
=>"commit",
4155 file_name
=>$file_name)},
4159 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4160 or die_error
(undef, "Open git-rev-parse failed");
4161 my $parent_commit = <$dd>;
4163 chomp($parent_commit);
4164 my $blamed = href
(action
=> 'blame',
4165 file_name
=> $meta->{'filename'},
4166 hash_base
=> $parent_commit);
4167 print "<td class=\"linenr\">";
4168 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4170 -class => "linenr" },
4173 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4179 or print "Reading blob failed\n";
4186 my ($have_blame) = gitweb_check_feature
('blame');
4188 die_error
('403 Permission denied', "Permission denied");
4190 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4191 $hash_base ||= git_get_head_hash
($project);
4192 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4193 my %co = parse_commit
($hash_base)
4194 or die_error
(undef, "Reading commit failed");
4195 if (!defined $hash) {
4196 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4197 or die_error
(undef, "Error lookup file");
4199 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4200 or die_error
(undef, "Open git-annotate failed");
4203 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4206 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4209 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4211 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4212 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4213 git_print_page_path
($file_name, 'blob', $hash_base);
4214 print "<div class=\"page_body\">\n";
4216 <table class="blame">
4225 my @line_class = (qw(light dark));
4226 my $line_class_len = scalar (@line_class);
4227 my $line_class_num = $#line_class;
4228 while (my $line = <$fd>) {
4240 $line_class_num = ($line_class_num + 1) % $line_class_len;
4242 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4249 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4252 $short_rev = substr ($long_rev, 0, 8);
4253 $age = time () - $time;
4254 $age_str = age_string
($age);
4255 $age_str =~ s/ / /g;
4256 $age_class = age_class
($age);
4257 $author = esc_html
($author);
4258 $author =~ s/ / /g;
4260 $data = untabify
($data);
4261 $data = esc_html
($data);
4264 <tr class="$line_class[$line_class_num]">
4265 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4266 <td class="$age_class">$age_str</td>
4268 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4269 <td class="pre">$data</td>
4272 } # while (my $line = <$fd>)
4273 print "</table>\n\n";
4275 or print "Reading blob failed.\n";
4281 my $head = git_get_head_hash
($project);
4283 git_print_page_nav
('','', $head,undef,$head);
4284 git_print_header_div
('summary', $project);
4286 my @tagslist = git_get_tags_list
();
4288 git_tags_body
(\
@tagslist);
4294 my $head = git_get_head_hash
($project);
4296 git_print_page_nav
('','', $head,undef,$head);
4297 git_print_header_div
('summary', $project);
4299 my @headslist = git_get_heads_list
();
4301 git_heads_body
(\
@headslist, $head);
4306 sub git_blob_plain
{
4309 if (!defined $hash) {
4310 if (defined $file_name) {
4311 my $base = $hash_base || git_get_head_hash
($project);
4312 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4313 or die_error
(undef, "Error lookup file");
4315 die_error
(undef, "No file name defined");
4317 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4318 # blobs defined by non-textual hash id's can be cached
4323 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4324 or die_error
(undef, "Couldn't cat $file_name, $hash");
4326 $type ||= blob_mimetype
($fd, $file_name);
4328 # save as filename, even when no $file_name is given
4329 my $save_as = "$hash";
4330 if (defined $file_name) {
4331 $save_as = $file_name;
4332 } elsif ($type =~ m/^text\//) {
4339 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4341 binmode STDOUT
, ':raw';
4343 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4351 if (!defined $hash) {
4352 if (defined $file_name) {
4353 my $base = $hash_base || git_get_head_hash
($project);
4354 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4355 or die_error
(undef, "Error lookup file");
4357 die_error
(undef, "No file name defined");
4359 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4360 # blobs defined by non-textual hash id's can be cached
4364 my ($have_blame) = gitweb_check_feature
('blame');
4365 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4366 or die_error
(undef, "Couldn't cat $file_name, $hash");
4367 my $mimetype = blob_mimetype
($fd, $file_name);
4368 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4370 return git_blob_plain
($mimetype);
4372 # we can have blame only for text/* mimetype
4373 $have_blame &&= ($mimetype =~ m!^text/!);
4375 git_header_html
(undef, $expires);
4376 my $formats_nav = '';
4377 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4378 if (defined $file_name) {
4381 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4386 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4389 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4392 $cgi->a({-href
=> href
(action
=>"blob",
4393 hash_base
=>"HEAD", file_name
=>$file_name)},
4397 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4400 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4401 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4403 print "<div class=\"page_nav\">\n" .
4404 "<br/><br/></div>\n" .
4405 "<div class=\"title\">$hash</div>\n";
4407 git_print_page_path
($file_name, "blob", $hash_base);
4408 print "<div class=\"page_body\">\n";
4409 if ($mimetype =~ m!^image/!) {
4410 print qq
!<img type
="$mimetype"!;
4412 print qq
! alt
="$file_name" title
="$file_name"!;
4415 href(action=>"blob_plain
", hash=>$hash,
4416 hash_base=>$hash_base, file_name=>$file_name) .
4420 while (my $line = <$fd>) {
4423 $line = untabify
($line);
4424 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4425 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4429 or print "Reading blob failed.\n";
4435 if (!defined $hash_base) {
4436 $hash_base = "HEAD";
4438 if (!defined $hash) {
4439 if (defined $file_name) {
4440 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4446 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4447 or die_error
(undef, "Open git-ls-tree failed");
4448 my @entries = map { chomp; $_ } <$fd>;
4449 close $fd or die_error
(undef, "Reading tree failed");
4452 my $refs = git_get_references
();
4453 my $ref = format_ref_marker
($refs, $hash_base);
4456 my ($have_blame) = gitweb_check_feature
('blame');
4457 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4459 if (defined $file_name) {
4461 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4463 $cgi->a({-href
=> href
(action
=>"tree",
4464 hash_base
=>"HEAD", file_name
=>$file_name)},
4467 my $snapshot_links = format_snapshot_links
($hash);
4468 if (defined $snapshot_links) {
4469 # FIXME: Should be available when we have no hash base as well.
4470 push @views_nav, $snapshot_links;
4472 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4473 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4476 print "<div class=\"page_nav\">\n";
4477 print "<br/><br/></div>\n";
4478 print "<div class=\"title\">$hash</div>\n";
4480 if (defined $file_name) {
4481 $basedir = $file_name;
4482 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4486 git_print_page_path
($file_name, 'tree', $hash_base);
4487 print "<div class=\"page_body\">\n";
4488 print "<table class=\"tree\">\n";
4490 # '..' (top directory) link if possible
4491 if (defined $hash_base &&
4492 defined $file_name && $file_name =~ m![^/]+$!) {
4494 print "<tr class=\"dark\">\n";
4496 print "<tr class=\"light\">\n";
4500 my $up = $file_name;
4501 $up =~ s!/?[^/]+$!!;
4502 undef $up unless $up;
4503 # based on git_print_tree_entry
4504 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4505 print '<td class="list">';
4506 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4510 print "<td class=\"link\"></td>\n";
4514 foreach my $line (@entries) {
4515 my %t = parse_ls_tree_line
($line, -z
=> 1);
4518 print "<tr class=\"dark\">\n";
4520 print "<tr class=\"light\">\n";
4524 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4528 print "</table>\n" .
4534 my @supported_fmts = gitweb_check_feature
('snapshot');
4535 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4537 my $format = $cgi->param('sf');
4538 if (!@supported_fmts) {
4539 die_error
('403 Permission denied', "Permission denied");
4541 # default to first supported snapshot format
4542 $format ||= $supported_fmts[0];
4543 if ($format !~ m/^[a-z0-9]+$/) {
4544 die_error
(undef, "Invalid snapshot format parameter");
4545 } elsif (!exists($known_snapshot_formats{$format})) {
4546 die_error
(undef, "Unknown snapshot format");
4547 } elsif (!grep($_ eq $format, @supported_fmts)) {
4548 die_error
(undef, "Unsupported snapshot format");
4551 if (!defined $hash) {
4552 $hash = git_get_head_hash
($project);
4555 my $git_command = git_cmd_str
();
4556 my $name = $project;
4557 $name =~ s
,([^/])/*\
.git
$,$1,;
4558 $name = basename
($name);
4559 my $filename = to_utf8
($name);
4560 $name =~ s/\047/\047\\\047\047/g;
4562 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4563 $cmd = "$git_command archive " .
4564 "--format=$known_snapshot_formats{$format}{'format'} " .
4565 "--prefix=\'$name\'/ $hash";
4566 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4567 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4571 -type
=> $known_snapshot_formats{$format}{'type'},
4572 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4573 -status
=> '200 OK');
4575 open my $fd, "-|", $cmd
4576 or die_error
(undef, "Execute git-archive failed");
4577 binmode STDOUT
, ':raw';
4579 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4584 my $head = git_get_head_hash
($project);
4585 if (!defined $hash) {
4588 if (!defined $page) {
4591 my $refs = git_get_references
();
4593 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4595 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4598 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4601 my %co = parse_commit
($hash);
4603 git_print_header_div
('summary', $project);
4604 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4606 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4607 for (my $i = 0; $i <= $to; $i++) {
4608 my %co = %{$commitlist[$i]};
4610 my $commit = $co{'id'};
4611 my $ref = format_ref_marker
($refs, $commit);
4612 my %ad = parse_date
($co{'author_epoch'});
4613 git_print_header_div
('commit',
4614 "<span class=\"age\">$co{'age_string'}</span>" .
4615 esc_html
($co{'title'}) . $ref,
4617 print "<div class=\"title_text\">\n" .
4618 "<div class=\"log_link\">\n" .
4619 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4621 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4623 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4626 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4629 print "<div class=\"log_body\">\n";
4630 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4633 if ($#commitlist >= 100) {
4634 print "<div class=\"page_nav\">\n";
4635 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4636 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4643 $hash ||= $hash_base || "HEAD";
4644 my %co = parse_commit
($hash);
4646 die_error
(undef, "Unknown commit object");
4648 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4649 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4651 my $parent = $co{'parent'};
4652 my $parents = $co{'parents'}; # listref
4654 # we need to prepare $formats_nav before any parameter munging
4656 if (!defined $parent) {
4658 $formats_nav .= '(initial)';
4659 } elsif (@$parents == 1) {
4660 # single parent commit
4663 $cgi->a({-href
=> href
(action
=>"commit",
4665 esc_html
(substr($parent, 0, 7))) .
4672 $cgi->a({-href
=> href
(action
=>"commit",
4674 esc_html
(substr($_, 0, 7)));
4679 if (!defined $parent) {
4683 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4685 (@$parents <= 1 ? $parent : '-c'),
4687 or die_error
(undef, "Open git-diff-tree failed");
4688 @difftree = map { chomp; $_ } <$fd>;
4689 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4691 # non-textual hash id's can be cached
4693 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4696 my $refs = git_get_references
();
4697 my $ref = format_ref_marker
($refs, $co{'id'});
4699 git_header_html
(undef, $expires);
4700 git_print_page_nav
('commit', '',
4701 $hash, $co{'tree'}, $hash,
4704 if (defined $co{'parent'}) {
4705 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4707 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4709 print "<div class=\"title_text\">\n" .
4710 "<table class=\"object_header\">\n";
4711 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4713 "<td></td><td> $ad{'rfc2822'}";
4714 if ($ad{'hour_local'} < 6) {
4715 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4716 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4718 printf(" (%02d:%02d %s)",
4719 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4723 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4724 print "<tr><td></td><td> $cd{'rfc2822'}" .
4725 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4727 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4730 "<td class=\"sha1\">" .
4731 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4732 class => "list"}, $co{'tree'}) .
4734 "<td class=\"link\">" .
4735 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4737 my $snapshot_links = format_snapshot_links
($hash);
4738 if (defined $snapshot_links) {
4739 print " | " . $snapshot_links;
4744 foreach my $par (@$parents) {
4747 "<td class=\"sha1\">" .
4748 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4749 class => "list"}, $par) .
4751 "<td class=\"link\">" .
4752 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4754 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4761 print "<div class=\"page_body\">\n";
4762 git_print_log
($co{'comment'});
4765 git_difftree_body
(\
@difftree, $hash, @$parents);
4771 # object is defined by:
4772 # - hash or hash_base alone
4773 # - hash_base and file_name
4776 # - hash or hash_base alone
4777 if ($hash || ($hash_base && !defined $file_name)) {
4778 my $object_id = $hash || $hash_base;
4780 my $git_command = git_cmd_str
();
4781 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4782 or die_error
('404 Not Found', "Object does not exist");
4786 or die_error
('404 Not Found', "Object does not exist");
4788 # - hash_base and file_name
4789 } elsif ($hash_base && defined $file_name) {
4790 $file_name =~ s
,/+$,,;
4792 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4793 or die_error
('404 Not Found', "Base object does not exist");
4795 # here errors should not hapen
4796 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4797 or die_error
(undef, "Open git-ls-tree failed");
4801 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4802 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4803 die_error
('404 Not Found', "File or directory for given base does not exist");
4808 die_error
('404 Not Found', "Not enough information to find object");
4811 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4812 hash
=>$hash, hash_base
=>$hash_base,
4813 file_name
=>$file_name),
4814 -status
=> '302 Found');
4818 my $format = shift || 'html';
4825 # preparing $fd and %diffinfo for git_patchset_body
4827 if (defined $hash_base && defined $hash_parent_base) {
4828 if (defined $file_name) {
4830 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4831 $hash_parent_base, $hash_base,
4832 "--", (defined $file_parent ? $file_parent : ()), $file_name
4833 or die_error
(undef, "Open git-diff-tree failed");
4834 @difftree = map { chomp; $_ } <$fd>;
4836 or die_error
(undef, "Reading git-diff-tree failed");
4838 or die_error
('404 Not Found', "Blob diff not found");
4840 } elsif (defined $hash &&
4841 $hash =~ /[0-9a-fA-F]{40}/) {
4842 # try to find filename from $hash
4844 # read filtered raw output
4845 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4846 $hash_parent_base, $hash_base, "--"
4847 or die_error
(undef, "Open git-diff-tree failed");
4849 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4851 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4852 map { chomp; $_ } <$fd>;
4854 or die_error
(undef, "Reading git-diff-tree failed");
4856 or die_error
('404 Not Found', "Blob diff not found");
4859 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4862 if (@difftree > 1) {
4863 die_error
('404 Not Found', "Ambiguous blob diff specification");
4866 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4867 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4868 $file_name ||= $diffinfo{'to_file'};
4870 $hash_parent ||= $diffinfo{'from_id'};
4871 $hash ||= $diffinfo{'to_id'};
4873 # non-textual hash id's can be cached
4874 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4875 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4880 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4881 '-p', ($format eq 'html' ? "--full-index" : ()),
4882 $hash_parent_base, $hash_base,
4883 "--", (defined $file_parent ? $file_parent : ()), $file_name
4884 or die_error
(undef, "Open git-diff-tree failed");
4887 # old/legacy style URI
4888 if (!%diffinfo && # if new style URI failed
4889 defined $hash && defined $hash_parent) {
4890 # fake git-diff-tree raw output
4891 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4892 $diffinfo{'from_id'} = $hash_parent;
4893 $diffinfo{'to_id'} = $hash;
4894 if (defined $file_name) {
4895 if (defined $file_parent) {
4896 $diffinfo{'status'} = '2';
4897 $diffinfo{'from_file'} = $file_parent;
4898 $diffinfo{'to_file'} = $file_name;
4899 } else { # assume not renamed
4900 $diffinfo{'status'} = '1';
4901 $diffinfo{'from_file'} = $file_name;
4902 $diffinfo{'to_file'} = $file_name;
4904 } else { # no filename given
4905 $diffinfo{'status'} = '2';
4906 $diffinfo{'from_file'} = $hash_parent;
4907 $diffinfo{'to_file'} = $hash;
4910 # non-textual hash id's can be cached
4911 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4912 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4917 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4918 '-p', ($format eq 'html' ? "--full-index" : ()),
4919 $hash_parent, $hash, "--"
4920 or die_error
(undef, "Open git-diff failed");
4922 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4927 if ($format eq 'html') {
4929 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4931 git_header_html
(undef, $expires);
4932 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4933 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4934 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4936 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4937 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4939 if (defined $file_name) {
4940 git_print_page_path
($file_name, "blob", $hash_base);
4942 print "<div class=\"page_path\"></div>\n";
4945 } elsif ($format eq 'plain') {
4947 -type
=> 'text/plain',
4948 -charset
=> 'utf-8',
4949 -expires
=> $expires,
4950 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4952 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4955 die_error
(undef, "Unknown blobdiff format");
4959 if ($format eq 'html') {
4960 print "<div class=\"page_body\">\n";
4962 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4965 print "</div>\n"; # class="page_body"
4969 while (my $line = <$fd>) {
4970 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4971 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4975 last if $line =~ m!^\+\+\+!;
4983 sub git_blobdiff_plain
{
4984 git_blobdiff
('plain');
4987 sub git_commitdiff
{
4988 my $format = shift || 'html';
4989 $hash ||= $hash_base || "HEAD";
4990 my %co = parse_commit
($hash);
4992 die_error
(undef, "Unknown commit object");
4995 # choose format for commitdiff for merge
4996 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4997 $hash_parent = '--cc';
4999 # we need to prepare $formats_nav before almost any parameter munging
5001 if ($format eq 'html') {
5003 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5006 if (defined $hash_parent &&
5007 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5008 # commitdiff with two commits given
5009 my $hash_parent_short = $hash_parent;
5010 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5011 $hash_parent_short = substr($hash_parent, 0, 7);
5015 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5016 if ($co{'parents'}[$i] eq $hash_parent) {
5017 $formats_nav .= ' parent ' . ($i+1);
5021 $formats_nav .= ': ' .
5022 $cgi->a({-href
=> href
(action
=>"commitdiff",
5023 hash
=>$hash_parent)},
5024 esc_html
($hash_parent_short)) .
5026 } elsif (!$co{'parent'}) {
5028 $formats_nav .= ' (initial)';
5029 } elsif (scalar @{$co{'parents'}} == 1) {
5030 # single parent commit
5033 $cgi->a({-href
=> href
(action
=>"commitdiff",
5034 hash
=>$co{'parent'})},
5035 esc_html
(substr($co{'parent'}, 0, 7))) .
5039 if ($hash_parent eq '--cc') {
5040 $formats_nav .= ' | ' .
5041 $cgi->a({-href
=> href
(action
=>"commitdiff",
5042 hash
=>$hash, hash_parent
=>'-c')},
5044 } else { # $hash_parent eq '-c'
5045 $formats_nav .= ' | ' .
5046 $cgi->a({-href
=> href
(action
=>"commitdiff",
5047 hash
=>$hash, hash_parent
=>'--cc')},
5053 $cgi->a({-href
=> href
(action
=>"commitdiff",
5055 esc_html
(substr($_, 0, 7)));
5056 } @{$co{'parents'}} ) .
5061 my $hash_parent_param = $hash_parent;
5062 if (!defined $hash_parent_param) {
5063 # --cc for multiple parents, --root for parentless
5064 $hash_parent_param =
5065 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5071 if ($format eq 'html') {
5072 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5073 "--no-commit-id", "--patch-with-raw", "--full-index",
5074 $hash_parent_param, $hash, "--"
5075 or die_error
(undef, "Open git-diff-tree failed");
5077 while (my $line = <$fd>) {
5079 # empty line ends raw part of diff-tree output
5081 push @difftree, scalar parse_difftree_raw_line
($line);
5084 } elsif ($format eq 'plain') {
5085 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5086 '-p', $hash_parent_param, $hash, "--"
5087 or die_error
(undef, "Open git-diff-tree failed");
5090 die_error
(undef, "Unknown commitdiff format");
5093 # non-textual hash id's can be cached
5095 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5099 # write commit message
5100 if ($format eq 'html') {
5101 my $refs = git_get_references
();
5102 my $ref = format_ref_marker
($refs, $co{'id'});
5104 git_header_html
(undef, $expires);
5105 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5106 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5107 git_print_authorship
(\
%co);
5108 print "<div class=\"page_body\">\n";
5109 if (@{$co{'comment'}} > 1) {
5110 print "<div class=\"log\">\n";
5111 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5112 print "</div>\n"; # class="log"
5115 } elsif ($format eq 'plain') {
5116 my $refs = git_get_references
("tags");
5117 my $tagname = git_get_rev_name_tags
($hash);
5118 my $filename = basename
($project) . "-$hash.patch";
5121 -type
=> 'text/plain',
5122 -charset
=> 'utf-8',
5123 -expires
=> $expires,
5124 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5125 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5126 print "From: " . to_utf8
($co{'author'}) . "\n";
5127 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5128 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5130 print "X-Git-Tag: $tagname\n" if $tagname;
5131 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5133 foreach my $line (@{$co{'comment'}}) {
5134 print to_utf8
($line) . "\n";
5140 if ($format eq 'html') {
5141 my $use_parents = !defined $hash_parent ||
5142 $hash_parent eq '-c' || $hash_parent eq '--cc';
5143 git_difftree_body
(\
@difftree, $hash,
5144 $use_parents ? @{$co{'parents'}} : $hash_parent);
5147 git_patchset_body
($fd, \
@difftree, $hash,
5148 $use_parents ? @{$co{'parents'}} : $hash_parent);
5150 print "</div>\n"; # class="page_body"
5153 } elsif ($format eq 'plain') {
5157 or print "Reading git-diff-tree failed\n";
5161 sub git_commitdiff_plain
{
5162 git_commitdiff
('plain');
5166 if (!defined $hash_base) {
5167 $hash_base = git_get_head_hash
($project);
5169 if (!defined $page) {
5173 my %co = parse_commit
($hash_base);
5175 die_error
(undef, "Unknown commit object");
5178 my $refs = git_get_references
();
5179 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5181 if (!defined $hash && defined $file_name) {
5182 $hash = git_get_hash_by_path
($hash_base, $file_name);
5184 if (defined $hash) {
5185 $ftype = git_get_type
($hash);
5188 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), $file_name, "--full-history");
5190 my $paging_nav = '';
5193 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5194 file_name
=>$file_name)},
5196 $paging_nav .= " ⋅ " .
5197 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5198 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5200 $paging_nav .= "first";
5201 $paging_nav .= " ⋅ prev";
5204 if ($#commitlist >= 100) {
5206 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5207 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5208 $paging_nav .= " ⋅ $next_link";
5210 $paging_nav .= " ⋅ next";
5214 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5215 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5216 git_print_page_path
($file_name, $ftype, $hash_base);
5218 git_history_body
(\
@commitlist, 0, 99,
5219 $refs, $hash_base, $ftype, $next_link);
5225 my ($have_search) = gitweb_check_feature
('search');
5226 if (!$have_search) {
5227 die_error
('403 Permission denied', "Permission denied");
5229 if (!defined $searchtext) {
5230 die_error
(undef, "Text field empty");
5232 if (!defined $hash) {
5233 $hash = git_get_head_hash
($project);
5235 my %co = parse_commit
($hash);
5237 die_error
(undef, "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 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5248 if (!$have_pickaxe) {
5249 die_error
('403 Permission denied', "Permission denied");
5252 if ($searchtype eq 'grep') {
5253 my ($have_grep) = gitweb_check_feature
('grep');
5255 die_error
('403 Permission denied', "Permission denied");
5261 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5263 if ($searchtype eq 'commit') {
5264 $greptype = "--grep=";
5265 } elsif ($searchtype eq 'author') {
5266 $greptype = "--author=";
5267 } elsif ($searchtype eq 'committer') {
5268 $greptype = "--committer=";
5270 $greptype .= $searchtext;
5271 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5272 $greptype, '--regexp-ignore-case',
5273 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5275 my $paging_nav = '';
5278 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5279 searchtext
=>$searchtext,
5280 searchtype
=>$searchtype)},
5282 $paging_nav .= " ⋅ " .
5283 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5284 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5286 $paging_nav .= "first";
5287 $paging_nav .= " ⋅ prev";
5290 if ($#commitlist >= 100) {
5292 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5293 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5294 $paging_nav .= " ⋅ $next_link";
5296 $paging_nav .= " ⋅ next";
5299 if ($#commitlist >= 100) {
5302 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5303 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5304 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5307 if ($searchtype eq 'pickaxe') {
5308 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5309 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5311 print "<table class=\"pickaxe search\">\n";
5314 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5315 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5316 ($search_use_regexp ? '--pickaxe-regex' : ());
5319 while (my $line = <$fd>) {
5323 my %set = parse_difftree_raw_line
($line);
5324 if (defined $set{'commit'}) {
5325 # finish previous commit
5328 "<td class=\"link\">" .
5329 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5331 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5337 print "<tr class=\"dark\">\n";
5339 print "<tr class=\"light\">\n";
5342 %co = parse_commit
($set{'commit'});
5343 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5344 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5345 "<td><i>$author</i></td>\n" .
5347 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5348 -class => "list subject"},
5349 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5350 } elsif (defined $set{'to_id'}) {
5351 next if ($set{'to_id'} =~ m/^0{40}$/);
5353 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5354 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5356 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5362 # finish last commit (warning: repetition!)
5365 "<td class=\"link\">" .
5366 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5368 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5376 if ($searchtype eq 'grep') {
5377 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5378 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5380 print "<table class=\"grep_search\">\n";
5384 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5385 $search_use_regexp ? ('-E', '-i') : '-F',
5386 $searchtext, $co{'tree'};
5388 while (my $line = <$fd>) {
5390 my ($file, $lno, $ltext, $binary);
5391 last if ($matches++ > 1000);
5392 if ($line =~ /^Binary file (.+) matches$/) {
5396 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5398 if ($file ne $lastfile) {
5399 $lastfile and print "</td></tr>\n";
5401 print "<tr class=\"dark\">\n";
5403 print "<tr class=\"light\">\n";
5405 print "<td class=\"list\">".
5406 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5407 file_name
=>"$file"),
5408 -class => "list"}, esc_path
($file));
5409 print "</td><td>\n";
5413 print "<div class=\"binary\">Binary file</div>\n";
5415 $ltext = untabify
($ltext);
5416 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5417 $ltext = esc_html
($1, -nbsp
=>1);
5418 $ltext .= '<span class="match">';
5419 $ltext .= esc_html
($2, -nbsp
=>1);
5420 $ltext .= '</span>';
5421 $ltext .= esc_html
($3, -nbsp
=>1);
5423 $ltext = esc_html
($ltext, -nbsp
=>1);
5425 print "<div class=\"pre\">" .
5426 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5427 file_name
=>"$file").'#l'.$lno,
5428 -class => "linenr"}, sprintf('%4i', $lno))
5429 . ' ' . $ltext . "</div>\n";
5433 print "</td></tr>\n";
5434 if ($matches > 1000) {
5435 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5438 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5447 sub git_search_help
{
5449 git_print_page_nav
('','', $hash,$hash,$hash);
5451 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5452 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5453 the pattern entered is recognized as the POSIX extended
5454 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5457 <dt><b>commit</b></dt>
5458 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5460 my ($have_grep) = gitweb_check_feature
('grep');
5463 <dt><b>grep</b></dt>
5464 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5465 a different one) are searched for the given pattern. On large trees, this search can take
5466 a while and put some strain on the server, so please use it with some consideration. Note that
5467 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5468 case-sensitive.</dd>
5472 <dt><b>author</b></dt>
5473 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5474 <dt><b>committer</b></dt>
5475 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5477 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5478 if ($have_pickaxe) {
5480 <dt><b>pickaxe</b></dt>
5481 <dd>All commits that caused the string to appear or disappear from any file (changes that
5482 added, removed or "modified" the string) will be listed. This search can take a while and
5483 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5484 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5492 my $head = git_get_head_hash
($project);
5493 if (!defined $hash) {
5496 if (!defined $page) {
5499 my $refs = git_get_references
();
5501 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5503 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
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
(undef, "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";