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 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
375 # version of the core git binary
376 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
378 $projects_list ||= $projectroot;
380 # ======================================================================
381 # input validation and dispatch
382 our $action = $cgi->param('a');
383 if (defined $action) {
384 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
385 die_error
(undef, "Invalid action parameter");
389 # parameters which are pathnames
390 our $project = $cgi->param('p');
391 if (defined $project) {
392 if (!validate_pathname
($project) ||
393 !(-d
"$projectroot/$project") ||
394 !check_head_link
("$projectroot/$project") ||
395 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
396 ($strict_export && !project_in_list
($project))) {
398 die_error
(undef, "No such project");
402 our $file_name = $cgi->param('f');
403 if (defined $file_name) {
404 if (!validate_pathname
($file_name)) {
405 die_error
(undef, "Invalid file parameter");
409 our $file_parent = $cgi->param('fp');
410 if (defined $file_parent) {
411 if (!validate_pathname
($file_parent)) {
412 die_error
(undef, "Invalid file parent parameter");
416 # parameters which are refnames
417 our $hash = $cgi->param('h');
419 if (!validate_refname
($hash)) {
420 die_error
(undef, "Invalid hash parameter");
424 our $hash_parent = $cgi->param('hp');
425 if (defined $hash_parent) {
426 if (!validate_refname
($hash_parent)) {
427 die_error
(undef, "Invalid hash parent parameter");
431 our $hash_base = $cgi->param('hb');
432 if (defined $hash_base) {
433 if (!validate_refname
($hash_base)) {
434 die_error
(undef, "Invalid hash base parameter");
438 my %allowed_options = (
439 "--no-merges" => [ qw(rss atom log shortlog history) ],
442 our @extra_options = $cgi->param('opt');
443 if (defined @extra_options) {
444 foreach my $opt (@extra_options) {
445 if (not exists $allowed_options{$opt}) {
446 die_error
(undef, "Invalid option parameter");
448 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
449 die_error
(undef, "Invalid option parameter for this action");
454 our $hash_parent_base = $cgi->param('hpb');
455 if (defined $hash_parent_base) {
456 if (!validate_refname
($hash_parent_base)) {
457 die_error
(undef, "Invalid hash parent base parameter");
462 our $page = $cgi->param('pg');
464 if ($page =~ m/[^0-9]/) {
465 die_error
(undef, "Invalid page parameter");
469 our $searchtype = $cgi->param('st');
470 if (defined $searchtype) {
471 if ($searchtype =~ m/[^a-z]/) {
472 die_error
(undef, "Invalid searchtype parameter");
476 our $searchtext = $cgi->param('s');
478 if (defined $searchtext) {
479 if (length($searchtext) < 2) {
480 die_error
(undef, "At least two characters are required for search parameter");
482 $search_regexp = quotemeta $searchtext;
485 # now read PATH_INFO and use it as alternative to parameters
486 sub evaluate_path_info
{
487 return if defined $project;
488 my $path_info = $ENV{"PATH_INFO"};
489 return if !$path_info;
490 $path_info =~ s
,^/+,,;
491 return if !$path_info;
492 # find which part of PATH_INFO is project
493 $project = $path_info;
495 while ($project && !check_head_link
("$projectroot/$project")) {
496 $project =~ s
,/*[^/]*$,,;
499 $project = validate_pathname
($project);
501 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
502 ($strict_export && !project_in_list
($project))) {
506 # do not change any parameters if an action is given using the query string
508 $path_info =~ s
,^$project/*,,;
509 my ($refname, $pathname) = split(/:/, $path_info, 2);
510 if (defined $pathname) {
511 # we got "project.git/branch:filename" or "project.git/branch:dir/"
512 # we could use git_get_type(branch:pathname), but it needs $git_dir
513 $pathname =~ s
,^/+,,;
514 if (!$pathname || substr($pathname, -1) eq "/") {
518 $action ||= "blob_plain";
520 $hash_base ||= validate_refname
($refname);
521 $file_name ||= validate_pathname
($pathname);
522 } elsif (defined $refname) {
523 # we got "project.git/branch"
524 $action ||= "shortlog";
525 $hash ||= validate_refname
($refname);
528 evaluate_path_info
();
530 # path to the current git repository
532 $git_dir = "$projectroot/$project" if $project;
536 "blame" => \
&git_blame2
,
537 "blobdiff" => \
&git_blobdiff
,
538 "blobdiff_plain" => \
&git_blobdiff_plain
,
539 "blob" => \
&git_blob
,
540 "blob_plain" => \
&git_blob_plain
,
541 "commitdiff" => \
&git_commitdiff
,
542 "commitdiff_plain" => \
&git_commitdiff_plain
,
543 "commit" => \
&git_commit
,
544 "forks" => \
&git_forks
,
545 "heads" => \
&git_heads
,
546 "history" => \
&git_history
,
549 "atom" => \
&git_atom
,
550 "search" => \
&git_search
,
551 "search_help" => \
&git_search_help
,
552 "shortlog" => \
&git_shortlog
,
553 "summary" => \
&git_summary
,
555 "tags" => \
&git_tags
,
556 "tree" => \
&git_tree
,
557 "snapshot" => \
&git_snapshot
,
558 "object" => \
&git_object
,
559 # those below don't need $project
560 "opml" => \
&git_opml
,
561 "project_list" => \
&git_project_list
,
562 "project_index" => \
&git_project_index
,
565 if (!defined $action) {
567 $action = git_get_type
($hash);
568 } elsif (defined $hash_base && defined $file_name) {
569 $action = git_get_type
("$hash_base:$file_name");
570 } elsif (defined $project) {
573 $action = 'project_list';
576 if (!defined($actions{$action})) {
577 die_error
(undef, "Unknown action");
579 if ($action !~ m/^(opml|project_list|project_index)$/ &&
581 die_error
(undef, "Project needed");
583 $actions{$action}->();
586 ## ======================================================================
591 # default is to use -absolute url() i.e. $my_uri
592 my $href = $params{-full
} ? $my_url : $my_uri;
594 # XXX: Warning: If you touch this, check the search form for updating,
605 hash_parent_base
=> "hpb",
610 snapshot_format
=> "sf",
611 extra_options
=> "opt",
613 my %mapping = @mapping;
615 $params{'project'} = $project unless exists $params{'project'};
617 if ($params{-replay
}) {
618 while (my ($name, $symbol) = each %mapping) {
619 if (!exists $params{$name}) {
620 # to allow for multivalued params we use arrayref form
621 $params{$name} = [ $cgi->param($symbol) ];
626 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
628 # use PATH_INFO for project name
629 $href .= "/$params{'project'}" if defined $params{'project'};
630 delete $params{'project'};
632 # Summary just uses the project path URL
633 if (defined $params{'action'} && $params{'action'} eq 'summary') {
634 delete $params{'action'};
638 # now encode the parameters explicitly
640 for (my $i = 0; $i < @mapping; $i += 2) {
641 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
642 if (defined $params{$name}) {
643 if (ref($params{$name}) eq "ARRAY") {
644 foreach my $par (@{$params{$name}}) {
645 push @result, $symbol . "=" . esc_param
($par);
648 push @result, $symbol . "=" . esc_param
($params{$name});
652 $href .= "?" . join(';', @result) if scalar @result;
658 ## ======================================================================
659 ## validation, quoting/unquoting and escaping
661 sub validate_pathname
{
662 my $input = shift || return undef;
664 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
665 # at the beginning, at the end, and between slashes.
666 # also this catches doubled slashes
667 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
671 if ($input =~ m!\0!) {
677 sub validate_refname
{
678 my $input = shift || return undef;
680 # textual hashes are O.K.
681 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
684 # it must be correct pathname
685 $input = validate_pathname
($input)
687 # restrictions on ref name according to git-check-ref-format
688 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
694 # decode sequences of octets in utf8 into Perl's internal form,
695 # which is utf-8 with utf8 flag set if needed. gitweb writes out
696 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
699 if (utf8
::valid
($str)) {
703 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
707 # quote unsafe chars, but keep the slash, even when it's not
708 # correct, but quoted slashes look too horrible in bookmarks
711 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
717 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
720 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
726 # replace invalid utf8 character with SUBSTITUTION sequence
731 $str = to_utf8
($str);
732 $str = $cgi->escapeHTML($str);
733 if ($opts{'-nbsp'}) {
734 $str =~ s/ / /g;
736 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
740 # quote control characters and escape filename to HTML
745 $str = to_utf8
($str);
746 $str = $cgi->escapeHTML($str);
747 if ($opts{'-nbsp'}) {
748 $str =~ s/ / /g;
750 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
754 # Make control characters "printable", using character escape codes (CEC)
758 my %es = ( # character escape codes, aka escape sequences
759 "\t" => '\t', # tab (HT)
760 "\n" => '\n', # line feed (LF)
761 "\r" => '\r', # carrige return (CR)
762 "\f" => '\f', # form feed (FF)
763 "\b" => '\b', # backspace (BS)
764 "\a" => '\a', # alarm (bell) (BEL)
765 "\e" => '\e', # escape (ESC)
766 "\013" => '\v', # vertical tab (VT)
767 "\000" => '\0', # nul character (NUL)
769 my $chr = ( (exists $es{$cntrl})
771 : sprintf('\%03o', ord($cntrl)) );
772 if ($opts{-nohtml
}) {
775 return "<span class=\"cntrl\">$chr</span>";
779 # Alternatively use unicode control pictures codepoints,
780 # Unicode "printable representation" (PR)
785 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
786 if ($opts{-nohtml
}) {
789 return "<span class=\"cntrl\">$chr</span>";
793 # git may return quoted and escaped filenames
799 my %es = ( # character escape codes, aka escape sequences
800 't' => "\t", # tab (HT, TAB)
801 'n' => "\n", # newline (NL)
802 'r' => "\r", # return (CR)
803 'f' => "\f", # form feed (FF)
804 'b' => "\b", # backspace (BS)
805 'a' => "\a", # alarm (bell) (BEL)
806 'e' => "\e", # escape (ESC)
807 'v' => "\013", # vertical tab (VT)
810 if ($seq =~ m/^[0-7]{1,3}$/) {
811 # octal char sequence
812 return chr(oct($seq));
813 } elsif (exists $es{$seq}) {
814 # C escape sequence, aka character escape code
817 # quoted ordinary character
821 if ($str =~ m/^"(.*)"$/) {
824 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
829 # escape tabs (convert tabs to spaces)
833 while ((my $pos = index($line, "\t")) != -1) {
834 if (my $count = (8 - ($pos % 8))) {
835 my $spaces = ' ' x
$count;
836 $line =~ s/\t/$spaces/;
843 sub project_in_list
{
845 my @list = git_get_projects_list
();
846 return @list && scalar(grep { $_->{'path'} eq $project } @list);
849 ## ----------------------------------------------------------------------
850 ## HTML aware string manipulation
852 # Try to chop given string on a word boundary between position
853 # $len and $len+$add_len. If there is no word boundary there,
854 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
855 # (marking chopped part) would be longer than given string.
859 my $add_len = shift || 10;
860 my $where = shift || 'right'; # 'left' | 'center' | 'right'
862 # allow only $len chars, but don't cut a word if it would fit in $add_len
863 # if it doesn't fit, cut it if it's still longer than the dots we would add
864 # remove chopped character entities entirely
866 # when chopping in the middle, distribute $len into left and right part
867 # return early if chopping wouldn't make string shorter
868 if ($where eq 'center') {
869 return $str if ($len + 5 >= length($str)); # filler is length 5
872 return $str if ($len + 4 >= length($str)); # filler is length 4
875 # regexps: ending and beginning with word part up to $add_len
876 my $endre = qr/.{$len}\w{0,$add_len}/;
877 my $begre = qr/\w{0,$add_len}.{$len}/;
879 if ($where eq 'left') {
880 $str =~ m/^(.*?)($begre)$/;
881 my ($lead, $body) = ($1, $2);
882 if (length($lead) > 4) {
883 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
888 } elsif ($where eq 'center') {
889 $str =~ m/^($endre)(.*)$/;
890 my ($left, $str) = ($1, $2);
891 $str =~ m/^(.*?)($begre)$/;
892 my ($mid, $right) = ($1, $2);
893 if (length($mid) > 5) {
894 $left =~ s/&[^;]*$//;
895 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
898 return "$left$mid$right";
901 $str =~ m/^($endre)(.*)$/;
904 if (length($tail) > 4) {
905 $body =~ s/&[^;]*$//;
912 # takes the same arguments as chop_str, but also wraps a <span> around the
913 # result with a title attribute if it does get chopped. Additionally, the
914 # string is HTML-escaped.
915 sub chop_and_escape_str
{
918 my $chopped = chop_str
(@_);
919 if ($chopped eq $str) {
920 return esc_html
($chopped);
922 $str =~ s/([[:cntrl:]])/?/g;
923 return $cgi->span({-title
=>$str}, esc_html
($chopped));
927 ## ----------------------------------------------------------------------
928 ## functions returning short strings
930 # CSS class for given age value (in seconds)
936 } elsif ($age < 60*60*2) {
938 } elsif ($age < 60*60*24*2) {
945 # convert age in seconds to "nn units ago" string
950 if ($age > 60*60*24*365*2) {
951 $age_str = (int $age/60/60/24/365);
952 $age_str .= " years ago";
953 } elsif ($age > 60*60*24*(365/12)*2) {
954 $age_str = int $age/60/60/24/(365/12);
955 $age_str .= " months ago";
956 } elsif ($age > 60*60*24*7*2) {
957 $age_str = int $age/60/60/24/7;
958 $age_str .= " weeks ago";
959 } elsif ($age > 60*60*24*2) {
960 $age_str = int $age/60/60/24;
961 $age_str .= " days ago";
962 } elsif ($age > 60*60*2) {
963 $age_str = int $age/60/60;
964 $age_str .= " hours ago";
965 } elsif ($age > 60*2) {
966 $age_str = int $age/60;
967 $age_str .= " min ago";
970 $age_str .= " sec ago";
972 $age_str .= " right now";
978 S_IFINVALID
=> 0030000,
979 S_IFGITLINK
=> 0160000,
982 # submodule/subproject, a commit object reference
986 return (($mode & S_IFMT
) == S_IFGITLINK
)
989 # convert file mode in octal to symbolic file mode string
991 my $mode = oct shift;
993 if (S_ISGITLINK
($mode)) {
995 } elsif (S_ISDIR
($mode & S_IFMT
)) {
997 } elsif (S_ISLNK
($mode)) {
999 } elsif (S_ISREG
($mode)) {
1000 # git cares only about the executable bit
1001 if ($mode & S_IXUSR
) {
1002 return '-rwxr-xr-x';
1004 return '-rw-r--r--';
1007 return '----------';
1011 # convert file mode in octal to file type string
1015 if ($mode !~ m/^[0-7]+$/) {
1021 if (S_ISGITLINK
($mode)) {
1023 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1025 } elsif (S_ISLNK
($mode)) {
1027 } elsif (S_ISREG
($mode)) {
1034 # convert file mode in octal to file type description string
1035 sub file_type_long
{
1038 if ($mode !~ m/^[0-7]+$/) {
1044 if (S_ISGITLINK
($mode)) {
1046 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1048 } elsif (S_ISLNK
($mode)) {
1050 } elsif (S_ISREG
($mode)) {
1051 if ($mode & S_IXUSR
) {
1052 return "executable";
1062 ## ----------------------------------------------------------------------
1063 ## functions returning short HTML fragments, or transforming HTML fragments
1064 ## which don't belong to other sections
1066 # format line of commit message.
1067 sub format_log_line_html
{
1070 $line = esc_html
($line, -nbsp
=>1);
1071 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1074 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1075 -class => "text"}, $hash_text);
1076 $line =~ s/$hash_text/$link/;
1081 # format marker of refs pointing to given object
1082 sub format_ref_marker
{
1083 my ($refs, $id) = @_;
1086 if (defined $refs->{$id}) {
1087 foreach my $ref (@{$refs->{$id}}) {
1088 my ($type, $name) = qw();
1089 # e.g. tags/v2.6.11 or heads/next
1090 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1098 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1099 esc_html
($name) . "</span>";
1104 return ' <span class="refs">'. $markers . '</span>';
1110 # format, perhaps shortened and with markers, title line
1111 sub format_subject_html
{
1112 my ($long, $short, $href, $extra) = @_;
1113 $extra = '' unless defined($extra);
1115 if (length($short) < length($long)) {
1116 return $cgi->a({-href
=> $href, -class => "list subject",
1117 -title
=> to_utf8
($long)},
1118 esc_html
($short) . $extra);
1120 return $cgi->a({-href
=> $href, -class => "list subject"},
1121 esc_html
($long) . $extra);
1125 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1126 sub format_git_diff_header_line
{
1128 my $diffinfo = shift;
1129 my ($from, $to) = @_;
1131 if ($diffinfo->{'nparents'}) {
1133 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1134 if ($to->{'href'}) {
1135 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1136 esc_path
($to->{'file'}));
1137 } else { # file was deleted (no href)
1138 $line .= esc_path
($to->{'file'});
1142 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1143 if ($from->{'href'}) {
1144 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1145 'a/' . esc_path
($from->{'file'}));
1146 } else { # file was added (no href)
1147 $line .= 'a/' . esc_path
($from->{'file'});
1150 if ($to->{'href'}) {
1151 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1152 'b/' . esc_path
($to->{'file'}));
1153 } else { # file was deleted
1154 $line .= 'b/' . esc_path
($to->{'file'});
1158 return "<div class=\"diff header\">$line</div>\n";
1161 # format extended diff header line, before patch itself
1162 sub format_extended_diff_header_line
{
1164 my $diffinfo = shift;
1165 my ($from, $to) = @_;
1168 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1169 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1170 esc_path
($from->{'file'}));
1172 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1173 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1174 esc_path
($to->{'file'}));
1176 # match single <mode>
1177 if ($line =~ m/\s(\d{6})$/) {
1178 $line .= '<span class="info"> (' .
1179 file_type_long
($1) .
1183 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1184 # can match only for combined diff
1186 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1187 if ($from->{'href'}[$i]) {
1188 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1190 substr($diffinfo->{'from_id'}[$i],0,7));
1195 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1198 if ($to->{'href'}) {
1199 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1200 substr($diffinfo->{'to_id'},0,7));
1205 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1206 # can match only for ordinary diff
1207 my ($from_link, $to_link);
1208 if ($from->{'href'}) {
1209 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1210 substr($diffinfo->{'from_id'},0,7));
1212 $from_link = '0' x
7;
1214 if ($to->{'href'}) {
1215 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1216 substr($diffinfo->{'to_id'},0,7));
1220 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1221 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1224 return $line . "<br/>\n";
1227 # format from-file/to-file diff header
1228 sub format_diff_from_to_header
{
1229 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1234 #assert($line =~ m/^---/) if DEBUG;
1235 # no extra formatting for "^--- /dev/null"
1236 if (! $diffinfo->{'nparents'}) {
1237 # ordinary (single parent) diff
1238 if ($line =~ m!^--- "?a/!) {
1239 if ($from->{'href'}) {
1241 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1242 esc_path
($from->{'file'}));
1245 esc_path
($from->{'file'});
1248 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1251 # combined diff (merge commit)
1252 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1253 if ($from->{'href'}[$i]) {
1255 $cgi->a({-href
=>href
(action
=>"blobdiff",
1256 hash_parent
=>$diffinfo->{'from_id'}[$i],
1257 hash_parent_base
=>$parents[$i],
1258 file_parent
=>$from->{'file'}[$i],
1259 hash
=>$diffinfo->{'to_id'},
1261 file_name
=>$to->{'file'}),
1263 -title
=>"diff" . ($i+1)},
1266 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1267 esc_path
($from->{'file'}[$i]));
1269 $line = '--- /dev/null';
1271 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1276 #assert($line =~ m/^\+\+\+/) if DEBUG;
1277 # no extra formatting for "^+++ /dev/null"
1278 if ($line =~ m!^\+\+\+ "?b/!) {
1279 if ($to->{'href'}) {
1281 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1282 esc_path
($to->{'file'}));
1285 esc_path
($to->{'file'});
1288 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1293 # create note for patch simplified by combined diff
1294 sub format_diff_cc_simplified
{
1295 my ($diffinfo, @parents) = @_;
1298 $result .= "<div class=\"diff header\">" .
1300 if (!is_deleted
($diffinfo)) {
1301 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1303 hash
=>$diffinfo->{'to_id'},
1304 file_name
=>$diffinfo->{'to_file'}),
1306 esc_path
($diffinfo->{'to_file'}));
1308 $result .= esc_path
($diffinfo->{'to_file'});
1310 $result .= "</div>\n" . # class="diff header"
1311 "<div class=\"diff nodifferences\">" .
1313 "</div>\n"; # class="diff nodifferences"
1318 # format patch (diff) line (not to be used for diff headers)
1319 sub format_diff_line
{
1321 my ($from, $to) = @_;
1322 my $diff_class = "";
1326 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1328 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1329 if ($line =~ m/^\@{3}/) {
1330 $diff_class = " chunk_header";
1331 } elsif ($line =~ m/^\\/) {
1332 $diff_class = " incomplete";
1333 } elsif ($prefix =~ tr/+/+/) {
1334 $diff_class = " add";
1335 } elsif ($prefix =~ tr/-/-/) {
1336 $diff_class = " rem";
1339 # assume ordinary diff
1340 my $char = substr($line, 0, 1);
1342 $diff_class = " add";
1343 } elsif ($char eq '-') {
1344 $diff_class = " rem";
1345 } elsif ($char eq '@') {
1346 $diff_class = " chunk_header";
1347 } elsif ($char eq "\\") {
1348 $diff_class = " incomplete";
1351 $line = untabify
($line);
1352 if ($from && $to && $line =~ m/^\@{2} /) {
1353 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1354 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1356 $from_lines = 0 unless defined $from_lines;
1357 $to_lines = 0 unless defined $to_lines;
1359 if ($from->{'href'}) {
1360 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1361 -class=>"list"}, $from_text);
1363 if ($to->{'href'}) {
1364 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1365 -class=>"list"}, $to_text);
1367 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1368 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1369 return "<div class=\"diff$diff_class\">$line</div>\n";
1370 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1371 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1372 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1374 @from_text = split(' ', $ranges);
1375 for (my $i = 0; $i < @from_text; ++$i) {
1376 ($from_start[$i], $from_nlines[$i]) =
1377 (split(',', substr($from_text[$i], 1)), 0);
1380 $to_text = pop @from_text;
1381 $to_start = pop @from_start;
1382 $to_nlines = pop @from_nlines;
1384 $line = "<span class=\"chunk_info\">$prefix ";
1385 for (my $i = 0; $i < @from_text; ++$i) {
1386 if ($from->{'href'}[$i]) {
1387 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1388 -class=>"list"}, $from_text[$i]);
1390 $line .= $from_text[$i];
1394 if ($to->{'href'}) {
1395 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1396 -class=>"list"}, $to_text);
1400 $line .= " $prefix</span>" .
1401 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1402 return "<div class=\"diff$diff_class\">$line</div>\n";
1404 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1407 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1408 # linked. Pass the hash of the tree/commit to snapshot.
1409 sub format_snapshot_links
{
1411 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1412 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1413 my $num_fmts = @snapshot_fmts;
1414 if ($num_fmts > 1) {
1415 # A parenthesized list of links bearing format names.
1416 # e.g. "snapshot (_tar.gz_ _zip_)"
1417 return "snapshot (" . join(' ', map
1424 }, $known_snapshot_formats{$_}{'display'})
1425 , @snapshot_fmts) . ")";
1426 } elsif ($num_fmts == 1) {
1427 # A single "snapshot" link whose tooltip bears the format name.
1429 my ($fmt) = @snapshot_fmts;
1435 snapshot_format
=>$fmt
1437 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1439 } else { # $num_fmts == 0
1444 ## ----------------------------------------------------------------------
1445 ## git utility subroutines, invoking git commands
1447 # returns path to the core git executable and the --git-dir parameter as list
1449 return $GIT, '--git-dir='.$git_dir;
1452 # returns path to the core git executable and the --git-dir parameter as string
1454 return join(' ', git_cmd
());
1457 # get HEAD ref of given project as hash
1458 sub git_get_head_hash
{
1459 my $project = shift;
1460 my $o_git_dir = $git_dir;
1462 $git_dir = "$projectroot/$project";
1463 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1466 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1470 if (defined $o_git_dir) {
1471 $git_dir = $o_git_dir;
1476 # get type of given object
1480 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1482 close $fd or return;
1487 # repository configuration
1488 our $config_file = '';
1491 # store multiple values for single key as anonymous array reference
1492 # single values stored directly in the hash, not as [ <value> ]
1493 sub hash_set_multi
{
1494 my ($hash, $key, $value) = @_;
1496 if (!exists $hash->{$key}) {
1497 $hash->{$key} = $value;
1498 } elsif (!ref $hash->{$key}) {
1499 $hash->{$key} = [ $hash->{$key}, $value ];
1501 push @{$hash->{$key}}, $value;
1505 # return hash of git project configuration
1506 # optionally limited to some section, e.g. 'gitweb'
1507 sub git_parse_project_config
{
1508 my $section_regexp = shift;
1513 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1516 while (my $keyval = <$fh>) {
1518 my ($key, $value) = split(/\n/, $keyval, 2);
1520 hash_set_multi
(\
%config, $key, $value)
1521 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1528 # convert config value to boolean, 'true' or 'false'
1529 # no value, number > 0, 'true' and 'yes' values are true
1530 # rest of values are treated as false (never as error)
1531 sub config_to_bool
{
1534 # strip leading and trailing whitespace
1538 return (!defined $val || # section.key
1539 ($val =~ /^\d+$/ && $val) || # section.key = 1
1540 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1543 # convert config value to simple decimal number
1544 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1545 # to be multiplied by 1024, 1048576, or 1073741824
1549 # strip leading and trailing whitespace
1553 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1555 # unknown unit is treated as 1
1556 return $num * ($unit eq 'g' ? 1073741824 :
1557 $unit eq 'm' ? 1048576 :
1558 $unit eq 'k' ? 1024 : 1);
1563 # convert config value to array reference, if needed
1564 sub config_to_multi
{
1567 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1570 sub git_get_project_config
{
1571 my ($key, $type) = @_;
1574 return unless ($key);
1575 $key =~ s/^gitweb\.//;
1576 return if ($key =~ m/\W/);
1579 if (defined $type) {
1582 unless ($type eq 'bool' || $type eq 'int');
1586 if (!defined $config_file ||
1587 $config_file ne "$git_dir/config") {
1588 %config = git_parse_project_config
('gitweb');
1589 $config_file = "$git_dir/config";
1593 if (!defined $type) {
1594 return $config{"gitweb.$key"};
1595 } elsif ($type eq 'bool') {
1596 # backward compatibility: 'git config --bool' returns true/false
1597 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1598 } elsif ($type eq 'int') {
1599 return config_to_int
($config{"gitweb.$key"});
1601 return $config{"gitweb.$key"};
1604 # get hash of given path at given ref
1605 sub git_get_hash_by_path
{
1607 my $path = shift || return undef;
1612 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1613 or die_error
(undef, "Open git-ls-tree failed");
1615 close $fd or return undef;
1617 if (!defined $line) {
1618 # there is no tree or hash given by $path at $base
1622 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1623 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1624 if (defined $type && $type ne $2) {
1625 # type doesn't match
1631 # get path of entry with given hash at given tree-ish (ref)
1632 # used to get 'from' filename for combined diff (merge commit) for renames
1633 sub git_get_path_by_hash
{
1634 my $base = shift || return;
1635 my $hash = shift || return;
1639 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1641 while (my $line = <$fd>) {
1644 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1645 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1646 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1655 ## ......................................................................
1656 ## git utility functions, directly accessing git repository
1658 sub git_get_project_description
{
1661 $git_dir = "$projectroot/$path";
1662 open my $fd, "$git_dir/description"
1663 or return git_get_project_config
('description');
1666 if (defined $descr) {
1672 sub git_get_project_url_list
{
1675 $git_dir = "$projectroot/$path";
1676 open my $fd, "$git_dir/cloneurl"
1677 or return wantarray ?
1678 @{ config_to_multi
(git_get_project_config
('url')) } :
1679 config_to_multi
(git_get_project_config
('url'));
1680 my @git_project_url_list = map { chomp; $_ } <$fd>;
1683 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1686 sub git_get_projects_list
{
1691 $filter =~ s/\.git$//;
1693 my ($check_forks) = gitweb_check_feature
('forks');
1695 if (-d
$projects_list) {
1696 # search in directory
1697 my $dir = $projects_list . ($filter ? "/$filter" : '');
1698 # remove the trailing "/"
1700 my $pfxlen = length("$dir");
1701 my $pfxdepth = ($dir =~ tr!/!!);
1704 follow_fast
=> 1, # follow symbolic links
1705 follow_skip
=> 2, # ignore duplicates
1706 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1708 # skip project-list toplevel, if we get it.
1709 return if (m!^[/.]$!);
1710 # only directories can be git repositories
1711 return unless (-d
$_);
1712 # don't traverse too deep (Find is super slow on os x)
1713 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1714 $File::Find
::prune
= 1;
1718 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1719 # we check related file in $projectroot
1720 if ($check_forks and $subdir =~ m
#/.#) {
1721 $File::Find
::prune
= 1;
1722 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1723 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1724 $File::Find
::prune
= 1;
1729 } elsif (-f
$projects_list) {
1730 # read from file(url-encoded):
1731 # 'git%2Fgit.git Linus+Torvalds'
1732 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1733 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1735 open my ($fd), $projects_list or return;
1737 while (my $line = <$fd>) {
1739 my ($path, $owner) = split ' ', $line;
1740 $path = unescape
($path);
1741 $owner = unescape
($owner);
1742 if (!defined $path) {
1745 if ($filter ne '') {
1746 # looking for forks;
1747 my $pfx = substr($path, 0, length($filter));
1748 if ($pfx ne $filter) {
1751 my $sfx = substr($path, length($filter));
1752 if ($sfx !~ /^\/.*\
.git
$/) {
1755 } elsif ($check_forks) {
1757 foreach my $filter (keys %paths) {
1758 # looking for forks;
1759 my $pfx = substr($path, 0, length($filter));
1760 if ($pfx ne $filter) {
1763 my $sfx = substr($path, length($filter));
1764 if ($sfx !~ /^\/.*\
.git
$/) {
1767 # is a fork, don't include it in
1772 if (check_export_ok
("$projectroot/$path")) {
1775 owner
=> to_utf8
($owner),
1778 (my $forks_path = $path) =~ s/\.git$//;
1779 $paths{$forks_path}++;
1787 our $gitweb_project_owner = undef;
1788 sub git_get_project_list_from_file
{
1790 return if (defined $gitweb_project_owner);
1792 $gitweb_project_owner = {};
1793 # read from file (url-encoded):
1794 # 'git%2Fgit.git Linus+Torvalds'
1795 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1796 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1797 if (-f
$projects_list) {
1798 open (my $fd , $projects_list);
1799 while (my $line = <$fd>) {
1801 my ($pr, $ow) = split ' ', $line;
1802 $pr = unescape
($pr);
1803 $ow = unescape
($ow);
1804 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1810 sub git_get_project_owner
{
1811 my $project = shift;
1814 return undef unless $project;
1815 $git_dir = "$projectroot/$project";
1817 if (!defined $gitweb_project_owner) {
1818 git_get_project_list_from_file
();
1821 if (exists $gitweb_project_owner->{$project}) {
1822 $owner = $gitweb_project_owner->{$project};
1824 if (!defined $owner){
1825 $owner = git_get_project_config
('owner');
1827 if (!defined $owner) {
1828 $owner = get_file_owner
("$git_dir");
1834 sub git_get_last_activity
{
1838 $git_dir = "$projectroot/$path";
1839 open($fd, "-|", git_cmd
(), 'for-each-ref',
1840 '--format=%(committer)',
1841 '--sort=-committerdate',
1843 'refs/heads') or return;
1844 my $most_recent = <$fd>;
1845 close $fd or return;
1846 if (defined $most_recent &&
1847 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1849 my $age = time - $timestamp;
1850 return ($age, age_string
($age));
1852 return (undef, undef);
1855 sub git_get_references
{
1856 my $type = shift || "";
1858 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1859 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1860 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1861 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1864 while (my $line = <$fd>) {
1866 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1867 if (defined $refs{$1}) {
1868 push @{$refs{$1}}, $2;
1874 close $fd or return;
1878 sub git_get_rev_name_tags
{
1879 my $hash = shift || return undef;
1881 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1883 my $name_rev = <$fd>;
1886 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1889 # catches also '$hash undefined' output
1894 ## ----------------------------------------------------------------------
1895 ## parse to hash functions
1899 my $tz = shift || "-0000";
1902 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1903 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1904 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1905 $date{'hour'} = $hour;
1906 $date{'minute'} = $min;
1907 $date{'mday'} = $mday;
1908 $date{'day'} = $days[$wday];
1909 $date{'month'} = $months[$mon];
1910 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1911 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1912 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1913 $mday, $months[$mon], $hour ,$min;
1914 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1915 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1917 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1918 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1919 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1920 $date{'hour_local'} = $hour;
1921 $date{'minute_local'} = $min;
1922 $date{'tz_local'} = $tz;
1923 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1924 1900+$year, $mon+1, $mday,
1925 $hour, $min, $sec, $tz);
1934 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1935 $tag{'id'} = $tag_id;
1936 while (my $line = <$fd>) {
1938 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1939 $tag{'object'} = $1;
1940 } elsif ($line =~ m/^type (.+)$/) {
1942 } elsif ($line =~ m/^tag (.+)$/) {
1944 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1945 $tag{'author'} = $1;
1948 } elsif ($line =~ m/--BEGIN/) {
1949 push @comment, $line;
1951 } elsif ($line eq "") {
1955 push @comment, <$fd>;
1956 $tag{'comment'} = \
@comment;
1957 close $fd or return;
1958 if (!defined $tag{'name'}) {
1964 sub parse_commit_text
{
1965 my ($commit_text, $withparents) = @_;
1966 my @commit_lines = split '\n', $commit_text;
1969 pop @commit_lines; # Remove '\0'
1971 if (! @commit_lines) {
1975 my $header = shift @commit_lines;
1976 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1979 ($co{'id'}, my @parents) = split ' ', $header;
1980 while (my $line = shift @commit_lines) {
1981 last if $line eq "\n";
1982 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1984 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1986 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1988 $co{'author_epoch'} = $2;
1989 $co{'author_tz'} = $3;
1990 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1991 $co{'author_name'} = $1;
1992 $co{'author_email'} = $2;
1994 $co{'author_name'} = $co{'author'};
1996 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1997 $co{'committer'} = $1;
1998 $co{'committer_epoch'} = $2;
1999 $co{'committer_tz'} = $3;
2000 $co{'committer_name'} = $co{'committer'};
2001 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2002 $co{'committer_name'} = $1;
2003 $co{'committer_email'} = $2;
2005 $co{'committer_name'} = $co{'committer'};
2009 if (!defined $co{'tree'}) {
2012 $co{'parents'} = \
@parents;
2013 $co{'parent'} = $parents[0];
2015 foreach my $title (@commit_lines) {
2018 $co{'title'} = chop_str
($title, 80, 5);
2019 # remove leading stuff of merges to make the interesting part visible
2020 if (length($title) > 50) {
2021 $title =~ s/^Automatic //;
2022 $title =~ s/^merge (of|with) /Merge ... /i;
2023 if (length($title) > 50) {
2024 $title =~ s/(http|rsync):\/\///;
2026 if (length($title) > 50) {
2027 $title =~ s/(master|www|rsync)\.//;
2029 if (length($title) > 50) {
2030 $title =~ s/kernel.org:?//;
2032 if (length($title) > 50) {
2033 $title =~ s/\/pub\/scm//;
2036 $co{'title_short'} = chop_str
($title, 50, 5);
2040 if ($co{'title'} eq "") {
2041 $co{'title'} = $co{'title_short'} = '(no commit message)';
2043 # remove added spaces
2044 foreach my $line (@commit_lines) {
2047 $co{'comment'} = \
@commit_lines;
2049 my $age = time - $co{'committer_epoch'};
2051 $co{'age_string'} = age_string
($age);
2052 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2053 if ($age > 60*60*24*7*2) {
2054 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2055 $co{'age_string_age'} = $co{'age_string'};
2057 $co{'age_string_date'} = $co{'age_string'};
2058 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2064 my ($commit_id) = @_;
2069 open my $fd, "-|", git_cmd
(), "rev-list",
2075 or die_error
(undef, "Open git-rev-list failed");
2076 %co = parse_commit_text
(<$fd>, 1);
2083 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2091 open my $fd, "-|", git_cmd
(), "rev-list",
2094 ("--max-count=" . $maxcount),
2095 ("--skip=" . $skip),
2099 ($filename ? ($filename) : ())
2100 or die_error
(undef, "Open git-rev-list failed");
2101 while (my $line = <$fd>) {
2102 my %co = parse_commit_text
($line);
2107 return wantarray ? @cos : \
@cos;
2110 # parse ref from ref_file, given by ref_id, with given type
2112 my $ref_file = shift;
2114 my $type = shift || git_get_type
($ref_id);
2117 $ref_item{'type'} = $type;
2118 $ref_item{'id'} = $ref_id;
2119 $ref_item{'epoch'} = 0;
2120 $ref_item{'age'} = "unknown";
2121 if ($type eq "tag") {
2122 my %tag = parse_tag
($ref_id);
2123 $ref_item{'comment'} = $tag{'comment'};
2124 if ($tag{'type'} eq "commit") {
2125 my %co = parse_commit
($tag{'object'});
2126 $ref_item{'epoch'} = $co{'committer_epoch'};
2127 $ref_item{'age'} = $co{'age_string'};
2128 } elsif (defined($tag{'epoch'})) {
2129 my $age = time - $tag{'epoch'};
2130 $ref_item{'epoch'} = $tag{'epoch'};
2131 $ref_item{'age'} = age_string
($age);
2133 $ref_item{'reftype'} = $tag{'type'};
2134 $ref_item{'name'} = $tag{'name'};
2135 $ref_item{'refid'} = $tag{'object'};
2136 } elsif ($type eq "commit"){
2137 my %co = parse_commit
($ref_id);
2138 $ref_item{'reftype'} = "commit";
2139 $ref_item{'name'} = $ref_file;
2140 $ref_item{'title'} = $co{'title'};
2141 $ref_item{'refid'} = $ref_id;
2142 $ref_item{'epoch'} = $co{'committer_epoch'};
2143 $ref_item{'age'} = $co{'age_string'};
2145 $ref_item{'reftype'} = $type;
2146 $ref_item{'name'} = $ref_file;
2147 $ref_item{'refid'} = $ref_id;
2153 # parse line of git-diff-tree "raw" output
2154 sub parse_difftree_raw_line
{
2158 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2159 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2160 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2161 $res{'from_mode'} = $1;
2162 $res{'to_mode'} = $2;
2163 $res{'from_id'} = $3;
2165 $res{'status'} = $res{'status_str'} = $5;
2166 $res{'similarity'} = $6;
2167 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2168 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2170 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2173 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2174 # combined diff (for merge commit)
2175 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2176 $res{'nparents'} = length($1);
2177 $res{'from_mode'} = [ split(' ', $2) ];
2178 $res{'to_mode'} = pop @{$res{'from_mode'}};
2179 $res{'from_id'} = [ split(' ', $3) ];
2180 $res{'to_id'} = pop @{$res{'from_id'}};
2181 $res{'status_str'} = $4;
2182 $res{'status'} = [ split('', $4) ];
2183 $res{'to_file'} = unquote
($5);
2185 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2186 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2187 $res{'commit'} = $1;
2190 return wantarray ? %res : \
%res;
2193 # wrapper: return parsed line of git-diff-tree "raw" output
2194 # (the argument might be raw line, or parsed info)
2195 sub parsed_difftree_line
{
2196 my $line_or_ref = shift;
2198 if (ref($line_or_ref) eq "HASH") {
2199 # pre-parsed (or generated by hand)
2200 return $line_or_ref;
2202 return parse_difftree_raw_line
($line_or_ref);
2206 # parse line of git-ls-tree output
2207 sub parse_ls_tree_line
($;%) {
2212 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2213 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2221 $res{'name'} = unquote
($4);
2224 return wantarray ? %res : \
%res;
2227 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2228 sub parse_from_to_diffinfo
{
2229 my ($diffinfo, $from, $to, @parents) = @_;
2231 if ($diffinfo->{'nparents'}) {
2233 $from->{'file'} = [];
2234 $from->{'href'} = [];
2235 fill_from_file_info
($diffinfo, @parents)
2236 unless exists $diffinfo->{'from_file'};
2237 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2238 $from->{'file'}[$i] =
2239 defined $diffinfo->{'from_file'}[$i] ?
2240 $diffinfo->{'from_file'}[$i] :
2241 $diffinfo->{'to_file'};
2242 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2243 $from->{'href'}[$i] = href
(action
=>"blob",
2244 hash_base
=>$parents[$i],
2245 hash
=>$diffinfo->{'from_id'}[$i],
2246 file_name
=>$from->{'file'}[$i]);
2248 $from->{'href'}[$i] = undef;
2252 # ordinary (not combined) diff
2253 $from->{'file'} = $diffinfo->{'from_file'};
2254 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2255 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2256 hash
=>$diffinfo->{'from_id'},
2257 file_name
=>$from->{'file'});
2259 delete $from->{'href'};
2263 $to->{'file'} = $diffinfo->{'to_file'};
2264 if (!is_deleted
($diffinfo)) { # file exists in result
2265 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2266 hash
=>$diffinfo->{'to_id'},
2267 file_name
=>$to->{'file'});
2269 delete $to->{'href'};
2273 ## ......................................................................
2274 ## parse to array of hashes functions
2276 sub git_get_heads_list
{
2280 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2281 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2282 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2285 while (my $line = <$fd>) {
2289 my ($refinfo, $committerinfo) = split(/\0/, $line);
2290 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2291 my ($committer, $epoch, $tz) =
2292 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2293 $ref_item{'fullname'} = $name;
2294 $name =~ s!^refs/heads/!!;
2296 $ref_item{'name'} = $name;
2297 $ref_item{'id'} = $hash;
2298 $ref_item{'title'} = $title || '(no commit message)';
2299 $ref_item{'epoch'} = $epoch;
2301 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2303 $ref_item{'age'} = "unknown";
2306 push @headslist, \
%ref_item;
2310 return wantarray ? @headslist : \
@headslist;
2313 sub git_get_tags_list
{
2317 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2318 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2319 '--format=%(objectname) %(objecttype) %(refname) '.
2320 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2323 while (my $line = <$fd>) {
2327 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2328 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2329 my ($creator, $epoch, $tz) =
2330 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2331 $ref_item{'fullname'} = $name;
2332 $name =~ s!^refs/tags/!!;
2334 $ref_item{'type'} = $type;
2335 $ref_item{'id'} = $id;
2336 $ref_item{'name'} = $name;
2337 if ($type eq "tag") {
2338 $ref_item{'subject'} = $title;
2339 $ref_item{'reftype'} = $reftype;
2340 $ref_item{'refid'} = $refid;
2342 $ref_item{'reftype'} = $type;
2343 $ref_item{'refid'} = $id;
2346 if ($type eq "tag" || $type eq "commit") {
2347 $ref_item{'epoch'} = $epoch;
2349 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2351 $ref_item{'age'} = "unknown";
2355 push @tagslist, \
%ref_item;
2359 return wantarray ? @tagslist : \
@tagslist;
2362 ## ----------------------------------------------------------------------
2363 ## filesystem-related functions
2365 sub get_file_owner
{
2368 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2369 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2370 if (!defined $gcos) {
2374 $owner =~ s/[,;].*$//;
2375 return to_utf8
($owner);
2378 ## ......................................................................
2379 ## mimetype related functions
2381 sub mimetype_guess_file
{
2382 my $filename = shift;
2383 my $mimemap = shift;
2384 -r
$mimemap or return undef;
2387 open(MIME
, $mimemap) or return undef;
2389 next if m/^#/; # skip comments
2390 my ($mime, $exts) = split(/\t+/);
2391 if (defined $exts) {
2392 my @exts = split(/\s+/, $exts);
2393 foreach my $ext (@exts) {
2394 $mimemap{$ext} = $mime;
2400 $filename =~ /\.([^.]*)$/;
2401 return $mimemap{$1};
2404 sub mimetype_guess
{
2405 my $filename = shift;
2407 $filename =~ /\./ or return undef;
2409 if ($mimetypes_file) {
2410 my $file = $mimetypes_file;
2411 if ($file !~ m!^/!) { # if it is relative path
2412 # it is relative to project
2413 $file = "$projectroot/$project/$file";
2415 $mime = mimetype_guess_file
($filename, $file);
2417 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2423 my $filename = shift;
2426 my $mime = mimetype_guess
($filename);
2427 $mime and return $mime;
2431 return $default_blob_plain_mimetype unless $fd;
2434 return 'text/plain' .
2435 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2436 } elsif (! $filename) {
2437 return 'application/octet-stream';
2438 } elsif ($filename =~ m/\.png$/i) {
2440 } elsif ($filename =~ m/\.gif$/i) {
2442 } elsif ($filename =~ m/\.jpe?g$/i) {
2443 return 'image/jpeg';
2445 return 'application/octet-stream';
2449 ## ======================================================================
2450 ## functions printing HTML: header, footer, error page
2452 sub git_header_html
{
2453 my $status = shift || "200 OK";
2454 my $expires = shift;
2456 my $title = "$site_name";
2457 if (defined $project) {
2458 $title .= " - " . to_utf8
($project);
2459 if (defined $action) {
2460 $title .= "/$action";
2461 if (defined $file_name) {
2462 $title .= " - " . esc_path
($file_name);
2463 if ($action eq "tree" && $file_name !~ m
|/$|) {
2470 # require explicit support from the UA if we are to send the page as
2471 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2472 # we have to do this because MSIE sometimes globs '*/*', pretending to
2473 # support xhtml+xml but choking when it gets what it asked for.
2474 if (defined $cgi->http('HTTP_ACCEPT') &&
2475 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2476 $cgi->Accept('application/xhtml+xml') != 0) {
2477 $content_type = 'application/xhtml+xml';
2479 $content_type = 'text/html';
2481 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2482 -status
=> $status, -expires
=> $expires);
2483 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2485 <?xml version="1.0" encoding="utf-8"?>
2486 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2487 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2488 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2489 <!-- git core binaries version $git_version -->
2491 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2492 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2493 <meta name="robots" content="index, nofollow"/>
2494 <title>$title</title>
2496 # print out each stylesheet that exist
2497 if (defined $stylesheet) {
2498 #provides backwards capability for those people who define style sheet in a config file
2499 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2501 foreach my $stylesheet (@stylesheets) {
2502 next unless $stylesheet;
2503 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2506 if (defined $project) {
2507 printf('<link rel="alternate" title="%s log RSS feed" '.
2508 'href="%s" type="application/rss+xml" />'."\n",
2509 esc_param
($project), href
(action
=>"rss"));
2510 printf('<link rel="alternate" title="%s log RSS feed (no merges)" '.
2511 'href="%s" type="application/rss+xml" />'."\n",
2512 esc_param
($project), href
(action
=>"rss",
2513 extra_options
=>"--no-merges"));
2514 printf('<link rel="alternate" title="%s log Atom feed" '.
2515 'href="%s" type="application/atom+xml" />'."\n",
2516 esc_param
($project), href
(action
=>"atom"));
2517 printf('<link rel="alternate" title="%s log Atom feed (no merges)" '.
2518 'href="%s" type="application/atom+xml" />'."\n",
2519 esc_param
($project), href
(action
=>"atom",
2520 extra_options
=>"--no-merges"));
2522 printf('<link rel="alternate" title="%s projects list" '.
2523 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2524 $site_name, href
(project
=>undef, action
=>"project_index"));
2525 printf('<link rel="alternate" title="%s projects feeds" '.
2526 'href="%s" type="text/x-opml"/>'."\n",
2527 $site_name, href
(project
=>undef, action
=>"opml"));
2529 if (defined $favicon) {
2530 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2536 if (-f
$site_header) {
2537 open (my $fd, $site_header);
2542 print "<div class=\"page_header\">\n" .
2543 $cgi->a({-href
=> esc_url
($logo_url),
2544 -title
=> $logo_label},
2545 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2546 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2547 if (defined $project) {
2548 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2549 if (defined $action) {
2556 my ($have_search) = gitweb_check_feature
('search');
2557 if ((defined $project) && ($have_search)) {
2558 if (!defined $searchtext) {
2562 if (defined $hash_base) {
2563 $search_hash = $hash_base;
2564 } elsif (defined $hash) {
2565 $search_hash = $hash;
2567 $search_hash = "HEAD";
2569 my $action = $my_uri;
2570 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2571 if ($use_pathinfo) {
2572 $action .= "/$project";
2574 $cgi->param("p", $project);
2576 $cgi->param("a", "search");
2577 $cgi->param("h", $search_hash);
2578 print $cgi->startform(-method => "get", -action
=> $action) .
2579 "<div class=\"search\">\n" .
2580 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2581 $cgi->hidden(-name
=> "a") . "\n" .
2582 $cgi->hidden(-name
=> "h") . "\n" .
2583 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2584 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2585 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2587 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2589 $cgi->end_form() . "\n";
2593 sub git_footer_html
{
2594 print "<div class=\"page_footer\">\n";
2595 if (defined $project) {
2596 my $descr = git_get_project_description
($project);
2597 if (defined $descr) {
2598 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2600 print $cgi->a({-href
=> href
(action
=>"rss"),
2601 -class => "rss_logo"}, "RSS") . " ";
2602 print $cgi->a({-href
=> href
(action
=>"atom"),
2603 -class => "rss_logo"}, "Atom") . "\n";
2605 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2606 -class => "rss_logo"}, "OPML") . " ";
2607 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2608 -class => "rss_logo"}, "TXT") . "\n";
2612 if (-f
$site_footer) {
2613 open (my $fd, $site_footer);
2623 my $status = shift || "403 Forbidden";
2624 my $error = shift || "Malformed query, file missing or permission denied";
2626 git_header_html
($status);
2628 <div class="page_body">
2638 ## ----------------------------------------------------------------------
2639 ## functions printing or outputting HTML: navigation
2641 sub git_print_page_nav
{
2642 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2643 $extra = '' if !defined $extra; # pager or formats
2645 my @navs = qw(summary shortlog log commit commitdiff tree);
2647 @navs = grep { $_ ne $suppress } @navs;
2650 my %arg = map { $_ => {action
=>$_} } @navs;
2651 if (defined $head) {
2652 for (qw(commit commitdiff)) {
2653 $arg{$_}{'hash'} = $head;
2655 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2656 for (qw(shortlog log)) {
2657 $arg{$_}{'hash'} = $head;
2661 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2662 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2664 print "<div class=\"page_nav\">\n" .
2666 map { $_ eq $current ?
2667 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2669 print "<br/>\n$extra<br/>\n" .
2673 sub format_paging_nav
{
2674 my ($action, $hash, $head, $page, $nrevs) = @_;
2678 if ($hash ne $head || $page) {
2679 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2681 $paging_nav .= "HEAD";
2685 $paging_nav .= " ⋅ " .
2686 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2687 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2689 $paging_nav .= " ⋅ prev";
2692 if ($nrevs >= (100 * ($page+1)-1)) {
2693 $paging_nav .= " ⋅ " .
2694 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2695 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2697 $paging_nav .= " ⋅ next";
2703 ## ......................................................................
2704 ## functions printing or outputting HTML: div
2706 sub git_print_header_div
{
2707 my ($action, $title, $hash, $hash_base) = @_;
2710 $args{'action'} = $action;
2711 $args{'hash'} = $hash if $hash;
2712 $args{'hash_base'} = $hash_base if $hash_base;
2714 print "<div class=\"header\">\n" .
2715 $cgi->a({-href
=> href
(%args), -class => "title"},
2716 $title ? $title : $action) .
2720 #sub git_print_authorship (\%) {
2721 sub git_print_authorship
{
2724 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2725 print "<div class=\"author_date\">" .
2726 esc_html
($co->{'author_name'}) .
2728 if ($ad{'hour_local'} < 6) {
2729 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2730 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2732 printf(" (%02d:%02d %s)",
2733 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2738 sub git_print_page_path
{
2744 print "<div class=\"page_path\">";
2745 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2746 -title
=> 'tree root'}, to_utf8
("[$project]"));
2748 if (defined $name) {
2749 my @dirname = split '/', $name;
2750 my $basename = pop @dirname;
2753 foreach my $dir (@dirname) {
2754 $fullname .= ($fullname ? '/' : '') . $dir;
2755 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2757 -title
=> $fullname}, esc_path
($dir));
2760 if (defined $type && $type eq 'blob') {
2761 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2763 -title
=> $name}, esc_path
($basename));
2764 } elsif (defined $type && $type eq 'tree') {
2765 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2767 -title
=> $name}, esc_path
($basename));
2770 print esc_path
($basename);
2773 print "<br/></div>\n";
2776 # sub git_print_log (\@;%) {
2777 sub git_print_log
($;%) {
2781 if ($opts{'-remove_title'}) {
2782 # remove title, i.e. first line of log
2785 # remove leading empty lines
2786 while (defined $log->[0] && $log->[0] eq "") {
2793 foreach my $line (@$log) {
2794 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2797 if (! $opts{'-remove_signoff'}) {
2798 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2801 # remove signoff lines
2808 # print only one empty line
2809 # do not print empty line after signoff
2811 next if ($empty || $signoff);
2817 print format_log_line_html
($line) . "<br/>\n";
2820 if ($opts{'-final_empty_line'}) {
2821 # end with single empty line
2822 print "<br/>\n" unless $empty;
2826 # return link target (what link points to)
2827 sub git_get_link_target
{
2832 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2836 $link_target = <$fd>;
2841 return $link_target;
2844 # given link target, and the directory (basedir) the link is in,
2845 # return target of link relative to top directory (top tree);
2846 # return undef if it is not possible (including absolute links).
2847 sub normalize_link_target
{
2848 my ($link_target, $basedir, $hash_base) = @_;
2850 # we can normalize symlink target only if $hash_base is provided
2851 return unless $hash_base;
2853 # absolute symlinks (beginning with '/') cannot be normalized
2854 return if (substr($link_target, 0, 1) eq '/');
2856 # normalize link target to path from top (root) tree (dir)
2859 $path = $basedir . '/' . $link_target;
2861 # we are in top (root) tree (dir)
2862 $path = $link_target;
2865 # remove //, /./, and /../
2867 foreach my $part (split('/', $path)) {
2868 # discard '.' and ''
2869 next if (!$part || $part eq '.');
2871 if ($part eq '..') {
2875 # link leads outside repository (outside top dir)
2879 push @path_parts, $part;
2882 $path = join('/', @path_parts);
2887 # print tree entry (row of git_tree), but without encompassing <tr> element
2888 sub git_print_tree_entry
{
2889 my ($t, $basedir, $hash_base, $have_blame) = @_;
2892 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2894 # The format of a table row is: mode list link. Where mode is
2895 # the mode of the entry, list is the name of the entry, an href,
2896 # and link is the action links of the entry.
2898 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2899 if ($t->{'type'} eq "blob") {
2900 print "<td class=\"list\">" .
2901 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2902 file_name
=>"$basedir$t->{'name'}", %base_key),
2903 -class => "list"}, esc_path
($t->{'name'}));
2904 if (S_ISLNK
(oct $t->{'mode'})) {
2905 my $link_target = git_get_link_target
($t->{'hash'});
2907 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2908 if (defined $norm_target) {
2910 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2911 file_name
=>$norm_target),
2912 -title
=> $norm_target}, esc_path
($link_target));
2914 print " -> " . esc_path
($link_target);
2919 print "<td class=\"link\">";
2920 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2921 file_name
=>"$basedir$t->{'name'}", %base_key)},
2925 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2926 file_name
=>"$basedir$t->{'name'}", %base_key)},
2929 if (defined $hash_base) {
2931 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2932 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2936 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2937 file_name
=>"$basedir$t->{'name'}")},
2941 } elsif ($t->{'type'} eq "tree") {
2942 print "<td class=\"list\">";
2943 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2944 file_name
=>"$basedir$t->{'name'}", %base_key)},
2945 esc_path
($t->{'name'}));
2947 print "<td class=\"link\">";
2948 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2949 file_name
=>"$basedir$t->{'name'}", %base_key)},
2951 if (defined $hash_base) {
2953 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2954 file_name
=>"$basedir$t->{'name'}")},
2959 # unknown object: we can only present history for it
2960 # (this includes 'commit' object, i.e. submodule support)
2961 print "<td class=\"list\">" .
2962 esc_path
($t->{'name'}) .
2964 print "<td class=\"link\">";
2965 if (defined $hash_base) {
2966 print $cgi->a({-href
=> href
(action
=>"history",
2967 hash_base
=>$hash_base,
2968 file_name
=>"$basedir$t->{'name'}")},
2975 ## ......................................................................
2976 ## functions printing large fragments of HTML
2978 # get pre-image filenames for merge (combined) diff
2979 sub fill_from_file_info
{
2980 my ($diff, @parents) = @_;
2982 $diff->{'from_file'} = [ ];
2983 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2984 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2985 if ($diff->{'status'}[$i] eq 'R' ||
2986 $diff->{'status'}[$i] eq 'C') {
2987 $diff->{'from_file'}[$i] =
2988 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2995 # is current raw difftree line of file deletion
2997 my $diffinfo = shift;
2999 return $diffinfo->{'status_str'} =~ /D/;
3002 # does patch correspond to [previous] difftree raw line
3003 # $diffinfo - hashref of parsed raw diff format
3004 # $patchinfo - hashref of parsed patch diff format
3005 # (the same keys as in $diffinfo)
3006 sub is_patch_split
{
3007 my ($diffinfo, $patchinfo) = @_;
3009 return defined $diffinfo && defined $patchinfo
3010 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3014 sub git_difftree_body
{
3015 my ($difftree, $hash, @parents) = @_;
3016 my ($parent) = $parents[0];
3017 my ($have_blame) = gitweb_check_feature
('blame');
3018 print "<div class=\"list_head\">\n";
3019 if ($#{$difftree} > 10) {
3020 print(($#{$difftree} + 1) . " files changed:\n");
3024 print "<table class=\"" .
3025 (@parents > 1 ? "combined " : "") .
3028 # header only for combined diff in 'commitdiff' view
3029 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3032 print "<thead><tr>\n" .
3033 "<th></th><th></th>\n"; # filename, patchN link
3034 for (my $i = 0; $i < @parents; $i++) {
3035 my $par = $parents[$i];
3037 $cgi->a({-href
=> href
(action
=>"commitdiff",
3038 hash
=>$hash, hash_parent
=>$par),
3039 -title
=> 'commitdiff to parent number ' .
3040 ($i+1) . ': ' . substr($par,0,7)},
3044 print "</tr></thead>\n<tbody>\n";
3049 foreach my $line (@{$difftree}) {
3050 my $diff = parsed_difftree_line
($line);
3053 print "<tr class=\"dark\">\n";
3055 print "<tr class=\"light\">\n";
3059 if (exists $diff->{'nparents'}) { # combined diff
3061 fill_from_file_info
($diff, @parents)
3062 unless exists $diff->{'from_file'};
3064 if (!is_deleted
($diff)) {
3065 # file exists in the result (child) commit
3067 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3068 file_name
=>$diff->{'to_file'},
3070 -class => "list"}, esc_path
($diff->{'to_file'})) .
3074 esc_path
($diff->{'to_file'}) .
3078 if ($action eq 'commitdiff') {
3081 print "<td class=\"link\">" .
3082 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3087 my $has_history = 0;
3088 my $not_deleted = 0;
3089 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3090 my $hash_parent = $parents[$i];
3091 my $from_hash = $diff->{'from_id'}[$i];
3092 my $from_path = $diff->{'from_file'}[$i];
3093 my $status = $diff->{'status'}[$i];
3095 $has_history ||= ($status ne 'A');
3096 $not_deleted ||= ($status ne 'D');
3098 if ($status eq 'A') {
3099 print "<td class=\"link\" align=\"right\"> | </td>\n";
3100 } elsif ($status eq 'D') {
3101 print "<td class=\"link\">" .
3102 $cgi->a({-href
=> href
(action
=>"blob",
3105 file_name
=>$from_path)},
3109 if ($diff->{'to_id'} eq $from_hash) {
3110 print "<td class=\"link nochange\">";
3112 print "<td class=\"link\">";
3114 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3115 hash
=>$diff->{'to_id'},
3116 hash_parent
=>$from_hash,
3118 hash_parent_base
=>$hash_parent,
3119 file_name
=>$diff->{'to_file'},
3120 file_parent
=>$from_path)},
3126 print "<td class=\"link\">";
3128 print $cgi->a({-href
=> href
(action
=>"blob",
3129 hash
=>$diff->{'to_id'},
3130 file_name
=>$diff->{'to_file'},
3133 print " | " if ($has_history);
3136 print $cgi->a({-href
=> href
(action
=>"history",
3137 file_name
=>$diff->{'to_file'},
3144 next; # instead of 'else' clause, to avoid extra indent
3146 # else ordinary diff
3148 my ($to_mode_oct, $to_mode_str, $to_file_type);
3149 my ($from_mode_oct, $from_mode_str, $from_file_type);
3150 if ($diff->{'to_mode'} ne ('0' x
6)) {
3151 $to_mode_oct = oct $diff->{'to_mode'};
3152 if (S_ISREG
($to_mode_oct)) { # only for regular file
3153 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3155 $to_file_type = file_type
($diff->{'to_mode'});
3157 if ($diff->{'from_mode'} ne ('0' x
6)) {
3158 $from_mode_oct = oct $diff->{'from_mode'};
3159 if (S_ISREG
($to_mode_oct)) { # only for regular file
3160 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3162 $from_file_type = file_type
($diff->{'from_mode'});
3165 if ($diff->{'status'} eq "A") { # created
3166 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3167 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3168 $mode_chng .= "]</span>";
3170 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3171 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3172 -class => "list"}, esc_path
($diff->{'file'}));
3174 print "<td>$mode_chng</td>\n";
3175 print "<td class=\"link\">";
3176 if ($action eq 'commitdiff') {
3179 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3182 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3183 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3187 } elsif ($diff->{'status'} eq "D") { # deleted
3188 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3190 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3191 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3192 -class => "list"}, esc_path
($diff->{'file'}));
3194 print "<td>$mode_chng</td>\n";
3195 print "<td class=\"link\">";
3196 if ($action eq 'commitdiff') {
3199 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3202 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3203 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3206 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3207 file_name
=>$diff->{'file'})},
3210 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3211 file_name
=>$diff->{'file'})},
3215 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3216 my $mode_chnge = "";
3217 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3218 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3219 if ($from_file_type ne $to_file_type) {
3220 $mode_chnge .= " from $from_file_type to $to_file_type";
3222 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3223 if ($from_mode_str && $to_mode_str) {
3224 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3225 } elsif ($to_mode_str) {
3226 $mode_chnge .= " mode: $to_mode_str";
3229 $mode_chnge .= "]</span>\n";
3232 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3233 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3234 -class => "list"}, esc_path
($diff->{'file'}));
3236 print "<td>$mode_chnge</td>\n";
3237 print "<td class=\"link\">";
3238 if ($action eq 'commitdiff') {
3241 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3243 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3244 # "commit" view and modified file (not onlu mode changed)
3245 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3246 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3247 hash_base
=>$hash, hash_parent_base
=>$parent,
3248 file_name
=>$diff->{'file'})},
3252 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3253 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3256 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3257 file_name
=>$diff->{'file'})},
3260 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3261 file_name
=>$diff->{'file'})},
3265 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3266 my %status_name = ('R' => 'moved', 'C' => 'copied');
3267 my $nstatus = $status_name{$diff->{'status'}};
3269 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3270 # mode also for directories, so we cannot use $to_mode_str
3271 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3274 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3275 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3276 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3277 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3278 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3279 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3280 -class => "list"}, esc_path
($diff->{'from_file'})) .
3281 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3282 "<td class=\"link\">";
3283 if ($action eq 'commitdiff') {
3286 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3288 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3289 # "commit" view and modified file (not only pure rename or copy)
3290 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3291 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3292 hash_base
=>$hash, hash_parent_base
=>$parent,
3293 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3297 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3298 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3301 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3302 file_name
=>$diff->{'to_file'})},
3305 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3306 file_name
=>$diff->{'to_file'})},
3310 } # we should not encounter Unmerged (U) or Unknown (X) status
3313 print "</tbody>" if $has_header;
3317 sub git_patchset_body
{
3318 my ($fd, $difftree, $hash, @hash_parents) = @_;
3319 my ($hash_parent) = $hash_parents[0];
3321 my $is_combined = (@hash_parents > 1);
3323 my $patch_number = 0;
3329 print "<div class=\"patchset\">\n";
3331 # skip to first patch
3332 while ($patch_line = <$fd>) {
3335 last if ($patch_line =~ m/^diff /);
3339 while ($patch_line) {
3341 # parse "git diff" header line
3342 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3343 # $1 is from_name, which we do not use
3344 $to_name = unquote
($2);
3345 $to_name =~ s!^b/!!;
3346 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3347 # $1 is 'cc' or 'combined', which we do not use
3348 $to_name = unquote
($2);
3353 # check if current patch belong to current raw line
3354 # and parse raw git-diff line if needed
3355 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3356 # this is continuation of a split patch
3357 print "<div class=\"patch cont\">\n";
3359 # advance raw git-diff output if needed
3360 $patch_idx++ if defined $diffinfo;
3362 # read and prepare patch information
3363 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3365 # compact combined diff output can have some patches skipped
3366 # find which patch (using pathname of result) we are at now;
3368 while ($to_name ne $diffinfo->{'to_file'}) {
3369 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3370 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3371 "</div>\n"; # class="patch"
3376 last if $patch_idx > $#$difftree;
3377 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3381 # modifies %from, %to hashes
3382 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3384 # this is first patch for raw difftree line with $patch_idx index
3385 # we index @$difftree array from 0, but number patches from 1
3386 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3390 #assert($patch_line =~ m/^diff /) if DEBUG;
3391 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3393 # print "git diff" header
3394 print format_git_diff_header_line
($patch_line, $diffinfo,
3397 # print extended diff header
3398 print "<div class=\"diff extended_header\">\n";
3400 while ($patch_line = <$fd>) {
3403 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3405 print format_extended_diff_header_line
($patch_line, $diffinfo,
3408 print "</div>\n"; # class="diff extended_header"
3410 # from-file/to-file diff header
3411 if (! $patch_line) {
3412 print "</div>\n"; # class="patch"
3415 next PATCH
if ($patch_line =~ m/^diff /);
3416 #assert($patch_line =~ m/^---/) if DEBUG;
3418 my $last_patch_line = $patch_line;
3419 $patch_line = <$fd>;
3421 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3423 print format_diff_from_to_header
($last_patch_line, $patch_line,
3424 $diffinfo, \
%from, \
%to,
3429 while ($patch_line = <$fd>) {
3432 next PATCH
if ($patch_line =~ m/^diff /);
3434 print format_diff_line
($patch_line, \
%from, \
%to);
3438 print "</div>\n"; # class="patch"
3441 # for compact combined (--cc) format, with chunk and patch simpliciaction
3442 # patchset might be empty, but there might be unprocessed raw lines
3443 for (++$patch_idx if $patch_number > 0;
3444 $patch_idx < @$difftree;
3446 # read and prepare patch information
3447 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3449 # generate anchor for "patch" links in difftree / whatchanged part
3450 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3451 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3452 "</div>\n"; # class="patch"
3457 if ($patch_number == 0) {
3458 if (@hash_parents > 1) {
3459 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3461 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3465 print "</div>\n"; # class="patchset"
3468 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3470 sub git_project_list_body
{
3471 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3473 my ($check_forks) = gitweb_check_feature
('forks');
3476 foreach my $pr (@$projlist) {
3477 my (@aa) = git_get_last_activity
($pr->{'path'});
3481 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3482 if (!defined $pr->{'descr'}) {
3483 my $descr = git_get_project_description
($pr->{'path'}) || "";
3484 $pr->{'descr_long'} = to_utf8
($descr);
3485 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3487 if (!defined $pr->{'owner'}) {
3488 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3491 my $pname = $pr->{'path'};
3492 if (($pname =~ s/\.git$//) &&
3493 ($pname !~ /\/$/) &&
3494 (-d
"$projectroot/$pname")) {
3495 $pr->{'forks'} = "-d $projectroot/$pname";
3501 push @projects, $pr;
3504 $order ||= $default_projects_order;
3505 $from = 0 unless defined $from;
3506 $to = $#projects if (!defined $to || $#projects < $to);
3508 print "<table class=\"project_list\">\n";
3509 unless ($no_header) {
3512 print "<th></th>\n";
3514 if ($order eq "project") {
3515 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3516 print "<th>Project</th>\n";
3519 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3520 -class => "header"}, "Project") .
3523 if ($order eq "descr") {
3524 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3525 print "<th>Description</th>\n";
3528 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3529 -class => "header"}, "Description") .
3532 if ($order eq "owner") {
3533 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3534 print "<th>Owner</th>\n";
3537 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3538 -class => "header"}, "Owner") .
3541 if ($order eq "age") {
3542 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3543 print "<th>Last Change</th>\n";
3546 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3547 -class => "header"}, "Last Change") .
3550 print "<th></th>\n" .
3554 for (my $i = $from; $i <= $to; $i++) {
3555 my $pr = $projects[$i];
3557 print "<tr class=\"dark\">\n";
3559 print "<tr class=\"light\">\n";
3564 if ($pr->{'forks'}) {
3565 print "<!-- $pr->{'forks'} -->\n";
3566 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3570 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3571 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3572 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3573 -class => "list", -title
=> $pr->{'descr_long'}},
3574 esc_html
($pr->{'descr'})) . "</td>\n" .
3575 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3576 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3577 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3578 "<td class=\"link\">" .
3579 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3580 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3581 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3582 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3583 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3587 if (defined $extra) {
3590 print "<td></td>\n";
3592 print "<td colspan=\"5\">$extra</td>\n" .
3598 sub git_shortlog_body
{
3599 # uses global variable $project
3600 my ($commitlist, $from, $to, $refs, $extra) = @_;
3602 $from = 0 unless defined $from;
3603 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3605 print "<table class=\"shortlog\">\n";
3607 for (my $i = $from; $i <= $to; $i++) {
3608 my %co = %{$commitlist->[$i]};
3609 my $commit = $co{'id'};
3610 my $ref = format_ref_marker
($refs, $commit);
3612 print "<tr class=\"dark\">\n";
3614 print "<tr class=\"light\">\n";
3617 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3618 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3619 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3620 "<td><i>" . $author . "</i></td>\n" .
3622 print format_subject_html
($co{'title'}, $co{'title_short'},
3623 href
(action
=>"commit", hash
=>$commit), $ref);
3625 "<td class=\"link\">" .
3626 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3627 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3628 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3629 my $snapshot_links = format_snapshot_links
($commit);
3630 if (defined $snapshot_links) {
3631 print " | " . $snapshot_links;
3636 if (defined $extra) {
3638 "<td colspan=\"4\">$extra</td>\n" .
3644 sub git_history_body
{
3645 # Warning: assumes constant type (blob or tree) during history
3646 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3648 $from = 0 unless defined $from;
3649 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3651 print "<table class=\"history\">\n";
3653 for (my $i = $from; $i <= $to; $i++) {
3654 my %co = %{$commitlist->[$i]};
3658 my $commit = $co{'id'};
3660 my $ref = format_ref_marker
($refs, $commit);
3663 print "<tr class=\"dark\">\n";
3665 print "<tr class=\"light\">\n";
3668 # shortlog uses chop_str($co{'author_name'}, 10)
3669 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3670 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3671 "<td><i>" . $author . "</i></td>\n" .
3673 # originally git_history used chop_str($co{'title'}, 50)
3674 print format_subject_html
($co{'title'}, $co{'title_short'},
3675 href
(action
=>"commit", hash
=>$commit), $ref);
3677 "<td class=\"link\">" .
3678 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3679 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3681 if ($ftype eq 'blob') {
3682 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3683 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3684 if (defined $blob_current && defined $blob_parent &&
3685 $blob_current ne $blob_parent) {
3687 $cgi->a({-href
=> href
(action
=>"blobdiff",
3688 hash
=>$blob_current, hash_parent
=>$blob_parent,
3689 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3690 file_name
=>$file_name)},
3697 if (defined $extra) {
3699 "<td colspan=\"4\">$extra</td>\n" .
3706 # uses global variable $project
3707 my ($taglist, $from, $to, $extra) = @_;
3708 $from = 0 unless defined $from;
3709 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3711 print "<table class=\"tags\">\n";
3713 for (my $i = $from; $i <= $to; $i++) {
3714 my $entry = $taglist->[$i];
3716 my $comment = $tag{'subject'};
3718 if (defined $comment) {
3719 $comment_short = chop_str
($comment, 30, 5);
3722 print "<tr class=\"dark\">\n";
3724 print "<tr class=\"light\">\n";
3727 if (defined $tag{'age'}) {
3728 print "<td><i>$tag{'age'}</i></td>\n";
3730 print "<td></td>\n";
3733 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3734 -class => "list name"}, esc_html
($tag{'name'})) .
3737 if (defined $comment) {
3738 print format_subject_html
($comment, $comment_short,
3739 href
(action
=>"tag", hash
=>$tag{'id'}));
3742 "<td class=\"selflink\">";
3743 if ($tag{'type'} eq "tag") {
3744 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3749 "<td class=\"link\">" . " | " .
3750 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3751 if ($tag{'reftype'} eq "commit") {
3752 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3753 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3754 } elsif ($tag{'reftype'} eq "blob") {
3755 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3760 if (defined $extra) {
3762 "<td colspan=\"5\">$extra</td>\n" .
3768 sub git_heads_body
{
3769 # uses global variable $project
3770 my ($headlist, $head, $from, $to, $extra) = @_;
3771 $from = 0 unless defined $from;
3772 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3774 print "<table class=\"heads\">\n";
3776 for (my $i = $from; $i <= $to; $i++) {
3777 my $entry = $headlist->[$i];
3779 my $curr = $ref{'id'} eq $head;
3781 print "<tr class=\"dark\">\n";
3783 print "<tr class=\"light\">\n";
3786 print "<td><i>$ref{'age'}</i></td>\n" .
3787 ($curr ? "<td class=\"current_head\">" : "<td>") .
3788 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3789 -class => "list name"},esc_html
($ref{'name'})) .
3791 "<td class=\"link\">" .
3792 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3793 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3794 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3798 if (defined $extra) {
3800 "<td colspan=\"3\">$extra</td>\n" .
3806 sub git_search_grep_body
{
3807 my ($commitlist, $from, $to, $extra) = @_;
3808 $from = 0 unless defined $from;
3809 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3811 print "<table class=\"commit_search\">\n";
3813 for (my $i = $from; $i <= $to; $i++) {
3814 my %co = %{$commitlist->[$i]};
3818 my $commit = $co{'id'};
3820 print "<tr class=\"dark\">\n";
3822 print "<tr class=\"light\">\n";
3825 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3826 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3827 "<td><i>" . $author . "</i></td>\n" .
3829 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3830 -class => "list subject"},
3831 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3832 my $comment = $co{'comment'};
3833 foreach my $line (@$comment) {
3834 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3835 my ($lead, $match, $trail) = ($1, $2, $3);
3836 $match = chop_str
($match, 70, 5, 'center');
3837 my $contextlen = int((80 - length($match))/2);
3838 $contextlen = 30 if ($contextlen > 30);
3839 $lead = chop_str
($lead, $contextlen, 10, 'left');
3840 $trail = chop_str
($trail, $contextlen, 10, 'right');
3842 $lead = esc_html
($lead);
3843 $match = esc_html
($match);
3844 $trail = esc_html
($trail);
3846 print "$lead<span class=\"match\">$match</span>$trail<br />";
3850 "<td class=\"link\">" .
3851 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3853 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3855 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3859 if (defined $extra) {
3861 "<td colspan=\"3\">$extra</td>\n" .
3867 ## ======================================================================
3868 ## ======================================================================
3871 sub git_project_list
{
3872 my $order = $cgi->param('o');
3873 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3874 die_error
(undef, "Unknown order parameter");
3877 my @list = git_get_projects_list
();
3879 die_error
(undef, "No projects found");
3883 if (-f
$home_text) {
3884 print "<div class=\"index_include\">\n";
3885 open (my $fd, $home_text);
3890 git_project_list_body
(\
@list, $order);
3895 my $order = $cgi->param('o');
3896 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3897 die_error
(undef, "Unknown order parameter");
3900 my @list = git_get_projects_list
($project);
3902 die_error
(undef, "No forks found");
3906 git_print_page_nav
('','');
3907 git_print_header_div
('summary', "$project forks");
3908 git_project_list_body
(\
@list, $order);
3912 sub git_project_index
{
3913 my @projects = git_get_projects_list
($project);
3916 -type
=> 'text/plain',
3917 -charset
=> 'utf-8',
3918 -content_disposition
=> 'inline; filename="index.aux"');
3920 foreach my $pr (@projects) {
3921 if (!exists $pr->{'owner'}) {
3922 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3925 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3926 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3927 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3928 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3932 print "$path $owner\n";
3937 my $descr = git_get_project_description
($project) || "none";
3938 my %co = parse_commit
("HEAD");
3939 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3940 my $head = $co{'id'};
3942 my $owner = git_get_project_owner
($project);
3944 my $refs = git_get_references
();
3945 # These get_*_list functions return one more to allow us to see if
3946 # there are more ...
3947 my @taglist = git_get_tags_list
(16);
3948 my @headlist = git_get_heads_list
(16);
3950 my ($check_forks) = gitweb_check_feature
('forks');
3953 @forklist = git_get_projects_list
($project);
3957 git_print_page_nav
('summary','', $head);
3959 print "<div class=\"title\"> </div>\n";
3960 print "<table class=\"projects_list\">\n" .
3961 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3962 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
3963 if (defined $cd{'rfc2822'}) {
3964 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3967 # use per project git URL list in $projectroot/$project/cloneurl
3968 # or make project git URL from git base URL and project name
3969 my $url_tag = "URL";
3970 my @url_list = git_get_project_url_list
($project);
3971 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3972 foreach my $git_url (@url_list) {
3973 next unless $git_url;
3974 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3979 if (-s
"$projectroot/$project/README.html") {
3980 if (open my $fd, "$projectroot/$project/README.html") {
3981 print "<div class=\"title\">readme</div>\n" .
3982 "<div class=\"readme\">\n";
3983 print $_ while (<$fd>);
3984 print "\n</div>\n"; # class="readme"
3989 # we need to request one more than 16 (0..15) to check if
3991 my @commitlist = $head ? parse_commits
($head, 17) : ();
3993 git_print_header_div
('shortlog');
3994 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3995 $#commitlist <= 15 ? undef :
3996 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4000 git_print_header_div
('tags');
4001 git_tags_body
(\
@taglist, 0, 15,
4002 $#taglist <= 15 ? undef :
4003 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4007 git_print_header_div
('heads');
4008 git_heads_body
(\
@headlist, $head, 0, 15,
4009 $#headlist <= 15 ? undef :
4010 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4014 git_print_header_div
('forks');
4015 git_project_list_body
(\
@forklist, undef, 0, 15,
4016 $#forklist <= 15 ? undef :
4017 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4025 my $head = git_get_head_hash
($project);
4027 git_print_page_nav
('','', $head,undef,$head);
4028 my %tag = parse_tag
($hash);
4031 die_error
(undef, "Unknown tag object");
4034 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4035 print "<div class=\"title_text\">\n" .
4036 "<table class=\"object_header\">\n" .
4038 "<td>object</td>\n" .
4039 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4040 $tag{'object'}) . "</td>\n" .
4041 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4042 $tag{'type'}) . "</td>\n" .
4044 if (defined($tag{'author'})) {
4045 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4046 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4047 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4048 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4051 print "</table>\n\n" .
4053 print "<div class=\"page_body\">";
4054 my $comment = $tag{'comment'};
4055 foreach my $line (@$comment) {
4057 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4067 my ($have_blame) = gitweb_check_feature
('blame');
4069 die_error
('403 Permission denied', "Permission denied");
4071 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4072 $hash_base ||= git_get_head_hash
($project);
4073 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4074 my %co = parse_commit
($hash_base)
4075 or die_error
(undef, "Reading commit failed");
4076 if (!defined $hash) {
4077 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4078 or die_error
(undef, "Error looking up file");
4080 $ftype = git_get_type
($hash);
4081 if ($ftype !~ "blob") {
4082 die_error
('400 Bad Request', "Object is not a blob");
4084 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4085 $file_name, $hash_base)
4086 or die_error
(undef, "Open git-blame failed");
4089 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4092 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4095 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4097 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4098 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4099 git_print_page_path
($file_name, $ftype, $hash_base);
4100 my @rev_color = (qw(light2 dark2));
4101 my $num_colors = scalar(@rev_color);
4102 my $current_color = 0;
4105 <div class="page_body">
4106 <table class="blame">
4107 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4112 last unless defined $_;
4113 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4114 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4115 if (!exists $metainfo{$full_rev}) {
4116 $metainfo{$full_rev} = {};
4118 my $meta = $metainfo{$full_rev};
4121 if (/^(\S+) (.*)$/) {
4127 my $rev = substr($full_rev, 0, 8);
4128 my $author = $meta->{'author'};
4129 my %date = parse_date
($meta->{'author-time'},
4130 $meta->{'author-tz'});
4131 my $date = $date{'iso-tz'};
4133 $current_color = ++$current_color % $num_colors;
4135 print "<tr class=\"$rev_color[$current_color]\">\n";
4137 print "<td class=\"sha1\"";
4138 print " title=\"". esc_html
($author) . ", $date\"";
4139 print " rowspan=\"$group_size\"" if ($group_size > 1);
4141 print $cgi->a({-href
=> href
(action
=>"commit",
4143 file_name
=>$file_name)},
4147 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4148 or die_error
(undef, "Open git-rev-parse failed");
4149 my $parent_commit = <$dd>;
4151 chomp($parent_commit);
4152 my $blamed = href
(action
=> 'blame',
4153 file_name
=> $meta->{'filename'},
4154 hash_base
=> $parent_commit);
4155 print "<td class=\"linenr\">";
4156 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4158 -class => "linenr" },
4161 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4167 or print "Reading blob failed\n";
4174 my ($have_blame) = gitweb_check_feature
('blame');
4176 die_error
('403 Permission denied', "Permission denied");
4178 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4179 $hash_base ||= git_get_head_hash
($project);
4180 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4181 my %co = parse_commit
($hash_base)
4182 or die_error
(undef, "Reading commit failed");
4183 if (!defined $hash) {
4184 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4185 or die_error
(undef, "Error lookup file");
4187 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4188 or die_error
(undef, "Open git-annotate failed");
4191 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4194 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4197 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4199 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4200 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4201 git_print_page_path
($file_name, 'blob', $hash_base);
4202 print "<div class=\"page_body\">\n";
4204 <table class="blame">
4213 my @line_class = (qw(light dark));
4214 my $line_class_len = scalar (@line_class);
4215 my $line_class_num = $#line_class;
4216 while (my $line = <$fd>) {
4228 $line_class_num = ($line_class_num + 1) % $line_class_len;
4230 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4237 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4240 $short_rev = substr ($long_rev, 0, 8);
4241 $age = time () - $time;
4242 $age_str = age_string
($age);
4243 $age_str =~ s/ / /g;
4244 $age_class = age_class
($age);
4245 $author = esc_html
($author);
4246 $author =~ s/ / /g;
4248 $data = untabify
($data);
4249 $data = esc_html
($data);
4252 <tr class="$line_class[$line_class_num]">
4253 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4254 <td class="$age_class">$age_str</td>
4256 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4257 <td class="pre">$data</td>
4260 } # while (my $line = <$fd>)
4261 print "</table>\n\n";
4263 or print "Reading blob failed.\n";
4269 my $head = git_get_head_hash
($project);
4271 git_print_page_nav
('','', $head,undef,$head);
4272 git_print_header_div
('summary', $project);
4274 my @tagslist = git_get_tags_list
();
4276 git_tags_body
(\
@tagslist);
4282 my $head = git_get_head_hash
($project);
4284 git_print_page_nav
('','', $head,undef,$head);
4285 git_print_header_div
('summary', $project);
4287 my @headslist = git_get_heads_list
();
4289 git_heads_body
(\
@headslist, $head);
4294 sub git_blob_plain
{
4297 if (!defined $hash) {
4298 if (defined $file_name) {
4299 my $base = $hash_base || git_get_head_hash
($project);
4300 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4301 or die_error
(undef, "Error lookup file");
4303 die_error
(undef, "No file name defined");
4305 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4306 # blobs defined by non-textual hash id's can be cached
4311 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4312 or die_error
(undef, "Couldn't cat $file_name, $hash");
4314 $type ||= blob_mimetype
($fd, $file_name);
4316 # save as filename, even when no $file_name is given
4317 my $save_as = "$hash";
4318 if (defined $file_name) {
4319 $save_as = $file_name;
4320 } elsif ($type =~ m/^text\//) {
4327 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4329 binmode STDOUT
, ':raw';
4331 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4339 if (!defined $hash) {
4340 if (defined $file_name) {
4341 my $base = $hash_base || git_get_head_hash
($project);
4342 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4343 or die_error
(undef, "Error lookup file");
4345 die_error
(undef, "No file name defined");
4347 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4348 # blobs defined by non-textual hash id's can be cached
4352 my ($have_blame) = gitweb_check_feature
('blame');
4353 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4354 or die_error
(undef, "Couldn't cat $file_name, $hash");
4355 my $mimetype = blob_mimetype
($fd, $file_name);
4356 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4358 return git_blob_plain
($mimetype);
4360 # we can have blame only for text/* mimetype
4361 $have_blame &&= ($mimetype =~ m!^text/!);
4363 git_header_html
(undef, $expires);
4364 my $formats_nav = '';
4365 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4366 if (defined $file_name) {
4369 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4374 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4377 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4380 $cgi->a({-href
=> href
(action
=>"blob",
4381 hash_base
=>"HEAD", file_name
=>$file_name)},
4385 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4388 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4389 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4391 print "<div class=\"page_nav\">\n" .
4392 "<br/><br/></div>\n" .
4393 "<div class=\"title\">$hash</div>\n";
4395 git_print_page_path
($file_name, "blob", $hash_base);
4396 print "<div class=\"page_body\">\n";
4397 if ($mimetype =~ m!^image/!) {
4398 print qq
!<img type
="$mimetype"!;
4400 print qq
! alt
="$file_name" title
="$file_name"!;
4403 href(action=>"blob_plain
", hash=>$hash,
4404 hash_base=>$hash_base, file_name=>$file_name) .
4408 while (my $line = <$fd>) {
4411 $line = untabify
($line);
4412 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4413 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4417 or print "Reading blob failed.\n";
4423 if (!defined $hash_base) {
4424 $hash_base = "HEAD";
4426 if (!defined $hash) {
4427 if (defined $file_name) {
4428 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4434 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4435 or die_error
(undef, "Open git-ls-tree failed");
4436 my @entries = map { chomp; $_ } <$fd>;
4437 close $fd or die_error
(undef, "Reading tree failed");
4440 my $refs = git_get_references
();
4441 my $ref = format_ref_marker
($refs, $hash_base);
4444 my ($have_blame) = gitweb_check_feature
('blame');
4445 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4447 if (defined $file_name) {
4449 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4451 $cgi->a({-href
=> href
(action
=>"tree",
4452 hash_base
=>"HEAD", file_name
=>$file_name)},
4455 my $snapshot_links = format_snapshot_links
($hash);
4456 if (defined $snapshot_links) {
4457 # FIXME: Should be available when we have no hash base as well.
4458 push @views_nav, $snapshot_links;
4460 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4461 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4464 print "<div class=\"page_nav\">\n";
4465 print "<br/><br/></div>\n";
4466 print "<div class=\"title\">$hash</div>\n";
4468 if (defined $file_name) {
4469 $basedir = $file_name;
4470 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4474 git_print_page_path
($file_name, 'tree', $hash_base);
4475 print "<div class=\"page_body\">\n";
4476 print "<table class=\"tree\">\n";
4478 # '..' (top directory) link if possible
4479 if (defined $hash_base &&
4480 defined $file_name && $file_name =~ m![^/]+$!) {
4482 print "<tr class=\"dark\">\n";
4484 print "<tr class=\"light\">\n";
4488 my $up = $file_name;
4489 $up =~ s!/?[^/]+$!!;
4490 undef $up unless $up;
4491 # based on git_print_tree_entry
4492 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4493 print '<td class="list">';
4494 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4498 print "<td class=\"link\"></td>\n";
4502 foreach my $line (@entries) {
4503 my %t = parse_ls_tree_line
($line, -z
=> 1);
4506 print "<tr class=\"dark\">\n";
4508 print "<tr class=\"light\">\n";
4512 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4516 print "</table>\n" .
4522 my @supported_fmts = gitweb_check_feature
('snapshot');
4523 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4525 my $format = $cgi->param('sf');
4526 if (!@supported_fmts) {
4527 die_error
('403 Permission denied', "Permission denied");
4529 # default to first supported snapshot format
4530 $format ||= $supported_fmts[0];
4531 if ($format !~ m/^[a-z0-9]+$/) {
4532 die_error
(undef, "Invalid snapshot format parameter");
4533 } elsif (!exists($known_snapshot_formats{$format})) {
4534 die_error
(undef, "Unknown snapshot format");
4535 } elsif (!grep($_ eq $format, @supported_fmts)) {
4536 die_error
(undef, "Unsupported snapshot format");
4539 if (!defined $hash) {
4540 $hash = git_get_head_hash
($project);
4543 my $git_command = git_cmd_str
();
4544 my $name = $project;
4545 $name =~ s
,([^/])/*\
.git
$,$1,;
4546 $name = basename
($name);
4547 my $filename = to_utf8
($name);
4548 $name =~ s/\047/\047\\\047\047/g;
4550 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4551 $cmd = "$git_command archive " .
4552 "--format=$known_snapshot_formats{$format}{'format'} " .
4553 "--prefix=\'$name\'/ $hash";
4554 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4555 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4559 -type
=> $known_snapshot_formats{$format}{'type'},
4560 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4561 -status
=> '200 OK');
4563 open my $fd, "-|", $cmd
4564 or die_error
(undef, "Execute git-archive failed");
4565 binmode STDOUT
, ':raw';
4567 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4572 my $head = git_get_head_hash
($project);
4573 if (!defined $hash) {
4576 if (!defined $page) {
4579 my $refs = git_get_references
();
4581 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4583 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4586 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4589 my %co = parse_commit
($hash);
4591 git_print_header_div
('summary', $project);
4592 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4594 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4595 for (my $i = 0; $i <= $to; $i++) {
4596 my %co = %{$commitlist[$i]};
4598 my $commit = $co{'id'};
4599 my $ref = format_ref_marker
($refs, $commit);
4600 my %ad = parse_date
($co{'author_epoch'});
4601 git_print_header_div
('commit',
4602 "<span class=\"age\">$co{'age_string'}</span>" .
4603 esc_html
($co{'title'}) . $ref,
4605 print "<div class=\"title_text\">\n" .
4606 "<div class=\"log_link\">\n" .
4607 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4609 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4611 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4614 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4617 print "<div class=\"log_body\">\n";
4618 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4621 if ($#commitlist >= 100) {
4622 print "<div class=\"page_nav\">\n";
4623 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4624 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4631 $hash ||= $hash_base || "HEAD";
4632 my %co = parse_commit
($hash);
4634 die_error
(undef, "Unknown commit object");
4636 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4637 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4639 my $parent = $co{'parent'};
4640 my $parents = $co{'parents'}; # listref
4642 # we need to prepare $formats_nav before any parameter munging
4644 if (!defined $parent) {
4646 $formats_nav .= '(initial)';
4647 } elsif (@$parents == 1) {
4648 # single parent commit
4651 $cgi->a({-href
=> href
(action
=>"commit",
4653 esc_html
(substr($parent, 0, 7))) .
4660 $cgi->a({-href
=> href
(action
=>"commit",
4662 esc_html
(substr($_, 0, 7)));
4667 if (!defined $parent) {
4671 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4673 (@$parents <= 1 ? $parent : '-c'),
4675 or die_error
(undef, "Open git-diff-tree failed");
4676 @difftree = map { chomp; $_ } <$fd>;
4677 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4679 # non-textual hash id's can be cached
4681 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4684 my $refs = git_get_references
();
4685 my $ref = format_ref_marker
($refs, $co{'id'});
4687 git_header_html
(undef, $expires);
4688 git_print_page_nav
('commit', '',
4689 $hash, $co{'tree'}, $hash,
4692 if (defined $co{'parent'}) {
4693 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4695 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4697 print "<div class=\"title_text\">\n" .
4698 "<table class=\"object_header\">\n";
4699 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4701 "<td></td><td> $ad{'rfc2822'}";
4702 if ($ad{'hour_local'} < 6) {
4703 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4704 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4706 printf(" (%02d:%02d %s)",
4707 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4711 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4712 print "<tr><td></td><td> $cd{'rfc2822'}" .
4713 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4715 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4718 "<td class=\"sha1\">" .
4719 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4720 class => "list"}, $co{'tree'}) .
4722 "<td class=\"link\">" .
4723 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4725 my $snapshot_links = format_snapshot_links
($hash);
4726 if (defined $snapshot_links) {
4727 print " | " . $snapshot_links;
4732 foreach my $par (@$parents) {
4735 "<td class=\"sha1\">" .
4736 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4737 class => "list"}, $par) .
4739 "<td class=\"link\">" .
4740 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4742 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4749 print "<div class=\"page_body\">\n";
4750 git_print_log
($co{'comment'});
4753 git_difftree_body
(\
@difftree, $hash, @$parents);
4759 # object is defined by:
4760 # - hash or hash_base alone
4761 # - hash_base and file_name
4764 # - hash or hash_base alone
4765 if ($hash || ($hash_base && !defined $file_name)) {
4766 my $object_id = $hash || $hash_base;
4768 my $git_command = git_cmd_str
();
4769 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4770 or die_error
('404 Not Found', "Object does not exist");
4774 or die_error
('404 Not Found', "Object does not exist");
4776 # - hash_base and file_name
4777 } elsif ($hash_base && defined $file_name) {
4778 $file_name =~ s
,/+$,,;
4780 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4781 or die_error
('404 Not Found', "Base object does not exist");
4783 # here errors should not hapen
4784 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4785 or die_error
(undef, "Open git-ls-tree failed");
4789 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4790 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4791 die_error
('404 Not Found', "File or directory for given base does not exist");
4796 die_error
('404 Not Found', "Not enough information to find object");
4799 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4800 hash
=>$hash, hash_base
=>$hash_base,
4801 file_name
=>$file_name),
4802 -status
=> '302 Found');
4806 my $format = shift || 'html';
4813 # preparing $fd and %diffinfo for git_patchset_body
4815 if (defined $hash_base && defined $hash_parent_base) {
4816 if (defined $file_name) {
4818 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4819 $hash_parent_base, $hash_base,
4820 "--", (defined $file_parent ? $file_parent : ()), $file_name
4821 or die_error
(undef, "Open git-diff-tree failed");
4822 @difftree = map { chomp; $_ } <$fd>;
4824 or die_error
(undef, "Reading git-diff-tree failed");
4826 or die_error
('404 Not Found', "Blob diff not found");
4828 } elsif (defined $hash &&
4829 $hash =~ /[0-9a-fA-F]{40}/) {
4830 # try to find filename from $hash
4832 # read filtered raw output
4833 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4834 $hash_parent_base, $hash_base, "--"
4835 or die_error
(undef, "Open git-diff-tree failed");
4837 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4839 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4840 map { chomp; $_ } <$fd>;
4842 or die_error
(undef, "Reading git-diff-tree failed");
4844 or die_error
('404 Not Found', "Blob diff not found");
4847 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4850 if (@difftree > 1) {
4851 die_error
('404 Not Found', "Ambiguous blob diff specification");
4854 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4855 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4856 $file_name ||= $diffinfo{'to_file'};
4858 $hash_parent ||= $diffinfo{'from_id'};
4859 $hash ||= $diffinfo{'to_id'};
4861 # non-textual hash id's can be cached
4862 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4863 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4868 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4869 '-p', ($format eq 'html' ? "--full-index" : ()),
4870 $hash_parent_base, $hash_base,
4871 "--", (defined $file_parent ? $file_parent : ()), $file_name
4872 or die_error
(undef, "Open git-diff-tree failed");
4875 # old/legacy style URI
4876 if (!%diffinfo && # if new style URI failed
4877 defined $hash && defined $hash_parent) {
4878 # fake git-diff-tree raw output
4879 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4880 $diffinfo{'from_id'} = $hash_parent;
4881 $diffinfo{'to_id'} = $hash;
4882 if (defined $file_name) {
4883 if (defined $file_parent) {
4884 $diffinfo{'status'} = '2';
4885 $diffinfo{'from_file'} = $file_parent;
4886 $diffinfo{'to_file'} = $file_name;
4887 } else { # assume not renamed
4888 $diffinfo{'status'} = '1';
4889 $diffinfo{'from_file'} = $file_name;
4890 $diffinfo{'to_file'} = $file_name;
4892 } else { # no filename given
4893 $diffinfo{'status'} = '2';
4894 $diffinfo{'from_file'} = $hash_parent;
4895 $diffinfo{'to_file'} = $hash;
4898 # non-textual hash id's can be cached
4899 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4900 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4905 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4906 '-p', ($format eq 'html' ? "--full-index" : ()),
4907 $hash_parent, $hash, "--"
4908 or die_error
(undef, "Open git-diff failed");
4910 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4915 if ($format eq 'html') {
4917 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4919 git_header_html
(undef, $expires);
4920 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4921 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4922 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4924 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4925 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4927 if (defined $file_name) {
4928 git_print_page_path
($file_name, "blob", $hash_base);
4930 print "<div class=\"page_path\"></div>\n";
4933 } elsif ($format eq 'plain') {
4935 -type
=> 'text/plain',
4936 -charset
=> 'utf-8',
4937 -expires
=> $expires,
4938 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4940 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4943 die_error
(undef, "Unknown blobdiff format");
4947 if ($format eq 'html') {
4948 print "<div class=\"page_body\">\n";
4950 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4953 print "</div>\n"; # class="page_body"
4957 while (my $line = <$fd>) {
4958 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4959 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4963 last if $line =~ m!^\+\+\+!;
4971 sub git_blobdiff_plain
{
4972 git_blobdiff
('plain');
4975 sub git_commitdiff
{
4976 my $format = shift || 'html';
4977 $hash ||= $hash_base || "HEAD";
4978 my %co = parse_commit
($hash);
4980 die_error
(undef, "Unknown commit object");
4983 # choose format for commitdiff for merge
4984 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4985 $hash_parent = '--cc';
4987 # we need to prepare $formats_nav before almost any parameter munging
4989 if ($format eq 'html') {
4991 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
4994 if (defined $hash_parent &&
4995 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4996 # commitdiff with two commits given
4997 my $hash_parent_short = $hash_parent;
4998 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4999 $hash_parent_short = substr($hash_parent, 0, 7);
5003 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5004 if ($co{'parents'}[$i] eq $hash_parent) {
5005 $formats_nav .= ' parent ' . ($i+1);
5009 $formats_nav .= ': ' .
5010 $cgi->a({-href
=> href
(action
=>"commitdiff",
5011 hash
=>$hash_parent)},
5012 esc_html
($hash_parent_short)) .
5014 } elsif (!$co{'parent'}) {
5016 $formats_nav .= ' (initial)';
5017 } elsif (scalar @{$co{'parents'}} == 1) {
5018 # single parent commit
5021 $cgi->a({-href
=> href
(action
=>"commitdiff",
5022 hash
=>$co{'parent'})},
5023 esc_html
(substr($co{'parent'}, 0, 7))) .
5027 if ($hash_parent eq '--cc') {
5028 $formats_nav .= ' | ' .
5029 $cgi->a({-href
=> href
(action
=>"commitdiff",
5030 hash
=>$hash, hash_parent
=>'-c')},
5032 } else { # $hash_parent eq '-c'
5033 $formats_nav .= ' | ' .
5034 $cgi->a({-href
=> href
(action
=>"commitdiff",
5035 hash
=>$hash, hash_parent
=>'--cc')},
5041 $cgi->a({-href
=> href
(action
=>"commitdiff",
5043 esc_html
(substr($_, 0, 7)));
5044 } @{$co{'parents'}} ) .
5049 my $hash_parent_param = $hash_parent;
5050 if (!defined $hash_parent_param) {
5051 # --cc for multiple parents, --root for parentless
5052 $hash_parent_param =
5053 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5059 if ($format eq 'html') {
5060 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5061 "--no-commit-id", "--patch-with-raw", "--full-index",
5062 $hash_parent_param, $hash, "--"
5063 or die_error
(undef, "Open git-diff-tree failed");
5065 while (my $line = <$fd>) {
5067 # empty line ends raw part of diff-tree output
5069 push @difftree, scalar parse_difftree_raw_line
($line);
5072 } elsif ($format eq 'plain') {
5073 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5074 '-p', $hash_parent_param, $hash, "--"
5075 or die_error
(undef, "Open git-diff-tree failed");
5078 die_error
(undef, "Unknown commitdiff format");
5081 # non-textual hash id's can be cached
5083 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5087 # write commit message
5088 if ($format eq 'html') {
5089 my $refs = git_get_references
();
5090 my $ref = format_ref_marker
($refs, $co{'id'});
5092 git_header_html
(undef, $expires);
5093 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5094 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5095 git_print_authorship
(\
%co);
5096 print "<div class=\"page_body\">\n";
5097 if (@{$co{'comment'}} > 1) {
5098 print "<div class=\"log\">\n";
5099 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5100 print "</div>\n"; # class="log"
5103 } elsif ($format eq 'plain') {
5104 my $refs = git_get_references
("tags");
5105 my $tagname = git_get_rev_name_tags
($hash);
5106 my $filename = basename
($project) . "-$hash.patch";
5109 -type
=> 'text/plain',
5110 -charset
=> 'utf-8',
5111 -expires
=> $expires,
5112 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5113 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5114 print "From: " . to_utf8
($co{'author'}) . "\n";
5115 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5116 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5118 print "X-Git-Tag: $tagname\n" if $tagname;
5119 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5121 foreach my $line (@{$co{'comment'}}) {
5122 print to_utf8
($line) . "\n";
5128 if ($format eq 'html') {
5129 my $use_parents = !defined $hash_parent ||
5130 $hash_parent eq '-c' || $hash_parent eq '--cc';
5131 git_difftree_body
(\
@difftree, $hash,
5132 $use_parents ? @{$co{'parents'}} : $hash_parent);
5135 git_patchset_body
($fd, \
@difftree, $hash,
5136 $use_parents ? @{$co{'parents'}} : $hash_parent);
5138 print "</div>\n"; # class="page_body"
5141 } elsif ($format eq 'plain') {
5145 or print "Reading git-diff-tree failed\n";
5149 sub git_commitdiff_plain
{
5150 git_commitdiff
('plain');
5154 if (!defined $hash_base) {
5155 $hash_base = git_get_head_hash
($project);
5157 if (!defined $page) {
5161 my %co = parse_commit
($hash_base);
5163 die_error
(undef, "Unknown commit object");
5166 my $refs = git_get_references
();
5167 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5169 if (!defined $hash && defined $file_name) {
5170 $hash = git_get_hash_by_path
($hash_base, $file_name);
5172 if (defined $hash) {
5173 $ftype = git_get_type
($hash);
5176 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), $file_name, "--full-history");
5178 my $paging_nav = '';
5181 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5182 file_name
=>$file_name)},
5184 $paging_nav .= " ⋅ " .
5185 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5186 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5188 $paging_nav .= "first";
5189 $paging_nav .= " ⋅ prev";
5192 if ($#commitlist >= 100) {
5194 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5195 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5196 $paging_nav .= " ⋅ $next_link";
5198 $paging_nav .= " ⋅ next";
5202 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5203 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5204 git_print_page_path
($file_name, $ftype, $hash_base);
5206 git_history_body
(\
@commitlist, 0, 99,
5207 $refs, $hash_base, $ftype, $next_link);
5213 my ($have_search) = gitweb_check_feature
('search');
5214 if (!$have_search) {
5215 die_error
('403 Permission denied', "Permission denied");
5217 if (!defined $searchtext) {
5218 die_error
(undef, "Text field empty");
5220 if (!defined $hash) {
5221 $hash = git_get_head_hash
($project);
5223 my %co = parse_commit
($hash);
5225 die_error
(undef, "Unknown commit object");
5227 if (!defined $page) {
5231 $searchtype ||= 'commit';
5232 if ($searchtype eq 'pickaxe') {
5233 # pickaxe may take all resources of your box and run for several minutes
5234 # with every query - so decide by yourself how public you make this feature
5235 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5236 if (!$have_pickaxe) {
5237 die_error
('403 Permission denied', "Permission denied");
5240 if ($searchtype eq 'grep') {
5241 my ($have_grep) = gitweb_check_feature
('grep');
5243 die_error
('403 Permission denied', "Permission denied");
5249 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5251 if ($searchtype eq 'commit') {
5252 $greptype = "--grep=";
5253 } elsif ($searchtype eq 'author') {
5254 $greptype = "--author=";
5255 } elsif ($searchtype eq 'committer') {
5256 $greptype = "--committer=";
5258 $greptype .= $search_regexp;
5259 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef, $greptype);
5261 my $paging_nav = '';
5264 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5265 searchtext
=>$searchtext, searchtype
=>$searchtype)},
5267 $paging_nav .= " ⋅ " .
5268 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5269 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5271 $paging_nav .= "first";
5272 $paging_nav .= " ⋅ prev";
5275 if ($#commitlist >= 100) {
5277 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5278 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5279 $paging_nav .= " ⋅ $next_link";
5281 $paging_nav .= " ⋅ next";
5284 if ($#commitlist >= 100) {
5287 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5288 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5289 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5292 if ($searchtype eq 'pickaxe') {
5293 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5294 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5296 print "<table class=\"pickaxe search\">\n";
5299 my $git_command = git_cmd_str
();
5300 my $searchqtext = $searchtext;
5301 $searchqtext =~ s/'/'\\''/;
5302 open my $fd, "-|", "$git_command rev-list $hash | " .
5303 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5306 while (my $line = <$fd>) {
5307 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5310 $set{'from_id'} = $3;
5312 $set{'id'} = $set{'to_id'};
5313 if ($set{'id'} =~ m/0{40}/) {
5314 $set{'id'} = $set{'from_id'};
5316 if ($set{'id'} =~ m/0{40}/) {
5320 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5323 print "<tr class=\"dark\">\n";
5325 print "<tr class=\"light\">\n";
5328 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5329 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5330 "<td><i>" . $author . "</i></td>\n" .
5332 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5333 -class => "list subject"},
5334 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5335 while (my $setref = shift @files) {
5337 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5338 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5340 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5344 "<td class=\"link\">" .
5345 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5347 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5351 %co = parse_commit
($1);
5359 if ($searchtype eq 'grep') {
5360 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5361 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5363 print "<table class=\"grep_search\">\n";
5367 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5369 while (my $line = <$fd>) {
5371 my ($file, $lno, $ltext, $binary);
5372 last if ($matches++ > 1000);
5373 if ($line =~ /^Binary file (.+) matches$/) {
5377 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5379 if ($file ne $lastfile) {
5380 $lastfile and print "</td></tr>\n";
5382 print "<tr class=\"dark\">\n";
5384 print "<tr class=\"light\">\n";
5386 print "<td class=\"list\">".
5387 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5388 file_name
=>"$file"),
5389 -class => "list"}, esc_path
($file));
5390 print "</td><td>\n";
5394 print "<div class=\"binary\">Binary file</div>\n";
5396 $ltext = untabify
($ltext);
5397 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5398 $ltext = esc_html
($1, -nbsp
=>1);
5399 $ltext .= '<span class="match">';
5400 $ltext .= esc_html
($2, -nbsp
=>1);
5401 $ltext .= '</span>';
5402 $ltext .= esc_html
($3, -nbsp
=>1);
5404 $ltext = esc_html
($ltext, -nbsp
=>1);
5406 print "<div class=\"pre\">" .
5407 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5408 file_name
=>"$file").'#l'.$lno,
5409 -class => "linenr"}, sprintf('%4i', $lno))
5410 . ' ' . $ltext . "</div>\n";
5414 print "</td></tr>\n";
5415 if ($matches > 1000) {
5416 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5419 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5428 sub git_search_help
{
5430 git_print_page_nav
('','', $hash,$hash,$hash);
5433 <dt><b>commit</b></dt>
5434 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5436 my ($have_grep) = gitweb_check_feature
('grep');
5439 <dt><b>grep</b></dt>
5440 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5441 a different one) are searched for the given
5442 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5443 (POSIX extended) and the matches are listed. On large
5444 trees, this search can take a while and put some strain on the server, so please use it with
5445 some consideration.</dd>
5449 <dt><b>author</b></dt>
5450 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5451 <dt><b>committer</b></dt>
5452 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5454 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5455 if ($have_pickaxe) {
5457 <dt><b>pickaxe</b></dt>
5458 <dd>All commits that caused the string to appear or disappear from any file (changes that
5459 added, removed or "modified" the string) will be listed. This search can take a while and
5460 takes a lot of strain on the server, so please use it wisely.</dd>
5468 my $head = git_get_head_hash
($project);
5469 if (!defined $hash) {
5472 if (!defined $page) {
5475 my $refs = git_get_references
();
5477 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5479 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5481 if ($#commitlist >= 100) {
5483 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5484 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5488 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5489 git_print_header_div
('summary', $project);
5491 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5496 ## ......................................................................
5497 ## feeds (RSS, Atom; OPML)
5500 my $format = shift || 'atom';
5501 my ($have_blame) = gitweb_check_feature
('blame');
5503 # Atom: http://www.atomenabled.org/developers/syndication/
5504 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5505 if ($format ne 'rss' && $format ne 'atom') {
5506 die_error
(undef, "Unknown web feed format");
5509 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5510 my $head = $hash || 'HEAD';
5511 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5515 my $content_type = "application/$format+xml";
5516 if (defined $cgi->http('HTTP_ACCEPT') &&
5517 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5518 # browser (feed reader) prefers text/xml
5519 $content_type = 'text/xml';
5521 if (defined($commitlist[0])) {
5522 %latest_commit = %{$commitlist[0]};
5523 %latest_date = parse_date
($latest_commit{'author_epoch'});
5525 -type
=> $content_type,
5526 -charset
=> 'utf-8',
5527 -last_modified
=> $latest_date{'rfc2822'});
5530 -type
=> $content_type,
5531 -charset
=> 'utf-8');
5534 # Optimization: skip generating the body if client asks only
5535 # for Last-Modified date.
5536 return if ($cgi->request_method() eq 'HEAD');
5539 my $title = "$site_name - $project/$action";
5540 my $feed_type = 'log';
5541 if (defined $hash) {
5542 $title .= " - '$hash'";
5543 $feed_type = 'branch log';
5544 if (defined $file_name) {
5545 $title .= " :: $file_name";
5546 $feed_type = 'history';
5548 } elsif (defined $file_name) {
5549 $title .= " - $file_name";
5550 $feed_type = 'history';
5552 $title .= " $feed_type";
5553 my $descr = git_get_project_description
($project);
5554 if (defined $descr) {
5555 $descr = esc_html
($descr);
5557 $descr = "$project " .
5558 ($format eq 'rss' ? 'RSS' : 'Atom') .
5561 my $owner = git_get_project_owner
($project);
5562 $owner = esc_html
($owner);
5566 if (defined $file_name) {
5567 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5568 } elsif (defined $hash) {
5569 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5571 $alt_url = href
(-full
=>1, action
=>"summary");
5573 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5574 if ($format eq 'rss') {
5576 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5579 print "<title>$title</title>\n" .
5580 "<link>$alt_url</link>\n" .
5581 "<description>$descr</description>\n" .
5582 "<language>en</language>\n";
5583 } elsif ($format eq 'atom') {
5585 <feed xmlns="http://www.w3.org/2005/Atom">
5587 print "<title>$title</title>\n" .
5588 "<subtitle>$descr</subtitle>\n" .
5589 '<link rel="alternate" type="text/html" href="' .
5590 $alt_url . '" />' . "\n" .
5591 '<link rel="self" type="' . $content_type . '" href="' .
5592 $cgi->self_url() . '" />' . "\n" .
5593 "<id>" . href
(-full
=>1) . "</id>\n" .
5594 # use project owner for feed author
5595 "<author><name>$owner</name></author>\n";
5596 if (defined $favicon) {
5597 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5599 if (defined $logo_url) {
5600 # not twice as wide as tall: 72 x 27 pixels
5601 print "<logo>" . esc_url
($logo) . "</logo>\n";
5603 if (! %latest_date) {
5604 # dummy date to keep the feed valid until commits trickle in:
5605 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5607 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5612 for (my $i = 0; $i <= $#commitlist; $i++) {
5613 my %co = %{$commitlist[$i]};
5614 my $commit = $co{'id'};
5615 # we read 150, we always show 30 and the ones more recent than 48 hours
5616 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5619 my %cd = parse_date
($co{'author_epoch'});
5621 # get list of changed files
5622 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5623 $co{'parent'} || "--root",
5624 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5626 my @difftree = map { chomp; $_ } <$fd>;
5630 # print element (entry, item)
5631 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5632 if ($format eq 'rss') {
5634 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5635 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5636 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5637 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5638 "<link>$co_url</link>\n" .
5639 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5640 "<content:encoded>" .
5642 } elsif ($format eq 'atom') {
5644 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5645 "<updated>$cd{'iso-8601'}</updated>\n" .
5647 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5648 if ($co{'author_email'}) {
5649 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5651 print "</author>\n" .
5652 # use committer for contributor
5654 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5655 if ($co{'committer_email'}) {
5656 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5658 print "</contributor>\n" .
5659 "<published>$cd{'iso-8601'}</published>\n" .
5660 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5661 "<id>$co_url</id>\n" .
5662 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5663 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5665 my $comment = $co{'comment'};
5667 foreach my $line (@$comment) {
5668 $line = esc_html
($line);
5671 print "</pre><ul>\n";
5672 foreach my $difftree_line (@difftree) {
5673 my %difftree = parse_difftree_raw_line
($difftree_line);
5674 next if !$difftree{'from_id'};
5676 my $file = $difftree{'file'} || $difftree{'to_file'};
5680 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5681 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5682 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5683 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5684 -title
=> "diff"}, 'D');
5686 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5687 file_name
=>$file, hash_base
=>$commit),
5688 -title
=> "blame"}, 'B');
5690 # if this is not a feed of a file history
5691 if (!defined $file_name || $file_name ne $file) {
5692 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5693 file_name
=>$file, hash
=>$commit),
5694 -title
=> "history"}, 'H');
5696 $file = esc_path
($file);
5700 if ($format eq 'rss') {
5701 print "</ul>]]>\n" .
5702 "</content:encoded>\n" .
5704 } elsif ($format eq 'atom') {
5705 print "</ul>\n</div>\n" .
5712 if ($format eq 'rss') {
5713 print "</channel>\n</rss>\n";
5714 } elsif ($format eq 'atom') {
5728 my @list = git_get_projects_list
();
5730 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5732 <?xml version="1.0" encoding="utf-8"?>
5733 <opml version="1.0">
5735 <title>$site_name OPML Export</title>
5738 <outline text="git RSS feeds">
5741 foreach my $pr (@list) {
5743 my $head = git_get_head_hash
($proj{'path'});
5744 if (!defined $head) {
5747 $git_dir = "$projectroot/$proj{'path'}";
5748 my %co = parse_commit
($head);
5753 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5754 my $rss = "$my_url?p=$proj{'path'};a=rss";
5755 my $html = "$my_url?p=$proj{'path'};a=summary";
5756 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";