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 # if we're called with PATH_INFO, we have to strip that
31 # from the URL to find our real URL
32 if (my $path_info = $ENV{"PATH_INFO"}) {
33 $my_url =~ s
,\Q
$path_info\E
$,,;
34 $my_uri =~ s
,\Q
$path_info\E
$,,;
37 # core git executable to use
38 # this can just be "git" if your webserver has a sensible PATH
39 our $GIT = "++GIT_BINDIR++/git";
41 # absolute fs-path which will be prepended to the project path
42 #our $projectroot = "/pub/scm";
43 our $projectroot = "++GITWEB_PROJECTROOT++";
45 # fs traversing limit for getting project list
46 # the number is relative to the projectroot
47 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
49 # target of the home link on top of all pages
50 our $home_link = $my_uri || "/";
52 # string of the home link on top of all pages
53 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
55 # name of your site or organization to appear in page titles
56 # replace this with something more descriptive for clearer bookmarks
57 our $site_name = "++GITWEB_SITENAME++"
58 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
60 # filename of html text to include at top of each page
61 our $site_header = "++GITWEB_SITE_HEADER++";
62 # html text to include at home page
63 our $home_text = "++GITWEB_HOMETEXT++";
64 # filename of html text to include at bottom of each page
65 our $site_footer = "++GITWEB_SITE_FOOTER++";
68 our @stylesheets = ("++GITWEB_CSS++");
69 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
70 our $stylesheet = undef;
72 # URI of GIT logo (72x27 size)
73 our $logo = "++GITWEB_LOGO++";
74 # URI of GIT favicon, assumed to be image/png type
75 our $favicon = "++GITWEB_FAVICON++";
77 # URI and label (title) of GIT logo link
78 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
79 #our $logo_label = "git documentation";
80 our $logo_url = "http://git.or.cz/";
81 our $logo_label = "git homepage";
83 # source of projects list
84 our $projects_list = "++GITWEB_LIST++";
86 # the width (in characters) of the projects list "Description" column
87 our $projects_list_description_width = 25;
89 # default order of projects list
90 # valid values are none, project, descr, owner, and age
91 our $default_projects_order = "project";
93 # show repository only if this file exists
94 # (only effective if this variable evaluates to true)
95 our $export_ok = "++GITWEB_EXPORT_OK++";
97 # only allow viewing of repositories also shown on the overview page
98 our $strict_export = "++GITWEB_STRICT_EXPORT++";
100 # list of git base URLs used for URL to where fetch project from,
101 # i.e. full URL is "$git_base_url/$project"
102 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
104 # default blob_plain mimetype and default charset for text/plain blob
105 our $default_blob_plain_mimetype = 'text/plain';
106 our $default_text_plain_charset = undef;
108 # file to use for guessing MIME types before trying /etc/mime.types
109 # (relative to the current git repository)
110 our $mimetypes_file = undef;
112 # assume this charset if line contains non-UTF-8 characters;
113 # it should be valid encoding (see Encoding::Supported(3pm) for list),
114 # for which encoding all byte sequences are valid, for example
115 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
116 # could be even 'utf-8' for the old behavior)
117 our $fallback_encoding = 'latin1';
119 # rename detection options for git-diff and git-diff-tree
120 # - default is '-M', with the cost proportional to
121 # (number of removed files) * (number of new files).
122 # - more costly is '-C' (which implies '-M'), with the cost proportional to
123 # (number of changed files + number of removed files) * (number of new files)
124 # - even more costly is '-C', '--find-copies-harder' with cost
125 # (number of files in the original tree) * (number of new files)
126 # - one might want to include '-B' option, e.g. '-B', '-M'
127 our @diff_opts = ('-M'); # taken from git_commit
129 # information about snapshot formats that gitweb is capable of serving
130 our %known_snapshot_formats = (
132 # 'display' => display name,
133 # 'type' => mime type,
134 # 'suffix' => filename suffix,
135 # 'format' => --format for git-archive,
136 # 'compressor' => [compressor command and arguments]
137 # (array reference, optional)}
140 'display' => 'tar.gz',
141 'type' => 'application/x-gzip',
142 'suffix' => '.tar.gz',
144 'compressor' => ['gzip']},
147 'display' => 'tar.bz2',
148 'type' => 'application/x-bzip2',
149 'suffix' => '.tar.bz2',
151 'compressor' => ['bzip2']},
155 'type' => 'application/x-zip',
160 # Aliases so we understand old gitweb.snapshot values in repository
162 our %known_snapshot_format_aliases = (
166 # backward compatibility: legacy gitweb config support
167 'x-gzip' => undef, 'gz' => undef,
168 'x-bzip2' => undef, 'bz2' => undef,
169 'x-zip' => undef, '' => undef,
172 # You define site-wide feature defaults here; override them with
173 # $GITWEB_CONFIG as necessary.
176 # 'sub' => feature-sub (subroutine),
177 # 'override' => allow-override (boolean),
178 # 'default' => [ default options...] (array reference)}
180 # if feature is overridable (it means that allow-override has true value),
181 # then feature-sub will be called with default options as parameters;
182 # return value of feature-sub indicates if to enable specified feature
184 # if there is no 'sub' key (no feature-sub), then feature cannot be
187 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
189 # Enable the 'blame' blob view, showing the last commit that modified
190 # each line in the file. This can be very CPU-intensive.
192 # To enable system wide have in $GITWEB_CONFIG
193 # $feature{'blame'}{'default'} = [1];
194 # To have project specific config enable override in $GITWEB_CONFIG
195 # $feature{'blame'}{'override'} = 1;
196 # and in project config gitweb.blame = 0|1;
198 'sub' => \
&feature_blame
,
202 # Enable the 'snapshot' link, providing a compressed archive of any
203 # tree. This can potentially generate high traffic if you have large
206 # Value is a list of formats defined in %known_snapshot_formats that
208 # To disable system wide have in $GITWEB_CONFIG
209 # $feature{'snapshot'}{'default'} = [];
210 # To have project specific config enable override in $GITWEB_CONFIG
211 # $feature{'snapshot'}{'override'} = 1;
212 # and in project config, a comma-separated list of formats or "none"
213 # to disable. Example: gitweb.snapshot = tbz2,zip;
215 'sub' => \
&feature_snapshot
,
217 'default' => ['tgz']},
219 # Enable text search, which will list the commits which match author,
220 # committer or commit text to a given string. Enabled by default.
221 # Project specific override is not supported.
226 # Enable grep search, which will list the files in currently selected
227 # tree containing the given string. Enabled by default. This can be
228 # potentially CPU-intensive, of course.
230 # To enable system wide have in $GITWEB_CONFIG
231 # $feature{'grep'}{'default'} = [1];
232 # To have project specific config enable override in $GITWEB_CONFIG
233 # $feature{'grep'}{'override'} = 1;
234 # and in project config gitweb.grep = 0|1;
239 # Enable the pickaxe search, which will list the commits that modified
240 # a given string in a file. This can be practical and quite faster
241 # alternative to 'blame', but still potentially CPU-intensive.
243 # To enable system wide have in $GITWEB_CONFIG
244 # $feature{'pickaxe'}{'default'} = [1];
245 # To have project specific config enable override in $GITWEB_CONFIG
246 # $feature{'pickaxe'}{'override'} = 1;
247 # and in project config gitweb.pickaxe = 0|1;
249 'sub' => \
&feature_pickaxe
,
253 # Make gitweb use an alternative format of the URLs which can be
254 # more readable and natural-looking: project name is embedded
255 # directly in the path and the query string contains other
256 # auxiliary information. All gitweb installations recognize
257 # URL in either format; this configures in which formats gitweb
260 # To enable system wide have in $GITWEB_CONFIG
261 # $feature{'pathinfo'}{'default'} = [1];
262 # Project specific override is not supported.
264 # Note that you will need to change the default location of CSS,
265 # favicon, logo and possibly other files to an absolute URL. Also,
266 # if gitweb.cgi serves as your indexfile, you will need to force
267 # $my_uri to contain the script name in your $GITWEB_CONFIG.
272 # Make gitweb consider projects in project root subdirectories
273 # to be forks of existing projects. Given project $projname.git,
274 # projects matching $projname/*.git will not be shown in the main
275 # projects list, instead a '+' mark will be added to $projname
276 # there and a 'forks' view will be enabled for the project, listing
277 # all the forks. If project list is taken from a file, forks have
278 # to be listed after the main project.
280 # To enable system wide have in $GITWEB_CONFIG
281 # $feature{'forks'}{'default'} = [1];
282 # Project specific override is not supported.
287 # Insert custom links to the action bar of all project pages.
288 # This enables you mainly to link to third-party scripts integrating
289 # into gitweb; e.g. git-browser for graphical history representation
290 # or custom web-based repository administration interface.
292 # The 'default' value consists of a list of triplets in the form
293 # (label, link, position) where position is the label after which
294 # to insert the link and link is a format string where %n expands
295 # to the project name, %f to the project path within the filesystem,
296 # %h to the current hash (h gitweb parameter) and %b to the current
297 # hash base (hb gitweb parameter); %% expands to %.
299 # To enable system wide have in $GITWEB_CONFIG e.g.
300 # $feature{'actions'}{'default'} = [('graphiclog',
301 # '/git-browser/by-commit.html?r=%n', 'summary')];
302 # Project specific override is not supported.
307 # Allow gitweb scan project content tags described in ctags/
308 # of project repository, and display the popular Web 2.0-ish
309 # "tag cloud" near the project list. Note that this is something
310 # COMPLETELY different from the normal Git tags.
312 # gitweb by itself can show existing tags, but it does not handle
313 # tagging itself; you need an external application for that.
314 # For an example script, check Girocco's cgi/tagproj.cgi.
315 # You may want to install the HTML::TagCloud Perl module to get
316 # a pretty tag cloud instead of just a list of tags.
318 # To enable system wide have in $GITWEB_CONFIG
319 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
320 # Project specific override is not supported.
326 sub gitweb_check_feature
{
328 return unless exists $feature{$name};
329 my ($sub, $override, @defaults) = (
330 $feature{$name}{'sub'},
331 $feature{$name}{'override'},
332 @{$feature{$name}{'default'}});
333 if (!$override) { return @defaults; }
335 warn "feature $name is not overrideable";
338 return $sub->(@defaults);
342 my ($val) = git_get_project_config
('blame', '--bool');
344 if ($val eq 'true') {
346 } elsif ($val eq 'false') {
353 sub feature_snapshot
{
356 my ($val) = git_get_project_config
('snapshot');
359 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
366 my ($val) = git_get_project_config
('grep', '--bool');
368 if ($val eq 'true') {
370 } elsif ($val eq 'false') {
377 sub feature_pickaxe
{
378 my ($val) = git_get_project_config
('pickaxe', '--bool');
380 if ($val eq 'true') {
382 } elsif ($val eq 'false') {
389 # checking HEAD file with -e is fragile if the repository was
390 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
392 sub check_head_link
{
394 my $headfile = "$dir/HEAD";
395 return ((-e
$headfile) ||
396 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
399 sub check_export_ok
{
401 return (check_head_link
($dir) &&
402 (!$export_ok || -e
"$dir/$export_ok"));
405 # process alternate names for backward compatibility
406 # filter out unsupported (unknown) snapshot formats
407 sub filter_snapshot_fmts
{
411 exists $known_snapshot_format_aliases{$_} ?
412 $known_snapshot_format_aliases{$_} : $_} @fmts;
413 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
417 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
418 if (-e
$GITWEB_CONFIG) {
421 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
422 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
425 # version of the core git binary
426 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
428 $projects_list ||= $projectroot;
430 # ======================================================================
431 # input validation and dispatch
432 our $action = $cgi->param('a');
433 if (defined $action) {
434 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
435 die_error
(400, "Invalid action parameter");
439 # parameters which are pathnames
440 our $project = $cgi->param('p');
441 if (defined $project) {
442 if (!validate_pathname
($project) ||
443 !(-d
"$projectroot/$project") ||
444 !check_head_link
("$projectroot/$project") ||
445 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
446 ($strict_export && !project_in_list
($project))) {
448 die_error
(404, "No such project");
452 our $file_name = $cgi->param('f');
453 if (defined $file_name) {
454 if (!validate_pathname
($file_name)) {
455 die_error
(400, "Invalid file parameter");
459 our $file_parent = $cgi->param('fp');
460 if (defined $file_parent) {
461 if (!validate_pathname
($file_parent)) {
462 die_error
(400, "Invalid file parent parameter");
466 # parameters which are refnames
467 our $hash = $cgi->param('h');
469 if (!validate_refname
($hash)) {
470 die_error
(400, "Invalid hash parameter");
474 our $hash_parent = $cgi->param('hp');
475 if (defined $hash_parent) {
476 if (!validate_refname
($hash_parent)) {
477 die_error
(400, "Invalid hash parent parameter");
481 our $hash_base = $cgi->param('hb');
482 if (defined $hash_base) {
483 if (!validate_refname
($hash_base)) {
484 die_error
(400, "Invalid hash base parameter");
488 my %allowed_options = (
489 "--no-merges" => [ qw(rss atom log shortlog history) ],
492 our @extra_options = $cgi->param('opt');
493 if (defined @extra_options) {
494 foreach my $opt (@extra_options) {
495 if (not exists $allowed_options{$opt}) {
496 die_error
(400, "Invalid option parameter");
498 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
499 die_error
(400, "Invalid option parameter for this action");
504 our $hash_parent_base = $cgi->param('hpb');
505 if (defined $hash_parent_base) {
506 if (!validate_refname
($hash_parent_base)) {
507 die_error
(400, "Invalid hash parent base parameter");
512 our $page = $cgi->param('pg');
514 if ($page =~ m/[^0-9]/) {
515 die_error
(400, "Invalid page parameter");
519 our $searchtype = $cgi->param('st');
520 if (defined $searchtype) {
521 if ($searchtype =~ m/[^a-z]/) {
522 die_error
(400, "Invalid searchtype parameter");
526 our $search_use_regexp = $cgi->param('sr');
528 our $searchtext = $cgi->param('s');
530 if (defined $searchtext) {
531 if (length($searchtext) < 2) {
532 die_error
(403, "At least two characters are required for search parameter");
534 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
537 # now read PATH_INFO and use it as alternative to parameters
538 sub evaluate_path_info
{
539 return if defined $project;
540 my $path_info = $ENV{"PATH_INFO"};
541 return if !$path_info;
542 $path_info =~ s
,^/+,,;
543 return if !$path_info;
544 # find which part of PATH_INFO is project
545 $project = $path_info;
547 while ($project && !check_head_link
("$projectroot/$project")) {
548 $project =~ s
,/*[^/]*$,,;
551 $project = validate_pathname
($project);
553 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
554 ($strict_export && !project_in_list
($project))) {
558 # do not change any parameters if an action is given using the query string
560 $path_info =~ s
,^\Q
$project\E
/*,,;
561 my ($refname, $pathname) = split(/:/, $path_info, 2);
562 if (defined $pathname) {
563 # we got "project.git/branch:filename" or "project.git/branch:dir/"
564 # we could use git_get_type(branch:pathname), but it needs $git_dir
565 $pathname =~ s
,^/+,,;
566 if (!$pathname || substr($pathname, -1) eq "/") {
570 $action ||= "blob_plain";
572 $hash_base ||= validate_refname
($refname);
573 $file_name ||= validate_pathname
($pathname);
574 } elsif (defined $refname) {
575 # we got "project.git/branch"
576 $action ||= "shortlog";
577 $hash ||= validate_refname
($refname);
580 evaluate_path_info
();
582 # path to the current git repository
584 $git_dir = "$projectroot/$project" if $project;
588 "blame" => \
&git_blame
,
589 "blobdiff" => \
&git_blobdiff
,
590 "blobdiff_plain" => \
&git_blobdiff_plain
,
591 "blob" => \
&git_blob
,
592 "blob_plain" => \
&git_blob_plain
,
593 "commitdiff" => \
&git_commitdiff
,
594 "commitdiff_plain" => \
&git_commitdiff_plain
,
595 "commit" => \
&git_commit
,
596 "forks" => \
&git_forks
,
597 "heads" => \
&git_heads
,
598 "history" => \
&git_history
,
601 "atom" => \
&git_atom
,
602 "search" => \
&git_search
,
603 "search_help" => \
&git_search_help
,
604 "shortlog" => \
&git_shortlog
,
605 "summary" => \
&git_summary
,
607 "tags" => \
&git_tags
,
608 "tree" => \
&git_tree
,
609 "snapshot" => \
&git_snapshot
,
610 "object" => \
&git_object
,
611 # those below don't need $project
612 "opml" => \
&git_opml
,
613 "project_list" => \
&git_project_list
,
614 "project_index" => \
&git_project_index
,
617 if (!defined $action) {
619 $action = git_get_type
($hash);
620 } elsif (defined $hash_base && defined $file_name) {
621 $action = git_get_type
("$hash_base:$file_name");
622 } elsif (defined $project) {
625 $action = 'project_list';
628 if (!defined($actions{$action})) {
629 die_error
(400, "Unknown action");
631 if ($action !~ m/^(opml|project_list|project_index)$/ &&
633 die_error
(400, "Project needed");
635 $actions{$action}->();
638 ## ======================================================================
643 # default is to use -absolute url() i.e. $my_uri
644 my $href = $params{-full
} ? $my_url : $my_uri;
646 # XXX: Warning: If you touch this, check the search form for updating,
657 hash_parent_base
=> "hpb",
662 snapshot_format
=> "sf",
663 extra_options
=> "opt",
664 search_use_regexp
=> "sr",
666 my %mapping = @mapping;
668 $params{'project'} = $project unless exists $params{'project'};
670 if ($params{-replay
}) {
671 while (my ($name, $symbol) = each %mapping) {
672 if (!exists $params{$name}) {
673 # to allow for multivalued params we use arrayref form
674 $params{$name} = [ $cgi->param($symbol) ];
679 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
681 # use PATH_INFO for project name
682 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
683 delete $params{'project'};
685 # Summary just uses the project path URL
686 if (defined $params{'action'} && $params{'action'} eq 'summary') {
687 delete $params{'action'};
691 # now encode the parameters explicitly
693 for (my $i = 0; $i < @mapping; $i += 2) {
694 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
695 if (defined $params{$name}) {
696 if (ref($params{$name}) eq "ARRAY") {
697 foreach my $par (@{$params{$name}}) {
698 push @result, $symbol . "=" . esc_param
($par);
701 push @result, $symbol . "=" . esc_param
($params{$name});
705 $href .= "?" . join(';', @result) if scalar @result;
711 ## ======================================================================
712 ## validation, quoting/unquoting and escaping
714 sub validate_pathname
{
715 my $input = shift || return undef;
717 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
718 # at the beginning, at the end, and between slashes.
719 # also this catches doubled slashes
720 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
724 if ($input =~ m!\0!) {
730 sub validate_refname
{
731 my $input = shift || return undef;
733 # textual hashes are O.K.
734 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
737 # it must be correct pathname
738 $input = validate_pathname
($input)
740 # restrictions on ref name according to git-check-ref-format
741 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
747 # decode sequences of octets in utf8 into Perl's internal form,
748 # which is utf-8 with utf8 flag set if needed. gitweb writes out
749 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
752 if (utf8
::valid
($str)) {
756 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
760 # quote unsafe chars, but keep the slash, even when it's not
761 # correct, but quoted slashes look too horrible in bookmarks
764 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
770 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
773 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
779 # replace invalid utf8 character with SUBSTITUTION sequence
784 $str = to_utf8
($str);
785 $str = $cgi->escapeHTML($str);
786 if ($opts{'-nbsp'}) {
787 $str =~ s/ / /g;
789 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
793 # quote control characters and escape filename to HTML
798 $str = to_utf8
($str);
799 $str = $cgi->escapeHTML($str);
800 if ($opts{'-nbsp'}) {
801 $str =~ s/ / /g;
803 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
807 # Make control characters "printable", using character escape codes (CEC)
811 my %es = ( # character escape codes, aka escape sequences
812 "\t" => '\t', # tab (HT)
813 "\n" => '\n', # line feed (LF)
814 "\r" => '\r', # carrige return (CR)
815 "\f" => '\f', # form feed (FF)
816 "\b" => '\b', # backspace (BS)
817 "\a" => '\a', # alarm (bell) (BEL)
818 "\e" => '\e', # escape (ESC)
819 "\013" => '\v', # vertical tab (VT)
820 "\000" => '\0', # nul character (NUL)
822 my $chr = ( (exists $es{$cntrl})
824 : sprintf('\%2x', ord($cntrl)) );
825 if ($opts{-nohtml
}) {
828 return "<span class=\"cntrl\">$chr</span>";
832 # Alternatively use unicode control pictures codepoints,
833 # Unicode "printable representation" (PR)
838 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
839 if ($opts{-nohtml
}) {
842 return "<span class=\"cntrl\">$chr</span>";
846 # git may return quoted and escaped filenames
852 my %es = ( # character escape codes, aka escape sequences
853 't' => "\t", # tab (HT, TAB)
854 'n' => "\n", # newline (NL)
855 'r' => "\r", # return (CR)
856 'f' => "\f", # form feed (FF)
857 'b' => "\b", # backspace (BS)
858 'a' => "\a", # alarm (bell) (BEL)
859 'e' => "\e", # escape (ESC)
860 'v' => "\013", # vertical tab (VT)
863 if ($seq =~ m/^[0-7]{1,3}$/) {
864 # octal char sequence
865 return chr(oct($seq));
866 } elsif (exists $es{$seq}) {
867 # C escape sequence, aka character escape code
870 # quoted ordinary character
874 if ($str =~ m/^"(.*)"$/) {
877 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
882 # escape tabs (convert tabs to spaces)
886 while ((my $pos = index($line, "\t")) != -1) {
887 if (my $count = (8 - ($pos % 8))) {
888 my $spaces = ' ' x
$count;
889 $line =~ s/\t/$spaces/;
896 sub project_in_list
{
898 my @list = git_get_projects_list
();
899 return @list && scalar(grep { $_->{'path'} eq $project } @list);
902 ## ----------------------------------------------------------------------
903 ## HTML aware string manipulation
905 # Try to chop given string on a word boundary between position
906 # $len and $len+$add_len. If there is no word boundary there,
907 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
908 # (marking chopped part) would be longer than given string.
912 my $add_len = shift || 10;
913 my $where = shift || 'right'; # 'left' | 'center' | 'right'
915 # Make sure perl knows it is utf8 encoded so we don't
916 # cut in the middle of a utf8 multibyte char.
917 $str = to_utf8
($str);
919 # allow only $len chars, but don't cut a word if it would fit in $add_len
920 # if it doesn't fit, cut it if it's still longer than the dots we would add
921 # remove chopped character entities entirely
923 # when chopping in the middle, distribute $len into left and right part
924 # return early if chopping wouldn't make string shorter
925 if ($where eq 'center') {
926 return $str if ($len + 5 >= length($str)); # filler is length 5
929 return $str if ($len + 4 >= length($str)); # filler is length 4
932 # regexps: ending and beginning with word part up to $add_len
933 my $endre = qr/.{$len}\w{0,$add_len}/;
934 my $begre = qr/\w{0,$add_len}.{$len}/;
936 if ($where eq 'left') {
937 $str =~ m/^(.*?)($begre)$/;
938 my ($lead, $body) = ($1, $2);
939 if (length($lead) > 4) {
940 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
945 } elsif ($where eq 'center') {
946 $str =~ m/^($endre)(.*)$/;
947 my ($left, $str) = ($1, $2);
948 $str =~ m/^(.*?)($begre)$/;
949 my ($mid, $right) = ($1, $2);
950 if (length($mid) > 5) {
951 $left =~ s/&[^;]*$//;
952 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
955 return "$left$mid$right";
958 $str =~ m/^($endre)(.*)$/;
961 if (length($tail) > 4) {
962 $body =~ s/&[^;]*$//;
969 # takes the same arguments as chop_str, but also wraps a <span> around the
970 # result with a title attribute if it does get chopped. Additionally, the
971 # string is HTML-escaped.
972 sub chop_and_escape_str
{
975 my $chopped = chop_str
(@_);
976 if ($chopped eq $str) {
977 return esc_html
($chopped);
979 $str =~ s/([[:cntrl:]])/?/g;
980 return $cgi->span({-title
=>$str}, esc_html
($chopped));
984 ## ----------------------------------------------------------------------
985 ## functions returning short strings
987 # CSS class for given age value (in seconds)
993 } elsif ($age < 60*60*2) {
995 } elsif ($age < 60*60*24*2) {
1002 # convert age in seconds to "nn units ago" string
1007 if ($age > 60*60*24*365*2) {
1008 $age_str = (int $age/60/60/24/365);
1009 $age_str .= " years ago";
1010 } elsif ($age > 60*60*24*(365/12)*2) {
1011 $age_str = int $age/60/60/24/(365/12);
1012 $age_str .= " months ago";
1013 } elsif ($age > 60*60*24*7*2) {
1014 $age_str = int $age/60/60/24/7;
1015 $age_str .= " weeks ago";
1016 } elsif ($age > 60*60*24*2) {
1017 $age_str = int $age/60/60/24;
1018 $age_str .= " days ago";
1019 } elsif ($age > 60*60*2) {
1020 $age_str = int $age/60/60;
1021 $age_str .= " hours ago";
1022 } elsif ($age > 60*2) {
1023 $age_str = int $age/60;
1024 $age_str .= " min ago";
1025 } elsif ($age > 2) {
1026 $age_str = int $age;
1027 $age_str .= " sec ago";
1029 $age_str .= " right now";
1035 S_IFINVALID
=> 0030000,
1036 S_IFGITLINK
=> 0160000,
1039 # submodule/subproject, a commit object reference
1040 sub S_ISGITLINK
($) {
1043 return (($mode & S_IFMT
) == S_IFGITLINK
)
1046 # convert file mode in octal to symbolic file mode string
1048 my $mode = oct shift;
1050 if (S_ISGITLINK
($mode)) {
1051 return 'm---------';
1052 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1053 return 'drwxr-xr-x';
1054 } elsif (S_ISLNK
($mode)) {
1055 return 'lrwxrwxrwx';
1056 } elsif (S_ISREG
($mode)) {
1057 # git cares only about the executable bit
1058 if ($mode & S_IXUSR
) {
1059 return '-rwxr-xr-x';
1061 return '-rw-r--r--';
1064 return '----------';
1068 # convert file mode in octal to file type string
1072 if ($mode !~ m/^[0-7]+$/) {
1078 if (S_ISGITLINK
($mode)) {
1080 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1082 } elsif (S_ISLNK
($mode)) {
1084 } elsif (S_ISREG
($mode)) {
1091 # convert file mode in octal to file type description string
1092 sub file_type_long
{
1095 if ($mode !~ m/^[0-7]+$/) {
1101 if (S_ISGITLINK
($mode)) {
1103 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1105 } elsif (S_ISLNK
($mode)) {
1107 } elsif (S_ISREG
($mode)) {
1108 if ($mode & S_IXUSR
) {
1109 return "executable";
1119 ## ----------------------------------------------------------------------
1120 ## functions returning short HTML fragments, or transforming HTML fragments
1121 ## which don't belong to other sections
1123 # format line of commit message.
1124 sub format_log_line_html
{
1127 $line = esc_html
($line, -nbsp
=>1);
1128 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1131 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1132 -class => "text"}, $hash_text);
1133 $line =~ s/$hash_text/$link/;
1138 # format marker of refs pointing to given object
1140 # the destination action is chosen based on object type and current context:
1141 # - for annotated tags, we choose the tag view unless it's the current view
1142 # already, in which case we go to shortlog view
1143 # - for other refs, we keep the current view if we're in history, shortlog or
1144 # log view, and select shortlog otherwise
1145 sub format_ref_marker
{
1146 my ($refs, $id) = @_;
1149 if (defined $refs->{$id}) {
1150 foreach my $ref (@{$refs->{$id}}) {
1151 # this code exploits the fact that non-lightweight tags are the
1152 # only indirect objects, and that they are the only objects for which
1153 # we want to use tag instead of shortlog as action
1154 my ($type, $name) = qw();
1155 my $indirect = ($ref =~ s/\^\{\}$//);
1156 # e.g. tags/v2.6.11 or heads/next
1157 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1166 $class .= " indirect" if $indirect;
1168 my $dest_action = "shortlog";
1171 $dest_action = "tag" unless $action eq "tag";
1172 } elsif ($action =~ /^(history|(short)?log)$/) {
1173 $dest_action = $action;
1177 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1180 my $link = $cgi->a({
1182 action
=>$dest_action,
1186 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1192 return ' <span class="refs">'. $markers . '</span>';
1198 # format, perhaps shortened and with markers, title line
1199 sub format_subject_html
{
1200 my ($long, $short, $href, $extra) = @_;
1201 $extra = '' unless defined($extra);
1203 if (length($short) < length($long)) {
1204 return $cgi->a({-href
=> $href, -class => "list subject",
1205 -title
=> to_utf8
($long)},
1206 esc_html
($short) . $extra);
1208 return $cgi->a({-href
=> $href, -class => "list subject"},
1209 esc_html
($long) . $extra);
1213 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1214 sub format_git_diff_header_line
{
1216 my $diffinfo = shift;
1217 my ($from, $to) = @_;
1219 if ($diffinfo->{'nparents'}) {
1221 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1222 if ($to->{'href'}) {
1223 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1224 esc_path
($to->{'file'}));
1225 } else { # file was deleted (no href)
1226 $line .= esc_path
($to->{'file'});
1230 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1231 if ($from->{'href'}) {
1232 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1233 'a/' . esc_path
($from->{'file'}));
1234 } else { # file was added (no href)
1235 $line .= 'a/' . esc_path
($from->{'file'});
1238 if ($to->{'href'}) {
1239 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1240 'b/' . esc_path
($to->{'file'}));
1241 } else { # file was deleted
1242 $line .= 'b/' . esc_path
($to->{'file'});
1246 return "<div class=\"diff header\">$line</div>\n";
1249 # format extended diff header line, before patch itself
1250 sub format_extended_diff_header_line
{
1252 my $diffinfo = shift;
1253 my ($from, $to) = @_;
1256 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1257 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1258 esc_path
($from->{'file'}));
1260 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1261 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1262 esc_path
($to->{'file'}));
1264 # match single <mode>
1265 if ($line =~ m/\s(\d{6})$/) {
1266 $line .= '<span class="info"> (' .
1267 file_type_long
($1) .
1271 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1272 # can match only for combined diff
1274 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1275 if ($from->{'href'}[$i]) {
1276 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1278 substr($diffinfo->{'from_id'}[$i],0,7));
1283 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1286 if ($to->{'href'}) {
1287 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1288 substr($diffinfo->{'to_id'},0,7));
1293 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1294 # can match only for ordinary diff
1295 my ($from_link, $to_link);
1296 if ($from->{'href'}) {
1297 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1298 substr($diffinfo->{'from_id'},0,7));
1300 $from_link = '0' x
7;
1302 if ($to->{'href'}) {
1303 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1304 substr($diffinfo->{'to_id'},0,7));
1308 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1309 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1312 return $line . "<br/>\n";
1315 # format from-file/to-file diff header
1316 sub format_diff_from_to_header
{
1317 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1322 #assert($line =~ m/^---/) if DEBUG;
1323 # no extra formatting for "^--- /dev/null"
1324 if (! $diffinfo->{'nparents'}) {
1325 # ordinary (single parent) diff
1326 if ($line =~ m!^--- "?a/!) {
1327 if ($from->{'href'}) {
1329 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1330 esc_path
($from->{'file'}));
1333 esc_path
($from->{'file'});
1336 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1339 # combined diff (merge commit)
1340 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1341 if ($from->{'href'}[$i]) {
1343 $cgi->a({-href
=>href
(action
=>"blobdiff",
1344 hash_parent
=>$diffinfo->{'from_id'}[$i],
1345 hash_parent_base
=>$parents[$i],
1346 file_parent
=>$from->{'file'}[$i],
1347 hash
=>$diffinfo->{'to_id'},
1349 file_name
=>$to->{'file'}),
1351 -title
=>"diff" . ($i+1)},
1354 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1355 esc_path
($from->{'file'}[$i]));
1357 $line = '--- /dev/null';
1359 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1364 #assert($line =~ m/^\+\+\+/) if DEBUG;
1365 # no extra formatting for "^+++ /dev/null"
1366 if ($line =~ m!^\+\+\+ "?b/!) {
1367 if ($to->{'href'}) {
1369 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1370 esc_path
($to->{'file'}));
1373 esc_path
($to->{'file'});
1376 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1381 # create note for patch simplified by combined diff
1382 sub format_diff_cc_simplified
{
1383 my ($diffinfo, @parents) = @_;
1386 $result .= "<div class=\"diff header\">" .
1388 if (!is_deleted
($diffinfo)) {
1389 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1391 hash
=>$diffinfo->{'to_id'},
1392 file_name
=>$diffinfo->{'to_file'}),
1394 esc_path
($diffinfo->{'to_file'}));
1396 $result .= esc_path
($diffinfo->{'to_file'});
1398 $result .= "</div>\n" . # class="diff header"
1399 "<div class=\"diff nodifferences\">" .
1401 "</div>\n"; # class="diff nodifferences"
1406 # format patch (diff) line (not to be used for diff headers)
1407 sub format_diff_line
{
1409 my ($from, $to) = @_;
1410 my $diff_class = "";
1414 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1416 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1417 if ($line =~ m/^\@{3}/) {
1418 $diff_class = " chunk_header";
1419 } elsif ($line =~ m/^\\/) {
1420 $diff_class = " incomplete";
1421 } elsif ($prefix =~ tr/+/+/) {
1422 $diff_class = " add";
1423 } elsif ($prefix =~ tr/-/-/) {
1424 $diff_class = " rem";
1427 # assume ordinary diff
1428 my $char = substr($line, 0, 1);
1430 $diff_class = " add";
1431 } elsif ($char eq '-') {
1432 $diff_class = " rem";
1433 } elsif ($char eq '@') {
1434 $diff_class = " chunk_header";
1435 } elsif ($char eq "\\") {
1436 $diff_class = " incomplete";
1439 $line = untabify
($line);
1440 if ($from && $to && $line =~ m/^\@{2} /) {
1441 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1442 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1444 $from_lines = 0 unless defined $from_lines;
1445 $to_lines = 0 unless defined $to_lines;
1447 if ($from->{'href'}) {
1448 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1449 -class=>"list"}, $from_text);
1451 if ($to->{'href'}) {
1452 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1453 -class=>"list"}, $to_text);
1455 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1456 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1457 return "<div class=\"diff$diff_class\">$line</div>\n";
1458 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1459 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1460 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1462 @from_text = split(' ', $ranges);
1463 for (my $i = 0; $i < @from_text; ++$i) {
1464 ($from_start[$i], $from_nlines[$i]) =
1465 (split(',', substr($from_text[$i], 1)), 0);
1468 $to_text = pop @from_text;
1469 $to_start = pop @from_start;
1470 $to_nlines = pop @from_nlines;
1472 $line = "<span class=\"chunk_info\">$prefix ";
1473 for (my $i = 0; $i < @from_text; ++$i) {
1474 if ($from->{'href'}[$i]) {
1475 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1476 -class=>"list"}, $from_text[$i]);
1478 $line .= $from_text[$i];
1482 if ($to->{'href'}) {
1483 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1484 -class=>"list"}, $to_text);
1488 $line .= " $prefix</span>" .
1489 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1490 return "<div class=\"diff$diff_class\">$line</div>\n";
1492 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1495 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1496 # linked. Pass the hash of the tree/commit to snapshot.
1497 sub format_snapshot_links
{
1499 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1500 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1501 my $num_fmts = @snapshot_fmts;
1502 if ($num_fmts > 1) {
1503 # A parenthesized list of links bearing format names.
1504 # e.g. "snapshot (_tar.gz_ _zip_)"
1505 return "snapshot (" . join(' ', map
1512 }, $known_snapshot_formats{$_}{'display'})
1513 , @snapshot_fmts) . ")";
1514 } elsif ($num_fmts == 1) {
1515 # A single "snapshot" link whose tooltip bears the format name.
1517 my ($fmt) = @snapshot_fmts;
1523 snapshot_format
=>$fmt
1525 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1527 } else { # $num_fmts == 0
1532 ## ......................................................................
1533 ## functions returning values to be passed, perhaps after some
1534 ## transformation, to other functions; e.g. returning arguments to href()
1536 # returns hash to be passed to href to generate gitweb URL
1537 # in -title key it returns description of link
1539 my $format = shift || 'Atom';
1540 my %res = (action
=> lc($format));
1542 # feed links are possible only for project views
1543 return unless (defined $project);
1544 # some views should link to OPML, or to generic project feed,
1545 # or don't have specific feed yet (so they should use generic)
1546 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1549 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1550 # from tag links; this also makes possible to detect branch links
1551 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1552 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1555 # find log type for feed description (title)
1557 if (defined $file_name) {
1558 $type = "history of $file_name";
1559 $type .= "/" if ($action eq 'tree');
1560 $type .= " on '$branch'" if (defined $branch);
1562 $type = "log of $branch" if (defined $branch);
1565 $res{-title
} = $type;
1566 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1567 $res{'file_name'} = $file_name;
1572 ## ----------------------------------------------------------------------
1573 ## git utility subroutines, invoking git commands
1575 # returns path to the core git executable and the --git-dir parameter as list
1577 return $GIT, '--git-dir='.$git_dir;
1580 # quote the given arguments for passing them to the shell
1581 # quote_command("command", "arg 1", "arg with ' and ! characters")
1582 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1583 # Try to avoid using this function wherever possible.
1586 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1589 # get HEAD ref of given project as hash
1590 sub git_get_head_hash
{
1591 my $project = shift;
1592 my $o_git_dir = $git_dir;
1594 $git_dir = "$projectroot/$project";
1595 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1598 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1602 if (defined $o_git_dir) {
1603 $git_dir = $o_git_dir;
1608 # get type of given object
1612 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1614 close $fd or return;
1619 # repository configuration
1620 our $config_file = '';
1623 # store multiple values for single key as anonymous array reference
1624 # single values stored directly in the hash, not as [ <value> ]
1625 sub hash_set_multi
{
1626 my ($hash, $key, $value) = @_;
1628 if (!exists $hash->{$key}) {
1629 $hash->{$key} = $value;
1630 } elsif (!ref $hash->{$key}) {
1631 $hash->{$key} = [ $hash->{$key}, $value ];
1633 push @{$hash->{$key}}, $value;
1637 # return hash of git project configuration
1638 # optionally limited to some section, e.g. 'gitweb'
1639 sub git_parse_project_config
{
1640 my $section_regexp = shift;
1645 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1648 while (my $keyval = <$fh>) {
1650 my ($key, $value) = split(/\n/, $keyval, 2);
1652 hash_set_multi
(\
%config, $key, $value)
1653 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1660 # convert config value to boolean, 'true' or 'false'
1661 # no value, number > 0, 'true' and 'yes' values are true
1662 # rest of values are treated as false (never as error)
1663 sub config_to_bool
{
1666 # strip leading and trailing whitespace
1670 return (!defined $val || # section.key
1671 ($val =~ /^\d+$/ && $val) || # section.key = 1
1672 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1675 # convert config value to simple decimal number
1676 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1677 # to be multiplied by 1024, 1048576, or 1073741824
1681 # strip leading and trailing whitespace
1685 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1687 # unknown unit is treated as 1
1688 return $num * ($unit eq 'g' ? 1073741824 :
1689 $unit eq 'm' ? 1048576 :
1690 $unit eq 'k' ? 1024 : 1);
1695 # convert config value to array reference, if needed
1696 sub config_to_multi
{
1699 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1702 sub git_get_project_config
{
1703 my ($key, $type) = @_;
1706 return unless ($key);
1707 $key =~ s/^gitweb\.//;
1708 return if ($key =~ m/\W/);
1711 if (defined $type) {
1714 unless ($type eq 'bool' || $type eq 'int');
1718 if (!defined $config_file ||
1719 $config_file ne "$git_dir/config") {
1720 %config = git_parse_project_config
('gitweb');
1721 $config_file = "$git_dir/config";
1725 if (!defined $type) {
1726 return $config{"gitweb.$key"};
1727 } elsif ($type eq 'bool') {
1728 # backward compatibility: 'git config --bool' returns true/false
1729 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1730 } elsif ($type eq 'int') {
1731 return config_to_int
($config{"gitweb.$key"});
1733 return $config{"gitweb.$key"};
1736 # get hash of given path at given ref
1737 sub git_get_hash_by_path
{
1739 my $path = shift || return undef;
1744 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1745 or die_error
(500, "Open git-ls-tree failed");
1747 close $fd or return undef;
1749 if (!defined $line) {
1750 # there is no tree or hash given by $path at $base
1754 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1755 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1756 if (defined $type && $type ne $2) {
1757 # type doesn't match
1763 # get path of entry with given hash at given tree-ish (ref)
1764 # used to get 'from' filename for combined diff (merge commit) for renames
1765 sub git_get_path_by_hash
{
1766 my $base = shift || return;
1767 my $hash = shift || return;
1771 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1773 while (my $line = <$fd>) {
1776 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1777 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1778 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1787 ## ......................................................................
1788 ## git utility functions, directly accessing git repository
1790 sub git_get_project_description
{
1793 $git_dir = "$projectroot/$path";
1794 open my $fd, "$git_dir/description"
1795 or return git_get_project_config
('description');
1798 if (defined $descr) {
1804 sub git_get_project_ctags
{
1808 $git_dir = "$projectroot/$path";
1809 foreach (<$git_dir/ctags/*>) {
1810 open CT
, $_ or next;
1814 my $ctag = $_; $ctag =~ s
#.*/##;
1815 $ctags->{$ctag} = $val;
1820 sub git_populate_project_tagcloud
{
1823 # First, merge different-cased tags; tags vote on casing
1825 foreach (keys %$ctags) {
1826 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
1827 if (not $ctags_lc{lc $_}->{topcount
}
1828 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
1829 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
1830 $ctags_lc{lc $_}->{topname
} = $_;
1835 if (eval { require HTML
::TagCloud
; 1; }) {
1836 $cloud = HTML
::TagCloud-
>new;
1837 foreach (sort keys %ctags_lc) {
1838 # Pad the title with spaces so that the cloud looks
1840 my $title = $ctags_lc{$_}->{topname
};
1841 $title =~ s/ / /g;
1842 $title =~ s/^/ /g;
1843 $title =~ s/$/ /g;
1844 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
1847 $cloud = \
%ctags_lc;
1852 sub git_show_project_tagcloud
{
1853 my ($cloud, $count) = @_;
1854 print STDERR
ref($cloud)."..\n";
1855 if (ref $cloud eq 'HTML::TagCloud') {
1856 return $cloud->html_and_css($count);
1858 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
1859 return '<p align="center">' . join (', ', map {
1860 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
1861 } splice(@tags, 0, $count)) . '</p>';
1865 sub git_get_project_url_list
{
1868 $git_dir = "$projectroot/$path";
1869 open my $fd, "$git_dir/cloneurl"
1870 or return wantarray ?
1871 @{ config_to_multi
(git_get_project_config
('url')) } :
1872 config_to_multi
(git_get_project_config
('url'));
1873 my @git_project_url_list = map { chomp; $_ } <$fd>;
1876 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1879 sub git_get_projects_list
{
1884 $filter =~ s/\.git$//;
1886 my ($check_forks) = gitweb_check_feature
('forks');
1888 if (-d
$projects_list) {
1889 # search in directory
1890 my $dir = $projects_list . ($filter ? "/$filter" : '');
1891 # remove the trailing "/"
1893 my $pfxlen = length("$dir");
1894 my $pfxdepth = ($dir =~ tr!/!!);
1897 follow_fast
=> 1, # follow symbolic links
1898 follow_skip
=> 2, # ignore duplicates
1899 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1901 # skip project-list toplevel, if we get it.
1902 return if (m!^[/.]$!);
1903 # only directories can be git repositories
1904 return unless (-d
$_);
1905 # don't traverse too deep (Find is super slow on os x)
1906 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1907 $File::Find
::prune
= 1;
1911 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1912 # we check related file in $projectroot
1913 if (check_export_ok
("$projectroot/$filter/$subdir")) {
1914 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1915 $File::Find
::prune
= 1;
1920 } elsif (-f
$projects_list) {
1921 # read from file(url-encoded):
1922 # 'git%2Fgit.git Linus+Torvalds'
1923 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1924 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1926 open my ($fd), $projects_list or return;
1928 while (my $line = <$fd>) {
1930 my ($path, $owner) = split ' ', $line;
1931 $path = unescape
($path);
1932 $owner = unescape
($owner);
1933 if (!defined $path) {
1936 if ($filter ne '') {
1937 # looking for forks;
1938 my $pfx = substr($path, 0, length($filter));
1939 if ($pfx ne $filter) {
1942 my $sfx = substr($path, length($filter));
1943 if ($sfx !~ /^\/.*\
.git
$/) {
1946 } elsif ($check_forks) {
1948 foreach my $filter (keys %paths) {
1949 # looking for forks;
1950 my $pfx = substr($path, 0, length($filter));
1951 if ($pfx ne $filter) {
1954 my $sfx = substr($path, length($filter));
1955 if ($sfx !~ /^\/.*\
.git
$/) {
1958 # is a fork, don't include it in
1963 if (check_export_ok
("$projectroot/$path")) {
1966 owner
=> to_utf8
($owner),
1969 (my $forks_path = $path) =~ s/\.git$//;
1970 $paths{$forks_path}++;
1978 our $gitweb_project_owner = undef;
1979 sub git_get_project_list_from_file
{
1981 return if (defined $gitweb_project_owner);
1983 $gitweb_project_owner = {};
1984 # read from file (url-encoded):
1985 # 'git%2Fgit.git Linus+Torvalds'
1986 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1987 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1988 if (-f
$projects_list) {
1989 open (my $fd , $projects_list);
1990 while (my $line = <$fd>) {
1992 my ($pr, $ow) = split ' ', $line;
1993 $pr = unescape
($pr);
1994 $ow = unescape
($ow);
1995 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2001 sub git_get_project_owner
{
2002 my $project = shift;
2005 return undef unless $project;
2006 $git_dir = "$projectroot/$project";
2008 if (!defined $gitweb_project_owner) {
2009 git_get_project_list_from_file
();
2012 if (exists $gitweb_project_owner->{$project}) {
2013 $owner = $gitweb_project_owner->{$project};
2015 if (!defined $owner){
2016 $owner = git_get_project_config
('owner');
2018 if (!defined $owner) {
2019 $owner = get_file_owner
("$git_dir");
2025 sub git_get_last_activity
{
2029 $git_dir = "$projectroot/$path";
2030 open($fd, "-|", git_cmd
(), 'for-each-ref',
2031 '--format=%(committer)',
2032 '--sort=-committerdate',
2034 'refs/heads') or return;
2035 my $most_recent = <$fd>;
2036 close $fd or return;
2037 if (defined $most_recent &&
2038 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2040 my $age = time - $timestamp;
2041 return ($age, age_string
($age));
2043 return (undef, undef);
2046 sub git_get_references
{
2047 my $type = shift || "";
2049 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2050 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2051 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2052 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2055 while (my $line = <$fd>) {
2057 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2058 if (defined $refs{$1}) {
2059 push @{$refs{$1}}, $2;
2065 close $fd or return;
2069 sub git_get_rev_name_tags
{
2070 my $hash = shift || return undef;
2072 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2074 my $name_rev = <$fd>;
2077 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2080 # catches also '$hash undefined' output
2085 ## ----------------------------------------------------------------------
2086 ## parse to hash functions
2090 my $tz = shift || "-0000";
2093 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2094 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2095 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2096 $date{'hour'} = $hour;
2097 $date{'minute'} = $min;
2098 $date{'mday'} = $mday;
2099 $date{'day'} = $days[$wday];
2100 $date{'month'} = $months[$mon];
2101 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2102 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2103 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2104 $mday, $months[$mon], $hour ,$min;
2105 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2106 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2108 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2109 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2110 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2111 $date{'hour_local'} = $hour;
2112 $date{'minute_local'} = $min;
2113 $date{'tz_local'} = $tz;
2114 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2115 1900+$year, $mon+1, $mday,
2116 $hour, $min, $sec, $tz);
2125 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2126 $tag{'id'} = $tag_id;
2127 while (my $line = <$fd>) {
2129 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2130 $tag{'object'} = $1;
2131 } elsif ($line =~ m/^type (.+)$/) {
2133 } elsif ($line =~ m/^tag (.+)$/) {
2135 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2136 $tag{'author'} = $1;
2139 } elsif ($line =~ m/--BEGIN/) {
2140 push @comment, $line;
2142 } elsif ($line eq "") {
2146 push @comment, <$fd>;
2147 $tag{'comment'} = \
@comment;
2148 close $fd or return;
2149 if (!defined $tag{'name'}) {
2155 sub parse_commit_text
{
2156 my ($commit_text, $withparents) = @_;
2157 my @commit_lines = split '\n', $commit_text;
2160 pop @commit_lines; # Remove '\0'
2162 if (! @commit_lines) {
2166 my $header = shift @commit_lines;
2167 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2170 ($co{'id'}, my @parents) = split ' ', $header;
2171 while (my $line = shift @commit_lines) {
2172 last if $line eq "\n";
2173 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2175 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2177 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2179 $co{'author_epoch'} = $2;
2180 $co{'author_tz'} = $3;
2181 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2182 $co{'author_name'} = $1;
2183 $co{'author_email'} = $2;
2185 $co{'author_name'} = $co{'author'};
2187 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2188 $co{'committer'} = $1;
2189 $co{'committer_epoch'} = $2;
2190 $co{'committer_tz'} = $3;
2191 $co{'committer_name'} = $co{'committer'};
2192 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2193 $co{'committer_name'} = $1;
2194 $co{'committer_email'} = $2;
2196 $co{'committer_name'} = $co{'committer'};
2200 if (!defined $co{'tree'}) {
2203 $co{'parents'} = \
@parents;
2204 $co{'parent'} = $parents[0];
2206 foreach my $title (@commit_lines) {
2209 $co{'title'} = chop_str
($title, 80, 5);
2210 # remove leading stuff of merges to make the interesting part visible
2211 if (length($title) > 50) {
2212 $title =~ s/^Automatic //;
2213 $title =~ s/^merge (of|with) /Merge ... /i;
2214 if (length($title) > 50) {
2215 $title =~ s/(http|rsync):\/\///;
2217 if (length($title) > 50) {
2218 $title =~ s/(master|www|rsync)\.//;
2220 if (length($title) > 50) {
2221 $title =~ s/kernel.org:?//;
2223 if (length($title) > 50) {
2224 $title =~ s/\/pub\/scm//;
2227 $co{'title_short'} = chop_str
($title, 50, 5);
2231 if (! defined $co{'title'} || $co{'title'} eq "") {
2232 $co{'title'} = $co{'title_short'} = '(no commit message)';
2234 # remove added spaces
2235 foreach my $line (@commit_lines) {
2238 $co{'comment'} = \
@commit_lines;
2240 my $age = time - $co{'committer_epoch'};
2242 $co{'age_string'} = age_string
($age);
2243 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2244 if ($age > 60*60*24*7*2) {
2245 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2246 $co{'age_string_age'} = $co{'age_string'};
2248 $co{'age_string_date'} = $co{'age_string'};
2249 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2255 my ($commit_id) = @_;
2260 open my $fd, "-|", git_cmd
(), "rev-list",
2266 or die_error
(500, "Open git-rev-list failed");
2267 %co = parse_commit_text
(<$fd>, 1);
2274 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2282 open my $fd, "-|", git_cmd
(), "rev-list",
2285 ("--max-count=" . $maxcount),
2286 ("--skip=" . $skip),
2290 ($filename ? ($filename) : ())
2291 or die_error
(500, "Open git-rev-list failed");
2292 while (my $line = <$fd>) {
2293 my %co = parse_commit_text
($line);
2298 return wantarray ? @cos : \
@cos;
2301 # parse line of git-diff-tree "raw" output
2302 sub parse_difftree_raw_line
{
2306 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2307 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2308 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2309 $res{'from_mode'} = $1;
2310 $res{'to_mode'} = $2;
2311 $res{'from_id'} = $3;
2313 $res{'status'} = $5;
2314 $res{'similarity'} = $6;
2315 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2316 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2318 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2321 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2322 # combined diff (for merge commit)
2323 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2324 $res{'nparents'} = length($1);
2325 $res{'from_mode'} = [ split(' ', $2) ];
2326 $res{'to_mode'} = pop @{$res{'from_mode'}};
2327 $res{'from_id'} = [ split(' ', $3) ];
2328 $res{'to_id'} = pop @{$res{'from_id'}};
2329 $res{'status'} = [ split('', $4) ];
2330 $res{'to_file'} = unquote
($5);
2332 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2333 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2334 $res{'commit'} = $1;
2337 return wantarray ? %res : \
%res;
2340 # wrapper: return parsed line of git-diff-tree "raw" output
2341 # (the argument might be raw line, or parsed info)
2342 sub parsed_difftree_line
{
2343 my $line_or_ref = shift;
2345 if (ref($line_or_ref) eq "HASH") {
2346 # pre-parsed (or generated by hand)
2347 return $line_or_ref;
2349 return parse_difftree_raw_line
($line_or_ref);
2353 # parse line of git-ls-tree output
2354 sub parse_ls_tree_line
($;%) {
2359 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2360 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2368 $res{'name'} = unquote
($4);
2371 return wantarray ? %res : \
%res;
2374 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2375 sub parse_from_to_diffinfo
{
2376 my ($diffinfo, $from, $to, @parents) = @_;
2378 if ($diffinfo->{'nparents'}) {
2380 $from->{'file'} = [];
2381 $from->{'href'} = [];
2382 fill_from_file_info
($diffinfo, @parents)
2383 unless exists $diffinfo->{'from_file'};
2384 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2385 $from->{'file'}[$i] =
2386 defined $diffinfo->{'from_file'}[$i] ?
2387 $diffinfo->{'from_file'}[$i] :
2388 $diffinfo->{'to_file'};
2389 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2390 $from->{'href'}[$i] = href
(action
=>"blob",
2391 hash_base
=>$parents[$i],
2392 hash
=>$diffinfo->{'from_id'}[$i],
2393 file_name
=>$from->{'file'}[$i]);
2395 $from->{'href'}[$i] = undef;
2399 # ordinary (not combined) diff
2400 $from->{'file'} = $diffinfo->{'from_file'};
2401 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2402 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2403 hash
=>$diffinfo->{'from_id'},
2404 file_name
=>$from->{'file'});
2406 delete $from->{'href'};
2410 $to->{'file'} = $diffinfo->{'to_file'};
2411 if (!is_deleted
($diffinfo)) { # file exists in result
2412 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2413 hash
=>$diffinfo->{'to_id'},
2414 file_name
=>$to->{'file'});
2416 delete $to->{'href'};
2420 ## ......................................................................
2421 ## parse to array of hashes functions
2423 sub git_get_heads_list
{
2427 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2428 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2429 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2432 while (my $line = <$fd>) {
2436 my ($refinfo, $committerinfo) = split(/\0/, $line);
2437 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2438 my ($committer, $epoch, $tz) =
2439 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2440 $ref_item{'fullname'} = $name;
2441 $name =~ s!^refs/heads/!!;
2443 $ref_item{'name'} = $name;
2444 $ref_item{'id'} = $hash;
2445 $ref_item{'title'} = $title || '(no commit message)';
2446 $ref_item{'epoch'} = $epoch;
2448 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2450 $ref_item{'age'} = "unknown";
2453 push @headslist, \
%ref_item;
2457 return wantarray ? @headslist : \
@headslist;
2460 sub git_get_tags_list
{
2464 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2465 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2466 '--format=%(objectname) %(objecttype) %(refname) '.
2467 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2470 while (my $line = <$fd>) {
2474 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2475 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2476 my ($creator, $epoch, $tz) =
2477 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2478 $ref_item{'fullname'} = $name;
2479 $name =~ s!^refs/tags/!!;
2481 $ref_item{'type'} = $type;
2482 $ref_item{'id'} = $id;
2483 $ref_item{'name'} = $name;
2484 if ($type eq "tag") {
2485 $ref_item{'subject'} = $title;
2486 $ref_item{'reftype'} = $reftype;
2487 $ref_item{'refid'} = $refid;
2489 $ref_item{'reftype'} = $type;
2490 $ref_item{'refid'} = $id;
2493 if ($type eq "tag" || $type eq "commit") {
2494 $ref_item{'epoch'} = $epoch;
2496 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2498 $ref_item{'age'} = "unknown";
2502 push @tagslist, \
%ref_item;
2506 return wantarray ? @tagslist : \
@tagslist;
2509 ## ----------------------------------------------------------------------
2510 ## filesystem-related functions
2512 sub get_file_owner
{
2515 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2516 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2517 if (!defined $gcos) {
2521 $owner =~ s/[,;].*$//;
2522 return to_utf8
($owner);
2525 ## ......................................................................
2526 ## mimetype related functions
2528 sub mimetype_guess_file
{
2529 my $filename = shift;
2530 my $mimemap = shift;
2531 -r
$mimemap or return undef;
2534 open(MIME
, $mimemap) or return undef;
2536 next if m/^#/; # skip comments
2537 my ($mime, $exts) = split(/\t+/);
2538 if (defined $exts) {
2539 my @exts = split(/\s+/, $exts);
2540 foreach my $ext (@exts) {
2541 $mimemap{$ext} = $mime;
2547 $filename =~ /\.([^.]*)$/;
2548 return $mimemap{$1};
2551 sub mimetype_guess
{
2552 my $filename = shift;
2554 $filename =~ /\./ or return undef;
2556 if ($mimetypes_file) {
2557 my $file = $mimetypes_file;
2558 if ($file !~ m!^/!) { # if it is relative path
2559 # it is relative to project
2560 $file = "$projectroot/$project/$file";
2562 $mime = mimetype_guess_file
($filename, $file);
2564 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2570 my $filename = shift;
2573 my $mime = mimetype_guess
($filename);
2574 $mime and return $mime;
2578 return $default_blob_plain_mimetype unless $fd;
2581 return 'text/plain';
2582 } elsif (! $filename) {
2583 return 'application/octet-stream';
2584 } elsif ($filename =~ m/\.png$/i) {
2586 } elsif ($filename =~ m/\.gif$/i) {
2588 } elsif ($filename =~ m/\.jpe?g$/i) {
2589 return 'image/jpeg';
2591 return 'application/octet-stream';
2595 sub blob_contenttype
{
2596 my ($fd, $file_name, $type) = @_;
2598 $type ||= blob_mimetype
($fd, $file_name);
2599 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2600 $type .= "; charset=$default_text_plain_charset";
2606 ## ======================================================================
2607 ## functions printing HTML: header, footer, error page
2609 sub git_header_html
{
2610 my $status = shift || "200 OK";
2611 my $expires = shift;
2613 my $title = "$site_name";
2614 if (defined $project) {
2615 $title .= " - " . to_utf8
($project);
2616 if (defined $action) {
2617 $title .= "/$action";
2618 if (defined $file_name) {
2619 $title .= " - " . esc_path
($file_name);
2620 if ($action eq "tree" && $file_name !~ m
|/$|) {
2627 # require explicit support from the UA if we are to send the page as
2628 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2629 # we have to do this because MSIE sometimes globs '*/*', pretending to
2630 # support xhtml+xml but choking when it gets what it asked for.
2631 if (defined $cgi->http('HTTP_ACCEPT') &&
2632 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2633 $cgi->Accept('application/xhtml+xml') != 0) {
2634 $content_type = 'application/xhtml+xml';
2636 $content_type = 'text/html';
2638 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2639 -status
=> $status, -expires
=> $expires);
2640 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2642 <?xml version="1.0" encoding="utf-8"?>
2643 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2644 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2645 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2646 <!-- git core binaries version $git_version -->
2648 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2649 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2650 <meta name="robots" content="index, nofollow"/>
2651 <title>$title</title>
2653 # print out each stylesheet that exist
2654 if (defined $stylesheet) {
2655 #provides backwards capability for those people who define style sheet in a config file
2656 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2658 foreach my $stylesheet (@stylesheets) {
2659 next unless $stylesheet;
2660 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2663 if (defined $project) {
2664 my %href_params = get_feed_info
();
2665 if (!exists $href_params{'-title'}) {
2666 $href_params{'-title'} = 'log';
2669 foreach my $format qw(RSS Atom) {
2670 my $type = lc($format);
2672 '-rel' => 'alternate',
2673 '-title' => "$project - $href_params{'-title'} - $format feed",
2674 '-type' => "application/$type+xml"
2677 $href_params{'action'} = $type;
2678 $link_attr{'-href'} = href
(%href_params);
2680 "rel=\"$link_attr{'-rel'}\" ".
2681 "title=\"$link_attr{'-title'}\" ".
2682 "href=\"$link_attr{'-href'}\" ".
2683 "type=\"$link_attr{'-type'}\" ".
2686 $href_params{'extra_options'} = '--no-merges';
2687 $link_attr{'-href'} = href
(%href_params);
2688 $link_attr{'-title'} .= ' (no merges)';
2690 "rel=\"$link_attr{'-rel'}\" ".
2691 "title=\"$link_attr{'-title'}\" ".
2692 "href=\"$link_attr{'-href'}\" ".
2693 "type=\"$link_attr{'-type'}\" ".
2698 printf('<link rel="alternate" title="%s projects list" '.
2699 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2700 $site_name, href
(project
=>undef, action
=>"project_index"));
2701 printf('<link rel="alternate" title="%s projects feeds" '.
2702 'href="%s" type="text/x-opml" />'."\n",
2703 $site_name, href
(project
=>undef, action
=>"opml"));
2705 if (defined $favicon) {
2706 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2712 if (-f
$site_header) {
2713 open (my $fd, $site_header);
2718 print "<div class=\"page_header\">\n" .
2719 $cgi->a({-href
=> esc_url
($logo_url),
2720 -title
=> $logo_label},
2721 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2722 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2723 if (defined $project) {
2724 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2725 if (defined $action) {
2732 my ($have_search) = gitweb_check_feature
('search');
2733 if (defined $project && $have_search) {
2734 if (!defined $searchtext) {
2738 if (defined $hash_base) {
2739 $search_hash = $hash_base;
2740 } elsif (defined $hash) {
2741 $search_hash = $hash;
2743 $search_hash = "HEAD";
2745 my $action = $my_uri;
2746 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2747 if ($use_pathinfo) {
2748 $action .= "/".esc_url
($project);
2750 print $cgi->startform(-method => "get", -action
=> $action) .
2751 "<div class=\"search\">\n" .
2753 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2754 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2755 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2756 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2757 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2758 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2760 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2761 "<span title=\"Extended regular expression\">" .
2762 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2763 -checked
=> $search_use_regexp) .
2766 $cgi->end_form() . "\n";
2770 sub git_footer_html
{
2771 my $feed_class = 'rss_logo';
2773 print "<div class=\"page_footer\">\n";
2774 if (defined $project) {
2775 my $descr = git_get_project_description
($project);
2776 if (defined $descr) {
2777 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2780 my %href_params = get_feed_info
();
2781 if (!%href_params) {
2782 $feed_class .= ' generic';
2784 $href_params{'-title'} ||= 'log';
2786 foreach my $format qw(RSS Atom) {
2787 $href_params{'action'} = lc($format);
2788 print $cgi->a({-href
=> href
(%href_params),
2789 -title
=> "$href_params{'-title'} $format feed",
2790 -class => $feed_class}, $format)."\n";
2794 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2795 -class => $feed_class}, "OPML") . " ";
2796 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2797 -class => $feed_class}, "TXT") . "\n";
2799 print "</div>\n"; # class="page_footer"
2801 if (-f
$site_footer) {
2802 open (my $fd, $site_footer);
2811 # die_error(<http_status_code>, <error_message>)
2812 # Example: die_error(404, 'Hash not found')
2813 # By convention, use the following status codes (as defined in RFC 2616):
2814 # 400: Invalid or missing CGI parameters, or
2815 # requested object exists but has wrong type.
2816 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2817 # this server or project.
2818 # 404: Requested object/revision/project doesn't exist.
2819 # 500: The server isn't configured properly, or
2820 # an internal error occurred (e.g. failed assertions caused by bugs), or
2821 # an unknown error occurred (e.g. the git binary died unexpectedly).
2823 my $status = shift || 500;
2824 my $error = shift || "Internal server error";
2826 my %http_responses = (400 => '400 Bad Request',
2827 403 => '403 Forbidden',
2828 404 => '404 Not Found',
2829 500 => '500 Internal Server Error');
2830 git_header_html
($http_responses{$status});
2832 <div class="page_body">
2842 ## ----------------------------------------------------------------------
2843 ## functions printing or outputting HTML: navigation
2845 sub git_print_page_nav
{
2846 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2847 $extra = '' if !defined $extra; # pager or formats
2849 my @navs = qw(summary shortlog log commit commitdiff tree);
2851 @navs = grep { $_ ne $suppress } @navs;
2854 my %arg = map { $_ => {action
=>$_} } @navs;
2855 if (defined $head) {
2856 for (qw(commit commitdiff)) {
2857 $arg{$_}{'hash'} = $head;
2859 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2860 for (qw(shortlog log)) {
2861 $arg{$_}{'hash'} = $head;
2866 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2867 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2869 my @actions = gitweb_check_feature
('actions');
2872 'n' => $project, # project name
2873 'f' => $git_dir, # project path within filesystem
2874 'h' => $treehead || '', # current hash ('h' parameter)
2875 'b' => $treebase || '', # hash base ('hb' parameter)
2878 my ($label, $link, $pos) = splice(@actions,0,3);
2880 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2882 $link =~ s/%([%nfhb])/$repl{$1}/g;
2883 $arg{$label}{'_href'} = $link;
2886 print "<div class=\"page_nav\">\n" .
2888 map { $_ eq $current ?
2889 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
2891 print "<br/>\n$extra<br/>\n" .
2895 sub format_paging_nav
{
2896 my ($action, $hash, $head, $page, $has_next_link) = @_;
2900 if ($hash ne $head || $page) {
2901 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2903 $paging_nav .= "HEAD";
2907 $paging_nav .= " ⋅ " .
2908 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2909 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2911 $paging_nav .= " ⋅ prev";
2914 if ($has_next_link) {
2915 $paging_nav .= " ⋅ " .
2916 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2917 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2919 $paging_nav .= " ⋅ next";
2925 ## ......................................................................
2926 ## functions printing or outputting HTML: div
2928 sub git_print_header_div
{
2929 my ($action, $title, $hash, $hash_base) = @_;
2932 $args{'action'} = $action;
2933 $args{'hash'} = $hash if $hash;
2934 $args{'hash_base'} = $hash_base if $hash_base;
2936 print "<div class=\"header\">\n" .
2937 $cgi->a({-href
=> href
(%args), -class => "title"},
2938 $title ? $title : $action) .
2942 #sub git_print_authorship (\%) {
2943 sub git_print_authorship
{
2946 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2947 print "<div class=\"author_date\">" .
2948 esc_html
($co->{'author_name'}) .
2950 if ($ad{'hour_local'} < 6) {
2951 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2952 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2954 printf(" (%02d:%02d %s)",
2955 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2960 sub git_print_page_path
{
2966 print "<div class=\"page_path\">";
2967 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2968 -title
=> 'tree root'}, to_utf8
("[$project]"));
2970 if (defined $name) {
2971 my @dirname = split '/', $name;
2972 my $basename = pop @dirname;
2975 foreach my $dir (@dirname) {
2976 $fullname .= ($fullname ? '/' : '') . $dir;
2977 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2979 -title
=> $fullname}, esc_path
($dir));
2982 if (defined $type && $type eq 'blob') {
2983 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2985 -title
=> $name}, esc_path
($basename));
2986 } elsif (defined $type && $type eq 'tree') {
2987 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2989 -title
=> $name}, esc_path
($basename));
2992 print esc_path
($basename);
2995 print "<br/></div>\n";
2998 # sub git_print_log (\@;%) {
2999 sub git_print_log
($;%) {
3003 if ($opts{'-remove_title'}) {
3004 # remove title, i.e. first line of log
3007 # remove leading empty lines
3008 while (defined $log->[0] && $log->[0] eq "") {
3015 foreach my $line (@$log) {
3016 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3019 if (! $opts{'-remove_signoff'}) {
3020 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3023 # remove signoff lines
3030 # print only one empty line
3031 # do not print empty line after signoff
3033 next if ($empty || $signoff);
3039 print format_log_line_html
($line) . "<br/>\n";
3042 if ($opts{'-final_empty_line'}) {
3043 # end with single empty line
3044 print "<br/>\n" unless $empty;
3048 # return link target (what link points to)
3049 sub git_get_link_target
{
3054 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3058 $link_target = <$fd>;
3063 return $link_target;
3066 # given link target, and the directory (basedir) the link is in,
3067 # return target of link relative to top directory (top tree);
3068 # return undef if it is not possible (including absolute links).
3069 sub normalize_link_target
{
3070 my ($link_target, $basedir, $hash_base) = @_;
3072 # we can normalize symlink target only if $hash_base is provided
3073 return unless $hash_base;
3075 # absolute symlinks (beginning with '/') cannot be normalized
3076 return if (substr($link_target, 0, 1) eq '/');
3078 # normalize link target to path from top (root) tree (dir)
3081 $path = $basedir . '/' . $link_target;
3083 # we are in top (root) tree (dir)
3084 $path = $link_target;
3087 # remove //, /./, and /../
3089 foreach my $part (split('/', $path)) {
3090 # discard '.' and ''
3091 next if (!$part || $part eq '.');
3093 if ($part eq '..') {
3097 # link leads outside repository (outside top dir)
3101 push @path_parts, $part;
3104 $path = join('/', @path_parts);
3109 # print tree entry (row of git_tree), but without encompassing <tr> element
3110 sub git_print_tree_entry
{
3111 my ($t, $basedir, $hash_base, $have_blame) = @_;
3114 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3116 # The format of a table row is: mode list link. Where mode is
3117 # the mode of the entry, list is the name of the entry, an href,
3118 # and link is the action links of the entry.
3120 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3121 if ($t->{'type'} eq "blob") {
3122 print "<td class=\"list\">" .
3123 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3124 file_name
=>"$basedir$t->{'name'}", %base_key),
3125 -class => "list"}, esc_path
($t->{'name'}));
3126 if (S_ISLNK
(oct $t->{'mode'})) {
3127 my $link_target = git_get_link_target
($t->{'hash'});
3129 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3130 if (defined $norm_target) {
3132 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3133 file_name
=>$norm_target),
3134 -title
=> $norm_target}, esc_path
($link_target));
3136 print " -> " . esc_path
($link_target);
3141 print "<td class=\"link\">";
3142 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3143 file_name
=>"$basedir$t->{'name'}", %base_key)},
3147 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3148 file_name
=>"$basedir$t->{'name'}", %base_key)},
3151 if (defined $hash_base) {
3153 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3154 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3158 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3159 file_name
=>"$basedir$t->{'name'}")},
3163 } elsif ($t->{'type'} eq "tree") {
3164 print "<td class=\"list\">";
3165 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3166 file_name
=>"$basedir$t->{'name'}", %base_key)},
3167 esc_path
($t->{'name'}));
3169 print "<td class=\"link\">";
3170 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3171 file_name
=>"$basedir$t->{'name'}", %base_key)},
3173 if (defined $hash_base) {
3175 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3176 file_name
=>"$basedir$t->{'name'}")},
3181 # unknown object: we can only present history for it
3182 # (this includes 'commit' object, i.e. submodule support)
3183 print "<td class=\"list\">" .
3184 esc_path
($t->{'name'}) .
3186 print "<td class=\"link\">";
3187 if (defined $hash_base) {
3188 print $cgi->a({-href
=> href
(action
=>"history",
3189 hash_base
=>$hash_base,
3190 file_name
=>"$basedir$t->{'name'}")},
3197 ## ......................................................................
3198 ## functions printing large fragments of HTML
3200 # get pre-image filenames for merge (combined) diff
3201 sub fill_from_file_info
{
3202 my ($diff, @parents) = @_;
3204 $diff->{'from_file'} = [ ];
3205 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3206 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3207 if ($diff->{'status'}[$i] eq 'R' ||
3208 $diff->{'status'}[$i] eq 'C') {
3209 $diff->{'from_file'}[$i] =
3210 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3217 # is current raw difftree line of file deletion
3219 my $diffinfo = shift;
3221 return $diffinfo->{'to_id'} eq ('0' x
40);
3224 # does patch correspond to [previous] difftree raw line
3225 # $diffinfo - hashref of parsed raw diff format
3226 # $patchinfo - hashref of parsed patch diff format
3227 # (the same keys as in $diffinfo)
3228 sub is_patch_split
{
3229 my ($diffinfo, $patchinfo) = @_;
3231 return defined $diffinfo && defined $patchinfo
3232 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3236 sub git_difftree_body
{
3237 my ($difftree, $hash, @parents) = @_;
3238 my ($parent) = $parents[0];
3239 my ($have_blame) = gitweb_check_feature
('blame');
3240 print "<div class=\"list_head\">\n";
3241 if ($#{$difftree} > 10) {
3242 print(($#{$difftree} + 1) . " files changed:\n");
3246 print "<table class=\"" .
3247 (@parents > 1 ? "combined " : "") .
3250 # header only for combined diff in 'commitdiff' view
3251 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3254 print "<thead><tr>\n" .
3255 "<th></th><th></th>\n"; # filename, patchN link
3256 for (my $i = 0; $i < @parents; $i++) {
3257 my $par = $parents[$i];
3259 $cgi->a({-href
=> href
(action
=>"commitdiff",
3260 hash
=>$hash, hash_parent
=>$par),
3261 -title
=> 'commitdiff to parent number ' .
3262 ($i+1) . ': ' . substr($par,0,7)},
3266 print "</tr></thead>\n<tbody>\n";
3271 foreach my $line (@{$difftree}) {
3272 my $diff = parsed_difftree_line
($line);
3275 print "<tr class=\"dark\">\n";
3277 print "<tr class=\"light\">\n";
3281 if (exists $diff->{'nparents'}) { # combined diff
3283 fill_from_file_info
($diff, @parents)
3284 unless exists $diff->{'from_file'};
3286 if (!is_deleted
($diff)) {
3287 # file exists in the result (child) commit
3289 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3290 file_name
=>$diff->{'to_file'},
3292 -class => "list"}, esc_path
($diff->{'to_file'})) .
3296 esc_path
($diff->{'to_file'}) .
3300 if ($action eq 'commitdiff') {
3303 print "<td class=\"link\">" .
3304 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3309 my $has_history = 0;
3310 my $not_deleted = 0;
3311 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3312 my $hash_parent = $parents[$i];
3313 my $from_hash = $diff->{'from_id'}[$i];
3314 my $from_path = $diff->{'from_file'}[$i];
3315 my $status = $diff->{'status'}[$i];
3317 $has_history ||= ($status ne 'A');
3318 $not_deleted ||= ($status ne 'D');
3320 if ($status eq 'A') {
3321 print "<td class=\"link\" align=\"right\"> | </td>\n";
3322 } elsif ($status eq 'D') {
3323 print "<td class=\"link\">" .
3324 $cgi->a({-href
=> href
(action
=>"blob",
3327 file_name
=>$from_path)},
3331 if ($diff->{'to_id'} eq $from_hash) {
3332 print "<td class=\"link nochange\">";
3334 print "<td class=\"link\">";
3336 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3337 hash
=>$diff->{'to_id'},
3338 hash_parent
=>$from_hash,
3340 hash_parent_base
=>$hash_parent,
3341 file_name
=>$diff->{'to_file'},
3342 file_parent
=>$from_path)},
3348 print "<td class=\"link\">";
3350 print $cgi->a({-href
=> href
(action
=>"blob",
3351 hash
=>$diff->{'to_id'},
3352 file_name
=>$diff->{'to_file'},
3355 print " | " if ($has_history);
3358 print $cgi->a({-href
=> href
(action
=>"history",
3359 file_name
=>$diff->{'to_file'},
3366 next; # instead of 'else' clause, to avoid extra indent
3368 # else ordinary diff
3370 my ($to_mode_oct, $to_mode_str, $to_file_type);
3371 my ($from_mode_oct, $from_mode_str, $from_file_type);
3372 if ($diff->{'to_mode'} ne ('0' x
6)) {
3373 $to_mode_oct = oct $diff->{'to_mode'};
3374 if (S_ISREG
($to_mode_oct)) { # only for regular file
3375 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3377 $to_file_type = file_type
($diff->{'to_mode'});
3379 if ($diff->{'from_mode'} ne ('0' x
6)) {
3380 $from_mode_oct = oct $diff->{'from_mode'};
3381 if (S_ISREG
($to_mode_oct)) { # only for regular file
3382 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3384 $from_file_type = file_type
($diff->{'from_mode'});
3387 if ($diff->{'status'} eq "A") { # created
3388 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3389 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3390 $mode_chng .= "]</span>";
3392 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3393 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3394 -class => "list"}, esc_path
($diff->{'file'}));
3396 print "<td>$mode_chng</td>\n";
3397 print "<td class=\"link\">";
3398 if ($action eq 'commitdiff') {
3401 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3404 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3405 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3409 } elsif ($diff->{'status'} eq "D") { # deleted
3410 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3412 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3413 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3414 -class => "list"}, esc_path
($diff->{'file'}));
3416 print "<td>$mode_chng</td>\n";
3417 print "<td class=\"link\">";
3418 if ($action eq 'commitdiff') {
3421 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3424 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3425 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3428 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3429 file_name
=>$diff->{'file'})},
3432 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3433 file_name
=>$diff->{'file'})},
3437 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3438 my $mode_chnge = "";
3439 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3440 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3441 if ($from_file_type ne $to_file_type) {
3442 $mode_chnge .= " from $from_file_type to $to_file_type";
3444 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3445 if ($from_mode_str && $to_mode_str) {
3446 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3447 } elsif ($to_mode_str) {
3448 $mode_chnge .= " mode: $to_mode_str";
3451 $mode_chnge .= "]</span>\n";
3454 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3455 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3456 -class => "list"}, esc_path
($diff->{'file'}));
3458 print "<td>$mode_chnge</td>\n";
3459 print "<td class=\"link\">";
3460 if ($action eq 'commitdiff') {
3463 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3465 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3466 # "commit" view and modified file (not onlu mode changed)
3467 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3468 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3469 hash_base
=>$hash, hash_parent_base
=>$parent,
3470 file_name
=>$diff->{'file'})},
3474 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3475 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3478 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3479 file_name
=>$diff->{'file'})},
3482 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3483 file_name
=>$diff->{'file'})},
3487 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3488 my %status_name = ('R' => 'moved', 'C' => 'copied');
3489 my $nstatus = $status_name{$diff->{'status'}};
3491 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3492 # mode also for directories, so we cannot use $to_mode_str
3493 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3496 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3497 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3498 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3499 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3500 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3501 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3502 -class => "list"}, esc_path
($diff->{'from_file'})) .
3503 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3504 "<td class=\"link\">";
3505 if ($action eq 'commitdiff') {
3508 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3510 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3511 # "commit" view and modified file (not only pure rename or copy)
3512 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3513 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3514 hash_base
=>$hash, hash_parent_base
=>$parent,
3515 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3519 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3520 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3523 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3524 file_name
=>$diff->{'to_file'})},
3527 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3528 file_name
=>$diff->{'to_file'})},
3532 } # we should not encounter Unmerged (U) or Unknown (X) status
3535 print "</tbody>" if $has_header;
3539 sub git_patchset_body
{
3540 my ($fd, $difftree, $hash, @hash_parents) = @_;
3541 my ($hash_parent) = $hash_parents[0];
3543 my $is_combined = (@hash_parents > 1);
3545 my $patch_number = 0;
3551 print "<div class=\"patchset\">\n";
3553 # skip to first patch
3554 while ($patch_line = <$fd>) {
3557 last if ($patch_line =~ m/^diff /);
3561 while ($patch_line) {
3563 # parse "git diff" header line
3564 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3565 # $1 is from_name, which we do not use
3566 $to_name = unquote
($2);
3567 $to_name =~ s!^b/!!;
3568 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3569 # $1 is 'cc' or 'combined', which we do not use
3570 $to_name = unquote
($2);
3575 # check if current patch belong to current raw line
3576 # and parse raw git-diff line if needed
3577 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3578 # this is continuation of a split patch
3579 print "<div class=\"patch cont\">\n";
3581 # advance raw git-diff output if needed
3582 $patch_idx++ if defined $diffinfo;
3584 # read and prepare patch information
3585 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3587 # compact combined diff output can have some patches skipped
3588 # find which patch (using pathname of result) we are at now;
3590 while ($to_name ne $diffinfo->{'to_file'}) {
3591 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3592 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3593 "</div>\n"; # class="patch"
3598 last if $patch_idx > $#$difftree;
3599 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3603 # modifies %from, %to hashes
3604 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3606 # this is first patch for raw difftree line with $patch_idx index
3607 # we index @$difftree array from 0, but number patches from 1
3608 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3612 #assert($patch_line =~ m/^diff /) if DEBUG;
3613 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3615 # print "git diff" header
3616 print format_git_diff_header_line
($patch_line, $diffinfo,
3619 # print extended diff header
3620 print "<div class=\"diff extended_header\">\n";
3622 while ($patch_line = <$fd>) {
3625 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3627 print format_extended_diff_header_line
($patch_line, $diffinfo,
3630 print "</div>\n"; # class="diff extended_header"
3632 # from-file/to-file diff header
3633 if (! $patch_line) {
3634 print "</div>\n"; # class="patch"
3637 next PATCH
if ($patch_line =~ m/^diff /);
3638 #assert($patch_line =~ m/^---/) if DEBUG;
3640 my $last_patch_line = $patch_line;
3641 $patch_line = <$fd>;
3643 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3645 print format_diff_from_to_header
($last_patch_line, $patch_line,
3646 $diffinfo, \
%from, \
%to,
3651 while ($patch_line = <$fd>) {
3654 next PATCH
if ($patch_line =~ m/^diff /);
3656 print format_diff_line
($patch_line, \
%from, \
%to);
3660 print "</div>\n"; # class="patch"
3663 # for compact combined (--cc) format, with chunk and patch simpliciaction
3664 # patchset might be empty, but there might be unprocessed raw lines
3665 for (++$patch_idx if $patch_number > 0;
3666 $patch_idx < @$difftree;
3668 # read and prepare patch information
3669 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3671 # generate anchor for "patch" links in difftree / whatchanged part
3672 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3673 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3674 "</div>\n"; # class="patch"
3679 if ($patch_number == 0) {
3680 if (@hash_parents > 1) {
3681 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3683 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3687 print "</div>\n"; # class="patchset"
3690 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3692 # fills project list info (age, description, owner, forks) for each
3693 # project in the list, removing invalid projects from returned list
3694 # NOTE: modifies $projlist, but does not remove entries from it
3695 sub fill_project_list_info
{
3696 my ($projlist, $check_forks) = @_;
3699 my $show_ctags = gitweb_check_feature
('ctags');
3701 foreach my $pr (@$projlist) {
3702 my (@activity) = git_get_last_activity
($pr->{'path'});
3703 unless (@activity) {
3706 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3707 if (!defined $pr->{'descr'}) {
3708 my $descr = git_get_project_description
($pr->{'path'}) || "";
3709 $descr = to_utf8
($descr);
3710 $pr->{'descr_long'} = $descr;
3711 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3713 if (!defined $pr->{'owner'}) {
3714 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3717 my $pname = $pr->{'path'};
3718 if (($pname =~ s/\.git$//) &&
3719 ($pname !~ /\/$/) &&
3720 (-d
"$projectroot/$pname")) {
3721 $pr->{'forks'} = "-d $projectroot/$pname";
3726 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3727 push @projects, $pr;
3733 # print 'sort by' <th> element, generating 'sort by $name' replay link
3734 # if that order is not selected
3736 my ($name, $order, $header) = @_;
3737 $header ||= ucfirst($name);
3739 if ($order eq $name) {
3740 print "<th>$header</th>\n";
3743 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3744 -class => "header"}, $header) .
3749 sub git_project_list_body
{
3750 # actually uses global variable $project
3751 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3753 my ($check_forks) = gitweb_check_feature
('forks');
3754 my @projects = fill_project_list_info
($projlist, $check_forks);
3756 $order ||= $default_projects_order;
3757 $from = 0 unless defined $from;
3758 $to = $#projects if (!defined $to || $#projects < $to);
3761 project
=> { key
=> 'path', type
=> 'str' },
3762 descr
=> { key
=> 'descr_long', type
=> 'str' },
3763 owner
=> { key
=> 'owner', type
=> 'str' },
3764 age
=> { key
=> 'age', type
=> 'num' }
3766 my $oi = $order_info{$order};
3767 if ($oi->{'type'} eq 'str') {
3768 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3770 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3773 my $show_ctags = gitweb_check_feature
('ctags');
3776 foreach my $p (@projects) {
3777 foreach my $ct (keys %{$p->{'ctags'}}) {
3778 $ctags{$ct} += $p->{'ctags'}->{$ct};
3781 my $cloud = git_populate_project_tagcloud
(\
%ctags);
3782 print git_show_project_tagcloud
($cloud, 64);
3785 print "<table class=\"project_list\">\n";
3786 unless ($no_header) {
3789 print "<th></th>\n";
3791 print_sort_th
('project', $order, 'Project');
3792 print_sort_th
('descr', $order, 'Description');
3793 print_sort_th
('owner', $order, 'Owner');
3794 print_sort_th
('age', $order, 'Last Change');
3795 print "<th></th>\n" . # for links
3799 my $tagfilter = $cgi->param('by_tag');
3800 for (my $i = $from; $i <= $to; $i++) {
3801 my $pr = $projects[$i];
3803 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
3804 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
3805 and not $pr->{'descr_long'} =~ /$searchtext/;
3806 # Weed out forks or non-matching entries of search
3808 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
3809 $forkbase="^$forkbase" if $forkbase;
3810 next if not $searchtext and not $tagfilter and $show_ctags
3811 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
3815 print "<tr class=\"dark\">\n";
3817 print "<tr class=\"light\">\n";
3822 if ($pr->{'forks'}) {
3823 print "<!-- $pr->{'forks'} -->\n";
3824 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3828 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3829 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3830 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3831 -class => "list", -title
=> $pr->{'descr_long'}},
3832 esc_html
($pr->{'descr'})) . "</td>\n" .
3833 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3834 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3835 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3836 "<td class=\"link\">" .
3837 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3838 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3839 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3840 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3841 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3845 if (defined $extra) {
3848 print "<td></td>\n";
3850 print "<td colspan=\"5\">$extra</td>\n" .
3856 sub git_shortlog_body
{
3857 # uses global variable $project
3858 my ($commitlist, $from, $to, $refs, $extra) = @_;
3860 $from = 0 unless defined $from;
3861 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3863 print "<table class=\"shortlog\">\n";
3865 for (my $i = $from; $i <= $to; $i++) {
3866 my %co = %{$commitlist->[$i]};
3867 my $commit = $co{'id'};
3868 my $ref = format_ref_marker
($refs, $commit);
3870 print "<tr class=\"dark\">\n";
3872 print "<tr class=\"light\">\n";
3875 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3876 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3877 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3878 "<td><i>" . $author . "</i></td>\n" .
3880 print format_subject_html
($co{'title'}, $co{'title_short'},
3881 href
(action
=>"commit", hash
=>$commit), $ref);
3883 "<td class=\"link\">" .
3884 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3885 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3886 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3887 my $snapshot_links = format_snapshot_links
($commit);
3888 if (defined $snapshot_links) {
3889 print " | " . $snapshot_links;
3894 if (defined $extra) {
3896 "<td colspan=\"4\">$extra</td>\n" .
3902 sub git_history_body
{
3903 # Warning: assumes constant type (blob or tree) during history
3904 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3906 $from = 0 unless defined $from;
3907 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3909 print "<table class=\"history\">\n";
3911 for (my $i = $from; $i <= $to; $i++) {
3912 my %co = %{$commitlist->[$i]};
3916 my $commit = $co{'id'};
3918 my $ref = format_ref_marker
($refs, $commit);
3921 print "<tr class=\"dark\">\n";
3923 print "<tr class=\"light\">\n";
3926 # shortlog uses chop_str($co{'author_name'}, 10)
3927 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3928 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3929 "<td><i>" . $author . "</i></td>\n" .
3931 # originally git_history used chop_str($co{'title'}, 50)
3932 print format_subject_html
($co{'title'}, $co{'title_short'},
3933 href
(action
=>"commit", hash
=>$commit), $ref);
3935 "<td class=\"link\">" .
3936 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3937 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3939 if ($ftype eq 'blob') {
3940 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3941 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3942 if (defined $blob_current && defined $blob_parent &&
3943 $blob_current ne $blob_parent) {
3945 $cgi->a({-href
=> href
(action
=>"blobdiff",
3946 hash
=>$blob_current, hash_parent
=>$blob_parent,
3947 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3948 file_name
=>$file_name)},
3955 if (defined $extra) {
3957 "<td colspan=\"4\">$extra</td>\n" .
3964 # uses global variable $project
3965 my ($taglist, $from, $to, $extra) = @_;
3966 $from = 0 unless defined $from;
3967 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3969 print "<table class=\"tags\">\n";
3971 for (my $i = $from; $i <= $to; $i++) {
3972 my $entry = $taglist->[$i];
3974 my $comment = $tag{'subject'};
3976 if (defined $comment) {
3977 $comment_short = chop_str
($comment, 30, 5);
3980 print "<tr class=\"dark\">\n";
3982 print "<tr class=\"light\">\n";
3985 if (defined $tag{'age'}) {
3986 print "<td><i>$tag{'age'}</i></td>\n";
3988 print "<td></td>\n";
3991 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3992 -class => "list name"}, esc_html
($tag{'name'})) .
3995 if (defined $comment) {
3996 print format_subject_html
($comment, $comment_short,
3997 href
(action
=>"tag", hash
=>$tag{'id'}));
4000 "<td class=\"selflink\">";
4001 if ($tag{'type'} eq "tag") {
4002 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4007 "<td class=\"link\">" . " | " .
4008 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4009 if ($tag{'reftype'} eq "commit") {
4010 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4011 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4012 } elsif ($tag{'reftype'} eq "blob") {
4013 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4018 if (defined $extra) {
4020 "<td colspan=\"5\">$extra</td>\n" .
4026 sub git_heads_body
{
4027 # uses global variable $project
4028 my ($headlist, $head, $from, $to, $extra) = @_;
4029 $from = 0 unless defined $from;
4030 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4032 print "<table class=\"heads\">\n";
4034 for (my $i = $from; $i <= $to; $i++) {
4035 my $entry = $headlist->[$i];
4037 my $curr = $ref{'id'} eq $head;
4039 print "<tr class=\"dark\">\n";
4041 print "<tr class=\"light\">\n";
4044 print "<td><i>$ref{'age'}</i></td>\n" .
4045 ($curr ? "<td class=\"current_head\">" : "<td>") .
4046 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4047 -class => "list name"},esc_html
($ref{'name'})) .
4049 "<td class=\"link\">" .
4050 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4051 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4052 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4056 if (defined $extra) {
4058 "<td colspan=\"3\">$extra</td>\n" .
4064 sub git_search_grep_body
{
4065 my ($commitlist, $from, $to, $extra) = @_;
4066 $from = 0 unless defined $from;
4067 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4069 print "<table class=\"commit_search\">\n";
4071 for (my $i = $from; $i <= $to; $i++) {
4072 my %co = %{$commitlist->[$i]};
4076 my $commit = $co{'id'};
4078 print "<tr class=\"dark\">\n";
4080 print "<tr class=\"light\">\n";
4083 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4084 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4085 "<td><i>" . $author . "</i></td>\n" .
4087 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4088 -class => "list subject"},
4089 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4090 my $comment = $co{'comment'};
4091 foreach my $line (@$comment) {
4092 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4093 my ($lead, $match, $trail) = ($1, $2, $3);
4094 $match = chop_str
($match, 70, 5, 'center');
4095 my $contextlen = int((80 - length($match))/2);
4096 $contextlen = 30 if ($contextlen > 30);
4097 $lead = chop_str
($lead, $contextlen, 10, 'left');
4098 $trail = chop_str
($trail, $contextlen, 10, 'right');
4100 $lead = esc_html
($lead);
4101 $match = esc_html
($match);
4102 $trail = esc_html
($trail);
4104 print "$lead<span class=\"match\">$match</span>$trail<br />";
4108 "<td class=\"link\">" .
4109 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4111 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4113 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4117 if (defined $extra) {
4119 "<td colspan=\"3\">$extra</td>\n" .
4125 ## ======================================================================
4126 ## ======================================================================
4129 sub git_project_list
{
4130 my $order = $cgi->param('o');
4131 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4132 die_error
(400, "Unknown order parameter");
4135 my @list = git_get_projects_list
();
4137 die_error
(404, "No projects found");
4141 if (-f
$home_text) {
4142 print "<div class=\"index_include\">\n";
4143 open (my $fd, $home_text);
4148 print $cgi->startform(-method => "get") .
4149 "<p class=\"projsearch\">Search:\n" .
4150 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4152 $cgi->end_form() . "\n";
4153 git_project_list_body
(\
@list, $order);
4158 my $order = $cgi->param('o');
4159 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4160 die_error
(400, "Unknown order parameter");
4163 my @list = git_get_projects_list
($project);
4165 die_error
(404, "No forks found");
4169 git_print_page_nav
('','');
4170 git_print_header_div
('summary', "$project forks");
4171 git_project_list_body
(\
@list, $order);
4175 sub git_project_index
{
4176 my @projects = git_get_projects_list
($project);
4179 -type
=> 'text/plain',
4180 -charset
=> 'utf-8',
4181 -content_disposition
=> 'inline; filename="index.aux"');
4183 foreach my $pr (@projects) {
4184 if (!exists $pr->{'owner'}) {
4185 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4188 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4189 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4190 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4191 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4195 print "$path $owner\n";
4200 my $descr = git_get_project_description
($project) || "none";
4201 my %co = parse_commit
("HEAD");
4202 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4203 my $head = $co{'id'};
4205 my $owner = git_get_project_owner
($project);
4207 my $refs = git_get_references
();
4208 # These get_*_list functions return one more to allow us to see if
4209 # there are more ...
4210 my @taglist = git_get_tags_list
(16);
4211 my @headlist = git_get_heads_list
(16);
4213 my ($check_forks) = gitweb_check_feature
('forks');
4216 @forklist = git_get_projects_list
($project);
4220 git_print_page_nav
('summary','', $head);
4222 print "<div class=\"title\"> </div>\n";
4223 print "<table class=\"projects_list\">\n" .
4224 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4225 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4226 if (defined $cd{'rfc2822'}) {
4227 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4230 # use per project git URL list in $projectroot/$project/cloneurl
4231 # or make project git URL from git base URL and project name
4232 my $url_tag = "URL";
4233 my @url_list = git_get_project_url_list
($project);
4234 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4235 foreach my $git_url (@url_list) {
4236 next unless $git_url;
4237 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4242 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4244 my $ctags = git_get_project_ctags
($project);
4245 my $cloud = git_populate_project_tagcloud
($ctags);
4246 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4247 print "</td>\n<td>" unless %$ctags;
4248 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4249 print "</td>\n<td>" if %$ctags;
4250 print git_show_project_tagcloud
($cloud, 48);
4256 if (-s
"$projectroot/$project/README.html") {
4257 if (open my $fd, "$projectroot/$project/README.html") {
4258 print "<div class=\"title\">readme</div>\n" .
4259 "<div class=\"readme\">\n";
4260 print $_ while (<$fd>);
4261 print "\n</div>\n"; # class="readme"
4266 # we need to request one more than 16 (0..15) to check if
4268 my @commitlist = $head ? parse_commits
($head, 17) : ();
4270 git_print_header_div
('shortlog');
4271 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4272 $#commitlist <= 15 ? undef :
4273 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4277 git_print_header_div
('tags');
4278 git_tags_body
(\
@taglist, 0, 15,
4279 $#taglist <= 15 ? undef :
4280 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4284 git_print_header_div
('heads');
4285 git_heads_body
(\
@headlist, $head, 0, 15,
4286 $#headlist <= 15 ? undef :
4287 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4291 git_print_header_div
('forks');
4292 git_project_list_body
(\
@forklist, 'age', 0, 15,
4293 $#forklist <= 15 ? undef :
4294 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4302 my $head = git_get_head_hash
($project);
4304 git_print_page_nav
('','', $head,undef,$head);
4305 my %tag = parse_tag
($hash);
4308 die_error
(404, "Unknown tag object");
4311 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4312 print "<div class=\"title_text\">\n" .
4313 "<table class=\"object_header\">\n" .
4315 "<td>object</td>\n" .
4316 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4317 $tag{'object'}) . "</td>\n" .
4318 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4319 $tag{'type'}) . "</td>\n" .
4321 if (defined($tag{'author'})) {
4322 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4323 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4324 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4325 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4328 print "</table>\n\n" .
4330 print "<div class=\"page_body\">";
4331 my $comment = $tag{'comment'};
4332 foreach my $line (@$comment) {
4334 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4344 gitweb_check_feature
('blame')
4345 or die_error
(403, "Blame view not allowed");
4347 die_error
(400, "No file name given") unless $file_name;
4348 $hash_base ||= git_get_head_hash
($project);
4349 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4350 my %co = parse_commit
($hash_base)
4351 or die_error
(404, "Commit not found");
4352 if (!defined $hash) {
4353 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4354 or die_error
(404, "Error looking up file");
4356 $ftype = git_get_type
($hash);
4357 if ($ftype !~ "blob") {
4358 die_error
(400, "Object is not a blob");
4360 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4361 $file_name, $hash_base)
4362 or die_error
(500, "Open git-blame failed");
4365 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4368 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4371 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4373 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4374 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4375 git_print_page_path
($file_name, $ftype, $hash_base);
4376 my @rev_color = (qw(light2 dark2));
4377 my $num_colors = scalar(@rev_color);
4378 my $current_color = 0;
4381 <div class="page_body">
4382 <table class="blame">
4383 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4388 last unless defined $_;
4389 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4390 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4391 if (!exists $metainfo{$full_rev}) {
4392 $metainfo{$full_rev} = {};
4394 my $meta = $metainfo{$full_rev};
4397 if (/^(\S+) (.*)$/) {
4403 my $rev = substr($full_rev, 0, 8);
4404 my $author = $meta->{'author'};
4405 my %date = parse_date
($meta->{'author-time'},
4406 $meta->{'author-tz'});
4407 my $date = $date{'iso-tz'};
4409 $current_color = ++$current_color % $num_colors;
4411 print "<tr class=\"$rev_color[$current_color]\">\n";
4413 print "<td class=\"sha1\"";
4414 print " title=\"". esc_html
($author) . ", $date\"";
4415 print " rowspan=\"$group_size\"" if ($group_size > 1);
4417 print $cgi->a({-href
=> href
(action
=>"commit",
4419 file_name
=>$file_name)},
4423 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4424 or die_error
(500, "Open git-rev-parse failed");
4425 my $parent_commit = <$dd>;
4427 chomp($parent_commit);
4428 my $blamed = href
(action
=> 'blame',
4429 file_name
=> $meta->{'filename'},
4430 hash_base
=> $parent_commit);
4431 print "<td class=\"linenr\">";
4432 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4434 -class => "linenr" },
4437 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4443 or print "Reading blob failed\n";
4448 my $head = git_get_head_hash
($project);
4450 git_print_page_nav
('','', $head,undef,$head);
4451 git_print_header_div
('summary', $project);
4453 my @tagslist = git_get_tags_list
();
4455 git_tags_body
(\
@tagslist);
4461 my $head = git_get_head_hash
($project);
4463 git_print_page_nav
('','', $head,undef,$head);
4464 git_print_header_div
('summary', $project);
4466 my @headslist = git_get_heads_list
();
4468 git_heads_body
(\
@headslist, $head);
4473 sub git_blob_plain
{
4477 if (!defined $hash) {
4478 if (defined $file_name) {
4479 my $base = $hash_base || git_get_head_hash
($project);
4480 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4481 or die_error
(404, "Cannot find file");
4483 die_error
(400, "No file name defined");
4485 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4486 # blobs defined by non-textual hash id's can be cached
4490 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4491 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4493 # content-type (can include charset)
4494 $type = blob_contenttype
($fd, $file_name, $type);
4496 # "save as" filename, even when no $file_name is given
4497 my $save_as = "$hash";
4498 if (defined $file_name) {
4499 $save_as = $file_name;
4500 } elsif ($type =~ m/^text\//) {
4506 -expires
=> $expires,
4507 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4509 binmode STDOUT
, ':raw';
4511 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4519 if (!defined $hash) {
4520 if (defined $file_name) {
4521 my $base = $hash_base || git_get_head_hash
($project);
4522 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4523 or die_error
(404, "Cannot find file");
4525 die_error
(400, "No file name defined");
4527 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4528 # blobs defined by non-textual hash id's can be cached
4532 my ($have_blame) = gitweb_check_feature
('blame');
4533 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4534 or die_error
(500, "Couldn't cat $file_name, $hash");
4535 my $mimetype = blob_mimetype
($fd, $file_name);
4536 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4538 return git_blob_plain
($mimetype);
4540 # we can have blame only for text/* mimetype
4541 $have_blame &&= ($mimetype =~ m!^text/!);
4543 git_header_html
(undef, $expires);
4544 my $formats_nav = '';
4545 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4546 if (defined $file_name) {
4549 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4554 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4557 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4560 $cgi->a({-href
=> href
(action
=>"blob",
4561 hash_base
=>"HEAD", file_name
=>$file_name)},
4565 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4568 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4569 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4571 print "<div class=\"page_nav\">\n" .
4572 "<br/><br/></div>\n" .
4573 "<div class=\"title\">$hash</div>\n";
4575 git_print_page_path
($file_name, "blob", $hash_base);
4576 print "<div class=\"page_body\">\n";
4577 if ($mimetype =~ m!^image/!) {
4578 print qq
!<img type
="$mimetype"!;
4580 print qq
! alt
="$file_name" title
="$file_name"!;
4583 href(action=>"blob_plain
", hash=>$hash,
4584 hash_base=>$hash_base, file_name=>$file_name) .
4588 while (my $line = <$fd>) {
4591 $line = untabify
($line);
4592 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4593 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4597 or print "Reading blob failed.\n";
4603 if (!defined $hash_base) {
4604 $hash_base = "HEAD";
4606 if (!defined $hash) {
4607 if (defined $file_name) {
4608 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4613 die_error
(404, "No such tree") unless defined($hash);
4615 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4616 or die_error
(500, "Open git-ls-tree failed");
4617 my @entries = map { chomp; $_ } <$fd>;
4618 close $fd or die_error
(404, "Reading tree failed");
4621 my $refs = git_get_references
();
4622 my $ref = format_ref_marker
($refs, $hash_base);
4625 my ($have_blame) = gitweb_check_feature
('blame');
4626 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4628 if (defined $file_name) {
4630 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4632 $cgi->a({-href
=> href
(action
=>"tree",
4633 hash_base
=>"HEAD", file_name
=>$file_name)},
4636 my $snapshot_links = format_snapshot_links
($hash);
4637 if (defined $snapshot_links) {
4638 # FIXME: Should be available when we have no hash base as well.
4639 push @views_nav, $snapshot_links;
4641 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4642 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4645 print "<div class=\"page_nav\">\n";
4646 print "<br/><br/></div>\n";
4647 print "<div class=\"title\">$hash</div>\n";
4649 if (defined $file_name) {
4650 $basedir = $file_name;
4651 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4654 git_print_page_path
($file_name, 'tree', $hash_base);
4656 print "<div class=\"page_body\">\n";
4657 print "<table class=\"tree\">\n";
4659 # '..' (top directory) link if possible
4660 if (defined $hash_base &&
4661 defined $file_name && $file_name =~ m![^/]+$!) {
4663 print "<tr class=\"dark\">\n";
4665 print "<tr class=\"light\">\n";
4669 my $up = $file_name;
4670 $up =~ s!/?[^/]+$!!;
4671 undef $up unless $up;
4672 # based on git_print_tree_entry
4673 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4674 print '<td class="list">';
4675 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4679 print "<td class=\"link\"></td>\n";
4683 foreach my $line (@entries) {
4684 my %t = parse_ls_tree_line
($line, -z
=> 1);
4687 print "<tr class=\"dark\">\n";
4689 print "<tr class=\"light\">\n";
4693 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4697 print "</table>\n" .
4703 my @supported_fmts = gitweb_check_feature
('snapshot');
4704 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4706 my $format = $cgi->param('sf');
4707 if (!@supported_fmts) {
4708 die_error
(403, "Snapshots not allowed");
4710 # default to first supported snapshot format
4711 $format ||= $supported_fmts[0];
4712 if ($format !~ m/^[a-z0-9]+$/) {
4713 die_error
(400, "Invalid snapshot format parameter");
4714 } elsif (!exists($known_snapshot_formats{$format})) {
4715 die_error
(400, "Unknown snapshot format");
4716 } elsif (!grep($_ eq $format, @supported_fmts)) {
4717 die_error
(403, "Unsupported snapshot format");
4720 if (!defined $hash) {
4721 $hash = git_get_head_hash
($project);
4724 my $name = $project;
4725 $name =~ s
,([^/])/*\
.git
$,$1,;
4726 $name = basename
($name);
4727 my $filename = to_utf8
($name);
4728 $name =~ s/\047/\047\\\047\047/g;
4730 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4731 $cmd = quote_command
(
4732 git_cmd
(), 'archive',
4733 "--format=$known_snapshot_formats{$format}{'format'}",
4734 "--prefix=$name/", $hash);
4735 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4736 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4740 -type
=> $known_snapshot_formats{$format}{'type'},
4741 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4742 -status
=> '200 OK');
4744 open my $fd, "-|", $cmd
4745 or die_error
(500, "Execute git-archive failed");
4746 binmode STDOUT
, ':raw';
4748 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4753 my $head = git_get_head_hash
($project);
4754 if (!defined $hash) {
4757 if (!defined $page) {
4760 my $refs = git_get_references
();
4762 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4764 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4767 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4770 my %co = parse_commit
($hash);
4772 git_print_header_div
('summary', $project);
4773 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4775 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4776 for (my $i = 0; $i <= $to; $i++) {
4777 my %co = %{$commitlist[$i]};
4779 my $commit = $co{'id'};
4780 my $ref = format_ref_marker
($refs, $commit);
4781 my %ad = parse_date
($co{'author_epoch'});
4782 git_print_header_div
('commit',
4783 "<span class=\"age\">$co{'age_string'}</span>" .
4784 esc_html
($co{'title'}) . $ref,
4786 print "<div class=\"title_text\">\n" .
4787 "<div class=\"log_link\">\n" .
4788 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4790 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4792 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4795 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4798 print "<div class=\"log_body\">\n";
4799 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4802 if ($#commitlist >= 100) {
4803 print "<div class=\"page_nav\">\n";
4804 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4805 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4812 $hash ||= $hash_base || "HEAD";
4813 my %co = parse_commit
($hash)
4814 or die_error
(404, "Unknown commit object");
4815 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4816 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4818 my $parent = $co{'parent'};
4819 my $parents = $co{'parents'}; # listref
4821 # we need to prepare $formats_nav before any parameter munging
4823 if (!defined $parent) {
4825 $formats_nav .= '(initial)';
4826 } elsif (@$parents == 1) {
4827 # single parent commit
4830 $cgi->a({-href
=> href
(action
=>"commit",
4832 esc_html
(substr($parent, 0, 7))) .
4839 $cgi->a({-href
=> href
(action
=>"commit",
4841 esc_html
(substr($_, 0, 7)));
4846 if (!defined $parent) {
4850 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4852 (@$parents <= 1 ? $parent : '-c'),
4854 or die_error
(500, "Open git-diff-tree failed");
4855 @difftree = map { chomp; $_ } <$fd>;
4856 close $fd or die_error
(404, "Reading git-diff-tree failed");
4858 # non-textual hash id's can be cached
4860 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4863 my $refs = git_get_references
();
4864 my $ref = format_ref_marker
($refs, $co{'id'});
4866 git_header_html
(undef, $expires);
4867 git_print_page_nav
('commit', '',
4868 $hash, $co{'tree'}, $hash,
4871 if (defined $co{'parent'}) {
4872 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4874 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4876 print "<div class=\"title_text\">\n" .
4877 "<table class=\"object_header\">\n";
4878 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4880 "<td></td><td> $ad{'rfc2822'}";
4881 if ($ad{'hour_local'} < 6) {
4882 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4883 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4885 printf(" (%02d:%02d %s)",
4886 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4890 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4891 print "<tr><td></td><td> $cd{'rfc2822'}" .
4892 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4894 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4897 "<td class=\"sha1\">" .
4898 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4899 class => "list"}, $co{'tree'}) .
4901 "<td class=\"link\">" .
4902 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4904 my $snapshot_links = format_snapshot_links
($hash);
4905 if (defined $snapshot_links) {
4906 print " | " . $snapshot_links;
4911 foreach my $par (@$parents) {
4914 "<td class=\"sha1\">" .
4915 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4916 class => "list"}, $par) .
4918 "<td class=\"link\">" .
4919 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4921 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4928 print "<div class=\"page_body\">\n";
4929 git_print_log
($co{'comment'});
4932 git_difftree_body
(\
@difftree, $hash, @$parents);
4938 # object is defined by:
4939 # - hash or hash_base alone
4940 # - hash_base and file_name
4943 # - hash or hash_base alone
4944 if ($hash || ($hash_base && !defined $file_name)) {
4945 my $object_id = $hash || $hash_base;
4947 open my $fd, "-|", quote_command
(
4948 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4949 or die_error
(404, "Object does not exist");
4953 or die_error
(404, "Object does not exist");
4955 # - hash_base and file_name
4956 } elsif ($hash_base && defined $file_name) {
4957 $file_name =~ s
,/+$,,;
4959 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4960 or die_error
(404, "Base object does not exist");
4962 # here errors should not hapen
4963 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4964 or die_error
(500, "Open git-ls-tree failed");
4968 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4969 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4970 die_error
(404, "File or directory for given base does not exist");
4975 die_error
(400, "Not enough information to find object");
4978 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4979 hash
=>$hash, hash_base
=>$hash_base,
4980 file_name
=>$file_name),
4981 -status
=> '302 Found');
4985 my $format = shift || 'html';
4992 # preparing $fd and %diffinfo for git_patchset_body
4994 if (defined $hash_base && defined $hash_parent_base) {
4995 if (defined $file_name) {
4997 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4998 $hash_parent_base, $hash_base,
4999 "--", (defined $file_parent ? $file_parent : ()), $file_name
5000 or die_error
(500, "Open git-diff-tree failed");
5001 @difftree = map { chomp; $_ } <$fd>;
5003 or die_error
(404, "Reading git-diff-tree failed");
5005 or die_error
(404, "Blob diff not found");
5007 } elsif (defined $hash &&
5008 $hash =~ /[0-9a-fA-F]{40}/) {
5009 # try to find filename from $hash
5011 # read filtered raw output
5012 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5013 $hash_parent_base, $hash_base, "--"
5014 or die_error
(500, "Open git-diff-tree failed");
5016 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5018 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5019 map { chomp; $_ } <$fd>;
5021 or die_error
(404, "Reading git-diff-tree failed");
5023 or die_error
(404, "Blob diff not found");
5026 die_error
(400, "Missing one of the blob diff parameters");
5029 if (@difftree > 1) {
5030 die_error
(400, "Ambiguous blob diff specification");
5033 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5034 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5035 $file_name ||= $diffinfo{'to_file'};
5037 $hash_parent ||= $diffinfo{'from_id'};
5038 $hash ||= $diffinfo{'to_id'};
5040 # non-textual hash id's can be cached
5041 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5042 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5047 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5048 '-p', ($format eq 'html' ? "--full-index" : ()),
5049 $hash_parent_base, $hash_base,
5050 "--", (defined $file_parent ? $file_parent : ()), $file_name
5051 or die_error
(500, "Open git-diff-tree failed");
5054 # old/legacy style URI
5055 if (!%diffinfo && # if new style URI failed
5056 defined $hash && defined $hash_parent) {
5057 # fake git-diff-tree raw output
5058 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5059 $diffinfo{'from_id'} = $hash_parent;
5060 $diffinfo{'to_id'} = $hash;
5061 if (defined $file_name) {
5062 if (defined $file_parent) {
5063 $diffinfo{'status'} = '2';
5064 $diffinfo{'from_file'} = $file_parent;
5065 $diffinfo{'to_file'} = $file_name;
5066 } else { # assume not renamed
5067 $diffinfo{'status'} = '1';
5068 $diffinfo{'from_file'} = $file_name;
5069 $diffinfo{'to_file'} = $file_name;
5071 } else { # no filename given
5072 $diffinfo{'status'} = '2';
5073 $diffinfo{'from_file'} = $hash_parent;
5074 $diffinfo{'to_file'} = $hash;
5077 # non-textual hash id's can be cached
5078 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5079 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5084 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5085 '-p', ($format eq 'html' ? "--full-index" : ()),
5086 $hash_parent, $hash, "--"
5087 or die_error
(500, "Open git-diff failed");
5089 die_error
(400, "Missing one of the blob diff parameters")
5094 if ($format eq 'html') {
5096 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5098 git_header_html
(undef, $expires);
5099 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5100 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5101 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5103 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5104 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5106 if (defined $file_name) {
5107 git_print_page_path
($file_name, "blob", $hash_base);
5109 print "<div class=\"page_path\"></div>\n";
5112 } elsif ($format eq 'plain') {
5114 -type
=> 'text/plain',
5115 -charset
=> 'utf-8',
5116 -expires
=> $expires,
5117 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5119 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5122 die_error
(400, "Unknown blobdiff format");
5126 if ($format eq 'html') {
5127 print "<div class=\"page_body\">\n";
5129 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5132 print "</div>\n"; # class="page_body"
5136 while (my $line = <$fd>) {
5137 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5138 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5142 last if $line =~ m!^\+\+\+!;
5150 sub git_blobdiff_plain
{
5151 git_blobdiff
('plain');
5154 sub git_commitdiff
{
5155 my $format = shift || 'html';
5156 $hash ||= $hash_base || "HEAD";
5157 my %co = parse_commit
($hash)
5158 or die_error
(404, "Unknown commit object");
5160 # choose format for commitdiff for merge
5161 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5162 $hash_parent = '--cc';
5164 # we need to prepare $formats_nav before almost any parameter munging
5166 if ($format eq 'html') {
5168 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5171 if (defined $hash_parent &&
5172 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5173 # commitdiff with two commits given
5174 my $hash_parent_short = $hash_parent;
5175 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5176 $hash_parent_short = substr($hash_parent, 0, 7);
5180 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5181 if ($co{'parents'}[$i] eq $hash_parent) {
5182 $formats_nav .= ' parent ' . ($i+1);
5186 $formats_nav .= ': ' .
5187 $cgi->a({-href
=> href
(action
=>"commitdiff",
5188 hash
=>$hash_parent)},
5189 esc_html
($hash_parent_short)) .
5191 } elsif (!$co{'parent'}) {
5193 $formats_nav .= ' (initial)';
5194 } elsif (scalar @{$co{'parents'}} == 1) {
5195 # single parent commit
5198 $cgi->a({-href
=> href
(action
=>"commitdiff",
5199 hash
=>$co{'parent'})},
5200 esc_html
(substr($co{'parent'}, 0, 7))) .
5204 if ($hash_parent eq '--cc') {
5205 $formats_nav .= ' | ' .
5206 $cgi->a({-href
=> href
(action
=>"commitdiff",
5207 hash
=>$hash, hash_parent
=>'-c')},
5209 } else { # $hash_parent eq '-c'
5210 $formats_nav .= ' | ' .
5211 $cgi->a({-href
=> href
(action
=>"commitdiff",
5212 hash
=>$hash, hash_parent
=>'--cc')},
5218 $cgi->a({-href
=> href
(action
=>"commitdiff",
5220 esc_html
(substr($_, 0, 7)));
5221 } @{$co{'parents'}} ) .
5226 my $hash_parent_param = $hash_parent;
5227 if (!defined $hash_parent_param) {
5228 # --cc for multiple parents, --root for parentless
5229 $hash_parent_param =
5230 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5236 if ($format eq 'html') {
5237 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5238 "--no-commit-id", "--patch-with-raw", "--full-index",
5239 $hash_parent_param, $hash, "--"
5240 or die_error
(500, "Open git-diff-tree failed");
5242 while (my $line = <$fd>) {
5244 # empty line ends raw part of diff-tree output
5246 push @difftree, scalar parse_difftree_raw_line
($line);
5249 } elsif ($format eq 'plain') {
5250 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5251 '-p', $hash_parent_param, $hash, "--"
5252 or die_error
(500, "Open git-diff-tree failed");
5255 die_error
(400, "Unknown commitdiff format");
5258 # non-textual hash id's can be cached
5260 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5264 # write commit message
5265 if ($format eq 'html') {
5266 my $refs = git_get_references
();
5267 my $ref = format_ref_marker
($refs, $co{'id'});
5269 git_header_html
(undef, $expires);
5270 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5271 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5272 git_print_authorship
(\
%co);
5273 print "<div class=\"page_body\">\n";
5274 if (@{$co{'comment'}} > 1) {
5275 print "<div class=\"log\">\n";
5276 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5277 print "</div>\n"; # class="log"
5280 } elsif ($format eq 'plain') {
5281 my $refs = git_get_references
("tags");
5282 my $tagname = git_get_rev_name_tags
($hash);
5283 my $filename = basename
($project) . "-$hash.patch";
5286 -type
=> 'text/plain',
5287 -charset
=> 'utf-8',
5288 -expires
=> $expires,
5289 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5290 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5291 print "From: " . to_utf8
($co{'author'}) . "\n";
5292 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5293 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5295 print "X-Git-Tag: $tagname\n" if $tagname;
5296 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5298 foreach my $line (@{$co{'comment'}}) {
5299 print to_utf8
($line) . "\n";
5305 if ($format eq 'html') {
5306 my $use_parents = !defined $hash_parent ||
5307 $hash_parent eq '-c' || $hash_parent eq '--cc';
5308 git_difftree_body
(\
@difftree, $hash,
5309 $use_parents ? @{$co{'parents'}} : $hash_parent);
5312 git_patchset_body
($fd, \
@difftree, $hash,
5313 $use_parents ? @{$co{'parents'}} : $hash_parent);
5315 print "</div>\n"; # class="page_body"
5318 } elsif ($format eq 'plain') {
5322 or print "Reading git-diff-tree failed\n";
5326 sub git_commitdiff_plain
{
5327 git_commitdiff
('plain');
5331 if (!defined $hash_base) {
5332 $hash_base = git_get_head_hash
($project);
5334 if (!defined $page) {
5338 my %co = parse_commit
($hash_base)
5339 or die_error
(404, "Unknown commit object");
5341 my $refs = git_get_references
();
5342 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5344 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5345 $file_name, "--full-history")
5346 or die_error
(404, "No such file or directory on given branch");
5348 if (!defined $hash && defined $file_name) {
5349 # some commits could have deleted file in question,
5350 # and not have it in tree, but one of them has to have it
5351 for (my $i = 0; $i <= @commitlist; $i++) {
5352 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5353 last if defined $hash;
5356 if (defined $hash) {
5357 $ftype = git_get_type
($hash);
5359 if (!defined $ftype) {
5360 die_error
(500, "Unknown type of object");
5363 my $paging_nav = '';
5366 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5367 file_name
=>$file_name)},
5369 $paging_nav .= " ⋅ " .
5370 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5371 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5373 $paging_nav .= "first";
5374 $paging_nav .= " ⋅ prev";
5377 if ($#commitlist >= 100) {
5379 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5380 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5381 $paging_nav .= " ⋅ $next_link";
5383 $paging_nav .= " ⋅ next";
5387 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5388 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5389 git_print_page_path
($file_name, $ftype, $hash_base);
5391 git_history_body
(\
@commitlist, 0, 99,
5392 $refs, $hash_base, $ftype, $next_link);
5398 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5399 if (!defined $searchtext) {
5400 die_error
(400, "Text field is empty");
5402 if (!defined $hash) {
5403 $hash = git_get_head_hash
($project);
5405 my %co = parse_commit
($hash);
5407 die_error
(404, "Unknown commit object");
5409 if (!defined $page) {
5413 $searchtype ||= 'commit';
5414 if ($searchtype eq 'pickaxe') {
5415 # pickaxe may take all resources of your box and run for several minutes
5416 # with every query - so decide by yourself how public you make this feature
5417 gitweb_check_feature
('pickaxe')
5418 or die_error
(403, "Pickaxe is disabled");
5420 if ($searchtype eq 'grep') {
5421 gitweb_check_feature
('grep')
5422 or die_error
(403, "Grep is disabled");
5427 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5429 if ($searchtype eq 'commit') {
5430 $greptype = "--grep=";
5431 } elsif ($searchtype eq 'author') {
5432 $greptype = "--author=";
5433 } elsif ($searchtype eq 'committer') {
5434 $greptype = "--committer=";
5436 $greptype .= $searchtext;
5437 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5438 $greptype, '--regexp-ignore-case',
5439 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5441 my $paging_nav = '';
5444 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5445 searchtext
=>$searchtext,
5446 searchtype
=>$searchtype)},
5448 $paging_nav .= " ⋅ " .
5449 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5450 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5452 $paging_nav .= "first";
5453 $paging_nav .= " ⋅ prev";
5456 if ($#commitlist >= 100) {
5458 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5459 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5460 $paging_nav .= " ⋅ $next_link";
5462 $paging_nav .= " ⋅ next";
5465 if ($#commitlist >= 100) {
5468 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5469 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5470 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5473 if ($searchtype eq 'pickaxe') {
5474 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5475 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5477 print "<table class=\"pickaxe search\">\n";
5480 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5481 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5482 ($search_use_regexp ? '--pickaxe-regex' : ());
5485 while (my $line = <$fd>) {
5489 my %set = parse_difftree_raw_line
($line);
5490 if (defined $set{'commit'}) {
5491 # finish previous commit
5494 "<td class=\"link\">" .
5495 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5497 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5503 print "<tr class=\"dark\">\n";
5505 print "<tr class=\"light\">\n";
5508 %co = parse_commit
($set{'commit'});
5509 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5510 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5511 "<td><i>$author</i></td>\n" .
5513 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5514 -class => "list subject"},
5515 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5516 } elsif (defined $set{'to_id'}) {
5517 next if ($set{'to_id'} =~ m/^0{40}$/);
5519 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5520 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5522 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5528 # finish last commit (warning: repetition!)
5531 "<td class=\"link\">" .
5532 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5534 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5542 if ($searchtype eq 'grep') {
5543 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5544 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5546 print "<table class=\"grep_search\">\n";
5550 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5551 $search_use_regexp ? ('-E', '-i') : '-F',
5552 $searchtext, $co{'tree'};
5554 while (my $line = <$fd>) {
5556 my ($file, $lno, $ltext, $binary);
5557 last if ($matches++ > 1000);
5558 if ($line =~ /^Binary file (.+) matches$/) {
5562 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5564 if ($file ne $lastfile) {
5565 $lastfile and print "</td></tr>\n";
5567 print "<tr class=\"dark\">\n";
5569 print "<tr class=\"light\">\n";
5571 print "<td class=\"list\">".
5572 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5573 file_name
=>"$file"),
5574 -class => "list"}, esc_path
($file));
5575 print "</td><td>\n";
5579 print "<div class=\"binary\">Binary file</div>\n";
5581 $ltext = untabify
($ltext);
5582 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5583 $ltext = esc_html
($1, -nbsp
=>1);
5584 $ltext .= '<span class="match">';
5585 $ltext .= esc_html
($2, -nbsp
=>1);
5586 $ltext .= '</span>';
5587 $ltext .= esc_html
($3, -nbsp
=>1);
5589 $ltext = esc_html
($ltext, -nbsp
=>1);
5591 print "<div class=\"pre\">" .
5592 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5593 file_name
=>"$file").'#l'.$lno,
5594 -class => "linenr"}, sprintf('%4i', $lno))
5595 . ' ' . $ltext . "</div>\n";
5599 print "</td></tr>\n";
5600 if ($matches > 1000) {
5601 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5604 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5613 sub git_search_help
{
5615 git_print_page_nav
('','', $hash,$hash,$hash);
5617 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5618 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5619 the pattern entered is recognized as the POSIX extended
5620 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5623 <dt><b>commit</b></dt>
5624 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5626 my ($have_grep) = gitweb_check_feature
('grep');
5629 <dt><b>grep</b></dt>
5630 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5631 a different one) are searched for the given pattern. On large trees, this search can take
5632 a while and put some strain on the server, so please use it with some consideration. Note that
5633 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5634 case-sensitive.</dd>
5638 <dt><b>author</b></dt>
5639 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5640 <dt><b>committer</b></dt>
5641 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5643 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5644 if ($have_pickaxe) {
5646 <dt><b>pickaxe</b></dt>
5647 <dd>All commits that caused the string to appear or disappear from any file (changes that
5648 added, removed or "modified" the string) will be listed. This search can take a while and
5649 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5650 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5658 my $head = git_get_head_hash
($project);
5659 if (!defined $hash) {
5662 if (!defined $page) {
5665 my $refs = git_get_references
();
5667 my $commit_hash = $hash;
5668 if (defined $hash_parent) {
5669 $commit_hash = "$hash_parent..$hash";
5671 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5673 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5675 if ($#commitlist >= 100) {
5677 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5678 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5682 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5683 git_print_header_div
('summary', $project);
5685 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5690 ## ......................................................................
5691 ## feeds (RSS, Atom; OPML)
5694 my $format = shift || 'atom';
5695 my ($have_blame) = gitweb_check_feature
('blame');
5697 # Atom: http://www.atomenabled.org/developers/syndication/
5698 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5699 if ($format ne 'rss' && $format ne 'atom') {
5700 die_error
(400, "Unknown web feed format");
5703 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5704 my $head = $hash || 'HEAD';
5705 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5709 my $content_type = "application/$format+xml";
5710 if (defined $cgi->http('HTTP_ACCEPT') &&
5711 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5712 # browser (feed reader) prefers text/xml
5713 $content_type = 'text/xml';
5715 if (defined($commitlist[0])) {
5716 %latest_commit = %{$commitlist[0]};
5717 %latest_date = parse_date
($latest_commit{'author_epoch'});
5719 -type
=> $content_type,
5720 -charset
=> 'utf-8',
5721 -last_modified
=> $latest_date{'rfc2822'});
5724 -type
=> $content_type,
5725 -charset
=> 'utf-8');
5728 # Optimization: skip generating the body if client asks only
5729 # for Last-Modified date.
5730 return if ($cgi->request_method() eq 'HEAD');
5733 my $title = "$site_name - $project/$action";
5734 my $feed_type = 'log';
5735 if (defined $hash) {
5736 $title .= " - '$hash'";
5737 $feed_type = 'branch log';
5738 if (defined $file_name) {
5739 $title .= " :: $file_name";
5740 $feed_type = 'history';
5742 } elsif (defined $file_name) {
5743 $title .= " - $file_name";
5744 $feed_type = 'history';
5746 $title .= " $feed_type";
5747 my $descr = git_get_project_description
($project);
5748 if (defined $descr) {
5749 $descr = esc_html
($descr);
5751 $descr = "$project " .
5752 ($format eq 'rss' ? 'RSS' : 'Atom') .
5755 my $owner = git_get_project_owner
($project);
5756 $owner = esc_html
($owner);
5760 if (defined $file_name) {
5761 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5762 } elsif (defined $hash) {
5763 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5765 $alt_url = href
(-full
=>1, action
=>"summary");
5767 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5768 if ($format eq 'rss') {
5770 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5773 print "<title>$title</title>\n" .
5774 "<link>$alt_url</link>\n" .
5775 "<description>$descr</description>\n" .
5776 "<language>en</language>\n";
5777 } elsif ($format eq 'atom') {
5779 <feed xmlns="http://www.w3.org/2005/Atom">
5781 print "<title>$title</title>\n" .
5782 "<subtitle>$descr</subtitle>\n" .
5783 '<link rel="alternate" type="text/html" href="' .
5784 $alt_url . '" />' . "\n" .
5785 '<link rel="self" type="' . $content_type . '" href="' .
5786 $cgi->self_url() . '" />' . "\n" .
5787 "<id>" . href
(-full
=>1) . "</id>\n" .
5788 # use project owner for feed author
5789 "<author><name>$owner</name></author>\n";
5790 if (defined $favicon) {
5791 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5793 if (defined $logo_url) {
5794 # not twice as wide as tall: 72 x 27 pixels
5795 print "<logo>" . esc_url
($logo) . "</logo>\n";
5797 if (! %latest_date) {
5798 # dummy date to keep the feed valid until commits trickle in:
5799 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5801 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5806 for (my $i = 0; $i <= $#commitlist; $i++) {
5807 my %co = %{$commitlist[$i]};
5808 my $commit = $co{'id'};
5809 # we read 150, we always show 30 and the ones more recent than 48 hours
5810 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5813 my %cd = parse_date
($co{'author_epoch'});
5815 # get list of changed files
5816 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5817 $co{'parent'} || "--root",
5818 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5820 my @difftree = map { chomp; $_ } <$fd>;
5824 # print element (entry, item)
5825 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5826 if ($format eq 'rss') {
5828 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5829 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5830 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5831 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5832 "<link>$co_url</link>\n" .
5833 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5834 "<content:encoded>" .
5836 } elsif ($format eq 'atom') {
5838 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5839 "<updated>$cd{'iso-8601'}</updated>\n" .
5841 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5842 if ($co{'author_email'}) {
5843 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5845 print "</author>\n" .
5846 # use committer for contributor
5848 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5849 if ($co{'committer_email'}) {
5850 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5852 print "</contributor>\n" .
5853 "<published>$cd{'iso-8601'}</published>\n" .
5854 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5855 "<id>$co_url</id>\n" .
5856 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5857 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5859 my $comment = $co{'comment'};
5861 foreach my $line (@$comment) {
5862 $line = esc_html
($line);
5865 print "</pre><ul>\n";
5866 foreach my $difftree_line (@difftree) {
5867 my %difftree = parse_difftree_raw_line
($difftree_line);
5868 next if !$difftree{'from_id'};
5870 my $file = $difftree{'file'} || $difftree{'to_file'};
5874 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5875 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5876 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5877 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5878 -title
=> "diff"}, 'D');
5880 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5881 file_name
=>$file, hash_base
=>$commit),
5882 -title
=> "blame"}, 'B');
5884 # if this is not a feed of a file history
5885 if (!defined $file_name || $file_name ne $file) {
5886 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5887 file_name
=>$file, hash
=>$commit),
5888 -title
=> "history"}, 'H');
5890 $file = esc_path
($file);
5894 if ($format eq 'rss') {
5895 print "</ul>]]>\n" .
5896 "</content:encoded>\n" .
5898 } elsif ($format eq 'atom') {
5899 print "</ul>\n</div>\n" .
5906 if ($format eq 'rss') {
5907 print "</channel>\n</rss>\n";
5908 } elsif ($format eq 'atom') {
5922 my @list = git_get_projects_list
();
5924 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5926 <?xml version="1.0" encoding="utf-8"?>
5927 <opml version="1.0">
5929 <title>$site_name OPML Export</title>
5932 <outline text="git RSS feeds">
5935 foreach my $pr (@list) {
5937 my $head = git_get_head_hash
($proj{'path'});
5938 if (!defined $head) {
5941 $git_dir = "$projectroot/$proj{'path'}";
5942 my %co = parse_commit
($head);
5947 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5948 my $rss = "$my_url?p=$proj{'path'};a=rss";
5949 my $html = "$my_url?p=$proj{'path'};a=summary";
5950 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";