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 # we make $path_info global because it's also used later on
33 my $path_info = $ENV{"PATH_INFO"};
35 $my_url =~ s
,\Q
$path_info\E
$,,;
36 $my_uri =~ s
,\Q
$path_info\E
$,,;
39 # core git executable to use
40 # this can just be "git" if your webserver has a sensible PATH
41 our $GIT = "++GIT_BINDIR++/git";
43 # absolute fs-path which will be prepended to the project path
44 #our $projectroot = "/pub/scm";
45 our $projectroot = "++GITWEB_PROJECTROOT++";
47 # fs traversing limit for getting project list
48 # the number is relative to the projectroot
49 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
51 # target of the home link on top of all pages
52 our $home_link = $my_uri || "/";
54 # string of the home link on top of all pages
55 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
57 # name of your site or organization to appear in page titles
58 # replace this with something more descriptive for clearer bookmarks
59 our $site_name = "++GITWEB_SITENAME++"
60 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
62 # filename of html text to include at top of each page
63 our $site_header = "++GITWEB_SITE_HEADER++";
64 # html text to include at home page
65 our $home_text = "++GITWEB_HOMETEXT++";
66 # filename of html text to include at bottom of each page
67 our $site_footer = "++GITWEB_SITE_FOOTER++";
70 our @stylesheets = ("++GITWEB_CSS++");
71 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
72 our $stylesheet = undef;
74 # URI of GIT logo (72x27 size)
75 our $logo = "++GITWEB_LOGO++";
76 # URI of GIT favicon, assumed to be image/png type
77 our $favicon = "++GITWEB_FAVICON++";
79 # URI and label (title) of GIT logo link
80 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
81 #our $logo_label = "git documentation";
82 our $logo_url = "http://git.or.cz/";
83 our $logo_label = "git homepage";
85 # source of projects list
86 our $projects_list = "++GITWEB_LIST++";
88 # the width (in characters) of the projects list "Description" column
89 our $projects_list_description_width = 25;
91 # default order of projects list
92 # valid values are none, project, descr, owner, and age
93 our $default_projects_order = "project";
95 # show repository only if this file exists
96 # (only effective if this variable evaluates to true)
97 our $export_ok = "++GITWEB_EXPORT_OK++";
99 # only allow viewing of repositories also shown on the overview page
100 our $strict_export = "++GITWEB_STRICT_EXPORT++";
102 # list of git base URLs used for URL to where fetch project from,
103 # i.e. full URL is "$git_base_url/$project"
104 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
106 # default blob_plain mimetype and default charset for text/plain blob
107 our $default_blob_plain_mimetype = 'text/plain';
108 our $default_text_plain_charset = undef;
110 # file to use for guessing MIME types before trying /etc/mime.types
111 # (relative to the current git repository)
112 our $mimetypes_file = undef;
114 # assume this charset if line contains non-UTF-8 characters;
115 # it should be valid encoding (see Encoding::Supported(3pm) for list),
116 # for which encoding all byte sequences are valid, for example
117 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
118 # could be even 'utf-8' for the old behavior)
119 our $fallback_encoding = 'latin1';
121 # rename detection options for git-diff and git-diff-tree
122 # - default is '-M', with the cost proportional to
123 # (number of removed files) * (number of new files).
124 # - more costly is '-C' (which implies '-M'), with the cost proportional to
125 # (number of changed files + number of removed files) * (number of new files)
126 # - even more costly is '-C', '--find-copies-harder' with cost
127 # (number of files in the original tree) * (number of new files)
128 # - one might want to include '-B' option, e.g. '-B', '-M'
129 our @diff_opts = ('-M'); # taken from git_commit
131 # information about snapshot formats that gitweb is capable of serving
132 our %known_snapshot_formats = (
134 # 'display' => display name,
135 # 'type' => mime type,
136 # 'suffix' => filename suffix,
137 # 'format' => --format for git-archive,
138 # 'compressor' => [compressor command and arguments]
139 # (array reference, optional)}
142 'display' => 'tar.gz',
143 'type' => 'application/x-gzip',
144 'suffix' => '.tar.gz',
146 'compressor' => ['gzip']},
149 'display' => 'tar.bz2',
150 'type' => 'application/x-bzip2',
151 'suffix' => '.tar.bz2',
153 'compressor' => ['bzip2']},
157 'type' => 'application/x-zip',
162 # Aliases so we understand old gitweb.snapshot values in repository
164 our %known_snapshot_format_aliases = (
168 # backward compatibility: legacy gitweb config support
169 'x-gzip' => undef, 'gz' => undef,
170 'x-bzip2' => undef, 'bz2' => undef,
171 'x-zip' => undef, '' => undef,
174 # You define site-wide feature defaults here; override them with
175 # $GITWEB_CONFIG as necessary.
178 # 'sub' => feature-sub (subroutine),
179 # 'override' => allow-override (boolean),
180 # 'default' => [ default options...] (array reference)}
182 # if feature is overridable (it means that allow-override has true value),
183 # then feature-sub will be called with default options as parameters;
184 # return value of feature-sub indicates if to enable specified feature
186 # if there is no 'sub' key (no feature-sub), then feature cannot be
189 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
191 # Enable the 'blame' blob view, showing the last commit that modified
192 # each line in the file. This can be very CPU-intensive.
194 # To enable system wide have in $GITWEB_CONFIG
195 # $feature{'blame'}{'default'} = [1];
196 # To have project specific config enable override in $GITWEB_CONFIG
197 # $feature{'blame'}{'override'} = 1;
198 # and in project config gitweb.blame = 0|1;
200 'sub' => \
&feature_blame
,
204 # Enable the 'snapshot' link, providing a compressed archive of any
205 # tree. This can potentially generate high traffic if you have large
208 # Value is a list of formats defined in %known_snapshot_formats that
210 # To disable system wide have in $GITWEB_CONFIG
211 # $feature{'snapshot'}{'default'} = [];
212 # To have project specific config enable override in $GITWEB_CONFIG
213 # $feature{'snapshot'}{'override'} = 1;
214 # and in project config, a comma-separated list of formats or "none"
215 # to disable. Example: gitweb.snapshot = tbz2,zip;
217 'sub' => \
&feature_snapshot
,
219 'default' => ['tgz']},
221 # Enable text search, which will list the commits which match author,
222 # committer or commit text to a given string. Enabled by default.
223 # Project specific override is not supported.
228 # Enable grep search, which will list the files in currently selected
229 # tree containing the given string. Enabled by default. This can be
230 # potentially CPU-intensive, of course.
232 # To enable system wide have in $GITWEB_CONFIG
233 # $feature{'grep'}{'default'} = [1];
234 # To have project specific config enable override in $GITWEB_CONFIG
235 # $feature{'grep'}{'override'} = 1;
236 # and in project config gitweb.grep = 0|1;
241 # Enable the pickaxe search, which will list the commits that modified
242 # a given string in a file. This can be practical and quite faster
243 # alternative to 'blame', but still potentially CPU-intensive.
245 # To enable system wide have in $GITWEB_CONFIG
246 # $feature{'pickaxe'}{'default'} = [1];
247 # To have project specific config enable override in $GITWEB_CONFIG
248 # $feature{'pickaxe'}{'override'} = 1;
249 # and in project config gitweb.pickaxe = 0|1;
251 'sub' => \
&feature_pickaxe
,
255 # Make gitweb use an alternative format of the URLs which can be
256 # more readable and natural-looking: project name is embedded
257 # directly in the path and the query string contains other
258 # auxiliary information. All gitweb installations recognize
259 # URL in either format; this configures in which formats gitweb
262 # To enable system wide have in $GITWEB_CONFIG
263 # $feature{'pathinfo'}{'default'} = [1];
264 # Project specific override is not supported.
266 # Note that you will need to change the default location of CSS,
267 # favicon, logo and possibly other files to an absolute URL. Also,
268 # if gitweb.cgi serves as your indexfile, you will need to force
269 # $my_uri to contain the script name in your $GITWEB_CONFIG.
274 # Make gitweb consider projects in project root subdirectories
275 # to be forks of existing projects. Given project $projname.git,
276 # projects matching $projname/*.git will not be shown in the main
277 # projects list, instead a '+' mark will be added to $projname
278 # there and a 'forks' view will be enabled for the project, listing
279 # all the forks. If project list is taken from a file, forks have
280 # to be listed after the main project.
282 # To enable system wide have in $GITWEB_CONFIG
283 # $feature{'forks'}{'default'} = [1];
284 # Project specific override is not supported.
289 # Insert custom links to the action bar of all project pages.
290 # This enables you mainly to link to third-party scripts integrating
291 # into gitweb; e.g. git-browser for graphical history representation
292 # or custom web-based repository administration interface.
294 # The 'default' value consists of a list of triplets in the form
295 # (label, link, position) where position is the label after which
296 # to insert the link and link is a format string where %n expands
297 # to the project name, %f to the project path within the filesystem,
298 # %h to the current hash (h gitweb parameter) and %b to the current
299 # hash base (hb gitweb parameter); %% expands to %.
301 # To enable system wide have in $GITWEB_CONFIG e.g.
302 # $feature{'actions'}{'default'} = [('graphiclog',
303 # '/git-browser/by-commit.html?r=%n', 'summary')];
304 # Project specific override is not supported.
309 # Allow gitweb scan project content tags described in ctags/
310 # of project repository, and display the popular Web 2.0-ish
311 # "tag cloud" near the project list. Note that this is something
312 # COMPLETELY different from the normal Git tags.
314 # gitweb by itself can show existing tags, but it does not handle
315 # tagging itself; you need an external application for that.
316 # For an example script, check Girocco's cgi/tagproj.cgi.
317 # You may want to install the HTML::TagCloud Perl module to get
318 # a pretty tag cloud instead of just a list of tags.
320 # To enable system wide have in $GITWEB_CONFIG
321 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
322 # Project specific override is not supported.
328 sub gitweb_check_feature
{
330 return unless exists $feature{$name};
331 my ($sub, $override, @defaults) = (
332 $feature{$name}{'sub'},
333 $feature{$name}{'override'},
334 @{$feature{$name}{'default'}});
335 if (!$override) { return @defaults; }
337 warn "feature $name is not overrideable";
340 return $sub->(@defaults);
344 my ($val) = git_get_project_config
('blame', '--bool');
346 if ($val eq 'true') {
348 } elsif ($val eq 'false') {
355 sub feature_snapshot
{
358 my ($val) = git_get_project_config
('snapshot');
361 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
368 my ($val) = git_get_project_config
('grep', '--bool');
370 if ($val eq 'true') {
372 } elsif ($val eq 'false') {
379 sub feature_pickaxe
{
380 my ($val) = git_get_project_config
('pickaxe', '--bool');
382 if ($val eq 'true') {
384 } elsif ($val eq 'false') {
391 # checking HEAD file with -e is fragile if the repository was
392 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
394 sub check_head_link
{
396 my $headfile = "$dir/HEAD";
397 return ((-e
$headfile) ||
398 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
401 sub check_export_ok
{
403 return (check_head_link
($dir) &&
404 (!$export_ok || -e
"$dir/$export_ok"));
407 # process alternate names for backward compatibility
408 # filter out unsupported (unknown) snapshot formats
409 sub filter_snapshot_fmts
{
413 exists $known_snapshot_format_aliases{$_} ?
414 $known_snapshot_format_aliases{$_} : $_} @fmts;
415 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
419 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
420 if (-e
$GITWEB_CONFIG) {
423 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
424 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
427 # version of the core git binary
428 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
430 $projects_list ||= $projectroot;
432 # ======================================================================
433 # input validation and dispatch
435 # input parameters can be collected from a variety of sources (presently, CGI
436 # and PATH_INFO), so we define an %input_params hash that collects them all
437 # together during validation: this allows subsequent uses (e.g. href()) to be
438 # agnostic of the parameter origin
440 my %input_params = ();
442 # input parameters are stored with the long parameter name as key. This will
443 # also be used in the href subroutine to convert parameters to their CGI
444 # equivalent, and since the href() usage is the most frequent one, we store
445 # the name -> CGI key mapping here, instead of the reverse.
447 # XXX: Warning: If you touch this, check the search form for updating,
450 my @cgi_param_mapping = (
458 hash_parent_base
=> "hpb",
463 snapshot_format
=> "sf",
464 extra_options
=> "opt",
465 search_use_regexp
=> "sr",
467 my %cgi_param_mapping = @cgi_param_mapping;
469 # we will also need to know the possible actions, for validation
471 "blame" => \
&git_blame
,
472 "blobdiff" => \
&git_blobdiff
,
473 "blobdiff_plain" => \
&git_blobdiff_plain
,
474 "blob" => \
&git_blob
,
475 "blob_plain" => \
&git_blob_plain
,
476 "commitdiff" => \
&git_commitdiff
,
477 "commitdiff_plain" => \
&git_commitdiff_plain
,
478 "commit" => \
&git_commit
,
479 "forks" => \
&git_forks
,
480 "heads" => \
&git_heads
,
481 "history" => \
&git_history
,
484 "atom" => \
&git_atom
,
485 "search" => \
&git_search
,
486 "search_help" => \
&git_search_help
,
487 "shortlog" => \
&git_shortlog
,
488 "summary" => \
&git_summary
,
490 "tags" => \
&git_tags
,
491 "tree" => \
&git_tree
,
492 "snapshot" => \
&git_snapshot
,
493 "object" => \
&git_object
,
494 # those below don't need $project
495 "opml" => \
&git_opml
,
496 "project_list" => \
&git_project_list
,
497 "project_index" => \
&git_project_index
,
500 # finally, we have the hash of allowed extra_options for the commands that
502 my %allowed_options = (
503 "--no-merges" => [ qw(rss atom log shortlog history) ],
506 # fill %input_params with the CGI parameters. All values except for 'opt'
507 # should be single values, but opt can be an array. We should probably
508 # build an array of parameters that can be multi-valued, but since for the time
509 # being it's only this one, we just single it out
510 while (my ($name, $symbol) = each %cgi_param_mapping) {
511 if ($symbol eq 'opt') {
512 $input_params{$name} = [ $cgi->param($symbol) ];
514 $input_params{$name} = $cgi->param($symbol);
518 # now read PATH_INFO and update the parameter list for missing parameters
519 sub evaluate_path_info
{
520 return if defined $input_params{'project'};
521 return if !$path_info;
522 $path_info =~ s
,^/+,,;
523 return if !$path_info;
525 # find which part of PATH_INFO is project
526 my $project = $path_info;
528 while ($project && !check_head_link
("$projectroot/$project")) {
529 $project =~ s
,/*[^/]*$,,;
531 return unless $project;
532 $input_params{'project'} = $project;
534 # do not change any parameters if an action is given using the query string
535 return if $input_params{'action'};
536 $path_info =~ s
,^\Q
$project\E
/*,,;
538 my ($refname, $pathname) = split(/:/, $path_info, 2);
539 if (defined $pathname) {
540 # we got "project.git/branch:filename" or "project.git/branch:dir/"
541 # we could use git_get_type(branch:pathname), but it needs $git_dir
542 $pathname =~ s
,^/+,,;
543 if (!$pathname || substr($pathname, -1) eq "/") {
544 $input_params{'action'} = "tree";
547 $input_params{'action'} = "blob_plain";
549 $input_params{'hash_base'} ||= $refname;
550 $input_params{'file_name'} ||= $pathname;
551 } elsif (defined $refname) {
552 # we got "project.git/branch"
553 $input_params{'action'} = "shortlog";
554 $input_params{'hash'} ||= $refname;
557 evaluate_path_info
();
559 our $action = $input_params{'action'};
560 if (defined $action) {
561 if (!validate_action
($action)) {
562 die_error
(400, "Invalid action parameter");
566 # parameters which are pathnames
567 our $project = $input_params{'project'};
568 if (defined $project) {
569 if (!validate_project
($project)) {
571 die_error
(404, "No such project");
575 our $file_name = $input_params{'file_name'};
576 if (defined $file_name) {
577 if (!validate_pathname
($file_name)) {
578 die_error
(400, "Invalid file parameter");
582 our $file_parent = $input_params{'file_parent'};
583 if (defined $file_parent) {
584 if (!validate_pathname
($file_parent)) {
585 die_error
(400, "Invalid file parent parameter");
589 # parameters which are refnames
590 our $hash = $input_params{'hash'};
592 if (!validate_refname
($hash)) {
593 die_error
(400, "Invalid hash parameter");
597 our $hash_parent = $input_params{'hash_parent'};
598 if (defined $hash_parent) {
599 if (!validate_refname
($hash_parent)) {
600 die_error
(400, "Invalid hash parent parameter");
604 our $hash_base = $input_params{'hash_base'};
605 if (defined $hash_base) {
606 if (!validate_refname
($hash_base)) {
607 die_error
(400, "Invalid hash base parameter");
611 our @extra_options = @{$input_params{'extra_options'}};
612 # @extra_options is always defined, since it can only be (currently) set from
613 # CGI, and $cgi->param() returns the empty array in array context if the param
615 foreach my $opt (@extra_options) {
616 if (not exists $allowed_options{$opt}) {
617 die_error
(400, "Invalid option parameter");
619 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
620 die_error
(400, "Invalid option parameter for this action");
624 our $hash_parent_base = $input_params{'hash_parent_base'};
625 if (defined $hash_parent_base) {
626 if (!validate_refname
($hash_parent_base)) {
627 die_error
(400, "Invalid hash parent base parameter");
632 our $page = $input_params{'page'};
634 if ($page =~ m/[^0-9]/) {
635 die_error
(400, "Invalid page parameter");
639 our $searchtype = $input_params{'searchtype'};
640 if (defined $searchtype) {
641 if ($searchtype =~ m/[^a-z]/) {
642 die_error
(400, "Invalid searchtype parameter");
646 our $search_use_regexp = $input_params{'search_use_regexp'};
648 our $searchtext = $input_params{'searchtext'};
650 if (defined $searchtext) {
651 if (length($searchtext) < 2) {
652 die_error
(403, "At least two characters are required for search parameter");
654 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
657 # path to the current git repository
659 $git_dir = "$projectroot/$project" if $project;
662 if (!defined $action) {
664 $action = git_get_type
($hash);
665 } elsif (defined $hash_base && defined $file_name) {
666 $action = git_get_type
("$hash_base:$file_name");
667 } elsif (defined $project) {
670 $action = 'project_list';
673 if (!defined($actions{$action})) {
674 die_error
(400, "Unknown action");
676 if ($action !~ m/^(opml|project_list|project_index)$/ &&
678 die_error
(400, "Project needed");
680 $actions{$action}->();
683 ## ======================================================================
688 # default is to use -absolute url() i.e. $my_uri
689 my $href = $params{-full
} ? $my_url : $my_uri;
691 $params{'project'} = $project unless exists $params{'project'};
693 if ($params{-replay
}) {
694 while (my ($name, $symbol) = each %cgi_param_mapping) {
695 if (!exists $params{$name}) {
696 $params{$name} = $input_params{$name};
701 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
703 # use PATH_INFO for project name
704 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
705 delete $params{'project'};
707 # Summary just uses the project path URL
708 if (defined $params{'action'} && $params{'action'} eq 'summary') {
709 delete $params{'action'};
713 # now encode the parameters explicitly
715 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
716 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
717 if (defined $params{$name}) {
718 if (ref($params{$name}) eq "ARRAY") {
719 foreach my $par (@{$params{$name}}) {
720 push @result, $symbol . "=" . esc_param
($par);
723 push @result, $symbol . "=" . esc_param
($params{$name});
727 $href .= "?" . join(';', @result) if scalar @result;
733 ## ======================================================================
734 ## validation, quoting/unquoting and escaping
736 sub validate_action
{
737 my $input = shift || return undef;
738 return undef unless exists $actions{$input};
742 sub validate_project
{
743 my $input = shift || return undef;
744 if (!validate_pathname
($input) ||
745 !(-d
"$projectroot/$input") ||
746 !check_head_link
("$projectroot/$input") ||
747 ($export_ok && !(-e
"$projectroot/$input/$export_ok")) ||
748 ($strict_export && !project_in_list
($input))) {
755 sub validate_pathname
{
756 my $input = shift || return undef;
758 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
759 # at the beginning, at the end, and between slashes.
760 # also this catches doubled slashes
761 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
765 if ($input =~ m!\0!) {
771 sub validate_refname
{
772 my $input = shift || return undef;
774 # textual hashes are O.K.
775 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
778 # it must be correct pathname
779 $input = validate_pathname
($input)
781 # restrictions on ref name according to git-check-ref-format
782 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
788 # decode sequences of octets in utf8 into Perl's internal form,
789 # which is utf-8 with utf8 flag set if needed. gitweb writes out
790 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
793 if (utf8
::valid
($str)) {
797 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
801 # quote unsafe chars, but keep the slash, even when it's not
802 # correct, but quoted slashes look too horrible in bookmarks
805 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
811 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
814 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
820 # replace invalid utf8 character with SUBSTITUTION sequence
825 $str = to_utf8
($str);
826 $str = $cgi->escapeHTML($str);
827 if ($opts{'-nbsp'}) {
828 $str =~ s/ / /g;
830 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
834 # quote control characters and escape filename to HTML
839 $str = to_utf8
($str);
840 $str = $cgi->escapeHTML($str);
841 if ($opts{'-nbsp'}) {
842 $str =~ s/ / /g;
844 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
848 # Make control characters "printable", using character escape codes (CEC)
852 my %es = ( # character escape codes, aka escape sequences
853 "\t" => '\t', # tab (HT)
854 "\n" => '\n', # line feed (LF)
855 "\r" => '\r', # carrige return (CR)
856 "\f" => '\f', # form feed (FF)
857 "\b" => '\b', # backspace (BS)
858 "\a" => '\a', # alarm (bell) (BEL)
859 "\e" => '\e', # escape (ESC)
860 "\013" => '\v', # vertical tab (VT)
861 "\000" => '\0', # nul character (NUL)
863 my $chr = ( (exists $es{$cntrl})
865 : sprintf('\%2x', ord($cntrl)) );
866 if ($opts{-nohtml
}) {
869 return "<span class=\"cntrl\">$chr</span>";
873 # Alternatively use unicode control pictures codepoints,
874 # Unicode "printable representation" (PR)
879 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
880 if ($opts{-nohtml
}) {
883 return "<span class=\"cntrl\">$chr</span>";
887 # git may return quoted and escaped filenames
893 my %es = ( # character escape codes, aka escape sequences
894 't' => "\t", # tab (HT, TAB)
895 'n' => "\n", # newline (NL)
896 'r' => "\r", # return (CR)
897 'f' => "\f", # form feed (FF)
898 'b' => "\b", # backspace (BS)
899 'a' => "\a", # alarm (bell) (BEL)
900 'e' => "\e", # escape (ESC)
901 'v' => "\013", # vertical tab (VT)
904 if ($seq =~ m/^[0-7]{1,3}$/) {
905 # octal char sequence
906 return chr(oct($seq));
907 } elsif (exists $es{$seq}) {
908 # C escape sequence, aka character escape code
911 # quoted ordinary character
915 if ($str =~ m/^"(.*)"$/) {
918 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
923 # escape tabs (convert tabs to spaces)
927 while ((my $pos = index($line, "\t")) != -1) {
928 if (my $count = (8 - ($pos % 8))) {
929 my $spaces = ' ' x
$count;
930 $line =~ s/\t/$spaces/;
937 sub project_in_list
{
939 my @list = git_get_projects_list
();
940 return @list && scalar(grep { $_->{'path'} eq $project } @list);
943 ## ----------------------------------------------------------------------
944 ## HTML aware string manipulation
946 # Try to chop given string on a word boundary between position
947 # $len and $len+$add_len. If there is no word boundary there,
948 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
949 # (marking chopped part) would be longer than given string.
953 my $add_len = shift || 10;
954 my $where = shift || 'right'; # 'left' | 'center' | 'right'
956 # Make sure perl knows it is utf8 encoded so we don't
957 # cut in the middle of a utf8 multibyte char.
958 $str = to_utf8
($str);
960 # allow only $len chars, but don't cut a word if it would fit in $add_len
961 # if it doesn't fit, cut it if it's still longer than the dots we would add
962 # remove chopped character entities entirely
964 # when chopping in the middle, distribute $len into left and right part
965 # return early if chopping wouldn't make string shorter
966 if ($where eq 'center') {
967 return $str if ($len + 5 >= length($str)); # filler is length 5
970 return $str if ($len + 4 >= length($str)); # filler is length 4
973 # regexps: ending and beginning with word part up to $add_len
974 my $endre = qr/.{$len}\w{0,$add_len}/;
975 my $begre = qr/\w{0,$add_len}.{$len}/;
977 if ($where eq 'left') {
978 $str =~ m/^(.*?)($begre)$/;
979 my ($lead, $body) = ($1, $2);
980 if (length($lead) > 4) {
981 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
986 } elsif ($where eq 'center') {
987 $str =~ m/^($endre)(.*)$/;
988 my ($left, $str) = ($1, $2);
989 $str =~ m/^(.*?)($begre)$/;
990 my ($mid, $right) = ($1, $2);
991 if (length($mid) > 5) {
992 $left =~ s/&[^;]*$//;
993 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
996 return "$left$mid$right";
999 $str =~ m/^($endre)(.*)$/;
1002 if (length($tail) > 4) {
1003 $body =~ s/&[^;]*$//;
1006 return "$body$tail";
1010 # takes the same arguments as chop_str, but also wraps a <span> around the
1011 # result with a title attribute if it does get chopped. Additionally, the
1012 # string is HTML-escaped.
1013 sub chop_and_escape_str
{
1016 my $chopped = chop_str
(@_);
1017 if ($chopped eq $str) {
1018 return esc_html
($chopped);
1020 $str =~ s/([[:cntrl:]])/?/g;
1021 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1025 ## ----------------------------------------------------------------------
1026 ## functions returning short strings
1028 # CSS class for given age value (in seconds)
1032 if (!defined $age) {
1034 } elsif ($age < 60*60*2) {
1036 } elsif ($age < 60*60*24*2) {
1043 # convert age in seconds to "nn units ago" string
1048 if ($age > 60*60*24*365*2) {
1049 $age_str = (int $age/60/60/24/365);
1050 $age_str .= " years ago";
1051 } elsif ($age > 60*60*24*(365/12)*2) {
1052 $age_str = int $age/60/60/24/(365/12);
1053 $age_str .= " months ago";
1054 } elsif ($age > 60*60*24*7*2) {
1055 $age_str = int $age/60/60/24/7;
1056 $age_str .= " weeks ago";
1057 } elsif ($age > 60*60*24*2) {
1058 $age_str = int $age/60/60/24;
1059 $age_str .= " days ago";
1060 } elsif ($age > 60*60*2) {
1061 $age_str = int $age/60/60;
1062 $age_str .= " hours ago";
1063 } elsif ($age > 60*2) {
1064 $age_str = int $age/60;
1065 $age_str .= " min ago";
1066 } elsif ($age > 2) {
1067 $age_str = int $age;
1068 $age_str .= " sec ago";
1070 $age_str .= " right now";
1076 S_IFINVALID
=> 0030000,
1077 S_IFGITLINK
=> 0160000,
1080 # submodule/subproject, a commit object reference
1081 sub S_ISGITLINK
($) {
1084 return (($mode & S_IFMT
) == S_IFGITLINK
)
1087 # convert file mode in octal to symbolic file mode string
1089 my $mode = oct shift;
1091 if (S_ISGITLINK
($mode)) {
1092 return 'm---------';
1093 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1094 return 'drwxr-xr-x';
1095 } elsif (S_ISLNK
($mode)) {
1096 return 'lrwxrwxrwx';
1097 } elsif (S_ISREG
($mode)) {
1098 # git cares only about the executable bit
1099 if ($mode & S_IXUSR
) {
1100 return '-rwxr-xr-x';
1102 return '-rw-r--r--';
1105 return '----------';
1109 # convert file mode in octal to file type string
1113 if ($mode !~ m/^[0-7]+$/) {
1119 if (S_ISGITLINK
($mode)) {
1121 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1123 } elsif (S_ISLNK
($mode)) {
1125 } elsif (S_ISREG
($mode)) {
1132 # convert file mode in octal to file type description string
1133 sub file_type_long
{
1136 if ($mode !~ m/^[0-7]+$/) {
1142 if (S_ISGITLINK
($mode)) {
1144 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1146 } elsif (S_ISLNK
($mode)) {
1148 } elsif (S_ISREG
($mode)) {
1149 if ($mode & S_IXUSR
) {
1150 return "executable";
1160 ## ----------------------------------------------------------------------
1161 ## functions returning short HTML fragments, or transforming HTML fragments
1162 ## which don't belong to other sections
1164 # format line of commit message.
1165 sub format_log_line_html
{
1168 $line = esc_html
($line, -nbsp
=>1);
1169 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1172 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1173 -class => "text"}, $hash_text);
1174 $line =~ s/$hash_text/$link/;
1179 # format marker of refs pointing to given object
1181 # the destination action is chosen based on object type and current context:
1182 # - for annotated tags, we choose the tag view unless it's the current view
1183 # already, in which case we go to shortlog view
1184 # - for other refs, we keep the current view if we're in history, shortlog or
1185 # log view, and select shortlog otherwise
1186 sub format_ref_marker
{
1187 my ($refs, $id) = @_;
1190 if (defined $refs->{$id}) {
1191 foreach my $ref (@{$refs->{$id}}) {
1192 # this code exploits the fact that non-lightweight tags are the
1193 # only indirect objects, and that they are the only objects for which
1194 # we want to use tag instead of shortlog as action
1195 my ($type, $name) = qw();
1196 my $indirect = ($ref =~ s/\^\{\}$//);
1197 # e.g. tags/v2.6.11 or heads/next
1198 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1207 $class .= " indirect" if $indirect;
1209 my $dest_action = "shortlog";
1212 $dest_action = "tag" unless $action eq "tag";
1213 } elsif ($action =~ /^(history|(short)?log)$/) {
1214 $dest_action = $action;
1218 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1221 my $link = $cgi->a({
1223 action
=>$dest_action,
1227 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1233 return ' <span class="refs">'. $markers . '</span>';
1239 # format, perhaps shortened and with markers, title line
1240 sub format_subject_html
{
1241 my ($long, $short, $href, $extra) = @_;
1242 $extra = '' unless defined($extra);
1244 if (length($short) < length($long)) {
1245 return $cgi->a({-href
=> $href, -class => "list subject",
1246 -title
=> to_utf8
($long)},
1247 esc_html
($short) . $extra);
1249 return $cgi->a({-href
=> $href, -class => "list subject"},
1250 esc_html
($long) . $extra);
1254 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1255 sub format_git_diff_header_line
{
1257 my $diffinfo = shift;
1258 my ($from, $to) = @_;
1260 if ($diffinfo->{'nparents'}) {
1262 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1263 if ($to->{'href'}) {
1264 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1265 esc_path
($to->{'file'}));
1266 } else { # file was deleted (no href)
1267 $line .= esc_path
($to->{'file'});
1271 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1272 if ($from->{'href'}) {
1273 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1274 'a/' . esc_path
($from->{'file'}));
1275 } else { # file was added (no href)
1276 $line .= 'a/' . esc_path
($from->{'file'});
1279 if ($to->{'href'}) {
1280 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1281 'b/' . esc_path
($to->{'file'}));
1282 } else { # file was deleted
1283 $line .= 'b/' . esc_path
($to->{'file'});
1287 return "<div class=\"diff header\">$line</div>\n";
1290 # format extended diff header line, before patch itself
1291 sub format_extended_diff_header_line
{
1293 my $diffinfo = shift;
1294 my ($from, $to) = @_;
1297 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1298 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1299 esc_path
($from->{'file'}));
1301 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1302 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1303 esc_path
($to->{'file'}));
1305 # match single <mode>
1306 if ($line =~ m/\s(\d{6})$/) {
1307 $line .= '<span class="info"> (' .
1308 file_type_long
($1) .
1312 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1313 # can match only for combined diff
1315 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1316 if ($from->{'href'}[$i]) {
1317 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1319 substr($diffinfo->{'from_id'}[$i],0,7));
1324 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1327 if ($to->{'href'}) {
1328 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1329 substr($diffinfo->{'to_id'},0,7));
1334 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1335 # can match only for ordinary diff
1336 my ($from_link, $to_link);
1337 if ($from->{'href'}) {
1338 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1339 substr($diffinfo->{'from_id'},0,7));
1341 $from_link = '0' x
7;
1343 if ($to->{'href'}) {
1344 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1345 substr($diffinfo->{'to_id'},0,7));
1349 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1350 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1353 return $line . "<br/>\n";
1356 # format from-file/to-file diff header
1357 sub format_diff_from_to_header
{
1358 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1363 #assert($line =~ m/^---/) if DEBUG;
1364 # no extra formatting for "^--- /dev/null"
1365 if (! $diffinfo->{'nparents'}) {
1366 # ordinary (single parent) diff
1367 if ($line =~ m!^--- "?a/!) {
1368 if ($from->{'href'}) {
1370 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1371 esc_path
($from->{'file'}));
1374 esc_path
($from->{'file'});
1377 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1380 # combined diff (merge commit)
1381 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1382 if ($from->{'href'}[$i]) {
1384 $cgi->a({-href
=>href
(action
=>"blobdiff",
1385 hash_parent
=>$diffinfo->{'from_id'}[$i],
1386 hash_parent_base
=>$parents[$i],
1387 file_parent
=>$from->{'file'}[$i],
1388 hash
=>$diffinfo->{'to_id'},
1390 file_name
=>$to->{'file'}),
1392 -title
=>"diff" . ($i+1)},
1395 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1396 esc_path
($from->{'file'}[$i]));
1398 $line = '--- /dev/null';
1400 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1405 #assert($line =~ m/^\+\+\+/) if DEBUG;
1406 # no extra formatting for "^+++ /dev/null"
1407 if ($line =~ m!^\+\+\+ "?b/!) {
1408 if ($to->{'href'}) {
1410 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1411 esc_path
($to->{'file'}));
1414 esc_path
($to->{'file'});
1417 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1422 # create note for patch simplified by combined diff
1423 sub format_diff_cc_simplified
{
1424 my ($diffinfo, @parents) = @_;
1427 $result .= "<div class=\"diff header\">" .
1429 if (!is_deleted
($diffinfo)) {
1430 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1432 hash
=>$diffinfo->{'to_id'},
1433 file_name
=>$diffinfo->{'to_file'}),
1435 esc_path
($diffinfo->{'to_file'}));
1437 $result .= esc_path
($diffinfo->{'to_file'});
1439 $result .= "</div>\n" . # class="diff header"
1440 "<div class=\"diff nodifferences\">" .
1442 "</div>\n"; # class="diff nodifferences"
1447 # format patch (diff) line (not to be used for diff headers)
1448 sub format_diff_line
{
1450 my ($from, $to) = @_;
1451 my $diff_class = "";
1455 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1457 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1458 if ($line =~ m/^\@{3}/) {
1459 $diff_class = " chunk_header";
1460 } elsif ($line =~ m/^\\/) {
1461 $diff_class = " incomplete";
1462 } elsif ($prefix =~ tr/+/+/) {
1463 $diff_class = " add";
1464 } elsif ($prefix =~ tr/-/-/) {
1465 $diff_class = " rem";
1468 # assume ordinary diff
1469 my $char = substr($line, 0, 1);
1471 $diff_class = " add";
1472 } elsif ($char eq '-') {
1473 $diff_class = " rem";
1474 } elsif ($char eq '@') {
1475 $diff_class = " chunk_header";
1476 } elsif ($char eq "\\") {
1477 $diff_class = " incomplete";
1480 $line = untabify
($line);
1481 if ($from && $to && $line =~ m/^\@{2} /) {
1482 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1483 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1485 $from_lines = 0 unless defined $from_lines;
1486 $to_lines = 0 unless defined $to_lines;
1488 if ($from->{'href'}) {
1489 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1490 -class=>"list"}, $from_text);
1492 if ($to->{'href'}) {
1493 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1494 -class=>"list"}, $to_text);
1496 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1497 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1498 return "<div class=\"diff$diff_class\">$line</div>\n";
1499 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1500 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1501 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1503 @from_text = split(' ', $ranges);
1504 for (my $i = 0; $i < @from_text; ++$i) {
1505 ($from_start[$i], $from_nlines[$i]) =
1506 (split(',', substr($from_text[$i], 1)), 0);
1509 $to_text = pop @from_text;
1510 $to_start = pop @from_start;
1511 $to_nlines = pop @from_nlines;
1513 $line = "<span class=\"chunk_info\">$prefix ";
1514 for (my $i = 0; $i < @from_text; ++$i) {
1515 if ($from->{'href'}[$i]) {
1516 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1517 -class=>"list"}, $from_text[$i]);
1519 $line .= $from_text[$i];
1523 if ($to->{'href'}) {
1524 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1525 -class=>"list"}, $to_text);
1529 $line .= " $prefix</span>" .
1530 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1531 return "<div class=\"diff$diff_class\">$line</div>\n";
1533 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1536 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1537 # linked. Pass the hash of the tree/commit to snapshot.
1538 sub format_snapshot_links
{
1540 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1541 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1542 my $num_fmts = @snapshot_fmts;
1543 if ($num_fmts > 1) {
1544 # A parenthesized list of links bearing format names.
1545 # e.g. "snapshot (_tar.gz_ _zip_)"
1546 return "snapshot (" . join(' ', map
1553 }, $known_snapshot_formats{$_}{'display'})
1554 , @snapshot_fmts) . ")";
1555 } elsif ($num_fmts == 1) {
1556 # A single "snapshot" link whose tooltip bears the format name.
1558 my ($fmt) = @snapshot_fmts;
1564 snapshot_format
=>$fmt
1566 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1568 } else { # $num_fmts == 0
1573 ## ......................................................................
1574 ## functions returning values to be passed, perhaps after some
1575 ## transformation, to other functions; e.g. returning arguments to href()
1577 # returns hash to be passed to href to generate gitweb URL
1578 # in -title key it returns description of link
1580 my $format = shift || 'Atom';
1581 my %res = (action
=> lc($format));
1583 # feed links are possible only for project views
1584 return unless (defined $project);
1585 # some views should link to OPML, or to generic project feed,
1586 # or don't have specific feed yet (so they should use generic)
1587 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1590 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1591 # from tag links; this also makes possible to detect branch links
1592 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1593 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1596 # find log type for feed description (title)
1598 if (defined $file_name) {
1599 $type = "history of $file_name";
1600 $type .= "/" if ($action eq 'tree');
1601 $type .= " on '$branch'" if (defined $branch);
1603 $type = "log of $branch" if (defined $branch);
1606 $res{-title
} = $type;
1607 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1608 $res{'file_name'} = $file_name;
1613 ## ----------------------------------------------------------------------
1614 ## git utility subroutines, invoking git commands
1616 # returns path to the core git executable and the --git-dir parameter as list
1618 return $GIT, '--git-dir='.$git_dir;
1621 # quote the given arguments for passing them to the shell
1622 # quote_command("command", "arg 1", "arg with ' and ! characters")
1623 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1624 # Try to avoid using this function wherever possible.
1627 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1630 # get HEAD ref of given project as hash
1631 sub git_get_head_hash
{
1632 my $project = shift;
1633 my $o_git_dir = $git_dir;
1635 $git_dir = "$projectroot/$project";
1636 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1639 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1643 if (defined $o_git_dir) {
1644 $git_dir = $o_git_dir;
1649 # get type of given object
1653 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1655 close $fd or return;
1660 # repository configuration
1661 our $config_file = '';
1664 # store multiple values for single key as anonymous array reference
1665 # single values stored directly in the hash, not as [ <value> ]
1666 sub hash_set_multi
{
1667 my ($hash, $key, $value) = @_;
1669 if (!exists $hash->{$key}) {
1670 $hash->{$key} = $value;
1671 } elsif (!ref $hash->{$key}) {
1672 $hash->{$key} = [ $hash->{$key}, $value ];
1674 push @{$hash->{$key}}, $value;
1678 # return hash of git project configuration
1679 # optionally limited to some section, e.g. 'gitweb'
1680 sub git_parse_project_config
{
1681 my $section_regexp = shift;
1686 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1689 while (my $keyval = <$fh>) {
1691 my ($key, $value) = split(/\n/, $keyval, 2);
1693 hash_set_multi
(\
%config, $key, $value)
1694 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1701 # convert config value to boolean, 'true' or 'false'
1702 # no value, number > 0, 'true' and 'yes' values are true
1703 # rest of values are treated as false (never as error)
1704 sub config_to_bool
{
1707 # strip leading and trailing whitespace
1711 return (!defined $val || # section.key
1712 ($val =~ /^\d+$/ && $val) || # section.key = 1
1713 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1716 # convert config value to simple decimal number
1717 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1718 # to be multiplied by 1024, 1048576, or 1073741824
1722 # strip leading and trailing whitespace
1726 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1728 # unknown unit is treated as 1
1729 return $num * ($unit eq 'g' ? 1073741824 :
1730 $unit eq 'm' ? 1048576 :
1731 $unit eq 'k' ? 1024 : 1);
1736 # convert config value to array reference, if needed
1737 sub config_to_multi
{
1740 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1743 sub git_get_project_config
{
1744 my ($key, $type) = @_;
1747 return unless ($key);
1748 $key =~ s/^gitweb\.//;
1749 return if ($key =~ m/\W/);
1752 if (defined $type) {
1755 unless ($type eq 'bool' || $type eq 'int');
1759 if (!defined $config_file ||
1760 $config_file ne "$git_dir/config") {
1761 %config = git_parse_project_config
('gitweb');
1762 $config_file = "$git_dir/config";
1766 if (!defined $type) {
1767 return $config{"gitweb.$key"};
1768 } elsif ($type eq 'bool') {
1769 # backward compatibility: 'git config --bool' returns true/false
1770 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1771 } elsif ($type eq 'int') {
1772 return config_to_int
($config{"gitweb.$key"});
1774 return $config{"gitweb.$key"};
1777 # get hash of given path at given ref
1778 sub git_get_hash_by_path
{
1780 my $path = shift || return undef;
1785 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1786 or die_error
(500, "Open git-ls-tree failed");
1788 close $fd or return undef;
1790 if (!defined $line) {
1791 # there is no tree or hash given by $path at $base
1795 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1796 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1797 if (defined $type && $type ne $2) {
1798 # type doesn't match
1804 # get path of entry with given hash at given tree-ish (ref)
1805 # used to get 'from' filename for combined diff (merge commit) for renames
1806 sub git_get_path_by_hash
{
1807 my $base = shift || return;
1808 my $hash = shift || return;
1812 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1814 while (my $line = <$fd>) {
1817 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1818 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1819 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1828 ## ......................................................................
1829 ## git utility functions, directly accessing git repository
1831 sub git_get_project_description
{
1834 $git_dir = "$projectroot/$path";
1835 open my $fd, "$git_dir/description"
1836 or return git_get_project_config
('description');
1839 if (defined $descr) {
1845 sub git_get_project_ctags
{
1849 $git_dir = "$projectroot/$path";
1850 foreach (<$git_dir/ctags/*>) {
1851 open CT
, $_ or next;
1855 my $ctag = $_; $ctag =~ s
#.*/##;
1856 $ctags->{$ctag} = $val;
1861 sub git_populate_project_tagcloud
{
1864 # First, merge different-cased tags; tags vote on casing
1866 foreach (keys %$ctags) {
1867 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
1868 if (not $ctags_lc{lc $_}->{topcount
}
1869 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
1870 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
1871 $ctags_lc{lc $_}->{topname
} = $_;
1876 if (eval { require HTML
::TagCloud
; 1; }) {
1877 $cloud = HTML
::TagCloud-
>new;
1878 foreach (sort keys %ctags_lc) {
1879 # Pad the title with spaces so that the cloud looks
1881 my $title = $ctags_lc{$_}->{topname
};
1882 $title =~ s/ / /g;
1883 $title =~ s/^/ /g;
1884 $title =~ s/$/ /g;
1885 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
1888 $cloud = \
%ctags_lc;
1893 sub git_show_project_tagcloud
{
1894 my ($cloud, $count) = @_;
1895 print STDERR
ref($cloud)."..\n";
1896 if (ref $cloud eq 'HTML::TagCloud') {
1897 return $cloud->html_and_css($count);
1899 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
1900 return '<p align="center">' . join (', ', map {
1901 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
1902 } splice(@tags, 0, $count)) . '</p>';
1906 sub git_get_project_url_list
{
1909 $git_dir = "$projectroot/$path";
1910 open my $fd, "$git_dir/cloneurl"
1911 or return wantarray ?
1912 @{ config_to_multi
(git_get_project_config
('url')) } :
1913 config_to_multi
(git_get_project_config
('url'));
1914 my @git_project_url_list = map { chomp; $_ } <$fd>;
1917 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1920 sub git_get_projects_list
{
1925 $filter =~ s/\.git$//;
1927 my ($check_forks) = gitweb_check_feature
('forks');
1929 if (-d
$projects_list) {
1930 # search in directory
1931 my $dir = $projects_list . ($filter ? "/$filter" : '');
1932 # remove the trailing "/"
1934 my $pfxlen = length("$dir");
1935 my $pfxdepth = ($dir =~ tr!/!!);
1938 follow_fast
=> 1, # follow symbolic links
1939 follow_skip
=> 2, # ignore duplicates
1940 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1942 # skip project-list toplevel, if we get it.
1943 return if (m!^[/.]$!);
1944 # only directories can be git repositories
1945 return unless (-d
$_);
1946 # don't traverse too deep (Find is super slow on os x)
1947 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1948 $File::Find
::prune
= 1;
1952 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1953 # we check related file in $projectroot
1954 if (check_export_ok
("$projectroot/$filter/$subdir")) {
1955 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1956 $File::Find
::prune
= 1;
1961 } elsif (-f
$projects_list) {
1962 # read from file(url-encoded):
1963 # 'git%2Fgit.git Linus+Torvalds'
1964 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1965 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1967 open my ($fd), $projects_list or return;
1969 while (my $line = <$fd>) {
1971 my ($path, $owner) = split ' ', $line;
1972 $path = unescape
($path);
1973 $owner = unescape
($owner);
1974 if (!defined $path) {
1977 if ($filter ne '') {
1978 # looking for forks;
1979 my $pfx = substr($path, 0, length($filter));
1980 if ($pfx ne $filter) {
1983 my $sfx = substr($path, length($filter));
1984 if ($sfx !~ /^\/.*\
.git
$/) {
1987 } elsif ($check_forks) {
1989 foreach my $filter (keys %paths) {
1990 # looking for forks;
1991 my $pfx = substr($path, 0, length($filter));
1992 if ($pfx ne $filter) {
1995 my $sfx = substr($path, length($filter));
1996 if ($sfx !~ /^\/.*\
.git
$/) {
1999 # is a fork, don't include it in
2004 if (check_export_ok
("$projectroot/$path")) {
2007 owner
=> to_utf8
($owner),
2010 (my $forks_path = $path) =~ s/\.git$//;
2011 $paths{$forks_path}++;
2019 our $gitweb_project_owner = undef;
2020 sub git_get_project_list_from_file
{
2022 return if (defined $gitweb_project_owner);
2024 $gitweb_project_owner = {};
2025 # read from file (url-encoded):
2026 # 'git%2Fgit.git Linus+Torvalds'
2027 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2028 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2029 if (-f
$projects_list) {
2030 open (my $fd , $projects_list);
2031 while (my $line = <$fd>) {
2033 my ($pr, $ow) = split ' ', $line;
2034 $pr = unescape
($pr);
2035 $ow = unescape
($ow);
2036 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2042 sub git_get_project_owner
{
2043 my $project = shift;
2046 return undef unless $project;
2047 $git_dir = "$projectroot/$project";
2049 if (!defined $gitweb_project_owner) {
2050 git_get_project_list_from_file
();
2053 if (exists $gitweb_project_owner->{$project}) {
2054 $owner = $gitweb_project_owner->{$project};
2056 if (!defined $owner){
2057 $owner = git_get_project_config
('owner');
2059 if (!defined $owner) {
2060 $owner = get_file_owner
("$git_dir");
2066 sub git_get_last_activity
{
2070 $git_dir = "$projectroot/$path";
2071 open($fd, "-|", git_cmd
(), 'for-each-ref',
2072 '--format=%(committer)',
2073 '--sort=-committerdate',
2075 'refs/heads') or return;
2076 my $most_recent = <$fd>;
2077 close $fd or return;
2078 if (defined $most_recent &&
2079 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2081 my $age = time - $timestamp;
2082 return ($age, age_string
($age));
2084 return (undef, undef);
2087 sub git_get_references
{
2088 my $type = shift || "";
2090 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2091 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2092 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2093 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2096 while (my $line = <$fd>) {
2098 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2099 if (defined $refs{$1}) {
2100 push @{$refs{$1}}, $2;
2106 close $fd or return;
2110 sub git_get_rev_name_tags
{
2111 my $hash = shift || return undef;
2113 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2115 my $name_rev = <$fd>;
2118 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2121 # catches also '$hash undefined' output
2126 ## ----------------------------------------------------------------------
2127 ## parse to hash functions
2131 my $tz = shift || "-0000";
2134 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2135 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2136 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2137 $date{'hour'} = $hour;
2138 $date{'minute'} = $min;
2139 $date{'mday'} = $mday;
2140 $date{'day'} = $days[$wday];
2141 $date{'month'} = $months[$mon];
2142 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2143 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2144 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2145 $mday, $months[$mon], $hour ,$min;
2146 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2147 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2149 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2150 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2151 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2152 $date{'hour_local'} = $hour;
2153 $date{'minute_local'} = $min;
2154 $date{'tz_local'} = $tz;
2155 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2156 1900+$year, $mon+1, $mday,
2157 $hour, $min, $sec, $tz);
2166 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2167 $tag{'id'} = $tag_id;
2168 while (my $line = <$fd>) {
2170 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2171 $tag{'object'} = $1;
2172 } elsif ($line =~ m/^type (.+)$/) {
2174 } elsif ($line =~ m/^tag (.+)$/) {
2176 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2177 $tag{'author'} = $1;
2180 } elsif ($line =~ m/--BEGIN/) {
2181 push @comment, $line;
2183 } elsif ($line eq "") {
2187 push @comment, <$fd>;
2188 $tag{'comment'} = \
@comment;
2189 close $fd or return;
2190 if (!defined $tag{'name'}) {
2196 sub parse_commit_text
{
2197 my ($commit_text, $withparents) = @_;
2198 my @commit_lines = split '\n', $commit_text;
2201 pop @commit_lines; # Remove '\0'
2203 if (! @commit_lines) {
2207 my $header = shift @commit_lines;
2208 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2211 ($co{'id'}, my @parents) = split ' ', $header;
2212 while (my $line = shift @commit_lines) {
2213 last if $line eq "\n";
2214 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2216 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2218 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2220 $co{'author_epoch'} = $2;
2221 $co{'author_tz'} = $3;
2222 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2223 $co{'author_name'} = $1;
2224 $co{'author_email'} = $2;
2226 $co{'author_name'} = $co{'author'};
2228 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2229 $co{'committer'} = $1;
2230 $co{'committer_epoch'} = $2;
2231 $co{'committer_tz'} = $3;
2232 $co{'committer_name'} = $co{'committer'};
2233 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2234 $co{'committer_name'} = $1;
2235 $co{'committer_email'} = $2;
2237 $co{'committer_name'} = $co{'committer'};
2241 if (!defined $co{'tree'}) {
2244 $co{'parents'} = \
@parents;
2245 $co{'parent'} = $parents[0];
2247 foreach my $title (@commit_lines) {
2250 $co{'title'} = chop_str
($title, 80, 5);
2251 # remove leading stuff of merges to make the interesting part visible
2252 if (length($title) > 50) {
2253 $title =~ s/^Automatic //;
2254 $title =~ s/^merge (of|with) /Merge ... /i;
2255 if (length($title) > 50) {
2256 $title =~ s/(http|rsync):\/\///;
2258 if (length($title) > 50) {
2259 $title =~ s/(master|www|rsync)\.//;
2261 if (length($title) > 50) {
2262 $title =~ s/kernel.org:?//;
2264 if (length($title) > 50) {
2265 $title =~ s/\/pub\/scm//;
2268 $co{'title_short'} = chop_str
($title, 50, 5);
2272 if (! defined $co{'title'} || $co{'title'} eq "") {
2273 $co{'title'} = $co{'title_short'} = '(no commit message)';
2275 # remove added spaces
2276 foreach my $line (@commit_lines) {
2279 $co{'comment'} = \
@commit_lines;
2281 my $age = time - $co{'committer_epoch'};
2283 $co{'age_string'} = age_string
($age);
2284 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2285 if ($age > 60*60*24*7*2) {
2286 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2287 $co{'age_string_age'} = $co{'age_string'};
2289 $co{'age_string_date'} = $co{'age_string'};
2290 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2296 my ($commit_id) = @_;
2301 open my $fd, "-|", git_cmd
(), "rev-list",
2307 or die_error
(500, "Open git-rev-list failed");
2308 %co = parse_commit_text
(<$fd>, 1);
2315 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2323 open my $fd, "-|", git_cmd
(), "rev-list",
2326 ("--max-count=" . $maxcount),
2327 ("--skip=" . $skip),
2331 ($filename ? ($filename) : ())
2332 or die_error
(500, "Open git-rev-list failed");
2333 while (my $line = <$fd>) {
2334 my %co = parse_commit_text
($line);
2339 return wantarray ? @cos : \
@cos;
2342 # parse line of git-diff-tree "raw" output
2343 sub parse_difftree_raw_line
{
2347 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2348 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2349 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2350 $res{'from_mode'} = $1;
2351 $res{'to_mode'} = $2;
2352 $res{'from_id'} = $3;
2354 $res{'status'} = $5;
2355 $res{'similarity'} = $6;
2356 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2357 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2359 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2362 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2363 # combined diff (for merge commit)
2364 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2365 $res{'nparents'} = length($1);
2366 $res{'from_mode'} = [ split(' ', $2) ];
2367 $res{'to_mode'} = pop @{$res{'from_mode'}};
2368 $res{'from_id'} = [ split(' ', $3) ];
2369 $res{'to_id'} = pop @{$res{'from_id'}};
2370 $res{'status'} = [ split('', $4) ];
2371 $res{'to_file'} = unquote
($5);
2373 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2374 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2375 $res{'commit'} = $1;
2378 return wantarray ? %res : \
%res;
2381 # wrapper: return parsed line of git-diff-tree "raw" output
2382 # (the argument might be raw line, or parsed info)
2383 sub parsed_difftree_line
{
2384 my $line_or_ref = shift;
2386 if (ref($line_or_ref) eq "HASH") {
2387 # pre-parsed (or generated by hand)
2388 return $line_or_ref;
2390 return parse_difftree_raw_line
($line_or_ref);
2394 # parse line of git-ls-tree output
2395 sub parse_ls_tree_line
($;%) {
2400 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2401 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2409 $res{'name'} = unquote
($4);
2412 return wantarray ? %res : \
%res;
2415 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2416 sub parse_from_to_diffinfo
{
2417 my ($diffinfo, $from, $to, @parents) = @_;
2419 if ($diffinfo->{'nparents'}) {
2421 $from->{'file'} = [];
2422 $from->{'href'} = [];
2423 fill_from_file_info
($diffinfo, @parents)
2424 unless exists $diffinfo->{'from_file'};
2425 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2426 $from->{'file'}[$i] =
2427 defined $diffinfo->{'from_file'}[$i] ?
2428 $diffinfo->{'from_file'}[$i] :
2429 $diffinfo->{'to_file'};
2430 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2431 $from->{'href'}[$i] = href
(action
=>"blob",
2432 hash_base
=>$parents[$i],
2433 hash
=>$diffinfo->{'from_id'}[$i],
2434 file_name
=>$from->{'file'}[$i]);
2436 $from->{'href'}[$i] = undef;
2440 # ordinary (not combined) diff
2441 $from->{'file'} = $diffinfo->{'from_file'};
2442 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2443 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2444 hash
=>$diffinfo->{'from_id'},
2445 file_name
=>$from->{'file'});
2447 delete $from->{'href'};
2451 $to->{'file'} = $diffinfo->{'to_file'};
2452 if (!is_deleted
($diffinfo)) { # file exists in result
2453 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2454 hash
=>$diffinfo->{'to_id'},
2455 file_name
=>$to->{'file'});
2457 delete $to->{'href'};
2461 ## ......................................................................
2462 ## parse to array of hashes functions
2464 sub git_get_heads_list
{
2468 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2469 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2470 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2473 while (my $line = <$fd>) {
2477 my ($refinfo, $committerinfo) = split(/\0/, $line);
2478 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2479 my ($committer, $epoch, $tz) =
2480 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2481 $ref_item{'fullname'} = $name;
2482 $name =~ s!^refs/heads/!!;
2484 $ref_item{'name'} = $name;
2485 $ref_item{'id'} = $hash;
2486 $ref_item{'title'} = $title || '(no commit message)';
2487 $ref_item{'epoch'} = $epoch;
2489 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2491 $ref_item{'age'} = "unknown";
2494 push @headslist, \
%ref_item;
2498 return wantarray ? @headslist : \
@headslist;
2501 sub git_get_tags_list
{
2505 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2506 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2507 '--format=%(objectname) %(objecttype) %(refname) '.
2508 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2511 while (my $line = <$fd>) {
2515 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2516 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2517 my ($creator, $epoch, $tz) =
2518 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2519 $ref_item{'fullname'} = $name;
2520 $name =~ s!^refs/tags/!!;
2522 $ref_item{'type'} = $type;
2523 $ref_item{'id'} = $id;
2524 $ref_item{'name'} = $name;
2525 if ($type eq "tag") {
2526 $ref_item{'subject'} = $title;
2527 $ref_item{'reftype'} = $reftype;
2528 $ref_item{'refid'} = $refid;
2530 $ref_item{'reftype'} = $type;
2531 $ref_item{'refid'} = $id;
2534 if ($type eq "tag" || $type eq "commit") {
2535 $ref_item{'epoch'} = $epoch;
2537 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2539 $ref_item{'age'} = "unknown";
2543 push @tagslist, \
%ref_item;
2547 return wantarray ? @tagslist : \
@tagslist;
2550 ## ----------------------------------------------------------------------
2551 ## filesystem-related functions
2553 sub get_file_owner
{
2556 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2557 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2558 if (!defined $gcos) {
2562 $owner =~ s/[,;].*$//;
2563 return to_utf8
($owner);
2566 ## ......................................................................
2567 ## mimetype related functions
2569 sub mimetype_guess_file
{
2570 my $filename = shift;
2571 my $mimemap = shift;
2572 -r
$mimemap or return undef;
2575 open(MIME
, $mimemap) or return undef;
2577 next if m/^#/; # skip comments
2578 my ($mime, $exts) = split(/\t+/);
2579 if (defined $exts) {
2580 my @exts = split(/\s+/, $exts);
2581 foreach my $ext (@exts) {
2582 $mimemap{$ext} = $mime;
2588 $filename =~ /\.([^.]*)$/;
2589 return $mimemap{$1};
2592 sub mimetype_guess
{
2593 my $filename = shift;
2595 $filename =~ /\./ or return undef;
2597 if ($mimetypes_file) {
2598 my $file = $mimetypes_file;
2599 if ($file !~ m!^/!) { # if it is relative path
2600 # it is relative to project
2601 $file = "$projectroot/$project/$file";
2603 $mime = mimetype_guess_file
($filename, $file);
2605 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2611 my $filename = shift;
2614 my $mime = mimetype_guess
($filename);
2615 $mime and return $mime;
2619 return $default_blob_plain_mimetype unless $fd;
2622 return 'text/plain';
2623 } elsif (! $filename) {
2624 return 'application/octet-stream';
2625 } elsif ($filename =~ m/\.png$/i) {
2627 } elsif ($filename =~ m/\.gif$/i) {
2629 } elsif ($filename =~ m/\.jpe?g$/i) {
2630 return 'image/jpeg';
2632 return 'application/octet-stream';
2636 sub blob_contenttype
{
2637 my ($fd, $file_name, $type) = @_;
2639 $type ||= blob_mimetype
($fd, $file_name);
2640 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2641 $type .= "; charset=$default_text_plain_charset";
2647 ## ======================================================================
2648 ## functions printing HTML: header, footer, error page
2650 sub git_header_html
{
2651 my $status = shift || "200 OK";
2652 my $expires = shift;
2654 my $title = "$site_name";
2655 if (defined $project) {
2656 $title .= " - " . to_utf8
($project);
2657 if (defined $action) {
2658 $title .= "/$action";
2659 if (defined $file_name) {
2660 $title .= " - " . esc_path
($file_name);
2661 if ($action eq "tree" && $file_name !~ m
|/$|) {
2668 # require explicit support from the UA if we are to send the page as
2669 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2670 # we have to do this because MSIE sometimes globs '*/*', pretending to
2671 # support xhtml+xml but choking when it gets what it asked for.
2672 if (defined $cgi->http('HTTP_ACCEPT') &&
2673 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2674 $cgi->Accept('application/xhtml+xml') != 0) {
2675 $content_type = 'application/xhtml+xml';
2677 $content_type = 'text/html';
2679 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2680 -status
=> $status, -expires
=> $expires);
2681 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2683 <?xml version="1.0" encoding="utf-8"?>
2684 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2685 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2686 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2687 <!-- git core binaries version $git_version -->
2689 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2690 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2691 <meta name="robots" content="index, nofollow"/>
2692 <title>$title</title>
2694 # print out each stylesheet that exist
2695 if (defined $stylesheet) {
2696 #provides backwards capability for those people who define style sheet in a config file
2697 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2699 foreach my $stylesheet (@stylesheets) {
2700 next unless $stylesheet;
2701 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2704 if (defined $project) {
2705 my %href_params = get_feed_info
();
2706 if (!exists $href_params{'-title'}) {
2707 $href_params{'-title'} = 'log';
2710 foreach my $format qw(RSS Atom) {
2711 my $type = lc($format);
2713 '-rel' => 'alternate',
2714 '-title' => "$project - $href_params{'-title'} - $format feed",
2715 '-type' => "application/$type+xml"
2718 $href_params{'action'} = $type;
2719 $link_attr{'-href'} = href
(%href_params);
2721 "rel=\"$link_attr{'-rel'}\" ".
2722 "title=\"$link_attr{'-title'}\" ".
2723 "href=\"$link_attr{'-href'}\" ".
2724 "type=\"$link_attr{'-type'}\" ".
2727 $href_params{'extra_options'} = '--no-merges';
2728 $link_attr{'-href'} = href
(%href_params);
2729 $link_attr{'-title'} .= ' (no merges)';
2731 "rel=\"$link_attr{'-rel'}\" ".
2732 "title=\"$link_attr{'-title'}\" ".
2733 "href=\"$link_attr{'-href'}\" ".
2734 "type=\"$link_attr{'-type'}\" ".
2739 printf('<link rel="alternate" title="%s projects list" '.
2740 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2741 $site_name, href
(project
=>undef, action
=>"project_index"));
2742 printf('<link rel="alternate" title="%s projects feeds" '.
2743 'href="%s" type="text/x-opml" />'."\n",
2744 $site_name, href
(project
=>undef, action
=>"opml"));
2746 if (defined $favicon) {
2747 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2753 if (-f
$site_header) {
2754 open (my $fd, $site_header);
2759 print "<div class=\"page_header\">\n" .
2760 $cgi->a({-href
=> esc_url
($logo_url),
2761 -title
=> $logo_label},
2762 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2763 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2764 if (defined $project) {
2765 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2766 if (defined $action) {
2773 my ($have_search) = gitweb_check_feature
('search');
2774 if (defined $project && $have_search) {
2775 if (!defined $searchtext) {
2779 if (defined $hash_base) {
2780 $search_hash = $hash_base;
2781 } elsif (defined $hash) {
2782 $search_hash = $hash;
2784 $search_hash = "HEAD";
2786 my $action = $my_uri;
2787 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2788 if ($use_pathinfo) {
2789 $action .= "/".esc_url
($project);
2791 print $cgi->startform(-method => "get", -action
=> $action) .
2792 "<div class=\"search\">\n" .
2794 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2795 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2796 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2797 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2798 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2799 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2801 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2802 "<span title=\"Extended regular expression\">" .
2803 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2804 -checked
=> $search_use_regexp) .
2807 $cgi->end_form() . "\n";
2811 sub git_footer_html
{
2812 my $feed_class = 'rss_logo';
2814 print "<div class=\"page_footer\">\n";
2815 if (defined $project) {
2816 my $descr = git_get_project_description
($project);
2817 if (defined $descr) {
2818 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2821 my %href_params = get_feed_info
();
2822 if (!%href_params) {
2823 $feed_class .= ' generic';
2825 $href_params{'-title'} ||= 'log';
2827 foreach my $format qw(RSS Atom) {
2828 $href_params{'action'} = lc($format);
2829 print $cgi->a({-href
=> href
(%href_params),
2830 -title
=> "$href_params{'-title'} $format feed",
2831 -class => $feed_class}, $format)."\n";
2835 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2836 -class => $feed_class}, "OPML") . " ";
2837 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2838 -class => $feed_class}, "TXT") . "\n";
2840 print "</div>\n"; # class="page_footer"
2842 if (-f
$site_footer) {
2843 open (my $fd, $site_footer);
2852 # die_error(<http_status_code>, <error_message>)
2853 # Example: die_error(404, 'Hash not found')
2854 # By convention, use the following status codes (as defined in RFC 2616):
2855 # 400: Invalid or missing CGI parameters, or
2856 # requested object exists but has wrong type.
2857 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2858 # this server or project.
2859 # 404: Requested object/revision/project doesn't exist.
2860 # 500: The server isn't configured properly, or
2861 # an internal error occurred (e.g. failed assertions caused by bugs), or
2862 # an unknown error occurred (e.g. the git binary died unexpectedly).
2864 my $status = shift || 500;
2865 my $error = shift || "Internal server error";
2867 my %http_responses = (400 => '400 Bad Request',
2868 403 => '403 Forbidden',
2869 404 => '404 Not Found',
2870 500 => '500 Internal Server Error');
2871 git_header_html
($http_responses{$status});
2873 <div class="page_body">
2883 ## ----------------------------------------------------------------------
2884 ## functions printing or outputting HTML: navigation
2886 sub git_print_page_nav
{
2887 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2888 $extra = '' if !defined $extra; # pager or formats
2890 my @navs = qw(summary shortlog log commit commitdiff tree);
2892 @navs = grep { $_ ne $suppress } @navs;
2895 my %arg = map { $_ => {action
=>$_} } @navs;
2896 if (defined $head) {
2897 for (qw(commit commitdiff)) {
2898 $arg{$_}{'hash'} = $head;
2900 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2901 for (qw(shortlog log)) {
2902 $arg{$_}{'hash'} = $head;
2907 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2908 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2910 my @actions = gitweb_check_feature
('actions');
2913 'n' => $project, # project name
2914 'f' => $git_dir, # project path within filesystem
2915 'h' => $treehead || '', # current hash ('h' parameter)
2916 'b' => $treebase || '', # hash base ('hb' parameter)
2919 my ($label, $link, $pos) = splice(@actions,0,3);
2921 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2923 $link =~ s/%([%nfhb])/$repl{$1}/g;
2924 $arg{$label}{'_href'} = $link;
2927 print "<div class=\"page_nav\">\n" .
2929 map { $_ eq $current ?
2930 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
2932 print "<br/>\n$extra<br/>\n" .
2936 sub format_paging_nav
{
2937 my ($action, $hash, $head, $page, $has_next_link) = @_;
2941 if ($hash ne $head || $page) {
2942 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2944 $paging_nav .= "HEAD";
2948 $paging_nav .= " ⋅ " .
2949 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2950 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2952 $paging_nav .= " ⋅ prev";
2955 if ($has_next_link) {
2956 $paging_nav .= " ⋅ " .
2957 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2958 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2960 $paging_nav .= " ⋅ next";
2966 ## ......................................................................
2967 ## functions printing or outputting HTML: div
2969 sub git_print_header_div
{
2970 my ($action, $title, $hash, $hash_base) = @_;
2973 $args{'action'} = $action;
2974 $args{'hash'} = $hash if $hash;
2975 $args{'hash_base'} = $hash_base if $hash_base;
2977 print "<div class=\"header\">\n" .
2978 $cgi->a({-href
=> href
(%args), -class => "title"},
2979 $title ? $title : $action) .
2983 #sub git_print_authorship (\%) {
2984 sub git_print_authorship
{
2987 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2988 print "<div class=\"author_date\">" .
2989 esc_html
($co->{'author_name'}) .
2991 if ($ad{'hour_local'} < 6) {
2992 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2993 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2995 printf(" (%02d:%02d %s)",
2996 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3001 sub git_print_page_path
{
3007 print "<div class=\"page_path\">";
3008 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3009 -title
=> 'tree root'}, to_utf8
("[$project]"));
3011 if (defined $name) {
3012 my @dirname = split '/', $name;
3013 my $basename = pop @dirname;
3016 foreach my $dir (@dirname) {
3017 $fullname .= ($fullname ? '/' : '') . $dir;
3018 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3020 -title
=> $fullname}, esc_path
($dir));
3023 if (defined $type && $type eq 'blob') {
3024 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3026 -title
=> $name}, esc_path
($basename));
3027 } elsif (defined $type && $type eq 'tree') {
3028 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3030 -title
=> $name}, esc_path
($basename));
3033 print esc_path
($basename);
3036 print "<br/></div>\n";
3039 # sub git_print_log (\@;%) {
3040 sub git_print_log
($;%) {
3044 if ($opts{'-remove_title'}) {
3045 # remove title, i.e. first line of log
3048 # remove leading empty lines
3049 while (defined $log->[0] && $log->[0] eq "") {
3056 foreach my $line (@$log) {
3057 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3060 if (! $opts{'-remove_signoff'}) {
3061 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3064 # remove signoff lines
3071 # print only one empty line
3072 # do not print empty line after signoff
3074 next if ($empty || $signoff);
3080 print format_log_line_html
($line) . "<br/>\n";
3083 if ($opts{'-final_empty_line'}) {
3084 # end with single empty line
3085 print "<br/>\n" unless $empty;
3089 # return link target (what link points to)
3090 sub git_get_link_target
{
3095 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3099 $link_target = <$fd>;
3104 return $link_target;
3107 # given link target, and the directory (basedir) the link is in,
3108 # return target of link relative to top directory (top tree);
3109 # return undef if it is not possible (including absolute links).
3110 sub normalize_link_target
{
3111 my ($link_target, $basedir, $hash_base) = @_;
3113 # we can normalize symlink target only if $hash_base is provided
3114 return unless $hash_base;
3116 # absolute symlinks (beginning with '/') cannot be normalized
3117 return if (substr($link_target, 0, 1) eq '/');
3119 # normalize link target to path from top (root) tree (dir)
3122 $path = $basedir . '/' . $link_target;
3124 # we are in top (root) tree (dir)
3125 $path = $link_target;
3128 # remove //, /./, and /../
3130 foreach my $part (split('/', $path)) {
3131 # discard '.' and ''
3132 next if (!$part || $part eq '.');
3134 if ($part eq '..') {
3138 # link leads outside repository (outside top dir)
3142 push @path_parts, $part;
3145 $path = join('/', @path_parts);
3150 # print tree entry (row of git_tree), but without encompassing <tr> element
3151 sub git_print_tree_entry
{
3152 my ($t, $basedir, $hash_base, $have_blame) = @_;
3155 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3157 # The format of a table row is: mode list link. Where mode is
3158 # the mode of the entry, list is the name of the entry, an href,
3159 # and link is the action links of the entry.
3161 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3162 if ($t->{'type'} eq "blob") {
3163 print "<td class=\"list\">" .
3164 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3165 file_name
=>"$basedir$t->{'name'}", %base_key),
3166 -class => "list"}, esc_path
($t->{'name'}));
3167 if (S_ISLNK
(oct $t->{'mode'})) {
3168 my $link_target = git_get_link_target
($t->{'hash'});
3170 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3171 if (defined $norm_target) {
3173 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3174 file_name
=>$norm_target),
3175 -title
=> $norm_target}, esc_path
($link_target));
3177 print " -> " . esc_path
($link_target);
3182 print "<td class=\"link\">";
3183 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3184 file_name
=>"$basedir$t->{'name'}", %base_key)},
3188 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3189 file_name
=>"$basedir$t->{'name'}", %base_key)},
3192 if (defined $hash_base) {
3194 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3195 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3199 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3200 file_name
=>"$basedir$t->{'name'}")},
3204 } elsif ($t->{'type'} eq "tree") {
3205 print "<td class=\"list\">";
3206 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3207 file_name
=>"$basedir$t->{'name'}", %base_key)},
3208 esc_path
($t->{'name'}));
3210 print "<td class=\"link\">";
3211 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3212 file_name
=>"$basedir$t->{'name'}", %base_key)},
3214 if (defined $hash_base) {
3216 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3217 file_name
=>"$basedir$t->{'name'}")},
3222 # unknown object: we can only present history for it
3223 # (this includes 'commit' object, i.e. submodule support)
3224 print "<td class=\"list\">" .
3225 esc_path
($t->{'name'}) .
3227 print "<td class=\"link\">";
3228 if (defined $hash_base) {
3229 print $cgi->a({-href
=> href
(action
=>"history",
3230 hash_base
=>$hash_base,
3231 file_name
=>"$basedir$t->{'name'}")},
3238 ## ......................................................................
3239 ## functions printing large fragments of HTML
3241 # get pre-image filenames for merge (combined) diff
3242 sub fill_from_file_info
{
3243 my ($diff, @parents) = @_;
3245 $diff->{'from_file'} = [ ];
3246 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3247 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3248 if ($diff->{'status'}[$i] eq 'R' ||
3249 $diff->{'status'}[$i] eq 'C') {
3250 $diff->{'from_file'}[$i] =
3251 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3258 # is current raw difftree line of file deletion
3260 my $diffinfo = shift;
3262 return $diffinfo->{'to_id'} eq ('0' x
40);
3265 # does patch correspond to [previous] difftree raw line
3266 # $diffinfo - hashref of parsed raw diff format
3267 # $patchinfo - hashref of parsed patch diff format
3268 # (the same keys as in $diffinfo)
3269 sub is_patch_split
{
3270 my ($diffinfo, $patchinfo) = @_;
3272 return defined $diffinfo && defined $patchinfo
3273 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3277 sub git_difftree_body
{
3278 my ($difftree, $hash, @parents) = @_;
3279 my ($parent) = $parents[0];
3280 my ($have_blame) = gitweb_check_feature
('blame');
3281 print "<div class=\"list_head\">\n";
3282 if ($#{$difftree} > 10) {
3283 print(($#{$difftree} + 1) . " files changed:\n");
3287 print "<table class=\"" .
3288 (@parents > 1 ? "combined " : "") .
3291 # header only for combined diff in 'commitdiff' view
3292 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3295 print "<thead><tr>\n" .
3296 "<th></th><th></th>\n"; # filename, patchN link
3297 for (my $i = 0; $i < @parents; $i++) {
3298 my $par = $parents[$i];
3300 $cgi->a({-href
=> href
(action
=>"commitdiff",
3301 hash
=>$hash, hash_parent
=>$par),
3302 -title
=> 'commitdiff to parent number ' .
3303 ($i+1) . ': ' . substr($par,0,7)},
3307 print "</tr></thead>\n<tbody>\n";
3312 foreach my $line (@{$difftree}) {
3313 my $diff = parsed_difftree_line
($line);
3316 print "<tr class=\"dark\">\n";
3318 print "<tr class=\"light\">\n";
3322 if (exists $diff->{'nparents'}) { # combined diff
3324 fill_from_file_info
($diff, @parents)
3325 unless exists $diff->{'from_file'};
3327 if (!is_deleted
($diff)) {
3328 # file exists in the result (child) commit
3330 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3331 file_name
=>$diff->{'to_file'},
3333 -class => "list"}, esc_path
($diff->{'to_file'})) .
3337 esc_path
($diff->{'to_file'}) .
3341 if ($action eq 'commitdiff') {
3344 print "<td class=\"link\">" .
3345 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3350 my $has_history = 0;
3351 my $not_deleted = 0;
3352 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3353 my $hash_parent = $parents[$i];
3354 my $from_hash = $diff->{'from_id'}[$i];
3355 my $from_path = $diff->{'from_file'}[$i];
3356 my $status = $diff->{'status'}[$i];
3358 $has_history ||= ($status ne 'A');
3359 $not_deleted ||= ($status ne 'D');
3361 if ($status eq 'A') {
3362 print "<td class=\"link\" align=\"right\"> | </td>\n";
3363 } elsif ($status eq 'D') {
3364 print "<td class=\"link\">" .
3365 $cgi->a({-href
=> href
(action
=>"blob",
3368 file_name
=>$from_path)},
3372 if ($diff->{'to_id'} eq $from_hash) {
3373 print "<td class=\"link nochange\">";
3375 print "<td class=\"link\">";
3377 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3378 hash
=>$diff->{'to_id'},
3379 hash_parent
=>$from_hash,
3381 hash_parent_base
=>$hash_parent,
3382 file_name
=>$diff->{'to_file'},
3383 file_parent
=>$from_path)},
3389 print "<td class=\"link\">";
3391 print $cgi->a({-href
=> href
(action
=>"blob",
3392 hash
=>$diff->{'to_id'},
3393 file_name
=>$diff->{'to_file'},
3396 print " | " if ($has_history);
3399 print $cgi->a({-href
=> href
(action
=>"history",
3400 file_name
=>$diff->{'to_file'},
3407 next; # instead of 'else' clause, to avoid extra indent
3409 # else ordinary diff
3411 my ($to_mode_oct, $to_mode_str, $to_file_type);
3412 my ($from_mode_oct, $from_mode_str, $from_file_type);
3413 if ($diff->{'to_mode'} ne ('0' x
6)) {
3414 $to_mode_oct = oct $diff->{'to_mode'};
3415 if (S_ISREG
($to_mode_oct)) { # only for regular file
3416 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3418 $to_file_type = file_type
($diff->{'to_mode'});
3420 if ($diff->{'from_mode'} ne ('0' x
6)) {
3421 $from_mode_oct = oct $diff->{'from_mode'};
3422 if (S_ISREG
($to_mode_oct)) { # only for regular file
3423 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3425 $from_file_type = file_type
($diff->{'from_mode'});
3428 if ($diff->{'status'} eq "A") { # created
3429 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3430 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3431 $mode_chng .= "]</span>";
3433 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3434 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3435 -class => "list"}, esc_path
($diff->{'file'}));
3437 print "<td>$mode_chng</td>\n";
3438 print "<td class=\"link\">";
3439 if ($action eq 'commitdiff') {
3442 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3445 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3446 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3450 } elsif ($diff->{'status'} eq "D") { # deleted
3451 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3453 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3454 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3455 -class => "list"}, esc_path
($diff->{'file'}));
3457 print "<td>$mode_chng</td>\n";
3458 print "<td class=\"link\">";
3459 if ($action eq 'commitdiff') {
3462 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3465 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3466 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3469 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3470 file_name
=>$diff->{'file'})},
3473 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3474 file_name
=>$diff->{'file'})},
3478 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3479 my $mode_chnge = "";
3480 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3481 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3482 if ($from_file_type ne $to_file_type) {
3483 $mode_chnge .= " from $from_file_type to $to_file_type";
3485 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3486 if ($from_mode_str && $to_mode_str) {
3487 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3488 } elsif ($to_mode_str) {
3489 $mode_chnge .= " mode: $to_mode_str";
3492 $mode_chnge .= "]</span>\n";
3495 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3496 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3497 -class => "list"}, esc_path
($diff->{'file'}));
3499 print "<td>$mode_chnge</td>\n";
3500 print "<td class=\"link\">";
3501 if ($action eq 'commitdiff') {
3504 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3506 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3507 # "commit" view and modified file (not onlu mode changed)
3508 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3509 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3510 hash_base
=>$hash, hash_parent_base
=>$parent,
3511 file_name
=>$diff->{'file'})},
3515 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3516 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3519 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3520 file_name
=>$diff->{'file'})},
3523 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3524 file_name
=>$diff->{'file'})},
3528 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3529 my %status_name = ('R' => 'moved', 'C' => 'copied');
3530 my $nstatus = $status_name{$diff->{'status'}};
3532 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3533 # mode also for directories, so we cannot use $to_mode_str
3534 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3537 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3538 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3539 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3540 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3541 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3542 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3543 -class => "list"}, esc_path
($diff->{'from_file'})) .
3544 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3545 "<td class=\"link\">";
3546 if ($action eq 'commitdiff') {
3549 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3551 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3552 # "commit" view and modified file (not only pure rename or copy)
3553 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3554 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3555 hash_base
=>$hash, hash_parent_base
=>$parent,
3556 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3560 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3561 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3564 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3565 file_name
=>$diff->{'to_file'})},
3568 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3569 file_name
=>$diff->{'to_file'})},
3573 } # we should not encounter Unmerged (U) or Unknown (X) status
3576 print "</tbody>" if $has_header;
3580 sub git_patchset_body
{
3581 my ($fd, $difftree, $hash, @hash_parents) = @_;
3582 my ($hash_parent) = $hash_parents[0];
3584 my $is_combined = (@hash_parents > 1);
3586 my $patch_number = 0;
3592 print "<div class=\"patchset\">\n";
3594 # skip to first patch
3595 while ($patch_line = <$fd>) {
3598 last if ($patch_line =~ m/^diff /);
3602 while ($patch_line) {
3604 # parse "git diff" header line
3605 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3606 # $1 is from_name, which we do not use
3607 $to_name = unquote
($2);
3608 $to_name =~ s!^b/!!;
3609 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3610 # $1 is 'cc' or 'combined', which we do not use
3611 $to_name = unquote
($2);
3616 # check if current patch belong to current raw line
3617 # and parse raw git-diff line if needed
3618 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3619 # this is continuation of a split patch
3620 print "<div class=\"patch cont\">\n";
3622 # advance raw git-diff output if needed
3623 $patch_idx++ if defined $diffinfo;
3625 # read and prepare patch information
3626 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3628 # compact combined diff output can have some patches skipped
3629 # find which patch (using pathname of result) we are at now;
3631 while ($to_name ne $diffinfo->{'to_file'}) {
3632 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3633 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3634 "</div>\n"; # class="patch"
3639 last if $patch_idx > $#$difftree;
3640 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3644 # modifies %from, %to hashes
3645 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3647 # this is first patch for raw difftree line with $patch_idx index
3648 # we index @$difftree array from 0, but number patches from 1
3649 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3653 #assert($patch_line =~ m/^diff /) if DEBUG;
3654 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3656 # print "git diff" header
3657 print format_git_diff_header_line
($patch_line, $diffinfo,
3660 # print extended diff header
3661 print "<div class=\"diff extended_header\">\n";
3663 while ($patch_line = <$fd>) {
3666 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3668 print format_extended_diff_header_line
($patch_line, $diffinfo,
3671 print "</div>\n"; # class="diff extended_header"
3673 # from-file/to-file diff header
3674 if (! $patch_line) {
3675 print "</div>\n"; # class="patch"
3678 next PATCH
if ($patch_line =~ m/^diff /);
3679 #assert($patch_line =~ m/^---/) if DEBUG;
3681 my $last_patch_line = $patch_line;
3682 $patch_line = <$fd>;
3684 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3686 print format_diff_from_to_header
($last_patch_line, $patch_line,
3687 $diffinfo, \
%from, \
%to,
3692 while ($patch_line = <$fd>) {
3695 next PATCH
if ($patch_line =~ m/^diff /);
3697 print format_diff_line
($patch_line, \
%from, \
%to);
3701 print "</div>\n"; # class="patch"
3704 # for compact combined (--cc) format, with chunk and patch simpliciaction
3705 # patchset might be empty, but there might be unprocessed raw lines
3706 for (++$patch_idx if $patch_number > 0;
3707 $patch_idx < @$difftree;
3709 # read and prepare patch information
3710 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3712 # generate anchor for "patch" links in difftree / whatchanged part
3713 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3714 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3715 "</div>\n"; # class="patch"
3720 if ($patch_number == 0) {
3721 if (@hash_parents > 1) {
3722 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3724 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3728 print "</div>\n"; # class="patchset"
3731 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3733 # fills project list info (age, description, owner, forks) for each
3734 # project in the list, removing invalid projects from returned list
3735 # NOTE: modifies $projlist, but does not remove entries from it
3736 sub fill_project_list_info
{
3737 my ($projlist, $check_forks) = @_;
3740 my $show_ctags = gitweb_check_feature
('ctags');
3742 foreach my $pr (@$projlist) {
3743 my (@activity) = git_get_last_activity
($pr->{'path'});
3744 unless (@activity) {
3747 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3748 if (!defined $pr->{'descr'}) {
3749 my $descr = git_get_project_description
($pr->{'path'}) || "";
3750 $descr = to_utf8
($descr);
3751 $pr->{'descr_long'} = $descr;
3752 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3754 if (!defined $pr->{'owner'}) {
3755 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3758 my $pname = $pr->{'path'};
3759 if (($pname =~ s/\.git$//) &&
3760 ($pname !~ /\/$/) &&
3761 (-d
"$projectroot/$pname")) {
3762 $pr->{'forks'} = "-d $projectroot/$pname";
3767 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3768 push @projects, $pr;
3774 # print 'sort by' <th> element, generating 'sort by $name' replay link
3775 # if that order is not selected
3777 my ($name, $order, $header) = @_;
3778 $header ||= ucfirst($name);
3780 if ($order eq $name) {
3781 print "<th>$header</th>\n";
3784 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3785 -class => "header"}, $header) .
3790 sub git_project_list_body
{
3791 # actually uses global variable $project
3792 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3794 my ($check_forks) = gitweb_check_feature
('forks');
3795 my @projects = fill_project_list_info
($projlist, $check_forks);
3797 $order ||= $default_projects_order;
3798 $from = 0 unless defined $from;
3799 $to = $#projects if (!defined $to || $#projects < $to);
3802 project
=> { key
=> 'path', type
=> 'str' },
3803 descr
=> { key
=> 'descr_long', type
=> 'str' },
3804 owner
=> { key
=> 'owner', type
=> 'str' },
3805 age
=> { key
=> 'age', type
=> 'num' }
3807 my $oi = $order_info{$order};
3808 if ($oi->{'type'} eq 'str') {
3809 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3811 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3814 my $show_ctags = gitweb_check_feature
('ctags');
3817 foreach my $p (@projects) {
3818 foreach my $ct (keys %{$p->{'ctags'}}) {
3819 $ctags{$ct} += $p->{'ctags'}->{$ct};
3822 my $cloud = git_populate_project_tagcloud
(\
%ctags);
3823 print git_show_project_tagcloud
($cloud, 64);
3826 print "<table class=\"project_list\">\n";
3827 unless ($no_header) {
3830 print "<th></th>\n";
3832 print_sort_th
('project', $order, 'Project');
3833 print_sort_th
('descr', $order, 'Description');
3834 print_sort_th
('owner', $order, 'Owner');
3835 print_sort_th
('age', $order, 'Last Change');
3836 print "<th></th>\n" . # for links
3840 my $tagfilter = $cgi->param('by_tag');
3841 for (my $i = $from; $i <= $to; $i++) {
3842 my $pr = $projects[$i];
3844 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
3845 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
3846 and not $pr->{'descr_long'} =~ /$searchtext/;
3847 # Weed out forks or non-matching entries of search
3849 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
3850 $forkbase="^$forkbase" if $forkbase;
3851 next if not $searchtext and not $tagfilter and $show_ctags
3852 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
3856 print "<tr class=\"dark\">\n";
3858 print "<tr class=\"light\">\n";
3863 if ($pr->{'forks'}) {
3864 print "<!-- $pr->{'forks'} -->\n";
3865 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3869 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3870 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3871 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3872 -class => "list", -title
=> $pr->{'descr_long'}},
3873 esc_html
($pr->{'descr'})) . "</td>\n" .
3874 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3875 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3876 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3877 "<td class=\"link\">" .
3878 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3879 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3880 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3881 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3882 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3886 if (defined $extra) {
3889 print "<td></td>\n";
3891 print "<td colspan=\"5\">$extra</td>\n" .
3897 sub git_shortlog_body
{
3898 # uses global variable $project
3899 my ($commitlist, $from, $to, $refs, $extra) = @_;
3901 $from = 0 unless defined $from;
3902 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3904 print "<table class=\"shortlog\">\n";
3906 for (my $i = $from; $i <= $to; $i++) {
3907 my %co = %{$commitlist->[$i]};
3908 my $commit = $co{'id'};
3909 my $ref = format_ref_marker
($refs, $commit);
3911 print "<tr class=\"dark\">\n";
3913 print "<tr class=\"light\">\n";
3916 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3917 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3918 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3919 "<td><i>" . $author . "</i></td>\n" .
3921 print format_subject_html
($co{'title'}, $co{'title_short'},
3922 href
(action
=>"commit", hash
=>$commit), $ref);
3924 "<td class=\"link\">" .
3925 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3926 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3927 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3928 my $snapshot_links = format_snapshot_links
($commit);
3929 if (defined $snapshot_links) {
3930 print " | " . $snapshot_links;
3935 if (defined $extra) {
3937 "<td colspan=\"4\">$extra</td>\n" .
3943 sub git_history_body
{
3944 # Warning: assumes constant type (blob or tree) during history
3945 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3947 $from = 0 unless defined $from;
3948 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3950 print "<table class=\"history\">\n";
3952 for (my $i = $from; $i <= $to; $i++) {
3953 my %co = %{$commitlist->[$i]};
3957 my $commit = $co{'id'};
3959 my $ref = format_ref_marker
($refs, $commit);
3962 print "<tr class=\"dark\">\n";
3964 print "<tr class=\"light\">\n";
3967 # shortlog uses chop_str($co{'author_name'}, 10)
3968 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3969 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3970 "<td><i>" . $author . "</i></td>\n" .
3972 # originally git_history used chop_str($co{'title'}, 50)
3973 print format_subject_html
($co{'title'}, $co{'title_short'},
3974 href
(action
=>"commit", hash
=>$commit), $ref);
3976 "<td class=\"link\">" .
3977 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3978 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3980 if ($ftype eq 'blob') {
3981 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3982 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3983 if (defined $blob_current && defined $blob_parent &&
3984 $blob_current ne $blob_parent) {
3986 $cgi->a({-href
=> href
(action
=>"blobdiff",
3987 hash
=>$blob_current, hash_parent
=>$blob_parent,
3988 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3989 file_name
=>$file_name)},
3996 if (defined $extra) {
3998 "<td colspan=\"4\">$extra</td>\n" .
4005 # uses global variable $project
4006 my ($taglist, $from, $to, $extra) = @_;
4007 $from = 0 unless defined $from;
4008 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4010 print "<table class=\"tags\">\n";
4012 for (my $i = $from; $i <= $to; $i++) {
4013 my $entry = $taglist->[$i];
4015 my $comment = $tag{'subject'};
4017 if (defined $comment) {
4018 $comment_short = chop_str
($comment, 30, 5);
4021 print "<tr class=\"dark\">\n";
4023 print "<tr class=\"light\">\n";
4026 if (defined $tag{'age'}) {
4027 print "<td><i>$tag{'age'}</i></td>\n";
4029 print "<td></td>\n";
4032 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4033 -class => "list name"}, esc_html
($tag{'name'})) .
4036 if (defined $comment) {
4037 print format_subject_html
($comment, $comment_short,
4038 href
(action
=>"tag", hash
=>$tag{'id'}));
4041 "<td class=\"selflink\">";
4042 if ($tag{'type'} eq "tag") {
4043 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4048 "<td class=\"link\">" . " | " .
4049 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4050 if ($tag{'reftype'} eq "commit") {
4051 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4052 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4053 } elsif ($tag{'reftype'} eq "blob") {
4054 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4059 if (defined $extra) {
4061 "<td colspan=\"5\">$extra</td>\n" .
4067 sub git_heads_body
{
4068 # uses global variable $project
4069 my ($headlist, $head, $from, $to, $extra) = @_;
4070 $from = 0 unless defined $from;
4071 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4073 print "<table class=\"heads\">\n";
4075 for (my $i = $from; $i <= $to; $i++) {
4076 my $entry = $headlist->[$i];
4078 my $curr = $ref{'id'} eq $head;
4080 print "<tr class=\"dark\">\n";
4082 print "<tr class=\"light\">\n";
4085 print "<td><i>$ref{'age'}</i></td>\n" .
4086 ($curr ? "<td class=\"current_head\">" : "<td>") .
4087 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4088 -class => "list name"},esc_html
($ref{'name'})) .
4090 "<td class=\"link\">" .
4091 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4092 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4093 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4097 if (defined $extra) {
4099 "<td colspan=\"3\">$extra</td>\n" .
4105 sub git_search_grep_body
{
4106 my ($commitlist, $from, $to, $extra) = @_;
4107 $from = 0 unless defined $from;
4108 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4110 print "<table class=\"commit_search\">\n";
4112 for (my $i = $from; $i <= $to; $i++) {
4113 my %co = %{$commitlist->[$i]};
4117 my $commit = $co{'id'};
4119 print "<tr class=\"dark\">\n";
4121 print "<tr class=\"light\">\n";
4124 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4125 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4126 "<td><i>" . $author . "</i></td>\n" .
4128 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4129 -class => "list subject"},
4130 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4131 my $comment = $co{'comment'};
4132 foreach my $line (@$comment) {
4133 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4134 my ($lead, $match, $trail) = ($1, $2, $3);
4135 $match = chop_str
($match, 70, 5, 'center');
4136 my $contextlen = int((80 - length($match))/2);
4137 $contextlen = 30 if ($contextlen > 30);
4138 $lead = chop_str
($lead, $contextlen, 10, 'left');
4139 $trail = chop_str
($trail, $contextlen, 10, 'right');
4141 $lead = esc_html
($lead);
4142 $match = esc_html
($match);
4143 $trail = esc_html
($trail);
4145 print "$lead<span class=\"match\">$match</span>$trail<br />";
4149 "<td class=\"link\">" .
4150 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4152 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4154 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4158 if (defined $extra) {
4160 "<td colspan=\"3\">$extra</td>\n" .
4166 ## ======================================================================
4167 ## ======================================================================
4170 sub git_project_list
{
4171 my $order = $input_params{'order'};
4172 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4173 die_error
(400, "Unknown order parameter");
4176 my @list = git_get_projects_list
();
4178 die_error
(404, "No projects found");
4182 if (-f
$home_text) {
4183 print "<div class=\"index_include\">\n";
4184 open (my $fd, $home_text);
4189 print $cgi->startform(-method => "get") .
4190 "<p class=\"projsearch\">Search:\n" .
4191 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4193 $cgi->end_form() . "\n";
4194 git_project_list_body
(\
@list, $order);
4199 my $order = $input_params{'order'};
4200 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4201 die_error
(400, "Unknown order parameter");
4204 my @list = git_get_projects_list
($project);
4206 die_error
(404, "No forks found");
4210 git_print_page_nav
('','');
4211 git_print_header_div
('summary', "$project forks");
4212 git_project_list_body
(\
@list, $order);
4216 sub git_project_index
{
4217 my @projects = git_get_projects_list
($project);
4220 -type
=> 'text/plain',
4221 -charset
=> 'utf-8',
4222 -content_disposition
=> 'inline; filename="index.aux"');
4224 foreach my $pr (@projects) {
4225 if (!exists $pr->{'owner'}) {
4226 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4229 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4230 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4231 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4232 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4236 print "$path $owner\n";
4241 my $descr = git_get_project_description
($project) || "none";
4242 my %co = parse_commit
("HEAD");
4243 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4244 my $head = $co{'id'};
4246 my $owner = git_get_project_owner
($project);
4248 my $refs = git_get_references
();
4249 # These get_*_list functions return one more to allow us to see if
4250 # there are more ...
4251 my @taglist = git_get_tags_list
(16);
4252 my @headlist = git_get_heads_list
(16);
4254 my ($check_forks) = gitweb_check_feature
('forks');
4257 @forklist = git_get_projects_list
($project);
4261 git_print_page_nav
('summary','', $head);
4263 print "<div class=\"title\"> </div>\n";
4264 print "<table class=\"projects_list\">\n" .
4265 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4266 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4267 if (defined $cd{'rfc2822'}) {
4268 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4271 # use per project git URL list in $projectroot/$project/cloneurl
4272 # or make project git URL from git base URL and project name
4273 my $url_tag = "URL";
4274 my @url_list = git_get_project_url_list
($project);
4275 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4276 foreach my $git_url (@url_list) {
4277 next unless $git_url;
4278 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4283 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4285 my $ctags = git_get_project_ctags
($project);
4286 my $cloud = git_populate_project_tagcloud
($ctags);
4287 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4288 print "</td>\n<td>" unless %$ctags;
4289 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4290 print "</td>\n<td>" if %$ctags;
4291 print git_show_project_tagcloud
($cloud, 48);
4297 if (-s
"$projectroot/$project/README.html") {
4298 if (open my $fd, "$projectroot/$project/README.html") {
4299 print "<div class=\"title\">readme</div>\n" .
4300 "<div class=\"readme\">\n";
4301 print $_ while (<$fd>);
4302 print "\n</div>\n"; # class="readme"
4307 # we need to request one more than 16 (0..15) to check if
4309 my @commitlist = $head ? parse_commits
($head, 17) : ();
4311 git_print_header_div
('shortlog');
4312 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4313 $#commitlist <= 15 ? undef :
4314 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4318 git_print_header_div
('tags');
4319 git_tags_body
(\
@taglist, 0, 15,
4320 $#taglist <= 15 ? undef :
4321 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4325 git_print_header_div
('heads');
4326 git_heads_body
(\
@headlist, $head, 0, 15,
4327 $#headlist <= 15 ? undef :
4328 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4332 git_print_header_div
('forks');
4333 git_project_list_body
(\
@forklist, 'age', 0, 15,
4334 $#forklist <= 15 ? undef :
4335 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4343 my $head = git_get_head_hash
($project);
4345 git_print_page_nav
('','', $head,undef,$head);
4346 my %tag = parse_tag
($hash);
4349 die_error
(404, "Unknown tag object");
4352 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4353 print "<div class=\"title_text\">\n" .
4354 "<table class=\"object_header\">\n" .
4356 "<td>object</td>\n" .
4357 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4358 $tag{'object'}) . "</td>\n" .
4359 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4360 $tag{'type'}) . "</td>\n" .
4362 if (defined($tag{'author'})) {
4363 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4364 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4365 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4366 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4369 print "</table>\n\n" .
4371 print "<div class=\"page_body\">";
4372 my $comment = $tag{'comment'};
4373 foreach my $line (@$comment) {
4375 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4385 gitweb_check_feature
('blame')
4386 or die_error
(403, "Blame view not allowed");
4388 die_error
(400, "No file name given") unless $file_name;
4389 $hash_base ||= git_get_head_hash
($project);
4390 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4391 my %co = parse_commit
($hash_base)
4392 or die_error
(404, "Commit not found");
4393 if (!defined $hash) {
4394 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4395 or die_error
(404, "Error looking up file");
4397 $ftype = git_get_type
($hash);
4398 if ($ftype !~ "blob") {
4399 die_error
(400, "Object is not a blob");
4401 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4402 $file_name, $hash_base)
4403 or die_error
(500, "Open git-blame failed");
4406 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4409 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4412 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4414 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4415 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4416 git_print_page_path
($file_name, $ftype, $hash_base);
4417 my @rev_color = (qw(light2 dark2));
4418 my $num_colors = scalar(@rev_color);
4419 my $current_color = 0;
4422 <div class="page_body">
4423 <table class="blame">
4424 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4429 last unless defined $_;
4430 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4431 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4432 if (!exists $metainfo{$full_rev}) {
4433 $metainfo{$full_rev} = {};
4435 my $meta = $metainfo{$full_rev};
4438 if (/^(\S+) (.*)$/) {
4444 my $rev = substr($full_rev, 0, 8);
4445 my $author = $meta->{'author'};
4446 my %date = parse_date
($meta->{'author-time'},
4447 $meta->{'author-tz'});
4448 my $date = $date{'iso-tz'};
4450 $current_color = ++$current_color % $num_colors;
4452 print "<tr class=\"$rev_color[$current_color]\">\n";
4454 print "<td class=\"sha1\"";
4455 print " title=\"". esc_html
($author) . ", $date\"";
4456 print " rowspan=\"$group_size\"" if ($group_size > 1);
4458 print $cgi->a({-href
=> href
(action
=>"commit",
4460 file_name
=>$file_name)},
4464 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4465 or die_error
(500, "Open git-rev-parse failed");
4466 my $parent_commit = <$dd>;
4468 chomp($parent_commit);
4469 my $blamed = href
(action
=> 'blame',
4470 file_name
=> $meta->{'filename'},
4471 hash_base
=> $parent_commit);
4472 print "<td class=\"linenr\">";
4473 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4475 -class => "linenr" },
4478 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4484 or print "Reading blob failed\n";
4489 my $head = git_get_head_hash
($project);
4491 git_print_page_nav
('','', $head,undef,$head);
4492 git_print_header_div
('summary', $project);
4494 my @tagslist = git_get_tags_list
();
4496 git_tags_body
(\
@tagslist);
4502 my $head = git_get_head_hash
($project);
4504 git_print_page_nav
('','', $head,undef,$head);
4505 git_print_header_div
('summary', $project);
4507 my @headslist = git_get_heads_list
();
4509 git_heads_body
(\
@headslist, $head);
4514 sub git_blob_plain
{
4518 if (!defined $hash) {
4519 if (defined $file_name) {
4520 my $base = $hash_base || git_get_head_hash
($project);
4521 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4522 or die_error
(404, "Cannot find file");
4524 die_error
(400, "No file name defined");
4526 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4527 # blobs defined by non-textual hash id's can be cached
4531 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4532 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4534 # content-type (can include charset)
4535 $type = blob_contenttype
($fd, $file_name, $type);
4537 # "save as" filename, even when no $file_name is given
4538 my $save_as = "$hash";
4539 if (defined $file_name) {
4540 $save_as = $file_name;
4541 } elsif ($type =~ m/^text\//) {
4547 -expires
=> $expires,
4548 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4550 binmode STDOUT
, ':raw';
4552 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4560 if (!defined $hash) {
4561 if (defined $file_name) {
4562 my $base = $hash_base || git_get_head_hash
($project);
4563 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4564 or die_error
(404, "Cannot find file");
4566 die_error
(400, "No file name defined");
4568 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4569 # blobs defined by non-textual hash id's can be cached
4573 my ($have_blame) = gitweb_check_feature
('blame');
4574 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4575 or die_error
(500, "Couldn't cat $file_name, $hash");
4576 my $mimetype = blob_mimetype
($fd, $file_name);
4577 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4579 return git_blob_plain
($mimetype);
4581 # we can have blame only for text/* mimetype
4582 $have_blame &&= ($mimetype =~ m!^text/!);
4584 git_header_html
(undef, $expires);
4585 my $formats_nav = '';
4586 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4587 if (defined $file_name) {
4590 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4595 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4598 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4601 $cgi->a({-href
=> href
(action
=>"blob",
4602 hash_base
=>"HEAD", file_name
=>$file_name)},
4606 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4609 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4610 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4612 print "<div class=\"page_nav\">\n" .
4613 "<br/><br/></div>\n" .
4614 "<div class=\"title\">$hash</div>\n";
4616 git_print_page_path
($file_name, "blob", $hash_base);
4617 print "<div class=\"page_body\">\n";
4618 if ($mimetype =~ m!^image/!) {
4619 print qq
!<img type
="$mimetype"!;
4621 print qq
! alt
="$file_name" title
="$file_name"!;
4624 href(action=>"blob_plain
", hash=>$hash,
4625 hash_base=>$hash_base, file_name=>$file_name) .
4629 while (my $line = <$fd>) {
4632 $line = untabify
($line);
4633 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4634 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4638 or print "Reading blob failed.\n";
4644 if (!defined $hash_base) {
4645 $hash_base = "HEAD";
4647 if (!defined $hash) {
4648 if (defined $file_name) {
4649 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4654 die_error
(404, "No such tree") unless defined($hash);
4656 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4657 or die_error
(500, "Open git-ls-tree failed");
4658 my @entries = map { chomp; $_ } <$fd>;
4659 close $fd or die_error
(404, "Reading tree failed");
4662 my $refs = git_get_references
();
4663 my $ref = format_ref_marker
($refs, $hash_base);
4666 my ($have_blame) = gitweb_check_feature
('blame');
4667 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4669 if (defined $file_name) {
4671 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4673 $cgi->a({-href
=> href
(action
=>"tree",
4674 hash_base
=>"HEAD", file_name
=>$file_name)},
4677 my $snapshot_links = format_snapshot_links
($hash);
4678 if (defined $snapshot_links) {
4679 # FIXME: Should be available when we have no hash base as well.
4680 push @views_nav, $snapshot_links;
4682 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4683 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4686 print "<div class=\"page_nav\">\n";
4687 print "<br/><br/></div>\n";
4688 print "<div class=\"title\">$hash</div>\n";
4690 if (defined $file_name) {
4691 $basedir = $file_name;
4692 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4695 git_print_page_path
($file_name, 'tree', $hash_base);
4697 print "<div class=\"page_body\">\n";
4698 print "<table class=\"tree\">\n";
4700 # '..' (top directory) link if possible
4701 if (defined $hash_base &&
4702 defined $file_name && $file_name =~ m![^/]+$!) {
4704 print "<tr class=\"dark\">\n";
4706 print "<tr class=\"light\">\n";
4710 my $up = $file_name;
4711 $up =~ s!/?[^/]+$!!;
4712 undef $up unless $up;
4713 # based on git_print_tree_entry
4714 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4715 print '<td class="list">';
4716 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4720 print "<td class=\"link\"></td>\n";
4724 foreach my $line (@entries) {
4725 my %t = parse_ls_tree_line
($line, -z
=> 1);
4728 print "<tr class=\"dark\">\n";
4730 print "<tr class=\"light\">\n";
4734 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4738 print "</table>\n" .
4744 my @supported_fmts = gitweb_check_feature
('snapshot');
4745 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4747 my $format = $input_params{'snapshot_format'};
4748 if (!@supported_fmts) {
4749 die_error
(403, "Snapshots not allowed");
4751 # default to first supported snapshot format
4752 $format ||= $supported_fmts[0];
4753 if ($format !~ m/^[a-z0-9]+$/) {
4754 die_error
(400, "Invalid snapshot format parameter");
4755 } elsif (!exists($known_snapshot_formats{$format})) {
4756 die_error
(400, "Unknown snapshot format");
4757 } elsif (!grep($_ eq $format, @supported_fmts)) {
4758 die_error
(403, "Unsupported snapshot format");
4761 if (!defined $hash) {
4762 $hash = git_get_head_hash
($project);
4765 my $name = $project;
4766 $name =~ s
,([^/])/*\
.git
$,$1,;
4767 $name = basename
($name);
4768 my $filename = to_utf8
($name);
4769 $name =~ s/\047/\047\\\047\047/g;
4771 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4772 $cmd = quote_command
(
4773 git_cmd
(), 'archive',
4774 "--format=$known_snapshot_formats{$format}{'format'}",
4775 "--prefix=$name/", $hash);
4776 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4777 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4781 -type
=> $known_snapshot_formats{$format}{'type'},
4782 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4783 -status
=> '200 OK');
4785 open my $fd, "-|", $cmd
4786 or die_error
(500, "Execute git-archive failed");
4787 binmode STDOUT
, ':raw';
4789 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4794 my $head = git_get_head_hash
($project);
4795 if (!defined $hash) {
4798 if (!defined $page) {
4801 my $refs = git_get_references
();
4803 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4805 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4808 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4811 my %co = parse_commit
($hash);
4813 git_print_header_div
('summary', $project);
4814 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4816 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4817 for (my $i = 0; $i <= $to; $i++) {
4818 my %co = %{$commitlist[$i]};
4820 my $commit = $co{'id'};
4821 my $ref = format_ref_marker
($refs, $commit);
4822 my %ad = parse_date
($co{'author_epoch'});
4823 git_print_header_div
('commit',
4824 "<span class=\"age\">$co{'age_string'}</span>" .
4825 esc_html
($co{'title'}) . $ref,
4827 print "<div class=\"title_text\">\n" .
4828 "<div class=\"log_link\">\n" .
4829 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4831 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4833 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4836 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4839 print "<div class=\"log_body\">\n";
4840 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4843 if ($#commitlist >= 100) {
4844 print "<div class=\"page_nav\">\n";
4845 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4846 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4853 $hash ||= $hash_base || "HEAD";
4854 my %co = parse_commit
($hash)
4855 or die_error
(404, "Unknown commit object");
4856 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4857 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4859 my $parent = $co{'parent'};
4860 my $parents = $co{'parents'}; # listref
4862 # we need to prepare $formats_nav before any parameter munging
4864 if (!defined $parent) {
4866 $formats_nav .= '(initial)';
4867 } elsif (@$parents == 1) {
4868 # single parent commit
4871 $cgi->a({-href
=> href
(action
=>"commit",
4873 esc_html
(substr($parent, 0, 7))) .
4880 $cgi->a({-href
=> href
(action
=>"commit",
4882 esc_html
(substr($_, 0, 7)));
4887 if (!defined $parent) {
4891 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4893 (@$parents <= 1 ? $parent : '-c'),
4895 or die_error
(500, "Open git-diff-tree failed");
4896 @difftree = map { chomp; $_ } <$fd>;
4897 close $fd or die_error
(404, "Reading git-diff-tree failed");
4899 # non-textual hash id's can be cached
4901 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4904 my $refs = git_get_references
();
4905 my $ref = format_ref_marker
($refs, $co{'id'});
4907 git_header_html
(undef, $expires);
4908 git_print_page_nav
('commit', '',
4909 $hash, $co{'tree'}, $hash,
4912 if (defined $co{'parent'}) {
4913 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4915 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4917 print "<div class=\"title_text\">\n" .
4918 "<table class=\"object_header\">\n";
4919 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4921 "<td></td><td> $ad{'rfc2822'}";
4922 if ($ad{'hour_local'} < 6) {
4923 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4924 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4926 printf(" (%02d:%02d %s)",
4927 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4931 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4932 print "<tr><td></td><td> $cd{'rfc2822'}" .
4933 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4935 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4938 "<td class=\"sha1\">" .
4939 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4940 class => "list"}, $co{'tree'}) .
4942 "<td class=\"link\">" .
4943 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4945 my $snapshot_links = format_snapshot_links
($hash);
4946 if (defined $snapshot_links) {
4947 print " | " . $snapshot_links;
4952 foreach my $par (@$parents) {
4955 "<td class=\"sha1\">" .
4956 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4957 class => "list"}, $par) .
4959 "<td class=\"link\">" .
4960 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4962 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4969 print "<div class=\"page_body\">\n";
4970 git_print_log
($co{'comment'});
4973 git_difftree_body
(\
@difftree, $hash, @$parents);
4979 # object is defined by:
4980 # - hash or hash_base alone
4981 # - hash_base and file_name
4984 # - hash or hash_base alone
4985 if ($hash || ($hash_base && !defined $file_name)) {
4986 my $object_id = $hash || $hash_base;
4988 open my $fd, "-|", quote_command
(
4989 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4990 or die_error
(404, "Object does not exist");
4994 or die_error
(404, "Object does not exist");
4996 # - hash_base and file_name
4997 } elsif ($hash_base && defined $file_name) {
4998 $file_name =~ s
,/+$,,;
5000 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5001 or die_error
(404, "Base object does not exist");
5003 # here errors should not hapen
5004 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5005 or die_error
(500, "Open git-ls-tree failed");
5009 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5010 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5011 die_error
(404, "File or directory for given base does not exist");
5016 die_error
(400, "Not enough information to find object");
5019 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5020 hash
=>$hash, hash_base
=>$hash_base,
5021 file_name
=>$file_name),
5022 -status
=> '302 Found');
5026 my $format = shift || 'html';
5033 # preparing $fd and %diffinfo for git_patchset_body
5035 if (defined $hash_base && defined $hash_parent_base) {
5036 if (defined $file_name) {
5038 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5039 $hash_parent_base, $hash_base,
5040 "--", (defined $file_parent ? $file_parent : ()), $file_name
5041 or die_error
(500, "Open git-diff-tree failed");
5042 @difftree = map { chomp; $_ } <$fd>;
5044 or die_error
(404, "Reading git-diff-tree failed");
5046 or die_error
(404, "Blob diff not found");
5048 } elsif (defined $hash &&
5049 $hash =~ /[0-9a-fA-F]{40}/) {
5050 # try to find filename from $hash
5052 # read filtered raw output
5053 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5054 $hash_parent_base, $hash_base, "--"
5055 or die_error
(500, "Open git-diff-tree failed");
5057 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5059 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5060 map { chomp; $_ } <$fd>;
5062 or die_error
(404, "Reading git-diff-tree failed");
5064 or die_error
(404, "Blob diff not found");
5067 die_error
(400, "Missing one of the blob diff parameters");
5070 if (@difftree > 1) {
5071 die_error
(400, "Ambiguous blob diff specification");
5074 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5075 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5076 $file_name ||= $diffinfo{'to_file'};
5078 $hash_parent ||= $diffinfo{'from_id'};
5079 $hash ||= $diffinfo{'to_id'};
5081 # non-textual hash id's can be cached
5082 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5083 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5088 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5089 '-p', ($format eq 'html' ? "--full-index" : ()),
5090 $hash_parent_base, $hash_base,
5091 "--", (defined $file_parent ? $file_parent : ()), $file_name
5092 or die_error
(500, "Open git-diff-tree failed");
5095 # old/legacy style URI
5096 if (!%diffinfo && # if new style URI failed
5097 defined $hash && defined $hash_parent) {
5098 # fake git-diff-tree raw output
5099 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5100 $diffinfo{'from_id'} = $hash_parent;
5101 $diffinfo{'to_id'} = $hash;
5102 if (defined $file_name) {
5103 if (defined $file_parent) {
5104 $diffinfo{'status'} = '2';
5105 $diffinfo{'from_file'} = $file_parent;
5106 $diffinfo{'to_file'} = $file_name;
5107 } else { # assume not renamed
5108 $diffinfo{'status'} = '1';
5109 $diffinfo{'from_file'} = $file_name;
5110 $diffinfo{'to_file'} = $file_name;
5112 } else { # no filename given
5113 $diffinfo{'status'} = '2';
5114 $diffinfo{'from_file'} = $hash_parent;
5115 $diffinfo{'to_file'} = $hash;
5118 # non-textual hash id's can be cached
5119 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5120 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5125 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5126 '-p', ($format eq 'html' ? "--full-index" : ()),
5127 $hash_parent, $hash, "--"
5128 or die_error
(500, "Open git-diff failed");
5130 die_error
(400, "Missing one of the blob diff parameters")
5135 if ($format eq 'html') {
5137 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5139 git_header_html
(undef, $expires);
5140 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5141 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5142 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5144 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5145 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5147 if (defined $file_name) {
5148 git_print_page_path
($file_name, "blob", $hash_base);
5150 print "<div class=\"page_path\"></div>\n";
5153 } elsif ($format eq 'plain') {
5155 -type
=> 'text/plain',
5156 -charset
=> 'utf-8',
5157 -expires
=> $expires,
5158 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5160 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5163 die_error
(400, "Unknown blobdiff format");
5167 if ($format eq 'html') {
5168 print "<div class=\"page_body\">\n";
5170 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5173 print "</div>\n"; # class="page_body"
5177 while (my $line = <$fd>) {
5178 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5179 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5183 last if $line =~ m!^\+\+\+!;
5191 sub git_blobdiff_plain
{
5192 git_blobdiff
('plain');
5195 sub git_commitdiff
{
5196 my $format = shift || 'html';
5197 $hash ||= $hash_base || "HEAD";
5198 my %co = parse_commit
($hash)
5199 or die_error
(404, "Unknown commit object");
5201 # choose format for commitdiff for merge
5202 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5203 $hash_parent = '--cc';
5205 # we need to prepare $formats_nav before almost any parameter munging
5207 if ($format eq 'html') {
5209 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5212 if (defined $hash_parent &&
5213 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5214 # commitdiff with two commits given
5215 my $hash_parent_short = $hash_parent;
5216 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5217 $hash_parent_short = substr($hash_parent, 0, 7);
5221 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5222 if ($co{'parents'}[$i] eq $hash_parent) {
5223 $formats_nav .= ' parent ' . ($i+1);
5227 $formats_nav .= ': ' .
5228 $cgi->a({-href
=> href
(action
=>"commitdiff",
5229 hash
=>$hash_parent)},
5230 esc_html
($hash_parent_short)) .
5232 } elsif (!$co{'parent'}) {
5234 $formats_nav .= ' (initial)';
5235 } elsif (scalar @{$co{'parents'}} == 1) {
5236 # single parent commit
5239 $cgi->a({-href
=> href
(action
=>"commitdiff",
5240 hash
=>$co{'parent'})},
5241 esc_html
(substr($co{'parent'}, 0, 7))) .
5245 if ($hash_parent eq '--cc') {
5246 $formats_nav .= ' | ' .
5247 $cgi->a({-href
=> href
(action
=>"commitdiff",
5248 hash
=>$hash, hash_parent
=>'-c')},
5250 } else { # $hash_parent eq '-c'
5251 $formats_nav .= ' | ' .
5252 $cgi->a({-href
=> href
(action
=>"commitdiff",
5253 hash
=>$hash, hash_parent
=>'--cc')},
5259 $cgi->a({-href
=> href
(action
=>"commitdiff",
5261 esc_html
(substr($_, 0, 7)));
5262 } @{$co{'parents'}} ) .
5267 my $hash_parent_param = $hash_parent;
5268 if (!defined $hash_parent_param) {
5269 # --cc for multiple parents, --root for parentless
5270 $hash_parent_param =
5271 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5277 if ($format eq 'html') {
5278 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5279 "--no-commit-id", "--patch-with-raw", "--full-index",
5280 $hash_parent_param, $hash, "--"
5281 or die_error
(500, "Open git-diff-tree failed");
5283 while (my $line = <$fd>) {
5285 # empty line ends raw part of diff-tree output
5287 push @difftree, scalar parse_difftree_raw_line
($line);
5290 } elsif ($format eq 'plain') {
5291 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5292 '-p', $hash_parent_param, $hash, "--"
5293 or die_error
(500, "Open git-diff-tree failed");
5296 die_error
(400, "Unknown commitdiff format");
5299 # non-textual hash id's can be cached
5301 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5305 # write commit message
5306 if ($format eq 'html') {
5307 my $refs = git_get_references
();
5308 my $ref = format_ref_marker
($refs, $co{'id'});
5310 git_header_html
(undef, $expires);
5311 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5312 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5313 git_print_authorship
(\
%co);
5314 print "<div class=\"page_body\">\n";
5315 if (@{$co{'comment'}} > 1) {
5316 print "<div class=\"log\">\n";
5317 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5318 print "</div>\n"; # class="log"
5321 } elsif ($format eq 'plain') {
5322 my $refs = git_get_references
("tags");
5323 my $tagname = git_get_rev_name_tags
($hash);
5324 my $filename = basename
($project) . "-$hash.patch";
5327 -type
=> 'text/plain',
5328 -charset
=> 'utf-8',
5329 -expires
=> $expires,
5330 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5331 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5332 print "From: " . to_utf8
($co{'author'}) . "\n";
5333 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5334 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5336 print "X-Git-Tag: $tagname\n" if $tagname;
5337 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5339 foreach my $line (@{$co{'comment'}}) {
5340 print to_utf8
($line) . "\n";
5346 if ($format eq 'html') {
5347 my $use_parents = !defined $hash_parent ||
5348 $hash_parent eq '-c' || $hash_parent eq '--cc';
5349 git_difftree_body
(\
@difftree, $hash,
5350 $use_parents ? @{$co{'parents'}} : $hash_parent);
5353 git_patchset_body
($fd, \
@difftree, $hash,
5354 $use_parents ? @{$co{'parents'}} : $hash_parent);
5356 print "</div>\n"; # class="page_body"
5359 } elsif ($format eq 'plain') {
5363 or print "Reading git-diff-tree failed\n";
5367 sub git_commitdiff_plain
{
5368 git_commitdiff
('plain');
5372 if (!defined $hash_base) {
5373 $hash_base = git_get_head_hash
($project);
5375 if (!defined $page) {
5379 my %co = parse_commit
($hash_base)
5380 or die_error
(404, "Unknown commit object");
5382 my $refs = git_get_references
();
5383 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5385 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5386 $file_name, "--full-history")
5387 or die_error
(404, "No such file or directory on given branch");
5389 if (!defined $hash && defined $file_name) {
5390 # some commits could have deleted file in question,
5391 # and not have it in tree, but one of them has to have it
5392 for (my $i = 0; $i <= @commitlist; $i++) {
5393 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5394 last if defined $hash;
5397 if (defined $hash) {
5398 $ftype = git_get_type
($hash);
5400 if (!defined $ftype) {
5401 die_error
(500, "Unknown type of object");
5404 my $paging_nav = '';
5407 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5408 file_name
=>$file_name)},
5410 $paging_nav .= " ⋅ " .
5411 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5412 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5414 $paging_nav .= "first";
5415 $paging_nav .= " ⋅ prev";
5418 if ($#commitlist >= 100) {
5420 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5421 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5422 $paging_nav .= " ⋅ $next_link";
5424 $paging_nav .= " ⋅ next";
5428 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5429 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5430 git_print_page_path
($file_name, $ftype, $hash_base);
5432 git_history_body
(\
@commitlist, 0, 99,
5433 $refs, $hash_base, $ftype, $next_link);
5439 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5440 if (!defined $searchtext) {
5441 die_error
(400, "Text field is empty");
5443 if (!defined $hash) {
5444 $hash = git_get_head_hash
($project);
5446 my %co = parse_commit
($hash);
5448 die_error
(404, "Unknown commit object");
5450 if (!defined $page) {
5454 $searchtype ||= 'commit';
5455 if ($searchtype eq 'pickaxe') {
5456 # pickaxe may take all resources of your box and run for several minutes
5457 # with every query - so decide by yourself how public you make this feature
5458 gitweb_check_feature
('pickaxe')
5459 or die_error
(403, "Pickaxe is disabled");
5461 if ($searchtype eq 'grep') {
5462 gitweb_check_feature
('grep')
5463 or die_error
(403, "Grep is disabled");
5468 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5470 if ($searchtype eq 'commit') {
5471 $greptype = "--grep=";
5472 } elsif ($searchtype eq 'author') {
5473 $greptype = "--author=";
5474 } elsif ($searchtype eq 'committer') {
5475 $greptype = "--committer=";
5477 $greptype .= $searchtext;
5478 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5479 $greptype, '--regexp-ignore-case',
5480 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5482 my $paging_nav = '';
5485 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5486 searchtext
=>$searchtext,
5487 searchtype
=>$searchtype)},
5489 $paging_nav .= " ⋅ " .
5490 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5491 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5493 $paging_nav .= "first";
5494 $paging_nav .= " ⋅ prev";
5497 if ($#commitlist >= 100) {
5499 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5500 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5501 $paging_nav .= " ⋅ $next_link";
5503 $paging_nav .= " ⋅ next";
5506 if ($#commitlist >= 100) {
5509 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5510 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5511 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5514 if ($searchtype eq 'pickaxe') {
5515 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5516 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5518 print "<table class=\"pickaxe search\">\n";
5521 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5522 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5523 ($search_use_regexp ? '--pickaxe-regex' : ());
5526 while (my $line = <$fd>) {
5530 my %set = parse_difftree_raw_line
($line);
5531 if (defined $set{'commit'}) {
5532 # finish previous commit
5535 "<td class=\"link\">" .
5536 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5538 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5544 print "<tr class=\"dark\">\n";
5546 print "<tr class=\"light\">\n";
5549 %co = parse_commit
($set{'commit'});
5550 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5551 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5552 "<td><i>$author</i></td>\n" .
5554 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5555 -class => "list subject"},
5556 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5557 } elsif (defined $set{'to_id'}) {
5558 next if ($set{'to_id'} =~ m/^0{40}$/);
5560 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5561 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5563 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5569 # finish last commit (warning: repetition!)
5572 "<td class=\"link\">" .
5573 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5575 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5583 if ($searchtype eq 'grep') {
5584 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5585 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5587 print "<table class=\"grep_search\">\n";
5591 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5592 $search_use_regexp ? ('-E', '-i') : '-F',
5593 $searchtext, $co{'tree'};
5595 while (my $line = <$fd>) {
5597 my ($file, $lno, $ltext, $binary);
5598 last if ($matches++ > 1000);
5599 if ($line =~ /^Binary file (.+) matches$/) {
5603 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5605 if ($file ne $lastfile) {
5606 $lastfile and print "</td></tr>\n";
5608 print "<tr class=\"dark\">\n";
5610 print "<tr class=\"light\">\n";
5612 print "<td class=\"list\">".
5613 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5614 file_name
=>"$file"),
5615 -class => "list"}, esc_path
($file));
5616 print "</td><td>\n";
5620 print "<div class=\"binary\">Binary file</div>\n";
5622 $ltext = untabify
($ltext);
5623 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5624 $ltext = esc_html
($1, -nbsp
=>1);
5625 $ltext .= '<span class="match">';
5626 $ltext .= esc_html
($2, -nbsp
=>1);
5627 $ltext .= '</span>';
5628 $ltext .= esc_html
($3, -nbsp
=>1);
5630 $ltext = esc_html
($ltext, -nbsp
=>1);
5632 print "<div class=\"pre\">" .
5633 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5634 file_name
=>"$file").'#l'.$lno,
5635 -class => "linenr"}, sprintf('%4i', $lno))
5636 . ' ' . $ltext . "</div>\n";
5640 print "</td></tr>\n";
5641 if ($matches > 1000) {
5642 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5645 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5654 sub git_search_help
{
5656 git_print_page_nav
('','', $hash,$hash,$hash);
5658 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5659 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5660 the pattern entered is recognized as the POSIX extended
5661 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5664 <dt><b>commit</b></dt>
5665 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5667 my ($have_grep) = gitweb_check_feature
('grep');
5670 <dt><b>grep</b></dt>
5671 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5672 a different one) are searched for the given pattern. On large trees, this search can take
5673 a while and put some strain on the server, so please use it with some consideration. Note that
5674 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5675 case-sensitive.</dd>
5679 <dt><b>author</b></dt>
5680 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5681 <dt><b>committer</b></dt>
5682 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5684 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5685 if ($have_pickaxe) {
5687 <dt><b>pickaxe</b></dt>
5688 <dd>All commits that caused the string to appear or disappear from any file (changes that
5689 added, removed or "modified" the string) will be listed. This search can take a while and
5690 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5691 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5699 my $head = git_get_head_hash
($project);
5700 if (!defined $hash) {
5703 if (!defined $page) {
5706 my $refs = git_get_references
();
5708 my $commit_hash = $hash;
5709 if (defined $hash_parent) {
5710 $commit_hash = "$hash_parent..$hash";
5712 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5714 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5716 if ($#commitlist >= 100) {
5718 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5719 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5723 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5724 git_print_header_div
('summary', $project);
5726 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5731 ## ......................................................................
5732 ## feeds (RSS, Atom; OPML)
5735 my $format = shift || 'atom';
5736 my ($have_blame) = gitweb_check_feature
('blame');
5738 # Atom: http://www.atomenabled.org/developers/syndication/
5739 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5740 if ($format ne 'rss' && $format ne 'atom') {
5741 die_error
(400, "Unknown web feed format");
5744 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5745 my $head = $hash || 'HEAD';
5746 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5750 my $content_type = "application/$format+xml";
5751 if (defined $cgi->http('HTTP_ACCEPT') &&
5752 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5753 # browser (feed reader) prefers text/xml
5754 $content_type = 'text/xml';
5756 if (defined($commitlist[0])) {
5757 %latest_commit = %{$commitlist[0]};
5758 %latest_date = parse_date
($latest_commit{'author_epoch'});
5760 -type
=> $content_type,
5761 -charset
=> 'utf-8',
5762 -last_modified
=> $latest_date{'rfc2822'});
5765 -type
=> $content_type,
5766 -charset
=> 'utf-8');
5769 # Optimization: skip generating the body if client asks only
5770 # for Last-Modified date.
5771 return if ($cgi->request_method() eq 'HEAD');
5774 my $title = "$site_name - $project/$action";
5775 my $feed_type = 'log';
5776 if (defined $hash) {
5777 $title .= " - '$hash'";
5778 $feed_type = 'branch log';
5779 if (defined $file_name) {
5780 $title .= " :: $file_name";
5781 $feed_type = 'history';
5783 } elsif (defined $file_name) {
5784 $title .= " - $file_name";
5785 $feed_type = 'history';
5787 $title .= " $feed_type";
5788 my $descr = git_get_project_description
($project);
5789 if (defined $descr) {
5790 $descr = esc_html
($descr);
5792 $descr = "$project " .
5793 ($format eq 'rss' ? 'RSS' : 'Atom') .
5796 my $owner = git_get_project_owner
($project);
5797 $owner = esc_html
($owner);
5801 if (defined $file_name) {
5802 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5803 } elsif (defined $hash) {
5804 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5806 $alt_url = href
(-full
=>1, action
=>"summary");
5808 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5809 if ($format eq 'rss') {
5811 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5814 print "<title>$title</title>\n" .
5815 "<link>$alt_url</link>\n" .
5816 "<description>$descr</description>\n" .
5817 "<language>en</language>\n";
5818 } elsif ($format eq 'atom') {
5820 <feed xmlns="http://www.w3.org/2005/Atom">
5822 print "<title>$title</title>\n" .
5823 "<subtitle>$descr</subtitle>\n" .
5824 '<link rel="alternate" type="text/html" href="' .
5825 $alt_url . '" />' . "\n" .
5826 '<link rel="self" type="' . $content_type . '" href="' .
5827 $cgi->self_url() . '" />' . "\n" .
5828 "<id>" . href
(-full
=>1) . "</id>\n" .
5829 # use project owner for feed author
5830 "<author><name>$owner</name></author>\n";
5831 if (defined $favicon) {
5832 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5834 if (defined $logo_url) {
5835 # not twice as wide as tall: 72 x 27 pixels
5836 print "<logo>" . esc_url
($logo) . "</logo>\n";
5838 if (! %latest_date) {
5839 # dummy date to keep the feed valid until commits trickle in:
5840 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5842 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5847 for (my $i = 0; $i <= $#commitlist; $i++) {
5848 my %co = %{$commitlist[$i]};
5849 my $commit = $co{'id'};
5850 # we read 150, we always show 30 and the ones more recent than 48 hours
5851 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5854 my %cd = parse_date
($co{'author_epoch'});
5856 # get list of changed files
5857 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5858 $co{'parent'} || "--root",
5859 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5861 my @difftree = map { chomp; $_ } <$fd>;
5865 # print element (entry, item)
5866 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5867 if ($format eq 'rss') {
5869 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5870 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5871 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5872 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5873 "<link>$co_url</link>\n" .
5874 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5875 "<content:encoded>" .
5877 } elsif ($format eq 'atom') {
5879 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5880 "<updated>$cd{'iso-8601'}</updated>\n" .
5882 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5883 if ($co{'author_email'}) {
5884 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5886 print "</author>\n" .
5887 # use committer for contributor
5889 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5890 if ($co{'committer_email'}) {
5891 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5893 print "</contributor>\n" .
5894 "<published>$cd{'iso-8601'}</published>\n" .
5895 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5896 "<id>$co_url</id>\n" .
5897 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5898 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5900 my $comment = $co{'comment'};
5902 foreach my $line (@$comment) {
5903 $line = esc_html
($line);
5906 print "</pre><ul>\n";
5907 foreach my $difftree_line (@difftree) {
5908 my %difftree = parse_difftree_raw_line
($difftree_line);
5909 next if !$difftree{'from_id'};
5911 my $file = $difftree{'file'} || $difftree{'to_file'};
5915 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5916 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5917 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5918 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5919 -title
=> "diff"}, 'D');
5921 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5922 file_name
=>$file, hash_base
=>$commit),
5923 -title
=> "blame"}, 'B');
5925 # if this is not a feed of a file history
5926 if (!defined $file_name || $file_name ne $file) {
5927 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5928 file_name
=>$file, hash
=>$commit),
5929 -title
=> "history"}, 'H');
5931 $file = esc_path
($file);
5935 if ($format eq 'rss') {
5936 print "</ul>]]>\n" .
5937 "</content:encoded>\n" .
5939 } elsif ($format eq 'atom') {
5940 print "</ul>\n</div>\n" .
5947 if ($format eq 'rss') {
5948 print "</channel>\n</rss>\n";
5949 } elsif ($format eq 'atom') {
5963 my @list = git_get_projects_list
();
5965 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5967 <?xml version="1.0" encoding="utf-8"?>
5968 <opml version="1.0">
5970 <title>$site_name OPML Export</title>
5973 <outline text="git RSS feeds">
5976 foreach my $pr (@list) {
5978 my $head = git_get_head_hash
($proj{'path'});
5979 if (!defined $head) {
5982 $git_dir = "$projectroot/$proj{'path'}";
5983 my %co = parse_commit
($head);
5988 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5989 my $rss = "$my_url?p=$proj{'path'};a=rss";
5990 my $html = "$my_url?p=$proj{'path'};a=summary";
5991 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";