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
,^\Q
$project\E
/*,,;
516 my ($refname, $pathname) = split(/:/, $path_info, 2);
517 if (defined $pathname) {
518 # we got "project.git/branch:filename" or "project.git/branch:dir/"
519 # we could use git_get_type(branch:pathname), but it needs $git_dir
520 $pathname =~ s
,^/+,,;
521 if (!$pathname || substr($pathname, -1) eq "/") {
525 $action ||= "blob_plain";
527 $hash_base ||= validate_refname
($refname);
528 $file_name ||= validate_pathname
($pathname);
529 } elsif (defined $refname) {
530 # we got "project.git/branch"
531 $action ||= "shortlog";
532 $hash ||= validate_refname
($refname);
535 evaluate_path_info
();
537 # path to the current git repository
539 $git_dir = "$projectroot/$project" if $project;
543 "blame" => \
&git_blame
,
544 "blobdiff" => \
&git_blobdiff
,
545 "blobdiff_plain" => \
&git_blobdiff_plain
,
546 "blob" => \
&git_blob
,
547 "blob_plain" => \
&git_blob_plain
,
548 "commitdiff" => \
&git_commitdiff
,
549 "commitdiff_plain" => \
&git_commitdiff_plain
,
550 "commit" => \
&git_commit
,
551 "forks" => \
&git_forks
,
552 "heads" => \
&git_heads
,
553 "history" => \
&git_history
,
556 "atom" => \
&git_atom
,
557 "search" => \
&git_search
,
558 "search_help" => \
&git_search_help
,
559 "shortlog" => \
&git_shortlog
,
560 "summary" => \
&git_summary
,
562 "tags" => \
&git_tags
,
563 "tree" => \
&git_tree
,
564 "snapshot" => \
&git_snapshot
,
565 "object" => \
&git_object
,
566 # those below don't need $project
567 "opml" => \
&git_opml
,
568 "project_list" => \
&git_project_list
,
569 "project_index" => \
&git_project_index
,
572 if (!defined $action) {
574 $action = git_get_type
($hash);
575 } elsif (defined $hash_base && defined $file_name) {
576 $action = git_get_type
("$hash_base:$file_name");
577 } elsif (defined $project) {
580 $action = 'project_list';
583 if (!defined($actions{$action})) {
584 die_error
(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 .= "/".esc_url
($params{'project'}) if defined $params{'project'};
638 delete $params{'project'};
640 # Summary just uses the project path URL
641 if (defined $params{'action'} && $params{'action'} eq 'summary') {
642 delete $params{'action'};
646 # now encode the parameters explicitly
648 for (my $i = 0; $i < @mapping; $i += 2) {
649 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
650 if (defined $params{$name}) {
651 if (ref($params{$name}) eq "ARRAY") {
652 foreach my $par (@{$params{$name}}) {
653 push @result, $symbol . "=" . esc_param
($par);
656 push @result, $symbol . "=" . esc_param
($params{$name});
660 $href .= "?" . join(';', @result) if scalar @result;
666 ## ======================================================================
667 ## validation, quoting/unquoting and escaping
669 sub validate_pathname
{
670 my $input = shift || return undef;
672 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
673 # at the beginning, at the end, and between slashes.
674 # also this catches doubled slashes
675 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
679 if ($input =~ m!\0!) {
685 sub validate_refname
{
686 my $input = shift || return undef;
688 # textual hashes are O.K.
689 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
692 # it must be correct pathname
693 $input = validate_pathname
($input)
695 # restrictions on ref name according to git-check-ref-format
696 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
702 # decode sequences of octets in utf8 into Perl's internal form,
703 # which is utf-8 with utf8 flag set if needed. gitweb writes out
704 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
707 if (utf8
::valid
($str)) {
711 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
715 # quote unsafe chars, but keep the slash, even when it's not
716 # correct, but quoted slashes look too horrible in bookmarks
719 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
725 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
728 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
734 # replace invalid utf8 character with SUBSTITUTION sequence
739 $str = to_utf8
($str);
740 $str = $cgi->escapeHTML($str);
741 if ($opts{'-nbsp'}) {
742 $str =~ s/ / /g;
744 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
748 # quote control characters and escape filename to HTML
753 $str = to_utf8
($str);
754 $str = $cgi->escapeHTML($str);
755 if ($opts{'-nbsp'}) {
756 $str =~ s/ / /g;
758 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
762 # Make control characters "printable", using character escape codes (CEC)
766 my %es = ( # character escape codes, aka escape sequences
767 "\t" => '\t', # tab (HT)
768 "\n" => '\n', # line feed (LF)
769 "\r" => '\r', # carrige return (CR)
770 "\f" => '\f', # form feed (FF)
771 "\b" => '\b', # backspace (BS)
772 "\a" => '\a', # alarm (bell) (BEL)
773 "\e" => '\e', # escape (ESC)
774 "\013" => '\v', # vertical tab (VT)
775 "\000" => '\0', # nul character (NUL)
777 my $chr = ( (exists $es{$cntrl})
779 : sprintf('\%03o', ord($cntrl)) );
780 if ($opts{-nohtml
}) {
783 return "<span class=\"cntrl\">$chr</span>";
787 # Alternatively use unicode control pictures codepoints,
788 # Unicode "printable representation" (PR)
793 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
794 if ($opts{-nohtml
}) {
797 return "<span class=\"cntrl\">$chr</span>";
801 # git may return quoted and escaped filenames
807 my %es = ( # character escape codes, aka escape sequences
808 't' => "\t", # tab (HT, TAB)
809 'n' => "\n", # newline (NL)
810 'r' => "\r", # return (CR)
811 'f' => "\f", # form feed (FF)
812 'b' => "\b", # backspace (BS)
813 'a' => "\a", # alarm (bell) (BEL)
814 'e' => "\e", # escape (ESC)
815 'v' => "\013", # vertical tab (VT)
818 if ($seq =~ m/^[0-7]{1,3}$/) {
819 # octal char sequence
820 return chr(oct($seq));
821 } elsif (exists $es{$seq}) {
822 # C escape sequence, aka character escape code
825 # quoted ordinary character
829 if ($str =~ m/^"(.*)"$/) {
832 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
837 # escape tabs (convert tabs to spaces)
841 while ((my $pos = index($line, "\t")) != -1) {
842 if (my $count = (8 - ($pos % 8))) {
843 my $spaces = ' ' x
$count;
844 $line =~ s/\t/$spaces/;
851 sub project_in_list
{
853 my @list = git_get_projects_list
();
854 return @list && scalar(grep { $_->{'path'} eq $project } @list);
857 ## ----------------------------------------------------------------------
858 ## HTML aware string manipulation
860 # Try to chop given string on a word boundary between position
861 # $len and $len+$add_len. If there is no word boundary there,
862 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
863 # (marking chopped part) would be longer than given string.
867 my $add_len = shift || 10;
868 my $where = shift || 'right'; # 'left' | 'center' | 'right'
870 # Make sure perl knows it is utf8 encoded so we don't
871 # cut in the middle of a utf8 multibyte char.
872 $str = to_utf8
($str);
874 # allow only $len chars, but don't cut a word if it would fit in $add_len
875 # if it doesn't fit, cut it if it's still longer than the dots we would add
876 # remove chopped character entities entirely
878 # when chopping in the middle, distribute $len into left and right part
879 # return early if chopping wouldn't make string shorter
880 if ($where eq 'center') {
881 return $str if ($len + 5 >= length($str)); # filler is length 5
884 return $str if ($len + 4 >= length($str)); # filler is length 4
887 # regexps: ending and beginning with word part up to $add_len
888 my $endre = qr/.{$len}\w{0,$add_len}/;
889 my $begre = qr/\w{0,$add_len}.{$len}/;
891 if ($where eq 'left') {
892 $str =~ m/^(.*?)($begre)$/;
893 my ($lead, $body) = ($1, $2);
894 if (length($lead) > 4) {
895 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
900 } elsif ($where eq 'center') {
901 $str =~ m/^($endre)(.*)$/;
902 my ($left, $str) = ($1, $2);
903 $str =~ m/^(.*?)($begre)$/;
904 my ($mid, $right) = ($1, $2);
905 if (length($mid) > 5) {
906 $left =~ s/&[^;]*$//;
907 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
910 return "$left$mid$right";
913 $str =~ m/^($endre)(.*)$/;
916 if (length($tail) > 4) {
917 $body =~ s/&[^;]*$//;
924 # takes the same arguments as chop_str, but also wraps a <span> around the
925 # result with a title attribute if it does get chopped. Additionally, the
926 # string is HTML-escaped.
927 sub chop_and_escape_str
{
930 my $chopped = chop_str
(@_);
931 if ($chopped eq $str) {
932 return esc_html
($chopped);
934 $str =~ s/([[:cntrl:]])/?/g;
935 return $cgi->span({-title
=>$str}, esc_html
($chopped));
939 ## ----------------------------------------------------------------------
940 ## functions returning short strings
942 # CSS class for given age value (in seconds)
948 } elsif ($age < 60*60*2) {
950 } elsif ($age < 60*60*24*2) {
957 # convert age in seconds to "nn units ago" string
962 if ($age > 60*60*24*365*2) {
963 $age_str = (int $age/60/60/24/365);
964 $age_str .= " years ago";
965 } elsif ($age > 60*60*24*(365/12)*2) {
966 $age_str = int $age/60/60/24/(365/12);
967 $age_str .= " months ago";
968 } elsif ($age > 60*60*24*7*2) {
969 $age_str = int $age/60/60/24/7;
970 $age_str .= " weeks ago";
971 } elsif ($age > 60*60*24*2) {
972 $age_str = int $age/60/60/24;
973 $age_str .= " days ago";
974 } elsif ($age > 60*60*2) {
975 $age_str = int $age/60/60;
976 $age_str .= " hours ago";
977 } elsif ($age > 60*2) {
978 $age_str = int $age/60;
979 $age_str .= " min ago";
982 $age_str .= " sec ago";
984 $age_str .= " right now";
990 S_IFINVALID
=> 0030000,
991 S_IFGITLINK
=> 0160000,
994 # submodule/subproject, a commit object reference
998 return (($mode & S_IFMT
) == S_IFGITLINK
)
1001 # convert file mode in octal to symbolic file mode string
1003 my $mode = oct shift;
1005 if (S_ISGITLINK
($mode)) {
1006 return 'm---------';
1007 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1008 return 'drwxr-xr-x';
1009 } elsif (S_ISLNK
($mode)) {
1010 return 'lrwxrwxrwx';
1011 } elsif (S_ISREG
($mode)) {
1012 # git cares only about the executable bit
1013 if ($mode & S_IXUSR
) {
1014 return '-rwxr-xr-x';
1016 return '-rw-r--r--';
1019 return '----------';
1023 # convert file mode in octal to file type string
1027 if ($mode !~ m/^[0-7]+$/) {
1033 if (S_ISGITLINK
($mode)) {
1035 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1037 } elsif (S_ISLNK
($mode)) {
1039 } elsif (S_ISREG
($mode)) {
1046 # convert file mode in octal to file type description string
1047 sub file_type_long
{
1050 if ($mode !~ m/^[0-7]+$/) {
1056 if (S_ISGITLINK
($mode)) {
1058 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1060 } elsif (S_ISLNK
($mode)) {
1062 } elsif (S_ISREG
($mode)) {
1063 if ($mode & S_IXUSR
) {
1064 return "executable";
1074 ## ----------------------------------------------------------------------
1075 ## functions returning short HTML fragments, or transforming HTML fragments
1076 ## which don't belong to other sections
1078 # format line of commit message.
1079 sub format_log_line_html
{
1082 $line = esc_html
($line, -nbsp
=>1);
1083 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1086 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1087 -class => "text"}, $hash_text);
1088 $line =~ s/$hash_text/$link/;
1093 # format marker of refs pointing to given object
1094 sub format_ref_marker
{
1095 my ($refs, $id) = @_;
1098 if (defined $refs->{$id}) {
1099 foreach my $ref (@{$refs->{$id}}) {
1100 my ($type, $name) = qw();
1101 # e.g. tags/v2.6.11 or heads/next
1102 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1110 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1111 esc_html
($name) . "</span>";
1116 return ' <span class="refs">'. $markers . '</span>';
1122 # format, perhaps shortened and with markers, title line
1123 sub format_subject_html
{
1124 my ($long, $short, $href, $extra) = @_;
1125 $extra = '' unless defined($extra);
1127 if (length($short) < length($long)) {
1128 return $cgi->a({-href
=> $href, -class => "list subject",
1129 -title
=> to_utf8
($long)},
1130 esc_html
($short) . $extra);
1132 return $cgi->a({-href
=> $href, -class => "list subject"},
1133 esc_html
($long) . $extra);
1137 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1138 sub format_git_diff_header_line
{
1140 my $diffinfo = shift;
1141 my ($from, $to) = @_;
1143 if ($diffinfo->{'nparents'}) {
1145 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1146 if ($to->{'href'}) {
1147 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1148 esc_path
($to->{'file'}));
1149 } else { # file was deleted (no href)
1150 $line .= esc_path
($to->{'file'});
1154 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1155 if ($from->{'href'}) {
1156 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1157 'a/' . esc_path
($from->{'file'}));
1158 } else { # file was added (no href)
1159 $line .= 'a/' . esc_path
($from->{'file'});
1162 if ($to->{'href'}) {
1163 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1164 'b/' . esc_path
($to->{'file'}));
1165 } else { # file was deleted
1166 $line .= 'b/' . esc_path
($to->{'file'});
1170 return "<div class=\"diff header\">$line</div>\n";
1173 # format extended diff header line, before patch itself
1174 sub format_extended_diff_header_line
{
1176 my $diffinfo = shift;
1177 my ($from, $to) = @_;
1180 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1181 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1182 esc_path
($from->{'file'}));
1184 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1185 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1186 esc_path
($to->{'file'}));
1188 # match single <mode>
1189 if ($line =~ m/\s(\d{6})$/) {
1190 $line .= '<span class="info"> (' .
1191 file_type_long
($1) .
1195 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1196 # can match only for combined diff
1198 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1199 if ($from->{'href'}[$i]) {
1200 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1202 substr($diffinfo->{'from_id'}[$i],0,7));
1207 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1210 if ($to->{'href'}) {
1211 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1212 substr($diffinfo->{'to_id'},0,7));
1217 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1218 # can match only for ordinary diff
1219 my ($from_link, $to_link);
1220 if ($from->{'href'}) {
1221 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1222 substr($diffinfo->{'from_id'},0,7));
1224 $from_link = '0' x
7;
1226 if ($to->{'href'}) {
1227 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1228 substr($diffinfo->{'to_id'},0,7));
1232 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1233 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1236 return $line . "<br/>\n";
1239 # format from-file/to-file diff header
1240 sub format_diff_from_to_header
{
1241 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1246 #assert($line =~ m/^---/) if DEBUG;
1247 # no extra formatting for "^--- /dev/null"
1248 if (! $diffinfo->{'nparents'}) {
1249 # ordinary (single parent) diff
1250 if ($line =~ m!^--- "?a/!) {
1251 if ($from->{'href'}) {
1253 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1254 esc_path
($from->{'file'}));
1257 esc_path
($from->{'file'});
1260 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1263 # combined diff (merge commit)
1264 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1265 if ($from->{'href'}[$i]) {
1267 $cgi->a({-href
=>href
(action
=>"blobdiff",
1268 hash_parent
=>$diffinfo->{'from_id'}[$i],
1269 hash_parent_base
=>$parents[$i],
1270 file_parent
=>$from->{'file'}[$i],
1271 hash
=>$diffinfo->{'to_id'},
1273 file_name
=>$to->{'file'}),
1275 -title
=>"diff" . ($i+1)},
1278 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1279 esc_path
($from->{'file'}[$i]));
1281 $line = '--- /dev/null';
1283 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1288 #assert($line =~ m/^\+\+\+/) if DEBUG;
1289 # no extra formatting for "^+++ /dev/null"
1290 if ($line =~ m!^\+\+\+ "?b/!) {
1291 if ($to->{'href'}) {
1293 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1294 esc_path
($to->{'file'}));
1297 esc_path
($to->{'file'});
1300 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1305 # create note for patch simplified by combined diff
1306 sub format_diff_cc_simplified
{
1307 my ($diffinfo, @parents) = @_;
1310 $result .= "<div class=\"diff header\">" .
1312 if (!is_deleted
($diffinfo)) {
1313 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1315 hash
=>$diffinfo->{'to_id'},
1316 file_name
=>$diffinfo->{'to_file'}),
1318 esc_path
($diffinfo->{'to_file'}));
1320 $result .= esc_path
($diffinfo->{'to_file'});
1322 $result .= "</div>\n" . # class="diff header"
1323 "<div class=\"diff nodifferences\">" .
1325 "</div>\n"; # class="diff nodifferences"
1330 # format patch (diff) line (not to be used for diff headers)
1331 sub format_diff_line
{
1333 my ($from, $to) = @_;
1334 my $diff_class = "";
1338 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1340 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1341 if ($line =~ m/^\@{3}/) {
1342 $diff_class = " chunk_header";
1343 } elsif ($line =~ m/^\\/) {
1344 $diff_class = " incomplete";
1345 } elsif ($prefix =~ tr/+/+/) {
1346 $diff_class = " add";
1347 } elsif ($prefix =~ tr/-/-/) {
1348 $diff_class = " rem";
1351 # assume ordinary diff
1352 my $char = substr($line, 0, 1);
1354 $diff_class = " add";
1355 } elsif ($char eq '-') {
1356 $diff_class = " rem";
1357 } elsif ($char eq '@') {
1358 $diff_class = " chunk_header";
1359 } elsif ($char eq "\\") {
1360 $diff_class = " incomplete";
1363 $line = untabify
($line);
1364 if ($from && $to && $line =~ m/^\@{2} /) {
1365 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1366 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1368 $from_lines = 0 unless defined $from_lines;
1369 $to_lines = 0 unless defined $to_lines;
1371 if ($from->{'href'}) {
1372 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1373 -class=>"list"}, $from_text);
1375 if ($to->{'href'}) {
1376 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1377 -class=>"list"}, $to_text);
1379 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1380 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1381 return "<div class=\"diff$diff_class\">$line</div>\n";
1382 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1383 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1384 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1386 @from_text = split(' ', $ranges);
1387 for (my $i = 0; $i < @from_text; ++$i) {
1388 ($from_start[$i], $from_nlines[$i]) =
1389 (split(',', substr($from_text[$i], 1)), 0);
1392 $to_text = pop @from_text;
1393 $to_start = pop @from_start;
1394 $to_nlines = pop @from_nlines;
1396 $line = "<span class=\"chunk_info\">$prefix ";
1397 for (my $i = 0; $i < @from_text; ++$i) {
1398 if ($from->{'href'}[$i]) {
1399 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1400 -class=>"list"}, $from_text[$i]);
1402 $line .= $from_text[$i];
1406 if ($to->{'href'}) {
1407 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1408 -class=>"list"}, $to_text);
1412 $line .= " $prefix</span>" .
1413 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1414 return "<div class=\"diff$diff_class\">$line</div>\n";
1416 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1419 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1420 # linked. Pass the hash of the tree/commit to snapshot.
1421 sub format_snapshot_links
{
1423 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1424 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1425 my $num_fmts = @snapshot_fmts;
1426 if ($num_fmts > 1) {
1427 # A parenthesized list of links bearing format names.
1428 # e.g. "snapshot (_tar.gz_ _zip_)"
1429 return "snapshot (" . join(' ', map
1436 }, $known_snapshot_formats{$_}{'display'})
1437 , @snapshot_fmts) . ")";
1438 } elsif ($num_fmts == 1) {
1439 # A single "snapshot" link whose tooltip bears the format name.
1441 my ($fmt) = @snapshot_fmts;
1447 snapshot_format
=>$fmt
1449 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1451 } else { # $num_fmts == 0
1456 ## ......................................................................
1457 ## functions returning values to be passed, perhaps after some
1458 ## transformation, to other functions; e.g. returning arguments to href()
1460 # returns hash to be passed to href to generate gitweb URL
1461 # in -title key it returns description of link
1463 my $format = shift || 'Atom';
1464 my %res = (action
=> lc($format));
1466 # feed links are possible only for project views
1467 return unless (defined $project);
1468 # some views should link to OPML, or to generic project feed,
1469 # or don't have specific feed yet (so they should use generic)
1470 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1473 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1474 # from tag links; this also makes possible to detect branch links
1475 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1476 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1479 # find log type for feed description (title)
1481 if (defined $file_name) {
1482 $type = "history of $file_name";
1483 $type .= "/" if ($action eq 'tree');
1484 $type .= " on '$branch'" if (defined $branch);
1486 $type = "log of $branch" if (defined $branch);
1489 $res{-title
} = $type;
1490 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1491 $res{'file_name'} = $file_name;
1496 ## ----------------------------------------------------------------------
1497 ## git utility subroutines, invoking git commands
1499 # returns path to the core git executable and the --git-dir parameter as list
1501 return $GIT, '--git-dir='.$git_dir;
1504 # quote the given arguments for passing them to the shell
1505 # quote_command("command", "arg 1", "arg with ' and ! characters")
1506 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1507 # Try to avoid using this function wherever possible.
1510 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1513 # get HEAD ref of given project as hash
1514 sub git_get_head_hash
{
1515 my $project = shift;
1516 my $o_git_dir = $git_dir;
1518 $git_dir = "$projectroot/$project";
1519 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1522 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1526 if (defined $o_git_dir) {
1527 $git_dir = $o_git_dir;
1532 # get type of given object
1536 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1538 close $fd or return;
1543 # repository configuration
1544 our $config_file = '';
1547 # store multiple values for single key as anonymous array reference
1548 # single values stored directly in the hash, not as [ <value> ]
1549 sub hash_set_multi
{
1550 my ($hash, $key, $value) = @_;
1552 if (!exists $hash->{$key}) {
1553 $hash->{$key} = $value;
1554 } elsif (!ref $hash->{$key}) {
1555 $hash->{$key} = [ $hash->{$key}, $value ];
1557 push @{$hash->{$key}}, $value;
1561 # return hash of git project configuration
1562 # optionally limited to some section, e.g. 'gitweb'
1563 sub git_parse_project_config
{
1564 my $section_regexp = shift;
1569 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1572 while (my $keyval = <$fh>) {
1574 my ($key, $value) = split(/\n/, $keyval, 2);
1576 hash_set_multi
(\
%config, $key, $value)
1577 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1584 # convert config value to boolean, 'true' or 'false'
1585 # no value, number > 0, 'true' and 'yes' values are true
1586 # rest of values are treated as false (never as error)
1587 sub config_to_bool
{
1590 # strip leading and trailing whitespace
1594 return (!defined $val || # section.key
1595 ($val =~ /^\d+$/ && $val) || # section.key = 1
1596 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1599 # convert config value to simple decimal number
1600 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1601 # to be multiplied by 1024, 1048576, or 1073741824
1605 # strip leading and trailing whitespace
1609 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1611 # unknown unit is treated as 1
1612 return $num * ($unit eq 'g' ? 1073741824 :
1613 $unit eq 'm' ? 1048576 :
1614 $unit eq 'k' ? 1024 : 1);
1619 # convert config value to array reference, if needed
1620 sub config_to_multi
{
1623 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1626 sub git_get_project_config
{
1627 my ($key, $type) = @_;
1630 return unless ($key);
1631 $key =~ s/^gitweb\.//;
1632 return if ($key =~ m/\W/);
1635 if (defined $type) {
1638 unless ($type eq 'bool' || $type eq 'int');
1642 if (!defined $config_file ||
1643 $config_file ne "$git_dir/config") {
1644 %config = git_parse_project_config
('gitweb');
1645 $config_file = "$git_dir/config";
1649 if (!defined $type) {
1650 return $config{"gitweb.$key"};
1651 } elsif ($type eq 'bool') {
1652 # backward compatibility: 'git config --bool' returns true/false
1653 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1654 } elsif ($type eq 'int') {
1655 return config_to_int
($config{"gitweb.$key"});
1657 return $config{"gitweb.$key"};
1660 # get hash of given path at given ref
1661 sub git_get_hash_by_path
{
1663 my $path = shift || return undef;
1668 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1669 or die_error
(undef, "Open git-ls-tree failed");
1671 close $fd or return undef;
1673 if (!defined $line) {
1674 # there is no tree or hash given by $path at $base
1678 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1679 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1680 if (defined $type && $type ne $2) {
1681 # type doesn't match
1687 # get path of entry with given hash at given tree-ish (ref)
1688 # used to get 'from' filename for combined diff (merge commit) for renames
1689 sub git_get_path_by_hash
{
1690 my $base = shift || return;
1691 my $hash = shift || return;
1695 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1697 while (my $line = <$fd>) {
1700 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1701 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1702 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1711 ## ......................................................................
1712 ## git utility functions, directly accessing git repository
1714 sub git_get_project_description
{
1717 $git_dir = "$projectroot/$path";
1718 open my $fd, "$git_dir/description"
1719 or return git_get_project_config
('description');
1722 if (defined $descr) {
1728 sub git_get_project_url_list
{
1731 $git_dir = "$projectroot/$path";
1732 open my $fd, "$git_dir/cloneurl"
1733 or return wantarray ?
1734 @{ config_to_multi
(git_get_project_config
('url')) } :
1735 config_to_multi
(git_get_project_config
('url'));
1736 my @git_project_url_list = map { chomp; $_ } <$fd>;
1739 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1742 sub git_get_projects_list
{
1747 $filter =~ s/\.git$//;
1749 my ($check_forks) = gitweb_check_feature
('forks');
1751 if (-d
$projects_list) {
1752 # search in directory
1753 my $dir = $projects_list . ($filter ? "/$filter" : '');
1754 # remove the trailing "/"
1756 my $pfxlen = length("$dir");
1757 my $pfxdepth = ($dir =~ tr!/!!);
1760 follow_fast
=> 1, # follow symbolic links
1761 follow_skip
=> 2, # ignore duplicates
1762 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1764 # skip project-list toplevel, if we get it.
1765 return if (m!^[/.]$!);
1766 # only directories can be git repositories
1767 return unless (-d
$_);
1768 # don't traverse too deep (Find is super slow on os x)
1769 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1770 $File::Find
::prune
= 1;
1774 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1775 # we check related file in $projectroot
1776 if ($check_forks and $subdir =~ m
#/.#) {
1777 $File::Find
::prune
= 1;
1778 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1779 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1780 $File::Find
::prune
= 1;
1785 } elsif (-f
$projects_list) {
1786 # read from file(url-encoded):
1787 # 'git%2Fgit.git Linus+Torvalds'
1788 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1789 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1791 open my ($fd), $projects_list or return;
1793 while (my $line = <$fd>) {
1795 my ($path, $owner) = split ' ', $line;
1796 $path = unescape
($path);
1797 $owner = unescape
($owner);
1798 if (!defined $path) {
1801 if ($filter ne '') {
1802 # looking for forks;
1803 my $pfx = substr($path, 0, length($filter));
1804 if ($pfx ne $filter) {
1807 my $sfx = substr($path, length($filter));
1808 if ($sfx !~ /^\/.*\
.git
$/) {
1811 } elsif ($check_forks) {
1813 foreach my $filter (keys %paths) {
1814 # looking for forks;
1815 my $pfx = substr($path, 0, length($filter));
1816 if ($pfx ne $filter) {
1819 my $sfx = substr($path, length($filter));
1820 if ($sfx !~ /^\/.*\
.git
$/) {
1823 # is a fork, don't include it in
1828 if (check_export_ok
("$projectroot/$path")) {
1831 owner
=> to_utf8
($owner),
1834 (my $forks_path = $path) =~ s/\.git$//;
1835 $paths{$forks_path}++;
1843 our $gitweb_project_owner = undef;
1844 sub git_get_project_list_from_file
{
1846 return if (defined $gitweb_project_owner);
1848 $gitweb_project_owner = {};
1849 # read from file (url-encoded):
1850 # 'git%2Fgit.git Linus+Torvalds'
1851 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1852 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1853 if (-f
$projects_list) {
1854 open (my $fd , $projects_list);
1855 while (my $line = <$fd>) {
1857 my ($pr, $ow) = split ' ', $line;
1858 $pr = unescape
($pr);
1859 $ow = unescape
($ow);
1860 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1866 sub git_get_project_owner
{
1867 my $project = shift;
1870 return undef unless $project;
1871 $git_dir = "$projectroot/$project";
1873 if (!defined $gitweb_project_owner) {
1874 git_get_project_list_from_file
();
1877 if (exists $gitweb_project_owner->{$project}) {
1878 $owner = $gitweb_project_owner->{$project};
1880 if (!defined $owner){
1881 $owner = git_get_project_config
('owner');
1883 if (!defined $owner) {
1884 $owner = get_file_owner
("$git_dir");
1890 sub git_get_last_activity
{
1894 $git_dir = "$projectroot/$path";
1895 open($fd, "-|", git_cmd
(), 'for-each-ref',
1896 '--format=%(committer)',
1897 '--sort=-committerdate',
1899 'refs/heads') or return;
1900 my $most_recent = <$fd>;
1901 close $fd or return;
1902 if (defined $most_recent &&
1903 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1905 my $age = time - $timestamp;
1906 return ($age, age_string
($age));
1908 return (undef, undef);
1911 sub git_get_references
{
1912 my $type = shift || "";
1914 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1915 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1916 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1917 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1920 while (my $line = <$fd>) {
1922 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1923 if (defined $refs{$1}) {
1924 push @{$refs{$1}}, $2;
1930 close $fd or return;
1934 sub git_get_rev_name_tags
{
1935 my $hash = shift || return undef;
1937 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1939 my $name_rev = <$fd>;
1942 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1945 # catches also '$hash undefined' output
1950 ## ----------------------------------------------------------------------
1951 ## parse to hash functions
1955 my $tz = shift || "-0000";
1958 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1959 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1960 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1961 $date{'hour'} = $hour;
1962 $date{'minute'} = $min;
1963 $date{'mday'} = $mday;
1964 $date{'day'} = $days[$wday];
1965 $date{'month'} = $months[$mon];
1966 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1967 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1968 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1969 $mday, $months[$mon], $hour ,$min;
1970 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1971 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1973 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1974 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1975 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1976 $date{'hour_local'} = $hour;
1977 $date{'minute_local'} = $min;
1978 $date{'tz_local'} = $tz;
1979 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1980 1900+$year, $mon+1, $mday,
1981 $hour, $min, $sec, $tz);
1990 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1991 $tag{'id'} = $tag_id;
1992 while (my $line = <$fd>) {
1994 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1995 $tag{'object'} = $1;
1996 } elsif ($line =~ m/^type (.+)$/) {
1998 } elsif ($line =~ m/^tag (.+)$/) {
2000 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2001 $tag{'author'} = $1;
2004 } elsif ($line =~ m/--BEGIN/) {
2005 push @comment, $line;
2007 } elsif ($line eq "") {
2011 push @comment, <$fd>;
2012 $tag{'comment'} = \
@comment;
2013 close $fd or return;
2014 if (!defined $tag{'name'}) {
2020 sub parse_commit_text
{
2021 my ($commit_text, $withparents) = @_;
2022 my @commit_lines = split '\n', $commit_text;
2025 pop @commit_lines; # Remove '\0'
2027 if (! @commit_lines) {
2031 my $header = shift @commit_lines;
2032 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2035 ($co{'id'}, my @parents) = split ' ', $header;
2036 while (my $line = shift @commit_lines) {
2037 last if $line eq "\n";
2038 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2040 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2042 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2044 $co{'author_epoch'} = $2;
2045 $co{'author_tz'} = $3;
2046 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2047 $co{'author_name'} = $1;
2048 $co{'author_email'} = $2;
2050 $co{'author_name'} = $co{'author'};
2052 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2053 $co{'committer'} = $1;
2054 $co{'committer_epoch'} = $2;
2055 $co{'committer_tz'} = $3;
2056 $co{'committer_name'} = $co{'committer'};
2057 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2058 $co{'committer_name'} = $1;
2059 $co{'committer_email'} = $2;
2061 $co{'committer_name'} = $co{'committer'};
2065 if (!defined $co{'tree'}) {
2068 $co{'parents'} = \
@parents;
2069 $co{'parent'} = $parents[0];
2071 foreach my $title (@commit_lines) {
2074 $co{'title'} = chop_str
($title, 80, 5);
2075 # remove leading stuff of merges to make the interesting part visible
2076 if (length($title) > 50) {
2077 $title =~ s/^Automatic //;
2078 $title =~ s/^merge (of|with) /Merge ... /i;
2079 if (length($title) > 50) {
2080 $title =~ s/(http|rsync):\/\///;
2082 if (length($title) > 50) {
2083 $title =~ s/(master|www|rsync)\.//;
2085 if (length($title) > 50) {
2086 $title =~ s/kernel.org:?//;
2088 if (length($title) > 50) {
2089 $title =~ s/\/pub\/scm//;
2092 $co{'title_short'} = chop_str
($title, 50, 5);
2096 if ($co{'title'} eq "") {
2097 $co{'title'} = $co{'title_short'} = '(no commit message)';
2099 # remove added spaces
2100 foreach my $line (@commit_lines) {
2103 $co{'comment'} = \
@commit_lines;
2105 my $age = time - $co{'committer_epoch'};
2107 $co{'age_string'} = age_string
($age);
2108 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2109 if ($age > 60*60*24*7*2) {
2110 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2111 $co{'age_string_age'} = $co{'age_string'};
2113 $co{'age_string_date'} = $co{'age_string'};
2114 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2120 my ($commit_id) = @_;
2125 open my $fd, "-|", git_cmd
(), "rev-list",
2131 or die_error
(undef, "Open git-rev-list failed");
2132 %co = parse_commit_text
(<$fd>, 1);
2139 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2147 open my $fd, "-|", git_cmd
(), "rev-list",
2150 ("--max-count=" . $maxcount),
2151 ("--skip=" . $skip),
2155 ($filename ? ($filename) : ())
2156 or die_error
(undef, "Open git-rev-list failed");
2157 while (my $line = <$fd>) {
2158 my %co = parse_commit_text
($line);
2163 return wantarray ? @cos : \
@cos;
2166 # parse line of git-diff-tree "raw" output
2167 sub parse_difftree_raw_line
{
2171 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2172 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2173 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2174 $res{'from_mode'} = $1;
2175 $res{'to_mode'} = $2;
2176 $res{'from_id'} = $3;
2178 $res{'status'} = $5;
2179 $res{'similarity'} = $6;
2180 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2181 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2183 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2186 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2187 # combined diff (for merge commit)
2188 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2189 $res{'nparents'} = length($1);
2190 $res{'from_mode'} = [ split(' ', $2) ];
2191 $res{'to_mode'} = pop @{$res{'from_mode'}};
2192 $res{'from_id'} = [ split(' ', $3) ];
2193 $res{'to_id'} = pop @{$res{'from_id'}};
2194 $res{'status'} = [ split('', $4) ];
2195 $res{'to_file'} = unquote
($5);
2197 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2198 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2199 $res{'commit'} = $1;
2202 return wantarray ? %res : \
%res;
2205 # wrapper: return parsed line of git-diff-tree "raw" output
2206 # (the argument might be raw line, or parsed info)
2207 sub parsed_difftree_line
{
2208 my $line_or_ref = shift;
2210 if (ref($line_or_ref) eq "HASH") {
2211 # pre-parsed (or generated by hand)
2212 return $line_or_ref;
2214 return parse_difftree_raw_line
($line_or_ref);
2218 # parse line of git-ls-tree output
2219 sub parse_ls_tree_line
($;%) {
2224 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2225 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2233 $res{'name'} = unquote
($4);
2236 return wantarray ? %res : \
%res;
2239 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2240 sub parse_from_to_diffinfo
{
2241 my ($diffinfo, $from, $to, @parents) = @_;
2243 if ($diffinfo->{'nparents'}) {
2245 $from->{'file'} = [];
2246 $from->{'href'} = [];
2247 fill_from_file_info
($diffinfo, @parents)
2248 unless exists $diffinfo->{'from_file'};
2249 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2250 $from->{'file'}[$i] =
2251 defined $diffinfo->{'from_file'}[$i] ?
2252 $diffinfo->{'from_file'}[$i] :
2253 $diffinfo->{'to_file'};
2254 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2255 $from->{'href'}[$i] = href
(action
=>"blob",
2256 hash_base
=>$parents[$i],
2257 hash
=>$diffinfo->{'from_id'}[$i],
2258 file_name
=>$from->{'file'}[$i]);
2260 $from->{'href'}[$i] = undef;
2264 # ordinary (not combined) diff
2265 $from->{'file'} = $diffinfo->{'from_file'};
2266 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2267 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2268 hash
=>$diffinfo->{'from_id'},
2269 file_name
=>$from->{'file'});
2271 delete $from->{'href'};
2275 $to->{'file'} = $diffinfo->{'to_file'};
2276 if (!is_deleted
($diffinfo)) { # file exists in result
2277 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2278 hash
=>$diffinfo->{'to_id'},
2279 file_name
=>$to->{'file'});
2281 delete $to->{'href'};
2285 ## ......................................................................
2286 ## parse to array of hashes functions
2288 sub git_get_heads_list
{
2292 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2293 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2294 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2297 while (my $line = <$fd>) {
2301 my ($refinfo, $committerinfo) = split(/\0/, $line);
2302 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2303 my ($committer, $epoch, $tz) =
2304 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2305 $ref_item{'fullname'} = $name;
2306 $name =~ s!^refs/heads/!!;
2308 $ref_item{'name'} = $name;
2309 $ref_item{'id'} = $hash;
2310 $ref_item{'title'} = $title || '(no commit message)';
2311 $ref_item{'epoch'} = $epoch;
2313 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2315 $ref_item{'age'} = "unknown";
2318 push @headslist, \
%ref_item;
2322 return wantarray ? @headslist : \
@headslist;
2325 sub git_get_tags_list
{
2329 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2330 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2331 '--format=%(objectname) %(objecttype) %(refname) '.
2332 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2335 while (my $line = <$fd>) {
2339 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2340 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2341 my ($creator, $epoch, $tz) =
2342 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2343 $ref_item{'fullname'} = $name;
2344 $name =~ s!^refs/tags/!!;
2346 $ref_item{'type'} = $type;
2347 $ref_item{'id'} = $id;
2348 $ref_item{'name'} = $name;
2349 if ($type eq "tag") {
2350 $ref_item{'subject'} = $title;
2351 $ref_item{'reftype'} = $reftype;
2352 $ref_item{'refid'} = $refid;
2354 $ref_item{'reftype'} = $type;
2355 $ref_item{'refid'} = $id;
2358 if ($type eq "tag" || $type eq "commit") {
2359 $ref_item{'epoch'} = $epoch;
2361 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2363 $ref_item{'age'} = "unknown";
2367 push @tagslist, \
%ref_item;
2371 return wantarray ? @tagslist : \
@tagslist;
2374 ## ----------------------------------------------------------------------
2375 ## filesystem-related functions
2377 sub get_file_owner
{
2380 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2381 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2382 if (!defined $gcos) {
2386 $owner =~ s/[,;].*$//;
2387 return to_utf8
($owner);
2390 ## ......................................................................
2391 ## mimetype related functions
2393 sub mimetype_guess_file
{
2394 my $filename = shift;
2395 my $mimemap = shift;
2396 -r
$mimemap or return undef;
2399 open(MIME
, $mimemap) or return undef;
2401 next if m/^#/; # skip comments
2402 my ($mime, $exts) = split(/\t+/);
2403 if (defined $exts) {
2404 my @exts = split(/\s+/, $exts);
2405 foreach my $ext (@exts) {
2406 $mimemap{$ext} = $mime;
2412 $filename =~ /\.([^.]*)$/;
2413 return $mimemap{$1};
2416 sub mimetype_guess
{
2417 my $filename = shift;
2419 $filename =~ /\./ or return undef;
2421 if ($mimetypes_file) {
2422 my $file = $mimetypes_file;
2423 if ($file !~ m!^/!) { # if it is relative path
2424 # it is relative to project
2425 $file = "$projectroot/$project/$file";
2427 $mime = mimetype_guess_file
($filename, $file);
2429 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2435 my $filename = shift;
2438 my $mime = mimetype_guess
($filename);
2439 $mime and return $mime;
2443 return $default_blob_plain_mimetype unless $fd;
2446 return 'text/plain';
2447 } elsif (! $filename) {
2448 return 'application/octet-stream';
2449 } elsif ($filename =~ m/\.png$/i) {
2451 } elsif ($filename =~ m/\.gif$/i) {
2453 } elsif ($filename =~ m/\.jpe?g$/i) {
2454 return 'image/jpeg';
2456 return 'application/octet-stream';
2460 sub blob_contenttype
{
2461 my ($fd, $file_name, $type) = @_;
2463 $type ||= blob_mimetype
($fd, $file_name);
2464 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2465 $type .= "; charset=$default_text_plain_charset";
2471 ## ======================================================================
2472 ## functions printing HTML: header, footer, error page
2474 sub git_header_html
{
2475 my $status = shift || "200 OK";
2476 my $expires = shift;
2478 my $title = "$site_name";
2479 if (defined $project) {
2480 $title .= " - " . to_utf8
($project);
2481 if (defined $action) {
2482 $title .= "/$action";
2483 if (defined $file_name) {
2484 $title .= " - " . esc_path
($file_name);
2485 if ($action eq "tree" && $file_name !~ m
|/$|) {
2492 # require explicit support from the UA if we are to send the page as
2493 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2494 # we have to do this because MSIE sometimes globs '*/*', pretending to
2495 # support xhtml+xml but choking when it gets what it asked for.
2496 if (defined $cgi->http('HTTP_ACCEPT') &&
2497 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2498 $cgi->Accept('application/xhtml+xml') != 0) {
2499 $content_type = 'application/xhtml+xml';
2501 $content_type = 'text/html';
2503 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2504 -status
=> $status, -expires
=> $expires);
2505 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2507 <?xml version="1.0" encoding="utf-8"?>
2508 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2509 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2510 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2511 <!-- git core binaries version $git_version -->
2513 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2514 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2515 <meta name="robots" content="index, nofollow"/>
2516 <title>$title</title>
2518 # print out each stylesheet that exist
2519 if (defined $stylesheet) {
2520 #provides backwards capability for those people who define style sheet in a config file
2521 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2523 foreach my $stylesheet (@stylesheets) {
2524 next unless $stylesheet;
2525 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2528 if (defined $project) {
2529 my %href_params = get_feed_info
();
2530 if (!exists $href_params{'-title'}) {
2531 $href_params{'-title'} = 'log';
2534 foreach my $format qw(RSS Atom) {
2535 my $type = lc($format);
2537 '-rel' => 'alternate',
2538 '-title' => "$project - $href_params{'-title'} - $format feed",
2539 '-type' => "application/$type+xml"
2542 $href_params{'action'} = $type;
2543 $link_attr{'-href'} = href
(%href_params);
2545 "rel=\"$link_attr{'-rel'}\" ".
2546 "title=\"$link_attr{'-title'}\" ".
2547 "href=\"$link_attr{'-href'}\" ".
2548 "type=\"$link_attr{'-type'}\" ".
2551 $href_params{'extra_options'} = '--no-merges';
2552 $link_attr{'-href'} = href
(%href_params);
2553 $link_attr{'-title'} .= ' (no merges)';
2555 "rel=\"$link_attr{'-rel'}\" ".
2556 "title=\"$link_attr{'-title'}\" ".
2557 "href=\"$link_attr{'-href'}\" ".
2558 "type=\"$link_attr{'-type'}\" ".
2563 printf('<link rel="alternate" title="%s projects list" '.
2564 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2565 $site_name, href
(project
=>undef, action
=>"project_index"));
2566 printf('<link rel="alternate" title="%s projects feeds" '.
2567 'href="%s" type="text/x-opml" />'."\n",
2568 $site_name, href
(project
=>undef, action
=>"opml"));
2570 if (defined $favicon) {
2571 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2577 if (-f
$site_header) {
2578 open (my $fd, $site_header);
2583 print "<div class=\"page_header\">\n" .
2584 $cgi->a({-href
=> esc_url
($logo_url),
2585 -title
=> $logo_label},
2586 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2587 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2588 if (defined $project) {
2589 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2590 if (defined $action) {
2597 my ($have_search) = gitweb_check_feature
('search');
2598 if (defined $project && $have_search) {
2599 if (!defined $searchtext) {
2603 if (defined $hash_base) {
2604 $search_hash = $hash_base;
2605 } elsif (defined $hash) {
2606 $search_hash = $hash;
2608 $search_hash = "HEAD";
2610 my $action = $my_uri;
2611 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2612 if ($use_pathinfo) {
2613 $action .= "/".esc_url
($project);
2615 print $cgi->startform(-method => "get", -action
=> $action) .
2616 "<div class=\"search\">\n" .
2618 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2619 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2620 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2621 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2622 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2623 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2625 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2626 "<span title=\"Extended regular expression\">" .
2627 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2628 -checked
=> $search_use_regexp) .
2631 $cgi->end_form() . "\n";
2635 sub git_footer_html
{
2636 my $feed_class = 'rss_logo';
2638 print "<div class=\"page_footer\">\n";
2639 if (defined $project) {
2640 my $descr = git_get_project_description
($project);
2641 if (defined $descr) {
2642 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2645 my %href_params = get_feed_info
();
2646 if (!%href_params) {
2647 $feed_class .= ' generic';
2649 $href_params{'-title'} ||= 'log';
2651 foreach my $format qw(RSS Atom) {
2652 $href_params{'action'} = lc($format);
2653 print $cgi->a({-href
=> href
(%href_params),
2654 -title
=> "$href_params{'-title'} $format feed",
2655 -class => $feed_class}, $format)."\n";
2659 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2660 -class => $feed_class}, "OPML") . " ";
2661 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2662 -class => $feed_class}, "TXT") . "\n";
2664 print "</div>\n"; # class="page_footer"
2666 if (-f
$site_footer) {
2667 open (my $fd, $site_footer);
2677 my $status = shift || "403 Forbidden";
2678 my $error = shift || "Malformed query, file missing or permission denied";
2680 git_header_html
($status);
2682 <div class="page_body">
2692 ## ----------------------------------------------------------------------
2693 ## functions printing or outputting HTML: navigation
2695 sub git_print_page_nav
{
2696 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2697 $extra = '' if !defined $extra; # pager or formats
2699 my @navs = qw(summary shortlog log commit commitdiff tree);
2701 @navs = grep { $_ ne $suppress } @navs;
2704 my %arg = map { $_ => {action
=>$_} } @navs;
2705 if (defined $head) {
2706 for (qw(commit commitdiff)) {
2707 $arg{$_}{'hash'} = $head;
2709 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2710 for (qw(shortlog log)) {
2711 $arg{$_}{'hash'} = $head;
2715 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2716 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2718 print "<div class=\"page_nav\">\n" .
2720 map { $_ eq $current ?
2721 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2723 print "<br/>\n$extra<br/>\n" .
2727 sub format_paging_nav
{
2728 my ($action, $hash, $head, $page, $has_next_link) = @_;
2732 if ($hash ne $head || $page) {
2733 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2735 $paging_nav .= "HEAD";
2739 $paging_nav .= " ⋅ " .
2740 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2741 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2743 $paging_nav .= " ⋅ prev";
2746 if ($has_next_link) {
2747 $paging_nav .= " ⋅ " .
2748 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2749 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2751 $paging_nav .= " ⋅ next";
2757 ## ......................................................................
2758 ## functions printing or outputting HTML: div
2760 sub git_print_header_div
{
2761 my ($action, $title, $hash, $hash_base) = @_;
2764 $args{'action'} = $action;
2765 $args{'hash'} = $hash if $hash;
2766 $args{'hash_base'} = $hash_base if $hash_base;
2768 print "<div class=\"header\">\n" .
2769 $cgi->a({-href
=> href
(%args), -class => "title"},
2770 $title ? $title : $action) .
2774 #sub git_print_authorship (\%) {
2775 sub git_print_authorship
{
2778 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2779 print "<div class=\"author_date\">" .
2780 esc_html
($co->{'author_name'}) .
2782 if ($ad{'hour_local'} < 6) {
2783 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2784 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2786 printf(" (%02d:%02d %s)",
2787 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2792 sub git_print_page_path
{
2798 print "<div class=\"page_path\">";
2799 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2800 -title
=> 'tree root'}, to_utf8
("[$project]"));
2802 if (defined $name) {
2803 my @dirname = split '/', $name;
2804 my $basename = pop @dirname;
2807 foreach my $dir (@dirname) {
2808 $fullname .= ($fullname ? '/' : '') . $dir;
2809 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2811 -title
=> $fullname}, esc_path
($dir));
2814 if (defined $type && $type eq 'blob') {
2815 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2817 -title
=> $name}, esc_path
($basename));
2818 } elsif (defined $type && $type eq 'tree') {
2819 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2821 -title
=> $name}, esc_path
($basename));
2824 print esc_path
($basename);
2827 print "<br/></div>\n";
2830 # sub git_print_log (\@;%) {
2831 sub git_print_log
($;%) {
2835 if ($opts{'-remove_title'}) {
2836 # remove title, i.e. first line of log
2839 # remove leading empty lines
2840 while (defined $log->[0] && $log->[0] eq "") {
2847 foreach my $line (@$log) {
2848 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2851 if (! $opts{'-remove_signoff'}) {
2852 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2855 # remove signoff lines
2862 # print only one empty line
2863 # do not print empty line after signoff
2865 next if ($empty || $signoff);
2871 print format_log_line_html
($line) . "<br/>\n";
2874 if ($opts{'-final_empty_line'}) {
2875 # end with single empty line
2876 print "<br/>\n" unless $empty;
2880 # return link target (what link points to)
2881 sub git_get_link_target
{
2886 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2890 $link_target = <$fd>;
2895 return $link_target;
2898 # given link target, and the directory (basedir) the link is in,
2899 # return target of link relative to top directory (top tree);
2900 # return undef if it is not possible (including absolute links).
2901 sub normalize_link_target
{
2902 my ($link_target, $basedir, $hash_base) = @_;
2904 # we can normalize symlink target only if $hash_base is provided
2905 return unless $hash_base;
2907 # absolute symlinks (beginning with '/') cannot be normalized
2908 return if (substr($link_target, 0, 1) eq '/');
2910 # normalize link target to path from top (root) tree (dir)
2913 $path = $basedir . '/' . $link_target;
2915 # we are in top (root) tree (dir)
2916 $path = $link_target;
2919 # remove //, /./, and /../
2921 foreach my $part (split('/', $path)) {
2922 # discard '.' and ''
2923 next if (!$part || $part eq '.');
2925 if ($part eq '..') {
2929 # link leads outside repository (outside top dir)
2933 push @path_parts, $part;
2936 $path = join('/', @path_parts);
2941 # print tree entry (row of git_tree), but without encompassing <tr> element
2942 sub git_print_tree_entry
{
2943 my ($t, $basedir, $hash_base, $have_blame) = @_;
2946 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2948 # The format of a table row is: mode list link. Where mode is
2949 # the mode of the entry, list is the name of the entry, an href,
2950 # and link is the action links of the entry.
2952 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2953 if ($t->{'type'} eq "blob") {
2954 print "<td class=\"list\">" .
2955 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2956 file_name
=>"$basedir$t->{'name'}", %base_key),
2957 -class => "list"}, esc_path
($t->{'name'}));
2958 if (S_ISLNK
(oct $t->{'mode'})) {
2959 my $link_target = git_get_link_target
($t->{'hash'});
2961 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2962 if (defined $norm_target) {
2964 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2965 file_name
=>$norm_target),
2966 -title
=> $norm_target}, esc_path
($link_target));
2968 print " -> " . esc_path
($link_target);
2973 print "<td class=\"link\">";
2974 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2975 file_name
=>"$basedir$t->{'name'}", %base_key)},
2979 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2980 file_name
=>"$basedir$t->{'name'}", %base_key)},
2983 if (defined $hash_base) {
2985 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2986 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2990 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2991 file_name
=>"$basedir$t->{'name'}")},
2995 } elsif ($t->{'type'} eq "tree") {
2996 print "<td class=\"list\">";
2997 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2998 file_name
=>"$basedir$t->{'name'}", %base_key)},
2999 esc_path
($t->{'name'}));
3001 print "<td class=\"link\">";
3002 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3003 file_name
=>"$basedir$t->{'name'}", %base_key)},
3005 if (defined $hash_base) {
3007 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3008 file_name
=>"$basedir$t->{'name'}")},
3013 # unknown object: we can only present history for it
3014 # (this includes 'commit' object, i.e. submodule support)
3015 print "<td class=\"list\">" .
3016 esc_path
($t->{'name'}) .
3018 print "<td class=\"link\">";
3019 if (defined $hash_base) {
3020 print $cgi->a({-href
=> href
(action
=>"history",
3021 hash_base
=>$hash_base,
3022 file_name
=>"$basedir$t->{'name'}")},
3029 ## ......................................................................
3030 ## functions printing large fragments of HTML
3032 # get pre-image filenames for merge (combined) diff
3033 sub fill_from_file_info
{
3034 my ($diff, @parents) = @_;
3036 $diff->{'from_file'} = [ ];
3037 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3038 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3039 if ($diff->{'status'}[$i] eq 'R' ||
3040 $diff->{'status'}[$i] eq 'C') {
3041 $diff->{'from_file'}[$i] =
3042 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3049 # is current raw difftree line of file deletion
3051 my $diffinfo = shift;
3053 return $diffinfo->{'to_id'} eq ('0' x
40);
3056 # does patch correspond to [previous] difftree raw line
3057 # $diffinfo - hashref of parsed raw diff format
3058 # $patchinfo - hashref of parsed patch diff format
3059 # (the same keys as in $diffinfo)
3060 sub is_patch_split
{
3061 my ($diffinfo, $patchinfo) = @_;
3063 return defined $diffinfo && defined $patchinfo
3064 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3068 sub git_difftree_body
{
3069 my ($difftree, $hash, @parents) = @_;
3070 my ($parent) = $parents[0];
3071 my ($have_blame) = gitweb_check_feature
('blame');
3072 print "<div class=\"list_head\">\n";
3073 if ($#{$difftree} > 10) {
3074 print(($#{$difftree} + 1) . " files changed:\n");
3078 print "<table class=\"" .
3079 (@parents > 1 ? "combined " : "") .
3082 # header only for combined diff in 'commitdiff' view
3083 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3086 print "<thead><tr>\n" .
3087 "<th></th><th></th>\n"; # filename, patchN link
3088 for (my $i = 0; $i < @parents; $i++) {
3089 my $par = $parents[$i];
3091 $cgi->a({-href
=> href
(action
=>"commitdiff",
3092 hash
=>$hash, hash_parent
=>$par),
3093 -title
=> 'commitdiff to parent number ' .
3094 ($i+1) . ': ' . substr($par,0,7)},
3098 print "</tr></thead>\n<tbody>\n";
3103 foreach my $line (@{$difftree}) {
3104 my $diff = parsed_difftree_line
($line);
3107 print "<tr class=\"dark\">\n";
3109 print "<tr class=\"light\">\n";
3113 if (exists $diff->{'nparents'}) { # combined diff
3115 fill_from_file_info
($diff, @parents)
3116 unless exists $diff->{'from_file'};
3118 if (!is_deleted
($diff)) {
3119 # file exists in the result (child) commit
3121 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3122 file_name
=>$diff->{'to_file'},
3124 -class => "list"}, esc_path
($diff->{'to_file'})) .
3128 esc_path
($diff->{'to_file'}) .
3132 if ($action eq 'commitdiff') {
3135 print "<td class=\"link\">" .
3136 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3141 my $has_history = 0;
3142 my $not_deleted = 0;
3143 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3144 my $hash_parent = $parents[$i];
3145 my $from_hash = $diff->{'from_id'}[$i];
3146 my $from_path = $diff->{'from_file'}[$i];
3147 my $status = $diff->{'status'}[$i];
3149 $has_history ||= ($status ne 'A');
3150 $not_deleted ||= ($status ne 'D');
3152 if ($status eq 'A') {
3153 print "<td class=\"link\" align=\"right\"> | </td>\n";
3154 } elsif ($status eq 'D') {
3155 print "<td class=\"link\">" .
3156 $cgi->a({-href
=> href
(action
=>"blob",
3159 file_name
=>$from_path)},
3163 if ($diff->{'to_id'} eq $from_hash) {
3164 print "<td class=\"link nochange\">";
3166 print "<td class=\"link\">";
3168 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3169 hash
=>$diff->{'to_id'},
3170 hash_parent
=>$from_hash,
3172 hash_parent_base
=>$hash_parent,
3173 file_name
=>$diff->{'to_file'},
3174 file_parent
=>$from_path)},
3180 print "<td class=\"link\">";
3182 print $cgi->a({-href
=> href
(action
=>"blob",
3183 hash
=>$diff->{'to_id'},
3184 file_name
=>$diff->{'to_file'},
3187 print " | " if ($has_history);
3190 print $cgi->a({-href
=> href
(action
=>"history",
3191 file_name
=>$diff->{'to_file'},
3198 next; # instead of 'else' clause, to avoid extra indent
3200 # else ordinary diff
3202 my ($to_mode_oct, $to_mode_str, $to_file_type);
3203 my ($from_mode_oct, $from_mode_str, $from_file_type);
3204 if ($diff->{'to_mode'} ne ('0' x
6)) {
3205 $to_mode_oct = oct $diff->{'to_mode'};
3206 if (S_ISREG
($to_mode_oct)) { # only for regular file
3207 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3209 $to_file_type = file_type
($diff->{'to_mode'});
3211 if ($diff->{'from_mode'} ne ('0' x
6)) {
3212 $from_mode_oct = oct $diff->{'from_mode'};
3213 if (S_ISREG
($to_mode_oct)) { # only for regular file
3214 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3216 $from_file_type = file_type
($diff->{'from_mode'});
3219 if ($diff->{'status'} eq "A") { # created
3220 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3221 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3222 $mode_chng .= "]</span>";
3224 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3225 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3226 -class => "list"}, esc_path
($diff->{'file'}));
3228 print "<td>$mode_chng</td>\n";
3229 print "<td class=\"link\">";
3230 if ($action eq 'commitdiff') {
3233 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3236 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3237 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3241 } elsif ($diff->{'status'} eq "D") { # deleted
3242 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3244 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3245 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3246 -class => "list"}, esc_path
($diff->{'file'}));
3248 print "<td>$mode_chng</td>\n";
3249 print "<td class=\"link\">";
3250 if ($action eq 'commitdiff') {
3253 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3256 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3257 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3260 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3261 file_name
=>$diff->{'file'})},
3264 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3265 file_name
=>$diff->{'file'})},
3269 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3270 my $mode_chnge = "";
3271 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3272 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3273 if ($from_file_type ne $to_file_type) {
3274 $mode_chnge .= " from $from_file_type to $to_file_type";
3276 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3277 if ($from_mode_str && $to_mode_str) {
3278 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3279 } elsif ($to_mode_str) {
3280 $mode_chnge .= " mode: $to_mode_str";
3283 $mode_chnge .= "]</span>\n";
3286 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3287 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3288 -class => "list"}, esc_path
($diff->{'file'}));
3290 print "<td>$mode_chnge</td>\n";
3291 print "<td class=\"link\">";
3292 if ($action eq 'commitdiff') {
3295 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3297 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3298 # "commit" view and modified file (not onlu mode changed)
3299 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3300 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3301 hash_base
=>$hash, hash_parent_base
=>$parent,
3302 file_name
=>$diff->{'file'})},
3306 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3307 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3310 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3311 file_name
=>$diff->{'file'})},
3314 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3315 file_name
=>$diff->{'file'})},
3319 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3320 my %status_name = ('R' => 'moved', 'C' => 'copied');
3321 my $nstatus = $status_name{$diff->{'status'}};
3323 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3324 # mode also for directories, so we cannot use $to_mode_str
3325 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3328 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3329 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3330 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3331 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3332 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3333 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3334 -class => "list"}, esc_path
($diff->{'from_file'})) .
3335 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3336 "<td class=\"link\">";
3337 if ($action eq 'commitdiff') {
3340 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3342 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3343 # "commit" view and modified file (not only pure rename or copy)
3344 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3345 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3346 hash_base
=>$hash, hash_parent_base
=>$parent,
3347 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3351 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3352 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3355 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3356 file_name
=>$diff->{'to_file'})},
3359 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3360 file_name
=>$diff->{'to_file'})},
3364 } # we should not encounter Unmerged (U) or Unknown (X) status
3367 print "</tbody>" if $has_header;
3371 sub git_patchset_body
{
3372 my ($fd, $difftree, $hash, @hash_parents) = @_;
3373 my ($hash_parent) = $hash_parents[0];
3375 my $is_combined = (@hash_parents > 1);
3377 my $patch_number = 0;
3383 print "<div class=\"patchset\">\n";
3385 # skip to first patch
3386 while ($patch_line = <$fd>) {
3389 last if ($patch_line =~ m/^diff /);
3393 while ($patch_line) {
3395 # parse "git diff" header line
3396 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3397 # $1 is from_name, which we do not use
3398 $to_name = unquote
($2);
3399 $to_name =~ s!^b/!!;
3400 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3401 # $1 is 'cc' or 'combined', which we do not use
3402 $to_name = unquote
($2);
3407 # check if current patch belong to current raw line
3408 # and parse raw git-diff line if needed
3409 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3410 # this is continuation of a split patch
3411 print "<div class=\"patch cont\">\n";
3413 # advance raw git-diff output if needed
3414 $patch_idx++ if defined $diffinfo;
3416 # read and prepare patch information
3417 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3419 # compact combined diff output can have some patches skipped
3420 # find which patch (using pathname of result) we are at now;
3422 while ($to_name ne $diffinfo->{'to_file'}) {
3423 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3424 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3425 "</div>\n"; # class="patch"
3430 last if $patch_idx > $#$difftree;
3431 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3435 # modifies %from, %to hashes
3436 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3438 # this is first patch for raw difftree line with $patch_idx index
3439 # we index @$difftree array from 0, but number patches from 1
3440 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3444 #assert($patch_line =~ m/^diff /) if DEBUG;
3445 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3447 # print "git diff" header
3448 print format_git_diff_header_line
($patch_line, $diffinfo,
3451 # print extended diff header
3452 print "<div class=\"diff extended_header\">\n";
3454 while ($patch_line = <$fd>) {
3457 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3459 print format_extended_diff_header_line
($patch_line, $diffinfo,
3462 print "</div>\n"; # class="diff extended_header"
3464 # from-file/to-file diff header
3465 if (! $patch_line) {
3466 print "</div>\n"; # class="patch"
3469 next PATCH
if ($patch_line =~ m/^diff /);
3470 #assert($patch_line =~ m/^---/) if DEBUG;
3472 my $last_patch_line = $patch_line;
3473 $patch_line = <$fd>;
3475 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3477 print format_diff_from_to_header
($last_patch_line, $patch_line,
3478 $diffinfo, \
%from, \
%to,
3483 while ($patch_line = <$fd>) {
3486 next PATCH
if ($patch_line =~ m/^diff /);
3488 print format_diff_line
($patch_line, \
%from, \
%to);
3492 print "</div>\n"; # class="patch"
3495 # for compact combined (--cc) format, with chunk and patch simpliciaction
3496 # patchset might be empty, but there might be unprocessed raw lines
3497 for (++$patch_idx if $patch_number > 0;
3498 $patch_idx < @$difftree;
3500 # read and prepare patch information
3501 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3503 # generate anchor for "patch" links in difftree / whatchanged part
3504 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3505 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3506 "</div>\n"; # class="patch"
3511 if ($patch_number == 0) {
3512 if (@hash_parents > 1) {
3513 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3515 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3519 print "</div>\n"; # class="patchset"
3522 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3524 # fills project list info (age, description, owner, forks) for each
3525 # project in the list, removing invalid projects from returned list
3526 # NOTE: modifies $projlist, but does not remove entries from it
3527 sub fill_project_list_info
{
3528 my ($projlist, $check_forks) = @_;
3532 foreach my $pr (@$projlist) {
3533 my (@activity) = git_get_last_activity
($pr->{'path'});
3534 unless (@activity) {
3537 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3538 if (!defined $pr->{'descr'}) {
3539 my $descr = git_get_project_description
($pr->{'path'}) || "";
3540 $descr = to_utf8
($descr);
3541 $pr->{'descr_long'} = $descr;
3542 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3544 if (!defined $pr->{'owner'}) {
3545 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3548 my $pname = $pr->{'path'};
3549 if (($pname =~ s/\.git$//) &&
3550 ($pname !~ /\/$/) &&
3551 (-d
"$projectroot/$pname")) {
3552 $pr->{'forks'} = "-d $projectroot/$pname";
3557 push @projects, $pr;
3563 # print 'sort by' <th> element, either sorting by $key if $name eq $order
3564 # (changing $list), or generating 'sort by $name' replay link otherwise
3566 my ($str_sort, $name, $order, $key, $header, $list) = @_;
3568 $header ||= ucfirst($name);
3570 if ($order eq $name) {
3572 @$list = sort {$a->{$key} cmp $b->{$key}} @$list;
3574 @$list = sort {$a->{$key} <=> $b->{$key}} @$list;
3576 print "<th>$header</th>\n";
3579 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3580 -class => "header"}, $header) .
3585 sub print_sort_th_str
{
3586 print_sort_th
(1, @_);
3589 sub print_sort_th_num
{
3590 print_sort_th
(0, @_);
3593 sub git_project_list_body
{
3594 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3596 my ($check_forks) = gitweb_check_feature
('forks');
3597 my @projects = fill_project_list_info
($projlist, $check_forks);
3599 $order ||= $default_projects_order;
3600 $from = 0 unless defined $from;
3601 $to = $#projects if (!defined $to || $#projects < $to);
3603 print "<table class=\"project_list\">\n";
3604 unless ($no_header) {
3607 print "<th></th>\n";
3609 print_sort_th_str
('project', $order, 'path',
3610 'Project', \
@projects);
3611 print_sort_th_str
('descr', $order, 'descr_long',
3612 'Description', \
@projects);
3613 print_sort_th_str
('owner', $order, 'owner',
3614 'Owner', \
@projects);
3615 print_sort_th_num
('age', $order, 'age',
3616 'Last Change', \
@projects);
3617 print "<th></th>\n" . # for links
3621 for (my $i = $from; $i <= $to; $i++) {
3622 my $pr = $projects[$i];
3624 print "<tr class=\"dark\">\n";
3626 print "<tr class=\"light\">\n";
3631 if ($pr->{'forks'}) {
3632 print "<!-- $pr->{'forks'} -->\n";
3633 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3637 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3638 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3639 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3640 -class => "list", -title
=> $pr->{'descr_long'}},
3641 esc_html
($pr->{'descr'})) . "</td>\n" .
3642 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3643 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3644 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3645 "<td class=\"link\">" .
3646 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3647 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3648 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3649 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3650 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3654 if (defined $extra) {
3657 print "<td></td>\n";
3659 print "<td colspan=\"5\">$extra</td>\n" .
3665 sub git_shortlog_body
{
3666 # uses global variable $project
3667 my ($commitlist, $from, $to, $refs, $extra) = @_;
3669 $from = 0 unless defined $from;
3670 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3672 print "<table class=\"shortlog\">\n";
3674 for (my $i = $from; $i <= $to; $i++) {
3675 my %co = %{$commitlist->[$i]};
3676 my $commit = $co{'id'};
3677 my $ref = format_ref_marker
($refs, $commit);
3679 print "<tr class=\"dark\">\n";
3681 print "<tr class=\"light\">\n";
3684 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3685 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3686 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3687 "<td><i>" . $author . "</i></td>\n" .
3689 print format_subject_html
($co{'title'}, $co{'title_short'},
3690 href
(action
=>"commit", hash
=>$commit), $ref);
3692 "<td class=\"link\">" .
3693 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3694 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3695 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3696 my $snapshot_links = format_snapshot_links
($commit);
3697 if (defined $snapshot_links) {
3698 print " | " . $snapshot_links;
3703 if (defined $extra) {
3705 "<td colspan=\"4\">$extra</td>\n" .
3711 sub git_history_body
{
3712 # Warning: assumes constant type (blob or tree) during history
3713 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3715 $from = 0 unless defined $from;
3716 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3718 print "<table class=\"history\">\n";
3720 for (my $i = $from; $i <= $to; $i++) {
3721 my %co = %{$commitlist->[$i]};
3725 my $commit = $co{'id'};
3727 my $ref = format_ref_marker
($refs, $commit);
3730 print "<tr class=\"dark\">\n";
3732 print "<tr class=\"light\">\n";
3735 # shortlog uses chop_str($co{'author_name'}, 10)
3736 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3737 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3738 "<td><i>" . $author . "</i></td>\n" .
3740 # originally git_history used chop_str($co{'title'}, 50)
3741 print format_subject_html
($co{'title'}, $co{'title_short'},
3742 href
(action
=>"commit", hash
=>$commit), $ref);
3744 "<td class=\"link\">" .
3745 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3746 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3748 if ($ftype eq 'blob') {
3749 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3750 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3751 if (defined $blob_current && defined $blob_parent &&
3752 $blob_current ne $blob_parent) {
3754 $cgi->a({-href
=> href
(action
=>"blobdiff",
3755 hash
=>$blob_current, hash_parent
=>$blob_parent,
3756 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3757 file_name
=>$file_name)},
3764 if (defined $extra) {
3766 "<td colspan=\"4\">$extra</td>\n" .
3773 # uses global variable $project
3774 my ($taglist, $from, $to, $extra) = @_;
3775 $from = 0 unless defined $from;
3776 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3778 print "<table class=\"tags\">\n";
3780 for (my $i = $from; $i <= $to; $i++) {
3781 my $entry = $taglist->[$i];
3783 my $comment = $tag{'subject'};
3785 if (defined $comment) {
3786 $comment_short = chop_str
($comment, 30, 5);
3789 print "<tr class=\"dark\">\n";
3791 print "<tr class=\"light\">\n";
3794 if (defined $tag{'age'}) {
3795 print "<td><i>$tag{'age'}</i></td>\n";
3797 print "<td></td>\n";
3800 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3801 -class => "list name"}, esc_html
($tag{'name'})) .
3804 if (defined $comment) {
3805 print format_subject_html
($comment, $comment_short,
3806 href
(action
=>"tag", hash
=>$tag{'id'}));
3809 "<td class=\"selflink\">";
3810 if ($tag{'type'} eq "tag") {
3811 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3816 "<td class=\"link\">" . " | " .
3817 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3818 if ($tag{'reftype'} eq "commit") {
3819 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3820 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3821 } elsif ($tag{'reftype'} eq "blob") {
3822 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3827 if (defined $extra) {
3829 "<td colspan=\"5\">$extra</td>\n" .
3835 sub git_heads_body
{
3836 # uses global variable $project
3837 my ($headlist, $head, $from, $to, $extra) = @_;
3838 $from = 0 unless defined $from;
3839 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3841 print "<table class=\"heads\">\n";
3843 for (my $i = $from; $i <= $to; $i++) {
3844 my $entry = $headlist->[$i];
3846 my $curr = $ref{'id'} eq $head;
3848 print "<tr class=\"dark\">\n";
3850 print "<tr class=\"light\">\n";
3853 print "<td><i>$ref{'age'}</i></td>\n" .
3854 ($curr ? "<td class=\"current_head\">" : "<td>") .
3855 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3856 -class => "list name"},esc_html
($ref{'name'})) .
3858 "<td class=\"link\">" .
3859 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3860 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3861 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3865 if (defined $extra) {
3867 "<td colspan=\"3\">$extra</td>\n" .
3873 sub git_search_grep_body
{
3874 my ($commitlist, $from, $to, $extra) = @_;
3875 $from = 0 unless defined $from;
3876 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3878 print "<table class=\"commit_search\">\n";
3880 for (my $i = $from; $i <= $to; $i++) {
3881 my %co = %{$commitlist->[$i]};
3885 my $commit = $co{'id'};
3887 print "<tr class=\"dark\">\n";
3889 print "<tr class=\"light\">\n";
3892 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3893 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3894 "<td><i>" . $author . "</i></td>\n" .
3896 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3897 -class => "list subject"},
3898 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3899 my $comment = $co{'comment'};
3900 foreach my $line (@$comment) {
3901 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3902 my ($lead, $match, $trail) = ($1, $2, $3);
3903 $match = chop_str
($match, 70, 5, 'center');
3904 my $contextlen = int((80 - length($match))/2);
3905 $contextlen = 30 if ($contextlen > 30);
3906 $lead = chop_str
($lead, $contextlen, 10, 'left');
3907 $trail = chop_str
($trail, $contextlen, 10, 'right');
3909 $lead = esc_html
($lead);
3910 $match = esc_html
($match);
3911 $trail = esc_html
($trail);
3913 print "$lead<span class=\"match\">$match</span>$trail<br />";
3917 "<td class=\"link\">" .
3918 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3920 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3922 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3926 if (defined $extra) {
3928 "<td colspan=\"3\">$extra</td>\n" .
3934 ## ======================================================================
3935 ## ======================================================================
3938 sub git_project_list
{
3939 my $order = $cgi->param('o');
3940 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3941 die_error
(undef, "Unknown order parameter");
3944 my @list = git_get_projects_list
();
3946 die_error
(undef, "No projects found");
3950 if (-f
$home_text) {
3951 print "<div class=\"index_include\">\n";
3952 open (my $fd, $home_text);
3957 git_project_list_body
(\
@list, $order);
3962 my $order = $cgi->param('o');
3963 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3964 die_error
(undef, "Unknown order parameter");
3967 my @list = git_get_projects_list
($project);
3969 die_error
(undef, "No forks found");
3973 git_print_page_nav
('','');
3974 git_print_header_div
('summary', "$project forks");
3975 git_project_list_body
(\
@list, $order);
3979 sub git_project_index
{
3980 my @projects = git_get_projects_list
($project);
3983 -type
=> 'text/plain',
3984 -charset
=> 'utf-8',
3985 -content_disposition
=> 'inline; filename="index.aux"');
3987 foreach my $pr (@projects) {
3988 if (!exists $pr->{'owner'}) {
3989 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3992 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3993 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3994 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3995 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3999 print "$path $owner\n";
4004 my $descr = git_get_project_description
($project) || "none";
4005 my %co = parse_commit
("HEAD");
4006 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4007 my $head = $co{'id'};
4009 my $owner = git_get_project_owner
($project);
4011 my $refs = git_get_references
();
4012 # These get_*_list functions return one more to allow us to see if
4013 # there are more ...
4014 my @taglist = git_get_tags_list
(16);
4015 my @headlist = git_get_heads_list
(16);
4017 my ($check_forks) = gitweb_check_feature
('forks');
4020 @forklist = git_get_projects_list
($project);
4024 git_print_page_nav
('summary','', $head);
4026 print "<div class=\"title\"> </div>\n";
4027 print "<table class=\"projects_list\">\n" .
4028 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4029 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4030 if (defined $cd{'rfc2822'}) {
4031 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4034 # use per project git URL list in $projectroot/$project/cloneurl
4035 # or make project git URL from git base URL and project name
4036 my $url_tag = "URL";
4037 my @url_list = git_get_project_url_list
($project);
4038 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4039 foreach my $git_url (@url_list) {
4040 next unless $git_url;
4041 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4046 if (-s
"$projectroot/$project/README.html") {
4047 if (open my $fd, "$projectroot/$project/README.html") {
4048 print "<div class=\"title\">readme</div>\n" .
4049 "<div class=\"readme\">\n";
4050 print $_ while (<$fd>);
4051 print "\n</div>\n"; # class="readme"
4056 # we need to request one more than 16 (0..15) to check if
4058 my @commitlist = $head ? parse_commits
($head, 17) : ();
4060 git_print_header_div
('shortlog');
4061 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4062 $#commitlist <= 15 ? undef :
4063 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4067 git_print_header_div
('tags');
4068 git_tags_body
(\
@taglist, 0, 15,
4069 $#taglist <= 15 ? undef :
4070 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4074 git_print_header_div
('heads');
4075 git_heads_body
(\
@headlist, $head, 0, 15,
4076 $#headlist <= 15 ? undef :
4077 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4081 git_print_header_div
('forks');
4082 git_project_list_body
(\
@forklist, undef, 0, 15,
4083 $#forklist <= 15 ? undef :
4084 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4092 my $head = git_get_head_hash
($project);
4094 git_print_page_nav
('','', $head,undef,$head);
4095 my %tag = parse_tag
($hash);
4098 die_error
(undef, "Unknown tag object");
4101 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4102 print "<div class=\"title_text\">\n" .
4103 "<table class=\"object_header\">\n" .
4105 "<td>object</td>\n" .
4106 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4107 $tag{'object'}) . "</td>\n" .
4108 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4109 $tag{'type'}) . "</td>\n" .
4111 if (defined($tag{'author'})) {
4112 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4113 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4114 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4115 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4118 print "</table>\n\n" .
4120 print "<div class=\"page_body\">";
4121 my $comment = $tag{'comment'};
4122 foreach my $line (@$comment) {
4124 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4134 my ($have_blame) = gitweb_check_feature
('blame');
4136 die_error
('403 Permission denied', "Permission denied");
4138 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4139 $hash_base ||= git_get_head_hash
($project);
4140 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4141 my %co = parse_commit
($hash_base)
4142 or die_error
(undef, "Reading commit failed");
4143 if (!defined $hash) {
4144 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4145 or die_error
(undef, "Error looking up file");
4147 $ftype = git_get_type
($hash);
4148 if ($ftype !~ "blob") {
4149 die_error
('400 Bad Request', "Object is not a blob");
4151 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4152 $file_name, $hash_base)
4153 or die_error
(undef, "Open git-blame failed");
4156 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4159 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4162 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4164 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4165 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4166 git_print_page_path
($file_name, $ftype, $hash_base);
4167 my @rev_color = (qw(light2 dark2));
4168 my $num_colors = scalar(@rev_color);
4169 my $current_color = 0;
4172 <div class="page_body">
4173 <table class="blame">
4174 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4179 last unless defined $_;
4180 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4181 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4182 if (!exists $metainfo{$full_rev}) {
4183 $metainfo{$full_rev} = {};
4185 my $meta = $metainfo{$full_rev};
4188 if (/^(\S+) (.*)$/) {
4194 my $rev = substr($full_rev, 0, 8);
4195 my $author = $meta->{'author'};
4196 my %date = parse_date
($meta->{'author-time'},
4197 $meta->{'author-tz'});
4198 my $date = $date{'iso-tz'};
4200 $current_color = ++$current_color % $num_colors;
4202 print "<tr class=\"$rev_color[$current_color]\">\n";
4204 print "<td class=\"sha1\"";
4205 print " title=\"". esc_html
($author) . ", $date\"";
4206 print " rowspan=\"$group_size\"" if ($group_size > 1);
4208 print $cgi->a({-href
=> href
(action
=>"commit",
4210 file_name
=>$file_name)},
4214 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4215 or die_error
(undef, "Open git-rev-parse failed");
4216 my $parent_commit = <$dd>;
4218 chomp($parent_commit);
4219 my $blamed = href
(action
=> 'blame',
4220 file_name
=> $meta->{'filename'},
4221 hash_base
=> $parent_commit);
4222 print "<td class=\"linenr\">";
4223 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4225 -class => "linenr" },
4228 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4234 or print "Reading blob failed\n";
4239 my $head = git_get_head_hash
($project);
4241 git_print_page_nav
('','', $head,undef,$head);
4242 git_print_header_div
('summary', $project);
4244 my @tagslist = git_get_tags_list
();
4246 git_tags_body
(\
@tagslist);
4252 my $head = git_get_head_hash
($project);
4254 git_print_page_nav
('','', $head,undef,$head);
4255 git_print_header_div
('summary', $project);
4257 my @headslist = git_get_heads_list
();
4259 git_heads_body
(\
@headslist, $head);
4264 sub git_blob_plain
{
4268 if (!defined $hash) {
4269 if (defined $file_name) {
4270 my $base = $hash_base || git_get_head_hash
($project);
4271 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4272 or die_error
(undef, "Error lookup file");
4274 die_error
(undef, "No file name defined");
4276 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4277 # blobs defined by non-textual hash id's can be cached
4281 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4282 or die_error
(undef, "Open git-cat-file blob '$hash' failed");
4284 # content-type (can include charset)
4285 $type = blob_contenttype
($fd, $file_name, $type);
4287 # "save as" filename, even when no $file_name is given
4288 my $save_as = "$hash";
4289 if (defined $file_name) {
4290 $save_as = $file_name;
4291 } elsif ($type =~ m/^text\//) {
4297 -expires
=> $expires,
4298 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4300 binmode STDOUT
, ':raw';
4302 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4310 if (!defined $hash) {
4311 if (defined $file_name) {
4312 my $base = $hash_base || git_get_head_hash
($project);
4313 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4314 or die_error
(undef, "Error lookup file");
4316 die_error
(undef, "No file name defined");
4318 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4319 # blobs defined by non-textual hash id's can be cached
4323 my ($have_blame) = gitweb_check_feature
('blame');
4324 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4325 or die_error
(undef, "Couldn't cat $file_name, $hash");
4326 my $mimetype = blob_mimetype
($fd, $file_name);
4327 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4329 return git_blob_plain
($mimetype);
4331 # we can have blame only for text/* mimetype
4332 $have_blame &&= ($mimetype =~ m!^text/!);
4334 git_header_html
(undef, $expires);
4335 my $formats_nav = '';
4336 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4337 if (defined $file_name) {
4340 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4345 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4348 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4351 $cgi->a({-href
=> href
(action
=>"blob",
4352 hash_base
=>"HEAD", file_name
=>$file_name)},
4356 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4359 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4360 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4362 print "<div class=\"page_nav\">\n" .
4363 "<br/><br/></div>\n" .
4364 "<div class=\"title\">$hash</div>\n";
4366 git_print_page_path
($file_name, "blob", $hash_base);
4367 print "<div class=\"page_body\">\n";
4368 if ($mimetype =~ m!^image/!) {
4369 print qq
!<img type
="$mimetype"!;
4371 print qq
! alt
="$file_name" title
="$file_name"!;
4374 href(action=>"blob_plain
", hash=>$hash,
4375 hash_base=>$hash_base, file_name=>$file_name) .
4379 while (my $line = <$fd>) {
4382 $line = untabify
($line);
4383 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4384 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4388 or print "Reading blob failed.\n";
4394 if (!defined $hash_base) {
4395 $hash_base = "HEAD";
4397 if (!defined $hash) {
4398 if (defined $file_name) {
4399 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4405 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4406 or die_error
(undef, "Open git-ls-tree failed");
4407 my @entries = map { chomp; $_ } <$fd>;
4408 close $fd or die_error
(undef, "Reading tree failed");
4411 my $refs = git_get_references
();
4412 my $ref = format_ref_marker
($refs, $hash_base);
4415 my ($have_blame) = gitweb_check_feature
('blame');
4416 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4418 if (defined $file_name) {
4420 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4422 $cgi->a({-href
=> href
(action
=>"tree",
4423 hash_base
=>"HEAD", file_name
=>$file_name)},
4426 my $snapshot_links = format_snapshot_links
($hash);
4427 if (defined $snapshot_links) {
4428 # FIXME: Should be available when we have no hash base as well.
4429 push @views_nav, $snapshot_links;
4431 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4432 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4435 print "<div class=\"page_nav\">\n";
4436 print "<br/><br/></div>\n";
4437 print "<div class=\"title\">$hash</div>\n";
4439 if (defined $file_name) {
4440 $basedir = $file_name;
4441 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4445 git_print_page_path
($file_name, 'tree', $hash_base);
4446 print "<div class=\"page_body\">\n";
4447 print "<table class=\"tree\">\n";
4449 # '..' (top directory) link if possible
4450 if (defined $hash_base &&
4451 defined $file_name && $file_name =~ m![^/]+$!) {
4453 print "<tr class=\"dark\">\n";
4455 print "<tr class=\"light\">\n";
4459 my $up = $file_name;
4460 $up =~ s!/?[^/]+$!!;
4461 undef $up unless $up;
4462 # based on git_print_tree_entry
4463 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4464 print '<td class="list">';
4465 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4469 print "<td class=\"link\"></td>\n";
4473 foreach my $line (@entries) {
4474 my %t = parse_ls_tree_line
($line, -z
=> 1);
4477 print "<tr class=\"dark\">\n";
4479 print "<tr class=\"light\">\n";
4483 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4487 print "</table>\n" .
4493 my @supported_fmts = gitweb_check_feature
('snapshot');
4494 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4496 my $format = $cgi->param('sf');
4497 if (!@supported_fmts) {
4498 die_error
('403 Permission denied', "Permission denied");
4500 # default to first supported snapshot format
4501 $format ||= $supported_fmts[0];
4502 if ($format !~ m/^[a-z0-9]+$/) {
4503 die_error
(undef, "Invalid snapshot format parameter");
4504 } elsif (!exists($known_snapshot_formats{$format})) {
4505 die_error
(undef, "Unknown snapshot format");
4506 } elsif (!grep($_ eq $format, @supported_fmts)) {
4507 die_error
(undef, "Unsupported snapshot format");
4510 if (!defined $hash) {
4511 $hash = git_get_head_hash
($project);
4514 my $name = $project;
4515 $name =~ s
,([^/])/*\
.git
$,$1,;
4516 $name = basename
($name);
4517 my $filename = to_utf8
($name);
4518 $name =~ s/\047/\047\\\047\047/g;
4520 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4521 $cmd = quote_command
(
4522 git_cmd
(), 'archive',
4523 "--format=$known_snapshot_formats{$format}{'format'}",
4524 "--prefix=$name/", $hash);
4525 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4526 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4530 -type
=> $known_snapshot_formats{$format}{'type'},
4531 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4532 -status
=> '200 OK');
4534 open my $fd, "-|", $cmd
4535 or die_error
(undef, "Execute git-archive failed");
4536 binmode STDOUT
, ':raw';
4538 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4543 my $head = git_get_head_hash
($project);
4544 if (!defined $hash) {
4547 if (!defined $page) {
4550 my $refs = git_get_references
();
4552 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4554 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4557 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4560 my %co = parse_commit
($hash);
4562 git_print_header_div
('summary', $project);
4563 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4565 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4566 for (my $i = 0; $i <= $to; $i++) {
4567 my %co = %{$commitlist[$i]};
4569 my $commit = $co{'id'};
4570 my $ref = format_ref_marker
($refs, $commit);
4571 my %ad = parse_date
($co{'author_epoch'});
4572 git_print_header_div
('commit',
4573 "<span class=\"age\">$co{'age_string'}</span>" .
4574 esc_html
($co{'title'}) . $ref,
4576 print "<div class=\"title_text\">\n" .
4577 "<div class=\"log_link\">\n" .
4578 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4580 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4582 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4585 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4588 print "<div class=\"log_body\">\n";
4589 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4592 if ($#commitlist >= 100) {
4593 print "<div class=\"page_nav\">\n";
4594 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4595 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4602 $hash ||= $hash_base || "HEAD";
4603 my %co = parse_commit
($hash);
4605 die_error
(undef, "Unknown commit object");
4607 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4608 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4610 my $parent = $co{'parent'};
4611 my $parents = $co{'parents'}; # listref
4613 # we need to prepare $formats_nav before any parameter munging
4615 if (!defined $parent) {
4617 $formats_nav .= '(initial)';
4618 } elsif (@$parents == 1) {
4619 # single parent commit
4622 $cgi->a({-href
=> href
(action
=>"commit",
4624 esc_html
(substr($parent, 0, 7))) .
4631 $cgi->a({-href
=> href
(action
=>"commit",
4633 esc_html
(substr($_, 0, 7)));
4638 if (!defined $parent) {
4642 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4644 (@$parents <= 1 ? $parent : '-c'),
4646 or die_error
(undef, "Open git-diff-tree failed");
4647 @difftree = map { chomp; $_ } <$fd>;
4648 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4650 # non-textual hash id's can be cached
4652 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4655 my $refs = git_get_references
();
4656 my $ref = format_ref_marker
($refs, $co{'id'});
4658 git_header_html
(undef, $expires);
4659 git_print_page_nav
('commit', '',
4660 $hash, $co{'tree'}, $hash,
4663 if (defined $co{'parent'}) {
4664 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4666 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4668 print "<div class=\"title_text\">\n" .
4669 "<table class=\"object_header\">\n";
4670 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4672 "<td></td><td> $ad{'rfc2822'}";
4673 if ($ad{'hour_local'} < 6) {
4674 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4675 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4677 printf(" (%02d:%02d %s)",
4678 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4682 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4683 print "<tr><td></td><td> $cd{'rfc2822'}" .
4684 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4686 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4689 "<td class=\"sha1\">" .
4690 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4691 class => "list"}, $co{'tree'}) .
4693 "<td class=\"link\">" .
4694 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4696 my $snapshot_links = format_snapshot_links
($hash);
4697 if (defined $snapshot_links) {
4698 print " | " . $snapshot_links;
4703 foreach my $par (@$parents) {
4706 "<td class=\"sha1\">" .
4707 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4708 class => "list"}, $par) .
4710 "<td class=\"link\">" .
4711 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4713 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4720 print "<div class=\"page_body\">\n";
4721 git_print_log
($co{'comment'});
4724 git_difftree_body
(\
@difftree, $hash, @$parents);
4730 # object is defined by:
4731 # - hash or hash_base alone
4732 # - hash_base and file_name
4735 # - hash or hash_base alone
4736 if ($hash || ($hash_base && !defined $file_name)) {
4737 my $object_id = $hash || $hash_base;
4739 open my $fd, "-|", quote_command
(
4740 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4741 or die_error
('404 Not Found', "Object does not exist");
4745 or die_error
('404 Not Found', "Object does not exist");
4747 # - hash_base and file_name
4748 } elsif ($hash_base && defined $file_name) {
4749 $file_name =~ s
,/+$,,;
4751 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4752 or die_error
('404 Not Found', "Base object does not exist");
4754 # here errors should not hapen
4755 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4756 or die_error
(undef, "Open git-ls-tree failed");
4760 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4761 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4762 die_error
('404 Not Found', "File or directory for given base does not exist");
4767 die_error
('404 Not Found', "Not enough information to find object");
4770 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4771 hash
=>$hash, hash_base
=>$hash_base,
4772 file_name
=>$file_name),
4773 -status
=> '302 Found');
4777 my $format = shift || 'html';
4784 # preparing $fd and %diffinfo for git_patchset_body
4786 if (defined $hash_base && defined $hash_parent_base) {
4787 if (defined $file_name) {
4789 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4790 $hash_parent_base, $hash_base,
4791 "--", (defined $file_parent ? $file_parent : ()), $file_name
4792 or die_error
(undef, "Open git-diff-tree failed");
4793 @difftree = map { chomp; $_ } <$fd>;
4795 or die_error
(undef, "Reading git-diff-tree failed");
4797 or die_error
('404 Not Found', "Blob diff not found");
4799 } elsif (defined $hash &&
4800 $hash =~ /[0-9a-fA-F]{40}/) {
4801 # try to find filename from $hash
4803 # read filtered raw output
4804 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4805 $hash_parent_base, $hash_base, "--"
4806 or die_error
(undef, "Open git-diff-tree failed");
4808 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4810 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4811 map { chomp; $_ } <$fd>;
4813 or die_error
(undef, "Reading git-diff-tree failed");
4815 or die_error
('404 Not Found', "Blob diff not found");
4818 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4821 if (@difftree > 1) {
4822 die_error
('404 Not Found', "Ambiguous blob diff specification");
4825 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4826 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4827 $file_name ||= $diffinfo{'to_file'};
4829 $hash_parent ||= $diffinfo{'from_id'};
4830 $hash ||= $diffinfo{'to_id'};
4832 # non-textual hash id's can be cached
4833 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4834 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4839 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4840 '-p', ($format eq 'html' ? "--full-index" : ()),
4841 $hash_parent_base, $hash_base,
4842 "--", (defined $file_parent ? $file_parent : ()), $file_name
4843 or die_error
(undef, "Open git-diff-tree failed");
4846 # old/legacy style URI
4847 if (!%diffinfo && # if new style URI failed
4848 defined $hash && defined $hash_parent) {
4849 # fake git-diff-tree raw output
4850 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4851 $diffinfo{'from_id'} = $hash_parent;
4852 $diffinfo{'to_id'} = $hash;
4853 if (defined $file_name) {
4854 if (defined $file_parent) {
4855 $diffinfo{'status'} = '2';
4856 $diffinfo{'from_file'} = $file_parent;
4857 $diffinfo{'to_file'} = $file_name;
4858 } else { # assume not renamed
4859 $diffinfo{'status'} = '1';
4860 $diffinfo{'from_file'} = $file_name;
4861 $diffinfo{'to_file'} = $file_name;
4863 } else { # no filename given
4864 $diffinfo{'status'} = '2';
4865 $diffinfo{'from_file'} = $hash_parent;
4866 $diffinfo{'to_file'} = $hash;
4869 # non-textual hash id's can be cached
4870 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4871 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4876 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4877 '-p', ($format eq 'html' ? "--full-index" : ()),
4878 $hash_parent, $hash, "--"
4879 or die_error
(undef, "Open git-diff failed");
4881 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4886 if ($format eq 'html') {
4888 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4890 git_header_html
(undef, $expires);
4891 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4892 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4893 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4895 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4896 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4898 if (defined $file_name) {
4899 git_print_page_path
($file_name, "blob", $hash_base);
4901 print "<div class=\"page_path\"></div>\n";
4904 } elsif ($format eq 'plain') {
4906 -type
=> 'text/plain',
4907 -charset
=> 'utf-8',
4908 -expires
=> $expires,
4909 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4911 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4914 die_error
(undef, "Unknown blobdiff format");
4918 if ($format eq 'html') {
4919 print "<div class=\"page_body\">\n";
4921 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4924 print "</div>\n"; # class="page_body"
4928 while (my $line = <$fd>) {
4929 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4930 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4934 last if $line =~ m!^\+\+\+!;
4942 sub git_blobdiff_plain
{
4943 git_blobdiff
('plain');
4946 sub git_commitdiff
{
4947 my $format = shift || 'html';
4948 $hash ||= $hash_base || "HEAD";
4949 my %co = parse_commit
($hash);
4951 die_error
(undef, "Unknown commit object");
4954 # choose format for commitdiff for merge
4955 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4956 $hash_parent = '--cc';
4958 # we need to prepare $formats_nav before almost any parameter munging
4960 if ($format eq 'html') {
4962 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4965 if (defined $hash_parent &&
4966 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4967 # commitdiff with two commits given
4968 my $hash_parent_short = $hash_parent;
4969 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4970 $hash_parent_short = substr($hash_parent, 0, 7);
4974 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4975 if ($co{'parents'}[$i] eq $hash_parent) {
4976 $formats_nav .= ' parent ' . ($i+1);
4980 $formats_nav .= ': ' .
4981 $cgi->a({-href
=> href
(action
=>"commitdiff",
4982 hash
=>$hash_parent)},
4983 esc_html
($hash_parent_short)) .
4985 } elsif (!$co{'parent'}) {
4987 $formats_nav .= ' (initial)';
4988 } elsif (scalar @{$co{'parents'}} == 1) {
4989 # single parent commit
4992 $cgi->a({-href
=> href
(action
=>"commitdiff",
4993 hash
=>$co{'parent'})},
4994 esc_html
(substr($co{'parent'}, 0, 7))) .
4998 if ($hash_parent eq '--cc') {
4999 $formats_nav .= ' | ' .
5000 $cgi->a({-href
=> href
(action
=>"commitdiff",
5001 hash
=>$hash, hash_parent
=>'-c')},
5003 } else { # $hash_parent eq '-c'
5004 $formats_nav .= ' | ' .
5005 $cgi->a({-href
=> href
(action
=>"commitdiff",
5006 hash
=>$hash, hash_parent
=>'--cc')},
5012 $cgi->a({-href
=> href
(action
=>"commitdiff",
5014 esc_html
(substr($_, 0, 7)));
5015 } @{$co{'parents'}} ) .
5020 my $hash_parent_param = $hash_parent;
5021 if (!defined $hash_parent_param) {
5022 # --cc for multiple parents, --root for parentless
5023 $hash_parent_param =
5024 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5030 if ($format eq 'html') {
5031 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5032 "--no-commit-id", "--patch-with-raw", "--full-index",
5033 $hash_parent_param, $hash, "--"
5034 or die_error
(undef, "Open git-diff-tree failed");
5036 while (my $line = <$fd>) {
5038 # empty line ends raw part of diff-tree output
5040 push @difftree, scalar parse_difftree_raw_line
($line);
5043 } elsif ($format eq 'plain') {
5044 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5045 '-p', $hash_parent_param, $hash, "--"
5046 or die_error
(undef, "Open git-diff-tree failed");
5049 die_error
(undef, "Unknown commitdiff format");
5052 # non-textual hash id's can be cached
5054 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5058 # write commit message
5059 if ($format eq 'html') {
5060 my $refs = git_get_references
();
5061 my $ref = format_ref_marker
($refs, $co{'id'});
5063 git_header_html
(undef, $expires);
5064 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5065 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5066 git_print_authorship
(\
%co);
5067 print "<div class=\"page_body\">\n";
5068 if (@{$co{'comment'}} > 1) {
5069 print "<div class=\"log\">\n";
5070 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5071 print "</div>\n"; # class="log"
5074 } elsif ($format eq 'plain') {
5075 my $refs = git_get_references
("tags");
5076 my $tagname = git_get_rev_name_tags
($hash);
5077 my $filename = basename
($project) . "-$hash.patch";
5080 -type
=> 'text/plain',
5081 -charset
=> 'utf-8',
5082 -expires
=> $expires,
5083 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5084 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5085 print "From: " . to_utf8
($co{'author'}) . "\n";
5086 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5087 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5089 print "X-Git-Tag: $tagname\n" if $tagname;
5090 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5092 foreach my $line (@{$co{'comment'}}) {
5093 print to_utf8
($line) . "\n";
5099 if ($format eq 'html') {
5100 my $use_parents = !defined $hash_parent ||
5101 $hash_parent eq '-c' || $hash_parent eq '--cc';
5102 git_difftree_body
(\
@difftree, $hash,
5103 $use_parents ? @{$co{'parents'}} : $hash_parent);
5106 git_patchset_body
($fd, \
@difftree, $hash,
5107 $use_parents ? @{$co{'parents'}} : $hash_parent);
5109 print "</div>\n"; # class="page_body"
5112 } elsif ($format eq 'plain') {
5116 or print "Reading git-diff-tree failed\n";
5120 sub git_commitdiff_plain
{
5121 git_commitdiff
('plain');
5125 if (!defined $hash_base) {
5126 $hash_base = git_get_head_hash
($project);
5128 if (!defined $page) {
5132 my %co = parse_commit
($hash_base);
5134 die_error
(undef, "Unknown commit object");
5137 my $refs = git_get_references
();
5138 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5140 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5141 $file_name, "--full-history");
5143 die_error
('404 Not Found', "No such file or directory on given branch");
5146 if (!defined $hash && defined $file_name) {
5147 # some commits could have deleted file in question,
5148 # and not have it in tree, but one of them has to have it
5149 for (my $i = 0; $i <= @commitlist; $i++) {
5150 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5151 last if defined $hash;
5154 if (defined $hash) {
5155 $ftype = git_get_type
($hash);
5157 if (!defined $ftype) {
5158 die_error
(undef, "Unknown type of object");
5161 my $paging_nav = '';
5164 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5165 file_name
=>$file_name)},
5167 $paging_nav .= " ⋅ " .
5168 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5169 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5171 $paging_nav .= "first";
5172 $paging_nav .= " ⋅ prev";
5175 if ($#commitlist >= 100) {
5177 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5178 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5179 $paging_nav .= " ⋅ $next_link";
5181 $paging_nav .= " ⋅ next";
5185 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5186 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5187 git_print_page_path
($file_name, $ftype, $hash_base);
5189 git_history_body
(\
@commitlist, 0, 99,
5190 $refs, $hash_base, $ftype, $next_link);
5196 my ($have_search) = gitweb_check_feature
('search');
5197 if (!$have_search) {
5198 die_error
('403 Permission denied', "Permission denied");
5200 if (!defined $searchtext) {
5201 die_error
(undef, "Text field empty");
5203 if (!defined $hash) {
5204 $hash = git_get_head_hash
($project);
5206 my %co = parse_commit
($hash);
5208 die_error
(undef, "Unknown commit object");
5210 if (!defined $page) {
5214 $searchtype ||= 'commit';
5215 if ($searchtype eq 'pickaxe') {
5216 # pickaxe may take all resources of your box and run for several minutes
5217 # with every query - so decide by yourself how public you make this feature
5218 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5219 if (!$have_pickaxe) {
5220 die_error
('403 Permission denied', "Permission denied");
5223 if ($searchtype eq 'grep') {
5224 my ($have_grep) = gitweb_check_feature
('grep');
5226 die_error
('403 Permission denied', "Permission denied");
5232 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5234 if ($searchtype eq 'commit') {
5235 $greptype = "--grep=";
5236 } elsif ($searchtype eq 'author') {
5237 $greptype = "--author=";
5238 } elsif ($searchtype eq 'committer') {
5239 $greptype = "--committer=";
5241 $greptype .= $searchtext;
5242 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5243 $greptype, '--regexp-ignore-case',
5244 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5246 my $paging_nav = '';
5249 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5250 searchtext
=>$searchtext,
5251 searchtype
=>$searchtype)},
5253 $paging_nav .= " ⋅ " .
5254 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5255 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5257 $paging_nav .= "first";
5258 $paging_nav .= " ⋅ prev";
5261 if ($#commitlist >= 100) {
5263 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5264 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5265 $paging_nav .= " ⋅ $next_link";
5267 $paging_nav .= " ⋅ next";
5270 if ($#commitlist >= 100) {
5273 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5274 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5275 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5278 if ($searchtype eq 'pickaxe') {
5279 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5280 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5282 print "<table class=\"pickaxe search\">\n";
5285 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5286 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5287 ($search_use_regexp ? '--pickaxe-regex' : ());
5290 while (my $line = <$fd>) {
5294 my %set = parse_difftree_raw_line
($line);
5295 if (defined $set{'commit'}) {
5296 # finish previous commit
5299 "<td class=\"link\">" .
5300 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5302 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5308 print "<tr class=\"dark\">\n";
5310 print "<tr class=\"light\">\n";
5313 %co = parse_commit
($set{'commit'});
5314 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5315 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5316 "<td><i>$author</i></td>\n" .
5318 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5319 -class => "list subject"},
5320 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5321 } elsif (defined $set{'to_id'}) {
5322 next if ($set{'to_id'} =~ m/^0{40}$/);
5324 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5325 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5327 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5333 # finish last commit (warning: repetition!)
5336 "<td class=\"link\">" .
5337 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5339 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5347 if ($searchtype eq 'grep') {
5348 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5349 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5351 print "<table class=\"grep_search\">\n";
5355 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5356 $search_use_regexp ? ('-E', '-i') : '-F',
5357 $searchtext, $co{'tree'};
5359 while (my $line = <$fd>) {
5361 my ($file, $lno, $ltext, $binary);
5362 last if ($matches++ > 1000);
5363 if ($line =~ /^Binary file (.+) matches$/) {
5367 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5369 if ($file ne $lastfile) {
5370 $lastfile and print "</td></tr>\n";
5372 print "<tr class=\"dark\">\n";
5374 print "<tr class=\"light\">\n";
5376 print "<td class=\"list\">".
5377 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5378 file_name
=>"$file"),
5379 -class => "list"}, esc_path
($file));
5380 print "</td><td>\n";
5384 print "<div class=\"binary\">Binary file</div>\n";
5386 $ltext = untabify
($ltext);
5387 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5388 $ltext = esc_html
($1, -nbsp
=>1);
5389 $ltext .= '<span class="match">';
5390 $ltext .= esc_html
($2, -nbsp
=>1);
5391 $ltext .= '</span>';
5392 $ltext .= esc_html
($3, -nbsp
=>1);
5394 $ltext = esc_html
($ltext, -nbsp
=>1);
5396 print "<div class=\"pre\">" .
5397 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5398 file_name
=>"$file").'#l'.$lno,
5399 -class => "linenr"}, sprintf('%4i', $lno))
5400 . ' ' . $ltext . "</div>\n";
5404 print "</td></tr>\n";
5405 if ($matches > 1000) {
5406 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5409 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5418 sub git_search_help
{
5420 git_print_page_nav
('','', $hash,$hash,$hash);
5422 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5423 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5424 the pattern entered is recognized as the POSIX extended
5425 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5428 <dt><b>commit</b></dt>
5429 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5431 my ($have_grep) = gitweb_check_feature
('grep');
5434 <dt><b>grep</b></dt>
5435 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5436 a different one) are searched for the given pattern. On large trees, this search can take
5437 a while and put some strain on the server, so please use it with some consideration. Note that
5438 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5439 case-sensitive.</dd>
5443 <dt><b>author</b></dt>
5444 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5445 <dt><b>committer</b></dt>
5446 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5448 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5449 if ($have_pickaxe) {
5451 <dt><b>pickaxe</b></dt>
5452 <dd>All commits that caused the string to appear or disappear from any file (changes that
5453 added, removed or "modified" the string) will be listed. This search can take a while and
5454 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5455 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5463 my $head = git_get_head_hash
($project);
5464 if (!defined $hash) {
5467 if (!defined $page) {
5470 my $refs = git_get_references
();
5472 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5474 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5476 if ($#commitlist >= 100) {
5478 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5479 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5483 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5484 git_print_header_div
('summary', $project);
5486 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5491 ## ......................................................................
5492 ## feeds (RSS, Atom; OPML)
5495 my $format = shift || 'atom';
5496 my ($have_blame) = gitweb_check_feature
('blame');
5498 # Atom: http://www.atomenabled.org/developers/syndication/
5499 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5500 if ($format ne 'rss' && $format ne 'atom') {
5501 die_error
(undef, "Unknown web feed format");
5504 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5505 my $head = $hash || 'HEAD';
5506 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5510 my $content_type = "application/$format+xml";
5511 if (defined $cgi->http('HTTP_ACCEPT') &&
5512 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5513 # browser (feed reader) prefers text/xml
5514 $content_type = 'text/xml';
5516 if (defined($commitlist[0])) {
5517 %latest_commit = %{$commitlist[0]};
5518 %latest_date = parse_date
($latest_commit{'author_epoch'});
5520 -type
=> $content_type,
5521 -charset
=> 'utf-8',
5522 -last_modified
=> $latest_date{'rfc2822'});
5525 -type
=> $content_type,
5526 -charset
=> 'utf-8');
5529 # Optimization: skip generating the body if client asks only
5530 # for Last-Modified date.
5531 return if ($cgi->request_method() eq 'HEAD');
5534 my $title = "$site_name - $project/$action";
5535 my $feed_type = 'log';
5536 if (defined $hash) {
5537 $title .= " - '$hash'";
5538 $feed_type = 'branch log';
5539 if (defined $file_name) {
5540 $title .= " :: $file_name";
5541 $feed_type = 'history';
5543 } elsif (defined $file_name) {
5544 $title .= " - $file_name";
5545 $feed_type = 'history';
5547 $title .= " $feed_type";
5548 my $descr = git_get_project_description
($project);
5549 if (defined $descr) {
5550 $descr = esc_html
($descr);
5552 $descr = "$project " .
5553 ($format eq 'rss' ? 'RSS' : 'Atom') .
5556 my $owner = git_get_project_owner
($project);
5557 $owner = esc_html
($owner);
5561 if (defined $file_name) {
5562 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5563 } elsif (defined $hash) {
5564 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5566 $alt_url = href
(-full
=>1, action
=>"summary");
5568 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5569 if ($format eq 'rss') {
5571 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5574 print "<title>$title</title>\n" .
5575 "<link>$alt_url</link>\n" .
5576 "<description>$descr</description>\n" .
5577 "<language>en</language>\n";
5578 } elsif ($format eq 'atom') {
5580 <feed xmlns="http://www.w3.org/2005/Atom">
5582 print "<title>$title</title>\n" .
5583 "<subtitle>$descr</subtitle>\n" .
5584 '<link rel="alternate" type="text/html" href="' .
5585 $alt_url . '" />' . "\n" .
5586 '<link rel="self" type="' . $content_type . '" href="' .
5587 $cgi->self_url() . '" />' . "\n" .
5588 "<id>" . href
(-full
=>1) . "</id>\n" .
5589 # use project owner for feed author
5590 "<author><name>$owner</name></author>\n";
5591 if (defined $favicon) {
5592 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5594 if (defined $logo_url) {
5595 # not twice as wide as tall: 72 x 27 pixels
5596 print "<logo>" . esc_url
($logo) . "</logo>\n";
5598 if (! %latest_date) {
5599 # dummy date to keep the feed valid until commits trickle in:
5600 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5602 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5607 for (my $i = 0; $i <= $#commitlist; $i++) {
5608 my %co = %{$commitlist[$i]};
5609 my $commit = $co{'id'};
5610 # we read 150, we always show 30 and the ones more recent than 48 hours
5611 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5614 my %cd = parse_date
($co{'author_epoch'});
5616 # get list of changed files
5617 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5618 $co{'parent'} || "--root",
5619 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5621 my @difftree = map { chomp; $_ } <$fd>;
5625 # print element (entry, item)
5626 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5627 if ($format eq 'rss') {
5629 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5630 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5631 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5632 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5633 "<link>$co_url</link>\n" .
5634 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5635 "<content:encoded>" .
5637 } elsif ($format eq 'atom') {
5639 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5640 "<updated>$cd{'iso-8601'}</updated>\n" .
5642 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5643 if ($co{'author_email'}) {
5644 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5646 print "</author>\n" .
5647 # use committer for contributor
5649 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5650 if ($co{'committer_email'}) {
5651 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5653 print "</contributor>\n" .
5654 "<published>$cd{'iso-8601'}</published>\n" .
5655 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5656 "<id>$co_url</id>\n" .
5657 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5658 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5660 my $comment = $co{'comment'};
5662 foreach my $line (@$comment) {
5663 $line = esc_html
($line);
5666 print "</pre><ul>\n";
5667 foreach my $difftree_line (@difftree) {
5668 my %difftree = parse_difftree_raw_line
($difftree_line);
5669 next if !$difftree{'from_id'};
5671 my $file = $difftree{'file'} || $difftree{'to_file'};
5675 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5676 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5677 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5678 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5679 -title
=> "diff"}, 'D');
5681 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5682 file_name
=>$file, hash_base
=>$commit),
5683 -title
=> "blame"}, 'B');
5685 # if this is not a feed of a file history
5686 if (!defined $file_name || $file_name ne $file) {
5687 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5688 file_name
=>$file, hash
=>$commit),
5689 -title
=> "history"}, 'H');
5691 $file = esc_path
($file);
5695 if ($format eq 'rss') {
5696 print "</ul>]]>\n" .
5697 "</content:encoded>\n" .
5699 } elsif ($format eq 'atom') {
5700 print "</ul>\n</div>\n" .
5707 if ($format eq 'rss') {
5708 print "</channel>\n</rss>\n";
5709 } elsif ($format eq 'atom') {
5723 my @list = git_get_projects_list
();
5725 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5727 <?xml version="1.0" encoding="utf-8"?>
5728 <opml version="1.0">
5730 <title>$site_name OPML Export</title>
5733 <outline text="git RSS feeds">
5736 foreach my $pr (@list) {
5738 my $head = git_get_head_hash
($proj{'path'});
5739 if (!defined $head) {
5742 $git_dir = "$projectroot/$proj{'path'}";
5743 my %co = parse_commit
($head);
5748 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5749 my $rss = "$my_url?p=$proj{'path'};a=rss";
5750 my $html = "$my_url?p=$proj{'path'};a=summary";
5751 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";