3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser set_message);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI
->compile() if $ENV{'MOD_PERL'};
31 our $version = "1.7.2.5";
33 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
37 our $my_url = $cgi->url();
38 our $my_uri = $cgi->url(-absolute
=> 1);
40 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
41 # needed and used only for URLs with nonempty PATH_INFO
42 our $base_url = $my_url;
44 # When the script is used as DirectoryIndex, the URL does not contain the name
45 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
46 # have to do it ourselves. We make $path_info global because it's also used
49 # Another issue with the script being the DirectoryIndex is that the resulting
50 # $my_url data is not the full script URL: this is good, because we want
51 # generated links to keep implying the script name if it wasn't explicitly
52 # indicated in the URL we're handling, but it means that $my_url cannot be used
54 # Therefore, if we needed to strip PATH_INFO, then we know that we have
55 # to build the base URL ourselves:
56 our $path_info = $ENV{"PATH_INFO"};
58 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
59 $my_uri =~ s
,\Q
$path_info\E
$,, &&
60 defined $ENV{'SCRIPT_NAME'}) {
61 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
65 # target of the home link on top of all pages
66 our $home_link = $my_uri || "/";
69 # core git executable to use
70 # this can just be "git" if your webserver has a sensible PATH
71 our $GIT = "/usr/bin/git";
73 # absolute fs-path which will be prepended to the project path
74 #our $projectroot = "/pub/scm";
75 our $projectroot = "/pub/git";
77 # fs traversing limit for getting project list
78 # the number is relative to the projectroot
79 our $project_maxdepth = 2007;
81 # string of the home link on top of all pages
82 our $home_link_str = "projects";
84 # name of your site or organization to appear in page titles
85 # replace this with something more descriptive for clearer bookmarks
87 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
89 # filename of html text to include at top of each page
90 our $site_header = "";
91 # html text to include at home page
92 our $home_text = "indextext.html";
93 # filename of html text to include at bottom of each page
94 our $site_footer = "";
97 our @stylesheets = ("gitweb.css");
98 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
99 our $stylesheet = undef;
100 # URI of GIT logo (72x27 size)
101 our $logo = "git-logo.png";
102 # URI of GIT favicon, assumed to be image/png type
103 our $favicon = "git-favicon.png";
104 # URI of gitweb.js (JavaScript code for gitweb)
105 our $javascript = "gitweb.js";
107 # URI and label (title) of GIT logo link
108 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
109 #our $logo_label = "git documentation";
110 our $logo_url = "http://git-scm.com/";
111 our $logo_label = "git homepage";
113 # source of projects list
114 our $projects_list = "";
116 # the width (in characters) of the projects list "Description" column
117 our $projects_list_description_width = 25;
119 # default order of projects list
120 # valid values are none, project, descr, owner, and age
121 our $default_projects_order = "project";
123 # show repository only if this file exists
124 # (only effective if this variable evaluates to true)
127 # show repository only if this subroutine returns true
128 # when given the path to the project, for example:
129 # sub { return -e "$_[0]/git-daemon-export-ok"; }
130 our $export_auth_hook = undef;
132 # only allow viewing of repositories also shown on the overview page
133 our $strict_export = "";
135 # list of git base URLs used for URL to where fetch project from,
136 # i.e. full URL is "$git_base_url/$project"
137 our @git_base_url_list = grep { $_ ne '' } ("");
139 # default blob_plain mimetype and default charset for text/plain blob
140 our $default_blob_plain_mimetype = 'text/plain';
141 our $default_text_plain_charset = undef;
143 # file to use for guessing MIME types before trying /etc/mime.types
144 # (relative to the current git repository)
145 our $mimetypes_file = undef;
147 # assume this charset if line contains non-UTF-8 characters;
148 # it should be valid encoding (see Encoding::Supported(3pm) for list),
149 # for which encoding all byte sequences are valid, for example
150 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
151 # could be even 'utf-8' for the old behavior)
152 our $fallback_encoding = 'latin1';
154 # rename detection options for git-diff and git-diff-tree
155 # - default is '-M', with the cost proportional to
156 # (number of removed files) * (number of new files).
157 # - more costly is '-C' (which implies '-M'), with the cost proportional to
158 # (number of changed files + number of removed files) * (number of new files)
159 # - even more costly is '-C', '--find-copies-harder' with cost
160 # (number of files in the original tree) * (number of new files)
161 # - one might want to include '-B' option, e.g. '-B', '-M'
162 our @diff_opts = ('-M'); # taken from git_commit
164 # Disables features that would allow repository owners to inject script into
166 our $prevent_xss = 0;
168 # information about snapshot formats that gitweb is capable of serving
169 our %known_snapshot_formats = (
171 # 'display' => display name,
172 # 'type' => mime type,
173 # 'suffix' => filename suffix,
174 # 'format' => --format for git-archive,
175 # 'compressor' => [compressor command and arguments]
176 # (array reference, optional)
177 # 'disabled' => boolean (optional)}
180 'display' => 'tar.gz',
181 'type' => 'application/x-gzip',
182 'suffix' => '.tar.gz',
184 'compressor' => ['gzip']},
187 'display' => 'tar.bz2',
188 'type' => 'application/x-bzip2',
189 'suffix' => '.tar.bz2',
191 'compressor' => ['bzip2']},
194 'display' => 'tar.xz',
195 'type' => 'application/x-xz',
196 'suffix' => '.tar.xz',
198 'compressor' => ['xz'],
203 'type' => 'application/x-zip',
208 # Aliases so we understand old gitweb.snapshot values in repository
210 our %known_snapshot_format_aliases = (
215 # backward compatibility: legacy gitweb config support
216 'x-gzip' => undef, 'gz' => undef,
217 'x-bzip2' => undef, 'bz2' => undef,
218 'x-zip' => undef, '' => undef,
221 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
222 # are changed, it may be appropriate to change these values too via
229 # Used to set the maximum load that we will still respond to gitweb queries.
230 # If server load exceed this value then return "503 server busy" error.
231 # If gitweb cannot determined server load, it is taken to be 0.
232 # Leave it undefined (or set to 'undef') to turn off load checking.
235 # You define site-wide feature defaults here; override them with
236 # $GITWEB_CONFIG as necessary.
239 # 'sub' => feature-sub (subroutine),
240 # 'override' => allow-override (boolean),
241 # 'default' => [ default options...] (array reference)}
243 # if feature is overridable (it means that allow-override has true value),
244 # then feature-sub will be called with default options as parameters;
245 # return value of feature-sub indicates if to enable specified feature
247 # if there is no 'sub' key (no feature-sub), then feature cannot be
250 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
251 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
254 # Enable the 'blame' blob view, showing the last commit that modified
255 # each line in the file. This can be very CPU-intensive.
257 # To enable system wide have in $GITWEB_CONFIG
258 # $feature{'blame'}{'default'} = [1];
259 # To have project specific config enable override in $GITWEB_CONFIG
260 # $feature{'blame'}{'override'} = 1;
261 # and in project config gitweb.blame = 0|1;
263 'sub' => sub { feature_bool
('blame', @_) },
267 # Enable the 'snapshot' link, providing a compressed archive of any
268 # tree. This can potentially generate high traffic if you have large
271 # Value is a list of formats defined in %known_snapshot_formats that
273 # To disable system wide have in $GITWEB_CONFIG
274 # $feature{'snapshot'}{'default'} = [];
275 # To have project specific config enable override in $GITWEB_CONFIG
276 # $feature{'snapshot'}{'override'} = 1;
277 # and in project config, a comma-separated list of formats or "none"
278 # to disable. Example: gitweb.snapshot = tbz2,zip;
280 'sub' => \
&feature_snapshot
,
282 'default' => ['tgz']},
284 # Enable text search, which will list the commits which match author,
285 # committer or commit text to a given string. Enabled by default.
286 # Project specific override is not supported.
291 # Enable grep search, which will list the files in currently selected
292 # tree containing the given string. Enabled by default. This can be
293 # potentially CPU-intensive, of course.
295 # To enable system wide have in $GITWEB_CONFIG
296 # $feature{'grep'}{'default'} = [1];
297 # To have project specific config enable override in $GITWEB_CONFIG
298 # $feature{'grep'}{'override'} = 1;
299 # and in project config gitweb.grep = 0|1;
301 'sub' => sub { feature_bool
('grep', @_) },
305 # Enable the pickaxe search, which will list the commits that modified
306 # a given string in a file. This can be practical and quite faster
307 # alternative to 'blame', but still potentially CPU-intensive.
309 # To enable system wide have in $GITWEB_CONFIG
310 # $feature{'pickaxe'}{'default'} = [1];
311 # To have project specific config enable override in $GITWEB_CONFIG
312 # $feature{'pickaxe'}{'override'} = 1;
313 # and in project config gitweb.pickaxe = 0|1;
315 'sub' => sub { feature_bool
('pickaxe', @_) },
319 # Enable showing size of blobs in a 'tree' view, in a separate
320 # column, similar to what 'ls -l' does. This cost a bit of IO.
322 # To disable system wide have in $GITWEB_CONFIG
323 # $feature{'show-sizes'}{'default'} = [0];
324 # To have project specific config enable override in $GITWEB_CONFIG
325 # $feature{'show-sizes'}{'override'} = 1;
326 # and in project config gitweb.showsizes = 0|1;
328 'sub' => sub { feature_bool
('showsizes', @_) },
332 # Make gitweb use an alternative format of the URLs which can be
333 # more readable and natural-looking: project name is embedded
334 # directly in the path and the query string contains other
335 # auxiliary information. All gitweb installations recognize
336 # URL in either format; this configures in which formats gitweb
339 # To enable system wide have in $GITWEB_CONFIG
340 # $feature{'pathinfo'}{'default'} = [1];
341 # Project specific override is not supported.
343 # Note that you will need to change the default location of CSS,
344 # favicon, logo and possibly other files to an absolute URL. Also,
345 # if gitweb.cgi serves as your indexfile, you will need to force
346 # $my_uri to contain the script name in your $GITWEB_CONFIG.
351 # Make gitweb consider projects in project root subdirectories
352 # to be forks of existing projects. Given project $projname.git,
353 # projects matching $projname/*.git will not be shown in the main
354 # projects list, instead a '+' mark will be added to $projname
355 # there and a 'forks' view will be enabled for the project, listing
356 # all the forks. If project list is taken from a file, forks have
357 # to be listed after the main project.
359 # To enable system wide have in $GITWEB_CONFIG
360 # $feature{'forks'}{'default'} = [1];
361 # Project specific override is not supported.
366 # Insert custom links to the action bar of all project pages.
367 # This enables you mainly to link to third-party scripts integrating
368 # into gitweb; e.g. git-browser for graphical history representation
369 # or custom web-based repository administration interface.
371 # The 'default' value consists of a list of triplets in the form
372 # (label, link, position) where position is the label after which
373 # to insert the link and link is a format string where %n expands
374 # to the project name, %f to the project path within the filesystem,
375 # %h to the current hash (h gitweb parameter) and %b to the current
376 # hash base (hb gitweb parameter); %% expands to %.
378 # To enable system wide have in $GITWEB_CONFIG e.g.
379 # $feature{'actions'}{'default'} = [('graphiclog',
380 # '/git-browser/by-commit.html?r=%n', 'summary')];
381 # Project specific override is not supported.
386 # Allow gitweb scan project content tags described in ctags/
387 # of project repository, and display the popular Web 2.0-ish
388 # "tag cloud" near the project list. Note that this is something
389 # COMPLETELY different from the normal Git tags.
391 # gitweb by itself can show existing tags, but it does not handle
392 # tagging itself; you need an external application for that.
393 # For an example script, check Girocco's cgi/tagproj.cgi.
394 # You may want to install the HTML::TagCloud Perl module to get
395 # a pretty tag cloud instead of just a list of tags.
397 # To enable system wide have in $GITWEB_CONFIG
398 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
399 # Project specific override is not supported.
404 # The maximum number of patches in a patchset generated in patch
405 # view. Set this to 0 or undef to disable patch view, or to a
406 # negative number to remove any limit.
408 # To disable system wide have in $GITWEB_CONFIG
409 # $feature{'patches'}{'default'} = [0];
410 # To have project specific config enable override in $GITWEB_CONFIG
411 # $feature{'patches'}{'override'} = 1;
412 # and in project config gitweb.patches = 0|n;
413 # where n is the maximum number of patches allowed in a patchset.
415 'sub' => \
&feature_patches
,
419 # Avatar support. When this feature is enabled, views such as
420 # shortlog or commit will display an avatar associated with
421 # the email of the committer(s) and/or author(s).
423 # Currently available providers are gravatar and picon.
424 # If an unknown provider is specified, the feature is disabled.
426 # Gravatar depends on Digest::MD5.
427 # Picon currently relies on the indiana.edu database.
429 # To enable system wide have in $GITWEB_CONFIG
430 # $feature{'avatar'}{'default'} = ['<provider>'];
431 # where <provider> is either gravatar or picon.
432 # To have project specific config enable override in $GITWEB_CONFIG
433 # $feature{'avatar'}{'override'} = 1;
434 # and in project config gitweb.avatar = <provider>;
436 'sub' => \
&feature_avatar
,
440 # Enable displaying how much time and how many git commands
441 # it took to generate and display page. Disabled by default.
442 # Project specific override is not supported.
447 # Enable turning some links into links to actions which require
448 # JavaScript to run (like 'blame_incremental'). Not enabled by
449 # default. Project specific override is currently not supported.
450 'javascript-actions' => {
454 # Syntax highlighting support. This is based on Daniel Svensson's
455 # and Sham Chukoury's work in gitweb-xmms2.git.
456 # It requires the 'highlight' program present in $PATH,
457 # and therefore is disabled by default.
459 # To enable system wide have in $GITWEB_CONFIG
460 # $feature{'highlight'}{'default'} = [1];
463 'sub' => sub { feature_bool
('highlight', @_) },
468 sub gitweb_get_feature
{
470 return unless exists $feature{$name};
471 my ($sub, $override, @defaults) = (
472 $feature{$name}{'sub'},
473 $feature{$name}{'override'},
474 @
{$feature{$name}{'default'}});
475 # project specific override is possible only if we have project
476 our $git_dir; # global variable, declared later
477 if (!$override || !defined $git_dir) {
481 warn "feature $name is not overridable";
484 return $sub->(@defaults);
487 # A wrapper to check if a given feature is enabled.
488 # With this, you can say
490 # my $bool_feat = gitweb_check_feature('bool_feat');
491 # gitweb_check_feature('bool_feat') or somecode;
495 # my ($bool_feat) = gitweb_get_feature('bool_feat');
496 # (gitweb_get_feature('bool_feat'))[0] or somecode;
498 sub gitweb_check_feature
{
499 return (gitweb_get_feature
(@_))[0];
505 my ($val) = git_get_project_config
($key, '--bool');
509 } elsif ($val eq 'true') {
511 } elsif ($val eq 'false') {
516 sub feature_snapshot
{
519 my ($val) = git_get_project_config
('snapshot');
522 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
528 sub feature_patches
{
529 my @val = (git_get_project_config
('patches', '--int'));
539 my @val = (git_get_project_config
('avatar'));
541 return @val ?
@val : @_;
544 # checking HEAD file with -e is fragile if the repository was
545 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
547 sub check_head_link
{
549 my $headfile = "$dir/HEAD";
550 return ((-e
$headfile) ||
551 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
554 sub check_export_ok
{
556 return (check_head_link
($dir) &&
557 (!$export_ok || -e
"$dir/$export_ok") &&
558 (!$export_auth_hook || $export_auth_hook->($dir)));
561 # process alternate names for backward compatibility
562 # filter out unsupported (unknown) snapshot formats
563 sub filter_snapshot_fmts
{
567 exists $known_snapshot_format_aliases{$_} ?
568 $known_snapshot_format_aliases{$_} : $_} @fmts;
570 exists $known_snapshot_formats{$_} &&
571 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
574 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
575 sub evaluate_gitweb_config
{
576 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
577 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
578 # die if there are errors parsing config file
579 if (-e
$GITWEB_CONFIG) {
582 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
583 do $GITWEB_CONFIG_SYSTEM;
588 # Get loadavg of system, to compare against $maxload.
589 # Currently it requires '/proc/loadavg' present to get loadavg;
590 # if it is not present it returns 0, which means no load checking.
592 if( -e
'/proc/loadavg' ){
593 open my $fd, '<', '/proc/loadavg'
595 my @load = split(/\s+/, scalar <$fd>);
598 # The first three columns measure CPU and IO utilization of the last one,
599 # five, and 10 minute periods. The fourth column shows the number of
600 # currently running processes and the total number of processes in the m/n
601 # format. The last column displays the last process ID used.
602 return $load[0] || 0;
604 # additional checks for load average should go here for things that don't export
610 # version of the core git binary
612 sub evaluate_git_version
{
613 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
614 $number_of_git_cmds++;
618 if (defined $maxload && get_loadavg
() > $maxload) {
619 die_error
(503, "The load average on the server is too high");
623 # ======================================================================
624 # input validation and dispatch
626 # input parameters can be collected from a variety of sources (presently, CGI
627 # and PATH_INFO), so we define an %input_params hash that collects them all
628 # together during validation: this allows subsequent uses (e.g. href()) to be
629 # agnostic of the parameter origin
631 our %input_params = ();
633 # input parameters are stored with the long parameter name as key. This will
634 # also be used in the href subroutine to convert parameters to their CGI
635 # equivalent, and since the href() usage is the most frequent one, we store
636 # the name -> CGI key mapping here, instead of the reverse.
638 # XXX: Warning: If you touch this, check the search form for updating,
641 our @cgi_param_mapping = (
649 hash_parent_base
=> "hpb",
654 snapshot_format
=> "sf",
655 extra_options
=> "opt",
656 search_use_regexp
=> "sr",
657 # this must be last entry (for manipulation from JavaScript)
660 our %cgi_param_mapping = @cgi_param_mapping;
662 # we will also need to know the possible actions, for validation
664 "blame" => \
&git_blame
,
665 "blame_incremental" => \
&git_blame_incremental
,
666 "blame_data" => \
&git_blame_data
,
667 "blobdiff" => \
&git_blobdiff
,
668 "blobdiff_plain" => \
&git_blobdiff_plain
,
669 "blob" => \
&git_blob
,
670 "blob_plain" => \
&git_blob_plain
,
671 "commitdiff" => \
&git_commitdiff
,
672 "commitdiff_plain" => \
&git_commitdiff_plain
,
673 "commit" => \
&git_commit
,
674 "forks" => \
&git_forks
,
675 "heads" => \
&git_heads
,
676 "history" => \
&git_history
,
678 "patch" => \
&git_patch
,
679 "patches" => \
&git_patches
,
681 "atom" => \
&git_atom
,
682 "search" => \
&git_search
,
683 "search_help" => \
&git_search_help
,
684 "shortlog" => \
&git_shortlog
,
685 "summary" => \
&git_summary
,
687 "tags" => \
&git_tags
,
688 "tree" => \
&git_tree
,
689 "snapshot" => \
&git_snapshot
,
690 "object" => \
&git_object
,
691 # those below don't need $project
692 "opml" => \
&git_opml
,
693 "project_list" => \
&git_project_list
,
694 "project_index" => \
&git_project_index
,
697 # finally, we have the hash of allowed extra_options for the commands that
699 our %allowed_options = (
700 "--no-merges" => [ qw(rss atom log shortlog history) ],
703 # fill %input_params with the CGI parameters. All values except for 'opt'
704 # should be single values, but opt can be an array. We should probably
705 # build an array of parameters that can be multi-valued, but since for the time
706 # being it's only this one, we just single it out
707 sub evaluate_query_params
{
710 while (my ($name, $symbol) = each %cgi_param_mapping) {
711 if ($symbol eq 'opt') {
712 $input_params{$name} = [ $cgi->param($symbol) ];
714 $input_params{$name} = $cgi->param($symbol);
719 # now read PATH_INFO and update the parameter list for missing parameters
720 sub evaluate_path_info
{
721 return if defined $input_params{'project'};
722 return if !$path_info;
723 $path_info =~ s
,^/+,,;
724 return if !$path_info;
726 # find which part of PATH_INFO is project
727 my $project = $path_info;
729 while ($project && !check_head_link
("$projectroot/$project")) {
730 $project =~ s
,/*[^/]*$,,;
732 return unless $project;
733 $input_params{'project'} = $project;
735 # do not change any parameters if an action is given using the query string
736 return if $input_params{'action'};
737 $path_info =~ s
,^\Q
$project\E
/*,,;
739 # next, check if we have an action
740 my $action = $path_info;
742 if (exists $actions{$action}) {
743 $path_info =~ s
,^$action/*,,;
744 $input_params{'action'} = $action;
747 # list of actions that want hash_base instead of hash, but can have no
748 # pathname (f) parameter
755 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
756 my ($parentrefname, $parentpathname, $refname, $pathname) =
757 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
759 # first, analyze the 'current' part
760 if (defined $pathname) {
761 # we got "branch:filename" or "branch:dir/"
762 # we could use git_get_type(branch:pathname), but:
763 # - it needs $git_dir
764 # - it does a git() call
765 # - the convention of terminating directories with a slash
766 # makes it superfluous
767 # - embedding the action in the PATH_INFO would make it even
769 $pathname =~ s
,^/+,,;
770 if (!$pathname || substr($pathname, -1) eq "/") {
771 $input_params{'action'} ||= "tree";
774 # the default action depends on whether we had parent info
776 if ($parentrefname) {
777 $input_params{'action'} ||= "blobdiff_plain";
779 $input_params{'action'} ||= "blob_plain";
782 $input_params{'hash_base'} ||= $refname;
783 $input_params{'file_name'} ||= $pathname;
784 } elsif (defined $refname) {
785 # we got "branch". In this case we have to choose if we have to
786 # set hash or hash_base.
788 # Most of the actions without a pathname only want hash to be
789 # set, except for the ones specified in @wants_base that want
790 # hash_base instead. It should also be noted that hand-crafted
791 # links having 'history' as an action and no pathname or hash
792 # set will fail, but that happens regardless of PATH_INFO.
793 $input_params{'action'} ||= "shortlog";
794 if (grep { $_ eq $input_params{'action'} } @wants_base) {
795 $input_params{'hash_base'} ||= $refname;
797 $input_params{'hash'} ||= $refname;
801 # next, handle the 'parent' part, if present
802 if (defined $parentrefname) {
803 # a missing pathspec defaults to the 'current' filename, allowing e.g.
804 # someproject/blobdiff/oldrev..newrev:/filename
805 if ($parentpathname) {
806 $parentpathname =~ s
,^/+,,;
807 $parentpathname =~ s
,/$,,;
808 $input_params{'file_parent'} ||= $parentpathname;
810 $input_params{'file_parent'} ||= $input_params{'file_name'};
812 # we assume that hash_parent_base is wanted if a path was specified,
813 # or if the action wants hash_base instead of hash
814 if (defined $input_params{'file_parent'} ||
815 grep { $_ eq $input_params{'action'} } @wants_base) {
816 $input_params{'hash_parent_base'} ||= $parentrefname;
818 $input_params{'hash_parent'} ||= $parentrefname;
822 # for the snapshot action, we allow URLs in the form
823 # $project/snapshot/$hash.ext
824 # where .ext determines the snapshot and gets removed from the
825 # passed $refname to provide the $hash.
827 # To be able to tell that $refname includes the format extension, we
828 # require the following two conditions to be satisfied:
829 # - the hash input parameter MUST have been set from the $refname part
830 # of the URL (i.e. they must be equal)
831 # - the snapshot format MUST NOT have been defined already (e.g. from
833 # It's also useless to try any matching unless $refname has a dot,
834 # so we check for that too
835 if (defined $input_params{'action'} &&
836 $input_params{'action'} eq 'snapshot' &&
837 defined $refname && index($refname, '.') != -1 &&
838 $refname eq $input_params{'hash'} &&
839 !defined $input_params{'snapshot_format'}) {
840 # We loop over the known snapshot formats, checking for
841 # extensions. Allowed extensions are both the defined suffix
842 # (which includes the initial dot already) and the snapshot
843 # format key itself, with a prepended dot
844 while (my ($fmt, $opt) = each %known_snapshot_formats) {
846 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
850 # a valid suffix was found, so set the snapshot format
851 # and reset the hash parameter
852 $input_params{'snapshot_format'} = $fmt;
853 $input_params{'hash'} = $hash;
854 # we also set the format suffix to the one requested
855 # in the URL: this way a request for e.g. .tgz returns
856 # a .tgz instead of a .tar.gz
857 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
863 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
864 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
865 $searchtext, $search_regexp);
866 sub evaluate_and_validate_params
{
867 our $action = $input_params{'action'};
868 if (defined $action) {
869 if (!validate_action
($action)) {
870 die_error
(400, "Invalid action parameter");
874 # parameters which are pathnames
875 our $project = $input_params{'project'};
876 if (defined $project) {
877 if (!validate_project
($project)) {
879 die_error
(404, "No such project");
883 our $file_name = $input_params{'file_name'};
884 if (defined $file_name) {
885 if (!validate_pathname
($file_name)) {
886 die_error
(400, "Invalid file parameter");
890 our $file_parent = $input_params{'file_parent'};
891 if (defined $file_parent) {
892 if (!validate_pathname
($file_parent)) {
893 die_error
(400, "Invalid file parent parameter");
897 # parameters which are refnames
898 our $hash = $input_params{'hash'};
900 if (!validate_refname
($hash)) {
901 die_error
(400, "Invalid hash parameter");
905 our $hash_parent = $input_params{'hash_parent'};
906 if (defined $hash_parent) {
907 if (!validate_refname
($hash_parent)) {
908 die_error
(400, "Invalid hash parent parameter");
912 our $hash_base = $input_params{'hash_base'};
913 if (defined $hash_base) {
914 if (!validate_refname
($hash_base)) {
915 die_error
(400, "Invalid hash base parameter");
919 our @extra_options = @
{$input_params{'extra_options'}};
920 # @extra_options is always defined, since it can only be (currently) set from
921 # CGI, and $cgi->param() returns the empty array in array context if the param
923 foreach my $opt (@extra_options) {
924 if (not exists $allowed_options{$opt}) {
925 die_error
(400, "Invalid option parameter");
927 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
928 die_error
(400, "Invalid option parameter for this action");
932 our $hash_parent_base = $input_params{'hash_parent_base'};
933 if (defined $hash_parent_base) {
934 if (!validate_refname
($hash_parent_base)) {
935 die_error
(400, "Invalid hash parent base parameter");
940 our $page = $input_params{'page'};
942 if ($page =~ m/[^0-9]/) {
943 die_error
(400, "Invalid page parameter");
947 our $searchtype = $input_params{'searchtype'};
948 if (defined $searchtype) {
949 if ($searchtype =~ m/[^a-z]/) {
950 die_error
(400, "Invalid searchtype parameter");
954 our $search_use_regexp = $input_params{'search_use_regexp'};
956 our $searchtext = $input_params{'searchtext'};
958 if (defined $searchtext) {
959 if (length($searchtext) < 2) {
960 die_error
(403, "At least two characters are required for search parameter");
962 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
966 # path to the current git repository
968 sub evaluate_git_dir
{
969 our $git_dir = "$projectroot/$project" if $project;
972 our (@snapshot_fmts, $git_avatar);
973 sub configure_gitweb_features
{
974 # list of supported snapshot formats
975 our @snapshot_fmts = gitweb_get_feature
('snapshot');
976 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
978 # check that the avatar feature is set to a known provider name,
979 # and for each provider check if the dependencies are satisfied.
980 # if the provider name is invalid or the dependencies are not met,
981 # reset $git_avatar to the empty string.
982 our ($git_avatar) = gitweb_get_feature
('avatar');
983 if ($git_avatar eq 'gravatar') {
984 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
985 } elsif ($git_avatar eq 'picon') {
992 # custom error handler: 'die <message>' is Internal Server Error
993 sub handle_errors_html
{
994 my $msg = shift; # it is already HTML escaped
996 # to avoid infinite loop where error occurs in die_error,
997 # change handler to default handler, disabling handle_errors_html
998 set_message
("Error occured when inside die_error:\n$msg");
1000 # you cannot jump out of die_error when called as error handler;
1001 # the subroutine set via CGI::Carp::set_message is called _after_
1002 # HTTP headers are already written, so it cannot write them itself
1003 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1005 set_message
(\
&handle_errors_html
);
1009 if (!defined $action) {
1010 if (defined $hash) {
1011 $action = git_get_type
($hash);
1012 } elsif (defined $hash_base && defined $file_name) {
1013 $action = git_get_type
("$hash_base:$file_name");
1014 } elsif (defined $project) {
1015 $action = 'summary';
1017 $action = 'project_list';
1020 if (!defined($actions{$action})) {
1021 die_error
(400, "Unknown action");
1023 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1025 die_error
(400, "Project needed");
1027 $actions{$action}->();
1031 our $t0 = [Time
::HiRes
::gettimeofday
()]
1033 our $number_of_git_cmds = 0;
1040 evaluate_gitweb_config
();
1043 # $projectroot and $projects_list might be set in gitweb config file
1044 $projects_list ||= $projectroot;
1046 evaluate_query_params
();
1047 evaluate_path_info
();
1048 evaluate_and_validate_params
();
1051 configure_gitweb_features
();
1056 our $is_last_request = sub { 1 };
1057 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1060 sub configure_as_fcgi
{
1062 our $CGI = 'CGI::Fast';
1064 my $request_number = 0;
1065 # let each child service 100 requests
1066 our $is_last_request = sub { ++$request_number > 100 };
1069 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1071 if $script_name =~ /\.fcgi$/;
1073 return unless (@ARGV);
1075 require Getopt
::Long
;
1076 Getopt
::Long
::GetOptions
(
1077 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1078 'nproc|n=i' => sub {
1079 my ($arg, $val) = @_;
1080 return unless eval { require FCGI
::ProcManager
; 1; };
1081 my $proc_manager = FCGI
::ProcManager
->new({
1082 n_processes
=> $val,
1084 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1085 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1086 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1093 evaluate_git_version
();
1095 $pre_listen_hook->()
1096 if $pre_listen_hook;
1099 while ($cgi = $CGI->new()) {
1100 $pre_dispatch_hook->()
1101 if $pre_dispatch_hook;
1105 $pre_dispatch_hook->()
1106 if $post_dispatch_hook;
1108 last REQUEST
if ($is_last_request->());
1117 if (defined caller) {
1118 # wrapped in a subroutine processing requests,
1119 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1122 # pure CGI script, serving single request
1126 ## ======================================================================
1129 # possible values of extra options
1130 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1131 # -replay => 1 - start from a current view (replay with modifications)
1132 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1135 # default is to use -absolute url() i.e. $my_uri
1136 my $href = $params{-full
} ?
$my_url : $my_uri;
1138 $params{'project'} = $project unless exists $params{'project'};
1140 if ($params{-replay
}) {
1141 while (my ($name, $symbol) = each %cgi_param_mapping) {
1142 if (!exists $params{$name}) {
1143 $params{$name} = $input_params{$name};
1148 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1149 if (defined $params{'project'} &&
1150 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1151 # try to put as many parameters as possible in PATH_INFO:
1154 # - hash_parent or hash_parent_base:/file_parent
1155 # - hash or hash_base:/filename
1156 # - the snapshot_format as an appropriate suffix
1158 # When the script is the root DirectoryIndex for the domain,
1159 # $href here would be something like http://gitweb.example.com/
1160 # Thus, we strip any trailing / from $href, to spare us double
1161 # slashes in the final URL
1164 # Then add the project name, if present
1165 $href .= "/".esc_url
($params{'project'});
1166 delete $params{'project'};
1168 # since we destructively absorb parameters, we keep this
1169 # boolean that remembers if we're handling a snapshot
1170 my $is_snapshot = $params{'action'} eq 'snapshot';
1172 # Summary just uses the project path URL, any other action is
1174 if (defined $params{'action'}) {
1175 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1176 delete $params{'action'};
1179 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1180 # stripping nonexistent or useless pieces
1181 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1182 || $params{'hash_parent'} || $params{'hash'});
1183 if (defined $params{'hash_base'}) {
1184 if (defined $params{'hash_parent_base'}) {
1185 $href .= esc_url
($params{'hash_parent_base'});
1186 # skip the file_parent if it's the same as the file_name
1187 if (defined $params{'file_parent'}) {
1188 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1189 delete $params{'file_parent'};
1190 } elsif ($params{'file_parent'} !~ /\.\./) {
1191 $href .= ":/".esc_url
($params{'file_parent'});
1192 delete $params{'file_parent'};
1196 delete $params{'hash_parent'};
1197 delete $params{'hash_parent_base'};
1198 } elsif (defined $params{'hash_parent'}) {
1199 $href .= esc_url
($params{'hash_parent'}). "..";
1200 delete $params{'hash_parent'};
1203 $href .= esc_url
($params{'hash_base'});
1204 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1205 $href .= ":/".esc_url
($params{'file_name'});
1206 delete $params{'file_name'};
1208 delete $params{'hash'};
1209 delete $params{'hash_base'};
1210 } elsif (defined $params{'hash'}) {
1211 $href .= esc_url
($params{'hash'});
1212 delete $params{'hash'};
1215 # If the action was a snapshot, we can absorb the
1216 # snapshot_format parameter too
1218 my $fmt = $params{'snapshot_format'};
1219 # snapshot_format should always be defined when href()
1220 # is called, but just in case some code forgets, we
1221 # fall back to the default
1222 $fmt ||= $snapshot_fmts[0];
1223 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1224 delete $params{'snapshot_format'};
1228 # now encode the parameters explicitly
1230 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1231 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1232 if (defined $params{$name}) {
1233 if (ref($params{$name}) eq "ARRAY") {
1234 foreach my $par (@
{$params{$name}}) {
1235 push @result, $symbol . "=" . esc_param
($par);
1238 push @result, $symbol . "=" . esc_param
($params{$name});
1242 $href .= "?" . join(';', @result) if scalar @result;
1248 ## ======================================================================
1249 ## validation, quoting/unquoting and escaping
1251 sub validate_action
{
1252 my $input = shift || return undef;
1253 return undef unless exists $actions{$input};
1257 sub validate_project
{
1258 my $input = shift || return undef;
1259 if (!validate_pathname
($input) ||
1260 !(-d
"$projectroot/$input") ||
1261 !check_export_ok
("$projectroot/$input") ||
1262 ($strict_export && !project_in_list
($input))) {
1269 sub validate_pathname
{
1270 my $input = shift || return undef;
1272 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1273 # at the beginning, at the end, and between slashes.
1274 # also this catches doubled slashes
1275 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1278 # no null characters
1279 if ($input =~ m!\0!) {
1285 sub validate_refname
{
1286 my $input = shift || return undef;
1288 # textual hashes are O.K.
1289 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1292 # it must be correct pathname
1293 $input = validate_pathname
($input)
1295 # restrictions on ref name according to git-check-ref-format
1296 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1302 # decode sequences of octets in utf8 into Perl's internal form,
1303 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1304 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1307 return undef unless defined $str;
1308 if (utf8
::valid
($str)) {
1312 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1316 # quote unsafe chars, but keep the slash, even when it's not
1317 # correct, but quoted slashes look too horrible in bookmarks
1320 return undef unless defined $str;
1321 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1326 # quote unsafe chars in whole URL, so some characters cannot be quoted
1329 return undef unless defined $str;
1330 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1335 # quote unsafe characters in HTML attributes
1338 # for XHTML conformance escaping '"' to '"' is not enough
1339 return esc_html
(@_);
1342 # replace invalid utf8 character with SUBSTITUTION sequence
1347 return undef unless defined $str;
1349 $str = to_utf8
($str);
1350 $str = $cgi->escapeHTML($str);
1351 if ($opts{'-nbsp'}) {
1352 $str =~ s/ / /g;
1354 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1358 # quote control characters and escape filename to HTML
1363 return undef unless defined $str;
1365 $str = to_utf8
($str);
1366 $str = $cgi->escapeHTML($str);
1367 if ($opts{'-nbsp'}) {
1368 $str =~ s/ / /g;
1370 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1374 # Make control characters "printable", using character escape codes (CEC)
1378 my %es = ( # character escape codes, aka escape sequences
1379 "\t" => '\t', # tab (HT)
1380 "\n" => '\n', # line feed (LF)
1381 "\r" => '\r', # carrige return (CR)
1382 "\f" => '\f', # form feed (FF)
1383 "\b" => '\b', # backspace (BS)
1384 "\a" => '\a', # alarm (bell) (BEL)
1385 "\e" => '\e', # escape (ESC)
1386 "\013" => '\v', # vertical tab (VT)
1387 "\000" => '\0', # nul character (NUL)
1389 my $chr = ( (exists $es{$cntrl})
1391 : sprintf('\%2x', ord($cntrl)) );
1392 if ($opts{-nohtml
}) {
1395 return "<span class=\"cntrl\">$chr</span>";
1399 # Alternatively use unicode control pictures codepoints,
1400 # Unicode "printable representation" (PR)
1405 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1406 if ($opts{-nohtml
}) {
1409 return "<span class=\"cntrl\">$chr</span>";
1413 # git may return quoted and escaped filenames
1419 my %es = ( # character escape codes, aka escape sequences
1420 't' => "\t", # tab (HT, TAB)
1421 'n' => "\n", # newline (NL)
1422 'r' => "\r", # return (CR)
1423 'f' => "\f", # form feed (FF)
1424 'b' => "\b", # backspace (BS)
1425 'a' => "\a", # alarm (bell) (BEL)
1426 'e' => "\e", # escape (ESC)
1427 'v' => "\013", # vertical tab (VT)
1430 if ($seq =~ m/^[0-7]{1,3}$/) {
1431 # octal char sequence
1432 return chr(oct($seq));
1433 } elsif (exists $es{$seq}) {
1434 # C escape sequence, aka character escape code
1437 # quoted ordinary character
1441 if ($str =~ m/^"(.*)"$/) {
1444 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1449 # escape tabs (convert tabs to spaces)
1453 while ((my $pos = index($line, "\t")) != -1) {
1454 if (my $count = (8 - ($pos % 8))) {
1455 my $spaces = ' ' x
$count;
1456 $line =~ s/\t/$spaces/;
1463 sub project_in_list
{
1464 my $project = shift;
1465 my @list = git_get_projects_list
();
1466 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1469 ## ----------------------------------------------------------------------
1470 ## HTML aware string manipulation
1472 # Try to chop given string on a word boundary between position
1473 # $len and $len+$add_len. If there is no word boundary there,
1474 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1475 # (marking chopped part) would be longer than given string.
1479 my $add_len = shift || 10;
1480 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1482 # Make sure perl knows it is utf8 encoded so we don't
1483 # cut in the middle of a utf8 multibyte char.
1484 $str = to_utf8
($str);
1486 # allow only $len chars, but don't cut a word if it would fit in $add_len
1487 # if it doesn't fit, cut it if it's still longer than the dots we would add
1488 # remove chopped character entities entirely
1490 # when chopping in the middle, distribute $len into left and right part
1491 # return early if chopping wouldn't make string shorter
1492 if ($where eq 'center') {
1493 return $str if ($len + 5 >= length($str)); # filler is length 5
1496 return $str if ($len + 4 >= length($str)); # filler is length 4
1499 # regexps: ending and beginning with word part up to $add_len
1500 my $endre = qr/.{$len}\w{0,$add_len}/;
1501 my $begre = qr/\w{0,$add_len}.{$len}/;
1503 if ($where eq 'left') {
1504 $str =~ m/^(.*?)($begre)$/;
1505 my ($lead, $body) = ($1, $2);
1506 if (length($lead) > 4) {
1509 return "$lead$body";
1511 } elsif ($where eq 'center') {
1512 $str =~ m/^($endre)(.*)$/;
1513 my ($left, $str) = ($1, $2);
1514 $str =~ m/^(.*?)($begre)$/;
1515 my ($mid, $right) = ($1, $2);
1516 if (length($mid) > 5) {
1519 return "$left$mid$right";
1522 $str =~ m/^($endre)(.*)$/;
1525 if (length($tail) > 4) {
1528 return "$body$tail";
1532 # takes the same arguments as chop_str, but also wraps a <span> around the
1533 # result with a title attribute if it does get chopped. Additionally, the
1534 # string is HTML-escaped.
1535 sub chop_and_escape_str
{
1538 my $chopped = chop_str
(@_);
1539 if ($chopped eq $str) {
1540 return esc_html
($chopped);
1542 $str =~ s/[[:cntrl:]]/?/g;
1543 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1547 ## ----------------------------------------------------------------------
1548 ## functions returning short strings
1550 # CSS class for given age value (in seconds)
1554 if (!defined $age) {
1556 } elsif ($age < 60*60*2) {
1558 } elsif ($age < 60*60*24*2) {
1565 # convert age in seconds to "nn units ago" string
1570 if ($age > 60*60*24*365*2) {
1571 $age_str = (int $age/60/60/24/365);
1572 $age_str .= " years ago";
1573 } elsif ($age > 60*60*24*(365/12)*2) {
1574 $age_str = int $age/60/60/24/(365/12);
1575 $age_str .= " months ago";
1576 } elsif ($age > 60*60*24*7*2) {
1577 $age_str = int $age/60/60/24/7;
1578 $age_str .= " weeks ago";
1579 } elsif ($age > 60*60*24*2) {
1580 $age_str = int $age/60/60/24;
1581 $age_str .= " days ago";
1582 } elsif ($age > 60*60*2) {
1583 $age_str = int $age/60/60;
1584 $age_str .= " hours ago";
1585 } elsif ($age > 60*2) {
1586 $age_str = int $age/60;
1587 $age_str .= " min ago";
1588 } elsif ($age > 2) {
1589 $age_str = int $age;
1590 $age_str .= " sec ago";
1592 $age_str .= " right now";
1598 S_IFINVALID
=> 0030000,
1599 S_IFGITLINK
=> 0160000,
1602 # submodule/subproject, a commit object reference
1606 return (($mode & S_IFMT
) == S_IFGITLINK
)
1609 # convert file mode in octal to symbolic file mode string
1611 my $mode = oct shift;
1613 if (S_ISGITLINK
($mode)) {
1614 return 'm---------';
1615 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1616 return 'drwxr-xr-x';
1617 } elsif (S_ISLNK
($mode)) {
1618 return 'lrwxrwxrwx';
1619 } elsif (S_ISREG
($mode)) {
1620 # git cares only about the executable bit
1621 if ($mode & S_IXUSR
) {
1622 return '-rwxr-xr-x';
1624 return '-rw-r--r--';
1627 return '----------';
1631 # convert file mode in octal to file type string
1635 if ($mode !~ m/^[0-7]+$/) {
1641 if (S_ISGITLINK
($mode)) {
1643 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1645 } elsif (S_ISLNK
($mode)) {
1647 } elsif (S_ISREG
($mode)) {
1654 # convert file mode in octal to file type description string
1655 sub file_type_long
{
1658 if ($mode !~ m/^[0-7]+$/) {
1664 if (S_ISGITLINK
($mode)) {
1666 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1668 } elsif (S_ISLNK
($mode)) {
1670 } elsif (S_ISREG
($mode)) {
1671 if ($mode & S_IXUSR
) {
1672 return "executable";
1682 ## ----------------------------------------------------------------------
1683 ## functions returning short HTML fragments, or transforming HTML fragments
1684 ## which don't belong to other sections
1686 # format line of commit message.
1687 sub format_log_line_html
{
1690 $line = esc_html
($line, -nbsp
=>1);
1691 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1692 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1693 -class => "text"}, $1);
1699 # format marker of refs pointing to given object
1701 # the destination action is chosen based on object type and current context:
1702 # - for annotated tags, we choose the tag view unless it's the current view
1703 # already, in which case we go to shortlog view
1704 # - for other refs, we keep the current view if we're in history, shortlog or
1705 # log view, and select shortlog otherwise
1706 sub format_ref_marker
{
1707 my ($refs, $id) = @_;
1710 if (defined $refs->{$id}) {
1711 foreach my $ref (@
{$refs->{$id}}) {
1712 # this code exploits the fact that non-lightweight tags are the
1713 # only indirect objects, and that they are the only objects for which
1714 # we want to use tag instead of shortlog as action
1715 my ($type, $name) = qw();
1716 my $indirect = ($ref =~ s/\^\{\}$//);
1717 # e.g. tags/v2.6.11 or heads/next
1718 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1727 $class .= " indirect" if $indirect;
1729 my $dest_action = "shortlog";
1732 $dest_action = "tag" unless $action eq "tag";
1733 } elsif ($action =~ /^(history|(short)?log)$/) {
1734 $dest_action = $action;
1738 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1741 my $link = $cgi->a({
1743 action
=>$dest_action,
1747 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
1753 return ' <span class="refs">'. $markers . '</span>';
1759 # format, perhaps shortened and with markers, title line
1760 sub format_subject_html
{
1761 my ($long, $short, $href, $extra) = @_;
1762 $extra = '' unless defined($extra);
1764 if (length($short) < length($long)) {
1765 $long =~ s/[[:cntrl:]]/?/g;
1766 return $cgi->a({-href
=> $href, -class => "list subject",
1767 -title
=> to_utf8
($long)},
1768 esc_html
($short)) . $extra;
1770 return $cgi->a({-href
=> $href, -class => "list subject"},
1771 esc_html
($long)) . $extra;
1775 # Rather than recomputing the url for an email multiple times, we cache it
1776 # after the first hit. This gives a visible benefit in views where the avatar
1777 # for the same email is used repeatedly (e.g. shortlog).
1778 # The cache is shared by all avatar engines (currently gravatar only), which
1779 # are free to use it as preferred. Since only one avatar engine is used for any
1780 # given page, there's no risk for cache conflicts.
1781 our %avatar_cache = ();
1783 # Compute the picon url for a given email, by using the picon search service over at
1784 # http://www.cs.indiana.edu/picons/search.html
1786 my $email = lc shift;
1787 if (!$avatar_cache{$email}) {
1788 my ($user, $domain) = split('@', $email);
1789 $avatar_cache{$email} =
1790 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1792 "users+domains+unknown/up/single";
1794 return $avatar_cache{$email};
1797 # Compute the gravatar url for a given email, if it's not in the cache already.
1798 # Gravatar stores only the part of the URL before the size, since that's the
1799 # one computationally more expensive. This also allows reuse of the cache for
1800 # different sizes (for this particular engine).
1802 my $email = lc shift;
1804 $avatar_cache{$email} ||=
1805 "http://www.gravatar.com/avatar/" .
1806 Digest
::MD5
::md5_hex
($email) . "?s=";
1807 return $avatar_cache{$email} . $size;
1810 # Insert an avatar for the given $email at the given $size if the feature
1812 sub git_get_avatar
{
1813 my ($email, %opts) = @_;
1814 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1815 my $post_white = ($opts{-pad_after
} ?
" " : "");
1816 $opts{-size
} ||= 'default';
1817 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1819 if ($git_avatar eq 'gravatar') {
1820 $url = gravatar_url
($email, $size);
1821 } elsif ($git_avatar eq 'picon') {
1822 $url = picon_url
($email);
1824 # Other providers can be added by extending the if chain, defining $url
1825 # as needed. If no variant puts something in $url, we assume avatars
1826 # are completely disabled/unavailable.
1829 "<img width=\"$size\" " .
1830 "class=\"avatar\" " .
1831 "src=\"".esc_url
($url)."\" " .
1839 sub format_search_author
{
1840 my ($author, $searchtype, $displaytext) = @_;
1841 my $have_search = gitweb_check_feature
('search');
1845 if ($searchtype eq 'author') {
1846 $performed = "authored";
1847 } elsif ($searchtype eq 'committer') {
1848 $performed = "committed";
1851 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1852 searchtext
=>$author,
1853 searchtype
=>$searchtype), class=>"list",
1854 title
=>"Search for commits $performed by $author"},
1858 return $displaytext;
1862 # format the author name of the given commit with the given tag
1863 # the author name is chopped and escaped according to the other
1864 # optional parameters (see chop_str).
1865 sub format_author_html
{
1868 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1869 return "<$tag class=\"author\">" .
1870 format_search_author
($co->{'author_name'}, "author",
1871 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1876 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1877 sub format_git_diff_header_line
{
1879 my $diffinfo = shift;
1880 my ($from, $to) = @_;
1882 if ($diffinfo->{'nparents'}) {
1884 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1885 if ($to->{'href'}) {
1886 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1887 esc_path
($to->{'file'}));
1888 } else { # file was deleted (no href)
1889 $line .= esc_path
($to->{'file'});
1893 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1894 if ($from->{'href'}) {
1895 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1896 'a/' . esc_path
($from->{'file'}));
1897 } else { # file was added (no href)
1898 $line .= 'a/' . esc_path
($from->{'file'});
1901 if ($to->{'href'}) {
1902 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1903 'b/' . esc_path
($to->{'file'}));
1904 } else { # file was deleted
1905 $line .= 'b/' . esc_path
($to->{'file'});
1909 return "<div class=\"diff header\">$line</div>\n";
1912 # format extended diff header line, before patch itself
1913 sub format_extended_diff_header_line
{
1915 my $diffinfo = shift;
1916 my ($from, $to) = @_;
1919 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1920 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1921 esc_path
($from->{'file'}));
1923 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1924 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1925 esc_path
($to->{'file'}));
1927 # match single <mode>
1928 if ($line =~ m/\s(\d{6})$/) {
1929 $line .= '<span class="info"> (' .
1930 file_type_long
($1) .
1934 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1935 # can match only for combined diff
1937 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1938 if ($from->{'href'}[$i]) {
1939 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1941 substr($diffinfo->{'from_id'}[$i],0,7));
1946 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1949 if ($to->{'href'}) {
1950 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1951 substr($diffinfo->{'to_id'},0,7));
1956 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1957 # can match only for ordinary diff
1958 my ($from_link, $to_link);
1959 if ($from->{'href'}) {
1960 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1961 substr($diffinfo->{'from_id'},0,7));
1963 $from_link = '0' x
7;
1965 if ($to->{'href'}) {
1966 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1967 substr($diffinfo->{'to_id'},0,7));
1971 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1972 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1975 return $line . "<br/>\n";
1978 # format from-file/to-file diff header
1979 sub format_diff_from_to_header
{
1980 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1985 #assert($line =~ m/^---/) if DEBUG;
1986 # no extra formatting for "^--- /dev/null"
1987 if (! $diffinfo->{'nparents'}) {
1988 # ordinary (single parent) diff
1989 if ($line =~ m!^--- "?a/!) {
1990 if ($from->{'href'}) {
1992 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1993 esc_path
($from->{'file'}));
1996 esc_path
($from->{'file'});
1999 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2002 # combined diff (merge commit)
2003 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2004 if ($from->{'href'}[$i]) {
2006 $cgi->a({-href
=>href
(action
=>"blobdiff",
2007 hash_parent
=>$diffinfo->{'from_id'}[$i],
2008 hash_parent_base
=>$parents[$i],
2009 file_parent
=>$from->{'file'}[$i],
2010 hash
=>$diffinfo->{'to_id'},
2012 file_name
=>$to->{'file'}),
2014 -title
=>"diff" . ($i+1)},
2017 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2018 esc_path
($from->{'file'}[$i]));
2020 $line = '--- /dev/null';
2022 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2027 #assert($line =~ m/^\+\+\+/) if DEBUG;
2028 # no extra formatting for "^+++ /dev/null"
2029 if ($line =~ m!^\+\+\+ "?b/!) {
2030 if ($to->{'href'}) {
2032 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2033 esc_path
($to->{'file'}));
2036 esc_path
($to->{'file'});
2039 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2044 # create note for patch simplified by combined diff
2045 sub format_diff_cc_simplified
{
2046 my ($diffinfo, @parents) = @_;
2049 $result .= "<div class=\"diff header\">" .
2051 if (!is_deleted
($diffinfo)) {
2052 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2054 hash
=>$diffinfo->{'to_id'},
2055 file_name
=>$diffinfo->{'to_file'}),
2057 esc_path
($diffinfo->{'to_file'}));
2059 $result .= esc_path
($diffinfo->{'to_file'});
2061 $result .= "</div>\n" . # class="diff header"
2062 "<div class=\"diff nodifferences\">" .
2064 "</div>\n"; # class="diff nodifferences"
2069 # format patch (diff) line (not to be used for diff headers)
2070 sub format_diff_line
{
2072 my ($from, $to) = @_;
2073 my $diff_class = "";
2077 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2079 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2080 if ($line =~ m/^\@{3}/) {
2081 $diff_class = " chunk_header";
2082 } elsif ($line =~ m/^\\/) {
2083 $diff_class = " incomplete";
2084 } elsif ($prefix =~ tr/+/+/) {
2085 $diff_class = " add";
2086 } elsif ($prefix =~ tr/-/-/) {
2087 $diff_class = " rem";
2090 # assume ordinary diff
2091 my $char = substr($line, 0, 1);
2093 $diff_class = " add";
2094 } elsif ($char eq '-') {
2095 $diff_class = " rem";
2096 } elsif ($char eq '@') {
2097 $diff_class = " chunk_header";
2098 } elsif ($char eq "\\") {
2099 $diff_class = " incomplete";
2102 $line = untabify
($line);
2103 if ($from && $to && $line =~ m/^\@{2} /) {
2104 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2105 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2107 $from_lines = 0 unless defined $from_lines;
2108 $to_lines = 0 unless defined $to_lines;
2110 if ($from->{'href'}) {
2111 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2112 -class=>"list"}, $from_text);
2114 if ($to->{'href'}) {
2115 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2116 -class=>"list"}, $to_text);
2118 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2119 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2120 return "<div class=\"diff$diff_class\">$line</div>\n";
2121 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2122 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2123 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2125 @from_text = split(' ', $ranges);
2126 for (my $i = 0; $i < @from_text; ++$i) {
2127 ($from_start[$i], $from_nlines[$i]) =
2128 (split(',', substr($from_text[$i], 1)), 0);
2131 $to_text = pop @from_text;
2132 $to_start = pop @from_start;
2133 $to_nlines = pop @from_nlines;
2135 $line = "<span class=\"chunk_info\">$prefix ";
2136 for (my $i = 0; $i < @from_text; ++$i) {
2137 if ($from->{'href'}[$i]) {
2138 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2139 -class=>"list"}, $from_text[$i]);
2141 $line .= $from_text[$i];
2145 if ($to->{'href'}) {
2146 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2147 -class=>"list"}, $to_text);
2151 $line .= " $prefix</span>" .
2152 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2153 return "<div class=\"diff$diff_class\">$line</div>\n";
2155 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2158 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2159 # linked. Pass the hash of the tree/commit to snapshot.
2160 sub format_snapshot_links
{
2162 my $num_fmts = @snapshot_fmts;
2163 if ($num_fmts > 1) {
2164 # A parenthesized list of links bearing format names.
2165 # e.g. "snapshot (_tar.gz_ _zip_)"
2166 return "snapshot (" . join(' ', map
2173 }, $known_snapshot_formats{$_}{'display'})
2174 , @snapshot_fmts) . ")";
2175 } elsif ($num_fmts == 1) {
2176 # A single "snapshot" link whose tooltip bears the format name.
2178 my ($fmt) = @snapshot_fmts;
2184 snapshot_format
=>$fmt
2186 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2188 } else { # $num_fmts == 0
2193 ## ......................................................................
2194 ## functions returning values to be passed, perhaps after some
2195 ## transformation, to other functions; e.g. returning arguments to href()
2197 # returns hash to be passed to href to generate gitweb URL
2198 # in -title key it returns description of link
2200 my $format = shift || 'Atom';
2201 my %res = (action
=> lc($format));
2203 # feed links are possible only for project views
2204 return unless (defined $project);
2205 # some views should link to OPML, or to generic project feed,
2206 # or don't have specific feed yet (so they should use generic)
2207 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2210 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2211 # from tag links; this also makes possible to detect branch links
2212 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2213 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2216 # find log type for feed description (title)
2218 if (defined $file_name) {
2219 $type = "history of $file_name";
2220 $type .= "/" if ($action eq 'tree');
2221 $type .= " on '$branch'" if (defined $branch);
2223 $type = "log of $branch" if (defined $branch);
2226 $res{-title
} = $type;
2227 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2228 $res{'file_name'} = $file_name;
2233 ## ----------------------------------------------------------------------
2234 ## git utility subroutines, invoking git commands
2236 # returns path to the core git executable and the --git-dir parameter as list
2238 $number_of_git_cmds++;
2239 return $GIT, '--git-dir='.$git_dir;
2242 # quote the given arguments for passing them to the shell
2243 # quote_command("command", "arg 1", "arg with ' and ! characters")
2244 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2245 # Try to avoid using this function wherever possible.
2248 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2251 # get HEAD ref of given project as hash
2252 sub git_get_head_hash
{
2253 return git_get_full_hash
(shift, 'HEAD');
2256 sub git_get_full_hash
{
2257 return git_get_hash
(@_);
2260 sub git_get_short_hash
{
2261 return git_get_hash
(@_, '--short=7');
2265 my ($project, $hash, @options) = @_;
2266 my $o_git_dir = $git_dir;
2268 $git_dir = "$projectroot/$project";
2269 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2270 '--verify', '-q', @options, $hash) {
2272 chomp $retval if defined $retval;
2275 if (defined $o_git_dir) {
2276 $git_dir = $o_git_dir;
2281 # get type of given object
2285 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2287 close $fd or return;
2292 # repository configuration
2293 our $config_file = '';
2296 # store multiple values for single key as anonymous array reference
2297 # single values stored directly in the hash, not as [ <value> ]
2298 sub hash_set_multi
{
2299 my ($hash, $key, $value) = @_;
2301 if (!exists $hash->{$key}) {
2302 $hash->{$key} = $value;
2303 } elsif (!ref $hash->{$key}) {
2304 $hash->{$key} = [ $hash->{$key}, $value ];
2306 push @
{$hash->{$key}}, $value;
2310 # return hash of git project configuration
2311 # optionally limited to some section, e.g. 'gitweb'
2312 sub git_parse_project_config
{
2313 my $section_regexp = shift;
2318 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2321 while (my $keyval = <$fh>) {
2323 my ($key, $value) = split(/\n/, $keyval, 2);
2325 hash_set_multi
(\
%config, $key, $value)
2326 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2333 # convert config value to boolean: 'true' or 'false'
2334 # no value, number > 0, 'true' and 'yes' values are true
2335 # rest of values are treated as false (never as error)
2336 sub config_to_bool
{
2339 return 1 if !defined $val; # section.key
2341 # strip leading and trailing whitespace
2345 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2346 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2349 # convert config value to simple decimal number
2350 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2351 # to be multiplied by 1024, 1048576, or 1073741824
2355 # strip leading and trailing whitespace
2359 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2361 # unknown unit is treated as 1
2362 return $num * ($unit eq 'g' ?
1073741824 :
2363 $unit eq 'm' ?
1048576 :
2364 $unit eq 'k' ?
1024 : 1);
2369 # convert config value to array reference, if needed
2370 sub config_to_multi
{
2373 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2376 sub git_get_project_config
{
2377 my ($key, $type) = @_;
2379 return unless defined $git_dir;
2382 return unless ($key);
2383 $key =~ s/^gitweb\.//;
2384 return if ($key =~ m/\W/);
2387 if (defined $type) {
2390 unless ($type eq 'bool' || $type eq 'int');
2394 if (!defined $config_file ||
2395 $config_file ne "$git_dir/config") {
2396 %config = git_parse_project_config
('gitweb');
2397 $config_file = "$git_dir/config";
2400 # check if config variable (key) exists
2401 return unless exists $config{"gitweb.$key"};
2404 if (!defined $type) {
2405 return $config{"gitweb.$key"};
2406 } elsif ($type eq 'bool') {
2407 # backward compatibility: 'git config --bool' returns true/false
2408 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2409 } elsif ($type eq 'int') {
2410 return config_to_int
($config{"gitweb.$key"});
2412 return $config{"gitweb.$key"};
2415 # get hash of given path at given ref
2416 sub git_get_hash_by_path
{
2418 my $path = shift || return undef;
2423 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2424 or die_error
(500, "Open git-ls-tree failed");
2426 close $fd or return undef;
2428 if (!defined $line) {
2429 # there is no tree or hash given by $path at $base
2433 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2434 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2435 if (defined $type && $type ne $2) {
2436 # type doesn't match
2442 # get path of entry with given hash at given tree-ish (ref)
2443 # used to get 'from' filename for combined diff (merge commit) for renames
2444 sub git_get_path_by_hash
{
2445 my $base = shift || return;
2446 my $hash = shift || return;
2450 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2452 while (my $line = <$fd>) {
2455 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2456 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2457 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2466 ## ......................................................................
2467 ## git utility functions, directly accessing git repository
2469 sub git_get_project_description
{
2472 $git_dir = "$projectroot/$path";
2473 open my $fd, '<', "$git_dir/description"
2474 or return git_get_project_config
('description');
2477 if (defined $descr) {
2483 sub git_get_project_ctags
{
2487 $git_dir = "$projectroot/$path";
2488 opendir my $dh, "$git_dir/ctags"
2490 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2491 open my $ct, '<', $_ or next;
2495 my $ctag = $_; $ctag =~ s
#.*/##;
2496 $ctags->{$ctag} = $val;
2502 sub git_populate_project_tagcloud
{
2505 # First, merge different-cased tags; tags vote on casing
2507 foreach (keys %$ctags) {
2508 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2509 if (not $ctags_lc{lc $_}->{topcount
}
2510 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2511 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2512 $ctags_lc{lc $_}->{topname
} = $_;
2517 if (eval { require HTML
::TagCloud
; 1; }) {
2518 $cloud = HTML
::TagCloud
->new;
2519 foreach (sort keys %ctags_lc) {
2520 # Pad the title with spaces so that the cloud looks
2522 my $title = $ctags_lc{$_}->{topname
};
2523 $title =~ s/ / /g;
2524 $title =~ s/^/ /g;
2525 $title =~ s/$/ /g;
2526 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2529 $cloud = \
%ctags_lc;
2534 sub git_show_project_tagcloud
{
2535 my ($cloud, $count) = @_;
2536 print STDERR
ref($cloud)."..\n";
2537 if (ref $cloud eq 'HTML::TagCloud') {
2538 return $cloud->html_and_css($count);
2540 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2541 return '<p align="center">' . join (', ', map {
2542 $cgi->a({-href
=>"$home_link?by_tag=$_"}, $cloud->{$_}->{topname
})
2543 } splice(@tags, 0, $count)) . '</p>';
2547 sub git_get_project_url_list
{
2550 $git_dir = "$projectroot/$path";
2551 open my $fd, '<', "$git_dir/cloneurl"
2552 or return wantarray ?
2553 @
{ config_to_multi
(git_get_project_config
('url')) } :
2554 config_to_multi
(git_get_project_config
('url'));
2555 my @git_project_url_list = map { chomp; $_ } <$fd>;
2558 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2561 sub git_get_projects_list
{
2566 $filter =~ s/\.git$//;
2568 my $check_forks = gitweb_check_feature
('forks');
2570 if (-d
$projects_list) {
2571 # search in directory
2572 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2573 # remove the trailing "/"
2575 my $pfxlen = length("$dir");
2576 my $pfxdepth = ($dir =~ tr!/!!);
2579 follow_fast
=> 1, # follow symbolic links
2580 follow_skip
=> 2, # ignore duplicates
2581 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2584 our $project_maxdepth;
2586 # skip project-list toplevel, if we get it.
2587 return if (m!^[/.]$!);
2588 # only directories can be git repositories
2589 return unless (-d
$_);
2590 # don't traverse too deep (Find is super slow on os x)
2591 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2592 $File::Find
::prune
= 1;
2596 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2597 # we check related file in $projectroot
2598 my $path = ($filter ?
"$filter/" : '') . $subdir;
2599 if (check_export_ok
("$projectroot/$path")) {
2600 push @list, { path
=> $path };
2601 $File::Find
::prune
= 1;
2606 } elsif (-f
$projects_list) {
2607 # read from file(url-encoded):
2608 # 'git%2Fgit.git Linus+Torvalds'
2609 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2610 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2612 open my $fd, '<', $projects_list or return;
2614 while (my $line = <$fd>) {
2616 my ($path, $owner) = split ' ', $line;
2617 $path = unescape
($path);
2618 $owner = unescape
($owner);
2619 if (!defined $path) {
2622 if ($filter ne '') {
2623 # looking for forks;
2624 my $pfx = substr($path, 0, length($filter));
2625 if ($pfx ne $filter) {
2628 my $sfx = substr($path, length($filter));
2629 if ($sfx !~ /^\/.*\
.git
$/) {
2632 } elsif ($check_forks) {
2634 foreach my $filter (keys %paths) {
2635 # looking for forks;
2636 my $pfx = substr($path, 0, length($filter));
2637 if ($pfx ne $filter) {
2640 my $sfx = substr($path, length($filter));
2641 if ($sfx !~ /^\/.*\
.git
$/) {
2644 # is a fork, don't include it in
2649 if (check_export_ok
("$projectroot/$path")) {
2652 owner
=> to_utf8
($owner),
2655 (my $forks_path = $path) =~ s/\.git$//;
2656 $paths{$forks_path}++;
2664 our $gitweb_project_owner = undef;
2665 sub git_get_project_list_from_file
{
2667 return if (defined $gitweb_project_owner);
2669 $gitweb_project_owner = {};
2670 # read from file (url-encoded):
2671 # 'git%2Fgit.git Linus+Torvalds'
2672 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2673 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2674 if (-f
$projects_list) {
2675 open(my $fd, '<', $projects_list);
2676 while (my $line = <$fd>) {
2678 my ($pr, $ow) = split ' ', $line;
2679 $pr = unescape
($pr);
2680 $ow = unescape
($ow);
2681 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2687 sub git_get_project_owner
{
2688 my $project = shift;
2691 return undef unless $project;
2692 $git_dir = "$projectroot/$project";
2694 if (!defined $gitweb_project_owner) {
2695 git_get_project_list_from_file
();
2698 if (exists $gitweb_project_owner->{$project}) {
2699 $owner = $gitweb_project_owner->{$project};
2701 if (!defined $owner){
2702 $owner = git_get_project_config
('owner');
2704 if (!defined $owner) {
2705 $owner = get_file_owner
("$git_dir");
2711 sub git_get_last_activity
{
2715 $git_dir = "$projectroot/$path";
2716 open($fd, "-|", git_cmd
(), 'for-each-ref',
2717 '--format=%(committer)',
2718 '--sort=-committerdate',
2720 'refs/heads') or return;
2721 my $most_recent = <$fd>;
2722 close $fd or return;
2723 if (defined $most_recent &&
2724 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2726 my $age = time - $timestamp;
2727 return ($age, age_string
($age));
2729 return (undef, undef);
2732 sub git_get_references
{
2733 my $type = shift || "";
2735 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2736 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2737 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2738 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2741 while (my $line = <$fd>) {
2743 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2744 if (defined $refs{$1}) {
2745 push @
{$refs{$1}}, $2;
2751 close $fd or return;
2755 sub git_get_rev_name_tags
{
2756 my $hash = shift || return undef;
2758 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2760 my $name_rev = <$fd>;
2763 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2766 # catches also '$hash undefined' output
2771 ## ----------------------------------------------------------------------
2772 ## parse to hash functions
2776 my $tz = shift || "-0000";
2779 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2780 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2781 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2782 $date{'hour'} = $hour;
2783 $date{'minute'} = $min;
2784 $date{'mday'} = $mday;
2785 $date{'day'} = $days[$wday];
2786 $date{'month'} = $months[$mon];
2787 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2788 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2789 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2790 $mday, $months[$mon], $hour ,$min;
2791 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2792 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2794 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2795 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2796 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2797 $date{'hour_local'} = $hour;
2798 $date{'minute_local'} = $min;
2799 $date{'tz_local'} = $tz;
2800 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2801 1900+$year, $mon+1, $mday,
2802 $hour, $min, $sec, $tz);
2811 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2812 $tag{'id'} = $tag_id;
2813 while (my $line = <$fd>) {
2815 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2816 $tag{'object'} = $1;
2817 } elsif ($line =~ m/^type (.+)$/) {
2819 } elsif ($line =~ m/^tag (.+)$/) {
2821 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2822 $tag{'author'} = $1;
2823 $tag{'author_epoch'} = $2;
2824 $tag{'author_tz'} = $3;
2825 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2826 $tag{'author_name'} = $1;
2827 $tag{'author_email'} = $2;
2829 $tag{'author_name'} = $tag{'author'};
2831 } elsif ($line =~ m/--BEGIN/) {
2832 push @comment, $line;
2834 } elsif ($line eq "") {
2838 push @comment, <$fd>;
2839 $tag{'comment'} = \
@comment;
2840 close $fd or return;
2841 if (!defined $tag{'name'}) {
2847 sub parse_commit_text
{
2848 my ($commit_text, $withparents) = @_;
2849 my @commit_lines = split '\n', $commit_text;
2852 pop @commit_lines; # Remove '\0'
2854 if (! @commit_lines) {
2858 my $header = shift @commit_lines;
2859 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2862 ($co{'id'}, my @parents) = split ' ', $header;
2863 while (my $line = shift @commit_lines) {
2864 last if $line eq "\n";
2865 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2867 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2869 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2870 $co{'author'} = to_utf8
($1);
2871 $co{'author_epoch'} = $2;
2872 $co{'author_tz'} = $3;
2873 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2874 $co{'author_name'} = $1;
2875 $co{'author_email'} = $2;
2877 $co{'author_name'} = $co{'author'};
2879 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2880 $co{'committer'} = to_utf8
($1);
2881 $co{'committer_epoch'} = $2;
2882 $co{'committer_tz'} = $3;
2883 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2884 $co{'committer_name'} = $1;
2885 $co{'committer_email'} = $2;
2887 $co{'committer_name'} = $co{'committer'};
2891 if (!defined $co{'tree'}) {
2894 $co{'parents'} = \
@parents;
2895 $co{'parent'} = $parents[0];
2897 foreach my $title (@commit_lines) {
2900 $co{'title'} = chop_str
($title, 80, 5);
2901 # remove leading stuff of merges to make the interesting part visible
2902 if (length($title) > 50) {
2903 $title =~ s/^Automatic //;
2904 $title =~ s/^merge (of|with) /Merge ... /i;
2905 if (length($title) > 50) {
2906 $title =~ s/(http|rsync):\/\///;
2908 if (length($title) > 50) {
2909 $title =~ s/(master|www|rsync)\.//;
2911 if (length($title) > 50) {
2912 $title =~ s/kernel.org:?//;
2914 if (length($title) > 50) {
2915 $title =~ s/\/pub\/scm//;
2918 $co{'title_short'} = chop_str
($title, 50, 5);
2922 if (! defined $co{'title'} || $co{'title'} eq "") {
2923 $co{'title'} = $co{'title_short'} = '(no commit message)';
2925 # remove added spaces
2926 foreach my $line (@commit_lines) {
2929 $co{'comment'} = \
@commit_lines;
2931 my $age = time - $co{'committer_epoch'};
2933 $co{'age_string'} = age_string
($age);
2934 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2935 if ($age > 60*60*24*7*2) {
2936 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2937 $co{'age_string_age'} = $co{'age_string'};
2939 $co{'age_string_date'} = $co{'age_string'};
2940 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2946 my ($commit_id) = @_;
2951 open my $fd, "-|", git_cmd
(), "rev-list",
2957 or die_error
(500, "Open git-rev-list failed");
2958 %co = parse_commit_text
(<$fd>, 1);
2965 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2973 open my $fd, "-|", git_cmd
(), "rev-list",
2976 ("--max-count=" . $maxcount),
2977 ("--skip=" . $skip),
2981 ($filename ?
($filename) : ())
2982 or die_error
(500, "Open git-rev-list failed");
2983 while (my $line = <$fd>) {
2984 my %co = parse_commit_text
($line);
2989 return wantarray ?
@cos : \
@cos;
2992 # parse line of git-diff-tree "raw" output
2993 sub parse_difftree_raw_line
{
2997 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2998 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2999 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3000 $res{'from_mode'} = $1;
3001 $res{'to_mode'} = $2;
3002 $res{'from_id'} = $3;
3004 $res{'status'} = $5;
3005 $res{'similarity'} = $6;
3006 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3007 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3009 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3012 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3013 # combined diff (for merge commit)
3014 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3015 $res{'nparents'} = length($1);
3016 $res{'from_mode'} = [ split(' ', $2) ];
3017 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3018 $res{'from_id'} = [ split(' ', $3) ];
3019 $res{'to_id'} = pop @
{$res{'from_id'}};
3020 $res{'status'} = [ split('', $4) ];
3021 $res{'to_file'} = unquote
($5);
3023 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3024 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3025 $res{'commit'} = $1;
3028 return wantarray ?
%res : \
%res;
3031 # wrapper: return parsed line of git-diff-tree "raw" output
3032 # (the argument might be raw line, or parsed info)
3033 sub parsed_difftree_line
{
3034 my $line_or_ref = shift;
3036 if (ref($line_or_ref) eq "HASH") {
3037 # pre-parsed (or generated by hand)
3038 return $line_or_ref;
3040 return parse_difftree_raw_line
($line_or_ref);
3044 # parse line of git-ls-tree output
3045 sub parse_ls_tree_line
{
3051 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3052 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3061 $res{'name'} = unquote
($5);
3064 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3065 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3073 $res{'name'} = unquote
($4);
3077 return wantarray ?
%res : \
%res;
3080 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3081 sub parse_from_to_diffinfo
{
3082 my ($diffinfo, $from, $to, @parents) = @_;
3084 if ($diffinfo->{'nparents'}) {
3086 $from->{'file'} = [];
3087 $from->{'href'} = [];
3088 fill_from_file_info
($diffinfo, @parents)
3089 unless exists $diffinfo->{'from_file'};
3090 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3091 $from->{'file'}[$i] =
3092 defined $diffinfo->{'from_file'}[$i] ?
3093 $diffinfo->{'from_file'}[$i] :
3094 $diffinfo->{'to_file'};
3095 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3096 $from->{'href'}[$i] = href
(action
=>"blob",
3097 hash_base
=>$parents[$i],
3098 hash
=>$diffinfo->{'from_id'}[$i],
3099 file_name
=>$from->{'file'}[$i]);
3101 $from->{'href'}[$i] = undef;
3105 # ordinary (not combined) diff
3106 $from->{'file'} = $diffinfo->{'from_file'};
3107 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3108 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3109 hash
=>$diffinfo->{'from_id'},
3110 file_name
=>$from->{'file'});
3112 delete $from->{'href'};
3116 $to->{'file'} = $diffinfo->{'to_file'};
3117 if (!is_deleted
($diffinfo)) { # file exists in result
3118 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3119 hash
=>$diffinfo->{'to_id'},
3120 file_name
=>$to->{'file'});
3122 delete $to->{'href'};
3126 ## ......................................................................
3127 ## parse to array of hashes functions
3129 sub git_get_heads_list
{
3133 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3134 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3135 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3138 while (my $line = <$fd>) {
3142 my ($refinfo, $committerinfo) = split(/\0/, $line);
3143 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3144 my ($committer, $epoch, $tz) =
3145 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3146 $ref_item{'fullname'} = $name;
3147 $name =~ s!^refs/heads/!!;
3149 $ref_item{'name'} = $name;
3150 $ref_item{'id'} = $hash;
3151 $ref_item{'title'} = $title || '(no commit message)';
3152 $ref_item{'epoch'} = $epoch;
3154 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3156 $ref_item{'age'} = "unknown";
3159 push @headslist, \
%ref_item;
3163 return wantarray ?
@headslist : \
@headslist;
3166 sub git_get_tags_list
{
3170 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3171 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3172 '--format=%(objectname) %(objecttype) %(refname) '.
3173 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3176 while (my $line = <$fd>) {
3180 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3181 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3182 my ($creator, $epoch, $tz) =
3183 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3184 $ref_item{'fullname'} = $name;
3185 $name =~ s!^refs/tags/!!;
3187 $ref_item{'type'} = $type;
3188 $ref_item{'id'} = $id;
3189 $ref_item{'name'} = $name;
3190 if ($type eq "tag") {
3191 $ref_item{'subject'} = $title;
3192 $ref_item{'reftype'} = $reftype;
3193 $ref_item{'refid'} = $refid;
3195 $ref_item{'reftype'} = $type;
3196 $ref_item{'refid'} = $id;
3199 if ($type eq "tag" || $type eq "commit") {
3200 $ref_item{'epoch'} = $epoch;
3202 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3204 $ref_item{'age'} = "unknown";
3208 push @tagslist, \
%ref_item;
3212 return wantarray ?
@tagslist : \
@tagslist;
3215 ## ----------------------------------------------------------------------
3216 ## filesystem-related functions
3218 sub get_file_owner
{
3221 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3222 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3223 if (!defined $gcos) {
3227 $owner =~ s/[,;].*$//;
3228 return to_utf8
($owner);
3231 # assume that file exists
3233 my $filename = shift;
3235 open my $fd, '<', $filename;
3236 print map { to_utf8
($_) } <$fd>;
3240 ## ......................................................................
3241 ## mimetype related functions
3243 sub mimetype_guess_file
{
3244 my $filename = shift;
3245 my $mimemap = shift;
3246 -r
$mimemap or return undef;
3249 open(my $mh, '<', $mimemap) or return undef;
3251 next if m/^#/; # skip comments
3252 my ($mimetype, $exts) = split(/\t+/);
3253 if (defined $exts) {
3254 my @exts = split(/\s+/, $exts);
3255 foreach my $ext (@exts) {
3256 $mimemap{$ext} = $mimetype;
3262 $filename =~ /\.([^.]*)$/;
3263 return $mimemap{$1};
3266 sub mimetype_guess
{
3267 my $filename = shift;
3269 $filename =~ /\./ or return undef;
3271 if ($mimetypes_file) {
3272 my $file = $mimetypes_file;
3273 if ($file !~ m!^/!) { # if it is relative path
3274 # it is relative to project
3275 $file = "$projectroot/$project/$file";
3277 $mime = mimetype_guess_file
($filename, $file);
3279 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3285 my $filename = shift;
3288 my $mime = mimetype_guess
($filename);
3289 $mime and return $mime;
3293 return $default_blob_plain_mimetype unless $fd;
3296 return 'text/plain';
3297 } elsif (! $filename) {
3298 return 'application/octet-stream';
3299 } elsif ($filename =~ m/\.png$/i) {
3301 } elsif ($filename =~ m/\.gif$/i) {
3303 } elsif ($filename =~ m/\.jpe?g$/i) {
3304 return 'image/jpeg';
3306 return 'application/octet-stream';
3310 sub blob_contenttype
{
3311 my ($fd, $file_name, $type) = @_;
3313 $type ||= blob_mimetype
($fd, $file_name);
3314 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3315 $type .= "; charset=$default_text_plain_charset";
3321 # guess file syntax for syntax highlighting; return undef if no highlighting
3322 # the name of syntax can (in the future) depend on syntax highlighter used
3323 sub guess_file_syntax
{
3324 my ($highlight, $mimetype, $file_name) = @_;
3325 return undef unless ($highlight && defined $file_name);
3327 # configuration for 'highlight' (http://www.andre-simon.de/)
3329 my %highlight_basename = (
3332 'SConstruct' => 'py', # SCons equivalent of Makefile
3333 'Makefile' => 'make',
3335 # match by extension
3336 my %highlight_ext = (
3337 # main extensions, defining name of syntax;
3338 # see files in /usr/share/highlight/langDefs/ directory
3340 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
3341 # alternate extensions, see /etc/highlight/filetypes.conf
3343 map { $_ => 'cpp' } qw(cxx c++ cc),
3344 map { $_ => 'php' } qw(php3 php4),
3345 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
3347 map { $_ => 'xml' } qw(xhtml html htm),
3350 my $basename = basename
($file_name, '.in');
3351 return $highlight_basename{$basename}
3352 if exists $highlight_basename{$basename};
3354 $basename =~ /\.([^.]*)$/;
3355 my $ext = $1 or return undef;
3356 return $highlight_ext{$ext}
3357 if exists $highlight_ext{$ext};
3362 # run highlighter and return FD of its output,
3363 # or return original FD if no highlighting
3364 sub run_highlighter
{
3365 my ($fd, $highlight, $syntax) = @_;
3366 return $fd unless ($highlight && defined $syntax);
3369 or die_error
(404, "Reading blob failed");
3370 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3371 "highlight --xhtml --fragment --syntax $syntax |"
3372 or die_error
(500, "Couldn't open file or run syntax highlighter");
3376 ## ======================================================================
3377 ## functions printing HTML: header, footer, error page
3379 sub get_page_title
{
3380 my $title = to_utf8
($site_name);
3382 return $title unless (defined $project);
3383 $title .= " - " . to_utf8
($project);
3385 return $title unless (defined $action);
3386 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3388 return $title unless (defined $file_name);
3389 $title .= " - " . esc_path
($file_name);
3390 if ($action eq "tree" && $file_name !~ m
|/$|) {
3397 sub git_header_html
{
3398 my $status = shift || "200 OK";
3399 my $expires = shift;
3402 my $title = get_page_title
();
3404 # require explicit support from the UA if we are to send the page as
3405 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3406 # we have to do this because MSIE sometimes globs '*/*', pretending to
3407 # support xhtml+xml but choking when it gets what it asked for.
3408 if (defined $cgi->http('HTTP_ACCEPT') &&
3409 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3410 $cgi->Accept('application/xhtml+xml') != 0) {
3411 $content_type = 'application/xhtml+xml';
3413 $content_type = 'text/html';
3415 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3416 -status
=> $status, -expires
=> $expires)
3417 unless ($opts{'-no_http_header'});
3418 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3420 <?xml version="1.0" encoding="utf-8"?>
3421 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3422 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3423 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3424 <!-- git core binaries version $git_version -->
3426 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3427 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3428 <meta name="robots" content="index, nofollow"/>
3429 <title>$title</title>
3431 # the stylesheet, favicon etc urls won't work correctly with path_info
3432 # unless we set the appropriate base URL
3433 if ($ENV{'PATH_INFO'}) {
3434 print "<base href=\"".esc_url
($base_url)."\" />\n";
3436 # print out each stylesheet that exist, providing backwards capability
3437 # for those people who defined $stylesheet in a config file
3438 if (defined $stylesheet) {
3439 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3441 foreach my $stylesheet (@stylesheets) {
3442 next unless $stylesheet;
3443 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3446 if (defined $project) {
3447 my %href_params = get_feed_info
();
3448 if (!exists $href_params{'-title'}) {
3449 $href_params{'-title'} = 'log';
3452 foreach my $format qw(RSS Atom) {
3453 my $type = lc($format);
3455 '-rel' => 'alternate',
3456 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3457 '-type' => "application/$type+xml"
3460 $href_params{'action'} = $type;
3461 $link_attr{'-href'} = href
(%href_params);
3463 "rel=\"$link_attr{'-rel'}\" ".
3464 "title=\"$link_attr{'-title'}\" ".
3465 "href=\"$link_attr{'-href'}\" ".
3466 "type=\"$link_attr{'-type'}\" ".
3469 $href_params{'extra_options'} = '--no-merges';
3470 $link_attr{'-href'} = href
(%href_params);
3471 $link_attr{'-title'} .= ' (no merges)';
3473 "rel=\"$link_attr{'-rel'}\" ".
3474 "title=\"$link_attr{'-title'}\" ".
3475 "href=\"$link_attr{'-href'}\" ".
3476 "type=\"$link_attr{'-type'}\" ".
3481 printf('<link rel="alternate" title="%s projects list" '.
3482 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3483 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3484 printf('<link rel="alternate" title="%s projects feeds" '.
3485 'href="%s" type="text/x-opml" />'."\n",
3486 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3488 if (defined $favicon) {
3489 print qq(<link rel
="shortcut icon" href
=").esc_url($favicon).qq(" type
="image/png" />\n);
3495 if (defined $site_header && -f
$site_header) {
3496 insert_file
($site_header);
3499 print "<div class=\"page_header\">\n";
3500 if (defined $logo) {
3501 print $cgi->a({-href
=> esc_url
($logo_url),
3502 -title
=> $logo_label},
3503 qq(<img src
=").esc_url($logo).qq(" width
="72" height
="27" alt
="git" class="logo"/>));
3505 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3506 if (defined $project) {
3507 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3508 if (defined $action) {
3515 my $have_search = gitweb_check_feature
('search');
3516 if (defined $project && $have_search) {
3517 if (!defined $searchtext) {
3521 if (defined $hash_base) {
3522 $search_hash = $hash_base;
3523 } elsif (defined $hash) {
3524 $search_hash = $hash;
3526 $search_hash = "HEAD";
3528 my $action = $my_uri;
3529 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3530 if ($use_pathinfo) {
3531 $action .= "/".esc_url
($project);
3533 print $cgi->startform(-method
=> "get", -action
=> $action) .
3534 "<div class=\"search\">\n" .
3536 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3537 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3538 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3539 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3540 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3541 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3543 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3544 "<span title=\"Extended regular expression\">" .
3545 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3546 -checked
=> $search_use_regexp) .
3549 $cgi->end_form() . "\n";
3553 sub git_footer_html
{
3554 my $feed_class = 'rss_logo';
3556 print "<div class=\"page_footer\">\n";
3557 if (defined $project) {
3558 my $descr = git_get_project_description
($project);
3559 if (defined $descr) {
3560 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3563 my %href_params = get_feed_info
();
3564 if (!%href_params) {
3565 $feed_class .= ' generic';
3567 $href_params{'-title'} ||= 'log';
3569 foreach my $format qw(RSS Atom) {
3570 $href_params{'action'} = lc($format);
3571 print $cgi->a({-href
=> href
(%href_params),
3572 -title
=> "$href_params{'-title'} $format feed",
3573 -class => $feed_class}, $format)."\n";
3577 print "<div class=\"page_footer_text\">Copyright © 2013, <a href=\"http://nexus-irc.de\">Nexus-IRC.de</a></div>\n";
3578 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3579 -class => $feed_class}, "OPML") . " ";
3580 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3581 -class => $feed_class}, "TXT") . "\n";
3583 print "</div>\n"; # class="page_footer"
3585 if (defined $t0 && gitweb_check_feature
('timed')) {
3586 print "<div id=\"generating_info\">\n";
3587 print 'This page took '.
3588 '<span id="generating_time" class="time_span">'.
3589 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3592 '<span id="generating_cmd">'.
3593 $number_of_git_cmds.
3594 '</span> git commands '.
3596 print "</div>\n"; # class="page_footer"
3599 if (defined $site_footer && -f
$site_footer) {
3600 insert_file
($site_footer);
3603 print qq!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
3604 if (defined $action &&
3605 $action eq 'blame_incremental') {
3606 print qq!<script type
="text/javascript">\n!.
3607 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3608 qq! "!. href() .qq!");\n!.
3610 } elsif (gitweb_check_feature
('javascript-actions')) {
3611 print qq!<script type
="text/javascript">\n!.
3612 qq!window
.onload
= fixLinks
;\n!.
3620 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3621 # Example: die_error(404, 'Hash not found')
3622 # By convention, use the following status codes (as defined in RFC 2616):
3623 # 400: Invalid or missing CGI parameters, or
3624 # requested object exists but has wrong type.
3625 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3626 # this server or project.
3627 # 404: Requested object/revision/project doesn't exist.
3628 # 500: The server isn't configured properly, or
3629 # an internal error occurred (e.g. failed assertions caused by bugs), or
3630 # an unknown error occurred (e.g. the git binary died unexpectedly).
3631 # 503: The server is currently unavailable (because it is overloaded,
3632 # or down for maintenance). Generally, this is a temporary state.
3634 my $status = shift || 500;
3635 my $error = esc_html
(shift) || "Internal Server Error";
3639 my %http_responses = (
3640 400 => '400 Bad Request',
3641 403 => '403 Forbidden',
3642 404 => '404 Not Found',
3643 500 => '500 Internal Server Error',
3644 503 => '503 Service Unavailable',
3646 git_header_html
($http_responses{$status}, undef, %opts);
3648 <div class="page_body">
3653 if (defined $extra) {
3661 unless ($opts{'-error_handler'});
3664 ## ----------------------------------------------------------------------
3665 ## functions printing or outputting HTML: navigation
3667 sub git_print_page_nav
{
3668 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3669 $extra = '' if !defined $extra; # pager or formats
3671 my @navs = qw(summary shortlog log commit commitdiff tree);
3673 @navs = grep { $_ ne $suppress } @navs;
3676 my %arg = map { $_ => {action
=>$_} } @navs;
3677 if (defined $head) {
3678 for (qw(commit commitdiff)) {
3679 $arg{$_}{'hash'} = $head;
3681 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3682 for (qw(shortlog log)) {
3683 $arg{$_}{'hash'} = $head;
3688 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3689 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3691 my @actions = gitweb_get_feature
('actions');
3694 'n' => $project, # project name
3695 'f' => $git_dir, # project path within filesystem
3696 'h' => $treehead || '', # current hash ('h' parameter)
3697 'b' => $treebase || '', # hash base ('hb' parameter)
3700 my ($label, $link, $pos) = splice(@actions,0,3);
3702 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3704 $link =~ s/%([%nfhb])/$repl{$1}/g;
3705 $arg{$label}{'_href'} = $link;
3708 print "<div class=\"page_nav\">\n" .
3710 map { $_ eq $current ?
3711 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3713 print "<br/>\n$extra<br/>\n" .
3717 sub format_paging_nav
{
3718 my ($action, $page, $has_next_link) = @_;
3724 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3726 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3727 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3729 $paging_nav .= "first ⋅ prev";
3732 if ($has_next_link) {
3733 $paging_nav .= " ⋅ " .
3734 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3735 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3737 $paging_nav .= " ⋅ next";
3743 ## ......................................................................
3744 ## functions printing or outputting HTML: div
3746 sub git_print_header_div
{
3747 my ($action, $title, $hash, $hash_base) = @_;
3750 $args{'action'} = $action;
3751 $args{'hash'} = $hash if $hash;
3752 $args{'hash_base'} = $hash_base if $hash_base;
3754 print "<div class=\"header\">\n" .
3755 $cgi->a({-href
=> href
(%args), -class => "title"},
3756 $title ?
$title : $action) .
3760 sub print_local_time
{
3761 print format_local_time
(@_);
3764 sub format_local_time
{
3767 if ($date{'hour_local'} < 6) {
3768 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3769 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3771 $localtime .= sprintf(" (%02d:%02d %s)",
3772 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3778 # Outputs the author name and date in long form
3779 sub git_print_authorship
{
3782 my $tag = $opts{-tag
} || 'div';
3783 my $author = $co->{'author_name'};
3785 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3786 print "<$tag class=\"author_date\">" .
3787 format_search_author
($author, "author", esc_html
($author)) .
3789 print_local_time
(%ad) if ($opts{-localtime});
3790 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3794 # Outputs table rows containing the full author or committer information,
3795 # in the format expected for 'commit' view (& similar).
3796 # Parameters are a commit hash reference, followed by the list of people
3797 # to output information for. If the list is empty it defaults to both
3798 # author and committer.
3799 sub git_print_authorship_rows
{
3801 # too bad we can't use @people = @_ || ('author', 'committer')
3803 @people = ('author', 'committer') unless @people;
3804 foreach my $who (@people) {
3805 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3806 print "<tr><td>$who</td><td>" .
3807 format_search_author
($co->{"${who}_name"}, $who,
3808 esc_html
($co->{"${who}_name"})) . " " .
3809 format_search_author
($co->{"${who}_email"}, $who,
3810 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3811 "</td><td rowspan=\"2\">" .
3812 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3815 "<td></td><td> $wd{'rfc2822'}";
3816 print_local_time
(%wd);
3822 sub git_print_page_path
{
3828 print "<div class=\"page_path\">";
3829 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3830 -title
=> 'tree root'}, to_utf8
("[$project]"));
3832 if (defined $name) {
3833 my @dirname = split '/', $name;
3834 my $basename = pop @dirname;
3837 foreach my $dir (@dirname) {
3838 $fullname .= ($fullname ?
'/' : '') . $dir;
3839 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3841 -title
=> $fullname}, esc_path
($dir));
3844 if (defined $type && $type eq 'blob') {
3845 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3847 -title
=> $name}, esc_path
($basename));
3848 } elsif (defined $type && $type eq 'tree') {
3849 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3851 -title
=> $name}, esc_path
($basename));
3854 print esc_path
($basename);
3857 print "<br/></div>\n";
3864 if ($opts{'-remove_title'}) {
3865 # remove title, i.e. first line of log
3868 # remove leading empty lines
3869 while (defined $log->[0] && $log->[0] eq "") {
3876 foreach my $line (@
$log) {
3877 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3880 if (! $opts{'-remove_signoff'}) {
3881 print "<div class=\"log\">\n";
3882 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3886 # remove signoff lines
3893 # print only one empty line
3894 # do not print empty line after signoff
3896 next if ($empty || $signoff);
3902 print format_log_line_html
($line) . "<br/>\n";
3904 if ($opts{'-final_empty_line'}) {
3905 # end with single empty line
3906 print "<br/>\n" unless $empty;
3910 # return link target (what link points to)
3911 sub git_get_link_target
{
3916 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3920 $link_target = <$fd>;
3925 return $link_target;
3928 # given link target, and the directory (basedir) the link is in,
3929 # return target of link relative to top directory (top tree);
3930 # return undef if it is not possible (including absolute links).
3931 sub normalize_link_target
{
3932 my ($link_target, $basedir) = @_;
3934 # absolute symlinks (beginning with '/') cannot be normalized
3935 return if (substr($link_target, 0, 1) eq '/');
3937 # normalize link target to path from top (root) tree (dir)
3940 $path = $basedir . '/' . $link_target;
3942 # we are in top (root) tree (dir)
3943 $path = $link_target;
3946 # remove //, /./, and /../
3948 foreach my $part (split('/', $path)) {
3949 # discard '.' and ''
3950 next if (!$part || $part eq '.');
3952 if ($part eq '..') {
3956 # link leads outside repository (outside top dir)
3960 push @path_parts, $part;
3963 $path = join('/', @path_parts);
3968 # print tree entry (row of git_tree), but without encompassing <tr> element
3969 sub git_print_tree_entry
{
3970 my ($t, $basedir, $hash_base, $have_blame) = @_;
3973 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3975 # The format of a table row is: mode list link. Where mode is
3976 # the mode of the entry, list is the name of the entry, an href,
3977 # and link is the action links of the entry.
3979 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3980 if (exists $t->{'size'}) {
3981 print "<td class=\"size\">$t->{'size'}</td>\n";
3983 if ($t->{'type'} eq "blob") {
3984 print "<td class=\"list\">" .
3985 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3986 file_name
=>"$basedir$t->{'name'}", %base_key),
3987 -class => "list"}, esc_path
($t->{'name'}));
3988 if (S_ISLNK
(oct $t->{'mode'})) {
3989 my $link_target = git_get_link_target
($t->{'hash'});
3991 my $norm_target = normalize_link_target
($link_target, $basedir);
3992 if (defined $norm_target) {
3994 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3995 file_name
=>$norm_target),
3996 -title
=> $norm_target}, esc_path
($link_target));
3998 print " -> " . esc_path
($link_target);
4003 print "<td class=\"link\">";
4004 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4005 file_name
=>"$basedir$t->{'name'}", %base_key)},
4009 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4010 file_name
=>"$basedir$t->{'name'}", %base_key)},
4013 if (defined $hash_base) {
4015 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4016 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4020 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4021 file_name
=>"$basedir$t->{'name'}")},
4025 } elsif ($t->{'type'} eq "tree") {
4026 print "<td class=\"list\">";
4027 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4028 file_name
=>"$basedir$t->{'name'}",
4030 esc_path
($t->{'name'}));
4032 print "<td class=\"link\">";
4033 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4034 file_name
=>"$basedir$t->{'name'}",
4037 if (defined $hash_base) {
4039 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4040 file_name
=>"$basedir$t->{'name'}")},
4045 # unknown object: we can only present history for it
4046 # (this includes 'commit' object, i.e. submodule support)
4047 print "<td class=\"list\">" .
4048 esc_path
($t->{'name'}) .
4050 print "<td class=\"link\">";
4051 if (defined $hash_base) {
4052 print $cgi->a({-href
=> href
(action
=>"history",
4053 hash_base
=>$hash_base,
4054 file_name
=>"$basedir$t->{'name'}")},
4061 ## ......................................................................
4062 ## functions printing large fragments of HTML
4064 # get pre-image filenames for merge (combined) diff
4065 sub fill_from_file_info
{
4066 my ($diff, @parents) = @_;
4068 $diff->{'from_file'} = [ ];
4069 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4070 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4071 if ($diff->{'status'}[$i] eq 'R' ||
4072 $diff->{'status'}[$i] eq 'C') {
4073 $diff->{'from_file'}[$i] =
4074 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4081 # is current raw difftree line of file deletion
4083 my $diffinfo = shift;
4085 return $diffinfo->{'to_id'} eq ('0' x
40);
4088 # does patch correspond to [previous] difftree raw line
4089 # $diffinfo - hashref of parsed raw diff format
4090 # $patchinfo - hashref of parsed patch diff format
4091 # (the same keys as in $diffinfo)
4092 sub is_patch_split
{
4093 my ($diffinfo, $patchinfo) = @_;
4095 return defined $diffinfo && defined $patchinfo
4096 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4100 sub git_difftree_body
{
4101 my ($difftree, $hash, @parents) = @_;
4102 my ($parent) = $parents[0];
4103 my $have_blame = gitweb_check_feature
('blame');
4104 if ($#{$difftree} > 10) {
4105 print "<div class=\"list_head\">\n";
4106 print(($#{$difftree} + 1) . " files changed:\n");
4110 print "<table class=\"" .
4111 (@parents > 1 ?
"combined " : "") .
4114 # header only for combined diff in 'commitdiff' view
4115 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4118 print "<thead><tr>\n" .
4119 "<th></th><th></th>\n"; # filename, patchN link
4120 for (my $i = 0; $i < @parents; $i++) {
4121 my $par = $parents[$i];
4123 $cgi->a({-href
=> href
(action
=>"commitdiff",
4124 hash
=>$hash, hash_parent
=>$par),
4125 -title
=> 'commitdiff to parent number ' .
4126 ($i+1) . ': ' . substr($par,0,7)},
4130 print "</tr></thead>\n<tbody>\n";
4135 foreach my $line (@
{$difftree}) {
4136 my $diff = parsed_difftree_line
($line);
4139 print "<tr class=\"dark\">\n";
4141 print "<tr class=\"light\">\n";
4145 if (exists $diff->{'nparents'}) { # combined diff
4147 fill_from_file_info
($diff, @parents)
4148 unless exists $diff->{'from_file'};
4150 if (!is_deleted
($diff)) {
4151 # file exists in the result (child) commit
4153 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4154 file_name
=>$diff->{'to_file'},
4156 -class => "list"}, esc_path
($diff->{'to_file'})) .
4160 esc_path
($diff->{'to_file'}) .
4164 if ($action eq 'commitdiff') {
4167 print "<td class=\"link\">" .
4168 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4173 my $has_history = 0;
4174 my $not_deleted = 0;
4175 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4176 my $hash_parent = $parents[$i];
4177 my $from_hash = $diff->{'from_id'}[$i];
4178 my $from_path = $diff->{'from_file'}[$i];
4179 my $status = $diff->{'status'}[$i];
4181 $has_history ||= ($status ne 'A');
4182 $not_deleted ||= ($status ne 'D');
4184 if ($status eq 'A') {
4185 print "<td class=\"link\" align=\"right\"> | </td>\n";
4186 } elsif ($status eq 'D') {
4187 print "<td class=\"link\">" .
4188 $cgi->a({-href
=> href
(action
=>"blob",
4191 file_name
=>$from_path)},
4195 if ($diff->{'to_id'} eq $from_hash) {
4196 print "<td class=\"link nochange\">";
4198 print "<td class=\"link\">";
4200 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4201 hash
=>$diff->{'to_id'},
4202 hash_parent
=>$from_hash,
4204 hash_parent_base
=>$hash_parent,
4205 file_name
=>$diff->{'to_file'},
4206 file_parent
=>$from_path)},
4212 print "<td class=\"link\">";
4214 print $cgi->a({-href
=> href
(action
=>"blob",
4215 hash
=>$diff->{'to_id'},
4216 file_name
=>$diff->{'to_file'},
4219 print " | " if ($has_history);
4222 print $cgi->a({-href
=> href
(action
=>"history",
4223 file_name
=>$diff->{'to_file'},
4230 next; # instead of 'else' clause, to avoid extra indent
4232 # else ordinary diff
4234 my ($to_mode_oct, $to_mode_str, $to_file_type);
4235 my ($from_mode_oct, $from_mode_str, $from_file_type);
4236 if ($diff->{'to_mode'} ne ('0' x
6)) {
4237 $to_mode_oct = oct $diff->{'to_mode'};
4238 if (S_ISREG
($to_mode_oct)) { # only for regular file
4239 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4241 $to_file_type = file_type
($diff->{'to_mode'});
4243 if ($diff->{'from_mode'} ne ('0' x
6)) {
4244 $from_mode_oct = oct $diff->{'from_mode'};
4245 if (S_ISREG
($to_mode_oct)) { # only for regular file
4246 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4248 $from_file_type = file_type
($diff->{'from_mode'});
4251 if ($diff->{'status'} eq "A") { # created
4252 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4253 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4254 $mode_chng .= "]</span>";
4256 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4257 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4258 -class => "list"}, esc_path
($diff->{'file'}));
4260 print "<td>$mode_chng</td>\n";
4261 print "<td class=\"link\">";
4262 if ($action eq 'commitdiff') {
4265 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4268 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4269 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4273 } elsif ($diff->{'status'} eq "D") { # deleted
4274 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4276 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4277 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4278 -class => "list"}, esc_path
($diff->{'file'}));
4280 print "<td>$mode_chng</td>\n";
4281 print "<td class=\"link\">";
4282 if ($action eq 'commitdiff') {
4285 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4288 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4289 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4292 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4293 file_name
=>$diff->{'file'})},
4296 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4297 file_name
=>$diff->{'file'})},
4301 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4302 my $mode_chnge = "";
4303 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4304 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4305 if ($from_file_type ne $to_file_type) {
4306 $mode_chnge .= " from $from_file_type to $to_file_type";
4308 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4309 if ($from_mode_str && $to_mode_str) {
4310 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4311 } elsif ($to_mode_str) {
4312 $mode_chnge .= " mode: $to_mode_str";
4315 $mode_chnge .= "]</span>\n";
4318 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4319 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4320 -class => "list"}, esc_path
($diff->{'file'}));
4322 print "<td>$mode_chnge</td>\n";
4323 print "<td class=\"link\">";
4324 if ($action eq 'commitdiff') {
4327 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4329 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4330 # "commit" view and modified file (not onlu mode changed)
4331 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4332 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4333 hash_base
=>$hash, hash_parent_base
=>$parent,
4334 file_name
=>$diff->{'file'})},
4338 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4339 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4342 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4343 file_name
=>$diff->{'file'})},
4346 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4347 file_name
=>$diff->{'file'})},
4351 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4352 my %status_name = ('R' => 'moved', 'C' => 'copied');
4353 my $nstatus = $status_name{$diff->{'status'}};
4355 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4356 # mode also for directories, so we cannot use $to_mode_str
4357 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4360 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4361 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4362 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4363 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4364 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4365 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4366 -class => "list"}, esc_path
($diff->{'from_file'})) .
4367 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4368 "<td class=\"link\">";
4369 if ($action eq 'commitdiff') {
4372 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4374 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4375 # "commit" view and modified file (not only pure rename or copy)
4376 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4377 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4378 hash_base
=>$hash, hash_parent_base
=>$parent,
4379 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4383 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4384 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4387 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4388 file_name
=>$diff->{'to_file'})},
4391 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4392 file_name
=>$diff->{'to_file'})},
4396 } # we should not encounter Unmerged (U) or Unknown (X) status
4399 print "</tbody>" if $has_header;
4403 sub git_patchset_body
{
4404 my ($fd, $difftree, $hash, @hash_parents) = @_;
4405 my ($hash_parent) = $hash_parents[0];
4407 my $is_combined = (@hash_parents > 1);
4409 my $patch_number = 0;
4415 print "<div class=\"patchset\">\n";
4417 # skip to first patch
4418 while ($patch_line = <$fd>) {
4421 last if ($patch_line =~ m/^diff /);
4425 while ($patch_line) {
4427 # parse "git diff" header line
4428 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4429 # $1 is from_name, which we do not use
4430 $to_name = unquote
($2);
4431 $to_name =~ s!^b/!!;
4432 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4433 # $1 is 'cc' or 'combined', which we do not use
4434 $to_name = unquote
($2);
4439 # check if current patch belong to current raw line
4440 # and parse raw git-diff line if needed
4441 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4442 # this is continuation of a split patch
4443 print "<div class=\"patch cont\">\n";
4445 # advance raw git-diff output if needed
4446 $patch_idx++ if defined $diffinfo;
4448 # read and prepare patch information
4449 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4451 # compact combined diff output can have some patches skipped
4452 # find which patch (using pathname of result) we are at now;
4454 while ($to_name ne $diffinfo->{'to_file'}) {
4455 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4456 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4457 "</div>\n"; # class="patch"
4462 last if $patch_idx > $#$difftree;
4463 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4467 # modifies %from, %to hashes
4468 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4470 # this is first patch for raw difftree line with $patch_idx index
4471 # we index @$difftree array from 0, but number patches from 1
4472 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4476 #assert($patch_line =~ m/^diff /) if DEBUG;
4477 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4479 # print "git diff" header
4480 print format_git_diff_header_line
($patch_line, $diffinfo,
4483 # print extended diff header
4484 print "<div class=\"diff extended_header\">\n";
4486 while ($patch_line = <$fd>) {
4489 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4491 print format_extended_diff_header_line
($patch_line, $diffinfo,
4494 print "</div>\n"; # class="diff extended_header"
4496 # from-file/to-file diff header
4497 if (! $patch_line) {
4498 print "</div>\n"; # class="patch"
4501 next PATCH
if ($patch_line =~ m/^diff /);
4502 #assert($patch_line =~ m/^---/) if DEBUG;
4504 my $last_patch_line = $patch_line;
4505 $patch_line = <$fd>;
4507 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4509 print format_diff_from_to_header
($last_patch_line, $patch_line,
4510 $diffinfo, \
%from, \
%to,
4515 while ($patch_line = <$fd>) {
4518 next PATCH
if ($patch_line =~ m/^diff /);
4520 print format_diff_line
($patch_line, \
%from, \
%to);
4524 print "</div>\n"; # class="patch"
4527 # for compact combined (--cc) format, with chunk and patch simplification
4528 # the patchset might be empty, but there might be unprocessed raw lines
4529 for (++$patch_idx if $patch_number > 0;
4530 $patch_idx < @
$difftree;
4532 # read and prepare patch information
4533 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4535 # generate anchor for "patch" links in difftree / whatchanged part
4536 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4537 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4538 "</div>\n"; # class="patch"
4543 if ($patch_number == 0) {
4544 if (@hash_parents > 1) {
4545 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4547 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4551 print "</div>\n"; # class="patchset"
4554 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4556 # fills project list info (age, description, owner, forks) for each
4557 # project in the list, removing invalid projects from returned list
4558 # NOTE: modifies $projlist, but does not remove entries from it
4559 sub fill_project_list_info
{
4560 my ($projlist, $check_forks) = @_;
4563 my $show_ctags = gitweb_check_feature
('ctags');
4565 foreach my $pr (@
$projlist) {
4566 my (@activity) = git_get_last_activity
($pr->{'path'});
4567 unless (@activity) {
4570 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4571 if (!defined $pr->{'descr'}) {
4572 my $descr = git_get_project_description
($pr->{'path'}) || "";
4573 $descr = to_utf8
($descr);
4574 $pr->{'descr_long'} = $descr;
4575 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4577 if (!defined $pr->{'owner'}) {
4578 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4581 my $pname = $pr->{'path'};
4582 if (($pname =~ s/\.git$//) &&
4583 ($pname !~ /\/$/) &&
4584 (-d
"$projectroot/$pname")) {
4585 $pr->{'forks'} = "-d $projectroot/$pname";
4590 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4591 push @projects, $pr;
4597 # print 'sort by' <th> element, generating 'sort by $name' replay link
4598 # if that order is not selected
4600 print format_sort_th
(@_);
4603 sub format_sort_th
{
4604 my ($name, $order, $header) = @_;
4606 $header ||= ucfirst($name);
4608 if ($order eq $name) {
4609 $sort_th .= "<th>$header</th>\n";
4611 $sort_th .= "<th>" .
4612 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4613 -class => "header"}, $header) .
4620 sub git_project_list_body
{
4621 # actually uses global variable $project
4622 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4624 my $check_forks = gitweb_check_feature
('forks');
4625 my @projects = fill_project_list_info
($projlist, $check_forks);
4627 $order ||= $default_projects_order;
4628 $from = 0 unless defined $from;
4629 $to = $#projects if (!defined $to || $#projects < $to);
4632 project
=> { key
=> 'path', type
=> 'str' },
4633 descr
=> { key
=> 'descr_long', type
=> 'str' },
4634 owner
=> { key
=> 'owner', type
=> 'str' },
4635 age
=> { key
=> 'age', type
=> 'num' }
4637 my $oi = $order_info{$order};
4638 if ($oi->{'type'} eq 'str') {
4639 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4641 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4644 my $show_ctags = gitweb_check_feature
('ctags');
4647 foreach my $p (@projects) {
4648 foreach my $ct (keys %{$p->{'ctags'}}) {
4649 $ctags{$ct} += $p->{'ctags'}->{$ct};
4652 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4653 print git_show_project_tagcloud
($cloud, 64);
4656 print "<table class=\"project_list\">\n";
4657 unless ($no_header) {
4660 print "<th></th>\n";
4662 print_sort_th
('project', $order, 'Project');
4663 print_sort_th
('descr', $order, 'Description');
4664 print_sort_th
('owner', $order, 'Owner');
4665 print_sort_th
('age', $order, 'Last Change');
4666 print "<th></th>\n" . # for links
4670 my $tagfilter = $cgi->param('by_tag');
4671 for (my $i = $from; $i <= $to; $i++) {
4673 my $pr = $projects[$i];
4675 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4676 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4677 and not $pr->{'descr_long'} =~ /$searchtext/;
4678 # Weed out forks or non-matching entries of search
4680 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4681 $forkbase="^$forkbase" if $forkbase;
4682 next if not $searchtext and not $tagfilter and $show_ctags
4683 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4687 print "<tr class=\"dark\">\n";
4689 print "<tr class=\"light\">\n";
4694 if ($pr->{'forks'}) {
4695 print "<!-- $pr->{'forks'} -->\n";
4696 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4700 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4701 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4702 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4703 -class => "list", -title
=> $pr->{'descr_long'}},
4704 esc_html
($pr->{'descr'})) . "</td>\n" .
4705 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4706 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4707 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4708 "<td class=\"link\">" .
4709 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4710 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4711 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4712 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4713 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4717 print "<tr><td> </td><td> </td><td> </td><td>".$count." projects found</td><td> </td><td> </td></tr>";
4718 if (defined $extra) {
4721 print "<td></td>\n";
4723 print "<td colspan=\"5\">$extra</td>\n" .
4730 # uses global variable $project
4731 my ($commitlist, $from, $to, $refs, $extra) = @_;
4733 $from = 0 unless defined $from;
4734 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4736 for (my $i = 0; $i <= $to; $i++) {
4737 my %co = %{$commitlist->[$i]};
4739 my $commit = $co{'id'};
4740 my $ref = format_ref_marker
($refs, $commit);
4741 my %ad = parse_date
($co{'author_epoch'});
4742 git_print_header_div
('commit',
4743 "<span class=\"age\">$co{'age_string'}</span>" .
4744 esc_html
($co{'title'}) . $ref,
4746 print "<div class=\"title_text\">\n" .
4747 "<div class=\"log_link\">\n" .
4748 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4750 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4752 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4755 git_print_authorship
(\
%co, -tag
=> 'span');
4756 print "<br/>\n</div>\n";
4758 print "<div class=\"log_body\">\n";
4759 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4763 print "<div class=\"page_nav\">\n";
4769 sub git_shortlog_body
{
4770 # uses global variable $project
4771 my ($commitlist, $from, $to, $refs, $extra, $file_name, $file_hash, $ftype, $allrefs) = @_;
4773 $from = 0 unless defined $from;
4774 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4776 print "<table class=\"shortlog\" cellspacing=\"0\" cellpadding=\"0\">\n";
4779 my $graph_rand = int(rand(99999));
4780 my $head = git_get_head_hash
($project);
4782 if (defined $allrefs && $allrefs == 1) {
4783 $graph_hash = "all";
4785 if (!defined $hash) {
4788 if(!defined $graph_hash) {
4789 $graph_hash = $hash;
4791 if (!defined $page) {
4795 print "<tr class=\"header\">\n";
4796 print "<td colspan=\"2\"><img class=\"graph\" src=\"git_graph.php?r=".$graph_rand.";p=".$project.";h=".$graph_hash.";from=".($from + (100 * $page)).";to=".($to + (100 * $page)).";c=header\" /></td>\n";
4797 print "<td valign=\"bottom\"><b>Author</b></td>\n";
4798 print "<td valign=\"bottom\"><b>Commit</b></td>\n";
4799 print "<td></td>\n";
4801 for (my $i = $from; $i <= $to; $i++) {
4802 my %co = %{$commitlist->[$i]};
4803 my $commit = $co{'id'};
4804 my $ref = format_ref_marker
($refs, $commit);
4806 print "<tr class=\"dark\">\n";
4808 print "<tr class=\"light\">\n";
4812 print "<td><img class=\"graph\" src=\"git_graph.php?r=".$graph_rand.";p=".$project.";h=".$graph_hash.";from=".($from + (100 * $page)).";to=".($to + (100 * $page)).";c=".$commit."\" /></td>";
4813 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4814 print "<td class=\"". age_class
($co{'age'}) . "\" title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4815 format_author_html
('td', \
%co, 10) . "<td>";
4816 print format_subject_html
($co{'title'}, $co{'title_short'},
4817 href
(action
=>"commit", hash
=>$commit), $ref);
4819 "<td class=\"link\">" .
4820 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4821 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4822 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4823 my $snapshot_links = format_snapshot_links
($commit);
4824 if (defined $snapshot_links) {
4825 print " | " . $snapshot_links;
4830 if (defined $extra) {
4832 "<td colspan=\"5\">$extra</td>\n" .
4838 sub git_history_body
{
4839 # Warning: assumes constant type (blob or tree) during history
4840 my ($commitlist, $from, $to, $refs, $extra,
4841 $file_name, $file_hash, $ftype) = @_;
4843 $from = 0 unless defined $from;
4844 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4846 print "<table class=\"history\">\n";
4848 for (my $i = $from; $i <= $to; $i++) {
4849 my %co = %{$commitlist->[$i]};
4853 my $commit = $co{'id'};
4855 my $ref = format_ref_marker
($refs, $commit);
4858 print "<tr class=\"dark\">\n";
4860 print "<tr class=\"light\">\n";
4863 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4864 # shortlog: format_author_html('td', \%co, 10)
4865 format_author_html
('td', \
%co, 15, 3) . "<td>";
4866 # originally git_history used chop_str($co{'title'}, 50)
4867 print format_subject_html
($co{'title'}, $co{'title_short'},
4868 href
(action
=>"commit", hash
=>$commit), $ref);
4870 "<td class=\"link\">" .
4871 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4872 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4874 if ($ftype eq 'blob') {
4875 my $blob_current = $file_hash;
4876 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4877 if (defined $blob_current && defined $blob_parent &&
4878 $blob_current ne $blob_parent) {
4880 $cgi->a({-href
=> href
(action
=>"blobdiff",
4881 hash
=>$blob_current, hash_parent
=>$blob_parent,
4882 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4883 file_name
=>$file_name)},
4890 if (defined $extra) {
4892 "<td colspan=\"4\">$extra</td>\n" .
4899 # uses global variable $project
4900 my ($taglist, $from, $to, $extra) = @_;
4901 $from = 0 unless defined $from;
4902 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4904 print "<table class=\"tags\">\n";
4906 for (my $i = $from; $i <= $to; $i++) {
4907 my $entry = $taglist->[$i];
4909 my $comment = $tag{'subject'};
4911 if (defined $comment) {
4912 $comment_short = chop_str
($comment, 30, 5);
4915 print "<tr class=\"dark\">\n";
4917 print "<tr class=\"light\">\n";
4920 if (defined $tag{'age'}) {
4921 print "<td><i>$tag{'age'}</i></td>\n";
4923 print "<td></td>\n";
4926 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4927 -class => "list name"}, esc_html
($tag{'name'})) .
4930 if (defined $comment) {
4931 print format_subject_html
($comment, $comment_short,
4932 href
(action
=>"tag", hash
=>$tag{'id'}));
4935 "<td class=\"selflink\">";
4936 if ($tag{'type'} eq "tag") {
4937 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4942 "<td class=\"link\">" . " | " .
4943 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4944 if ($tag{'reftype'} eq "commit") {
4945 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4946 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4947 } elsif ($tag{'reftype'} eq "blob") {
4948 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4953 if (defined $extra) {
4955 "<td colspan=\"5\">$extra</td>\n" .
4961 sub git_heads_body
{
4962 # uses global variable $project
4963 my ($headlist, $head, $from, $to, $extra) = @_;
4964 $from = 0 unless defined $from;
4965 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4967 print "<table class=\"heads\">\n";
4969 for (my $i = $from; $i <= $to; $i++) {
4970 my $entry = $headlist->[$i];
4972 my $curr = $ref{'id'} eq $head;
4974 print "<tr class=\"dark\">\n";
4976 print "<tr class=\"light\">\n";
4979 print "<td><i>$ref{'age'}</i></td>\n" .
4980 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4981 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4982 -class => "list name"},esc_html
($ref{'name'})) .
4984 "<td class=\"link\">" .
4985 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4986 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4987 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4991 if (defined $extra) {
4993 "<td colspan=\"3\">$extra</td>\n" .
4999 sub git_search_grep_body
{
5000 my ($commitlist, $from, $to, $extra) = @_;
5001 $from = 0 unless defined $from;
5002 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5004 print "<table class=\"commit_search\">\n";
5006 for (my $i = $from; $i <= $to; $i++) {
5007 my %co = %{$commitlist->[$i]};
5011 my $commit = $co{'id'};
5013 print "<tr class=\"dark\">\n";
5015 print "<tr class=\"light\">\n";
5018 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5019 format_author_html
('td', \
%co, 15, 5) .
5021 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5022 -class => "list subject"},
5023 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5024 my $comment = $co{'comment'};
5025 foreach my $line (@
$comment) {
5026 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5027 my ($lead, $match, $trail) = ($1, $2, $3);
5028 $match = chop_str
($match, 70, 5, 'center');
5029 my $contextlen = int((80 - length($match))/2);
5030 $contextlen = 30 if ($contextlen > 30);
5031 $lead = chop_str
($lead, $contextlen, 10, 'left');
5032 $trail = chop_str
($trail, $contextlen, 10, 'right');
5034 $lead = esc_html
($lead);
5035 $match = esc_html
($match);
5036 $trail = esc_html
($trail);
5038 print "$lead<span class=\"match\">$match</span>$trail<br />";
5042 "<td class=\"link\">" .
5043 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5045 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5047 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5051 if (defined $extra) {
5053 "<td colspan=\"3\">$extra</td>\n" .
5059 ## ======================================================================
5060 ## ======================================================================
5063 sub git_project_list
{
5064 my $order = $input_params{'order'};
5065 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5066 die_error
(400, "Unknown order parameter");
5069 my @list = git_get_projects_list
();
5071 die_error
(404, "No projects found");
5075 if (defined $home_text && -f
$home_text) {
5076 print "<div class=\"index_include\">\n";
5077 insert_file
($home_text);
5080 print $cgi->startform(-method
=> "get") .
5081 "<p class=\"projsearch\">Search:\n" .
5082 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5084 $cgi->end_form() . "\n";
5085 git_project_list_body
(\
@list, $order);
5090 my $order = $input_params{'order'};
5091 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5092 die_error
(400, "Unknown order parameter");
5095 my @list = git_get_projects_list
($project);
5097 die_error
(404, "No forks found");
5101 git_print_page_nav
('','');
5102 git_print_header_div
('summary', "$project forks");
5103 git_project_list_body
(\
@list, $order);
5107 sub git_project_index
{
5108 my @projects = git_get_projects_list
($project);
5111 -type
=> 'text/plain',
5112 -charset
=> 'utf-8',
5113 -content_disposition
=> 'inline; filename="index.aux"');
5115 foreach my $pr (@projects) {
5116 if (!exists $pr->{'owner'}) {
5117 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5120 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5121 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5122 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5123 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5127 print "$path $owner\n";
5132 my $descr = git_get_project_description
($project) || "none";
5133 my %co = parse_commit
("HEAD");
5134 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5135 my $head = $co{'id'};
5137 my $owner = git_get_project_owner
($project);
5139 my $refs = git_get_references
();
5140 # These get_*_list functions return one more to allow us to see if
5141 # there are more ...
5142 my @taglist = git_get_tags_list
(16);
5143 my @headlist = git_get_heads_list
(16);
5145 my $check_forks = gitweb_check_feature
('forks');
5148 @forklist = git_get_projects_list
($project);
5152 git_print_page_nav
('summary','', $head);
5154 print "<div class=\"title\"> </div>\n";
5155 print "<table class=\"projects_list\">\n" .
5156 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5157 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5158 if (defined $cd{'rfc2822'}) {
5159 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5162 # use per project git URL list in $projectroot/$project/cloneurl
5163 # or make project git URL from git base URL and project name
5164 my $url_tag = "URL";
5165 my @url_list = git_get_project_url_list
($project);
5166 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5167 foreach my $git_url (@url_list) {
5168 next unless $git_url;
5169 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5174 my $show_ctags = gitweb_check_feature
('ctags');
5176 my $ctags = git_get_project_ctags
($project);
5177 my $cloud = git_populate_project_tagcloud
($ctags);
5178 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5179 print "</td>\n<td>" unless %$ctags;
5180 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5181 print "</td>\n<td>" if %$ctags;
5182 print git_show_project_tagcloud
($cloud, 48);
5188 # If XSS prevention is on, we don't include README.html.
5189 # TODO: Allow a readme in some safe format.
5190 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5191 print "<div class=\"title\">readme</div>\n" .
5192 "<div class=\"readme\">\n";
5193 insert_file
("$projectroot/$project/README.html");
5194 print "\n</div>\n"; # class="readme"
5197 # we need to request one more than 16 (0..15) to check if
5199 my @commitlist = $head ? parse_commits
("--all", 17) : ();
5201 git_print_header_div
('shortlog');
5202 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5203 $#commitlist <= 15 ?
undef :
5204 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."), 0, 0, 0, 1);
5208 git_print_header_div
('tags');
5209 git_tags_body
(\
@taglist, 0, 15,
5210 $#taglist <= 15 ?
undef :
5211 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5215 git_print_header_div
('heads');
5216 git_heads_body
(\
@headlist, $head, 0, 15,
5217 $#headlist <= 15 ?
undef :
5218 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5222 git_print_header_div
('forks');
5223 git_project_list_body
(\
@forklist, 'age', 0, 15,
5224 $#forklist <= 15 ?
undef :
5225 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5233 my $head = git_get_head_hash
($project);
5235 git_print_page_nav
('','', $head,undef,$head);
5236 my %tag = parse_tag
($hash);
5239 die_error
(404, "Unknown tag object");
5242 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5243 print "<div class=\"title_text\">\n" .
5244 "<table class=\"object_header\">\n" .
5246 "<td>object</td>\n" .
5247 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5248 $tag{'object'}) . "</td>\n" .
5249 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5250 $tag{'type'}) . "</td>\n" .
5252 if (defined($tag{'author'})) {
5253 git_print_authorship_rows
(\
%tag, 'author');
5255 print "</table>\n\n" .
5257 print "<div class=\"page_body\">";
5258 my $comment = $tag{'comment'};
5259 foreach my $line (@
$comment) {
5261 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5267 sub git_blame_common
{
5268 my $format = shift || 'porcelain';
5269 if ($format eq 'porcelain' && $cgi->param('js')) {
5270 $format = 'incremental';
5271 $action = 'blame_incremental'; # for page title etc
5275 gitweb_check_feature
('blame')
5276 or die_error
(403, "Blame view not allowed");
5279 die_error
(400, "No file name given") unless $file_name;
5280 $hash_base ||= git_get_head_hash
($project);
5281 die_error
(404, "Couldn't find base commit") unless $hash_base;
5282 my %co = parse_commit
($hash_base)
5283 or die_error
(404, "Commit not found");
5285 if (!defined $hash) {
5286 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5287 or die_error
(404, "Error looking up file");
5289 $ftype = git_get_type
($hash);
5290 if ($ftype !~ "blob") {
5291 die_error
(400, "Object is not a blob");
5296 if ($format eq 'incremental') {
5297 # get file contents (as base)
5298 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5299 or die_error
(500, "Open git-cat-file failed");
5300 } elsif ($format eq 'data') {
5301 # run git-blame --incremental
5302 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5303 $hash_base, "--", $file_name
5304 or die_error
(500, "Open git-blame --incremental failed");
5306 # run git-blame --porcelain
5307 open $fd, "-|", git_cmd
(), "blame", '-p',
5308 $hash_base, '--', $file_name
5309 or die_error
(500, "Open git-blame --porcelain failed");
5312 # incremental blame data returns early
5313 if ($format eq 'data') {
5315 -type
=>"text/plain", -charset
=> "utf-8",
5316 -status
=> "200 OK");
5317 local $| = 1; # output autoflush
5320 or print "ERROR $!\n";
5323 if (defined $t0 && gitweb_check_feature
('timed')) {
5325 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5326 ' '.$number_of_git_cmds;
5336 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5339 if ($format eq 'incremental') {
5341 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5342 "blame") . " (non-incremental)";
5345 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5346 "blame") . " (incremental)";
5350 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5353 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5355 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5356 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5357 git_print_page_path
($file_name, $ftype, $hash_base);
5360 if ($format eq 'incremental') {
5361 print "<noscript>\n<div class=\"error\"><center><b>\n".
5362 "This page requires JavaScript to run.\n Use ".
5363 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5366 "</b></center></div>\n</noscript>\n";
5368 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5371 print qq!<div
class="page_body">\n!;
5372 print qq!<div id
="progress_info">... / ...</div
>\n!
5373 if ($format eq 'incremental');
5374 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5375 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5377 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5381 my @rev_color = qw(light dark);
5382 my $num_colors = scalar(@rev_color);
5383 my $current_color = 0;
5385 if ($format eq 'incremental') {
5386 my $color_class = $rev_color[$current_color];
5391 while (my $line = <$fd>) {
5395 print qq!<tr id
="l$linenr" class="$color_class">!.
5396 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5397 qq!<td
class="linenr">!.
5398 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5399 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5403 } else { # porcelain, i.e. ordinary blame
5404 my %metainfo = (); # saves information about commits
5408 while (my $line = <$fd>) {
5410 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5411 # no <lines in group> for subsequent lines in group of lines
5412 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5413 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5414 if (!exists $metainfo{$full_rev}) {
5415 $metainfo{$full_rev} = { 'nprevious' => 0 };
5417 my $meta = $metainfo{$full_rev};
5419 while ($data = <$fd>) {
5421 last if ($data =~ s/^\t//); # contents of line
5422 if ($data =~ /^(\S+)(?: (.*))?$/) {
5423 $meta->{$1} = $2 unless exists $meta->{$1};
5425 if ($data =~ /^previous /) {
5426 $meta->{'nprevious'}++;
5429 my $short_rev = substr($full_rev, 0, 8);
5430 my $author = $meta->{'author'};
5432 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5433 my $date = $date{'iso-tz'};
5435 $current_color = ($current_color + 1) % $num_colors;
5437 my $tr_class = $rev_color[$current_color];
5438 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5439 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5440 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5441 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5443 print "<td class=\"sha1\"";
5444 print " title=\"". esc_html
($author) . ", $date\"";
5445 print " rowspan=\"$group_size\"" if ($group_size > 1);
5447 print $cgi->a({-href
=> href
(action
=>"commit",
5449 file_name
=>$file_name)},
5450 esc_html
($short_rev));
5451 if ($group_size >= 2) {
5452 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5453 if (@author_initials) {
5455 esc_html
(join('', @author_initials));
5461 # 'previous' <sha1 of parent commit> <filename at commit>
5462 if (exists $meta->{'previous'} &&
5463 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5464 $meta->{'parent'} = $1;
5465 $meta->{'file_parent'} = unquote
($2);
5468 exists($meta->{'parent'}) ?
5469 $meta->{'parent'} : $full_rev;
5470 my $linenr_filename =
5471 exists($meta->{'file_parent'}) ?
5472 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5473 my $blamed = href
(action
=> 'blame',
5474 file_name
=> $linenr_filename,
5475 hash_base
=> $linenr_commit);
5476 print "<td class=\"linenr\">";
5477 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5478 -class => "linenr" },
5481 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5489 "</table>\n"; # class="blame"
5490 print "</div>\n"; # class="blame_body"
5492 or print "Reading blob failed\n";
5501 sub git_blame_incremental
{
5502 git_blame_common
('incremental');
5505 sub git_blame_data
{
5506 git_blame_common
('data');
5510 my $head = git_get_head_hash
($project);
5512 git_print_page_nav
('','', $head,undef,$head);
5513 git_print_header_div
('summary', $project);
5515 my @tagslist = git_get_tags_list
();
5517 git_tags_body
(\
@tagslist);
5523 my $head = git_get_head_hash
($project);
5525 git_print_page_nav
('','', $head,undef,$head);
5526 git_print_header_div
('summary', $project);
5528 my @headslist = git_get_heads_list
();
5530 git_heads_body
(\
@headslist, $head);
5535 sub git_blob_plain
{
5539 if (!defined $hash) {
5540 if (defined $file_name) {
5541 my $base = $hash_base || git_get_head_hash
($project);
5542 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5543 or die_error
(404, "Cannot find file");
5545 die_error
(400, "No file name defined");
5547 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5548 # blobs defined by non-textual hash id's can be cached
5552 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5553 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5555 # content-type (can include charset)
5556 $type = blob_contenttype
($fd, $file_name, $type);
5558 # "save as" filename, even when no $file_name is given
5559 my $save_as = "$hash";
5560 if (defined $file_name) {
5561 $save_as = $file_name;
5562 } elsif ($type =~ m/^text\//) {
5566 # With XSS prevention on, blobs of all types except a few known safe
5567 # ones are served with "Content-Disposition: attachment" to make sure
5568 # they don't run in our security domain. For certain image types,
5569 # blob view writes an <img> tag referring to blob_plain view, and we
5570 # want to be sure not to break that by serving the image as an
5571 # attachment (though Firefox 3 doesn't seem to care).
5572 my $sandbox = $prevent_xss &&
5573 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5577 -expires
=> $expires,
5578 -content_disposition
=>
5579 ($sandbox ?
'attachment' : 'inline')
5580 . '; filename="' . $save_as . '"');
5582 binmode STDOUT
, ':raw';
5584 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5591 if (!defined $hash) {
5592 if (defined $file_name) {
5593 my $base = $hash_base || git_get_head_hash
($project);
5594 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5595 or die_error
(404, "Cannot find file");
5597 die_error
(400, "No file name defined");
5599 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5600 # blobs defined by non-textual hash id's can be cached
5604 my $have_blame = gitweb_check_feature
('blame');
5605 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5606 or die_error
(500, "Couldn't cat $file_name, $hash");
5607 my $mimetype = blob_mimetype
($fd, $file_name);
5608 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5609 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5611 return git_blob_plain
($mimetype);
5613 # we can have blame only for text/* mimetype
5614 $have_blame &&= ($mimetype =~ m!^text/!);
5616 my $highlight = gitweb_check_feature
('highlight');
5617 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5618 $fd = run_highlighter
($fd, $highlight, $syntax)
5621 git_header_html
(undef, $expires);
5622 my $formats_nav = '';
5623 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5624 if (defined $file_name) {
5627 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5632 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5635 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5638 $cgi->a({-href
=> href
(action
=>"blob",
5639 hash_base
=>"HEAD", file_name
=>$file_name)},
5643 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5646 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5647 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5649 print "<div class=\"page_nav\">\n" .
5650 "<br/><br/></div>\n" .
5651 "<div class=\"title\">".esc_html
($hash)."</div>\n";
5653 git_print_page_path
($file_name, "blob", $hash_base);
5654 print "<div class=\"page_body\">\n";
5655 if ($mimetype =~ m!^image/!) {
5656 print qq!<img type
="!.esc_attr($mimetype).qq!"!;
5658 print qq! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
5661 href(action=>"blob_plain
", hash=>$hash,
5662 hash_base=>$hash_base, file_name=>$file_name) .
5666 while (my $line = <$fd>) {
5669 $line = untabify
($line);
5670 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5671 $nr, esc_attr
(href
(-replay
=> 1)), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5675 or print "Reading blob failed.\n";
5681 if (!defined $hash_base) {
5682 $hash_base = "HEAD";
5684 if (!defined $hash) {
5685 if (defined $file_name) {
5686 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5691 die_error
(404, "No such tree") unless defined($hash);
5693 my $show_sizes = gitweb_check_feature
('show-sizes');
5694 my $have_blame = gitweb_check_feature
('blame');
5699 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5700 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5701 or die_error
(500, "Open git-ls-tree failed");
5702 @entries = map { chomp; $_ } <$fd>;
5704 or die_error
(404, "Reading tree failed");
5707 my $refs = git_get_references
();
5708 my $ref = format_ref_marker
($refs, $hash_base);
5711 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5713 if (defined $file_name) {
5715 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5717 $cgi->a({-href
=> href
(action
=>"tree",
5718 hash_base
=>"HEAD", file_name
=>$file_name)},
5721 my $snapshot_links = format_snapshot_links
($hash);
5722 if (defined $snapshot_links) {
5723 # FIXME: Should be available when we have no hash base as well.
5724 push @views_nav, $snapshot_links;
5726 git_print_page_nav
('tree','', $hash_base, undef, undef,
5727 join(' | ', @views_nav));
5728 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5731 print "<div class=\"page_nav\">\n";
5732 print "<br/><br/></div>\n";
5733 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
5735 if (defined $file_name) {
5736 $basedir = $file_name;
5737 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5740 git_print_page_path
($file_name, 'tree', $hash_base);
5742 print "<div class=\"page_body\">\n";
5743 print "<table class=\"tree\">\n";
5745 # '..' (top directory) link if possible
5746 if (defined $hash_base &&
5747 defined $file_name && $file_name =~ m![^/]+$!) {
5749 print "<tr class=\"dark\">\n";
5751 print "<tr class=\"light\">\n";
5755 my $up = $file_name;
5756 $up =~ s!/?[^/]+$!!;
5757 undef $up unless $up;
5758 # based on git_print_tree_entry
5759 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5760 print '<td class="size"> </td>'."\n" if $show_sizes;
5761 print '<td class="list">';
5762 print $cgi->a({-href
=> href
(action
=>"tree",
5763 hash_base
=>$hash_base,
5767 print "<td class=\"link\"></td>\n";
5771 foreach my $line (@entries) {
5772 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5775 print "<tr class=\"dark\">\n";
5777 print "<tr class=\"light\">\n";
5781 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5785 print "</table>\n" .
5791 my ($project, $hash) = @_;
5793 # path/to/project.git -> project
5794 # path/to/project/.git -> project
5795 my $name = to_utf8
($project);
5796 $name =~ s
,([^/])/*\
.git
$,$1,;
5797 $name = basename
($name);
5799 $name =~ s/[[:cntrl:]]/?/g;
5802 if ($hash =~ /^[0-9a-fA-F]+$/) {
5803 # shorten SHA-1 hash
5804 my $full_hash = git_get_full_hash
($project, $hash);
5805 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5806 $ver = git_get_short_hash
($project, $hash);
5808 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5809 # tags don't need shortened SHA-1 hash
5812 # branches and other need shortened SHA-1 hash
5813 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5816 $ver .= '-' . git_get_short_hash
($project, $hash);
5818 # in case of hierarchical branch names
5821 # name = project-version_string
5822 $name = "$name-$ver";
5824 return wantarray ?
($name, $name) : $name;
5828 my $format = $input_params{'snapshot_format'};
5829 if (!@snapshot_fmts) {
5830 die_error
(403, "Snapshots not allowed");
5832 # default to first supported snapshot format
5833 $format ||= $snapshot_fmts[0];
5834 if ($format !~ m/^[a-z0-9]+$/) {
5835 die_error
(400, "Invalid snapshot format parameter");
5836 } elsif (!exists($known_snapshot_formats{$format})) {
5837 die_error
(400, "Unknown snapshot format");
5838 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5839 die_error
(403, "Snapshot format not allowed");
5840 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5841 die_error
(403, "Unsupported snapshot format");
5844 my $type = git_get_type
("$hash^{}");
5846 die_error
(404, 'Object does not exist');
5847 } elsif ($type eq 'blob') {
5848 die_error
(400, 'Object is not a tree-ish');
5851 my ($name, $prefix) = snapshot_name
($project, $hash);
5852 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5853 my $cmd = quote_command
(
5854 git_cmd
(), 'archive',
5855 "--format=$known_snapshot_formats{$format}{'format'}",
5856 "--prefix=$prefix/", $hash);
5857 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5858 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5861 $filename =~ s/(["\\])/\\$1/g;
5863 -type
=> $known_snapshot_formats{$format}{'type'},
5864 -content_disposition
=> 'inline; filename="' . $filename . '"',
5865 -status
=> '200 OK');
5867 open my $fd, "-|", $cmd
5868 or die_error
(500, "Execute git-archive failed");
5869 binmode STDOUT
, ':raw';
5871 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5875 sub git_log_generic
{
5876 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5878 my $head = git_get_head_hash
($project);
5880 if (!defined $base) {
5884 if (!defined $page) {
5887 my $refs = git_get_references
();
5889 my $commit_hash = $base;
5890 if (defined $allrefs) {
5891 $commit_hash = "--all";
5893 if (defined $parent) {
5894 $commit_hash = "$parent..$base";
5897 parse_commits
($commit_hash, 101, (100 * $page),
5898 defined $file_name ?
($file_name, "--full-history") : ());
5901 if (!defined $file_hash && defined $file_name) {
5902 # some commits could have deleted file in question,
5903 # and not have it in tree, but one of them has to have it
5904 for (my $i = 0; $i < @commitlist; $i++) {
5905 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5906 last if defined $file_hash;
5909 if (defined $file_hash) {
5910 $ftype = git_get_type
($file_hash);
5912 if (defined $file_name && !defined $ftype) {
5913 die_error
(500, "Unknown type of object");
5916 if (defined $file_name) {
5917 %co = parse_commit
($base)
5918 or die_error
(404, "Unknown commit object");
5922 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5924 if ($#commitlist >= 100) {
5926 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5927 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5929 my $patch_max = gitweb_get_feature
('patches');
5930 if ($patch_max && !defined $file_name) {
5931 if ($patch_max < 0 || @commitlist <= $patch_max) {
5932 $paging_nav .= " ⋅ " .
5933 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5939 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5940 if (defined $file_name) {
5941 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5943 git_print_header_div
('summary', $project)
5945 git_print_page_path
($file_name, $ftype, $hash_base)
5946 if (defined $file_name);
5948 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5949 $file_name, $file_hash, $ftype, $allrefs);
5955 git_log_generic
('log', \
&git_log_body
,
5956 $hash, $hash_parent);
5960 $hash ||= $hash_base || "HEAD";
5961 my %co = parse_commit
($hash)
5962 or die_error
(404, "Unknown commit object");
5964 my $parent = $co{'parent'};
5965 my $parents = $co{'parents'}; # listref
5967 # we need to prepare $formats_nav before any parameter munging
5969 if (!defined $parent) {
5971 $formats_nav .= '(initial)';
5972 } elsif (@
$parents == 1) {
5973 # single parent commit
5976 $cgi->a({-href
=> href
(action
=>"commit",
5978 esc_html
(substr($parent, 0, 7))) .
5985 $cgi->a({-href
=> href
(action
=>"commit",
5987 esc_html
(substr($_, 0, 7)));
5991 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5992 $formats_nav .= " | " .
5993 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5997 if (!defined $parent) {
6001 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
6003 (@
$parents <= 1 ?
$parent : '-c'),
6005 or die_error
(500, "Open git-diff-tree failed");
6006 @difftree = map { chomp; $_ } <$fd>;
6007 close $fd or die_error
(404, "Reading git-diff-tree failed");
6009 # non-textual hash id's can be cached
6011 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6014 my $refs = git_get_references
();
6015 my $ref = format_ref_marker
($refs, $co{'id'});
6017 git_header_html
(undef, $expires);
6018 git_print_page_nav
('commit', '',
6019 $hash, $co{'tree'}, $hash,
6022 if (defined $co{'parent'}) {
6023 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
6025 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
6027 print "<div class=\"title_text\">\n" .
6028 "<table class=\"object_header\">\n";
6029 git_print_authorship_rows
(\
%co);
6030 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6033 "<td class=\"sha1\">" .
6034 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6035 class => "list"}, $co{'tree'}) .
6037 "<td class=\"link\">" .
6038 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6040 my $snapshot_links = format_snapshot_links
($hash);
6041 if (defined $snapshot_links) {
6042 print " | " . $snapshot_links;
6047 foreach my $par (@
$parents) {
6050 "<td class=\"sha1\">" .
6051 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6052 class => "list"}, $par) .
6054 "<td class=\"link\">" .
6055 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6057 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6064 print "<div class=\"page_body\">\n";
6065 git_print_log
($co{'comment'});
6068 git_difftree_body
(\
@difftree, $hash, @
$parents);
6074 # object is defined by:
6075 # - hash or hash_base alone
6076 # - hash_base and file_name
6079 # - hash or hash_base alone
6080 if ($hash || ($hash_base && !defined $file_name)) {
6081 my $object_id = $hash || $hash_base;
6083 open my $fd, "-|", quote_command
(
6084 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6085 or die_error
(404, "Object does not exist");
6089 or die_error
(404, "Object does not exist");
6091 # - hash_base and file_name
6092 } elsif ($hash_base && defined $file_name) {
6093 $file_name =~ s
,/+$,,;
6095 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6096 or die_error
(404, "Base object does not exist");
6098 # here errors should not hapen
6099 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6100 or die_error
(500, "Open git-ls-tree failed");
6104 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6105 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6106 die_error
(404, "File or directory for given base does not exist");
6111 die_error
(400, "Not enough information to find object");
6114 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6115 hash
=>$hash, hash_base
=>$hash_base,
6116 file_name
=>$file_name),
6117 -status
=> '302 Found');
6121 my $format = shift || 'html';
6128 # preparing $fd and %diffinfo for git_patchset_body
6130 if (defined $hash_base && defined $hash_parent_base) {
6131 if (defined $file_name) {
6133 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6134 $hash_parent_base, $hash_base,
6135 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6136 or die_error
(500, "Open git-diff-tree failed");
6137 @difftree = map { chomp; $_ } <$fd>;
6139 or die_error
(404, "Reading git-diff-tree failed");
6141 or die_error
(404, "Blob diff not found");
6143 } elsif (defined $hash &&
6144 $hash =~ /[0-9a-fA-F]{40}/) {
6145 # try to find filename from $hash
6147 # read filtered raw output
6148 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6149 $hash_parent_base, $hash_base, "--"
6150 or die_error
(500, "Open git-diff-tree failed");
6152 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6154 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6155 map { chomp; $_ } <$fd>;
6157 or die_error
(404, "Reading git-diff-tree failed");
6159 or die_error
(404, "Blob diff not found");
6162 die_error
(400, "Missing one of the blob diff parameters");
6165 if (@difftree > 1) {
6166 die_error
(400, "Ambiguous blob diff specification");
6169 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6170 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6171 $file_name ||= $diffinfo{'to_file'};
6173 $hash_parent ||= $diffinfo{'from_id'};
6174 $hash ||= $diffinfo{'to_id'};
6176 # non-textual hash id's can be cached
6177 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6178 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6183 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6184 '-p', ($format eq 'html' ?
"--full-index" : ()),
6185 $hash_parent_base, $hash_base,
6186 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6187 or die_error
(500, "Open git-diff-tree failed");
6190 # old/legacy style URI -- not generated anymore since 1.4.3.
6192 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6196 if ($format eq 'html') {
6198 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6200 git_header_html
(undef, $expires);
6201 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6202 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6203 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6205 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6206 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
6208 if (defined $file_name) {
6209 git_print_page_path
($file_name, "blob", $hash_base);
6211 print "<div class=\"page_path\"></div>\n";
6214 } elsif ($format eq 'plain') {
6216 -type
=> 'text/plain',
6217 -charset
=> 'utf-8',
6218 -expires
=> $expires,
6219 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6221 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6224 die_error
(400, "Unknown blobdiff format");
6228 if ($format eq 'html') {
6229 print "<div class=\"page_body\">\n";
6231 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6234 print "</div>\n"; # class="page_body"
6238 while (my $line = <$fd>) {
6239 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6240 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6244 last if $line =~ m!^\+\+\+!;
6252 sub git_blobdiff_plain
{
6253 git_blobdiff
('plain');
6256 sub git_commitdiff
{
6258 my $format = $params{-format
} || 'html';
6260 my ($patch_max) = gitweb_get_feature
('patches');
6261 if ($format eq 'patch') {
6262 die_error
(403, "Patch view not allowed") unless $patch_max;
6265 $hash ||= $hash_base || "HEAD";
6266 my %co = parse_commit
($hash)
6267 or die_error
(404, "Unknown commit object");
6269 # choose format for commitdiff for merge
6270 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6271 $hash_parent = '--cc';
6273 # we need to prepare $formats_nav before almost any parameter munging
6275 if ($format eq 'html') {
6277 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6279 if ($patch_max && @
{$co{'parents'}} <= 1) {
6280 $formats_nav .= " | " .
6281 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6285 if (defined $hash_parent &&
6286 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6287 # commitdiff with two commits given
6288 my $hash_parent_short = $hash_parent;
6289 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6290 $hash_parent_short = substr($hash_parent, 0, 7);
6294 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6295 if ($co{'parents'}[$i] eq $hash_parent) {
6296 $formats_nav .= ' parent ' . ($i+1);
6300 $formats_nav .= ': ' .
6301 $cgi->a({-href
=> href
(action
=>"commitdiff",
6302 hash
=>$hash_parent)},
6303 esc_html
($hash_parent_short)) .
6305 } elsif (!$co{'parent'}) {
6307 $formats_nav .= ' (initial)';
6308 } elsif (scalar @
{$co{'parents'}} == 1) {
6309 # single parent commit
6312 $cgi->a({-href
=> href
(action
=>"commitdiff",
6313 hash
=>$co{'parent'})},
6314 esc_html
(substr($co{'parent'}, 0, 7))) .
6318 if ($hash_parent eq '--cc') {
6319 $formats_nav .= ' | ' .
6320 $cgi->a({-href
=> href
(action
=>"commitdiff",
6321 hash
=>$hash, hash_parent
=>'-c')},
6323 } else { # $hash_parent eq '-c'
6324 $formats_nav .= ' | ' .
6325 $cgi->a({-href
=> href
(action
=>"commitdiff",
6326 hash
=>$hash, hash_parent
=>'--cc')},
6332 $cgi->a({-href
=> href
(action
=>"commitdiff",
6334 esc_html
(substr($_, 0, 7)));
6335 } @
{$co{'parents'}} ) .
6340 my $hash_parent_param = $hash_parent;
6341 if (!defined $hash_parent_param) {
6342 # --cc for multiple parents, --root for parentless
6343 $hash_parent_param =
6344 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6350 if ($format eq 'html') {
6351 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6352 "--no-commit-id", "--patch-with-raw", "--full-index",
6353 $hash_parent_param, $hash, "--"
6354 or die_error
(500, "Open git-diff-tree failed");
6356 while (my $line = <$fd>) {
6358 # empty line ends raw part of diff-tree output
6360 push @difftree, scalar parse_difftree_raw_line
($line);
6363 } elsif ($format eq 'plain') {
6364 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6365 '-p', $hash_parent_param, $hash, "--"
6366 or die_error
(500, "Open git-diff-tree failed");
6367 } elsif ($format eq 'patch') {
6368 # For commit ranges, we limit the output to the number of
6369 # patches specified in the 'patches' feature.
6370 # For single commits, we limit the output to a single patch,
6371 # diverging from the git-format-patch default.
6372 my @commit_spec = ();
6374 if ($patch_max > 0) {
6375 push @commit_spec, "-$patch_max";
6377 push @commit_spec, '-n', "$hash_parent..$hash";
6379 if ($params{-single
}) {
6380 push @commit_spec, '-1';
6382 if ($patch_max > 0) {
6383 push @commit_spec, "-$patch_max";
6385 push @commit_spec, "-n";
6387 push @commit_spec, '--root', $hash;
6389 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6390 '--stdout', @commit_spec
6391 or die_error
(500, "Open git-format-patch failed");
6393 die_error
(400, "Unknown commitdiff format");
6396 # non-textual hash id's can be cached
6398 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6402 # write commit message
6403 if ($format eq 'html') {
6404 my $refs = git_get_references
();
6405 my $ref = format_ref_marker
($refs, $co{'id'});
6407 git_header_html
(undef, $expires);
6408 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6409 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6410 print "<div class=\"title_text\">\n" .
6411 "<table class=\"object_header\">\n";
6412 git_print_authorship_rows
(\
%co);
6415 print "<div class=\"page_body\">\n";
6416 if (@
{$co{'comment'}} > 1) {
6417 print "<div class=\"log\">\n";
6418 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6419 print "</div>\n"; # class="log"
6422 } elsif ($format eq 'plain') {
6423 my $refs = git_get_references
("tags");
6424 my $tagname = git_get_rev_name_tags
($hash);
6425 my $filename = basename
($project) . "-$hash.patch";
6428 -type
=> 'text/plain',
6429 -charset
=> 'utf-8',
6430 -expires
=> $expires,
6431 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6432 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6433 print "From: " . to_utf8
($co{'author'}) . "\n";
6434 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6435 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6437 print "X-Git-Tag: $tagname\n" if $tagname;
6438 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6440 foreach my $line (@
{$co{'comment'}}) {
6441 print to_utf8
($line) . "\n";
6444 } elsif ($format eq 'patch') {
6445 my $filename = basename
($project) . "-$hash.patch";
6448 -type
=> 'text/plain',
6449 -charset
=> 'utf-8',
6450 -expires
=> $expires,
6451 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6455 if ($format eq 'html') {
6456 my $use_parents = !defined $hash_parent ||
6457 $hash_parent eq '-c' || $hash_parent eq '--cc';
6458 git_difftree_body
(\
@difftree, $hash,
6459 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6462 git_patchset_body
($fd, \
@difftree, $hash,
6463 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6465 print "</div>\n"; # class="page_body"
6468 } elsif ($format eq 'plain') {
6472 or print "Reading git-diff-tree failed\n";
6473 } elsif ($format eq 'patch') {
6477 or print "Reading git-format-patch failed\n";
6481 sub git_commitdiff_plain
{
6482 git_commitdiff
(-format
=> 'plain');
6485 # format-patch-style patches
6487 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6491 git_commitdiff
(-format
=> 'patch');
6495 git_log_generic
('history', \
&git_history_body
,
6496 $hash_base, $hash_parent_base,
6501 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6502 if (!defined $searchtext) {
6503 die_error
(400, "Text field is empty");
6505 if (!defined $hash) {
6506 $hash = git_get_head_hash
($project);
6508 my %co = parse_commit
($hash);
6510 die_error
(404, "Unknown commit object");
6512 if (!defined $page) {
6516 $searchtype ||= 'commit';
6517 if ($searchtype eq 'pickaxe') {
6518 # pickaxe may take all resources of your box and run for several minutes
6519 # with every query - so decide by yourself how public you make this feature
6520 gitweb_check_feature
('pickaxe')
6521 or die_error
(403, "Pickaxe is disabled");
6523 if ($searchtype eq 'grep') {
6524 gitweb_check_feature
('grep')
6525 or die_error
(403, "Grep is disabled");
6530 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6532 if ($searchtype eq 'commit') {
6533 $greptype = "--grep=";
6534 } elsif ($searchtype eq 'author') {
6535 $greptype = "--author=";
6536 } elsif ($searchtype eq 'committer') {
6537 $greptype = "--committer=";
6539 $greptype .= $searchtext;
6540 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6541 $greptype, '--regexp-ignore-case',
6542 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6544 my $paging_nav = '';
6547 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6548 searchtext
=>$searchtext,
6549 searchtype
=>$searchtype)},
6551 $paging_nav .= " ⋅ " .
6552 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6553 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6555 $paging_nav .= "first";
6556 $paging_nav .= " ⋅ prev";
6559 if ($#commitlist >= 100) {
6561 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6562 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6563 $paging_nav .= " ⋅ $next_link";
6565 $paging_nav .= " ⋅ next";
6568 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6569 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6570 if ($page == 0 && !@commitlist) {
6571 print "<p>No match.</p>\n";
6573 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6577 if ($searchtype eq 'pickaxe') {
6578 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6579 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6581 print "<table class=\"pickaxe search\">\n";
6584 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6585 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6586 ($search_use_regexp ?
'--pickaxe-regex' : ());
6589 while (my $line = <$fd>) {
6593 my %set = parse_difftree_raw_line
($line);
6594 if (defined $set{'commit'}) {
6595 # finish previous commit
6598 "<td class=\"link\">" .
6599 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6601 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6607 print "<tr class=\"dark\">\n";
6609 print "<tr class=\"light\">\n";
6612 %co = parse_commit
($set{'commit'});
6613 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6614 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6615 "<td><i>$author</i></td>\n" .
6617 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6618 -class => "list subject"},
6619 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6620 } elsif (defined $set{'to_id'}) {
6621 next if ($set{'to_id'} =~ m/^0{40}$/);
6623 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6624 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6626 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6632 # finish last commit (warning: repetition!)
6635 "<td class=\"link\">" .
6636 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6638 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6646 if ($searchtype eq 'grep') {
6647 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6648 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6650 print "<table class=\"grep_search\">\n";
6654 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6655 $search_use_regexp ?
('-E', '-i') : '-F',
6656 $searchtext, $co{'tree'};
6658 while (my $line = <$fd>) {
6660 my ($file, $lno, $ltext, $binary);
6661 last if ($matches++ > 1000);
6662 if ($line =~ /^Binary file (.+) matches$/) {
6666 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6668 if ($file ne $lastfile) {
6669 $lastfile and print "</td></tr>\n";
6671 print "<tr class=\"dark\">\n";
6673 print "<tr class=\"light\">\n";
6675 print "<td class=\"list\">".
6676 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6677 file_name
=>"$file"),
6678 -class => "list"}, esc_path
($file));
6679 print "</td><td>\n";
6683 print "<div class=\"binary\">Binary file</div>\n";
6685 $ltext = untabify
($ltext);
6686 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6687 $ltext = esc_html
($1, -nbsp
=>1);
6688 $ltext .= '<span class="match">';
6689 $ltext .= esc_html
($2, -nbsp
=>1);
6690 $ltext .= '</span>';
6691 $ltext .= esc_html
($3, -nbsp
=>1);
6693 $ltext = esc_html
($ltext, -nbsp
=>1);
6695 print "<div class=\"pre\">" .
6696 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6697 file_name
=>"$file").'#l'.$lno,
6698 -class => "linenr"}, sprintf('%4i', $lno))
6699 . ' ' . $ltext . "</div>\n";
6703 print "</td></tr>\n";
6704 if ($matches > 1000) {
6705 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6708 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6717 sub git_search_help
{
6719 git_print_page_nav
('','', $hash,$hash,$hash);
6721 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6722 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6723 the pattern entered is recognized as the POSIX extended
6724 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6727 <dt><b>commit</b></dt>
6728 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6730 my $have_grep = gitweb_check_feature
('grep');
6733 <dt><b>grep</b></dt>
6734 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6735 a different one) are searched for the given pattern. On large trees, this search can take
6736 a while and put some strain on the server, so please use it with some consideration. Note that
6737 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6738 case-sensitive.</dd>
6742 <dt><b>author</b></dt>
6743 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6744 <dt><b>committer</b></dt>
6745 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6747 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6748 if ($have_pickaxe) {
6750 <dt><b>pickaxe</b></dt>
6751 <dd>All commits that caused the string to appear or disappear from any file (changes that
6752 added, removed or "modified" the string) will be listed. This search can take a while and
6753 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6754 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6762 git_log_generic
('shortlog', \
&git_shortlog_body
,
6763 $hash, $hash_parent);
6766 ## ......................................................................
6767 ## feeds (RSS, Atom; OPML)
6770 my $format = shift || 'atom';
6771 my $have_blame = gitweb_check_feature
('blame');
6773 # Atom: http://www.atomenabled.org/developers/syndication/
6774 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6775 if ($format ne 'rss' && $format ne 'atom') {
6776 die_error
(400, "Unknown web feed format");
6779 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6780 my $head = $hash || 'HEAD';
6781 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6785 my $content_type = "application/$format+xml";
6786 if (defined $cgi->http('HTTP_ACCEPT') &&
6787 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6788 # browser (feed reader) prefers text/xml
6789 $content_type = 'text/xml';
6791 if (defined($commitlist[0])) {
6792 %latest_commit = %{$commitlist[0]};
6793 my $latest_epoch = $latest_commit{'committer_epoch'};
6794 %latest_date = parse_date
($latest_epoch);
6795 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6796 if (defined $if_modified) {
6798 if (eval { require HTTP
::Date
; 1; }) {
6799 $since = HTTP
::Date
::str2time
($if_modified);
6800 } elsif (eval { require Time
::ParseDate
; 1; }) {
6801 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6803 if (defined $since && $latest_epoch <= $since) {
6805 -type
=> $content_type,
6806 -charset
=> 'utf-8',
6807 -last_modified
=> $latest_date{'rfc2822'},
6808 -status
=> '304 Not Modified');
6813 -type
=> $content_type,
6814 -charset
=> 'utf-8',
6815 -last_modified
=> $latest_date{'rfc2822'});
6818 -type
=> $content_type,
6819 -charset
=> 'utf-8');
6822 # Optimization: skip generating the body if client asks only
6823 # for Last-Modified date.
6824 return if ($cgi->request_method() eq 'HEAD');
6827 my $title = "$site_name - $project/$action";
6828 my $feed_type = 'log';
6829 if (defined $hash) {
6830 $title .= " - '$hash'";
6831 $feed_type = 'branch log';
6832 if (defined $file_name) {
6833 $title .= " :: $file_name";
6834 $feed_type = 'history';
6836 } elsif (defined $file_name) {
6837 $title .= " - $file_name";
6838 $feed_type = 'history';
6840 $title .= " $feed_type";
6841 my $descr = git_get_project_description
($project);
6842 if (defined $descr) {
6843 $descr = esc_html
($descr);
6845 $descr = "$project " .
6846 ($format eq 'rss' ?
'RSS' : 'Atom') .
6849 my $owner = git_get_project_owner
($project);
6850 $owner = esc_html
($owner);
6854 if (defined $file_name) {
6855 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6856 } elsif (defined $hash) {
6857 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6859 $alt_url = href
(-full
=>1, action
=>"summary");
6861 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6862 if ($format eq 'rss') {
6864 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6867 print "<title>$title</title>\n" .
6868 "<link>$alt_url</link>\n" .
6869 "<description>$descr</description>\n" .
6870 "<language>en</language>\n" .
6871 # project owner is responsible for 'editorial' content
6872 "<managingEditor>$owner</managingEditor>\n";
6873 if (defined $logo || defined $favicon) {
6874 # prefer the logo to the favicon, since RSS
6875 # doesn't allow both
6876 my $img = esc_url
($logo || $favicon);
6878 "<url>$img</url>\n" .
6879 "<title>$title</title>\n" .
6880 "<link>$alt_url</link>\n" .
6884 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6885 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6887 print "<generator>gitweb v.$version/$git_version</generator>\n";
6888 } elsif ($format eq 'atom') {
6890 <feed xmlns="http://www.w3.org/2005/Atom">
6892 print "<title>$title</title>\n" .
6893 "<subtitle>$descr</subtitle>\n" .
6894 '<link rel="alternate" type="text/html" href="' .
6895 $alt_url . '" />' . "\n" .
6896 '<link rel="self" type="' . $content_type . '" href="' .
6897 $cgi->self_url() . '" />' . "\n" .
6898 "<id>" . href
(-full
=>1) . "</id>\n" .
6899 # use project owner for feed author
6900 "<author><name>$owner</name></author>\n";
6901 if (defined $favicon) {
6902 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6904 if (defined $logo) {
6905 # not twice as wide as tall: 72 x 27 pixels
6906 print "<logo>" . esc_url
($logo) . "</logo>\n";
6908 if (! %latest_date) {
6909 # dummy date to keep the feed valid until commits trickle in:
6910 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6912 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6914 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6918 for (my $i = 0; $i <= $#commitlist; $i++) {
6919 my %co = %{$commitlist[$i]};
6920 my $commit = $co{'id'};
6921 # we read 150, we always show 30 and the ones more recent than 48 hours
6922 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6925 my %cd = parse_date
($co{'author_epoch'});
6927 # get list of changed files
6928 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6929 $co{'parent'} || "--root",
6930 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6932 my @difftree = map { chomp; $_ } <$fd>;
6936 # print element (entry, item)
6937 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6938 if ($format eq 'rss') {
6940 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6941 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6942 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6943 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6944 "<link>$co_url</link>\n" .
6945 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6946 "<content:encoded>" .
6948 } elsif ($format eq 'atom') {
6950 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6951 "<updated>$cd{'iso-8601'}</updated>\n" .
6953 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6954 if ($co{'author_email'}) {
6955 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6957 print "</author>\n" .
6958 # use committer for contributor
6960 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6961 if ($co{'committer_email'}) {
6962 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6964 print "</contributor>\n" .
6965 "<published>$cd{'iso-8601'}</published>\n" .
6966 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6967 "<id>$co_url</id>\n" .
6968 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6969 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6971 my $comment = $co{'comment'};
6973 foreach my $line (@
$comment) {
6974 $line = esc_html
($line);
6977 print "</pre><ul>\n";
6978 foreach my $difftree_line (@difftree) {
6979 my %difftree = parse_difftree_raw_line
($difftree_line);
6980 next if !$difftree{'from_id'};
6982 my $file = $difftree{'file'} || $difftree{'to_file'};
6986 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6987 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6988 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6989 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6990 -title
=> "diff"}, 'D');
6992 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6993 file_name
=>$file, hash_base
=>$commit),
6994 -title
=> "blame"}, 'B');
6996 # if this is not a feed of a file history
6997 if (!defined $file_name || $file_name ne $file) {
6998 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6999 file_name
=>$file, hash
=>$commit),
7000 -title
=> "history"}, 'H');
7002 $file = esc_path
($file);
7006 if ($format eq 'rss') {
7007 print "</ul>]]>\n" .
7008 "</content:encoded>\n" .
7010 } elsif ($format eq 'atom') {
7011 print "</ul>\n</div>\n" .
7018 if ($format eq 'rss') {
7019 print "</channel>\n</rss>\n";
7020 } elsif ($format eq 'atom') {
7034 my @list = git_get_projects_list
();
7037 -type
=> 'text/xml',
7038 -charset
=> 'utf-8',
7039 -content_disposition
=> 'inline; filename="opml.xml"');
7042 <?xml version="1.0" encoding="utf-8"?>
7043 <opml version="1.0">
7045 <title>$site_name OPML Export</title>
7048 <outline text="git RSS feeds">
7051 foreach my $pr (@list) {
7053 my $head = git_get_head_hash
($proj{'path'});
7054 if (!defined $head) {
7057 $git_dir = "$projectroot/$proj{'path'}";
7058 my %co = parse_commit
($head);
7063 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7064 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7065 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7066 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";