3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI
->compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
33 our $my_url = $cgi->url();
34 our $my_uri = $cgi->url(-absolute
=> 1);
36 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
37 # needed and used only for URLs with nonempty PATH_INFO
38 our $base_url = $my_url;
40 # When the script is used as DirectoryIndex, the URL does not contain the name
41 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
42 # have to do it ourselves. We make $path_info global because it's also used
45 # Another issue with the script being the DirectoryIndex is that the resulting
46 # $my_url data is not the full script URL: this is good, because we want
47 # generated links to keep implying the script name if it wasn't explicitly
48 # indicated in the URL we're handling, but it means that $my_url cannot be used
50 # Therefore, if we needed to strip PATH_INFO, then we know that we have
51 # to build the base URL ourselves:
52 our $path_info = $ENV{"PATH_INFO"};
54 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
55 $my_uri =~ s
,\Q
$path_info\E
$,, &&
56 defined $ENV{'SCRIPT_NAME'}) {
57 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
61 # core git executable to use
62 # this can just be "git" if your webserver has a sensible PATH
63 our $GIT = "++GIT_BINDIR++/git";
65 # absolute fs-path which will be prepended to the project path
66 #our $projectroot = "/pub/scm";
67 our $projectroot = "++GITWEB_PROJECTROOT++";
69 # fs traversing limit for getting project list
70 # the number is relative to the projectroot
71 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
73 # target of the home link on top of all pages
74 our $home_link = $my_uri || "/";
76 # string of the home link on top of all pages
77 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
79 # name of your site or organization to appear in page titles
80 # replace this with something more descriptive for clearer bookmarks
81 our $site_name = "++GITWEB_SITENAME++"
82 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
84 # filename of html text to include at top of each page
85 our $site_header = "++GITWEB_SITE_HEADER++";
86 # html text to include at home page
87 our $home_text = "++GITWEB_HOMETEXT++";
88 # filename of html text to include at bottom of each page
89 our $site_footer = "++GITWEB_SITE_FOOTER++";
92 our @stylesheets = ("++GITWEB_CSS++");
93 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
94 our $stylesheet = undef;
95 # URI of GIT logo (72x27 size)
96 our $logo = "++GITWEB_LOGO++";
97 # URI of GIT favicon, assumed to be image/png type
98 our $favicon = "++GITWEB_FAVICON++";
99 # URI of gitweb.js (JavaScript code for gitweb)
100 our $javascript = "++GITWEB_JS++";
102 # URI and label (title) of GIT logo link
103 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
104 #our $logo_label = "git documentation";
105 our $logo_url = "http://git-scm.com/";
106 our $logo_label = "git homepage";
108 # source of projects list
109 our $projects_list = "++GITWEB_LIST++";
111 # the width (in characters) of the projects list "Description" column
112 our $projects_list_description_width = 25;
114 # default order of projects list
115 # valid values are none, project, descr, owner, and age
116 our $default_projects_order = "project";
118 # show repository only if this file exists
119 # (only effective if this variable evaluates to true)
120 our $export_ok = "++GITWEB_EXPORT_OK++";
122 # show repository only if this subroutine returns true
123 # when given the path to the project, for example:
124 # sub { return -e "$_[0]/git-daemon-export-ok"; }
125 our $export_auth_hook = undef;
127 # only allow viewing of repositories also shown on the overview page
128 our $strict_export = "++GITWEB_STRICT_EXPORT++";
130 # list of git base URLs used for URL to where fetch project from,
131 # i.e. full URL is "$git_base_url/$project"
132 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
134 # default blob_plain mimetype and default charset for text/plain blob
135 our $default_blob_plain_mimetype = 'text/plain';
136 our $default_text_plain_charset = undef;
138 # file to use for guessing MIME types before trying /etc/mime.types
139 # (relative to the current git repository)
140 our $mimetypes_file = undef;
142 # assume this charset if line contains non-UTF-8 characters;
143 # it should be valid encoding (see Encoding::Supported(3pm) for list),
144 # for which encoding all byte sequences are valid, for example
145 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
146 # could be even 'utf-8' for the old behavior)
147 our $fallback_encoding = 'latin1';
149 # rename detection options for git-diff and git-diff-tree
150 # - default is '-M', with the cost proportional to
151 # (number of removed files) * (number of new files).
152 # - more costly is '-C' (which implies '-M'), with the cost proportional to
153 # (number of changed files + number of removed files) * (number of new files)
154 # - even more costly is '-C', '--find-copies-harder' with cost
155 # (number of files in the original tree) * (number of new files)
156 # - one might want to include '-B' option, e.g. '-B', '-M'
157 our @diff_opts = ('-M'); # taken from git_commit
159 # Disables features that would allow repository owners to inject script into
161 our $prevent_xss = 0;
163 # information about snapshot formats that gitweb is capable of serving
164 our %known_snapshot_formats = (
166 # 'display' => display name,
167 # 'type' => mime type,
168 # 'suffix' => filename suffix,
169 # 'format' => --format for git-archive,
170 # 'compressor' => [compressor command and arguments]
171 # (array reference, optional)
172 # 'disabled' => boolean (optional)}
175 'display' => 'tar.gz',
176 'type' => 'application/x-gzip',
177 'suffix' => '.tar.gz',
179 'compressor' => ['gzip']},
182 'display' => 'tar.bz2',
183 'type' => 'application/x-bzip2',
184 'suffix' => '.tar.bz2',
186 'compressor' => ['bzip2']},
189 'display' => 'tar.xz',
190 'type' => 'application/x-xz',
191 'suffix' => '.tar.xz',
193 'compressor' => ['xz'],
198 'type' => 'application/x-zip',
203 # Aliases so we understand old gitweb.snapshot values in repository
205 our %known_snapshot_format_aliases = (
210 # backward compatibility: legacy gitweb config support
211 'x-gzip' => undef, 'gz' => undef,
212 'x-bzip2' => undef, 'bz2' => undef,
213 'x-zip' => undef, '' => undef,
216 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
217 # are changed, it may be appropriate to change these values too via
224 # Used to set the maximum load that we will still respond to gitweb queries.
225 # If server load exceed this value then return "503 server busy" error.
226 # If gitweb cannot determined server load, it is taken to be 0.
227 # Leave it undefined (or set to 'undef') to turn off load checking.
230 # This enables/disables the caching layer in gitweb. Currently supported
231 # is only output (response) caching, similar to the one used on git.kernel.org.
232 our $caching_enabled = 0;
233 # Set to _initialized_ instance of cache interface implementing (at least)
234 # get($key) and set($key, $data) methods (Cache::Cache and CHI interfaces).
235 # If unset, GitwebCache::SimpleFileCache would be used, which is 'dumb'
236 # (but fast) file based caching layer, currently without any support for
237 # cache size limiting. It is therefore recommended that the cache directory
238 # be periodically completely deleted; this operation is safe to perform.
239 # Suggested mechanism:
240 # mv $cachedir $cachedir.flush && mkdir $cachedir && rm -rf $cachedir.flush
242 # Locations of 'cache.pm' file; if it is relative path, it is relative to
243 # the directory gitweb is run from
244 our $cache_pm = 'cache.pm';
245 # You define site-wide cache options defaults here; override them with
246 # $GITWEB_CONFIG as necessary.
247 our %cache_options = (
248 # The location in the filesystem that will hold the root of the cache.
249 # This directory will be created as needed (if possible) on the first
250 # cache set. Note that either this directory must exists and web server
251 # has to have write permissions to it, or web server must be able to
252 # create this directory.
254 # * 'cache' (relative to gitweb),
255 # * File::Spec->catdir(File::Spec->tmpdir(), 'gitweb-cache'),
256 # * '/var/cache/gitweb' (FHS compliant, requires being set up),
257 'cache_root' => 'cache',
258 # The number of subdirectories deep to cache object item. This should be
259 # large enough that no cache directory has more than a few hundred
260 # objects. Each non-leaf directory contains up to 256 subdirectories
261 # (00-ff). Must be larger than 0.
263 # The (global) expiration time for objects placed in the cache, in seconds.
268 # You define site-wide feature defaults here; override them with
269 # $GITWEB_CONFIG as necessary.
272 # 'sub' => feature-sub (subroutine),
273 # 'override' => allow-override (boolean),
274 # 'default' => [ default options...] (array reference)}
276 # if feature is overridable (it means that allow-override has true value),
277 # then feature-sub will be called with default options as parameters;
278 # return value of feature-sub indicates if to enable specified feature
280 # if there is no 'sub' key (no feature-sub), then feature cannot be
283 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
284 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
287 # Enable the 'blame' blob view, showing the last commit that modified
288 # each line in the file. This can be very CPU-intensive.
290 # To enable system wide have in $GITWEB_CONFIG
291 # $feature{'blame'}{'default'} = [1];
292 # To have project specific config enable override in $GITWEB_CONFIG
293 # $feature{'blame'}{'override'} = 1;
294 # and in project config gitweb.blame = 0|1;
296 'sub' => sub { feature_bool
('blame', @_) },
300 # Enable the 'snapshot' link, providing a compressed archive of any
301 # tree. This can potentially generate high traffic if you have large
304 # Value is a list of formats defined in %known_snapshot_formats that
306 # To disable system wide have in $GITWEB_CONFIG
307 # $feature{'snapshot'}{'default'} = [];
308 # To have project specific config enable override in $GITWEB_CONFIG
309 # $feature{'snapshot'}{'override'} = 1;
310 # and in project config, a comma-separated list of formats or "none"
311 # to disable. Example: gitweb.snapshot = tbz2,zip;
313 'sub' => \
&feature_snapshot
,
315 'default' => ['tgz']},
317 # Enable text search, which will list the commits which match author,
318 # committer or commit text to a given string. Enabled by default.
319 # Project specific override is not supported.
324 # Enable grep search, which will list the files in currently selected
325 # tree containing the given string. Enabled by default. This can be
326 # potentially CPU-intensive, of course.
328 # To enable system wide have in $GITWEB_CONFIG
329 # $feature{'grep'}{'default'} = [1];
330 # To have project specific config enable override in $GITWEB_CONFIG
331 # $feature{'grep'}{'override'} = 1;
332 # and in project config gitweb.grep = 0|1;
334 'sub' => sub { feature_bool
('grep', @_) },
338 # Enable the pickaxe search, which will list the commits that modified
339 # a given string in a file. This can be practical and quite faster
340 # alternative to 'blame', but still potentially CPU-intensive.
342 # To enable system wide have in $GITWEB_CONFIG
343 # $feature{'pickaxe'}{'default'} = [1];
344 # To have project specific config enable override in $GITWEB_CONFIG
345 # $feature{'pickaxe'}{'override'} = 1;
346 # and in project config gitweb.pickaxe = 0|1;
348 'sub' => sub { feature_bool
('pickaxe', @_) },
352 # Enable showing size of blobs in a 'tree' view, in a separate
353 # column, similar to what 'ls -l' does. This cost a bit of IO.
355 # To disable system wide have in $GITWEB_CONFIG
356 # $feature{'show-sizes'}{'default'} = [0];
357 # To have project specific config enable override in $GITWEB_CONFIG
358 # $feature{'show-sizes'}{'override'} = 1;
359 # and in project config gitweb.showsizes = 0|1;
361 'sub' => sub { feature_bool
('showsizes', @_) },
365 # Make gitweb use an alternative format of the URLs which can be
366 # more readable and natural-looking: project name is embedded
367 # directly in the path and the query string contains other
368 # auxiliary information. All gitweb installations recognize
369 # URL in either format; this configures in which formats gitweb
372 # To enable system wide have in $GITWEB_CONFIG
373 # $feature{'pathinfo'}{'default'} = [1];
374 # Project specific override is not supported.
376 # Note that you will need to change the default location of CSS,
377 # favicon, logo and possibly other files to an absolute URL. Also,
378 # if gitweb.cgi serves as your indexfile, you will need to force
379 # $my_uri to contain the script name in your $GITWEB_CONFIG.
384 # Make gitweb consider projects in project root subdirectories
385 # to be forks of existing projects. Given project $projname.git,
386 # projects matching $projname/*.git will not be shown in the main
387 # projects list, instead a '+' mark will be added to $projname
388 # there and a 'forks' view will be enabled for the project, listing
389 # all the forks. If project list is taken from a file, forks have
390 # to be listed after the main project.
392 # To enable system wide have in $GITWEB_CONFIG
393 # $feature{'forks'}{'default'} = [1];
394 # Project specific override is not supported.
399 # Insert custom links to the action bar of all project pages.
400 # This enables you mainly to link to third-party scripts integrating
401 # into gitweb; e.g. git-browser for graphical history representation
402 # or custom web-based repository administration interface.
404 # The 'default' value consists of a list of triplets in the form
405 # (label, link, position) where position is the label after which
406 # to insert the link and link is a format string where %n expands
407 # to the project name, %f to the project path within the filesystem,
408 # %h to the current hash (h gitweb parameter) and %b to the current
409 # hash base (hb gitweb parameter); %% expands to %.
411 # To enable system wide have in $GITWEB_CONFIG e.g.
412 # $feature{'actions'}{'default'} = [('graphiclog',
413 # '/git-browser/by-commit.html?r=%n', 'summary')];
414 # Project specific override is not supported.
419 # Allow gitweb scan project content tags described in ctags/
420 # of project repository, and display the popular Web 2.0-ish
421 # "tag cloud" near the project list. Note that this is something
422 # COMPLETELY different from the normal Git tags.
424 # gitweb by itself can show existing tags, but it does not handle
425 # tagging itself; you need an external application for that.
426 # For an example script, check Girocco's cgi/tagproj.cgi.
427 # You may want to install the HTML::TagCloud Perl module to get
428 # a pretty tag cloud instead of just a list of tags.
430 # To enable system wide have in $GITWEB_CONFIG
431 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
432 # Project specific override is not supported.
437 # The maximum number of patches in a patchset generated in patch
438 # view. Set this to 0 or undef to disable patch view, or to a
439 # negative number to remove any limit.
441 # To disable system wide have in $GITWEB_CONFIG
442 # $feature{'patches'}{'default'} = [0];
443 # To have project specific config enable override in $GITWEB_CONFIG
444 # $feature{'patches'}{'override'} = 1;
445 # and in project config gitweb.patches = 0|n;
446 # where n is the maximum number of patches allowed in a patchset.
448 'sub' => \
&feature_patches
,
452 # Avatar support. When this feature is enabled, views such as
453 # shortlog or commit will display an avatar associated with
454 # the email of the committer(s) and/or author(s).
456 # Currently available providers are gravatar and picon.
457 # If an unknown provider is specified, the feature is disabled.
459 # Gravatar depends on Digest::MD5.
460 # Picon currently relies on the indiana.edu database.
462 # To enable system wide have in $GITWEB_CONFIG
463 # $feature{'avatar'}{'default'} = ['<provider>'];
464 # where <provider> is either gravatar or picon.
465 # To have project specific config enable override in $GITWEB_CONFIG
466 # $feature{'avatar'}{'override'} = 1;
467 # and in project config gitweb.avatar = <provider>;
469 'sub' => \
&feature_avatar
,
473 # Enable displaying how much time and how many git commands
474 # it took to generate and display page. Disabled by default.
475 # Project specific override is not supported.
480 # Enable turning some links into links to actions which require
481 # JavaScript to run (like 'blame_incremental'). Not enabled by
482 # default. Project specific override is currently not supported.
483 'javascript-actions' => {
488 sub gitweb_get_feature
{
490 return unless exists $feature{$name};
491 my ($sub, $override, @defaults) = (
492 $feature{$name}{'sub'},
493 $feature{$name}{'override'},
494 @
{$feature{$name}{'default'}});
495 if (!$override) { return @defaults; }
497 warn "feature $name is not overridable";
500 return $sub->(@defaults);
503 # A wrapper to check if a given feature is enabled.
504 # With this, you can say
506 # my $bool_feat = gitweb_check_feature('bool_feat');
507 # gitweb_check_feature('bool_feat') or somecode;
511 # my ($bool_feat) = gitweb_get_feature('bool_feat');
512 # (gitweb_get_feature('bool_feat'))[0] or somecode;
514 sub gitweb_check_feature
{
515 return (gitweb_get_feature
(@_))[0];
521 my ($val) = git_get_project_config
($key, '--bool');
525 } elsif ($val eq 'true') {
527 } elsif ($val eq 'false') {
532 sub feature_snapshot
{
535 my ($val) = git_get_project_config
('snapshot');
538 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
544 sub feature_patches
{
545 my @val = (git_get_project_config
('patches', '--int'));
555 my @val = (git_get_project_config
('avatar'));
557 return @val ?
@val : @_;
560 # checking HEAD file with -e is fragile if the repository was
561 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
563 sub check_head_link
{
565 my $headfile = "$dir/HEAD";
566 return ((-e
$headfile) ||
567 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
570 sub check_export_ok
{
572 return (check_head_link
($dir) &&
573 (!$export_ok || -e
"$dir/$export_ok") &&
574 (!$export_auth_hook || $export_auth_hook->($dir)));
577 # process alternate names for backward compatibility
578 # filter out unsupported (unknown) snapshot formats
579 sub filter_snapshot_fmts
{
583 exists $known_snapshot_format_aliases{$_} ?
584 $known_snapshot_format_aliases{$_} : $_} @fmts;
586 exists $known_snapshot_formats{$_} &&
587 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
590 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
591 if (-e
$GITWEB_CONFIG) {
594 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
595 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
598 # Get loadavg of system, to compare against $maxload.
599 # Currently it requires '/proc/loadavg' present to get loadavg;
600 # if it is not present it returns 0, which means no load checking.
602 if( -e
'/proc/loadavg' ){
603 open my $fd, '<', '/proc/loadavg'
605 my @load = split(/\s+/, scalar <$fd>);
608 # The first three columns measure CPU and IO utilization of the last one,
609 # five, and 10 minute periods. The fourth column shows the number of
610 # currently running processes and the total number of processes in the m/n
611 # format. The last column displays the last process ID used.
612 return $load[0] || 0;
614 # additional checks for load average should go here for things that don't export
620 # version of the core git binary
621 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
622 $number_of_git_cmds++;
624 $projects_list ||= $projectroot;
626 if (defined $maxload && get_loadavg
() > $maxload) {
627 die_error
(503, "The load average on the server is too high");
630 # ======================================================================
631 # input validation and dispatch
633 # input parameters can be collected from a variety of sources (presently, CGI
634 # and PATH_INFO), so we define an %input_params hash that collects them all
635 # together during validation: this allows subsequent uses (e.g. href()) to be
636 # agnostic of the parameter origin
638 our %input_params = ();
640 # input parameters are stored with the long parameter name as key. This will
641 # also be used in the href subroutine to convert parameters to their CGI
642 # equivalent, and since the href() usage is the most frequent one, we store
643 # the name -> CGI key mapping here, instead of the reverse.
645 # XXX: Warning: If you touch this, check the search form for updating,
648 our @cgi_param_mapping = (
656 hash_parent_base
=> "hpb",
661 snapshot_format
=> "sf",
662 extra_options
=> "opt",
663 search_use_regexp
=> "sr",
664 # this must be last entry (for manipulation from JavaScript)
667 our %cgi_param_mapping = @cgi_param_mapping;
669 # we will also need to know the possible actions, for validation
671 "blame" => \
&git_blame
,
672 "blame_incremental" => \
&git_blame_incremental
,
673 "blame_data" => \
&git_blame_data
,
674 "blobdiff" => \
&git_blobdiff
,
675 "blobdiff_plain" => \
&git_blobdiff_plain
,
676 "blob" => \
&git_blob
,
677 "blob_plain" => \
&git_blob_plain
,
678 "commitdiff" => \
&git_commitdiff
,
679 "commitdiff_plain" => \
&git_commitdiff_plain
,
680 "commit" => \
&git_commit
,
681 "forks" => \
&git_forks
,
682 "heads" => \
&git_heads
,
683 "history" => \
&git_history
,
685 "patch" => \
&git_patch
,
686 "patches" => \
&git_patches
,
688 "atom" => \
&git_atom
,
689 "search" => \
&git_search
,
690 "search_help" => \
&git_search_help
,
691 "shortlog" => \
&git_shortlog
,
692 "summary" => \
&git_summary
,
694 "tags" => \
&git_tags
,
695 "tree" => \
&git_tree
,
696 "snapshot" => \
&git_snapshot
,
697 "object" => \
&git_object
,
698 # those below don't need $project
699 "opml" => \
&git_opml
,
700 "project_list" => \
&git_project_list
,
701 "project_index" => \
&git_project_index
,
704 # finally, we have the hash of allowed extra_options for the commands that
706 our %allowed_options = (
707 "--no-merges" => [ qw(rss atom log shortlog history) ],
710 # fill %input_params with the CGI parameters. All values except for 'opt'
711 # should be single values, but opt can be an array. We should probably
712 # build an array of parameters that can be multi-valued, but since for the time
713 # being it's only this one, we just single it out
714 while (my ($name, $symbol) = each %cgi_param_mapping) {
715 if ($symbol eq 'opt') {
716 $input_params{$name} = [ $cgi->param($symbol) ];
718 $input_params{$name} = $cgi->param($symbol);
722 # now read PATH_INFO and update the parameter list for missing parameters
723 sub evaluate_path_info
{
724 return if defined $input_params{'project'};
725 return if !$path_info;
726 $path_info =~ s
,^/+,,;
727 return if !$path_info;
729 # find which part of PATH_INFO is project
730 my $project = $path_info;
732 while ($project && !check_head_link
("$projectroot/$project")) {
733 $project =~ s
,/*[^/]*$,,;
735 return unless $project;
736 $input_params{'project'} = $project;
738 # do not change any parameters if an action is given using the query string
739 return if $input_params{'action'};
740 $path_info =~ s
,^\Q
$project\E
/*,,;
742 # next, check if we have an action
743 my $action = $path_info;
745 if (exists $actions{$action}) {
746 $path_info =~ s
,^$action/*,,;
747 $input_params{'action'} = $action;
750 # list of actions that want hash_base instead of hash, but can have no
751 # pathname (f) parameter
758 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
759 my ($parentrefname, $parentpathname, $refname, $pathname) =
760 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
762 # first, analyze the 'current' part
763 if (defined $pathname) {
764 # we got "branch:filename" or "branch:dir/"
765 # we could use git_get_type(branch:pathname), but:
766 # - it needs $git_dir
767 # - it does a git() call
768 # - the convention of terminating directories with a slash
769 # makes it superfluous
770 # - embedding the action in the PATH_INFO would make it even
772 $pathname =~ s
,^/+,,;
773 if (!$pathname || substr($pathname, -1) eq "/") {
774 $input_params{'action'} ||= "tree";
777 # the default action depends on whether we had parent info
779 if ($parentrefname) {
780 $input_params{'action'} ||= "blobdiff_plain";
782 $input_params{'action'} ||= "blob_plain";
785 $input_params{'hash_base'} ||= $refname;
786 $input_params{'file_name'} ||= $pathname;
787 } elsif (defined $refname) {
788 # we got "branch". In this case we have to choose if we have to
789 # set hash or hash_base.
791 # Most of the actions without a pathname only want hash to be
792 # set, except for the ones specified in @wants_base that want
793 # hash_base instead. It should also be noted that hand-crafted
794 # links having 'history' as an action and no pathname or hash
795 # set will fail, but that happens regardless of PATH_INFO.
796 $input_params{'action'} ||= "shortlog";
797 if (grep { $_ eq $input_params{'action'} } @wants_base) {
798 $input_params{'hash_base'} ||= $refname;
800 $input_params{'hash'} ||= $refname;
804 # next, handle the 'parent' part, if present
805 if (defined $parentrefname) {
806 # a missing pathspec defaults to the 'current' filename, allowing e.g.
807 # someproject/blobdiff/oldrev..newrev:/filename
808 if ($parentpathname) {
809 $parentpathname =~ s
,^/+,,;
810 $parentpathname =~ s
,/$,,;
811 $input_params{'file_parent'} ||= $parentpathname;
813 $input_params{'file_parent'} ||= $input_params{'file_name'};
815 # we assume that hash_parent_base is wanted if a path was specified,
816 # or if the action wants hash_base instead of hash
817 if (defined $input_params{'file_parent'} ||
818 grep { $_ eq $input_params{'action'} } @wants_base) {
819 $input_params{'hash_parent_base'} ||= $parentrefname;
821 $input_params{'hash_parent'} ||= $parentrefname;
825 # for the snapshot action, we allow URLs in the form
826 # $project/snapshot/$hash.ext
827 # where .ext determines the snapshot and gets removed from the
828 # passed $refname to provide the $hash.
830 # To be able to tell that $refname includes the format extension, we
831 # require the following two conditions to be satisfied:
832 # - the hash input parameter MUST have been set from the $refname part
833 # of the URL (i.e. they must be equal)
834 # - the snapshot format MUST NOT have been defined already (e.g. from
836 # It's also useless to try any matching unless $refname has a dot,
837 # so we check for that too
838 if (defined $input_params{'action'} &&
839 $input_params{'action'} eq 'snapshot' &&
840 defined $refname && index($refname, '.') != -1 &&
841 $refname eq $input_params{'hash'} &&
842 !defined $input_params{'snapshot_format'}) {
843 # We loop over the known snapshot formats, checking for
844 # extensions. Allowed extensions are both the defined suffix
845 # (which includes the initial dot already) and the snapshot
846 # format key itself, with a prepended dot
847 while (my ($fmt, $opt) = each %known_snapshot_formats) {
849 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
853 # a valid suffix was found, so set the snapshot format
854 # and reset the hash parameter
855 $input_params{'snapshot_format'} = $fmt;
856 $input_params{'hash'} = $hash;
857 # we also set the format suffix to the one requested
858 # in the URL: this way a request for e.g. .tgz returns
859 # a .tgz instead of a .tar.gz
860 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
865 evaluate_path_info
();
867 our $action = $input_params{'action'};
868 if (defined $action) {
869 if (!validate_action
($action)) {
870 die_error
(400, "Invalid action parameter");
874 # parameters which are pathnames
875 our $project = $input_params{'project'};
876 if (defined $project) {
877 if (!validate_project
($project)) {
879 die_error
(404, "No such project");
883 our $file_name = $input_params{'file_name'};
884 if (defined $file_name) {
885 if (!validate_pathname
($file_name)) {
886 die_error
(400, "Invalid file parameter");
890 our $file_parent = $input_params{'file_parent'};
891 if (defined $file_parent) {
892 if (!validate_pathname
($file_parent)) {
893 die_error
(400, "Invalid file parent parameter");
897 # parameters which are refnames
898 our $hash = $input_params{'hash'};
900 if (!validate_refname
($hash)) {
901 die_error
(400, "Invalid hash parameter");
905 our $hash_parent = $input_params{'hash_parent'};
906 if (defined $hash_parent) {
907 if (!validate_refname
($hash_parent)) {
908 die_error
(400, "Invalid hash parent parameter");
912 our $hash_base = $input_params{'hash_base'};
913 if (defined $hash_base) {
914 if (!validate_refname
($hash_base)) {
915 die_error
(400, "Invalid hash base parameter");
919 our @extra_options = @
{$input_params{'extra_options'}};
920 # @extra_options is always defined, since it can only be (currently) set from
921 # CGI, and $cgi->param() returns the empty array in array context if the param
923 foreach my $opt (@extra_options) {
924 if (not exists $allowed_options{$opt}) {
925 die_error
(400, "Invalid option parameter");
927 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
928 die_error
(400, "Invalid option parameter for this action");
932 our $hash_parent_base = $input_params{'hash_parent_base'};
933 if (defined $hash_parent_base) {
934 if (!validate_refname
($hash_parent_base)) {
935 die_error
(400, "Invalid hash parent base parameter");
940 our $page = $input_params{'page'};
942 if ($page =~ m/[^0-9]/) {
943 die_error
(400, "Invalid page parameter");
947 our $searchtype = $input_params{'searchtype'};
948 if (defined $searchtype) {
949 if ($searchtype =~ m/[^a-z]/) {
950 die_error
(400, "Invalid searchtype parameter");
954 our $search_use_regexp = $input_params{'search_use_regexp'};
956 our $searchtext = $input_params{'searchtext'};
958 if (defined $searchtext) {
959 if (length($searchtext) < 2) {
960 die_error
(403, "At least two characters are required for search parameter");
962 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
965 # path to the current git repository
967 $git_dir = "$projectroot/$project" if $project;
969 # list of supported snapshot formats
970 our @snapshot_fmts = gitweb_get_feature
('snapshot');
971 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
973 # check that the avatar feature is set to a known provider name,
974 # and for each provider check if the dependencies are satisfied.
975 # if the provider name is invalid or the dependencies are not met,
976 # reset $git_avatar to the empty string.
977 our ($git_avatar) = gitweb_get_feature
('avatar');
978 if ($git_avatar eq 'gravatar') {
979 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
980 } elsif ($git_avatar eq 'picon') {
987 if (!defined $action) {
989 $action = git_get_type
($hash);
990 } elsif (defined $hash_base && defined $file_name) {
991 $action = git_get_type
("$hash_base:$file_name");
992 } elsif (defined $project) {
995 $action = 'project_list';
998 if (!defined($actions{$action})) {
999 die_error
(400, "Unknown action");
1001 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1003 die_error
(400, "Project needed");
1006 if ($caching_enabled) {
1007 die_error
(500, 'Caching enabled and "'.esc_path
($cache_pm).'" not found')
1008 unless -f
$cache_pm;
1012 # $cache might be initialized (instantiated) cache, i.e. cache object,
1013 # or it might be name of class, or it might be undefined
1014 unless (defined $cache && ref($cache)) {
1015 $cache ||= 'GitwebCache::SimpleFileCache';
1016 $cache = $cache->new({
1018 #'cache_root' => '/tmp/cache',
1019 #'cache_depth' => 2,
1020 #'expires_in' => 20, # in seconds (CHI compatibile)
1021 # (Cache::Cache compatibile initialization)
1022 'default_expires_in' => $cache_options{'expires_in'},
1023 # (CHI compatibile initialization)
1024 'root_dir' => $cache_options{'cache_root'},
1025 'depth' => $cache_options{'cache_depth'},
1028 cache_fetch
($cache, $action);
1030 $actions{$action}->();
1035 ## ======================================================================
1038 # possible values of extra options
1039 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1040 # -replay => 1 - start from a current view (replay with modifications)
1041 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1044 # default is to use -absolute url() i.e. $my_uri
1045 my $href = $params{-full
} ?
$my_url : $my_uri;
1047 $params{'project'} = $project unless exists $params{'project'};
1049 if ($params{-replay
}) {
1050 while (my ($name, $symbol) = each %cgi_param_mapping) {
1051 if (!exists $params{$name}) {
1052 $params{$name} = $input_params{$name};
1057 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1058 if (defined $params{'project'} &&
1059 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1060 # try to put as many parameters as possible in PATH_INFO:
1063 # - hash_parent or hash_parent_base:/file_parent
1064 # - hash or hash_base:/filename
1065 # - the snapshot_format as an appropriate suffix
1067 # When the script is the root DirectoryIndex for the domain,
1068 # $href here would be something like http://gitweb.example.com/
1069 # Thus, we strip any trailing / from $href, to spare us double
1070 # slashes in the final URL
1073 # Then add the project name, if present
1074 $href .= "/".esc_url
($params{'project'});
1075 delete $params{'project'};
1077 # since we destructively absorb parameters, we keep this
1078 # boolean that remembers if we're handling a snapshot
1079 my $is_snapshot = $params{'action'} eq 'snapshot';
1081 # Summary just uses the project path URL, any other action is
1083 if (defined $params{'action'}) {
1084 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1085 delete $params{'action'};
1088 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1089 # stripping nonexistent or useless pieces
1090 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1091 || $params{'hash_parent'} || $params{'hash'});
1092 if (defined $params{'hash_base'}) {
1093 if (defined $params{'hash_parent_base'}) {
1094 $href .= esc_url
($params{'hash_parent_base'});
1095 # skip the file_parent if it's the same as the file_name
1096 if (defined $params{'file_parent'}) {
1097 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1098 delete $params{'file_parent'};
1099 } elsif ($params{'file_parent'} !~ /\.\./) {
1100 $href .= ":/".esc_url
($params{'file_parent'});
1101 delete $params{'file_parent'};
1105 delete $params{'hash_parent'};
1106 delete $params{'hash_parent_base'};
1107 } elsif (defined $params{'hash_parent'}) {
1108 $href .= esc_url
($params{'hash_parent'}). "..";
1109 delete $params{'hash_parent'};
1112 $href .= esc_url
($params{'hash_base'});
1113 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1114 $href .= ":/".esc_url
($params{'file_name'});
1115 delete $params{'file_name'};
1117 delete $params{'hash'};
1118 delete $params{'hash_base'};
1119 } elsif (defined $params{'hash'}) {
1120 $href .= esc_url
($params{'hash'});
1121 delete $params{'hash'};
1124 # If the action was a snapshot, we can absorb the
1125 # snapshot_format parameter too
1127 my $fmt = $params{'snapshot_format'};
1128 # snapshot_format should always be defined when href()
1129 # is called, but just in case some code forgets, we
1130 # fall back to the default
1131 $fmt ||= $snapshot_fmts[0];
1132 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1133 delete $params{'snapshot_format'};
1137 # now encode the parameters explicitly
1139 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1140 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1141 if (defined $params{$name}) {
1142 if (ref($params{$name}) eq "ARRAY") {
1143 foreach my $par (@
{$params{$name}}) {
1144 push @result, $symbol . "=" . esc_param
($par);
1147 push @result, $symbol . "=" . esc_param
($params{$name});
1151 $href .= "?" . join(';', @result) if scalar @result;
1157 ## ======================================================================
1158 ## validation, quoting/unquoting and escaping
1160 sub validate_action
{
1161 my $input = shift || return undef;
1162 return undef unless exists $actions{$input};
1166 sub validate_project
{
1167 my $input = shift || return undef;
1168 if (!validate_pathname
($input) ||
1169 !(-d
"$projectroot/$input") ||
1170 !check_export_ok
("$projectroot/$input") ||
1171 ($strict_export && !project_in_list
($input))) {
1178 sub validate_pathname
{
1179 my $input = shift || return undef;
1181 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1182 # at the beginning, at the end, and between slashes.
1183 # also this catches doubled slashes
1184 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1187 # no null characters
1188 if ($input =~ m!\0!) {
1194 sub validate_refname
{
1195 my $input = shift || return undef;
1197 # textual hashes are O.K.
1198 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1201 # it must be correct pathname
1202 $input = validate_pathname
($input)
1204 # restrictions on ref name according to git-check-ref-format
1205 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1211 # decode sequences of octets in utf8 into Perl's internal form,
1212 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1213 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1216 if (utf8
::valid
($str)) {
1220 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1224 # quote unsafe chars, but keep the slash, even when it's not
1225 # correct, but quoted slashes look too horrible in bookmarks
1228 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1233 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1236 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1242 # replace invalid utf8 character with SUBSTITUTION sequence
1247 $str = to_utf8
($str);
1248 $str = $cgi->escapeHTML($str);
1249 if ($opts{'-nbsp'}) {
1250 $str =~ s/ / /g;
1252 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1256 # quote control characters and escape filename to HTML
1261 $str = to_utf8
($str);
1262 $str = $cgi->escapeHTML($str);
1263 if ($opts{'-nbsp'}) {
1264 $str =~ s/ / /g;
1266 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1270 # Make control characters "printable", using character escape codes (CEC)
1274 my %es = ( # character escape codes, aka escape sequences
1275 "\t" => '\t', # tab (HT)
1276 "\n" => '\n', # line feed (LF)
1277 "\r" => '\r', # carrige return (CR)
1278 "\f" => '\f', # form feed (FF)
1279 "\b" => '\b', # backspace (BS)
1280 "\a" => '\a', # alarm (bell) (BEL)
1281 "\e" => '\e', # escape (ESC)
1282 "\013" => '\v', # vertical tab (VT)
1283 "\000" => '\0', # nul character (NUL)
1285 my $chr = ( (exists $es{$cntrl})
1287 : sprintf('\%2x', ord($cntrl)) );
1288 if ($opts{-nohtml
}) {
1291 return "<span class=\"cntrl\">$chr</span>";
1295 # Alternatively use unicode control pictures codepoints,
1296 # Unicode "printable representation" (PR)
1301 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1302 if ($opts{-nohtml
}) {
1305 return "<span class=\"cntrl\">$chr</span>";
1309 # git may return quoted and escaped filenames
1315 my %es = ( # character escape codes, aka escape sequences
1316 't' => "\t", # tab (HT, TAB)
1317 'n' => "\n", # newline (NL)
1318 'r' => "\r", # return (CR)
1319 'f' => "\f", # form feed (FF)
1320 'b' => "\b", # backspace (BS)
1321 'a' => "\a", # alarm (bell) (BEL)
1322 'e' => "\e", # escape (ESC)
1323 'v' => "\013", # vertical tab (VT)
1326 if ($seq =~ m/^[0-7]{1,3}$/) {
1327 # octal char sequence
1328 return chr(oct($seq));
1329 } elsif (exists $es{$seq}) {
1330 # C escape sequence, aka character escape code
1333 # quoted ordinary character
1337 if ($str =~ m/^"(.*)"$/) {
1340 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1345 # escape tabs (convert tabs to spaces)
1349 while ((my $pos = index($line, "\t")) != -1) {
1350 if (my $count = (8 - ($pos % 8))) {
1351 my $spaces = ' ' x
$count;
1352 $line =~ s/\t/$spaces/;
1359 sub project_in_list
{
1360 my $project = shift;
1361 my @list = git_get_projects_list
();
1362 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1365 ## ----------------------------------------------------------------------
1366 ## HTML aware string manipulation
1368 # Try to chop given string on a word boundary between position
1369 # $len and $len+$add_len. If there is no word boundary there,
1370 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1371 # (marking chopped part) would be longer than given string.
1375 my $add_len = shift || 10;
1376 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1378 # Make sure perl knows it is utf8 encoded so we don't
1379 # cut in the middle of a utf8 multibyte char.
1380 $str = to_utf8
($str);
1382 # allow only $len chars, but don't cut a word if it would fit in $add_len
1383 # if it doesn't fit, cut it if it's still longer than the dots we would add
1384 # remove chopped character entities entirely
1386 # when chopping in the middle, distribute $len into left and right part
1387 # return early if chopping wouldn't make string shorter
1388 if ($where eq 'center') {
1389 return $str if ($len + 5 >= length($str)); # filler is length 5
1392 return $str if ($len + 4 >= length($str)); # filler is length 4
1395 # regexps: ending and beginning with word part up to $add_len
1396 my $endre = qr/.{$len}\w{0,$add_len}/;
1397 my $begre = qr/\w{0,$add_len}.{$len}/;
1399 if ($where eq 'left') {
1400 $str =~ m/^(.*?)($begre)$/;
1401 my ($lead, $body) = ($1, $2);
1402 if (length($lead) > 4) {
1405 return "$lead$body";
1407 } elsif ($where eq 'center') {
1408 $str =~ m/^($endre)(.*)$/;
1409 my ($left, $str) = ($1, $2);
1410 $str =~ m/^(.*?)($begre)$/;
1411 my ($mid, $right) = ($1, $2);
1412 if (length($mid) > 5) {
1415 return "$left$mid$right";
1418 $str =~ m/^($endre)(.*)$/;
1421 if (length($tail) > 4) {
1424 return "$body$tail";
1428 # takes the same arguments as chop_str, but also wraps a <span> around the
1429 # result with a title attribute if it does get chopped. Additionally, the
1430 # string is HTML-escaped.
1431 sub chop_and_escape_str
{
1434 my $chopped = chop_str
(@_);
1435 if ($chopped eq $str) {
1436 return esc_html
($chopped);
1438 $str =~ s/[[:cntrl:]]/?/g;
1439 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1443 ## ----------------------------------------------------------------------
1444 ## functions returning short strings
1446 # CSS class for given age value (in seconds)
1450 if (!defined $age) {
1452 } elsif ($age < 60*60*2) {
1454 } elsif ($age < 60*60*24*2) {
1461 # convert age in seconds to "nn units ago" string
1466 if ($age > 60*60*24*365*2) {
1467 $age_str = (int $age/60/60/24/365);
1468 $age_str .= " years ago";
1469 } elsif ($age > 60*60*24*(365/12)*2) {
1470 $age_str = int $age/60/60/24/(365/12);
1471 $age_str .= " months ago";
1472 } elsif ($age > 60*60*24*7*2) {
1473 $age_str = int $age/60/60/24/7;
1474 $age_str .= " weeks ago";
1475 } elsif ($age > 60*60*24*2) {
1476 $age_str = int $age/60/60/24;
1477 $age_str .= " days ago";
1478 } elsif ($age > 60*60*2) {
1479 $age_str = int $age/60/60;
1480 $age_str .= " hours ago";
1481 } elsif ($age > 60*2) {
1482 $age_str = int $age/60;
1483 $age_str .= " min ago";
1484 } elsif ($age > 2) {
1485 $age_str = int $age;
1486 $age_str .= " sec ago";
1488 $age_str .= " right now";
1494 S_IFINVALID
=> 0030000,
1495 S_IFGITLINK
=> 0160000,
1498 # submodule/subproject, a commit object reference
1502 return (($mode & S_IFMT
) == S_IFGITLINK
)
1505 # convert file mode in octal to symbolic file mode string
1507 my $mode = oct shift;
1509 if (S_ISGITLINK
($mode)) {
1510 return 'm---------';
1511 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1512 return 'drwxr-xr-x';
1513 } elsif (S_ISLNK
($mode)) {
1514 return 'lrwxrwxrwx';
1515 } elsif (S_ISREG
($mode)) {
1516 # git cares only about the executable bit
1517 if ($mode & S_IXUSR
) {
1518 return '-rwxr-xr-x';
1520 return '-rw-r--r--';
1523 return '----------';
1527 # convert file mode in octal to file type string
1531 if ($mode !~ m/^[0-7]+$/) {
1537 if (S_ISGITLINK
($mode)) {
1539 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1541 } elsif (S_ISLNK
($mode)) {
1543 } elsif (S_ISREG
($mode)) {
1550 # convert file mode in octal to file type description string
1551 sub file_type_long
{
1554 if ($mode !~ m/^[0-7]+$/) {
1560 if (S_ISGITLINK
($mode)) {
1562 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1564 } elsif (S_ISLNK
($mode)) {
1566 } elsif (S_ISREG
($mode)) {
1567 if ($mode & S_IXUSR
) {
1568 return "executable";
1578 ## ----------------------------------------------------------------------
1579 ## functions returning short HTML fragments, or transforming HTML fragments
1580 ## which don't belong to other sections
1582 # format line of commit message.
1583 sub format_log_line_html
{
1586 $line = esc_html
($line, -nbsp
=>1);
1587 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1588 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1589 -class => "text"}, $1);
1595 # format marker of refs pointing to given object
1597 # the destination action is chosen based on object type and current context:
1598 # - for annotated tags, we choose the tag view unless it's the current view
1599 # already, in which case we go to shortlog view
1600 # - for other refs, we keep the current view if we're in history, shortlog or
1601 # log view, and select shortlog otherwise
1602 sub format_ref_marker
{
1603 my ($refs, $id) = @_;
1606 if (defined $refs->{$id}) {
1607 foreach my $ref (@
{$refs->{$id}}) {
1608 # this code exploits the fact that non-lightweight tags are the
1609 # only indirect objects, and that they are the only objects for which
1610 # we want to use tag instead of shortlog as action
1611 my ($type, $name) = qw();
1612 my $indirect = ($ref =~ s/\^\{\}$//);
1613 # e.g. tags/v2.6.11 or heads/next
1614 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1623 $class .= " indirect" if $indirect;
1625 my $dest_action = "shortlog";
1628 $dest_action = "tag" unless $action eq "tag";
1629 } elsif ($action =~ /^(history|(short)?log)$/) {
1630 $dest_action = $action;
1634 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1637 my $link = $cgi->a({
1639 action
=>$dest_action,
1643 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1649 return ' <span class="refs">'. $markers . '</span>';
1655 # format, perhaps shortened and with markers, title line
1656 sub format_subject_html
{
1657 my ($long, $short, $href, $extra) = @_;
1658 $extra = '' unless defined($extra);
1660 if (length($short) < length($long)) {
1661 $long =~ s/[[:cntrl:]]/?/g;
1662 return $cgi->a({-href
=> $href, -class => "list subject",
1663 -title
=> to_utf8
($long)},
1664 esc_html
($short)) . $extra;
1666 return $cgi->a({-href
=> $href, -class => "list subject"},
1667 esc_html
($long)) . $extra;
1671 # Rather than recomputing the url for an email multiple times, we cache it
1672 # after the first hit. This gives a visible benefit in views where the avatar
1673 # for the same email is used repeatedly (e.g. shortlog).
1674 # The cache is shared by all avatar engines (currently gravatar only), which
1675 # are free to use it as preferred. Since only one avatar engine is used for any
1676 # given page, there's no risk for cache conflicts.
1677 our %avatar_cache = ();
1679 # Compute the picon url for a given email, by using the picon search service over at
1680 # http://www.cs.indiana.edu/picons/search.html
1682 my $email = lc shift;
1683 if (!$avatar_cache{$email}) {
1684 my ($user, $domain) = split('@', $email);
1685 $avatar_cache{$email} =
1686 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1688 "users+domains+unknown/up/single";
1690 return $avatar_cache{$email};
1693 # Compute the gravatar url for a given email, if it's not in the cache already.
1694 # Gravatar stores only the part of the URL before the size, since that's the
1695 # one computationally more expensive. This also allows reuse of the cache for
1696 # different sizes (for this particular engine).
1698 my $email = lc shift;
1700 $avatar_cache{$email} ||=
1701 "http://www.gravatar.com/avatar/" .
1702 Digest
::MD5
::md5_hex
($email) . "?s=";
1703 return $avatar_cache{$email} . $size;
1706 # Insert an avatar for the given $email at the given $size if the feature
1708 sub git_get_avatar
{
1709 my ($email, %opts) = @_;
1710 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1711 my $post_white = ($opts{-pad_after
} ?
" " : "");
1712 $opts{-size
} ||= 'default';
1713 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1715 if ($git_avatar eq 'gravatar') {
1716 $url = gravatar_url
($email, $size);
1717 } elsif ($git_avatar eq 'picon') {
1718 $url = picon_url
($email);
1720 # Other providers can be added by extending the if chain, defining $url
1721 # as needed. If no variant puts something in $url, we assume avatars
1722 # are completely disabled/unavailable.
1725 "<img width=\"$size\" " .
1726 "class=\"avatar\" " .
1735 sub format_search_author
{
1736 my ($author, $searchtype, $displaytext) = @_;
1737 my $have_search = gitweb_check_feature
('search');
1741 if ($searchtype eq 'author') {
1742 $performed = "authored";
1743 } elsif ($searchtype eq 'committer') {
1744 $performed = "committed";
1747 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1748 searchtext
=>$author,
1749 searchtype
=>$searchtype), class=>"list",
1750 title
=>"Search for commits $performed by $author"},
1754 return $displaytext;
1758 # format the author name of the given commit with the given tag
1759 # the author name is chopped and escaped according to the other
1760 # optional parameters (see chop_str).
1761 sub format_author_html
{
1764 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1765 return "<$tag class=\"author\">" .
1766 format_search_author
($co->{'author_name'}, "author",
1767 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1772 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1773 sub format_git_diff_header_line
{
1775 my $diffinfo = shift;
1776 my ($from, $to) = @_;
1778 if ($diffinfo->{'nparents'}) {
1780 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1781 if ($to->{'href'}) {
1782 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1783 esc_path
($to->{'file'}));
1784 } else { # file was deleted (no href)
1785 $line .= esc_path
($to->{'file'});
1789 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1790 if ($from->{'href'}) {
1791 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1792 'a/' . esc_path
($from->{'file'}));
1793 } else { # file was added (no href)
1794 $line .= 'a/' . esc_path
($from->{'file'});
1797 if ($to->{'href'}) {
1798 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1799 'b/' . esc_path
($to->{'file'}));
1800 } else { # file was deleted
1801 $line .= 'b/' . esc_path
($to->{'file'});
1805 return "<div class=\"diff header\">$line</div>\n";
1808 # format extended diff header line, before patch itself
1809 sub format_extended_diff_header_line
{
1811 my $diffinfo = shift;
1812 my ($from, $to) = @_;
1815 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1816 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1817 esc_path
($from->{'file'}));
1819 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1820 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1821 esc_path
($to->{'file'}));
1823 # match single <mode>
1824 if ($line =~ m/\s(\d{6})$/) {
1825 $line .= '<span class="info"> (' .
1826 file_type_long
($1) .
1830 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1831 # can match only for combined diff
1833 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1834 if ($from->{'href'}[$i]) {
1835 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1837 substr($diffinfo->{'from_id'}[$i],0,7));
1842 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1845 if ($to->{'href'}) {
1846 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1847 substr($diffinfo->{'to_id'},0,7));
1852 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1853 # can match only for ordinary diff
1854 my ($from_link, $to_link);
1855 if ($from->{'href'}) {
1856 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1857 substr($diffinfo->{'from_id'},0,7));
1859 $from_link = '0' x
7;
1861 if ($to->{'href'}) {
1862 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1863 substr($diffinfo->{'to_id'},0,7));
1867 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1868 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1871 return $line . "<br/>\n";
1874 # format from-file/to-file diff header
1875 sub format_diff_from_to_header
{
1876 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1881 #assert($line =~ m/^---/) if DEBUG;
1882 # no extra formatting for "^--- /dev/null"
1883 if (! $diffinfo->{'nparents'}) {
1884 # ordinary (single parent) diff
1885 if ($line =~ m!^--- "?a/!) {
1886 if ($from->{'href'}) {
1888 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1889 esc_path
($from->{'file'}));
1892 esc_path
($from->{'file'});
1895 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1898 # combined diff (merge commit)
1899 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1900 if ($from->{'href'}[$i]) {
1902 $cgi->a({-href
=>href
(action
=>"blobdiff",
1903 hash_parent
=>$diffinfo->{'from_id'}[$i],
1904 hash_parent_base
=>$parents[$i],
1905 file_parent
=>$from->{'file'}[$i],
1906 hash
=>$diffinfo->{'to_id'},
1908 file_name
=>$to->{'file'}),
1910 -title
=>"diff" . ($i+1)},
1913 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1914 esc_path
($from->{'file'}[$i]));
1916 $line = '--- /dev/null';
1918 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1923 #assert($line =~ m/^\+\+\+/) if DEBUG;
1924 # no extra formatting for "^+++ /dev/null"
1925 if ($line =~ m!^\+\+\+ "?b/!) {
1926 if ($to->{'href'}) {
1928 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1929 esc_path
($to->{'file'}));
1932 esc_path
($to->{'file'});
1935 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1940 # create note for patch simplified by combined diff
1941 sub format_diff_cc_simplified
{
1942 my ($diffinfo, @parents) = @_;
1945 $result .= "<div class=\"diff header\">" .
1947 if (!is_deleted
($diffinfo)) {
1948 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1950 hash
=>$diffinfo->{'to_id'},
1951 file_name
=>$diffinfo->{'to_file'}),
1953 esc_path
($diffinfo->{'to_file'}));
1955 $result .= esc_path
($diffinfo->{'to_file'});
1957 $result .= "</div>\n" . # class="diff header"
1958 "<div class=\"diff nodifferences\">" .
1960 "</div>\n"; # class="diff nodifferences"
1965 # format patch (diff) line (not to be used for diff headers)
1966 sub format_diff_line
{
1968 my ($from, $to) = @_;
1969 my $diff_class = "";
1973 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1975 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1976 if ($line =~ m/^\@{3}/) {
1977 $diff_class = " chunk_header";
1978 } elsif ($line =~ m/^\\/) {
1979 $diff_class = " incomplete";
1980 } elsif ($prefix =~ tr/+/+/) {
1981 $diff_class = " add";
1982 } elsif ($prefix =~ tr/-/-/) {
1983 $diff_class = " rem";
1986 # assume ordinary diff
1987 my $char = substr($line, 0, 1);
1989 $diff_class = " add";
1990 } elsif ($char eq '-') {
1991 $diff_class = " rem";
1992 } elsif ($char eq '@') {
1993 $diff_class = " chunk_header";
1994 } elsif ($char eq "\\") {
1995 $diff_class = " incomplete";
1998 $line = untabify
($line);
1999 if ($from && $to && $line =~ m/^\@{2} /) {
2000 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2001 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2003 $from_lines = 0 unless defined $from_lines;
2004 $to_lines = 0 unless defined $to_lines;
2006 if ($from->{'href'}) {
2007 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2008 -class=>"list"}, $from_text);
2010 if ($to->{'href'}) {
2011 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2012 -class=>"list"}, $to_text);
2014 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2015 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2016 return "<div class=\"diff$diff_class\">$line</div>\n";
2017 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2018 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2019 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2021 @from_text = split(' ', $ranges);
2022 for (my $i = 0; $i < @from_text; ++$i) {
2023 ($from_start[$i], $from_nlines[$i]) =
2024 (split(',', substr($from_text[$i], 1)), 0);
2027 $to_text = pop @from_text;
2028 $to_start = pop @from_start;
2029 $to_nlines = pop @from_nlines;
2031 $line = "<span class=\"chunk_info\">$prefix ";
2032 for (my $i = 0; $i < @from_text; ++$i) {
2033 if ($from->{'href'}[$i]) {
2034 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2035 -class=>"list"}, $from_text[$i]);
2037 $line .= $from_text[$i];
2041 if ($to->{'href'}) {
2042 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2043 -class=>"list"}, $to_text);
2047 $line .= " $prefix</span>" .
2048 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2049 return "<div class=\"diff$diff_class\">$line</div>\n";
2051 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2054 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2055 # linked. Pass the hash of the tree/commit to snapshot.
2056 sub format_snapshot_links
{
2058 my $num_fmts = @snapshot_fmts;
2059 if ($num_fmts > 1) {
2060 # A parenthesized list of links bearing format names.
2061 # e.g. "snapshot (_tar.gz_ _zip_)"
2062 return "snapshot (" . join(' ', map
2069 }, $known_snapshot_formats{$_}{'display'})
2070 , @snapshot_fmts) . ")";
2071 } elsif ($num_fmts == 1) {
2072 # A single "snapshot" link whose tooltip bears the format name.
2074 my ($fmt) = @snapshot_fmts;
2080 snapshot_format
=>$fmt
2082 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2084 } else { # $num_fmts == 0
2089 ## ......................................................................
2090 ## functions returning values to be passed, perhaps after some
2091 ## transformation, to other functions; e.g. returning arguments to href()
2093 # returns hash to be passed to href to generate gitweb URL
2094 # in -title key it returns description of link
2096 my $format = shift || 'Atom';
2097 my %res = (action
=> lc($format));
2099 # feed links are possible only for project views
2100 return unless (defined $project);
2101 # some views should link to OPML, or to generic project feed,
2102 # or don't have specific feed yet (so they should use generic)
2103 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2106 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2107 # from tag links; this also makes possible to detect branch links
2108 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2109 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2112 # find log type for feed description (title)
2114 if (defined $file_name) {
2115 $type = "history of $file_name";
2116 $type .= "/" if ($action eq 'tree');
2117 $type .= " on '$branch'" if (defined $branch);
2119 $type = "log of $branch" if (defined $branch);
2122 $res{-title
} = $type;
2123 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2124 $res{'file_name'} = $file_name;
2129 ## ----------------------------------------------------------------------
2130 ## git utility subroutines, invoking git commands
2132 # returns path to the core git executable and the --git-dir parameter as list
2134 $number_of_git_cmds++;
2135 return $GIT, '--git-dir='.$git_dir;
2138 # quote the given arguments for passing them to the shell
2139 # quote_command("command", "arg 1", "arg with ' and ! characters")
2140 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2141 # Try to avoid using this function wherever possible.
2144 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2147 # get HEAD ref of given project as hash
2148 sub git_get_head_hash
{
2149 return git_get_full_hash
(shift, 'HEAD');
2152 sub git_get_full_hash
{
2153 return git_get_hash
(@_);
2156 sub git_get_short_hash
{
2157 return git_get_hash
(@_, '--short=7');
2161 my ($project, $hash, @options) = @_;
2162 my $o_git_dir = $git_dir;
2164 $git_dir = "$projectroot/$project";
2165 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2166 '--verify', '-q', @options, $hash) {
2168 chomp $retval if defined $retval;
2171 if (defined $o_git_dir) {
2172 $git_dir = $o_git_dir;
2177 # get type of given object
2181 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2183 close $fd or return;
2188 # repository configuration
2189 our $config_file = '';
2192 # store multiple values for single key as anonymous array reference
2193 # single values stored directly in the hash, not as [ <value> ]
2194 sub hash_set_multi
{
2195 my ($hash, $key, $value) = @_;
2197 if (!exists $hash->{$key}) {
2198 $hash->{$key} = $value;
2199 } elsif (!ref $hash->{$key}) {
2200 $hash->{$key} = [ $hash->{$key}, $value ];
2202 push @
{$hash->{$key}}, $value;
2206 # return hash of git project configuration
2207 # optionally limited to some section, e.g. 'gitweb'
2208 sub git_parse_project_config
{
2209 my $section_regexp = shift;
2214 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2217 while (my $keyval = <$fh>) {
2219 my ($key, $value) = split(/\n/, $keyval, 2);
2221 hash_set_multi
(\
%config, $key, $value)
2222 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2229 # convert config value to boolean: 'true' or 'false'
2230 # no value, number > 0, 'true' and 'yes' values are true
2231 # rest of values are treated as false (never as error)
2232 sub config_to_bool
{
2235 return 1 if !defined $val; # section.key
2237 # strip leading and trailing whitespace
2241 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2242 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2245 # convert config value to simple decimal number
2246 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2247 # to be multiplied by 1024, 1048576, or 1073741824
2251 # strip leading and trailing whitespace
2255 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2257 # unknown unit is treated as 1
2258 return $num * ($unit eq 'g' ?
1073741824 :
2259 $unit eq 'm' ?
1048576 :
2260 $unit eq 'k' ?
1024 : 1);
2265 # convert config value to array reference, if needed
2266 sub config_to_multi
{
2269 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2272 sub git_get_project_config
{
2273 my ($key, $type) = @_;
2276 return unless ($key);
2277 $key =~ s/^gitweb\.//;
2278 return if ($key =~ m/\W/);
2281 if (defined $type) {
2284 unless ($type eq 'bool' || $type eq 'int');
2288 if (!defined $config_file ||
2289 $config_file ne "$git_dir/config") {
2290 %config = git_parse_project_config
('gitweb');
2291 $config_file = "$git_dir/config";
2294 # check if config variable (key) exists
2295 return unless exists $config{"gitweb.$key"};
2298 if (!defined $type) {
2299 return $config{"gitweb.$key"};
2300 } elsif ($type eq 'bool') {
2301 # backward compatibility: 'git config --bool' returns true/false
2302 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2303 } elsif ($type eq 'int') {
2304 return config_to_int
($config{"gitweb.$key"});
2306 return $config{"gitweb.$key"};
2309 # get hash of given path at given ref
2310 sub git_get_hash_by_path
{
2312 my $path = shift || return undef;
2317 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2318 or die_error
(500, "Open git-ls-tree failed");
2320 close $fd or return undef;
2322 if (!defined $line) {
2323 # there is no tree or hash given by $path at $base
2327 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2328 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2329 if (defined $type && $type ne $2) {
2330 # type doesn't match
2336 # get path of entry with given hash at given tree-ish (ref)
2337 # used to get 'from' filename for combined diff (merge commit) for renames
2338 sub git_get_path_by_hash
{
2339 my $base = shift || return;
2340 my $hash = shift || return;
2344 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2346 while (my $line = <$fd>) {
2349 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2350 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2351 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2360 ## ......................................................................
2361 ## git utility functions, directly accessing git repository
2363 sub git_get_project_description
{
2366 $git_dir = "$projectroot/$path";
2367 open my $fd, '<', "$git_dir/description"
2368 or return git_get_project_config
('description');
2371 if (defined $descr) {
2377 sub git_get_project_ctags
{
2381 $git_dir = "$projectroot/$path";
2382 opendir my $dh, "$git_dir/ctags"
2384 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2385 open my $ct, '<', $_ or next;
2389 my $ctag = $_; $ctag =~ s
#.*/##;
2390 $ctags->{$ctag} = $val;
2396 sub git_populate_project_tagcloud
{
2399 # First, merge different-cased tags; tags vote on casing
2401 foreach (keys %$ctags) {
2402 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2403 if (not $ctags_lc{lc $_}->{topcount
}
2404 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2405 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2406 $ctags_lc{lc $_}->{topname
} = $_;
2411 if (eval { require HTML
::TagCloud
; 1; }) {
2412 $cloud = HTML
::TagCloud
->new;
2413 foreach (sort keys %ctags_lc) {
2414 # Pad the title with spaces so that the cloud looks
2416 my $title = $ctags_lc{$_}->{topname
};
2417 $title =~ s/ / /g;
2418 $title =~ s/^/ /g;
2419 $title =~ s/$/ /g;
2420 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2423 $cloud = \
%ctags_lc;
2428 sub git_show_project_tagcloud
{
2429 my ($cloud, $count) = @_;
2430 print STDERR
ref($cloud)."..\n";
2431 if (ref $cloud eq 'HTML::TagCloud') {
2432 return $cloud->html_and_css($count);
2434 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2435 return '<p align="center">' . join (', ', map {
2436 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2437 } splice(@tags, 0, $count)) . '</p>';
2441 sub git_get_project_url_list
{
2444 $git_dir = "$projectroot/$path";
2445 open my $fd, '<', "$git_dir/cloneurl"
2446 or return wantarray ?
2447 @
{ config_to_multi
(git_get_project_config
('url')) } :
2448 config_to_multi
(git_get_project_config
('url'));
2449 my @git_project_url_list = map { chomp; $_ } <$fd>;
2452 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2455 sub git_get_projects_list
{
2460 $filter =~ s/\.git$//;
2462 my $check_forks = gitweb_check_feature
('forks');
2464 if (-d
$projects_list) {
2465 # search in directory
2466 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2467 # remove the trailing "/"
2469 my $pfxlen = length("$dir");
2470 my $pfxdepth = ($dir =~ tr!/!!);
2473 follow_fast
=> 1, # follow symbolic links
2474 follow_skip
=> 2, # ignore duplicates
2475 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2477 # skip project-list toplevel, if we get it.
2478 return if (m!^[/.]$!);
2479 # only directories can be git repositories
2480 return unless (-d
$_);
2481 # don't traverse too deep (Find is super slow on os x)
2482 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2483 $File::Find
::prune
= 1;
2487 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2488 # we check related file in $projectroot
2489 my $path = ($filter ?
"$filter/" : '') . $subdir;
2490 if (check_export_ok
("$projectroot/$path")) {
2491 push @list, { path
=> $path };
2492 $File::Find
::prune
= 1;
2497 } elsif (-f
$projects_list) {
2498 # read from file(url-encoded):
2499 # 'git%2Fgit.git Linus+Torvalds'
2500 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2501 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2503 open my $fd, '<', $projects_list or return;
2505 while (my $line = <$fd>) {
2507 my ($path, $owner) = split ' ', $line;
2508 $path = unescape
($path);
2509 $owner = unescape
($owner);
2510 if (!defined $path) {
2513 if ($filter ne '') {
2514 # looking for forks;
2515 my $pfx = substr($path, 0, length($filter));
2516 if ($pfx ne $filter) {
2519 my $sfx = substr($path, length($filter));
2520 if ($sfx !~ /^\/.*\
.git
$/) {
2523 } elsif ($check_forks) {
2525 foreach my $filter (keys %paths) {
2526 # looking for forks;
2527 my $pfx = substr($path, 0, length($filter));
2528 if ($pfx ne $filter) {
2531 my $sfx = substr($path, length($filter));
2532 if ($sfx !~ /^\/.*\
.git
$/) {
2535 # is a fork, don't include it in
2540 if (check_export_ok
("$projectroot/$path")) {
2543 owner
=> to_utf8
($owner),
2546 (my $forks_path = $path) =~ s/\.git$//;
2547 $paths{$forks_path}++;
2555 our $gitweb_project_owner = undef;
2556 sub git_get_project_list_from_file
{
2558 return if (defined $gitweb_project_owner);
2560 $gitweb_project_owner = {};
2561 # read from file (url-encoded):
2562 # 'git%2Fgit.git Linus+Torvalds'
2563 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2564 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2565 if (-f
$projects_list) {
2566 open(my $fd, '<', $projects_list);
2567 while (my $line = <$fd>) {
2569 my ($pr, $ow) = split ' ', $line;
2570 $pr = unescape
($pr);
2571 $ow = unescape
($ow);
2572 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2578 sub git_get_project_owner
{
2579 my $project = shift;
2582 return undef unless $project;
2583 $git_dir = "$projectroot/$project";
2585 if (!defined $gitweb_project_owner) {
2586 git_get_project_list_from_file
();
2589 if (exists $gitweb_project_owner->{$project}) {
2590 $owner = $gitweb_project_owner->{$project};
2592 if (!defined $owner){
2593 $owner = git_get_project_config
('owner');
2595 if (!defined $owner) {
2596 $owner = get_file_owner
("$git_dir");
2602 sub git_get_last_activity
{
2606 $git_dir = "$projectroot/$path";
2607 open($fd, "-|", git_cmd
(), 'for-each-ref',
2608 '--format=%(committer)',
2609 '--sort=-committerdate',
2611 'refs/heads') or return;
2612 my $most_recent = <$fd>;
2613 close $fd or return;
2614 if (defined $most_recent &&
2615 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2617 my $age = time - $timestamp;
2618 return ($age, age_string
($age));
2620 return (undef, undef);
2623 sub git_get_references
{
2624 my $type = shift || "";
2626 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2627 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2628 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2629 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2632 while (my $line = <$fd>) {
2634 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2635 if (defined $refs{$1}) {
2636 push @
{$refs{$1}}, $2;
2642 close $fd or return;
2646 sub git_get_rev_name_tags
{
2647 my $hash = shift || return undef;
2649 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2651 my $name_rev = <$fd>;
2654 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2657 # catches also '$hash undefined' output
2662 ## ----------------------------------------------------------------------
2663 ## parse to hash functions
2667 my $tz = shift || "-0000";
2670 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2671 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2672 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2673 $date{'hour'} = $hour;
2674 $date{'minute'} = $min;
2675 $date{'mday'} = $mday;
2676 $date{'day'} = $days[$wday];
2677 $date{'month'} = $months[$mon];
2678 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2679 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2680 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2681 $mday, $months[$mon], $hour ,$min;
2682 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2683 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2685 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2686 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2687 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2688 $date{'hour_local'} = $hour;
2689 $date{'minute_local'} = $min;
2690 $date{'tz_local'} = $tz;
2691 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2692 1900+$year, $mon+1, $mday,
2693 $hour, $min, $sec, $tz);
2702 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2703 $tag{'id'} = $tag_id;
2704 while (my $line = <$fd>) {
2706 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2707 $tag{'object'} = $1;
2708 } elsif ($line =~ m/^type (.+)$/) {
2710 } elsif ($line =~ m/^tag (.+)$/) {
2712 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2713 $tag{'author'} = $1;
2714 $tag{'author_epoch'} = $2;
2715 $tag{'author_tz'} = $3;
2716 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2717 $tag{'author_name'} = $1;
2718 $tag{'author_email'} = $2;
2720 $tag{'author_name'} = $tag{'author'};
2722 } elsif ($line =~ m/--BEGIN/) {
2723 push @comment, $line;
2725 } elsif ($line eq "") {
2729 push @comment, <$fd>;
2730 $tag{'comment'} = \
@comment;
2731 close $fd or return;
2732 if (!defined $tag{'name'}) {
2738 sub parse_commit_text
{
2739 my ($commit_text, $withparents) = @_;
2740 my @commit_lines = split '\n', $commit_text;
2743 pop @commit_lines; # Remove '\0'
2745 if (! @commit_lines) {
2749 my $header = shift @commit_lines;
2750 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2753 ($co{'id'}, my @parents) = split ' ', $header;
2754 while (my $line = shift @commit_lines) {
2755 last if $line eq "\n";
2756 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2758 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2760 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2761 $co{'author'} = to_utf8
($1);
2762 $co{'author_epoch'} = $2;
2763 $co{'author_tz'} = $3;
2764 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2765 $co{'author_name'} = $1;
2766 $co{'author_email'} = $2;
2768 $co{'author_name'} = $co{'author'};
2770 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2771 $co{'committer'} = to_utf8
($1);
2772 $co{'committer_epoch'} = $2;
2773 $co{'committer_tz'} = $3;
2774 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2775 $co{'committer_name'} = $1;
2776 $co{'committer_email'} = $2;
2778 $co{'committer_name'} = $co{'committer'};
2782 if (!defined $co{'tree'}) {
2785 $co{'parents'} = \
@parents;
2786 $co{'parent'} = $parents[0];
2788 foreach my $title (@commit_lines) {
2791 $co{'title'} = chop_str
($title, 80, 5);
2792 # remove leading stuff of merges to make the interesting part visible
2793 if (length($title) > 50) {
2794 $title =~ s/^Automatic //;
2795 $title =~ s/^merge (of|with) /Merge ... /i;
2796 if (length($title) > 50) {
2797 $title =~ s/(http|rsync):\/\///;
2799 if (length($title) > 50) {
2800 $title =~ s/(master|www|rsync)\.//;
2802 if (length($title) > 50) {
2803 $title =~ s/kernel.org:?//;
2805 if (length($title) > 50) {
2806 $title =~ s/\/pub\/scm//;
2809 $co{'title_short'} = chop_str
($title, 50, 5);
2813 if (! defined $co{'title'} || $co{'title'} eq "") {
2814 $co{'title'} = $co{'title_short'} = '(no commit message)';
2816 # remove added spaces
2817 foreach my $line (@commit_lines) {
2820 $co{'comment'} = \
@commit_lines;
2822 my $age = time - $co{'committer_epoch'};
2824 $co{'age_string'} = age_string
($age);
2825 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2826 if ($age > 60*60*24*7*2) {
2827 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2828 $co{'age_string_age'} = $co{'age_string'};
2830 $co{'age_string_date'} = $co{'age_string'};
2831 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2837 my ($commit_id) = @_;
2842 open my $fd, "-|", git_cmd
(), "rev-list",
2848 or die_error
(500, "Open git-rev-list failed");
2849 %co = parse_commit_text
(<$fd>, 1);
2856 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2864 open my $fd, "-|", git_cmd
(), "rev-list",
2867 ("--max-count=" . $maxcount),
2868 ("--skip=" . $skip),
2872 ($filename ?
($filename) : ())
2873 or die_error
(500, "Open git-rev-list failed");
2874 while (my $line = <$fd>) {
2875 my %co = parse_commit_text
($line);
2880 return wantarray ?
@cos : \
@cos;
2883 # parse line of git-diff-tree "raw" output
2884 sub parse_difftree_raw_line
{
2888 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2889 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2890 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2891 $res{'from_mode'} = $1;
2892 $res{'to_mode'} = $2;
2893 $res{'from_id'} = $3;
2895 $res{'status'} = $5;
2896 $res{'similarity'} = $6;
2897 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2898 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2900 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2903 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2904 # combined diff (for merge commit)
2905 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2906 $res{'nparents'} = length($1);
2907 $res{'from_mode'} = [ split(' ', $2) ];
2908 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2909 $res{'from_id'} = [ split(' ', $3) ];
2910 $res{'to_id'} = pop @
{$res{'from_id'}};
2911 $res{'status'} = [ split('', $4) ];
2912 $res{'to_file'} = unquote
($5);
2914 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2915 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2916 $res{'commit'} = $1;
2919 return wantarray ?
%res : \
%res;
2922 # wrapper: return parsed line of git-diff-tree "raw" output
2923 # (the argument might be raw line, or parsed info)
2924 sub parsed_difftree_line
{
2925 my $line_or_ref = shift;
2927 if (ref($line_or_ref) eq "HASH") {
2928 # pre-parsed (or generated by hand)
2929 return $line_or_ref;
2931 return parse_difftree_raw_line
($line_or_ref);
2935 # parse line of git-ls-tree output
2936 sub parse_ls_tree_line
{
2942 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2943 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2952 $res{'name'} = unquote
($5);
2955 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2956 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2964 $res{'name'} = unquote
($4);
2968 return wantarray ?
%res : \
%res;
2971 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2972 sub parse_from_to_diffinfo
{
2973 my ($diffinfo, $from, $to, @parents) = @_;
2975 if ($diffinfo->{'nparents'}) {
2977 $from->{'file'} = [];
2978 $from->{'href'} = [];
2979 fill_from_file_info
($diffinfo, @parents)
2980 unless exists $diffinfo->{'from_file'};
2981 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2982 $from->{'file'}[$i] =
2983 defined $diffinfo->{'from_file'}[$i] ?
2984 $diffinfo->{'from_file'}[$i] :
2985 $diffinfo->{'to_file'};
2986 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2987 $from->{'href'}[$i] = href
(action
=>"blob",
2988 hash_base
=>$parents[$i],
2989 hash
=>$diffinfo->{'from_id'}[$i],
2990 file_name
=>$from->{'file'}[$i]);
2992 $from->{'href'}[$i] = undef;
2996 # ordinary (not combined) diff
2997 $from->{'file'} = $diffinfo->{'from_file'};
2998 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2999 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3000 hash
=>$diffinfo->{'from_id'},
3001 file_name
=>$from->{'file'});
3003 delete $from->{'href'};
3007 $to->{'file'} = $diffinfo->{'to_file'};
3008 if (!is_deleted
($diffinfo)) { # file exists in result
3009 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3010 hash
=>$diffinfo->{'to_id'},
3011 file_name
=>$to->{'file'});
3013 delete $to->{'href'};
3017 ## ......................................................................
3018 ## parse to array of hashes functions
3020 sub git_get_heads_list
{
3024 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3025 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3026 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3029 while (my $line = <$fd>) {
3033 my ($refinfo, $committerinfo) = split(/\0/, $line);
3034 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3035 my ($committer, $epoch, $tz) =
3036 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3037 $ref_item{'fullname'} = $name;
3038 $name =~ s!^refs/heads/!!;
3040 $ref_item{'name'} = $name;
3041 $ref_item{'id'} = $hash;
3042 $ref_item{'title'} = $title || '(no commit message)';
3043 $ref_item{'epoch'} = $epoch;
3045 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3047 $ref_item{'age'} = "unknown";
3050 push @headslist, \
%ref_item;
3054 return wantarray ?
@headslist : \
@headslist;
3057 sub git_get_tags_list
{
3061 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3062 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3063 '--format=%(objectname) %(objecttype) %(refname) '.
3064 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3067 while (my $line = <$fd>) {
3071 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3072 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3073 my ($creator, $epoch, $tz) =
3074 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3075 $ref_item{'fullname'} = $name;
3076 $name =~ s!^refs/tags/!!;
3078 $ref_item{'type'} = $type;
3079 $ref_item{'id'} = $id;
3080 $ref_item{'name'} = $name;
3081 if ($type eq "tag") {
3082 $ref_item{'subject'} = $title;
3083 $ref_item{'reftype'} = $reftype;
3084 $ref_item{'refid'} = $refid;
3086 $ref_item{'reftype'} = $type;
3087 $ref_item{'refid'} = $id;
3090 if ($type eq "tag" || $type eq "commit") {
3091 $ref_item{'epoch'} = $epoch;
3093 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3095 $ref_item{'age'} = "unknown";
3099 push @tagslist, \
%ref_item;
3103 return wantarray ?
@tagslist : \
@tagslist;
3106 ## ----------------------------------------------------------------------
3107 ## filesystem-related functions
3109 sub get_file_owner
{
3112 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3113 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3114 if (!defined $gcos) {
3118 $owner =~ s/[,;].*$//;
3119 return to_utf8
($owner);
3122 # assume that file exists
3124 my $filename = shift;
3126 open my $fd, '<', $filename;
3127 print map { to_utf8
($_) } <$fd>;
3131 ## ......................................................................
3132 ## mimetype related functions
3134 sub mimetype_guess_file
{
3135 my $filename = shift;
3136 my $mimemap = shift;
3137 -r
$mimemap or return undef;
3140 open(my $mh, '<', $mimemap) or return undef;
3142 next if m/^#/; # skip comments
3143 my ($mimetype, $exts) = split(/\t+/);
3144 if (defined $exts) {
3145 my @exts = split(/\s+/, $exts);
3146 foreach my $ext (@exts) {
3147 $mimemap{$ext} = $mimetype;
3153 $filename =~ /\.([^.]*)$/;
3154 return $mimemap{$1};
3157 sub mimetype_guess
{
3158 my $filename = shift;
3160 $filename =~ /\./ or return undef;
3162 if ($mimetypes_file) {
3163 my $file = $mimetypes_file;
3164 if ($file !~ m!^/!) { # if it is relative path
3165 # it is relative to project
3166 $file = "$projectroot/$project/$file";
3168 $mime = mimetype_guess_file
($filename, $file);
3170 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3176 my $filename = shift;
3179 my $mime = mimetype_guess
($filename);
3180 $mime and return $mime;
3184 return $default_blob_plain_mimetype unless $fd;
3187 return 'text/plain';
3188 } elsif (! $filename) {
3189 return 'application/octet-stream';
3190 } elsif ($filename =~ m/\.png$/i) {
3192 } elsif ($filename =~ m/\.gif$/i) {
3194 } elsif ($filename =~ m/\.jpe?g$/i) {
3195 return 'image/jpeg';
3197 return 'application/octet-stream';
3201 sub blob_contenttype
{
3202 my ($fd, $file_name, $type) = @_;
3204 $type ||= blob_mimetype
($fd, $file_name);
3205 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3206 $type .= "; charset=$default_text_plain_charset";
3212 ## ======================================================================
3213 ## functions printing HTML: header, footer, error page
3215 sub git_header_html
{
3216 my $status = shift || "200 OK";
3217 my $expires = shift;
3219 my $title = "$site_name";
3220 if (defined $project) {
3221 $title .= " - " . to_utf8
($project);
3222 if (defined $action) {
3223 $title .= "/$action";
3224 if (defined $file_name) {
3225 $title .= " - " . esc_path
($file_name);
3226 if ($action eq "tree" && $file_name !~ m
|/$|) {
3233 # require explicit support from the UA if we are to send the page as
3234 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3235 # we have to do this because MSIE sometimes globs '*/*', pretending to
3236 # support xhtml+xml but choking when it gets what it asked for.
3237 # Disable content-type negotiation when caching (use mimetype good for all).
3238 if (!$caching_enabled &&
3239 defined $cgi->http('HTTP_ACCEPT') &&
3240 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3241 $cgi->Accept('application/xhtml+xml') != 0) {
3242 $content_type = 'application/xhtml+xml';
3244 $content_type = 'text/html';
3246 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3247 -status
=> $status, -expires
=> $expires);
3248 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3250 <?xml version="1.0" encoding="utf-8"?>
3251 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3252 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3253 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3254 <!-- git core binaries version $git_version -->
3256 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3257 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3258 <meta name="robots" content="index, nofollow"/>
3259 <title>$title</title>
3261 # the stylesheet, favicon etc urls won't work correctly with path_info
3262 # unless we set the appropriate base URL
3263 if ($ENV{'PATH_INFO'}) {
3264 print "<base href=\"".esc_url
($base_url)."\" />\n";
3266 # print out each stylesheet that exist, providing backwards capability
3267 # for those people who defined $stylesheet in a config file
3268 if (defined $stylesheet) {
3269 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3271 foreach my $stylesheet (@stylesheets) {
3272 next unless $stylesheet;
3273 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3276 if (defined $project) {
3277 my %href_params = get_feed_info
();
3278 if (!exists $href_params{'-title'}) {
3279 $href_params{'-title'} = 'log';
3282 foreach my $format qw(RSS Atom) {
3283 my $type = lc($format);
3285 '-rel' => 'alternate',
3286 '-title' => "$project - $href_params{'-title'} - $format feed",
3287 '-type' => "application/$type+xml"
3290 $href_params{'action'} = $type;
3291 $link_attr{'-href'} = href
(%href_params);
3293 "rel=\"$link_attr{'-rel'}\" ".
3294 "title=\"$link_attr{'-title'}\" ".
3295 "href=\"$link_attr{'-href'}\" ".
3296 "type=\"$link_attr{'-type'}\" ".
3299 $href_params{'extra_options'} = '--no-merges';
3300 $link_attr{'-href'} = href
(%href_params);
3301 $link_attr{'-title'} .= ' (no merges)';
3303 "rel=\"$link_attr{'-rel'}\" ".
3304 "title=\"$link_attr{'-title'}\" ".
3305 "href=\"$link_attr{'-href'}\" ".
3306 "type=\"$link_attr{'-type'}\" ".
3311 printf('<link rel="alternate" title="%s projects list" '.
3312 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3313 $site_name, href
(project
=>undef, action
=>"project_index"));
3314 printf('<link rel="alternate" title="%s projects feeds" '.
3315 'href="%s" type="text/x-opml" />'."\n",
3316 $site_name, href
(project
=>undef, action
=>"opml"));
3318 if (defined $favicon) {
3319 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3325 if (defined $site_header && -f
$site_header) {
3326 insert_file
($site_header);
3329 print "<div class=\"page_header\">\n" .
3330 $cgi->a({-href
=> esc_url
($logo_url),
3331 -title
=> $logo_label},
3332 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3333 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3334 if (defined $project) {
3335 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3336 if (defined $action) {
3343 my $have_search = gitweb_check_feature
('search');
3344 if (defined $project && $have_search) {
3345 if (!defined $searchtext) {
3349 if (defined $hash_base) {
3350 $search_hash = $hash_base;
3351 } elsif (defined $hash) {
3352 $search_hash = $hash;
3354 $search_hash = "HEAD";
3356 my $action = $my_uri;
3357 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3358 if ($use_pathinfo) {
3359 $action .= "/".esc_url
($project);
3361 print $cgi->startform(-method
=> "get", -action
=> $action) .
3362 "<div class=\"search\">\n" .
3364 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3365 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3366 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3367 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3368 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3369 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3371 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3372 "<span title=\"Extended regular expression\">" .
3373 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3374 -checked
=> $search_use_regexp) .
3377 $cgi->end_form() . "\n";
3381 sub git_footer_html
{
3382 my $feed_class = 'rss_logo';
3384 print "<div class=\"page_footer\">\n";
3385 if (defined $project) {
3386 my $descr = git_get_project_description
($project);
3387 if (defined $descr) {
3388 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3391 my %href_params = get_feed_info
();
3392 if (!%href_params) {
3393 $feed_class .= ' generic';
3395 $href_params{'-title'} ||= 'log';
3397 foreach my $format qw(RSS Atom) {
3398 $href_params{'action'} = lc($format);
3399 print $cgi->a({-href
=> href
(%href_params),
3400 -title
=> "$href_params{'-title'} $format feed",
3401 -class => $feed_class}, $format)."\n";
3405 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3406 -class => $feed_class}, "OPML") . " ";
3407 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3408 -class => $feed_class}, "TXT") . "\n";
3410 print "</div>\n"; # class="page_footer"
3412 # timing info doesn't make much sense with output (response) caching,
3413 # so when caching is enabled gitweb prints the time of page generation
3414 if ((defined $t0 || $caching_enabled) &&
3415 gitweb_check_feature
('timed')) {
3416 print "<div id=\"generating_info\">\n";
3417 if ($caching_enabled) {
3418 print 'This page was generated at '.
3419 gmtime( time() )." GMT\n";
3421 print 'This page took '.
3422 '<span id="generating_time" class="time_span">'.
3423 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3426 '<span id="generating_cmd">'.
3427 $number_of_git_cmds.
3428 '</span> git commands '.
3431 print "</div>\n"; # class="page_footer"
3434 if (defined $site_footer && -f
$site_footer) {
3435 insert_file
($site_footer);
3438 print qq!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3439 if (defined $action &&
3440 $action eq 'blame_incremental') {
3441 print qq!<script type
="text/javascript">\n!.
3442 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3443 qq! "!. href() .qq!");\n!.
3445 } elsif (gitweb_check_feature
('javascript-actions')) {
3446 print qq!<script type
="text/javascript">\n!.
3447 qq!window
.onload
= fixLinks
;\n!.
3455 # die_error(<http_status_code>, <error_message>)
3456 # Example: die_error(404, 'Hash not found')
3457 # By convention, use the following status codes (as defined in RFC 2616):
3458 # 400: Invalid or missing CGI parameters, or
3459 # requested object exists but has wrong type.
3460 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3461 # this server or project.
3462 # 404: Requested object/revision/project doesn't exist.
3463 # 500: The server isn't configured properly, or
3464 # an internal error occurred (e.g. failed assertions caused by bugs), or
3465 # an unknown error occurred (e.g. the git binary died unexpectedly).
3466 # 503: The server is currently unavailable (because it is overloaded,
3467 # or down for maintenance). Generally, this is a temporary state.
3469 my $status = shift || 500;
3470 my $error = shift || "Internal server error";
3473 my %http_responses = (
3474 400 => '400 Bad Request',
3475 403 => '403 Forbidden',
3476 404 => '404 Not Found',
3477 500 => '500 Internal Server Error',
3478 503 => '503 Service Unavailable',
3481 # Do not cache error pages (die_error() uses 'exit')
3482 cache_stop
() if ($caching_enabled);
3484 git_header_html
($http_responses{$status});
3486 <div class="page_body">
3491 if (defined $extra) {
3501 ## ----------------------------------------------------------------------
3502 ## functions printing or outputting HTML: navigation
3504 sub git_print_page_nav
{
3505 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3506 $extra = '' if !defined $extra; # pager or formats
3508 my @navs = qw(summary shortlog log commit commitdiff tree);
3510 @navs = grep { $_ ne $suppress } @navs;
3513 my %arg = map { $_ => {action
=>$_} } @navs;
3514 if (defined $head) {
3515 for (qw(commit commitdiff)) {
3516 $arg{$_}{'hash'} = $head;
3518 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3519 for (qw(shortlog log)) {
3520 $arg{$_}{'hash'} = $head;
3525 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3526 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3528 my @actions = gitweb_get_feature
('actions');
3531 'n' => $project, # project name
3532 'f' => $git_dir, # project path within filesystem
3533 'h' => $treehead || '', # current hash ('h' parameter)
3534 'b' => $treebase || '', # hash base ('hb' parameter)
3537 my ($label, $link, $pos) = splice(@actions,0,3);
3539 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3541 $link =~ s/%([%nfhb])/$repl{$1}/g;
3542 $arg{$label}{'_href'} = $link;
3545 print "<div class=\"page_nav\">\n" .
3547 map { $_ eq $current ?
3548 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3550 print "<br/>\n$extra<br/>\n" .
3554 sub format_paging_nav
{
3555 my ($action, $page, $has_next_link) = @_;
3561 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3563 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3564 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3566 $paging_nav .= "first ⋅ prev";
3569 if ($has_next_link) {
3570 $paging_nav .= " ⋅ " .
3571 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3572 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3574 $paging_nav .= " ⋅ next";
3580 ## ......................................................................
3581 ## functions printing or outputting HTML: div
3583 sub git_print_header_div
{
3584 my ($action, $title, $hash, $hash_base) = @_;
3587 $args{'action'} = $action;
3588 $args{'hash'} = $hash if $hash;
3589 $args{'hash_base'} = $hash_base if $hash_base;
3591 print "<div class=\"header\">\n" .
3592 $cgi->a({-href
=> href
(%args), -class => "title"},
3593 $title ?
$title : $action) .
3597 sub print_local_time
{
3598 print format_local_time
(@_);
3601 sub format_local_time
{
3604 if ($date{'hour_local'} < 6) {
3605 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3606 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3608 $localtime .= sprintf(" (%02d:%02d %s)",
3609 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3615 # Outputs the author name and date in long form
3616 sub git_print_authorship
{
3619 my $tag = $opts{-tag
} || 'div';
3620 my $author = $co->{'author_name'};
3622 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3623 print "<$tag class=\"author_date\">" .
3624 format_search_author
($author, "author", esc_html
($author)) .
3626 print_local_time
(%ad) if ($opts{-localtime});
3627 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3631 # Outputs table rows containing the full author or committer information,
3632 # in the format expected for 'commit' view (& similia).
3633 # Parameters are a commit hash reference, followed by the list of people
3634 # to output information for. If the list is empty it defalts to both
3635 # author and committer.
3636 sub git_print_authorship_rows
{
3638 # too bad we can't use @people = @_ || ('author', 'committer')
3640 @people = ('author', 'committer') unless @people;
3641 foreach my $who (@people) {
3642 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3643 print "<tr><td>$who</td><td>" .
3644 format_search_author
($co->{"${who}_name"}, $who,
3645 esc_html
($co->{"${who}_name"})) . " " .
3646 format_search_author
($co->{"${who}_email"}, $who,
3647 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3648 "</td><td rowspan=\"2\">" .
3649 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3652 "<td></td><td> $wd{'rfc2822'}";
3653 print_local_time
(%wd);
3659 sub git_print_page_path
{
3665 print "<div class=\"page_path\">";
3666 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3667 -title
=> 'tree root'}, to_utf8
("[$project]"));
3669 if (defined $name) {
3670 my @dirname = split '/', $name;
3671 my $basename = pop @dirname;
3674 foreach my $dir (@dirname) {
3675 $fullname .= ($fullname ?
'/' : '') . $dir;
3676 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3678 -title
=> $fullname}, esc_path
($dir));
3681 if (defined $type && $type eq 'blob') {
3682 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3684 -title
=> $name}, esc_path
($basename));
3685 } elsif (defined $type && $type eq 'tree') {
3686 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3688 -title
=> $name}, esc_path
($basename));
3691 print esc_path
($basename);
3694 print "<br/></div>\n";
3701 if ($opts{'-remove_title'}) {
3702 # remove title, i.e. first line of log
3705 # remove leading empty lines
3706 while (defined $log->[0] && $log->[0] eq "") {
3713 foreach my $line (@
$log) {
3714 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3717 if (! $opts{'-remove_signoff'}) {
3718 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3721 # remove signoff lines
3728 # print only one empty line
3729 # do not print empty line after signoff
3731 next if ($empty || $signoff);
3737 print format_log_line_html
($line) . "<br/>\n";
3740 if ($opts{'-final_empty_line'}) {
3741 # end with single empty line
3742 print "<br/>\n" unless $empty;
3746 # return link target (what link points to)
3747 sub git_get_link_target
{
3752 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3756 $link_target = <$fd>;
3761 return $link_target;
3764 # given link target, and the directory (basedir) the link is in,
3765 # return target of link relative to top directory (top tree);
3766 # return undef if it is not possible (including absolute links).
3767 sub normalize_link_target
{
3768 my ($link_target, $basedir) = @_;
3770 # absolute symlinks (beginning with '/') cannot be normalized
3771 return if (substr($link_target, 0, 1) eq '/');
3773 # normalize link target to path from top (root) tree (dir)
3776 $path = $basedir . '/' . $link_target;
3778 # we are in top (root) tree (dir)
3779 $path = $link_target;
3782 # remove //, /./, and /../
3784 foreach my $part (split('/', $path)) {
3785 # discard '.' and ''
3786 next if (!$part || $part eq '.');
3788 if ($part eq '..') {
3792 # link leads outside repository (outside top dir)
3796 push @path_parts, $part;
3799 $path = join('/', @path_parts);
3804 # print tree entry (row of git_tree), but without encompassing <tr> element
3805 sub git_print_tree_entry
{
3806 my ($t, $basedir, $hash_base, $have_blame) = @_;
3809 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3811 # The format of a table row is: mode list link. Where mode is
3812 # the mode of the entry, list is the name of the entry, an href,
3813 # and link is the action links of the entry.
3815 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3816 if (exists $t->{'size'}) {
3817 print "<td class=\"size\">$t->{'size'}</td>\n";
3819 if ($t->{'type'} eq "blob") {
3820 print "<td class=\"list\">" .
3821 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3822 file_name
=>"$basedir$t->{'name'}", %base_key),
3823 -class => "list"}, esc_path
($t->{'name'}));
3824 if (S_ISLNK
(oct $t->{'mode'})) {
3825 my $link_target = git_get_link_target
($t->{'hash'});
3827 my $norm_target = normalize_link_target
($link_target, $basedir);
3828 if (defined $norm_target) {
3830 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3831 file_name
=>$norm_target),
3832 -title
=> $norm_target}, esc_path
($link_target));
3834 print " -> " . esc_path
($link_target);
3839 print "<td class=\"link\">";
3840 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3841 file_name
=>"$basedir$t->{'name'}", %base_key)},
3845 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3846 file_name
=>"$basedir$t->{'name'}", %base_key)},
3849 if (defined $hash_base) {
3851 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3852 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3856 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3857 file_name
=>"$basedir$t->{'name'}")},
3861 } elsif ($t->{'type'} eq "tree") {
3862 print "<td class=\"list\">";
3863 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3864 file_name
=>"$basedir$t->{'name'}",
3866 esc_path
($t->{'name'}));
3868 print "<td class=\"link\">";
3869 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3870 file_name
=>"$basedir$t->{'name'}",
3873 if (defined $hash_base) {
3875 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3876 file_name
=>"$basedir$t->{'name'}")},
3881 # unknown object: we can only present history for it
3882 # (this includes 'commit' object, i.e. submodule support)
3883 print "<td class=\"list\">" .
3884 esc_path
($t->{'name'}) .
3886 print "<td class=\"link\">";
3887 if (defined $hash_base) {
3888 print $cgi->a({-href
=> href
(action
=>"history",
3889 hash_base
=>$hash_base,
3890 file_name
=>"$basedir$t->{'name'}")},
3897 ## ......................................................................
3898 ## functions printing large fragments of HTML
3900 # get pre-image filenames for merge (combined) diff
3901 sub fill_from_file_info
{
3902 my ($diff, @parents) = @_;
3904 $diff->{'from_file'} = [ ];
3905 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3906 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3907 if ($diff->{'status'}[$i] eq 'R' ||
3908 $diff->{'status'}[$i] eq 'C') {
3909 $diff->{'from_file'}[$i] =
3910 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3917 # is current raw difftree line of file deletion
3919 my $diffinfo = shift;
3921 return $diffinfo->{'to_id'} eq ('0' x
40);
3924 # does patch correspond to [previous] difftree raw line
3925 # $diffinfo - hashref of parsed raw diff format
3926 # $patchinfo - hashref of parsed patch diff format
3927 # (the same keys as in $diffinfo)
3928 sub is_patch_split
{
3929 my ($diffinfo, $patchinfo) = @_;
3931 return defined $diffinfo && defined $patchinfo
3932 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3936 sub git_difftree_body
{
3937 my ($difftree, $hash, @parents) = @_;
3938 my ($parent) = $parents[0];
3939 my $have_blame = gitweb_check_feature
('blame');
3940 print "<div class=\"list_head\">\n";
3941 if ($#{$difftree} > 10) {
3942 print(($#{$difftree} + 1) . " files changed:\n");
3946 print "<table class=\"" .
3947 (@parents > 1 ?
"combined " : "") .
3950 # header only for combined diff in 'commitdiff' view
3951 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3954 print "<thead><tr>\n" .
3955 "<th></th><th></th>\n"; # filename, patchN link
3956 for (my $i = 0; $i < @parents; $i++) {
3957 my $par = $parents[$i];
3959 $cgi->a({-href
=> href
(action
=>"commitdiff",
3960 hash
=>$hash, hash_parent
=>$par),
3961 -title
=> 'commitdiff to parent number ' .
3962 ($i+1) . ': ' . substr($par,0,7)},
3966 print "</tr></thead>\n<tbody>\n";
3971 foreach my $line (@
{$difftree}) {
3972 my $diff = parsed_difftree_line
($line);
3975 print "<tr class=\"dark\">\n";
3977 print "<tr class=\"light\">\n";
3981 if (exists $diff->{'nparents'}) { # combined diff
3983 fill_from_file_info
($diff, @parents)
3984 unless exists $diff->{'from_file'};
3986 if (!is_deleted
($diff)) {
3987 # file exists in the result (child) commit
3989 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3990 file_name
=>$diff->{'to_file'},
3992 -class => "list"}, esc_path
($diff->{'to_file'})) .
3996 esc_path
($diff->{'to_file'}) .
4000 if ($action eq 'commitdiff') {
4003 print "<td class=\"link\">" .
4004 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4009 my $has_history = 0;
4010 my $not_deleted = 0;
4011 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4012 my $hash_parent = $parents[$i];
4013 my $from_hash = $diff->{'from_id'}[$i];
4014 my $from_path = $diff->{'from_file'}[$i];
4015 my $status = $diff->{'status'}[$i];
4017 $has_history ||= ($status ne 'A');
4018 $not_deleted ||= ($status ne 'D');
4020 if ($status eq 'A') {
4021 print "<td class=\"link\" align=\"right\"> | </td>\n";
4022 } elsif ($status eq 'D') {
4023 print "<td class=\"link\">" .
4024 $cgi->a({-href
=> href
(action
=>"blob",
4027 file_name
=>$from_path)},
4031 if ($diff->{'to_id'} eq $from_hash) {
4032 print "<td class=\"link nochange\">";
4034 print "<td class=\"link\">";
4036 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4037 hash
=>$diff->{'to_id'},
4038 hash_parent
=>$from_hash,
4040 hash_parent_base
=>$hash_parent,
4041 file_name
=>$diff->{'to_file'},
4042 file_parent
=>$from_path)},
4048 print "<td class=\"link\">";
4050 print $cgi->a({-href
=> href
(action
=>"blob",
4051 hash
=>$diff->{'to_id'},
4052 file_name
=>$diff->{'to_file'},
4055 print " | " if ($has_history);
4058 print $cgi->a({-href
=> href
(action
=>"history",
4059 file_name
=>$diff->{'to_file'},
4066 next; # instead of 'else' clause, to avoid extra indent
4068 # else ordinary diff
4070 my ($to_mode_oct, $to_mode_str, $to_file_type);
4071 my ($from_mode_oct, $from_mode_str, $from_file_type);
4072 if ($diff->{'to_mode'} ne ('0' x
6)) {
4073 $to_mode_oct = oct $diff->{'to_mode'};
4074 if (S_ISREG
($to_mode_oct)) { # only for regular file
4075 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4077 $to_file_type = file_type
($diff->{'to_mode'});
4079 if ($diff->{'from_mode'} ne ('0' x
6)) {
4080 $from_mode_oct = oct $diff->{'from_mode'};
4081 if (S_ISREG
($to_mode_oct)) { # only for regular file
4082 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4084 $from_file_type = file_type
($diff->{'from_mode'});
4087 if ($diff->{'status'} eq "A") { # created
4088 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4089 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4090 $mode_chng .= "]</span>";
4092 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4093 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4094 -class => "list"}, esc_path
($diff->{'file'}));
4096 print "<td>$mode_chng</td>\n";
4097 print "<td class=\"link\">";
4098 if ($action eq 'commitdiff') {
4101 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4104 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4105 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4109 } elsif ($diff->{'status'} eq "D") { # deleted
4110 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4112 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4113 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4114 -class => "list"}, esc_path
($diff->{'file'}));
4116 print "<td>$mode_chng</td>\n";
4117 print "<td class=\"link\">";
4118 if ($action eq 'commitdiff') {
4121 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4124 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4125 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4128 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4129 file_name
=>$diff->{'file'})},
4132 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4133 file_name
=>$diff->{'file'})},
4137 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4138 my $mode_chnge = "";
4139 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4140 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4141 if ($from_file_type ne $to_file_type) {
4142 $mode_chnge .= " from $from_file_type to $to_file_type";
4144 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4145 if ($from_mode_str && $to_mode_str) {
4146 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4147 } elsif ($to_mode_str) {
4148 $mode_chnge .= " mode: $to_mode_str";
4151 $mode_chnge .= "]</span>\n";
4154 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4155 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4156 -class => "list"}, esc_path
($diff->{'file'}));
4158 print "<td>$mode_chnge</td>\n";
4159 print "<td class=\"link\">";
4160 if ($action eq 'commitdiff') {
4163 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4165 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4166 # "commit" view and modified file (not onlu mode changed)
4167 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4168 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4169 hash_base
=>$hash, hash_parent_base
=>$parent,
4170 file_name
=>$diff->{'file'})},
4174 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4175 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4178 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4179 file_name
=>$diff->{'file'})},
4182 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4183 file_name
=>$diff->{'file'})},
4187 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4188 my %status_name = ('R' => 'moved', 'C' => 'copied');
4189 my $nstatus = $status_name{$diff->{'status'}};
4191 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4192 # mode also for directories, so we cannot use $to_mode_str
4193 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4196 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4197 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4198 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4199 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4200 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4201 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4202 -class => "list"}, esc_path
($diff->{'from_file'})) .
4203 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4204 "<td class=\"link\">";
4205 if ($action eq 'commitdiff') {
4208 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4210 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4211 # "commit" view and modified file (not only pure rename or copy)
4212 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4213 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4214 hash_base
=>$hash, hash_parent_base
=>$parent,
4215 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4219 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4220 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4223 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4224 file_name
=>$diff->{'to_file'})},
4227 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4228 file_name
=>$diff->{'to_file'})},
4232 } # we should not encounter Unmerged (U) or Unknown (X) status
4235 print "</tbody>" if $has_header;
4239 sub git_patchset_body
{
4240 my ($fd, $difftree, $hash, @hash_parents) = @_;
4241 my ($hash_parent) = $hash_parents[0];
4243 my $is_combined = (@hash_parents > 1);
4245 my $patch_number = 0;
4251 print "<div class=\"patchset\">\n";
4253 # skip to first patch
4254 while ($patch_line = <$fd>) {
4257 last if ($patch_line =~ m/^diff /);
4261 while ($patch_line) {
4263 # parse "git diff" header line
4264 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4265 # $1 is from_name, which we do not use
4266 $to_name = unquote
($2);
4267 $to_name =~ s!^b/!!;
4268 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4269 # $1 is 'cc' or 'combined', which we do not use
4270 $to_name = unquote
($2);
4275 # check if current patch belong to current raw line
4276 # and parse raw git-diff line if needed
4277 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4278 # this is continuation of a split patch
4279 print "<div class=\"patch cont\">\n";
4281 # advance raw git-diff output if needed
4282 $patch_idx++ if defined $diffinfo;
4284 # read and prepare patch information
4285 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4287 # compact combined diff output can have some patches skipped
4288 # find which patch (using pathname of result) we are at now;
4290 while ($to_name ne $diffinfo->{'to_file'}) {
4291 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4292 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4293 "</div>\n"; # class="patch"
4298 last if $patch_idx > $#$difftree;
4299 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4303 # modifies %from, %to hashes
4304 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4306 # this is first patch for raw difftree line with $patch_idx index
4307 # we index @$difftree array from 0, but number patches from 1
4308 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4312 #assert($patch_line =~ m/^diff /) if DEBUG;
4313 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4315 # print "git diff" header
4316 print format_git_diff_header_line
($patch_line, $diffinfo,
4319 # print extended diff header
4320 print "<div class=\"diff extended_header\">\n";
4322 while ($patch_line = <$fd>) {
4325 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4327 print format_extended_diff_header_line
($patch_line, $diffinfo,
4330 print "</div>\n"; # class="diff extended_header"
4332 # from-file/to-file diff header
4333 if (! $patch_line) {
4334 print "</div>\n"; # class="patch"
4337 next PATCH
if ($patch_line =~ m/^diff /);
4338 #assert($patch_line =~ m/^---/) if DEBUG;
4340 my $last_patch_line = $patch_line;
4341 $patch_line = <$fd>;
4343 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4345 print format_diff_from_to_header
($last_patch_line, $patch_line,
4346 $diffinfo, \
%from, \
%to,
4351 while ($patch_line = <$fd>) {
4354 next PATCH
if ($patch_line =~ m/^diff /);
4356 print format_diff_line
($patch_line, \
%from, \
%to);
4360 print "</div>\n"; # class="patch"
4363 # for compact combined (--cc) format, with chunk and patch simpliciaction
4364 # patchset might be empty, but there might be unprocessed raw lines
4365 for (++$patch_idx if $patch_number > 0;
4366 $patch_idx < @
$difftree;
4368 # read and prepare patch information
4369 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4371 # generate anchor for "patch" links in difftree / whatchanged part
4372 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4373 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4374 "</div>\n"; # class="patch"
4379 if ($patch_number == 0) {
4380 if (@hash_parents > 1) {
4381 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4383 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4387 print "</div>\n"; # class="patchset"
4390 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4392 # fills project list info (age, description, owner, forks) for each
4393 # project in the list, removing invalid projects from returned list
4394 # NOTE: modifies $projlist, but does not remove entries from it
4395 sub fill_project_list_info
{
4396 my ($projlist, $check_forks) = @_;
4399 my $show_ctags = gitweb_check_feature
('ctags');
4401 foreach my $pr (@
$projlist) {
4402 my (@activity) = git_get_last_activity
($pr->{'path'});
4403 unless (@activity) {
4406 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4407 if (!defined $pr->{'descr'}) {
4408 my $descr = git_get_project_description
($pr->{'path'}) || "";
4409 $descr = to_utf8
($descr);
4410 $pr->{'descr_long'} = $descr;
4411 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4413 if (!defined $pr->{'owner'}) {
4414 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4417 my $pname = $pr->{'path'};
4418 if (($pname =~ s/\.git$//) &&
4419 ($pname !~ /\/$/) &&
4420 (-d
"$projectroot/$pname")) {
4421 $pr->{'forks'} = "-d $projectroot/$pname";
4426 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4427 push @projects, $pr;
4433 # print 'sort by' <th> element, generating 'sort by $name' replay link
4434 # if that order is not selected
4436 print format_sort_th
(@_);
4439 sub format_sort_th
{
4440 my ($name, $order, $header) = @_;
4442 $header ||= ucfirst($name);
4444 if ($order eq $name) {
4445 $sort_th .= "<th>$header</th>\n";
4447 $sort_th .= "<th>" .
4448 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4449 -class => "header"}, $header) .
4456 sub git_project_list_body
{
4457 # actually uses global variable $project
4458 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4460 my $check_forks = gitweb_check_feature
('forks');
4461 my @projects = fill_project_list_info
($projlist, $check_forks);
4463 $order ||= $default_projects_order;
4464 $from = 0 unless defined $from;
4465 $to = $#projects if (!defined $to || $#projects < $to);
4468 project
=> { key
=> 'path', type
=> 'str' },
4469 descr
=> { key
=> 'descr_long', type
=> 'str' },
4470 owner
=> { key
=> 'owner', type
=> 'str' },
4471 age
=> { key
=> 'age', type
=> 'num' }
4473 my $oi = $order_info{$order};
4474 if ($oi->{'type'} eq 'str') {
4475 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4477 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4480 my $show_ctags = gitweb_check_feature
('ctags');
4483 foreach my $p (@projects) {
4484 foreach my $ct (keys %{$p->{'ctags'}}) {
4485 $ctags{$ct} += $p->{'ctags'}->{$ct};
4488 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4489 print git_show_project_tagcloud
($cloud, 64);
4492 print "<table class=\"project_list\">\n";
4493 unless ($no_header) {
4496 print "<th></th>\n";
4498 print_sort_th
('project', $order, 'Project');
4499 print_sort_th
('descr', $order, 'Description');
4500 print_sort_th
('owner', $order, 'Owner');
4501 print_sort_th
('age', $order, 'Last Change');
4502 print "<th></th>\n" . # for links
4506 my $tagfilter = $cgi->param('by_tag');
4507 for (my $i = $from; $i <= $to; $i++) {
4508 my $pr = $projects[$i];
4510 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4511 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4512 and not $pr->{'descr_long'} =~ /$searchtext/;
4513 # Weed out forks or non-matching entries of search
4515 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4516 $forkbase="^$forkbase" if $forkbase;
4517 next if not $searchtext and not $tagfilter and $show_ctags
4518 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4522 print "<tr class=\"dark\">\n";
4524 print "<tr class=\"light\">\n";
4529 if ($pr->{'forks'}) {
4530 print "<!-- $pr->{'forks'} -->\n";
4531 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4535 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4536 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4537 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4538 -class => "list", -title
=> $pr->{'descr_long'}},
4539 esc_html
($pr->{'descr'})) . "</td>\n" .
4540 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4541 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4542 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4543 "<td class=\"link\">" .
4544 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4545 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4546 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4547 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4548 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4552 if (defined $extra) {
4555 print "<td></td>\n";
4557 print "<td colspan=\"5\">$extra</td>\n" .
4564 # uses global variable $project
4565 my ($commitlist, $from, $to, $refs, $extra) = @_;
4567 $from = 0 unless defined $from;
4568 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4570 for (my $i = 0; $i <= $to; $i++) {
4571 my %co = %{$commitlist->[$i]};
4573 my $commit = $co{'id'};
4574 my $ref = format_ref_marker
($refs, $commit);
4575 my %ad = parse_date
($co{'author_epoch'});
4576 git_print_header_div
('commit',
4577 "<span class=\"age\">$co{'age_string'}</span>" .
4578 esc_html
($co{'title'}) . $ref,
4580 print "<div class=\"title_text\">\n" .
4581 "<div class=\"log_link\">\n" .
4582 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4584 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4586 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4589 git_print_authorship
(\
%co, -tag
=> 'span');
4590 print "<br/>\n</div>\n";
4592 print "<div class=\"log_body\">\n";
4593 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4597 print "<div class=\"page_nav\">\n";
4603 sub git_shortlog_body
{
4604 # uses global variable $project
4605 my ($commitlist, $from, $to, $refs, $extra) = @_;
4607 $from = 0 unless defined $from;
4608 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4610 print "<table class=\"shortlog\">\n";
4612 for (my $i = $from; $i <= $to; $i++) {
4613 my %co = %{$commitlist->[$i]};
4614 my $commit = $co{'id'};
4615 my $ref = format_ref_marker
($refs, $commit);
4617 print "<tr class=\"dark\">\n";
4619 print "<tr class=\"light\">\n";
4622 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4623 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4624 format_author_html
('td', \
%co, 10) . "<td>";
4625 print format_subject_html
($co{'title'}, $co{'title_short'},
4626 href
(action
=>"commit", hash
=>$commit), $ref);
4628 "<td class=\"link\">" .
4629 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4630 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4631 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4632 my $snapshot_links = format_snapshot_links
($commit);
4633 if (defined $snapshot_links) {
4634 print " | " . $snapshot_links;
4639 if (defined $extra) {
4641 "<td colspan=\"4\">$extra</td>\n" .
4647 sub git_history_body
{
4648 # Warning: assumes constant type (blob or tree) during history
4649 my ($commitlist, $from, $to, $refs, $extra,
4650 $file_name, $file_hash, $ftype) = @_;
4652 $from = 0 unless defined $from;
4653 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4655 print "<table class=\"history\">\n";
4657 for (my $i = $from; $i <= $to; $i++) {
4658 my %co = %{$commitlist->[$i]};
4662 my $commit = $co{'id'};
4664 my $ref = format_ref_marker
($refs, $commit);
4667 print "<tr class=\"dark\">\n";
4669 print "<tr class=\"light\">\n";
4672 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4673 # shortlog: format_author_html('td', \%co, 10)
4674 format_author_html
('td', \
%co, 15, 3) . "<td>";
4675 # originally git_history used chop_str($co{'title'}, 50)
4676 print format_subject_html
($co{'title'}, $co{'title_short'},
4677 href
(action
=>"commit", hash
=>$commit), $ref);
4679 "<td class=\"link\">" .
4680 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4681 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4683 if ($ftype eq 'blob') {
4684 my $blob_current = $file_hash;
4685 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4686 if (defined $blob_current && defined $blob_parent &&
4687 $blob_current ne $blob_parent) {
4689 $cgi->a({-href
=> href
(action
=>"blobdiff",
4690 hash
=>$blob_current, hash_parent
=>$blob_parent,
4691 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4692 file_name
=>$file_name)},
4699 if (defined $extra) {
4701 "<td colspan=\"4\">$extra</td>\n" .
4708 # uses global variable $project
4709 my ($taglist, $from, $to, $extra) = @_;
4710 $from = 0 unless defined $from;
4711 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4713 print "<table class=\"tags\">\n";
4715 for (my $i = $from; $i <= $to; $i++) {
4716 my $entry = $taglist->[$i];
4718 my $comment = $tag{'subject'};
4720 if (defined $comment) {
4721 $comment_short = chop_str
($comment, 30, 5);
4724 print "<tr class=\"dark\">\n";
4726 print "<tr class=\"light\">\n";
4729 if (defined $tag{'age'}) {
4730 print "<td><i>$tag{'age'}</i></td>\n";
4732 print "<td></td>\n";
4735 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4736 -class => "list name"}, esc_html
($tag{'name'})) .
4739 if (defined $comment) {
4740 print format_subject_html
($comment, $comment_short,
4741 href
(action
=>"tag", hash
=>$tag{'id'}));
4744 "<td class=\"selflink\">";
4745 if ($tag{'type'} eq "tag") {
4746 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4751 "<td class=\"link\">" . " | " .
4752 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4753 if ($tag{'reftype'} eq "commit") {
4754 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4755 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4756 } elsif ($tag{'reftype'} eq "blob") {
4757 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4762 if (defined $extra) {
4764 "<td colspan=\"5\">$extra</td>\n" .
4770 sub git_heads_body
{
4771 # uses global variable $project
4772 my ($headlist, $head, $from, $to, $extra) = @_;
4773 $from = 0 unless defined $from;
4774 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4776 print "<table class=\"heads\">\n";
4778 for (my $i = $from; $i <= $to; $i++) {
4779 my $entry = $headlist->[$i];
4781 my $curr = $ref{'id'} eq $head;
4783 print "<tr class=\"dark\">\n";
4785 print "<tr class=\"light\">\n";
4788 print "<td><i>$ref{'age'}</i></td>\n" .
4789 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4790 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4791 -class => "list name"},esc_html
($ref{'name'})) .
4793 "<td class=\"link\">" .
4794 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4795 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4796 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4800 if (defined $extra) {
4802 "<td colspan=\"3\">$extra</td>\n" .
4808 sub git_search_grep_body
{
4809 my ($commitlist, $from, $to, $extra) = @_;
4810 $from = 0 unless defined $from;
4811 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4813 print "<table class=\"commit_search\">\n";
4815 for (my $i = $from; $i <= $to; $i++) {
4816 my %co = %{$commitlist->[$i]};
4820 my $commit = $co{'id'};
4822 print "<tr class=\"dark\">\n";
4824 print "<tr class=\"light\">\n";
4827 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4828 format_author_html
('td', \
%co, 15, 5) .
4830 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4831 -class => "list subject"},
4832 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4833 my $comment = $co{'comment'};
4834 foreach my $line (@
$comment) {
4835 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4836 my ($lead, $match, $trail) = ($1, $2, $3);
4837 $match = chop_str
($match, 70, 5, 'center');
4838 my $contextlen = int((80 - length($match))/2);
4839 $contextlen = 30 if ($contextlen > 30);
4840 $lead = chop_str
($lead, $contextlen, 10, 'left');
4841 $trail = chop_str
($trail, $contextlen, 10, 'right');
4843 $lead = esc_html
($lead);
4844 $match = esc_html
($match);
4845 $trail = esc_html
($trail);
4847 print "$lead<span class=\"match\">$match</span>$trail<br />";
4851 "<td class=\"link\">" .
4852 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4854 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4856 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4860 if (defined $extra) {
4862 "<td colspan=\"3\">$extra</td>\n" .
4868 ## ======================================================================
4869 ## ======================================================================
4872 sub git_project_list
{
4873 my $order = $input_params{'order'};
4874 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4875 die_error
(400, "Unknown order parameter");
4878 my @list = git_get_projects_list
();
4880 die_error
(404, "No projects found");
4884 if (defined $home_text && -f
$home_text) {
4885 print "<div class=\"index_include\">\n";
4886 insert_file
($home_text);
4889 print $cgi->startform(-method
=> "get") .
4890 "<p class=\"projsearch\">Search:\n" .
4891 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4893 $cgi->end_form() . "\n";
4894 git_project_list_body
(\
@list, $order);
4899 my $order = $input_params{'order'};
4900 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4901 die_error
(400, "Unknown order parameter");
4904 my @list = git_get_projects_list
($project);
4906 die_error
(404, "No forks found");
4910 git_print_page_nav
('','');
4911 git_print_header_div
('summary', "$project forks");
4912 git_project_list_body
(\
@list, $order);
4916 sub git_project_index
{
4917 my @projects = git_get_projects_list
($project);
4920 -type
=> 'text/plain',
4921 -charset
=> 'utf-8',
4922 -content_disposition
=> 'inline; filename="index.aux"');
4924 foreach my $pr (@projects) {
4925 if (!exists $pr->{'owner'}) {
4926 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4929 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4930 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4931 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4932 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4936 print "$path $owner\n";
4941 my $descr = git_get_project_description
($project) || "none";
4942 my %co = parse_commit
("HEAD");
4943 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4944 my $head = $co{'id'};
4946 my $owner = git_get_project_owner
($project);
4948 my $refs = git_get_references
();
4949 # These get_*_list functions return one more to allow us to see if
4950 # there are more ...
4951 my @taglist = git_get_tags_list
(16);
4952 my @headlist = git_get_heads_list
(16);
4954 my $check_forks = gitweb_check_feature
('forks');
4957 @forklist = git_get_projects_list
($project);
4961 git_print_page_nav
('summary','', $head);
4963 print "<div class=\"title\"> </div>\n";
4964 print "<table class=\"projects_list\">\n" .
4965 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4966 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4967 if (defined $cd{'rfc2822'}) {
4968 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4971 # use per project git URL list in $projectroot/$project/cloneurl
4972 # or make project git URL from git base URL and project name
4973 my $url_tag = "URL";
4974 my @url_list = git_get_project_url_list
($project);
4975 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4976 foreach my $git_url (@url_list) {
4977 next unless $git_url;
4978 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4983 my $show_ctags = gitweb_check_feature
('ctags');
4985 my $ctags = git_get_project_ctags
($project);
4986 my $cloud = git_populate_project_tagcloud
($ctags);
4987 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4988 print "</td>\n<td>" unless %$ctags;
4989 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4990 print "</td>\n<td>" if %$ctags;
4991 print git_show_project_tagcloud
($cloud, 48);
4997 # If XSS prevention is on, we don't include README.html.
4998 # TODO: Allow a readme in some safe format.
4999 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5000 print "<div class=\"title\">readme</div>\n" .
5001 "<div class=\"readme\">\n";
5002 insert_file
("$projectroot/$project/README.html");
5003 print "\n</div>\n"; # class="readme"
5006 # we need to request one more than 16 (0..15) to check if
5008 my @commitlist = $head ? parse_commits
($head, 17) : ();
5010 git_print_header_div
('shortlog');
5011 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5012 $#commitlist <= 15 ?
undef :
5013 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5017 git_print_header_div
('tags');
5018 git_tags_body
(\
@taglist, 0, 15,
5019 $#taglist <= 15 ?
undef :
5020 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5024 git_print_header_div
('heads');
5025 git_heads_body
(\
@headlist, $head, 0, 15,
5026 $#headlist <= 15 ?
undef :
5027 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5031 git_print_header_div
('forks');
5032 git_project_list_body
(\
@forklist, 'age', 0, 15,
5033 $#forklist <= 15 ?
undef :
5034 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5042 my $head = git_get_head_hash
($project);
5044 git_print_page_nav
('','', $head,undef,$head);
5045 my %tag = parse_tag
($hash);
5048 die_error
(404, "Unknown tag object");
5051 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5052 print "<div class=\"title_text\">\n" .
5053 "<table class=\"object_header\">\n" .
5055 "<td>object</td>\n" .
5056 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5057 $tag{'object'}) . "</td>\n" .
5058 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5059 $tag{'type'}) . "</td>\n" .
5061 if (defined($tag{'author'})) {
5062 git_print_authorship_rows
(\
%tag, 'author');
5064 print "</table>\n\n" .
5066 print "<div class=\"page_body\">";
5067 my $comment = $tag{'comment'};
5068 foreach my $line (@
$comment) {
5070 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5076 sub git_blame_common
{
5077 my $format = shift || 'porcelain';
5078 if ($format eq 'porcelain' && $cgi->param('js')) {
5079 $format = 'incremental';
5080 $action = 'blame_incremental'; # for page title etc
5084 gitweb_check_feature
('blame')
5085 or die_error
(403, "Blame view not allowed");
5088 die_error
(400, "No file name given") unless $file_name;
5089 $hash_base ||= git_get_head_hash
($project);
5090 die_error
(404, "Couldn't find base commit") unless $hash_base;
5091 my %co = parse_commit
($hash_base)
5092 or die_error
(404, "Commit not found");
5094 if (!defined $hash) {
5095 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5096 or die_error
(404, "Error looking up file");
5098 $ftype = git_get_type
($hash);
5099 if ($ftype !~ "blob") {
5100 die_error
(400, "Object is not a blob");
5105 if ($format eq 'incremental') {
5106 # get file contents (as base)
5107 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5108 or die_error
(500, "Open git-cat-file failed");
5109 } elsif ($format eq 'data') {
5110 # run git-blame --incremental
5111 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5112 $hash_base, "--", $file_name
5113 or die_error
(500, "Open git-blame --incremental failed");
5115 # run git-blame --porcelain
5116 open $fd, "-|", git_cmd
(), "blame", '-p',
5117 $hash_base, '--', $file_name
5118 or die_error
(500, "Open git-blame --porcelain failed");
5121 # incremental blame data returns early
5122 if ($format eq 'data') {
5124 -type
=>"text/plain", -charset
=> "utf-8",
5125 -status
=> "200 OK");
5126 local $| = 1; # output autoflush
5129 or print "ERROR $!\n";
5132 if (!$caching_enabled &&
5133 defined $t0 && gitweb_check_feature
('timed')) {
5135 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5136 ' '.$number_of_git_cmds;
5146 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5149 if ($format eq 'incremental') {
5151 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5152 "blame") . " (non-incremental)";
5155 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5156 "blame") . " (incremental)";
5160 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5163 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5165 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5166 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5167 git_print_page_path
($file_name, $ftype, $hash_base);
5170 if ($format eq 'incremental') {
5171 print "<noscript>\n<div class=\"error\"><center><b>\n".
5172 "This page requires JavaScript to run.\n Use ".
5173 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5176 "</b></center></div>\n</noscript>\n";
5178 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5181 print qq!<div
class="page_body">\n!;
5182 print qq!<div id
="progress_info">... / ...</div
>\n!
5183 if ($format eq 'incremental');
5184 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5185 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5187 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5191 my @rev_color = qw(light dark);
5192 my $num_colors = scalar(@rev_color);
5193 my $current_color = 0;
5195 if ($format eq 'incremental') {
5196 my $color_class = $rev_color[$current_color];
5201 while (my $line = <$fd>) {
5205 print qq!<tr id
="l$linenr" class="$color_class">!.
5206 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5207 qq!<td
class="linenr">!.
5208 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5209 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5213 } else { # porcelain, i.e. ordinary blame
5214 my %metainfo = (); # saves information about commits
5218 while (my $line = <$fd>) {
5220 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5221 # no <lines in group> for subsequent lines in group of lines
5222 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5223 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5224 if (!exists $metainfo{$full_rev}) {
5225 $metainfo{$full_rev} = { 'nprevious' => 0 };
5227 my $meta = $metainfo{$full_rev};
5229 while ($data = <$fd>) {
5231 last if ($data =~ s/^\t//); # contents of line
5232 if ($data =~ /^(\S+)(?: (.*))?$/) {
5233 $meta->{$1} = $2 unless exists $meta->{$1};
5235 if ($data =~ /^previous /) {
5236 $meta->{'nprevious'}++;
5239 my $short_rev = substr($full_rev, 0, 8);
5240 my $author = $meta->{'author'};
5242 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5243 my $date = $date{'iso-tz'};
5245 $current_color = ($current_color + 1) % $num_colors;
5247 my $tr_class = $rev_color[$current_color];
5248 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5249 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5250 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5251 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5253 print "<td class=\"sha1\"";
5254 print " title=\"". esc_html
($author) . ", $date\"";
5255 print " rowspan=\"$group_size\"" if ($group_size > 1);
5257 print $cgi->a({-href
=> href
(action
=>"commit",
5259 file_name
=>$file_name)},
5260 esc_html
($short_rev));
5261 if ($group_size >= 2) {
5262 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5263 if (@author_initials) {
5265 esc_html
(join('', @author_initials));
5271 # 'previous' <sha1 of parent commit> <filename at commit>
5272 if (exists $meta->{'previous'} &&
5273 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5274 $meta->{'parent'} = $1;
5275 $meta->{'file_parent'} = unquote
($2);
5278 exists($meta->{'parent'}) ?
5279 $meta->{'parent'} : $full_rev;
5280 my $linenr_filename =
5281 exists($meta->{'file_parent'}) ?
5282 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5283 my $blamed = href
(action
=> 'blame',
5284 file_name
=> $linenr_filename,
5285 hash_base
=> $linenr_commit);
5286 print "<td class=\"linenr\">";
5287 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5288 -class => "linenr" },
5291 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5299 "</table>\n"; # class="blame"
5300 print "</div>\n"; # class="blame_body"
5302 or print "Reading blob failed\n";
5311 sub git_blame_incremental
{
5312 git_blame_common
('incremental');
5315 sub git_blame_data
{
5316 git_blame_common
('data');
5320 my $head = git_get_head_hash
($project);
5322 git_print_page_nav
('','', $head,undef,$head);
5323 git_print_header_div
('summary', $project);
5325 my @tagslist = git_get_tags_list
();
5327 git_tags_body
(\
@tagslist);
5333 my $head = git_get_head_hash
($project);
5335 git_print_page_nav
('','', $head,undef,$head);
5336 git_print_header_div
('summary', $project);
5338 my @headslist = git_get_heads_list
();
5340 git_heads_body
(\
@headslist, $head);
5345 sub git_blob_plain
{
5349 if (!defined $hash) {
5350 if (defined $file_name) {
5351 my $base = $hash_base || git_get_head_hash
($project);
5352 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5353 or die_error
(404, "Cannot find file");
5355 die_error
(400, "No file name defined");
5357 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5358 # blobs defined by non-textual hash id's can be cached
5362 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5363 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5365 # content-type (can include charset)
5366 $type = blob_contenttype
($fd, $file_name, $type);
5368 # "save as" filename, even when no $file_name is given
5369 my $save_as = "$hash";
5370 if (defined $file_name) {
5371 $save_as = $file_name;
5372 } elsif ($type =~ m/^text\//) {
5376 # With XSS prevention on, blobs of all types except a few known safe
5377 # ones are served with "Content-Disposition: attachment" to make sure
5378 # they don't run in our security domain. For certain image types,
5379 # blob view writes an <img> tag referring to blob_plain view, and we
5380 # want to be sure not to break that by serving the image as an
5381 # attachment (though Firefox 3 doesn't seem to care).
5382 my $sandbox = $prevent_xss &&
5383 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5387 -expires
=> $expires,
5388 -content_disposition
=>
5389 ($sandbox ?
'attachment' : 'inline')
5390 . '; filename="' . $save_as . '"');
5392 binmode STDOUT
, ':raw';
5394 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5401 if (!defined $hash) {
5402 if (defined $file_name) {
5403 my $base = $hash_base || git_get_head_hash
($project);
5404 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5405 or die_error
(404, "Cannot find file");
5407 die_error
(400, "No file name defined");
5409 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5410 # blobs defined by non-textual hash id's can be cached
5414 my $have_blame = gitweb_check_feature
('blame');
5415 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5416 or die_error
(500, "Couldn't cat $file_name, $hash");
5417 my $mimetype = blob_mimetype
($fd, $file_name);
5418 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5420 return git_blob_plain
($mimetype);
5422 # we can have blame only for text/* mimetype
5423 $have_blame &&= ($mimetype =~ m!^text/!);
5425 git_header_html
(undef, $expires);
5426 my $formats_nav = '';
5427 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5428 if (defined $file_name) {
5431 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5436 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5439 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5442 $cgi->a({-href
=> href
(action
=>"blob",
5443 hash_base
=>"HEAD", file_name
=>$file_name)},
5447 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5450 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5451 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5453 print "<div class=\"page_nav\">\n" .
5454 "<br/><br/></div>\n" .
5455 "<div class=\"title\">$hash</div>\n";
5457 git_print_page_path
($file_name, "blob", $hash_base);
5458 print "<div class=\"page_body\">\n";
5459 if ($mimetype =~ m!^image/!) {
5460 print qq!<img type
="$mimetype"!;
5462 print qq! alt
="$file_name" title
="$file_name"!;
5465 href(action=>"blob_plain
", hash=>$hash,
5466 hash_base=>$hash_base, file_name=>$file_name) .
5470 while (my $line = <$fd>) {
5473 $line = untabify
($line);
5474 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5475 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5476 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5480 or print "Reading blob failed.\n";
5486 if (!defined $hash_base) {
5487 $hash_base = "HEAD";
5489 if (!defined $hash) {
5490 if (defined $file_name) {
5491 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5496 die_error
(404, "No such tree") unless defined($hash);
5498 my $show_sizes = gitweb_check_feature
('show-sizes');
5499 my $have_blame = gitweb_check_feature
('blame');
5504 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5505 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5506 or die_error
(500, "Open git-ls-tree failed");
5507 @entries = map { chomp; $_ } <$fd>;
5509 or die_error
(404, "Reading tree failed");
5512 my $refs = git_get_references
();
5513 my $ref = format_ref_marker
($refs, $hash_base);
5516 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5518 if (defined $file_name) {
5520 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5522 $cgi->a({-href
=> href
(action
=>"tree",
5523 hash_base
=>"HEAD", file_name
=>$file_name)},
5526 my $snapshot_links = format_snapshot_links
($hash);
5527 if (defined $snapshot_links) {
5528 # FIXME: Should be available when we have no hash base as well.
5529 push @views_nav, $snapshot_links;
5531 git_print_page_nav
('tree','', $hash_base, undef, undef,
5532 join(' | ', @views_nav));
5533 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5536 print "<div class=\"page_nav\">\n";
5537 print "<br/><br/></div>\n";
5538 print "<div class=\"title\">$hash</div>\n";
5540 if (defined $file_name) {
5541 $basedir = $file_name;
5542 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5545 git_print_page_path
($file_name, 'tree', $hash_base);
5547 print "<div class=\"page_body\">\n";
5548 print "<table class=\"tree\">\n";
5550 # '..' (top directory) link if possible
5551 if (defined $hash_base &&
5552 defined $file_name && $file_name =~ m![^/]+$!) {
5554 print "<tr class=\"dark\">\n";
5556 print "<tr class=\"light\">\n";
5560 my $up = $file_name;
5561 $up =~ s!/?[^/]+$!!;
5562 undef $up unless $up;
5563 # based on git_print_tree_entry
5564 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5565 print '<td class="size"> </td>'."\n" if $show_sizes;
5566 print '<td class="list">';
5567 print $cgi->a({-href
=> href
(action
=>"tree",
5568 hash_base
=>$hash_base,
5572 print "<td class=\"link\"></td>\n";
5576 foreach my $line (@entries) {
5577 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5580 print "<tr class=\"dark\">\n";
5582 print "<tr class=\"light\">\n";
5586 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5590 print "</table>\n" .
5596 my ($project, $hash) = @_;
5598 # path/to/project.git -> project
5599 # path/to/project/.git -> project
5600 my $name = to_utf8
($project);
5601 $name =~ s
,([^/])/*\
.git
$,$1,;
5602 $name = basename
($name);
5604 $name =~ s/[[:cntrl:]]/?/g;
5607 if ($hash =~ /^[0-9a-fA-F]+$/) {
5608 # shorten SHA-1 hash
5609 my $full_hash = git_get_full_hash
($project, $hash);
5610 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5611 $ver = git_get_short_hash
($project, $hash);
5613 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5614 # tags don't need shortened SHA-1 hash
5617 # branches and other need shortened SHA-1 hash
5618 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5621 $ver .= '-' . git_get_short_hash
($project, $hash);
5623 # in case of hierarchical branch names
5626 # name = project-version_string
5627 $name = "$name-$ver";
5629 return wantarray ?
($name, $name) : $name;
5633 my $format = $input_params{'snapshot_format'};
5634 if (!@snapshot_fmts) {
5635 die_error
(403, "Snapshots not allowed");
5637 # default to first supported snapshot format
5638 $format ||= $snapshot_fmts[0];
5639 if ($format !~ m/^[a-z0-9]+$/) {
5640 die_error
(400, "Invalid snapshot format parameter");
5641 } elsif (!exists($known_snapshot_formats{$format})) {
5642 die_error
(400, "Unknown snapshot format");
5643 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5644 die_error
(403, "Snapshot format not allowed");
5645 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5646 die_error
(403, "Unsupported snapshot format");
5649 my $type = git_get_type
("$hash^{}");
5651 die_error
(404, 'Object does not exist');
5652 } elsif ($type eq 'blob') {
5653 die_error
(400, 'Object is not a tree-ish');
5656 my ($name, $prefix) = snapshot_name
($project, $hash);
5657 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5658 my $cmd = quote_command
(
5659 git_cmd
(), 'archive',
5660 "--format=$known_snapshot_formats{$format}{'format'}",
5661 "--prefix=$prefix/", $hash);
5662 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5663 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5666 $filename =~ s/(["\\])/\\$1/g;
5668 -type
=> $known_snapshot_formats{$format}{'type'},
5669 -content_disposition
=> 'inline; filename="' . $filename . '"',
5670 -status
=> '200 OK');
5672 open my $fd, "-|", $cmd
5673 or die_error
(500, "Execute git-archive failed");
5674 binmode STDOUT
, ':raw';
5676 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5680 sub git_log_generic
{
5681 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5683 my $head = git_get_head_hash
($project);
5684 if (!defined $base) {
5687 if (!defined $page) {
5690 my $refs = git_get_references
();
5692 my $commit_hash = $base;
5693 if (defined $parent) {
5694 $commit_hash = "$parent..$base";
5697 parse_commits
($commit_hash, 101, (100 * $page),
5698 defined $file_name ?
($file_name, "--full-history") : ());
5701 if (!defined $file_hash && defined $file_name) {
5702 # some commits could have deleted file in question,
5703 # and not have it in tree, but one of them has to have it
5704 for (my $i = 0; $i < @commitlist; $i++) {
5705 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5706 last if defined $file_hash;
5709 if (defined $file_hash) {
5710 $ftype = git_get_type
($file_hash);
5712 if (defined $file_name && !defined $ftype) {
5713 die_error
(500, "Unknown type of object");
5716 if (defined $file_name) {
5717 %co = parse_commit
($base)
5718 or die_error
(404, "Unknown commit object");
5722 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5724 if ($#commitlist >= 100) {
5726 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5727 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5729 my $patch_max = gitweb_get_feature
('patches');
5730 if ($patch_max && !defined $file_name) {
5731 if ($patch_max < 0 || @commitlist <= $patch_max) {
5732 $paging_nav .= " ⋅ " .
5733 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5739 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5740 if (defined $file_name) {
5741 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5743 git_print_header_div
('summary', $project)
5745 git_print_page_path
($file_name, $ftype, $hash_base)
5746 if (defined $file_name);
5748 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5749 $file_name, $file_hash, $ftype);
5755 git_log_generic
('log', \
&git_log_body
,
5756 $hash, $hash_parent);
5760 $hash ||= $hash_base || "HEAD";
5761 my %co = parse_commit
($hash)
5762 or die_error
(404, "Unknown commit object");
5764 my $parent = $co{'parent'};
5765 my $parents = $co{'parents'}; # listref
5767 # we need to prepare $formats_nav before any parameter munging
5769 if (!defined $parent) {
5771 $formats_nav .= '(initial)';
5772 } elsif (@
$parents == 1) {
5773 # single parent commit
5776 $cgi->a({-href
=> href
(action
=>"commit",
5778 esc_html
(substr($parent, 0, 7))) .
5785 $cgi->a({-href
=> href
(action
=>"commit",
5787 esc_html
(substr($_, 0, 7)));
5791 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5792 $formats_nav .= " | " .
5793 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5797 if (!defined $parent) {
5801 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5803 (@
$parents <= 1 ?
$parent : '-c'),
5805 or die_error
(500, "Open git-diff-tree failed");
5806 @difftree = map { chomp; $_ } <$fd>;
5807 close $fd or die_error
(404, "Reading git-diff-tree failed");
5809 # non-textual hash id's can be cached
5811 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5814 my $refs = git_get_references
();
5815 my $ref = format_ref_marker
($refs, $co{'id'});
5817 git_header_html
(undef, $expires);
5818 git_print_page_nav
('commit', '',
5819 $hash, $co{'tree'}, $hash,
5822 if (defined $co{'parent'}) {
5823 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5825 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5827 print "<div class=\"title_text\">\n" .
5828 "<table class=\"object_header\">\n";
5829 git_print_authorship_rows
(\
%co);
5830 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5833 "<td class=\"sha1\">" .
5834 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5835 class => "list"}, $co{'tree'}) .
5837 "<td class=\"link\">" .
5838 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5840 my $snapshot_links = format_snapshot_links
($hash);
5841 if (defined $snapshot_links) {
5842 print " | " . $snapshot_links;
5847 foreach my $par (@
$parents) {
5850 "<td class=\"sha1\">" .
5851 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5852 class => "list"}, $par) .
5854 "<td class=\"link\">" .
5855 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5857 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5864 print "<div class=\"page_body\">\n";
5865 git_print_log
($co{'comment'});
5868 git_difftree_body
(\
@difftree, $hash, @
$parents);
5874 # object is defined by:
5875 # - hash or hash_base alone
5876 # - hash_base and file_name
5879 # - hash or hash_base alone
5880 if ($hash || ($hash_base && !defined $file_name)) {
5881 my $object_id = $hash || $hash_base;
5883 open my $fd, "-|", quote_command
(
5884 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5885 or die_error
(404, "Object does not exist");
5889 or die_error
(404, "Object does not exist");
5891 # - hash_base and file_name
5892 } elsif ($hash_base && defined $file_name) {
5893 $file_name =~ s
,/+$,,;
5895 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5896 or die_error
(404, "Base object does not exist");
5898 # here errors should not hapen
5899 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5900 or die_error
(500, "Open git-ls-tree failed");
5904 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5905 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5906 die_error
(404, "File or directory for given base does not exist");
5911 die_error
(400, "Not enough information to find object");
5914 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5915 hash
=>$hash, hash_base
=>$hash_base,
5916 file_name
=>$file_name),
5917 -status
=> '302 Found');
5921 my $format = shift || 'html';
5928 # preparing $fd and %diffinfo for git_patchset_body
5930 if (defined $hash_base && defined $hash_parent_base) {
5931 if (defined $file_name) {
5933 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5934 $hash_parent_base, $hash_base,
5935 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5936 or die_error
(500, "Open git-diff-tree failed");
5937 @difftree = map { chomp; $_ } <$fd>;
5939 or die_error
(404, "Reading git-diff-tree failed");
5941 or die_error
(404, "Blob diff not found");
5943 } elsif (defined $hash &&
5944 $hash =~ /[0-9a-fA-F]{40}/) {
5945 # try to find filename from $hash
5947 # read filtered raw output
5948 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5949 $hash_parent_base, $hash_base, "--"
5950 or die_error
(500, "Open git-diff-tree failed");
5952 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5954 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5955 map { chomp; $_ } <$fd>;
5957 or die_error
(404, "Reading git-diff-tree failed");
5959 or die_error
(404, "Blob diff not found");
5962 die_error
(400, "Missing one of the blob diff parameters");
5965 if (@difftree > 1) {
5966 die_error
(400, "Ambiguous blob diff specification");
5969 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5970 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5971 $file_name ||= $diffinfo{'to_file'};
5973 $hash_parent ||= $diffinfo{'from_id'};
5974 $hash ||= $diffinfo{'to_id'};
5976 # non-textual hash id's can be cached
5977 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5978 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5983 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5984 '-p', ($format eq 'html' ?
"--full-index" : ()),
5985 $hash_parent_base, $hash_base,
5986 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5987 or die_error
(500, "Open git-diff-tree failed");
5990 # old/legacy style URI -- not generated anymore since 1.4.3.
5992 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5996 if ($format eq 'html') {
5998 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6000 git_header_html
(undef, $expires);
6001 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6002 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6003 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6005 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6006 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
6008 if (defined $file_name) {
6009 git_print_page_path
($file_name, "blob", $hash_base);
6011 print "<div class=\"page_path\"></div>\n";
6014 } elsif ($format eq 'plain') {
6016 -type
=> 'text/plain',
6017 -charset
=> 'utf-8',
6018 -expires
=> $expires,
6019 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6021 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6024 die_error
(400, "Unknown blobdiff format");
6028 if ($format eq 'html') {
6029 print "<div class=\"page_body\">\n";
6031 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6034 print "</div>\n"; # class="page_body"
6038 while (my $line = <$fd>) {
6039 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6040 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6044 last if $line =~ m!^\+\+\+!;
6052 sub git_blobdiff_plain
{
6053 git_blobdiff
('plain');
6056 sub git_commitdiff
{
6058 my $format = $params{-format
} || 'html';
6060 my ($patch_max) = gitweb_get_feature
('patches');
6061 if ($format eq 'patch') {
6062 die_error
(403, "Patch view not allowed") unless $patch_max;
6065 $hash ||= $hash_base || "HEAD";
6066 my %co = parse_commit
($hash)
6067 or die_error
(404, "Unknown commit object");
6069 # choose format for commitdiff for merge
6070 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6071 $hash_parent = '--cc';
6073 # we need to prepare $formats_nav before almost any parameter munging
6075 if ($format eq 'html') {
6077 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6079 if ($patch_max && @
{$co{'parents'}} <= 1) {
6080 $formats_nav .= " | " .
6081 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6085 if (defined $hash_parent &&
6086 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6087 # commitdiff with two commits given
6088 my $hash_parent_short = $hash_parent;
6089 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6090 $hash_parent_short = substr($hash_parent, 0, 7);
6094 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6095 if ($co{'parents'}[$i] eq $hash_parent) {
6096 $formats_nav .= ' parent ' . ($i+1);
6100 $formats_nav .= ': ' .
6101 $cgi->a({-href
=> href
(action
=>"commitdiff",
6102 hash
=>$hash_parent)},
6103 esc_html
($hash_parent_short)) .
6105 } elsif (!$co{'parent'}) {
6107 $formats_nav .= ' (initial)';
6108 } elsif (scalar @
{$co{'parents'}} == 1) {
6109 # single parent commit
6112 $cgi->a({-href
=> href
(action
=>"commitdiff",
6113 hash
=>$co{'parent'})},
6114 esc_html
(substr($co{'parent'}, 0, 7))) .
6118 if ($hash_parent eq '--cc') {
6119 $formats_nav .= ' | ' .
6120 $cgi->a({-href
=> href
(action
=>"commitdiff",
6121 hash
=>$hash, hash_parent
=>'-c')},
6123 } else { # $hash_parent eq '-c'
6124 $formats_nav .= ' | ' .
6125 $cgi->a({-href
=> href
(action
=>"commitdiff",
6126 hash
=>$hash, hash_parent
=>'--cc')},
6132 $cgi->a({-href
=> href
(action
=>"commitdiff",
6134 esc_html
(substr($_, 0, 7)));
6135 } @
{$co{'parents'}} ) .
6140 my $hash_parent_param = $hash_parent;
6141 if (!defined $hash_parent_param) {
6142 # --cc for multiple parents, --root for parentless
6143 $hash_parent_param =
6144 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6150 if ($format eq 'html') {
6151 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6152 "--no-commit-id", "--patch-with-raw", "--full-index",
6153 $hash_parent_param, $hash, "--"
6154 or die_error
(500, "Open git-diff-tree failed");
6156 while (my $line = <$fd>) {
6158 # empty line ends raw part of diff-tree output
6160 push @difftree, scalar parse_difftree_raw_line
($line);
6163 } elsif ($format eq 'plain') {
6164 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6165 '-p', $hash_parent_param, $hash, "--"
6166 or die_error
(500, "Open git-diff-tree failed");
6167 } elsif ($format eq 'patch') {
6168 # For commit ranges, we limit the output to the number of
6169 # patches specified in the 'patches' feature.
6170 # For single commits, we limit the output to a single patch,
6171 # diverging from the git-format-patch default.
6172 my @commit_spec = ();
6174 if ($patch_max > 0) {
6175 push @commit_spec, "-$patch_max";
6177 push @commit_spec, '-n', "$hash_parent..$hash";
6179 if ($params{-single
}) {
6180 push @commit_spec, '-1';
6182 if ($patch_max > 0) {
6183 push @commit_spec, "-$patch_max";
6185 push @commit_spec, "-n";
6187 push @commit_spec, '--root', $hash;
6189 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6190 '--stdout', @commit_spec
6191 or die_error
(500, "Open git-format-patch failed");
6193 die_error
(400, "Unknown commitdiff format");
6196 # non-textual hash id's can be cached
6198 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6202 # write commit message
6203 if ($format eq 'html') {
6204 my $refs = git_get_references
();
6205 my $ref = format_ref_marker
($refs, $co{'id'});
6207 git_header_html
(undef, $expires);
6208 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6209 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6210 print "<div class=\"title_text\">\n" .
6211 "<table class=\"object_header\">\n";
6212 git_print_authorship_rows
(\
%co);
6215 print "<div class=\"page_body\">\n";
6216 if (@
{$co{'comment'}} > 1) {
6217 print "<div class=\"log\">\n";
6218 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6219 print "</div>\n"; # class="log"
6222 } elsif ($format eq 'plain') {
6223 my $refs = git_get_references
("tags");
6224 my $tagname = git_get_rev_name_tags
($hash);
6225 my $filename = basename
($project) . "-$hash.patch";
6228 -type
=> 'text/plain',
6229 -charset
=> 'utf-8',
6230 -expires
=> $expires,
6231 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6232 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6233 print "From: " . to_utf8
($co{'author'}) . "\n";
6234 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6235 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6237 print "X-Git-Tag: $tagname\n" if $tagname;
6238 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6240 foreach my $line (@
{$co{'comment'}}) {
6241 print to_utf8
($line) . "\n";
6244 } elsif ($format eq 'patch') {
6245 my $filename = basename
($project) . "-$hash.patch";
6248 -type
=> 'text/plain',
6249 -charset
=> 'utf-8',
6250 -expires
=> $expires,
6251 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6255 if ($format eq 'html') {
6256 my $use_parents = !defined $hash_parent ||
6257 $hash_parent eq '-c' || $hash_parent eq '--cc';
6258 git_difftree_body
(\
@difftree, $hash,
6259 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6262 git_patchset_body
($fd, \
@difftree, $hash,
6263 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6265 print "</div>\n"; # class="page_body"
6268 } elsif ($format eq 'plain') {
6272 or print "Reading git-diff-tree failed\n";
6273 } elsif ($format eq 'patch') {
6277 or print "Reading git-format-patch failed\n";
6281 sub git_commitdiff_plain
{
6282 git_commitdiff
(-format
=> 'plain');
6285 # format-patch-style patches
6287 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6291 git_commitdiff
(-format
=> 'patch');
6295 git_log_generic
('history', \
&git_history_body
,
6296 $hash_base, $hash_parent_base,
6301 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6302 if (!defined $searchtext) {
6303 die_error
(400, "Text field is empty");
6305 if (!defined $hash) {
6306 $hash = git_get_head_hash
($project);
6308 my %co = parse_commit
($hash);
6310 die_error
(404, "Unknown commit object");
6312 if (!defined $page) {
6316 $searchtype ||= 'commit';
6317 if ($searchtype eq 'pickaxe') {
6318 # pickaxe may take all resources of your box and run for several minutes
6319 # with every query - so decide by yourself how public you make this feature
6320 gitweb_check_feature
('pickaxe')
6321 or die_error
(403, "Pickaxe is disabled");
6323 if ($searchtype eq 'grep') {
6324 gitweb_check_feature
('grep')
6325 or die_error
(403, "Grep is disabled");
6330 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6332 if ($searchtype eq 'commit') {
6333 $greptype = "--grep=";
6334 } elsif ($searchtype eq 'author') {
6335 $greptype = "--author=";
6336 } elsif ($searchtype eq 'committer') {
6337 $greptype = "--committer=";
6339 $greptype .= $searchtext;
6340 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6341 $greptype, '--regexp-ignore-case',
6342 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6344 my $paging_nav = '';
6347 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6348 searchtext
=>$searchtext,
6349 searchtype
=>$searchtype)},
6351 $paging_nav .= " ⋅ " .
6352 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6353 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6355 $paging_nav .= "first";
6356 $paging_nav .= " ⋅ prev";
6359 if ($#commitlist >= 100) {
6361 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6362 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6363 $paging_nav .= " ⋅ $next_link";
6365 $paging_nav .= " ⋅ next";
6368 if ($#commitlist >= 100) {
6371 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6372 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6373 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6376 if ($searchtype eq 'pickaxe') {
6377 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6378 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6380 print "<table class=\"pickaxe search\">\n";
6383 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6384 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6385 ($search_use_regexp ?
'--pickaxe-regex' : ());
6388 while (my $line = <$fd>) {
6392 my %set = parse_difftree_raw_line
($line);
6393 if (defined $set{'commit'}) {
6394 # finish previous commit
6397 "<td class=\"link\">" .
6398 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6400 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6406 print "<tr class=\"dark\">\n";
6408 print "<tr class=\"light\">\n";
6411 %co = parse_commit
($set{'commit'});
6412 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6413 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6414 "<td><i>$author</i></td>\n" .
6416 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6417 -class => "list subject"},
6418 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6419 } elsif (defined $set{'to_id'}) {
6420 next if ($set{'to_id'} =~ m/^0{40}$/);
6422 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6423 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6425 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6431 # finish last commit (warning: repetition!)
6434 "<td class=\"link\">" .
6435 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6437 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6445 if ($searchtype eq 'grep') {
6446 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6447 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6449 print "<table class=\"grep_search\">\n";
6453 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6454 $search_use_regexp ?
('-E', '-i') : '-F',
6455 $searchtext, $co{'tree'};
6457 while (my $line = <$fd>) {
6459 my ($file, $lno, $ltext, $binary);
6460 last if ($matches++ > 1000);
6461 if ($line =~ /^Binary file (.+) matches$/) {
6465 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6467 if ($file ne $lastfile) {
6468 $lastfile and print "</td></tr>\n";
6470 print "<tr class=\"dark\">\n";
6472 print "<tr class=\"light\">\n";
6474 print "<td class=\"list\">".
6475 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6476 file_name
=>"$file"),
6477 -class => "list"}, esc_path
($file));
6478 print "</td><td>\n";
6482 print "<div class=\"binary\">Binary file</div>\n";
6484 $ltext = untabify
($ltext);
6485 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6486 $ltext = esc_html
($1, -nbsp
=>1);
6487 $ltext .= '<span class="match">';
6488 $ltext .= esc_html
($2, -nbsp
=>1);
6489 $ltext .= '</span>';
6490 $ltext .= esc_html
($3, -nbsp
=>1);
6492 $ltext = esc_html
($ltext, -nbsp
=>1);
6494 print "<div class=\"pre\">" .
6495 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6496 file_name
=>"$file").'#l'.$lno,
6497 -class => "linenr"}, sprintf('%4i', $lno))
6498 . ' ' . $ltext . "</div>\n";
6502 print "</td></tr>\n";
6503 if ($matches > 1000) {
6504 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6507 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6516 sub git_search_help
{
6518 git_print_page_nav
('','', $hash,$hash,$hash);
6520 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6521 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6522 the pattern entered is recognized as the POSIX extended
6523 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6526 <dt><b>commit</b></dt>
6527 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6529 my $have_grep = gitweb_check_feature
('grep');
6532 <dt><b>grep</b></dt>
6533 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6534 a different one) are searched for the given pattern. On large trees, this search can take
6535 a while and put some strain on the server, so please use it with some consideration. Note that
6536 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6537 case-sensitive.</dd>
6541 <dt><b>author</b></dt>
6542 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6543 <dt><b>committer</b></dt>
6544 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6546 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6547 if ($have_pickaxe) {
6549 <dt><b>pickaxe</b></dt>
6550 <dd>All commits that caused the string to appear or disappear from any file (changes that
6551 added, removed or "modified" the string) will be listed. This search can take a while and
6552 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6553 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6561 git_log_generic
('shortlog', \
&git_shortlog_body
,
6562 $hash, $hash_parent);
6565 ## ......................................................................
6566 ## feeds (RSS, Atom; OPML)
6569 my $format = shift || 'atom';
6570 my $have_blame = gitweb_check_feature
('blame');
6572 # Atom: http://www.atomenabled.org/developers/syndication/
6573 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6574 if ($format ne 'rss' && $format ne 'atom') {
6575 die_error
(400, "Unknown web feed format");
6578 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6579 my $head = $hash || 'HEAD';
6580 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6584 my $content_type = "application/$format+xml";
6585 if (defined $cgi->http('HTTP_ACCEPT') &&
6586 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6587 # browser (feed reader) prefers text/xml
6588 $content_type = 'text/xml';
6590 if (defined($commitlist[0])) {
6591 %latest_commit = %{$commitlist[0]};
6592 my $latest_epoch = $latest_commit{'committer_epoch'};
6593 %latest_date = parse_date
($latest_epoch);
6594 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6595 if (defined $if_modified) {
6597 if (eval { require HTTP
::Date
; 1; }) {
6598 $since = HTTP
::Date
::str2time
($if_modified);
6599 } elsif (eval { require Time
::ParseDate
; 1; }) {
6600 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6602 if (defined $since && $latest_epoch <= $since) {
6604 -type
=> $content_type,
6605 -charset
=> 'utf-8',
6606 -last_modified
=> $latest_date{'rfc2822'},
6607 -status
=> '304 Not Modified');
6612 -type
=> $content_type,
6613 -charset
=> 'utf-8',
6614 -last_modified
=> $latest_date{'rfc2822'});
6617 -type
=> $content_type,
6618 -charset
=> 'utf-8');
6621 # Optimization: skip generating the body if client asks only
6622 # for Last-Modified date.
6623 return if ($cgi->request_method() eq 'HEAD');
6626 my $title = "$site_name - $project/$action";
6627 my $feed_type = 'log';
6628 if (defined $hash) {
6629 $title .= " - '$hash'";
6630 $feed_type = 'branch log';
6631 if (defined $file_name) {
6632 $title .= " :: $file_name";
6633 $feed_type = 'history';
6635 } elsif (defined $file_name) {
6636 $title .= " - $file_name";
6637 $feed_type = 'history';
6639 $title .= " $feed_type";
6640 my $descr = git_get_project_description
($project);
6641 if (defined $descr) {
6642 $descr = esc_html
($descr);
6644 $descr = "$project " .
6645 ($format eq 'rss' ?
'RSS' : 'Atom') .
6648 my $owner = git_get_project_owner
($project);
6649 $owner = esc_html
($owner);
6653 if (defined $file_name) {
6654 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6655 } elsif (defined $hash) {
6656 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6658 $alt_url = href
(-full
=>1, action
=>"summary");
6660 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6661 if ($format eq 'rss') {
6663 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6666 print "<title>$title</title>\n" .
6667 "<link>$alt_url</link>\n" .
6668 "<description>$descr</description>\n" .
6669 "<language>en</language>\n" .
6670 # project owner is responsible for 'editorial' content
6671 "<managingEditor>$owner</managingEditor>\n";
6672 if (defined $logo || defined $favicon) {
6673 # prefer the logo to the favicon, since RSS
6674 # doesn't allow both
6675 my $img = esc_url
($logo || $favicon);
6677 "<url>$img</url>\n" .
6678 "<title>$title</title>\n" .
6679 "<link>$alt_url</link>\n" .
6683 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6684 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6686 print "<generator>gitweb v.$version/$git_version</generator>\n";
6687 } elsif ($format eq 'atom') {
6689 <feed xmlns="http://www.w3.org/2005/Atom">
6691 print "<title>$title</title>\n" .
6692 "<subtitle>$descr</subtitle>\n" .
6693 '<link rel="alternate" type="text/html" href="' .
6694 $alt_url . '" />' . "\n" .
6695 '<link rel="self" type="' . $content_type . '" href="' .
6696 $cgi->self_url() . '" />' . "\n" .
6697 "<id>" . href
(-full
=>1) . "</id>\n" .
6698 # use project owner for feed author
6699 "<author><name>$owner</name></author>\n";
6700 if (defined $favicon) {
6701 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6703 if (defined $logo_url) {
6704 # not twice as wide as tall: 72 x 27 pixels
6705 print "<logo>" . esc_url
($logo) . "</logo>\n";
6707 if (! %latest_date) {
6708 # dummy date to keep the feed valid until commits trickle in:
6709 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6711 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6713 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6717 for (my $i = 0; $i <= $#commitlist; $i++) {
6718 my %co = %{$commitlist[$i]};
6719 my $commit = $co{'id'};
6720 # we read 150, we always show 30 and the ones more recent than 48 hours
6721 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6724 my %cd = parse_date
($co{'author_epoch'});
6726 # get list of changed files
6727 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6728 $co{'parent'} || "--root",
6729 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6731 my @difftree = map { chomp; $_ } <$fd>;
6735 # print element (entry, item)
6736 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6737 if ($format eq 'rss') {
6739 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6740 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6741 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6742 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6743 "<link>$co_url</link>\n" .
6744 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6745 "<content:encoded>" .
6747 } elsif ($format eq 'atom') {
6749 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6750 "<updated>$cd{'iso-8601'}</updated>\n" .
6752 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6753 if ($co{'author_email'}) {
6754 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6756 print "</author>\n" .
6757 # use committer for contributor
6759 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6760 if ($co{'committer_email'}) {
6761 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6763 print "</contributor>\n" .
6764 "<published>$cd{'iso-8601'}</published>\n" .
6765 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6766 "<id>$co_url</id>\n" .
6767 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6768 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6770 my $comment = $co{'comment'};
6772 foreach my $line (@
$comment) {
6773 $line = esc_html
($line);
6776 print "</pre><ul>\n";
6777 foreach my $difftree_line (@difftree) {
6778 my %difftree = parse_difftree_raw_line
($difftree_line);
6779 next if !$difftree{'from_id'};
6781 my $file = $difftree{'file'} || $difftree{'to_file'};
6785 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6786 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6787 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6788 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6789 -title
=> "diff"}, 'D');
6791 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6792 file_name
=>$file, hash_base
=>$commit),
6793 -title
=> "blame"}, 'B');
6795 # if this is not a feed of a file history
6796 if (!defined $file_name || $file_name ne $file) {
6797 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6798 file_name
=>$file, hash
=>$commit),
6799 -title
=> "history"}, 'H');
6801 $file = esc_path
($file);
6805 if ($format eq 'rss') {
6806 print "</ul>]]>\n" .
6807 "</content:encoded>\n" .
6809 } elsif ($format eq 'atom') {
6810 print "</ul>\n</div>\n" .
6817 if ($format eq 'rss') {
6818 print "</channel>\n</rss>\n";
6819 } elsif ($format eq 'atom') {
6833 my @list = git_get_projects_list
();
6836 -type
=> 'text/xml',
6837 -charset
=> 'utf-8',
6838 -content_disposition
=> 'inline; filename="opml.xml"');
6841 <?xml version="1.0" encoding="utf-8"?>
6842 <opml version="1.0">
6844 <title>$site_name OPML Export</title>
6847 <outline text="git RSS feeds">
6850 foreach my $pr (@list) {
6852 my $head = git_get_head_hash
($proj{'path'});
6853 if (!defined $head) {
6856 $git_dir = "$projectroot/$proj{'path'}";
6857 my %co = parse_commit
($head);
6862 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6863 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6864 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6865 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";