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;
71 # URI of GIT logo (72x27 size)
72 our $logo = "++GITWEB_LOGO++";
73 # URI of GIT favicon, assumed to be image/png type
74 our $favicon = "++GITWEB_FAVICON++";
76 our $gitwebjs = "++GITWEB_GITWEBJS++";
78 # URI and label (title) of GIT logo link
79 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
80 #our $logo_label = "git documentation";
81 our $logo_url = "http://git.or.cz/";
82 our $logo_label = "git homepage";
84 # source of projects list
85 our $projects_list = "++GITWEB_LIST++";
87 # the width (in characters) of the projects list "Description" column
88 our $projects_list_description_width = 25;
90 # default order of projects list
91 # valid values are none, project, descr, owner, and age
92 our $default_projects_order = "project";
94 # show repository only if this file exists
95 # (only effective if this variable evaluates to true)
96 our $export_ok = "++GITWEB_EXPORT_OK++";
98 # only allow viewing of repositories also shown on the overview page
99 our $strict_export = "++GITWEB_STRICT_EXPORT++";
101 # list of git base URLs used for URL to where fetch project from,
102 # i.e. full URL is "$git_base_url/$project"
103 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
105 # an URL designated for pushing new changes, extended by the
106 # project name (i.e. "$git_base_push_url/$project")
107 our $git_base_push_url = '';
109 # default blob_plain mimetype and default charset for text/plain blob
110 our $default_blob_plain_mimetype = 'text/plain';
111 our $default_text_plain_charset = undef;
113 # file to use for guessing MIME types before trying /etc/mime.types
114 # (relative to the current git repository)
115 our $mimetypes_file = undef;
117 # assume this charset if line contains non-UTF-8 characters;
118 # it should be valid encoding (see Encoding::Supported(3pm) for list),
119 # for which encoding all byte sequences are valid, for example
120 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
121 # could be even 'utf-8' for the old behavior)
122 our $fallback_encoding = 'latin1';
124 # rename detection options for git-diff and git-diff-tree
125 # - default is '-M', with the cost proportional to
126 # (number of removed files) * (number of new files).
127 # - more costly is '-C' (which implies '-M'), with the cost proportional to
128 # (number of changed files + number of removed files) * (number of new files)
129 # - even more costly is '-C', '--find-copies-harder' with cost
130 # (number of files in the original tree) * (number of new files)
131 # - one might want to include '-B' option, e.g. '-B', '-M'
132 our @diff_opts = ('-M'); # taken from git_commit
134 # projects list cache for busy sites with many projects;
135 # if you set this to non-zero, it will be used as the cached
136 # index lifetime in minutes
138 # the cached list version is stored in $cache_dir/$cache_name and can
139 # be tweaked by other scripts running with the same uid as gitweb -
140 # use this ONLY at secure installations; only single gitweb project
141 # root per system is supported, unless you tweak configuration!
142 our $projlist_cache_lifetime = 0; # in minutes
143 # FHS compliant $cache_dir would be "/var/cache/gitweb"
145 (defined $ENV{'TMPDIR'} ?
$ENV{'TMPDIR'} : '/tmp').'/gitweb';
146 our $projlist_cache_name = 'gitweb.index.cache';
148 # information about snapshot formats that gitweb is capable of serving
149 our %known_snapshot_formats = (
151 # 'display' => display name,
152 # 'type' => mime type,
153 # 'suffix' => filename suffix,
154 # 'format' => --format for git-archive,
155 # 'compressor' => [compressor command and arguments]
156 # (array reference, optional)}
159 'display' => 'tar.gz',
160 'type' => 'application/x-gzip',
161 'suffix' => '.tar.gz',
163 'compressor' => ['gzip']},
166 'display' => 'tar.bz2',
167 'type' => 'application/x-bzip2',
168 'suffix' => '.tar.bz2',
170 'compressor' => ['bzip2']},
174 'type' => 'application/x-zip',
179 # Aliases so we understand old gitweb.snapshot values in repository
181 our %known_snapshot_format_aliases = (
185 # backward compatibility: legacy gitweb config support
186 'x-gzip' => undef, 'gz' => undef,
187 'x-bzip2' => undef, 'bz2' => undef,
188 'x-zip' => undef, '' => undef,
191 # You define site-wide feature defaults here; override them with
192 # $GITWEB_CONFIG as necessary.
195 # 'sub' => feature-sub (subroutine),
196 # 'override' => allow-override (boolean),
197 # 'default' => [ default options...] (array reference)}
199 # if feature is overridable (it means that allow-override has true value),
200 # then feature-sub will be called with default options as parameters;
201 # return value of feature-sub indicates if to enable specified feature
203 # if there is no 'sub' key (no feature-sub), then feature cannot be
206 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
208 # Enable the 'blame' blob view, showing the last commit that modified
209 # each line in the file. This can be very CPU-intensive.
211 # To enable system wide have in $GITWEB_CONFIG
212 # $feature{'blame'}{'default'} = [1];
213 # To have project specific config enable override in $GITWEB_CONFIG
214 # $feature{'blame'}{'override'} = 1;
215 # and in project config gitweb.blame = 0|1;
217 'sub' => \
&feature_blame
,
221 # Enable the 'snapshot' link, providing a compressed archive of any
222 # tree. This can potentially generate high traffic if you have large
225 # Value is a list of formats defined in %known_snapshot_formats that
227 # To disable system wide have in $GITWEB_CONFIG
228 # $feature{'snapshot'}{'default'} = [];
229 # To have project specific config enable override in $GITWEB_CONFIG
230 # $feature{'snapshot'}{'override'} = 1;
231 # and in project config, a comma-separated list of formats or "none"
232 # to disable. Example: gitweb.snapshot = tbz2,zip;
234 'sub' => \
&feature_snapshot
,
236 'default' => ['tgz']},
238 # Enable text search, which will list the commits which match author,
239 # committer or commit text to a given string. Enabled by default.
240 # Project specific override is not supported.
245 # Enable grep search, which will list the files in currently selected
246 # tree containing the given string. Enabled by default. This can be
247 # potentially CPU-intensive, of course.
249 # To enable system wide have in $GITWEB_CONFIG
250 # $feature{'grep'}{'default'} = [1];
251 # To have project specific config enable override in $GITWEB_CONFIG
252 # $feature{'grep'}{'override'} = 1;
253 # and in project config gitweb.grep = 0|1;
258 # Enable the pickaxe search, which will list the commits that modified
259 # a given string in a file. This can be practical and quite faster
260 # alternative to 'blame', but still potentially CPU-intensive.
262 # To enable system wide have in $GITWEB_CONFIG
263 # $feature{'pickaxe'}{'default'} = [1];
264 # To have project specific config enable override in $GITWEB_CONFIG
265 # $feature{'pickaxe'}{'override'} = 1;
266 # and in project config gitweb.pickaxe = 0|1;
268 'sub' => \
&feature_pickaxe
,
272 # Make gitweb use an alternative format of the URLs which can be
273 # more readable and natural-looking: project name is embedded
274 # directly in the path and the query string contains other
275 # auxiliary information. All gitweb installations recognize
276 # URL in either format; this configures in which formats gitweb
279 # To enable system wide have in $GITWEB_CONFIG
280 # $feature{'pathinfo'}{'default'} = [1];
281 # Project specific override is not supported.
283 # Note that you will need to change the default location of CSS,
284 # favicon, logo and possibly other files to an absolute URL. Also,
285 # if gitweb.cgi serves as your indexfile, you will need to force
286 # $my_uri to contain the script name in your $GITWEB_CONFIG.
291 # Make gitweb consider projects in project root subdirectories
292 # to be forks of existing projects. Given project $projname.git,
293 # projects matching $projname/*.git will not be shown in the main
294 # projects list, instead a '+' mark will be added to $projname
295 # there and a 'forks' view will be enabled for the project, listing
296 # all the forks. If project list is taken from a file, forks have
297 # to be listed after the main project.
299 # To enable system wide have in $GITWEB_CONFIG
300 # $feature{'forks'}{'default'} = [1];
301 # Project specific override is not supported.
306 # Insert custom links to the action bar of all project pages.
307 # This enables you mainly to link to third-party scripts integrating
308 # into gitweb; e.g. git-browser for graphical history representation
309 # or custom web-based repository administration interface.
311 # The 'default' value consists of a list of triplets in the form
312 # (label, link, position) where position is the label after which
313 # to inster the link and link is a format string where %n expands
314 # to the project name, %f to the project path within the filesystem,
315 # %h to the current hash (h gitweb parameter) and %b to the current
316 # hash base (hb gitweb parameter).
318 # To enable system wide have in $GITWEB_CONFIG e.g.
319 # $feature{'actions'}{'default'} = [('graphiclog',
320 # '/git-browser/by-commit.html?r=%n', 'summary')];
321 # Project specific override is not supported.
326 # Allow gitweb scan project content tags described in ctags/
327 # of project repository, and display the popular Web 2.0-ish
328 # "tag cloud" near the project list. Note that this is something
329 # COMPLETELY different from the normal Git tags.
331 # gitweb by itself can show existing tags, but it does not handle
332 # tagging itself; you need an external application for that.
333 # For an example script, check Girocco's cgi/tagproj.cgi.
334 # You may want to install the HTML::TagCloud Perl module to get
335 # a pretty tag cloud instead of just a list of tags.
337 # To enable system wide have in $GITWEB_CONFIG
338 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
339 # Project specific override is not supported.
347 if (eval { require HTML
::Email
::Obfuscate
; 1 }) {
348 $email = HTML
::Email
::Obfuscate
->new(lite
=> 1);
351 sub gitweb_check_feature
{
353 return unless exists $feature{$name};
354 my ($sub, $override, @defaults) = (
355 $feature{$name}{'sub'},
356 $feature{$name}{'override'},
357 @
{$feature{$name}{'default'}});
358 if (!$override) { return @defaults; }
360 warn "feature $name is not overrideable";
363 return $sub->(@defaults);
367 my ($val) = git_get_project_config
('blame', '--bool');
369 if ($val eq 'true') {
371 } elsif ($val eq 'false') {
378 sub feature_snapshot
{
381 my ($val) = git_get_project_config
('snapshot');
384 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
391 my ($val) = git_get_project_config
('grep', '--bool');
393 if ($val eq 'true') {
395 } elsif ($val eq 'false') {
402 sub feature_pickaxe
{
403 my ($val) = git_get_project_config
('pickaxe', '--bool');
405 if ($val eq 'true') {
407 } elsif ($val eq 'false') {
414 # checking HEAD file with -e is fragile if the repository was
415 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
417 sub check_head_link
{
419 my $headfile = "$dir/HEAD";
420 return ((-e
$headfile) ||
421 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
424 sub check_export_ok
{
426 return (check_head_link
($dir) &&
427 (!$export_ok || -e
"$dir/$export_ok"));
430 # process alternate names for backward compatibility
431 # filter out unsupported (unknown) snapshot formats
432 sub filter_snapshot_fmts
{
436 exists $known_snapshot_format_aliases{$_} ?
437 $known_snapshot_format_aliases{$_} : $_} @fmts;
438 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
442 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
443 if (-e
$GITWEB_CONFIG) {
446 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
447 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
450 # version of the core git binary
451 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
453 $projects_list ||= $projectroot;
455 # ======================================================================
456 # input validation and dispatch
457 our $action = $cgi->param('a');
458 if (defined $action) {
459 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
460 die_error
(400, "Invalid action parameter");
464 # parameters which are pathnames
465 our $project = $cgi->param('p');
466 if (defined $project) {
467 if (!validate_pathname
($project) ||
468 !(-d
"$projectroot/$project") ||
469 !check_head_link
("$projectroot/$project") ||
470 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
471 ($strict_export && !project_in_list
($project))) {
473 die_error
(404, "No such project");
477 our $file_name = $cgi->param('f');
478 if (defined $file_name) {
479 if (!validate_pathname
($file_name)) {
480 die_error
(400, "Invalid file parameter");
484 our $file_parent = $cgi->param('fp');
485 if (defined $file_parent) {
486 if (!validate_pathname
($file_parent)) {
487 die_error
(400, "Invalid file parent parameter");
491 # parameters which are refnames
492 our $hash = $cgi->param('h');
494 if (!validate_refname
($hash)) {
495 die_error
(400, "Invalid hash parameter");
499 our $hash_parent = $cgi->param('hp');
500 if (defined $hash_parent) {
501 if (!validate_refname
($hash_parent)) {
502 die_error
(400, "Invalid hash parent parameter");
506 our $hash_base = $cgi->param('hb');
507 if (defined $hash_base) {
508 if (!validate_refname
($hash_base)) {
509 die_error
(400, "Invalid hash base parameter");
513 my %allowed_options = (
514 "--no-merges" => [ qw(rss atom log shortlog history) ],
517 our @extra_options = $cgi->param('opt');
518 if (defined @extra_options) {
519 foreach my $opt (@extra_options) {
520 if (not exists $allowed_options{$opt}) {
521 die_error
(400, "Invalid option parameter");
523 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
524 die_error
(400, "Invalid option parameter for this action");
529 our $hash_parent_base = $cgi->param('hpb');
530 if (defined $hash_parent_base) {
531 if (!validate_refname
($hash_parent_base)) {
532 die_error
(400, "Invalid hash parent base parameter");
537 our $page = $cgi->param('pg');
539 if ($page =~ m/[^0-9]/) {
540 die_error
(400, "Invalid page parameter");
544 our $searchtype = $cgi->param('st');
545 if (defined $searchtype) {
546 if ($searchtype =~ m/[^a-z]/) {
547 die_error
(400, "Invalid searchtype parameter");
551 our $search_use_regexp = $cgi->param('sr');
553 our $searchtext = $cgi->param('s');
555 if (defined $searchtext) {
556 if (length($searchtext) < 2) {
557 die_error
(403, "At least two characters are required for search parameter");
559 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
562 # now read PATH_INFO and use it as alternative to parameters
563 sub evaluate_path_info
{
564 return if defined $project;
565 my $path_info = $ENV{"PATH_INFO"};
566 return if !$path_info;
567 $path_info =~ s
,^/+,,;
568 return if !$path_info;
569 # find which part of PATH_INFO is project
570 $project = $path_info;
572 while ($project && !check_head_link
("$projectroot/$project")) {
573 $project =~ s
,/*[^/]*$,,;
576 $project = validate_pathname
($project);
578 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
579 ($strict_export && !project_in_list
($project))) {
583 # do not change any parameters if an action is given using the query string
585 $path_info =~ s
,^\Q
$project\E
/*,,;
586 my ($refname, $pathname) = split(/:/, $path_info, 2);
587 if (defined $pathname) {
588 # we got "project.git/branch:filename" or "project.git/branch:dir/"
589 # we could use git_get_type(branch:pathname), but it needs $git_dir
590 $pathname =~ s
,^/+,,;
591 if (!$pathname || substr($pathname, -1) eq "/") {
595 $action ||= "blob_plain";
597 $hash_base ||= validate_refname
($refname);
598 $file_name ||= validate_pathname
($pathname);
599 } elsif (defined $refname) {
600 # we got "project.git/branch"
601 $action ||= "shortlog";
602 $hash ||= validate_refname
($refname);
605 evaluate_path_info
();
607 # path to the current git repository
609 $git_dir = "$projectroot/$project" if $project;
613 "blame" => \
&git_blame
,
614 "blame_incremental" => \
&git_blame_incremental
,
615 "blame_data" => \
&git_blame_data
,
616 "blobdiff" => \
&git_blobdiff
,
617 "blobdiff_plain" => \
&git_blobdiff_plain
,
618 "blob" => \
&git_blob
,
619 "blob_plain" => \
&git_blob_plain
,
620 "commitdiff" => \
&git_commitdiff
,
621 "commitdiff_plain" => \
&git_commitdiff_plain
,
622 "commit" => \
&git_commit
,
623 "forks" => \
&git_forks
,
624 "heads" => \
&git_heads
,
625 "history" => \
&git_history
,
628 "atom" => \
&git_atom
,
629 "search" => \
&git_search
,
630 "search_help" => \
&git_search_help
,
631 "shortlog" => \
&git_shortlog
,
632 "summary" => \
&git_summary
,
634 "tags" => \
&git_tags
,
635 "tree" => \
&git_tree
,
636 "snapshot" => \
&git_snapshot
,
637 "object" => \
&git_object
,
638 # those below don't need $project
639 "opml" => \
&git_opml
,
640 "project_list" => \
&git_project_list
,
641 "project_index" => \
&git_project_index
,
644 if (!defined $action) {
646 $action = git_get_type
($hash);
647 } elsif (defined $hash_base && defined $file_name) {
648 $action = git_get_type
("$hash_base:$file_name");
649 } elsif (defined $project) {
652 $action = 'project_list';
655 if (!defined($actions{$action})) {
656 die_error
(400, "Unknown action");
658 if ($action !~ m/^(opml|project_list|project_index)$/ &&
660 die_error
(400, "Project needed");
662 $actions{$action}->();
665 ## ======================================================================
670 # default is to use -absolute url() i.e. $my_uri
671 my $href = $params{-full
} ?
$my_url : $my_uri;
673 # XXX: Warning: If you touch this, check the search form for updating,
684 hash_parent_base
=> "hpb",
689 snapshot_format
=> "sf",
690 extra_options
=> "opt",
691 search_use_regexp
=> "sr",
693 my %mapping = @mapping;
695 $params{'project'} = $project unless exists $params{'project'};
697 if ($params{-replay
}) {
698 while (my ($name, $symbol) = each %mapping) {
699 if (!exists $params{$name}) {
700 # to allow for multivalued params we use arrayref form
701 $params{$name} = [ $cgi->param($symbol) ];
706 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
708 # use PATH_INFO for project name
709 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
710 delete $params{'project'};
712 # Summary just uses the project path URL
713 if (defined $params{'action'} && $params{'action'} eq 'summary') {
714 delete $params{'action'};
718 # now encode the parameters explicitly
720 for (my $i = 0; $i < @mapping; $i += 2) {
721 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
722 if (defined $params{$name}) {
723 if (ref($params{$name}) eq "ARRAY") {
724 foreach my $par (@
{$params{$name}}) {
725 push @result, $symbol . "=" . esc_param
($par);
728 push @result, $symbol . "=" . esc_param
($params{$name});
732 $href .= "?" . join(';', @result) if $params{-partial_query
} or scalar @result;
738 ## ======================================================================
739 ## validation, quoting/unquoting and escaping
741 sub validate_pathname
{
742 my $input = shift || return undef;
744 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
745 # at the beginning, at the end, and between slashes.
746 # also this catches doubled slashes
747 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
751 if ($input =~ m!\0!) {
757 sub validate_refname
{
758 my $input = shift || return undef;
760 # textual hashes are O.K.
761 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
764 # it must be correct pathname
765 $input = validate_pathname
($input)
767 # restrictions on ref name according to git-check-ref-format
768 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
774 # decode sequences of octets in utf8 into Perl's internal form,
775 # which is utf-8 with utf8 flag set if needed. gitweb writes out
776 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
779 if (utf8
::valid
($str)) {
783 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
787 # quote unsafe chars, but keep the slash, even when it's not
788 # correct, but quoted slashes look too horrible in bookmarks
791 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
797 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
800 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
806 # replace invalid utf8 character with SUBSTITUTION sequence
811 $str = to_utf8
($str);
812 $str = $cgi->escapeHTML($str);
813 if ($opts{'-nbsp'}) {
814 $str =~ s/ / /g;
816 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
820 # quote control characters and escape filename to HTML
825 $str = to_utf8
($str);
826 $str = $cgi->escapeHTML($str);
827 if ($opts{'-nbsp'}) {
828 $str =~ s/ / /g;
830 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
834 # Make control characters "printable", using character escape codes (CEC)
838 my %es = ( # character escape codes, aka escape sequences
839 "\t" => '\t', # tab (HT)
840 "\n" => '\n', # line feed (LF)
841 "\r" => '\r', # carrige return (CR)
842 "\f" => '\f', # form feed (FF)
843 "\b" => '\b', # backspace (BS)
844 "\a" => '\a', # alarm (bell) (BEL)
845 "\e" => '\e', # escape (ESC)
846 "\013" => '\v', # vertical tab (VT)
847 "\000" => '\0', # nul character (NUL)
849 my $chr = ( (exists $es{$cntrl})
851 : sprintf('\%2x', ord($cntrl)) );
852 if ($opts{-nohtml
}) {
855 return "<span class=\"cntrl\">$chr</span>";
859 # Alternatively use unicode control pictures codepoints,
860 # Unicode "printable representation" (PR)
865 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
866 if ($opts{-nohtml
}) {
869 return "<span class=\"cntrl\">$chr</span>";
873 # git may return quoted and escaped filenames
879 my %es = ( # character escape codes, aka escape sequences
880 't' => "\t", # tab (HT, TAB)
881 'n' => "\n", # newline (NL)
882 'r' => "\r", # return (CR)
883 'f' => "\f", # form feed (FF)
884 'b' => "\b", # backspace (BS)
885 'a' => "\a", # alarm (bell) (BEL)
886 'e' => "\e", # escape (ESC)
887 'v' => "\013", # vertical tab (VT)
890 if ($seq =~ m/^[0-7]{1,3}$/) {
891 # octal char sequence
892 return chr(oct($seq));
893 } elsif (exists $es{$seq}) {
894 # C escape sequence, aka character escape code
897 # quoted ordinary character
901 if ($str =~ m/^"(.*)"$/) {
904 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
909 # escape tabs (convert tabs to spaces)
913 while ((my $pos = index($line, "\t")) != -1) {
914 if (my $count = (8 - ($pos % 8))) {
915 my $spaces = ' ' x
$count;
916 $line =~ s/\t/$spaces/;
923 sub project_in_list
{
925 my @list = git_get_projects_list
();
926 return @list && scalar(grep { $_->{'path'} eq $project } @list);
929 ## ----------------------------------------------------------------------
930 ## HTML aware string manipulation
932 # Try to chop given string on a word boundary between position
933 # $len and $len+$add_len. If there is no word boundary there,
934 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
935 # (marking chopped part) would be longer than given string.
939 my $add_len = shift || 10;
940 my $where = shift || 'right'; # 'left' | 'center' | 'right'
942 # Make sure perl knows it is utf8 encoded so we don't
943 # cut in the middle of a utf8 multibyte char.
944 $str = to_utf8
($str);
946 # allow only $len chars, but don't cut a word if it would fit in $add_len
947 # if it doesn't fit, cut it if it's still longer than the dots we would add
948 # remove chopped character entities entirely
950 # when chopping in the middle, distribute $len into left and right part
951 # return early if chopping wouldn't make string shorter
952 if ($where eq 'center') {
953 return $str if ($len + 5 >= length($str)); # filler is length 5
956 return $str if ($len + 4 >= length($str)); # filler is length 4
959 # regexps: ending and beginning with word part up to $add_len
960 my $endre = qr/.{$len}\w{0,$add_len}/;
961 my $begre = qr/\w{0,$add_len}.{$len}/;
963 if ($where eq 'left') {
964 $str =~ m/^(.*?)($begre)$/;
965 my ($lead, $body) = ($1, $2);
966 if (length($lead) > 4) {
967 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
972 } elsif ($where eq 'center') {
973 $str =~ m/^($endre)(.*)$/;
974 my ($left, $str) = ($1, $2);
975 $str =~ m/^(.*?)($begre)$/;
976 my ($mid, $right) = ($1, $2);
977 if (length($mid) > 5) {
978 $left =~ s/&[^;]*$//;
979 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
982 return "$left$mid$right";
985 $str =~ m/^($endre)(.*)$/;
988 if (length($tail) > 4) {
989 $body =~ s/&[^;]*$//;
996 # pass-through email filter, obfuscating it when possible
997 sub email_obfuscate
{
1000 $str = $email->escape_html($str);
1001 # Stock HTML::Email::Obfuscate version likes to produce
1003 $str =~ s
#<(/?)B>#<$1b>#g;
1006 $str = esc_html
($str);
1007 $str =~ s/@/@/;
1012 # takes the same arguments as chop_str, but also wraps a <span> around the
1013 # result with a title attribute if it does get chopped. Additionally, the
1014 # string is HTML-escaped.
1015 sub chop_and_escape_str
{
1018 my $chopped = chop_str
(@_);
1019 if ($chopped eq $str) {
1020 return email_obfuscate
($chopped);
1022 $str =~ s/([[:cntrl:]])/?/g;
1023 return $cgi->span({-title
=>$str}, email_obfuscate
($chopped));
1027 ## ----------------------------------------------------------------------
1028 ## functions returning short strings
1030 # CSS class for given age value (in seconds)
1034 if (!defined $age) {
1036 } elsif ($age < 60*60*2) {
1038 } elsif ($age < 60*60*24*2) {
1045 # convert age in seconds to "nn units ago" string
1050 if ($age > 60*60*24*365*2) {
1051 $age_str = (int $age/60/60/24/365);
1052 $age_str .= " years ago";
1053 } elsif ($age > 60*60*24*(365/12)*2) {
1054 $age_str = int $age/60/60/24/(365/12);
1055 $age_str .= " months ago";
1056 } elsif ($age > 60*60*24*7*2) {
1057 $age_str = int $age/60/60/24/7;
1058 $age_str .= " weeks ago";
1059 } elsif ($age > 60*60*24*2) {
1060 $age_str = int $age/60/60/24;
1061 $age_str .= " days ago";
1062 } elsif ($age > 60*60*2) {
1063 $age_str = int $age/60/60;
1064 $age_str .= " hours ago";
1065 } elsif ($age > 60*2) {
1066 $age_str = int $age/60;
1067 $age_str .= " min ago";
1068 } elsif ($age > 2) {
1069 $age_str = int $age;
1070 $age_str .= " sec ago";
1072 $age_str .= " right now";
1078 S_IFINVALID
=> 0030000,
1079 S_IFGITLINK
=> 0160000,
1082 # submodule/subproject, a commit object reference
1083 sub S_ISGITLINK
($) {
1086 return (($mode & S_IFMT
) == S_IFGITLINK
)
1089 # convert file mode in octal to symbolic file mode string
1091 my $mode = oct shift;
1093 if (S_ISGITLINK
($mode)) {
1094 return 'm---------';
1095 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1096 return 'drwxr-xr-x';
1097 } elsif (S_ISLNK
($mode)) {
1098 return 'lrwxrwxrwx';
1099 } elsif (S_ISREG
($mode)) {
1100 # git cares only about the executable bit
1101 if ($mode & S_IXUSR
) {
1102 return '-rwxr-xr-x';
1104 return '-rw-r--r--';
1107 return '----------';
1111 # convert file mode in octal to file type string
1115 if ($mode !~ m/^[0-7]+$/) {
1121 if (S_ISGITLINK
($mode)) {
1123 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1125 } elsif (S_ISLNK
($mode)) {
1127 } elsif (S_ISREG
($mode)) {
1134 # convert file mode in octal to file type description string
1135 sub file_type_long
{
1138 if ($mode !~ m/^[0-7]+$/) {
1144 if (S_ISGITLINK
($mode)) {
1146 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1148 } elsif (S_ISLNK
($mode)) {
1150 } elsif (S_ISREG
($mode)) {
1151 if ($mode & S_IXUSR
) {
1152 return "executable";
1162 ## ----------------------------------------------------------------------
1163 ## functions returning short HTML fragments, or transforming HTML fragments
1164 ## which don't belong to other sections
1166 # format line of commit message.
1167 sub format_log_line_html
{
1170 $line = esc_html
($line, -nbsp
=>1);
1171 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1174 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1175 -class => "text"}, $hash_text);
1176 $line =~ s/$hash_text/$link/;
1181 # format marker of refs pointing to given object
1183 # the destination action is chosen based on object type and current context:
1184 # - for annotated tags, we choose the tag view unless it's the current view
1185 # already, in which case we go to shortlog view
1186 # - for other refs, we keep the current view if we're in history, shortlog or
1187 # log view, and select shortlog otherwise
1188 sub format_ref_marker
{
1189 my ($refs, $id) = @_;
1192 if (defined $refs->{$id}) {
1193 foreach my $ref (@
{$refs->{$id}}) {
1194 # this code exploits the fact that non-lightweight tags are the
1195 # only indirect objects, and that they are the only objects for which
1196 # we want to use tag instead of shortlog as action
1197 my ($type, $name) = qw();
1198 my $indirect = ($ref =~ s/\^\{\}$//);
1199 # e.g. tags/v2.6.11 or heads/next
1200 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1209 $class .= " indirect" if $indirect;
1211 my $dest_action = "shortlog";
1214 $dest_action = "tag" unless $action eq "tag";
1215 } elsif ($action =~ /^(history|(short)?log)$/) {
1216 $dest_action = $action;
1220 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1223 my $link = $cgi->a({
1225 action
=>$dest_action,
1229 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1235 return ' <span class="refs">'. $markers . '</span>';
1241 # format, perhaps shortened and with markers, title line
1242 sub format_subject_html
{
1243 my ($long, $short, $href, $extra) = @_;
1244 $extra = '' unless defined($extra);
1246 if (length($short) < length($long)) {
1247 return $cgi->a({-href
=> $href, -class => "list subject",
1248 -title
=> to_utf8
($long)},
1249 esc_html
($short) . $extra);
1251 return $cgi->a({-href
=> $href, -class => "list subject"},
1252 esc_html
($long) . $extra);
1256 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1257 sub format_git_diff_header_line
{
1259 my $diffinfo = shift;
1260 my ($from, $to) = @_;
1262 if ($diffinfo->{'nparents'}) {
1264 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1265 if ($to->{'href'}) {
1266 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1267 esc_path
($to->{'file'}));
1268 } else { # file was deleted (no href)
1269 $line .= esc_path
($to->{'file'});
1273 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1274 if ($from->{'href'}) {
1275 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1276 'a/' . esc_path
($from->{'file'}));
1277 } else { # file was added (no href)
1278 $line .= 'a/' . esc_path
($from->{'file'});
1281 if ($to->{'href'}) {
1282 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1283 'b/' . esc_path
($to->{'file'}));
1284 } else { # file was deleted
1285 $line .= 'b/' . esc_path
($to->{'file'});
1289 return "<div class=\"diff header\">$line</div>\n";
1292 # format extended diff header line, before patch itself
1293 sub format_extended_diff_header_line
{
1295 my $diffinfo = shift;
1296 my ($from, $to) = @_;
1299 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1300 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1301 esc_path
($from->{'file'}));
1303 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1304 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1305 esc_path
($to->{'file'}));
1307 # match single <mode>
1308 if ($line =~ m/\s(\d{6})$/) {
1309 $line .= '<span class="info"> (' .
1310 file_type_long
($1) .
1314 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1315 # can match only for combined diff
1317 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1318 if ($from->{'href'}[$i]) {
1319 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1321 substr($diffinfo->{'from_id'}[$i],0,7));
1326 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1329 if ($to->{'href'}) {
1330 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1331 substr($diffinfo->{'to_id'},0,7));
1336 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1337 # can match only for ordinary diff
1338 my ($from_link, $to_link);
1339 if ($from->{'href'}) {
1340 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1341 substr($diffinfo->{'from_id'},0,7));
1343 $from_link = '0' x
7;
1345 if ($to->{'href'}) {
1346 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1347 substr($diffinfo->{'to_id'},0,7));
1351 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1352 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1355 return $line . "<br/>\n";
1358 # format from-file/to-file diff header
1359 sub format_diff_from_to_header
{
1360 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1365 #assert($line =~ m/^---/) if DEBUG;
1366 # no extra formatting for "^--- /dev/null"
1367 if (! $diffinfo->{'nparents'}) {
1368 # ordinary (single parent) diff
1369 if ($line =~ m!^--- "?a/!) {
1370 if ($from->{'href'}) {
1372 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1373 esc_path
($from->{'file'}));
1376 esc_path
($from->{'file'});
1379 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1382 # combined diff (merge commit)
1383 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1384 if ($from->{'href'}[$i]) {
1386 $cgi->a({-href
=>href
(action
=>"blobdiff",
1387 hash_parent
=>$diffinfo->{'from_id'}[$i],
1388 hash_parent_base
=>$parents[$i],
1389 file_parent
=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i],
1390 hash
=>$diffinfo->{'to_id'},
1392 file_name
=>$diffinfo->{'to_prefix'}.$to->{'file'}),
1394 -title
=>"diff" . ($i+1)},
1397 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1398 esc_path
($from->{'file'}[$i]));
1400 $line = '--- /dev/null';
1402 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1407 #assert($line =~ m/^\+\+\+/) if DEBUG;
1408 # no extra formatting for "^+++ /dev/null"
1409 if ($line =~ m!^\+\+\+ "?b/!) {
1410 if ($to->{'href'}) {
1412 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1413 esc_path
($to->{'file'}));
1416 esc_path
($to->{'file'});
1419 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1424 # create note for patch simplified by combined diff
1425 sub format_diff_cc_simplified
{
1426 my ($diffinfo, @parents) = @_;
1429 $result .= "<div class=\"diff header\">" .
1431 if (!is_deleted
($diffinfo)) {
1432 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1434 hash
=>$diffinfo->{'to_id'},
1435 file_name
=>$diffinfo->{'to_prefix'}.$diffinfo->{'to_file'}),
1437 esc_path
($diffinfo->{'to_file'}));
1439 $result .= esc_path
($diffinfo->{'to_file'});
1441 $result .= "</div>\n" . # class="diff header"
1442 "<div class=\"diff nodifferences\">" .
1444 "</div>\n"; # class="diff nodifferences"
1449 # format patch (diff) line (not to be used for diff headers)
1450 sub format_diff_line
{
1452 my ($from, $to) = @_;
1453 my $diff_class = "";
1457 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1459 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1460 if ($line =~ m/^\@{3}/) {
1461 $diff_class = " chunk_header";
1462 } elsif ($line =~ m/^\\/) {
1463 $diff_class = " incomplete";
1464 } elsif ($prefix =~ tr/+/+/) {
1465 $diff_class = " add";
1466 } elsif ($prefix =~ tr/-/-/) {
1467 $diff_class = " rem";
1470 # assume ordinary diff
1471 my $char = substr($line, 0, 1);
1473 $diff_class = " add";
1474 } elsif ($char eq '-') {
1475 $diff_class = " rem";
1476 } elsif ($char eq '@') {
1477 $diff_class = " chunk_header";
1478 } elsif ($char eq "\\") {
1479 $diff_class = " incomplete";
1482 $line = untabify
($line);
1483 if ($from && $to && $line =~ m/^\@{2} /) {
1484 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1485 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1487 $from_lines = 0 unless defined $from_lines;
1488 $to_lines = 0 unless defined $to_lines;
1490 if ($from->{'href'}) {
1491 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1492 -class=>"list"}, $from_text);
1494 if ($to->{'href'}) {
1495 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1496 -class=>"list"}, $to_text);
1498 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1499 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1500 return "<div class=\"diff$diff_class\">$line</div>\n";
1501 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1502 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1503 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1505 @from_text = split(' ', $ranges);
1506 for (my $i = 0; $i < @from_text; ++$i) {
1507 ($from_start[$i], $from_nlines[$i]) =
1508 (split(',', substr($from_text[$i], 1)), 0);
1511 $to_text = pop @from_text;
1512 $to_start = pop @from_start;
1513 $to_nlines = pop @from_nlines;
1515 $line = "<span class=\"chunk_info\">$prefix ";
1516 for (my $i = 0; $i < @from_text; ++$i) {
1517 if ($from->{'href'}[$i]) {
1518 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1519 -class=>"list"}, $from_text[$i]);
1521 $line .= $from_text[$i];
1525 if ($to->{'href'}) {
1526 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1527 -class=>"list"}, $to_text);
1531 $line .= " $prefix</span>" .
1532 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1533 return "<div class=\"diff$diff_class\">$line</div>\n";
1535 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1538 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1539 # linked. Pass the hash of the tree/commit to snapshot.
1540 sub format_snapshot_links
{
1542 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1543 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1544 my $num_fmts = @snapshot_fmts;
1545 if ($num_fmts > 1) {
1546 # A parenthesized list of links bearing format names.
1547 # e.g. "snapshot (_tar.gz_ _zip_)"
1548 return "snapshot (" . join(' ', map
1555 }, $known_snapshot_formats{$_}{'display'})
1556 , @snapshot_fmts) . ")";
1557 } elsif ($num_fmts == 1) {
1558 # A single "snapshot" link whose tooltip bears the format name.
1560 my ($fmt) = @snapshot_fmts;
1566 snapshot_format
=>$fmt
1568 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1570 } else { # $num_fmts == 0
1575 ## ......................................................................
1576 ## functions returning values to be passed, perhaps after some
1577 ## transformation, to other functions; e.g. returning arguments to href()
1579 # returns hash to be passed to href to generate gitweb URL
1580 # in -title key it returns description of link
1582 my $format = shift || 'Atom';
1583 my %res = (action
=> lc($format));
1585 # feed links are possible only for project views
1586 return unless (defined $project);
1587 # some views should link to OPML, or to generic project feed,
1588 # or don't have specific feed yet (so they should use generic)
1589 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1592 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1593 # from tag links; this also makes possible to detect branch links
1594 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1595 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1598 # find log type for feed description (title)
1600 if (defined $file_name) {
1601 $type = "history of $file_name";
1602 $type .= "/" if ($action eq 'tree');
1603 $type .= " on '$branch'" if (defined $branch);
1605 $type = "log of $branch" if (defined $branch);
1608 $res{-title
} = $type;
1609 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1610 $res{'file_name'} = $file_name;
1615 ## ----------------------------------------------------------------------
1616 ## git utility subroutines, invoking git commands
1618 # returns path to the core git executable and the --git-dir parameter as list
1620 return $GIT, '--git-dir='.$git_dir;
1623 # quote the given arguments for passing them to the shell
1624 # quote_command("command", "arg 1", "arg with ' and ! characters")
1625 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1626 # Try to avoid using this function wherever possible.
1629 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1632 # get HEAD ref of given project as hash
1633 sub git_get_head_hash
{
1634 my $project = shift;
1635 my $o_git_dir = $git_dir;
1637 $git_dir = "$projectroot/$project";
1638 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1641 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1645 if (defined $o_git_dir) {
1646 $git_dir = $o_git_dir;
1651 # get type of given object
1655 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1657 close $fd or return;
1662 # repository configuration
1663 our $config_file = '';
1666 # store multiple values for single key as anonymous array reference
1667 # single values stored directly in the hash, not as [ <value> ]
1668 sub hash_set_multi
{
1669 my ($hash, $key, $value) = @_;
1671 if (!exists $hash->{$key}) {
1672 $hash->{$key} = $value;
1673 } elsif (!ref $hash->{$key}) {
1674 $hash->{$key} = [ $hash->{$key}, $value ];
1676 push @
{$hash->{$key}}, $value;
1680 # return hash of git project configuration
1681 # optionally limited to some section, e.g. 'gitweb'
1682 sub git_parse_project_config
{
1683 my $section_regexp = shift;
1688 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1691 while (my $keyval = <$fh>) {
1693 my ($key, $value) = split(/\n/, $keyval, 2);
1695 hash_set_multi
(\
%config, $key, $value)
1696 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1703 # convert config value to boolean, 'true' or 'false'
1704 # no value, number > 0, 'true' and 'yes' values are true
1705 # rest of values are treated as false (never as error)
1706 sub config_to_bool
{
1709 # strip leading and trailing whitespace
1713 return (!defined $val || # section.key
1714 ($val =~ /^\d+$/ && $val) || # section.key = 1
1715 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1718 # convert config value to simple decimal number
1719 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1720 # to be multiplied by 1024, 1048576, or 1073741824
1724 # strip leading and trailing whitespace
1728 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1730 # unknown unit is treated as 1
1731 return $num * ($unit eq 'g' ?
1073741824 :
1732 $unit eq 'm' ?
1048576 :
1733 $unit eq 'k' ?
1024 : 1);
1738 # convert config value to array reference, if needed
1739 sub config_to_multi
{
1742 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1745 sub git_get_project_config
{
1746 my ($key, $type) = @_;
1749 return unless ($key);
1750 $key =~ s/^gitweb\.//;
1751 return if ($key =~ m/\W/);
1754 if (defined $type) {
1757 unless ($type eq 'bool' || $type eq 'int');
1761 if (!defined $config_file ||
1762 $config_file ne "$git_dir/config") {
1763 %config = git_parse_project_config
('gitweb');
1764 $config_file = "$git_dir/config";
1768 if (!defined $type) {
1769 return $config{"gitweb.$key"};
1770 } elsif ($type eq 'bool') {
1771 # backward compatibility: 'git config --bool' returns true/false
1772 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1773 } elsif ($type eq 'int') {
1774 return config_to_int
($config{"gitweb.$key"});
1776 return $config{"gitweb.$key"};
1779 # get hash of given path at given ref
1780 sub git_get_hash_by_path
{
1782 my $path = shift || return undef;
1787 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1788 or die_error
(500, "Open git-ls-tree failed");
1790 close $fd or return undef;
1792 if (!defined $line) {
1793 # there is no tree or hash given by $path at $base
1797 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1798 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1799 if (defined $type && $type ne $2) {
1800 # type doesn't match
1806 # get path of entry with given hash at given tree-ish (ref)
1807 # used to get 'from' filename for combined diff (merge commit) for renames
1808 sub git_get_path_by_hash
{
1809 my $base = shift || return;
1810 my $hash = shift || return;
1814 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1816 while (my $line = <$fd>) {
1819 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1820 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1821 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1830 ## ......................................................................
1831 ## git utility functions, directly accessing git repository
1833 sub git_get_project_description
{
1836 $git_dir = "$projectroot/$path";
1837 open my $fd, "$git_dir/description"
1838 or return git_get_project_config
('description');
1841 if (defined $descr) {
1847 sub git_get_project_ctags
{
1851 $git_dir = "$projectroot/$path";
1852 foreach (<$git_dir/ctags/*>) {
1853 open CT
, $_ or next;
1857 my $ctag = $_; $ctag =~ s
#.*/##;
1858 $ctags->{$ctag} = $val;
1863 sub git_populate_project_tagcloud
{
1866 # First, merge different-cased tags; tags vote on casing
1868 foreach (keys %$ctags) {
1869 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
1870 if (not $ctags_lc{lc $_}->{topcount
}
1871 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
1872 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
1873 $ctags_lc{lc $_}->{topname
} = $_;
1878 if (eval { require HTML
::TagCloud
; 1; }) {
1879 $cloud = HTML
::TagCloud
->new;
1880 foreach (sort keys %ctags_lc) {
1881 # Pad the title with spaces so that the cloud looks
1883 my $title = $ctags_lc{$_}->{topname
};
1884 $title =~ s/ / /g;
1885 $title =~ s/^/ /g;
1886 $title =~ s/$/ /g;
1887 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
1890 $cloud = \
%ctags_lc;
1895 sub git_show_project_tagcloud
{
1896 my ($cloud, $count) = @_;
1897 print STDERR
ref($cloud)."..\n";
1898 if (ref $cloud eq 'HTML::TagCloud') {
1899 return $cloud->html_and_css($count);
1901 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
1902 return '<p align="center">' . join (', ', map {
1903 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
1904 } splice(@tags, 0, $count)) . '</p>';
1908 sub git_get_project_url_list
{
1911 $git_dir = "$projectroot/$path";
1912 open my $fd, "$git_dir/cloneurl"
1913 or return wantarray ?
1914 @
{ config_to_multi
(git_get_project_config
('url')) } :
1915 config_to_multi
(git_get_project_config
('url'));
1916 my @git_project_url_list = map { chomp; $_ } <$fd>;
1919 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1922 sub git_get_projects_list
{
1927 $filter =~ s/\.git$//;
1929 my ($check_forks) = gitweb_check_feature
('forks');
1931 if (-d
$projects_list) {
1932 # search in directory
1933 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1934 # remove the trailing "/"
1936 my $pfxlen = length("$dir");
1937 my $pfxdepth = ($dir =~ tr!/!!);
1940 follow_fast
=> 1, # follow symbolic links
1941 follow_skip
=> 2, # ignore duplicates
1942 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1944 # skip project-list toplevel, if we get it.
1945 return if (m!^[/.]$!);
1946 # only directories can be git repositories
1947 return unless (-d
$_);
1948 # don't traverse too deep (Find is super slow on os x)
1949 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1950 $File::Find
::prune
= 1;
1954 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1955 # we check related file in $projectroot
1956 if (check_export_ok
("$projectroot/$filter/$subdir")) {
1957 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1958 $File::Find
::prune
= 1;
1963 } elsif (-f
$projects_list) {
1964 # read from file(url-encoded):
1965 # 'git%2Fgit.git Linus+Torvalds'
1966 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1967 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1969 open my ($fd), $projects_list or return;
1971 while (my $line = <$fd>) {
1973 my ($path, $owner) = split ' ', $line;
1974 $path = unescape
($path);
1975 $owner = unescape
($owner);
1976 if (!defined $path) {
1979 if ($filter ne '') {
1980 # looking for forks;
1981 my $pfx = substr($path, 0, length($filter));
1982 if ($pfx ne $filter) {
1985 my $sfx = substr($path, length($filter));
1986 if ($sfx !~ /^\/.*\
.git
$/) {
1989 } elsif ($check_forks) {
1991 foreach my $filter (keys %paths) {
1992 # looking for forks;
1993 my $pfx = substr($path, 0, length($filter));
1994 if ($pfx ne $filter) {
1997 my $sfx = substr($path, length($filter));
1998 if ($sfx !~ /^\/.*\
.git
$/) {
2001 # is a fork, don't include it in
2006 if (check_export_ok
("$projectroot/$path")) {
2009 owner
=> to_utf8
($owner),
2012 (my $forks_path = $path) =~ s/\.git$//;
2013 $paths{$forks_path}++;
2021 our $gitweb_project_owner = undef;
2022 sub git_get_project_list_from_file
{
2024 return if (defined $gitweb_project_owner);
2026 $gitweb_project_owner = {};
2027 # read from file (url-encoded):
2028 # 'git%2Fgit.git Linus+Torvalds'
2029 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2030 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2031 if (-f
$projects_list) {
2032 open (my $fd , $projects_list);
2033 while (my $line = <$fd>) {
2035 my ($pr, $ow) = split ' ', $line;
2036 $pr = unescape
($pr);
2037 $ow = unescape
($ow);
2038 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2044 sub git_get_project_owner
{
2045 my $project = shift;
2048 return undef unless $project;
2049 $git_dir = "$projectroot/$project";
2051 if (!defined $gitweb_project_owner) {
2052 git_get_project_list_from_file
();
2055 if (exists $gitweb_project_owner->{$project}) {
2056 $owner = $gitweb_project_owner->{$project};
2058 if (!defined $owner){
2059 $owner = git_get_project_config
('owner');
2061 if (!defined $owner) {
2062 $owner = get_file_owner
("$git_dir");
2068 sub git_get_last_activity
{
2072 $git_dir = "$projectroot/$path";
2073 open($fd, "-|", git_cmd
(), 'for-each-ref',
2074 '--format=%(committer)',
2075 '--sort=-committerdate',
2077 'refs/heads') or return;
2078 my $most_recent = <$fd>;
2079 close $fd or return;
2080 if (defined $most_recent &&
2081 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2083 my $age = time - $timestamp;
2084 return ($age, age_string
($age));
2086 return (undef, undef);
2089 sub git_get_references
{
2090 my $type = shift || "";
2092 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2093 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2094 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2095 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2098 while (my $line = <$fd>) {
2100 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2101 if (defined $refs{$1}) {
2102 push @
{$refs{$1}}, $2;
2108 close $fd or return;
2112 sub git_get_rev_name_tags
{
2113 my $hash = shift || return undef;
2115 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2117 my $name_rev = <$fd>;
2120 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2123 # catches also '$hash undefined' output
2128 ## ----------------------------------------------------------------------
2129 ## parse to hash functions
2133 my $tz = shift || "-0000";
2136 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2137 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2138 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2139 $date{'hour'} = $hour;
2140 $date{'minute'} = $min;
2141 $date{'mday'} = $mday;
2142 $date{'day'} = $days[$wday];
2143 $date{'month'} = $months[$mon];
2144 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2145 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2146 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2147 $mday, $months[$mon], $hour ,$min;
2148 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2149 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2151 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2152 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2153 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2154 $date{'hour_local'} = $hour;
2155 $date{'minute_local'} = $min;
2156 $date{'tz_local'} = $tz;
2157 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2158 1900+$year, $mon+1, $mday,
2159 $hour, $min, $sec, $tz);
2168 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2169 $tag{'id'} = $tag_id;
2170 while (my $line = <$fd>) {
2172 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2173 $tag{'object'} = $1;
2174 } elsif ($line =~ m/^type (.+)$/) {
2176 } elsif ($line =~ m/^tag (.+)$/) {
2178 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2179 $tag{'author'} = $1;
2182 } elsif ($line =~ m/--BEGIN/) {
2183 push @comment, $line;
2185 } elsif ($line eq "") {
2189 push @comment, <$fd>;
2190 $tag{'comment'} = \
@comment;
2191 close $fd or return;
2192 if (!defined $tag{'name'}) {
2198 sub parse_commit_text
{
2199 my ($commit_text, $withparents) = @_;
2200 my @commit_lines = split '\n', $commit_text;
2203 pop @commit_lines; # Remove '\0'
2205 if (! @commit_lines) {
2209 my $header = shift @commit_lines;
2210 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2213 ($co{'id'}, my @parents) = split ' ', $header;
2214 while (my $line = shift @commit_lines) {
2215 last if $line eq "\n";
2216 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2218 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2220 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2222 $co{'author_epoch'} = $2;
2223 $co{'author_tz'} = $3;
2224 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2225 $co{'author_name'} = $1;
2226 $co{'author_email'} = $2;
2228 $co{'author_name'} = $co{'author'};
2230 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2231 $co{'committer'} = $1;
2232 $co{'committer_epoch'} = $2;
2233 $co{'committer_tz'} = $3;
2234 $co{'committer_name'} = $co{'committer'};
2235 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2236 $co{'committer_name'} = $1;
2237 $co{'committer_email'} = $2;
2239 $co{'committer_name'} = $co{'committer'};
2243 if (!defined $co{'tree'}) {
2246 $co{'parents'} = \
@parents;
2247 $co{'parent'} = $parents[0];
2249 foreach my $title (@commit_lines) {
2252 $co{'title'} = chop_str
($title, 80, 5);
2253 # remove leading stuff of merges to make the interesting part visible
2254 if (length($title) > 50) {
2255 $title =~ s/^Automatic //;
2256 $title =~ s/^merge (of|with) /Merge ... /i;
2257 if (length($title) > 50) {
2258 $title =~ s/(http|rsync):\/\///;
2260 if (length($title) > 50) {
2261 $title =~ s/(master|www|rsync)\.//;
2263 if (length($title) > 50) {
2264 $title =~ s/kernel.org:?//;
2266 if (length($title) > 50) {
2267 $title =~ s/\/pub\/scm//;
2270 $co{'title_short'} = chop_str
($title, 50, 5);
2274 if (! defined $co{'title'} || $co{'title'} eq "") {
2275 $co{'title'} = $co{'title_short'} = '(no commit message)';
2277 # remove added spaces
2278 foreach my $line (@commit_lines) {
2281 $co{'comment'} = \
@commit_lines;
2283 my $age = time - $co{'committer_epoch'};
2285 $co{'age_string'} = age_string
($age);
2286 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2287 if ($age > 60*60*24*7*2) {
2288 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2289 $co{'age_string_age'} = $co{'age_string'};
2291 $co{'age_string_date'} = $co{'age_string'};
2292 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2298 my ($commit_id) = @_;
2303 open my $fd, "-|", git_cmd
(), "rev-list",
2309 or die_error
(500, "Open git-rev-list failed");
2310 %co = parse_commit_text
(<$fd>, 1);
2317 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2325 open my $fd, "-|", git_cmd
(), "rev-list",
2328 ("--max-count=" . $maxcount),
2329 ("--skip=" . $skip),
2333 ($filename ?
($filename) : ())
2334 or die_error
(500, "Open git-rev-list failed");
2335 while (my $line = <$fd>) {
2336 my %co = parse_commit_text
($line);
2341 return wantarray ?
@cos : \
@cos;
2344 # parse line of git-diff-tree "raw" output
2345 sub parse_difftree_raw_line
{
2349 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2350 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2351 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2352 $res{'from_mode'} = $1;
2353 $res{'to_mode'} = $2;
2354 $res{'from_id'} = $3;
2356 $res{'status'} = $5;
2357 $res{'similarity'} = $6;
2358 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2359 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2361 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2364 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2365 # combined diff (for merge commit)
2366 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2367 $res{'nparents'} = length($1);
2368 $res{'from_mode'} = [ split(' ', $2) ];
2369 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2370 $res{'from_id'} = [ split(' ', $3) ];
2371 $res{'to_id'} = pop @
{$res{'from_id'}};
2372 $res{'status'} = [ split('', $4) ];
2373 $res{'to_file'} = unquote
($5);
2375 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2376 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2377 $res{'commit'} = $1;
2380 return wantarray ?
%res : \
%res;
2383 # wrapper: return parsed line of git-diff-tree "raw" output
2384 # (the argument might be raw line, or parsed info)
2385 sub parsed_difftree_line
{
2386 my $line_or_ref = shift;
2388 if (ref($line_or_ref) eq "HASH") {
2389 # pre-parsed (or generated by hand)
2390 return $line_or_ref;
2392 return parse_difftree_raw_line
($line_or_ref);
2396 # parse line of git-ls-tree output
2397 sub parse_ls_tree_line
($;%) {
2402 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2403 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2411 $res{'name'} = unquote
($4);
2414 return wantarray ?
%res : \
%res;
2417 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2418 sub parse_from_to_diffinfo
{
2419 my ($diffinfo, $from, $to, @parents) = @_;
2421 if ($diffinfo->{'nparents'}) {
2423 $from->{'file'} = [];
2424 $from->{'href'} = [];
2425 fill_from_file_info
($diffinfo, @parents)
2426 unless exists $diffinfo->{'from_file'};
2427 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2428 $from->{'file'}[$i] =
2429 defined $diffinfo->{'from_file'}[$i] ?
2430 $diffinfo->{'from_file'}[$i] :
2431 $diffinfo->{'to_file'};
2432 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2433 $from->{'href'}[$i] = href
(action
=>"blob",
2434 hash_base
=>$parents[$i],
2435 hash
=>$diffinfo->{'from_id'}[$i],
2436 file_name
=>$diffinfo->{'from_prefix'}.$from->{'file'}[$i]);
2438 $from->{'href'}[$i] = undef;
2442 # ordinary (not combined) diff
2443 $from->{'file'} = $diffinfo->{'from_file'};
2444 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2445 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2446 hash
=>$diffinfo->{'from_id'},
2447 file_name
=>$diffinfo->{'from_prefix'}.$from->{'file'});
2449 delete $from->{'href'};
2453 $to->{'file'} = $diffinfo->{'to_file'};
2454 if (!is_deleted
($diffinfo)) { # file exists in result
2455 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2456 hash
=>$diffinfo->{'to_id'},
2457 file_name
=>$diffinfo->{'to_prefix'}.$to->{'file'});
2459 delete $to->{'href'};
2463 ## ......................................................................
2464 ## parse to array of hashes functions
2466 sub git_get_heads_list
{
2470 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2471 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2472 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2475 while (my $line = <$fd>) {
2479 my ($refinfo, $committerinfo) = split(/\0/, $line);
2480 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2481 my ($committer, $epoch, $tz) =
2482 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2483 $ref_item{'fullname'} = $name;
2484 $name =~ s!^refs/heads/!!;
2486 $ref_item{'name'} = $name;
2487 $ref_item{'id'} = $hash;
2488 $ref_item{'title'} = $title || '(no commit message)';
2489 $ref_item{'epoch'} = $epoch;
2491 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2493 $ref_item{'age'} = "unknown";
2496 push @headslist, \
%ref_item;
2500 return wantarray ?
@headslist : \
@headslist;
2503 sub git_get_tags_list
{
2507 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2508 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2509 '--format=%(objectname) %(objecttype) %(refname) '.
2510 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2513 while (my $line = <$fd>) {
2517 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2518 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2519 my ($creator, $epoch, $tz) =
2520 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2521 $ref_item{'fullname'} = $name;
2522 $name =~ s!^refs/tags/!!;
2524 $ref_item{'type'} = $type;
2525 $ref_item{'id'} = $id;
2526 $ref_item{'name'} = $name;
2527 if ($type eq "tag") {
2528 $ref_item{'subject'} = $title;
2529 $ref_item{'reftype'} = $reftype;
2530 $ref_item{'refid'} = $refid;
2532 $ref_item{'reftype'} = $type;
2533 $ref_item{'refid'} = $id;
2536 if ($type eq "tag" || $type eq "commit") {
2537 $ref_item{'epoch'} = $epoch;
2539 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2541 $ref_item{'age'} = "unknown";
2545 push @tagslist, \
%ref_item;
2549 return wantarray ?
@tagslist : \
@tagslist;
2552 ## ----------------------------------------------------------------------
2553 ## filesystem-related functions
2555 sub get_file_owner
{
2558 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2559 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2560 if (!defined $gcos) {
2564 $owner =~ s/[,;].*$//;
2565 return to_utf8
($owner);
2568 ## ......................................................................
2569 ## mimetype related functions
2571 sub mimetype_guess_file
{
2572 my $filename = shift;
2573 my $mimemap = shift;
2574 -r
$mimemap or return undef;
2577 open(MIME
, $mimemap) or return undef;
2579 next if m/^#/; # skip comments
2580 my ($mime, $exts) = split(/\t+/);
2581 if (defined $exts) {
2582 my @exts = split(/\s+/, $exts);
2583 foreach my $ext (@exts) {
2584 $mimemap{$ext} = $mime;
2590 $filename =~ /\.([^.]*)$/;
2591 return $mimemap{$1};
2594 sub mimetype_guess
{
2595 my $filename = shift;
2597 $filename =~ /\./ or return undef;
2599 if ($mimetypes_file) {
2600 my $file = $mimetypes_file;
2601 if ($file !~ m!^/!) { # if it is relative path
2602 # it is relative to project
2603 $file = "$projectroot/$project/$file";
2605 $mime = mimetype_guess_file
($filename, $file);
2607 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2613 my $filename = shift;
2616 my $mime = mimetype_guess
($filename);
2617 $mime and return $mime;
2621 return $default_blob_plain_mimetype unless $fd;
2624 return 'text/plain';
2625 } elsif (! $filename) {
2626 return 'application/octet-stream';
2627 } elsif ($filename =~ m/\.png$/i) {
2629 } elsif ($filename =~ m/\.gif$/i) {
2631 } elsif ($filename =~ m/\.jpe?g$/i) {
2632 return 'image/jpeg';
2634 return 'application/octet-stream';
2638 sub blob_contenttype
{
2639 my ($fd, $file_name, $type) = @_;
2641 $type ||= blob_mimetype
($fd, $file_name);
2642 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2643 $type .= "; charset=$default_text_plain_charset";
2649 ## ======================================================================
2650 ## functions printing HTML: header, footer, error page
2652 sub git_header_html
{
2653 my $status = shift || "200 OK";
2654 my $expires = shift;
2656 my $title = "$site_name";
2657 if (defined $project) {
2658 $title .= " - " . to_utf8
($project);
2659 if (defined $action) {
2660 $title .= "/$action";
2661 if (defined $file_name) {
2662 $title .= " - " . esc_path
($file_name);
2663 if ($action eq "tree" && $file_name !~ m
|/$|) {
2669 # We do not ever emit application/xhtml+xml since that gives us
2670 # no benefits and it makes many browsers (e.g. Firefox) exceedingly
2671 # strict, which is troublesome for example when showing user-supplied
2672 # README.html files.
2673 my $content_type = 'text/html';
2674 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2675 -status
=> $status, -expires
=> $expires);
2676 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2678 <?xml version="1.0" encoding="utf-8"?>
2679 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2680 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2681 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2682 <!-- git core binaries version $git_version -->
2684 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2685 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2686 <meta name="robots" content="index, nofollow"/>
2687 <title>$title</title>
2688 <script type="text/javascript">/* <![CDATA[ */
2689 function fixBlameLinks() {
2690 var allLinks = document.getElementsByTagName("a");
2691 for (var i = 0; i < allLinks.length; i++) {
2692 var link = allLinks.item(i);
2693 if (link.className == 'blamelink')
2694 link.href = link.href.replace("a=blame", "a=blame_incremental");
2699 # print out each stylesheet that exist
2700 if (defined $stylesheet) {
2701 #provides backwards capability for those people who define style sheet in a config file
2702 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2704 foreach my $stylesheet (@stylesheets) {
2705 next unless $stylesheet;
2706 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2709 if (defined $project) {
2710 my %href_params = get_feed_info
();
2711 if (!exists $href_params{'-title'}) {
2712 $href_params{'-title'} = 'log';
2715 foreach my $format qw(RSS Atom) {
2716 my $type = lc($format);
2718 '-rel' => 'alternate',
2719 '-title' => "$project - $href_params{'-title'} - $format feed",
2720 '-type' => "application/$type+xml"
2723 $href_params{'action'} = $type;
2724 $link_attr{'-href'} = href
(%href_params);
2726 "rel=\"$link_attr{'-rel'}\" ".
2727 "title=\"$link_attr{'-title'}\" ".
2728 "href=\"$link_attr{'-href'}\" ".
2729 "type=\"$link_attr{'-type'}\" ".
2732 $href_params{'extra_options'} = '--no-merges';
2733 $link_attr{'-href'} = href
(%href_params);
2734 $link_attr{'-title'} .= ' (no merges)';
2736 "rel=\"$link_attr{'-rel'}\" ".
2737 "title=\"$link_attr{'-title'}\" ".
2738 "href=\"$link_attr{'-href'}\" ".
2739 "type=\"$link_attr{'-type'}\" ".
2744 printf('<link rel="alternate" title="%s projects list" '.
2745 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2746 $site_name, href
(project
=>undef, action
=>"project_index"));
2747 printf('<link rel="alternate" title="%s projects feeds" '.
2748 'href="%s" type="text/x-opml" />'."\n",
2749 $site_name, href
(project
=>undef, action
=>"opml"));
2751 if (defined $favicon) {
2752 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2755 if (defined $gitwebjs) {
2756 print qq(<script src
="$gitwebjs" type
="text/javascript"></script
>\n);
2760 "<body onload=\"GitAddLinks(); fixBlameLinks();\">\n";
2762 if (-f
$site_header) {
2763 open (my $fd, $site_header);
2768 print "<div class=\"page_header\">\n" .
2769 $cgi->a({-href
=> esc_url
($logo_url),
2770 -title
=> $logo_label},
2771 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2772 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2773 if (defined $project) {
2774 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2775 if (defined $action) {
2782 my ($have_search) = gitweb_check_feature
('search');
2783 if (defined $project && $have_search) {
2784 if (!defined $searchtext) {
2788 if (defined $hash_base) {
2789 $search_hash = $hash_base;
2790 } elsif (defined $hash) {
2791 $search_hash = $hash;
2793 $search_hash = "HEAD";
2795 my $action = $my_uri;
2796 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2797 if ($use_pathinfo) {
2798 $action .= "/".esc_url
($project);
2800 print $cgi->startform(-method
=> "get", -action
=> $action) .
2801 "<div class=\"search\">\n" .
2803 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2804 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2805 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2806 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2807 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2808 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2810 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2811 "<span title=\"Extended regular expression\">" .
2812 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2813 -checked
=> $search_use_regexp) .
2816 $cgi->end_form() . "\n";
2820 sub git_footer_html
{
2821 my $feed_class = 'rss_logo';
2823 print "<div class=\"page_footer\">\n";
2824 if (defined $project) {
2825 my $descr = git_get_project_description
($project);
2826 if (defined $descr) {
2827 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2830 my %href_params = get_feed_info
();
2831 if (!%href_params) {
2832 $feed_class .= ' generic';
2834 $href_params{'-title'} ||= 'log';
2836 foreach my $format qw(RSS Atom) {
2837 $href_params{'action'} = lc($format);
2838 print $cgi->a({-href
=> href
(%href_params),
2839 -title
=> "$href_params{'-title'} $format feed",
2840 -class => $feed_class}, $format)."\n";
2844 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2845 -class => $feed_class}, "OPML") . " ";
2846 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2847 -class => $feed_class}, "TXT") . "\n";
2849 print "</div>\n"; # class="page_footer"
2851 if (-f
$site_footer) {
2852 open (my $fd, $site_footer);
2861 # die_error(<http_status_code>, <error_message>)
2862 # Example: die_error(404, 'Hash not found')
2863 # By convention, use the following status codes (as defined in RFC 2616):
2864 # 400: Invalid or missing CGI parameters, or
2865 # requested object exists but has wrong type.
2866 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2867 # this server or project.
2868 # 404: Requested object/revision/project doesn't exist.
2869 # 500: The server isn't configured properly, or
2870 # an internal error occurred (e.g. failed assertions caused by bugs), or
2871 # an unknown error occurred (e.g. the git binary died unexpectedly).
2873 my $status = shift || 500;
2874 my $error = shift || "Internal server error";
2876 my %http_responses = (400 => '400 Bad Request',
2877 403 => '403 Forbidden',
2878 404 => '404 Not Found',
2879 500 => '500 Internal Server Error');
2880 git_header_html
($http_responses{$status});
2882 <div class="page_body">
2892 ## ----------------------------------------------------------------------
2893 ## functions printing or outputting HTML: navigation
2895 sub git_print_page_nav
{
2896 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2897 $extra = '' if !defined $extra; # pager or formats
2899 my @navs = qw(summary log commit commitdiff tree);
2901 @navs = grep { $_ ne $suppress } @navs;
2904 my %arg = map { $_ => {action
=>$_} } @navs;
2905 if (defined $head) {
2906 for (qw(commit commitdiff)) {
2907 $arg{$_}{'hash'} = $head;
2909 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2910 $arg{'log'}{'hash'} = $head;
2914 $arg{'log'}{'action'} = 'shortlog';
2915 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2916 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2918 my @actions = gitweb_check_feature
('actions');
2920 my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2921 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
2923 $link =~ s
#%n#$project#g;
2924 $link =~ s
#%f#$git_dir#g;
2925 $treehead ?
$link =~ s
#%h#$treehead#g : $link =~ s#%h##g;
2926 $treebase ?
$link =~ s
#%b#$treebase#g : $link =~ s#%b##g;
2927 $arg{$label}{'_href'} = $link;
2930 print "<div class=\"page_nav\">\n" .
2932 map { $_ eq $current ?
2933 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
2935 print "<br/>\n$extra<br/>\n" .
2939 sub format_paging_nav
{
2940 my ($action, $hash, $head, $page, $has_next_link) = @_;
2944 if ($hash ne $head || $page) {
2945 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2947 $paging_nav .= "HEAD";
2951 $paging_nav .= " ⋅ " .
2952 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2953 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2955 $paging_nav .= " ⋅ prev";
2958 if ($has_next_link) {
2959 $paging_nav .= " ⋅ " .
2960 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2961 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2963 $paging_nav .= " ⋅ next";
2969 sub format_log_nav
{
2970 my ($action, $hash, $head, $page, $has_next_link) = @_;
2973 if ($action eq 'shortlog') {
2974 $paging_nav .= 'shortlog';
2976 $paging_nav .= $cgi->a({-href
=> href
(action
=>'shortlog', -replay
=>1)}, 'shortlog');
2978 $paging_nav .= ' | ';
2979 if ($action eq 'log') {
2980 $paging_nav .= 'fulllog';
2982 $paging_nav .= $cgi->a({-href
=> href
(action
=>'log', -replay
=>1)}, 'fulllog');
2985 $paging_nav .= " | " . format_paging_nav
($action, $hash, $head, $page, $has_next_link);
2989 ## ......................................................................
2990 ## functions printing or outputting HTML: div
2992 sub git_print_header_div
{
2993 my ($action, $title, $hash, $hash_base) = @_;
2996 $args{'action'} = $action;
2997 $args{'hash'} = $hash if $hash;
2998 $args{'hash_base'} = $hash_base if $hash_base;
3000 print "<div class=\"header\">\n" .
3001 $cgi->a({-href
=> href
(%args), -class => "title"},
3002 $title ?
$title : $action) .
3006 #sub git_print_authorship (\%) {
3007 sub git_print_authorship
{
3010 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3011 print "<div class=\"author_date\">" .
3012 esc_html
($co->{'author_name'}) .
3014 if ($ad{'hour_local'} < 6) {
3015 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3016 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3018 printf(" (%02d:%02d %s)",
3019 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3024 sub git_print_page_path
{
3030 print "<div class=\"page_path\">";
3031 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3032 -title
=> 'tree root'}, to_utf8
("[$project]"));
3034 if (defined $name) {
3035 my @dirname = split '/', $name;
3036 my $basename = pop @dirname;
3039 foreach my $dir (@dirname) {
3040 $fullname .= ($fullname ?
'/' : '') . $dir;
3041 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3043 -title
=> $fullname}, esc_path
($dir));
3046 if (defined $type && $type eq 'blob') {
3047 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3049 -title
=> $name}, esc_path
($basename));
3050 } elsif (defined $type && $type eq 'tree') {
3051 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3053 -title
=> $name}, esc_path
($basename));
3056 print esc_path
($basename);
3059 print "<br/></div>\n";
3062 # sub git_print_log (\@;%) {
3063 sub git_print_log
($;%) {
3067 if ($opts{'-remove_title'}) {
3068 # remove title, i.e. first line of log
3071 # remove leading empty lines
3072 while (defined $log->[0] && $log->[0] eq "") {
3079 foreach my $line (@
$log) {
3080 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3083 if (! $opts{'-remove_signoff'}) {
3084 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3087 # remove signoff lines
3094 # print only one empty line
3095 # do not print empty line after signoff
3097 next if ($empty || $signoff);
3103 print format_log_line_html
($line) . "<br/>\n";
3106 if ($opts{'-final_empty_line'}) {
3107 # end with single empty line
3108 print "<br/>\n" unless $empty;
3112 # return link target (what link points to)
3113 sub git_get_link_target
{
3118 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3122 $link_target = <$fd>;
3127 return $link_target;
3130 # given link target, and the directory (basedir) the link is in,
3131 # return target of link relative to top directory (top tree);
3132 # return undef if it is not possible (including absolute links).
3133 sub normalize_link_target
{
3134 my ($link_target, $basedir, $hash_base) = @_;
3136 # we can normalize symlink target only if $hash_base is provided
3137 return unless $hash_base;
3139 # absolute symlinks (beginning with '/') cannot be normalized
3140 return if (substr($link_target, 0, 1) eq '/');
3142 # normalize link target to path from top (root) tree (dir)
3145 $path = $basedir . '/' . $link_target;
3147 # we are in top (root) tree (dir)
3148 $path = $link_target;
3151 # remove //, /./, and /../
3153 foreach my $part (split('/', $path)) {
3154 # discard '.' and ''
3155 next if (!$part || $part eq '.');
3157 if ($part eq '..') {
3161 # link leads outside repository (outside top dir)
3165 push @path_parts, $part;
3168 $path = join('/', @path_parts);
3173 # print tree entry (row of git_tree), but without encompassing <tr> element
3174 sub git_print_tree_entry
{
3175 my ($t, $basedir, $hash_base, $have_blame) = @_;
3178 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3180 # The format of a table row is: mode list link. Where mode is
3181 # the mode of the entry, list is the name of the entry, an href,
3182 # and link is the action links of the entry.
3184 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3185 if ($t->{'type'} eq "blob") {
3186 print "<td class=\"list\">" .
3187 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3188 file_name
=>"$basedir$t->{'name'}", %base_key),
3189 -class => "list"}, esc_path
($t->{'name'}));
3190 if (S_ISLNK
(oct $t->{'mode'})) {
3191 my $link_target = git_get_link_target
($t->{'hash'});
3193 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3194 if (defined $norm_target) {
3196 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3197 file_name
=>$norm_target),
3198 -title
=> $norm_target}, esc_path
($link_target));
3200 print " -> " . esc_path
($link_target);
3205 print "<td class=\"link\">";
3206 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3207 file_name
=>"$basedir$t->{'name'}", %base_key)},
3211 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3212 file_name
=>"$basedir$t->{'name'}", %base_key), -class => "blamelink"},
3215 if (defined $hash_base) {
3217 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3218 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3222 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3223 file_name
=>"$basedir$t->{'name'}")},
3227 } elsif ($t->{'type'} eq "tree") {
3228 print "<td class=\"list\">";
3229 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3230 file_name
=>"$basedir$t->{'name'}", %base_key)},
3231 esc_path
($t->{'name'}));
3233 print "<td class=\"link\">";
3234 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3235 file_name
=>"$basedir$t->{'name'}", %base_key)},
3237 if (defined $hash_base) {
3239 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3240 file_name
=>"$basedir$t->{'name'}")},
3245 # unknown object: we can only present history for it
3246 # (this includes 'commit' object, i.e. submodule support)
3247 print "<td class=\"list\">" .
3248 esc_path
($t->{'name'}) .
3250 print "<td class=\"link\">";
3251 if (defined $hash_base) {
3252 print $cgi->a({-href
=> href
(action
=>"history",
3253 hash_base
=>$hash_base,
3254 file_name
=>"$basedir$t->{'name'}")},
3261 ## ......................................................................
3262 ## functions printing large fragments of HTML
3264 # get pre-image filenames for merge (combined) diff
3265 sub fill_from_file_info
{
3266 my ($diff, @parents) = @_;
3268 $diff->{'from_file'} = [ ];
3269 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3270 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3271 if ($diff->{'status'}[$i] eq 'R' ||
3272 $diff->{'status'}[$i] eq 'C') {
3273 $diff->{'from_file'}[$i] =
3274 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3281 # is current raw difftree line of file deletion
3283 my $diffinfo = shift;
3285 return $diffinfo->{'to_id'} eq ('0' x
40);
3288 # does patch correspond to [previous] difftree raw line
3289 # $diffinfo - hashref of parsed raw diff format
3290 # $patchinfo - hashref of parsed patch diff format
3291 # (the same keys as in $diffinfo)
3292 sub is_patch_split
{
3293 my ($diffinfo, $patchinfo) = @_;
3295 return defined $diffinfo && defined $patchinfo
3296 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3300 sub git_difftree_body
{
3301 my ($difftree, $from_prefix, $to_prefix, $hash, @parents) = @_;
3302 my ($parent) = $parents[0];
3303 my ($have_blame) = gitweb_check_feature
('blame');
3305 $from_prefix = !defined $from_prefix ?
'' : $from_prefix.'/';
3306 $to_prefix = !defined $to_prefix ?
'' : $to_prefix . '/';
3308 print "<div class=\"list_head\">\n";
3309 if ($#{$difftree} > 10) {
3310 print(($#{$difftree} + 1) . " files changed:\n");
3314 print "<table class=\"" .
3315 (@parents > 1 ?
"combined " : "") .
3318 # header only for combined diff in 'commitdiff' view
3319 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3322 print "<thead><tr>\n" .
3323 "<th></th><th></th>\n"; # filename, patchN link
3324 for (my $i = 0; $i < @parents; $i++) {
3325 my $par = $parents[$i];
3327 $cgi->a({-href
=> href
(action
=>"commitdiff",
3328 hash
=>$hash, hash_parent
=>$par),
3329 -title
=> 'commitdiff to parent number ' .
3330 ($i+1) . ': ' . substr($par,0,7)},
3334 print "</tr></thead>\n<tbody>\n";
3339 foreach my $line (@
{$difftree}) {
3340 my $diff = parsed_difftree_line
($line);
3343 print "<tr class=\"dark\">\n";
3345 print "<tr class=\"light\">\n";
3349 if (exists $diff->{'nparents'}) { # combined diff
3351 fill_from_file_info
($diff, @parents)
3352 unless exists $diff->{'from_file'};
3354 if (!is_deleted
($diff)) {
3355 # file exists in the result (child) commit
3357 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3358 file_name
=>$to_prefix.$diff->{'to_file'},
3360 -class => "list"}, esc_path
($diff->{'to_file'})) .
3364 esc_path
($diff->{'to_file'}) .
3368 if ($action eq 'commitdiff') {
3371 print "<td class=\"link\">" .
3372 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3377 my $has_history = 0;
3378 my $not_deleted = 0;
3379 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3380 my $hash_parent = $parents[$i];
3381 my $from_hash = $diff->{'from_id'}[$i];
3382 my $from_path = $diff->{'from_file'}[$i];
3383 my $status = $diff->{'status'}[$i];
3385 $has_history ||= ($status ne 'A');
3386 $not_deleted ||= ($status ne 'D');
3388 if ($status eq 'A') {
3389 print "<td class=\"link\" align=\"right\"> | </td>\n";
3390 } elsif ($status eq 'D') {
3391 print "<td class=\"link\">" .
3392 $cgi->a({-href
=> href
(action
=>"blob",
3395 file_name
=>$from_prefix.$from_path)},
3399 if ($diff->{'to_id'} eq $from_hash) {
3400 print "<td class=\"link nochange\">";
3402 print "<td class=\"link\">";
3404 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3405 hash
=>$diff->{'to_id'},
3406 hash_parent
=>$from_hash,
3408 hash_parent_base
=>$hash_parent,
3409 file_name
=>$to_prefix.$diff->{'to_file'},
3410 file_parent
=>$from_prefix.$from_path)},
3416 print "<td class=\"link\">";
3418 print $cgi->a({-href
=> href
(action
=>"blob",
3419 hash
=>$diff->{'to_id'},
3420 file_name
=>$to_prefix.$diff->{'to_file'},
3423 print " | " if ($has_history);
3426 print $cgi->a({-href
=> href
(action
=>"history",
3427 file_name
=>$to_prefix.$diff->{'to_file'},
3434 next; # instead of 'else' clause, to avoid extra indent
3436 # else ordinary diff
3438 my ($to_mode_oct, $to_mode_str, $to_file_type);
3439 my ($from_mode_oct, $from_mode_str, $from_file_type);
3440 if ($diff->{'to_mode'} ne ('0' x
6)) {
3441 $to_mode_oct = oct $diff->{'to_mode'};
3442 if (S_ISREG
($to_mode_oct)) { # only for regular file
3443 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3445 $to_file_type = file_type
($diff->{'to_mode'});
3447 if ($diff->{'from_mode'} ne ('0' x
6)) {
3448 $from_mode_oct = oct $diff->{'from_mode'};
3449 if (S_ISREG
($to_mode_oct)) { # only for regular file
3450 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3452 $from_file_type = file_type
($diff->{'from_mode'});
3455 if ($diff->{'status'} eq "A") { # created
3456 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3457 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3458 $mode_chng .= "]</span>";
3460 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3461 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'}),
3462 -class => "list"}, esc_path
($diff->{'file'}));
3464 print "<td>$mode_chng</td>\n";
3465 print "<td class=\"link\">";
3466 if ($action eq 'commitdiff') {
3469 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3472 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3473 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'})},
3477 } elsif ($diff->{'status'} eq "D") { # deleted
3478 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3480 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3481 hash_base
=>$parent, file_name
=>$from_prefix.$diff->{'file'}),
3482 -class => "list"}, esc_path
($diff->{'file'}));
3484 print "<td>$mode_chng</td>\n";
3485 print "<td class=\"link\">";
3486 if ($action eq 'commitdiff') {
3489 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3492 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3493 hash_base
=>$parent, file_name
=>$from_prefix.$diff->{'file'})},
3496 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3497 file_name
=>$from_prefix.$diff->{'file'}), -class => "blamelink"},
3500 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3501 file_name
=>$from_prefix.$diff->{'file'})},
3505 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3506 my $mode_chnge = "";
3507 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3508 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3509 if ($from_file_type ne $to_file_type) {
3510 $mode_chnge .= " from $from_file_type to $to_file_type";
3512 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3513 if ($from_mode_str && $to_mode_str) {
3514 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3515 } elsif ($to_mode_str) {
3516 $mode_chnge .= " mode: $to_mode_str";
3519 $mode_chnge .= "]</span>\n";
3522 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3523 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'}),
3524 -class => "list"}, esc_path
($diff->{'file'}));
3526 print "<td>$mode_chnge</td>\n";
3527 print "<td class=\"link\">";
3528 if ($action eq 'commitdiff') {
3531 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3533 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3534 # "commit" view and modified file (not onlu mode changed)
3535 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3536 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3537 hash_base
=>$hash, hash_parent_base
=>$parent,
3538 file_name
=>$to_prefix.$diff->{'file'},
3539 file_parent
=>$from_prefix.$diff->{'file'})},
3543 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3544 hash_base
=>$hash, file_name
=>$to_prefix.$diff->{'file'})},
3547 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3548 file_name
=>$diff->{'file'}), -class => "blamelink"},
3551 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3552 file_name
=>$to_prefix.$diff->{'file'})},
3556 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3557 my %status_name = ('R' => 'moved', 'C' => 'copied');
3558 my $nstatus = $status_name{$diff->{'status'}};
3560 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3561 # mode also for directories, so we cannot use $to_mode_str
3562 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3565 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3566 hash
=>$diff->{'to_id'}, file_name
=>$to_prefix.$diff->{'to_file'}),
3567 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3568 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3569 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3570 hash
=>$diff->{'from_id'}, file_name
=>$from_prefix.$diff->{'from_file'}),
3571 -class => "list"}, esc_path
($diff->{'from_file'})) .
3572 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3573 "<td class=\"link\">";
3574 if ($action eq 'commitdiff') {
3577 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3579 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3580 # "commit" view and modified file (not only pure rename or copy)
3581 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3582 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3583 hash_base
=>$hash, hash_parent_base
=>$parent,
3584 file_name
=>$to_prefix.$diff->{'to_file'}, file_parent
=>$from_prefix.$diff->{'from_file'})},
3588 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3589 hash_base
=>$parent, file_name
=>$to_prefix.$diff->{'to_file'})},
3592 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3593 file_name
=>$diff->{'to_file'}), -class => "blamelink"},
3596 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3597 file_name
=>$to_prefix.$diff->{'to_file'})},
3601 } # we should not encounter Unmerged (U) or Unknown (X) status
3604 print "</tbody>" if $has_header;
3608 sub git_patchset_body
{
3609 my ($fd, $difftree, $from_prefix, $to_prefix, $hash, @hash_parents) = @_;
3610 my ($hash_parent) = $hash_parents[0];
3612 my $is_combined = (@hash_parents > 1);
3614 my $patch_number = 0;
3620 $from_prefix = !defined $from_prefix ?
'' : $from_prefix.'/';
3621 $to_prefix = !defined $to_prefix ?
'' : $to_prefix . '/';
3623 print "<div class=\"patchset\">\n";
3625 # skip to first patch
3626 while ($patch_line = <$fd>) {
3629 last if ($patch_line =~ m/^diff /);
3633 while ($patch_line) {
3635 # parse "git diff" header line
3636 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3637 # $1 is from_name, which we do not use
3638 $to_name = unquote
($2);
3639 $to_name =~ s!^b/!!;
3640 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3641 # $1 is 'cc' or 'combined', which we do not use
3642 $to_name = unquote
($2);
3647 # check if current patch belong to current raw line
3648 # and parse raw git-diff line if needed
3649 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3650 # this is continuation of a split patch
3651 print "<div class=\"patch cont\">\n";
3652 $diffinfo->{'from_prefix'} = $from_prefix;
3653 $diffinfo->{'to_prefix'} = $to_prefix;
3655 # advance raw git-diff output if needed
3656 $patch_idx++ if defined $diffinfo;
3658 # read and prepare patch information
3659 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3661 # compact combined diff output can have some patches skipped
3662 # find which patch (using pathname of result) we are at now;
3664 while ($to_name ne $diffinfo->{'to_file'}) {
3665 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3666 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3667 "</div>\n"; # class="patch"
3672 last if $patch_idx > $#$difftree;
3673 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3677 $diffinfo->{'from_prefix'} = $from_prefix;
3678 $diffinfo->{'to_prefix'} = $to_prefix;
3680 # modifies %from, %to hashes
3681 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3682 # this is first patch for raw difftree line with $patch_idx index
3683 # we index @$difftree array from 0, but number patches from 1
3684 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3688 #assert($patch_line =~ m/^diff /) if DEBUG;
3689 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3691 # print "git diff" header
3692 print format_git_diff_header_line
($patch_line, $diffinfo,
3695 # print extended diff header
3696 print "<div class=\"diff extended_header\">\n";
3698 while ($patch_line = <$fd>) {
3701 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3703 print format_extended_diff_header_line
($patch_line, $diffinfo,
3706 print "</div>\n"; # class="diff extended_header"
3708 # from-file/to-file diff header
3709 if (! $patch_line) {
3710 print "</div>\n"; # class="patch"
3713 next PATCH
if ($patch_line =~ m/^diff /);
3714 #assert($patch_line =~ m/^---/) if DEBUG;
3716 my $last_patch_line = $patch_line;
3717 $patch_line = <$fd>;
3719 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3721 print format_diff_from_to_header
($last_patch_line, $patch_line,
3722 $diffinfo, \
%from, \
%to,
3727 while ($patch_line = <$fd>) {
3730 next PATCH
if ($patch_line =~ m/^diff /);
3732 print format_diff_line
($patch_line, \
%from, \
%to);
3736 print "</div>\n"; # class="patch"
3739 # for compact combined (--cc) format, with chunk and patch simpliciaction
3740 # patchset might be empty, but there might be unprocessed raw lines
3741 for (++$patch_idx if $patch_number > 0;
3742 $patch_idx < @
$difftree;
3744 # read and prepare patch information
3745 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3747 # generate anchor for "patch" links in difftree / whatchanged part
3748 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3749 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3750 "</div>\n"; # class="patch"
3755 if ($patch_number == 0) {
3756 if (@hash_parents > 1) {
3757 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3759 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3763 print "</div>\n"; # class="patchset"
3766 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3768 # fills project list info (age, description, owner, forks) for each
3769 # project in the list, removing invalid projects from returned list
3770 # NOTE: modifies $projlist, but does not remove entries from it
3771 sub fill_project_list_info
{
3772 my ($projlist, $check_forks) = @_;
3775 my $show_ctags = gitweb_check_feature
('ctags');
3777 foreach my $pr (@
$projlist) {
3778 my (@activity) = git_get_last_activity
($pr->{'path'});
3779 unless (@activity) {
3782 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3783 if (!defined $pr->{'descr'}) {
3784 my $descr = git_get_project_description
($pr->{'path'}) || "";
3785 $descr = to_utf8
($descr);
3786 $pr->{'descr_long'} = $descr;
3787 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3789 if (!defined $pr->{'owner'}) {
3790 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3793 my $pname = $pr->{'path'};
3794 if (($pname =~ s/\.git$//) &&
3795 ($pname !~ /\/$/) &&
3796 (-d
"$projectroot/$pname")) {
3797 $pr->{'forks'} = "-d $projectroot/$pname";
3802 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3803 push @projects, $pr;
3809 # print 'sort by' <th> element, generating 'sort by $name' replay link
3810 # if that order is not selected
3812 my ($name, $order, $header) = @_;
3813 $header ||= ucfirst($name);
3815 if ($order eq $name) {
3816 print "<th>$header</th>\n";
3819 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3820 -class => "header"}, $header) .
3825 sub git_project_list_body
{
3826 # actually uses global variable $project
3827 my ($projlist, $order, $from, $to, $extra, $no_header, $cache_lifetime) = @_;
3829 my ($check_forks) = gitweb_check_feature
('forks');
3832 use POSIX
qw(:fcntl_h);
3833 use Storable
qw(store_fd retrieve);
3835 my $cache_file = "$cache_dir/$projlist_cache_name";
3841 if ($cache_lifetime && -f
$cache_file) {
3842 $cache_mtime = stat($cache_file)->mtime;
3844 if (defined $cache_mtime && # caching is on and $cache_file exists
3845 $cache_mtime + $cache_lifetime*60 > $now &&
3846 (my $dump = retrieve
($cache_file))) {
3847 $stale = $now - $cache_mtime;
3850 if (defined $cache_mtime) {
3851 # Postpone timeout by two minutes so that we get
3852 # enough time to do our job, or to be more exact
3853 # make cache expire after two minutes from now.
3854 my $time = $now - $cache_lifetime*60 + 120;
3855 utime $time, $time, $cache_file;
3857 @projects = fill_project_list_info
($projlist, $check_forks);
3858 if ($cache_lifetime &&
3859 (-d
$cache_dir || mkdir($cache_dir, 0700)) &&
3860 sysopen(my $fd, "$cache_file.lock", O_WRONLY
|O_CREAT
|O_EXCL
, 0600)) {
3861 store_fd
(\
@projects, $fd);
3863 rename "$cache_file.lock", $cache_file;
3867 $order ||= $default_projects_order;
3868 $from = 0 unless defined $from;
3869 $to = $#projects if (!defined $to || $#projects < $to);
3871 if ($cache_lifetime && $stale > 0) {
3872 print "<div class=\"stale_info\">Cached version (${stale}s old)</div>\n";
3876 project
=> { key
=> 'path', type
=> 'str' },
3877 descr
=> { key
=> 'descr_long', type
=> 'str' },
3878 owner
=> { key
=> 'owner', type
=> 'str' },
3879 age
=> { key
=> 'age', type
=> 'num' }
3881 my $oi = $order_info{$order};
3882 if ($oi->{'type'} eq 'str') {
3883 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3885 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3888 if ($cache_lifetime && $stale > 0) {
3889 print "<div class=\"stale_info\">Cached version (${stale}s old)</div>\n";
3892 my $show_ctags = gitweb_check_feature
('ctags');
3895 foreach my $p (@projects) {
3896 foreach my $ct (keys %{$p->{'ctags'}}) {
3897 $ctags{$ct} += $p->{'ctags'}->{$ct};
3900 my $cloud = git_populate_project_tagcloud
(\
%ctags);
3901 print git_show_project_tagcloud
($cloud, 64);
3904 print "<table class=\"project_list\">\n";
3905 unless ($no_header) {
3908 print "<th></th>\n";
3910 print_sort_th
('project', $order, 'Project');
3911 print_sort_th
('descr', $order, 'Description');
3912 print_sort_th
('owner', $order, 'Owner');
3913 print_sort_th
('age', $order, 'Last Change');
3914 print "<th></th>\n" . # for links
3918 my $tagfilter = $cgi->param('by_tag');
3919 for (my $i = $from; $i <= $to; $i++) {
3920 my $pr = $projects[$i];
3922 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
3923 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
3924 and not $pr->{'descr_long'} =~ /$searchtext/;
3925 # Weed out forks or non-matching entries of search
3927 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
3928 $forkbase="^$forkbase" if $forkbase;
3929 next if not $searchtext and not $tagfilter and $show_ctags
3930 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
3934 print "<tr class=\"dark\">\n";
3936 print "<tr class=\"light\">\n";
3941 if ($pr->{'forks'}) {
3942 print "<!-- $pr->{'forks'} -->\n";
3943 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3947 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3948 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3949 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3950 -class => "list", -title
=> $pr->{'descr_long'}},
3951 esc_html
($pr->{'descr'})) . "</td>\n" .
3952 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3953 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3954 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3955 "<td class=\"link\">" .
3956 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3957 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "log") . " | " .
3958 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3959 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3963 if (defined $extra) {
3966 print "<td></td>\n";
3968 print "<td colspan=\"5\">$extra</td>\n" .
3974 sub git_shortlog_body
{
3975 # uses global variable $project
3976 my ($commitlist, $from, $to, $refs, $extra) = @_;
3978 $from = 0 unless defined $from;
3979 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3981 print "<table class=\"shortlog\">\n";
3983 for (my $i = $from; $i <= $to; $i++) {
3984 my %co = %{$commitlist->[$i]};
3985 my $commit = $co{'id'};
3986 my $ref = format_ref_marker
($refs, $commit);
3988 print "<tr class=\"dark\">\n";
3990 print "<tr class=\"light\">\n";
3993 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3994 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3995 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3996 "<td><i>" . $author . "</i></td>\n" .
3998 print format_subject_html
($co{'title'}, $co{'title_short'},
3999 href
(action
=>"commit", hash
=>$commit), $ref);
4001 "<td class=\"link\">" .
4002 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4003 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4004 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4005 my $snapshot_links = format_snapshot_links
($commit);
4006 if (defined $snapshot_links) {
4007 print " | " . $snapshot_links;
4012 if (defined $extra) {
4014 "<td colspan=\"4\">$extra</td>\n" .
4020 sub git_history_body
{
4021 # Warning: assumes constant type (blob or tree) during history
4022 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4024 $from = 0 unless defined $from;
4025 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4027 print "<table class=\"history\">\n";
4029 for (my $i = $from; $i <= $to; $i++) {
4030 my %co = %{$commitlist->[$i]};
4034 my $commit = $co{'id'};
4036 my $ref = format_ref_marker
($refs, $commit);
4039 print "<tr class=\"dark\">\n";
4041 print "<tr class=\"light\">\n";
4044 # shortlog uses chop_str($co{'author_name'}, 10)
4045 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4046 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4047 "<td><i>" . $author . "</i></td>\n" .
4049 # originally git_history used chop_str($co{'title'}, 50)
4050 print format_subject_html
($co{'title'}, $co{'title_short'},
4051 href
(action
=>"commit", hash
=>$commit), $ref);
4053 "<td class=\"link\">" .
4054 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4055 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4057 if ($ftype eq 'blob') {
4058 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4059 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4060 if (defined $blob_current && defined $blob_parent &&
4061 $blob_current ne $blob_parent) {
4063 $cgi->a({-href
=> href
(action
=>"blobdiff",
4064 hash
=>$blob_current, hash_parent
=>$blob_parent,
4065 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4066 file_name
=>$file_name)},
4073 if (defined $extra) {
4075 "<td colspan=\"4\">$extra</td>\n" .
4082 # uses global variable $project
4083 my ($taglist, $from, $to, $extra) = @_;
4084 $from = 0 unless defined $from;
4085 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4087 print "<table class=\"tags\">\n";
4089 for (my $i = $from; $i <= $to; $i++) {
4090 my $entry = $taglist->[$i];
4092 my $comment = $tag{'subject'};
4094 if (defined $comment) {
4095 $comment_short = chop_str
($comment, 30, 5);
4098 print "<tr class=\"dark\">\n";
4100 print "<tr class=\"light\">\n";
4103 if (defined $tag{'age'}) {
4104 print "<td><i>$tag{'age'}</i></td>\n";
4106 print "<td></td>\n";
4109 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4110 -class => "list name"}, esc_html
($tag{'name'})) .
4113 if (defined $comment) {
4114 print format_subject_html
($comment, $comment_short,
4115 href
(action
=>"tag", hash
=>$tag{'id'}));
4118 "<td class=\"selflink\">";
4119 if ($tag{'type'} eq "tag") {
4120 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4125 "<td class=\"link\">" . " | " .
4126 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4127 if ($tag{'reftype'} eq "commit") {
4128 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "log");
4129 } elsif ($tag{'reftype'} eq "blob") {
4130 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4135 if (defined $extra) {
4137 "<td colspan=\"5\">$extra</td>\n" .
4143 sub git_heads_body
{
4144 # uses global variable $project
4145 my ($headlist, $head, $from, $to, $extra) = @_;
4146 $from = 0 unless defined $from;
4147 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4149 print "<table class=\"heads\">\n";
4151 for (my $i = $from; $i <= $to; $i++) {
4152 my $entry = $headlist->[$i];
4154 my $curr = $ref{'id'} eq $head;
4156 print "<tr class=\"dark\">\n";
4158 print "<tr class=\"light\">\n";
4161 print "<td><i>$ref{'age'}</i></td>\n" .
4162 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4163 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4164 -class => "list name"},esc_html
($ref{'name'})) .
4166 "<td class=\"link\">" .
4167 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "log") . " | " .
4168 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4172 if (defined $extra) {
4174 "<td colspan=\"3\">$extra</td>\n" .
4180 sub git_search_grep_body
{
4181 my ($commitlist, $from, $to, $extra) = @_;
4182 $from = 0 unless defined $from;
4183 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4185 print "<table class=\"commit_search\">\n";
4187 for (my $i = $from; $i <= $to; $i++) {
4188 my %co = %{$commitlist->[$i]};
4192 my $commit = $co{'id'};
4194 print "<tr class=\"dark\">\n";
4196 print "<tr class=\"light\">\n";
4199 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4200 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4201 "<td><i>" . $author . "</i></td>\n" .
4203 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4204 -class => "list subject"},
4205 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4206 my $comment = $co{'comment'};
4207 foreach my $line (@
$comment) {
4208 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4209 my ($lead, $match, $trail) = ($1, $2, $3);
4210 $match = chop_str
($match, 70, 5, 'center');
4211 my $contextlen = int((80 - length($match))/2);
4212 $contextlen = 30 if ($contextlen > 30);
4213 $lead = chop_str
($lead, $contextlen, 10, 'left');
4214 $trail = chop_str
($trail, $contextlen, 10, 'right');
4216 $lead = esc_html
($lead);
4217 $match = esc_html
($match);
4218 $trail = esc_html
($trail);
4220 print "$lead<span class=\"match\">$match</span>$trail<br />";
4224 "<td class=\"link\">" .
4225 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4227 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4229 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4233 if (defined $extra) {
4235 "<td colspan=\"3\">$extra</td>\n" .
4241 ## ======================================================================
4242 ## ======================================================================
4245 sub git_project_list
{
4246 my $order = $cgi->param('o');
4247 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4248 die_error
(400, "Unknown order parameter");
4251 my @list = git_get_projects_list
();
4253 die_error
(404, "No projects found");
4257 if (-f
$home_text) {
4258 print "<div class=\"index_include\">\n";
4259 open (my $fd, $home_text);
4264 print $cgi->startform(-method
=> "get") .
4265 "<p class=\"projsearch\">Search:\n" .
4266 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4268 $cgi->end_form() . "\n";
4269 git_project_list_body
(\
@list, $order, undef, undef, undef, undef, $projlist_cache_lifetime);
4274 my $order = $cgi->param('o');
4275 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4276 die_error
(400, "Unknown order parameter");
4279 my @list = git_get_projects_list
($project);
4281 die_error
(404, "No forks found");
4285 git_print_page_nav
('','');
4286 git_print_header_div
('summary', "$project forks");
4287 git_project_list_body
(\
@list, $order);
4291 sub git_project_index
{
4292 my @projects = git_get_projects_list
($project);
4295 -type
=> 'text/plain',
4296 -charset
=> 'utf-8',
4297 -content_disposition
=> 'inline; filename="index.aux"');
4299 foreach my $pr (@projects) {
4300 if (!exists $pr->{'owner'}) {
4301 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4304 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4305 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4306 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4307 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4311 print "$path $owner\n";
4316 my $descr = git_get_project_description
($project) || "none";
4317 my %co = parse_commit
("HEAD");
4318 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4319 my $head = $co{'id'};
4321 my $owner = git_get_project_owner
($project);
4322 my $homepage = git_get_project_config
('homepage');
4323 my $base_url = git_get_project_config
('base_url');
4324 my $last_refresh = git_get_project_config
("last_refresh");
4326 my $refs = git_get_references
();
4327 # These get_*_list functions return one more to allow us to see if
4328 # there are more ...
4329 my @taglist = git_get_tags_list
(16);
4330 my @headlist = git_get_heads_list
(16);
4332 my ($check_forks) = gitweb_check_feature
('forks');
4335 @forklist = git_get_projects_list
($project);
4339 git_print_page_nav
('summary','', $head);
4341 if ($check_forks and $project =~ m
#/#) {
4342 my $xproject = $project; $xproject =~ s
#/.+?$#.git#; #
4343 my $r = $cgi->a({-href
=> href
(project
=> $xproject, action
=> 'summary')}, $xproject);
4345 <div class="forkinfo">
4346 This project is a fork of the $r project. If you have that one
4347 already cloned locally, you can use
4348 <pre>git clone --reference /path/to/your/$xproject/incarnation mirror_URL</pre>
4349 to save bandwidth during cloning.
4354 print "<div class=\"title\"> </div>\n";
4355 print "<table class=\"projects_list\">\n";
4356 print "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4357 $homepage and print "<tr id=\"metadata_homepage\"><td>homepage URL</td><td>" . $cgi->a({-href
=> $homepage}, $homepage) . "</td></tr>\n";
4358 $base_url and print "<tr id=\"metadata_baseurl\"><td>repository URL</td><td>" . esc_html
($base_url) . "</td></tr>\n";
4359 print "<tr id=\"metadata_owner\"><td>owner</td><td>" . email_obfuscate
($owner) . "</td></tr>\n";
4360 if (defined $cd{'rfc2822'}) {
4361 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4363 $last_refresh and print "<tr id=\"metadata_lrefresh\"><td>last refresh</td><td>$last_refresh</td></tr>\n";
4365 # use per project git URL list in $projectroot/$project/cloneurl
4366 # or make project git URL from git base URL and project name
4367 my $url_tag = $base_url ?
"mirror URL" : "URL";
4368 my @url_list = git_get_project_url_list
($project);
4369 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4370 foreach my $git_url (@url_list) {
4371 next unless $git_url;
4372 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4375 -f
"$projectroot/$project/.nofetch" and $git_base_push_url and
4376 print "<tr id=\"metadata_pushurl\"><td>Push URL</td><td>$git_base_push_url/$project</td></tr>\n";
4379 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4381 my $ctags = git_get_project_ctags
($project);
4382 my $cloud = git_populate_project_tagcloud
($ctags);
4383 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4384 print "</td>\n<td>" unless %$ctags;
4385 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4386 print "</td>\n<td>" if %$ctags;
4387 print git_show_project_tagcloud
($cloud, 48);
4393 if (-s
"$projectroot/$project/README.html") {
4394 if (open my $fd, "$projectroot/$project/README.html") {
4395 print "<div class=\"title\">readme</div>\n" .
4396 "<div class=\"readme\">\n";
4397 print $_ while (<$fd>);
4398 print "\n</div>\n"; # class="readme"
4403 # we need to request one more than 16 (0..15) to check if
4405 my @commitlist = $head ? parse_commits
($head, 17) : ();
4407 git_print_header_div
('shortlog');
4408 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4409 $#commitlist <= 15 ?
undef :
4410 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4414 git_print_header_div
('tags');
4415 git_tags_body
(\
@taglist, 0, 15,
4416 $#taglist <= 15 ?
undef :
4417 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4421 git_print_header_div
('heads');
4422 git_heads_body
(\
@headlist, $head, 0, 15,
4423 $#headlist <= 15 ?
undef :
4424 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4428 git_print_header_div
('forks');
4429 git_project_list_body
(\
@forklist, 'age', 0, 15,
4430 $#forklist <= 15 ?
undef :
4431 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4439 my $head = git_get_head_hash
($project);
4441 git_print_page_nav
('','', $head,undef,$head);
4442 my %tag = parse_tag
($hash);
4445 die_error
(404, "Unknown tag object");
4448 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4449 print "<div class=\"title_text\">\n" .
4450 "<table class=\"object_header\">\n" .
4452 "<td>object</td>\n" .
4453 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4454 $tag{'object'}) . "</td>\n" .
4455 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4456 $tag{'type'}) . "</td>\n" .
4458 if (defined($tag{'author'})) {
4459 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4460 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4461 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4462 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4465 print "</table>\n\n" .
4467 print "<div class=\"page_body\">";
4468 my $comment = $tag{'comment'};
4469 foreach my $line (@
$comment) {
4471 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4477 sub git_blame_data
{
4481 my ($have_blame) = gitweb_check_feature
('blame');
4483 die_error
('403 Permission denied', "Permission denied");
4485 die_error
('404 Not Found', "File name not defined") if (!$file_name);
4486 $hash_base ||= git_get_head_hash
($project);
4487 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
4488 my %co = parse_commit
($hash_base)
4489 or die_error
(undef, "Reading commit failed");
4490 if (!defined $hash) {
4491 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4492 or die_error
(undef, "Error looking up file");
4494 $ftype = git_get_type
($hash);
4495 if ($ftype !~ "blob") {
4496 die_error
("400 Bad Request", "Object is not a blob");
4498 open ($fd, "-|", git_cmd
(), "blame", '--incremental', $hash_base, '--',
4500 or die_error
(undef, "Open git-blame --incremental failed");
4502 print $cgi->header(-type
=>"text/plain", -charset
=> 'utf-8',
4503 -status
=> "200 OK");
4506 if (/^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ or
4507 /^author-time |^author |^filename /) {
4512 close $fd or print "Reading blame data failed\n";
4515 sub git_blame_common
{
4521 gitweb_check_feature
('blame')
4522 or die_error
(403, "Blame view not allowed");
4524 die_error
(400, "No file name given") unless $file_name;
4525 $hash_base ||= git_get_head_hash
($project);
4526 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4527 my %co = parse_commit
($hash_base)
4528 or die_error
(404, "Commit not found");
4529 if (!defined $hash) {
4530 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4531 or die_error
(404, "Error looking up file");
4533 $ftype = git_get_type
($hash);
4534 if ($ftype !~ "blob") {
4535 die_error
(400, "Object is not a blob");
4537 if ($type eq 'incremental') {
4538 open ($fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash)
4539 or die_error
(undef, "Open git-cat-file failed");
4541 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4542 $file_name, $hash_base)
4543 or die_error
(500, "Open git-blame failed");
4547 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4550 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4553 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name), -class => "blamelink"},
4555 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4556 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4557 git_print_page_path
($file_name, $ftype, $hash_base);
4558 my @rev_color = (qw(light2 dark2));
4559 my $num_colors = scalar(@rev_color);
4560 my $current_color = 0;
4564 <div class="page_body">
4565 <table class="blame">
4566 <tr><th>Commit <a href="javascript:extra_blame_columns()" id="columns_expander">[+]</a></th>
4567 <th class="extra_column">Author</th>
4568 <th class="extra_column">Date</th>
4576 if ($type eq 'incremental') {
4577 # Empty stage with just the file contents
4579 print "<tr id=\"l$linenr\" class=\"light2\">";
4580 print '<td class="sha1"><a href=""></a></td>';
4581 print "<td class=\"extra_column\"></td>";
4582 print "<td class=\"extra_column\"></td>";
4583 print "<td class=\"linenr\"><a class=\"linenr\" href=\"\">$linenr</a></td><td class=\"pre\">" . esc_html
($_) . "</td>\n";
4588 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4589 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4590 if (!exists $metainfo{$full_rev}) {
4591 $metainfo{$full_rev} = {};
4593 my $meta = $metainfo{$full_rev};
4596 if (/^(\S+) (.*)$/) {
4602 my $rev = substr($full_rev, 0, 8);
4603 my $author = $meta->{'author'};
4604 my %date = parse_date
($meta->{'author-time'},
4605 $meta->{'author-tz'});
4606 my $date = $date{'iso-tz'};
4608 $current_color = ++$current_color % $num_colors;
4610 print "<tr class=\"$rev_color[$current_color]\">\n";
4612 my $rowspan = $group_size > 1 ?
" rowspan=\"$group_size\"" : "";
4613 print "<td class=\"sha1\"";
4614 print " title=\"". esc_html
($author) . ", $date\"";
4616 print $cgi->a({-href
=> href
(action
=>"commit",
4618 file_name
=>$file_name)},
4621 print "<td class=\"extra_column\" $rowspan>". esc_html
($author) . "</td>";
4622 print "<td class=\"extra_column\" $rowspan>". $date . "</td>";
4624 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4625 or die_error
(500, "Open git-rev-parse failed");
4626 my $parent_commit = <$dd>;
4628 chomp($parent_commit);
4629 my $blamed = href
(action
=> 'blame',
4630 file_name
=> $meta->{'filename'},
4631 hash_base
=> $parent_commit);
4632 print "<td class=\"linenr\">";
4633 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4635 -class => "linenr" },
4638 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4645 or print "Reading blob failed\n";
4647 if ($type eq 'incremental') {
4648 print "<script type=\"text/javascript\">\n";
4649 print "startBlame(\"" . href
(action
=>"blame_data", hash_base
=>$hash_base, file_name
=>$file_name) . "\", \"" .
4650 href
(-partial_query
=>1) . "\");\n";
4651 print "</script>\n";
4657 sub git_blame_incremental
{
4658 git_blame_common
('incremental');
4662 git_blame_common
('oneshot');
4666 my $head = git_get_head_hash
($project);
4668 git_print_page_nav
('','', $head,undef,$head);
4669 git_print_header_div
('summary', $project);
4671 my @tagslist = git_get_tags_list
();
4673 git_tags_body
(\
@tagslist);
4679 my $head = git_get_head_hash
($project);
4681 git_print_page_nav
('','', $head,undef,$head);
4682 git_print_header_div
('summary', $project);
4684 my @headslist = git_get_heads_list
();
4686 git_heads_body
(\
@headslist, $head);
4691 sub git_blob_plain
{
4695 if (!defined $hash) {
4696 if (defined $file_name) {
4697 my $base = $hash_base || git_get_head_hash
($project);
4698 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4699 or die_error
(404, "Cannot find file");
4701 die_error
(400, "No file name defined");
4703 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4704 # blobs defined by non-textual hash id's can be cached
4708 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4709 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4711 # content-type (can include charset)
4712 $type = blob_contenttype
($fd, $file_name, $type);
4714 # "save as" filename, even when no $file_name is given
4715 my $save_as = "$hash";
4716 if (defined $file_name) {
4717 $save_as = $file_name;
4718 } elsif ($type =~ m/^text\//) {
4724 -expires
=> $expires,
4725 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4727 binmode STDOUT
, ':raw';
4729 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4737 if (!defined $hash) {
4738 if (defined $file_name) {
4739 my $base = $hash_base || git_get_head_hash
($project);
4740 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4741 or die_error
(404, "Cannot find file");
4743 die_error
(400, "No file name defined");
4745 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4746 # blobs defined by non-textual hash id's can be cached
4750 my ($have_blame) = gitweb_check_feature
('blame');
4751 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4752 or die_error
(500, "Couldn't cat $file_name, $hash");
4753 my $mimetype = blob_mimetype
($fd, $file_name);
4754 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4756 return git_blob_plain
($mimetype);
4758 # we can have blame only for text/* mimetype
4759 $have_blame &&= ($mimetype =~ m!^text/!);
4761 git_header_html
(undef, $expires);
4762 my $formats_nav = '';
4763 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4764 if (defined $file_name) {
4767 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1,
4768 -class => "blamelink")},
4773 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4776 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4779 $cgi->a({-href
=> href
(action
=>"blob",
4780 hash_base
=>"HEAD", file_name
=>$file_name)},
4784 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4787 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4788 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4790 print "<div class=\"page_nav\">\n" .
4791 "<br/><br/></div>\n" .
4792 "<div class=\"title\">$hash</div>\n";
4794 git_print_page_path
($file_name, "blob", $hash_base);
4795 print "<div class=\"page_body\">\n";
4796 if ($mimetype =~ m!^image/!) {
4797 print qq!<img type
="$mimetype"!;
4799 print qq! alt
="$file_name" title
="$file_name"!;
4802 href(action=>"blob_plain
", hash=>$hash,
4803 hash_base=>$hash_base, file_name=>$file_name) .
4807 while (my $line = <$fd>) {
4810 $line = untabify
($line);
4811 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4812 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4816 or print "Reading blob failed.\n";
4822 if (!defined $hash_base) {
4823 $hash_base = "HEAD";
4825 if (!defined $hash) {
4826 if (defined $file_name) {
4827 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4832 die_error
(404, "No such tree") unless defined($hash);
4834 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4835 or die_error
(500, "Open git-ls-tree failed");
4836 my @entries = map { chomp; $_ } <$fd>;
4837 close $fd or die_error
(404, "Reading tree failed");
4840 my $refs = git_get_references
();
4841 my $ref = format_ref_marker
($refs, $hash_base);
4844 my ($have_blame) = gitweb_check_feature
('blame');
4845 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4847 if (defined $file_name) {
4849 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4851 $cgi->a({-href
=> href
(action
=>"tree",
4852 hash_base
=>"HEAD", file_name
=>$file_name)},
4855 my $snapshot_links = format_snapshot_links
($hash);
4856 if (defined $snapshot_links) {
4857 # FIXME: Should be available when we have no hash base as well.
4858 push @views_nav, $snapshot_links;
4860 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4861 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4864 print "<div class=\"page_nav\">\n";
4865 print "<br/><br/></div>\n";
4866 print "<div class=\"title\">$hash</div>\n";
4868 if (defined $file_name) {
4869 $basedir = $file_name;
4870 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4873 git_print_page_path
($file_name, 'tree', $hash_base);
4875 print "<div class=\"page_body\">\n";
4876 print "<table class=\"tree\">\n";
4878 # '..' (top directory) link if possible
4879 if (defined $hash_base &&
4880 defined $file_name && $file_name =~ m![^/]+$!) {
4882 print "<tr class=\"dark\">\n";
4884 print "<tr class=\"light\">\n";
4888 my $up = $file_name;
4889 $up =~ s!/?[^/]+$!!;
4890 undef $up unless $up;
4891 # based on git_print_tree_entry
4892 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4893 print '<td class="list">';
4894 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4898 print "<td class=\"link\"></td>\n";
4902 foreach my $line (@entries) {
4903 my %t = parse_ls_tree_line
($line, -z
=> 1);
4906 print "<tr class=\"dark\">\n";
4908 print "<tr class=\"light\">\n";
4912 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4916 print "</table>\n" .
4922 my @supported_fmts = gitweb_check_feature
('snapshot');
4923 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4925 my $format = $cgi->param('sf');
4926 if (!@supported_fmts) {
4927 die_error
(403, "Snapshots not allowed");
4929 # default to first supported snapshot format
4930 $format ||= $supported_fmts[0];
4931 if ($format !~ m/^[a-z0-9]+$/) {
4932 die_error
(400, "Invalid snapshot format parameter");
4933 } elsif (!exists($known_snapshot_formats{$format})) {
4934 die_error
(400, "Unknown snapshot format");
4935 } elsif (!grep($_ eq $format, @supported_fmts)) {
4936 die_error
(403, "Unsupported snapshot format");
4939 if (!defined $hash) {
4940 $hash = git_get_head_hash
($project);
4943 my $name = $project;
4944 $name =~ s
,([^/])/*\
.git
$,$1,;
4945 $name = basename
($name);
4946 my $filename = to_utf8
($name);
4947 $name =~ s/\047/\047\\\047\047/g;
4949 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4950 $cmd = quote_command
(
4951 git_cmd
(), 'archive',
4952 "--format=$known_snapshot_formats{$format}{'format'}",
4953 "--prefix=$name/", $hash);
4954 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4955 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4959 -type
=> $known_snapshot_formats{$format}{'type'},
4960 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4961 -status
=> '200 OK');
4963 open my $fd, "-|", $cmd
4964 or die_error
(500, "Execute git-archive failed");
4965 binmode STDOUT
, ':raw';
4967 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4972 my $head = git_get_head_hash
($project);
4973 if (!defined $hash) {
4976 if (!defined $page) {
4979 my $refs = git_get_references
();
4981 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4983 my $paging_nav = format_log_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4986 local $action = 'fulllog';
4989 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4992 my %co = parse_commit
($hash);
4994 git_print_header_div
('summary', $project);
4995 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4997 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4998 for (my $i = 0; $i <= $to; $i++) {
4999 my %co = %{$commitlist[$i]};
5001 my $commit = $co{'id'};
5002 my $ref = format_ref_marker
($refs, $commit);
5003 my %ad = parse_date
($co{'author_epoch'});
5004 git_print_header_div
('commit',
5005 "<span class=\"age\">$co{'age_string'}</span>" .
5006 esc_html
($co{'title'}) . $ref,
5008 print "<div class=\"title_text\">\n" .
5009 "<div class=\"log_link\">\n" .
5010 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5012 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5014 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5017 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5020 print "<div class=\"log_body\">\n";
5021 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5024 if ($#commitlist >= 100) {
5025 print "<div class=\"page_nav\">\n";
5026 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5027 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5034 $hash ||= $hash_base || "HEAD";
5035 my %co = parse_commit
($hash)
5036 or die_error
(404, "Unknown commit object");
5037 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5038 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5040 my $parent = $co{'parent'};
5041 my $parents = $co{'parents'}; # listref
5043 # we need to prepare $formats_nav before any parameter munging
5045 if (!defined $parent) {
5047 $formats_nav .= '(initial)';
5048 } elsif (@
$parents == 1) {
5049 # single parent commit
5052 $cgi->a({-href
=> href
(action
=>"commit",
5054 esc_html
(substr($parent, 0, 7))) .
5061 $cgi->a({-href
=> href
(action
=>"commit",
5063 esc_html
(substr($_, 0, 7)));
5068 if (!defined $parent) {
5072 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5074 (@
$parents <= 1 ?
$parent : '-c'),
5076 or die_error
(500, "Open git-diff-tree failed");
5077 @difftree = map { chomp; $_ } <$fd>;
5078 close $fd or die_error
(404, "Reading git-diff-tree failed");
5080 # non-textual hash id's can be cached
5082 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5085 my $refs = git_get_references
();
5086 my $ref = format_ref_marker
($refs, $co{'id'});
5088 git_header_html
(undef, $expires);
5089 git_print_page_nav
('commit', '',
5090 $hash, $co{'tree'}, $hash,
5093 if (defined $co{'parent'}) {
5094 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5096 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5098 print "<div class=\"title_text\">\n" .
5099 "<table class=\"object_header\">\n";
5100 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5102 "<td></td><td> $ad{'rfc2822'}";
5103 if ($ad{'hour_local'} < 6) {
5104 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5105 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5107 printf(" (%02d:%02d %s)",
5108 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5112 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5113 print "<tr><td></td><td> $cd{'rfc2822'}" .
5114 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5116 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5119 "<td class=\"sha1\">" .
5120 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5121 class => "list"}, $co{'tree'}) .
5123 "<td class=\"link\">" .
5124 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5126 my $snapshot_links = format_snapshot_links
($hash);
5127 if (defined $snapshot_links) {
5128 print " | " . $snapshot_links;
5133 foreach my $par (@
$parents) {
5136 "<td class=\"sha1\">" .
5137 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5138 class => "list"}, $par) .
5140 "<td class=\"link\">" .
5141 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5143 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5150 print "<div class=\"page_body\">\n";
5151 git_print_log
($co{'comment'});
5154 git_difftree_body
(\
@difftree, undef, undef, $hash, @
$parents);
5160 # object is defined by:
5161 # - hash or hash_base alone
5162 # - hash_base and file_name
5165 # - hash or hash_base alone
5166 if ($hash || ($hash_base && !defined $file_name)) {
5167 my $object_id = $hash || $hash_base;
5169 open my $fd, "-|", quote_command
(
5170 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5171 or die_error
(404, "Object does not exist");
5175 or die_error
(404, "Object does not exist");
5177 # - hash_base and file_name
5178 } elsif ($hash_base && defined $file_name) {
5179 $file_name =~ s
,/+$,,;
5181 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5182 or die_error
(404, "Base object does not exist");
5184 # here errors should not hapen
5185 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5186 or die_error
(500, "Open git-ls-tree failed");
5190 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5191 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5192 die_error
(404, "File or directory for given base does not exist");
5197 die_error
(400, "Not enough information to find object");
5200 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5201 hash
=>$hash, hash_base
=>$hash_base,
5202 file_name
=>$file_name),
5203 -status
=> '302 Found');
5207 my $format = shift || 'html';
5212 my $expires = '+1d';
5215 $file_parent ||= $file_name;
5217 # non-textual hash id's can be cached
5218 if (defined $hash && $hash !~ m/^[0-9a-fA-F]{40}$/) {
5220 } elsif (defined $hash_parent && $hash_parent !~ m/^[0-9a-fA-F]{40}$/) {
5222 } elsif (defined $hash_base && $hash_base !~ m/^[0-9a-fA-F]{40}$/) {
5224 } elsif (defined $hash_parent_base && $hash_parent_base !~ m/^[0-9a-fA-F]{40}$/) {
5228 # if hash parameter is missing, read it from the commit.
5229 if (defined $hash_base && defined $file_name && !defined $hash) {
5230 $hash = git_get_hash_by_path
($hash_base, $file_name);
5233 if (defined $hash_parent_base && defined $file_parent && !defined $hash_parent) {
5234 $hash_parent = git_get_hash_by_path
($hash_parent_base, $file_parent);
5237 if (!defined $hash || ! defined $hash_parent) {
5238 die_error
(404, "Missing one of the blob diff parameters");
5241 if (defined $hash_base && defined $file_name) {
5242 $to = $hash_base . ':' . $file_name;
5247 if (defined $hash_parent_base && defined $file_parent) {
5248 $from = $hash_parent_base . ':' . $file_parent;
5250 $from = $hash_parent;
5253 # fake git-diff-tree raw output
5254 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5255 $diffinfo{'from_id'} = $hash_parent;
5256 $diffinfo{'to_id'} = $hash;
5257 if (defined $file_name) {
5258 $diffinfo{'status'} = '2';
5259 $diffinfo{'from_file'} = $file_parent;
5260 $diffinfo{'to_file'} = $file_name;
5261 } else { # no filename given
5262 $diffinfo{'status'} = '2';
5263 $diffinfo{'from_file'} = $hash_parent;
5264 $diffinfo{'to_file'} = $hash;
5268 open $fd, "-|", git_cmd
(), "diff", @diff_opts, '-p', "--full-index",
5269 ($format eq 'html' ?
"--raw" : ()), $from, $to, "--"
5270 or die_error
(500, "Open git-diff failed");
5273 if ($format eq 'html') {
5275 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5277 git_header_html
(undef, $expires);
5278 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5279 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5280 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5282 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5283 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5285 if (defined $file_name) {
5286 git_print_page_path
($file_name, "blob", $hash_base);
5288 print "<div class=\"page_path\"></div>\n";
5291 } elsif ($format eq 'plain') {
5292 my $patch_file_name = $file_name || $hash;
5294 -type
=> 'text/plain',
5295 -charset
=> 'utf-8',
5296 -expires
=> $expires,
5297 -content_disposition
=> 'inline; filename="' . "$patch_file_name" . '.patch"');
5299 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5302 die_error
(400, "Unknown blobdiff format");
5306 if ($format eq 'html') {
5307 print "<div class=\"page_body\">\n";
5309 git_patchset_body
($fd, [ \
%diffinfo ], undef, undef, $hash_base, $hash_parent_base);
5312 print "</div>\n"; # class="page_body"
5316 while (my $line = <$fd>) {
5317 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5318 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5322 last if $line =~ m!^\+\+\+!;
5330 sub git_blobdiff_plain
{
5331 git_blobdiff
('plain');
5334 sub git_commitdiff
{
5335 my $format = shift || 'html';
5336 $hash ||= $hash_base || "HEAD";
5337 my %co = parse_commit
($hash)
5338 or die_error
(404, "Unknown commit object");
5340 # choose format for commitdiff for merge
5341 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5342 $hash_parent = '--cc';
5344 # we need to prepare $formats_nav before almost any parameter munging
5346 if ($format eq 'html') {
5348 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5351 if (defined $hash_parent &&
5352 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5353 # commitdiff with two commits given
5354 my $hash_parent_short = $hash_parent;
5355 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5356 $hash_parent_short = substr($hash_parent, 0, 7);
5360 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5361 if ($co{'parents'}[$i] eq $hash_parent) {
5362 $formats_nav .= ' parent ' . ($i+1);
5366 $formats_nav .= ': ' .
5367 $cgi->a({-href
=> href
(action
=>"commitdiff",
5368 hash
=>$hash_parent)},
5369 esc_html
($hash_parent_short)) .
5371 } elsif (!$co{'parent'}) {
5373 $formats_nav .= ' (initial)';
5374 } elsif (scalar @
{$co{'parents'}} == 1) {
5375 # single parent commit
5378 $cgi->a({-href
=> href
(action
=>"commitdiff",
5379 hash
=>$co{'parent'})},
5380 esc_html
(substr($co{'parent'}, 0, 7))) .
5384 if ($hash_parent eq '--cc') {
5385 $formats_nav .= ' | ' .
5386 $cgi->a({-href
=> href
(action
=>"commitdiff",
5387 hash
=>$hash, hash_parent
=>'-c')},
5389 } else { # $hash_parent eq '-c'
5390 $formats_nav .= ' | ' .
5391 $cgi->a({-href
=> href
(action
=>"commitdiff",
5392 hash
=>$hash, hash_parent
=>'--cc')},
5398 $cgi->a({-href
=> href
(action
=>"commitdiff",
5400 esc_html
(substr($_, 0, 7)));
5401 } @
{$co{'parents'}} ) .
5406 my $hash_parent_param = $hash_parent;
5407 if (!defined $hash_parent_param) {
5408 # --cc for multiple parents, --root for parentless
5409 $hash_parent_param =
5410 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5416 if ($format eq 'html') {
5417 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5418 "--no-commit-id", "--patch-with-raw", "--full-index",
5419 $hash_parent_param, $hash, "--"
5420 or die_error
(500, "Open git-diff-tree failed");
5422 while (my $line = <$fd>) {
5424 # empty line ends raw part of diff-tree output
5426 push @difftree, scalar parse_difftree_raw_line
($line);
5429 } elsif ($format eq 'plain') {
5430 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5431 '-p', $hash_parent_param, $hash, "--"
5432 or die_error
(500, "Open git-diff-tree failed");
5435 die_error
(400, "Unknown commitdiff format");
5438 # non-textual hash id's can be cached
5440 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5444 # write commit message
5445 if ($format eq 'html') {
5446 my $refs = git_get_references
();
5447 my $ref = format_ref_marker
($refs, $co{'id'});
5449 git_header_html
(undef, $expires);
5450 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5451 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5452 git_print_authorship
(\
%co);
5453 print "<div class=\"page_body\">\n";
5454 if (@
{$co{'comment'}} > 1) {
5455 print "<div class=\"log\">\n";
5456 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5457 print "</div>\n"; # class="log"
5460 } elsif ($format eq 'plain') {
5461 my $refs = git_get_references
("tags");
5462 my $tagname = git_get_rev_name_tags
($hash);
5463 my $filename = basename
($project) . "-$hash.patch";
5466 -type
=> 'text/plain',
5467 -charset
=> 'utf-8',
5468 -expires
=> $expires,
5469 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5470 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5471 print "From: " . to_utf8
($co{'author'}) . "\n";
5472 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5473 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5475 print "X-Git-Tag: $tagname\n" if $tagname;
5476 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5478 foreach my $line (@
{$co{'comment'}}) {
5479 print to_utf8
($line) . "\n";
5485 if ($format eq 'html') {
5486 my $use_parents = !defined $hash_parent ||
5487 $hash_parent eq '-c' || $hash_parent eq '--cc';
5488 git_difftree_body
(\
@difftree, undef, undef, $hash,
5489 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5492 git_patchset_body
($fd, \
@difftree, undef, undef, $hash,
5493 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5495 print "</div>\n"; # class="page_body"
5498 } elsif ($format eq 'plain') {
5502 or print "Reading git-diff-tree failed\n";
5506 sub git_commitdiff_plain
{
5507 git_commitdiff
('plain');
5511 if (!defined $hash_base) {
5512 $hash_base = git_get_head_hash
($project);
5514 if (!defined $page) {
5518 my %co = parse_commit
($hash_base)
5519 or die_error
(404, "Unknown commit object");
5521 my $refs = git_get_references
();
5522 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5524 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5525 $file_name, "--full-history")
5526 or die_error
(404, "No such file or directory on given branch");
5528 if (!defined $hash && defined $file_name) {
5529 # some commits could have deleted file in question,
5530 # and not have it in tree, but one of them has to have it
5531 for (my $i = 0; $i <= @commitlist; $i++) {
5532 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5533 last if defined $hash;
5536 if (defined $hash) {
5537 $ftype = git_get_type
($hash);
5539 if (!defined $ftype) {
5540 die_error
(500, "Unknown type of object");
5543 my $paging_nav = '';
5546 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5547 file_name
=>$file_name)},
5549 $paging_nav .= " ⋅ " .
5550 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5551 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5553 $paging_nav .= "first";
5554 $paging_nav .= " ⋅ prev";
5557 if ($#commitlist >= 100) {
5559 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5560 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5561 $paging_nav .= " ⋅ $next_link";
5563 $paging_nav .= " ⋅ next";
5567 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5568 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5569 git_print_page_path
($file_name, $ftype, $hash_base);
5571 git_history_body
(\
@commitlist, 0, 99,
5572 $refs, $hash_base, $ftype, $next_link);
5578 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5579 if (!defined $searchtext) {
5580 die_error
(400, "Text field is empty");
5582 if (!defined $hash) {
5583 $hash = git_get_head_hash
($project);
5585 my %co = parse_commit
($hash);
5587 die_error
(404, "Unknown commit object");
5589 if (!defined $page) {
5593 $searchtype ||= 'commit';
5594 if ($searchtype eq 'pickaxe') {
5595 # pickaxe may take all resources of your box and run for several minutes
5596 # with every query - so decide by yourself how public you make this feature
5597 gitweb_check_feature
('pickaxe')
5598 or die_error
(403, "Pickaxe is disabled");
5600 if ($searchtype eq 'grep') {
5601 gitweb_check_feature
('grep')
5602 or die_error
(403, "Grep is disabled");
5607 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5609 if ($searchtype eq 'commit') {
5610 $greptype = "--grep=";
5611 } elsif ($searchtype eq 'author') {
5612 $greptype = "--author=";
5613 } elsif ($searchtype eq 'committer') {
5614 $greptype = "--committer=";
5616 $greptype .= $searchtext;
5617 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5618 $greptype, '--regexp-ignore-case',
5619 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5621 my $paging_nav = '';
5624 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5625 searchtext
=>$searchtext,
5626 searchtype
=>$searchtype)},
5628 $paging_nav .= " ⋅ " .
5629 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5630 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5632 $paging_nav .= "first";
5633 $paging_nav .= " ⋅ prev";
5636 if ($#commitlist >= 100) {
5638 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5639 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5640 $paging_nav .= " ⋅ $next_link";
5642 $paging_nav .= " ⋅ next";
5645 if ($#commitlist >= 100) {
5648 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5649 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5650 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5653 if ($searchtype eq 'pickaxe') {
5654 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5655 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5657 print "<table class=\"pickaxe search\">\n";
5660 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5661 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5662 ($search_use_regexp ?
'--pickaxe-regex' : ());
5665 while (my $line = <$fd>) {
5669 my %set = parse_difftree_raw_line
($line);
5670 if (defined $set{'commit'}) {
5671 # finish previous commit
5674 "<td class=\"link\">" .
5675 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5677 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5683 print "<tr class=\"dark\">\n";
5685 print "<tr class=\"light\">\n";
5688 %co = parse_commit
($set{'commit'});
5689 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5690 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5691 "<td><i>$author</i></td>\n" .
5693 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5694 -class => "list subject"},
5695 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5696 } elsif (defined $set{'to_id'}) {
5697 next if ($set{'to_id'} =~ m/^0{40}$/);
5699 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5700 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5702 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5708 # finish last commit (warning: repetition!)
5711 "<td class=\"link\">" .
5712 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5714 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5722 if ($searchtype eq 'grep') {
5723 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5724 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5726 print "<table class=\"grep_search\">\n";
5730 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5731 $search_use_regexp ?
('-E', '-i') : '-F',
5732 $searchtext, $co{'tree'};
5734 while (my $line = <$fd>) {
5736 my ($file, $lno, $ltext, $binary);
5737 last if ($matches++ > 1000);
5738 if ($line =~ /^Binary file (.+) matches$/) {
5742 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5744 if ($file ne $lastfile) {
5745 $lastfile and print "</td></tr>\n";
5747 print "<tr class=\"dark\">\n";
5749 print "<tr class=\"light\">\n";
5751 print "<td class=\"list\">".
5752 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5753 file_name
=>"$file"),
5754 -class => "list"}, esc_path
($file));
5755 print "</td><td>\n";
5759 print "<div class=\"binary\">Binary file</div>\n";
5761 $ltext = untabify
($ltext);
5762 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5763 $ltext = esc_html
($1, -nbsp
=>1);
5764 $ltext .= '<span class="match">';
5765 $ltext .= esc_html
($2, -nbsp
=>1);
5766 $ltext .= '</span>';
5767 $ltext .= esc_html
($3, -nbsp
=>1);
5769 $ltext = esc_html
($ltext, -nbsp
=>1);
5771 print "<div class=\"pre\">" .
5772 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5773 file_name
=>"$file").'#l'.$lno,
5774 -class => "linenr"}, sprintf('%4i', $lno))
5775 . ' ' . $ltext . "</div>\n";
5779 print "</td></tr>\n";
5780 if ($matches > 1000) {
5781 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5784 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5793 sub git_search_help
{
5795 git_print_page_nav
('','', $hash,$hash,$hash);
5797 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5798 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5799 the pattern entered is recognized as the POSIX extended
5800 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5803 <dt><b>commit</b></dt>
5804 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5806 my ($have_grep) = gitweb_check_feature
('grep');
5809 <dt><b>grep</b></dt>
5810 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5811 a different one) are searched for the given pattern. On large trees, this search can take
5812 a while and put some strain on the server, so please use it with some consideration. Note that
5813 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5814 case-sensitive.</dd>
5818 <dt><b>author</b></dt>
5819 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5820 <dt><b>committer</b></dt>
5821 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5823 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5824 if ($have_pickaxe) {
5826 <dt><b>pickaxe</b></dt>
5827 <dd>All commits that caused the string to appear or disappear from any file (changes that
5828 added, removed or "modified" the string) will be listed. This search can take a while and
5829 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5830 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5838 my $head = git_get_head_hash
($project);
5839 if (!defined $hash) {
5842 if (!defined $page) {
5845 my $refs = git_get_references
();
5847 my $commit_hash = $hash;
5848 if (defined $hash_parent) {
5849 $commit_hash = "$hash_parent..$hash";
5851 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5853 my $paging_nav = format_log_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5856 if ($#commitlist >= 100) {
5858 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5859 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5863 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5864 git_print_header_div
('summary', $project);
5866 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5871 ## ......................................................................
5872 ## feeds (RSS, Atom; OPML)
5875 my $format = shift || 'atom';
5876 my ($have_blame) = gitweb_check_feature
('blame');
5878 # Atom: http://www.atomenabled.org/developers/syndication/
5879 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5880 if ($format ne 'rss' && $format ne 'atom') {
5881 die_error
(400, "Unknown web feed format");
5884 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5885 my $head = $hash || 'HEAD';
5886 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5890 my $content_type = "application/$format+xml";
5891 if (defined $cgi->http('HTTP_ACCEPT') &&
5892 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5893 # browser (feed reader) prefers text/xml
5894 $content_type = 'text/xml';
5896 if (defined($commitlist[0])) {
5897 %latest_commit = %{$commitlist[0]};
5898 %latest_date = parse_date
($latest_commit{'author_epoch'});
5900 -type
=> $content_type,
5901 -charset
=> 'utf-8',
5902 -last_modified
=> $latest_date{'rfc2822'});
5905 -type
=> $content_type,
5906 -charset
=> 'utf-8');
5909 # Optimization: skip generating the body if client asks only
5910 # for Last-Modified date.
5911 return if ($cgi->request_method() eq 'HEAD');
5914 my $title = "$site_name - $project/$action";
5915 my $feed_type = 'log';
5916 if (defined $hash) {
5917 $title .= " - '$hash'";
5918 $feed_type = 'branch log';
5919 if (defined $file_name) {
5920 $title .= " :: $file_name";
5921 $feed_type = 'history';
5923 } elsif (defined $file_name) {
5924 $title .= " - $file_name";
5925 $feed_type = 'history';
5927 $title .= " $feed_type";
5928 my $descr = git_get_project_description
($project);
5929 if (defined $descr) {
5930 $descr = esc_html
($descr);
5932 $descr = "$project " .
5933 ($format eq 'rss' ?
'RSS' : 'Atom') .
5936 my $owner = git_get_project_owner
($project);
5937 $owner = esc_html
($owner);
5941 if (defined $file_name) {
5942 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5943 } elsif (defined $hash) {
5944 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5946 $alt_url = href
(-full
=>1, action
=>"summary");
5948 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5949 if ($format eq 'rss') {
5951 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5954 print "<title>$title</title>\n" .
5955 "<link>$alt_url</link>\n" .
5956 "<description>$descr</description>\n" .
5957 "<language>en</language>\n";
5958 } elsif ($format eq 'atom') {
5960 <feed xmlns="http://www.w3.org/2005/Atom">
5962 print "<title>$title</title>\n" .
5963 "<subtitle>$descr</subtitle>\n" .
5964 '<link rel="alternate" type="text/html" href="' .
5965 $alt_url . '" />' . "\n" .
5966 '<link rel="self" type="' . $content_type . '" href="' .
5967 $cgi->self_url() . '" />' . "\n" .
5968 "<id>" . href
(-full
=>1) . "</id>\n" .
5969 # use project owner for feed author
5970 '<author><name>'. email_obfuscate
($owner) . '</name></author>\n';
5971 if (defined $favicon) {
5972 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5974 if (defined $logo_url) {
5975 # not twice as wide as tall: 72 x 27 pixels
5976 print "<logo>" . esc_url
($logo) . "</logo>\n";
5978 if (! %latest_date) {
5979 # dummy date to keep the feed valid until commits trickle in:
5980 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5982 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5987 for (my $i = 0; $i <= $#commitlist; $i++) {
5988 my %co = %{$commitlist[$i]};
5989 my $commit = $co{'id'};
5990 # we read 150, we always show 30 and the ones more recent than 48 hours
5991 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5994 my %cd = parse_date
($co{'author_epoch'});
5996 # get list of changed files
5997 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5998 $co{'parent'} || "--root",
5999 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6001 my @difftree = map { chomp; $_ } <$fd>;
6005 # print element (entry, item)
6006 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6007 if ($format eq 'rss') {
6009 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6010 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6011 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6012 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6013 "<link>$co_url</link>\n" .
6014 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6015 "<content:encoded>" .
6017 } elsif ($format eq 'atom') {
6019 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6020 "<updated>$cd{'iso-8601'}</updated>\n" .
6022 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6023 if ($co{'author_email'}) {
6024 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6026 print "</author>\n" .
6027 # use committer for contributor
6029 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6030 if ($co{'committer_email'}) {
6031 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6033 print "</contributor>\n" .
6034 "<published>$cd{'iso-8601'}</published>\n" .
6035 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6036 "<id>$co_url</id>\n" .
6037 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6038 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6040 my $comment = $co{'comment'};
6042 foreach my $line (@
$comment) {
6043 $line = esc_html
($line);
6046 print "</pre><ul>\n";
6047 foreach my $difftree_line (@difftree) {
6048 my %difftree = parse_difftree_raw_line
($difftree_line);
6049 next if !$difftree{'from_id'};
6051 my $file = $difftree{'file'} || $difftree{'to_file'};
6055 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6056 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6057 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6058 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6059 -title
=> "diff"}, 'D');
6061 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6062 file_name
=>$file, hash_base
=>$commit), -class => "blamelink",
6063 -title
=> "blame"}, 'B');
6065 # if this is not a feed of a file history
6066 if (!defined $file_name || $file_name ne $file) {
6067 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6068 file_name
=>$file, hash
=>$commit),
6069 -title
=> "history"}, 'H');
6071 $file = esc_path
($file);
6075 if ($format eq 'rss') {
6076 print "</ul>]]>\n" .
6077 "</content:encoded>\n" .
6079 } elsif ($format eq 'atom') {
6080 print "</ul>\n</div>\n" .
6087 if ($format eq 'rss') {
6088 print "</channel>\n</rss>\n";
6089 } elsif ($format eq 'atom') {
6103 my @list = git_get_projects_list
();
6105 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6107 <?xml version="1.0" encoding="utf-8"?>
6108 <opml version="1.0">
6110 <title>$site_name OPML Export</title>
6113 <outline text="git RSS feeds">
6116 foreach my $pr (@list) {
6118 my $head = git_get_head_hash
($proj{'path'});
6119 if (!defined $head) {
6122 $git_dir = "$projectroot/$proj{'path'}";
6123 my %co = parse_commit
($head);
6128 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6129 my $rss = "$my_url?p=$proj{'path'};a=rss";
6130 my $html = "$my_url?p=$proj{'path'};a=summary";
6131 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";