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);
20 binmode STDOUT
, ':utf8';
23 if (eval { require Time
::HiRes
; 1; }) {
24 $t0 = [Time
::HiRes
::gettimeofday
()];
26 our $number_of_git_cmds = 0;
29 CGI
->compile() if $ENV{'MOD_PERL'};
32 our $version = "1.7.2.5";
34 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
38 our $my_url = $cgi->url();
39 our $my_uri = $cgi->url(-absolute
=> 1);
41 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
42 # needed and used only for URLs with nonempty PATH_INFO
43 our $base_url = $my_url;
45 # When the script is used as DirectoryIndex, the URL does not contain the name
46 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
47 # have to do it ourselves. We make $path_info global because it's also used
50 # Another issue with the script being the DirectoryIndex is that the resulting
51 # $my_url data is not the full script URL: this is good, because we want
52 # generated links to keep implying the script name if it wasn't explicitly
53 # indicated in the URL we're handling, but it means that $my_url cannot be used
55 # Therefore, if we needed to strip PATH_INFO, then we know that we have
56 # to build the base URL ourselves:
57 our $path_info = $ENV{"PATH_INFO"};
59 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
60 $my_uri =~ s
,\Q
$path_info\E
$,, &&
61 defined $ENV{'SCRIPT_NAME'}) {
62 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
66 # target of the home link on top of all pages
67 our $home_link = $my_uri || "/";
70 # core git executable to use
71 # this can just be "git" if your webserver has a sensible PATH
72 our $GIT = "/usr/bin/git";
74 # absolute fs-path which will be prepended to the project path
75 #our $projectroot = "/pub/scm";
76 our $projectroot = "/pub/git";
78 # fs traversing limit for getting project list
79 # the number is relative to the projectroot
80 our $project_maxdepth = 2007;
82 # string of the home link on top of all pages
83 our $home_link_str = "projects";
85 # name of your site or organization to appear in page titles
86 # replace this with something more descriptive for clearer bookmarks
88 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
90 # filename of html text to include at top of each page
91 our $site_header = "";
92 # html text to include at home page
93 our $home_text = "indextext.html";
94 # filename of html text to include at bottom of each page
95 our $site_footer = "";
98 our @stylesheets = ("gitweb.css");
99 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
100 our $stylesheet = undef;
101 # URI of GIT logo (72x27 size)
102 our $logo = "git-logo.png";
103 # URI of GIT favicon, assumed to be image/png type
104 our $favicon = "git-favicon.png";
105 # URI of gitweb.js (JavaScript code for gitweb)
106 our $javascript = "gitweb.js";
108 # URI and label (title) of GIT logo link
109 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
110 #our $logo_label = "git documentation";
111 our $logo_url = "http://git-scm.com/";
112 our $logo_label = "git homepage";
114 # source of projects list
115 our $projects_list = "";
117 # the width (in characters) of the projects list "Description" column
118 our $projects_list_description_width = 25;
120 # default order of projects list
121 # valid values are none, project, descr, owner, and age
122 our $default_projects_order = "project";
124 # show repository only if this file exists
125 # (only effective if this variable evaluates to true)
128 # show repository only if this subroutine returns true
129 # when given the path to the project, for example:
130 # sub { return -e "$_[0]/git-daemon-export-ok"; }
131 our $export_auth_hook = undef;
133 # only allow viewing of repositories also shown on the overview page
134 our $strict_export = "";
136 # list of git base URLs used for URL to where fetch project from,
137 # i.e. full URL is "$git_base_url/$project"
138 our @git_base_url_list = grep { $_ ne '' } ("");
140 # default blob_plain mimetype and default charset for text/plain blob
141 our $default_blob_plain_mimetype = 'text/plain';
142 our $default_text_plain_charset = undef;
144 # file to use for guessing MIME types before trying /etc/mime.types
145 # (relative to the current git repository)
146 our $mimetypes_file = undef;
148 # assume this charset if line contains non-UTF-8 characters;
149 # it should be valid encoding (see Encoding::Supported(3pm) for list),
150 # for which encoding all byte sequences are valid, for example
151 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
152 # could be even 'utf-8' for the old behavior)
153 our $fallback_encoding = 'latin1';
155 # rename detection options for git-diff and git-diff-tree
156 # - default is '-M', with the cost proportional to
157 # (number of removed files) * (number of new files).
158 # - more costly is '-C' (which implies '-M'), with the cost proportional to
159 # (number of changed files + number of removed files) * (number of new files)
160 # - even more costly is '-C', '--find-copies-harder' with cost
161 # (number of files in the original tree) * (number of new files)
162 # - one might want to include '-B' option, e.g. '-B', '-M'
163 our @diff_opts = ('-M'); # taken from git_commit
165 # Disables features that would allow repository owners to inject script into
167 our $prevent_xss = 0;
169 # information about snapshot formats that gitweb is capable of serving
170 our %known_snapshot_formats = (
172 # 'display' => display name,
173 # 'type' => mime type,
174 # 'suffix' => filename suffix,
175 # 'format' => --format for git-archive,
176 # 'compressor' => [compressor command and arguments]
177 # (array reference, optional)
178 # 'disabled' => boolean (optional)}
181 'display' => 'tar.gz',
182 'type' => 'application/x-gzip',
183 'suffix' => '.tar.gz',
185 'compressor' => ['gzip']},
188 'display' => 'tar.bz2',
189 'type' => 'application/x-bzip2',
190 'suffix' => '.tar.bz2',
192 'compressor' => ['bzip2']},
195 'display' => 'tar.xz',
196 'type' => 'application/x-xz',
197 'suffix' => '.tar.xz',
199 'compressor' => ['xz'],
204 'type' => 'application/x-zip',
209 # Aliases so we understand old gitweb.snapshot values in repository
211 our %known_snapshot_format_aliases = (
216 # backward compatibility: legacy gitweb config support
217 'x-gzip' => undef, 'gz' => undef,
218 'x-bzip2' => undef, 'bz2' => undef,
219 'x-zip' => undef, '' => undef,
222 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
223 # are changed, it may be appropriate to change these values too via
230 # Used to set the maximum load that we will still respond to gitweb queries.
231 # If server load exceed this value then return "503 server busy" error.
232 # If gitweb cannot determined server load, it is taken to be 0.
233 # Leave it undefined (or set to 'undef') to turn off load checking.
236 # You define site-wide feature defaults here; override them with
237 # $GITWEB_CONFIG as necessary.
240 # 'sub' => feature-sub (subroutine),
241 # 'override' => allow-override (boolean),
242 # 'default' => [ default options...] (array reference)}
244 # if feature is overridable (it means that allow-override has true value),
245 # then feature-sub will be called with default options as parameters;
246 # return value of feature-sub indicates if to enable specified feature
248 # if there is no 'sub' key (no feature-sub), then feature cannot be
251 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
252 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
255 # Enable the 'blame' blob view, showing the last commit that modified
256 # each line in the file. This can be very CPU-intensive.
258 # To enable system wide have in $GITWEB_CONFIG
259 # $feature{'blame'}{'default'} = [1];
260 # To have project specific config enable override in $GITWEB_CONFIG
261 # $feature{'blame'}{'override'} = 1;
262 # and in project config gitweb.blame = 0|1;
264 'sub' => sub { feature_bool
('blame', @_) },
268 # Enable the 'snapshot' link, providing a compressed archive of any
269 # tree. This can potentially generate high traffic if you have large
272 # Value is a list of formats defined in %known_snapshot_formats that
274 # To disable system wide have in $GITWEB_CONFIG
275 # $feature{'snapshot'}{'default'} = [];
276 # To have project specific config enable override in $GITWEB_CONFIG
277 # $feature{'snapshot'}{'override'} = 1;
278 # and in project config, a comma-separated list of formats or "none"
279 # to disable. Example: gitweb.snapshot = tbz2,zip;
281 'sub' => \
&feature_snapshot
,
283 'default' => ['tgz']},
285 # Enable text search, which will list the commits which match author,
286 # committer or commit text to a given string. Enabled by default.
287 # Project specific override is not supported.
292 # Enable grep search, which will list the files in currently selected
293 # tree containing the given string. Enabled by default. This can be
294 # potentially CPU-intensive, of course.
296 # To enable system wide have in $GITWEB_CONFIG
297 # $feature{'grep'}{'default'} = [1];
298 # To have project specific config enable override in $GITWEB_CONFIG
299 # $feature{'grep'}{'override'} = 1;
300 # and in project config gitweb.grep = 0|1;
302 'sub' => sub { feature_bool
('grep', @_) },
306 # Enable the pickaxe search, which will list the commits that modified
307 # a given string in a file. This can be practical and quite faster
308 # alternative to 'blame', but still potentially CPU-intensive.
310 # To enable system wide have in $GITWEB_CONFIG
311 # $feature{'pickaxe'}{'default'} = [1];
312 # To have project specific config enable override in $GITWEB_CONFIG
313 # $feature{'pickaxe'}{'override'} = 1;
314 # and in project config gitweb.pickaxe = 0|1;
316 'sub' => sub { feature_bool
('pickaxe', @_) },
320 # Enable showing size of blobs in a 'tree' view, in a separate
321 # column, similar to what 'ls -l' does. This cost a bit of IO.
323 # To disable system wide have in $GITWEB_CONFIG
324 # $feature{'show-sizes'}{'default'} = [0];
325 # To have project specific config enable override in $GITWEB_CONFIG
326 # $feature{'show-sizes'}{'override'} = 1;
327 # and in project config gitweb.showsizes = 0|1;
329 'sub' => sub { feature_bool
('showsizes', @_) },
333 # Make gitweb use an alternative format of the URLs which can be
334 # more readable and natural-looking: project name is embedded
335 # directly in the path and the query string contains other
336 # auxiliary information. All gitweb installations recognize
337 # URL in either format; this configures in which formats gitweb
340 # To enable system wide have in $GITWEB_CONFIG
341 # $feature{'pathinfo'}{'default'} = [1];
342 # Project specific override is not supported.
344 # Note that you will need to change the default location of CSS,
345 # favicon, logo and possibly other files to an absolute URL. Also,
346 # if gitweb.cgi serves as your indexfile, you will need to force
347 # $my_uri to contain the script name in your $GITWEB_CONFIG.
352 # Make gitweb consider projects in project root subdirectories
353 # to be forks of existing projects. Given project $projname.git,
354 # projects matching $projname/*.git will not be shown in the main
355 # projects list, instead a '+' mark will be added to $projname
356 # there and a 'forks' view will be enabled for the project, listing
357 # all the forks. If project list is taken from a file, forks have
358 # to be listed after the main project.
360 # To enable system wide have in $GITWEB_CONFIG
361 # $feature{'forks'}{'default'} = [1];
362 # Project specific override is not supported.
367 # Insert custom links to the action bar of all project pages.
368 # This enables you mainly to link to third-party scripts integrating
369 # into gitweb; e.g. git-browser for graphical history representation
370 # or custom web-based repository administration interface.
372 # The 'default' value consists of a list of triplets in the form
373 # (label, link, position) where position is the label after which
374 # to insert the link and link is a format string where %n expands
375 # to the project name, %f to the project path within the filesystem,
376 # %h to the current hash (h gitweb parameter) and %b to the current
377 # hash base (hb gitweb parameter); %% expands to %.
379 # To enable system wide have in $GITWEB_CONFIG e.g.
380 # $feature{'actions'}{'default'} = [('graphiclog',
381 # '/git-browser/by-commit.html?r=%n', 'summary')];
382 # Project specific override is not supported.
387 # Allow gitweb scan project content tags described in ctags/
388 # of project repository, and display the popular Web 2.0-ish
389 # "tag cloud" near the project list. Note that this is something
390 # COMPLETELY different from the normal Git tags.
392 # gitweb by itself can show existing tags, but it does not handle
393 # tagging itself; you need an external application for that.
394 # For an example script, check Girocco's cgi/tagproj.cgi.
395 # You may want to install the HTML::TagCloud Perl module to get
396 # a pretty tag cloud instead of just a list of tags.
398 # To enable system wide have in $GITWEB_CONFIG
399 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
400 # Project specific override is not supported.
405 # The maximum number of patches in a patchset generated in patch
406 # view. Set this to 0 or undef to disable patch view, or to a
407 # negative number to remove any limit.
409 # To disable system wide have in $GITWEB_CONFIG
410 # $feature{'patches'}{'default'} = [0];
411 # To have project specific config enable override in $GITWEB_CONFIG
412 # $feature{'patches'}{'override'} = 1;
413 # and in project config gitweb.patches = 0|n;
414 # where n is the maximum number of patches allowed in a patchset.
416 'sub' => \
&feature_patches
,
420 # Avatar support. When this feature is enabled, views such as
421 # shortlog or commit will display an avatar associated with
422 # the email of the committer(s) and/or author(s).
424 # Currently available providers are gravatar and picon.
425 # If an unknown provider is specified, the feature is disabled.
427 # Gravatar depends on Digest::MD5.
428 # Picon currently relies on the indiana.edu database.
430 # To enable system wide have in $GITWEB_CONFIG
431 # $feature{'avatar'}{'default'} = ['<provider>'];
432 # where <provider> is either gravatar or picon.
433 # To have project specific config enable override in $GITWEB_CONFIG
434 # $feature{'avatar'}{'override'} = 1;
435 # and in project config gitweb.avatar = <provider>;
437 'sub' => \
&feature_avatar
,
441 # Enable displaying how much time and how many git commands
442 # it took to generate and display page. Disabled by default.
443 # Project specific override is not supported.
448 # Enable turning some links into links to actions which require
449 # JavaScript to run (like 'blame_incremental'). Not enabled by
450 # default. Project specific override is currently not supported.
451 'javascript-actions' => {
455 # Syntax highlighting support. This is based on Daniel Svensson's
456 # and Sham Chukoury's work in gitweb-xmms2.git.
457 # It requires the 'highlight' program present in $PATH,
458 # and therefore is disabled by default.
460 # To enable system wide have in $GITWEB_CONFIG
461 # $feature{'highlight'}{'default'} = [1];
464 'sub' => sub { feature_bool
('highlight', @_) },
469 sub gitweb_get_feature
{
471 return unless exists $feature{$name};
472 my ($sub, $override, @defaults) = (
473 $feature{$name}{'sub'},
474 $feature{$name}{'override'},
475 @
{$feature{$name}{'default'}});
476 # project specific override is possible only if we have project
477 our $git_dir; # global variable, declared later
478 if (!$override || !defined $git_dir) {
482 warn "feature $name is not overridable";
485 return $sub->(@defaults);
488 # A wrapper to check if a given feature is enabled.
489 # With this, you can say
491 # my $bool_feat = gitweb_check_feature('bool_feat');
492 # gitweb_check_feature('bool_feat') or somecode;
496 # my ($bool_feat) = gitweb_get_feature('bool_feat');
497 # (gitweb_get_feature('bool_feat'))[0] or somecode;
499 sub gitweb_check_feature
{
500 return (gitweb_get_feature
(@_))[0];
506 my ($val) = git_get_project_config
($key, '--bool');
510 } elsif ($val eq 'true') {
512 } elsif ($val eq 'false') {
517 sub feature_snapshot
{
520 my ($val) = git_get_project_config
('snapshot');
523 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
529 sub feature_patches
{
530 my @val = (git_get_project_config
('patches', '--int'));
540 my @val = (git_get_project_config
('avatar'));
542 return @val ?
@val : @_;
545 # checking HEAD file with -e is fragile if the repository was
546 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
548 sub check_head_link
{
550 my $headfile = "$dir/HEAD";
551 return ((-e
$headfile) ||
552 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
555 sub check_export_ok
{
557 return (check_head_link
($dir) &&
558 (!$export_ok || -e
"$dir/$export_ok") &&
559 (!$export_auth_hook || $export_auth_hook->($dir)));
562 # process alternate names for backward compatibility
563 # filter out unsupported (unknown) snapshot formats
564 sub filter_snapshot_fmts
{
568 exists $known_snapshot_format_aliases{$_} ?
569 $known_snapshot_format_aliases{$_} : $_} @fmts;
571 exists $known_snapshot_formats{$_} &&
572 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
575 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
576 sub evaluate_gitweb_config
{
577 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
578 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
579 # die if there are errors parsing config file
580 if (-e
$GITWEB_CONFIG) {
583 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
584 do $GITWEB_CONFIG_SYSTEM;
589 # Get loadavg of system, to compare against $maxload.
590 # Currently it requires '/proc/loadavg' present to get loadavg;
591 # if it is not present it returns 0, which means no load checking.
593 if( -e
'/proc/loadavg' ){
594 open my $fd, '<', '/proc/loadavg'
596 my @load = split(/\s+/, scalar <$fd>);
599 # The first three columns measure CPU and IO utilization of the last one,
600 # five, and 10 minute periods. The fourth column shows the number of
601 # currently running processes and the total number of processes in the m/n
602 # format. The last column displays the last process ID used.
603 return $load[0] || 0;
605 # additional checks for load average should go here for things that don't export
611 # version of the core git binary
613 sub evaluate_git_version
{
614 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
615 $number_of_git_cmds++;
619 if (defined $maxload && get_loadavg
() > $maxload) {
620 die_error
(503, "The load average on the server is too high");
624 # ======================================================================
625 # input validation and dispatch
627 # input parameters can be collected from a variety of sources (presently, CGI
628 # and PATH_INFO), so we define an %input_params hash that collects them all
629 # together during validation: this allows subsequent uses (e.g. href()) to be
630 # agnostic of the parameter origin
632 our %input_params = ();
634 # input parameters are stored with the long parameter name as key. This will
635 # also be used in the href subroutine to convert parameters to their CGI
636 # equivalent, and since the href() usage is the most frequent one, we store
637 # the name -> CGI key mapping here, instead of the reverse.
639 # XXX: Warning: If you touch this, check the search form for updating,
642 our @cgi_param_mapping = (
650 hash_parent_base
=> "hpb",
655 snapshot_format
=> "sf",
656 extra_options
=> "opt",
657 search_use_regexp
=> "sr",
658 # this must be last entry (for manipulation from JavaScript)
661 our %cgi_param_mapping = @cgi_param_mapping;
663 # we will also need to know the possible actions, for validation
665 "blame" => \
&git_blame
,
666 "blame_incremental" => \
&git_blame_incremental
,
667 "blame_data" => \
&git_blame_data
,
668 "blobdiff" => \
&git_blobdiff
,
669 "blobdiff_plain" => \
&git_blobdiff_plain
,
670 "blob" => \
&git_blob
,
671 "blob_plain" => \
&git_blob_plain
,
672 "commitdiff" => \
&git_commitdiff
,
673 "commitdiff_plain" => \
&git_commitdiff_plain
,
674 "commit" => \
&git_commit
,
675 "forks" => \
&git_forks
,
676 "heads" => \
&git_heads
,
677 "history" => \
&git_history
,
679 "patch" => \
&git_patch
,
680 "patches" => \
&git_patches
,
682 "atom" => \
&git_atom
,
683 "search" => \
&git_search
,
684 "search_help" => \
&git_search_help
,
685 "shortlog" => \
&git_shortlog
,
686 "summary" => \
&git_summary
,
688 "tags" => \
&git_tags
,
689 "tree" => \
&git_tree
,
690 "snapshot" => \
&git_snapshot
,
691 "object" => \
&git_object
,
692 # those below don't need $project
693 "opml" => \
&git_opml
,
694 "project_list" => \
&git_project_list
,
695 "project_index" => \
&git_project_index
,
696 "project_index2" => \
&git_project_index2
,
697 "download" => \
&git_download
,
698 "bugtracker" => \
&git_project_bugtracker
,
701 # finally, we have the hash of allowed extra_options for the commands that
703 our %allowed_options = (
704 "--no-merges" => [ qw(rss atom log shortlog history) ],
707 # fill %input_params with the CGI parameters. All values except for 'opt'
708 # should be single values, but opt can be an array. We should probably
709 # build an array of parameters that can be multi-valued, but since for the time
710 # being it's only this one, we just single it out
711 sub evaluate_query_params
{
714 while (my ($name, $symbol) = each %cgi_param_mapping) {
715 if ($symbol eq 'opt') {
716 $input_params{$name} = [ $cgi->param($symbol) ];
718 $input_params{$name} = $cgi->param($symbol);
723 # now read PATH_INFO and update the parameter list for missing parameters
724 sub evaluate_path_info
{
725 return if defined $input_params{'project'};
726 return if !$path_info;
727 $path_info =~ s
,^/+,,;
728 return if !$path_info;
730 # find which part of PATH_INFO is project
731 my $project = $path_info;
733 while ($project && !check_head_link
("$projectroot/$project")) {
734 $project =~ s
,/*[^/]*$,,;
736 return unless $project;
737 $input_params{'project'} = $project;
739 # do not change any parameters if an action is given using the query string
740 return if $input_params{'action'};
741 $path_info =~ s
,^\Q
$project\E
/*,,;
743 # next, check if we have an action
744 my $action = $path_info;
746 if (exists $actions{$action}) {
747 $path_info =~ s
,^$action/*,,;
748 $input_params{'action'} = $action;
751 # list of actions that want hash_base instead of hash, but can have no
752 # pathname (f) parameter
759 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
760 my ($parentrefname, $parentpathname, $refname, $pathname) =
761 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
763 # first, analyze the 'current' part
764 if (defined $pathname) {
765 # we got "branch:filename" or "branch:dir/"
766 # we could use git_get_type(branch:pathname), but:
767 # - it needs $git_dir
768 # - it does a git() call
769 # - the convention of terminating directories with a slash
770 # makes it superfluous
771 # - embedding the action in the PATH_INFO would make it even
773 $pathname =~ s
,^/+,,;
774 if (!$pathname || substr($pathname, -1) eq "/") {
775 $input_params{'action'} ||= "tree";
778 # the default action depends on whether we had parent info
780 if ($parentrefname) {
781 $input_params{'action'} ||= "blobdiff_plain";
783 $input_params{'action'} ||= "blob_plain";
786 $input_params{'hash_base'} ||= $refname;
787 $input_params{'file_name'} ||= $pathname;
788 } elsif (defined $refname) {
789 # we got "branch". In this case we have to choose if we have to
790 # set hash or hash_base.
792 # Most of the actions without a pathname only want hash to be
793 # set, except for the ones specified in @wants_base that want
794 # hash_base instead. It should also be noted that hand-crafted
795 # links having 'history' as an action and no pathname or hash
796 # set will fail, but that happens regardless of PATH_INFO.
797 $input_params{'action'} ||= "shortlog";
798 if (grep { $_ eq $input_params{'action'} } @wants_base) {
799 $input_params{'hash_base'} ||= $refname;
801 $input_params{'hash'} ||= $refname;
805 # next, handle the 'parent' part, if present
806 if (defined $parentrefname) {
807 # a missing pathspec defaults to the 'current' filename, allowing e.g.
808 # someproject/blobdiff/oldrev..newrev:/filename
809 if ($parentpathname) {
810 $parentpathname =~ s
,^/+,,;
811 $parentpathname =~ s
,/$,,;
812 $input_params{'file_parent'} ||= $parentpathname;
814 $input_params{'file_parent'} ||= $input_params{'file_name'};
816 # we assume that hash_parent_base is wanted if a path was specified,
817 # or if the action wants hash_base instead of hash
818 if (defined $input_params{'file_parent'} ||
819 grep { $_ eq $input_params{'action'} } @wants_base) {
820 $input_params{'hash_parent_base'} ||= $parentrefname;
822 $input_params{'hash_parent'} ||= $parentrefname;
826 # for the snapshot action, we allow URLs in the form
827 # $project/snapshot/$hash.ext
828 # where .ext determines the snapshot and gets removed from the
829 # passed $refname to provide the $hash.
831 # To be able to tell that $refname includes the format extension, we
832 # require the following two conditions to be satisfied:
833 # - the hash input parameter MUST have been set from the $refname part
834 # of the URL (i.e. they must be equal)
835 # - the snapshot format MUST NOT have been defined already (e.g. from
837 # It's also useless to try any matching unless $refname has a dot,
838 # so we check for that too
839 if (defined $input_params{'action'} &&
840 $input_params{'action'} eq 'snapshot' &&
841 defined $refname && index($refname, '.') != -1 &&
842 $refname eq $input_params{'hash'} &&
843 !defined $input_params{'snapshot_format'}) {
844 # We loop over the known snapshot formats, checking for
845 # extensions. Allowed extensions are both the defined suffix
846 # (which includes the initial dot already) and the snapshot
847 # format key itself, with a prepended dot
848 while (my ($fmt, $opt) = each %known_snapshot_formats) {
850 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
854 # a valid suffix was found, so set the snapshot format
855 # and reset the hash parameter
856 $input_params{'snapshot_format'} = $fmt;
857 $input_params{'hash'} = $hash;
858 # we also set the format suffix to the one requested
859 # in the URL: this way a request for e.g. .tgz returns
860 # a .tgz instead of a .tar.gz
861 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
867 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
868 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
869 $searchtext, $search_regexp);
870 sub evaluate_and_validate_params
{
871 our $action = $input_params{'action'};
872 if (defined $action) {
873 if (!validate_action
($action)) {
874 die_error
(400, "Invalid action parameter");
878 # parameters which are pathnames
879 our $project = $input_params{'project'};
880 if (defined $project) {
881 if (!validate_project
($project)) {
883 die_error
(404, "No such project");
887 our $file_name = $input_params{'file_name'};
888 if (defined $file_name) {
889 if (!validate_pathname
($file_name)) {
890 die_error
(400, "Invalid file parameter");
894 our $file_parent = $input_params{'file_parent'};
895 if (defined $file_parent) {
896 if (!validate_pathname
($file_parent)) {
897 die_error
(400, "Invalid file parent parameter");
901 # parameters which are refnames
902 our $hash = $input_params{'hash'};
904 if (!validate_refname
($hash)) {
905 die_error
(400, "Invalid hash parameter");
909 our $hash_parent = $input_params{'hash_parent'};
910 if (defined $hash_parent) {
911 if (!validate_refname
($hash_parent)) {
912 die_error
(400, "Invalid hash parent parameter");
916 our $hash_base = $input_params{'hash_base'};
917 if (defined $hash_base) {
918 if (!validate_refname
($hash_base)) {
919 die_error
(400, "Invalid hash base parameter");
923 our @extra_options = @
{$input_params{'extra_options'}};
924 # @extra_options is always defined, since it can only be (currently) set from
925 # CGI, and $cgi->param() returns the empty array in array context if the param
927 foreach my $opt (@extra_options) {
928 if (not exists $allowed_options{$opt}) {
929 die_error
(400, "Invalid option parameter");
931 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
932 die_error
(400, "Invalid option parameter for this action");
936 our $hash_parent_base = $input_params{'hash_parent_base'};
937 if (defined $hash_parent_base) {
938 if (!validate_refname
($hash_parent_base)) {
939 die_error
(400, "Invalid hash parent base parameter");
944 our $page = $input_params{'page'};
946 if ($page =~ m/[^0-9]/) {
947 die_error
(400, "Invalid page parameter");
951 our $searchtype = $input_params{'searchtype'};
952 if (defined $searchtype) {
953 if ($searchtype =~ m/[^a-z]/) {
954 die_error
(400, "Invalid searchtype parameter");
958 our $search_use_regexp = $input_params{'search_use_regexp'};
960 our $searchtext = $input_params{'searchtext'};
962 if (defined $searchtext) {
963 if (length($searchtext) < 2) {
964 die_error
(403, "At least two characters are required for search parameter");
966 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
970 # path to the current git repository
972 sub evaluate_git_dir
{
973 our $git_dir = "$projectroot/$project" if $project;
976 our (@snapshot_fmts, $git_avatar);
977 sub configure_gitweb_features
{
978 # list of supported snapshot formats
979 our @snapshot_fmts = gitweb_get_feature
('snapshot');
980 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
982 # check that the avatar feature is set to a known provider name,
983 # and for each provider check if the dependencies are satisfied.
984 # if the provider name is invalid or the dependencies are not met,
985 # reset $git_avatar to the empty string.
986 our ($git_avatar) = gitweb_get_feature
('avatar');
987 if ($git_avatar eq 'gravatar') {
988 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
989 } elsif ($git_avatar eq 'picon') {
996 # custom error handler: 'die <message>' is Internal Server Error
997 sub handle_errors_html
{
998 my $msg = shift; # it is already HTML escaped
1000 # to avoid infinite loop where error occurs in die_error,
1001 # change handler to default handler, disabling handle_errors_html
1002 set_message
("Error occured when inside die_error:\n$msg");
1004 # you cannot jump out of die_error when called as error handler;
1005 # the subroutine set via CGI::Carp::set_message is called _after_
1006 # HTTP headers are already written, so it cannot write them itself
1007 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1009 set_message
(\
&handle_errors_html
);
1013 if (!defined $action) {
1014 if (defined $hash) {
1015 $action = git_get_type
($hash);
1016 } elsif (defined $hash_base && defined $file_name) {
1017 $action = git_get_type
("$hash_base:$file_name");
1018 } elsif (defined $project) {
1019 $action = 'summary';
1021 $action = 'project_list';
1024 if (!defined($actions{$action})) {
1025 die_error
(400, "Unknown action");
1027 if ($action !~ m/^(?:opml|project_list|project_index2|project_index|download)$/ &&
1029 die_error
(400, "Project needed");
1031 $actions{$action}->();
1035 our $t0 = [Time
::HiRes
::gettimeofday
()]
1037 our $number_of_git_cmds = 0;
1044 evaluate_gitweb_config
();
1047 # $projectroot and $projects_list might be set in gitweb config file
1048 $projects_list ||= $projectroot;
1050 evaluate_query_params
();
1051 evaluate_path_info
();
1052 evaluate_and_validate_params
();
1055 configure_gitweb_features
();
1060 our $is_last_request = sub { 1 };
1061 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1064 sub configure_as_fcgi
{
1066 our $CGI = 'CGI::Fast';
1068 my $request_number = 0;
1069 # let each child service 100 requests
1070 our $is_last_request = sub { ++$request_number > 100 };
1073 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1075 if $script_name =~ /\.fcgi$/;
1077 return unless (@ARGV);
1079 require Getopt
::Long
;
1080 Getopt
::Long
::GetOptions
(
1081 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1082 'nproc|n=i' => sub {
1083 my ($arg, $val) = @_;
1084 return unless eval { require FCGI
::ProcManager
; 1; };
1085 my $proc_manager = FCGI
::ProcManager
->new({
1086 n_processes
=> $val,
1088 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1089 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1090 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1097 evaluate_git_version
();
1099 $pre_listen_hook->()
1100 if $pre_listen_hook;
1103 while ($cgi = $CGI->new()) {
1104 $pre_dispatch_hook->()
1105 if $pre_dispatch_hook;
1109 $pre_dispatch_hook->()
1110 if $post_dispatch_hook;
1112 last REQUEST
if ($is_last_request->());
1121 if (defined caller) {
1122 # wrapped in a subroutine processing requests,
1123 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1126 # pure CGI script, serving single request
1130 ## ======================================================================
1133 # possible values of extra options
1134 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1135 # -replay => 1 - start from a current view (replay with modifications)
1136 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1139 # default is to use -absolute url() i.e. $my_uri
1140 my $href = $params{-full
} ?
$my_url : $my_uri;
1142 $params{'project'} = $project unless exists $params{'project'};
1144 if ($params{-replay
}) {
1145 while (my ($name, $symbol) = each %cgi_param_mapping) {
1146 if (!exists $params{$name}) {
1147 $params{$name} = $input_params{$name};
1152 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1153 if (defined $params{'project'} &&
1154 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1155 # try to put as many parameters as possible in PATH_INFO:
1158 # - hash_parent or hash_parent_base:/file_parent
1159 # - hash or hash_base:/filename
1160 # - the snapshot_format as an appropriate suffix
1162 # When the script is the root DirectoryIndex for the domain,
1163 # $href here would be something like http://gitweb.example.com/
1164 # Thus, we strip any trailing / from $href, to spare us double
1165 # slashes in the final URL
1168 # Then add the project name, if present
1169 $href .= "/".esc_url
($params{'project'});
1170 delete $params{'project'};
1172 # since we destructively absorb parameters, we keep this
1173 # boolean that remembers if we're handling a snapshot
1174 my $is_snapshot = $params{'action'} eq 'snapshot';
1176 # Summary just uses the project path URL, any other action is
1178 if (defined $params{'action'}) {
1179 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1180 delete $params{'action'};
1183 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1184 # stripping nonexistent or useless pieces
1185 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1186 || $params{'hash_parent'} || $params{'hash'});
1187 if (defined $params{'hash_base'}) {
1188 if (defined $params{'hash_parent_base'}) {
1189 $href .= esc_url
($params{'hash_parent_base'});
1190 # skip the file_parent if it's the same as the file_name
1191 if (defined $params{'file_parent'}) {
1192 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1193 delete $params{'file_parent'};
1194 } elsif ($params{'file_parent'} !~ /\.\./) {
1195 $href .= ":/".esc_url
($params{'file_parent'});
1196 delete $params{'file_parent'};
1200 delete $params{'hash_parent'};
1201 delete $params{'hash_parent_base'};
1202 } elsif (defined $params{'hash_parent'}) {
1203 $href .= esc_url
($params{'hash_parent'}). "..";
1204 delete $params{'hash_parent'};
1207 $href .= esc_url
($params{'hash_base'});
1208 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1209 $href .= ":/".esc_url
($params{'file_name'});
1210 delete $params{'file_name'};
1212 delete $params{'hash'};
1213 delete $params{'hash_base'};
1214 } elsif (defined $params{'hash'}) {
1215 $href .= esc_url
($params{'hash'});
1216 delete $params{'hash'};
1219 # If the action was a snapshot, we can absorb the
1220 # snapshot_format parameter too
1222 my $fmt = $params{'snapshot_format'};
1223 # snapshot_format should always be defined when href()
1224 # is called, but just in case some code forgets, we
1225 # fall back to the default
1226 $fmt ||= $snapshot_fmts[0];
1227 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1228 delete $params{'snapshot_format'};
1232 # now encode the parameters explicitly
1234 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1235 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1236 if (defined $params{$name}) {
1237 if (ref($params{$name}) eq "ARRAY") {
1238 foreach my $par (@
{$params{$name}}) {
1239 push @result, $symbol . "=" . esc_param
($par);
1242 push @result, $symbol . "=" . esc_param
($params{$name});
1246 $href .= "?" . join(';', @result) if scalar @result;
1252 ## ======================================================================
1253 ## validation, quoting/unquoting and escaping
1255 sub validate_action
{
1256 my $input = shift || return undef;
1257 return undef unless exists $actions{$input};
1261 sub validate_project
{
1262 my $input = shift || return undef;
1263 if (!validate_pathname
($input) ||
1264 !(-d
"$projectroot/$input") ||
1265 !check_export_ok
("$projectroot/$input") ||
1266 ($strict_export && !project_in_list
($input))) {
1273 sub validate_pathname
{
1274 my $input = shift || return undef;
1276 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1277 # at the beginning, at the end, and between slashes.
1278 # also this catches doubled slashes
1279 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1282 # no null characters
1283 if ($input =~ m!\0!) {
1289 sub validate_refname
{
1290 my $input = shift || return undef;
1292 # textual hashes are O.K.
1293 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1296 # it must be correct pathname
1297 $input = validate_pathname
($input)
1299 # restrictions on ref name according to git-check-ref-format
1300 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1306 # decode sequences of octets in utf8 into Perl's internal form,
1307 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1308 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1311 return undef unless defined $str;
1312 if (utf8
::valid
($str)) {
1316 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1320 # quote unsafe chars, but keep the slash, even when it's not
1321 # correct, but quoted slashes look too horrible in bookmarks
1324 return undef unless defined $str;
1325 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1330 # quote unsafe chars in whole URL, so some characters cannot be quoted
1333 return undef unless defined $str;
1334 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1339 # quote unsafe characters in HTML attributes
1342 # for XHTML conformance escaping '"' to '"' is not enough
1343 return esc_html
(@_);
1346 # replace invalid utf8 character with SUBSTITUTION sequence
1351 return undef unless defined $str;
1353 $str = to_utf8
($str);
1354 $str = $cgi->escapeHTML($str);
1355 if ($opts{'-nbsp'}) {
1356 $str =~ s/ / /g;
1358 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1362 # quote control characters and escape filename to HTML
1367 return undef unless defined $str;
1369 $str = to_utf8
($str);
1370 $str = $cgi->escapeHTML($str);
1371 if ($opts{'-nbsp'}) {
1372 $str =~ s/ / /g;
1374 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1378 # Make control characters "printable", using character escape codes (CEC)
1382 my %es = ( # character escape codes, aka escape sequences
1383 "\t" => '\t', # tab (HT)
1384 "\n" => '\n', # line feed (LF)
1385 "\r" => '\r', # carrige return (CR)
1386 "\f" => '\f', # form feed (FF)
1387 "\b" => '\b', # backspace (BS)
1388 "\a" => '\a', # alarm (bell) (BEL)
1389 "\e" => '\e', # escape (ESC)
1390 "\013" => '\v', # vertical tab (VT)
1391 "\000" => '\0', # nul character (NUL)
1393 my $chr = ( (exists $es{$cntrl})
1395 : sprintf('\%2x', ord($cntrl)) );
1396 if ($opts{-nohtml
}) {
1399 return "<span class=\"cntrl\">$chr</span>";
1403 # Alternatively use unicode control pictures codepoints,
1404 # Unicode "printable representation" (PR)
1409 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1410 if ($opts{-nohtml
}) {
1413 return "<span class=\"cntrl\">$chr</span>";
1417 # git may return quoted and escaped filenames
1423 my %es = ( # character escape codes, aka escape sequences
1424 't' => "\t", # tab (HT, TAB)
1425 'n' => "\n", # newline (NL)
1426 'r' => "\r", # return (CR)
1427 'f' => "\f", # form feed (FF)
1428 'b' => "\b", # backspace (BS)
1429 'a' => "\a", # alarm (bell) (BEL)
1430 'e' => "\e", # escape (ESC)
1431 'v' => "\013", # vertical tab (VT)
1434 if ($seq =~ m/^[0-7]{1,3}$/) {
1435 # octal char sequence
1436 return chr(oct($seq));
1437 } elsif (exists $es{$seq}) {
1438 # C escape sequence, aka character escape code
1441 # quoted ordinary character
1445 if ($str =~ m/^"(.*)"$/) {
1448 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1453 # escape tabs (convert tabs to spaces)
1457 while ((my $pos = index($line, "\t")) != -1) {
1458 if (my $count = (8 - ($pos % 8))) {
1459 my $spaces = ' ' x
$count;
1460 $line =~ s/\t/$spaces/;
1467 sub project_in_list
{
1468 my $project = shift;
1469 my @list = git_get_projects_list
();
1470 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1473 ## ----------------------------------------------------------------------
1474 ## HTML aware string manipulation
1476 # Try to chop given string on a word boundary between position
1477 # $len and $len+$add_len. If there is no word boundary there,
1478 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1479 # (marking chopped part) would be longer than given string.
1483 my $add_len = shift || 10;
1484 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1486 # Make sure perl knows it is utf8 encoded so we don't
1487 # cut in the middle of a utf8 multibyte char.
1488 $str = to_utf8
($str);
1490 # allow only $len chars, but don't cut a word if it would fit in $add_len
1491 # if it doesn't fit, cut it if it's still longer than the dots we would add
1492 # remove chopped character entities entirely
1494 # when chopping in the middle, distribute $len into left and right part
1495 # return early if chopping wouldn't make string shorter
1496 if ($where eq 'center') {
1497 return $str if ($len + 5 >= length($str)); # filler is length 5
1500 return $str if ($len + 4 >= length($str)); # filler is length 4
1503 # regexps: ending and beginning with word part up to $add_len
1504 my $endre = qr/.{$len}\w{0,$add_len}/;
1505 my $begre = qr/\w{0,$add_len}.{$len}/;
1507 if ($where eq 'left') {
1508 $str =~ m/^(.*?)($begre)$/;
1509 my ($lead, $body) = ($1, $2);
1510 if (length($lead) > 4) {
1513 return "$lead$body";
1515 } elsif ($where eq 'center') {
1516 $str =~ m/^($endre)(.*)$/;
1517 my ($left, $str) = ($1, $2);
1518 $str =~ m/^(.*?)($begre)$/;
1519 my ($mid, $right) = ($1, $2);
1520 if (length($mid) > 5) {
1523 return "$left$mid$right";
1526 $str =~ m/^($endre)(.*)$/;
1529 if (length($tail) > 4) {
1532 return "$body$tail";
1536 # takes the same arguments as chop_str, but also wraps a <span> around the
1537 # result with a title attribute if it does get chopped. Additionally, the
1538 # string is HTML-escaped.
1539 sub chop_and_escape_str
{
1542 my $chopped = chop_str
(@_);
1543 if ($chopped eq $str) {
1544 return esc_html
($chopped);
1546 $str =~ s/[[:cntrl:]]/?/g;
1547 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1551 ## ----------------------------------------------------------------------
1552 ## functions returning short strings
1554 # CSS class for given age value (in seconds)
1558 if (!defined $age) {
1560 } elsif ($age < 60*60*2) {
1562 } elsif ($age < 60*60*24*2) {
1569 # convert age in seconds to "nn units ago" string
1574 if ($age > 60*60*24*365*2) {
1575 $age_str = (int $age/60/60/24/365);
1576 $age_str .= " years ago";
1577 } elsif ($age > 60*60*24*(365/12)*2) {
1578 $age_str = int $age/60/60/24/(365/12);
1579 $age_str .= " months ago";
1580 } elsif ($age > 60*60*24*7*2) {
1581 $age_str = int $age/60/60/24/7;
1582 $age_str .= " weeks ago";
1583 } elsif ($age > 60*60*24*2) {
1584 $age_str = int $age/60/60/24;
1585 $age_str .= " days ago";
1586 } elsif ($age > 60*60*2) {
1587 $age_str = int $age/60/60;
1588 $age_str .= " hours ago";
1589 } elsif ($age > 60*2) {
1590 $age_str = int $age/60;
1591 $age_str .= " min ago";
1592 } elsif ($age > 2) {
1593 $age_str = int $age;
1594 $age_str .= " sec ago";
1596 $age_str .= " right now";
1602 S_IFINVALID
=> 0030000,
1603 S_IFGITLINK
=> 0160000,
1606 # submodule/subproject, a commit object reference
1610 return (($mode & S_IFMT
) == S_IFGITLINK
)
1613 # convert file mode in octal to symbolic file mode string
1615 my $mode = oct shift;
1617 if (S_ISGITLINK
($mode)) {
1618 return 'm---------';
1619 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1620 return 'drwxr-xr-x';
1621 } elsif (S_ISLNK
($mode)) {
1622 return 'lrwxrwxrwx';
1623 } elsif (S_ISREG
($mode)) {
1624 # git cares only about the executable bit
1625 if ($mode & S_IXUSR
) {
1626 return '-rwxr-xr-x';
1628 return '-rw-r--r--';
1631 return '----------';
1635 # convert file mode in octal to file type string
1639 if ($mode !~ m/^[0-7]+$/) {
1645 if (S_ISGITLINK
($mode)) {
1647 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1649 } elsif (S_ISLNK
($mode)) {
1651 } elsif (S_ISREG
($mode)) {
1658 # convert file mode in octal to file type description string
1659 sub file_type_long
{
1662 if ($mode !~ m/^[0-7]+$/) {
1668 if (S_ISGITLINK
($mode)) {
1670 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1672 } elsif (S_ISLNK
($mode)) {
1674 } elsif (S_ISREG
($mode)) {
1675 if ($mode & S_IXUSR
) {
1676 return "executable";
1686 ## ----------------------------------------------------------------------
1687 ## functions returning short HTML fragments, or transforming HTML fragments
1688 ## which don't belong to other sections
1690 # format line of commit message.
1691 sub format_log_line_html
{
1694 $line = esc_html
($line, -nbsp
=>1);
1695 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1696 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1697 -class => "text"}, $1);
1703 # format marker of refs pointing to given object
1705 # the destination action is chosen based on object type and current context:
1706 # - for annotated tags, we choose the tag view unless it's the current view
1707 # already, in which case we go to shortlog view
1708 # - for other refs, we keep the current view if we're in history, shortlog or
1709 # log view, and select shortlog otherwise
1710 sub format_ref_marker
{
1711 my ($refs, $id) = @_;
1714 if (defined $refs->{$id}) {
1715 foreach my $ref (@
{$refs->{$id}}) {
1716 # this code exploits the fact that non-lightweight tags are the
1717 # only indirect objects, and that they are the only objects for which
1718 # we want to use tag instead of shortlog as action
1719 my ($type, $name) = qw();
1720 my $indirect = ($ref =~ s/\^\{\}$//);
1721 # e.g. tags/v2.6.11 or heads/next
1722 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1731 $class .= " indirect" if $indirect;
1733 my $dest_action = "shortlog";
1736 $dest_action = "tag" unless $action eq "tag";
1737 } elsif ($action =~ /^(history|(short)?log)$/) {
1738 $dest_action = $action;
1742 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1745 my $link = $cgi->a({
1747 action
=>$dest_action,
1751 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
1757 return ' <span class="refs">'. $markers . '</span>';
1763 # format, perhaps shortened and with markers, title line
1764 sub format_subject_html
{
1765 my ($long, $short, $href, $extra) = @_;
1766 $extra = '' unless defined($extra);
1768 if (length($short) < length($long)) {
1769 $long =~ s/[[:cntrl:]]/?/g;
1770 return $cgi->a({-href
=> $href, -class => "list subject",
1771 -title
=> to_utf8
($long)},
1772 esc_html
($short)) . $extra;
1774 return $cgi->a({-href
=> $href, -class => "list subject"},
1775 esc_html
($long)) . $extra;
1779 # Rather than recomputing the url for an email multiple times, we cache it
1780 # after the first hit. This gives a visible benefit in views where the avatar
1781 # for the same email is used repeatedly (e.g. shortlog).
1782 # The cache is shared by all avatar engines (currently gravatar only), which
1783 # are free to use it as preferred. Since only one avatar engine is used for any
1784 # given page, there's no risk for cache conflicts.
1785 our %avatar_cache = ();
1787 # Compute the picon url for a given email, by using the picon search service over at
1788 # http://www.cs.indiana.edu/picons/search.html
1790 my $email = lc shift;
1791 if (!$avatar_cache{$email}) {
1792 my ($user, $domain) = split('@', $email);
1793 $avatar_cache{$email} =
1794 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1796 "users+domains+unknown/up/single";
1798 return $avatar_cache{$email};
1801 # Compute the gravatar url for a given email, if it's not in the cache already.
1802 # Gravatar stores only the part of the URL before the size, since that's the
1803 # one computationally more expensive. This also allows reuse of the cache for
1804 # different sizes (for this particular engine).
1806 my $email = lc shift;
1808 $avatar_cache{$email} ||=
1809 "http://www.gravatar.com/avatar/" .
1810 Digest
::MD5
::md5_hex
($email) . "?s=";
1811 return $avatar_cache{$email} . $size;
1814 # Insert an avatar for the given $email at the given $size if the feature
1816 sub git_get_avatar
{
1817 my ($email, %opts) = @_;
1818 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1819 my $post_white = ($opts{-pad_after
} ?
" " : "");
1820 $opts{-size
} ||= 'default';
1821 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1823 if ($git_avatar eq 'gravatar') {
1824 $url = gravatar_url
($email, $size);
1825 } elsif ($git_avatar eq 'picon') {
1826 $url = picon_url
($email);
1828 # Other providers can be added by extending the if chain, defining $url
1829 # as needed. If no variant puts something in $url, we assume avatars
1830 # are completely disabled/unavailable.
1833 "<img width=\"$size\" " .
1834 "class=\"avatar\" " .
1835 "src=\"".esc_url
($url)."\" " .
1843 sub format_search_author
{
1844 my ($author, $searchtype, $displaytext) = @_;
1845 my $have_search = gitweb_check_feature
('search');
1849 if ($searchtype eq 'author') {
1850 $performed = "authored";
1851 } elsif ($searchtype eq 'committer') {
1852 $performed = "committed";
1855 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1856 searchtext
=>$author,
1857 searchtype
=>$searchtype), class=>"list",
1858 title
=>"Search for commits $performed by $author"},
1862 return $displaytext;
1866 # format the author name of the given commit with the given tag
1867 # the author name is chopped and escaped according to the other
1868 # optional parameters (see chop_str).
1869 sub format_author_html
{
1872 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1873 return "<$tag class=\"author\">" .
1874 format_search_author
($co->{'author_name'}, "author",
1875 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1880 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1881 sub format_git_diff_header_line
{
1883 my $diffinfo = shift;
1884 my ($from, $to) = @_;
1886 if ($diffinfo->{'nparents'}) {
1888 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1889 if ($to->{'href'}) {
1890 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1891 esc_path
($to->{'file'}));
1892 } else { # file was deleted (no href)
1893 $line .= esc_path
($to->{'file'});
1897 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1898 if ($from->{'href'}) {
1899 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1900 'a/' . esc_path
($from->{'file'}));
1901 } else { # file was added (no href)
1902 $line .= 'a/' . esc_path
($from->{'file'});
1905 if ($to->{'href'}) {
1906 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1907 'b/' . esc_path
($to->{'file'}));
1908 } else { # file was deleted
1909 $line .= 'b/' . esc_path
($to->{'file'});
1913 return "<div class=\"diff header\">$line</div>\n";
1916 # format extended diff header line, before patch itself
1917 sub format_extended_diff_header_line
{
1919 my $diffinfo = shift;
1920 my ($from, $to) = @_;
1923 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1924 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1925 esc_path
($from->{'file'}));
1927 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1928 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1929 esc_path
($to->{'file'}));
1931 # match single <mode>
1932 if ($line =~ m/\s(\d{6})$/) {
1933 $line .= '<span class="info"> (' .
1934 file_type_long
($1) .
1938 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1939 # can match only for combined diff
1941 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1942 if ($from->{'href'}[$i]) {
1943 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1945 substr($diffinfo->{'from_id'}[$i],0,7));
1950 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1953 if ($to->{'href'}) {
1954 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1955 substr($diffinfo->{'to_id'},0,7));
1960 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1961 # can match only for ordinary diff
1962 my ($from_link, $to_link);
1963 if ($from->{'href'}) {
1964 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1965 substr($diffinfo->{'from_id'},0,7));
1967 $from_link = '0' x
7;
1969 if ($to->{'href'}) {
1970 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1971 substr($diffinfo->{'to_id'},0,7));
1975 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1976 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1979 return $line . "<br/>\n";
1982 # format from-file/to-file diff header
1983 sub format_diff_from_to_header
{
1984 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1989 #assert($line =~ m/^---/) if DEBUG;
1990 # no extra formatting for "^--- /dev/null"
1991 if (! $diffinfo->{'nparents'}) {
1992 # ordinary (single parent) diff
1993 if ($line =~ m!^--- "?a/!) {
1994 if ($from->{'href'}) {
1996 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1997 esc_path
($from->{'file'}));
2000 esc_path
($from->{'file'});
2003 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2006 # combined diff (merge commit)
2007 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2008 if ($from->{'href'}[$i]) {
2010 $cgi->a({-href
=>href
(action
=>"blobdiff",
2011 hash_parent
=>$diffinfo->{'from_id'}[$i],
2012 hash_parent_base
=>$parents[$i],
2013 file_parent
=>$from->{'file'}[$i],
2014 hash
=>$diffinfo->{'to_id'},
2016 file_name
=>$to->{'file'}),
2018 -title
=>"diff" . ($i+1)},
2021 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2022 esc_path
($from->{'file'}[$i]));
2024 $line = '--- /dev/null';
2026 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2031 #assert($line =~ m/^\+\+\+/) if DEBUG;
2032 # no extra formatting for "^+++ /dev/null"
2033 if ($line =~ m!^\+\+\+ "?b/!) {
2034 if ($to->{'href'}) {
2036 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2037 esc_path
($to->{'file'}));
2040 esc_path
($to->{'file'});
2043 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2048 # create note for patch simplified by combined diff
2049 sub format_diff_cc_simplified
{
2050 my ($diffinfo, @parents) = @_;
2053 $result .= "<div class=\"diff header\">" .
2055 if (!is_deleted
($diffinfo)) {
2056 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2058 hash
=>$diffinfo->{'to_id'},
2059 file_name
=>$diffinfo->{'to_file'}),
2061 esc_path
($diffinfo->{'to_file'}));
2063 $result .= esc_path
($diffinfo->{'to_file'});
2065 $result .= "</div>\n" . # class="diff header"
2066 "<div class=\"diff nodifferences\">" .
2068 "</div>\n"; # class="diff nodifferences"
2073 # format patch (diff) line (not to be used for diff headers)
2074 sub format_diff_line
{
2076 my ($from, $to) = @_;
2077 my $diff_class = "";
2081 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2083 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2084 if ($line =~ m/^\@{3}/) {
2085 $diff_class = " chunk_header";
2086 } elsif ($line =~ m/^\\/) {
2087 $diff_class = " incomplete";
2088 } elsif ($prefix =~ tr/+/+/) {
2089 $diff_class = " add";
2090 } elsif ($prefix =~ tr/-/-/) {
2091 $diff_class = " rem";
2094 # assume ordinary diff
2095 my $char = substr($line, 0, 1);
2097 $diff_class = " add";
2098 } elsif ($char eq '-') {
2099 $diff_class = " rem";
2100 } elsif ($char eq '@') {
2101 $diff_class = " chunk_header";
2102 } elsif ($char eq "\\") {
2103 $diff_class = " incomplete";
2106 $line = untabify
($line);
2107 if ($from && $to && $line =~ m/^\@{2} /) {
2108 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2109 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2111 $from_lines = 0 unless defined $from_lines;
2112 $to_lines = 0 unless defined $to_lines;
2114 if ($from->{'href'}) {
2115 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2116 -class=>"list"}, $from_text);
2118 if ($to->{'href'}) {
2119 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2120 -class=>"list"}, $to_text);
2122 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2123 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2124 return "<div class=\"diff$diff_class\">$line</div>\n";
2125 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2126 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2127 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2129 @from_text = split(' ', $ranges);
2130 for (my $i = 0; $i < @from_text; ++$i) {
2131 ($from_start[$i], $from_nlines[$i]) =
2132 (split(',', substr($from_text[$i], 1)), 0);
2135 $to_text = pop @from_text;
2136 $to_start = pop @from_start;
2137 $to_nlines = pop @from_nlines;
2139 $line = "<span class=\"chunk_info\">$prefix ";
2140 for (my $i = 0; $i < @from_text; ++$i) {
2141 if ($from->{'href'}[$i]) {
2142 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2143 -class=>"list"}, $from_text[$i]);
2145 $line .= $from_text[$i];
2149 if ($to->{'href'}) {
2150 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2151 -class=>"list"}, $to_text);
2155 $line .= " $prefix</span>" .
2156 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2157 return "<div class=\"diff$diff_class\">$line</div>\n";
2159 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2162 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2163 # linked. Pass the hash of the tree/commit to snapshot.
2164 sub format_snapshot_links
{
2166 my $num_fmts = @snapshot_fmts;
2167 if ($num_fmts > 1) {
2168 # A parenthesized list of links bearing format names.
2169 # e.g. "snapshot (_tar.gz_ _zip_)"
2170 return "snapshot (" . join(' ', map
2177 }, $known_snapshot_formats{$_}{'display'})
2178 , @snapshot_fmts) . ")";
2179 } elsif ($num_fmts == 1) {
2180 # A single "snapshot" link whose tooltip bears the format name.
2182 my ($fmt) = @snapshot_fmts;
2188 snapshot_format
=>$fmt
2190 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2192 } else { # $num_fmts == 0
2197 ## ......................................................................
2198 ## functions returning values to be passed, perhaps after some
2199 ## transformation, to other functions; e.g. returning arguments to href()
2201 # returns hash to be passed to href to generate gitweb URL
2202 # in -title key it returns description of link
2204 my $format = shift || 'Atom';
2205 my %res = (action
=> lc($format));
2207 # feed links are possible only for project views
2208 return unless (defined $project);
2209 # some views should link to OPML, or to generic project feed,
2210 # or don't have specific feed yet (so they should use generic)
2211 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2214 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2215 # from tag links; this also makes possible to detect branch links
2216 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2217 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2220 # find log type for feed description (title)
2222 if (defined $file_name) {
2223 $type = "history of $file_name";
2224 $type .= "/" if ($action eq 'tree');
2225 $type .= " on '$branch'" if (defined $branch);
2227 $type = "log of $branch" if (defined $branch);
2230 $res{-title
} = $type;
2231 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2232 $res{'file_name'} = $file_name;
2237 ## ----------------------------------------------------------------------
2238 ## git utility subroutines, invoking git commands
2240 # returns path to the core git executable and the --git-dir parameter as list
2242 $number_of_git_cmds++;
2243 return $GIT, '--git-dir='.$git_dir;
2246 # quote the given arguments for passing them to the shell
2247 # quote_command("command", "arg 1", "arg with ' and ! characters")
2248 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2249 # Try to avoid using this function wherever possible.
2252 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2255 # get HEAD ref of given project as hash
2256 sub git_get_head_hash
{
2257 return git_get_full_hash
(shift, 'HEAD');
2260 sub git_get_full_hash
{
2261 return git_get_hash
(@_);
2264 sub git_get_short_hash
{
2265 return git_get_hash
(@_, '--short=7');
2269 my ($project, $hash, @options) = @_;
2270 my $o_git_dir = $git_dir;
2272 $git_dir = "$projectroot/$project";
2273 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2274 '--verify', '-q', @options, $hash) {
2276 chomp $retval if defined $retval;
2279 if (defined $o_git_dir) {
2280 $git_dir = $o_git_dir;
2285 # get type of given object
2289 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2291 close $fd or return;
2296 # repository configuration
2297 our $config_file = '';
2300 # store multiple values for single key as anonymous array reference
2301 # single values stored directly in the hash, not as [ <value> ]
2302 sub hash_set_multi
{
2303 my ($hash, $key, $value) = @_;
2305 if (!exists $hash->{$key}) {
2306 $hash->{$key} = $value;
2307 } elsif (!ref $hash->{$key}) {
2308 $hash->{$key} = [ $hash->{$key}, $value ];
2310 push @
{$hash->{$key}}, $value;
2314 # return hash of git project configuration
2315 # optionally limited to some section, e.g. 'gitweb'
2316 sub git_parse_project_config
{
2317 my $section_regexp = shift;
2322 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2325 while (my $keyval = <$fh>) {
2327 my ($key, $value) = split(/\n/, $keyval, 2);
2329 hash_set_multi
(\
%config, $key, $value)
2330 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2337 # convert config value to boolean: 'true' or 'false'
2338 # no value, number > 0, 'true' and 'yes' values are true
2339 # rest of values are treated as false (never as error)
2340 sub config_to_bool
{
2343 return 1 if !defined $val; # section.key
2345 # strip leading and trailing whitespace
2349 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2350 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2353 # convert config value to simple decimal number
2354 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2355 # to be multiplied by 1024, 1048576, or 1073741824
2359 # strip leading and trailing whitespace
2363 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2365 # unknown unit is treated as 1
2366 return $num * ($unit eq 'g' ?
1073741824 :
2367 $unit eq 'm' ?
1048576 :
2368 $unit eq 'k' ?
1024 : 1);
2373 # convert config value to array reference, if needed
2374 sub config_to_multi
{
2377 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2380 sub git_get_project_config
{
2381 my ($key, $type) = @_;
2383 return unless defined $git_dir;
2386 return unless ($key);
2387 $key =~ s/^gitweb\.//;
2388 return if ($key =~ m/\W/);
2391 if (defined $type) {
2394 unless ($type eq 'bool' || $type eq 'int');
2398 if (!defined $config_file ||
2399 $config_file ne "$git_dir/config") {
2400 %config = git_parse_project_config
('gitweb');
2401 $config_file = "$git_dir/config";
2404 # check if config variable (key) exists
2405 return unless exists $config{"gitweb.$key"};
2408 if (!defined $type) {
2409 return $config{"gitweb.$key"};
2410 } elsif ($type eq 'bool') {
2411 # backward compatibility: 'git config --bool' returns true/false
2412 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2413 } elsif ($type eq 'int') {
2414 return config_to_int
($config{"gitweb.$key"});
2416 return $config{"gitweb.$key"};
2419 # get hash of given path at given ref
2420 sub git_get_hash_by_path
{
2422 my $path = shift || return undef;
2427 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2428 or die_error
(500, "Open git-ls-tree failed");
2430 close $fd or return undef;
2432 if (!defined $line) {
2433 # there is no tree or hash given by $path at $base
2437 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2438 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2439 if (defined $type && $type ne $2) {
2440 # type doesn't match
2446 # get path of entry with given hash at given tree-ish (ref)
2447 # used to get 'from' filename for combined diff (merge commit) for renames
2448 sub git_get_path_by_hash
{
2449 my $base = shift || return;
2450 my $hash = shift || return;
2454 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2456 while (my $line = <$fd>) {
2459 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2460 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2461 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2470 ## ......................................................................
2471 ## git utility functions, directly accessing git repository
2473 sub git_get_project_description
{
2476 $git_dir = "$projectroot/$path";
2477 open my $fd, '<', "$git_dir/description"
2478 or return git_get_project_config
('description');
2481 if (defined $descr) {
2487 sub git_get_project_ctags
{
2491 $git_dir = "$projectroot/$path";
2492 opendir my $dh, "$git_dir/ctags"
2494 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2495 open my $ct, '<', $_ or next;
2499 my $ctag = $_; $ctag =~ s
#.*/##;
2500 $ctags->{$ctag} = $val;
2506 sub git_populate_project_tagcloud
{
2509 # First, merge different-cased tags; tags vote on casing
2511 foreach (keys %$ctags) {
2512 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2513 if (not $ctags_lc{lc $_}->{topcount
}
2514 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2515 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2516 $ctags_lc{lc $_}->{topname
} = $_;
2521 if (eval { require HTML
::TagCloud
; 1; }) {
2522 $cloud = HTML
::TagCloud
->new;
2523 foreach (sort keys %ctags_lc) {
2524 # Pad the title with spaces so that the cloud looks
2526 my $title = $ctags_lc{$_}->{topname
};
2527 $title =~ s/ / /g;
2528 $title =~ s/^/ /g;
2529 $title =~ s/$/ /g;
2530 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2533 $cloud = \
%ctags_lc;
2538 sub git_show_project_tagcloud
{
2539 my ($cloud, $count) = @_;
2540 print STDERR
ref($cloud)."..\n";
2541 if (ref $cloud eq 'HTML::TagCloud') {
2542 return $cloud->html_and_css($count);
2544 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2545 return '<p align="center">' . join (', ', map {
2546 $cgi->a({-href
=>"$home_link?by_tag=$_"}, $cloud->{$_}->{topname
})
2547 } splice(@tags, 0, $count)) . '</p>';
2551 sub git_get_project_url_list
{
2554 $git_dir = "$projectroot/$path";
2555 open my $fd, '<', "$git_dir/cloneurl"
2556 or return wantarray ?
2557 @
{ config_to_multi
(git_get_project_config
('url')) } :
2558 config_to_multi
(git_get_project_config
('url'));
2559 my @git_project_url_list = map { chomp; $_ } <$fd>;
2562 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2565 sub git_get_projects_list
{
2570 $filter =~ s/\.git$//;
2572 my $check_forks = gitweb_check_feature
('forks');
2574 if (-d
$projects_list) {
2575 # search in directory
2576 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2577 # remove the trailing "/"
2579 my $pfxlen = length("$dir");
2580 my $pfxdepth = ($dir =~ tr!/!!);
2583 follow_fast
=> 1, # follow symbolic links
2584 follow_skip
=> 2, # ignore duplicates
2585 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2588 our $project_maxdepth;
2590 # skip project-list toplevel, if we get it.
2591 return if (m!^[/.]$!);
2592 # only directories can be git repositories
2593 return unless (-d
$_);
2594 # don't traverse too deep (Find is super slow on os x)
2595 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2596 $File::Find
::prune
= 1;
2600 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2601 # we check related file in $projectroot
2602 my $path = ($filter ?
"$filter/" : '') . $subdir;
2603 if (check_export_ok
("$projectroot/$path")) {
2604 push @list, { path
=> $path };
2605 $File::Find
::prune
= 1;
2610 } elsif (-f
$projects_list) {
2611 # read from file(url-encoded):
2612 # 'git%2Fgit.git Linus+Torvalds'
2613 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2614 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2616 open my $fd, '<', $projects_list or return;
2618 while (my $line = <$fd>) {
2620 my ($path, $owner) = split ' ', $line;
2621 $path = unescape
($path);
2622 $owner = unescape
($owner);
2623 if (!defined $path) {
2626 if ($filter ne '') {
2627 # looking for forks;
2628 my $pfx = substr($path, 0, length($filter));
2629 if ($pfx ne $filter) {
2632 my $sfx = substr($path, length($filter));
2633 if ($sfx !~ /^\/.*\
.git
$/) {
2636 } elsif ($check_forks) {
2638 foreach my $filter (keys %paths) {
2639 # looking for forks;
2640 my $pfx = substr($path, 0, length($filter));
2641 if ($pfx ne $filter) {
2644 my $sfx = substr($path, length($filter));
2645 if ($sfx !~ /^\/.*\
.git
$/) {
2648 # is a fork, don't include it in
2653 if (check_export_ok
("$projectroot/$path")) {
2656 owner
=> to_utf8
($owner),
2659 (my $forks_path = $path) =~ s/\.git$//;
2660 $paths{$forks_path}++;
2668 our $gitweb_project_owner = undef;
2669 sub git_get_project_list_from_file
{
2671 return if (defined $gitweb_project_owner);
2673 $gitweb_project_owner = {};
2674 # read from file (url-encoded):
2675 # 'git%2Fgit.git Linus+Torvalds'
2676 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2677 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2678 if (-f
$projects_list) {
2679 open(my $fd, '<', $projects_list);
2680 while (my $line = <$fd>) {
2682 my ($pr, $ow) = split ' ', $line;
2683 $pr = unescape
($pr);
2684 $ow = unescape
($ow);
2685 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2691 sub git_get_project_owner
{
2692 my $project = shift;
2695 return undef unless $project;
2696 $git_dir = "$projectroot/$project";
2698 if (!defined $gitweb_project_owner) {
2699 git_get_project_list_from_file
();
2702 if (exists $gitweb_project_owner->{$project}) {
2703 $owner = $gitweb_project_owner->{$project};
2705 if (!defined $owner){
2706 $owner = git_get_project_config
('owner');
2708 if (!defined $owner) {
2709 $owner = get_file_owner
("$git_dir");
2715 sub git_get_last_activity
{
2719 $git_dir = "$projectroot/$path";
2720 open($fd, "-|", git_cmd
(), 'for-each-ref',
2721 '--format=%(committer)',
2722 '--sort=-committerdate',
2724 'refs/heads') or return;
2725 my $most_recent = <$fd>;
2726 close $fd or return;
2727 if (defined $most_recent && $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2729 my $age = time - $timestamp;
2730 return ($age, age_string
($age));
2732 return (undef, undef);
2735 sub git_get_references
{
2736 my $type = shift || "";
2738 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2739 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2740 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2741 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2744 while (my $line = <$fd>) {
2746 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2747 if (defined $refs{$1}) {
2748 push @
{$refs{$1}}, $2;
2754 close $fd or return;
2758 sub git_get_rev_name_tags
{
2759 my $hash = shift || return undef;
2761 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2763 my $name_rev = <$fd>;
2766 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2769 # catches also '$hash undefined' output
2774 ## ----------------------------------------------------------------------
2775 ## parse to hash functions
2779 my $tz = shift || "-0000";
2782 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2783 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2784 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2785 $date{'hour'} = $hour;
2786 $date{'minute'} = $min;
2787 $date{'mday'} = $mday;
2788 $date{'day'} = $days[$wday];
2789 $date{'month'} = $months[$mon];
2790 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2791 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2792 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2793 $mday, $months[$mon], $hour ,$min;
2794 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2795 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2797 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2798 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2799 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2800 $date{'hour_local'} = $hour;
2801 $date{'minute_local'} = $min;
2802 $date{'tz_local'} = $tz;
2803 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2804 1900+$year, $mon+1, $mday,
2805 $hour, $min, $sec, $tz);
2814 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2815 $tag{'id'} = $tag_id;
2816 while (my $line = <$fd>) {
2818 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2819 $tag{'object'} = $1;
2820 } elsif ($line =~ m/^type (.+)$/) {
2822 } elsif ($line =~ m/^tag (.+)$/) {
2824 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2825 $tag{'author'} = $1;
2826 $tag{'author_epoch'} = $2;
2827 $tag{'author_tz'} = $3;
2828 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2829 $tag{'author_name'} = $1;
2830 $tag{'author_email'} = $2;
2832 $tag{'author_name'} = $tag{'author'};
2834 } elsif ($line =~ m/--BEGIN/) {
2835 push @comment, $line;
2837 } elsif ($line eq "") {
2841 push @comment, <$fd>;
2842 $tag{'comment'} = \
@comment;
2843 close $fd or return;
2844 if (!defined $tag{'name'}) {
2850 sub parse_commit_text
{
2851 my ($commit_text, $withparents) = @_;
2852 my @commit_lines = split '\n', $commit_text;
2855 pop @commit_lines; # Remove '\0'
2857 if (! @commit_lines) {
2861 my $header = shift @commit_lines;
2862 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2865 ($co{'id'}, my @parents) = split ' ', $header;
2866 while (my $line = shift @commit_lines) {
2867 last if $line eq "\n";
2868 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2870 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2872 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2873 $co{'author'} = to_utf8
($1);
2874 $co{'author_epoch'} = $2;
2875 $co{'author_tz'} = $3;
2876 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2877 $co{'author_name'} = $1;
2878 $co{'author_email'} = $2;
2880 $co{'author_name'} = $co{'author'};
2882 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2883 $co{'committer'} = to_utf8
($1);
2884 $co{'committer_epoch'} = $2;
2885 $co{'committer_tz'} = $3;
2886 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2887 $co{'committer_name'} = $1;
2888 $co{'committer_email'} = $2;
2890 $co{'committer_name'} = $co{'committer'};
2894 if (!defined $co{'tree'}) {
2897 $co{'parents'} = \
@parents;
2898 $co{'parent'} = $parents[0];
2900 foreach my $title (@commit_lines) {
2903 $co{'title'} = chop_str
($title, 80, 5);
2904 # remove leading stuff of merges to make the interesting part visible
2905 if (length($title) > 50) {
2906 $title =~ s/^Automatic //;
2907 $title =~ s/^merge (of|with) /Merge ... /i;
2908 if (length($title) > 50) {
2909 $title =~ s/(http|rsync):\/\///;
2911 if (length($title) > 50) {
2912 $title =~ s/(master|www|rsync)\.//;
2914 if (length($title) > 50) {
2915 $title =~ s/kernel.org:?//;
2917 if (length($title) > 50) {
2918 $title =~ s/\/pub\/scm//;
2921 $co{'title_short'} = chop_str
($title, 50, 5);
2925 if (! defined $co{'title'} || $co{'title'} eq "") {
2926 $co{'title'} = $co{'title_short'} = '(no commit message)';
2928 # remove added spaces
2929 foreach my $line (@commit_lines) {
2932 $co{'comment'} = \
@commit_lines;
2934 my $age = time - $co{'committer_epoch'};
2936 $co{'age_string'} = age_string
($age);
2937 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2938 if ($age > 60*60*24*7*2) {
2939 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2940 $co{'age_string_age'} = $co{'age_string'};
2942 $co{'age_string_date'} = $co{'age_string'};
2943 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2949 my ($commit_id) = @_;
2954 open my $fd, "-|", git_cmd
(), "rev-list",
2960 or die_error
(500, "Open git-rev-list failed");
2961 %co = parse_commit_text
(<$fd>, 1);
2968 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2976 open my $fd, "-|", git_cmd
(), "rev-list",
2979 ("--max-count=" . $maxcount),
2980 ("--skip=" . $skip),
2984 ($filename ?
($filename) : ())
2985 or die_error
(500, "Open git-rev-list failed");
2986 while (my $line = <$fd>) {
2987 my %co = parse_commit_text
($line);
2992 return wantarray ?
@cos : \
@cos;
2995 # parse line of git-diff-tree "raw" output
2996 sub parse_difftree_raw_line
{
3000 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
3001 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
3002 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
3003 $res{'from_mode'} = $1;
3004 $res{'to_mode'} = $2;
3005 $res{'from_id'} = $3;
3007 $res{'status'} = $5;
3008 $res{'similarity'} = $6;
3009 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3010 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3012 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3015 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3016 # combined diff (for merge commit)
3017 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3018 $res{'nparents'} = length($1);
3019 $res{'from_mode'} = [ split(' ', $2) ];
3020 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3021 $res{'from_id'} = [ split(' ', $3) ];
3022 $res{'to_id'} = pop @
{$res{'from_id'}};
3023 $res{'status'} = [ split('', $4) ];
3024 $res{'to_file'} = unquote
($5);
3026 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3027 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3028 $res{'commit'} = $1;
3031 return wantarray ?
%res : \
%res;
3034 # wrapper: return parsed line of git-diff-tree "raw" output
3035 # (the argument might be raw line, or parsed info)
3036 sub parsed_difftree_line
{
3037 my $line_or_ref = shift;
3039 if (ref($line_or_ref) eq "HASH") {
3040 # pre-parsed (or generated by hand)
3041 return $line_or_ref;
3043 return parse_difftree_raw_line
($line_or_ref);
3047 # parse line of git-ls-tree output
3048 sub parse_ls_tree_line
{
3054 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3055 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3064 $res{'name'} = unquote
($5);
3067 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3068 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3076 $res{'name'} = unquote
($4);
3080 return wantarray ?
%res : \
%res;
3083 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3084 sub parse_from_to_diffinfo
{
3085 my ($diffinfo, $from, $to, @parents) = @_;
3087 if ($diffinfo->{'nparents'}) {
3089 $from->{'file'} = [];
3090 $from->{'href'} = [];
3091 fill_from_file_info
($diffinfo, @parents)
3092 unless exists $diffinfo->{'from_file'};
3093 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3094 $from->{'file'}[$i] =
3095 defined $diffinfo->{'from_file'}[$i] ?
3096 $diffinfo->{'from_file'}[$i] :
3097 $diffinfo->{'to_file'};
3098 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3099 $from->{'href'}[$i] = href
(action
=>"blob",
3100 hash_base
=>$parents[$i],
3101 hash
=>$diffinfo->{'from_id'}[$i],
3102 file_name
=>$from->{'file'}[$i]);
3104 $from->{'href'}[$i] = undef;
3108 # ordinary (not combined) diff
3109 $from->{'file'} = $diffinfo->{'from_file'};
3110 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3111 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3112 hash
=>$diffinfo->{'from_id'},
3113 file_name
=>$from->{'file'});
3115 delete $from->{'href'};
3119 $to->{'file'} = $diffinfo->{'to_file'};
3120 if (!is_deleted
($diffinfo)) { # file exists in result
3121 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3122 hash
=>$diffinfo->{'to_id'},
3123 file_name
=>$to->{'file'});
3125 delete $to->{'href'};
3129 ## ......................................................................
3130 ## parse to array of hashes functions
3132 sub git_get_heads_list
{
3136 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3137 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3138 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3141 while (my $line = <$fd>) {
3145 my ($refinfo, $committerinfo) = split(/\0/, $line);
3146 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3147 my ($committer, $epoch, $tz) =
3148 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3149 $ref_item{'fullname'} = $name;
3150 $name =~ s!^refs/heads/!!;
3152 $ref_item{'name'} = $name;
3153 $ref_item{'id'} = $hash;
3154 $ref_item{'title'} = $title || '(no commit message)';
3155 $ref_item{'epoch'} = $epoch;
3157 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3159 $ref_item{'age'} = "unknown";
3162 push @headslist, \
%ref_item;
3166 return wantarray ?
@headslist : \
@headslist;
3169 sub git_get_tags_list
{
3173 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3174 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3175 '--format=%(objectname) %(objecttype) %(refname) '.
3176 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3179 while (my $line = <$fd>) {
3183 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3184 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3185 my ($creator, $epoch, $tz) =
3186 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3187 $ref_item{'fullname'} = $name;
3188 $name =~ s!^refs/tags/!!;
3190 $ref_item{'type'} = $type;
3191 $ref_item{'id'} = $id;
3192 $ref_item{'name'} = $name;
3193 if ($type eq "tag") {
3194 $ref_item{'subject'} = $title;
3195 $ref_item{'reftype'} = $reftype;
3196 $ref_item{'refid'} = $refid;
3198 $ref_item{'reftype'} = $type;
3199 $ref_item{'refid'} = $id;
3202 if ($type eq "tag" || $type eq "commit") {
3203 $ref_item{'epoch'} = $epoch;
3205 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3207 $ref_item{'age'} = "unknown";
3211 push @tagslist, \
%ref_item;
3215 return wantarray ?
@tagslist : \
@tagslist;
3218 ## ----------------------------------------------------------------------
3219 ## filesystem-related functions
3221 sub get_file_owner
{
3224 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3225 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3226 if (!defined $gcos) {
3230 $owner =~ s/[,;].*$//;
3231 return to_utf8
($owner);
3234 # assume that file exists
3236 my $filename = shift;
3238 open my $fd, '<', $filename;
3239 print map { to_utf8
($_) } <$fd>;
3243 ## ......................................................................
3244 ## mimetype related functions
3246 sub mimetype_guess_file
{
3247 my $filename = shift;
3248 my $mimemap = shift;
3249 -r
$mimemap or return undef;
3252 open(my $mh, '<', $mimemap) or return undef;
3254 next if m/^#/; # skip comments
3255 my ($mimetype, $exts) = split(/\t+/);
3256 if (defined $exts) {
3257 my @exts = split(/\s+/, $exts);
3258 foreach my $ext (@exts) {
3259 $mimemap{$ext} = $mimetype;
3265 $filename =~ /\.([^.]*)$/;
3266 return $mimemap{$1};
3269 sub mimetype_guess
{
3270 my $filename = shift;
3272 $filename =~ /\./ or return undef;
3274 if ($mimetypes_file) {
3275 my $file = $mimetypes_file;
3276 if ($file !~ m!^/!) { # if it is relative path
3277 # it is relative to project
3278 $file = "$projectroot/$project/$file";
3280 $mime = mimetype_guess_file
($filename, $file);
3282 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3288 my $filename = shift;
3291 my $mime = mimetype_guess
($filename);
3292 $mime and return $mime;
3296 return $default_blob_plain_mimetype unless $fd;
3299 return 'text/plain';
3300 } elsif (! $filename) {
3301 return 'application/octet-stream';
3302 } elsif ($filename =~ m/\.png$/i) {
3304 } elsif ($filename =~ m/\.gif$/i) {
3306 } elsif ($filename =~ m/\.jpe?g$/i) {
3307 return 'image/jpeg';
3309 return 'application/octet-stream';
3313 sub blob_contenttype
{
3314 my ($fd, $file_name, $type) = @_;
3316 $type ||= blob_mimetype
($fd, $file_name);
3317 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3318 $type .= "; charset=$default_text_plain_charset";
3324 # guess file syntax for syntax highlighting; return undef if no highlighting
3325 # the name of syntax can (in the future) depend on syntax highlighter used
3326 sub guess_file_syntax
{
3327 my ($highlight, $mimetype, $file_name) = @_;
3328 return undef unless ($highlight && defined $file_name);
3330 # configuration for 'highlight' (http://www.andre-simon.de/)
3332 my %highlight_basename = (
3335 'SConstruct' => 'py', # SCons equivalent of Makefile
3336 'Makefile' => 'make',
3338 # match by extension
3339 my %highlight_ext = (
3340 # main extensions, defining name of syntax;
3341 # see files in /usr/share/highlight/langDefs/ directory
3343 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
3344 # alternate extensions, see /etc/highlight/filetypes.conf
3346 map { $_ => 'cpp' } qw(cxx c++ cc),
3347 map { $_ => 'php' } qw(php3 php4),
3348 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
3350 map { $_ => 'xml' } qw(xhtml html htm),
3353 my $basename = basename
($file_name, '.in');
3354 return $highlight_basename{$basename}
3355 if exists $highlight_basename{$basename};
3357 $basename =~ /\.([^.]*)$/;
3358 my $ext = $1 or return undef;
3359 return $highlight_ext{$ext}
3360 if exists $highlight_ext{$ext};
3365 # run highlighter and return FD of its output,
3366 # or return original FD if no highlighting
3367 sub run_highlighter
{
3368 my ($fd, $highlight, $syntax) = @_;
3369 return $fd unless ($highlight && defined $syntax);
3372 or die_error
(404, "Reading blob failed");
3373 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3374 "highlight --xhtml --fragment --syntax $syntax |"
3375 or die_error
(500, "Couldn't open file or run syntax highlighter");
3379 ## ======================================================================
3380 ## functions printing HTML: header, footer, error page
3382 sub get_page_title
{
3383 my $title = to_utf8
($site_name);
3385 return $title unless (defined $project);
3386 $title .= " - " . to_utf8
($project);
3388 return $title unless (defined $action);
3389 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3391 return $title unless (defined $file_name);
3392 $title .= " - " . esc_path
($file_name);
3393 if ($action eq "tree" && $file_name !~ m
|/$|) {
3400 sub git_header_html
{
3401 my $status = shift || "200 OK";
3402 my $expires = shift;
3405 my $title = get_page_title
();
3407 # require explicit support from the UA if we are to send the page as
3408 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3409 # we have to do this because MSIE sometimes globs '*/*', pretending to
3410 # support xhtml+xml but choking when it gets what it asked for.
3411 if (defined $cgi->http('HTTP_ACCEPT') &&
3412 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3413 $cgi->Accept('application/xhtml+xml') != 0) {
3414 $content_type = 'application/xhtml+xml';
3416 $content_type = 'text/html';
3418 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3419 -status
=> $status, -expires
=> $expires)
3420 unless ($opts{'-no_http_header'});
3421 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3423 <?xml version="1.0" encoding="utf-8"?>
3424 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3425 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3426 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3427 <!-- git core binaries version $git_version -->
3429 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3430 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3431 <meta name="robots" content="index, nofollow"/>
3432 <title>$title</title>
3434 # the stylesheet, favicon etc urls won't work correctly with path_info
3435 # unless we set the appropriate base URL
3436 if ($ENV{'PATH_INFO'}) {
3437 print "<base href=\"".esc_url
($base_url)."\" />\n";
3439 # print out each stylesheet that exist, providing backwards capability
3440 # for those people who defined $stylesheet in a config file
3441 if (defined $stylesheet) {
3442 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3444 foreach my $stylesheet (@stylesheets) {
3445 next unless $stylesheet;
3446 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3449 if (defined $project) {
3450 my %href_params = get_feed_info
();
3451 if (!exists $href_params{'-title'}) {
3452 $href_params{'-title'} = 'log';
3455 foreach my $format qw(RSS Atom) {
3456 my $type = lc($format);
3458 '-rel' => 'alternate',
3459 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3460 '-type' => "application/$type+xml"
3463 $href_params{'action'} = $type;
3464 $link_attr{'-href'} = href
(%href_params);
3466 "rel=\"$link_attr{'-rel'}\" ".
3467 "title=\"$link_attr{'-title'}\" ".
3468 "href=\"$link_attr{'-href'}\" ".
3469 "type=\"$link_attr{'-type'}\" ".
3472 $href_params{'extra_options'} = '--no-merges';
3473 $link_attr{'-href'} = href
(%href_params);
3474 $link_attr{'-title'} .= ' (no merges)';
3476 "rel=\"$link_attr{'-rel'}\" ".
3477 "title=\"$link_attr{'-title'}\" ".
3478 "href=\"$link_attr{'-href'}\" ".
3479 "type=\"$link_attr{'-type'}\" ".
3484 printf('<link rel="alternate" title="%s projects list" '.
3485 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3486 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3487 printf('<link rel="alternate" title="%s projects feeds" '.
3488 'href="%s" type="text/x-opml" />'."\n",
3489 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3491 if (defined $favicon) {
3492 print qq(<link rel
="shortcut icon" href
=").esc_url($favicon).qq(" type
="image/png" />\n);
3498 if (defined $site_header && -f
$site_header) {
3499 insert_file
($site_header);
3502 print "<div class=\"page_header\">\n";
3503 if (defined $logo) {
3504 print $cgi->a({-href
=> esc_url
($logo_url),
3505 -title
=> $logo_label},
3506 qq(<img src
=").esc_url($logo).qq(" width
="72" height
="27" alt
="git" class="logo"/>));
3508 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3509 if (defined $project) {
3510 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3511 if (defined $action) {
3516 if (defined $action && $action != $home_link_str) {
3522 my $have_search = gitweb_check_feature
('search');
3523 if (defined $project && $have_search) {
3524 if (!defined $searchtext) {
3528 if (defined $hash_base) {
3529 $search_hash = $hash_base;
3530 } elsif (defined $hash) {
3531 $search_hash = $hash;
3533 $search_hash = "HEAD";
3535 my $action = $my_uri;
3536 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3537 if ($use_pathinfo) {
3538 $action .= "/".esc_url
($project);
3540 print $cgi->startform(-method
=> "get", -action
=> $action) .
3541 "<div class=\"search\">\n" .
3543 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3544 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3545 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3546 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3547 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3548 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3550 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3551 "<span title=\"Extended regular expression\">" .
3552 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3553 -checked
=> $search_use_regexp) .
3556 $cgi->end_form() . "\n";
3560 sub git_footer_html
{
3561 my $feed_class = 'rss_logo';
3562 my $feed_class2 = 'rss_logo2';
3564 print "<div class=\"page_footer\">\n";
3565 if (defined $project) {
3566 my $descr = git_get_project_description
($project);
3567 if (defined $descr) {
3568 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3571 my %href_params = get_feed_info
();
3572 if (!%href_params) {
3573 $feed_class .= ' generic';
3575 $href_params{'-title'} ||= 'log';
3577 foreach my $format qw(RSS Atom) {
3578 $href_params{'action'} = lc($format);
3579 print $cgi->a({-href
=> href
(%href_params),
3580 -title
=> "$href_params{'-title'} $format feed",
3581 -class => $feed_class}, $format)."\n";
3585 print "<div class=\"page_footer_text\">Copyright © 2012, <a href=\"http://nexus-irc.de\">Nexus-IRC.de</a></div>\n";
3586 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3587 -class => $feed_class}, "OPML") . " ";
3588 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3589 -class => $feed_class}, "TXT") . " ";
3590 print $cgi->a({-href
=> href
(project
=>undef, action
=>"download"),
3591 -class => $feed_class2}, "Downloads") . "\n";
3593 print "</div>\n"; # class="page_footer"
3595 if (defined $t0 && gitweb_check_feature
('timed')) {
3596 print "<div id=\"generating_info\">\n";
3597 print 'This page took '.
3598 '<span id="generating_time" class="time_span">'.
3599 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3602 '<span id="generating_cmd">'.
3603 $number_of_git_cmds.
3604 '</span> git commands '.
3606 print "</div>\n"; # class="page_footer"
3609 if (defined $site_footer && -f
$site_footer) {
3610 insert_file
($site_footer);
3613 print qq!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
3614 if (defined $action &&
3615 $action eq 'blame_incremental') {
3616 print qq!<script type
="text/javascript">\n!.
3617 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3618 qq! "!. href() .qq!");\n!.
3620 } elsif (gitweb_check_feature
('javascript-actions')) {
3621 print qq!<script type
="text/javascript">\n!.
3622 qq!window
.onload
= fixLinks
;\n!.
3630 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3631 # Example: die_error(404, 'Hash not found')
3632 # By convention, use the following status codes (as defined in RFC 2616):
3633 # 400: Invalid or missing CGI parameters, or
3634 # requested object exists but has wrong type.
3635 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3636 # this server or project.
3637 # 404: Requested object/revision/project doesn't exist.
3638 # 500: The server isn't configured properly, or
3639 # an internal error occurred (e.g. failed assertions caused by bugs), or
3640 # an unknown error occurred (e.g. the git binary died unexpectedly).
3641 # 503: The server is currently unavailable (because it is overloaded,
3642 # or down for maintenance). Generally, this is a temporary state.
3644 my $status = shift || 500;
3645 my $error = esc_html
(shift) || "Internal Server Error";
3649 my %http_responses = (
3650 400 => '400 Bad Request',
3651 403 => '403 Forbidden',
3652 404 => '404 Not Found',
3653 500 => '500 Internal Server Error',
3654 503 => '503 Service Unavailable',
3656 git_header_html
($http_responses{$status}, undef, %opts);
3658 <div class="page_body">
3663 if (defined $extra) {
3671 unless ($opts{'-error_handler'});
3674 ## ----------------------------------------------------------------------
3675 ## functions printing or outputting HTML: navigation
3677 sub git_print_page_nav
{
3678 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3679 $extra = '' if !defined $extra; # pager or formats
3681 my @navs = qw(summary bugtracker shortlog log commit commitdiff tree);
3683 @navs = grep { $_ ne $suppress } @navs;
3686 my %arg = map { $_ => {action
=>$_} } @navs;
3687 if (defined $head) {
3688 for (qw(commit commitdiff)) {
3689 $arg{$_}{'hash'} = $head;
3691 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3692 for (qw(shortlog log)) {
3693 $arg{$_}{'hash'} = $head;
3698 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3699 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3701 my @actions = gitweb_get_feature
('actions');
3704 'n' => $project, # project name
3705 'f' => $git_dir, # project path within filesystem
3706 'h' => $treehead || '', # current hash ('h' parameter)
3707 'b' => $treebase || '', # hash base ('hb' parameter)
3710 my ($label, $link, $pos) = splice(@actions,0,3);
3712 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3714 $link =~ s/%([%nfhb])/$repl{$1}/g;
3715 $arg{$label}{'_href'} = $link;
3718 print "<div class=\"page_nav\">\n" .
3720 map { $_ eq $current ?
3721 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3723 print "<br/>\n$extra<br/>\n" .
3727 sub format_paging_nav
{
3728 my ($action, $page, $has_next_link) = @_;
3734 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3736 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3737 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3739 $paging_nav .= "first ⋅ prev";
3742 if ($has_next_link) {
3743 $paging_nav .= " ⋅ " .
3744 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3745 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3747 $paging_nav .= " ⋅ next";
3753 ## ......................................................................
3754 ## functions printing or outputting HTML: div
3756 sub git_print_header_div
{
3757 my ($action, $title, $hash, $hash_base) = @_;
3760 $args{'action'} = $action;
3761 $args{'hash'} = $hash if $hash;
3762 $args{'hash_base'} = $hash_base if $hash_base;
3764 print "<div class=\"header\">\n" .
3765 $cgi->a({-href
=> href
(%args), -class => "title"},
3766 $title ?
$title : $action) .
3770 sub print_local_time
{
3771 print format_local_time
(@_);
3774 sub format_local_time
{
3777 if ($date{'hour_local'} < 6) {
3778 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3779 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3781 $localtime .= sprintf(" (%02d:%02d %s)",
3782 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3788 # Outputs the author name and date in long form
3789 sub git_print_authorship
{
3792 my $tag = $opts{-tag
} || 'div';
3793 my $author = $co->{'author_name'};
3795 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3796 print "<$tag class=\"author_date\">" .
3797 format_search_author
($author, "author", esc_html
($author)) .
3799 print_local_time
(%ad) if ($opts{-localtime});
3800 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3804 # Outputs table rows containing the full author or committer information,
3805 # in the format expected for 'commit' view (& similar).
3806 # Parameters are a commit hash reference, followed by the list of people
3807 # to output information for. If the list is empty it defaults to both
3808 # author and committer.
3809 sub git_print_authorship_rows
{
3811 # too bad we can't use @people = @_ || ('author', 'committer')
3813 @people = ('author', 'committer') unless @people;
3814 foreach my $who (@people) {
3815 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3816 print "<tr><td>$who</td><td>" .
3817 format_search_author
($co->{"${who}_name"}, $who,
3818 esc_html
($co->{"${who}_name"})) . " " .
3819 format_search_author
($co->{"${who}_email"}, $who,
3820 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3821 "</td><td rowspan=\"2\">" .
3822 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3825 "<td></td><td> $wd{'rfc2822'}";
3826 print_local_time
(%wd);
3832 sub git_print_page_path
{
3838 print "<div class=\"page_path\">";
3839 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3840 -title
=> 'tree root'}, to_utf8
("[$project]"));
3842 if (defined $name) {
3843 my @dirname = split '/', $name;
3844 my $basename = pop @dirname;
3847 foreach my $dir (@dirname) {
3848 $fullname .= ($fullname ?
'/' : '') . $dir;
3849 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3851 -title
=> $fullname}, esc_path
($dir));
3854 if (defined $type && $type eq 'blob') {
3855 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3857 -title
=> $name}, esc_path
($basename));
3858 } elsif (defined $type && $type eq 'tree') {
3859 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3861 -title
=> $name}, esc_path
($basename));
3864 print esc_path
($basename);
3867 print "<br/></div>\n";
3874 if ($opts{'-remove_title'}) {
3875 # remove title, i.e. first line of log
3878 # remove leading empty lines
3879 while (defined $log->[0] && $log->[0] eq "") {
3886 foreach my $line (@
$log) {
3887 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3890 if (! $opts{'-remove_signoff'}) {
3891 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3894 # remove signoff lines
3901 # print only one empty line
3902 # do not print empty line after signoff
3904 next if ($empty || $signoff);
3910 print format_log_line_html
($line) . "<br/>\n";
3913 if ($opts{'-final_empty_line'}) {
3914 # end with single empty line
3915 print "<br/>\n" unless $empty;
3919 # return link target (what link points to)
3920 sub git_get_link_target
{
3925 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3929 $link_target = <$fd>;
3934 return $link_target;
3937 # given link target, and the directory (basedir) the link is in,
3938 # return target of link relative to top directory (top tree);
3939 # return undef if it is not possible (including absolute links).
3940 sub normalize_link_target
{
3941 my ($link_target, $basedir) = @_;
3943 # absolute symlinks (beginning with '/') cannot be normalized
3944 return if (substr($link_target, 0, 1) eq '/');
3946 # normalize link target to path from top (root) tree (dir)
3949 $path = $basedir . '/' . $link_target;
3951 # we are in top (root) tree (dir)
3952 $path = $link_target;
3955 # remove //, /./, and /../
3957 foreach my $part (split('/', $path)) {
3958 # discard '.' and ''
3959 next if (!$part || $part eq '.');
3961 if ($part eq '..') {
3965 # link leads outside repository (outside top dir)
3969 push @path_parts, $part;
3972 $path = join('/', @path_parts);
3977 # print tree entry (row of git_tree), but without encompassing <tr> element
3978 sub git_print_tree_entry
{
3979 my ($t, $basedir, $hash_base, $have_blame) = @_;
3982 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3984 # The format of a table row is: mode list link. Where mode is
3985 # the mode of the entry, list is the name of the entry, an href,
3986 # and link is the action links of the entry.
3988 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3989 if (exists $t->{'size'}) {
3990 print "<td class=\"size\">$t->{'size'}</td>\n";
3992 if ($t->{'type'} eq "blob") {
3993 print "<td class=\"list\">" .
3994 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3995 file_name
=>"$basedir$t->{'name'}", %base_key),
3996 -class => "list"}, esc_path
($t->{'name'}));
3997 if (S_ISLNK
(oct $t->{'mode'})) {
3998 my $link_target = git_get_link_target
($t->{'hash'});
4000 my $norm_target = normalize_link_target
($link_target, $basedir);
4001 if (defined $norm_target) {
4003 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
4004 file_name
=>$norm_target),
4005 -title
=> $norm_target}, esc_path
($link_target));
4007 print " -> " . esc_path
($link_target);
4012 print "<td class=\"link\">";
4013 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
4014 file_name
=>"$basedir$t->{'name'}", %base_key)},
4018 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
4019 file_name
=>"$basedir$t->{'name'}", %base_key)},
4022 if (defined $hash_base) {
4024 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4025 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4029 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4030 file_name
=>"$basedir$t->{'name'}")},
4034 } elsif ($t->{'type'} eq "tree") {
4035 print "<td class=\"list\">";
4036 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4037 file_name
=>"$basedir$t->{'name'}",
4039 esc_path
($t->{'name'}));
4041 print "<td class=\"link\">";
4042 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4043 file_name
=>"$basedir$t->{'name'}",
4046 if (defined $hash_base) {
4048 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4049 file_name
=>"$basedir$t->{'name'}")},
4054 # unknown object: we can only present history for it
4055 # (this includes 'commit' object, i.e. submodule support)
4056 print "<td class=\"list\">" .
4057 esc_path
($t->{'name'}) .
4059 print "<td class=\"link\">";
4060 if (defined $hash_base) {
4061 print $cgi->a({-href
=> href
(action
=>"history",
4062 hash_base
=>$hash_base,
4063 file_name
=>"$basedir$t->{'name'}")},
4070 ## ......................................................................
4071 ## functions printing large fragments of HTML
4073 # get pre-image filenames for merge (combined) diff
4074 sub fill_from_file_info
{
4075 my ($diff, @parents) = @_;
4077 $diff->{'from_file'} = [ ];
4078 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4079 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4080 if ($diff->{'status'}[$i] eq 'R' ||
4081 $diff->{'status'}[$i] eq 'C') {
4082 $diff->{'from_file'}[$i] =
4083 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4090 # is current raw difftree line of file deletion
4092 my $diffinfo = shift;
4094 return $diffinfo->{'to_id'} eq ('0' x
40);
4097 # does patch correspond to [previous] difftree raw line
4098 # $diffinfo - hashref of parsed raw diff format
4099 # $patchinfo - hashref of parsed patch diff format
4100 # (the same keys as in $diffinfo)
4101 sub is_patch_split
{
4102 my ($diffinfo, $patchinfo) = @_;
4104 return defined $diffinfo && defined $patchinfo
4105 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4109 sub git_difftree_body
{
4110 my ($difftree, $hash, @parents) = @_;
4111 my ($parent) = $parents[0];
4112 my $have_blame = gitweb_check_feature
('blame');
4113 print "<div class=\"list_head\">\n";
4114 if ($#{$difftree} > 10) {
4115 print(($#{$difftree} + 1) . " files changed:\n");
4119 print "<table class=\"" .
4120 (@parents > 1 ?
"combined " : "") .
4123 # header only for combined diff in 'commitdiff' view
4124 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4127 print "<thead><tr>\n" .
4128 "<th></th><th></th>\n"; # filename, patchN link
4129 for (my $i = 0; $i < @parents; $i++) {
4130 my $par = $parents[$i];
4132 $cgi->a({-href
=> href
(action
=>"commitdiff",
4133 hash
=>$hash, hash_parent
=>$par),
4134 -title
=> 'commitdiff to parent number ' .
4135 ($i+1) . ': ' . substr($par,0,7)},
4139 print "</tr></thead>\n<tbody>\n";
4144 foreach my $line (@
{$difftree}) {
4145 my $diff = parsed_difftree_line
($line);
4148 print "<tr class=\"dark\">\n";
4150 print "<tr class=\"light\">\n";
4154 if (exists $diff->{'nparents'}) { # combined diff
4156 fill_from_file_info
($diff, @parents)
4157 unless exists $diff->{'from_file'};
4159 if (!is_deleted
($diff)) {
4160 # file exists in the result (child) commit
4162 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4163 file_name
=>$diff->{'to_file'},
4165 -class => "list"}, esc_path
($diff->{'to_file'})) .
4169 esc_path
($diff->{'to_file'}) .
4173 if ($action eq 'commitdiff') {
4176 print "<td class=\"link\">" .
4177 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4182 my $has_history = 0;
4183 my $not_deleted = 0;
4184 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4185 my $hash_parent = $parents[$i];
4186 my $from_hash = $diff->{'from_id'}[$i];
4187 my $from_path = $diff->{'from_file'}[$i];
4188 my $status = $diff->{'status'}[$i];
4190 $has_history ||= ($status ne 'A');
4191 $not_deleted ||= ($status ne 'D');
4193 if ($status eq 'A') {
4194 print "<td class=\"link\" align=\"right\"> | </td>\n";
4195 } elsif ($status eq 'D') {
4196 print "<td class=\"link\">" .
4197 $cgi->a({-href
=> href
(action
=>"blob",
4200 file_name
=>$from_path)},
4204 if ($diff->{'to_id'} eq $from_hash) {
4205 print "<td class=\"link nochange\">";
4207 print "<td class=\"link\">";
4209 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4210 hash
=>$diff->{'to_id'},
4211 hash_parent
=>$from_hash,
4213 hash_parent_base
=>$hash_parent,
4214 file_name
=>$diff->{'to_file'},
4215 file_parent
=>$from_path)},
4221 print "<td class=\"link\">";
4223 print $cgi->a({-href
=> href
(action
=>"blob",
4224 hash
=>$diff->{'to_id'},
4225 file_name
=>$diff->{'to_file'},
4228 print " | " if ($has_history);
4231 print $cgi->a({-href
=> href
(action
=>"history",
4232 file_name
=>$diff->{'to_file'},
4239 next; # instead of 'else' clause, to avoid extra indent
4241 # else ordinary diff
4243 my ($to_mode_oct, $to_mode_str, $to_file_type);
4244 my ($from_mode_oct, $from_mode_str, $from_file_type);
4245 if ($diff->{'to_mode'} ne ('0' x
6)) {
4246 $to_mode_oct = oct $diff->{'to_mode'};
4247 if (S_ISREG
($to_mode_oct)) { # only for regular file
4248 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4250 $to_file_type = file_type
($diff->{'to_mode'});
4252 if ($diff->{'from_mode'} ne ('0' x
6)) {
4253 $from_mode_oct = oct $diff->{'from_mode'};
4254 if (S_ISREG
($to_mode_oct)) { # only for regular file
4255 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4257 $from_file_type = file_type
($diff->{'from_mode'});
4260 if ($diff->{'status'} eq "A") { # created
4261 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4262 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4263 $mode_chng .= "]</span>";
4265 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4266 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4267 -class => "list"}, esc_path
($diff->{'file'}));
4269 print "<td>$mode_chng</td>\n";
4270 print "<td class=\"link\">";
4271 if ($action eq 'commitdiff') {
4274 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4277 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4278 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4282 } elsif ($diff->{'status'} eq "D") { # deleted
4283 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4285 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4286 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4287 -class => "list"}, esc_path
($diff->{'file'}));
4289 print "<td>$mode_chng</td>\n";
4290 print "<td class=\"link\">";
4291 if ($action eq 'commitdiff') {
4294 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4297 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4298 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4301 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4302 file_name
=>$diff->{'file'})},
4305 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4306 file_name
=>$diff->{'file'})},
4310 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4311 my $mode_chnge = "";
4312 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4313 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4314 if ($from_file_type ne $to_file_type) {
4315 $mode_chnge .= " from $from_file_type to $to_file_type";
4317 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4318 if ($from_mode_str && $to_mode_str) {
4319 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4320 } elsif ($to_mode_str) {
4321 $mode_chnge .= " mode: $to_mode_str";
4324 $mode_chnge .= "]</span>\n";
4327 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4328 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4329 -class => "list"}, esc_path
($diff->{'file'}));
4331 print "<td>$mode_chnge</td>\n";
4332 print "<td class=\"link\">";
4333 if ($action eq 'commitdiff') {
4336 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4338 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4339 # "commit" view and modified file (not onlu mode changed)
4340 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4341 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4342 hash_base
=>$hash, hash_parent_base
=>$parent,
4343 file_name
=>$diff->{'file'})},
4347 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4348 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4351 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4352 file_name
=>$diff->{'file'})},
4355 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4356 file_name
=>$diff->{'file'})},
4360 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4361 my %status_name = ('R' => 'moved', 'C' => 'copied');
4362 my $nstatus = $status_name{$diff->{'status'}};
4364 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4365 # mode also for directories, so we cannot use $to_mode_str
4366 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4369 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4370 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4371 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4372 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4373 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4374 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4375 -class => "list"}, esc_path
($diff->{'from_file'})) .
4376 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4377 "<td class=\"link\">";
4378 if ($action eq 'commitdiff') {
4381 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4383 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4384 # "commit" view and modified file (not only pure rename or copy)
4385 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4386 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4387 hash_base
=>$hash, hash_parent_base
=>$parent,
4388 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4392 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4393 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4396 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4397 file_name
=>$diff->{'to_file'})},
4400 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4401 file_name
=>$diff->{'to_file'})},
4405 } # we should not encounter Unmerged (U) or Unknown (X) status
4408 print "</tbody>" if $has_header;
4412 sub git_patchset_body
{
4413 my ($fd, $difftree, $hash, @hash_parents) = @_;
4414 my ($hash_parent) = $hash_parents[0];
4416 my $is_combined = (@hash_parents > 1);
4418 my $patch_number = 0;
4424 print "<div class=\"patchset\">\n";
4426 # skip to first patch
4427 while ($patch_line = <$fd>) {
4430 last if ($patch_line =~ m/^diff /);
4434 while ($patch_line) {
4436 # parse "git diff" header line
4437 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4438 # $1 is from_name, which we do not use
4439 $to_name = unquote
($2);
4440 $to_name =~ s!^b/!!;
4441 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4442 # $1 is 'cc' or 'combined', which we do not use
4443 $to_name = unquote
($2);
4448 # check if current patch belong to current raw line
4449 # and parse raw git-diff line if needed
4450 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4451 # this is continuation of a split patch
4452 print "<div class=\"patch cont\">\n";
4454 # advance raw git-diff output if needed
4455 $patch_idx++ if defined $diffinfo;
4457 # read and prepare patch information
4458 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4460 # compact combined diff output can have some patches skipped
4461 # find which patch (using pathname of result) we are at now;
4463 while ($to_name ne $diffinfo->{'to_file'}) {
4464 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4465 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4466 "</div>\n"; # class="patch"
4471 last if $patch_idx > $#$difftree;
4472 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4476 # modifies %from, %to hashes
4477 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4479 # this is first patch for raw difftree line with $patch_idx index
4480 # we index @$difftree array from 0, but number patches from 1
4481 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4485 #assert($patch_line =~ m/^diff /) if DEBUG;
4486 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4488 # print "git diff" header
4489 print format_git_diff_header_line
($patch_line, $diffinfo,
4492 # print extended diff header
4493 print "<div class=\"diff extended_header\">\n";
4495 while ($patch_line = <$fd>) {
4498 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4500 print format_extended_diff_header_line
($patch_line, $diffinfo,
4503 print "</div>\n"; # class="diff extended_header"
4505 # from-file/to-file diff header
4506 if (! $patch_line) {
4507 print "</div>\n"; # class="patch"
4510 next PATCH
if ($patch_line =~ m/^diff /);
4511 #assert($patch_line =~ m/^---/) if DEBUG;
4513 my $last_patch_line = $patch_line;
4514 $patch_line = <$fd>;
4516 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4518 print format_diff_from_to_header
($last_patch_line, $patch_line,
4519 $diffinfo, \
%from, \
%to,
4524 while ($patch_line = <$fd>) {
4527 next PATCH
if ($patch_line =~ m/^diff /);
4529 print format_diff_line
($patch_line, \
%from, \
%to);
4533 print "</div>\n"; # class="patch"
4536 # for compact combined (--cc) format, with chunk and patch simplification
4537 # the patchset might be empty, but there might be unprocessed raw lines
4538 for (++$patch_idx if $patch_number > 0;
4539 $patch_idx < @
$difftree;
4541 # read and prepare patch information
4542 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4544 # generate anchor for "patch" links in difftree / whatchanged part
4545 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4546 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4547 "</div>\n"; # class="patch"
4552 if ($patch_number == 0) {
4553 if (@hash_parents > 1) {
4554 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4556 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4560 print "</div>\n"; # class="patchset"
4563 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4565 # fills project list info (age, description, owner, forks) for each
4566 # project in the list, removing invalid projects from returned list
4567 # NOTE: modifies $projlist, but does not remove entries from it
4568 sub fill_project_list_info
{
4569 my ($projlist, $check_forks) = @_;
4572 my $show_ctags = gitweb_check_feature
('ctags');
4574 foreach my $pr (@
$projlist) {
4575 my (@activity) = git_get_last_activity
($pr->{'path'});
4576 unless (@activity) {
4579 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4580 if (!defined $pr->{'descr'}) {
4581 my $descr = git_get_project_description
($pr->{'path'}) || "";
4582 $descr = to_utf8
($descr);
4583 $pr->{'descr_long'} = $descr;
4584 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4586 if (!defined $pr->{'owner'}) {
4587 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4590 my $pname = $pr->{'path'};
4591 if (($pname =~ s/\.git$//) &&
4592 ($pname !~ /\/$/) &&
4593 (-d
"$projectroot/$pname")) {
4594 $pr->{'forks'} = "-d $projectroot/$pname";
4599 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4600 push @projects, $pr;
4606 # print 'sort by' <th> element, generating 'sort by $name' replay link
4607 # if that order is not selected
4609 print format_sort_th
(@_);
4612 sub format_sort_th
{
4613 my ($name, $order, $header) = @_;
4615 $header ||= ucfirst($name);
4617 if ($order eq $name) {
4618 $sort_th .= "<th>$header</th>\n";
4620 $sort_th .= "<th>" .
4621 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4622 -class => "header"}, $header) .
4629 sub git_project_list_body
{
4630 # actually uses global variable $project
4631 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4633 my $check_forks = gitweb_check_feature
('forks');
4634 my @projects = fill_project_list_info
($projlist, $check_forks);
4636 $order ||= $default_projects_order;
4637 $from = 0 unless defined $from;
4638 $to = $#projects if (!defined $to || $#projects < $to);
4641 project
=> { key
=> 'path', type
=> 'str' },
4642 descr
=> { key
=> 'descr_long', type
=> 'str' },
4643 owner
=> { key
=> 'owner', type
=> 'str' },
4644 age
=> { key
=> 'age', type
=> 'num' }
4646 my $oi = $order_info{$order};
4647 if ($oi->{'type'} eq 'str') {
4648 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4650 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4653 my $show_ctags = gitweb_check_feature
('ctags');
4656 foreach my $p (@projects) {
4657 foreach my $ct (keys %{$p->{'ctags'}}) {
4658 $ctags{$ct} += $p->{'ctags'}->{$ct};
4661 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4662 print git_show_project_tagcloud
($cloud, 64);
4664 print "<table class=\"project_list\">\n";
4665 unless ($no_header) {
4668 print "<th></th>\n";
4670 print_sort_th
('project', $order, 'Project');
4671 print_sort_th
('descr', $order, 'Description');
4672 print_sort_th
('owner', $order, 'Owner');
4673 print_sort_th
('age', $order, 'Last Change');
4674 print "<th></th>\n" . # for links
4678 my $tagfilter = $cgi->param('by_tag');
4679 for (my $i = $from; $i <= $to; $i++) {
4680 my $pr = $projects[$i];
4682 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4683 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4684 and not $pr->{'descr_long'} =~ /$searchtext/;
4685 # Weed out forks or non-matching entries of search
4687 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4688 $forkbase="^$forkbase" if $forkbase;
4689 next if not $searchtext and not $tagfilter and $show_ctags
4690 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4694 print "<tr class=\"dark\">\n";
4696 print "<tr class=\"light\">\n";
4701 if ($pr->{'forks'}) {
4702 print "<!-- $pr->{'forks'} -->\n";
4703 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4707 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4708 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4709 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4710 -class => "list", -title
=> $pr->{'descr_long'}},
4711 esc_html
($pr->{'descr'})) . "</td>\n" .
4712 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4713 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4714 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4715 "<td class=\"link\">" .
4716 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4717 #$cgi->a({-href => href(project=>$pr->{'path'}, action=>"bugtrack")}, "bugtrack") . " | " .
4718 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4719 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4720 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4721 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4725 if (defined $extra) {
4728 print "<td></td>\n";
4730 print "<td colspan=\"5\">$extra</td>\n" .
4737 # uses global variable $project
4738 my ($commitlist, $from, $to, $refs, $extra) = @_;
4740 $from = 0 unless defined $from;
4741 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4743 for (my $i = 0; $i <= $to; $i++) {
4744 my %co = %{$commitlist->[$i]};
4746 my $commit = $co{'id'};
4747 my $ref = format_ref_marker
($refs, $commit);
4748 my %ad = parse_date
($co{'author_epoch'});
4749 git_print_header_div
('commit',
4750 "<span class=\"age\">$co{'age_string'}</span>" .
4751 esc_html
($co{'title'}) . $ref,
4753 print "<div class=\"title_text\">\n" .
4754 "<div class=\"log_link\">\n" .
4755 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4757 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4759 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4762 git_print_authorship
(\
%co, -tag
=> 'span');
4763 print "<br/>\n</div>\n";
4765 print "<div class=\"log_body\">\n";
4766 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4770 print "<div class=\"page_nav\">\n";
4776 sub git_shortlog_body
{
4777 # uses global variable $project
4778 my ($commitlist, $from, $to, $refs, $extra, $file_name, $file_hash, $ftype, $allrefs) = @_;
4780 $from = 0 unless defined $from;
4781 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4783 print "<table class=\"shortlog\" cellspacing=\"0\" cellpadding=\"0\">\n";
4785 my $head = git_get_head_hash
($project);
4787 if (defined $allrefs && $allrefs == 1) {
4788 $graph_hash = "all";
4790 if (!defined $hash) {
4793 if(!defined $graph_hash) {
4794 $graph_hash = $hash;
4796 if (!defined $page) {
4799 my $graph_rand = int(rand(99999));
4800 print "<tr class=\"header\">\n";
4801 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";
4802 print "<td valign=\"bottom\"><b>Author</b></td>\n";
4803 print "<td valign=\"bottom\"><b>Commit</b></td>\n";
4804 print "<td></td>\n";
4806 for (my $i = $from; $i <= $to; $i++) {
4807 my %co = %{$commitlist->[$i]};
4808 my $commit = $co{'id'};
4810 my $ref = format_ref_marker
($refs, $commit);
4812 print "<tr class=\"dark\">\n";
4814 print "<tr class=\"light\">\n";
4817 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4818 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>";
4819 print "<td class=\"". age_class
($co{'age'}) . "\" title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4820 format_author_html
('td', \
%co, 10) . "<td>";
4821 print format_subject_html
($co{'title'}, $co{'title_short'},
4822 href
(action
=>"commit", hash
=>$commit), $ref);
4824 "<td class=\"link\">" .
4825 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4826 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4827 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4828 my $snapshot_links = format_snapshot_links
($commit);
4829 if (defined $snapshot_links) {
4830 print " | " . $snapshot_links;
4835 if (defined $extra) {
4837 "<td colspan=\"4\">$extra</td>\n" .
4843 sub git_history_body
{
4844 # Warning: assumes constant type (blob or tree) during history
4845 my ($commitlist, $from, $to, $refs, $extra,
4846 $file_name, $file_hash, $ftype) = @_;
4848 $from = 0 unless defined $from;
4849 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4851 print "<table class=\"history\">\n";
4853 for (my $i = $from; $i <= $to; $i++) {
4854 my %co = %{$commitlist->[$i]};
4858 my $commit = $co{'id'};
4860 my $ref = format_ref_marker
($refs, $commit);
4863 print "<tr class=\"dark\">\n";
4865 print "<tr class=\"light\">\n";
4868 print "<td class=\"". age_class
($co{'age'}) . "\" title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4869 # shortlog: format_author_html('td', \%co, 10)
4870 format_author_html
('td', \
%co, 15, 3) . "<td>";
4871 # originally git_history used chop_str($co{'title'}, 50)
4872 print format_subject_html
($co{'title'}, $co{'title_short'},
4873 href
(action
=>"commit", hash
=>$commit), $ref);
4875 "<td class=\"link\">" .
4876 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4877 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4879 if ($ftype eq 'blob') {
4880 my $blob_current = $file_hash;
4881 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4882 if (defined $blob_current && defined $blob_parent &&
4883 $blob_current ne $blob_parent) {
4885 $cgi->a({-href
=> href
(action
=>"blobdiff",
4886 hash
=>$blob_current, hash_parent
=>$blob_parent,
4887 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4888 file_name
=>$file_name)},
4895 if (defined $extra) {
4897 "<td colspan=\"4\">$extra</td>\n" .
4904 # uses global variable $project
4905 my ($taglist, $from, $to, $extra) = @_;
4906 $from = 0 unless defined $from;
4907 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4909 print "<table class=\"tags\">\n";
4911 for (my $i = $from; $i <= $to; $i++) {
4912 my $entry = $taglist->[$i];
4914 my $comment = $tag{'subject'};
4916 if (defined $comment) {
4917 $comment_short = chop_str
($comment, 30, 5);
4920 print "<tr class=\"dark\">\n";
4922 print "<tr class=\"light\">\n";
4925 if (defined $tag{'age'}) {
4926 print "<td><i>$tag{'age'}</i></td>\n";
4928 print "<td></td>\n";
4931 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4932 -class => "list name"}, esc_html
($tag{'name'})) .
4935 if (defined $comment) {
4936 print format_subject_html
($comment, $comment_short,
4937 href
(action
=>"tag", hash
=>$tag{'id'}));
4940 "<td class=\"selflink\">";
4941 if ($tag{'type'} eq "tag") {
4942 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4947 "<td class=\"link\">" . " | " .
4948 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4949 if ($tag{'reftype'} eq "commit") {
4950 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4951 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4952 } elsif ($tag{'reftype'} eq "blob") {
4953 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4958 if (defined $extra) {
4960 "<td colspan=\"5\">$extra</td>\n" .
4966 sub git_heads_body
{
4967 # uses global variable $project
4968 my ($headlist, $head, $from, $to, $extra) = @_;
4969 $from = 0 unless defined $from;
4970 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4972 print "<table class=\"heads\">\n";
4974 for (my $i = $from; $i <= $to; $i++) {
4975 my $entry = $headlist->[$i];
4977 my $curr = $ref{'id'} eq $head;
4979 print "<tr class=\"dark\">\n";
4981 print "<tr class=\"light\">\n";
4984 print "<td><i>$ref{'age'}</i></td>\n" .
4985 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4986 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4987 -class => "list name"},esc_html
($ref{'name'})) .
4989 "<td class=\"link\">" .
4990 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4991 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4992 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4996 if (defined $extra) {
4998 "<td colspan=\"3\">$extra</td>\n" .
5004 sub git_search_grep_body
{
5005 my ($commitlist, $from, $to, $extra) = @_;
5006 $from = 0 unless defined $from;
5007 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
5009 print "<table class=\"commit_search\">\n";
5011 for (my $i = $from; $i <= $to; $i++) {
5012 my %co = %{$commitlist->[$i]};
5016 my $commit = $co{'id'};
5018 print "<tr class=\"dark\">\n";
5020 print "<tr class=\"light\">\n";
5023 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5024 format_author_html
('td', \
%co, 15, 5) .
5026 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5027 -class => "list subject"},
5028 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5029 my $comment = $co{'comment'};
5030 foreach my $line (@
$comment) {
5031 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
5032 my ($lead, $match, $trail) = ($1, $2, $3);
5033 $match = chop_str
($match, 70, 5, 'center');
5034 my $contextlen = int((80 - length($match))/2);
5035 $contextlen = 30 if ($contextlen > 30);
5036 $lead = chop_str
($lead, $contextlen, 10, 'left');
5037 $trail = chop_str
($trail, $contextlen, 10, 'right');
5039 $lead = esc_html
($lead);
5040 $match = esc_html
($match);
5041 $trail = esc_html
($trail);
5043 print "$lead<span class=\"match\">$match</span>$trail<br />";
5047 "<td class=\"link\">" .
5048 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5050 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5052 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5056 if (defined $extra) {
5058 "<td colspan=\"3\">$extra</td>\n" .
5064 ## ======================================================================
5065 ## ======================================================================
5068 sub git_project_list
{
5069 my $order = $input_params{'order'};
5070 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5071 die_error
(400, "Unknown order parameter");
5074 my @list = git_get_projects_list
();
5076 die_error
(404, "No projects found");
5080 if (defined $home_text && -f
$home_text) {
5081 print "<div class=\"index_include\">\n";
5082 insert_file
($home_text);
5085 print $cgi->startform(-method
=> "get") .
5086 "<p class=\"projsearch\">Search:\n" .
5087 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5089 $cgi->end_form() . "\n";
5090 git_project_list_body
(\
@list, $order);
5095 my $order = $input_params{'order'};
5096 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5097 die_error
(400, "Unknown order parameter");
5100 my @list = git_get_projects_list
($project);
5102 die_error
(404, "No forks found");
5106 git_print_page_nav
('','');
5107 git_print_header_div
('summary', "$project forks");
5108 git_project_list_body
(\
@list, $order);
5112 sub git_project_index
{
5113 my @projects = git_get_projects_list
($project);
5116 -type
=> 'text/plain',
5117 -charset
=> 'utf-8',
5118 -content_disposition
=> 'inline; filename="index.aux"');
5120 foreach my $pr (@projects) {
5121 if (!exists $pr->{'owner'}) {
5122 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5125 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5126 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5127 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5128 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5132 print "$path $owner\n";
5135 sub git_project_index2
{
5136 my @projects = git_get_projects_list
($project);
5139 -type
=> 'text/plain',
5140 -charset
=> 'utf-8',
5141 -content_disposition
=> 'inline; filename="index.aux"');
5143 foreach my $pr (@projects) {
5144 if (!exists $pr->{'owner'}) {
5145 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5148 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5149 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5150 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5151 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5159 my $dl = get
("http://git.nexus-irc.de/git_download.php");
5161 print "<div class=\"title\">Downloads</div>\n";
5166 sub git_project_bugtracker
{
5167 my $descr = git_get_project_description
($project) || "none";
5168 my $bugtrack = get
("http://git.nexus-irc.de/git_bugtrack.php?p=".$project);
5169 my %co = parse_commit
("HEAD");
5170 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5171 my $head = $co{'id'};
5172 my $owner = git_get_project_owner
($project);
5173 my $version = get
("http://git.nexus-irc.de/git_version.php?git=".$project);
5175 git_print_page_nav
('bugtracker','', $head);
5176 print "<div class=\"title\"> </div>\n";
5177 print "<table class=\"projects_list\">\n" .
5178 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5179 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5180 if (defined $cd{'rfc2822'}) {
5181 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5183 my $url_tag = "URL";
5184 my @url_list = git_get_project_url_list
($project);
5185 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5186 foreach my $git_url (@url_list) {
5187 next unless $git_url;
5188 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5191 print "<tr id=\"metadata_owner\"><td>version</td><td>" . esc_html
($version) . "</td></tr>\n";
5193 git_print_header_div
('bugtracker');
5199 my $descr = git_get_project_description
($project) || "none";
5200 my %co = parse_commit
("HEAD");
5201 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5202 my $head = $co{'id'};
5204 my $owner = git_get_project_owner
($project);
5206 my $version = get
("http://git.nexus-irc.de/git_version.php?git=".$project);
5207 my $download = get
("http://git.nexus-irc.de/git_download.php?p=".$project);
5209 my $refs = git_get_references
();
5210 # These get_*_list functions return one more to allow us to see if
5211 # there are more ...
5212 my @taglist = git_get_tags_list
(16);
5213 my @headlist = git_get_heads_list
(16);
5215 my $check_forks = gitweb_check_feature
('forks');
5218 @forklist = git_get_projects_list
($project);
5222 git_print_page_nav
('summary','', $head);
5223 print "<div class=\"title\"> </div>\n";
5224 print "<table class=\"projects_list\">\n" .
5225 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5226 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5227 if (defined $cd{'rfc2822'}) {
5228 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5231 # use per project git URL list in $projectroot/$project/cloneurl
5232 # or make project git URL from git base URL and project name
5233 my $url_tag = "URL";
5234 my @url_list = git_get_project_url_list
($project);
5235 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5236 foreach my $git_url (@url_list) {
5237 next unless $git_url;
5238 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5241 print "<tr id=\"metadata_owner\"><td>version</td><td>" . esc_html
($version) . "</td></tr>\n";
5242 print "<tr id=\"metadata_owner\"><td>download</td><td>" . $download . "</td></tr>\n";
5244 my $show_ctags = gitweb_check_feature
('ctags');
5246 my $ctags = git_get_project_ctags
($project);
5247 my $cloud = git_populate_project_tagcloud
($ctags);
5248 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5249 print "</td>\n<td>" unless %$ctags;
5250 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5251 print "</td>\n<td>" if %$ctags;
5252 print git_show_project_tagcloud
($cloud, 48);
5258 # If XSS prevention is on, we don't include README.html.
5259 # TODO: Allow a readme in some safe format.
5260 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5261 print "<div class=\"title\">readme</div>\n" .
5262 "<div class=\"readme\">\n";
5263 insert_file
("$projectroot/$project/README.html");
5264 print "\n</div>\n"; # class="readme"
5267 # we need to request one more than 16 (0..15) to check if
5269 my @commitlist = $head ? parse_commits
("--all", 17) : ();
5271 git_print_header_div
('shortlog');
5272 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5273 $#commitlist <= 15 ?
undef :
5274 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."), 0, 0, 0, 1);
5278 git_print_header_div
('tags');
5279 git_tags_body
(\
@taglist, 0, 15,
5280 $#taglist <= 15 ?
undef :
5281 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5285 git_print_header_div
('heads');
5286 git_heads_body
(\
@headlist, $head, 0, 15,
5287 $#headlist <= 15 ?
undef :
5288 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5292 git_print_header_div
('forks');
5293 git_project_list_body
(\
@forklist, 'age', 0, 15,
5294 $#forklist <= 15 ?
undef :
5295 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5303 my $head = git_get_head_hash
($project);
5305 git_print_page_nav
('','', $head,undef,$head);
5306 my %tag = parse_tag
($hash);
5309 die_error
(404, "Unknown tag object");
5312 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5313 print "<div class=\"title_text\">\n" .
5314 "<table class=\"object_header\">\n" .
5316 "<td>object</td>\n" .
5317 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5318 $tag{'object'}) . "</td>\n" .
5319 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5320 $tag{'type'}) . "</td>\n" .
5322 if (defined($tag{'author'})) {
5323 git_print_authorship_rows
(\
%tag, 'author');
5325 print "</table>\n\n" .
5327 print "<div class=\"page_body\">";
5328 my $comment = $tag{'comment'};
5329 foreach my $line (@
$comment) {
5331 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5337 sub git_blame_common
{
5338 my $format = shift || 'porcelain';
5339 if ($format eq 'porcelain' && $cgi->param('js')) {
5340 $format = 'incremental';
5341 $action = 'blame_incremental'; # for page title etc
5345 gitweb_check_feature
('blame')
5346 or die_error
(403, "Blame view not allowed");
5349 die_error
(400, "No file name given") unless $file_name;
5350 $hash_base ||= git_get_head_hash
($project);
5351 die_error
(404, "Couldn't find base commit") unless $hash_base;
5352 my %co = parse_commit
($hash_base)
5353 or die_error
(404, "Commit not found");
5355 if (!defined $hash) {
5356 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5357 or die_error
(404, "Error looking up file");
5359 $ftype = git_get_type
($hash);
5360 if ($ftype !~ "blob") {
5361 die_error
(400, "Object is not a blob");
5366 if ($format eq 'incremental') {
5367 # get file contents (as base)
5368 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5369 or die_error
(500, "Open git-cat-file failed");
5370 } elsif ($format eq 'data') {
5371 # run git-blame --incremental
5372 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5373 $hash_base, "--", $file_name
5374 or die_error
(500, "Open git-blame --incremental failed");
5376 # run git-blame --porcelain
5377 open $fd, "-|", git_cmd
(), "blame", '-p',
5378 $hash_base, '--', $file_name
5379 or die_error
(500, "Open git-blame --porcelain failed");
5382 # incremental blame data returns early
5383 if ($format eq 'data') {
5385 -type
=>"text/plain", -charset
=> "utf-8",
5386 -status
=> "200 OK");
5387 local $| = 1; # output autoflush
5390 or print "ERROR $!\n";
5393 if (defined $t0 && gitweb_check_feature
('timed')) {
5395 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5396 ' '.$number_of_git_cmds;
5406 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5409 if ($format eq 'incremental') {
5411 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5412 "blame") . " (non-incremental)";
5415 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5416 "blame") . " (incremental)";
5420 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5423 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5425 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5426 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5427 git_print_page_path
($file_name, $ftype, $hash_base);
5430 if ($format eq 'incremental') {
5431 print "<noscript>\n<div class=\"error\"><center><b>\n".
5432 "This page requires JavaScript to run.\n Use ".
5433 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5436 "</b></center></div>\n</noscript>\n";
5438 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5441 print qq!<div
class="page_body">\n!;
5442 print qq!<div id
="progress_info">... / ...</div
>\n!
5443 if ($format eq 'incremental');
5444 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5445 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5447 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5451 my @rev_color = qw(light dark);
5452 my $num_colors = scalar(@rev_color);
5453 my $current_color = 0;
5455 if ($format eq 'incremental') {
5456 my $color_class = $rev_color[$current_color];
5461 while (my $line = <$fd>) {
5465 print qq!<tr id
="l$linenr" class="$color_class">!.
5466 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5467 qq!<td
class="linenr">!.
5468 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5469 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5473 } else { # porcelain, i.e. ordinary blame
5474 my %metainfo = (); # saves information about commits
5478 while (my $line = <$fd>) {
5480 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5481 # no <lines in group> for subsequent lines in group of lines
5482 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5483 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5484 if (!exists $metainfo{$full_rev}) {
5485 $metainfo{$full_rev} = { 'nprevious' => 0 };
5487 my $meta = $metainfo{$full_rev};
5489 while ($data = <$fd>) {
5491 last if ($data =~ s/^\t//); # contents of line
5492 if ($data =~ /^(\S+)(?: (.*))?$/) {
5493 $meta->{$1} = $2 unless exists $meta->{$1};
5495 if ($data =~ /^previous /) {
5496 $meta->{'nprevious'}++;
5499 my $short_rev = substr($full_rev, 0, 8);
5500 my $author = $meta->{'author'};
5502 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5503 my $date = $date{'iso-tz'};
5505 $current_color = ($current_color + 1) % $num_colors;
5507 my $tr_class = $rev_color[$current_color];
5508 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5509 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5510 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5511 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5513 print "<td class=\"sha1\"";
5514 print " title=\"". esc_html
($author) . ", $date\"";
5515 print " rowspan=\"$group_size\"" if ($group_size > 1);
5517 print $cgi->a({-href
=> href
(action
=>"commit",
5519 file_name
=>$file_name)},
5520 esc_html
($short_rev));
5521 if ($group_size >= 2) {
5522 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5523 if (@author_initials) {
5525 esc_html
(join('', @author_initials));
5531 # 'previous' <sha1 of parent commit> <filename at commit>
5532 if (exists $meta->{'previous'} &&
5533 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5534 $meta->{'parent'} = $1;
5535 $meta->{'file_parent'} = unquote
($2);
5538 exists($meta->{'parent'}) ?
5539 $meta->{'parent'} : $full_rev;
5540 my $linenr_filename =
5541 exists($meta->{'file_parent'}) ?
5542 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5543 my $blamed = href
(action
=> 'blame',
5544 file_name
=> $linenr_filename,
5545 hash_base
=> $linenr_commit);
5546 print "<td class=\"linenr\">";
5547 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5548 -class => "linenr" },
5551 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5559 "</table>\n"; # class="blame"
5560 print "</div>\n"; # class="blame_body"
5562 or print "Reading blob failed\n";
5571 sub git_blame_incremental
{
5572 git_blame_common
('incremental');
5575 sub git_blame_data
{
5576 git_blame_common
('data');
5580 my $head = git_get_head_hash
($project);
5582 git_print_page_nav
('','', $head,undef,$head);
5583 git_print_header_div
('summary', $project);
5585 my @tagslist = git_get_tags_list
();
5587 git_tags_body
(\
@tagslist);
5593 my $head = git_get_head_hash
($project);
5595 git_print_page_nav
('','', $head,undef,$head);
5596 git_print_header_div
('summary', $project);
5598 my @headslist = git_get_heads_list
();
5600 git_heads_body
(\
@headslist, $head);
5605 sub git_blob_plain
{
5609 if (!defined $hash) {
5610 if (defined $file_name) {
5611 my $base = $hash_base || git_get_head_hash
($project);
5612 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5613 or die_error
(404, "Cannot find file");
5615 die_error
(400, "No file name defined");
5617 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5618 # blobs defined by non-textual hash id's can be cached
5622 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5623 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5625 # content-type (can include charset)
5626 $type = blob_contenttype
($fd, $file_name, $type);
5628 # "save as" filename, even when no $file_name is given
5629 my $save_as = "$hash";
5630 if (defined $file_name) {
5631 $save_as = $file_name;
5632 } elsif ($type =~ m/^text\//) {
5636 # With XSS prevention on, blobs of all types except a few known safe
5637 # ones are served with "Content-Disposition: attachment" to make sure
5638 # they don't run in our security domain. For certain image types,
5639 # blob view writes an <img> tag referring to blob_plain view, and we
5640 # want to be sure not to break that by serving the image as an
5641 # attachment (though Firefox 3 doesn't seem to care).
5642 my $sandbox = $prevent_xss &&
5643 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5647 -expires
=> $expires,
5648 -content_disposition
=>
5649 ($sandbox ?
'attachment' : 'inline')
5650 . '; filename="' . $save_as . '"');
5652 binmode STDOUT
, ':raw';
5654 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5661 if (!defined $hash) {
5662 if (defined $file_name) {
5663 my $base = $hash_base || git_get_head_hash
($project);
5664 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5665 or die_error
(404, "Cannot find file");
5667 die_error
(400, "No file name defined");
5669 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5670 # blobs defined by non-textual hash id's can be cached
5674 my $have_blame = gitweb_check_feature
('blame');
5675 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5676 or die_error
(500, "Couldn't cat $file_name, $hash");
5677 my $mimetype = blob_mimetype
($fd, $file_name);
5678 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5679 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5681 return git_blob_plain
($mimetype);
5683 # we can have blame only for text/* mimetype
5684 $have_blame &&= ($mimetype =~ m!^text/!);
5686 my $highlight = gitweb_check_feature
('highlight');
5687 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5688 $fd = run_highlighter
($fd, $highlight, $syntax)
5691 git_header_html
(undef, $expires);
5692 my $formats_nav = '';
5693 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5694 if (defined $file_name) {
5697 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5702 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5705 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5708 $cgi->a({-href
=> href
(action
=>"blob",
5709 hash_base
=>"HEAD", file_name
=>$file_name)},
5713 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5716 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5717 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5719 print "<div class=\"page_nav\">\n" .
5720 "<br/><br/></div>\n" .
5721 "<div class=\"title\">".esc_html
($hash)."</div>\n";
5723 git_print_page_path
($file_name, "blob", $hash_base);
5724 print "<div class=\"page_body\">\n";
5725 if ($mimetype =~ m!^image/!) {
5726 print qq!<img type
="!.esc_attr($mimetype).qq!"!;
5728 print qq! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
5731 href(action=>"blob_plain
", hash=>$hash,
5732 hash_base=>$hash_base, file_name=>$file_name) .
5736 while (my $line = <$fd>) {
5739 $line = untabify
($line);
5740 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5741 $nr, esc_attr
(href
(-replay
=> 1)), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5745 or print "Reading blob failed.\n";
5751 if (!defined $hash_base) {
5752 $hash_base = "HEAD";
5754 if (!defined $hash) {
5755 if (defined $file_name) {
5756 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5761 die_error
(404, "No such tree") unless defined($hash);
5763 my $show_sizes = gitweb_check_feature
('show-sizes');
5764 my $have_blame = gitweb_check_feature
('blame');
5769 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5770 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5771 or die_error
(500, "Open git-ls-tree failed");
5772 @entries = map { chomp; $_ } <$fd>;
5774 or die_error
(404, "Reading tree failed");
5777 my $refs = git_get_references
();
5778 my $ref = format_ref_marker
($refs, $hash_base);
5781 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5783 if (defined $file_name) {
5785 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5787 $cgi->a({-href
=> href
(action
=>"tree",
5788 hash_base
=>"HEAD", file_name
=>$file_name)},
5791 my $snapshot_links = format_snapshot_links
($hash);
5792 if (defined $snapshot_links) {
5793 # FIXME: Should be available when we have no hash base as well.
5794 push @views_nav, $snapshot_links;
5796 git_print_page_nav
('tree','', $hash_base, undef, undef,
5797 join(' | ', @views_nav));
5798 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5801 print "<div class=\"page_nav\">\n";
5802 print "<br/><br/></div>\n";
5803 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
5805 if (defined $file_name) {
5806 $basedir = $file_name;
5807 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5810 git_print_page_path
($file_name, 'tree', $hash_base);
5812 print "<div class=\"page_body\">\n";
5813 print "<table class=\"tree\">\n";
5815 # '..' (top directory) link if possible
5816 if (defined $hash_base &&
5817 defined $file_name && $file_name =~ m![^/]+$!) {
5819 print "<tr class=\"dark\">\n";
5821 print "<tr class=\"light\">\n";
5825 my $up = $file_name;
5826 $up =~ s!/?[^/]+$!!;
5827 undef $up unless $up;
5828 # based on git_print_tree_entry
5829 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5830 print '<td class="size"> </td>'."\n" if $show_sizes;
5831 print '<td class="list">';
5832 print $cgi->a({-href
=> href
(action
=>"tree",
5833 hash_base
=>$hash_base,
5837 print "<td class=\"link\"></td>\n";
5841 foreach my $line (@entries) {
5842 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5845 print "<tr class=\"dark\">\n";
5847 print "<tr class=\"light\">\n";
5851 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5855 print "</table>\n" .
5861 my ($project, $hash) = @_;
5863 # path/to/project.git -> project
5864 # path/to/project/.git -> project
5865 my $name = to_utf8
($project);
5866 $name =~ s
,([^/])/*\
.git
$,$1,;
5867 $name = basename
($name);
5869 $name =~ s/[[:cntrl:]]/?/g;
5872 if ($hash =~ /^[0-9a-fA-F]+$/) {
5873 # shorten SHA-1 hash
5874 my $full_hash = git_get_full_hash
($project, $hash);
5875 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5876 $ver = git_get_short_hash
($project, $hash);
5878 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5879 # tags don't need shortened SHA-1 hash
5882 # branches and other need shortened SHA-1 hash
5883 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5886 $ver .= '-' . git_get_short_hash
($project, $hash);
5888 # in case of hierarchical branch names
5891 # name = project-version_string
5892 $name = "$name-$ver";
5894 return wantarray ?
($name, $name) : $name;
5898 my $format = $input_params{'snapshot_format'};
5899 if (!@snapshot_fmts) {
5900 die_error
(403, "Snapshots not allowed");
5902 # default to first supported snapshot format
5903 $format ||= $snapshot_fmts[0];
5904 if ($format !~ m/^[a-z0-9]+$/) {
5905 die_error
(400, "Invalid snapshot format parameter");
5906 } elsif (!exists($known_snapshot_formats{$format})) {
5907 die_error
(400, "Unknown snapshot format");
5908 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5909 die_error
(403, "Snapshot format not allowed");
5910 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5911 die_error
(403, "Unsupported snapshot format");
5914 my $type = git_get_type
("$hash^{}");
5916 die_error
(404, 'Object does not exist');
5917 } elsif ($type eq 'blob') {
5918 die_error
(400, 'Object is not a tree-ish');
5921 my ($name, $prefix) = snapshot_name
($project, $hash);
5922 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5923 my $cmd = quote_command
(
5924 git_cmd
(), 'archive',
5925 "--format=$known_snapshot_formats{$format}{'format'}",
5926 "--prefix=$prefix/", $hash);
5927 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5928 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5931 $filename =~ s/(["\\])/\\$1/g;
5933 -type
=> $known_snapshot_formats{$format}{'type'},
5934 -content_disposition
=> 'inline; filename="' . $filename . '"',
5935 -status
=> '200 OK');
5937 open my $fd, "-|", $cmd
5938 or die_error
(500, "Execute git-archive failed");
5939 binmode STDOUT
, ':raw';
5941 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5945 sub git_log_generic
{
5946 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5948 my $head = git_get_head_hash
($project);
5950 if (!defined $base) {
5954 if (!defined $page) {
5957 my $refs = git_get_references
();
5959 my $commit_hash = $base;
5960 if (defined $allrefs) {
5961 $commit_hash = "--all";
5963 if (defined $parent) {
5964 $commit_hash = "$parent..$base";
5967 parse_commits
($commit_hash, 101, (100 * $page),
5968 defined $file_name ?
($file_name, "--full-history") : ());
5971 if (!defined $file_hash && defined $file_name) {
5972 # some commits could have deleted file in question,
5973 # and not have it in tree, but one of them has to have it
5974 for (my $i = 0; $i < @commitlist; $i++) {
5975 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5976 last if defined $file_hash;
5979 if (defined $file_hash) {
5980 $ftype = git_get_type
($file_hash);
5982 if (defined $file_name && !defined $ftype) {
5983 die_error
(500, "Unknown type of object");
5986 if (defined $file_name) {
5987 %co = parse_commit
($base)
5988 or die_error
(404, "Unknown commit object");
5992 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5994 if ($#commitlist >= 100) {
5996 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5997 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5999 my $patch_max = gitweb_get_feature
('patches');
6000 if ($patch_max && !defined $file_name) {
6001 if ($patch_max < 0 || @commitlist <= $patch_max) {
6002 $paging_nav .= " ⋅ " .
6003 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6009 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
6010 if (defined $file_name) {
6011 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
6013 git_print_header_div
('summary', $project)
6015 git_print_page_path
($file_name, $ftype, $hash_base)
6016 if (defined $file_name);
6018 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
6019 $file_name, $file_hash, $ftype, $allrefs);
6025 git_log_generic
('log', \
&git_log_body
,
6026 $hash, $hash_parent);
6030 $hash ||= $hash_base || "HEAD";
6031 my %co = parse_commit
($hash)
6032 or die_error
(404, "Unknown commit object");
6034 my $parent = $co{'parent'};
6035 my $parents = $co{'parents'}; # listref
6037 # we need to prepare $formats_nav before any parameter munging
6039 if (!defined $parent) {
6041 $formats_nav .= '(initial)';
6042 } elsif (@
$parents == 1) {
6043 # single parent commit
6046 $cgi->a({-href
=> href
(action
=>"commit",
6048 esc_html
(substr($parent, 0, 7))) .
6055 $cgi->a({-href
=> href
(action
=>"commit",
6057 esc_html
(substr($_, 0, 7)));
6061 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
6062 $formats_nav .= " | " .
6063 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6067 if (!defined $parent) {
6071 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
6073 (@
$parents <= 1 ?
$parent : '-c'),
6075 or die_error
(500, "Open git-diff-tree failed");
6076 @difftree = map { chomp; $_ } <$fd>;
6077 close $fd or die_error
(404, "Reading git-diff-tree failed");
6079 # non-textual hash id's can be cached
6081 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6084 my $refs = git_get_references
();
6085 my $ref = format_ref_marker
($refs, $co{'id'});
6087 git_header_html
(undef, $expires);
6088 git_print_page_nav
('commit', '',
6089 $hash, $co{'tree'}, $hash,
6092 if (defined $co{'parent'}) {
6093 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
6095 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
6097 print "<div class=\"title_text\">\n" .
6098 "<table class=\"object_header\">\n";
6099 git_print_authorship_rows
(\
%co);
6100 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
6103 "<td class=\"sha1\">" .
6104 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
6105 class => "list"}, $co{'tree'}) .
6107 "<td class=\"link\">" .
6108 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
6110 my $snapshot_links = format_snapshot_links
($hash);
6111 if (defined $snapshot_links) {
6112 print " | " . $snapshot_links;
6117 foreach my $par (@
$parents) {
6120 "<td class=\"sha1\">" .
6121 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6122 class => "list"}, $par) .
6124 "<td class=\"link\">" .
6125 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6127 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6134 print "<div class=\"page_body\">\n";
6135 git_print_log
($co{'comment'});
6138 git_difftree_body
(\
@difftree, $hash, @
$parents);
6144 # object is defined by:
6145 # - hash or hash_base alone
6146 # - hash_base and file_name
6149 # - hash or hash_base alone
6150 if ($hash || ($hash_base && !defined $file_name)) {
6151 my $object_id = $hash || $hash_base;
6153 open my $fd, "-|", quote_command
(
6154 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6155 or die_error
(404, "Object does not exist");
6159 or die_error
(404, "Object does not exist");
6161 # - hash_base and file_name
6162 } elsif ($hash_base && defined $file_name) {
6163 $file_name =~ s
,/+$,,;
6165 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6166 or die_error
(404, "Base object does not exist");
6168 # here errors should not hapen
6169 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6170 or die_error
(500, "Open git-ls-tree failed");
6174 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6175 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6176 die_error
(404, "File or directory for given base does not exist");
6181 die_error
(400, "Not enough information to find object");
6184 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6185 hash
=>$hash, hash_base
=>$hash_base,
6186 file_name
=>$file_name),
6187 -status
=> '302 Found');
6191 my $format = shift || 'html';
6198 # preparing $fd and %diffinfo for git_patchset_body
6200 if (defined $hash_base && defined $hash_parent_base) {
6201 if (defined $file_name) {
6203 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6204 $hash_parent_base, $hash_base,
6205 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6206 or die_error
(500, "Open git-diff-tree failed");
6207 @difftree = map { chomp; $_ } <$fd>;
6209 or die_error
(404, "Reading git-diff-tree failed");
6211 or die_error
(404, "Blob diff not found");
6213 } elsif (defined $hash &&
6214 $hash =~ /[0-9a-fA-F]{40}/) {
6215 # try to find filename from $hash
6217 # read filtered raw output
6218 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6219 $hash_parent_base, $hash_base, "--"
6220 or die_error
(500, "Open git-diff-tree failed");
6222 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6224 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6225 map { chomp; $_ } <$fd>;
6227 or die_error
(404, "Reading git-diff-tree failed");
6229 or die_error
(404, "Blob diff not found");
6232 die_error
(400, "Missing one of the blob diff parameters");
6235 if (@difftree > 1) {
6236 die_error
(400, "Ambiguous blob diff specification");
6239 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6240 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6241 $file_name ||= $diffinfo{'to_file'};
6243 $hash_parent ||= $diffinfo{'from_id'};
6244 $hash ||= $diffinfo{'to_id'};
6246 # non-textual hash id's can be cached
6247 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6248 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6253 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6254 '-p', ($format eq 'html' ?
"--full-index" : ()),
6255 $hash_parent_base, $hash_base,
6256 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6257 or die_error
(500, "Open git-diff-tree failed");
6260 # old/legacy style URI -- not generated anymore since 1.4.3.
6262 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6266 if ($format eq 'html') {
6268 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6270 git_header_html
(undef, $expires);
6271 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6272 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6273 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6275 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6276 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
6278 if (defined $file_name) {
6279 git_print_page_path
($file_name, "blob", $hash_base);
6281 print "<div class=\"page_path\"></div>\n";
6284 } elsif ($format eq 'plain') {
6286 -type
=> 'text/plain',
6287 -charset
=> 'utf-8',
6288 -expires
=> $expires,
6289 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6291 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6294 die_error
(400, "Unknown blobdiff format");
6298 if ($format eq 'html') {
6299 print "<div class=\"page_body\">\n";
6301 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6304 print "</div>\n"; # class="page_body"
6308 while (my $line = <$fd>) {
6309 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6310 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6314 last if $line =~ m!^\+\+\+!;
6322 sub git_blobdiff_plain
{
6323 git_blobdiff
('plain');
6326 sub git_commitdiff
{
6328 my $format = $params{-format
} || 'html';
6330 my ($patch_max) = gitweb_get_feature
('patches');
6331 if ($format eq 'patch') {
6332 die_error
(403, "Patch view not allowed") unless $patch_max;
6335 $hash ||= $hash_base || "HEAD";
6336 my %co = parse_commit
($hash)
6337 or die_error
(404, "Unknown commit object");
6339 # choose format for commitdiff for merge
6340 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6341 $hash_parent = '--cc';
6343 # we need to prepare $formats_nav before almost any parameter munging
6345 if ($format eq 'html') {
6347 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6349 if ($patch_max && @
{$co{'parents'}} <= 1) {
6350 $formats_nav .= " | " .
6351 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6355 if (defined $hash_parent &&
6356 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6357 # commitdiff with two commits given
6358 my $hash_parent_short = $hash_parent;
6359 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6360 $hash_parent_short = substr($hash_parent, 0, 7);
6364 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6365 if ($co{'parents'}[$i] eq $hash_parent) {
6366 $formats_nav .= ' parent ' . ($i+1);
6370 $formats_nav .= ': ' .
6371 $cgi->a({-href
=> href
(action
=>"commitdiff",
6372 hash
=>$hash_parent)},
6373 esc_html
($hash_parent_short)) .
6375 } elsif (!$co{'parent'}) {
6377 $formats_nav .= ' (initial)';
6378 } elsif (scalar @
{$co{'parents'}} == 1) {
6379 # single parent commit
6382 $cgi->a({-href
=> href
(action
=>"commitdiff",
6383 hash
=>$co{'parent'})},
6384 esc_html
(substr($co{'parent'}, 0, 7))) .
6388 if ($hash_parent eq '--cc') {
6389 $formats_nav .= ' | ' .
6390 $cgi->a({-href
=> href
(action
=>"commitdiff",
6391 hash
=>$hash, hash_parent
=>'-c')},
6393 } else { # $hash_parent eq '-c'
6394 $formats_nav .= ' | ' .
6395 $cgi->a({-href
=> href
(action
=>"commitdiff",
6396 hash
=>$hash, hash_parent
=>'--cc')},
6402 $cgi->a({-href
=> href
(action
=>"commitdiff",
6404 esc_html
(substr($_, 0, 7)));
6405 } @
{$co{'parents'}} ) .
6410 my $hash_parent_param = $hash_parent;
6411 if (!defined $hash_parent_param) {
6412 # --cc for multiple parents, --root for parentless
6413 $hash_parent_param =
6414 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6420 if ($format eq 'html') {
6421 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6422 "--no-commit-id", "--patch-with-raw", "--full-index",
6423 $hash_parent_param, $hash, "--"
6424 or die_error
(500, "Open git-diff-tree failed");
6426 while (my $line = <$fd>) {
6428 # empty line ends raw part of diff-tree output
6430 push @difftree, scalar parse_difftree_raw_line
($line);
6433 } elsif ($format eq 'plain') {
6434 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6435 '-p', $hash_parent_param, $hash, "--"
6436 or die_error
(500, "Open git-diff-tree failed");
6437 } elsif ($format eq 'patch') {
6438 # For commit ranges, we limit the output to the number of
6439 # patches specified in the 'patches' feature.
6440 # For single commits, we limit the output to a single patch,
6441 # diverging from the git-format-patch default.
6442 my @commit_spec = ();
6444 if ($patch_max > 0) {
6445 push @commit_spec, "-$patch_max";
6447 push @commit_spec, '-n', "$hash_parent..$hash";
6449 if ($params{-single
}) {
6450 push @commit_spec, '-1';
6452 if ($patch_max > 0) {
6453 push @commit_spec, "-$patch_max";
6455 push @commit_spec, "-n";
6457 push @commit_spec, '--root', $hash;
6459 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6460 '--stdout', @commit_spec
6461 or die_error
(500, "Open git-format-patch failed");
6463 die_error
(400, "Unknown commitdiff format");
6466 # non-textual hash id's can be cached
6468 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6472 # write commit message
6473 if ($format eq 'html') {
6474 my $refs = git_get_references
();
6475 my $ref = format_ref_marker
($refs, $co{'id'});
6477 git_header_html
(undef, $expires);
6478 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6479 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6480 print "<div class=\"title_text\">\n" .
6481 "<table class=\"object_header\">\n";
6482 git_print_authorship_rows
(\
%co);
6485 print "<div class=\"page_body\">\n";
6486 if (@
{$co{'comment'}} > 1) {
6487 print "<div class=\"log\">\n";
6488 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6489 print "</div>\n"; # class="log"
6492 } elsif ($format eq 'plain') {
6493 my $refs = git_get_references
("tags");
6494 my $tagname = git_get_rev_name_tags
($hash);
6495 my $filename = basename
($project) . "-$hash.patch";
6498 -type
=> 'text/plain',
6499 -charset
=> 'utf-8',
6500 -expires
=> $expires,
6501 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6502 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6503 print "From: " . to_utf8
($co{'author'}) . "\n";
6504 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6505 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6507 print "X-Git-Tag: $tagname\n" if $tagname;
6508 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6510 foreach my $line (@
{$co{'comment'}}) {
6511 print to_utf8
($line) . "\n";
6514 } elsif ($format eq 'patch') {
6515 my $filename = basename
($project) . "-$hash.patch";
6518 -type
=> 'text/plain',
6519 -charset
=> 'utf-8',
6520 -expires
=> $expires,
6521 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6525 if ($format eq 'html') {
6526 my $use_parents = !defined $hash_parent ||
6527 $hash_parent eq '-c' || $hash_parent eq '--cc';
6528 git_difftree_body
(\
@difftree, $hash,
6529 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6532 git_patchset_body
($fd, \
@difftree, $hash,
6533 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6535 print "</div>\n"; # class="page_body"
6538 } elsif ($format eq 'plain') {
6542 or print "Reading git-diff-tree failed\n";
6543 } elsif ($format eq 'patch') {
6547 or print "Reading git-format-patch failed\n";
6551 sub git_commitdiff_plain
{
6552 git_commitdiff
(-format
=> 'plain');
6555 # format-patch-style patches
6557 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6561 git_commitdiff
(-format
=> 'patch');
6565 git_log_generic
('history', \
&git_history_body
,
6566 $hash_base, $hash_parent_base,
6571 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6572 if (!defined $searchtext) {
6573 die_error
(400, "Text field is empty");
6575 if (!defined $hash) {
6576 $hash = git_get_head_hash
($project);
6578 my %co = parse_commit
($hash);
6580 die_error
(404, "Unknown commit object");
6582 if (!defined $page) {
6586 $searchtype ||= 'commit';
6587 if ($searchtype eq 'pickaxe') {
6588 # pickaxe may take all resources of your box and run for several minutes
6589 # with every query - so decide by yourself how public you make this feature
6590 gitweb_check_feature
('pickaxe')
6591 or die_error
(403, "Pickaxe is disabled");
6593 if ($searchtype eq 'grep') {
6594 gitweb_check_feature
('grep')
6595 or die_error
(403, "Grep is disabled");
6600 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6602 if ($searchtype eq 'commit') {
6603 $greptype = "--grep=";
6604 } elsif ($searchtype eq 'author') {
6605 $greptype = "--author=";
6606 } elsif ($searchtype eq 'committer') {
6607 $greptype = "--committer=";
6609 $greptype .= $searchtext;
6610 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6611 $greptype, '--regexp-ignore-case',
6612 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6614 my $paging_nav = '';
6617 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6618 searchtext
=>$searchtext,
6619 searchtype
=>$searchtype)},
6621 $paging_nav .= " ⋅ " .
6622 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6623 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6625 $paging_nav .= "first";
6626 $paging_nav .= " ⋅ prev";
6629 if ($#commitlist >= 100) {
6631 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6632 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6633 $paging_nav .= " ⋅ $next_link";
6635 $paging_nav .= " ⋅ next";
6638 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6639 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6640 if ($page == 0 && !@commitlist) {
6641 print "<p>No match.</p>\n";
6643 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6647 if ($searchtype eq 'pickaxe') {
6648 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6649 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6651 print "<table class=\"pickaxe search\">\n";
6654 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6655 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6656 ($search_use_regexp ?
'--pickaxe-regex' : ());
6659 while (my $line = <$fd>) {
6663 my %set = parse_difftree_raw_line
($line);
6664 if (defined $set{'commit'}) {
6665 # finish previous commit
6668 "<td class=\"link\">" .
6669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6671 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6677 print "<tr class=\"dark\">\n";
6679 print "<tr class=\"light\">\n";
6682 %co = parse_commit
($set{'commit'});
6683 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6684 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6685 "<td><i>$author</i></td>\n" .
6687 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6688 -class => "list subject"},
6689 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6690 } elsif (defined $set{'to_id'}) {
6691 next if ($set{'to_id'} =~ m/^0{40}$/);
6693 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6694 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6696 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6702 # finish last commit (warning: repetition!)
6705 "<td class=\"link\">" .
6706 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6708 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6716 if ($searchtype eq 'grep') {
6717 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6718 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6720 print "<table class=\"grep_search\">\n";
6724 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6725 $search_use_regexp ?
('-E', '-i') : '-F',
6726 $searchtext, $co{'tree'};
6728 while (my $line = <$fd>) {
6730 my ($file, $lno, $ltext, $binary);
6731 last if ($matches++ > 1000);
6732 if ($line =~ /^Binary file (.+) matches$/) {
6736 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6738 if ($file ne $lastfile) {
6739 $lastfile and print "</td></tr>\n";
6741 print "<tr class=\"dark\">\n";
6743 print "<tr class=\"light\">\n";
6745 print "<td class=\"list\">".
6746 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6747 file_name
=>"$file"),
6748 -class => "list"}, esc_path
($file));
6749 print "</td><td>\n";
6753 print "<div class=\"binary\">Binary file</div>\n";
6755 $ltext = untabify
($ltext);
6756 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6757 $ltext = esc_html
($1, -nbsp
=>1);
6758 $ltext .= '<span class="match">';
6759 $ltext .= esc_html
($2, -nbsp
=>1);
6760 $ltext .= '</span>';
6761 $ltext .= esc_html
($3, -nbsp
=>1);
6763 $ltext = esc_html
($ltext, -nbsp
=>1);
6765 print "<div class=\"pre\">" .
6766 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6767 file_name
=>"$file").'#l'.$lno,
6768 -class => "linenr"}, sprintf('%4i', $lno))
6769 . ' ' . $ltext . "</div>\n";
6773 print "</td></tr>\n";
6774 if ($matches > 1000) {
6775 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6778 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6787 sub git_search_help
{
6789 git_print_page_nav
('','', $hash,$hash,$hash);
6791 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6792 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6793 the pattern entered is recognized as the POSIX extended
6794 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6797 <dt><b>commit</b></dt>
6798 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6800 my $have_grep = gitweb_check_feature
('grep');
6803 <dt><b>grep</b></dt>
6804 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6805 a different one) are searched for the given pattern. On large trees, this search can take
6806 a while and put some strain on the server, so please use it with some consideration. Note that
6807 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6808 case-sensitive.</dd>
6812 <dt><b>author</b></dt>
6813 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6814 <dt><b>committer</b></dt>
6815 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6817 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6818 if ($have_pickaxe) {
6820 <dt><b>pickaxe</b></dt>
6821 <dd>All commits that caused the string to appear or disappear from any file (changes that
6822 added, removed or "modified" the string) will be listed. This search can take a while and
6823 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6824 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6832 git_log_generic
('shortlog', \
&git_shortlog_body
,
6833 $hash, $hash_parent);
6836 ## ......................................................................
6837 ## feeds (RSS, Atom; OPML)
6840 my $format = shift || 'atom';
6841 my $have_blame = gitweb_check_feature
('blame');
6843 # Atom: http://www.atomenabled.org/developers/syndication/
6844 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6845 if ($format ne 'rss' && $format ne 'atom') {
6846 die_error
(400, "Unknown web feed format");
6849 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6850 my $head = $hash || 'HEAD';
6851 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6855 my $content_type = "application/$format+xml";
6856 if (defined $cgi->http('HTTP_ACCEPT') &&
6857 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6858 # browser (feed reader) prefers text/xml
6859 $content_type = 'text/xml';
6861 if (defined($commitlist[0])) {
6862 %latest_commit = %{$commitlist[0]};
6863 my $latest_epoch = $latest_commit{'committer_epoch'};
6864 %latest_date = parse_date
($latest_epoch);
6865 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6866 if (defined $if_modified) {
6868 if (eval { require HTTP
::Date
; 1; }) {
6869 $since = HTTP
::Date
::str2time
($if_modified);
6870 } elsif (eval { require Time
::ParseDate
; 1; }) {
6871 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6873 if (defined $since && $latest_epoch <= $since) {
6875 -type
=> $content_type,
6876 -charset
=> 'utf-8',
6877 -last_modified
=> $latest_date{'rfc2822'},
6878 -status
=> '304 Not Modified');
6883 -type
=> $content_type,
6884 -charset
=> 'utf-8',
6885 -last_modified
=> $latest_date{'rfc2822'});
6888 -type
=> $content_type,
6889 -charset
=> 'utf-8');
6892 # Optimization: skip generating the body if client asks only
6893 # for Last-Modified date.
6894 return if ($cgi->request_method() eq 'HEAD');
6897 my $title = "$site_name - $project/$action";
6898 my $feed_type = 'log';
6899 if (defined $hash) {
6900 $title .= " - '$hash'";
6901 $feed_type = 'branch log';
6902 if (defined $file_name) {
6903 $title .= " :: $file_name";
6904 $feed_type = 'history';
6906 } elsif (defined $file_name) {
6907 $title .= " - $file_name";
6908 $feed_type = 'history';
6910 $title .= " $feed_type";
6911 my $descr = git_get_project_description
($project);
6912 if (defined $descr) {
6913 $descr = esc_html
($descr);
6915 $descr = "$project " .
6916 ($format eq 'rss' ?
'RSS' : 'Atom') .
6919 my $owner = git_get_project_owner
($project);
6920 $owner = esc_html
($owner);
6924 if (defined $file_name) {
6925 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6926 } elsif (defined $hash) {
6927 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6929 $alt_url = href
(-full
=>1, action
=>"summary");
6931 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6932 if ($format eq 'rss') {
6934 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6937 print "<title>$title</title>\n" .
6938 "<link>$alt_url</link>\n" .
6939 "<description>$descr</description>\n" .
6940 "<language>en</language>\n" .
6941 # project owner is responsible for 'editorial' content
6942 "<managingEditor>$owner</managingEditor>\n";
6943 if (defined $logo || defined $favicon) {
6944 # prefer the logo to the favicon, since RSS
6945 # doesn't allow both
6946 my $img = esc_url
($logo || $favicon);
6948 "<url>$img</url>\n" .
6949 "<title>$title</title>\n" .
6950 "<link>$alt_url</link>\n" .
6954 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6955 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6957 print "<generator>gitweb v.$version/$git_version</generator>\n";
6958 } elsif ($format eq 'atom') {
6960 <feed xmlns="http://www.w3.org/2005/Atom">
6962 print "<title>$title</title>\n" .
6963 "<subtitle>$descr</subtitle>\n" .
6964 '<link rel="alternate" type="text/html" href="' .
6965 $alt_url . '" />' . "\n" .
6966 '<link rel="self" type="' . $content_type . '" href="' .
6967 $cgi->self_url() . '" />' . "\n" .
6968 "<id>" . href
(-full
=>1) . "</id>\n" .
6969 # use project owner for feed author
6970 "<author><name>$owner</name></author>\n";
6971 if (defined $favicon) {
6972 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6974 if (defined $logo) {
6975 # not twice as wide as tall: 72 x 27 pixels
6976 print "<logo>" . esc_url
($logo) . "</logo>\n";
6978 if (! %latest_date) {
6979 # dummy date to keep the feed valid until commits trickle in:
6980 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6982 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6984 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6988 for (my $i = 0; $i <= $#commitlist; $i++) {
6989 my %co = %{$commitlist[$i]};
6990 my $commit = $co{'id'};
6991 # we read 150, we always show 30 and the ones more recent than 48 hours
6992 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6995 my %cd = parse_date
($co{'author_epoch'});
6997 # get list of changed files
6998 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6999 $co{'parent'} || "--root",
7000 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
7002 my @difftree = map { chomp; $_ } <$fd>;
7006 # print element (entry, item)
7007 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
7008 if ($format eq 'rss') {
7010 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
7011 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
7012 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
7013 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
7014 "<link>$co_url</link>\n" .
7015 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
7016 "<content:encoded>" .
7018 } elsif ($format eq 'atom') {
7020 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
7021 "<updated>$cd{'iso-8601'}</updated>\n" .
7023 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
7024 if ($co{'author_email'}) {
7025 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
7027 print "</author>\n" .
7028 # use committer for contributor
7030 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
7031 if ($co{'committer_email'}) {
7032 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
7034 print "</contributor>\n" .
7035 "<published>$cd{'iso-8601'}</published>\n" .
7036 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
7037 "<id>$co_url</id>\n" .
7038 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
7039 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
7041 my $comment = $co{'comment'};
7043 foreach my $line (@
$comment) {
7044 $line = esc_html
($line);
7047 print "</pre><ul>\n";
7048 foreach my $difftree_line (@difftree) {
7049 my %difftree = parse_difftree_raw_line
($difftree_line);
7050 next if !$difftree{'from_id'};
7052 my $file = $difftree{'file'} || $difftree{'to_file'};
7056 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
7057 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
7058 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
7059 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
7060 -title
=> "diff"}, 'D');
7062 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
7063 file_name
=>$file, hash_base
=>$commit),
7064 -title
=> "blame"}, 'B');
7066 # if this is not a feed of a file history
7067 if (!defined $file_name || $file_name ne $file) {
7068 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
7069 file_name
=>$file, hash
=>$commit),
7070 -title
=> "history"}, 'H');
7072 $file = esc_path
($file);
7076 if ($format eq 'rss') {
7077 print "</ul>]]>\n" .
7078 "</content:encoded>\n" .
7080 } elsif ($format eq 'atom') {
7081 print "</ul>\n</div>\n" .
7088 if ($format eq 'rss') {
7089 print "</channel>\n</rss>\n";
7090 } elsif ($format eq 'atom') {
7104 my @list = git_get_projects_list
();
7107 -type
=> 'text/xml',
7108 -charset
=> 'utf-8',
7109 -content_disposition
=> 'inline; filename="opml.xml"');
7112 <?xml version="1.0" encoding="utf-8"?>
7113 <opml version="1.0">
7115 <title>$site_name OPML Export</title>
7118 <outline text="git RSS feeds">
7121 foreach my $pr (@list) {
7123 my $head = git_get_head_hash
($proj{'path'});
7124 if (!defined $head) {
7127 $git_dir = "$projectroot/$proj{'path'}";
7128 my %co = parse_commit
($head);
7133 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7134 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7135 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7136 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";