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
13 use CGI
qw(:standard :escapeHTML -nosticky);
14 use CGI
::Util
qw(unescape);
15 use CGI
::Carp
qw(fatalsToBrowser set_message);
19 use File
::Basename
qw(basename);
20 use Time
::HiRes
qw(gettimeofday tv_interval);
21 binmode STDOUT
, ':utf8';
23 our $t0 = [ gettimeofday
() ];
24 our $number_of_git_cmds = 0;
27 CGI
->compile() if $ENV{'MOD_PERL'};
30 our $version = "++GIT_VERSION++";
32 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
36 our $my_url = $cgi->url();
37 our $my_uri = $cgi->url(-absolute
=> 1);
39 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
40 # needed and used only for URLs with nonempty PATH_INFO
41 our $base_url = $my_url;
43 # When the script is used as DirectoryIndex, the URL does not contain the name
44 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
45 # have to do it ourselves. We make $path_info global because it's also used
48 # Another issue with the script being the DirectoryIndex is that the resulting
49 # $my_url data is not the full script URL: this is good, because we want
50 # generated links to keep implying the script name if it wasn't explicitly
51 # indicated in the URL we're handling, but it means that $my_url cannot be used
53 # Therefore, if we needed to strip PATH_INFO, then we know that we have
54 # to build the base URL ourselves:
55 our $path_info = $ENV{"PATH_INFO"};
57 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
58 $my_uri =~ s
,\Q
$path_info\E
$,, &&
59 defined $ENV{'SCRIPT_NAME'}) {
60 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
64 # target of the home link on top of all pages
65 our $home_link = $my_uri || "/";
68 # core git executable to use
69 # this can just be "git" if your webserver has a sensible PATH
70 our $GIT = "++GIT_BINDIR++/git";
72 # absolute fs-path which will be prepended to the project path
73 #our $projectroot = "/pub/scm";
74 our $projectroot = "++GITWEB_PROJECTROOT++";
76 # fs traversing limit for getting project list
77 # the number is relative to the projectroot
78 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
80 # string of the home link on top of all pages
81 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
83 # name of your site or organization to appear in page titles
84 # replace this with something more descriptive for clearer bookmarks
85 our $site_name = "++GITWEB_SITENAME++"
86 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
88 # filename of html text to include at top of each page
89 our $site_header = "++GITWEB_SITE_HEADER++";
90 # html text to include at home page
91 our $home_text = "++GITWEB_HOMETEXT++";
92 # filename of html text to include at bottom of each page
93 our $site_footer = "++GITWEB_SITE_FOOTER++";
96 our @stylesheets = ("++GITWEB_CSS++");
97 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
98 our $stylesheet = undef;
99 # URI of GIT logo (72x27 size)
100 our $logo = "++GITWEB_LOGO++";
101 # URI of GIT favicon, assumed to be image/png type
102 our $favicon = "++GITWEB_FAVICON++";
103 # URI of gitweb.js (JavaScript code for gitweb)
104 our $javascript = "++GITWEB_JS++";
106 # URI and label (title) of GIT logo link
107 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
108 #our $logo_label = "git documentation";
109 our $logo_url = "http://git-scm.com/";
110 our $logo_label = "git homepage";
112 # source of projects list
113 our $projects_list = "++GITWEB_LIST++";
115 # the width (in characters) of the projects list "Description" column
116 our $projects_list_description_width = 25;
118 # default order of projects list
119 # valid values are none, project, descr, owner, and age
120 our $default_projects_order = "project";
122 # show repository only if this file exists
123 # (only effective if this variable evaluates to true)
124 our $export_ok = "++GITWEB_EXPORT_OK++";
126 # show repository only if this subroutine returns true
127 # when given the path to the project, for example:
128 # sub { return -e "$_[0]/git-daemon-export-ok"; }
129 our $export_auth_hook = undef;
131 # only allow viewing of repositories also shown on the overview page
132 our $strict_export = "++GITWEB_STRICT_EXPORT++";
134 # list of git base URLs used for URL to where fetch project from,
135 # i.e. full URL is "$git_base_url/$project"
136 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
138 # default blob_plain mimetype and default charset for text/plain blob
139 our $default_blob_plain_mimetype = 'text/plain';
140 our $default_text_plain_charset = undef;
142 # file to use for guessing MIME types before trying /etc/mime.types
143 # (relative to the current git repository)
144 our $mimetypes_file = undef;
146 # assume this charset if line contains non-UTF-8 characters;
147 # it should be valid encoding (see Encoding::Supported(3pm) for list),
148 # for which encoding all byte sequences are valid, for example
149 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
150 # could be even 'utf-8' for the old behavior)
151 our $fallback_encoding = 'latin1';
153 # rename detection options for git-diff and git-diff-tree
154 # - default is '-M', with the cost proportional to
155 # (number of removed files) * (number of new files).
156 # - more costly is '-C' (which implies '-M'), with the cost proportional to
157 # (number of changed files + number of removed files) * (number of new files)
158 # - even more costly is '-C', '--find-copies-harder' with cost
159 # (number of files in the original tree) * (number of new files)
160 # - one might want to include '-B' option, e.g. '-B', '-M'
161 our @diff_opts = ('-M'); # taken from git_commit
163 # Disables features that would allow repository owners to inject script into
165 our $prevent_xss = 0;
167 # Path to the highlight executable to use (must be the one from
168 # http://www.andre-simon.de due to assumptions about parameters and output).
169 # Useful if highlight is not installed on your webserver's PATH.
170 # [Default: highlight]
171 our $highlight_bin = "++HIGHLIGHT_BIN++";
173 # information about snapshot formats that gitweb is capable of serving
174 our %known_snapshot_formats = (
176 # 'display' => display name,
177 # 'type' => mime type,
178 # 'suffix' => filename suffix,
179 # 'format' => --format for git-archive,
180 # 'compressor' => [compressor command and arguments]
181 # (array reference, optional)
182 # 'disabled' => boolean (optional)}
185 'display' => 'tar.gz',
186 'type' => 'application/x-gzip',
187 'suffix' => '.tar.gz',
189 'compressor' => ['gzip']},
192 'display' => 'tar.bz2',
193 'type' => 'application/x-bzip2',
194 'suffix' => '.tar.bz2',
196 'compressor' => ['bzip2']},
199 'display' => 'tar.xz',
200 'type' => 'application/x-xz',
201 'suffix' => '.tar.xz',
203 'compressor' => ['xz'],
208 'type' => 'application/x-zip',
213 # Aliases so we understand old gitweb.snapshot values in repository
215 our %known_snapshot_format_aliases = (
220 # backward compatibility: legacy gitweb config support
221 'x-gzip' => undef, 'gz' => undef,
222 'x-bzip2' => undef, 'bz2' => undef,
223 'x-zip' => undef, '' => undef,
226 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
227 # are changed, it may be appropriate to change these values too via
234 # Used to set the maximum load that we will still respond to gitweb queries.
235 # If server load exceed this value then return "503 server busy" error.
236 # If gitweb cannot determined server load, it is taken to be 0.
237 # Leave it undefined (or set to 'undef') to turn off load checking.
240 # configuration for 'highlight' (http://www.andre-simon.de/)
242 our %highlight_basename = (
245 'SConstruct' => 'py', # SCons equivalent of Makefile
246 'Makefile' => 'make',
249 our %highlight_ext = (
250 # main extensions, defining name of syntax;
251 # see files in /usr/share/highlight/langDefs/ directory
253 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
254 # alternate extensions, see /etc/highlight/filetypes.conf
256 map { $_ => 'cpp' } qw(cxx c++ cc),
257 map { $_ => 'php' } qw(php3 php4),
258 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
260 map { $_ => 'xml' } qw(xhtml html htm),
263 # You define site-wide feature defaults here; override them with
264 # $GITWEB_CONFIG as necessary.
267 # 'sub' => feature-sub (subroutine),
268 # 'override' => allow-override (boolean),
269 # 'default' => [ default options...] (array reference)}
271 # if feature is overridable (it means that allow-override has true value),
272 # then feature-sub will be called with default options as parameters;
273 # return value of feature-sub indicates if to enable specified feature
275 # if there is no 'sub' key (no feature-sub), then feature cannot be
278 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
279 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
282 # Enable the 'blame' blob view, showing the last commit that modified
283 # each line in the file. This can be very CPU-intensive.
285 # To enable system wide have in $GITWEB_CONFIG
286 # $feature{'blame'}{'default'} = [1];
287 # To have project specific config enable override in $GITWEB_CONFIG
288 # $feature{'blame'}{'override'} = 1;
289 # and in project config gitweb.blame = 0|1;
291 'sub' => sub { feature_bool
('blame', @_) },
295 # Enable the 'snapshot' link, providing a compressed archive of any
296 # tree. This can potentially generate high traffic if you have large
299 # Value is a list of formats defined in %known_snapshot_formats that
301 # To disable system wide have in $GITWEB_CONFIG
302 # $feature{'snapshot'}{'default'} = [];
303 # To have project specific config enable override in $GITWEB_CONFIG
304 # $feature{'snapshot'}{'override'} = 1;
305 # and in project config, a comma-separated list of formats or "none"
306 # to disable. Example: gitweb.snapshot = tbz2,zip;
308 'sub' => \
&feature_snapshot
,
310 'default' => ['tgz']},
312 # Enable text search, which will list the commits which match author,
313 # committer or commit text to a given string. Enabled by default.
314 # Project specific override is not supported.
319 # Enable grep search, which will list the files in currently selected
320 # tree containing the given string. Enabled by default. This can be
321 # potentially CPU-intensive, of course.
323 # To enable system wide have in $GITWEB_CONFIG
324 # $feature{'grep'}{'default'} = [1];
325 # To have project specific config enable override in $GITWEB_CONFIG
326 # $feature{'grep'}{'override'} = 1;
327 # and in project config gitweb.grep = 0|1;
329 'sub' => sub { feature_bool
('grep', @_) },
333 # Enable the pickaxe search, which will list the commits that modified
334 # a given string in a file. This can be practical and quite faster
335 # alternative to 'blame', but still potentially CPU-intensive.
337 # To enable system wide have in $GITWEB_CONFIG
338 # $feature{'pickaxe'}{'default'} = [1];
339 # To have project specific config enable override in $GITWEB_CONFIG
340 # $feature{'pickaxe'}{'override'} = 1;
341 # and in project config gitweb.pickaxe = 0|1;
343 'sub' => sub { feature_bool
('pickaxe', @_) },
347 # Enable showing size of blobs in a 'tree' view, in a separate
348 # column, similar to what 'ls -l' does. This cost a bit of IO.
350 # To disable system wide have in $GITWEB_CONFIG
351 # $feature{'show-sizes'}{'default'} = [0];
352 # To have project specific config enable override in $GITWEB_CONFIG
353 # $feature{'show-sizes'}{'override'} = 1;
354 # and in project config gitweb.showsizes = 0|1;
356 'sub' => sub { feature_bool
('showsizes', @_) },
360 # Make gitweb use an alternative format of the URLs which can be
361 # more readable and natural-looking: project name is embedded
362 # directly in the path and the query string contains other
363 # auxiliary information. All gitweb installations recognize
364 # URL in either format; this configures in which formats gitweb
367 # To enable system wide have in $GITWEB_CONFIG
368 # $feature{'pathinfo'}{'default'} = [1];
369 # Project specific override is not supported.
371 # Note that you will need to change the default location of CSS,
372 # favicon, logo and possibly other files to an absolute URL. Also,
373 # if gitweb.cgi serves as your indexfile, you will need to force
374 # $my_uri to contain the script name in your $GITWEB_CONFIG.
379 # Make gitweb consider projects in project root subdirectories
380 # to be forks of existing projects. Given project $projname.git,
381 # projects matching $projname/*.git will not be shown in the main
382 # projects list, instead a '+' mark will be added to $projname
383 # there and a 'forks' view will be enabled for the project, listing
384 # all the forks. If project list is taken from a file, forks have
385 # to be listed after the main project.
387 # To enable system wide have in $GITWEB_CONFIG
388 # $feature{'forks'}{'default'} = [1];
389 # Project specific override is not supported.
394 # Insert custom links to the action bar of all project pages.
395 # This enables you mainly to link to third-party scripts integrating
396 # into gitweb; e.g. git-browser for graphical history representation
397 # or custom web-based repository administration interface.
399 # The 'default' value consists of a list of triplets in the form
400 # (label, link, position) where position is the label after which
401 # to insert the link and link is a format string where %n expands
402 # to the project name, %f to the project path within the filesystem,
403 # %h to the current hash (h gitweb parameter) and %b to the current
404 # hash base (hb gitweb parameter); %% expands to %.
406 # To enable system wide have in $GITWEB_CONFIG e.g.
407 # $feature{'actions'}{'default'} = [('graphiclog',
408 # '/git-browser/by-commit.html?r=%n', 'summary')];
409 # Project specific override is not supported.
414 # Allow gitweb scan project content tags described in ctags/
415 # of project repository, and display the popular Web 2.0-ish
416 # "tag cloud" near the project list. Note that this is something
417 # COMPLETELY different from the normal Git tags.
419 # gitweb by itself can show existing tags, but it does not handle
420 # tagging itself; you need an external application for that.
421 # For an example script, check Girocco's cgi/tagproj.cgi.
422 # You may want to install the HTML::TagCloud Perl module to get
423 # a pretty tag cloud instead of just a list of tags.
425 # To enable system wide have in $GITWEB_CONFIG
426 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
427 # Project specific override is not supported.
432 # The maximum number of patches in a patchset generated in patch
433 # view. Set this to 0 or undef to disable patch view, or to a
434 # negative number to remove any limit.
436 # To disable system wide have in $GITWEB_CONFIG
437 # $feature{'patches'}{'default'} = [0];
438 # To have project specific config enable override in $GITWEB_CONFIG
439 # $feature{'patches'}{'override'} = 1;
440 # and in project config gitweb.patches = 0|n;
441 # where n is the maximum number of patches allowed in a patchset.
443 'sub' => \
&feature_patches
,
447 # Avatar support. When this feature is enabled, views such as
448 # shortlog or commit will display an avatar associated with
449 # the email of the committer(s) and/or author(s).
451 # Currently available providers are gravatar and picon.
452 # If an unknown provider is specified, the feature is disabled.
454 # Gravatar depends on Digest::MD5.
455 # Picon currently relies on the indiana.edu database.
457 # To enable system wide have in $GITWEB_CONFIG
458 # $feature{'avatar'}{'default'} = ['<provider>'];
459 # where <provider> is either gravatar or picon.
460 # To have project specific config enable override in $GITWEB_CONFIG
461 # $feature{'avatar'}{'override'} = 1;
462 # and in project config gitweb.avatar = <provider>;
464 'sub' => \
&feature_avatar
,
468 # Enable displaying how much time and how many git commands
469 # it took to generate and display page. Disabled by default.
470 # Project specific override is not supported.
475 # Enable turning some links into links to actions which require
476 # JavaScript to run (like 'blame_incremental'). Not enabled by
477 # default. Project specific override is currently not supported.
478 'javascript-actions' => {
482 # Syntax highlighting support. This is based on Daniel Svensson's
483 # and Sham Chukoury's work in gitweb-xmms2.git.
484 # It requires the 'highlight' program present in $PATH,
485 # and therefore is disabled by default.
487 # To enable system wide have in $GITWEB_CONFIG
488 # $feature{'highlight'}{'default'} = [1];
491 'sub' => sub { feature_bool
('highlight', @_) },
495 # Enable displaying of remote heads in the heads list
497 # To enable system wide have in $GITWEB_CONFIG
498 # $feature{'remote_heads'}{'default'} = [1];
499 # To have project specific config enable override in $GITWEB_CONFIG
500 # $feature{'remote_heads'}{'override'} = 1;
501 # and in project config gitweb.remote_heads = 0|1;
503 'sub' => sub { feature_bool
('remote_heads', @_) },
508 sub gitweb_get_feature
{
510 return unless exists $feature{$name};
511 my ($sub, $override, @defaults) = (
512 $feature{$name}{'sub'},
513 $feature{$name}{'override'},
514 @
{$feature{$name}{'default'}});
515 # project specific override is possible only if we have project
516 our $git_dir; # global variable, declared later
517 if (!$override || !defined $git_dir) {
521 warn "feature $name is not overridable";
524 return $sub->(@defaults);
527 # A wrapper to check if a given feature is enabled.
528 # With this, you can say
530 # my $bool_feat = gitweb_check_feature('bool_feat');
531 # gitweb_check_feature('bool_feat') or somecode;
535 # my ($bool_feat) = gitweb_get_feature('bool_feat');
536 # (gitweb_get_feature('bool_feat'))[0] or somecode;
538 sub gitweb_check_feature
{
539 return (gitweb_get_feature
(@_))[0];
545 my ($val) = git_get_project_config
($key, '--bool');
549 } elsif ($val eq 'true') {
551 } elsif ($val eq 'false') {
556 sub feature_snapshot
{
559 my ($val) = git_get_project_config
('snapshot');
562 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
568 sub feature_patches
{
569 my @val = (git_get_project_config
('patches', '--int'));
579 my @val = (git_get_project_config
('avatar'));
581 return @val ?
@val : @_;
584 # checking HEAD file with -e is fragile if the repository was
585 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
587 sub check_head_link
{
589 my $headfile = "$dir/HEAD";
590 return ((-e
$headfile) ||
591 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
594 sub check_export_ok
{
596 return (check_head_link
($dir) &&
597 (!$export_ok || -e
"$dir/$export_ok") &&
598 (!$export_auth_hook || $export_auth_hook->($dir)));
601 # process alternate names for backward compatibility
602 # filter out unsupported (unknown) snapshot formats
603 sub filter_snapshot_fmts
{
607 exists $known_snapshot_format_aliases{$_} ?
608 $known_snapshot_format_aliases{$_} : $_} @fmts;
610 exists $known_snapshot_formats{$_} &&
611 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
614 # If it is set to code reference, it is code that it is to be run once per
615 # request, allowing updating configurations that change with each request,
616 # while running other code in config file only once.
618 # Otherwise, if it is false then gitweb would process config file only once;
619 # if it is true then gitweb config would be run for each request.
620 our $per_request_config = 1;
622 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
623 sub evaluate_gitweb_config
{
624 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
625 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
626 # die if there are errors parsing config file
627 if (-e
$GITWEB_CONFIG) {
630 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
631 do $GITWEB_CONFIG_SYSTEM;
636 # Get loadavg of system, to compare against $maxload.
637 # Currently it requires '/proc/loadavg' present to get loadavg;
638 # if it is not present it returns 0, which means no load checking.
640 if( -e
'/proc/loadavg' ){
641 open my $fd, '<', '/proc/loadavg'
643 my @load = split(/\s+/, scalar <$fd>);
646 # The first three columns measure CPU and IO utilization of the last one,
647 # five, and 10 minute periods. The fourth column shows the number of
648 # currently running processes and the total number of processes in the m/n
649 # format. The last column displays the last process ID used.
650 return $load[0] || 0;
652 # additional checks for load average should go here for things that don't export
658 # version of the core git binary
660 sub evaluate_git_version
{
661 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
662 $number_of_git_cmds++;
666 if (defined $maxload && get_loadavg
() > $maxload) {
667 die_error
(503, "The load average on the server is too high");
671 # ======================================================================
672 # input validation and dispatch
674 # input parameters can be collected from a variety of sources (presently, CGI
675 # and PATH_INFO), so we define an %input_params hash that collects them all
676 # together during validation: this allows subsequent uses (e.g. href()) to be
677 # agnostic of the parameter origin
679 our %input_params = ();
681 # input parameters are stored with the long parameter name as key. This will
682 # also be used in the href subroutine to convert parameters to their CGI
683 # equivalent, and since the href() usage is the most frequent one, we store
684 # the name -> CGI key mapping here, instead of the reverse.
686 # XXX: Warning: If you touch this, check the search form for updating,
689 our @cgi_param_mapping = (
697 hash_parent_base
=> "hpb",
702 snapshot_format
=> "sf",
703 extra_options
=> "opt",
704 search_use_regexp
=> "sr",
705 # this must be last entry (for manipulation from JavaScript)
708 our %cgi_param_mapping = @cgi_param_mapping;
710 # we will also need to know the possible actions, for validation
712 "blame" => \
&git_blame
,
713 "blame_incremental" => \
&git_blame_incremental
,
714 "blame_data" => \
&git_blame_data
,
715 "blobdiff" => \
&git_blobdiff
,
716 "blobdiff_plain" => \
&git_blobdiff_plain
,
717 "blob" => \
&git_blob
,
718 "blob_plain" => \
&git_blob_plain
,
719 "commitdiff" => \
&git_commitdiff
,
720 "commitdiff_plain" => \
&git_commitdiff_plain
,
721 "commit" => \
&git_commit
,
722 "forks" => \
&git_forks
,
723 "heads" => \
&git_heads
,
724 "history" => \
&git_history
,
726 "patch" => \
&git_patch
,
727 "patches" => \
&git_patches
,
728 "remotes" => \
&git_remotes
,
730 "atom" => \
&git_atom
,
731 "search" => \
&git_search
,
732 "search_help" => \
&git_search_help
,
733 "shortlog" => \
&git_shortlog
,
734 "summary" => \
&git_summary
,
736 "tags" => \
&git_tags
,
737 "tree" => \
&git_tree
,
738 "snapshot" => \
&git_snapshot
,
739 "object" => \
&git_object
,
740 # those below don't need $project
741 "opml" => \
&git_opml
,
742 "project_list" => \
&git_project_list
,
743 "project_index" => \
&git_project_index
,
746 # finally, we have the hash of allowed extra_options for the commands that
748 our %allowed_options = (
749 "--no-merges" => [ qw(rss atom log shortlog history) ],
752 # fill %input_params with the CGI parameters. All values except for 'opt'
753 # should be single values, but opt can be an array. We should probably
754 # build an array of parameters that can be multi-valued, but since for the time
755 # being it's only this one, we just single it out
756 sub evaluate_query_params
{
759 while (my ($name, $symbol) = each %cgi_param_mapping) {
760 if ($symbol eq 'opt') {
761 $input_params{$name} = [ $cgi->param($symbol) ];
763 $input_params{$name} = $cgi->param($symbol);
768 # now read PATH_INFO and update the parameter list for missing parameters
769 sub evaluate_path_info
{
770 return if defined $input_params{'project'};
771 return if !$path_info;
772 $path_info =~ s
,^/+,,;
773 return if !$path_info;
775 # find which part of PATH_INFO is project
776 my $project = $path_info;
778 while ($project && !check_head_link
("$projectroot/$project")) {
779 $project =~ s
,/*[^/]*$,,;
781 return unless $project;
782 $input_params{'project'} = $project;
784 # do not change any parameters if an action is given using the query string
785 return if $input_params{'action'};
786 $path_info =~ s
,^\Q
$project\E
/*,,;
788 # next, check if we have an action
789 my $action = $path_info;
791 if (exists $actions{$action}) {
792 $path_info =~ s
,^$action/*,,;
793 $input_params{'action'} = $action;
796 # list of actions that want hash_base instead of hash, but can have no
797 # pathname (f) parameter
803 # we want to catch, among others
804 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
805 my ($parentrefname, $parentpathname, $refname, $pathname) =
806 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);
808 # first, analyze the 'current' part
809 if (defined $pathname) {
810 # we got "branch:filename" or "branch:dir/"
811 # we could use git_get_type(branch:pathname), but:
812 # - it needs $git_dir
813 # - it does a git() call
814 # - the convention of terminating directories with a slash
815 # makes it superfluous
816 # - embedding the action in the PATH_INFO would make it even
818 $pathname =~ s
,^/+,,;
819 if (!$pathname || substr($pathname, -1) eq "/") {
820 $input_params{'action'} ||= "tree";
823 # the default action depends on whether we had parent info
825 if ($parentrefname) {
826 $input_params{'action'} ||= "blobdiff_plain";
828 $input_params{'action'} ||= "blob_plain";
831 $input_params{'hash_base'} ||= $refname;
832 $input_params{'file_name'} ||= $pathname;
833 } elsif (defined $refname) {
834 # we got "branch". In this case we have to choose if we have to
835 # set hash or hash_base.
837 # Most of the actions without a pathname only want hash to be
838 # set, except for the ones specified in @wants_base that want
839 # hash_base instead. It should also be noted that hand-crafted
840 # links having 'history' as an action and no pathname or hash
841 # set will fail, but that happens regardless of PATH_INFO.
842 if (defined $parentrefname) {
843 # if there is parent let the default be 'shortlog' action
844 # (for http://git.example.com/repo.git/A..B links); if there
845 # is no parent, dispatch will detect type of object and set
846 # action appropriately if required (if action is not set)
847 $input_params{'action'} ||= "shortlog";
849 if ($input_params{'action'} &&
850 grep { $_ eq $input_params{'action'} } @wants_base) {
851 $input_params{'hash_base'} ||= $refname;
853 $input_params{'hash'} ||= $refname;
857 # next, handle the 'parent' part, if present
858 if (defined $parentrefname) {
859 # a missing pathspec defaults to the 'current' filename, allowing e.g.
860 # someproject/blobdiff/oldrev..newrev:/filename
861 if ($parentpathname) {
862 $parentpathname =~ s
,^/+,,;
863 $parentpathname =~ s
,/$,,;
864 $input_params{'file_parent'} ||= $parentpathname;
866 $input_params{'file_parent'} ||= $input_params{'file_name'};
868 # we assume that hash_parent_base is wanted if a path was specified,
869 # or if the action wants hash_base instead of hash
870 if (defined $input_params{'file_parent'} ||
871 grep { $_ eq $input_params{'action'} } @wants_base) {
872 $input_params{'hash_parent_base'} ||= $parentrefname;
874 $input_params{'hash_parent'} ||= $parentrefname;
878 # for the snapshot action, we allow URLs in the form
879 # $project/snapshot/$hash.ext
880 # where .ext determines the snapshot and gets removed from the
881 # passed $refname to provide the $hash.
883 # To be able to tell that $refname includes the format extension, we
884 # require the following two conditions to be satisfied:
885 # - the hash input parameter MUST have been set from the $refname part
886 # of the URL (i.e. they must be equal)
887 # - the snapshot format MUST NOT have been defined already (e.g. from
889 # It's also useless to try any matching unless $refname has a dot,
890 # so we check for that too
891 if (defined $input_params{'action'} &&
892 $input_params{'action'} eq 'snapshot' &&
893 defined $refname && index($refname, '.') != -1 &&
894 $refname eq $input_params{'hash'} &&
895 !defined $input_params{'snapshot_format'}) {
896 # We loop over the known snapshot formats, checking for
897 # extensions. Allowed extensions are both the defined suffix
898 # (which includes the initial dot already) and the snapshot
899 # format key itself, with a prepended dot
900 while (my ($fmt, $opt) = each %known_snapshot_formats) {
902 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
906 # a valid suffix was found, so set the snapshot format
907 # and reset the hash parameter
908 $input_params{'snapshot_format'} = $fmt;
909 $input_params{'hash'} = $hash;
910 # we also set the format suffix to the one requested
911 # in the URL: this way a request for e.g. .tgz returns
912 # a .tgz instead of a .tar.gz
913 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
919 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
920 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
921 $searchtext, $search_regexp);
922 sub evaluate_and_validate_params
{
923 our $action = $input_params{'action'};
924 if (defined $action) {
925 if (!validate_action
($action)) {
926 die_error
(400, "Invalid action parameter");
930 # parameters which are pathnames
931 our $project = $input_params{'project'};
932 if (defined $project) {
933 if (!validate_project
($project)) {
935 die_error
(404, "No such project");
939 our $file_name = $input_params{'file_name'};
940 if (defined $file_name) {
941 if (!validate_pathname
($file_name)) {
942 die_error
(400, "Invalid file parameter");
946 our $file_parent = $input_params{'file_parent'};
947 if (defined $file_parent) {
948 if (!validate_pathname
($file_parent)) {
949 die_error
(400, "Invalid file parent parameter");
953 # parameters which are refnames
954 our $hash = $input_params{'hash'};
956 if (!validate_refname
($hash)) {
957 die_error
(400, "Invalid hash parameter");
961 our $hash_parent = $input_params{'hash_parent'};
962 if (defined $hash_parent) {
963 if (!validate_refname
($hash_parent)) {
964 die_error
(400, "Invalid hash parent parameter");
968 our $hash_base = $input_params{'hash_base'};
969 if (defined $hash_base) {
970 if (!validate_refname
($hash_base)) {
971 die_error
(400, "Invalid hash base parameter");
975 our @extra_options = @
{$input_params{'extra_options'}};
976 # @extra_options is always defined, since it can only be (currently) set from
977 # CGI, and $cgi->param() returns the empty array in array context if the param
979 foreach my $opt (@extra_options) {
980 if (not exists $allowed_options{$opt}) {
981 die_error
(400, "Invalid option parameter");
983 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
984 die_error
(400, "Invalid option parameter for this action");
988 our $hash_parent_base = $input_params{'hash_parent_base'};
989 if (defined $hash_parent_base) {
990 if (!validate_refname
($hash_parent_base)) {
991 die_error
(400, "Invalid hash parent base parameter");
996 our $page = $input_params{'page'};
998 if ($page =~ m/[^0-9]/) {
999 die_error
(400, "Invalid page parameter");
1003 our $searchtype = $input_params{'searchtype'};
1004 if (defined $searchtype) {
1005 if ($searchtype =~ m/[^a-z]/) {
1006 die_error
(400, "Invalid searchtype parameter");
1010 our $search_use_regexp = $input_params{'search_use_regexp'};
1012 our $searchtext = $input_params{'searchtext'};
1014 if (defined $searchtext) {
1015 if (length($searchtext) < 2) {
1016 die_error
(403, "At least two characters are required for search parameter");
1018 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
1022 # path to the current git repository
1024 sub evaluate_git_dir
{
1025 our $git_dir = "$projectroot/$project" if $project;
1028 our (@snapshot_fmts, $git_avatar);
1029 sub configure_gitweb_features
{
1030 # list of supported snapshot formats
1031 our @snapshot_fmts = gitweb_get_feature
('snapshot');
1032 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1034 # check that the avatar feature is set to a known provider name,
1035 # and for each provider check if the dependencies are satisfied.
1036 # if the provider name is invalid or the dependencies are not met,
1037 # reset $git_avatar to the empty string.
1038 our ($git_avatar) = gitweb_get_feature
('avatar');
1039 if ($git_avatar eq 'gravatar') {
1040 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
1041 } elsif ($git_avatar eq 'picon') {
1048 # custom error handler: 'die <message>' is Internal Server Error
1049 sub handle_errors_html
{
1050 my $msg = shift; # it is already HTML escaped
1052 # to avoid infinite loop where error occurs in die_error,
1053 # change handler to default handler, disabling handle_errors_html
1054 set_message
("Error occured when inside die_error:\n$msg");
1056 # you cannot jump out of die_error when called as error handler;
1057 # the subroutine set via CGI::Carp::set_message is called _after_
1058 # HTTP headers are already written, so it cannot write them itself
1059 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1061 set_message
(\
&handle_errors_html
);
1065 if (!defined $action) {
1066 if (defined $hash) {
1067 $action = git_get_type
($hash);
1068 } elsif (defined $hash_base && defined $file_name) {
1069 $action = git_get_type
("$hash_base:$file_name");
1070 } elsif (defined $project) {
1071 $action = 'summary';
1073 $action = 'project_list';
1076 if (!defined($actions{$action})) {
1077 die_error
(400, "Unknown action");
1079 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1081 die_error
(400, "Project needed");
1083 $actions{$action}->();
1087 our $t0 = [ gettimeofday
() ]
1089 our $number_of_git_cmds = 0;
1092 our $first_request = 1;
1097 if ($first_request) {
1098 evaluate_gitweb_config
();
1099 evaluate_git_version
();
1101 if ($per_request_config) {
1102 if (ref($per_request_config) eq 'CODE') {
1103 $per_request_config->();
1104 } elsif (!$first_request) {
1105 evaluate_gitweb_config
();
1110 # $projectroot and $projects_list might be set in gitweb config file
1111 $projects_list ||= $projectroot;
1113 evaluate_query_params
();
1114 evaluate_path_info
();
1115 evaluate_and_validate_params
();
1118 configure_gitweb_features
();
1123 our $is_last_request = sub { 1 };
1124 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1127 sub configure_as_fcgi
{
1129 our $CGI = 'CGI::Fast';
1131 my $request_number = 0;
1132 # let each child service 100 requests
1133 our $is_last_request = sub { ++$request_number > 100 };
1136 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1138 if $script_name =~ /\.fcgi$/;
1140 return unless (@ARGV);
1142 require Getopt
::Long
;
1143 Getopt
::Long
::GetOptions
(
1144 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1145 'nproc|n=i' => sub {
1146 my ($arg, $val) = @_;
1147 return unless eval { require FCGI
::ProcManager
; 1; };
1148 my $proc_manager = FCGI
::ProcManager
->new({
1149 n_processes
=> $val,
1151 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1152 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1153 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1162 $pre_listen_hook->()
1163 if $pre_listen_hook;
1166 while ($cgi = $CGI->new()) {
1167 $pre_dispatch_hook->()
1168 if $pre_dispatch_hook;
1172 $post_dispatch_hook->()
1173 if $post_dispatch_hook;
1176 last REQUEST
if ($is_last_request->());
1185 if (defined caller) {
1186 # wrapped in a subroutine processing requests,
1187 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1190 # pure CGI script, serving single request
1194 ## ======================================================================
1197 # possible values of extra options
1198 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1199 # -replay => 1 - start from a current view (replay with modifications)
1200 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1203 # default is to use -absolute url() i.e. $my_uri
1204 my $href = $params{-full
} ?
$my_url : $my_uri;
1206 $params{'project'} = $project unless exists $params{'project'};
1208 if ($params{-replay
}) {
1209 while (my ($name, $symbol) = each %cgi_param_mapping) {
1210 if (!exists $params{$name}) {
1211 $params{$name} = $input_params{$name};
1216 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1217 if (defined $params{'project'} &&
1218 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1219 # try to put as many parameters as possible in PATH_INFO:
1222 # - hash_parent or hash_parent_base:/file_parent
1223 # - hash or hash_base:/filename
1224 # - the snapshot_format as an appropriate suffix
1226 # When the script is the root DirectoryIndex for the domain,
1227 # $href here would be something like http://gitweb.example.com/
1228 # Thus, we strip any trailing / from $href, to spare us double
1229 # slashes in the final URL
1232 # Then add the project name, if present
1233 $href .= "/".esc_url
($params{'project'});
1234 delete $params{'project'};
1236 # since we destructively absorb parameters, we keep this
1237 # boolean that remembers if we're handling a snapshot
1238 my $is_snapshot = $params{'action'} eq 'snapshot';
1240 # Summary just uses the project path URL, any other action is
1242 if (defined $params{'action'}) {
1243 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1244 delete $params{'action'};
1247 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1248 # stripping nonexistent or useless pieces
1249 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1250 || $params{'hash_parent'} || $params{'hash'});
1251 if (defined $params{'hash_base'}) {
1252 if (defined $params{'hash_parent_base'}) {
1253 $href .= esc_url
($params{'hash_parent_base'});
1254 # skip the file_parent if it's the same as the file_name
1255 if (defined $params{'file_parent'}) {
1256 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1257 delete $params{'file_parent'};
1258 } elsif ($params{'file_parent'} !~ /\.\./) {
1259 $href .= ":/".esc_url
($params{'file_parent'});
1260 delete $params{'file_parent'};
1264 delete $params{'hash_parent'};
1265 delete $params{'hash_parent_base'};
1266 } elsif (defined $params{'hash_parent'}) {
1267 $href .= esc_url
($params{'hash_parent'}). "..";
1268 delete $params{'hash_parent'};
1271 $href .= esc_url
($params{'hash_base'});
1272 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1273 $href .= ":/".esc_url
($params{'file_name'});
1274 delete $params{'file_name'};
1276 delete $params{'hash'};
1277 delete $params{'hash_base'};
1278 } elsif (defined $params{'hash'}) {
1279 $href .= esc_url
($params{'hash'});
1280 delete $params{'hash'};
1283 # If the action was a snapshot, we can absorb the
1284 # snapshot_format parameter too
1286 my $fmt = $params{'snapshot_format'};
1287 # snapshot_format should always be defined when href()
1288 # is called, but just in case some code forgets, we
1289 # fall back to the default
1290 $fmt ||= $snapshot_fmts[0];
1291 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1292 delete $params{'snapshot_format'};
1296 # now encode the parameters explicitly
1298 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1299 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1300 if (defined $params{$name}) {
1301 if (ref($params{$name}) eq "ARRAY") {
1302 foreach my $par (@
{$params{$name}}) {
1303 push @result, $symbol . "=" . esc_param
($par);
1306 push @result, $symbol . "=" . esc_param
($params{$name});
1310 $href .= "?" . join(';', @result) if scalar @result;
1316 ## ======================================================================
1317 ## validation, quoting/unquoting and escaping
1319 sub validate_action
{
1320 my $input = shift || return undef;
1321 return undef unless exists $actions{$input};
1325 sub validate_project
{
1326 my $input = shift || return undef;
1327 if (!validate_pathname
($input) ||
1328 !(-d
"$projectroot/$input") ||
1329 !check_export_ok
("$projectroot/$input") ||
1330 ($strict_export && !project_in_list
($input))) {
1337 sub validate_pathname
{
1338 my $input = shift || return undef;
1340 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1341 # at the beginning, at the end, and between slashes.
1342 # also this catches doubled slashes
1343 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1346 # no null characters
1347 if ($input =~ m!\0!) {
1353 sub validate_refname
{
1354 my $input = shift || return undef;
1356 # textual hashes are O.K.
1357 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1360 # it must be correct pathname
1361 $input = validate_pathname
($input)
1363 # restrictions on ref name according to git-check-ref-format
1364 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1370 # decode sequences of octets in utf8 into Perl's internal form,
1371 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1372 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1375 return undef unless defined $str;
1376 if (utf8
::valid
($str)) {
1380 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1384 # quote unsafe chars, but keep the slash, even when it's not
1385 # correct, but quoted slashes look too horrible in bookmarks
1388 return undef unless defined $str;
1389 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1394 # quote unsafe chars in whole URL, so some characters cannot be quoted
1397 return undef unless defined $str;
1398 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1403 # quote unsafe characters in HTML attributes
1406 # for XHTML conformance escaping '"' to '"' is not enough
1407 return esc_html
(@_);
1410 # replace invalid utf8 character with SUBSTITUTION sequence
1415 return undef unless defined $str;
1417 $str = to_utf8
($str);
1418 $str = $cgi->escapeHTML($str);
1419 if ($opts{'-nbsp'}) {
1420 $str =~ s/ / /g;
1422 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1426 # quote control characters and escape filename to HTML
1431 return undef unless defined $str;
1433 $str = to_utf8
($str);
1434 $str = $cgi->escapeHTML($str);
1435 if ($opts{'-nbsp'}) {
1436 $str =~ s/ / /g;
1438 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1442 # Make control characters "printable", using character escape codes (CEC)
1446 my %es = ( # character escape codes, aka escape sequences
1447 "\t" => '\t', # tab (HT)
1448 "\n" => '\n', # line feed (LF)
1449 "\r" => '\r', # carrige return (CR)
1450 "\f" => '\f', # form feed (FF)
1451 "\b" => '\b', # backspace (BS)
1452 "\a" => '\a', # alarm (bell) (BEL)
1453 "\e" => '\e', # escape (ESC)
1454 "\013" => '\v', # vertical tab (VT)
1455 "\000" => '\0', # nul character (NUL)
1457 my $chr = ( (exists $es{$cntrl})
1459 : sprintf('\%2x', ord($cntrl)) );
1460 if ($opts{-nohtml
}) {
1463 return "<span class=\"cntrl\">$chr</span>";
1467 # Alternatively use unicode control pictures codepoints,
1468 # Unicode "printable representation" (PR)
1473 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1474 if ($opts{-nohtml
}) {
1477 return "<span class=\"cntrl\">$chr</span>";
1481 # git may return quoted and escaped filenames
1487 my %es = ( # character escape codes, aka escape sequences
1488 't' => "\t", # tab (HT, TAB)
1489 'n' => "\n", # newline (NL)
1490 'r' => "\r", # return (CR)
1491 'f' => "\f", # form feed (FF)
1492 'b' => "\b", # backspace (BS)
1493 'a' => "\a", # alarm (bell) (BEL)
1494 'e' => "\e", # escape (ESC)
1495 'v' => "\013", # vertical tab (VT)
1498 if ($seq =~ m/^[0-7]{1,3}$/) {
1499 # octal char sequence
1500 return chr(oct($seq));
1501 } elsif (exists $es{$seq}) {
1502 # C escape sequence, aka character escape code
1505 # quoted ordinary character
1509 if ($str =~ m/^"(.*)"$/) {
1512 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1517 # escape tabs (convert tabs to spaces)
1521 while ((my $pos = index($line, "\t")) != -1) {
1522 if (my $count = (8 - ($pos % 8))) {
1523 my $spaces = ' ' x
$count;
1524 $line =~ s/\t/$spaces/;
1531 sub project_in_list
{
1532 my $project = shift;
1533 my @list = git_get_projects_list
();
1534 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1537 ## ----------------------------------------------------------------------
1538 ## HTML aware string manipulation
1540 # Try to chop given string on a word boundary between position
1541 # $len and $len+$add_len. If there is no word boundary there,
1542 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1543 # (marking chopped part) would be longer than given string.
1547 my $add_len = shift || 10;
1548 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1550 # Make sure perl knows it is utf8 encoded so we don't
1551 # cut in the middle of a utf8 multibyte char.
1552 $str = to_utf8
($str);
1554 # allow only $len chars, but don't cut a word if it would fit in $add_len
1555 # if it doesn't fit, cut it if it's still longer than the dots we would add
1556 # remove chopped character entities entirely
1558 # when chopping in the middle, distribute $len into left and right part
1559 # return early if chopping wouldn't make string shorter
1560 if ($where eq 'center') {
1561 return $str if ($len + 5 >= length($str)); # filler is length 5
1564 return $str if ($len + 4 >= length($str)); # filler is length 4
1567 # regexps: ending and beginning with word part up to $add_len
1568 my $endre = qr/.{$len}\w{0,$add_len}/;
1569 my $begre = qr/\w{0,$add_len}.{$len}/;
1571 if ($where eq 'left') {
1572 $str =~ m/^(.*?)($begre)$/;
1573 my ($lead, $body) = ($1, $2);
1574 if (length($lead) > 4) {
1577 return "$lead$body";
1579 } elsif ($where eq 'center') {
1580 $str =~ m/^($endre)(.*)$/;
1581 my ($left, $str) = ($1, $2);
1582 $str =~ m/^(.*?)($begre)$/;
1583 my ($mid, $right) = ($1, $2);
1584 if (length($mid) > 5) {
1587 return "$left$mid$right";
1590 $str =~ m/^($endre)(.*)$/;
1593 if (length($tail) > 4) {
1596 return "$body$tail";
1600 # takes the same arguments as chop_str, but also wraps a <span> around the
1601 # result with a title attribute if it does get chopped. Additionally, the
1602 # string is HTML-escaped.
1603 sub chop_and_escape_str
{
1606 my $chopped = chop_str
(@_);
1607 if ($chopped eq $str) {
1608 return esc_html
($chopped);
1610 $str =~ s/[[:cntrl:]]/?/g;
1611 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1615 ## ----------------------------------------------------------------------
1616 ## functions returning short strings
1618 # CSS class for given age value (in seconds)
1622 if (!defined $age) {
1624 } elsif ($age < 60*60*2) {
1626 } elsif ($age < 60*60*24*2) {
1633 # convert age in seconds to "nn units ago" string
1638 if ($age > 60*60*24*365*2) {
1639 $age_str = (int $age/60/60/24/365);
1640 $age_str .= " years ago";
1641 } elsif ($age > 60*60*24*(365/12)*2) {
1642 $age_str = int $age/60/60/24/(365/12);
1643 $age_str .= " months ago";
1644 } elsif ($age > 60*60*24*7*2) {
1645 $age_str = int $age/60/60/24/7;
1646 $age_str .= " weeks ago";
1647 } elsif ($age > 60*60*24*2) {
1648 $age_str = int $age/60/60/24;
1649 $age_str .= " days ago";
1650 } elsif ($age > 60*60*2) {
1651 $age_str = int $age/60/60;
1652 $age_str .= " hours ago";
1653 } elsif ($age > 60*2) {
1654 $age_str = int $age/60;
1655 $age_str .= " min ago";
1656 } elsif ($age > 2) {
1657 $age_str = int $age;
1658 $age_str .= " sec ago";
1660 $age_str .= " right now";
1666 S_IFINVALID
=> 0030000,
1667 S_IFGITLINK
=> 0160000,
1670 # submodule/subproject, a commit object reference
1674 return (($mode & S_IFMT
) == S_IFGITLINK
)
1677 # convert file mode in octal to symbolic file mode string
1679 my $mode = oct shift;
1681 if (S_ISGITLINK
($mode)) {
1682 return 'm---------';
1683 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1684 return 'drwxr-xr-x';
1685 } elsif (S_ISLNK
($mode)) {
1686 return 'lrwxrwxrwx';
1687 } elsif (S_ISREG
($mode)) {
1688 # git cares only about the executable bit
1689 if ($mode & S_IXUSR
) {
1690 return '-rwxr-xr-x';
1692 return '-rw-r--r--';
1695 return '----------';
1699 # convert file mode in octal to file type string
1703 if ($mode !~ m/^[0-7]+$/) {
1709 if (S_ISGITLINK
($mode)) {
1711 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1713 } elsif (S_ISLNK
($mode)) {
1715 } elsif (S_ISREG
($mode)) {
1722 # convert file mode in octal to file type description string
1723 sub file_type_long
{
1726 if ($mode !~ m/^[0-7]+$/) {
1732 if (S_ISGITLINK
($mode)) {
1734 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1736 } elsif (S_ISLNK
($mode)) {
1738 } elsif (S_ISREG
($mode)) {
1739 if ($mode & S_IXUSR
) {
1740 return "executable";
1750 ## ----------------------------------------------------------------------
1751 ## functions returning short HTML fragments, or transforming HTML fragments
1752 ## which don't belong to other sections
1754 # format line of commit message.
1755 sub format_log_line_html
{
1758 $line = esc_html
($line, -nbsp
=>1);
1759 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1760 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1761 -class => "text"}, $1);
1767 # format marker of refs pointing to given object
1769 # the destination action is chosen based on object type and current context:
1770 # - for annotated tags, we choose the tag view unless it's the current view
1771 # already, in which case we go to shortlog view
1772 # - for other refs, we keep the current view if we're in history, shortlog or
1773 # log view, and select shortlog otherwise
1774 sub format_ref_marker
{
1775 my ($refs, $id) = @_;
1778 if (defined $refs->{$id}) {
1779 foreach my $ref (@
{$refs->{$id}}) {
1780 # this code exploits the fact that non-lightweight tags are the
1781 # only indirect objects, and that they are the only objects for which
1782 # we want to use tag instead of shortlog as action
1783 my ($type, $name) = qw();
1784 my $indirect = ($ref =~ s/\^\{\}$//);
1785 # e.g. tags/v2.6.11 or heads/next
1786 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1795 $class .= " indirect" if $indirect;
1797 my $dest_action = "shortlog";
1800 $dest_action = "tag" unless $action eq "tag";
1801 } elsif ($action =~ /^(history|(short)?log)$/) {
1802 $dest_action = $action;
1806 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1809 my $link = $cgi->a({
1811 action
=>$dest_action,
1815 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
1821 return ' <span class="refs">'. $markers . '</span>';
1827 # format, perhaps shortened and with markers, title line
1828 sub format_subject_html
{
1829 my ($long, $short, $href, $extra) = @_;
1830 $extra = '' unless defined($extra);
1832 if (length($short) < length($long)) {
1833 $long =~ s/[[:cntrl:]]/?/g;
1834 return $cgi->a({-href
=> $href, -class => "list subject",
1835 -title
=> to_utf8
($long)},
1836 esc_html
($short)) . $extra;
1838 return $cgi->a({-href
=> $href, -class => "list subject"},
1839 esc_html
($long)) . $extra;
1843 # Rather than recomputing the url for an email multiple times, we cache it
1844 # after the first hit. This gives a visible benefit in views where the avatar
1845 # for the same email is used repeatedly (e.g. shortlog).
1846 # The cache is shared by all avatar engines (currently gravatar only), which
1847 # are free to use it as preferred. Since only one avatar engine is used for any
1848 # given page, there's no risk for cache conflicts.
1849 our %avatar_cache = ();
1851 # Compute the picon url for a given email, by using the picon search service over at
1852 # http://www.cs.indiana.edu/picons/search.html
1854 my $email = lc shift;
1855 if (!$avatar_cache{$email}) {
1856 my ($user, $domain) = split('@', $email);
1857 $avatar_cache{$email} =
1858 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1860 "users+domains+unknown/up/single";
1862 return $avatar_cache{$email};
1865 # Compute the gravatar url for a given email, if it's not in the cache already.
1866 # Gravatar stores only the part of the URL before the size, since that's the
1867 # one computationally more expensive. This also allows reuse of the cache for
1868 # different sizes (for this particular engine).
1870 my $email = lc shift;
1872 $avatar_cache{$email} ||=
1873 "http://www.gravatar.com/avatar/" .
1874 Digest
::MD5
::md5_hex
($email) . "?s=";
1875 return $avatar_cache{$email} . $size;
1878 # Insert an avatar for the given $email at the given $size if the feature
1880 sub git_get_avatar
{
1881 my ($email, %opts) = @_;
1882 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1883 my $post_white = ($opts{-pad_after
} ?
" " : "");
1884 $opts{-size
} ||= 'default';
1885 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1887 if ($git_avatar eq 'gravatar') {
1888 $url = gravatar_url
($email, $size);
1889 } elsif ($git_avatar eq 'picon') {
1890 $url = picon_url
($email);
1892 # Other providers can be added by extending the if chain, defining $url
1893 # as needed. If no variant puts something in $url, we assume avatars
1894 # are completely disabled/unavailable.
1897 "<img width=\"$size\" " .
1898 "class=\"avatar\" " .
1899 "src=\"".esc_url
($url)."\" " .
1907 sub format_search_author
{
1908 my ($author, $searchtype, $displaytext) = @_;
1909 my $have_search = gitweb_check_feature
('search');
1913 if ($searchtype eq 'author') {
1914 $performed = "authored";
1915 } elsif ($searchtype eq 'committer') {
1916 $performed = "committed";
1919 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1920 searchtext
=>$author,
1921 searchtype
=>$searchtype), class=>"list",
1922 title
=>"Search for commits $performed by $author"},
1926 return $displaytext;
1930 # format the author name of the given commit with the given tag
1931 # the author name is chopped and escaped according to the other
1932 # optional parameters (see chop_str).
1933 sub format_author_html
{
1936 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1937 return "<$tag class=\"author\">" .
1938 format_search_author
($co->{'author_name'}, "author",
1939 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1944 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1945 sub format_git_diff_header_line
{
1947 my $diffinfo = shift;
1948 my ($from, $to) = @_;
1950 if ($diffinfo->{'nparents'}) {
1952 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1953 if ($to->{'href'}) {
1954 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1955 esc_path
($to->{'file'}));
1956 } else { # file was deleted (no href)
1957 $line .= esc_path
($to->{'file'});
1961 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1962 if ($from->{'href'}) {
1963 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1964 'a/' . esc_path
($from->{'file'}));
1965 } else { # file was added (no href)
1966 $line .= 'a/' . esc_path
($from->{'file'});
1969 if ($to->{'href'}) {
1970 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1971 'b/' . esc_path
($to->{'file'}));
1972 } else { # file was deleted
1973 $line .= 'b/' . esc_path
($to->{'file'});
1977 return "<div class=\"diff header\">$line</div>\n";
1980 # format extended diff header line, before patch itself
1981 sub format_extended_diff_header_line
{
1983 my $diffinfo = shift;
1984 my ($from, $to) = @_;
1987 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1988 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1989 esc_path
($from->{'file'}));
1991 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1992 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1993 esc_path
($to->{'file'}));
1995 # match single <mode>
1996 if ($line =~ m/\s(\d{6})$/) {
1997 $line .= '<span class="info"> (' .
1998 file_type_long
($1) .
2002 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2003 # can match only for combined diff
2005 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2006 if ($from->{'href'}[$i]) {
2007 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
2009 substr($diffinfo->{'from_id'}[$i],0,7));
2014 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2017 if ($to->{'href'}) {
2018 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2019 substr($diffinfo->{'to_id'},0,7));
2024 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2025 # can match only for ordinary diff
2026 my ($from_link, $to_link);
2027 if ($from->{'href'}) {
2028 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
2029 substr($diffinfo->{'from_id'},0,7));
2031 $from_link = '0' x
7;
2033 if ($to->{'href'}) {
2034 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2035 substr($diffinfo->{'to_id'},0,7));
2039 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2040 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2043 return $line . "<br/>\n";
2046 # format from-file/to-file diff header
2047 sub format_diff_from_to_header
{
2048 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
2053 #assert($line =~ m/^---/) if DEBUG;
2054 # no extra formatting for "^--- /dev/null"
2055 if (! $diffinfo->{'nparents'}) {
2056 # ordinary (single parent) diff
2057 if ($line =~ m!^--- "?a/!) {
2058 if ($from->{'href'}) {
2060 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2061 esc_path
($from->{'file'}));
2064 esc_path
($from->{'file'});
2067 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2070 # combined diff (merge commit)
2071 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2072 if ($from->{'href'}[$i]) {
2074 $cgi->a({-href
=>href
(action
=>"blobdiff",
2075 hash_parent
=>$diffinfo->{'from_id'}[$i],
2076 hash_parent_base
=>$parents[$i],
2077 file_parent
=>$from->{'file'}[$i],
2078 hash
=>$diffinfo->{'to_id'},
2080 file_name
=>$to->{'file'}),
2082 -title
=>"diff" . ($i+1)},
2085 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2086 esc_path
($from->{'file'}[$i]));
2088 $line = '--- /dev/null';
2090 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2095 #assert($line =~ m/^\+\+\+/) if DEBUG;
2096 # no extra formatting for "^+++ /dev/null"
2097 if ($line =~ m!^\+\+\+ "?b/!) {
2098 if ($to->{'href'}) {
2100 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2101 esc_path
($to->{'file'}));
2104 esc_path
($to->{'file'});
2107 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2112 # create note for patch simplified by combined diff
2113 sub format_diff_cc_simplified
{
2114 my ($diffinfo, @parents) = @_;
2117 $result .= "<div class=\"diff header\">" .
2119 if (!is_deleted
($diffinfo)) {
2120 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2122 hash
=>$diffinfo->{'to_id'},
2123 file_name
=>$diffinfo->{'to_file'}),
2125 esc_path
($diffinfo->{'to_file'}));
2127 $result .= esc_path
($diffinfo->{'to_file'});
2129 $result .= "</div>\n" . # class="diff header"
2130 "<div class=\"diff nodifferences\">" .
2132 "</div>\n"; # class="diff nodifferences"
2137 # format patch (diff) line (not to be used for diff headers)
2138 sub format_diff_line
{
2140 my ($from, $to) = @_;
2141 my $diff_class = "";
2145 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2147 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2148 if ($line =~ m/^\@{3}/) {
2149 $diff_class = " chunk_header";
2150 } elsif ($line =~ m/^\\/) {
2151 $diff_class = " incomplete";
2152 } elsif ($prefix =~ tr/+/+/) {
2153 $diff_class = " add";
2154 } elsif ($prefix =~ tr/-/-/) {
2155 $diff_class = " rem";
2158 # assume ordinary diff
2159 my $char = substr($line, 0, 1);
2161 $diff_class = " add";
2162 } elsif ($char eq '-') {
2163 $diff_class = " rem";
2164 } elsif ($char eq '@') {
2165 $diff_class = " chunk_header";
2166 } elsif ($char eq "\\") {
2167 $diff_class = " incomplete";
2170 $line = untabify
($line);
2171 if ($from && $to && $line =~ m/^\@{2} /) {
2172 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2173 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2175 $from_lines = 0 unless defined $from_lines;
2176 $to_lines = 0 unless defined $to_lines;
2178 if ($from->{'href'}) {
2179 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2180 -class=>"list"}, $from_text);
2182 if ($to->{'href'}) {
2183 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2184 -class=>"list"}, $to_text);
2186 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2187 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2188 return "<div class=\"diff$diff_class\">$line</div>\n";
2189 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2190 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2191 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2193 @from_text = split(' ', $ranges);
2194 for (my $i = 0; $i < @from_text; ++$i) {
2195 ($from_start[$i], $from_nlines[$i]) =
2196 (split(',', substr($from_text[$i], 1)), 0);
2199 $to_text = pop @from_text;
2200 $to_start = pop @from_start;
2201 $to_nlines = pop @from_nlines;
2203 $line = "<span class=\"chunk_info\">$prefix ";
2204 for (my $i = 0; $i < @from_text; ++$i) {
2205 if ($from->{'href'}[$i]) {
2206 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2207 -class=>"list"}, $from_text[$i]);
2209 $line .= $from_text[$i];
2213 if ($to->{'href'}) {
2214 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2215 -class=>"list"}, $to_text);
2219 $line .= " $prefix</span>" .
2220 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2221 return "<div class=\"diff$diff_class\">$line</div>\n";
2223 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2226 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2227 # linked. Pass the hash of the tree/commit to snapshot.
2228 sub format_snapshot_links
{
2230 my $num_fmts = @snapshot_fmts;
2231 if ($num_fmts > 1) {
2232 # A parenthesized list of links bearing format names.
2233 # e.g. "snapshot (_tar.gz_ _zip_)"
2234 return "snapshot (" . join(' ', map
2241 }, $known_snapshot_formats{$_}{'display'})
2242 , @snapshot_fmts) . ")";
2243 } elsif ($num_fmts == 1) {
2244 # A single "snapshot" link whose tooltip bears the format name.
2246 my ($fmt) = @snapshot_fmts;
2252 snapshot_format
=>$fmt
2254 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2256 } else { # $num_fmts == 0
2261 ## ......................................................................
2262 ## functions returning values to be passed, perhaps after some
2263 ## transformation, to other functions; e.g. returning arguments to href()
2265 # returns hash to be passed to href to generate gitweb URL
2266 # in -title key it returns description of link
2268 my $format = shift || 'Atom';
2269 my %res = (action
=> lc($format));
2271 # feed links are possible only for project views
2272 return unless (defined $project);
2273 # some views should link to OPML, or to generic project feed,
2274 # or don't have specific feed yet (so they should use generic)
2275 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2278 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2279 # from tag links; this also makes possible to detect branch links
2280 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2281 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2284 # find log type for feed description (title)
2286 if (defined $file_name) {
2287 $type = "history of $file_name";
2288 $type .= "/" if ($action eq 'tree');
2289 $type .= " on '$branch'" if (defined $branch);
2291 $type = "log of $branch" if (defined $branch);
2294 $res{-title
} = $type;
2295 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2296 $res{'file_name'} = $file_name;
2301 ## ----------------------------------------------------------------------
2302 ## git utility subroutines, invoking git commands
2304 # returns path to the core git executable and the --git-dir parameter as list
2306 $number_of_git_cmds++;
2307 return $GIT, '--git-dir='.$git_dir;
2310 # quote the given arguments for passing them to the shell
2311 # quote_command("command", "arg 1", "arg with ' and ! characters")
2312 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2313 # Try to avoid using this function wherever possible.
2316 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2319 # get HEAD ref of given project as hash
2320 sub git_get_head_hash
{
2321 return git_get_full_hash
(shift, 'HEAD');
2324 sub git_get_full_hash
{
2325 return git_get_hash
(@_);
2328 sub git_get_short_hash
{
2329 return git_get_hash
(@_, '--short=7');
2333 my ($project, $hash, @options) = @_;
2334 my $o_git_dir = $git_dir;
2336 $git_dir = "$projectroot/$project";
2337 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2338 '--verify', '-q', @options, $hash) {
2340 chomp $retval if defined $retval;
2343 if (defined $o_git_dir) {
2344 $git_dir = $o_git_dir;
2349 # get type of given object
2353 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2355 close $fd or return;
2360 # repository configuration
2361 our $config_file = '';
2364 # store multiple values for single key as anonymous array reference
2365 # single values stored directly in the hash, not as [ <value> ]
2366 sub hash_set_multi
{
2367 my ($hash, $key, $value) = @_;
2369 if (!exists $hash->{$key}) {
2370 $hash->{$key} = $value;
2371 } elsif (!ref $hash->{$key}) {
2372 $hash->{$key} = [ $hash->{$key}, $value ];
2374 push @
{$hash->{$key}}, $value;
2378 # return hash of git project configuration
2379 # optionally limited to some section, e.g. 'gitweb'
2380 sub git_parse_project_config
{
2381 my $section_regexp = shift;
2386 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2389 while (my $keyval = <$fh>) {
2391 my ($key, $value) = split(/\n/, $keyval, 2);
2393 hash_set_multi
(\
%config, $key, $value)
2394 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2401 # convert config value to boolean: 'true' or 'false'
2402 # no value, number > 0, 'true' and 'yes' values are true
2403 # rest of values are treated as false (never as error)
2404 sub config_to_bool
{
2407 return 1 if !defined $val; # section.key
2409 # strip leading and trailing whitespace
2413 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2414 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2417 # convert config value to simple decimal number
2418 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2419 # to be multiplied by 1024, 1048576, or 1073741824
2423 # strip leading and trailing whitespace
2427 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2429 # unknown unit is treated as 1
2430 return $num * ($unit eq 'g' ?
1073741824 :
2431 $unit eq 'm' ?
1048576 :
2432 $unit eq 'k' ?
1024 : 1);
2437 # convert config value to array reference, if needed
2438 sub config_to_multi
{
2441 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2444 sub git_get_project_config
{
2445 my ($key, $type) = @_;
2447 return unless defined $git_dir;
2450 return unless ($key);
2451 $key =~ s/^gitweb\.//;
2452 return if ($key =~ m/\W/);
2455 if (defined $type) {
2458 unless ($type eq 'bool' || $type eq 'int');
2462 if (!defined $config_file ||
2463 $config_file ne "$git_dir/config") {
2464 %config = git_parse_project_config
('gitweb');
2465 $config_file = "$git_dir/config";
2468 # check if config variable (key) exists
2469 return unless exists $config{"gitweb.$key"};
2472 if (!defined $type) {
2473 return $config{"gitweb.$key"};
2474 } elsif ($type eq 'bool') {
2475 # backward compatibility: 'git config --bool' returns true/false
2476 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2477 } elsif ($type eq 'int') {
2478 return config_to_int
($config{"gitweb.$key"});
2480 return $config{"gitweb.$key"};
2483 # get hash of given path at given ref
2484 sub git_get_hash_by_path
{
2486 my $path = shift || return undef;
2491 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2492 or die_error
(500, "Open git-ls-tree failed");
2494 close $fd or return undef;
2496 if (!defined $line) {
2497 # there is no tree or hash given by $path at $base
2501 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2502 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2503 if (defined $type && $type ne $2) {
2504 # type doesn't match
2510 # get path of entry with given hash at given tree-ish (ref)
2511 # used to get 'from' filename for combined diff (merge commit) for renames
2512 sub git_get_path_by_hash
{
2513 my $base = shift || return;
2514 my $hash = shift || return;
2518 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2520 while (my $line = <$fd>) {
2523 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2524 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2525 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2534 ## ......................................................................
2535 ## git utility functions, directly accessing git repository
2537 sub git_get_project_description
{
2540 $git_dir = "$projectroot/$path";
2541 open my $fd, '<', "$git_dir/description"
2542 or return git_get_project_config
('description');
2545 if (defined $descr) {
2551 sub git_get_project_ctags
{
2555 $git_dir = "$projectroot/$path";
2556 opendir my $dh, "$git_dir/ctags"
2558 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2559 open my $ct, '<', $_ or next;
2563 my $ctag = $_; $ctag =~ s
#.*/##;
2564 $ctags->{$ctag} = $val;
2570 sub git_populate_project_tagcloud
{
2573 # First, merge different-cased tags; tags vote on casing
2575 foreach (keys %$ctags) {
2576 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2577 if (not $ctags_lc{lc $_}->{topcount
}
2578 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2579 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2580 $ctags_lc{lc $_}->{topname
} = $_;
2585 if (eval { require HTML
::TagCloud
; 1; }) {
2586 $cloud = HTML
::TagCloud
->new;
2587 foreach (sort keys %ctags_lc) {
2588 # Pad the title with spaces so that the cloud looks
2590 my $title = $ctags_lc{$_}->{topname
};
2591 $title =~ s/ / /g;
2592 $title =~ s/^/ /g;
2593 $title =~ s/$/ /g;
2594 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2597 $cloud = \
%ctags_lc;
2602 sub git_show_project_tagcloud
{
2603 my ($cloud, $count) = @_;
2604 print STDERR
ref($cloud)."..\n";
2605 if (ref $cloud eq 'HTML::TagCloud') {
2606 return $cloud->html_and_css($count);
2608 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2609 return '<p align="center">' . join (', ', map {
2610 $cgi->a({-href
=>"$home_link?by_tag=$_"}, $cloud->{$_}->{topname
})
2611 } splice(@tags, 0, $count)) . '</p>';
2615 sub git_get_project_url_list
{
2618 $git_dir = "$projectroot/$path";
2619 open my $fd, '<', "$git_dir/cloneurl"
2620 or return wantarray ?
2621 @
{ config_to_multi
(git_get_project_config
('url')) } :
2622 config_to_multi
(git_get_project_config
('url'));
2623 my @git_project_url_list = map { chomp; $_ } <$fd>;
2626 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2629 sub git_get_projects_list
{
2634 $filter =~ s/\.git$//;
2636 my $check_forks = gitweb_check_feature
('forks');
2638 if (-d
$projects_list) {
2639 # search in directory
2640 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2641 # remove the trailing "/"
2643 my $pfxlen = length("$dir");
2644 my $pfxdepth = ($dir =~ tr!/!!);
2647 follow_fast
=> 1, # follow symbolic links
2648 follow_skip
=> 2, # ignore duplicates
2649 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2652 our $project_maxdepth;
2654 # skip project-list toplevel, if we get it.
2655 return if (m!^[/.]$!);
2656 # only directories can be git repositories
2657 return unless (-d
$_);
2658 # don't traverse too deep (Find is super slow on os x)
2659 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2660 $File::Find
::prune
= 1;
2664 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2665 # we check related file in $projectroot
2666 my $path = ($filter ?
"$filter/" : '') . $subdir;
2667 if (check_export_ok
("$projectroot/$path")) {
2668 push @list, { path
=> $path };
2669 $File::Find
::prune
= 1;
2674 } elsif (-f
$projects_list) {
2675 # read from file(url-encoded):
2676 # 'git%2Fgit.git Linus+Torvalds'
2677 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2678 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2680 open my $fd, '<', $projects_list or return;
2682 while (my $line = <$fd>) {
2684 my ($path, $owner) = split ' ', $line;
2685 $path = unescape
($path);
2686 $owner = unescape
($owner);
2687 if (!defined $path) {
2690 if ($filter ne '') {
2691 # looking for forks;
2692 my $pfx = substr($path, 0, length($filter));
2693 if ($pfx ne $filter) {
2696 my $sfx = substr($path, length($filter));
2697 if ($sfx !~ /^\/.*\
.git
$/) {
2700 } elsif ($check_forks) {
2702 foreach my $filter (keys %paths) {
2703 # looking for forks;
2704 my $pfx = substr($path, 0, length($filter));
2705 if ($pfx ne $filter) {
2708 my $sfx = substr($path, length($filter));
2709 if ($sfx !~ /^\/.*\
.git
$/) {
2712 # is a fork, don't include it in
2717 if (check_export_ok
("$projectroot/$path")) {
2720 owner
=> to_utf8
($owner),
2723 (my $forks_path = $path) =~ s/\.git$//;
2724 $paths{$forks_path}++;
2732 our $gitweb_project_owner = undef;
2733 sub git_get_project_list_from_file
{
2735 return if (defined $gitweb_project_owner);
2737 $gitweb_project_owner = {};
2738 # read from file (url-encoded):
2739 # 'git%2Fgit.git Linus+Torvalds'
2740 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2741 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2742 if (-f
$projects_list) {
2743 open(my $fd, '<', $projects_list);
2744 while (my $line = <$fd>) {
2746 my ($pr, $ow) = split ' ', $line;
2747 $pr = unescape
($pr);
2748 $ow = unescape
($ow);
2749 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2755 sub git_get_project_owner
{
2756 my $project = shift;
2759 return undef unless $project;
2760 $git_dir = "$projectroot/$project";
2762 if (!defined $gitweb_project_owner) {
2763 git_get_project_list_from_file
();
2766 if (exists $gitweb_project_owner->{$project}) {
2767 $owner = $gitweb_project_owner->{$project};
2769 if (!defined $owner){
2770 $owner = git_get_project_config
('owner');
2772 if (!defined $owner) {
2773 $owner = get_file_owner
("$git_dir");
2779 sub git_get_last_activity
{
2783 $git_dir = "$projectroot/$path";
2784 open($fd, "-|", git_cmd
(), 'for-each-ref',
2785 '--format=%(committer)',
2786 '--sort=-committerdate',
2788 'refs/heads') or return;
2789 my $most_recent = <$fd>;
2790 close $fd or return;
2791 if (defined $most_recent &&
2792 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2794 my $age = time - $timestamp;
2795 return ($age, age_string
($age));
2797 return (undef, undef);
2800 # Implementation note: when a single remote is wanted, we cannot use 'git
2801 # remote show -n' because that command always work (assuming it's a remote URL
2802 # if it's not defined), and we cannot use 'git remote show' because that would
2803 # try to make a network roundtrip. So the only way to find if that particular
2804 # remote is defined is to walk the list provided by 'git remote -v' and stop if
2805 # and when we find what we want.
2806 sub git_get_remotes_list
{
2810 open my $fd, '-|' , git_cmd
(), 'remote', '-v';
2812 while (my $remote = <$fd>) {
2814 $remote =~ s!\t(.*?)\s+\((\w+)\)$!!;
2815 next if $wanted and not $remote eq $wanted;
2816 my ($url, $key) = ($1, $2);
2818 $remotes{$remote} ||= { 'heads' => () };
2819 $remotes{$remote}{$key} = $url;
2821 close $fd or return;
2822 return wantarray ?
%remotes : \
%remotes;
2825 # Takes a hash of remotes as first parameter and fills it by adding the
2826 # available remote heads for each of the indicated remotes.
2827 sub fill_remote_heads
{
2828 my $remotes = shift;
2829 my @heads = map { "remotes/$_" } keys %$remotes;
2830 my @remoteheads = git_get_heads_list
(undef, @heads);
2831 foreach my $remote (keys %$remotes) {
2832 $remotes->{$remote}{'heads'} = [ grep {
2833 $_->{'name'} =~ s!^$remote/!!
2838 sub git_get_references
{
2839 my $type = shift || "";
2841 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2842 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2843 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2844 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2847 while (my $line = <$fd>) {
2849 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2850 if (defined $refs{$1}) {
2851 push @
{$refs{$1}}, $2;
2857 close $fd or return;
2861 sub git_get_rev_name_tags
{
2862 my $hash = shift || return undef;
2864 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2866 my $name_rev = <$fd>;
2869 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2872 # catches also '$hash undefined' output
2877 ## ----------------------------------------------------------------------
2878 ## parse to hash functions
2882 my $tz = shift || "-0000";
2885 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2886 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2887 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2888 $date{'hour'} = $hour;
2889 $date{'minute'} = $min;
2890 $date{'mday'} = $mday;
2891 $date{'day'} = $days[$wday];
2892 $date{'month'} = $months[$mon];
2893 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2894 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2895 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2896 $mday, $months[$mon], $hour ,$min;
2897 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2898 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2900 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2901 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2902 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2903 $date{'hour_local'} = $hour;
2904 $date{'minute_local'} = $min;
2905 $date{'tz_local'} = $tz;
2906 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2907 1900+$year, $mon+1, $mday,
2908 $hour, $min, $sec, $tz);
2917 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2918 $tag{'id'} = $tag_id;
2919 while (my $line = <$fd>) {
2921 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2922 $tag{'object'} = $1;
2923 } elsif ($line =~ m/^type (.+)$/) {
2925 } elsif ($line =~ m/^tag (.+)$/) {
2927 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2928 $tag{'author'} = $1;
2929 $tag{'author_epoch'} = $2;
2930 $tag{'author_tz'} = $3;
2931 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2932 $tag{'author_name'} = $1;
2933 $tag{'author_email'} = $2;
2935 $tag{'author_name'} = $tag{'author'};
2937 } elsif ($line =~ m/--BEGIN/) {
2938 push @comment, $line;
2940 } elsif ($line eq "") {
2944 push @comment, <$fd>;
2945 $tag{'comment'} = \
@comment;
2946 close $fd or return;
2947 if (!defined $tag{'name'}) {
2953 sub parse_commit_text
{
2954 my ($commit_text, $withparents) = @_;
2955 my @commit_lines = split '\n', $commit_text;
2958 pop @commit_lines; # Remove '\0'
2960 if (! @commit_lines) {
2964 my $header = shift @commit_lines;
2965 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2968 ($co{'id'}, my @parents) = split ' ', $header;
2969 while (my $line = shift @commit_lines) {
2970 last if $line eq "\n";
2971 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2973 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2975 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2976 $co{'author'} = to_utf8
($1);
2977 $co{'author_epoch'} = $2;
2978 $co{'author_tz'} = $3;
2979 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2980 $co{'author_name'} = $1;
2981 $co{'author_email'} = $2;
2983 $co{'author_name'} = $co{'author'};
2985 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2986 $co{'committer'} = to_utf8
($1);
2987 $co{'committer_epoch'} = $2;
2988 $co{'committer_tz'} = $3;
2989 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2990 $co{'committer_name'} = $1;
2991 $co{'committer_email'} = $2;
2993 $co{'committer_name'} = $co{'committer'};
2997 if (!defined $co{'tree'}) {
3000 $co{'parents'} = \
@parents;
3001 $co{'parent'} = $parents[0];
3003 foreach my $title (@commit_lines) {
3006 $co{'title'} = chop_str
($title, 80, 5);
3007 # remove leading stuff of merges to make the interesting part visible
3008 if (length($title) > 50) {
3009 $title =~ s/^Automatic //;
3010 $title =~ s/^merge (of|with) /Merge ... /i;
3011 if (length($title) > 50) {
3012 $title =~ s/(http|rsync):\/\///;
3014 if (length($title) > 50) {
3015 $title =~ s/(master|www|rsync)\.//;
3017 if (length($title) > 50) {
3018 $title =~ s/kernel.org:?//;
3020 if (length($title) > 50) {
3021 $title =~ s/\/pub\/scm//;
3024 $co{'title_short'} = chop_str
($title, 50, 5);
3028 if (! defined $co{'title'} || $co{'title'} eq "") {
3029 $co{'title'} = $co{'title_short'} = '(no commit message)';
3031 # remove added spaces
3032 foreach my $line (@commit_lines) {
3035 $co{'comment'} = \
@commit_lines;
3037 my $age = time - $co{'committer_epoch'};
3039 $co{'age_string'} = age_string
($age);
3040 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
3041 if ($age > 60*60*24*7*2) {
3042 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3043 $co{'age_string_age'} = $co{'age_string'};
3045 $co{'age_string_date'} = $co{'age_string'};
3046 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3052 my ($commit_id) = @_;
3057 open my $fd, "-|", git_cmd
(), "rev-list",
3063 or die_error
(500, "Open git-rev-list failed");
3064 %co = parse_commit_text
(<$fd>, 1);
3071 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
3079 open my $fd, "-|", git_cmd
(), "rev-list",
3082 ("--max-count=" . $maxcount),
3083 ("--skip=" . $skip),
3087 ($filename ?
($filename) : ())
3088 or die_error
(500, "Open git-rev-list failed");
3089 while (my $line = <$fd>) {
3090 my %co = parse_commit_text
($line);
3095 return wantarray ?
@cos : \
@cos;
3098 # parse line of git-diff-tree "raw" output
3099 sub parse_difftree_raw_line
{
3103 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3104 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3105 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3106 $res{'from_mode'} = $1;
3107 $res{'to_mode'} = $2;
3108 $res{'from_id'} = $3;
3110 $res{'status'} = $5;
3111 $res{'similarity'} = $6;
3112 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3113 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3115 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3118 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3119 # combined diff (for merge commit)
3120 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3121 $res{'nparents'} = length($1);
3122 $res{'from_mode'} = [ split(' ', $2) ];
3123 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3124 $res{'from_id'} = [ split(' ', $3) ];
3125 $res{'to_id'} = pop @
{$res{'from_id'}};
3126 $res{'status'} = [ split('', $4) ];
3127 $res{'to_file'} = unquote
($5);
3129 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3130 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3131 $res{'commit'} = $1;
3134 return wantarray ?
%res : \
%res;
3137 # wrapper: return parsed line of git-diff-tree "raw" output
3138 # (the argument might be raw line, or parsed info)
3139 sub parsed_difftree_line
{
3140 my $line_or_ref = shift;
3142 if (ref($line_or_ref) eq "HASH") {
3143 # pre-parsed (or generated by hand)
3144 return $line_or_ref;
3146 return parse_difftree_raw_line
($line_or_ref);
3150 # parse line of git-ls-tree output
3151 sub parse_ls_tree_line
{
3157 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3158 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3167 $res{'name'} = unquote
($5);
3170 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3171 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3179 $res{'name'} = unquote
($4);
3183 return wantarray ?
%res : \
%res;
3186 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3187 sub parse_from_to_diffinfo
{
3188 my ($diffinfo, $from, $to, @parents) = @_;
3190 if ($diffinfo->{'nparents'}) {
3192 $from->{'file'} = [];
3193 $from->{'href'} = [];
3194 fill_from_file_info
($diffinfo, @parents)
3195 unless exists $diffinfo->{'from_file'};
3196 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3197 $from->{'file'}[$i] =
3198 defined $diffinfo->{'from_file'}[$i] ?
3199 $diffinfo->{'from_file'}[$i] :
3200 $diffinfo->{'to_file'};
3201 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3202 $from->{'href'}[$i] = href
(action
=>"blob",
3203 hash_base
=>$parents[$i],
3204 hash
=>$diffinfo->{'from_id'}[$i],
3205 file_name
=>$from->{'file'}[$i]);
3207 $from->{'href'}[$i] = undef;
3211 # ordinary (not combined) diff
3212 $from->{'file'} = $diffinfo->{'from_file'};
3213 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3214 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3215 hash
=>$diffinfo->{'from_id'},
3216 file_name
=>$from->{'file'});
3218 delete $from->{'href'};
3222 $to->{'file'} = $diffinfo->{'to_file'};
3223 if (!is_deleted
($diffinfo)) { # file exists in result
3224 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3225 hash
=>$diffinfo->{'to_id'},
3226 file_name
=>$to->{'file'});
3228 delete $to->{'href'};
3232 ## ......................................................................
3233 ## parse to array of hashes functions
3235 sub git_get_heads_list
{
3236 my ($limit, @classes) = @_;
3237 @classes = ('heads') unless @classes;
3238 my @patterns = map { "refs/$_" } @classes;
3241 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3242 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3243 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3246 while (my $line = <$fd>) {
3250 my ($refinfo, $committerinfo) = split(/\0/, $line);
3251 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3252 my ($committer, $epoch, $tz) =
3253 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3254 $ref_item{'fullname'} = $name;
3255 $name =~ s!^refs/(?:head|remote)s/!!;
3257 $ref_item{'name'} = $name;
3258 $ref_item{'id'} = $hash;
3259 $ref_item{'title'} = $title || '(no commit message)';
3260 $ref_item{'epoch'} = $epoch;
3262 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3264 $ref_item{'age'} = "unknown";
3267 push @headslist, \
%ref_item;
3271 return wantarray ?
@headslist : \
@headslist;
3274 sub git_get_tags_list
{
3278 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3279 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3280 '--format=%(objectname) %(objecttype) %(refname) '.
3281 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3284 while (my $line = <$fd>) {
3288 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3289 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3290 my ($creator, $epoch, $tz) =
3291 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3292 $ref_item{'fullname'} = $name;
3293 $name =~ s!^refs/tags/!!;
3295 $ref_item{'type'} = $type;
3296 $ref_item{'id'} = $id;
3297 $ref_item{'name'} = $name;
3298 if ($type eq "tag") {
3299 $ref_item{'subject'} = $title;
3300 $ref_item{'reftype'} = $reftype;
3301 $ref_item{'refid'} = $refid;
3303 $ref_item{'reftype'} = $type;
3304 $ref_item{'refid'} = $id;
3307 if ($type eq "tag" || $type eq "commit") {
3308 $ref_item{'epoch'} = $epoch;
3310 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3312 $ref_item{'age'} = "unknown";
3316 push @tagslist, \
%ref_item;
3320 return wantarray ?
@tagslist : \
@tagslist;
3323 ## ----------------------------------------------------------------------
3324 ## filesystem-related functions
3326 sub get_file_owner
{
3329 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3330 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3331 if (!defined $gcos) {
3335 $owner =~ s/[,;].*$//;
3336 return to_utf8
($owner);
3339 # assume that file exists
3341 my $filename = shift;
3343 open my $fd, '<', $filename;
3344 print map { to_utf8
($_) } <$fd>;
3348 ## ......................................................................
3349 ## mimetype related functions
3351 sub mimetype_guess_file
{
3352 my $filename = shift;
3353 my $mimemap = shift;
3354 -r
$mimemap or return undef;
3357 open(my $mh, '<', $mimemap) or return undef;
3359 next if m/^#/; # skip comments
3360 my ($mimetype, $exts) = split(/\t+/);
3361 if (defined $exts) {
3362 my @exts = split(/\s+/, $exts);
3363 foreach my $ext (@exts) {
3364 $mimemap{$ext} = $mimetype;
3370 $filename =~ /\.([^.]*)$/;
3371 return $mimemap{$1};
3374 sub mimetype_guess
{
3375 my $filename = shift;
3377 $filename =~ /\./ or return undef;
3379 if ($mimetypes_file) {
3380 my $file = $mimetypes_file;
3381 if ($file !~ m!^/!) { # if it is relative path
3382 # it is relative to project
3383 $file = "$projectroot/$project/$file";
3385 $mime = mimetype_guess_file
($filename, $file);
3387 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3393 my $filename = shift;
3396 my $mime = mimetype_guess
($filename);
3397 $mime and return $mime;
3401 return $default_blob_plain_mimetype unless $fd;
3404 return 'text/plain';
3405 } elsif (! $filename) {
3406 return 'application/octet-stream';
3407 } elsif ($filename =~ m/\.png$/i) {
3409 } elsif ($filename =~ m/\.gif$/i) {
3411 } elsif ($filename =~ m/\.jpe?g$/i) {
3412 return 'image/jpeg';
3414 return 'application/octet-stream';
3418 sub blob_contenttype
{
3419 my ($fd, $file_name, $type) = @_;
3421 $type ||= blob_mimetype
($fd, $file_name);
3422 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3423 $type .= "; charset=$default_text_plain_charset";
3429 # guess file syntax for syntax highlighting; return undef if no highlighting
3430 # the name of syntax can (in the future) depend on syntax highlighter used
3431 sub guess_file_syntax
{
3432 my ($highlight, $mimetype, $file_name) = @_;
3433 return undef unless ($highlight && defined $file_name);
3434 my $basename = basename
($file_name, '.in');
3435 return $highlight_basename{$basename}
3436 if exists $highlight_basename{$basename};
3438 $basename =~ /\.([^.]*)$/;
3439 my $ext = $1 or return undef;
3440 return $highlight_ext{$ext}
3441 if exists $highlight_ext{$ext};
3446 # run highlighter and return FD of its output,
3447 # or return original FD if no highlighting
3448 sub run_highlighter
{
3449 my ($fd, $highlight, $syntax) = @_;
3450 return $fd unless ($highlight && defined $syntax);
3453 or die_error
(404, "Reading blob failed");
3454 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3455 quote_command
($highlight_bin).
3456 " --xhtml --fragment --syntax $syntax |"
3457 or die_error
(500, "Couldn't open file or run syntax highlighter");
3461 ## ======================================================================
3462 ## functions printing HTML: header, footer, error page
3464 sub get_page_title
{
3465 my $title = to_utf8
($site_name);
3467 return $title unless (defined $project);
3468 $title .= " - " . to_utf8
($project);
3470 return $title unless (defined $action);
3471 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3473 return $title unless (defined $file_name);
3474 $title .= " - " . esc_path
($file_name);
3475 if ($action eq "tree" && $file_name !~ m
|/$|) {
3482 sub print_feed_meta
{
3483 if (defined $project) {
3484 my %href_params = get_feed_info
();
3485 if (!exists $href_params{'-title'}) {
3486 $href_params{'-title'} = 'log';
3489 foreach my $format qw(RSS Atom) {
3490 my $type = lc($format);
3492 '-rel' => 'alternate',
3493 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3494 '-type' => "application/$type+xml"
3497 $href_params{'action'} = $type;
3498 $link_attr{'-href'} = href
(%href_params);
3500 "rel=\"$link_attr{'-rel'}\" ".
3501 "title=\"$link_attr{'-title'}\" ".
3502 "href=\"$link_attr{'-href'}\" ".
3503 "type=\"$link_attr{'-type'}\" ".
3506 $href_params{'extra_options'} = '--no-merges';
3507 $link_attr{'-href'} = href
(%href_params);
3508 $link_attr{'-title'} .= ' (no merges)';
3510 "rel=\"$link_attr{'-rel'}\" ".
3511 "title=\"$link_attr{'-title'}\" ".
3512 "href=\"$link_attr{'-href'}\" ".
3513 "type=\"$link_attr{'-type'}\" ".
3518 printf('<link rel="alternate" title="%s projects list" '.
3519 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3520 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3521 printf('<link rel="alternate" title="%s projects feeds" '.
3522 'href="%s" type="text/x-opml" />'."\n",
3523 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3527 sub git_header_html
{
3528 my $status = shift || "200 OK";
3529 my $expires = shift;
3532 my $title = get_page_title
();
3534 # require explicit support from the UA if we are to send the page as
3535 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3536 # we have to do this because MSIE sometimes globs '*/*', pretending to
3537 # support xhtml+xml but choking when it gets what it asked for.
3538 if (defined $cgi->http('HTTP_ACCEPT') &&
3539 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3540 $cgi->Accept('application/xhtml+xml') != 0) {
3541 $content_type = 'application/xhtml+xml';
3543 $content_type = 'text/html';
3545 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3546 -status
=> $status, -expires
=> $expires)
3547 unless ($opts{'-no_http_header'});
3548 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3550 <?xml version="1.0" encoding="utf-8"?>
3551 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3552 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3553 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3554 <!-- git core binaries version $git_version -->
3556 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3557 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3558 <meta name="robots" content="index, nofollow"/>
3559 <title>$title</title>
3561 # the stylesheet, favicon etc urls won't work correctly with path_info
3562 # unless we set the appropriate base URL
3563 if ($ENV{'PATH_INFO'}) {
3564 print "<base href=\"".esc_url
($base_url)."\" />\n";
3566 # print out each stylesheet that exist, providing backwards capability
3567 # for those people who defined $stylesheet in a config file
3568 if (defined $stylesheet) {
3569 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3571 foreach my $stylesheet (@stylesheets) {
3572 next unless $stylesheet;
3573 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3577 if ($status eq '200 OK');
3578 if (defined $favicon) {
3579 print qq(<link rel
="shortcut icon" href
=").esc_url($favicon).qq(" type
="image/png" />\n);
3585 if (defined $site_header && -f
$site_header) {
3586 insert_file
($site_header);
3589 print "<div class=\"page_header\">\n" .
3590 $cgi->a({-href
=> esc_url
($logo_url),
3591 -title
=> $logo_label},
3592 qq(<img src
=").esc_url($logo).qq(" width
="72" height
="27" alt
="git" class="logo"/>));
3593 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3594 if (defined $project) {
3595 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3596 if (defined $action) {
3597 my $action_print = $action ;
3598 if (defined $opts{-action_extra
}) {
3599 $action_print = $cgi->a({-href
=> href
(action
=>$action)},
3602 print " / $action_print";
3604 if (defined $opts{-action_extra
}) {
3605 print " / $opts{-action_extra}";
3611 my $have_search = gitweb_check_feature
('search');
3612 if (defined $project && $have_search) {
3613 if (!defined $searchtext) {
3617 if (defined $hash_base) {
3618 $search_hash = $hash_base;
3619 } elsif (defined $hash) {
3620 $search_hash = $hash;
3622 $search_hash = "HEAD";
3624 my $action = $my_uri;
3625 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3626 if ($use_pathinfo) {
3627 $action .= "/".esc_url
($project);
3629 print $cgi->startform(-method
=> "get", -action
=> $action) .
3630 "<div class=\"search\">\n" .
3632 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3633 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3634 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3635 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3636 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3637 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3639 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3640 "<span title=\"Extended regular expression\">" .
3641 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3642 -checked
=> $search_use_regexp) .
3645 $cgi->end_form() . "\n";
3649 sub git_footer_html
{
3650 my $feed_class = 'rss_logo';
3652 print "<div class=\"page_footer\">\n";
3653 if (defined $project) {
3654 my $descr = git_get_project_description
($project);
3655 if (defined $descr) {
3656 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3659 my %href_params = get_feed_info
();
3660 if (!%href_params) {
3661 $feed_class .= ' generic';
3663 $href_params{'-title'} ||= 'log';
3665 foreach my $format qw(RSS Atom) {
3666 $href_params{'action'} = lc($format);
3667 print $cgi->a({-href
=> href
(%href_params),
3668 -title
=> "$href_params{'-title'} $format feed",
3669 -class => $feed_class}, $format)."\n";
3673 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3674 -class => $feed_class}, "OPML") . " ";
3675 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3676 -class => $feed_class}, "TXT") . "\n";
3678 print "</div>\n"; # class="page_footer"
3680 if (defined $t0 && gitweb_check_feature
('timed')) {
3681 print "<div id=\"generating_info\">\n";
3682 print 'This page took '.
3683 '<span id="generating_time" class="time_span">'.
3684 tv_interval
($t0, [ gettimeofday
() ]).
3687 '<span id="generating_cmd">'.
3688 $number_of_git_cmds.
3689 '</span> git commands '.
3691 print "</div>\n"; # class="page_footer"
3694 if (defined $site_footer && -f
$site_footer) {
3695 insert_file
($site_footer);
3698 print qq!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
3699 if (defined $action &&
3700 $action eq 'blame_incremental') {
3701 print qq!<script type
="text/javascript">\n!.
3702 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3703 qq! "!. href() .qq!");\n!.
3705 } elsif (gitweb_check_feature
('javascript-actions')) {
3706 print qq!<script type
="text/javascript">\n!.
3707 qq!window
.onload
= fixLinks
;\n!.
3715 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3716 # Example: die_error(404, 'Hash not found')
3717 # By convention, use the following status codes (as defined in RFC 2616):
3718 # 400: Invalid or missing CGI parameters, or
3719 # requested object exists but has wrong type.
3720 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3721 # this server or project.
3722 # 404: Requested object/revision/project doesn't exist.
3723 # 500: The server isn't configured properly, or
3724 # an internal error occurred (e.g. failed assertions caused by bugs), or
3725 # an unknown error occurred (e.g. the git binary died unexpectedly).
3726 # 503: The server is currently unavailable (because it is overloaded,
3727 # or down for maintenance). Generally, this is a temporary state.
3729 my $status = shift || 500;
3730 my $error = esc_html
(shift) || "Internal Server Error";
3734 my %http_responses = (
3735 400 => '400 Bad Request',
3736 403 => '403 Forbidden',
3737 404 => '404 Not Found',
3738 500 => '500 Internal Server Error',
3739 503 => '503 Service Unavailable',
3741 git_header_html
($http_responses{$status}, undef, %opts);
3743 <div class="page_body">
3748 if (defined $extra) {
3756 unless ($opts{'-error_handler'});
3759 ## ----------------------------------------------------------------------
3760 ## functions printing or outputting HTML: navigation
3762 sub git_print_page_nav
{
3763 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3764 $extra = '' if !defined $extra; # pager or formats
3766 my @navs = qw(summary shortlog log commit commitdiff tree);
3768 @navs = grep { $_ ne $suppress } @navs;
3771 my %arg = map { $_ => {action
=>$_} } @navs;
3772 if (defined $head) {
3773 for (qw(commit commitdiff)) {
3774 $arg{$_}{'hash'} = $head;
3776 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3777 for (qw(shortlog log)) {
3778 $arg{$_}{'hash'} = $head;
3783 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3784 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3786 my @actions = gitweb_get_feature
('actions');
3789 'n' => $project, # project name
3790 'f' => $git_dir, # project path within filesystem
3791 'h' => $treehead || '', # current hash ('h' parameter)
3792 'b' => $treebase || '', # hash base ('hb' parameter)
3795 my ($label, $link, $pos) = splice(@actions,0,3);
3797 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3799 $link =~ s/%([%nfhb])/$repl{$1}/g;
3800 $arg{$label}{'_href'} = $link;
3803 print "<div class=\"page_nav\">\n" .
3805 map { $_ eq $current ?
3806 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3808 print "<br/>\n$extra<br/>\n" .
3812 # returns a submenu for the nagivation of the refs views (tags, heads,
3813 # remotes) with the current view disabled and the remotes view only
3814 # available if the feature is enabled
3815 sub format_ref_views
{
3817 my @ref_views = qw{tags heads
};
3818 push @ref_views, 'remotes' if gitweb_check_feature
('remote_heads');
3819 return join " | ", map {
3820 $_ eq $current ?
$_ :
3821 $cgi->a({-href
=> href
(action
=>$_)}, $_)
3825 sub format_paging_nav
{
3826 my ($action, $page, $has_next_link) = @_;
3832 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3834 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3835 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3837 $paging_nav .= "first ⋅ prev";
3840 if ($has_next_link) {
3841 $paging_nav .= " ⋅ " .
3842 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3843 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3845 $paging_nav .= " ⋅ next";
3851 ## ......................................................................
3852 ## functions printing or outputting HTML: div
3854 sub git_print_header_div
{
3855 my ($action, $title, $hash, $hash_base) = @_;
3858 $args{'action'} = $action;
3859 $args{'hash'} = $hash if $hash;
3860 $args{'hash_base'} = $hash_base if $hash_base;
3862 print "<div class=\"header\">\n" .
3863 $cgi->a({-href
=> href
(%args), -class => "title"},
3864 $title ?
$title : $action) .
3868 sub format_repo_url
{
3869 my ($name, $url) = @_;
3870 return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
3873 # Group output by placing it in a DIV element and adding a header.
3874 # Options for start_div() can be provided by passing a hash reference as the
3875 # first parameter to the function.
3876 # Options to git_print_header_div() can be provided by passing an array
3877 # reference. This must follow the options to start_div if they are present.
3878 # The content can be a scalar, which is output as-is, a scalar reference, which
3879 # is output after html escaping, an IO handle passed either as *handle or
3880 # *handle{IO}, or a function reference. In the latter case all following
3881 # parameters will be taken as argument to the content function call.
3882 sub git_print_section
{
3883 my ($div_args, $header_args, $content);
3885 if (ref($arg) eq 'HASH') {
3889 if (ref($arg) eq 'ARRAY') {
3890 $header_args = $arg;
3895 print $cgi->start_div($div_args);
3896 git_print_header_div
(@
$header_args);
3898 if (ref($content) eq 'CODE') {
3900 } elsif (ref($content) eq 'SCALAR') {
3901 print esc_html
($$content);
3902 } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
3904 } elsif (!ref($content) && defined($content)) {
3908 print $cgi->end_div;
3911 sub print_local_time
{
3912 print format_local_time
(@_);
3915 sub format_local_time
{
3918 if ($date{'hour_local'} < 6) {
3919 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3920 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3922 $localtime .= sprintf(" (%02d:%02d %s)",
3923 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3929 # Outputs the author name and date in long form
3930 sub git_print_authorship
{
3933 my $tag = $opts{-tag
} || 'div';
3934 my $author = $co->{'author_name'};
3936 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3937 print "<$tag class=\"author_date\">" .
3938 format_search_author
($author, "author", esc_html
($author)) .
3940 print_local_time
(%ad) if ($opts{-localtime});
3941 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3945 # Outputs table rows containing the full author or committer information,
3946 # in the format expected for 'commit' view (& similar).
3947 # Parameters are a commit hash reference, followed by the list of people
3948 # to output information for. If the list is empty it defaults to both
3949 # author and committer.
3950 sub git_print_authorship_rows
{
3952 # too bad we can't use @people = @_ || ('author', 'committer')
3954 @people = ('author', 'committer') unless @people;
3955 foreach my $who (@people) {
3956 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3957 print "<tr><td>$who</td><td>" .
3958 format_search_author
($co->{"${who}_name"}, $who,
3959 esc_html
($co->{"${who}_name"})) . " " .
3960 format_search_author
($co->{"${who}_email"}, $who,
3961 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3962 "</td><td rowspan=\"2\">" .
3963 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3966 "<td></td><td> $wd{'rfc2822'}";
3967 print_local_time
(%wd);
3973 sub git_print_page_path
{
3979 print "<div class=\"page_path\">";
3980 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3981 -title
=> 'tree root'}, to_utf8
("[$project]"));
3983 if (defined $name) {
3984 my @dirname = split '/', $name;
3985 my $basename = pop @dirname;
3988 foreach my $dir (@dirname) {
3989 $fullname .= ($fullname ?
'/' : '') . $dir;
3990 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3992 -title
=> $fullname}, esc_path
($dir));
3995 if (defined $type && $type eq 'blob') {
3996 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3998 -title
=> $name}, esc_path
($basename));
3999 } elsif (defined $type && $type eq 'tree') {
4000 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
4002 -title
=> $name}, esc_path
($basename));
4005 print esc_path
($basename);
4008 print "<br/></div>\n";
4015 if ($opts{'-remove_title'}) {
4016 # remove title, i.e. first line of log
4019 # remove leading empty lines
4020 while (defined $log->[0] && $log->[0] eq "") {
4027 foreach my $line (@
$log) {
4028 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
4031 if (! $opts{'-remove_signoff'}) {
4032 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
4035 # remove signoff lines
4042 # print only one empty line
4043 # do not print empty line after signoff
4045 next if ($empty || $signoff);
4051 print format_log_line_html
($line) . "<br/>\n";
4054 if ($opts{'-final_empty_line'}) {
4055 # end with single empty line
4056 print "<br/>\n" unless $empty;
4060 # return link target (what link points to)
4061 sub git_get_link_target
{
4066 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4070 $link_target = <$fd>;
4075 return $link_target;
4078 # given link target, and the directory (basedir) the link is in,
4079 # return target of link relative to top directory (top tree);
4080 # return undef if it is not possible (including absolute links).
4081 sub normalize_link_target
{
4082 my ($link_target, $basedir) = @_;
4084 # absolute symlinks (beginning with '/') cannot be normalized
4085 return if (substr($link_target, 0, 1) eq '/');
4087 # normalize link target to path from top (root) tree (dir)
4090 $path = $basedir . '/' . $link_target;
4092 # we are in top (root) tree (dir)
4093 $path = $link_target;
4096 # remove //, /./, and /../
4098 foreach my $part (split('/', $path)) {
4099 # discard '.' and ''
4100 next if (!$part || $part eq '.');
4102 if ($part eq '..') {
4106 # link leads outside repository (outside top dir)
4110 push @path_parts, $part;
4113 $path = join('/', @path_parts);
4118 # print tree entry (row of git_tree), but without encompassing <tr> element
4119 sub git_print_tree_entry
{
4120 my ($t, $basedir, $hash_base, $have_blame) = @_;
4123 $base_key{'hash_base'} = $hash_base if defined $hash_base;
4125 # The format of a table row is: mode list link. Where mode is
4126 # the mode of the entry, list is the name of the entry, an href,
4127 # and link is the action links of the entry.
4129 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
4130 if (exists $t->{'size'}) {
4131 print "<td class=\"size\">$t->{'size'}</td>\n";
4133 if ($t->{'type'} eq "blob") {
4134 print "<td class=\"list\">" .
4135 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4136 file_name
=>"$basedir$t->{'name'}", %base_key),
4137 -class => "list"}, esc_path
($t->{'name'}));
4138 if (S_ISLNK
(oct $t->{'mode'})) {
4139 my $link_target = git_get_link_target
($t->{'hash'});
4141 my $norm_target = normalize_link_target
($link_target, $basedir);
4142 if (defined $norm_target) {
4144 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
4145 file_name
=>$norm_target),
4146 -title
=> $norm_target}, esc_path
($link_target));
4148 print " -> " . esc_path
($link_target);
4153 print "<td class=\"link\">";
4154 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4155 file_name
=>"$basedir$t->{'name'}", %base_key)},
4159 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4160 file_name
=>"$basedir$t->{'name'}", %base_key)},
4163 if (defined $hash_base) {
4165 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4166 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4170 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4171 file_name
=>"$basedir$t->{'name'}")},
4175 } elsif ($t->{'type'} eq "tree") {
4176 print "<td class=\"list\">";
4177 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4178 file_name
=>"$basedir$t->{'name'}",
4180 esc_path
($t->{'name'}));
4182 print "<td class=\"link\">";
4183 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4184 file_name
=>"$basedir$t->{'name'}",
4187 if (defined $hash_base) {
4189 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4190 file_name
=>"$basedir$t->{'name'}")},
4195 # unknown object: we can only present history for it
4196 # (this includes 'commit' object, i.e. submodule support)
4197 print "<td class=\"list\">" .
4198 esc_path
($t->{'name'}) .
4200 print "<td class=\"link\">";
4201 if (defined $hash_base) {
4202 print $cgi->a({-href
=> href
(action
=>"history",
4203 hash_base
=>$hash_base,
4204 file_name
=>"$basedir$t->{'name'}")},
4211 ## ......................................................................
4212 ## functions printing large fragments of HTML
4214 # get pre-image filenames for merge (combined) diff
4215 sub fill_from_file_info
{
4216 my ($diff, @parents) = @_;
4218 $diff->{'from_file'} = [ ];
4219 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4220 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4221 if ($diff->{'status'}[$i] eq 'R' ||
4222 $diff->{'status'}[$i] eq 'C') {
4223 $diff->{'from_file'}[$i] =
4224 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4231 # is current raw difftree line of file deletion
4233 my $diffinfo = shift;
4235 return $diffinfo->{'to_id'} eq ('0' x
40);
4238 # does patch correspond to [previous] difftree raw line
4239 # $diffinfo - hashref of parsed raw diff format
4240 # $patchinfo - hashref of parsed patch diff format
4241 # (the same keys as in $diffinfo)
4242 sub is_patch_split
{
4243 my ($diffinfo, $patchinfo) = @_;
4245 return defined $diffinfo && defined $patchinfo
4246 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4250 sub git_difftree_body
{
4251 my ($difftree, $hash, @parents) = @_;
4252 my ($parent) = $parents[0];
4253 my $have_blame = gitweb_check_feature
('blame');
4254 print "<div class=\"list_head\">\n";
4255 if ($#{$difftree} > 10) {
4256 print(($#{$difftree} + 1) . " files changed:\n");
4260 print "<table class=\"" .
4261 (@parents > 1 ?
"combined " : "") .
4264 # header only for combined diff in 'commitdiff' view
4265 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4268 print "<thead><tr>\n" .
4269 "<th></th><th></th>\n"; # filename, patchN link
4270 for (my $i = 0; $i < @parents; $i++) {
4271 my $par = $parents[$i];
4273 $cgi->a({-href
=> href
(action
=>"commitdiff",
4274 hash
=>$hash, hash_parent
=>$par),
4275 -title
=> 'commitdiff to parent number ' .
4276 ($i+1) . ': ' . substr($par,0,7)},
4280 print "</tr></thead>\n<tbody>\n";
4285 foreach my $line (@
{$difftree}) {
4286 my $diff = parsed_difftree_line
($line);
4289 print "<tr class=\"dark\">\n";
4291 print "<tr class=\"light\">\n";
4295 if (exists $diff->{'nparents'}) { # combined diff
4297 fill_from_file_info
($diff, @parents)
4298 unless exists $diff->{'from_file'};
4300 if (!is_deleted
($diff)) {
4301 # file exists in the result (child) commit
4303 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4304 file_name
=>$diff->{'to_file'},
4306 -class => "list"}, esc_path
($diff->{'to_file'})) .
4310 esc_path
($diff->{'to_file'}) .
4314 if ($action eq 'commitdiff') {
4317 print "<td class=\"link\">" .
4318 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4323 my $has_history = 0;
4324 my $not_deleted = 0;
4325 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4326 my $hash_parent = $parents[$i];
4327 my $from_hash = $diff->{'from_id'}[$i];
4328 my $from_path = $diff->{'from_file'}[$i];
4329 my $status = $diff->{'status'}[$i];
4331 $has_history ||= ($status ne 'A');
4332 $not_deleted ||= ($status ne 'D');
4334 if ($status eq 'A') {
4335 print "<td class=\"link\" align=\"right\"> | </td>\n";
4336 } elsif ($status eq 'D') {
4337 print "<td class=\"link\">" .
4338 $cgi->a({-href
=> href
(action
=>"blob",
4341 file_name
=>$from_path)},
4345 if ($diff->{'to_id'} eq $from_hash) {
4346 print "<td class=\"link nochange\">";
4348 print "<td class=\"link\">";
4350 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4351 hash
=>$diff->{'to_id'},
4352 hash_parent
=>$from_hash,
4354 hash_parent_base
=>$hash_parent,
4355 file_name
=>$diff->{'to_file'},
4356 file_parent
=>$from_path)},
4362 print "<td class=\"link\">";
4364 print $cgi->a({-href
=> href
(action
=>"blob",
4365 hash
=>$diff->{'to_id'},
4366 file_name
=>$diff->{'to_file'},
4369 print " | " if ($has_history);
4372 print $cgi->a({-href
=> href
(action
=>"history",
4373 file_name
=>$diff->{'to_file'},
4380 next; # instead of 'else' clause, to avoid extra indent
4382 # else ordinary diff
4384 my ($to_mode_oct, $to_mode_str, $to_file_type);
4385 my ($from_mode_oct, $from_mode_str, $from_file_type);
4386 if ($diff->{'to_mode'} ne ('0' x
6)) {
4387 $to_mode_oct = oct $diff->{'to_mode'};
4388 if (S_ISREG
($to_mode_oct)) { # only for regular file
4389 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4391 $to_file_type = file_type
($diff->{'to_mode'});
4393 if ($diff->{'from_mode'} ne ('0' x
6)) {
4394 $from_mode_oct = oct $diff->{'from_mode'};
4395 if (S_ISREG
($to_mode_oct)) { # only for regular file
4396 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4398 $from_file_type = file_type
($diff->{'from_mode'});
4401 if ($diff->{'status'} eq "A") { # created
4402 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4403 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4404 $mode_chng .= "]</span>";
4406 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4407 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4408 -class => "list"}, esc_path
($diff->{'file'}));
4410 print "<td>$mode_chng</td>\n";
4411 print "<td class=\"link\">";
4412 if ($action eq 'commitdiff') {
4415 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4418 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4419 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4423 } elsif ($diff->{'status'} eq "D") { # deleted
4424 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4426 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4427 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4428 -class => "list"}, esc_path
($diff->{'file'}));
4430 print "<td>$mode_chng</td>\n";
4431 print "<td class=\"link\">";
4432 if ($action eq 'commitdiff') {
4435 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4438 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4439 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4442 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4443 file_name
=>$diff->{'file'})},
4446 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4447 file_name
=>$diff->{'file'})},
4451 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4452 my $mode_chnge = "";
4453 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4454 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4455 if ($from_file_type ne $to_file_type) {
4456 $mode_chnge .= " from $from_file_type to $to_file_type";
4458 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4459 if ($from_mode_str && $to_mode_str) {
4460 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4461 } elsif ($to_mode_str) {
4462 $mode_chnge .= " mode: $to_mode_str";
4465 $mode_chnge .= "]</span>\n";
4468 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4469 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4470 -class => "list"}, esc_path
($diff->{'file'}));
4472 print "<td>$mode_chnge</td>\n";
4473 print "<td class=\"link\">";
4474 if ($action eq 'commitdiff') {
4477 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4479 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4480 # "commit" view and modified file (not onlu mode changed)
4481 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4482 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4483 hash_base
=>$hash, hash_parent_base
=>$parent,
4484 file_name
=>$diff->{'file'})},
4488 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4489 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4492 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4493 file_name
=>$diff->{'file'})},
4496 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4497 file_name
=>$diff->{'file'})},
4501 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4502 my %status_name = ('R' => 'moved', 'C' => 'copied');
4503 my $nstatus = $status_name{$diff->{'status'}};
4505 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4506 # mode also for directories, so we cannot use $to_mode_str
4507 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4510 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4511 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4512 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4513 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4514 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4515 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4516 -class => "list"}, esc_path
($diff->{'from_file'})) .
4517 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4518 "<td class=\"link\">";
4519 if ($action eq 'commitdiff') {
4522 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4524 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4525 # "commit" view and modified file (not only pure rename or copy)
4526 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4527 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4528 hash_base
=>$hash, hash_parent_base
=>$parent,
4529 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4533 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4534 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4537 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4538 file_name
=>$diff->{'to_file'})},
4541 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4542 file_name
=>$diff->{'to_file'})},
4546 } # we should not encounter Unmerged (U) or Unknown (X) status
4549 print "</tbody>" if $has_header;
4553 sub git_patchset_body
{
4554 my ($fd, $difftree, $hash, @hash_parents) = @_;
4555 my ($hash_parent) = $hash_parents[0];
4557 my $is_combined = (@hash_parents > 1);
4559 my $patch_number = 0;
4565 print "<div class=\"patchset\">\n";
4567 # skip to first patch
4568 while ($patch_line = <$fd>) {
4571 last if ($patch_line =~ m/^diff /);
4575 while ($patch_line) {
4577 # parse "git diff" header line
4578 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4579 # $1 is from_name, which we do not use
4580 $to_name = unquote
($2);
4581 $to_name =~ s!^b/!!;
4582 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4583 # $1 is 'cc' or 'combined', which we do not use
4584 $to_name = unquote
($2);
4589 # check if current patch belong to current raw line
4590 # and parse raw git-diff line if needed
4591 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4592 # this is continuation of a split patch
4593 print "<div class=\"patch cont\">\n";
4595 # advance raw git-diff output if needed
4596 $patch_idx++ if defined $diffinfo;
4598 # read and prepare patch information
4599 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4601 # compact combined diff output can have some patches skipped
4602 # find which patch (using pathname of result) we are at now;
4604 while ($to_name ne $diffinfo->{'to_file'}) {
4605 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4606 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4607 "</div>\n"; # class="patch"
4612 last if $patch_idx > $#$difftree;
4613 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4617 # modifies %from, %to hashes
4618 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4620 # this is first patch for raw difftree line with $patch_idx index
4621 # we index @$difftree array from 0, but number patches from 1
4622 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4626 #assert($patch_line =~ m/^diff /) if DEBUG;
4627 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4629 # print "git diff" header
4630 print format_git_diff_header_line
($patch_line, $diffinfo,
4633 # print extended diff header
4634 print "<div class=\"diff extended_header\">\n";
4636 while ($patch_line = <$fd>) {
4639 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4641 print format_extended_diff_header_line
($patch_line, $diffinfo,
4644 print "</div>\n"; # class="diff extended_header"
4646 # from-file/to-file diff header
4647 if (! $patch_line) {
4648 print "</div>\n"; # class="patch"
4651 next PATCH
if ($patch_line =~ m/^diff /);
4652 #assert($patch_line =~ m/^---/) if DEBUG;
4654 my $last_patch_line = $patch_line;
4655 $patch_line = <$fd>;
4657 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4659 print format_diff_from_to_header
($last_patch_line, $patch_line,
4660 $diffinfo, \
%from, \
%to,
4665 while ($patch_line = <$fd>) {
4668 next PATCH
if ($patch_line =~ m/^diff /);
4670 print format_diff_line
($patch_line, \
%from, \
%to);
4674 print "</div>\n"; # class="patch"
4677 # for compact combined (--cc) format, with chunk and patch simplification
4678 # the patchset might be empty, but there might be unprocessed raw lines
4679 for (++$patch_idx if $patch_number > 0;
4680 $patch_idx < @
$difftree;
4682 # read and prepare patch information
4683 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4685 # generate anchor for "patch" links in difftree / whatchanged part
4686 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4687 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4688 "</div>\n"; # class="patch"
4693 if ($patch_number == 0) {
4694 if (@hash_parents > 1) {
4695 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4697 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4701 print "</div>\n"; # class="patchset"
4704 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4706 # fills project list info (age, description, owner, forks) for each
4707 # project in the list, removing invalid projects from returned list
4708 # NOTE: modifies $projlist, but does not remove entries from it
4709 sub fill_project_list_info
{
4710 my ($projlist, $check_forks) = @_;
4713 my $show_ctags = gitweb_check_feature
('ctags');
4715 foreach my $pr (@
$projlist) {
4716 my (@activity) = git_get_last_activity
($pr->{'path'});
4717 unless (@activity) {
4720 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4721 if (!defined $pr->{'descr'}) {
4722 my $descr = git_get_project_description
($pr->{'path'}) || "";
4723 $descr = to_utf8
($descr);
4724 $pr->{'descr_long'} = $descr;
4725 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4727 if (!defined $pr->{'owner'}) {
4728 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4731 my $pname = $pr->{'path'};
4732 if (($pname =~ s/\.git$//) &&
4733 ($pname !~ /\/$/) &&
4734 (-d
"$projectroot/$pname")) {
4735 $pr->{'forks'} = "-d $projectroot/$pname";
4740 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4741 push @projects, $pr;
4747 # print 'sort by' <th> element, generating 'sort by $name' replay link
4748 # if that order is not selected
4750 print format_sort_th
(@_);
4753 sub format_sort_th
{
4754 my ($name, $order, $header) = @_;
4756 $header ||= ucfirst($name);
4758 if ($order eq $name) {
4759 $sort_th .= "<th>$header</th>\n";
4761 $sort_th .= "<th>" .
4762 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4763 -class => "header"}, $header) .
4770 sub git_project_list_body
{
4771 # actually uses global variable $project
4772 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4774 my $check_forks = gitweb_check_feature
('forks');
4775 my @projects = fill_project_list_info
($projlist, $check_forks);
4777 $order ||= $default_projects_order;
4778 $from = 0 unless defined $from;
4779 $to = $#projects if (!defined $to || $#projects < $to);
4782 project
=> { key
=> 'path', type
=> 'str' },
4783 descr
=> { key
=> 'descr_long', type
=> 'str' },
4784 owner
=> { key
=> 'owner', type
=> 'str' },
4785 age
=> { key
=> 'age', type
=> 'num' }
4787 my $oi = $order_info{$order};
4788 if ($oi->{'type'} eq 'str') {
4789 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4791 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4794 my $show_ctags = gitweb_check_feature
('ctags');
4797 foreach my $p (@projects) {
4798 foreach my $ct (keys %{$p->{'ctags'}}) {
4799 $ctags{$ct} += $p->{'ctags'}->{$ct};
4802 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4803 print git_show_project_tagcloud
($cloud, 64);
4806 print "<table class=\"project_list\">\n";
4807 unless ($no_header) {
4810 print "<th></th>\n";
4812 print_sort_th
('project', $order, 'Project');
4813 print_sort_th
('descr', $order, 'Description');
4814 print_sort_th
('owner', $order, 'Owner');
4815 print_sort_th
('age', $order, 'Last Change');
4816 print "<th></th>\n" . # for links
4820 my $tagfilter = $cgi->param('by_tag');
4821 for (my $i = $from; $i <= $to; $i++) {
4822 my $pr = $projects[$i];
4824 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4825 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4826 and not $pr->{'descr_long'} =~ /$searchtext/;
4827 # Weed out forks or non-matching entries of search
4829 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4830 $forkbase="^$forkbase" if $forkbase;
4831 next if not $searchtext and not $tagfilter and $show_ctags
4832 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4836 print "<tr class=\"dark\">\n";
4838 print "<tr class=\"light\">\n";
4843 if ($pr->{'forks'}) {
4844 print "<!-- $pr->{'forks'} -->\n";
4845 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4849 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4850 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4851 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4852 -class => "list", -title
=> $pr->{'descr_long'}},
4853 esc_html
($pr->{'descr'})) . "</td>\n" .
4854 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4855 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4856 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4857 "<td class=\"link\">" .
4858 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4859 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4860 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4861 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4862 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4866 if (defined $extra) {
4869 print "<td></td>\n";
4871 print "<td colspan=\"5\">$extra</td>\n" .
4878 # uses global variable $project
4879 my ($commitlist, $from, $to, $refs, $extra) = @_;
4881 $from = 0 unless defined $from;
4882 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4884 for (my $i = 0; $i <= $to; $i++) {
4885 my %co = %{$commitlist->[$i]};
4887 my $commit = $co{'id'};
4888 my $ref = format_ref_marker
($refs, $commit);
4889 my %ad = parse_date
($co{'author_epoch'});
4890 git_print_header_div
('commit',
4891 "<span class=\"age\">$co{'age_string'}</span>" .
4892 esc_html
($co{'title'}) . $ref,
4894 print "<div class=\"title_text\">\n" .
4895 "<div class=\"log_link\">\n" .
4896 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4898 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4900 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4903 git_print_authorship
(\
%co, -tag
=> 'span');
4904 print "<br/>\n</div>\n";
4906 print "<div class=\"log_body\">\n";
4907 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4911 print "<div class=\"page_nav\">\n";
4917 sub git_shortlog_body
{
4918 # uses global variable $project
4919 my ($commitlist, $from, $to, $refs, $extra) = @_;
4921 $from = 0 unless defined $from;
4922 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4924 print "<table class=\"shortlog\">\n";
4926 for (my $i = $from; $i <= $to; $i++) {
4927 my %co = %{$commitlist->[$i]};
4928 my $commit = $co{'id'};
4929 my $ref = format_ref_marker
($refs, $commit);
4931 print "<tr class=\"dark\">\n";
4933 print "<tr class=\"light\">\n";
4936 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4937 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4938 format_author_html
('td', \
%co, 10) . "<td>";
4939 print format_subject_html
($co{'title'}, $co{'title_short'},
4940 href
(action
=>"commit", hash
=>$commit), $ref);
4942 "<td class=\"link\">" .
4943 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4944 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4945 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4946 my $snapshot_links = format_snapshot_links
($commit);
4947 if (defined $snapshot_links) {
4948 print " | " . $snapshot_links;
4953 if (defined $extra) {
4955 "<td colspan=\"4\">$extra</td>\n" .
4961 sub git_history_body
{
4962 # Warning: assumes constant type (blob or tree) during history
4963 my ($commitlist, $from, $to, $refs, $extra,
4964 $file_name, $file_hash, $ftype) = @_;
4966 $from = 0 unless defined $from;
4967 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4969 print "<table class=\"history\">\n";
4971 for (my $i = $from; $i <= $to; $i++) {
4972 my %co = %{$commitlist->[$i]};
4976 my $commit = $co{'id'};
4978 my $ref = format_ref_marker
($refs, $commit);
4981 print "<tr class=\"dark\">\n";
4983 print "<tr class=\"light\">\n";
4986 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4987 # shortlog: format_author_html('td', \%co, 10)
4988 format_author_html
('td', \
%co, 15, 3) . "<td>";
4989 # originally git_history used chop_str($co{'title'}, 50)
4990 print format_subject_html
($co{'title'}, $co{'title_short'},
4991 href
(action
=>"commit", hash
=>$commit), $ref);
4993 "<td class=\"link\">" .
4994 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4995 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4997 if ($ftype eq 'blob') {
4998 my $blob_current = $file_hash;
4999 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
5000 if (defined $blob_current && defined $blob_parent &&
5001 $blob_current ne $blob_parent) {
5003 $cgi->a({-href
=> href
(action
=>"blobdiff",
5004 hash
=>$blob_current, hash_parent
=>$blob_parent,
5005 hash_base
=>$hash_base, hash_parent_base
=>$commit,
5006 file_name
=>$file_name)},
5013 if (defined $extra) {
5015 "<td colspan=\"4\">$extra</td>\n" .
5022 # uses global variable $project
5023 my ($taglist, $from, $to, $extra) = @_;
5024 $from = 0 unless defined $from;
5025 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
5027 print "<table class=\"tags\">\n";
5029 for (my $i = $from; $i <= $to; $i++) {
5030 my $entry = $taglist->[$i];
5032 my $comment = $tag{'subject'};
5034 if (defined $comment) {
5035 $comment_short = chop_str
($comment, 30, 5);
5038 print "<tr class=\"dark\">\n";
5040 print "<tr class=\"light\">\n";
5043 if (defined $tag{'age'}) {
5044 print "<td><i>$tag{'age'}</i></td>\n";
5046 print "<td></td>\n";
5049 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
5050 -class => "list name"}, esc_html
($tag{'name'})) .
5053 if (defined $comment) {
5054 print format_subject_html
($comment, $comment_short,
5055 href
(action
=>"tag", hash
=>$tag{'id'}));
5058 "<td class=\"selflink\">";
5059 if ($tag{'type'} eq "tag") {
5060 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
5065 "<td class=\"link\">" . " | " .
5066 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
5067 if ($tag{'reftype'} eq "commit") {
5068 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
5069 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
5070 } elsif ($tag{'reftype'} eq "blob") {
5071 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
5076 if (defined $extra) {
5078 "<td colspan=\"5\">$extra</td>\n" .
5084 sub git_heads_body
{
5085 # uses global variable $project
5086 my ($headlist, $head, $from, $to, $extra) = @_;
5087 $from = 0 unless defined $from;
5088 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
5090 print "<table class=\"heads\">\n";
5092 for (my $i = $from; $i <= $to; $i++) {
5093 my $entry = $headlist->[$i];
5095 my $curr = $ref{'id'} eq $head;
5097 print "<tr class=\"dark\">\n";
5099 print "<tr class=\"light\">\n";
5102 print "<td><i>$ref{'age'}</i></td>\n" .
5103 ($curr ?
"<td class=\"current_head\">" : "<td>") .
5104 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
5105 -class => "list name"},esc_html
($ref{'name'})) .
5107 "<td class=\"link\">" .
5108 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
5109 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
5110 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'fullname'})}, "tree") .
5114 if (defined $extra) {
5116 "<td colspan=\"3\">$extra</td>\n" .
5122 # Display a single remote block
5123 sub git_remote_block
{
5124 my ($remote, $rdata, $limit, $head) = @_;
5126 my $heads = $rdata->{'heads'};
5127 my $fetch = $rdata->{'fetch'};
5128 my $push = $rdata->{'push'};
5130 my $urls_table = "<table class=\"projects_list\">\n" ;
5132 if (defined $fetch) {
5133 if ($fetch eq $push) {
5134 $urls_table .= format_repo_url
("URL", $fetch);
5136 $urls_table .= format_repo_url
("Fetch URL", $fetch);
5137 $urls_table .= format_repo_url
("Push URL", $push) if defined $push;
5139 } elsif (defined $push) {
5140 $urls_table .= format_repo_url
("Push URL", $push);
5142 $urls_table .= format_repo_url
("", "No remote URL");
5145 $urls_table .= "</table>\n";
5148 if (defined $limit && $limit < @
$heads) {
5149 $dots = $cgi->a({-href
=> href
(action
=>"remotes", hash
=>$remote)}, "...");
5153 git_heads_body
($heads, $head, 0, $limit, $dots);
5156 # Display a list of remote names with the respective fetch and push URLs
5157 sub git_remotes_list
{
5158 my ($remotedata, $limit) = @_;
5159 print "<table class=\"heads\">\n";
5161 my @remotes = sort keys %$remotedata;
5163 my $limited = $limit && $limit < @remotes;
5165 $#remotes = $limit - 1 if $limited;
5167 while (my $remote = shift @remotes) {
5168 my $rdata = $remotedata->{$remote};
5169 my $fetch = $rdata->{'fetch'};
5170 my $push = $rdata->{'push'};
5172 print "<tr class=\"dark\">\n";
5174 print "<tr class=\"light\">\n";
5178 $cgi->a({-href
=> href
(action
=>'remotes', hash
=>$remote),
5179 -class=> "list name"},esc_html
($remote)) .
5181 print "<td class=\"link\">" .
5182 (defined $fetch ?
$cgi->a({-href
=> $fetch}, "fetch") : "fetch") .
5184 (defined $push ?
$cgi->a({-href
=> $push}, "push") : "push") .
5192 "<td colspan=\"3\">" .
5193 $cgi->a({-href
=> href
(action
=>"remotes")}, "...") .
5194 "</td>\n" . "</tr>\n";
5200 # Display remote heads grouped by remote, unless there are too many
5201 # remotes, in which case we only display the remote names
5202 sub git_remotes_body
{
5203 my ($remotedata, $limit, $head) = @_;
5204 if ($limit and $limit < keys %$remotedata) {
5205 git_remotes_list
($remotedata, $limit);
5207 fill_remote_heads
($remotedata);
5208 while (my ($remote, $rdata) = each %$remotedata) {
5209 git_print_section
({-class=>"remote", -id
=>$remote},
5210 ["remotes", $remote, $remote], sub {
5211 git_remote_block
($remote, $rdata, $limit, $head);
5217 sub git_search_grep_body
{
5218 my ($commitlist, $from, $to, $extra) = @_;
5219 $from = 0 unless defined $from;
5220 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5222 print "<table class=\"commit_search\">\n";
5224 for (my $i = $from; $i <= $to; $i++) {
5225 my %co = %{$commitlist->[$i]};
5229 my $commit = $co{'id'};
5231 print "<tr class=\"dark\">\n";
5233 print "<tr class=\"light\">\n";
5236 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5237 format_author_html
('td', \
%co, 15, 5) .
5239 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5240 -class => "list subject"},
5241 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5242 my $comment = $co{'comment'};
5243 foreach my $line (@
$comment) {
5244 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5245 my ($lead, $match, $trail) = ($1, $2, $3);
5246 $match = chop_str
($match, 70, 5, 'center');
5247 my $contextlen = int((80 - length($match))/2);
5248 $contextlen = 30 if ($contextlen > 30);
5249 $lead = chop_str
($lead, $contextlen, 10, 'left');
5250 $trail = chop_str
($trail, $contextlen, 10, 'right');
5252 $lead = esc_html
($lead);
5253 $match = esc_html
($match);
5254 $trail = esc_html
($trail);
5256 print "$lead<span class=\"match\">$match</span>$trail<br />";
5260 "<td class=\"link\">" .
5261 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5263 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5265 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5269 if (defined $extra) {
5271 "<td colspan=\"3\">$extra</td>\n" .
5277 ## ======================================================================
5278 ## ======================================================================
5281 sub git_project_list
{
5282 my $order = $input_params{'order'};
5283 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5284 die_error
(400, "Unknown order parameter");
5287 my @list = git_get_projects_list
();
5289 die_error
(404, "No projects found");
5293 if (defined $home_text && -f
$home_text) {
5294 print "<div class=\"index_include\">\n";
5295 insert_file
($home_text);
5298 print $cgi->startform(-method
=> "get") .
5299 "<p class=\"projsearch\">Search:\n" .
5300 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5302 $cgi->end_form() . "\n";
5303 git_project_list_body
(\
@list, $order);
5308 my $order = $input_params{'order'};
5309 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5310 die_error
(400, "Unknown order parameter");
5313 my @list = git_get_projects_list
($project);
5315 die_error
(404, "No forks found");
5319 git_print_page_nav
('','');
5320 git_print_header_div
('summary', "$project forks");
5321 git_project_list_body
(\
@list, $order);
5325 sub git_project_index
{
5326 my @projects = git_get_projects_list
($project);
5329 -type
=> 'text/plain',
5330 -charset
=> 'utf-8',
5331 -content_disposition
=> 'inline; filename="index.aux"');
5333 foreach my $pr (@projects) {
5334 if (!exists $pr->{'owner'}) {
5335 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5338 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5339 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5340 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5341 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5345 print "$path $owner\n";
5350 my $descr = git_get_project_description
($project) || "none";
5351 my %co = parse_commit
("HEAD");
5352 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5353 my $head = $co{'id'};
5354 my $remote_heads = gitweb_check_feature
('remote_heads');
5356 my $owner = git_get_project_owner
($project);
5358 my $refs = git_get_references
();
5359 # These get_*_list functions return one more to allow us to see if
5360 # there are more ...
5361 my @taglist = git_get_tags_list
(16);
5362 my @headlist = git_get_heads_list
(16);
5363 my %remotedata = $remote_heads ? git_get_remotes_list
() : ();
5365 my $check_forks = gitweb_check_feature
('forks');
5368 @forklist = git_get_projects_list
($project);
5372 git_print_page_nav
('summary','', $head);
5374 print "<div class=\"title\"> </div>\n";
5375 print "<table class=\"projects_list\">\n" .
5376 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5377 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5378 if (defined $cd{'rfc2822'}) {
5379 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5382 # use per project git URL list in $projectroot/$project/cloneurl
5383 # or make project git URL from git base URL and project name
5384 my $url_tag = "URL";
5385 my @url_list = git_get_project_url_list
($project);
5386 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5387 foreach my $git_url (@url_list) {
5388 next unless $git_url;
5389 print format_repo_url
($url_tag, $git_url);
5394 my $show_ctags = gitweb_check_feature
('ctags');
5396 my $ctags = git_get_project_ctags
($project);
5397 my $cloud = git_populate_project_tagcloud
($ctags);
5398 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5399 print "</td>\n<td>" unless %$ctags;
5400 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5401 print "</td>\n<td>" if %$ctags;
5402 print git_show_project_tagcloud
($cloud, 48);
5408 # If XSS prevention is on, we don't include README.html.
5409 # TODO: Allow a readme in some safe format.
5410 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5411 print "<div class=\"title\">readme</div>\n" .
5412 "<div class=\"readme\">\n";
5413 insert_file
("$projectroot/$project/README.html");
5414 print "\n</div>\n"; # class="readme"
5417 # we need to request one more than 16 (0..15) to check if
5419 my @commitlist = $head ? parse_commits
($head, 17) : ();
5421 git_print_header_div
('shortlog');
5422 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5423 $#commitlist <= 15 ?
undef :
5424 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5428 git_print_header_div
('tags');
5429 git_tags_body
(\
@taglist, 0, 15,
5430 $#taglist <= 15 ?
undef :
5431 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5435 git_print_header_div
('heads');
5436 git_heads_body
(\
@headlist, $head, 0, 15,
5437 $#headlist <= 15 ?
undef :
5438 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5442 git_print_header_div
('remotes');
5443 git_remotes_body
(\
%remotedata, 15, $head);
5447 git_print_header_div
('forks');
5448 git_project_list_body
(\
@forklist, 'age', 0, 15,
5449 $#forklist <= 15 ?
undef :
5450 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5458 my %tag = parse_tag
($hash);
5461 die_error
(404, "Unknown tag object");
5464 my $head = git_get_head_hash
($project);
5466 git_print_page_nav
('','', $head,undef,$head);
5467 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5468 print "<div class=\"title_text\">\n" .
5469 "<table class=\"object_header\">\n" .
5471 "<td>object</td>\n" .
5472 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5473 $tag{'object'}) . "</td>\n" .
5474 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5475 $tag{'type'}) . "</td>\n" .
5477 if (defined($tag{'author'})) {
5478 git_print_authorship_rows
(\
%tag, 'author');
5480 print "</table>\n\n" .
5482 print "<div class=\"page_body\">";
5483 my $comment = $tag{'comment'};
5484 foreach my $line (@
$comment) {
5486 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5492 sub git_blame_common
{
5493 my $format = shift || 'porcelain';
5494 if ($format eq 'porcelain' && $cgi->param('js')) {
5495 $format = 'incremental';
5496 $action = 'blame_incremental'; # for page title etc
5500 gitweb_check_feature
('blame')
5501 or die_error
(403, "Blame view not allowed");
5504 die_error
(400, "No file name given") unless $file_name;
5505 $hash_base ||= git_get_head_hash
($project);
5506 die_error
(404, "Couldn't find base commit") unless $hash_base;
5507 my %co = parse_commit
($hash_base)
5508 or die_error
(404, "Commit not found");
5510 if (!defined $hash) {
5511 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5512 or die_error
(404, "Error looking up file");
5514 $ftype = git_get_type
($hash);
5515 if ($ftype !~ "blob") {
5516 die_error
(400, "Object is not a blob");
5521 if ($format eq 'incremental') {
5522 # get file contents (as base)
5523 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5524 or die_error
(500, "Open git-cat-file failed");
5525 } elsif ($format eq 'data') {
5526 # run git-blame --incremental
5527 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5528 $hash_base, "--", $file_name
5529 or die_error
(500, "Open git-blame --incremental failed");
5531 # run git-blame --porcelain
5532 open $fd, "-|", git_cmd
(), "blame", '-p',
5533 $hash_base, '--', $file_name
5534 or die_error
(500, "Open git-blame --porcelain failed");
5537 # incremental blame data returns early
5538 if ($format eq 'data') {
5540 -type
=>"text/plain", -charset
=> "utf-8",
5541 -status
=> "200 OK");
5542 local $| = 1; # output autoflush
5545 or print "ERROR $!\n";
5548 if (defined $t0 && gitweb_check_feature
('timed')) {
5550 tv_interval
($t0, [ gettimeofday
() ]).
5551 ' '.$number_of_git_cmds;
5561 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5564 if ($format eq 'incremental') {
5566 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5567 "blame") . " (non-incremental)";
5570 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5571 "blame") . " (incremental)";
5575 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5578 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5580 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5581 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5582 git_print_page_path
($file_name, $ftype, $hash_base);
5585 if ($format eq 'incremental') {
5586 print "<noscript>\n<div class=\"error\"><center><b>\n".
5587 "This page requires JavaScript to run.\n Use ".
5588 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5591 "</b></center></div>\n</noscript>\n";
5593 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5596 print qq!<div
class="page_body">\n!;
5597 print qq!<div id
="progress_info">... / ...</div
>\n!
5598 if ($format eq 'incremental');
5599 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5600 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5602 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5606 my @rev_color = qw(light dark);
5607 my $num_colors = scalar(@rev_color);
5608 my $current_color = 0;
5610 if ($format eq 'incremental') {
5611 my $color_class = $rev_color[$current_color];
5616 while (my $line = <$fd>) {
5620 print qq!<tr id
="l$linenr" class="$color_class">!.
5621 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5622 qq!<td
class="linenr">!.
5623 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5624 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5628 } else { # porcelain, i.e. ordinary blame
5629 my %metainfo = (); # saves information about commits
5633 while (my $line = <$fd>) {
5635 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5636 # no <lines in group> for subsequent lines in group of lines
5637 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5638 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5639 if (!exists $metainfo{$full_rev}) {
5640 $metainfo{$full_rev} = { 'nprevious' => 0 };
5642 my $meta = $metainfo{$full_rev};
5644 while ($data = <$fd>) {
5646 last if ($data =~ s/^\t//); # contents of line
5647 if ($data =~ /^(\S+)(?: (.*))?$/) {
5648 $meta->{$1} = $2 unless exists $meta->{$1};
5650 if ($data =~ /^previous /) {
5651 $meta->{'nprevious'}++;
5654 my $short_rev = substr($full_rev, 0, 8);
5655 my $author = $meta->{'author'};
5657 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5658 my $date = $date{'iso-tz'};
5660 $current_color = ($current_color + 1) % $num_colors;
5662 my $tr_class = $rev_color[$current_color];
5663 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5664 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5665 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5666 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5668 print "<td class=\"sha1\"";
5669 print " title=\"". esc_html
($author) . ", $date\"";
5670 print " rowspan=\"$group_size\"" if ($group_size > 1);
5672 print $cgi->a({-href
=> href
(action
=>"commit",
5674 file_name
=>$file_name)},
5675 esc_html
($short_rev));
5676 if ($group_size >= 2) {
5677 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5678 if (@author_initials) {
5680 esc_html
(join('', @author_initials));
5686 # 'previous' <sha1 of parent commit> <filename at commit>
5687 if (exists $meta->{'previous'} &&
5688 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5689 $meta->{'parent'} = $1;
5690 $meta->{'file_parent'} = unquote
($2);
5693 exists($meta->{'parent'}) ?
5694 $meta->{'parent'} : $full_rev;
5695 my $linenr_filename =
5696 exists($meta->{'file_parent'}) ?
5697 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5698 my $blamed = href
(action
=> 'blame',
5699 file_name
=> $linenr_filename,
5700 hash_base
=> $linenr_commit);
5701 print "<td class=\"linenr\">";
5702 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5703 -class => "linenr" },
5706 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5714 "</table>\n"; # class="blame"
5715 print "</div>\n"; # class="blame_body"
5717 or print "Reading blob failed\n";
5726 sub git_blame_incremental
{
5727 git_blame_common
('incremental');
5730 sub git_blame_data
{
5731 git_blame_common
('data');
5735 my $head = git_get_head_hash
($project);
5737 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('tags'));
5738 git_print_header_div
('summary', $project);
5740 my @tagslist = git_get_tags_list
();
5742 git_tags_body
(\
@tagslist);
5748 my $head = git_get_head_hash
($project);
5750 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('heads'));
5751 git_print_header_div
('summary', $project);
5753 my @headslist = git_get_heads_list
();
5755 git_heads_body
(\
@headslist, $head);
5760 # used both for single remote view and for list of all the remotes
5762 gitweb_check_feature
('remote_heads')
5763 or die_error
(403, "Remote heads view is disabled");
5765 my $head = git_get_head_hash
($project);
5766 my $remote = $input_params{'hash'};
5768 my $remotedata = git_get_remotes_list
($remote);
5769 die_error
(500, "Unable to get remote information") unless defined $remotedata;
5771 unless (%$remotedata) {
5772 die_error
(404, defined $remote ?
5773 "Remote $remote not found" :
5774 "No remotes found");
5777 git_header_html
(undef, undef, -action_extra
=> $remote);
5778 git_print_page_nav
('', '', $head, undef, $head,
5779 format_ref_views
($remote ?
'' : 'remotes'));
5781 fill_remote_heads
($remotedata);
5782 if (defined $remote) {
5783 git_print_header_div
('remotes', "$remote remote for $project");
5784 git_remote_block
($remote, $remotedata->{$remote}, undef, $head);
5786 git_print_header_div
('summary', "$project remotes");
5787 git_remotes_body
($remotedata, undef, $head);
5793 sub git_blob_plain
{
5797 if (!defined $hash) {
5798 if (defined $file_name) {
5799 my $base = $hash_base || git_get_head_hash
($project);
5800 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5801 or die_error
(404, "Cannot find file");
5803 die_error
(400, "No file name defined");
5805 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5806 # blobs defined by non-textual hash id's can be cached
5810 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5811 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5813 # content-type (can include charset)
5814 $type = blob_contenttype
($fd, $file_name, $type);
5816 # "save as" filename, even when no $file_name is given
5817 my $save_as = "$hash";
5818 if (defined $file_name) {
5819 $save_as = $file_name;
5820 } elsif ($type =~ m/^text\//) {
5824 # With XSS prevention on, blobs of all types except a few known safe
5825 # ones are served with "Content-Disposition: attachment" to make sure
5826 # they don't run in our security domain. For certain image types,
5827 # blob view writes an <img> tag referring to blob_plain view, and we
5828 # want to be sure not to break that by serving the image as an
5829 # attachment (though Firefox 3 doesn't seem to care).
5830 my $sandbox = $prevent_xss &&
5831 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5835 -expires
=> $expires,
5836 -content_disposition
=>
5837 ($sandbox ?
'attachment' : 'inline')
5838 . '; filename="' . $save_as . '"');
5840 binmode STDOUT
, ':raw';
5842 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5849 if (!defined $hash) {
5850 if (defined $file_name) {
5851 my $base = $hash_base || git_get_head_hash
($project);
5852 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5853 or die_error
(404, "Cannot find file");
5855 die_error
(400, "No file name defined");
5857 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5858 # blobs defined by non-textual hash id's can be cached
5862 my $have_blame = gitweb_check_feature
('blame');
5863 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5864 or die_error
(500, "Couldn't cat $file_name, $hash");
5865 my $mimetype = blob_mimetype
($fd, $file_name);
5866 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5867 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5869 return git_blob_plain
($mimetype);
5871 # we can have blame only for text/* mimetype
5872 $have_blame &&= ($mimetype =~ m!^text/!);
5874 my $highlight = gitweb_check_feature
('highlight');
5875 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5876 $fd = run_highlighter
($fd, $highlight, $syntax)
5879 git_header_html
(undef, $expires);
5880 my $formats_nav = '';
5881 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5882 if (defined $file_name) {
5885 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5890 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5893 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5896 $cgi->a({-href
=> href
(action
=>"blob",
5897 hash_base
=>"HEAD", file_name
=>$file_name)},
5901 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5904 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5905 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5907 print "<div class=\"page_nav\">\n" .
5908 "<br/><br/></div>\n" .
5909 "<div class=\"title\">".esc_html
($hash)."</div>\n";
5911 git_print_page_path
($file_name, "blob", $hash_base);
5912 print "<div class=\"page_body\">\n";
5913 if ($mimetype =~ m!^image/!) {
5914 print qq!<img type
="!.esc_attr($mimetype).qq!"!;
5916 print qq! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
5919 href(action=>"blob_plain
", hash=>$hash,
5920 hash_base=>$hash_base, file_name=>$file_name) .
5924 while (my $line = <$fd>) {
5927 $line = untabify
($line);
5928 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5929 $nr, esc_attr
(href
(-replay
=> 1)), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5933 or print "Reading blob failed.\n";
5939 if (!defined $hash_base) {
5940 $hash_base = "HEAD";
5942 if (!defined $hash) {
5943 if (defined $file_name) {
5944 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5949 die_error
(404, "No such tree") unless defined($hash);
5951 my $show_sizes = gitweb_check_feature
('show-sizes');
5952 my $have_blame = gitweb_check_feature
('blame');
5957 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5958 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5959 or die_error
(500, "Open git-ls-tree failed");
5960 @entries = map { chomp; $_ } <$fd>;
5962 or die_error
(404, "Reading tree failed");
5965 my $refs = git_get_references
();
5966 my $ref = format_ref_marker
($refs, $hash_base);
5969 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5971 if (defined $file_name) {
5973 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5975 $cgi->a({-href
=> href
(action
=>"tree",
5976 hash_base
=>"HEAD", file_name
=>$file_name)},
5979 my $snapshot_links = format_snapshot_links
($hash);
5980 if (defined $snapshot_links) {
5981 # FIXME: Should be available when we have no hash base as well.
5982 push @views_nav, $snapshot_links;
5984 git_print_page_nav
('tree','', $hash_base, undef, undef,
5985 join(' | ', @views_nav));
5986 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5989 print "<div class=\"page_nav\">\n";
5990 print "<br/><br/></div>\n";
5991 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
5993 if (defined $file_name) {
5994 $basedir = $file_name;
5995 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5998 git_print_page_path
($file_name, 'tree', $hash_base);
6000 print "<div class=\"page_body\">\n";
6001 print "<table class=\"tree\">\n";
6003 # '..' (top directory) link if possible
6004 if (defined $hash_base &&
6005 defined $file_name && $file_name =~ m![^/]+$!) {
6007 print "<tr class=\"dark\">\n";
6009 print "<tr class=\"light\">\n";
6013 my $up = $file_name;
6014 $up =~ s!/?[^/]+$!!;
6015 undef $up unless $up;
6016 # based on git_print_tree_entry
6017 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
6018 print '<td class="size"> </td>'."\n" if $show_sizes;
6019 print '<td class="list">';
6020 print $cgi->a({-href
=> href
(action
=>"tree",
6021 hash_base
=>$hash_base,
6025 print "<td class=\"link\"></td>\n";
6029 foreach my $line (@entries) {
6030 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
6033 print "<tr class=\"dark\">\n";
6035 print "<tr class=\"light\">\n";
6039 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
6043 print "</table>\n" .
6049 my ($project, $hash) = @_;
6051 # path/to/project.git -> project
6052 # path/to/project/.git -> project
6053 my $name = to_utf8
($project);
6054 $name =~ s
,([^/])/*\
.git
$,$1,;
6055 $name = basename
($name);
6057 $name =~ s/[[:cntrl:]]/?/g;
6060 if ($hash =~ /^[0-9a-fA-F]+$/) {
6061 # shorten SHA-1 hash
6062 my $full_hash = git_get_full_hash
($project, $hash);
6063 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
6064 $ver = git_get_short_hash
($project, $hash);
6066 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
6067 # tags don't need shortened SHA-1 hash
6070 # branches and other need shortened SHA-1 hash
6071 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
6074 $ver .= '-' . git_get_short_hash
($project, $hash);
6076 # in case of hierarchical branch names
6079 # name = project-version_string
6080 $name = "$name-$ver";
6082 return wantarray ?
($name, $name) : $name;
6086 my $format = $input_params{'snapshot_format'};
6087 if (!@snapshot_fmts) {
6088 die_error
(403, "Snapshots not allowed");
6090 # default to first supported snapshot format
6091 $format ||= $snapshot_fmts[0];
6092 if ($format !~ m/^[a-z0-9]+$/) {
6093 die_error
(400, "Invalid snapshot format parameter");
6094 } elsif (!exists($known_snapshot_formats{$format})) {
6095 die_error
(400, "Unknown snapshot format");
6096 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
6097 die_error
(403, "Snapshot format not allowed");
6098 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
6099 die_error
(403, "Unsupported snapshot format");
6102 my $type = git_get_type
("$hash^{}");
6104 die_error
(404, 'Object does not exist');
6105 } elsif ($type eq 'blob') {
6106 die_error
(400, 'Object is not a tree-ish');
6109 my ($name, $prefix) = snapshot_name
($project, $hash);
6110 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
6111 my $cmd = quote_command
(
6112 git_cmd
(), 'archive',
6113 "--format=$known_snapshot_formats{$format}{'format'}",
6114 "--prefix=$prefix/", $hash);
6115 if (exists $known_snapshot_formats{$format}{'compressor'}) {
6116 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
6119 $filename =~ s/(["\\])/\\$1/g;
6121 -type
=> $known_snapshot_formats{$format}{'type'},
6122 -content_disposition
=> 'inline; filename="' . $filename . '"',
6123 -status
=> '200 OK');
6125 open my $fd, "-|", $cmd
6126 or die_error
(500, "Execute git-archive failed");
6127 binmode STDOUT
, ':raw';
6129 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
6133 sub git_log_generic
{
6134 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
6136 my $head = git_get_head_hash
($project);
6137 if (!defined $base) {
6140 if (!defined $page) {
6143 my $refs = git_get_references
();
6145 my $commit_hash = $base;
6146 if (defined $parent) {
6147 $commit_hash = "$parent..$base";
6150 parse_commits
($commit_hash, 101, (100 * $page),
6151 defined $file_name ?
($file_name, "--full-history") : ());
6154 if (!defined $file_hash && defined $file_name) {
6155 # some commits could have deleted file in question,
6156 # and not have it in tree, but one of them has to have it
6157 for (my $i = 0; $i < @commitlist; $i++) {
6158 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
6159 last if defined $file_hash;
6162 if (defined $file_hash) {
6163 $ftype = git_get_type
($file_hash);
6165 if (defined $file_name && !defined $ftype) {
6166 die_error
(500, "Unknown type of object");
6169 if (defined $file_name) {
6170 %co = parse_commit
($base)
6171 or die_error
(404, "Unknown commit object");
6175 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
6177 if ($#commitlist >= 100) {
6179 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6180 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6182 my $patch_max = gitweb_get_feature
('patches');
6183 if ($patch_max && !defined $file_name) {
6184 if ($patch_max < 0 || @commitlist <= $patch_max) {
6185 $paging_nav .= " ⋅ " .
6186 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6192 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
6193 if (defined $file_name) {
6194 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
6196 git_print_header_div
('summary', $project)
6198 git_print_page_path
($file_name, $ftype, $hash_base)
6199 if (defined $file_name);
6201 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
6202 $file_name, $file_hash, $ftype);
6208 git_log_generic
('log', \
&git_log_body
,
6209 $hash, $hash_parent);
6213 $hash ||= $hash_base || "HEAD";
6214 my %co = parse_commit
($hash)
6215 or die_error
(404, "Unknown commit object");
6217 my $parent = $co{'parent'};
6218 my $parents = $co{'parents'}; # listref
6220 # we need to prepare $formats_nav before any parameter munging
6222 if (!defined $parent) {
6224 $formats_nav .= '(initial)';
6225 } elsif (@
$parents == 1) {
6226 # single parent commit
6229 $cgi->a({-href
=> href
(action
=>"commit",
6231 esc_html
(substr($parent, 0, 7))) .
6238 $cgi->a({-href
=> href
(action
=>"commit",
6240 esc_html
(substr($_, 0, 7)));
6244 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
6245 $formats_nav .= " | " .
6246 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6250 if (!defined $parent) {
6254 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
6256 (@
$parents <= 1 ?
$parent : '-c'),
6258 or die_error
(500, "Open git-diff-tree failed");
6259 @difftree = map { chomp; $_ } <$fd>;
6260 close $fd or die_error
(404, "Reading git-diff-tree failed");
6262 # non-textual hash id's can be cached
6264 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6267 my $refs = git_get_references
();
6268 my $ref = format_ref_marker
($refs, $co{'id'});
6270 git_header_html
(undef, $expires);
6271 git_print_page_nav
('commit', '',
6272 $hash, $co{'tree'}, $hash,
6275 if (defined $co{'parent'}) {
6276 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
6278 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
6280 print "<div class=\"title_text\">\n" .
6281 "<table class=\"object_header\">\n";
6282 git_print_authorship_rows
(\
%co);
6283 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6286 "<td class=\"sha1\">" .
6287 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6288 class => "list"}, $co{'tree'}) .
6290 "<td class=\"link\">" .
6291 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6293 my $snapshot_links = format_snapshot_links
($hash);
6294 if (defined $snapshot_links) {
6295 print " | " . $snapshot_links;
6300 foreach my $par (@
$parents) {
6303 "<td class=\"sha1\">" .
6304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6305 class => "list"}, $par) .
6307 "<td class=\"link\">" .
6308 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6310 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6317 print "<div class=\"page_body\">\n";
6318 git_print_log
($co{'comment'});
6321 git_difftree_body
(\
@difftree, $hash, @
$parents);
6327 # object is defined by:
6328 # - hash or hash_base alone
6329 # - hash_base and file_name
6332 # - hash or hash_base alone
6333 if ($hash || ($hash_base && !defined $file_name)) {
6334 my $object_id = $hash || $hash_base;
6336 open my $fd, "-|", quote_command
(
6337 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6338 or die_error
(404, "Object does not exist");
6342 or die_error
(404, "Object does not exist");
6344 # - hash_base and file_name
6345 } elsif ($hash_base && defined $file_name) {
6346 $file_name =~ s
,/+$,,;
6348 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6349 or die_error
(404, "Base object does not exist");
6351 # here errors should not hapen
6352 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6353 or die_error
(500, "Open git-ls-tree failed");
6357 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6358 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6359 die_error
(404, "File or directory for given base does not exist");
6364 die_error
(400, "Not enough information to find object");
6367 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6368 hash
=>$hash, hash_base
=>$hash_base,
6369 file_name
=>$file_name),
6370 -status
=> '302 Found');
6374 my $format = shift || 'html';
6381 # preparing $fd and %diffinfo for git_patchset_body
6383 if (defined $hash_base && defined $hash_parent_base) {
6384 if (defined $file_name) {
6386 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6387 $hash_parent_base, $hash_base,
6388 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6389 or die_error
(500, "Open git-diff-tree failed");
6390 @difftree = map { chomp; $_ } <$fd>;
6392 or die_error
(404, "Reading git-diff-tree failed");
6394 or die_error
(404, "Blob diff not found");
6396 } elsif (defined $hash &&
6397 $hash =~ /[0-9a-fA-F]{40}/) {
6398 # try to find filename from $hash
6400 # read filtered raw output
6401 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6402 $hash_parent_base, $hash_base, "--"
6403 or die_error
(500, "Open git-diff-tree failed");
6405 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6407 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6408 map { chomp; $_ } <$fd>;
6410 or die_error
(404, "Reading git-diff-tree failed");
6412 or die_error
(404, "Blob diff not found");
6415 die_error
(400, "Missing one of the blob diff parameters");
6418 if (@difftree > 1) {
6419 die_error
(400, "Ambiguous blob diff specification");
6422 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6423 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6424 $file_name ||= $diffinfo{'to_file'};
6426 $hash_parent ||= $diffinfo{'from_id'};
6427 $hash ||= $diffinfo{'to_id'};
6429 # non-textual hash id's can be cached
6430 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6431 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6436 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6437 '-p', ($format eq 'html' ?
"--full-index" : ()),
6438 $hash_parent_base, $hash_base,
6439 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6440 or die_error
(500, "Open git-diff-tree failed");
6443 # old/legacy style URI -- not generated anymore since 1.4.3.
6445 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6449 if ($format eq 'html') {
6451 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6453 git_header_html
(undef, $expires);
6454 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6455 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6456 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6458 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6459 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
6461 if (defined $file_name) {
6462 git_print_page_path
($file_name, "blob", $hash_base);
6464 print "<div class=\"page_path\"></div>\n";
6467 } elsif ($format eq 'plain') {
6469 -type
=> 'text/plain',
6470 -charset
=> 'utf-8',
6471 -expires
=> $expires,
6472 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6474 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6477 die_error
(400, "Unknown blobdiff format");
6481 if ($format eq 'html') {
6482 print "<div class=\"page_body\">\n";
6484 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6487 print "</div>\n"; # class="page_body"
6491 while (my $line = <$fd>) {
6492 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6493 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6497 last if $line =~ m!^\+\+\+!;
6505 sub git_blobdiff_plain
{
6506 git_blobdiff
('plain');
6509 sub git_commitdiff
{
6511 my $format = $params{-format
} || 'html';
6513 my ($patch_max) = gitweb_get_feature
('patches');
6514 if ($format eq 'patch') {
6515 die_error
(403, "Patch view not allowed") unless $patch_max;
6518 $hash ||= $hash_base || "HEAD";
6519 my %co = parse_commit
($hash)
6520 or die_error
(404, "Unknown commit object");
6522 # choose format for commitdiff for merge
6523 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6524 $hash_parent = '--cc';
6526 # we need to prepare $formats_nav before almost any parameter munging
6528 if ($format eq 'html') {
6530 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6532 if ($patch_max && @
{$co{'parents'}} <= 1) {
6533 $formats_nav .= " | " .
6534 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6538 if (defined $hash_parent &&
6539 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6540 # commitdiff with two commits given
6541 my $hash_parent_short = $hash_parent;
6542 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6543 $hash_parent_short = substr($hash_parent, 0, 7);
6547 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6548 if ($co{'parents'}[$i] eq $hash_parent) {
6549 $formats_nav .= ' parent ' . ($i+1);
6553 $formats_nav .= ': ' .
6554 $cgi->a({-href
=> href
(action
=>"commitdiff",
6555 hash
=>$hash_parent)},
6556 esc_html
($hash_parent_short)) .
6558 } elsif (!$co{'parent'}) {
6560 $formats_nav .= ' (initial)';
6561 } elsif (scalar @
{$co{'parents'}} == 1) {
6562 # single parent commit
6565 $cgi->a({-href
=> href
(action
=>"commitdiff",
6566 hash
=>$co{'parent'})},
6567 esc_html
(substr($co{'parent'}, 0, 7))) .
6571 if ($hash_parent eq '--cc') {
6572 $formats_nav .= ' | ' .
6573 $cgi->a({-href
=> href
(action
=>"commitdiff",
6574 hash
=>$hash, hash_parent
=>'-c')},
6576 } else { # $hash_parent eq '-c'
6577 $formats_nav .= ' | ' .
6578 $cgi->a({-href
=> href
(action
=>"commitdiff",
6579 hash
=>$hash, hash_parent
=>'--cc')},
6585 $cgi->a({-href
=> href
(action
=>"commitdiff",
6587 esc_html
(substr($_, 0, 7)));
6588 } @
{$co{'parents'}} ) .
6593 my $hash_parent_param = $hash_parent;
6594 if (!defined $hash_parent_param) {
6595 # --cc for multiple parents, --root for parentless
6596 $hash_parent_param =
6597 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6603 if ($format eq 'html') {
6604 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6605 "--no-commit-id", "--patch-with-raw", "--full-index",
6606 $hash_parent_param, $hash, "--"
6607 or die_error
(500, "Open git-diff-tree failed");
6609 while (my $line = <$fd>) {
6611 # empty line ends raw part of diff-tree output
6613 push @difftree, scalar parse_difftree_raw_line
($line);
6616 } elsif ($format eq 'plain') {
6617 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6618 '-p', $hash_parent_param, $hash, "--"
6619 or die_error
(500, "Open git-diff-tree failed");
6620 } elsif ($format eq 'patch') {
6621 # For commit ranges, we limit the output to the number of
6622 # patches specified in the 'patches' feature.
6623 # For single commits, we limit the output to a single patch,
6624 # diverging from the git-format-patch default.
6625 my @commit_spec = ();
6627 if ($patch_max > 0) {
6628 push @commit_spec, "-$patch_max";
6630 push @commit_spec, '-n', "$hash_parent..$hash";
6632 if ($params{-single
}) {
6633 push @commit_spec, '-1';
6635 if ($patch_max > 0) {
6636 push @commit_spec, "-$patch_max";
6638 push @commit_spec, "-n";
6640 push @commit_spec, '--root', $hash;
6642 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6643 '--encoding=utf8', '--stdout', @commit_spec
6644 or die_error
(500, "Open git-format-patch failed");
6646 die_error
(400, "Unknown commitdiff format");
6649 # non-textual hash id's can be cached
6651 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6655 # write commit message
6656 if ($format eq 'html') {
6657 my $refs = git_get_references
();
6658 my $ref = format_ref_marker
($refs, $co{'id'});
6660 git_header_html
(undef, $expires);
6661 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6662 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6663 print "<div class=\"title_text\">\n" .
6664 "<table class=\"object_header\">\n";
6665 git_print_authorship_rows
(\
%co);
6668 print "<div class=\"page_body\">\n";
6669 if (@
{$co{'comment'}} > 1) {
6670 print "<div class=\"log\">\n";
6671 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6672 print "</div>\n"; # class="log"
6675 } elsif ($format eq 'plain') {
6676 my $refs = git_get_references
("tags");
6677 my $tagname = git_get_rev_name_tags
($hash);
6678 my $filename = basename
($project) . "-$hash.patch";
6681 -type
=> 'text/plain',
6682 -charset
=> 'utf-8',
6683 -expires
=> $expires,
6684 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6685 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6686 print "From: " . to_utf8
($co{'author'}) . "\n";
6687 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6688 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6690 print "X-Git-Tag: $tagname\n" if $tagname;
6691 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6693 foreach my $line (@
{$co{'comment'}}) {
6694 print to_utf8
($line) . "\n";
6697 } elsif ($format eq 'patch') {
6698 my $filename = basename
($project) . "-$hash.patch";
6701 -type
=> 'text/plain',
6702 -charset
=> 'utf-8',
6703 -expires
=> $expires,
6704 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6708 if ($format eq 'html') {
6709 my $use_parents = !defined $hash_parent ||
6710 $hash_parent eq '-c' || $hash_parent eq '--cc';
6711 git_difftree_body
(\
@difftree, $hash,
6712 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6715 git_patchset_body
($fd, \
@difftree, $hash,
6716 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6718 print "</div>\n"; # class="page_body"
6721 } elsif ($format eq 'plain') {
6725 or print "Reading git-diff-tree failed\n";
6726 } elsif ($format eq 'patch') {
6730 or print "Reading git-format-patch failed\n";
6734 sub git_commitdiff_plain
{
6735 git_commitdiff
(-format
=> 'plain');
6738 # format-patch-style patches
6740 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6744 git_commitdiff
(-format
=> 'patch');
6748 git_log_generic
('history', \
&git_history_body
,
6749 $hash_base, $hash_parent_base,
6754 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6755 if (!defined $searchtext) {
6756 die_error
(400, "Text field is empty");
6758 if (!defined $hash) {
6759 $hash = git_get_head_hash
($project);
6761 my %co = parse_commit
($hash);
6763 die_error
(404, "Unknown commit object");
6765 if (!defined $page) {
6769 $searchtype ||= 'commit';
6770 if ($searchtype eq 'pickaxe') {
6771 # pickaxe may take all resources of your box and run for several minutes
6772 # with every query - so decide by yourself how public you make this feature
6773 gitweb_check_feature
('pickaxe')
6774 or die_error
(403, "Pickaxe is disabled");
6776 if ($searchtype eq 'grep') {
6777 gitweb_check_feature
('grep')
6778 or die_error
(403, "Grep is disabled");
6783 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6785 if ($searchtype eq 'commit') {
6786 $greptype = "--grep=";
6787 } elsif ($searchtype eq 'author') {
6788 $greptype = "--author=";
6789 } elsif ($searchtype eq 'committer') {
6790 $greptype = "--committer=";
6792 $greptype .= $searchtext;
6793 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6794 $greptype, '--regexp-ignore-case',
6795 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6797 my $paging_nav = '';
6800 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6801 searchtext
=>$searchtext,
6802 searchtype
=>$searchtype)},
6804 $paging_nav .= " ⋅ " .
6805 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6806 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6808 $paging_nav .= "first";
6809 $paging_nav .= " ⋅ prev";
6812 if ($#commitlist >= 100) {
6814 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6815 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6816 $paging_nav .= " ⋅ $next_link";
6818 $paging_nav .= " ⋅ next";
6821 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6822 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6823 if ($page == 0 && !@commitlist) {
6824 print "<p>No match.</p>\n";
6826 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6830 if ($searchtype eq 'pickaxe') {
6831 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6832 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6834 print "<table class=\"pickaxe search\">\n";
6837 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6838 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6839 ($search_use_regexp ?
'--pickaxe-regex' : ());
6842 while (my $line = <$fd>) {
6846 my %set = parse_difftree_raw_line
($line);
6847 if (defined $set{'commit'}) {
6848 # finish previous commit
6851 "<td class=\"link\">" .
6852 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6854 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6860 print "<tr class=\"dark\">\n";
6862 print "<tr class=\"light\">\n";
6865 %co = parse_commit
($set{'commit'});
6866 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6867 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6868 "<td><i>$author</i></td>\n" .
6870 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6871 -class => "list subject"},
6872 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6873 } elsif (defined $set{'to_id'}) {
6874 next if ($set{'to_id'} =~ m/^0{40}$/);
6876 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6877 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6879 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6885 # finish last commit (warning: repetition!)
6888 "<td class=\"link\">" .
6889 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6891 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6899 if ($searchtype eq 'grep') {
6900 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6901 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6903 print "<table class=\"grep_search\">\n";
6907 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6908 $search_use_regexp ?
('-E', '-i') : '-F',
6909 $searchtext, $co{'tree'};
6911 while (my $line = <$fd>) {
6913 my ($file, $lno, $ltext, $binary);
6914 last if ($matches++ > 1000);
6915 if ($line =~ /^Binary file (.+) matches$/) {
6919 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6921 if ($file ne $lastfile) {
6922 $lastfile and print "</td></tr>\n";
6924 print "<tr class=\"dark\">\n";
6926 print "<tr class=\"light\">\n";
6928 print "<td class=\"list\">".
6929 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6930 file_name
=>"$file"),
6931 -class => "list"}, esc_path
($file));
6932 print "</td><td>\n";
6936 print "<div class=\"binary\">Binary file</div>\n";
6938 $ltext = untabify
($ltext);
6939 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6940 $ltext = esc_html
($1, -nbsp
=>1);
6941 $ltext .= '<span class="match">';
6942 $ltext .= esc_html
($2, -nbsp
=>1);
6943 $ltext .= '</span>';
6944 $ltext .= esc_html
($3, -nbsp
=>1);
6946 $ltext = esc_html
($ltext, -nbsp
=>1);
6948 print "<div class=\"pre\">" .
6949 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6950 file_name
=>"$file").'#l'.$lno,
6951 -class => "linenr"}, sprintf('%4i', $lno))
6952 . ' ' . $ltext . "</div>\n";
6956 print "</td></tr>\n";
6957 if ($matches > 1000) {
6958 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6961 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6970 sub git_search_help
{
6972 git_print_page_nav
('','', $hash,$hash,$hash);
6974 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6975 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6976 the pattern entered is recognized as the POSIX extended
6977 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6980 <dt><b>commit</b></dt>
6981 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6983 my $have_grep = gitweb_check_feature
('grep');
6986 <dt><b>grep</b></dt>
6987 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6988 a different one) are searched for the given pattern. On large trees, this search can take
6989 a while and put some strain on the server, so please use it with some consideration. Note that
6990 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6991 case-sensitive.</dd>
6995 <dt><b>author</b></dt>
6996 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6997 <dt><b>committer</b></dt>
6998 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
7000 my $have_pickaxe = gitweb_check_feature
('pickaxe');
7001 if ($have_pickaxe) {
7003 <dt><b>pickaxe</b></dt>
7004 <dd>All commits that caused the string to appear or disappear from any file (changes that
7005 added, removed or "modified" the string) will be listed. This search can take a while and
7006 takes a lot of strain on the server, so please use it wisely. Note that since you may be
7007 interested even in changes just changing the case as well, this search is case sensitive.</dd>
7015 git_log_generic
('shortlog', \
&git_shortlog_body
,
7016 $hash, $hash_parent);
7019 ## ......................................................................
7020 ## feeds (RSS, Atom; OPML)
7023 my $format = shift || 'atom';
7024 my $have_blame = gitweb_check_feature
('blame');
7026 # Atom: http://www.atomenabled.org/developers/syndication/
7027 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
7028 if ($format ne 'rss' && $format ne 'atom') {
7029 die_error
(400, "Unknown web feed format");
7032 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
7033 my $head = $hash || 'HEAD';
7034 my @commitlist = parse_commits
($head, 150, 0, $file_name);
7038 my $content_type = "application/$format+xml";
7039 if (defined $cgi->http('HTTP_ACCEPT') &&
7040 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
7041 # browser (feed reader) prefers text/xml
7042 $content_type = 'text/xml';
7044 if (defined($commitlist[0])) {
7045 %latest_commit = %{$commitlist[0]};
7046 my $latest_epoch = $latest_commit{'committer_epoch'};
7047 %latest_date = parse_date
($latest_epoch);
7048 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
7049 if (defined $if_modified) {
7051 if (eval { require HTTP
::Date
; 1; }) {
7052 $since = HTTP
::Date
::str2time
($if_modified);
7053 } elsif (eval { require Time
::ParseDate
; 1; }) {
7054 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
7056 if (defined $since && $latest_epoch <= $since) {
7058 -type
=> $content_type,
7059 -charset
=> 'utf-8',
7060 -last_modified
=> $latest_date{'rfc2822'},
7061 -status
=> '304 Not Modified');
7066 -type
=> $content_type,
7067 -charset
=> 'utf-8',
7068 -last_modified
=> $latest_date{'rfc2822'});
7071 -type
=> $content_type,
7072 -charset
=> 'utf-8');
7075 # Optimization: skip generating the body if client asks only
7076 # for Last-Modified date.
7077 return if ($cgi->request_method() eq 'HEAD');
7080 my $title = "$site_name - $project/$action";
7081 my $feed_type = 'log';
7082 if (defined $hash) {
7083 $title .= " - '$hash'";
7084 $feed_type = 'branch log';
7085 if (defined $file_name) {
7086 $title .= " :: $file_name";
7087 $feed_type = 'history';
7089 } elsif (defined $file_name) {
7090 $title .= " - $file_name";
7091 $feed_type = 'history';
7093 $title .= " $feed_type";
7094 my $descr = git_get_project_description
($project);
7095 if (defined $descr) {
7096 $descr = esc_html
($descr);
7098 $descr = "$project " .
7099 ($format eq 'rss' ?
'RSS' : 'Atom') .
7102 my $owner = git_get_project_owner
($project);
7103 $owner = esc_html
($owner);
7107 if (defined $file_name) {
7108 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
7109 } elsif (defined $hash) {
7110 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
7112 $alt_url = href
(-full
=>1, action
=>"summary");
7114 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
7115 if ($format eq 'rss') {
7117 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
7120 print "<title>$title</title>\n" .
7121 "<link>$alt_url</link>\n" .
7122 "<description>$descr</description>\n" .
7123 "<language>en</language>\n" .
7124 # project owner is responsible for 'editorial' content
7125 "<managingEditor>$owner</managingEditor>\n";
7126 if (defined $logo || defined $favicon) {
7127 # prefer the logo to the favicon, since RSS
7128 # doesn't allow both
7129 my $img = esc_url
($logo || $favicon);
7131 "<url>$img</url>\n" .
7132 "<title>$title</title>\n" .
7133 "<link>$alt_url</link>\n" .
7137 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
7138 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
7140 print "<generator>gitweb v.$version/$git_version</generator>\n";
7141 } elsif ($format eq 'atom') {
7143 <feed xmlns="http://www.w3.org/2005/Atom">
7145 print "<title>$title</title>\n" .
7146 "<subtitle>$descr</subtitle>\n" .
7147 '<link rel="alternate" type="text/html" href="' .
7148 $alt_url . '" />' . "\n" .
7149 '<link rel="self" type="' . $content_type . '" href="' .
7150 $cgi->self_url() . '" />' . "\n" .
7151 "<id>" . href
(-full
=>1) . "</id>\n" .
7152 # use project owner for feed author
7153 "<author><name>$owner</name></author>\n";
7154 if (defined $favicon) {
7155 print "<icon>" . esc_url
($favicon) . "</icon>\n";
7157 if (defined $logo_url) {
7158 # not twice as wide as tall: 72 x 27 pixels
7159 print "<logo>" . esc_url
($logo) . "</logo>\n";
7161 if (! %latest_date) {
7162 # dummy date to keep the feed valid until commits trickle in:
7163 print "<updated>1970-01-01T00:00:00Z</updated>\n";
7165 print "<updated>$latest_date{'iso-8601'}</updated>\n";
7167 print "<generator version='$version/$git_version'>gitweb</generator>\n";
7171 for (my $i = 0; $i <= $#commitlist; $i++) {
7172 my %co = %{$commitlist[$i]};
7173 my $commit = $co{'id'};
7174 # we read 150, we always show 30 and the ones more recent than 48 hours
7175 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
7178 my %cd = parse_date
($co{'author_epoch'});
7180 # get list of changed files
7181 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7182 $co{'parent'} || "--root",
7183 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
7185 my @difftree = map { chomp; $_ } <$fd>;
7189 # print element (entry, item)
7190 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
7191 if ($format eq 'rss') {
7193 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
7194 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
7195 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
7196 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
7197 "<link>$co_url</link>\n" .
7198 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
7199 "<content:encoded>" .
7201 } elsif ($format eq 'atom') {
7203 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
7204 "<updated>$cd{'iso-8601'}</updated>\n" .
7206 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
7207 if ($co{'author_email'}) {
7208 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
7210 print "</author>\n" .
7211 # use committer for contributor
7213 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
7214 if ($co{'committer_email'}) {
7215 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
7217 print "</contributor>\n" .
7218 "<published>$cd{'iso-8601'}</published>\n" .
7219 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
7220 "<id>$co_url</id>\n" .
7221 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
7222 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
7224 my $comment = $co{'comment'};
7226 foreach my $line (@
$comment) {
7227 $line = esc_html
($line);
7230 print "</pre><ul>\n";
7231 foreach my $difftree_line (@difftree) {
7232 my %difftree = parse_difftree_raw_line
($difftree_line);
7233 next if !$difftree{'from_id'};
7235 my $file = $difftree{'file'} || $difftree{'to_file'};
7239 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
7240 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
7241 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
7242 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
7243 -title
=> "diff"}, 'D');
7245 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
7246 file_name
=>$file, hash_base
=>$commit),
7247 -title
=> "blame"}, 'B');
7249 # if this is not a feed of a file history
7250 if (!defined $file_name || $file_name ne $file) {
7251 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
7252 file_name
=>$file, hash
=>$commit),
7253 -title
=> "history"}, 'H');
7255 $file = esc_path
($file);
7259 if ($format eq 'rss') {
7260 print "</ul>]]>\n" .
7261 "</content:encoded>\n" .
7263 } elsif ($format eq 'atom') {
7264 print "</ul>\n</div>\n" .
7271 if ($format eq 'rss') {
7272 print "</channel>\n</rss>\n";
7273 } elsif ($format eq 'atom') {
7287 my @list = git_get_projects_list
();
7290 -type
=> 'text/xml',
7291 -charset
=> 'utf-8',
7292 -content_disposition
=> 'inline; filename="opml.xml"');
7295 <?xml version="1.0" encoding="utf-8"?>
7296 <opml version="1.0">
7298 <title>$site_name OPML Export</title>
7301 <outline text="git RSS feeds">
7304 foreach my $pr (@list) {
7306 my $head = git_get_head_hash
($proj{'path'});
7307 if (!defined $head) {
7310 $git_dir = "$projectroot/$proj{'path'}";
7311 my %co = parse_commit
($head);
7316 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7317 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7318 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7319 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";