3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # fs traversing limit for getting project list
39 # the number is relative to the projectroot
40 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
45 # string of the home link on top of all pages
46 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
48 # name of your site or organization to appear in page titles
49 # replace this with something more descriptive for clearer bookmarks
50 our $site_name = "++GITWEB_SITENAME++"
51 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
53 # filename of html text to include at top of each page
54 our $site_header = "++GITWEB_SITE_HEADER++";
55 # html text to include at home page
56 our $home_text = "++GITWEB_HOMETEXT++";
57 # filename of html text to include at bottom of each page
58 our $site_footer = "++GITWEB_SITE_FOOTER++";
61 our @stylesheets = ("++GITWEB_CSS++");
62 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
63 our $stylesheet = undef;
65 # URI of GIT logo (72x27 size)
66 our $logo = "++GITWEB_LOGO++";
67 # URI of GIT favicon, assumed to be image/png type
68 our $favicon = "++GITWEB_FAVICON++";
70 # URI and label (title) of GIT logo link
71 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
72 #our $logo_label = "git documentation";
73 our $logo_url = "http://git.or.cz/";
74 our $logo_label = "git homepage";
76 # source of projects list
77 our $projects_list = "++GITWEB_LIST++";
79 # the width (in characters) of the projects list "Description" column
80 our $projects_list_description_width = 25;
82 # default order of projects list
83 # valid values are none, project, descr, owner, and age
84 our $default_projects_order = "project";
86 # show repository only if this file exists
87 # (only effective if this variable evaluates to true)
88 our $export_ok = "++GITWEB_EXPORT_OK++";
90 # only allow viewing of repositories also shown on the overview page
91 our $strict_export = "++GITWEB_STRICT_EXPORT++";
93 # list of git base URLs used for URL to where fetch project from,
94 # i.e. full URL is "$git_base_url/$project"
95 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
97 # default blob_plain mimetype and default charset for text/plain blob
98 our $default_blob_plain_mimetype = 'text/plain';
99 our $default_text_plain_charset = undef;
101 # file to use for guessing MIME types before trying /etc/mime.types
102 # (relative to the current git repository)
103 our $mimetypes_file = undef;
105 # assume this charset if line contains non-UTF-8 characters;
106 # it should be valid encoding (see Encoding::Supported(3pm) for list),
107 # for which encoding all byte sequences are valid, for example
108 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
109 # could be even 'utf-8' for the old behavior)
110 our $fallback_encoding = 'latin1';
112 # rename detection options for git-diff and git-diff-tree
113 # - default is '-M', with the cost proportional to
114 # (number of removed files) * (number of new files).
115 # - more costly is '-C' (which implies '-M'), with the cost proportional to
116 # (number of changed files + number of removed files) * (number of new files)
117 # - even more costly is '-C', '--find-copies-harder' with cost
118 # (number of files in the original tree) * (number of new files)
119 # - one might want to include '-B' option, e.g. '-B', '-M'
120 our @diff_opts = ('-M'); # taken from git_commit
122 # information about snapshot formats that gitweb is capable of serving
123 our %known_snapshot_formats = (
125 # 'display' => display name,
126 # 'type' => mime type,
127 # 'suffix' => filename suffix,
128 # 'format' => --format for git-archive,
129 # 'compressor' => [compressor command and arguments]
130 # (array reference, optional)}
133 'display' => 'tar.gz',
134 'type' => 'application/x-gzip',
135 'suffix' => '.tar.gz',
137 'compressor' => ['gzip']},
140 'display' => 'tar.bz2',
141 'type' => 'application/x-bzip2',
142 'suffix' => '.tar.bz2',
144 'compressor' => ['bzip2']},
148 'type' => 'application/x-zip',
153 # Aliases so we understand old gitweb.snapshot values in repository
155 our %known_snapshot_format_aliases = (
159 # backward compatibility: legacy gitweb config support
160 'x-gzip' => undef, 'gz' => undef,
161 'x-bzip2' => undef, 'bz2' => undef,
162 'x-zip' => undef, '' => undef,
165 # You define site-wide feature defaults here; override them with
166 # $GITWEB_CONFIG as necessary.
169 # 'sub' => feature-sub (subroutine),
170 # 'override' => allow-override (boolean),
171 # 'default' => [ default options...] (array reference)}
173 # if feature is overridable (it means that allow-override has true value),
174 # then feature-sub will be called with default options as parameters;
175 # return value of feature-sub indicates if to enable specified feature
177 # if there is no 'sub' key (no feature-sub), then feature cannot be
180 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
182 # Enable the 'blame' blob view, showing the last commit that modified
183 # each line in the file. This can be very CPU-intensive.
185 # To enable system wide have in $GITWEB_CONFIG
186 # $feature{'blame'}{'default'} = [1];
187 # To have project specific config enable override in $GITWEB_CONFIG
188 # $feature{'blame'}{'override'} = 1;
189 # and in project config gitweb.blame = 0|1;
191 'sub' => \
&feature_blame
,
195 # Enable the 'snapshot' link, providing a compressed archive of any
196 # tree. This can potentially generate high traffic if you have large
199 # Value is a list of formats defined in %known_snapshot_formats that
201 # To disable system wide have in $GITWEB_CONFIG
202 # $feature{'snapshot'}{'default'} = [];
203 # To have project specific config enable override in $GITWEB_CONFIG
204 # $feature{'snapshot'}{'override'} = 1;
205 # and in project config, a comma-separated list of formats or "none"
206 # to disable. Example: gitweb.snapshot = tbz2,zip;
208 'sub' => \
&feature_snapshot
,
210 'default' => ['tgz']},
212 # Enable text search, which will list the commits which match author,
213 # committer or commit text to a given string. Enabled by default.
214 # Project specific override is not supported.
219 # Enable grep search, which will list the files in currently selected
220 # tree containing the given string. Enabled by default. This can be
221 # potentially CPU-intensive, of course.
223 # To enable system wide have in $GITWEB_CONFIG
224 # $feature{'grep'}{'default'} = [1];
225 # To have project specific config enable override in $GITWEB_CONFIG
226 # $feature{'grep'}{'override'} = 1;
227 # and in project config gitweb.grep = 0|1;
232 # Enable the pickaxe search, which will list the commits that modified
233 # a given string in a file. This can be practical and quite faster
234 # alternative to 'blame', but still potentially CPU-intensive.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'pickaxe'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'pickaxe'}{'override'} = 1;
240 # and in project config gitweb.pickaxe = 0|1;
242 'sub' => \
&feature_pickaxe
,
246 # Make gitweb use an alternative format of the URLs which can be
247 # more readable and natural-looking: project name is embedded
248 # directly in the path and the query string contains other
249 # auxiliary information. All gitweb installations recognize
250 # URL in either format; this configures in which formats gitweb
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'pathinfo'}{'default'} = [1];
255 # Project specific override is not supported.
257 # Note that you will need to change the default location of CSS,
258 # favicon, logo and possibly other files to an absolute URL. Also,
259 # if gitweb.cgi serves as your indexfile, you will need to force
260 # $my_uri to contain the script name in your $GITWEB_CONFIG.
265 # Make gitweb consider projects in project root subdirectories
266 # to be forks of existing projects. Given project $projname.git,
267 # projects matching $projname/*.git will not be shown in the main
268 # projects list, instead a '+' mark will be added to $projname
269 # there and a 'forks' view will be enabled for the project, listing
270 # all the forks. If project list is taken from a file, forks have
271 # to be listed after the main project.
273 # To enable system wide have in $GITWEB_CONFIG
274 # $feature{'forks'}{'default'} = [1];
275 # Project specific override is not supported.
281 sub gitweb_check_feature
{
283 return unless exists $feature{$name};
284 my ($sub, $override, @defaults) = (
285 $feature{$name}{'sub'},
286 $feature{$name}{'override'},
287 @{$feature{$name}{'default'}});
288 if (!$override) { return @defaults; }
290 warn "feature $name is not overrideable";
293 return $sub->(@defaults);
297 my ($val) = git_get_project_config
('blame', '--bool');
299 if ($val eq 'true') {
301 } elsif ($val eq 'false') {
308 sub feature_snapshot
{
311 my ($val) = git_get_project_config
('snapshot');
314 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
321 my ($val) = git_get_project_config
('grep', '--bool');
323 if ($val eq 'true') {
325 } elsif ($val eq 'false') {
332 sub feature_pickaxe
{
333 my ($val) = git_get_project_config
('pickaxe', '--bool');
335 if ($val eq 'true') {
337 } elsif ($val eq 'false') {
344 # checking HEAD file with -e is fragile if the repository was
345 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
347 sub check_head_link
{
349 my $headfile = "$dir/HEAD";
350 return ((-e
$headfile) ||
351 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
354 sub check_export_ok
{
356 return (check_head_link
($dir) &&
357 (!$export_ok || -e
"$dir/$export_ok"));
360 # process alternate names for backward compatibility
361 # filter out unsupported (unknown) snapshot formats
362 sub filter_snapshot_fmts
{
366 exists $known_snapshot_format_aliases{$_} ?
367 $known_snapshot_format_aliases{$_} : $_} @fmts;
368 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
372 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
373 if (-e
$GITWEB_CONFIG) {
376 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
377 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
380 # version of the core git binary
381 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
383 $projects_list ||= $projectroot;
385 # ======================================================================
386 # input validation and dispatch
387 our $action = $cgi->param('a');
388 if (defined $action) {
389 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
390 die_error
(undef, "Invalid action parameter");
394 # parameters which are pathnames
395 our $project = $cgi->param('p');
396 if (defined $project) {
397 if (!validate_pathname
($project) ||
398 !(-d
"$projectroot/$project") ||
399 !check_head_link
("$projectroot/$project") ||
400 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
401 ($strict_export && !project_in_list
($project))) {
403 die_error
(undef, "No such project");
407 our $file_name = $cgi->param('f');
408 if (defined $file_name) {
409 if (!validate_pathname
($file_name)) {
410 die_error
(undef, "Invalid file parameter");
414 our $file_parent = $cgi->param('fp');
415 if (defined $file_parent) {
416 if (!validate_pathname
($file_parent)) {
417 die_error
(undef, "Invalid file parent parameter");
421 # parameters which are refnames
422 our $hash = $cgi->param('h');
424 if (!validate_refname
($hash)) {
425 die_error
(undef, "Invalid hash parameter");
429 our $hash_parent = $cgi->param('hp');
430 if (defined $hash_parent) {
431 if (!validate_refname
($hash_parent)) {
432 die_error
(undef, "Invalid hash parent parameter");
436 our $hash_base = $cgi->param('hb');
437 if (defined $hash_base) {
438 if (!validate_refname
($hash_base)) {
439 die_error
(undef, "Invalid hash base parameter");
443 my %allowed_options = (
444 "--no-merges" => [ qw(rss atom log shortlog history) ],
447 our @extra_options = $cgi->param('opt');
448 if (defined @extra_options) {
449 foreach my $opt (@extra_options) {
450 if (not exists $allowed_options{$opt}) {
451 die_error
(undef, "Invalid option parameter");
453 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
454 die_error
(undef, "Invalid option parameter for this action");
459 our $hash_parent_base = $cgi->param('hpb');
460 if (defined $hash_parent_base) {
461 if (!validate_refname
($hash_parent_base)) {
462 die_error
(undef, "Invalid hash parent base parameter");
467 our $page = $cgi->param('pg');
469 if ($page =~ m/[^0-9]/) {
470 die_error
(undef, "Invalid page parameter");
474 our $searchtype = $cgi->param('st');
475 if (defined $searchtype) {
476 if ($searchtype =~ m/[^a-z]/) {
477 die_error
(undef, "Invalid searchtype parameter");
481 our $search_use_regexp = $cgi->param('sr');
483 our $searchtext = $cgi->param('s');
485 if (defined $searchtext) {
486 if (length($searchtext) < 2) {
487 die_error
(undef, "At least two characters are required for search parameter");
489 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
492 # now read PATH_INFO and use it as alternative to parameters
493 sub evaluate_path_info
{
494 return if defined $project;
495 my $path_info = $ENV{"PATH_INFO"};
496 return if !$path_info;
497 $path_info =~ s
,^/+,,;
498 return if !$path_info;
499 # find which part of PATH_INFO is project
500 $project = $path_info;
502 while ($project && !check_head_link
("$projectroot/$project")) {
503 $project =~ s
,/*[^/]*$,,;
506 $project = validate_pathname
($project);
508 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
509 ($strict_export && !project_in_list
($project))) {
513 # do not change any parameters if an action is given using the query string
515 $path_info =~ s
,^\Q
$project\E
/*,,;
516 my ($refname, $pathname) = split(/:/, $path_info, 2);
517 if (defined $pathname) {
518 # we got "project.git/branch:filename" or "project.git/branch:dir/"
519 # we could use git_get_type(branch:pathname), but it needs $git_dir
520 $pathname =~ s
,^/+,,;
521 if (!$pathname || substr($pathname, -1) eq "/") {
525 $action ||= "blob_plain";
527 $hash_base ||= validate_refname
($refname);
528 $file_name ||= validate_pathname
($pathname);
529 } elsif (defined $refname) {
530 # we got "project.git/branch"
531 $action ||= "shortlog";
532 $hash ||= validate_refname
($refname);
535 evaluate_path_info
();
537 # path to the current git repository
539 $git_dir = "$projectroot/$project" if $project;
543 "blame" => \
&git_blame2
,
544 "blobdiff" => \
&git_blobdiff
,
545 "blobdiff_plain" => \
&git_blobdiff_plain
,
546 "blob" => \
&git_blob
,
547 "blob_plain" => \
&git_blob_plain
,
548 "commitdiff" => \
&git_commitdiff
,
549 "commitdiff_plain" => \
&git_commitdiff_plain
,
550 "commit" => \
&git_commit
,
551 "forks" => \
&git_forks
,
552 "heads" => \
&git_heads
,
553 "history" => \
&git_history
,
556 "atom" => \
&git_atom
,
557 "search" => \
&git_search
,
558 "search_help" => \
&git_search_help
,
559 "shortlog" => \
&git_shortlog
,
560 "summary" => \
&git_summary
,
562 "tags" => \
&git_tags
,
563 "tree" => \
&git_tree
,
564 "snapshot" => \
&git_snapshot
,
565 "object" => \
&git_object
,
566 # those below don't need $project
567 "opml" => \
&git_opml
,
568 "project_list" => \
&git_project_list
,
569 "project_index" => \
&git_project_index
,
572 if (!defined $action) {
574 $action = git_get_type
($hash);
575 } elsif (defined $hash_base && defined $file_name) {
576 $action = git_get_type
("$hash_base:$file_name");
577 } elsif (defined $project) {
580 $action = 'project_list';
583 if (!defined($actions{$action})) {
584 die_error
(undef, "Unknown action");
586 if ($action !~ m/^(opml|project_list|project_index)$/ &&
588 die_error
(undef, "Project needed");
590 $actions{$action}->();
593 ## ======================================================================
598 # default is to use -absolute url() i.e. $my_uri
599 my $href = $params{-full
} ? $my_url : $my_uri;
601 # XXX: Warning: If you touch this, check the search form for updating,
612 hash_parent_base
=> "hpb",
617 snapshot_format
=> "sf",
618 extra_options
=> "opt",
619 search_use_regexp
=> "sr",
621 my %mapping = @mapping;
623 $params{'project'} = $project unless exists $params{'project'};
625 if ($params{-replay
}) {
626 while (my ($name, $symbol) = each %mapping) {
627 if (!exists $params{$name}) {
628 # to allow for multivalued params we use arrayref form
629 $params{$name} = [ $cgi->param($symbol) ];
634 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
636 # use PATH_INFO for project name
637 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
638 delete $params{'project'};
640 # Summary just uses the project path URL
641 if (defined $params{'action'} && $params{'action'} eq 'summary') {
642 delete $params{'action'};
646 # now encode the parameters explicitly
648 for (my $i = 0; $i < @mapping; $i += 2) {
649 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
650 if (defined $params{$name}) {
651 if (ref($params{$name}) eq "ARRAY") {
652 foreach my $par (@{$params{$name}}) {
653 push @result, $symbol . "=" . esc_param
($par);
656 push @result, $symbol . "=" . esc_param
($params{$name});
660 $href .= "?" . join(';', @result) if scalar @result;
666 ## ======================================================================
667 ## validation, quoting/unquoting and escaping
669 sub validate_pathname
{
670 my $input = shift || return undef;
672 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
673 # at the beginning, at the end, and between slashes.
674 # also this catches doubled slashes
675 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
679 if ($input =~ m!\0!) {
685 sub validate_refname
{
686 my $input = shift || return undef;
688 # textual hashes are O.K.
689 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
692 # it must be correct pathname
693 $input = validate_pathname
($input)
695 # restrictions on ref name according to git-check-ref-format
696 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
702 # decode sequences of octets in utf8 into Perl's internal form,
703 # which is utf-8 with utf8 flag set if needed. gitweb writes out
704 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
707 if (utf8
::valid
($str)) {
711 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
715 # quote unsafe chars, but keep the slash, even when it's not
716 # correct, but quoted slashes look too horrible in bookmarks
719 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
725 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
728 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
734 # replace invalid utf8 character with SUBSTITUTION sequence
739 $str = to_utf8
($str);
740 $str = $cgi->escapeHTML($str);
741 if ($opts{'-nbsp'}) {
742 $str =~ s/ / /g;
744 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
748 # quote control characters and escape filename to HTML
753 $str = to_utf8
($str);
754 $str = $cgi->escapeHTML($str);
755 if ($opts{'-nbsp'}) {
756 $str =~ s/ / /g;
758 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
762 # Make control characters "printable", using character escape codes (CEC)
766 my %es = ( # character escape codes, aka escape sequences
767 "\t" => '\t', # tab (HT)
768 "\n" => '\n', # line feed (LF)
769 "\r" => '\r', # carrige return (CR)
770 "\f" => '\f', # form feed (FF)
771 "\b" => '\b', # backspace (BS)
772 "\a" => '\a', # alarm (bell) (BEL)
773 "\e" => '\e', # escape (ESC)
774 "\013" => '\v', # vertical tab (VT)
775 "\000" => '\0', # nul character (NUL)
777 my $chr = ( (exists $es{$cntrl})
779 : sprintf('\%03o', ord($cntrl)) );
780 if ($opts{-nohtml
}) {
783 return "<span class=\"cntrl\">$chr</span>";
787 # Alternatively use unicode control pictures codepoints,
788 # Unicode "printable representation" (PR)
793 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
794 if ($opts{-nohtml
}) {
797 return "<span class=\"cntrl\">$chr</span>";
801 # git may return quoted and escaped filenames
807 my %es = ( # character escape codes, aka escape sequences
808 't' => "\t", # tab (HT, TAB)
809 'n' => "\n", # newline (NL)
810 'r' => "\r", # return (CR)
811 'f' => "\f", # form feed (FF)
812 'b' => "\b", # backspace (BS)
813 'a' => "\a", # alarm (bell) (BEL)
814 'e' => "\e", # escape (ESC)
815 'v' => "\013", # vertical tab (VT)
818 if ($seq =~ m/^[0-7]{1,3}$/) {
819 # octal char sequence
820 return chr(oct($seq));
821 } elsif (exists $es{$seq}) {
822 # C escape sequence, aka character escape code
825 # quoted ordinary character
829 if ($str =~ m/^"(.*)"$/) {
832 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
837 # escape tabs (convert tabs to spaces)
841 while ((my $pos = index($line, "\t")) != -1) {
842 if (my $count = (8 - ($pos % 8))) {
843 my $spaces = ' ' x
$count;
844 $line =~ s/\t/$spaces/;
851 sub project_in_list
{
853 my @list = git_get_projects_list
();
854 return @list && scalar(grep { $_->{'path'} eq $project } @list);
857 ## ----------------------------------------------------------------------
858 ## HTML aware string manipulation
860 # Try to chop given string on a word boundary between position
861 # $len and $len+$add_len. If there is no word boundary there,
862 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
863 # (marking chopped part) would be longer than given string.
867 my $add_len = shift || 10;
868 my $where = shift || 'right'; # 'left' | 'center' | 'right'
870 # Make sure perl knows it is utf8 encoded so we don't
871 # cut in the middle of a utf8 multibyte char.
872 $str = to_utf8
($str);
874 # allow only $len chars, but don't cut a word if it would fit in $add_len
875 # if it doesn't fit, cut it if it's still longer than the dots we would add
876 # remove chopped character entities entirely
878 # when chopping in the middle, distribute $len into left and right part
879 # return early if chopping wouldn't make string shorter
880 if ($where eq 'center') {
881 return $str if ($len + 5 >= length($str)); # filler is length 5
884 return $str if ($len + 4 >= length($str)); # filler is length 4
887 # regexps: ending and beginning with word part up to $add_len
888 my $endre = qr/.{$len}\w{0,$add_len}/;
889 my $begre = qr/\w{0,$add_len}.{$len}/;
891 if ($where eq 'left') {
892 $str =~ m/^(.*?)($begre)$/;
893 my ($lead, $body) = ($1, $2);
894 if (length($lead) > 4) {
895 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
900 } elsif ($where eq 'center') {
901 $str =~ m/^($endre)(.*)$/;
902 my ($left, $str) = ($1, $2);
903 $str =~ m/^(.*?)($begre)$/;
904 my ($mid, $right) = ($1, $2);
905 if (length($mid) > 5) {
906 $left =~ s/&[^;]*$//;
907 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
910 return "$left$mid$right";
913 $str =~ m/^($endre)(.*)$/;
916 if (length($tail) > 4) {
917 $body =~ s/&[^;]*$//;
924 # takes the same arguments as chop_str, but also wraps a <span> around the
925 # result with a title attribute if it does get chopped. Additionally, the
926 # string is HTML-escaped.
927 sub chop_and_escape_str
{
930 my $chopped = chop_str
(@_);
931 if ($chopped eq $str) {
932 return esc_html
($chopped);
934 $str =~ s/([[:cntrl:]])/?/g;
935 return $cgi->span({-title
=>$str}, esc_html
($chopped));
939 ## ----------------------------------------------------------------------
940 ## functions returning short strings
942 # CSS class for given age value (in seconds)
948 } elsif ($age < 60*60*2) {
950 } elsif ($age < 60*60*24*2) {
957 # convert age in seconds to "nn units ago" string
962 if ($age > 60*60*24*365*2) {
963 $age_str = (int $age/60/60/24/365);
964 $age_str .= " years ago";
965 } elsif ($age > 60*60*24*(365/12)*2) {
966 $age_str = int $age/60/60/24/(365/12);
967 $age_str .= " months ago";
968 } elsif ($age > 60*60*24*7*2) {
969 $age_str = int $age/60/60/24/7;
970 $age_str .= " weeks ago";
971 } elsif ($age > 60*60*24*2) {
972 $age_str = int $age/60/60/24;
973 $age_str .= " days ago";
974 } elsif ($age > 60*60*2) {
975 $age_str = int $age/60/60;
976 $age_str .= " hours ago";
977 } elsif ($age > 60*2) {
978 $age_str = int $age/60;
979 $age_str .= " min ago";
982 $age_str .= " sec ago";
984 $age_str .= " right now";
990 S_IFINVALID
=> 0030000,
991 S_IFGITLINK
=> 0160000,
994 # submodule/subproject, a commit object reference
998 return (($mode & S_IFMT
) == S_IFGITLINK
)
1001 # convert file mode in octal to symbolic file mode string
1003 my $mode = oct shift;
1005 if (S_ISGITLINK
($mode)) {
1006 return 'm---------';
1007 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1008 return 'drwxr-xr-x';
1009 } elsif (S_ISLNK
($mode)) {
1010 return 'lrwxrwxrwx';
1011 } elsif (S_ISREG
($mode)) {
1012 # git cares only about the executable bit
1013 if ($mode & S_IXUSR
) {
1014 return '-rwxr-xr-x';
1016 return '-rw-r--r--';
1019 return '----------';
1023 # convert file mode in octal to file type string
1027 if ($mode !~ m/^[0-7]+$/) {
1033 if (S_ISGITLINK
($mode)) {
1035 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1037 } elsif (S_ISLNK
($mode)) {
1039 } elsif (S_ISREG
($mode)) {
1046 # convert file mode in octal to file type description string
1047 sub file_type_long
{
1050 if ($mode !~ m/^[0-7]+$/) {
1056 if (S_ISGITLINK
($mode)) {
1058 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1060 } elsif (S_ISLNK
($mode)) {
1062 } elsif (S_ISREG
($mode)) {
1063 if ($mode & S_IXUSR
) {
1064 return "executable";
1074 ## ----------------------------------------------------------------------
1075 ## functions returning short HTML fragments, or transforming HTML fragments
1076 ## which don't belong to other sections
1078 # format line of commit message.
1079 sub format_log_line_html
{
1082 $line = esc_html
($line, -nbsp
=>1);
1083 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1086 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1087 -class => "text"}, $hash_text);
1088 $line =~ s/$hash_text/$link/;
1093 # format marker of refs pointing to given object
1094 sub format_ref_marker
{
1095 my ($refs, $id) = @_;
1098 if (defined $refs->{$id}) {
1099 foreach my $ref (@{$refs->{$id}}) {
1100 my ($type, $name) = qw();
1101 # e.g. tags/v2.6.11 or heads/next
1102 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1110 $markers .= " <span class=\"$type\" title=\"$ref\">" .
1111 esc_html
($name) . "</span>";
1116 return ' <span class="refs">'. $markers . '</span>';
1122 # format, perhaps shortened and with markers, title line
1123 sub format_subject_html
{
1124 my ($long, $short, $href, $extra) = @_;
1125 $extra = '' unless defined($extra);
1127 if (length($short) < length($long)) {
1128 return $cgi->a({-href
=> $href, -class => "list subject",
1129 -title
=> to_utf8
($long)},
1130 esc_html
($short) . $extra);
1132 return $cgi->a({-href
=> $href, -class => "list subject"},
1133 esc_html
($long) . $extra);
1137 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1138 sub format_git_diff_header_line
{
1140 my $diffinfo = shift;
1141 my ($from, $to) = @_;
1143 if ($diffinfo->{'nparents'}) {
1145 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1146 if ($to->{'href'}) {
1147 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1148 esc_path
($to->{'file'}));
1149 } else { # file was deleted (no href)
1150 $line .= esc_path
($to->{'file'});
1154 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1155 if ($from->{'href'}) {
1156 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1157 'a/' . esc_path
($from->{'file'}));
1158 } else { # file was added (no href)
1159 $line .= 'a/' . esc_path
($from->{'file'});
1162 if ($to->{'href'}) {
1163 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1164 'b/' . esc_path
($to->{'file'}));
1165 } else { # file was deleted
1166 $line .= 'b/' . esc_path
($to->{'file'});
1170 return "<div class=\"diff header\">$line</div>\n";
1173 # format extended diff header line, before patch itself
1174 sub format_extended_diff_header_line
{
1176 my $diffinfo = shift;
1177 my ($from, $to) = @_;
1180 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1181 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1182 esc_path
($from->{'file'}));
1184 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1185 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1186 esc_path
($to->{'file'}));
1188 # match single <mode>
1189 if ($line =~ m/\s(\d{6})$/) {
1190 $line .= '<span class="info"> (' .
1191 file_type_long
($1) .
1195 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1196 # can match only for combined diff
1198 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1199 if ($from->{'href'}[$i]) {
1200 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1202 substr($diffinfo->{'from_id'}[$i],0,7));
1207 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1210 if ($to->{'href'}) {
1211 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1212 substr($diffinfo->{'to_id'},0,7));
1217 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1218 # can match only for ordinary diff
1219 my ($from_link, $to_link);
1220 if ($from->{'href'}) {
1221 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1222 substr($diffinfo->{'from_id'},0,7));
1224 $from_link = '0' x
7;
1226 if ($to->{'href'}) {
1227 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1228 substr($diffinfo->{'to_id'},0,7));
1232 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1233 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1236 return $line . "<br/>\n";
1239 # format from-file/to-file diff header
1240 sub format_diff_from_to_header
{
1241 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1246 #assert($line =~ m/^---/) if DEBUG;
1247 # no extra formatting for "^--- /dev/null"
1248 if (! $diffinfo->{'nparents'}) {
1249 # ordinary (single parent) diff
1250 if ($line =~ m!^--- "?a/!) {
1251 if ($from->{'href'}) {
1253 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1254 esc_path
($from->{'file'}));
1257 esc_path
($from->{'file'});
1260 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1263 # combined diff (merge commit)
1264 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1265 if ($from->{'href'}[$i]) {
1267 $cgi->a({-href
=>href
(action
=>"blobdiff",
1268 hash_parent
=>$diffinfo->{'from_id'}[$i],
1269 hash_parent_base
=>$parents[$i],
1270 file_parent
=>$from->{'file'}[$i],
1271 hash
=>$diffinfo->{'to_id'},
1273 file_name
=>$to->{'file'}),
1275 -title
=>"diff" . ($i+1)},
1278 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1279 esc_path
($from->{'file'}[$i]));
1281 $line = '--- /dev/null';
1283 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1288 #assert($line =~ m/^\+\+\+/) if DEBUG;
1289 # no extra formatting for "^+++ /dev/null"
1290 if ($line =~ m!^\+\+\+ "?b/!) {
1291 if ($to->{'href'}) {
1293 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1294 esc_path
($to->{'file'}));
1297 esc_path
($to->{'file'});
1300 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1305 # create note for patch simplified by combined diff
1306 sub format_diff_cc_simplified
{
1307 my ($diffinfo, @parents) = @_;
1310 $result .= "<div class=\"diff header\">" .
1312 if (!is_deleted
($diffinfo)) {
1313 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1315 hash
=>$diffinfo->{'to_id'},
1316 file_name
=>$diffinfo->{'to_file'}),
1318 esc_path
($diffinfo->{'to_file'}));
1320 $result .= esc_path
($diffinfo->{'to_file'});
1322 $result .= "</div>\n" . # class="diff header"
1323 "<div class=\"diff nodifferences\">" .
1325 "</div>\n"; # class="diff nodifferences"
1330 # format patch (diff) line (not to be used for diff headers)
1331 sub format_diff_line
{
1333 my ($from, $to) = @_;
1334 my $diff_class = "";
1338 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1340 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1341 if ($line =~ m/^\@{3}/) {
1342 $diff_class = " chunk_header";
1343 } elsif ($line =~ m/^\\/) {
1344 $diff_class = " incomplete";
1345 } elsif ($prefix =~ tr/+/+/) {
1346 $diff_class = " add";
1347 } elsif ($prefix =~ tr/-/-/) {
1348 $diff_class = " rem";
1351 # assume ordinary diff
1352 my $char = substr($line, 0, 1);
1354 $diff_class = " add";
1355 } elsif ($char eq '-') {
1356 $diff_class = " rem";
1357 } elsif ($char eq '@') {
1358 $diff_class = " chunk_header";
1359 } elsif ($char eq "\\") {
1360 $diff_class = " incomplete";
1363 $line = untabify
($line);
1364 if ($from && $to && $line =~ m/^\@{2} /) {
1365 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1366 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1368 $from_lines = 0 unless defined $from_lines;
1369 $to_lines = 0 unless defined $to_lines;
1371 if ($from->{'href'}) {
1372 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1373 -class=>"list"}, $from_text);
1375 if ($to->{'href'}) {
1376 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1377 -class=>"list"}, $to_text);
1379 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1380 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1381 return "<div class=\"diff$diff_class\">$line</div>\n";
1382 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1383 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1384 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1386 @from_text = split(' ', $ranges);
1387 for (my $i = 0; $i < @from_text; ++$i) {
1388 ($from_start[$i], $from_nlines[$i]) =
1389 (split(',', substr($from_text[$i], 1)), 0);
1392 $to_text = pop @from_text;
1393 $to_start = pop @from_start;
1394 $to_nlines = pop @from_nlines;
1396 $line = "<span class=\"chunk_info\">$prefix ";
1397 for (my $i = 0; $i < @from_text; ++$i) {
1398 if ($from->{'href'}[$i]) {
1399 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1400 -class=>"list"}, $from_text[$i]);
1402 $line .= $from_text[$i];
1406 if ($to->{'href'}) {
1407 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1408 -class=>"list"}, $to_text);
1412 $line .= " $prefix</span>" .
1413 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1414 return "<div class=\"diff$diff_class\">$line</div>\n";
1416 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1419 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1420 # linked. Pass the hash of the tree/commit to snapshot.
1421 sub format_snapshot_links
{
1423 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1424 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1425 my $num_fmts = @snapshot_fmts;
1426 if ($num_fmts > 1) {
1427 # A parenthesized list of links bearing format names.
1428 # e.g. "snapshot (_tar.gz_ _zip_)"
1429 return "snapshot (" . join(' ', map
1436 }, $known_snapshot_formats{$_}{'display'})
1437 , @snapshot_fmts) . ")";
1438 } elsif ($num_fmts == 1) {
1439 # A single "snapshot" link whose tooltip bears the format name.
1441 my ($fmt) = @snapshot_fmts;
1447 snapshot_format
=>$fmt
1449 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1451 } else { # $num_fmts == 0
1456 ## ......................................................................
1457 ## functions returning values to be passed, perhaps after some
1458 ## transformation, to other functions; e.g. returning arguments to href()
1460 # returns hash to be passed to href to generate gitweb URL
1461 # in -title key it returns description of link
1463 my $format = shift || 'Atom';
1464 my %res = (action
=> lc($format));
1466 # feed links are possible only for project views
1467 return unless (defined $project);
1468 # some views should link to OPML, or to generic project feed,
1469 # or don't have specific feed yet (so they should use generic)
1470 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1473 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1474 # from tag links; this also makes possible to detect branch links
1475 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1476 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1479 # find log type for feed description (title)
1481 if (defined $file_name) {
1482 $type = "history of $file_name";
1483 $type .= "/" if ($action eq 'tree');
1484 $type .= " on '$branch'" if (defined $branch);
1486 $type = "log of $branch" if (defined $branch);
1489 $res{-title
} = $type;
1490 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1491 $res{'file_name'} = $file_name;
1496 ## ----------------------------------------------------------------------
1497 ## git utility subroutines, invoking git commands
1499 # returns path to the core git executable and the --git-dir parameter as list
1501 return $GIT, '--git-dir='.$git_dir;
1504 # returns path to the core git executable and the --git-dir parameter as string
1506 return join(' ', git_cmd
());
1509 # get HEAD ref of given project as hash
1510 sub git_get_head_hash
{
1511 my $project = shift;
1512 my $o_git_dir = $git_dir;
1514 $git_dir = "$projectroot/$project";
1515 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1518 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1522 if (defined $o_git_dir) {
1523 $git_dir = $o_git_dir;
1528 # get type of given object
1532 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1534 close $fd or return;
1539 # repository configuration
1540 our $config_file = '';
1543 # store multiple values for single key as anonymous array reference
1544 # single values stored directly in the hash, not as [ <value> ]
1545 sub hash_set_multi
{
1546 my ($hash, $key, $value) = @_;
1548 if (!exists $hash->{$key}) {
1549 $hash->{$key} = $value;
1550 } elsif (!ref $hash->{$key}) {
1551 $hash->{$key} = [ $hash->{$key}, $value ];
1553 push @{$hash->{$key}}, $value;
1557 # return hash of git project configuration
1558 # optionally limited to some section, e.g. 'gitweb'
1559 sub git_parse_project_config
{
1560 my $section_regexp = shift;
1565 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1568 while (my $keyval = <$fh>) {
1570 my ($key, $value) = split(/\n/, $keyval, 2);
1572 hash_set_multi
(\
%config, $key, $value)
1573 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1580 # convert config value to boolean, 'true' or 'false'
1581 # no value, number > 0, 'true' and 'yes' values are true
1582 # rest of values are treated as false (never as error)
1583 sub config_to_bool
{
1586 # strip leading and trailing whitespace
1590 return (!defined $val || # section.key
1591 ($val =~ /^\d+$/ && $val) || # section.key = 1
1592 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1595 # convert config value to simple decimal number
1596 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1597 # to be multiplied by 1024, 1048576, or 1073741824
1601 # strip leading and trailing whitespace
1605 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1607 # unknown unit is treated as 1
1608 return $num * ($unit eq 'g' ? 1073741824 :
1609 $unit eq 'm' ? 1048576 :
1610 $unit eq 'k' ? 1024 : 1);
1615 # convert config value to array reference, if needed
1616 sub config_to_multi
{
1619 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1622 sub git_get_project_config
{
1623 my ($key, $type) = @_;
1626 return unless ($key);
1627 $key =~ s/^gitweb\.//;
1628 return if ($key =~ m/\W/);
1631 if (defined $type) {
1634 unless ($type eq 'bool' || $type eq 'int');
1638 if (!defined $config_file ||
1639 $config_file ne "$git_dir/config") {
1640 %config = git_parse_project_config
('gitweb');
1641 $config_file = "$git_dir/config";
1645 if (!defined $type) {
1646 return $config{"gitweb.$key"};
1647 } elsif ($type eq 'bool') {
1648 # backward compatibility: 'git config --bool' returns true/false
1649 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1650 } elsif ($type eq 'int') {
1651 return config_to_int
($config{"gitweb.$key"});
1653 return $config{"gitweb.$key"};
1656 # get hash of given path at given ref
1657 sub git_get_hash_by_path
{
1659 my $path = shift || return undef;
1664 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1665 or die_error
(undef, "Open git-ls-tree failed");
1667 close $fd or return undef;
1669 if (!defined $line) {
1670 # there is no tree or hash given by $path at $base
1674 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1675 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1676 if (defined $type && $type ne $2) {
1677 # type doesn't match
1683 # get path of entry with given hash at given tree-ish (ref)
1684 # used to get 'from' filename for combined diff (merge commit) for renames
1685 sub git_get_path_by_hash
{
1686 my $base = shift || return;
1687 my $hash = shift || return;
1691 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1693 while (my $line = <$fd>) {
1696 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1697 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1698 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1707 ## ......................................................................
1708 ## git utility functions, directly accessing git repository
1710 sub git_get_project_description
{
1713 $git_dir = "$projectroot/$path";
1714 open my $fd, "$git_dir/description"
1715 or return git_get_project_config
('description');
1718 if (defined $descr) {
1724 sub git_get_project_url_list
{
1727 $git_dir = "$projectroot/$path";
1728 open my $fd, "$git_dir/cloneurl"
1729 or return wantarray ?
1730 @{ config_to_multi
(git_get_project_config
('url')) } :
1731 config_to_multi
(git_get_project_config
('url'));
1732 my @git_project_url_list = map { chomp; $_ } <$fd>;
1735 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1738 sub git_get_projects_list
{
1743 $filter =~ s/\.git$//;
1745 my ($check_forks) = gitweb_check_feature
('forks');
1747 if (-d
$projects_list) {
1748 # search in directory
1749 my $dir = $projects_list . ($filter ? "/$filter" : '');
1750 # remove the trailing "/"
1752 my $pfxlen = length("$dir");
1753 my $pfxdepth = ($dir =~ tr!/!!);
1756 follow_fast
=> 1, # follow symbolic links
1757 follow_skip
=> 2, # ignore duplicates
1758 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1760 # skip project-list toplevel, if we get it.
1761 return if (m!^[/.]$!);
1762 # only directories can be git repositories
1763 return unless (-d
$_);
1764 # don't traverse too deep (Find is super slow on os x)
1765 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1766 $File::Find
::prune
= 1;
1770 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1771 # we check related file in $projectroot
1772 if ($check_forks and $subdir =~ m
#/.#) {
1773 $File::Find
::prune
= 1;
1774 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1775 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1776 $File::Find
::prune
= 1;
1781 } elsif (-f
$projects_list) {
1782 # read from file(url-encoded):
1783 # 'git%2Fgit.git Linus+Torvalds'
1784 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1785 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1787 open my ($fd), $projects_list or return;
1789 while (my $line = <$fd>) {
1791 my ($path, $owner) = split ' ', $line;
1792 $path = unescape
($path);
1793 $owner = unescape
($owner);
1794 if (!defined $path) {
1797 if ($filter ne '') {
1798 # looking for forks;
1799 my $pfx = substr($path, 0, length($filter));
1800 if ($pfx ne $filter) {
1803 my $sfx = substr($path, length($filter));
1804 if ($sfx !~ /^\/.*\
.git
$/) {
1807 } elsif ($check_forks) {
1809 foreach my $filter (keys %paths) {
1810 # looking for forks;
1811 my $pfx = substr($path, 0, length($filter));
1812 if ($pfx ne $filter) {
1815 my $sfx = substr($path, length($filter));
1816 if ($sfx !~ /^\/.*\
.git
$/) {
1819 # is a fork, don't include it in
1824 if (check_export_ok
("$projectroot/$path")) {
1827 owner
=> to_utf8
($owner),
1830 (my $forks_path = $path) =~ s/\.git$//;
1831 $paths{$forks_path}++;
1839 our $gitweb_project_owner = undef;
1840 sub git_get_project_list_from_file
{
1842 return if (defined $gitweb_project_owner);
1844 $gitweb_project_owner = {};
1845 # read from file (url-encoded):
1846 # 'git%2Fgit.git Linus+Torvalds'
1847 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1848 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1849 if (-f
$projects_list) {
1850 open (my $fd , $projects_list);
1851 while (my $line = <$fd>) {
1853 my ($pr, $ow) = split ' ', $line;
1854 $pr = unescape
($pr);
1855 $ow = unescape
($ow);
1856 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1862 sub git_get_project_owner
{
1863 my $project = shift;
1866 return undef unless $project;
1867 $git_dir = "$projectroot/$project";
1869 if (!defined $gitweb_project_owner) {
1870 git_get_project_list_from_file
();
1873 if (exists $gitweb_project_owner->{$project}) {
1874 $owner = $gitweb_project_owner->{$project};
1876 if (!defined $owner){
1877 $owner = git_get_project_config
('owner');
1879 if (!defined $owner) {
1880 $owner = get_file_owner
("$git_dir");
1886 sub git_get_last_activity
{
1890 $git_dir = "$projectroot/$path";
1891 open($fd, "-|", git_cmd
(), 'for-each-ref',
1892 '--format=%(committer)',
1893 '--sort=-committerdate',
1895 'refs/heads') or return;
1896 my $most_recent = <$fd>;
1897 close $fd or return;
1898 if (defined $most_recent &&
1899 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1901 my $age = time - $timestamp;
1902 return ($age, age_string
($age));
1904 return (undef, undef);
1907 sub git_get_references
{
1908 my $type = shift || "";
1910 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1911 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1912 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1913 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1916 while (my $line = <$fd>) {
1918 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1919 if (defined $refs{$1}) {
1920 push @{$refs{$1}}, $2;
1926 close $fd or return;
1930 sub git_get_rev_name_tags
{
1931 my $hash = shift || return undef;
1933 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1935 my $name_rev = <$fd>;
1938 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1941 # catches also '$hash undefined' output
1946 ## ----------------------------------------------------------------------
1947 ## parse to hash functions
1951 my $tz = shift || "-0000";
1954 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1955 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1956 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1957 $date{'hour'} = $hour;
1958 $date{'minute'} = $min;
1959 $date{'mday'} = $mday;
1960 $date{'day'} = $days[$wday];
1961 $date{'month'} = $months[$mon];
1962 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1963 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1964 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1965 $mday, $months[$mon], $hour ,$min;
1966 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1967 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
1969 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1970 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1971 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1972 $date{'hour_local'} = $hour;
1973 $date{'minute_local'} = $min;
1974 $date{'tz_local'} = $tz;
1975 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1976 1900+$year, $mon+1, $mday,
1977 $hour, $min, $sec, $tz);
1986 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1987 $tag{'id'} = $tag_id;
1988 while (my $line = <$fd>) {
1990 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1991 $tag{'object'} = $1;
1992 } elsif ($line =~ m/^type (.+)$/) {
1994 } elsif ($line =~ m/^tag (.+)$/) {
1996 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1997 $tag{'author'} = $1;
2000 } elsif ($line =~ m/--BEGIN/) {
2001 push @comment, $line;
2003 } elsif ($line eq "") {
2007 push @comment, <$fd>;
2008 $tag{'comment'} = \
@comment;
2009 close $fd or return;
2010 if (!defined $tag{'name'}) {
2016 sub parse_commit_text
{
2017 my ($commit_text, $withparents) = @_;
2018 my @commit_lines = split '\n', $commit_text;
2021 pop @commit_lines; # Remove '\0'
2023 if (! @commit_lines) {
2027 my $header = shift @commit_lines;
2028 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2031 ($co{'id'}, my @parents) = split ' ', $header;
2032 while (my $line = shift @commit_lines) {
2033 last if $line eq "\n";
2034 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2036 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2038 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2040 $co{'author_epoch'} = $2;
2041 $co{'author_tz'} = $3;
2042 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2043 $co{'author_name'} = $1;
2044 $co{'author_email'} = $2;
2046 $co{'author_name'} = $co{'author'};
2048 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2049 $co{'committer'} = $1;
2050 $co{'committer_epoch'} = $2;
2051 $co{'committer_tz'} = $3;
2052 $co{'committer_name'} = $co{'committer'};
2053 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2054 $co{'committer_name'} = $1;
2055 $co{'committer_email'} = $2;
2057 $co{'committer_name'} = $co{'committer'};
2061 if (!defined $co{'tree'}) {
2064 $co{'parents'} = \
@parents;
2065 $co{'parent'} = $parents[0];
2067 foreach my $title (@commit_lines) {
2070 $co{'title'} = chop_str
($title, 80, 5);
2071 # remove leading stuff of merges to make the interesting part visible
2072 if (length($title) > 50) {
2073 $title =~ s/^Automatic //;
2074 $title =~ s/^merge (of|with) /Merge ... /i;
2075 if (length($title) > 50) {
2076 $title =~ s/(http|rsync):\/\///;
2078 if (length($title) > 50) {
2079 $title =~ s/(master|www|rsync)\.//;
2081 if (length($title) > 50) {
2082 $title =~ s/kernel.org:?//;
2084 if (length($title) > 50) {
2085 $title =~ s/\/pub\/scm//;
2088 $co{'title_short'} = chop_str
($title, 50, 5);
2092 if ($co{'title'} eq "") {
2093 $co{'title'} = $co{'title_short'} = '(no commit message)';
2095 # remove added spaces
2096 foreach my $line (@commit_lines) {
2099 $co{'comment'} = \
@commit_lines;
2101 my $age = time - $co{'committer_epoch'};
2103 $co{'age_string'} = age_string
($age);
2104 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2105 if ($age > 60*60*24*7*2) {
2106 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2107 $co{'age_string_age'} = $co{'age_string'};
2109 $co{'age_string_date'} = $co{'age_string'};
2110 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2116 my ($commit_id) = @_;
2121 open my $fd, "-|", git_cmd
(), "rev-list",
2127 or die_error
(undef, "Open git-rev-list failed");
2128 %co = parse_commit_text
(<$fd>, 1);
2135 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2143 open my $fd, "-|", git_cmd
(), "rev-list",
2146 ("--max-count=" . $maxcount),
2147 ("--skip=" . $skip),
2151 ($filename ? ($filename) : ())
2152 or die_error
(undef, "Open git-rev-list failed");
2153 while (my $line = <$fd>) {
2154 my %co = parse_commit_text
($line);
2159 return wantarray ? @cos : \
@cos;
2162 # parse ref from ref_file, given by ref_id, with given type
2164 my $ref_file = shift;
2166 my $type = shift || git_get_type
($ref_id);
2169 $ref_item{'type'} = $type;
2170 $ref_item{'id'} = $ref_id;
2171 $ref_item{'epoch'} = 0;
2172 $ref_item{'age'} = "unknown";
2173 if ($type eq "tag") {
2174 my %tag = parse_tag
($ref_id);
2175 $ref_item{'comment'} = $tag{'comment'};
2176 if ($tag{'type'} eq "commit") {
2177 my %co = parse_commit
($tag{'object'});
2178 $ref_item{'epoch'} = $co{'committer_epoch'};
2179 $ref_item{'age'} = $co{'age_string'};
2180 } elsif (defined($tag{'epoch'})) {
2181 my $age = time - $tag{'epoch'};
2182 $ref_item{'epoch'} = $tag{'epoch'};
2183 $ref_item{'age'} = age_string
($age);
2185 $ref_item{'reftype'} = $tag{'type'};
2186 $ref_item{'name'} = $tag{'name'};
2187 $ref_item{'refid'} = $tag{'object'};
2188 } elsif ($type eq "commit"){
2189 my %co = parse_commit
($ref_id);
2190 $ref_item{'reftype'} = "commit";
2191 $ref_item{'name'} = $ref_file;
2192 $ref_item{'title'} = $co{'title'};
2193 $ref_item{'refid'} = $ref_id;
2194 $ref_item{'epoch'} = $co{'committer_epoch'};
2195 $ref_item{'age'} = $co{'age_string'};
2197 $ref_item{'reftype'} = $type;
2198 $ref_item{'name'} = $ref_file;
2199 $ref_item{'refid'} = $ref_id;
2205 # parse line of git-diff-tree "raw" output
2206 sub parse_difftree_raw_line
{
2210 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2211 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2212 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2213 $res{'from_mode'} = $1;
2214 $res{'to_mode'} = $2;
2215 $res{'from_id'} = $3;
2217 $res{'status'} = $5;
2218 $res{'similarity'} = $6;
2219 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2220 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2222 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2225 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2226 # combined diff (for merge commit)
2227 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2228 $res{'nparents'} = length($1);
2229 $res{'from_mode'} = [ split(' ', $2) ];
2230 $res{'to_mode'} = pop @{$res{'from_mode'}};
2231 $res{'from_id'} = [ split(' ', $3) ];
2232 $res{'to_id'} = pop @{$res{'from_id'}};
2233 $res{'status'} = [ split('', $4) ];
2234 $res{'to_file'} = unquote
($5);
2236 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2237 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2238 $res{'commit'} = $1;
2241 return wantarray ? %res : \
%res;
2244 # wrapper: return parsed line of git-diff-tree "raw" output
2245 # (the argument might be raw line, or parsed info)
2246 sub parsed_difftree_line
{
2247 my $line_or_ref = shift;
2249 if (ref($line_or_ref) eq "HASH") {
2250 # pre-parsed (or generated by hand)
2251 return $line_or_ref;
2253 return parse_difftree_raw_line
($line_or_ref);
2257 # parse line of git-ls-tree output
2258 sub parse_ls_tree_line
($;%) {
2263 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2264 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2272 $res{'name'} = unquote
($4);
2275 return wantarray ? %res : \
%res;
2278 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2279 sub parse_from_to_diffinfo
{
2280 my ($diffinfo, $from, $to, @parents) = @_;
2282 if ($diffinfo->{'nparents'}) {
2284 $from->{'file'} = [];
2285 $from->{'href'} = [];
2286 fill_from_file_info
($diffinfo, @parents)
2287 unless exists $diffinfo->{'from_file'};
2288 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2289 $from->{'file'}[$i] =
2290 defined $diffinfo->{'from_file'}[$i] ?
2291 $diffinfo->{'from_file'}[$i] :
2292 $diffinfo->{'to_file'};
2293 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2294 $from->{'href'}[$i] = href
(action
=>"blob",
2295 hash_base
=>$parents[$i],
2296 hash
=>$diffinfo->{'from_id'}[$i],
2297 file_name
=>$from->{'file'}[$i]);
2299 $from->{'href'}[$i] = undef;
2303 # ordinary (not combined) diff
2304 $from->{'file'} = $diffinfo->{'from_file'};
2305 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2306 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2307 hash
=>$diffinfo->{'from_id'},
2308 file_name
=>$from->{'file'});
2310 delete $from->{'href'};
2314 $to->{'file'} = $diffinfo->{'to_file'};
2315 if (!is_deleted
($diffinfo)) { # file exists in result
2316 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2317 hash
=>$diffinfo->{'to_id'},
2318 file_name
=>$to->{'file'});
2320 delete $to->{'href'};
2324 ## ......................................................................
2325 ## parse to array of hashes functions
2327 sub git_get_heads_list
{
2331 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2332 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2333 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2336 while (my $line = <$fd>) {
2340 my ($refinfo, $committerinfo) = split(/\0/, $line);
2341 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2342 my ($committer, $epoch, $tz) =
2343 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2344 $ref_item{'fullname'} = $name;
2345 $name =~ s!^refs/heads/!!;
2347 $ref_item{'name'} = $name;
2348 $ref_item{'id'} = $hash;
2349 $ref_item{'title'} = $title || '(no commit message)';
2350 $ref_item{'epoch'} = $epoch;
2352 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2354 $ref_item{'age'} = "unknown";
2357 push @headslist, \
%ref_item;
2361 return wantarray ? @headslist : \
@headslist;
2364 sub git_get_tags_list
{
2368 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2369 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2370 '--format=%(objectname) %(objecttype) %(refname) '.
2371 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2374 while (my $line = <$fd>) {
2378 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2379 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2380 my ($creator, $epoch, $tz) =
2381 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2382 $ref_item{'fullname'} = $name;
2383 $name =~ s!^refs/tags/!!;
2385 $ref_item{'type'} = $type;
2386 $ref_item{'id'} = $id;
2387 $ref_item{'name'} = $name;
2388 if ($type eq "tag") {
2389 $ref_item{'subject'} = $title;
2390 $ref_item{'reftype'} = $reftype;
2391 $ref_item{'refid'} = $refid;
2393 $ref_item{'reftype'} = $type;
2394 $ref_item{'refid'} = $id;
2397 if ($type eq "tag" || $type eq "commit") {
2398 $ref_item{'epoch'} = $epoch;
2400 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2402 $ref_item{'age'} = "unknown";
2406 push @tagslist, \
%ref_item;
2410 return wantarray ? @tagslist : \
@tagslist;
2413 ## ----------------------------------------------------------------------
2414 ## filesystem-related functions
2416 sub get_file_owner
{
2419 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2420 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2421 if (!defined $gcos) {
2425 $owner =~ s/[,;].*$//;
2426 return to_utf8
($owner);
2429 ## ......................................................................
2430 ## mimetype related functions
2432 sub mimetype_guess_file
{
2433 my $filename = shift;
2434 my $mimemap = shift;
2435 -r
$mimemap or return undef;
2438 open(MIME
, $mimemap) or return undef;
2440 next if m/^#/; # skip comments
2441 my ($mime, $exts) = split(/\t+/);
2442 if (defined $exts) {
2443 my @exts = split(/\s+/, $exts);
2444 foreach my $ext (@exts) {
2445 $mimemap{$ext} = $mime;
2451 $filename =~ /\.([^.]*)$/;
2452 return $mimemap{$1};
2455 sub mimetype_guess
{
2456 my $filename = shift;
2458 $filename =~ /\./ or return undef;
2460 if ($mimetypes_file) {
2461 my $file = $mimetypes_file;
2462 if ($file !~ m!^/!) { # if it is relative path
2463 # it is relative to project
2464 $file = "$projectroot/$project/$file";
2466 $mime = mimetype_guess_file
($filename, $file);
2468 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2474 my $filename = shift;
2477 my $mime = mimetype_guess
($filename);
2478 $mime and return $mime;
2482 return $default_blob_plain_mimetype unless $fd;
2485 return 'text/plain' .
2486 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2487 } elsif (! $filename) {
2488 return 'application/octet-stream';
2489 } elsif ($filename =~ m/\.png$/i) {
2491 } elsif ($filename =~ m/\.gif$/i) {
2493 } elsif ($filename =~ m/\.jpe?g$/i) {
2494 return 'image/jpeg';
2496 return 'application/octet-stream';
2500 ## ======================================================================
2501 ## functions printing HTML: header, footer, error page
2503 sub git_header_html
{
2504 my $status = shift || "200 OK";
2505 my $expires = shift;
2507 my $title = "$site_name";
2508 if (defined $project) {
2509 $title .= " - " . to_utf8
($project);
2510 if (defined $action) {
2511 $title .= "/$action";
2512 if (defined $file_name) {
2513 $title .= " - " . esc_path
($file_name);
2514 if ($action eq "tree" && $file_name !~ m
|/$|) {
2521 # require explicit support from the UA if we are to send the page as
2522 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2523 # we have to do this because MSIE sometimes globs '*/*', pretending to
2524 # support xhtml+xml but choking when it gets what it asked for.
2525 if (defined $cgi->http('HTTP_ACCEPT') &&
2526 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2527 $cgi->Accept('application/xhtml+xml') != 0) {
2528 $content_type = 'application/xhtml+xml';
2530 $content_type = 'text/html';
2532 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2533 -status
=> $status, -expires
=> $expires);
2534 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2536 <?xml version="1.0" encoding="utf-8"?>
2537 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2538 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2539 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2540 <!-- git core binaries version $git_version -->
2542 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2543 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2544 <meta name="robots" content="index, nofollow"/>
2545 <title>$title</title>
2547 # print out each stylesheet that exist
2548 if (defined $stylesheet) {
2549 #provides backwards capability for those people who define style sheet in a config file
2550 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2552 foreach my $stylesheet (@stylesheets) {
2553 next unless $stylesheet;
2554 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2557 if (defined $project) {
2558 my %href_params = get_feed_info
();
2559 if (!exists $href_params{'-title'}) {
2560 $href_params{'-title'} = 'log';
2563 foreach my $format qw(RSS Atom) {
2564 my $type = lc($format);
2566 '-rel' => 'alternate',
2567 '-title' => "$project - $href_params{'-title'} - $format feed",
2568 '-type' => "application/$type+xml"
2571 $href_params{'action'} = $type;
2572 $link_attr{'-href'} = href
(%href_params);
2574 "rel=\"$link_attr{'-rel'}\" ".
2575 "title=\"$link_attr{'-title'}\" ".
2576 "href=\"$link_attr{'-href'}\" ".
2577 "type=\"$link_attr{'-type'}\" ".
2580 $href_params{'extra_options'} = '--no-merges';
2581 $link_attr{'-href'} = href
(%href_params);
2582 $link_attr{'-title'} .= ' (no merges)';
2584 "rel=\"$link_attr{'-rel'}\" ".
2585 "title=\"$link_attr{'-title'}\" ".
2586 "href=\"$link_attr{'-href'}\" ".
2587 "type=\"$link_attr{'-type'}\" ".
2592 printf('<link rel="alternate" title="%s projects list" '.
2593 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2594 $site_name, href
(project
=>undef, action
=>"project_index"));
2595 printf('<link rel="alternate" title="%s projects feeds" '.
2596 'href="%s" type="text/x-opml" />'."\n",
2597 $site_name, href
(project
=>undef, action
=>"opml"));
2599 if (defined $favicon) {
2600 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2606 if (-f
$site_header) {
2607 open (my $fd, $site_header);
2612 print "<div class=\"page_header\">\n" .
2613 $cgi->a({-href
=> esc_url
($logo_url),
2614 -title
=> $logo_label},
2615 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2616 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2617 if (defined $project) {
2618 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2619 if (defined $action) {
2626 my ($have_search) = gitweb_check_feature
('search');
2627 if (defined $project && $have_search) {
2628 if (!defined $searchtext) {
2632 if (defined $hash_base) {
2633 $search_hash = $hash_base;
2634 } elsif (defined $hash) {
2635 $search_hash = $hash;
2637 $search_hash = "HEAD";
2639 my $action = $my_uri;
2640 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2641 if ($use_pathinfo) {
2642 $action .= "/".esc_url
($project);
2644 print $cgi->startform(-method => "get", -action
=> $action) .
2645 "<div class=\"search\">\n" .
2647 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2648 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2649 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2650 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2651 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2652 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2654 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2655 "<span title=\"Extended regular expression\">" .
2656 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2657 -checked
=> $search_use_regexp) .
2660 $cgi->end_form() . "\n";
2664 sub git_footer_html
{
2665 my $feed_class = 'rss_logo';
2667 print "<div class=\"page_footer\">\n";
2668 if (defined $project) {
2669 my $descr = git_get_project_description
($project);
2670 if (defined $descr) {
2671 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2674 my %href_params = get_feed_info
();
2675 if (!%href_params) {
2676 $feed_class .= ' generic';
2678 $href_params{'-title'} ||= 'log';
2680 foreach my $format qw(RSS Atom) {
2681 $href_params{'action'} = lc($format);
2682 print $cgi->a({-href
=> href
(%href_params),
2683 -title
=> "$href_params{'-title'} $format feed",
2684 -class => $feed_class}, $format)."\n";
2688 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2689 -class => $feed_class}, "OPML") . " ";
2690 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2691 -class => $feed_class}, "TXT") . "\n";
2693 print "</div>\n"; # class="page_footer"
2695 if (-f
$site_footer) {
2696 open (my $fd, $site_footer);
2706 my $status = shift || "403 Forbidden";
2707 my $error = shift || "Malformed query, file missing or permission denied";
2709 git_header_html
($status);
2711 <div class="page_body">
2721 ## ----------------------------------------------------------------------
2722 ## functions printing or outputting HTML: navigation
2724 sub git_print_page_nav
{
2725 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2726 $extra = '' if !defined $extra; # pager or formats
2728 my @navs = qw(summary shortlog log commit commitdiff tree);
2730 @navs = grep { $_ ne $suppress } @navs;
2733 my %arg = map { $_ => {action
=>$_} } @navs;
2734 if (defined $head) {
2735 for (qw(commit commitdiff)) {
2736 $arg{$_}{'hash'} = $head;
2738 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2739 for (qw(shortlog log)) {
2740 $arg{$_}{'hash'} = $head;
2744 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2745 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2747 print "<div class=\"page_nav\">\n" .
2749 map { $_ eq $current ?
2750 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2752 print "<br/>\n$extra<br/>\n" .
2756 sub format_paging_nav
{
2757 my ($action, $hash, $head, $page, $has_next_link) = @_;
2761 if ($hash ne $head || $page) {
2762 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2764 $paging_nav .= "HEAD";
2768 $paging_nav .= " ⋅ " .
2769 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2770 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2772 $paging_nav .= " ⋅ prev";
2775 if ($has_next_link) {
2776 $paging_nav .= " ⋅ " .
2777 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2778 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2780 $paging_nav .= " ⋅ next";
2786 ## ......................................................................
2787 ## functions printing or outputting HTML: div
2789 sub git_print_header_div
{
2790 my ($action, $title, $hash, $hash_base) = @_;
2793 $args{'action'} = $action;
2794 $args{'hash'} = $hash if $hash;
2795 $args{'hash_base'} = $hash_base if $hash_base;
2797 print "<div class=\"header\">\n" .
2798 $cgi->a({-href
=> href
(%args), -class => "title"},
2799 $title ? $title : $action) .
2803 #sub git_print_authorship (\%) {
2804 sub git_print_authorship
{
2807 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2808 print "<div class=\"author_date\">" .
2809 esc_html
($co->{'author_name'}) .
2811 if ($ad{'hour_local'} < 6) {
2812 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2813 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2815 printf(" (%02d:%02d %s)",
2816 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2821 sub git_print_page_path
{
2827 print "<div class=\"page_path\">";
2828 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2829 -title
=> 'tree root'}, to_utf8
("[$project]"));
2831 if (defined $name) {
2832 my @dirname = split '/', $name;
2833 my $basename = pop @dirname;
2836 foreach my $dir (@dirname) {
2837 $fullname .= ($fullname ? '/' : '') . $dir;
2838 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2840 -title
=> $fullname}, esc_path
($dir));
2843 if (defined $type && $type eq 'blob') {
2844 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2846 -title
=> $name}, esc_path
($basename));
2847 } elsif (defined $type && $type eq 'tree') {
2848 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2850 -title
=> $name}, esc_path
($basename));
2853 print esc_path
($basename);
2856 print "<br/></div>\n";
2859 # sub git_print_log (\@;%) {
2860 sub git_print_log
($;%) {
2864 if ($opts{'-remove_title'}) {
2865 # remove title, i.e. first line of log
2868 # remove leading empty lines
2869 while (defined $log->[0] && $log->[0] eq "") {
2876 foreach my $line (@$log) {
2877 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2880 if (! $opts{'-remove_signoff'}) {
2881 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2884 # remove signoff lines
2891 # print only one empty line
2892 # do not print empty line after signoff
2894 next if ($empty || $signoff);
2900 print format_log_line_html
($line) . "<br/>\n";
2903 if ($opts{'-final_empty_line'}) {
2904 # end with single empty line
2905 print "<br/>\n" unless $empty;
2909 # return link target (what link points to)
2910 sub git_get_link_target
{
2915 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2919 $link_target = <$fd>;
2924 return $link_target;
2927 # given link target, and the directory (basedir) the link is in,
2928 # return target of link relative to top directory (top tree);
2929 # return undef if it is not possible (including absolute links).
2930 sub normalize_link_target
{
2931 my ($link_target, $basedir, $hash_base) = @_;
2933 # we can normalize symlink target only if $hash_base is provided
2934 return unless $hash_base;
2936 # absolute symlinks (beginning with '/') cannot be normalized
2937 return if (substr($link_target, 0, 1) eq '/');
2939 # normalize link target to path from top (root) tree (dir)
2942 $path = $basedir . '/' . $link_target;
2944 # we are in top (root) tree (dir)
2945 $path = $link_target;
2948 # remove //, /./, and /../
2950 foreach my $part (split('/', $path)) {
2951 # discard '.' and ''
2952 next if (!$part || $part eq '.');
2954 if ($part eq '..') {
2958 # link leads outside repository (outside top dir)
2962 push @path_parts, $part;
2965 $path = join('/', @path_parts);
2970 # print tree entry (row of git_tree), but without encompassing <tr> element
2971 sub git_print_tree_entry
{
2972 my ($t, $basedir, $hash_base, $have_blame) = @_;
2975 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2977 # The format of a table row is: mode list link. Where mode is
2978 # the mode of the entry, list is the name of the entry, an href,
2979 # and link is the action links of the entry.
2981 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2982 if ($t->{'type'} eq "blob") {
2983 print "<td class=\"list\">" .
2984 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2985 file_name
=>"$basedir$t->{'name'}", %base_key),
2986 -class => "list"}, esc_path
($t->{'name'}));
2987 if (S_ISLNK
(oct $t->{'mode'})) {
2988 my $link_target = git_get_link_target
($t->{'hash'});
2990 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2991 if (defined $norm_target) {
2993 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2994 file_name
=>$norm_target),
2995 -title
=> $norm_target}, esc_path
($link_target));
2997 print " -> " . esc_path
($link_target);
3002 print "<td class=\"link\">";
3003 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3004 file_name
=>"$basedir$t->{'name'}", %base_key)},
3008 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3009 file_name
=>"$basedir$t->{'name'}", %base_key)},
3012 if (defined $hash_base) {
3014 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3015 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3019 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3020 file_name
=>"$basedir$t->{'name'}")},
3024 } elsif ($t->{'type'} eq "tree") {
3025 print "<td class=\"list\">";
3026 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3027 file_name
=>"$basedir$t->{'name'}", %base_key)},
3028 esc_path
($t->{'name'}));
3030 print "<td class=\"link\">";
3031 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3032 file_name
=>"$basedir$t->{'name'}", %base_key)},
3034 if (defined $hash_base) {
3036 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3037 file_name
=>"$basedir$t->{'name'}")},
3042 # unknown object: we can only present history for it
3043 # (this includes 'commit' object, i.e. submodule support)
3044 print "<td class=\"list\">" .
3045 esc_path
($t->{'name'}) .
3047 print "<td class=\"link\">";
3048 if (defined $hash_base) {
3049 print $cgi->a({-href
=> href
(action
=>"history",
3050 hash_base
=>$hash_base,
3051 file_name
=>"$basedir$t->{'name'}")},
3058 ## ......................................................................
3059 ## functions printing large fragments of HTML
3061 # get pre-image filenames for merge (combined) diff
3062 sub fill_from_file_info
{
3063 my ($diff, @parents) = @_;
3065 $diff->{'from_file'} = [ ];
3066 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3067 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3068 if ($diff->{'status'}[$i] eq 'R' ||
3069 $diff->{'status'}[$i] eq 'C') {
3070 $diff->{'from_file'}[$i] =
3071 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3078 # is current raw difftree line of file deletion
3080 my $diffinfo = shift;
3082 return $diffinfo->{'to_id'} eq ('0' x
40);
3085 # does patch correspond to [previous] difftree raw line
3086 # $diffinfo - hashref of parsed raw diff format
3087 # $patchinfo - hashref of parsed patch diff format
3088 # (the same keys as in $diffinfo)
3089 sub is_patch_split
{
3090 my ($diffinfo, $patchinfo) = @_;
3092 return defined $diffinfo && defined $patchinfo
3093 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3097 sub git_difftree_body
{
3098 my ($difftree, $hash, @parents) = @_;
3099 my ($parent) = $parents[0];
3100 my ($have_blame) = gitweb_check_feature
('blame');
3101 print "<div class=\"list_head\">\n";
3102 if ($#{$difftree} > 10) {
3103 print(($#{$difftree} + 1) . " files changed:\n");
3107 print "<table class=\"" .
3108 (@parents > 1 ? "combined " : "") .
3111 # header only for combined diff in 'commitdiff' view
3112 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3115 print "<thead><tr>\n" .
3116 "<th></th><th></th>\n"; # filename, patchN link
3117 for (my $i = 0; $i < @parents; $i++) {
3118 my $par = $parents[$i];
3120 $cgi->a({-href
=> href
(action
=>"commitdiff",
3121 hash
=>$hash, hash_parent
=>$par),
3122 -title
=> 'commitdiff to parent number ' .
3123 ($i+1) . ': ' . substr($par,0,7)},
3127 print "</tr></thead>\n<tbody>\n";
3132 foreach my $line (@{$difftree}) {
3133 my $diff = parsed_difftree_line
($line);
3136 print "<tr class=\"dark\">\n";
3138 print "<tr class=\"light\">\n";
3142 if (exists $diff->{'nparents'}) { # combined diff
3144 fill_from_file_info
($diff, @parents)
3145 unless exists $diff->{'from_file'};
3147 if (!is_deleted
($diff)) {
3148 # file exists in the result (child) commit
3150 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3151 file_name
=>$diff->{'to_file'},
3153 -class => "list"}, esc_path
($diff->{'to_file'})) .
3157 esc_path
($diff->{'to_file'}) .
3161 if ($action eq 'commitdiff') {
3164 print "<td class=\"link\">" .
3165 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3170 my $has_history = 0;
3171 my $not_deleted = 0;
3172 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3173 my $hash_parent = $parents[$i];
3174 my $from_hash = $diff->{'from_id'}[$i];
3175 my $from_path = $diff->{'from_file'}[$i];
3176 my $status = $diff->{'status'}[$i];
3178 $has_history ||= ($status ne 'A');
3179 $not_deleted ||= ($status ne 'D');
3181 if ($status eq 'A') {
3182 print "<td class=\"link\" align=\"right\"> | </td>\n";
3183 } elsif ($status eq 'D') {
3184 print "<td class=\"link\">" .
3185 $cgi->a({-href
=> href
(action
=>"blob",
3188 file_name
=>$from_path)},
3192 if ($diff->{'to_id'} eq $from_hash) {
3193 print "<td class=\"link nochange\">";
3195 print "<td class=\"link\">";
3197 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3198 hash
=>$diff->{'to_id'},
3199 hash_parent
=>$from_hash,
3201 hash_parent_base
=>$hash_parent,
3202 file_name
=>$diff->{'to_file'},
3203 file_parent
=>$from_path)},
3209 print "<td class=\"link\">";
3211 print $cgi->a({-href
=> href
(action
=>"blob",
3212 hash
=>$diff->{'to_id'},
3213 file_name
=>$diff->{'to_file'},
3216 print " | " if ($has_history);
3219 print $cgi->a({-href
=> href
(action
=>"history",
3220 file_name
=>$diff->{'to_file'},
3227 next; # instead of 'else' clause, to avoid extra indent
3229 # else ordinary diff
3231 my ($to_mode_oct, $to_mode_str, $to_file_type);
3232 my ($from_mode_oct, $from_mode_str, $from_file_type);
3233 if ($diff->{'to_mode'} ne ('0' x
6)) {
3234 $to_mode_oct = oct $diff->{'to_mode'};
3235 if (S_ISREG
($to_mode_oct)) { # only for regular file
3236 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3238 $to_file_type = file_type
($diff->{'to_mode'});
3240 if ($diff->{'from_mode'} ne ('0' x
6)) {
3241 $from_mode_oct = oct $diff->{'from_mode'};
3242 if (S_ISREG
($to_mode_oct)) { # only for regular file
3243 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3245 $from_file_type = file_type
($diff->{'from_mode'});
3248 if ($diff->{'status'} eq "A") { # created
3249 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3250 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3251 $mode_chng .= "]</span>";
3253 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3254 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3255 -class => "list"}, esc_path
($diff->{'file'}));
3257 print "<td>$mode_chng</td>\n";
3258 print "<td class=\"link\">";
3259 if ($action eq 'commitdiff') {
3262 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3265 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3266 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3270 } elsif ($diff->{'status'} eq "D") { # deleted
3271 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3273 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3274 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3275 -class => "list"}, esc_path
($diff->{'file'}));
3277 print "<td>$mode_chng</td>\n";
3278 print "<td class=\"link\">";
3279 if ($action eq 'commitdiff') {
3282 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3285 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3286 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3289 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3290 file_name
=>$diff->{'file'})},
3293 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3294 file_name
=>$diff->{'file'})},
3298 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3299 my $mode_chnge = "";
3300 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3301 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3302 if ($from_file_type ne $to_file_type) {
3303 $mode_chnge .= " from $from_file_type to $to_file_type";
3305 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3306 if ($from_mode_str && $to_mode_str) {
3307 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3308 } elsif ($to_mode_str) {
3309 $mode_chnge .= " mode: $to_mode_str";
3312 $mode_chnge .= "]</span>\n";
3315 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3316 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3317 -class => "list"}, esc_path
($diff->{'file'}));
3319 print "<td>$mode_chnge</td>\n";
3320 print "<td class=\"link\">";
3321 if ($action eq 'commitdiff') {
3324 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3326 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3327 # "commit" view and modified file (not onlu mode changed)
3328 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3329 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3330 hash_base
=>$hash, hash_parent_base
=>$parent,
3331 file_name
=>$diff->{'file'})},
3335 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3336 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3339 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3340 file_name
=>$diff->{'file'})},
3343 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3344 file_name
=>$diff->{'file'})},
3348 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3349 my %status_name = ('R' => 'moved', 'C' => 'copied');
3350 my $nstatus = $status_name{$diff->{'status'}};
3352 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3353 # mode also for directories, so we cannot use $to_mode_str
3354 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3357 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3358 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3359 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3360 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3361 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3362 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3363 -class => "list"}, esc_path
($diff->{'from_file'})) .
3364 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3365 "<td class=\"link\">";
3366 if ($action eq 'commitdiff') {
3369 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3371 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3372 # "commit" view and modified file (not only pure rename or copy)
3373 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3374 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3375 hash_base
=>$hash, hash_parent_base
=>$parent,
3376 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3380 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3381 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3384 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3385 file_name
=>$diff->{'to_file'})},
3388 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3389 file_name
=>$diff->{'to_file'})},
3393 } # we should not encounter Unmerged (U) or Unknown (X) status
3396 print "</tbody>" if $has_header;
3400 sub git_patchset_body
{
3401 my ($fd, $difftree, $hash, @hash_parents) = @_;
3402 my ($hash_parent) = $hash_parents[0];
3404 my $is_combined = (@hash_parents > 1);
3406 my $patch_number = 0;
3412 print "<div class=\"patchset\">\n";
3414 # skip to first patch
3415 while ($patch_line = <$fd>) {
3418 last if ($patch_line =~ m/^diff /);
3422 while ($patch_line) {
3424 # parse "git diff" header line
3425 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3426 # $1 is from_name, which we do not use
3427 $to_name = unquote
($2);
3428 $to_name =~ s!^b/!!;
3429 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3430 # $1 is 'cc' or 'combined', which we do not use
3431 $to_name = unquote
($2);
3436 # check if current patch belong to current raw line
3437 # and parse raw git-diff line if needed
3438 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3439 # this is continuation of a split patch
3440 print "<div class=\"patch cont\">\n";
3442 # advance raw git-diff output if needed
3443 $patch_idx++ if defined $diffinfo;
3445 # read and prepare patch information
3446 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3448 # compact combined diff output can have some patches skipped
3449 # find which patch (using pathname of result) we are at now;
3451 while ($to_name ne $diffinfo->{'to_file'}) {
3452 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3453 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3454 "</div>\n"; # class="patch"
3459 last if $patch_idx > $#$difftree;
3460 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3464 # modifies %from, %to hashes
3465 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3467 # this is first patch for raw difftree line with $patch_idx index
3468 # we index @$difftree array from 0, but number patches from 1
3469 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3473 #assert($patch_line =~ m/^diff /) if DEBUG;
3474 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3476 # print "git diff" header
3477 print format_git_diff_header_line
($patch_line, $diffinfo,
3480 # print extended diff header
3481 print "<div class=\"diff extended_header\">\n";
3483 while ($patch_line = <$fd>) {
3486 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3488 print format_extended_diff_header_line
($patch_line, $diffinfo,
3491 print "</div>\n"; # class="diff extended_header"
3493 # from-file/to-file diff header
3494 if (! $patch_line) {
3495 print "</div>\n"; # class="patch"
3498 next PATCH
if ($patch_line =~ m/^diff /);
3499 #assert($patch_line =~ m/^---/) if DEBUG;
3501 my $last_patch_line = $patch_line;
3502 $patch_line = <$fd>;
3504 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3506 print format_diff_from_to_header
($last_patch_line, $patch_line,
3507 $diffinfo, \
%from, \
%to,
3512 while ($patch_line = <$fd>) {
3515 next PATCH
if ($patch_line =~ m/^diff /);
3517 print format_diff_line
($patch_line, \
%from, \
%to);
3521 print "</div>\n"; # class="patch"
3524 # for compact combined (--cc) format, with chunk and patch simpliciaction
3525 # patchset might be empty, but there might be unprocessed raw lines
3526 for (++$patch_idx if $patch_number > 0;
3527 $patch_idx < @$difftree;
3529 # read and prepare patch information
3530 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3532 # generate anchor for "patch" links in difftree / whatchanged part
3533 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3534 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3535 "</div>\n"; # class="patch"
3540 if ($patch_number == 0) {
3541 if (@hash_parents > 1) {
3542 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3544 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3548 print "</div>\n"; # class="patchset"
3551 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3553 sub git_project_list_body
{
3554 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3556 my ($check_forks) = gitweb_check_feature
('forks');
3559 foreach my $pr (@$projlist) {
3560 my (@aa) = git_get_last_activity
($pr->{'path'});
3564 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3565 if (!defined $pr->{'descr'}) {
3566 my $descr = git_get_project_description
($pr->{'path'}) || "";
3567 $pr->{'descr_long'} = to_utf8
($descr);
3568 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3570 if (!defined $pr->{'owner'}) {
3571 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3574 my $pname = $pr->{'path'};
3575 if (($pname =~ s/\.git$//) &&
3576 ($pname !~ /\/$/) &&
3577 (-d
"$projectroot/$pname")) {
3578 $pr->{'forks'} = "-d $projectroot/$pname";
3584 push @projects, $pr;
3587 $order ||= $default_projects_order;
3588 $from = 0 unless defined $from;
3589 $to = $#projects if (!defined $to || $#projects < $to);
3591 print "<table class=\"project_list\">\n";
3592 unless ($no_header) {
3595 print "<th></th>\n";
3597 if ($order eq "project") {
3598 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3599 print "<th>Project</th>\n";
3602 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3603 -class => "header"}, "Project") .
3606 if ($order eq "descr") {
3607 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3608 print "<th>Description</th>\n";
3611 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3612 -class => "header"}, "Description") .
3615 if ($order eq "owner") {
3616 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3617 print "<th>Owner</th>\n";
3620 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3621 -class => "header"}, "Owner") .
3624 if ($order eq "age") {
3625 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3626 print "<th>Last Change</th>\n";
3629 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3630 -class => "header"}, "Last Change") .
3633 print "<th></th>\n" .
3637 for (my $i = $from; $i <= $to; $i++) {
3638 my $pr = $projects[$i];
3640 print "<tr class=\"dark\">\n";
3642 print "<tr class=\"light\">\n";
3647 if ($pr->{'forks'}) {
3648 print "<!-- $pr->{'forks'} -->\n";
3649 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3653 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3654 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3655 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3656 -class => "list", -title
=> $pr->{'descr_long'}},
3657 esc_html
($pr->{'descr'})) . "</td>\n" .
3658 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3659 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3660 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3661 "<td class=\"link\">" .
3662 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3663 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3664 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3665 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3666 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3670 if (defined $extra) {
3673 print "<td></td>\n";
3675 print "<td colspan=\"5\">$extra</td>\n" .
3681 sub git_shortlog_body
{
3682 # uses global variable $project
3683 my ($commitlist, $from, $to, $refs, $extra) = @_;
3685 $from = 0 unless defined $from;
3686 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3688 print "<table class=\"shortlog\">\n";
3690 for (my $i = $from; $i <= $to; $i++) {
3691 my %co = %{$commitlist->[$i]};
3692 my $commit = $co{'id'};
3693 my $ref = format_ref_marker
($refs, $commit);
3695 print "<tr class=\"dark\">\n";
3697 print "<tr class=\"light\">\n";
3700 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3701 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3702 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3703 "<td><i>" . $author . "</i></td>\n" .
3705 print format_subject_html
($co{'title'}, $co{'title_short'},
3706 href
(action
=>"commit", hash
=>$commit), $ref);
3708 "<td class=\"link\">" .
3709 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3710 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3711 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3712 my $snapshot_links = format_snapshot_links
($commit);
3713 if (defined $snapshot_links) {
3714 print " | " . $snapshot_links;
3719 if (defined $extra) {
3721 "<td colspan=\"4\">$extra</td>\n" .
3727 sub git_history_body
{
3728 # Warning: assumes constant type (blob or tree) during history
3729 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3731 $from = 0 unless defined $from;
3732 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3734 print "<table class=\"history\">\n";
3736 for (my $i = $from; $i <= $to; $i++) {
3737 my %co = %{$commitlist->[$i]};
3741 my $commit = $co{'id'};
3743 my $ref = format_ref_marker
($refs, $commit);
3746 print "<tr class=\"dark\">\n";
3748 print "<tr class=\"light\">\n";
3751 # shortlog uses chop_str($co{'author_name'}, 10)
3752 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3753 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3754 "<td><i>" . $author . "</i></td>\n" .
3756 # originally git_history used chop_str($co{'title'}, 50)
3757 print format_subject_html
($co{'title'}, $co{'title_short'},
3758 href
(action
=>"commit", hash
=>$commit), $ref);
3760 "<td class=\"link\">" .
3761 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3762 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3764 if ($ftype eq 'blob') {
3765 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3766 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3767 if (defined $blob_current && defined $blob_parent &&
3768 $blob_current ne $blob_parent) {
3770 $cgi->a({-href
=> href
(action
=>"blobdiff",
3771 hash
=>$blob_current, hash_parent
=>$blob_parent,
3772 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3773 file_name
=>$file_name)},
3780 if (defined $extra) {
3782 "<td colspan=\"4\">$extra</td>\n" .
3789 # uses global variable $project
3790 my ($taglist, $from, $to, $extra) = @_;
3791 $from = 0 unless defined $from;
3792 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3794 print "<table class=\"tags\">\n";
3796 for (my $i = $from; $i <= $to; $i++) {
3797 my $entry = $taglist->[$i];
3799 my $comment = $tag{'subject'};
3801 if (defined $comment) {
3802 $comment_short = chop_str
($comment, 30, 5);
3805 print "<tr class=\"dark\">\n";
3807 print "<tr class=\"light\">\n";
3810 if (defined $tag{'age'}) {
3811 print "<td><i>$tag{'age'}</i></td>\n";
3813 print "<td></td>\n";
3816 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3817 -class => "list name"}, esc_html
($tag{'name'})) .
3820 if (defined $comment) {
3821 print format_subject_html
($comment, $comment_short,
3822 href
(action
=>"tag", hash
=>$tag{'id'}));
3825 "<td class=\"selflink\">";
3826 if ($tag{'type'} eq "tag") {
3827 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3832 "<td class=\"link\">" . " | " .
3833 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3834 if ($tag{'reftype'} eq "commit") {
3835 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3836 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3837 } elsif ($tag{'reftype'} eq "blob") {
3838 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3843 if (defined $extra) {
3845 "<td colspan=\"5\">$extra</td>\n" .
3851 sub git_heads_body
{
3852 # uses global variable $project
3853 my ($headlist, $head, $from, $to, $extra) = @_;
3854 $from = 0 unless defined $from;
3855 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3857 print "<table class=\"heads\">\n";
3859 for (my $i = $from; $i <= $to; $i++) {
3860 my $entry = $headlist->[$i];
3862 my $curr = $ref{'id'} eq $head;
3864 print "<tr class=\"dark\">\n";
3866 print "<tr class=\"light\">\n";
3869 print "<td><i>$ref{'age'}</i></td>\n" .
3870 ($curr ? "<td class=\"current_head\">" : "<td>") .
3871 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3872 -class => "list name"},esc_html
($ref{'name'})) .
3874 "<td class=\"link\">" .
3875 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3876 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3877 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3881 if (defined $extra) {
3883 "<td colspan=\"3\">$extra</td>\n" .
3889 sub git_search_grep_body
{
3890 my ($commitlist, $from, $to, $extra) = @_;
3891 $from = 0 unless defined $from;
3892 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3894 print "<table class=\"commit_search\">\n";
3896 for (my $i = $from; $i <= $to; $i++) {
3897 my %co = %{$commitlist->[$i]};
3901 my $commit = $co{'id'};
3903 print "<tr class=\"dark\">\n";
3905 print "<tr class=\"light\">\n";
3908 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3909 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3910 "<td><i>" . $author . "</i></td>\n" .
3912 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3913 -class => "list subject"},
3914 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3915 my $comment = $co{'comment'};
3916 foreach my $line (@$comment) {
3917 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3918 my ($lead, $match, $trail) = ($1, $2, $3);
3919 $match = chop_str
($match, 70, 5, 'center');
3920 my $contextlen = int((80 - length($match))/2);
3921 $contextlen = 30 if ($contextlen > 30);
3922 $lead = chop_str
($lead, $contextlen, 10, 'left');
3923 $trail = chop_str
($trail, $contextlen, 10, 'right');
3925 $lead = esc_html
($lead);
3926 $match = esc_html
($match);
3927 $trail = esc_html
($trail);
3929 print "$lead<span class=\"match\">$match</span>$trail<br />";
3933 "<td class=\"link\">" .
3934 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3936 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
3938 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3942 if (defined $extra) {
3944 "<td colspan=\"3\">$extra</td>\n" .
3950 ## ======================================================================
3951 ## ======================================================================
3954 sub git_project_list
{
3955 my $order = $cgi->param('o');
3956 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3957 die_error
(undef, "Unknown order parameter");
3960 my @list = git_get_projects_list
();
3962 die_error
(undef, "No projects found");
3966 if (-f
$home_text) {
3967 print "<div class=\"index_include\">\n";
3968 open (my $fd, $home_text);
3973 git_project_list_body
(\
@list, $order);
3978 my $order = $cgi->param('o');
3979 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3980 die_error
(undef, "Unknown order parameter");
3983 my @list = git_get_projects_list
($project);
3985 die_error
(undef, "No forks found");
3989 git_print_page_nav
('','');
3990 git_print_header_div
('summary', "$project forks");
3991 git_project_list_body
(\
@list, $order);
3995 sub git_project_index
{
3996 my @projects = git_get_projects_list
($project);
3999 -type
=> 'text/plain',
4000 -charset
=> 'utf-8',
4001 -content_disposition
=> 'inline; filename="index.aux"');
4003 foreach my $pr (@projects) {
4004 if (!exists $pr->{'owner'}) {
4005 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4008 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4009 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4010 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4011 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4015 print "$path $owner\n";
4020 my $descr = git_get_project_description
($project) || "none";
4021 my %co = parse_commit
("HEAD");
4022 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4023 my $head = $co{'id'};
4025 my $owner = git_get_project_owner
($project);
4027 my $refs = git_get_references
();
4028 # These get_*_list functions return one more to allow us to see if
4029 # there are more ...
4030 my @taglist = git_get_tags_list
(16);
4031 my @headlist = git_get_heads_list
(16);
4033 my ($check_forks) = gitweb_check_feature
('forks');
4036 @forklist = git_get_projects_list
($project);
4040 git_print_page_nav
('summary','', $head);
4042 print "<div class=\"title\"> </div>\n";
4043 print "<table class=\"projects_list\">\n" .
4044 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4045 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4046 if (defined $cd{'rfc2822'}) {
4047 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4050 # use per project git URL list in $projectroot/$project/cloneurl
4051 # or make project git URL from git base URL and project name
4052 my $url_tag = "URL";
4053 my @url_list = git_get_project_url_list
($project);
4054 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4055 foreach my $git_url (@url_list) {
4056 next unless $git_url;
4057 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
4062 if (-s
"$projectroot/$project/README.html") {
4063 if (open my $fd, "$projectroot/$project/README.html") {
4064 print "<div class=\"title\">readme</div>\n" .
4065 "<div class=\"readme\">\n";
4066 print $_ while (<$fd>);
4067 print "\n</div>\n"; # class="readme"
4072 # we need to request one more than 16 (0..15) to check if
4074 my @commitlist = $head ? parse_commits
($head, 17) : ();
4076 git_print_header_div
('shortlog');
4077 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4078 $#commitlist <= 15 ? undef :
4079 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4083 git_print_header_div
('tags');
4084 git_tags_body
(\
@taglist, 0, 15,
4085 $#taglist <= 15 ? undef :
4086 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4090 git_print_header_div
('heads');
4091 git_heads_body
(\
@headlist, $head, 0, 15,
4092 $#headlist <= 15 ? undef :
4093 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4097 git_print_header_div
('forks');
4098 git_project_list_body
(\
@forklist, undef, 0, 15,
4099 $#forklist <= 15 ? undef :
4100 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4108 my $head = git_get_head_hash
($project);
4110 git_print_page_nav
('','', $head,undef,$head);
4111 my %tag = parse_tag
($hash);
4114 die_error
(undef, "Unknown tag object");
4117 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4118 print "<div class=\"title_text\">\n" .
4119 "<table class=\"object_header\">\n" .
4121 "<td>object</td>\n" .
4122 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4123 $tag{'object'}) . "</td>\n" .
4124 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4125 $tag{'type'}) . "</td>\n" .
4127 if (defined($tag{'author'})) {
4128 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4129 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4130 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4131 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4134 print "</table>\n\n" .
4136 print "<div class=\"page_body\">";
4137 my $comment = $tag{'comment'};
4138 foreach my $line (@$comment) {
4140 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4150 my ($have_blame) = gitweb_check_feature
('blame');
4152 die_error
('403 Permission denied', "Permission denied");
4154 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4155 $hash_base ||= git_get_head_hash
($project);
4156 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4157 my %co = parse_commit
($hash_base)
4158 or die_error
(undef, "Reading commit failed");
4159 if (!defined $hash) {
4160 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4161 or die_error
(undef, "Error looking up file");
4163 $ftype = git_get_type
($hash);
4164 if ($ftype !~ "blob") {
4165 die_error
('400 Bad Request', "Object is not a blob");
4167 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4168 $file_name, $hash_base)
4169 or die_error
(undef, "Open git-blame failed");
4172 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4175 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4178 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4180 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4181 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4182 git_print_page_path
($file_name, $ftype, $hash_base);
4183 my @rev_color = (qw(light2 dark2));
4184 my $num_colors = scalar(@rev_color);
4185 my $current_color = 0;
4188 <div class="page_body">
4189 <table class="blame">
4190 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4195 last unless defined $_;
4196 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4197 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4198 if (!exists $metainfo{$full_rev}) {
4199 $metainfo{$full_rev} = {};
4201 my $meta = $metainfo{$full_rev};
4204 if (/^(\S+) (.*)$/) {
4210 my $rev = substr($full_rev, 0, 8);
4211 my $author = $meta->{'author'};
4212 my %date = parse_date
($meta->{'author-time'},
4213 $meta->{'author-tz'});
4214 my $date = $date{'iso-tz'};
4216 $current_color = ++$current_color % $num_colors;
4218 print "<tr class=\"$rev_color[$current_color]\">\n";
4220 print "<td class=\"sha1\"";
4221 print " title=\"". esc_html
($author) . ", $date\"";
4222 print " rowspan=\"$group_size\"" if ($group_size > 1);
4224 print $cgi->a({-href
=> href
(action
=>"commit",
4226 file_name
=>$file_name)},
4230 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4231 or die_error
(undef, "Open git-rev-parse failed");
4232 my $parent_commit = <$dd>;
4234 chomp($parent_commit);
4235 my $blamed = href
(action
=> 'blame',
4236 file_name
=> $meta->{'filename'},
4237 hash_base
=> $parent_commit);
4238 print "<td class=\"linenr\">";
4239 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4241 -class => "linenr" },
4244 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4250 or print "Reading blob failed\n";
4257 my ($have_blame) = gitweb_check_feature
('blame');
4259 die_error
('403 Permission denied', "Permission denied");
4261 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4262 $hash_base ||= git_get_head_hash
($project);
4263 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4264 my %co = parse_commit
($hash_base)
4265 or die_error
(undef, "Reading commit failed");
4266 if (!defined $hash) {
4267 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4268 or die_error
(undef, "Error lookup file");
4270 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
4271 or die_error
(undef, "Open git-annotate failed");
4274 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4277 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
4280 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4282 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4283 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4284 git_print_page_path
($file_name, 'blob', $hash_base);
4285 print "<div class=\"page_body\">\n";
4287 <table class="blame">
4296 my @line_class = (qw(light dark));
4297 my $line_class_len = scalar (@line_class);
4298 my $line_class_num = $#line_class;
4299 while (my $line = <$fd>) {
4311 $line_class_num = ($line_class_num + 1) % $line_class_len;
4313 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
4320 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
4323 $short_rev = substr ($long_rev, 0, 8);
4324 $age = time () - $time;
4325 $age_str = age_string
($age);
4326 $age_str =~ s/ / /g;
4327 $age_class = age_class
($age);
4328 $author = esc_html
($author);
4329 $author =~ s/ / /g;
4331 $data = untabify
($data);
4332 $data = esc_html
($data);
4335 <tr class="$line_class[$line_class_num]">
4336 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
4337 <td class="$age_class">$age_str</td>
4339 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
4340 <td class="pre">$data</td>
4343 } # while (my $line = <$fd>)
4344 print "</table>\n\n";
4346 or print "Reading blob failed.\n";
4352 my $head = git_get_head_hash
($project);
4354 git_print_page_nav
('','', $head,undef,$head);
4355 git_print_header_div
('summary', $project);
4357 my @tagslist = git_get_tags_list
();
4359 git_tags_body
(\
@tagslist);
4365 my $head = git_get_head_hash
($project);
4367 git_print_page_nav
('','', $head,undef,$head);
4368 git_print_header_div
('summary', $project);
4370 my @headslist = git_get_heads_list
();
4372 git_heads_body
(\
@headslist, $head);
4377 sub git_blob_plain
{
4380 if (!defined $hash) {
4381 if (defined $file_name) {
4382 my $base = $hash_base || git_get_head_hash
($project);
4383 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4384 or die_error
(undef, "Error lookup file");
4386 die_error
(undef, "No file name defined");
4388 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4389 # blobs defined by non-textual hash id's can be cached
4394 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4395 or die_error
(undef, "Couldn't cat $file_name, $hash");
4397 $type ||= blob_mimetype
($fd, $file_name);
4399 # save as filename, even when no $file_name is given
4400 my $save_as = "$hash";
4401 if (defined $file_name) {
4402 $save_as = $file_name;
4403 } elsif ($type =~ m/^text\//) {
4410 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4412 binmode STDOUT
, ':raw';
4414 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4422 if (!defined $hash) {
4423 if (defined $file_name) {
4424 my $base = $hash_base || git_get_head_hash
($project);
4425 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4426 or die_error
(undef, "Error lookup file");
4428 die_error
(undef, "No file name defined");
4430 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4431 # blobs defined by non-textual hash id's can be cached
4435 my ($have_blame) = gitweb_check_feature
('blame');
4436 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4437 or die_error
(undef, "Couldn't cat $file_name, $hash");
4438 my $mimetype = blob_mimetype
($fd, $file_name);
4439 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4441 return git_blob_plain
($mimetype);
4443 # we can have blame only for text/* mimetype
4444 $have_blame &&= ($mimetype =~ m!^text/!);
4446 git_header_html
(undef, $expires);
4447 my $formats_nav = '';
4448 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4449 if (defined $file_name) {
4452 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4457 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4460 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4463 $cgi->a({-href
=> href
(action
=>"blob",
4464 hash_base
=>"HEAD", file_name
=>$file_name)},
4468 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4471 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4472 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4474 print "<div class=\"page_nav\">\n" .
4475 "<br/><br/></div>\n" .
4476 "<div class=\"title\">$hash</div>\n";
4478 git_print_page_path
($file_name, "blob", $hash_base);
4479 print "<div class=\"page_body\">\n";
4480 if ($mimetype =~ m!^image/!) {
4481 print qq
!<img type
="$mimetype"!;
4483 print qq
! alt
="$file_name" title
="$file_name"!;
4486 href(action=>"blob_plain
", hash=>$hash,
4487 hash_base=>$hash_base, file_name=>$file_name) .
4491 while (my $line = <$fd>) {
4494 $line = untabify
($line);
4495 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4496 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4500 or print "Reading blob failed.\n";
4506 if (!defined $hash_base) {
4507 $hash_base = "HEAD";
4509 if (!defined $hash) {
4510 if (defined $file_name) {
4511 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4517 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4518 or die_error
(undef, "Open git-ls-tree failed");
4519 my @entries = map { chomp; $_ } <$fd>;
4520 close $fd or die_error
(undef, "Reading tree failed");
4523 my $refs = git_get_references
();
4524 my $ref = format_ref_marker
($refs, $hash_base);
4527 my ($have_blame) = gitweb_check_feature
('blame');
4528 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4530 if (defined $file_name) {
4532 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4534 $cgi->a({-href
=> href
(action
=>"tree",
4535 hash_base
=>"HEAD", file_name
=>$file_name)},
4538 my $snapshot_links = format_snapshot_links
($hash);
4539 if (defined $snapshot_links) {
4540 # FIXME: Should be available when we have no hash base as well.
4541 push @views_nav, $snapshot_links;
4543 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4544 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4547 print "<div class=\"page_nav\">\n";
4548 print "<br/><br/></div>\n";
4549 print "<div class=\"title\">$hash</div>\n";
4551 if (defined $file_name) {
4552 $basedir = $file_name;
4553 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4557 git_print_page_path
($file_name, 'tree', $hash_base);
4558 print "<div class=\"page_body\">\n";
4559 print "<table class=\"tree\">\n";
4561 # '..' (top directory) link if possible
4562 if (defined $hash_base &&
4563 defined $file_name && $file_name =~ m![^/]+$!) {
4565 print "<tr class=\"dark\">\n";
4567 print "<tr class=\"light\">\n";
4571 my $up = $file_name;
4572 $up =~ s!/?[^/]+$!!;
4573 undef $up unless $up;
4574 # based on git_print_tree_entry
4575 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4576 print '<td class="list">';
4577 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4581 print "<td class=\"link\"></td>\n";
4585 foreach my $line (@entries) {
4586 my %t = parse_ls_tree_line
($line, -z
=> 1);
4589 print "<tr class=\"dark\">\n";
4591 print "<tr class=\"light\">\n";
4595 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4599 print "</table>\n" .
4605 my @supported_fmts = gitweb_check_feature
('snapshot');
4606 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4608 my $format = $cgi->param('sf');
4609 if (!@supported_fmts) {
4610 die_error
('403 Permission denied', "Permission denied");
4612 # default to first supported snapshot format
4613 $format ||= $supported_fmts[0];
4614 if ($format !~ m/^[a-z0-9]+$/) {
4615 die_error
(undef, "Invalid snapshot format parameter");
4616 } elsif (!exists($known_snapshot_formats{$format})) {
4617 die_error
(undef, "Unknown snapshot format");
4618 } elsif (!grep($_ eq $format, @supported_fmts)) {
4619 die_error
(undef, "Unsupported snapshot format");
4622 if (!defined $hash) {
4623 $hash = git_get_head_hash
($project);
4626 my $git_command = git_cmd_str
();
4627 my $name = $project;
4628 $name =~ s
,([^/])/*\
.git
$,$1,;
4629 $name = basename
($name);
4630 my $filename = to_utf8
($name);
4631 $name =~ s/\047/\047\\\047\047/g;
4633 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4634 $cmd = "$git_command archive " .
4635 "--format=$known_snapshot_formats{$format}{'format'} " .
4636 "--prefix=\'$name\'/ $hash";
4637 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4638 $cmd .= ' | ' . join ' ', @{$known_snapshot_formats{$format}{'compressor'}};
4642 -type
=> $known_snapshot_formats{$format}{'type'},
4643 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4644 -status
=> '200 OK');
4646 open my $fd, "-|", $cmd
4647 or die_error
(undef, "Execute git-archive failed");
4648 binmode STDOUT
, ':raw';
4650 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4655 my $head = git_get_head_hash
($project);
4656 if (!defined $hash) {
4659 if (!defined $page) {
4662 my $refs = git_get_references
();
4664 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4666 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4669 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4672 my %co = parse_commit
($hash);
4674 git_print_header_div
('summary', $project);
4675 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4677 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4678 for (my $i = 0; $i <= $to; $i++) {
4679 my %co = %{$commitlist[$i]};
4681 my $commit = $co{'id'};
4682 my $ref = format_ref_marker
($refs, $commit);
4683 my %ad = parse_date
($co{'author_epoch'});
4684 git_print_header_div
('commit',
4685 "<span class=\"age\">$co{'age_string'}</span>" .
4686 esc_html
($co{'title'}) . $ref,
4688 print "<div class=\"title_text\">\n" .
4689 "<div class=\"log_link\">\n" .
4690 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4692 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4694 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4697 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4700 print "<div class=\"log_body\">\n";
4701 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4704 if ($#commitlist >= 100) {
4705 print "<div class=\"page_nav\">\n";
4706 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4707 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4714 $hash ||= $hash_base || "HEAD";
4715 my %co = parse_commit
($hash);
4717 die_error
(undef, "Unknown commit object");
4719 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4720 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4722 my $parent = $co{'parent'};
4723 my $parents = $co{'parents'}; # listref
4725 # we need to prepare $formats_nav before any parameter munging
4727 if (!defined $parent) {
4729 $formats_nav .= '(initial)';
4730 } elsif (@$parents == 1) {
4731 # single parent commit
4734 $cgi->a({-href
=> href
(action
=>"commit",
4736 esc_html
(substr($parent, 0, 7))) .
4743 $cgi->a({-href
=> href
(action
=>"commit",
4745 esc_html
(substr($_, 0, 7)));
4750 if (!defined $parent) {
4754 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4756 (@$parents <= 1 ? $parent : '-c'),
4758 or die_error
(undef, "Open git-diff-tree failed");
4759 @difftree = map { chomp; $_ } <$fd>;
4760 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4762 # non-textual hash id's can be cached
4764 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4767 my $refs = git_get_references
();
4768 my $ref = format_ref_marker
($refs, $co{'id'});
4770 git_header_html
(undef, $expires);
4771 git_print_page_nav
('commit', '',
4772 $hash, $co{'tree'}, $hash,
4775 if (defined $co{'parent'}) {
4776 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4778 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4780 print "<div class=\"title_text\">\n" .
4781 "<table class=\"object_header\">\n";
4782 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4784 "<td></td><td> $ad{'rfc2822'}";
4785 if ($ad{'hour_local'} < 6) {
4786 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4787 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4789 printf(" (%02d:%02d %s)",
4790 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4794 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4795 print "<tr><td></td><td> $cd{'rfc2822'}" .
4796 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4798 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4801 "<td class=\"sha1\">" .
4802 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4803 class => "list"}, $co{'tree'}) .
4805 "<td class=\"link\">" .
4806 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4808 my $snapshot_links = format_snapshot_links
($hash);
4809 if (defined $snapshot_links) {
4810 print " | " . $snapshot_links;
4815 foreach my $par (@$parents) {
4818 "<td class=\"sha1\">" .
4819 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4820 class => "list"}, $par) .
4822 "<td class=\"link\">" .
4823 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4825 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4832 print "<div class=\"page_body\">\n";
4833 git_print_log
($co{'comment'});
4836 git_difftree_body
(\
@difftree, $hash, @$parents);
4842 # object is defined by:
4843 # - hash or hash_base alone
4844 # - hash_base and file_name
4847 # - hash or hash_base alone
4848 if ($hash || ($hash_base && !defined $file_name)) {
4849 my $object_id = $hash || $hash_base;
4851 my $git_command = git_cmd_str
();
4852 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4853 or die_error
('404 Not Found', "Object does not exist");
4857 or die_error
('404 Not Found', "Object does not exist");
4859 # - hash_base and file_name
4860 } elsif ($hash_base && defined $file_name) {
4861 $file_name =~ s
,/+$,,;
4863 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4864 or die_error
('404 Not Found', "Base object does not exist");
4866 # here errors should not hapen
4867 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4868 or die_error
(undef, "Open git-ls-tree failed");
4872 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4873 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4874 die_error
('404 Not Found', "File or directory for given base does not exist");
4879 die_error
('404 Not Found', "Not enough information to find object");
4882 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4883 hash
=>$hash, hash_base
=>$hash_base,
4884 file_name
=>$file_name),
4885 -status
=> '302 Found');
4889 my $format = shift || 'html';
4896 # preparing $fd and %diffinfo for git_patchset_body
4898 if (defined $hash_base && defined $hash_parent_base) {
4899 if (defined $file_name) {
4901 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4902 $hash_parent_base, $hash_base,
4903 "--", (defined $file_parent ? $file_parent : ()), $file_name
4904 or die_error
(undef, "Open git-diff-tree failed");
4905 @difftree = map { chomp; $_ } <$fd>;
4907 or die_error
(undef, "Reading git-diff-tree failed");
4909 or die_error
('404 Not Found', "Blob diff not found");
4911 } elsif (defined $hash &&
4912 $hash =~ /[0-9a-fA-F]{40}/) {
4913 # try to find filename from $hash
4915 # read filtered raw output
4916 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4917 $hash_parent_base, $hash_base, "--"
4918 or die_error
(undef, "Open git-diff-tree failed");
4920 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4922 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4923 map { chomp; $_ } <$fd>;
4925 or die_error
(undef, "Reading git-diff-tree failed");
4927 or die_error
('404 Not Found', "Blob diff not found");
4930 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4933 if (@difftree > 1) {
4934 die_error
('404 Not Found', "Ambiguous blob diff specification");
4937 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4938 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4939 $file_name ||= $diffinfo{'to_file'};
4941 $hash_parent ||= $diffinfo{'from_id'};
4942 $hash ||= $diffinfo{'to_id'};
4944 # non-textual hash id's can be cached
4945 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4946 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4951 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4952 '-p', ($format eq 'html' ? "--full-index" : ()),
4953 $hash_parent_base, $hash_base,
4954 "--", (defined $file_parent ? $file_parent : ()), $file_name
4955 or die_error
(undef, "Open git-diff-tree failed");
4958 # old/legacy style URI
4959 if (!%diffinfo && # if new style URI failed
4960 defined $hash && defined $hash_parent) {
4961 # fake git-diff-tree raw output
4962 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4963 $diffinfo{'from_id'} = $hash_parent;
4964 $diffinfo{'to_id'} = $hash;
4965 if (defined $file_name) {
4966 if (defined $file_parent) {
4967 $diffinfo{'status'} = '2';
4968 $diffinfo{'from_file'} = $file_parent;
4969 $diffinfo{'to_file'} = $file_name;
4970 } else { # assume not renamed
4971 $diffinfo{'status'} = '1';
4972 $diffinfo{'from_file'} = $file_name;
4973 $diffinfo{'to_file'} = $file_name;
4975 } else { # no filename given
4976 $diffinfo{'status'} = '2';
4977 $diffinfo{'from_file'} = $hash_parent;
4978 $diffinfo{'to_file'} = $hash;
4981 # non-textual hash id's can be cached
4982 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4983 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4988 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4989 '-p', ($format eq 'html' ? "--full-index" : ()),
4990 $hash_parent, $hash, "--"
4991 or die_error
(undef, "Open git-diff failed");
4993 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4998 if ($format eq 'html') {
5000 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5002 git_header_html
(undef, $expires);
5003 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5004 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5005 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5007 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5008 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5010 if (defined $file_name) {
5011 git_print_page_path
($file_name, "blob", $hash_base);
5013 print "<div class=\"page_path\"></div>\n";
5016 } elsif ($format eq 'plain') {
5018 -type
=> 'text/plain',
5019 -charset
=> 'utf-8',
5020 -expires
=> $expires,
5021 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5023 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5026 die_error
(undef, "Unknown blobdiff format");
5030 if ($format eq 'html') {
5031 print "<div class=\"page_body\">\n";
5033 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5036 print "</div>\n"; # class="page_body"
5040 while (my $line = <$fd>) {
5041 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5042 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5046 last if $line =~ m!^\+\+\+!;
5054 sub git_blobdiff_plain
{
5055 git_blobdiff
('plain');
5058 sub git_commitdiff
{
5059 my $format = shift || 'html';
5060 $hash ||= $hash_base || "HEAD";
5061 my %co = parse_commit
($hash);
5063 die_error
(undef, "Unknown commit object");
5066 # choose format for commitdiff for merge
5067 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5068 $hash_parent = '--cc';
5070 # we need to prepare $formats_nav before almost any parameter munging
5072 if ($format eq 'html') {
5074 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5077 if (defined $hash_parent &&
5078 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5079 # commitdiff with two commits given
5080 my $hash_parent_short = $hash_parent;
5081 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5082 $hash_parent_short = substr($hash_parent, 0, 7);
5086 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5087 if ($co{'parents'}[$i] eq $hash_parent) {
5088 $formats_nav .= ' parent ' . ($i+1);
5092 $formats_nav .= ': ' .
5093 $cgi->a({-href
=> href
(action
=>"commitdiff",
5094 hash
=>$hash_parent)},
5095 esc_html
($hash_parent_short)) .
5097 } elsif (!$co{'parent'}) {
5099 $formats_nav .= ' (initial)';
5100 } elsif (scalar @{$co{'parents'}} == 1) {
5101 # single parent commit
5104 $cgi->a({-href
=> href
(action
=>"commitdiff",
5105 hash
=>$co{'parent'})},
5106 esc_html
(substr($co{'parent'}, 0, 7))) .
5110 if ($hash_parent eq '--cc') {
5111 $formats_nav .= ' | ' .
5112 $cgi->a({-href
=> href
(action
=>"commitdiff",
5113 hash
=>$hash, hash_parent
=>'-c')},
5115 } else { # $hash_parent eq '-c'
5116 $formats_nav .= ' | ' .
5117 $cgi->a({-href
=> href
(action
=>"commitdiff",
5118 hash
=>$hash, hash_parent
=>'--cc')},
5124 $cgi->a({-href
=> href
(action
=>"commitdiff",
5126 esc_html
(substr($_, 0, 7)));
5127 } @{$co{'parents'}} ) .
5132 my $hash_parent_param = $hash_parent;
5133 if (!defined $hash_parent_param) {
5134 # --cc for multiple parents, --root for parentless
5135 $hash_parent_param =
5136 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5142 if ($format eq 'html') {
5143 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5144 "--no-commit-id", "--patch-with-raw", "--full-index",
5145 $hash_parent_param, $hash, "--"
5146 or die_error
(undef, "Open git-diff-tree failed");
5148 while (my $line = <$fd>) {
5150 # empty line ends raw part of diff-tree output
5152 push @difftree, scalar parse_difftree_raw_line
($line);
5155 } elsif ($format eq 'plain') {
5156 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5157 '-p', $hash_parent_param, $hash, "--"
5158 or die_error
(undef, "Open git-diff-tree failed");
5161 die_error
(undef, "Unknown commitdiff format");
5164 # non-textual hash id's can be cached
5166 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5170 # write commit message
5171 if ($format eq 'html') {
5172 my $refs = git_get_references
();
5173 my $ref = format_ref_marker
($refs, $co{'id'});
5175 git_header_html
(undef, $expires);
5176 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5177 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5178 git_print_authorship
(\
%co);
5179 print "<div class=\"page_body\">\n";
5180 if (@{$co{'comment'}} > 1) {
5181 print "<div class=\"log\">\n";
5182 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5183 print "</div>\n"; # class="log"
5186 } elsif ($format eq 'plain') {
5187 my $refs = git_get_references
("tags");
5188 my $tagname = git_get_rev_name_tags
($hash);
5189 my $filename = basename
($project) . "-$hash.patch";
5192 -type
=> 'text/plain',
5193 -charset
=> 'utf-8',
5194 -expires
=> $expires,
5195 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5196 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5197 print "From: " . to_utf8
($co{'author'}) . "\n";
5198 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5199 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5201 print "X-Git-Tag: $tagname\n" if $tagname;
5202 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5204 foreach my $line (@{$co{'comment'}}) {
5205 print to_utf8
($line) . "\n";
5211 if ($format eq 'html') {
5212 my $use_parents = !defined $hash_parent ||
5213 $hash_parent eq '-c' || $hash_parent eq '--cc';
5214 git_difftree_body
(\
@difftree, $hash,
5215 $use_parents ? @{$co{'parents'}} : $hash_parent);
5218 git_patchset_body
($fd, \
@difftree, $hash,
5219 $use_parents ? @{$co{'parents'}} : $hash_parent);
5221 print "</div>\n"; # class="page_body"
5224 } elsif ($format eq 'plain') {
5228 or print "Reading git-diff-tree failed\n";
5232 sub git_commitdiff_plain
{
5233 git_commitdiff
('plain');
5237 if (!defined $hash_base) {
5238 $hash_base = git_get_head_hash
($project);
5240 if (!defined $page) {
5244 my %co = parse_commit
($hash_base);
5246 die_error
(undef, "Unknown commit object");
5249 my $refs = git_get_references
();
5250 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5252 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5253 $file_name, "--full-history");
5255 die_error
('404 Not Found', "No such file or directory on given branch");
5258 if (!defined $hash && defined $file_name) {
5259 # some commits could have deleted file in question,
5260 # and not have it in tree, but one of them has to have it
5261 for (my $i = 0; $i <= @commitlist; $i++) {
5262 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5263 last if defined $hash;
5266 if (defined $hash) {
5267 $ftype = git_get_type
($hash);
5269 if (!defined $ftype) {
5270 die_error
(undef, "Unknown type of object");
5273 my $paging_nav = '';
5276 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5277 file_name
=>$file_name)},
5279 $paging_nav .= " ⋅ " .
5280 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5281 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5283 $paging_nav .= "first";
5284 $paging_nav .= " ⋅ prev";
5287 if ($#commitlist >= 100) {
5289 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5290 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5291 $paging_nav .= " ⋅ $next_link";
5293 $paging_nav .= " ⋅ next";
5297 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5298 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5299 git_print_page_path
($file_name, $ftype, $hash_base);
5301 git_history_body
(\
@commitlist, 0, 99,
5302 $refs, $hash_base, $ftype, $next_link);
5308 my ($have_search) = gitweb_check_feature
('search');
5309 if (!$have_search) {
5310 die_error
('403 Permission denied', "Permission denied");
5312 if (!defined $searchtext) {
5313 die_error
(undef, "Text field empty");
5315 if (!defined $hash) {
5316 $hash = git_get_head_hash
($project);
5318 my %co = parse_commit
($hash);
5320 die_error
(undef, "Unknown commit object");
5322 if (!defined $page) {
5326 $searchtype ||= 'commit';
5327 if ($searchtype eq 'pickaxe') {
5328 # pickaxe may take all resources of your box and run for several minutes
5329 # with every query - so decide by yourself how public you make this feature
5330 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5331 if (!$have_pickaxe) {
5332 die_error
('403 Permission denied', "Permission denied");
5335 if ($searchtype eq 'grep') {
5336 my ($have_grep) = gitweb_check_feature
('grep');
5338 die_error
('403 Permission denied', "Permission denied");
5344 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5346 if ($searchtype eq 'commit') {
5347 $greptype = "--grep=";
5348 } elsif ($searchtype eq 'author') {
5349 $greptype = "--author=";
5350 } elsif ($searchtype eq 'committer') {
5351 $greptype = "--committer=";
5353 $greptype .= $searchtext;
5354 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5355 $greptype, '--regexp-ignore-case',
5356 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5358 my $paging_nav = '';
5361 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5362 searchtext
=>$searchtext,
5363 searchtype
=>$searchtype)},
5365 $paging_nav .= " ⋅ " .
5366 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5367 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5369 $paging_nav .= "first";
5370 $paging_nav .= " ⋅ prev";
5373 if ($#commitlist >= 100) {
5375 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5376 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5377 $paging_nav .= " ⋅ $next_link";
5379 $paging_nav .= " ⋅ next";
5382 if ($#commitlist >= 100) {
5385 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5386 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5387 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5390 if ($searchtype eq 'pickaxe') {
5391 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5392 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5394 print "<table class=\"pickaxe search\">\n";
5397 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5398 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5399 ($search_use_regexp ? '--pickaxe-regex' : ());
5402 while (my $line = <$fd>) {
5406 my %set = parse_difftree_raw_line
($line);
5407 if (defined $set{'commit'}) {
5408 # finish previous commit
5411 "<td class=\"link\">" .
5412 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5414 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5420 print "<tr class=\"dark\">\n";
5422 print "<tr class=\"light\">\n";
5425 %co = parse_commit
($set{'commit'});
5426 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5427 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5428 "<td><i>$author</i></td>\n" .
5430 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5431 -class => "list subject"},
5432 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5433 } elsif (defined $set{'to_id'}) {
5434 next if ($set{'to_id'} =~ m/^0{40}$/);
5436 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5437 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5439 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5445 # finish last commit (warning: repetition!)
5448 "<td class=\"link\">" .
5449 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5451 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5459 if ($searchtype eq 'grep') {
5460 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5461 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5463 print "<table class=\"grep_search\">\n";
5467 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5468 $search_use_regexp ? ('-E', '-i') : '-F',
5469 $searchtext, $co{'tree'};
5471 while (my $line = <$fd>) {
5473 my ($file, $lno, $ltext, $binary);
5474 last if ($matches++ > 1000);
5475 if ($line =~ /^Binary file (.+) matches$/) {
5479 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5481 if ($file ne $lastfile) {
5482 $lastfile and print "</td></tr>\n";
5484 print "<tr class=\"dark\">\n";
5486 print "<tr class=\"light\">\n";
5488 print "<td class=\"list\">".
5489 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5490 file_name
=>"$file"),
5491 -class => "list"}, esc_path
($file));
5492 print "</td><td>\n";
5496 print "<div class=\"binary\">Binary file</div>\n";
5498 $ltext = untabify
($ltext);
5499 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5500 $ltext = esc_html
($1, -nbsp
=>1);
5501 $ltext .= '<span class="match">';
5502 $ltext .= esc_html
($2, -nbsp
=>1);
5503 $ltext .= '</span>';
5504 $ltext .= esc_html
($3, -nbsp
=>1);
5506 $ltext = esc_html
($ltext, -nbsp
=>1);
5508 print "<div class=\"pre\">" .
5509 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5510 file_name
=>"$file").'#l'.$lno,
5511 -class => "linenr"}, sprintf('%4i', $lno))
5512 . ' ' . $ltext . "</div>\n";
5516 print "</td></tr>\n";
5517 if ($matches > 1000) {
5518 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5521 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5530 sub git_search_help
{
5532 git_print_page_nav
('','', $hash,$hash,$hash);
5534 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5535 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5536 the pattern entered is recognized as the POSIX extended
5537 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5540 <dt><b>commit</b></dt>
5541 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5543 my ($have_grep) = gitweb_check_feature
('grep');
5546 <dt><b>grep</b></dt>
5547 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5548 a different one) are searched for the given pattern. On large trees, this search can take
5549 a while and put some strain on the server, so please use it with some consideration. Note that
5550 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5551 case-sensitive.</dd>
5555 <dt><b>author</b></dt>
5556 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5557 <dt><b>committer</b></dt>
5558 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5560 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5561 if ($have_pickaxe) {
5563 <dt><b>pickaxe</b></dt>
5564 <dd>All commits that caused the string to appear or disappear from any file (changes that
5565 added, removed or "modified" the string) will be listed. This search can take a while and
5566 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5567 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5575 my $head = git_get_head_hash
($project);
5576 if (!defined $hash) {
5579 if (!defined $page) {
5582 my $refs = git_get_references
();
5584 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5586 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5588 if ($#commitlist >= 100) {
5590 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5591 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5595 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5596 git_print_header_div
('summary', $project);
5598 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5603 ## ......................................................................
5604 ## feeds (RSS, Atom; OPML)
5607 my $format = shift || 'atom';
5608 my ($have_blame) = gitweb_check_feature
('blame');
5610 # Atom: http://www.atomenabled.org/developers/syndication/
5611 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5612 if ($format ne 'rss' && $format ne 'atom') {
5613 die_error
(undef, "Unknown web feed format");
5616 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5617 my $head = $hash || 'HEAD';
5618 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5622 my $content_type = "application/$format+xml";
5623 if (defined $cgi->http('HTTP_ACCEPT') &&
5624 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5625 # browser (feed reader) prefers text/xml
5626 $content_type = 'text/xml';
5628 if (defined($commitlist[0])) {
5629 %latest_commit = %{$commitlist[0]};
5630 %latest_date = parse_date
($latest_commit{'author_epoch'});
5632 -type
=> $content_type,
5633 -charset
=> 'utf-8',
5634 -last_modified
=> $latest_date{'rfc2822'});
5637 -type
=> $content_type,
5638 -charset
=> 'utf-8');
5641 # Optimization: skip generating the body if client asks only
5642 # for Last-Modified date.
5643 return if ($cgi->request_method() eq 'HEAD');
5646 my $title = "$site_name - $project/$action";
5647 my $feed_type = 'log';
5648 if (defined $hash) {
5649 $title .= " - '$hash'";
5650 $feed_type = 'branch log';
5651 if (defined $file_name) {
5652 $title .= " :: $file_name";
5653 $feed_type = 'history';
5655 } elsif (defined $file_name) {
5656 $title .= " - $file_name";
5657 $feed_type = 'history';
5659 $title .= " $feed_type";
5660 my $descr = git_get_project_description
($project);
5661 if (defined $descr) {
5662 $descr = esc_html
($descr);
5664 $descr = "$project " .
5665 ($format eq 'rss' ? 'RSS' : 'Atom') .
5668 my $owner = git_get_project_owner
($project);
5669 $owner = esc_html
($owner);
5673 if (defined $file_name) {
5674 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5675 } elsif (defined $hash) {
5676 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5678 $alt_url = href
(-full
=>1, action
=>"summary");
5680 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5681 if ($format eq 'rss') {
5683 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5686 print "<title>$title</title>\n" .
5687 "<link>$alt_url</link>\n" .
5688 "<description>$descr</description>\n" .
5689 "<language>en</language>\n";
5690 } elsif ($format eq 'atom') {
5692 <feed xmlns="http://www.w3.org/2005/Atom">
5694 print "<title>$title</title>\n" .
5695 "<subtitle>$descr</subtitle>\n" .
5696 '<link rel="alternate" type="text/html" href="' .
5697 $alt_url . '" />' . "\n" .
5698 '<link rel="self" type="' . $content_type . '" href="' .
5699 $cgi->self_url() . '" />' . "\n" .
5700 "<id>" . href
(-full
=>1) . "</id>\n" .
5701 # use project owner for feed author
5702 "<author><name>$owner</name></author>\n";
5703 if (defined $favicon) {
5704 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5706 if (defined $logo_url) {
5707 # not twice as wide as tall: 72 x 27 pixels
5708 print "<logo>" . esc_url
($logo) . "</logo>\n";
5710 if (! %latest_date) {
5711 # dummy date to keep the feed valid until commits trickle in:
5712 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5714 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5719 for (my $i = 0; $i <= $#commitlist; $i++) {
5720 my %co = %{$commitlist[$i]};
5721 my $commit = $co{'id'};
5722 # we read 150, we always show 30 and the ones more recent than 48 hours
5723 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5726 my %cd = parse_date
($co{'author_epoch'});
5728 # get list of changed files
5729 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5730 $co{'parent'} || "--root",
5731 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5733 my @difftree = map { chomp; $_ } <$fd>;
5737 # print element (entry, item)
5738 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5739 if ($format eq 'rss') {
5741 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5742 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5743 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5744 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5745 "<link>$co_url</link>\n" .
5746 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5747 "<content:encoded>" .
5749 } elsif ($format eq 'atom') {
5751 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5752 "<updated>$cd{'iso-8601'}</updated>\n" .
5754 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5755 if ($co{'author_email'}) {
5756 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5758 print "</author>\n" .
5759 # use committer for contributor
5761 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5762 if ($co{'committer_email'}) {
5763 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5765 print "</contributor>\n" .
5766 "<published>$cd{'iso-8601'}</published>\n" .
5767 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5768 "<id>$co_url</id>\n" .
5769 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5770 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5772 my $comment = $co{'comment'};
5774 foreach my $line (@$comment) {
5775 $line = esc_html
($line);
5778 print "</pre><ul>\n";
5779 foreach my $difftree_line (@difftree) {
5780 my %difftree = parse_difftree_raw_line
($difftree_line);
5781 next if !$difftree{'from_id'};
5783 my $file = $difftree{'file'} || $difftree{'to_file'};
5787 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5788 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5789 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5790 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5791 -title
=> "diff"}, 'D');
5793 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5794 file_name
=>$file, hash_base
=>$commit),
5795 -title
=> "blame"}, 'B');
5797 # if this is not a feed of a file history
5798 if (!defined $file_name || $file_name ne $file) {
5799 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5800 file_name
=>$file, hash
=>$commit),
5801 -title
=> "history"}, 'H');
5803 $file = esc_path
($file);
5807 if ($format eq 'rss') {
5808 print "</ul>]]>\n" .
5809 "</content:encoded>\n" .
5811 } elsif ($format eq 'atom') {
5812 print "</ul>\n</div>\n" .
5819 if ($format eq 'rss') {
5820 print "</channel>\n</rss>\n";
5821 } elsif ($format eq 'atom') {
5835 my @list = git_get_projects_list
();
5837 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5839 <?xml version="1.0" encoding="utf-8"?>
5840 <opml version="1.0">
5842 <title>$site_name OPML Export</title>
5845 <outline text="git RSS feeds">
5848 foreach my $pr (@list) {
5850 my $head = git_get_head_hash
($proj{'path'});
5851 if (!defined $head) {
5854 $git_dir = "$projectroot/$proj{'path'}";
5855 my %co = parse_commit
($head);
5860 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5861 my $rss = "$my_url?p=$proj{'path'};a=rss";
5862 my $html = "$my_url?p=$proj{'path'};a=summary";
5863 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";