3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
13 use CGI
qw(:standard :escapeHTML -nosticky);
14 use CGI
::Util
qw(unescape);
15 use CGI
::Carp
qw(fatalsToBrowser set_message);
19 use File
::Basename
qw(basename);
20 binmode STDOUT
, ':utf8';
23 if (eval { require Time
::HiRes
; 1; }) {
24 $t0 = [Time
::HiRes
::gettimeofday
()];
26 our $number_of_git_cmds = 0;
29 CGI
->compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
34 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
38 our $my_url = $cgi->url();
39 our $my_uri = $cgi->url(-absolute
=> 1);
41 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
42 # needed and used only for URLs with nonempty PATH_INFO
43 our $base_url = $my_url;
45 # When the script is used as DirectoryIndex, the URL does not contain the name
46 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
47 # have to do it ourselves. We make $path_info global because it's also used
50 # Another issue with the script being the DirectoryIndex is that the resulting
51 # $my_url data is not the full script URL: this is good, because we want
52 # generated links to keep implying the script name if it wasn't explicitly
53 # indicated in the URL we're handling, but it means that $my_url cannot be used
55 # Therefore, if we needed to strip PATH_INFO, then we know that we have
56 # to build the base URL ourselves:
57 our $path_info = $ENV{"PATH_INFO"};
59 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
60 $my_uri =~ s
,\Q
$path_info\E
$,, &&
61 defined $ENV{'SCRIPT_NAME'}) {
62 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
66 # target of the home link on top of all pages
67 our $home_link = $my_uri || "/";
70 # core git executable to use
71 # this can just be "git" if your webserver has a sensible PATH
72 our $GIT = "++GIT_BINDIR++/git";
74 # absolute fs-path which will be prepended to the project path
75 #our $projectroot = "/pub/scm";
76 our $projectroot = "++GITWEB_PROJECTROOT++";
78 # fs traversing limit for getting project list
79 # the number is relative to the projectroot
80 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
82 # string of the home link on top of all pages
83 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
85 # name of your site or organization to appear in page titles
86 # replace this with something more descriptive for clearer bookmarks
87 our $site_name = "++GITWEB_SITENAME++"
88 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
90 # filename of html text to include at top of each page
91 our $site_header = "++GITWEB_SITE_HEADER++";
92 # html text to include at home page
93 our $home_text = "++GITWEB_HOMETEXT++";
94 # filename of html text to include at bottom of each page
95 our $site_footer = "++GITWEB_SITE_FOOTER++";
98 our @stylesheets = ("++GITWEB_CSS++");
99 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
100 our $stylesheet = undef;
101 # URI of GIT logo (72x27 size)
102 our $logo = "++GITWEB_LOGO++";
103 # URI of GIT favicon, assumed to be image/png type
104 our $favicon = "++GITWEB_FAVICON++";
105 # URI of gitweb.js (JavaScript code for gitweb)
106 our $javascript = "++GITWEB_JS++";
108 # URI and label (title) of GIT logo link
109 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
110 #our $logo_label = "git documentation";
111 our $logo_url = "http://git-scm.com/";
112 our $logo_label = "git homepage";
114 # source of projects list
115 our $projects_list = "++GITWEB_LIST++";
117 # the width (in characters) of the projects list "Description" column
118 our $projects_list_description_width = 25;
120 # default order of projects list
121 # valid values are none, project, descr, owner, and age
122 our $default_projects_order = "project";
124 # show repository only if this file exists
125 # (only effective if this variable evaluates to true)
126 our $export_ok = "++GITWEB_EXPORT_OK++";
128 # show repository only if this subroutine returns true
129 # when given the path to the project, for example:
130 # sub { return -e "$_[0]/git-daemon-export-ok"; }
131 our $export_auth_hook = undef;
133 # only allow viewing of repositories also shown on the overview page
134 our $strict_export = "++GITWEB_STRICT_EXPORT++";
136 # list of git base URLs used for URL to where fetch project from,
137 # i.e. full URL is "$git_base_url/$project"
138 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
140 # default blob_plain mimetype and default charset for text/plain blob
141 our $default_blob_plain_mimetype = 'text/plain';
142 our $default_text_plain_charset = undef;
144 # file to use for guessing MIME types before trying /etc/mime.types
145 # (relative to the current git repository)
146 our $mimetypes_file = undef;
148 # assume this charset if line contains non-UTF-8 characters;
149 # it should be valid encoding (see Encoding::Supported(3pm) for list),
150 # for which encoding all byte sequences are valid, for example
151 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
152 # could be even 'utf-8' for the old behavior)
153 our $fallback_encoding = 'latin1';
155 # rename detection options for git-diff and git-diff-tree
156 # - default is '-M', with the cost proportional to
157 # (number of removed files) * (number of new files).
158 # - more costly is '-C' (which implies '-M'), with the cost proportional to
159 # (number of changed files + number of removed files) * (number of new files)
160 # - even more costly is '-C', '--find-copies-harder' with cost
161 # (number of files in the original tree) * (number of new files)
162 # - one might want to include '-B' option, e.g. '-B', '-M'
163 our @diff_opts = ('-M'); # taken from git_commit
165 # Disables features that would allow repository owners to inject script into
167 our $prevent_xss = 0;
169 # Path to the highlight executable to use (must be the one from
170 # http://www.andre-simon.de due to assumptions about parameters and output).
171 # Useful if highlight is not installed on your webserver's PATH.
172 # [Default: highlight]
173 our $highlight_bin = "++HIGHLIGHT_BIN++";
175 # information about snapshot formats that gitweb is capable of serving
176 our %known_snapshot_formats = (
178 # 'display' => display name,
179 # 'type' => mime type,
180 # 'suffix' => filename suffix,
181 # 'format' => --format for git-archive,
182 # 'compressor' => [compressor command and arguments]
183 # (array reference, optional)
184 # 'disabled' => boolean (optional)}
187 'display' => 'tar.gz',
188 'type' => 'application/x-gzip',
189 'suffix' => '.tar.gz',
191 'compressor' => ['gzip']},
194 'display' => 'tar.bz2',
195 'type' => 'application/x-bzip2',
196 'suffix' => '.tar.bz2',
198 'compressor' => ['bzip2']},
201 'display' => 'tar.xz',
202 'type' => 'application/x-xz',
203 'suffix' => '.tar.xz',
205 'compressor' => ['xz'],
210 'type' => 'application/x-zip',
215 # Aliases so we understand old gitweb.snapshot values in repository
217 our %known_snapshot_format_aliases = (
222 # backward compatibility: legacy gitweb config support
223 'x-gzip' => undef, 'gz' => undef,
224 'x-bzip2' => undef, 'bz2' => undef,
225 'x-zip' => undef, '' => undef,
228 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
229 # are changed, it may be appropriate to change these values too via
236 # Used to set the maximum load that we will still respond to gitweb queries.
237 # If server load exceed this value then return "503 server busy" error.
238 # If gitweb cannot determined server load, it is taken to be 0.
239 # Leave it undefined (or set to 'undef') to turn off load checking.
242 # configuration for 'highlight' (http://www.andre-simon.de/)
244 our %highlight_basename = (
247 'SConstruct' => 'py', # SCons equivalent of Makefile
248 'Makefile' => 'make',
251 our %highlight_ext = (
252 # main extensions, defining name of syntax;
253 # see files in /usr/share/highlight/langDefs/ directory
255 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
256 # alternate extensions, see /etc/highlight/filetypes.conf
258 map { $_ => 'cpp' } qw(cxx c++ cc),
259 map { $_ => 'php' } qw(php3 php4),
260 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
262 map { $_ => 'xml' } qw(xhtml html htm),
265 # You define site-wide feature defaults here; override them with
266 # $GITWEB_CONFIG as necessary.
269 # 'sub' => feature-sub (subroutine),
270 # 'override' => allow-override (boolean),
271 # 'default' => [ default options...] (array reference)}
273 # if feature is overridable (it means that allow-override has true value),
274 # then feature-sub will be called with default options as parameters;
275 # return value of feature-sub indicates if to enable specified feature
277 # if there is no 'sub' key (no feature-sub), then feature cannot be
280 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
281 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
284 # Enable the 'blame' blob view, showing the last commit that modified
285 # each line in the file. This can be very CPU-intensive.
287 # To enable system wide have in $GITWEB_CONFIG
288 # $feature{'blame'}{'default'} = [1];
289 # To have project specific config enable override in $GITWEB_CONFIG
290 # $feature{'blame'}{'override'} = 1;
291 # and in project config gitweb.blame = 0|1;
293 'sub' => sub { feature_bool
('blame', @_) },
297 # Enable the 'snapshot' link, providing a compressed archive of any
298 # tree. This can potentially generate high traffic if you have large
301 # Value is a list of formats defined in %known_snapshot_formats that
303 # To disable system wide have in $GITWEB_CONFIG
304 # $feature{'snapshot'}{'default'} = [];
305 # To have project specific config enable override in $GITWEB_CONFIG
306 # $feature{'snapshot'}{'override'} = 1;
307 # and in project config, a comma-separated list of formats or "none"
308 # to disable. Example: gitweb.snapshot = tbz2,zip;
310 'sub' => \
&feature_snapshot
,
312 'default' => ['tgz']},
314 # Enable text search, which will list the commits which match author,
315 # committer or commit text to a given string. Enabled by default.
316 # Project specific override is not supported.
321 # Enable grep search, which will list the files in currently selected
322 # tree containing the given string. Enabled by default. This can be
323 # potentially CPU-intensive, of course.
325 # To enable system wide have in $GITWEB_CONFIG
326 # $feature{'grep'}{'default'} = [1];
327 # To have project specific config enable override in $GITWEB_CONFIG
328 # $feature{'grep'}{'override'} = 1;
329 # and in project config gitweb.grep = 0|1;
331 'sub' => sub { feature_bool
('grep', @_) },
335 # Enable the pickaxe search, which will list the commits that modified
336 # a given string in a file. This can be practical and quite faster
337 # alternative to 'blame', but still potentially CPU-intensive.
339 # To enable system wide have in $GITWEB_CONFIG
340 # $feature{'pickaxe'}{'default'} = [1];
341 # To have project specific config enable override in $GITWEB_CONFIG
342 # $feature{'pickaxe'}{'override'} = 1;
343 # and in project config gitweb.pickaxe = 0|1;
345 'sub' => sub { feature_bool
('pickaxe', @_) },
349 # Enable showing size of blobs in a 'tree' view, in a separate
350 # column, similar to what 'ls -l' does. This cost a bit of IO.
352 # To disable system wide have in $GITWEB_CONFIG
353 # $feature{'show-sizes'}{'default'} = [0];
354 # To have project specific config enable override in $GITWEB_CONFIG
355 # $feature{'show-sizes'}{'override'} = 1;
356 # and in project config gitweb.showsizes = 0|1;
358 'sub' => sub { feature_bool
('showsizes', @_) },
362 # Make gitweb use an alternative format of the URLs which can be
363 # more readable and natural-looking: project name is embedded
364 # directly in the path and the query string contains other
365 # auxiliary information. All gitweb installations recognize
366 # URL in either format; this configures in which formats gitweb
369 # To enable system wide have in $GITWEB_CONFIG
370 # $feature{'pathinfo'}{'default'} = [1];
371 # Project specific override is not supported.
373 # Note that you will need to change the default location of CSS,
374 # favicon, logo and possibly other files to an absolute URL. Also,
375 # if gitweb.cgi serves as your indexfile, you will need to force
376 # $my_uri to contain the script name in your $GITWEB_CONFIG.
381 # Make gitweb consider projects in project root subdirectories
382 # to be forks of existing projects. Given project $projname.git,
383 # projects matching $projname/*.git will not be shown in the main
384 # projects list, instead a '+' mark will be added to $projname
385 # there and a 'forks' view will be enabled for the project, listing
386 # all the forks. If project list is taken from a file, forks have
387 # to be listed after the main project.
389 # To enable system wide have in $GITWEB_CONFIG
390 # $feature{'forks'}{'default'} = [1];
391 # Project specific override is not supported.
396 # Insert custom links to the action bar of all project pages.
397 # This enables you mainly to link to third-party scripts integrating
398 # into gitweb; e.g. git-browser for graphical history representation
399 # or custom web-based repository administration interface.
401 # The 'default' value consists of a list of triplets in the form
402 # (label, link, position) where position is the label after which
403 # to insert the link and link is a format string where %n expands
404 # to the project name, %f to the project path within the filesystem,
405 # %h to the current hash (h gitweb parameter) and %b to the current
406 # hash base (hb gitweb parameter); %% expands to %.
408 # To enable system wide have in $GITWEB_CONFIG e.g.
409 # $feature{'actions'}{'default'} = [('graphiclog',
410 # '/git-browser/by-commit.html?r=%n', 'summary')];
411 # Project specific override is not supported.
416 # Allow gitweb scan project content tags described in ctags/
417 # of project repository, and display the popular Web 2.0-ish
418 # "tag cloud" near the project list. Note that this is something
419 # COMPLETELY different from the normal Git tags.
421 # gitweb by itself can show existing tags, but it does not handle
422 # tagging itself; you need an external application for that.
423 # For an example script, check Girocco's cgi/tagproj.cgi.
424 # You may want to install the HTML::TagCloud Perl module to get
425 # a pretty tag cloud instead of just a list of tags.
427 # To enable system wide have in $GITWEB_CONFIG
428 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
429 # Project specific override is not supported.
434 # The maximum number of patches in a patchset generated in patch
435 # view. Set this to 0 or undef to disable patch view, or to a
436 # negative number to remove any limit.
438 # To disable system wide have in $GITWEB_CONFIG
439 # $feature{'patches'}{'default'} = [0];
440 # To have project specific config enable override in $GITWEB_CONFIG
441 # $feature{'patches'}{'override'} = 1;
442 # and in project config gitweb.patches = 0|n;
443 # where n is the maximum number of patches allowed in a patchset.
445 'sub' => \
&feature_patches
,
449 # Avatar support. When this feature is enabled, views such as
450 # shortlog or commit will display an avatar associated with
451 # the email of the committer(s) and/or author(s).
453 # Currently available providers are gravatar and picon.
454 # If an unknown provider is specified, the feature is disabled.
456 # Gravatar depends on Digest::MD5.
457 # Picon currently relies on the indiana.edu database.
459 # To enable system wide have in $GITWEB_CONFIG
460 # $feature{'avatar'}{'default'} = ['<provider>'];
461 # where <provider> is either gravatar or picon.
462 # To have project specific config enable override in $GITWEB_CONFIG
463 # $feature{'avatar'}{'override'} = 1;
464 # and in project config gitweb.avatar = <provider>;
466 'sub' => \
&feature_avatar
,
470 # Enable displaying how much time and how many git commands
471 # it took to generate and display page. Disabled by default.
472 # Project specific override is not supported.
477 # Enable turning some links into links to actions which require
478 # JavaScript to run (like 'blame_incremental'). Not enabled by
479 # default. Project specific override is currently not supported.
480 'javascript-actions' => {
484 # Syntax highlighting support. This is based on Daniel Svensson's
485 # and Sham Chukoury's work in gitweb-xmms2.git.
486 # It requires the 'highlight' program present in $PATH,
487 # and therefore is disabled by default.
489 # To enable system wide have in $GITWEB_CONFIG
490 # $feature{'highlight'}{'default'} = [1];
493 'sub' => sub { feature_bool
('highlight', @_) },
497 # Enable displaying of remote heads in the heads list
499 # To enable system wide have in $GITWEB_CONFIG
500 # $feature{'remote_heads'}{'default'} = [1];
501 # To have project specific config enable override in $GITWEB_CONFIG
502 # $feature{'remote_heads'}{'override'} = 1;
503 # and in project config gitweb.remote_heads = 0|1;
505 'sub' => sub { feature_bool
('remote_heads', @_) },
510 sub gitweb_get_feature
{
512 return unless exists $feature{$name};
513 my ($sub, $override, @defaults) = (
514 $feature{$name}{'sub'},
515 $feature{$name}{'override'},
516 @
{$feature{$name}{'default'}});
517 # project specific override is possible only if we have project
518 our $git_dir; # global variable, declared later
519 if (!$override || !defined $git_dir) {
523 warn "feature $name is not overridable";
526 return $sub->(@defaults);
529 # A wrapper to check if a given feature is enabled.
530 # With this, you can say
532 # my $bool_feat = gitweb_check_feature('bool_feat');
533 # gitweb_check_feature('bool_feat') or somecode;
537 # my ($bool_feat) = gitweb_get_feature('bool_feat');
538 # (gitweb_get_feature('bool_feat'))[0] or somecode;
540 sub gitweb_check_feature
{
541 return (gitweb_get_feature
(@_))[0];
547 my ($val) = git_get_project_config
($key, '--bool');
551 } elsif ($val eq 'true') {
553 } elsif ($val eq 'false') {
558 sub feature_snapshot
{
561 my ($val) = git_get_project_config
('snapshot');
564 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
570 sub feature_patches
{
571 my @val = (git_get_project_config
('patches', '--int'));
581 my @val = (git_get_project_config
('avatar'));
583 return @val ?
@val : @_;
586 # checking HEAD file with -e is fragile if the repository was
587 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
589 sub check_head_link
{
591 my $headfile = "$dir/HEAD";
592 return ((-e
$headfile) ||
593 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
596 sub check_export_ok
{
598 return (check_head_link
($dir) &&
599 (!$export_ok || -e
"$dir/$export_ok") &&
600 (!$export_auth_hook || $export_auth_hook->($dir)));
603 # process alternate names for backward compatibility
604 # filter out unsupported (unknown) snapshot formats
605 sub filter_snapshot_fmts
{
609 exists $known_snapshot_format_aliases{$_} ?
610 $known_snapshot_format_aliases{$_} : $_} @fmts;
612 exists $known_snapshot_formats{$_} &&
613 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
616 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
617 sub evaluate_gitweb_config
{
618 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
619 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
620 # die if there are errors parsing config file
621 if (-e
$GITWEB_CONFIG) {
624 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
625 do $GITWEB_CONFIG_SYSTEM;
630 # Get loadavg of system, to compare against $maxload.
631 # Currently it requires '/proc/loadavg' present to get loadavg;
632 # if it is not present it returns 0, which means no load checking.
634 if( -e
'/proc/loadavg' ){
635 open my $fd, '<', '/proc/loadavg'
637 my @load = split(/\s+/, scalar <$fd>);
640 # The first three columns measure CPU and IO utilization of the last one,
641 # five, and 10 minute periods. The fourth column shows the number of
642 # currently running processes and the total number of processes in the m/n
643 # format. The last column displays the last process ID used.
644 return $load[0] || 0;
646 # additional checks for load average should go here for things that don't export
652 # version of the core git binary
654 sub evaluate_git_version
{
655 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
656 $number_of_git_cmds++;
660 if (defined $maxload && get_loadavg
() > $maxload) {
661 die_error
(503, "The load average on the server is too high");
665 # ======================================================================
666 # input validation and dispatch
668 # input parameters can be collected from a variety of sources (presently, CGI
669 # and PATH_INFO), so we define an %input_params hash that collects them all
670 # together during validation: this allows subsequent uses (e.g. href()) to be
671 # agnostic of the parameter origin
673 our %input_params = ();
675 # input parameters are stored with the long parameter name as key. This will
676 # also be used in the href subroutine to convert parameters to their CGI
677 # equivalent, and since the href() usage is the most frequent one, we store
678 # the name -> CGI key mapping here, instead of the reverse.
680 # XXX: Warning: If you touch this, check the search form for updating,
683 our @cgi_param_mapping = (
691 hash_parent_base
=> "hpb",
696 snapshot_format
=> "sf",
697 extra_options
=> "opt",
698 search_use_regexp
=> "sr",
699 # this must be last entry (for manipulation from JavaScript)
702 our %cgi_param_mapping = @cgi_param_mapping;
704 # we will also need to know the possible actions, for validation
706 "blame" => \
&git_blame
,
707 "blame_incremental" => \
&git_blame_incremental
,
708 "blame_data" => \
&git_blame_data
,
709 "blobdiff" => \
&git_blobdiff
,
710 "blobdiff_plain" => \
&git_blobdiff_plain
,
711 "blob" => \
&git_blob
,
712 "blob_plain" => \
&git_blob_plain
,
713 "commitdiff" => \
&git_commitdiff
,
714 "commitdiff_plain" => \
&git_commitdiff_plain
,
715 "commit" => \
&git_commit
,
716 "forks" => \
&git_forks
,
717 "heads" => \
&git_heads
,
718 "history" => \
&git_history
,
720 "patch" => \
&git_patch
,
721 "patches" => \
&git_patches
,
722 "remotes" => \
&git_remotes
,
724 "atom" => \
&git_atom
,
725 "search" => \
&git_search
,
726 "search_help" => \
&git_search_help
,
727 "shortlog" => \
&git_shortlog
,
728 "summary" => \
&git_summary
,
730 "tags" => \
&git_tags
,
731 "tree" => \
&git_tree
,
732 "snapshot" => \
&git_snapshot
,
733 "object" => \
&git_object
,
734 # those below don't need $project
735 "opml" => \
&git_opml
,
736 "project_list" => \
&git_project_list
,
737 "project_index" => \
&git_project_index
,
740 # finally, we have the hash of allowed extra_options for the commands that
742 our %allowed_options = (
743 "--no-merges" => [ qw(rss atom log shortlog history) ],
746 # fill %input_params with the CGI parameters. All values except for 'opt'
747 # should be single values, but opt can be an array. We should probably
748 # build an array of parameters that can be multi-valued, but since for the time
749 # being it's only this one, we just single it out
750 sub evaluate_query_params
{
753 while (my ($name, $symbol) = each %cgi_param_mapping) {
754 if ($symbol eq 'opt') {
755 $input_params{$name} = [ $cgi->param($symbol) ];
757 $input_params{$name} = $cgi->param($symbol);
762 # now read PATH_INFO and update the parameter list for missing parameters
763 sub evaluate_path_info
{
764 return if defined $input_params{'project'};
765 return if !$path_info;
766 $path_info =~ s
,^/+,,;
767 return if !$path_info;
769 # find which part of PATH_INFO is project
770 my $project = $path_info;
772 while ($project && !check_head_link
("$projectroot/$project")) {
773 $project =~ s
,/*[^/]*$,,;
775 return unless $project;
776 $input_params{'project'} = $project;
778 # do not change any parameters if an action is given using the query string
779 return if $input_params{'action'};
780 $path_info =~ s
,^\Q
$project\E
/*,,;
782 # next, check if we have an action
783 my $action = $path_info;
785 if (exists $actions{$action}) {
786 $path_info =~ s
,^$action/*,,;
787 $input_params{'action'} = $action;
790 # list of actions that want hash_base instead of hash, but can have no
791 # pathname (f) parameter
797 # we want to catch, among others
798 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
799 my ($parentrefname, $parentpathname, $refname, $pathname) =
800 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);
802 # first, analyze the 'current' part
803 if (defined $pathname) {
804 # we got "branch:filename" or "branch:dir/"
805 # we could use git_get_type(branch:pathname), but:
806 # - it needs $git_dir
807 # - it does a git() call
808 # - the convention of terminating directories with a slash
809 # makes it superfluous
810 # - embedding the action in the PATH_INFO would make it even
812 $pathname =~ s
,^/+,,;
813 if (!$pathname || substr($pathname, -1) eq "/") {
814 $input_params{'action'} ||= "tree";
817 # the default action depends on whether we had parent info
819 if ($parentrefname) {
820 $input_params{'action'} ||= "blobdiff_plain";
822 $input_params{'action'} ||= "blob_plain";
825 $input_params{'hash_base'} ||= $refname;
826 $input_params{'file_name'} ||= $pathname;
827 } elsif (defined $refname) {
828 # we got "branch". In this case we have to choose if we have to
829 # set hash or hash_base.
831 # Most of the actions without a pathname only want hash to be
832 # set, except for the ones specified in @wants_base that want
833 # hash_base instead. It should also be noted that hand-crafted
834 # links having 'history' as an action and no pathname or hash
835 # set will fail, but that happens regardless of PATH_INFO.
836 if (defined $parentrefname) {
837 # if there is parent let the default be 'shortlog' action
838 # (for http://git.example.com/repo.git/A..B links); if there
839 # is no parent, dispatch will detect type of object and set
840 # action appropriately if required (if action is not set)
841 $input_params{'action'} ||= "shortlog";
843 if ($input_params{'action'} &&
844 grep { $_ eq $input_params{'action'} } @wants_base) {
845 $input_params{'hash_base'} ||= $refname;
847 $input_params{'hash'} ||= $refname;
851 # next, handle the 'parent' part, if present
852 if (defined $parentrefname) {
853 # a missing pathspec defaults to the 'current' filename, allowing e.g.
854 # someproject/blobdiff/oldrev..newrev:/filename
855 if ($parentpathname) {
856 $parentpathname =~ s
,^/+,,;
857 $parentpathname =~ s
,/$,,;
858 $input_params{'file_parent'} ||= $parentpathname;
860 $input_params{'file_parent'} ||= $input_params{'file_name'};
862 # we assume that hash_parent_base is wanted if a path was specified,
863 # or if the action wants hash_base instead of hash
864 if (defined $input_params{'file_parent'} ||
865 grep { $_ eq $input_params{'action'} } @wants_base) {
866 $input_params{'hash_parent_base'} ||= $parentrefname;
868 $input_params{'hash_parent'} ||= $parentrefname;
872 # for the snapshot action, we allow URLs in the form
873 # $project/snapshot/$hash.ext
874 # where .ext determines the snapshot and gets removed from the
875 # passed $refname to provide the $hash.
877 # To be able to tell that $refname includes the format extension, we
878 # require the following two conditions to be satisfied:
879 # - the hash input parameter MUST have been set from the $refname part
880 # of the URL (i.e. they must be equal)
881 # - the snapshot format MUST NOT have been defined already (e.g. from
883 # It's also useless to try any matching unless $refname has a dot,
884 # so we check for that too
885 if (defined $input_params{'action'} &&
886 $input_params{'action'} eq 'snapshot' &&
887 defined $refname && index($refname, '.') != -1 &&
888 $refname eq $input_params{'hash'} &&
889 !defined $input_params{'snapshot_format'}) {
890 # We loop over the known snapshot formats, checking for
891 # extensions. Allowed extensions are both the defined suffix
892 # (which includes the initial dot already) and the snapshot
893 # format key itself, with a prepended dot
894 while (my ($fmt, $opt) = each %known_snapshot_formats) {
896 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
900 # a valid suffix was found, so set the snapshot format
901 # and reset the hash parameter
902 $input_params{'snapshot_format'} = $fmt;
903 $input_params{'hash'} = $hash;
904 # we also set the format suffix to the one requested
905 # in the URL: this way a request for e.g. .tgz returns
906 # a .tgz instead of a .tar.gz
907 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
913 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
914 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
915 $searchtext, $search_regexp);
916 sub evaluate_and_validate_params
{
917 our $action = $input_params{'action'};
918 if (defined $action) {
919 if (!validate_action
($action)) {
920 die_error
(400, "Invalid action parameter");
924 # parameters which are pathnames
925 our $project = $input_params{'project'};
926 if (defined $project) {
927 if (!validate_project
($project)) {
929 die_error
(404, "No such project");
933 our $file_name = $input_params{'file_name'};
934 if (defined $file_name) {
935 if (!validate_pathname
($file_name)) {
936 die_error
(400, "Invalid file parameter");
940 our $file_parent = $input_params{'file_parent'};
941 if (defined $file_parent) {
942 if (!validate_pathname
($file_parent)) {
943 die_error
(400, "Invalid file parent parameter");
947 # parameters which are refnames
948 our $hash = $input_params{'hash'};
950 if (!validate_refname
($hash)) {
951 die_error
(400, "Invalid hash parameter");
955 our $hash_parent = $input_params{'hash_parent'};
956 if (defined $hash_parent) {
957 if (!validate_refname
($hash_parent)) {
958 die_error
(400, "Invalid hash parent parameter");
962 our $hash_base = $input_params{'hash_base'};
963 if (defined $hash_base) {
964 if (!validate_refname
($hash_base)) {
965 die_error
(400, "Invalid hash base parameter");
969 our @extra_options = @
{$input_params{'extra_options'}};
970 # @extra_options is always defined, since it can only be (currently) set from
971 # CGI, and $cgi->param() returns the empty array in array context if the param
973 foreach my $opt (@extra_options) {
974 if (not exists $allowed_options{$opt}) {
975 die_error
(400, "Invalid option parameter");
977 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
978 die_error
(400, "Invalid option parameter for this action");
982 our $hash_parent_base = $input_params{'hash_parent_base'};
983 if (defined $hash_parent_base) {
984 if (!validate_refname
($hash_parent_base)) {
985 die_error
(400, "Invalid hash parent base parameter");
990 our $page = $input_params{'page'};
992 if ($page =~ m/[^0-9]/) {
993 die_error
(400, "Invalid page parameter");
997 our $searchtype = $input_params{'searchtype'};
998 if (defined $searchtype) {
999 if ($searchtype =~ m/[^a-z]/) {
1000 die_error
(400, "Invalid searchtype parameter");
1004 our $search_use_regexp = $input_params{'search_use_regexp'};
1006 our $searchtext = $input_params{'searchtext'};
1008 if (defined $searchtext) {
1009 if (length($searchtext) < 2) {
1010 die_error
(403, "At least two characters are required for search parameter");
1012 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
1016 # path to the current git repository
1018 sub evaluate_git_dir
{
1019 our $git_dir = "$projectroot/$project" if $project;
1022 our (@snapshot_fmts, $git_avatar);
1023 sub configure_gitweb_features
{
1024 # list of supported snapshot formats
1025 our @snapshot_fmts = gitweb_get_feature
('snapshot');
1026 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1028 # check that the avatar feature is set to a known provider name,
1029 # and for each provider check if the dependencies are satisfied.
1030 # if the provider name is invalid or the dependencies are not met,
1031 # reset $git_avatar to the empty string.
1032 our ($git_avatar) = gitweb_get_feature
('avatar');
1033 if ($git_avatar eq 'gravatar') {
1034 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
1035 } elsif ($git_avatar eq 'picon') {
1042 # custom error handler: 'die <message>' is Internal Server Error
1043 sub handle_errors_html
{
1044 my $msg = shift; # it is already HTML escaped
1046 # to avoid infinite loop where error occurs in die_error,
1047 # change handler to default handler, disabling handle_errors_html
1048 set_message
("Error occured when inside die_error:\n$msg");
1050 # you cannot jump out of die_error when called as error handler;
1051 # the subroutine set via CGI::Carp::set_message is called _after_
1052 # HTTP headers are already written, so it cannot write them itself
1053 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1055 set_message
(\
&handle_errors_html
);
1059 if (!defined $action) {
1060 if (defined $hash) {
1061 $action = git_get_type
($hash);
1062 } elsif (defined $hash_base && defined $file_name) {
1063 $action = git_get_type
("$hash_base:$file_name");
1064 } elsif (defined $project) {
1065 $action = 'summary';
1067 $action = 'project_list';
1070 if (!defined($actions{$action})) {
1071 die_error
(400, "Unknown action");
1073 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1075 die_error
(400, "Project needed");
1077 $actions{$action}->();
1081 our $t0 = [Time
::HiRes
::gettimeofday
()]
1083 our $number_of_git_cmds = 0;
1090 evaluate_gitweb_config
();
1093 # $projectroot and $projects_list might be set in gitweb config file
1094 $projects_list ||= $projectroot;
1096 evaluate_query_params
();
1097 evaluate_path_info
();
1098 evaluate_and_validate_params
();
1101 configure_gitweb_features
();
1106 our $is_last_request = sub { 1 };
1107 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1110 sub configure_as_fcgi
{
1112 our $CGI = 'CGI::Fast';
1114 my $request_number = 0;
1115 # let each child service 100 requests
1116 our $is_last_request = sub { ++$request_number > 100 };
1119 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1121 if $script_name =~ /\.fcgi$/;
1123 return unless (@ARGV);
1125 require Getopt
::Long
;
1126 Getopt
::Long
::GetOptions
(
1127 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1128 'nproc|n=i' => sub {
1129 my ($arg, $val) = @_;
1130 return unless eval { require FCGI
::ProcManager
; 1; };
1131 my $proc_manager = FCGI
::ProcManager
->new({
1132 n_processes
=> $val,
1134 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1135 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1136 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1143 evaluate_git_version
();
1145 $pre_listen_hook->()
1146 if $pre_listen_hook;
1149 while ($cgi = $CGI->new()) {
1150 $pre_dispatch_hook->()
1151 if $pre_dispatch_hook;
1155 $post_dispatch_hook->()
1156 if $post_dispatch_hook;
1158 last REQUEST
if ($is_last_request->());
1167 if (defined caller) {
1168 # wrapped in a subroutine processing requests,
1169 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1172 # pure CGI script, serving single request
1176 ## ======================================================================
1179 # possible values of extra options
1180 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1181 # -replay => 1 - start from a current view (replay with modifications)
1182 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1185 # default is to use -absolute url() i.e. $my_uri
1186 my $href = $params{-full
} ?
$my_url : $my_uri;
1188 $params{'project'} = $project unless exists $params{'project'};
1190 if ($params{-replay
}) {
1191 while (my ($name, $symbol) = each %cgi_param_mapping) {
1192 if (!exists $params{$name}) {
1193 $params{$name} = $input_params{$name};
1198 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1199 if (defined $params{'project'} &&
1200 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1201 # try to put as many parameters as possible in PATH_INFO:
1204 # - hash_parent or hash_parent_base:/file_parent
1205 # - hash or hash_base:/filename
1206 # - the snapshot_format as an appropriate suffix
1208 # When the script is the root DirectoryIndex for the domain,
1209 # $href here would be something like http://gitweb.example.com/
1210 # Thus, we strip any trailing / from $href, to spare us double
1211 # slashes in the final URL
1214 # Then add the project name, if present
1215 $href .= "/".esc_url
($params{'project'});
1216 delete $params{'project'};
1218 # since we destructively absorb parameters, we keep this
1219 # boolean that remembers if we're handling a snapshot
1220 my $is_snapshot = $params{'action'} eq 'snapshot';
1222 # Summary just uses the project path URL, any other action is
1224 if (defined $params{'action'}) {
1225 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1226 delete $params{'action'};
1229 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1230 # stripping nonexistent or useless pieces
1231 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1232 || $params{'hash_parent'} || $params{'hash'});
1233 if (defined $params{'hash_base'}) {
1234 if (defined $params{'hash_parent_base'}) {
1235 $href .= esc_url
($params{'hash_parent_base'});
1236 # skip the file_parent if it's the same as the file_name
1237 if (defined $params{'file_parent'}) {
1238 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1239 delete $params{'file_parent'};
1240 } elsif ($params{'file_parent'} !~ /\.\./) {
1241 $href .= ":/".esc_url
($params{'file_parent'});
1242 delete $params{'file_parent'};
1246 delete $params{'hash_parent'};
1247 delete $params{'hash_parent_base'};
1248 } elsif (defined $params{'hash_parent'}) {
1249 $href .= esc_url
($params{'hash_parent'}). "..";
1250 delete $params{'hash_parent'};
1253 $href .= esc_url
($params{'hash_base'});
1254 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1255 $href .= ":/".esc_url
($params{'file_name'});
1256 delete $params{'file_name'};
1258 delete $params{'hash'};
1259 delete $params{'hash_base'};
1260 } elsif (defined $params{'hash'}) {
1261 $href .= esc_url
($params{'hash'});
1262 delete $params{'hash'};
1265 # If the action was a snapshot, we can absorb the
1266 # snapshot_format parameter too
1268 my $fmt = $params{'snapshot_format'};
1269 # snapshot_format should always be defined when href()
1270 # is called, but just in case some code forgets, we
1271 # fall back to the default
1272 $fmt ||= $snapshot_fmts[0];
1273 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1274 delete $params{'snapshot_format'};
1278 # now encode the parameters explicitly
1280 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1281 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1282 if (defined $params{$name}) {
1283 if (ref($params{$name}) eq "ARRAY") {
1284 foreach my $par (@
{$params{$name}}) {
1285 push @result, $symbol . "=" . esc_param
($par);
1288 push @result, $symbol . "=" . esc_param
($params{$name});
1292 $href .= "?" . join(';', @result) if scalar @result;
1298 ## ======================================================================
1299 ## validation, quoting/unquoting and escaping
1301 sub validate_action
{
1302 my $input = shift || return undef;
1303 return undef unless exists $actions{$input};
1307 sub validate_project
{
1308 my $input = shift || return undef;
1309 if (!validate_pathname
($input) ||
1310 !(-d
"$projectroot/$input") ||
1311 !check_export_ok
("$projectroot/$input") ||
1312 ($strict_export && !project_in_list
($input))) {
1319 sub validate_pathname
{
1320 my $input = shift || return undef;
1322 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1323 # at the beginning, at the end, and between slashes.
1324 # also this catches doubled slashes
1325 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1328 # no null characters
1329 if ($input =~ m!\0!) {
1335 sub validate_refname
{
1336 my $input = shift || return undef;
1338 # textual hashes are O.K.
1339 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1342 # it must be correct pathname
1343 $input = validate_pathname
($input)
1345 # restrictions on ref name according to git-check-ref-format
1346 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1352 # decode sequences of octets in utf8 into Perl's internal form,
1353 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1354 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1357 return undef unless defined $str;
1358 if (utf8
::valid
($str)) {
1362 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1366 # quote unsafe chars, but keep the slash, even when it's not
1367 # correct, but quoted slashes look too horrible in bookmarks
1370 return undef unless defined $str;
1371 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1376 # quote unsafe chars in whole URL, so some characters cannot be quoted
1379 return undef unless defined $str;
1380 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1385 # replace invalid utf8 character with SUBSTITUTION sequence
1390 return undef unless defined $str;
1392 $str = to_utf8
($str);
1393 $str = $cgi->escapeHTML($str);
1394 if ($opts{'-nbsp'}) {
1395 $str =~ s/ / /g;
1397 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1401 # quote control characters and escape filename to HTML
1406 return undef unless defined $str;
1408 $str = to_utf8
($str);
1409 $str = $cgi->escapeHTML($str);
1410 if ($opts{'-nbsp'}) {
1411 $str =~ s/ / /g;
1413 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1417 # Make control characters "printable", using character escape codes (CEC)
1421 my %es = ( # character escape codes, aka escape sequences
1422 "\t" => '\t', # tab (HT)
1423 "\n" => '\n', # line feed (LF)
1424 "\r" => '\r', # carrige return (CR)
1425 "\f" => '\f', # form feed (FF)
1426 "\b" => '\b', # backspace (BS)
1427 "\a" => '\a', # alarm (bell) (BEL)
1428 "\e" => '\e', # escape (ESC)
1429 "\013" => '\v', # vertical tab (VT)
1430 "\000" => '\0', # nul character (NUL)
1432 my $chr = ( (exists $es{$cntrl})
1434 : sprintf('\%2x', ord($cntrl)) );
1435 if ($opts{-nohtml
}) {
1438 return "<span class=\"cntrl\">$chr</span>";
1442 # Alternatively use unicode control pictures codepoints,
1443 # Unicode "printable representation" (PR)
1448 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1449 if ($opts{-nohtml
}) {
1452 return "<span class=\"cntrl\">$chr</span>";
1456 # git may return quoted and escaped filenames
1462 my %es = ( # character escape codes, aka escape sequences
1463 't' => "\t", # tab (HT, TAB)
1464 'n' => "\n", # newline (NL)
1465 'r' => "\r", # return (CR)
1466 'f' => "\f", # form feed (FF)
1467 'b' => "\b", # backspace (BS)
1468 'a' => "\a", # alarm (bell) (BEL)
1469 'e' => "\e", # escape (ESC)
1470 'v' => "\013", # vertical tab (VT)
1473 if ($seq =~ m/^[0-7]{1,3}$/) {
1474 # octal char sequence
1475 return chr(oct($seq));
1476 } elsif (exists $es{$seq}) {
1477 # C escape sequence, aka character escape code
1480 # quoted ordinary character
1484 if ($str =~ m/^"(.*)"$/) {
1487 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1492 # escape tabs (convert tabs to spaces)
1496 while ((my $pos = index($line, "\t")) != -1) {
1497 if (my $count = (8 - ($pos % 8))) {
1498 my $spaces = ' ' x
$count;
1499 $line =~ s/\t/$spaces/;
1506 sub project_in_list
{
1507 my $project = shift;
1508 my @list = git_get_projects_list
();
1509 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1512 ## ----------------------------------------------------------------------
1513 ## HTML aware string manipulation
1515 # Try to chop given string on a word boundary between position
1516 # $len and $len+$add_len. If there is no word boundary there,
1517 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1518 # (marking chopped part) would be longer than given string.
1522 my $add_len = shift || 10;
1523 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1525 # Make sure perl knows it is utf8 encoded so we don't
1526 # cut in the middle of a utf8 multibyte char.
1527 $str = to_utf8
($str);
1529 # allow only $len chars, but don't cut a word if it would fit in $add_len
1530 # if it doesn't fit, cut it if it's still longer than the dots we would add
1531 # remove chopped character entities entirely
1533 # when chopping in the middle, distribute $len into left and right part
1534 # return early if chopping wouldn't make string shorter
1535 if ($where eq 'center') {
1536 return $str if ($len + 5 >= length($str)); # filler is length 5
1539 return $str if ($len + 4 >= length($str)); # filler is length 4
1542 # regexps: ending and beginning with word part up to $add_len
1543 my $endre = qr/.{$len}\w{0,$add_len}/;
1544 my $begre = qr/\w{0,$add_len}.{$len}/;
1546 if ($where eq 'left') {
1547 $str =~ m/^(.*?)($begre)$/;
1548 my ($lead, $body) = ($1, $2);
1549 if (length($lead) > 4) {
1552 return "$lead$body";
1554 } elsif ($where eq 'center') {
1555 $str =~ m/^($endre)(.*)$/;
1556 my ($left, $str) = ($1, $2);
1557 $str =~ m/^(.*?)($begre)$/;
1558 my ($mid, $right) = ($1, $2);
1559 if (length($mid) > 5) {
1562 return "$left$mid$right";
1565 $str =~ m/^($endre)(.*)$/;
1568 if (length($tail) > 4) {
1571 return "$body$tail";
1575 # takes the same arguments as chop_str, but also wraps a <span> around the
1576 # result with a title attribute if it does get chopped. Additionally, the
1577 # string is HTML-escaped.
1578 sub chop_and_escape_str
{
1581 my $chopped = chop_str
(@_);
1582 if ($chopped eq $str) {
1583 return esc_html
($chopped);
1585 $str =~ s/[[:cntrl:]]/?/g;
1586 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1590 ## ----------------------------------------------------------------------
1591 ## functions returning short strings
1593 # CSS class for given age value (in seconds)
1597 if (!defined $age) {
1599 } elsif ($age < 60*60*2) {
1601 } elsif ($age < 60*60*24*2) {
1608 # convert age in seconds to "nn units ago" string
1613 if ($age > 60*60*24*365*2) {
1614 $age_str = (int $age/60/60/24/365);
1615 $age_str .= " years ago";
1616 } elsif ($age > 60*60*24*(365/12)*2) {
1617 $age_str = int $age/60/60/24/(365/12);
1618 $age_str .= " months ago";
1619 } elsif ($age > 60*60*24*7*2) {
1620 $age_str = int $age/60/60/24/7;
1621 $age_str .= " weeks ago";
1622 } elsif ($age > 60*60*24*2) {
1623 $age_str = int $age/60/60/24;
1624 $age_str .= " days ago";
1625 } elsif ($age > 60*60*2) {
1626 $age_str = int $age/60/60;
1627 $age_str .= " hours ago";
1628 } elsif ($age > 60*2) {
1629 $age_str = int $age/60;
1630 $age_str .= " min ago";
1631 } elsif ($age > 2) {
1632 $age_str = int $age;
1633 $age_str .= " sec ago";
1635 $age_str .= " right now";
1641 S_IFINVALID
=> 0030000,
1642 S_IFGITLINK
=> 0160000,
1645 # submodule/subproject, a commit object reference
1649 return (($mode & S_IFMT
) == S_IFGITLINK
)
1652 # convert file mode in octal to symbolic file mode string
1654 my $mode = oct shift;
1656 if (S_ISGITLINK
($mode)) {
1657 return 'm---------';
1658 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1659 return 'drwxr-xr-x';
1660 } elsif (S_ISLNK
($mode)) {
1661 return 'lrwxrwxrwx';
1662 } elsif (S_ISREG
($mode)) {
1663 # git cares only about the executable bit
1664 if ($mode & S_IXUSR
) {
1665 return '-rwxr-xr-x';
1667 return '-rw-r--r--';
1670 return '----------';
1674 # convert file mode in octal to file type string
1678 if ($mode !~ m/^[0-7]+$/) {
1684 if (S_ISGITLINK
($mode)) {
1686 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1688 } elsif (S_ISLNK
($mode)) {
1690 } elsif (S_ISREG
($mode)) {
1697 # convert file mode in octal to file type description string
1698 sub file_type_long
{
1701 if ($mode !~ m/^[0-7]+$/) {
1707 if (S_ISGITLINK
($mode)) {
1709 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1711 } elsif (S_ISLNK
($mode)) {
1713 } elsif (S_ISREG
($mode)) {
1714 if ($mode & S_IXUSR
) {
1715 return "executable";
1725 ## ----------------------------------------------------------------------
1726 ## functions returning short HTML fragments, or transforming HTML fragments
1727 ## which don't belong to other sections
1729 # format line of commit message.
1730 sub format_log_line_html
{
1733 $line = esc_html
($line, -nbsp
=>1);
1734 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1735 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1736 -class => "text"}, $1);
1742 # format marker of refs pointing to given object
1744 # the destination action is chosen based on object type and current context:
1745 # - for annotated tags, we choose the tag view unless it's the current view
1746 # already, in which case we go to shortlog view
1747 # - for other refs, we keep the current view if we're in history, shortlog or
1748 # log view, and select shortlog otherwise
1749 sub format_ref_marker
{
1750 my ($refs, $id) = @_;
1753 if (defined $refs->{$id}) {
1754 foreach my $ref (@
{$refs->{$id}}) {
1755 # this code exploits the fact that non-lightweight tags are the
1756 # only indirect objects, and that they are the only objects for which
1757 # we want to use tag instead of shortlog as action
1758 my ($type, $name) = qw();
1759 my $indirect = ($ref =~ s/\^\{\}$//);
1760 # e.g. tags/v2.6.11 or heads/next
1761 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1770 $class .= " indirect" if $indirect;
1772 my $dest_action = "shortlog";
1775 $dest_action = "tag" unless $action eq "tag";
1776 } elsif ($action =~ /^(history|(short)?log)$/) {
1777 $dest_action = $action;
1781 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1784 my $link = $cgi->a({
1786 action
=>$dest_action,
1790 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1796 return ' <span class="refs">'. $markers . '</span>';
1802 # format, perhaps shortened and with markers, title line
1803 sub format_subject_html
{
1804 my ($long, $short, $href, $extra) = @_;
1805 $extra = '' unless defined($extra);
1807 if (length($short) < length($long)) {
1808 $long =~ s/[[:cntrl:]]/?/g;
1809 return $cgi->a({-href
=> $href, -class => "list subject",
1810 -title
=> to_utf8
($long)},
1811 esc_html
($short)) . $extra;
1813 return $cgi->a({-href
=> $href, -class => "list subject"},
1814 esc_html
($long)) . $extra;
1818 # Rather than recomputing the url for an email multiple times, we cache it
1819 # after the first hit. This gives a visible benefit in views where the avatar
1820 # for the same email is used repeatedly (e.g. shortlog).
1821 # The cache is shared by all avatar engines (currently gravatar only), which
1822 # are free to use it as preferred. Since only one avatar engine is used for any
1823 # given page, there's no risk for cache conflicts.
1824 our %avatar_cache = ();
1826 # Compute the picon url for a given email, by using the picon search service over at
1827 # http://www.cs.indiana.edu/picons/search.html
1829 my $email = lc shift;
1830 if (!$avatar_cache{$email}) {
1831 my ($user, $domain) = split('@', $email);
1832 $avatar_cache{$email} =
1833 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1835 "users+domains+unknown/up/single";
1837 return $avatar_cache{$email};
1840 # Compute the gravatar url for a given email, if it's not in the cache already.
1841 # Gravatar stores only the part of the URL before the size, since that's the
1842 # one computationally more expensive. This also allows reuse of the cache for
1843 # different sizes (for this particular engine).
1845 my $email = lc shift;
1847 $avatar_cache{$email} ||=
1848 "http://www.gravatar.com/avatar/" .
1849 Digest
::MD5
::md5_hex
($email) . "?s=";
1850 return $avatar_cache{$email} . $size;
1853 # Insert an avatar for the given $email at the given $size if the feature
1855 sub git_get_avatar
{
1856 my ($email, %opts) = @_;
1857 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1858 my $post_white = ($opts{-pad_after
} ?
" " : "");
1859 $opts{-size
} ||= 'default';
1860 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1862 if ($git_avatar eq 'gravatar') {
1863 $url = gravatar_url
($email, $size);
1864 } elsif ($git_avatar eq 'picon') {
1865 $url = picon_url
($email);
1867 # Other providers can be added by extending the if chain, defining $url
1868 # as needed. If no variant puts something in $url, we assume avatars
1869 # are completely disabled/unavailable.
1872 "<img width=\"$size\" " .
1873 "class=\"avatar\" " .
1882 sub format_search_author
{
1883 my ($author, $searchtype, $displaytext) = @_;
1884 my $have_search = gitweb_check_feature
('search');
1888 if ($searchtype eq 'author') {
1889 $performed = "authored";
1890 } elsif ($searchtype eq 'committer') {
1891 $performed = "committed";
1894 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1895 searchtext
=>$author,
1896 searchtype
=>$searchtype), class=>"list",
1897 title
=>"Search for commits $performed by $author"},
1901 return $displaytext;
1905 # format the author name of the given commit with the given tag
1906 # the author name is chopped and escaped according to the other
1907 # optional parameters (see chop_str).
1908 sub format_author_html
{
1911 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1912 return "<$tag class=\"author\">" .
1913 format_search_author
($co->{'author_name'}, "author",
1914 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1919 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1920 sub format_git_diff_header_line
{
1922 my $diffinfo = shift;
1923 my ($from, $to) = @_;
1925 if ($diffinfo->{'nparents'}) {
1927 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1928 if ($to->{'href'}) {
1929 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1930 esc_path
($to->{'file'}));
1931 } else { # file was deleted (no href)
1932 $line .= esc_path
($to->{'file'});
1936 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1937 if ($from->{'href'}) {
1938 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1939 'a/' . esc_path
($from->{'file'}));
1940 } else { # file was added (no href)
1941 $line .= 'a/' . esc_path
($from->{'file'});
1944 if ($to->{'href'}) {
1945 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1946 'b/' . esc_path
($to->{'file'}));
1947 } else { # file was deleted
1948 $line .= 'b/' . esc_path
($to->{'file'});
1952 return "<div class=\"diff header\">$line</div>\n";
1955 # format extended diff header line, before patch itself
1956 sub format_extended_diff_header_line
{
1958 my $diffinfo = shift;
1959 my ($from, $to) = @_;
1962 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1963 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1964 esc_path
($from->{'file'}));
1966 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1967 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1968 esc_path
($to->{'file'}));
1970 # match single <mode>
1971 if ($line =~ m/\s(\d{6})$/) {
1972 $line .= '<span class="info"> (' .
1973 file_type_long
($1) .
1977 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1978 # can match only for combined diff
1980 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1981 if ($from->{'href'}[$i]) {
1982 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1984 substr($diffinfo->{'from_id'}[$i],0,7));
1989 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1992 if ($to->{'href'}) {
1993 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1994 substr($diffinfo->{'to_id'},0,7));
1999 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2000 # can match only for ordinary diff
2001 my ($from_link, $to_link);
2002 if ($from->{'href'}) {
2003 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
2004 substr($diffinfo->{'from_id'},0,7));
2006 $from_link = '0' x
7;
2008 if ($to->{'href'}) {
2009 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2010 substr($diffinfo->{'to_id'},0,7));
2014 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2015 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2018 return $line . "<br/>\n";
2021 # format from-file/to-file diff header
2022 sub format_diff_from_to_header
{
2023 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
2028 #assert($line =~ m/^---/) if DEBUG;
2029 # no extra formatting for "^--- /dev/null"
2030 if (! $diffinfo->{'nparents'}) {
2031 # ordinary (single parent) diff
2032 if ($line =~ m!^--- "?a/!) {
2033 if ($from->{'href'}) {
2035 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2036 esc_path
($from->{'file'}));
2039 esc_path
($from->{'file'});
2042 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2045 # combined diff (merge commit)
2046 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2047 if ($from->{'href'}[$i]) {
2049 $cgi->a({-href
=>href
(action
=>"blobdiff",
2050 hash_parent
=>$diffinfo->{'from_id'}[$i],
2051 hash_parent_base
=>$parents[$i],
2052 file_parent
=>$from->{'file'}[$i],
2053 hash
=>$diffinfo->{'to_id'},
2055 file_name
=>$to->{'file'}),
2057 -title
=>"diff" . ($i+1)},
2060 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2061 esc_path
($from->{'file'}[$i]));
2063 $line = '--- /dev/null';
2065 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2070 #assert($line =~ m/^\+\+\+/) if DEBUG;
2071 # no extra formatting for "^+++ /dev/null"
2072 if ($line =~ m!^\+\+\+ "?b/!) {
2073 if ($to->{'href'}) {
2075 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2076 esc_path
($to->{'file'}));
2079 esc_path
($to->{'file'});
2082 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2087 # create note for patch simplified by combined diff
2088 sub format_diff_cc_simplified
{
2089 my ($diffinfo, @parents) = @_;
2092 $result .= "<div class=\"diff header\">" .
2094 if (!is_deleted
($diffinfo)) {
2095 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2097 hash
=>$diffinfo->{'to_id'},
2098 file_name
=>$diffinfo->{'to_file'}),
2100 esc_path
($diffinfo->{'to_file'}));
2102 $result .= esc_path
($diffinfo->{'to_file'});
2104 $result .= "</div>\n" . # class="diff header"
2105 "<div class=\"diff nodifferences\">" .
2107 "</div>\n"; # class="diff nodifferences"
2112 # format patch (diff) line (not to be used for diff headers)
2113 sub format_diff_line
{
2115 my ($from, $to) = @_;
2116 my $diff_class = "";
2120 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2122 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2123 if ($line =~ m/^\@{3}/) {
2124 $diff_class = " chunk_header";
2125 } elsif ($line =~ m/^\\/) {
2126 $diff_class = " incomplete";
2127 } elsif ($prefix =~ tr/+/+/) {
2128 $diff_class = " add";
2129 } elsif ($prefix =~ tr/-/-/) {
2130 $diff_class = " rem";
2133 # assume ordinary diff
2134 my $char = substr($line, 0, 1);
2136 $diff_class = " add";
2137 } elsif ($char eq '-') {
2138 $diff_class = " rem";
2139 } elsif ($char eq '@') {
2140 $diff_class = " chunk_header";
2141 } elsif ($char eq "\\") {
2142 $diff_class = " incomplete";
2145 $line = untabify
($line);
2146 if ($from && $to && $line =~ m/^\@{2} /) {
2147 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2148 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2150 $from_lines = 0 unless defined $from_lines;
2151 $to_lines = 0 unless defined $to_lines;
2153 if ($from->{'href'}) {
2154 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2155 -class=>"list"}, $from_text);
2157 if ($to->{'href'}) {
2158 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2159 -class=>"list"}, $to_text);
2161 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2162 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2163 return "<div class=\"diff$diff_class\">$line</div>\n";
2164 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2165 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2166 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2168 @from_text = split(' ', $ranges);
2169 for (my $i = 0; $i < @from_text; ++$i) {
2170 ($from_start[$i], $from_nlines[$i]) =
2171 (split(',', substr($from_text[$i], 1)), 0);
2174 $to_text = pop @from_text;
2175 $to_start = pop @from_start;
2176 $to_nlines = pop @from_nlines;
2178 $line = "<span class=\"chunk_info\">$prefix ";
2179 for (my $i = 0; $i < @from_text; ++$i) {
2180 if ($from->{'href'}[$i]) {
2181 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2182 -class=>"list"}, $from_text[$i]);
2184 $line .= $from_text[$i];
2188 if ($to->{'href'}) {
2189 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2190 -class=>"list"}, $to_text);
2194 $line .= " $prefix</span>" .
2195 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2196 return "<div class=\"diff$diff_class\">$line</div>\n";
2198 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2201 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2202 # linked. Pass the hash of the tree/commit to snapshot.
2203 sub format_snapshot_links
{
2205 my $num_fmts = @snapshot_fmts;
2206 if ($num_fmts > 1) {
2207 # A parenthesized list of links bearing format names.
2208 # e.g. "snapshot (_tar.gz_ _zip_)"
2209 return "snapshot (" . join(' ', map
2216 }, $known_snapshot_formats{$_}{'display'})
2217 , @snapshot_fmts) . ")";
2218 } elsif ($num_fmts == 1) {
2219 # A single "snapshot" link whose tooltip bears the format name.
2221 my ($fmt) = @snapshot_fmts;
2227 snapshot_format
=>$fmt
2229 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2231 } else { # $num_fmts == 0
2236 ## ......................................................................
2237 ## functions returning values to be passed, perhaps after some
2238 ## transformation, to other functions; e.g. returning arguments to href()
2240 # returns hash to be passed to href to generate gitweb URL
2241 # in -title key it returns description of link
2243 my $format = shift || 'Atom';
2244 my %res = (action
=> lc($format));
2246 # feed links are possible only for project views
2247 return unless (defined $project);
2248 # some views should link to OPML, or to generic project feed,
2249 # or don't have specific feed yet (so they should use generic)
2250 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2253 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2254 # from tag links; this also makes possible to detect branch links
2255 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2256 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2259 # find log type for feed description (title)
2261 if (defined $file_name) {
2262 $type = "history of $file_name";
2263 $type .= "/" if ($action eq 'tree');
2264 $type .= " on '$branch'" if (defined $branch);
2266 $type = "log of $branch" if (defined $branch);
2269 $res{-title
} = $type;
2270 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2271 $res{'file_name'} = $file_name;
2276 ## ----------------------------------------------------------------------
2277 ## git utility subroutines, invoking git commands
2279 # returns path to the core git executable and the --git-dir parameter as list
2281 $number_of_git_cmds++;
2282 return $GIT, '--git-dir='.$git_dir;
2285 # quote the given arguments for passing them to the shell
2286 # quote_command("command", "arg 1", "arg with ' and ! characters")
2287 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2288 # Try to avoid using this function wherever possible.
2291 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2294 # get HEAD ref of given project as hash
2295 sub git_get_head_hash
{
2296 return git_get_full_hash
(shift, 'HEAD');
2299 sub git_get_full_hash
{
2300 return git_get_hash
(@_);
2303 sub git_get_short_hash
{
2304 return git_get_hash
(@_, '--short=7');
2308 my ($project, $hash, @options) = @_;
2309 my $o_git_dir = $git_dir;
2311 $git_dir = "$projectroot/$project";
2312 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2313 '--verify', '-q', @options, $hash) {
2315 chomp $retval if defined $retval;
2318 if (defined $o_git_dir) {
2319 $git_dir = $o_git_dir;
2324 # get type of given object
2328 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2330 close $fd or return;
2335 # repository configuration
2336 our $config_file = '';
2339 # store multiple values for single key as anonymous array reference
2340 # single values stored directly in the hash, not as [ <value> ]
2341 sub hash_set_multi
{
2342 my ($hash, $key, $value) = @_;
2344 if (!exists $hash->{$key}) {
2345 $hash->{$key} = $value;
2346 } elsif (!ref $hash->{$key}) {
2347 $hash->{$key} = [ $hash->{$key}, $value ];
2349 push @
{$hash->{$key}}, $value;
2353 # return hash of git project configuration
2354 # optionally limited to some section, e.g. 'gitweb'
2355 sub git_parse_project_config
{
2356 my $section_regexp = shift;
2361 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2364 while (my $keyval = <$fh>) {
2366 my ($key, $value) = split(/\n/, $keyval, 2);
2368 hash_set_multi
(\
%config, $key, $value)
2369 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2376 # convert config value to boolean: 'true' or 'false'
2377 # no value, number > 0, 'true' and 'yes' values are true
2378 # rest of values are treated as false (never as error)
2379 sub config_to_bool
{
2382 return 1 if !defined $val; # section.key
2384 # strip leading and trailing whitespace
2388 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2389 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2392 # convert config value to simple decimal number
2393 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2394 # to be multiplied by 1024, 1048576, or 1073741824
2398 # strip leading and trailing whitespace
2402 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2404 # unknown unit is treated as 1
2405 return $num * ($unit eq 'g' ?
1073741824 :
2406 $unit eq 'm' ?
1048576 :
2407 $unit eq 'k' ?
1024 : 1);
2412 # convert config value to array reference, if needed
2413 sub config_to_multi
{
2416 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2419 sub git_get_project_config
{
2420 my ($key, $type) = @_;
2422 return unless defined $git_dir;
2425 return unless ($key);
2426 $key =~ s/^gitweb\.//;
2427 return if ($key =~ m/\W/);
2430 if (defined $type) {
2433 unless ($type eq 'bool' || $type eq 'int');
2437 if (!defined $config_file ||
2438 $config_file ne "$git_dir/config") {
2439 %config = git_parse_project_config
('gitweb');
2440 $config_file = "$git_dir/config";
2443 # check if config variable (key) exists
2444 return unless exists $config{"gitweb.$key"};
2447 if (!defined $type) {
2448 return $config{"gitweb.$key"};
2449 } elsif ($type eq 'bool') {
2450 # backward compatibility: 'git config --bool' returns true/false
2451 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2452 } elsif ($type eq 'int') {
2453 return config_to_int
($config{"gitweb.$key"});
2455 return $config{"gitweb.$key"};
2458 # get hash of given path at given ref
2459 sub git_get_hash_by_path
{
2461 my $path = shift || return undef;
2466 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2467 or die_error
(500, "Open git-ls-tree failed");
2469 close $fd or return undef;
2471 if (!defined $line) {
2472 # there is no tree or hash given by $path at $base
2476 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2477 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2478 if (defined $type && $type ne $2) {
2479 # type doesn't match
2485 # get path of entry with given hash at given tree-ish (ref)
2486 # used to get 'from' filename for combined diff (merge commit) for renames
2487 sub git_get_path_by_hash
{
2488 my $base = shift || return;
2489 my $hash = shift || return;
2493 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2495 while (my $line = <$fd>) {
2498 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2499 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2500 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2509 ## ......................................................................
2510 ## git utility functions, directly accessing git repository
2512 sub git_get_project_description
{
2515 $git_dir = "$projectroot/$path";
2516 open my $fd, '<', "$git_dir/description"
2517 or return git_get_project_config
('description');
2520 if (defined $descr) {
2526 sub git_get_project_ctags
{
2530 $git_dir = "$projectroot/$path";
2531 opendir my $dh, "$git_dir/ctags"
2533 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2534 open my $ct, '<', $_ or next;
2538 my $ctag = $_; $ctag =~ s
#.*/##;
2539 $ctags->{$ctag} = $val;
2545 sub git_populate_project_tagcloud
{
2548 # First, merge different-cased tags; tags vote on casing
2550 foreach (keys %$ctags) {
2551 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2552 if (not $ctags_lc{lc $_}->{topcount
}
2553 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2554 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2555 $ctags_lc{lc $_}->{topname
} = $_;
2560 if (eval { require HTML
::TagCloud
; 1; }) {
2561 $cloud = HTML
::TagCloud
->new;
2562 foreach (sort keys %ctags_lc) {
2563 # Pad the title with spaces so that the cloud looks
2565 my $title = $ctags_lc{$_}->{topname
};
2566 $title =~ s/ / /g;
2567 $title =~ s/^/ /g;
2568 $title =~ s/$/ /g;
2569 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2572 $cloud = \
%ctags_lc;
2577 sub git_show_project_tagcloud
{
2578 my ($cloud, $count) = @_;
2579 print STDERR
ref($cloud)."..\n";
2580 if (ref $cloud eq 'HTML::TagCloud') {
2581 return $cloud->html_and_css($count);
2583 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2584 return '<p align="center">' . join (', ', map {
2585 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2586 } splice(@tags, 0, $count)) . '</p>';
2590 sub git_get_project_url_list
{
2593 $git_dir = "$projectroot/$path";
2594 open my $fd, '<', "$git_dir/cloneurl"
2595 or return wantarray ?
2596 @
{ config_to_multi
(git_get_project_config
('url')) } :
2597 config_to_multi
(git_get_project_config
('url'));
2598 my @git_project_url_list = map { chomp; $_ } <$fd>;
2601 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2604 sub git_get_projects_list
{
2609 $filter =~ s/\.git$//;
2611 my $check_forks = gitweb_check_feature
('forks');
2613 if (-d
$projects_list) {
2614 # search in directory
2615 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2616 # remove the trailing "/"
2618 my $pfxlen = length("$dir");
2619 my $pfxdepth = ($dir =~ tr!/!!);
2622 follow_fast
=> 1, # follow symbolic links
2623 follow_skip
=> 2, # ignore duplicates
2624 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2627 our $project_maxdepth;
2629 # skip project-list toplevel, if we get it.
2630 return if (m!^[/.]$!);
2631 # only directories can be git repositories
2632 return unless (-d
$_);
2633 # don't traverse too deep (Find is super slow on os x)
2634 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2635 $File::Find
::prune
= 1;
2639 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2640 # we check related file in $projectroot
2641 my $path = ($filter ?
"$filter/" : '') . $subdir;
2642 if (check_export_ok
("$projectroot/$path")) {
2643 push @list, { path
=> $path };
2644 $File::Find
::prune
= 1;
2649 } elsif (-f
$projects_list) {
2650 # read from file(url-encoded):
2651 # 'git%2Fgit.git Linus+Torvalds'
2652 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2653 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2655 open my $fd, '<', $projects_list or return;
2657 while (my $line = <$fd>) {
2659 my ($path, $owner) = split ' ', $line;
2660 $path = unescape
($path);
2661 $owner = unescape
($owner);
2662 if (!defined $path) {
2665 if ($filter ne '') {
2666 # looking for forks;
2667 my $pfx = substr($path, 0, length($filter));
2668 if ($pfx ne $filter) {
2671 my $sfx = substr($path, length($filter));
2672 if ($sfx !~ /^\/.*\
.git
$/) {
2675 } elsif ($check_forks) {
2677 foreach my $filter (keys %paths) {
2678 # looking for forks;
2679 my $pfx = substr($path, 0, length($filter));
2680 if ($pfx ne $filter) {
2683 my $sfx = substr($path, length($filter));
2684 if ($sfx !~ /^\/.*\
.git
$/) {
2687 # is a fork, don't include it in
2692 if (check_export_ok
("$projectroot/$path")) {
2695 owner
=> to_utf8
($owner),
2698 (my $forks_path = $path) =~ s/\.git$//;
2699 $paths{$forks_path}++;
2707 our $gitweb_project_owner = undef;
2708 sub git_get_project_list_from_file
{
2710 return if (defined $gitweb_project_owner);
2712 $gitweb_project_owner = {};
2713 # read from file (url-encoded):
2714 # 'git%2Fgit.git Linus+Torvalds'
2715 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2716 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2717 if (-f
$projects_list) {
2718 open(my $fd, '<', $projects_list);
2719 while (my $line = <$fd>) {
2721 my ($pr, $ow) = split ' ', $line;
2722 $pr = unescape
($pr);
2723 $ow = unescape
($ow);
2724 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2730 sub git_get_project_owner
{
2731 my $project = shift;
2734 return undef unless $project;
2735 $git_dir = "$projectroot/$project";
2737 if (!defined $gitweb_project_owner) {
2738 git_get_project_list_from_file
();
2741 if (exists $gitweb_project_owner->{$project}) {
2742 $owner = $gitweb_project_owner->{$project};
2744 if (!defined $owner){
2745 $owner = git_get_project_config
('owner');
2747 if (!defined $owner) {
2748 $owner = get_file_owner
("$git_dir");
2754 sub git_get_last_activity
{
2758 $git_dir = "$projectroot/$path";
2759 open($fd, "-|", git_cmd
(), 'for-each-ref',
2760 '--format=%(committer)',
2761 '--sort=-committerdate',
2763 'refs/heads') or return;
2764 my $most_recent = <$fd>;
2765 close $fd or return;
2766 if (defined $most_recent &&
2767 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2769 my $age = time - $timestamp;
2770 return ($age, age_string
($age));
2772 return (undef, undef);
2775 sub git_get_references
{
2776 my $type = shift || "";
2778 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2779 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2780 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2781 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2784 while (my $line = <$fd>) {
2786 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2787 if (defined $refs{$1}) {
2788 push @
{$refs{$1}}, $2;
2794 close $fd or return;
2798 sub git_get_rev_name_tags
{
2799 my $hash = shift || return undef;
2801 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2803 my $name_rev = <$fd>;
2806 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2809 # catches also '$hash undefined' output
2814 ## ----------------------------------------------------------------------
2815 ## parse to hash functions
2819 my $tz = shift || "-0000";
2822 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2823 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2824 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2825 $date{'hour'} = $hour;
2826 $date{'minute'} = $min;
2827 $date{'mday'} = $mday;
2828 $date{'day'} = $days[$wday];
2829 $date{'month'} = $months[$mon];
2830 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2831 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2832 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2833 $mday, $months[$mon], $hour ,$min;
2834 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2835 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2837 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2838 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2839 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2840 $date{'hour_local'} = $hour;
2841 $date{'minute_local'} = $min;
2842 $date{'tz_local'} = $tz;
2843 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2844 1900+$year, $mon+1, $mday,
2845 $hour, $min, $sec, $tz);
2854 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2855 $tag{'id'} = $tag_id;
2856 while (my $line = <$fd>) {
2858 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2859 $tag{'object'} = $1;
2860 } elsif ($line =~ m/^type (.+)$/) {
2862 } elsif ($line =~ m/^tag (.+)$/) {
2864 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2865 $tag{'author'} = $1;
2866 $tag{'author_epoch'} = $2;
2867 $tag{'author_tz'} = $3;
2868 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2869 $tag{'author_name'} = $1;
2870 $tag{'author_email'} = $2;
2872 $tag{'author_name'} = $tag{'author'};
2874 } elsif ($line =~ m/--BEGIN/) {
2875 push @comment, $line;
2877 } elsif ($line eq "") {
2881 push @comment, <$fd>;
2882 $tag{'comment'} = \
@comment;
2883 close $fd or return;
2884 if (!defined $tag{'name'}) {
2890 sub parse_commit_text
{
2891 my ($commit_text, $withparents) = @_;
2892 my @commit_lines = split '\n', $commit_text;
2895 pop @commit_lines; # Remove '\0'
2897 if (! @commit_lines) {
2901 my $header = shift @commit_lines;
2902 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2905 ($co{'id'}, my @parents) = split ' ', $header;
2906 while (my $line = shift @commit_lines) {
2907 last if $line eq "\n";
2908 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2910 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2912 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2913 $co{'author'} = to_utf8
($1);
2914 $co{'author_epoch'} = $2;
2915 $co{'author_tz'} = $3;
2916 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2917 $co{'author_name'} = $1;
2918 $co{'author_email'} = $2;
2920 $co{'author_name'} = $co{'author'};
2922 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2923 $co{'committer'} = to_utf8
($1);
2924 $co{'committer_epoch'} = $2;
2925 $co{'committer_tz'} = $3;
2926 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2927 $co{'committer_name'} = $1;
2928 $co{'committer_email'} = $2;
2930 $co{'committer_name'} = $co{'committer'};
2934 if (!defined $co{'tree'}) {
2937 $co{'parents'} = \
@parents;
2938 $co{'parent'} = $parents[0];
2940 foreach my $title (@commit_lines) {
2943 $co{'title'} = chop_str
($title, 80, 5);
2944 # remove leading stuff of merges to make the interesting part visible
2945 if (length($title) > 50) {
2946 $title =~ s/^Automatic //;
2947 $title =~ s/^merge (of|with) /Merge ... /i;
2948 if (length($title) > 50) {
2949 $title =~ s/(http|rsync):\/\///;
2951 if (length($title) > 50) {
2952 $title =~ s/(master|www|rsync)\.//;
2954 if (length($title) > 50) {
2955 $title =~ s/kernel.org:?//;
2957 if (length($title) > 50) {
2958 $title =~ s/\/pub\/scm//;
2961 $co{'title_short'} = chop_str
($title, 50, 5);
2965 if (! defined $co{'title'} || $co{'title'} eq "") {
2966 $co{'title'} = $co{'title_short'} = '(no commit message)';
2968 # remove added spaces
2969 foreach my $line (@commit_lines) {
2972 $co{'comment'} = \
@commit_lines;
2974 my $age = time - $co{'committer_epoch'};
2976 $co{'age_string'} = age_string
($age);
2977 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2978 if ($age > 60*60*24*7*2) {
2979 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2980 $co{'age_string_age'} = $co{'age_string'};
2982 $co{'age_string_date'} = $co{'age_string'};
2983 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2989 my ($commit_id) = @_;
2994 open my $fd, "-|", git_cmd
(), "rev-list",
3000 or die_error
(500, "Open git-rev-list failed");
3001 %co = parse_commit_text
(<$fd>, 1);
3008 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
3016 open my $fd, "-|", git_cmd
(), "rev-list",
3019 ("--max-count=" . $maxcount),
3020 ("--skip=" . $skip),
3024 ($filename ?
($filename) : ())
3025 or die_error
(500, "Open git-rev-list failed");
3026 while (my $line = <$fd>) {
3027 my %co = parse_commit_text
($line);
3032 return wantarray ?
@cos : \
@cos;
3035 # parse line of git-diff-tree "raw" output
3036 sub parse_difftree_raw_line
{
3040 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3041 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3042 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3043 $res{'from_mode'} = $1;
3044 $res{'to_mode'} = $2;
3045 $res{'from_id'} = $3;
3047 $res{'status'} = $5;
3048 $res{'similarity'} = $6;
3049 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3050 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3052 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3055 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3056 # combined diff (for merge commit)
3057 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3058 $res{'nparents'} = length($1);
3059 $res{'from_mode'} = [ split(' ', $2) ];
3060 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3061 $res{'from_id'} = [ split(' ', $3) ];
3062 $res{'to_id'} = pop @
{$res{'from_id'}};
3063 $res{'status'} = [ split('', $4) ];
3064 $res{'to_file'} = unquote
($5);
3066 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3067 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3068 $res{'commit'} = $1;
3071 return wantarray ?
%res : \
%res;
3074 # wrapper: return parsed line of git-diff-tree "raw" output
3075 # (the argument might be raw line, or parsed info)
3076 sub parsed_difftree_line
{
3077 my $line_or_ref = shift;
3079 if (ref($line_or_ref) eq "HASH") {
3080 # pre-parsed (or generated by hand)
3081 return $line_or_ref;
3083 return parse_difftree_raw_line
($line_or_ref);
3087 # parse line of git-ls-tree output
3088 sub parse_ls_tree_line
{
3094 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3095 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3104 $res{'name'} = unquote
($5);
3107 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3108 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3116 $res{'name'} = unquote
($4);
3120 return wantarray ?
%res : \
%res;
3123 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3124 sub parse_from_to_diffinfo
{
3125 my ($diffinfo, $from, $to, @parents) = @_;
3127 if ($diffinfo->{'nparents'}) {
3129 $from->{'file'} = [];
3130 $from->{'href'} = [];
3131 fill_from_file_info
($diffinfo, @parents)
3132 unless exists $diffinfo->{'from_file'};
3133 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3134 $from->{'file'}[$i] =
3135 defined $diffinfo->{'from_file'}[$i] ?
3136 $diffinfo->{'from_file'}[$i] :
3137 $diffinfo->{'to_file'};
3138 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3139 $from->{'href'}[$i] = href
(action
=>"blob",
3140 hash_base
=>$parents[$i],
3141 hash
=>$diffinfo->{'from_id'}[$i],
3142 file_name
=>$from->{'file'}[$i]);
3144 $from->{'href'}[$i] = undef;
3148 # ordinary (not combined) diff
3149 $from->{'file'} = $diffinfo->{'from_file'};
3150 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3151 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3152 hash
=>$diffinfo->{'from_id'},
3153 file_name
=>$from->{'file'});
3155 delete $from->{'href'};
3159 $to->{'file'} = $diffinfo->{'to_file'};
3160 if (!is_deleted
($diffinfo)) { # file exists in result
3161 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3162 hash
=>$diffinfo->{'to_id'},
3163 file_name
=>$to->{'file'});
3165 delete $to->{'href'};
3169 ## ......................................................................
3170 ## parse to array of hashes functions
3172 sub git_get_heads_list
{
3173 my ($limit, @classes) = @_;
3174 @classes = ('heads') unless @classes;
3175 my @patterns = map { "refs/$_" } @classes;
3178 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3179 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3180 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3183 while (my $line = <$fd>) {
3187 my ($refinfo, $committerinfo) = split(/\0/, $line);
3188 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3189 my ($committer, $epoch, $tz) =
3190 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3191 $ref_item{'fullname'} = $name;
3192 $name =~ s!^refs/(?:head|remote)s/!!;
3194 $ref_item{'name'} = $name;
3195 $ref_item{'id'} = $hash;
3196 $ref_item{'title'} = $title || '(no commit message)';
3197 $ref_item{'epoch'} = $epoch;
3199 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3201 $ref_item{'age'} = "unknown";
3204 push @headslist, \
%ref_item;
3208 return wantarray ?
@headslist : \
@headslist;
3211 sub git_get_tags_list
{
3215 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3216 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3217 '--format=%(objectname) %(objecttype) %(refname) '.
3218 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3221 while (my $line = <$fd>) {
3225 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3226 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3227 my ($creator, $epoch, $tz) =
3228 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3229 $ref_item{'fullname'} = $name;
3230 $name =~ s!^refs/tags/!!;
3232 $ref_item{'type'} = $type;
3233 $ref_item{'id'} = $id;
3234 $ref_item{'name'} = $name;
3235 if ($type eq "tag") {
3236 $ref_item{'subject'} = $title;
3237 $ref_item{'reftype'} = $reftype;
3238 $ref_item{'refid'} = $refid;
3240 $ref_item{'reftype'} = $type;
3241 $ref_item{'refid'} = $id;
3244 if ($type eq "tag" || $type eq "commit") {
3245 $ref_item{'epoch'} = $epoch;
3247 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3249 $ref_item{'age'} = "unknown";
3253 push @tagslist, \
%ref_item;
3257 return wantarray ?
@tagslist : \
@tagslist;
3260 ## ----------------------------------------------------------------------
3261 ## filesystem-related functions
3263 sub get_file_owner
{
3266 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3267 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3268 if (!defined $gcos) {
3272 $owner =~ s/[,;].*$//;
3273 return to_utf8
($owner);
3276 # assume that file exists
3278 my $filename = shift;
3280 open my $fd, '<', $filename;
3281 print map { to_utf8
($_) } <$fd>;
3285 ## ......................................................................
3286 ## mimetype related functions
3288 sub mimetype_guess_file
{
3289 my $filename = shift;
3290 my $mimemap = shift;
3291 -r
$mimemap or return undef;
3294 open(my $mh, '<', $mimemap) or return undef;
3296 next if m/^#/; # skip comments
3297 my ($mimetype, $exts) = split(/\t+/);
3298 if (defined $exts) {
3299 my @exts = split(/\s+/, $exts);
3300 foreach my $ext (@exts) {
3301 $mimemap{$ext} = $mimetype;
3307 $filename =~ /\.([^.]*)$/;
3308 return $mimemap{$1};
3311 sub mimetype_guess
{
3312 my $filename = shift;
3314 $filename =~ /\./ or return undef;
3316 if ($mimetypes_file) {
3317 my $file = $mimetypes_file;
3318 if ($file !~ m!^/!) { # if it is relative path
3319 # it is relative to project
3320 $file = "$projectroot/$project/$file";
3322 $mime = mimetype_guess_file
($filename, $file);
3324 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3330 my $filename = shift;
3333 my $mime = mimetype_guess
($filename);
3334 $mime and return $mime;
3338 return $default_blob_plain_mimetype unless $fd;
3341 return 'text/plain';
3342 } elsif (! $filename) {
3343 return 'application/octet-stream';
3344 } elsif ($filename =~ m/\.png$/i) {
3346 } elsif ($filename =~ m/\.gif$/i) {
3348 } elsif ($filename =~ m/\.jpe?g$/i) {
3349 return 'image/jpeg';
3351 return 'application/octet-stream';
3355 sub blob_contenttype
{
3356 my ($fd, $file_name, $type) = @_;
3358 $type ||= blob_mimetype
($fd, $file_name);
3359 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3360 $type .= "; charset=$default_text_plain_charset";
3366 # guess file syntax for syntax highlighting; return undef if no highlighting
3367 # the name of syntax can (in the future) depend on syntax highlighter used
3368 sub guess_file_syntax
{
3369 my ($highlight, $mimetype, $file_name) = @_;
3370 return undef unless ($highlight && defined $file_name);
3371 my $basename = basename
($file_name, '.in');
3372 return $highlight_basename{$basename}
3373 if exists $highlight_basename{$basename};
3375 $basename =~ /\.([^.]*)$/;
3376 my $ext = $1 or return undef;
3377 return $highlight_ext{$ext}
3378 if exists $highlight_ext{$ext};
3383 # run highlighter and return FD of its output,
3384 # or return original FD if no highlighting
3385 sub run_highlighter
{
3386 my ($fd, $highlight, $syntax) = @_;
3387 return $fd unless ($highlight && defined $syntax);
3390 or die_error
(404, "Reading blob failed");
3391 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3392 quote_command
($highlight_bin).
3393 " --xhtml --fragment --syntax $syntax |"
3394 or die_error
(500, "Couldn't open file or run syntax highlighter");
3398 ## ======================================================================
3399 ## functions printing HTML: header, footer, error page
3401 sub get_page_title
{
3402 my $title = to_utf8
($site_name);
3404 return $title unless (defined $project);
3405 $title .= " - " . to_utf8
($project);
3407 return $title unless (defined $action);
3408 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3410 return $title unless (defined $file_name);
3411 $title .= " - " . esc_path
($file_name);
3412 if ($action eq "tree" && $file_name !~ m
|/$|) {
3419 sub git_header_html
{
3420 my $status = shift || "200 OK";
3421 my $expires = shift;
3424 my $title = get_page_title
();
3426 # require explicit support from the UA if we are to send the page as
3427 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3428 # we have to do this because MSIE sometimes globs '*/*', pretending to
3429 # support xhtml+xml but choking when it gets what it asked for.
3430 if (defined $cgi->http('HTTP_ACCEPT') &&
3431 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3432 $cgi->Accept('application/xhtml+xml') != 0) {
3433 $content_type = 'application/xhtml+xml';
3435 $content_type = 'text/html';
3437 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3438 -status
=> $status, -expires
=> $expires)
3439 unless ($opts{'-no_http_header'});
3440 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3442 <?xml version="1.0" encoding="utf-8"?>
3443 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3444 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3445 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3446 <!-- git core binaries version $git_version -->
3448 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3449 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3450 <meta name="robots" content="index, nofollow"/>
3451 <title>$title</title>
3453 # the stylesheet, favicon etc urls won't work correctly with path_info
3454 # unless we set the appropriate base URL
3455 if ($ENV{'PATH_INFO'}) {
3456 print "<base href=\"".esc_url
($base_url)."\" />\n";
3458 # print out each stylesheet that exist, providing backwards capability
3459 # for those people who defined $stylesheet in a config file
3460 if (defined $stylesheet) {
3461 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3463 foreach my $stylesheet (@stylesheets) {
3464 next unless $stylesheet;
3465 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3468 if (defined $project) {
3469 my %href_params = get_feed_info
();
3470 if (!exists $href_params{'-title'}) {
3471 $href_params{'-title'} = 'log';
3474 foreach my $format qw(RSS Atom) {
3475 my $type = lc($format);
3477 '-rel' => 'alternate',
3478 '-title' => "$project - $href_params{'-title'} - $format feed",
3479 '-type' => "application/$type+xml"
3482 $href_params{'action'} = $type;
3483 $link_attr{'-href'} = href
(%href_params);
3485 "rel=\"$link_attr{'-rel'}\" ".
3486 "title=\"$link_attr{'-title'}\" ".
3487 "href=\"$link_attr{'-href'}\" ".
3488 "type=\"$link_attr{'-type'}\" ".
3491 $href_params{'extra_options'} = '--no-merges';
3492 $link_attr{'-href'} = href
(%href_params);
3493 $link_attr{'-title'} .= ' (no merges)';
3495 "rel=\"$link_attr{'-rel'}\" ".
3496 "title=\"$link_attr{'-title'}\" ".
3497 "href=\"$link_attr{'-href'}\" ".
3498 "type=\"$link_attr{'-type'}\" ".
3503 printf('<link rel="alternate" title="%s projects list" '.
3504 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3505 $site_name, href
(project
=>undef, action
=>"project_index"));
3506 printf('<link rel="alternate" title="%s projects feeds" '.
3507 'href="%s" type="text/x-opml" />'."\n",
3508 $site_name, href
(project
=>undef, action
=>"opml"));
3510 if (defined $favicon) {
3511 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3517 if (defined $site_header && -f
$site_header) {
3518 insert_file
($site_header);
3521 print "<div class=\"page_header\">\n" .
3522 $cgi->a({-href
=> esc_url
($logo_url),
3523 -title
=> $logo_label},
3524 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3525 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3526 if (defined $project) {
3527 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3528 if (defined $action) {
3529 my $action_print = $action ;
3530 if (defined $opts{-action_extra
}) {
3531 $action_print = $cgi->a({-href
=> href
(action
=>$action)},
3534 print " / $action_print";
3536 if (defined $opts{-action_extra
}) {
3537 print " / $opts{-action_extra}";
3543 my $have_search = gitweb_check_feature
('search');
3544 if (defined $project && $have_search) {
3545 if (!defined $searchtext) {
3549 if (defined $hash_base) {
3550 $search_hash = $hash_base;
3551 } elsif (defined $hash) {
3552 $search_hash = $hash;
3554 $search_hash = "HEAD";
3556 my $action = $my_uri;
3557 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3558 if ($use_pathinfo) {
3559 $action .= "/".esc_url
($project);
3561 print $cgi->startform(-method
=> "get", -action
=> $action) .
3562 "<div class=\"search\">\n" .
3564 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3565 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3566 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3567 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3568 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3569 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3571 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3572 "<span title=\"Extended regular expression\">" .
3573 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3574 -checked
=> $search_use_regexp) .
3577 $cgi->end_form() . "\n";
3581 sub git_footer_html
{
3582 my $feed_class = 'rss_logo';
3584 print "<div class=\"page_footer\">\n";
3585 if (defined $project) {
3586 my $descr = git_get_project_description
($project);
3587 if (defined $descr) {
3588 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3591 my %href_params = get_feed_info
();
3592 if (!%href_params) {
3593 $feed_class .= ' generic';
3595 $href_params{'-title'} ||= 'log';
3597 foreach my $format qw(RSS Atom) {
3598 $href_params{'action'} = lc($format);
3599 print $cgi->a({-href
=> href
(%href_params),
3600 -title
=> "$href_params{'-title'} $format feed",
3601 -class => $feed_class}, $format)."\n";
3605 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3606 -class => $feed_class}, "OPML") . " ";
3607 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3608 -class => $feed_class}, "TXT") . "\n";
3610 print "</div>\n"; # class="page_footer"
3612 if (defined $t0 && gitweb_check_feature
('timed')) {
3613 print "<div id=\"generating_info\">\n";
3614 print 'This page took '.
3615 '<span id="generating_time" class="time_span">'.
3616 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3619 '<span id="generating_cmd">'.
3620 $number_of_git_cmds.
3621 '</span> git commands '.
3623 print "</div>\n"; # class="page_footer"
3626 if (defined $site_footer && -f
$site_footer) {
3627 insert_file
($site_footer);
3630 print qq!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3631 if (defined $action &&
3632 $action eq 'blame_incremental') {
3633 print qq!<script type
="text/javascript">\n!.
3634 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3635 qq! "!. href() .qq!");\n!.
3637 } elsif (gitweb_check_feature
('javascript-actions')) {
3638 print qq!<script type
="text/javascript">\n!.
3639 qq!window
.onload
= fixLinks
;\n!.
3647 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3648 # Example: die_error(404, 'Hash not found')
3649 # By convention, use the following status codes (as defined in RFC 2616):
3650 # 400: Invalid or missing CGI parameters, or
3651 # requested object exists but has wrong type.
3652 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3653 # this server or project.
3654 # 404: Requested object/revision/project doesn't exist.
3655 # 500: The server isn't configured properly, or
3656 # an internal error occurred (e.g. failed assertions caused by bugs), or
3657 # an unknown error occurred (e.g. the git binary died unexpectedly).
3658 # 503: The server is currently unavailable (because it is overloaded,
3659 # or down for maintenance). Generally, this is a temporary state.
3661 my $status = shift || 500;
3662 my $error = esc_html
(shift) || "Internal Server Error";
3666 my %http_responses = (
3667 400 => '400 Bad Request',
3668 403 => '403 Forbidden',
3669 404 => '404 Not Found',
3670 500 => '500 Internal Server Error',
3671 503 => '503 Service Unavailable',
3673 git_header_html
($http_responses{$status}, undef, %opts);
3675 <div class="page_body">
3680 if (defined $extra) {
3688 unless ($opts{'-error_handler'});
3691 ## ----------------------------------------------------------------------
3692 ## functions printing or outputting HTML: navigation
3694 sub git_print_page_nav
{
3695 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3696 $extra = '' if !defined $extra; # pager or formats
3698 my @navs = qw(summary shortlog log commit commitdiff tree);
3700 @navs = grep { $_ ne $suppress } @navs;
3703 my %arg = map { $_ => {action
=>$_} } @navs;
3704 if (defined $head) {
3705 for (qw(commit commitdiff)) {
3706 $arg{$_}{'hash'} = $head;
3708 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3709 for (qw(shortlog log)) {
3710 $arg{$_}{'hash'} = $head;
3715 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3716 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3718 my @actions = gitweb_get_feature
('actions');
3721 'n' => $project, # project name
3722 'f' => $git_dir, # project path within filesystem
3723 'h' => $treehead || '', # current hash ('h' parameter)
3724 'b' => $treebase || '', # hash base ('hb' parameter)
3727 my ($label, $link, $pos) = splice(@actions,0,3);
3729 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3731 $link =~ s/%([%nfhb])/$repl{$1}/g;
3732 $arg{$label}{'_href'} = $link;
3735 print "<div class=\"page_nav\">\n" .
3737 map { $_ eq $current ?
3738 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3740 print "<br/>\n$extra<br/>\n" .
3744 # returns a submenu for the nagivation of the refs views (tags, heads,
3745 # remotes) with the current view disabled and the remotes view only
3746 # available if the feature is enabled
3747 sub format_ref_views
{
3749 my @ref_views = qw{tags heads
};
3750 push @ref_views, 'remotes' if gitweb_check_feature
('remote_heads');
3751 return join " | ", map {
3752 $_ eq $current ?
$_ :
3753 $cgi->a({-href
=> href
(action
=>$_)}, $_)
3757 sub format_paging_nav
{
3758 my ($action, $page, $has_next_link) = @_;
3764 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3766 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3767 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3769 $paging_nav .= "first ⋅ prev";
3772 if ($has_next_link) {
3773 $paging_nav .= " ⋅ " .
3774 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3775 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3777 $paging_nav .= " ⋅ next";
3783 ## ......................................................................
3784 ## functions printing or outputting HTML: div
3786 sub git_print_header_div
{
3787 my ($action, $title, $hash, $hash_base) = @_;
3790 $args{'action'} = $action;
3791 $args{'hash'} = $hash if $hash;
3792 $args{'hash_base'} = $hash_base if $hash_base;
3794 print "<div class=\"header\">\n" .
3795 $cgi->a({-href
=> href
(%args), -class => "title"},
3796 $title ?
$title : $action) .
3800 sub format_repo_url
{
3801 my ($name, $url) = @_;
3802 return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
3805 # Group output by placing it in a DIV element and adding a header.
3806 # Options for start_div() can be provided by passing a hash reference as the
3807 # first parameter to the function.
3808 # Options to git_print_header_div() can be provided by passing an array
3809 # reference. This must follow the options to start_div if they are present.
3810 # The content can be a scalar, which is output as-is, a scalar reference, which
3811 # is output after html escaping, an IO handle passed either as *handle or
3812 # *handle{IO}, or a function reference. In the latter case all following
3813 # parameters will be taken as argument to the content function call.
3814 sub git_print_section
{
3815 my ($div_args, $header_args, $content);
3817 if (ref($arg) eq 'HASH') {
3821 if (ref($arg) eq 'ARRAY') {
3822 $header_args = $arg;
3827 print $cgi->start_div($div_args);
3828 git_print_header_div
(@
$header_args);
3830 if (ref($content) eq 'CODE') {
3832 } elsif (ref($content) eq 'SCALAR') {
3833 print esc_html
($$content);
3834 } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
3836 } elsif (!ref($content) && defined($content)) {
3840 print $cgi->end_div;
3843 sub print_local_time
{
3844 print format_local_time
(@_);
3847 sub format_local_time
{
3850 if ($date{'hour_local'} < 6) {
3851 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3852 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3854 $localtime .= sprintf(" (%02d:%02d %s)",
3855 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3861 # Outputs the author name and date in long form
3862 sub git_print_authorship
{
3865 my $tag = $opts{-tag
} || 'div';
3866 my $author = $co->{'author_name'};
3868 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3869 print "<$tag class=\"author_date\">" .
3870 format_search_author
($author, "author", esc_html
($author)) .
3872 print_local_time
(%ad) if ($opts{-localtime});
3873 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3877 # Outputs table rows containing the full author or committer information,
3878 # in the format expected for 'commit' view (& similar).
3879 # Parameters are a commit hash reference, followed by the list of people
3880 # to output information for. If the list is empty it defaults to both
3881 # author and committer.
3882 sub git_print_authorship_rows
{
3884 # too bad we can't use @people = @_ || ('author', 'committer')
3886 @people = ('author', 'committer') unless @people;
3887 foreach my $who (@people) {
3888 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3889 print "<tr><td>$who</td><td>" .
3890 format_search_author
($co->{"${who}_name"}, $who,
3891 esc_html
($co->{"${who}_name"})) . " " .
3892 format_search_author
($co->{"${who}_email"}, $who,
3893 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3894 "</td><td rowspan=\"2\">" .
3895 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3898 "<td></td><td> $wd{'rfc2822'}";
3899 print_local_time
(%wd);
3905 sub git_print_page_path
{
3911 print "<div class=\"page_path\">";
3912 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3913 -title
=> 'tree root'}, to_utf8
("[$project]"));
3915 if (defined $name) {
3916 my @dirname = split '/', $name;
3917 my $basename = pop @dirname;
3920 foreach my $dir (@dirname) {
3921 $fullname .= ($fullname ?
'/' : '') . $dir;
3922 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3924 -title
=> $fullname}, esc_path
($dir));
3927 if (defined $type && $type eq 'blob') {
3928 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3930 -title
=> $name}, esc_path
($basename));
3931 } elsif (defined $type && $type eq 'tree') {
3932 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3934 -title
=> $name}, esc_path
($basename));
3937 print esc_path
($basename);
3940 print "<br/></div>\n";
3947 if ($opts{'-remove_title'}) {
3948 # remove title, i.e. first line of log
3951 # remove leading empty lines
3952 while (defined $log->[0] && $log->[0] eq "") {
3959 foreach my $line (@
$log) {
3960 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3963 if (! $opts{'-remove_signoff'}) {
3964 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3967 # remove signoff lines
3974 # print only one empty line
3975 # do not print empty line after signoff
3977 next if ($empty || $signoff);
3983 print format_log_line_html
($line) . "<br/>\n";
3986 if ($opts{'-final_empty_line'}) {
3987 # end with single empty line
3988 print "<br/>\n" unless $empty;
3992 # return link target (what link points to)
3993 sub git_get_link_target
{
3998 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4002 $link_target = <$fd>;
4007 return $link_target;
4010 # given link target, and the directory (basedir) the link is in,
4011 # return target of link relative to top directory (top tree);
4012 # return undef if it is not possible (including absolute links).
4013 sub normalize_link_target
{
4014 my ($link_target, $basedir) = @_;
4016 # absolute symlinks (beginning with '/') cannot be normalized
4017 return if (substr($link_target, 0, 1) eq '/');
4019 # normalize link target to path from top (root) tree (dir)
4022 $path = $basedir . '/' . $link_target;
4024 # we are in top (root) tree (dir)
4025 $path = $link_target;
4028 # remove //, /./, and /../
4030 foreach my $part (split('/', $path)) {
4031 # discard '.' and ''
4032 next if (!$part || $part eq '.');
4034 if ($part eq '..') {
4038 # link leads outside repository (outside top dir)
4042 push @path_parts, $part;
4045 $path = join('/', @path_parts);
4050 # print tree entry (row of git_tree), but without encompassing <tr> element
4051 sub git_print_tree_entry
{
4052 my ($t, $basedir, $hash_base, $have_blame) = @_;
4055 $base_key{'hash_base'} = $hash_base if defined $hash_base;
4057 # The format of a table row is: mode list link. Where mode is
4058 # the mode of the entry, list is the name of the entry, an href,
4059 # and link is the action links of the entry.
4061 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
4062 if (exists $t->{'size'}) {
4063 print "<td class=\"size\">$t->{'size'}</td>\n";
4065 if ($t->{'type'} eq "blob") {
4066 print "<td class=\"list\">" .
4067 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4068 file_name
=>"$basedir$t->{'name'}", %base_key),
4069 -class => "list"}, esc_path
($t->{'name'}));
4070 if (S_ISLNK
(oct $t->{'mode'})) {
4071 my $link_target = git_get_link_target
($t->{'hash'});
4073 my $norm_target = normalize_link_target
($link_target, $basedir);
4074 if (defined $norm_target) {
4076 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
4077 file_name
=>$norm_target),
4078 -title
=> $norm_target}, esc_path
($link_target));
4080 print " -> " . esc_path
($link_target);
4085 print "<td class=\"link\">";
4086 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4087 file_name
=>"$basedir$t->{'name'}", %base_key)},
4091 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4092 file_name
=>"$basedir$t->{'name'}", %base_key)},
4095 if (defined $hash_base) {
4097 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4098 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4102 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4103 file_name
=>"$basedir$t->{'name'}")},
4107 } elsif ($t->{'type'} eq "tree") {
4108 print "<td class=\"list\">";
4109 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4110 file_name
=>"$basedir$t->{'name'}",
4112 esc_path
($t->{'name'}));
4114 print "<td class=\"link\">";
4115 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4116 file_name
=>"$basedir$t->{'name'}",
4119 if (defined $hash_base) {
4121 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4122 file_name
=>"$basedir$t->{'name'}")},
4127 # unknown object: we can only present history for it
4128 # (this includes 'commit' object, i.e. submodule support)
4129 print "<td class=\"list\">" .
4130 esc_path
($t->{'name'}) .
4132 print "<td class=\"link\">";
4133 if (defined $hash_base) {
4134 print $cgi->a({-href
=> href
(action
=>"history",
4135 hash_base
=>$hash_base,
4136 file_name
=>"$basedir$t->{'name'}")},
4143 ## ......................................................................
4144 ## functions printing large fragments of HTML
4146 # get pre-image filenames for merge (combined) diff
4147 sub fill_from_file_info
{
4148 my ($diff, @parents) = @_;
4150 $diff->{'from_file'} = [ ];
4151 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4152 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4153 if ($diff->{'status'}[$i] eq 'R' ||
4154 $diff->{'status'}[$i] eq 'C') {
4155 $diff->{'from_file'}[$i] =
4156 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4163 # is current raw difftree line of file deletion
4165 my $diffinfo = shift;
4167 return $diffinfo->{'to_id'} eq ('0' x
40);
4170 # does patch correspond to [previous] difftree raw line
4171 # $diffinfo - hashref of parsed raw diff format
4172 # $patchinfo - hashref of parsed patch diff format
4173 # (the same keys as in $diffinfo)
4174 sub is_patch_split
{
4175 my ($diffinfo, $patchinfo) = @_;
4177 return defined $diffinfo && defined $patchinfo
4178 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4182 sub git_difftree_body
{
4183 my ($difftree, $hash, @parents) = @_;
4184 my ($parent) = $parents[0];
4185 my $have_blame = gitweb_check_feature
('blame');
4186 print "<div class=\"list_head\">\n";
4187 if ($#{$difftree} > 10) {
4188 print(($#{$difftree} + 1) . " files changed:\n");
4192 print "<table class=\"" .
4193 (@parents > 1 ?
"combined " : "") .
4196 # header only for combined diff in 'commitdiff' view
4197 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4200 print "<thead><tr>\n" .
4201 "<th></th><th></th>\n"; # filename, patchN link
4202 for (my $i = 0; $i < @parents; $i++) {
4203 my $par = $parents[$i];
4205 $cgi->a({-href
=> href
(action
=>"commitdiff",
4206 hash
=>$hash, hash_parent
=>$par),
4207 -title
=> 'commitdiff to parent number ' .
4208 ($i+1) . ': ' . substr($par,0,7)},
4212 print "</tr></thead>\n<tbody>\n";
4217 foreach my $line (@
{$difftree}) {
4218 my $diff = parsed_difftree_line
($line);
4221 print "<tr class=\"dark\">\n";
4223 print "<tr class=\"light\">\n";
4227 if (exists $diff->{'nparents'}) { # combined diff
4229 fill_from_file_info
($diff, @parents)
4230 unless exists $diff->{'from_file'};
4232 if (!is_deleted
($diff)) {
4233 # file exists in the result (child) commit
4235 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4236 file_name
=>$diff->{'to_file'},
4238 -class => "list"}, esc_path
($diff->{'to_file'})) .
4242 esc_path
($diff->{'to_file'}) .
4246 if ($action eq 'commitdiff') {
4249 print "<td class=\"link\">" .
4250 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4255 my $has_history = 0;
4256 my $not_deleted = 0;
4257 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4258 my $hash_parent = $parents[$i];
4259 my $from_hash = $diff->{'from_id'}[$i];
4260 my $from_path = $diff->{'from_file'}[$i];
4261 my $status = $diff->{'status'}[$i];
4263 $has_history ||= ($status ne 'A');
4264 $not_deleted ||= ($status ne 'D');
4266 if ($status eq 'A') {
4267 print "<td class=\"link\" align=\"right\"> | </td>\n";
4268 } elsif ($status eq 'D') {
4269 print "<td class=\"link\">" .
4270 $cgi->a({-href
=> href
(action
=>"blob",
4273 file_name
=>$from_path)},
4277 if ($diff->{'to_id'} eq $from_hash) {
4278 print "<td class=\"link nochange\">";
4280 print "<td class=\"link\">";
4282 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4283 hash
=>$diff->{'to_id'},
4284 hash_parent
=>$from_hash,
4286 hash_parent_base
=>$hash_parent,
4287 file_name
=>$diff->{'to_file'},
4288 file_parent
=>$from_path)},
4294 print "<td class=\"link\">";
4296 print $cgi->a({-href
=> href
(action
=>"blob",
4297 hash
=>$diff->{'to_id'},
4298 file_name
=>$diff->{'to_file'},
4301 print " | " if ($has_history);
4304 print $cgi->a({-href
=> href
(action
=>"history",
4305 file_name
=>$diff->{'to_file'},
4312 next; # instead of 'else' clause, to avoid extra indent
4314 # else ordinary diff
4316 my ($to_mode_oct, $to_mode_str, $to_file_type);
4317 my ($from_mode_oct, $from_mode_str, $from_file_type);
4318 if ($diff->{'to_mode'} ne ('0' x
6)) {
4319 $to_mode_oct = oct $diff->{'to_mode'};
4320 if (S_ISREG
($to_mode_oct)) { # only for regular file
4321 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4323 $to_file_type = file_type
($diff->{'to_mode'});
4325 if ($diff->{'from_mode'} ne ('0' x
6)) {
4326 $from_mode_oct = oct $diff->{'from_mode'};
4327 if (S_ISREG
($to_mode_oct)) { # only for regular file
4328 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4330 $from_file_type = file_type
($diff->{'from_mode'});
4333 if ($diff->{'status'} eq "A") { # created
4334 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4335 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4336 $mode_chng .= "]</span>";
4338 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4339 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4340 -class => "list"}, esc_path
($diff->{'file'}));
4342 print "<td>$mode_chng</td>\n";
4343 print "<td class=\"link\">";
4344 if ($action eq 'commitdiff') {
4347 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4350 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4351 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4355 } elsif ($diff->{'status'} eq "D") { # deleted
4356 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4358 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4359 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4360 -class => "list"}, esc_path
($diff->{'file'}));
4362 print "<td>$mode_chng</td>\n";
4363 print "<td class=\"link\">";
4364 if ($action eq 'commitdiff') {
4367 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4370 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4371 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4374 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4375 file_name
=>$diff->{'file'})},
4378 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4379 file_name
=>$diff->{'file'})},
4383 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4384 my $mode_chnge = "";
4385 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4386 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4387 if ($from_file_type ne $to_file_type) {
4388 $mode_chnge .= " from $from_file_type to $to_file_type";
4390 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4391 if ($from_mode_str && $to_mode_str) {
4392 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4393 } elsif ($to_mode_str) {
4394 $mode_chnge .= " mode: $to_mode_str";
4397 $mode_chnge .= "]</span>\n";
4400 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4401 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4402 -class => "list"}, esc_path
($diff->{'file'}));
4404 print "<td>$mode_chnge</td>\n";
4405 print "<td class=\"link\">";
4406 if ($action eq 'commitdiff') {
4409 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4411 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4412 # "commit" view and modified file (not onlu mode changed)
4413 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4414 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4415 hash_base
=>$hash, hash_parent_base
=>$parent,
4416 file_name
=>$diff->{'file'})},
4420 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4421 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4424 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4425 file_name
=>$diff->{'file'})},
4428 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4429 file_name
=>$diff->{'file'})},
4433 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4434 my %status_name = ('R' => 'moved', 'C' => 'copied');
4435 my $nstatus = $status_name{$diff->{'status'}};
4437 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4438 # mode also for directories, so we cannot use $to_mode_str
4439 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4442 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4443 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4444 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4445 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4446 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4447 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4448 -class => "list"}, esc_path
($diff->{'from_file'})) .
4449 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4450 "<td class=\"link\">";
4451 if ($action eq 'commitdiff') {
4454 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4456 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4457 # "commit" view and modified file (not only pure rename or copy)
4458 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4459 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4460 hash_base
=>$hash, hash_parent_base
=>$parent,
4461 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4465 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4466 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4469 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4470 file_name
=>$diff->{'to_file'})},
4473 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4474 file_name
=>$diff->{'to_file'})},
4478 } # we should not encounter Unmerged (U) or Unknown (X) status
4481 print "</tbody>" if $has_header;
4485 sub git_patchset_body
{
4486 my ($fd, $difftree, $hash, @hash_parents) = @_;
4487 my ($hash_parent) = $hash_parents[0];
4489 my $is_combined = (@hash_parents > 1);
4491 my $patch_number = 0;
4497 print "<div class=\"patchset\">\n";
4499 # skip to first patch
4500 while ($patch_line = <$fd>) {
4503 last if ($patch_line =~ m/^diff /);
4507 while ($patch_line) {
4509 # parse "git diff" header line
4510 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4511 # $1 is from_name, which we do not use
4512 $to_name = unquote
($2);
4513 $to_name =~ s!^b/!!;
4514 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4515 # $1 is 'cc' or 'combined', which we do not use
4516 $to_name = unquote
($2);
4521 # check if current patch belong to current raw line
4522 # and parse raw git-diff line if needed
4523 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4524 # this is continuation of a split patch
4525 print "<div class=\"patch cont\">\n";
4527 # advance raw git-diff output if needed
4528 $patch_idx++ if defined $diffinfo;
4530 # read and prepare patch information
4531 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4533 # compact combined diff output can have some patches skipped
4534 # find which patch (using pathname of result) we are at now;
4536 while ($to_name ne $diffinfo->{'to_file'}) {
4537 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4538 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4539 "</div>\n"; # class="patch"
4544 last if $patch_idx > $#$difftree;
4545 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4549 # modifies %from, %to hashes
4550 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4552 # this is first patch for raw difftree line with $patch_idx index
4553 # we index @$difftree array from 0, but number patches from 1
4554 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4558 #assert($patch_line =~ m/^diff /) if DEBUG;
4559 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4561 # print "git diff" header
4562 print format_git_diff_header_line
($patch_line, $diffinfo,
4565 # print extended diff header
4566 print "<div class=\"diff extended_header\">\n";
4568 while ($patch_line = <$fd>) {
4571 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4573 print format_extended_diff_header_line
($patch_line, $diffinfo,
4576 print "</div>\n"; # class="diff extended_header"
4578 # from-file/to-file diff header
4579 if (! $patch_line) {
4580 print "</div>\n"; # class="patch"
4583 next PATCH
if ($patch_line =~ m/^diff /);
4584 #assert($patch_line =~ m/^---/) if DEBUG;
4586 my $last_patch_line = $patch_line;
4587 $patch_line = <$fd>;
4589 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4591 print format_diff_from_to_header
($last_patch_line, $patch_line,
4592 $diffinfo, \
%from, \
%to,
4597 while ($patch_line = <$fd>) {
4600 next PATCH
if ($patch_line =~ m/^diff /);
4602 print format_diff_line
($patch_line, \
%from, \
%to);
4606 print "</div>\n"; # class="patch"
4609 # for compact combined (--cc) format, with chunk and patch simplification
4610 # the patchset might be empty, but there might be unprocessed raw lines
4611 for (++$patch_idx if $patch_number > 0;
4612 $patch_idx < @
$difftree;
4614 # read and prepare patch information
4615 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4617 # generate anchor for "patch" links in difftree / whatchanged part
4618 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4619 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4620 "</div>\n"; # class="patch"
4625 if ($patch_number == 0) {
4626 if (@hash_parents > 1) {
4627 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4629 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4633 print "</div>\n"; # class="patchset"
4636 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4638 # fills project list info (age, description, owner, forks) for each
4639 # project in the list, removing invalid projects from returned list
4640 # NOTE: modifies $projlist, but does not remove entries from it
4641 sub fill_project_list_info
{
4642 my ($projlist, $check_forks) = @_;
4645 my $show_ctags = gitweb_check_feature
('ctags');
4647 foreach my $pr (@
$projlist) {
4648 my (@activity) = git_get_last_activity
($pr->{'path'});
4649 unless (@activity) {
4652 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4653 if (!defined $pr->{'descr'}) {
4654 my $descr = git_get_project_description
($pr->{'path'}) || "";
4655 $descr = to_utf8
($descr);
4656 $pr->{'descr_long'} = $descr;
4657 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4659 if (!defined $pr->{'owner'}) {
4660 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4663 my $pname = $pr->{'path'};
4664 if (($pname =~ s/\.git$//) &&
4665 ($pname !~ /\/$/) &&
4666 (-d
"$projectroot/$pname")) {
4667 $pr->{'forks'} = "-d $projectroot/$pname";
4672 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4673 push @projects, $pr;
4679 # print 'sort by' <th> element, generating 'sort by $name' replay link
4680 # if that order is not selected
4682 print format_sort_th
(@_);
4685 sub format_sort_th
{
4686 my ($name, $order, $header) = @_;
4688 $header ||= ucfirst($name);
4690 if ($order eq $name) {
4691 $sort_th .= "<th>$header</th>\n";
4693 $sort_th .= "<th>" .
4694 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4695 -class => "header"}, $header) .
4702 sub git_project_list_body
{
4703 # actually uses global variable $project
4704 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4706 my $check_forks = gitweb_check_feature
('forks');
4707 my @projects = fill_project_list_info
($projlist, $check_forks);
4709 $order ||= $default_projects_order;
4710 $from = 0 unless defined $from;
4711 $to = $#projects if (!defined $to || $#projects < $to);
4714 project
=> { key
=> 'path', type
=> 'str' },
4715 descr
=> { key
=> 'descr_long', type
=> 'str' },
4716 owner
=> { key
=> 'owner', type
=> 'str' },
4717 age
=> { key
=> 'age', type
=> 'num' }
4719 my $oi = $order_info{$order};
4720 if ($oi->{'type'} eq 'str') {
4721 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4723 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4726 my $show_ctags = gitweb_check_feature
('ctags');
4729 foreach my $p (@projects) {
4730 foreach my $ct (keys %{$p->{'ctags'}}) {
4731 $ctags{$ct} += $p->{'ctags'}->{$ct};
4734 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4735 print git_show_project_tagcloud
($cloud, 64);
4738 print "<table class=\"project_list\">\n";
4739 unless ($no_header) {
4742 print "<th></th>\n";
4744 print_sort_th
('project', $order, 'Project');
4745 print_sort_th
('descr', $order, 'Description');
4746 print_sort_th
('owner', $order, 'Owner');
4747 print_sort_th
('age', $order, 'Last Change');
4748 print "<th></th>\n" . # for links
4752 my $tagfilter = $cgi->param('by_tag');
4753 for (my $i = $from; $i <= $to; $i++) {
4754 my $pr = $projects[$i];
4756 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4757 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4758 and not $pr->{'descr_long'} =~ /$searchtext/;
4759 # Weed out forks or non-matching entries of search
4761 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4762 $forkbase="^$forkbase" if $forkbase;
4763 next if not $searchtext and not $tagfilter and $show_ctags
4764 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4768 print "<tr class=\"dark\">\n";
4770 print "<tr class=\"light\">\n";
4775 if ($pr->{'forks'}) {
4776 print "<!-- $pr->{'forks'} -->\n";
4777 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4781 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4782 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4783 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4784 -class => "list", -title
=> $pr->{'descr_long'}},
4785 esc_html
($pr->{'descr'})) . "</td>\n" .
4786 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4787 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4788 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4789 "<td class=\"link\">" .
4790 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4791 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4792 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4793 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4794 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4798 if (defined $extra) {
4801 print "<td></td>\n";
4803 print "<td colspan=\"5\">$extra</td>\n" .
4810 # uses global variable $project
4811 my ($commitlist, $from, $to, $refs, $extra) = @_;
4813 $from = 0 unless defined $from;
4814 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4816 for (my $i = 0; $i <= $to; $i++) {
4817 my %co = %{$commitlist->[$i]};
4819 my $commit = $co{'id'};
4820 my $ref = format_ref_marker
($refs, $commit);
4821 my %ad = parse_date
($co{'author_epoch'});
4822 git_print_header_div
('commit',
4823 "<span class=\"age\">$co{'age_string'}</span>" .
4824 esc_html
($co{'title'}) . $ref,
4826 print "<div class=\"title_text\">\n" .
4827 "<div class=\"log_link\">\n" .
4828 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4830 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4832 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4835 git_print_authorship
(\
%co, -tag
=> 'span');
4836 print "<br/>\n</div>\n";
4838 print "<div class=\"log_body\">\n";
4839 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4843 print "<div class=\"page_nav\">\n";
4849 sub git_shortlog_body
{
4850 # uses global variable $project
4851 my ($commitlist, $from, $to, $refs, $extra) = @_;
4853 $from = 0 unless defined $from;
4854 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4856 print "<table class=\"shortlog\">\n";
4858 for (my $i = $from; $i <= $to; $i++) {
4859 my %co = %{$commitlist->[$i]};
4860 my $commit = $co{'id'};
4861 my $ref = format_ref_marker
($refs, $commit);
4863 print "<tr class=\"dark\">\n";
4865 print "<tr class=\"light\">\n";
4868 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4869 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4870 format_author_html
('td', \
%co, 10) . "<td>";
4871 print format_subject_html
($co{'title'}, $co{'title_short'},
4872 href
(action
=>"commit", hash
=>$commit), $ref);
4874 "<td class=\"link\">" .
4875 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4876 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4877 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4878 my $snapshot_links = format_snapshot_links
($commit);
4879 if (defined $snapshot_links) {
4880 print " | " . $snapshot_links;
4885 if (defined $extra) {
4887 "<td colspan=\"4\">$extra</td>\n" .
4893 sub git_history_body
{
4894 # Warning: assumes constant type (blob or tree) during history
4895 my ($commitlist, $from, $to, $refs, $extra,
4896 $file_name, $file_hash, $ftype) = @_;
4898 $from = 0 unless defined $from;
4899 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4901 print "<table class=\"history\">\n";
4903 for (my $i = $from; $i <= $to; $i++) {
4904 my %co = %{$commitlist->[$i]};
4908 my $commit = $co{'id'};
4910 my $ref = format_ref_marker
($refs, $commit);
4913 print "<tr class=\"dark\">\n";
4915 print "<tr class=\"light\">\n";
4918 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4919 # shortlog: format_author_html('td', \%co, 10)
4920 format_author_html
('td', \
%co, 15, 3) . "<td>";
4921 # originally git_history used chop_str($co{'title'}, 50)
4922 print format_subject_html
($co{'title'}, $co{'title_short'},
4923 href
(action
=>"commit", hash
=>$commit), $ref);
4925 "<td class=\"link\">" .
4926 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4927 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4929 if ($ftype eq 'blob') {
4930 my $blob_current = $file_hash;
4931 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4932 if (defined $blob_current && defined $blob_parent &&
4933 $blob_current ne $blob_parent) {
4935 $cgi->a({-href
=> href
(action
=>"blobdiff",
4936 hash
=>$blob_current, hash_parent
=>$blob_parent,
4937 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4938 file_name
=>$file_name)},
4945 if (defined $extra) {
4947 "<td colspan=\"4\">$extra</td>\n" .
4954 # uses global variable $project
4955 my ($taglist, $from, $to, $extra) = @_;
4956 $from = 0 unless defined $from;
4957 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4959 print "<table class=\"tags\">\n";
4961 for (my $i = $from; $i <= $to; $i++) {
4962 my $entry = $taglist->[$i];
4964 my $comment = $tag{'subject'};
4966 if (defined $comment) {
4967 $comment_short = chop_str
($comment, 30, 5);
4970 print "<tr class=\"dark\">\n";
4972 print "<tr class=\"light\">\n";
4975 if (defined $tag{'age'}) {
4976 print "<td><i>$tag{'age'}</i></td>\n";
4978 print "<td></td>\n";
4981 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4982 -class => "list name"}, esc_html
($tag{'name'})) .
4985 if (defined $comment) {
4986 print format_subject_html
($comment, $comment_short,
4987 href
(action
=>"tag", hash
=>$tag{'id'}));
4990 "<td class=\"selflink\">";
4991 if ($tag{'type'} eq "tag") {
4992 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4997 "<td class=\"link\">" . " | " .
4998 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4999 if ($tag{'reftype'} eq "commit") {
5000 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
5001 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
5002 } elsif ($tag{'reftype'} eq "blob") {
5003 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
5008 if (defined $extra) {
5010 "<td colspan=\"5\">$extra</td>\n" .
5016 sub git_heads_body
{
5017 # uses global variable $project
5018 my ($headlist, $head, $from, $to, $extra) = @_;
5019 $from = 0 unless defined $from;
5020 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
5022 print "<table class=\"heads\">\n";
5024 for (my $i = $from; $i <= $to; $i++) {
5025 my $entry = $headlist->[$i];
5027 my $curr = $ref{'id'} eq $head;
5029 print "<tr class=\"dark\">\n";
5031 print "<tr class=\"light\">\n";
5034 print "<td><i>$ref{'age'}</i></td>\n" .
5035 ($curr ?
"<td class=\"current_head\">" : "<td>") .
5036 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
5037 -class => "list name"},esc_html
($ref{'name'})) .
5039 "<td class=\"link\">" .
5040 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
5041 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
5042 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'fullname'})}, "tree") .
5046 if (defined $extra) {
5048 "<td colspan=\"3\">$extra</td>\n" .
5054 sub git_search_grep_body
{
5055 my ($commitlist, $from, $to, $extra) = @_;
5056 $from = 0 unless defined $from;
5057 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5059 print "<table class=\"commit_search\">\n";
5061 for (my $i = $from; $i <= $to; $i++) {
5062 my %co = %{$commitlist->[$i]};
5066 my $commit = $co{'id'};
5068 print "<tr class=\"dark\">\n";
5070 print "<tr class=\"light\">\n";
5073 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5074 format_author_html
('td', \
%co, 15, 5) .
5076 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5077 -class => "list subject"},
5078 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5079 my $comment = $co{'comment'};
5080 foreach my $line (@
$comment) {
5081 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5082 my ($lead, $match, $trail) = ($1, $2, $3);
5083 $match = chop_str
($match, 70, 5, 'center');
5084 my $contextlen = int((80 - length($match))/2);
5085 $contextlen = 30 if ($contextlen > 30);
5086 $lead = chop_str
($lead, $contextlen, 10, 'left');
5087 $trail = chop_str
($trail, $contextlen, 10, 'right');
5089 $lead = esc_html
($lead);
5090 $match = esc_html
($match);
5091 $trail = esc_html
($trail);
5093 print "$lead<span class=\"match\">$match</span>$trail<br />";
5097 "<td class=\"link\">" .
5098 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5100 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5102 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5106 if (defined $extra) {
5108 "<td colspan=\"3\">$extra</td>\n" .
5114 ## ======================================================================
5115 ## ======================================================================
5118 sub git_project_list
{
5119 my $order = $input_params{'order'};
5120 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5121 die_error
(400, "Unknown order parameter");
5124 my @list = git_get_projects_list
();
5126 die_error
(404, "No projects found");
5130 if (defined $home_text && -f
$home_text) {
5131 print "<div class=\"index_include\">\n";
5132 insert_file
($home_text);
5135 print $cgi->startform(-method
=> "get") .
5136 "<p class=\"projsearch\">Search:\n" .
5137 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5139 $cgi->end_form() . "\n";
5140 git_project_list_body
(\
@list, $order);
5145 my $order = $input_params{'order'};
5146 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5147 die_error
(400, "Unknown order parameter");
5150 my @list = git_get_projects_list
($project);
5152 die_error
(404, "No forks found");
5156 git_print_page_nav
('','');
5157 git_print_header_div
('summary', "$project forks");
5158 git_project_list_body
(\
@list, $order);
5162 sub git_project_index
{
5163 my @projects = git_get_projects_list
($project);
5166 -type
=> 'text/plain',
5167 -charset
=> 'utf-8',
5168 -content_disposition
=> 'inline; filename="index.aux"');
5170 foreach my $pr (@projects) {
5171 if (!exists $pr->{'owner'}) {
5172 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5175 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5176 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5177 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5178 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5182 print "$path $owner\n";
5187 my $descr = git_get_project_description
($project) || "none";
5188 my %co = parse_commit
("HEAD");
5189 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5190 my $head = $co{'id'};
5191 my $remote_heads = gitweb_check_feature
('remote_heads');
5193 my $owner = git_get_project_owner
($project);
5195 my $refs = git_get_references
();
5196 # These get_*_list functions return one more to allow us to see if
5197 # there are more ...
5198 my @taglist = git_get_tags_list
(16);
5199 my @headlist = git_get_heads_list
(16);
5200 my @remotelist = $remote_heads ? git_get_heads_list
(16, 'remotes') : ();
5202 my $check_forks = gitweb_check_feature
('forks');
5205 @forklist = git_get_projects_list
($project);
5209 git_print_page_nav
('summary','', $head);
5211 print "<div class=\"title\"> </div>\n";
5212 print "<table class=\"projects_list\">\n" .
5213 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5214 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5215 if (defined $cd{'rfc2822'}) {
5216 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5219 # use per project git URL list in $projectroot/$project/cloneurl
5220 # or make project git URL from git base URL and project name
5221 my $url_tag = "URL";
5222 my @url_list = git_get_project_url_list
($project);
5223 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5224 foreach my $git_url (@url_list) {
5225 next unless $git_url;
5226 print format_repo_url
($url_tag, $git_url);
5231 my $show_ctags = gitweb_check_feature
('ctags');
5233 my $ctags = git_get_project_ctags
($project);
5234 my $cloud = git_populate_project_tagcloud
($ctags);
5235 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5236 print "</td>\n<td>" unless %$ctags;
5237 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5238 print "</td>\n<td>" if %$ctags;
5239 print git_show_project_tagcloud
($cloud, 48);
5245 # If XSS prevention is on, we don't include README.html.
5246 # TODO: Allow a readme in some safe format.
5247 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5248 print "<div class=\"title\">readme</div>\n" .
5249 "<div class=\"readme\">\n";
5250 insert_file
("$projectroot/$project/README.html");
5251 print "\n</div>\n"; # class="readme"
5254 # we need to request one more than 16 (0..15) to check if
5256 my @commitlist = $head ? parse_commits
($head, 17) : ();
5258 git_print_header_div
('shortlog');
5259 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5260 $#commitlist <= 15 ?
undef :
5261 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5265 git_print_header_div
('tags');
5266 git_tags_body
(\
@taglist, 0, 15,
5267 $#taglist <= 15 ?
undef :
5268 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5272 git_print_header_div
('heads');
5273 git_heads_body
(\
@headlist, $head, 0, 15,
5274 $#headlist <= 15 ?
undef :
5275 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5279 git_print_header_div
('remotes');
5280 git_heads_body
(\
@remotelist, $head, 0, 15,
5281 $#remotelist <= 15 ?
undef :
5282 $cgi->a({-href
=> href
(action
=>"remotes")}, "..."));
5286 git_print_header_div
('forks');
5287 git_project_list_body
(\
@forklist, 'age', 0, 15,
5288 $#forklist <= 15 ?
undef :
5289 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5297 my %tag = parse_tag
($hash);
5300 die_error
(404, "Unknown tag object");
5303 my $head = git_get_head_hash
($project);
5305 git_print_page_nav
('','', $head,undef,$head);
5306 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5307 print "<div class=\"title_text\">\n" .
5308 "<table class=\"object_header\">\n" .
5310 "<td>object</td>\n" .
5311 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5312 $tag{'object'}) . "</td>\n" .
5313 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5314 $tag{'type'}) . "</td>\n" .
5316 if (defined($tag{'author'})) {
5317 git_print_authorship_rows
(\
%tag, 'author');
5319 print "</table>\n\n" .
5321 print "<div class=\"page_body\">";
5322 my $comment = $tag{'comment'};
5323 foreach my $line (@
$comment) {
5325 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5331 sub git_blame_common
{
5332 my $format = shift || 'porcelain';
5333 if ($format eq 'porcelain' && $cgi->param('js')) {
5334 $format = 'incremental';
5335 $action = 'blame_incremental'; # for page title etc
5339 gitweb_check_feature
('blame')
5340 or die_error
(403, "Blame view not allowed");
5343 die_error
(400, "No file name given") unless $file_name;
5344 $hash_base ||= git_get_head_hash
($project);
5345 die_error
(404, "Couldn't find base commit") unless $hash_base;
5346 my %co = parse_commit
($hash_base)
5347 or die_error
(404, "Commit not found");
5349 if (!defined $hash) {
5350 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5351 or die_error
(404, "Error looking up file");
5353 $ftype = git_get_type
($hash);
5354 if ($ftype !~ "blob") {
5355 die_error
(400, "Object is not a blob");
5360 if ($format eq 'incremental') {
5361 # get file contents (as base)
5362 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5363 or die_error
(500, "Open git-cat-file failed");
5364 } elsif ($format eq 'data') {
5365 # run git-blame --incremental
5366 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5367 $hash_base, "--", $file_name
5368 or die_error
(500, "Open git-blame --incremental failed");
5370 # run git-blame --porcelain
5371 open $fd, "-|", git_cmd
(), "blame", '-p',
5372 $hash_base, '--', $file_name
5373 or die_error
(500, "Open git-blame --porcelain failed");
5376 # incremental blame data returns early
5377 if ($format eq 'data') {
5379 -type
=>"text/plain", -charset
=> "utf-8",
5380 -status
=> "200 OK");
5381 local $| = 1; # output autoflush
5384 or print "ERROR $!\n";
5387 if (defined $t0 && gitweb_check_feature
('timed')) {
5389 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5390 ' '.$number_of_git_cmds;
5400 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5403 if ($format eq 'incremental') {
5405 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5406 "blame") . " (non-incremental)";
5409 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5410 "blame") . " (incremental)";
5414 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5417 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5419 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5420 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5421 git_print_page_path
($file_name, $ftype, $hash_base);
5424 if ($format eq 'incremental') {
5425 print "<noscript>\n<div class=\"error\"><center><b>\n".
5426 "This page requires JavaScript to run.\n Use ".
5427 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5430 "</b></center></div>\n</noscript>\n";
5432 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5435 print qq!<div
class="page_body">\n!;
5436 print qq!<div id
="progress_info">... / ...</div
>\n!
5437 if ($format eq 'incremental');
5438 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5439 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5441 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5445 my @rev_color = qw(light dark);
5446 my $num_colors = scalar(@rev_color);
5447 my $current_color = 0;
5449 if ($format eq 'incremental') {
5450 my $color_class = $rev_color[$current_color];
5455 while (my $line = <$fd>) {
5459 print qq!<tr id
="l$linenr" class="$color_class">!.
5460 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5461 qq!<td
class="linenr">!.
5462 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5463 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5467 } else { # porcelain, i.e. ordinary blame
5468 my %metainfo = (); # saves information about commits
5472 while (my $line = <$fd>) {
5474 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5475 # no <lines in group> for subsequent lines in group of lines
5476 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5477 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5478 if (!exists $metainfo{$full_rev}) {
5479 $metainfo{$full_rev} = { 'nprevious' => 0 };
5481 my $meta = $metainfo{$full_rev};
5483 while ($data = <$fd>) {
5485 last if ($data =~ s/^\t//); # contents of line
5486 if ($data =~ /^(\S+)(?: (.*))?$/) {
5487 $meta->{$1} = $2 unless exists $meta->{$1};
5489 if ($data =~ /^previous /) {
5490 $meta->{'nprevious'}++;
5493 my $short_rev = substr($full_rev, 0, 8);
5494 my $author = $meta->{'author'};
5496 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5497 my $date = $date{'iso-tz'};
5499 $current_color = ($current_color + 1) % $num_colors;
5501 my $tr_class = $rev_color[$current_color];
5502 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5503 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5504 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5505 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5507 print "<td class=\"sha1\"";
5508 print " title=\"". esc_html
($author) . ", $date\"";
5509 print " rowspan=\"$group_size\"" if ($group_size > 1);
5511 print $cgi->a({-href
=> href
(action
=>"commit",
5513 file_name
=>$file_name)},
5514 esc_html
($short_rev));
5515 if ($group_size >= 2) {
5516 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5517 if (@author_initials) {
5519 esc_html
(join('', @author_initials));
5525 # 'previous' <sha1 of parent commit> <filename at commit>
5526 if (exists $meta->{'previous'} &&
5527 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5528 $meta->{'parent'} = $1;
5529 $meta->{'file_parent'} = unquote
($2);
5532 exists($meta->{'parent'}) ?
5533 $meta->{'parent'} : $full_rev;
5534 my $linenr_filename =
5535 exists($meta->{'file_parent'}) ?
5536 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5537 my $blamed = href
(action
=> 'blame',
5538 file_name
=> $linenr_filename,
5539 hash_base
=> $linenr_commit);
5540 print "<td class=\"linenr\">";
5541 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5542 -class => "linenr" },
5545 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5553 "</table>\n"; # class="blame"
5554 print "</div>\n"; # class="blame_body"
5556 or print "Reading blob failed\n";
5565 sub git_blame_incremental
{
5566 git_blame_common
('incremental');
5569 sub git_blame_data
{
5570 git_blame_common
('data');
5574 my $head = git_get_head_hash
($project);
5576 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('tags'));
5577 git_print_header_div
('summary', $project);
5579 my @tagslist = git_get_tags_list
();
5581 git_tags_body
(\
@tagslist);
5587 my $head = git_get_head_hash
($project);
5589 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('heads'));
5590 git_print_header_div
('summary', $project);
5592 my @headslist = git_get_heads_list
();
5594 git_heads_body
(\
@headslist, $head);
5600 gitweb_check_feature
('remote_heads')
5601 or die_error
(403, "Remote heads view is disabled");
5603 my $head = git_get_head_hash
($project);
5604 my $remote = $input_params{'hash'};
5608 if (defined $remote) {
5609 # only display the heads in a given remote, stripping the
5610 # remote name which is already visible elsewhere
5613 $ref->{'name'} =~ s!^$remote/!!;
5615 } git_get_heads_list
(undef, "remotes/$remote");
5617 @remotelist = git_get_heads_list
(undef, 'remotes');
5620 git_header_html
(undef, undef, -action_extra
=> $remote);
5621 git_print_page_nav
('', '', $head, undef, $head,
5622 format_ref_views
($remote ?
'' : 'remotes'));
5624 if (defined $remote) {
5625 git_print_header_div
('remotes', "$remote remote for $project");
5627 git_print_header_div
('summary', "$project remotes");
5631 git_heads_body
(\
@remotelist, $head);
5637 sub git_blob_plain
{
5641 if (!defined $hash) {
5642 if (defined $file_name) {
5643 my $base = $hash_base || git_get_head_hash
($project);
5644 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5645 or die_error
(404, "Cannot find file");
5647 die_error
(400, "No file name defined");
5649 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5650 # blobs defined by non-textual hash id's can be cached
5654 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5655 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5657 # content-type (can include charset)
5658 $type = blob_contenttype
($fd, $file_name, $type);
5660 # "save as" filename, even when no $file_name is given
5661 my $save_as = "$hash";
5662 if (defined $file_name) {
5663 $save_as = $file_name;
5664 } elsif ($type =~ m/^text\//) {
5668 # With XSS prevention on, blobs of all types except a few known safe
5669 # ones are served with "Content-Disposition: attachment" to make sure
5670 # they don't run in our security domain. For certain image types,
5671 # blob view writes an <img> tag referring to blob_plain view, and we
5672 # want to be sure not to break that by serving the image as an
5673 # attachment (though Firefox 3 doesn't seem to care).
5674 my $sandbox = $prevent_xss &&
5675 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5679 -expires
=> $expires,
5680 -content_disposition
=>
5681 ($sandbox ?
'attachment' : 'inline')
5682 . '; filename="' . $save_as . '"');
5684 binmode STDOUT
, ':raw';
5686 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5693 if (!defined $hash) {
5694 if (defined $file_name) {
5695 my $base = $hash_base || git_get_head_hash
($project);
5696 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5697 or die_error
(404, "Cannot find file");
5699 die_error
(400, "No file name defined");
5701 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5702 # blobs defined by non-textual hash id's can be cached
5706 my $have_blame = gitweb_check_feature
('blame');
5707 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5708 or die_error
(500, "Couldn't cat $file_name, $hash");
5709 my $mimetype = blob_mimetype
($fd, $file_name);
5710 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5711 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5713 return git_blob_plain
($mimetype);
5715 # we can have blame only for text/* mimetype
5716 $have_blame &&= ($mimetype =~ m!^text/!);
5718 my $highlight = gitweb_check_feature
('highlight');
5719 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5720 $fd = run_highlighter
($fd, $highlight, $syntax)
5723 git_header_html
(undef, $expires);
5724 my $formats_nav = '';
5725 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5726 if (defined $file_name) {
5729 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5734 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5737 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5740 $cgi->a({-href
=> href
(action
=>"blob",
5741 hash_base
=>"HEAD", file_name
=>$file_name)},
5745 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5748 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5749 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5751 print "<div class=\"page_nav\">\n" .
5752 "<br/><br/></div>\n" .
5753 "<div class=\"title\">$hash</div>\n";
5755 git_print_page_path
($file_name, "blob", $hash_base);
5756 print "<div class=\"page_body\">\n";
5757 if ($mimetype =~ m!^image/!) {
5758 print qq!<img type
="$mimetype"!;
5760 print qq! alt
="$file_name" title
="$file_name"!;
5763 href(action=>"blob_plain
", hash=>$hash,
5764 hash_base=>$hash_base, file_name=>$file_name) .
5768 while (my $line = <$fd>) {
5771 $line = untabify
($line);
5772 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5773 $nr, href
(-replay
=> 1), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5777 or print "Reading blob failed.\n";
5783 if (!defined $hash_base) {
5784 $hash_base = "HEAD";
5786 if (!defined $hash) {
5787 if (defined $file_name) {
5788 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5793 die_error
(404, "No such tree") unless defined($hash);
5795 my $show_sizes = gitweb_check_feature
('show-sizes');
5796 my $have_blame = gitweb_check_feature
('blame');
5801 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5802 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5803 or die_error
(500, "Open git-ls-tree failed");
5804 @entries = map { chomp; $_ } <$fd>;
5806 or die_error
(404, "Reading tree failed");
5809 my $refs = git_get_references
();
5810 my $ref = format_ref_marker
($refs, $hash_base);
5813 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5815 if (defined $file_name) {
5817 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5819 $cgi->a({-href
=> href
(action
=>"tree",
5820 hash_base
=>"HEAD", file_name
=>$file_name)},
5823 my $snapshot_links = format_snapshot_links
($hash);
5824 if (defined $snapshot_links) {
5825 # FIXME: Should be available when we have no hash base as well.
5826 push @views_nav, $snapshot_links;
5828 git_print_page_nav
('tree','', $hash_base, undef, undef,
5829 join(' | ', @views_nav));
5830 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5833 print "<div class=\"page_nav\">\n";
5834 print "<br/><br/></div>\n";
5835 print "<div class=\"title\">$hash</div>\n";
5837 if (defined $file_name) {
5838 $basedir = $file_name;
5839 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5842 git_print_page_path
($file_name, 'tree', $hash_base);
5844 print "<div class=\"page_body\">\n";
5845 print "<table class=\"tree\">\n";
5847 # '..' (top directory) link if possible
5848 if (defined $hash_base &&
5849 defined $file_name && $file_name =~ m![^/]+$!) {
5851 print "<tr class=\"dark\">\n";
5853 print "<tr class=\"light\">\n";
5857 my $up = $file_name;
5858 $up =~ s!/?[^/]+$!!;
5859 undef $up unless $up;
5860 # based on git_print_tree_entry
5861 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5862 print '<td class="size"> </td>'."\n" if $show_sizes;
5863 print '<td class="list">';
5864 print $cgi->a({-href
=> href
(action
=>"tree",
5865 hash_base
=>$hash_base,
5869 print "<td class=\"link\"></td>\n";
5873 foreach my $line (@entries) {
5874 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5877 print "<tr class=\"dark\">\n";
5879 print "<tr class=\"light\">\n";
5883 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5887 print "</table>\n" .
5893 my ($project, $hash) = @_;
5895 # path/to/project.git -> project
5896 # path/to/project/.git -> project
5897 my $name = to_utf8
($project);
5898 $name =~ s
,([^/])/*\
.git
$,$1,;
5899 $name = basename
($name);
5901 $name =~ s/[[:cntrl:]]/?/g;
5904 if ($hash =~ /^[0-9a-fA-F]+$/) {
5905 # shorten SHA-1 hash
5906 my $full_hash = git_get_full_hash
($project, $hash);
5907 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5908 $ver = git_get_short_hash
($project, $hash);
5910 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5911 # tags don't need shortened SHA-1 hash
5914 # branches and other need shortened SHA-1 hash
5915 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5918 $ver .= '-' . git_get_short_hash
($project, $hash);
5920 # in case of hierarchical branch names
5923 # name = project-version_string
5924 $name = "$name-$ver";
5926 return wantarray ?
($name, $name) : $name;
5930 my $format = $input_params{'snapshot_format'};
5931 if (!@snapshot_fmts) {
5932 die_error
(403, "Snapshots not allowed");
5934 # default to first supported snapshot format
5935 $format ||= $snapshot_fmts[0];
5936 if ($format !~ m/^[a-z0-9]+$/) {
5937 die_error
(400, "Invalid snapshot format parameter");
5938 } elsif (!exists($known_snapshot_formats{$format})) {
5939 die_error
(400, "Unknown snapshot format");
5940 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5941 die_error
(403, "Snapshot format not allowed");
5942 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5943 die_error
(403, "Unsupported snapshot format");
5946 my $type = git_get_type
("$hash^{}");
5948 die_error
(404, 'Object does not exist');
5949 } elsif ($type eq 'blob') {
5950 die_error
(400, 'Object is not a tree-ish');
5953 my ($name, $prefix) = snapshot_name
($project, $hash);
5954 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5955 my $cmd = quote_command
(
5956 git_cmd
(), 'archive',
5957 "--format=$known_snapshot_formats{$format}{'format'}",
5958 "--prefix=$prefix/", $hash);
5959 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5960 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5963 $filename =~ s/(["\\])/\\$1/g;
5965 -type
=> $known_snapshot_formats{$format}{'type'},
5966 -content_disposition
=> 'inline; filename="' . $filename . '"',
5967 -status
=> '200 OK');
5969 open my $fd, "-|", $cmd
5970 or die_error
(500, "Execute git-archive failed");
5971 binmode STDOUT
, ':raw';
5973 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5977 sub git_log_generic
{
5978 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5980 my $head = git_get_head_hash
($project);
5981 if (!defined $base) {
5984 if (!defined $page) {
5987 my $refs = git_get_references
();
5989 my $commit_hash = $base;
5990 if (defined $parent) {
5991 $commit_hash = "$parent..$base";
5994 parse_commits
($commit_hash, 101, (100 * $page),
5995 defined $file_name ?
($file_name, "--full-history") : ());
5998 if (!defined $file_hash && defined $file_name) {
5999 # some commits could have deleted file in question,
6000 # and not have it in tree, but one of them has to have it
6001 for (my $i = 0; $i < @commitlist; $i++) {
6002 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
6003 last if defined $file_hash;
6006 if (defined $file_hash) {
6007 $ftype = git_get_type
($file_hash);
6009 if (defined $file_name && !defined $ftype) {
6010 die_error
(500, "Unknown type of object");
6013 if (defined $file_name) {
6014 %co = parse_commit
($base)
6015 or die_error
(404, "Unknown commit object");
6019 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
6021 if ($#commitlist >= 100) {
6023 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6024 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6026 my $patch_max = gitweb_get_feature
('patches');
6027 if ($patch_max && !defined $file_name) {
6028 if ($patch_max < 0 || @commitlist <= $patch_max) {
6029 $paging_nav .= " ⋅ " .
6030 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6036 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
6037 if (defined $file_name) {
6038 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
6040 git_print_header_div
('summary', $project)
6042 git_print_page_path
($file_name, $ftype, $hash_base)
6043 if (defined $file_name);
6045 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
6046 $file_name, $file_hash, $ftype);
6052 git_log_generic
('log', \
&git_log_body
,
6053 $hash, $hash_parent);
6057 $hash ||= $hash_base || "HEAD";
6058 my %co = parse_commit
($hash)
6059 or die_error
(404, "Unknown commit object");
6061 my $parent = $co{'parent'};
6062 my $parents = $co{'parents'}; # listref
6064 # we need to prepare $formats_nav before any parameter munging
6066 if (!defined $parent) {
6068 $formats_nav .= '(initial)';
6069 } elsif (@
$parents == 1) {
6070 # single parent commit
6073 $cgi->a({-href
=> href
(action
=>"commit",
6075 esc_html
(substr($parent, 0, 7))) .
6082 $cgi->a({-href
=> href
(action
=>"commit",
6084 esc_html
(substr($_, 0, 7)));
6088 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
6089 $formats_nav .= " | " .
6090 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6094 if (!defined $parent) {
6098 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
6100 (@
$parents <= 1 ?
$parent : '-c'),
6102 or die_error
(500, "Open git-diff-tree failed");
6103 @difftree = map { chomp; $_ } <$fd>;
6104 close $fd or die_error
(404, "Reading git-diff-tree failed");
6106 # non-textual hash id's can be cached
6108 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6111 my $refs = git_get_references
();
6112 my $ref = format_ref_marker
($refs, $co{'id'});
6114 git_header_html
(undef, $expires);
6115 git_print_page_nav
('commit', '',
6116 $hash, $co{'tree'}, $hash,
6119 if (defined $co{'parent'}) {
6120 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
6122 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
6124 print "<div class=\"title_text\">\n" .
6125 "<table class=\"object_header\">\n";
6126 git_print_authorship_rows
(\
%co);
6127 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6130 "<td class=\"sha1\">" .
6131 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6132 class => "list"}, $co{'tree'}) .
6134 "<td class=\"link\">" .
6135 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6137 my $snapshot_links = format_snapshot_links
($hash);
6138 if (defined $snapshot_links) {
6139 print " | " . $snapshot_links;
6144 foreach my $par (@
$parents) {
6147 "<td class=\"sha1\">" .
6148 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6149 class => "list"}, $par) .
6151 "<td class=\"link\">" .
6152 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6154 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6161 print "<div class=\"page_body\">\n";
6162 git_print_log
($co{'comment'});
6165 git_difftree_body
(\
@difftree, $hash, @
$parents);
6171 # object is defined by:
6172 # - hash or hash_base alone
6173 # - hash_base and file_name
6176 # - hash or hash_base alone
6177 if ($hash || ($hash_base && !defined $file_name)) {
6178 my $object_id = $hash || $hash_base;
6180 open my $fd, "-|", quote_command
(
6181 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6182 or die_error
(404, "Object does not exist");
6186 or die_error
(404, "Object does not exist");
6188 # - hash_base and file_name
6189 } elsif ($hash_base && defined $file_name) {
6190 $file_name =~ s
,/+$,,;
6192 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6193 or die_error
(404, "Base object does not exist");
6195 # here errors should not hapen
6196 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6197 or die_error
(500, "Open git-ls-tree failed");
6201 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6202 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6203 die_error
(404, "File or directory for given base does not exist");
6208 die_error
(400, "Not enough information to find object");
6211 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6212 hash
=>$hash, hash_base
=>$hash_base,
6213 file_name
=>$file_name),
6214 -status
=> '302 Found');
6218 my $format = shift || 'html';
6225 # preparing $fd and %diffinfo for git_patchset_body
6227 if (defined $hash_base && defined $hash_parent_base) {
6228 if (defined $file_name) {
6230 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6231 $hash_parent_base, $hash_base,
6232 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6233 or die_error
(500, "Open git-diff-tree failed");
6234 @difftree = map { chomp; $_ } <$fd>;
6236 or die_error
(404, "Reading git-diff-tree failed");
6238 or die_error
(404, "Blob diff not found");
6240 } elsif (defined $hash &&
6241 $hash =~ /[0-9a-fA-F]{40}/) {
6242 # try to find filename from $hash
6244 # read filtered raw output
6245 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6246 $hash_parent_base, $hash_base, "--"
6247 or die_error
(500, "Open git-diff-tree failed");
6249 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6251 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6252 map { chomp; $_ } <$fd>;
6254 or die_error
(404, "Reading git-diff-tree failed");
6256 or die_error
(404, "Blob diff not found");
6259 die_error
(400, "Missing one of the blob diff parameters");
6262 if (@difftree > 1) {
6263 die_error
(400, "Ambiguous blob diff specification");
6266 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6267 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6268 $file_name ||= $diffinfo{'to_file'};
6270 $hash_parent ||= $diffinfo{'from_id'};
6271 $hash ||= $diffinfo{'to_id'};
6273 # non-textual hash id's can be cached
6274 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6275 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6280 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6281 '-p', ($format eq 'html' ?
"--full-index" : ()),
6282 $hash_parent_base, $hash_base,
6283 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6284 or die_error
(500, "Open git-diff-tree failed");
6287 # old/legacy style URI -- not generated anymore since 1.4.3.
6289 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6293 if ($format eq 'html') {
6295 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6297 git_header_html
(undef, $expires);
6298 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6299 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6300 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6302 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6303 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
6305 if (defined $file_name) {
6306 git_print_page_path
($file_name, "blob", $hash_base);
6308 print "<div class=\"page_path\"></div>\n";
6311 } elsif ($format eq 'plain') {
6313 -type
=> 'text/plain',
6314 -charset
=> 'utf-8',
6315 -expires
=> $expires,
6316 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6318 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6321 die_error
(400, "Unknown blobdiff format");
6325 if ($format eq 'html') {
6326 print "<div class=\"page_body\">\n";
6328 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6331 print "</div>\n"; # class="page_body"
6335 while (my $line = <$fd>) {
6336 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6337 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6341 last if $line =~ m!^\+\+\+!;
6349 sub git_blobdiff_plain
{
6350 git_blobdiff
('plain');
6353 sub git_commitdiff
{
6355 my $format = $params{-format
} || 'html';
6357 my ($patch_max) = gitweb_get_feature
('patches');
6358 if ($format eq 'patch') {
6359 die_error
(403, "Patch view not allowed") unless $patch_max;
6362 $hash ||= $hash_base || "HEAD";
6363 my %co = parse_commit
($hash)
6364 or die_error
(404, "Unknown commit object");
6366 # choose format for commitdiff for merge
6367 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6368 $hash_parent = '--cc';
6370 # we need to prepare $formats_nav before almost any parameter munging
6372 if ($format eq 'html') {
6374 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6376 if ($patch_max && @
{$co{'parents'}} <= 1) {
6377 $formats_nav .= " | " .
6378 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6382 if (defined $hash_parent &&
6383 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6384 # commitdiff with two commits given
6385 my $hash_parent_short = $hash_parent;
6386 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6387 $hash_parent_short = substr($hash_parent, 0, 7);
6391 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6392 if ($co{'parents'}[$i] eq $hash_parent) {
6393 $formats_nav .= ' parent ' . ($i+1);
6397 $formats_nav .= ': ' .
6398 $cgi->a({-href
=> href
(action
=>"commitdiff",
6399 hash
=>$hash_parent)},
6400 esc_html
($hash_parent_short)) .
6402 } elsif (!$co{'parent'}) {
6404 $formats_nav .= ' (initial)';
6405 } elsif (scalar @
{$co{'parents'}} == 1) {
6406 # single parent commit
6409 $cgi->a({-href
=> href
(action
=>"commitdiff",
6410 hash
=>$co{'parent'})},
6411 esc_html
(substr($co{'parent'}, 0, 7))) .
6415 if ($hash_parent eq '--cc') {
6416 $formats_nav .= ' | ' .
6417 $cgi->a({-href
=> href
(action
=>"commitdiff",
6418 hash
=>$hash, hash_parent
=>'-c')},
6420 } else { # $hash_parent eq '-c'
6421 $formats_nav .= ' | ' .
6422 $cgi->a({-href
=> href
(action
=>"commitdiff",
6423 hash
=>$hash, hash_parent
=>'--cc')},
6429 $cgi->a({-href
=> href
(action
=>"commitdiff",
6431 esc_html
(substr($_, 0, 7)));
6432 } @
{$co{'parents'}} ) .
6437 my $hash_parent_param = $hash_parent;
6438 if (!defined $hash_parent_param) {
6439 # --cc for multiple parents, --root for parentless
6440 $hash_parent_param =
6441 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6447 if ($format eq 'html') {
6448 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6449 "--no-commit-id", "--patch-with-raw", "--full-index",
6450 $hash_parent_param, $hash, "--"
6451 or die_error
(500, "Open git-diff-tree failed");
6453 while (my $line = <$fd>) {
6455 # empty line ends raw part of diff-tree output
6457 push @difftree, scalar parse_difftree_raw_line
($line);
6460 } elsif ($format eq 'plain') {
6461 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6462 '-p', $hash_parent_param, $hash, "--"
6463 or die_error
(500, "Open git-diff-tree failed");
6464 } elsif ($format eq 'patch') {
6465 # For commit ranges, we limit the output to the number of
6466 # patches specified in the 'patches' feature.
6467 # For single commits, we limit the output to a single patch,
6468 # diverging from the git-format-patch default.
6469 my @commit_spec = ();
6471 if ($patch_max > 0) {
6472 push @commit_spec, "-$patch_max";
6474 push @commit_spec, '-n', "$hash_parent..$hash";
6476 if ($params{-single
}) {
6477 push @commit_spec, '-1';
6479 if ($patch_max > 0) {
6480 push @commit_spec, "-$patch_max";
6482 push @commit_spec, "-n";
6484 push @commit_spec, '--root', $hash;
6486 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6487 '--encoding=utf8', '--stdout', @commit_spec
6488 or die_error
(500, "Open git-format-patch failed");
6490 die_error
(400, "Unknown commitdiff format");
6493 # non-textual hash id's can be cached
6495 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6499 # write commit message
6500 if ($format eq 'html') {
6501 my $refs = git_get_references
();
6502 my $ref = format_ref_marker
($refs, $co{'id'});
6504 git_header_html
(undef, $expires);
6505 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6506 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6507 print "<div class=\"title_text\">\n" .
6508 "<table class=\"object_header\">\n";
6509 git_print_authorship_rows
(\
%co);
6512 print "<div class=\"page_body\">\n";
6513 if (@
{$co{'comment'}} > 1) {
6514 print "<div class=\"log\">\n";
6515 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6516 print "</div>\n"; # class="log"
6519 } elsif ($format eq 'plain') {
6520 my $refs = git_get_references
("tags");
6521 my $tagname = git_get_rev_name_tags
($hash);
6522 my $filename = basename
($project) . "-$hash.patch";
6525 -type
=> 'text/plain',
6526 -charset
=> 'utf-8',
6527 -expires
=> $expires,
6528 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6529 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6530 print "From: " . to_utf8
($co{'author'}) . "\n";
6531 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6532 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6534 print "X-Git-Tag: $tagname\n" if $tagname;
6535 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6537 foreach my $line (@
{$co{'comment'}}) {
6538 print to_utf8
($line) . "\n";
6541 } elsif ($format eq 'patch') {
6542 my $filename = basename
($project) . "-$hash.patch";
6545 -type
=> 'text/plain',
6546 -charset
=> 'utf-8',
6547 -expires
=> $expires,
6548 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6552 if ($format eq 'html') {
6553 my $use_parents = !defined $hash_parent ||
6554 $hash_parent eq '-c' || $hash_parent eq '--cc';
6555 git_difftree_body
(\
@difftree, $hash,
6556 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6559 git_patchset_body
($fd, \
@difftree, $hash,
6560 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6562 print "</div>\n"; # class="page_body"
6565 } elsif ($format eq 'plain') {
6569 or print "Reading git-diff-tree failed\n";
6570 } elsif ($format eq 'patch') {
6574 or print "Reading git-format-patch failed\n";
6578 sub git_commitdiff_plain
{
6579 git_commitdiff
(-format
=> 'plain');
6582 # format-patch-style patches
6584 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6588 git_commitdiff
(-format
=> 'patch');
6592 git_log_generic
('history', \
&git_history_body
,
6593 $hash_base, $hash_parent_base,
6598 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6599 if (!defined $searchtext) {
6600 die_error
(400, "Text field is empty");
6602 if (!defined $hash) {
6603 $hash = git_get_head_hash
($project);
6605 my %co = parse_commit
($hash);
6607 die_error
(404, "Unknown commit object");
6609 if (!defined $page) {
6613 $searchtype ||= 'commit';
6614 if ($searchtype eq 'pickaxe') {
6615 # pickaxe may take all resources of your box and run for several minutes
6616 # with every query - so decide by yourself how public you make this feature
6617 gitweb_check_feature
('pickaxe')
6618 or die_error
(403, "Pickaxe is disabled");
6620 if ($searchtype eq 'grep') {
6621 gitweb_check_feature
('grep')
6622 or die_error
(403, "Grep is disabled");
6627 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6629 if ($searchtype eq 'commit') {
6630 $greptype = "--grep=";
6631 } elsif ($searchtype eq 'author') {
6632 $greptype = "--author=";
6633 } elsif ($searchtype eq 'committer') {
6634 $greptype = "--committer=";
6636 $greptype .= $searchtext;
6637 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6638 $greptype, '--regexp-ignore-case',
6639 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6641 my $paging_nav = '';
6644 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6645 searchtext
=>$searchtext,
6646 searchtype
=>$searchtype)},
6648 $paging_nav .= " ⋅ " .
6649 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6650 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6652 $paging_nav .= "first";
6653 $paging_nav .= " ⋅ prev";
6656 if ($#commitlist >= 100) {
6658 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6659 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6660 $paging_nav .= " ⋅ $next_link";
6662 $paging_nav .= " ⋅ next";
6665 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6666 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6667 if ($page == 0 && !@commitlist) {
6668 print "<p>No match.</p>\n";
6670 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6674 if ($searchtype eq 'pickaxe') {
6675 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6676 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6678 print "<table class=\"pickaxe search\">\n";
6681 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6682 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6683 ($search_use_regexp ?
'--pickaxe-regex' : ());
6686 while (my $line = <$fd>) {
6690 my %set = parse_difftree_raw_line
($line);
6691 if (defined $set{'commit'}) {
6692 # finish previous commit
6695 "<td class=\"link\">" .
6696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6698 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6704 print "<tr class=\"dark\">\n";
6706 print "<tr class=\"light\">\n";
6709 %co = parse_commit
($set{'commit'});
6710 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6711 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6712 "<td><i>$author</i></td>\n" .
6714 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6715 -class => "list subject"},
6716 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6717 } elsif (defined $set{'to_id'}) {
6718 next if ($set{'to_id'} =~ m/^0{40}$/);
6720 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6721 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6723 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6729 # finish last commit (warning: repetition!)
6732 "<td class=\"link\">" .
6733 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6735 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6743 if ($searchtype eq 'grep') {
6744 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6745 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6747 print "<table class=\"grep_search\">\n";
6751 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6752 $search_use_regexp ?
('-E', '-i') : '-F',
6753 $searchtext, $co{'tree'};
6755 while (my $line = <$fd>) {
6757 my ($file, $lno, $ltext, $binary);
6758 last if ($matches++ > 1000);
6759 if ($line =~ /^Binary file (.+) matches$/) {
6763 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6765 if ($file ne $lastfile) {
6766 $lastfile and print "</td></tr>\n";
6768 print "<tr class=\"dark\">\n";
6770 print "<tr class=\"light\">\n";
6772 print "<td class=\"list\">".
6773 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6774 file_name
=>"$file"),
6775 -class => "list"}, esc_path
($file));
6776 print "</td><td>\n";
6780 print "<div class=\"binary\">Binary file</div>\n";
6782 $ltext = untabify
($ltext);
6783 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6784 $ltext = esc_html
($1, -nbsp
=>1);
6785 $ltext .= '<span class="match">';
6786 $ltext .= esc_html
($2, -nbsp
=>1);
6787 $ltext .= '</span>';
6788 $ltext .= esc_html
($3, -nbsp
=>1);
6790 $ltext = esc_html
($ltext, -nbsp
=>1);
6792 print "<div class=\"pre\">" .
6793 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6794 file_name
=>"$file").'#l'.$lno,
6795 -class => "linenr"}, sprintf('%4i', $lno))
6796 . ' ' . $ltext . "</div>\n";
6800 print "</td></tr>\n";
6801 if ($matches > 1000) {
6802 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6805 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6814 sub git_search_help
{
6816 git_print_page_nav
('','', $hash,$hash,$hash);
6818 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6819 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6820 the pattern entered is recognized as the POSIX extended
6821 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6824 <dt><b>commit</b></dt>
6825 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6827 my $have_grep = gitweb_check_feature
('grep');
6830 <dt><b>grep</b></dt>
6831 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6832 a different one) are searched for the given pattern. On large trees, this search can take
6833 a while and put some strain on the server, so please use it with some consideration. Note that
6834 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6835 case-sensitive.</dd>
6839 <dt><b>author</b></dt>
6840 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6841 <dt><b>committer</b></dt>
6842 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6844 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6845 if ($have_pickaxe) {
6847 <dt><b>pickaxe</b></dt>
6848 <dd>All commits that caused the string to appear or disappear from any file (changes that
6849 added, removed or "modified" the string) will be listed. This search can take a while and
6850 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6851 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6859 git_log_generic
('shortlog', \
&git_shortlog_body
,
6860 $hash, $hash_parent);
6863 ## ......................................................................
6864 ## feeds (RSS, Atom; OPML)
6867 my $format = shift || 'atom';
6868 my $have_blame = gitweb_check_feature
('blame');
6870 # Atom: http://www.atomenabled.org/developers/syndication/
6871 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6872 if ($format ne 'rss' && $format ne 'atom') {
6873 die_error
(400, "Unknown web feed format");
6876 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6877 my $head = $hash || 'HEAD';
6878 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6882 my $content_type = "application/$format+xml";
6883 if (defined $cgi->http('HTTP_ACCEPT') &&
6884 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6885 # browser (feed reader) prefers text/xml
6886 $content_type = 'text/xml';
6888 if (defined($commitlist[0])) {
6889 %latest_commit = %{$commitlist[0]};
6890 my $latest_epoch = $latest_commit{'committer_epoch'};
6891 %latest_date = parse_date
($latest_epoch);
6892 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6893 if (defined $if_modified) {
6895 if (eval { require HTTP
::Date
; 1; }) {
6896 $since = HTTP
::Date
::str2time
($if_modified);
6897 } elsif (eval { require Time
::ParseDate
; 1; }) {
6898 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6900 if (defined $since && $latest_epoch <= $since) {
6902 -type
=> $content_type,
6903 -charset
=> 'utf-8',
6904 -last_modified
=> $latest_date{'rfc2822'},
6905 -status
=> '304 Not Modified');
6910 -type
=> $content_type,
6911 -charset
=> 'utf-8',
6912 -last_modified
=> $latest_date{'rfc2822'});
6915 -type
=> $content_type,
6916 -charset
=> 'utf-8');
6919 # Optimization: skip generating the body if client asks only
6920 # for Last-Modified date.
6921 return if ($cgi->request_method() eq 'HEAD');
6924 my $title = "$site_name - $project/$action";
6925 my $feed_type = 'log';
6926 if (defined $hash) {
6927 $title .= " - '$hash'";
6928 $feed_type = 'branch log';
6929 if (defined $file_name) {
6930 $title .= " :: $file_name";
6931 $feed_type = 'history';
6933 } elsif (defined $file_name) {
6934 $title .= " - $file_name";
6935 $feed_type = 'history';
6937 $title .= " $feed_type";
6938 my $descr = git_get_project_description
($project);
6939 if (defined $descr) {
6940 $descr = esc_html
($descr);
6942 $descr = "$project " .
6943 ($format eq 'rss' ?
'RSS' : 'Atom') .
6946 my $owner = git_get_project_owner
($project);
6947 $owner = esc_html
($owner);
6951 if (defined $file_name) {
6952 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6953 } elsif (defined $hash) {
6954 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6956 $alt_url = href
(-full
=>1, action
=>"summary");
6958 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6959 if ($format eq 'rss') {
6961 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6964 print "<title>$title</title>\n" .
6965 "<link>$alt_url</link>\n" .
6966 "<description>$descr</description>\n" .
6967 "<language>en</language>\n" .
6968 # project owner is responsible for 'editorial' content
6969 "<managingEditor>$owner</managingEditor>\n";
6970 if (defined $logo || defined $favicon) {
6971 # prefer the logo to the favicon, since RSS
6972 # doesn't allow both
6973 my $img = esc_url
($logo || $favicon);
6975 "<url>$img</url>\n" .
6976 "<title>$title</title>\n" .
6977 "<link>$alt_url</link>\n" .
6981 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6982 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6984 print "<generator>gitweb v.$version/$git_version</generator>\n";
6985 } elsif ($format eq 'atom') {
6987 <feed xmlns="http://www.w3.org/2005/Atom">
6989 print "<title>$title</title>\n" .
6990 "<subtitle>$descr</subtitle>\n" .
6991 '<link rel="alternate" type="text/html" href="' .
6992 $alt_url . '" />' . "\n" .
6993 '<link rel="self" type="' . $content_type . '" href="' .
6994 $cgi->self_url() . '" />' . "\n" .
6995 "<id>" . href
(-full
=>1) . "</id>\n" .
6996 # use project owner for feed author
6997 "<author><name>$owner</name></author>\n";
6998 if (defined $favicon) {
6999 print "<icon>" . esc_url
($favicon) . "</icon>\n";
7001 if (defined $logo_url) {
7002 # not twice as wide as tall: 72 x 27 pixels
7003 print "<logo>" . esc_url
($logo) . "</logo>\n";
7005 if (! %latest_date) {
7006 # dummy date to keep the feed valid until commits trickle in:
7007 print "<updated>1970-01-01T00:00:00Z</updated>\n";
7009 print "<updated>$latest_date{'iso-8601'}</updated>\n";
7011 print "<generator version='$version/$git_version'>gitweb</generator>\n";
7015 for (my $i = 0; $i <= $#commitlist; $i++) {
7016 my %co = %{$commitlist[$i]};
7017 my $commit = $co{'id'};
7018 # we read 150, we always show 30 and the ones more recent than 48 hours
7019 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
7022 my %cd = parse_date
($co{'author_epoch'});
7024 # get list of changed files
7025 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7026 $co{'parent'} || "--root",
7027 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
7029 my @difftree = map { chomp; $_ } <$fd>;
7033 # print element (entry, item)
7034 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
7035 if ($format eq 'rss') {
7037 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
7038 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
7039 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
7040 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
7041 "<link>$co_url</link>\n" .
7042 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
7043 "<content:encoded>" .
7045 } elsif ($format eq 'atom') {
7047 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
7048 "<updated>$cd{'iso-8601'}</updated>\n" .
7050 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
7051 if ($co{'author_email'}) {
7052 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
7054 print "</author>\n" .
7055 # use committer for contributor
7057 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
7058 if ($co{'committer_email'}) {
7059 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
7061 print "</contributor>\n" .
7062 "<published>$cd{'iso-8601'}</published>\n" .
7063 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
7064 "<id>$co_url</id>\n" .
7065 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
7066 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
7068 my $comment = $co{'comment'};
7070 foreach my $line (@
$comment) {
7071 $line = esc_html
($line);
7074 print "</pre><ul>\n";
7075 foreach my $difftree_line (@difftree) {
7076 my %difftree = parse_difftree_raw_line
($difftree_line);
7077 next if !$difftree{'from_id'};
7079 my $file = $difftree{'file'} || $difftree{'to_file'};
7083 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
7084 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
7085 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
7086 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
7087 -title
=> "diff"}, 'D');
7089 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
7090 file_name
=>$file, hash_base
=>$commit),
7091 -title
=> "blame"}, 'B');
7093 # if this is not a feed of a file history
7094 if (!defined $file_name || $file_name ne $file) {
7095 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
7096 file_name
=>$file, hash
=>$commit),
7097 -title
=> "history"}, 'H');
7099 $file = esc_path
($file);
7103 if ($format eq 'rss') {
7104 print "</ul>]]>\n" .
7105 "</content:encoded>\n" .
7107 } elsif ($format eq 'atom') {
7108 print "</ul>\n</div>\n" .
7115 if ($format eq 'rss') {
7116 print "</channel>\n</rss>\n";
7117 } elsif ($format eq 'atom') {
7131 my @list = git_get_projects_list
();
7134 -type
=> 'text/xml',
7135 -charset
=> 'utf-8',
7136 -content_disposition
=> 'inline; filename="opml.xml"');
7139 <?xml version="1.0" encoding="utf-8"?>
7140 <opml version="1.0">
7142 <title>$site_name OPML Export</title>
7145 <outline text="git RSS feeds">
7148 foreach my $pr (@list) {
7150 my $head = git_get_head_hash
($proj{'path'});
7151 if (!defined $head) {
7154 $git_dir = "$projectroot/$proj{'path'}";
7155 my %co = parse_commit
($head);
7160 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7161 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7162 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7163 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";