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);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31 # needed and used only for URLs with nonempty PATH_INFO
32 our $base_url = $my_url;
34 # When the script is used as DirectoryIndex, the URL does not contain the name
35 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36 # have to do it ourselves. We make $path_info global because it's also used
39 # Another issue with the script being the DirectoryIndex is that the resulting
40 # $my_url data is not the full script URL: this is good, because we want
41 # generated links to keep implying the script name if it wasn't explicitly
42 # indicated in the URL we're handling, but it means that $my_url cannot be used
44 # Therefore, if we needed to strip PATH_INFO, then we know that we have
45 # to build the base URL ourselves:
46 our $path_info = $ENV{"PATH_INFO"};
48 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
49 $my_uri =~ s
,\Q
$path_info\E
$,, &&
50 defined $ENV{'SCRIPT_NAME'}) {
51 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
55 # core git executable to use
56 # this can just be "git" if your webserver has a sensible PATH
57 our $GIT = "++GIT_BINDIR++/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "++GITWEB_PROJECTROOT++";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
67 # target of the home link on top of all pages
68 our $home_link = $my_uri || "/";
70 # string of the home link on top of all pages
71 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
73 # name of your site or organization to appear in page titles
74 # replace this with something more descriptive for clearer bookmarks
75 our $site_name = "++GITWEB_SITENAME++"
76 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 # filename of html text to include at top of each page
79 our $site_header = "++GITWEB_SITE_HEADER++";
80 # html text to include at home page
81 our $home_text = "++GITWEB_HOMETEXT++";
82 # filename of html text to include at bottom of each page
83 our $site_footer = "++GITWEB_SITE_FOOTER++";
86 our @stylesheets = ("++GITWEB_CSS++");
87 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
88 our $stylesheet = undef;
89 # URI of GIT logo (72x27 size)
90 our $logo = "++GITWEB_LOGO++";
91 # URI of GIT favicon, assumed to be image/png type
92 our $favicon = "++GITWEB_FAVICON++";
94 # URI and label (title) of GIT logo link
95 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
96 #our $logo_label = "git documentation";
97 our $logo_url = "http://git-scm.com/";
98 our $logo_label = "git homepage";
100 # source of projects list
101 our $projects_list = "++GITWEB_LIST++";
103 # the width (in characters) of the projects list "Description" column
104 our $projects_list_description_width = 25;
106 # default order of projects list
107 # valid values are none, project, descr, owner, and age
108 our $default_projects_order = "project";
110 # show repository only if this file exists
111 # (only effective if this variable evaluates to true)
112 our $export_ok = "++GITWEB_EXPORT_OK++";
114 # show repository only if this subroutine returns true
115 # when given the path to the project, for example:
116 # sub { return -e "$_[0]/git-daemon-export-ok"; }
117 our $export_auth_hook = undef;
119 # only allow viewing of repositories also shown on the overview page
120 our $strict_export = "++GITWEB_STRICT_EXPORT++";
122 # list of git base URLs used for URL to where fetch project from,
123 # i.e. full URL is "$git_base_url/$project"
124 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
126 # default blob_plain mimetype and default charset for text/plain blob
127 our $default_blob_plain_mimetype = 'text/plain';
128 our $default_text_plain_charset = undef;
130 # file to use for guessing MIME types before trying /etc/mime.types
131 # (relative to the current git repository)
132 our $mimetypes_file = undef;
134 # assume this charset if line contains non-UTF-8 characters;
135 # it should be valid encoding (see Encoding::Supported(3pm) for list),
136 # for which encoding all byte sequences are valid, for example
137 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
138 # could be even 'utf-8' for the old behavior)
139 our $fallback_encoding = 'latin1';
141 # rename detection options for git-diff and git-diff-tree
142 # - default is '-M', with the cost proportional to
143 # (number of removed files) * (number of new files).
144 # - more costly is '-C' (which implies '-M'), with the cost proportional to
145 # (number of changed files + number of removed files) * (number of new files)
146 # - even more costly is '-C', '--find-copies-harder' with cost
147 # (number of files in the original tree) * (number of new files)
148 # - one might want to include '-B' option, e.g. '-B', '-M'
149 our @diff_opts = ('-M'); # taken from git_commit
151 # Disables features that would allow repository owners to inject script into
153 our $prevent_xss = 0;
155 # Whether to include project list on the gitweb front page; 0 means yes,
156 # 1 means no list but show tag cloud if enabled (all projects still need
157 # to be scanned, unless the info is cached), 2 means no list and no tag cloud
159 our $frontpage_no_project_list = 0;
161 # projects list cache for busy sites with many projects;
162 # if you set this to non-zero, it will be used as the cached
163 # index lifetime in minutes
165 # the cached list version is stored in $cache_dir/$cache_name and can
166 # be tweaked by other scripts running with the same uid as gitweb -
167 # use this ONLY at secure installations; only single gitweb project
168 # root per system is supported, unless you tweak configuration!
169 our $projlist_cache_lifetime = 0; # in minutes
170 # FHS compliant $cache_dir would be "/var/cache/gitweb"
172 (defined $ENV{'TMPDIR'} ?
$ENV{'TMPDIR'} : '/tmp').'/gitweb';
173 our $projlist_cache_name = 'gitweb.index.cache';
175 # information about snapshot formats that gitweb is capable of serving
176 our %known_snapshot_formats = (
178 # 'display' => display name,
179 # 'type' => mime type,
180 # 'suffix' => filename suffix,
181 # 'format' => --format for git-archive,
182 # 'compressor' => [compressor command and arguments]
183 # (array reference, optional)
184 # 'disabled' => boolean (optional)}
187 'display' => 'tar.gz',
188 'type' => 'application/x-gzip',
189 'suffix' => '.tar.gz',
191 'compressor' => ['gzip']},
194 'display' => 'tar.bz2',
195 'type' => 'application/x-bzip2',
196 'suffix' => '.tar.bz2',
198 'compressor' => ['bzip2']},
201 'display' => 'tar.xz',
202 'type' => 'application/x-xz',
203 'suffix' => '.tar.xz',
205 'compressor' => ['xz'],
210 'type' => 'application/x-zip',
215 # Aliases so we understand old gitweb.snapshot values in repository
217 our %known_snapshot_format_aliases = (
222 # backward compatibility: legacy gitweb config support
223 'x-gzip' => undef, 'gz' => undef,
224 'x-bzip2' => undef, 'bz2' => undef,
225 'x-zip' => undef, '' => undef,
228 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
229 # are changed, it may be appropriate to change these values too via
236 # You define site-wide feature defaults here; override them with
237 # $GITWEB_CONFIG as necessary.
240 # 'sub' => feature-sub (subroutine),
241 # 'override' => allow-override (boolean),
242 # 'default' => [ default options...] (array reference)}
244 # if feature is overridable (it means that allow-override has true value),
245 # then feature-sub will be called with default options as parameters;
246 # return value of feature-sub indicates if to enable specified feature
248 # if there is no 'sub' key (no feature-sub), then feature cannot be
251 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
252 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
255 # Enable the 'blame' blob view, showing the last commit that modified
256 # each line in the file. This can be very CPU-intensive.
258 # To enable system wide have in $GITWEB_CONFIG
259 # $feature{'blame'}{'default'} = [1];
260 # To have project specific config enable override in $GITWEB_CONFIG
261 # $feature{'blame'}{'override'} = 1;
262 # and in project config gitweb.blame = 0|1;
264 'sub' => sub { feature_bool
('blame', @_) },
268 # Enable the 'snapshot' link, providing a compressed archive of any
269 # tree. This can potentially generate high traffic if you have large
272 # Value is a list of formats defined in %known_snapshot_formats that
274 # To disable system wide have in $GITWEB_CONFIG
275 # $feature{'snapshot'}{'default'} = [];
276 # To have project specific config enable override in $GITWEB_CONFIG
277 # $feature{'snapshot'}{'override'} = 1;
278 # and in project config, a comma-separated list of formats or "none"
279 # to disable. Example: gitweb.snapshot = tbz2,zip;
281 'sub' => \
&feature_snapshot
,
283 'default' => ['tgz']},
285 # Enable text search, which will list the commits which match author,
286 # committer or commit text to a given string. Enabled by default.
287 # Project specific override is not supported.
292 # Enable grep search, which will list the files in currently selected
293 # tree containing the given string. Enabled by default. This can be
294 # potentially CPU-intensive, of course.
296 # To enable system wide have in $GITWEB_CONFIG
297 # $feature{'grep'}{'default'} = [1];
298 # To have project specific config enable override in $GITWEB_CONFIG
299 # $feature{'grep'}{'override'} = 1;
300 # and in project config gitweb.grep = 0|1;
302 'sub' => sub { feature_bool
('grep', @_) },
306 # Enable the pickaxe search, which will list the commits that modified
307 # a given string in a file. This can be practical and quite faster
308 # alternative to 'blame', but still potentially CPU-intensive.
310 # To enable system wide have in $GITWEB_CONFIG
311 # $feature{'pickaxe'}{'default'} = [1];
312 # To have project specific config enable override in $GITWEB_CONFIG
313 # $feature{'pickaxe'}{'override'} = 1;
314 # and in project config gitweb.pickaxe = 0|1;
316 'sub' => sub { feature_bool
('pickaxe', @_) },
320 # Enable showing size of blobs in a 'tree' view, in a separate
321 # column, similar to what 'ls -l' does. This cost a bit of IO.
323 # To disable system wide have in $GITWEB_CONFIG
324 # $feature{'show-sizes'}{'default'} = [0];
325 # To have project specific config enable override in $GITWEB_CONFIG
326 # $feature{'show-sizes'}{'override'} = 1;
327 # and in project config gitweb.showsizes = 0|1;
329 'sub' => sub { feature_bool
('showsizes', @_) },
333 # Make gitweb use an alternative format of the URLs which can be
334 # more readable and natural-looking: project name is embedded
335 # directly in the path and the query string contains other
336 # auxiliary information. All gitweb installations recognize
337 # URL in either format; this configures in which formats gitweb
340 # To enable system wide have in $GITWEB_CONFIG
341 # $feature{'pathinfo'}{'default'} = [1];
342 # Project specific override is not supported.
344 # Note that you will need to change the default location of CSS,
345 # favicon, logo and possibly other files to an absolute URL. Also,
346 # if gitweb.cgi serves as your indexfile, you will need to force
347 # $my_uri to contain the script name in your $GITWEB_CONFIG.
352 # Make gitweb consider projects in project root subdirectories
353 # to be forks of existing projects. Given project $projname.git,
354 # projects matching $projname/*.git will not be shown in the main
355 # projects list, instead a '+' mark will be added to $projname
356 # there and a 'forks' view will be enabled for the project, listing
357 # all the forks. If project list is taken from a file, forks have
358 # to be listed after the main project.
360 # To enable system wide have in $GITWEB_CONFIG
361 # $feature{'forks'}{'default'} = [1];
362 # Project specific override is not supported.
367 # Insert custom links to the action bar of all project pages.
368 # This enables you mainly to link to third-party scripts integrating
369 # into gitweb; e.g. git-browser for graphical history representation
370 # or custom web-based repository administration interface.
372 # The 'default' value consists of a list of triplets in the form
373 # (label, link, position) where position is the label after which
374 # to insert the link and link is a format string where %n expands
375 # to the project name, %f to the project path within the filesystem,
376 # %h to the current hash (h gitweb parameter) and %b to the current
377 # hash base (hb gitweb parameter); %% expands to %.
379 # To enable system wide have in $GITWEB_CONFIG e.g.
380 # $feature{'actions'}{'default'} = [('graphiclog',
381 # '/git-browser/by-commit.html?r=%n', 'summary')];
382 # Project specific override is not supported.
387 # Allow gitweb scan project content tags described in ctags/
388 # of project repository, and display the popular Web 2.0-ish
389 # "tag cloud" near the project list. Note that this is something
390 # COMPLETELY different from the normal Git tags.
392 # gitweb by itself can show existing tags, but it does not handle
393 # tagging itself; you need an external application for that.
394 # For an example script, check Girocco's cgi/tagproj.cgi.
395 # You may want to install the HTML::TagCloud Perl module to get
396 # a pretty tag cloud instead of just a list of tags.
398 # To enable system wide have in $GITWEB_CONFIG
399 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
400 # Project specific override is not supported.
405 # The maximum number of patches in a patchset generated in patch
406 # view. Set this to 0 or undef to disable patch view, or to a
407 # negative number to remove any limit.
409 # To disable system wide have in $GITWEB_CONFIG
410 # $feature{'patches'}{'default'} = [0];
411 # To have project specific config enable override in $GITWEB_CONFIG
412 # $feature{'patches'}{'override'} = 1;
413 # and in project config gitweb.patches = 0|n;
414 # where n is the maximum number of patches allowed in a patchset.
416 'sub' => \
&feature_patches
,
420 # Avatar support. When this feature is enabled, views such as
421 # shortlog or commit will display an avatar associated with
422 # the email of the committer(s) and/or author(s).
424 # Currently available providers are gravatar and picon.
425 # If an unknown provider is specified, the feature is disabled.
427 # Gravatar depends on Digest::MD5.
428 # Picon currently relies on the indiana.edu database.
430 # To enable system wide have in $GITWEB_CONFIG
431 # $feature{'avatar'}{'default'} = ['<provider>'];
432 # where <provider> is either gravatar or picon.
433 # To have project specific config enable override in $GITWEB_CONFIG
434 # $feature{'avatar'}{'override'} = 1;
435 # and in project config gitweb.avatar = <provider>;
437 'sub' => \
&feature_avatar
,
442 sub gitweb_get_feature
{
444 return unless exists $feature{$name};
445 my ($sub, $override, @defaults) = (
446 $feature{$name}{'sub'},
447 $feature{$name}{'override'},
448 @
{$feature{$name}{'default'}});
449 if (!$override) { return @defaults; }
451 warn "feature $name is not overridable";
454 return $sub->(@defaults);
457 # A wrapper to check if a given feature is enabled.
458 # With this, you can say
460 # my $bool_feat = gitweb_check_feature('bool_feat');
461 # gitweb_check_feature('bool_feat') or somecode;
465 # my ($bool_feat) = gitweb_get_feature('bool_feat');
466 # (gitweb_get_feature('bool_feat'))[0] or somecode;
468 sub gitweb_check_feature
{
469 return (gitweb_get_feature
(@_))[0];
475 my ($val) = git_get_project_config
($key, '--bool');
479 } elsif ($val eq 'true') {
481 } elsif ($val eq 'false') {
486 sub feature_snapshot
{
489 my ($val) = git_get_project_config
('snapshot');
492 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
498 sub feature_patches
{
499 my @val = (git_get_project_config
('patches', '--int'));
509 my @val = (git_get_project_config
('avatar'));
511 return @val ?
@val : @_;
514 # checking HEAD file with -e is fragile if the repository was
515 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
517 sub check_head_link
{
519 my $headfile = "$dir/HEAD";
520 return ((-e
$headfile) ||
521 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
524 sub check_export_ok
{
526 return (check_head_link
($dir) &&
527 (!$export_ok || -e
"$dir/$export_ok") &&
528 (!$export_auth_hook || $export_auth_hook->($dir)));
531 # process alternate names for backward compatibility
532 # filter out unsupported (unknown) snapshot formats
533 sub filter_snapshot_fmts
{
537 exists $known_snapshot_format_aliases{$_} ?
538 $known_snapshot_format_aliases{$_} : $_} @fmts;
540 exists $known_snapshot_formats{$_} &&
541 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
544 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
545 if (-e
$GITWEB_CONFIG) {
548 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
549 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
552 # version of the core git binary
553 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
555 $projects_list ||= $projectroot;
557 # ======================================================================
558 # input validation and dispatch
560 # input parameters can be collected from a variety of sources (presently, CGI
561 # and PATH_INFO), so we define an %input_params hash that collects them all
562 # together during validation: this allows subsequent uses (e.g. href()) to be
563 # agnostic of the parameter origin
565 our %input_params = ();
567 # input parameters are stored with the long parameter name as key. This will
568 # also be used in the href subroutine to convert parameters to their CGI
569 # equivalent, and since the href() usage is the most frequent one, we store
570 # the name -> CGI key mapping here, instead of the reverse.
572 # XXX: Warning: If you touch this, check the search form for updating,
575 our @cgi_param_mapping = (
583 hash_parent_base
=> "hpb",
588 snapshot_format
=> "sf",
590 extra_options
=> "opt",
591 search_use_regexp
=> "sr",
593 our %cgi_param_mapping = @cgi_param_mapping;
595 # we will also need to know the possible actions, for validation
597 "blame" => \
&git_blame
,
598 "blobdiff" => \
&git_blobdiff
,
599 "blobdiff_plain" => \
&git_blobdiff_plain
,
600 "blob" => \
&git_blob
,
601 "blob_plain" => \
&git_blob_plain
,
602 "commitdiff" => \
&git_commitdiff
,
603 "commitdiff_plain" => \
&git_commitdiff_plain
,
604 "commit" => \
&git_commit
,
605 "forks" => \
&git_forks
,
606 "heads" => \
&git_heads
,
607 "history" => \
&git_history
,
609 "patch" => \
&git_patch
,
610 "patches" => \
&git_patches
,
612 "atom" => \
&git_atom
,
613 "search" => \
&git_search
,
614 "search_help" => \
&git_search_help
,
615 "shortlog" => \
&git_shortlog
,
616 "summary" => \
&git_summary
,
618 "tags" => \
&git_tags
,
619 "tree" => \
&git_tree
,
620 "snapshot" => \
&git_snapshot
,
621 "object" => \
&git_object
,
622 # those below don't need $project
623 "opml" => \
&git_opml
,
624 "frontpage" => \
&git_frontpage
,
625 "project_list" => \
&git_project_list
,
626 "project_index" => \
&git_project_index
,
629 # finally, we have the hash of allowed extra_options for the commands that
631 our %allowed_options = (
632 "--no-merges" => [ qw(rss atom log shortlog history) ],
635 # fill %input_params with the CGI parameters. All values except for 'opt'
636 # should be single values, but opt can be an array. We should probably
637 # build an array of parameters that can be multi-valued, but since for the time
638 # being it's only this one, we just single it out
639 while (my ($name, $symbol) = each %cgi_param_mapping) {
640 if ($symbol eq 'opt') {
641 $input_params{$name} = [ $cgi->param($symbol) ];
643 $input_params{$name} = $cgi->param($symbol);
647 # Backwards compatibility - by_tag= <=> t=
648 if ($cgi->param('by_tag')) {
649 $input_params{'ctag_filter'} = $cgi->param('by_tag');
652 # now read PATH_INFO and update the parameter list for missing parameters
653 sub evaluate_path_info
{
654 return if defined $input_params{'project'};
655 return if !$path_info;
656 $path_info =~ s
,^/+,,;
657 return if !$path_info;
659 # find which part of PATH_INFO is project
660 my $project = $path_info;
662 while ($project && !check_head_link
("$projectroot/$project")) {
663 $project =~ s
,/*[^/]*$,,;
665 return unless $project;
666 $input_params{'project'} = $project;
668 # do not change any parameters if an action is given using the query string
669 return if $input_params{'action'};
670 $path_info =~ s
,^\Q
$project\E
/*,,;
672 # next, check if we have an action
673 my $action = $path_info;
675 if (exists $actions{$action}) {
676 $path_info =~ s
,^$action/*,,;
677 $input_params{'action'} = $action;
680 # list of actions that want hash_base instead of hash, but can have no
681 # pathname (f) parameter
688 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
689 my ($parentrefname, $parentpathname, $refname, $pathname) =
690 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
692 # first, analyze the 'current' part
693 if (defined $pathname) {
694 # we got "branch:filename" or "branch:dir/"
695 # we could use git_get_type(branch:pathname), but:
696 # - it needs $git_dir
697 # - it does a git() call
698 # - the convention of terminating directories with a slash
699 # makes it superfluous
700 # - embedding the action in the PATH_INFO would make it even
702 $pathname =~ s
,^/+,,;
703 if (!$pathname || substr($pathname, -1) eq "/") {
704 $input_params{'action'} ||= "tree";
707 # the default action depends on whether we had parent info
709 if ($parentrefname) {
710 $input_params{'action'} ||= "blobdiff_plain";
712 $input_params{'action'} ||= "blob_plain";
715 $input_params{'hash_base'} ||= $refname;
716 $input_params{'file_name'} ||= $pathname;
717 } elsif (defined $refname) {
718 # we got "branch". In this case we have to choose if we have to
719 # set hash or hash_base.
721 # Most of the actions without a pathname only want hash to be
722 # set, except for the ones specified in @wants_base that want
723 # hash_base instead. It should also be noted that hand-crafted
724 # links having 'history' as an action and no pathname or hash
725 # set will fail, but that happens regardless of PATH_INFO.
726 $input_params{'action'} ||= "shortlog";
727 if (grep { $_ eq $input_params{'action'} } @wants_base) {
728 $input_params{'hash_base'} ||= $refname;
730 $input_params{'hash'} ||= $refname;
734 # next, handle the 'parent' part, if present
735 if (defined $parentrefname) {
736 # a missing pathspec defaults to the 'current' filename, allowing e.g.
737 # someproject/blobdiff/oldrev..newrev:/filename
738 if ($parentpathname) {
739 $parentpathname =~ s
,^/+,,;
740 $parentpathname =~ s
,/$,,;
741 $input_params{'file_parent'} ||= $parentpathname;
743 $input_params{'file_parent'} ||= $input_params{'file_name'};
745 # we assume that hash_parent_base is wanted if a path was specified,
746 # or if the action wants hash_base instead of hash
747 if (defined $input_params{'file_parent'} ||
748 grep { $_ eq $input_params{'action'} } @wants_base) {
749 $input_params{'hash_parent_base'} ||= $parentrefname;
751 $input_params{'hash_parent'} ||= $parentrefname;
755 # for the snapshot action, we allow URLs in the form
756 # $project/snapshot/$hash.ext
757 # where .ext determines the snapshot and gets removed from the
758 # passed $refname to provide the $hash.
760 # To be able to tell that $refname includes the format extension, we
761 # require the following two conditions to be satisfied:
762 # - the hash input parameter MUST have been set from the $refname part
763 # of the URL (i.e. they must be equal)
764 # - the snapshot format MUST NOT have been defined already (e.g. from
766 # It's also useless to try any matching unless $refname has a dot,
767 # so we check for that too
768 if (defined $input_params{'action'} &&
769 $input_params{'action'} eq 'snapshot' &&
770 defined $refname && index($refname, '.') != -1 &&
771 $refname eq $input_params{'hash'} &&
772 !defined $input_params{'snapshot_format'}) {
773 # We loop over the known snapshot formats, checking for
774 # extensions. Allowed extensions are both the defined suffix
775 # (which includes the initial dot already) and the snapshot
776 # format key itself, with a prepended dot
777 while (my ($fmt, $opt) = each %known_snapshot_formats) {
779 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
783 # a valid suffix was found, so set the snapshot format
784 # and reset the hash parameter
785 $input_params{'snapshot_format'} = $fmt;
786 $input_params{'hash'} = $hash;
787 # we also set the format suffix to the one requested
788 # in the URL: this way a request for e.g. .tgz returns
789 # a .tgz instead of a .tar.gz
790 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
795 evaluate_path_info
();
797 our $action = $input_params{'action'};
798 if (defined $action) {
799 if (!validate_action
($action)) {
800 die_error
(400, "Invalid action parameter");
804 # parameters which are pathnames
805 our $project = $input_params{'project'};
806 if (defined $project) {
807 if (!validate_project
($project)) {
809 die_error
(404, "No such project");
813 our $file_name = $input_params{'file_name'};
814 if (defined $file_name) {
815 if (!validate_pathname
($file_name)) {
816 die_error
(400, "Invalid file parameter");
820 our $file_parent = $input_params{'file_parent'};
821 if (defined $file_parent) {
822 if (!validate_pathname
($file_parent)) {
823 die_error
(400, "Invalid file parent parameter");
827 # parameters which are refnames
828 our $hash = $input_params{'hash'};
830 if (!validate_refname
($hash)) {
831 die_error
(400, "Invalid hash parameter");
835 our $hash_parent = $input_params{'hash_parent'};
836 if (defined $hash_parent) {
837 if (!validate_refname
($hash_parent)) {
838 die_error
(400, "Invalid hash parent parameter");
842 our $hash_base = $input_params{'hash_base'};
843 if (defined $hash_base) {
844 if (!validate_refname
($hash_base)) {
845 die_error
(400, "Invalid hash base parameter");
849 our @extra_options = @
{$input_params{'extra_options'}};
850 # @extra_options is always defined, since it can only be (currently) set from
851 # CGI, and $cgi->param() returns the empty array in array context if the param
853 foreach my $opt (@extra_options) {
854 if (not exists $allowed_options{$opt}) {
855 die_error
(400, "Invalid option parameter");
857 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
858 die_error
(400, "Invalid option parameter for this action");
862 our $hash_parent_base = $input_params{'hash_parent_base'};
863 if (defined $hash_parent_base) {
864 if (!validate_refname
($hash_parent_base)) {
865 die_error
(400, "Invalid hash parent base parameter");
870 our $page = $input_params{'page'};
872 if ($page =~ m/[^0-9]/) {
873 die_error
(400, "Invalid page parameter");
877 our $searchtype = $input_params{'searchtype'};
878 if (defined $searchtype) {
879 if ($searchtype =~ m/[^a-z]/) {
880 die_error
(400, "Invalid searchtype parameter");
884 our $search_use_regexp = $input_params{'search_use_regexp'};
886 our $searchtext = $input_params{'searchtext'};
888 if (defined $searchtext) {
889 if (length($searchtext) < 2) {
890 die_error
(403, "At least two characters are required for search parameter");
892 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
895 # path to the current git repository
897 $git_dir = "$projectroot/$project" if $project;
899 # list of supported snapshot formats
900 our @snapshot_fmts = gitweb_get_feature
('snapshot');
901 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
903 # check that the avatar feature is set to a known provider name,
904 # and for each provider check if the dependencies are satisfied.
905 # if the provider name is invalid or the dependencies are not met,
906 # reset $git_avatar to the empty string.
907 our ($git_avatar) = gitweb_get_feature
('avatar');
908 if ($git_avatar eq 'gravatar') {
909 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
910 } elsif ($git_avatar eq 'picon') {
917 if (!defined $action) {
919 $action = git_get_type
($hash);
920 } elsif (defined $hash_base && defined $file_name) {
921 $action = git_get_type
("$hash_base:$file_name");
922 } elsif (defined $project) {
925 $action = 'frontpage';
928 if (!defined($actions{$action})) {
929 die_error
(400, "Unknown action");
931 if ($action !~ m/^(?:opml|frontpage|project_list|project_index)$/ &&
933 die_error
(400, "Project needed");
935 $actions{$action}->();
938 ## ======================================================================
943 # default is to use -absolute url() i.e. $my_uri
944 my $href = $params{-full
} ?
$my_url : $my_uri;
946 $params{'project'} = $project unless exists $params{'project'};
948 if ($params{-replay
}) {
949 while (my ($name, $symbol) = each %cgi_param_mapping) {
950 if (!exists $params{$name}) {
951 $params{$name} = $input_params{$name};
956 my $use_pathinfo = gitweb_check_feature
('pathinfo');
957 if ($use_pathinfo and defined $params{'project'}) {
958 # try to put as many parameters as possible in PATH_INFO:
961 # - hash_parent or hash_parent_base:/file_parent
962 # - hash or hash_base:/filename
963 # - the snapshot_format as an appropriate suffix
965 # When the script is the root DirectoryIndex for the domain,
966 # $href here would be something like http://gitweb.example.com/
967 # Thus, we strip any trailing / from $href, to spare us double
968 # slashes in the final URL
971 # Then add the project name, if present
972 $href .= "/".esc_url
($params{'project'});
973 delete $params{'project'};
975 # since we destructively absorb parameters, we keep this
976 # boolean that remembers if we're handling a snapshot
977 my $is_snapshot = $params{'action'} eq 'snapshot';
979 # Summary just uses the project path URL, any other action is
981 if (defined $params{'action'}) {
982 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
983 delete $params{'action'};
986 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
987 # stripping nonexistent or useless pieces
988 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
989 || $params{'hash_parent'} || $params{'hash'});
990 if (defined $params{'hash_base'}) {
991 if (defined $params{'hash_parent_base'}) {
992 $href .= esc_url
($params{'hash_parent_base'});
993 # skip the file_parent if it's the same as the file_name
994 if (defined $params{'file_parent'}) {
995 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
996 delete $params{'file_parent'};
997 } elsif ($params{'file_parent'} !~ /\.\./) {
998 $href .= ":/".esc_url
($params{'file_parent'});
999 delete $params{'file_parent'};
1003 delete $params{'hash_parent'};
1004 delete $params{'hash_parent_base'};
1005 } elsif (defined $params{'hash_parent'}) {
1006 $href .= esc_url
($params{'hash_parent'}). "..";
1007 delete $params{'hash_parent'};
1010 $href .= esc_url
($params{'hash_base'});
1011 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1012 $href .= ":/".esc_url
($params{'file_name'});
1013 delete $params{'file_name'};
1015 delete $params{'hash'};
1016 delete $params{'hash_base'};
1017 } elsif (defined $params{'hash'}) {
1018 $href .= esc_url
($params{'hash'});
1019 delete $params{'hash'};
1022 # If the action was a snapshot, we can absorb the
1023 # snapshot_format parameter too
1025 my $fmt = $params{'snapshot_format'};
1026 # snapshot_format should always be defined when href()
1027 # is called, but just in case some code forgets, we
1028 # fall back to the default
1029 $fmt ||= $snapshot_fmts[0];
1030 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1031 delete $params{'snapshot_format'};
1035 # now encode the parameters explicitly
1037 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1038 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1039 if (defined $params{$name}) {
1040 if (ref($params{$name}) eq "ARRAY") {
1041 foreach my $par (@
{$params{$name}}) {
1042 push @result, $symbol . "=" . esc_param
($par);
1045 push @result, $symbol . "=" . esc_param
($params{$name});
1049 $href .= "?" . join(';', @result) if scalar @result;
1055 ## ======================================================================
1056 ## validation, quoting/unquoting and escaping
1058 sub validate_action
{
1059 my $input = shift || return undef;
1060 return undef unless exists $actions{$input};
1064 sub validate_project
{
1065 my $input = shift || return undef;
1066 if (!validate_pathname
($input) ||
1067 !(-d
"$projectroot/$input") ||
1068 !check_export_ok
("$projectroot/$input") ||
1069 ($strict_export && !project_in_list
($input))) {
1076 sub validate_pathname
{
1077 my $input = shift || return undef;
1079 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1080 # at the beginning, at the end, and between slashes.
1081 # also this catches doubled slashes
1082 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1085 # no null characters
1086 if ($input =~ m!\0!) {
1092 sub validate_refname
{
1093 my $input = shift || return undef;
1095 # textual hashes are O.K.
1096 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1099 # it must be correct pathname
1100 $input = validate_pathname
($input)
1102 # restrictions on ref name according to git-check-ref-format
1103 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1109 # decode sequences of octets in utf8 into Perl's internal form,
1110 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1111 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1114 if (utf8
::valid
($str)) {
1118 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1122 # quote unsafe chars, but keep the slash, even when it's not
1123 # correct, but quoted slashes look too horrible in bookmarks
1126 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1131 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1134 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1140 # replace invalid utf8 character with SUBSTITUTION sequence
1145 $str = to_utf8
($str);
1146 $str = $cgi->escapeHTML($str);
1147 if ($opts{'-nbsp'}) {
1148 $str =~ s/ / /g;
1150 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1154 # quote control characters and escape filename to HTML
1159 $str = to_utf8
($str);
1160 $str = $cgi->escapeHTML($str);
1161 if ($opts{'-nbsp'}) {
1162 $str =~ s/ / /g;
1164 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1168 # Make control characters "printable", using character escape codes (CEC)
1172 my %es = ( # character escape codes, aka escape sequences
1173 "\t" => '\t', # tab (HT)
1174 "\n" => '\n', # line feed (LF)
1175 "\r" => '\r', # carrige return (CR)
1176 "\f" => '\f', # form feed (FF)
1177 "\b" => '\b', # backspace (BS)
1178 "\a" => '\a', # alarm (bell) (BEL)
1179 "\e" => '\e', # escape (ESC)
1180 "\013" => '\v', # vertical tab (VT)
1181 "\000" => '\0', # nul character (NUL)
1183 my $chr = ( (exists $es{$cntrl})
1185 : sprintf('\%2x', ord($cntrl)) );
1186 if ($opts{-nohtml
}) {
1189 return "<span class=\"cntrl\">$chr</span>";
1193 # Alternatively use unicode control pictures codepoints,
1194 # Unicode "printable representation" (PR)
1199 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1200 if ($opts{-nohtml
}) {
1203 return "<span class=\"cntrl\">$chr</span>";
1207 # git may return quoted and escaped filenames
1213 my %es = ( # character escape codes, aka escape sequences
1214 't' => "\t", # tab (HT, TAB)
1215 'n' => "\n", # newline (NL)
1216 'r' => "\r", # return (CR)
1217 'f' => "\f", # form feed (FF)
1218 'b' => "\b", # backspace (BS)
1219 'a' => "\a", # alarm (bell) (BEL)
1220 'e' => "\e", # escape (ESC)
1221 'v' => "\013", # vertical tab (VT)
1224 if ($seq =~ m/^[0-7]{1,3}$/) {
1225 # octal char sequence
1226 return chr(oct($seq));
1227 } elsif (exists $es{$seq}) {
1228 # C escape sequence, aka character escape code
1231 # quoted ordinary character
1235 if ($str =~ m/^"(.*)"$/) {
1238 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1243 # escape tabs (convert tabs to spaces)
1247 while ((my $pos = index($line, "\t")) != -1) {
1248 if (my $count = (8 - ($pos % 8))) {
1249 my $spaces = ' ' x
$count;
1250 $line =~ s/\t/$spaces/;
1257 sub project_in_list
{
1258 my $project = shift;
1259 my @list = git_get_projects_list
();
1260 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1263 ## ----------------------------------------------------------------------
1264 ## HTML aware string manipulation
1266 # Try to chop given string on a word boundary between position
1267 # $len and $len+$add_len. If there is no word boundary there,
1268 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1269 # (marking chopped part) would be longer than given string.
1273 my $add_len = shift || 10;
1274 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1276 # Make sure perl knows it is utf8 encoded so we don't
1277 # cut in the middle of a utf8 multibyte char.
1278 $str = to_utf8
($str);
1280 # allow only $len chars, but don't cut a word if it would fit in $add_len
1281 # if it doesn't fit, cut it if it's still longer than the dots we would add
1282 # remove chopped character entities entirely
1284 # when chopping in the middle, distribute $len into left and right part
1285 # return early if chopping wouldn't make string shorter
1286 if ($where eq 'center') {
1287 return $str if ($len + 5 >= length($str)); # filler is length 5
1290 return $str if ($len + 4 >= length($str)); # filler is length 4
1293 # regexps: ending and beginning with word part up to $add_len
1294 my $endre = qr/.{$len}\w{0,$add_len}/;
1295 my $begre = qr/\w{0,$add_len}.{$len}/;
1297 if ($where eq 'left') {
1298 $str =~ m/^(.*?)($begre)$/;
1299 my ($lead, $body) = ($1, $2);
1300 if (length($lead) > 4) {
1301 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1304 return "$lead$body";
1306 } elsif ($where eq 'center') {
1307 $str =~ m/^($endre)(.*)$/;
1308 my ($left, $str) = ($1, $2);
1309 $str =~ m/^(.*?)($begre)$/;
1310 my ($mid, $right) = ($1, $2);
1311 if (length($mid) > 5) {
1312 $left =~ s/&[^;]*$//;
1313 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1316 return "$left$mid$right";
1319 $str =~ m/^($endre)(.*)$/;
1322 if (length($tail) > 4) {
1323 $body =~ s/&[^;]*$//;
1326 return "$body$tail";
1330 # takes the same arguments as chop_str, but also wraps a <span> around the
1331 # result with a title attribute if it does get chopped. Additionally, the
1332 # string is HTML-escaped.
1333 sub chop_and_escape_str
{
1336 my $chopped = chop_str
(@_);
1337 if ($chopped eq $str) {
1338 return esc_html
($chopped);
1340 $str =~ s/[[:cntrl:]]/?/g;
1341 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1345 ## ----------------------------------------------------------------------
1346 ## functions returning short strings
1348 # CSS class for given age value (in seconds)
1352 if (!defined $age) {
1354 } elsif ($age < 60*60*2) {
1356 } elsif ($age < 60*60*24*2) {
1363 # convert age in seconds to "nn units ago" string
1368 if ($age > 60*60*24*365*2) {
1369 $age_str = (int $age/60/60/24/365);
1370 $age_str .= " years ago";
1371 } elsif ($age > 60*60*24*(365/12)*2) {
1372 $age_str = int $age/60/60/24/(365/12);
1373 $age_str .= " months ago";
1374 } elsif ($age > 60*60*24*7*2) {
1375 $age_str = int $age/60/60/24/7;
1376 $age_str .= " weeks ago";
1377 } elsif ($age > 60*60*24*2) {
1378 $age_str = int $age/60/60/24;
1379 $age_str .= " days ago";
1380 } elsif ($age > 60*60*2) {
1381 $age_str = int $age/60/60;
1382 $age_str .= " hours ago";
1383 } elsif ($age > 60*2) {
1384 $age_str = int $age/60;
1385 $age_str .= " min ago";
1386 } elsif ($age > 2) {
1387 $age_str = int $age;
1388 $age_str .= " sec ago";
1390 $age_str .= " right now";
1396 S_IFINVALID
=> 0030000,
1397 S_IFGITLINK
=> 0160000,
1400 # submodule/subproject, a commit object reference
1404 return (($mode & S_IFMT
) == S_IFGITLINK
)
1407 # convert file mode in octal to symbolic file mode string
1409 my $mode = oct shift;
1411 if (S_ISGITLINK
($mode)) {
1412 return 'm---------';
1413 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1414 return 'drwxr-xr-x';
1415 } elsif (S_ISLNK
($mode)) {
1416 return 'lrwxrwxrwx';
1417 } elsif (S_ISREG
($mode)) {
1418 # git cares only about the executable bit
1419 if ($mode & S_IXUSR
) {
1420 return '-rwxr-xr-x';
1422 return '-rw-r--r--';
1425 return '----------';
1429 # convert file mode in octal to file type string
1433 if ($mode !~ m/^[0-7]+$/) {
1439 if (S_ISGITLINK
($mode)) {
1441 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1443 } elsif (S_ISLNK
($mode)) {
1445 } elsif (S_ISREG
($mode)) {
1452 # convert file mode in octal to file type description string
1453 sub file_type_long
{
1456 if ($mode !~ m/^[0-7]+$/) {
1462 if (S_ISGITLINK
($mode)) {
1464 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1466 } elsif (S_ISLNK
($mode)) {
1468 } elsif (S_ISREG
($mode)) {
1469 if ($mode & S_IXUSR
) {
1470 return "executable";
1480 ## ----------------------------------------------------------------------
1481 ## functions returning short HTML fragments, or transforming HTML fragments
1482 ## which don't belong to other sections
1484 # format line of commit message.
1485 sub format_log_line_html
{
1488 $line = esc_html
($line, -nbsp
=>1);
1489 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1490 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1491 -class => "text"}, $1);
1497 # format marker of refs pointing to given object
1499 # the destination action is chosen based on object type and current context:
1500 # - for annotated tags, we choose the tag view unless it's the current view
1501 # already, in which case we go to shortlog view
1502 # - for other refs, we keep the current view if we're in history, shortlog or
1503 # log view, and select shortlog otherwise
1504 sub format_ref_marker
{
1505 my ($refs, $id) = @_;
1508 if (defined $refs->{$id}) {
1509 foreach my $ref (@
{$refs->{$id}}) {
1510 # this code exploits the fact that non-lightweight tags are the
1511 # only indirect objects, and that they are the only objects for which
1512 # we want to use tag instead of shortlog as action
1513 my ($type, $name) = qw();
1514 my $indirect = ($ref =~ s/\^\{\}$//);
1515 # e.g. tags/v2.6.11 or heads/next
1516 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1525 $class .= " indirect" if $indirect;
1527 my $dest_action = "shortlog";
1530 $dest_action = "tag" unless $action eq "tag";
1531 } elsif ($action =~ /^(history|(short)?log)$/) {
1532 $dest_action = $action;
1536 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1539 my $link = $cgi->a({
1541 action
=>$dest_action,
1545 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1551 return ' <span class="refs">'. $markers . '</span>';
1557 # format, perhaps shortened and with markers, title line
1558 sub format_subject_html
{
1559 my ($long, $short, $href, $extra) = @_;
1560 $extra = '' unless defined($extra);
1562 if (length($short) < length($long)) {
1563 $long =~ s/[[:cntrl:]]/?/g;
1564 return $cgi->a({-href
=> $href, -class => "list subject",
1565 -title
=> to_utf8
($long)},
1566 esc_html
($short)) . $extra;
1568 return $cgi->a({-href
=> $href, -class => "list subject"},
1569 esc_html
($long)) . $extra;
1573 # Rather than recomputing the url for an email multiple times, we cache it
1574 # after the first hit. This gives a visible benefit in views where the avatar
1575 # for the same email is used repeatedly (e.g. shortlog).
1576 # The cache is shared by all avatar engines (currently gravatar only), which
1577 # are free to use it as preferred. Since only one avatar engine is used for any
1578 # given page, there's no risk for cache conflicts.
1579 our %avatar_cache = ();
1581 # Compute the picon url for a given email, by using the picon search service over at
1582 # http://www.cs.indiana.edu/picons/search.html
1584 my $email = lc shift;
1585 if (!$avatar_cache{$email}) {
1586 my ($user, $domain) = split('@', $email);
1587 $avatar_cache{$email} =
1588 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1590 "users+domains+unknown/up/single";
1592 return $avatar_cache{$email};
1595 # Compute the gravatar url for a given email, if it's not in the cache already.
1596 # Gravatar stores only the part of the URL before the size, since that's the
1597 # one computationally more expensive. This also allows reuse of the cache for
1598 # different sizes (for this particular engine).
1600 my $email = lc shift;
1602 $avatar_cache{$email} ||=
1603 "http://www.gravatar.com/avatar/" .
1604 Digest
::MD5
::md5_hex
($email) . "?s=";
1605 return $avatar_cache{$email} . $size;
1608 # Insert an avatar for the given $email at the given $size if the feature
1610 sub git_get_avatar
{
1611 my ($email, %opts) = @_;
1612 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1613 my $post_white = ($opts{-pad_after
} ?
" " : "");
1614 $opts{-size
} ||= 'default';
1615 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1617 if ($git_avatar eq 'gravatar') {
1618 $url = gravatar_url
($email, $size);
1619 } elsif ($git_avatar eq 'picon') {
1620 $url = picon_url
($email);
1622 # Other providers can be added by extending the if chain, defining $url
1623 # as needed. If no variant puts something in $url, we assume avatars
1624 # are completely disabled/unavailable.
1627 "<img width=\"$size\" " .
1628 "class=\"avatar\" " .
1637 sub format_search_author
{
1638 my ($author, $searchtype, $displaytext) = @_;
1639 my $have_search = gitweb_check_feature
('search');
1643 if ($searchtype eq 'author') {
1644 $performed = "authored";
1645 } elsif ($searchtype eq 'committer') {
1646 $performed = "committed";
1649 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1650 searchtext
=>$author,
1651 searchtype
=>$searchtype), class=>"list",
1652 title
=>"Search for commits $performed by $author"},
1656 return $displaytext;
1660 # format the author name of the given commit with the given tag
1661 # the author name is chopped and escaped according to the other
1662 # optional parameters (see chop_str).
1663 sub format_author_html
{
1666 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1667 return "<$tag class=\"author\">" .
1668 format_search_author
($co->{'author_name'}, "author",
1669 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1674 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1675 sub format_git_diff_header_line
{
1677 my $diffinfo = shift;
1678 my ($from, $to) = @_;
1680 if ($diffinfo->{'nparents'}) {
1682 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1683 if ($to->{'href'}) {
1684 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1685 esc_path
($to->{'file'}));
1686 } else { # file was deleted (no href)
1687 $line .= esc_path
($to->{'file'});
1691 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1692 if ($from->{'href'}) {
1693 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1694 'a/' . esc_path
($from->{'file'}));
1695 } else { # file was added (no href)
1696 $line .= 'a/' . esc_path
($from->{'file'});
1699 if ($to->{'href'}) {
1700 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1701 'b/' . esc_path
($to->{'file'}));
1702 } else { # file was deleted
1703 $line .= 'b/' . esc_path
($to->{'file'});
1707 return "<div class=\"diff header\">$line</div>\n";
1710 # format extended diff header line, before patch itself
1711 sub format_extended_diff_header_line
{
1713 my $diffinfo = shift;
1714 my ($from, $to) = @_;
1717 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1718 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1719 esc_path
($from->{'file'}));
1721 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1722 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1723 esc_path
($to->{'file'}));
1725 # match single <mode>
1726 if ($line =~ m/\s(\d{6})$/) {
1727 $line .= '<span class="info"> (' .
1728 file_type_long
($1) .
1732 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1733 # can match only for combined diff
1735 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1736 if ($from->{'href'}[$i]) {
1737 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1739 substr($diffinfo->{'from_id'}[$i],0,7));
1744 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1747 if ($to->{'href'}) {
1748 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1749 substr($diffinfo->{'to_id'},0,7));
1754 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1755 # can match only for ordinary diff
1756 my ($from_link, $to_link);
1757 if ($from->{'href'}) {
1758 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1759 substr($diffinfo->{'from_id'},0,7));
1761 $from_link = '0' x
7;
1763 if ($to->{'href'}) {
1764 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1765 substr($diffinfo->{'to_id'},0,7));
1769 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1770 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1773 return $line . "<br/>\n";
1776 # format from-file/to-file diff header
1777 sub format_diff_from_to_header
{
1778 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1783 #assert($line =~ m/^---/) if DEBUG;
1784 # no extra formatting for "^--- /dev/null"
1785 if (! $diffinfo->{'nparents'}) {
1786 # ordinary (single parent) diff
1787 if ($line =~ m!^--- "?a/!) {
1788 if ($from->{'href'}) {
1790 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1791 esc_path
($from->{'file'}));
1794 esc_path
($from->{'file'});
1797 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1800 # combined diff (merge commit)
1801 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1802 if ($from->{'href'}[$i]) {
1804 $cgi->a({-href
=>href
(action
=>"blobdiff",
1805 hash_parent
=>$diffinfo->{'from_id'}[$i],
1806 hash_parent_base
=>$parents[$i],
1807 file_parent
=>$from->{'file'}[$i],
1808 hash
=>$diffinfo->{'to_id'},
1810 file_name
=>$to->{'file'}),
1812 -title
=>"diff" . ($i+1)},
1815 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1816 esc_path
($from->{'file'}[$i]));
1818 $line = '--- /dev/null';
1820 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1825 #assert($line =~ m/^\+\+\+/) if DEBUG;
1826 # no extra formatting for "^+++ /dev/null"
1827 if ($line =~ m!^\+\+\+ "?b/!) {
1828 if ($to->{'href'}) {
1830 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1831 esc_path
($to->{'file'}));
1834 esc_path
($to->{'file'});
1837 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1842 # create note for patch simplified by combined diff
1843 sub format_diff_cc_simplified
{
1844 my ($diffinfo, @parents) = @_;
1847 $result .= "<div class=\"diff header\">" .
1849 if (!is_deleted
($diffinfo)) {
1850 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1852 hash
=>$diffinfo->{'to_id'},
1853 file_name
=>$diffinfo->{'to_file'}),
1855 esc_path
($diffinfo->{'to_file'}));
1857 $result .= esc_path
($diffinfo->{'to_file'});
1859 $result .= "</div>\n" . # class="diff header"
1860 "<div class=\"diff nodifferences\">" .
1862 "</div>\n"; # class="diff nodifferences"
1867 # format patch (diff) line (not to be used for diff headers)
1868 sub format_diff_line
{
1870 my ($from, $to) = @_;
1871 my $diff_class = "";
1875 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1877 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1878 if ($line =~ m/^\@{3}/) {
1879 $diff_class = " chunk_header";
1880 } elsif ($line =~ m/^\\/) {
1881 $diff_class = " incomplete";
1882 } elsif ($prefix =~ tr/+/+/) {
1883 $diff_class = " add";
1884 } elsif ($prefix =~ tr/-/-/) {
1885 $diff_class = " rem";
1888 # assume ordinary diff
1889 my $char = substr($line, 0, 1);
1891 $diff_class = " add";
1892 } elsif ($char eq '-') {
1893 $diff_class = " rem";
1894 } elsif ($char eq '@') {
1895 $diff_class = " chunk_header";
1896 } elsif ($char eq "\\") {
1897 $diff_class = " incomplete";
1900 $line = untabify
($line);
1901 if ($from && $to && $line =~ m/^\@{2} /) {
1902 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1903 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1905 $from_lines = 0 unless defined $from_lines;
1906 $to_lines = 0 unless defined $to_lines;
1908 if ($from->{'href'}) {
1909 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1910 -class=>"list"}, $from_text);
1912 if ($to->{'href'}) {
1913 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1914 -class=>"list"}, $to_text);
1916 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1917 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1918 return "<div class=\"diff$diff_class\">$line</div>\n";
1919 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1920 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1921 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1923 @from_text = split(' ', $ranges);
1924 for (my $i = 0; $i < @from_text; ++$i) {
1925 ($from_start[$i], $from_nlines[$i]) =
1926 (split(',', substr($from_text[$i], 1)), 0);
1929 $to_text = pop @from_text;
1930 $to_start = pop @from_start;
1931 $to_nlines = pop @from_nlines;
1933 $line = "<span class=\"chunk_info\">$prefix ";
1934 for (my $i = 0; $i < @from_text; ++$i) {
1935 if ($from->{'href'}[$i]) {
1936 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1937 -class=>"list"}, $from_text[$i]);
1939 $line .= $from_text[$i];
1943 if ($to->{'href'}) {
1944 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1945 -class=>"list"}, $to_text);
1949 $line .= " $prefix</span>" .
1950 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1951 return "<div class=\"diff$diff_class\">$line</div>\n";
1953 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1956 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1957 # linked. Pass the hash of the tree/commit to snapshot.
1958 sub format_snapshot_links
{
1960 my $num_fmts = @snapshot_fmts;
1961 if ($num_fmts > 1) {
1962 # A parenthesized list of links bearing format names.
1963 # e.g. "snapshot (_tar.gz_ _zip_)"
1964 return "snapshot (" . join(' ', map
1971 }, $known_snapshot_formats{$_}{'display'})
1972 , @snapshot_fmts) . ")";
1973 } elsif ($num_fmts == 1) {
1974 # A single "snapshot" link whose tooltip bears the format name.
1976 my ($fmt) = @snapshot_fmts;
1982 snapshot_format
=>$fmt
1984 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1986 } else { # $num_fmts == 0
1991 ## ......................................................................
1992 ## functions returning values to be passed, perhaps after some
1993 ## transformation, to other functions; e.g. returning arguments to href()
1995 # returns hash to be passed to href to generate gitweb URL
1996 # in -title key it returns description of link
1998 my $format = shift || 'Atom';
1999 my %res = (action
=> lc($format));
2001 # feed links are possible only for project views
2002 return unless (defined $project);
2003 # some views should link to OPML, or to generic project feed,
2004 # or don't have specific feed yet (so they should use generic)
2005 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2008 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2009 # from tag links; this also makes possible to detect branch links
2010 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2011 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2014 # find log type for feed description (title)
2016 if (defined $file_name) {
2017 $type = "history of $file_name";
2018 $type .= "/" if ($action eq 'tree');
2019 $type .= " on '$branch'" if (defined $branch);
2021 $type = "log of $branch" if (defined $branch);
2024 $res{-title
} = $type;
2025 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2026 $res{'file_name'} = $file_name;
2031 ## ----------------------------------------------------------------------
2032 ## git utility subroutines, invoking git commands
2034 # returns path to the core git executable and the --git-dir parameter as list
2036 return $GIT, '--git-dir='.$git_dir;
2039 # quote the given arguments for passing them to the shell
2040 # quote_command("command", "arg 1", "arg with ' and ! characters")
2041 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2042 # Try to avoid using this function wherever possible.
2045 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2048 # get HEAD ref of given project as hash
2049 sub git_get_head_hash
{
2050 my $project = shift;
2051 my $o_git_dir = $git_dir;
2053 $git_dir = "$projectroot/$project";
2054 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
2057 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
2061 if (defined $o_git_dir) {
2062 $git_dir = $o_git_dir;
2067 # get type of given object
2071 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2073 close $fd or return;
2078 # repository configuration
2079 our $config_file = '';
2082 # store multiple values for single key as anonymous array reference
2083 # single values stored directly in the hash, not as [ <value> ]
2084 sub hash_set_multi
{
2085 my ($hash, $key, $value) = @_;
2087 if (!exists $hash->{$key}) {
2088 $hash->{$key} = $value;
2089 } elsif (!ref $hash->{$key}) {
2090 $hash->{$key} = [ $hash->{$key}, $value ];
2092 push @
{$hash->{$key}}, $value;
2096 # return hash of git project configuration
2097 # optionally limited to some section, e.g. 'gitweb'
2098 sub git_parse_project_config
{
2099 my $section_regexp = shift;
2104 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2107 while (my $keyval = <$fh>) {
2109 my ($key, $value) = split(/\n/, $keyval, 2);
2111 hash_set_multi
(\
%config, $key, $value)
2112 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2119 # convert config value to boolean: 'true' or 'false'
2120 # no value, number > 0, 'true' and 'yes' values are true
2121 # rest of values are treated as false (never as error)
2122 sub config_to_bool
{
2125 return 1 if !defined $val; # section.key
2127 # strip leading and trailing whitespace
2131 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2132 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2135 # convert config value to simple decimal number
2136 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2137 # to be multiplied by 1024, 1048576, or 1073741824
2141 # strip leading and trailing whitespace
2145 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2147 # unknown unit is treated as 1
2148 return $num * ($unit eq 'g' ?
1073741824 :
2149 $unit eq 'm' ?
1048576 :
2150 $unit eq 'k' ?
1024 : 1);
2155 # convert config value to array reference, if needed
2156 sub config_to_multi
{
2159 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2162 sub git_get_project_config
{
2163 my ($key, $type) = @_;
2166 return unless ($key);
2167 $key =~ s/^gitweb\.//;
2168 return if ($key =~ m/\W/);
2171 if (defined $type) {
2174 unless ($type eq 'bool' || $type eq 'int');
2178 if (!defined $config_file ||
2179 $config_file ne "$git_dir/config") {
2180 %config = git_parse_project_config
('gitweb');
2181 $config_file = "$git_dir/config";
2184 # check if config variable (key) exists
2185 return unless exists $config{"gitweb.$key"};
2188 if (!defined $type) {
2189 return $config{"gitweb.$key"};
2190 } elsif ($type eq 'bool') {
2191 # backward compatibility: 'git config --bool' returns true/false
2192 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2193 } elsif ($type eq 'int') {
2194 return config_to_int
($config{"gitweb.$key"});
2196 return $config{"gitweb.$key"};
2199 # get hash of given path at given ref
2200 sub git_get_hash_by_path
{
2202 my $path = shift || return undef;
2207 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2208 or die_error
(500, "Open git-ls-tree failed");
2210 close $fd or return undef;
2212 if (!defined $line) {
2213 # there is no tree or hash given by $path at $base
2217 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2218 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2219 if (defined $type && $type ne $2) {
2220 # type doesn't match
2226 # get path of entry with given hash at given tree-ish (ref)
2227 # used to get 'from' filename for combined diff (merge commit) for renames
2228 sub git_get_path_by_hash
{
2229 my $base = shift || return;
2230 my $hash = shift || return;
2234 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2236 while (my $line = <$fd>) {
2239 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2240 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2241 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2250 ## ......................................................................
2251 ## git utility functions, directly accessing git repository
2253 sub git_get_project_description
{
2256 $git_dir = "$projectroot/$path";
2257 open my $fd, '<', "$git_dir/description"
2258 or return git_get_project_config
('description');
2261 if (defined $descr) {
2267 sub git_get_project_ctags
{
2271 $git_dir = "$projectroot/$path";
2272 opendir my $dh, "$git_dir/ctags"
2274 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2275 open my $ct, '<', $_ or next;
2279 my $ctag = $_; $ctag =~ s
#.*/##;
2280 $ctags->{$ctag} = $val;
2286 sub git_populate_project_tagcloud
{
2287 my ($ctags, $action) = @_;
2289 # First, merge different-cased tags; tags vote on casing
2291 foreach (keys %$ctags) {
2292 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2293 if (not $ctags_lc{lc $_}->{topcount
}
2294 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2295 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2296 $ctags_lc{lc $_}->{topname
} = $_;
2301 if (eval { require HTML
::TagCloud
; 1; }) {
2302 $cloud = HTML
::TagCloud
->new;
2303 foreach (sort keys %ctags_lc) {
2304 # Pad the title with spaces so that the cloud looks
2306 my $title = $ctags_lc{$_}->{topname
};
2307 $title =~ s/ / /g;
2308 $title =~ s/^/ /g;
2309 $title =~ s/$/ /g;
2310 $cloud->add($title, href
(-replay
=>1, action
=>$action, ctag_filter
=>$_),
2311 $ctags_lc{$_}->{count
});
2314 $cloud = \
%ctags_lc;
2319 sub git_show_project_tagcloud
{
2320 my ($cloud, $count, $action) = @_;
2321 print STDERR
ref($cloud)."..\n";
2322 if (ref $cloud eq 'HTML::TagCloud') {
2323 return $cloud->html_and_css($count);
2325 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2326 return '<p align="center">' . join (', ', map {
2327 $cgi->a({-href
=> href
(-replay
=>1, action
=>$action, ctag_filter
=>$_)},
2328 $cloud->{$_}->{topname
});
2329 } splice(@tags, 0, $count)) . '</p>';
2333 sub git_get_project_url_list
{
2336 $git_dir = "$projectroot/$path";
2337 open my $fd, '<', "$git_dir/cloneurl"
2338 or return wantarray ?
2339 @
{ config_to_multi
(git_get_project_config
('url')) } :
2340 config_to_multi
(git_get_project_config
('url'));
2341 my @git_project_url_list = map { chomp; $_ } <$fd>;
2344 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2347 sub git_get_projects_list
{
2352 $filter =~ s/\.git$//;
2354 my $check_forks = gitweb_check_feature
('forks');
2356 if (-d
$projects_list) {
2357 # search in directory
2358 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2359 # remove the trailing "/"
2361 my $pfxlen = length("$dir");
2362 my $pfxdepth = ($dir =~ tr!/!!);
2365 follow_fast
=> 1, # follow symbolic links
2366 follow_skip
=> 2, # ignore duplicates
2367 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2369 # skip project-list toplevel, if we get it.
2370 return if (m!^[/.]$!);
2371 # only directories can be git repositories
2372 return unless (-d
$_);
2373 # don't traverse too deep (Find is super slow on os x)
2374 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2375 $File::Find
::prune
= 1;
2379 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2380 # we check related file in $projectroot
2381 my $path = ($filter ?
"$filter/" : '') . $subdir;
2382 if (check_export_ok
("$projectroot/$path")) {
2383 push @list, { path
=> $path };
2384 $File::Find
::prune
= 1;
2389 } elsif (-f
$projects_list) {
2390 # read from file(url-encoded):
2391 # 'git%2Fgit.git Linus+Torvalds'
2392 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2393 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2395 open my $fd, '<', $projects_list or return;
2397 while (my $line = <$fd>) {
2399 my ($path, $owner) = split ' ', $line;
2400 $path = unescape
($path);
2401 $owner = unescape
($owner);
2402 if (!defined $path) {
2405 if ($filter ne '') {
2406 # looking for forks;
2407 my $pfx = substr($path, 0, length($filter));
2408 if ($pfx ne $filter) {
2411 my $sfx = substr($path, length($filter));
2412 if ($sfx !~ /^\/.*\
.git
$/) {
2415 } elsif ($check_forks) {
2417 foreach my $filter (keys %paths) {
2418 # looking for forks;
2419 my $pfx = substr($path, 0, length($filter));
2420 if ($pfx ne $filter) {
2423 my $sfx = substr($path, length($filter));
2424 if ($sfx !~ /^\/.*\
.git
$/) {
2427 # is a fork, don't include it in
2432 if (check_export_ok
("$projectroot/$path")) {
2435 owner
=> to_utf8
($owner),
2438 (my $forks_path = $path) =~ s/\.git$//;
2439 $paths{$forks_path}++;
2447 our $gitweb_project_owner = undef;
2448 sub git_get_project_list_from_file
{
2450 return if (defined $gitweb_project_owner);
2452 $gitweb_project_owner = {};
2453 # read from file (url-encoded):
2454 # 'git%2Fgit.git Linus+Torvalds'
2455 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2456 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2457 if (-f
$projects_list) {
2458 open(my $fd, '<', $projects_list);
2459 while (my $line = <$fd>) {
2461 my ($pr, $ow) = split ' ', $line;
2462 $pr = unescape
($pr);
2463 $ow = unescape
($ow);
2464 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2470 sub git_get_project_owner
{
2471 my $project = shift;
2474 return undef unless $project;
2475 $git_dir = "$projectroot/$project";
2477 if (!defined $gitweb_project_owner) {
2478 git_get_project_list_from_file
();
2481 if (exists $gitweb_project_owner->{$project}) {
2482 $owner = $gitweb_project_owner->{$project};
2484 if (!defined $owner){
2485 $owner = git_get_project_config
('owner');
2487 if (!defined $owner) {
2488 $owner = get_file_owner
("$git_dir");
2494 sub git_get_last_activity
{
2498 $git_dir = "$projectroot/$path";
2499 open($fd, "-|", git_cmd
(), 'for-each-ref',
2500 '--format=%(committer)',
2501 '--sort=-committerdate',
2503 'refs/heads') or return;
2504 my $most_recent = <$fd>;
2505 close $fd or return;
2506 if (defined $most_recent &&
2507 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2509 my $age = time - $timestamp;
2510 return ($age, age_string
($age));
2512 return (undef, undef);
2515 sub git_get_references
{
2516 my $type = shift || "";
2518 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2519 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2520 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2521 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2524 while (my $line = <$fd>) {
2526 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2527 if (defined $refs{$1}) {
2528 push @
{$refs{$1}}, $2;
2534 close $fd or return;
2538 sub git_get_rev_name_tags
{
2539 my $hash = shift || return undef;
2541 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2543 my $name_rev = <$fd>;
2546 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2549 # catches also '$hash undefined' output
2554 ## ----------------------------------------------------------------------
2555 ## parse to hash functions
2559 my $tz = shift || "-0000";
2562 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2563 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2564 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2565 $date{'hour'} = $hour;
2566 $date{'minute'} = $min;
2567 $date{'mday'} = $mday;
2568 $date{'day'} = $days[$wday];
2569 $date{'month'} = $months[$mon];
2570 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2571 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2572 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2573 $mday, $months[$mon], $hour ,$min;
2574 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2575 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2577 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2578 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2579 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2580 $date{'hour_local'} = $hour;
2581 $date{'minute_local'} = $min;
2582 $date{'tz_local'} = $tz;
2583 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2584 1900+$year, $mon+1, $mday,
2585 $hour, $min, $sec, $tz);
2594 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2595 $tag{'id'} = $tag_id;
2596 while (my $line = <$fd>) {
2598 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2599 $tag{'object'} = $1;
2600 } elsif ($line =~ m/^type (.+)$/) {
2602 } elsif ($line =~ m/^tag (.+)$/) {
2604 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2605 $tag{'author'} = $1;
2606 $tag{'author_epoch'} = $2;
2607 $tag{'author_tz'} = $3;
2608 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2609 $tag{'author_name'} = $1;
2610 $tag{'author_email'} = $2;
2612 $tag{'author_name'} = $tag{'author'};
2614 } elsif ($line =~ m/--BEGIN/) {
2615 push @comment, $line;
2617 } elsif ($line eq "") {
2621 push @comment, <$fd>;
2622 $tag{'comment'} = \
@comment;
2623 close $fd or return;
2624 if (!defined $tag{'name'}) {
2630 sub parse_commit_text
{
2631 my ($commit_text, $withparents) = @_;
2632 my @commit_lines = split '\n', $commit_text;
2635 pop @commit_lines; # Remove '\0'
2637 if (! @commit_lines) {
2641 my $header = shift @commit_lines;
2642 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2645 ($co{'id'}, my @parents) = split ' ', $header;
2646 while (my $line = shift @commit_lines) {
2647 last if $line eq "\n";
2648 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2650 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2652 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2653 $co{'author'} = to_utf8
($1);
2654 $co{'author_epoch'} = $2;
2655 $co{'author_tz'} = $3;
2656 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2657 $co{'author_name'} = $1;
2658 $co{'author_email'} = $2;
2660 $co{'author_name'} = $co{'author'};
2662 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2663 $co{'committer'} = to_utf8
($1);
2664 $co{'committer_epoch'} = $2;
2665 $co{'committer_tz'} = $3;
2666 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2667 $co{'committer_name'} = $1;
2668 $co{'committer_email'} = $2;
2670 $co{'committer_name'} = $co{'committer'};
2674 if (!defined $co{'tree'}) {
2677 $co{'parents'} = \
@parents;
2678 $co{'parent'} = $parents[0];
2680 foreach my $title (@commit_lines) {
2683 $co{'title'} = chop_str
($title, 80, 5);
2684 # remove leading stuff of merges to make the interesting part visible
2685 if (length($title) > 50) {
2686 $title =~ s/^Automatic //;
2687 $title =~ s/^merge (of|with) /Merge ... /i;
2688 if (length($title) > 50) {
2689 $title =~ s/(http|rsync):\/\///;
2691 if (length($title) > 50) {
2692 $title =~ s/(master|www|rsync)\.//;
2694 if (length($title) > 50) {
2695 $title =~ s/kernel.org:?//;
2697 if (length($title) > 50) {
2698 $title =~ s/\/pub\/scm//;
2701 $co{'title_short'} = chop_str
($title, 50, 5);
2705 if (! defined $co{'title'} || $co{'title'} eq "") {
2706 $co{'title'} = $co{'title_short'} = '(no commit message)';
2708 # remove added spaces
2709 foreach my $line (@commit_lines) {
2712 $co{'comment'} = \
@commit_lines;
2714 my $age = time - $co{'committer_epoch'};
2716 $co{'age_string'} = age_string
($age);
2717 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2718 if ($age > 60*60*24*7*2) {
2719 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2720 $co{'age_string_age'} = $co{'age_string'};
2722 $co{'age_string_date'} = $co{'age_string'};
2723 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2729 my ($commit_id) = @_;
2734 open my $fd, "-|", git_cmd
(), "rev-list",
2740 or die_error
(500, "Open git-rev-list failed");
2741 %co = parse_commit_text
(<$fd>, 1);
2748 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2756 open my $fd, "-|", git_cmd
(), "rev-list",
2759 ("--max-count=" . $maxcount),
2760 ("--skip=" . $skip),
2764 ($filename ?
($filename) : ())
2765 or die_error
(500, "Open git-rev-list failed");
2766 while (my $line = <$fd>) {
2767 my %co = parse_commit_text
($line);
2772 return wantarray ?
@cos : \
@cos;
2775 # parse line of git-diff-tree "raw" output
2776 sub parse_difftree_raw_line
{
2780 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2781 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2782 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2783 $res{'from_mode'} = $1;
2784 $res{'to_mode'} = $2;
2785 $res{'from_id'} = $3;
2787 $res{'status'} = $5;
2788 $res{'similarity'} = $6;
2789 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2790 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2792 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2795 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2796 # combined diff (for merge commit)
2797 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2798 $res{'nparents'} = length($1);
2799 $res{'from_mode'} = [ split(' ', $2) ];
2800 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2801 $res{'from_id'} = [ split(' ', $3) ];
2802 $res{'to_id'} = pop @
{$res{'from_id'}};
2803 $res{'status'} = [ split('', $4) ];
2804 $res{'to_file'} = unquote
($5);
2806 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2807 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2808 $res{'commit'} = $1;
2811 return wantarray ?
%res : \
%res;
2814 # wrapper: return parsed line of git-diff-tree "raw" output
2815 # (the argument might be raw line, or parsed info)
2816 sub parsed_difftree_line
{
2817 my $line_or_ref = shift;
2819 if (ref($line_or_ref) eq "HASH") {
2820 # pre-parsed (or generated by hand)
2821 return $line_or_ref;
2823 return parse_difftree_raw_line
($line_or_ref);
2827 # parse line of git-ls-tree output
2828 sub parse_ls_tree_line
{
2834 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2835 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2844 $res{'name'} = unquote
($5);
2847 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2848 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2856 $res{'name'} = unquote
($4);
2860 return wantarray ?
%res : \
%res;
2863 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2864 sub parse_from_to_diffinfo
{
2865 my ($diffinfo, $from, $to, @parents) = @_;
2867 if ($diffinfo->{'nparents'}) {
2869 $from->{'file'} = [];
2870 $from->{'href'} = [];
2871 fill_from_file_info
($diffinfo, @parents)
2872 unless exists $diffinfo->{'from_file'};
2873 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2874 $from->{'file'}[$i] =
2875 defined $diffinfo->{'from_file'}[$i] ?
2876 $diffinfo->{'from_file'}[$i] :
2877 $diffinfo->{'to_file'};
2878 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2879 $from->{'href'}[$i] = href
(action
=>"blob",
2880 hash_base
=>$parents[$i],
2881 hash
=>$diffinfo->{'from_id'}[$i],
2882 file_name
=>$from->{'file'}[$i]);
2884 $from->{'href'}[$i] = undef;
2888 # ordinary (not combined) diff
2889 $from->{'file'} = $diffinfo->{'from_file'};
2890 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2891 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2892 hash
=>$diffinfo->{'from_id'},
2893 file_name
=>$from->{'file'});
2895 delete $from->{'href'};
2899 $to->{'file'} = $diffinfo->{'to_file'};
2900 if (!is_deleted
($diffinfo)) { # file exists in result
2901 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2902 hash
=>$diffinfo->{'to_id'},
2903 file_name
=>$to->{'file'});
2905 delete $to->{'href'};
2909 ## ......................................................................
2910 ## parse to array of hashes functions
2912 sub git_get_heads_list
{
2916 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2917 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2918 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2921 while (my $line = <$fd>) {
2925 my ($refinfo, $committerinfo) = split(/\0/, $line);
2926 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2927 my ($committer, $epoch, $tz) =
2928 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2929 $ref_item{'fullname'} = $name;
2930 $name =~ s!^refs/heads/!!;
2932 $ref_item{'name'} = $name;
2933 $ref_item{'id'} = $hash;
2934 $ref_item{'title'} = $title || '(no commit message)';
2935 $ref_item{'epoch'} = $epoch;
2937 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2939 $ref_item{'age'} = "unknown";
2942 push @headslist, \
%ref_item;
2946 return wantarray ?
@headslist : \
@headslist;
2949 sub git_get_tags_list
{
2953 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2954 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2955 '--format=%(objectname) %(objecttype) %(refname) '.
2956 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2959 while (my $line = <$fd>) {
2963 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2964 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2965 my ($creator, $epoch, $tz) =
2966 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2967 $ref_item{'fullname'} = $name;
2968 $name =~ s!^refs/tags/!!;
2970 $ref_item{'type'} = $type;
2971 $ref_item{'id'} = $id;
2972 $ref_item{'name'} = $name;
2973 if ($type eq "tag") {
2974 $ref_item{'subject'} = $title;
2975 $ref_item{'reftype'} = $reftype;
2976 $ref_item{'refid'} = $refid;
2978 $ref_item{'reftype'} = $type;
2979 $ref_item{'refid'} = $id;
2982 if ($type eq "tag" || $type eq "commit") {
2983 $ref_item{'epoch'} = $epoch;
2985 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2987 $ref_item{'age'} = "unknown";
2991 push @tagslist, \
%ref_item;
2995 return wantarray ?
@tagslist : \
@tagslist;
2998 ## ----------------------------------------------------------------------
2999 ## filesystem-related functions
3001 sub get_file_owner
{
3004 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3005 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3006 if (!defined $gcos) {
3010 $owner =~ s/[,;].*$//;
3011 return to_utf8
($owner);
3014 # assume that file exists
3016 my $filename = shift;
3018 open my $fd, '<', $filename;
3019 print map { to_utf8
($_) } <$fd>;
3023 ## ......................................................................
3024 ## mimetype related functions
3026 sub mimetype_guess_file
{
3027 my $filename = shift;
3028 my $mimemap = shift;
3029 -r
$mimemap or return undef;
3032 open(my $mh, '<', $mimemap) or return undef;
3034 next if m/^#/; # skip comments
3035 my ($mimetype, $exts) = split(/\t+/);
3036 if (defined $exts) {
3037 my @exts = split(/\s+/, $exts);
3038 foreach my $ext (@exts) {
3039 $mimemap{$ext} = $mimetype;
3045 $filename =~ /\.([^.]*)$/;
3046 return $mimemap{$1};
3049 sub mimetype_guess
{
3050 my $filename = shift;
3052 $filename =~ /\./ or return undef;
3054 if ($mimetypes_file) {
3055 my $file = $mimetypes_file;
3056 if ($file !~ m!^/!) { # if it is relative path
3057 # it is relative to project
3058 $file = "$projectroot/$project/$file";
3060 $mime = mimetype_guess_file
($filename, $file);
3062 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3068 my $filename = shift;
3071 my $mime = mimetype_guess
($filename);
3072 $mime and return $mime;
3076 return $default_blob_plain_mimetype unless $fd;
3079 return 'text/plain';
3080 } elsif (! $filename) {
3081 return 'application/octet-stream';
3082 } elsif ($filename =~ m/\.png$/i) {
3084 } elsif ($filename =~ m/\.gif$/i) {
3086 } elsif ($filename =~ m/\.jpe?g$/i) {
3087 return 'image/jpeg';
3089 return 'application/octet-stream';
3093 sub blob_contenttype
{
3094 my ($fd, $file_name, $type) = @_;
3096 $type ||= blob_mimetype
($fd, $file_name);
3097 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3098 $type .= "; charset=$default_text_plain_charset";
3104 ## ======================================================================
3105 ## functions printing HTML: header, footer, error page
3107 sub git_header_html
{
3108 my $status = shift || "200 OK";
3109 my $expires = shift;
3111 my $title = "$site_name";
3112 if (defined $project) {
3113 $title .= " - " . to_utf8
($project);
3114 if (defined $action) {
3115 $title .= "/$action";
3116 if (defined $file_name) {
3117 $title .= " - " . esc_path
($file_name);
3118 if ($action eq "tree" && $file_name !~ m
|/$|) {
3125 # require explicit support from the UA if we are to send the page as
3126 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3127 # we have to do this because MSIE sometimes globs '*/*', pretending to
3128 # support xhtml+xml but choking when it gets what it asked for.
3129 if (defined $cgi->http('HTTP_ACCEPT') &&
3130 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3131 $cgi->Accept('application/xhtml+xml') != 0) {
3132 $content_type = 'application/xhtml+xml';
3134 $content_type = 'text/html';
3136 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3137 -status
=> $status, -expires
=> $expires);
3138 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3140 <?xml version="1.0" encoding="utf-8"?>
3141 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3142 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3143 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3144 <!-- git core binaries version $git_version -->
3146 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3147 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3148 <meta name="robots" content="index, nofollow"/>
3149 <title>$title</title>
3151 # the stylesheet, favicon etc urls won't work correctly with path_info
3152 # unless we set the appropriate base URL
3153 if ($ENV{'PATH_INFO'}) {
3154 print "<base href=\"".esc_url
($base_url)."\" />\n";
3156 # print out each stylesheet that exist, providing backwards capability
3157 # for those people who defined $stylesheet in a config file
3158 if (defined $stylesheet) {
3159 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3161 foreach my $stylesheet (@stylesheets) {
3162 next unless $stylesheet;
3163 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3166 if (defined $project) {
3167 my %href_params = get_feed_info
();
3168 if (!exists $href_params{'-title'}) {
3169 $href_params{'-title'} = 'log';
3172 foreach my $format qw(RSS Atom) {
3173 my $type = lc($format);
3175 '-rel' => 'alternate',
3176 '-title' => "$project - $href_params{'-title'} - $format feed",
3177 '-type' => "application/$type+xml"
3180 $href_params{'action'} = $type;
3181 $link_attr{'-href'} = href
(%href_params);
3183 "rel=\"$link_attr{'-rel'}\" ".
3184 "title=\"$link_attr{'-title'}\" ".
3185 "href=\"$link_attr{'-href'}\" ".
3186 "type=\"$link_attr{'-type'}\" ".
3189 $href_params{'extra_options'} = '--no-merges';
3190 $link_attr{'-href'} = href
(%href_params);
3191 $link_attr{'-title'} .= ' (no merges)';
3193 "rel=\"$link_attr{'-rel'}\" ".
3194 "title=\"$link_attr{'-title'}\" ".
3195 "href=\"$link_attr{'-href'}\" ".
3196 "type=\"$link_attr{'-type'}\" ".
3201 printf('<link rel="alternate" title="%s projects list" '.
3202 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3203 $site_name, href
(project
=>undef, action
=>"project_index"));
3204 printf('<link rel="alternate" title="%s projects feeds" '.
3205 'href="%s" type="text/x-opml" />'."\n",
3206 $site_name, href
(project
=>undef, action
=>"opml"));
3208 if (defined $favicon) {
3209 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3215 if (-f
$site_header) {
3216 insert_file
($site_header);
3219 print "<div class=\"page_header\">\n" .
3220 $cgi->a({-href
=> esc_url
($logo_url),
3221 -title
=> $logo_label},
3222 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3223 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3224 if (defined $project) {
3225 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3226 if (defined $action) {
3233 my $have_search = gitweb_check_feature
('search');
3234 if (defined $project && $have_search) {
3235 if (!defined $searchtext) {
3239 if (defined $hash_base) {
3240 $search_hash = $hash_base;
3241 } elsif (defined $hash) {
3242 $search_hash = $hash;
3244 $search_hash = "HEAD";
3246 my $action = $my_uri;
3247 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3248 if ($use_pathinfo) {
3249 $action .= "/".esc_url
($project);
3251 print $cgi->startform(-method
=> "get", -action
=> $action) .
3252 "<div class=\"search\">\n" .
3254 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3255 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3256 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3257 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3258 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3259 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3261 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3262 "<span title=\"Extended regular expression\">" .
3263 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3264 -checked
=> $search_use_regexp) .
3267 $cgi->end_form() . "\n";
3271 sub git_footer_html
{
3272 my $feed_class = 'rss_logo';
3274 print "<div class=\"page_footer\">\n";
3275 if (defined $project) {
3276 my $descr = git_get_project_description
($project);
3277 if (defined $descr) {
3278 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3281 my %href_params = get_feed_info
();
3282 if (!%href_params) {
3283 $feed_class .= ' generic';
3285 $href_params{'-title'} ||= 'log';
3287 foreach my $format qw(RSS Atom) {
3288 $href_params{'action'} = lc($format);
3289 print $cgi->a({-href
=> href
(%href_params),
3290 -title
=> "$href_params{'-title'} $format feed",
3291 -class => $feed_class}, $format)."\n";
3295 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3296 -class => $feed_class}, "OPML") . " ";
3297 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3298 -class => $feed_class}, "TXT") . "\n";
3300 print "</div>\n"; # class="page_footer"
3302 if (-f
$site_footer) {
3303 insert_file
($site_footer);
3310 # die_error(<http_status_code>, <error_message>)
3311 # Example: die_error(404, 'Hash not found')
3312 # By convention, use the following status codes (as defined in RFC 2616):
3313 # 400: Invalid or missing CGI parameters, or
3314 # requested object exists but has wrong type.
3315 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3316 # this server or project.
3317 # 404: Requested object/revision/project doesn't exist.
3318 # 500: The server isn't configured properly, or
3319 # an internal error occurred (e.g. failed assertions caused by bugs), or
3320 # an unknown error occurred (e.g. the git binary died unexpectedly).
3322 my $status = shift || 500;
3323 my $error = shift || "Internal server error";
3325 my %http_responses = (400 => '400 Bad Request',
3326 403 => '403 Forbidden',
3327 404 => '404 Not Found',
3328 500 => '500 Internal Server Error');
3329 git_header_html
($http_responses{$status});
3331 <div class="page_body">
3341 ## ----------------------------------------------------------------------
3342 ## functions printing or outputting HTML: navigation
3344 sub git_print_page_nav
{
3345 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3346 $extra = '' if !defined $extra; # pager or formats
3348 my @navs = qw(summary shortlog log commit commitdiff tree);
3350 @navs = grep { $_ ne $suppress } @navs;
3353 my %arg = map { $_ => {action
=>$_} } @navs;
3354 if (defined $head) {
3355 for (qw(commit commitdiff)) {
3356 $arg{$_}{'hash'} = $head;
3358 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3359 for (qw(shortlog log)) {
3360 $arg{$_}{'hash'} = $head;
3365 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3366 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3368 my @actions = gitweb_get_feature
('actions');
3371 'n' => $project, # project name
3372 'f' => $git_dir, # project path within filesystem
3373 'h' => $treehead || '', # current hash ('h' parameter)
3374 'b' => $treebase || '', # hash base ('hb' parameter)
3377 my ($label, $link, $pos) = splice(@actions,0,3);
3379 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3381 $link =~ s/%([%nfhb])/$repl{$1}/g;
3382 $arg{$label}{'_href'} = $link;
3385 print "<div class=\"page_nav\">\n" .
3387 map { $_ eq $current ?
3388 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3390 print "<br/>\n$extra<br/>\n" .
3394 sub format_paging_nav
{
3395 my ($action, $hash, $head, $page, $has_next_link) = @_;
3399 if ($hash ne $head || $page) {
3400 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3402 $paging_nav .= "HEAD";
3406 $paging_nav .= " ⋅ " .
3407 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3408 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3410 $paging_nav .= " ⋅ prev";
3413 if ($has_next_link) {
3414 $paging_nav .= " ⋅ " .
3415 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3416 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3418 $paging_nav .= " ⋅ next";
3424 ## ......................................................................
3425 ## functions printing or outputting HTML: div
3427 sub git_print_header_div
{
3428 my ($action, $title, $hash, $hash_base) = @_;
3431 $args{'action'} = $action;
3432 $args{'hash'} = $hash if $hash;
3433 $args{'hash_base'} = $hash_base if $hash_base;
3435 print "<div class=\"header\">\n" .
3436 $cgi->a({-href
=> href
(%args), -class => "title"},
3437 $title ?
$title : $action) .
3441 sub print_local_time
{
3443 if ($date{'hour_local'} < 6) {
3444 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3445 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3447 printf(" (%02d:%02d %s)",
3448 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3452 # Outputs the author name and date in long form
3453 sub git_print_authorship
{
3456 my $tag = $opts{-tag
} || 'div';
3457 my $author = $co->{'author_name'};
3459 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3460 print "<$tag class=\"author_date\">" .
3461 format_search_author
($author, "author", esc_html
($author)) .
3463 print_local_time
(%ad) if ($opts{-localtime});
3464 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3468 # Outputs table rows containing the full author or committer information,
3469 # in the format expected for 'commit' view (& similia).
3470 # Parameters are a commit hash reference, followed by the list of people
3471 # to output information for. If the list is empty it defalts to both
3472 # author and committer.
3473 sub git_print_authorship_rows
{
3475 # too bad we can't use @people = @_ || ('author', 'committer')
3477 @people = ('author', 'committer') unless @people;
3478 foreach my $who (@people) {
3479 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3480 print "<tr><td>$who</td><td>" .
3481 format_search_author
($co->{"${who}_name"}, $who,
3482 esc_html
($co->{"${who}_name"})) . " " .
3483 format_search_author
($co->{"${who}_email"}, $who,
3484 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3485 "</td><td rowspan=\"2\">" .
3486 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3489 "<td></td><td> $wd{'rfc2822'}";
3490 print_local_time
(%wd);
3496 sub git_print_page_path
{
3502 print "<div class=\"page_path\">";
3503 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3504 -title
=> 'tree root'}, to_utf8
("[$project]"));
3506 if (defined $name) {
3507 my @dirname = split '/', $name;
3508 my $basename = pop @dirname;
3511 foreach my $dir (@dirname) {
3512 $fullname .= ($fullname ?
'/' : '') . $dir;
3513 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3515 -title
=> $fullname}, esc_path
($dir));
3518 if (defined $type && $type eq 'blob') {
3519 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3521 -title
=> $name}, esc_path
($basename));
3522 } elsif (defined $type && $type eq 'tree') {
3523 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3525 -title
=> $name}, esc_path
($basename));
3528 print esc_path
($basename);
3531 print "<br/></div>\n";
3538 if ($opts{'-remove_title'}) {
3539 # remove title, i.e. first line of log
3542 # remove leading empty lines
3543 while (defined $log->[0] && $log->[0] eq "") {
3550 foreach my $line (@
$log) {
3551 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3554 if (! $opts{'-remove_signoff'}) {
3555 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3558 # remove signoff lines
3565 # print only one empty line
3566 # do not print empty line after signoff
3568 next if ($empty || $signoff);
3574 print format_log_line_html
($line) . "<br/>\n";
3577 if ($opts{'-final_empty_line'}) {
3578 # end with single empty line
3579 print "<br/>\n" unless $empty;
3583 # return link target (what link points to)
3584 sub git_get_link_target
{
3589 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3593 $link_target = <$fd>;
3598 return $link_target;
3601 # given link target, and the directory (basedir) the link is in,
3602 # return target of link relative to top directory (top tree);
3603 # return undef if it is not possible (including absolute links).
3604 sub normalize_link_target
{
3605 my ($link_target, $basedir) = @_;
3607 # absolute symlinks (beginning with '/') cannot be normalized
3608 return if (substr($link_target, 0, 1) eq '/');
3610 # normalize link target to path from top (root) tree (dir)
3613 $path = $basedir . '/' . $link_target;
3615 # we are in top (root) tree (dir)
3616 $path = $link_target;
3619 # remove //, /./, and /../
3621 foreach my $part (split('/', $path)) {
3622 # discard '.' and ''
3623 next if (!$part || $part eq '.');
3625 if ($part eq '..') {
3629 # link leads outside repository (outside top dir)
3633 push @path_parts, $part;
3636 $path = join('/', @path_parts);
3641 # print tree entry (row of git_tree), but without encompassing <tr> element
3642 sub git_print_tree_entry
{
3643 my ($t, $basedir, $hash_base, $have_blame) = @_;
3646 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3648 # The format of a table row is: mode list link. Where mode is
3649 # the mode of the entry, list is the name of the entry, an href,
3650 # and link is the action links of the entry.
3652 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3653 if (exists $t->{'size'}) {
3654 print "<td class=\"size\">$t->{'size'}</td>\n";
3656 if ($t->{'type'} eq "blob") {
3657 print "<td class=\"list\">" .
3658 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3659 file_name
=>"$basedir$t->{'name'}", %base_key),
3660 -class => "list"}, esc_path
($t->{'name'}));
3661 if (S_ISLNK
(oct $t->{'mode'})) {
3662 my $link_target = git_get_link_target
($t->{'hash'});
3664 my $norm_target = normalize_link_target
($link_target, $basedir);
3665 if (defined $norm_target) {
3667 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3668 file_name
=>$norm_target),
3669 -title
=> $norm_target}, esc_path
($link_target));
3671 print " -> " . esc_path
($link_target);
3676 print "<td class=\"link\">";
3677 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3678 file_name
=>"$basedir$t->{'name'}", %base_key)},
3682 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3683 file_name
=>"$basedir$t->{'name'}", %base_key)},
3686 if (defined $hash_base) {
3688 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3689 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3693 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3694 file_name
=>"$basedir$t->{'name'}")},
3698 } elsif ($t->{'type'} eq "tree") {
3699 print "<td class=\"list\">";
3700 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3701 file_name
=>"$basedir$t->{'name'}",
3703 esc_path
($t->{'name'}));
3705 print "<td class=\"link\">";
3706 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3707 file_name
=>"$basedir$t->{'name'}",
3710 if (defined $hash_base) {
3712 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3713 file_name
=>"$basedir$t->{'name'}")},
3718 # unknown object: we can only present history for it
3719 # (this includes 'commit' object, i.e. submodule support)
3720 print "<td class=\"list\">" .
3721 esc_path
($t->{'name'}) .
3723 print "<td class=\"link\">";
3724 if (defined $hash_base) {
3725 print $cgi->a({-href
=> href
(action
=>"history",
3726 hash_base
=>$hash_base,
3727 file_name
=>"$basedir$t->{'name'}")},
3734 ## ......................................................................
3735 ## functions printing large fragments of HTML
3737 # get pre-image filenames for merge (combined) diff
3738 sub fill_from_file_info
{
3739 my ($diff, @parents) = @_;
3741 $diff->{'from_file'} = [ ];
3742 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3743 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3744 if ($diff->{'status'}[$i] eq 'R' ||
3745 $diff->{'status'}[$i] eq 'C') {
3746 $diff->{'from_file'}[$i] =
3747 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3754 # is current raw difftree line of file deletion
3756 my $diffinfo = shift;
3758 return $diffinfo->{'to_id'} eq ('0' x
40);
3761 # does patch correspond to [previous] difftree raw line
3762 # $diffinfo - hashref of parsed raw diff format
3763 # $patchinfo - hashref of parsed patch diff format
3764 # (the same keys as in $diffinfo)
3765 sub is_patch_split
{
3766 my ($diffinfo, $patchinfo) = @_;
3768 return defined $diffinfo && defined $patchinfo
3769 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3773 sub git_difftree_body
{
3774 my ($difftree, $hash, @parents) = @_;
3775 my ($parent) = $parents[0];
3776 my $have_blame = gitweb_check_feature
('blame');
3777 print "<div class=\"list_head\">\n";
3778 if ($#{$difftree} > 10) {
3779 print(($#{$difftree} + 1) . " files changed:\n");
3783 print "<table class=\"" .
3784 (@parents > 1 ?
"combined " : "") .
3787 # header only for combined diff in 'commitdiff' view
3788 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3791 print "<thead><tr>\n" .
3792 "<th></th><th></th>\n"; # filename, patchN link
3793 for (my $i = 0; $i < @parents; $i++) {
3794 my $par = $parents[$i];
3796 $cgi->a({-href
=> href
(action
=>"commitdiff",
3797 hash
=>$hash, hash_parent
=>$par),
3798 -title
=> 'commitdiff to parent number ' .
3799 ($i+1) . ': ' . substr($par,0,7)},
3803 print "</tr></thead>\n<tbody>\n";
3808 foreach my $line (@
{$difftree}) {
3809 my $diff = parsed_difftree_line
($line);
3812 print "<tr class=\"dark\">\n";
3814 print "<tr class=\"light\">\n";
3818 if (exists $diff->{'nparents'}) { # combined diff
3820 fill_from_file_info
($diff, @parents)
3821 unless exists $diff->{'from_file'};
3823 if (!is_deleted
($diff)) {
3824 # file exists in the result (child) commit
3826 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3827 file_name
=>$diff->{'to_file'},
3829 -class => "list"}, esc_path
($diff->{'to_file'})) .
3833 esc_path
($diff->{'to_file'}) .
3837 if ($action eq 'commitdiff') {
3840 print "<td class=\"link\">" .
3841 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3846 my $has_history = 0;
3847 my $not_deleted = 0;
3848 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3849 my $hash_parent = $parents[$i];
3850 my $from_hash = $diff->{'from_id'}[$i];
3851 my $from_path = $diff->{'from_file'}[$i];
3852 my $status = $diff->{'status'}[$i];
3854 $has_history ||= ($status ne 'A');
3855 $not_deleted ||= ($status ne 'D');
3857 if ($status eq 'A') {
3858 print "<td class=\"link\" align=\"right\"> | </td>\n";
3859 } elsif ($status eq 'D') {
3860 print "<td class=\"link\">" .
3861 $cgi->a({-href
=> href
(action
=>"blob",
3864 file_name
=>$from_path)},
3868 if ($diff->{'to_id'} eq $from_hash) {
3869 print "<td class=\"link nochange\">";
3871 print "<td class=\"link\">";
3873 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3874 hash
=>$diff->{'to_id'},
3875 hash_parent
=>$from_hash,
3877 hash_parent_base
=>$hash_parent,
3878 file_name
=>$diff->{'to_file'},
3879 file_parent
=>$from_path)},
3885 print "<td class=\"link\">";
3887 print $cgi->a({-href
=> href
(action
=>"blob",
3888 hash
=>$diff->{'to_id'},
3889 file_name
=>$diff->{'to_file'},
3892 print " | " if ($has_history);
3895 print $cgi->a({-href
=> href
(action
=>"history",
3896 file_name
=>$diff->{'to_file'},
3903 next; # instead of 'else' clause, to avoid extra indent
3905 # else ordinary diff
3907 my ($to_mode_oct, $to_mode_str, $to_file_type);
3908 my ($from_mode_oct, $from_mode_str, $from_file_type);
3909 if ($diff->{'to_mode'} ne ('0' x
6)) {
3910 $to_mode_oct = oct $diff->{'to_mode'};
3911 if (S_ISREG
($to_mode_oct)) { # only for regular file
3912 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3914 $to_file_type = file_type
($diff->{'to_mode'});
3916 if ($diff->{'from_mode'} ne ('0' x
6)) {
3917 $from_mode_oct = oct $diff->{'from_mode'};
3918 if (S_ISREG
($to_mode_oct)) { # only for regular file
3919 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3921 $from_file_type = file_type
($diff->{'from_mode'});
3924 if ($diff->{'status'} eq "A") { # created
3925 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3926 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3927 $mode_chng .= "]</span>";
3929 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3930 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3931 -class => "list"}, esc_path
($diff->{'file'}));
3933 print "<td>$mode_chng</td>\n";
3934 print "<td class=\"link\">";
3935 if ($action eq 'commitdiff') {
3938 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3941 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3942 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3946 } elsif ($diff->{'status'} eq "D") { # deleted
3947 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3949 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3950 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3951 -class => "list"}, esc_path
($diff->{'file'}));
3953 print "<td>$mode_chng</td>\n";
3954 print "<td class=\"link\">";
3955 if ($action eq 'commitdiff') {
3958 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3961 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3962 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3965 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3966 file_name
=>$diff->{'file'})},
3969 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3970 file_name
=>$diff->{'file'})},
3974 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3975 my $mode_chnge = "";
3976 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3977 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3978 if ($from_file_type ne $to_file_type) {
3979 $mode_chnge .= " from $from_file_type to $to_file_type";
3981 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3982 if ($from_mode_str && $to_mode_str) {
3983 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3984 } elsif ($to_mode_str) {
3985 $mode_chnge .= " mode: $to_mode_str";
3988 $mode_chnge .= "]</span>\n";
3991 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3992 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3993 -class => "list"}, esc_path
($diff->{'file'}));
3995 print "<td>$mode_chnge</td>\n";
3996 print "<td class=\"link\">";
3997 if ($action eq 'commitdiff') {
4000 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4002 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4003 # "commit" view and modified file (not onlu mode changed)
4004 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4005 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4006 hash_base
=>$hash, hash_parent_base
=>$parent,
4007 file_name
=>$diff->{'file'})},
4011 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4012 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4015 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4016 file_name
=>$diff->{'file'})},
4019 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4020 file_name
=>$diff->{'file'})},
4024 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4025 my %status_name = ('R' => 'moved', 'C' => 'copied');
4026 my $nstatus = $status_name{$diff->{'status'}};
4028 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4029 # mode also for directories, so we cannot use $to_mode_str
4030 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4033 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4034 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4035 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4036 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4037 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4038 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4039 -class => "list"}, esc_path
($diff->{'from_file'})) .
4040 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4041 "<td class=\"link\">";
4042 if ($action eq 'commitdiff') {
4045 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4047 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4048 # "commit" view and modified file (not only pure rename or copy)
4049 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4050 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4051 hash_base
=>$hash, hash_parent_base
=>$parent,
4052 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4056 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4057 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4060 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4061 file_name
=>$diff->{'to_file'})},
4064 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4065 file_name
=>$diff->{'to_file'})},
4069 } # we should not encounter Unmerged (U) or Unknown (X) status
4072 print "</tbody>" if $has_header;
4076 sub git_patchset_body
{
4077 my ($fd, $difftree, $hash, @hash_parents) = @_;
4078 my ($hash_parent) = $hash_parents[0];
4080 my $is_combined = (@hash_parents > 1);
4082 my $patch_number = 0;
4088 print "<div class=\"patchset\">\n";
4090 # skip to first patch
4091 while ($patch_line = <$fd>) {
4094 last if ($patch_line =~ m/^diff /);
4098 while ($patch_line) {
4100 # parse "git diff" header line
4101 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4102 # $1 is from_name, which we do not use
4103 $to_name = unquote
($2);
4104 $to_name =~ s!^b/!!;
4105 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4106 # $1 is 'cc' or 'combined', which we do not use
4107 $to_name = unquote
($2);
4112 # check if current patch belong to current raw line
4113 # and parse raw git-diff line if needed
4114 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4115 # this is continuation of a split patch
4116 print "<div class=\"patch cont\">\n";
4118 # advance raw git-diff output if needed
4119 $patch_idx++ if defined $diffinfo;
4121 # read and prepare patch information
4122 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4124 # compact combined diff output can have some patches skipped
4125 # find which patch (using pathname of result) we are at now;
4127 while ($to_name ne $diffinfo->{'to_file'}) {
4128 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4129 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4130 "</div>\n"; # class="patch"
4135 last if $patch_idx > $#$difftree;
4136 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4140 # modifies %from, %to hashes
4141 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4143 # this is first patch for raw difftree line with $patch_idx index
4144 # we index @$difftree array from 0, but number patches from 1
4145 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4149 #assert($patch_line =~ m/^diff /) if DEBUG;
4150 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4152 # print "git diff" header
4153 print format_git_diff_header_line
($patch_line, $diffinfo,
4156 # print extended diff header
4157 print "<div class=\"diff extended_header\">\n";
4159 while ($patch_line = <$fd>) {
4162 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4164 print format_extended_diff_header_line
($patch_line, $diffinfo,
4167 print "</div>\n"; # class="diff extended_header"
4169 # from-file/to-file diff header
4170 if (! $patch_line) {
4171 print "</div>\n"; # class="patch"
4174 next PATCH
if ($patch_line =~ m/^diff /);
4175 #assert($patch_line =~ m/^---/) if DEBUG;
4177 my $last_patch_line = $patch_line;
4178 $patch_line = <$fd>;
4180 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4182 print format_diff_from_to_header
($last_patch_line, $patch_line,
4183 $diffinfo, \
%from, \
%to,
4188 while ($patch_line = <$fd>) {
4191 next PATCH
if ($patch_line =~ m/^diff /);
4193 print format_diff_line
($patch_line, \
%from, \
%to);
4197 print "</div>\n"; # class="patch"
4200 # for compact combined (--cc) format, with chunk and patch simpliciaction
4201 # patchset might be empty, but there might be unprocessed raw lines
4202 for (++$patch_idx if $patch_number > 0;
4203 $patch_idx < @
$difftree;
4205 # read and prepare patch information
4206 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4208 # generate anchor for "patch" links in difftree / whatchanged part
4209 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4210 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4211 "</div>\n"; # class="patch"
4216 if ($patch_number == 0) {
4217 if (@hash_parents > 1) {
4218 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4220 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4224 print "</div>\n"; # class="patchset"
4227 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4229 # fills project list info (age, description, owner, forks) for each
4230 # project in the list, removing invalid projects from returned list
4231 # NOTE: modifies $projlist, but does not remove entries from it
4232 sub fill_project_list_info
{
4233 my ($projlist, $check_forks, $show_ctags) = @_;
4237 foreach my $pr (@
$projlist) {
4238 my (@activity) = git_get_last_activity
($pr->{'path'});
4239 unless (@activity) {
4242 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4243 if (!defined $pr->{'descr'}) {
4244 my $descr = git_get_project_description
($pr->{'path'}) || "";
4245 $descr = to_utf8
($descr);
4246 $pr->{'descr_long'} = $descr;
4247 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4249 if (!defined $pr->{'owner'}) {
4250 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4253 my $pname = $pr->{'path'};
4254 if (($pname =~ s/\.git$//) &&
4255 ($pname !~ /\/$/) &&
4256 (-d
"$projectroot/$pname")) {
4257 $pr->{'forks'} = "-d $projectroot/$pname";
4262 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4263 push @projects, $pr;
4269 sub cached_project_list_info
{
4270 my ($projlist, $check_forks, $show_ctags, $cache_lifetime) = @_;
4273 use POSIX
qw(:fcntl_h);
4274 use Storable
qw(store_fd retrieve);
4276 my $cache_file = "$cache_dir/$projlist_cache_name";
4282 if ($cache_lifetime && -f
$cache_file) {
4283 $cache_mtime = stat($cache_file)->mtime;
4285 if (defined $cache_mtime && # caching is on and $cache_file exists
4286 $cache_mtime + $cache_lifetime*60 > $now &&
4287 (my $dump = retrieve
($cache_file))) {
4289 $stale = $now - $cache_mtime;
4292 } else { # Cache miss.
4293 if (defined $cache_mtime) {
4294 # Postpone timeout by two minutes so that we get
4295 # enough time to do our job, or to be more exact
4296 # make cache expire after two minutes from now.
4297 my $time = $now - $cache_lifetime*60 + 120;
4298 utime $time, $time, $cache_file;
4300 @projects = fill_project_list_info
($projlist, $check_forks, $show_ctags);
4301 if ($cache_lifetime &&
4302 (-d
$cache_dir || mkdir($cache_dir, 0700)) &&
4303 sysopen(my $fd, "$cache_file.lock", O_WRONLY
|O_CREAT
|O_EXCL
, 0600)) {
4304 store_fd
(\
@projects, $fd);
4306 rename "$cache_file.lock", $cache_file;
4310 if ($cache_lifetime && $stale > 0) {
4311 print "<div class=\"stale_info\">Cached version (${stale}s old)</div>\n";
4317 # print 'sort by' <th> element, generating 'sort by $name' replay link
4318 # if that order is not selected
4320 my ($name, $order, $header) = @_;
4321 $header ||= ucfirst($name);
4323 if ($order eq $name) {
4324 print "<th>$header</th>\n";
4327 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4328 -class => "header"}, $header) .
4333 sub git_project_list_ctags
{
4334 my ($projects, $action) = @_;
4335 $action ||= 'project_list';
4338 foreach my $p (@
$projects) {
4339 foreach my $ct (keys %{$p->{'ctags'}}) {
4340 $ctags{$ct} += $p->{'ctags'}->{$ct};
4343 my $cloud = git_populate_project_tagcloud
(\
%ctags, $action);
4344 print git_show_project_tagcloud
($cloud, 64, $action);
4347 sub git_project_list_body
{
4348 # actually uses global variable $project
4349 my ($projlist, $order, $from, $to, $extra, $no_header, $ctags_action, $cache_lifetime) = @_;
4351 my $check_forks = gitweb_check_feature
('forks');
4352 my $show_ctags = gitweb_check_feature
('ctags');
4353 my @projects = cached_project_list_info
($projlist, $check_forks, $show_ctags, $cache_lifetime);
4355 $order ||= $default_projects_order;
4356 $from = 0 unless defined $from;
4357 $to = $#projects if (!defined $to || $#projects < $to);
4360 project
=> { key
=> 'path', type
=> 'str' },
4361 descr
=> { key
=> 'descr_long', type
=> 'str' },
4362 owner
=> { key
=> 'owner', type
=> 'str' },
4363 age
=> { key
=> 'age', type
=> 'num' }
4365 my $oi = $order_info{$order};
4366 if ($oi->{'type'} eq 'str') {
4367 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4369 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4373 git_project_list_ctags
(\
@projects, $ctags_action);
4376 print "<table class=\"project_list\">\n";
4377 unless ($no_header) {
4380 print "<th></th>\n";
4382 print_sort_th
('project', $order, 'Project');
4383 print_sort_th
('descr', $order, 'Description');
4384 print_sort_th
('owner', $order, 'Owner');
4385 print_sort_th
('age', $order, 'Last Change');
4386 print "<th></th>\n" . # for links
4390 my $tagfilter = $input_params{'ctag_filter'};
4391 for (my $i = $from; $i <= $to; $i++) {
4392 my $pr = $projects[$i];
4394 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4395 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4396 and not $pr->{'descr_long'} =~ /$searchtext/;
4397 # Weed out forks or non-matching entries of search
4399 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4400 $forkbase="^$forkbase" if $forkbase;
4401 next if not $searchtext and not $tagfilter and $show_ctags
4402 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4406 print "<tr class=\"dark\">\n";
4408 print "<tr class=\"light\">\n";
4413 if ($pr->{'forks'}) {
4414 print "<!-- $pr->{'forks'} -->\n";
4415 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4419 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4420 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4421 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4422 -class => "list", -title
=> $pr->{'descr_long'}},
4423 esc_html
($pr->{'descr'})) . "</td>\n" .
4424 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4425 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4426 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4427 "<td class=\"link\">" .
4428 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4429 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4430 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4431 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4432 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4436 if (defined $extra) {
4439 print "<td></td>\n";
4441 print "<td colspan=\"5\">$extra</td>\n" .
4447 sub git_project_search_form
{
4448 print $cgi->startform(-method
=> "get") .
4449 $cgi->hidden({-name
=>"a", -value
=>"project_list"}) . "\n" .
4450 "<p class=\"projsearch\">Search:\n" .
4451 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4453 $cgi->end_form() . "\n";
4456 sub git_project_list_all
{
4457 my $order = $input_params{'order'};
4458 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4459 die_error
(400, "Unknown order parameter");
4462 my @list = git_get_projects_list
();
4464 die_error
(404, "No projects found");
4467 git_project_list_body
(\
@list, $order, undef, undef, undef, undef, undef, $projlist_cache_lifetime);
4470 sub git_shortlog_body
{
4471 # uses global variable $project
4472 my ($commitlist, $from, $to, $refs, $extra) = @_;
4474 $from = 0 unless defined $from;
4475 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4477 print "<table class=\"shortlog\">\n";
4479 for (my $i = $from; $i <= $to; $i++) {
4480 my %co = %{$commitlist->[$i]};
4481 my $commit = $co{'id'};
4482 my $ref = format_ref_marker
($refs, $commit);
4484 print "<tr class=\"dark\">\n";
4486 print "<tr class=\"light\">\n";
4489 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4490 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4491 format_author_html
('td', \
%co, 10) . "<td>";
4492 print format_subject_html
($co{'title'}, $co{'title_short'},
4493 href
(action
=>"commit", hash
=>$commit), $ref);
4495 "<td class=\"link\">" .
4496 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4497 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4498 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4499 my $snapshot_links = format_snapshot_links
($commit);
4500 if (defined $snapshot_links) {
4501 print " | " . $snapshot_links;
4506 if (defined $extra) {
4508 "<td colspan=\"4\">$extra</td>\n" .
4514 sub git_history_body
{
4515 # Warning: assumes constant type (blob or tree) during history
4516 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4518 $from = 0 unless defined $from;
4519 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4521 print "<table class=\"history\">\n";
4523 for (my $i = $from; $i <= $to; $i++) {
4524 my %co = %{$commitlist->[$i]};
4528 my $commit = $co{'id'};
4530 my $ref = format_ref_marker
($refs, $commit);
4533 print "<tr class=\"dark\">\n";
4535 print "<tr class=\"light\">\n";
4538 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4539 # shortlog: format_author_html('td', \%co, 10)
4540 format_author_html
('td', \
%co, 15, 3) . "<td>";
4541 # originally git_history used chop_str($co{'title'}, 50)
4542 print format_subject_html
($co{'title'}, $co{'title_short'},
4543 href
(action
=>"commit", hash
=>$commit), $ref);
4545 "<td class=\"link\">" .
4546 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4547 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4549 if ($ftype eq 'blob') {
4550 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4551 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4552 if (defined $blob_current && defined $blob_parent &&
4553 $blob_current ne $blob_parent) {
4555 $cgi->a({-href
=> href
(action
=>"blobdiff",
4556 hash
=>$blob_current, hash_parent
=>$blob_parent,
4557 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4558 file_name
=>$file_name)},
4565 if (defined $extra) {
4567 "<td colspan=\"4\">$extra</td>\n" .
4574 # uses global variable $project
4575 my ($taglist, $from, $to, $extra) = @_;
4576 $from = 0 unless defined $from;
4577 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4579 print "<table class=\"tags\">\n";
4581 for (my $i = $from; $i <= $to; $i++) {
4582 my $entry = $taglist->[$i];
4584 my $comment = $tag{'subject'};
4586 if (defined $comment) {
4587 $comment_short = chop_str
($comment, 30, 5);
4590 print "<tr class=\"dark\">\n";
4592 print "<tr class=\"light\">\n";
4595 if (defined $tag{'age'}) {
4596 print "<td><i>$tag{'age'}</i></td>\n";
4598 print "<td></td>\n";
4601 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4602 -class => "list name"}, esc_html
($tag{'name'})) .
4605 if (defined $comment) {
4606 print format_subject_html
($comment, $comment_short,
4607 href
(action
=>"tag", hash
=>$tag{'id'}));
4610 "<td class=\"selflink\">";
4611 if ($tag{'type'} eq "tag") {
4612 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4617 "<td class=\"link\">" . " | " .
4618 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4619 if ($tag{'reftype'} eq "commit") {
4620 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4621 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4622 } elsif ($tag{'reftype'} eq "blob") {
4623 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4628 if (defined $extra) {
4630 "<td colspan=\"5\">$extra</td>\n" .
4636 sub git_heads_body
{
4637 # uses global variable $project
4638 my ($headlist, $head, $from, $to, $extra) = @_;
4639 $from = 0 unless defined $from;
4640 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4642 print "<table class=\"heads\">\n";
4644 for (my $i = $from; $i <= $to; $i++) {
4645 my $entry = $headlist->[$i];
4647 my $curr = $ref{'id'} eq $head;
4649 print "<tr class=\"dark\">\n";
4651 print "<tr class=\"light\">\n";
4654 print "<td><i>$ref{'age'}</i></td>\n" .
4655 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4656 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4657 -class => "list name"},esc_html
($ref{'name'})) .
4659 "<td class=\"link\">" .
4660 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4661 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4662 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4666 if (defined $extra) {
4668 "<td colspan=\"3\">$extra</td>\n" .
4674 sub git_search_grep_body
{
4675 my ($commitlist, $from, $to, $extra) = @_;
4676 $from = 0 unless defined $from;
4677 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4679 print "<table class=\"commit_search\">\n";
4681 for (my $i = $from; $i <= $to; $i++) {
4682 my %co = %{$commitlist->[$i]};
4686 my $commit = $co{'id'};
4688 print "<tr class=\"dark\">\n";
4690 print "<tr class=\"light\">\n";
4693 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4694 format_author_html
('td', \
%co, 15, 5) .
4696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4697 -class => "list subject"},
4698 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4699 my $comment = $co{'comment'};
4700 foreach my $line (@
$comment) {
4701 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4702 my ($lead, $match, $trail) = ($1, $2, $3);
4703 $match = chop_str
($match, 70, 5, 'center');
4704 my $contextlen = int((80 - length($match))/2);
4705 $contextlen = 30 if ($contextlen > 30);
4706 $lead = chop_str
($lead, $contextlen, 10, 'left');
4707 $trail = chop_str
($trail, $contextlen, 10, 'right');
4709 $lead = esc_html
($lead);
4710 $match = esc_html
($match);
4711 $trail = esc_html
($trail);
4713 print "$lead<span class=\"match\">$match</span>$trail<br />";
4717 "<td class=\"link\">" .
4718 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4720 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4722 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4726 if (defined $extra) {
4728 "<td colspan=\"3\">$extra</td>\n" .
4734 ## ======================================================================
4735 ## ======================================================================
4740 if (-f
$home_text) {
4741 print "<div class=\"index_include\">\n";
4742 insert_file
($home_text);
4745 git_project_search_form
();
4746 if (not $frontpage_no_project_list) {
4747 git_project_list_all
();
4749 my $show_ctags = gitweb_check_feature
('ctags');
4750 if ($frontpage_no_project_list == 1 and $show_ctags) {
4751 my @list = git_get_projects_list
();
4752 my @projects = cached_project_list_info
(\
@list,
4753 gitweb_check_feature
('forks'),
4754 $show_ctags, $projlist_cache_lifetime);
4755 git_project_list_ctags
(\
@projects);
4757 print "<p class=\"projectlist_link\">" .
4758 $cgi->a({-href
=> href
(action
=>'project_list')}, "Browse all projects") .
4764 sub git_project_list
{
4766 git_project_search_form
();
4767 git_project_list_all
();
4772 my $order = $input_params{'order'};
4773 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4774 die_error
(400, "Unknown order parameter");
4777 my @list = git_get_projects_list
($project);
4779 die_error
(404, "No forks found");
4783 git_print_page_nav
('','');
4784 git_print_header_div
('summary', "$project forks");
4785 git_project_list_body
(\
@list, $order, undef, undef, undef, undef, 'forks');
4789 sub git_project_index
{
4790 my @projects = git_get_projects_list
($project);
4793 -type
=> 'text/plain',
4794 -charset
=> 'utf-8',
4795 -content_disposition
=> 'inline; filename="index.aux"');
4797 foreach my $pr (@projects) {
4798 if (!exists $pr->{'owner'}) {
4799 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4802 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4803 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4804 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4805 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4809 print "$path $owner\n";
4814 my $descr = git_get_project_description
($project) || "none";
4815 my %co = parse_commit
("HEAD");
4816 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4817 my $head = $co{'id'};
4819 my $owner = git_get_project_owner
($project);
4821 my $refs = git_get_references
();
4822 # These get_*_list functions return one more to allow us to see if
4823 # there are more ...
4824 my @taglist = git_get_tags_list
(16);
4825 my @headlist = git_get_heads_list
(16);
4827 my $check_forks = gitweb_check_feature
('forks');
4830 @forklist = git_get_projects_list
($project);
4834 git_print_page_nav
('summary','', $head);
4836 print "<div class=\"title\"> </div>\n";
4837 print "<table class=\"projects_list\">\n" .
4838 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4839 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4840 if (defined $cd{'rfc2822'}) {
4841 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4844 # use per project git URL list in $projectroot/$project/cloneurl
4845 # or make project git URL from git base URL and project name
4846 my $url_tag = "URL";
4847 my @url_list = git_get_project_url_list
($project);
4848 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4849 foreach my $git_url (@url_list) {
4850 next unless $git_url;
4851 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4856 my $show_ctags = gitweb_check_feature
('ctags');
4858 my $ctags = git_get_project_ctags
($project);
4859 my $cloud = git_populate_project_tagcloud
($ctags, 'project_list');
4860 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4861 print "</td>\n<td>" unless %$ctags;
4862 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4863 print "</td>\n<td>" if %$ctags;
4864 print git_show_project_tagcloud
($cloud, 48, 'project_list');
4870 # If XSS prevention is on, we don't include README.html.
4871 # TODO: Allow a readme in some safe format.
4872 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4873 print "<div class=\"title\">readme</div>\n" .
4874 "<div class=\"readme\">\n";
4875 insert_file
("$projectroot/$project/README.html");
4876 print "\n</div>\n"; # class="readme"
4879 # we need to request one more than 16 (0..15) to check if
4881 my @commitlist = $head ? parse_commits
($head, 17) : ();
4883 git_print_header_div
('shortlog');
4884 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4885 $#commitlist <= 15 ?
undef :
4886 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4890 git_print_header_div
('tags');
4891 git_tags_body
(\
@taglist, 0, 15,
4892 $#taglist <= 15 ?
undef :
4893 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4897 git_print_header_div
('heads');
4898 git_heads_body
(\
@headlist, $head, 0, 15,
4899 $#headlist <= 15 ?
undef :
4900 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4904 git_print_header_div
('forks');
4905 git_project_list_body
(\
@forklist, 'age', 0, 15,
4906 $#forklist <= 15 ?
undef :
4907 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4908 'no_header', 'forks');
4915 my $head = git_get_head_hash
($project);
4917 git_print_page_nav
('','', $head,undef,$head);
4918 my %tag = parse_tag
($hash);
4921 die_error
(404, "Unknown tag object");
4924 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4925 print "<div class=\"title_text\">\n" .
4926 "<table class=\"object_header\">\n" .
4928 "<td>object</td>\n" .
4929 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4930 $tag{'object'}) . "</td>\n" .
4931 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4932 $tag{'type'}) . "</td>\n" .
4934 if (defined($tag{'author'})) {
4935 git_print_authorship_rows
(\
%tag, 'author');
4937 print "</table>\n\n" .
4939 print "<div class=\"page_body\">";
4940 my $comment = $tag{'comment'};
4941 foreach my $line (@
$comment) {
4943 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4951 gitweb_check_feature
('blame')
4952 or die_error
(403, "Blame view not allowed");
4955 die_error
(400, "No file name given") unless $file_name;
4956 $hash_base ||= git_get_head_hash
($project);
4957 die_error
(404, "Couldn't find base commit") unless $hash_base;
4958 my %co = parse_commit
($hash_base)
4959 or die_error
(404, "Commit not found");
4961 if (!defined $hash) {
4962 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4963 or die_error
(404, "Error looking up file");
4965 $ftype = git_get_type
($hash);
4966 if ($ftype !~ "blob") {
4967 die_error
(400, "Object is not a blob");
4971 # run git-blame --porcelain
4972 open my $fd, "-|", git_cmd
(), "blame", '-p',
4973 $hash_base, '--', $file_name
4974 or die_error
(500, "Open git-blame failed");
4979 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4982 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4985 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4987 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4988 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4989 git_print_page_path
($file_name, $ftype, $hash_base);
4992 my @rev_color = qw(light dark);
4993 my $num_colors = scalar(@rev_color);
4994 my $current_color = 0;
4998 <div class="page_body">
4999 <table class="blame">
5000 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
5003 while (my $line = <$fd>) {
5005 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5006 # no <lines in group> for subsequent lines in group of lines
5007 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5008 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5009 if (!exists $metainfo{$full_rev}) {
5010 $metainfo{$full_rev} = { 'nprevious' => 0 };
5012 my $meta = $metainfo{$full_rev};
5014 while ($data = <$fd>) {
5016 last if ($data =~ s/^\t//); # contents of line
5017 if ($data =~ /^(\S+)(?: (.*))?$/) {
5018 $meta->{$1} = $2 unless exists $meta->{$1};
5020 if ($data =~ /^previous /) {
5021 $meta->{'nprevious'}++;
5024 my $short_rev = substr($full_rev, 0, 8);
5025 my $author = $meta->{'author'};
5027 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5028 my $date = $date{'iso-tz'};
5030 $current_color = ($current_color + 1) % $num_colors;
5032 my $tr_class = $rev_color[$current_color];
5033 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5034 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5035 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5036 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5038 print "<td class=\"sha1\"";
5039 print " title=\"". esc_html
($author) . ", $date\"";
5040 print " rowspan=\"$group_size\"" if ($group_size > 1);
5042 print $cgi->a({-href
=> href
(action
=>"commit",
5044 file_name
=>$file_name)},
5045 esc_html
($short_rev));
5046 if ($group_size >= 2) {
5047 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5048 if (@author_initials) {
5050 esc_html
(join('', @author_initials));
5056 # 'previous' <sha1 of parent commit> <filename at commit>
5057 if (exists $meta->{'previous'} &&
5058 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5059 $meta->{'parent'} = $1;
5060 $meta->{'file_parent'} = unquote
($2);
5063 exists($meta->{'parent'}) ?
5064 $meta->{'parent'} : $full_rev;
5065 my $linenr_filename =
5066 exists($meta->{'file_parent'}) ?
5067 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5068 my $blamed = href
(action
=> 'blame',
5069 file_name
=> $linenr_filename,
5070 hash_base
=> $linenr_commit);
5071 print "<td class=\"linenr\">";
5072 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5073 -class => "linenr" },
5076 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5082 or print "Reading blob failed\n";
5089 my $head = git_get_head_hash
($project);
5091 git_print_page_nav
('','', $head,undef,$head);
5092 git_print_header_div
('summary', $project);
5094 my @tagslist = git_get_tags_list
();
5096 git_tags_body
(\
@tagslist);
5102 my $head = git_get_head_hash
($project);
5104 git_print_page_nav
('','', $head,undef,$head);
5105 git_print_header_div
('summary', $project);
5107 my @headslist = git_get_heads_list
();
5109 git_heads_body
(\
@headslist, $head);
5114 sub git_blob_plain
{
5118 if (!defined $hash) {
5119 if (defined $file_name) {
5120 my $base = $hash_base || git_get_head_hash
($project);
5121 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5122 or die_error
(404, "Cannot find file");
5124 die_error
(400, "No file name defined");
5126 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5127 # blobs defined by non-textual hash id's can be cached
5131 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5132 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5134 # content-type (can include charset)
5135 $type = blob_contenttype
($fd, $file_name, $type);
5137 # "save as" filename, even when no $file_name is given
5138 my $save_as = "$hash";
5139 if (defined $file_name) {
5140 $save_as = $file_name;
5141 } elsif ($type =~ m/^text\//) {
5145 # With XSS prevention on, blobs of all types except a few known safe
5146 # ones are served with "Content-Disposition: attachment" to make sure
5147 # they don't run in our security domain. For certain image types,
5148 # blob view writes an <img> tag referring to blob_plain view, and we
5149 # want to be sure not to break that by serving the image as an
5150 # attachment (though Firefox 3 doesn't seem to care).
5151 my $sandbox = $prevent_xss &&
5152 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5156 -expires
=> $expires,
5157 -content_disposition
=>
5158 ($sandbox ?
'attachment' : 'inline')
5159 . '; filename="' . $save_as . '"');
5161 binmode STDOUT
, ':raw';
5163 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5170 if (!defined $hash) {
5171 if (defined $file_name) {
5172 my $base = $hash_base || git_get_head_hash
($project);
5173 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5174 or die_error
(404, "Cannot find file");
5176 die_error
(400, "No file name defined");
5178 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5179 # blobs defined by non-textual hash id's can be cached
5183 my $have_blame = gitweb_check_feature
('blame');
5184 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5185 or die_error
(500, "Couldn't cat $file_name, $hash");
5186 my $mimetype = blob_mimetype
($fd, $file_name);
5187 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5189 return git_blob_plain
($mimetype);
5191 # we can have blame only for text/* mimetype
5192 $have_blame &&= ($mimetype =~ m!^text/!);
5194 git_header_html
(undef, $expires);
5195 my $formats_nav = '';
5196 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5197 if (defined $file_name) {
5200 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5205 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5208 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5211 $cgi->a({-href
=> href
(action
=>"blob",
5212 hash_base
=>"HEAD", file_name
=>$file_name)},
5216 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5219 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5220 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5222 print "<div class=\"page_nav\">\n" .
5223 "<br/><br/></div>\n" .
5224 "<div class=\"title\">$hash</div>\n";
5226 git_print_page_path
($file_name, "blob", $hash_base);
5227 print "<div class=\"page_body\">\n";
5228 if ($mimetype =~ m!^image/!) {
5229 print qq!<img type
="$mimetype"!;
5231 print qq! alt
="$file_name" title
="$file_name"!;
5234 href(action=>"blob_plain
", hash=>$hash,
5235 hash_base=>$hash_base, file_name=>$file_name) .
5239 while (my $line = <$fd>) {
5242 $line = untabify
($line);
5243 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5244 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5248 or print "Reading blob failed.\n";
5254 if (!defined $hash_base) {
5255 $hash_base = "HEAD";
5257 if (!defined $hash) {
5258 if (defined $file_name) {
5259 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5264 die_error
(404, "No such tree") unless defined($hash);
5266 my $show_sizes = gitweb_check_feature
('show-sizes');
5267 my $have_blame = gitweb_check_feature
('blame');
5272 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5273 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5274 or die_error
(500, "Open git-ls-tree failed");
5275 @entries = map { chomp; $_ } <$fd>;
5277 or die_error
(404, "Reading tree failed");
5280 my $refs = git_get_references
();
5281 my $ref = format_ref_marker
($refs, $hash_base);
5284 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5286 if (defined $file_name) {
5288 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5290 $cgi->a({-href
=> href
(action
=>"tree",
5291 hash_base
=>"HEAD", file_name
=>$file_name)},
5294 my $snapshot_links = format_snapshot_links
($hash);
5295 if (defined $snapshot_links) {
5296 # FIXME: Should be available when we have no hash base as well.
5297 push @views_nav, $snapshot_links;
5299 git_print_page_nav
('tree','', $hash_base, undef, undef,
5300 join(' | ', @views_nav));
5301 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5304 print "<div class=\"page_nav\">\n";
5305 print "<br/><br/></div>\n";
5306 print "<div class=\"title\">$hash</div>\n";
5308 if (defined $file_name) {
5309 $basedir = $file_name;
5310 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5313 git_print_page_path
($file_name, 'tree', $hash_base);
5315 print "<div class=\"page_body\">\n";
5316 print "<table class=\"tree\">\n";
5318 # '..' (top directory) link if possible
5319 if (defined $hash_base &&
5320 defined $file_name && $file_name =~ m![^/]+$!) {
5322 print "<tr class=\"dark\">\n";
5324 print "<tr class=\"light\">\n";
5328 my $up = $file_name;
5329 $up =~ s!/?[^/]+$!!;
5330 undef $up unless $up;
5331 # based on git_print_tree_entry
5332 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5333 print '<td class="size"> </td>'."\n" if $show_sizes;
5334 print '<td class="list">';
5335 print $cgi->a({-href
=> href
(action
=>"tree",
5336 hash_base
=>$hash_base,
5340 print "<td class=\"link\"></td>\n";
5344 foreach my $line (@entries) {
5345 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5348 print "<tr class=\"dark\">\n";
5350 print "<tr class=\"light\">\n";
5354 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5358 print "</table>\n" .
5364 my $format = $input_params{'snapshot_format'};
5365 if (!@snapshot_fmts) {
5366 die_error
(403, "Snapshots not allowed");
5368 # default to first supported snapshot format
5369 $format ||= $snapshot_fmts[0];
5370 if ($format !~ m/^[a-z0-9]+$/) {
5371 die_error
(400, "Invalid snapshot format parameter");
5372 } elsif (!exists($known_snapshot_formats{$format})) {
5373 die_error
(400, "Unknown snapshot format");
5374 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5375 die_error
(403, "Snapshot format not allowed");
5376 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5377 die_error
(403, "Unsupported snapshot format");
5380 if (!defined $hash) {
5381 $hash = git_get_head_hash
($project);
5384 my $name = $project;
5385 $name =~ s
,([^/])/*\
.git
$,$1,;
5386 $name = basename
($name);
5387 my $filename = to_utf8
($name);
5388 $name =~ s/\047/\047\\\047\047/g;
5390 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5391 $cmd = quote_command
(
5392 git_cmd
(), 'archive',
5393 "--format=$known_snapshot_formats{$format}{'format'}",
5394 "--prefix=$name/", $hash);
5395 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5396 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5400 -type
=> $known_snapshot_formats{$format}{'type'},
5401 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5402 -status
=> '200 OK');
5404 open my $fd, "-|", $cmd
5405 or die_error
(500, "Execute git-archive failed");
5406 binmode STDOUT
, ':raw';
5408 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5413 my $head = git_get_head_hash
($project);
5414 if (!defined $hash) {
5417 if (!defined $page) {
5420 my $refs = git_get_references
();
5422 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5424 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5426 my ($patch_max) = gitweb_get_feature
('patches');
5428 if ($patch_max < 0 || @commitlist <= $patch_max) {
5429 $paging_nav .= " ⋅ " .
5430 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5436 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5439 my %co = parse_commit
($hash);
5441 git_print_header_div
('summary', $project);
5442 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5444 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5445 for (my $i = 0; $i <= $to; $i++) {
5446 my %co = %{$commitlist[$i]};
5448 my $commit = $co{'id'};
5449 my $ref = format_ref_marker
($refs, $commit);
5450 my %ad = parse_date
($co{'author_epoch'});
5451 git_print_header_div
('commit',
5452 "<span class=\"age\">$co{'age_string'}</span>" .
5453 esc_html
($co{'title'}) . $ref,
5455 print "<div class=\"title_text\">\n" .
5456 "<div class=\"log_link\">\n" .
5457 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5459 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5461 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5464 git_print_authorship
(\
%co, -tag
=> 'span');
5465 print "<br/>\n</div>\n";
5467 print "<div class=\"log_body\">\n";
5468 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5471 if ($#commitlist >= 100) {
5472 print "<div class=\"page_nav\">\n";
5473 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5474 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5481 $hash ||= $hash_base || "HEAD";
5482 my %co = parse_commit
($hash)
5483 or die_error
(404, "Unknown commit object");
5485 my $parent = $co{'parent'};
5486 my $parents = $co{'parents'}; # listref
5488 # we need to prepare $formats_nav before any parameter munging
5490 if (!defined $parent) {
5492 $formats_nav .= '(initial)';
5493 } elsif (@
$parents == 1) {
5494 # single parent commit
5497 $cgi->a({-href
=> href
(action
=>"commit",
5499 esc_html
(substr($parent, 0, 7))) .
5506 $cgi->a({-href
=> href
(action
=>"commit",
5508 esc_html
(substr($_, 0, 7)));
5512 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5513 $formats_nav .= " | " .
5514 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5518 if (!defined $parent) {
5522 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5524 (@
$parents <= 1 ?
$parent : '-c'),
5526 or die_error
(500, "Open git-diff-tree failed");
5527 @difftree = map { chomp; $_ } <$fd>;
5528 close $fd or die_error
(404, "Reading git-diff-tree failed");
5530 # non-textual hash id's can be cached
5532 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5535 my $refs = git_get_references
();
5536 my $ref = format_ref_marker
($refs, $co{'id'});
5538 git_header_html
(undef, $expires);
5539 git_print_page_nav
('commit', '',
5540 $hash, $co{'tree'}, $hash,
5543 if (defined $co{'parent'}) {
5544 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5546 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5548 print "<div class=\"title_text\">\n" .
5549 "<table class=\"object_header\">\n";
5550 git_print_authorship_rows
(\
%co);
5551 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5554 "<td class=\"sha1\">" .
5555 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5556 class => "list"}, $co{'tree'}) .
5558 "<td class=\"link\">" .
5559 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5561 my $snapshot_links = format_snapshot_links
($hash);
5562 if (defined $snapshot_links) {
5563 print " | " . $snapshot_links;
5568 foreach my $par (@
$parents) {
5571 "<td class=\"sha1\">" .
5572 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5573 class => "list"}, $par) .
5575 "<td class=\"link\">" .
5576 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5578 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5585 print "<div class=\"page_body\">\n";
5586 git_print_log
($co{'comment'});
5589 git_difftree_body
(\
@difftree, $hash, @
$parents);
5595 # object is defined by:
5596 # - hash or hash_base alone
5597 # - hash_base and file_name
5600 # - hash or hash_base alone
5601 if ($hash || ($hash_base && !defined $file_name)) {
5602 my $object_id = $hash || $hash_base;
5604 open my $fd, "-|", quote_command
(
5605 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5606 or die_error
(404, "Object does not exist");
5610 or die_error
(404, "Object does not exist");
5612 # - hash_base and file_name
5613 } elsif ($hash_base && defined $file_name) {
5614 $file_name =~ s
,/+$,,;
5616 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5617 or die_error
(404, "Base object does not exist");
5619 # here errors should not hapen
5620 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5621 or die_error
(500, "Open git-ls-tree failed");
5625 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5626 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5627 die_error
(404, "File or directory for given base does not exist");
5632 die_error
(400, "Not enough information to find object");
5635 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5636 hash
=>$hash, hash_base
=>$hash_base,
5637 file_name
=>$file_name),
5638 -status
=> '302 Found');
5642 my $format = shift || 'html';
5649 # preparing $fd and %diffinfo for git_patchset_body
5651 if (defined $hash_base && defined $hash_parent_base) {
5652 if (defined $file_name) {
5654 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5655 $hash_parent_base, $hash_base,
5656 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5657 or die_error
(500, "Open git-diff-tree failed");
5658 @difftree = map { chomp; $_ } <$fd>;
5660 or die_error
(404, "Reading git-diff-tree failed");
5662 or die_error
(404, "Blob diff not found");
5664 } elsif (defined $hash &&
5665 $hash =~ /[0-9a-fA-F]{40}/) {
5666 # try to find filename from $hash
5668 # read filtered raw output
5669 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5670 $hash_parent_base, $hash_base, "--"
5671 or die_error
(500, "Open git-diff-tree failed");
5673 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5675 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5676 map { chomp; $_ } <$fd>;
5678 or die_error
(404, "Reading git-diff-tree failed");
5680 or die_error
(404, "Blob diff not found");
5683 die_error
(400, "Missing one of the blob diff parameters");
5686 if (@difftree > 1) {
5687 die_error
(400, "Ambiguous blob diff specification");
5690 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5691 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5692 $file_name ||= $diffinfo{'to_file'};
5694 $hash_parent ||= $diffinfo{'from_id'};
5695 $hash ||= $diffinfo{'to_id'};
5697 # non-textual hash id's can be cached
5698 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5699 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5704 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5705 '-p', ($format eq 'html' ?
"--full-index" : ()),
5706 $hash_parent_base, $hash_base,
5707 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5708 or die_error
(500, "Open git-diff-tree failed");
5711 # old/legacy style URI -- not generated anymore since 1.4.3.
5713 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5717 if ($format eq 'html') {
5719 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5721 git_header_html
(undef, $expires);
5722 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5723 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5724 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5726 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5727 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5729 if (defined $file_name) {
5730 git_print_page_path
($file_name, "blob", $hash_base);
5732 print "<div class=\"page_path\"></div>\n";
5735 } elsif ($format eq 'plain') {
5737 -type
=> 'text/plain',
5738 -charset
=> 'utf-8',
5739 -expires
=> $expires,
5740 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5742 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5745 die_error
(400, "Unknown blobdiff format");
5749 if ($format eq 'html') {
5750 print "<div class=\"page_body\">\n";
5752 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5755 print "</div>\n"; # class="page_body"
5759 while (my $line = <$fd>) {
5760 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5761 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5765 last if $line =~ m!^\+\+\+!;
5773 sub git_blobdiff_plain
{
5774 git_blobdiff
('plain');
5777 sub git_commitdiff
{
5779 my $format = $params{-format
} || 'html';
5781 my ($patch_max) = gitweb_get_feature
('patches');
5782 if ($format eq 'patch') {
5783 die_error
(403, "Patch view not allowed") unless $patch_max;
5786 $hash ||= $hash_base || "HEAD";
5787 my %co = parse_commit
($hash)
5788 or die_error
(404, "Unknown commit object");
5790 # choose format for commitdiff for merge
5791 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5792 $hash_parent = '--cc';
5794 # we need to prepare $formats_nav before almost any parameter munging
5796 if ($format eq 'html') {
5798 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5800 if ($patch_max && @
{$co{'parents'}} <= 1) {
5801 $formats_nav .= " | " .
5802 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5806 if (defined $hash_parent &&
5807 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5808 # commitdiff with two commits given
5809 my $hash_parent_short = $hash_parent;
5810 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5811 $hash_parent_short = substr($hash_parent, 0, 7);
5815 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5816 if ($co{'parents'}[$i] eq $hash_parent) {
5817 $formats_nav .= ' parent ' . ($i+1);
5821 $formats_nav .= ': ' .
5822 $cgi->a({-href
=> href
(action
=>"commitdiff",
5823 hash
=>$hash_parent)},
5824 esc_html
($hash_parent_short)) .
5826 } elsif (!$co{'parent'}) {
5828 $formats_nav .= ' (initial)';
5829 } elsif (scalar @
{$co{'parents'}} == 1) {
5830 # single parent commit
5833 $cgi->a({-href
=> href
(action
=>"commitdiff",
5834 hash
=>$co{'parent'})},
5835 esc_html
(substr($co{'parent'}, 0, 7))) .
5839 if ($hash_parent eq '--cc') {
5840 $formats_nav .= ' | ' .
5841 $cgi->a({-href
=> href
(action
=>"commitdiff",
5842 hash
=>$hash, hash_parent
=>'-c')},
5844 } else { # $hash_parent eq '-c'
5845 $formats_nav .= ' | ' .
5846 $cgi->a({-href
=> href
(action
=>"commitdiff",
5847 hash
=>$hash, hash_parent
=>'--cc')},
5853 $cgi->a({-href
=> href
(action
=>"commitdiff",
5855 esc_html
(substr($_, 0, 7)));
5856 } @
{$co{'parents'}} ) .
5861 my $hash_parent_param = $hash_parent;
5862 if (!defined $hash_parent_param) {
5863 # --cc for multiple parents, --root for parentless
5864 $hash_parent_param =
5865 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5871 if ($format eq 'html') {
5872 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5873 "--no-commit-id", "--patch-with-raw", "--full-index",
5874 $hash_parent_param, $hash, "--"
5875 or die_error
(500, "Open git-diff-tree failed");
5877 while (my $line = <$fd>) {
5879 # empty line ends raw part of diff-tree output
5881 push @difftree, scalar parse_difftree_raw_line
($line);
5884 } elsif ($format eq 'plain') {
5885 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5886 '-p', $hash_parent_param, $hash, "--"
5887 or die_error
(500, "Open git-diff-tree failed");
5888 } elsif ($format eq 'patch') {
5889 # For commit ranges, we limit the output to the number of
5890 # patches specified in the 'patches' feature.
5891 # For single commits, we limit the output to a single patch,
5892 # diverging from the git-format-patch default.
5893 my @commit_spec = ();
5895 if ($patch_max > 0) {
5896 push @commit_spec, "-$patch_max";
5898 push @commit_spec, '-n', "$hash_parent..$hash";
5900 if ($params{-single
}) {
5901 push @commit_spec, '-1';
5903 if ($patch_max > 0) {
5904 push @commit_spec, "-$patch_max";
5906 push @commit_spec, "-n";
5908 push @commit_spec, '--root', $hash;
5910 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5911 '--stdout', @commit_spec
5912 or die_error
(500, "Open git-format-patch failed");
5914 die_error
(400, "Unknown commitdiff format");
5917 # non-textual hash id's can be cached
5919 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5923 # write commit message
5924 if ($format eq 'html') {
5925 my $refs = git_get_references
();
5926 my $ref = format_ref_marker
($refs, $co{'id'});
5928 git_header_html
(undef, $expires);
5929 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5930 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5931 print "<div class=\"title_text\">\n" .
5932 "<table class=\"object_header\">\n";
5933 git_print_authorship_rows
(\
%co);
5936 print "<div class=\"page_body\">\n";
5937 if (@
{$co{'comment'}} > 1) {
5938 print "<div class=\"log\">\n";
5939 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5940 print "</div>\n"; # class="log"
5943 } elsif ($format eq 'plain') {
5944 my $refs = git_get_references
("tags");
5945 my $tagname = git_get_rev_name_tags
($hash);
5946 my $filename = basename
($project) . "-$hash.patch";
5949 -type
=> 'text/plain',
5950 -charset
=> 'utf-8',
5951 -expires
=> $expires,
5952 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5953 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5954 print "From: " . to_utf8
($co{'author'}) . "\n";
5955 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5956 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5958 print "X-Git-Tag: $tagname\n" if $tagname;
5959 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5961 foreach my $line (@
{$co{'comment'}}) {
5962 print to_utf8
($line) . "\n";
5965 } elsif ($format eq 'patch') {
5966 my $filename = basename
($project) . "-$hash.patch";
5969 -type
=> 'text/plain',
5970 -charset
=> 'utf-8',
5971 -expires
=> $expires,
5972 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5976 if ($format eq 'html') {
5977 my $use_parents = !defined $hash_parent ||
5978 $hash_parent eq '-c' || $hash_parent eq '--cc';
5979 git_difftree_body
(\
@difftree, $hash,
5980 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5983 git_patchset_body
($fd, \
@difftree, $hash,
5984 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5986 print "</div>\n"; # class="page_body"
5989 } elsif ($format eq 'plain') {
5993 or print "Reading git-diff-tree failed\n";
5994 } elsif ($format eq 'patch') {
5998 or print "Reading git-format-patch failed\n";
6002 sub git_commitdiff_plain
{
6003 git_commitdiff
(-format
=> 'plain');
6006 # format-patch-style patches
6008 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6012 git_commitdiff
(-format
=> 'patch');
6016 if (!defined $hash_base) {
6017 $hash_base = git_get_head_hash
($project);
6019 if (!defined $page) {
6023 my %co = parse_commit
($hash_base)
6024 or die_error
(404, "Unknown commit object");
6026 my $refs = git_get_references
();
6027 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
6029 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
6030 $file_name, "--full-history")
6031 or die_error
(404, "No such file or directory on given branch");
6033 if (!defined $hash && defined $file_name) {
6034 # some commits could have deleted file in question,
6035 # and not have it in tree, but one of them has to have it
6036 for (my $i = 0; $i <= @commitlist; $i++) {
6037 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
6038 last if defined $hash;
6041 if (defined $hash) {
6042 $ftype = git_get_type
($hash);
6044 if (!defined $ftype) {
6045 die_error
(500, "Unknown type of object");
6048 my $paging_nav = '';
6051 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
6052 file_name
=>$file_name)},
6054 $paging_nav .= " ⋅ " .
6055 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6056 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6058 $paging_nav .= "first";
6059 $paging_nav .= " ⋅ prev";
6062 if ($#commitlist >= 100) {
6064 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6065 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6066 $paging_nav .= " ⋅ $next_link";
6068 $paging_nav .= " ⋅ next";
6072 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
6073 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6074 git_print_page_path
($file_name, $ftype, $hash_base);
6076 git_history_body
(\
@commitlist, 0, 99,
6077 $refs, $hash_base, $ftype, $next_link);
6083 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6084 if (!defined $searchtext) {
6085 die_error
(400, "Text field is empty");
6087 if (!defined $hash) {
6088 $hash = git_get_head_hash
($project);
6090 my %co = parse_commit
($hash);
6092 die_error
(404, "Unknown commit object");
6094 if (!defined $page) {
6098 $searchtype ||= 'commit';
6099 if ($searchtype eq 'pickaxe') {
6100 # pickaxe may take all resources of your box and run for several minutes
6101 # with every query - so decide by yourself how public you make this feature
6102 gitweb_check_feature
('pickaxe')
6103 or die_error
(403, "Pickaxe is disabled");
6105 if ($searchtype eq 'grep') {
6106 gitweb_check_feature
('grep')
6107 or die_error
(403, "Grep is disabled");
6112 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6114 if ($searchtype eq 'commit') {
6115 $greptype = "--grep=";
6116 } elsif ($searchtype eq 'author') {
6117 $greptype = "--author=";
6118 } elsif ($searchtype eq 'committer') {
6119 $greptype = "--committer=";
6121 $greptype .= $searchtext;
6122 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6123 $greptype, '--regexp-ignore-case',
6124 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6126 my $paging_nav = '';
6129 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6130 searchtext
=>$searchtext,
6131 searchtype
=>$searchtype)},
6133 $paging_nav .= " ⋅ " .
6134 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6135 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6137 $paging_nav .= "first";
6138 $paging_nav .= " ⋅ prev";
6141 if ($#commitlist >= 100) {
6143 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6144 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6145 $paging_nav .= " ⋅ $next_link";
6147 $paging_nav .= " ⋅ next";
6150 if ($#commitlist >= 100) {
6153 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6154 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6155 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6158 if ($searchtype eq 'pickaxe') {
6159 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6160 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6162 print "<table class=\"pickaxe search\">\n";
6165 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6166 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6167 ($search_use_regexp ?
'--pickaxe-regex' : ());
6170 while (my $line = <$fd>) {
6174 my %set = parse_difftree_raw_line
($line);
6175 if (defined $set{'commit'}) {
6176 # finish previous commit
6179 "<td class=\"link\">" .
6180 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6182 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6188 print "<tr class=\"dark\">\n";
6190 print "<tr class=\"light\">\n";
6193 %co = parse_commit
($set{'commit'});
6194 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6195 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6196 "<td><i>$author</i></td>\n" .
6198 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6199 -class => "list subject"},
6200 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6201 } elsif (defined $set{'to_id'}) {
6202 next if ($set{'to_id'} =~ m/^0{40}$/);
6204 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6205 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6207 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6213 # finish last commit (warning: repetition!)
6216 "<td class=\"link\">" .
6217 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6219 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6227 if ($searchtype eq 'grep') {
6228 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6229 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6231 print "<table class=\"grep_search\">\n";
6235 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6236 $search_use_regexp ?
('-E', '-i') : '-F',
6237 $searchtext, $co{'tree'};
6239 while (my $line = <$fd>) {
6241 my ($file, $lno, $ltext, $binary);
6242 last if ($matches++ > 1000);
6243 if ($line =~ /^Binary file (.+) matches$/) {
6247 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6249 if ($file ne $lastfile) {
6250 $lastfile and print "</td></tr>\n";
6252 print "<tr class=\"dark\">\n";
6254 print "<tr class=\"light\">\n";
6256 print "<td class=\"list\">".
6257 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6258 file_name
=>"$file"),
6259 -class => "list"}, esc_path
($file));
6260 print "</td><td>\n";
6264 print "<div class=\"binary\">Binary file</div>\n";
6266 $ltext = untabify
($ltext);
6267 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6268 $ltext = esc_html
($1, -nbsp
=>1);
6269 $ltext .= '<span class="match">';
6270 $ltext .= esc_html
($2, -nbsp
=>1);
6271 $ltext .= '</span>';
6272 $ltext .= esc_html
($3, -nbsp
=>1);
6274 $ltext = esc_html
($ltext, -nbsp
=>1);
6276 print "<div class=\"pre\">" .
6277 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6278 file_name
=>"$file").'#l'.$lno,
6279 -class => "linenr"}, sprintf('%4i', $lno))
6280 . ' ' . $ltext . "</div>\n";
6284 print "</td></tr>\n";
6285 if ($matches > 1000) {
6286 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6289 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6298 sub git_search_help
{
6300 git_print_page_nav
('','', $hash,$hash,$hash);
6302 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6303 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6304 the pattern entered is recognized as the POSIX extended
6305 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6308 <dt><b>commit</b></dt>
6309 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6311 my $have_grep = gitweb_check_feature
('grep');
6314 <dt><b>grep</b></dt>
6315 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6316 a different one) are searched for the given pattern. On large trees, this search can take
6317 a while and put some strain on the server, so please use it with some consideration. Note that
6318 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6319 case-sensitive.</dd>
6323 <dt><b>author</b></dt>
6324 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6325 <dt><b>committer</b></dt>
6326 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6328 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6329 if ($have_pickaxe) {
6331 <dt><b>pickaxe</b></dt>
6332 <dd>All commits that caused the string to appear or disappear from any file (changes that
6333 added, removed or "modified" the string) will be listed. This search can take a while and
6334 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6335 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6343 my $head = git_get_head_hash
($project);
6344 if (!defined $hash) {
6347 if (!defined $page) {
6350 my $refs = git_get_references
();
6352 my $commit_hash = $hash;
6353 if (defined $hash_parent) {
6354 $commit_hash = "$hash_parent..$hash";
6356 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6358 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6360 if ($#commitlist >= 100) {
6362 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6363 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6365 my $patch_max = gitweb_check_feature
('patches');
6367 if ($patch_max < 0 || @commitlist <= $patch_max) {
6368 $paging_nav .= " ⋅ " .
6369 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6375 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6376 git_print_header_div
('summary', $project);
6378 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6383 ## ......................................................................
6384 ## feeds (RSS, Atom; OPML)
6387 my $format = shift || 'atom';
6388 my $have_blame = gitweb_check_feature
('blame');
6390 # Atom: http://www.atomenabled.org/developers/syndication/
6391 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6392 if ($format ne 'rss' && $format ne 'atom') {
6393 die_error
(400, "Unknown web feed format");
6396 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6397 my $head = $hash || 'HEAD';
6398 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6402 my $content_type = "application/$format+xml";
6403 if (defined $cgi->http('HTTP_ACCEPT') &&
6404 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6405 # browser (feed reader) prefers text/xml
6406 $content_type = 'text/xml';
6408 if (defined($commitlist[0])) {
6409 %latest_commit = %{$commitlist[0]};
6410 my $latest_epoch = $latest_commit{'committer_epoch'};
6411 %latest_date = parse_date
($latest_epoch);
6412 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6413 if (defined $if_modified) {
6415 if (eval { require HTTP
::Date
; 1; }) {
6416 $since = HTTP
::Date
::str2time
($if_modified);
6417 } elsif (eval { require Time
::ParseDate
; 1; }) {
6418 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6420 if (defined $since && $latest_epoch <= $since) {
6422 -type
=> $content_type,
6423 -charset
=> 'utf-8',
6424 -last_modified
=> $latest_date{'rfc2822'},
6425 -status
=> '304 Not Modified');
6430 -type
=> $content_type,
6431 -charset
=> 'utf-8',
6432 -last_modified
=> $latest_date{'rfc2822'});
6435 -type
=> $content_type,
6436 -charset
=> 'utf-8');
6439 # Optimization: skip generating the body if client asks only
6440 # for Last-Modified date.
6441 return if ($cgi->request_method() eq 'HEAD');
6444 my $title = "$site_name - $project/$action";
6445 my $feed_type = 'log';
6446 if (defined $hash) {
6447 $title .= " - '$hash'";
6448 $feed_type = 'branch log';
6449 if (defined $file_name) {
6450 $title .= " :: $file_name";
6451 $feed_type = 'history';
6453 } elsif (defined $file_name) {
6454 $title .= " - $file_name";
6455 $feed_type = 'history';
6457 $title .= " $feed_type";
6458 my $descr = git_get_project_description
($project);
6459 if (defined $descr) {
6460 $descr = esc_html
($descr);
6462 $descr = "$project " .
6463 ($format eq 'rss' ?
'RSS' : 'Atom') .
6466 my $owner = git_get_project_owner
($project);
6467 $owner = esc_html
($owner);
6471 if (defined $file_name) {
6472 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6473 } elsif (defined $hash) {
6474 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6476 $alt_url = href
(-full
=>1, action
=>"summary");
6478 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6479 if ($format eq 'rss') {
6481 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6484 print "<title>$title</title>\n" .
6485 "<link>$alt_url</link>\n" .
6486 "<description>$descr</description>\n" .
6487 "<language>en</language>\n" .
6488 # project owner is responsible for 'editorial' content
6489 "<managingEditor>$owner</managingEditor>\n";
6490 if (defined $logo || defined $favicon) {
6491 # prefer the logo to the favicon, since RSS
6492 # doesn't allow both
6493 my $img = esc_url
($logo || $favicon);
6495 "<url>$img</url>\n" .
6496 "<title>$title</title>\n" .
6497 "<link>$alt_url</link>\n" .
6501 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6502 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6504 print "<generator>gitweb v.$version/$git_version</generator>\n";
6505 } elsif ($format eq 'atom') {
6507 <feed xmlns="http://www.w3.org/2005/Atom">
6509 print "<title>$title</title>\n" .
6510 "<subtitle>$descr</subtitle>\n" .
6511 '<link rel="alternate" type="text/html" href="' .
6512 $alt_url . '" />' . "\n" .
6513 '<link rel="self" type="' . $content_type . '" href="' .
6514 $cgi->self_url() . '" />' . "\n" .
6515 "<id>" . href
(-full
=>1) . "</id>\n" .
6516 # use project owner for feed author
6517 "<author><name>$owner</name></author>\n";
6518 if (defined $favicon) {
6519 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6521 if (defined $logo_url) {
6522 # not twice as wide as tall: 72 x 27 pixels
6523 print "<logo>" . esc_url
($logo) . "</logo>\n";
6525 if (! %latest_date) {
6526 # dummy date to keep the feed valid until commits trickle in:
6527 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6529 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6531 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6535 for (my $i = 0; $i <= $#commitlist; $i++) {
6536 my %co = %{$commitlist[$i]};
6537 my $commit = $co{'id'};
6538 # we read 150, we always show 30 and the ones more recent than 48 hours
6539 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6542 my %cd = parse_date
($co{'author_epoch'});
6544 # get list of changed files
6545 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6546 $co{'parent'} || "--root",
6547 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6549 my @difftree = map { chomp; $_ } <$fd>;
6553 # print element (entry, item)
6554 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6555 if ($format eq 'rss') {
6557 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6558 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6559 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6560 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6561 "<link>$co_url</link>\n" .
6562 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6563 "<content:encoded>" .
6565 } elsif ($format eq 'atom') {
6567 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6568 "<updated>$cd{'iso-8601'}</updated>\n" .
6570 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6571 if ($co{'author_email'}) {
6572 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6574 print "</author>\n" .
6575 # use committer for contributor
6577 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6578 if ($co{'committer_email'}) {
6579 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6581 print "</contributor>\n" .
6582 "<published>$cd{'iso-8601'}</published>\n" .
6583 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6584 "<id>$co_url</id>\n" .
6585 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6586 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6588 my $comment = $co{'comment'};
6590 foreach my $line (@
$comment) {
6591 $line = esc_html
($line);
6594 print "</pre><ul>\n";
6595 foreach my $difftree_line (@difftree) {
6596 my %difftree = parse_difftree_raw_line
($difftree_line);
6597 next if !$difftree{'from_id'};
6599 my $file = $difftree{'file'} || $difftree{'to_file'};
6603 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6604 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6605 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6606 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6607 -title
=> "diff"}, 'D');
6609 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6610 file_name
=>$file, hash_base
=>$commit),
6611 -title
=> "blame"}, 'B');
6613 # if this is not a feed of a file history
6614 if (!defined $file_name || $file_name ne $file) {
6615 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6616 file_name
=>$file, hash
=>$commit),
6617 -title
=> "history"}, 'H');
6619 $file = esc_path
($file);
6623 if ($format eq 'rss') {
6624 print "</ul>]]>\n" .
6625 "</content:encoded>\n" .
6627 } elsif ($format eq 'atom') {
6628 print "</ul>\n</div>\n" .
6635 if ($format eq 'rss') {
6636 print "</channel>\n</rss>\n";
6637 } elsif ($format eq 'atom') {
6651 my @list = git_get_projects_list
();
6654 -type
=> 'text/xml',
6655 -charset
=> 'utf-8',
6656 -content_disposition
=> 'inline; filename="opml.xml"');
6659 <?xml version="1.0" encoding="utf-8"?>
6660 <opml version="1.0">
6662 <title>$site_name OPML Export</title>
6665 <outline text="git RSS feeds">
6668 foreach my $pr (@list) {
6670 my $head = git_get_head_hash
($proj{'path'});
6671 if (!defined $head) {
6674 $git_dir = "$projectroot/$proj{'path'}";
6675 my %co = parse_commit
($head);
6680 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6681 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6682 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6683 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";