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 = "debian.1.5.6.1.19.ge6b2";
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 = "/usr/bin/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "/pub/git";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = 2007;
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 # hcoop-change: Customize.
47 our $home_link_str = "HCoop";
49 # name of your site or organization to appear in page titles
50 # replace this with something more descriptive for clearer bookmarks
51 # hcoop-change: Customize.
52 our $site_name = "HCoop Git"
53 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
55 # filename of html text to include at top of each page
56 our $site_header = "";
57 # html text to include at home page
58 our $home_text = "indextext.html";
59 # filename of html text to include at bottom of each page
60 our $site_footer = "";
63 our @stylesheets = ("gitweb.css");
64 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
65 our $stylesheet = undef;
66 # URI of GIT logo (72x27 size)
67 our $logo = "git-logo.png";
68 # URI of GIT favicon, assumed to be image/png type
69 our $favicon = "git-favicon.png";
71 # URI and label (title) of GIT logo link
72 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
73 #our $logo_label = "git documentation";
74 our $logo_url = "http://git.or.cz/";
75 our $logo_label = "git homepage";
77 # source of projects list
78 our $projects_list = "";
80 # the width (in characters) of the projects list "Description" column
81 our $projects_list_description_width = 25;
83 # default order of projects list
84 # valid values are none, project, descr, owner, and age
85 our $default_projects_order = "project";
87 # show repository only if this file exists
88 # (only effective if this variable evaluates to true)
91 # only allow viewing of repositories also shown on the overview page
92 our $strict_export = "";
94 # list of git base URLs used for URL to where fetch project from,
95 # i.e. full URL is "$git_base_url/$project"
96 # hcoop-change: We like several URLs.
97 #our @git_base_url_list = grep { $_ ne '' } ("");
98 our @git_base_url_list = ('git://git.hcoop.net/git',
99 'http://git.hcoop.net/git');
101 # default blob_plain mimetype and default charset for text/plain blob
102 our $default_blob_plain_mimetype = 'text/plain';
103 our $default_text_plain_charset = undef;
105 # file to use for guessing MIME types before trying /etc/mime.types
106 # (relative to the current git repository)
107 our $mimetypes_file = undef;
109 # assume this charset if line contains non-UTF-8 characters;
110 # it should be valid encoding (see Encoding::Supported(3pm) for list),
111 # for which encoding all byte sequences are valid, for example
112 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
113 # could be even 'utf-8' for the old behavior)
114 our $fallback_encoding = 'latin1';
116 # rename detection options for git-diff and git-diff-tree
117 # - default is '-M', with the cost proportional to
118 # (number of removed files) * (number of new files).
119 # - more costly is '-C' (which implies '-M'), with the cost proportional to
120 # (number of changed files + number of removed files) * (number of new files)
121 # - even more costly is '-C', '--find-copies-harder' with cost
122 # (number of files in the original tree) * (number of new files)
123 # - one might want to include '-B' option, e.g. '-B', '-M'
124 our @diff_opts = ('-M'); # taken from git_commit
126 # information about snapshot formats that gitweb is capable of serving
127 our %known_snapshot_formats = (
129 # 'display' => display name,
130 # 'type' => mime type,
131 # 'suffix' => filename suffix,
132 # 'format' => --format for git-archive,
133 # 'compressor' => [compressor command and arguments]
134 # (array reference, optional)}
137 'display' => 'tar.gz',
138 'type' => 'application/x-gzip',
139 'suffix' => '.tar.gz',
141 'compressor' => ['gzip']},
144 'display' => 'tar.bz2',
145 'type' => 'application/x-bzip2',
146 'suffix' => '.tar.bz2',
148 'compressor' => ['bzip2']},
152 'type' => 'application/x-zip',
157 # Aliases so we understand old gitweb.snapshot values in repository
159 our %known_snapshot_format_aliases = (
163 # backward compatibility: legacy gitweb config support
164 'x-gzip' => undef, 'gz' => undef,
165 'x-bzip2' => undef, 'bz2' => undef,
166 'x-zip' => undef, '' => undef,
169 # You define site-wide feature defaults here; override them with
170 # $GITWEB_CONFIG as necessary.
173 # 'sub' => feature-sub (subroutine),
174 # 'override' => allow-override (boolean),
175 # 'default' => [ default options...] (array reference)}
177 # if feature is overridable (it means that allow-override has true value),
178 # then feature-sub will be called with default options as parameters;
179 # return value of feature-sub indicates if to enable specified feature
181 # if there is no 'sub' key (no feature-sub), then feature cannot be
184 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
186 # Enable the 'blame' blob view, showing the last commit that modified
187 # each line in the file. This can be very CPU-intensive.
189 # To enable system wide have in $GITWEB_CONFIG
190 # $feature{'blame'}{'default'} = [1];
191 # To have project specific config enable override in $GITWEB_CONFIG
192 # $feature{'blame'}{'override'} = 1;
193 # and in project config gitweb.blame = 0|1;
195 'sub' => \
&feature_blame
,
199 # Enable the 'snapshot' link, providing a compressed archive of any
200 # tree. This can potentially generate high traffic if you have large
203 # Value is a list of formats defined in %known_snapshot_formats that
205 # To disable system wide have in $GITWEB_CONFIG
206 # $feature{'snapshot'}{'default'} = [];
207 # To have project specific config enable override in $GITWEB_CONFIG
208 # $feature{'snapshot'}{'override'} = 1;
209 # and in project config, a comma-separated list of formats or "none"
210 # to disable. Example: gitweb.snapshot = tbz2,zip;
212 'sub' => \
&feature_snapshot
,
214 'default' => ['tgz']},
216 # Enable text search, which will list the commits which match author,
217 # committer or commit text to a given string. Enabled by default.
218 # Project specific override is not supported.
223 # Enable grep search, which will list the files in currently selected
224 # tree containing the given string. Enabled by default. This can be
225 # potentially CPU-intensive, of course.
227 # To enable system wide have in $GITWEB_CONFIG
228 # $feature{'grep'}{'default'} = [1];
229 # To have project specific config enable override in $GITWEB_CONFIG
230 # $feature{'grep'}{'override'} = 1;
231 # and in project config gitweb.grep = 0|1;
236 # Enable the pickaxe search, which will list the commits that modified
237 # a given string in a file. This can be practical and quite faster
238 # alternative to 'blame', but still potentially CPU-intensive.
240 # To enable system wide have in $GITWEB_CONFIG
241 # $feature{'pickaxe'}{'default'} = [1];
242 # To have project specific config enable override in $GITWEB_CONFIG
243 # $feature{'pickaxe'}{'override'} = 1;
244 # and in project config gitweb.pickaxe = 0|1;
246 'sub' => \
&feature_pickaxe
,
250 # Make gitweb use an alternative format of the URLs which can be
251 # more readable and natural-looking: project name is embedded
252 # directly in the path and the query string contains other
253 # auxiliary information. All gitweb installations recognize
254 # URL in either format; this configures in which formats gitweb
257 # To enable system wide have in $GITWEB_CONFIG
258 # $feature{'pathinfo'}{'default'} = [1];
259 # Project specific override is not supported.
261 # Note that you will need to change the default location of CSS,
262 # favicon, logo and possibly other files to an absolute URL. Also,
263 # if gitweb.cgi serves as your indexfile, you will need to force
264 # $my_uri to contain the script name in your $GITWEB_CONFIG.
269 # Make gitweb consider projects in project root subdirectories
270 # to be forks of existing projects. Given project $projname.git,
271 # projects matching $projname/*.git will not be shown in the main
272 # projects list, instead a '+' mark will be added to $projname
273 # there and a 'forks' view will be enabled for the project, listing
274 # all the forks. If project list is taken from a file, forks have
275 # to be listed after the main project.
277 # To enable system wide have in $GITWEB_CONFIG
278 # $feature{'forks'}{'default'} = [1];
279 # Project specific override is not supported.
285 sub gitweb_check_feature
{
287 return unless exists $feature{$name};
288 my ($sub, $override, @defaults) = (
289 $feature{$name}{'sub'},
290 $feature{$name}{'override'},
291 @
{$feature{$name}{'default'}});
292 if (!$override) { return @defaults; }
294 warn "feature $name is not overrideable";
297 return $sub->(@defaults);
301 my ($val) = git_get_project_config
('blame', '--bool');
303 if ($val eq 'true') {
305 } elsif ($val eq 'false') {
312 sub feature_snapshot
{
315 my ($val) = git_get_project_config
('snapshot');
318 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
325 my ($val) = git_get_project_config
('grep', '--bool');
327 if ($val eq 'true') {
329 } elsif ($val eq 'false') {
336 sub feature_pickaxe
{
337 my ($val) = git_get_project_config
('pickaxe', '--bool');
339 if ($val eq 'true') {
341 } elsif ($val eq 'false') {
348 # checking HEAD file with -e is fragile if the repository was
349 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
351 sub check_head_link
{
353 my $headfile = "$dir/HEAD";
354 return ((-e
$headfile) ||
355 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
358 sub check_export_ok
{
360 return (check_head_link
($dir) &&
361 (!$export_ok || -e
"$dir/$export_ok"));
364 # process alternate names for backward compatibility
365 # filter out unsupported (unknown) snapshot formats
366 sub filter_snapshot_fmts
{
370 exists $known_snapshot_format_aliases{$_} ?
371 $known_snapshot_format_aliases{$_} : $_} @fmts;
372 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
376 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
377 if (-e
$GITWEB_CONFIG) {
380 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
381 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
384 # version of the core git binary
385 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
387 $projects_list ||= $projectroot;
389 # ======================================================================
390 # input validation and dispatch
391 our $action = $cgi->param('a');
392 if (defined $action) {
393 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
394 die_error
(undef, "Invalid action parameter");
398 # parameters which are pathnames
399 our $project = $cgi->param('p');
400 if (defined $project) {
401 if (!validate_pathname
($project) ||
402 !(-d
"$projectroot/$project") ||
403 !check_head_link
("$projectroot/$project") ||
404 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
405 ($strict_export && !project_in_list
($project))) {
407 die_error
(undef, "No such project");
411 our $file_name = $cgi->param('f');
412 if (defined $file_name) {
413 if (!validate_pathname
($file_name)) {
414 die_error
(undef, "Invalid file parameter");
418 our $file_parent = $cgi->param('fp');
419 if (defined $file_parent) {
420 if (!validate_pathname
($file_parent)) {
421 die_error
(undef, "Invalid file parent parameter");
425 # parameters which are refnames
426 our $hash = $cgi->param('h');
428 if (!validate_refname
($hash)) {
429 die_error
(undef, "Invalid hash parameter");
433 our $hash_parent = $cgi->param('hp');
434 if (defined $hash_parent) {
435 if (!validate_refname
($hash_parent)) {
436 die_error
(undef, "Invalid hash parent parameter");
440 our $hash_base = $cgi->param('hb');
441 if (defined $hash_base) {
442 if (!validate_refname
($hash_base)) {
443 die_error
(undef, "Invalid hash base parameter");
447 my %allowed_options = (
448 "--no-merges" => [ qw(rss atom log shortlog history) ],
451 our @extra_options = $cgi->param('opt');
452 if (defined @extra_options) {
453 foreach my $opt (@extra_options) {
454 if (not exists $allowed_options{$opt}) {
455 die_error
(undef, "Invalid option parameter");
457 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
458 die_error
(undef, "Invalid option parameter for this action");
463 our $hash_parent_base = $cgi->param('hpb');
464 if (defined $hash_parent_base) {
465 if (!validate_refname
($hash_parent_base)) {
466 die_error
(undef, "Invalid hash parent base parameter");
471 our $page = $cgi->param('pg');
473 if ($page =~ m/[^0-9]/) {
474 die_error
(undef, "Invalid page parameter");
478 our $searchtype = $cgi->param('st');
479 if (defined $searchtype) {
480 if ($searchtype =~ m/[^a-z]/) {
481 die_error
(undef, "Invalid searchtype parameter");
485 our $search_use_regexp = $cgi->param('sr');
487 our $searchtext = $cgi->param('s');
489 if (defined $searchtext) {
490 if (length($searchtext) < 2) {
491 die_error
(undef, "At least two characters are required for search parameter");
493 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
496 # now read PATH_INFO and use it as alternative to parameters
497 sub evaluate_path_info
{
498 return if defined $project;
499 my $path_info = $ENV{"PATH_INFO"};
500 return if !$path_info;
501 $path_info =~ s
,^/+,,;
502 return if !$path_info;
503 # find which part of PATH_INFO is project
504 $project = $path_info;
506 while ($project && !check_head_link
("$projectroot/$project")) {
507 $project =~ s
,/*[^/]*$,,;
510 $project = validate_pathname
($project);
512 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
513 ($strict_export && !project_in_list
($project))) {
517 # do not change any parameters if an action is given using the query string
519 $path_info =~ s
,^\Q
$project\E
/*,,;
520 my ($refname, $pathname) = split(/:/, $path_info, 2);
521 if (defined $pathname) {
522 # we got "project.git/branch:filename" or "project.git/branch:dir/"
523 # we could use git_get_type(branch:pathname), but it needs $git_dir
524 $pathname =~ s
,^/+,,;
525 if (!$pathname || substr($pathname, -1) eq "/") {
529 $action ||= "blob_plain";
531 $hash_base ||= validate_refname
($refname);
532 $file_name ||= validate_pathname
($pathname);
533 } elsif (defined $refname) {
534 # we got "project.git/branch"
535 $action ||= "shortlog";
536 $hash ||= validate_refname
($refname);
539 evaluate_path_info
();
541 # path to the current git repository
543 $git_dir = "$projectroot/$project" if $project;
547 "blame" => \
&git_blame2
,
548 "blobdiff" => \
&git_blobdiff
,
549 "blobdiff_plain" => \
&git_blobdiff_plain
,
550 "blob" => \
&git_blob
,
551 "blob_plain" => \
&git_blob_plain
,
552 "commitdiff" => \
&git_commitdiff
,
553 "commitdiff_plain" => \
&git_commitdiff_plain
,
554 "commit" => \
&git_commit
,
555 "forks" => \
&git_forks
,
556 "heads" => \
&git_heads
,
557 "history" => \
&git_history
,
560 "atom" => \
&git_atom
,
561 "search" => \
&git_search
,
562 "search_help" => \
&git_search_help
,
563 "shortlog" => \
&git_shortlog
,
564 "summary" => \
&git_summary
,
566 "tags" => \
&git_tags
,
567 "tree" => \
&git_tree
,
568 "snapshot" => \
&git_snapshot
,
569 "object" => \
&git_object
,
570 # those below don't need $project
571 "opml" => \
&git_opml
,
572 "project_list" => \
&git_project_list
,
573 "project_index" => \
&git_project_index
,
576 if (!defined $action) {
578 $action = git_get_type
($hash);
579 } elsif (defined $hash_base && defined $file_name) {
580 $action = git_get_type
("$hash_base:$file_name");
581 } elsif (defined $project) {
584 $action = 'project_list';
587 if (!defined($actions{$action})) {
588 die_error
(undef, "Unknown action");
590 if ($action !~ m/^(opml|project_list|project_index)$/ &&
592 die_error
(undef, "Project needed");
594 $actions{$action}->();
597 ## ======================================================================
602 # default is to use -absolute url() i.e. $my_uri
603 my $href = $params{-full
} ?
$my_url : $my_uri;
605 # XXX: Warning: If you touch this, check the search form for updating,
616 hash_parent_base
=> "hpb",
621 snapshot_format
=> "sf",
622 extra_options
=> "opt",
623 search_use_regexp
=> "sr",
625 my %mapping = @mapping;
627 $params{'project'} = $project unless exists $params{'project'};
629 if ($params{-replay
}) {
630 while (my ($name, $symbol) = each %mapping) {
631 if (!exists $params{$name}) {
632 # to allow for multivalued params we use arrayref form
633 $params{$name} = [ $cgi->param($symbol) ];
638 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
640 # use PATH_INFO for project name
641 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
642 delete $params{'project'};
644 # Summary just uses the project path URL
645 if (defined $params{'action'} && $params{'action'} eq 'summary') {
646 delete $params{'action'};
650 # now encode the parameters explicitly
652 for (my $i = 0; $i < @mapping; $i += 2) {
653 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
654 if (defined $params{$name}) {
655 if (ref($params{$name}) eq "ARRAY") {
656 foreach my $par (@
{$params{$name}}) {
657 push @result, $symbol . "=" . esc_param
($par);
660 push @result, $symbol . "=" . esc_param
($params{$name});
664 $href .= "?" . join(';', @result) if scalar @result;
670 ## ======================================================================
671 ## validation, quoting/unquoting and escaping
673 sub validate_pathname
{
674 my $input = shift || return undef;
676 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
677 # at the beginning, at the end, and between slashes.
678 # also this catches doubled slashes
679 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
683 if ($input =~ m!\0!) {
689 sub validate_refname
{
690 my $input = shift || return undef;
692 # textual hashes are O.K.
693 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
696 # it must be correct pathname
697 $input = validate_pathname
($input)
699 # restrictions on ref name according to git-check-ref-format
700 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
706 # decode sequences of octets in utf8 into Perl's internal form,
707 # which is utf-8 with utf8 flag set if needed. gitweb writes out
708 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
711 if (utf8
::valid
($str)) {
715 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
719 # quote unsafe chars, but keep the slash, even when it's not
720 # correct, but quoted slashes look too horrible in bookmarks
723 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
729 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
732 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
738 # replace invalid utf8 character with SUBSTITUTION sequence
743 $str = to_utf8
($str);
744 $str = $cgi->escapeHTML($str);
745 if ($opts{'-nbsp'}) {
746 $str =~ s/ / /g;
748 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
752 # quote control characters and escape filename to HTML
757 $str = to_utf8
($str);
758 $str = $cgi->escapeHTML($str);
759 if ($opts{'-nbsp'}) {
760 $str =~ s/ / /g;
762 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
766 # Make control characters "printable", using character escape codes (CEC)
770 my %es = ( # character escape codes, aka escape sequences
771 "\t" => '\t', # tab (HT)
772 "\n" => '\n', # line feed (LF)
773 "\r" => '\r', # carrige return (CR)
774 "\f" => '\f', # form feed (FF)
775 "\b" => '\b', # backspace (BS)
776 "\a" => '\a', # alarm (bell) (BEL)
777 "\e" => '\e', # escape (ESC)
778 "\013" => '\v', # vertical tab (VT)
779 "\000" => '\0', # nul character (NUL)
781 my $chr = ( (exists $es{$cntrl})
783 : sprintf('\%03o', ord($cntrl)) );
784 if ($opts{-nohtml
}) {
787 return "<span class=\"cntrl\">$chr</span>";
791 # Alternatively use unicode control pictures codepoints,
792 # Unicode "printable representation" (PR)
797 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
798 if ($opts{-nohtml
}) {
801 return "<span class=\"cntrl\">$chr</span>";
805 # git may return quoted and escaped filenames
811 my %es = ( # character escape codes, aka escape sequences
812 't' => "\t", # tab (HT, TAB)
813 'n' => "\n", # newline (NL)
814 'r' => "\r", # return (CR)
815 'f' => "\f", # form feed (FF)
816 'b' => "\b", # backspace (BS)
817 'a' => "\a", # alarm (bell) (BEL)
818 'e' => "\e", # escape (ESC)
819 'v' => "\013", # vertical tab (VT)
822 if ($seq =~ m/^[0-7]{1,3}$/) {
823 # octal char sequence
824 return chr(oct($seq));
825 } elsif (exists $es{$seq}) {
826 # C escape sequence, aka character escape code
829 # quoted ordinary character
833 if ($str =~ m/^"(.*)"$/) {
836 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
841 # escape tabs (convert tabs to spaces)
845 while ((my $pos = index($line, "\t")) != -1) {
846 if (my $count = (8 - ($pos % 8))) {
847 my $spaces = ' ' x
$count;
848 $line =~ s/\t/$spaces/;
855 sub project_in_list
{
857 my @list = git_get_projects_list
();
858 return @list && scalar(grep { $_->{'path'} eq $project } @list);
861 ## ----------------------------------------------------------------------
862 ## HTML aware string manipulation
864 # Try to chop given string on a word boundary between position
865 # $len and $len+$add_len. If there is no word boundary there,
866 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
867 # (marking chopped part) would be longer than given string.
871 my $add_len = shift || 10;
872 my $where = shift || 'right'; # 'left' | 'center' | 'right'
874 # Make sure perl knows it is utf8 encoded so we don't
875 # cut in the middle of a utf8 multibyte char.
876 $str = to_utf8
($str);
878 # allow only $len chars, but don't cut a word if it would fit in $add_len
879 # if it doesn't fit, cut it if it's still longer than the dots we would add
880 # remove chopped character entities entirely
882 # when chopping in the middle, distribute $len into left and right part
883 # return early if chopping wouldn't make string shorter
884 if ($where eq 'center') {
885 return $str if ($len + 5 >= length($str)); # filler is length 5
888 return $str if ($len + 4 >= length($str)); # filler is length 4
891 # regexps: ending and beginning with word part up to $add_len
892 my $endre = qr/.{$len}\w{0,$add_len}/;
893 my $begre = qr/\w{0,$add_len}.{$len}/;
895 if ($where eq 'left') {
896 $str =~ m/^(.*?)($begre)$/;
897 my ($lead, $body) = ($1, $2);
898 if (length($lead) > 4) {
899 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
904 } elsif ($where eq 'center') {
905 $str =~ m/^($endre)(.*)$/;
906 my ($left, $str) = ($1, $2);
907 $str =~ m/^(.*?)($begre)$/;
908 my ($mid, $right) = ($1, $2);
909 if (length($mid) > 5) {
910 $left =~ s/&[^;]*$//;
911 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
914 return "$left$mid$right";
917 $str =~ m/^($endre)(.*)$/;
920 if (length($tail) > 4) {
921 $body =~ s/&[^;]*$//;
928 # takes the same arguments as chop_str, but also wraps a <span> around the
929 # result with a title attribute if it does get chopped. Additionally, the
930 # string is HTML-escaped.
931 sub chop_and_escape_str
{
934 my $chopped = chop_str
(@_);
935 if ($chopped eq $str) {
936 return esc_html
($chopped);
938 $str =~ s/([[:cntrl:]])/?/g;
939 return $cgi->span({-title
=>$str}, esc_html
($chopped));
943 ## ----------------------------------------------------------------------
944 ## functions returning short strings
946 # CSS class for given age value (in seconds)
952 } elsif ($age < 60*60*2) {
954 } elsif ($age < 60*60*24*2) {
961 # convert age in seconds to "nn units ago" string
966 if ($age > 60*60*24*365*2) {
967 $age_str = (int $age/60/60/24/365);
968 $age_str .= " years ago";
969 } elsif ($age > 60*60*24*(365/12)*2) {
970 $age_str = int $age/60/60/24/(365/12);
971 $age_str .= " months ago";
972 } elsif ($age > 60*60*24*7*2) {
973 $age_str = int $age/60/60/24/7;
974 $age_str .= " weeks ago";
975 } elsif ($age > 60*60*24*2) {
976 $age_str = int $age/60/60/24;
977 $age_str .= " days ago";
978 } elsif ($age > 60*60*2) {
979 $age_str = int $age/60/60;
980 $age_str .= " hours ago";
981 } elsif ($age > 60*2) {
982 $age_str = int $age/60;
983 $age_str .= " min ago";
986 $age_str .= " sec ago";
988 $age_str .= " right now";
994 S_IFINVALID
=> 0030000,
995 S_IFGITLINK
=> 0160000,
998 # submodule/subproject, a commit object reference
1002 return (($mode & S_IFMT
) == S_IFGITLINK
)
1005 # convert file mode in octal to symbolic file mode string
1007 my $mode = oct shift;
1009 if (S_ISGITLINK
($mode)) {
1010 return 'm---------';
1011 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1012 return 'drwxr-xr-x';
1013 } elsif (S_ISLNK
($mode)) {
1014 return 'lrwxrwxrwx';
1015 } elsif (S_ISREG
($mode)) {
1016 # git cares only about the executable bit
1017 if ($mode & S_IXUSR
) {
1018 return '-rwxr-xr-x';
1020 return '-rw-r--r--';
1023 return '----------';
1027 # convert file mode in octal to file type string
1031 if ($mode !~ m/^[0-7]+$/) {
1037 if (S_ISGITLINK
($mode)) {
1039 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1041 } elsif (S_ISLNK
($mode)) {
1043 } elsif (S_ISREG
($mode)) {
1050 # convert file mode in octal to file type description string
1051 sub file_type_long
{
1054 if ($mode !~ m/^[0-7]+$/) {
1060 if (S_ISGITLINK
($mode)) {
1062 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1064 } elsif (S_ISLNK
($mode)) {
1066 } elsif (S_ISREG
($mode)) {
1067 if ($mode & S_IXUSR
) {
1068 return "executable";
1078 ## ----------------------------------------------------------------------
1079 ## functions returning short HTML fragments, or transforming HTML fragments
1080 ## which don't belong to other sections
1082 # format line of commit message.
1083 sub format_log_line_html
{
1086 $line = esc_html
($line, -nbsp
=>1);
1087 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1090 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1091 -class => "text"}, $hash_text);
1092 $line =~ s/$hash_text/$link/;
1097 # format marker of refs pointing to given object
1098 sub format_ref_marker
{
1099 my ($refs, $id) = @_;
1102 if (defined $refs->{$id}) {
1103 foreach my $ref (@
{$refs->{$id}}) {
1104 my ($type, $name) = qw();
1105 # e.g. tags/v2.6.11 or heads/next
1106 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1114 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1115 esc_html
($name) . "</span>";
1120 return ' <span class="refs">'. $markers . '</span>';
1126 # format, perhaps shortened and with markers, title line
1127 sub format_subject_html
{
1128 my ($long, $short, $href, $extra) = @_;
1129 $extra = '' unless defined($extra);
1131 if (length($short) < length($long)) {
1132 return $cgi->a({-href
=> $href, -class => "list subject",
1133 -title
=> to_utf8
($long)},
1134 esc_html
($short) . $extra);
1136 return $cgi->a({-href
=> $href, -class => "list subject"},
1137 esc_html
($long) . $extra);
1141 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1142 sub format_git_diff_header_line
{
1144 my $diffinfo = shift;
1145 my ($from, $to) = @_;
1147 if ($diffinfo->{'nparents'}) {
1149 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1150 if ($to->{'href'}) {
1151 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1152 esc_path
($to->{'file'}));
1153 } else { # file was deleted (no href)
1154 $line .= esc_path
($to->{'file'});
1158 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1159 if ($from->{'href'}) {
1160 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1161 'a/' . esc_path
($from->{'file'}));
1162 } else { # file was added (no href)
1163 $line .= 'a/' . esc_path
($from->{'file'});
1166 if ($to->{'href'}) {
1167 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1168 'b/' . esc_path
($to->{'file'}));
1169 } else { # file was deleted
1170 $line .= 'b/' . esc_path
($to->{'file'});
1174 return "<div class=\"diff header\">$line</div>\n";
1177 # format extended diff header line, before patch itself
1178 sub format_extended_diff_header_line
{
1180 my $diffinfo = shift;
1181 my ($from, $to) = @_;
1184 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1185 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1186 esc_path
($from->{'file'}));
1188 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1189 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1190 esc_path
($to->{'file'}));
1192 # match single <mode>
1193 if ($line =~ m/\s(\d{6})$/) {
1194 $line .= '<span class="info"> (' .
1195 file_type_long
($1) .
1199 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1200 # can match only for combined diff
1202 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1203 if ($from->{'href'}[$i]) {
1204 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1206 substr($diffinfo->{'from_id'}[$i],0,7));
1211 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1214 if ($to->{'href'}) {
1215 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1216 substr($diffinfo->{'to_id'},0,7));
1221 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1222 # can match only for ordinary diff
1223 my ($from_link, $to_link);
1224 if ($from->{'href'}) {
1225 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1226 substr($diffinfo->{'from_id'},0,7));
1228 $from_link = '0' x
7;
1230 if ($to->{'href'}) {
1231 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1232 substr($diffinfo->{'to_id'},0,7));
1236 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1237 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1240 return $line . "<br/>\n";
1243 # format from-file/to-file diff header
1244 sub format_diff_from_to_header
{
1245 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1250 #assert($line =~ m/^---/) if DEBUG;
1251 # no extra formatting for "^--- /dev/null"
1252 if (! $diffinfo->{'nparents'}) {
1253 # ordinary (single parent) diff
1254 if ($line =~ m!^--- "?a/!) {
1255 if ($from->{'href'}) {
1257 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1258 esc_path
($from->{'file'}));
1261 esc_path
($from->{'file'});
1264 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1267 # combined diff (merge commit)
1268 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1269 if ($from->{'href'}[$i]) {
1271 $cgi->a({-href
=>href
(action
=>"blobdiff",
1272 hash_parent
=>$diffinfo->{'from_id'}[$i],
1273 hash_parent_base
=>$parents[$i],
1274 file_parent
=>$from->{'file'}[$i],
1275 hash
=>$diffinfo->{'to_id'},
1277 file_name
=>$to->{'file'}),
1279 -title
=>"diff" . ($i+1)},
1282 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1283 esc_path
($from->{'file'}[$i]));
1285 $line = '--- /dev/null';
1287 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1292 #assert($line =~ m/^\+\+\+/) if DEBUG;
1293 # no extra formatting for "^+++ /dev/null"
1294 if ($line =~ m!^\+\+\+ "?b/!) {
1295 if ($to->{'href'}) {
1297 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1298 esc_path
($to->{'file'}));
1301 esc_path
($to->{'file'});
1304 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1309 # create note for patch simplified by combined diff
1310 sub format_diff_cc_simplified
{
1311 my ($diffinfo, @parents) = @_;
1314 $result .= "<div class=\"diff header\">" .
1316 if (!is_deleted
($diffinfo)) {
1317 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1319 hash
=>$diffinfo->{'to_id'},
1320 file_name
=>$diffinfo->{'to_file'}),
1322 esc_path
($diffinfo->{'to_file'}));
1324 $result .= esc_path
($diffinfo->{'to_file'});
1326 $result .= "</div>\n" . # class="diff header"
1327 "<div class=\"diff nodifferences\">" .
1329 "</div>\n"; # class="diff nodifferences"
1334 # format patch (diff) line (not to be used for diff headers)
1335 sub format_diff_line
{
1337 my ($from, $to) = @_;
1338 my $diff_class = "";
1342 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1344 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1345 if ($line =~ m/^\@{3}/) {
1346 $diff_class = " chunk_header";
1347 } elsif ($line =~ m/^\\/) {
1348 $diff_class = " incomplete";
1349 } elsif ($prefix =~ tr/+/+/) {
1350 $diff_class = " add";
1351 } elsif ($prefix =~ tr/-/-/) {
1352 $diff_class = " rem";
1355 # assume ordinary diff
1356 my $char = substr($line, 0, 1);
1358 $diff_class = " add";
1359 } elsif ($char eq '-') {
1360 $diff_class = " rem";
1361 } elsif ($char eq '@') {
1362 $diff_class = " chunk_header";
1363 } elsif ($char eq "\\") {
1364 $diff_class = " incomplete";
1367 $line = untabify
($line);
1368 if ($from && $to && $line =~ m/^\@{2} /) {
1369 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1370 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1372 $from_lines = 0 unless defined $from_lines;
1373 $to_lines = 0 unless defined $to_lines;
1375 if ($from->{'href'}) {
1376 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1377 -class=>"list"}, $from_text);
1379 if ($to->{'href'}) {
1380 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1381 -class=>"list"}, $to_text);
1383 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1384 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1385 return "<div class=\"diff$diff_class\">$line</div>\n";
1386 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1387 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1388 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1390 @from_text = split(' ', $ranges);
1391 for (my $i = 0; $i < @from_text; ++$i) {
1392 ($from_start[$i], $from_nlines[$i]) =
1393 (split(',', substr($from_text[$i], 1)), 0);
1396 $to_text = pop @from_text;
1397 $to_start = pop @from_start;
1398 $to_nlines = pop @from_nlines;
1400 $line = "<span class=\"chunk_info\">$prefix ";
1401 for (my $i = 0; $i < @from_text; ++$i) {
1402 if ($from->{'href'}[$i]) {
1403 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1404 -class=>"list"}, $from_text[$i]);
1406 $line .= $from_text[$i];
1410 if ($to->{'href'}) {
1411 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1412 -class=>"list"}, $to_text);
1416 $line .= " $prefix</span>" .
1417 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1418 return "<div class=\"diff$diff_class\">$line</div>\n";
1420 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1423 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1424 # linked. Pass the hash of the tree/commit to snapshot.
1425 sub format_snapshot_links
{
1427 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1428 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1429 my $num_fmts = @snapshot_fmts;
1430 if ($num_fmts > 1) {
1431 # A parenthesized list of links bearing format names.
1432 # e.g. "snapshot (_tar.gz_ _zip_)"
1433 return "snapshot (" . join(' ', map
1440 }, $known_snapshot_formats{$_}{'display'})
1441 , @snapshot_fmts) . ")";
1442 } elsif ($num_fmts == 1) {
1443 # A single "snapshot" link whose tooltip bears the format name.
1445 my ($fmt) = @snapshot_fmts;
1451 snapshot_format
=>$fmt
1453 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1455 } else { # $num_fmts == 0
1460 ## ......................................................................
1461 ## functions returning values to be passed, perhaps after some
1462 ## transformation, to other functions; e.g. returning arguments to href()
1464 # returns hash to be passed to href to generate gitweb URL
1465 # in -title key it returns description of link
1467 my $format = shift || 'Atom';
1468 my %res = (action
=> lc($format));
1470 # feed links are possible only for project views
1471 return unless (defined $project);
1472 # some views should link to OPML, or to generic project feed,
1473 # or don't have specific feed yet (so they should use generic)
1474 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1477 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1478 # from tag links; this also makes possible to detect branch links
1479 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1480 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1483 # find log type for feed description (title)
1485 if (defined $file_name) {
1486 $type = "history of $file_name";
1487 $type .= "/" if ($action eq 'tree');
1488 $type .= " on '$branch'" if (defined $branch);
1490 $type = "log of $branch" if (defined $branch);
1493 $res{-title
} = $type;
1494 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1495 $res{'file_name'} = $file_name;
1500 ## ----------------------------------------------------------------------
1501 ## git utility subroutines, invoking git commands
1503 # returns path to the core git executable and the --git-dir parameter as list
1505 return $GIT, '--git-dir='.$git_dir;
1508 # quote the given arguments for passing them to the shell
1509 # quote_command("command", "arg 1", "arg with ' and ! characters")
1510 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1511 # Try to avoid using this function wherever possible.
1514 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1517 # get HEAD ref of given project as hash
1518 sub git_get_head_hash
{
1519 my $project = shift;
1520 my $o_git_dir = $git_dir;
1522 $git_dir = "$projectroot/$project";
1523 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1526 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1530 if (defined $o_git_dir) {
1531 $git_dir = $o_git_dir;
1536 # get type of given object
1540 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1542 close $fd or return;
1547 # repository configuration
1548 our $config_file = '';
1551 # store multiple values for single key as anonymous array reference
1552 # single values stored directly in the hash, not as [ <value> ]
1553 sub hash_set_multi
{
1554 my ($hash, $key, $value) = @_;
1556 if (!exists $hash->{$key}) {
1557 $hash->{$key} = $value;
1558 } elsif (!ref $hash->{$key}) {
1559 $hash->{$key} = [ $hash->{$key}, $value ];
1561 push @
{$hash->{$key}}, $value;
1565 # return hash of git project configuration
1566 # optionally limited to some section, e.g. 'gitweb'
1567 sub git_parse_project_config
{
1568 my $section_regexp = shift;
1573 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1576 while (my $keyval = <$fh>) {
1578 my ($key, $value) = split(/\n/, $keyval, 2);
1580 hash_set_multi
(\
%config, $key, $value)
1581 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1588 # convert config value to boolean, 'true' or 'false'
1589 # no value, number > 0, 'true' and 'yes' values are true
1590 # rest of values are treated as false (never as error)
1591 sub config_to_bool
{
1594 # strip leading and trailing whitespace
1598 return (!defined $val || # section.key
1599 ($val =~ /^\d+$/ && $val) || # section.key = 1
1600 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1603 # convert config value to simple decimal number
1604 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1605 # to be multiplied by 1024, 1048576, or 1073741824
1609 # strip leading and trailing whitespace
1613 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1615 # unknown unit is treated as 1
1616 return $num * ($unit eq 'g' ?
1073741824 :
1617 $unit eq 'm' ?
1048576 :
1618 $unit eq 'k' ?
1024 : 1);
1623 # convert config value to array reference, if needed
1624 sub config_to_multi
{
1627 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1630 sub git_get_project_config
{
1631 my ($key, $type) = @_;
1634 return unless ($key);
1635 $key =~ s/^gitweb\.//;
1636 return if ($key =~ m/\W/);
1639 if (defined $type) {
1642 unless ($type eq 'bool' || $type eq 'int');
1646 if (!defined $config_file ||
1647 $config_file ne "$git_dir/config") {
1648 %config = git_parse_project_config
('gitweb');
1649 $config_file = "$git_dir/config";
1653 if (!defined $type) {
1654 return $config{"gitweb.$key"};
1655 } elsif ($type eq 'bool') {
1656 # backward compatibility: 'git config --bool' returns true/false
1657 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1658 } elsif ($type eq 'int') {
1659 return config_to_int
($config{"gitweb.$key"});
1661 return $config{"gitweb.$key"};
1664 # get hash of given path at given ref
1665 sub git_get_hash_by_path
{
1667 my $path = shift || return undef;
1672 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1673 or die_error
(undef, "Open git-ls-tree failed");
1675 close $fd or return undef;
1677 if (!defined $line) {
1678 # there is no tree or hash given by $path at $base
1682 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1683 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1684 if (defined $type && $type ne $2) {
1685 # type doesn't match
1691 # get path of entry with given hash at given tree-ish (ref)
1692 # used to get 'from' filename for combined diff (merge commit) for renames
1693 sub git_get_path_by_hash
{
1694 my $base = shift || return;
1695 my $hash = shift || return;
1699 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1701 while (my $line = <$fd>) {
1704 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1705 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1706 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1715 ## ......................................................................
1716 ## git utility functions, directly accessing git repository
1718 sub git_get_project_description
{
1721 $git_dir = "$projectroot/$path";
1722 open my $fd, "$git_dir/description"
1723 or return git_get_project_config
('description');
1726 if (defined $descr) {
1732 sub git_get_project_url_list
{
1735 $git_dir = "$projectroot/$path";
1736 open my $fd, "$git_dir/cloneurl"
1737 or return wantarray ?
1738 @
{ config_to_multi
(git_get_project_config
('url')) } :
1739 config_to_multi
(git_get_project_config
('url'));
1740 my @git_project_url_list = map { chomp; $_ } <$fd>;
1743 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1746 sub git_get_projects_list
{
1751 $filter =~ s/\.git$//;
1753 my ($check_forks) = gitweb_check_feature
('forks');
1755 if (-d
$projects_list) {
1756 # search in directory
1757 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1758 # remove the trailing "/"
1760 my $pfxlen = length("$dir");
1761 my $pfxdepth = ($dir =~ tr!/!!);
1764 follow_fast
=> 1, # follow symbolic links
1765 follow_skip
=> 2, # ignore duplicates
1766 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1768 # skip project-list toplevel, if we get it.
1769 return if (m!^[/.]$!);
1770 # only directories can be git repositories
1771 return unless (-d
$_);
1772 # don't traverse too deep (Find is super slow on os x)
1773 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1774 $File::Find
::prune
= 1;
1778 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1779 # we check related file in $projectroot
1780 if ($check_forks and $subdir =~ m
#/.#) {
1781 $File::Find
::prune
= 1;
1782 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1783 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1784 $File::Find
::prune
= 1;
1789 } elsif (-f
$projects_list) {
1790 # read from file(url-encoded):
1791 # 'git%2Fgit.git Linus+Torvalds'
1792 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1793 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1795 open my ($fd), $projects_list or return;
1797 while (my $line = <$fd>) {
1799 my ($path, $owner) = split ' ', $line;
1800 $path = unescape
($path);
1801 $owner = unescape
($owner);
1802 if (!defined $path) {
1805 if ($filter ne '') {
1806 # looking for forks;
1807 my $pfx = substr($path, 0, length($filter));
1808 if ($pfx ne $filter) {
1811 my $sfx = substr($path, length($filter));
1812 if ($sfx !~ /^\/.*\
.git
$/) {
1815 } elsif ($check_forks) {
1817 foreach my $filter (keys %paths) {
1818 # looking for forks;
1819 my $pfx = substr($path, 0, length($filter));
1820 if ($pfx ne $filter) {
1823 my $sfx = substr($path, length($filter));
1824 if ($sfx !~ /^\/.*\
.git
$/) {
1827 # is a fork, don't include it in
1832 if (check_export_ok
("$projectroot/$path")) {
1835 owner
=> to_utf8
($owner),
1838 (my $forks_path = $path) =~ s/\.git$//;
1839 $paths{$forks_path}++;
1847 our $gitweb_project_owner = undef;
1848 sub git_get_project_list_from_file
{
1850 return if (defined $gitweb_project_owner);
1852 $gitweb_project_owner = {};
1853 # read from file (url-encoded):
1854 # 'git%2Fgit.git Linus+Torvalds'
1855 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1856 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1857 if (-f
$projects_list) {
1858 open (my $fd , $projects_list);
1859 while (my $line = <$fd>) {
1861 my ($pr, $ow) = split ' ', $line;
1862 $pr = unescape
($pr);
1863 $ow = unescape
($ow);
1864 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1870 sub git_get_project_owner
{
1871 my $project = shift;
1874 return undef unless $project;
1875 $git_dir = "$projectroot/$project";
1877 if (!defined $gitweb_project_owner) {
1878 git_get_project_list_from_file
();
1881 if (exists $gitweb_project_owner->{$project}) {
1882 $owner = $gitweb_project_owner->{$project};
1884 if (!defined $owner){
1885 $owner = git_get_project_config
('owner');
1887 if (!defined $owner) {
1888 $owner = get_file_owner
("$git_dir");
1894 sub git_get_last_activity
{
1898 $git_dir = "$projectroot/$path";
1899 open($fd, "-|", git_cmd
(), 'for-each-ref',
1900 '--format=%(committer)',
1901 '--sort=-committerdate',
1903 'refs/heads') or return;
1904 my $most_recent = <$fd>;
1905 close $fd or return;
1906 if (defined $most_recent &&
1907 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1909 my $age = time - $timestamp;
1910 return ($age, age_string
($age));
1912 return (undef, undef);
1915 sub git_get_references
{
1916 my $type = shift || "";
1918 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1919 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1920 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1921 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1924 while (my $line = <$fd>) {
1926 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1927 if (defined $refs{$1}) {
1928 push @
{$refs{$1}}, $2;
1934 close $fd or return;
1938 sub git_get_rev_name_tags
{
1939 my $hash = shift || return undef;
1941 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1943 my $name_rev = <$fd>;
1946 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1949 # catches also '$hash undefined' output
1954 ## ----------------------------------------------------------------------
1955 ## parse to hash functions
1959 my $tz = shift || "-0000";
1962 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1963 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1964 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1965 $date{'hour'} = $hour;
1966 $date{'minute'} = $min;
1967 $date{'mday'} = $mday;
1968 $date{'day'} = $days[$wday];
1969 $date{'month'} = $months[$mon];
1970 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1971 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1972 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1973 $mday, $months[$mon], $hour ,$min;
1974 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1975 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1977 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1978 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1979 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1980 $date{'hour_local'} = $hour;
1981 $date{'minute_local'} = $min;
1982 $date{'tz_local'} = $tz;
1983 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1984 1900+$year, $mon+1, $mday,
1985 $hour, $min, $sec, $tz);
1994 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1995 $tag{'id'} = $tag_id;
1996 while (my $line = <$fd>) {
1998 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1999 $tag{'object'} = $1;
2000 } elsif ($line =~ m/^type (.+)$/) {
2002 } elsif ($line =~ m/^tag (.+)$/) {
2004 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2005 $tag{'author'} = $1;
2008 } elsif ($line =~ m/--BEGIN/) {
2009 push @comment, $line;
2011 } elsif ($line eq "") {
2015 push @comment, <$fd>;
2016 $tag{'comment'} = \
@comment;
2017 close $fd or return;
2018 if (!defined $tag{'name'}) {
2024 sub parse_commit_text
{
2025 my ($commit_text, $withparents) = @_;
2026 my @commit_lines = split '\n', $commit_text;
2029 pop @commit_lines; # Remove '\0'
2031 if (! @commit_lines) {
2035 my $header = shift @commit_lines;
2036 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2039 ($co{'id'}, my @parents) = split ' ', $header;
2040 while (my $line = shift @commit_lines) {
2041 last if $line eq "\n";
2042 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2044 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2046 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2048 $co{'author_epoch'} = $2;
2049 $co{'author_tz'} = $3;
2050 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2051 $co{'author_name'} = $1;
2052 $co{'author_email'} = $2;
2054 $co{'author_name'} = $co{'author'};
2056 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2057 $co{'committer'} = $1;
2058 $co{'committer_epoch'} = $2;
2059 $co{'committer_tz'} = $3;
2060 $co{'committer_name'} = $co{'committer'};
2061 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2062 $co{'committer_name'} = $1;
2063 $co{'committer_email'} = $2;
2065 $co{'committer_name'} = $co{'committer'};
2069 if (!defined $co{'tree'}) {
2072 $co{'parents'} = \
@parents;
2073 $co{'parent'} = $parents[0];
2075 foreach my $title (@commit_lines) {
2078 $co{'title'} = chop_str
($title, 80, 5);
2079 # remove leading stuff of merges to make the interesting part visible
2080 if (length($title) > 50) {
2081 $title =~ s/^Automatic //;
2082 $title =~ s/^merge (of|with) /Merge ... /i;
2083 if (length($title) > 50) {
2084 $title =~ s/(http|rsync):\/\///;
2086 if (length($title) > 50) {
2087 $title =~ s/(master|www|rsync)\.//;
2089 if (length($title) > 50) {
2090 $title =~ s/kernel.org:?//;
2092 if (length($title) > 50) {
2093 $title =~ s/\/pub\/scm//;
2096 $co{'title_short'} = chop_str
($title, 50, 5);
2100 if ($co{'title'} eq "") {
2101 $co{'title'} = $co{'title_short'} = '(no commit message)';
2103 # remove added spaces
2104 foreach my $line (@commit_lines) {
2107 $co{'comment'} = \
@commit_lines;
2109 my $age = time - $co{'committer_epoch'};
2111 $co{'age_string'} = age_string
($age);
2112 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2113 if ($age > 60*60*24*7*2) {
2114 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2115 $co{'age_string_age'} = $co{'age_string'};
2117 $co{'age_string_date'} = $co{'age_string'};
2118 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2124 my ($commit_id) = @_;
2129 open my $fd, "-|", git_cmd
(), "rev-list",
2135 or die_error
(undef, "Open git-rev-list failed");
2136 %co = parse_commit_text
(<$fd>, 1);
2143 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2151 open my $fd, "-|", git_cmd
(), "rev-list",
2154 ("--max-count=" . $maxcount),
2155 ("--skip=" . $skip),
2159 ($filename ?
($filename) : ())
2160 or die_error
(undef, "Open git-rev-list failed");
2161 while (my $line = <$fd>) {
2162 my %co = parse_commit_text
($line);
2167 return wantarray ?
@cos : \
@cos;
2170 # parse line of git-diff-tree "raw" output
2171 sub parse_difftree_raw_line
{
2175 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2176 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2177 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2178 $res{'from_mode'} = $1;
2179 $res{'to_mode'} = $2;
2180 $res{'from_id'} = $3;
2182 $res{'status'} = $5;
2183 $res{'similarity'} = $6;
2184 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2185 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2187 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2190 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2191 # combined diff (for merge commit)
2192 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2193 $res{'nparents'} = length($1);
2194 $res{'from_mode'} = [ split(' ', $2) ];
2195 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2196 $res{'from_id'} = [ split(' ', $3) ];
2197 $res{'to_id'} = pop @
{$res{'from_id'}};
2198 $res{'status'} = [ split('', $4) ];
2199 $res{'to_file'} = unquote
($5);
2201 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2202 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2203 $res{'commit'} = $1;
2206 return wantarray ?
%res : \
%res;
2209 # wrapper: return parsed line of git-diff-tree "raw" output
2210 # (the argument might be raw line, or parsed info)
2211 sub parsed_difftree_line
{
2212 my $line_or_ref = shift;
2214 if (ref($line_or_ref) eq "HASH") {
2215 # pre-parsed (or generated by hand)
2216 return $line_or_ref;
2218 return parse_difftree_raw_line
($line_or_ref);
2222 # parse line of git-ls-tree output
2223 sub parse_ls_tree_line
($;%) {
2228 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2229 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2237 $res{'name'} = unquote
($4);
2240 return wantarray ?
%res : \
%res;
2243 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2244 sub parse_from_to_diffinfo
{
2245 my ($diffinfo, $from, $to, @parents) = @_;
2247 if ($diffinfo->{'nparents'}) {
2249 $from->{'file'} = [];
2250 $from->{'href'} = [];
2251 fill_from_file_info
($diffinfo, @parents)
2252 unless exists $diffinfo->{'from_file'};
2253 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2254 $from->{'file'}[$i] =
2255 defined $diffinfo->{'from_file'}[$i] ?
2256 $diffinfo->{'from_file'}[$i] :
2257 $diffinfo->{'to_file'};
2258 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2259 $from->{'href'}[$i] = href
(action
=>"blob",
2260 hash_base
=>$parents[$i],
2261 hash
=>$diffinfo->{'from_id'}[$i],
2262 file_name
=>$from->{'file'}[$i]);
2264 $from->{'href'}[$i] = undef;
2268 # ordinary (not combined) diff
2269 $from->{'file'} = $diffinfo->{'from_file'};
2270 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2271 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2272 hash
=>$diffinfo->{'from_id'},
2273 file_name
=>$from->{'file'});
2275 delete $from->{'href'};
2279 $to->{'file'} = $diffinfo->{'to_file'};
2280 if (!is_deleted
($diffinfo)) { # file exists in result
2281 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2282 hash
=>$diffinfo->{'to_id'},
2283 file_name
=>$to->{'file'});
2285 delete $to->{'href'};
2289 ## ......................................................................
2290 ## parse to array of hashes functions
2292 sub git_get_heads_list
{
2296 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2297 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2298 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2301 while (my $line = <$fd>) {
2305 my ($refinfo, $committerinfo) = split(/\0/, $line);
2306 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2307 my ($committer, $epoch, $tz) =
2308 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2309 $ref_item{'fullname'} = $name;
2310 $name =~ s!^refs/heads/!!;
2312 $ref_item{'name'} = $name;
2313 $ref_item{'id'} = $hash;
2314 $ref_item{'title'} = $title || '(no commit message)';
2315 $ref_item{'epoch'} = $epoch;
2317 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2319 $ref_item{'age'} = "unknown";
2322 push @headslist, \
%ref_item;
2326 return wantarray ?
@headslist : \
@headslist;
2329 sub git_get_tags_list
{
2333 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2334 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2335 '--format=%(objectname) %(objecttype) %(refname) '.
2336 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2339 while (my $line = <$fd>) {
2343 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2344 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2345 my ($creator, $epoch, $tz) =
2346 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2347 $ref_item{'fullname'} = $name;
2348 $name =~ s!^refs/tags/!!;
2350 $ref_item{'type'} = $type;
2351 $ref_item{'id'} = $id;
2352 $ref_item{'name'} = $name;
2353 if ($type eq "tag") {
2354 $ref_item{'subject'} = $title;
2355 $ref_item{'reftype'} = $reftype;
2356 $ref_item{'refid'} = $refid;
2358 $ref_item{'reftype'} = $type;
2359 $ref_item{'refid'} = $id;
2362 if ($type eq "tag" || $type eq "commit") {
2363 $ref_item{'epoch'} = $epoch;
2365 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2367 $ref_item{'age'} = "unknown";
2371 push @tagslist, \
%ref_item;
2375 return wantarray ?
@tagslist : \
@tagslist;
2378 ## ----------------------------------------------------------------------
2379 ## filesystem-related functions
2381 sub get_file_owner
{
2384 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2385 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2386 if (!defined $gcos) {
2390 $owner =~ s/[,;].*$//;
2391 return to_utf8
($owner);
2394 ## ......................................................................
2395 ## mimetype related functions
2397 sub mimetype_guess_file
{
2398 my $filename = shift;
2399 my $mimemap = shift;
2400 -r
$mimemap or return undef;
2403 open(MIME
, $mimemap) or return undef;
2405 next if m/^#/; # skip comments
2406 my ($mime, $exts) = split(/\t+/);
2407 if (defined $exts) {
2408 my @exts = split(/\s+/, $exts);
2409 foreach my $ext (@exts) {
2410 $mimemap{$ext} = $mime;
2416 $filename =~ /\.([^.]*)$/;
2417 return $mimemap{$1};
2420 sub mimetype_guess
{
2421 my $filename = shift;
2423 $filename =~ /\./ or return undef;
2425 if ($mimetypes_file) {
2426 my $file = $mimetypes_file;
2427 if ($file !~ m!^/!) { # if it is relative path
2428 # it is relative to project
2429 $file = "$projectroot/$project/$file";
2431 $mime = mimetype_guess_file
($filename, $file);
2433 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2439 my $filename = shift;
2442 my $mime = mimetype_guess
($filename);
2443 $mime and return $mime;
2447 return $default_blob_plain_mimetype unless $fd;
2450 return 'text/plain';
2451 } elsif (! $filename) {
2452 return 'application/octet-stream';
2453 } elsif ($filename =~ m/\.png$/i) {
2455 } elsif ($filename =~ m/\.gif$/i) {
2457 } elsif ($filename =~ m/\.jpe?g$/i) {
2458 return 'image/jpeg';
2460 return 'application/octet-stream';
2464 sub blob_contenttype
{
2465 my ($fd, $file_name, $type) = @_;
2467 $type ||= blob_mimetype
($fd, $file_name);
2468 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2469 $type .= "; charset=$default_text_plain_charset";
2475 ## ======================================================================
2476 ## functions printing HTML: header, footer, error page
2478 sub git_header_html
{
2479 my $status = shift || "200 OK";
2480 my $expires = shift;
2482 my $title = "$site_name";
2483 if (defined $project) {
2484 $title .= " - " . to_utf8
($project);
2485 if (defined $action) {
2486 $title .= "/$action";
2487 if (defined $file_name) {
2488 $title .= " - " . esc_path
($file_name);
2489 if ($action eq "tree" && $file_name !~ m
|/$|) {
2496 # require explicit support from the UA if we are to send the page as
2497 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2498 # we have to do this because MSIE sometimes globs '*/*', pretending to
2499 # support xhtml+xml but choking when it gets what it asked for.
2500 if (defined $cgi->http('HTTP_ACCEPT') &&
2501 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2502 $cgi->Accept('application/xhtml+xml') != 0) {
2503 $content_type = 'application/xhtml+xml';
2505 $content_type = 'text/html';
2507 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2508 -status
=> $status, -expires
=> $expires);
2509 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2511 <?xml version="1.0" encoding="utf-8"?>
2512 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2513 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2514 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2515 <!-- git core binaries version $git_version -->
2517 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2518 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2519 <meta name="robots" content="index, nofollow"/>
2520 <title>$title</title>
2522 # print out each stylesheet that exist
2523 if (defined $stylesheet) {
2524 #provides backwards capability for those people who define style sheet in a config file
2525 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2527 foreach my $stylesheet (@stylesheets) {
2528 next unless $stylesheet;
2529 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2532 if (defined $project) {
2533 my %href_params = get_feed_info
();
2534 if (!exists $href_params{'-title'}) {
2535 $href_params{'-title'} = 'log';
2538 foreach my $format qw(RSS Atom) {
2539 my $type = lc($format);
2541 '-rel' => 'alternate',
2542 '-title' => "$project - $href_params{'-title'} - $format feed",
2543 '-type' => "application/$type+xml"
2546 $href_params{'action'} = $type;
2547 $link_attr{'-href'} = href
(%href_params);
2549 "rel=\"$link_attr{'-rel'}\" ".
2550 "title=\"$link_attr{'-title'}\" ".
2551 "href=\"$link_attr{'-href'}\" ".
2552 "type=\"$link_attr{'-type'}\" ".
2555 $href_params{'extra_options'} = '--no-merges';
2556 $link_attr{'-href'} = href
(%href_params);
2557 $link_attr{'-title'} .= ' (no merges)';
2559 "rel=\"$link_attr{'-rel'}\" ".
2560 "title=\"$link_attr{'-title'}\" ".
2561 "href=\"$link_attr{'-href'}\" ".
2562 "type=\"$link_attr{'-type'}\" ".
2567 printf('<link rel="alternate" title="%s projects list" '.
2568 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2569 $site_name, href
(project
=>undef, action
=>"project_index"));
2570 printf('<link rel="alternate" title="%s projects feeds" '.
2571 'href="%s" type="text/x-opml" />'."\n",
2572 $site_name, href
(project
=>undef, action
=>"opml"));
2574 if (defined $favicon) {
2575 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2581 if (-f
$site_header) {
2582 open (my $fd, $site_header);
2587 print "<div class=\"page_header\">\n" .
2588 $cgi->a({-href
=> esc_url
($logo_url),
2589 -title
=> $logo_label},
2590 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2591 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2592 if (defined $project) {
2593 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2594 if (defined $action) {
2601 my ($have_search) = gitweb_check_feature
('search');
2602 if (defined $project && $have_search) {
2603 if (!defined $searchtext) {
2607 if (defined $hash_base) {
2608 $search_hash = $hash_base;
2609 } elsif (defined $hash) {
2610 $search_hash = $hash;
2612 $search_hash = "HEAD";
2614 my $action = $my_uri;
2615 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2616 if ($use_pathinfo) {
2617 $action .= "/".esc_url
($project);
2619 print $cgi->startform(-method
=> "get", -action
=> $action) .
2620 "<div class=\"search\">\n" .
2622 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2623 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2624 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2625 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2626 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2627 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2629 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2630 "<span title=\"Extended regular expression\">" .
2631 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2632 -checked
=> $search_use_regexp) .
2635 $cgi->end_form() . "\n";
2639 sub git_footer_html
{
2640 my $feed_class = 'rss_logo';
2642 print "<div class=\"page_footer\">\n";
2643 if (defined $project) {
2644 my $descr = git_get_project_description
($project);
2645 if (defined $descr) {
2646 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2649 my %href_params = get_feed_info
();
2650 if (!%href_params) {
2651 $feed_class .= ' generic';
2653 $href_params{'-title'} ||= 'log';
2655 foreach my $format qw(RSS Atom) {
2656 $href_params{'action'} = lc($format);
2657 print $cgi->a({-href
=> href
(%href_params),
2658 -title
=> "$href_params{'-title'} $format feed",
2659 -class => $feed_class}, $format)."\n";
2663 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2664 -class => $feed_class}, "OPML") . " ";
2665 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2666 -class => $feed_class}, "TXT") . "\n";
2668 print "</div>\n"; # class="page_footer"
2670 if (-f
$site_footer) {
2671 open (my $fd, $site_footer);
2681 my $status = shift || "403 Forbidden";
2682 my $error = shift || "Malformed query, file missing or permission denied";
2684 git_header_html
($status);
2686 <div class="page_body">
2696 ## ----------------------------------------------------------------------
2697 ## functions printing or outputting HTML: navigation
2699 sub git_print_page_nav
{
2700 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2701 $extra = '' if !defined $extra; # pager or formats
2703 my @navs = qw(summary shortlog log commit commitdiff tree);
2705 @navs = grep { $_ ne $suppress } @navs;
2708 my %arg = map { $_ => {action
=>$_} } @navs;
2709 if (defined $head) {
2710 for (qw(commit commitdiff)) {
2711 $arg{$_}{'hash'} = $head;
2713 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2714 for (qw(shortlog log)) {
2715 $arg{$_}{'hash'} = $head;
2719 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2720 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2722 print "<div class=\"page_nav\">\n" .
2724 map { $_ eq $current ?
2725 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2727 print "<br/>\n$extra<br/>\n" .
2731 sub format_paging_nav
{
2732 my ($action, $hash, $head, $page, $has_next_link) = @_;
2736 if ($hash ne $head || $page) {
2737 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2739 $paging_nav .= "HEAD";
2743 $paging_nav .= " ⋅ " .
2744 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2745 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2747 $paging_nav .= " ⋅ prev";
2750 if ($has_next_link) {
2751 $paging_nav .= " ⋅ " .
2752 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2753 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2755 $paging_nav .= " ⋅ next";
2761 ## ......................................................................
2762 ## functions printing or outputting HTML: div
2764 sub git_print_header_div
{
2765 my ($action, $title, $hash, $hash_base) = @_;
2768 $args{'action'} = $action;
2769 $args{'hash'} = $hash if $hash;
2770 $args{'hash_base'} = $hash_base if $hash_base;
2772 print "<div class=\"header\">\n" .
2773 $cgi->a({-href
=> href
(%args), -class => "title"},
2774 $title ?
$title : $action) .
2778 #sub git_print_authorship (\%) {
2779 sub git_print_authorship
{
2782 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2783 print "<div class=\"author_date\">" .
2784 esc_html
($co->{'author_name'}) .
2786 if ($ad{'hour_local'} < 6) {
2787 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2788 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2790 printf(" (%02d:%02d %s)",
2791 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2796 sub git_print_page_path
{
2802 print "<div class=\"page_path\">";
2803 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2804 -title
=> 'tree root'}, to_utf8
("[$project]"));
2806 if (defined $name) {
2807 my @dirname = split '/', $name;
2808 my $basename = pop @dirname;
2811 foreach my $dir (@dirname) {
2812 $fullname .= ($fullname ?
'/' : '') . $dir;
2813 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2815 -title
=> $fullname}, esc_path
($dir));
2818 if (defined $type && $type eq 'blob') {
2819 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2821 -title
=> $name}, esc_path
($basename));
2822 } elsif (defined $type && $type eq 'tree') {
2823 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2825 -title
=> $name}, esc_path
($basename));
2828 print esc_path
($basename);
2831 print "<br/></div>\n";
2834 # sub git_print_log (\@;%) {
2835 sub git_print_log
($;%) {
2839 if ($opts{'-remove_title'}) {
2840 # remove title, i.e. first line of log
2843 # remove leading empty lines
2844 while (defined $log->[0] && $log->[0] eq "") {
2851 foreach my $line (@
$log) {
2852 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2855 if (! $opts{'-remove_signoff'}) {
2856 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2859 # remove signoff lines
2866 # print only one empty line
2867 # do not print empty line after signoff
2869 next if ($empty || $signoff);
2875 print format_log_line_html
($line) . "<br/>\n";
2878 if ($opts{'-final_empty_line'}) {
2879 # end with single empty line
2880 print "<br/>\n" unless $empty;
2884 # return link target (what link points to)
2885 sub git_get_link_target
{
2890 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2894 $link_target = <$fd>;
2899 return $link_target;
2902 # given link target, and the directory (basedir) the link is in,
2903 # return target of link relative to top directory (top tree);
2904 # return undef if it is not possible (including absolute links).
2905 sub normalize_link_target
{
2906 my ($link_target, $basedir, $hash_base) = @_;
2908 # we can normalize symlink target only if $hash_base is provided
2909 return unless $hash_base;
2911 # absolute symlinks (beginning with '/') cannot be normalized
2912 return if (substr($link_target, 0, 1) eq '/');
2914 # normalize link target to path from top (root) tree (dir)
2917 $path = $basedir . '/' . $link_target;
2919 # we are in top (root) tree (dir)
2920 $path = $link_target;
2923 # remove //, /./, and /../
2925 foreach my $part (split('/', $path)) {
2926 # discard '.' and ''
2927 next if (!$part || $part eq '.');
2929 if ($part eq '..') {
2933 # link leads outside repository (outside top dir)
2937 push @path_parts, $part;
2940 $path = join('/', @path_parts);
2945 # print tree entry (row of git_tree), but without encompassing <tr> element
2946 sub git_print_tree_entry
{
2947 my ($t, $basedir, $hash_base, $have_blame) = @_;
2950 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2952 # The format of a table row is: mode list link. Where mode is
2953 # the mode of the entry, list is the name of the entry, an href,
2954 # and link is the action links of the entry.
2956 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2957 if ($t->{'type'} eq "blob") {
2958 print "<td class=\"list\">" .
2959 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2960 file_name
=>"$basedir$t->{'name'}", %base_key),
2961 -class => "list"}, esc_path
($t->{'name'}));
2962 if (S_ISLNK
(oct $t->{'mode'})) {
2963 my $link_target = git_get_link_target
($t->{'hash'});
2965 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2966 if (defined $norm_target) {
2968 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2969 file_name
=>$norm_target),
2970 -title
=> $norm_target}, esc_path
($link_target));
2972 print " -> " . esc_path
($link_target);
2977 print "<td class=\"link\">";
2978 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2979 file_name
=>"$basedir$t->{'name'}", %base_key)},
2983 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2984 file_name
=>"$basedir$t->{'name'}", %base_key)},
2987 if (defined $hash_base) {
2989 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2990 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2994 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2995 file_name
=>"$basedir$t->{'name'}")},
2999 } elsif ($t->{'type'} eq "tree") {
3000 print "<td class=\"list\">";
3001 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3002 file_name
=>"$basedir$t->{'name'}", %base_key)},
3003 esc_path
($t->{'name'}));
3005 print "<td class=\"link\">";
3006 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3007 file_name
=>"$basedir$t->{'name'}", %base_key)},
3009 if (defined $hash_base) {
3011 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3012 file_name
=>"$basedir$t->{'name'}")},
3017 # unknown object: we can only present history for it
3018 # (this includes 'commit' object, i.e. submodule support)
3019 print "<td class=\"list\">" .
3020 esc_path
($t->{'name'}) .
3022 print "<td class=\"link\">";
3023 if (defined $hash_base) {
3024 print $cgi->a({-href
=> href
(action
=>"history",
3025 hash_base
=>$hash_base,
3026 file_name
=>"$basedir$t->{'name'}")},
3033 ## ......................................................................
3034 ## functions printing large fragments of HTML
3036 # get pre-image filenames for merge (combined) diff
3037 sub fill_from_file_info
{
3038 my ($diff, @parents) = @_;
3040 $diff->{'from_file'} = [ ];
3041 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3042 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3043 if ($diff->{'status'}[$i] eq 'R' ||
3044 $diff->{'status'}[$i] eq 'C') {
3045 $diff->{'from_file'}[$i] =
3046 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3053 # is current raw difftree line of file deletion
3055 my $diffinfo = shift;
3057 return $diffinfo->{'to_id'} eq ('0' x
40);
3060 # does patch correspond to [previous] difftree raw line
3061 # $diffinfo - hashref of parsed raw diff format
3062 # $patchinfo - hashref of parsed patch diff format
3063 # (the same keys as in $diffinfo)
3064 sub is_patch_split
{
3065 my ($diffinfo, $patchinfo) = @_;
3067 return defined $diffinfo && defined $patchinfo
3068 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3072 sub git_difftree_body
{
3073 my ($difftree, $hash, @parents) = @_;
3074 my ($parent) = $parents[0];
3075 my ($have_blame) = gitweb_check_feature
('blame');
3076 print "<div class=\"list_head\">\n";
3077 if ($#{$difftree} > 10) {
3078 print(($#{$difftree} + 1) . " files changed:\n");
3082 print "<table class=\"" .
3083 (@parents > 1 ?
"combined " : "") .
3086 # header only for combined diff in 'commitdiff' view
3087 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3090 print "<thead><tr>\n" .
3091 "<th></th><th></th>\n"; # filename, patchN link
3092 for (my $i = 0; $i < @parents; $i++) {
3093 my $par = $parents[$i];
3095 $cgi->a({-href
=> href
(action
=>"commitdiff",
3096 hash
=>$hash, hash_parent
=>$par),
3097 -title
=> 'commitdiff to parent number ' .
3098 ($i+1) . ': ' . substr($par,0,7)},
3102 print "</tr></thead>\n<tbody>\n";
3107 foreach my $line (@
{$difftree}) {
3108 my $diff = parsed_difftree_line
($line);
3111 print "<tr class=\"dark\">\n";
3113 print "<tr class=\"light\">\n";
3117 if (exists $diff->{'nparents'}) { # combined diff
3119 fill_from_file_info
($diff, @parents)
3120 unless exists $diff->{'from_file'};
3122 if (!is_deleted
($diff)) {
3123 # file exists in the result (child) commit
3125 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3126 file_name
=>$diff->{'to_file'},
3128 -class => "list"}, esc_path
($diff->{'to_file'})) .
3132 esc_path
($diff->{'to_file'}) .
3136 if ($action eq 'commitdiff') {
3139 print "<td class=\"link\">" .
3140 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3145 my $has_history = 0;
3146 my $not_deleted = 0;
3147 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3148 my $hash_parent = $parents[$i];
3149 my $from_hash = $diff->{'from_id'}[$i];
3150 my $from_path = $diff->{'from_file'}[$i];
3151 my $status = $diff->{'status'}[$i];
3153 $has_history ||= ($status ne 'A');
3154 $not_deleted ||= ($status ne 'D');
3156 if ($status eq 'A') {
3157 print "<td class=\"link\" align=\"right\"> | </td>\n";
3158 } elsif ($status eq 'D') {
3159 print "<td class=\"link\">" .
3160 $cgi->a({-href
=> href
(action
=>"blob",
3163 file_name
=>$from_path)},
3167 if ($diff->{'to_id'} eq $from_hash) {
3168 print "<td class=\"link nochange\">";
3170 print "<td class=\"link\">";
3172 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3173 hash
=>$diff->{'to_id'},
3174 hash_parent
=>$from_hash,
3176 hash_parent_base
=>$hash_parent,
3177 file_name
=>$diff->{'to_file'},
3178 file_parent
=>$from_path)},
3184 print "<td class=\"link\">";
3186 print $cgi->a({-href
=> href
(action
=>"blob",
3187 hash
=>$diff->{'to_id'},
3188 file_name
=>$diff->{'to_file'},
3191 print " | " if ($has_history);
3194 print $cgi->a({-href
=> href
(action
=>"history",
3195 file_name
=>$diff->{'to_file'},
3202 next; # instead of 'else' clause, to avoid extra indent
3204 # else ordinary diff
3206 my ($to_mode_oct, $to_mode_str, $to_file_type);
3207 my ($from_mode_oct, $from_mode_str, $from_file_type);
3208 if ($diff->{'to_mode'} ne ('0' x
6)) {
3209 $to_mode_oct = oct $diff->{'to_mode'};
3210 if (S_ISREG
($to_mode_oct)) { # only for regular file
3211 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3213 $to_file_type = file_type
($diff->{'to_mode'});
3215 if ($diff->{'from_mode'} ne ('0' x
6)) {
3216 $from_mode_oct = oct $diff->{'from_mode'};
3217 if (S_ISREG
($to_mode_oct)) { # only for regular file
3218 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3220 $from_file_type = file_type
($diff->{'from_mode'});
3223 if ($diff->{'status'} eq "A") { # created
3224 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3225 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3226 $mode_chng .= "]</span>";
3228 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3229 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3230 -class => "list"}, esc_path
($diff->{'file'}));
3232 print "<td>$mode_chng</td>\n";
3233 print "<td class=\"link\">";
3234 if ($action eq 'commitdiff') {
3237 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3240 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3241 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3245 } elsif ($diff->{'status'} eq "D") { # deleted
3246 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3248 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3249 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3250 -class => "list"}, esc_path
($diff->{'file'}));
3252 print "<td>$mode_chng</td>\n";
3253 print "<td class=\"link\">";
3254 if ($action eq 'commitdiff') {
3257 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3260 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3261 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3264 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3265 file_name
=>$diff->{'file'})},
3268 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3269 file_name
=>$diff->{'file'})},
3273 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3274 my $mode_chnge = "";
3275 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3276 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3277 if ($from_file_type ne $to_file_type) {
3278 $mode_chnge .= " from $from_file_type to $to_file_type";
3280 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3281 if ($from_mode_str && $to_mode_str) {
3282 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3283 } elsif ($to_mode_str) {
3284 $mode_chnge .= " mode: $to_mode_str";
3287 $mode_chnge .= "]</span>\n";
3290 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3291 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3292 -class => "list"}, esc_path
($diff->{'file'}));
3294 print "<td>$mode_chnge</td>\n";
3295 print "<td class=\"link\">";
3296 if ($action eq 'commitdiff') {
3299 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3301 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3302 # "commit" view and modified file (not onlu mode changed)
3303 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3304 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3305 hash_base
=>$hash, hash_parent_base
=>$parent,
3306 file_name
=>$diff->{'file'})},
3310 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3311 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3314 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3315 file_name
=>$diff->{'file'})},
3318 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3319 file_name
=>$diff->{'file'})},
3323 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3324 my %status_name = ('R' => 'moved', 'C' => 'copied');
3325 my $nstatus = $status_name{$diff->{'status'}};
3327 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3328 # mode also for directories, so we cannot use $to_mode_str
3329 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3332 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3333 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3334 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3335 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3336 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3337 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3338 -class => "list"}, esc_path
($diff->{'from_file'})) .
3339 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3340 "<td class=\"link\">";
3341 if ($action eq 'commitdiff') {
3344 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3346 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3347 # "commit" view and modified file (not only pure rename or copy)
3348 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3349 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3350 hash_base
=>$hash, hash_parent_base
=>$parent,
3351 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3355 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3356 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3359 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3360 file_name
=>$diff->{'to_file'})},
3363 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3364 file_name
=>$diff->{'to_file'})},
3368 } # we should not encounter Unmerged (U) or Unknown (X) status
3371 print "</tbody>" if $has_header;
3375 sub git_patchset_body
{
3376 my ($fd, $difftree, $hash, @hash_parents) = @_;
3377 my ($hash_parent) = $hash_parents[0];
3379 my $is_combined = (@hash_parents > 1);
3381 my $patch_number = 0;
3387 print "<div class=\"patchset\">\n";
3389 # skip to first patch
3390 while ($patch_line = <$fd>) {
3393 last if ($patch_line =~ m/^diff /);
3397 while ($patch_line) {
3399 # parse "git diff" header line
3400 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3401 # $1 is from_name, which we do not use
3402 $to_name = unquote
($2);
3403 $to_name =~ s!^b/!!;
3404 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3405 # $1 is 'cc' or 'combined', which we do not use
3406 $to_name = unquote
($2);
3411 # check if current patch belong to current raw line
3412 # and parse raw git-diff line if needed
3413 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3414 # this is continuation of a split patch
3415 print "<div class=\"patch cont\">\n";
3417 # advance raw git-diff output if needed
3418 $patch_idx++ if defined $diffinfo;
3420 # read and prepare patch information
3421 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3423 # compact combined diff output can have some patches skipped
3424 # find which patch (using pathname of result) we are at now;
3426 while ($to_name ne $diffinfo->{'to_file'}) {
3427 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3428 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3429 "</div>\n"; # class="patch"
3434 last if $patch_idx > $#$difftree;
3435 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3439 # modifies %from, %to hashes
3440 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3442 # this is first patch for raw difftree line with $patch_idx index
3443 # we index @$difftree array from 0, but number patches from 1
3444 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3448 #assert($patch_line =~ m/^diff /) if DEBUG;
3449 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3451 # print "git diff" header
3452 print format_git_diff_header_line
($patch_line, $diffinfo,
3455 # print extended diff header
3456 print "<div class=\"diff extended_header\">\n";
3458 while ($patch_line = <$fd>) {
3461 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3463 print format_extended_diff_header_line
($patch_line, $diffinfo,
3466 print "</div>\n"; # class="diff extended_header"
3468 # from-file/to-file diff header
3469 if (! $patch_line) {
3470 print "</div>\n"; # class="patch"
3473 next PATCH
if ($patch_line =~ m/^diff /);
3474 #assert($patch_line =~ m/^---/) if DEBUG;
3476 my $last_patch_line = $patch_line;
3477 $patch_line = <$fd>;
3479 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3481 print format_diff_from_to_header
($last_patch_line, $patch_line,
3482 $diffinfo, \
%from, \
%to,
3487 while ($patch_line = <$fd>) {
3490 next PATCH
if ($patch_line =~ m/^diff /);
3492 print format_diff_line
($patch_line, \
%from, \
%to);
3496 print "</div>\n"; # class="patch"
3499 # for compact combined (--cc) format, with chunk and patch simpliciaction
3500 # patchset might be empty, but there might be unprocessed raw lines
3501 for (++$patch_idx if $patch_number > 0;
3502 $patch_idx < @
$difftree;
3504 # read and prepare patch information
3505 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3507 # generate anchor for "patch" links in difftree / whatchanged part
3508 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3509 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3510 "</div>\n"; # class="patch"
3515 if ($patch_number == 0) {
3516 if (@hash_parents > 1) {
3517 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3519 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3523 print "</div>\n"; # class="patchset"
3526 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3528 sub git_project_list_body
{
3529 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3531 my ($check_forks) = gitweb_check_feature
('forks');
3534 foreach my $pr (@
$projlist) {
3535 my (@aa) = git_get_last_activity
($pr->{'path'});
3539 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3540 if (!defined $pr->{'descr'}) {
3541 my $descr = git_get_project_description
($pr->{'path'}) || "";
3542 $pr->{'descr_long'} = to_utf8
($descr);
3543 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3545 if (!defined $pr->{'owner'}) {
3546 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3549 my $pname = $pr->{'path'};
3550 if (($pname =~ s/\.git$//) &&
3551 ($pname !~ /\/$/) &&
3552 (-d
"$projectroot/$pname")) {
3553 $pr->{'forks'} = "-d $projectroot/$pname";
3559 push @projects, $pr;
3562 $order ||= $default_projects_order;
3563 $from = 0 unless defined $from;
3564 $to = $#projects if (!defined $to || $#projects < $to);
3566 print "<table class=\"project_list\">\n";
3567 unless ($no_header) {
3570 print "<th></th>\n";
3572 if ($order eq "project") {
3573 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3574 print "<th>Project</th>\n";
3577 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3578 -class => "header"}, "Project") .
3581 if ($order eq "descr") {
3582 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3583 print "<th>Description</th>\n";
3586 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3587 -class => "header"}, "Description") .
3590 if ($order eq "owner") {
3591 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3592 print "<th>Owner</th>\n";
3595 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3596 -class => "header"}, "Owner") .
3599 if ($order eq "age") {
3600 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3601 print "<th>Last Change</th>\n";
3604 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3605 -class => "header"}, "Last Change") .
3608 print "<th></th>\n" .
3612 for (my $i = $from; $i <= $to; $i++) {
3613 my $pr = $projects[$i];
3615 print "<tr class=\"dark\">\n";
3617 print "<tr class=\"light\">\n";
3622 if ($pr->{'forks'}) {
3623 print "<!-- $pr->{'forks'} -->\n";
3624 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3628 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3629 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3630 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3631 -class => "list", -title
=> $pr->{'descr_long'}},
3632 esc_html
($pr->{'descr'})) . "</td>\n" .
3633 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3634 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3635 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3636 "<td class=\"link\">" .
3637 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3638 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3639 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3640 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3641 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3645 if (defined $extra) {
3648 print "<td></td>\n";
3650 print "<td colspan=\"5\">$extra</td>\n" .
3656 sub git_shortlog_body
{
3657 # uses global variable $project
3658 my ($commitlist, $from, $to, $refs, $extra) = @_;
3660 $from = 0 unless defined $from;
3661 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3663 print "<table class=\"shortlog\">\n";
3665 for (my $i = $from; $i <= $to; $i++) {
3666 my %co = %{$commitlist->[$i]};
3667 my $commit = $co{'id'};
3668 my $ref = format_ref_marker
($refs, $commit);
3670 print "<tr class=\"dark\">\n";
3672 print "<tr class=\"light\">\n";
3675 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3676 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3677 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3678 "<td><i>" . $author . "</i></td>\n" .
3680 print format_subject_html
($co{'title'}, $co{'title_short'},
3681 href
(action
=>"commit", hash
=>$commit), $ref);
3683 "<td class=\"link\">" .
3684 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3685 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3686 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3687 my $snapshot_links = format_snapshot_links
($commit);
3688 if (defined $snapshot_links) {
3689 print " | " . $snapshot_links;
3694 if (defined $extra) {
3696 "<td colspan=\"4\">$extra</td>\n" .
3702 sub git_history_body
{
3703 # Warning: assumes constant type (blob or tree) during history
3704 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3706 $from = 0 unless defined $from;
3707 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3709 print "<table class=\"history\">\n";
3711 for (my $i = $from; $i <= $to; $i++) {
3712 my %co = %{$commitlist->[$i]};
3716 my $commit = $co{'id'};
3718 my $ref = format_ref_marker
($refs, $commit);
3721 print "<tr class=\"dark\">\n";
3723 print "<tr class=\"light\">\n";
3726 # shortlog uses chop_str($co{'author_name'}, 10)
3727 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3728 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3729 "<td><i>" . $author . "</i></td>\n" .
3731 # originally git_history used chop_str($co{'title'}, 50)
3732 print format_subject_html
($co{'title'}, $co{'title_short'},
3733 href
(action
=>"commit", hash
=>$commit), $ref);
3735 "<td class=\"link\">" .
3736 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3737 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3739 if ($ftype eq 'blob') {
3740 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3741 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3742 if (defined $blob_current && defined $blob_parent &&
3743 $blob_current ne $blob_parent) {
3745 $cgi->a({-href
=> href
(action
=>"blobdiff",
3746 hash
=>$blob_current, hash_parent
=>$blob_parent,
3747 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3748 file_name
=>$file_name)},
3755 if (defined $extra) {
3757 "<td colspan=\"4\">$extra</td>\n" .
3764 # uses global variable $project
3765 my ($taglist, $from, $to, $extra) = @_;
3766 $from = 0 unless defined $from;
3767 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3769 print "<table class=\"tags\">\n";
3771 for (my $i = $from; $i <= $to; $i++) {
3772 my $entry = $taglist->[$i];
3774 my $comment = $tag{'subject'};
3776 if (defined $comment) {
3777 $comment_short = chop_str
($comment, 30, 5);
3780 print "<tr class=\"dark\">\n";
3782 print "<tr class=\"light\">\n";
3785 if (defined $tag{'age'}) {
3786 print "<td><i>$tag{'age'}</i></td>\n";
3788 print "<td></td>\n";
3791 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3792 -class => "list name"}, esc_html
($tag{'name'})) .
3795 if (defined $comment) {
3796 print format_subject_html
($comment, $comment_short,
3797 href
(action
=>"tag", hash
=>$tag{'id'}));
3800 "<td class=\"selflink\">";
3801 if ($tag{'type'} eq "tag") {
3802 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3807 "<td class=\"link\">" . " | " .
3808 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3809 if ($tag{'reftype'} eq "commit") {
3810 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3811 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3812 } elsif ($tag{'reftype'} eq "blob") {
3813 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3818 if (defined $extra) {
3820 "<td colspan=\"5\">$extra</td>\n" .
3826 sub git_heads_body
{
3827 # uses global variable $project
3828 my ($headlist, $head, $from, $to, $extra) = @_;
3829 $from = 0 unless defined $from;
3830 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3832 print "<table class=\"heads\">\n";
3834 for (my $i = $from; $i <= $to; $i++) {
3835 my $entry = $headlist->[$i];
3837 my $curr = $ref{'id'} eq $head;
3839 print "<tr class=\"dark\">\n";
3841 print "<tr class=\"light\">\n";
3844 print "<td><i>$ref{'age'}</i></td>\n" .
3845 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3846 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3847 -class => "list name"},esc_html
($ref{'name'})) .
3849 "<td class=\"link\">" .
3850 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3851 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3852 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3856 if (defined $extra) {
3858 "<td colspan=\"3\">$extra</td>\n" .
3864 sub git_search_grep_body
{
3865 my ($commitlist, $from, $to, $extra) = @_;
3866 $from = 0 unless defined $from;
3867 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3869 print "<table class=\"commit_search\">\n";
3871 for (my $i = $from; $i <= $to; $i++) {
3872 my %co = %{$commitlist->[$i]};
3876 my $commit = $co{'id'};
3878 print "<tr class=\"dark\">\n";
3880 print "<tr class=\"light\">\n";
3883 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3884 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3885 "<td><i>" . $author . "</i></td>\n" .
3887 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3888 -class => "list subject"},
3889 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3890 my $comment = $co{'comment'};
3891 foreach my $line (@
$comment) {
3892 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3893 my ($lead, $match, $trail) = ($1, $2, $3);
3894 $match = chop_str
($match, 70, 5, 'center');
3895 my $contextlen = int((80 - length($match))/2);
3896 $contextlen = 30 if ($contextlen > 30);
3897 $lead = chop_str
($lead, $contextlen, 10, 'left');
3898 $trail = chop_str
($trail, $contextlen, 10, 'right');
3900 $lead = esc_html
($lead);
3901 $match = esc_html
($match);
3902 $trail = esc_html
($trail);
3904 print "$lead<span class=\"match\">$match</span>$trail<br />";
3908 "<td class=\"link\">" .
3909 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3911 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3913 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3917 if (defined $extra) {
3919 "<td colspan=\"3\">$extra</td>\n" .
3925 ## ======================================================================
3926 ## ======================================================================
3929 sub git_project_list
{
3930 my $order = $cgi->param('o');
3931 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3932 die_error
(undef, "Unknown order parameter");
3935 my @list = git_get_projects_list
();
3937 die_error
(undef, "No projects found");
3941 if (-f
$home_text) {
3942 print "<div class=\"index_include\">\n";
3943 open (my $fd, $home_text);
3948 git_project_list_body
(\
@list, $order);
3953 my $order = $cgi->param('o');
3954 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3955 die_error
(undef, "Unknown order parameter");
3958 my @list = git_get_projects_list
($project);
3960 die_error
(undef, "No forks found");
3964 git_print_page_nav
('','');
3965 git_print_header_div
('summary', "$project forks");
3966 git_project_list_body
(\
@list, $order);
3970 sub git_project_index
{
3971 my @projects = git_get_projects_list
($project);
3974 -type
=> 'text/plain',
3975 -charset
=> 'utf-8',
3976 -content_disposition
=> 'inline; filename="index.aux"');
3978 foreach my $pr (@projects) {
3979 if (!exists $pr->{'owner'}) {
3980 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3983 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3984 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3985 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3986 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3990 print "$path $owner\n";
3995 my $descr = git_get_project_description
($project) || "none";
3996 my %co = parse_commit
("HEAD");
3997 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3998 my $head = $co{'id'};
4000 my $owner = git_get_project_owner
($project);
4002 my $refs = git_get_references
();
4003 # These get_*_list functions return one more to allow us to see if
4004 # there are more ...
4005 my @taglist = git_get_tags_list
(16);
4006 my @headlist = git_get_heads_list
(16);
4008 my ($check_forks) = gitweb_check_feature
('forks');
4011 @forklist = git_get_projects_list
($project);
4015 git_print_page_nav
('summary','', $head);
4017 print "<div class=\"title\"> </div>\n";
4018 print "<table class=\"projects_list\">\n" .
4019 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4020 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4021 if (defined $cd{'rfc2822'}) {
4022 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4025 # use per project git URL list in $projectroot/$project/cloneurl
4026 # or make project git URL from git base URL and project name
4027 my $url_tag = "URL";
4028 my @url_list = git_get_project_url_list
($project);
4029 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4030 foreach my $git_url (@url_list) {
4031 next unless $git_url;
4032 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4037 if (-s
"$projectroot/$project/README.html") {
4038 if (open my $fd, "$projectroot/$project/README.html") {
4039 print "<div class=\"title\">readme</div>\n" .
4040 "<div class=\"readme\">\n";
4041 print $_ while (<$fd>);
4042 print "\n</div>\n"; # class="readme"
4047 # we need to request one more than 16 (0..15) to check if
4049 my @commitlist = $head ? parse_commits
($head, 17) : ();
4051 git_print_header_div
('shortlog');
4052 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4053 $#commitlist <= 15 ?
undef :
4054 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4058 git_print_header_div
('tags');
4059 git_tags_body
(\
@taglist, 0, 15,
4060 $#taglist <= 15 ?
undef :
4061 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4065 git_print_header_div
('heads');
4066 git_heads_body
(\
@headlist, $head, 0, 15,
4067 $#headlist <= 15 ?
undef :
4068 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4072 git_print_header_div
('forks');
4073 git_project_list_body
(\
@forklist, undef, 0, 15,
4074 $#forklist <= 15 ?
undef :
4075 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4083 my $head = git_get_head_hash
($project);
4085 git_print_page_nav
('','', $head,undef,$head);
4086 my %tag = parse_tag
($hash);
4089 die_error
(undef, "Unknown tag object");
4092 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4093 print "<div class=\"title_text\">\n" .
4094 "<table class=\"object_header\">\n" .
4096 "<td>object</td>\n" .
4097 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4098 $tag{'object'}) . "</td>\n" .
4099 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4100 $tag{'type'}) . "</td>\n" .
4102 if (defined($tag{'author'})) {
4103 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4104 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4105 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4106 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4109 print "</table>\n\n" .
4111 print "<div class=\"page_body\">";
4112 my $comment = $tag{'comment'};
4113 foreach my $line (@
$comment) {
4115 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4125 my ($have_blame) = gitweb_check_feature
('blame');
4127 die_error
('403 Permission denied', "Permission denied");
4129 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4130 $hash_base ||= git_get_head_hash
($project);
4131 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4132 my %co = parse_commit
($hash_base)
4133 or die_error
(undef, "Reading commit failed");
4134 if (!defined $hash) {
4135 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4136 or die_error
(undef, "Error looking up file");
4138 $ftype = git_get_type
($hash);
4139 if ($ftype !~ "blob") {
4140 die_error
('400 Bad Request', "Object is not a blob");
4142 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4143 $file_name, $hash_base)
4144 or die_error
(undef, "Open git-blame failed");
4147 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4150 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4153 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4155 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4156 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4157 git_print_page_path
($file_name, $ftype, $hash_base);
4158 my @rev_color = (qw(light2 dark2));
4159 my $num_colors = scalar(@rev_color);
4160 my $current_color = 0;
4163 <div class="page_body">
4164 <table class="blame">
4165 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4170 last unless defined $_;
4171 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4172 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4173 if (!exists $metainfo{$full_rev}) {
4174 $metainfo{$full_rev} = {};
4176 my $meta = $metainfo{$full_rev};
4179 if (/^(\S+) (.*)$/) {
4185 my $rev = substr($full_rev, 0, 8);
4186 my $author = $meta->{'author'};
4187 my %date = parse_date
($meta->{'author-time'},
4188 $meta->{'author-tz'});
4189 my $date = $date{'iso-tz'};
4191 $current_color = ++$current_color % $num_colors;
4193 print "<tr class=\"$rev_color[$current_color]\">\n";
4195 print "<td class=\"sha1\"";
4196 print " title=\"". esc_html
($author) . ", $date\"";
4197 print " rowspan=\"$group_size\"" if ($group_size > 1);
4199 print $cgi->a({-href
=> href
(action
=>"commit",
4201 file_name
=>$file_name)},
4205 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4206 or die_error
(undef, "Open git-rev-parse failed");
4207 my $parent_commit = <$dd>;
4209 chomp($parent_commit);
4210 my $blamed = href
(action
=> 'blame',
4211 file_name
=> $meta->{'filename'},
4212 hash_base
=> $parent_commit);
4213 print "<td class=\"linenr\">";
4214 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4216 -class => "linenr" },
4219 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4225 or print "Reading blob failed\n";
4232 my ($have_blame) = gitweb_check_feature
('blame');
4234 die_error
('403 Permission denied', "Permission denied");
4236 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4237 $hash_base ||= git_get_head_hash
($project);
4238 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4239 my %co = parse_commit
($hash_base)
4240 or die_error
(undef, "Reading commit failed");
4241 if (!defined $hash) {
4242 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4243 or die_error
(undef, "Error lookup file");
4245 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4246 or die_error
(undef, "Open git-annotate failed");
4249 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4252 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4255 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4257 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4258 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4259 git_print_page_path
($file_name, 'blob', $hash_base);
4260 print "<div class=\"page_body\">\n";
4262 <table class="blame">
4271 my @line_class = (qw(light dark));
4272 my $line_class_len = scalar (@line_class);
4273 my $line_class_num = $#line_class;
4274 while (my $line = <$fd>) {
4286 $line_class_num = ($line_class_num + 1) % $line_class_len;
4288 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4295 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
4298 $short_rev = substr ($long_rev, 0, 8);
4299 $age = time () - $time;
4300 $age_str = age_string
($age);
4301 $age_str =~ s/ / /g;
4302 $age_class = age_class
($age);
4303 $author = esc_html
($author);
4304 $author =~ s/ / /g;
4306 $data = untabify
($data);
4307 $data = esc_html
($data);
4310 <tr class="$line_class[$line_class_num]">
4311 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4312 <td class="$age_class">$age_str</td>
4314 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4315 <td class="pre">$data</td>
4318 } # while (my $line = <$fd>)
4319 print "</table>\n\n";
4321 or print "Reading blob failed.\n";
4327 my $head = git_get_head_hash
($project);
4329 git_print_page_nav
('','', $head,undef,$head);
4330 git_print_header_div
('summary', $project);
4332 my @tagslist = git_get_tags_list
();
4334 git_tags_body
(\
@tagslist);
4340 my $head = git_get_head_hash
($project);
4342 git_print_page_nav
('','', $head,undef,$head);
4343 git_print_header_div
('summary', $project);
4345 my @headslist = git_get_heads_list
();
4347 git_heads_body
(\
@headslist, $head);
4352 sub git_blob_plain
{
4356 if (!defined $hash) {
4357 if (defined $file_name) {
4358 my $base = $hash_base || git_get_head_hash
($project);
4359 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4360 or die_error
(undef, "Error lookup file");
4362 die_error
(undef, "No file name defined");
4364 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4365 # blobs defined by non-textual hash id's can be cached
4369 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4370 or die_error
(undef, "Open git-cat-file blob '$hash' failed");
4372 # content-type (can include charset)
4373 $type = blob_contenttype
($fd, $file_name, $type);
4375 # "save as" filename, even when no $file_name is given
4376 my $save_as = "$hash";
4377 if (defined $file_name) {
4378 $save_as = $file_name;
4379 } elsif ($type =~ m/^text\//) {
4385 -expires
=> $expires,
4386 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4388 binmode STDOUT
, ':raw';
4390 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4398 if (!defined $hash) {
4399 if (defined $file_name) {
4400 my $base = $hash_base || git_get_head_hash
($project);
4401 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4402 or die_error
(undef, "Error lookup file");
4404 die_error
(undef, "No file name defined");
4406 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4407 # blobs defined by non-textual hash id's can be cached
4411 my ($have_blame) = gitweb_check_feature
('blame');
4412 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4413 or die_error
(undef, "Couldn't cat $file_name, $hash");
4414 my $mimetype = blob_mimetype
($fd, $file_name);
4415 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4417 return git_blob_plain
($mimetype);
4419 # we can have blame only for text/* mimetype
4420 $have_blame &&= ($mimetype =~ m!^text/!);
4422 git_header_html
(undef, $expires);
4423 my $formats_nav = '';
4424 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4425 if (defined $file_name) {
4428 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4433 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4436 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4439 $cgi->a({-href
=> href
(action
=>"blob",
4440 hash_base
=>"HEAD", file_name
=>$file_name)},
4444 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4447 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4448 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4450 print "<div class=\"page_nav\">\n" .
4451 "<br/><br/></div>\n" .
4452 "<div class=\"title\">$hash</div>\n";
4454 git_print_page_path
($file_name, "blob", $hash_base);
4455 print "<div class=\"page_body\">\n";
4456 if ($mimetype =~ m!^image/!) {
4457 print qq!<img type
="$mimetype"!;
4459 print qq! alt
="$file_name" title
="$file_name"!;
4462 href(action=>"blob_plain
", hash=>$hash,
4463 hash_base=>$hash_base, file_name=>$file_name) .
4467 while (my $line = <$fd>) {
4470 $line = untabify
($line);
4471 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4472 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4476 or print "Reading blob failed.\n";
4482 if (!defined $hash_base) {
4483 $hash_base = "HEAD";
4485 if (!defined $hash) {
4486 if (defined $file_name) {
4487 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4493 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4494 or die_error
(undef, "Open git-ls-tree failed");
4495 my @entries = map { chomp; $_ } <$fd>;
4496 close $fd or die_error
(undef, "Reading tree failed");
4499 my $refs = git_get_references
();
4500 my $ref = format_ref_marker
($refs, $hash_base);
4503 my ($have_blame) = gitweb_check_feature
('blame');
4504 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4506 if (defined $file_name) {
4508 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4510 $cgi->a({-href
=> href
(action
=>"tree",
4511 hash_base
=>"HEAD", file_name
=>$file_name)},
4514 my $snapshot_links = format_snapshot_links
($hash);
4515 if (defined $snapshot_links) {
4516 # FIXME: Should be available when we have no hash base as well.
4517 push @views_nav, $snapshot_links;
4519 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4520 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4523 print "<div class=\"page_nav\">\n";
4524 print "<br/><br/></div>\n";
4525 print "<div class=\"title\">$hash</div>\n";
4527 if (defined $file_name) {
4528 $basedir = $file_name;
4529 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4533 git_print_page_path
($file_name, 'tree', $hash_base);
4534 print "<div class=\"page_body\">\n";
4535 print "<table class=\"tree\">\n";
4537 # '..' (top directory) link if possible
4538 if (defined $hash_base &&
4539 defined $file_name && $file_name =~ m![^/]+$!) {
4541 print "<tr class=\"dark\">\n";
4543 print "<tr class=\"light\">\n";
4547 my $up = $file_name;
4548 $up =~ s!/?[^/]+$!!;
4549 undef $up unless $up;
4550 # based on git_print_tree_entry
4551 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4552 print '<td class="list">';
4553 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4557 print "<td class=\"link\"></td>\n";
4561 foreach my $line (@entries) {
4562 my %t = parse_ls_tree_line
($line, -z
=> 1);
4565 print "<tr class=\"dark\">\n";
4567 print "<tr class=\"light\">\n";
4571 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4575 print "</table>\n" .
4581 my @supported_fmts = gitweb_check_feature
('snapshot');
4582 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4584 my $format = $cgi->param('sf');
4585 if (!@supported_fmts) {
4586 die_error
('403 Permission denied', "Permission denied");
4588 # default to first supported snapshot format
4589 $format ||= $supported_fmts[0];
4590 if ($format !~ m/^[a-z0-9]+$/) {
4591 die_error
(undef, "Invalid snapshot format parameter");
4592 } elsif (!exists($known_snapshot_formats{$format})) {
4593 die_error
(undef, "Unknown snapshot format");
4594 } elsif (!grep($_ eq $format, @supported_fmts)) {
4595 die_error
(undef, "Unsupported snapshot format");
4598 if (!defined $hash) {
4599 $hash = git_get_head_hash
($project);
4602 my $name = $project;
4603 $name =~ s
,([^/])/*\
.git
$,$1,;
4604 $name = basename
($name);
4605 my $filename = to_utf8
($name);
4606 $name =~ s/\047/\047\\\047\047/g;
4608 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4609 $cmd = quote_command
(
4610 git_cmd
(), 'archive',
4611 "--format=$known_snapshot_formats{$format}{'format'}",
4612 "--prefix=$name/", $hash);
4613 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4614 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4618 -type
=> $known_snapshot_formats{$format}{'type'},
4619 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4620 -status
=> '200 OK');
4622 open my $fd, "-|", $cmd
4623 or die_error
(undef, "Execute git-archive failed");
4624 binmode STDOUT
, ':raw';
4626 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4631 my $head = git_get_head_hash
($project);
4632 if (!defined $hash) {
4635 if (!defined $page) {
4638 my $refs = git_get_references
();
4640 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4642 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4645 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4648 my %co = parse_commit
($hash);
4650 git_print_header_div
('summary', $project);
4651 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4653 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4654 for (my $i = 0; $i <= $to; $i++) {
4655 my %co = %{$commitlist[$i]};
4657 my $commit = $co{'id'};
4658 my $ref = format_ref_marker
($refs, $commit);
4659 my %ad = parse_date
($co{'author_epoch'});
4660 git_print_header_div
('commit',
4661 "<span class=\"age\">$co{'age_string'}</span>" .
4662 esc_html
($co{'title'}) . $ref,
4664 print "<div class=\"title_text\">\n" .
4665 "<div class=\"log_link\">\n" .
4666 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4668 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4670 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4673 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4676 print "<div class=\"log_body\">\n";
4677 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4680 if ($#commitlist >= 100) {
4681 print "<div class=\"page_nav\">\n";
4682 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4683 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4690 $hash ||= $hash_base || "HEAD";
4691 my %co = parse_commit
($hash);
4693 die_error
(undef, "Unknown commit object");
4695 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4696 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4698 my $parent = $co{'parent'};
4699 my $parents = $co{'parents'}; # listref
4701 # we need to prepare $formats_nav before any parameter munging
4703 if (!defined $parent) {
4705 $formats_nav .= '(initial)';
4706 } elsif (@
$parents == 1) {
4707 # single parent commit
4710 $cgi->a({-href
=> href
(action
=>"commit",
4712 esc_html
(substr($parent, 0, 7))) .
4719 $cgi->a({-href
=> href
(action
=>"commit",
4721 esc_html
(substr($_, 0, 7)));
4726 if (!defined $parent) {
4730 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4732 (@
$parents <= 1 ?
$parent : '-c'),
4734 or die_error
(undef, "Open git-diff-tree failed");
4735 @difftree = map { chomp; $_ } <$fd>;
4736 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4738 # non-textual hash id's can be cached
4740 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4743 my $refs = git_get_references
();
4744 my $ref = format_ref_marker
($refs, $co{'id'});
4746 git_header_html
(undef, $expires);
4747 git_print_page_nav
('commit', '',
4748 $hash, $co{'tree'}, $hash,
4751 if (defined $co{'parent'}) {
4752 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4754 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4756 print "<div class=\"title_text\">\n" .
4757 "<table class=\"object_header\">\n";
4758 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4760 "<td></td><td> $ad{'rfc2822'}";
4761 if ($ad{'hour_local'} < 6) {
4762 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4763 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4765 printf(" (%02d:%02d %s)",
4766 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4770 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4771 print "<tr><td></td><td> $cd{'rfc2822'}" .
4772 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4774 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4777 "<td class=\"sha1\">" .
4778 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4779 class => "list"}, $co{'tree'}) .
4781 "<td class=\"link\">" .
4782 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4784 my $snapshot_links = format_snapshot_links
($hash);
4785 if (defined $snapshot_links) {
4786 print " | " . $snapshot_links;
4791 foreach my $par (@
$parents) {
4794 "<td class=\"sha1\">" .
4795 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4796 class => "list"}, $par) .
4798 "<td class=\"link\">" .
4799 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4801 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4808 print "<div class=\"page_body\">\n";
4809 git_print_log
($co{'comment'});
4812 git_difftree_body
(\
@difftree, $hash, @
$parents);
4818 # object is defined by:
4819 # - hash or hash_base alone
4820 # - hash_base and file_name
4823 # - hash or hash_base alone
4824 if ($hash || ($hash_base && !defined $file_name)) {
4825 my $object_id = $hash || $hash_base;
4827 open my $fd, "-|", quote_command
(
4828 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4829 or die_error
('404 Not Found', "Object does not exist");
4833 or die_error
('404 Not Found', "Object does not exist");
4835 # - hash_base and file_name
4836 } elsif ($hash_base && defined $file_name) {
4837 $file_name =~ s
,/+$,,;
4839 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4840 or die_error
('404 Not Found', "Base object does not exist");
4842 # here errors should not hapen
4843 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4844 or die_error
(undef, "Open git-ls-tree failed");
4848 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4849 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4850 die_error
('404 Not Found', "File or directory for given base does not exist");
4855 die_error
('404 Not Found', "Not enough information to find object");
4858 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4859 hash
=>$hash, hash_base
=>$hash_base,
4860 file_name
=>$file_name),
4861 -status
=> '302 Found');
4865 my $format = shift || 'html';
4872 # preparing $fd and %diffinfo for git_patchset_body
4874 if (defined $hash_base && defined $hash_parent_base) {
4875 if (defined $file_name) {
4877 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4878 $hash_parent_base, $hash_base,
4879 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4880 or die_error
(undef, "Open git-diff-tree failed");
4881 @difftree = map { chomp; $_ } <$fd>;
4883 or die_error
(undef, "Reading git-diff-tree failed");
4885 or die_error
('404 Not Found', "Blob diff not found");
4887 } elsif (defined $hash &&
4888 $hash =~ /[0-9a-fA-F]{40}/) {
4889 # try to find filename from $hash
4891 # read filtered raw output
4892 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4893 $hash_parent_base, $hash_base, "--"
4894 or die_error
(undef, "Open git-diff-tree failed");
4896 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4898 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4899 map { chomp; $_ } <$fd>;
4901 or die_error
(undef, "Reading git-diff-tree failed");
4903 or die_error
('404 Not Found', "Blob diff not found");
4906 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4909 if (@difftree > 1) {
4910 die_error
('404 Not Found', "Ambiguous blob diff specification");
4913 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4914 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4915 $file_name ||= $diffinfo{'to_file'};
4917 $hash_parent ||= $diffinfo{'from_id'};
4918 $hash ||= $diffinfo{'to_id'};
4920 # non-textual hash id's can be cached
4921 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4922 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4927 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4928 '-p', ($format eq 'html' ?
"--full-index" : ()),
4929 $hash_parent_base, $hash_base,
4930 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4931 or die_error
(undef, "Open git-diff-tree failed");
4934 # old/legacy style URI
4935 if (!%diffinfo && # if new style URI failed
4936 defined $hash && defined $hash_parent) {
4937 # fake git-diff-tree raw output
4938 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4939 $diffinfo{'from_id'} = $hash_parent;
4940 $diffinfo{'to_id'} = $hash;
4941 if (defined $file_name) {
4942 if (defined $file_parent) {
4943 $diffinfo{'status'} = '2';
4944 $diffinfo{'from_file'} = $file_parent;
4945 $diffinfo{'to_file'} = $file_name;
4946 } else { # assume not renamed
4947 $diffinfo{'status'} = '1';
4948 $diffinfo{'from_file'} = $file_name;
4949 $diffinfo{'to_file'} = $file_name;
4951 } else { # no filename given
4952 $diffinfo{'status'} = '2';
4953 $diffinfo{'from_file'} = $hash_parent;
4954 $diffinfo{'to_file'} = $hash;
4957 # non-textual hash id's can be cached
4958 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4959 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4964 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4965 '-p', ($format eq 'html' ?
"--full-index" : ()),
4966 $hash_parent, $hash, "--"
4967 or die_error
(undef, "Open git-diff failed");
4969 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4974 if ($format eq 'html') {
4976 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4978 git_header_html
(undef, $expires);
4979 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4980 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4981 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4983 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4984 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4986 if (defined $file_name) {
4987 git_print_page_path
($file_name, "blob", $hash_base);
4989 print "<div class=\"page_path\"></div>\n";
4992 } elsif ($format eq 'plain') {
4994 -type
=> 'text/plain',
4995 -charset
=> 'utf-8',
4996 -expires
=> $expires,
4997 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4999 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5002 die_error
(undef, "Unknown blobdiff format");
5006 if ($format eq 'html') {
5007 print "<div class=\"page_body\">\n";
5009 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5012 print "</div>\n"; # class="page_body"
5016 while (my $line = <$fd>) {
5017 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5018 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5022 last if $line =~ m!^\+\+\+!;
5030 sub git_blobdiff_plain
{
5031 git_blobdiff
('plain');
5034 sub git_commitdiff
{
5035 my $format = shift || 'html';
5036 $hash ||= $hash_base || "HEAD";
5037 my %co = parse_commit
($hash);
5039 die_error
(undef, "Unknown commit object");
5042 # choose format for commitdiff for merge
5043 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5044 $hash_parent = '--cc';
5046 # we need to prepare $formats_nav before almost any parameter munging
5048 if ($format eq 'html') {
5050 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5053 if (defined $hash_parent &&
5054 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5055 # commitdiff with two commits given
5056 my $hash_parent_short = $hash_parent;
5057 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5058 $hash_parent_short = substr($hash_parent, 0, 7);
5062 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5063 if ($co{'parents'}[$i] eq $hash_parent) {
5064 $formats_nav .= ' parent ' . ($i+1);
5068 $formats_nav .= ': ' .
5069 $cgi->a({-href
=> href
(action
=>"commitdiff",
5070 hash
=>$hash_parent)},
5071 esc_html
($hash_parent_short)) .
5073 } elsif (!$co{'parent'}) {
5075 $formats_nav .= ' (initial)';
5076 } elsif (scalar @
{$co{'parents'}} == 1) {
5077 # single parent commit
5080 $cgi->a({-href
=> href
(action
=>"commitdiff",
5081 hash
=>$co{'parent'})},
5082 esc_html
(substr($co{'parent'}, 0, 7))) .
5086 if ($hash_parent eq '--cc') {
5087 $formats_nav .= ' | ' .
5088 $cgi->a({-href
=> href
(action
=>"commitdiff",
5089 hash
=>$hash, hash_parent
=>'-c')},
5091 } else { # $hash_parent eq '-c'
5092 $formats_nav .= ' | ' .
5093 $cgi->a({-href
=> href
(action
=>"commitdiff",
5094 hash
=>$hash, hash_parent
=>'--cc')},
5100 $cgi->a({-href
=> href
(action
=>"commitdiff",
5102 esc_html
(substr($_, 0, 7)));
5103 } @
{$co{'parents'}} ) .
5108 my $hash_parent_param = $hash_parent;
5109 if (!defined $hash_parent_param) {
5110 # --cc for multiple parents, --root for parentless
5111 $hash_parent_param =
5112 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5118 if ($format eq 'html') {
5119 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5120 "--no-commit-id", "--patch-with-raw", "--full-index",
5121 $hash_parent_param, $hash, "--"
5122 or die_error
(undef, "Open git-diff-tree failed");
5124 while (my $line = <$fd>) {
5126 # empty line ends raw part of diff-tree output
5128 push @difftree, scalar parse_difftree_raw_line
($line);
5131 } elsif ($format eq 'plain') {
5132 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5133 '-p', $hash_parent_param, $hash, "--"
5134 or die_error
(undef, "Open git-diff-tree failed");
5137 die_error
(undef, "Unknown commitdiff format");
5140 # non-textual hash id's can be cached
5142 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5146 # write commit message
5147 if ($format eq 'html') {
5148 my $refs = git_get_references
();
5149 my $ref = format_ref_marker
($refs, $co{'id'});
5151 git_header_html
(undef, $expires);
5152 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5153 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5154 git_print_authorship
(\
%co);
5155 print "<div class=\"page_body\">\n";
5156 if (@
{$co{'comment'}} > 1) {
5157 print "<div class=\"log\">\n";
5158 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5159 print "</div>\n"; # class="log"
5162 } elsif ($format eq 'plain') {
5163 my $refs = git_get_references
("tags");
5164 my $tagname = git_get_rev_name_tags
($hash);
5165 my $filename = basename
($project) . "-$hash.patch";
5168 -type
=> 'text/plain',
5169 -charset
=> 'utf-8',
5170 -expires
=> $expires,
5171 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5172 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5173 print "From: " . to_utf8
($co{'author'}) . "\n";
5174 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5175 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5177 print "X-Git-Tag: $tagname\n" if $tagname;
5178 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5180 foreach my $line (@
{$co{'comment'}}) {
5181 print to_utf8
($line) . "\n";
5187 if ($format eq 'html') {
5188 my $use_parents = !defined $hash_parent ||
5189 $hash_parent eq '-c' || $hash_parent eq '--cc';
5190 git_difftree_body
(\
@difftree, $hash,
5191 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5194 git_patchset_body
($fd, \
@difftree, $hash,
5195 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5197 print "</div>\n"; # class="page_body"
5200 } elsif ($format eq 'plain') {
5204 or print "Reading git-diff-tree failed\n";
5208 sub git_commitdiff_plain
{
5209 git_commitdiff
('plain');
5213 if (!defined $hash_base) {
5214 $hash_base = git_get_head_hash
($project);
5216 if (!defined $page) {
5220 my %co = parse_commit
($hash_base);
5222 die_error
(undef, "Unknown commit object");
5225 my $refs = git_get_references
();
5226 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5228 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5229 $file_name, "--full-history");
5231 die_error
('404 Not Found', "No such file or directory on given branch");
5234 if (!defined $hash && defined $file_name) {
5235 # some commits could have deleted file in question,
5236 # and not have it in tree, but one of them has to have it
5237 for (my $i = 0; $i <= @commitlist; $i++) {
5238 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5239 last if defined $hash;
5242 if (defined $hash) {
5243 $ftype = git_get_type
($hash);
5245 if (!defined $ftype) {
5246 die_error
(undef, "Unknown type of object");
5249 my $paging_nav = '';
5252 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5253 file_name
=>$file_name)},
5255 $paging_nav .= " ⋅ " .
5256 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5257 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5259 $paging_nav .= "first";
5260 $paging_nav .= " ⋅ prev";
5263 if ($#commitlist >= 100) {
5265 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5266 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5267 $paging_nav .= " ⋅ $next_link";
5269 $paging_nav .= " ⋅ next";
5273 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5274 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5275 git_print_page_path
($file_name, $ftype, $hash_base);
5277 git_history_body
(\
@commitlist, 0, 99,
5278 $refs, $hash_base, $ftype, $next_link);
5284 my ($have_search) = gitweb_check_feature
('search');
5285 if (!$have_search) {
5286 die_error
('403 Permission denied', "Permission denied");
5288 if (!defined $searchtext) {
5289 die_error
(undef, "Text field empty");
5291 if (!defined $hash) {
5292 $hash = git_get_head_hash
($project);
5294 my %co = parse_commit
($hash);
5296 die_error
(undef, "Unknown commit object");
5298 if (!defined $page) {
5302 $searchtype ||= 'commit';
5303 if ($searchtype eq 'pickaxe') {
5304 # pickaxe may take all resources of your box and run for several minutes
5305 # with every query - so decide by yourself how public you make this feature
5306 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5307 if (!$have_pickaxe) {
5308 die_error
('403 Permission denied', "Permission denied");
5311 if ($searchtype eq 'grep') {
5312 my ($have_grep) = gitweb_check_feature
('grep');
5314 die_error
('403 Permission denied', "Permission denied");
5320 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5322 if ($searchtype eq 'commit') {
5323 $greptype = "--grep=";
5324 } elsif ($searchtype eq 'author') {
5325 $greptype = "--author=";
5326 } elsif ($searchtype eq 'committer') {
5327 $greptype = "--committer=";
5329 $greptype .= $searchtext;
5330 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5331 $greptype, '--regexp-ignore-case',
5332 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5334 my $paging_nav = '';
5337 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5338 searchtext
=>$searchtext,
5339 searchtype
=>$searchtype)},
5341 $paging_nav .= " ⋅ " .
5342 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5343 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5345 $paging_nav .= "first";
5346 $paging_nav .= " ⋅ prev";
5349 if ($#commitlist >= 100) {
5351 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5352 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5353 $paging_nav .= " ⋅ $next_link";
5355 $paging_nav .= " ⋅ next";
5358 if ($#commitlist >= 100) {
5361 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5362 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5363 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5366 if ($searchtype eq 'pickaxe') {
5367 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5368 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5370 print "<table class=\"pickaxe search\">\n";
5373 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5374 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5375 ($search_use_regexp ?
'--pickaxe-regex' : ());
5378 while (my $line = <$fd>) {
5382 my %set = parse_difftree_raw_line
($line);
5383 if (defined $set{'commit'}) {
5384 # finish previous commit
5387 "<td class=\"link\">" .
5388 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5390 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5396 print "<tr class=\"dark\">\n";
5398 print "<tr class=\"light\">\n";
5401 %co = parse_commit
($set{'commit'});
5402 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5403 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5404 "<td><i>$author</i></td>\n" .
5406 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5407 -class => "list subject"},
5408 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5409 } elsif (defined $set{'to_id'}) {
5410 next if ($set{'to_id'} =~ m/^0{40}$/);
5412 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5413 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5415 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5421 # finish last commit (warning: repetition!)
5424 "<td class=\"link\">" .
5425 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5427 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5435 if ($searchtype eq 'grep') {
5436 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5437 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5439 print "<table class=\"grep_search\">\n";
5443 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5444 $search_use_regexp ?
('-E', '-i') : '-F',
5445 $searchtext, $co{'tree'};
5447 while (my $line = <$fd>) {
5449 my ($file, $lno, $ltext, $binary);
5450 last if ($matches++ > 1000);
5451 if ($line =~ /^Binary file (.+) matches$/) {
5455 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5457 if ($file ne $lastfile) {
5458 $lastfile and print "</td></tr>\n";
5460 print "<tr class=\"dark\">\n";
5462 print "<tr class=\"light\">\n";
5464 print "<td class=\"list\">".
5465 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5466 file_name
=>"$file"),
5467 -class => "list"}, esc_path
($file));
5468 print "</td><td>\n";
5472 print "<div class=\"binary\">Binary file</div>\n";
5474 $ltext = untabify
($ltext);
5475 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5476 $ltext = esc_html
($1, -nbsp
=>1);
5477 $ltext .= '<span class="match">';
5478 $ltext .= esc_html
($2, -nbsp
=>1);
5479 $ltext .= '</span>';
5480 $ltext .= esc_html
($3, -nbsp
=>1);
5482 $ltext = esc_html
($ltext, -nbsp
=>1);
5484 print "<div class=\"pre\">" .
5485 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5486 file_name
=>"$file").'#l'.$lno,
5487 -class => "linenr"}, sprintf('%4i', $lno))
5488 . ' ' . $ltext . "</div>\n";
5492 print "</td></tr>\n";
5493 if ($matches > 1000) {
5494 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5497 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5506 sub git_search_help
{
5508 git_print_page_nav
('','', $hash,$hash,$hash);
5510 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5511 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5512 the pattern entered is recognized as the POSIX extended
5513 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5516 <dt><b>commit</b></dt>
5517 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5519 my ($have_grep) = gitweb_check_feature
('grep');
5522 <dt><b>grep</b></dt>
5523 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5524 a different one) are searched for the given pattern. On large trees, this search can take
5525 a while and put some strain on the server, so please use it with some consideration. Note that
5526 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5527 case-sensitive.</dd>
5531 <dt><b>author</b></dt>
5532 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5533 <dt><b>committer</b></dt>
5534 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5536 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5537 if ($have_pickaxe) {
5539 <dt><b>pickaxe</b></dt>
5540 <dd>All commits that caused the string to appear or disappear from any file (changes that
5541 added, removed or "modified" the string) will be listed. This search can take a while and
5542 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5543 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5551 my $head = git_get_head_hash
($project);
5552 if (!defined $hash) {
5555 if (!defined $page) {
5558 my $refs = git_get_references
();
5560 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5562 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5564 if ($#commitlist >= 100) {
5566 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5567 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5571 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5572 git_print_header_div
('summary', $project);
5574 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5579 ## ......................................................................
5580 ## feeds (RSS, Atom; OPML)
5583 my $format = shift || 'atom';
5584 my ($have_blame) = gitweb_check_feature
('blame');
5586 # Atom: http://www.atomenabled.org/developers/syndication/
5587 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5588 if ($format ne 'rss' && $format ne 'atom') {
5589 die_error
(undef, "Unknown web feed format");
5592 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5593 my $head = $hash || 'HEAD';
5594 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5598 my $content_type = "application/$format+xml";
5599 if (defined $cgi->http('HTTP_ACCEPT') &&
5600 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5601 # browser (feed reader) prefers text/xml
5602 $content_type = 'text/xml';
5604 if (defined($commitlist[0])) {
5605 %latest_commit = %{$commitlist[0]};
5606 %latest_date = parse_date
($latest_commit{'author_epoch'});
5608 -type
=> $content_type,
5609 -charset
=> 'utf-8',
5610 -last_modified
=> $latest_date{'rfc2822'});
5613 -type
=> $content_type,
5614 -charset
=> 'utf-8');
5617 # Optimization: skip generating the body if client asks only
5618 # for Last-Modified date.
5619 return if ($cgi->request_method() eq 'HEAD');
5622 my $title = "$site_name - $project/$action";
5623 my $feed_type = 'log';
5624 if (defined $hash) {
5625 $title .= " - '$hash'";
5626 $feed_type = 'branch log';
5627 if (defined $file_name) {
5628 $title .= " :: $file_name";
5629 $feed_type = 'history';
5631 } elsif (defined $file_name) {
5632 $title .= " - $file_name";
5633 $feed_type = 'history';
5635 $title .= " $feed_type";
5636 my $descr = git_get_project_description
($project);
5637 if (defined $descr) {
5638 $descr = esc_html
($descr);
5640 $descr = "$project " .
5641 ($format eq 'rss' ?
'RSS' : 'Atom') .
5644 my $owner = git_get_project_owner
($project);
5645 $owner = esc_html
($owner);
5649 if (defined $file_name) {
5650 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5651 } elsif (defined $hash) {
5652 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5654 $alt_url = href
(-full
=>1, action
=>"summary");
5656 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5657 if ($format eq 'rss') {
5659 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5662 print "<title>$title</title>\n" .
5663 "<link>$alt_url</link>\n" .
5664 "<description>$descr</description>\n" .
5665 "<language>en</language>\n";
5666 } elsif ($format eq 'atom') {
5668 <feed xmlns="http://www.w3.org/2005/Atom">
5670 print "<title>$title</title>\n" .
5671 "<subtitle>$descr</subtitle>\n" .
5672 '<link rel="alternate" type="text/html" href="' .
5673 $alt_url . '" />' . "\n" .
5674 '<link rel="self" type="' . $content_type . '" href="' .
5675 $cgi->self_url() . '" />' . "\n" .
5676 "<id>" . href
(-full
=>1) . "</id>\n" .
5677 # use project owner for feed author
5678 "<author><name>$owner</name></author>\n";
5679 if (defined $favicon) {
5680 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5682 if (defined $logo_url) {
5683 # not twice as wide as tall: 72 x 27 pixels
5684 print "<logo>" . esc_url
($logo) . "</logo>\n";
5686 if (! %latest_date) {
5687 # dummy date to keep the feed valid until commits trickle in:
5688 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5690 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5695 for (my $i = 0; $i <= $#commitlist; $i++) {
5696 my %co = %{$commitlist[$i]};
5697 my $commit = $co{'id'};
5698 # we read 150, we always show 30 and the ones more recent than 48 hours
5699 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5702 my %cd = parse_date
($co{'author_epoch'});
5704 # get list of changed files
5705 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5706 $co{'parent'} || "--root",
5707 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5709 my @difftree = map { chomp; $_ } <$fd>;
5713 # print element (entry, item)
5714 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5715 if ($format eq 'rss') {
5717 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5718 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5719 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5720 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5721 "<link>$co_url</link>\n" .
5722 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5723 "<content:encoded>" .
5725 } elsif ($format eq 'atom') {
5727 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5728 "<updated>$cd{'iso-8601'}</updated>\n" .
5730 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5731 if ($co{'author_email'}) {
5732 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5734 print "</author>\n" .
5735 # use committer for contributor
5737 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5738 if ($co{'committer_email'}) {
5739 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5741 print "</contributor>\n" .
5742 "<published>$cd{'iso-8601'}</published>\n" .
5743 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5744 "<id>$co_url</id>\n" .
5745 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5746 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5748 my $comment = $co{'comment'};
5750 foreach my $line (@
$comment) {
5751 $line = esc_html
($line);
5754 print "</pre><ul>\n";
5755 foreach my $difftree_line (@difftree) {
5756 my %difftree = parse_difftree_raw_line
($difftree_line);
5757 next if !$difftree{'from_id'};
5759 my $file = $difftree{'file'} || $difftree{'to_file'};
5763 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5764 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5765 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5766 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5767 -title
=> "diff"}, 'D');
5769 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5770 file_name
=>$file, hash_base
=>$commit),
5771 -title
=> "blame"}, 'B');
5773 # if this is not a feed of a file history
5774 if (!defined $file_name || $file_name ne $file) {
5775 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5776 file_name
=>$file, hash
=>$commit),
5777 -title
=> "history"}, 'H');
5779 $file = esc_path
($file);
5783 if ($format eq 'rss') {
5784 print "</ul>]]>\n" .
5785 "</content:encoded>\n" .
5787 } elsif ($format eq 'atom') {
5788 print "</ul>\n</div>\n" .
5795 if ($format eq 'rss') {
5796 print "</channel>\n</rss>\n";
5797 } elsif ($format eq 'atom') {
5811 my @list = git_get_projects_list
();
5813 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5815 <?xml version="1.0" encoding="utf-8"?>
5816 <opml version="1.0">
5818 <title>$site_name OPML Export</title>
5821 <outline text="git RSS feeds">
5824 foreach my $pr (@list) {
5826 my $head = git_get_head_hash
($proj{'path'});
5827 if (!defined $head) {
5830 $git_dir = "$projectroot/$proj{'path'}";
5831 my %co = parse_commit
($head);
5836 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5837 my $rss = "$my_url?p=$proj{'path'};a=rss";
5838 my $html = "$my_url?p=$proj{'path'};a=summary";
5839 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";