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
()]
1035 evaluate_gitweb_config
();
1036 evaluate_git_version
();
1039 # $projectroot and $projects_list might be set in gitweb config file
1040 $projects_list ||= $projectroot;
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() };
1090 $pre_listen_hook->()
1091 if $pre_listen_hook;
1094 while ($cgi = $CGI->new()) {
1095 $pre_dispatch_hook->()
1096 if $pre_dispatch_hook;
1100 $pre_dispatch_hook->()
1101 if $post_dispatch_hook;
1103 last REQUEST
if ($is_last_request->());
1112 if (defined caller) {
1113 # wrapped in a subroutine processing requests,
1114 # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
1117 # pure CGI script, serving single request
1121 ## ======================================================================
1124 # possible values of extra options
1125 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
1126 # -replay => 1 - start from a current view (replay with modifications)
1127 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1130 # default is to use -absolute url() i.e. $my_uri
1131 my $href = $params{-full
} ?
$my_url : $my_uri;
1133 $params{'project'} = $project unless exists $params{'project'};
1135 if ($params{-replay
}) {
1136 while (my ($name, $symbol) = each %cgi_param_mapping) {
1137 if (!exists $params{$name}) {
1138 $params{$name} = $input_params{$name};
1143 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1144 if (defined $params{'project'} &&
1145 (exists $params{-path_info
} ?
$params{-path_info
} : $use_pathinfo)) {
1146 # try to put as many parameters as possible in PATH_INFO:
1149 # - hash_parent or hash_parent_base:/file_parent
1150 # - hash or hash_base:/filename
1151 # - the snapshot_format as an appropriate suffix
1153 # When the script is the root DirectoryIndex for the domain,
1154 # $href here would be something like http://gitweb.example.com/
1155 # Thus, we strip any trailing / from $href, to spare us double
1156 # slashes in the final URL
1159 # Then add the project name, if present
1160 $href .= "/".esc_url
($params{'project'});
1161 delete $params{'project'};
1163 # since we destructively absorb parameters, we keep this
1164 # boolean that remembers if we're handling a snapshot
1165 my $is_snapshot = $params{'action'} eq 'snapshot';
1167 # Summary just uses the project path URL, any other action is
1169 if (defined $params{'action'}) {
1170 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1171 delete $params{'action'};
1174 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1175 # stripping nonexistent or useless pieces
1176 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1177 || $params{'hash_parent'} || $params{'hash'});
1178 if (defined $params{'hash_base'}) {
1179 if (defined $params{'hash_parent_base'}) {
1180 $href .= esc_url
($params{'hash_parent_base'});
1181 # skip the file_parent if it's the same as the file_name
1182 if (defined $params{'file_parent'}) {
1183 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1184 delete $params{'file_parent'};
1185 } elsif ($params{'file_parent'} !~ /\.\./) {
1186 $href .= ":/".esc_url
($params{'file_parent'});
1187 delete $params{'file_parent'};
1191 delete $params{'hash_parent'};
1192 delete $params{'hash_parent_base'};
1193 } elsif (defined $params{'hash_parent'}) {
1194 $href .= esc_url
($params{'hash_parent'}). "..";
1195 delete $params{'hash_parent'};
1198 $href .= esc_url
($params{'hash_base'});
1199 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1200 $href .= ":/".esc_url
($params{'file_name'});
1201 delete $params{'file_name'};
1203 delete $params{'hash'};
1204 delete $params{'hash_base'};
1205 } elsif (defined $params{'hash'}) {
1206 $href .= esc_url
($params{'hash'});
1207 delete $params{'hash'};
1210 # If the action was a snapshot, we can absorb the
1211 # snapshot_format parameter too
1213 my $fmt = $params{'snapshot_format'};
1214 # snapshot_format should always be defined when href()
1215 # is called, but just in case some code forgets, we
1216 # fall back to the default
1217 $fmt ||= $snapshot_fmts[0];
1218 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1219 delete $params{'snapshot_format'};
1223 # now encode the parameters explicitly
1225 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1226 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1227 if (defined $params{$name}) {
1228 if (ref($params{$name}) eq "ARRAY") {
1229 foreach my $par (@
{$params{$name}}) {
1230 push @result, $symbol . "=" . esc_param
($par);
1233 push @result, $symbol . "=" . esc_param
($params{$name});
1237 $href .= "?" . join(';', @result) if scalar @result;
1243 ## ======================================================================
1244 ## validation, quoting/unquoting and escaping
1246 sub validate_action
{
1247 my $input = shift || return undef;
1248 return undef unless exists $actions{$input};
1252 sub validate_project
{
1253 my $input = shift || return undef;
1254 if (!validate_pathname
($input) ||
1255 !(-d
"$projectroot/$input") ||
1256 !check_export_ok
("$projectroot/$input") ||
1257 ($strict_export && !project_in_list
($input))) {
1264 sub validate_pathname
{
1265 my $input = shift || return undef;
1267 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1268 # at the beginning, at the end, and between slashes.
1269 # also this catches doubled slashes
1270 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1273 # no null characters
1274 if ($input =~ m!\0!) {
1280 sub validate_refname
{
1281 my $input = shift || return undef;
1283 # textual hashes are O.K.
1284 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1287 # it must be correct pathname
1288 $input = validate_pathname
($input)
1290 # restrictions on ref name according to git-check-ref-format
1291 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1297 # decode sequences of octets in utf8 into Perl's internal form,
1298 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1299 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1302 return undef unless defined $str;
1303 if (utf8
::valid
($str)) {
1307 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1311 # quote unsafe chars, but keep the slash, even when it's not
1312 # correct, but quoted slashes look too horrible in bookmarks
1315 return undef unless defined $str;
1316 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1321 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1324 return undef unless defined $str;
1325 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1331 # replace invalid utf8 character with SUBSTITUTION sequence
1336 return undef unless defined $str;
1338 $str = to_utf8
($str);
1339 $str = $cgi->escapeHTML($str);
1340 if ($opts{'-nbsp'}) {
1341 $str =~ s/ / /g;
1343 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1347 # quote control characters and escape filename to HTML
1352 return undef unless defined $str;
1354 $str = to_utf8
($str);
1355 $str = $cgi->escapeHTML($str);
1356 if ($opts{'-nbsp'}) {
1357 $str =~ s/ / /g;
1359 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1363 # Make control characters "printable", using character escape codes (CEC)
1367 my %es = ( # character escape codes, aka escape sequences
1368 "\t" => '\t', # tab (HT)
1369 "\n" => '\n', # line feed (LF)
1370 "\r" => '\r', # carrige return (CR)
1371 "\f" => '\f', # form feed (FF)
1372 "\b" => '\b', # backspace (BS)
1373 "\a" => '\a', # alarm (bell) (BEL)
1374 "\e" => '\e', # escape (ESC)
1375 "\013" => '\v', # vertical tab (VT)
1376 "\000" => '\0', # nul character (NUL)
1378 my $chr = ( (exists $es{$cntrl})
1380 : sprintf('\%2x', ord($cntrl)) );
1381 if ($opts{-nohtml
}) {
1384 return "<span class=\"cntrl\">$chr</span>";
1388 # Alternatively use unicode control pictures codepoints,
1389 # Unicode "printable representation" (PR)
1394 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1395 if ($opts{-nohtml
}) {
1398 return "<span class=\"cntrl\">$chr</span>";
1402 # git may return quoted and escaped filenames
1408 my %es = ( # character escape codes, aka escape sequences
1409 't' => "\t", # tab (HT, TAB)
1410 'n' => "\n", # newline (NL)
1411 'r' => "\r", # return (CR)
1412 'f' => "\f", # form feed (FF)
1413 'b' => "\b", # backspace (BS)
1414 'a' => "\a", # alarm (bell) (BEL)
1415 'e' => "\e", # escape (ESC)
1416 'v' => "\013", # vertical tab (VT)
1419 if ($seq =~ m/^[0-7]{1,3}$/) {
1420 # octal char sequence
1421 return chr(oct($seq));
1422 } elsif (exists $es{$seq}) {
1423 # C escape sequence, aka character escape code
1426 # quoted ordinary character
1430 if ($str =~ m/^"(.*)"$/) {
1433 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1438 # escape tabs (convert tabs to spaces)
1442 while ((my $pos = index($line, "\t")) != -1) {
1443 if (my $count = (8 - ($pos % 8))) {
1444 my $spaces = ' ' x
$count;
1445 $line =~ s/\t/$spaces/;
1452 sub project_in_list
{
1453 my $project = shift;
1454 my @list = git_get_projects_list
();
1455 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1458 ## ----------------------------------------------------------------------
1459 ## HTML aware string manipulation
1461 # Try to chop given string on a word boundary between position
1462 # $len and $len+$add_len. If there is no word boundary there,
1463 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1464 # (marking chopped part) would be longer than given string.
1468 my $add_len = shift || 10;
1469 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1471 # Make sure perl knows it is utf8 encoded so we don't
1472 # cut in the middle of a utf8 multibyte char.
1473 $str = to_utf8
($str);
1475 # allow only $len chars, but don't cut a word if it would fit in $add_len
1476 # if it doesn't fit, cut it if it's still longer than the dots we would add
1477 # remove chopped character entities entirely
1479 # when chopping in the middle, distribute $len into left and right part
1480 # return early if chopping wouldn't make string shorter
1481 if ($where eq 'center') {
1482 return $str if ($len + 5 >= length($str)); # filler is length 5
1485 return $str if ($len + 4 >= length($str)); # filler is length 4
1488 # regexps: ending and beginning with word part up to $add_len
1489 my $endre = qr/.{$len}\w{0,$add_len}/;
1490 my $begre = qr/\w{0,$add_len}.{$len}/;
1492 if ($where eq 'left') {
1493 $str =~ m/^(.*?)($begre)$/;
1494 my ($lead, $body) = ($1, $2);
1495 if (length($lead) > 4) {
1498 return "$lead$body";
1500 } elsif ($where eq 'center') {
1501 $str =~ m/^($endre)(.*)$/;
1502 my ($left, $str) = ($1, $2);
1503 $str =~ m/^(.*?)($begre)$/;
1504 my ($mid, $right) = ($1, $2);
1505 if (length($mid) > 5) {
1508 return "$left$mid$right";
1511 $str =~ m/^($endre)(.*)$/;
1514 if (length($tail) > 4) {
1517 return "$body$tail";
1521 # takes the same arguments as chop_str, but also wraps a <span> around the
1522 # result with a title attribute if it does get chopped. Additionally, the
1523 # string is HTML-escaped.
1524 sub chop_and_escape_str
{
1527 my $chopped = chop_str
(@_);
1528 if ($chopped eq $str) {
1529 return esc_html
($chopped);
1531 $str =~ s/[[:cntrl:]]/?/g;
1532 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1536 ## ----------------------------------------------------------------------
1537 ## functions returning short strings
1539 # CSS class for given age value (in seconds)
1543 if (!defined $age) {
1545 } elsif ($age < 60*60*2) {
1547 } elsif ($age < 60*60*24*2) {
1554 # convert age in seconds to "nn units ago" string
1559 if ($age > 60*60*24*365*2) {
1560 $age_str = (int $age/60/60/24/365);
1561 $age_str .= " years ago";
1562 } elsif ($age > 60*60*24*(365/12)*2) {
1563 $age_str = int $age/60/60/24/(365/12);
1564 $age_str .= " months ago";
1565 } elsif ($age > 60*60*24*7*2) {
1566 $age_str = int $age/60/60/24/7;
1567 $age_str .= " weeks ago";
1568 } elsif ($age > 60*60*24*2) {
1569 $age_str = int $age/60/60/24;
1570 $age_str .= " days ago";
1571 } elsif ($age > 60*60*2) {
1572 $age_str = int $age/60/60;
1573 $age_str .= " hours ago";
1574 } elsif ($age > 60*2) {
1575 $age_str = int $age/60;
1576 $age_str .= " min ago";
1577 } elsif ($age > 2) {
1578 $age_str = int $age;
1579 $age_str .= " sec ago";
1581 $age_str .= " right now";
1587 S_IFINVALID
=> 0030000,
1588 S_IFGITLINK
=> 0160000,
1591 # submodule/subproject, a commit object reference
1595 return (($mode & S_IFMT
) == S_IFGITLINK
)
1598 # convert file mode in octal to symbolic file mode string
1600 my $mode = oct shift;
1602 if (S_ISGITLINK
($mode)) {
1603 return 'm---------';
1604 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1605 return 'drwxr-xr-x';
1606 } elsif (S_ISLNK
($mode)) {
1607 return 'lrwxrwxrwx';
1608 } elsif (S_ISREG
($mode)) {
1609 # git cares only about the executable bit
1610 if ($mode & S_IXUSR
) {
1611 return '-rwxr-xr-x';
1613 return '-rw-r--r--';
1616 return '----------';
1620 # convert file mode in octal to file type string
1624 if ($mode !~ m/^[0-7]+$/) {
1630 if (S_ISGITLINK
($mode)) {
1632 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1634 } elsif (S_ISLNK
($mode)) {
1636 } elsif (S_ISREG
($mode)) {
1643 # convert file mode in octal to file type description string
1644 sub file_type_long
{
1647 if ($mode !~ m/^[0-7]+$/) {
1653 if (S_ISGITLINK
($mode)) {
1655 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1657 } elsif (S_ISLNK
($mode)) {
1659 } elsif (S_ISREG
($mode)) {
1660 if ($mode & S_IXUSR
) {
1661 return "executable";
1671 ## ----------------------------------------------------------------------
1672 ## functions returning short HTML fragments, or transforming HTML fragments
1673 ## which don't belong to other sections
1675 # format line of commit message.
1676 sub format_log_line_html
{
1679 $line = esc_html
($line, -nbsp
=>1);
1680 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1681 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1682 -class => "text"}, $1);
1688 # format marker of refs pointing to given object
1690 # the destination action is chosen based on object type and current context:
1691 # - for annotated tags, we choose the tag view unless it's the current view
1692 # already, in which case we go to shortlog view
1693 # - for other refs, we keep the current view if we're in history, shortlog or
1694 # log view, and select shortlog otherwise
1695 sub format_ref_marker
{
1696 my ($refs, $id) = @_;
1699 if (defined $refs->{$id}) {
1700 foreach my $ref (@
{$refs->{$id}}) {
1701 # this code exploits the fact that non-lightweight tags are the
1702 # only indirect objects, and that they are the only objects for which
1703 # we want to use tag instead of shortlog as action
1704 my ($type, $name) = qw();
1705 my $indirect = ($ref =~ s/\^\{\}$//);
1706 # e.g. tags/v2.6.11 or heads/next
1707 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1716 $class .= " indirect" if $indirect;
1718 my $dest_action = "shortlog";
1721 $dest_action = "tag" unless $action eq "tag";
1722 } elsif ($action =~ /^(history|(short)?log)$/) {
1723 $dest_action = $action;
1727 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1730 my $link = $cgi->a({
1732 action
=>$dest_action,
1736 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1742 return ' <span class="refs">'. $markers . '</span>';
1748 # format, perhaps shortened and with markers, title line
1749 sub format_subject_html
{
1750 my ($long, $short, $href, $extra) = @_;
1751 $extra = '' unless defined($extra);
1753 if (length($short) < length($long)) {
1754 $long =~ s/[[:cntrl:]]/?/g;
1755 return $cgi->a({-href
=> $href, -class => "list subject",
1756 -title
=> to_utf8
($long)},
1757 esc_html
($short)) . $extra;
1759 return $cgi->a({-href
=> $href, -class => "list subject"},
1760 esc_html
($long)) . $extra;
1764 # Rather than recomputing the url for an email multiple times, we cache it
1765 # after the first hit. This gives a visible benefit in views where the avatar
1766 # for the same email is used repeatedly (e.g. shortlog).
1767 # The cache is shared by all avatar engines (currently gravatar only), which
1768 # are free to use it as preferred. Since only one avatar engine is used for any
1769 # given page, there's no risk for cache conflicts.
1770 our %avatar_cache = ();
1772 # Compute the picon url for a given email, by using the picon search service over at
1773 # http://www.cs.indiana.edu/picons/search.html
1775 my $email = lc shift;
1776 if (!$avatar_cache{$email}) {
1777 my ($user, $domain) = split('@', $email);
1778 $avatar_cache{$email} =
1779 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1781 "users+domains+unknown/up/single";
1783 return $avatar_cache{$email};
1786 # Compute the gravatar url for a given email, if it's not in the cache already.
1787 # Gravatar stores only the part of the URL before the size, since that's the
1788 # one computationally more expensive. This also allows reuse of the cache for
1789 # different sizes (for this particular engine).
1791 my $email = lc shift;
1793 $avatar_cache{$email} ||=
1794 "http://www.gravatar.com/avatar/" .
1795 Digest
::MD5
::md5_hex
($email) . "?s=";
1796 return $avatar_cache{$email} . $size;
1799 # Insert an avatar for the given $email at the given $size if the feature
1801 sub git_get_avatar
{
1802 my ($email, %opts) = @_;
1803 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1804 my $post_white = ($opts{-pad_after
} ?
" " : "");
1805 $opts{-size
} ||= 'default';
1806 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1808 if ($git_avatar eq 'gravatar') {
1809 $url = gravatar_url
($email, $size);
1810 } elsif ($git_avatar eq 'picon') {
1811 $url = picon_url
($email);
1813 # Other providers can be added by extending the if chain, defining $url
1814 # as needed. If no variant puts something in $url, we assume avatars
1815 # are completely disabled/unavailable.
1818 "<img width=\"$size\" " .
1819 "class=\"avatar\" " .
1828 sub format_search_author
{
1829 my ($author, $searchtype, $displaytext) = @_;
1830 my $have_search = gitweb_check_feature
('search');
1834 if ($searchtype eq 'author') {
1835 $performed = "authored";
1836 } elsif ($searchtype eq 'committer') {
1837 $performed = "committed";
1840 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1841 searchtext
=>$author,
1842 searchtype
=>$searchtype), class=>"list",
1843 title
=>"Search for commits $performed by $author"},
1847 return $displaytext;
1851 # format the author name of the given commit with the given tag
1852 # the author name is chopped and escaped according to the other
1853 # optional parameters (see chop_str).
1854 sub format_author_html
{
1857 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1858 return "<$tag class=\"author\">" .
1859 format_search_author
($co->{'author_name'}, "author",
1860 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1865 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1866 sub format_git_diff_header_line
{
1868 my $diffinfo = shift;
1869 my ($from, $to) = @_;
1871 if ($diffinfo->{'nparents'}) {
1873 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1874 if ($to->{'href'}) {
1875 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1876 esc_path
($to->{'file'}));
1877 } else { # file was deleted (no href)
1878 $line .= esc_path
($to->{'file'});
1882 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1883 if ($from->{'href'}) {
1884 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1885 'a/' . esc_path
($from->{'file'}));
1886 } else { # file was added (no href)
1887 $line .= 'a/' . esc_path
($from->{'file'});
1890 if ($to->{'href'}) {
1891 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1892 'b/' . esc_path
($to->{'file'}));
1893 } else { # file was deleted
1894 $line .= 'b/' . esc_path
($to->{'file'});
1898 return "<div class=\"diff header\">$line</div>\n";
1901 # format extended diff header line, before patch itself
1902 sub format_extended_diff_header_line
{
1904 my $diffinfo = shift;
1905 my ($from, $to) = @_;
1908 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1909 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1910 esc_path
($from->{'file'}));
1912 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1913 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1914 esc_path
($to->{'file'}));
1916 # match single <mode>
1917 if ($line =~ m/\s(\d{6})$/) {
1918 $line .= '<span class="info"> (' .
1919 file_type_long
($1) .
1923 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1924 # can match only for combined diff
1926 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1927 if ($from->{'href'}[$i]) {
1928 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1930 substr($diffinfo->{'from_id'}[$i],0,7));
1935 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1938 if ($to->{'href'}) {
1939 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1940 substr($diffinfo->{'to_id'},0,7));
1945 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1946 # can match only for ordinary diff
1947 my ($from_link, $to_link);
1948 if ($from->{'href'}) {
1949 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1950 substr($diffinfo->{'from_id'},0,7));
1952 $from_link = '0' x
7;
1954 if ($to->{'href'}) {
1955 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1956 substr($diffinfo->{'to_id'},0,7));
1960 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1961 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1964 return $line . "<br/>\n";
1967 # format from-file/to-file diff header
1968 sub format_diff_from_to_header
{
1969 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1974 #assert($line =~ m/^---/) if DEBUG;
1975 # no extra formatting for "^--- /dev/null"
1976 if (! $diffinfo->{'nparents'}) {
1977 # ordinary (single parent) diff
1978 if ($line =~ m!^--- "?a/!) {
1979 if ($from->{'href'}) {
1981 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1982 esc_path
($from->{'file'}));
1985 esc_path
($from->{'file'});
1988 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1991 # combined diff (merge commit)
1992 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1993 if ($from->{'href'}[$i]) {
1995 $cgi->a({-href
=>href
(action
=>"blobdiff",
1996 hash_parent
=>$diffinfo->{'from_id'}[$i],
1997 hash_parent_base
=>$parents[$i],
1998 file_parent
=>$from->{'file'}[$i],
1999 hash
=>$diffinfo->{'to_id'},
2001 file_name
=>$to->{'file'}),
2003 -title
=>"diff" . ($i+1)},
2006 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
2007 esc_path
($from->{'file'}[$i]));
2009 $line = '--- /dev/null';
2011 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
2016 #assert($line =~ m/^\+\+\+/) if DEBUG;
2017 # no extra formatting for "^+++ /dev/null"
2018 if ($line =~ m!^\+\+\+ "?b/!) {
2019 if ($to->{'href'}) {
2021 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
2022 esc_path
($to->{'file'}));
2025 esc_path
($to->{'file'});
2028 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
2033 # create note for patch simplified by combined diff
2034 sub format_diff_cc_simplified
{
2035 my ($diffinfo, @parents) = @_;
2038 $result .= "<div class=\"diff header\">" .
2040 if (!is_deleted
($diffinfo)) {
2041 $result .= $cgi->a({-href
=> href
(action
=>"blob",
2043 hash
=>$diffinfo->{'to_id'},
2044 file_name
=>$diffinfo->{'to_file'}),
2046 esc_path
($diffinfo->{'to_file'}));
2048 $result .= esc_path
($diffinfo->{'to_file'});
2050 $result .= "</div>\n" . # class="diff header"
2051 "<div class=\"diff nodifferences\">" .
2053 "</div>\n"; # class="diff nodifferences"
2058 # format patch (diff) line (not to be used for diff headers)
2059 sub format_diff_line
{
2061 my ($from, $to) = @_;
2062 my $diff_class = "";
2066 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
2068 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
2069 if ($line =~ m/^\@{3}/) {
2070 $diff_class = " chunk_header";
2071 } elsif ($line =~ m/^\\/) {
2072 $diff_class = " incomplete";
2073 } elsif ($prefix =~ tr/+/+/) {
2074 $diff_class = " add";
2075 } elsif ($prefix =~ tr/-/-/) {
2076 $diff_class = " rem";
2079 # assume ordinary diff
2080 my $char = substr($line, 0, 1);
2082 $diff_class = " add";
2083 } elsif ($char eq '-') {
2084 $diff_class = " rem";
2085 } elsif ($char eq '@') {
2086 $diff_class = " chunk_header";
2087 } elsif ($char eq "\\") {
2088 $diff_class = " incomplete";
2091 $line = untabify
($line);
2092 if ($from && $to && $line =~ m/^\@{2} /) {
2093 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
2094 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
2096 $from_lines = 0 unless defined $from_lines;
2097 $to_lines = 0 unless defined $to_lines;
2099 if ($from->{'href'}) {
2100 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
2101 -class=>"list"}, $from_text);
2103 if ($to->{'href'}) {
2104 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2105 -class=>"list"}, $to_text);
2107 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
2108 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2109 return "<div class=\"diff$diff_class\">$line</div>\n";
2110 } elsif ($from && $to && $line =~ m/^\@{3}/) {
2111 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
2112 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
2114 @from_text = split(' ', $ranges);
2115 for (my $i = 0; $i < @from_text; ++$i) {
2116 ($from_start[$i], $from_nlines[$i]) =
2117 (split(',', substr($from_text[$i], 1)), 0);
2120 $to_text = pop @from_text;
2121 $to_start = pop @from_start;
2122 $to_nlines = pop @from_nlines;
2124 $line = "<span class=\"chunk_info\">$prefix ";
2125 for (my $i = 0; $i < @from_text; ++$i) {
2126 if ($from->{'href'}[$i]) {
2127 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2128 -class=>"list"}, $from_text[$i]);
2130 $line .= $from_text[$i];
2134 if ($to->{'href'}) {
2135 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2136 -class=>"list"}, $to_text);
2140 $line .= " $prefix</span>" .
2141 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2142 return "<div class=\"diff$diff_class\">$line</div>\n";
2144 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2147 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2148 # linked. Pass the hash of the tree/commit to snapshot.
2149 sub format_snapshot_links
{
2151 my $num_fmts = @snapshot_fmts;
2152 if ($num_fmts > 1) {
2153 # A parenthesized list of links bearing format names.
2154 # e.g. "snapshot (_tar.gz_ _zip_)"
2155 return "snapshot (" . join(' ', map
2162 }, $known_snapshot_formats{$_}{'display'})
2163 , @snapshot_fmts) . ")";
2164 } elsif ($num_fmts == 1) {
2165 # A single "snapshot" link whose tooltip bears the format name.
2167 my ($fmt) = @snapshot_fmts;
2173 snapshot_format
=>$fmt
2175 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2177 } else { # $num_fmts == 0
2182 ## ......................................................................
2183 ## functions returning values to be passed, perhaps after some
2184 ## transformation, to other functions; e.g. returning arguments to href()
2186 # returns hash to be passed to href to generate gitweb URL
2187 # in -title key it returns description of link
2189 my $format = shift || 'Atom';
2190 my %res = (action
=> lc($format));
2192 # feed links are possible only for project views
2193 return unless (defined $project);
2194 # some views should link to OPML, or to generic project feed,
2195 # or don't have specific feed yet (so they should use generic)
2196 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2199 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2200 # from tag links; this also makes possible to detect branch links
2201 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2202 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2205 # find log type for feed description (title)
2207 if (defined $file_name) {
2208 $type = "history of $file_name";
2209 $type .= "/" if ($action eq 'tree');
2210 $type .= " on '$branch'" if (defined $branch);
2212 $type = "log of $branch" if (defined $branch);
2215 $res{-title
} = $type;
2216 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2217 $res{'file_name'} = $file_name;
2222 ## ----------------------------------------------------------------------
2223 ## git utility subroutines, invoking git commands
2225 # returns path to the core git executable and the --git-dir parameter as list
2227 $number_of_git_cmds++;
2228 return $GIT, '--git-dir='.$git_dir;
2231 # quote the given arguments for passing them to the shell
2232 # quote_command("command", "arg 1", "arg with ' and ! characters")
2233 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2234 # Try to avoid using this function wherever possible.
2237 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2240 # get HEAD ref of given project as hash
2241 sub git_get_head_hash
{
2242 return git_get_full_hash
(shift, 'HEAD');
2245 sub git_get_full_hash
{
2246 return git_get_hash
(@_);
2249 sub git_get_short_hash
{
2250 return git_get_hash
(@_, '--short=7');
2254 my ($project, $hash, @options) = @_;
2255 my $o_git_dir = $git_dir;
2257 $git_dir = "$projectroot/$project";
2258 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2259 '--verify', '-q', @options, $hash) {
2261 chomp $retval if defined $retval;
2264 if (defined $o_git_dir) {
2265 $git_dir = $o_git_dir;
2270 # get type of given object
2274 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2276 close $fd or return;
2281 # repository configuration
2282 our $config_file = '';
2285 # store multiple values for single key as anonymous array reference
2286 # single values stored directly in the hash, not as [ <value> ]
2287 sub hash_set_multi
{
2288 my ($hash, $key, $value) = @_;
2290 if (!exists $hash->{$key}) {
2291 $hash->{$key} = $value;
2292 } elsif (!ref $hash->{$key}) {
2293 $hash->{$key} = [ $hash->{$key}, $value ];
2295 push @
{$hash->{$key}}, $value;
2299 # return hash of git project configuration
2300 # optionally limited to some section, e.g. 'gitweb'
2301 sub git_parse_project_config
{
2302 my $section_regexp = shift;
2307 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2310 while (my $keyval = <$fh>) {
2312 my ($key, $value) = split(/\n/, $keyval, 2);
2314 hash_set_multi
(\
%config, $key, $value)
2315 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2322 # convert config value to boolean: 'true' or 'false'
2323 # no value, number > 0, 'true' and 'yes' values are true
2324 # rest of values are treated as false (never as error)
2325 sub config_to_bool
{
2328 return 1 if !defined $val; # section.key
2330 # strip leading and trailing whitespace
2334 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2335 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2338 # convert config value to simple decimal number
2339 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2340 # to be multiplied by 1024, 1048576, or 1073741824
2344 # strip leading and trailing whitespace
2348 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2350 # unknown unit is treated as 1
2351 return $num * ($unit eq 'g' ?
1073741824 :
2352 $unit eq 'm' ?
1048576 :
2353 $unit eq 'k' ?
1024 : 1);
2358 # convert config value to array reference, if needed
2359 sub config_to_multi
{
2362 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2365 sub git_get_project_config
{
2366 my ($key, $type) = @_;
2368 return unless defined $git_dir;
2371 return unless ($key);
2372 $key =~ s/^gitweb\.//;
2373 return if ($key =~ m/\W/);
2376 if (defined $type) {
2379 unless ($type eq 'bool' || $type eq 'int');
2383 if (!defined $config_file ||
2384 $config_file ne "$git_dir/config") {
2385 %config = git_parse_project_config
('gitweb');
2386 $config_file = "$git_dir/config";
2389 # check if config variable (key) exists
2390 return unless exists $config{"gitweb.$key"};
2393 if (!defined $type) {
2394 return $config{"gitweb.$key"};
2395 } elsif ($type eq 'bool') {
2396 # backward compatibility: 'git config --bool' returns true/false
2397 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2398 } elsif ($type eq 'int') {
2399 return config_to_int
($config{"gitweb.$key"});
2401 return $config{"gitweb.$key"};
2404 # get hash of given path at given ref
2405 sub git_get_hash_by_path
{
2407 my $path = shift || return undef;
2412 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2413 or die_error
(500, "Open git-ls-tree failed");
2415 close $fd or return undef;
2417 if (!defined $line) {
2418 # there is no tree or hash given by $path at $base
2422 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2423 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2424 if (defined $type && $type ne $2) {
2425 # type doesn't match
2431 # get path of entry with given hash at given tree-ish (ref)
2432 # used to get 'from' filename for combined diff (merge commit) for renames
2433 sub git_get_path_by_hash
{
2434 my $base = shift || return;
2435 my $hash = shift || return;
2439 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2441 while (my $line = <$fd>) {
2444 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2445 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2446 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2455 ## ......................................................................
2456 ## git utility functions, directly accessing git repository
2458 sub git_get_project_description
{
2461 $git_dir = "$projectroot/$path";
2462 open my $fd, '<', "$git_dir/description"
2463 or return git_get_project_config
('description');
2466 if (defined $descr) {
2472 sub git_get_project_ctags
{
2476 $git_dir = "$projectroot/$path";
2477 opendir my $dh, "$git_dir/ctags"
2479 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2480 open my $ct, '<', $_ or next;
2484 my $ctag = $_; $ctag =~ s
#.*/##;
2485 $ctags->{$ctag} = $val;
2491 sub git_populate_project_tagcloud
{
2494 # First, merge different-cased tags; tags vote on casing
2496 foreach (keys %$ctags) {
2497 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2498 if (not $ctags_lc{lc $_}->{topcount
}
2499 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2500 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2501 $ctags_lc{lc $_}->{topname
} = $_;
2506 if (eval { require HTML
::TagCloud
; 1; }) {
2507 $cloud = HTML
::TagCloud
->new;
2508 foreach (sort keys %ctags_lc) {
2509 # Pad the title with spaces so that the cloud looks
2511 my $title = $ctags_lc{$_}->{topname
};
2512 $title =~ s/ / /g;
2513 $title =~ s/^/ /g;
2514 $title =~ s/$/ /g;
2515 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2518 $cloud = \
%ctags_lc;
2523 sub git_show_project_tagcloud
{
2524 my ($cloud, $count) = @_;
2525 print STDERR
ref($cloud)."..\n";
2526 if (ref $cloud eq 'HTML::TagCloud') {
2527 return $cloud->html_and_css($count);
2529 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2530 return '<p align="center">' . join (', ', map {
2531 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2532 } splice(@tags, 0, $count)) . '</p>';
2536 sub git_get_project_url_list
{
2539 $git_dir = "$projectroot/$path";
2540 open my $fd, '<', "$git_dir/cloneurl"
2541 or return wantarray ?
2542 @
{ config_to_multi
(git_get_project_config
('url')) } :
2543 config_to_multi
(git_get_project_config
('url'));
2544 my @git_project_url_list = map { chomp; $_ } <$fd>;
2547 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2550 sub git_get_projects_list
{
2555 $filter =~ s/\.git$//;
2557 my $check_forks = gitweb_check_feature
('forks');
2559 if (-d
$projects_list) {
2560 # search in directory
2561 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2562 # remove the trailing "/"
2564 my $pfxlen = length("$dir");
2565 my $pfxdepth = ($dir =~ tr!/!!);
2568 follow_fast
=> 1, # follow symbolic links
2569 follow_skip
=> 2, # ignore duplicates
2570 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2573 our $project_maxdepth;
2575 # skip project-list toplevel, if we get it.
2576 return if (m!^[/.]$!);
2577 # only directories can be git repositories
2578 return unless (-d
$_);
2579 # don't traverse too deep (Find is super slow on os x)
2580 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2581 $File::Find
::prune
= 1;
2585 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2586 # we check related file in $projectroot
2587 my $path = ($filter ?
"$filter/" : '') . $subdir;
2588 if (check_export_ok
("$projectroot/$path")) {
2589 push @list, { path
=> $path };
2590 $File::Find
::prune
= 1;
2595 } elsif (-f
$projects_list) {
2596 # read from file(url-encoded):
2597 # 'git%2Fgit.git Linus+Torvalds'
2598 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2599 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2601 open my $fd, '<', $projects_list or return;
2603 while (my $line = <$fd>) {
2605 my ($path, $owner) = split ' ', $line;
2606 $path = unescape
($path);
2607 $owner = unescape
($owner);
2608 if (!defined $path) {
2611 if ($filter ne '') {
2612 # looking for forks;
2613 my $pfx = substr($path, 0, length($filter));
2614 if ($pfx ne $filter) {
2617 my $sfx = substr($path, length($filter));
2618 if ($sfx !~ /^\/.*\
.git
$/) {
2621 } elsif ($check_forks) {
2623 foreach my $filter (keys %paths) {
2624 # looking for forks;
2625 my $pfx = substr($path, 0, length($filter));
2626 if ($pfx ne $filter) {
2629 my $sfx = substr($path, length($filter));
2630 if ($sfx !~ /^\/.*\
.git
$/) {
2633 # is a fork, don't include it in
2638 if (check_export_ok
("$projectroot/$path")) {
2641 owner
=> to_utf8
($owner),
2644 (my $forks_path = $path) =~ s/\.git$//;
2645 $paths{$forks_path}++;
2653 our $gitweb_project_owner = undef;
2654 sub git_get_project_list_from_file
{
2656 return if (defined $gitweb_project_owner);
2658 $gitweb_project_owner = {};
2659 # read from file (url-encoded):
2660 # 'git%2Fgit.git Linus+Torvalds'
2661 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2662 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2663 if (-f
$projects_list) {
2664 open(my $fd, '<', $projects_list);
2665 while (my $line = <$fd>) {
2667 my ($pr, $ow) = split ' ', $line;
2668 $pr = unescape
($pr);
2669 $ow = unescape
($ow);
2670 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2676 sub git_get_project_owner
{
2677 my $project = shift;
2680 return undef unless $project;
2681 $git_dir = "$projectroot/$project";
2683 if (!defined $gitweb_project_owner) {
2684 git_get_project_list_from_file
();
2687 if (exists $gitweb_project_owner->{$project}) {
2688 $owner = $gitweb_project_owner->{$project};
2690 if (!defined $owner){
2691 $owner = git_get_project_config
('owner');
2693 if (!defined $owner) {
2694 $owner = get_file_owner
("$git_dir");
2700 sub git_get_last_activity
{
2704 $git_dir = "$projectroot/$path";
2705 open($fd, "-|", git_cmd
(), 'for-each-ref',
2706 '--format=%(committer)',
2707 '--sort=-committerdate',
2709 'refs/heads') or return;
2710 my $most_recent = <$fd>;
2711 close $fd or return;
2712 if (defined $most_recent &&
2713 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2715 my $age = time - $timestamp;
2716 return ($age, age_string
($age));
2718 return (undef, undef);
2721 sub git_get_references
{
2722 my $type = shift || "";
2724 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2725 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2726 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2727 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2730 while (my $line = <$fd>) {
2732 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2733 if (defined $refs{$1}) {
2734 push @
{$refs{$1}}, $2;
2740 close $fd or return;
2744 sub git_get_rev_name_tags
{
2745 my $hash = shift || return undef;
2747 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2749 my $name_rev = <$fd>;
2752 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2755 # catches also '$hash undefined' output
2760 ## ----------------------------------------------------------------------
2761 ## parse to hash functions
2765 my $tz = shift || "-0000";
2768 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2769 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2770 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2771 $date{'hour'} = $hour;
2772 $date{'minute'} = $min;
2773 $date{'mday'} = $mday;
2774 $date{'day'} = $days[$wday];
2775 $date{'month'} = $months[$mon];
2776 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2777 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2778 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2779 $mday, $months[$mon], $hour ,$min;
2780 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2781 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2783 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2784 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2785 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2786 $date{'hour_local'} = $hour;
2787 $date{'minute_local'} = $min;
2788 $date{'tz_local'} = $tz;
2789 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2790 1900+$year, $mon+1, $mday,
2791 $hour, $min, $sec, $tz);
2800 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2801 $tag{'id'} = $tag_id;
2802 while (my $line = <$fd>) {
2804 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2805 $tag{'object'} = $1;
2806 } elsif ($line =~ m/^type (.+)$/) {
2808 } elsif ($line =~ m/^tag (.+)$/) {
2810 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2811 $tag{'author'} = $1;
2812 $tag{'author_epoch'} = $2;
2813 $tag{'author_tz'} = $3;
2814 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2815 $tag{'author_name'} = $1;
2816 $tag{'author_email'} = $2;
2818 $tag{'author_name'} = $tag{'author'};
2820 } elsif ($line =~ m/--BEGIN/) {
2821 push @comment, $line;
2823 } elsif ($line eq "") {
2827 push @comment, <$fd>;
2828 $tag{'comment'} = \
@comment;
2829 close $fd or return;
2830 if (!defined $tag{'name'}) {
2836 sub parse_commit_text
{
2837 my ($commit_text, $withparents) = @_;
2838 my @commit_lines = split '\n', $commit_text;
2841 pop @commit_lines; # Remove '\0'
2843 if (! @commit_lines) {
2847 my $header = shift @commit_lines;
2848 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2851 ($co{'id'}, my @parents) = split ' ', $header;
2852 while (my $line = shift @commit_lines) {
2853 last if $line eq "\n";
2854 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2856 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2858 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2859 $co{'author'} = to_utf8
($1);
2860 $co{'author_epoch'} = $2;
2861 $co{'author_tz'} = $3;
2862 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2863 $co{'author_name'} = $1;
2864 $co{'author_email'} = $2;
2866 $co{'author_name'} = $co{'author'};
2868 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2869 $co{'committer'} = to_utf8
($1);
2870 $co{'committer_epoch'} = $2;
2871 $co{'committer_tz'} = $3;
2872 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2873 $co{'committer_name'} = $1;
2874 $co{'committer_email'} = $2;
2876 $co{'committer_name'} = $co{'committer'};
2880 if (!defined $co{'tree'}) {
2883 $co{'parents'} = \
@parents;
2884 $co{'parent'} = $parents[0];
2886 foreach my $title (@commit_lines) {
2889 $co{'title'} = chop_str
($title, 80, 5);
2890 # remove leading stuff of merges to make the interesting part visible
2891 if (length($title) > 50) {
2892 $title =~ s/^Automatic //;
2893 $title =~ s/^merge (of|with) /Merge ... /i;
2894 if (length($title) > 50) {
2895 $title =~ s/(http|rsync):\/\///;
2897 if (length($title) > 50) {
2898 $title =~ s/(master|www|rsync)\.//;
2900 if (length($title) > 50) {
2901 $title =~ s/kernel.org:?//;
2903 if (length($title) > 50) {
2904 $title =~ s/\/pub\/scm//;
2907 $co{'title_short'} = chop_str
($title, 50, 5);
2911 if (! defined $co{'title'} || $co{'title'} eq "") {
2912 $co{'title'} = $co{'title_short'} = '(no commit message)';
2914 # remove added spaces
2915 foreach my $line (@commit_lines) {
2918 $co{'comment'} = \
@commit_lines;
2920 my $age = time - $co{'committer_epoch'};
2922 $co{'age_string'} = age_string
($age);
2923 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2924 if ($age > 60*60*24*7*2) {
2925 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2926 $co{'age_string_age'} = $co{'age_string'};
2928 $co{'age_string_date'} = $co{'age_string'};
2929 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2935 my ($commit_id) = @_;
2940 open my $fd, "-|", git_cmd
(), "rev-list",
2946 or die_error
(500, "Open git-rev-list failed");
2947 %co = parse_commit_text
(<$fd>, 1);
2954 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2962 open my $fd, "-|", git_cmd
(), "rev-list",
2965 ("--max-count=" . $maxcount),
2966 ("--skip=" . $skip),
2970 ($filename ?
($filename) : ())
2971 or die_error
(500, "Open git-rev-list failed");
2972 while (my $line = <$fd>) {
2973 my %co = parse_commit_text
($line);
2978 return wantarray ?
@cos : \
@cos;
2981 # parse line of git-diff-tree "raw" output
2982 sub parse_difftree_raw_line
{
2986 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2987 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2988 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2989 $res{'from_mode'} = $1;
2990 $res{'to_mode'} = $2;
2991 $res{'from_id'} = $3;
2993 $res{'status'} = $5;
2994 $res{'similarity'} = $6;
2995 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2996 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2998 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
3001 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
3002 # combined diff (for merge commit)
3003 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
3004 $res{'nparents'} = length($1);
3005 $res{'from_mode'} = [ split(' ', $2) ];
3006 $res{'to_mode'} = pop @
{$res{'from_mode'}};
3007 $res{'from_id'} = [ split(' ', $3) ];
3008 $res{'to_id'} = pop @
{$res{'from_id'}};
3009 $res{'status'} = [ split('', $4) ];
3010 $res{'to_file'} = unquote
($5);
3012 # 'c512b523472485aef4fff9e57b229d9d243c967f'
3013 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
3014 $res{'commit'} = $1;
3017 return wantarray ?
%res : \
%res;
3020 # wrapper: return parsed line of git-diff-tree "raw" output
3021 # (the argument might be raw line, or parsed info)
3022 sub parsed_difftree_line
{
3023 my $line_or_ref = shift;
3025 if (ref($line_or_ref) eq "HASH") {
3026 # pre-parsed (or generated by hand)
3027 return $line_or_ref;
3029 return parse_difftree_raw_line
($line_or_ref);
3033 # parse line of git-ls-tree output
3034 sub parse_ls_tree_line
{
3040 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
3041 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
3050 $res{'name'} = unquote
($5);
3053 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3054 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
3062 $res{'name'} = unquote
($4);
3066 return wantarray ?
%res : \
%res;
3069 # generates _two_ hashes, references to which are passed as 2 and 3 argument
3070 sub parse_from_to_diffinfo
{
3071 my ($diffinfo, $from, $to, @parents) = @_;
3073 if ($diffinfo->{'nparents'}) {
3075 $from->{'file'} = [];
3076 $from->{'href'} = [];
3077 fill_from_file_info
($diffinfo, @parents)
3078 unless exists $diffinfo->{'from_file'};
3079 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3080 $from->{'file'}[$i] =
3081 defined $diffinfo->{'from_file'}[$i] ?
3082 $diffinfo->{'from_file'}[$i] :
3083 $diffinfo->{'to_file'};
3084 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3085 $from->{'href'}[$i] = href
(action
=>"blob",
3086 hash_base
=>$parents[$i],
3087 hash
=>$diffinfo->{'from_id'}[$i],
3088 file_name
=>$from->{'file'}[$i]);
3090 $from->{'href'}[$i] = undef;
3094 # ordinary (not combined) diff
3095 $from->{'file'} = $diffinfo->{'from_file'};
3096 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3097 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3098 hash
=>$diffinfo->{'from_id'},
3099 file_name
=>$from->{'file'});
3101 delete $from->{'href'};
3105 $to->{'file'} = $diffinfo->{'to_file'};
3106 if (!is_deleted
($diffinfo)) { # file exists in result
3107 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3108 hash
=>$diffinfo->{'to_id'},
3109 file_name
=>$to->{'file'});
3111 delete $to->{'href'};
3115 ## ......................................................................
3116 ## parse to array of hashes functions
3118 sub git_get_heads_list
{
3122 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3123 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
3124 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
3127 while (my $line = <$fd>) {
3131 my ($refinfo, $committerinfo) = split(/\0/, $line);
3132 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3133 my ($committer, $epoch, $tz) =
3134 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3135 $ref_item{'fullname'} = $name;
3136 $name =~ s!^refs/heads/!!;
3138 $ref_item{'name'} = $name;
3139 $ref_item{'id'} = $hash;
3140 $ref_item{'title'} = $title || '(no commit message)';
3141 $ref_item{'epoch'} = $epoch;
3143 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3145 $ref_item{'age'} = "unknown";
3148 push @headslist, \
%ref_item;
3152 return wantarray ?
@headslist : \
@headslist;
3155 sub git_get_tags_list
{
3159 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3160 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3161 '--format=%(objectname) %(objecttype) %(refname) '.
3162 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3165 while (my $line = <$fd>) {
3169 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3170 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3171 my ($creator, $epoch, $tz) =
3172 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3173 $ref_item{'fullname'} = $name;
3174 $name =~ s!^refs/tags/!!;
3176 $ref_item{'type'} = $type;
3177 $ref_item{'id'} = $id;
3178 $ref_item{'name'} = $name;
3179 if ($type eq "tag") {
3180 $ref_item{'subject'} = $title;
3181 $ref_item{'reftype'} = $reftype;
3182 $ref_item{'refid'} = $refid;
3184 $ref_item{'reftype'} = $type;
3185 $ref_item{'refid'} = $id;
3188 if ($type eq "tag" || $type eq "commit") {
3189 $ref_item{'epoch'} = $epoch;
3191 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3193 $ref_item{'age'} = "unknown";
3197 push @tagslist, \
%ref_item;
3201 return wantarray ?
@tagslist : \
@tagslist;
3204 ## ----------------------------------------------------------------------
3205 ## filesystem-related functions
3207 sub get_file_owner
{
3210 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3211 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3212 if (!defined $gcos) {
3216 $owner =~ s/[,;].*$//;
3217 return to_utf8
($owner);
3220 # assume that file exists
3222 my $filename = shift;
3224 open my $fd, '<', $filename;
3225 print map { to_utf8
($_) } <$fd>;
3229 ## ......................................................................
3230 ## mimetype related functions
3232 sub mimetype_guess_file
{
3233 my $filename = shift;
3234 my $mimemap = shift;
3235 -r
$mimemap or return undef;
3238 open(my $mh, '<', $mimemap) or return undef;
3240 next if m/^#/; # skip comments
3241 my ($mimetype, $exts) = split(/\t+/);
3242 if (defined $exts) {
3243 my @exts = split(/\s+/, $exts);
3244 foreach my $ext (@exts) {
3245 $mimemap{$ext} = $mimetype;
3251 $filename =~ /\.([^.]*)$/;
3252 return $mimemap{$1};
3255 sub mimetype_guess
{
3256 my $filename = shift;
3258 $filename =~ /\./ or return undef;
3260 if ($mimetypes_file) {
3261 my $file = $mimetypes_file;
3262 if ($file !~ m!^/!) { # if it is relative path
3263 # it is relative to project
3264 $file = "$projectroot/$project/$file";
3266 $mime = mimetype_guess_file
($filename, $file);
3268 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3274 my $filename = shift;
3277 my $mime = mimetype_guess
($filename);
3278 $mime and return $mime;
3282 return $default_blob_plain_mimetype unless $fd;
3285 return 'text/plain';
3286 } elsif (! $filename) {
3287 return 'application/octet-stream';
3288 } elsif ($filename =~ m/\.png$/i) {
3290 } elsif ($filename =~ m/\.gif$/i) {
3292 } elsif ($filename =~ m/\.jpe?g$/i) {
3293 return 'image/jpeg';
3295 return 'application/octet-stream';
3299 sub blob_contenttype
{
3300 my ($fd, $file_name, $type) = @_;
3302 $type ||= blob_mimetype
($fd, $file_name);
3303 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3304 $type .= "; charset=$default_text_plain_charset";
3310 # guess file syntax for syntax highlighting; return undef if no highlighting
3311 # the name of syntax can (in the future) depend on syntax highlighter used
3312 sub guess_file_syntax
{
3313 my ($highlight, $mimetype, $file_name) = @_;
3314 return undef unless ($highlight && defined $file_name);
3316 # configuration for 'highlight' (http://www.andre-simon.de/)
3318 my %highlight_basename = (
3321 'SConstruct' => 'py', # SCons equivalent of Makefile
3322 'Makefile' => 'make',
3324 # match by extension
3325 my %highlight_ext = (
3326 # main extensions, defining name of syntax;
3327 # see files in /usr/share/highlight/langDefs/ directory
3329 qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
3330 # alternate extensions, see /etc/highlight/filetypes.conf
3332 map { $_ => 'cpp' } qw(cxx c++ cc),
3333 map { $_ => 'php' } qw(php3 php4),
3334 map { $_ => 'pl' } qw(perl pm), # perhaps also 'cgi'
3336 map { $_ => 'xml' } qw(xhtml html htm),
3339 my $basename = basename
($file_name, '.in');
3340 return $highlight_basename{$basename}
3341 if exists $highlight_basename{$basename};
3343 $basename =~ /\.([^.]*)$/;
3344 my $ext = $1 or return undef;
3345 return $highlight_ext{$ext}
3346 if exists $highlight_ext{$ext};
3351 # run highlighter and return FD of its output,
3352 # or return original FD if no highlighting
3353 sub run_highlighter
{
3354 my ($fd, $highlight, $syntax) = @_;
3355 return $fd unless ($highlight && defined $syntax);
3358 or die_error
(404, "Reading blob failed");
3359 open $fd, quote_command
(git_cmd
(), "cat-file", "blob", $hash)." | ".
3360 "highlight --xhtml --fragment --syntax $syntax |"
3361 or die_error
(500, "Couldn't open file or run syntax highlighter");
3365 ## ======================================================================
3366 ## functions printing HTML: header, footer, error page
3368 sub get_page_title
{
3369 my $title = to_utf8
($site_name);
3371 return $title unless (defined $project);
3372 $title .= " - " . to_utf8
($project);
3374 return $title unless (defined $action);
3375 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3377 return $title unless (defined $file_name);
3378 $title .= " - " . esc_path
($file_name);
3379 if ($action eq "tree" && $file_name !~ m
|/$|) {
3386 sub git_header_html
{
3387 my $status = shift || "200 OK";
3388 my $expires = shift;
3391 my $title = get_page_title
();
3393 # require explicit support from the UA if we are to send the page as
3394 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3395 # we have to do this because MSIE sometimes globs '*/*', pretending to
3396 # support xhtml+xml but choking when it gets what it asked for.
3397 if (defined $cgi->http('HTTP_ACCEPT') &&
3398 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3399 $cgi->Accept('application/xhtml+xml') != 0) {
3400 $content_type = 'application/xhtml+xml';
3402 $content_type = 'text/html';
3404 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3405 -status
=> $status, -expires
=> $expires)
3406 unless ($opts{'-no_http_header'});
3407 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3409 <?xml version="1.0" encoding="utf-8"?>
3410 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3411 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3412 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3413 <!-- git core binaries version $git_version -->
3415 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3416 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3417 <meta name="robots" content="index, nofollow"/>
3418 <title>$title</title>
3420 # the stylesheet, favicon etc urls won't work correctly with path_info
3421 # unless we set the appropriate base URL
3422 if ($ENV{'PATH_INFO'}) {
3423 print "<base href=\"".esc_url
($base_url)."\" />\n";
3425 # print out each stylesheet that exist, providing backwards capability
3426 # for those people who defined $stylesheet in a config file
3427 if (defined $stylesheet) {
3428 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3430 foreach my $stylesheet (@stylesheets) {
3431 next unless $stylesheet;
3432 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3435 if (defined $project) {
3436 my %href_params = get_feed_info
();
3437 if (!exists $href_params{'-title'}) {
3438 $href_params{'-title'} = 'log';
3441 foreach my $format qw(RSS Atom) {
3442 my $type = lc($format);
3444 '-rel' => 'alternate',
3445 '-title' => "$project - $href_params{'-title'} - $format feed",
3446 '-type' => "application/$type+xml"
3449 $href_params{'action'} = $type;
3450 $link_attr{'-href'} = href
(%href_params);
3452 "rel=\"$link_attr{'-rel'}\" ".
3453 "title=\"$link_attr{'-title'}\" ".
3454 "href=\"$link_attr{'-href'}\" ".
3455 "type=\"$link_attr{'-type'}\" ".
3458 $href_params{'extra_options'} = '--no-merges';
3459 $link_attr{'-href'} = href
(%href_params);
3460 $link_attr{'-title'} .= ' (no merges)';
3462 "rel=\"$link_attr{'-rel'}\" ".
3463 "title=\"$link_attr{'-title'}\" ".
3464 "href=\"$link_attr{'-href'}\" ".
3465 "type=\"$link_attr{'-type'}\" ".
3470 printf('<link rel="alternate" title="%s projects list" '.
3471 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3472 $site_name, href
(project
=>undef, action
=>"project_index"));
3473 printf('<link rel="alternate" title="%s projects feeds" '.
3474 'href="%s" type="text/x-opml" />'."\n",
3475 $site_name, href
(project
=>undef, action
=>"opml"));
3477 if (defined $favicon) {
3478 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3484 if (defined $site_header && -f
$site_header) {
3485 insert_file
($site_header);
3488 print "<div class=\"page_header\">\n" .
3489 $cgi->a({-href
=> esc_url
($logo_url),
3490 -title
=> $logo_label},
3491 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3492 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3493 if (defined $project) {
3494 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3495 if (defined $action) {
3502 my $have_search = gitweb_check_feature
('search');
3503 if (defined $project && $have_search) {
3504 if (!defined $searchtext) {
3508 if (defined $hash_base) {
3509 $search_hash = $hash_base;
3510 } elsif (defined $hash) {
3511 $search_hash = $hash;
3513 $search_hash = "HEAD";
3515 my $action = $my_uri;
3516 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3517 if ($use_pathinfo) {
3518 $action .= "/".esc_url
($project);
3520 print $cgi->startform(-method
=> "get", -action
=> $action) .
3521 "<div class=\"search\">\n" .
3523 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3524 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3525 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3526 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3527 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3528 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3530 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3531 "<span title=\"Extended regular expression\">" .
3532 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3533 -checked
=> $search_use_regexp) .
3536 $cgi->end_form() . "\n";
3540 sub git_footer_html
{
3541 my $feed_class = 'rss_logo';
3543 print "<div class=\"page_footer\">\n";
3544 if (defined $project) {
3545 my $descr = git_get_project_description
($project);
3546 if (defined $descr) {
3547 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3550 my %href_params = get_feed_info
();
3551 if (!%href_params) {
3552 $feed_class .= ' generic';
3554 $href_params{'-title'} ||= 'log';
3556 foreach my $format qw(RSS Atom) {
3557 $href_params{'action'} = lc($format);
3558 print $cgi->a({-href
=> href
(%href_params),
3559 -title
=> "$href_params{'-title'} $format feed",
3560 -class => $feed_class}, $format)."\n";
3564 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3565 -class => $feed_class}, "OPML") . " ";
3566 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3567 -class => $feed_class}, "TXT") . "\n";
3569 print "</div>\n"; # class="page_footer"
3571 if (defined $t0 && gitweb_check_feature
('timed')) {
3572 print "<div id=\"generating_info\">\n";
3573 print 'This page took '.
3574 '<span id="generating_time" class="time_span">'.
3575 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3578 '<span id="generating_cmd">'.
3579 $number_of_git_cmds.
3580 '</span> git commands '.
3582 print "</div>\n"; # class="page_footer"
3585 if (defined $site_footer && -f
$site_footer) {
3586 insert_file
($site_footer);
3589 print qq!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3590 if (defined $action &&
3591 $action eq 'blame_incremental') {
3592 print qq!<script type
="text/javascript">\n!.
3593 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3594 qq! "!. href() .qq!");\n!.
3596 } elsif (gitweb_check_feature
('javascript-actions')) {
3597 print qq!<script type
="text/javascript">\n!.
3598 qq!window
.onload
= fixLinks
;\n!.
3606 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3607 # Example: die_error(404, 'Hash not found')
3608 # By convention, use the following status codes (as defined in RFC 2616):
3609 # 400: Invalid or missing CGI parameters, or
3610 # requested object exists but has wrong type.
3611 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3612 # this server or project.
3613 # 404: Requested object/revision/project doesn't exist.
3614 # 500: The server isn't configured properly, or
3615 # an internal error occurred (e.g. failed assertions caused by bugs), or
3616 # an unknown error occurred (e.g. the git binary died unexpectedly).
3617 # 503: The server is currently unavailable (because it is overloaded,
3618 # or down for maintenance). Generally, this is a temporary state.
3620 my $status = shift || 500;
3621 my $error = esc_html
(shift) || "Internal Server Error";
3625 my %http_responses = (
3626 400 => '400 Bad Request',
3627 403 => '403 Forbidden',
3628 404 => '404 Not Found',
3629 500 => '500 Internal Server Error',
3630 503 => '503 Service Unavailable',
3632 git_header_html
($http_responses{$status}, undef, %opts);
3634 <div class="page_body">
3639 if (defined $extra) {
3647 unless ($opts{'-error_handler'});
3650 ## ----------------------------------------------------------------------
3651 ## functions printing or outputting HTML: navigation
3653 sub git_print_page_nav
{
3654 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3655 $extra = '' if !defined $extra; # pager or formats
3657 my @navs = qw(summary shortlog log commit commitdiff tree);
3659 @navs = grep { $_ ne $suppress } @navs;
3662 my %arg = map { $_ => {action
=>$_} } @navs;
3663 if (defined $head) {
3664 for (qw(commit commitdiff)) {
3665 $arg{$_}{'hash'} = $head;
3667 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3668 for (qw(shortlog log)) {
3669 $arg{$_}{'hash'} = $head;
3674 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3675 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3677 my @actions = gitweb_get_feature
('actions');
3680 'n' => $project, # project name
3681 'f' => $git_dir, # project path within filesystem
3682 'h' => $treehead || '', # current hash ('h' parameter)
3683 'b' => $treebase || '', # hash base ('hb' parameter)
3686 my ($label, $link, $pos) = splice(@actions,0,3);
3688 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3690 $link =~ s/%([%nfhb])/$repl{$1}/g;
3691 $arg{$label}{'_href'} = $link;
3694 print "<div class=\"page_nav\">\n" .
3696 map { $_ eq $current ?
3697 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3699 print "<br/>\n$extra<br/>\n" .
3703 sub format_paging_nav
{
3704 my ($action, $page, $has_next_link) = @_;
3710 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3712 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3713 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3715 $paging_nav .= "first ⋅ prev";
3718 if ($has_next_link) {
3719 $paging_nav .= " ⋅ " .
3720 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3721 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3723 $paging_nav .= " ⋅ next";
3729 ## ......................................................................
3730 ## functions printing or outputting HTML: div
3732 sub git_print_header_div
{
3733 my ($action, $title, $hash, $hash_base) = @_;
3736 $args{'action'} = $action;
3737 $args{'hash'} = $hash if $hash;
3738 $args{'hash_base'} = $hash_base if $hash_base;
3740 print "<div class=\"header\">\n" .
3741 $cgi->a({-href
=> href
(%args), -class => "title"},
3742 $title ?
$title : $action) .
3746 sub print_local_time
{
3747 print format_local_time
(@_);
3750 sub format_local_time
{
3753 if ($date{'hour_local'} < 6) {
3754 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3755 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3757 $localtime .= sprintf(" (%02d:%02d %s)",
3758 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3764 # Outputs the author name and date in long form
3765 sub git_print_authorship
{
3768 my $tag = $opts{-tag
} || 'div';
3769 my $author = $co->{'author_name'};
3771 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3772 print "<$tag class=\"author_date\">" .
3773 format_search_author
($author, "author", esc_html
($author)) .
3775 print_local_time
(%ad) if ($opts{-localtime});
3776 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3780 # Outputs table rows containing the full author or committer information,
3781 # in the format expected for 'commit' view (& similia).
3782 # Parameters are a commit hash reference, followed by the list of people
3783 # to output information for. If the list is empty it defalts to both
3784 # author and committer.
3785 sub git_print_authorship_rows
{
3787 # too bad we can't use @people = @_ || ('author', 'committer')
3789 @people = ('author', 'committer') unless @people;
3790 foreach my $who (@people) {
3791 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3792 print "<tr><td>$who</td><td>" .
3793 format_search_author
($co->{"${who}_name"}, $who,
3794 esc_html
($co->{"${who}_name"})) . " " .
3795 format_search_author
($co->{"${who}_email"}, $who,
3796 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3797 "</td><td rowspan=\"2\">" .
3798 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3801 "<td></td><td> $wd{'rfc2822'}";
3802 print_local_time
(%wd);
3808 sub git_print_page_path
{
3814 print "<div class=\"page_path\">";
3815 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3816 -title
=> 'tree root'}, to_utf8
("[$project]"));
3818 if (defined $name) {
3819 my @dirname = split '/', $name;
3820 my $basename = pop @dirname;
3823 foreach my $dir (@dirname) {
3824 $fullname .= ($fullname ?
'/' : '') . $dir;
3825 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3827 -title
=> $fullname}, esc_path
($dir));
3830 if (defined $type && $type eq 'blob') {
3831 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3833 -title
=> $name}, esc_path
($basename));
3834 } elsif (defined $type && $type eq 'tree') {
3835 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3837 -title
=> $name}, esc_path
($basename));
3840 print esc_path
($basename);
3843 print "<br/></div>\n";
3850 if ($opts{'-remove_title'}) {
3851 # remove title, i.e. first line of log
3854 # remove leading empty lines
3855 while (defined $log->[0] && $log->[0] eq "") {
3862 foreach my $line (@
$log) {
3863 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3866 if (! $opts{'-remove_signoff'}) {
3867 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3870 # remove signoff lines
3877 # print only one empty line
3878 # do not print empty line after signoff
3880 next if ($empty || $signoff);
3886 print format_log_line_html
($line) . "<br/>\n";
3889 if ($opts{'-final_empty_line'}) {
3890 # end with single empty line
3891 print "<br/>\n" unless $empty;
3895 # return link target (what link points to)
3896 sub git_get_link_target
{
3901 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3905 $link_target = <$fd>;
3910 return $link_target;
3913 # given link target, and the directory (basedir) the link is in,
3914 # return target of link relative to top directory (top tree);
3915 # return undef if it is not possible (including absolute links).
3916 sub normalize_link_target
{
3917 my ($link_target, $basedir) = @_;
3919 # absolute symlinks (beginning with '/') cannot be normalized
3920 return if (substr($link_target, 0, 1) eq '/');
3922 # normalize link target to path from top (root) tree (dir)
3925 $path = $basedir . '/' . $link_target;
3927 # we are in top (root) tree (dir)
3928 $path = $link_target;
3931 # remove //, /./, and /../
3933 foreach my $part (split('/', $path)) {
3934 # discard '.' and ''
3935 next if (!$part || $part eq '.');
3937 if ($part eq '..') {
3941 # link leads outside repository (outside top dir)
3945 push @path_parts, $part;
3948 $path = join('/', @path_parts);
3953 # print tree entry (row of git_tree), but without encompassing <tr> element
3954 sub git_print_tree_entry
{
3955 my ($t, $basedir, $hash_base, $have_blame) = @_;
3958 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3960 # The format of a table row is: mode list link. Where mode is
3961 # the mode of the entry, list is the name of the entry, an href,
3962 # and link is the action links of the entry.
3964 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3965 if (exists $t->{'size'}) {
3966 print "<td class=\"size\">$t->{'size'}</td>\n";
3968 if ($t->{'type'} eq "blob") {
3969 print "<td class=\"list\">" .
3970 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3971 file_name
=>"$basedir$t->{'name'}", %base_key),
3972 -class => "list"}, esc_path
($t->{'name'}));
3973 if (S_ISLNK
(oct $t->{'mode'})) {
3974 my $link_target = git_get_link_target
($t->{'hash'});
3976 my $norm_target = normalize_link_target
($link_target, $basedir);
3977 if (defined $norm_target) {
3979 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3980 file_name
=>$norm_target),
3981 -title
=> $norm_target}, esc_path
($link_target));
3983 print " -> " . esc_path
($link_target);
3988 print "<td class=\"link\">";
3989 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3990 file_name
=>"$basedir$t->{'name'}", %base_key)},
3994 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3995 file_name
=>"$basedir$t->{'name'}", %base_key)},
3998 if (defined $hash_base) {
4000 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4001 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
4005 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
4006 file_name
=>"$basedir$t->{'name'}")},
4010 } elsif ($t->{'type'} eq "tree") {
4011 print "<td class=\"list\">";
4012 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4013 file_name
=>"$basedir$t->{'name'}",
4015 esc_path
($t->{'name'}));
4017 print "<td class=\"link\">";
4018 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
4019 file_name
=>"$basedir$t->{'name'}",
4022 if (defined $hash_base) {
4024 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4025 file_name
=>"$basedir$t->{'name'}")},
4030 # unknown object: we can only present history for it
4031 # (this includes 'commit' object, i.e. submodule support)
4032 print "<td class=\"list\">" .
4033 esc_path
($t->{'name'}) .
4035 print "<td class=\"link\">";
4036 if (defined $hash_base) {
4037 print $cgi->a({-href
=> href
(action
=>"history",
4038 hash_base
=>$hash_base,
4039 file_name
=>"$basedir$t->{'name'}")},
4046 ## ......................................................................
4047 ## functions printing large fragments of HTML
4049 # get pre-image filenames for merge (combined) diff
4050 sub fill_from_file_info
{
4051 my ($diff, @parents) = @_;
4053 $diff->{'from_file'} = [ ];
4054 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
4055 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4056 if ($diff->{'status'}[$i] eq 'R' ||
4057 $diff->{'status'}[$i] eq 'C') {
4058 $diff->{'from_file'}[$i] =
4059 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
4066 # is current raw difftree line of file deletion
4068 my $diffinfo = shift;
4070 return $diffinfo->{'to_id'} eq ('0' x
40);
4073 # does patch correspond to [previous] difftree raw line
4074 # $diffinfo - hashref of parsed raw diff format
4075 # $patchinfo - hashref of parsed patch diff format
4076 # (the same keys as in $diffinfo)
4077 sub is_patch_split
{
4078 my ($diffinfo, $patchinfo) = @_;
4080 return defined $diffinfo && defined $patchinfo
4081 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
4085 sub git_difftree_body
{
4086 my ($difftree, $hash, @parents) = @_;
4087 my ($parent) = $parents[0];
4088 my $have_blame = gitweb_check_feature
('blame');
4089 print "<div class=\"list_head\">\n";
4090 if ($#{$difftree} > 10) {
4091 print(($#{$difftree} + 1) . " files changed:\n");
4095 print "<table class=\"" .
4096 (@parents > 1 ?
"combined " : "") .
4099 # header only for combined diff in 'commitdiff' view
4100 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
4103 print "<thead><tr>\n" .
4104 "<th></th><th></th>\n"; # filename, patchN link
4105 for (my $i = 0; $i < @parents; $i++) {
4106 my $par = $parents[$i];
4108 $cgi->a({-href
=> href
(action
=>"commitdiff",
4109 hash
=>$hash, hash_parent
=>$par),
4110 -title
=> 'commitdiff to parent number ' .
4111 ($i+1) . ': ' . substr($par,0,7)},
4115 print "</tr></thead>\n<tbody>\n";
4120 foreach my $line (@
{$difftree}) {
4121 my $diff = parsed_difftree_line
($line);
4124 print "<tr class=\"dark\">\n";
4126 print "<tr class=\"light\">\n";
4130 if (exists $diff->{'nparents'}) { # combined diff
4132 fill_from_file_info
($diff, @parents)
4133 unless exists $diff->{'from_file'};
4135 if (!is_deleted
($diff)) {
4136 # file exists in the result (child) commit
4138 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4139 file_name
=>$diff->{'to_file'},
4141 -class => "list"}, esc_path
($diff->{'to_file'})) .
4145 esc_path
($diff->{'to_file'}) .
4149 if ($action eq 'commitdiff') {
4152 print "<td class=\"link\">" .
4153 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4158 my $has_history = 0;
4159 my $not_deleted = 0;
4160 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
4161 my $hash_parent = $parents[$i];
4162 my $from_hash = $diff->{'from_id'}[$i];
4163 my $from_path = $diff->{'from_file'}[$i];
4164 my $status = $diff->{'status'}[$i];
4166 $has_history ||= ($status ne 'A');
4167 $not_deleted ||= ($status ne 'D');
4169 if ($status eq 'A') {
4170 print "<td class=\"link\" align=\"right\"> | </td>\n";
4171 } elsif ($status eq 'D') {
4172 print "<td class=\"link\">" .
4173 $cgi->a({-href
=> href
(action
=>"blob",
4176 file_name
=>$from_path)},
4180 if ($diff->{'to_id'} eq $from_hash) {
4181 print "<td class=\"link nochange\">";
4183 print "<td class=\"link\">";
4185 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4186 hash
=>$diff->{'to_id'},
4187 hash_parent
=>$from_hash,
4189 hash_parent_base
=>$hash_parent,
4190 file_name
=>$diff->{'to_file'},
4191 file_parent
=>$from_path)},
4197 print "<td class=\"link\">";
4199 print $cgi->a({-href
=> href
(action
=>"blob",
4200 hash
=>$diff->{'to_id'},
4201 file_name
=>$diff->{'to_file'},
4204 print " | " if ($has_history);
4207 print $cgi->a({-href
=> href
(action
=>"history",
4208 file_name
=>$diff->{'to_file'},
4215 next; # instead of 'else' clause, to avoid extra indent
4217 # else ordinary diff
4219 my ($to_mode_oct, $to_mode_str, $to_file_type);
4220 my ($from_mode_oct, $from_mode_str, $from_file_type);
4221 if ($diff->{'to_mode'} ne ('0' x
6)) {
4222 $to_mode_oct = oct $diff->{'to_mode'};
4223 if (S_ISREG
($to_mode_oct)) { # only for regular file
4224 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4226 $to_file_type = file_type
($diff->{'to_mode'});
4228 if ($diff->{'from_mode'} ne ('0' x
6)) {
4229 $from_mode_oct = oct $diff->{'from_mode'};
4230 if (S_ISREG
($to_mode_oct)) { # only for regular file
4231 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4233 $from_file_type = file_type
($diff->{'from_mode'});
4236 if ($diff->{'status'} eq "A") { # created
4237 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4238 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4239 $mode_chng .= "]</span>";
4241 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4242 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4243 -class => "list"}, esc_path
($diff->{'file'}));
4245 print "<td>$mode_chng</td>\n";
4246 print "<td class=\"link\">";
4247 if ($action eq 'commitdiff') {
4250 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4253 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4254 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4258 } elsif ($diff->{'status'} eq "D") { # deleted
4259 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4261 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4262 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4263 -class => "list"}, esc_path
($diff->{'file'}));
4265 print "<td>$mode_chng</td>\n";
4266 print "<td class=\"link\">";
4267 if ($action eq 'commitdiff') {
4270 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4273 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4274 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4277 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4278 file_name
=>$diff->{'file'})},
4281 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4282 file_name
=>$diff->{'file'})},
4286 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4287 my $mode_chnge = "";
4288 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4289 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4290 if ($from_file_type ne $to_file_type) {
4291 $mode_chnge .= " from $from_file_type to $to_file_type";
4293 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4294 if ($from_mode_str && $to_mode_str) {
4295 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4296 } elsif ($to_mode_str) {
4297 $mode_chnge .= " mode: $to_mode_str";
4300 $mode_chnge .= "]</span>\n";
4303 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4304 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4305 -class => "list"}, esc_path
($diff->{'file'}));
4307 print "<td>$mode_chnge</td>\n";
4308 print "<td class=\"link\">";
4309 if ($action eq 'commitdiff') {
4312 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4314 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4315 # "commit" view and modified file (not onlu mode changed)
4316 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4317 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4318 hash_base
=>$hash, hash_parent_base
=>$parent,
4319 file_name
=>$diff->{'file'})},
4323 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4324 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4327 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4328 file_name
=>$diff->{'file'})},
4331 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4332 file_name
=>$diff->{'file'})},
4336 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4337 my %status_name = ('R' => 'moved', 'C' => 'copied');
4338 my $nstatus = $status_name{$diff->{'status'}};
4340 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4341 # mode also for directories, so we cannot use $to_mode_str
4342 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4345 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4346 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4347 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4348 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4349 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4350 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4351 -class => "list"}, esc_path
($diff->{'from_file'})) .
4352 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4353 "<td class=\"link\">";
4354 if ($action eq 'commitdiff') {
4357 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4359 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4360 # "commit" view and modified file (not only pure rename or copy)
4361 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4362 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4363 hash_base
=>$hash, hash_parent_base
=>$parent,
4364 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4368 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4369 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4372 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4373 file_name
=>$diff->{'to_file'})},
4376 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4377 file_name
=>$diff->{'to_file'})},
4381 } # we should not encounter Unmerged (U) or Unknown (X) status
4384 print "</tbody>" if $has_header;
4388 sub git_patchset_body
{
4389 my ($fd, $difftree, $hash, @hash_parents) = @_;
4390 my ($hash_parent) = $hash_parents[0];
4392 my $is_combined = (@hash_parents > 1);
4394 my $patch_number = 0;
4400 print "<div class=\"patchset\">\n";
4402 # skip to first patch
4403 while ($patch_line = <$fd>) {
4406 last if ($patch_line =~ m/^diff /);
4410 while ($patch_line) {
4412 # parse "git diff" header line
4413 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4414 # $1 is from_name, which we do not use
4415 $to_name = unquote
($2);
4416 $to_name =~ s!^b/!!;
4417 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4418 # $1 is 'cc' or 'combined', which we do not use
4419 $to_name = unquote
($2);
4424 # check if current patch belong to current raw line
4425 # and parse raw git-diff line if needed
4426 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4427 # this is continuation of a split patch
4428 print "<div class=\"patch cont\">\n";
4430 # advance raw git-diff output if needed
4431 $patch_idx++ if defined $diffinfo;
4433 # read and prepare patch information
4434 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4436 # compact combined diff output can have some patches skipped
4437 # find which patch (using pathname of result) we are at now;
4439 while ($to_name ne $diffinfo->{'to_file'}) {
4440 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4441 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4442 "</div>\n"; # class="patch"
4447 last if $patch_idx > $#$difftree;
4448 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4452 # modifies %from, %to hashes
4453 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4455 # this is first patch for raw difftree line with $patch_idx index
4456 # we index @$difftree array from 0, but number patches from 1
4457 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4461 #assert($patch_line =~ m/^diff /) if DEBUG;
4462 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4464 # print "git diff" header
4465 print format_git_diff_header_line
($patch_line, $diffinfo,
4468 # print extended diff header
4469 print "<div class=\"diff extended_header\">\n";
4471 while ($patch_line = <$fd>) {
4474 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4476 print format_extended_diff_header_line
($patch_line, $diffinfo,
4479 print "</div>\n"; # class="diff extended_header"
4481 # from-file/to-file diff header
4482 if (! $patch_line) {
4483 print "</div>\n"; # class="patch"
4486 next PATCH
if ($patch_line =~ m/^diff /);
4487 #assert($patch_line =~ m/^---/) if DEBUG;
4489 my $last_patch_line = $patch_line;
4490 $patch_line = <$fd>;
4492 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4494 print format_diff_from_to_header
($last_patch_line, $patch_line,
4495 $diffinfo, \
%from, \
%to,
4500 while ($patch_line = <$fd>) {
4503 next PATCH
if ($patch_line =~ m/^diff /);
4505 print format_diff_line
($patch_line, \
%from, \
%to);
4509 print "</div>\n"; # class="patch"
4512 # for compact combined (--cc) format, with chunk and patch simpliciaction
4513 # patchset might be empty, but there might be unprocessed raw lines
4514 for (++$patch_idx if $patch_number > 0;
4515 $patch_idx < @
$difftree;
4517 # read and prepare patch information
4518 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4520 # generate anchor for "patch" links in difftree / whatchanged part
4521 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4522 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4523 "</div>\n"; # class="patch"
4528 if ($patch_number == 0) {
4529 if (@hash_parents > 1) {
4530 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4532 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4536 print "</div>\n"; # class="patchset"
4539 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4541 # fills project list info (age, description, owner, forks) for each
4542 # project in the list, removing invalid projects from returned list
4543 # NOTE: modifies $projlist, but does not remove entries from it
4544 sub fill_project_list_info
{
4545 my ($projlist, $check_forks) = @_;
4548 my $show_ctags = gitweb_check_feature
('ctags');
4550 foreach my $pr (@
$projlist) {
4551 my (@activity) = git_get_last_activity
($pr->{'path'});
4552 unless (@activity) {
4555 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4556 if (!defined $pr->{'descr'}) {
4557 my $descr = git_get_project_description
($pr->{'path'}) || "";
4558 $descr = to_utf8
($descr);
4559 $pr->{'descr_long'} = $descr;
4560 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4562 if (!defined $pr->{'owner'}) {
4563 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4566 my $pname = $pr->{'path'};
4567 if (($pname =~ s/\.git$//) &&
4568 ($pname !~ /\/$/) &&
4569 (-d
"$projectroot/$pname")) {
4570 $pr->{'forks'} = "-d $projectroot/$pname";
4575 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4576 push @projects, $pr;
4582 # print 'sort by' <th> element, generating 'sort by $name' replay link
4583 # if that order is not selected
4585 print format_sort_th
(@_);
4588 sub format_sort_th
{
4589 my ($name, $order, $header) = @_;
4591 $header ||= ucfirst($name);
4593 if ($order eq $name) {
4594 $sort_th .= "<th>$header</th>\n";
4596 $sort_th .= "<th>" .
4597 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4598 -class => "header"}, $header) .
4605 sub git_project_list_body
{
4606 # actually uses global variable $project
4607 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4609 my $check_forks = gitweb_check_feature
('forks');
4610 my @projects = fill_project_list_info
($projlist, $check_forks);
4612 $order ||= $default_projects_order;
4613 $from = 0 unless defined $from;
4614 $to = $#projects if (!defined $to || $#projects < $to);
4617 project
=> { key
=> 'path', type
=> 'str' },
4618 descr
=> { key
=> 'descr_long', type
=> 'str' },
4619 owner
=> { key
=> 'owner', type
=> 'str' },
4620 age
=> { key
=> 'age', type
=> 'num' }
4622 my $oi = $order_info{$order};
4623 if ($oi->{'type'} eq 'str') {
4624 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4626 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4629 my $show_ctags = gitweb_check_feature
('ctags');
4632 foreach my $p (@projects) {
4633 foreach my $ct (keys %{$p->{'ctags'}}) {
4634 $ctags{$ct} += $p->{'ctags'}->{$ct};
4637 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4638 print git_show_project_tagcloud
($cloud, 64);
4641 print "<table class=\"project_list\">\n";
4642 unless ($no_header) {
4645 print "<th></th>\n";
4647 print_sort_th
('project', $order, 'Project');
4648 print_sort_th
('descr', $order, 'Description');
4649 print_sort_th
('owner', $order, 'Owner');
4650 print_sort_th
('age', $order, 'Last Change');
4651 print "<th></th>\n" . # for links
4655 my $tagfilter = $cgi->param('by_tag');
4656 for (my $i = $from; $i <= $to; $i++) {
4657 my $pr = $projects[$i];
4659 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4660 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4661 and not $pr->{'descr_long'} =~ /$searchtext/;
4662 # Weed out forks or non-matching entries of search
4664 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4665 $forkbase="^$forkbase" if $forkbase;
4666 next if not $searchtext and not $tagfilter and $show_ctags
4667 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4671 print "<tr class=\"dark\">\n";
4673 print "<tr class=\"light\">\n";
4678 if ($pr->{'forks'}) {
4679 print "<!-- $pr->{'forks'} -->\n";
4680 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4684 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4685 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4686 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4687 -class => "list", -title
=> $pr->{'descr_long'}},
4688 esc_html
($pr->{'descr'})) . "</td>\n" .
4689 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4690 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4691 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4692 "<td class=\"link\">" .
4693 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4694 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4695 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4696 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4697 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4701 if (defined $extra) {
4704 print "<td></td>\n";
4706 print "<td colspan=\"5\">$extra</td>\n" .
4713 # uses global variable $project
4714 my ($commitlist, $from, $to, $refs, $extra) = @_;
4716 $from = 0 unless defined $from;
4717 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4719 for (my $i = 0; $i <= $to; $i++) {
4720 my %co = %{$commitlist->[$i]};
4722 my $commit = $co{'id'};
4723 my $ref = format_ref_marker
($refs, $commit);
4724 my %ad = parse_date
($co{'author_epoch'});
4725 git_print_header_div
('commit',
4726 "<span class=\"age\">$co{'age_string'}</span>" .
4727 esc_html
($co{'title'}) . $ref,
4729 print "<div class=\"title_text\">\n" .
4730 "<div class=\"log_link\">\n" .
4731 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4733 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4735 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4738 git_print_authorship
(\
%co, -tag
=> 'span');
4739 print "<br/>\n</div>\n";
4741 print "<div class=\"log_body\">\n";
4742 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4746 print "<div class=\"page_nav\">\n";
4752 sub git_shortlog_body
{
4753 # uses global variable $project
4754 my ($commitlist, $from, $to, $refs, $extra) = @_;
4756 $from = 0 unless defined $from;
4757 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4759 print "<table class=\"shortlog\">\n";
4761 for (my $i = $from; $i <= $to; $i++) {
4762 my %co = %{$commitlist->[$i]};
4763 my $commit = $co{'id'};
4764 my $ref = format_ref_marker
($refs, $commit);
4766 print "<tr class=\"dark\">\n";
4768 print "<tr class=\"light\">\n";
4771 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4772 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4773 format_author_html
('td', \
%co, 10) . "<td>";
4774 print format_subject_html
($co{'title'}, $co{'title_short'},
4775 href
(action
=>"commit", hash
=>$commit), $ref);
4777 "<td class=\"link\">" .
4778 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4779 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4780 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4781 my $snapshot_links = format_snapshot_links
($commit);
4782 if (defined $snapshot_links) {
4783 print " | " . $snapshot_links;
4788 if (defined $extra) {
4790 "<td colspan=\"4\">$extra</td>\n" .
4796 sub git_history_body
{
4797 # Warning: assumes constant type (blob or tree) during history
4798 my ($commitlist, $from, $to, $refs, $extra,
4799 $file_name, $file_hash, $ftype) = @_;
4801 $from = 0 unless defined $from;
4802 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4804 print "<table class=\"history\">\n";
4806 for (my $i = $from; $i <= $to; $i++) {
4807 my %co = %{$commitlist->[$i]};
4811 my $commit = $co{'id'};
4813 my $ref = format_ref_marker
($refs, $commit);
4816 print "<tr class=\"dark\">\n";
4818 print "<tr class=\"light\">\n";
4821 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4822 # shortlog: format_author_html('td', \%co, 10)
4823 format_author_html
('td', \
%co, 15, 3) . "<td>";
4824 # originally git_history used chop_str($co{'title'}, 50)
4825 print format_subject_html
($co{'title'}, $co{'title_short'},
4826 href
(action
=>"commit", hash
=>$commit), $ref);
4828 "<td class=\"link\">" .
4829 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4830 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4832 if ($ftype eq 'blob') {
4833 my $blob_current = $file_hash;
4834 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4835 if (defined $blob_current && defined $blob_parent &&
4836 $blob_current ne $blob_parent) {
4838 $cgi->a({-href
=> href
(action
=>"blobdiff",
4839 hash
=>$blob_current, hash_parent
=>$blob_parent,
4840 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4841 file_name
=>$file_name)},
4848 if (defined $extra) {
4850 "<td colspan=\"4\">$extra</td>\n" .
4857 # uses global variable $project
4858 my ($taglist, $from, $to, $extra) = @_;
4859 $from = 0 unless defined $from;
4860 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4862 print "<table class=\"tags\">\n";
4864 for (my $i = $from; $i <= $to; $i++) {
4865 my $entry = $taglist->[$i];
4867 my $comment = $tag{'subject'};
4869 if (defined $comment) {
4870 $comment_short = chop_str
($comment, 30, 5);
4873 print "<tr class=\"dark\">\n";
4875 print "<tr class=\"light\">\n";
4878 if (defined $tag{'age'}) {
4879 print "<td><i>$tag{'age'}</i></td>\n";
4881 print "<td></td>\n";
4884 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4885 -class => "list name"}, esc_html
($tag{'name'})) .
4888 if (defined $comment) {
4889 print format_subject_html
($comment, $comment_short,
4890 href
(action
=>"tag", hash
=>$tag{'id'}));
4893 "<td class=\"selflink\">";
4894 if ($tag{'type'} eq "tag") {
4895 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4900 "<td class=\"link\">" . " | " .
4901 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4902 if ($tag{'reftype'} eq "commit") {
4903 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4904 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4905 } elsif ($tag{'reftype'} eq "blob") {
4906 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4911 if (defined $extra) {
4913 "<td colspan=\"5\">$extra</td>\n" .
4919 sub git_heads_body
{
4920 # uses global variable $project
4921 my ($headlist, $head, $from, $to, $extra) = @_;
4922 $from = 0 unless defined $from;
4923 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4925 print "<table class=\"heads\">\n";
4927 for (my $i = $from; $i <= $to; $i++) {
4928 my $entry = $headlist->[$i];
4930 my $curr = $ref{'id'} eq $head;
4932 print "<tr class=\"dark\">\n";
4934 print "<tr class=\"light\">\n";
4937 print "<td><i>$ref{'age'}</i></td>\n" .
4938 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4939 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4940 -class => "list name"},esc_html
($ref{'name'})) .
4942 "<td class=\"link\">" .
4943 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4944 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4945 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4949 if (defined $extra) {
4951 "<td colspan=\"3\">$extra</td>\n" .
4957 sub git_search_grep_body
{
4958 my ($commitlist, $from, $to, $extra) = @_;
4959 $from = 0 unless defined $from;
4960 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4962 print "<table class=\"commit_search\">\n";
4964 for (my $i = $from; $i <= $to; $i++) {
4965 my %co = %{$commitlist->[$i]};
4969 my $commit = $co{'id'};
4971 print "<tr class=\"dark\">\n";
4973 print "<tr class=\"light\">\n";
4976 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4977 format_author_html
('td', \
%co, 15, 5) .
4979 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4980 -class => "list subject"},
4981 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4982 my $comment = $co{'comment'};
4983 foreach my $line (@
$comment) {
4984 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4985 my ($lead, $match, $trail) = ($1, $2, $3);
4986 $match = chop_str
($match, 70, 5, 'center');
4987 my $contextlen = int((80 - length($match))/2);
4988 $contextlen = 30 if ($contextlen > 30);
4989 $lead = chop_str
($lead, $contextlen, 10, 'left');
4990 $trail = chop_str
($trail, $contextlen, 10, 'right');
4992 $lead = esc_html
($lead);
4993 $match = esc_html
($match);
4994 $trail = esc_html
($trail);
4996 print "$lead<span class=\"match\">$match</span>$trail<br />";
5000 "<td class=\"link\">" .
5001 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5003 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
5005 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5009 if (defined $extra) {
5011 "<td colspan=\"3\">$extra</td>\n" .
5017 ## ======================================================================
5018 ## ======================================================================
5021 sub git_project_list
{
5022 my $order = $input_params{'order'};
5023 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5024 die_error
(400, "Unknown order parameter");
5027 my @list = git_get_projects_list
();
5029 die_error
(404, "No projects found");
5033 if (defined $home_text && -f
$home_text) {
5034 print "<div class=\"index_include\">\n";
5035 insert_file
($home_text);
5038 print $cgi->startform(-method
=> "get") .
5039 "<p class=\"projsearch\">Search:\n" .
5040 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
5042 $cgi->end_form() . "\n";
5043 git_project_list_body
(\
@list, $order);
5048 my $order = $input_params{'order'};
5049 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
5050 die_error
(400, "Unknown order parameter");
5053 my @list = git_get_projects_list
($project);
5055 die_error
(404, "No forks found");
5059 git_print_page_nav
('','');
5060 git_print_header_div
('summary', "$project forks");
5061 git_project_list_body
(\
@list, $order);
5065 sub git_project_index
{
5066 my @projects = git_get_projects_list
($project);
5069 -type
=> 'text/plain',
5070 -charset
=> 'utf-8',
5071 -content_disposition
=> 'inline; filename="index.aux"');
5073 foreach my $pr (@projects) {
5074 if (!exists $pr->{'owner'}) {
5075 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
5078 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
5079 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
5080 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5081 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
5085 print "$path $owner\n";
5090 my $descr = git_get_project_description
($project) || "none";
5091 my %co = parse_commit
("HEAD");
5092 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
5093 my $head = $co{'id'};
5095 my $owner = git_get_project_owner
($project);
5097 my $refs = git_get_references
();
5098 # These get_*_list functions return one more to allow us to see if
5099 # there are more ...
5100 my @taglist = git_get_tags_list
(16);
5101 my @headlist = git_get_heads_list
(16);
5103 my $check_forks = gitweb_check_feature
('forks');
5106 @forklist = git_get_projects_list
($project);
5110 git_print_page_nav
('summary','', $head);
5112 print "<div class=\"title\"> </div>\n";
5113 print "<table class=\"projects_list\">\n" .
5114 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
5115 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
5116 if (defined $cd{'rfc2822'}) {
5117 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
5120 # use per project git URL list in $projectroot/$project/cloneurl
5121 # or make project git URL from git base URL and project name
5122 my $url_tag = "URL";
5123 my @url_list = git_get_project_url_list
($project);
5124 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
5125 foreach my $git_url (@url_list) {
5126 next unless $git_url;
5127 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
5132 my $show_ctags = gitweb_check_feature
('ctags');
5134 my $ctags = git_get_project_ctags
($project);
5135 my $cloud = git_populate_project_tagcloud
($ctags);
5136 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
5137 print "</td>\n<td>" unless %$ctags;
5138 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
5139 print "</td>\n<td>" if %$ctags;
5140 print git_show_project_tagcloud
($cloud, 48);
5146 # If XSS prevention is on, we don't include README.html.
5147 # TODO: Allow a readme in some safe format.
5148 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
5149 print "<div class=\"title\">readme</div>\n" .
5150 "<div class=\"readme\">\n";
5151 insert_file
("$projectroot/$project/README.html");
5152 print "\n</div>\n"; # class="readme"
5155 # we need to request one more than 16 (0..15) to check if
5157 my @commitlist = $head ? parse_commits
($head, 17) : ();
5159 git_print_header_div
('shortlog');
5160 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
5161 $#commitlist <= 15 ?
undef :
5162 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
5166 git_print_header_div
('tags');
5167 git_tags_body
(\
@taglist, 0, 15,
5168 $#taglist <= 15 ?
undef :
5169 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
5173 git_print_header_div
('heads');
5174 git_heads_body
(\
@headlist, $head, 0, 15,
5175 $#headlist <= 15 ?
undef :
5176 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
5180 git_print_header_div
('forks');
5181 git_project_list_body
(\
@forklist, 'age', 0, 15,
5182 $#forklist <= 15 ?
undef :
5183 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5191 my $head = git_get_head_hash
($project);
5193 git_print_page_nav
('','', $head,undef,$head);
5194 my %tag = parse_tag
($hash);
5197 die_error
(404, "Unknown tag object");
5200 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5201 print "<div class=\"title_text\">\n" .
5202 "<table class=\"object_header\">\n" .
5204 "<td>object</td>\n" .
5205 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5206 $tag{'object'}) . "</td>\n" .
5207 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5208 $tag{'type'}) . "</td>\n" .
5210 if (defined($tag{'author'})) {
5211 git_print_authorship_rows
(\
%tag, 'author');
5213 print "</table>\n\n" .
5215 print "<div class=\"page_body\">";
5216 my $comment = $tag{'comment'};
5217 foreach my $line (@
$comment) {
5219 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5225 sub git_blame_common
{
5226 my $format = shift || 'porcelain';
5227 if ($format eq 'porcelain' && $cgi->param('js')) {
5228 $format = 'incremental';
5229 $action = 'blame_incremental'; # for page title etc
5233 gitweb_check_feature
('blame')
5234 or die_error
(403, "Blame view not allowed");
5237 die_error
(400, "No file name given") unless $file_name;
5238 $hash_base ||= git_get_head_hash
($project);
5239 die_error
(404, "Couldn't find base commit") unless $hash_base;
5240 my %co = parse_commit
($hash_base)
5241 or die_error
(404, "Commit not found");
5243 if (!defined $hash) {
5244 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5245 or die_error
(404, "Error looking up file");
5247 $ftype = git_get_type
($hash);
5248 if ($ftype !~ "blob") {
5249 die_error
(400, "Object is not a blob");
5254 if ($format eq 'incremental') {
5255 # get file contents (as base)
5256 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5257 or die_error
(500, "Open git-cat-file failed");
5258 } elsif ($format eq 'data') {
5259 # run git-blame --incremental
5260 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5261 $hash_base, "--", $file_name
5262 or die_error
(500, "Open git-blame --incremental failed");
5264 # run git-blame --porcelain
5265 open $fd, "-|", git_cmd
(), "blame", '-p',
5266 $hash_base, '--', $file_name
5267 or die_error
(500, "Open git-blame --porcelain failed");
5270 # incremental blame data returns early
5271 if ($format eq 'data') {
5273 -type
=>"text/plain", -charset
=> "utf-8",
5274 -status
=> "200 OK");
5275 local $| = 1; # output autoflush
5278 or print "ERROR $!\n";
5281 if (defined $t0 && gitweb_check_feature
('timed')) {
5283 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5284 ' '.$number_of_git_cmds;
5294 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5297 if ($format eq 'incremental') {
5299 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5300 "blame") . " (non-incremental)";
5303 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5304 "blame") . " (incremental)";
5308 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5311 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5313 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5314 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5315 git_print_page_path
($file_name, $ftype, $hash_base);
5318 if ($format eq 'incremental') {
5319 print "<noscript>\n<div class=\"error\"><center><b>\n".
5320 "This page requires JavaScript to run.\n Use ".
5321 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5324 "</b></center></div>\n</noscript>\n";
5326 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5329 print qq!<div
class="page_body">\n!;
5330 print qq!<div id
="progress_info">... / ...</div
>\n!
5331 if ($format eq 'incremental');
5332 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5333 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5335 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5339 my @rev_color = qw(light dark);
5340 my $num_colors = scalar(@rev_color);
5341 my $current_color = 0;
5343 if ($format eq 'incremental') {
5344 my $color_class = $rev_color[$current_color];
5349 while (my $line = <$fd>) {
5353 print qq!<tr id
="l$linenr" class="$color_class">!.
5354 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5355 qq!<td
class="linenr">!.
5356 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5357 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5361 } else { # porcelain, i.e. ordinary blame
5362 my %metainfo = (); # saves information about commits
5366 while (my $line = <$fd>) {
5368 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5369 # no <lines in group> for subsequent lines in group of lines
5370 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5371 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5372 if (!exists $metainfo{$full_rev}) {
5373 $metainfo{$full_rev} = { 'nprevious' => 0 };
5375 my $meta = $metainfo{$full_rev};
5377 while ($data = <$fd>) {
5379 last if ($data =~ s/^\t//); # contents of line
5380 if ($data =~ /^(\S+)(?: (.*))?$/) {
5381 $meta->{$1} = $2 unless exists $meta->{$1};
5383 if ($data =~ /^previous /) {
5384 $meta->{'nprevious'}++;
5387 my $short_rev = substr($full_rev, 0, 8);
5388 my $author = $meta->{'author'};
5390 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5391 my $date = $date{'iso-tz'};
5393 $current_color = ($current_color + 1) % $num_colors;
5395 my $tr_class = $rev_color[$current_color];
5396 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5397 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5398 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5399 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5401 print "<td class=\"sha1\"";
5402 print " title=\"". esc_html
($author) . ", $date\"";
5403 print " rowspan=\"$group_size\"" if ($group_size > 1);
5405 print $cgi->a({-href
=> href
(action
=>"commit",
5407 file_name
=>$file_name)},
5408 esc_html
($short_rev));
5409 if ($group_size >= 2) {
5410 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5411 if (@author_initials) {
5413 esc_html
(join('', @author_initials));
5419 # 'previous' <sha1 of parent commit> <filename at commit>
5420 if (exists $meta->{'previous'} &&
5421 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5422 $meta->{'parent'} = $1;
5423 $meta->{'file_parent'} = unquote
($2);
5426 exists($meta->{'parent'}) ?
5427 $meta->{'parent'} : $full_rev;
5428 my $linenr_filename =
5429 exists($meta->{'file_parent'}) ?
5430 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5431 my $blamed = href
(action
=> 'blame',
5432 file_name
=> $linenr_filename,
5433 hash_base
=> $linenr_commit);
5434 print "<td class=\"linenr\">";
5435 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5436 -class => "linenr" },
5439 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5447 "</table>\n"; # class="blame"
5448 print "</div>\n"; # class="blame_body"
5450 or print "Reading blob failed\n";
5459 sub git_blame_incremental
{
5460 git_blame_common
('incremental');
5463 sub git_blame_data
{
5464 git_blame_common
('data');
5468 my $head = git_get_head_hash
($project);
5470 git_print_page_nav
('','', $head,undef,$head);
5471 git_print_header_div
('summary', $project);
5473 my @tagslist = git_get_tags_list
();
5475 git_tags_body
(\
@tagslist);
5481 my $head = git_get_head_hash
($project);
5483 git_print_page_nav
('','', $head,undef,$head);
5484 git_print_header_div
('summary', $project);
5486 my @headslist = git_get_heads_list
();
5488 git_heads_body
(\
@headslist, $head);
5493 sub git_blob_plain
{
5497 if (!defined $hash) {
5498 if (defined $file_name) {
5499 my $base = $hash_base || git_get_head_hash
($project);
5500 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5501 or die_error
(404, "Cannot find file");
5503 die_error
(400, "No file name defined");
5505 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5506 # blobs defined by non-textual hash id's can be cached
5510 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5511 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5513 # content-type (can include charset)
5514 $type = blob_contenttype
($fd, $file_name, $type);
5516 # "save as" filename, even when no $file_name is given
5517 my $save_as = "$hash";
5518 if (defined $file_name) {
5519 $save_as = $file_name;
5520 } elsif ($type =~ m/^text\//) {
5524 # With XSS prevention on, blobs of all types except a few known safe
5525 # ones are served with "Content-Disposition: attachment" to make sure
5526 # they don't run in our security domain. For certain image types,
5527 # blob view writes an <img> tag referring to blob_plain view, and we
5528 # want to be sure not to break that by serving the image as an
5529 # attachment (though Firefox 3 doesn't seem to care).
5530 my $sandbox = $prevent_xss &&
5531 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5535 -expires
=> $expires,
5536 -content_disposition
=>
5537 ($sandbox ?
'attachment' : 'inline')
5538 . '; filename="' . $save_as . '"');
5540 binmode STDOUT
, ':raw';
5542 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5549 if (!defined $hash) {
5550 if (defined $file_name) {
5551 my $base = $hash_base || git_get_head_hash
($project);
5552 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5553 or die_error
(404, "Cannot find file");
5555 die_error
(400, "No file name defined");
5557 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5558 # blobs defined by non-textual hash id's can be cached
5562 my $have_blame = gitweb_check_feature
('blame');
5563 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5564 or die_error
(500, "Couldn't cat $file_name, $hash");
5565 my $mimetype = blob_mimetype
($fd, $file_name);
5566 # use 'blob_plain' (aka 'raw') view for files that cannot be displayed
5567 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5569 return git_blob_plain
($mimetype);
5571 # we can have blame only for text/* mimetype
5572 $have_blame &&= ($mimetype =~ m!^text/!);
5574 my $highlight = gitweb_check_feature
('highlight');
5575 my $syntax = guess_file_syntax
($highlight, $mimetype, $file_name);
5576 $fd = run_highlighter
($fd, $highlight, $syntax)
5579 git_header_html
(undef, $expires);
5580 my $formats_nav = '';
5581 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5582 if (defined $file_name) {
5585 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5590 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5593 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5596 $cgi->a({-href
=> href
(action
=>"blob",
5597 hash_base
=>"HEAD", file_name
=>$file_name)},
5601 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5604 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5605 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5607 print "<div class=\"page_nav\">\n" .
5608 "<br/><br/></div>\n" .
5609 "<div class=\"title\">$hash</div>\n";
5611 git_print_page_path
($file_name, "blob", $hash_base);
5612 print "<div class=\"page_body\">\n";
5613 if ($mimetype =~ m!^image/!) {
5614 print qq!<img type
="$mimetype"!;
5616 print qq! alt
="$file_name" title
="$file_name"!;
5619 href(action=>"blob_plain
", hash=>$hash,
5620 hash_base=>$hash_base, file_name=>$file_name) .
5624 while (my $line = <$fd>) {
5627 $line = untabify
($line);
5628 printf qq!<div
class="pre"><a id
="l%i" href
="%s#l%i" class="linenr">%4i</a> %s</div
>\n!,
5629 $nr, href
(-replay
=> 1), $nr, $nr, $syntax ?
$line : esc_html
($line, -nbsp
=>1);
5633 or print "Reading blob failed.\n";
5639 if (!defined $hash_base) {
5640 $hash_base = "HEAD";
5642 if (!defined $hash) {
5643 if (defined $file_name) {
5644 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5649 die_error
(404, "No such tree") unless defined($hash);
5651 my $show_sizes = gitweb_check_feature
('show-sizes');
5652 my $have_blame = gitweb_check_feature
('blame');
5657 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5658 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5659 or die_error
(500, "Open git-ls-tree failed");
5660 @entries = map { chomp; $_ } <$fd>;
5662 or die_error
(404, "Reading tree failed");
5665 my $refs = git_get_references
();
5666 my $ref = format_ref_marker
($refs, $hash_base);
5669 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5671 if (defined $file_name) {
5673 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5675 $cgi->a({-href
=> href
(action
=>"tree",
5676 hash_base
=>"HEAD", file_name
=>$file_name)},
5679 my $snapshot_links = format_snapshot_links
($hash);
5680 if (defined $snapshot_links) {
5681 # FIXME: Should be available when we have no hash base as well.
5682 push @views_nav, $snapshot_links;
5684 git_print_page_nav
('tree','', $hash_base, undef, undef,
5685 join(' | ', @views_nav));
5686 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5689 print "<div class=\"page_nav\">\n";
5690 print "<br/><br/></div>\n";
5691 print "<div class=\"title\">$hash</div>\n";
5693 if (defined $file_name) {
5694 $basedir = $file_name;
5695 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5698 git_print_page_path
($file_name, 'tree', $hash_base);
5700 print "<div class=\"page_body\">\n";
5701 print "<table class=\"tree\">\n";
5703 # '..' (top directory) link if possible
5704 if (defined $hash_base &&
5705 defined $file_name && $file_name =~ m![^/]+$!) {
5707 print "<tr class=\"dark\">\n";
5709 print "<tr class=\"light\">\n";
5713 my $up = $file_name;
5714 $up =~ s!/?[^/]+$!!;
5715 undef $up unless $up;
5716 # based on git_print_tree_entry
5717 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5718 print '<td class="size"> </td>'."\n" if $show_sizes;
5719 print '<td class="list">';
5720 print $cgi->a({-href
=> href
(action
=>"tree",
5721 hash_base
=>$hash_base,
5725 print "<td class=\"link\"></td>\n";
5729 foreach my $line (@entries) {
5730 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5733 print "<tr class=\"dark\">\n";
5735 print "<tr class=\"light\">\n";
5739 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5743 print "</table>\n" .
5749 my ($project, $hash) = @_;
5751 # path/to/project.git -> project
5752 # path/to/project/.git -> project
5753 my $name = to_utf8
($project);
5754 $name =~ s
,([^/])/*\
.git
$,$1,;
5755 $name = basename
($name);
5757 $name =~ s/[[:cntrl:]]/?/g;
5760 if ($hash =~ /^[0-9a-fA-F]+$/) {
5761 # shorten SHA-1 hash
5762 my $full_hash = git_get_full_hash
($project, $hash);
5763 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5764 $ver = git_get_short_hash
($project, $hash);
5766 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5767 # tags don't need shortened SHA-1 hash
5770 # branches and other need shortened SHA-1 hash
5771 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5774 $ver .= '-' . git_get_short_hash
($project, $hash);
5776 # in case of hierarchical branch names
5779 # name = project-version_string
5780 $name = "$name-$ver";
5782 return wantarray ?
($name, $name) : $name;
5786 my $format = $input_params{'snapshot_format'};
5787 if (!@snapshot_fmts) {
5788 die_error
(403, "Snapshots not allowed");
5790 # default to first supported snapshot format
5791 $format ||= $snapshot_fmts[0];
5792 if ($format !~ m/^[a-z0-9]+$/) {
5793 die_error
(400, "Invalid snapshot format parameter");
5794 } elsif (!exists($known_snapshot_formats{$format})) {
5795 die_error
(400, "Unknown snapshot format");
5796 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5797 die_error
(403, "Snapshot format not allowed");
5798 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5799 die_error
(403, "Unsupported snapshot format");
5802 my $type = git_get_type
("$hash^{}");
5804 die_error
(404, 'Object does not exist');
5805 } elsif ($type eq 'blob') {
5806 die_error
(400, 'Object is not a tree-ish');
5809 my ($name, $prefix) = snapshot_name
($project, $hash);
5810 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5811 my $cmd = quote_command
(
5812 git_cmd
(), 'archive',
5813 "--format=$known_snapshot_formats{$format}{'format'}",
5814 "--prefix=$prefix/", $hash);
5815 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5816 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5819 $filename =~ s/(["\\])/\\$1/g;
5821 -type
=> $known_snapshot_formats{$format}{'type'},
5822 -content_disposition
=> 'inline; filename="' . $filename . '"',
5823 -status
=> '200 OK');
5825 open my $fd, "-|", $cmd
5826 or die_error
(500, "Execute git-archive failed");
5827 binmode STDOUT
, ':raw';
5829 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5833 sub git_log_generic
{
5834 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5836 my $head = git_get_head_hash
($project);
5837 if (!defined $base) {
5840 if (!defined $page) {
5843 my $refs = git_get_references
();
5845 my $commit_hash = $base;
5846 if (defined $parent) {
5847 $commit_hash = "$parent..$base";
5850 parse_commits
($commit_hash, 101, (100 * $page),
5851 defined $file_name ?
($file_name, "--full-history") : ());
5854 if (!defined $file_hash && defined $file_name) {
5855 # some commits could have deleted file in question,
5856 # and not have it in tree, but one of them has to have it
5857 for (my $i = 0; $i < @commitlist; $i++) {
5858 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5859 last if defined $file_hash;
5862 if (defined $file_hash) {
5863 $ftype = git_get_type
($file_hash);
5865 if (defined $file_name && !defined $ftype) {
5866 die_error
(500, "Unknown type of object");
5869 if (defined $file_name) {
5870 %co = parse_commit
($base)
5871 or die_error
(404, "Unknown commit object");
5875 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5877 if ($#commitlist >= 100) {
5879 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5880 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5882 my $patch_max = gitweb_get_feature
('patches');
5883 if ($patch_max && !defined $file_name) {
5884 if ($patch_max < 0 || @commitlist <= $patch_max) {
5885 $paging_nav .= " ⋅ " .
5886 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5892 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5893 if (defined $file_name) {
5894 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5896 git_print_header_div
('summary', $project)
5898 git_print_page_path
($file_name, $ftype, $hash_base)
5899 if (defined $file_name);
5901 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5902 $file_name, $file_hash, $ftype);
5908 git_log_generic
('log', \
&git_log_body
,
5909 $hash, $hash_parent);
5913 $hash ||= $hash_base || "HEAD";
5914 my %co = parse_commit
($hash)
5915 or die_error
(404, "Unknown commit object");
5917 my $parent = $co{'parent'};
5918 my $parents = $co{'parents'}; # listref
5920 # we need to prepare $formats_nav before any parameter munging
5922 if (!defined $parent) {
5924 $formats_nav .= '(initial)';
5925 } elsif (@
$parents == 1) {
5926 # single parent commit
5929 $cgi->a({-href
=> href
(action
=>"commit",
5931 esc_html
(substr($parent, 0, 7))) .
5938 $cgi->a({-href
=> href
(action
=>"commit",
5940 esc_html
(substr($_, 0, 7)));
5944 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5945 $formats_nav .= " | " .
5946 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5950 if (!defined $parent) {
5954 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5956 (@
$parents <= 1 ?
$parent : '-c'),
5958 or die_error
(500, "Open git-diff-tree failed");
5959 @difftree = map { chomp; $_ } <$fd>;
5960 close $fd or die_error
(404, "Reading git-diff-tree failed");
5962 # non-textual hash id's can be cached
5964 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5967 my $refs = git_get_references
();
5968 my $ref = format_ref_marker
($refs, $co{'id'});
5970 git_header_html
(undef, $expires);
5971 git_print_page_nav
('commit', '',
5972 $hash, $co{'tree'}, $hash,
5975 if (defined $co{'parent'}) {
5976 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5978 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5980 print "<div class=\"title_text\">\n" .
5981 "<table class=\"object_header\">\n";
5982 git_print_authorship_rows
(\
%co);
5983 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5986 "<td class=\"sha1\">" .
5987 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5988 class => "list"}, $co{'tree'}) .
5990 "<td class=\"link\">" .
5991 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5993 my $snapshot_links = format_snapshot_links
($hash);
5994 if (defined $snapshot_links) {
5995 print " | " . $snapshot_links;
6000 foreach my $par (@
$parents) {
6003 "<td class=\"sha1\">" .
6004 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
6005 class => "list"}, $par) .
6007 "<td class=\"link\">" .
6008 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
6010 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
6017 print "<div class=\"page_body\">\n";
6018 git_print_log
($co{'comment'});
6021 git_difftree_body
(\
@difftree, $hash, @
$parents);
6027 # object is defined by:
6028 # - hash or hash_base alone
6029 # - hash_base and file_name
6032 # - hash or hash_base alone
6033 if ($hash || ($hash_base && !defined $file_name)) {
6034 my $object_id = $hash || $hash_base;
6036 open my $fd, "-|", quote_command
(
6037 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
6038 or die_error
(404, "Object does not exist");
6042 or die_error
(404, "Object does not exist");
6044 # - hash_base and file_name
6045 } elsif ($hash_base && defined $file_name) {
6046 $file_name =~ s
,/+$,,;
6048 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
6049 or die_error
(404, "Base object does not exist");
6051 # here errors should not hapen
6052 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
6053 or die_error
(500, "Open git-ls-tree failed");
6057 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
6058 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
6059 die_error
(404, "File or directory for given base does not exist");
6064 die_error
(400, "Not enough information to find object");
6067 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
6068 hash
=>$hash, hash_base
=>$hash_base,
6069 file_name
=>$file_name),
6070 -status
=> '302 Found');
6074 my $format = shift || 'html';
6081 # preparing $fd and %diffinfo for git_patchset_body
6083 if (defined $hash_base && defined $hash_parent_base) {
6084 if (defined $file_name) {
6086 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6087 $hash_parent_base, $hash_base,
6088 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6089 or die_error
(500, "Open git-diff-tree failed");
6090 @difftree = map { chomp; $_ } <$fd>;
6092 or die_error
(404, "Reading git-diff-tree failed");
6094 or die_error
(404, "Blob diff not found");
6096 } elsif (defined $hash &&
6097 $hash =~ /[0-9a-fA-F]{40}/) {
6098 # try to find filename from $hash
6100 # read filtered raw output
6101 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6102 $hash_parent_base, $hash_base, "--"
6103 or die_error
(500, "Open git-diff-tree failed");
6105 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
6107 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
6108 map { chomp; $_ } <$fd>;
6110 or die_error
(404, "Reading git-diff-tree failed");
6112 or die_error
(404, "Blob diff not found");
6115 die_error
(400, "Missing one of the blob diff parameters");
6118 if (@difftree > 1) {
6119 die_error
(400, "Ambiguous blob diff specification");
6122 %diffinfo = parse_difftree_raw_line
($difftree[0]);
6123 $file_parent ||= $diffinfo{'from_file'} || $file_name;
6124 $file_name ||= $diffinfo{'to_file'};
6126 $hash_parent ||= $diffinfo{'from_id'};
6127 $hash ||= $diffinfo{'to_id'};
6129 # non-textual hash id's can be cached
6130 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
6131 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
6136 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6137 '-p', ($format eq 'html' ?
"--full-index" : ()),
6138 $hash_parent_base, $hash_base,
6139 "--", (defined $file_parent ?
$file_parent : ()), $file_name
6140 or die_error
(500, "Open git-diff-tree failed");
6143 # old/legacy style URI -- not generated anymore since 1.4.3.
6145 die_error
('404 Not Found', "Missing one of the blob diff parameters")
6149 if ($format eq 'html') {
6151 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
6153 git_header_html
(undef, $expires);
6154 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
6155 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
6156 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6158 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
6159 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
6161 if (defined $file_name) {
6162 git_print_page_path
($file_name, "blob", $hash_base);
6164 print "<div class=\"page_path\"></div>\n";
6167 } elsif ($format eq 'plain') {
6169 -type
=> 'text/plain',
6170 -charset
=> 'utf-8',
6171 -expires
=> $expires,
6172 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
6174 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6177 die_error
(400, "Unknown blobdiff format");
6181 if ($format eq 'html') {
6182 print "<div class=\"page_body\">\n";
6184 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
6187 print "</div>\n"; # class="page_body"
6191 while (my $line = <$fd>) {
6192 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6193 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6197 last if $line =~ m!^\+\+\+!;
6205 sub git_blobdiff_plain
{
6206 git_blobdiff
('plain');
6209 sub git_commitdiff
{
6211 my $format = $params{-format
} || 'html';
6213 my ($patch_max) = gitweb_get_feature
('patches');
6214 if ($format eq 'patch') {
6215 die_error
(403, "Patch view not allowed") unless $patch_max;
6218 $hash ||= $hash_base || "HEAD";
6219 my %co = parse_commit
($hash)
6220 or die_error
(404, "Unknown commit object");
6222 # choose format for commitdiff for merge
6223 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
6224 $hash_parent = '--cc';
6226 # we need to prepare $formats_nav before almost any parameter munging
6228 if ($format eq 'html') {
6230 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6232 if ($patch_max && @
{$co{'parents'}} <= 1) {
6233 $formats_nav .= " | " .
6234 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6238 if (defined $hash_parent &&
6239 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6240 # commitdiff with two commits given
6241 my $hash_parent_short = $hash_parent;
6242 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6243 $hash_parent_short = substr($hash_parent, 0, 7);
6247 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6248 if ($co{'parents'}[$i] eq $hash_parent) {
6249 $formats_nav .= ' parent ' . ($i+1);
6253 $formats_nav .= ': ' .
6254 $cgi->a({-href
=> href
(action
=>"commitdiff",
6255 hash
=>$hash_parent)},
6256 esc_html
($hash_parent_short)) .
6258 } elsif (!$co{'parent'}) {
6260 $formats_nav .= ' (initial)';
6261 } elsif (scalar @
{$co{'parents'}} == 1) {
6262 # single parent commit
6265 $cgi->a({-href
=> href
(action
=>"commitdiff",
6266 hash
=>$co{'parent'})},
6267 esc_html
(substr($co{'parent'}, 0, 7))) .
6271 if ($hash_parent eq '--cc') {
6272 $formats_nav .= ' | ' .
6273 $cgi->a({-href
=> href
(action
=>"commitdiff",
6274 hash
=>$hash, hash_parent
=>'-c')},
6276 } else { # $hash_parent eq '-c'
6277 $formats_nav .= ' | ' .
6278 $cgi->a({-href
=> href
(action
=>"commitdiff",
6279 hash
=>$hash, hash_parent
=>'--cc')},
6285 $cgi->a({-href
=> href
(action
=>"commitdiff",
6287 esc_html
(substr($_, 0, 7)));
6288 } @
{$co{'parents'}} ) .
6293 my $hash_parent_param = $hash_parent;
6294 if (!defined $hash_parent_param) {
6295 # --cc for multiple parents, --root for parentless
6296 $hash_parent_param =
6297 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6303 if ($format eq 'html') {
6304 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6305 "--no-commit-id", "--patch-with-raw", "--full-index",
6306 $hash_parent_param, $hash, "--"
6307 or die_error
(500, "Open git-diff-tree failed");
6309 while (my $line = <$fd>) {
6311 # empty line ends raw part of diff-tree output
6313 push @difftree, scalar parse_difftree_raw_line
($line);
6316 } elsif ($format eq 'plain') {
6317 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6318 '-p', $hash_parent_param, $hash, "--"
6319 or die_error
(500, "Open git-diff-tree failed");
6320 } elsif ($format eq 'patch') {
6321 # For commit ranges, we limit the output to the number of
6322 # patches specified in the 'patches' feature.
6323 # For single commits, we limit the output to a single patch,
6324 # diverging from the git-format-patch default.
6325 my @commit_spec = ();
6327 if ($patch_max > 0) {
6328 push @commit_spec, "-$patch_max";
6330 push @commit_spec, '-n', "$hash_parent..$hash";
6332 if ($params{-single
}) {
6333 push @commit_spec, '-1';
6335 if ($patch_max > 0) {
6336 push @commit_spec, "-$patch_max";
6338 push @commit_spec, "-n";
6340 push @commit_spec, '--root', $hash;
6342 open $fd, "-|", git_cmd
(), "format-patch", @diff_opts,
6343 '--encoding=utf8', '--stdout', @commit_spec
6344 or die_error
(500, "Open git-format-patch failed");
6346 die_error
(400, "Unknown commitdiff format");
6349 # non-textual hash id's can be cached
6351 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6355 # write commit message
6356 if ($format eq 'html') {
6357 my $refs = git_get_references
();
6358 my $ref = format_ref_marker
($refs, $co{'id'});
6360 git_header_html
(undef, $expires);
6361 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6362 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6363 print "<div class=\"title_text\">\n" .
6364 "<table class=\"object_header\">\n";
6365 git_print_authorship_rows
(\
%co);
6368 print "<div class=\"page_body\">\n";
6369 if (@
{$co{'comment'}} > 1) {
6370 print "<div class=\"log\">\n";
6371 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6372 print "</div>\n"; # class="log"
6375 } elsif ($format eq 'plain') {
6376 my $refs = git_get_references
("tags");
6377 my $tagname = git_get_rev_name_tags
($hash);
6378 my $filename = basename
($project) . "-$hash.patch";
6381 -type
=> 'text/plain',
6382 -charset
=> 'utf-8',
6383 -expires
=> $expires,
6384 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6385 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6386 print "From: " . to_utf8
($co{'author'}) . "\n";
6387 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6388 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6390 print "X-Git-Tag: $tagname\n" if $tagname;
6391 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6393 foreach my $line (@
{$co{'comment'}}) {
6394 print to_utf8
($line) . "\n";
6397 } elsif ($format eq 'patch') {
6398 my $filename = basename
($project) . "-$hash.patch";
6401 -type
=> 'text/plain',
6402 -charset
=> 'utf-8',
6403 -expires
=> $expires,
6404 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6408 if ($format eq 'html') {
6409 my $use_parents = !defined $hash_parent ||
6410 $hash_parent eq '-c' || $hash_parent eq '--cc';
6411 git_difftree_body
(\
@difftree, $hash,
6412 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6415 git_patchset_body
($fd, \
@difftree, $hash,
6416 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6418 print "</div>\n"; # class="page_body"
6421 } elsif ($format eq 'plain') {
6425 or print "Reading git-diff-tree failed\n";
6426 } elsif ($format eq 'patch') {
6430 or print "Reading git-format-patch failed\n";
6434 sub git_commitdiff_plain
{
6435 git_commitdiff
(-format
=> 'plain');
6438 # format-patch-style patches
6440 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6444 git_commitdiff
(-format
=> 'patch');
6448 git_log_generic
('history', \
&git_history_body
,
6449 $hash_base, $hash_parent_base,
6454 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6455 if (!defined $searchtext) {
6456 die_error
(400, "Text field is empty");
6458 if (!defined $hash) {
6459 $hash = git_get_head_hash
($project);
6461 my %co = parse_commit
($hash);
6463 die_error
(404, "Unknown commit object");
6465 if (!defined $page) {
6469 $searchtype ||= 'commit';
6470 if ($searchtype eq 'pickaxe') {
6471 # pickaxe may take all resources of your box and run for several minutes
6472 # with every query - so decide by yourself how public you make this feature
6473 gitweb_check_feature
('pickaxe')
6474 or die_error
(403, "Pickaxe is disabled");
6476 if ($searchtype eq 'grep') {
6477 gitweb_check_feature
('grep')
6478 or die_error
(403, "Grep is disabled");
6483 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6485 if ($searchtype eq 'commit') {
6486 $greptype = "--grep=";
6487 } elsif ($searchtype eq 'author') {
6488 $greptype = "--author=";
6489 } elsif ($searchtype eq 'committer') {
6490 $greptype = "--committer=";
6492 $greptype .= $searchtext;
6493 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6494 $greptype, '--regexp-ignore-case',
6495 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6497 my $paging_nav = '';
6500 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6501 searchtext
=>$searchtext,
6502 searchtype
=>$searchtype)},
6504 $paging_nav .= " ⋅ " .
6505 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6506 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6508 $paging_nav .= "first";
6509 $paging_nav .= " ⋅ prev";
6512 if ($#commitlist >= 100) {
6514 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6515 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6516 $paging_nav .= " ⋅ $next_link";
6518 $paging_nav .= " ⋅ next";
6521 if ($#commitlist >= 100) {
6524 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6525 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6526 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6529 if ($searchtype eq 'pickaxe') {
6530 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6531 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6533 print "<table class=\"pickaxe search\">\n";
6536 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6537 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6538 ($search_use_regexp ?
'--pickaxe-regex' : ());
6541 while (my $line = <$fd>) {
6545 my %set = parse_difftree_raw_line
($line);
6546 if (defined $set{'commit'}) {
6547 # finish previous commit
6550 "<td class=\"link\">" .
6551 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6553 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6559 print "<tr class=\"dark\">\n";
6561 print "<tr class=\"light\">\n";
6564 %co = parse_commit
($set{'commit'});
6565 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6566 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6567 "<td><i>$author</i></td>\n" .
6569 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6570 -class => "list subject"},
6571 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6572 } elsif (defined $set{'to_id'}) {
6573 next if ($set{'to_id'} =~ m/^0{40}$/);
6575 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6576 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6578 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6584 # finish last commit (warning: repetition!)
6587 "<td class=\"link\">" .
6588 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6590 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6598 if ($searchtype eq 'grep') {
6599 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6600 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6602 print "<table class=\"grep_search\">\n";
6606 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6607 $search_use_regexp ?
('-E', '-i') : '-F',
6608 $searchtext, $co{'tree'};
6610 while (my $line = <$fd>) {
6612 my ($file, $lno, $ltext, $binary);
6613 last if ($matches++ > 1000);
6614 if ($line =~ /^Binary file (.+) matches$/) {
6618 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6620 if ($file ne $lastfile) {
6621 $lastfile and print "</td></tr>\n";
6623 print "<tr class=\"dark\">\n";
6625 print "<tr class=\"light\">\n";
6627 print "<td class=\"list\">".
6628 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6629 file_name
=>"$file"),
6630 -class => "list"}, esc_path
($file));
6631 print "</td><td>\n";
6635 print "<div class=\"binary\">Binary file</div>\n";
6637 $ltext = untabify
($ltext);
6638 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6639 $ltext = esc_html
($1, -nbsp
=>1);
6640 $ltext .= '<span class="match">';
6641 $ltext .= esc_html
($2, -nbsp
=>1);
6642 $ltext .= '</span>';
6643 $ltext .= esc_html
($3, -nbsp
=>1);
6645 $ltext = esc_html
($ltext, -nbsp
=>1);
6647 print "<div class=\"pre\">" .
6648 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6649 file_name
=>"$file").'#l'.$lno,
6650 -class => "linenr"}, sprintf('%4i', $lno))
6651 . ' ' . $ltext . "</div>\n";
6655 print "</td></tr>\n";
6656 if ($matches > 1000) {
6657 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6660 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6669 sub git_search_help
{
6671 git_print_page_nav
('','', $hash,$hash,$hash);
6673 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6674 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6675 the pattern entered is recognized as the POSIX extended
6676 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6679 <dt><b>commit</b></dt>
6680 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6682 my $have_grep = gitweb_check_feature
('grep');
6685 <dt><b>grep</b></dt>
6686 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6687 a different one) are searched for the given pattern. On large trees, this search can take
6688 a while and put some strain on the server, so please use it with some consideration. Note that
6689 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6690 case-sensitive.</dd>
6694 <dt><b>author</b></dt>
6695 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6696 <dt><b>committer</b></dt>
6697 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6699 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6700 if ($have_pickaxe) {
6702 <dt><b>pickaxe</b></dt>
6703 <dd>All commits that caused the string to appear or disappear from any file (changes that
6704 added, removed or "modified" the string) will be listed. This search can take a while and
6705 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6706 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6714 git_log_generic
('shortlog', \
&git_shortlog_body
,
6715 $hash, $hash_parent);
6718 ## ......................................................................
6719 ## feeds (RSS, Atom; OPML)
6722 my $format = shift || 'atom';
6723 my $have_blame = gitweb_check_feature
('blame');
6725 # Atom: http://www.atomenabled.org/developers/syndication/
6726 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6727 if ($format ne 'rss' && $format ne 'atom') {
6728 die_error
(400, "Unknown web feed format");
6731 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6732 my $head = $hash || 'HEAD';
6733 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6737 my $content_type = "application/$format+xml";
6738 if (defined $cgi->http('HTTP_ACCEPT') &&
6739 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6740 # browser (feed reader) prefers text/xml
6741 $content_type = 'text/xml';
6743 if (defined($commitlist[0])) {
6744 %latest_commit = %{$commitlist[0]};
6745 my $latest_epoch = $latest_commit{'committer_epoch'};
6746 %latest_date = parse_date
($latest_epoch);
6747 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6748 if (defined $if_modified) {
6750 if (eval { require HTTP
::Date
; 1; }) {
6751 $since = HTTP
::Date
::str2time
($if_modified);
6752 } elsif (eval { require Time
::ParseDate
; 1; }) {
6753 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6755 if (defined $since && $latest_epoch <= $since) {
6757 -type
=> $content_type,
6758 -charset
=> 'utf-8',
6759 -last_modified
=> $latest_date{'rfc2822'},
6760 -status
=> '304 Not Modified');
6765 -type
=> $content_type,
6766 -charset
=> 'utf-8',
6767 -last_modified
=> $latest_date{'rfc2822'});
6770 -type
=> $content_type,
6771 -charset
=> 'utf-8');
6774 # Optimization: skip generating the body if client asks only
6775 # for Last-Modified date.
6776 return if ($cgi->request_method() eq 'HEAD');
6779 my $title = "$site_name - $project/$action";
6780 my $feed_type = 'log';
6781 if (defined $hash) {
6782 $title .= " - '$hash'";
6783 $feed_type = 'branch log';
6784 if (defined $file_name) {
6785 $title .= " :: $file_name";
6786 $feed_type = 'history';
6788 } elsif (defined $file_name) {
6789 $title .= " - $file_name";
6790 $feed_type = 'history';
6792 $title .= " $feed_type";
6793 my $descr = git_get_project_description
($project);
6794 if (defined $descr) {
6795 $descr = esc_html
($descr);
6797 $descr = "$project " .
6798 ($format eq 'rss' ?
'RSS' : 'Atom') .
6801 my $owner = git_get_project_owner
($project);
6802 $owner = esc_html
($owner);
6806 if (defined $file_name) {
6807 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6808 } elsif (defined $hash) {
6809 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6811 $alt_url = href
(-full
=>1, action
=>"summary");
6813 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6814 if ($format eq 'rss') {
6816 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6819 print "<title>$title</title>\n" .
6820 "<link>$alt_url</link>\n" .
6821 "<description>$descr</description>\n" .
6822 "<language>en</language>\n" .
6823 # project owner is responsible for 'editorial' content
6824 "<managingEditor>$owner</managingEditor>\n";
6825 if (defined $logo || defined $favicon) {
6826 # prefer the logo to the favicon, since RSS
6827 # doesn't allow both
6828 my $img = esc_url
($logo || $favicon);
6830 "<url>$img</url>\n" .
6831 "<title>$title</title>\n" .
6832 "<link>$alt_url</link>\n" .
6836 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6837 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6839 print "<generator>gitweb v.$version/$git_version</generator>\n";
6840 } elsif ($format eq 'atom') {
6842 <feed xmlns="http://www.w3.org/2005/Atom">
6844 print "<title>$title</title>\n" .
6845 "<subtitle>$descr</subtitle>\n" .
6846 '<link rel="alternate" type="text/html" href="' .
6847 $alt_url . '" />' . "\n" .
6848 '<link rel="self" type="' . $content_type . '" href="' .
6849 $cgi->self_url() . '" />' . "\n" .
6850 "<id>" . href
(-full
=>1) . "</id>\n" .
6851 # use project owner for feed author
6852 "<author><name>$owner</name></author>\n";
6853 if (defined $favicon) {
6854 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6856 if (defined $logo_url) {
6857 # not twice as wide as tall: 72 x 27 pixels
6858 print "<logo>" . esc_url
($logo) . "</logo>\n";
6860 if (! %latest_date) {
6861 # dummy date to keep the feed valid until commits trickle in:
6862 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6864 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6866 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6870 for (my $i = 0; $i <= $#commitlist; $i++) {
6871 my %co = %{$commitlist[$i]};
6872 my $commit = $co{'id'};
6873 # we read 150, we always show 30 and the ones more recent than 48 hours
6874 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6877 my %cd = parse_date
($co{'author_epoch'});
6879 # get list of changed files
6880 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6881 $co{'parent'} || "--root",
6882 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6884 my @difftree = map { chomp; $_ } <$fd>;
6888 # print element (entry, item)
6889 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6890 if ($format eq 'rss') {
6892 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6893 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6894 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6895 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6896 "<link>$co_url</link>\n" .
6897 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6898 "<content:encoded>" .
6900 } elsif ($format eq 'atom') {
6902 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6903 "<updated>$cd{'iso-8601'}</updated>\n" .
6905 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6906 if ($co{'author_email'}) {
6907 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6909 print "</author>\n" .
6910 # use committer for contributor
6912 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6913 if ($co{'committer_email'}) {
6914 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6916 print "</contributor>\n" .
6917 "<published>$cd{'iso-8601'}</published>\n" .
6918 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6919 "<id>$co_url</id>\n" .
6920 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6921 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6923 my $comment = $co{'comment'};
6925 foreach my $line (@
$comment) {
6926 $line = esc_html
($line);
6929 print "</pre><ul>\n";
6930 foreach my $difftree_line (@difftree) {
6931 my %difftree = parse_difftree_raw_line
($difftree_line);
6932 next if !$difftree{'from_id'};
6934 my $file = $difftree{'file'} || $difftree{'to_file'};
6938 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6939 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6940 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6941 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6942 -title
=> "diff"}, 'D');
6944 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6945 file_name
=>$file, hash_base
=>$commit),
6946 -title
=> "blame"}, 'B');
6948 # if this is not a feed of a file history
6949 if (!defined $file_name || $file_name ne $file) {
6950 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6951 file_name
=>$file, hash
=>$commit),
6952 -title
=> "history"}, 'H');
6954 $file = esc_path
($file);
6958 if ($format eq 'rss') {
6959 print "</ul>]]>\n" .
6960 "</content:encoded>\n" .
6962 } elsif ($format eq 'atom') {
6963 print "</ul>\n</div>\n" .
6970 if ($format eq 'rss') {
6971 print "</channel>\n</rss>\n";
6972 } elsif ($format eq 'atom') {
6986 my @list = git_get_projects_list
();
6989 -type
=> 'text/xml',
6990 -charset
=> 'utf-8',
6991 -content_disposition
=> 'inline; filename="opml.xml"');
6994 <?xml version="1.0" encoding="utf-8"?>
6995 <opml version="1.0">
6997 <title>$site_name OPML Export</title>
7000 <outline text="git RSS feeds">
7003 foreach my $pr (@list) {
7005 my $head = git_get_head_hash
($proj{'path'});
7006 if (!defined $head) {
7009 $git_dir = "$projectroot/$proj{'path'}";
7010 my %co = parse_commit
($head);
7015 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
7016 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
7017 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
7018 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";