3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
13 use CGI
qw(:standard :escapeHTML -nosticky);
14 use CGI
::Util
qw(unescape);
15 use CGI
::Carp
qw(fatalsToBrowser set_message);
19 use File
::Basename
qw(basename);
20 use Time
::HiRes
qw(gettimeofday tv_interval);
21 binmode STDOUT
, ':utf8';
23 our $t0 = [ gettimeofday
() ];
24 our $number_of_git_cmds = 0;
27 CGI-
>compile() if $ENV{'MOD_PERL'};
30 our $version = "++GIT_VERSION++";
32 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
36 our $my_url = $cgi->url();
37 our $my_uri = $cgi->url(-absolute
=> 1);
39 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
40 # needed and used only for URLs with nonempty PATH_INFO
41 our $base_url = $my_url;
43 # When the script is used as DirectoryIndex, the URL does not contain the name
44 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
45 # have to do it ourselves. We make $path_info global because it's also used
48 # Another issue with the script being the DirectoryIndex is that the resulting
49 # $my_url data is not the full script URL: this is good, because we want
50 # generated links to keep implying the script name if it wasn't explicitly
51 # indicated in the URL we're handling, but it means that $my_url cannot be used
53 # Therefore, if we needed to strip PATH_INFO, then we know that we have
54 # to build the base URL ourselves:
55 our $path_info = $ENV{"PATH_INFO"};
57 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
58 $my_uri =~ s
,\Q
$path_info\E
$,, &&
59 defined $ENV{'SCRIPT_NAME'}) {
60 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
64 # target of the home link on top of all pages
65 our $home_link = $my_uri || "/";
68 # core git executable to use
69 # this can just be "git" if your webserver has a sensible PATH
70 our $GIT = "++GIT_BINDIR++/git";
72 # absolute fs-path which will be prepended to the project path
73 #our $projectroot = "/pub/scm";
74 our $projectroot = "++GITWEB_PROJECTROOT++";
76 # fs traversing limit for getting project list
77 # the number is relative to the projectroot
78 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
80 # string of the home link on top of all pages
81 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
83 # name of your site or organization to appear in page titles
84 # replace this with something more descriptive for clearer bookmarks
85 our $site_name = "++GITWEB_SITENAME++"
86 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
88 # filename of html text to include at top of each page
89 our $site_header = "++GITWEB_SITE_HEADER++";
90 # html text to include at home page
91 our $home_text = "++GITWEB_HOMETEXT++";
92 # filename of html text to include at bottom of each page
93 our $site_footer = "++GITWEB_SITE_FOOTER++";
96 our @stylesheets = ("++GITWEB_CSS++");
97 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
98 our $stylesheet = undef;
100 # URI of GIT logo (72x27 size)
101 our $logo = "++GITWEB_LOGO++";
102 # URI of GIT favicon, assumed to be image/png type
103 our $favicon = "++GITWEB_FAVICON++";
104 # URI of gitweb.js (JavaScript code for gitweb)
105 our $javascript = "++GITWEB_JS++";
107 # URI and label (title) of GIT logo link
108 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
109 #our $logo_label = "git documentation";
110 our $logo_url = "http://git-scm.com/";
111 our $logo_label = "git homepage";
113 # source of projects list
114 our $projects_list = "++GITWEB_LIST++";
116 # the width (in characters) of the projects list "Description" column
117 our $projects_list_description_width = 25;
119 # group projects by category on the projects list
120 # (enabled if this variable evaluates to true)
121 our $projects_list_group_categories = 0;
123 # default category if none specified
124 # (leave the empty string for no category)
125 our $project_list_default_category = "";
127 # default order of projects list
128 # valid values are none, project, descr, owner, and age
129 our $default_projects_order = "project";
131 # show repository only if this file exists
132 # (only effective if this variable evaluates to true)
133 our $export_ok = "++GITWEB_EXPORT_OK++";
135 # show repository only if this subroutine returns true
136 # when given the path to the project, for example:
137 # sub { return -e "$_[0]/git-daemon-export-ok"; }
138 our $export_auth_hook = undef;
140 # only allow viewing of repositories also shown on the overview page
141 our $strict_export = "++GITWEB_STRICT_EXPORT++";
143 # list of git base URLs used for URL to where fetch project from,
144 # i.e. full URL is "$git_base_url/$project"
145 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
147 # default blob_plain mimetype and default charset for text/plain blob
148 our $default_blob_plain_mimetype = 'text/plain';
149 our $default_text_plain_charset = undef;
151 # file to use for guessing MIME types before trying /etc/mime.types
152 # (relative to the current git repository)
153 our $mimetypes_file = undef;
155 # assume this charset if line contains non-UTF-8 characters;
156 # it should be valid encoding (see Encoding::Supported(3pm) for list),
157 # for which encoding all byte sequences are valid, for example
158 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
159 # could be even 'utf-8' for the old behavior)
160 our $fallback_encoding = 'latin1';
162 # rename detection options for git-diff and git-diff-tree
163 # - default is '-M', with the cost proportional to
164 # (number of removed files) * (number of new files).
165 # - more costly is '-C' (which implies '-M'), with the cost proportional to
166 # (number of changed files + number of removed files) * (number of new files)
167 # - even more costly is '-C', '--find-copies-harder' with cost
168 # (number of files in the original tree) * (number of new files)
169 # - one might want to include '-B' option, e.g. '-B', '-M'
170 our @diff_opts = ('-M'); # taken from git_commit
172 # Disables features that would allow repository owners to inject script into
174 our $prevent_xss = 0;
176 # Path to the highlight executable to use (must be the one from
177 # http://www.andre-simon.de due to assumptions about parameters and output).
178 # Useful if highlight is not installed on your webserver's PATH.
179 # [Default: highlight]
180 our $highlight_bin = "++HIGHLIGHT_BIN++";
182 # information about snapshot formats that gitweb is capable of serving
183 our %known_snapshot_formats = (
185 # 'display' => display name,
186 # 'type' => mime type,
187 # 'suffix' => filename suffix,
188 # 'format' => --format for git-archive,
189 # 'compressor' => [compressor command and arguments]
190 # (array reference, optional)
191 # 'disabled' => boolean (optional)}
194 'display' => 'tar.gz',
195 'type' => 'application/x-gzip',
196 'suffix' => '.tar.gz',
198 'compressor' => ['gzip', '-n']},
201 'display' => 'tar.bz2',
202 'type' => 'application/x-bzip2',
203 'suffix' => '.tar.bz2',
205 'compressor' => ['bzip2']},
208 'display' => 'tar.xz',
209 'type' => 'application/x-xz',
210 'suffix' => '.tar.xz',
212 'compressor' => ['xz'],
217 'type' => 'application/x-zip',
222 # Aliases so we understand old gitweb.snapshot values in repository
224 our %known_snapshot_format_aliases = (
229 # backward compatibility: legacy gitweb config support
230 'x-gzip' => undef, 'gz' => undef,
231 'x-bzip2' => undef, 'bz2' => undef,
232 'x-zip' => undef, '' => undef,
235 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
236 # are changed, it may be appropriate to change these values too via
243 # Used to set the maximum load that we will still respond to gitweb queries.
244 # If server load exceed this value then return "503 server busy" error.
245 # If gitweb cannot determined server load, it is taken to be 0.
246 # Leave it undefined (or set to 'undef') to turn off load checking.
249 # configuration for 'highlight' (http://www.andre-simon.de/)
251 our %highlight_basename = (
254 'SConstruct' => 'py', # SCons equivalent of Makefile
255 'Makefile' => 'make',
258 our %highlight_ext = (
259 # main extensions, defining name of syntax;
260 # see files in /usr/share/highlight/langDefs/ directory
262 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make),
263 # alternate extensions, see /etc/highlight/filetypes.conf
265 map { $_ => 'sh' } qw(bash zsh ksh),
266 map { $_ => 'cpp' } qw(cxx c++ cc),
267 map { $_ => 'php' } qw(php3 php4 php5 phps),
268 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
269 map { $_ => 'make'} qw(mak mk),
270 map { $_ => 'xml' } qw(xhtml html htm),
273 # You define site-wide feature defaults here; override them with
274 # $GITWEB_CONFIG as necessary.
277 # 'sub' => feature-sub (subroutine),
278 # 'override' => allow-override (boolean),
279 # 'default' => [ default options...] (array reference)}
281 # if feature is overridable (it means that allow-override has true value),
282 # then feature-sub will be called with default options as parameters;
283 # return value of feature-sub indicates if to enable specified feature
285 # if there is no 'sub' key (no feature-sub), then feature cannot be
288 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
289 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
292 # Enable the 'blame' blob view, showing the last commit that modified
293 # each line in the file. This can be very CPU-intensive.
295 # To enable system wide have in $GITWEB_CONFIG
296 # $feature{'blame'}{'default'} = [1];
297 # To have project specific config enable override in $GITWEB_CONFIG
298 # $feature{'blame'}{'override'} = 1;
299 # and in project config gitweb.blame = 0|1;
301 'sub' => sub { feature_bool
('blame', @_) },
305 # Enable the 'snapshot' link, providing a compressed archive of any
306 # tree. This can potentially generate high traffic if you have large
309 # Value is a list of formats defined in %known_snapshot_formats that
311 # To disable system wide have in $GITWEB_CONFIG
312 # $feature{'snapshot'}{'default'} = [];
313 # To have project specific config enable override in $GITWEB_CONFIG
314 # $feature{'snapshot'}{'override'} = 1;
315 # and in project config, a comma-separated list of formats or "none"
316 # to disable. Example: gitweb.snapshot = tbz2,zip;
318 'sub' => \
&feature_snapshot
,
320 'default' => ['tgz']},
322 # Enable text search, which will list the commits which match author,
323 # committer or commit text to a given string. Enabled by default.
324 # Project specific override is not supported.
329 # Enable grep search, which will list the files in currently selected
330 # tree containing the given string. Enabled by default. This can be
331 # potentially CPU-intensive, of course.
333 # To enable system wide have in $GITWEB_CONFIG
334 # $feature{'grep'}{'default'} = [1];
335 # To have project specific config enable override in $GITWEB_CONFIG
336 # $feature{'grep'}{'override'} = 1;
337 # and in project config gitweb.grep = 0|1;
339 'sub' => sub { feature_bool
('grep', @_) },
343 # Enable the pickaxe search, which will list the commits that modified
344 # a given string in a file. This can be practical and quite faster
345 # alternative to 'blame', but still potentially CPU-intensive.
347 # To enable system wide have in $GITWEB_CONFIG
348 # $feature{'pickaxe'}{'default'} = [1];
349 # To have project specific config enable override in $GITWEB_CONFIG
350 # $feature{'pickaxe'}{'override'} = 1;
351 # and in project config gitweb.pickaxe = 0|1;
353 'sub' => sub { feature_bool
('pickaxe', @_) },
357 # Enable showing size of blobs in a 'tree' view, in a separate
358 # column, similar to what 'ls -l' does. This cost a bit of IO.
360 # To disable system wide have in $GITWEB_CONFIG
361 # $feature{'show-sizes'}{'default'} = [0];
362 # To have project specific config enable override in $GITWEB_CONFIG
363 # $feature{'show-sizes'}{'override'} = 1;
364 # and in project config gitweb.showsizes = 0|1;
366 'sub' => sub { feature_bool
('showsizes', @_) },
370 # Make gitweb use an alternative format of the URLs which can be
371 # more readable and natural-looking: project name is embedded
372 # directly in the path and the query string contains other
373 # auxiliary information. All gitweb installations recognize
374 # URL in either format; this configures in which formats gitweb
377 # To enable system wide have in $GITWEB_CONFIG
378 # $feature{'pathinfo'}{'default'} = [1];
379 # Project specific override is not supported.
381 # Note that you will need to change the default location of CSS,
382 # favicon, logo and possibly other files to an absolute URL. Also,
383 # if gitweb.cgi serves as your indexfile, you will need to force
384 # $my_uri to contain the script name in your $GITWEB_CONFIG.
389 # Make gitweb consider projects in project root subdirectories
390 # to be forks of existing projects. Given project $projname.git,
391 # projects matching $projname/*.git will not be shown in the main
392 # projects list, instead a '+' mark will be added to $projname
393 # there and a 'forks' view will be enabled for the project, listing
394 # all the forks. If project list is taken from a file, forks have
395 # to be listed after the main project.
397 # To enable system wide have in $GITWEB_CONFIG
398 # $feature{'forks'}{'default'} = [1];
399 # Project specific override is not supported.
404 # Insert custom links to the action bar of all project pages.
405 # This enables you mainly to link to third-party scripts integrating
406 # into gitweb; e.g. git-browser for graphical history representation
407 # or custom web-based repository administration interface.
409 # The 'default' value consists of a list of triplets in the form
410 # (label, link, position) where position is the label after which
411 # to insert the link and link is a format string where %n expands
412 # to the project name, %f to the project path within the filesystem,
413 # %h to the current hash (h gitweb parameter) and %b to the current
414 # hash base (hb gitweb parameter); %% expands to %.
416 # To enable system wide have in $GITWEB_CONFIG e.g.
417 # $feature{'actions'}{'default'} = [('graphiclog',
418 # '/git-browser/by-commit.html?r=%n', 'summary')];
419 # Project specific override is not supported.
424 # Allow gitweb scan project content tags of project repository,
425 # and display the popular Web 2.0-ish "tag cloud" near the projects
426 # list. Note that this is something COMPLETELY different from the
429 # gitweb by itself can show existing tags, but it does not handle
430 # tagging itself; you need to do it externally, outside gitweb.
431 # The format is described in git_get_project_ctags() subroutine.
432 # You may want to install the HTML::TagCloud Perl module to get
433 # a pretty tag cloud instead of just a list of tags.
435 # To enable system wide have in $GITWEB_CONFIG
436 # $feature{'ctags'}{'default'} = [1];
437 # Project specific override is not supported.
439 # In the future whether ctags editing is enabled might depend
440 # on the value, but using 1 should always mean no editing of ctags.
445 # The maximum number of patches in a patchset generated in patch
446 # view. Set this to 0 or undef to disable patch view, or to a
447 # negative number to remove any limit.
449 # To disable system wide have in $GITWEB_CONFIG
450 # $feature{'patches'}{'default'} = [0];
451 # To have project specific config enable override in $GITWEB_CONFIG
452 # $feature{'patches'}{'override'} = 1;
453 # and in project config gitweb.patches = 0|n;
454 # where n is the maximum number of patches allowed in a patchset.
456 'sub' => \
&feature_patches
,
460 # Avatar support. When this feature is enabled, views such as
461 # shortlog or commit will display an avatar associated with
462 # the email of the committer(s) and/or author(s).
464 # Currently available providers are gravatar and picon.
465 # If an unknown provider is specified, the feature is disabled.
467 # Gravatar depends on Digest::MD5.
468 # Picon currently relies on the indiana.edu database.
470 # To enable system wide have in $GITWEB_CONFIG
471 # $feature{'avatar'}{'default'} = ['<provider>'];
472 # where <provider> is either gravatar or picon.
473 # To have project specific config enable override in $GITWEB_CONFIG
474 # $feature{'avatar'}{'override'} = 1;
475 # and in project config gitweb.avatar = <provider>;
477 'sub' => \
&feature_avatar
,
481 # Enable displaying how much time and how many git commands
482 # it took to generate and display page. Disabled by default.
483 # Project specific override is not supported.
488 # Enable turning some links into links to actions which require
489 # JavaScript to run (like 'blame_incremental'). Not enabled by
490 # default. Project specific override is currently not supported.
491 'javascript-actions' => {
495 # Enable and configure ability to change common timezone for dates
496 # in gitweb output via JavaScript. Enabled by default.
497 # Project specific override is not supported.
498 'javascript-timezone' => {
501 'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
502 # or undef to turn off this feature
503 'gitweb_tz', # name of cookie where to store selected timezone
504 'datetime', # CSS class used to mark up dates for manipulation
507 # Syntax highlighting support. This is based on Daniel Svensson's
508 # and Sham Chukoury's work in gitweb-xmms2.git.
509 # It requires the 'highlight' program present in $PATH,
510 # and therefore is disabled by default.
512 # To enable system wide have in $GITWEB_CONFIG
513 # $feature{'highlight'}{'default'} = [1];
516 'sub' => sub { feature_bool
('highlight', @_) },
520 # Enable displaying of remote heads in the heads list
522 # To enable system wide have in $GITWEB_CONFIG
523 # $feature{'remote_heads'}{'default'} = [1];
524 # To have project specific config enable override in $GITWEB_CONFIG
525 # $feature{'remote_heads'}{'override'} = 1;
526 # and in project config gitweb.remote_heads = 0|1;
528 'sub' => sub { feature_bool
('remote_heads', @_) },
533 sub gitweb_get_feature
{
535 return unless exists $feature{$name};
536 my ($sub, $override, @defaults) = (
537 $feature{$name}{'sub'},
538 $feature{$name}{'override'},
539 @{$feature{$name}{'default'}});
540 # project specific override is possible only if we have project
541 our $git_dir; # global variable, declared later
542 if (!$override || !defined $git_dir) {
546 warn "feature $name is not overridable";
549 return $sub->(@defaults);
552 # A wrapper to check if a given feature is enabled.
553 # With this, you can say
555 # my $bool_feat = gitweb_check_feature('bool_feat');
556 # gitweb_check_feature('bool_feat') or somecode;
560 # my ($bool_feat) = gitweb_get_feature('bool_feat');
561 # (gitweb_get_feature('bool_feat'))[0] or somecode;
563 sub gitweb_check_feature
{
564 return (gitweb_get_feature
(@_))[0];
570 my ($val) = git_get_project_config
($key, '--bool');
574 } elsif ($val eq 'true') {
576 } elsif ($val eq 'false') {
581 sub feature_snapshot
{
584 my ($val) = git_get_project_config
('snapshot');
587 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
593 sub feature_patches
{
594 my @val = (git_get_project_config
('patches', '--int'));
604 my @val = (git_get_project_config
('avatar'));
606 return @val ? @val : @_;
609 # checking HEAD file with -e is fragile if the repository was
610 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
612 sub check_head_link
{
614 my $headfile = "$dir/HEAD";
615 return ((-e
$headfile) ||
616 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
619 sub check_export_ok
{
621 return (check_head_link
($dir) &&
622 (!$export_ok || -e
"$dir/$export_ok") &&
623 (!$export_auth_hook || $export_auth_hook->($dir)));
626 # process alternate names for backward compatibility
627 # filter out unsupported (unknown) snapshot formats
628 sub filter_snapshot_fmts
{
632 exists $known_snapshot_format_aliases{$_} ?
633 $known_snapshot_format_aliases{$_} : $_} @fmts;
635 exists $known_snapshot_formats{$_} &&
636 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
639 # If it is set to code reference, it is code that it is to be run once per
640 # request, allowing updating configurations that change with each request,
641 # while running other code in config file only once.
643 # Otherwise, if it is false then gitweb would process config file only once;
644 # if it is true then gitweb config would be run for each request.
645 our $per_request_config = 1;
647 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
648 sub evaluate_gitweb_config
{
649 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
650 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
651 # die if there are errors parsing config file
652 if (-e
$GITWEB_CONFIG) {
655 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
656 do $GITWEB_CONFIG_SYSTEM;
661 # Get loadavg of system, to compare against $maxload.
662 # Currently it requires '/proc/loadavg' present to get loadavg;
663 # if it is not present it returns 0, which means no load checking.
665 if( -e
'/proc/loadavg' ){
666 open my $fd, '<', '/proc/loadavg'
668 my @load = split(/\s+/, scalar <$fd>);
671 # The first three columns measure CPU and IO utilization of the last one,
672 # five, and 10 minute periods. The fourth column shows the number of
673 # currently running processes and the total number of processes in the m/n
674 # format. The last column displays the last process ID used.
675 return $load[0] || 0;
677 # additional checks for load average should go here for things that don't export
683 # version of the core git binary
685 sub evaluate_git_version
{
686 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
687 $number_of_git_cmds++;
691 if (defined $maxload && get_loadavg
() > $maxload) {
692 die_error
(503, "The load average on the server is too high");
696 # ======================================================================
697 # input validation and dispatch
699 # input parameters can be collected from a variety of sources (presently, CGI
700 # and PATH_INFO), so we define an %input_params hash that collects them all
701 # together during validation: this allows subsequent uses (e.g. href()) to be
702 # agnostic of the parameter origin
704 our %input_params = ();
706 # input parameters are stored with the long parameter name as key. This will
707 # also be used in the href subroutine to convert parameters to their CGI
708 # equivalent, and since the href() usage is the most frequent one, we store
709 # the name -> CGI key mapping here, instead of the reverse.
711 # XXX: Warning: If you touch this, check the search form for updating,
714 our @cgi_param_mapping = (
722 hash_parent_base
=> "hpb",
727 snapshot_format
=> "sf",
728 extra_options
=> "opt",
729 search_use_regexp
=> "sr",
731 # this must be last entry (for manipulation from JavaScript)
734 our %cgi_param_mapping = @cgi_param_mapping;
736 # we will also need to know the possible actions, for validation
738 "blame" => \
&git_blame
,
739 "blame_incremental" => \
&git_blame_incremental
,
740 "blame_data" => \
&git_blame_data
,
741 "blobdiff" => \
&git_blobdiff
,
742 "blobdiff_plain" => \
&git_blobdiff_plain
,
743 "blob" => \
&git_blob
,
744 "blob_plain" => \
&git_blob_plain
,
745 "commitdiff" => \
&git_commitdiff
,
746 "commitdiff_plain" => \
&git_commitdiff_plain
,
747 "commit" => \
&git_commit
,
748 "forks" => \
&git_forks
,
749 "heads" => \
&git_heads
,
750 "history" => \
&git_history
,
752 "patch" => \
&git_patch
,
753 "patches" => \
&git_patches
,
754 "remotes" => \
&git_remotes
,
756 "atom" => \
&git_atom
,
757 "search" => \
&git_search
,
758 "search_help" => \
&git_search_help
,
759 "shortlog" => \
&git_shortlog
,
760 "summary" => \
&git_summary
,
762 "tags" => \
&git_tags
,
763 "tree" => \
&git_tree
,
764 "snapshot" => \
&git_snapshot
,
765 "object" => \
&git_object
,
766 # those below don't need $project
767 "opml" => \
&git_opml
,
768 "project_list" => \
&git_project_list
,
769 "project_index" => \
&git_project_index
,
772 # finally, we have the hash of allowed extra_options for the commands that
774 our %allowed_options = (
775 "--no-merges" => [ qw(rss atom log shortlog history) ],
778 # fill %input_params with the CGI parameters. All values except for 'opt'
779 # should be single values, but opt can be an array. We should probably
780 # build an array of parameters that can be multi-valued, but since for the time
781 # being it's only this one, we just single it out
782 sub evaluate_query_params
{
785 while (my ($name, $symbol) = each %cgi_param_mapping) {
786 if ($symbol eq 'opt') {
787 $input_params{$name} = [ $cgi->param($symbol) ];
789 $input_params{$name} = $cgi->param($symbol);
794 # now read PATH_INFO and update the parameter list for missing parameters
795 sub evaluate_path_info
{
796 return if defined $input_params{'project'};
797 return if !$path_info;
798 $path_info =~ s
,^/+,,;
799 return if !$path_info;
801 # find which part of PATH_INFO is project
802 my $project = $path_info;
804 while ($project && !check_head_link
("$projectroot/$project")) {
805 $project =~ s
,/*[^/]*$,,;
807 return unless $project;
808 $input_params{'project'} = $project;
810 # do not change any parameters if an action is given using the query string
811 return if $input_params{'action'};
812 $path_info =~ s
,^\Q
$project\E
/*,,;
814 # next, check if we have an action
815 my $action = $path_info;
817 if (exists $actions{$action}) {
818 $path_info =~ s
,^$action/*,,;
819 $input_params{'action'} = $action;
822 # list of actions that want hash_base instead of hash, but can have no
823 # pathname (f) parameter
829 # we want to catch, among others
830 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
831 my ($parentrefname, $parentpathname, $refname, $pathname) =
832 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);
834 # first, analyze the 'current' part
835 if (defined $pathname) {
836 # we got "branch:filename" or "branch:dir/"
837 # we could use git_get_type(branch:pathname), but:
838 # - it needs $git_dir
839 # - it does a git() call
840 # - the convention of terminating directories with a slash
841 # makes it superfluous
842 # - embedding the action in the PATH_INFO would make it even
844 $pathname =~ s
,^/+,,;
845 if (!$pathname || substr($pathname, -1) eq "/") {
846 $input_params{'action'} ||= "tree";
849 # the default action depends on whether we had parent info
851 if ($parentrefname) {
852 $input_params{'action'} ||= "blobdiff_plain";
854 $input_params{'action'} ||= "blob_plain";
857 $input_params{'hash_base'} ||= $refname;
858 $input_params{'file_name'} ||= $pathname;
859 } elsif (defined $refname) {
860 # we got "branch". In this case we have to choose if we have to
861 # set hash or hash_base.
863 # Most of the actions without a pathname only want hash to be
864 # set, except for the ones specified in @wants_base that want
865 # hash_base instead. It should also be noted that hand-crafted
866 # links having 'history' as an action and no pathname or hash
867 # set will fail, but that happens regardless of PATH_INFO.
868 if (defined $parentrefname) {
869 # if there is parent let the default be 'shortlog' action
870 # (for http://git.example.com/repo.git/A..B links); if there
871 # is no parent, dispatch will detect type of object and set
872 # action appropriately if required (if action is not set)
873 $input_params{'action'} ||= "shortlog";
875 if ($input_params{'action'} &&
876 grep { $_ eq $input_params{'action'} } @wants_base) {
877 $input_params{'hash_base'} ||= $refname;
879 $input_params{'hash'} ||= $refname;
883 # next, handle the 'parent' part, if present
884 if (defined $parentrefname) {
885 # a missing pathspec defaults to the 'current' filename, allowing e.g.
886 # someproject/blobdiff/oldrev..newrev:/filename
887 if ($parentpathname) {
888 $parentpathname =~ s
,^/+,,;
889 $parentpathname =~ s
,/$,,;
890 $input_params{'file_parent'} ||= $parentpathname;
892 $input_params{'file_parent'} ||= $input_params{'file_name'};
894 # we assume that hash_parent_base is wanted if a path was specified,
895 # or if the action wants hash_base instead of hash
896 if (defined $input_params{'file_parent'} ||
897 grep { $_ eq $input_params{'action'} } @wants_base) {
898 $input_params{'hash_parent_base'} ||= $parentrefname;
900 $input_params{'hash_parent'} ||= $parentrefname;
904 # for the snapshot action, we allow URLs in the form
905 # $project/snapshot/$hash.ext
906 # where .ext determines the snapshot and gets removed from the
907 # passed $refname to provide the $hash.
909 # To be able to tell that $refname includes the format extension, we
910 # require the following two conditions to be satisfied:
911 # - the hash input parameter MUST have been set from the $refname part
912 # of the URL (i.e. they must be equal)
913 # - the snapshot format MUST NOT have been defined already (e.g. from
915 # It's also useless to try any matching unless $refname has a dot,
916 # so we check for that too
917 if (defined $input_params{'action'} &&
918 $input_params{'action'} eq 'snapshot' &&
919 defined $refname && index($refname, '.') != -1 &&
920 $refname eq $input_params{'hash'} &&
921 !defined $input_params{'snapshot_format'}) {
922 # We loop over the known snapshot formats, checking for
923 # extensions. Allowed extensions are both the defined suffix
924 # (which includes the initial dot already) and the snapshot
925 # format key itself, with a prepended dot
926 while (my ($fmt, $opt) = each %known_snapshot_formats) {
928 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
932 # a valid suffix was found, so set the snapshot format
933 # and reset the hash parameter
934 $input_params{'snapshot_format'} = $fmt;
935 $input_params{'hash'} = $hash;
936 # we also set the format suffix to the one requested
937 # in the URL: this way a request for e.g. .tgz returns
938 # a .tgz instead of a .tar.gz
939 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
945 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
946 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
947 $searchtext, $search_regexp);
948 sub evaluate_and_validate_params
{
949 our $action = $input_params{'action'};
950 if (defined $action) {
951 if (!validate_action
($action)) {
952 die_error
(400, "Invalid action parameter");
956 # parameters which are pathnames
957 our $project = $input_params{'project'};
958 if (defined $project) {
959 if (!validate_project
($project)) {
961 die_error
(404, "No such project");
965 our $file_name = $input_params{'file_name'};
966 if (defined $file_name) {
967 if (!validate_pathname
($file_name)) {
968 die_error
(400, "Invalid file parameter");
972 our $file_parent = $input_params{'file_parent'};
973 if (defined $file_parent) {
974 if (!validate_pathname
($file_parent)) {
975 die_error
(400, "Invalid file parent parameter");
979 # parameters which are refnames
980 our $hash = $input_params{'hash'};
982 if (!validate_refname
($hash)) {
983 die_error
(400, "Invalid hash parameter");
987 our $hash_parent = $input_params{'hash_parent'};
988 if (defined $hash_parent) {
989 if (!validate_refname
($hash_parent)) {
990 die_error
(400, "Invalid hash parent parameter");
994 our $hash_base = $input_params{'hash_base'};
995 if (defined $hash_base) {
996 if (!validate_refname
($hash_base)) {
997 die_error
(400, "Invalid hash base parameter");
1001 our @extra_options = @{$input_params{'extra_options'}};
1002 # @extra_options is always defined, since it can only be (currently) set from
1003 # CGI, and $cgi->param() returns the empty array in array context if the param
1005 foreach my $opt (@extra_options) {
1006 if (not exists $allowed_options{$opt}) {
1007 die_error
(400, "Invalid option parameter");
1009 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
1010 die_error
(400, "Invalid option parameter for this action");
1014 our $hash_parent_base = $input_params{'hash_parent_base'};
1015 if (defined $hash_parent_base) {
1016 if (!validate_refname
($hash_parent_base)) {
1017 die_error
(400, "Invalid hash parent base parameter");
1022 our $page = $input_params{'page'};
1023 if (defined $page) {
1024 if ($page =~ m/[^0-9]/) {
1025 die_error
(400, "Invalid page parameter");
1029 our $searchtype = $input_params{'searchtype'};
1030 if (defined $searchtype) {
1031 if ($searchtype =~ m/[^a-z]/) {
1032 die_error
(400, "Invalid searchtype parameter");
1036 our $search_use_regexp = $input_params{'search_use_regexp'};
1038 our $searchtext = $input_params{'searchtext'};
1040 if (defined $searchtext) {
1041 if (length($searchtext) < 2) {
1042 die_error
(403, "At least two characters are required for search parameter");
1044 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
1048 # path to the current git repository
1050 sub evaluate_git_dir
{
1051 our $git_dir = "$projectroot/$project" if $project;
1054 our (@snapshot_fmts, $git_avatar);
1055 sub configure_gitweb_features
{
1056 # list of supported snapshot formats
1057 our @snapshot_fmts = gitweb_get_feature
('snapshot');
1058 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1060 # check that the avatar feature is set to a known provider name,
1061 # and for each provider check if the dependencies are satisfied.
1062 # if the provider name is invalid or the dependencies are not met,
1063 # reset $git_avatar to the empty string.
1064 our ($git_avatar) = gitweb_get_feature
('avatar');
1065 if ($git_avatar eq 'gravatar') {
1066 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
1067 } elsif ($git_avatar eq 'picon') {
1074 # custom error handler: 'die <message>' is Internal Server Error
1075 sub handle_errors_html
{
1076 my $msg = shift; # it is already HTML escaped
1078 # to avoid infinite loop where error occurs in die_error,
1079 # change handler to default handler, disabling handle_errors_html
1080 set_message
("Error occured when inside die_error:\n$msg");
1082 # you cannot jump out of die_error when called as error handler;
1083 # the subroutine set via CGI::Carp::set_message is called _after_
1084 # HTTP headers are already written, so it cannot write them itself
1085 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1087 set_message
(\
&handle_errors_html
);
1091 if (!defined $action) {
1092 if (defined $hash) {
1093 $action = git_get_type
($hash);
1094 } elsif (defined $hash_base && defined $file_name) {
1095 $action = git_get_type
("$hash_base:$file_name");
1096 } elsif (defined $project) {
1097 $action = 'summary';
1099 $action = 'project_list';
1102 if (!defined($actions{$action})) {
1103 die_error
(400, "Unknown action");
1105 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1107 die_error
(400, "Project needed");
1109 $actions{$action}->();
1113 our $t0 = [ gettimeofday
() ]
1115 our $number_of_git_cmds = 0;
1118 our $first_request = 1;
1123 if ($first_request) {
1124 evaluate_gitweb_config
();
1125 evaluate_git_version
();
1127 if ($per_request_config) {
1128 if (ref($per_request_config) eq 'CODE') {
1129 $per_request_config->();
1130 } elsif (!$first_request) {
1131 evaluate_gitweb_config
();
1136 # $projectroot and $projects_list might be set in gitweb config file
1137 $projects_list ||= $projectroot;
1139 evaluate_query_params
();
1140 evaluate_path_info
();
1141 evaluate_and_validate_params
();
1144 configure_gitweb_features
();
1149 our $is_last_request = sub { 1 };
1150 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1153 sub configure_as_fcgi
{
1155 our $CGI = 'CGI::Fast';
1157 my $request_number = 0;
1158 # let each child service 100 requests
1159 our $is_last_request = sub { ++$request_number > 100 };
1162 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1164 if $script_name =~ /\.fcgi$/;
1166 return unless (@ARGV);
1168 require Getopt
::Long
;
1169 Getopt
::Long
::GetOptions
(
1170 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1171 'nproc|n=i' => sub {
1172 my ($arg, $val) = @_;
1173 return unless eval { require FCGI
::ProcManager
; 1; };
1174 my $proc_manager = FCGI
::ProcManager-
>new({
1175 n_processes
=> $val,
1177 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1178 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1179 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1188 $pre_listen_hook->()
1189 if $pre_listen_hook;
1192 while ($cgi = $CGI->new()) {
1193 $pre_dispatch_hook->()
1194 if $pre_dispatch_hook;
1198 $post_dispatch_hook->()
1199 if $post_dispatch_hook;
1202 last REQUEST
if ($is_last_request->());
1211 if (defined caller) {
1212 # wrapped in a subroutine processing requests,
1213 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1216 # pure CGI script, serving single request
1220 ## ======================================================================
1223 # possible values of extra options
1224 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1225 # -replay => 1 - start from a current view (replay with modifications)
1226 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1227 # -anchor => ANCHOR - add #ANCHOR to end of URL, implies -replay if used alone
1230 # default is to use -absolute url() i.e. $my_uri
1231 my $href = $params{-full
} ? $my_url : $my_uri;
1233 # implicit -replay, must be first of implicit params
1234 $params{-replay
} = 1 if (keys %params == 1 && $params{-anchor
});
1236 $params{'project'} = $project unless exists $params{'project'};
1238 if ($params{-replay
}) {
1239 while (my ($name, $symbol) = each %cgi_param_mapping) {
1240 if (!exists $params{$name}) {
1241 $params{$name} = $input_params{$name};
1246 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1247 if (defined $params{'project'} &&
1248 (exists $params{-path_info
} ? $params{-path_info
} : $use_pathinfo)) {
1249 # try to put as many parameters as possible in PATH_INFO:
1252 # - hash_parent or hash_parent_base:/file_parent
1253 # - hash or hash_base:/filename
1254 # - the snapshot_format as an appropriate suffix
1256 # When the script is the root DirectoryIndex for the domain,
1257 # $href here would be something like http://gitweb.example.com/
1258 # Thus, we strip any trailing / from $href, to spare us double
1259 # slashes in the final URL
1262 # Then add the project name, if present
1263 $href .= "/".esc_path_info
($params{'project'});
1264 delete $params{'project'};
1266 # since we destructively absorb parameters, we keep this
1267 # boolean that remembers if we're handling a snapshot
1268 my $is_snapshot = $params{'action'} eq 'snapshot';
1270 # Summary just uses the project path URL, any other action is
1272 if (defined $params{'action'}) {
1273 $href .= "/".esc_path_info
($params{'action'})
1274 unless $params{'action'} eq 'summary';
1275 delete $params{'action'};
1278 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1279 # stripping nonexistent or useless pieces
1280 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1281 || $params{'hash_parent'} || $params{'hash'});
1282 if (defined $params{'hash_base'}) {
1283 if (defined $params{'hash_parent_base'}) {
1284 $href .= esc_path_info
($params{'hash_parent_base'});
1285 # skip the file_parent if it's the same as the file_name
1286 if (defined $params{'file_parent'}) {
1287 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1288 delete $params{'file_parent'};
1289 } elsif ($params{'file_parent'} !~ /\.\./) {
1290 $href .= ":/".esc_path_info
($params{'file_parent'});
1291 delete $params{'file_parent'};
1295 delete $params{'hash_parent'};
1296 delete $params{'hash_parent_base'};
1297 } elsif (defined $params{'hash_parent'}) {
1298 $href .= esc_path_info
($params{'hash_parent'}). "..";
1299 delete $params{'hash_parent'};
1302 $href .= esc_path_info
($params{'hash_base'});
1303 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1304 $href .= ":/".esc_path_info
($params{'file_name'});
1305 delete $params{'file_name'};
1307 delete $params{'hash'};
1308 delete $params{'hash_base'};
1309 } elsif (defined $params{'hash'}) {
1310 $href .= esc_path_info
($params{'hash'});
1311 delete $params{'hash'};
1314 # If the action was a snapshot, we can absorb the
1315 # snapshot_format parameter too
1317 my $fmt = $params{'snapshot_format'};
1318 # snapshot_format should always be defined when href()
1319 # is called, but just in case some code forgets, we
1320 # fall back to the default
1321 $fmt ||= $snapshot_fmts[0];
1322 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1323 delete $params{'snapshot_format'};
1327 # now encode the parameters explicitly
1329 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1330 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1331 if (defined $params{$name}) {
1332 if (ref($params{$name}) eq "ARRAY") {
1333 foreach my $par (@{$params{$name}}) {
1334 push @result, $symbol . "=" . esc_param
($par);
1337 push @result, $symbol . "=" . esc_param
($params{$name});
1341 $href .= "?" . join(';', @result) if scalar @result;
1343 # final transformation: trailing spaces must be escaped (URI-encoded)
1344 $href =~ s/(\s+)$/CGI::escape($1)/e;
1346 if ($params{-anchor
}) {
1347 $href .= "#".esc_param
($params{-anchor
});
1354 ## ======================================================================
1355 ## validation, quoting/unquoting and escaping
1357 sub validate_action
{
1358 my $input = shift || return undef;
1359 return undef unless exists $actions{$input};
1363 sub validate_project
{
1364 my $input = shift || return undef;
1365 if (!validate_pathname
($input) ||
1366 !(-d
"$projectroot/$input") ||
1367 !check_export_ok
("$projectroot/$input") ||
1368 ($strict_export && !project_in_list
($input))) {
1375 sub validate_pathname
{
1376 my $input = shift || return undef;
1378 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1379 # at the beginning, at the end, and between slashes.
1380 # also this catches doubled slashes
1381 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1384 # no null characters
1385 if ($input =~ m!\0!) {
1391 sub validate_refname
{
1392 my $input = shift || return undef;
1394 # textual hashes are O.K.
1395 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1398 # it must be correct pathname
1399 $input = validate_pathname
($input)
1401 # restrictions on ref name according to git-check-ref-format
1402 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1408 # decode sequences of octets in utf8 into Perl's internal form,
1409 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1410 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1413 return undef unless defined $str;
1414 if (utf8
::valid
($str)) {
1418 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1422 # quote unsafe chars, but keep the slash, even when it's not
1423 # correct, but quoted slashes look too horrible in bookmarks
1426 return undef unless defined $str;
1427 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1432 # the quoting rules for path_info fragment are slightly different
1435 return undef unless defined $str;
1437 # path_info doesn't treat '+' as space (specially), but '?' must be escaped
1438 $str =~ s/([^A-Za-z0-9\-_.~();\/;:@&= +]+)/CGI
::escape
($1)/eg
;
1443 # quote unsafe chars in whole URL, so some characters cannot be quoted
1446 return undef unless defined $str;
1447 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1452 # quote unsafe characters in HTML attributes
1455 # for XHTML conformance escaping '"' to '"' is not enough
1456 return esc_html
(@_);
1459 # replace invalid utf8 character with SUBSTITUTION sequence
1464 return undef unless defined $str;
1466 $str = to_utf8
($str);
1467 $str = $cgi->escapeHTML($str);
1468 if ($opts{'-nbsp'}) {
1469 $str =~ s/ / /g;
1471 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1475 # quote control characters and escape filename to HTML
1480 return undef unless defined $str;
1482 $str = to_utf8
($str);
1483 $str = $cgi->escapeHTML($str);
1484 if ($opts{'-nbsp'}) {
1485 $str =~ s/ / /g;
1487 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1491 # Make control characters "printable", using character escape codes (CEC)
1495 my %es = ( # character escape codes, aka escape sequences
1496 "\t" => '\t', # tab (HT)
1497 "\n" => '\n', # line feed (LF)
1498 "\r" => '\r', # carrige return (CR)
1499 "\f" => '\f', # form feed (FF)
1500 "\b" => '\b', # backspace (BS)
1501 "\a" => '\a', # alarm (bell) (BEL)
1502 "\e" => '\e', # escape (ESC)
1503 "\013" => '\v', # vertical tab (VT)
1504 "\000" => '\0', # nul character (NUL)
1506 my $chr = ( (exists $es{$cntrl})
1508 : sprintf('\%2x', ord($cntrl)) );
1509 if ($opts{-nohtml
}) {
1512 return "<span class=\"cntrl\">$chr</span>";
1516 # Alternatively use unicode control pictures codepoints,
1517 # Unicode "printable representation" (PR)
1522 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1523 if ($opts{-nohtml
}) {
1526 return "<span class=\"cntrl\">$chr</span>";
1530 # git may return quoted and escaped filenames
1536 my %es = ( # character escape codes, aka escape sequences
1537 't' => "\t", # tab (HT, TAB)
1538 'n' => "\n", # newline (NL)
1539 'r' => "\r", # return (CR)
1540 'f' => "\f", # form feed (FF)
1541 'b' => "\b", # backspace (BS)
1542 'a' => "\a", # alarm (bell) (BEL)
1543 'e' => "\e", # escape (ESC)
1544 'v' => "\013", # vertical tab (VT)
1547 if ($seq =~ m/^[0-7]{1,3}$/) {
1548 # octal char sequence
1549 return chr(oct($seq));
1550 } elsif (exists $es{$seq}) {
1551 # C escape sequence, aka character escape code
1554 # quoted ordinary character
1558 if ($str =~ m/^"(.*)"$/) {
1561 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1566 # escape tabs (convert tabs to spaces)
1570 while ((my $pos = index($line, "\t")) != -1) {
1571 if (my $count = (8 - ($pos % 8))) {
1572 my $spaces = ' ' x
$count;
1573 $line =~ s/\t/$spaces/;
1580 sub project_in_list
{
1581 my $project = shift;
1582 my @list = git_get_projects_list
();
1583 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1586 ## ----------------------------------------------------------------------
1587 ## HTML aware string manipulation
1589 # Try to chop given string on a word boundary between position
1590 # $len and $len+$add_len. If there is no word boundary there,
1591 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1592 # (marking chopped part) would be longer than given string.
1596 my $add_len = shift || 10;
1597 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1599 # Make sure perl knows it is utf8 encoded so we don't
1600 # cut in the middle of a utf8 multibyte char.
1601 $str = to_utf8
($str);
1603 # allow only $len chars, but don't cut a word if it would fit in $add_len
1604 # if it doesn't fit, cut it if it's still longer than the dots we would add
1605 # remove chopped character entities entirely
1607 # when chopping in the middle, distribute $len into left and right part
1608 # return early if chopping wouldn't make string shorter
1609 if ($where eq 'center') {
1610 return $str if ($len + 5 >= length($str)); # filler is length 5
1613 return $str if ($len + 4 >= length($str)); # filler is length 4
1616 # regexps: ending and beginning with word part up to $add_len
1617 my $endre = qr/.{$len}\w{0,$add_len}/;
1618 my $begre = qr/\w{0,$add_len}.{$len}/;
1620 if ($where eq 'left') {
1621 $str =~ m/^(.*?)($begre)$/;
1622 my ($lead, $body) = ($1, $2);
1623 if (length($lead) > 4) {
1626 return "$lead$body";
1628 } elsif ($where eq 'center') {
1629 $str =~ m/^($endre)(.*)$/;
1630 my ($left, $str) = ($1, $2);
1631 $str =~ m/^(.*?)($begre)$/;
1632 my ($mid, $right) = ($1, $2);
1633 if (length($mid) > 5) {
1636 return "$left$mid$right";
1639 $str =~ m/^($endre)(.*)$/;
1642 if (length($tail) > 4) {
1645 return "$body$tail";
1649 # takes the same arguments as chop_str, but also wraps a <span> around the
1650 # result with a title attribute if it does get chopped. Additionally, the
1651 # string is HTML-escaped.
1652 sub chop_and_escape_str
{
1655 my $chopped = chop_str
(@_);
1656 if ($chopped eq $str) {
1657 return esc_html
($chopped);
1659 $str =~ s/[[:cntrl:]]/?/g;
1660 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1664 ## ----------------------------------------------------------------------
1665 ## functions returning short strings
1667 # CSS class for given age value (in seconds)
1671 if (!defined $age) {
1673 } elsif ($age < 60*60*2) {
1675 } elsif ($age < 60*60*24*2) {
1682 # convert age in seconds to "nn units ago" string
1687 if ($age > 60*60*24*365*2) {
1688 $age_str = (int $age/60/60/24/365);
1689 $age_str .= " years ago";
1690 } elsif ($age > 60*60*24*(365/12)*2) {
1691 $age_str = int $age/60/60/24/(365/12);
1692 $age_str .= " months ago";
1693 } elsif ($age > 60*60*24*7*2) {
1694 $age_str = int $age/60/60/24/7;
1695 $age_str .= " weeks ago";
1696 } elsif ($age > 60*60*24*2) {
1697 $age_str = int $age/60/60/24;
1698 $age_str .= " days ago";
1699 } elsif ($age > 60*60*2) {
1700 $age_str = int $age/60/60;
1701 $age_str .= " hours ago";
1702 } elsif ($age > 60*2) {
1703 $age_str = int $age/60;
1704 $age_str .= " min ago";
1705 } elsif ($age > 2) {
1706 $age_str = int $age;
1707 $age_str .= " sec ago";
1709 $age_str .= " right now";
1715 S_IFINVALID
=> 0030000,
1716 S_IFGITLINK
=> 0160000,
1719 # submodule/subproject, a commit object reference
1723 return (($mode & S_IFMT
) == S_IFGITLINK
)
1726 # convert file mode in octal to symbolic file mode string
1728 my $mode = oct shift;
1730 if (S_ISGITLINK
($mode)) {
1731 return 'm---------';
1732 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1733 return 'drwxr-xr-x';
1734 } elsif (S_ISLNK
($mode)) {
1735 return 'lrwxrwxrwx';
1736 } elsif (S_ISREG
($mode)) {
1737 # git cares only about the executable bit
1738 if ($mode & S_IXUSR
) {
1739 return '-rwxr-xr-x';
1741 return '-rw-r--r--';
1744 return '----------';
1748 # convert file mode in octal to file type string
1752 if ($mode !~ m/^[0-7]+$/) {
1758 if (S_ISGITLINK
($mode)) {
1760 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1762 } elsif (S_ISLNK
($mode)) {
1764 } elsif (S_ISREG
($mode)) {
1771 # convert file mode in octal to file type description string
1772 sub file_type_long
{
1775 if ($mode !~ m/^[0-7]+$/) {
1781 if (S_ISGITLINK
($mode)) {
1783 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1785 } elsif (S_ISLNK
($mode)) {
1787 } elsif (S_ISREG
($mode)) {
1788 if ($mode & S_IXUSR
) {
1789 return "executable";
1799 ## ----------------------------------------------------------------------
1800 ## functions returning short HTML fragments, or transforming HTML fragments
1801 ## which don't belong to other sections
1803 # format line of commit message.
1804 sub format_log_line_html
{
1807 $line = esc_html
($line, -nbsp
=>1);
1808 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1809 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1810 -class => "text"}, $1);
1816 # format marker of refs pointing to given object
1818 # the destination action is chosen based on object type and current context:
1819 # - for annotated tags, we choose the tag view unless it's the current view
1820 # already, in which case we go to shortlog view
1821 # - for other refs, we keep the current view if we're in history, shortlog or
1822 # log view, and select shortlog otherwise
1823 sub format_ref_marker
{
1824 my ($refs, $id) = @_;
1827 if (defined $refs->{$id}) {
1828 foreach my $ref (@{$refs->{$id}}) {
1829 # this code exploits the fact that non-lightweight tags are the
1830 # only indirect objects, and that they are the only objects for which
1831 # we want to use tag instead of shortlog as action
1832 my ($type, $name) = qw();
1833 my $indirect = ($ref =~ s/\^\{\}$//);
1834 # e.g. tags/v2.6.11 or heads/next
1835 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1844 $class .= " indirect" if $indirect;
1846 my $dest_action = "shortlog";
1849 $dest_action = "tag" unless $action eq "tag";
1850 } elsif ($action =~ /^(history|(short)?log)$/) {
1851 $dest_action = $action;
1855 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1858 my $link = $cgi->a({
1860 action
=>$dest_action,
1864 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
1870 return ' <span class="refs">'. $markers . '</span>';
1876 # format, perhaps shortened and with markers, title line
1877 sub format_subject_html
{
1878 my ($long, $short, $href, $extra) = @_;
1879 $extra = '' unless defined($extra);
1881 if (length($short) < length($long)) {
1882 $long =~ s/[[:cntrl:]]/?/g;
1883 return $cgi->a({-href
=> $href, -class => "list subject",
1884 -title
=> to_utf8
($long)},
1885 esc_html
($short)) . $extra;
1887 return $cgi->a({-href
=> $href, -class => "list subject"},
1888 esc_html
($long)) . $extra;
1892 # Rather than recomputing the url for an email multiple times, we cache it
1893 # after the first hit. This gives a visible benefit in views where the avatar
1894 # for the same email is used repeatedly (e.g. shortlog).
1895 # The cache is shared by all avatar engines (currently gravatar only), which
1896 # are free to use it as preferred. Since only one avatar engine is used for any
1897 # given page, there's no risk for cache conflicts.
1898 our %avatar_cache = ();
1900 # Compute the picon url for a given email, by using the picon search service over at
1901 # http://www.cs.indiana.edu/picons/search.html
1903 my $email = lc shift;
1904 if (!$avatar_cache{$email}) {
1905 my ($user, $domain) = split('@', $email);
1906 $avatar_cache{$email} =
1907 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1909 "users+domains+unknown/up/single";
1911 return $avatar_cache{$email};
1914 # Compute the gravatar url for a given email, if it's not in the cache already.
1915 # Gravatar stores only the part of the URL before the size, since that's the
1916 # one computationally more expensive. This also allows reuse of the cache for
1917 # different sizes (for this particular engine).
1919 my $email = lc shift;
1921 $avatar_cache{$email} ||=
1922 "http://www.gravatar.com/avatar/" .
1923 Digest
::MD5
::md5_hex
($email) . "?s=";
1924 return $avatar_cache{$email} . $size;
1927 # Insert an avatar for the given $email at the given $size if the feature
1929 sub git_get_avatar
{
1930 my ($email, %opts) = @_;
1931 my $pre_white = ($opts{-pad_before
} ? " " : "");
1932 my $post_white = ($opts{-pad_after
} ? " " : "");
1933 $opts{-size
} ||= 'default';
1934 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1936 if ($git_avatar eq 'gravatar') {
1937 $url = gravatar_url
($email, $size);
1938 } elsif ($git_avatar eq 'picon') {
1939 $url = picon_url
($email);
1941 # Other providers can be added by extending the if chain, defining $url
1942 # as needed. If no variant puts something in $url, we assume avatars
1943 # are completely disabled/unavailable.
1946 "<img width=\"$size\" " .
1947 "class=\"avatar\" " .
1948 "src=\"".esc_url
($url)."\" " .
1956 sub format_search_author
{
1957 my ($author, $searchtype, $displaytext) = @_;
1958 my $have_search = gitweb_check_feature
('search');
1962 if ($searchtype eq 'author') {
1963 $performed = "authored";
1964 } elsif ($searchtype eq 'committer') {
1965 $performed = "committed";
1968 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1969 searchtext
=>$author,
1970 searchtype
=>$searchtype), class=>"list",
1971 title
=>"Search for commits $performed by $author"},
1975 return $displaytext;
1979 # format the author name of the given commit with the given tag
1980 # the author name is chopped and escaped according to the other
1981 # optional parameters (see chop_str).
1982 sub format_author_html
{
1985 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1986 return "<$tag class=\"author\">" .
1987 format_search_author
($co->{'author_name'}, "author",
1988 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1993 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1994 sub format_git_diff_header_line
{
1996 my $diffinfo = shift;
1997 my ($from, $to) = @_;
1999 if ($diffinfo->{'nparents'}) {
2001 $line =~ s!^(diff (.*?) )"?.*$!$1!;
2002 if ($to->{'href'}) {
2003 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
2004 esc_path
($to->{'file'}));
2005 } else { # file was deleted (no href)
2006 $line .= esc_path
($to->{'file'});
2010 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2011 if ($from->{'href'}) {
2012 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
2013 'a/' . esc_path
($from->{'file'}));
2014 } else { # file was added (no href)
2015 $line .= 'a/' . esc_path
($from->{'file'});
2018 if ($to->{'href'}) {
2019 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
2020 'b/' . esc_path
($to->{'file'}));
2021 } else { # file was deleted
2022 $line .= 'b/' . esc_path
($to->{'file'});
2026 return "<div class=\"diff header\">$line</div>\n";
2029 # format extended diff header line, before patch itself
2030 sub format_extended_diff_header_line
{
2032 my $diffinfo = shift;
2033 my ($from, $to) = @_;
2036 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
2037 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2038 esc_path
($from->{'file'}));
2040 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
2041 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2042 esc_path
($to->{'file'}));
2044 # match single <mode>
2045 if ($line =~ m/\s(\d{6})$/) {
2046 $line .= '<span class="info"> (' .
2047 file_type_long
($1) .
2051 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
2052 # can match only for combined diff
2054 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2055 if ($from->{'href'}[$i]) {
2056 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
2058 substr($diffinfo->{'from_id'}[$i],0,7));
2063 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
2066 if ($to->{'href'}) {
2067 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2068 substr($diffinfo->{'to_id'},0,7));
2073 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
2074 # can match only for ordinary diff
2075 my ($from_link, $to_link);
2076 if ($from->{'href'}) {
2077 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
2078 substr($diffinfo->{'from_id'},0,7));
2080 $from_link = '0' x
7;
2082 if ($to->{'href'}) {
2083 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
2084 substr($diffinfo->{'to_id'},0,7));
2088 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2089 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2092 return $line . "<br/>\n";
2095 # format from-file/to-file diff header
2096 sub format_diff_from_to_header
{
2097 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
2102 #assert($line =~ m/^---/) if DEBUG;
2103 # no extra formatting for "^--- /dev/null"
2104 if (! $diffinfo->{'nparents'}) {
2105 # ordinary (single parent) diff
2106 if ($line =~ m!^--- "?a/!) {
2107 if ($from->{'href'}) {
2109 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2110 esc_path
($from->{'file'}));
2113 esc_path
($from->{'file'});
2116 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2119 # combined diff (merge commit)
2120 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2121 if ($from->{'href'}[$i]) {
2123 $cgi->a({-href
=>href
(action
=>"blobdiff",
2124 hash_parent
=>$diffinfo->{'from_id'}[$i],
2125 hash_parent_base
=>$parents[$i],
2126 file_parent
=>$from->{'file'}[$i],
2127 hash
=>$diffinfo->{'to_id'},
2129 file_name
=>$to->{'file'}),
2131 -title
=>"diff" . ($i+1)},
2134 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2135 esc_path
($from->{'file'}[$i]));
2137 $line = '--- /dev/null';
2139 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2144 #assert($line =~ m/^\+\+\+/) if DEBUG;
2145 # no extra formatting for "^+++ /dev/null"
2146 if ($line =~ m!^\+\+\+ "?b/!) {
2147 if ($to->{'href'}) {
2149 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2150 esc_path
($to->{'file'}));
2153 esc_path
($to->{'file'});
2156 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
2161 # create note for patch simplified by combined diff
2162 sub format_diff_cc_simplified
{
2163 my ($diffinfo, @parents) = @_;
2166 $result .= "<div class=\"diff header\">" .
2168 if (!is_deleted
($diffinfo)) {
2169 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2171 hash
=>$diffinfo->{'to_id'},
2172 file_name
=>$diffinfo->{'to_file'}),
2174 esc_path
($diffinfo->{'to_file'}));
2176 $result .= esc_path
($diffinfo->{'to_file'});
2178 $result .= "</div>\n" . # class="diff header"
2179 "<div class=\"diff nodifferences\">" .
2181 "</div>\n"; # class="diff nodifferences"
2186 # format patch (diff) line (not to be used for diff headers)
2187 sub format_diff_line
{
2189 my ($from, $to) = @_;
2190 my $diff_class = "";
2194 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2196 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
2197 if ($line =~ m/^\@{3}/) {
2198 $diff_class = " chunk_header";
2199 } elsif ($line =~ m/^\\/) {
2200 $diff_class = " incomplete";
2201 } elsif ($prefix =~ tr/+/+/) {
2202 $diff_class = " add";
2203 } elsif ($prefix =~ tr/-/-/) {
2204 $diff_class = " rem";
2207 # assume ordinary diff
2208 my $char = substr($line, 0, 1);
2210 $diff_class = " add";
2211 } elsif ($char eq '-') {
2212 $diff_class = " rem";
2213 } elsif ($char eq '@') {
2214 $diff_class = " chunk_header";
2215 } elsif ($char eq "\\") {
2216 $diff_class = " incomplete";
2219 $line = untabify
($line);
2220 if ($from && $to && $line =~ m/^\@{2} /) {
2221 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2222 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2224 $from_lines = 0 unless defined $from_lines;
2225 $to_lines = 0 unless defined $to_lines;
2227 if ($from->{'href'}) {
2228 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2229 -class=>"list"}, $from_text);
2231 if ($to->{'href'}) {
2232 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2233 -class=>"list"}, $to_text);
2235 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2236 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2237 return "<div class=\"diff$diff_class\">$line</div>\n";
2238 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2239 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2240 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2242 @from_text = split(' ', $ranges);
2243 for (my $i = 0; $i < @from_text; ++$i) {
2244 ($from_start[$i], $from_nlines[$i]) =
2245 (split(',', substr($from_text[$i], 1)), 0);
2248 $to_text = pop @from_text;
2249 $to_start = pop @from_start;
2250 $to_nlines = pop @from_nlines;
2252 $line = "<span class=\"chunk_info\">$prefix ";
2253 for (my $i = 0; $i < @from_text; ++$i) {
2254 if ($from->{'href'}[$i]) {
2255 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2256 -class=>"list"}, $from_text[$i]);
2258 $line .= $from_text[$i];
2262 if ($to->{'href'}) {
2263 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2264 -class=>"list"}, $to_text);
2268 $line .= " $prefix</span>" .
2269 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2270 return "<div class=\"diff$diff_class\">$line</div>\n";
2272 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2275 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2276 # linked. Pass the hash of the tree/commit to snapshot.
2277 sub format_snapshot_links
{
2279 my $num_fmts = @snapshot_fmts;
2280 if ($num_fmts > 1) {
2281 # A parenthesized list of links bearing format names.
2282 # e.g. "snapshot (_tar.gz_ _zip_)"
2283 return "snapshot (" . join(' ', map
2290 }, $known_snapshot_formats{$_}{'display'})
2291 , @snapshot_fmts) . ")";
2292 } elsif ($num_fmts == 1) {
2293 # A single "snapshot" link whose tooltip bears the format name.
2295 my ($fmt) = @snapshot_fmts;
2301 snapshot_format
=>$fmt
2303 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2305 } else { # $num_fmts == 0
2310 ## ......................................................................
2311 ## functions returning values to be passed, perhaps after some
2312 ## transformation, to other functions; e.g. returning arguments to href()
2314 # returns hash to be passed to href to generate gitweb URL
2315 # in -title key it returns description of link
2317 my $format = shift || 'Atom';
2318 my %res = (action
=> lc($format));
2320 # feed links are possible only for project views
2321 return unless (defined $project);
2322 # some views should link to OPML, or to generic project feed,
2323 # or don't have specific feed yet (so they should use generic)
2324 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2327 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2328 # from tag links; this also makes possible to detect branch links
2329 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2330 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2333 # find log type for feed description (title)
2335 if (defined $file_name) {
2336 $type = "history of $file_name";
2337 $type .= "/" if ($action eq 'tree');
2338 $type .= " on '$branch'" if (defined $branch);
2340 $type = "log of $branch" if (defined $branch);
2343 $res{-title
} = $type;
2344 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2345 $res{'file_name'} = $file_name;
2350 ## ----------------------------------------------------------------------
2351 ## git utility subroutines, invoking git commands
2353 # returns path to the core git executable and the --git-dir parameter as list
2355 $number_of_git_cmds++;
2356 return $GIT, '--git-dir='.$git_dir;
2359 # quote the given arguments for passing them to the shell
2360 # quote_command("command", "arg 1", "arg with ' and ! characters")
2361 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2362 # Try to avoid using this function wherever possible.
2365 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2368 # get HEAD ref of given project as hash
2369 sub git_get_head_hash
{
2370 return git_get_full_hash
(shift, 'HEAD');
2373 sub git_get_full_hash
{
2374 return git_get_hash
(@_);
2377 sub git_get_short_hash
{
2378 return git_get_hash
(@_, '--short=7');
2382 my ($project, $hash, @options) = @_;
2383 my $o_git_dir = $git_dir;
2385 $git_dir = "$projectroot/$project";
2386 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2387 '--verify', '-q', @options, $hash) {
2389 chomp $retval if defined $retval;
2392 if (defined $o_git_dir) {
2393 $git_dir = $o_git_dir;
2398 # get type of given object
2402 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2404 close $fd or return;
2409 # repository configuration
2410 our $config_file = '';
2413 # store multiple values for single key as anonymous array reference
2414 # single values stored directly in the hash, not as [ <value> ]
2415 sub hash_set_multi
{
2416 my ($hash, $key, $value) = @_;
2418 if (!exists $hash->{$key}) {
2419 $hash->{$key} = $value;
2420 } elsif (!ref $hash->{$key}) {
2421 $hash->{$key} = [ $hash->{$key}, $value ];
2423 push @{$hash->{$key}}, $value;
2427 # return hash of git project configuration
2428 # optionally limited to some section, e.g. 'gitweb'
2429 sub git_parse_project_config
{
2430 my $section_regexp = shift;
2435 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2438 while (my $keyval = <$fh>) {
2440 my ($key, $value) = split(/\n/, $keyval, 2);
2442 hash_set_multi
(\
%config, $key, $value)
2443 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2450 # convert config value to boolean: 'true' or 'false'
2451 # no value, number > 0, 'true' and 'yes' values are true
2452 # rest of values are treated as false (never as error)
2453 sub config_to_bool
{
2456 return 1 if !defined $val; # section.key
2458 # strip leading and trailing whitespace
2462 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2463 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2466 # convert config value to simple decimal number
2467 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2468 # to be multiplied by 1024, 1048576, or 1073741824
2472 # strip leading and trailing whitespace
2476 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2478 # unknown unit is treated as 1
2479 return $num * ($unit eq 'g' ? 1073741824 :
2480 $unit eq 'm' ? 1048576 :
2481 $unit eq 'k' ? 1024 : 1);
2486 # convert config value to array reference, if needed
2487 sub config_to_multi
{
2490 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2493 sub git_get_project_config
{
2494 my ($key, $type) = @_;
2496 return unless defined $git_dir;
2499 return unless ($key);
2500 $key =~ s/^gitweb\.//;
2501 return if ($key =~ m/\W/);
2504 if (defined $type) {
2507 unless ($type eq 'bool' || $type eq 'int');
2511 if (!defined $config_file ||
2512 $config_file ne "$git_dir/config") {
2513 %config = git_parse_project_config
('gitweb');
2514 $config_file = "$git_dir/config";
2517 # check if config variable (key) exists
2518 return unless exists $config{"gitweb.$key"};
2521 if (!defined $type) {
2522 return $config{"gitweb.$key"};
2523 } elsif ($type eq 'bool') {
2524 # backward compatibility: 'git config --bool' returns true/false
2525 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2526 } elsif ($type eq 'int') {
2527 return config_to_int
($config{"gitweb.$key"});
2529 return $config{"gitweb.$key"};
2532 # get hash of given path at given ref
2533 sub git_get_hash_by_path
{
2535 my $path = shift || return undef;
2540 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2541 or die_error
(500, "Open git-ls-tree failed");
2543 close $fd or return undef;
2545 if (!defined $line) {
2546 # there is no tree or hash given by $path at $base
2550 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2551 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2552 if (defined $type && $type ne $2) {
2553 # type doesn't match
2559 # get path of entry with given hash at given tree-ish (ref)
2560 # used to get 'from' filename for combined diff (merge commit) for renames
2561 sub git_get_path_by_hash
{
2562 my $base = shift || return;
2563 my $hash = shift || return;
2567 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2569 while (my $line = <$fd>) {
2572 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2573 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2574 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2583 ## ......................................................................
2584 ## git utility functions, directly accessing git repository
2586 # get the value of config variable either from file named as the variable
2587 # itself in the repository ($GIT_DIR/$name file), or from gitweb.$name
2588 # configuration variable in the repository config file.
2589 sub git_get_file_or_project_config
{
2590 my ($path, $name) = @_;
2592 $git_dir = "$projectroot/$path";
2593 open my $fd, '<', "$git_dir/$name"
2594 or return git_get_project_config
($name);
2597 if (defined $conf) {
2603 sub git_get_project_description
{
2605 return git_get_file_or_project_config
($path, 'description');
2608 sub git_get_project_category
{
2610 return git_get_file_or_project_config
($path, 'category');
2614 # supported formats:
2615 # * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)
2616 # - if its contents is a number, use it as tag weight,
2617 # - otherwise add a tag with weight 1
2618 # * $GIT_DIR/ctags file, each line is a tag (with weight 1)
2619 # the same value multiple times increases tag weight
2620 # * `gitweb.ctag' multi-valued repo config variable
2621 sub git_get_project_ctags
{
2622 my $project = shift;
2625 $git_dir = "$projectroot/$project";
2626 if (opendir my $dh, "$git_dir/ctags") {
2627 my @files = grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh);
2628 foreach my $tagfile (@files) {
2629 open my $ct, '<', $tagfile
2635 (my $ctag = $tagfile) =~ s
#.*/##;
2636 if ($val =~ /\d+/) {
2637 $ctags->{$ctag} = $val;
2639 $ctags->{$ctag} = 1;
2644 } elsif (open my $fh, '<', "$git_dir/ctags") {
2645 while (my $line = <$fh>) {
2647 $ctags->{$line}++ if $line;
2652 my $taglist = config_to_multi
(git_get_project_config
('ctag'));
2653 foreach my $tag (@$taglist) {
2661 # return hash, where keys are content tags ('ctags'),
2662 # and values are sum of weights of given tag in every project
2663 sub git_gather_all_ctags
{
2664 my $projects = shift;
2667 foreach my $p (@$projects) {
2668 foreach my $ct (keys %{$p->{'ctags'}}) {
2669 $ctags->{$ct} += $p->{'ctags'}->{$ct};
2676 sub git_populate_project_tagcloud
{
2679 # First, merge different-cased tags; tags vote on casing
2681 foreach (keys %$ctags) {
2682 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2683 if (not $ctags_lc{lc $_}->{topcount
}
2684 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2685 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2686 $ctags_lc{lc $_}->{topname
} = $_;
2691 my $matched = $cgi->param('by_tag');
2692 if (eval { require HTML
::TagCloud
; 1; }) {
2693 $cloud = HTML
::TagCloud-
>new;
2694 foreach my $ctag (sort keys %ctags_lc) {
2695 # Pad the title with spaces so that the cloud looks
2697 my $title = esc_html
($ctags_lc{$ctag}->{topname
});
2698 $title =~ s/ / /g;
2699 $title =~ s/^/ /g;
2700 $title =~ s/$/ /g;
2701 if (defined $matched && $matched eq $ctag) {
2702 $title = qq(<span class="match">$title</span>);
2704 $cloud->add($title, href
(project
=>undef, ctag
=>$ctag),
2705 $ctags_lc{$ctag}->{count
});
2709 foreach my $ctag (keys %ctags_lc) {
2710 my $title = esc_html
($ctags_lc{$ctag}->{topname
}, -nbsp
=>1);
2711 if (defined $matched && $matched eq $ctag) {
2712 $title = qq(<span class="match">$title</span>);
2714 $cloud->{$ctag}{count
} = $ctags_lc{$ctag}->{count
};
2715 $cloud->{$ctag}{ctag
} =
2716 $cgi->a({-href
=>href
(project
=>undef, ctag
=>$ctag)}, $title);
2722 sub git_show_project_tagcloud
{
2723 my ($cloud, $count) = @_;
2724 if (ref $cloud eq 'HTML::TagCloud') {
2725 return $cloud->html_and_css($count);
2727 my @tags = sort { $cloud->{$a}->{'count'} <=> $cloud->{$b}->{'count'} } keys %$cloud;
2729 '<div id="htmltagcloud"'.($project ? '' : ' align="center"').'>' .
2731 $cloud->{$_}->{'ctag'}
2732 } splice(@tags, 0, $count)) .
2737 sub git_get_project_url_list
{
2740 $git_dir = "$projectroot/$path";
2741 open my $fd, '<', "$git_dir/cloneurl"
2742 or return wantarray ?
2743 @{ config_to_multi
(git_get_project_config
('url')) } :
2744 config_to_multi
(git_get_project_config
('url'));
2745 my @git_project_url_list = map { chomp; $_ } <$fd>;
2748 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2751 sub git_get_projects_list
{
2752 my $filter = shift || '';
2755 $filter =~ s/\.git$//;
2757 if (-d
$projects_list) {
2758 # search in directory
2759 my $dir = $projects_list;
2760 # remove the trailing "/"
2762 my $pfxlen = length("$projects_list");
2763 my $pfxdepth = ($projects_list =~ tr!/!!);
2764 # when filtering, search only given subdirectory
2771 follow_fast
=> 1, # follow symbolic links
2772 follow_skip
=> 2, # ignore duplicates
2773 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2776 our $project_maxdepth;
2778 # skip project-list toplevel, if we get it.
2779 return if (m!^[/.]$!);
2780 # only directories can be git repositories
2781 return unless (-d
$_);
2782 # don't traverse too deep (Find is super slow on os x)
2783 # $project_maxdepth excludes depth of $projectroot
2784 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2785 $File::Find
::prune
= 1;
2789 my $path = substr($File::Find
::name
, $pfxlen + 1);
2790 # we check related file in $projectroot
2791 if (check_export_ok
("$projectroot/$path")) {
2792 push @list, { path
=> $path };
2793 $File::Find
::prune
= 1;
2798 } elsif (-f
$projects_list) {
2799 # read from file(url-encoded):
2800 # 'git%2Fgit.git Linus+Torvalds'
2801 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2802 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2803 open my $fd, '<', $projects_list or return;
2805 while (my $line = <$fd>) {
2807 my ($path, $owner) = split ' ', $line;
2808 $path = unescape
($path);
2809 $owner = unescape
($owner);
2810 if (!defined $path) {
2813 # if $filter is rpovided, check if $path begins with $filter
2814 if ($filter && $path !~ m!^\Q$filter\E/!) {
2817 if (check_export_ok
("$projectroot/$path")) {
2820 owner
=> to_utf8
($owner),
2830 # written with help of Tree::Trie module (Perl Artistic License, GPL compatibile)
2831 # as side effects it sets 'forks' field to list of forks for forked projects
2832 sub filter_forks_from_projects_list
{
2833 my $projects = shift;
2835 my %trie; # prefix tree of directories (path components)
2836 # generate trie out of those directories that might contain forks
2837 foreach my $pr (@$projects) {
2838 my $path = $pr->{'path'};
2839 $path =~ s/\.git$//; # forks of 'repo.git' are in 'repo/' directory
2840 next if ($path =~ m!/$!); # skip non-bare repositories, e.g. 'repo/.git'
2841 next unless ($path); # skip '.git' repository: tests, git-instaweb
2842 next unless (-d
$path); # containing directory exists
2843 $pr->{'forks'} = []; # there can be 0 or more forks of project
2846 my @dirs = split('/', $path);
2847 # walk the trie, until either runs out of components or out of trie
2849 while (scalar @dirs &&
2850 exists($ref->{$dirs[0]})) {
2851 $ref = $ref->{shift @dirs};
2853 # create rest of trie structure from rest of components
2854 foreach my $dir (@dirs) {
2855 $ref = $ref->{$dir} = {};
2857 # create end marker, store $pr as a data
2858 $ref->{''} = $pr if (!exists $ref->{''});
2861 # filter out forks, by finding shortest prefix match for paths
2864 foreach my $pr (@$projects) {
2868 foreach my $dir (split('/', $pr->{'path'})) {
2869 if (exists $ref->{''}) {
2870 # found [shortest] prefix, is a fork - skip it
2871 push @{$ref->{''}{'forks'}}, $pr;
2874 if (!exists $ref->{$dir}) {
2875 # not in trie, cannot have prefix, not a fork
2876 push @filtered, $pr;
2879 # If the dir is there, we just walk one step down the trie.
2880 $ref = $ref->{$dir};
2882 # we ran out of trie
2883 # (shouldn't happen: it's either no match, or end marker)
2884 push @filtered, $pr;
2890 # note: fill_project_list_info must be run first,
2891 # for 'descr_long' and 'ctags' to be filled
2892 sub search_projects_list
{
2893 my ($projlist, %opts) = @_;
2894 my $tagfilter = $opts{'tagfilter'};
2895 my $searchtext = $opts{'searchtext'};
2898 unless ($tagfilter || $searchtext);
2902 foreach my $pr (@$projlist) {
2905 next unless ref($pr->{'ctags'}) eq 'HASH';
2907 grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
2912 $pr->{'path'} =~ /$searchtext/ ||
2913 $pr->{'descr_long'} =~ /$searchtext/;
2916 push @projects, $pr;
2922 our $gitweb_project_owner = undef;
2923 sub git_get_project_list_from_file
{
2925 return if (defined $gitweb_project_owner);
2927 $gitweb_project_owner = {};
2928 # read from file (url-encoded):
2929 # 'git%2Fgit.git Linus+Torvalds'
2930 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2931 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2932 if (-f
$projects_list) {
2933 open(my $fd, '<', $projects_list);
2934 while (my $line = <$fd>) {
2936 my ($pr, $ow) = split ' ', $line;
2937 $pr = unescape
($pr);
2938 $ow = unescape
($ow);
2939 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2945 sub git_get_project_owner
{
2946 my $project = shift;
2949 return undef unless $project;
2950 $git_dir = "$projectroot/$project";
2952 if (!defined $gitweb_project_owner) {
2953 git_get_project_list_from_file
();
2956 if (exists $gitweb_project_owner->{$project}) {
2957 $owner = $gitweb_project_owner->{$project};
2959 if (!defined $owner){
2960 $owner = git_get_project_config
('owner');
2962 if (!defined $owner) {
2963 $owner = get_file_owner
("$git_dir");
2969 sub git_get_last_activity
{
2973 $git_dir = "$projectroot/$path";
2974 open($fd, "-|", git_cmd
(), 'for-each-ref',
2975 '--format=%(committer)',
2976 '--sort=-committerdate',
2978 'refs/heads') or return;
2979 my $most_recent = <$fd>;
2980 close $fd or return;
2981 if (defined $most_recent &&
2982 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2984 my $age = time - $timestamp;
2985 return ($age, age_string
($age));
2987 return (undef, undef);
2990 # Implementation note: when a single remote is wanted, we cannot use 'git
2991 # remote show -n' because that command always work (assuming it's a remote URL
2992 # if it's not defined), and we cannot use 'git remote show' because that would
2993 # try to make a network roundtrip. So the only way to find if that particular
2994 # remote is defined is to walk the list provided by 'git remote -v' and stop if
2995 # and when we find what we want.
2996 sub git_get_remotes_list
{
3000 open my $fd, '-|' , git_cmd
(), 'remote', '-v';
3002 while (my $remote = <$fd>) {
3004 $remote =~ s!\t(.*?)\s+\((\w+)\)$!!;
3005 next if $wanted and not $remote eq $wanted;
3006 my ($url, $key) = ($1, $2);
3008 $remotes{$remote} ||= { 'heads' => () };
3009 $remotes{$remote}{$key} = $url;
3011 close $fd or return;
3012 return wantarray ? %remotes : \
%remotes;
3015 # Takes a hash of remotes as first parameter and fills it by adding the
3016 # available remote heads for each of the indicated remotes.
3017 sub fill_remote_heads
{
3018 my $remotes = shift;
3019 my @heads = map { "remotes/$_" } keys %$remotes;
3020 my @remoteheads = git_get_heads_list
(undef, @heads);
3021 foreach my $remote (keys %$remotes) {
3022 $remotes->{$remote}{'heads'} = [ grep {
3023 $_->{'name'} =~ s!^$remote/!!
3028 sub git_get_references
{
3029 my $type = shift || "";
3031 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
3032 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
3033 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
3034 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
3037 while (my $line = <$fd>) {
3039 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
3040 if (defined $refs{$1}) {
3041 push @{$refs{$1}}, $2;
3047 close $fd or return;
3051 sub git_get_rev_name_tags
{
3052 my $hash = shift || return undef;
3054 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
3056 my $name_rev = <$fd>;
3059 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
3062 # catches also '$hash undefined' output
3067 ## ----------------------------------------------------------------------
3068 ## parse to hash functions
3072 my $tz = shift || "-0000";
3075 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
3076 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
3077 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
3078 $date{'hour'} = $hour;
3079 $date{'minute'} = $min;
3080 $date{'mday'} = $mday;
3081 $date{'day'} = $days[$wday];
3082 $date{'month'} = $months[$mon];
3083 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
3084 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
3085 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
3086 $mday, $months[$mon], $hour ,$min;
3087 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
3088 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
3090 my ($tz_sign, $tz_hour, $tz_min) =
3091 ($tz =~ m/^([-+])(\d\d)(\d\d)$/);
3092 $tz_sign = ($tz_sign eq '-' ? -1 : +1);
3093 my $local = $epoch + $tz_sign*((($tz_hour*60) + $tz_min)*60);
3094 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
3095 $date{'hour_local'} = $hour;
3096 $date{'minute_local'} = $min;
3097 $date{'tz_local'} = $tz;
3098 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
3099 1900+$year, $mon+1, $mday,
3100 $hour, $min, $sec, $tz);
3109 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
3110 $tag{'id'} = $tag_id;
3111 while (my $line = <$fd>) {
3113 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
3114 $tag{'object'} = $1;
3115 } elsif ($line =~ m/^type (.+)$/) {
3117 } elsif ($line =~ m/^tag (.+)$/) {
3119 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
3120 $tag{'author'} = $1;
3121 $tag{'author_epoch'} = $2;
3122 $tag{'author_tz'} = $3;
3123 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
3124 $tag{'author_name'} = $1;
3125 $tag{'author_email'} = $2;
3127 $tag{'author_name'} = $tag{'author'};
3129 } elsif ($line =~ m/--BEGIN/) {
3130 push @comment, $line;
3132 } elsif ($line eq "") {
3136 push @comment, <$fd>;
3137 $tag{'comment'} = \
@comment;
3138 close $fd or return;
3139 if (!defined $tag{'name'}) {
3145 sub parse_commit_text
{
3146 my ($commit_text, $withparents) = @_;
3147 my @commit_lines = split '\n', $commit_text;
3150 pop @commit_lines; # Remove '\0'
3152 if (! @commit_lines) {
3156 my $header = shift @commit_lines;
3157 if ($header !~ m/^[0-9a-fA-F]{40}/) {
3160 ($co{'id'}, my @parents) = split ' ', $header;
3161 while (my $line = shift @commit_lines) {
3162 last if $line eq "\n";
3163 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
3165 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
3167 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
3168 $co{'author'} = to_utf8
($1);
3169 $co{'author_epoch'} = $2;
3170 $co{'author_tz'} = $3;
3171 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
3172 $co{'author_name'} = $1;
3173 $co{'author_email'} = $2;
3175 $co{'author_name'} = $co{'author'};
3177 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
3178 $co{'committer'} = to_utf8
($1);
3179 $co{'committer_epoch'} = $2;
3180 $co{'committer_tz'} = $3;
3181 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
3182 $co{'committer_name'} = $1;
3183 $co{'committer_email'} = $2;
3185 $co{'committer_name'} = $co{'committer'};
3189 if (!defined $co{'tree'}) {
3192 $co{'parents'} = \
@parents;
3193 $co{'parent'} = $parents[0];
3195 foreach my $title (@commit_lines) {
3198 $co{'title'} = chop_str
($title, 80, 5);
3199 # remove leading stuff of merges to make the interesting part visible
3200 if (length($title) > 50) {
3201 $title =~ s/^Automatic //;
3202 $title =~ s/^merge (of|with) /Merge ... /i;
3203 if (length($title) > 50) {
3204 $title =~ s/(http|rsync):\/\///;
3206 if (length($title) > 50) {
3207 $title =~ s/(master|www|rsync)\.//;
3209 if (length($title) > 50) {
3210 $title =~ s/kernel.org:?//;
3212 if (length($title) > 50) {
3213 $title =~ s/\/pub\/scm//;
3216 $co{'title_short'} = chop_str
($title, 50, 5);
3220 if (! defined $co{'title'} || $co{'title'} eq "") {
3221 $co{'title'} = $co{'title_short'} = '(no commit message)';
3223 # remove added spaces
3224 foreach my $line (@commit_lines) {
3227 $co{'comment'} = \
@commit_lines;
3229 my $age = time - $co{'committer_epoch'};
3231 $co{'age_string'} = age_string
($age);
3232 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
3233 if ($age > 60*60*24*7*2) {
3234 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3235 $co{'age_string_age'} = $co{'age_string'};
3237 $co{'age_string_date'} = $co{'age_string'};
3238 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
3244 my ($commit_id) = @_;
3249 open my $fd, "-|", git_cmd
(), "rev-list",
3255 or die_error
(500, "Open git-rev-list failed");
3256 %co = parse_commit_text
(<$fd>, 1);
3263 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
3271 open my $fd, "-|", git_cmd
(), "rev-list",
3274 ("--max-count=" . $maxcount),
3275 ("--skip=" . $skip),
3279 ($filename ? ($filename) : ())
3280 or die_error
(500, "Open git-rev-list failed");
3281 while (my $line = <$fd>) {
3282 my %co = parse_commit_text
($line);
3287 return wantarray ? @cos : \
@cos;
3290 # parse line of git-diff-tree "raw" output
3291 sub parse_difftree_raw_line
{
3295 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3296 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3297 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3298 $res{'from_mode'} = $1;
3299 $res{'to_mode'} = $2;
3300 $res{'from_id'} = $3;
3302 $res{'status'} = $5;
3303 $res{'similarity'} = $6;
3304 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3305 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3307 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3310 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3311 # combined diff (for merge commit)
3312 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3313 $res{'nparents'} = length($1);
3314 $res{'from_mode'} = [ split(' ', $2) ];
3315 $res{'to_mode'} = pop @{$res{'from_mode'}};
3316 $res{'from_id'} = [ split(' ', $3) ];
3317 $res{'to_id'} = pop @{$res{'from_id'}};
3318 $res{'status'} = [ split('', $4) ];
3319 $res{'to_file'} = unquote
($5);
3321 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3322 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3323 $res{'commit'} = $1;
3326 return wantarray ? %res : \
%res;
3329 # wrapper: return parsed line of git-diff-tree "raw" output
3330 # (the argument might be raw line, or parsed info)
3331 sub parsed_difftree_line
{
3332 my $line_or_ref = shift;
3334 if (ref($line_or_ref) eq "HASH") {
3335 # pre-parsed (or generated by hand)
3336 return $line_or_ref;
3338 return parse_difftree_raw_line
($line_or_ref);
3342 # parse line of git-ls-tree output
3343 sub parse_ls_tree_line
{
3349 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3350 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3359 $res{'name'} = unquote
($5);
3362 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3363 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3371 $res{'name'} = unquote
($4);
3375 return wantarray ? %res : \
%res;
3378 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3379 sub parse_from_to_diffinfo
{
3380 my ($diffinfo, $from, $to, @parents) = @_;
3382 if ($diffinfo->{'nparents'}) {
3384 $from->{'file'} = [];
3385 $from->{'href'} = [];
3386 fill_from_file_info
($diffinfo, @parents)
3387 unless exists $diffinfo->{'from_file'};
3388 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3389 $from->{'file'}[$i] =
3390 defined $diffinfo->{'from_file'}[$i] ?
3391 $diffinfo->{'from_file'}[$i] :
3392 $diffinfo->{'to_file'};
3393 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3394 $from->{'href'}[$i] = href
(action
=>"blob",
3395 hash_base
=>$parents[$i],
3396 hash
=>$diffinfo->{'from_id'}[$i],
3397 file_name
=>$from->{'file'}[$i]);
3399 $from->{'href'}[$i] = undef;
3403 # ordinary (not combined) diff
3404 $from->{'file'} = $diffinfo->{'from_file'};
3405 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3406 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3407 hash
=>$diffinfo->{'from_id'},
3408 file_name
=>$from->{'file'});
3410 delete $from->{'href'};
3414 $to->{'file'} = $diffinfo->{'to_file'};
3415 if (!is_deleted
($diffinfo)) { # file exists in result
3416 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3417 hash
=>$diffinfo->{'to_id'},
3418 file_name
=>$to->{'file'});
3420 delete $to->{'href'};
3424 ## ......................................................................
3425 ## parse to array of hashes functions
3427 sub git_get_heads_list
{
3428 my ($limit, @classes) = @_;
3429 @classes = ('heads') unless @classes;
3430 my @patterns = map { "refs/$_" } @classes;
3433 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3434 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
3435 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3438 while (my $line = <$fd>) {
3442 my ($refinfo, $committerinfo) = split(/\0/, $line);
3443 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3444 my ($committer, $epoch, $tz) =
3445 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3446 $ref_item{'fullname'} = $name;
3447 $name =~ s!^refs/(?:head|remote)s/!!;
3449 $ref_item{'name'} = $name;
3450 $ref_item{'id'} = $hash;
3451 $ref_item{'title'} = $title || '(no commit message)';
3452 $ref_item{'epoch'} = $epoch;
3454 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3456 $ref_item{'age'} = "unknown";
3459 push @headslist, \
%ref_item;
3463 return wantarray ? @headslist : \
@headslist;
3466 sub git_get_tags_list
{
3470 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3471 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
3472 '--format=%(objectname) %(objecttype) %(refname) '.
3473 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3476 while (my $line = <$fd>) {
3480 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3481 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3482 my ($creator, $epoch, $tz) =
3483 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3484 $ref_item{'fullname'} = $name;
3485 $name =~ s!^refs/tags/!!;
3487 $ref_item{'type'} = $type;
3488 $ref_item{'id'} = $id;
3489 $ref_item{'name'} = $name;
3490 if ($type eq "tag") {
3491 $ref_item{'subject'} = $title;
3492 $ref_item{'reftype'} = $reftype;
3493 $ref_item{'refid'} = $refid;
3495 $ref_item{'reftype'} = $type;
3496 $ref_item{'refid'} = $id;
3499 if ($type eq "tag" || $type eq "commit") {
3500 $ref_item{'epoch'} = $epoch;
3502 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3504 $ref_item{'age'} = "unknown";
3508 push @tagslist, \
%ref_item;
3512 return wantarray ? @tagslist : \
@tagslist;
3515 ## ----------------------------------------------------------------------
3516 ## filesystem-related functions
3518 sub get_file_owner
{
3521 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3522 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3523 if (!defined $gcos) {
3527 $owner =~ s/[,;].*$//;
3528 return to_utf8
($owner);
3531 # assume that file exists
3533 my $filename = shift;
3535 open my $fd, '<', $filename;
3536 print map { to_utf8
($_) } <$fd>;
3540 ## ......................................................................
3541 ## mimetype related functions
3543 sub mimetype_guess_file
{
3544 my $filename = shift;
3545 my $mimemap = shift;
3546 -r
$mimemap or return undef;
3549 open(my $mh, '<', $mimemap) or return undef;
3551 next if m/^#/; # skip comments
3552 my ($mimetype, $exts) = split(/\t+/);
3553 if (defined $exts) {
3554 my @exts = split(/\s+/, $exts);
3555 foreach my $ext (@exts) {
3556 $mimemap{$ext} = $mimetype;
3562 $filename =~ /\.([^.]*)$/;
3563 return $mimemap{$1};
3566 sub mimetype_guess
{
3567 my $filename = shift;
3569 $filename =~ /\./ or return undef;
3571 if ($mimetypes_file) {
3572 my $file = $mimetypes_file;
3573 if ($file !~ m!^/!) { # if it is relative path
3574 # it is relative to project
3575 $file = "$projectroot/$project/$file";
3577 $mime = mimetype_guess_file
($filename, $file);
3579 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3585 my $filename = shift;
3588 my $mime = mimetype_guess
($filename);
3589 $mime and return $mime;
3593 return $default_blob_plain_mimetype unless $fd;
3596 return 'text/plain';
3597 } elsif (! $filename) {
3598 return 'application/octet-stream';
3599 } elsif ($filename =~ m/\.png$/i) {
3601 } elsif ($filename =~ m/\.gif$/i) {
3603 } elsif ($filename =~ m/\.jpe?g$/i) {
3604 return 'image/jpeg';
3606 return 'application/octet-stream';
3610 sub blob_contenttype
{
3611 my ($fd, $file_name, $type) = @_;
3613 $type ||= blob_mimetype
($fd, $file_name);
3614 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3615 $type .= "; charset=$default_text_plain_charset";
3621 # guess file syntax for syntax highlighting; return undef if no highlighting
3622 # the name of syntax can (in the future) depend on syntax highlighter used
3623 sub guess_file_syntax
{
3624 my ($highlight, $mimetype, $file_name) = @_;
3625 return undef unless ($highlight && defined $file_name);
3626 my $basename = basename
($file_name, '.in');
3627 return $highlight_basename{$basename}
3628 if exists $highlight_basename{$basename};
3630 $basename =~ /\.([^.]*)$/;
3631 my $ext = $1 or return undef;
3632 return $highlight_ext{$ext}
3633 if exists $highlight_ext{$ext};
3638 # run highlighter and return FD of its output,
3639 # or return original FD if no highlighting
3640 sub run_highlighter
{
3641 my ($fd, $highlight, $syntax) = @_;
3642 return $fd unless ($highlight && defined $syntax);
3645 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3646 quote_command
($highlight_bin).
3647 " --replace-tabs=8 --fragment --syntax $syntax |"
3648 or die_error
(500, "Couldn't open file or run syntax highlighter");
3652 ## ======================================================================
3653 ## functions printing HTML: header, footer, error page
3655 sub get_page_title
{
3656 my $title = to_utf8
($site_name);
3658 return $title unless (defined $project);
3659 $title .= " - " . to_utf8
($project);
3661 return $title unless (defined $action);
3662 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3664 return $title unless (defined $file_name);
3665 $title .= " - " . esc_path
($file_name);
3666 if ($action eq "tree" && $file_name !~ m
|/$|) {
3673 sub print_feed_meta
{
3674 if (defined $project) {
3675 my %href_params = get_feed_info
();
3676 if (!exists $href_params{'-title'}) {
3677 $href_params{'-title'} = 'log';
3680 foreach my $format (qw(RSS Atom)) {
3681 my $type = lc($format);
3683 '-rel' => 'alternate',
3684 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3685 '-type' => "application/$type+xml"
3688 $href_params{'action'} = $type;
3689 $link_attr{'-href'} = href
(%href_params);
3691 "rel=\"$link_attr{'-rel'}\" ".
3692 "title=\"$link_attr{'-title'}\" ".
3693 "href=\"$link_attr{'-href'}\" ".
3694 "type=\"$link_attr{'-type'}\" ".
3697 $href_params{'extra_options'} = '--no-merges';
3698 $link_attr{'-href'} = href
(%href_params);
3699 $link_attr{'-title'} .= ' (no merges)';
3701 "rel=\"$link_attr{'-rel'}\" ".
3702 "title=\"$link_attr{'-title'}\" ".
3703 "href=\"$link_attr{'-href'}\" ".
3704 "type=\"$link_attr{'-type'}\" ".
3709 printf('<link rel="alternate" title="%s projects list" '.
3710 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3711 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3712 printf('<link rel="alternate" title="%s projects feeds" '.
3713 'href="%s" type="text/x-opml" />'."\n",
3714 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3718 sub git_header_html
{
3719 my $status = shift || "200 OK";
3720 my $expires = shift;
3723 my $title = get_page_title
();
3725 # require explicit support from the UA if we are to send the page as
3726 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3727 # we have to do this because MSIE sometimes globs '*/*', pretending to
3728 # support xhtml+xml but choking when it gets what it asked for.
3729 if (defined $cgi->http('HTTP_ACCEPT') &&
3730 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3731 $cgi->Accept('application/xhtml+xml') != 0) {
3732 $content_type = 'application/xhtml+xml';
3734 $content_type = 'text/html';
3736 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3737 -status
=> $status, -expires
=> $expires)
3738 unless ($opts{'-no_http_header'});
3739 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3741 <?xml version="1.0" encoding="utf-8"?>
3742 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3743 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3744 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3745 <!-- git core binaries version $git_version -->
3747 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3748 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3749 <meta name="robots" content="index, nofollow"/>
3750 <title>$title</title>
3752 # the stylesheet, favicon etc urls won't work correctly with path_info
3753 # unless we set the appropriate base URL
3754 if ($ENV{'PATH_INFO'}) {
3755 print "<base href=\"".esc_url
($base_url)."\" />\n";
3757 # print out each stylesheet that exist, providing backwards capability
3758 # for those people who defined $stylesheet in a config file
3759 if (defined $stylesheet) {
3760 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3762 foreach my $stylesheet (@stylesheets) {
3763 next unless $stylesheet;
3764 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3768 if ($status eq '200 OK');
3769 if (defined $favicon) {
3770 print qq(<link rel="shortcut icon" href=").esc_url
($favicon).qq(" type="image/png" />\n);
3776 if (defined $site_header && -f
$site_header) {
3777 insert_file
($site_header);
3780 print "<div class=\"page_header\">\n";
3781 if (defined $logo) {
3782 print $cgi->a({-href
=> esc_url
($logo_url),
3783 -title
=> $logo_label},
3784 $cgi->img({-src
=> esc_url
($logo),
3785 -width
=> 72, -height
=> 27,
3787 -class => "logo"}));
3789 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3790 if (defined $project) {
3791 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3792 if (defined $action) {
3793 my $action_print = $action ;
3794 if (defined $opts{-action_extra
}) {
3795 $action_print = $cgi->a({-href
=> href
(action
=>$action)},
3798 print " / $action_print";
3800 if (defined $opts{-action_extra
}) {
3801 print " / $opts{-action_extra}";
3807 my $have_search = gitweb_check_feature
('search');
3808 if (defined $project && $have_search) {
3809 if (!defined $searchtext) {
3813 if (defined $hash_base) {
3814 $search_hash = $hash_base;
3815 } elsif (defined $hash) {
3816 $search_hash = $hash;
3818 $search_hash = "HEAD";
3820 my $action = $my_uri;
3821 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3822 if ($use_pathinfo) {
3823 $action .= "/".esc_url
($project);
3825 print $cgi->startform(-method => "get", -action
=> $action) .
3826 "<div class=\"search\">\n" .
3828 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3829 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3830 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3831 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3832 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3833 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3835 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3836 "<span title=\"Extended regular expression\">" .
3837 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3838 -checked
=> $search_use_regexp) .
3841 $cgi->end_form() . "\n";
3845 sub git_footer_html
{
3846 my $feed_class = 'rss_logo';
3848 print "<div class=\"page_footer\">\n";
3849 if (defined $project) {
3850 my $descr = git_get_project_description
($project);
3851 if (defined $descr) {
3852 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3855 my %href_params = get_feed_info
();
3856 if (!%href_params) {
3857 $feed_class .= ' generic';
3859 $href_params{'-title'} ||= 'log';
3861 foreach my $format (qw(RSS Atom)) {
3862 $href_params{'action'} = lc($format);
3863 print $cgi->a({-href
=> href
(%href_params),
3864 -title
=> "$href_params{'-title'} $format feed",
3865 -class => $feed_class}, $format)."\n";
3869 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3870 -class => $feed_class}, "OPML") . " ";
3871 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3872 -class => $feed_class}, "TXT") . "\n";
3874 print "</div>\n"; # class="page_footer"
3876 if (defined $t0 && gitweb_check_feature
('timed')) {
3877 print "<div id=\"generating_info\">\n";
3878 print 'This page took '.
3879 '<span id="generating_time" class="time_span">'.
3880 tv_interval
($t0, [ gettimeofday
() ]).
3883 '<span id="generating_cmd">'.
3884 $number_of_git_cmds.
3885 '</span> git commands '.
3887 print "</div>\n"; # class="page_footer"
3890 if (defined $site_footer && -f
$site_footer) {
3891 insert_file
($site_footer);
3894 print qq
!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
3895 if (defined $action &&
3896 $action eq 'blame_incremental') {
3897 print qq
!<script type
="text/javascript">\n!.
3898 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3899 qq
! "!. href() .qq!");\n!.
3902 my ($jstimezone, $tz_cookie, $datetime_class) =
3903 gitweb_get_feature
('javascript-timezone');
3905 print qq
!<script type
="text/javascript">\n!.
3906 qq
!window
.onload
= function
() {\n!;
3907 if (gitweb_check_feature
('javascript-actions')) {
3908 print qq
! fixLinks
();\n!;
3910 if ($jstimezone && $tz_cookie && $datetime_class) {
3911 print qq
! var tz_cookie
= { name
: '$tz_cookie', expires
: 14, path
: '/' };\n!. # in days
3912 qq
! onloadTZSetup
('$jstimezone', tz_cookie
, '$datetime_class');\n!;
3922 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3923 # Example: die_error(404, 'Hash not found')
3924 # By convention, use the following status codes (as defined in RFC 2616):
3925 # 400: Invalid or missing CGI parameters, or
3926 # requested object exists but has wrong type.
3927 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3928 # this server or project.
3929 # 404: Requested object/revision/project doesn't exist.
3930 # 500: The server isn't configured properly, or
3931 # an internal error occurred (e.g. failed assertions caused by bugs), or
3932 # an unknown error occurred (e.g. the git binary died unexpectedly).
3933 # 503: The server is currently unavailable (because it is overloaded,
3934 # or down for maintenance). Generally, this is a temporary state.
3936 my $status = shift || 500;
3937 my $error = esc_html
(shift) || "Internal Server Error";
3941 my %http_responses = (
3942 400 => '400 Bad Request',
3943 403 => '403 Forbidden',
3944 404 => '404 Not Found',
3945 500 => '500 Internal Server Error',
3946 503 => '503 Service Unavailable',
3948 git_header_html
($http_responses{$status}, undef, %opts);
3950 <div class="page_body">
3955 if (defined $extra) {
3963 unless ($opts{'-error_handler'});
3966 ## ----------------------------------------------------------------------
3967 ## functions printing or outputting HTML: navigation
3969 sub git_print_page_nav
{
3970 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3971 $extra = '' if !defined $extra; # pager or formats
3973 my @navs = qw(summary shortlog log commit commitdiff tree);
3975 @navs = grep { $_ ne $suppress } @navs;
3978 my %arg = map { $_ => {action
=>$_} } @navs;
3979 if (defined $head) {
3980 for (qw(commit commitdiff)) {
3981 $arg{$_}{'hash'} = $head;
3983 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3984 for (qw(shortlog log)) {
3985 $arg{$_}{'hash'} = $head;
3990 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3991 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3993 my @actions = gitweb_get_feature
('actions');
3996 'n' => $project, # project name
3997 'f' => $git_dir, # project path within filesystem
3998 'h' => $treehead || '', # current hash ('h' parameter)
3999 'b' => $treebase || '', # hash base ('hb' parameter)
4002 my ($label, $link, $pos) = splice(@actions,0,3);
4004 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
4006 $link =~ s/%([%nfhb])/$repl{$1}/g;
4007 $arg{$label}{'_href'} = $link;
4010 print "<div class=\"page_nav\">\n" .
4012 map { $_ eq $current ?
4013 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
4015 print "<br/>\n$extra<br/>\n" .
4019 # returns a submenu for the nagivation of the refs views (tags, heads,
4020 # remotes) with the current view disabled and the remotes view only
4021 # available if the feature is enabled
4022 sub format_ref_views
{
4024 my @ref_views = qw{tags heads};
4025 push @ref_views, 'remotes' if gitweb_check_feature
('remote_heads');
4026 return join " | ", map {
4027 $_ eq $current ? $_ :
4028 $cgi->a({-href
=> href
(action
=>$_)}, $_)
4032 sub format_paging_nav
{
4033 my ($action, $page, $has_next_link) = @_;
4039 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
4041 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
4042 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4044 $paging_nav .= "first ⋅ prev";
4047 if ($has_next_link) {
4048 $paging_nav .= " ⋅ " .
4049 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4050 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4052 $paging_nav .= " ⋅ next";
4058 ## ......................................................................
4059 ## functions printing or outputting HTML: div
4061 sub git_print_header_div
{
4062 my ($action, $title, $hash, $hash_base) = @_;
4065 $args{'action'} = $action;
4066 $args{'hash'} = $hash if $hash;
4067 $args{'hash_base'} = $hash_base if $hash_base;
4069 print "<div class=\"header\">\n" .
4070 $cgi->a({-href
=> href
(%args), -class => "title"},
4071 $title ? $title : $action) .
4075 sub format_repo_url
{
4076 my ($name, $url) = @_;
4077 return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n";
4080 # Group output by placing it in a DIV element and adding a header.
4081 # Options for start_div() can be provided by passing a hash reference as the
4082 # first parameter to the function.
4083 # Options to git_print_header_div() can be provided by passing an array
4084 # reference. This must follow the options to start_div if they are present.
4085 # The content can be a scalar, which is output as-is, a scalar reference, which
4086 # is output after html escaping, an IO handle passed either as *handle or
4087 # *handle{IO}, or a function reference. In the latter case all following
4088 # parameters will be taken as argument to the content function call.
4089 sub git_print_section
{
4090 my ($div_args, $header_args, $content);
4092 if (ref($arg) eq 'HASH') {
4096 if (ref($arg) eq 'ARRAY') {
4097 $header_args = $arg;
4102 print $cgi->start_div($div_args);
4103 git_print_header_div
(@$header_args);
4105 if (ref($content) eq 'CODE') {
4107 } elsif (ref($content) eq 'SCALAR') {
4108 print esc_html
($$content);
4109 } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') {
4111 } elsif (!ref($content) && defined($content)) {
4115 print $cgi->end_div;
4118 sub format_timestamp_html
{
4120 my $strtime = $date->{'rfc2822'};
4122 my (undef, undef, $datetime_class) =
4123 gitweb_get_feature
('javascript-timezone');
4124 if ($datetime_class) {
4125 $strtime = qq
!<span
class="$datetime_class">$strtime</span
>!;
4128 my $localtime_format = '(%02d:%02d %s)';
4129 if ($date->{'hour_local'} < 6) {
4130 $localtime_format = '(<span class="atnight">%02d:%02d</span> %s)';
4133 sprintf($localtime_format,
4134 $date->{'hour_local'}, $date->{'minute_local'}, $date->{'tz_local'});
4139 # Outputs the author name and date in long form
4140 sub git_print_authorship
{
4143 my $tag = $opts{-tag
} || 'div';
4144 my $author = $co->{'author_name'};
4146 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
4147 print "<$tag class=\"author_date\">" .
4148 format_search_author
($author, "author", esc_html
($author)) .
4149 " [".format_timestamp_html
(\
%ad)."]".
4150 git_get_avatar
($co->{'author_email'}, -pad_before
=> 1) .
4154 # Outputs table rows containing the full author or committer information,
4155 # in the format expected for 'commit' view (& similar).
4156 # Parameters are a commit hash reference, followed by the list of people
4157 # to output information for. If the list is empty it defaults to both
4158 # author and committer.
4159 sub git_print_authorship_rows
{
4161 # too bad we can't use @people = @_ || ('author', 'committer')
4163 @people = ('author', 'committer') unless @people;
4164 foreach my $who (@people) {
4165 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
4166 print "<tr><td>$who</td><td>" .
4167 format_search_author
($co->{"${who}_name"}, $who,
4168 esc_html
($co->{"${who}_name"})) . " " .
4169 format_search_author
($co->{"${who}_email"}, $who,
4170 esc_html
("<" . $co->{"${who}_email"} . ">")) .
4171 "</td><td rowspan=\"2\">" .
4172 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
4176 format_timestamp_html
(\
%wd) .
4182 sub git_print_page_path
{
4188 print "<div class=\"page_path\">";
4189 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
4190 -title
=> 'tree root'}, to_utf8
("[$project]"));
4192 if (defined $name) {
4193 my @dirname = split '/', $name;
4194 my $basename = pop @dirname;
4197 foreach my $dir (@dirname) {
4198 $fullname .= ($fullname ? '/' : '') . $dir;
4199 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
4201 -title
=> $fullname}, esc_path
($dir));
4204 if (defined $type && $type eq 'blob') {
4205 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
4207 -title
=> $name}, esc_path
($basename));
4208 } elsif (defined $type && $type eq 'tree') {
4209 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
4211 -title
=> $name}, esc_path
($basename));
4214 print esc_path
($basename);
4217 print "<br/></div>\n";
4224 if ($opts{'-remove_title'}) {
4225 # remove title, i.e. first line of log
4228 # remove leading empty lines
4229 while (defined $log->[0] && $log->[0] eq "") {
4236 foreach my $line (@$log) {
4237 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
4240 if (! $opts{'-remove_signoff'}) {
4241 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
4244 # remove signoff lines
4251 # print only one empty line
4252 # do not print empty line after signoff
4254 next if ($empty || $signoff);
4260 print format_log_line_html
($line) . "<br/>\n";
4263 if ($opts{'-final_empty_line'}) {
4264 # end with single empty line
4265 print "<br/>\n" unless $empty;
4269 # return link target (what link points to)
4270 sub git_get_link_target
{
4275 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4279 $link_target = <$fd>;
4284 return $link_target;
4287 # given link target, and the directory (basedir) the link is in,
4288 # return target of link relative to top directory (top tree);
4289 # return undef if it is not possible (including absolute links).
4290 sub normalize_link_target
{
4291 my ($link_target, $basedir) = @_;
4293 # absolute symlinks (beginning with '/') cannot be normalized
4294 return if (substr($link_target, 0, 1) eq '/');
4296 # normalize link target to path from top (root) tree (dir)
4299 $path = $basedir . '/' . $link_target;
4301 # we are in top (root) tree (dir)
4302 $path = $link_target;
4305 # remove //, /./, and /../
4307 foreach my $part (split('/', $path)) {
4308 # discard '.' and ''
4309 next if (!$part || $part eq '.');
4311 if ($part eq '..') {
4315 # link leads outside repository (outside top dir)
4319 push @path_parts, $part;
4322 $path = join('/', @path_parts);
4327 # print tree entry (row of git_tree), but without encompassing <tr> element
4328 sub git_print_tree_entry
{
4329 my ($t, $basedir, $hash_base, $have_blame) = @_;
4332 $base_key{'hash_base'} = $hash_base if defined $hash_base;
4334 # The format of a table row is: mode list link. Where mode is
4335 # the mode of the entry, list is the name of the entry, an href,
4336 # and link is the action links of the entry.
4338 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
4339 if (exists $t->{'size'}) {
4340 print "<td class=\"size\">$t->{'size'}</td>\n";
4342 if ($t->{'type'} eq "blob") {
4343 print "<td class=\"list\">" .
4344 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4345 file_name
=>"$basedir$t->{'name'}", %base_key),
4346 -class => "list"}, esc_path
($t->{'name'}));
4347 if (S_ISLNK
(oct $t->{'mode'})) {
4348 my $link_target = git_get_link_target
($t->{'hash'});
4350 my $norm_target = normalize_link_target
($link_target, $basedir);
4351 if (defined $norm_target) {
4353 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
4354 file_name
=>$norm_target),
4355 -title
=> $norm_target}, esc_path
($link_target));
4357 print " -> " . esc_path
($link_target);
4362 print "<td class=\"link\">";
4363 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4364 file_name
=>"$basedir$t->{'name'}", %base_key)},
4368 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4369 file_name
=>"$basedir$t->{'name'}", %base_key)},
4372 if (defined $hash_base) {
4374 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4375 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4379 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4380 file_name
=>"$basedir$t->{'name'}")},
4384 } elsif ($t->{'type'} eq "tree") {
4385 print "<td class=\"list\">";
4386 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4387 file_name
=>"$basedir$t->{'name'}",
4389 esc_path
($t->{'name'}));
4391 print "<td class=\"link\">";
4392 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4393 file_name
=>"$basedir$t->{'name'}",
4396 if (defined $hash_base) {
4398 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4399 file_name
=>"$basedir$t->{'name'}")},
4404 # unknown object: we can only present history for it
4405 # (this includes 'commit' object, i.e. submodule support)
4406 print "<td class=\"list\">" .
4407 esc_path
($t->{'name'}) .
4409 print "<td class=\"link\">";
4410 if (defined $hash_base) {
4411 print $cgi->a({-href
=> href
(action
=>"history",
4412 hash_base
=>$hash_base,
4413 file_name
=>"$basedir$t->{'name'}")},
4420 ## ......................................................................
4421 ## functions printing large fragments of HTML
4423 # get pre-image filenames for merge (combined) diff
4424 sub fill_from_file_info
{
4425 my ($diff, @parents) = @_;
4427 $diff->{'from_file'} = [ ];
4428 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4429 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4430 if ($diff->{'status'}[$i] eq 'R' ||
4431 $diff->{'status'}[$i] eq 'C') {
4432 $diff->{'from_file'}[$i] =
4433 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4440 # is current raw difftree line of file deletion
4442 my $diffinfo = shift;
4444 return $diffinfo->{'to_id'} eq ('0' x
40);
4447 # does patch correspond to [previous] difftree raw line
4448 # $diffinfo - hashref of parsed raw diff format
4449 # $patchinfo - hashref of parsed patch diff format
4450 # (the same keys as in $diffinfo)
4451 sub is_patch_split
{
4452 my ($diffinfo, $patchinfo) = @_;
4454 return defined $diffinfo && defined $patchinfo
4455 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4459 sub git_difftree_body
{
4460 my ($difftree, $hash, @parents) = @_;
4461 my ($parent) = $parents[0];
4462 my $have_blame = gitweb_check_feature
('blame');
4463 print "<div class=\"list_head\">\n";
4464 if ($#{$difftree} > 10) {
4465 print(($#{$difftree} + 1) . " files changed:\n");
4469 print "<table class=\"" .
4470 (@parents > 1 ? "combined " : "") .
4473 # header only for combined diff in 'commitdiff' view
4474 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
4477 print "<thead><tr>\n" .
4478 "<th></th><th></th>\n"; # filename, patchN link
4479 for (my $i = 0; $i < @parents; $i++) {
4480 my $par = $parents[$i];
4482 $cgi->a({-href
=> href
(action
=>"commitdiff",
4483 hash
=>$hash, hash_parent
=>$par),
4484 -title
=> 'commitdiff to parent number ' .
4485 ($i+1) . ': ' . substr($par,0,7)},
4489 print "</tr></thead>\n<tbody>\n";
4494 foreach my $line (@{$difftree}) {
4495 my $diff = parsed_difftree_line
($line);
4498 print "<tr class=\"dark\">\n";
4500 print "<tr class=\"light\">\n";
4504 if (exists $diff->{'nparents'}) { # combined diff
4506 fill_from_file_info
($diff, @parents)
4507 unless exists $diff->{'from_file'};
4509 if (!is_deleted
($diff)) {
4510 # file exists in the result (child) commit
4512 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4513 file_name
=>$diff->{'to_file'},
4515 -class => "list"}, esc_path
($diff->{'to_file'})) .
4519 esc_path
($diff->{'to_file'}) .
4523 if ($action eq 'commitdiff') {
4526 print "<td class=\"link\">" .
4527 $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4533 my $has_history = 0;
4534 my $not_deleted = 0;
4535 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4536 my $hash_parent = $parents[$i];
4537 my $from_hash = $diff->{'from_id'}[$i];
4538 my $from_path = $diff->{'from_file'}[$i];
4539 my $status = $diff->{'status'}[$i];
4541 $has_history ||= ($status ne 'A');
4542 $not_deleted ||= ($status ne 'D');
4544 if ($status eq 'A') {
4545 print "<td class=\"link\" align=\"right\"> | </td>\n";
4546 } elsif ($status eq 'D') {
4547 print "<td class=\"link\">" .
4548 $cgi->a({-href
=> href
(action
=>"blob",
4551 file_name
=>$from_path)},
4555 if ($diff->{'to_id'} eq $from_hash) {
4556 print "<td class=\"link nochange\">";
4558 print "<td class=\"link\">";
4560 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4561 hash
=>$diff->{'to_id'},
4562 hash_parent
=>$from_hash,
4564 hash_parent_base
=>$hash_parent,
4565 file_name
=>$diff->{'to_file'},
4566 file_parent
=>$from_path)},
4572 print "<td class=\"link\">";
4574 print $cgi->a({-href
=> href
(action
=>"blob",
4575 hash
=>$diff->{'to_id'},
4576 file_name
=>$diff->{'to_file'},
4579 print " | " if ($has_history);
4582 print $cgi->a({-href
=> href
(action
=>"history",
4583 file_name
=>$diff->{'to_file'},
4590 next; # instead of 'else' clause, to avoid extra indent
4592 # else ordinary diff
4594 my ($to_mode_oct, $to_mode_str, $to_file_type);
4595 my ($from_mode_oct, $from_mode_str, $from_file_type);
4596 if ($diff->{'to_mode'} ne ('0' x
6)) {
4597 $to_mode_oct = oct $diff->{'to_mode'};
4598 if (S_ISREG
($to_mode_oct)) { # only for regular file
4599 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4601 $to_file_type = file_type
($diff->{'to_mode'});
4603 if ($diff->{'from_mode'} ne ('0' x
6)) {
4604 $from_mode_oct = oct $diff->{'from_mode'};
4605 if (S_ISREG
($from_mode_oct)) { # only for regular file
4606 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4608 $from_file_type = file_type
($diff->{'from_mode'});
4611 if ($diff->{'status'} eq "A") { # created
4612 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4613 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4614 $mode_chng .= "]</span>";
4616 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4617 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4618 -class => "list"}, esc_path
($diff->{'file'}));
4620 print "<td>$mode_chng</td>\n";
4621 print "<td class=\"link\">";
4622 if ($action eq 'commitdiff') {
4625 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4629 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4630 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4634 } elsif ($diff->{'status'} eq "D") { # deleted
4635 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4637 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4638 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4639 -class => "list"}, esc_path
($diff->{'file'}));
4641 print "<td>$mode_chng</td>\n";
4642 print "<td class=\"link\">";
4643 if ($action eq 'commitdiff') {
4646 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4650 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4651 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4654 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4655 file_name
=>$diff->{'file'})},
4658 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4659 file_name
=>$diff->{'file'})},
4663 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4664 my $mode_chnge = "";
4665 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4666 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4667 if ($from_file_type ne $to_file_type) {
4668 $mode_chnge .= " from $from_file_type to $to_file_type";
4670 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4671 if ($from_mode_str && $to_mode_str) {
4672 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4673 } elsif ($to_mode_str) {
4674 $mode_chnge .= " mode: $to_mode_str";
4677 $mode_chnge .= "]</span>\n";
4680 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4681 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4682 -class => "list"}, esc_path
($diff->{'file'}));
4684 print "<td>$mode_chnge</td>\n";
4685 print "<td class=\"link\">";
4686 if ($action eq 'commitdiff') {
4689 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4692 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4693 # "commit" view and modified file (not onlu mode changed)
4694 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4695 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4696 hash_base
=>$hash, hash_parent_base
=>$parent,
4697 file_name
=>$diff->{'file'})},
4701 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4702 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4705 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4706 file_name
=>$diff->{'file'})},
4709 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4710 file_name
=>$diff->{'file'})},
4714 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4715 my %status_name = ('R' => 'moved', 'C' => 'copied');
4716 my $nstatus = $status_name{$diff->{'status'}};
4718 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4719 # mode also for directories, so we cannot use $to_mode_str
4720 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4723 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4724 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4725 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4726 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4727 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4728 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4729 -class => "list"}, esc_path
($diff->{'from_file'})) .
4730 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4731 "<td class=\"link\">";
4732 if ($action eq 'commitdiff') {
4735 print $cgi->a({-href
=> href
(-anchor
=>"patch$patchno")},
4738 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4739 # "commit" view and modified file (not only pure rename or copy)
4740 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4741 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4742 hash_base
=>$hash, hash_parent_base
=>$parent,
4743 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4747 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4748 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4751 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4752 file_name
=>$diff->{'to_file'})},
4755 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4756 file_name
=>$diff->{'to_file'})},
4760 } # we should not encounter Unmerged (U) or Unknown (X) status
4763 print "</tbody>" if $has_header;
4767 sub git_patchset_body
{
4768 my ($fd, $difftree, $hash, @hash_parents) = @_;
4769 my ($hash_parent) = $hash_parents[0];
4771 my $is_combined = (@hash_parents > 1);
4773 my $patch_number = 0;
4779 print "<div class=\"patchset\">\n";
4781 # skip to first patch
4782 while ($patch_line = <$fd>) {
4785 last if ($patch_line =~ m/^diff /);
4789 while ($patch_line) {
4791 # parse "git diff" header line
4792 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4793 # $1 is from_name, which we do not use
4794 $to_name = unquote
($2);
4795 $to_name =~ s!^b/!!;
4796 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4797 # $1 is 'cc' or 'combined', which we do not use
4798 $to_name = unquote
($2);
4803 # check if current patch belong to current raw line
4804 # and parse raw git-diff line if needed
4805 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4806 # this is continuation of a split patch
4807 print "<div class=\"patch cont\">\n";
4809 # advance raw git-diff output if needed
4810 $patch_idx++ if defined $diffinfo;
4812 # read and prepare patch information
4813 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4815 # compact combined diff output can have some patches skipped
4816 # find which patch (using pathname of result) we are at now;
4818 while ($to_name ne $diffinfo->{'to_file'}) {
4819 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4820 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4821 "</div>\n"; # class="patch"
4826 last if $patch_idx > $#$difftree;
4827 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4831 # modifies %from, %to hashes
4832 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4834 # this is first patch for raw difftree line with $patch_idx index
4835 # we index @$difftree array from 0, but number patches from 1
4836 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4840 #assert($patch_line =~ m/^diff /) if DEBUG;
4841 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4843 # print "git diff" header
4844 print format_git_diff_header_line
($patch_line, $diffinfo,
4847 # print extended diff header
4848 print "<div class=\"diff extended_header\">\n";
4850 while ($patch_line = <$fd>) {
4853 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4855 print format_extended_diff_header_line
($patch_line, $diffinfo,
4858 print "</div>\n"; # class="diff extended_header"
4860 # from-file/to-file diff header
4861 if (! $patch_line) {
4862 print "</div>\n"; # class="patch"
4865 next PATCH
if ($patch_line =~ m/^diff /);
4866 #assert($patch_line =~ m/^---/) if DEBUG;
4868 my $last_patch_line = $patch_line;
4869 $patch_line = <$fd>;
4871 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4873 print format_diff_from_to_header
($last_patch_line, $patch_line,
4874 $diffinfo, \
%from, \
%to,
4879 while ($patch_line = <$fd>) {
4882 next PATCH
if ($patch_line =~ m/^diff /);
4884 print format_diff_line
($patch_line, \
%from, \
%to);
4888 print "</div>\n"; # class="patch"
4891 # for compact combined (--cc) format, with chunk and patch simplification
4892 # the patchset might be empty, but there might be unprocessed raw lines
4893 for (++$patch_idx if $patch_number > 0;
4894 $patch_idx < @$difftree;
4896 # read and prepare patch information
4897 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4899 # generate anchor for "patch" links in difftree / whatchanged part
4900 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4901 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4902 "</div>\n"; # class="patch"
4907 if ($patch_number == 0) {
4908 if (@hash_parents > 1) {
4909 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4911 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4915 print "</div>\n"; # class="patchset"
4918 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4920 # fills project list info (age, description, owner, category, forks)
4921 # for each project in the list, removing invalid projects from
4923 # NOTE: modifies $projlist, but does not remove entries from it
4924 sub fill_project_list_info
{
4925 my $projlist = shift;
4928 my $show_ctags = gitweb_check_feature
('ctags');
4930 foreach my $pr (@$projlist) {
4931 my (@activity) = git_get_last_activity
($pr->{'path'});
4932 unless (@activity) {
4935 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4936 if (!defined $pr->{'descr'}) {
4937 my $descr = git_get_project_description
($pr->{'path'}) || "";
4938 $descr = to_utf8
($descr);
4939 $pr->{'descr_long'} = $descr;
4940 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4942 if (!defined $pr->{'owner'}) {
4943 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4946 $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4948 if ($projects_list_group_categories && !defined $pr->{'category'}) {
4949 my $cat = git_get_project_category
($pr->{'path'}) ||
4950 $project_list_default_category;
4951 $pr->{'category'} = to_utf8
($cat);
4954 push @projects, $pr;
4960 sub sort_projects_list
{
4961 my ($projlist, $order) = @_;
4965 project
=> { key
=> 'path', type
=> 'str' },
4966 descr
=> { key
=> 'descr_long', type
=> 'str' },
4967 owner
=> { key
=> 'owner', type
=> 'str' },
4968 age
=> { key
=> 'age', type
=> 'num' }
4970 my $oi = $order_info{$order};
4971 return @$projlist unless defined $oi;
4972 if ($oi->{'type'} eq 'str') {
4973 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projlist;
4975 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projlist;
4981 # returns a hash of categories, containing the list of project
4982 # belonging to each category
4983 sub build_projlist_by_category
{
4984 my ($projlist, $from, $to) = @_;
4987 $from = 0 unless defined $from;
4988 $to = $#$projlist if (!defined $to || $#$projlist < $to);
4990 for (my $i = $from; $i <= $to; $i++) {
4991 my $pr = $projlist->[$i];
4992 push @{$categories{ $pr->{'category'} }}, $pr;
4995 return wantarray ? %categories : \
%categories;
4998 # print 'sort by' <th> element, generating 'sort by $name' replay link
4999 # if that order is not selected
5001 print format_sort_th
(@_);
5004 sub format_sort_th
{
5005 my ($name, $order, $header) = @_;
5007 $header ||= ucfirst($name);
5009 if ($order eq $name) {
5010 $sort_th .= "<th>$header</th>\n";
5012 $sort_th .= "<th>" .
5013 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
5014 -class => "header"}, $header) .
5021 sub git_project_list_rows
{
5022 my ($projlist, $from, $to, $check_forks) = @_;
5024 $from = 0 unless defined $from;
5025 $to = $#$projlist if (!defined $to || $#$projlist < $to);
5028 for (my $i = $from; $i <= $to; $i++) {
5029 my $pr = $projlist->[$i];
5032 print "<tr class=\"dark\">\n";
5034 print "<tr class=\"light\">\n";
5040 if ($pr->{'forks'}) {
5041 my $nforks = scalar @{$pr->{'forks'}};
5043 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks"),
5044 -title
=> "$nforks forks"}, "+");
5046 print $cgi->span({-title
=> "$nforks forks"}, "+");
5051 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
5052 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
5053 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
5054 -class => "list", -title
=> $pr->{'descr_long'}},
5055 esc_html
($pr->{'descr'})) . "</td>\n" .
5056 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
5057 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
5058 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
5059 "<td class=\"link\">" .
5060 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
5061 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
5062 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
5063 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
5064 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
5070 sub git_project_list_body
{
5071 # actually uses global variable $project
5072 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
5073 my @projects = @$projlist;
5075 my $check_forks = gitweb_check_feature
('forks');
5076 my $show_ctags = gitweb_check_feature
('ctags');
5077 my $tagfilter = $show_ctags ? $cgi->param('by_tag') : undef;
5078 $check_forks = undef
5079 if ($tagfilter || $searchtext);
5081 # filtering out forks before filling info allows to do less work
5082 @projects = filter_forks_from_projects_list
(\
@projects)
5084 @projects = fill_project_list_info
(\
@projects);
5085 # searching projects require filling to be run before it
5086 @projects = search_projects_list
(\
@projects,
5087 'searchtext' => $searchtext,
5088 'tagfilter' => $tagfilter)
5089 if ($tagfilter || $searchtext);
5091 $order ||= $default_projects_order;
5092 $from = 0 unless defined $from;
5093 $to = $#projects if (!defined $to || $#projects < $to);
5098 "<b>No such projects found</b><br />\n".
5099 "Click ".$cgi->a({-href
=>href
(project
=>undef)},"here")." to view all projects<br />\n".
5100 "</center>\n<br />\n";
5104 @projects = sort_projects_list
(\
@projects, $order);
5107 my $ctags = git_gather_all_ctags
(\
@projects);
5108 my $cloud = git_populate_project_tagcloud
($ctags);
5109 print git_show_project_tagcloud
($cloud, 64);
5112 print "<table class=\"project_list\">\n";
5113 unless ($no_header) {
5116 print "<th></th>\n";
5118 print_sort_th
('project', $order, 'Project');
5119 print_sort_th
('descr', $order, 'Description');
5120 print_sort_th
('owner', $order, 'Owner');
5121 print_sort_th
('age', $order, 'Last Change');
5122 print "<th></th>\n" . # for links
5126 if ($projects_list_group_categories) {
5127 # only display categories with projects in the $from-$to window
5128 @projects = sort {$a->{'category'} cmp $b->{'category'}} @projects[$from..$to];
5129 my %categories = build_projlist_by_category
(\
@projects, $from, $to);
5130 foreach my $cat (sort keys %categories) {
5131 unless ($cat eq "") {
5134 print "<td></td>\n";
5136 print "<td class=\"category\" colspan=\"5\">".esc_html
($cat)."</td>\n";
5140 git_project_list_rows
($categories{$cat}, undef, undef, $check_forks);
5143 git_project_list_rows
(\
@projects, $from, $to, $check_forks);
5146 if (defined $extra) {
5149 print "<td></td>\n";
5151 print "<td colspan=\"5\">$extra</td>\n" .
5158 # uses global variable $project
5159 my ($commitlist, $from, $to, $refs, $extra) = @_;
5161 $from = 0 unless defined $from;
5162 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5164 for (my $i = 0; $i <= $to; $i++) {
5165 my %co = %{$commitlist->[$i]};
5167 my $commit = $co{'id'};
5168 my $ref = format_ref_marker
($refs, $commit);
5169 git_print_header_div
('commit',
5170 "<span class=\"age\">$co{'age_string'}</span>" .
5171 esc_html
($co{'title'}) . $ref,
5173 print "<div class=\"title_text\">\n" .
5174 "<div class=\"log_link\">\n" .
5175 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5177 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5179 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5182 git_print_authorship
(\
%co, -tag
=> 'span');
5183 print "<br/>\n</div>\n";
5185 print "<div class=\"log_body\">\n";
5186 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5190 print "<div class=\"page_nav\">\n";
5196 sub git_shortlog_body
{
5197 # uses global variable $project
5198 my ($commitlist, $from, $to, $refs, $extra) = @_;
5200 $from = 0 unless defined $from;
5201 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5203 print "<table class=\"shortlog\">\n";
5205 for (my $i = $from; $i <= $to; $i++) {
5206 my %co = %{$commitlist->[$i]};
5207 my $commit = $co{'id'};
5208 my $ref = format_ref_marker
($refs, $commit);
5210 print "<tr class=\"dark\">\n";
5212 print "<tr class=\"light\">\n";
5215 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
5216 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5217 format_author_html
('td', \
%co, 10) . "<td>";
5218 print format_subject_html
($co{'title'}, $co{'title_short'},
5219 href
(action
=>"commit", hash
=>$commit), $ref);
5221 "<td class=\"link\">" .
5222 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
5223 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
5224 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
5225 my $snapshot_links = format_snapshot_links
($commit);
5226 if (defined $snapshot_links) {
5227 print " | " . $snapshot_links;
5232 if (defined $extra) {
5234 "<td colspan=\"4\">$extra</td>\n" .
5240 sub git_history_body
{
5241 # Warning: assumes constant type (blob or tree) during history
5242 my ($commitlist, $from, $to, $refs, $extra,
5243 $file_name, $file_hash, $ftype) = @_;
5245 $from = 0 unless defined $from;
5246 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
5248 print "<table class=\"history\">\n";
5250 for (my $i = $from; $i <= $to; $i++) {
5251 my %co = %{$commitlist->[$i]};
5255 my $commit = $co{'id'};
5257 my $ref = format_ref_marker
($refs, $commit);
5260 print "<tr class=\"dark\">\n";
5262 print "<tr class=\"light\">\n";
5265 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5266 # shortlog: format_author_html('td', \%co, 10)
5267 format_author_html
('td', \
%co, 15, 3) . "<td>";
5268 # originally git_history used chop_str($co{'title'}, 50)
5269 print format_subject_html
($co{'title'}, $co{'title_short'},
5270 href
(action
=>"commit", hash
=>$commit), $ref);
5272 "<td class=\"link\">" .
5273 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
5274 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
5276 if ($ftype eq 'blob') {
5277 my $blob_current = $file_hash;
5278 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
5279 if (defined $blob_current && defined $blob_parent &&
5280 $blob_current ne $blob_parent) {
5282 $cgi->a({-href
=> href
(action
=>"blobdiff",
5283 hash
=>$blob_current, hash_parent
=>$blob_parent,
5284 hash_base
=>$hash_base, hash_parent_base
=>$commit,
5285 file_name
=>$file_name)},
5292 if (defined $extra) {
5294 "<td colspan=\"4\">$extra</td>\n" .
5301 # uses global variable $project
5302 my ($taglist, $from, $to, $extra) = @_;
5303 $from = 0 unless defined $from;
5304 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
5306 print "<table class=\"tags\">\n";
5308 for (my $i = $from; $i <= $to; $i++) {
5309 my $entry = $taglist->[$i];
5311 my $comment = $tag{'subject'};
5313 if (defined $comment) {
5314 $comment_short = chop_str
($comment, 30, 5);
5317 print "<tr class=\"dark\">\n";
5319 print "<tr class=\"light\">\n";
5322 if (defined $tag{'age'}) {
5323 print "<td><i>$tag{'age'}</i></td>\n";
5325 print "<td></td>\n";
5328 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
5329 -class => "list name"}, esc_html
($tag{'name'})) .
5332 if (defined $comment) {
5333 print format_subject_html
($comment, $comment_short,
5334 href
(action
=>"tag", hash
=>$tag{'id'}));
5337 "<td class=\"selflink\">";
5338 if ($tag{'type'} eq "tag") {
5339 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
5344 "<td class=\"link\">" . " | " .
5345 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
5346 if ($tag{'reftype'} eq "commit") {
5347 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
5348 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
5349 } elsif ($tag{'reftype'} eq "blob") {
5350 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
5355 if (defined $extra) {
5357 "<td colspan=\"5\">$extra</td>\n" .
5363 sub git_heads_body
{
5364 # uses global variable $project
5365 my ($headlist, $head, $from, $to, $extra) = @_;
5366 $from = 0 unless defined $from;
5367 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
5369 print "<table class=\"heads\">\n";
5371 for (my $i = $from; $i <= $to; $i++) {
5372 my $entry = $headlist->[$i];
5374 my $curr = $ref{'id'} eq $head;
5376 print "<tr class=\"dark\">\n";
5378 print "<tr class=\"light\">\n";
5381 print "<td><i>$ref{'age'}</i></td>\n" .
5382 ($curr ? "<td class=\"current_head\">" : "<td>") .
5383 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
5384 -class => "list name"},esc_html
($ref{'name'})) .
5386 "<td class=\"link\">" .
5387 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
5388 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
5389 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'fullname'})}, "tree") .
5393 if (defined $extra) {
5395 "<td colspan=\"3\">$extra</td>\n" .
5401 # Display a single remote block
5402 sub git_remote_block
{
5403 my ($remote, $rdata, $limit, $head) = @_;
5405 my $heads = $rdata->{'heads'};
5406 my $fetch = $rdata->{'fetch'};
5407 my $push = $rdata->{'push'};
5409 my $urls_table = "<table class=\"projects_list\">\n" ;
5411 if (defined $fetch) {
5412 if ($fetch eq $push) {
5413 $urls_table .= format_repo_url
("URL", $fetch);
5415 $urls_table .= format_repo_url
("Fetch URL", $fetch);
5416 $urls_table .= format_repo_url
("Push URL", $push) if defined $push;
5418 } elsif (defined $push) {
5419 $urls_table .= format_repo_url
("Push URL", $push);
5421 $urls_table .= format_repo_url
("", "No remote URL");
5424 $urls_table .= "</table>\n";
5427 if (defined $limit && $limit < @$heads) {
5428 $dots = $cgi->a({-href
=> href
(action
=>"remotes", hash
=>$remote)}, "...");
5432 git_heads_body
($heads, $head, 0, $limit, $dots);
5435 # Display a list of remote names with the respective fetch and push URLs
5436 sub git_remotes_list
{
5437 my ($remotedata, $limit) = @_;
5438 print "<table class=\"heads\">\n";
5440 my @remotes = sort keys %$remotedata;
5442 my $limited = $limit && $limit < @remotes;
5444 $#remotes = $limit - 1 if $limited;
5446 while (my $remote = shift @remotes) {
5447 my $rdata = $remotedata->{$remote};
5448 my $fetch = $rdata->{'fetch'};
5449 my $push = $rdata->{'push'};
5451 print "<tr class=\"dark\">\n";
5453 print "<tr class=\"light\">\n";
5457 $cgi->a({-href
=> href
(action
=>'remotes', hash
=>$remote),
5458 -class=> "list name"},esc_html
($remote)) .
5460 print "<td class=\"link\">" .
5461 (defined $fetch ? $cgi->a({-href
=> $fetch}, "fetch") : "fetch") .
5463 (defined $push ? $cgi->a({-href
=> $push}, "push") : "push") .
5471 "<td colspan=\"3\">" .
5472 $cgi->a({-href
=> href
(action
=>"remotes")}, "...") .
5473 "</td>\n" . "</tr>\n";
5479 # Display remote heads grouped by remote, unless there are too many
5480 # remotes, in which case we only display the remote names
5481 sub git_remotes_body
{
5482 my ($remotedata, $limit, $head) = @_;
5483 if ($limit and $limit < keys %$remotedata) {
5484 git_remotes_list
($remotedata, $limit);
5486 fill_remote_heads
($remotedata);
5487 while (my ($remote, $rdata) = each %$remotedata) {
5488 git_print_section
({-class=>"remote", -id
=>$remote},
5489 ["remotes", $remote, $remote], sub {
5490 git_remote_block
($remote, $rdata, $limit, $head);
5496 sub git_search_grep_body
{
5497 my ($commitlist, $from, $to, $extra) = @_;
5498 $from = 0 unless defined $from;
5499 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5501 print "<table class=\"commit_search\">\n";
5503 for (my $i = $from; $i <= $to; $i++) {
5504 my %co = %{$commitlist->[$i]};
5508 my $commit = $co{'id'};
5510 print "<tr class=\"dark\">\n";
5512 print "<tr class=\"light\">\n";
5515 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5516 format_author_html
('td', \
%co, 15, 5) .
5518 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5519 -class => "list subject"},
5520 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5521 my $comment = $co{'comment'};
5522 foreach my $line (@$comment) {
5523 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5524 my ($lead, $match, $trail) = ($1, $2, $3);
5525 $match = chop_str
($match, 70, 5, 'center');
5526 my $contextlen = int((80 - length($match))/2);
5527 $contextlen = 30 if ($contextlen > 30);
5528 $lead = chop_str
($lead, $contextlen, 10, 'left');
5529 $trail = chop_str
($trail, $contextlen, 10, 'right');
5531 $lead = esc_html
($lead);
5532 $match = esc_html
($match);
5533 $trail = esc_html
($trail);
5535 print "$lead<span class=\"match\">$match</span>$trail<br />";
5539 "<td class=\"link\">" .
5540 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5542 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5544 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5548 if (defined $extra) {
5550 "<td colspan=\"3\">$extra</td>\n" .
5556 ## ======================================================================
5557 ## ======================================================================
5560 sub git_project_list
{
5561 my $order = $input_params{'order'};
5562 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5563 die_error
(400, "Unknown order parameter");
5566 my @list = git_get_projects_list
();
5568 die_error
(404, "No projects found");
5572 if (defined $home_text && -f
$home_text) {
5573 print "<div class=\"index_include\">\n";
5574 insert_file
($home_text);
5577 print $cgi->startform(-method => "get") .
5578 "<p class=\"projsearch\">Search:\n" .
5579 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5581 $cgi->end_form() . "\n";
5582 git_project_list_body
(\
@list, $order);
5587 my $order = $input_params{'order'};
5588 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5589 die_error
(400, "Unknown order parameter");
5592 my @list = git_get_projects_list
($project);
5594 die_error
(404, "No forks found");
5598 git_print_page_nav
('','');
5599 git_print_header_div
('summary', "$project forks");
5600 git_project_list_body
(\
@list, $order);
5604 sub git_project_index
{
5605 my @projects = git_get_projects_list
();
5607 die_error
(404, "No projects found");
5611 -type
=> 'text/plain',
5612 -charset
=> 'utf-8',
5613 -content_disposition
=> 'inline; filename="index.aux"');
5615 foreach my $pr (@projects) {
5616 if (!exists $pr->{'owner'}) {
5617 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5620 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5621 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5622 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5623 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5627 print "$path $owner\n";
5632 my $descr = git_get_project_description
($project) || "none";
5633 my %co = parse_commit
("HEAD");
5634 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5635 my $head = $co{'id'};
5636 my $remote_heads = gitweb_check_feature
('remote_heads');
5638 my $owner = git_get_project_owner
($project);
5640 my $refs = git_get_references
();
5641 # These get_*_list functions return one more to allow us to see if
5642 # there are more ...
5643 my @taglist = git_get_tags_list
(16);
5644 my @headlist = git_get_heads_list
(16);
5645 my %remotedata = $remote_heads ? git_get_remotes_list
() : ();
5647 my $check_forks = gitweb_check_feature
('forks');
5650 # find forks of a project
5651 @forklist = git_get_projects_list
($project);
5652 # filter out forks of forks
5653 @forklist = filter_forks_from_projects_list
(\
@forklist)
5658 git_print_page_nav
('summary','', $head);
5660 print "<div class=\"title\"> </div>\n";
5661 print "<table class=\"projects_list\">\n" .
5662 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5663 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5664 if (defined $cd{'rfc2822'}) {
5665 print "<tr id=\"metadata_lchange\"><td>last change</td>" .
5666 "<td>".format_timestamp_html
(\
%cd)."</td></tr>\n";
5669 # use per project git URL list in $projectroot/$project/cloneurl
5670 # or make project git URL from git base URL and project name
5671 my $url_tag = "URL";
5672 my @url_list = git_get_project_url_list
($project);
5673 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5674 foreach my $git_url (@url_list) {
5675 next unless $git_url;
5676 print format_repo_url
($url_tag, $git_url);
5681 my $show_ctags = gitweb_check_feature
('ctags');
5683 my $ctags = git_get_project_ctags
($project);
5685 # without ability to add tags, don't show if there are none
5686 my $cloud = git_populate_project_tagcloud
($ctags);
5687 print "<tr id=\"metadata_ctags\">" .
5688 "<td>content tags</td>" .
5689 "<td>".git_show_project_tagcloud
($cloud, 48)."</td>" .
5696 # If XSS prevention is on, we don't include README.html.
5697 # TODO: Allow a readme in some safe format.
5698 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5699 print "<div class=\"title\">readme</div>\n" .
5700 "<div class=\"readme\">\n";
5701 insert_file
("$projectroot/$project/README.html");
5702 print "\n</div>\n"; # class="readme"
5705 # we need to request one more than 16 (0..15) to check if
5707 my @commitlist = $head ? parse_commits
($head, 17) : ();
5709 git_print_header_div
('shortlog');
5710 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5711 $#commitlist <= 15 ? undef :
5712 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5716 git_print_header_div
('tags');
5717 git_tags_body
(\
@taglist, 0, 15,
5718 $#taglist <= 15 ? undef :
5719 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5723 git_print_header_div
('heads');
5724 git_heads_body
(\
@headlist, $head, 0, 15,
5725 $#headlist <= 15 ? undef :
5726 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5730 git_print_header_div
('remotes');
5731 git_remotes_body
(\
%remotedata, 15, $head);
5735 git_print_header_div
('forks');
5736 git_project_list_body
(\
@forklist, 'age', 0, 15,
5737 $#forklist <= 15 ? undef :
5738 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5746 my %tag = parse_tag
($hash);
5749 die_error
(404, "Unknown tag object");
5752 my $head = git_get_head_hash
($project);
5754 git_print_page_nav
('','', $head,undef,$head);
5755 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5756 print "<div class=\"title_text\">\n" .
5757 "<table class=\"object_header\">\n" .
5759 "<td>object</td>\n" .
5760 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5761 $tag{'object'}) . "</td>\n" .
5762 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5763 $tag{'type'}) . "</td>\n" .
5765 if (defined($tag{'author'})) {
5766 git_print_authorship_rows
(\
%tag, 'author');
5768 print "</table>\n\n" .
5770 print "<div class=\"page_body\">";
5771 my $comment = $tag{'comment'};
5772 foreach my $line (@$comment) {
5774 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5780 sub git_blame_common
{
5781 my $format = shift || 'porcelain';
5782 if ($format eq 'porcelain' && $cgi->param('js')) {
5783 $format = 'incremental';
5784 $action = 'blame_incremental'; # for page title etc
5788 gitweb_check_feature
('blame')
5789 or die_error
(403, "Blame view not allowed");
5792 die_error
(400, "No file name given") unless $file_name;
5793 $hash_base ||= git_get_head_hash
($project);
5794 die_error
(404, "Couldn't find base commit") unless $hash_base;
5795 my %co = parse_commit
($hash_base)
5796 or die_error
(404, "Commit not found");
5798 if (!defined $hash) {
5799 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5800 or die_error
(404, "Error looking up file");
5802 $ftype = git_get_type
($hash);
5803 if ($ftype !~ "blob") {
5804 die_error
(400, "Object is not a blob");
5809 if ($format eq 'incremental') {
5810 # get file contents (as base)
5811 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5812 or die_error
(500, "Open git-cat-file failed");
5813 } elsif ($format eq 'data') {
5814 # run git-blame --incremental
5815 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5816 $hash_base, "--", $file_name
5817 or die_error
(500, "Open git-blame --incremental failed");
5819 # run git-blame --porcelain
5820 open $fd, "-|", git_cmd
(), "blame", '-p',
5821 $hash_base, '--', $file_name
5822 or die_error
(500, "Open git-blame --porcelain failed");
5825 # incremental blame data returns early
5826 if ($format eq 'data') {
5828 -type
=>"text/plain", -charset
=> "utf-8",
5829 -status
=> "200 OK");
5830 local $| = 1; # output autoflush
5833 or print "ERROR $!\n";
5836 if (defined $t0 && gitweb_check_feature
('timed')) {
5838 tv_interval
($t0, [ gettimeofday
() ]).
5839 ' '.$number_of_git_cmds;
5849 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5852 if ($format eq 'incremental') {
5854 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5855 "blame") . " (non-incremental)";
5858 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5859 "blame") . " (incremental)";
5863 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5866 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5868 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5869 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5870 git_print_page_path
($file_name, $ftype, $hash_base);
5873 if ($format eq 'incremental') {
5874 print "<noscript>\n<div class=\"error\"><center><b>\n".
5875 "This page requires JavaScript to run.\n Use ".
5876 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5879 "</b></center></div>\n</noscript>\n";
5881 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5884 print qq
!<div
class="page_body">\n!;
5885 print qq
!<div id
="progress_info">... / ...</div
>\n!
5886 if ($format eq 'incremental');
5887 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5888 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5890 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5894 my @rev_color = qw(light dark);
5895 my $num_colors = scalar(@rev_color);
5896 my $current_color = 0;
5898 if ($format eq 'incremental') {
5899 my $color_class = $rev_color[$current_color];
5904 while (my $line = <$fd>) {
5908 print qq
!<tr id
="l$linenr" class="$color_class">!.
5909 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5910 qq
!<td
class="linenr">!.
5911 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5912 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5916 } else { # porcelain, i.e. ordinary blame
5917 my %metainfo = (); # saves information about commits
5921 while (my $line = <$fd>) {
5923 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5924 # no <lines in group> for subsequent lines in group of lines
5925 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5926 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5927 if (!exists $metainfo{$full_rev}) {
5928 $metainfo{$full_rev} = { 'nprevious' => 0 };
5930 my $meta = $metainfo{$full_rev};
5932 while ($data = <$fd>) {
5934 last if ($data =~ s/^\t//); # contents of line
5935 if ($data =~ /^(\S+)(?: (.*))?$/) {
5936 $meta->{$1} = $2 unless exists $meta->{$1};
5938 if ($data =~ /^previous /) {
5939 $meta->{'nprevious'}++;
5942 my $short_rev = substr($full_rev, 0, 8);
5943 my $author = $meta->{'author'};
5945 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5946 my $date = $date{'iso-tz'};
5948 $current_color = ($current_color + 1) % $num_colors;
5950 my $tr_class = $rev_color[$current_color];
5951 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5952 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5953 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5954 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5956 print "<td class=\"sha1\"";
5957 print " title=\"". esc_html
($author) . ", $date\"";
5958 print " rowspan=\"$group_size\"" if ($group_size > 1);
5960 print $cgi->a({-href
=> href
(action
=>"commit",
5962 file_name
=>$file_name)},
5963 esc_html
($short_rev));
5964 if ($group_size >= 2) {
5965 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5966 if (@author_initials) {
5968 esc_html
(join('', @author_initials));
5974 # 'previous' <sha1 of parent commit> <filename at commit>
5975 if (exists $meta->{'previous'} &&
5976 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5977 $meta->{'parent'} = $1;
5978 $meta->{'file_parent'} = unquote
($2);
5981 exists($meta->{'parent'}) ?
5982 $meta->{'parent'} : $full_rev;
5983 my $linenr_filename =
5984 exists($meta->{'file_parent'}) ?
5985 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5986 my $blamed = href
(action
=> 'blame',
5987 file_name
=> $linenr_filename,
5988 hash_base
=> $linenr_commit);
5989 print "<td class=\"linenr\">";
5990 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5991 -class => "linenr" },
5994 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
6002 "</table>\n"; # class="blame"
6003 print "</div>\n"; # class="blame_body"
6005 or print "Reading blob failed\n";
6014 sub git_blame_incremental
{
6015 git_blame_common
('incremental');
6018 sub git_blame_data
{
6019 git_blame_common
('data');
6023 my $head = git_get_head_hash
($project);
6025 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('tags'));
6026 git_print_header_div
('summary', $project);
6028 my @tagslist = git_get_tags_list
();
6030 git_tags_body
(\
@tagslist);
6036 my $head = git_get_head_hash
($project);
6038 git_print_page_nav
('','', $head,undef,$head,format_ref_views
('heads'));
6039 git_print_header_div
('summary', $project);
6041 my @headslist = git_get_heads_list
();
6043 git_heads_body
(\
@headslist, $head);
6048 # used both for single remote view and for list of all the remotes
6050 gitweb_check_feature
('remote_heads')
6051 or die_error
(403, "Remote heads view is disabled");
6053 my $head = git_get_head_hash
($project);
6054 my $remote = $input_params{'hash'};
6056 my $remotedata = git_get_remotes_list
($remote);
6057 die_error
(500, "Unable to get remote information") unless defined $remotedata;
6059 unless (%$remotedata) {
6060 die_error
(404, defined $remote ?
6061 "Remote $remote not found" :
6062 "No remotes found");
6065 git_header_html
(undef, undef, -action_extra
=> $remote);
6066 git_print_page_nav
('', '', $head, undef, $head,
6067 format_ref_views
($remote ? '' : 'remotes'));
6069 fill_remote_heads
($remotedata);
6070 if (defined $remote) {
6071 git_print_header_div
('remotes', "$remote remote for $project");
6072 git_remote_block
($remote, $remotedata->{$remote}, undef, $head);
6074 git_print_header_div
('summary', "$project remotes");
6075 git_remotes_body
($remotedata, undef, $head);
6081 sub git_blob_plain
{
6085 if (!defined $hash) {
6086 if (defined $file_name) {
6087 my $base = $hash_base || git_get_head_hash
($project);
6088 $hash = git_get_hash_by_path
($base, $file_name, "blob")
6089 or die_error
(404, "Cannot find file");
6091 die_error
(400, "No file name defined");
6093 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6094 # blobs defined by non-textual hash id's can be cached
6098 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
6099 or die_error
(500, "Open git-cat-file blob '$hash' failed");
6101 # content-type (can include charset)
6102 $type = blob_contenttype
($fd, $file_name, $type);
6104 # "save as" filename, even when no $file_name is given
6105 my $save_as = "$hash";
6106 if (defined $file_name) {
6107 $save_as = $file_name;
6108 } elsif ($type =~ m/^text\//) {
6112 # With XSS prevention on, blobs of all types except a few known safe
6113 # ones are served with "Content-Disposition: attachment" to make sure
6114 # they don't run in our security domain. For certain image types,
6115 # blob view writes an <img> tag referring to blob_plain view, and we
6116 # want to be sure not to break that by serving the image as an
6117 # attachment (though Firefox 3 doesn't seem to care).
6118 my $sandbox = $prevent_xss &&
6119 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
6123 -expires
=> $expires,
6124 -content_disposition
=>
6125 ($sandbox ? 'attachment' : 'inline')
6126 . '; filename="' . $save_as . '"');
6128 binmode STDOUT
, ':raw';
6130 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
6137 if (!defined $hash) {
6138 if (defined $file_name) {
6139 my $base = $hash_base || git_get_head_hash
($project);
6140 $hash = git_get_hash_by_path
($base, $file_name, "blob")
6141 or die_error
(404, "Cannot find file");
6143 die_error
(400, "No file name defined");
6145 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6146 # blobs defined by non-textual hash id's can be cached
6150 my $have_blame = gitweb_check_feature
('blame');
6151 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
6152 or die_error
(500, "Couldn't cat $file_name, $hash");
6153 my $mimetype = blob_mimetype
($fd, $file_name);
6154 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
6155 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
6157 return git_blob_plain
($mimetype);
6159 # we can have blame only for text/* mimetype
6160 $have_blame &&= ($mimetype =~ m!^text/!);
6162 my $highlight = gitweb_check_feature
('highlight');
6163 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
6164 $fd = run_highlighter
($fd, $highlight, $syntax)
6167 git_header_html
(undef, $expires);
6168 my $formats_nav = '';
6169 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6170 if (defined $file_name) {
6173 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
6178 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
6181 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
6184 $cgi->a({-href
=> href
(action
=>"blob",
6185 hash_base
=>"HEAD", file_name
=>$file_name)},
6189 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
6192 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6193 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6195 print "<div class=\"page_nav\">\n" .
6196 "<br/><br/></div>\n" .
6197 "<div class=\"title\">".esc_html
($hash)."</div>\n";
6199 git_print_page_path
($file_name, "blob", $hash_base);
6200 print "<div class=\"page_body\">\n";
6201 if ($mimetype =~ m!^image/!) {
6202 print qq
!<img type
="!.esc_attr($mimetype).qq!"!;
6204 print qq
! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
6207 href(action=>"blob_plain
", hash=>$hash,
6208 hash_base=>$hash_base, file_name=>$file_name) .
6212 while (my $line = <$fd>) {
6215 $line = untabify
($line);
6216 printf qq
!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
6217 $nr, href
(-replay
=> 1), $nr, $nr, $syntax ? $line : esc_html
($line, -nbsp
=>1);
6221 or print "Reading blob failed.\n";
6227 if (!defined $hash_base) {
6228 $hash_base = "HEAD";
6230 if (!defined $hash) {
6231 if (defined $file_name) {
6232 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
6237 die_error
(404, "No such tree") unless defined($hash);
6239 my $show_sizes = gitweb_check_feature
('show-sizes');
6240 my $have_blame = gitweb_check_feature
('blame');
6245 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
6246 ($show_sizes ? '-l' : ()), @extra_options, $hash
6247 or die_error
(500, "Open git-ls-tree failed");
6248 @entries = map { chomp; $_ } <$fd>;
6250 or die_error
(404, "Reading tree failed");
6253 my $refs = git_get_references
();
6254 my $ref = format_ref_marker
($refs, $hash_base);
6257 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6259 if (defined $file_name) {
6261 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
6263 $cgi->a({-href
=> href
(action
=>"tree",
6264 hash_base
=>"HEAD", file_name
=>$file_name)},
6267 my $snapshot_links = format_snapshot_links
($hash);
6268 if (defined $snapshot_links) {
6269 # FIXME: Should be available when we have no hash base as well.
6270 push @views_nav, $snapshot_links;
6272 git_print_page_nav
('tree','', $hash_base, undef, undef,
6273 join(' | ', @views_nav));
6274 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
6277 print "<div class=\"page_nav\">\n";
6278 print "<br/><br/></div>\n";
6279 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
6281 if (defined $file_name) {
6282 $basedir = $file_name;
6283 if ($basedir ne '' && substr($basedir, -1) ne '/') {
6286 git_print_page_path
($file_name, 'tree', $hash_base);
6288 print "<div class=\"page_body\">\n";
6289 print "<table class=\"tree\">\n";
6291 # '..' (top directory) link if possible
6292 if (defined $hash_base &&
6293 defined $file_name && $file_name =~ m![^/]+$!) {
6295 print "<tr class=\"dark\">\n";
6297 print "<tr class=\"light\">\n";
6301 my $up = $file_name;
6302 $up =~ s!/?[^/]+$!!;
6303 undef $up unless $up;
6304 # based on git_print_tree_entry
6305 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
6306 print '<td class="size"> </td>'."\n" if $show_sizes;
6307 print '<td class="list">';
6308 print $cgi->a({-href
=> href
(action
=>"tree",
6309 hash_base
=>$hash_base,
6313 print "<td class=\"link\"></td>\n";
6317 foreach my $line (@entries) {
6318 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
6321 print "<tr class=\"dark\">\n";
6323 print "<tr class=\"light\">\n";
6327 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
6331 print "</table>\n" .
6337 my ($project, $hash) = @_;
6339 # path/to/project.git -> project
6340 # path/to/project/.git -> project
6341 my $name = to_utf8
($project);
6342 $name =~ s
,([^/])/*\
.git
$,$1,;
6343 $name = basename
($name);
6345 $name =~ s/[[:cntrl:]]/?/g;
6348 if ($hash =~ /^[0-9a-fA-F]+$/) {
6349 # shorten SHA-1 hash
6350 my $full_hash = git_get_full_hash
($project, $hash);
6351 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
6352 $ver = git_get_short_hash
($project, $hash);
6354 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
6355 # tags don't need shortened SHA-1 hash
6358 # branches and other need shortened SHA-1 hash
6359 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
6362 $ver .= '-' . git_get_short_hash
($project, $hash);
6364 # in case of hierarchical branch names
6367 # name = project-version_string
6368 $name = "$name-$ver";
6370 return wantarray ? ($name, $name) : $name;
6374 my $format = $input_params{'snapshot_format'};
6375 if (!@snapshot_fmts) {
6376 die_error
(403, "Snapshots not allowed");
6378 # default to first supported snapshot format
6379 $format ||= $snapshot_fmts[0];
6380 if ($format !~ m/^[a-z0-9]+$/) {
6381 die_error
(400, "Invalid snapshot format parameter");
6382 } elsif (!exists($known_snapshot_formats{$format})) {
6383 die_error
(400, "Unknown snapshot format");
6384 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
6385 die_error
(403, "Snapshot format not allowed");
6386 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
6387 die_error
(403, "Unsupported snapshot format");
6390 my $type = git_get_type
("$hash^{}");
6392 die_error
(404, 'Object does not exist');
6393 } elsif ($type eq 'blob') {
6394 die_error
(400, 'Object is not a tree-ish');
6397 my ($name, $prefix) = snapshot_name
($project, $hash);
6398 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
6399 my $cmd = quote_command
(
6400 git_cmd
(), 'archive',
6401 "--format=$known_snapshot_formats{$format}{'format'}",
6402 "--prefix=$prefix/", $hash);
6403 if (exists $known_snapshot_formats{$format}{'compressor'}) {
6404 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
6407 $filename =~ s/(["\\])/\\$1/g;
6409 -type
=> $known_snapshot_formats{$format}{'type'},
6410 -content_disposition
=> 'inline; filename="' . $filename . '"',
6411 -status
=> '200 OK');
6413 open my $fd, "-|", $cmd
6414 or die_error
(500, "Execute git-archive failed");
6415 binmode STDOUT
, ':raw';
6417 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
6421 sub git_log_generic
{
6422 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
6424 my $head = git_get_head_hash
($project);
6425 if (!defined $base) {
6428 if (!defined $page) {
6431 my $refs = git_get_references
();
6433 my $commit_hash = $base;
6434 if (defined $parent) {
6435 $commit_hash = "$parent..$base";
6438 parse_commits
($commit_hash, 101, (100 * $page),
6439 defined $file_name ? ($file_name, "--full-history") : ());
6442 if (!defined $file_hash && defined $file_name) {
6443 # some commits could have deleted file in question,
6444 # and not have it in tree, but one of them has to have it
6445 for (my $i = 0; $i < @commitlist; $i++) {
6446 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
6447 last if defined $file_hash;
6450 if (defined $file_hash) {
6451 $ftype = git_get_type
($file_hash);
6453 if (defined $file_name && !defined $ftype) {
6454 die_error
(500, "Unknown type of object");
6457 if (defined $file_name) {
6458 %co = parse_commit
($base)
6459 or die_error
(404, "Unknown commit object");
6463 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
6465 if ($#commitlist >= 100) {
6467 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6468 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6470 my $patch_max = gitweb_get_feature
('patches');
6471 if ($patch_max && !defined $file_name) {
6472 if ($patch_max < 0 || @commitlist <= $patch_max) {
6473 $paging_nav .= " ⋅ " .
6474 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6480 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
6481 if (defined $file_name) {
6482 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
6484 git_print_header_div
('summary', $project)
6486 git_print_page_path
($file_name, $ftype, $hash_base)
6487 if (defined $file_name);
6489 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
6490 $file_name, $file_hash, $ftype);
6496 git_log_generic
('log', \
&git_log_body
,
6497 $hash, $hash_parent);
6501 $hash ||= $hash_base || "HEAD";
6502 my %co = parse_commit
($hash)
6503 or die_error
(404, "Unknown commit object");
6505 my $parent = $co{'parent'};
6506 my $parents = $co{'parents'}; # listref
6508 # we need to prepare $formats_nav before any parameter munging
6510 if (!defined $parent) {
6512 $formats_nav .= '(initial)';
6513 } elsif (@$parents == 1) {
6514 # single parent commit
6517 $cgi->a({-href
=> href
(action
=>"commit",
6519 esc_html
(substr($parent, 0, 7))) .
6526 $cgi->a({-href
=> href
(action
=>"commit",
6528 esc_html
(substr($_, 0, 7)));
6532 if (gitweb_check_feature
('patches') && @$parents <= 1) {
6533 $formats_nav .= " | " .
6534 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6538 if (!defined $parent) {
6542 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
6544 (@$parents <= 1 ? $parent : '-c'),
6546 or die_error
(500, "Open git-diff-tree failed");
6547 @difftree = map { chomp; $_ } <$fd>;
6548 close $fd or die_error
(404, "Reading git-diff-tree failed");
6550 # non-textual hash id's can be cached
6552 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6555 my $refs = git_get_references
();
6556 my $ref = format_ref_marker
($refs, $co{'id'});
6558 git_header_html
(undef, $expires);
6559 git_print_page_nav
('commit', '',
6560 $hash, $co{'tree'}, $hash,
6563 if (defined $co{'parent'}) {
6564 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
6566 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
6568 print "<div class=\"title_text\">\n" .
6569 "<table class=\"object_header\">\n";
6570 git_print_authorship_rows
(\
%co);
6571 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6574 "<td class=\"sha1\">" .
6575 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6576 class => "list"}, $co{'tree'}) .
6578 "<td class=\"link\">" .
6579 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6581 my $snapshot_links = format_snapshot_links
($hash);
6582 if (defined $snapshot_links) {
6583 print " | " . $snapshot_links;
6588 foreach my $par (@$parents) {
6591 "<td class=\"sha1\">" .
6592 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6593 class => "list"}, $par) .
6595 "<td class=\"link\">" .
6596 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6598 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6605 print "<div class=\"page_body\">\n";
6606 git_print_log
($co{'comment'});
6609 git_difftree_body
(\
@difftree, $hash, @$parents);
6615 # object is defined by:
6616 # - hash or hash_base alone
6617 # - hash_base and file_name
6620 # - hash or hash_base alone
6621 if ($hash || ($hash_base && !defined $file_name)) {
6622 my $object_id = $hash || $hash_base;
6624 open my $fd, "-|", quote_command
(
6625 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6626 or die_error
(404, "Object does not exist");
6630 or die_error
(404, "Object does not exist");
6632 # - hash_base and file_name
6633 } elsif ($hash_base && defined $file_name) {
6634 $file_name =~ s
,/+$,,;
6636 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6637 or die_error
(404, "Base object does not exist");
6639 # here errors should not hapen
6640 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6641 or die_error
(500, "Open git-ls-tree failed");
6645 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6646 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6647 die_error
(404, "File or directory for given base does not exist");
6652 die_error
(400, "Not enough information to find object");
6655 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6656 hash
=>$hash, hash_base
=>$hash_base,
6657 file_name
=>$file_name),
6658 -status
=> '302 Found');
6662 my $format = shift || 'html';
6669 # preparing $fd and %diffinfo for git_patchset_body
6671 if (defined $hash_base && defined $hash_parent_base) {
6672 if (defined $file_name) {
6674 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6675 $hash_parent_base, $hash_base,
6676 "--", (defined $file_parent ? $file_parent : ()), $file_name
6677 or die_error
(500, "Open git-diff-tree failed");
6678 @difftree = map { chomp; $_ } <$fd>;
6680 or die_error
(404, "Reading git-diff-tree failed");
6682 or die_error
(404, "Blob diff not found");
6684 } elsif (defined $hash &&
6685 $hash =~ /[0-9a-fA-F]{40}/) {
6686 # try to find filename from $hash
6688 # read filtered raw output
6689 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6690 $hash_parent_base, $hash_base, "--"
6691 or die_error
(500, "Open git-diff-tree failed");
6693 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6695 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6696 map { chomp; $_ } <$fd>;
6698 or die_error
(404, "Reading git-diff-tree failed");
6700 or die_error
(404, "Blob diff not found");
6703 die_error
(400, "Missing one of the blob diff parameters");
6706 if (@difftree > 1) {
6707 die_error
(400, "Ambiguous blob diff specification");
6710 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6711 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6712 $file_name ||= $diffinfo{'to_file'};
6714 $hash_parent ||= $diffinfo{'from_id'};
6715 $hash ||= $diffinfo{'to_id'};
6717 # non-textual hash id's can be cached
6718 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6719 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6724 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6725 '-p', ($format eq 'html' ? "--full-index" : ()),
6726 $hash_parent_base, $hash_base,
6727 "--", (defined $file_parent ? $file_parent : ()), $file_name
6728 or die_error
(500, "Open git-diff-tree failed");
6731 # old/legacy style URI -- not generated anymore since 1.4.3.
6733 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6737 if ($format eq 'html') {
6739 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6741 git_header_html
(undef, $expires);
6742 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6743 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6744 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6746 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6747 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
6749 if (defined $file_name) {
6750 git_print_page_path
($file_name, "blob", $hash_base);
6752 print "<div class=\"page_path\"></div>\n";
6755 } elsif ($format eq 'plain') {
6757 -type
=> 'text/plain',
6758 -charset
=> 'utf-8',
6759 -expires
=> $expires,
6760 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6762 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6765 die_error
(400, "Unknown blobdiff format");
6769 if ($format eq 'html') {
6770 print "<div class=\"page_body\">\n";
6772 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6775 print "</div>\n"; # class="page_body"
6779 while (my $line = <$fd>) {
6780 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6781 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6785 last if $line =~ m!^\+\+\+!;
6793 sub git_blobdiff_plain
{
6794 git_blobdiff
('plain');
6797 sub git_commitdiff
{
6799 my $format = $params{-format
} || 'html';
6801 my ($patch_max) = gitweb_get_feature
('patches');
6802 if ($format eq 'patch') {
6803 die_error
(403, "Patch view not allowed") unless $patch_max;
6806 $hash ||= $hash_base || "HEAD";
6807 my %co = parse_commit
($hash)
6808 or die_error
(404, "Unknown commit object");
6810 # choose format for commitdiff for merge
6811 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
6812 $hash_parent = '--cc';
6814 # we need to prepare $formats_nav before almost any parameter munging
6816 if ($format eq 'html') {
6818 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6820 if ($patch_max && @{$co{'parents'}} <= 1) {
6821 $formats_nav .= " | " .
6822 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6826 if (defined $hash_parent &&
6827 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6828 # commitdiff with two commits given
6829 my $hash_parent_short = $hash_parent;
6830 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6831 $hash_parent_short = substr($hash_parent, 0, 7);
6835 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
6836 if ($co{'parents'}[$i] eq $hash_parent) {
6837 $formats_nav .= ' parent ' . ($i+1);
6841 $formats_nav .= ': ' .
6842 $cgi->a({-href
=> href
(action
=>"commitdiff",
6843 hash
=>$hash_parent)},
6844 esc_html
($hash_parent_short)) .
6846 } elsif (!$co{'parent'}) {
6848 $formats_nav .= ' (initial)';
6849 } elsif (scalar @{$co{'parents'}} == 1) {
6850 # single parent commit
6853 $cgi->a({-href
=> href
(action
=>"commitdiff",
6854 hash
=>$co{'parent'})},
6855 esc_html
(substr($co{'parent'}, 0, 7))) .
6859 if ($hash_parent eq '--cc') {
6860 $formats_nav .= ' | ' .
6861 $cgi->a({-href
=> href
(action
=>"commitdiff",
6862 hash
=>$hash, hash_parent
=>'-c')},
6864 } else { # $hash_parent eq '-c'
6865 $formats_nav .= ' | ' .
6866 $cgi->a({-href
=> href
(action
=>"commitdiff",
6867 hash
=>$hash, hash_parent
=>'--cc')},
6873 $cgi->a({-href
=> href
(action
=>"commitdiff",
6875 esc_html
(substr($_, 0, 7)));
6876 } @{$co{'parents'}} ) .
6881 my $hash_parent_param = $hash_parent;
6882 if (!defined $hash_parent_param) {
6883 # --cc for multiple parents, --root for parentless
6884 $hash_parent_param =
6885 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6891 if ($format eq 'html') {
6892 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6893 "--no-commit-id", "--patch-with-raw", "--full-index",
6894 $hash_parent_param, $hash, "--"
6895 or die_error
(500, "Open git-diff-tree failed");
6897 while (my $line = <$fd>) {
6899 # empty line ends raw part of diff-tree output
6901 push @difftree, scalar parse_difftree_raw_line
($line);
6904 } elsif ($format eq 'plain') {
6905 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6906 '-p', $hash_parent_param, $hash, "--"
6907 or die_error
(500, "Open git-diff-tree failed");
6908 } elsif ($format eq 'patch') {
6909 # For commit ranges, we limit the output to the number of
6910 # patches specified in the 'patches' feature.
6911 # For single commits, we limit the output to a single patch,
6912 # diverging from the git-format-patch default.
6913 my @commit_spec = ();
6915 if ($patch_max > 0) {
6916 push @commit_spec, "-$patch_max";
6918 push @commit_spec, '-n', "$hash_parent..$hash";
6920 if ($params{-single
}) {
6921 push @commit_spec, '-1';
6923 if ($patch_max > 0) {
6924 push @commit_spec, "-$patch_max";
6926 push @commit_spec, "-n";
6928 push @commit_spec, '--root', $hash;
6930 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6931 '--encoding=utf8', '--stdout', @commit_spec
6932 or die_error
(500, "Open git-format-patch failed");
6934 die_error
(400, "Unknown commitdiff format");
6937 # non-textual hash id's can be cached
6939 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6943 # write commit message
6944 if ($format eq 'html') {
6945 my $refs = git_get_references
();
6946 my $ref = format_ref_marker
($refs, $co{'id'});
6948 git_header_html
(undef, $expires);
6949 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6950 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6951 print "<div class=\"title_text\">\n" .
6952 "<table class=\"object_header\">\n";
6953 git_print_authorship_rows
(\
%co);
6956 print "<div class=\"page_body\">\n";
6957 if (@{$co{'comment'}} > 1) {
6958 print "<div class=\"log\">\n";
6959 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6960 print "</div>\n"; # class="log"
6963 } elsif ($format eq 'plain') {
6964 my $refs = git_get_references
("tags");
6965 my $tagname = git_get_rev_name_tags
($hash);
6966 my $filename = basename
($project) . "-$hash.patch";
6969 -type
=> 'text/plain',
6970 -charset
=> 'utf-8',
6971 -expires
=> $expires,
6972 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6973 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6974 print "From: " . to_utf8
($co{'author'}) . "\n";
6975 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6976 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6978 print "X-Git-Tag: $tagname\n" if $tagname;
6979 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6981 foreach my $line (@{$co{'comment'}}) {
6982 print to_utf8
($line) . "\n";
6985 } elsif ($format eq 'patch') {
6986 my $filename = basename
($project) . "-$hash.patch";
6989 -type
=> 'text/plain',
6990 -charset
=> 'utf-8',
6991 -expires
=> $expires,
6992 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6996 if ($format eq 'html') {
6997 my $use_parents = !defined $hash_parent ||
6998 $hash_parent eq '-c' || $hash_parent eq '--cc';
6999 git_difftree_body
(\
@difftree, $hash,
7000 $use_parents ? @{$co{'parents'}} : $hash_parent);
7003 git_patchset_body
($fd, \
@difftree, $hash,
7004 $use_parents ? @{$co{'parents'}} : $hash_parent);
7006 print "</div>\n"; # class="page_body"
7009 } elsif ($format eq 'plain') {
7013 or print "Reading git-diff-tree failed\n";
7014 } elsif ($format eq 'patch') {
7018 or print "Reading git-format-patch failed\n";
7022 sub git_commitdiff_plain
{
7023 git_commitdiff
(-format
=> 'plain');
7026 # format-patch-style patches
7028 git_commitdiff
(-format
=> 'patch', -single
=> 1);
7032 git_commitdiff
(-format
=> 'patch');
7036 git_log_generic
('history', \
&git_history_body
,
7037 $hash_base, $hash_parent_base,
7042 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
7043 if (!defined $searchtext) {
7044 die_error
(400, "Text field is empty");
7046 if (!defined $hash) {
7047 $hash = git_get_head_hash
($project);
7049 my %co = parse_commit
($hash);
7051 die_error
(404, "Unknown commit object");
7053 if (!defined $page) {
7057 $searchtype ||= 'commit';
7058 if ($searchtype eq 'pickaxe') {
7059 # pickaxe may take all resources of your box and run for several minutes
7060 # with every query - so decide by yourself how public you make this feature
7061 gitweb_check_feature
('pickaxe')
7062 or die_error
(403, "Pickaxe is disabled");
7064 if ($searchtype eq 'grep') {
7065 gitweb_check_feature
('grep')[0]
7066 or die_error
(403, "Grep is disabled");
7071 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
7073 if ($searchtype eq 'commit') {
7074 $greptype = "--grep=";
7075 } elsif ($searchtype eq 'author') {
7076 $greptype = "--author=";
7077 } elsif ($searchtype eq 'committer') {
7078 $greptype = "--committer=";
7080 $greptype .= $searchtext;
7081 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
7082 $greptype, '--regexp-ignore-case',
7083 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
7085 my $paging_nav = '';
7088 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
7089 searchtext
=>$searchtext,
7090 searchtype
=>$searchtype)},
7092 $paging_nav .= " ⋅ " .
7093 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
7094 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
7096 $paging_nav .= "first";
7097 $paging_nav .= " ⋅ prev";
7100 if ($#commitlist >= 100) {
7102 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
7103 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
7104 $paging_nav .= " ⋅ $next_link";
7106 $paging_nav .= " ⋅ next";
7109 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
7110 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
7111 if ($page == 0 && !@commitlist) {
7112 print "<p>No match.</p>\n";
7114 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
7118 if ($searchtype eq 'pickaxe') {
7119 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
7120 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
7122 print "<table class=\"pickaxe search\">\n";
7125 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
7126 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
7127 ($search_use_regexp ? '--pickaxe-regex' : ());
7130 while (my $line = <$fd>) {
7134 my %set = parse_difftree_raw_line
($line);
7135 if (defined $set{'commit'}) {
7136 # finish previous commit
7139 "<td class=\"link\">" .
7140 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
7142 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
7148 print "<tr class=\"dark\">\n";
7150 print "<tr class=\"light\">\n";
7153 %co = parse_commit
($set{'commit'});
7154 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
7155 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
7156 "<td><i>$author</i></td>\n" .
7158 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
7159 -class => "list subject"},
7160 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
7161 } elsif (defined $set{'to_id'}) {
7162 next if ($set{'to_id'} =~ m/^0{40}$/);
7164 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
7165 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
7167 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
7173 # finish last commit (warning: repetition!)
7176 "<td class=\"link\">" .
7177 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
7179 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
7187 if ($searchtype eq 'grep') {
7188 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
7189 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
7191 print "<table class=\"grep_search\">\n";
7195 open my $fd, "-|", git_cmd
(), 'grep', '-n',
7196 $search_use_regexp ? ('-E', '-i') : '-F',
7197 $searchtext, $co{'tree'};
7199 while (my $line = <$fd>) {
7201 my ($file, $lno, $ltext, $binary);
7202 last if ($matches++ > 1000);
7203 if ($line =~ /^Binary file (.+) matches$/) {
7207 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
7209 if ($file ne $lastfile) {
7210 $lastfile and print "</td></tr>\n";
7212 print "<tr class=\"dark\">\n";
7214 print "<tr class=\"light\">\n";
7216 print "<td class=\"list\">".
7217 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
7218 file_name
=>"$file"),
7219 -class => "list"}, esc_path
($file));
7220 print "</td><td>\n";
7224 print "<div class=\"binary\">Binary file</div>\n";
7226 $ltext = untabify
($ltext);
7227 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
7228 $ltext = esc_html
($1, -nbsp
=>1);
7229 $ltext .= '<span class="match">';
7230 $ltext .= esc_html
($2, -nbsp
=>1);
7231 $ltext .= '</span>';
7232 $ltext .= esc_html
($3, -nbsp
=>1);
7234 $ltext = esc_html
($ltext, -nbsp
=>1);
7236 print "<div class=\"pre\">" .
7237 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
7238 file_name
=>"$file").'#l'.$lno,
7239 -class => "linenr"}, sprintf('%4i', $lno))
7240 . ' ' . $ltext . "</div>\n";
7244 print "</td></tr>\n";
7245 if ($matches > 1000) {
7246 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
7249 print "<div class=\"diff nodifferences\">No matches found</div>\n";
7258 sub git_search_help
{
7260 git_print_page_nav
('','', $hash,$hash,$hash);
7262 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
7263 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
7264 the pattern entered is recognized as the POSIX extended
7265 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
7268 <dt><b>commit</b></dt>
7269 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
7271 my $have_grep = gitweb_check_feature
('grep');
7274 <dt><b>grep</b></dt>
7275 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
7276 a different one) are searched for the given pattern. On large trees, this search can take
7277 a while and put some strain on the server, so please use it with some consideration. Note that
7278 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
7279 case-sensitive.</dd>
7283 <dt><b>author</b></dt>
7284 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
7285 <dt><b>committer</b></dt>
7286 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
7288 my $have_pickaxe = gitweb_check_feature
('pickaxe');
7289 if ($have_pickaxe) {
7291 <dt><b>pickaxe</b></dt>
7292 <dd>All commits that caused the string to appear or disappear from any file (changes that
7293 added, removed or "modified" the string) will be listed. This search can take a while and
7294 takes a lot of strain on the server, so please use it wisely. Note that since you may be
7295 interested even in changes just changing the case as well, this search is case sensitive.</dd>
7303 git_log_generic
('shortlog', \
&git_shortlog_body
,
7304 $hash, $hash_parent);
7307 ## ......................................................................
7308 ## feeds (RSS, Atom; OPML)
7311 my $format = shift || 'atom';
7312 my $have_blame = gitweb_check_feature
('blame');
7314 # Atom: http://www.atomenabled.org/developers/syndication/
7315 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
7316 if ($format ne 'rss' && $format ne 'atom') {
7317 die_error
(400, "Unknown web feed format");
7320 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
7321 my $head = $hash || 'HEAD';
7322 my @commitlist = parse_commits
($head, 150, 0, $file_name);
7326 my $content_type = "application/$format+xml";
7327 if (defined $cgi->http('HTTP_ACCEPT') &&
7328 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
7329 # browser (feed reader) prefers text/xml
7330 $content_type = 'text/xml';
7332 if (defined($commitlist[0])) {
7333 %latest_commit = %{$commitlist[0]};
7334 my $latest_epoch = $latest_commit{'committer_epoch'};
7335 %latest_date = parse_date
($latest_epoch, $latest_commit{'comitter_tz'});
7336 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
7337 if (defined $if_modified) {
7339 if (eval { require HTTP
::Date
; 1; }) {
7340 $since = HTTP
::Date
::str2time
($if_modified);
7341 } elsif (eval { require Time
::ParseDate
; 1; }) {
7342 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
7344 if (defined $since && $latest_epoch <= $since) {
7346 -type
=> $content_type,
7347 -charset
=> 'utf-8',
7348 -last_modified
=> $latest_date{'rfc2822'},
7349 -status
=> '304 Not Modified');
7354 -type
=> $content_type,
7355 -charset
=> 'utf-8',
7356 -last_modified
=> $latest_date{'rfc2822'});
7359 -type
=> $content_type,
7360 -charset
=> 'utf-8');
7363 # Optimization: skip generating the body if client asks only
7364 # for Last-Modified date.
7365 return if ($cgi->request_method() eq 'HEAD');
7368 my $title = "$site_name - $project/$action";
7369 my $feed_type = 'log';
7370 if (defined $hash) {
7371 $title .= " - '$hash'";
7372 $feed_type = 'branch log';
7373 if (defined $file_name) {
7374 $title .= " :: $file_name";
7375 $feed_type = 'history';
7377 } elsif (defined $file_name) {
7378 $title .= " - $file_name";
7379 $feed_type = 'history';
7381 $title .= " $feed_type";
7382 my $descr = git_get_project_description
($project);
7383 if (defined $descr) {
7384 $descr = esc_html
($descr);
7386 $descr = "$project " .
7387 ($format eq 'rss' ? 'RSS' : 'Atom') .
7390 my $owner = git_get_project_owner
($project);
7391 $owner = esc_html
($owner);
7395 if (defined $file_name) {
7396 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
7397 } elsif (defined $hash) {
7398 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
7400 $alt_url = href
(-full
=>1, action
=>"summary");
7402 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
7403 if ($format eq 'rss') {
7405 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
7408 print "<title>$title</title>\n" .
7409 "<link>$alt_url</link>\n" .
7410 "<description>$descr</description>\n" .
7411 "<language>en</language>\n" .
7412 # project owner is responsible for 'editorial' content
7413 "<managingEditor>$owner</managingEditor>\n";
7414 if (defined $logo || defined $favicon) {
7415 # prefer the logo to the favicon, since RSS
7416 # doesn't allow both
7417 my $img = esc_url
($logo || $favicon);
7419 "<url>$img</url>\n" .
7420 "<title>$title</title>\n" .
7421 "<link>$alt_url</link>\n" .
7425 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
7426 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
7428 print "<generator>gitweb v.$version/$git_version</generator>\n";
7429 } elsif ($format eq 'atom') {
7431 <feed xmlns="http://www.w3.org/2005/Atom">
7433 print "<title>$title</title>\n" .
7434 "<subtitle>$descr</subtitle>\n" .
7435 '<link rel="alternate" type="text/html" href="' .
7436 $alt_url . '" />' . "\n" .
7437 '<link rel="self" type="' . $content_type . '" href="' .
7438 $cgi->self_url() . '" />' . "\n" .
7439 "<id>" . href
(-full
=>1) . "</id>\n" .
7440 # use project owner for feed author
7441 "<author><name>$owner</name></author>\n";
7442 if (defined $favicon) {
7443 print "<icon>" . esc_url
($favicon) . "</icon>\n";
7445 if (defined $logo) {
7446 # not twice as wide as tall: 72 x 27 pixels
7447 print "<logo>" . esc_url
($logo) . "</logo>\n";
7449 if (! %latest_date) {
7450 # dummy date to keep the feed valid until commits trickle in:
7451 print "<updated>1970-01-01T00:00:00Z</updated>\n";
7453 print "<updated>$latest_date{'iso-8601'}</updated>\n";
7455 print "<generator version='$version/$git_version'>gitweb</generator>\n";
7459 for (my $i = 0; $i <= $#commitlist; $i++) {
7460 my %co = %{$commitlist[$i]};
7461 my $commit = $co{'id'};
7462 # we read 150, we always show 30 and the ones more recent than 48 hours
7463 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
7466 my %cd = parse_date
($co{'author_epoch'}, $co{'author_tz'});
7468 # get list of changed files
7469 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
7470 $co{'parent'} || "--root",
7471 $co{'id'}, "--", (defined $file_name ? $file_name : ())
7473 my @difftree = map { chomp; $_ } <$fd>;
7477 # print element (entry, item)
7478 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
7479 if ($format eq 'rss') {
7481 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
7482 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
7483 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
7484 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
7485 "<link>$co_url</link>\n" .
7486 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
7487 "<content:encoded>" .
7489 } elsif ($format eq 'atom') {
7491 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
7492 "<updated>$cd{'iso-8601'}</updated>\n" .
7494 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
7495 if ($co{'author_email'}) {
7496 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
7498 print "</author>\n" .
7499 # use committer for contributor
7501 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
7502 if ($co{'committer_email'}) {
7503 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
7505 print "</contributor>\n" .
7506 "<published>$cd{'iso-8601'}</published>\n" .
7507 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
7508 "<id>$co_url</id>\n" .
7509 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
7510 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
7512 my $comment = $co{'comment'};
7514 foreach my $line (@$comment) {
7515 $line = esc_html
($line);
7518 print "</pre><ul>\n";
7519 foreach my $difftree_line (@difftree) {
7520 my %difftree = parse_difftree_raw_line
($difftree_line);
7521 next if !$difftree{'from_id'};
7523 my $file = $difftree{'file'} || $difftree{'to_file'};
7527 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
7528 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
7529 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
7530 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
7531 -title
=> "diff"}, 'D');
7533 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
7534 file_name
=>$file, hash_base
=>$commit),
7535 -title
=> "blame"}, 'B');
7537 # if this is not a feed of a file history
7538 if (!defined $file_name || $file_name ne $file) {
7539 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
7540 file_name
=>$file, hash
=>$commit),
7541 -title
=> "history"}, 'H');
7543 $file = esc_path
($file);
7547 if ($format eq 'rss') {
7548 print "</ul>]]>\n" .
7549 "</content:encoded>\n" .
7551 } elsif ($format eq 'atom') {
7552 print "</ul>\n</div>\n" .
7559 if ($format eq 'rss') {
7560 print "</channel>\n</rss>\n";
7561 } elsif ($format eq 'atom') {
7575 my @list = git_get_projects_list
();
7577 die_error
(404, "No projects found");
7581 -type
=> 'text/xml',
7582 -charset
=> 'utf-8',
7583 -content_disposition
=> 'inline; filename="opml.xml"');
7586 <?xml version="1.0" encoding="utf-8"?>
7587 <opml version="1.0">
7589 <title>$site_name OPML Export</title>
7592 <outline text="git RSS feeds">
7595 foreach my $pr (@list) {
7597 my $head = git_get_head_hash
($proj{'path'});
7598 if (!defined $head) {
7601 $git_dir = "$projectroot/$proj{'path'}";
7602 my %co = parse_commit
($head);
7607 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7608 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7609 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7610 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";