3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
13 use CGI
qw(:standard :escapeHTML -nosticky);
14 use CGI
::Util
qw(unescape);
15 use CGI
::Carp
qw(fatalsToBrowser set_message);
19 use File
::Basename
qw(basename);
20 binmode STDOUT
, ':utf8';
23 if (eval { require Time
::HiRes
; 1; }) {
24 $t0 = [Time
::HiRes
::gettimeofday
()];
26 our $number_of_git_cmds = 0;
29 CGI-
>compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
34 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
38 our $my_url = $cgi->url();
39 our $my_uri = $cgi->url(-absolute
=> 1);
41 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
42 # needed and used only for URLs with nonempty PATH_INFO
43 our $base_url = $my_url;
45 # When the script is used as DirectoryIndex, the URL does not contain the name
46 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
47 # have to do it ourselves. We make $path_info global because it's also used
50 # Another issue with the script being the DirectoryIndex is that the resulting
51 # $my_url data is not the full script URL: this is good, because we want
52 # generated links to keep implying the script name if it wasn't explicitly
53 # indicated in the URL we're handling, but it means that $my_url cannot be used
55 # Therefore, if we needed to strip PATH_INFO, then we know that we have
56 # to build the base URL ourselves:
57 our $path_info = $ENV{"PATH_INFO"};
59 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
60 $my_uri =~ s
,\Q
$path_info\E
$,, &&
61 defined $ENV{'SCRIPT_NAME'}) {
62 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
66 # target of the home link on top of all pages
67 our $home_link = $my_uri || "/";
70 # core git executable to use
71 # this can just be "git" if your webserver has a sensible PATH
72 our $GIT = "++GIT_BINDIR++/git";
74 # absolute fs-path which will be prepended to the project path
75 #our $projectroot = "/pub/scm";
76 our $projectroot = "++GITWEB_PROJECTROOT++";
78 # fs traversing limit for getting project list
79 # the number is relative to the projectroot
80 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
82 # string of the home link on top of all pages
83 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
85 # name of your site or organization to appear in page titles
86 # replace this with something more descriptive for clearer bookmarks
87 our $site_name = "++GITWEB_SITENAME++"
88 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
90 # filename of html text to include at top of each page
91 our $site_header = "++GITWEB_SITE_HEADER++";
92 # html text to include at home page
93 our $home_text = "++GITWEB_HOMETEXT++";
94 # filename of html text to include at bottom of each page
95 our $site_footer = "++GITWEB_SITE_FOOTER++";
98 our @stylesheets = ("++GITWEB_CSS++");
99 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
100 our $stylesheet = undef;
102 # URI of GIT logo (72x27 size)
103 our $logo = "++GITWEB_LOGO++";
104 # URI of GIT favicon, assumed to be image/png type
105 our $favicon = "++GITWEB_FAVICON++";
106 # URI of gitweb.js (JavaScript code for gitweb)
107 our $javascript = "++GITWEB_JS++";
109 # URI and label (title) of GIT logo link
110 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
111 #our $logo_label = "git documentation";
112 our $logo_url = "http://git-scm.com/";
113 our $logo_label = "git homepage";
115 # source of projects list
116 our $projects_list = "++GITWEB_LIST++";
118 # the width (in characters) of the projects list "Description" column
119 our $projects_list_description_width = 25;
121 # default order of projects list
122 # valid values are none, project, descr, owner, and age
123 our $default_projects_order = "project";
125 # show repository only if this file exists
126 # (only effective if this variable evaluates to true)
127 our $export_ok = "++GITWEB_EXPORT_OK++";
129 # show repository only if this subroutine returns true
130 # when given the path to the project, for example:
131 # sub { return -e "$_[0]/git-daemon-export-ok"; }
132 our $export_auth_hook = undef;
134 # only allow viewing of repositories also shown on the overview page
135 our $strict_export = "++GITWEB_STRICT_EXPORT++";
137 # list of git base URLs used for URL to where fetch project from,
138 # i.e. full URL is "$git_base_url/$project"
139 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
141 # default blob_plain mimetype and default charset for text/plain blob
142 our $default_blob_plain_mimetype = 'text/plain';
143 our $default_text_plain_charset = undef;
145 # file to use for guessing MIME types before trying /etc/mime.types
146 # (relative to the current git repository)
147 our $mimetypes_file = undef;
149 # assume this charset if line contains non-UTF-8 characters;
150 # it should be valid encoding (see Encoding::Supported(3pm) for list),
151 # for which encoding all byte sequences are valid, for example
152 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
153 # could be even 'utf-8' for the old behavior)
154 our $fallback_encoding = 'latin1';
156 # rename detection options for git-diff and git-diff-tree
157 # - default is '-M', with the cost proportional to
158 # (number of removed files) * (number of new files).
159 # - more costly is '-C' (which implies '-M'), with the cost proportional to
160 # (number of changed files + number of removed files) * (number of new files)
161 # - even more costly is '-C', '--find-copies-harder' with cost
162 # (number of files in the original tree) * (number of new files)
163 # - one might want to include '-B' option, e.g. '-B', '-M'
164 our @diff_opts = ('-M'); # taken from git_commit
166 # Disables features that would allow repository owners to inject script into
168 our $prevent_xss = 0;
170 # Path to the highlight executable to use (must be the one from
171 # http://www.andre-simon.de due to assumptions about parameters and output).
172 # Useful if highlight is not installed on your webserver's PATH.
173 # [Default: highlight]
174 our $highlight_bin = "++HIGHLIGHT_BIN++";
176 # information about snapshot formats that gitweb is capable of serving
177 our %known_snapshot_formats = (
179 # 'display' => display name,
180 # 'type' => mime type,
181 # 'suffix' => filename suffix,
182 # 'format' => --format for git-archive,
183 # 'compressor' => [compressor command and arguments]
184 # (array reference, optional)
185 # 'disabled' => boolean (optional)}
188 'display' => 'tar.gz',
189 'type' => 'application/x-gzip',
190 'suffix' => '.tar.gz',
192 'compressor' => ['gzip']},
195 'display' => 'tar.bz2',
196 'type' => 'application/x-bzip2',
197 'suffix' => '.tar.bz2',
199 'compressor' => ['bzip2']},
202 'display' => 'tar.xz',
203 'type' => 'application/x-xz',
204 'suffix' => '.tar.xz',
206 'compressor' => ['xz'],
211 'type' => 'application/x-zip',
216 # Aliases so we understand old gitweb.snapshot values in repository
218 our %known_snapshot_format_aliases = (
223 # backward compatibility: legacy gitweb config support
224 'x-gzip' => undef, 'gz' => undef,
225 'x-bzip2' => undef, 'bz2' => undef,
226 'x-zip' => undef, '' => undef,
229 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
230 # are changed, it may be appropriate to change these values too via
237 # Used to set the maximum load that we will still respond to gitweb queries.
238 # If server load exceed this value then return "503 server busy" error.
239 # If gitweb cannot determined server load, it is taken to be 0.
240 # Leave it undefined (or set to 'undef') to turn off load checking.
243 # configuration for 'highlight' (http://www.andre-simon.de/)
245 our %highlight_basename = (
248 'SConstruct' => 'py', # SCons equivalent of Makefile
249 'Makefile' => 'make',
252 our %highlight_ext = (
253 # main extensions, defining name of syntax;
254 # see files in /usr/share/highlight/langDefs/ directory
256 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
257 # alternate extensions, see /etc/highlight/filetypes.conf
259 map { $_ => 'cpp' } qw(cxx c++ cc),
260 map { $_ => 'php' } qw(php3 php4),
261 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
263 map { $_ => 'xml' } qw(xhtml html htm),
266 # You define site-wide feature defaults here; override them with
267 # $GITWEB_CONFIG as necessary.
270 # 'sub' => feature-sub (subroutine),
271 # 'override' => allow-override (boolean),
272 # 'default' => [ default options...] (array reference)}
274 # if feature is overridable (it means that allow-override has true value),
275 # then feature-sub will be called with default options as parameters;
276 # return value of feature-sub indicates if to enable specified feature
278 # if there is no 'sub' key (no feature-sub), then feature cannot be
281 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
282 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
285 # Enable the 'blame' blob view, showing the last commit that modified
286 # each line in the file. This can be very CPU-intensive.
288 # To enable system wide have in $GITWEB_CONFIG
289 # $feature{'blame'}{'default'} = [1];
290 # To have project specific config enable override in $GITWEB_CONFIG
291 # $feature{'blame'}{'override'} = 1;
292 # and in project config gitweb.blame = 0|1;
294 'sub' => sub { feature_bool
('blame', @_) },
298 # Enable the 'snapshot' link, providing a compressed archive of any
299 # tree. This can potentially generate high traffic if you have large
302 # Value is a list of formats defined in %known_snapshot_formats that
304 # To disable system wide have in $GITWEB_CONFIG
305 # $feature{'snapshot'}{'default'} = [];
306 # To have project specific config enable override in $GITWEB_CONFIG
307 # $feature{'snapshot'}{'override'} = 1;
308 # and in project config, a comma-separated list of formats or "none"
309 # to disable. Example: gitweb.snapshot = tbz2,zip;
311 'sub' => \
&feature_snapshot
,
313 'default' => ['tgz']},
315 # Enable text search, which will list the commits which match author,
316 # committer or commit text to a given string. Enabled by default.
317 # Project specific override is not supported.
322 # Enable grep search, which will list the files in currently selected
323 # tree containing the given string. Enabled by default. This can be
324 # potentially CPU-intensive, of course.
326 # To enable system wide have in $GITWEB_CONFIG
327 # $feature{'grep'}{'default'} = [1];
328 # To have project specific config enable override in $GITWEB_CONFIG
329 # $feature{'grep'}{'override'} = 1;
330 # and in project config gitweb.grep = 0|1;
332 'sub' => sub { feature_bool
('grep', @_) },
336 # Enable the pickaxe search, which will list the commits that modified
337 # a given string in a file. This can be practical and quite faster
338 # alternative to 'blame', but still potentially CPU-intensive.
340 # To enable system wide have in $GITWEB_CONFIG
341 # $feature{'pickaxe'}{'default'} = [1];
342 # To have project specific config enable override in $GITWEB_CONFIG
343 # $feature{'pickaxe'}{'override'} = 1;
344 # and in project config gitweb.pickaxe = 0|1;
346 'sub' => sub { feature_bool
('pickaxe', @_) },
350 # Enable showing size of blobs in a 'tree' view, in a separate
351 # column, similar to what 'ls -l' does. This cost a bit of IO.
353 # To disable system wide have in $GITWEB_CONFIG
354 # $feature{'show-sizes'}{'default'} = [0];
355 # To have project specific config enable override in $GITWEB_CONFIG
356 # $feature{'show-sizes'}{'override'} = 1;
357 # and in project config gitweb.showsizes = 0|1;
359 'sub' => sub { feature_bool
('showsizes', @_) },
363 # Make gitweb use an alternative format of the URLs which can be
364 # more readable and natural-looking: project name is embedded
365 # directly in the path and the query string contains other
366 # auxiliary information. All gitweb installations recognize
367 # URL in either format; this configures in which formats gitweb
370 # To enable system wide have in $GITWEB_CONFIG
371 # $feature{'pathinfo'}{'default'} = [1];
372 # Project specific override is not supported.
374 # Note that you will need to change the default location of CSS,
375 # favicon, logo and possibly other files to an absolute URL. Also,
376 # if gitweb.cgi serves as your indexfile, you will need to force
377 # $my_uri to contain the script name in your $GITWEB_CONFIG.
382 # Make gitweb consider projects in project root subdirectories
383 # to be forks of existing projects. Given project $projname.git,
384 # projects matching $projname/*.git will not be shown in the main
385 # projects list, instead a '+' mark will be added to $projname
386 # there and a 'forks' view will be enabled for the project, listing
387 # all the forks. If project list is taken from a file, forks have
388 # to be listed after the main project.
390 # To enable system wide have in $GITWEB_CONFIG
391 # $feature{'forks'}{'default'} = [1];
392 # Project specific override is not supported.
397 # Insert custom links to the action bar of all project pages.
398 # This enables you mainly to link to third-party scripts integrating
399 # into gitweb; e.g. git-browser for graphical history representation
400 # or custom web-based repository administration interface.
402 # The 'default' value consists of a list of triplets in the form
403 # (label, link, position) where position is the label after which
404 # to insert the link and link is a format string where %n expands
405 # to the project name, %f to the project path within the filesystem,
406 # %h to the current hash (h gitweb parameter) and %b to the current
407 # hash base (hb gitweb parameter); %% expands to %.
409 # To enable system wide have in $GITWEB_CONFIG e.g.
410 # $feature{'actions'}{'default'} = [('graphiclog',
411 # '/git-browser/by-commit.html?r=%n', 'summary')];
412 # Project specific override is not supported.
417 # Allow gitweb scan project content tags described in ctags/
418 # of project repository, and display the popular Web 2.0-ish
419 # "tag cloud" near the project list. Note that this is something
420 # COMPLETELY different from the normal Git tags.
422 # gitweb by itself can show existing tags, but it does not handle
423 # tagging itself; you need an external application for that.
424 # For an example script, check Girocco's cgi/tagproj.cgi.
425 # You may want to install the HTML::TagCloud Perl module to get
426 # a pretty tag cloud instead of just a list of tags.
428 # To enable system wide have in $GITWEB_CONFIG
429 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
430 # Project specific override is not supported.
435 # The maximum number of patches in a patchset generated in patch
436 # view. Set this to 0 or undef to disable patch view, or to a
437 # negative number to remove any limit.
439 # To disable system wide have in $GITWEB_CONFIG
440 # $feature{'patches'}{'default'} = [0];
441 # To have project specific config enable override in $GITWEB_CONFIG
442 # $feature{'patches'}{'override'} = 1;
443 # and in project config gitweb.patches = 0|n;
444 # where n is the maximum number of patches allowed in a patchset.
446 'sub' => \
&feature_patches
,
450 # Avatar support. When this feature is enabled, views such as
451 # shortlog or commit will display an avatar associated with
452 # the email of the committer(s) and/or author(s).
454 # Currently available providers are gravatar and picon.
455 # If an unknown provider is specified, the feature is disabled.
457 # Gravatar depends on Digest::MD5.
458 # Picon currently relies on the indiana.edu database.
460 # To enable system wide have in $GITWEB_CONFIG
461 # $feature{'avatar'}{'default'} = ['<provider>'];
462 # where <provider> is either gravatar or picon.
463 # To have project specific config enable override in $GITWEB_CONFIG
464 # $feature{'avatar'}{'override'} = 1;
465 # and in project config gitweb.avatar = <provider>;
467 'sub' => \
&feature_avatar
,
471 # Enable displaying how much time and how many git commands
472 # it took to generate and display page. Disabled by default.
473 # Project specific override is not supported.
478 # Enable turning some links into links to actions which require
479 # JavaScript to run (like 'blame_incremental'). Not enabled by
480 # default. Project specific override is currently not supported.
481 'javascript-actions' => {
485 # Syntax highlighting support. This is based on Daniel Svensson's
486 # and Sham Chukoury's work in gitweb-xmms2.git.
487 # It requires the 'highlight' program present in $PATH,
488 # and therefore is disabled by default.
490 # To enable system wide have in $GITWEB_CONFIG
491 # $feature{'highlight'}{'default'} = [1];
494 'sub' => sub { feature_bool
('highlight', @_) },
499 sub gitweb_get_feature
{
501 return unless exists $feature{$name};
502 my ($sub, $override, @defaults) = (
503 $feature{$name}{'sub'},
504 $feature{$name}{'override'},
505 @{$feature{$name}{'default'}});
506 # project specific override is possible only if we have project
507 our $git_dir; # global variable, declared later
508 if (!$override || !defined $git_dir) {
512 warn "feature $name is not overridable";
515 return $sub->(@defaults);
518 # A wrapper to check if a given feature is enabled.
519 # With this, you can say
521 # my $bool_feat = gitweb_check_feature('bool_feat');
522 # gitweb_check_feature('bool_feat') or somecode;
526 # my ($bool_feat) = gitweb_get_feature('bool_feat');
527 # (gitweb_get_feature('bool_feat'))[0] or somecode;
529 sub gitweb_check_feature
{
530 return (gitweb_get_feature
(@_))[0];
536 my ($val) = git_get_project_config
($key, '--bool');
540 } elsif ($val eq 'true') {
542 } elsif ($val eq 'false') {
547 sub feature_snapshot
{
550 my ($val) = git_get_project_config
('snapshot');
553 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
559 sub feature_patches
{
560 my @val = (git_get_project_config
('patches', '--int'));
570 my @val = (git_get_project_config
('avatar'));
572 return @val ? @val : @_;
575 # checking HEAD file with -e is fragile if the repository was
576 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
578 sub check_head_link
{
580 my $headfile = "$dir/HEAD";
581 return ((-e
$headfile) ||
582 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
585 sub check_export_ok
{
587 return (check_head_link
($dir) &&
588 (!$export_ok || -e
"$dir/$export_ok") &&
589 (!$export_auth_hook || $export_auth_hook->($dir)));
592 # process alternate names for backward compatibility
593 # filter out unsupported (unknown) snapshot formats
594 sub filter_snapshot_fmts
{
598 exists $known_snapshot_format_aliases{$_} ?
599 $known_snapshot_format_aliases{$_} : $_} @fmts;
601 exists $known_snapshot_formats{$_} &&
602 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
605 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
606 sub evaluate_gitweb_config
{
607 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
608 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
609 # die if there are errors parsing config file
610 if (-e
$GITWEB_CONFIG) {
613 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
614 do $GITWEB_CONFIG_SYSTEM;
619 # Get loadavg of system, to compare against $maxload.
620 # Currently it requires '/proc/loadavg' present to get loadavg;
621 # if it is not present it returns 0, which means no load checking.
623 if( -e
'/proc/loadavg' ){
624 open my $fd, '<', '/proc/loadavg'
626 my @load = split(/\s+/, scalar <$fd>);
629 # The first three columns measure CPU and IO utilization of the last one,
630 # five, and 10 minute periods. The fourth column shows the number of
631 # currently running processes and the total number of processes in the m/n
632 # format. The last column displays the last process ID used.
633 return $load[0] || 0;
635 # additional checks for load average should go here for things that don't export
641 # version of the core git binary
643 sub evaluate_git_version
{
644 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
645 $number_of_git_cmds++;
649 if (defined $maxload && get_loadavg
() > $maxload) {
650 die_error
(503, "The load average on the server is too high");
654 # ======================================================================
655 # input validation and dispatch
657 # input parameters can be collected from a variety of sources (presently, CGI
658 # and PATH_INFO), so we define an %input_params hash that collects them all
659 # together during validation: this allows subsequent uses (e.g. href()) to be
660 # agnostic of the parameter origin
662 our %input_params = ();
664 # input parameters are stored with the long parameter name as key. This will
665 # also be used in the href subroutine to convert parameters to their CGI
666 # equivalent, and since the href() usage is the most frequent one, we store
667 # the name -> CGI key mapping here, instead of the reverse.
669 # XXX: Warning: If you touch this, check the search form for updating,
672 our @cgi_param_mapping = (
680 hash_parent_base
=> "hpb",
685 snapshot_format
=> "sf",
686 extra_options
=> "opt",
687 search_use_regexp
=> "sr",
688 # this must be last entry (for manipulation from JavaScript)
691 our %cgi_param_mapping = @cgi_param_mapping;
693 # we will also need to know the possible actions, for validation
695 "blame" => \
&git_blame
,
696 "blame_incremental" => \
&git_blame_incremental
,
697 "blame_data" => \
&git_blame_data
,
698 "blobdiff" => \
&git_blobdiff
,
699 "blobdiff_plain" => \
&git_blobdiff_plain
,
700 "blob" => \
&git_blob
,
701 "blob_plain" => \
&git_blob_plain
,
702 "commitdiff" => \
&git_commitdiff
,
703 "commitdiff_plain" => \
&git_commitdiff_plain
,
704 "commit" => \
&git_commit
,
705 "forks" => \
&git_forks
,
706 "heads" => \
&git_heads
,
707 "history" => \
&git_history
,
709 "patch" => \
&git_patch
,
710 "patches" => \
&git_patches
,
712 "atom" => \
&git_atom
,
713 "search" => \
&git_search
,
714 "search_help" => \
&git_search_help
,
715 "shortlog" => \
&git_shortlog
,
716 "summary" => \
&git_summary
,
718 "tags" => \
&git_tags
,
719 "tree" => \
&git_tree
,
720 "snapshot" => \
&git_snapshot
,
721 "object" => \
&git_object
,
722 # those below don't need $project
723 "opml" => \
&git_opml
,
724 "project_list" => \
&git_project_list
,
725 "project_index" => \
&git_project_index
,
728 # finally, we have the hash of allowed extra_options for the commands that
730 our %allowed_options = (
731 "--no-merges" => [ qw(rss atom log shortlog history) ],
734 # fill %input_params with the CGI parameters. All values except for 'opt'
735 # should be single values, but opt can be an array. We should probably
736 # build an array of parameters that can be multi-valued, but since for the time
737 # being it's only this one, we just single it out
738 sub evaluate_query_params
{
741 while (my ($name, $symbol) = each %cgi_param_mapping) {
742 if ($symbol eq 'opt') {
743 $input_params{$name} = [ $cgi->param($symbol) ];
745 $input_params{$name} = $cgi->param($symbol);
750 # now read PATH_INFO and update the parameter list for missing parameters
751 sub evaluate_path_info
{
752 return if defined $input_params{'project'};
753 return if !$path_info;
754 $path_info =~ s
,^/+,,;
755 return if !$path_info;
757 # find which part of PATH_INFO is project
758 my $project = $path_info;
760 while ($project && !check_head_link
("$projectroot/$project")) {
761 $project =~ s
,/*[^/]*$,,;
763 return unless $project;
764 $input_params{'project'} = $project;
766 # do not change any parameters if an action is given using the query string
767 return if $input_params{'action'};
768 $path_info =~ s
,^\Q
$project\E
/*,,;
770 # next, check if we have an action
771 my $action = $path_info;
773 if (exists $actions{$action}) {
774 $path_info =~ s
,^$action/*,,;
775 $input_params{'action'} = $action;
778 # list of actions that want hash_base instead of hash, but can have no
779 # pathname (f) parameter
785 # we want to catch, among others
786 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
787 my ($parentrefname, $parentpathname, $refname, $pathname) =
788 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?([^:]+?)?(?::(.+))?$/);
790 # first, analyze the 'current' part
791 if (defined $pathname) {
792 # we got "branch:filename" or "branch:dir/"
793 # we could use git_get_type(branch:pathname), but:
794 # - it needs $git_dir
795 # - it does a git() call
796 # - the convention of terminating directories with a slash
797 # makes it superfluous
798 # - embedding the action in the PATH_INFO would make it even
800 $pathname =~ s
,^/+,,;
801 if (!$pathname || substr($pathname, -1) eq "/") {
802 $input_params{'action'} ||= "tree";
805 # the default action depends on whether we had parent info
807 if ($parentrefname) {
808 $input_params{'action'} ||= "blobdiff_plain";
810 $input_params{'action'} ||= "blob_plain";
813 $input_params{'hash_base'} ||= $refname;
814 $input_params{'file_name'} ||= $pathname;
815 } elsif (defined $refname) {
816 # we got "branch". In this case we have to choose if we have to
817 # set hash or hash_base.
819 # Most of the actions without a pathname only want hash to be
820 # set, except for the ones specified in @wants_base that want
821 # hash_base instead. It should also be noted that hand-crafted
822 # links having 'history' as an action and no pathname or hash
823 # set will fail, but that happens regardless of PATH_INFO.
824 if (defined $parentrefname) {
825 # if there is parent let the default be 'shortlog' action
826 # (for http://git.example.com/repo.git/A..B links); if there
827 # is no parent, dispatch will detect type of object and set
828 # action appropriately if required (if action is not set)
829 $input_params{'action'} ||= "shortlog";
831 if ($input_params{'action'} &&
832 grep { $_ eq $input_params{'action'} } @wants_base) {
833 $input_params{'hash_base'} ||= $refname;
835 $input_params{'hash'} ||= $refname;
839 # next, handle the 'parent' part, if present
840 if (defined $parentrefname) {
841 # a missing pathspec defaults to the 'current' filename, allowing e.g.
842 # someproject/blobdiff/oldrev..newrev:/filename
843 if ($parentpathname) {
844 $parentpathname =~ s
,^/+,,;
845 $parentpathname =~ s
,/$,,;
846 $input_params{'file_parent'} ||= $parentpathname;
848 $input_params{'file_parent'} ||= $input_params{'file_name'};
850 # we assume that hash_parent_base is wanted if a path was specified,
851 # or if the action wants hash_base instead of hash
852 if (defined $input_params{'file_parent'} ||
853 grep { $_ eq $input_params{'action'} } @wants_base) {
854 $input_params{'hash_parent_base'} ||= $parentrefname;
856 $input_params{'hash_parent'} ||= $parentrefname;
860 # for the snapshot action, we allow URLs in the form
861 # $project/snapshot/$hash.ext
862 # where .ext determines the snapshot and gets removed from the
863 # passed $refname to provide the $hash.
865 # To be able to tell that $refname includes the format extension, we
866 # require the following two conditions to be satisfied:
867 # - the hash input parameter MUST have been set from the $refname part
868 # of the URL (i.e. they must be equal)
869 # - the snapshot format MUST NOT have been defined already (e.g. from
871 # It's also useless to try any matching unless $refname has a dot,
872 # so we check for that too
873 if (defined $input_params{'action'} &&
874 $input_params{'action'} eq 'snapshot' &&
875 defined $refname && index($refname, '.') != -1 &&
876 $refname eq $input_params{'hash'} &&
877 !defined $input_params{'snapshot_format'}) {
878 # We loop over the known snapshot formats, checking for
879 # extensions. Allowed extensions are both the defined suffix
880 # (which includes the initial dot already) and the snapshot
881 # format key itself, with a prepended dot
882 while (my ($fmt, $opt) = each %known_snapshot_formats) {
884 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
888 # a valid suffix was found, so set the snapshot format
889 # and reset the hash parameter
890 $input_params{'snapshot_format'} = $fmt;
891 $input_params{'hash'} = $hash;
892 # we also set the format suffix to the one requested
893 # in the URL: this way a request for e.g. .tgz returns
894 # a .tgz instead of a .tar.gz
895 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
901 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
902 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
903 $searchtext, $search_regexp);
904 sub evaluate_and_validate_params
{
905 our $action = $input_params{'action'};
906 if (defined $action) {
907 if (!validate_action
($action)) {
908 die_error
(400, "Invalid action parameter");
912 # parameters which are pathnames
913 our $project = $input_params{'project'};
914 if (defined $project) {
915 if (!validate_project
($project)) {
917 die_error
(404, "No such project");
921 our $file_name = $input_params{'file_name'};
922 if (defined $file_name) {
923 if (!validate_pathname
($file_name)) {
924 die_error
(400, "Invalid file parameter");
928 our $file_parent = $input_params{'file_parent'};
929 if (defined $file_parent) {
930 if (!validate_pathname
($file_parent)) {
931 die_error
(400, "Invalid file parent parameter");
935 # parameters which are refnames
936 our $hash = $input_params{'hash'};
938 if (!validate_refname
($hash)) {
939 die_error
(400, "Invalid hash parameter");
943 our $hash_parent = $input_params{'hash_parent'};
944 if (defined $hash_parent) {
945 if (!validate_refname
($hash_parent)) {
946 die_error
(400, "Invalid hash parent parameter");
950 our $hash_base = $input_params{'hash_base'};
951 if (defined $hash_base) {
952 if (!validate_refname
($hash_base)) {
953 die_error
(400, "Invalid hash base parameter");
957 our @extra_options = @{$input_params{'extra_options'}};
958 # @extra_options is always defined, since it can only be (currently) set from
959 # CGI, and $cgi->param() returns the empty array in array context if the param
961 foreach my $opt (@extra_options) {
962 if (not exists $allowed_options{$opt}) {
963 die_error
(400, "Invalid option parameter");
965 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
966 die_error
(400, "Invalid option parameter for this action");
970 our $hash_parent_base = $input_params{'hash_parent_base'};
971 if (defined $hash_parent_base) {
972 if (!validate_refname
($hash_parent_base)) {
973 die_error
(400, "Invalid hash parent base parameter");
978 our $page = $input_params{'page'};
980 if ($page =~ m/[^0-9]/) {
981 die_error
(400, "Invalid page parameter");
985 our $searchtype = $input_params{'searchtype'};
986 if (defined $searchtype) {
987 if ($searchtype =~ m/[^a-z]/) {
988 die_error
(400, "Invalid searchtype parameter");
992 our $search_use_regexp = $input_params{'search_use_regexp'};
994 our $searchtext = $input_params{'searchtext'};
996 if (defined $searchtext) {
997 if (length($searchtext) < 2) {
998 die_error
(403, "At least two characters are required for search parameter");
1000 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
1004 # path to the current git repository
1006 sub evaluate_git_dir
{
1007 our $git_dir = "$projectroot/$project" if $project;
1010 our (@snapshot_fmts, $git_avatar);
1011 sub configure_gitweb_features
{
1012 # list of supported snapshot formats
1013 our @snapshot_fmts = gitweb_get_feature
('snapshot');
1014 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1016 # check that the avatar feature is set to a known provider name,
1017 # and for each provider check if the dependencies are satisfied.
1018 # if the provider name is invalid or the dependencies are not met,
1019 # reset $git_avatar to the empty string.
1020 our ($git_avatar) = gitweb_get_feature
('avatar');
1021 if ($git_avatar eq 'gravatar') {
1022 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
1023 } elsif ($git_avatar eq 'picon') {
1030 # custom error handler: 'die <message>' is Internal Server Error
1031 sub handle_errors_html
{
1032 my $msg = shift; # it is already HTML escaped
1034 # to avoid infinite loop where error occurs in die_error,
1035 # change handler to default handler, disabling handle_errors_html
1036 set_message
("Error occured when inside die_error:\n$msg");
1038 # you cannot jump out of die_error when called as error handler;
1039 # the subroutine set via CGI::Carp::set_message is called _after_
1040 # HTTP headers are already written, so it cannot write them itself
1041 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1043 set_message
(\
&handle_errors_html
);
1047 if (!defined $action) {
1048 if (defined $hash) {
1049 $action = git_get_type
($hash);
1050 } elsif (defined $hash_base && defined $file_name) {
1051 $action = git_get_type
("$hash_base:$file_name");
1052 } elsif (defined $project) {
1053 $action = 'summary';
1055 $action = 'project_list';
1058 if (!defined($actions{$action})) {
1059 die_error
(400, "Unknown action");
1061 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1063 die_error
(400, "Project needed");
1065 $actions{$action}->();
1069 our $t0 = [Time
::HiRes
::gettimeofday
()]
1071 our $number_of_git_cmds = 0;
1078 evaluate_gitweb_config
();
1079 evaluate_git_version
();
1082 # $projectroot and $projects_list might be set in gitweb config file
1083 $projects_list ||= $projectroot;
1085 evaluate_query_params
();
1086 evaluate_path_info
();
1087 evaluate_and_validate_params
();
1090 configure_gitweb_features
();
1095 our $is_last_request = sub { 1 };
1096 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1099 sub configure_as_fcgi
{
1101 our $CGI = 'CGI::Fast';
1103 my $request_number = 0;
1104 # let each child service 100 requests
1105 our $is_last_request = sub { ++$request_number > 100 };
1108 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1110 if $script_name =~ /\.fcgi$/;
1112 return unless (@ARGV);
1114 require Getopt
::Long
;
1115 Getopt
::Long
::GetOptions
(
1116 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1117 'nproc|n=i' => sub {
1118 my ($arg, $val) = @_;
1119 return unless eval { require FCGI
::ProcManager
; 1; };
1120 my $proc_manager = FCGI
::ProcManager-
>new({
1121 n_processes
=> $val,
1123 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1124 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1125 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1133 $pre_listen_hook->()
1134 if $pre_listen_hook;
1137 while ($cgi = $CGI->new()) {
1138 $pre_dispatch_hook->()
1139 if $pre_dispatch_hook;
1143 $post_dispatch_hook->()
1144 if $post_dispatch_hook;
1146 last REQUEST
if ($is_last_request->());
1155 if (defined caller) {
1156 # wrapped in a subroutine processing requests,
1157 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1160 # pure CGI script, serving single request
1164 ## ======================================================================
1167 # possible values of extra options
1168 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1169 # -replay => 1 - start from a current view (replay with modifications)
1170 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1173 # default is to use -absolute url() i.e. $my_uri
1174 my $href = $params{-full
} ? $my_url : $my_uri;
1176 $params{'project'} = $project unless exists $params{'project'};
1178 if ($params{-replay
}) {
1179 while (my ($name, $symbol) = each %cgi_param_mapping) {
1180 if (!exists $params{$name}) {
1181 $params{$name} = $input_params{$name};
1186 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1187 if (defined $params{'project'} &&
1188 (exists $params{-path_info
} ? $params{-path_info
} : $use_pathinfo)) {
1189 # try to put as many parameters as possible in PATH_INFO:
1192 # - hash_parent or hash_parent_base:/file_parent
1193 # - hash or hash_base:/filename
1194 # - the snapshot_format as an appropriate suffix
1196 # When the script is the root DirectoryIndex for the domain,
1197 # $href here would be something like http://gitweb.example.com/
1198 # Thus, we strip any trailing / from $href, to spare us double
1199 # slashes in the final URL
1202 # Then add the project name, if present
1203 $href .= "/".esc_url
($params{'project'});
1204 delete $params{'project'};
1206 # since we destructively absorb parameters, we keep this
1207 # boolean that remembers if we're handling a snapshot
1208 my $is_snapshot = $params{'action'} eq 'snapshot';
1210 # Summary just uses the project path URL, any other action is
1212 if (defined $params{'action'}) {
1213 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1214 delete $params{'action'};
1217 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1218 # stripping nonexistent or useless pieces
1219 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1220 || $params{'hash_parent'} || $params{'hash'});
1221 if (defined $params{'hash_base'}) {
1222 if (defined $params{'hash_parent_base'}) {
1223 $href .= esc_url
($params{'hash_parent_base'});
1224 # skip the file_parent if it's the same as the file_name
1225 if (defined $params{'file_parent'}) {
1226 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1227 delete $params{'file_parent'};
1228 } elsif ($params{'file_parent'} !~ /\.\./) {
1229 $href .= ":/".esc_url
($params{'file_parent'});
1230 delete $params{'file_parent'};
1234 delete $params{'hash_parent'};
1235 delete $params{'hash_parent_base'};
1236 } elsif (defined $params{'hash_parent'}) {
1237 $href .= esc_url
($params{'hash_parent'}). "..";
1238 delete $params{'hash_parent'};
1241 $href .= esc_url
($params{'hash_base'});
1242 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1243 $href .= ":/".esc_url
($params{'file_name'});
1244 delete $params{'file_name'};
1246 delete $params{'hash'};
1247 delete $params{'hash_base'};
1248 } elsif (defined $params{'hash'}) {
1249 $href .= esc_url
($params{'hash'});
1250 delete $params{'hash'};
1253 # If the action was a snapshot, we can absorb the
1254 # snapshot_format parameter too
1256 my $fmt = $params{'snapshot_format'};
1257 # snapshot_format should always be defined when href()
1258 # is called, but just in case some code forgets, we
1259 # fall back to the default
1260 $fmt ||= $snapshot_fmts[0];
1261 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1262 delete $params{'snapshot_format'};
1266 # now encode the parameters explicitly
1268 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1269 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1270 if (defined $params{$name}) {
1271 if (ref($params{$name}) eq "ARRAY") {
1272 foreach my $par (@{$params{$name}}) {
1273 push @result, $symbol . "=" . esc_param
($par);
1276 push @result, $symbol . "=" . esc_param
($params{$name});
1280 $href .= "?" . join(';', @result) if scalar @result;
1286 ## ======================================================================
1287 ## validation, quoting/unquoting and escaping
1289 sub validate_action
{
1290 my $input = shift || return undef;
1291 return undef unless exists $actions{$input};
1295 sub validate_project
{
1296 my $input = shift || return undef;
1297 if (!validate_pathname
($input) ||
1298 !(-d
"$projectroot/$input") ||
1299 !check_export_ok
("$projectroot/$input") ||
1300 ($strict_export && !project_in_list
($input))) {
1307 sub validate_pathname
{
1308 my $input = shift || return undef;
1310 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1311 # at the beginning, at the end, and between slashes.
1312 # also this catches doubled slashes
1313 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1316 # no null characters
1317 if ($input =~ m!\0!) {
1323 sub validate_refname
{
1324 my $input = shift || return undef;
1326 # textual hashes are O.K.
1327 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1330 # it must be correct pathname
1331 $input = validate_pathname
($input)
1333 # restrictions on ref name according to git-check-ref-format
1334 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1340 # decode sequences of octets in utf8 into Perl's internal form,
1341 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1342 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1345 return undef unless defined $str;
1346 if (utf8
::valid
($str)) {
1350 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1354 # quote unsafe chars, but keep the slash, even when it's not
1355 # correct, but quoted slashes look too horrible in bookmarks
1358 return undef unless defined $str;
1359 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1364 # quote unsafe chars in whole URL, so some characters cannot be quoted
1367 return undef unless defined $str;
1368 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1373 # replace invalid utf8 character with SUBSTITUTION sequence
1378 return undef unless defined $str;
1380 $str = to_utf8
($str);
1381 $str = $cgi->escapeHTML($str);
1382 if ($opts{'-nbsp'}) {
1383 $str =~ s/ / /g;
1385 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1389 # quote control characters and escape filename to HTML
1394 return undef unless defined $str;
1396 $str = to_utf8
($str);
1397 $str = $cgi->escapeHTML($str);
1398 if ($opts{'-nbsp'}) {
1399 $str =~ s/ / /g;
1401 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1405 # Make control characters "printable", using character escape codes (CEC)
1409 my %es = ( # character escape codes, aka escape sequences
1410 "\t" => '\t', # tab (HT)
1411 "\n" => '\n', # line feed (LF)
1412 "\r" => '\r', # carrige return (CR)
1413 "\f" => '\f', # form feed (FF)
1414 "\b" => '\b', # backspace (BS)
1415 "\a" => '\a', # alarm (bell) (BEL)
1416 "\e" => '\e', # escape (ESC)
1417 "\013" => '\v', # vertical tab (VT)
1418 "\000" => '\0', # nul character (NUL)
1420 my $chr = ( (exists $es{$cntrl})
1422 : sprintf('\%2x', ord($cntrl)) );
1423 if ($opts{-nohtml
}) {
1426 return "<span class=\"cntrl\">$chr</span>";
1430 # Alternatively use unicode control pictures codepoints,
1431 # Unicode "printable representation" (PR)
1436 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1437 if ($opts{-nohtml
}) {
1440 return "<span class=\"cntrl\">$chr</span>";
1444 # git may return quoted and escaped filenames
1450 my %es = ( # character escape codes, aka escape sequences
1451 't' => "\t", # tab (HT, TAB)
1452 'n' => "\n", # newline (NL)
1453 'r' => "\r", # return (CR)
1454 'f' => "\f", # form feed (FF)
1455 'b' => "\b", # backspace (BS)
1456 'a' => "\a", # alarm (bell) (BEL)
1457 'e' => "\e", # escape (ESC)
1458 'v' => "\013", # vertical tab (VT)
1461 if ($seq =~ m/^[0-7]{1,3}$/) {
1462 # octal char sequence
1463 return chr(oct($seq));
1464 } elsif (exists $es{$seq}) {
1465 # C escape sequence, aka character escape code
1468 # quoted ordinary character
1472 if ($str =~ m/^"(.*)"$/) {
1475 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1480 # escape tabs (convert tabs to spaces)
1484 while ((my $pos = index($line, "\t")) != -1) {
1485 if (my $count = (8 - ($pos % 8))) {
1486 my $spaces = ' ' x
$count;
1487 $line =~ s/\t/$spaces/;
1494 sub project_in_list
{
1495 my $project = shift;
1496 my @list = git_get_projects_list
();
1497 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1500 ## ----------------------------------------------------------------------
1501 ## HTML aware string manipulation
1503 # Try to chop given string on a word boundary between position
1504 # $len and $len+$add_len. If there is no word boundary there,
1505 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1506 # (marking chopped part) would be longer than given string.
1510 my $add_len = shift || 10;
1511 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1513 # Make sure perl knows it is utf8 encoded so we don't
1514 # cut in the middle of a utf8 multibyte char.
1515 $str = to_utf8
($str);
1517 # allow only $len chars, but don't cut a word if it would fit in $add_len
1518 # if it doesn't fit, cut it if it's still longer than the dots we would add
1519 # remove chopped character entities entirely
1521 # when chopping in the middle, distribute $len into left and right part
1522 # return early if chopping wouldn't make string shorter
1523 if ($where eq 'center') {
1524 return $str if ($len + 5 >= length($str)); # filler is length 5
1527 return $str if ($len + 4 >= length($str)); # filler is length 4
1530 # regexps: ending and beginning with word part up to $add_len
1531 my $endre = qr/.{$len}\w{0,$add_len}/;
1532 my $begre = qr/\w{0,$add_len}.{$len}/;
1534 if ($where eq 'left') {
1535 $str =~ m/^(.*?)($begre)$/;
1536 my ($lead, $body) = ($1, $2);
1537 if (length($lead) > 4) {
1540 return "$lead$body";
1542 } elsif ($where eq 'center') {
1543 $str =~ m/^($endre)(.*)$/;
1544 my ($left, $str) = ($1, $2);
1545 $str =~ m/^(.*?)($begre)$/;
1546 my ($mid, $right) = ($1, $2);
1547 if (length($mid) > 5) {
1550 return "$left$mid$right";
1553 $str =~ m/^($endre)(.*)$/;
1556 if (length($tail) > 4) {
1559 return "$body$tail";
1563 # takes the same arguments as chop_str, but also wraps a <span> around the
1564 # result with a title attribute if it does get chopped. Additionally, the
1565 # string is HTML-escaped.
1566 sub chop_and_escape_str
{
1569 my $chopped = chop_str
(@_);
1570 if ($chopped eq $str) {
1571 return esc_html
($chopped);
1573 $str =~ s/[[:cntrl:]]/?/g;
1574 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1578 ## ----------------------------------------------------------------------
1579 ## functions returning short strings
1581 # CSS class for given age value (in seconds)
1585 if (!defined $age) {
1587 } elsif ($age < 60*60*2) {
1589 } elsif ($age < 60*60*24*2) {
1596 # convert age in seconds to "nn units ago" string
1601 if ($age > 60*60*24*365*2) {
1602 $age_str = (int $age/60/60/24/365);
1603 $age_str .= " years ago";
1604 } elsif ($age > 60*60*24*(365/12)*2) {
1605 $age_str = int $age/60/60/24/(365/12);
1606 $age_str .= " months ago";
1607 } elsif ($age > 60*60*24*7*2) {
1608 $age_str = int $age/60/60/24/7;
1609 $age_str .= " weeks ago";
1610 } elsif ($age > 60*60*24*2) {
1611 $age_str = int $age/60/60/24;
1612 $age_str .= " days ago";
1613 } elsif ($age > 60*60*2) {
1614 $age_str = int $age/60/60;
1615 $age_str .= " hours ago";
1616 } elsif ($age > 60*2) {
1617 $age_str = int $age/60;
1618 $age_str .= " min ago";
1619 } elsif ($age > 2) {
1620 $age_str = int $age;
1621 $age_str .= " sec ago";
1623 $age_str .= " right now";
1629 S_IFINVALID
=> 0030000,
1630 S_IFGITLINK
=> 0160000,
1633 # submodule/subproject, a commit object reference
1637 return (($mode & S_IFMT
) == S_IFGITLINK
)
1640 # convert file mode in octal to symbolic file mode string
1642 my $mode = oct shift;
1644 if (S_ISGITLINK
($mode)) {
1645 return 'm---------';
1646 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1647 return 'drwxr-xr-x';
1648 } elsif (S_ISLNK
($mode)) {
1649 return 'lrwxrwxrwx';
1650 } elsif (S_ISREG
($mode)) {
1651 # git cares only about the executable bit
1652 if ($mode & S_IXUSR
) {
1653 return '-rwxr-xr-x';
1655 return '-rw-r--r--';
1658 return '----------';
1662 # convert file mode in octal to file type string
1666 if ($mode !~ m/^[0-7]+$/) {
1672 if (S_ISGITLINK
($mode)) {
1674 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1676 } elsif (S_ISLNK
($mode)) {
1678 } elsif (S_ISREG
($mode)) {
1685 # convert file mode in octal to file type description string
1686 sub file_type_long
{
1689 if ($mode !~ m/^[0-7]+$/) {
1695 if (S_ISGITLINK
($mode)) {
1697 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1699 } elsif (S_ISLNK
($mode)) {
1701 } elsif (S_ISREG
($mode)) {
1702 if ($mode & S_IXUSR
) {
1703 return "executable";
1713 ## ----------------------------------------------------------------------
1714 ## functions returning short HTML fragments, or transforming HTML fragments
1715 ## which don't belong to other sections
1717 # format line of commit message.
1718 sub format_log_line_html
{
1721 $line = esc_html
($line, -nbsp
=>1);
1722 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1723 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1724 -class => "text"}, $1);
1730 # format marker of refs pointing to given object
1732 # the destination action is chosen based on object type and current context:
1733 # - for annotated tags, we choose the tag view unless it's the current view
1734 # already, in which case we go to shortlog view
1735 # - for other refs, we keep the current view if we're in history, shortlog or
1736 # log view, and select shortlog otherwise
1737 sub format_ref_marker
{
1738 my ($refs, $id) = @_;
1741 if (defined $refs->{$id}) {
1742 foreach my $ref (@{$refs->{$id}}) {
1743 # this code exploits the fact that non-lightweight tags are the
1744 # only indirect objects, and that they are the only objects for which
1745 # we want to use tag instead of shortlog as action
1746 my ($type, $name) = qw();
1747 my $indirect = ($ref =~ s/\^\{\}$//);
1748 # e.g. tags/v2.6.11 or heads/next
1749 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1758 $class .= " indirect" if $indirect;
1760 my $dest_action = "shortlog";
1763 $dest_action = "tag" unless $action eq "tag";
1764 } elsif ($action =~ /^(history|(short)?log)$/) {
1765 $dest_action = $action;
1769 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1772 my $link = $cgi->a({
1774 action
=>$dest_action,
1778 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1784 return ' <span class="refs">'. $markers . '</span>';
1790 # format, perhaps shortened and with markers, title line
1791 sub format_subject_html
{
1792 my ($long, $short, $href, $extra) = @_;
1793 $extra = '' unless defined($extra);
1795 if (length($short) < length($long)) {
1796 $long =~ s/[[:cntrl:]]/?/g;
1797 return $cgi->a({-href
=> $href, -class => "list subject",
1798 -title
=> to_utf8
($long)},
1799 esc_html
($short)) . $extra;
1801 return $cgi->a({-href
=> $href, -class => "list subject"},
1802 esc_html
($long)) . $extra;
1806 # Rather than recomputing the url for an email multiple times, we cache it
1807 # after the first hit. This gives a visible benefit in views where the avatar
1808 # for the same email is used repeatedly (e.g. shortlog).
1809 # The cache is shared by all avatar engines (currently gravatar only), which
1810 # are free to use it as preferred. Since only one avatar engine is used for any
1811 # given page, there's no risk for cache conflicts.
1812 our %avatar_cache = ();
1814 # Compute the picon url for a given email, by using the picon search service over at
1815 # http://www.cs.indiana.edu/picons/search.html
1817 my $email = lc shift;
1818 if (!$avatar_cache{$email}) {
1819 my ($user, $domain) = split('@', $email);
1820 $avatar_cache{$email} =
1821 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1823 "users+domains+unknown/up/single";
1825 return $avatar_cache{$email};
1828 # Compute the gravatar url for a given email, if it's not in the cache already.
1829 # Gravatar stores only the part of the URL before the size, since that's the
1830 # one computationally more expensive. This also allows reuse of the cache for
1831 # different sizes (for this particular engine).
1833 my $email = lc shift;
1835 $avatar_cache{$email} ||=
1836 "http://www.gravatar.com/avatar/" .
1837 Digest
::MD5
::md5_hex
($email) . "?s=";
1838 return $avatar_cache{$email} . $size;
1841 # Insert an avatar for the given $email at the given $size if the feature
1843 sub git_get_avatar
{
1844 my ($email, %opts) = @_;
1845 my $pre_white = ($opts{-pad_before
} ? " " : "");
1846 my $post_white = ($opts{-pad_after
} ? " " : "");
1847 $opts{-size
} ||= 'default';
1848 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1850 if ($git_avatar eq 'gravatar') {
1851 $url = gravatar_url
($email, $size);
1852 } elsif ($git_avatar eq 'picon') {
1853 $url = picon_url
($email);
1855 # Other providers can be added by extending the if chain, defining $url
1856 # as needed. If no variant puts something in $url, we assume avatars
1857 # are completely disabled/unavailable.
1860 "<img width=\"$size\" " .
1861 "class=\"avatar\" " .
1870 sub format_search_author
{
1871 my ($author, $searchtype, $displaytext) = @_;
1872 my $have_search = gitweb_check_feature
('search');
1876 if ($searchtype eq 'author') {
1877 $performed = "authored";
1878 } elsif ($searchtype eq 'committer') {
1879 $performed = "committed";
1882 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1883 searchtext
=>$author,
1884 searchtype
=>$searchtype), class=>"list",
1885 title
=>"Search for commits $performed by $author"},
1889 return $displaytext;
1893 # format the author name of the given commit with the given tag
1894 # the author name is chopped and escaped according to the other
1895 # optional parameters (see chop_str).
1896 sub format_author_html
{
1899 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1900 return "<$tag class=\"author\">" .
1901 format_search_author
($co->{'author_name'}, "author",
1902 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1907 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1908 sub format_git_diff_header_line
{
1910 my $diffinfo = shift;
1911 my ($from, $to) = @_;
1913 if ($diffinfo->{'nparents'}) {
1915 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1916 if ($to->{'href'}) {
1917 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1918 esc_path
($to->{'file'}));
1919 } else { # file was deleted (no href)
1920 $line .= esc_path
($to->{'file'});
1924 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1925 if ($from->{'href'}) {
1926 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1927 'a/' . esc_path
($from->{'file'}));
1928 } else { # file was added (no href)
1929 $line .= 'a/' . esc_path
($from->{'file'});
1932 if ($to->{'href'}) {
1933 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1934 'b/' . esc_path
($to->{'file'}));
1935 } else { # file was deleted
1936 $line .= 'b/' . esc_path
($to->{'file'});
1940 return "<div class=\"diff header\">$line</div>\n";
1943 # format extended diff header line, before patch itself
1944 sub format_extended_diff_header_line
{
1946 my $diffinfo = shift;
1947 my ($from, $to) = @_;
1950 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1951 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1952 esc_path
($from->{'file'}));
1954 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1955 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1956 esc_path
($to->{'file'}));
1958 # match single <mode>
1959 if ($line =~ m/\s(\d{6})$/) {
1960 $line .= '<span class="info"> (' .
1961 file_type_long
($1) .
1965 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1966 # can match only for combined diff
1968 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1969 if ($from->{'href'}[$i]) {
1970 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1972 substr($diffinfo->{'from_id'}[$i],0,7));
1977 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1980 if ($to->{'href'}) {
1981 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1982 substr($diffinfo->{'to_id'},0,7));
1987 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1988 # can match only for ordinary diff
1989 my ($from_link, $to_link);
1990 if ($from->{'href'}) {
1991 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1992 substr($diffinfo->{'from_id'},0,7));
1994 $from_link = '0' x
7;
1996 if ($to->{'href'}) {
1997 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1998 substr($diffinfo->{'to_id'},0,7));
2002 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2003 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2006 return $line . "<br/>\n";
2009 # format from-file/to-file diff header
2010 sub format_diff_from_to_header
{
2011 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
2016 #assert($line =~ m/^---/) if DEBUG;
2017 # no extra formatting for "^--- /dev/null"
2018 if (! $diffinfo->{'nparents'}) {
2019 # ordinary (single parent) diff
2020 if ($line =~ m!^--- "?a/!) {
2021 if ($from->{'href'}) {
2023 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
2024 esc_path
($from->{'file'}));
2027 esc_path
($from->{'file'});
2030 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2033 # combined diff (merge commit)
2034 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2035 if ($from->{'href'}[$i]) {
2037 $cgi->a({-href
=>href
(action
=>"blobdiff",
2038 hash_parent
=>$diffinfo->{'from_id'}[$i],
2039 hash_parent_base
=>$parents[$i],
2040 file_parent
=>$from->{'file'}[$i],
2041 hash
=>$diffinfo->{'to_id'},
2043 file_name
=>$to->{'file'}),
2045 -title
=>"diff" . ($i+1)},
2048 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2049 esc_path
($from->{'file'}[$i]));
2051 $line = '--- /dev/null';
2053 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
2058 #assert($line =~ m/^\+\+\+/) if DEBUG;
2059 # no extra formatting for "^+++ /dev/null"
2060 if ($line =~ m!^\+\+\+ "?b/!) {
2061 if ($to->{'href'}) {
2063 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2064 esc_path
($to->{'file'}));
2067 esc_path
($to->{'file'});
2070 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
2075 # create note for patch simplified by combined diff
2076 sub format_diff_cc_simplified
{
2077 my ($diffinfo, @parents) = @_;
2080 $result .= "<div class=\"diff header\">" .
2082 if (!is_deleted
($diffinfo)) {
2083 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2085 hash
=>$diffinfo->{'to_id'},
2086 file_name
=>$diffinfo->{'to_file'}),
2088 esc_path
($diffinfo->{'to_file'}));
2090 $result .= esc_path
($diffinfo->{'to_file'});
2092 $result .= "</div>\n" . # class="diff header"
2093 "<div class=\"diff nodifferences\">" .
2095 "</div>\n"; # class="diff nodifferences"
2100 # format patch (diff) line (not to be used for diff headers)
2101 sub format_diff_line
{
2103 my ($from, $to) = @_;
2104 my $diff_class = "";
2108 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2110 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
2111 if ($line =~ m/^\@{3}/) {
2112 $diff_class = " chunk_header";
2113 } elsif ($line =~ m/^\\/) {
2114 $diff_class = " incomplete";
2115 } elsif ($prefix =~ tr/+/+/) {
2116 $diff_class = " add";
2117 } elsif ($prefix =~ tr/-/-/) {
2118 $diff_class = " rem";
2121 # assume ordinary diff
2122 my $char = substr($line, 0, 1);
2124 $diff_class = " add";
2125 } elsif ($char eq '-') {
2126 $diff_class = " rem";
2127 } elsif ($char eq '@') {
2128 $diff_class = " chunk_header";
2129 } elsif ($char eq "\\") {
2130 $diff_class = " incomplete";
2133 $line = untabify
($line);
2134 if ($from && $to && $line =~ m/^\@{2} /) {
2135 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2136 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2138 $from_lines = 0 unless defined $from_lines;
2139 $to_lines = 0 unless defined $to_lines;
2141 if ($from->{'href'}) {
2142 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2143 -class=>"list"}, $from_text);
2145 if ($to->{'href'}) {
2146 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2147 -class=>"list"}, $to_text);
2149 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2150 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2151 return "<div class=\"diff$diff_class\">$line</div>\n";
2152 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2153 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2154 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2156 @from_text = split(' ', $ranges);
2157 for (my $i = 0; $i < @from_text; ++$i) {
2158 ($from_start[$i], $from_nlines[$i]) =
2159 (split(',', substr($from_text[$i], 1)), 0);
2162 $to_text = pop @from_text;
2163 $to_start = pop @from_start;
2164 $to_nlines = pop @from_nlines;
2166 $line = "<span class=\"chunk_info\">$prefix ";
2167 for (my $i = 0; $i < @from_text; ++$i) {
2168 if ($from->{'href'}[$i]) {
2169 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2170 -class=>"list"}, $from_text[$i]);
2172 $line .= $from_text[$i];
2176 if ($to->{'href'}) {
2177 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2178 -class=>"list"}, $to_text);
2182 $line .= " $prefix</span>" .
2183 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2184 return "<div class=\"diff$diff_class\">$line</div>\n";
2186 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2189 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2190 # linked. Pass the hash of the tree/commit to snapshot.
2191 sub format_snapshot_links
{
2193 my $num_fmts = @snapshot_fmts;
2194 if ($num_fmts > 1) {
2195 # A parenthesized list of links bearing format names.
2196 # e.g. "snapshot (_tar.gz_ _zip_)"
2197 return "snapshot (" . join(' ', map
2204 }, $known_snapshot_formats{$_}{'display'})
2205 , @snapshot_fmts) . ")";
2206 } elsif ($num_fmts == 1) {
2207 # A single "snapshot" link whose tooltip bears the format name.
2209 my ($fmt) = @snapshot_fmts;
2215 snapshot_format
=>$fmt
2217 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2219 } else { # $num_fmts == 0
2224 ## ......................................................................
2225 ## functions returning values to be passed, perhaps after some
2226 ## transformation, to other functions; e.g. returning arguments to href()
2228 # returns hash to be passed to href to generate gitweb URL
2229 # in -title key it returns description of link
2231 my $format = shift || 'Atom';
2232 my %res = (action
=> lc($format));
2234 # feed links are possible only for project views
2235 return unless (defined $project);
2236 # some views should link to OPML, or to generic project feed,
2237 # or don't have specific feed yet (so they should use generic)
2238 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2241 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2242 # from tag links; this also makes possible to detect branch links
2243 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2244 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2247 # find log type for feed description (title)
2249 if (defined $file_name) {
2250 $type = "history of $file_name";
2251 $type .= "/" if ($action eq 'tree');
2252 $type .= " on '$branch'" if (defined $branch);
2254 $type = "log of $branch" if (defined $branch);
2257 $res{-title
} = $type;
2258 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2259 $res{'file_name'} = $file_name;
2264 ## ----------------------------------------------------------------------
2265 ## git utility subroutines, invoking git commands
2267 # returns path to the core git executable and the --git-dir parameter as list
2269 $number_of_git_cmds++;
2270 return $GIT, '--git-dir='.$git_dir;
2273 # quote the given arguments for passing them to the shell
2274 # quote_command("command", "arg 1", "arg with ' and ! characters")
2275 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2276 # Try to avoid using this function wherever possible.
2279 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2282 # get HEAD ref of given project as hash
2283 sub git_get_head_hash
{
2284 return git_get_full_hash
(shift, 'HEAD');
2287 sub git_get_full_hash
{
2288 return git_get_hash
(@_);
2291 sub git_get_short_hash
{
2292 return git_get_hash
(@_, '--short=7');
2296 my ($project, $hash, @options) = @_;
2297 my $o_git_dir = $git_dir;
2299 $git_dir = "$projectroot/$project";
2300 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2301 '--verify', '-q', @options, $hash) {
2303 chomp $retval if defined $retval;
2306 if (defined $o_git_dir) {
2307 $git_dir = $o_git_dir;
2312 # get type of given object
2316 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2318 close $fd or return;
2323 # repository configuration
2324 our $config_file = '';
2327 # store multiple values for single key as anonymous array reference
2328 # single values stored directly in the hash, not as [ <value> ]
2329 sub hash_set_multi
{
2330 my ($hash, $key, $value) = @_;
2332 if (!exists $hash->{$key}) {
2333 $hash->{$key} = $value;
2334 } elsif (!ref $hash->{$key}) {
2335 $hash->{$key} = [ $hash->{$key}, $value ];
2337 push @{$hash->{$key}}, $value;
2341 # return hash of git project configuration
2342 # optionally limited to some section, e.g. 'gitweb'
2343 sub git_parse_project_config
{
2344 my $section_regexp = shift;
2349 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2352 while (my $keyval = <$fh>) {
2354 my ($key, $value) = split(/\n/, $keyval, 2);
2356 hash_set_multi
(\
%config, $key, $value)
2357 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2364 # convert config value to boolean: 'true' or 'false'
2365 # no value, number > 0, 'true' and 'yes' values are true
2366 # rest of values are treated as false (never as error)
2367 sub config_to_bool
{
2370 return 1 if !defined $val; # section.key
2372 # strip leading and trailing whitespace
2376 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2377 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2380 # convert config value to simple decimal number
2381 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2382 # to be multiplied by 1024, 1048576, or 1073741824
2386 # strip leading and trailing whitespace
2390 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2392 # unknown unit is treated as 1
2393 return $num * ($unit eq 'g' ? 1073741824 :
2394 $unit eq 'm' ? 1048576 :
2395 $unit eq 'k' ? 1024 : 1);
2400 # convert config value to array reference, if needed
2401 sub config_to_multi
{
2404 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2407 sub git_get_project_config
{
2408 my ($key, $type) = @_;
2410 return unless defined $git_dir;
2413 return unless ($key);
2414 $key =~ s/^gitweb\.//;
2415 return if ($key =~ m/\W/);
2418 if (defined $type) {
2421 unless ($type eq 'bool' || $type eq 'int');
2425 if (!defined $config_file ||
2426 $config_file ne "$git_dir/config") {
2427 %config = git_parse_project_config
('gitweb');
2428 $config_file = "$git_dir/config";
2431 # check if config variable (key) exists
2432 return unless exists $config{"gitweb.$key"};
2435 if (!defined $type) {
2436 return $config{"gitweb.$key"};
2437 } elsif ($type eq 'bool') {
2438 # backward compatibility: 'git config --bool' returns true/false
2439 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2440 } elsif ($type eq 'int') {
2441 return config_to_int
($config{"gitweb.$key"});
2443 return $config{"gitweb.$key"};
2446 # get hash of given path at given ref
2447 sub git_get_hash_by_path
{
2449 my $path = shift || return undef;
2454 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2455 or die_error
(500, "Open git-ls-tree failed");
2457 close $fd or return undef;
2459 if (!defined $line) {
2460 # there is no tree or hash given by $path at $base
2464 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2465 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2466 if (defined $type && $type ne $2) {
2467 # type doesn't match
2473 # get path of entry with given hash at given tree-ish (ref)
2474 # used to get 'from' filename for combined diff (merge commit) for renames
2475 sub git_get_path_by_hash
{
2476 my $base = shift || return;
2477 my $hash = shift || return;
2481 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2483 while (my $line = <$fd>) {
2486 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2487 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2488 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2497 ## ......................................................................
2498 ## git utility functions, directly accessing git repository
2500 sub git_get_project_description
{
2503 $git_dir = "$projectroot/$path";
2504 open my $fd, '<', "$git_dir/description"
2505 or return git_get_project_config
('description');
2508 if (defined $descr) {
2514 sub git_get_project_ctags
{
2518 $git_dir = "$projectroot/$path";
2519 opendir my $dh, "$git_dir/ctags"
2521 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2522 open my $ct, '<', $_ or next;
2526 my $ctag = $_; $ctag =~ s
#.*/##;
2527 $ctags->{$ctag} = $val;
2533 sub git_populate_project_tagcloud
{
2536 # First, merge different-cased tags; tags vote on casing
2538 foreach (keys %$ctags) {
2539 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2540 if (not $ctags_lc{lc $_}->{topcount
}
2541 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2542 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2543 $ctags_lc{lc $_}->{topname
} = $_;
2548 if (eval { require HTML
::TagCloud
; 1; }) {
2549 $cloud = HTML
::TagCloud-
>new;
2550 foreach (sort keys %ctags_lc) {
2551 # Pad the title with spaces so that the cloud looks
2553 my $title = $ctags_lc{$_}->{topname
};
2554 $title =~ s/ / /g;
2555 $title =~ s/^/ /g;
2556 $title =~ s/$/ /g;
2557 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2560 $cloud = \
%ctags_lc;
2565 sub git_show_project_tagcloud
{
2566 my ($cloud, $count) = @_;
2567 print STDERR
ref($cloud)."..\n";
2568 if (ref $cloud eq 'HTML::TagCloud') {
2569 return $cloud->html_and_css($count);
2571 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2572 return '<p align="center">' . join (', ', map {
2573 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2574 } splice(@tags, 0, $count)) . '</p>';
2578 sub git_get_project_url_list
{
2581 $git_dir = "$projectroot/$path";
2582 open my $fd, '<', "$git_dir/cloneurl"
2583 or return wantarray ?
2584 @{ config_to_multi
(git_get_project_config
('url')) } :
2585 config_to_multi
(git_get_project_config
('url'));
2586 my @git_project_url_list = map { chomp; $_ } <$fd>;
2589 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2592 sub git_get_projects_list
{
2597 $filter =~ s/\.git$//;
2599 my $check_forks = gitweb_check_feature
('forks');
2601 if (-d
$projects_list) {
2602 # search in directory
2603 my $dir = $projects_list . ($filter ? "/$filter" : '');
2604 # remove the trailing "/"
2606 my $pfxlen = length("$dir");
2607 my $pfxdepth = ($dir =~ tr!/!!);
2610 follow_fast
=> 1, # follow symbolic links
2611 follow_skip
=> 2, # ignore duplicates
2612 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2615 our $project_maxdepth;
2617 # skip project-list toplevel, if we get it.
2618 return if (m!^[/.]$!);
2619 # only directories can be git repositories
2620 return unless (-d
$_);
2621 # don't traverse too deep (Find is super slow on os x)
2622 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2623 $File::Find
::prune
= 1;
2627 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2628 # we check related file in $projectroot
2629 my $path = ($filter ? "$filter/" : '') . $subdir;
2630 if (check_export_ok
("$projectroot/$path")) {
2631 push @list, { path
=> $path };
2632 $File::Find
::prune
= 1;
2637 } elsif (-f
$projects_list) {
2638 # read from file(url-encoded):
2639 # 'git%2Fgit.git Linus+Torvalds'
2640 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2641 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2643 open my $fd, '<', $projects_list or return;
2645 while (my $line = <$fd>) {
2647 my ($path, $owner) = split ' ', $line;
2648 $path = unescape
($path);
2649 $owner = unescape
($owner);
2650 if (!defined $path) {
2653 if ($filter ne '') {
2654 # looking for forks;
2655 my $pfx = substr($path, 0, length($filter));
2656 if ($pfx ne $filter) {
2659 my $sfx = substr($path, length($filter));
2660 if ($sfx !~ /^\/.*\
.git
$/) {
2663 } elsif ($check_forks) {
2665 foreach my $filter (keys %paths) {
2666 # looking for forks;
2667 my $pfx = substr($path, 0, length($filter));
2668 if ($pfx ne $filter) {
2671 my $sfx = substr($path, length($filter));
2672 if ($sfx !~ /^\/.*\
.git
$/) {
2675 # is a fork, don't include it in
2680 if (check_export_ok
("$projectroot/$path")) {
2683 owner
=> to_utf8
($owner),
2686 (my $forks_path = $path) =~ s/\.git$//;
2687 $paths{$forks_path}++;
2695 our $gitweb_project_owner = undef;
2696 sub git_get_project_list_from_file
{
2698 return if (defined $gitweb_project_owner);
2700 $gitweb_project_owner = {};
2701 # read from file (url-encoded):
2702 # 'git%2Fgit.git Linus+Torvalds'
2703 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2704 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2705 if (-f
$projects_list) {
2706 open(my $fd, '<', $projects_list);
2707 while (my $line = <$fd>) {
2709 my ($pr, $ow) = split ' ', $line;
2710 $pr = unescape
($pr);
2711 $ow = unescape
($ow);
2712 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2718 sub git_get_project_owner
{
2719 my $project = shift;
2722 return undef unless $project;
2723 $git_dir = "$projectroot/$project";
2725 if (!defined $gitweb_project_owner) {
2726 git_get_project_list_from_file
();
2729 if (exists $gitweb_project_owner->{$project}) {
2730 $owner = $gitweb_project_owner->{$project};
2732 if (!defined $owner){
2733 $owner = git_get_project_config
('owner');
2735 if (!defined $owner) {
2736 $owner = get_file_owner
("$git_dir");
2742 sub git_get_last_activity
{
2746 $git_dir = "$projectroot/$path";
2747 open($fd, "-|", git_cmd
(), 'for-each-ref',
2748 '--format=%(committer)',
2749 '--sort=-committerdate',
2751 'refs/heads') or return;
2752 my $most_recent = <$fd>;
2753 close $fd or return;
2754 if (defined $most_recent &&
2755 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2757 my $age = time - $timestamp;
2758 return ($age, age_string
($age));
2760 return (undef, undef);
2763 sub git_get_references
{
2764 my $type = shift || "";
2766 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2767 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2768 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2769 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2772 while (my $line = <$fd>) {
2774 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2775 if (defined $refs{$1}) {
2776 push @{$refs{$1}}, $2;
2782 close $fd or return;
2786 sub git_get_rev_name_tags
{
2787 my $hash = shift || return undef;
2789 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2791 my $name_rev = <$fd>;
2794 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2797 # catches also '$hash undefined' output
2802 ## ----------------------------------------------------------------------
2803 ## parse to hash functions
2807 my $tz = shift || "-0000";
2810 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2811 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2812 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2813 $date{'hour'} = $hour;
2814 $date{'minute'} = $min;
2815 $date{'mday'} = $mday;
2816 $date{'day'} = $days[$wday];
2817 $date{'month'} = $months[$mon];
2818 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2819 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2820 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2821 $mday, $months[$mon], $hour ,$min;
2822 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2823 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2825 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2826 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2827 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2828 $date{'hour_local'} = $hour;
2829 $date{'minute_local'} = $min;
2830 $date{'tz_local'} = $tz;
2831 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2832 1900+$year, $mon+1, $mday,
2833 $hour, $min, $sec, $tz);
2842 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2843 $tag{'id'} = $tag_id;
2844 while (my $line = <$fd>) {
2846 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2847 $tag{'object'} = $1;
2848 } elsif ($line =~ m/^type (.+)$/) {
2850 } elsif ($line =~ m/^tag (.+)$/) {
2852 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2853 $tag{'author'} = $1;
2854 $tag{'author_epoch'} = $2;
2855 $tag{'author_tz'} = $3;
2856 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2857 $tag{'author_name'} = $1;
2858 $tag{'author_email'} = $2;
2860 $tag{'author_name'} = $tag{'author'};
2862 } elsif ($line =~ m/--BEGIN/) {
2863 push @comment, $line;
2865 } elsif ($line eq "") {
2869 push @comment, <$fd>;
2870 $tag{'comment'} = \
@comment;
2871 close $fd or return;
2872 if (!defined $tag{'name'}) {
2878 sub parse_commit_text
{
2879 my ($commit_text, $withparents) = @_;
2880 my @commit_lines = split '\n', $commit_text;
2883 pop @commit_lines; # Remove '\0'
2885 if (! @commit_lines) {
2889 my $header = shift @commit_lines;
2890 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2893 ($co{'id'}, my @parents) = split ' ', $header;
2894 while (my $line = shift @commit_lines) {
2895 last if $line eq "\n";
2896 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2898 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2900 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2901 $co{'author'} = to_utf8
($1);
2902 $co{'author_epoch'} = $2;
2903 $co{'author_tz'} = $3;
2904 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2905 $co{'author_name'} = $1;
2906 $co{'author_email'} = $2;
2908 $co{'author_name'} = $co{'author'};
2910 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2911 $co{'committer'} = to_utf8
($1);
2912 $co{'committer_epoch'} = $2;
2913 $co{'committer_tz'} = $3;
2914 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2915 $co{'committer_name'} = $1;
2916 $co{'committer_email'} = $2;
2918 $co{'committer_name'} = $co{'committer'};
2922 if (!defined $co{'tree'}) {
2925 $co{'parents'} = \
@parents;
2926 $co{'parent'} = $parents[0];
2928 foreach my $title (@commit_lines) {
2931 $co{'title'} = chop_str
($title, 80, 5);
2932 # remove leading stuff of merges to make the interesting part visible
2933 if (length($title) > 50) {
2934 $title =~ s/^Automatic //;
2935 $title =~ s/^merge (of|with) /Merge ... /i;
2936 if (length($title) > 50) {
2937 $title =~ s/(http|rsync):\/\///;
2939 if (length($title) > 50) {
2940 $title =~ s/(master|www|rsync)\.//;
2942 if (length($title) > 50) {
2943 $title =~ s/kernel.org:?//;
2945 if (length($title) > 50) {
2946 $title =~ s/\/pub\/scm//;
2949 $co{'title_short'} = chop_str
($title, 50, 5);
2953 if (! defined $co{'title'} || $co{'title'} eq "") {
2954 $co{'title'} = $co{'title_short'} = '(no commit message)';
2956 # remove added spaces
2957 foreach my $line (@commit_lines) {
2960 $co{'comment'} = \
@commit_lines;
2962 my $age = time - $co{'committer_epoch'};
2964 $co{'age_string'} = age_string
($age);
2965 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2966 if ($age > 60*60*24*7*2) {
2967 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2968 $co{'age_string_age'} = $co{'age_string'};
2970 $co{'age_string_date'} = $co{'age_string'};
2971 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2977 my ($commit_id) = @_;
2982 open my $fd, "-|", git_cmd
(), "rev-list",
2988 or die_error
(500, "Open git-rev-list failed");
2989 %co = parse_commit_text
(<$fd>, 1);
2996 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
3004 open my $fd, "-|", git_cmd
(), "rev-list",
3007 ("--max-count=" . $maxcount),
3008 ("--skip=" . $skip),
3012 ($filename ? ($filename) : ())
3013 or die_error
(500, "Open git-rev-list failed");
3014 while (my $line = <$fd>) {
3015 my %co = parse_commit_text
($line);
3020 return wantarray ? @cos : \
@cos;
3023 # parse line of git-diff-tree "raw" output
3024 sub parse_difftree_raw_line
{
3028 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3029 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3030 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3031 $res{'from_mode'} = $1;
3032 $res{'to_mode'} = $2;
3033 $res{'from_id'} = $3;
3035 $res{'status'} = $5;
3036 $res{'similarity'} = $6;
3037 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3038 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3040 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3043 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3044 # combined diff (for merge commit)
3045 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3046 $res{'nparents'} = length($1);
3047 $res{'from_mode'} = [ split(' ', $2) ];
3048 $res{'to_mode'} = pop @{$res{'from_mode'}};
3049 $res{'from_id'} = [ split(' ', $3) ];
3050 $res{'to_id'} = pop @{$res{'from_id'}};
3051 $res{'status'} = [ split('', $4) ];
3052 $res{'to_file'} = unquote
($5);
3054 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3055 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3056 $res{'commit'} = $1;
3059 return wantarray ? %res : \
%res;
3062 # wrapper: return parsed line of git-diff-tree "raw" output
3063 # (the argument might be raw line, or parsed info)
3064 sub parsed_difftree_line
{
3065 my $line_or_ref = shift;
3067 if (ref($line_or_ref) eq "HASH") {
3068 # pre-parsed (or generated by hand)
3069 return $line_or_ref;
3071 return parse_difftree_raw_line
($line_or_ref);
3075 # parse line of git-ls-tree output
3076 sub parse_ls_tree_line
{
3082 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3083 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3092 $res{'name'} = unquote
($5);
3095 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3096 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3104 $res{'name'} = unquote
($4);
3108 return wantarray ? %res : \
%res;
3111 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3112 sub parse_from_to_diffinfo
{
3113 my ($diffinfo, $from, $to, @parents) = @_;
3115 if ($diffinfo->{'nparents'}) {
3117 $from->{'file'} = [];
3118 $from->{'href'} = [];
3119 fill_from_file_info
($diffinfo, @parents)
3120 unless exists $diffinfo->{'from_file'};
3121 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3122 $from->{'file'}[$i] =
3123 defined $diffinfo->{'from_file'}[$i] ?
3124 $diffinfo->{'from_file'}[$i] :
3125 $diffinfo->{'to_file'};
3126 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3127 $from->{'href'}[$i] = href
(action
=>"blob",
3128 hash_base
=>$parents[$i],
3129 hash
=>$diffinfo->{'from_id'}[$i],
3130 file_name
=>$from->{'file'}[$i]);
3132 $from->{'href'}[$i] = undef;
3136 # ordinary (not combined) diff
3137 $from->{'file'} = $diffinfo->{'from_file'};
3138 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3139 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3140 hash
=>$diffinfo->{'from_id'},
3141 file_name
=>$from->{'file'});
3143 delete $from->{'href'};
3147 $to->{'file'} = $diffinfo->{'to_file'};
3148 if (!is_deleted
($diffinfo)) { # file exists in result
3149 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3150 hash
=>$diffinfo->{'to_id'},
3151 file_name
=>$to->{'file'});
3153 delete $to->{'href'};
3157 ## ......................................................................
3158 ## parse to array of hashes functions
3160 sub git_get_heads_list
{
3164 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3165 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
3166 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3169 while (my $line = <$fd>) {
3173 my ($refinfo, $committerinfo) = split(/\0/, $line);
3174 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3175 my ($committer, $epoch, $tz) =
3176 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3177 $ref_item{'fullname'} = $name;
3178 $name =~ s!^refs/heads/!!;
3180 $ref_item{'name'} = $name;
3181 $ref_item{'id'} = $hash;
3182 $ref_item{'title'} = $title || '(no commit message)';
3183 $ref_item{'epoch'} = $epoch;
3185 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3187 $ref_item{'age'} = "unknown";
3190 push @headslist, \
%ref_item;
3194 return wantarray ? @headslist : \
@headslist;
3197 sub git_get_tags_list
{
3201 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3202 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
3203 '--format=%(objectname) %(objecttype) %(refname) '.
3204 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3207 while (my $line = <$fd>) {
3211 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3212 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3213 my ($creator, $epoch, $tz) =
3214 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3215 $ref_item{'fullname'} = $name;
3216 $name =~ s!^refs/tags/!!;
3218 $ref_item{'type'} = $type;
3219 $ref_item{'id'} = $id;
3220 $ref_item{'name'} = $name;
3221 if ($type eq "tag") {
3222 $ref_item{'subject'} = $title;
3223 $ref_item{'reftype'} = $reftype;
3224 $ref_item{'refid'} = $refid;
3226 $ref_item{'reftype'} = $type;
3227 $ref_item{'refid'} = $id;
3230 if ($type eq "tag" || $type eq "commit") {
3231 $ref_item{'epoch'} = $epoch;
3233 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3235 $ref_item{'age'} = "unknown";
3239 push @tagslist, \
%ref_item;
3243 return wantarray ? @tagslist : \
@tagslist;
3246 ## ----------------------------------------------------------------------
3247 ## filesystem-related functions
3249 sub get_file_owner
{
3252 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3253 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3254 if (!defined $gcos) {
3258 $owner =~ s/[,;].*$//;
3259 return to_utf8
($owner);
3262 # assume that file exists
3264 my $filename = shift;
3266 open my $fd, '<', $filename;
3267 print map { to_utf8
($_) } <$fd>;
3271 ## ......................................................................
3272 ## mimetype related functions
3274 sub mimetype_guess_file
{
3275 my $filename = shift;
3276 my $mimemap = shift;
3277 -r
$mimemap or return undef;
3280 open(my $mh, '<', $mimemap) or return undef;
3282 next if m/^#/; # skip comments
3283 my ($mimetype, $exts) = split(/\t+/);
3284 if (defined $exts) {
3285 my @exts = split(/\s+/, $exts);
3286 foreach my $ext (@exts) {
3287 $mimemap{$ext} = $mimetype;
3293 $filename =~ /\.([^.]*)$/;
3294 return $mimemap{$1};
3297 sub mimetype_guess
{
3298 my $filename = shift;
3300 $filename =~ /\./ or return undef;
3302 if ($mimetypes_file) {
3303 my $file = $mimetypes_file;
3304 if ($file !~ m!^/!) { # if it is relative path
3305 # it is relative to project
3306 $file = "$projectroot/$project/$file";
3308 $mime = mimetype_guess_file
($filename, $file);
3310 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3316 my $filename = shift;
3319 my $mime = mimetype_guess
($filename);
3320 $mime and return $mime;
3324 return $default_blob_plain_mimetype unless $fd;
3327 return 'text/plain';
3328 } elsif (! $filename) {
3329 return 'application/octet-stream';
3330 } elsif ($filename =~ m/\.png$/i) {
3332 } elsif ($filename =~ m/\.gif$/i) {
3334 } elsif ($filename =~ m/\.jpe?g$/i) {
3335 return 'image/jpeg';
3337 return 'application/octet-stream';
3341 sub blob_contenttype
{
3342 my ($fd, $file_name, $type) = @_;
3344 $type ||= blob_mimetype
($fd, $file_name);
3345 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3346 $type .= "; charset=$default_text_plain_charset";
3352 # guess file syntax for syntax highlighting; return undef if no highlighting
3353 # the name of syntax can (in the future) depend on syntax highlighter used
3354 sub guess_file_syntax
{
3355 my ($highlight, $mimetype, $file_name) = @_;
3356 return undef unless ($highlight && defined $file_name);
3357 my $basename = basename
($file_name, '.in');
3358 return $highlight_basename{$basename}
3359 if exists $highlight_basename{$basename};
3361 $basename =~ /\.([^.]*)$/;
3362 my $ext = $1 or return undef;
3363 return $highlight_ext{$ext}
3364 if exists $highlight_ext{$ext};
3369 # run highlighter and return FD of its output,
3370 # or return original FD if no highlighting
3371 sub run_highlighter
{
3372 my ($fd, $highlight, $syntax) = @_;
3373 return $fd unless ($highlight && defined $syntax);
3376 or die_error
(404, "Reading blob failed");
3377 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3378 quote_command
($highlight_bin).
3379 " --xhtml --fragment --syntax $syntax |"
3380 or die_error
(500, "Couldn't open file or run syntax highlighter");
3384 ## ======================================================================
3385 ## functions printing HTML: header, footer, error page
3387 sub get_page_title
{
3388 my $title = to_utf8
($site_name);
3390 return $title unless (defined $project);
3391 $title .= " - " . to_utf8
($project);
3393 return $title unless (defined $action);
3394 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3396 return $title unless (defined $file_name);
3397 $title .= " - " . esc_path
($file_name);
3398 if ($action eq "tree" && $file_name !~ m
|/$|) {
3405 sub git_header_html
{
3406 my $status = shift || "200 OK";
3407 my $expires = shift;
3410 my $title = get_page_title
();
3412 # require explicit support from the UA if we are to send the page as
3413 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3414 # we have to do this because MSIE sometimes globs '*/*', pretending to
3415 # support xhtml+xml but choking when it gets what it asked for.
3416 if (defined $cgi->http('HTTP_ACCEPT') &&
3417 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3418 $cgi->Accept('application/xhtml+xml') != 0) {
3419 $content_type = 'application/xhtml+xml';
3421 $content_type = 'text/html';
3423 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3424 -status
=> $status, -expires
=> $expires)
3425 unless ($opts{'-no_http_header'});
3426 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3428 <?xml version="1.0" encoding="utf-8"?>
3429 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3430 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3431 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3432 <!-- git core binaries version $git_version -->
3434 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3435 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3436 <meta name="robots" content="index, nofollow"/>
3437 <title>$title</title>
3439 # the stylesheet, favicon etc urls won't work correctly with path_info
3440 # unless we set the appropriate base URL
3441 if ($ENV{'PATH_INFO'}) {
3442 print "<base href=\"".esc_url
($base_url)."\" />\n";
3444 # print out each stylesheet that exist, providing backwards capability
3445 # for those people who defined $stylesheet in a config file
3446 if (defined $stylesheet) {
3447 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3449 foreach my $stylesheet (@stylesheets) {
3450 next unless $stylesheet;
3451 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3454 if (defined $project) {
3455 my %href_params = get_feed_info
();
3456 if (!exists $href_params{'-title'}) {
3457 $href_params{'-title'} = 'log';
3460 foreach my $format qw(RSS Atom) {
3461 my $type = lc($format);
3463 '-rel' => 'alternate',
3464 '-title' => "$project - $href_params{'-title'} - $format feed",
3465 '-type' => "application/$type+xml"
3468 $href_params{'action'} = $type;
3469 $link_attr{'-href'} = href
(%href_params);
3471 "rel=\"$link_attr{'-rel'}\" ".
3472 "title=\"$link_attr{'-title'}\" ".
3473 "href=\"$link_attr{'-href'}\" ".
3474 "type=\"$link_attr{'-type'}\" ".
3477 $href_params{'extra_options'} = '--no-merges';
3478 $link_attr{'-href'} = href
(%href_params);
3479 $link_attr{'-title'} .= ' (no merges)';
3481 "rel=\"$link_attr{'-rel'}\" ".
3482 "title=\"$link_attr{'-title'}\" ".
3483 "href=\"$link_attr{'-href'}\" ".
3484 "type=\"$link_attr{'-type'}\" ".
3489 printf('<link rel="alternate" title="%s projects list" '.
3490 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3491 $site_name, href
(project
=>undef, action
=>"project_index"));
3492 printf('<link rel="alternate" title="%s projects feeds" '.
3493 'href="%s" type="text/x-opml" />'."\n",
3494 $site_name, href
(project
=>undef, action
=>"opml"));
3496 if (defined $favicon) {
3497 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3503 if (defined $site_header && -f
$site_header) {
3504 insert_file
($site_header);
3507 print "<div class=\"page_header\">\n" .
3508 $cgi->a({-href
=> esc_url
($logo_url),
3509 -title
=> $logo_label},
3510 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3511 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3512 if (defined $project) {
3513 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3514 if (defined $action) {
3521 my $have_search = gitweb_check_feature
('search');
3522 if (defined $project && $have_search) {
3523 if (!defined $searchtext) {
3527 if (defined $hash_base) {
3528 $search_hash = $hash_base;
3529 } elsif (defined $hash) {
3530 $search_hash = $hash;
3532 $search_hash = "HEAD";
3534 my $action = $my_uri;
3535 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3536 if ($use_pathinfo) {
3537 $action .= "/".esc_url
($project);
3539 print $cgi->startform(-method => "get", -action
=> $action) .
3540 "<div class=\"search\">\n" .
3542 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3543 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3544 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3545 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3546 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3547 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3549 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3550 "<span title=\"Extended regular expression\">" .
3551 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3552 -checked
=> $search_use_regexp) .
3555 $cgi->end_form() . "\n";
3559 sub git_footer_html
{
3560 my $feed_class = 'rss_logo';
3562 print "<div class=\"page_footer\">\n";
3563 if (defined $project) {
3564 my $descr = git_get_project_description
($project);
3565 if (defined $descr) {
3566 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3569 my %href_params = get_feed_info
();
3570 if (!%href_params) {
3571 $feed_class .= ' generic';
3573 $href_params{'-title'} ||= 'log';
3575 foreach my $format qw(RSS Atom) {
3576 $href_params{'action'} = lc($format);
3577 print $cgi->a({-href
=> href
(%href_params),
3578 -title
=> "$href_params{'-title'} $format feed",
3579 -class => $feed_class}, $format)."\n";
3583 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3584 -class => $feed_class}, "OPML") . " ";
3585 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3586 -class => $feed_class}, "TXT") . "\n";
3588 print "</div>\n"; # class="page_footer"
3590 if (defined $t0 && gitweb_check_feature
('timed')) {
3591 print "<div id=\"generating_info\">\n";
3592 print 'This page took '.
3593 '<span id="generating_time" class="time_span">'.
3594 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3597 '<span id="generating_cmd">'.
3598 $number_of_git_cmds.
3599 '</span> git commands '.
3601 print "</div>\n"; # class="page_footer"
3604 if (defined $site_footer && -f
$site_footer) {
3605 insert_file
($site_footer);
3608 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3609 if (defined $action &&
3610 $action eq 'blame_incremental') {
3611 print qq
!<script type
="text/javascript">\n!.
3612 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3613 qq
! "!. href() .qq!");\n!.
3615 } elsif (gitweb_check_feature
('javascript-actions')) {
3616 print qq
!<script type
="text/javascript">\n!.
3617 qq
!window
.onload
= fixLinks
;\n!.
3625 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3626 # Example: die_error(404, 'Hash not found')
3627 # By convention, use the following status codes (as defined in RFC 2616):
3628 # 400: Invalid or missing CGI parameters, or
3629 # requested object exists but has wrong type.
3630 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3631 # this server or project.
3632 # 404: Requested object/revision/project doesn't exist.
3633 # 500: The server isn't configured properly, or
3634 # an internal error occurred (e.g. failed assertions caused by bugs), or
3635 # an unknown error occurred (e.g. the git binary died unexpectedly).
3636 # 503: The server is currently unavailable (because it is overloaded,
3637 # or down for maintenance). Generally, this is a temporary state.
3639 my $status = shift || 500;
3640 my $error = esc_html
(shift) || "Internal Server Error";
3644 my %http_responses = (
3645 400 => '400 Bad Request',
3646 403 => '403 Forbidden',
3647 404 => '404 Not Found',
3648 500 => '500 Internal Server Error',
3649 503 => '503 Service Unavailable',
3651 git_header_html
($http_responses{$status}, undef, %opts);
3653 <div class="page_body">
3658 if (defined $extra) {
3666 unless ($opts{'-error_handler'});
3669 ## ----------------------------------------------------------------------
3670 ## functions printing or outputting HTML: navigation
3672 sub git_print_page_nav
{
3673 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3674 $extra = '' if !defined $extra; # pager or formats
3676 my @navs = qw(summary shortlog log commit commitdiff tree);
3678 @navs = grep { $_ ne $suppress } @navs;
3681 my %arg = map { $_ => {action
=>$_} } @navs;
3682 if (defined $head) {
3683 for (qw(commit commitdiff)) {
3684 $arg{$_}{'hash'} = $head;
3686 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3687 for (qw(shortlog log)) {
3688 $arg{$_}{'hash'} = $head;
3693 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3694 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3696 my @actions = gitweb_get_feature
('actions');
3699 'n' => $project, # project name
3700 'f' => $git_dir, # project path within filesystem
3701 'h' => $treehead || '', # current hash ('h' parameter)
3702 'b' => $treebase || '', # hash base ('hb' parameter)
3705 my ($label, $link, $pos) = splice(@actions,0,3);
3707 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3709 $link =~ s/%([%nfhb])/$repl{$1}/g;
3710 $arg{$label}{'_href'} = $link;
3713 print "<div class=\"page_nav\">\n" .
3715 map { $_ eq $current ?
3716 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3718 print "<br/>\n$extra<br/>\n" .
3722 sub format_paging_nav
{
3723 my ($action, $page, $has_next_link) = @_;
3729 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3731 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3732 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3734 $paging_nav .= "first ⋅ prev";
3737 if ($has_next_link) {
3738 $paging_nav .= " ⋅ " .
3739 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3740 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3742 $paging_nav .= " ⋅ next";
3748 ## ......................................................................
3749 ## functions printing or outputting HTML: div
3751 sub git_print_header_div
{
3752 my ($action, $title, $hash, $hash_base) = @_;
3755 $args{'action'} = $action;
3756 $args{'hash'} = $hash if $hash;
3757 $args{'hash_base'} = $hash_base if $hash_base;
3759 print "<div class=\"header\">\n" .
3760 $cgi->a({-href
=> href
(%args), -class => "title"},
3761 $title ? $title : $action) .
3765 sub print_local_time
{
3766 print format_local_time
(@_);
3769 sub format_local_time
{
3772 if ($date{'hour_local'} < 6) {
3773 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3774 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3776 $localtime .= sprintf(" (%02d:%02d %s)",
3777 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3783 # Outputs the author name and date in long form
3784 sub git_print_authorship
{
3787 my $tag = $opts{-tag
} || 'div';
3788 my $author = $co->{'author_name'};
3790 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3791 print "<$tag class=\"author_date\">" .
3792 format_search_author
($author, "author", esc_html
($author)) .
3794 print_local_time
(%ad) if ($opts{-localtime});
3795 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3799 # Outputs table rows containing the full author or committer information,
3800 # in the format expected for 'commit' view (& similar).
3801 # Parameters are a commit hash reference, followed by the list of people
3802 # to output information for. If the list is empty it defaults to both
3803 # author and committer.
3804 sub git_print_authorship_rows
{
3806 # too bad we can't use @people = @_ || ('author', 'committer')
3808 @people = ('author', 'committer') unless @people;
3809 foreach my $who (@people) {
3810 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3811 print "<tr><td>$who</td><td>" .
3812 format_search_author
($co->{"${who}_name"}, $who,
3813 esc_html
($co->{"${who}_name"})) . " " .
3814 format_search_author
($co->{"${who}_email"}, $who,
3815 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3816 "</td><td rowspan=\"2\">" .
3817 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3820 "<td></td><td> $wd{'rfc2822'}";
3821 print_local_time
(%wd);
3827 sub git_print_page_path
{
3833 print "<div class=\"page_path\">";
3834 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3835 -title
=> 'tree root'}, to_utf8
("[$project]"));
3837 if (defined $name) {
3838 my @dirname = split '/', $name;
3839 my $basename = pop @dirname;
3842 foreach my $dir (@dirname) {
3843 $fullname .= ($fullname ? '/' : '') . $dir;
3844 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3846 -title
=> $fullname}, esc_path
($dir));
3849 if (defined $type && $type eq 'blob') {
3850 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3852 -title
=> $name}, esc_path
($basename));
3853 } elsif (defined $type && $type eq 'tree') {
3854 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3856 -title
=> $name}, esc_path
($basename));
3859 print esc_path
($basename);
3862 print "<br/></div>\n";
3869 if ($opts{'-remove_title'}) {
3870 # remove title, i.e. first line of log
3873 # remove leading empty lines
3874 while (defined $log->[0] && $log->[0] eq "") {
3881 foreach my $line (@$log) {
3882 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3885 if (! $opts{'-remove_signoff'}) {
3886 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3889 # remove signoff lines
3896 # print only one empty line
3897 # do not print empty line after signoff
3899 next if ($empty || $signoff);
3905 print format_log_line_html
($line) . "<br/>\n";
3908 if ($opts{'-final_empty_line'}) {
3909 # end with single empty line
3910 print "<br/>\n" unless $empty;
3914 # return link target (what link points to)
3915 sub git_get_link_target
{
3920 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3924 $link_target = <$fd>;
3929 return $link_target;
3932 # given link target, and the directory (basedir) the link is in,
3933 # return target of link relative to top directory (top tree);
3934 # return undef if it is not possible (including absolute links).
3935 sub normalize_link_target
{
3936 my ($link_target, $basedir) = @_;
3938 # absolute symlinks (beginning with '/') cannot be normalized
3939 return if (substr($link_target, 0, 1) eq '/');
3941 # normalize link target to path from top (root) tree (dir)
3944 $path = $basedir . '/' . $link_target;
3946 # we are in top (root) tree (dir)
3947 $path = $link_target;
3950 # remove //, /./, and /../
3952 foreach my $part (split('/', $path)) {
3953 # discard '.' and ''
3954 next if (!$part || $part eq '.');
3956 if ($part eq '..') {
3960 # link leads outside repository (outside top dir)
3964 push @path_parts, $part;
3967 $path = join('/', @path_parts);
3972 # print tree entry (row of git_tree), but without encompassing <tr> element
3973 sub git_print_tree_entry
{
3974 my ($t, $basedir, $hash_base, $have_blame) = @_;
3977 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3979 # The format of a table row is: mode list link. Where mode is
3980 # the mode of the entry, list is the name of the entry, an href,
3981 # and link is the action links of the entry.
3983 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3984 if (exists $t->{'size'}) {
3985 print "<td class=\"size\">$t->{'size'}</td>\n";
3987 if ($t->{'type'} eq "blob") {
3988 print "<td class=\"list\">" .
3989 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3990 file_name
=>"$basedir$t->{'name'}", %base_key),
3991 -class => "list"}, esc_path
($t->{'name'}));
3992 if (S_ISLNK
(oct $t->{'mode'})) {
3993 my $link_target = git_get_link_target
($t->{'hash'});
3995 my $norm_target = normalize_link_target
($link_target, $basedir);
3996 if (defined $norm_target) {
3998 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3999 file_name
=>$norm_target),
4000 -title
=> $norm_target}, esc_path
($link_target));
4002 print " -> " . esc_path
($link_target);
4007 print "<td class=\"link\">";
4008 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4009 file_name
=>"$basedir$t->{'name'}", %base_key)},
4013 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4014 file_name
=>"$basedir$t->{'name'}", %base_key)},
4017 if (defined $hash_base) {
4019 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4020 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4024 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4025 file_name
=>"$basedir$t->{'name'}")},
4029 } elsif ($t->{'type'} eq "tree") {
4030 print "<td class=\"list\">";
4031 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4032 file_name
=>"$basedir$t->{'name'}",
4034 esc_path
($t->{'name'}));
4036 print "<td class=\"link\">";
4037 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4038 file_name
=>"$basedir$t->{'name'}",
4041 if (defined $hash_base) {
4043 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4044 file_name
=>"$basedir$t->{'name'}")},
4049 # unknown object: we can only present history for it
4050 # (this includes 'commit' object, i.e. submodule support)
4051 print "<td class=\"list\">" .
4052 esc_path
($t->{'name'}) .
4054 print "<td class=\"link\">";
4055 if (defined $hash_base) {
4056 print $cgi->a({-href
=> href
(action
=>"history",
4057 hash_base
=>$hash_base,
4058 file_name
=>"$basedir$t->{'name'}")},
4065 ## ......................................................................
4066 ## functions printing large fragments of HTML
4068 # get pre-image filenames for merge (combined) diff
4069 sub fill_from_file_info
{
4070 my ($diff, @parents) = @_;
4072 $diff->{'from_file'} = [ ];
4073 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4074 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4075 if ($diff->{'status'}[$i] eq 'R' ||
4076 $diff->{'status'}[$i] eq 'C') {
4077 $diff->{'from_file'}[$i] =
4078 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4085 # is current raw difftree line of file deletion
4087 my $diffinfo = shift;
4089 return $diffinfo->{'to_id'} eq ('0' x
40);
4092 # does patch correspond to [previous] difftree raw line
4093 # $diffinfo - hashref of parsed raw diff format
4094 # $patchinfo - hashref of parsed patch diff format
4095 # (the same keys as in $diffinfo)
4096 sub is_patch_split
{
4097 my ($diffinfo, $patchinfo) = @_;
4099 return defined $diffinfo && defined $patchinfo
4100 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4104 sub git_difftree_body
{
4105 my ($difftree, $hash, @parents) = @_;
4106 my ($parent) = $parents[0];
4107 my $have_blame = gitweb_check_feature
('blame');
4108 print "<div class=\"list_head\">\n";
4109 if ($#{$difftree} > 10) {
4110 print(($#{$difftree} + 1) . " files changed:\n");
4114 print "<table class=\"" .
4115 (@parents > 1 ? "combined " : "") .
4118 # header only for combined diff in 'commitdiff' view
4119 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
4122 print "<thead><tr>\n" .
4123 "<th></th><th></th>\n"; # filename, patchN link
4124 for (my $i = 0; $i < @parents; $i++) {
4125 my $par = $parents[$i];
4127 $cgi->a({-href
=> href
(action
=>"commitdiff",
4128 hash
=>$hash, hash_parent
=>$par),
4129 -title
=> 'commitdiff to parent number ' .
4130 ($i+1) . ': ' . substr($par,0,7)},
4134 print "</tr></thead>\n<tbody>\n";
4139 foreach my $line (@{$difftree}) {
4140 my $diff = parsed_difftree_line
($line);
4143 print "<tr class=\"dark\">\n";
4145 print "<tr class=\"light\">\n";
4149 if (exists $diff->{'nparents'}) { # combined diff
4151 fill_from_file_info
($diff, @parents)
4152 unless exists $diff->{'from_file'};
4154 if (!is_deleted
($diff)) {
4155 # file exists in the result (child) commit
4157 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4158 file_name
=>$diff->{'to_file'},
4160 -class => "list"}, esc_path
($diff->{'to_file'})) .
4164 esc_path
($diff->{'to_file'}) .
4168 if ($action eq 'commitdiff') {
4171 print "<td class=\"link\">" .
4172 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4177 my $has_history = 0;
4178 my $not_deleted = 0;
4179 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4180 my $hash_parent = $parents[$i];
4181 my $from_hash = $diff->{'from_id'}[$i];
4182 my $from_path = $diff->{'from_file'}[$i];
4183 my $status = $diff->{'status'}[$i];
4185 $has_history ||= ($status ne 'A');
4186 $not_deleted ||= ($status ne 'D');
4188 if ($status eq 'A') {
4189 print "<td class=\"link\" align=\"right\"> | </td>\n";
4190 } elsif ($status eq 'D') {
4191 print "<td class=\"link\">" .
4192 $cgi->a({-href
=> href
(action
=>"blob",
4195 file_name
=>$from_path)},
4199 if ($diff->{'to_id'} eq $from_hash) {
4200 print "<td class=\"link nochange\">";
4202 print "<td class=\"link\">";
4204 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4205 hash
=>$diff->{'to_id'},
4206 hash_parent
=>$from_hash,
4208 hash_parent_base
=>$hash_parent,
4209 file_name
=>$diff->{'to_file'},
4210 file_parent
=>$from_path)},
4216 print "<td class=\"link\">";
4218 print $cgi->a({-href
=> href
(action
=>"blob",
4219 hash
=>$diff->{'to_id'},
4220 file_name
=>$diff->{'to_file'},
4223 print " | " if ($has_history);
4226 print $cgi->a({-href
=> href
(action
=>"history",
4227 file_name
=>$diff->{'to_file'},
4234 next; # instead of 'else' clause, to avoid extra indent
4236 # else ordinary diff
4238 my ($to_mode_oct, $to_mode_str, $to_file_type);
4239 my ($from_mode_oct, $from_mode_str, $from_file_type);
4240 if ($diff->{'to_mode'} ne ('0' x
6)) {
4241 $to_mode_oct = oct $diff->{'to_mode'};
4242 if (S_ISREG
($to_mode_oct)) { # only for regular file
4243 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4245 $to_file_type = file_type
($diff->{'to_mode'});
4247 if ($diff->{'from_mode'} ne ('0' x
6)) {
4248 $from_mode_oct = oct $diff->{'from_mode'};
4249 if (S_ISREG
($to_mode_oct)) { # only for regular file
4250 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4252 $from_file_type = file_type
($diff->{'from_mode'});
4255 if ($diff->{'status'} eq "A") { # created
4256 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4257 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4258 $mode_chng .= "]</span>";
4260 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4261 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4262 -class => "list"}, esc_path
($diff->{'file'}));
4264 print "<td>$mode_chng</td>\n";
4265 print "<td class=\"link\">";
4266 if ($action eq 'commitdiff') {
4269 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4272 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4273 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4277 } elsif ($diff->{'status'} eq "D") { # deleted
4278 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4280 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4281 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4282 -class => "list"}, esc_path
($diff->{'file'}));
4284 print "<td>$mode_chng</td>\n";
4285 print "<td class=\"link\">";
4286 if ($action eq 'commitdiff') {
4289 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4292 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4293 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4296 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4297 file_name
=>$diff->{'file'})},
4300 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4301 file_name
=>$diff->{'file'})},
4305 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4306 my $mode_chnge = "";
4307 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4308 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4309 if ($from_file_type ne $to_file_type) {
4310 $mode_chnge .= " from $from_file_type to $to_file_type";
4312 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4313 if ($from_mode_str && $to_mode_str) {
4314 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4315 } elsif ($to_mode_str) {
4316 $mode_chnge .= " mode: $to_mode_str";
4319 $mode_chnge .= "]</span>\n";
4322 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4323 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4324 -class => "list"}, esc_path
($diff->{'file'}));
4326 print "<td>$mode_chnge</td>\n";
4327 print "<td class=\"link\">";
4328 if ($action eq 'commitdiff') {
4331 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4333 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4334 # "commit" view and modified file (not onlu mode changed)
4335 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4336 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4337 hash_base
=>$hash, hash_parent_base
=>$parent,
4338 file_name
=>$diff->{'file'})},
4342 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4343 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4346 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4347 file_name
=>$diff->{'file'})},
4350 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4351 file_name
=>$diff->{'file'})},
4355 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4356 my %status_name = ('R' => 'moved', 'C' => 'copied');
4357 my $nstatus = $status_name{$diff->{'status'}};
4359 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4360 # mode also for directories, so we cannot use $to_mode_str
4361 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4364 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4365 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4366 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4367 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4368 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4369 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4370 -class => "list"}, esc_path
($diff->{'from_file'})) .
4371 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4372 "<td class=\"link\">";
4373 if ($action eq 'commitdiff') {
4376 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4378 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4379 # "commit" view and modified file (not only pure rename or copy)
4380 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4381 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4382 hash_base
=>$hash, hash_parent_base
=>$parent,
4383 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4387 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4388 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4391 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4392 file_name
=>$diff->{'to_file'})},
4395 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4396 file_name
=>$diff->{'to_file'})},
4400 } # we should not encounter Unmerged (U) or Unknown (X) status
4403 print "</tbody>" if $has_header;
4407 sub git_patchset_body
{
4408 my ($fd, $difftree, $hash, @hash_parents) = @_;
4409 my ($hash_parent) = $hash_parents[0];
4411 my $is_combined = (@hash_parents > 1);
4413 my $patch_number = 0;
4419 print "<div class=\"patchset\">\n";
4421 # skip to first patch
4422 while ($patch_line = <$fd>) {
4425 last if ($patch_line =~ m/^diff /);
4429 while ($patch_line) {
4431 # parse "git diff" header line
4432 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4433 # $1 is from_name, which we do not use
4434 $to_name = unquote
($2);
4435 $to_name =~ s!^b/!!;
4436 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4437 # $1 is 'cc' or 'combined', which we do not use
4438 $to_name = unquote
($2);
4443 # check if current patch belong to current raw line
4444 # and parse raw git-diff line if needed
4445 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4446 # this is continuation of a split patch
4447 print "<div class=\"patch cont\">\n";
4449 # advance raw git-diff output if needed
4450 $patch_idx++ if defined $diffinfo;
4452 # read and prepare patch information
4453 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4455 # compact combined diff output can have some patches skipped
4456 # find which patch (using pathname of result) we are at now;
4458 while ($to_name ne $diffinfo->{'to_file'}) {
4459 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4460 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4461 "</div>\n"; # class="patch"
4466 last if $patch_idx > $#$difftree;
4467 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4471 # modifies %from, %to hashes
4472 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4474 # this is first patch for raw difftree line with $patch_idx index
4475 # we index @$difftree array from 0, but number patches from 1
4476 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4480 #assert($patch_line =~ m/^diff /) if DEBUG;
4481 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4483 # print "git diff" header
4484 print format_git_diff_header_line
($patch_line, $diffinfo,
4487 # print extended diff header
4488 print "<div class=\"diff extended_header\">\n";
4490 while ($patch_line = <$fd>) {
4493 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4495 print format_extended_diff_header_line
($patch_line, $diffinfo,
4498 print "</div>\n"; # class="diff extended_header"
4500 # from-file/to-file diff header
4501 if (! $patch_line) {
4502 print "</div>\n"; # class="patch"
4505 next PATCH
if ($patch_line =~ m/^diff /);
4506 #assert($patch_line =~ m/^---/) if DEBUG;
4508 my $last_patch_line = $patch_line;
4509 $patch_line = <$fd>;
4511 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4513 print format_diff_from_to_header
($last_patch_line, $patch_line,
4514 $diffinfo, \
%from, \
%to,
4519 while ($patch_line = <$fd>) {
4522 next PATCH
if ($patch_line =~ m/^diff /);
4524 print format_diff_line
($patch_line, \
%from, \
%to);
4528 print "</div>\n"; # class="patch"
4531 # for compact combined (--cc) format, with chunk and patch simplification
4532 # the patchset might be empty, but there might be unprocessed raw lines
4533 for (++$patch_idx if $patch_number > 0;
4534 $patch_idx < @$difftree;
4536 # read and prepare patch information
4537 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4539 # generate anchor for "patch" links in difftree / whatchanged part
4540 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4541 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4542 "</div>\n"; # class="patch"
4547 if ($patch_number == 0) {
4548 if (@hash_parents > 1) {
4549 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4551 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4555 print "</div>\n"; # class="patchset"
4558 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4560 # fills project list info (age, description, owner, forks) for each
4561 # project in the list, removing invalid projects from returned list
4562 # NOTE: modifies $projlist, but does not remove entries from it
4563 sub fill_project_list_info
{
4564 my ($projlist, $check_forks) = @_;
4567 my $show_ctags = gitweb_check_feature
('ctags');
4569 foreach my $pr (@$projlist) {
4570 my (@activity) = git_get_last_activity
($pr->{'path'});
4571 unless (@activity) {
4574 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4575 if (!defined $pr->{'descr'}) {
4576 my $descr = git_get_project_description
($pr->{'path'}) || "";
4577 $descr = to_utf8
($descr);
4578 $pr->{'descr_long'} = $descr;
4579 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4581 if (!defined $pr->{'owner'}) {
4582 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4585 my $pname = $pr->{'path'};
4586 if (($pname =~ s/\.git$//) &&
4587 ($pname !~ /\/$/) &&
4588 (-d
"$projectroot/$pname")) {
4589 $pr->{'forks'} = "-d $projectroot/$pname";
4594 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4595 push @projects, $pr;
4601 # print 'sort by' <th> element, generating 'sort by $name' replay link
4602 # if that order is not selected
4604 print format_sort_th
(@_);
4607 sub format_sort_th
{
4608 my ($name, $order, $header) = @_;
4610 $header ||= ucfirst($name);
4612 if ($order eq $name) {
4613 $sort_th .= "<th>$header</th>\n";
4615 $sort_th .= "<th>" .
4616 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4617 -class => "header"}, $header) .
4624 sub git_project_list_body
{
4625 # actually uses global variable $project
4626 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4628 my $check_forks = gitweb_check_feature
('forks');
4629 my @projects = fill_project_list_info
($projlist, $check_forks);
4631 $order ||= $default_projects_order;
4632 $from = 0 unless defined $from;
4633 $to = $#projects if (!defined $to || $#projects < $to);
4636 project
=> { key
=> 'path', type
=> 'str' },
4637 descr
=> { key
=> 'descr_long', type
=> 'str' },
4638 owner
=> { key
=> 'owner', type
=> 'str' },
4639 age
=> { key
=> 'age', type
=> 'num' }
4641 my $oi = $order_info{$order};
4642 if ($oi->{'type'} eq 'str') {
4643 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4645 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4648 my $show_ctags = gitweb_check_feature
('ctags');
4651 foreach my $p (@projects) {
4652 foreach my $ct (keys %{$p->{'ctags'}}) {
4653 $ctags{$ct} += $p->{'ctags'}->{$ct};
4656 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4657 print git_show_project_tagcloud
($cloud, 64);
4660 print "<table class=\"project_list\">\n";
4661 unless ($no_header) {
4664 print "<th></th>\n";
4666 print_sort_th
('project', $order, 'Project');
4667 print_sort_th
('descr', $order, 'Description');
4668 print_sort_th
('owner', $order, 'Owner');
4669 print_sort_th
('age', $order, 'Last Change');
4670 print "<th></th>\n" . # for links
4674 my $tagfilter = $cgi->param('by_tag');
4675 for (my $i = $from; $i <= $to; $i++) {
4676 my $pr = $projects[$i];
4678 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4679 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4680 and not $pr->{'descr_long'} =~ /$searchtext/;
4681 # Weed out forks or non-matching entries of search
4683 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4684 $forkbase="^$forkbase" if $forkbase;
4685 next if not $searchtext and not $tagfilter and $show_ctags
4686 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4690 print "<tr class=\"dark\">\n";
4692 print "<tr class=\"light\">\n";
4697 if ($pr->{'forks'}) {
4698 print "<!-- $pr->{'forks'} -->\n";
4699 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4703 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4704 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4705 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4706 -class => "list", -title
=> $pr->{'descr_long'}},
4707 esc_html
($pr->{'descr'})) . "</td>\n" .
4708 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4709 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4710 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4711 "<td class=\"link\">" .
4712 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4713 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4714 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4715 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4716 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4720 if (defined $extra) {
4723 print "<td></td>\n";
4725 print "<td colspan=\"5\">$extra</td>\n" .
4732 # uses global variable $project
4733 my ($commitlist, $from, $to, $refs, $extra) = @_;
4735 $from = 0 unless defined $from;
4736 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4738 for (my $i = 0; $i <= $to; $i++) {
4739 my %co = %{$commitlist->[$i]};
4741 my $commit = $co{'id'};
4742 my $ref = format_ref_marker
($refs, $commit);
4743 my %ad = parse_date
($co{'author_epoch'});
4744 git_print_header_div
('commit',
4745 "<span class=\"age\">$co{'age_string'}</span>" .
4746 esc_html
($co{'title'}) . $ref,
4748 print "<div class=\"title_text\">\n" .
4749 "<div class=\"log_link\">\n" .
4750 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4752 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4754 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4757 git_print_authorship
(\
%co, -tag
=> 'span');
4758 print "<br/>\n</div>\n";
4760 print "<div class=\"log_body\">\n";
4761 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4765 print "<div class=\"page_nav\">\n";
4771 sub git_shortlog_body
{
4772 # uses global variable $project
4773 my ($commitlist, $from, $to, $refs, $extra) = @_;
4775 $from = 0 unless defined $from;
4776 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4778 print "<table class=\"shortlog\">\n";
4780 for (my $i = $from; $i <= $to; $i++) {
4781 my %co = %{$commitlist->[$i]};
4782 my $commit = $co{'id'};
4783 my $ref = format_ref_marker
($refs, $commit);
4785 print "<tr class=\"dark\">\n";
4787 print "<tr class=\"light\">\n";
4790 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4791 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4792 format_author_html
('td', \
%co, 10) . "<td>";
4793 print format_subject_html
($co{'title'}, $co{'title_short'},
4794 href
(action
=>"commit", hash
=>$commit), $ref);
4796 "<td class=\"link\">" .
4797 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4798 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4799 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4800 my $snapshot_links = format_snapshot_links
($commit);
4801 if (defined $snapshot_links) {
4802 print " | " . $snapshot_links;
4807 if (defined $extra) {
4809 "<td colspan=\"4\">$extra</td>\n" .
4815 sub git_history_body
{
4816 # Warning: assumes constant type (blob or tree) during history
4817 my ($commitlist, $from, $to, $refs, $extra,
4818 $file_name, $file_hash, $ftype) = @_;
4820 $from = 0 unless defined $from;
4821 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4823 print "<table class=\"history\">\n";
4825 for (my $i = $from; $i <= $to; $i++) {
4826 my %co = %{$commitlist->[$i]};
4830 my $commit = $co{'id'};
4832 my $ref = format_ref_marker
($refs, $commit);
4835 print "<tr class=\"dark\">\n";
4837 print "<tr class=\"light\">\n";
4840 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4841 # shortlog: format_author_html('td', \%co, 10)
4842 format_author_html
('td', \
%co, 15, 3) . "<td>";
4843 # originally git_history used chop_str($co{'title'}, 50)
4844 print format_subject_html
($co{'title'}, $co{'title_short'},
4845 href
(action
=>"commit", hash
=>$commit), $ref);
4847 "<td class=\"link\">" .
4848 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4849 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4851 if ($ftype eq 'blob') {
4852 my $blob_current = $file_hash;
4853 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4854 if (defined $blob_current && defined $blob_parent &&
4855 $blob_current ne $blob_parent) {
4857 $cgi->a({-href
=> href
(action
=>"blobdiff",
4858 hash
=>$blob_current, hash_parent
=>$blob_parent,
4859 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4860 file_name
=>$file_name)},
4867 if (defined $extra) {
4869 "<td colspan=\"4\">$extra</td>\n" .
4876 # uses global variable $project
4877 my ($taglist, $from, $to, $extra) = @_;
4878 $from = 0 unless defined $from;
4879 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4881 print "<table class=\"tags\">\n";
4883 for (my $i = $from; $i <= $to; $i++) {
4884 my $entry = $taglist->[$i];
4886 my $comment = $tag{'subject'};
4888 if (defined $comment) {
4889 $comment_short = chop_str
($comment, 30, 5);
4892 print "<tr class=\"dark\">\n";
4894 print "<tr class=\"light\">\n";
4897 if (defined $tag{'age'}) {
4898 print "<td><i>$tag{'age'}</i></td>\n";
4900 print "<td></td>\n";
4903 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4904 -class => "list name"}, esc_html
($tag{'name'})) .
4907 if (defined $comment) {
4908 print format_subject_html
($comment, $comment_short,
4909 href
(action
=>"tag", hash
=>$tag{'id'}));
4912 "<td class=\"selflink\">";
4913 if ($tag{'type'} eq "tag") {
4914 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4919 "<td class=\"link\">" . " | " .
4920 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4921 if ($tag{'reftype'} eq "commit") {
4922 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4923 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4924 } elsif ($tag{'reftype'} eq "blob") {
4925 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4930 if (defined $extra) {
4932 "<td colspan=\"5\">$extra</td>\n" .
4938 sub git_heads_body
{
4939 # uses global variable $project
4940 my ($headlist, $head, $from, $to, $extra) = @_;
4941 $from = 0 unless defined $from;
4942 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4944 print "<table class=\"heads\">\n";
4946 for (my $i = $from; $i <= $to; $i++) {
4947 my $entry = $headlist->[$i];
4949 my $curr = $ref{'id'} eq $head;
4951 print "<tr class=\"dark\">\n";
4953 print "<tr class=\"light\">\n";
4956 print "<td><i>$ref{'age'}</i></td>\n" .
4957 ($curr ? "<td class=\"current_head\">" : "<td>") .
4958 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4959 -class => "list name"},esc_html
($ref{'name'})) .
4961 "<td class=\"link\">" .
4962 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4963 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4964 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4968 if (defined $extra) {
4970 "<td colspan=\"3\">$extra</td>\n" .
4976 sub git_search_grep_body
{
4977 my ($commitlist, $from, $to, $extra) = @_;
4978 $from = 0 unless defined $from;
4979 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4981 print "<table class=\"commit_search\">\n";
4983 for (my $i = $from; $i <= $to; $i++) {
4984 my %co = %{$commitlist->[$i]};
4988 my $commit = $co{'id'};
4990 print "<tr class=\"dark\">\n";
4992 print "<tr class=\"light\">\n";
4995 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4996 format_author_html
('td', \
%co, 15, 5) .
4998 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4999 -class => "list subject"},
5000 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5001 my $comment = $co{'comment'};
5002 foreach my $line (@$comment) {
5003 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5004 my ($lead, $match, $trail) = ($1, $2, $3);
5005 $match = chop_str
($match, 70, 5, 'center');
5006 my $contextlen = int((80 - length($match))/2);
5007 $contextlen = 30 if ($contextlen > 30);
5008 $lead = chop_str
($lead, $contextlen, 10, 'left');
5009 $trail = chop_str
($trail, $contextlen, 10, 'right');
5011 $lead = esc_html
($lead);
5012 $match = esc_html
($match);
5013 $trail = esc_html
($trail);
5015 print "$lead<span class=\"match\">$match</span>$trail<br />";
5019 "<td class=\"link\">" .
5020 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5022 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5024 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5028 if (defined $extra) {
5030 "<td colspan=\"3\">$extra</td>\n" .
5036 ## ======================================================================
5037 ## ======================================================================
5040 sub git_project_list
{
5041 my $order = $input_params{'order'};
5042 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5043 die_error
(400, "Unknown order parameter");
5046 my @list = git_get_projects_list
();
5048 die_error
(404, "No projects found");
5052 if (defined $home_text && -f
$home_text) {
5053 print "<div class=\"index_include\">\n";
5054 insert_file
($home_text);
5057 print $cgi->startform(-method => "get") .
5058 "<p class=\"projsearch\">Search:\n" .
5059 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5061 $cgi->end_form() . "\n";
5062 git_project_list_body
(\
@list, $order);
5067 my $order = $input_params{'order'};
5068 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5069 die_error
(400, "Unknown order parameter");
5072 my @list = git_get_projects_list
($project);
5074 die_error
(404, "No forks found");
5078 git_print_page_nav
('','');
5079 git_print_header_div
('summary', "$project forks");
5080 git_project_list_body
(\
@list, $order);
5084 sub git_project_index
{
5085 my @projects = git_get_projects_list
($project);
5088 -type
=> 'text/plain',
5089 -charset
=> 'utf-8',
5090 -content_disposition
=> 'inline; filename="index.aux"');
5092 foreach my $pr (@projects) {
5093 if (!exists $pr->{'owner'}) {
5094 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5097 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5098 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5099 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5100 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5104 print "$path $owner\n";
5109 my $descr = git_get_project_description
($project) || "none";
5110 my %co = parse_commit
("HEAD");
5111 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5112 my $head = $co{'id'};
5114 my $owner = git_get_project_owner
($project);
5116 my $refs = git_get_references
();
5117 # These get_*_list functions return one more to allow us to see if
5118 # there are more ...
5119 my @taglist = git_get_tags_list
(16);
5120 my @headlist = git_get_heads_list
(16);
5122 my $check_forks = gitweb_check_feature
('forks');
5125 @forklist = git_get_projects_list
($project);
5129 git_print_page_nav
('summary','', $head);
5131 print "<div class=\"title\"> </div>\n";
5132 print "<table class=\"projects_list\">\n" .
5133 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5134 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5135 if (defined $cd{'rfc2822'}) {
5136 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5139 # use per project git URL list in $projectroot/$project/cloneurl
5140 # or make project git URL from git base URL and project name
5141 my $url_tag = "URL";
5142 my @url_list = git_get_project_url_list
($project);
5143 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5144 foreach my $git_url (@url_list) {
5145 next unless $git_url;
5146 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5151 my $show_ctags = gitweb_check_feature
('ctags');
5153 my $ctags = git_get_project_ctags
($project);
5154 my $cloud = git_populate_project_tagcloud
($ctags);
5155 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5156 print "</td>\n<td>" unless %$ctags;
5157 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5158 print "</td>\n<td>" if %$ctags;
5159 print git_show_project_tagcloud
($cloud, 48);
5165 # If XSS prevention is on, we don't include README.html.
5166 # TODO: Allow a readme in some safe format.
5167 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5168 print "<div class=\"title\">readme</div>\n" .
5169 "<div class=\"readme\">\n";
5170 insert_file
("$projectroot/$project/README.html");
5171 print "\n</div>\n"; # class="readme"
5174 # we need to request one more than 16 (0..15) to check if
5176 my @commitlist = $head ? parse_commits
($head, 17) : ();
5178 git_print_header_div
('shortlog');
5179 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5180 $#commitlist <= 15 ? undef :
5181 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5185 git_print_header_div
('tags');
5186 git_tags_body
(\
@taglist, 0, 15,
5187 $#taglist <= 15 ? undef :
5188 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5192 git_print_header_div
('heads');
5193 git_heads_body
(\
@headlist, $head, 0, 15,
5194 $#headlist <= 15 ? undef :
5195 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5199 git_print_header_div
('forks');
5200 git_project_list_body
(\
@forklist, 'age', 0, 15,
5201 $#forklist <= 15 ? undef :
5202 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5210 my %tag = parse_tag
($hash);
5213 die_error
(404, "Unknown tag object");
5216 my $head = git_get_head_hash
($project);
5218 git_print_page_nav
('','', $head,undef,$head);
5219 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5220 print "<div class=\"title_text\">\n" .
5221 "<table class=\"object_header\">\n" .
5223 "<td>object</td>\n" .
5224 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5225 $tag{'object'}) . "</td>\n" .
5226 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5227 $tag{'type'}) . "</td>\n" .
5229 if (defined($tag{'author'})) {
5230 git_print_authorship_rows
(\
%tag, 'author');
5232 print "</table>\n\n" .
5234 print "<div class=\"page_body\">";
5235 my $comment = $tag{'comment'};
5236 foreach my $line (@$comment) {
5238 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5244 sub git_blame_common
{
5245 my $format = shift || 'porcelain';
5246 if ($format eq 'porcelain' && $cgi->param('js')) {
5247 $format = 'incremental';
5248 $action = 'blame_incremental'; # for page title etc
5252 gitweb_check_feature
('blame')
5253 or die_error
(403, "Blame view not allowed");
5256 die_error
(400, "No file name given") unless $file_name;
5257 $hash_base ||= git_get_head_hash
($project);
5258 die_error
(404, "Couldn't find base commit") unless $hash_base;
5259 my %co = parse_commit
($hash_base)
5260 or die_error
(404, "Commit not found");
5262 if (!defined $hash) {
5263 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5264 or die_error
(404, "Error looking up file");
5266 $ftype = git_get_type
($hash);
5267 if ($ftype !~ "blob") {
5268 die_error
(400, "Object is not a blob");
5273 if ($format eq 'incremental') {
5274 # get file contents (as base)
5275 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5276 or die_error
(500, "Open git-cat-file failed");
5277 } elsif ($format eq 'data') {
5278 # run git-blame --incremental
5279 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5280 $hash_base, "--", $file_name
5281 or die_error
(500, "Open git-blame --incremental failed");
5283 # run git-blame --porcelain
5284 open $fd, "-|", git_cmd
(), "blame", '-p',
5285 $hash_base, '--', $file_name
5286 or die_error
(500, "Open git-blame --porcelain failed");
5289 # incremental blame data returns early
5290 if ($format eq 'data') {
5292 -type
=>"text/plain", -charset
=> "utf-8",
5293 -status
=> "200 OK");
5294 local $| = 1; # output autoflush
5297 or print "ERROR $!\n";
5300 if (defined $t0 && gitweb_check_feature
('timed')) {
5302 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5303 ' '.$number_of_git_cmds;
5313 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5316 if ($format eq 'incremental') {
5318 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5319 "blame") . " (non-incremental)";
5322 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5323 "blame") . " (incremental)";
5327 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5330 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5332 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5333 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5334 git_print_page_path
($file_name, $ftype, $hash_base);
5337 if ($format eq 'incremental') {
5338 print "<noscript>\n<div class=\"error\"><center><b>\n".
5339 "This page requires JavaScript to run.\n Use ".
5340 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5343 "</b></center></div>\n</noscript>\n";
5345 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5348 print qq
!<div
class="page_body">\n!;
5349 print qq
!<div id
="progress_info">... / ...</div
>\n!
5350 if ($format eq 'incremental');
5351 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5352 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5354 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5358 my @rev_color = qw(light dark);
5359 my $num_colors = scalar(@rev_color);
5360 my $current_color = 0;
5362 if ($format eq 'incremental') {
5363 my $color_class = $rev_color[$current_color];
5368 while (my $line = <$fd>) {
5372 print qq
!<tr id
="l$linenr" class="$color_class">!.
5373 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5374 qq
!<td
class="linenr">!.
5375 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5376 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5380 } else { # porcelain, i.e. ordinary blame
5381 my %metainfo = (); # saves information about commits
5385 while (my $line = <$fd>) {
5387 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5388 # no <lines in group> for subsequent lines in group of lines
5389 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5390 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5391 if (!exists $metainfo{$full_rev}) {
5392 $metainfo{$full_rev} = { 'nprevious' => 0 };
5394 my $meta = $metainfo{$full_rev};
5396 while ($data = <$fd>) {
5398 last if ($data =~ s/^\t//); # contents of line
5399 if ($data =~ /^(\S+)(?: (.*))?$/) {
5400 $meta->{$1} = $2 unless exists $meta->{$1};
5402 if ($data =~ /^previous /) {
5403 $meta->{'nprevious'}++;
5406 my $short_rev = substr($full_rev, 0, 8);
5407 my $author = $meta->{'author'};
5409 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5410 my $date = $date{'iso-tz'};
5412 $current_color = ($current_color + 1) % $num_colors;
5414 my $tr_class = $rev_color[$current_color];
5415 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5416 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5417 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5418 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5420 print "<td class=\"sha1\"";
5421 print " title=\"". esc_html
($author) . ", $date\"";
5422 print " rowspan=\"$group_size\"" if ($group_size > 1);
5424 print $cgi->a({-href
=> href
(action
=>"commit",
5426 file_name
=>$file_name)},
5427 esc_html
($short_rev));
5428 if ($group_size >= 2) {
5429 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5430 if (@author_initials) {
5432 esc_html
(join('', @author_initials));
5438 # 'previous' <sha1 of parent commit> <filename at commit>
5439 if (exists $meta->{'previous'} &&
5440 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5441 $meta->{'parent'} = $1;
5442 $meta->{'file_parent'} = unquote
($2);
5445 exists($meta->{'parent'}) ?
5446 $meta->{'parent'} : $full_rev;
5447 my $linenr_filename =
5448 exists($meta->{'file_parent'}) ?
5449 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5450 my $blamed = href
(action
=> 'blame',
5451 file_name
=> $linenr_filename,
5452 hash_base
=> $linenr_commit);
5453 print "<td class=\"linenr\">";
5454 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5455 -class => "linenr" },
5458 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5466 "</table>\n"; # class="blame"
5467 print "</div>\n"; # class="blame_body"
5469 or print "Reading blob failed\n";
5478 sub git_blame_incremental
{
5479 git_blame_common
('incremental');
5482 sub git_blame_data
{
5483 git_blame_common
('data');
5487 my $head = git_get_head_hash
($project);
5489 git_print_page_nav
('','', $head,undef,$head);
5490 git_print_header_div
('summary', $project);
5492 my @tagslist = git_get_tags_list
();
5494 git_tags_body
(\
@tagslist);
5500 my $head = git_get_head_hash
($project);
5502 git_print_page_nav
('','', $head,undef,$head);
5503 git_print_header_div
('summary', $project);
5505 my @headslist = git_get_heads_list
();
5507 git_heads_body
(\
@headslist, $head);
5512 sub git_blob_plain
{
5516 if (!defined $hash) {
5517 if (defined $file_name) {
5518 my $base = $hash_base || git_get_head_hash
($project);
5519 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5520 or die_error
(404, "Cannot find file");
5522 die_error
(400, "No file name defined");
5524 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5525 # blobs defined by non-textual hash id's can be cached
5529 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5530 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5532 # content-type (can include charset)
5533 $type = blob_contenttype
($fd, $file_name, $type);
5535 # "save as" filename, even when no $file_name is given
5536 my $save_as = "$hash";
5537 if (defined $file_name) {
5538 $save_as = $file_name;
5539 } elsif ($type =~ m/^text\//) {
5543 # With XSS prevention on, blobs of all types except a few known safe
5544 # ones are served with "Content-Disposition: attachment" to make sure
5545 # they don't run in our security domain. For certain image types,
5546 # blob view writes an <img> tag referring to blob_plain view, and we
5547 # want to be sure not to break that by serving the image as an
5548 # attachment (though Firefox 3 doesn't seem to care).
5549 my $sandbox = $prevent_xss &&
5550 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5554 -expires
=> $expires,
5555 -content_disposition
=>
5556 ($sandbox ? 'attachment' : 'inline')
5557 . '; filename="' . $save_as . '"');
5559 binmode STDOUT
, ':raw';
5561 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5568 if (!defined $hash) {
5569 if (defined $file_name) {
5570 my $base = $hash_base || git_get_head_hash
($project);
5571 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5572 or die_error
(404, "Cannot find file");
5574 die_error
(400, "No file name defined");
5576 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5577 # blobs defined by non-textual hash id's can be cached
5581 my $have_blame = gitweb_check_feature
('blame');
5582 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5583 or die_error
(500, "Couldn't cat $file_name, $hash");
5584 my $mimetype = blob_mimetype
($fd, $file_name);
5585 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5586 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5588 return git_blob_plain
($mimetype);
5590 # we can have blame only for text/* mimetype
5591 $have_blame &&= ($mimetype =~ m!^text/!);
5593 my $highlight = gitweb_check_feature
('highlight');
5594 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5595 $fd = run_highlighter
($fd, $highlight, $syntax)
5598 git_header_html
(undef, $expires);
5599 my $formats_nav = '';
5600 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5601 if (defined $file_name) {
5604 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5609 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5612 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5615 $cgi->a({-href
=> href
(action
=>"blob",
5616 hash_base
=>"HEAD", file_name
=>$file_name)},
5620 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5623 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5624 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5626 print "<div class=\"page_nav\">\n" .
5627 "<br/><br/></div>\n" .
5628 "<div class=\"title\">$hash</div>\n";
5630 git_print_page_path
($file_name, "blob", $hash_base);
5631 print "<div class=\"page_body\">\n";
5632 if ($mimetype =~ m!^image/!) {
5633 print qq
!<img type
="$mimetype"!;
5635 print qq
! alt
="$file_name" title
="$file_name"!;
5638 href(action=>"blob_plain
", hash=>$hash,
5639 hash_base=>$hash_base, file_name=>$file_name) .
5643 while (my $line = <$fd>) {
5646 $line = untabify
($line);
5647 printf qq
!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5648 $nr, href
(-replay
=> 1), $nr, $nr, $syntax ? $line : esc_html
($line, -nbsp
=>1);
5652 or print "Reading blob failed.\n";
5658 if (!defined $hash_base) {
5659 $hash_base = "HEAD";
5661 if (!defined $hash) {
5662 if (defined $file_name) {
5663 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5668 die_error
(404, "No such tree") unless defined($hash);
5670 my $show_sizes = gitweb_check_feature
('show-sizes');
5671 my $have_blame = gitweb_check_feature
('blame');
5676 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5677 ($show_sizes ? '-l' : ()), @extra_options, $hash
5678 or die_error
(500, "Open git-ls-tree failed");
5679 @entries = map { chomp; $_ } <$fd>;
5681 or die_error
(404, "Reading tree failed");
5684 my $refs = git_get_references
();
5685 my $ref = format_ref_marker
($refs, $hash_base);
5688 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5690 if (defined $file_name) {
5692 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5694 $cgi->a({-href
=> href
(action
=>"tree",
5695 hash_base
=>"HEAD", file_name
=>$file_name)},
5698 my $snapshot_links = format_snapshot_links
($hash);
5699 if (defined $snapshot_links) {
5700 # FIXME: Should be available when we have no hash base as well.
5701 push @views_nav, $snapshot_links;
5703 git_print_page_nav
('tree','', $hash_base, undef, undef,
5704 join(' | ', @views_nav));
5705 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5708 print "<div class=\"page_nav\">\n";
5709 print "<br/><br/></div>\n";
5710 print "<div class=\"title\">$hash</div>\n";
5712 if (defined $file_name) {
5713 $basedir = $file_name;
5714 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5717 git_print_page_path
($file_name, 'tree', $hash_base);
5719 print "<div class=\"page_body\">\n";
5720 print "<table class=\"tree\">\n";
5722 # '..' (top directory) link if possible
5723 if (defined $hash_base &&
5724 defined $file_name && $file_name =~ m![^/]+$!) {
5726 print "<tr class=\"dark\">\n";
5728 print "<tr class=\"light\">\n";
5732 my $up = $file_name;
5733 $up =~ s!/?[^/]+$!!;
5734 undef $up unless $up;
5735 # based on git_print_tree_entry
5736 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5737 print '<td class="size"> </td>'."\n" if $show_sizes;
5738 print '<td class="list">';
5739 print $cgi->a({-href
=> href
(action
=>"tree",
5740 hash_base
=>$hash_base,
5744 print "<td class=\"link\"></td>\n";
5748 foreach my $line (@entries) {
5749 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5752 print "<tr class=\"dark\">\n";
5754 print "<tr class=\"light\">\n";
5758 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5762 print "</table>\n" .
5768 my ($project, $hash) = @_;
5770 # path/to/project.git -> project
5771 # path/to/project/.git -> project
5772 my $name = to_utf8
($project);
5773 $name =~ s
,([^/])/*\
.git
$,$1,;
5774 $name = basename
($name);
5776 $name =~ s/[[:cntrl:]]/?/g;
5779 if ($hash =~ /^[0-9a-fA-F]+$/) {
5780 # shorten SHA-1 hash
5781 my $full_hash = git_get_full_hash
($project, $hash);
5782 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5783 $ver = git_get_short_hash
($project, $hash);
5785 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5786 # tags don't need shortened SHA-1 hash
5789 # branches and other need shortened SHA-1 hash
5790 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5793 $ver .= '-' . git_get_short_hash
($project, $hash);
5795 # in case of hierarchical branch names
5798 # name = project-version_string
5799 $name = "$name-$ver";
5801 return wantarray ? ($name, $name) : $name;
5805 my $format = $input_params{'snapshot_format'};
5806 if (!@snapshot_fmts) {
5807 die_error
(403, "Snapshots not allowed");
5809 # default to first supported snapshot format
5810 $format ||= $snapshot_fmts[0];
5811 if ($format !~ m/^[a-z0-9]+$/) {
5812 die_error
(400, "Invalid snapshot format parameter");
5813 } elsif (!exists($known_snapshot_formats{$format})) {
5814 die_error
(400, "Unknown snapshot format");
5815 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5816 die_error
(403, "Snapshot format not allowed");
5817 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5818 die_error
(403, "Unsupported snapshot format");
5821 my $type = git_get_type
("$hash^{}");
5823 die_error
(404, 'Object does not exist');
5824 } elsif ($type eq 'blob') {
5825 die_error
(400, 'Object is not a tree-ish');
5828 my ($name, $prefix) = snapshot_name
($project, $hash);
5829 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5830 my $cmd = quote_command
(
5831 git_cmd
(), 'archive',
5832 "--format=$known_snapshot_formats{$format}{'format'}",
5833 "--prefix=$prefix/", $hash);
5834 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5835 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5838 $filename =~ s/(["\\])/\\$1/g;
5840 -type
=> $known_snapshot_formats{$format}{'type'},
5841 -content_disposition
=> 'inline; filename="' . $filename . '"',
5842 -status
=> '200 OK');
5844 open my $fd, "-|", $cmd
5845 or die_error
(500, "Execute git-archive failed");
5846 binmode STDOUT
, ':raw';
5848 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5852 sub git_log_generic
{
5853 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5855 my $head = git_get_head_hash
($project);
5856 if (!defined $base) {
5859 if (!defined $page) {
5862 my $refs = git_get_references
();
5864 my $commit_hash = $base;
5865 if (defined $parent) {
5866 $commit_hash = "$parent..$base";
5869 parse_commits
($commit_hash, 101, (100 * $page),
5870 defined $file_name ? ($file_name, "--full-history") : ());
5873 if (!defined $file_hash && defined $file_name) {
5874 # some commits could have deleted file in question,
5875 # and not have it in tree, but one of them has to have it
5876 for (my $i = 0; $i < @commitlist; $i++) {
5877 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5878 last if defined $file_hash;
5881 if (defined $file_hash) {
5882 $ftype = git_get_type
($file_hash);
5884 if (defined $file_name && !defined $ftype) {
5885 die_error
(500, "Unknown type of object");
5888 if (defined $file_name) {
5889 %co = parse_commit
($base)
5890 or die_error
(404, "Unknown commit object");
5894 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5896 if ($#commitlist >= 100) {
5898 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5899 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5901 my $patch_max = gitweb_get_feature
('patches');
5902 if ($patch_max && !defined $file_name) {
5903 if ($patch_max < 0 || @commitlist <= $patch_max) {
5904 $paging_nav .= " ⋅ " .
5905 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5911 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5912 if (defined $file_name) {
5913 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5915 git_print_header_div
('summary', $project)
5917 git_print_page_path
($file_name, $ftype, $hash_base)
5918 if (defined $file_name);
5920 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5921 $file_name, $file_hash, $ftype);
5927 git_log_generic
('log', \
&git_log_body
,
5928 $hash, $hash_parent);
5932 $hash ||= $hash_base || "HEAD";
5933 my %co = parse_commit
($hash)
5934 or die_error
(404, "Unknown commit object");
5936 my $parent = $co{'parent'};
5937 my $parents = $co{'parents'}; # listref
5939 # we need to prepare $formats_nav before any parameter munging
5941 if (!defined $parent) {
5943 $formats_nav .= '(initial)';
5944 } elsif (@$parents == 1) {
5945 # single parent commit
5948 $cgi->a({-href
=> href
(action
=>"commit",
5950 esc_html
(substr($parent, 0, 7))) .
5957 $cgi->a({-href
=> href
(action
=>"commit",
5959 esc_html
(substr($_, 0, 7)));
5963 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5964 $formats_nav .= " | " .
5965 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5969 if (!defined $parent) {
5973 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5975 (@$parents <= 1 ? $parent : '-c'),
5977 or die_error
(500, "Open git-diff-tree failed");
5978 @difftree = map { chomp; $_ } <$fd>;
5979 close $fd or die_error
(404, "Reading git-diff-tree failed");
5981 # non-textual hash id's can be cached
5983 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5986 my $refs = git_get_references
();
5987 my $ref = format_ref_marker
($refs, $co{'id'});
5989 git_header_html
(undef, $expires);
5990 git_print_page_nav
('commit', '',
5991 $hash, $co{'tree'}, $hash,
5994 if (defined $co{'parent'}) {
5995 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5997 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5999 print "<div class=\"title_text\">\n" .
6000 "<table class=\"object_header\">\n";
6001 git_print_authorship_rows
(\
%co);
6002 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6005 "<td class=\"sha1\">" .
6006 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6007 class => "list"}, $co{'tree'}) .
6009 "<td class=\"link\">" .
6010 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6012 my $snapshot_links = format_snapshot_links
($hash);
6013 if (defined $snapshot_links) {
6014 print " | " . $snapshot_links;
6019 foreach my $par (@$parents) {
6022 "<td class=\"sha1\">" .
6023 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6024 class => "list"}, $par) .
6026 "<td class=\"link\">" .
6027 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6029 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6036 print "<div class=\"page_body\">\n";
6037 git_print_log
($co{'comment'});
6040 git_difftree_body
(\
@difftree, $hash, @$parents);
6046 # object is defined by:
6047 # - hash or hash_base alone
6048 # - hash_base and file_name
6051 # - hash or hash_base alone
6052 if ($hash || ($hash_base && !defined $file_name)) {
6053 my $object_id = $hash || $hash_base;
6055 open my $fd, "-|", quote_command
(
6056 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6057 or die_error
(404, "Object does not exist");
6061 or die_error
(404, "Object does not exist");
6063 # - hash_base and file_name
6064 } elsif ($hash_base && defined $file_name) {
6065 $file_name =~ s
,/+$,,;
6067 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6068 or die_error
(404, "Base object does not exist");
6070 # here errors should not hapen
6071 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6072 or die_error
(500, "Open git-ls-tree failed");
6076 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6077 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6078 die_error
(404, "File or directory for given base does not exist");
6083 die_error
(400, "Not enough information to find object");
6086 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6087 hash
=>$hash, hash_base
=>$hash_base,
6088 file_name
=>$file_name),
6089 -status
=> '302 Found');
6093 my $format = shift || 'html';
6100 # preparing $fd and %diffinfo for git_patchset_body
6102 if (defined $hash_base && defined $hash_parent_base) {
6103 if (defined $file_name) {
6105 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6106 $hash_parent_base, $hash_base,
6107 "--", (defined $file_parent ? $file_parent : ()), $file_name
6108 or die_error
(500, "Open git-diff-tree failed");
6109 @difftree = map { chomp; $_ } <$fd>;
6111 or die_error
(404, "Reading git-diff-tree failed");
6113 or die_error
(404, "Blob diff not found");
6115 } elsif (defined $hash &&
6116 $hash =~ /[0-9a-fA-F]{40}/) {
6117 # try to find filename from $hash
6119 # read filtered raw output
6120 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6121 $hash_parent_base, $hash_base, "--"
6122 or die_error
(500, "Open git-diff-tree failed");
6124 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6126 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6127 map { chomp; $_ } <$fd>;
6129 or die_error
(404, "Reading git-diff-tree failed");
6131 or die_error
(404, "Blob diff not found");
6134 die_error
(400, "Missing one of the blob diff parameters");
6137 if (@difftree > 1) {
6138 die_error
(400, "Ambiguous blob diff specification");
6141 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6142 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6143 $file_name ||= $diffinfo{'to_file'};
6145 $hash_parent ||= $diffinfo{'from_id'};
6146 $hash ||= $diffinfo{'to_id'};
6148 # non-textual hash id's can be cached
6149 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6150 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6155 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6156 '-p', ($format eq 'html' ? "--full-index" : ()),
6157 $hash_parent_base, $hash_base,
6158 "--", (defined $file_parent ? $file_parent : ()), $file_name
6159 or die_error
(500, "Open git-diff-tree failed");
6162 # old/legacy style URI -- not generated anymore since 1.4.3.
6164 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6168 if ($format eq 'html') {
6170 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6172 git_header_html
(undef, $expires);
6173 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6174 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6175 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6177 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6178 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
6180 if (defined $file_name) {
6181 git_print_page_path
($file_name, "blob", $hash_base);
6183 print "<div class=\"page_path\"></div>\n";
6186 } elsif ($format eq 'plain') {
6188 -type
=> 'text/plain',
6189 -charset
=> 'utf-8',
6190 -expires
=> $expires,
6191 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6193 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6196 die_error
(400, "Unknown blobdiff format");
6200 if ($format eq 'html') {
6201 print "<div class=\"page_body\">\n";
6203 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6206 print "</div>\n"; # class="page_body"
6210 while (my $line = <$fd>) {
6211 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6212 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6216 last if $line =~ m!^\+\+\+!;
6224 sub git_blobdiff_plain
{
6225 git_blobdiff
('plain');
6228 sub git_commitdiff
{
6230 my $format = $params{-format
} || 'html';
6232 my ($patch_max) = gitweb_get_feature
('patches');
6233 if ($format eq 'patch') {
6234 die_error
(403, "Patch view not allowed") unless $patch_max;
6237 $hash ||= $hash_base || "HEAD";
6238 my %co = parse_commit
($hash)
6239 or die_error
(404, "Unknown commit object");
6241 # choose format for commitdiff for merge
6242 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
6243 $hash_parent = '--cc';
6245 # we need to prepare $formats_nav before almost any parameter munging
6247 if ($format eq 'html') {
6249 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6251 if ($patch_max && @{$co{'parents'}} <= 1) {
6252 $formats_nav .= " | " .
6253 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6257 if (defined $hash_parent &&
6258 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6259 # commitdiff with two commits given
6260 my $hash_parent_short = $hash_parent;
6261 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6262 $hash_parent_short = substr($hash_parent, 0, 7);
6266 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
6267 if ($co{'parents'}[$i] eq $hash_parent) {
6268 $formats_nav .= ' parent ' . ($i+1);
6272 $formats_nav .= ': ' .
6273 $cgi->a({-href
=> href
(action
=>"commitdiff",
6274 hash
=>$hash_parent)},
6275 esc_html
($hash_parent_short)) .
6277 } elsif (!$co{'parent'}) {
6279 $formats_nav .= ' (initial)';
6280 } elsif (scalar @{$co{'parents'}} == 1) {
6281 # single parent commit
6284 $cgi->a({-href
=> href
(action
=>"commitdiff",
6285 hash
=>$co{'parent'})},
6286 esc_html
(substr($co{'parent'}, 0, 7))) .
6290 if ($hash_parent eq '--cc') {
6291 $formats_nav .= ' | ' .
6292 $cgi->a({-href
=> href
(action
=>"commitdiff",
6293 hash
=>$hash, hash_parent
=>'-c')},
6295 } else { # $hash_parent eq '-c'
6296 $formats_nav .= ' | ' .
6297 $cgi->a({-href
=> href
(action
=>"commitdiff",
6298 hash
=>$hash, hash_parent
=>'--cc')},
6304 $cgi->a({-href
=> href
(action
=>"commitdiff",
6306 esc_html
(substr($_, 0, 7)));
6307 } @{$co{'parents'}} ) .
6312 my $hash_parent_param = $hash_parent;
6313 if (!defined $hash_parent_param) {
6314 # --cc for multiple parents, --root for parentless
6315 $hash_parent_param =
6316 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6322 if ($format eq 'html') {
6323 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6324 "--no-commit-id", "--patch-with-raw", "--full-index",
6325 $hash_parent_param, $hash, "--"
6326 or die_error
(500, "Open git-diff-tree failed");
6328 while (my $line = <$fd>) {
6330 # empty line ends raw part of diff-tree output
6332 push @difftree, scalar parse_difftree_raw_line
($line);
6335 } elsif ($format eq 'plain') {
6336 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6337 '-p', $hash_parent_param, $hash, "--"
6338 or die_error
(500, "Open git-diff-tree failed");
6339 } elsif ($format eq 'patch') {
6340 # For commit ranges, we limit the output to the number of
6341 # patches specified in the 'patches' feature.
6342 # For single commits, we limit the output to a single patch,
6343 # diverging from the git-format-patch default.
6344 my @commit_spec = ();
6346 if ($patch_max > 0) {
6347 push @commit_spec, "-$patch_max";
6349 push @commit_spec, '-n', "$hash_parent..$hash";
6351 if ($params{-single
}) {
6352 push @commit_spec, '-1';
6354 if ($patch_max > 0) {
6355 push @commit_spec, "-$patch_max";
6357 push @commit_spec, "-n";
6359 push @commit_spec, '--root', $hash;
6361 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6362 '--encoding=utf8', '--stdout', @commit_spec
6363 or die_error
(500, "Open git-format-patch failed");
6365 die_error
(400, "Unknown commitdiff format");
6368 # non-textual hash id's can be cached
6370 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6374 # write commit message
6375 if ($format eq 'html') {
6376 my $refs = git_get_references
();
6377 my $ref = format_ref_marker
($refs, $co{'id'});
6379 git_header_html
(undef, $expires);
6380 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6381 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6382 print "<div class=\"title_text\">\n" .
6383 "<table class=\"object_header\">\n";
6384 git_print_authorship_rows
(\
%co);
6387 print "<div class=\"page_body\">\n";
6388 if (@{$co{'comment'}} > 1) {
6389 print "<div class=\"log\">\n";
6390 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6391 print "</div>\n"; # class="log"
6394 } elsif ($format eq 'plain') {
6395 my $refs = git_get_references
("tags");
6396 my $tagname = git_get_rev_name_tags
($hash);
6397 my $filename = basename
($project) . "-$hash.patch";
6400 -type
=> 'text/plain',
6401 -charset
=> 'utf-8',
6402 -expires
=> $expires,
6403 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6404 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6405 print "From: " . to_utf8
($co{'author'}) . "\n";
6406 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6407 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6409 print "X-Git-Tag: $tagname\n" if $tagname;
6410 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6412 foreach my $line (@{$co{'comment'}}) {
6413 print to_utf8
($line) . "\n";
6416 } elsif ($format eq 'patch') {
6417 my $filename = basename
($project) . "-$hash.patch";
6420 -type
=> 'text/plain',
6421 -charset
=> 'utf-8',
6422 -expires
=> $expires,
6423 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6427 if ($format eq 'html') {
6428 my $use_parents = !defined $hash_parent ||
6429 $hash_parent eq '-c' || $hash_parent eq '--cc';
6430 git_difftree_body
(\
@difftree, $hash,
6431 $use_parents ? @{$co{'parents'}} : $hash_parent);
6434 git_patchset_body
($fd, \
@difftree, $hash,
6435 $use_parents ? @{$co{'parents'}} : $hash_parent);
6437 print "</div>\n"; # class="page_body"
6440 } elsif ($format eq 'plain') {
6444 or print "Reading git-diff-tree failed\n";
6445 } elsif ($format eq 'patch') {
6449 or print "Reading git-format-patch failed\n";
6453 sub git_commitdiff_plain
{
6454 git_commitdiff
(-format
=> 'plain');
6457 # format-patch-style patches
6459 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6463 git_commitdiff
(-format
=> 'patch');
6467 git_log_generic
('history', \
&git_history_body
,
6468 $hash_base, $hash_parent_base,
6473 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6474 if (!defined $searchtext) {
6475 die_error
(400, "Text field is empty");
6477 if (!defined $hash) {
6478 $hash = git_get_head_hash
($project);
6480 my %co = parse_commit
($hash);
6482 die_error
(404, "Unknown commit object");
6484 if (!defined $page) {
6488 $searchtype ||= 'commit';
6489 if ($searchtype eq 'pickaxe') {
6490 # pickaxe may take all resources of your box and run for several minutes
6491 # with every query - so decide by yourself how public you make this feature
6492 gitweb_check_feature
('pickaxe')
6493 or die_error
(403, "Pickaxe is disabled");
6495 if ($searchtype eq 'grep') {
6496 gitweb_check_feature
('grep')[0]
6497 or die_error
(403, "Grep is disabled");
6502 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6504 if ($searchtype eq 'commit') {
6505 $greptype = "--grep=";
6506 } elsif ($searchtype eq 'author') {
6507 $greptype = "--author=";
6508 } elsif ($searchtype eq 'committer') {
6509 $greptype = "--committer=";
6511 $greptype .= $searchtext;
6512 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6513 $greptype, '--regexp-ignore-case',
6514 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6516 my $paging_nav = '';
6519 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6520 searchtext
=>$searchtext,
6521 searchtype
=>$searchtype)},
6523 $paging_nav .= " ⋅ " .
6524 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6525 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6527 $paging_nav .= "first";
6528 $paging_nav .= " ⋅ prev";
6531 if ($#commitlist >= 100) {
6533 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6534 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6535 $paging_nav .= " ⋅ $next_link";
6537 $paging_nav .= " ⋅ next";
6540 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6541 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6542 if ($page == 0 && !@commitlist) {
6543 print "<p>No match.</p>\n";
6545 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6549 if ($searchtype eq 'pickaxe') {
6550 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6551 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6553 print "<table class=\"pickaxe search\">\n";
6556 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6557 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6558 ($search_use_regexp ? '--pickaxe-regex' : ());
6561 while (my $line = <$fd>) {
6565 my %set = parse_difftree_raw_line
($line);
6566 if (defined $set{'commit'}) {
6567 # finish previous commit
6570 "<td class=\"link\">" .
6571 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6573 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6579 print "<tr class=\"dark\">\n";
6581 print "<tr class=\"light\">\n";
6584 %co = parse_commit
($set{'commit'});
6585 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6586 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6587 "<td><i>$author</i></td>\n" .
6589 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6590 -class => "list subject"},
6591 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6592 } elsif (defined $set{'to_id'}) {
6593 next if ($set{'to_id'} =~ m/^0{40}$/);
6595 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6596 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6598 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6604 # finish last commit (warning: repetition!)
6607 "<td class=\"link\">" .
6608 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6610 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6618 if ($searchtype eq 'grep') {
6619 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6620 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6622 print "<table class=\"grep_search\">\n";
6626 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6627 $search_use_regexp ? ('-E', '-i') : '-F',
6628 $searchtext, $co{'tree'};
6630 while (my $line = <$fd>) {
6632 my ($file, $lno, $ltext, $binary);
6633 last if ($matches++ > 1000);
6634 if ($line =~ /^Binary file (.+) matches$/) {
6638 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6640 if ($file ne $lastfile) {
6641 $lastfile and print "</td></tr>\n";
6643 print "<tr class=\"dark\">\n";
6645 print "<tr class=\"light\">\n";
6647 print "<td class=\"list\">".
6648 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6649 file_name
=>"$file"),
6650 -class => "list"}, esc_path
($file));
6651 print "</td><td>\n";
6655 print "<div class=\"binary\">Binary file</div>\n";
6657 $ltext = untabify
($ltext);
6658 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6659 $ltext = esc_html
($1, -nbsp
=>1);
6660 $ltext .= '<span class="match">';
6661 $ltext .= esc_html
($2, -nbsp
=>1);
6662 $ltext .= '</span>';
6663 $ltext .= esc_html
($3, -nbsp
=>1);
6665 $ltext = esc_html
($ltext, -nbsp
=>1);
6667 print "<div class=\"pre\">" .
6668 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6669 file_name
=>"$file").'#l'.$lno,
6670 -class => "linenr"}, sprintf('%4i', $lno))
6671 . ' ' . $ltext . "</div>\n";
6675 print "</td></tr>\n";
6676 if ($matches > 1000) {
6677 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6680 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6689 sub git_search_help
{
6691 git_print_page_nav
('','', $hash,$hash,$hash);
6693 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6694 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6695 the pattern entered is recognized as the POSIX extended
6696 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6699 <dt><b>commit</b></dt>
6700 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6702 my $have_grep = gitweb_check_feature
('grep');
6705 <dt><b>grep</b></dt>
6706 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6707 a different one) are searched for the given pattern. On large trees, this search can take
6708 a while and put some strain on the server, so please use it with some consideration. Note that
6709 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6710 case-sensitive.</dd>
6714 <dt><b>author</b></dt>
6715 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6716 <dt><b>committer</b></dt>
6717 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6719 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6720 if ($have_pickaxe) {
6722 <dt><b>pickaxe</b></dt>
6723 <dd>All commits that caused the string to appear or disappear from any file (changes that
6724 added, removed or "modified" the string) will be listed. This search can take a while and
6725 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6726 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6734 git_log_generic
('shortlog', \
&git_shortlog_body
,
6735 $hash, $hash_parent);
6738 ## ......................................................................
6739 ## feeds (RSS, Atom; OPML)
6742 my $format = shift || 'atom';
6743 my $have_blame = gitweb_check_feature
('blame');
6745 # Atom: http://www.atomenabled.org/developers/syndication/
6746 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6747 if ($format ne 'rss' && $format ne 'atom') {
6748 die_error
(400, "Unknown web feed format");
6751 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6752 my $head = $hash || 'HEAD';
6753 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6757 my $content_type = "application/$format+xml";
6758 if (defined $cgi->http('HTTP_ACCEPT') &&
6759 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6760 # browser (feed reader) prefers text/xml
6761 $content_type = 'text/xml';
6763 if (defined($commitlist[0])) {
6764 %latest_commit = %{$commitlist[0]};
6765 my $latest_epoch = $latest_commit{'committer_epoch'};
6766 %latest_date = parse_date
($latest_epoch);
6767 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6768 if (defined $if_modified) {
6770 if (eval { require HTTP
::Date
; 1; }) {
6771 $since = HTTP
::Date
::str2time
($if_modified);
6772 } elsif (eval { require Time
::ParseDate
; 1; }) {
6773 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6775 if (defined $since && $latest_epoch <= $since) {
6777 -type
=> $content_type,
6778 -charset
=> 'utf-8',
6779 -last_modified
=> $latest_date{'rfc2822'},
6780 -status
=> '304 Not Modified');
6785 -type
=> $content_type,
6786 -charset
=> 'utf-8',
6787 -last_modified
=> $latest_date{'rfc2822'});
6790 -type
=> $content_type,
6791 -charset
=> 'utf-8');
6794 # Optimization: skip generating the body if client asks only
6795 # for Last-Modified date.
6796 return if ($cgi->request_method() eq 'HEAD');
6799 my $title = "$site_name - $project/$action";
6800 my $feed_type = 'log';
6801 if (defined $hash) {
6802 $title .= " - '$hash'";
6803 $feed_type = 'branch log';
6804 if (defined $file_name) {
6805 $title .= " :: $file_name";
6806 $feed_type = 'history';
6808 } elsif (defined $file_name) {
6809 $title .= " - $file_name";
6810 $feed_type = 'history';
6812 $title .= " $feed_type";
6813 my $descr = git_get_project_description
($project);
6814 if (defined $descr) {
6815 $descr = esc_html
($descr);
6817 $descr = "$project " .
6818 ($format eq 'rss' ? 'RSS' : 'Atom') .
6821 my $owner = git_get_project_owner
($project);
6822 $owner = esc_html
($owner);
6826 if (defined $file_name) {
6827 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6828 } elsif (defined $hash) {
6829 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6831 $alt_url = href
(-full
=>1, action
=>"summary");
6833 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6834 if ($format eq 'rss') {
6836 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6839 print "<title>$title</title>\n" .
6840 "<link>$alt_url</link>\n" .
6841 "<description>$descr</description>\n" .
6842 "<language>en</language>\n" .
6843 # project owner is responsible for 'editorial' content
6844 "<managingEditor>$owner</managingEditor>\n";
6845 if (defined $logo || defined $favicon) {
6846 # prefer the logo to the favicon, since RSS
6847 # doesn't allow both
6848 my $img = esc_url
($logo || $favicon);
6850 "<url>$img</url>\n" .
6851 "<title>$title</title>\n" .
6852 "<link>$alt_url</link>\n" .
6856 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6857 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6859 print "<generator>gitweb v.$version/$git_version</generator>\n";
6860 } elsif ($format eq 'atom') {
6862 <feed xmlns="http://www.w3.org/2005/Atom">
6864 print "<title>$title</title>\n" .
6865 "<subtitle>$descr</subtitle>\n" .
6866 '<link rel="alternate" type="text/html" href="' .
6867 $alt_url . '" />' . "\n" .
6868 '<link rel="self" type="' . $content_type . '" href="' .
6869 $cgi->self_url() . '" />' . "\n" .
6870 "<id>" . href
(-full
=>1) . "</id>\n" .
6871 # use project owner for feed author
6872 "<author><name>$owner</name></author>\n";
6873 if (defined $favicon) {
6874 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6876 if (defined $logo_url) {
6877 # not twice as wide as tall: 72 x 27 pixels
6878 print "<logo>" . esc_url
($logo) . "</logo>\n";
6880 if (! %latest_date) {
6881 # dummy date to keep the feed valid until commits trickle in:
6882 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6884 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6886 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6890 for (my $i = 0; $i <= $#commitlist; $i++) {
6891 my %co = %{$commitlist[$i]};
6892 my $commit = $co{'id'};
6893 # we read 150, we always show 30 and the ones more recent than 48 hours
6894 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6897 my %cd = parse_date
($co{'author_epoch'});
6899 # get list of changed files
6900 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6901 $co{'parent'} || "--root",
6902 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6904 my @difftree = map { chomp; $_ } <$fd>;
6908 # print element (entry, item)
6909 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6910 if ($format eq 'rss') {
6912 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6913 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6914 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6915 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6916 "<link>$co_url</link>\n" .
6917 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6918 "<content:encoded>" .
6920 } elsif ($format eq 'atom') {
6922 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6923 "<updated>$cd{'iso-8601'}</updated>\n" .
6925 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6926 if ($co{'author_email'}) {
6927 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6929 print "</author>\n" .
6930 # use committer for contributor
6932 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6933 if ($co{'committer_email'}) {
6934 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6936 print "</contributor>\n" .
6937 "<published>$cd{'iso-8601'}</published>\n" .
6938 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6939 "<id>$co_url</id>\n" .
6940 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6941 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6943 my $comment = $co{'comment'};
6945 foreach my $line (@$comment) {
6946 $line = esc_html
($line);
6949 print "</pre><ul>\n";
6950 foreach my $difftree_line (@difftree) {
6951 my %difftree = parse_difftree_raw_line
($difftree_line);
6952 next if !$difftree{'from_id'};
6954 my $file = $difftree{'file'} || $difftree{'to_file'};
6958 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6959 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6960 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6961 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6962 -title
=> "diff"}, 'D');
6964 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6965 file_name
=>$file, hash_base
=>$commit),
6966 -title
=> "blame"}, 'B');
6968 # if this is not a feed of a file history
6969 if (!defined $file_name || $file_name ne $file) {
6970 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6971 file_name
=>$file, hash
=>$commit),
6972 -title
=> "history"}, 'H');
6974 $file = esc_path
($file);
6978 if ($format eq 'rss') {
6979 print "</ul>]]>\n" .
6980 "</content:encoded>\n" .
6982 } elsif ($format eq 'atom') {
6983 print "</ul>\n</div>\n" .
6990 if ($format eq 'rss') {
6991 print "</channel>\n</rss>\n";
6992 } elsif ($format eq 'atom') {
7006 my @list = git_get_projects_list
();
7009 -type
=> 'text/xml',
7010 -charset
=> 'utf-8',
7011 -content_disposition
=> 'inline; filename="opml.xml"');
7014 <?xml version="1.0" encoding="utf-8"?>
7015 <opml version="1.0">
7017 <title>$site_name OPML Export</title>
7020 <outline text="git RSS feeds">
7023 foreach my $pr (@list) {
7025 my $head = git_get_head_hash
($proj{'path'});
7026 if (!defined $head) {
7029 $git_dir = "$projectroot/$proj{'path'}";
7030 my %co = parse_commit
($head);
7035 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7036 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7037 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7038 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";