3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser set_message);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI
->compile() if $ENV{'MOD_PERL'};
31 our $version = "++GIT_VERSION++";
33 our ($my_url, $my_uri, $base_url, $path_info, $home_link);
37 our $my_url = $cgi->url();
38 our $my_uri = $cgi->url(-absolute
=> 1);
40 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
41 # needed and used only for URLs with nonempty PATH_INFO
42 our $base_url = $my_url;
44 # When the script is used as DirectoryIndex, the URL does not contain the name
45 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
46 # have to do it ourselves. We make $path_info global because it's also used
49 # Another issue with the script being the DirectoryIndex is that the resulting
50 # $my_url data is not the full script URL: this is good, because we want
51 # generated links to keep implying the script name if it wasn't explicitly
52 # indicated in the URL we're handling, but it means that $my_url cannot be used
54 # Therefore, if we needed to strip PATH_INFO, then we know that we have
55 # to build the base URL ourselves:
56 our $path_info = $ENV{"PATH_INFO"};
58 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
59 $my_uri =~ s
,\Q
$path_info\E
$,, &&
60 defined $ENV{'SCRIPT_NAME'}) {
61 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
65 # target of the home link on top of all pages
66 our $home_link = $my_uri || "/";
69 # core git executable to use
70 # this can just be "git" if your webserver has a sensible PATH
71 our $GIT = "++GIT_BINDIR++/git";
73 # absolute fs-path which will be prepended to the project path
74 #our $projectroot = "/pub/scm";
75 our $projectroot = "++GITWEB_PROJECTROOT++";
77 # fs traversing limit for getting project list
78 # the number is relative to the projectroot
79 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
81 # string of the home link on top of all pages
82 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
84 # name of your site or organization to appear in page titles
85 # replace this with something more descriptive for clearer bookmarks
86 our $site_name = "++GITWEB_SITENAME++"
87 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
89 # filename of html text to include at top of each page
90 our $site_header = "++GITWEB_SITE_HEADER++";
91 # html text to include at home page
92 our $home_text = "++GITWEB_HOMETEXT++";
93 # filename of html text to include at bottom of each page
94 our $site_footer = "++GITWEB_SITE_FOOTER++";
97 our @stylesheets = ("++GITWEB_CSS++");
98 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
99 our $stylesheet = undef;
100 # URI of GIT logo (72x27 size)
101 our $logo = "++GITWEB_LOGO++";
102 # URI of GIT favicon, assumed to be image/png type
103 our $favicon = "++GITWEB_FAVICON++";
104 # URI of gitweb.js (JavaScript code for gitweb)
105 our $javascript = "++GITWEB_JS++";
107 # URI and label (title) of GIT logo link
108 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
109 #our $logo_label = "git documentation";
110 our $logo_url = "http://git-scm.com/";
111 our $logo_label = "git homepage";
113 # source of projects list
114 our $projects_list = "++GITWEB_LIST++";
116 # the width (in characters) of the projects list "Description" column
117 our $projects_list_description_width = 25;
119 # default order of projects list
120 # valid values are none, project, descr, owner, and age
121 our $default_projects_order = "project";
123 # show repository only if this file exists
124 # (only effective if this variable evaluates to true)
125 our $export_ok = "++GITWEB_EXPORT_OK++";
127 # show repository only if this subroutine returns true
128 # when given the path to the project, for example:
129 # sub { return -e "$_[0]/git-daemon-export-ok"; }
130 our $export_auth_hook = undef;
132 # only allow viewing of repositories also shown on the overview page
133 our $strict_export = "++GITWEB_STRICT_EXPORT++";
135 # list of git base URLs used for URL to where fetch project from,
136 # i.e. full URL is "$git_base_url/$project"
137 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
139 # default blob_plain mimetype and default charset for text/plain blob
140 our $default_blob_plain_mimetype = 'text/plain';
141 our $default_text_plain_charset = undef;
143 # file to use for guessing MIME types before trying /etc/mime.types
144 # (relative to the current git repository)
145 our $mimetypes_file = undef;
147 # assume this charset if line contains non-UTF-8 characters;
148 # it should be valid encoding (see Encoding::Supported(3pm) for list),
149 # for which encoding all byte sequences are valid, for example
150 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
151 # could be even 'utf-8' for the old behavior)
152 our $fallback_encoding = 'latin1';
154 # rename detection options for git-diff and git-diff-tree
155 # - default is '-M', with the cost proportional to
156 # (number of removed files) * (number of new files).
157 # - more costly is '-C' (which implies '-M'), with the cost proportional to
158 # (number of changed files + number of removed files) * (number of new files)
159 # - even more costly is '-C', '--find-copies-harder' with cost
160 # (number of files in the original tree) * (number of new files)
161 # - one might want to include '-B' option, e.g. '-B', '-M'
162 our @diff_opts = ('-M'); # taken from git_commit
164 # Disables features that would allow repository owners to inject script into
166 our $prevent_xss = 0;
168 # information about snapshot formats that gitweb is capable of serving
169 our %known_snapshot_formats = (
171 # 'display' => display name,
172 # 'type' => mime type,
173 # 'suffix' => filename suffix,
174 # 'format' => --format for git-archive,
175 # 'compressor' => [compressor command and arguments]
176 # (array reference, optional)
177 # 'disabled' => boolean (optional)}
180 'display' => 'tar.gz',
181 'type' => 'application/x-gzip',
182 'suffix' => '.tar.gz',
184 'compressor' => ['gzip']},
187 'display' => 'tar.bz2',
188 'type' => 'application/x-bzip2',
189 'suffix' => '.tar.bz2',
191 'compressor' => ['bzip2']},
194 'display' => 'tar.xz',
195 'type' => 'application/x-xz',
196 'suffix' => '.tar.xz',
198 'compressor' => ['xz'],
203 'type' => 'application/x-zip',
208 # Aliases so we understand old gitweb.snapshot values in repository
210 our %known_snapshot_format_aliases = (
215 # backward compatibility: legacy gitweb config support
216 'x-gzip' => undef, 'gz' => undef,
217 'x-bzip2' => undef, 'bz2' => undef,
218 'x-zip' => undef, '' => undef,
221 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
222 # are changed, it may be appropriate to change these values too via
229 # Used to set the maximum load that we will still respond to gitweb queries.
230 # If server load exceed this value then return "503 server busy" error.
231 # If gitweb cannot determined server load, it is taken to be 0.
232 # Leave it undefined (or set to 'undef') to turn off load checking.
235 # You define site-wide feature defaults here; override them with
236 # $GITWEB_CONFIG as necessary.
239 # 'sub' => feature-sub (subroutine),
240 # 'override' => allow-override (boolean),
241 # 'default' => [ default options...] (array reference)}
243 # if feature is overridable (it means that allow-override has true value),
244 # then feature-sub will be called with default options as parameters;
245 # return value of feature-sub indicates if to enable specified feature
247 # if there is no 'sub' key (no feature-sub), then feature cannot be
250 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
251 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
254 # Enable the 'blame' blob view, showing the last commit that modified
255 # each line in the file. This can be very CPU-intensive.
257 # To enable system wide have in $GITWEB_CONFIG
258 # $feature{'blame'}{'default'} = [1];
259 # To have project specific config enable override in $GITWEB_CONFIG
260 # $feature{'blame'}{'override'} = 1;
261 # and in project config gitweb.blame = 0|1;
263 'sub' => sub { feature_bool
('blame', @_) },
267 # Enable the 'snapshot' link, providing a compressed archive of any
268 # tree. This can potentially generate high traffic if you have large
271 # Value is a list of formats defined in %known_snapshot_formats that
273 # To disable system wide have in $GITWEB_CONFIG
274 # $feature{'snapshot'}{'default'} = [];
275 # To have project specific config enable override in $GITWEB_CONFIG
276 # $feature{'snapshot'}{'override'} = 1;
277 # and in project config, a comma-separated list of formats or "none"
278 # to disable. Example: gitweb.snapshot = tbz2,zip;
280 'sub' => \
&feature_snapshot
,
282 'default' => ['tgz']},
284 # Enable text search, which will list the commits which match author,
285 # committer or commit text to a given string. Enabled by default.
286 # Project specific override is not supported.
291 # Enable grep search, which will list the files in currently selected
292 # tree containing the given string. Enabled by default. This can be
293 # potentially CPU-intensive, of course.
295 # To enable system wide have in $GITWEB_CONFIG
296 # $feature{'grep'}{'default'} = [1];
297 # To have project specific config enable override in $GITWEB_CONFIG
298 # $feature{'grep'}{'override'} = 1;
299 # and in project config gitweb.grep = 0|1;
301 'sub' => sub { feature_bool
('grep', @_) },
305 # Enable the pickaxe search, which will list the commits that modified
306 # a given string in a file. This can be practical and quite faster
307 # alternative to 'blame', but still potentially CPU-intensive.
309 # To enable system wide have in $GITWEB_CONFIG
310 # $feature{'pickaxe'}{'default'} = [1];
311 # To have project specific config enable override in $GITWEB_CONFIG
312 # $feature{'pickaxe'}{'override'} = 1;
313 # and in project config gitweb.pickaxe = 0|1;
315 'sub' => sub { feature_bool
('pickaxe', @_) },
319 # Enable showing size of blobs in a 'tree' view, in a separate
320 # column, similar to what 'ls -l' does. This cost a bit of IO.
322 # To disable system wide have in $GITWEB_CONFIG
323 # $feature{'show-sizes'}{'default'} = [0];
324 # To have project specific config enable override in $GITWEB_CONFIG
325 # $feature{'show-sizes'}{'override'} = 1;
326 # and in project config gitweb.showsizes = 0|1;
328 'sub' => sub { feature_bool
('showsizes', @_) },
332 # Make gitweb use an alternative format of the URLs which can be
333 # more readable and natural-looking: project name is embedded
334 # directly in the path and the query string contains other
335 # auxiliary information. All gitweb installations recognize
336 # URL in either format; this configures in which formats gitweb
339 # To enable system wide have in $GITWEB_CONFIG
340 # $feature{'pathinfo'}{'default'} = [1];
341 # Project specific override is not supported.
343 # Note that you will need to change the default location of CSS,
344 # favicon, logo and possibly other files to an absolute URL. Also,
345 # if gitweb.cgi serves as your indexfile, you will need to force
346 # $my_uri to contain the script name in your $GITWEB_CONFIG.
351 # Make gitweb consider projects in project root subdirectories
352 # to be forks of existing projects. Given project $projname.git,
353 # projects matching $projname/*.git will not be shown in the main
354 # projects list, instead a '+' mark will be added to $projname
355 # there and a 'forks' view will be enabled for the project, listing
356 # all the forks. If project list is taken from a file, forks have
357 # to be listed after the main project.
359 # To enable system wide have in $GITWEB_CONFIG
360 # $feature{'forks'}{'default'} = [1];
361 # Project specific override is not supported.
366 # Insert custom links to the action bar of all project pages.
367 # This enables you mainly to link to third-party scripts integrating
368 # into gitweb; e.g. git-browser for graphical history representation
369 # or custom web-based repository administration interface.
371 # The 'default' value consists of a list of triplets in the form
372 # (label, link, position) where position is the label after which
373 # to insert the link and link is a format string where %n expands
374 # to the project name, %f to the project path within the filesystem,
375 # %h to the current hash (h gitweb parameter) and %b to the current
376 # hash base (hb gitweb parameter); %% expands to %.
378 # To enable system wide have in $GITWEB_CONFIG e.g.
379 # $feature{'actions'}{'default'} = [('graphiclog',
380 # '/git-browser/by-commit.html?r=%n', 'summary')];
381 # Project specific override is not supported.
386 # Allow gitweb scan project content tags described in ctags/
387 # of project repository, and display the popular Web 2.0-ish
388 # "tag cloud" near the project list. Note that this is something
389 # COMPLETELY different from the normal Git tags.
391 # gitweb by itself can show existing tags, but it does not handle
392 # tagging itself; you need an external application for that.
393 # For an example script, check Girocco's cgi/tagproj.cgi.
394 # You may want to install the HTML::TagCloud Perl module to get
395 # a pretty tag cloud instead of just a list of tags.
397 # To enable system wide have in $GITWEB_CONFIG
398 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
399 # Project specific override is not supported.
404 # The maximum number of patches in a patchset generated in patch
405 # view. Set this to 0 or undef to disable patch view, or to a
406 # negative number to remove any limit.
408 # To disable system wide have in $GITWEB_CONFIG
409 # $feature{'patches'}{'default'} = [0];
410 # To have project specific config enable override in $GITWEB_CONFIG
411 # $feature{'patches'}{'override'} = 1;
412 # and in project config gitweb.patches = 0|n;
413 # where n is the maximum number of patches allowed in a patchset.
415 'sub' => \
&feature_patches
,
419 # Avatar support. When this feature is enabled, views such as
420 # shortlog or commit will display an avatar associated with
421 # the email of the committer(s) and/or author(s).
423 # Currently available providers are gravatar and picon.
424 # If an unknown provider is specified, the feature is disabled.
426 # Gravatar depends on Digest::MD5.
427 # Picon currently relies on the indiana.edu database.
429 # To enable system wide have in $GITWEB_CONFIG
430 # $feature{'avatar'}{'default'} = ['<provider>'];
431 # where <provider> is either gravatar or picon.
432 # To have project specific config enable override in $GITWEB_CONFIG
433 # $feature{'avatar'}{'override'} = 1;
434 # and in project config gitweb.avatar = <provider>;
436 'sub' => \
&feature_avatar
,
440 # Enable displaying how much time and how many git commands
441 # it took to generate and display page. Disabled by default.
442 # Project specific override is not supported.
447 # Enable turning some links into links to actions which require
448 # JavaScript to run (like 'blame_incremental'). Not enabled by
449 # default. Project specific override is currently not supported.
450 'javascript-actions' => {
454 # Syntax highlighting support. This is based on Daniel Svensson's
455 # and Sham Chukoury's work in gitweb-xmms2.git.
456 # It requires the 'highlight' program present in $PATH,
457 # and therefore is disabled by default.
459 # To enable system wide have in $GITWEB_CONFIG
460 # $feature{'highlight'}{'default'} = [1];
463 'sub' => sub { feature_bool
('highlight', @_) },
468 sub gitweb_get_feature
{
470 return unless exists $feature{$name};
471 my ($sub, $override, @defaults) = (
472 $feature{$name}{'sub'},
473 $feature{$name}{'override'},
474 @
{$feature{$name}{'default'}});
475 # project specific override is possible only if we have project
476 our $git_dir; # global variable, declared later
477 if (!$override || !defined $git_dir) {
481 warn "feature $name is not overridable";
484 return $sub->(@defaults);
487 # A wrapper to check if a given feature is enabled.
488 # With this, you can say
490 # my $bool_feat = gitweb_check_feature('bool_feat');
491 # gitweb_check_feature('bool_feat') or somecode;
495 # my ($bool_feat) = gitweb_get_feature('bool_feat');
496 # (gitweb_get_feature('bool_feat'))[0] or somecode;
498 sub gitweb_check_feature
{
499 return (gitweb_get_feature
(@_))[0];
505 my ($val) = git_get_project_config
($key, '--bool');
509 } elsif ($val eq 'true') {
511 } elsif ($val eq 'false') {
516 sub feature_snapshot
{
519 my ($val) = git_get_project_config
('snapshot');
522 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
528 sub feature_patches
{
529 my @val = (git_get_project_config
('patches', '--int'));
539 my @val = (git_get_project_config
('avatar'));
541 return @val ?
@val : @_;
544 # checking HEAD file with -e is fragile if the repository was
545 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
547 sub check_head_link
{
549 my $headfile = "$dir/HEAD";
550 return ((-e
$headfile) ||
551 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
554 sub check_export_ok
{
556 return (check_head_link
($dir) &&
557 (!$export_ok || -e
"$dir/$export_ok") &&
558 (!$export_auth_hook || $export_auth_hook->($dir)));
561 # process alternate names for backward compatibility
562 # filter out unsupported (unknown) snapshot formats
563 sub filter_snapshot_fmts
{
567 exists $known_snapshot_format_aliases{$_} ?
568 $known_snapshot_format_aliases{$_} : $_} @fmts;
570 exists $known_snapshot_formats{$_} &&
571 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
574 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
575 sub evaluate_gitweb_config
{
576 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
577 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
578 # die if there are errors parsing config file
579 if (-e
$GITWEB_CONFIG) {
582 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
583 do $GITWEB_CONFIG_SYSTEM;
588 # Get loadavg of system, to compare against $maxload.
589 # Currently it requires '/proc/loadavg' present to get loadavg;
590 # if it is not present it returns 0, which means no load checking.
592 if( -e
'/proc/loadavg' ){
593 open my $fd, '<', '/proc/loadavg'
595 my @load = split(/\s+/, scalar <$fd>);
598 # The first three columns measure CPU and IO utilization of the last one,
599 # five, and 10 minute periods. The fourth column shows the number of
600 # currently running processes and the total number of processes in the m/n
601 # format. The last column displays the last process ID used.
602 return $load[0] || 0;
604 # additional checks for load average should go here for things that don't export
610 # version of the core git binary
612 sub evaluate_git_version
{
613 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
614 $number_of_git_cmds++;
618 if (defined $maxload && get_loadavg
() > $maxload) {
619 die_error
(503, "The load average on the server is too high");
623 # ======================================================================
624 # input validation and dispatch
626 # input parameters can be collected from a variety of sources (presently, CGI
627 # and PATH_INFO), so we define an %input_params hash that collects them all
628 # together during validation: this allows subsequent uses (e.g. href()) to be
629 # agnostic of the parameter origin
631 our %input_params = ();
633 # input parameters are stored with the long parameter name as key. This will
634 # also be used in the href subroutine to convert parameters to their CGI
635 # equivalent, and since the href() usage is the most frequent one, we store
636 # the name -> CGI key mapping here, instead of the reverse.
638 # XXX: Warning: If you touch this, check the search form for updating,
641 our @cgi_param_mapping = (
649 hash_parent_base
=> "hpb",
654 snapshot_format
=> "sf",
655 extra_options
=> "opt",
656 search_use_regexp
=> "sr",
657 # this must be last entry (for manipulation from JavaScript)
660 our %cgi_param_mapping = @cgi_param_mapping;
662 # we will also need to know the possible actions, for validation
664 "blame" => \
&git_blame
,
665 "blame_incremental" => \
&git_blame_incremental
,
666 "blame_data" => \
&git_blame_data
,
667 "blobdiff" => \
&git_blobdiff
,
668 "blobdiff_plain" => \
&git_blobdiff_plain
,
669 "blob" => \
&git_blob
,
670 "blob_plain" => \
&git_blob_plain
,
671 "commitdiff" => \
&git_commitdiff
,
672 "commitdiff_plain" => \
&git_commitdiff_plain
,
673 "commit" => \
&git_commit
,
674 "forks" => \
&git_forks
,
675 "heads" => \
&git_heads
,
676 "history" => \
&git_history
,
678 "patch" => \
&git_patch
,
679 "patches" => \
&git_patches
,
681 "atom" => \
&git_atom
,
682 "search" => \
&git_search
,
683 "search_help" => \
&git_search_help
,
684 "shortlog" => \
&git_shortlog
,
685 "summary" => \
&git_summary
,
687 "tags" => \
&git_tags
,
688 "tree" => \
&git_tree
,
689 "snapshot" => \
&git_snapshot
,
690 "object" => \
&git_object
,
691 # those below don't need $project
692 "opml" => \
&git_opml
,
693 "project_list" => \
&git_project_list
,
694 "project_index" => \
&git_project_index
,
697 # finally, we have the hash of allowed extra_options for the commands that
699 our %allowed_options = (
700 "--no-merges" => [ qw(rss atom log shortlog history) ],
703 # fill %input_params with the CGI parameters. All values except for 'opt'
704 # should be single values, but opt can be an array. We should probably
705 # build an array of parameters that can be multi-valued, but since for the time
706 # being it's only this one, we just single it out
707 sub evaluate_query_params
{
710 while (my ($name, $symbol) = each %cgi_param_mapping) {
711 if ($symbol eq 'opt') {
712 $input_params{$name} = [ $cgi->param($symbol) ];
714 $input_params{$name} = $cgi->param($symbol);
719 # now read PATH_INFO and update the parameter list for missing parameters
720 sub evaluate_path_info
{
721 return if defined $input_params{'project'};
722 return if !$path_info;
723 $path_info =~ s
,^/+,,;
724 return if !$path_info;
726 # find which part of PATH_INFO is project
727 my $project = $path_info;
729 while ($project && !check_head_link
("$projectroot/$project")) {
730 $project =~ s
,/*[^/]*$,,;
732 return unless $project;
733 $input_params{'project'} = $project;
735 # do not change any parameters if an action is given using the query string
736 return if $input_params{'action'};
737 $path_info =~ s
,^\Q
$project\E
/*,,;
739 # next, check if we have an action
740 my $action = $path_info;
742 if (exists $actions{$action}) {
743 $path_info =~ s
,^$action/*,,;
744 $input_params{'action'} = $action;
747 # list of actions that want hash_base instead of hash, but can have no
748 # pathname (f) parameter
755 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
756 my ($parentrefname, $parentpathname, $refname, $pathname) =
757 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
759 # first, analyze the 'current' part
760 if (defined $pathname) {
761 # we got "branch:filename" or "branch:dir/"
762 # we could use git_get_type(branch:pathname), but:
763 # - it needs $git_dir
764 # - it does a git() call
765 # - the convention of terminating directories with a slash
766 # makes it superfluous
767 # - embedding the action in the PATH_INFO would make it even
769 $pathname =~ s
,^/+,,;
770 if (!$pathname || substr($pathname, -1) eq "/") {
771 $input_params{'action'} ||= "tree";
774 # the default action depends on whether we had parent info
776 if ($parentrefname) {
777 $input_params{'action'} ||= "blobdiff_plain";
779 $input_params{'action'} ||= "blob_plain";
782 $input_params{'hash_base'} ||= $refname;
783 $input_params{'file_name'} ||= $pathname;
784 } elsif (defined $refname) {
785 # we got "branch". In this case we have to choose if we have to
786 # set hash or hash_base.
788 # Most of the actions without a pathname only want hash to be
789 # set, except for the ones specified in @wants_base that want
790 # hash_base instead. It should also be noted that hand-crafted
791 # links having 'history' as an action and no pathname or hash
792 # set will fail, but that happens regardless of PATH_INFO.
793 $input_params{'action'} ||= "shortlog";
794 if (grep { $_ eq $input_params{'action'} } @wants_base) {
795 $input_params{'hash_base'} ||= $refname;
797 $input_params{'hash'} ||= $refname;
801 # next, handle the 'parent' part, if present
802 if (defined $parentrefname) {
803 # a missing pathspec defaults to the 'current' filename, allowing e.g.
804 # someproject/blobdiff/oldrev..newrev:/filename
805 if ($parentpathname) {
806 $parentpathname =~ s
,^/+,,;
807 $parentpathname =~ s
,/$,,;
808 $input_params{'file_parent'} ||= $parentpathname;
810 $input_params{'file_parent'} ||= $input_params{'file_name'};
812 # we assume that hash_parent_base is wanted if a path was specified,
813 # or if the action wants hash_base instead of hash
814 if (defined $input_params{'file_parent'} ||
815 grep { $_ eq $input_params{'action'} } @wants_base) {
816 $input_params{'hash_parent_base'} ||= $parentrefname;
818 $input_params{'hash_parent'} ||= $parentrefname;
822 # for the snapshot action, we allow URLs in the form
823 # $project/snapshot/$hash.ext
824 # where .ext determines the snapshot and gets removed from the
825 # passed $refname to provide the $hash.
827 # To be able to tell that $refname includes the format extension, we
828 # require the following two conditions to be satisfied:
829 # - the hash input parameter MUST have been set from the $refname part
830 # of the URL (i.e. they must be equal)
831 # - the snapshot format MUST NOT have been defined already (e.g. from
833 # It's also useless to try any matching unless $refname has a dot,
834 # so we check for that too
835 if (defined $input_params{'action'} &&
836 $input_params{'action'} eq 'snapshot' &&
837 defined $refname && index($refname, '.') != -1 &&
838 $refname eq $input_params{'hash'} &&
839 !defined $input_params{'snapshot_format'}) {
840 # We loop over the known snapshot formats, checking for
841 # extensions. Allowed extensions are both the defined suffix
842 # (which includes the initial dot already) and the snapshot
843 # format key itself, with a prepended dot
844 while (my ($fmt, $opt) = each %known_snapshot_formats) {
846 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
850 # a valid suffix was found, so set the snapshot format
851 # and reset the hash parameter
852 $input_params{'snapshot_format'} = $fmt;
853 $input_params{'hash'} = $hash;
854 # we also set the format suffix to the one requested
855 # in the URL: this way a request for e.g. .tgz returns
856 # a .tgz instead of a .tar.gz
857 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
863 our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
864 $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
865 $searchtext, $search_regexp);
866 sub evaluate_and_validate_params
{
867 our $action = $input_params{'action'};
868 if (defined $action) {
869 if (!validate_action
($action)) {
870 die_error
(400, "Invalid action parameter");
874 # parameters which are pathnames
875 our $project = $input_params{'project'};
876 if (defined $project) {
877 if (!validate_project
($project)) {
879 die_error
(404, "No such project");
883 our $file_name = $input_params{'file_name'};
884 if (defined $file_name) {
885 if (!validate_pathname
($file_name)) {
886 die_error
(400, "Invalid file parameter");
890 our $file_parent = $input_params{'file_parent'};
891 if (defined $file_parent) {
892 if (!validate_pathname
($file_parent)) {
893 die_error
(400, "Invalid file parent parameter");
897 # parameters which are refnames
898 our $hash = $input_params{'hash'};
900 if (!validate_refname
($hash)) {
901 die_error
(400, "Invalid hash parameter");
905 our $hash_parent = $input_params{'hash_parent'};
906 if (defined $hash_parent) {
907 if (!validate_refname
($hash_parent)) {
908 die_error
(400, "Invalid hash parent parameter");
912 our $hash_base = $input_params{'hash_base'};
913 if (defined $hash_base) {
914 if (!validate_refname
($hash_base)) {
915 die_error
(400, "Invalid hash base parameter");
919 our @extra_options = @
{$input_params{'extra_options'}};
920 # @extra_options is always defined, since it can only be (currently) set from
921 # CGI, and $cgi->param() returns the empty array in array context if the param
923 foreach my $opt (@extra_options) {
924 if (not exists $allowed_options{$opt}) {
925 die_error
(400, "Invalid option parameter");
927 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
928 die_error
(400, "Invalid option parameter for this action");
932 our $hash_parent_base = $input_params{'hash_parent_base'};
933 if (defined $hash_parent_base) {
934 if (!validate_refname
($hash_parent_base)) {
935 die_error
(400, "Invalid hash parent base parameter");
940 our $page = $input_params{'page'};
942 if ($page =~ m/[^0-9]/) {
943 die_error
(400, "Invalid page parameter");
947 our $searchtype = $input_params{'searchtype'};
948 if (defined $searchtype) {
949 if ($searchtype =~ m/[^a-z]/) {
950 die_error
(400, "Invalid searchtype parameter");
954 our $search_use_regexp = $input_params{'search_use_regexp'};
956 our $searchtext = $input_params{'searchtext'};
958 if (defined $searchtext) {
959 if (length($searchtext) < 2) {
960 die_error
(403, "At least two characters are required for search parameter");
962 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
966 # path to the current git repository
968 sub evaluate_git_dir
{
969 our $git_dir = "$projectroot/$project" if $project;
972 our (@snapshot_fmts, $git_avatar);
973 sub configure_gitweb_features
{
974 # list of supported snapshot formats
975 our @snapshot_fmts = gitweb_get_feature
('snapshot');
976 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
978 # check that the avatar feature is set to a known provider name,
979 # and for each provider check if the dependencies are satisfied.
980 # if the provider name is invalid or the dependencies are not met,
981 # reset $git_avatar to the empty string.
982 our ($git_avatar) = gitweb_get_feature
('avatar');
983 if ($git_avatar eq 'gravatar') {
984 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
985 } elsif ($git_avatar eq 'picon') {
992 # custom error handler: 'die <message>' is Internal Server Error
993 sub handle_errors_html
{
994 my $msg = shift; # it is already HTML escaped
996 # to avoid infinite loop where error occurs in die_error,
997 # change handler to default handler, disabling handle_errors_html
998 set_message
("Error occured when inside die_error:\n$msg");
1000 # you cannot jump out of die_error when called as error handler;
1001 # the subroutine set via CGI::Carp::set_message is called _after_
1002 # HTTP headers are already written, so it cannot write them itself
1003 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
1005 set_message
(\
&handle_errors_html
);
1009 if (!defined $action) {
1010 if (defined $hash) {
1011 $action = git_get_type
($hash);
1012 } elsif (defined $hash_base && defined $file_name) {
1013 $action = git_get_type
("$hash_base:$file_name");
1014 } elsif (defined $project) {
1015 $action = 'summary';
1017 $action = 'project_list';
1020 if (!defined($actions{$action})) {
1021 die_error
(400, "Unknown action");
1023 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
1025 die_error
(400, "Project needed");
1027 $actions{$action}->();
1031 our $t0 = [Time
::HiRes
::gettimeofday
()]
1033 our $number_of_git_cmds = 0;
1042 evaluate_query_params
();
1043 evaluate_path_info
();
1044 evaluate_and_validate_params
();
1047 configure_gitweb_features
();
1052 our $is_last_request = sub { 1 };
1053 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1056 sub configure_as_fcgi
{
1058 our $CGI = 'CGI::Fast';
1060 my $request_number = 0;
1061 # let each child service 100 requests
1062 our $is_last_request = sub { ++$request_number > 100 };
1065 my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__
;
1067 if $script_name =~ /\.fcgi$/;
1069 return unless (@ARGV);
1071 require Getopt
::Long
;
1072 Getopt
::Long
::GetOptions
(
1073 'fastcgi|fcgi|f' => \
&configure_as_fcgi
,
1074 'nproc|n=i' => sub {
1075 my ($arg, $val) = @_;
1076 return unless eval { require FCGI
::ProcManager
; 1; };
1077 my $proc_manager = FCGI
::ProcManager
->new({
1078 n_processes
=> $val,
1080 our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1081 our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1082 our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1089 evaluate_gitweb_config
();
1090 evaluate_git_version
();
1092 # $projectroot and $projects_list might be set in gitweb config file
1093 $projects_list ||= $projectroot;
1095 $pre_listen_hook->()
1096 if $pre_listen_hook;
1099 while ($cgi = $CGI->new()) {
1100 $pre_dispatch_hook->()
1101 if $pre_dispatch_hook;
1105 $pre_dispatch_hook->()
1106 if $post_dispatch_hook;
1108 last REQUEST
if ($is_last_request->());
1117 if (defined caller) {
1118 # wrapped in a subroutine processing requests,
1119 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1122 # pure CGI script, serving single request
1126 ## ======================================================================
1129 # possible values of extra options
1130 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1131 # -replay => 1 - start from a current view (replay with modifications)
1132 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1135 # default is to use -absolute url() i.e. $my_uri
1136 my $href = $params{-full
} ?
$my_url : $my_uri;
1138 $params{'project'} = $project unless exists $params{'project'};
1140 if ($params{-replay
}) {
1141 while (my ($name, $symbol) = each %cgi_param_mapping) {
1142 if (!exists $params{$name}) {
1143 $params{$name} = $input_params{$name};
1148 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1149 if (defined $params{'project'} &&
1150 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1151 # try to put as many parameters as possible in PATH_INFO:
1154 # - hash_parent or hash_parent_base:/file_parent
1155 # - hash or hash_base:/filename
1156 # - the snapshot_format as an appropriate suffix
1158 # When the script is the root DirectoryIndex for the domain,
1159 # $href here would be something like http://gitweb.example.com/
1160 # Thus, we strip any trailing / from $href, to spare us double
1161 # slashes in the final URL
1164 # Then add the project name, if present
1165 $href .= "/".esc_url
($params{'project'});
1166 delete $params{'project'};
1168 # since we destructively absorb parameters, we keep this
1169 # boolean that remembers if we're handling a snapshot
1170 my $is_snapshot = $params{'action'} eq 'snapshot';
1172 # Summary just uses the project path URL, any other action is
1174 if (defined $params{'action'}) {
1175 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1176 delete $params{'action'};
1179 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1180 # stripping nonexistent or useless pieces
1181 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1182 || $params{'hash_parent'} || $params{'hash'});
1183 if (defined $params{'hash_base'}) {
1184 if (defined $params{'hash_parent_base'}) {
1185 $href .= esc_url
($params{'hash_parent_base'});
1186 # skip the file_parent if it's the same as the file_name
1187 if (defined $params{'file_parent'}) {
1188 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1189 delete $params{'file_parent'};
1190 } elsif ($params{'file_parent'} !~ /\.\./) {
1191 $href .= ":/".esc_url
($params{'file_parent'});
1192 delete $params{'file_parent'};
1196 delete $params{'hash_parent'};
1197 delete $params{'hash_parent_base'};
1198 } elsif (defined $params{'hash_parent'}) {
1199 $href .= esc_url
($params{'hash_parent'}). "..";
1200 delete $params{'hash_parent'};
1203 $href .= esc_url
($params{'hash_base'});
1204 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1205 $href .= ":/".esc_url
($params{'file_name'});
1206 delete $params{'file_name'};
1208 delete $params{'hash'};
1209 delete $params{'hash_base'};
1210 } elsif (defined $params{'hash'}) {
1211 $href .= esc_url
($params{'hash'});
1212 delete $params{'hash'};
1215 # If the action was a snapshot, we can absorb the
1216 # snapshot_format parameter too
1218 my $fmt = $params{'snapshot_format'};
1219 # snapshot_format should always be defined when href()
1220 # is called, but just in case some code forgets, we
1221 # fall back to the default
1222 $fmt ||= $snapshot_fmts[0];
1223 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1224 delete $params{'snapshot_format'};
1228 # now encode the parameters explicitly
1230 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1231 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1232 if (defined $params{$name}) {
1233 if (ref($params{$name}) eq "ARRAY") {
1234 foreach my $par (@
{$params{$name}}) {
1235 push @result, $symbol . "=" . esc_param
($par);
1238 push @result, $symbol . "=" . esc_param
($params{$name});
1242 $href .= "?" . join(';', @result) if scalar @result;
1248 ## ======================================================================
1249 ## validation, quoting/unquoting and escaping
1251 sub validate_action
{
1252 my $input = shift || return undef;
1253 return undef unless exists $actions{$input};
1257 sub validate_project
{
1258 my $input = shift || return undef;
1259 if (!validate_pathname
($input) ||
1260 !(-d
"$projectroot/$input") ||
1261 !check_export_ok
("$projectroot/$input") ||
1262 ($strict_export && !project_in_list
($input))) {
1269 sub validate_pathname
{
1270 my $input = shift || return undef;
1272 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1273 # at the beginning, at the end, and between slashes.
1274 # also this catches doubled slashes
1275 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1278 # no null characters
1279 if ($input =~ m!\0!) {
1285 sub validate_refname
{
1286 my $input = shift || return undef;
1288 # textual hashes are O.K.
1289 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1292 # it must be correct pathname
1293 $input = validate_pathname
($input)
1295 # restrictions on ref name according to git-check-ref-format
1296 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1302 # decode sequences of octets in utf8 into Perl's internal form,
1303 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1304 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1307 return undef unless defined $str;
1308 if (utf8
::valid
($str)) {
1312 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1316 # quote unsafe chars, but keep the slash, even when it's not
1317 # correct, but quoted slashes look too horrible in bookmarks
1320 return undef unless defined $str;
1321 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1326 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1329 return undef unless defined $str;
1330 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI
::escape
($1)/eg
;
1335 # replace invalid utf8 character with SUBSTITUTION sequence
1340 return undef unless defined $str;
1342 $str = to_utf8
($str);
1343 $str = $cgi->escapeHTML($str);
1344 if ($opts{'-nbsp'}) {
1345 $str =~ s/ / /g;
1347 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1351 # quote control characters and escape filename to HTML
1356 return undef unless defined $str;
1358 $str = to_utf8
($str);
1359 $str = $cgi->escapeHTML($str);
1360 if ($opts{'-nbsp'}) {
1361 $str =~ s/ / /g;
1363 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1367 # Make control characters "printable", using character escape codes (CEC)
1371 my %es = ( # character escape codes, aka escape sequences
1372 "\t" => '\t', # tab (HT)
1373 "\n" => '\n', # line feed (LF)
1374 "\r" => '\r', # carrige return (CR)
1375 "\f" => '\f', # form feed (FF)
1376 "\b" => '\b', # backspace (BS)
1377 "\a" => '\a', # alarm (bell) (BEL)
1378 "\e" => '\e', # escape (ESC)
1379 "\013" => '\v', # vertical tab (VT)
1380 "\000" => '\0', # nul character (NUL)
1382 my $chr = ( (exists $es{$cntrl})
1384 : sprintf('\%2x', ord($cntrl)) );
1385 if ($opts{-nohtml
}) {
1388 return "<span class=\"cntrl\">$chr</span>";
1392 # Alternatively use unicode control pictures codepoints,
1393 # Unicode "printable representation" (PR)
1398 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1399 if ($opts{-nohtml
}) {
1402 return "<span class=\"cntrl\">$chr</span>";
1406 # git may return quoted and escaped filenames
1412 my %es = ( # character escape codes, aka escape sequences
1413 't' => "\t", # tab (HT, TAB)
1414 'n' => "\n", # newline (NL)
1415 'r' => "\r", # return (CR)
1416 'f' => "\f", # form feed (FF)
1417 'b' => "\b", # backspace (BS)
1418 'a' => "\a", # alarm (bell) (BEL)
1419 'e' => "\e", # escape (ESC)
1420 'v' => "\013", # vertical tab (VT)
1423 if ($seq =~ m/^[0-7]{1,3}$/) {
1424 # octal char sequence
1425 return chr(oct($seq));
1426 } elsif (exists $es{$seq}) {
1427 # C escape sequence, aka character escape code
1430 # quoted ordinary character
1434 if ($str =~ m/^"(.*)"$/) {
1437 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1442 # escape tabs (convert tabs to spaces)
1446 while ((my $pos = index($line, "\t")) != -1) {
1447 if (my $count = (8 - ($pos % 8))) {
1448 my $spaces = ' ' x
$count;
1449 $line =~ s/\t/$spaces/;
1456 sub project_in_list
{
1457 my $project = shift;
1458 my @list = git_get_projects_list
();
1459 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1462 ## ----------------------------------------------------------------------
1463 ## HTML aware string manipulation
1465 # Try to chop given string on a word boundary between position
1466 # $len and $len+$add_len. If there is no word boundary there,
1467 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1468 # (marking chopped part) would be longer than given string.
1472 my $add_len = shift || 10;
1473 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1475 # Make sure perl knows it is utf8 encoded so we don't
1476 # cut in the middle of a utf8 multibyte char.
1477 $str = to_utf8
($str);
1479 # allow only $len chars, but don't cut a word if it would fit in $add_len
1480 # if it doesn't fit, cut it if it's still longer than the dots we would add
1481 # remove chopped character entities entirely
1483 # when chopping in the middle, distribute $len into left and right part
1484 # return early if chopping wouldn't make string shorter
1485 if ($where eq 'center') {
1486 return $str if ($len + 5 >= length($str)); # filler is length 5
1489 return $str if ($len + 4 >= length($str)); # filler is length 4
1492 # regexps: ending and beginning with word part up to $add_len
1493 my $endre = qr/.{$len}\w{0,$add_len}/;
1494 my $begre = qr/\w{0,$add_len}.{$len}/;
1496 if ($where eq 'left') {
1497 $str =~ m/^(.*?)($begre)$/;
1498 my ($lead, $body) = ($1, $2);
1499 if (length($lead) > 4) {
1502 return "$lead$body";
1504 } elsif ($where eq 'center') {
1505 $str =~ m/^($endre)(.*)$/;
1506 my ($left, $str) = ($1, $2);
1507 $str =~ m/^(.*?)($begre)$/;
1508 my ($mid, $right) = ($1, $2);
1509 if (length($mid) > 5) {
1512 return "$left$mid$right";
1515 $str =~ m/^($endre)(.*)$/;
1518 if (length($tail) > 4) {
1521 return "$body$tail";
1525 # takes the same arguments as chop_str, but also wraps a <span> around the
1526 # result with a title attribute if it does get chopped. Additionally, the
1527 # string is HTML-escaped.
1528 sub chop_and_escape_str
{
1531 my $chopped = chop_str
(@_);
1532 if ($chopped eq $str) {
1533 return esc_html
($chopped);
1535 $str =~ s/[[:cntrl:]]/?/g;
1536 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1540 ## ----------------------------------------------------------------------
1541 ## functions returning short strings
1543 # CSS class for given age value (in seconds)
1547 if (!defined $age) {
1549 } elsif ($age < 60*60*2) {
1551 } elsif ($age < 60*60*24*2) {
1558 # convert age in seconds to "nn units ago" string
1563 if ($age > 60*60*24*365*2) {
1564 $age_str = (int $age/60/60/24/365);
1565 $age_str .= " years ago";
1566 } elsif ($age > 60*60*24*(365/12)*2) {
1567 $age_str = int $age/60/60/24/(365/12);
1568 $age_str .= " months ago";
1569 } elsif ($age > 60*60*24*7*2) {
1570 $age_str = int $age/60/60/24/7;
1571 $age_str .= " weeks ago";
1572 } elsif ($age > 60*60*24*2) {
1573 $age_str = int $age/60/60/24;
1574 $age_str .= " days ago";
1575 } elsif ($age > 60*60*2) {
1576 $age_str = int $age/60/60;
1577 $age_str .= " hours ago";
1578 } elsif ($age > 60*2) {
1579 $age_str = int $age/60;
1580 $age_str .= " min ago";
1581 } elsif ($age > 2) {
1582 $age_str = int $age;
1583 $age_str .= " sec ago";
1585 $age_str .= " right now";
1591 S_IFINVALID
=> 0030000,
1592 S_IFGITLINK
=> 0160000,
1595 # submodule/subproject, a commit object reference
1599 return (($mode & S_IFMT
) == S_IFGITLINK
)
1602 # convert file mode in octal to symbolic file mode string
1604 my $mode = oct shift;
1606 if (S_ISGITLINK
($mode)) {
1607 return 'm---------';
1608 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1609 return 'drwxr-xr-x';
1610 } elsif (S_ISLNK
($mode)) {
1611 return 'lrwxrwxrwx';
1612 } elsif (S_ISREG
($mode)) {
1613 # git cares only about the executable bit
1614 if ($mode & S_IXUSR
) {
1615 return '-rwxr-xr-x';
1617 return '-rw-r--r--';
1620 return '----------';
1624 # convert file mode in octal to file type string
1628 if ($mode !~ m/^[0-7]+$/) {
1634 if (S_ISGITLINK
($mode)) {
1636 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1638 } elsif (S_ISLNK
($mode)) {
1640 } elsif (S_ISREG
($mode)) {
1647 # convert file mode in octal to file type description string
1648 sub file_type_long
{
1651 if ($mode !~ m/^[0-7]+$/) {
1657 if (S_ISGITLINK
($mode)) {
1659 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1661 } elsif (S_ISLNK
($mode)) {
1663 } elsif (S_ISREG
($mode)) {
1664 if ($mode & S_IXUSR
) {
1665 return "executable";
1675 ## ----------------------------------------------------------------------
1676 ## functions returning short HTML fragments, or transforming HTML fragments
1677 ## which don't belong to other sections
1679 # format line of commit message.
1680 sub format_log_line_html
{
1683 $line = esc_html
($line, -nbsp
=>1);
1684 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1685 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1686 -class => "text"}, $1);
1692 # format marker of refs pointing to given object
1694 # the destination action is chosen based on object type and current context:
1695 # - for annotated tags, we choose the tag view unless it's the current view
1696 # already, in which case we go to shortlog view
1697 # - for other refs, we keep the current view if we're in history, shortlog or
1698 # log view, and select shortlog otherwise
1699 sub format_ref_marker
{
1700 my ($refs, $id) = @_;
1703 if (defined $refs->{$id}) {
1704 foreach my $ref (@
{$refs->{$id}}) {
1705 # this code exploits the fact that non-lightweight tags are the
1706 # only indirect objects, and that they are the only objects for which
1707 # we want to use tag instead of shortlog as action
1708 my ($type, $name) = qw();
1709 my $indirect = ($ref =~ s/\^\{\}$//);
1710 # e.g. tags/v2.6.11 or heads/next
1711 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1720 $class .= " indirect" if $indirect;
1722 my $dest_action = "shortlog";
1725 $dest_action = "tag" unless $action eq "tag";
1726 } elsif ($action =~ /^(history|(short)?log)$/) {
1727 $dest_action = $action;
1731 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1734 my $link = $cgi->a({
1736 action
=>$dest_action,
1740 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1746 return ' <span class="refs">'. $markers . '</span>';
1752 # format, perhaps shortened and with markers, title line
1753 sub format_subject_html
{
1754 my ($long, $short, $href, $extra) = @_;
1755 $extra = '' unless defined($extra);
1757 if (length($short) < length($long)) {
1758 $long =~ s/[[:cntrl:]]/?/g;
1759 return $cgi->a({-href
=> $href, -class => "list subject",
1760 -title
=> to_utf8
($long)},
1761 esc_html
($short)) . $extra;
1763 return $cgi->a({-href
=> $href, -class => "list subject"},
1764 esc_html
($long)) . $extra;
1768 # Rather than recomputing the url for an email multiple times, we cache it
1769 # after the first hit. This gives a visible benefit in views where the avatar
1770 # for the same email is used repeatedly (e.g. shortlog).
1771 # The cache is shared by all avatar engines (currently gravatar only), which
1772 # are free to use it as preferred. Since only one avatar engine is used for any
1773 # given page, there's no risk for cache conflicts.
1774 our %avatar_cache = ();
1776 # Compute the picon url for a given email, by using the picon search service over at
1777 # http://www.cs.indiana.edu/picons/search.html
1779 my $email = lc shift;
1780 if (!$avatar_cache{$email}) {
1781 my ($user, $domain) = split('@', $email);
1782 $avatar_cache{$email} =
1783 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1785 "users+domains+unknown/up/single";
1787 return $avatar_cache{$email};
1790 # Compute the gravatar url for a given email, if it's not in the cache already.
1791 # Gravatar stores only the part of the URL before the size, since that's the
1792 # one computationally more expensive. This also allows reuse of the cache for
1793 # different sizes (for this particular engine).
1795 my $email = lc shift;
1797 $avatar_cache{$email} ||=
1798 "http://www.gravatar.com/avatar/" .
1799 Digest
::MD5
::md5_hex
($email) . "?s=";
1800 return $avatar_cache{$email} . $size;
1803 # Insert an avatar for the given $email at the given $size if the feature
1805 sub git_get_avatar
{
1806 my ($email, %opts) = @_;
1807 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1808 my $post_white = ($opts{-pad_after
} ?
" " : "");
1809 $opts{-size
} ||= 'default';
1810 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1812 if ($git_avatar eq 'gravatar') {
1813 $url = gravatar_url
($email, $size);
1814 } elsif ($git_avatar eq 'picon') {
1815 $url = picon_url
($email);
1817 # Other providers can be added by extending the if chain, defining $url
1818 # as needed. If no variant puts something in $url, we assume avatars
1819 # are completely disabled/unavailable.
1822 "<img width=\"$size\" " .
1823 "class=\"avatar\" " .
1832 sub format_search_author
{
1833 my ($author, $searchtype, $displaytext) = @_;
1834 my $have_search = gitweb_check_feature
('search');
1838 if ($searchtype eq 'author') {
1839 $performed = "authored";
1840 } elsif ($searchtype eq 'committer') {
1841 $performed = "committed";
1844 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1845 searchtext
=>$author,
1846 searchtype
=>$searchtype), class=>"list",
1847 title
=>"Search for commits $performed by $author"},
1851 return $displaytext;
1855 # format the author name of the given commit with the given tag
1856 # the author name is chopped and escaped according to the other
1857 # optional parameters (see chop_str).
1858 sub format_author_html
{
1861 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1862 return "<$tag class=\"author\">" .
1863 format_search_author
($co->{'author_name'}, "author",
1864 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1869 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1870 sub format_git_diff_header_line
{
1872 my $diffinfo = shift;
1873 my ($from, $to) = @_;
1875 if ($diffinfo->{'nparents'}) {
1877 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1878 if ($to->{'href'}) {
1879 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1880 esc_path
($to->{'file'}));
1881 } else { # file was deleted (no href)
1882 $line .= esc_path
($to->{'file'});
1886 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1887 if ($from->{'href'}) {
1888 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1889 'a/' . esc_path
($from->{'file'}));
1890 } else { # file was added (no href)
1891 $line .= 'a/' . esc_path
($from->{'file'});
1894 if ($to->{'href'}) {
1895 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1896 'b/' . esc_path
($to->{'file'}));
1897 } else { # file was deleted
1898 $line .= 'b/' . esc_path
($to->{'file'});
1902 return "<div class=\"diff header\">$line</div>\n";
1905 # format extended diff header line, before patch itself
1906 sub format_extended_diff_header_line
{
1908 my $diffinfo = shift;
1909 my ($from, $to) = @_;
1912 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1913 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1914 esc_path
($from->{'file'}));
1916 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1917 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1918 esc_path
($to->{'file'}));
1920 # match single <mode>
1921 if ($line =~ m/\s(\d{6})$/) {
1922 $line .= '<span class="info"> (' .
1923 file_type_long
($1) .
1927 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1928 # can match only for combined diff
1930 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1931 if ($from->{'href'}[$i]) {
1932 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1934 substr($diffinfo->{'from_id'}[$i],0,7));
1939 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1942 if ($to->{'href'}) {
1943 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1944 substr($diffinfo->{'to_id'},0,7));
1949 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1950 # can match only for ordinary diff
1951 my ($from_link, $to_link);
1952 if ($from->{'href'}) {
1953 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1954 substr($diffinfo->{'from_id'},0,7));
1956 $from_link = '0' x
7;
1958 if ($to->{'href'}) {
1959 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1960 substr($diffinfo->{'to_id'},0,7));
1964 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1965 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1968 return $line . "<br/>\n";
1971 # format from-file/to-file diff header
1972 sub format_diff_from_to_header
{
1973 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1978 #assert($line =~ m/^---/) if DEBUG;
1979 # no extra formatting for "^--- /dev/null"
1980 if (! $diffinfo->{'nparents'}) {
1981 # ordinary (single parent) diff
1982 if ($line =~ m!^--- "?a/!) {
1983 if ($from->{'href'}) {
1985 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1986 esc_path
($from->{'file'}));
1989 esc_path
($from->{'file'});
1992 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1995 # combined diff (merge commit)
1996 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1997 if ($from->{'href'}[$i]) {
1999 $cgi->a({-href
=>href
(action
=>"blobdiff",
2000 hash_parent
=>$diffinfo->{'from_id'}[$i],
2001 hash_parent_base
=>$parents[$i],
2002 file_parent
=>$from->{'file'}[$i],
2003 hash
=>$diffinfo->{'to_id'},
2005 file_name
=>$to->{'file'}),
2007 -title
=>"diff" . ($i+1)},
2010 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2011 esc_path
($from->{'file'}[$i]));
2013 $line = '--- /dev/null';
2015 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2020 #assert($line =~ m/^\+\+\+/) if DEBUG;
2021 # no extra formatting for "^+++ /dev/null"
2022 if ($line =~ m!^\+\+\+ "?b/!) {
2023 if ($to->{'href'}) {
2025 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2026 esc_path
($to->{'file'}));
2029 esc_path
($to->{'file'});
2032 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2037 # create note for patch simplified by combined diff
2038 sub format_diff_cc_simplified
{
2039 my ($diffinfo, @parents) = @_;
2042 $result .= "<div class=\"diff header\">" .
2044 if (!is_deleted
($diffinfo)) {
2045 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2047 hash
=>$diffinfo->{'to_id'},
2048 file_name
=>$diffinfo->{'to_file'}),
2050 esc_path
($diffinfo->{'to_file'}));
2052 $result .= esc_path
($diffinfo->{'to_file'});
2054 $result .= "</div>\n" . # class="diff header"
2055 "<div class=\"diff nodifferences\">" .
2057 "</div>\n"; # class="diff nodifferences"
2062 # format patch (diff) line (not to be used for diff headers)
2063 sub format_diff_line
{
2065 my ($from, $to) = @_;
2066 my $diff_class = "";
2070 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2072 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2073 if ($line =~ m/^\@{3}/) {
2074 $diff_class = " chunk_header";
2075 } elsif ($line =~ m/^\\/) {
2076 $diff_class = " incomplete";
2077 } elsif ($prefix =~ tr/+/+/) {
2078 $diff_class = " add";
2079 } elsif ($prefix =~ tr/-/-/) {
2080 $diff_class = " rem";
2083 # assume ordinary diff
2084 my $char = substr($line, 0, 1);
2086 $diff_class = " add";
2087 } elsif ($char eq '-') {
2088 $diff_class = " rem";
2089 } elsif ($char eq '@') {
2090 $diff_class = " chunk_header";
2091 } elsif ($char eq "\\") {
2092 $diff_class = " incomplete";
2095 $line = untabify
($line);
2096 if ($from && $to && $line =~ m/^\@{2} /) {
2097 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2098 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2100 $from_lines = 0 unless defined $from_lines;
2101 $to_lines = 0 unless defined $to_lines;
2103 if ($from->{'href'}) {
2104 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2105 -class=>"list"}, $from_text);
2107 if ($to->{'href'}) {
2108 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2109 -class=>"list"}, $to_text);
2111 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2112 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2113 return "<div class=\"diff$diff_class\">$line</div>\n";
2114 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2115 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2116 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2118 @from_text = split(' ', $ranges);
2119 for (my $i = 0; $i < @from_text; ++$i) {
2120 ($from_start[$i], $from_nlines[$i]) =
2121 (split(',', substr($from_text[$i], 1)), 0);
2124 $to_text = pop @from_text;
2125 $to_start = pop @from_start;
2126 $to_nlines = pop @from_nlines;
2128 $line = "<span class=\"chunk_info\">$prefix ";
2129 for (my $i = 0; $i < @from_text; ++$i) {
2130 if ($from->{'href'}[$i]) {
2131 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2132 -class=>"list"}, $from_text[$i]);
2134 $line .= $from_text[$i];
2138 if ($to->{'href'}) {
2139 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2140 -class=>"list"}, $to_text);
2144 $line .= " $prefix</span>" .
2145 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2146 return "<div class=\"diff$diff_class\">$line</div>\n";
2148 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2151 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2152 # linked. Pass the hash of the tree/commit to snapshot.
2153 sub format_snapshot_links
{
2155 my $num_fmts = @snapshot_fmts;
2156 if ($num_fmts > 1) {
2157 # A parenthesized list of links bearing format names.
2158 # e.g. "snapshot (_tar.gz_ _zip_)"
2159 return "snapshot (" . join(' ', map
2166 }, $known_snapshot_formats{$_}{'display'})
2167 , @snapshot_fmts) . ")";
2168 } elsif ($num_fmts == 1) {
2169 # A single "snapshot" link whose tooltip bears the format name.
2171 my ($fmt) = @snapshot_fmts;
2177 snapshot_format
=>$fmt
2179 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2181 } else { # $num_fmts == 0
2186 ## ......................................................................
2187 ## functions returning values to be passed, perhaps after some
2188 ## transformation, to other functions; e.g. returning arguments to href()
2190 # returns hash to be passed to href to generate gitweb URL
2191 # in -title key it returns description of link
2193 my $format = shift || 'Atom';
2194 my %res = (action
=> lc($format));
2196 # feed links are possible only for project views
2197 return unless (defined $project);
2198 # some views should link to OPML, or to generic project feed,
2199 # or don't have specific feed yet (so they should use generic)
2200 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2203 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2204 # from tag links; this also makes possible to detect branch links
2205 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2206 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2209 # find log type for feed description (title)
2211 if (defined $file_name) {
2212 $type = "history of $file_name";
2213 $type .= "/" if ($action eq 'tree');
2214 $type .= " on '$branch'" if (defined $branch);
2216 $type = "log of $branch" if (defined $branch);
2219 $res{-title
} = $type;
2220 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2221 $res{'file_name'} = $file_name;
2226 ## ----------------------------------------------------------------------
2227 ## git utility subroutines, invoking git commands
2229 # returns path to the core git executable and the --git-dir parameter as list
2231 $number_of_git_cmds++;
2232 return $GIT, '--git-dir='.$git_dir;
2235 # quote the given arguments for passing them to the shell
2236 # quote_command("command", "arg 1", "arg with ' and ! characters")
2237 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2238 # Try to avoid using this function wherever possible.
2241 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2244 # get HEAD ref of given project as hash
2245 sub git_get_head_hash
{
2246 return git_get_full_hash
(shift, 'HEAD');
2249 sub git_get_full_hash
{
2250 return git_get_hash
(@_);
2253 sub git_get_short_hash
{
2254 return git_get_hash
(@_, '--short=7');
2258 my ($project, $hash, @options) = @_;
2259 my $o_git_dir = $git_dir;
2261 $git_dir = "$projectroot/$project";
2262 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2263 '--verify', '-q', @options, $hash) {
2265 chomp $retval if defined $retval;
2268 if (defined $o_git_dir) {
2269 $git_dir = $o_git_dir;
2274 # get type of given object
2278 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2280 close $fd or return;
2285 # repository configuration
2286 our $config_file = '';
2289 # store multiple values for single key as anonymous array reference
2290 # single values stored directly in the hash, not as [ <value> ]
2291 sub hash_set_multi
{
2292 my ($hash, $key, $value) = @_;
2294 if (!exists $hash->{$key}) {
2295 $hash->{$key} = $value;
2296 } elsif (!ref $hash->{$key}) {
2297 $hash->{$key} = [ $hash->{$key}, $value ];
2299 push @
{$hash->{$key}}, $value;
2303 # return hash of git project configuration
2304 # optionally limited to some section, e.g. 'gitweb'
2305 sub git_parse_project_config
{
2306 my $section_regexp = shift;
2311 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2314 while (my $keyval = <$fh>) {
2316 my ($key, $value) = split(/\n/, $keyval, 2);
2318 hash_set_multi
(\
%config, $key, $value)
2319 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2326 # convert config value to boolean: 'true' or 'false'
2327 # no value, number > 0, 'true' and 'yes' values are true
2328 # rest of values are treated as false (never as error)
2329 sub config_to_bool
{
2332 return 1 if !defined $val; # section.key
2334 # strip leading and trailing whitespace
2338 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2339 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2342 # convert config value to simple decimal number
2343 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2344 # to be multiplied by 1024, 1048576, or 1073741824
2348 # strip leading and trailing whitespace
2352 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2354 # unknown unit is treated as 1
2355 return $num * ($unit eq 'g' ?
1073741824 :
2356 $unit eq 'm' ?
1048576 :
2357 $unit eq 'k' ?
1024 : 1);
2362 # convert config value to array reference, if needed
2363 sub config_to_multi
{
2366 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2369 sub git_get_project_config
{
2370 my ($key, $type) = @_;
2372 return unless defined $git_dir;
2375 return unless ($key);
2376 $key =~ s/^gitweb\.//;
2377 return if ($key =~ m/\W/);
2380 if (defined $type) {
2383 unless ($type eq 'bool' || $type eq 'int');
2387 if (!defined $config_file ||
2388 $config_file ne "$git_dir/config") {
2389 %config = git_parse_project_config
('gitweb');
2390 $config_file = "$git_dir/config";
2393 # check if config variable (key) exists
2394 return unless exists $config{"gitweb.$key"};
2397 if (!defined $type) {
2398 return $config{"gitweb.$key"};
2399 } elsif ($type eq 'bool') {
2400 # backward compatibility: 'git config --bool' returns true/false
2401 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2402 } elsif ($type eq 'int') {
2403 return config_to_int
($config{"gitweb.$key"});
2405 return $config{"gitweb.$key"};
2408 # get hash of given path at given ref
2409 sub git_get_hash_by_path
{
2411 my $path = shift || return undef;
2416 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2417 or die_error
(500, "Open git-ls-tree failed");
2419 close $fd or return undef;
2421 if (!defined $line) {
2422 # there is no tree or hash given by $path at $base
2426 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2427 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2428 if (defined $type && $type ne $2) {
2429 # type doesn't match
2435 # get path of entry with given hash at given tree-ish (ref)
2436 # used to get 'from' filename for combined diff (merge commit) for renames
2437 sub git_get_path_by_hash
{
2438 my $base = shift || return;
2439 my $hash = shift || return;
2443 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2445 while (my $line = <$fd>) {
2448 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2449 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2450 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2459 ## ......................................................................
2460 ## git utility functions, directly accessing git repository
2462 sub git_get_project_description
{
2465 $git_dir = "$projectroot/$path";
2466 open my $fd, '<', "$git_dir/description"
2467 or return git_get_project_config
('description');
2470 if (defined $descr) {
2476 sub git_get_project_ctags
{
2480 $git_dir = "$projectroot/$path";
2481 opendir my $dh, "$git_dir/ctags"
2483 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2484 open my $ct, '<', $_ or next;
2488 my $ctag = $_; $ctag =~ s
#.*/##;
2489 $ctags->{$ctag} = $val;
2495 sub git_populate_project_tagcloud
{
2498 # First, merge different-cased tags; tags vote on casing
2500 foreach (keys %$ctags) {
2501 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2502 if (not $ctags_lc{lc $_}->{topcount
}
2503 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2504 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2505 $ctags_lc{lc $_}->{topname
} = $_;
2510 if (eval { require HTML
::TagCloud
; 1; }) {
2511 $cloud = HTML
::TagCloud
->new;
2512 foreach (sort keys %ctags_lc) {
2513 # Pad the title with spaces so that the cloud looks
2515 my $title = $ctags_lc{$_}->{topname
};
2516 $title =~ s/ / /g;
2517 $title =~ s/^/ /g;
2518 $title =~ s/$/ /g;
2519 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2522 $cloud = \
%ctags_lc;
2527 sub git_show_project_tagcloud
{
2528 my ($cloud, $count) = @_;
2529 print STDERR
ref($cloud)."..\n";
2530 if (ref $cloud eq 'HTML::TagCloud') {
2531 return $cloud->html_and_css($count);
2533 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2534 return '<p align="center">' . join (', ', map {
2535 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2536 } splice(@tags, 0, $count)) . '</p>';
2540 sub git_get_project_url_list
{
2543 $git_dir = "$projectroot/$path";
2544 open my $fd, '<', "$git_dir/cloneurl"
2545 or return wantarray ?
2546 @
{ config_to_multi
(git_get_project_config
('url')) } :
2547 config_to_multi
(git_get_project_config
('url'));
2548 my @git_project_url_list = map { chomp; $_ } <$fd>;
2551 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2554 sub git_get_projects_list
{
2559 $filter =~ s/\.git$//;
2561 my $check_forks = gitweb_check_feature
('forks');
2563 if (-d
$projects_list) {
2564 # search in directory
2565 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2566 # remove the trailing "/"
2568 my $pfxlen = length("$dir");
2569 my $pfxdepth = ($dir =~ tr!/!!);
2572 follow_fast
=> 1, # follow symbolic links
2573 follow_skip
=> 2, # ignore duplicates
2574 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2577 our $project_maxdepth;
2579 # skip project-list toplevel, if we get it.
2580 return if (m!^[/.]$!);
2581 # only directories can be git repositories
2582 return unless (-d
$_);
2583 # don't traverse too deep (Find is super slow on os x)
2584 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2585 $File::Find
::prune
= 1;
2589 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2590 # we check related file in $projectroot
2591 my $path = ($filter ?
"$filter/" : '') . $subdir;
2592 if (check_export_ok
("$projectroot/$path")) {
2593 push @list, { path
=> $path };
2594 $File::Find
::prune
= 1;
2599 } elsif (-f
$projects_list) {
2600 # read from file(url-encoded):
2601 # 'git%2Fgit.git Linus+Torvalds'
2602 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2603 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2605 open my $fd, '<', $projects_list or return;
2607 while (my $line = <$fd>) {
2609 my ($path, $owner) = split ' ', $line;
2610 $path = unescape
($path);
2611 $owner = unescape
($owner);
2612 if (!defined $path) {
2615 if ($filter ne '') {
2616 # looking for forks;
2617 my $pfx = substr($path, 0, length($filter));
2618 if ($pfx ne $filter) {
2621 my $sfx = substr($path, length($filter));
2622 if ($sfx !~ /^\/.*\
.git
$/) {
2625 } elsif ($check_forks) {
2627 foreach my $filter (keys %paths) {
2628 # looking for forks;
2629 my $pfx = substr($path, 0, length($filter));
2630 if ($pfx ne $filter) {
2633 my $sfx = substr($path, length($filter));
2634 if ($sfx !~ /^\/.*\
.git
$/) {
2637 # is a fork, don't include it in
2642 if (check_export_ok
("$projectroot/$path")) {
2645 owner
=> to_utf8
($owner),
2648 (my $forks_path = $path) =~ s/\.git$//;
2649 $paths{$forks_path}++;
2657 our $gitweb_project_owner = undef;
2658 sub git_get_project_list_from_file
{
2660 return if (defined $gitweb_project_owner);
2662 $gitweb_project_owner = {};
2663 # read from file (url-encoded):
2664 # 'git%2Fgit.git Linus+Torvalds'
2665 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2666 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2667 if (-f
$projects_list) {
2668 open(my $fd, '<', $projects_list);
2669 while (my $line = <$fd>) {
2671 my ($pr, $ow) = split ' ', $line;
2672 $pr = unescape
($pr);
2673 $ow = unescape
($ow);
2674 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2680 sub git_get_project_owner
{
2681 my $project = shift;
2684 return undef unless $project;
2685 $git_dir = "$projectroot/$project";
2687 if (!defined $gitweb_project_owner) {
2688 git_get_project_list_from_file
();
2691 if (exists $gitweb_project_owner->{$project}) {
2692 $owner = $gitweb_project_owner->{$project};
2694 if (!defined $owner){
2695 $owner = git_get_project_config
('owner');
2697 if (!defined $owner) {
2698 $owner = get_file_owner
("$git_dir");
2704 sub git_get_last_activity
{
2708 $git_dir = "$projectroot/$path";
2709 open($fd, "-|", git_cmd
(), 'for-each-ref',
2710 '--format=%(committer)',
2711 '--sort=-committerdate',
2713 'refs/heads') or return;
2714 my $most_recent = <$fd>;
2715 close $fd or return;
2716 if (defined $most_recent &&
2717 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2719 my $age = time - $timestamp;
2720 return ($age, age_string
($age));
2722 return (undef, undef);
2725 sub git_get_references
{
2726 my $type = shift || "";
2728 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2729 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2730 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2731 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2734 while (my $line = <$fd>) {
2736 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2737 if (defined $refs{$1}) {
2738 push @
{$refs{$1}}, $2;
2744 close $fd or return;
2748 sub git_get_rev_name_tags
{
2749 my $hash = shift || return undef;
2751 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2753 my $name_rev = <$fd>;
2756 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2759 # catches also '$hash undefined' output
2764 ## ----------------------------------------------------------------------
2765 ## parse to hash functions
2769 my $tz = shift || "-0000";
2772 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2773 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2774 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2775 $date{'hour'} = $hour;
2776 $date{'minute'} = $min;
2777 $date{'mday'} = $mday;
2778 $date{'day'} = $days[$wday];
2779 $date{'month'} = $months[$mon];
2780 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2781 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2782 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2783 $mday, $months[$mon], $hour ,$min;
2784 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2785 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2787 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2788 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2789 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2790 $date{'hour_local'} = $hour;
2791 $date{'minute_local'} = $min;
2792 $date{'tz_local'} = $tz;
2793 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2794 1900+$year, $mon+1, $mday,
2795 $hour, $min, $sec, $tz);
2804 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2805 $tag{'id'} = $tag_id;
2806 while (my $line = <$fd>) {
2808 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2809 $tag{'object'} = $1;
2810 } elsif ($line =~ m/^type (.+)$/) {
2812 } elsif ($line =~ m/^tag (.+)$/) {
2814 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2815 $tag{'author'} = $1;
2816 $tag{'author_epoch'} = $2;
2817 $tag{'author_tz'} = $3;
2818 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2819 $tag{'author_name'} = $1;
2820 $tag{'author_email'} = $2;
2822 $tag{'author_name'} = $tag{'author'};
2824 } elsif ($line =~ m/--BEGIN/) {
2825 push @comment, $line;
2827 } elsif ($line eq "") {
2831 push @comment, <$fd>;
2832 $tag{'comment'} = \
@comment;
2833 close $fd or return;
2834 if (!defined $tag{'name'}) {
2840 sub parse_commit_text
{
2841 my ($commit_text, $withparents) = @_;
2842 my @commit_lines = split '\n', $commit_text;
2845 pop @commit_lines; # Remove '\0'
2847 if (! @commit_lines) {
2851 my $header = shift @commit_lines;
2852 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2855 ($co{'id'}, my @parents) = split ' ', $header;
2856 while (my $line = shift @commit_lines) {
2857 last if $line eq "\n";
2858 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2860 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2862 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2863 $co{'author'} = to_utf8
($1);
2864 $co{'author_epoch'} = $2;
2865 $co{'author_tz'} = $3;
2866 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2867 $co{'author_name'} = $1;
2868 $co{'author_email'} = $2;
2870 $co{'author_name'} = $co{'author'};
2872 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2873 $co{'committer'} = to_utf8
($1);
2874 $co{'committer_epoch'} = $2;
2875 $co{'committer_tz'} = $3;
2876 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2877 $co{'committer_name'} = $1;
2878 $co{'committer_email'} = $2;
2880 $co{'committer_name'} = $co{'committer'};
2884 if (!defined $co{'tree'}) {
2887 $co{'parents'} = \
@parents;
2888 $co{'parent'} = $parents[0];
2890 foreach my $title (@commit_lines) {
2893 $co{'title'} = chop_str
($title, 80, 5);
2894 # remove leading stuff of merges to make the interesting part visible
2895 if (length($title) > 50) {
2896 $title =~ s/^Automatic //;
2897 $title =~ s/^merge (of|with) /Merge ... /i;
2898 if (length($title) > 50) {
2899 $title =~ s/(http|rsync):\/\///;
2901 if (length($title) > 50) {
2902 $title =~ s/(master|www|rsync)\.//;
2904 if (length($title) > 50) {
2905 $title =~ s/kernel.org:?//;
2907 if (length($title) > 50) {
2908 $title =~ s/\/pub\/scm//;
2911 $co{'title_short'} = chop_str
($title, 50, 5);
2915 if (! defined $co{'title'} || $co{'title'} eq "") {
2916 $co{'title'} = $co{'title_short'} = '(no commit message)';
2918 # remove added spaces
2919 foreach my $line (@commit_lines) {
2922 $co{'comment'} = \
@commit_lines;
2924 my $age = time - $co{'committer_epoch'};
2926 $co{'age_string'} = age_string
($age);
2927 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2928 if ($age > 60*60*24*7*2) {
2929 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2930 $co{'age_string_age'} = $co{'age_string'};
2932 $co{'age_string_date'} = $co{'age_string'};
2933 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2939 my ($commit_id) = @_;
2944 open my $fd, "-|", git_cmd
(), "rev-list",
2950 or die_error
(500, "Open git-rev-list failed");
2951 %co = parse_commit_text
(<$fd>, 1);
2958 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2966 open my $fd, "-|", git_cmd
(), "rev-list",
2969 ("--max-count=" . $maxcount),
2970 ("--skip=" . $skip),
2974 ($filename ?
($filename) : ())
2975 or die_error
(500, "Open git-rev-list failed");
2976 while (my $line = <$fd>) {
2977 my %co = parse_commit_text
($line);
2982 return wantarray ?
@cos : \
@cos;
2985 # parse line of git-diff-tree "raw" output
2986 sub parse_difftree_raw_line
{
2990 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2991 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2992 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2993 $res{'from_mode'} = $1;
2994 $res{'to_mode'} = $2;
2995 $res{'from_id'} = $3;
2997 $res{'status'} = $5;
2998 $res{'similarity'} = $6;
2999 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
3000 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
3002 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3005 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3006 # combined diff (for merge commit)
3007 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3008 $res{'nparents'} = length($1);
3009 $res{'from_mode'} = [ split(' ', $2) ];
3010 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3011 $res{'from_id'} = [ split(' ', $3) ];
3012 $res{'to_id'} = pop @
{$res{'from_id'}};
3013 $res{'status'} = [ split('', $4) ];
3014 $res{'to_file'} = unquote
($5);
3016 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3017 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3018 $res{'commit'} = $1;
3021 return wantarray ?
%res : \
%res;
3024 # wrapper: return parsed line of git-diff-tree "raw" output
3025 # (the argument might be raw line, or parsed info)
3026 sub parsed_difftree_line
{
3027 my $line_or_ref = shift;
3029 if (ref($line_or_ref) eq "HASH") {
3030 # pre-parsed (or generated by hand)
3031 return $line_or_ref;
3033 return parse_difftree_raw_line
($line_or_ref);
3037 # parse line of git-ls-tree output
3038 sub parse_ls_tree_line
{
3044 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3045 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3054 $res{'name'} = unquote
($5);
3057 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3058 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3066 $res{'name'} = unquote
($4);
3070 return wantarray ?
%res : \
%res;
3073 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3074 sub parse_from_to_diffinfo
{
3075 my ($diffinfo, $from, $to, @parents) = @_;
3077 if ($diffinfo->{'nparents'}) {
3079 $from->{'file'} = [];
3080 $from->{'href'} = [];
3081 fill_from_file_info
($diffinfo, @parents)
3082 unless exists $diffinfo->{'from_file'};
3083 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3084 $from->{'file'}[$i] =
3085 defined $diffinfo->{'from_file'}[$i] ?
3086 $diffinfo->{'from_file'}[$i] :
3087 $diffinfo->{'to_file'};
3088 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3089 $from->{'href'}[$i] = href
(action
=>"blob",
3090 hash_base
=>$parents[$i],
3091 hash
=>$diffinfo->{'from_id'}[$i],
3092 file_name
=>$from->{'file'}[$i]);
3094 $from->{'href'}[$i] = undef;
3098 # ordinary (not combined) diff
3099 $from->{'file'} = $diffinfo->{'from_file'};
3100 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3101 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3102 hash
=>$diffinfo->{'from_id'},
3103 file_name
=>$from->{'file'});
3105 delete $from->{'href'};
3109 $to->{'file'} = $diffinfo->{'to_file'};
3110 if (!is_deleted
($diffinfo)) { # file exists in result
3111 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3112 hash
=>$diffinfo->{'to_id'},
3113 file_name
=>$to->{'file'});
3115 delete $to->{'href'};
3119 ## ......................................................................
3120 ## parse to array of hashes functions
3122 sub git_get_heads_list
{
3126 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3127 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3128 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3131 while (my $line = <$fd>) {
3135 my ($refinfo, $committerinfo) = split(/\0/, $line);
3136 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3137 my ($committer, $epoch, $tz) =
3138 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3139 $ref_item{'fullname'} = $name;
3140 $name =~ s!^refs/heads/!!;
3142 $ref_item{'name'} = $name;
3143 $ref_item{'id'} = $hash;
3144 $ref_item{'title'} = $title || '(no commit message)';
3145 $ref_item{'epoch'} = $epoch;
3147 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3149 $ref_item{'age'} = "unknown";
3152 push @headslist, \
%ref_item;
3156 return wantarray ?
@headslist : \
@headslist;
3159 sub git_get_tags_list
{
3163 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3164 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3165 '--format=%(objectname) %(objecttype) %(refname) '.
3166 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3169 while (my $line = <$fd>) {
3173 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3174 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3175 my ($creator, $epoch, $tz) =
3176 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3177 $ref_item{'fullname'} = $name;
3178 $name =~ s!^refs/tags/!!;
3180 $ref_item{'type'} = $type;
3181 $ref_item{'id'} = $id;
3182 $ref_item{'name'} = $name;
3183 if ($type eq "tag") {
3184 $ref_item{'subject'} = $title;
3185 $ref_item{'reftype'} = $reftype;
3186 $ref_item{'refid'} = $refid;
3188 $ref_item{'reftype'} = $type;
3189 $ref_item{'refid'} = $id;
3192 if ($type eq "tag" || $type eq "commit") {
3193 $ref_item{'epoch'} = $epoch;
3195 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3197 $ref_item{'age'} = "unknown";
3201 push @tagslist, \
%ref_item;
3205 return wantarray ?
@tagslist : \
@tagslist;
3208 ## ----------------------------------------------------------------------
3209 ## filesystem-related functions
3211 sub get_file_owner
{
3214 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3215 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3216 if (!defined $gcos) {
3220 $owner =~ s/[,;].*$//;
3221 return to_utf8
($owner);
3224 # assume that file exists
3226 my $filename = shift;
3228 open my $fd, '<', $filename;
3229 print map { to_utf8
($_) } <$fd>;
3233 ## ......................................................................
3234 ## mimetype related functions
3236 sub mimetype_guess_file
{
3237 my $filename = shift;
3238 my $mimemap = shift;
3239 -r
$mimemap or return undef;
3242 open(my $mh, '<', $mimemap) or return undef;
3244 next if m/^#/; # skip comments
3245 my ($mimetype, $exts) = split(/\t+/);
3246 if (defined $exts) {
3247 my @exts = split(/\s+/, $exts);
3248 foreach my $ext (@exts) {
3249 $mimemap{$ext} = $mimetype;
3255 $filename =~ /\.([^.]*)$/;
3256 return $mimemap{$1};
3259 sub mimetype_guess
{
3260 my $filename = shift;
3262 $filename =~ /\./ or return undef;
3264 if ($mimetypes_file) {
3265 my $file = $mimetypes_file;
3266 if ($file !~ m!^/!) { # if it is relative path
3267 # it is relative to project
3268 $file = "$projectroot/$project/$file";
3270 $mime = mimetype_guess_file
($filename, $file);
3272 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3278 my $filename = shift;
3281 my $mime = mimetype_guess
($filename);
3282 $mime and return $mime;
3286 return $default_blob_plain_mimetype unless $fd;
3289 return 'text/plain';
3290 } elsif (! $filename) {
3291 return 'application/octet-stream';
3292 } elsif ($filename =~ m/\.png$/i) {
3294 } elsif ($filename =~ m/\.gif$/i) {
3296 } elsif ($filename =~ m/\.jpe?g$/i) {
3297 return 'image/jpeg';
3299 return 'application/octet-stream';
3303 sub blob_contenttype
{
3304 my ($fd, $file_name, $type) = @_;
3306 $type ||= blob_mimetype
($fd, $file_name);
3307 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3308 $type .= "; charset=$default_text_plain_charset";
3314 # guess file syntax for syntax highlighting; return undef if no highlighting
3315 # the name of syntax can (in the future) depend on syntax highlighter used
3316 sub guess_file_syntax
{
3317 my ($highlight, $mimetype, $file_name) = @_;
3318 return undef unless ($highlight && defined $file_name);
3320 # configuration for 'highlight' (http://www.andre-simon.de/)
3322 my %highlight_basename = (
3325 'SConstruct' => 'py', # SCons equivalent of Makefile
3326 'Makefile' => 'make',
3328 # match by extension
3329 my %highlight_ext = (
3330 # main extensions, defining name of syntax;
3331 # see files in /usr/share/highlight/langDefs/ directory
3333 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
3334 # alternate extensions, see /etc/highlight/filetypes.conf
3336 map { $_ => 'cpp' } qw(cxx c++ cc),
3337 map { $_ => 'php' } qw(php3 php4),
3338 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
3340 map { $_ => 'xml' } qw(xhtml html htm),
3343 my $basename = basename
($file_name, '.in');
3344 return $highlight_basename{$basename}
3345 if exists $highlight_basename{$basename};
3347 $basename =~ /\.([^.]*)$/;
3348 my $ext = $1 or return undef;
3349 return $highlight_ext{$ext}
3350 if exists $highlight_ext{$ext};
3355 # run highlighter and return FD of its output,
3356 # or return original FD if no highlighting
3357 sub run_highlighter
{
3358 my ($fd, $highlight, $syntax) = @_;
3359 return $fd unless ($highlight && defined $syntax);
3362 or die_error
(404, "Reading blob failed");
3363 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3364 "highlight --xhtml --fragment --syntax $syntax |"
3365 or die_error
(500, "Couldn't open file or run syntax highlighter");
3369 ## ======================================================================
3370 ## functions printing HTML: header, footer, error page
3372 sub get_page_title
{
3373 my $title = to_utf8
($site_name);
3375 return $title unless (defined $project);
3376 $title .= " - " . to_utf8
($project);
3378 return $title unless (defined $action);
3379 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3381 return $title unless (defined $file_name);
3382 $title .= " - " . esc_path
($file_name);
3383 if ($action eq "tree" && $file_name !~ m
|/$|) {
3390 sub git_header_html
{
3391 my $status = shift || "200 OK";
3392 my $expires = shift;
3395 my $title = get_page_title
();
3397 # require explicit support from the UA if we are to send the page as
3398 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3399 # we have to do this because MSIE sometimes globs '*/*', pretending to
3400 # support xhtml+xml but choking when it gets what it asked for.
3401 if (defined $cgi->http('HTTP_ACCEPT') &&
3402 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3403 $cgi->Accept('application/xhtml+xml') != 0) {
3404 $content_type = 'application/xhtml+xml';
3406 $content_type = 'text/html';
3408 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3409 -status
=> $status, -expires
=> $expires)
3410 unless ($opts{'-no_http_header'});
3411 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3413 <?xml version="1.0" encoding="utf-8"?>
3414 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3415 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3416 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3417 <!-- git core binaries version $git_version -->
3419 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3420 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3421 <meta name="robots" content="index, nofollow"/>
3422 <title>$title</title>
3424 # the stylesheet, favicon etc urls won't work correctly with path_info
3425 # unless we set the appropriate base URL
3426 if ($ENV{'PATH_INFO'}) {
3427 print "<base href=\"".esc_url
($base_url)."\" />\n";
3429 # print out each stylesheet that exist, providing backwards capability
3430 # for those people who defined $stylesheet in a config file
3431 if (defined $stylesheet) {
3432 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3434 foreach my $stylesheet (@stylesheets) {
3435 next unless $stylesheet;
3436 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3439 if (defined $project) {
3440 my %href_params = get_feed_info
();
3441 if (!exists $href_params{'-title'}) {
3442 $href_params{'-title'} = 'log';
3445 foreach my $format qw(RSS Atom) {
3446 my $type = lc($format);
3448 '-rel' => 'alternate',
3449 '-title' => "$project - $href_params{'-title'} - $format feed",
3450 '-type' => "application/$type+xml"
3453 $href_params{'action'} = $type;
3454 $link_attr{'-href'} = href
(%href_params);
3456 "rel=\"$link_attr{'-rel'}\" ".
3457 "title=\"$link_attr{'-title'}\" ".
3458 "href=\"$link_attr{'-href'}\" ".
3459 "type=\"$link_attr{'-type'}\" ".
3462 $href_params{'extra_options'} = '--no-merges';
3463 $link_attr{'-href'} = href
(%href_params);
3464 $link_attr{'-title'} .= ' (no merges)';
3466 "rel=\"$link_attr{'-rel'}\" ".
3467 "title=\"$link_attr{'-title'}\" ".
3468 "href=\"$link_attr{'-href'}\" ".
3469 "type=\"$link_attr{'-type'}\" ".
3474 printf('<link rel="alternate" title="%s projects list" '.
3475 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3476 $site_name, href
(project
=>undef, action
=>"project_index"));
3477 printf('<link rel="alternate" title="%s projects feeds" '.
3478 'href="%s" type="text/x-opml" />'."\n",
3479 $site_name, href
(project
=>undef, action
=>"opml"));
3481 if (defined $favicon) {
3482 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3488 if (defined $site_header && -f
$site_header) {
3489 insert_file
($site_header);
3492 print "<div class=\"page_header\">\n" .
3493 $cgi->a({-href
=> esc_url
($logo_url),
3494 -title
=> $logo_label},
3495 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3496 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3497 if (defined $project) {
3498 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3499 if (defined $action) {
3506 my $have_search = gitweb_check_feature
('search');
3507 if (defined $project && $have_search) {
3508 if (!defined $searchtext) {
3512 if (defined $hash_base) {
3513 $search_hash = $hash_base;
3514 } elsif (defined $hash) {
3515 $search_hash = $hash;
3517 $search_hash = "HEAD";
3519 my $action = $my_uri;
3520 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3521 if ($use_pathinfo) {
3522 $action .= "/".esc_url
($project);
3524 print $cgi->startform(-method
=> "get", -action
=> $action) .
3525 "<div class=\"search\">\n" .
3527 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3528 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3529 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3530 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3531 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3532 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3534 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3535 "<span title=\"Extended regular expression\">" .
3536 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3537 -checked
=> $search_use_regexp) .
3540 $cgi->end_form() . "\n";
3544 sub git_footer_html
{
3545 my $feed_class = 'rss_logo';
3547 print "<div class=\"page_footer\">\n";
3548 if (defined $project) {
3549 my $descr = git_get_project_description
($project);
3550 if (defined $descr) {
3551 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3554 my %href_params = get_feed_info
();
3555 if (!%href_params) {
3556 $feed_class .= ' generic';
3558 $href_params{'-title'} ||= 'log';
3560 foreach my $format qw(RSS Atom) {
3561 $href_params{'action'} = lc($format);
3562 print $cgi->a({-href
=> href
(%href_params),
3563 -title
=> "$href_params{'-title'} $format feed",
3564 -class => $feed_class}, $format)."\n";
3568 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3569 -class => $feed_class}, "OPML") . " ";
3570 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3571 -class => $feed_class}, "TXT") . "\n";
3573 print "</div>\n"; # class="page_footer"
3575 if (defined $t0 && gitweb_check_feature
('timed')) {
3576 print "<div id=\"generating_info\">\n";
3577 print 'This page took '.
3578 '<span id="generating_time" class="time_span">'.
3579 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3582 '<span id="generating_cmd">'.
3583 $number_of_git_cmds.
3584 '</span> git commands '.
3586 print "</div>\n"; # class="page_footer"
3589 if (defined $site_footer && -f
$site_footer) {
3590 insert_file
($site_footer);
3593 print qq!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3594 if (defined $action &&
3595 $action eq 'blame_incremental') {
3596 print qq!<script type
="text/javascript">\n!.
3597 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3598 qq! "!. href() .qq!");\n!.
3600 } elsif (gitweb_check_feature
('javascript-actions')) {
3601 print qq!<script type
="text/javascript">\n!.
3602 qq!window
.onload
= fixLinks
;\n!.
3610 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3611 # Example: die_error(404, 'Hash not found')
3612 # By convention, use the following status codes (as defined in RFC 2616):
3613 # 400: Invalid or missing CGI parameters, or
3614 # requested object exists but has wrong type.
3615 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3616 # this server or project.
3617 # 404: Requested object/revision/project doesn't exist.
3618 # 500: The server isn't configured properly, or
3619 # an internal error occurred (e.g. failed assertions caused by bugs), or
3620 # an unknown error occurred (e.g. the git binary died unexpectedly).
3621 # 503: The server is currently unavailable (because it is overloaded,
3622 # or down for maintenance). Generally, this is a temporary state.
3624 my $status = shift || 500;
3625 my $error = esc_html
(shift) || "Internal Server Error";
3629 my %http_responses = (
3630 400 => '400 Bad Request',
3631 403 => '403 Forbidden',
3632 404 => '404 Not Found',
3633 500 => '500 Internal Server Error',
3634 503 => '503 Service Unavailable',
3636 git_header_html
($http_responses{$status}, undef, %opts);
3638 <div class="page_body">
3643 if (defined $extra) {
3651 unless ($opts{'-error_handler'});
3654 ## ----------------------------------------------------------------------
3655 ## functions printing or outputting HTML: navigation
3657 sub git_print_page_nav
{
3658 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3659 $extra = '' if !defined $extra; # pager or formats
3661 my @navs = qw(summary shortlog log commit commitdiff tree);
3663 @navs = grep { $_ ne $suppress } @navs;
3666 my %arg = map { $_ => {action
=>$_} } @navs;
3667 if (defined $head) {
3668 for (qw(commit commitdiff)) {
3669 $arg{$_}{'hash'} = $head;
3671 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3672 for (qw(shortlog log)) {
3673 $arg{$_}{'hash'} = $head;
3678 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3679 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3681 my @actions = gitweb_get_feature
('actions');
3684 'n' => $project, # project name
3685 'f' => $git_dir, # project path within filesystem
3686 'h' => $treehead || '', # current hash ('h' parameter)
3687 'b' => $treebase || '', # hash base ('hb' parameter)
3690 my ($label, $link, $pos) = splice(@actions,0,3);
3692 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3694 $link =~ s/%([%nfhb])/$repl{$1}/g;
3695 $arg{$label}{'_href'} = $link;
3698 print "<div class=\"page_nav\">\n" .
3700 map { $_ eq $current ?
3701 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3703 print "<br/>\n$extra<br/>\n" .
3707 sub format_paging_nav
{
3708 my ($action, $page, $has_next_link) = @_;
3714 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3716 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3717 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3719 $paging_nav .= "first ⋅ prev";
3722 if ($has_next_link) {
3723 $paging_nav .= " ⋅ " .
3724 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3725 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3727 $paging_nav .= " ⋅ next";
3733 ## ......................................................................
3734 ## functions printing or outputting HTML: div
3736 sub git_print_header_div
{
3737 my ($action, $title, $hash, $hash_base) = @_;
3740 $args{'action'} = $action;
3741 $args{'hash'} = $hash if $hash;
3742 $args{'hash_base'} = $hash_base if $hash_base;
3744 print "<div class=\"header\">\n" .
3745 $cgi->a({-href
=> href
(%args), -class => "title"},
3746 $title ?
$title : $action) .
3750 sub print_local_time
{
3751 print format_local_time
(@_);
3754 sub format_local_time
{
3757 if ($date{'hour_local'} < 6) {
3758 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3759 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3761 $localtime .= sprintf(" (%02d:%02d %s)",
3762 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3768 # Outputs the author name and date in long form
3769 sub git_print_authorship
{
3772 my $tag = $opts{-tag
} || 'div';
3773 my $author = $co->{'author_name'};
3775 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3776 print "<$tag class=\"author_date\">" .
3777 format_search_author
($author, "author", esc_html
($author)) .
3779 print_local_time
(%ad) if ($opts{-localtime});
3780 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3784 # Outputs table rows containing the full author or committer information,
3785 # in the format expected for 'commit' view (& similia).
3786 # Parameters are a commit hash reference, followed by the list of people
3787 # to output information for. If the list is empty it defalts to both
3788 # author and committer.
3789 sub git_print_authorship_rows
{
3791 # too bad we can't use @people = @_ || ('author', 'committer')
3793 @people = ('author', 'committer') unless @people;
3794 foreach my $who (@people) {
3795 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3796 print "<tr><td>$who</td><td>" .
3797 format_search_author
($co->{"${who}_name"}, $who,
3798 esc_html
($co->{"${who}_name"})) . " " .
3799 format_search_author
($co->{"${who}_email"}, $who,
3800 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3801 "</td><td rowspan=\"2\">" .
3802 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3805 "<td></td><td> $wd{'rfc2822'}";
3806 print_local_time
(%wd);
3812 sub git_print_page_path
{
3818 print "<div class=\"page_path\">";
3819 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3820 -title
=> 'tree root'}, to_utf8
("[$project]"));
3822 if (defined $name) {
3823 my @dirname = split '/', $name;
3824 my $basename = pop @dirname;
3827 foreach my $dir (@dirname) {
3828 $fullname .= ($fullname ?
'/' : '') . $dir;
3829 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3831 -title
=> $fullname}, esc_path
($dir));
3834 if (defined $type && $type eq 'blob') {
3835 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3837 -title
=> $name}, esc_path
($basename));
3838 } elsif (defined $type && $type eq 'tree') {
3839 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3841 -title
=> $name}, esc_path
($basename));
3844 print esc_path
($basename);
3847 print "<br/></div>\n";
3854 if ($opts{'-remove_title'}) {
3855 # remove title, i.e. first line of log
3858 # remove leading empty lines
3859 while (defined $log->[0] && $log->[0] eq "") {
3866 foreach my $line (@
$log) {
3867 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3870 if (! $opts{'-remove_signoff'}) {
3871 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3874 # remove signoff lines
3881 # print only one empty line
3882 # do not print empty line after signoff
3884 next if ($empty || $signoff);
3890 print format_log_line_html
($line) . "<br/>\n";
3893 if ($opts{'-final_empty_line'}) {
3894 # end with single empty line
3895 print "<br/>\n" unless $empty;
3899 # return link target (what link points to)
3900 sub git_get_link_target
{
3905 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3909 $link_target = <$fd>;
3914 return $link_target;
3917 # given link target, and the directory (basedir) the link is in,
3918 # return target of link relative to top directory (top tree);
3919 # return undef if it is not possible (including absolute links).
3920 sub normalize_link_target
{
3921 my ($link_target, $basedir) = @_;
3923 # absolute symlinks (beginning with '/') cannot be normalized
3924 return if (substr($link_target, 0, 1) eq '/');
3926 # normalize link target to path from top (root) tree (dir)
3929 $path = $basedir . '/' . $link_target;
3931 # we are in top (root) tree (dir)
3932 $path = $link_target;
3935 # remove //, /./, and /../
3937 foreach my $part (split('/', $path)) {
3938 # discard '.' and ''
3939 next if (!$part || $part eq '.');
3941 if ($part eq '..') {
3945 # link leads outside repository (outside top dir)
3949 push @path_parts, $part;
3952 $path = join('/', @path_parts);
3957 # print tree entry (row of git_tree), but without encompassing <tr> element
3958 sub git_print_tree_entry
{
3959 my ($t, $basedir, $hash_base, $have_blame) = @_;
3962 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3964 # The format of a table row is: mode list link. Where mode is
3965 # the mode of the entry, list is the name of the entry, an href,
3966 # and link is the action links of the entry.
3968 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3969 if (exists $t->{'size'}) {
3970 print "<td class=\"size\">$t->{'size'}</td>\n";
3972 if ($t->{'type'} eq "blob") {
3973 print "<td class=\"list\">" .
3974 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3975 file_name
=>"$basedir$t->{'name'}", %base_key),
3976 -class => "list"}, esc_path
($t->{'name'}));
3977 if (S_ISLNK
(oct $t->{'mode'})) {
3978 my $link_target = git_get_link_target
($t->{'hash'});
3980 my $norm_target = normalize_link_target
($link_target, $basedir);
3981 if (defined $norm_target) {
3983 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3984 file_name
=>$norm_target),
3985 -title
=> $norm_target}, esc_path
($link_target));
3987 print " -> " . esc_path
($link_target);
3992 print "<td class=\"link\">";
3993 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3994 file_name
=>"$basedir$t->{'name'}", %base_key)},
3998 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3999 file_name
=>"$basedir$t->{'name'}", %base_key)},
4002 if (defined $hash_base) {
4004 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4005 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4009 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4010 file_name
=>"$basedir$t->{'name'}")},
4014 } elsif ($t->{'type'} eq "tree") {
4015 print "<td class=\"list\">";
4016 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4017 file_name
=>"$basedir$t->{'name'}",
4019 esc_path
($t->{'name'}));
4021 print "<td class=\"link\">";
4022 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4023 file_name
=>"$basedir$t->{'name'}",
4026 if (defined $hash_base) {
4028 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4029 file_name
=>"$basedir$t->{'name'}")},
4034 # unknown object: we can only present history for it
4035 # (this includes 'commit' object, i.e. submodule support)
4036 print "<td class=\"list\">" .
4037 esc_path
($t->{'name'}) .
4039 print "<td class=\"link\">";
4040 if (defined $hash_base) {
4041 print $cgi->a({-href
=> href
(action
=>"history",
4042 hash_base
=>$hash_base,
4043 file_name
=>"$basedir$t->{'name'}")},
4050 ## ......................................................................
4051 ## functions printing large fragments of HTML
4053 # get pre-image filenames for merge (combined) diff
4054 sub fill_from_file_info
{
4055 my ($diff, @parents) = @_;
4057 $diff->{'from_file'} = [ ];
4058 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4059 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4060 if ($diff->{'status'}[$i] eq 'R' ||
4061 $diff->{'status'}[$i] eq 'C') {
4062 $diff->{'from_file'}[$i] =
4063 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4070 # is current raw difftree line of file deletion
4072 my $diffinfo = shift;
4074 return $diffinfo->{'to_id'} eq ('0' x
40);
4077 # does patch correspond to [previous] difftree raw line
4078 # $diffinfo - hashref of parsed raw diff format
4079 # $patchinfo - hashref of parsed patch diff format
4080 # (the same keys as in $diffinfo)
4081 sub is_patch_split
{
4082 my ($diffinfo, $patchinfo) = @_;
4084 return defined $diffinfo && defined $patchinfo
4085 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4089 sub git_difftree_body
{
4090 my ($difftree, $hash, @parents) = @_;
4091 my ($parent) = $parents[0];
4092 my $have_blame = gitweb_check_feature
('blame');
4093 print "<div class=\"list_head\">\n";
4094 if ($#{$difftree} > 10) {
4095 print(($#{$difftree} + 1) . " files changed:\n");
4099 print "<table class=\"" .
4100 (@parents > 1 ?
"combined " : "") .
4103 # header only for combined diff in 'commitdiff' view
4104 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4107 print "<thead><tr>\n" .
4108 "<th></th><th></th>\n"; # filename, patchN link
4109 for (my $i = 0; $i < @parents; $i++) {
4110 my $par = $parents[$i];
4112 $cgi->a({-href
=> href
(action
=>"commitdiff",
4113 hash
=>$hash, hash_parent
=>$par),
4114 -title
=> 'commitdiff to parent number ' .
4115 ($i+1) . ': ' . substr($par,0,7)},
4119 print "</tr></thead>\n<tbody>\n";
4124 foreach my $line (@
{$difftree}) {
4125 my $diff = parsed_difftree_line
($line);
4128 print "<tr class=\"dark\">\n";
4130 print "<tr class=\"light\">\n";
4134 if (exists $diff->{'nparents'}) { # combined diff
4136 fill_from_file_info
($diff, @parents)
4137 unless exists $diff->{'from_file'};
4139 if (!is_deleted
($diff)) {
4140 # file exists in the result (child) commit
4142 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4143 file_name
=>$diff->{'to_file'},
4145 -class => "list"}, esc_path
($diff->{'to_file'})) .
4149 esc_path
($diff->{'to_file'}) .
4153 if ($action eq 'commitdiff') {
4156 print "<td class=\"link\">" .
4157 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4162 my $has_history = 0;
4163 my $not_deleted = 0;
4164 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4165 my $hash_parent = $parents[$i];
4166 my $from_hash = $diff->{'from_id'}[$i];
4167 my $from_path = $diff->{'from_file'}[$i];
4168 my $status = $diff->{'status'}[$i];
4170 $has_history ||= ($status ne 'A');
4171 $not_deleted ||= ($status ne 'D');
4173 if ($status eq 'A') {
4174 print "<td class=\"link\" align=\"right\"> | </td>\n";
4175 } elsif ($status eq 'D') {
4176 print "<td class=\"link\">" .
4177 $cgi->a({-href
=> href
(action
=>"blob",
4180 file_name
=>$from_path)},
4184 if ($diff->{'to_id'} eq $from_hash) {
4185 print "<td class=\"link nochange\">";
4187 print "<td class=\"link\">";
4189 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4190 hash
=>$diff->{'to_id'},
4191 hash_parent
=>$from_hash,
4193 hash_parent_base
=>$hash_parent,
4194 file_name
=>$diff->{'to_file'},
4195 file_parent
=>$from_path)},
4201 print "<td class=\"link\">";
4203 print $cgi->a({-href
=> href
(action
=>"blob",
4204 hash
=>$diff->{'to_id'},
4205 file_name
=>$diff->{'to_file'},
4208 print " | " if ($has_history);
4211 print $cgi->a({-href
=> href
(action
=>"history",
4212 file_name
=>$diff->{'to_file'},
4219 next; # instead of 'else' clause, to avoid extra indent
4221 # else ordinary diff
4223 my ($to_mode_oct, $to_mode_str, $to_file_type);
4224 my ($from_mode_oct, $from_mode_str, $from_file_type);
4225 if ($diff->{'to_mode'} ne ('0' x
6)) {
4226 $to_mode_oct = oct $diff->{'to_mode'};
4227 if (S_ISREG
($to_mode_oct)) { # only for regular file
4228 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4230 $to_file_type = file_type
($diff->{'to_mode'});
4232 if ($diff->{'from_mode'} ne ('0' x
6)) {
4233 $from_mode_oct = oct $diff->{'from_mode'};
4234 if (S_ISREG
($to_mode_oct)) { # only for regular file
4235 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4237 $from_file_type = file_type
($diff->{'from_mode'});
4240 if ($diff->{'status'} eq "A") { # created
4241 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4242 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4243 $mode_chng .= "]</span>";
4245 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4246 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4247 -class => "list"}, esc_path
($diff->{'file'}));
4249 print "<td>$mode_chng</td>\n";
4250 print "<td class=\"link\">";
4251 if ($action eq 'commitdiff') {
4254 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4257 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4258 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4262 } elsif ($diff->{'status'} eq "D") { # deleted
4263 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4265 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4266 hash_base
=>$parent, 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->{'from_id'},
4278 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4281 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4282 file_name
=>$diff->{'file'})},
4285 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4286 file_name
=>$diff->{'file'})},
4290 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4291 my $mode_chnge = "";
4292 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4293 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4294 if ($from_file_type ne $to_file_type) {
4295 $mode_chnge .= " from $from_file_type to $to_file_type";
4297 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4298 if ($from_mode_str && $to_mode_str) {
4299 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4300 } elsif ($to_mode_str) {
4301 $mode_chnge .= " mode: $to_mode_str";
4304 $mode_chnge .= "]</span>\n";
4307 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4308 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4309 -class => "list"}, esc_path
($diff->{'file'}));
4311 print "<td>$mode_chnge</td>\n";
4312 print "<td class=\"link\">";
4313 if ($action eq 'commitdiff') {
4316 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4318 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4319 # "commit" view and modified file (not onlu mode changed)
4320 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4321 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4322 hash_base
=>$hash, hash_parent_base
=>$parent,
4323 file_name
=>$diff->{'file'})},
4327 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4328 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4331 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4332 file_name
=>$diff->{'file'})},
4335 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4336 file_name
=>$diff->{'file'})},
4340 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4341 my %status_name = ('R' => 'moved', 'C' => 'copied');
4342 my $nstatus = $status_name{$diff->{'status'}};
4344 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4345 # mode also for directories, so we cannot use $to_mode_str
4346 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4349 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4350 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4351 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4352 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4353 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4354 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4355 -class => "list"}, esc_path
($diff->{'from_file'})) .
4356 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4357 "<td class=\"link\">";
4358 if ($action eq 'commitdiff') {
4361 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4363 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4364 # "commit" view and modified file (not only pure rename or copy)
4365 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4366 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4367 hash_base
=>$hash, hash_parent_base
=>$parent,
4368 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4372 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4373 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4376 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4377 file_name
=>$diff->{'to_file'})},
4380 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4381 file_name
=>$diff->{'to_file'})},
4385 } # we should not encounter Unmerged (U) or Unknown (X) status
4388 print "</tbody>" if $has_header;
4392 sub git_patchset_body
{
4393 my ($fd, $difftree, $hash, @hash_parents) = @_;
4394 my ($hash_parent) = $hash_parents[0];
4396 my $is_combined = (@hash_parents > 1);
4398 my $patch_number = 0;
4404 print "<div class=\"patchset\">\n";
4406 # skip to first patch
4407 while ($patch_line = <$fd>) {
4410 last if ($patch_line =~ m/^diff /);
4414 while ($patch_line) {
4416 # parse "git diff" header line
4417 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4418 # $1 is from_name, which we do not use
4419 $to_name = unquote
($2);
4420 $to_name =~ s!^b/!!;
4421 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4422 # $1 is 'cc' or 'combined', which we do not use
4423 $to_name = unquote
($2);
4428 # check if current patch belong to current raw line
4429 # and parse raw git-diff line if needed
4430 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4431 # this is continuation of a split patch
4432 print "<div class=\"patch cont\">\n";
4434 # advance raw git-diff output if needed
4435 $patch_idx++ if defined $diffinfo;
4437 # read and prepare patch information
4438 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4440 # compact combined diff output can have some patches skipped
4441 # find which patch (using pathname of result) we are at now;
4443 while ($to_name ne $diffinfo->{'to_file'}) {
4444 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4445 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4446 "</div>\n"; # class="patch"
4451 last if $patch_idx > $#$difftree;
4452 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4456 # modifies %from, %to hashes
4457 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4459 # this is first patch for raw difftree line with $patch_idx index
4460 # we index @$difftree array from 0, but number patches from 1
4461 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4465 #assert($patch_line =~ m/^diff /) if DEBUG;
4466 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4468 # print "git diff" header
4469 print format_git_diff_header_line
($patch_line, $diffinfo,
4472 # print extended diff header
4473 print "<div class=\"diff extended_header\">\n";
4475 while ($patch_line = <$fd>) {
4478 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4480 print format_extended_diff_header_line
($patch_line, $diffinfo,
4483 print "</div>\n"; # class="diff extended_header"
4485 # from-file/to-file diff header
4486 if (! $patch_line) {
4487 print "</div>\n"; # class="patch"
4490 next PATCH
if ($patch_line =~ m/^diff /);
4491 #assert($patch_line =~ m/^---/) if DEBUG;
4493 my $last_patch_line = $patch_line;
4494 $patch_line = <$fd>;
4496 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4498 print format_diff_from_to_header
($last_patch_line, $patch_line,
4499 $diffinfo, \
%from, \
%to,
4504 while ($patch_line = <$fd>) {
4507 next PATCH
if ($patch_line =~ m/^diff /);
4509 print format_diff_line
($patch_line, \
%from, \
%to);
4513 print "</div>\n"; # class="patch"
4516 # for compact combined (--cc) format, with chunk and patch simpliciaction
4517 # patchset might be empty, but there might be unprocessed raw lines
4518 for (++$patch_idx if $patch_number > 0;
4519 $patch_idx < @
$difftree;
4521 # read and prepare patch information
4522 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4524 # generate anchor for "patch" links in difftree / whatchanged part
4525 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4526 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4527 "</div>\n"; # class="patch"
4532 if ($patch_number == 0) {
4533 if (@hash_parents > 1) {
4534 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4536 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4540 print "</div>\n"; # class="patchset"
4543 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4545 # fills project list info (age, description, owner, forks) for each
4546 # project in the list, removing invalid projects from returned list
4547 # NOTE: modifies $projlist, but does not remove entries from it
4548 sub fill_project_list_info
{
4549 my ($projlist, $check_forks) = @_;
4552 my $show_ctags = gitweb_check_feature
('ctags');
4554 foreach my $pr (@
$projlist) {
4555 my (@activity) = git_get_last_activity
($pr->{'path'});
4556 unless (@activity) {
4559 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4560 if (!defined $pr->{'descr'}) {
4561 my $descr = git_get_project_description
($pr->{'path'}) || "";
4562 $descr = to_utf8
($descr);
4563 $pr->{'descr_long'} = $descr;
4564 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4566 if (!defined $pr->{'owner'}) {
4567 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4570 my $pname = $pr->{'path'};
4571 if (($pname =~ s/\.git$//) &&
4572 ($pname !~ /\/$/) &&
4573 (-d
"$projectroot/$pname")) {
4574 $pr->{'forks'} = "-d $projectroot/$pname";
4579 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4580 push @projects, $pr;
4586 # print 'sort by' <th> element, generating 'sort by $name' replay link
4587 # if that order is not selected
4589 print format_sort_th
(@_);
4592 sub format_sort_th
{
4593 my ($name, $order, $header) = @_;
4595 $header ||= ucfirst($name);
4597 if ($order eq $name) {
4598 $sort_th .= "<th>$header</th>\n";
4600 $sort_th .= "<th>" .
4601 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4602 -class => "header"}, $header) .
4609 sub git_project_list_body
{
4610 # actually uses global variable $project
4611 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4613 my $check_forks = gitweb_check_feature
('forks');
4614 my @projects = fill_project_list_info
($projlist, $check_forks);
4616 $order ||= $default_projects_order;
4617 $from = 0 unless defined $from;
4618 $to = $#projects if (!defined $to || $#projects < $to);
4621 project
=> { key
=> 'path', type
=> 'str' },
4622 descr
=> { key
=> 'descr_long', type
=> 'str' },
4623 owner
=> { key
=> 'owner', type
=> 'str' },
4624 age
=> { key
=> 'age', type
=> 'num' }
4626 my $oi = $order_info{$order};
4627 if ($oi->{'type'} eq 'str') {
4628 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4630 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4633 my $show_ctags = gitweb_check_feature
('ctags');
4636 foreach my $p (@projects) {
4637 foreach my $ct (keys %{$p->{'ctags'}}) {
4638 $ctags{$ct} += $p->{'ctags'}->{$ct};
4641 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4642 print git_show_project_tagcloud
($cloud, 64);
4645 print "<table class=\"project_list\">\n";
4646 unless ($no_header) {
4649 print "<th></th>\n";
4651 print_sort_th
('project', $order, 'Project');
4652 print_sort_th
('descr', $order, 'Description');
4653 print_sort_th
('owner', $order, 'Owner');
4654 print_sort_th
('age', $order, 'Last Change');
4655 print "<th></th>\n" . # for links
4659 my $tagfilter = $cgi->param('by_tag');
4660 for (my $i = $from; $i <= $to; $i++) {
4661 my $pr = $projects[$i];
4663 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4664 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4665 and not $pr->{'descr_long'} =~ /$searchtext/;
4666 # Weed out forks or non-matching entries of search
4668 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4669 $forkbase="^$forkbase" if $forkbase;
4670 next if not $searchtext and not $tagfilter and $show_ctags
4671 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4675 print "<tr class=\"dark\">\n";
4677 print "<tr class=\"light\">\n";
4682 if ($pr->{'forks'}) {
4683 print "<!-- $pr->{'forks'} -->\n";
4684 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4688 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4689 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4690 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4691 -class => "list", -title
=> $pr->{'descr_long'}},
4692 esc_html
($pr->{'descr'})) . "</td>\n" .
4693 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4694 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4695 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4696 "<td class=\"link\">" .
4697 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4698 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4699 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4700 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4701 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4705 if (defined $extra) {
4708 print "<td></td>\n";
4710 print "<td colspan=\"5\">$extra</td>\n" .
4717 # uses global variable $project
4718 my ($commitlist, $from, $to, $refs, $extra) = @_;
4720 $from = 0 unless defined $from;
4721 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4723 for (my $i = 0; $i <= $to; $i++) {
4724 my %co = %{$commitlist->[$i]};
4726 my $commit = $co{'id'};
4727 my $ref = format_ref_marker
($refs, $commit);
4728 my %ad = parse_date
($co{'author_epoch'});
4729 git_print_header_div
('commit',
4730 "<span class=\"age\">$co{'age_string'}</span>" .
4731 esc_html
($co{'title'}) . $ref,
4733 print "<div class=\"title_text\">\n" .
4734 "<div class=\"log_link\">\n" .
4735 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4737 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4739 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4742 git_print_authorship
(\
%co, -tag
=> 'span');
4743 print "<br/>\n</div>\n";
4745 print "<div class=\"log_body\">\n";
4746 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4750 print "<div class=\"page_nav\">\n";
4756 sub git_shortlog_body
{
4757 # uses global variable $project
4758 my ($commitlist, $from, $to, $refs, $extra) = @_;
4760 $from = 0 unless defined $from;
4761 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4763 print "<table class=\"shortlog\">\n";
4765 for (my $i = $from; $i <= $to; $i++) {
4766 my %co = %{$commitlist->[$i]};
4767 my $commit = $co{'id'};
4768 my $ref = format_ref_marker
($refs, $commit);
4770 print "<tr class=\"dark\">\n";
4772 print "<tr class=\"light\">\n";
4775 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4776 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4777 format_author_html
('td', \
%co, 10) . "<td>";
4778 print format_subject_html
($co{'title'}, $co{'title_short'},
4779 href
(action
=>"commit", hash
=>$commit), $ref);
4781 "<td class=\"link\">" .
4782 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4783 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4784 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4785 my $snapshot_links = format_snapshot_links
($commit);
4786 if (defined $snapshot_links) {
4787 print " | " . $snapshot_links;
4792 if (defined $extra) {
4794 "<td colspan=\"4\">$extra</td>\n" .
4800 sub git_history_body
{
4801 # Warning: assumes constant type (blob or tree) during history
4802 my ($commitlist, $from, $to, $refs, $extra,
4803 $file_name, $file_hash, $ftype) = @_;
4805 $from = 0 unless defined $from;
4806 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4808 print "<table class=\"history\">\n";
4810 for (my $i = $from; $i <= $to; $i++) {
4811 my %co = %{$commitlist->[$i]};
4815 my $commit = $co{'id'};
4817 my $ref = format_ref_marker
($refs, $commit);
4820 print "<tr class=\"dark\">\n";
4822 print "<tr class=\"light\">\n";
4825 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4826 # shortlog: format_author_html('td', \%co, 10)
4827 format_author_html
('td', \
%co, 15, 3) . "<td>";
4828 # originally git_history used chop_str($co{'title'}, 50)
4829 print format_subject_html
($co{'title'}, $co{'title_short'},
4830 href
(action
=>"commit", hash
=>$commit), $ref);
4832 "<td class=\"link\">" .
4833 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4834 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4836 if ($ftype eq 'blob') {
4837 my $blob_current = $file_hash;
4838 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4839 if (defined $blob_current && defined $blob_parent &&
4840 $blob_current ne $blob_parent) {
4842 $cgi->a({-href
=> href
(action
=>"blobdiff",
4843 hash
=>$blob_current, hash_parent
=>$blob_parent,
4844 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4845 file_name
=>$file_name)},
4852 if (defined $extra) {
4854 "<td colspan=\"4\">$extra</td>\n" .
4861 # uses global variable $project
4862 my ($taglist, $from, $to, $extra) = @_;
4863 $from = 0 unless defined $from;
4864 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4866 print "<table class=\"tags\">\n";
4868 for (my $i = $from; $i <= $to; $i++) {
4869 my $entry = $taglist->[$i];
4871 my $comment = $tag{'subject'};
4873 if (defined $comment) {
4874 $comment_short = chop_str
($comment, 30, 5);
4877 print "<tr class=\"dark\">\n";
4879 print "<tr class=\"light\">\n";
4882 if (defined $tag{'age'}) {
4883 print "<td><i>$tag{'age'}</i></td>\n";
4885 print "<td></td>\n";
4888 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4889 -class => "list name"}, esc_html
($tag{'name'})) .
4892 if (defined $comment) {
4893 print format_subject_html
($comment, $comment_short,
4894 href
(action
=>"tag", hash
=>$tag{'id'}));
4897 "<td class=\"selflink\">";
4898 if ($tag{'type'} eq "tag") {
4899 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4904 "<td class=\"link\">" . " | " .
4905 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4906 if ($tag{'reftype'} eq "commit") {
4907 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4908 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4909 } elsif ($tag{'reftype'} eq "blob") {
4910 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4915 if (defined $extra) {
4917 "<td colspan=\"5\">$extra</td>\n" .
4923 sub git_heads_body
{
4924 # uses global variable $project
4925 my ($headlist, $head, $from, $to, $extra) = @_;
4926 $from = 0 unless defined $from;
4927 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4929 print "<table class=\"heads\">\n";
4931 for (my $i = $from; $i <= $to; $i++) {
4932 my $entry = $headlist->[$i];
4934 my $curr = $ref{'id'} eq $head;
4936 print "<tr class=\"dark\">\n";
4938 print "<tr class=\"light\">\n";
4941 print "<td><i>$ref{'age'}</i></td>\n" .
4942 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4943 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4944 -class => "list name"},esc_html
($ref{'name'})) .
4946 "<td class=\"link\">" .
4947 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4948 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4949 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4953 if (defined $extra) {
4955 "<td colspan=\"3\">$extra</td>\n" .
4961 sub git_search_grep_body
{
4962 my ($commitlist, $from, $to, $extra) = @_;
4963 $from = 0 unless defined $from;
4964 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4966 print "<table class=\"commit_search\">\n";
4968 for (my $i = $from; $i <= $to; $i++) {
4969 my %co = %{$commitlist->[$i]};
4973 my $commit = $co{'id'};
4975 print "<tr class=\"dark\">\n";
4977 print "<tr class=\"light\">\n";
4980 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4981 format_author_html
('td', \
%co, 15, 5) .
4983 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4984 -class => "list subject"},
4985 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4986 my $comment = $co{'comment'};
4987 foreach my $line (@
$comment) {
4988 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4989 my ($lead, $match, $trail) = ($1, $2, $3);
4990 $match = chop_str
($match, 70, 5, 'center');
4991 my $contextlen = int((80 - length($match))/2);
4992 $contextlen = 30 if ($contextlen > 30);
4993 $lead = chop_str
($lead, $contextlen, 10, 'left');
4994 $trail = chop_str
($trail, $contextlen, 10, 'right');
4996 $lead = esc_html
($lead);
4997 $match = esc_html
($match);
4998 $trail = esc_html
($trail);
5000 print "$lead<span class=\"match\">$match</span>$trail<br />";
5004 "<td class=\"link\">" .
5005 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5007 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5009 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5013 if (defined $extra) {
5015 "<td colspan=\"3\">$extra</td>\n" .
5021 ## ======================================================================
5022 ## ======================================================================
5025 sub git_project_list
{
5026 my $order = $input_params{'order'};
5027 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5028 die_error
(400, "Unknown order parameter");
5031 my @list = git_get_projects_list
();
5033 die_error
(404, "No projects found");
5037 if (defined $home_text && -f
$home_text) {
5038 print "<div class=\"index_include\">\n";
5039 insert_file
($home_text);
5042 print $cgi->startform(-method
=> "get") .
5043 "<p class=\"projsearch\">Search:\n" .
5044 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5046 $cgi->end_form() . "\n";
5047 git_project_list_body
(\
@list, $order);
5052 my $order = $input_params{'order'};
5053 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5054 die_error
(400, "Unknown order parameter");
5057 my @list = git_get_projects_list
($project);
5059 die_error
(404, "No forks found");
5063 git_print_page_nav
('','');
5064 git_print_header_div
('summary', "$project forks");
5065 git_project_list_body
(\
@list, $order);
5069 sub git_project_index
{
5070 my @projects = git_get_projects_list
($project);
5073 -type
=> 'text/plain',
5074 -charset
=> 'utf-8',
5075 -content_disposition
=> 'inline; filename="index.aux"');
5077 foreach my $pr (@projects) {
5078 if (!exists $pr->{'owner'}) {
5079 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5082 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5083 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5084 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5085 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5089 print "$path $owner\n";
5094 my $descr = git_get_project_description
($project) || "none";
5095 my %co = parse_commit
("HEAD");
5096 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5097 my $head = $co{'id'};
5099 my $owner = git_get_project_owner
($project);
5101 my $refs = git_get_references
();
5102 # These get_*_list functions return one more to allow us to see if
5103 # there are more ...
5104 my @taglist = git_get_tags_list
(16);
5105 my @headlist = git_get_heads_list
(16);
5107 my $check_forks = gitweb_check_feature
('forks');
5110 @forklist = git_get_projects_list
($project);
5114 git_print_page_nav
('summary','', $head);
5116 print "<div class=\"title\"> </div>\n";
5117 print "<table class=\"projects_list\">\n" .
5118 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5119 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5120 if (defined $cd{'rfc2822'}) {
5121 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5124 # use per project git URL list in $projectroot/$project/cloneurl
5125 # or make project git URL from git base URL and project name
5126 my $url_tag = "URL";
5127 my @url_list = git_get_project_url_list
($project);
5128 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5129 foreach my $git_url (@url_list) {
5130 next unless $git_url;
5131 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5136 my $show_ctags = gitweb_check_feature
('ctags');
5138 my $ctags = git_get_project_ctags
($project);
5139 my $cloud = git_populate_project_tagcloud
($ctags);
5140 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5141 print "</td>\n<td>" unless %$ctags;
5142 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5143 print "</td>\n<td>" if %$ctags;
5144 print git_show_project_tagcloud
($cloud, 48);
5150 # If XSS prevention is on, we don't include README.html.
5151 # TODO: Allow a readme in some safe format.
5152 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5153 print "<div class=\"title\">readme</div>\n" .
5154 "<div class=\"readme\">\n";
5155 insert_file
("$projectroot/$project/README.html");
5156 print "\n</div>\n"; # class="readme"
5159 # we need to request one more than 16 (0..15) to check if
5161 my @commitlist = $head ? parse_commits
($head, 17) : ();
5163 git_print_header_div
('shortlog');
5164 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5165 $#commitlist <= 15 ?
undef :
5166 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5170 git_print_header_div
('tags');
5171 git_tags_body
(\
@taglist, 0, 15,
5172 $#taglist <= 15 ?
undef :
5173 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5177 git_print_header_div
('heads');
5178 git_heads_body
(\
@headlist, $head, 0, 15,
5179 $#headlist <= 15 ?
undef :
5180 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5184 git_print_header_div
('forks');
5185 git_project_list_body
(\
@forklist, 'age', 0, 15,
5186 $#forklist <= 15 ?
undef :
5187 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5195 my $head = git_get_head_hash
($project);
5197 git_print_page_nav
('','', $head,undef,$head);
5198 my %tag = parse_tag
($hash);
5201 die_error
(404, "Unknown tag object");
5204 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5205 print "<div class=\"title_text\">\n" .
5206 "<table class=\"object_header\">\n" .
5208 "<td>object</td>\n" .
5209 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5210 $tag{'object'}) . "</td>\n" .
5211 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5212 $tag{'type'}) . "</td>\n" .
5214 if (defined($tag{'author'})) {
5215 git_print_authorship_rows
(\
%tag, 'author');
5217 print "</table>\n\n" .
5219 print "<div class=\"page_body\">";
5220 my $comment = $tag{'comment'};
5221 foreach my $line (@
$comment) {
5223 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5229 sub git_blame_common
{
5230 my $format = shift || 'porcelain';
5231 if ($format eq 'porcelain' && $cgi->param('js')) {
5232 $format = 'incremental';
5233 $action = 'blame_incremental'; # for page title etc
5237 gitweb_check_feature
('blame')
5238 or die_error
(403, "Blame view not allowed");
5241 die_error
(400, "No file name given") unless $file_name;
5242 $hash_base ||= git_get_head_hash
($project);
5243 die_error
(404, "Couldn't find base commit") unless $hash_base;
5244 my %co = parse_commit
($hash_base)
5245 or die_error
(404, "Commit not found");
5247 if (!defined $hash) {
5248 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5249 or die_error
(404, "Error looking up file");
5251 $ftype = git_get_type
($hash);
5252 if ($ftype !~ "blob") {
5253 die_error
(400, "Object is not a blob");
5258 if ($format eq 'incremental') {
5259 # get file contents (as base)
5260 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5261 or die_error
(500, "Open git-cat-file failed");
5262 } elsif ($format eq 'data') {
5263 # run git-blame --incremental
5264 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5265 $hash_base, "--", $file_name
5266 or die_error
(500, "Open git-blame --incremental failed");
5268 # run git-blame --porcelain
5269 open $fd, "-|", git_cmd
(), "blame", '-p',
5270 $hash_base, '--', $file_name
5271 or die_error
(500, "Open git-blame --porcelain failed");
5274 # incremental blame data returns early
5275 if ($format eq 'data') {
5277 -type
=>"text/plain", -charset
=> "utf-8",
5278 -status
=> "200 OK");
5279 local $| = 1; # output autoflush
5282 or print "ERROR $!\n";
5285 if (defined $t0 && gitweb_check_feature
('timed')) {
5287 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5288 ' '.$number_of_git_cmds;
5298 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5301 if ($format eq 'incremental') {
5303 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5304 "blame") . " (non-incremental)";
5307 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5308 "blame") . " (incremental)";
5312 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5315 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5317 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5318 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5319 git_print_page_path
($file_name, $ftype, $hash_base);
5322 if ($format eq 'incremental') {
5323 print "<noscript>\n<div class=\"error\"><center><b>\n".
5324 "This page requires JavaScript to run.\n Use ".
5325 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5328 "</b></center></div>\n</noscript>\n";
5330 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5333 print qq!<div
class="page_body">\n!;
5334 print qq!<div id
="progress_info">... / ...</div
>\n!
5335 if ($format eq 'incremental');
5336 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5337 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5339 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5343 my @rev_color = qw(light dark);
5344 my $num_colors = scalar(@rev_color);
5345 my $current_color = 0;
5347 if ($format eq 'incremental') {
5348 my $color_class = $rev_color[$current_color];
5353 while (my $line = <$fd>) {
5357 print qq!<tr id
="l$linenr" class="$color_class">!.
5358 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5359 qq!<td
class="linenr">!.
5360 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5361 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5365 } else { # porcelain, i.e. ordinary blame
5366 my %metainfo = (); # saves information about commits
5370 while (my $line = <$fd>) {
5372 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5373 # no <lines in group> for subsequent lines in group of lines
5374 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5375 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5376 if (!exists $metainfo{$full_rev}) {
5377 $metainfo{$full_rev} = { 'nprevious' => 0 };
5379 my $meta = $metainfo{$full_rev};
5381 while ($data = <$fd>) {
5383 last if ($data =~ s/^\t//); # contents of line
5384 if ($data =~ /^(\S+)(?: (.*))?$/) {
5385 $meta->{$1} = $2 unless exists $meta->{$1};
5387 if ($data =~ /^previous /) {
5388 $meta->{'nprevious'}++;
5391 my $short_rev = substr($full_rev, 0, 8);
5392 my $author = $meta->{'author'};
5394 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5395 my $date = $date{'iso-tz'};
5397 $current_color = ($current_color + 1) % $num_colors;
5399 my $tr_class = $rev_color[$current_color];
5400 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5401 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5402 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5403 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5405 print "<td class=\"sha1\"";
5406 print " title=\"". esc_html
($author) . ", $date\"";
5407 print " rowspan=\"$group_size\"" if ($group_size > 1);
5409 print $cgi->a({-href
=> href
(action
=>"commit",
5411 file_name
=>$file_name)},
5412 esc_html
($short_rev));
5413 if ($group_size >= 2) {
5414 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5415 if (@author_initials) {
5417 esc_html
(join('', @author_initials));
5423 # 'previous' <sha1 of parent commit> <filename at commit>
5424 if (exists $meta->{'previous'} &&
5425 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5426 $meta->{'parent'} = $1;
5427 $meta->{'file_parent'} = unquote
($2);
5430 exists($meta->{'parent'}) ?
5431 $meta->{'parent'} : $full_rev;
5432 my $linenr_filename =
5433 exists($meta->{'file_parent'}) ?
5434 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5435 my $blamed = href
(action
=> 'blame',
5436 file_name
=> $linenr_filename,
5437 hash_base
=> $linenr_commit);
5438 print "<td class=\"linenr\">";
5439 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5440 -class => "linenr" },
5443 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5451 "</table>\n"; # class="blame"
5452 print "</div>\n"; # class="blame_body"
5454 or print "Reading blob failed\n";
5463 sub git_blame_incremental
{
5464 git_blame_common
('incremental');
5467 sub git_blame_data
{
5468 git_blame_common
('data');
5472 my $head = git_get_head_hash
($project);
5474 git_print_page_nav
('','', $head,undef,$head);
5475 git_print_header_div
('summary', $project);
5477 my @tagslist = git_get_tags_list
();
5479 git_tags_body
(\
@tagslist);
5485 my $head = git_get_head_hash
($project);
5487 git_print_page_nav
('','', $head,undef,$head);
5488 git_print_header_div
('summary', $project);
5490 my @headslist = git_get_heads_list
();
5492 git_heads_body
(\
@headslist, $head);
5497 sub git_blob_plain
{
5501 if (!defined $hash) {
5502 if (defined $file_name) {
5503 my $base = $hash_base || git_get_head_hash
($project);
5504 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5505 or die_error
(404, "Cannot find file");
5507 die_error
(400, "No file name defined");
5509 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5510 # blobs defined by non-textual hash id's can be cached
5514 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5515 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5517 # content-type (can include charset)
5518 $type = blob_contenttype
($fd, $file_name, $type);
5520 # "save as" filename, even when no $file_name is given
5521 my $save_as = "$hash";
5522 if (defined $file_name) {
5523 $save_as = $file_name;
5524 } elsif ($type =~ m/^text\//) {
5528 # With XSS prevention on, blobs of all types except a few known safe
5529 # ones are served with "Content-Disposition: attachment" to make sure
5530 # they don't run in our security domain. For certain image types,
5531 # blob view writes an <img> tag referring to blob_plain view, and we
5532 # want to be sure not to break that by serving the image as an
5533 # attachment (though Firefox 3 doesn't seem to care).
5534 my $sandbox = $prevent_xss &&
5535 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5539 -expires
=> $expires,
5540 -content_disposition
=>
5541 ($sandbox ?
'attachment' : 'inline')
5542 . '; filename="' . $save_as . '"');
5544 binmode STDOUT
, ':raw';
5546 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5553 if (!defined $hash) {
5554 if (defined $file_name) {
5555 my $base = $hash_base || git_get_head_hash
($project);
5556 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5557 or die_error
(404, "Cannot find file");
5559 die_error
(400, "No file name defined");
5561 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5562 # blobs defined by non-textual hash id's can be cached
5566 my $have_blame = gitweb_check_feature
('blame');
5567 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5568 or die_error
(500, "Couldn't cat $file_name, $hash");
5569 my $mimetype = blob_mimetype
($fd, $file_name);
5570 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5571 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5573 return git_blob_plain
($mimetype);
5575 # we can have blame only for text/* mimetype
5576 $have_blame &&= ($mimetype =~ m!^text/!);
5578 my $highlight = gitweb_check_feature
('highlight');
5579 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5580 $fd = run_highlighter
($fd, $highlight, $syntax)
5583 git_header_html
(undef, $expires);
5584 my $formats_nav = '';
5585 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5586 if (defined $file_name) {
5589 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5594 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5597 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5600 $cgi->a({-href
=> href
(action
=>"blob",
5601 hash_base
=>"HEAD", file_name
=>$file_name)},
5605 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5608 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5609 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5611 print "<div class=\"page_nav\">\n" .
5612 "<br/><br/></div>\n" .
5613 "<div class=\"title\">$hash</div>\n";
5615 git_print_page_path
($file_name, "blob", $hash_base);
5616 print "<div class=\"page_body\">\n";
5617 if ($mimetype =~ m!^image/!) {
5618 print qq!<img type
="$mimetype"!;
5620 print qq! alt
="$file_name" title
="$file_name"!;
5623 href(action=>"blob_plain
", hash=>$hash,
5624 hash_base=>$hash_base, file_name=>$file_name) .
5628 while (my $line = <$fd>) {
5631 $line = untabify
($line);
5632 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5633 $nr, href
(-replay
=> 1), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5637 or print "Reading blob failed.\n";
5643 if (!defined $hash_base) {
5644 $hash_base = "HEAD";
5646 if (!defined $hash) {
5647 if (defined $file_name) {
5648 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5653 die_error
(404, "No such tree") unless defined($hash);
5655 my $show_sizes = gitweb_check_feature
('show-sizes');
5656 my $have_blame = gitweb_check_feature
('blame');
5661 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5662 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5663 or die_error
(500, "Open git-ls-tree failed");
5664 @entries = map { chomp; $_ } <$fd>;
5666 or die_error
(404, "Reading tree failed");
5669 my $refs = git_get_references
();
5670 my $ref = format_ref_marker
($refs, $hash_base);
5673 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5675 if (defined $file_name) {
5677 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5679 $cgi->a({-href
=> href
(action
=>"tree",
5680 hash_base
=>"HEAD", file_name
=>$file_name)},
5683 my $snapshot_links = format_snapshot_links
($hash);
5684 if (defined $snapshot_links) {
5685 # FIXME: Should be available when we have no hash base as well.
5686 push @views_nav, $snapshot_links;
5688 git_print_page_nav
('tree','', $hash_base, undef, undef,
5689 join(' | ', @views_nav));
5690 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5693 print "<div class=\"page_nav\">\n";
5694 print "<br/><br/></div>\n";
5695 print "<div class=\"title\">$hash</div>\n";
5697 if (defined $file_name) {
5698 $basedir = $file_name;
5699 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5702 git_print_page_path
($file_name, 'tree', $hash_base);
5704 print "<div class=\"page_body\">\n";
5705 print "<table class=\"tree\">\n";
5707 # '..' (top directory) link if possible
5708 if (defined $hash_base &&
5709 defined $file_name && $file_name =~ m![^/]+$!) {
5711 print "<tr class=\"dark\">\n";
5713 print "<tr class=\"light\">\n";
5717 my $up = $file_name;
5718 $up =~ s!/?[^/]+$!!;
5719 undef $up unless $up;
5720 # based on git_print_tree_entry
5721 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5722 print '<td class="size"> </td>'."\n" if $show_sizes;
5723 print '<td class="list">';
5724 print $cgi->a({-href
=> href
(action
=>"tree",
5725 hash_base
=>$hash_base,
5729 print "<td class=\"link\"></td>\n";
5733 foreach my $line (@entries) {
5734 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5737 print "<tr class=\"dark\">\n";
5739 print "<tr class=\"light\">\n";
5743 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5747 print "</table>\n" .
5753 my ($project, $hash) = @_;
5755 # path/to/project.git -> project
5756 # path/to/project/.git -> project
5757 my $name = to_utf8
($project);
5758 $name =~ s
,([^/])/*\
.git
$,$1,;
5759 $name = basename
($name);
5761 $name =~ s/[[:cntrl:]]/?/g;
5764 if ($hash =~ /^[0-9a-fA-F]+$/) {
5765 # shorten SHA-1 hash
5766 my $full_hash = git_get_full_hash
($project, $hash);
5767 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5768 $ver = git_get_short_hash
($project, $hash);
5770 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5771 # tags don't need shortened SHA-1 hash
5774 # branches and other need shortened SHA-1 hash
5775 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5778 $ver .= '-' . git_get_short_hash
($project, $hash);
5780 # in case of hierarchical branch names
5783 # name = project-version_string
5784 $name = "$name-$ver";
5786 return wantarray ?
($name, $name) : $name;
5790 my $format = $input_params{'snapshot_format'};
5791 if (!@snapshot_fmts) {
5792 die_error
(403, "Snapshots not allowed");
5794 # default to first supported snapshot format
5795 $format ||= $snapshot_fmts[0];
5796 if ($format !~ m/^[a-z0-9]+$/) {
5797 die_error
(400, "Invalid snapshot format parameter");
5798 } elsif (!exists($known_snapshot_formats{$format})) {
5799 die_error
(400, "Unknown snapshot format");
5800 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5801 die_error
(403, "Snapshot format not allowed");
5802 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5803 die_error
(403, "Unsupported snapshot format");
5806 my $type = git_get_type
("$hash^{}");
5808 die_error
(404, 'Object does not exist');
5809 } elsif ($type eq 'blob') {
5810 die_error
(400, 'Object is not a tree-ish');
5813 my ($name, $prefix) = snapshot_name
($project, $hash);
5814 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5815 my $cmd = quote_command
(
5816 git_cmd
(), 'archive',
5817 "--format=$known_snapshot_formats{$format}{'format'}",
5818 "--prefix=$prefix/", $hash);
5819 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5820 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5823 $filename =~ s/(["\\])/\\$1/g;
5825 -type
=> $known_snapshot_formats{$format}{'type'},
5826 -content_disposition
=> 'inline; filename="' . $filename . '"',
5827 -status
=> '200 OK');
5829 open my $fd, "-|", $cmd
5830 or die_error
(500, "Execute git-archive failed");
5831 binmode STDOUT
, ':raw';
5833 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5837 sub git_log_generic
{
5838 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5840 my $head = git_get_head_hash
($project);
5841 if (!defined $base) {
5844 if (!defined $page) {
5847 my $refs = git_get_references
();
5849 my $commit_hash = $base;
5850 if (defined $parent) {
5851 $commit_hash = "$parent..$base";
5854 parse_commits
($commit_hash, 101, (100 * $page),
5855 defined $file_name ?
($file_name, "--full-history") : ());
5858 if (!defined $file_hash && defined $file_name) {
5859 # some commits could have deleted file in question,
5860 # and not have it in tree, but one of them has to have it
5861 for (my $i = 0; $i < @commitlist; $i++) {
5862 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5863 last if defined $file_hash;
5866 if (defined $file_hash) {
5867 $ftype = git_get_type
($file_hash);
5869 if (defined $file_name && !defined $ftype) {
5870 die_error
(500, "Unknown type of object");
5873 if (defined $file_name) {
5874 %co = parse_commit
($base)
5875 or die_error
(404, "Unknown commit object");
5879 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5881 if ($#commitlist >= 100) {
5883 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5884 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5886 my $patch_max = gitweb_get_feature
('patches');
5887 if ($patch_max && !defined $file_name) {
5888 if ($patch_max < 0 || @commitlist <= $patch_max) {
5889 $paging_nav .= " ⋅ " .
5890 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5896 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5897 if (defined $file_name) {
5898 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5900 git_print_header_div
('summary', $project)
5902 git_print_page_path
($file_name, $ftype, $hash_base)
5903 if (defined $file_name);
5905 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5906 $file_name, $file_hash, $ftype);
5912 git_log_generic
('log', \
&git_log_body
,
5913 $hash, $hash_parent);
5917 $hash ||= $hash_base || "HEAD";
5918 my %co = parse_commit
($hash)
5919 or die_error
(404, "Unknown commit object");
5921 my $parent = $co{'parent'};
5922 my $parents = $co{'parents'}; # listref
5924 # we need to prepare $formats_nav before any parameter munging
5926 if (!defined $parent) {
5928 $formats_nav .= '(initial)';
5929 } elsif (@
$parents == 1) {
5930 # single parent commit
5933 $cgi->a({-href
=> href
(action
=>"commit",
5935 esc_html
(substr($parent, 0, 7))) .
5942 $cgi->a({-href
=> href
(action
=>"commit",
5944 esc_html
(substr($_, 0, 7)));
5948 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5949 $formats_nav .= " | " .
5950 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5954 if (!defined $parent) {
5958 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5960 (@
$parents <= 1 ?
$parent : '-c'),
5962 or die_error
(500, "Open git-diff-tree failed");
5963 @difftree = map { chomp; $_ } <$fd>;
5964 close $fd or die_error
(404, "Reading git-diff-tree failed");
5966 # non-textual hash id's can be cached
5968 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5971 my $refs = git_get_references
();
5972 my $ref = format_ref_marker
($refs, $co{'id'});
5974 git_header_html
(undef, $expires);
5975 git_print_page_nav
('commit', '',
5976 $hash, $co{'tree'}, $hash,
5979 if (defined $co{'parent'}) {
5980 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5982 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5984 print "<div class=\"title_text\">\n" .
5985 "<table class=\"object_header\">\n";
5986 git_print_authorship_rows
(\
%co);
5987 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5990 "<td class=\"sha1\">" .
5991 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5992 class => "list"}, $co{'tree'}) .
5994 "<td class=\"link\">" .
5995 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5997 my $snapshot_links = format_snapshot_links
($hash);
5998 if (defined $snapshot_links) {
5999 print " | " . $snapshot_links;
6004 foreach my $par (@
$parents) {
6007 "<td class=\"sha1\">" .
6008 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6009 class => "list"}, $par) .
6011 "<td class=\"link\">" .
6012 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6014 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6021 print "<div class=\"page_body\">\n";
6022 git_print_log
($co{'comment'});
6025 git_difftree_body
(\
@difftree, $hash, @
$parents);
6031 # object is defined by:
6032 # - hash or hash_base alone
6033 # - hash_base and file_name
6036 # - hash or hash_base alone
6037 if ($hash || ($hash_base && !defined $file_name)) {
6038 my $object_id = $hash || $hash_base;
6040 open my $fd, "-|", quote_command
(
6041 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6042 or die_error
(404, "Object does not exist");
6046 or die_error
(404, "Object does not exist");
6048 # - hash_base and file_name
6049 } elsif ($hash_base && defined $file_name) {
6050 $file_name =~ s
,/+$,,;
6052 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6053 or die_error
(404, "Base object does not exist");
6055 # here errors should not hapen
6056 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6057 or die_error
(500, "Open git-ls-tree failed");
6061 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6062 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6063 die_error
(404, "File or directory for given base does not exist");
6068 die_error
(400, "Not enough information to find object");
6071 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6072 hash
=>$hash, hash_base
=>$hash_base,
6073 file_name
=>$file_name),
6074 -status
=> '302 Found');
6078 my $format = shift || 'html';
6085 # preparing $fd and %diffinfo for git_patchset_body
6087 if (defined $hash_base && defined $hash_parent_base) {
6088 if (defined $file_name) {
6090 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6091 $hash_parent_base, $hash_base,
6092 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6093 or die_error
(500, "Open git-diff-tree failed");
6094 @difftree = map { chomp; $_ } <$fd>;
6096 or die_error
(404, "Reading git-diff-tree failed");
6098 or die_error
(404, "Blob diff not found");
6100 } elsif (defined $hash &&
6101 $hash =~ /[0-9a-fA-F]{40}/) {
6102 # try to find filename from $hash
6104 # read filtered raw output
6105 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6106 $hash_parent_base, $hash_base, "--"
6107 or die_error
(500, "Open git-diff-tree failed");
6109 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6111 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6112 map { chomp; $_ } <$fd>;
6114 or die_error
(404, "Reading git-diff-tree failed");
6116 or die_error
(404, "Blob diff not found");
6119 die_error
(400, "Missing one of the blob diff parameters");
6122 if (@difftree > 1) {
6123 die_error
(400, "Ambiguous blob diff specification");
6126 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6127 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6128 $file_name ||= $diffinfo{'to_file'};
6130 $hash_parent ||= $diffinfo{'from_id'};
6131 $hash ||= $diffinfo{'to_id'};
6133 # non-textual hash id's can be cached
6134 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6135 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6140 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6141 '-p', ($format eq 'html' ?
"--full-index" : ()),
6142 $hash_parent_base, $hash_base,
6143 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6144 or die_error
(500, "Open git-diff-tree failed");
6147 # old/legacy style URI -- not generated anymore since 1.4.3.
6149 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6153 if ($format eq 'html') {
6155 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6157 git_header_html
(undef, $expires);
6158 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6159 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6160 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6162 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6163 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
6165 if (defined $file_name) {
6166 git_print_page_path
($file_name, "blob", $hash_base);
6168 print "<div class=\"page_path\"></div>\n";
6171 } elsif ($format eq 'plain') {
6173 -type
=> 'text/plain',
6174 -charset
=> 'utf-8',
6175 -expires
=> $expires,
6176 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6178 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6181 die_error
(400, "Unknown blobdiff format");
6185 if ($format eq 'html') {
6186 print "<div class=\"page_body\">\n";
6188 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6191 print "</div>\n"; # class="page_body"
6195 while (my $line = <$fd>) {
6196 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6197 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6201 last if $line =~ m!^\+\+\+!;
6209 sub git_blobdiff_plain
{
6210 git_blobdiff
('plain');
6213 sub git_commitdiff
{
6215 my $format = $params{-format
} || 'html';
6217 my ($patch_max) = gitweb_get_feature
('patches');
6218 if ($format eq 'patch') {
6219 die_error
(403, "Patch view not allowed") unless $patch_max;
6222 $hash ||= $hash_base || "HEAD";
6223 my %co = parse_commit
($hash)
6224 or die_error
(404, "Unknown commit object");
6226 # choose format for commitdiff for merge
6227 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6228 $hash_parent = '--cc';
6230 # we need to prepare $formats_nav before almost any parameter munging
6232 if ($format eq 'html') {
6234 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6236 if ($patch_max && @
{$co{'parents'}} <= 1) {
6237 $formats_nav .= " | " .
6238 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6242 if (defined $hash_parent &&
6243 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6244 # commitdiff with two commits given
6245 my $hash_parent_short = $hash_parent;
6246 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6247 $hash_parent_short = substr($hash_parent, 0, 7);
6251 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6252 if ($co{'parents'}[$i] eq $hash_parent) {
6253 $formats_nav .= ' parent ' . ($i+1);
6257 $formats_nav .= ': ' .
6258 $cgi->a({-href
=> href
(action
=>"commitdiff",
6259 hash
=>$hash_parent)},
6260 esc_html
($hash_parent_short)) .
6262 } elsif (!$co{'parent'}) {
6264 $formats_nav .= ' (initial)';
6265 } elsif (scalar @
{$co{'parents'}} == 1) {
6266 # single parent commit
6269 $cgi->a({-href
=> href
(action
=>"commitdiff",
6270 hash
=>$co{'parent'})},
6271 esc_html
(substr($co{'parent'}, 0, 7))) .
6275 if ($hash_parent eq '--cc') {
6276 $formats_nav .= ' | ' .
6277 $cgi->a({-href
=> href
(action
=>"commitdiff",
6278 hash
=>$hash, hash_parent
=>'-c')},
6280 } else { # $hash_parent eq '-c'
6281 $formats_nav .= ' | ' .
6282 $cgi->a({-href
=> href
(action
=>"commitdiff",
6283 hash
=>$hash, hash_parent
=>'--cc')},
6289 $cgi->a({-href
=> href
(action
=>"commitdiff",
6291 esc_html
(substr($_, 0, 7)));
6292 } @
{$co{'parents'}} ) .
6297 my $hash_parent_param = $hash_parent;
6298 if (!defined $hash_parent_param) {
6299 # --cc for multiple parents, --root for parentless
6300 $hash_parent_param =
6301 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6307 if ($format eq 'html') {
6308 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6309 "--no-commit-id", "--patch-with-raw", "--full-index",
6310 $hash_parent_param, $hash, "--"
6311 or die_error
(500, "Open git-diff-tree failed");
6313 while (my $line = <$fd>) {
6315 # empty line ends raw part of diff-tree output
6317 push @difftree, scalar parse_difftree_raw_line
($line);
6320 } elsif ($format eq 'plain') {
6321 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6322 '-p', $hash_parent_param, $hash, "--"
6323 or die_error
(500, "Open git-diff-tree failed");
6324 } elsif ($format eq 'patch') {
6325 # For commit ranges, we limit the output to the number of
6326 # patches specified in the 'patches' feature.
6327 # For single commits, we limit the output to a single patch,
6328 # diverging from the git-format-patch default.
6329 my @commit_spec = ();
6331 if ($patch_max > 0) {
6332 push @commit_spec, "-$patch_max";
6334 push @commit_spec, '-n', "$hash_parent..$hash";
6336 if ($params{-single
}) {
6337 push @commit_spec, '-1';
6339 if ($patch_max > 0) {
6340 push @commit_spec, "-$patch_max";
6342 push @commit_spec, "-n";
6344 push @commit_spec, '--root', $hash;
6346 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6347 '--encoding=utf8', '--stdout', @commit_spec
6348 or die_error
(500, "Open git-format-patch failed");
6350 die_error
(400, "Unknown commitdiff format");
6353 # non-textual hash id's can be cached
6355 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6359 # write commit message
6360 if ($format eq 'html') {
6361 my $refs = git_get_references
();
6362 my $ref = format_ref_marker
($refs, $co{'id'});
6364 git_header_html
(undef, $expires);
6365 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6366 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6367 print "<div class=\"title_text\">\n" .
6368 "<table class=\"object_header\">\n";
6369 git_print_authorship_rows
(\
%co);
6372 print "<div class=\"page_body\">\n";
6373 if (@
{$co{'comment'}} > 1) {
6374 print "<div class=\"log\">\n";
6375 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6376 print "</div>\n"; # class="log"
6379 } elsif ($format eq 'plain') {
6380 my $refs = git_get_references
("tags");
6381 my $tagname = git_get_rev_name_tags
($hash);
6382 my $filename = basename
($project) . "-$hash.patch";
6385 -type
=> 'text/plain',
6386 -charset
=> 'utf-8',
6387 -expires
=> $expires,
6388 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6389 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6390 print "From: " . to_utf8
($co{'author'}) . "\n";
6391 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6392 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6394 print "X-Git-Tag: $tagname\n" if $tagname;
6395 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6397 foreach my $line (@
{$co{'comment'}}) {
6398 print to_utf8
($line) . "\n";
6401 } elsif ($format eq 'patch') {
6402 my $filename = basename
($project) . "-$hash.patch";
6405 -type
=> 'text/plain',
6406 -charset
=> 'utf-8',
6407 -expires
=> $expires,
6408 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6412 if ($format eq 'html') {
6413 my $use_parents = !defined $hash_parent ||
6414 $hash_parent eq '-c' || $hash_parent eq '--cc';
6415 git_difftree_body
(\
@difftree, $hash,
6416 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6419 git_patchset_body
($fd, \
@difftree, $hash,
6420 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6422 print "</div>\n"; # class="page_body"
6425 } elsif ($format eq 'plain') {
6429 or print "Reading git-diff-tree failed\n";
6430 } elsif ($format eq 'patch') {
6434 or print "Reading git-format-patch failed\n";
6438 sub git_commitdiff_plain
{
6439 git_commitdiff
(-format
=> 'plain');
6442 # format-patch-style patches
6444 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6448 git_commitdiff
(-format
=> 'patch');
6452 git_log_generic
('history', \
&git_history_body
,
6453 $hash_base, $hash_parent_base,
6458 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6459 if (!defined $searchtext) {
6460 die_error
(400, "Text field is empty");
6462 if (!defined $hash) {
6463 $hash = git_get_head_hash
($project);
6465 my %co = parse_commit
($hash);
6467 die_error
(404, "Unknown commit object");
6469 if (!defined $page) {
6473 $searchtype ||= 'commit';
6474 if ($searchtype eq 'pickaxe') {
6475 # pickaxe may take all resources of your box and run for several minutes
6476 # with every query - so decide by yourself how public you make this feature
6477 gitweb_check_feature
('pickaxe')
6478 or die_error
(403, "Pickaxe is disabled");
6480 if ($searchtype eq 'grep') {
6481 gitweb_check_feature
('grep')
6482 or die_error
(403, "Grep is disabled");
6487 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6489 if ($searchtype eq 'commit') {
6490 $greptype = "--grep=";
6491 } elsif ($searchtype eq 'author') {
6492 $greptype = "--author=";
6493 } elsif ($searchtype eq 'committer') {
6494 $greptype = "--committer=";
6496 $greptype .= $searchtext;
6497 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6498 $greptype, '--regexp-ignore-case',
6499 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6501 my $paging_nav = '';
6504 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6505 searchtext
=>$searchtext,
6506 searchtype
=>$searchtype)},
6508 $paging_nav .= " ⋅ " .
6509 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6510 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6512 $paging_nav .= "first";
6513 $paging_nav .= " ⋅ prev";
6516 if ($#commitlist >= 100) {
6518 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6519 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6520 $paging_nav .= " ⋅ $next_link";
6522 $paging_nav .= " ⋅ next";
6525 if ($#commitlist >= 100) {
6528 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6529 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6530 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6533 if ($searchtype eq 'pickaxe') {
6534 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6535 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6537 print "<table class=\"pickaxe search\">\n";
6540 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6541 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6542 ($search_use_regexp ?
'--pickaxe-regex' : ());
6545 while (my $line = <$fd>) {
6549 my %set = parse_difftree_raw_line
($line);
6550 if (defined $set{'commit'}) {
6551 # finish previous commit
6554 "<td class=\"link\">" .
6555 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6557 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6563 print "<tr class=\"dark\">\n";
6565 print "<tr class=\"light\">\n";
6568 %co = parse_commit
($set{'commit'});
6569 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6570 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6571 "<td><i>$author</i></td>\n" .
6573 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6574 -class => "list subject"},
6575 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6576 } elsif (defined $set{'to_id'}) {
6577 next if ($set{'to_id'} =~ m/^0{40}$/);
6579 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6580 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6582 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6588 # finish last commit (warning: repetition!)
6591 "<td class=\"link\">" .
6592 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6594 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6602 if ($searchtype eq 'grep') {
6603 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6604 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6606 print "<table class=\"grep_search\">\n";
6610 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6611 $search_use_regexp ?
('-E', '-i') : '-F',
6612 $searchtext, $co{'tree'};
6614 while (my $line = <$fd>) {
6616 my ($file, $lno, $ltext, $binary);
6617 last if ($matches++ > 1000);
6618 if ($line =~ /^Binary file (.+) matches$/) {
6622 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6624 if ($file ne $lastfile) {
6625 $lastfile and print "</td></tr>\n";
6627 print "<tr class=\"dark\">\n";
6629 print "<tr class=\"light\">\n";
6631 print "<td class=\"list\">".
6632 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6633 file_name
=>"$file"),
6634 -class => "list"}, esc_path
($file));
6635 print "</td><td>\n";
6639 print "<div class=\"binary\">Binary file</div>\n";
6641 $ltext = untabify
($ltext);
6642 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6643 $ltext = esc_html
($1, -nbsp
=>1);
6644 $ltext .= '<span class="match">';
6645 $ltext .= esc_html
($2, -nbsp
=>1);
6646 $ltext .= '</span>';
6647 $ltext .= esc_html
($3, -nbsp
=>1);
6649 $ltext = esc_html
($ltext, -nbsp
=>1);
6651 print "<div class=\"pre\">" .
6652 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6653 file_name
=>"$file").'#l'.$lno,
6654 -class => "linenr"}, sprintf('%4i', $lno))
6655 . ' ' . $ltext . "</div>\n";
6659 print "</td></tr>\n";
6660 if ($matches > 1000) {
6661 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6664 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6673 sub git_search_help
{
6675 git_print_page_nav
('','', $hash,$hash,$hash);
6677 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6678 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6679 the pattern entered is recognized as the POSIX extended
6680 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6683 <dt><b>commit</b></dt>
6684 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6686 my $have_grep = gitweb_check_feature
('grep');
6689 <dt><b>grep</b></dt>
6690 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6691 a different one) are searched for the given pattern. On large trees, this search can take
6692 a while and put some strain on the server, so please use it with some consideration. Note that
6693 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6694 case-sensitive.</dd>
6698 <dt><b>author</b></dt>
6699 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6700 <dt><b>committer</b></dt>
6701 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6703 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6704 if ($have_pickaxe) {
6706 <dt><b>pickaxe</b></dt>
6707 <dd>All commits that caused the string to appear or disappear from any file (changes that
6708 added, removed or "modified" the string) will be listed. This search can take a while and
6709 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6710 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6718 git_log_generic
('shortlog', \
&git_shortlog_body
,
6719 $hash, $hash_parent);
6722 ## ......................................................................
6723 ## feeds (RSS, Atom; OPML)
6726 my $format = shift || 'atom';
6727 my $have_blame = gitweb_check_feature
('blame');
6729 # Atom: http://www.atomenabled.org/developers/syndication/
6730 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6731 if ($format ne 'rss' && $format ne 'atom') {
6732 die_error
(400, "Unknown web feed format");
6735 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6736 my $head = $hash || 'HEAD';
6737 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6741 my $content_type = "application/$format+xml";
6742 if (defined $cgi->http('HTTP_ACCEPT') &&
6743 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6744 # browser (feed reader) prefers text/xml
6745 $content_type = 'text/xml';
6747 if (defined($commitlist[0])) {
6748 %latest_commit = %{$commitlist[0]};
6749 my $latest_epoch = $latest_commit{'committer_epoch'};
6750 %latest_date = parse_date
($latest_epoch);
6751 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6752 if (defined $if_modified) {
6754 if (eval { require HTTP
::Date
; 1; }) {
6755 $since = HTTP
::Date
::str2time
($if_modified);
6756 } elsif (eval { require Time
::ParseDate
; 1; }) {
6757 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6759 if (defined $since && $latest_epoch <= $since) {
6761 -type
=> $content_type,
6762 -charset
=> 'utf-8',
6763 -last_modified
=> $latest_date{'rfc2822'},
6764 -status
=> '304 Not Modified');
6769 -type
=> $content_type,
6770 -charset
=> 'utf-8',
6771 -last_modified
=> $latest_date{'rfc2822'});
6774 -type
=> $content_type,
6775 -charset
=> 'utf-8');
6778 # Optimization: skip generating the body if client asks only
6779 # for Last-Modified date.
6780 return if ($cgi->request_method() eq 'HEAD');
6783 my $title = "$site_name - $project/$action";
6784 my $feed_type = 'log';
6785 if (defined $hash) {
6786 $title .= " - '$hash'";
6787 $feed_type = 'branch log';
6788 if (defined $file_name) {
6789 $title .= " :: $file_name";
6790 $feed_type = 'history';
6792 } elsif (defined $file_name) {
6793 $title .= " - $file_name";
6794 $feed_type = 'history';
6796 $title .= " $feed_type";
6797 my $descr = git_get_project_description
($project);
6798 if (defined $descr) {
6799 $descr = esc_html
($descr);
6801 $descr = "$project " .
6802 ($format eq 'rss' ?
'RSS' : 'Atom') .
6805 my $owner = git_get_project_owner
($project);
6806 $owner = esc_html
($owner);
6810 if (defined $file_name) {
6811 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6812 } elsif (defined $hash) {
6813 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6815 $alt_url = href
(-full
=>1, action
=>"summary");
6817 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6818 if ($format eq 'rss') {
6820 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6823 print "<title>$title</title>\n" .
6824 "<link>$alt_url</link>\n" .
6825 "<description>$descr</description>\n" .
6826 "<language>en</language>\n" .
6827 # project owner is responsible for 'editorial' content
6828 "<managingEditor>$owner</managingEditor>\n";
6829 if (defined $logo || defined $favicon) {
6830 # prefer the logo to the favicon, since RSS
6831 # doesn't allow both
6832 my $img = esc_url
($logo || $favicon);
6834 "<url>$img</url>\n" .
6835 "<title>$title</title>\n" .
6836 "<link>$alt_url</link>\n" .
6840 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6841 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6843 print "<generator>gitweb v.$version/$git_version</generator>\n";
6844 } elsif ($format eq 'atom') {
6846 <feed xmlns="http://www.w3.org/2005/Atom">
6848 print "<title>$title</title>\n" .
6849 "<subtitle>$descr</subtitle>\n" .
6850 '<link rel="alternate" type="text/html" href="' .
6851 $alt_url . '" />' . "\n" .
6852 '<link rel="self" type="' . $content_type . '" href="' .
6853 $cgi->self_url() . '" />' . "\n" .
6854 "<id>" . href
(-full
=>1) . "</id>\n" .
6855 # use project owner for feed author
6856 "<author><name>$owner</name></author>\n";
6857 if (defined $favicon) {
6858 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6860 if (defined $logo_url) {
6861 # not twice as wide as tall: 72 x 27 pixels
6862 print "<logo>" . esc_url
($logo) . "</logo>\n";
6864 if (! %latest_date) {
6865 # dummy date to keep the feed valid until commits trickle in:
6866 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6868 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6870 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6874 for (my $i = 0; $i <= $#commitlist; $i++) {
6875 my %co = %{$commitlist[$i]};
6876 my $commit = $co{'id'};
6877 # we read 150, we always show 30 and the ones more recent than 48 hours
6878 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6881 my %cd = parse_date
($co{'author_epoch'});
6883 # get list of changed files
6884 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6885 $co{'parent'} || "--root",
6886 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6888 my @difftree = map { chomp; $_ } <$fd>;
6892 # print element (entry, item)
6893 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6894 if ($format eq 'rss') {
6896 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6897 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6898 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6899 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6900 "<link>$co_url</link>\n" .
6901 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6902 "<content:encoded>" .
6904 } elsif ($format eq 'atom') {
6906 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6907 "<updated>$cd{'iso-8601'}</updated>\n" .
6909 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6910 if ($co{'author_email'}) {
6911 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6913 print "</author>\n" .
6914 # use committer for contributor
6916 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6917 if ($co{'committer_email'}) {
6918 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6920 print "</contributor>\n" .
6921 "<published>$cd{'iso-8601'}</published>\n" .
6922 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6923 "<id>$co_url</id>\n" .
6924 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6925 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6927 my $comment = $co{'comment'};
6929 foreach my $line (@
$comment) {
6930 $line = esc_html
($line);
6933 print "</pre><ul>\n";
6934 foreach my $difftree_line (@difftree) {
6935 my %difftree = parse_difftree_raw_line
($difftree_line);
6936 next if !$difftree{'from_id'};
6938 my $file = $difftree{'file'} || $difftree{'to_file'};
6942 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6943 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6944 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6945 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6946 -title
=> "diff"}, 'D');
6948 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6949 file_name
=>$file, hash_base
=>$commit),
6950 -title
=> "blame"}, 'B');
6952 # if this is not a feed of a file history
6953 if (!defined $file_name || $file_name ne $file) {
6954 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6955 file_name
=>$file, hash
=>$commit),
6956 -title
=> "history"}, 'H');
6958 $file = esc_path
($file);
6962 if ($format eq 'rss') {
6963 print "</ul>]]>\n" .
6964 "</content:encoded>\n" .
6966 } elsif ($format eq 'atom') {
6967 print "</ul>\n</div>\n" .
6974 if ($format eq 'rss') {
6975 print "</channel>\n</rss>\n";
6976 } elsif ($format eq 'atom') {
6990 my @list = git_get_projects_list
();
6993 -type
=> 'text/xml',
6994 -charset
=> 'utf-8',
6995 -content_disposition
=> 'inline; filename="opml.xml"');
6998 <?xml version="1.0" encoding="utf-8"?>
6999 <opml version="1.0">
7001 <title>$site_name OPML Export</title>
7004 <outline text="git RSS feeds">
7007 foreach my $pr (@list) {
7009 my $head = git_get_head_hash
($proj{'path'});
7010 if (!defined $head) {
7013 $git_dir = "$projectroot/$proj{'path'}";
7014 my %co = parse_commit
($head);
7019 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7020 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7021 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7022 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";