3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
13 use CGI
qw(:standard :escapeHTML -nosticky);
14 use CGI
::Util
qw(unescape);
15 use CGI
::Carp
qw(fatalsToBrowser set_message);
19 use File
::Basename
qw(basename);
20 use Time
::HiRes
qw(gettimeofday tv_interval);
21 binmode STDOUT
, ':utf8';
23 our $t0 = [ gettimeofday
() ];
24 our $number_of_git_cmds = 0;
27 CGI-
>compile() if $ENV{'MOD_PERL'};
30 our $version = "++GIT_VERSION++";
32 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
36 our $my_url = $cgi->url();
37 our $my_uri = $cgi->url(-absolute
=> 1);
39 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
40 # needed and used only for URLs with nonempty PATH_INFO
41 our $base_url = $my_url;
43 # When the script is used as DirectoryIndex, the URL does not contain the name
44 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
45 # have to do it ourselves. We make $path_info global because it's also used
48 # Another issue with the script being the DirectoryIndex is that the resulting
49 # $my_url data is not the full script URL: this is good, because we want
50 # generated links to keep implying the script name if it wasn't explicitly
51 # indicated in the URL we're handling, but it means that $my_url cannot be used
53 # Therefore, if we needed to strip PATH_INFO, then we know that we have
54 # to build the base URL ourselves:
55 our $path_info = decode_utf8
($ENV{"PATH_INFO"});
57 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
58 $my_uri =~ s
,\Q
$path_info\E
$,, &&
59 defined $ENV{'SCRIPT_NAME'}) {
60 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
64 # target of the home link on top of all pages
65 our $home_link = $my_uri || "/";
68 # core git executable to use
69 # this can just be "git" if your webserver has a sensible PATH
70 our $GIT = "++GIT_BINDIR++/git";
72 # absolute fs-path which will be prepended to the project path
73 #our $projectroot = "/pub/scm";
74 our $projectroot = "++GITWEB_PROJECTROOT++";
76 # fs traversing limit for getting project list
77 # the number is relative to the projectroot
78 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
80 # string of the home link on top of all pages
81 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
83 # name of your site or organization to appear in page titles
84 # replace this with something more descriptive for clearer bookmarks
85 our $site_name = "++GITWEB_SITENAME++"
86 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
88 # html snippet to include in the <head> section of each page
89 our $site_html_head_string = "++GITWEB_SITE_HTML_HEAD_STRING++";
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;
102 # URI of GIT logo (72x27 size)
103 our $logo = "++GITWEB_LOGO++";
104 # URI of GIT favicon, assumed to be image/png type
105 our $favicon = "++GITWEB_FAVICON++";
106 # URI of gitweb.js (JavaScript code for gitweb)
107 our $javascript = "++GITWEB_JS++";
109 # URI and label (title) of GIT logo link
110 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
111 #our $logo_label = "git documentation";
112 our $logo_url = "http://git-scm.com/";
113 our $logo_label = "git homepage";
115 # source of projects list
116 our $projects_list = "++GITWEB_LIST++";
118 # the width (in characters) of the projects list "Description" column
119 our $projects_list_description_width = 25;
121 # group projects by category on the projects list
122 # (enabled if this variable evaluates to true)
123 our $projects_list_group_categories = 0;
125 # default category if none specified
126 # (leave the empty string for no category)
127 our $project_list_default_category = "";
129 # default order of projects list
130 # valid values are none, project, descr, owner, and age
131 our $default_projects_order = "project";
133 # show repository only if this file exists
134 # (only effective if this variable evaluates to true)
135 our $export_ok = "++GITWEB_EXPORT_OK++";
137 # show repository only if this subroutine returns true
138 # when given the path to the project, for example:
139 # sub { return -e "$_[0]/git-daemon-export-ok"; }
140 our $export_auth_hook = undef;
142 # only allow viewing of repositories also shown on the overview page
143 our $strict_export = "++GITWEB_STRICT_EXPORT++";
145 # list of git base URLs used for URL to where fetch project from,
146 # i.e. full URL is "$git_base_url/$project"
147 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
149 # default blob_plain mimetype and default charset for text/plain blob
150 our $default_blob_plain_mimetype = 'text/plain';
151 our $default_text_plain_charset = undef;
153 # file to use for guessing MIME types before trying /etc/mime.types
154 # (relative to the current git repository)
155 our $mimetypes_file = undef;
157 # assume this charset if line contains non-UTF-8 characters;
158 # it should be valid encoding (see Encoding::Supported(3pm) for list),
159 # for which encoding all byte sequences are valid, for example
160 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
161 # could be even 'utf-8' for the old behavior)
162 our $fallback_encoding = 'latin1';
164 # rename detection options for git-diff and git-diff-tree
165 # - default is '-M', with the cost proportional to
166 # (number of removed files) * (number of new files).
167 # - more costly is '-C' (which implies '-M'), with the cost proportional to
168 # (number of changed files + number of removed files) * (number of new files)
169 # - even more costly is '-C', '--find-copies-harder' with cost
170 # (number of files in the original tree) * (number of new files)
171 # - one might want to include '-B' option, e.g. '-B', '-M'
172 our @diff_opts = ('-M'); # taken from git_commit
174 # Disables features that would allow repository owners to inject script into
176 our $prevent_xss = 0;
178 # Path to the highlight executable to use (must be the one from
179 # http://www.andre-simon.de due to assumptions about parameters and output).
180 # Useful if highlight is not installed on your webserver's PATH.
181 # [Default: highlight]
182 our $highlight_bin = "++HIGHLIGHT_BIN++";
184 # information about snapshot formats that gitweb is capable of serving
185 our %known_snapshot_formats = (
187 # 'display' => display name,
188 # 'type' => mime type,
189 # 'suffix' => filename suffix,
190 # 'format' => --format for git-archive,
191 # 'compressor' => [compressor command and arguments]
192 # (array reference, optional)
193 # 'disabled' => boolean (optional)}
196 'display' => 'tar.gz',
197 'type' => 'application/x-gzip',
198 'suffix' => '.tar.gz',
200 'compressor' => ['gzip', '-n']},
203 'display' => 'tar.bz2',
204 'type' => 'application/x-bzip2',
205 'suffix' => '.tar.bz2',
207 'compressor' => ['bzip2']},
210 'display' => 'tar.xz',
211 'type' => 'application/x-xz',
212 'suffix' => '.tar.xz',
214 'compressor' => ['xz'],
219 'type' => 'application/x-zip',
224 # Aliases so we understand old gitweb.snapshot values in repository
226 our %known_snapshot_format_aliases = (
231 # backward compatibility: legacy gitweb config support
232 'x-gzip' => undef, 'gz' => undef,
233 'x-bzip2' => undef, 'bz2' => undef,
234 'x-zip' => undef, '' => undef,
237 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
238 # are changed, it may be appropriate to change these values too via
245 # Used to set the maximum load that we will still respond to gitweb queries.
246 # If server load exceed this value then return "503 server busy" error.
247 # If gitweb cannot determined server load, it is taken to be 0.
248 # Leave it undefined (or set to 'undef') to turn off load checking.
251 # configuration for 'highlight' (http://www.andre-simon.de/)
253 our %highlight_basename = (
256 'SConstruct' => 'py', # SCons equivalent of Makefile
257 'Makefile' => 'make',
260 our %highlight_ext = (
261 # main extensions, defining name of syntax;
262 # see files in /usr/share/highlight/langDefs/ directory
264 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make),
265 # alternate extensions, see /etc/highlight/filetypes.conf
267 map { $_ => 'sh' } qw(bash zsh ksh),
268 map { $_ => 'cpp' } qw(cxx c++ cc),
269 map { $_ => 'php' } qw(php3 php4 php5 phps),
270 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
271 map { $_ => 'make'} qw(mak mk),
272 map { $_ => 'xml' } qw(xhtml html htm),
275 # You define site-wide feature defaults here; override them with
276 # $GITWEB_CONFIG as necessary.
279 # 'sub' => feature-sub (subroutine),
280 # 'override' => allow-override (boolean),
281 # 'default' => [ default options...] (array reference)}
283 # if feature is overridable (it means that allow-override has true value),
284 # then feature-sub will be called with default options as parameters;
285 # return value of feature-sub indicates if to enable specified feature
287 # if there is no 'sub' key (no feature-sub), then feature cannot be
290 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
291 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
294 # Enable the 'blame' blob view, showing the last commit that modified
295 # each line in the file. This can be very CPU-intensive.
297 # To enable system wide have in $GITWEB_CONFIG
298 # $feature{'blame'}{'default'} = [1];
299 # To have project specific config enable override in $GITWEB_CONFIG
300 # $feature{'blame'}{'override'} = 1;
301 # and in project config gitweb.blame = 0|1;
303 'sub' => sub { feature_bool
('blame', @_) },
307 # Enable the 'snapshot' link, providing a compressed archive of any
308 # tree. This can potentially generate high traffic if you have large
311 # Value is a list of formats defined in %known_snapshot_formats that
313 # To disable system wide have in $GITWEB_CONFIG
314 # $feature{'snapshot'}{'default'} = [];
315 # To have project specific config enable override in $GITWEB_CONFIG
316 # $feature{'snapshot'}{'override'} = 1;
317 # and in project config, a comma-separated list of formats or "none"
318 # to disable. Example: gitweb.snapshot = tbz2,zip;
320 'sub' => \
&feature_snapshot
,
322 'default' => ['tgz']},
324 # Enable text search, which will list the commits which match author,
325 # committer or commit text to a given string. Enabled by default.
326 # Project specific override is not supported.
328 # Note that this controls all search features, which means that if
329 # it is disabled, then 'grep' and 'pickaxe' search would also be
335 # Enable grep search, which will list the files in currently selected
336 # tree containing the given string. Enabled by default. This can be
337 # potentially CPU-intensive, of course.
338 # Note that you need to have 'search' feature enabled too.
340 # To enable system wide have in $GITWEB_CONFIG
341 # $feature{'grep'}{'default'} = [1];
342 # To have project specific config enable override in $GITWEB_CONFIG
343 # $feature{'grep'}{'override'} = 1;
344 # and in project config gitweb.grep = 0|1;
346 'sub' => sub { feature_bool
('grep', @_) },
350 # Enable the pickaxe search, which will list the commits that modified
351 # a given string in a file. This can be practical and quite faster
352 # alternative to 'blame', but still potentially CPU-intensive.
353 # Note that you need to have 'search' feature enabled too.
355 # To enable system wide have in $GITWEB_CONFIG
356 # $feature{'pickaxe'}{'default'} = [1];
357 # To have project specific config enable override in $GITWEB_CONFIG
358 # $feature{'pickaxe'}{'override'} = 1;
359 # and in project config gitweb.pickaxe = 0|1;
361 'sub' => sub { feature_bool
('pickaxe', @_) },
365 # Enable showing size of blobs in a 'tree' view, in a separate
366 # column, similar to what 'ls -l' does. This cost a bit of IO.
368 # To disable system wide have in $GITWEB_CONFIG
369 # $feature{'show-sizes'}{'default'} = [0];
370 # To have project specific config enable override in $GITWEB_CONFIG
371 # $feature{'show-sizes'}{'override'} = 1;
372 # and in project config gitweb.showsizes = 0|1;
374 'sub' => sub { feature_bool
('showsizes', @_) },
378 # Make gitweb use an alternative format of the URLs which can be
379 # more readable and natural-looking: project name is embedded
380 # directly in the path and the query string contains other
381 # auxiliary information. All gitweb installations recognize
382 # URL in either format; this configures in which formats gitweb
385 # To enable system wide have in $GITWEB_CONFIG
386 # $feature{'pathinfo'}{'default'} = [1];
387 # Project specific override is not supported.
389 # Note that you will need to change the default location of CSS,
390 # favicon, logo and possibly other files to an absolute URL. Also,
391 # if gitweb.cgi serves as your indexfile, you will need to force
392 # $my_uri to contain the script name in your $GITWEB_CONFIG.
397 # Make gitweb consider projects in project root subdirectories
398 # to be forks of existing projects. Given project $projname.git,
399 # projects matching $projname/*.git will not be shown in the main
400 # projects list, instead a '+' mark will be added to $projname
401 # there and a 'forks' view will be enabled for the project, listing
402 # all the forks. If project list is taken from a file, forks have
403 # to be listed after the main project.
405 # To enable system wide have in $GITWEB_CONFIG
406 # $feature{'forks'}{'default'} = [1];
407 # Project specific override is not supported.
412 # Insert custom links to the action bar of all project pages.
413 # This enables you mainly to link to third-party scripts integrating
414 # into gitweb; e.g. git-browser for graphical history representation
415 # or custom web-based repository administration interface.
417 # The 'default' value consists of a list of triplets in the form
418 # (label, link, position) where position is the label after which
419 # to insert the link and link is a format string where %n expands
420 # to the project name, %f to the project path within the filesystem,
421 # %h to the current hash (h gitweb parameter) and %b to the current
422 # hash base (hb gitweb parameter); %% expands to %.
424 # To enable system wide have in $GITWEB_CONFIG e.g.
425 # $feature{'actions'}{'default'} = [('graphiclog',
426 # '/git-browser/by-commit.html?r=%n', 'summary')];
427 # Project specific override is not supported.
432 # Allow gitweb scan project content tags of project repository,
433 # and display the popular Web 2.0-ish "tag cloud" near the projects
434 # list. Note that this is something COMPLETELY different from the
437 # gitweb by itself can show existing tags, but it does not handle
438 # tagging itself; you need to do it externally, outside gitweb.
439 # The format is described in git_get_project_ctags() subroutine.
440 # You may want to install the HTML::TagCloud Perl module to get
441 # a pretty tag cloud instead of just a list of tags.
443 # To enable system wide have in $GITWEB_CONFIG
444 # $feature{'ctags'}{'default'} = [1];
445 # Project specific override is not supported.
447 # In the future whether ctags editing is enabled might depend
448 # on the value, but using 1 should always mean no editing of ctags.
453 # The maximum number of patches in a patchset generated in patch
454 # view. Set this to 0 or undef to disable patch view, or to a
455 # negative number to remove any limit.
457 # To disable system wide have in $GITWEB_CONFIG
458 # $feature{'patches'}{'default'} = [0];
459 # To have project specific config enable override in $GITWEB_CONFIG
460 # $feature{'patches'}{'override'} = 1;
461 # and in project config gitweb.patches = 0|n;
462 # where n is the maximum number of patches allowed in a patchset.
464 'sub' => \
&feature_patches
,
468 # Avatar support. When this feature is enabled, views such as
469 # shortlog or commit will display an avatar associated with
470 # the email of the committer(s) and/or author(s).
472 # Currently available providers are gravatar and picon.
473 # If an unknown provider is specified, the feature is disabled.
475 # Gravatar depends on Digest::MD5.
476 # Picon currently relies on the indiana.edu database.
478 # To enable system wide have in $GITWEB_CONFIG
479 # $feature{'avatar'}{'default'} = ['<provider>'];
480 # where <provider> is either gravatar or picon.
481 # To have project specific config enable override in $GITWEB_CONFIG
482 # $feature{'avatar'}{'override'} = 1;
483 # and in project config gitweb.avatar = <provider>;
485 'sub' => \
&feature_avatar
,
489 # Enable displaying how much time and how many git commands
490 # it took to generate and display page. Disabled by default.
491 # Project specific override is not supported.
496 # Enable turning some links into links to actions which require
497 # JavaScript to run (like 'blame_incremental'). Not enabled by
498 # default. Project specific override is currently not supported.
499 'javascript-actions' => {
503 # Enable and configure ability to change common timezone for dates
504 # in gitweb output via JavaScript. Enabled by default.
505 # Project specific override is not supported.
506 'javascript-timezone' => {
509 'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
510 # or undef to turn off this feature
511 'gitweb_tz', # name of cookie where to store selected timezone
512 'datetime', # CSS class used to mark up dates for manipulation
515 # Syntax highlighting support. This is based on Daniel Svensson's
516 # and Sham Chukoury's work in gitweb-xmms2.git.
517 # It requires the 'highlight' program present in $PATH,
518 # and therefore is disabled by default.
520 # To enable system wide have in $GITWEB_CONFIG
521 # $feature{'highlight'}{'default'} = [1];
524 'sub' => sub { feature_bool
('highlight', @_) },
528 # Enable displaying of remote heads in the heads list
530 # To enable system wide have in $GITWEB_CONFIG
531 # $feature{'remote_heads'}{'default'} = [1];
532 # To have project specific config enable override in $GITWEB_CONFIG
533 # $feature{'remote_heads'}{'override'} = 1;
534 # and in project config gitweb.remote_heads = 0|1;
536 'sub' => sub { feature_bool
('remote_heads', @_) },
541 sub gitweb_get_feature
{
543 return unless exists $feature{$name};
544 my ($sub, $override, @defaults) = (
545 $feature{$name}{'sub'},
546 $feature{$name}{'override'},
547 @{$feature{$name}{'default'}});
548 # project specific override is possible only if we have project
549 our $git_dir; # global variable, declared later
550 if (!$override || !defined $git_dir) {
554 warn "feature $name is not overridable";
557 return $sub->(@defaults);
560 # A wrapper to check if a given feature is enabled.
561 # With this, you can say
563 # my $bool_feat = gitweb_check_feature('bool_feat');
564 # gitweb_check_feature('bool_feat') or somecode;
568 # my ($bool_feat) = gitweb_get_feature('bool_feat');
569 # (gitweb_get_feature('bool_feat'))[0] or somecode;
571 sub gitweb_check_feature
{
572 return (gitweb_get_feature
(@_))[0];
578 my ($val) = git_get_project_config
($key, '--bool');
582 } elsif ($val eq 'true') {
584 } elsif ($val eq 'false') {
589 sub feature_snapshot
{
592 my ($val) = git_get_project_config
('snapshot');
595 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
601 sub feature_patches
{
602 my @val = (git_get_project_config
('patches', '--int'));
612 my @val = (git_get_project_config
('avatar'));
614 return @val ? @val : @_;
617 # checking HEAD file with -e is fragile if the repository was
618 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
620 sub check_head_link
{
622 my $headfile = "$dir/HEAD";
623 return ((-e
$headfile) ||
624 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
627 sub check_export_ok
{
629 return (check_head_link
($dir) &&
630 (!$export_ok || -e
"$dir/$export_ok") &&
631 (!$export_auth_hook || $export_auth_hook->($dir)));
634 # process alternate names for backward compatibility
635 # filter out unsupported (unknown) snapshot formats
636 sub filter_snapshot_fmts
{
640 exists $known_snapshot_format_aliases{$_} ?
641 $known_snapshot_format_aliases{$_} : $_} @fmts;
643 exists $known_snapshot_formats{$_} &&
644 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
647 # If it is set to code reference, it is code that it is to be run once per
648 # request, allowing updating configurations that change with each request,
649 # while running other code in config file only once.
651 # Otherwise, if it is false then gitweb would process config file only once;
652 # if it is true then gitweb config would be run for each request.
653 our $per_request_config = 1;
655 # read and parse gitweb config file given by its parameter.
656 # returns true on success, false on recoverable error, allowing
657 # to chain this subroutine, using first file that exists.
658 # dies on errors during parsing config file, as it is unrecoverable.
659 sub read_config_file
{
660 my $filename = shift;
661 return unless defined $filename;
662 # die if there are errors parsing config file
671 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);
672 sub evaluate_gitweb_config
{
673 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
674 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
675 our $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || "++GITWEB_CONFIG_COMMON++";
677 # Protect agains duplications of file names, to not read config twice.
678 # Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so
679 # there possibility of duplication of filename there doesn't matter.
680 $GITWEB_CONFIG = "" if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);
681 $GITWEB_CONFIG_SYSTEM = "" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);
683 # Common system-wide settings for convenience.
684 # Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
685 read_config_file
($GITWEB_CONFIG_COMMON);
687 # Use first config file that exists. This means use the per-instance
688 # GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG.
689 read_config_file
($GITWEB_CONFIG) and return;
690 read_config_file
($GITWEB_CONFIG_SYSTEM);
693 # Get loadavg of system, to compare against $maxload.
694 # Currently it requires '/proc/loadavg' present to get loadavg;
695 # if it is not present it returns 0, which means no load checking.
697 if( -e
'/proc/loadavg' ){
698 open my $fd, '<', '/proc/loadavg'
700 my @load = split(/\s+/, scalar <$fd>);
703 # The first three columns measure CPU and IO utilization of the last one,
704 # five, and 10 minute periods. The fourth column shows the number of
705 # currently running processes and the total number of processes in the m/n
706 # format. The last column displays the last process ID used.
707 return $load[0] || 0;
709 # additional checks for load average should go here for things that don't export
715 # version of the core git binary
717 sub evaluate_git_version
{
718 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
719 $number_of_git_cmds++;
723 if (defined $maxload && get_loadavg
() > $maxload) {
724 die_error
(503, "The load average on the server is too high");
728 # ======================================================================
729 # input validation and dispatch
731 # input parameters can be collected from a variety of sources (presently, CGI
732 # and PATH_INFO), so we define an %input_params hash that collects them all
733 # together during validation: this allows subsequent uses (e.g. href()) to be
734 # agnostic of the parameter origin
736 our %input_params = ();
738 # input parameters are stored with the long parameter name as key. This will
739 # also be used in the href subroutine to convert parameters to their CGI
740 # equivalent, and since the href() usage is the most frequent one, we store
741 # the name -> CGI key mapping here, instead of the reverse.
743 # XXX: Warning: If you touch this, check the search form for updating,
746 our @cgi_param_mapping = (
754 hash_parent_base
=> "hpb",
759 snapshot_format
=> "sf",
760 extra_options
=> "opt",
761 search_use_regexp
=> "sr",
764 project_filter
=> "pf",
765 # this must be last entry (for manipulation from JavaScript)
768 our %cgi_param_mapping = @cgi_param_mapping;
770 # we will also need to know the possible actions, for validation
772 "blame" => \
&git_blame
,
773 "blame_incremental" => \
&git_blame_incremental
,
774 "blame_data" => \
&git_blame_data
,
775 "blobdiff" => \
&git_blobdiff
,
776 "blobdiff_plain" => \
&git_blobdiff_plain
,
777 "blob" => \
&git_blob
,
778 "blob_plain" => \
&git_blob_plain
,
779 "commitdiff" => \
&git_commitdiff
,
780 "commitdiff_plain" => \
&git_commitdiff_plain
,
781 "commit" => \
&git_commit
,
782 "forks" => \
&git_forks
,
783 "heads" => \
&git_heads
,
784 "history" => \
&git_history
,
786 "patch" => \
&git_patch
,
787 "patches" => \
&git_patches
,
788 "remotes" => \
&git_remotes
,
790 "atom" => \
&git_atom
,
791 "search" => \
&git_search
,
792 "search_help" => \
&git_search_help
,
793 "shortlog" => \
&git_shortlog
,
794 "summary" => \
&git_summary
,
796 "tags" => \
&git_tags
,
797 "tree" => \
&git_tree
,
798 "snapshot" => \
&git_snapshot
,
799 "object" => \
&git_object
,
800 # those below don't need $project
801 "opml" => \
&git_opml
,
802 "project_list" => \
&git_project_list
,
803 "project_index" => \
&git_project_index
,
806 # finally, we have the hash of allowed extra_options for the commands that
808 our %allowed_options = (
809 "--no-merges" => [ qw(rss atom log shortlog history) ],
812 # fill %input_params with the CGI parameters. All values except for 'opt'
813 # should be single values, but opt can be an array. We should probably
814 # build an array of parameters that can be multi-valued, but since for the time
815 # being it's only this one, we just single it out
816 sub evaluate_query_params
{
819 while (my ($name, $symbol) = each %cgi_param_mapping) {
820 if ($symbol eq 'opt') {
821 $input_params{$name} = [ map { decode_utf8
($_) } $cgi->param($symbol) ];
823 $input_params{$name} = decode_utf8
($cgi->param($symbol));
828 # now read PATH_INFO and update the parameter list for missing parameters
829 sub evaluate_path_info
{
830 return if defined $input_params{'project'};
831 return if !$path_info;
832 $path_info =~ s
,^/+,,;
833 return if !$path_info;
835 # find which part of PATH_INFO is project
836 my $project = $path_info;
838 while ($project && !check_head_link
("$projectroot/$project")) {
839 $project =~ s
,/*[^/]*$,,;
841 return unless $project;
842 $input_params{'project'} = $project;
844 # do not change any parameters if an action is given using the query string
845 return if $input_params{'action'};
846 $path_info =~ s
,^\Q
$project\E
/*,,;
848 # next, check if we have an action
849 my $action = $path_info;
851 if (exists $actions{$action}) {
852 $path_info =~ s
,^$action/*,,;
853 $input_params{'action'} = $action;
856 # list of actions that want hash_base instead of hash, but can have no
857 # pathname (f) parameter
863 # we want to catch, among others
864 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
865 my ($parentrefname, $parentpathname, $refname, $pathname) =
866 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);
868 # first, analyze the 'current' part
869 if (defined $pathname) {
870 # we got "branch:filename" or "branch:dir/"
871 # we could use git_get_type(branch:pathname), but:
872 # - it needs $git_dir
873 # - it does a git() call
874 # - the convention of terminating directories with a slash
875 # makes it superfluous
876 # - embedding the action in the PATH_INFO would make it even
878 $pathname =~ s
,^/+,,;
879 if (!$pathname || substr($pathname, -1) eq "/") {
880 $input_params{'action'} ||= "tree";
883 # the default action depends on whether we had parent info
885 if ($parentrefname) {
886 $input_params{'action'} ||= "blobdiff_plain";
888 $input_params{'action'} ||= "blob_plain";
891 $input_params{'hash_base'} ||= $refname;
892 $input_params{'file_name'} ||= $pathname;
893 } elsif (defined $refname) {
894 # we got "branch". In this case we have to choose if we have to
895 # set hash or hash_base.
897 # Most of the actions without a pathname only want hash to be
898 # set, except for the ones specified in @wants_base that want
899 # hash_base instead. It should also be noted that hand-crafted
900 # links having 'history' as an action and no pathname or hash
901 # set will fail, but that happens regardless of PATH_INFO.
902 if (defined $parentrefname) {
903 # if there is parent let the default be 'shortlog' action
904 # (for http://git.example.com/repo.git/A..B links); if there
905 # is no parent, dispatch will detect type of object and set
906 # action appropriately if required (if action is not set)
907 $input_params{'action'} ||= "shortlog";
909 if ($input_params{'action'} &&
910 grep { $_ eq $input_params{'action'} } @wants_base) {
911 $input_params{'hash_base'} ||= $refname;
913 $input_params{'hash'} ||= $refname;
917 # next, handle the 'parent' part, if present
918 if (defined $parentrefname) {
919 # a missing pathspec defaults to the 'current' filename, allowing e.g.
920 # someproject/blobdiff/oldrev..newrev:/filename
921 if ($parentpathname) {
922 $parentpathname =~ s
,^/+,,;
923 $parentpathname =~ s
,/$,,;
924 $input_params{'file_parent'} ||= $parentpathname;
926 $input_params{'file_parent'} ||= $input_params{'file_name'};
928 # we assume that hash_parent_base is wanted if a path was specified,
929 # or if the action wants hash_base instead of hash
930 if (defined $input_params{'file_parent'} ||
931 grep { $_ eq $input_params{'action'} } @wants_base) {
932 $input_params{'hash_parent_base'} ||= $parentrefname;
934 $input_params{'hash_parent'} ||= $parentrefname;
938 # for the snapshot action, we allow URLs in the form
939 # $project/snapshot/$hash.ext
940 # where .ext determines the snapshot and gets removed from the
941 # passed $refname to provide the $hash.
943 # To be able to tell that $refname includes the format extension, we
944 # require the following two conditions to be satisfied:
945 # - the hash input parameter MUST have been set from the $refname part
946 # of the URL (i.e. they must be equal)
947 # - the snapshot format MUST NOT have been defined already (e.g. from
949 # It's also useless to try any matching unless $refname has a dot,
950 # so we check for that too
951 if (defined $input_params{'action'} &&
952 $input_params{'action'} eq 'snapshot' &&
953 defined $refname && index($refname, '.') != -1 &&
954 $refname eq $input_params{'hash'} &&
955 !defined $input_params{'snapshot_format'}) {
956 # We loop over the known snapshot formats, checking for
957 # extensions. Allowed extensions are both the defined suffix
958 # (which includes the initial dot already) and the snapshot
959 # format key itself, with a prepended dot
960 while (my ($fmt, $opt) = each %known_snapshot_formats) {
962 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
966 # a valid suffix was found, so set the snapshot format
967 # and reset the hash parameter
968 $input_params{'snapshot_format'} = $fmt;
969 $input_params{'hash'} = $hash;
970 # we also set the format suffix to the one requested
971 # in the URL: this way a request for e.g. .tgz returns
972 # a .tgz instead of a .tar.gz
973 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
979 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
980 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
981 $searchtext, $search_regexp, $project_filter);
982 sub evaluate_and_validate_params
{
983 our $action = $input_params{'action'};
984 if (defined $action) {
985 if (!validate_action
($action)) {
986 die_error
(400, "Invalid action parameter");
990 # parameters which are pathnames
991 our $project = $input_params{'project'};
992 if (defined $project) {
993 if (!validate_project
($project)) {
995 die_error
(404, "No such project");
999 our $project_filter = $input_params{'project_filter'};
1000 if (defined $project_filter) {
1001 if (!validate_pathname
($project_filter)) {
1002 die_error
(404, "Invalid project_filter parameter");
1006 our $file_name = $input_params{'file_name'};
1007 if (defined $file_name) {
1008 if (!validate_pathname
($file_name)) {
1009 die_error
(400, "Invalid file parameter");
1013 our $file_parent = $input_params{'file_parent'};
1014 if (defined $file_parent) {
1015 if (!validate_pathname
($file_parent)) {
1016 die_error
(400, "Invalid file parent parameter");
1020 # parameters which are refnames
1021 our $hash = $input_params{'hash'};
1022 if (defined $hash) {
1023 if (!validate_refname
($hash)) {
1024 die_error
(400, "Invalid hash parameter");
1028 our $hash_parent = $input_params{'hash_parent'};
1029 if (defined $hash_parent) {
1030 if (!validate_refname
($hash_parent)) {
1031 die_error
(400, "Invalid hash parent parameter");
1035 our $hash_base = $input_params{'hash_base'};
1036 if (defined $hash_base) {
1037 if (!validate_refname
($hash_base)) {
1038 die_error
(400, "Invalid hash base parameter");
1042 our @extra_options = @{$input_params{'extra_options'}};
1043 # @extra_options is always defined, since it can only be (currently) set from
1044 # CGI, and $cgi->param() returns the empty array in array context if the param
1046 foreach my $opt (@extra_options) {
1047 if (not exists $allowed_options{$opt}) {
1048 die_error
(400, "Invalid option parameter");
1050 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
1051 die_error
(400, "Invalid option parameter for this action");
1055 our $hash_parent_base = $input_params{'hash_parent_base'};
1056 if (defined $hash_parent_base) {
1057 if (!validate_refname
($hash_parent_base)) {
1058 die_error
(400, "Invalid hash parent base parameter");
1063 our $page = $input_params{'page'};
1064 if (defined $page) {
1065 if ($page =~ m/[^0-9]/) {
1066 die_error
(400, "Invalid page parameter");
1070 our $searchtype = $input_params{'searchtype'};
1071 if (defined $searchtype) {
1072 if ($searchtype =~ m/[^a-z]/) {
1073 die_error
(400, "Invalid searchtype parameter");
1077 our $search_use_regexp = $input_params{'search_use_regexp'};
1079 our $searchtext = $input_params{'searchtext'};
1081 if (defined $searchtext) {
1082 if (length($searchtext) < 2) {
1083 die_error
(403, "At least two characters are required for search parameter");
1085 if ($search_use_regexp) {
1086 $search_regexp = $searchtext;
1087 if (!eval { qr/$search_regexp/; 1; }) {
1088 (my $error = $@) =~ s/ at \S+ line \d+.*\n?//;
1089 die_error
(400, "Invalid search regexp '$search_regexp'",
1093 $search_regexp = quotemeta $searchtext;
1098 # path to the current git repository
1100 sub evaluate_git_dir
{
1101 our $git_dir = "$projectroot/$project" if $project;
1104 our (@snapshot_fmts, $git_avatar);
1105 sub configure_gitweb_features
{
1106 # list of supported snapshot formats
1107 our @snapshot_fmts = gitweb_get_feature
('snapshot');
1108 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1110 # check that the avatar feature is set to a known provider name,
1111 # and for each provider check if the dependencies are satisfied.
1112 # if the provider name is invalid or the dependencies are not met,
1113 # reset $git_avatar to the empty string.
1114 our ($git_avatar) = gitweb_get_feature
('avatar');
1115 if ($git_avatar eq 'gravatar') {
1116 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
1117 } elsif ($git_avatar eq 'picon') {
1124 # custom error handler: 'die <message>' is Internal Server Error
1125 sub handle_errors_html
{
1126 my $msg = shift; # it is already HTML escaped
1128 # to avoid infinite loop where error occurs in die_error,
1129 # change handler to default handler, disabling handle_errors_html
1130 set_message
("Error occured when inside die_error:\n$msg");
1132 # you cannot jump out of die_error when called as error handler;
1133 # the subroutine set via CGI::Carp::set_message is called _after_
1134 # HTTP headers are already written, so it cannot write them itself
1135 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1137 set_message
(\
&handle_errors_html
);
1141 if (!defined $action) {
1142 if (defined $hash) {
1143 $action = git_get_type
($hash);
1144 $action or die_error
(404, "Object does not exist");
1145 } elsif (defined $hash_base && defined $file_name) {
1146 $action = git_get_type
("$hash_base:$file_name");
1147 $action or die_error
(404, "File or directory does not exist");
1148 } elsif (defined $project) {
1149 $action = 'summary';
1151 $action = 'project_list';
1154 if (!defined($actions{$action})) {
1155 die_error
(400, "Unknown action");
1157 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1159 die_error
(400, "Project needed");
1161 $actions{$action}->();
1165 our $t0 = [ gettimeofday
() ]
1167 our $number_of_git_cmds = 0;
1170 our $first_request = 1;
1175 if ($first_request) {
1176 evaluate_gitweb_config
();
1177 evaluate_git_version
();
1179 if ($per_request_config) {
1180 if (ref($per_request_config) eq 'CODE') {
1181 $per_request_config->();
1182 } elsif (!$first_request) {
1183 evaluate_gitweb_config
();
1188 # $projectroot and $projects_list might be set in gitweb config file
1189 $projects_list ||= $projectroot;
1191 evaluate_query_params
();
1192 evaluate_path_info
();
1193 evaluate_and_validate_params
();
1196 configure_gitweb_features
();
1201 our $is_last_request = sub { 1 };
1202 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1205 sub configure_as_fcgi
{
1207 our $CGI = 'CGI::Fast';
1209 my $request_number = 0;
1210 # let each child service 100 requests
1211 our $is_last_request = sub { ++$request_number > 100 };
1214 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1216 if $script_name =~ /\.fcgi$/;
1218 return unless (@ARGV);
1220 require Getopt
::Long
;
1221 Getopt
::Long
::GetOptions
(
1222 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1223 'nproc|n=i' => sub {
1224 my ($arg, $val) = @_;
1225 return unless eval { require FCGI
::ProcManager
; 1; };
1226 my $proc_manager = FCGI
::ProcManager-
>new({
1227 n_processes
=> $val,
1229 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1230 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1231 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1240 $pre_listen_hook->()
1241 if $pre_listen_hook;
1244 while ($cgi = $CGI->new()) {
1245 $pre_dispatch_hook->()
1246 if $pre_dispatch_hook;
1250 $post_dispatch_hook->()
1251 if $post_dispatch_hook;
1254 last REQUEST
if ($is_last_request->());
1263 if (defined caller) {
1264 # wrapped in a subroutine processing requests,
1265 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1268 # pure CGI script, serving single request
1272 ## ======================================================================
1275 # possible values of extra options
1276 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1277 # -replay => 1 - start from a current view (replay with modifications)
1278 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1279 # -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone
1282 # default is to use -absolute url() i.e. $my_uri
1283 my $href = $params{-full
} ? $my_url : $my_uri;
1285 # implicit -replay, must be first of implicit params
1286 $params{-replay
} = 1 if (keys %params == 1 && $params{-anchor
});
1288 $params{'project'} = $project unless exists $params{'project'};
1290 if ($params{-replay
}) {
1291 while (my ($name, $symbol) = each %cgi_param_mapping) {
1292 if (!exists $params{$name}) {
1293 $params{$name} = $input_params{$name};
1298 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1299 if (defined $params{'project'} &&
1300 (exists $params{-path_info
} ? $params{-path_info
} : $use_pathinfo)) {
1301 # try to put as many parameters as possible in PATH_INFO:
1304 # - hash_parent or hash_parent_base:/file_parent
1305 # - hash or hash_base:/filename
1306 # - the snapshot_format as an appropriate suffix
1308 # When the script is the root DirectoryIndex for the domain,
1309 # $href here would be something like http://gitweb.example.com/
1310 # Thus, we strip any trailing / from $href, to spare us double
1311 # slashes in the final URL
1314 # Then add the project name, if present
1315 $href .= "/".esc_path_info
($params{'project'});
1316 delete $params{'project'};
1318 # since we destructively absorb parameters, we keep this
1319 # boolean that remembers if we're handling a snapshot
1320 my $is_snapshot = $params{'action'} eq 'snapshot';
1322 # Summary just uses the project path URL, any other action is
1324 if (defined $params{'action'}) {
1325 $href .= "/".esc_path_info
($params{'action'})
1326 unless $params{'action'} eq 'summary';
1327 delete $params{'action'};
1330 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1331 # stripping nonexistent or useless pieces
1332 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1333 || $params{'hash_parent'} || $params{'hash'});
1334 if (defined $params{'hash_base'}) {
1335 if (defined $params{'hash_parent_base'}) {
1336 $href .= esc_path_info
($params{'hash_parent_base'});
1337 # skip the file_parent if it's the same as the file_name
1338 if (defined $params{'file_parent'}) {
1339 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1340 delete $params{'file_parent'};
1341 } elsif ($params{'file_parent'} !~ /\.\./) {
1342 $href .= ":/".esc_path_info
($params{'file_parent'});
1343 delete $params{'file_parent'};
1347 delete $params{'hash_parent'};
1348 delete $params{'hash_parent_base'};
1349 } elsif (defined $params{'hash_parent'}) {
1350 $href .= esc_path_info
($params{'hash_parent'}). "..";
1351 delete $params{'hash_parent'};
1354 $href .= esc_path_info
($params{'hash_base'});
1355 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1356 $href .= ":/".esc_path_info
($params{'file_name'});
1357 delete $params{'file_name'};
1359 delete $params{'hash'};
1360 delete $params{'hash_base'};
1361 } elsif (defined $params{'hash'}) {
1362 $href .= esc_path_info
($params{'hash'});
1363 delete $params{'hash'};
1366 # If the action was a snapshot, we can absorb the
1367 # snapshot_format parameter too
1369 my $fmt = $params{'snapshot_format'};
1370 # snapshot_format should always be defined when href()
1371 # is called, but just in case some code forgets, we
1372 # fall back to the default
1373 $fmt ||= $snapshot_fmts[0];
1374 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1375 delete $params{'snapshot_format'};
1379 # now encode the parameters explicitly
1381 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1382 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1383 if (defined $params{$name}) {
1384 if (ref($params{$name}) eq "ARRAY") {
1385 foreach my $par (@{$params{$name}}) {
1386 push @result, $symbol . "=" . esc_param
($par);
1389 push @result, $symbol . "=" . esc_param
($params{$name});
1393 $href .= "?" . join(';', @result) if scalar @result;
1395 # final transformation: trailing spaces must be escaped (URI-encoded)
1396 $href =~ s/(\s+)$/CGI::escape($1)/e;
1398 if ($params{-anchor
}) {
1399 $href .= "#".esc_param
($params{-anchor
});
1406 ## ======================================================================
1407 ## validation, quoting/unquoting and escaping
1409 sub validate_action
{
1410 my $input = shift || return undef;
1411 return undef unless exists $actions{$input};
1415 sub validate_project
{
1416 my $input = shift || return undef;
1417 if (!validate_pathname
($input) ||
1418 !(-d
"$projectroot/$input") ||
1419 !check_export_ok
("$projectroot/$input") ||
1420 ($strict_export && !project_in_list
($input))) {
1427 sub validate_pathname
{
1428 my $input = shift || return undef;
1430 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1431 # at the beginning, at the end, and between slashes.
1432 # also this catches doubled slashes
1433 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1436 # no null characters
1437 if ($input =~ m!\0!) {
1443 sub validate_refname
{
1444 my $input = shift || return undef;
1446 # textual hashes are O.K.
1447 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1450 # it must be correct pathname
1451 $input = validate_pathname
($input)
1453 # restrictions on ref name according to git-check-ref-format
1454 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1460 # decode sequences of octets in utf8 into Perl's internal form,
1461 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1462 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1465 return undef unless defined $str;
1467 if (utf8
::is_utf8
($str) || utf8
::decode
($str)) {
1470 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1474 # quote unsafe chars, but keep the slash, even when it's not
1475 # correct, but quoted slashes look too horrible in bookmarks
1478 return undef unless defined $str;
1479 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1484 # the quoting rules for path_info fragment are slightly different
1487 return undef unless defined $str;
1489 # path_info doesn't treat '+' as space (specially), but '?' must be escaped
1490 $str =~ s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI
::escape
($1)/eg
;
1495 # quote unsafe chars in whole URL, so some characters cannot be quoted
1498 return undef unless defined $str;
1499 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1504 # quote unsafe characters in HTML attributes
1507 # for XHTML conformance escaping '"' to '"' is not enough
1508 return esc_html
(@_);
1511 # replace invalid utf8 character with SUBSTITUTION sequence
1516 return undef unless defined $str;
1518 $str = to_utf8
($str);
1519 $str = $cgi->escapeHTML($str);
1520 if ($opts{'-nbsp'}) {
1521 $str =~ s/ / /g;
1523 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1527 # quote control characters and escape filename to HTML
1532 return undef unless defined $str;
1534 $str = to_utf8
($str);
1535 $str = $cgi->escapeHTML($str);
1536 if ($opts{'-nbsp'}) {
1537 $str =~ s/ / /g;
1539 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1543 # Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0)
1547 return undef unless defined $str;
1549 $str = to_utf8
($str);
1550 $str =~ s
|([[:cntrl
:]])|($1 =~ /[\t\n\r]/ ? $1 : quot_cec
($1))|eg
;
1554 # Make control characters "printable", using character escape codes (CEC)
1558 my %es = ( # character escape codes, aka escape sequences
1559 "\t" => '\t', # tab (HT)
1560 "\n" => '\n', # line feed (LF)
1561 "\r" => '\r', # carrige return (CR)
1562 "\f" => '\f', # form feed (FF)
1563 "\b" => '\b', # backspace (BS)
1564 "\a" => '\a', # alarm (bell) (BEL)
1565 "\e" => '\e', # escape (ESC)
1566 "\013" => '\v', # vertical tab (VT)
1567 "\000" => '\0', # nul character (NUL)
1569 my $chr = ( (exists $es{$cntrl})
1571 : sprintf('\%2x', ord($cntrl)) );
1572 if ($opts{-nohtml
}) {
1575 return "<span class=\"cntrl\">$chr</span>";
1579 # Alternatively use unicode control pictures codepoints,
1580 # Unicode "printable representation" (PR)
1585 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1586 if ($opts{-nohtml
}) {
1589 return "<span class=\"cntrl\">$chr</span>";
1593 # git may return quoted and escaped filenames
1599 my %es = ( # character escape codes, aka escape sequences
1600 't' => "\t", # tab (HT, TAB)
1601 'n' => "\n", # newline (NL)
1602 'r' => "\r", # return (CR)
1603 'f' => "\f", # form feed (FF)
1604 'b' => "\b", # backspace (BS)
1605 'a' => "\a", # alarm (bell) (BEL)
1606 'e' => "\e", # escape (ESC)
1607 'v' => "\013", # vertical tab (VT)
1610 if ($seq =~ m/^[0-7]{1,3}$/) {
1611 # octal char sequence
1612 return chr(oct($seq));
1613 } elsif (exists $es{$seq}) {
1614 # C escape sequence, aka character escape code
1617 # quoted ordinary character
1621 if ($str =~ m/^"(.*)"$/) {
1624 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1629 # escape tabs (convert tabs to spaces)
1633 while ((my $pos = index($line, "\t")) != -1) {
1634 if (my $count = (8 - ($pos % 8))) {
1635 my $spaces = ' ' x
$count;
1636 $line =~ s/\t/$spaces/;
1643 sub project_in_list
{
1644 my $project = shift;
1645 my @list = git_get_projects_list
();
1646 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1649 ## ----------------------------------------------------------------------
1650 ## HTML aware string manipulation
1652 # Try to chop given string on a word boundary between position
1653 # $len and $len+$add_len. If there is no word boundary there,
1654 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1655 # (marking chopped part) would be longer than given string.
1659 my $add_len = shift || 10;
1660 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1662 # Make sure perl knows it is utf8 encoded so we don't
1663 # cut in the middle of a utf8 multibyte char.
1664 $str = to_utf8
($str);
1666 # allow only $len chars, but don't cut a word if it would fit in $add_len
1667 # if it doesn't fit, cut it if it's still longer than the dots we would add
1668 # remove chopped character entities entirely
1670 # when chopping in the middle, distribute $len into left and right part
1671 # return early if chopping wouldn't make string shorter
1672 if ($where eq 'center') {
1673 return $str if ($len + 5 >= length($str)); # filler is length 5
1676 return $str if ($len + 4 >= length($str)); # filler is length 4
1679 # regexps: ending and beginning with word part up to $add_len
1680 my $endre = qr/.{$len}\w{0,$add_len}/;
1681 my $begre = qr/\w{0,$add_len}.{$len}/;
1683 if ($where eq 'left') {
1684 $str =~ m/^(.*?)($begre)$/;
1685 my ($lead, $body) = ($1, $2);
1686 if (length($lead) > 4) {
1689 return "$lead$body";
1691 } elsif ($where eq 'center') {
1692 $str =~ m/^($endre)(.*)$/;
1693 my ($left, $str) = ($1, $2);
1694 $str =~ m/^(.*?)($begre)$/;
1695 my ($mid, $right) = ($1, $2);
1696 if (length($mid) > 5) {
1699 return "$left$mid$right";
1702 $str =~ m/^($endre)(.*)$/;
1705 if (length($tail) > 4) {
1708 return "$body$tail";
1712 # takes the same arguments as chop_str, but also wraps a <span> around the
1713 # result with a title attribute if it does get chopped. Additionally, the
1714 # string is HTML-escaped.
1715 sub chop_and_escape_str
{
1718 my $chopped = chop_str
(@_);
1719 $str = to_utf8
($str);
1720 if ($chopped eq $str) {
1721 return esc_html
($chopped);
1723 $str =~ s/[[:cntrl:]]/?/g;
1724 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1728 # Highlight selected fragments of string, using given CSS class,
1729 # and escape HTML. It is assumed that fragments do not overlap.
1730 # Regions are passed as list of pairs (array references).
1732 # Example: esc_html_hl_regions("foobar", "mark", [ 0, 3 ]) returns
1733 # '<span class="mark">foo</span>bar'
1734 sub esc_html_hl_regions
{
1735 my ($str, $css_class, @sel) = @_;
1736 return esc_html
($str) unless @sel;
1742 my ($begin, $end) = @$s;
1744 # Don't create empty <span> elements.
1745 next if $end <= $begin;
1747 my $escaped = esc_html
(substr($str, $begin, $end - $begin));
1749 $out .= esc_html
(substr($str, $pos, $begin - $pos))
1750 if ($begin - $pos > 0);
1751 $out .= $cgi->span({-class => $css_class}, $escaped);
1755 $out .= esc_html
(substr($str, $pos))
1756 if ($pos < length($str));
1761 # return positions of beginning and end of each match
1763 my ($str, $regexp) = @_;
1764 return unless (defined $str && defined $regexp);
1767 while ($str =~ /$regexp/g) {
1768 push @matches, [$-[0], $+[0]];
1773 # highlight match (if any), and escape HTML
1774 sub esc_html_match_hl
{
1775 my ($str, $regexp) = @_;
1776 return esc_html
($str) unless defined $regexp;
1778 my @matches = matchpos_list
($str, $regexp);
1779 return esc_html
($str) unless @matches;
1781 return esc_html_hl_regions
($str, 'match', @matches);
1785 # highlight match (if any) of shortened string, and escape HTML
1786 sub esc_html_match_hl_chopped
{
1787 my ($str, $chopped, $regexp) = @_;
1788 return esc_html_match_hl
($str, $regexp) unless defined $chopped;
1790 my @matches = matchpos_list
($str, $regexp);
1791 return esc_html
($chopped) unless @matches;
1793 # filter matches so that we mark chopped string
1794 my $tail = "... "; # see chop_str
1795 unless ($chopped =~ s/\Q$tail\E$//) {
1798 my $chop_len = length($chopped);
1799 my $tail_len = length($tail);
1802 for my $m (@matches) {
1803 if ($m->[0] > $chop_len) {
1804 push @filtered, [ $chop_len, $chop_len + $tail_len ] if ($tail_len > 0);
1806 } elsif ($m->[1] > $chop_len) {
1807 push @filtered, [ $m->[0], $chop_len + $tail_len ];
1813 return esc_html_hl_regions
($chopped . $tail, 'match', @filtered);
1816 ## ----------------------------------------------------------------------
1817 ## functions returning short strings
1819 # CSS class for given age value (in seconds)
1823 if (!defined $age) {
1825 } elsif ($age < 60*60*2) {
1827 } elsif ($age < 60*60*24*2) {
1834 # convert age in seconds to "nn units ago" string
1839 if ($age > 60*60*24*365*2) {
1840 $age_str = (int $age/60/60/24/365);
1841 $age_str .= " years ago";
1842 } elsif ($age > 60*60*24*(365/12)*2) {
1843 $age_str = int $age/60/60/24/(365/12);
1844 $age_str .= " months ago";
1845 } elsif ($age > 60*60*24*7*2) {
1846 $age_str = int $age/60/60/24/7;
1847 $age_str .= " weeks ago";
1848 } elsif ($age > 60*60*24*2) {
1849 $age_str = int $age/60/60/24;
1850 $age_str .= " days ago";
1851 } elsif ($age > 60*60*2) {
1852 $age_str = int $age/60/60;
1853 $age_str .= " hours ago";
1854 } elsif ($age > 60*2) {
1855 $age_str = int $age/60;
1856 $age_str .= " min ago";
1857 } elsif ($age > 2) {
1858 $age_str = int $age;
1859 $age_str .= " sec ago";
1861 $age_str .= " right now";
1867 S_IFINVALID
=> 0030000,
1868 S_IFGITLINK
=> 0160000,
1871 # submodule/subproject, a commit object reference
1875 return (($mode & S_IFMT
) == S_IFGITLINK
)
1878 # convert file mode in octal to symbolic file mode string
1880 my $mode = oct shift;
1882 if (S_ISGITLINK
($mode)) {
1883 return 'm---------';
1884 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1885 return 'drwxr-xr-x';
1886 } elsif (S_ISLNK
($mode)) {
1887 return 'lrwxrwxrwx';
1888 } elsif (S_ISREG
($mode)) {
1889 # git cares only about the executable bit
1890 if ($mode & S_IXUSR
) {
1891 return '-rwxr-xr-x';
1893 return '-rw-r--r--';
1896 return '----------';
1900 # convert file mode in octal to file type string
1904 if ($mode !~ m/^[0-7]+$/) {
1910 if (S_ISGITLINK
($mode)) {
1912 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1914 } elsif (S_ISLNK
($mode)) {
1916 } elsif (S_ISREG
($mode)) {
1923 # convert file mode in octal to file type description string
1924 sub file_type_long
{
1927 if ($mode !~ m/^[0-7]+$/) {
1933 if (S_ISGITLINK
($mode)) {
1935 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1937 } elsif (S_ISLNK
($mode)) {
1939 } elsif (S_ISREG
($mode)) {
1940 if ($mode & S_IXUSR
) {
1941 return "executable";
1951 ## ----------------------------------------------------------------------
1952 ## functions returning short HTML fragments, or transforming HTML fragments
1953 ## which don't belong to other sections
1955 # format line of commit message.
1956 sub format_log_line_html
{
1959 $line = esc_html
($line, -nbsp
=>1);
1960 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1961 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1962 -class => "text"}, $1);
1968 # format marker of refs pointing to given object
1970 # the destination action is chosen based on object type and current context:
1971 # - for annotated tags, we choose the tag view unless it's the current view
1972 # already, in which case we go to shortlog view
1973 # - for other refs, we keep the current view if we're in history, shortlog or
1974 # log view, and select shortlog otherwise
1975 sub format_ref_marker
{
1976 my ($refs, $id) = @_;
1979 if (defined $refs->{$id}) {
1980 foreach my $ref (@{$refs->{$id}}) {
1981 # this code exploits the fact that non-lightweight tags are the
1982 # only indirect objects, and that they are the only objects for which
1983 # we want to use tag instead of shortlog as action
1984 my ($type, $name) = qw();
1985 my $indirect = ($ref =~ s/\^\{\}$//);
1986 # e.g. tags/v2.6.11 or heads/next
1987 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1996 $class .= " indirect" if $indirect;
1998 my $dest_action = "shortlog";
2001 $dest_action = "tag" unless $action eq "tag";
2002 } elsif ($action =~ /^(history|(short)?log)$/) {
2003 $dest_action = $action;
2007 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
2010 my $link = $cgi->a({
2012 action
=>$dest_action,
2016 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
2022 return ' <span class="refs">'. $markers . '</span>';
2028 # format, perhaps shortened and with markers, title line
2029 sub format_subject_html
{
2030 my ($long, $short, $href, $extra) = @_;
2031 $extra = '' unless defined($extra);
2033 if (length($short) < length($long)) {
2034 $long =~ s/[[:cntrl:]]/?/g;
2035 return $cgi->a({-href
=> $href, -class => "list subject",
2036 -title
=> to_utf8
($long)},
2037 esc_html
($short)) . $extra;
2039 return $cgi->a({-href
=> $href, -class => "list subject"},
2040 esc_html
($long)) . $extra;
2044 # Rather than recomputing the url for an email multiple times, we cache it
2045 # after the first hit. This gives a visible benefit in views where the avatar
2046 # for the same email is used repeatedly (e.g. shortlog).
2047 # The cache is shared by all avatar engines (currently gravatar only), which
2048 # are free to use it as preferred. Since only one avatar engine is used for any
2049 # given page, there's no risk for cache conflicts.
2050 our %avatar_cache = ();
2052 # Compute the picon url for a given email, by using the picon search service over at
2053 # http://www.cs.indiana.edu/picons/search.html
2055 my $email = lc shift;
2056 if (!$avatar_cache{$email}) {
2057 my ($user, $domain) = split('@', $email);
2058 $avatar_cache{$email} =
2059 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
2061 "users+domains+unknown/up/single";
2063 return $avatar_cache{$email};
2066 # Compute the gravatar url for a given email, if it's not in the cache already.
2067 # Gravatar stores only the part of the URL before the size, since that's the
2068 # one computationally more expensive. This also allows reuse of the cache for
2069 # different sizes (for this particular engine).
2071 my $email = lc shift;
2073 $avatar_cache{$email} ||=
2074 "http://www.gravatar.com/avatar/" .
2075 Digest
::MD5
::md5_hex
($email) . "?s=";
2076 return $avatar_cache{$email} . $size;
2079 # Insert an avatar for the given $email at the given $size if the feature
2081 sub git_get_avatar
{
2082 my ($email, %opts) = @_;
2083 my $pre_white = ($opts{-pad_before
} ? " " : "");
2084 my $post_white = ($opts{-pad_after
} ? " " : "");
2085 $opts{-size
} ||= 'default';
2086 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
2088 if ($git_avatar eq 'gravatar') {
2089 $url = gravatar_url
($email, $size);
2090 } elsif ($git_avatar eq 'picon') {
2091 $url = picon_url
($email);
2093 # Other providers can be added by extending the if chain, defining $url
2094 # as needed. If no variant puts something in $url, we assume avatars
2095 # are completely disabled/unavailable.
2098 "<img width=\"$size\" " .
2099 "class=\"avatar\" " .
2100 "src=\"".esc_url
($url)."\" " .
2108 sub format_search_author
{
2109 my ($author, $searchtype, $displaytext) = @_;
2110 my $have_search = gitweb_check_feature
('search');
2114 if ($searchtype eq 'author') {
2115 $performed = "authored";
2116 } elsif ($searchtype eq 'committer') {
2117 $performed = "committed";
2120 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
2121 searchtext
=>$author,
2122 searchtype
=>$searchtype), class=>"list",
2123 title
=>"Search for commits $performed by $author"},
2127 return $displaytext;
2131 # format the author name of the given commit with the given tag
2132 # the author name is chopped and escaped according to the other
2133 # optional parameters (see chop_str).
2134 sub format_author_html
{
2137 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
2138 return "<$tag class=\"author\">" .
2139 format_search_author
($co->{'author_name'}, "author",
2140 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
2145 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
2146 sub format_git_diff_header_line
{
2148 my $diffinfo = shift;
2149 my ($from, $to) = @_;
2151 if ($diffinfo->{'nparents'}) {
2153 $line =~ s!^(diff (.*?) )"?.*$!$1!;
2154 if ($to->{'href'}) {
2155 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
2156 esc_path
($to->{'file'}));
2157 } else { # file was deleted (no href)
2158 $line .= esc_path
($to->{'file'});
2162 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2163 if ($from->{'href'}) {
2164 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
2165 'a/' . esc_path
($from->{'file'}));
2166 } else { # file was added (no href)
2167 $line .= 'a/' . esc_path
($from->{'file'});
2170 if ($to->{'href'}) {
2171 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
2172 'b/' . esc_path
($to->{'file'}));
2173 } else { # file was deleted
2174 $line .= 'b/' . esc_path
($to->{'file'});
2178 return "<div class=\"diff header\">$line</div>\n";
2181 # format extended diff header line, before patch itself
2182 sub format_extended_diff_header_line
{
2184 my $diffinfo = shift;
2185 my ($from, $to) = @_;
2188 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
2189 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2190 esc_path
($from->{'file'}));
2192 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
2193 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2194 esc_path
($to->{'file'}));
2196 # match single <mode>
2197 if ($line =~ m/\s(\d{6})$/) {
2198 $line .= '<span class="info"> (' .
2199 file_type_long
($1) .
2203 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2204 # can match only for combined diff
2206 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2207 if ($from->{'href'}[$i]) {
2208 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
2210 substr($diffinfo->{'from_id'}[$i],0,7));
2215 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2218 if ($to->{'href'}) {
2219 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2220 substr($diffinfo->{'to_id'},0,7));
2225 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2226 # can match only for ordinary diff
2227 my ($from_link, $to_link);
2228 if ($from->{'href'}) {
2229 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
2230 substr($diffinfo->{'from_id'},0,7));
2232 $from_link = '0' x
7;
2234 if ($to->{'href'}) {
2235 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2236 substr($diffinfo->{'to_id'},0,7));
2240 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2241 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2244 return $line . "<br/>\n";
2247 # format from-file/to-file diff header
2248 sub format_diff_from_to_header
{
2249 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
2254 #assert($line =~ m/^---/) if DEBUG;
2255 # no extra formatting for "^--- /dev/null"
2256 if (! $diffinfo->{'nparents'}) {
2257 # ordinary (single parent) diff
2258 if ($line =~ m!^--- "?a/!) {
2259 if ($from->{'href'}) {
2261 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2262 esc_path
($from->{'file'}));
2265 esc_path
($from->{'file'});
2268 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2271 # combined diff (merge commit)
2272 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2273 if ($from->{'href'}[$i]) {
2275 $cgi->a({-href
=>href
(action
=>"blobdiff",
2276 hash_parent
=>$diffinfo->{'from_id'}[$i],
2277 hash_parent_base
=>$parents[$i],
2278 file_parent
=>$from->{'file'}[$i],
2279 hash
=>$diffinfo->{'to_id'},
2281 file_name
=>$to->{'file'}),
2283 -title
=>"diff" . ($i+1)},
2286 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2287 esc_path
($from->{'file'}[$i]));
2289 $line = '--- /dev/null';
2291 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2296 #assert($line =~ m/^\+\+\+/) if DEBUG;
2297 # no extra formatting for "^+++ /dev/null"
2298 if ($line =~ m!^\+\+\+ "?b/!) {
2299 if ($to->{'href'}) {
2301 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2302 esc_path
($to->{'file'}));
2305 esc_path
($to->{'file'});
2308 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
2313 # create note for patch simplified by combined diff
2314 sub format_diff_cc_simplified
{
2315 my ($diffinfo, @parents) = @_;
2318 $result .= "<div class=\"diff header\">" .
2320 if (!is_deleted
($diffinfo)) {
2321 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2323 hash
=>$diffinfo->{'to_id'},
2324 file_name
=>$diffinfo->{'to_file'}),
2326 esc_path
($diffinfo->{'to_file'}));
2328 $result .= esc_path
($diffinfo->{'to_file'});
2330 $result .= "</div>\n" . # class="diff header"
2331 "<div class=\"diff nodifferences\">" .
2333 "</div>\n"; # class="diff nodifferences"
2338 sub diff_line_class
{
2339 my ($line, $from, $to) = @_;
2344 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2345 $num_sign = scalar @{$from->{'href'}};
2348 my @diff_line_classifier = (
2349 { regexp
=> qr/^\@\@{$num_sign} /, class => "chunk_header"},
2350 { regexp
=> qr/^\\/, class => "incomplete" },
2351 { regexp
=> qr/^ {$num_sign}/, class => "ctx" },
2352 # classifier for context must come before classifier add/rem,
2353 # or we would have to use more complicated regexp, for example
2354 # qr/(?= {0,$m}\+)[+ ]{$num_sign}/, where $m = $num_sign - 1;
2355 { regexp
=> qr/^[+ ]{$num_sign}/, class => "add" },
2356 { regexp
=> qr/^[- ]{$num_sign}/, class => "rem" },
2358 for my $clsfy (@diff_line_classifier) {
2359 return $clsfy->{'class'}
2360 if ($line =~ $clsfy->{'regexp'});
2367 # assumes that $from and $to are defined and correctly filled,
2368 # and that $line holds a line of chunk header for unified diff
2369 sub format_unidiff_chunk_header
{
2370 my ($line, $from, $to) = @_;
2372 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2373 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2375 $from_lines = 0 unless defined $from_lines;
2376 $to_lines = 0 unless defined $to_lines;
2378 if ($from->{'href'}) {
2379 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2380 -class=>"list"}, $from_text);
2382 if ($to->{'href'}) {
2383 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2384 -class=>"list"}, $to_text);
2386 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2387 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2391 # assumes that $from and $to are defined and correctly filled,
2392 # and that $line holds a line of chunk header for combined diff
2393 sub format_cc_diff_chunk_header
{
2394 my ($line, $from, $to) = @_;
2396 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2397 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2399 @from_text = split(' ', $ranges);
2400 for (my $i = 0; $i < @from_text; ++$i) {
2401 ($from_start[$i], $from_nlines[$i]) =
2402 (split(',', substr($from_text[$i], 1)), 0);
2405 $to_text = pop @from_text;
2406 $to_start = pop @from_start;
2407 $to_nlines = pop @from_nlines;
2409 $line = "<span class=\"chunk_info\">$prefix ";
2410 for (my $i = 0; $i < @from_text; ++$i) {
2411 if ($from->{'href'}[$i]) {
2412 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2413 -class=>"list"}, $from_text[$i]);
2415 $line .= $from_text[$i];
2419 if ($to->{'href'}) {
2420 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2421 -class=>"list"}, $to_text);
2425 $line .= " $prefix</span>" .
2426 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2430 # process patch (diff) line (not to be used for diff headers),
2431 # returning class and HTML-formatted (but not wrapped) line
2432 sub process_diff_line
{
2434 my ($from, $to) = @_;
2436 my $diff_class = diff_line_class
($line, $from, $to);
2439 $line = untabify
($line);
2441 if ($from && $to && $line =~ m/^\@{2} /) {
2442 $line = format_unidiff_chunk_header
($line, $from, $to);
2443 return $diff_class, $line;
2445 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2446 $line = format_cc_diff_chunk_header
($line, $from, $to);
2447 return $diff_class, $line;
2450 return $diff_class, esc_html
($line, -nbsp
=>1);
2453 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2454 # linked. Pass the hash of the tree/commit to snapshot.
2455 sub format_snapshot_links
{
2457 my $num_fmts = @snapshot_fmts;
2458 if ($num_fmts > 1) {
2459 # A parenthesized list of links bearing format names.
2460 # e.g. "snapshot (_tar.gz_ _zip_)"
2461 return "snapshot (" . join(' ', map
2468 }, $known_snapshot_formats{$_}{'display'})
2469 , @snapshot_fmts) . ")";
2470 } elsif ($num_fmts == 1) {
2471 # A single "snapshot" link whose tooltip bears the format name.
2473 my ($fmt) = @snapshot_fmts;
2479 snapshot_format
=>$fmt
2481 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2483 } else { # $num_fmts == 0
2488 ## ......................................................................
2489 ## functions returning values to be passed, perhaps after some
2490 ## transformation, to other functions; e.g. returning arguments to href()
2492 # returns hash to be passed to href to generate gitweb URL
2493 # in -title key it returns description of link
2495 my $format = shift || 'Atom';
2496 my %res = (action
=> lc($format));
2498 # feed links are possible only for project views
2499 return unless (defined $project);
2500 # some views should link to OPML, or to generic project feed,
2501 # or don't have specific feed yet (so they should use generic)
2502 return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
2505 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2506 # from tag links; this also makes possible to detect branch links
2507 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2508 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2511 # find log type for feed description (title)
2513 if (defined $file_name) {
2514 $type = "history of $file_name";
2515 $type .= "/" if ($action eq 'tree');
2516 $type .= " on '$branch'" if (defined $branch);
2518 $type = "log of $branch" if (defined $branch);
2521 $res{-title
} = $type;
2522 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2523 $res{'file_name'} = $file_name;
2528 ## ----------------------------------------------------------------------
2529 ## git utility subroutines, invoking git commands
2531 # returns path to the core git executable and the --git-dir parameter as list
2533 $number_of_git_cmds++;
2534 return $GIT, '--git-dir='.$git_dir;
2537 # quote the given arguments for passing them to the shell
2538 # quote_command("command", "arg 1", "arg with ' and ! characters")
2539 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2540 # Try to avoid using this function wherever possible.
2543 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2546 # get HEAD ref of given project as hash
2547 sub git_get_head_hash
{
2548 return git_get_full_hash
(shift, 'HEAD');
2551 sub git_get_full_hash
{
2552 return git_get_hash
(@_);
2555 sub git_get_short_hash
{
2556 return git_get_hash
(@_, '--short=7');
2560 my ($project, $hash, @options) = @_;
2561 my $o_git_dir = $git_dir;
2563 $git_dir = "$projectroot/$project";
2564 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2565 '--verify', '-q', @options, $hash) {
2567 chomp $retval if defined $retval;
2570 if (defined $o_git_dir) {
2571 $git_dir = $o_git_dir;
2576 # get type of given object
2580 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2582 close $fd or return;
2587 # repository configuration
2588 our $config_file = '';
2591 # store multiple values for single key as anonymous array reference
2592 # single values stored directly in the hash, not as [ <value> ]
2593 sub hash_set_multi
{
2594 my ($hash, $key, $value) = @_;
2596 if (!exists $hash->{$key}) {
2597 $hash->{$key} = $value;
2598 } elsif (!ref $hash->{$key}) {
2599 $hash->{$key} = [ $hash->{$key}, $value ];
2601 push @{$hash->{$key}}, $value;
2605 # return hash of git project configuration
2606 # optionally limited to some section, e.g. 'gitweb'
2607 sub git_parse_project_config
{
2608 my $section_regexp = shift;
2613 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2616 while (my $keyval = <$fh>) {
2618 my ($key, $value) = split(/\n/, $keyval, 2);
2620 hash_set_multi
(\
%config, $key, $value)
2621 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2628 # convert config value to boolean: 'true' or 'false'
2629 # no value, number > 0, 'true' and 'yes' values are true
2630 # rest of values are treated as false (never as error)
2631 sub config_to_bool
{
2634 return 1 if !defined $val; # section.key
2636 # strip leading and trailing whitespace
2640 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2641 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2644 # convert config value to simple decimal number
2645 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2646 # to be multiplied by 1024, 1048576, or 1073741824
2650 # strip leading and trailing whitespace
2654 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2656 # unknown unit is treated as 1
2657 return $num * ($unit eq 'g' ? 1073741824 :
2658 $unit eq 'm' ? 1048576 :
2659 $unit eq 'k' ? 1024 : 1);
2664 # convert config value to array reference, if needed
2665 sub config_to_multi
{
2668 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2671 sub git_get_project_config
{
2672 my ($key, $type) = @_;
2674 return unless defined $git_dir;
2677 return unless ($key);
2678 # only subsection, if exists, is case sensitive,
2679 # and not lowercased by 'git config -z -l'
2680 if (my ($hi, $mi, $lo) = ($key =~ /^([^.]*)\.(.*)\.([^.]*)$/)) {
2681 $key = join(".", lc($hi), $mi, lc($lo));
2685 $key =~ s/^gitweb\.//;
2686 return if ($key =~ m/\W/);
2689 if (defined $type) {
2692 unless ($type eq 'bool' || $type eq 'int');
2696 if (!defined $config_file ||
2697 $config_file ne "$git_dir/config") {
2698 %config = git_parse_project_config
('gitweb');
2699 $config_file = "$git_dir/config";
2702 # check if config variable (key) exists
2703 return unless exists $config{"gitweb.$key"};
2706 if (!defined $type) {
2707 return $config{"gitweb.$key"};
2708 } elsif ($type eq 'bool') {
2709 # backward compatibility: 'git config --bool' returns true/false
2710 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2711 } elsif ($type eq 'int') {
2712 return config_to_int
($config{"gitweb.$key"});
2714 return $config{"gitweb.$key"};
2717 # get hash of given path at given ref
2718 sub git_get_hash_by_path
{
2720 my $path = shift || return undef;
2725 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2726 or die_error
(500, "Open git-ls-tree failed");
2728 close $fd or return undef;
2730 if (!defined $line) {
2731 # there is no tree or hash given by $path at $base
2735 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2736 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2737 if (defined $type && $type ne $2) {
2738 # type doesn't match
2744 # get path of entry with given hash at given tree-ish (ref)
2745 # used to get 'from' filename for combined diff (merge commit) for renames
2746 sub git_get_path_by_hash
{
2747 my $base = shift || return;
2748 my $hash = shift || return;
2752 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2754 while (my $line = <$fd>) {
2757 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2758 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2759 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2768 ## ......................................................................
2769 ## git utility functions, directly accessing git repository
2771 # get the value of config variable either from file named as the variable
2772 # itself in the repository ($GIT_DIR/$name file), or from gitweb.$name
2773 # configuration variable in the repository config file.
2774 sub git_get_file_or_project_config
{
2775 my ($path, $name) = @_;
2777 $git_dir = "$projectroot/$path";
2778 open my $fd, '<', "$git_dir/$name"
2779 or return git_get_project_config
($name);
2782 if (defined $conf) {
2788 sub git_get_project_description
{
2790 return git_get_file_or_project_config
($path, 'description');
2793 sub git_get_project_category
{
2795 return git_get_file_or_project_config
($path, 'category');
2799 # supported formats:
2800 # * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)
2801 # - if its contents is a number, use it as tag weight,
2802 # - otherwise add a tag with weight 1
2803 # * $GIT_DIR/ctags file, each line is a tag (with weight 1)
2804 # the same value multiple times increases tag weight
2805 # * `gitweb.ctag' multi-valued repo config variable
2806 sub git_get_project_ctags
{
2807 my $project = shift;
2810 $git_dir = "$projectroot/$project";
2811 if (opendir my $dh, "$git_dir/ctags") {
2812 my @files = grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh);
2813 foreach my $tagfile (@files) {
2814 open my $ct, '<', $tagfile
2820 (my $ctag = $tagfile) =~ s
#.*/##;
2821 if ($val =~ /^\d+$/) {
2822 $ctags->{$ctag} = $val;
2824 $ctags->{$ctag} = 1;
2829 } elsif (open my $fh, '<', "$git_dir/ctags") {
2830 while (my $line = <$fh>) {
2832 $ctags->{$line}++ if $line;
2837 my $taglist = config_to_multi
(git_get_project_config
('ctag'));
2838 foreach my $tag (@$taglist) {
2846 # return hash, where keys are content tags ('ctags'),
2847 # and values are sum of weights of given tag in every project
2848 sub git_gather_all_ctags
{
2849 my $projects = shift;
2852 foreach my $p (@$projects) {
2853 foreach my $ct (keys %{$p->{'ctags'}}) {
2854 $ctags->{$ct} += $p->{'ctags'}->{$ct};
2861 sub git_populate_project_tagcloud
{
2864 # First, merge different-cased tags; tags vote on casing
2866 foreach (keys %$ctags) {
2867 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2868 if (not $ctags_lc{lc $_}->{topcount
}
2869 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2870 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2871 $ctags_lc{lc $_}->{topname
} = $_;
2876 my $matched = $input_params{'ctag'};
2877 if (eval { require HTML
::TagCloud
; 1; }) {
2878 $cloud = HTML
::TagCloud-
>new;
2879 foreach my $ctag (sort keys %ctags_lc) {
2880 # Pad the title with spaces so that the cloud looks
2882 my $title = esc_html
($ctags_lc{$ctag}->{topname
});
2883 $title =~ s/ / /g;
2884 $title =~ s/^/ /g;
2885 $title =~ s/$/ /g;
2886 if (defined $matched && $matched eq $ctag) {
2887 $title = qq(<span class="match">$title</span>);
2889 $cloud->add($title, href
(project
=>undef, ctag
=>$ctag),
2890 $ctags_lc{$ctag}->{count
});
2894 foreach my $ctag (keys %ctags_lc) {
2895 my $title = esc_html
($ctags_lc{$ctag}->{topname
}, -nbsp
=>1);
2896 if (defined $matched && $matched eq $ctag) {
2897 $title = qq(<span class="match">$title</span>);
2899 $cloud->{$ctag}{count
} = $ctags_lc{$ctag}->{count
};
2900 $cloud->{$ctag}{ctag
} =
2901 $cgi->a({-href
=>href
(project
=>undef, ctag
=>$ctag)}, $title);
2907 sub git_show_project_tagcloud
{
2908 my ($cloud, $count) = @_;
2909 if (ref $cloud eq 'HTML::TagCloud') {
2910 return $cloud->html_and_css($count);
2912 my @tags = sort { $cloud->{$a}->{'count'} <=> $cloud->{$b}->{'count'} } keys %$cloud;
2914 '<div id="htmltagcloud"'.($project ? '' : ' align="center"').'>' .
2916 $cloud->{$_}->{'ctag'}
2917 } splice(@tags, 0, $count)) .
2922 sub git_get_project_url_list
{
2925 $git_dir = "$projectroot/$path";
2926 open my $fd, '<', "$git_dir/cloneurl"
2927 or return wantarray ?
2928 @{ config_to_multi
(git_get_project_config
('url')) } :
2929 config_to_multi
(git_get_project_config
('url'));
2930 my @git_project_url_list = map { chomp; $_ } <$fd>;
2933 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2936 sub git_get_projects_list
{
2937 my $filter = shift || '';
2938 my $paranoid = shift;
2941 if (-d
$projects_list) {
2942 # search in directory
2943 my $dir = $projects_list;
2944 # remove the trailing "/"
2946 my $pfxlen = length("$dir");
2947 my $pfxdepth = ($dir =~ tr!/!!);
2948 # when filtering, search only given subdirectory
2949 if ($filter && !$paranoid) {
2955 follow_fast
=> 1, # follow symbolic links
2956 follow_skip
=> 2, # ignore duplicates
2957 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2960 our $project_maxdepth;
2962 # skip project-list toplevel, if we get it.
2963 return if (m!^[/.]$!);
2964 # only directories can be git repositories
2965 return unless (-d
$_);
2966 # don't traverse too deep (Find is super slow on os x)
2967 # $project_maxdepth excludes depth of $projectroot
2968 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2969 $File::Find
::prune
= 1;
2973 my $path = substr($File::Find
::name
, $pfxlen + 1);
2974 # paranoidly only filter here
2975 if ($paranoid && $filter && $path !~ m!^\Q$filter\E/!) {
2978 # we check related file in $projectroot
2979 if (check_export_ok
("$projectroot/$path")) {
2980 push @list, { path
=> $path };
2981 $File::Find
::prune
= 1;
2986 } elsif (-f
$projects_list) {
2987 # read from file(url-encoded):
2988 # 'git%2Fgit.git Linus+Torvalds'
2989 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2990 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2991 open my $fd, '<', $projects_list or return;
2993 while (my $line = <$fd>) {
2995 my ($path, $owner) = split ' ', $line;
2996 $path = unescape
($path);
2997 $owner = unescape
($owner);
2998 if (!defined $path) {
3001 # if $filter is rpovided, check if $path begins with $filter
3002 if ($filter && $path !~ m!^\Q$filter\E/!) {
3005 if (check_export_ok
("$projectroot/$path")) {
3008 owner
=> to_utf8
($owner),
3018 # written with help of Tree::Trie module (Perl Artistic License, GPL compatibile)
3019 # as side effects it sets 'forks' field to list of forks for forked projects
3020 sub filter_forks_from_projects_list
{
3021 my $projects = shift;
3023 my %trie; # prefix tree of directories (path components)
3024 # generate trie out of those directories that might contain forks
3025 foreach my $pr (@$projects) {
3026 my $path = $pr->{'path'};
3027 $path =~ s/\.git$//; # forks of 'repo.git' are in 'repo/' directory
3028 next if ($path =~ m!/$!); # skip non-bare repositories, e.g. 'repo/.git'
3029 next unless ($path); # skip '.git' repository: tests, git-instaweb
3030 next unless (-d
"$projectroot/$path"); # containing directory exists
3031 $pr->{'forks'} = []; # there can be 0 or more forks of project
3034 my @dirs = split('/', $path);
3035 # walk the trie, until either runs out of components or out of trie
3037 while (scalar @dirs &&
3038 exists($ref->{$dirs[0]})) {
3039 $ref = $ref->{shift @dirs};
3041 # create rest of trie structure from rest of components
3042 foreach my $dir (@dirs) {
3043 $ref = $ref->{$dir} = {};
3045 # create end marker, store $pr as a data
3046 $ref->{''} = $pr if (!exists $ref->{''});
3049 # filter out forks, by finding shortest prefix match for paths
3052 foreach my $pr (@$projects) {
3056 foreach my $dir (split('/', $pr->{'path'})) {
3057 if (exists $ref->{''}) {
3058 # found [shortest] prefix, is a fork - skip it
3059 push @{$ref->{''}{'forks'}}, $pr;
3062 if (!exists $ref->{$dir}) {
3063 # not in trie, cannot have prefix, not a fork
3064 push @filtered, $pr;
3067 # If the dir is there, we just walk one step down the trie.
3068 $ref = $ref->{$dir};
3070 # we ran out of trie
3071 # (shouldn't happen: it's either no match, or end marker)
3072 push @filtered, $pr;
3078 # note: fill_project_list_info must be run first,
3079 # for 'descr_long' and 'ctags' to be filled
3080 sub search_projects_list
{
3081 my ($projlist, %opts) = @_;
3082 my $tagfilter = $opts{'tagfilter'};
3083 my $search_re = $opts{'search_regexp'};
3086 unless ($tagfilter || $search_re);
3088 # searching projects require filling to be run before it;
3089 fill_project_list_info
($projlist,
3090 $tagfilter ? 'ctags' : (),
3091 $search_re ? ('path', 'descr') : ());
3094 foreach my $pr (@$projlist) {
3097 next unless ref($pr->{'ctags'}) eq 'HASH';
3099 grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
3104 $pr->{'path'} =~ /$search_re/ ||
3105 $pr->{'descr_long'} =~ /$search_re/;
3108 push @projects, $pr;
3114 our $gitweb_project_owner = undef;
3115 sub git_get_project_list_from_file
{
3117 return if (defined $gitweb_project_owner);
3119 $gitweb_project_owner = {};
3120 # read from file (url-encoded):
3121 # 'git%2Fgit.git Linus+Torvalds'
3122 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
3123 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
3124 if (-f
$projects_list) {
3125 open(my $fd, '<', $projects_list);
3126 while (my $line = <$fd>) {
3128 my ($pr, $ow) = split ' ', $line;
3129 $pr = unescape
($pr);
3130 $ow = unescape
($ow);
3131 $gitweb_project_owner->{$pr} = to_utf8
($ow);
3137 sub git_get_project_owner
{
3138 my $project = shift;
3141 return undef unless $project;
3142 $git_dir = "$projectroot/$project";
3144 if (!defined $gitweb_project_owner) {
3145 git_get_project_list_from_file
();
3148 if (exists $gitweb_project_owner->{$project}) {
3149 $owner = $gitweb_project_owner->{$project};
3151 if (!defined $owner){
3152 $owner = git_get_project_config
('owner');
3154 if (!defined $owner) {
3155 $owner = get_file_owner
("$git_dir");
3161 sub git_get_last_activity
{
3165 $git_dir = "$projectroot/$path";
3166 open($fd, "-|", git_cmd
(), 'for-each-ref',
3167 '--format=%(committer)',
3168 '--sort=-committerdate',
3170 'refs/heads') or return;
3171 my $most_recent = <$fd>;
3172 close $fd or return;
3173 if (defined $most_recent &&
3174 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
3176 my $age = time - $timestamp;
3177 return ($age, age_string
($age));
3179 return (undef, undef);
3182 # Implementation note: when a single remote is wanted, we cannot use 'git
3183 # remote show -n' because that command always work (assuming it's a remote URL
3184 # if it's not defined), and we cannot use 'git remote show' because that would
3185 # try to make a network roundtrip. So the only way to find if that particular
3186 # remote is defined is to walk the list provided by 'git remote -v' and stop if
3187 # and when we find what we want.
3188 sub git_get_remotes_list
{
3192 open my $fd, '-|' , git_cmd
(), 'remote', '-v';
3194 while (my $remote = <$fd>) {
3196 $remote =~ s!\t(.*?)\s+\((\w+)\)$!!;
3197 next if $wanted and not $remote eq $wanted;
3198 my ($url, $key) = ($1, $2);
3200 $remotes{$remote} ||= { 'heads' => () };
3201 $remotes{$remote}{$key} = $url;
3203 close $fd or return;
3204 return wantarray ? %remotes : \
%remotes;
3207 # Takes a hash of remotes as first parameter and fills it by adding the
3208 # available remote heads for each of the indicated remotes.
3209 sub fill_remote_heads
{
3210 my $remotes = shift;
3211 my @heads = map { "remotes/$_" } keys %$remotes;
3212 my @remoteheads = git_get_heads_list
(undef, @heads);
3213 foreach my $remote (keys %$remotes) {
3214 $remotes->{$remote}{'heads'} = [ grep {
3215 $_->{'name'} =~ s!^$remote/!!
3220 sub git_get_references
{
3221 my $type = shift || "";
3223 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
3224 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
3225 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
3226 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
3229 while (my $line = <$fd>) {
3231 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
3232 if (defined $refs{$1}) {
3233 push @{$refs{$1}}, $2;
3239 close $fd or return;
3243 sub git_get_rev_name_tags
{
3244 my $hash = shift || return undef;
3246 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
3248 my $name_rev = <$fd>;
3251 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
3254 # catches also '$hash undefined' output
3259 ## ----------------------------------------------------------------------
3260 ## parse to hash functions
3264 my $tz = shift || "-0000";
3267 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
3268 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
3269 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
3270 $date{'hour'} = $hour;
3271 $date{'minute'} = $min;
3272 $date{'mday'} = $mday;
3273 $date{'day'} = $days[$wday];
3274 $date{'month'} = $months[$mon];
3275 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
3276 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
3277 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
3278 $mday, $months[$mon], $hour ,$min;
3279 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
3280 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
3282 my ($tz_sign, $tz_hour, $tz_min) =
3283 ($tz =~ m/^([-+])(\d\d)(\d\d)$/);
3284 $tz_sign = ($tz_sign eq '-' ? -1 : +1);
3285 my $local = $epoch + $tz_sign*((($tz_hour*60) + $tz_min)*60);
3286 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
3287 $date{'hour_local'} = $hour;
3288 $date{'minute_local'} = $min;
3289 $date{'tz_local'} = $tz;
3290 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
3291 1900+$year, $mon+1, $mday,
3292 $hour, $min, $sec, $tz);
3301 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
3302 $tag{'id'} = $tag_id;
3303 while (my $line = <$fd>) {
3305 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
3306 $tag{'object'} = $1;
3307 } elsif ($line =~ m/^type (.+)$/) {
3309 } elsif ($line =~ m/^tag (.+)$/) {
3311 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
3312 $tag{'author'} = $1;
3313 $tag{'author_epoch'} = $2;
3314 $tag{'author_tz'} = $3;
3315 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
3316 $tag{'author_name'} = $1;
3317 $tag{'author_email'} = $2;
3319 $tag{'author_name'} = $tag{'author'};
3321 } elsif ($line =~ m/--BEGIN/) {
3322 push @comment, $line;
3324 } elsif ($line eq "") {
3328 push @comment, <$fd>;
3329 $tag{'comment'} = \
@comment;
3330 close $fd or return;
3331 if (!defined $tag{'name'}) {
3337 sub parse_commit_text
{
3338 my ($commit_text, $withparents) = @_;
3339 my @commit_lines = split '\n', $commit_text;
3342 pop @commit_lines; # Remove '\0'
3344 if (! @commit_lines) {
3348 my $header = shift @commit_lines;
3349 if ($header !~ m/^[0-9a-fA-F]{40}/) {
3352 ($co{'id'}, my @parents) = split ' ', $header;
3353 while (my $line = shift @commit_lines) {
3354 last if $line eq "\n";
3355 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
3357 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
3359 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
3360 $co{'author'} = to_utf8
($1);
3361 $co{'author_epoch'} = $2;
3362 $co{'author_tz'} = $3;
3363 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
3364 $co{'author_name'} = $1;
3365 $co{'author_email'} = $2;
3367 $co{'author_name'} = $co{'author'};
3369 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
3370 $co{'committer'} = to_utf8
($1);
3371 $co{'committer_epoch'} = $2;
3372 $co{'committer_tz'} = $3;
3373 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
3374 $co{'committer_name'} = $1;
3375 $co{'committer_email'} = $2;
3377 $co{'committer_name'} = $co{'committer'};
3381 if (!defined $co{'tree'}) {
3384 $co{'parents'} = \
@parents;
3385 $co{'parent'} = $parents[0];
3387 foreach my $title (@commit_lines) {
3390 $co{'title'} = chop_str
($title, 80, 5);
3391 # remove leading stuff of merges to make the interesting part visible
3392 if (length($title) > 50) {
3393 $title =~ s/^Automatic //;
3394 $title =~ s/^merge (of|with) /Merge ... /i;
3395 if (length($title) > 50) {
3396 $title =~ s/(http|rsync):\/\///;
3398 if (length($title) > 50) {
3399 $title =~ s/(master|www|rsync)\.//;
3401 if (length($title) > 50) {
3402 $title =~ s/kernel.org:?//;
3404 if (length($title) > 50) {
3405 $title =~ s/\/pub\/scm//;
3408 $co{'title_short'} = chop_str
($title, 50, 5);
3412 if (! defined $co{'title'} || $co{'title'} eq "") {
3413 $co{'title'} = $co{'title_short'} = '(no commit message)';
3415 # remove added spaces
3416 foreach my $line (@commit_lines) {
3419 $co{'comment'} = \
@commit_lines;
3421 my $age = time - $co{'committer_epoch'};
3423 $co{'age_string'} = age_string
($age);
3424 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
3425 if ($age > 60*60*24*7*2) {
3426 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3427 $co{'age_string_age'} = $co{'age_string'};
3429 $co{'age_string_date'} = $co{'age_string'};
3430 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3436 my ($commit_id) = @_;
3441 open my $fd, "-|", git_cmd
(), "rev-list",
3447 or die_error
(500, "Open git-rev-list failed");
3448 %co = parse_commit_text
(<$fd>, 1);
3455 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
3463 open my $fd, "-|", git_cmd
(), "rev-list",
3466 ("--max-count=" . $maxcount),
3467 ("--skip=" . $skip),
3471 ($filename ? ($filename) : ())
3472 or die_error
(500, "Open git-rev-list failed");
3473 while (my $line = <$fd>) {
3474 my %co = parse_commit_text
($line);
3479 return wantarray ? @cos : \
@cos;
3482 # parse line of git-diff-tree "raw" output
3483 sub parse_difftree_raw_line
{
3487 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3488 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3489 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3490 $res{'from_mode'} = $1;
3491 $res{'to_mode'} = $2;
3492 $res{'from_id'} = $3;
3494 $res{'status'} = $5;
3495 $res{'similarity'} = $6;
3496 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3497 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3499 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3502 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3503 # combined diff (for merge commit)
3504 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3505 $res{'nparents'} = length($1);
3506 $res{'from_mode'} = [ split(' ', $2) ];
3507 $res{'to_mode'} = pop @{$res{'from_mode'}};
3508 $res{'from_id'} = [ split(' ', $3) ];
3509 $res{'to_id'} = pop @{$res{'from_id'}};
3510 $res{'status'} = [ split('', $4) ];
3511 $res{'to_file'} = unquote
($5);
3513 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3514 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3515 $res{'commit'} = $1;
3518 return wantarray ? %res : \
%res;
3521 # wrapper: return parsed line of git-diff-tree "raw" output
3522 # (the argument might be raw line, or parsed info)
3523 sub parsed_difftree_line
{
3524 my $line_or_ref = shift;
3526 if (ref($line_or_ref) eq "HASH") {
3527 # pre-parsed (or generated by hand)
3528 return $line_or_ref;
3530 return parse_difftree_raw_line
($line_or_ref);
3534 # parse line of git-ls-tree output
3535 sub parse_ls_tree_line
{
3541 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3542 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3551 $res{'name'} = unquote
($5);
3554 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3555 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3563 $res{'name'} = unquote
($4);
3567 return wantarray ? %res : \
%res;
3570 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3571 sub parse_from_to_diffinfo
{
3572 my ($diffinfo, $from, $to, @parents) = @_;
3574 if ($diffinfo->{'nparents'}) {
3576 $from->{'file'} = [];
3577 $from->{'href'} = [];
3578 fill_from_file_info
($diffinfo, @parents)
3579 unless exists $diffinfo->{'from_file'};
3580 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3581 $from->{'file'}[$i] =
3582 defined $diffinfo->{'from_file'}[$i] ?
3583 $diffinfo->{'from_file'}[$i] :
3584 $diffinfo->{'to_file'};
3585 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3586 $from->{'href'}[$i] = href
(action
=>"blob",
3587 hash_base
=>$parents[$i],
3588 hash
=>$diffinfo->{'from_id'}[$i],
3589 file_name
=>$from->{'file'}[$i]);
3591 $from->{'href'}[$i] = undef;
3595 # ordinary (not combined) diff
3596 $from->{'file'} = $diffinfo->{'from_file'};
3597 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3598 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3599 hash
=>$diffinfo->{'from_id'},
3600 file_name
=>$from->{'file'});
3602 delete $from->{'href'};
3606 $to->{'file'} = $diffinfo->{'to_file'};
3607 if (!is_deleted
($diffinfo)) { # file exists in result
3608 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3609 hash
=>$diffinfo->{'to_id'},
3610 file_name
=>$to->{'file'});
3612 delete $to->{'href'};
3616 ## ......................................................................
3617 ## parse to array of hashes functions
3619 sub git_get_heads_list
{
3620 my ($limit, @classes) = @_;
3621 @classes = ('heads') unless @classes;
3622 my @patterns = map { "refs/$_" } @classes;
3625 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3626 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
3627 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3630 while (my $line = <$fd>) {
3634 my ($refinfo, $committerinfo) = split(/\0/, $line);
3635 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3636 my ($committer, $epoch, $tz) =
3637 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3638 $ref_item{'fullname'} = $name;
3639 $name =~ s!^refs/(?:head|remote)s/!!;
3641 $ref_item{'name'} = $name;
3642 $ref_item{'id'} = $hash;
3643 $ref_item{'title'} = $title || '(no commit message)';
3644 $ref_item{'epoch'} = $epoch;
3646 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3648 $ref_item{'age'} = "unknown";
3651 push @headslist, \
%ref_item;
3655 return wantarray ? @headslist : \
@headslist;
3658 sub git_get_tags_list
{
3662 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3663 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
3664 '--format=%(objectname) %(objecttype) %(refname) '.
3665 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3668 while (my $line = <$fd>) {
3672 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3673 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3674 my ($creator, $epoch, $tz) =
3675 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3676 $ref_item{'fullname'} = $name;
3677 $name =~ s!^refs/tags/!!;
3679 $ref_item{'type'} = $type;
3680 $ref_item{'id'} = $id;
3681 $ref_item{'name'} = $name;
3682 if ($type eq "tag") {
3683 $ref_item{'subject'} = $title;
3684 $ref_item{'reftype'} = $reftype;
3685 $ref_item{'refid'} = $refid;
3687 $ref_item{'reftype'} = $type;
3688 $ref_item{'refid'} = $id;
3691 if ($type eq "tag" || $type eq "commit") {
3692 $ref_item{'epoch'} = $epoch;
3694 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3696 $ref_item{'age'} = "unknown";
3700 push @tagslist, \
%ref_item;
3704 return wantarray ? @tagslist : \
@tagslist;
3707 ## ----------------------------------------------------------------------
3708 ## filesystem-related functions
3710 sub get_file_owner
{
3713 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3714 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3715 if (!defined $gcos) {
3719 $owner =~ s/[,;].*$//;
3720 return to_utf8
($owner);
3723 # assume that file exists
3725 my $filename = shift;
3727 open my $fd, '<', $filename;
3728 print map { to_utf8
($_) } <$fd>;
3732 ## ......................................................................
3733 ## mimetype related functions
3735 sub mimetype_guess_file
{
3736 my $filename = shift;
3737 my $mimemap = shift;
3738 -r
$mimemap or return undef;
3741 open(my $mh, '<', $mimemap) or return undef;
3743 next if m/^#/; # skip comments
3744 my ($mimetype, @exts) = split(/\s+/);
3745 foreach my $ext (@exts) {
3746 $mimemap{$ext} = $mimetype;
3751 $filename =~ /\.([^.]*)$/;
3752 return $mimemap{$1};
3755 sub mimetype_guess
{
3756 my $filename = shift;
3758 $filename =~ /\./ or return undef;
3760 if ($mimetypes_file) {
3761 my $file = $mimetypes_file;
3762 if ($file !~ m!^/!) { # if it is relative path
3763 # it is relative to project
3764 $file = "$projectroot/$project/$file";
3766 $mime = mimetype_guess_file
($filename, $file);
3768 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3774 my $filename = shift;
3777 my $mime = mimetype_guess
($filename);
3778 $mime and return $mime;
3782 return $default_blob_plain_mimetype unless $fd;
3785 return 'text/plain';
3786 } elsif (! $filename) {
3787 return 'application/octet-stream';
3788 } elsif ($filename =~ m/\.png$/i) {
3790 } elsif ($filename =~ m/\.gif$/i) {
3792 } elsif ($filename =~ m/\.jpe?g$/i) {
3793 return 'image/jpeg';
3795 return 'application/octet-stream';
3799 sub blob_contenttype
{
3800 my ($fd, $file_name, $type) = @_;
3802 $type ||= blob_mimetype
($fd, $file_name);
3803 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3804 $type .= "; charset=$default_text_plain_charset";
3810 # guess file syntax for syntax highlighting; return undef if no highlighting
3811 # the name of syntax can (in the future) depend on syntax highlighter used
3812 sub guess_file_syntax
{
3813 my ($highlight, $mimetype, $file_name) = @_;
3814 return undef unless ($highlight && defined $file_name);
3815 my $basename = basename
($file_name, '.in');
3816 return $highlight_basename{$basename}
3817 if exists $highlight_basename{$basename};
3819 $basename =~ /\.([^.]*)$/;
3820 my $ext = $1 or return undef;
3821 return $highlight_ext{$ext}
3822 if exists $highlight_ext{$ext};
3827 # run highlighter and return FD of its output,
3828 # or return original FD if no highlighting
3829 sub run_highlighter
{
3830 my ($fd, $highlight, $syntax) = @_;
3831 return $fd unless ($highlight && defined $syntax);
3834 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3835 quote_command
($highlight_bin).
3836 " --replace-tabs=8 --fragment --syntax $syntax |"
3837 or die_error
(500, "Couldn't open file or run syntax highlighter");
3841 ## ======================================================================
3842 ## functions printing HTML: header, footer, error page
3844 sub get_page_title
{
3845 my $title = to_utf8
($site_name);
3847 unless (defined $project) {
3848 if (defined $project_filter) {
3849 $title .= " - projects in '" . esc_path
($project_filter) . "'";
3853 $title .= " - " . to_utf8
($project);
3855 return $title unless (defined $action);
3856 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3858 return $title unless (defined $file_name);
3859 $title .= " - " . esc_path
($file_name);
3860 if ($action eq "tree" && $file_name !~ m
|/$|) {
3867 sub get_content_type_html
{
3868 # require explicit support from the UA if we are to send the page as
3869 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3870 # we have to do this because MSIE sometimes globs '*/*', pretending to
3871 # support xhtml+xml but choking when it gets what it asked for.
3872 if (defined $cgi->http('HTTP_ACCEPT') &&
3873 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3874 $cgi->Accept('application/xhtml+xml') != 0) {
3875 return 'application/xhtml+xml';
3881 sub print_feed_meta
{
3882 if (defined $project) {
3883 my %href_params = get_feed_info
();
3884 if (!exists $href_params{'-title'}) {
3885 $href_params{'-title'} = 'log';
3888 foreach my $format (qw(RSS Atom)) {
3889 my $type = lc($format);
3891 '-rel' => 'alternate',
3892 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3893 '-type' => "application/$type+xml"
3896 $href_params{'extra_options'} = undef;
3897 $href_params{'action'} = $type;
3898 $link_attr{'-href'} = href
(%href_params);
3900 "rel=\"$link_attr{'-rel'}\" ".
3901 "title=\"$link_attr{'-title'}\" ".
3902 "href=\"$link_attr{'-href'}\" ".
3903 "type=\"$link_attr{'-type'}\" ".
3906 $href_params{'extra_options'} = '--no-merges';
3907 $link_attr{'-href'} = href
(%href_params);
3908 $link_attr{'-title'} .= ' (no merges)';
3910 "rel=\"$link_attr{'-rel'}\" ".
3911 "title=\"$link_attr{'-title'}\" ".
3912 "href=\"$link_attr{'-href'}\" ".
3913 "type=\"$link_attr{'-type'}\" ".
3918 printf('<link rel="alternate" title="%s projects list" '.
3919 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3920 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3921 printf('<link rel="alternate" title="%s projects feeds" '.
3922 'href="%s" type="text/x-opml" />'."\n",
3923 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3927 sub print_header_links
{
3930 # print out each stylesheet that exist, providing backwards capability
3931 # for those people who defined $stylesheet in a config file
3932 if (defined $stylesheet) {
3933 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3935 foreach my $stylesheet (@stylesheets) {
3936 next unless $stylesheet;
3937 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3941 if ($status eq '200 OK');
3942 if (defined $favicon) {
3943 print qq(<link rel="shortcut icon" href=").esc_url
($favicon).qq(" type="image/png" />\n);
3947 sub print_nav_breadcrumbs_path
{
3948 my $dirprefix = undef;
3949 while (my $part = shift) {
3950 $dirprefix .= "/" if defined $dirprefix;
3951 $dirprefix .= $part;
3952 print $cgi->a({-href
=> href
(project
=> undef,
3953 project_filter
=> $dirprefix,
3954 action
=> "project_list")},
3955 esc_html
($part)) . " / ";
3959 sub print_nav_breadcrumbs
{
3962 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3963 if (defined $project) {
3964 my @dirname = split '/', $project;
3965 my $projectbasename = pop @dirname;
3966 print_nav_breadcrumbs_path
(@dirname);
3967 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($projectbasename));
3968 if (defined $action) {
3969 my $action_print = $action ;
3970 if (defined $opts{-action_extra
}) {
3971 $action_print = $cgi->a({-href
=> href
(action
=>$action)},
3974 print " / $action_print";
3976 if (defined $opts{-action_extra
}) {
3977 print " / $opts{-action_extra}";
3980 } elsif (defined $project_filter) {
3981 print_nav_breadcrumbs_path
(split '/', $project_filter);
3985 sub print_search_form
{
3986 if (!defined $searchtext) {
3990 if (defined $hash_base) {
3991 $search_hash = $hash_base;
3992 } elsif (defined $hash) {
3993 $search_hash = $hash;
3995 $search_hash = "HEAD";
3997 my $action = $my_uri;
3998 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3999 if ($use_pathinfo) {
4000 $action .= "/".esc_url
($project);
4002 print $cgi->startform(-method => "get", -action
=> $action) .
4003 "<div class=\"search\">\n" .
4005 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
4006 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
4007 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
4008 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
4009 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
4010 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
4012 $cgi->textfield(-name
=> "s", -value
=> $searchtext, -override
=> 1) . "\n" .
4013 "<span title=\"Extended regular expression\">" .
4014 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
4015 -checked
=> $search_use_regexp) .
4018 $cgi->end_form() . "\n";
4021 sub git_header_html
{
4022 my $status = shift || "200 OK";
4023 my $expires = shift;
4026 my $title = get_page_title
();
4027 my $content_type = get_content_type_html
();
4028 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
4029 -status
=> $status, -expires
=> $expires)
4030 unless ($opts{'-no_http_header'});
4031 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
4033 <?xml version="1.0" encoding="utf-8"?>
4034 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4035 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
4036 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
4037 <!-- git core binaries version $git_version -->
4039 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
4040 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
4041 <meta name="robots" content="index, nofollow"/>
4042 <title>$title</title>
4044 # the stylesheet, favicon etc urls won't work correctly with path_info
4045 # unless we set the appropriate base URL
4046 if ($ENV{'PATH_INFO'}) {
4047 print "<base href=\"".esc_url
($base_url)."\" />\n";
4049 print_header_links
($status);
4051 if (defined $site_html_head_string) {
4052 print to_utf8
($site_html_head_string);
4058 if (defined $site_header && -f
$site_header) {
4059 insert_file
($site_header);
4062 print "<div class=\"page_header\">\n";
4063 if (defined $logo) {
4064 print $cgi->a({-href
=> esc_url
($logo_url),
4065 -title
=> $logo_label},
4066 $cgi->img({-src
=> esc_url
($logo),
4067 -width
=> 72, -height
=> 27,
4069 -class => "logo"}));
4071 print_nav_breadcrumbs
(%opts);
4074 my $have_search = gitweb_check_feature
('search');
4075 if (defined $project && $have_search) {
4076 print_search_form
();
4080 sub git_footer_html
{
4081 my $feed_class = 'rss_logo';
4083 print "<div class=\"page_footer\">\n";
4084 if (defined $project) {
4085 my $descr = git_get_project_description
($project);
4086 if (defined $descr) {
4087 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
4090 my %href_params = get_feed_info
();
4091 if (!%href_params) {
4092 $feed_class .= ' generic';
4094 $href_params{'-title'} ||= 'log';
4096 foreach my $format (qw(RSS Atom)) {
4097 $href_params{'action'} = lc($format);
4098 print $cgi->a({-href
=> href
(%href_params),
4099 -title
=> "$href_params{'-title'} $format feed",
4100 -class => $feed_class}, $format)."\n";
4104 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml",
4105 project_filter
=> $project_filter),
4106 -class => $feed_class}, "OPML") . " ";
4107 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index",
4108 project_filter
=> $project_filter),
4109 -class => $feed_class}, "TXT") . "\n";
4111 print "</div>\n"; # class="page_footer"
4113 if (defined $t0 && gitweb_check_feature
('timed')) {
4114 print "<div id=\"generating_info\">\n";
4115 print 'This page took '.
4116 '<span id="generating_time" class="time_span">'.
4117 tv_interval
($t0, [ gettimeofday
() ]).
4120 '<span id="generating_cmd">'.
4121 $number_of_git_cmds.
4122 '</span> git commands '.
4124 print "</div>\n"; # class="page_footer"
4127 if (defined $site_footer && -f
$site_footer) {
4128 insert_file
($site_footer);
4131 print qq
!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
4132 if (defined $action &&
4133 $action eq 'blame_incremental') {
4134 print qq
!<script type
="text/javascript">\n!.
4135 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
4136 qq
! "!. href() .qq!");\n!.
4139 my ($jstimezone, $tz_cookie, $datetime_class) =
4140 gitweb_get_feature
('javascript-timezone');
4142 print qq
!<script type
="text/javascript">\n!.
4143 qq
!window
.onload
= function
() {\n!;
4144 if (gitweb_check_feature
('javascript-actions')) {
4145 print qq
! fixLinks
();\n!;
4147 if ($jstimezone && $tz_cookie && $datetime_class) {
4148 print qq
! var tz_cookie
= { name
: '$tz_cookie', expires
: 14, path
: '/' };\n!. # in days
4149 qq
! onloadTZSetup
('$jstimezone', tz_cookie
, '$datetime_class');\n!;
4159 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
4160 # Example: die_error(404, 'Hash not found')
4161 # By convention, use the following status codes (as defined in RFC 2616):
4162 # 400: Invalid or missing CGI parameters, or
4163 # requested object exists but has wrong type.
4164 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
4165 # this server or project.
4166 # 404: Requested object/revision/project doesn't exist.
4167 # 500: The server isn't configured properly, or
4168 # an internal error occurred (e.g. failed assertions caused by bugs), or
4169 # an unknown error occurred (e.g. the git binary died unexpectedly).
4170 # 503: The server is currently unavailable (because it is overloaded,
4171 # or down for maintenance). Generally, this is a temporary state.
4173 my $status = shift || 500;
4174 my $error = esc_html
(shift) || "Internal Server Error";
4178 my %http_responses = (
4179 400 => '400 Bad Request',
4180 403 => '403 Forbidden',
4181 404 => '404 Not Found',
4182 500 => '500 Internal Server Error',
4183 503 => '503 Service Unavailable',
4185 git_header_html
($http_responses{$status}, undef, %opts);
4187 <div class="page_body">
4192 if (defined $extra) {
4200 unless ($opts{'-error_handler'});
4203 ## ----------------------------------------------------------------------
4204 ## functions printing or outputting HTML: navigation
4206 sub git_print_page_nav
{
4207 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
4208 $extra = '' if !defined $extra; # pager or formats
4210 my @navs = qw(summary shortlog log commit commitdiff tree);
4212 @navs = grep { $_ ne $suppress } @navs;
4215 my %arg = map { $_ => {action
=>$_} } @navs;
4216 if (defined $head) {
4217 for (qw(commit commitdiff)) {
4218 $arg{$_}{'hash'} = $head;
4220 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
4221 for (qw(shortlog log)) {
4222 $arg{$_}{'hash'} = $head;
4227 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
4228 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
4230 my @actions = gitweb_get_feature
('actions');
4233 'n' => $project, # project name
4234 'f' => $git_dir, # project path within filesystem
4235 'h' => $treehead || '', # current hash ('h' parameter)
4236 'b' => $treebase || '', # hash base ('hb' parameter)
4239 my ($label, $link, $pos) = splice(@actions,0,3);
4241 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
4243 $link =~ s/%([%nfhb])/$repl{$1}/g;
4244 $arg{$label}{'_href'} = $link;
4247 print "<div class=\"page_nav\">\n" .
4249 map { $_ eq $current ?
4250 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
4252 print "<br/>\n$extra<br/>\n" .
4256 # returns a submenu for the nagivation of the refs views (tags, heads,
4257 # remotes) with the current view disabled and the remotes view only
4258 # available if the feature is enabled
4259 sub format_ref_views
{
4261 my @ref_views = qw{tags heads};
4262 push @ref_views, 'remotes' if gitweb_check_feature
('remote_heads');
4263 return join " | ", map {
4264 $_ eq $current ? $_ :
4265 $cgi->a({-href
=> href
(action
=>$_)}, $_)
4269 sub format_paging_nav
{
4270 my ($action, $page, $has_next_link) = @_;
4276 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
4278 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
4279 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4281 $paging_nav .= "first ⋅ prev";
4284 if ($has_next_link) {
4285 $paging_nav .= " ⋅ " .
4286 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4287 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4289 $paging_nav .= " ⋅ next";
4295 ## ......................................................................
4296 ## functions printing or outputting HTML: div
4298 sub git_print_header_div
{
4299 my ($action, $title, $hash, $hash_base) = @_;
4302 $args{'action'} = $action;
4303 $args{'hash'} = $hash if $hash;
4304 $args{'hash_base'} = $hash_base if $hash_base;
4306 print "<div class=\"header\">\n" .
4307 $cgi->a({-href
=> href
(%args), -class => "title"},
4308 $title ? $title : $action) .
4312 sub format_repo_url
{
4313 my ($name, $url) = @_;
4314 return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
4317 # Group output by placing it in a DIV element and adding a header.
4318 # Options for start_div() can be provided by passing a hash reference as the
4319 # first parameter to the function.
4320 # Options to git_print_header_div() can be provided by passing an array
4321 # reference. This must follow the options to start_div if they are present.
4322 # The content can be a scalar, which is output as-is, a scalar reference, which
4323 # is output after html escaping, an IO handle passed either as *handle or
4324 # *handle{IO}, or a function reference. In the latter case all following
4325 # parameters will be taken as argument to the content function call.
4326 sub git_print_section
{
4327 my ($div_args, $header_args, $content);
4329 if (ref($arg) eq 'HASH') {
4333 if (ref($arg) eq 'ARRAY') {
4334 $header_args = $arg;
4339 print $cgi->start_div($div_args);
4340 git_print_header_div
(@$header_args);
4342 if (ref($content) eq 'CODE') {
4344 } elsif (ref($content) eq 'SCALAR') {
4345 print esc_html
($$content);
4346 } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
4348 } elsif (!ref($content) && defined($content)) {
4352 print $cgi->end_div;
4355 sub format_timestamp_html
{
4357 my $strtime = $date->{'rfc2822'};
4359 my (undef, undef, $datetime_class) =
4360 gitweb_get_feature
('javascript-timezone');
4361 if ($datetime_class) {
4362 $strtime = qq
!<span
class="$datetime_class">$strtime</span
>!;
4365 my $localtime_format = '(%02d:%02d %s)';
4366 if ($date->{'hour_local'} < 6) {
4367 $localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
4370 sprintf($localtime_format,
4371 $date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
4376 # Outputs the author name and date in long form
4377 sub git_print_authorship
{
4380 my $tag = $opts{-tag
} || 'div';
4381 my $author = $co->{'author_name'};
4383 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
4384 print "<$tag class=\"author_date\">" .
4385 format_search_author
($author, "author", esc_html
($author)) .
4386 " [".format_timestamp_html
(\
%ad)."]".
4387 git_get_avatar
($co->{'author_email'}, -pad_before
=> 1) .
4391 # Outputs table rows containing the full author or committer information,
4392 # in the format expected for 'commit' view (& similar).
4393 # Parameters are a commit hash reference, followed by the list of people
4394 # to output information for. If the list is empty it defaults to both
4395 # author and committer.
4396 sub git_print_authorship_rows
{
4398 # too bad we can't use @people = @_ || ('author', 'committer')
4400 @people = ('author', 'committer') unless @people;
4401 foreach my $who (@people) {
4402 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
4403 print "<tr><td>$who</td><td>" .
4404 format_search_author
($co->{"${who}_name"}, $who,
4405 esc_html
($co->{"${who}_name"})) . " " .
4406 format_search_author
($co->{"${who}_email"}, $who,
4407 esc_html
("<" . $co->{"${who}_email"} . ">")) .
4408 "</td><td rowspan=\"2\">" .
4409 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
4413 format_timestamp_html
(\
%wd) .
4419 sub git_print_page_path
{
4425 print "<div class=\"page_path\">";
4426 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
4427 -title
=> 'tree root'}, to_utf8
("[$project]"));
4429 if (defined $name) {
4430 my @dirname = split '/', $name;
4431 my $basename = pop @dirname;
4434 foreach my $dir (@dirname) {
4435 $fullname .= ($fullname ? '/' : '') . $dir;
4436 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
4438 -title
=> $fullname}, esc_path
($dir));
4441 if (defined $type && $type eq 'blob') {
4442 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
4444 -title
=> $name}, esc_path
($basename));
4445 } elsif (defined $type && $type eq 'tree') {
4446 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
4448 -title
=> $name}, esc_path
($basename));
4451 print esc_path
($basename);
4454 print "<br/></div>\n";
4461 if ($opts{'-remove_title'}) {
4462 # remove title, i.e. first line of log
4465 # remove leading empty lines
4466 while (defined $log->[0] && $log->[0] eq "") {
4473 foreach my $line (@$log) {
4474 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
4477 if (! $opts{'-remove_signoff'}) {
4478 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
4481 # remove signoff lines
4488 # print only one empty line
4489 # do not print empty line after signoff
4491 next if ($empty || $signoff);
4497 print format_log_line_html
($line) . "<br/>\n";
4500 if ($opts{'-final_empty_line'}) {
4501 # end with single empty line
4502 print "<br/>\n" unless $empty;
4506 # return link target (what link points to)
4507 sub git_get_link_target
{
4512 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4516 $link_target = <$fd>;
4521 return $link_target;
4524 # given link target, and the directory (basedir) the link is in,
4525 # return target of link relative to top directory (top tree);
4526 # return undef if it is not possible (including absolute links).
4527 sub normalize_link_target
{
4528 my ($link_target, $basedir) = @_;
4530 # absolute symlinks (beginning with '/') cannot be normalized
4531 return if (substr($link_target, 0, 1) eq '/');
4533 # normalize link target to path from top (root) tree (dir)
4536 $path = $basedir . '/' . $link_target;
4538 # we are in top (root) tree (dir)
4539 $path = $link_target;
4542 # remove //, /./, and /../
4544 foreach my $part (split('/', $path)) {
4545 # discard '.' and ''
4546 next if (!$part || $part eq '.');
4548 if ($part eq '..') {
4552 # link leads outside repository (outside top dir)
4556 push @path_parts, $part;
4559 $path = join('/', @path_parts);
4564 # print tree entry (row of git_tree), but without encompassing <tr> element
4565 sub git_print_tree_entry
{
4566 my ($t, $basedir, $hash_base, $have_blame) = @_;
4569 $base_key{'hash_base'} = $hash_base if defined $hash_base;
4571 # The format of a table row is: mode list link. Where mode is
4572 # the mode of the entry, list is the name of the entry, an href,
4573 # and link is the action links of the entry.
4575 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
4576 if (exists $t->{'size'}) {
4577 print "<td class=\"size\">$t->{'size'}</td>\n";
4579 if ($t->{'type'} eq "blob") {
4580 print "<td class=\"list\">" .
4581 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4582 file_name
=>"$basedir$t->{'name'}", %base_key),
4583 -class => "list"}, esc_path
($t->{'name'}));
4584 if (S_ISLNK
(oct $t->{'mode'})) {
4585 my $link_target = git_get_link_target
($t->{'hash'});
4587 my $norm_target = normalize_link_target
($link_target, $basedir);
4588 if (defined $norm_target) {
4590 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
4591 file_name
=>$norm_target),
4592 -title
=> $norm_target}, esc_path
($link_target));
4594 print " -> " . esc_path
($link_target);
4599 print "<td class=\"link\">";
4600 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4601 file_name
=>"$basedir$t->{'name'}", %base_key)},
4605 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4606 file_name
=>"$basedir$t->{'name'}", %base_key)},
4609 if (defined $hash_base) {
4611 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4612 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4616 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4617 file_name
=>"$basedir$t->{'name'}")},
4621 } elsif ($t->{'type'} eq "tree") {
4622 print "<td class=\"list\">";
4623 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4624 file_name
=>"$basedir$t->{'name'}",
4626 esc_path
($t->{'name'}));
4628 print "<td class=\"link\">";
4629 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4630 file_name
=>"$basedir$t->{'name'}",
4633 if (defined $hash_base) {
4635 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4636 file_name
=>"$basedir$t->{'name'}")},
4641 # unknown object: we can only present history for it
4642 # (this includes 'commit' object, i.e. submodule support)
4643 print "<td class=\"list\">" .
4644 esc_path
($t->{'name'}) .
4646 print "<td class=\"link\">";
4647 if (defined $hash_base) {
4648 print $cgi->a({-href
=> href
(action
=>"history",
4649 hash_base
=>$hash_base,
4650 file_name
=>"$basedir$t->{'name'}")},
4657 ## ......................................................................
4658 ## functions printing large fragments of HTML
4660 # get pre-image filenames for merge (combined) diff
4661 sub fill_from_file_info
{
4662 my ($diff, @parents) = @_;
4664 $diff->{'from_file'} = [ ];
4665 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4666 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4667 if ($diff->{'status'}[$i] eq 'R' ||
4668 $diff->{'status'}[$i] eq 'C') {
4669 $diff->{'from_file'}[$i] =
4670 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4677 # is current raw difftree line of file deletion
4679 my $diffinfo = shift;
4681 return $diffinfo->{'to_id'} eq ('0' x
40);
4684 # does patch correspond to [previous] difftree raw line
4685 # $diffinfo - hashref of parsed raw diff format
4686 # $patchinfo - hashref of parsed patch diff format
4687 # (the same keys as in $diffinfo)
4688 sub is_patch_split
{
4689 my ($diffinfo, $patchinfo) = @_;
4691 return defined $diffinfo && defined $patchinfo
4692 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4696 sub git_difftree_body
{
4697 my ($difftree, $hash, @parents) = @_;
4698 my ($parent) = $parents[0];
4699 my $have_blame = gitweb_check_feature
('blame');
4700 print "<div class=\"list_head\">\n";
4701 if ($#{$difftree} > 10) {
4702 print(($#{$difftree} + 1) . " files changed:\n");
4706 print "<table class=\"" .
4707 (@parents > 1 ? "combined " : "") .
4710 # header only for combined diff in 'commitdiff' view
4711 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
4714 print "<thead><tr>\n" .
4715 "<th></th><th></th>\n"; # filename, patchN link
4716 for (my $i = 0; $i < @parents; $i++) {
4717 my $par = $parents[$i];
4719 $cgi->a({-href
=> href
(action
=>"commitdiff",
4720 hash
=>$hash, hash_parent
=>$par),
4721 -title
=> 'commitdiff to parent number ' .
4722 ($i+1) . ': ' . substr($par,0,7)},
4726 print "</tr></thead>\n<tbody>\n";
4731 foreach my $line (@{$difftree}) {
4732 my $diff = parsed_difftree_line
($line);
4735 print "<tr class=\"dark\">\n";
4737 print "<tr class=\"light\">\n";
4741 if (exists $diff->{'nparents'}) { # combined diff
4743 fill_from_file_info
($diff, @parents)
4744 unless exists $diff->{'from_file'};
4746 if (!is_deleted
($diff)) {
4747 # file exists in the result (child) commit
4749 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4750 file_name
=>$diff->{'to_file'},
4752 -class => "list"}, esc_path
($diff->{'to_file'})) .
4756 esc_path
($diff->{'to_file'}) .
4760 if ($action eq 'commitdiff') {
4763 print "<td class=\"link\">" .
4764 $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4770 my $has_history = 0;
4771 my $not_deleted = 0;
4772 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4773 my $hash_parent = $parents[$i];
4774 my $from_hash = $diff->{'from_id'}[$i];
4775 my $from_path = $diff->{'from_file'}[$i];
4776 my $status = $diff->{'status'}[$i];
4778 $has_history ||= ($status ne 'A');
4779 $not_deleted ||= ($status ne 'D');
4781 if ($status eq 'A') {
4782 print "<td class=\"link\" align=\"right\"> | </td>\n";
4783 } elsif ($status eq 'D') {
4784 print "<td class=\"link\">" .
4785 $cgi->a({-href
=> href
(action
=>"blob",
4788 file_name
=>$from_path)},
4792 if ($diff->{'to_id'} eq $from_hash) {
4793 print "<td class=\"link nochange\">";
4795 print "<td class=\"link\">";
4797 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4798 hash
=>$diff->{'to_id'},
4799 hash_parent
=>$from_hash,
4801 hash_parent_base
=>$hash_parent,
4802 file_name
=>$diff->{'to_file'},
4803 file_parent
=>$from_path)},
4809 print "<td class=\"link\">";
4811 print $cgi->a({-href
=> href
(action
=>"blob",
4812 hash
=>$diff->{'to_id'},
4813 file_name
=>$diff->{'to_file'},
4816 print " | " if ($has_history);
4819 print $cgi->a({-href
=> href
(action
=>"history",
4820 file_name
=>$diff->{'to_file'},
4827 next; # instead of 'else' clause, to avoid extra indent
4829 # else ordinary diff
4831 my ($to_mode_oct, $to_mode_str, $to_file_type);
4832 my ($from_mode_oct, $from_mode_str, $from_file_type);
4833 if ($diff->{'to_mode'} ne ('0' x
6)) {
4834 $to_mode_oct = oct $diff->{'to_mode'};
4835 if (S_ISREG
($to_mode_oct)) { # only for regular file
4836 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4838 $to_file_type = file_type
($diff->{'to_mode'});
4840 if ($diff->{'from_mode'} ne ('0' x
6)) {
4841 $from_mode_oct = oct $diff->{'from_mode'};
4842 if (S_ISREG
($from_mode_oct)) { # only for regular file
4843 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4845 $from_file_type = file_type
($diff->{'from_mode'});
4848 if ($diff->{'status'} eq "A") { # created
4849 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4850 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4851 $mode_chng .= "]</span>";
4853 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4854 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4855 -class => "list"}, esc_path
($diff->{'file'}));
4857 print "<td>$mode_chng</td>\n";
4858 print "<td class=\"link\">";
4859 if ($action eq 'commitdiff') {
4862 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4866 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4867 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4871 } elsif ($diff->{'status'} eq "D") { # deleted
4872 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4874 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4875 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4876 -class => "list"}, esc_path
($diff->{'file'}));
4878 print "<td>$mode_chng</td>\n";
4879 print "<td class=\"link\">";
4880 if ($action eq 'commitdiff') {
4883 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4887 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4888 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4891 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4892 file_name
=>$diff->{'file'})},
4895 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4896 file_name
=>$diff->{'file'})},
4900 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4901 my $mode_chnge = "";
4902 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4903 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4904 if ($from_file_type ne $to_file_type) {
4905 $mode_chnge .= " from $from_file_type to $to_file_type";
4907 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4908 if ($from_mode_str && $to_mode_str) {
4909 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4910 } elsif ($to_mode_str) {
4911 $mode_chnge .= " mode: $to_mode_str";
4914 $mode_chnge .= "]</span>\n";
4917 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4918 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4919 -class => "list"}, esc_path
($diff->{'file'}));
4921 print "<td>$mode_chnge</td>\n";
4922 print "<td class=\"link\">";
4923 if ($action eq 'commitdiff') {
4926 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4929 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4930 # "commit" view and modified file (not onlu mode changed)
4931 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4932 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4933 hash_base
=>$hash, hash_parent_base
=>$parent,
4934 file_name
=>$diff->{'file'})},
4938 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4939 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4942 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4943 file_name
=>$diff->{'file'})},
4946 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4947 file_name
=>$diff->{'file'})},
4951 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4952 my %status_name = ('R' => 'moved', 'C' => 'copied');
4953 my $nstatus = $status_name{$diff->{'status'}};
4955 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4956 # mode also for directories, so we cannot use $to_mode_str
4957 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4960 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4961 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4962 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4963 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4964 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4965 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4966 -class => "list"}, esc_path
($diff->{'from_file'})) .
4967 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4968 "<td class=\"link\">";
4969 if ($action eq 'commitdiff') {
4972 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4975 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4976 # "commit" view and modified file (not only pure rename or copy)
4977 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4978 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4979 hash_base
=>$hash, hash_parent_base
=>$parent,
4980 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4984 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4985 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4988 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4989 file_name
=>$diff->{'to_file'})},
4992 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4993 file_name
=>$diff->{'to_file'})},
4997 } # we should not encounter Unmerged (U) or Unknown (X) status
5000 print "</tbody>" if $has_header;
5004 sub print_sidebyside_diff_chunk
{
5006 my (@ctx, @rem, @add);
5008 return unless @chunk;
5010 # incomplete last line might be among removed or added lines,
5011 # or both, or among context lines: find which
5012 for (my $i = 1; $i < @chunk; $i++) {
5013 if ($chunk[$i][0] eq 'incomplete') {
5014 $chunk[$i][0] = $chunk[$i-1][0];
5019 push @chunk, ["", ""];
5021 foreach my $line_info (@chunk) {
5022 my ($class, $line) = @$line_info;
5024 # print chunk headers
5025 if ($class && $class eq 'chunk_header') {
5030 ## print from accumulator when type of class of lines change
5031 # empty contents block on start rem/add block, or end of chunk
5032 if (@ctx && (!$class || $class eq 'rem' || $class eq 'add')) {
5034 '<div class="chunk_block ctx">',
5035 '<div class="old">',
5038 '<div class="new">',
5044 # empty add/rem block on start context block, or end of chunk
5045 if ((@rem || @add) && (!$class || $class eq 'ctx')) {
5049 '<div class="chunk_block rem">',
5050 '<div class="old">',
5057 '<div class="chunk_block add">',
5058 '<div class="new">',
5063 # assume that it is change
5065 '<div class="chunk_block chg">',
5066 '<div class="old">',
5069 '<div class="new">',
5077 ## adding lines to accumulator
5080 # rem, add or change
5081 if ($class eq 'rem') {
5083 } elsif ($class eq 'add') {
5087 if ($class eq 'ctx') {
5093 sub git_patchset_body
{
5094 my ($fd, $diff_style, $difftree, $hash, @hash_parents) = @_;
5095 my ($hash_parent) = $hash_parents[0];
5097 my $is_combined = (@hash_parents > 1);
5099 my $patch_number = 0;
5104 my @chunk; # for side-by-side diff
5106 print "<div class=\"patchset\">\n";
5108 # skip to first patch
5109 while ($patch_line = <$fd>) {
5112 last if ($patch_line =~ m/^diff /);
5116 while ($patch_line) {
5118 # parse "git diff" header line
5119 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
5120 # $1 is from_name, which we do not use
5121 $to_name = unquote
($2);
5122 $to_name =~ s!^b/!!;
5123 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
5124 # $1 is 'cc' or 'combined', which we do not use
5125 $to_name = unquote
($2);
5130 # check if current patch belong to current raw line
5131 # and parse raw git-diff line if needed
5132 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
5133 # this is continuation of a split patch
5134 print "<div class=\"patch cont\">\n";
5136 # advance raw git-diff output if needed
5137 $patch_idx++ if defined $diffinfo;
5139 # read and prepare patch information
5140 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
5142 # compact combined diff output can have some patches skipped
5143 # find which patch (using pathname of result) we are at now;
5145 while ($to_name ne $diffinfo->{'to_file'}) {
5146 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
5147 format_diff_cc_simplified
($diffinfo, @hash_parents) .
5148 "</div>\n"; # class="patch"
5153 last if $patch_idx > $#$difftree;
5154 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
5158 # modifies %from, %to hashes
5159 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
5161 # this is first patch for raw difftree line with $patch_idx index
5162 # we index @$difftree array from 0, but number patches from 1
5163 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
5167 #assert($patch_line =~ m/^diff /) if DEBUG;
5168 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
5170 # print "git diff" header
5171 print format_git_diff_header_line
($patch_line, $diffinfo,
5174 # print extended diff header
5175 print "<div class=\"diff extended_header\">\n";
5177 while ($patch_line = <$fd>) {
5180 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
5182 print format_extended_diff_header_line
($patch_line, $diffinfo,
5185 print "</div>\n"; # class="diff extended_header"
5187 # from-file/to-file diff header
5188 if (! $patch_line) {
5189 print "</div>\n"; # class="patch"
5192 next PATCH
if ($patch_line =~ m/^diff /);
5193 #assert($patch_line =~ m/^---/) if DEBUG;
5195 my $last_patch_line = $patch_line;
5196 $patch_line = <$fd>;
5198 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
5200 print format_diff_from_to_header
($last_patch_line, $patch_line,
5201 $diffinfo, \
%from, \
%to,
5206 while ($patch_line = <$fd>) {
5209 next PATCH
if ($patch_line =~ m/^diff /);
5211 my ($class, $line) = process_diff_line
($patch_line, \
%from, \
%to);
5212 my $diff_classes = "diff";
5213 $diff_classes .= " $class" if ($class);
5214 $line = "<div class=\"$diff_classes\">$line</div>\n";
5216 if ($diff_style eq 'sidebyside' && !$is_combined) {
5217 if ($class eq 'chunk_header') {
5218 print_sidebyside_diff_chunk
(@chunk);
5219 @chunk = ( [ $class, $line ] );
5221 push @chunk, [ $class, $line ];
5224 # default 'inline' style and unknown styles
5231 print_sidebyside_diff_chunk
(@chunk);
5234 print "</div>\n"; # class="patch"
5237 # for compact combined (--cc) format, with chunk and patch simplification
5238 # the patchset might be empty, but there might be unprocessed raw lines
5239 for (++$patch_idx if $patch_number > 0;
5240 $patch_idx < @$difftree;
5242 # read and prepare patch information
5243 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
5245 # generate anchor for "patch" links in difftree / whatchanged part
5246 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
5247 format_diff_cc_simplified
($diffinfo, @hash_parents) .
5248 "</div>\n"; # class="patch"
5253 if ($patch_number == 0) {
5254 if (@hash_parents > 1) {
5255 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
5257 print "<div class=\"diff nodifferences\">No differences found</div>\n";
5261 print "</div>\n"; # class="patchset"
5264 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5266 sub git_project_search_form
{
5267 my ($searchtext, $search_use_regexp) = @_;
5270 if ($project_filter) {
5271 $limit = " in '$project_filter/'";
5274 print "<div class=\"projsearch\">\n";
5275 print $cgi->startform(-method => 'get', -action
=> $my_uri) .
5276 $cgi->hidden(-name
=> 'a', -value
=> 'project_list') . "\n";
5277 print $cgi->hidden(-name
=> 'pf', -value
=> $project_filter). "\n"
5278 if (defined $project_filter);
5279 print $cgi->textfield(-name
=> 's', -value
=> $searchtext,
5280 -title
=> "Search project by name and description$limit",
5281 -size
=> 60) . "\n" .
5282 "<span title=\"Extended regular expression\">" .
5283 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
5284 -checked
=> $search_use_regexp) .
5286 $cgi->submit(-name
=> 'btnS', -value
=> 'Search') .
5287 $cgi->end_form() . "\n" .
5288 $cgi->a({-href
=> href
(project
=> undef, searchtext
=> undef,
5289 project_filter
=> $project_filter)},
5290 esc_html
("List all projects$limit")) . "<br />\n";
5294 # entry for given @keys needs filling if at least one of keys in list
5295 # is not present in %$project_info
5296 sub project_info_needs_filling
{
5297 my ($project_info, @keys) = @_;
5299 # return List::MoreUtils::any { !exists $project_info->{$_} } @keys;
5300 foreach my $key (@keys) {
5301 if (!exists $project_info->{$key}) {
5308 # fills project list info (age, description, owner, category, forks, etc.)
5309 # for each project in the list, removing invalid projects from
5310 # returned list, or fill only specified info.
5312 # Invalid projects are removed from the returned list if and only if you
5313 # ask 'age' or 'age_string' to be filled, because they are the only fields
5314 # that run unconditionally git command that requires repository, and
5315 # therefore do always check if project repository is invalid.
5318 # * fill_project_list_info(\@project_list, 'descr_long', 'ctags')
5319 # ensures that 'descr_long' and 'ctags' fields are filled
5320 # * @project_list = fill_project_list_info(\@project_list)
5321 # ensures that all fields are filled (and invalid projects removed)
5323 # NOTE: modifies $projlist, but does not remove entries from it
5324 sub fill_project_list_info
{
5325 my ($projlist, @wanted_keys) = @_;
5327 my $filter_set = sub { return @_; };
5329 my %wanted_keys = map { $_ => 1 } @wanted_keys;
5330 $filter_set = sub { return grep { $wanted_keys{$_} } @_; };
5333 my $show_ctags = gitweb_check_feature
('ctags');
5335 foreach my $pr (@$projlist) {
5336 if (project_info_needs_filling
($pr, $filter_set->('age', 'age_string'))) {
5337 my (@activity) = git_get_last_activity
($pr->{'path'});
5338 unless (@activity) {
5341 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
5343 if (project_info_needs_filling
($pr, $filter_set->('descr', 'descr_long'))) {
5344 my $descr = git_get_project_description
($pr->{'path'}) || "";
5345 $descr = to_utf8
($descr);
5346 $pr->{'descr_long'} = $descr;
5347 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
5349 if (project_info_needs_filling
($pr, $filter_set->('owner'))) {
5350 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
5353 project_info_needs_filling
($pr, $filter_set->('ctags'))) {
5354 $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
5356 if ($projects_list_group_categories &&
5357 project_info_needs_filling
($pr, $filter_set->('category'))) {
5358 my $cat = git_get_project_category
($pr->{'path'}) ||
5359 $project_list_default_category;
5360 $pr->{'category'} = to_utf8
($cat);
5363 push @projects, $pr;
5369 sub sort_projects_list
{
5370 my ($projlist, $order) = @_;
5374 project
=> { key
=> 'path', type
=> 'str' },
5375 descr
=> { key
=> 'descr_long', type
=> 'str' },
5376 owner
=> { key
=> 'owner', type
=> 'str' },
5377 age
=> { key
=> 'age', type
=> 'num' }
5379 my $oi = $order_info{$order};
5380 return @$projlist unless defined $oi;
5381 if ($oi->{'type'} eq 'str') {
5382 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projlist;
5384 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projlist;
5390 # returns a hash of categories, containing the list of project
5391 # belonging to each category
5392 sub build_projlist_by_category
{
5393 my ($projlist, $from, $to) = @_;
5396 $from = 0 unless defined $from;
5397 $to = $#$projlist if (!defined $to || $#$projlist < $to);
5399 for (my $i = $from; $i <= $to; $i++) {
5400 my $pr = $projlist->[$i];
5401 push @{$categories{ $pr->{'category'} }}, $pr;
5404 return wantarray ? %categories : \
%categories;
5407 # print 'sort by' <th> element, generating 'sort by $name' replay link
5408 # if that order is not selected
5410 print format_sort_th
(@_);
5413 sub format_sort_th
{
5414 my ($name, $order, $header) = @_;
5416 $header ||= ucfirst($name);
5418 if ($order eq $name) {
5419 $sort_th .= "<th>$header</th>\n";
5421 $sort_th .= "<th>" .
5422 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
5423 -class => "header"}, $header) .
5430 sub git_project_list_rows
{
5431 my ($projlist, $from, $to, $check_forks) = @_;
5433 $from = 0 unless defined $from;
5434 $to = $#$projlist if (!defined $to || $#$projlist < $to);
5437 for (my $i = $from; $i <= $to; $i++) {
5438 my $pr = $projlist->[$i];
5441 print "<tr class=\"dark\">\n";
5443 print "<tr class=\"light\">\n";
5449 if ($pr->{'forks'}) {
5450 my $nforks = scalar @{$pr->{'forks'}};
5452 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks"),
5453 -title
=> "$nforks forks"}, "+");
5455 print $cgi->span({-title
=> "$nforks forks"}, "+");
5460 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
5462 esc_html_match_hl
($pr->{'path'}, $search_regexp)) .
5464 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
5466 -title
=> $pr->{'descr_long'}},
5468 ? esc_html_match_hl_chopped
($pr->{'descr_long'},
5469 $pr->{'descr'}, $search_regexp)
5470 : esc_html
($pr->{'descr'})) .
5472 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
5473 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
5474 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
5475 "<td class=\"link\">" .
5476 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
5477 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
5478 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
5479 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
5480 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
5486 sub git_project_list_body
{
5487 # actually uses global variable $project
5488 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
5489 my @projects = @$projlist;
5491 my $check_forks = gitweb_check_feature
('forks');
5492 my $show_ctags = gitweb_check_feature
('ctags');
5493 my $tagfilter = $show_ctags ? $input_params{'ctag'} : undef;
5494 $check_forks = undef
5495 if ($tagfilter || $search_regexp);
5497 # filtering out forks before filling info allows to do less work
5498 @projects = filter_forks_from_projects_list
(\
@projects)
5500 # search_projects_list pre-fills required info
5501 @projects = search_projects_list
(\
@projects,
5502 'search_regexp' => $search_regexp,
5503 'tagfilter' => $tagfilter)
5504 if ($tagfilter || $search_regexp);
5506 @projects = fill_project_list_info
(\
@projects);
5508 $order ||= $default_projects_order;
5509 $from = 0 unless defined $from;
5510 $to = $#projects if (!defined $to || $#projects < $to);
5515 "<b>No such projects found</b><br />\n".
5516 "Click ".$cgi->a({-href
=>href
(project
=>undef)},"here")." to view all projects<br />\n".
5517 "</center>\n<br />\n";
5521 @projects = sort_projects_list
(\
@projects, $order);
5524 my $ctags = git_gather_all_ctags
(\
@projects);
5525 my $cloud = git_populate_project_tagcloud
($ctags);
5526 print git_show_project_tagcloud
($cloud, 64);
5529 print "<table class=\"project_list\">\n";
5530 unless ($no_header) {
5533 print "<th></th>\n";
5535 print_sort_th
('project', $order, 'Project');
5536 print_sort_th
('descr', $order, 'Description');
5537 print_sort_th
('owner', $order, 'Owner');
5538 print_sort_th
('age', $order, 'Last Change');
5539 print "<th></th>\n" . # for links
5543 if ($projects_list_group_categories) {
5544 # only display categories with projects in the $from-$to window
5545 @projects = sort {$a->{'category'} cmp $b->{'category'}} @projects[$from..$to];
5546 my %categories = build_projlist_by_category
(\
@projects, $from, $to);
5547 foreach my $cat (sort keys %categories) {
5548 unless ($cat eq "") {
5551 print "<td></td>\n";
5553 print "<td class=\"category\" colspan=\"5\">".esc_html
($cat)."</td>\n";
5557 git_project_list_rows
($categories{$cat}, undef, undef, $check_forks);
5560 git_project_list_rows
(\
@projects, $from, $to, $check_forks);
5563 if (defined $extra) {
5566 print "<td></td>\n";
5568 print "<td colspan=\"5\">$extra</td>\n" .
5575 # uses global variable $project
5576 my ($commitlist, $from, $to, $refs, $extra) = @_;
5578 $from = 0 unless defined $from;
5579 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5581 for (my $i = 0; $i <= $to; $i++) {
5582 my %co = %{$commitlist->[$i]};
5584 my $commit = $co{'id'};
5585 my $ref = format_ref_marker
($refs, $commit);
5586 git_print_header_div
('commit',
5587 "<span class=\"age\">$co{'age_string'}</span>" .
5588 esc_html
($co{'title'}) . $ref,
5590 print "<div class=\"title_text\">\n" .
5591 "<div class=\"log_link\">\n" .
5592 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5594 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5596 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5599 git_print_authorship
(\
%co, -tag
=> 'span');
5600 print "<br/>\n</div>\n";
5602 print "<div class=\"log_body\">\n";
5603 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5607 print "<div class=\"page_nav\">\n";
5613 sub git_shortlog_body
{
5614 # uses global variable $project
5615 my ($commitlist, $from, $to, $refs, $extra) = @_;
5617 $from = 0 unless defined $from;
5618 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5620 print "<table class=\"shortlog\">\n";
5622 for (my $i = $from; $i <= $to; $i++) {
5623 my %co = %{$commitlist->[$i]};
5624 my $commit = $co{'id'};
5625 my $ref = format_ref_marker
($refs, $commit);
5627 print "<tr class=\"dark\">\n";
5629 print "<tr class=\"light\">\n";
5632 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
5633 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5634 format_author_html
('td', \
%co, 10) . "<td>";
5635 print format_subject_html
($co{'title'}, $co{'title_short'},
5636 href
(action
=>"commit", hash
=>$commit), $ref);
5638 "<td class=\"link\">" .
5639 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
5640 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
5641 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
5642 my $snapshot_links = format_snapshot_links
($commit);
5643 if (defined $snapshot_links) {
5644 print " | " . $snapshot_links;
5649 if (defined $extra) {
5651 "<td colspan=\"4\">$extra</td>\n" .
5657 sub git_history_body
{
5658 # Warning: assumes constant type (blob or tree) during history
5659 my ($commitlist, $from, $to, $refs, $extra,
5660 $file_name, $file_hash, $ftype) = @_;
5662 $from = 0 unless defined $from;
5663 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
5665 print "<table class=\"history\">\n";
5667 for (my $i = $from; $i <= $to; $i++) {
5668 my %co = %{$commitlist->[$i]};
5672 my $commit = $co{'id'};
5674 my $ref = format_ref_marker
($refs, $commit);
5677 print "<tr class=\"dark\">\n";
5679 print "<tr class=\"light\">\n";
5682 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5683 # shortlog: format_author_html('td', \%co, 10)
5684 format_author_html
('td', \
%co, 15, 3) . "<td>";
5685 # originally git_history used chop_str($co{'title'}, 50)
5686 print format_subject_html
($co{'title'}, $co{'title_short'},
5687 href
(action
=>"commit", hash
=>$commit), $ref);
5689 "<td class=\"link\">" .
5690 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
5691 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
5693 if ($ftype eq 'blob') {
5694 my $blob_current = $file_hash;
5695 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
5696 if (defined $blob_current && defined $blob_parent &&
5697 $blob_current ne $blob_parent) {
5699 $cgi->a({-href
=> href
(action
=>"blobdiff",
5700 hash
=>$blob_current, hash_parent
=>$blob_parent,
5701 hash_base
=>$hash_base, hash_parent_base
=>$commit,
5702 file_name
=>$file_name)},
5709 if (defined $extra) {
5711 "<td colspan=\"4\">$extra</td>\n" .
5718 # uses global variable $project
5719 my ($taglist, $from, $to, $extra) = @_;
5720 $from = 0 unless defined $from;
5721 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
5723 print "<table class=\"tags\">\n";
5725 for (my $i = $from; $i <= $to; $i++) {
5726 my $entry = $taglist->[$i];
5728 my $comment = $tag{'subject'};
5730 if (defined $comment) {
5731 $comment_short = chop_str
($comment, 30, 5);
5734 print "<tr class=\"dark\">\n";
5736 print "<tr class=\"light\">\n";
5739 if (defined $tag{'age'}) {
5740 print "<td><i>$tag{'age'}</i></td>\n";
5742 print "<td></td>\n";
5745 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
5746 -class => "list name"}, esc_html
($tag{'name'})) .
5749 if (defined $comment) {
5750 print format_subject_html
($comment, $comment_short,
5751 href
(action
=>"tag", hash
=>$tag{'id'}));
5754 "<td class=\"selflink\">";
5755 if ($tag{'type'} eq "tag") {
5756 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
5761 "<td class=\"link\">" . " | " .
5762 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
5763 if ($tag{'reftype'} eq "commit") {
5764 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
5765 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
5766 } elsif ($tag{'reftype'} eq "blob") {
5767 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
5772 if (defined $extra) {
5774 "<td colspan=\"5\">$extra</td>\n" .
5780 sub git_heads_body
{
5781 # uses global variable $project
5782 my ($headlist, $head_at, $from, $to, $extra) = @_;
5783 $from = 0 unless defined $from;
5784 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
5786 print "<table class=\"heads\">\n";
5788 for (my $i = $from; $i <= $to; $i++) {
5789 my $entry = $headlist->[$i];
5791 my $curr = defined $head_at && $ref{'id'} eq $head_at;
5793 print "<tr class=\"dark\">\n";
5795 print "<tr class=\"light\">\n";
5798 print "<td><i>$ref{'age'}</i></td>\n" .
5799 ($curr ? "<td class=\"current_head\">" : "<td>") .
5800 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
5801 -class => "list name"},esc_html
($ref{'name'})) .
5803 "<td class=\"link\">" .
5804 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
5805 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
5806 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'fullname'})}, "tree") .
5810 if (defined $extra) {
5812 "<td colspan=\"3\">$extra</td>\n" .
5818 # Display a single remote block
5819 sub git_remote_block
{
5820 my ($remote, $rdata, $limit, $head) = @_;
5822 my $heads = $rdata->{'heads'};
5823 my $fetch = $rdata->{'fetch'};
5824 my $push = $rdata->{'push'};
5826 my $urls_table = "<table class=\"projects_list\">\n" ;
5828 if (defined $fetch) {
5829 if ($fetch eq $push) {
5830 $urls_table .= format_repo_url
("URL", $fetch);
5832 $urls_table .= format_repo_url
("Fetch URL", $fetch);
5833 $urls_table .= format_repo_url
("Push URL", $push) if defined $push;
5835 } elsif (defined $push) {
5836 $urls_table .= format_repo_url
("Push URL", $push);
5838 $urls_table .= format_repo_url
("", "No remote URL");
5841 $urls_table .= "</table>\n";
5844 if (defined $limit && $limit < @$heads) {
5845 $dots = $cgi->a({-href
=> href
(action
=>"remotes", hash
=>$remote)}, "...");
5849 git_heads_body
($heads, $head, 0, $limit, $dots);
5852 # Display a list of remote names with the respective fetch and push URLs
5853 sub git_remotes_list
{
5854 my ($remotedata, $limit) = @_;
5855 print "<table class=\"heads\">\n";
5857 my @remotes = sort keys %$remotedata;
5859 my $limited = $limit && $limit < @remotes;
5861 $#remotes = $limit - 1 if $limited;
5863 while (my $remote = shift @remotes) {
5864 my $rdata = $remotedata->{$remote};
5865 my $fetch = $rdata->{'fetch'};
5866 my $push = $rdata->{'push'};
5868 print "<tr class=\"dark\">\n";
5870 print "<tr class=\"light\">\n";
5874 $cgi->a({-href
=> href
(action
=>'remotes', hash
=>$remote),
5875 -class=> "list name"},esc_html
($remote)) .
5877 print "<td class=\"link\">" .
5878 (defined $fetch ? $cgi->a({-href
=> $fetch}, "fetch") : "fetch") .
5880 (defined $push ? $cgi->a({-href
=> $push}, "push") : "push") .
5888 "<td colspan=\"3\">" .
5889 $cgi->a({-href
=> href
(action
=>"remotes")}, "...") .
5890 "</td>\n" . "</tr>\n";
5896 # Display remote heads grouped by remote, unless there are too many
5897 # remotes, in which case we only display the remote names
5898 sub git_remotes_body
{
5899 my ($remotedata, $limit, $head) = @_;
5900 if ($limit and $limit < keys %$remotedata) {
5901 git_remotes_list
($remotedata, $limit);
5903 fill_remote_heads
($remotedata);
5904 while (my ($remote, $rdata) = each %$remotedata) {
5905 git_print_section
({-class=>"remote", -id
=>$remote},
5906 ["remotes", $remote, $remote], sub {
5907 git_remote_block
($remote, $rdata, $limit, $head);
5913 sub git_search_message
{
5917 if ($searchtype eq 'commit') {
5918 $greptype = "--grep=";
5919 } elsif ($searchtype eq 'author') {
5920 $greptype = "--author=";
5921 } elsif ($searchtype eq 'committer') {
5922 $greptype = "--committer=";
5924 $greptype .= $searchtext;
5925 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5926 $greptype, '--regexp-ignore-case',
5927 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5929 my $paging_nav = '';
5932 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)},
5935 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5936 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5938 $paging_nav .= "first ⋅ prev";
5941 if ($#commitlist >= 100) {
5943 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5944 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5945 $paging_nav .= " ⋅ $next_link";
5947 $paging_nav .= " ⋅ next";
5952 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5953 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5954 if ($page == 0 && !@commitlist) {
5955 print "<p>No match.</p>\n";
5957 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5963 sub git_search_changes
{
5967 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5968 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5969 ($search_use_regexp ? '--pickaxe-regex' : ())
5970 or die_error
(500, "Open git-log failed");
5974 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5975 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5977 print "<table class=\"pickaxe search\">\n";
5981 while (my $line = <$fd>) {
5985 my %set = parse_difftree_raw_line
($line);
5986 if (defined $set{'commit'}) {
5987 # finish previous commit
5990 "<td class=\"link\">" .
5991 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})},
5994 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'},
5995 hash_base
=>$co{'id'})},
6002 print "<tr class=\"dark\">\n";
6004 print "<tr class=\"light\">\n";
6007 %co = parse_commit
($set{'commit'});
6008 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6009 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6010 "<td><i>$author</i></td>\n" .
6012 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6013 -class => "list subject"},
6014 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6015 } elsif (defined $set{'to_id'}) {
6016 next if ($set{'to_id'} =~ m/^0{40}$/);
6018 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6019 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6021 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6027 # finish last commit (warning: repetition!)
6030 "<td class=\"link\">" .
6031 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})},
6034 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'},
6035 hash_base
=>$co{'id'})},
6046 sub git_search_files
{
6050 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-z',
6051 $search_use_regexp ? ('-E', '-i') : '-F',
6052 $searchtext, $co{'tree'}
6053 or die_error
(500, "Open git-grep failed");
6057 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6058 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6060 print "<table class=\"grep_search\">\n";
6065 while (my $line = <$fd>) {
6067 my ($file, $lno, $ltext, $binary);
6068 last if ($matches++ > 1000);
6069 if ($line =~ /^Binary file (.+) matches$/) {
6073 ($file, $lno, $ltext) = split(/\0/, $line, 3);
6074 $file =~ s/^$co{'tree'}://;
6076 if ($file ne $lastfile) {
6077 $lastfile and print "</td></tr>\n";
6079 print "<tr class=\"dark\">\n";
6081 print "<tr class=\"light\">\n";
6083 $file_href = href
(action
=>"blob", hash_base
=>$co{'id'},
6085 print "<td class=\"list\">".
6086 $cgi->a({-href
=> $file_href, -class => "list"}, esc_path
($file));
6087 print "</td><td>\n";
6091 print "<div class=\"binary\">Binary file</div>\n";
6093 $ltext = untabify
($ltext);
6094 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6095 $ltext = esc_html
($1, -nbsp
=>1);
6096 $ltext .= '<span class="match">';
6097 $ltext .= esc_html
($2, -nbsp
=>1);
6098 $ltext .= '</span>';
6099 $ltext .= esc_html
($3, -nbsp
=>1);
6101 $ltext = esc_html
($ltext, -nbsp
=>1);
6103 print "<div class=\"pre\">" .
6104 $cgi->a({-href
=> $file_href.'#l'.$lno,
6105 -class => "linenr"}, sprintf('%4i', $lno)) .
6106 ' ' . $ltext . "</div>\n";
6110 print "</td></tr>\n";
6111 if ($matches > 1000) {
6112 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6115 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6124 sub git_search_grep_body
{
6125 my ($commitlist, $from, $to, $extra) = @_;
6126 $from = 0 unless defined $from;
6127 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
6129 print "<table class=\"commit_search\">\n";
6131 for (my $i = $from; $i <= $to; $i++) {
6132 my %co = %{$commitlist->[$i]};
6136 my $commit = $co{'id'};
6138 print "<tr class=\"dark\">\n";
6140 print "<tr class=\"light\">\n";
6143 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6144 format_author_html
('td', \
%co, 15, 5) .
6146 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6147 -class => "list subject"},
6148 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6149 my $comment = $co{'comment'};
6150 foreach my $line (@$comment) {
6151 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
6152 my ($lead, $match, $trail) = ($1, $2, $3);
6153 $match = chop_str
($match, 70, 5, 'center');
6154 my $contextlen = int((80 - length($match))/2);
6155 $contextlen = 30 if ($contextlen > 30);
6156 $lead = chop_str
($lead, $contextlen, 10, 'left');
6157 $trail = chop_str
($trail, $contextlen, 10, 'right');
6159 $lead = esc_html
($lead);
6160 $match = esc_html
($match);
6161 $trail = esc_html
($trail);
6163 print "$lead<span class=\"match\">$match</span>$trail<br />";
6167 "<td class=\"link\">" .
6168 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6170 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
6172 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6176 if (defined $extra) {
6178 "<td colspan=\"3\">$extra</td>\n" .
6184 ## ======================================================================
6185 ## ======================================================================
6188 sub git_project_list
{
6189 my $order = $input_params{'order'};
6190 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
6191 die_error
(400, "Unknown order parameter");
6194 my @list = git_get_projects_list
($project_filter, $strict_export);
6196 die_error
(404, "No projects found");
6200 if (defined $home_text && -f
$home_text) {
6201 print "<div class=\"index_include\">\n";
6202 insert_file
($home_text);
6206 git_project_search_form
($searchtext, $search_use_regexp);
6207 git_project_list_body
(\
@list, $order);
6212 my $order = $input_params{'order'};
6213 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
6214 die_error
(400, "Unknown order parameter");
6217 my $filter = $project;
6218 $filter =~ s/\.git$//;
6219 my @list = git_get_projects_list
($filter);
6221 die_error
(404, "No forks found");
6225 git_print_page_nav
('','');
6226 git_print_header_div
('summary', "$project forks");
6227 git_project_list_body
(\
@list, $order);
6231 sub git_project_index
{
6232 my @projects = git_get_projects_list
($project_filter, $strict_export);
6234 die_error
(404, "No projects found");
6238 -type
=> 'text/plain',
6239 -charset
=> 'utf-8',
6240 -content_disposition
=> 'inline; filename="index.aux"');
6242 foreach my $pr (@projects) {
6243 if (!exists $pr->{'owner'}) {
6244 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
6247 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
6248 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
6249 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
6250 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
6254 print "$path $owner\n";
6259 my $descr = git_get_project_description
($project) || "none";
6260 my %co = parse_commit
("HEAD");
6261 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
6262 my $head = $co{'id'};
6263 my $remote_heads = gitweb_check_feature
('remote_heads');
6265 my $owner = git_get_project_owner
($project);
6267 my $refs = git_get_references
();
6268 # These get_*_list functions return one more to allow us to see if
6269 # there are more ...
6270 my @taglist = git_get_tags_list
(16);
6271 my @headlist = git_get_heads_list
(16);
6272 my %remotedata = $remote_heads ? git_get_remotes_list
() : ();
6274 my $check_forks = gitweb_check_feature
('forks');
6277 # find forks of a project
6278 my $filter = $project;
6279 $filter =~ s/\.git$//;
6280 @forklist = git_get_projects_list
($filter);
6281 # filter out forks of forks
6282 @forklist = filter_forks_from_projects_list
(\
@forklist)
6287 git_print_page_nav
('summary','', $head);
6289 print "<div class=\"title\"> </div>\n";
6290 print "<table class=\"projects_list\">\n" .
6291 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
6292 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
6293 if (defined $cd{'rfc2822'}) {
6294 print "<tr id=\"metadata_lchange\"><td>last change</td>" .
6295 "<td>".format_timestamp_html
(\
%cd)."</td></tr>\n";
6298 # use per project git URL list in $projectroot/$project/cloneurl
6299 # or make project git URL from git base URL and project name
6300 my $url_tag = "URL";
6301 my @url_list = git_get_project_url_list
($project);
6302 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
6303 foreach my $git_url (@url_list) {
6304 next unless $git_url;
6305 print format_repo_url
($url_tag, $git_url);
6310 my $show_ctags = gitweb_check_feature
('ctags');
6312 my $ctags = git_get_project_ctags
($project);
6314 # without ability to add tags, don't show if there are none
6315 my $cloud = git_populate_project_tagcloud
($ctags);
6316 print "<tr id=\"metadata_ctags\">" .
6317 "<td>content tags</td>" .
6318 "<td>".git_show_project_tagcloud
($cloud, 48)."</td>" .
6325 # If XSS prevention is on, we don't include README.html.
6326 # TODO: Allow a readme in some safe format.
6327 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
6328 print "<div class=\"title\">readme</div>\n" .
6329 "<div class=\"readme\">\n";
6330 insert_file
("$projectroot/$project/README.html");
6331 print "\n</div>\n"; # class="readme"
6334 # we need to request one more than 16 (0..15) to check if
6336 my @commitlist = $head ? parse_commits
($head, 17) : ();
6338 git_print_header_div
('shortlog');
6339 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
6340 $#commitlist <= 15 ? undef :
6341 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
6345 git_print_header_div
('tags');
6346 git_tags_body
(\
@taglist, 0, 15,
6347 $#taglist <= 15 ? undef :
6348 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
6352 git_print_header_div
('heads');
6353 git_heads_body
(\
@headlist, $head, 0, 15,
6354 $#headlist <= 15 ? undef :
6355 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
6359 git_print_header_div
('remotes');
6360 git_remotes_body
(\
%remotedata, 15, $head);
6364 git_print_header_div
('forks');
6365 git_project_list_body
(\
@forklist, 'age', 0, 15,
6366 $#forklist <= 15 ? undef :
6367 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
6375 my %tag = parse_tag
($hash);
6378 die_error
(404, "Unknown tag object");
6381 my $head = git_get_head_hash
($project);
6383 git_print_page_nav
('','', $head,undef,$head);
6384 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
6385 print "<div class=\"title_text\">\n" .
6386 "<table class=\"object_header\">\n" .
6388 "<td>object</td>\n" .
6389 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
6390 $tag{'object'}) . "</td>\n" .
6391 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
6392 $tag{'type'}) . "</td>\n" .
6394 if (defined($tag{'author'})) {
6395 git_print_authorship_rows
(\
%tag, 'author');
6397 print "</table>\n\n" .
6399 print "<div class=\"page_body\">";
6400 my $comment = $tag{'comment'};
6401 foreach my $line (@$comment) {
6403 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
6409 sub git_blame_common
{
6410 my $format = shift || 'porcelain';
6411 if ($format eq 'porcelain' && $input_params{'javascript'}) {
6412 $format = 'incremental';
6413 $action = 'blame_incremental'; # for page title etc
6417 gitweb_check_feature
('blame')
6418 or die_error
(403, "Blame view not allowed");
6421 die_error
(400, "No file name given") unless $file_name;
6422 $hash_base ||= git_get_head_hash
($project);
6423 die_error
(404, "Couldn't find base commit") unless $hash_base;
6424 my %co = parse_commit
($hash_base)
6425 or die_error
(404, "Commit not found");
6427 if (!defined $hash) {
6428 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
6429 or die_error
(404, "Error looking up file");
6431 $ftype = git_get_type
($hash);
6432 if ($ftype !~ "blob") {
6433 die_error
(400, "Object is not a blob");
6438 if ($format eq 'incremental') {
6439 # get file contents (as base)
6440 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
6441 or die_error
(500, "Open git-cat-file failed");
6442 } elsif ($format eq 'data') {
6443 # run git-blame --incremental
6444 open $fd, "-|", git_cmd
(), "blame", "--incremental",
6445 $hash_base, "--", $file_name
6446 or die_error
(500, "Open git-blame --incremental failed");
6448 # run git-blame --porcelain
6449 open $fd, "-|", git_cmd
(), "blame", '-p',
6450 $hash_base, '--', $file_name
6451 or die_error
(500, "Open git-blame --porcelain failed");
6454 # incremental blame data returns early
6455 if ($format eq 'data') {
6457 -type
=>"text/plain", -charset
=> "utf-8",
6458 -status
=> "200 OK");
6459 local $| = 1; # output autoflush
6460 while (my $line = <$fd>) {
6461 print to_utf8
($line);
6464 or print "ERROR $!\n";
6467 if (defined $t0 && gitweb_check_feature
('timed')) {
6469 tv_interval
($t0, [ gettimeofday
() ]).
6470 ' '.$number_of_git_cmds;
6480 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
6483 if ($format eq 'incremental') {
6485 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
6486 "blame") . " (non-incremental)";
6489 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
6490 "blame") . " (incremental)";
6494 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
6497 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
6499 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6500 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6501 git_print_page_path
($file_name, $ftype, $hash_base);
6504 if ($format eq 'incremental') {
6505 print "<noscript>\n<div class=\"error\"><center><b>\n".
6506 "This page requires JavaScript to run.\n Use ".
6507 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
6510 "</b></center></div>\n</noscript>\n";
6512 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
6515 print qq
!<div
class="page_body">\n!;
6516 print qq
!<div id
="progress_info">... / ...</div
>\n!
6517 if ($format eq 'incremental');
6518 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
6519 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
6521 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
6525 my @rev_color = qw(light dark);
6526 my $num_colors = scalar(@rev_color);
6527 my $current_color = 0;
6529 if ($format eq 'incremental') {
6530 my $color_class = $rev_color[$current_color];
6535 while (my $line = <$fd>) {
6539 print qq
!<tr id
="l$linenr" class="$color_class">!.
6540 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
6541 qq
!<td
class="linenr">!.
6542 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
6543 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
6547 } else { # porcelain, i.e. ordinary blame
6548 my %metainfo = (); # saves information about commits
6552 while (my $line = <$fd>) {
6554 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
6555 # no <lines in group> for subsequent lines in group of lines
6556 my ($full_rev, $orig_lineno, $lineno, $group_size) =
6557 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
6558 if (!exists $metainfo{$full_rev}) {
6559 $metainfo{$full_rev} = { 'nprevious' => 0 };
6561 my $meta = $metainfo{$full_rev};
6563 while ($data = <$fd>) {
6565 last if ($data =~ s/^\t//); # contents of line
6566 if ($data =~ /^(\S+)(?: (.*))?$/) {
6567 $meta->{$1} = $2 unless exists $meta->{$1};
6569 if ($data =~ /^previous /) {
6570 $meta->{'nprevious'}++;
6573 my $short_rev = substr($full_rev, 0, 8);
6574 my $author = $meta->{'author'};
6576 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
6577 my $date = $date{'iso-tz'};
6579 $current_color = ($current_color + 1) % $num_colors;
6581 my $tr_class = $rev_color[$current_color];
6582 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
6583 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
6584 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
6585 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
6587 print "<td class=\"sha1\"";
6588 print " title=\"". esc_html
($author) . ", $date\"";
6589 print " rowspan=\"$group_size\"" if ($group_size > 1);
6591 print $cgi->a({-href
=> href
(action
=>"commit",
6593 file_name
=>$file_name)},
6594 esc_html
($short_rev));
6595 if ($group_size >= 2) {
6596 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
6597 if (@author_initials) {
6599 esc_html
(join('', @author_initials));
6605 # 'previous' <sha1 of parent commit> <filename at commit>
6606 if (exists $meta->{'previous'} &&
6607 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
6608 $meta->{'parent'} = $1;
6609 $meta->{'file_parent'} = unquote
($2);
6612 exists($meta->{'parent'}) ?
6613 $meta->{'parent'} : $full_rev;
6614 my $linenr_filename =
6615 exists($meta->{'file_parent'}) ?
6616 $meta->{'file_parent'} : unquote
($meta->{'filename'});
6617 my $blamed = href
(action
=> 'blame',
6618 file_name
=> $linenr_filename,
6619 hash_base
=> $linenr_commit);
6620 print "<td class=\"linenr\">";
6621 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
6622 -class => "linenr" },
6625 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
6633 "</table>\n"; # class="blame"
6634 print "</div>\n"; # class="blame_body"
6636 or print "Reading blob failed\n";
6645 sub git_blame_incremental
{
6646 git_blame_common
('incremental');
6649 sub git_blame_data
{
6650 git_blame_common
('data');
6654 my $head = git_get_head_hash
($project);
6656 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('tags'));
6657 git_print_header_div
('summary', $project);
6659 my @tagslist = git_get_tags_list
();
6661 git_tags_body
(\
@tagslist);
6667 my $head = git_get_head_hash
($project);
6669 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('heads'));
6670 git_print_header_div
('summary', $project);
6672 my @headslist = git_get_heads_list
();
6674 git_heads_body
(\
@headslist, $head);
6679 # used both for single remote view and for list of all the remotes
6681 gitweb_check_feature
('remote_heads')
6682 or die_error
(403, "Remote heads view is disabled");
6684 my $head = git_get_head_hash
($project);
6685 my $remote = $input_params{'hash'};
6687 my $remotedata = git_get_remotes_list
($remote);
6688 die_error
(500, "Unable to get remote information") unless defined $remotedata;
6690 unless (%$remotedata) {
6691 die_error
(404, defined $remote ?
6692 "Remote $remote not found" :
6693 "No remotes found");
6696 git_header_html
(undef, undef, -action_extra
=> $remote);
6697 git_print_page_nav
('', '', $head, undef, $head,
6698 format_ref_views
($remote ? '' : 'remotes'));
6700 fill_remote_heads
($remotedata);
6701 if (defined $remote) {
6702 git_print_header_div
('remotes', "$remote remote for $project");
6703 git_remote_block
($remote, $remotedata->{$remote}, undef, $head);
6705 git_print_header_div
('summary', "$project remotes");
6706 git_remotes_body
($remotedata, undef, $head);
6712 sub git_blob_plain
{
6716 if (!defined $hash) {
6717 if (defined $file_name) {
6718 my $base = $hash_base || git_get_head_hash
($project);
6719 $hash = git_get_hash_by_path
($base, $file_name, "blob")
6720 or die_error
(404, "Cannot find file");
6722 die_error
(400, "No file name defined");
6724 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6725 # blobs defined by non-textual hash id's can be cached
6729 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
6730 or die_error
(500, "Open git-cat-file blob '$hash' failed");
6732 # content-type (can include charset)
6733 $type = blob_contenttype
($fd, $file_name, $type);
6735 # "save as" filename, even when no $file_name is given
6736 my $save_as = "$hash";
6737 if (defined $file_name) {
6738 $save_as = $file_name;
6739 } elsif ($type =~ m/^text\//) {
6743 # With XSS prevention on, blobs of all types except a few known safe
6744 # ones are served with "Content-Disposition: attachment" to make sure
6745 # they don't run in our security domain. For certain image types,
6746 # blob view writes an <img> tag referring to blob_plain view, and we
6747 # want to be sure not to break that by serving the image as an
6748 # attachment (though Firefox 3 doesn't seem to care).
6749 my $sandbox = $prevent_xss &&
6750 $type !~ m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;
6752 # serve text/* as text/plain
6754 ($type =~ m!^text/[a-z]+\b(.*)$! ||
6755 ($type =~ m!^[a-z]+/[a-z]\+xml\b(.*)$! && -T
$fd))) {
6757 $rest = defined $rest ? $rest : '';
6758 $type = "text/plain$rest";
6763 -expires
=> $expires,
6764 -content_disposition
=>
6765 ($sandbox ? 'attachment' : 'inline')
6766 . '; filename="' . $save_as . '"');
6768 binmode STDOUT
, ':raw';
6770 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
6777 if (!defined $hash) {
6778 if (defined $file_name) {
6779 my $base = $hash_base || git_get_head_hash
($project);
6780 $hash = git_get_hash_by_path
($base, $file_name, "blob")
6781 or die_error
(404, "Cannot find file");
6783 die_error
(400, "No file name defined");
6785 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6786 # blobs defined by non-textual hash id's can be cached
6790 my $have_blame = gitweb_check_feature
('blame');
6791 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
6792 or die_error
(500, "Couldn't cat $file_name, $hash");
6793 my $mimetype = blob_mimetype
($fd, $file_name);
6794 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
6795 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
6797 return git_blob_plain
($mimetype);
6799 # we can have blame only for text/* mimetype
6800 $have_blame &&= ($mimetype =~ m!^text/!);
6802 my $highlight = gitweb_check_feature
('highlight');
6803 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
6804 $fd = run_highlighter
($fd, $highlight, $syntax)
6807 git_header_html
(undef, $expires);
6808 my $formats_nav = '';
6809 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6810 if (defined $file_name) {
6813 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
6818 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
6821 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
6824 $cgi->a({-href
=> href
(action
=>"blob",
6825 hash_base
=>"HEAD", file_name
=>$file_name)},
6829 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
6832 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6833 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6835 print "<div class=\"page_nav\">\n" .
6836 "<br/><br/></div>\n" .
6837 "<div class=\"title\">".esc_html
($hash)."</div>\n";
6839 git_print_page_path
($file_name, "blob", $hash_base);
6840 print "<div class=\"page_body\">\n";
6841 if ($mimetype =~ m!^image/!) {
6842 print qq
!<img type
="!.esc_attr($mimetype).qq!"!;
6844 print qq
! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
6847 href(action=>"blob_plain
", hash=>$hash,
6848 hash_base=>$hash_base, file_name=>$file_name) .
6852 while (my $line = <$fd>) {
6855 $line = untabify
($line);
6856 printf qq
!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
6857 $nr, esc_attr
(href
(-replay
=> 1)), $nr, $nr,
6858 $syntax ? sanitize
($line) : esc_html
($line, -nbsp
=>1);
6862 or print "Reading blob failed.\n";
6868 if (!defined $hash_base) {
6869 $hash_base = "HEAD";
6871 if (!defined $hash) {
6872 if (defined $file_name) {
6873 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
6878 die_error
(404, "No such tree") unless defined($hash);
6880 my $show_sizes = gitweb_check_feature
('show-sizes');
6881 my $have_blame = gitweb_check_feature
('blame');
6886 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
6887 ($show_sizes ? '-l' : ()), @extra_options, $hash
6888 or die_error
(500, "Open git-ls-tree failed");
6889 @entries = map { chomp; $_ } <$fd>;
6891 or die_error
(404, "Reading tree failed");
6894 my $refs = git_get_references
();
6895 my $ref = format_ref_marker
($refs, $hash_base);
6898 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6900 if (defined $file_name) {
6902 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
6904 $cgi->a({-href
=> href
(action
=>"tree",
6905 hash_base
=>"HEAD", file_name
=>$file_name)},
6908 my $snapshot_links = format_snapshot_links
($hash);
6909 if (defined $snapshot_links) {
6910 # FIXME: Should be available when we have no hash base as well.
6911 push @views_nav, $snapshot_links;
6913 git_print_page_nav
('tree','', $hash_base, undef, undef,
6914 join(' | ', @views_nav));
6915 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
6918 print "<div class=\"page_nav\">\n";
6919 print "<br/><br/></div>\n";
6920 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
6922 if (defined $file_name) {
6923 $basedir = $file_name;
6924 if ($basedir ne '' && substr($basedir, -1) ne '/') {
6927 git_print_page_path
($file_name, 'tree', $hash_base);
6929 print "<div class=\"page_body\">\n";
6930 print "<table class=\"tree\">\n";
6932 # '..' (top directory) link if possible
6933 if (defined $hash_base &&
6934 defined $file_name && $file_name =~ m![^/]+$!) {
6936 print "<tr class=\"dark\">\n";
6938 print "<tr class=\"light\">\n";
6942 my $up = $file_name;
6943 $up =~ s!/?[^/]+$!!;
6944 undef $up unless $up;
6945 # based on git_print_tree_entry
6946 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
6947 print '<td class="size"> </td>'."\n" if $show_sizes;
6948 print '<td class="list">';
6949 print $cgi->a({-href
=> href
(action
=>"tree",
6950 hash_base
=>$hash_base,
6954 print "<td class=\"link\"></td>\n";
6958 foreach my $line (@entries) {
6959 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
6962 print "<tr class=\"dark\">\n";
6964 print "<tr class=\"light\">\n";
6968 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
6972 print "</table>\n" .
6978 my ($project, $hash) = @_;
6980 # path/to/project.git -> project
6981 # path/to/project/.git -> project
6982 my $name = to_utf8
($project);
6983 $name =~ s
,([^/])/*\
.git
$,$1,;
6984 $name = basename
($name);
6986 $name =~ s/[[:cntrl:]]/?/g;
6989 if ($hash =~ /^[0-9a-fA-F]+$/) {
6990 # shorten SHA-1 hash
6991 my $full_hash = git_get_full_hash
($project, $hash);
6992 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
6993 $ver = git_get_short_hash
($project, $hash);
6995 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
6996 # tags don't need shortened SHA-1 hash
6999 # branches and other need shortened SHA-1 hash
7000 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
7003 $ver .= '-' . git_get_short_hash
($project, $hash);
7005 # in case of hierarchical branch names
7008 # name = project-version_string
7009 $name = "$name-$ver";
7011 return wantarray ? ($name, $name) : $name;
7014 sub exit_if_unmodified_since
{
7015 my ($latest_epoch) = @_;
7018 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
7019 if (defined $if_modified) {
7021 if (eval { require HTTP
::Date
; 1; }) {
7022 $since = HTTP
::Date
::str2time
($if_modified);
7023 } elsif (eval { require Time
::ParseDate
; 1; }) {
7024 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
7026 if (defined $since && $latest_epoch <= $since) {
7027 my %latest_date = parse_date
($latest_epoch);
7029 -last_modified
=> $latest_date{'rfc2822'},
7030 -status
=> '304 Not Modified');
7037 my $format = $input_params{'snapshot_format'};
7038 if (!@snapshot_fmts) {
7039 die_error
(403, "Snapshots not allowed");
7041 # default to first supported snapshot format
7042 $format ||= $snapshot_fmts[0];
7043 if ($format !~ m/^[a-z0-9]+$/) {
7044 die_error
(400, "Invalid snapshot format parameter");
7045 } elsif (!exists($known_snapshot_formats{$format})) {
7046 die_error
(400, "Unknown snapshot format");
7047 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
7048 die_error
(403, "Snapshot format not allowed");
7049 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
7050 die_error
(403, "Unsupported snapshot format");
7053 my $type = git_get_type
("$hash^{}");
7055 die_error
(404, 'Object does not exist');
7056 } elsif ($type eq 'blob') {
7057 die_error
(400, 'Object is not a tree-ish');
7060 my ($name, $prefix) = snapshot_name
($project, $hash);
7061 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
7063 my %co = parse_commit
($hash);
7064 exit_if_unmodified_since
($co{'committer_epoch'}) if %co;
7066 my $cmd = quote_command
(
7067 git_cmd
(), 'archive',
7068 "--format=$known_snapshot_formats{$format}{'format'}",
7069 "--prefix=$prefix/", $hash);
7070 if (exists $known_snapshot_formats{$format}{'compressor'}) {
7071 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
7074 $filename =~ s/(["\\])/\\$1/g;
7077 %latest_date = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
7081 -type
=> $known_snapshot_formats{$format}{'type'},
7082 -content_disposition
=> 'inline; filename="' . $filename . '"',
7083 %co ? (-last_modified
=> $latest_date{'rfc2822'}) : (),
7084 -status
=> '200 OK');
7086 open my $fd, "-|", $cmd
7087 or die_error
(500, "Execute git-archive failed");
7088 binmode STDOUT
, ':raw';
7090 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
7094 sub git_log_generic
{
7095 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
7097 my $head = git_get_head_hash
($project);
7098 if (!defined $base) {
7101 if (!defined $page) {
7104 my $refs = git_get_references
();
7106 my $commit_hash = $base;
7107 if (defined $parent) {
7108 $commit_hash = "$parent..$base";
7111 parse_commits
($commit_hash, 101, (100 * $page),
7112 defined $file_name ? ($file_name, "--full-history") : ());
7115 if (!defined $file_hash && defined $file_name) {
7116 # some commits could have deleted file in question,
7117 # and not have it in tree, but one of them has to have it
7118 for (my $i = 0; $i < @commitlist; $i++) {
7119 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
7120 last if defined $file_hash;
7123 if (defined $file_hash) {
7124 $ftype = git_get_type
($file_hash);
7126 if (defined $file_name && !defined $ftype) {
7127 die_error
(500, "Unknown type of object");
7130 if (defined $file_name) {
7131 %co = parse_commit
($base)
7132 or die_error
(404, "Unknown commit object");
7136 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
7138 if ($#commitlist >= 100) {
7140 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
7141 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
7143 my $patch_max = gitweb_get_feature
('patches');
7144 if ($patch_max && !defined $file_name) {
7145 if ($patch_max < 0 || @commitlist <= $patch_max) {
7146 $paging_nav .= " ⋅ " .
7147 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
7153 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
7154 if (defined $file_name) {
7155 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
7157 git_print_header_div
('summary', $project)
7159 git_print_page_path
($file_name, $ftype, $hash_base)
7160 if (defined $file_name);
7162 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
7163 $file_name, $file_hash, $ftype);
7169 git_log_generic
('log', \
&git_log_body
,
7170 $hash, $hash_parent);
7174 $hash ||= $hash_base || "HEAD";
7175 my %co = parse_commit
($hash)
7176 or die_error
(404, "Unknown commit object");
7178 my $parent = $co{'parent'};
7179 my $parents = $co{'parents'}; # listref
7181 # we need to prepare $formats_nav before any parameter munging
7183 if (!defined $parent) {
7185 $formats_nav .= '(initial)';
7186 } elsif (@$parents == 1) {
7187 # single parent commit
7190 $cgi->a({-href
=> href
(action
=>"commit",
7192 esc_html
(substr($parent, 0, 7))) .
7199 $cgi->a({-href
=> href
(action
=>"commit",
7201 esc_html
(substr($_, 0, 7)));
7205 if (gitweb_check_feature
('patches') && @$parents <= 1) {
7206 $formats_nav .= " | " .
7207 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
7211 if (!defined $parent) {
7215 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
7217 (@$parents <= 1 ? $parent : '-c'),
7219 or die_error
(500, "Open git-diff-tree failed");
7220 @difftree = map { chomp; $_ } <$fd>;
7221 close $fd or die_error
(404, "Reading git-diff-tree failed");
7223 # non-textual hash id's can be cached
7225 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
7228 my $refs = git_get_references
();
7229 my $ref = format_ref_marker
($refs, $co{'id'});
7231 git_header_html
(undef, $expires);
7232 git_print_page_nav
('commit', '',
7233 $hash, $co{'tree'}, $hash,
7236 if (defined $co{'parent'}) {
7237 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
7239 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
7241 print "<div class=\"title_text\">\n" .
7242 "<table class=\"object_header\">\n";
7243 git_print_authorship_rows
(\
%co);
7244 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
7247 "<td class=\"sha1\">" .
7248 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
7249 class => "list"}, $co{'tree'}) .
7251 "<td class=\"link\">" .
7252 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
7254 my $snapshot_links = format_snapshot_links
($hash);
7255 if (defined $snapshot_links) {
7256 print " | " . $snapshot_links;
7261 foreach my $par (@$parents) {
7264 "<td class=\"sha1\">" .
7265 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
7266 class => "list"}, $par) .
7268 "<td class=\"link\">" .
7269 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
7271 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
7278 print "<div class=\"page_body\">\n";
7279 git_print_log
($co{'comment'});
7282 git_difftree_body
(\
@difftree, $hash, @$parents);
7288 # object is defined by:
7289 # - hash or hash_base alone
7290 # - hash_base and file_name
7293 # - hash or hash_base alone
7294 if ($hash || ($hash_base && !defined $file_name)) {
7295 my $object_id = $hash || $hash_base;
7297 open my $fd, "-|", quote_command
(
7298 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
7299 or die_error
(404, "Object does not exist");
7303 or die_error
(404, "Object does not exist");
7305 # - hash_base and file_name
7306 } elsif ($hash_base && defined $file_name) {
7307 $file_name =~ s
,/+$,,;
7309 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
7310 or die_error
(404, "Base object does not exist");
7312 # here errors should not hapen
7313 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
7314 or die_error
(500, "Open git-ls-tree failed");
7318 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
7319 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
7320 die_error
(404, "File or directory for given base does not exist");
7325 die_error
(400, "Not enough information to find object");
7328 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
7329 hash
=>$hash, hash_base
=>$hash_base,
7330 file_name
=>$file_name),
7331 -status
=> '302 Found');
7335 my $format = shift || 'html';
7336 my $diff_style = $input_params{'diff_style'} || 'inline';
7343 # preparing $fd and %diffinfo for git_patchset_body
7345 if (defined $hash_base && defined $hash_parent_base) {
7346 if (defined $file_name) {
7348 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7349 $hash_parent_base, $hash_base,
7350 "--", (defined $file_parent ? $file_parent : ()), $file_name
7351 or die_error
(500, "Open git-diff-tree failed");
7352 @difftree = map { chomp; $_ } <$fd>;
7354 or die_error
(404, "Reading git-diff-tree failed");
7356 or die_error
(404, "Blob diff not found");
7358 } elsif (defined $hash &&
7359 $hash =~ /[0-9a-fA-F]{40}/) {
7360 # try to find filename from $hash
7362 # read filtered raw output
7363 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7364 $hash_parent_base, $hash_base, "--"
7365 or die_error
(500, "Open git-diff-tree failed");
7367 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
7369 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
7370 map { chomp; $_ } <$fd>;
7372 or die_error
(404, "Reading git-diff-tree failed");
7374 or die_error
(404, "Blob diff not found");
7377 die_error
(400, "Missing one of the blob diff parameters");
7380 if (@difftree > 1) {
7381 die_error
(400, "Ambiguous blob diff specification");
7384 %diffinfo = parse_difftree_raw_line
($difftree[0]);
7385 $file_parent ||= $diffinfo{'from_file'} || $file_name;
7386 $file_name ||= $diffinfo{'to_file'};
7388 $hash_parent ||= $diffinfo{'from_id'};
7389 $hash ||= $diffinfo{'to_id'};
7391 # non-textual hash id's can be cached
7392 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
7393 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
7398 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7399 '-p', ($format eq 'html' ? "--full-index" : ()),
7400 $hash_parent_base, $hash_base,
7401 "--", (defined $file_parent ? $file_parent : ()), $file_name
7402 or die_error
(500, "Open git-diff-tree failed");
7405 # old/legacy style URI -- not generated anymore since 1.4.3.
7407 die_error
('404 Not Found', "Missing one of the blob diff parameters")
7411 if ($format eq 'html') {
7413 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
7415 $formats_nav .= diff_style_nav
($diff_style);
7416 git_header_html
(undef, $expires);
7417 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
7418 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
7419 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
7421 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
7422 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
7424 if (defined $file_name) {
7425 git_print_page_path
($file_name, "blob", $hash_base);
7427 print "<div class=\"page_path\"></div>\n";
7430 } elsif ($format eq 'plain') {
7432 -type
=> 'text/plain',
7433 -charset
=> 'utf-8',
7434 -expires
=> $expires,
7435 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
7437 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
7440 die_error
(400, "Unknown blobdiff format");
7444 if ($format eq 'html') {
7445 print "<div class=\"page_body\">\n";
7447 git_patchset_body
($fd, $diff_style,
7448 [ \
%diffinfo ], $hash_base, $hash_parent_base);
7451 print "</div>\n"; # class="page_body"
7455 while (my $line = <$fd>) {
7456 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
7457 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
7461 last if $line =~ m!^\+\+\+!;
7469 sub git_blobdiff_plain
{
7470 git_blobdiff
('plain');
7473 # assumes that it is added as later part of already existing navigation,
7474 # so it returns "| foo | bar" rather than just "foo | bar"
7475 sub diff_style_nav
{
7476 my ($diff_style, $is_combined) = @_;
7477 $diff_style ||= 'inline';
7479 return "" if ($is_combined);
7481 my @styles = (inline
=> 'inline', 'sidebyside' => 'side by side');
7482 my %styles = @styles;
7484 @styles[ map { $_ * 2 } 0..$#styles/2 ];
7489 $_ eq $diff_style ? $styles{$_} :
7490 $cgi->a({-href
=> href
(-replay
=>1, diff_style
=> $_)}, $styles{$_})
7494 sub git_commitdiff
{
7496 my $format = $params{-format
} || 'html';
7497 my $diff_style = $input_params{'diff_style'} || 'inline';
7499 my ($patch_max) = gitweb_get_feature
('patches');
7500 if ($format eq 'patch') {
7501 die_error
(403, "Patch view not allowed") unless $patch_max;
7504 $hash ||= $hash_base || "HEAD";
7505 my %co = parse_commit
($hash)
7506 or die_error
(404, "Unknown commit object");
7508 # choose format for commitdiff for merge
7509 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
7510 $hash_parent = '--cc';
7512 # we need to prepare $formats_nav before almost any parameter munging
7514 if ($format eq 'html') {
7516 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
7518 if ($patch_max && @{$co{'parents'}} <= 1) {
7519 $formats_nav .= " | " .
7520 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
7523 $formats_nav .= diff_style_nav
($diff_style, @{$co{'parents'}} > 1);
7525 if (defined $hash_parent &&
7526 $hash_parent ne '-c' && $hash_parent ne '--cc') {
7527 # commitdiff with two commits given
7528 my $hash_parent_short = $hash_parent;
7529 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
7530 $hash_parent_short = substr($hash_parent, 0, 7);
7534 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
7535 if ($co{'parents'}[$i] eq $hash_parent) {
7536 $formats_nav .= ' parent ' . ($i+1);
7540 $formats_nav .= ': ' .
7541 $cgi->a({-href
=> href
(-replay
=>1,
7542 hash
=>$hash_parent, hash_base
=>undef)},
7543 esc_html
($hash_parent_short)) .
7545 } elsif (!$co{'parent'}) {
7547 $formats_nav .= ' (initial)';
7548 } elsif (scalar @{$co{'parents'}} == 1) {
7549 # single parent commit
7552 $cgi->a({-href
=> href
(-replay
=>1,
7553 hash
=>$co{'parent'}, hash_base
=>undef)},
7554 esc_html
(substr($co{'parent'}, 0, 7))) .
7558 if ($hash_parent eq '--cc') {
7559 $formats_nav .= ' | ' .
7560 $cgi->a({-href
=> href
(-replay
=>1,
7561 hash
=>$hash, hash_parent
=>'-c')},
7563 } else { # $hash_parent eq '-c'
7564 $formats_nav .= ' | ' .
7565 $cgi->a({-href
=> href
(-replay
=>1,
7566 hash
=>$hash, hash_parent
=>'--cc')},
7572 $cgi->a({-href
=> href
(-replay
=>1,
7573 hash
=>$_, hash_base
=>undef)},
7574 esc_html
(substr($_, 0, 7)));
7575 } @{$co{'parents'}} ) .
7580 my $hash_parent_param = $hash_parent;
7581 if (!defined $hash_parent_param) {
7582 # --cc for multiple parents, --root for parentless
7583 $hash_parent_param =
7584 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
7590 if ($format eq 'html') {
7591 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7592 "--no-commit-id", "--patch-with-raw", "--full-index",
7593 $hash_parent_param, $hash, "--"
7594 or die_error
(500, "Open git-diff-tree failed");
7596 while (my $line = <$fd>) {
7598 # empty line ends raw part of diff-tree output
7600 push @difftree, scalar parse_difftree_raw_line
($line);
7603 } elsif ($format eq 'plain') {
7604 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7605 '-p', $hash_parent_param, $hash, "--"
7606 or die_error
(500, "Open git-diff-tree failed");
7607 } elsif ($format eq 'patch') {
7608 # For commit ranges, we limit the output to the number of
7609 # patches specified in the 'patches' feature.
7610 # For single commits, we limit the output to a single patch,
7611 # diverging from the git-format-patch default.
7612 my @commit_spec = ();
7614 if ($patch_max > 0) {
7615 push @commit_spec, "-$patch_max";
7617 push @commit_spec, '-n', "$hash_parent..$hash";
7619 if ($params{-single
}) {
7620 push @commit_spec, '-1';
7622 if ($patch_max > 0) {
7623 push @commit_spec, "-$patch_max";
7625 push @commit_spec, "-n";
7627 push @commit_spec, '--root', $hash;
7629 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
7630 '--encoding=utf8', '--stdout', @commit_spec
7631 or die_error
(500, "Open git-format-patch failed");
7633 die_error
(400, "Unknown commitdiff format");
7636 # non-textual hash id's can be cached
7638 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
7642 # write commit message
7643 if ($format eq 'html') {
7644 my $refs = git_get_references
();
7645 my $ref = format_ref_marker
($refs, $co{'id'});
7647 git_header_html
(undef, $expires);
7648 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
7649 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
7650 print "<div class=\"title_text\">\n" .
7651 "<table class=\"object_header\">\n";
7652 git_print_authorship_rows
(\
%co);
7655 print "<div class=\"page_body\">\n";
7656 if (@{$co{'comment'}} > 1) {
7657 print "<div class=\"log\">\n";
7658 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
7659 print "</div>\n"; # class="log"
7662 } elsif ($format eq 'plain') {
7663 my $refs = git_get_references
("tags");
7664 my $tagname = git_get_rev_name_tags
($hash);
7665 my $filename = basename
($project) . "-$hash.patch";
7668 -type
=> 'text/plain',
7669 -charset
=> 'utf-8',
7670 -expires
=> $expires,
7671 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
7672 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
7673 print "From: " . to_utf8
($co{'author'}) . "\n";
7674 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
7675 print "Subject: " . to_utf8
($co{'title'}) . "\n";
7677 print "X-Git-Tag: $tagname\n" if $tagname;
7678 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
7680 foreach my $line (@{$co{'comment'}}) {
7681 print to_utf8
($line) . "\n";
7684 } elsif ($format eq 'patch') {
7685 my $filename = basename
($project) . "-$hash.patch";
7688 -type
=> 'text/plain',
7689 -charset
=> 'utf-8',
7690 -expires
=> $expires,
7691 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
7695 if ($format eq 'html') {
7696 my $use_parents = !defined $hash_parent ||
7697 $hash_parent eq '-c' || $hash_parent eq '--cc';
7698 git_difftree_body
(\
@difftree, $hash,
7699 $use_parents ? @{$co{'parents'}} : $hash_parent);
7702 git_patchset_body
($fd, $diff_style,
7704 $use_parents ? @{$co{'parents'}} : $hash_parent);
7706 print "</div>\n"; # class="page_body"
7709 } elsif ($format eq 'plain') {
7713 or print "Reading git-diff-tree failed\n";
7714 } elsif ($format eq 'patch') {
7718 or print "Reading git-format-patch failed\n";
7722 sub git_commitdiff_plain
{
7723 git_commitdiff
(-format
=> 'plain');
7726 # format-patch-style patches
7728 git_commitdiff
(-format
=> 'patch', -single
=> 1);
7732 git_commitdiff
(-format
=> 'patch');
7736 git_log_generic
('history', \
&git_history_body
,
7737 $hash_base, $hash_parent_base,
7742 $searchtype ||= 'commit';
7744 # check if appropriate features are enabled
7745 gitweb_check_feature
('search')
7746 or die_error
(403, "Search is disabled");
7747 if ($searchtype eq 'pickaxe') {
7748 # pickaxe may take all resources of your box and run for several minutes
7749 # with every query - so decide by yourself how public you make this feature
7750 gitweb_check_feature
('pickaxe')
7751 or die_error
(403, "Pickaxe search is disabled");
7753 if ($searchtype eq 'grep') {
7754 # grep search might be potentially CPU-intensive, too
7755 gitweb_check_feature
('grep')
7756 or die_error
(403, "Grep search is disabled");
7759 if (!defined $searchtext) {
7760 die_error
(400, "Text field is empty");
7762 if (!defined $hash) {
7763 $hash = git_get_head_hash
($project);
7765 my %co = parse_commit
($hash);
7767 die_error
(404, "Unknown commit object");
7769 if (!defined $page) {
7773 if ($searchtype eq 'commit' ||
7774 $searchtype eq 'author' ||
7775 $searchtype eq 'committer') {
7776 git_search_message
(%co);
7777 } elsif ($searchtype eq 'pickaxe') {
7778 git_search_changes
(%co);
7779 } elsif ($searchtype eq 'grep') {
7780 git_search_files
(%co);
7782 die_error
(400, "Unknown search type");
7786 sub git_search_help
{
7788 git_print_page_nav
('','', $hash,$hash,$hash);
7790 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
7791 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
7792 the pattern entered is recognized as the POSIX extended
7793 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
7796 <dt><b>commit</b></dt>
7797 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
7799 my $have_grep = gitweb_check_feature
('grep');
7802 <dt><b>grep</b></dt>
7803 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
7804 a different one) are searched for the given pattern. On large trees, this search can take
7805 a while and put some strain on the server, so please use it with some consideration. Note that
7806 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
7807 case-sensitive.</dd>
7811 <dt><b>author</b></dt>
7812 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
7813 <dt><b>committer</b></dt>
7814 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
7816 my $have_pickaxe = gitweb_check_feature
('pickaxe');
7817 if ($have_pickaxe) {
7819 <dt><b>pickaxe</b></dt>
7820 <dd>All commits that caused the string to appear or disappear from any file (changes that
7821 added, removed or "modified" the string) will be listed. This search can take a while and
7822 takes a lot of strain on the server, so please use it wisely. Note that since you may be
7823 interested even in changes just changing the case as well, this search is case sensitive.</dd>
7831 git_log_generic
('shortlog', \
&git_shortlog_body
,
7832 $hash, $hash_parent);
7835 ## ......................................................................
7836 ## feeds (RSS, Atom; OPML)
7839 my $format = shift || 'atom';
7840 my $have_blame = gitweb_check_feature
('blame');
7842 # Atom: http://www.atomenabled.org/developers/syndication/
7843 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
7844 if ($format ne 'rss' && $format ne 'atom') {
7845 die_error
(400, "Unknown web feed format");
7848 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
7849 my $head = $hash || 'HEAD';
7850 my @commitlist = parse_commits
($head, 150, 0, $file_name);
7854 my $content_type = "application/$format+xml";
7855 if (defined $cgi->http('HTTP_ACCEPT') &&
7856 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
7857 # browser (feed reader) prefers text/xml
7858 $content_type = 'text/xml';
7860 if (defined($commitlist[0])) {
7861 %latest_commit = %{$commitlist[0]};
7862 my $latest_epoch = $latest_commit{'committer_epoch'};
7863 exit_if_unmodified_since
($latest_epoch);
7864 %latest_date = parse_date
($latest_epoch, $latest_commit{'comitter_tz'});
7867 -type
=> $content_type,
7868 -charset
=> 'utf-8',
7869 %latest_date ? (-last_modified
=> $latest_date{'rfc2822'}) : (),
7870 -status
=> '200 OK');
7872 # Optimization: skip generating the body if client asks only
7873 # for Last-Modified date.
7874 return if ($cgi->request_method() eq 'HEAD');
7877 my $title = "$site_name - $project/$action";
7878 my $feed_type = 'log';
7879 if (defined $hash) {
7880 $title .= " - '$hash'";
7881 $feed_type = 'branch log';
7882 if (defined $file_name) {
7883 $title .= " :: $file_name";
7884 $feed_type = 'history';
7886 } elsif (defined $file_name) {
7887 $title .= " - $file_name";
7888 $feed_type = 'history';
7890 $title .= " $feed_type";
7891 my $descr = git_get_project_description
($project);
7892 if (defined $descr) {
7893 $descr = esc_html
($descr);
7895 $descr = "$project " .
7896 ($format eq 'rss' ? 'RSS' : 'Atom') .
7899 my $owner = git_get_project_owner
($project);
7900 $owner = esc_html
($owner);
7904 if (defined $file_name) {
7905 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
7906 } elsif (defined $hash) {
7907 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
7909 $alt_url = href
(-full
=>1, action
=>"summary");
7911 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
7912 if ($format eq 'rss') {
7914 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
7917 print "<title>$title</title>\n" .
7918 "<link>$alt_url</link>\n" .
7919 "<description>$descr</description>\n" .
7920 "<language>en</language>\n" .
7921 # project owner is responsible for 'editorial' content
7922 "<managingEditor>$owner</managingEditor>\n";
7923 if (defined $logo || defined $favicon) {
7924 # prefer the logo to the favicon, since RSS
7925 # doesn't allow both
7926 my $img = esc_url
($logo || $favicon);
7928 "<url>$img</url>\n" .
7929 "<title>$title</title>\n" .
7930 "<link>$alt_url</link>\n" .
7934 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
7935 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
7937 print "<generator>gitweb v.$version/$git_version</generator>\n";
7938 } elsif ($format eq 'atom') {
7940 <feed xmlns="http://www.w3.org/2005/Atom">
7942 print "<title>$title</title>\n" .
7943 "<subtitle>$descr</subtitle>\n" .
7944 '<link rel="alternate" type="text/html" href="' .
7945 $alt_url . '" />' . "\n" .
7946 '<link rel="self" type="' . $content_type . '" href="' .
7947 $cgi->self_url() . '" />' . "\n" .
7948 "<id>" . href
(-full
=>1) . "</id>\n" .
7949 # use project owner for feed author
7950 "<author><name>$owner</name></author>\n";
7951 if (defined $favicon) {
7952 print "<icon>" . esc_url
($favicon) . "</icon>\n";
7954 if (defined $logo) {
7955 # not twice as wide as tall: 72 x 27 pixels
7956 print "<logo>" . esc_url
($logo) . "</logo>\n";
7958 if (! %latest_date) {
7959 # dummy date to keep the feed valid until commits trickle in:
7960 print "<updated>1970-01-01T00:00:00Z</updated>\n";
7962 print "<updated>$latest_date{'iso-8601'}</updated>\n";
7964 print "<generator version='$version/$git_version'>gitweb</generator>\n";
7968 for (my $i = 0; $i <= $#commitlist; $i++) {
7969 my %co = %{$commitlist[$i]};
7970 my $commit = $co{'id'};
7971 # we read 150, we always show 30 and the ones more recent than 48 hours
7972 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
7975 my %cd = parse_date
($co{'author_epoch'}, $co{'author_tz'});
7977 # get list of changed files
7978 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7979 $co{'parent'} || "--root",
7980 $co{'id'}, "--", (defined $file_name ? $file_name : ())
7982 my @difftree = map { chomp; $_ } <$fd>;
7986 # print element (entry, item)
7987 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
7988 if ($format eq 'rss') {
7990 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
7991 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
7992 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
7993 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
7994 "<link>$co_url</link>\n" .
7995 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
7996 "<content:encoded>" .
7998 } elsif ($format eq 'atom') {
8000 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
8001 "<updated>$cd{'iso-8601'}</updated>\n" .
8003 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
8004 if ($co{'author_email'}) {
8005 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
8007 print "</author>\n" .
8008 # use committer for contributor
8010 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
8011 if ($co{'committer_email'}) {
8012 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
8014 print "</contributor>\n" .
8015 "<published>$cd{'iso-8601'}</published>\n" .
8016 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
8017 "<id>$co_url</id>\n" .
8018 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
8019 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
8021 my $comment = $co{'comment'};
8023 foreach my $line (@$comment) {
8024 $line = esc_html
($line);
8027 print "</pre><ul>\n";
8028 foreach my $difftree_line (@difftree) {
8029 my %difftree = parse_difftree_raw_line
($difftree_line);
8030 next if !$difftree{'from_id'};
8032 my $file = $difftree{'file'} || $difftree{'to_file'};
8036 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
8037 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
8038 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
8039 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
8040 -title
=> "diff"}, 'D');
8042 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
8043 file_name
=>$file, hash_base
=>$commit),
8044 -title
=> "blame"}, 'B');
8046 # if this is not a feed of a file history
8047 if (!defined $file_name || $file_name ne $file) {
8048 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
8049 file_name
=>$file, hash
=>$commit),
8050 -title
=> "history"}, 'H');
8052 $file = esc_path
($file);
8056 if ($format eq 'rss') {
8057 print "</ul>]]>\n" .
8058 "</content:encoded>\n" .
8060 } elsif ($format eq 'atom') {
8061 print "</ul>\n</div>\n" .
8068 if ($format eq 'rss') {
8069 print "</channel>\n</rss>\n";
8070 } elsif ($format eq 'atom') {
8084 my @list = git_get_projects_list
($project_filter, $strict_export);
8086 die_error
(404, "No projects found");
8090 -type
=> 'text/xml',
8091 -charset
=> 'utf-8',
8092 -content_disposition
=> 'inline; filename="opml.xml"');
8094 my $title = esc_html
($site_name);
8095 my $filter = " within subdirectory ";
8096 if (defined $project_filter) {
8097 $filter .= esc_html
($project_filter);
8102 <?xml version="1.0" encoding="utf-8"?>
8103 <opml version="1.0">
8105 <title>$title OPML Export$filter</title>
8108 <outline text="git RSS feeds">
8111 foreach my $pr (@list) {
8113 my $head = git_get_head_hash
($proj{'path'});
8114 if (!defined $head) {
8117 $git_dir = "$projectroot/$proj{'path'}";
8118 my %co = parse_commit
($head);
8123 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
8124 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
8125 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
8126 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";