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 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI-
>compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
33 our $my_url = $cgi->url();
34 our $my_uri = $cgi->url(-absolute
=> 1);
36 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
37 # needed and used only for URLs with nonempty PATH_INFO
38 our $base_url = $my_url;
40 # When the script is used as DirectoryIndex, the URL does not contain the name
41 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
42 # have to do it ourselves. We make $path_info global because it's also used
45 # Another issue with the script being the DirectoryIndex is that the resulting
46 # $my_url data is not the full script URL: this is good, because we want
47 # generated links to keep implying the script name if it wasn't explicitly
48 # indicated in the URL we're handling, but it means that $my_url cannot be used
50 # Therefore, if we needed to strip PATH_INFO, then we know that we have
51 # to build the base URL ourselves:
52 our $path_info = $ENV{"PATH_INFO"};
54 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
55 $my_uri =~ s
,\Q
$path_info\E
$,, &&
56 defined $ENV{'SCRIPT_NAME'}) {
57 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
61 # core git executable to use
62 # this can just be "git" if your webserver has a sensible PATH
63 our $GIT = "++GIT_BINDIR++/git";
65 # absolute fs-path which will be prepended to the project path
66 #our $projectroot = "/pub/scm";
67 our $projectroot = "++GITWEB_PROJECTROOT++";
69 # fs traversing limit for getting project list
70 # the number is relative to the projectroot
71 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
73 # target of the home link on top of all pages
74 our $home_link = $my_uri || "/";
76 # string of the home link on top of all pages
77 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
79 # name of your site or organization to appear in page titles
80 # replace this with something more descriptive for clearer bookmarks
81 our $site_name = "++GITWEB_SITENAME++"
82 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
84 # filename of html text to include at top of each page
85 our $site_header = "++GITWEB_SITE_HEADER++";
86 # html text to include at home page
87 our $home_text = "++GITWEB_HOMETEXT++";
88 # filename of html text to include at bottom of each page
89 our $site_footer = "++GITWEB_SITE_FOOTER++";
92 our @stylesheets = ("++GITWEB_CSS++");
93 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
94 our $stylesheet = undef;
96 # URI of GIT logo (72x27 size)
97 our $logo = "++GITWEB_LOGO++";
98 # URI of GIT favicon, assumed to be image/png type
99 our $favicon = "++GITWEB_FAVICON++";
100 # URI of gitweb.js (JavaScript code for gitweb)
101 our $javascript = "++GITWEB_JS++";
103 # URI and label (title) of GIT logo link
104 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
105 #our $logo_label = "git documentation";
106 our $logo_url = "http://git-scm.com/";
107 our $logo_label = "git homepage";
109 # source of projects list
110 our $projects_list = "++GITWEB_LIST++";
112 # the width (in characters) of the projects list "Description" column
113 our $projects_list_description_width = 25;
115 # default order of projects list
116 # valid values are none, project, descr, owner, and age
117 our $default_projects_order = "project";
119 # show repository only if this file exists
120 # (only effective if this variable evaluates to true)
121 our $export_ok = "++GITWEB_EXPORT_OK++";
123 # show repository only if this subroutine returns true
124 # when given the path to the project, for example:
125 # sub { return -e "$_[0]/git-daemon-export-ok"; }
126 our $export_auth_hook = undef;
128 # only allow viewing of repositories also shown on the overview page
129 our $strict_export = "++GITWEB_STRICT_EXPORT++";
131 # list of git base URLs used for URL to where fetch project from,
132 # i.e. full URL is "$git_base_url/$project"
133 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
135 # default blob_plain mimetype and default charset for text/plain blob
136 our $default_blob_plain_mimetype = 'text/plain';
137 our $default_text_plain_charset = undef;
139 # file to use for guessing MIME types before trying /etc/mime.types
140 # (relative to the current git repository)
141 our $mimetypes_file = undef;
143 # assume this charset if line contains non-UTF-8 characters;
144 # it should be valid encoding (see Encoding::Supported(3pm) for list),
145 # for which encoding all byte sequences are valid, for example
146 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
147 # could be even 'utf-8' for the old behavior)
148 our $fallback_encoding = 'latin1';
150 # rename detection options for git-diff and git-diff-tree
151 # - default is '-M', with the cost proportional to
152 # (number of removed files) * (number of new files).
153 # - more costly is '-C' (which implies '-M'), with the cost proportional to
154 # (number of changed files + number of removed files) * (number of new files)
155 # - even more costly is '-C', '--find-copies-harder' with cost
156 # (number of files in the original tree) * (number of new files)
157 # - one might want to include '-B' option, e.g. '-B', '-M'
158 our @diff_opts = ('-M'); # taken from git_commit
160 # Disables features that would allow repository owners to inject script into
162 our $prevent_xss = 0;
164 # information about snapshot formats that gitweb is capable of serving
165 our %known_snapshot_formats = (
167 # 'display' => display name,
168 # 'type' => mime type,
169 # 'suffix' => filename suffix,
170 # 'format' => --format for git-archive,
171 # 'compressor' => [compressor command and arguments]
172 # (array reference, optional)
173 # 'disabled' => boolean (optional)}
176 'display' => 'tar.gz',
177 'type' => 'application/x-gzip',
178 'suffix' => '.tar.gz',
180 'compressor' => ['gzip']},
183 'display' => 'tar.bz2',
184 'type' => 'application/x-bzip2',
185 'suffix' => '.tar.bz2',
187 'compressor' => ['bzip2']},
190 'display' => 'tar.xz',
191 'type' => 'application/x-xz',
192 'suffix' => '.tar.xz',
194 'compressor' => ['xz'],
199 'type' => 'application/x-zip',
204 # Aliases so we understand old gitweb.snapshot values in repository
206 our %known_snapshot_format_aliases = (
211 # backward compatibility: legacy gitweb config support
212 'x-gzip' => undef, 'gz' => undef,
213 'x-bzip2' => undef, 'bz2' => undef,
214 'x-zip' => undef, '' => undef,
217 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
218 # are changed, it may be appropriate to change these values too via
225 # Used to set the maximum load that we will still respond to gitweb queries.
226 # If server load exceed this value then return "503 server busy" error.
227 # If gitweb cannot determined server load, it is taken to be 0.
228 # Leave it undefined (or set to 'undef') to turn off load checking.
231 # You define site-wide feature defaults here; override them with
232 # $GITWEB_CONFIG as necessary.
235 # 'sub' => feature-sub (subroutine),
236 # 'override' => allow-override (boolean),
237 # 'default' => [ default options...] (array reference)}
239 # if feature is overridable (it means that allow-override has true value),
240 # then feature-sub will be called with default options as parameters;
241 # return value of feature-sub indicates if to enable specified feature
243 # if there is no 'sub' key (no feature-sub), then feature cannot be
246 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
247 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
250 # Enable the 'blame' blob view, showing the last commit that modified
251 # each line in the file. This can be very CPU-intensive.
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'blame'}{'default'} = [1];
255 # To have project specific config enable override in $GITWEB_CONFIG
256 # $feature{'blame'}{'override'} = 1;
257 # and in project config gitweb.blame = 0|1;
259 'sub' => sub { feature_bool
('blame', @_) },
263 # Enable the 'snapshot' link, providing a compressed archive of any
264 # tree. This can potentially generate high traffic if you have large
267 # Value is a list of formats defined in %known_snapshot_formats that
269 # To disable system wide have in $GITWEB_CONFIG
270 # $feature{'snapshot'}{'default'} = [];
271 # To have project specific config enable override in $GITWEB_CONFIG
272 # $feature{'snapshot'}{'override'} = 1;
273 # and in project config, a comma-separated list of formats or "none"
274 # to disable. Example: gitweb.snapshot = tbz2,zip;
276 'sub' => \
&feature_snapshot
,
278 'default' => ['tgz']},
280 # Enable text search, which will list the commits which match author,
281 # committer or commit text to a given string. Enabled by default.
282 # Project specific override is not supported.
287 # Enable grep search, which will list the files in currently selected
288 # tree containing the given string. Enabled by default. This can be
289 # potentially CPU-intensive, of course.
291 # To enable system wide have in $GITWEB_CONFIG
292 # $feature{'grep'}{'default'} = [1];
293 # To have project specific config enable override in $GITWEB_CONFIG
294 # $feature{'grep'}{'override'} = 1;
295 # and in project config gitweb.grep = 0|1;
297 'sub' => sub { feature_bool
('grep', @_) },
301 # Enable the pickaxe search, which will list the commits that modified
302 # a given string in a file. This can be practical and quite faster
303 # alternative to 'blame', but still potentially CPU-intensive.
305 # To enable system wide have in $GITWEB_CONFIG
306 # $feature{'pickaxe'}{'default'} = [1];
307 # To have project specific config enable override in $GITWEB_CONFIG
308 # $feature{'pickaxe'}{'override'} = 1;
309 # and in project config gitweb.pickaxe = 0|1;
311 'sub' => sub { feature_bool
('pickaxe', @_) },
315 # Enable showing size of blobs in a 'tree' view, in a separate
316 # column, similar to what 'ls -l' does. This cost a bit of IO.
318 # To disable system wide have in $GITWEB_CONFIG
319 # $feature{'show-sizes'}{'default'} = [0];
320 # To have project specific config enable override in $GITWEB_CONFIG
321 # $feature{'show-sizes'}{'override'} = 1;
322 # and in project config gitweb.showsizes = 0|1;
324 'sub' => sub { feature_bool
('showsizes', @_) },
328 # Make gitweb use an alternative format of the URLs which can be
329 # more readable and natural-looking: project name is embedded
330 # directly in the path and the query string contains other
331 # auxiliary information. All gitweb installations recognize
332 # URL in either format; this configures in which formats gitweb
335 # To enable system wide have in $GITWEB_CONFIG
336 # $feature{'pathinfo'}{'default'} = [1];
337 # Project specific override is not supported.
339 # Note that you will need to change the default location of CSS,
340 # favicon, logo and possibly other files to an absolute URL. Also,
341 # if gitweb.cgi serves as your indexfile, you will need to force
342 # $my_uri to contain the script name in your $GITWEB_CONFIG.
347 # Make gitweb consider projects in project root subdirectories
348 # to be forks of existing projects. Given project $projname.git,
349 # projects matching $projname/*.git will not be shown in the main
350 # projects list, instead a '+' mark will be added to $projname
351 # there and a 'forks' view will be enabled for the project, listing
352 # all the forks. If project list is taken from a file, forks have
353 # to be listed after the main project.
355 # To enable system wide have in $GITWEB_CONFIG
356 # $feature{'forks'}{'default'} = [1];
357 # Project specific override is not supported.
362 # Insert custom links to the action bar of all project pages.
363 # This enables you mainly to link to third-party scripts integrating
364 # into gitweb; e.g. git-browser for graphical history representation
365 # or custom web-based repository administration interface.
367 # The 'default' value consists of a list of triplets in the form
368 # (label, link, position) where position is the label after which
369 # to insert the link and link is a format string where %n expands
370 # to the project name, %f to the project path within the filesystem,
371 # %h to the current hash (h gitweb parameter) and %b to the current
372 # hash base (hb gitweb parameter); %% expands to %.
374 # To enable system wide have in $GITWEB_CONFIG e.g.
375 # $feature{'actions'}{'default'} = [('graphiclog',
376 # '/git-browser/by-commit.html?r=%n', 'summary')];
377 # Project specific override is not supported.
382 # Allow gitweb scan project content tags described in ctags/
383 # of project repository, and display the popular Web 2.0-ish
384 # "tag cloud" near the project list. Note that this is something
385 # COMPLETELY different from the normal Git tags.
387 # gitweb by itself can show existing tags, but it does not handle
388 # tagging itself; you need an external application for that.
389 # For an example script, check Girocco's cgi/tagproj.cgi.
390 # You may want to install the HTML::TagCloud Perl module to get
391 # a pretty tag cloud instead of just a list of tags.
393 # To enable system wide have in $GITWEB_CONFIG
394 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
395 # Project specific override is not supported.
400 # The maximum number of patches in a patchset generated in patch
401 # view. Set this to 0 or undef to disable patch view, or to a
402 # negative number to remove any limit.
404 # To disable system wide have in $GITWEB_CONFIG
405 # $feature{'patches'}{'default'} = [0];
406 # To have project specific config enable override in $GITWEB_CONFIG
407 # $feature{'patches'}{'override'} = 1;
408 # and in project config gitweb.patches = 0|n;
409 # where n is the maximum number of patches allowed in a patchset.
411 'sub' => \
&feature_patches
,
415 # Avatar support. When this feature is enabled, views such as
416 # shortlog or commit will display an avatar associated with
417 # the email of the committer(s) and/or author(s).
419 # Currently available providers are gravatar and picon.
420 # If an unknown provider is specified, the feature is disabled.
422 # Gravatar depends on Digest::MD5.
423 # Picon currently relies on the indiana.edu database.
425 # To enable system wide have in $GITWEB_CONFIG
426 # $feature{'avatar'}{'default'} = ['<provider>'];
427 # where <provider> is either gravatar or picon.
428 # To have project specific config enable override in $GITWEB_CONFIG
429 # $feature{'avatar'}{'override'} = 1;
430 # and in project config gitweb.avatar = <provider>;
432 'sub' => \
&feature_avatar
,
436 # Enable displaying how much time and how many git commands
437 # it took to generate and display page. Disabled by default.
438 # Project specific override is not supported.
443 # Enable turning some links into links to actions which require
444 # JavaScript to run (like 'blame_incremental'). Not enabled by
445 # default. Project specific override is currently not supported.
446 'javascript-actions' => {
451 sub gitweb_get_feature
{
453 return unless exists $feature{$name};
454 my ($sub, $override, @defaults) = (
455 $feature{$name}{'sub'},
456 $feature{$name}{'override'},
457 @{$feature{$name}{'default'}});
458 if (!$override) { return @defaults; }
460 warn "feature $name is not overridable";
463 return $sub->(@defaults);
466 # A wrapper to check if a given feature is enabled.
467 # With this, you can say
469 # my $bool_feat = gitweb_check_feature('bool_feat');
470 # gitweb_check_feature('bool_feat') or somecode;
474 # my ($bool_feat) = gitweb_get_feature('bool_feat');
475 # (gitweb_get_feature('bool_feat'))[0] or somecode;
477 sub gitweb_check_feature
{
478 return (gitweb_get_feature
(@_))[0];
484 my ($val) = git_get_project_config
($key, '--bool');
488 } elsif ($val eq 'true') {
490 } elsif ($val eq 'false') {
495 sub feature_snapshot
{
498 my ($val) = git_get_project_config
('snapshot');
501 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
507 sub feature_patches
{
508 my @val = (git_get_project_config
('patches', '--int'));
518 my @val = (git_get_project_config
('avatar'));
520 return @val ? @val : @_;
523 # checking HEAD file with -e is fragile if the repository was
524 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
526 sub check_head_link
{
528 my $headfile = "$dir/HEAD";
529 return ((-e
$headfile) ||
530 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
533 sub check_export_ok
{
535 return (check_head_link
($dir) &&
536 (!$export_ok || -e
"$dir/$export_ok") &&
537 (!$export_auth_hook || $export_auth_hook->($dir)));
540 # process alternate names for backward compatibility
541 # filter out unsupported (unknown) snapshot formats
542 sub filter_snapshot_fmts
{
546 exists $known_snapshot_format_aliases{$_} ?
547 $known_snapshot_format_aliases{$_} : $_} @fmts;
549 exists $known_snapshot_formats{$_} &&
550 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
553 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
554 if (-e
$GITWEB_CONFIG) {
557 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
558 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
561 # Get loadavg of system, to compare against $maxload.
562 # Currently it requires '/proc/loadavg' present to get loadavg;
563 # if it is not present it returns 0, which means no load checking.
565 if( -e
'/proc/loadavg' ){
566 open my $fd, '<', '/proc/loadavg'
568 my @load = split(/\s+/, scalar <$fd>);
571 # The first three columns measure CPU and IO utilization of the last one,
572 # five, and 10 minute periods. The fourth column shows the number of
573 # currently running processes and the total number of processes in the m/n
574 # format. The last column displays the last process ID used.
575 return $load[0] || 0;
577 # additional checks for load average should go here for things that don't export
583 # version of the core git binary
584 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
585 $number_of_git_cmds++;
587 $projects_list ||= $projectroot;
589 if (defined $maxload && get_loadavg
() > $maxload) {
590 die_error
(503, "The load average on the server is too high");
593 # ======================================================================
594 # input validation and dispatch
596 # input parameters can be collected from a variety of sources (presently, CGI
597 # and PATH_INFO), so we define an %input_params hash that collects them all
598 # together during validation: this allows subsequent uses (e.g. href()) to be
599 # agnostic of the parameter origin
601 our %input_params = ();
603 # input parameters are stored with the long parameter name as key. This will
604 # also be used in the href subroutine to convert parameters to their CGI
605 # equivalent, and since the href() usage is the most frequent one, we store
606 # the name -> CGI key mapping here, instead of the reverse.
608 # XXX: Warning: If you touch this, check the search form for updating,
611 our @cgi_param_mapping = (
619 hash_parent_base
=> "hpb",
624 snapshot_format
=> "sf",
625 extra_options
=> "opt",
626 search_use_regexp
=> "sr",
627 # this must be last entry (for manipulation from JavaScript)
630 our %cgi_param_mapping = @cgi_param_mapping;
632 # we will also need to know the possible actions, for validation
634 "blame" => \
&git_blame
,
635 "blame_incremental" => \
&git_blame_incremental
,
636 "blame_data" => \
&git_blame_data
,
637 "blobdiff" => \
&git_blobdiff
,
638 "blobdiff_plain" => \
&git_blobdiff_plain
,
639 "blob" => \
&git_blob
,
640 "blob_plain" => \
&git_blob_plain
,
641 "commitdiff" => \
&git_commitdiff
,
642 "commitdiff_plain" => \
&git_commitdiff_plain
,
643 "commit" => \
&git_commit
,
644 "forks" => \
&git_forks
,
645 "heads" => \
&git_heads
,
646 "history" => \
&git_history
,
648 "patch" => \
&git_patch
,
649 "patches" => \
&git_patches
,
651 "atom" => \
&git_atom
,
652 "search" => \
&git_search
,
653 "search_help" => \
&git_search_help
,
654 "shortlog" => \
&git_shortlog
,
655 "summary" => \
&git_summary
,
657 "tags" => \
&git_tags
,
658 "tree" => \
&git_tree
,
659 "snapshot" => \
&git_snapshot
,
660 "object" => \
&git_object
,
661 # those below don't need $project
662 "opml" => \
&git_opml
,
663 "project_list" => \
&git_project_list
,
664 "project_index" => \
&git_project_index
,
667 # finally, we have the hash of allowed extra_options for the commands that
669 our %allowed_options = (
670 "--no-merges" => [ qw(rss atom log shortlog history) ],
673 # fill %input_params with the CGI parameters. All values except for 'opt'
674 # should be single values, but opt can be an array. We should probably
675 # build an array of parameters that can be multi-valued, but since for the time
676 # being it's only this one, we just single it out
677 while (my ($name, $symbol) = each %cgi_param_mapping) {
678 if ($symbol eq 'opt') {
679 $input_params{$name} = [ $cgi->param($symbol) ];
681 $input_params{$name} = $cgi->param($symbol);
685 # now read PATH_INFO and update the parameter list for missing parameters
686 sub evaluate_path_info
{
687 return if defined $input_params{'project'};
688 return if !$path_info;
689 $path_info =~ s
,^/+,,;
690 return if !$path_info;
692 # find which part of PATH_INFO is project
693 my $project = $path_info;
695 while ($project && !check_head_link
("$projectroot/$project")) {
696 $project =~ s
,/*[^/]*$,,;
698 return unless $project;
699 $input_params{'project'} = $project;
701 # do not change any parameters if an action is given using the query string
702 return if $input_params{'action'};
703 $path_info =~ s
,^\Q
$project\E
/*,,;
705 # next, check if we have an action
706 my $action = $path_info;
708 if (exists $actions{$action}) {
709 $path_info =~ s
,^$action/*,,;
710 $input_params{'action'} = $action;
713 # list of actions that want hash_base instead of hash, but can have no
714 # pathname (f) parameter
721 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
722 my ($parentrefname, $parentpathname, $refname, $pathname) =
723 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
725 # first, analyze the 'current' part
726 if (defined $pathname) {
727 # we got "branch:filename" or "branch:dir/"
728 # we could use git_get_type(branch:pathname), but:
729 # - it needs $git_dir
730 # - it does a git() call
731 # - the convention of terminating directories with a slash
732 # makes it superfluous
733 # - embedding the action in the PATH_INFO would make it even
735 $pathname =~ s
,^/+,,;
736 if (!$pathname || substr($pathname, -1) eq "/") {
737 $input_params{'action'} ||= "tree";
740 # the default action depends on whether we had parent info
742 if ($parentrefname) {
743 $input_params{'action'} ||= "blobdiff_plain";
745 $input_params{'action'} ||= "blob_plain";
748 $input_params{'hash_base'} ||= $refname;
749 $input_params{'file_name'} ||= $pathname;
750 } elsif (defined $refname) {
751 # we got "branch". In this case we have to choose if we have to
752 # set hash or hash_base.
754 # Most of the actions without a pathname only want hash to be
755 # set, except for the ones specified in @wants_base that want
756 # hash_base instead. It should also be noted that hand-crafted
757 # links having 'history' as an action and no pathname or hash
758 # set will fail, but that happens regardless of PATH_INFO.
759 $input_params{'action'} ||= "shortlog";
760 if (grep { $_ eq $input_params{'action'} } @wants_base) {
761 $input_params{'hash_base'} ||= $refname;
763 $input_params{'hash'} ||= $refname;
767 # next, handle the 'parent' part, if present
768 if (defined $parentrefname) {
769 # a missing pathspec defaults to the 'current' filename, allowing e.g.
770 # someproject/blobdiff/oldrev..newrev:/filename
771 if ($parentpathname) {
772 $parentpathname =~ s
,^/+,,;
773 $parentpathname =~ s
,/$,,;
774 $input_params{'file_parent'} ||= $parentpathname;
776 $input_params{'file_parent'} ||= $input_params{'file_name'};
778 # we assume that hash_parent_base is wanted if a path was specified,
779 # or if the action wants hash_base instead of hash
780 if (defined $input_params{'file_parent'} ||
781 grep { $_ eq $input_params{'action'} } @wants_base) {
782 $input_params{'hash_parent_base'} ||= $parentrefname;
784 $input_params{'hash_parent'} ||= $parentrefname;
788 # for the snapshot action, we allow URLs in the form
789 # $project/snapshot/$hash.ext
790 # where .ext determines the snapshot and gets removed from the
791 # passed $refname to provide the $hash.
793 # To be able to tell that $refname includes the format extension, we
794 # require the following two conditions to be satisfied:
795 # - the hash input parameter MUST have been set from the $refname part
796 # of the URL (i.e. they must be equal)
797 # - the snapshot format MUST NOT have been defined already (e.g. from
799 # It's also useless to try any matching unless $refname has a dot,
800 # so we check for that too
801 if (defined $input_params{'action'} &&
802 $input_params{'action'} eq 'snapshot' &&
803 defined $refname && index($refname, '.') != -1 &&
804 $refname eq $input_params{'hash'} &&
805 !defined $input_params{'snapshot_format'}) {
806 # We loop over the known snapshot formats, checking for
807 # extensions. Allowed extensions are both the defined suffix
808 # (which includes the initial dot already) and the snapshot
809 # format key itself, with a prepended dot
810 while (my ($fmt, $opt) = each %known_snapshot_formats) {
812 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
816 # a valid suffix was found, so set the snapshot format
817 # and reset the hash parameter
818 $input_params{'snapshot_format'} = $fmt;
819 $input_params{'hash'} = $hash;
820 # we also set the format suffix to the one requested
821 # in the URL: this way a request for e.g. .tgz returns
822 # a .tgz instead of a .tar.gz
823 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
828 evaluate_path_info
();
830 our $action = $input_params{'action'};
831 if (defined $action) {
832 if (!validate_action
($action)) {
833 die_error
(400, "Invalid action parameter");
837 # parameters which are pathnames
838 our $project = $input_params{'project'};
839 if (defined $project) {
840 if (!validate_project
($project)) {
842 die_error
(404, "No such project");
846 our $file_name = $input_params{'file_name'};
847 if (defined $file_name) {
848 if (!validate_pathname
($file_name)) {
849 die_error
(400, "Invalid file parameter");
853 our $file_parent = $input_params{'file_parent'};
854 if (defined $file_parent) {
855 if (!validate_pathname
($file_parent)) {
856 die_error
(400, "Invalid file parent parameter");
860 # parameters which are refnames
861 our $hash = $input_params{'hash'};
863 if (!validate_refname
($hash)) {
864 die_error
(400, "Invalid hash parameter");
868 our $hash_parent = $input_params{'hash_parent'};
869 if (defined $hash_parent) {
870 if (!validate_refname
($hash_parent)) {
871 die_error
(400, "Invalid hash parent parameter");
875 our $hash_base = $input_params{'hash_base'};
876 if (defined $hash_base) {
877 if (!validate_refname
($hash_base)) {
878 die_error
(400, "Invalid hash base parameter");
882 our @extra_options = @{$input_params{'extra_options'}};
883 # @extra_options is always defined, since it can only be (currently) set from
884 # CGI, and $cgi->param() returns the empty array in array context if the param
886 foreach my $opt (@extra_options) {
887 if (not exists $allowed_options{$opt}) {
888 die_error
(400, "Invalid option parameter");
890 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
891 die_error
(400, "Invalid option parameter for this action");
895 our $hash_parent_base = $input_params{'hash_parent_base'};
896 if (defined $hash_parent_base) {
897 if (!validate_refname
($hash_parent_base)) {
898 die_error
(400, "Invalid hash parent base parameter");
903 our $page = $input_params{'page'};
905 if ($page =~ m/[^0-9]/) {
906 die_error
(400, "Invalid page parameter");
910 our $searchtype = $input_params{'searchtype'};
911 if (defined $searchtype) {
912 if ($searchtype =~ m/[^a-z]/) {
913 die_error
(400, "Invalid searchtype parameter");
917 our $search_use_regexp = $input_params{'search_use_regexp'};
919 our $searchtext = $input_params{'searchtext'};
921 if (defined $searchtext) {
922 if (length($searchtext) < 2) {
923 die_error
(403, "At least two characters are required for search parameter");
925 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
928 # path to the current git repository
930 $git_dir = "$projectroot/$project" if $project;
932 # list of supported snapshot formats
933 our @snapshot_fmts = gitweb_get_feature
('snapshot');
934 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
936 # check that the avatar feature is set to a known provider name,
937 # and for each provider check if the dependencies are satisfied.
938 # if the provider name is invalid or the dependencies are not met,
939 # reset $git_avatar to the empty string.
940 our ($git_avatar) = gitweb_get_feature
('avatar');
941 if ($git_avatar eq 'gravatar') {
942 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
943 } elsif ($git_avatar eq 'picon') {
950 if (!defined $action) {
952 $action = git_get_type
($hash);
953 } elsif (defined $hash_base && defined $file_name) {
954 $action = git_get_type
("$hash_base:$file_name");
955 } elsif (defined $project) {
958 $action = 'project_list';
961 if (!defined($actions{$action})) {
962 die_error
(400, "Unknown action");
964 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
966 die_error
(400, "Project needed");
968 $actions{$action}->();
971 ## ======================================================================
976 # default is to use -absolute url() i.e. $my_uri
977 my $href = $params{-full
} ? $my_url : $my_uri;
979 $params{'project'} = $project unless exists $params{'project'};
981 if ($params{-replay
}) {
982 while (my ($name, $symbol) = each %cgi_param_mapping) {
983 if (!exists $params{$name}) {
984 $params{$name} = $input_params{$name};
989 my $use_pathinfo = gitweb_check_feature
('pathinfo');
990 if ($use_pathinfo and defined $params{'project'}) {
991 # try to put as many parameters as possible in PATH_INFO:
994 # - hash_parent or hash_parent_base:/file_parent
995 # - hash or hash_base:/filename
996 # - the snapshot_format as an appropriate suffix
998 # When the script is the root DirectoryIndex for the domain,
999 # $href here would be something like http://gitweb.example.com/
1000 # Thus, we strip any trailing / from $href, to spare us double
1001 # slashes in the final URL
1004 # Then add the project name, if present
1005 $href .= "/".esc_url
($params{'project'});
1006 delete $params{'project'};
1008 # since we destructively absorb parameters, we keep this
1009 # boolean that remembers if we're handling a snapshot
1010 my $is_snapshot = $params{'action'} eq 'snapshot';
1012 # Summary just uses the project path URL, any other action is
1014 if (defined $params{'action'}) {
1015 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1016 delete $params{'action'};
1019 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1020 # stripping nonexistent or useless pieces
1021 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1022 || $params{'hash_parent'} || $params{'hash'});
1023 if (defined $params{'hash_base'}) {
1024 if (defined $params{'hash_parent_base'}) {
1025 $href .= esc_url
($params{'hash_parent_base'});
1026 # skip the file_parent if it's the same as the file_name
1027 if (defined $params{'file_parent'}) {
1028 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1029 delete $params{'file_parent'};
1030 } elsif ($params{'file_parent'} !~ /\.\./) {
1031 $href .= ":/".esc_url
($params{'file_parent'});
1032 delete $params{'file_parent'};
1036 delete $params{'hash_parent'};
1037 delete $params{'hash_parent_base'};
1038 } elsif (defined $params{'hash_parent'}) {
1039 $href .= esc_url
($params{'hash_parent'}). "..";
1040 delete $params{'hash_parent'};
1043 $href .= esc_url
($params{'hash_base'});
1044 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1045 $href .= ":/".esc_url
($params{'file_name'});
1046 delete $params{'file_name'};
1048 delete $params{'hash'};
1049 delete $params{'hash_base'};
1050 } elsif (defined $params{'hash'}) {
1051 $href .= esc_url
($params{'hash'});
1052 delete $params{'hash'};
1055 # If the action was a snapshot, we can absorb the
1056 # snapshot_format parameter too
1058 my $fmt = $params{'snapshot_format'};
1059 # snapshot_format should always be defined when href()
1060 # is called, but just in case some code forgets, we
1061 # fall back to the default
1062 $fmt ||= $snapshot_fmts[0];
1063 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1064 delete $params{'snapshot_format'};
1068 # now encode the parameters explicitly
1070 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1071 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1072 if (defined $params{$name}) {
1073 if (ref($params{$name}) eq "ARRAY") {
1074 foreach my $par (@{$params{$name}}) {
1075 push @result, $symbol . "=" . esc_param
($par);
1078 push @result, $symbol . "=" . esc_param
($params{$name});
1082 $href .= "?" . join(';', @result) if scalar @result;
1088 ## ======================================================================
1089 ## validation, quoting/unquoting and escaping
1091 sub validate_action
{
1092 my $input = shift || return undef;
1093 return undef unless exists $actions{$input};
1097 sub validate_project
{
1098 my $input = shift || return undef;
1099 if (!validate_pathname
($input) ||
1100 !(-d
"$projectroot/$input") ||
1101 !check_export_ok
("$projectroot/$input") ||
1102 ($strict_export && !project_in_list
($input))) {
1109 sub validate_pathname
{
1110 my $input = shift || return undef;
1112 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1113 # at the beginning, at the end, and between slashes.
1114 # also this catches doubled slashes
1115 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1118 # no null characters
1119 if ($input =~ m!\0!) {
1125 sub validate_refname
{
1126 my $input = shift || return undef;
1128 # textual hashes are O.K.
1129 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1132 # it must be correct pathname
1133 $input = validate_pathname
($input)
1135 # restrictions on ref name according to git-check-ref-format
1136 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1142 # decode sequences of octets in utf8 into Perl's internal form,
1143 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1144 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1147 if (utf8
::valid
($str)) {
1151 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1155 # quote unsafe chars, but keep the slash, even when it's not
1156 # correct, but quoted slashes look too horrible in bookmarks
1159 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1164 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1167 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1173 # replace invalid utf8 character with SUBSTITUTION sequence
1178 $str = to_utf8
($str);
1179 $str = $cgi->escapeHTML($str);
1180 if ($opts{'-nbsp'}) {
1181 $str =~ s/ / /g;
1183 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1187 # quote control characters and escape filename to HTML
1192 $str = to_utf8
($str);
1193 $str = $cgi->escapeHTML($str);
1194 if ($opts{'-nbsp'}) {
1195 $str =~ s/ / /g;
1197 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1201 # Make control characters "printable", using character escape codes (CEC)
1205 my %es = ( # character escape codes, aka escape sequences
1206 "\t" => '\t', # tab (HT)
1207 "\n" => '\n', # line feed (LF)
1208 "\r" => '\r', # carrige return (CR)
1209 "\f" => '\f', # form feed (FF)
1210 "\b" => '\b', # backspace (BS)
1211 "\a" => '\a', # alarm (bell) (BEL)
1212 "\e" => '\e', # escape (ESC)
1213 "\013" => '\v', # vertical tab (VT)
1214 "\000" => '\0', # nul character (NUL)
1216 my $chr = ( (exists $es{$cntrl})
1218 : sprintf('\%2x', ord($cntrl)) );
1219 if ($opts{-nohtml
}) {
1222 return "<span class=\"cntrl\">$chr</span>";
1226 # Alternatively use unicode control pictures codepoints,
1227 # Unicode "printable representation" (PR)
1232 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1233 if ($opts{-nohtml
}) {
1236 return "<span class=\"cntrl\">$chr</span>";
1240 # git may return quoted and escaped filenames
1246 my %es = ( # character escape codes, aka escape sequences
1247 't' => "\t", # tab (HT, TAB)
1248 'n' => "\n", # newline (NL)
1249 'r' => "\r", # return (CR)
1250 'f' => "\f", # form feed (FF)
1251 'b' => "\b", # backspace (BS)
1252 'a' => "\a", # alarm (bell) (BEL)
1253 'e' => "\e", # escape (ESC)
1254 'v' => "\013", # vertical tab (VT)
1257 if ($seq =~ m/^[0-7]{1,3}$/) {
1258 # octal char sequence
1259 return chr(oct($seq));
1260 } elsif (exists $es{$seq}) {
1261 # C escape sequence, aka character escape code
1264 # quoted ordinary character
1268 if ($str =~ m/^"(.*)"$/) {
1271 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1276 # escape tabs (convert tabs to spaces)
1280 while ((my $pos = index($line, "\t")) != -1) {
1281 if (my $count = (8 - ($pos % 8))) {
1282 my $spaces = ' ' x
$count;
1283 $line =~ s/\t/$spaces/;
1290 sub project_in_list
{
1291 my $project = shift;
1292 my @list = git_get_projects_list
();
1293 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1296 ## ----------------------------------------------------------------------
1297 ## HTML aware string manipulation
1299 # Try to chop given string on a word boundary between position
1300 # $len and $len+$add_len. If there is no word boundary there,
1301 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1302 # (marking chopped part) would be longer than given string.
1306 my $add_len = shift || 10;
1307 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1309 # Make sure perl knows it is utf8 encoded so we don't
1310 # cut in the middle of a utf8 multibyte char.
1311 $str = to_utf8
($str);
1313 # allow only $len chars, but don't cut a word if it would fit in $add_len
1314 # if it doesn't fit, cut it if it's still longer than the dots we would add
1315 # remove chopped character entities entirely
1317 # when chopping in the middle, distribute $len into left and right part
1318 # return early if chopping wouldn't make string shorter
1319 if ($where eq 'center') {
1320 return $str if ($len + 5 >= length($str)); # filler is length 5
1323 return $str if ($len + 4 >= length($str)); # filler is length 4
1326 # regexps: ending and beginning with word part up to $add_len
1327 my $endre = qr/.{$len}\w{0,$add_len}/;
1328 my $begre = qr/\w{0,$add_len}.{$len}/;
1330 if ($where eq 'left') {
1331 $str =~ m/^(.*?)($begre)$/;
1332 my ($lead, $body) = ($1, $2);
1333 if (length($lead) > 4) {
1334 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1337 return "$lead$body";
1339 } elsif ($where eq 'center') {
1340 $str =~ m/^($endre)(.*)$/;
1341 my ($left, $str) = ($1, $2);
1342 $str =~ m/^(.*?)($begre)$/;
1343 my ($mid, $right) = ($1, $2);
1344 if (length($mid) > 5) {
1345 $left =~ s/&[^;]*$//;
1346 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1349 return "$left$mid$right";
1352 $str =~ m/^($endre)(.*)$/;
1355 if (length($tail) > 4) {
1356 $body =~ s/&[^;]*$//;
1359 return "$body$tail";
1363 # takes the same arguments as chop_str, but also wraps a <span> around the
1364 # result with a title attribute if it does get chopped. Additionally, the
1365 # string is HTML-escaped.
1366 sub chop_and_escape_str
{
1369 my $chopped = chop_str
(@_);
1370 if ($chopped eq $str) {
1371 return esc_html
($chopped);
1373 $str =~ s/[[:cntrl:]]/?/g;
1374 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1378 ## ----------------------------------------------------------------------
1379 ## functions returning short strings
1381 # CSS class for given age value (in seconds)
1385 if (!defined $age) {
1387 } elsif ($age < 60*60*2) {
1389 } elsif ($age < 60*60*24*2) {
1396 # convert age in seconds to "nn units ago" string
1401 if ($age > 60*60*24*365*2) {
1402 $age_str = (int $age/60/60/24/365);
1403 $age_str .= " years ago";
1404 } elsif ($age > 60*60*24*(365/12)*2) {
1405 $age_str = int $age/60/60/24/(365/12);
1406 $age_str .= " months ago";
1407 } elsif ($age > 60*60*24*7*2) {
1408 $age_str = int $age/60/60/24/7;
1409 $age_str .= " weeks ago";
1410 } elsif ($age > 60*60*24*2) {
1411 $age_str = int $age/60/60/24;
1412 $age_str .= " days ago";
1413 } elsif ($age > 60*60*2) {
1414 $age_str = int $age/60/60;
1415 $age_str .= " hours ago";
1416 } elsif ($age > 60*2) {
1417 $age_str = int $age/60;
1418 $age_str .= " min ago";
1419 } elsif ($age > 2) {
1420 $age_str = int $age;
1421 $age_str .= " sec ago";
1423 $age_str .= " right now";
1429 S_IFINVALID
=> 0030000,
1430 S_IFGITLINK
=> 0160000,
1433 # submodule/subproject, a commit object reference
1437 return (($mode & S_IFMT
) == S_IFGITLINK
)
1440 # convert file mode in octal to symbolic file mode string
1442 my $mode = oct shift;
1444 if (S_ISGITLINK
($mode)) {
1445 return 'm---------';
1446 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1447 return 'drwxr-xr-x';
1448 } elsif (S_ISLNK
($mode)) {
1449 return 'lrwxrwxrwx';
1450 } elsif (S_ISREG
($mode)) {
1451 # git cares only about the executable bit
1452 if ($mode & S_IXUSR
) {
1453 return '-rwxr-xr-x';
1455 return '-rw-r--r--';
1458 return '----------';
1462 # convert file mode in octal to file type string
1466 if ($mode !~ m/^[0-7]+$/) {
1472 if (S_ISGITLINK
($mode)) {
1474 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1476 } elsif (S_ISLNK
($mode)) {
1478 } elsif (S_ISREG
($mode)) {
1485 # convert file mode in octal to file type description string
1486 sub file_type_long
{
1489 if ($mode !~ m/^[0-7]+$/) {
1495 if (S_ISGITLINK
($mode)) {
1497 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1499 } elsif (S_ISLNK
($mode)) {
1501 } elsif (S_ISREG
($mode)) {
1502 if ($mode & S_IXUSR
) {
1503 return "executable";
1513 ## ----------------------------------------------------------------------
1514 ## functions returning short HTML fragments, or transforming HTML fragments
1515 ## which don't belong to other sections
1517 # format line of commit message.
1518 sub format_log_line_html
{
1521 $line = esc_html
($line, -nbsp
=>1);
1522 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1523 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1524 -class => "text"}, $1);
1530 # format marker of refs pointing to given object
1532 # the destination action is chosen based on object type and current context:
1533 # - for annotated tags, we choose the tag view unless it's the current view
1534 # already, in which case we go to shortlog view
1535 # - for other refs, we keep the current view if we're in history, shortlog or
1536 # log view, and select shortlog otherwise
1537 sub format_ref_marker
{
1538 my ($refs, $id) = @_;
1541 if (defined $refs->{$id}) {
1542 foreach my $ref (@{$refs->{$id}}) {
1543 # this code exploits the fact that non-lightweight tags are the
1544 # only indirect objects, and that they are the only objects for which
1545 # we want to use tag instead of shortlog as action
1546 my ($type, $name) = qw();
1547 my $indirect = ($ref =~ s/\^\{\}$//);
1548 # e.g. tags/v2.6.11 or heads/next
1549 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1558 $class .= " indirect" if $indirect;
1560 my $dest_action = "shortlog";
1563 $dest_action = "tag" unless $action eq "tag";
1564 } elsif ($action =~ /^(history|(short)?log)$/) {
1565 $dest_action = $action;
1569 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1572 my $link = $cgi->a({
1574 action
=>$dest_action,
1578 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1584 return ' <span class="refs">'. $markers . '</span>';
1590 # format, perhaps shortened and with markers, title line
1591 sub format_subject_html
{
1592 my ($long, $short, $href, $extra) = @_;
1593 $extra = '' unless defined($extra);
1595 if (length($short) < length($long)) {
1596 $long =~ s/[[:cntrl:]]/?/g;
1597 return $cgi->a({-href
=> $href, -class => "list subject",
1598 -title
=> to_utf8
($long)},
1599 esc_html
($short)) . $extra;
1601 return $cgi->a({-href
=> $href, -class => "list subject"},
1602 esc_html
($long)) . $extra;
1606 # Rather than recomputing the url for an email multiple times, we cache it
1607 # after the first hit. This gives a visible benefit in views where the avatar
1608 # for the same email is used repeatedly (e.g. shortlog).
1609 # The cache is shared by all avatar engines (currently gravatar only), which
1610 # are free to use it as preferred. Since only one avatar engine is used for any
1611 # given page, there's no risk for cache conflicts.
1612 our %avatar_cache = ();
1614 # Compute the picon url for a given email, by using the picon search service over at
1615 # http://www.cs.indiana.edu/picons/search.html
1617 my $email = lc shift;
1618 if (!$avatar_cache{$email}) {
1619 my ($user, $domain) = split('@', $email);
1620 $avatar_cache{$email} =
1621 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1623 "users+domains+unknown/up/single";
1625 return $avatar_cache{$email};
1628 # Compute the gravatar url for a given email, if it's not in the cache already.
1629 # Gravatar stores only the part of the URL before the size, since that's the
1630 # one computationally more expensive. This also allows reuse of the cache for
1631 # different sizes (for this particular engine).
1633 my $email = lc shift;
1635 $avatar_cache{$email} ||=
1636 "http://www.gravatar.com/avatar/" .
1637 Digest
::MD5
::md5_hex
($email) . "?s=";
1638 return $avatar_cache{$email} . $size;
1641 # Insert an avatar for the given $email at the given $size if the feature
1643 sub git_get_avatar
{
1644 my ($email, %opts) = @_;
1645 my $pre_white = ($opts{-pad_before
} ? " " : "");
1646 my $post_white = ($opts{-pad_after
} ? " " : "");
1647 $opts{-size
} ||= 'default';
1648 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1650 if ($git_avatar eq 'gravatar') {
1651 $url = gravatar_url
($email, $size);
1652 } elsif ($git_avatar eq 'picon') {
1653 $url = picon_url
($email);
1655 # Other providers can be added by extending the if chain, defining $url
1656 # as needed. If no variant puts something in $url, we assume avatars
1657 # are completely disabled/unavailable.
1660 "<img width=\"$size\" " .
1661 "class=\"avatar\" " .
1670 sub format_search_author
{
1671 my ($author, $searchtype, $displaytext) = @_;
1672 my $have_search = gitweb_check_feature
('search');
1676 if ($searchtype eq 'author') {
1677 $performed = "authored";
1678 } elsif ($searchtype eq 'committer') {
1679 $performed = "committed";
1682 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1683 searchtext
=>$author,
1684 searchtype
=>$searchtype), class=>"list",
1685 title
=>"Search for commits $performed by $author"},
1689 return $displaytext;
1693 # format the author name of the given commit with the given tag
1694 # the author name is chopped and escaped according to the other
1695 # optional parameters (see chop_str).
1696 sub format_author_html
{
1699 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1700 return "<$tag class=\"author\">" .
1701 format_search_author
($co->{'author_name'}, "author",
1702 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1707 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1708 sub format_git_diff_header_line
{
1710 my $diffinfo = shift;
1711 my ($from, $to) = @_;
1713 if ($diffinfo->{'nparents'}) {
1715 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1716 if ($to->{'href'}) {
1717 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1718 esc_path
($to->{'file'}));
1719 } else { # file was deleted (no href)
1720 $line .= esc_path
($to->{'file'});
1724 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1725 if ($from->{'href'}) {
1726 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1727 'a/' . esc_path
($from->{'file'}));
1728 } else { # file was added (no href)
1729 $line .= 'a/' . esc_path
($from->{'file'});
1732 if ($to->{'href'}) {
1733 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1734 'b/' . esc_path
($to->{'file'}));
1735 } else { # file was deleted
1736 $line .= 'b/' . esc_path
($to->{'file'});
1740 return "<div class=\"diff header\">$line</div>\n";
1743 # format extended diff header line, before patch itself
1744 sub format_extended_diff_header_line
{
1746 my $diffinfo = shift;
1747 my ($from, $to) = @_;
1750 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1751 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1752 esc_path
($from->{'file'}));
1754 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1755 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1756 esc_path
($to->{'file'}));
1758 # match single <mode>
1759 if ($line =~ m/\s(\d{6})$/) {
1760 $line .= '<span class="info"> (' .
1761 file_type_long
($1) .
1765 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1766 # can match only for combined diff
1768 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1769 if ($from->{'href'}[$i]) {
1770 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1772 substr($diffinfo->{'from_id'}[$i],0,7));
1777 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1780 if ($to->{'href'}) {
1781 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1782 substr($diffinfo->{'to_id'},0,7));
1787 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1788 # can match only for ordinary diff
1789 my ($from_link, $to_link);
1790 if ($from->{'href'}) {
1791 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1792 substr($diffinfo->{'from_id'},0,7));
1794 $from_link = '0' x
7;
1796 if ($to->{'href'}) {
1797 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1798 substr($diffinfo->{'to_id'},0,7));
1802 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1803 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1806 return $line . "<br/>\n";
1809 # format from-file/to-file diff header
1810 sub format_diff_from_to_header
{
1811 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1816 #assert($line =~ m/^---/) if DEBUG;
1817 # no extra formatting for "^--- /dev/null"
1818 if (! $diffinfo->{'nparents'}) {
1819 # ordinary (single parent) diff
1820 if ($line =~ m!^--- "?a/!) {
1821 if ($from->{'href'}) {
1823 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1824 esc_path
($from->{'file'}));
1827 esc_path
($from->{'file'});
1830 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1833 # combined diff (merge commit)
1834 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1835 if ($from->{'href'}[$i]) {
1837 $cgi->a({-href
=>href
(action
=>"blobdiff",
1838 hash_parent
=>$diffinfo->{'from_id'}[$i],
1839 hash_parent_base
=>$parents[$i],
1840 file_parent
=>$from->{'file'}[$i],
1841 hash
=>$diffinfo->{'to_id'},
1843 file_name
=>$to->{'file'}),
1845 -title
=>"diff" . ($i+1)},
1848 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1849 esc_path
($from->{'file'}[$i]));
1851 $line = '--- /dev/null';
1853 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1858 #assert($line =~ m/^\+\+\+/) if DEBUG;
1859 # no extra formatting for "^+++ /dev/null"
1860 if ($line =~ m!^\+\+\+ "?b/!) {
1861 if ($to->{'href'}) {
1863 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1864 esc_path
($to->{'file'}));
1867 esc_path
($to->{'file'});
1870 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1875 # create note for patch simplified by combined diff
1876 sub format_diff_cc_simplified
{
1877 my ($diffinfo, @parents) = @_;
1880 $result .= "<div class=\"diff header\">" .
1882 if (!is_deleted
($diffinfo)) {
1883 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1885 hash
=>$diffinfo->{'to_id'},
1886 file_name
=>$diffinfo->{'to_file'}),
1888 esc_path
($diffinfo->{'to_file'}));
1890 $result .= esc_path
($diffinfo->{'to_file'});
1892 $result .= "</div>\n" . # class="diff header"
1893 "<div class=\"diff nodifferences\">" .
1895 "</div>\n"; # class="diff nodifferences"
1900 # format patch (diff) line (not to be used for diff headers)
1901 sub format_diff_line
{
1903 my ($from, $to) = @_;
1904 my $diff_class = "";
1908 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1910 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1911 if ($line =~ m/^\@{3}/) {
1912 $diff_class = " chunk_header";
1913 } elsif ($line =~ m/^\\/) {
1914 $diff_class = " incomplete";
1915 } elsif ($prefix =~ tr/+/+/) {
1916 $diff_class = " add";
1917 } elsif ($prefix =~ tr/-/-/) {
1918 $diff_class = " rem";
1921 # assume ordinary diff
1922 my $char = substr($line, 0, 1);
1924 $diff_class = " add";
1925 } elsif ($char eq '-') {
1926 $diff_class = " rem";
1927 } elsif ($char eq '@') {
1928 $diff_class = " chunk_header";
1929 } elsif ($char eq "\\") {
1930 $diff_class = " incomplete";
1933 $line = untabify
($line);
1934 if ($from && $to && $line =~ m/^\@{2} /) {
1935 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1936 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1938 $from_lines = 0 unless defined $from_lines;
1939 $to_lines = 0 unless defined $to_lines;
1941 if ($from->{'href'}) {
1942 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1943 -class=>"list"}, $from_text);
1945 if ($to->{'href'}) {
1946 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1947 -class=>"list"}, $to_text);
1949 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1950 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1951 return "<div class=\"diff$diff_class\">$line</div>\n";
1952 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1953 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1954 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1956 @from_text = split(' ', $ranges);
1957 for (my $i = 0; $i < @from_text; ++$i) {
1958 ($from_start[$i], $from_nlines[$i]) =
1959 (split(',', substr($from_text[$i], 1)), 0);
1962 $to_text = pop @from_text;
1963 $to_start = pop @from_start;
1964 $to_nlines = pop @from_nlines;
1966 $line = "<span class=\"chunk_info\">$prefix ";
1967 for (my $i = 0; $i < @from_text; ++$i) {
1968 if ($from->{'href'}[$i]) {
1969 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1970 -class=>"list"}, $from_text[$i]);
1972 $line .= $from_text[$i];
1976 if ($to->{'href'}) {
1977 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1978 -class=>"list"}, $to_text);
1982 $line .= " $prefix</span>" .
1983 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1984 return "<div class=\"diff$diff_class\">$line</div>\n";
1986 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1989 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1990 # linked. Pass the hash of the tree/commit to snapshot.
1991 sub format_snapshot_links
{
1993 my $num_fmts = @snapshot_fmts;
1994 if ($num_fmts > 1) {
1995 # A parenthesized list of links bearing format names.
1996 # e.g. "snapshot (_tar.gz_ _zip_)"
1997 return "snapshot (" . join(' ', map
2004 }, $known_snapshot_formats{$_}{'display'})
2005 , @snapshot_fmts) . ")";
2006 } elsif ($num_fmts == 1) {
2007 # A single "snapshot" link whose tooltip bears the format name.
2009 my ($fmt) = @snapshot_fmts;
2015 snapshot_format
=>$fmt
2017 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2019 } else { # $num_fmts == 0
2024 ## ......................................................................
2025 ## functions returning values to be passed, perhaps after some
2026 ## transformation, to other functions; e.g. returning arguments to href()
2028 # returns hash to be passed to href to generate gitweb URL
2029 # in -title key it returns description of link
2031 my $format = shift || 'Atom';
2032 my %res = (action
=> lc($format));
2034 # feed links are possible only for project views
2035 return unless (defined $project);
2036 # some views should link to OPML, or to generic project feed,
2037 # or don't have specific feed yet (so they should use generic)
2038 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2041 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2042 # from tag links; this also makes possible to detect branch links
2043 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2044 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2047 # find log type for feed description (title)
2049 if (defined $file_name) {
2050 $type = "history of $file_name";
2051 $type .= "/" if ($action eq 'tree');
2052 $type .= " on '$branch'" if (defined $branch);
2054 $type = "log of $branch" if (defined $branch);
2057 $res{-title
} = $type;
2058 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2059 $res{'file_name'} = $file_name;
2064 ## ----------------------------------------------------------------------
2065 ## git utility subroutines, invoking git commands
2067 # returns path to the core git executable and the --git-dir parameter as list
2069 $number_of_git_cmds++;
2070 return $GIT, '--git-dir='.$git_dir;
2073 # quote the given arguments for passing them to the shell
2074 # quote_command("command", "arg 1", "arg with ' and ! characters")
2075 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2076 # Try to avoid using this function wherever possible.
2079 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2082 # get HEAD ref of given project as hash
2083 sub git_get_head_hash
{
2084 return git_get_full_hash
(shift, 'HEAD');
2087 sub git_get_full_hash
{
2088 return git_get_hash
(@_);
2091 sub git_get_short_hash
{
2092 return git_get_hash
(@_, '--short=7');
2096 my ($project, $hash, @options) = @_;
2097 my $o_git_dir = $git_dir;
2099 $git_dir = "$projectroot/$project";
2100 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2101 '--verify', '-q', @options, $hash) {
2103 chomp $retval if defined $retval;
2106 if (defined $o_git_dir) {
2107 $git_dir = $o_git_dir;
2112 # get type of given object
2116 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2118 close $fd or return;
2123 # repository configuration
2124 our $config_file = '';
2127 # store multiple values for single key as anonymous array reference
2128 # single values stored directly in the hash, not as [ <value> ]
2129 sub hash_set_multi
{
2130 my ($hash, $key, $value) = @_;
2132 if (!exists $hash->{$key}) {
2133 $hash->{$key} = $value;
2134 } elsif (!ref $hash->{$key}) {
2135 $hash->{$key} = [ $hash->{$key}, $value ];
2137 push @{$hash->{$key}}, $value;
2141 # return hash of git project configuration
2142 # optionally limited to some section, e.g. 'gitweb'
2143 sub git_parse_project_config
{
2144 my $section_regexp = shift;
2149 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2152 while (my $keyval = <$fh>) {
2154 my ($key, $value) = split(/\n/, $keyval, 2);
2156 hash_set_multi
(\
%config, $key, $value)
2157 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2164 # convert config value to boolean: 'true' or 'false'
2165 # no value, number > 0, 'true' and 'yes' values are true
2166 # rest of values are treated as false (never as error)
2167 sub config_to_bool
{
2170 return 1 if !defined $val; # section.key
2172 # strip leading and trailing whitespace
2176 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2177 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2180 # convert config value to simple decimal number
2181 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2182 # to be multiplied by 1024, 1048576, or 1073741824
2186 # strip leading and trailing whitespace
2190 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2192 # unknown unit is treated as 1
2193 return $num * ($unit eq 'g' ? 1073741824 :
2194 $unit eq 'm' ? 1048576 :
2195 $unit eq 'k' ? 1024 : 1);
2200 # convert config value to array reference, if needed
2201 sub config_to_multi
{
2204 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2207 sub git_get_project_config
{
2208 my ($key, $type) = @_;
2211 return unless ($key);
2212 $key =~ s/^gitweb\.//;
2213 return if ($key =~ m/\W/);
2216 if (defined $type) {
2219 unless ($type eq 'bool' || $type eq 'int');
2223 if (!defined $config_file ||
2224 $config_file ne "$git_dir/config") {
2225 %config = git_parse_project_config
('gitweb');
2226 $config_file = "$git_dir/config";
2229 # check if config variable (key) exists
2230 return unless exists $config{"gitweb.$key"};
2233 if (!defined $type) {
2234 return $config{"gitweb.$key"};
2235 } elsif ($type eq 'bool') {
2236 # backward compatibility: 'git config --bool' returns true/false
2237 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2238 } elsif ($type eq 'int') {
2239 return config_to_int
($config{"gitweb.$key"});
2241 return $config{"gitweb.$key"};
2244 # get hash of given path at given ref
2245 sub git_get_hash_by_path
{
2247 my $path = shift || return undef;
2252 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2253 or die_error
(500, "Open git-ls-tree failed");
2255 close $fd or return undef;
2257 if (!defined $line) {
2258 # there is no tree or hash given by $path at $base
2262 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2263 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2264 if (defined $type && $type ne $2) {
2265 # type doesn't match
2271 # get path of entry with given hash at given tree-ish (ref)
2272 # used to get 'from' filename for combined diff (merge commit) for renames
2273 sub git_get_path_by_hash
{
2274 my $base = shift || return;
2275 my $hash = shift || return;
2279 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2281 while (my $line = <$fd>) {
2284 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2285 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2286 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2295 ## ......................................................................
2296 ## git utility functions, directly accessing git repository
2298 sub git_get_project_description
{
2301 $git_dir = "$projectroot/$path";
2302 open my $fd, '<', "$git_dir/description"
2303 or return git_get_project_config
('description');
2306 if (defined $descr) {
2312 sub git_get_project_ctags
{
2316 $git_dir = "$projectroot/$path";
2317 opendir my $dh, "$git_dir/ctags"
2319 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2320 open my $ct, '<', $_ or next;
2324 my $ctag = $_; $ctag =~ s
#.*/##;
2325 $ctags->{$ctag} = $val;
2331 sub git_populate_project_tagcloud
{
2334 # First, merge different-cased tags; tags vote on casing
2336 foreach (keys %$ctags) {
2337 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2338 if (not $ctags_lc{lc $_}->{topcount
}
2339 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2340 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2341 $ctags_lc{lc $_}->{topname
} = $_;
2346 if (eval { require HTML
::TagCloud
; 1; }) {
2347 $cloud = HTML
::TagCloud-
>new;
2348 foreach (sort keys %ctags_lc) {
2349 # Pad the title with spaces so that the cloud looks
2351 my $title = $ctags_lc{$_}->{topname
};
2352 $title =~ s/ / /g;
2353 $title =~ s/^/ /g;
2354 $title =~ s/$/ /g;
2355 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2358 $cloud = \
%ctags_lc;
2363 sub git_show_project_tagcloud
{
2364 my ($cloud, $count) = @_;
2365 print STDERR
ref($cloud)."..\n";
2366 if (ref $cloud eq 'HTML::TagCloud') {
2367 return $cloud->html_and_css($count);
2369 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2370 return '<p align="center">' . join (', ', map {
2371 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2372 } splice(@tags, 0, $count)) . '</p>';
2376 sub git_get_project_url_list
{
2379 $git_dir = "$projectroot/$path";
2380 open my $fd, '<', "$git_dir/cloneurl"
2381 or return wantarray ?
2382 @{ config_to_multi
(git_get_project_config
('url')) } :
2383 config_to_multi
(git_get_project_config
('url'));
2384 my @git_project_url_list = map { chomp; $_ } <$fd>;
2387 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2390 sub git_get_projects_list
{
2395 $filter =~ s/\.git$//;
2397 my $check_forks = gitweb_check_feature
('forks');
2399 if (-d
$projects_list) {
2400 # search in directory
2401 my $dir = $projects_list . ($filter ? "/$filter" : '');
2402 # remove the trailing "/"
2404 my $pfxlen = length("$dir");
2405 my $pfxdepth = ($dir =~ tr!/!!);
2408 follow_fast
=> 1, # follow symbolic links
2409 follow_skip
=> 2, # ignore duplicates
2410 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2412 # skip project-list toplevel, if we get it.
2413 return if (m!^[/.]$!);
2414 # only directories can be git repositories
2415 return unless (-d
$_);
2416 # don't traverse too deep (Find is super slow on os x)
2417 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2418 $File::Find
::prune
= 1;
2422 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2423 # we check related file in $projectroot
2424 my $path = ($filter ? "$filter/" : '') . $subdir;
2425 if (check_export_ok
("$projectroot/$path")) {
2426 push @list, { path
=> $path };
2427 $File::Find
::prune
= 1;
2432 } elsif (-f
$projects_list) {
2433 # read from file(url-encoded):
2434 # 'git%2Fgit.git Linus+Torvalds'
2435 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2436 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2438 open my $fd, '<', $projects_list or return;
2440 while (my $line = <$fd>) {
2442 my ($path, $owner) = split ' ', $line;
2443 $path = unescape
($path);
2444 $owner = unescape
($owner);
2445 if (!defined $path) {
2448 if ($filter ne '') {
2449 # looking for forks;
2450 my $pfx = substr($path, 0, length($filter));
2451 if ($pfx ne $filter) {
2454 my $sfx = substr($path, length($filter));
2455 if ($sfx !~ /^\/.*\
.git
$/) {
2458 } elsif ($check_forks) {
2460 foreach my $filter (keys %paths) {
2461 # looking for forks;
2462 my $pfx = substr($path, 0, length($filter));
2463 if ($pfx ne $filter) {
2466 my $sfx = substr($path, length($filter));
2467 if ($sfx !~ /^\/.*\
.git
$/) {
2470 # is a fork, don't include it in
2475 if (check_export_ok
("$projectroot/$path")) {
2478 owner
=> to_utf8
($owner),
2481 (my $forks_path = $path) =~ s/\.git$//;
2482 $paths{$forks_path}++;
2490 our $gitweb_project_owner = undef;
2491 sub git_get_project_list_from_file
{
2493 return if (defined $gitweb_project_owner);
2495 $gitweb_project_owner = {};
2496 # read from file (url-encoded):
2497 # 'git%2Fgit.git Linus+Torvalds'
2498 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2499 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2500 if (-f
$projects_list) {
2501 open(my $fd, '<', $projects_list);
2502 while (my $line = <$fd>) {
2504 my ($pr, $ow) = split ' ', $line;
2505 $pr = unescape
($pr);
2506 $ow = unescape
($ow);
2507 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2513 sub git_get_project_owner
{
2514 my $project = shift;
2517 return undef unless $project;
2518 $git_dir = "$projectroot/$project";
2520 if (!defined $gitweb_project_owner) {
2521 git_get_project_list_from_file
();
2524 if (exists $gitweb_project_owner->{$project}) {
2525 $owner = $gitweb_project_owner->{$project};
2527 if (!defined $owner){
2528 $owner = git_get_project_config
('owner');
2530 if (!defined $owner) {
2531 $owner = get_file_owner
("$git_dir");
2537 sub git_get_last_activity
{
2541 $git_dir = "$projectroot/$path";
2542 open($fd, "-|", git_cmd
(), 'for-each-ref',
2543 '--format=%(committer)',
2544 '--sort=-committerdate',
2546 'refs/heads') or return;
2547 my $most_recent = <$fd>;
2548 close $fd or return;
2549 if (defined $most_recent &&
2550 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2552 my $age = time - $timestamp;
2553 return ($age, age_string
($age));
2555 return (undef, undef);
2558 sub git_get_references
{
2559 my $type = shift || "";
2561 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2562 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2563 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2564 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2567 while (my $line = <$fd>) {
2569 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2570 if (defined $refs{$1}) {
2571 push @{$refs{$1}}, $2;
2577 close $fd or return;
2581 sub git_get_rev_name_tags
{
2582 my $hash = shift || return undef;
2584 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2586 my $name_rev = <$fd>;
2589 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2592 # catches also '$hash undefined' output
2597 ## ----------------------------------------------------------------------
2598 ## parse to hash functions
2602 my $tz = shift || "-0000";
2605 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2606 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2607 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2608 $date{'hour'} = $hour;
2609 $date{'minute'} = $min;
2610 $date{'mday'} = $mday;
2611 $date{'day'} = $days[$wday];
2612 $date{'month'} = $months[$mon];
2613 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2614 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2615 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2616 $mday, $months[$mon], $hour ,$min;
2617 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2618 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2620 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2621 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2622 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2623 $date{'hour_local'} = $hour;
2624 $date{'minute_local'} = $min;
2625 $date{'tz_local'} = $tz;
2626 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2627 1900+$year, $mon+1, $mday,
2628 $hour, $min, $sec, $tz);
2637 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2638 $tag{'id'} = $tag_id;
2639 while (my $line = <$fd>) {
2641 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2642 $tag{'object'} = $1;
2643 } elsif ($line =~ m/^type (.+)$/) {
2645 } elsif ($line =~ m/^tag (.+)$/) {
2647 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2648 $tag{'author'} = $1;
2649 $tag{'author_epoch'} = $2;
2650 $tag{'author_tz'} = $3;
2651 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2652 $tag{'author_name'} = $1;
2653 $tag{'author_email'} = $2;
2655 $tag{'author_name'} = $tag{'author'};
2657 } elsif ($line =~ m/--BEGIN/) {
2658 push @comment, $line;
2660 } elsif ($line eq "") {
2664 push @comment, <$fd>;
2665 $tag{'comment'} = \
@comment;
2666 close $fd or return;
2667 if (!defined $tag{'name'}) {
2673 sub parse_commit_text
{
2674 my ($commit_text, $withparents) = @_;
2675 my @commit_lines = split '\n', $commit_text;
2678 pop @commit_lines; # Remove '\0'
2680 if (! @commit_lines) {
2684 my $header = shift @commit_lines;
2685 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2688 ($co{'id'}, my @parents) = split ' ', $header;
2689 while (my $line = shift @commit_lines) {
2690 last if $line eq "\n";
2691 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2693 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2695 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2696 $co{'author'} = to_utf8
($1);
2697 $co{'author_epoch'} = $2;
2698 $co{'author_tz'} = $3;
2699 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2700 $co{'author_name'} = $1;
2701 $co{'author_email'} = $2;
2703 $co{'author_name'} = $co{'author'};
2705 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2706 $co{'committer'} = to_utf8
($1);
2707 $co{'committer_epoch'} = $2;
2708 $co{'committer_tz'} = $3;
2709 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2710 $co{'committer_name'} = $1;
2711 $co{'committer_email'} = $2;
2713 $co{'committer_name'} = $co{'committer'};
2717 if (!defined $co{'tree'}) {
2720 $co{'parents'} = \
@parents;
2721 $co{'parent'} = $parents[0];
2723 foreach my $title (@commit_lines) {
2726 $co{'title'} = chop_str
($title, 80, 5);
2727 # remove leading stuff of merges to make the interesting part visible
2728 if (length($title) > 50) {
2729 $title =~ s/^Automatic //;
2730 $title =~ s/^merge (of|with) /Merge ... /i;
2731 if (length($title) > 50) {
2732 $title =~ s/(http|rsync):\/\///;
2734 if (length($title) > 50) {
2735 $title =~ s/(master|www|rsync)\.//;
2737 if (length($title) > 50) {
2738 $title =~ s/kernel.org:?//;
2740 if (length($title) > 50) {
2741 $title =~ s/\/pub\/scm//;
2744 $co{'title_short'} = chop_str
($title, 50, 5);
2748 if (! defined $co{'title'} || $co{'title'} eq "") {
2749 $co{'title'} = $co{'title_short'} = '(no commit message)';
2751 # remove added spaces
2752 foreach my $line (@commit_lines) {
2755 $co{'comment'} = \
@commit_lines;
2757 my $age = time - $co{'committer_epoch'};
2759 $co{'age_string'} = age_string
($age);
2760 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2761 if ($age > 60*60*24*7*2) {
2762 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2763 $co{'age_string_age'} = $co{'age_string'};
2765 $co{'age_string_date'} = $co{'age_string'};
2766 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2772 my ($commit_id) = @_;
2777 open my $fd, "-|", git_cmd
(), "rev-list",
2783 or die_error
(500, "Open git-rev-list failed");
2784 %co = parse_commit_text
(<$fd>, 1);
2791 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2799 open my $fd, "-|", git_cmd
(), "rev-list",
2802 ("--max-count=" . $maxcount),
2803 ("--skip=" . $skip),
2807 ($filename ? ($filename) : ())
2808 or die_error
(500, "Open git-rev-list failed");
2809 while (my $line = <$fd>) {
2810 my %co = parse_commit_text
($line);
2815 return wantarray ? @cos : \
@cos;
2818 # parse line of git-diff-tree "raw" output
2819 sub parse_difftree_raw_line
{
2823 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2824 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2825 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2826 $res{'from_mode'} = $1;
2827 $res{'to_mode'} = $2;
2828 $res{'from_id'} = $3;
2830 $res{'status'} = $5;
2831 $res{'similarity'} = $6;
2832 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2833 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2835 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2838 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2839 # combined diff (for merge commit)
2840 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2841 $res{'nparents'} = length($1);
2842 $res{'from_mode'} = [ split(' ', $2) ];
2843 $res{'to_mode'} = pop @{$res{'from_mode'}};
2844 $res{'from_id'} = [ split(' ', $3) ];
2845 $res{'to_id'} = pop @{$res{'from_id'}};
2846 $res{'status'} = [ split('', $4) ];
2847 $res{'to_file'} = unquote
($5);
2849 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2850 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2851 $res{'commit'} = $1;
2854 return wantarray ? %res : \
%res;
2857 # wrapper: return parsed line of git-diff-tree "raw" output
2858 # (the argument might be raw line, or parsed info)
2859 sub parsed_difftree_line
{
2860 my $line_or_ref = shift;
2862 if (ref($line_or_ref) eq "HASH") {
2863 # pre-parsed (or generated by hand)
2864 return $line_or_ref;
2866 return parse_difftree_raw_line
($line_or_ref);
2870 # parse line of git-ls-tree output
2871 sub parse_ls_tree_line
{
2877 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2878 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2887 $res{'name'} = unquote
($5);
2890 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2891 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2899 $res{'name'} = unquote
($4);
2903 return wantarray ? %res : \
%res;
2906 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2907 sub parse_from_to_diffinfo
{
2908 my ($diffinfo, $from, $to, @parents) = @_;
2910 if ($diffinfo->{'nparents'}) {
2912 $from->{'file'} = [];
2913 $from->{'href'} = [];
2914 fill_from_file_info
($diffinfo, @parents)
2915 unless exists $diffinfo->{'from_file'};
2916 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2917 $from->{'file'}[$i] =
2918 defined $diffinfo->{'from_file'}[$i] ?
2919 $diffinfo->{'from_file'}[$i] :
2920 $diffinfo->{'to_file'};
2921 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2922 $from->{'href'}[$i] = href
(action
=>"blob",
2923 hash_base
=>$parents[$i],
2924 hash
=>$diffinfo->{'from_id'}[$i],
2925 file_name
=>$from->{'file'}[$i]);
2927 $from->{'href'}[$i] = undef;
2931 # ordinary (not combined) diff
2932 $from->{'file'} = $diffinfo->{'from_file'};
2933 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2934 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2935 hash
=>$diffinfo->{'from_id'},
2936 file_name
=>$from->{'file'});
2938 delete $from->{'href'};
2942 $to->{'file'} = $diffinfo->{'to_file'};
2943 if (!is_deleted
($diffinfo)) { # file exists in result
2944 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2945 hash
=>$diffinfo->{'to_id'},
2946 file_name
=>$to->{'file'});
2948 delete $to->{'href'};
2952 ## ......................................................................
2953 ## parse to array of hashes functions
2955 sub git_get_heads_list
{
2959 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2960 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2961 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2964 while (my $line = <$fd>) {
2968 my ($refinfo, $committerinfo) = split(/\0/, $line);
2969 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2970 my ($committer, $epoch, $tz) =
2971 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2972 $ref_item{'fullname'} = $name;
2973 $name =~ s!^refs/heads/!!;
2975 $ref_item{'name'} = $name;
2976 $ref_item{'id'} = $hash;
2977 $ref_item{'title'} = $title || '(no commit message)';
2978 $ref_item{'epoch'} = $epoch;
2980 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2982 $ref_item{'age'} = "unknown";
2985 push @headslist, \
%ref_item;
2989 return wantarray ? @headslist : \
@headslist;
2992 sub git_get_tags_list
{
2996 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2997 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2998 '--format=%(objectname) %(objecttype) %(refname) '.
2999 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3002 while (my $line = <$fd>) {
3006 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3007 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3008 my ($creator, $epoch, $tz) =
3009 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3010 $ref_item{'fullname'} = $name;
3011 $name =~ s!^refs/tags/!!;
3013 $ref_item{'type'} = $type;
3014 $ref_item{'id'} = $id;
3015 $ref_item{'name'} = $name;
3016 if ($type eq "tag") {
3017 $ref_item{'subject'} = $title;
3018 $ref_item{'reftype'} = $reftype;
3019 $ref_item{'refid'} = $refid;
3021 $ref_item{'reftype'} = $type;
3022 $ref_item{'refid'} = $id;
3025 if ($type eq "tag" || $type eq "commit") {
3026 $ref_item{'epoch'} = $epoch;
3028 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3030 $ref_item{'age'} = "unknown";
3034 push @tagslist, \
%ref_item;
3038 return wantarray ? @tagslist : \
@tagslist;
3041 ## ----------------------------------------------------------------------
3042 ## filesystem-related functions
3044 sub get_file_owner
{
3047 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3048 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3049 if (!defined $gcos) {
3053 $owner =~ s/[,;].*$//;
3054 return to_utf8
($owner);
3057 # assume that file exists
3059 my $filename = shift;
3061 open my $fd, '<', $filename;
3062 print map { to_utf8
($_) } <$fd>;
3066 ## ......................................................................
3067 ## mimetype related functions
3069 sub mimetype_guess_file
{
3070 my $filename = shift;
3071 my $mimemap = shift;
3072 -r
$mimemap or return undef;
3075 open(my $mh, '<', $mimemap) or return undef;
3077 next if m/^#/; # skip comments
3078 my ($mimetype, $exts) = split(/\t+/);
3079 if (defined $exts) {
3080 my @exts = split(/\s+/, $exts);
3081 foreach my $ext (@exts) {
3082 $mimemap{$ext} = $mimetype;
3088 $filename =~ /\.([^.]*)$/;
3089 return $mimemap{$1};
3092 sub mimetype_guess
{
3093 my $filename = shift;
3095 $filename =~ /\./ or return undef;
3097 if ($mimetypes_file) {
3098 my $file = $mimetypes_file;
3099 if ($file !~ m!^/!) { # if it is relative path
3100 # it is relative to project
3101 $file = "$projectroot/$project/$file";
3103 $mime = mimetype_guess_file
($filename, $file);
3105 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3111 my $filename = shift;
3114 my $mime = mimetype_guess
($filename);
3115 $mime and return $mime;
3119 return $default_blob_plain_mimetype unless $fd;
3122 return 'text/plain';
3123 } elsif (! $filename) {
3124 return 'application/octet-stream';
3125 } elsif ($filename =~ m/\.png$/i) {
3127 } elsif ($filename =~ m/\.gif$/i) {
3129 } elsif ($filename =~ m/\.jpe?g$/i) {
3130 return 'image/jpeg';
3132 return 'application/octet-stream';
3136 sub blob_contenttype
{
3137 my ($fd, $file_name, $type) = @_;
3139 $type ||= blob_mimetype
($fd, $file_name);
3140 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3141 $type .= "; charset=$default_text_plain_charset";
3147 ## ======================================================================
3148 ## functions printing HTML: header, footer, error page
3150 sub git_header_html
{
3151 my $status = shift || "200 OK";
3152 my $expires = shift;
3154 my $title = "$site_name";
3155 if (defined $project) {
3156 $title .= " - " . to_utf8
($project);
3157 if (defined $action) {
3158 $title .= "/$action";
3159 if (defined $file_name) {
3160 $title .= " - " . esc_path
($file_name);
3161 if ($action eq "tree" && $file_name !~ m
|/$|) {
3168 # require explicit support from the UA if we are to send the page as
3169 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3170 # we have to do this because MSIE sometimes globs '*/*', pretending to
3171 # support xhtml+xml but choking when it gets what it asked for.
3172 if (defined $cgi->http('HTTP_ACCEPT') &&
3173 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3174 $cgi->Accept('application/xhtml+xml') != 0) {
3175 $content_type = 'application/xhtml+xml';
3177 $content_type = 'text/html';
3179 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3180 -status
=> $status, -expires
=> $expires);
3181 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3183 <?xml version="1.0" encoding="utf-8"?>
3184 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3185 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3186 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3187 <!-- git core binaries version $git_version -->
3189 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3190 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3191 <meta name="robots" content="index, nofollow"/>
3192 <title>$title</title>
3194 # the stylesheet, favicon etc urls won't work correctly with path_info
3195 # unless we set the appropriate base URL
3196 if ($ENV{'PATH_INFO'}) {
3197 print "<base href=\"".esc_url
($base_url)."\" />\n";
3199 # print out each stylesheet that exist, providing backwards capability
3200 # for those people who defined $stylesheet in a config file
3201 if (defined $stylesheet) {
3202 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3204 foreach my $stylesheet (@stylesheets) {
3205 next unless $stylesheet;
3206 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3209 if (defined $project) {
3210 my %href_params = get_feed_info
();
3211 if (!exists $href_params{'-title'}) {
3212 $href_params{'-title'} = 'log';
3215 foreach my $format qw(RSS Atom) {
3216 my $type = lc($format);
3218 '-rel' => 'alternate',
3219 '-title' => "$project - $href_params{'-title'} - $format feed",
3220 '-type' => "application/$type+xml"
3223 $href_params{'action'} = $type;
3224 $link_attr{'-href'} = href
(%href_params);
3226 "rel=\"$link_attr{'-rel'}\" ".
3227 "title=\"$link_attr{'-title'}\" ".
3228 "href=\"$link_attr{'-href'}\" ".
3229 "type=\"$link_attr{'-type'}\" ".
3232 $href_params{'extra_options'} = '--no-merges';
3233 $link_attr{'-href'} = href
(%href_params);
3234 $link_attr{'-title'} .= ' (no merges)';
3236 "rel=\"$link_attr{'-rel'}\" ".
3237 "title=\"$link_attr{'-title'}\" ".
3238 "href=\"$link_attr{'-href'}\" ".
3239 "type=\"$link_attr{'-type'}\" ".
3244 printf('<link rel="alternate" title="%s projects list" '.
3245 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3246 $site_name, href
(project
=>undef, action
=>"project_index"));
3247 printf('<link rel="alternate" title="%s projects feeds" '.
3248 'href="%s" type="text/x-opml" />'."\n",
3249 $site_name, href
(project
=>undef, action
=>"opml"));
3251 if (defined $favicon) {
3252 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3258 if (defined $site_header && -f
$site_header) {
3259 insert_file
($site_header);
3262 print "<div class=\"page_header\">\n" .
3263 $cgi->a({-href
=> esc_url
($logo_url),
3264 -title
=> $logo_label},
3265 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3266 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3267 if (defined $project) {
3268 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3269 if (defined $action) {
3276 my $have_search = gitweb_check_feature
('search');
3277 if (defined $project && $have_search) {
3278 if (!defined $searchtext) {
3282 if (defined $hash_base) {
3283 $search_hash = $hash_base;
3284 } elsif (defined $hash) {
3285 $search_hash = $hash;
3287 $search_hash = "HEAD";
3289 my $action = $my_uri;
3290 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3291 if ($use_pathinfo) {
3292 $action .= "/".esc_url
($project);
3294 print $cgi->startform(-method => "get", -action
=> $action) .
3295 "<div class=\"search\">\n" .
3297 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3298 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3299 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3300 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3301 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3302 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3304 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3305 "<span title=\"Extended regular expression\">" .
3306 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3307 -checked
=> $search_use_regexp) .
3310 $cgi->end_form() . "\n";
3314 sub git_footer_html
{
3315 my $feed_class = 'rss_logo';
3317 print "<div class=\"page_footer\">\n";
3318 if (defined $project) {
3319 my $descr = git_get_project_description
($project);
3320 if (defined $descr) {
3321 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3324 my %href_params = get_feed_info
();
3325 if (!%href_params) {
3326 $feed_class .= ' generic';
3328 $href_params{'-title'} ||= 'log';
3330 foreach my $format qw(RSS Atom) {
3331 $href_params{'action'} = lc($format);
3332 print $cgi->a({-href
=> href
(%href_params),
3333 -title
=> "$href_params{'-title'} $format feed",
3334 -class => $feed_class}, $format)."\n";
3338 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3339 -class => $feed_class}, "OPML") . " ";
3340 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3341 -class => $feed_class}, "TXT") . "\n";
3343 print "</div>\n"; # class="page_footer"
3345 if (defined $t0 && gitweb_check_feature
('timed')) {
3346 print "<div id=\"generating_info\">\n";
3347 print 'This page took '.
3348 '<span id="generating_time" class="time_span">'.
3349 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3352 '<span id="generating_cmd">'.
3353 $number_of_git_cmds.
3354 '</span> git commands '.
3356 print "</div>\n"; # class="page_footer"
3359 if (defined $site_footer && -f
$site_footer) {
3360 insert_file
($site_footer);
3363 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3364 if (defined $action &&
3365 $action eq 'blame_incremental') {
3366 print qq
!<script type
="text/javascript">\n!.
3367 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3368 qq
! "!. href() .qq!");\n!.
3370 } elsif (gitweb_check_feature
('javascript-actions')) {
3371 print qq
!<script type
="text/javascript">\n!.
3372 qq
!window
.onload
= fixLinks
;\n!.
3380 # die_error(<http_status_code>, <error_message>)
3381 # Example: die_error(404, 'Hash not found')
3382 # By convention, use the following status codes (as defined in RFC 2616):
3383 # 400: Invalid or missing CGI parameters, or
3384 # requested object exists but has wrong type.
3385 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3386 # this server or project.
3387 # 404: Requested object/revision/project doesn't exist.
3388 # 500: The server isn't configured properly, or
3389 # an internal error occurred (e.g. failed assertions caused by bugs), or
3390 # an unknown error occurred (e.g. the git binary died unexpectedly).
3391 # 503: The server is currently unavailable (because it is overloaded,
3392 # or down for maintenance). Generally, this is a temporary state.
3394 my $status = shift || 500;
3395 my $error = shift || "Internal server error";
3397 my %http_responses = (
3398 400 => '400 Bad Request',
3399 403 => '403 Forbidden',
3400 404 => '404 Not Found',
3401 500 => '500 Internal Server Error',
3402 503 => '503 Service Unavailable',
3404 git_header_html
($http_responses{$status});
3406 <div class="page_body">
3416 ## ----------------------------------------------------------------------
3417 ## functions printing or outputting HTML: navigation
3419 sub git_print_page_nav
{
3420 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3421 $extra = '' if !defined $extra; # pager or formats
3423 my @navs = qw(summary shortlog log commit commitdiff tree);
3425 @navs = grep { $_ ne $suppress } @navs;
3428 my %arg = map { $_ => {action
=>$_} } @navs;
3429 if (defined $head) {
3430 for (qw(commit commitdiff)) {
3431 $arg{$_}{'hash'} = $head;
3433 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3434 for (qw(shortlog log)) {
3435 $arg{$_}{'hash'} = $head;
3440 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3441 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3443 my @actions = gitweb_get_feature
('actions');
3446 'n' => $project, # project name
3447 'f' => $git_dir, # project path within filesystem
3448 'h' => $treehead || '', # current hash ('h' parameter)
3449 'b' => $treebase || '', # hash base ('hb' parameter)
3452 my ($label, $link, $pos) = splice(@actions,0,3);
3454 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3456 $link =~ s/%([%nfhb])/$repl{$1}/g;
3457 $arg{$label}{'_href'} = $link;
3460 print "<div class=\"page_nav\">\n" .
3462 map { $_ eq $current ?
3463 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3465 print "<br/>\n$extra<br/>\n" .
3469 sub format_paging_nav
{
3470 my ($action, $page, $has_next_link) = @_;
3476 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3478 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3479 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3481 $paging_nav .= "first ⋅ prev";
3484 if ($has_next_link) {
3485 $paging_nav .= " ⋅ " .
3486 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3487 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3489 $paging_nav .= " ⋅ next";
3495 ## ......................................................................
3496 ## functions printing or outputting HTML: div
3498 sub git_print_header_div
{
3499 my ($action, $title, $hash, $hash_base) = @_;
3502 $args{'action'} = $action;
3503 $args{'hash'} = $hash if $hash;
3504 $args{'hash_base'} = $hash_base if $hash_base;
3506 print "<div class=\"header\">\n" .
3507 $cgi->a({-href
=> href
(%args), -class => "title"},
3508 $title ? $title : $action) .
3512 sub print_local_time
{
3513 print format_local_time
(@_);
3516 sub format_local_time
{
3519 if ($date{'hour_local'} < 6) {
3520 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3521 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3523 $localtime .= sprintf(" (%02d:%02d %s)",
3524 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3530 # Outputs the author name and date in long form
3531 sub git_print_authorship
{
3534 my $tag = $opts{-tag
} || 'div';
3535 my $author = $co->{'author_name'};
3537 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3538 print "<$tag class=\"author_date\">" .
3539 format_search_author
($author, "author", esc_html
($author)) .
3541 print_local_time
(%ad) if ($opts{-localtime});
3542 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3546 # Outputs table rows containing the full author or committer information,
3547 # in the format expected for 'commit' view (& similia).
3548 # Parameters are a commit hash reference, followed by the list of people
3549 # to output information for. If the list is empty it defalts to both
3550 # author and committer.
3551 sub git_print_authorship_rows
{
3553 # too bad we can't use @people = @_ || ('author', 'committer')
3555 @people = ('author', 'committer') unless @people;
3556 foreach my $who (@people) {
3557 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3558 print "<tr><td>$who</td><td>" .
3559 format_search_author
($co->{"${who}_name"}, $who,
3560 esc_html
($co->{"${who}_name"})) . " " .
3561 format_search_author
($co->{"${who}_email"}, $who,
3562 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3563 "</td><td rowspan=\"2\">" .
3564 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3567 "<td></td><td> $wd{'rfc2822'}";
3568 print_local_time
(%wd);
3574 sub git_print_page_path
{
3580 print "<div class=\"page_path\">";
3581 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3582 -title
=> 'tree root'}, to_utf8
("[$project]"));
3584 if (defined $name) {
3585 my @dirname = split '/', $name;
3586 my $basename = pop @dirname;
3589 foreach my $dir (@dirname) {
3590 $fullname .= ($fullname ? '/' : '') . $dir;
3591 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3593 -title
=> $fullname}, esc_path
($dir));
3596 if (defined $type && $type eq 'blob') {
3597 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3599 -title
=> $name}, esc_path
($basename));
3600 } elsif (defined $type && $type eq 'tree') {
3601 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3603 -title
=> $name}, esc_path
($basename));
3606 print esc_path
($basename);
3609 print "<br/></div>\n";
3616 if ($opts{'-remove_title'}) {
3617 # remove title, i.e. first line of log
3620 # remove leading empty lines
3621 while (defined $log->[0] && $log->[0] eq "") {
3628 foreach my $line (@$log) {
3629 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3632 if (! $opts{'-remove_signoff'}) {
3633 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3636 # remove signoff lines
3643 # print only one empty line
3644 # do not print empty line after signoff
3646 next if ($empty || $signoff);
3652 print format_log_line_html
($line) . "<br/>\n";
3655 if ($opts{'-final_empty_line'}) {
3656 # end with single empty line
3657 print "<br/>\n" unless $empty;
3661 # return link target (what link points to)
3662 sub git_get_link_target
{
3667 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3671 $link_target = <$fd>;
3676 return $link_target;
3679 # given link target, and the directory (basedir) the link is in,
3680 # return target of link relative to top directory (top tree);
3681 # return undef if it is not possible (including absolute links).
3682 sub normalize_link_target
{
3683 my ($link_target, $basedir) = @_;
3685 # absolute symlinks (beginning with '/') cannot be normalized
3686 return if (substr($link_target, 0, 1) eq '/');
3688 # normalize link target to path from top (root) tree (dir)
3691 $path = $basedir . '/' . $link_target;
3693 # we are in top (root) tree (dir)
3694 $path = $link_target;
3697 # remove //, /./, and /../
3699 foreach my $part (split('/', $path)) {
3700 # discard '.' and ''
3701 next if (!$part || $part eq '.');
3703 if ($part eq '..') {
3707 # link leads outside repository (outside top dir)
3711 push @path_parts, $part;
3714 $path = join('/', @path_parts);
3719 # print tree entry (row of git_tree), but without encompassing <tr> element
3720 sub git_print_tree_entry
{
3721 my ($t, $basedir, $hash_base, $have_blame) = @_;
3724 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3726 # The format of a table row is: mode list link. Where mode is
3727 # the mode of the entry, list is the name of the entry, an href,
3728 # and link is the action links of the entry.
3730 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3731 if (exists $t->{'size'}) {
3732 print "<td class=\"size\">$t->{'size'}</td>\n";
3734 if ($t->{'type'} eq "blob") {
3735 print "<td class=\"list\">" .
3736 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3737 file_name
=>"$basedir$t->{'name'}", %base_key),
3738 -class => "list"}, esc_path
($t->{'name'}));
3739 if (S_ISLNK
(oct $t->{'mode'})) {
3740 my $link_target = git_get_link_target
($t->{'hash'});
3742 my $norm_target = normalize_link_target
($link_target, $basedir);
3743 if (defined $norm_target) {
3745 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3746 file_name
=>$norm_target),
3747 -title
=> $norm_target}, esc_path
($link_target));
3749 print " -> " . esc_path
($link_target);
3754 print "<td class=\"link\">";
3755 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3756 file_name
=>"$basedir$t->{'name'}", %base_key)},
3760 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3761 file_name
=>"$basedir$t->{'name'}", %base_key)},
3764 if (defined $hash_base) {
3766 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3767 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3771 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3772 file_name
=>"$basedir$t->{'name'}")},
3776 } elsif ($t->{'type'} eq "tree") {
3777 print "<td class=\"list\">";
3778 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3779 file_name
=>"$basedir$t->{'name'}",
3781 esc_path
($t->{'name'}));
3783 print "<td class=\"link\">";
3784 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3785 file_name
=>"$basedir$t->{'name'}",
3788 if (defined $hash_base) {
3790 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3791 file_name
=>"$basedir$t->{'name'}")},
3796 # unknown object: we can only present history for it
3797 # (this includes 'commit' object, i.e. submodule support)
3798 print "<td class=\"list\">" .
3799 esc_path
($t->{'name'}) .
3801 print "<td class=\"link\">";
3802 if (defined $hash_base) {
3803 print $cgi->a({-href
=> href
(action
=>"history",
3804 hash_base
=>$hash_base,
3805 file_name
=>"$basedir$t->{'name'}")},
3812 ## ......................................................................
3813 ## functions printing large fragments of HTML
3815 # get pre-image filenames for merge (combined) diff
3816 sub fill_from_file_info
{
3817 my ($diff, @parents) = @_;
3819 $diff->{'from_file'} = [ ];
3820 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3821 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3822 if ($diff->{'status'}[$i] eq 'R' ||
3823 $diff->{'status'}[$i] eq 'C') {
3824 $diff->{'from_file'}[$i] =
3825 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3832 # is current raw difftree line of file deletion
3834 my $diffinfo = shift;
3836 return $diffinfo->{'to_id'} eq ('0' x
40);
3839 # does patch correspond to [previous] difftree raw line
3840 # $diffinfo - hashref of parsed raw diff format
3841 # $patchinfo - hashref of parsed patch diff format
3842 # (the same keys as in $diffinfo)
3843 sub is_patch_split
{
3844 my ($diffinfo, $patchinfo) = @_;
3846 return defined $diffinfo && defined $patchinfo
3847 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3851 sub git_difftree_body
{
3852 my ($difftree, $hash, @parents) = @_;
3853 my ($parent) = $parents[0];
3854 my $have_blame = gitweb_check_feature
('blame');
3855 print "<div class=\"list_head\">\n";
3856 if ($#{$difftree} > 10) {
3857 print(($#{$difftree} + 1) . " files changed:\n");
3861 print "<table class=\"" .
3862 (@parents > 1 ? "combined " : "") .
3865 # header only for combined diff in 'commitdiff' view
3866 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3869 print "<thead><tr>\n" .
3870 "<th></th><th></th>\n"; # filename, patchN link
3871 for (my $i = 0; $i < @parents; $i++) {
3872 my $par = $parents[$i];
3874 $cgi->a({-href
=> href
(action
=>"commitdiff",
3875 hash
=>$hash, hash_parent
=>$par),
3876 -title
=> 'commitdiff to parent number ' .
3877 ($i+1) . ': ' . substr($par,0,7)},
3881 print "</tr></thead>\n<tbody>\n";
3886 foreach my $line (@{$difftree}) {
3887 my $diff = parsed_difftree_line
($line);
3890 print "<tr class=\"dark\">\n";
3892 print "<tr class=\"light\">\n";
3896 if (exists $diff->{'nparents'}) { # combined diff
3898 fill_from_file_info
($diff, @parents)
3899 unless exists $diff->{'from_file'};
3901 if (!is_deleted
($diff)) {
3902 # file exists in the result (child) commit
3904 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3905 file_name
=>$diff->{'to_file'},
3907 -class => "list"}, esc_path
($diff->{'to_file'})) .
3911 esc_path
($diff->{'to_file'}) .
3915 if ($action eq 'commitdiff') {
3918 print "<td class=\"link\">" .
3919 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3924 my $has_history = 0;
3925 my $not_deleted = 0;
3926 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3927 my $hash_parent = $parents[$i];
3928 my $from_hash = $diff->{'from_id'}[$i];
3929 my $from_path = $diff->{'from_file'}[$i];
3930 my $status = $diff->{'status'}[$i];
3932 $has_history ||= ($status ne 'A');
3933 $not_deleted ||= ($status ne 'D');
3935 if ($status eq 'A') {
3936 print "<td class=\"link\" align=\"right\"> | </td>\n";
3937 } elsif ($status eq 'D') {
3938 print "<td class=\"link\">" .
3939 $cgi->a({-href
=> href
(action
=>"blob",
3942 file_name
=>$from_path)},
3946 if ($diff->{'to_id'} eq $from_hash) {
3947 print "<td class=\"link nochange\">";
3949 print "<td class=\"link\">";
3951 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3952 hash
=>$diff->{'to_id'},
3953 hash_parent
=>$from_hash,
3955 hash_parent_base
=>$hash_parent,
3956 file_name
=>$diff->{'to_file'},
3957 file_parent
=>$from_path)},
3963 print "<td class=\"link\">";
3965 print $cgi->a({-href
=> href
(action
=>"blob",
3966 hash
=>$diff->{'to_id'},
3967 file_name
=>$diff->{'to_file'},
3970 print " | " if ($has_history);
3973 print $cgi->a({-href
=> href
(action
=>"history",
3974 file_name
=>$diff->{'to_file'},
3981 next; # instead of 'else' clause, to avoid extra indent
3983 # else ordinary diff
3985 my ($to_mode_oct, $to_mode_str, $to_file_type);
3986 my ($from_mode_oct, $from_mode_str, $from_file_type);
3987 if ($diff->{'to_mode'} ne ('0' x
6)) {
3988 $to_mode_oct = oct $diff->{'to_mode'};
3989 if (S_ISREG
($to_mode_oct)) { # only for regular file
3990 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3992 $to_file_type = file_type
($diff->{'to_mode'});
3994 if ($diff->{'from_mode'} ne ('0' x
6)) {
3995 $from_mode_oct = oct $diff->{'from_mode'};
3996 if (S_ISREG
($to_mode_oct)) { # only for regular file
3997 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3999 $from_file_type = file_type
($diff->{'from_mode'});
4002 if ($diff->{'status'} eq "A") { # created
4003 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4004 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4005 $mode_chng .= "]</span>";
4007 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4008 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4009 -class => "list"}, esc_path
($diff->{'file'}));
4011 print "<td>$mode_chng</td>\n";
4012 print "<td class=\"link\">";
4013 if ($action eq 'commitdiff') {
4016 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4019 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4020 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4024 } elsif ($diff->{'status'} eq "D") { # deleted
4025 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4027 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4028 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4029 -class => "list"}, esc_path
($diff->{'file'}));
4031 print "<td>$mode_chng</td>\n";
4032 print "<td class=\"link\">";
4033 if ($action eq 'commitdiff') {
4036 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4039 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4040 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4043 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4044 file_name
=>$diff->{'file'})},
4047 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4048 file_name
=>$diff->{'file'})},
4052 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4053 my $mode_chnge = "";
4054 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4055 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4056 if ($from_file_type ne $to_file_type) {
4057 $mode_chnge .= " from $from_file_type to $to_file_type";
4059 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4060 if ($from_mode_str && $to_mode_str) {
4061 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4062 } elsif ($to_mode_str) {
4063 $mode_chnge .= " mode: $to_mode_str";
4066 $mode_chnge .= "]</span>\n";
4069 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4070 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4071 -class => "list"}, esc_path
($diff->{'file'}));
4073 print "<td>$mode_chnge</td>\n";
4074 print "<td class=\"link\">";
4075 if ($action eq 'commitdiff') {
4078 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4080 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4081 # "commit" view and modified file (not onlu mode changed)
4082 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4083 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4084 hash_base
=>$hash, hash_parent_base
=>$parent,
4085 file_name
=>$diff->{'file'})},
4089 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4090 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4093 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4094 file_name
=>$diff->{'file'})},
4097 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4098 file_name
=>$diff->{'file'})},
4102 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4103 my %status_name = ('R' => 'moved', 'C' => 'copied');
4104 my $nstatus = $status_name{$diff->{'status'}};
4106 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4107 # mode also for directories, so we cannot use $to_mode_str
4108 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4111 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4112 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4113 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4114 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4115 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4116 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4117 -class => "list"}, esc_path
($diff->{'from_file'})) .
4118 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4119 "<td class=\"link\">";
4120 if ($action eq 'commitdiff') {
4123 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4125 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4126 # "commit" view and modified file (not only pure rename or copy)
4127 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4128 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4129 hash_base
=>$hash, hash_parent_base
=>$parent,
4130 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4134 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4135 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4138 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4139 file_name
=>$diff->{'to_file'})},
4142 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4143 file_name
=>$diff->{'to_file'})},
4147 } # we should not encounter Unmerged (U) or Unknown (X) status
4150 print "</tbody>" if $has_header;
4154 sub git_patchset_body
{
4155 my ($fd, $difftree, $hash, @hash_parents) = @_;
4156 my ($hash_parent) = $hash_parents[0];
4158 my $is_combined = (@hash_parents > 1);
4160 my $patch_number = 0;
4166 print "<div class=\"patchset\">\n";
4168 # skip to first patch
4169 while ($patch_line = <$fd>) {
4172 last if ($patch_line =~ m/^diff /);
4176 while ($patch_line) {
4178 # parse "git diff" header line
4179 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4180 # $1 is from_name, which we do not use
4181 $to_name = unquote
($2);
4182 $to_name =~ s!^b/!!;
4183 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4184 # $1 is 'cc' or 'combined', which we do not use
4185 $to_name = unquote
($2);
4190 # check if current patch belong to current raw line
4191 # and parse raw git-diff line if needed
4192 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4193 # this is continuation of a split patch
4194 print "<div class=\"patch cont\">\n";
4196 # advance raw git-diff output if needed
4197 $patch_idx++ if defined $diffinfo;
4199 # read and prepare patch information
4200 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4202 # compact combined diff output can have some patches skipped
4203 # find which patch (using pathname of result) we are at now;
4205 while ($to_name ne $diffinfo->{'to_file'}) {
4206 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4207 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4208 "</div>\n"; # class="patch"
4213 last if $patch_idx > $#$difftree;
4214 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4218 # modifies %from, %to hashes
4219 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4221 # this is first patch for raw difftree line with $patch_idx index
4222 # we index @$difftree array from 0, but number patches from 1
4223 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4227 #assert($patch_line =~ m/^diff /) if DEBUG;
4228 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4230 # print "git diff" header
4231 print format_git_diff_header_line
($patch_line, $diffinfo,
4234 # print extended diff header
4235 print "<div class=\"diff extended_header\">\n";
4237 while ($patch_line = <$fd>) {
4240 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4242 print format_extended_diff_header_line
($patch_line, $diffinfo,
4245 print "</div>\n"; # class="diff extended_header"
4247 # from-file/to-file diff header
4248 if (! $patch_line) {
4249 print "</div>\n"; # class="patch"
4252 next PATCH
if ($patch_line =~ m/^diff /);
4253 #assert($patch_line =~ m/^---/) if DEBUG;
4255 my $last_patch_line = $patch_line;
4256 $patch_line = <$fd>;
4258 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4260 print format_diff_from_to_header
($last_patch_line, $patch_line,
4261 $diffinfo, \
%from, \
%to,
4266 while ($patch_line = <$fd>) {
4269 next PATCH
if ($patch_line =~ m/^diff /);
4271 print format_diff_line
($patch_line, \
%from, \
%to);
4275 print "</div>\n"; # class="patch"
4278 # for compact combined (--cc) format, with chunk and patch simpliciaction
4279 # patchset might be empty, but there might be unprocessed raw lines
4280 for (++$patch_idx if $patch_number > 0;
4281 $patch_idx < @$difftree;
4283 # read and prepare patch information
4284 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4286 # generate anchor for "patch" links in difftree / whatchanged part
4287 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4288 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4289 "</div>\n"; # class="patch"
4294 if ($patch_number == 0) {
4295 if (@hash_parents > 1) {
4296 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4298 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4302 print "</div>\n"; # class="patchset"
4305 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4307 # fills project list info (age, description, owner, forks) for each
4308 # project in the list, removing invalid projects from returned list
4309 # NOTE: modifies $projlist, but does not remove entries from it
4310 sub fill_project_list_info
{
4311 my ($projlist, $check_forks) = @_;
4314 my $show_ctags = gitweb_check_feature
('ctags');
4316 foreach my $pr (@$projlist) {
4317 my (@activity) = git_get_last_activity
($pr->{'path'});
4318 unless (@activity) {
4321 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4322 if (!defined $pr->{'descr'}) {
4323 my $descr = git_get_project_description
($pr->{'path'}) || "";
4324 $descr = to_utf8
($descr);
4325 $pr->{'descr_long'} = $descr;
4326 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4328 if (!defined $pr->{'owner'}) {
4329 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4332 my $pname = $pr->{'path'};
4333 if (($pname =~ s/\.git$//) &&
4334 ($pname !~ /\/$/) &&
4335 (-d
"$projectroot/$pname")) {
4336 $pr->{'forks'} = "-d $projectroot/$pname";
4341 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4342 push @projects, $pr;
4348 # print 'sort by' <th> element, generating 'sort by $name' replay link
4349 # if that order is not selected
4351 my ($name, $order, $header) = @_;
4352 $header ||= ucfirst($name);
4354 if ($order eq $name) {
4355 print "<th>$header</th>\n";
4358 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4359 -class => "header"}, $header) .
4364 sub git_project_list_body
{
4365 # actually uses global variable $project
4366 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4368 my $check_forks = gitweb_check_feature
('forks');
4369 my @projects = fill_project_list_info
($projlist, $check_forks);
4371 $order ||= $default_projects_order;
4372 $from = 0 unless defined $from;
4373 $to = $#projects if (!defined $to || $#projects < $to);
4376 project
=> { key
=> 'path', type
=> 'str' },
4377 descr
=> { key
=> 'descr_long', type
=> 'str' },
4378 owner
=> { key
=> 'owner', type
=> 'str' },
4379 age
=> { key
=> 'age', type
=> 'num' }
4381 my $oi = $order_info{$order};
4382 if ($oi->{'type'} eq 'str') {
4383 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4385 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4388 my $show_ctags = gitweb_check_feature
('ctags');
4391 foreach my $p (@projects) {
4392 foreach my $ct (keys %{$p->{'ctags'}}) {
4393 $ctags{$ct} += $p->{'ctags'}->{$ct};
4396 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4397 print git_show_project_tagcloud
($cloud, 64);
4400 print "<table class=\"project_list\">\n";
4401 unless ($no_header) {
4404 print "<th></th>\n";
4406 print_sort_th
('project', $order, 'Project');
4407 print_sort_th
('descr', $order, 'Description');
4408 print_sort_th
('owner', $order, 'Owner');
4409 print_sort_th
('age', $order, 'Last Change');
4410 print "<th></th>\n" . # for links
4414 my $tagfilter = $cgi->param('by_tag');
4415 for (my $i = $from; $i <= $to; $i++) {
4416 my $pr = $projects[$i];
4418 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4419 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4420 and not $pr->{'descr_long'} =~ /$searchtext/;
4421 # Weed out forks or non-matching entries of search
4423 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4424 $forkbase="^$forkbase" if $forkbase;
4425 next if not $searchtext and not $tagfilter and $show_ctags
4426 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4430 print "<tr class=\"dark\">\n";
4432 print "<tr class=\"light\">\n";
4437 if ($pr->{'forks'}) {
4438 print "<!-- $pr->{'forks'} -->\n";
4439 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4443 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4444 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4445 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4446 -class => "list", -title
=> $pr->{'descr_long'}},
4447 esc_html
($pr->{'descr'})) . "</td>\n" .
4448 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4449 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4450 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4451 "<td class=\"link\">" .
4452 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4453 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4454 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4455 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4456 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4460 if (defined $extra) {
4463 print "<td></td>\n";
4465 print "<td colspan=\"5\">$extra</td>\n" .
4472 # uses global variable $project
4473 my ($commitlist, $from, $to, $refs, $extra) = @_;
4475 $from = 0 unless defined $from;
4476 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4478 for (my $i = 0; $i <= $to; $i++) {
4479 my %co = %{$commitlist->[$i]};
4481 my $commit = $co{'id'};
4482 my $ref = format_ref_marker
($refs, $commit);
4483 my %ad = parse_date
($co{'author_epoch'});
4484 git_print_header_div
('commit',
4485 "<span class=\"age\">$co{'age_string'}</span>" .
4486 esc_html
($co{'title'}) . $ref,
4488 print "<div class=\"title_text\">\n" .
4489 "<div class=\"log_link\">\n" .
4490 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4492 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4497 git_print_authorship
(\
%co, -tag
=> 'span');
4498 print "<br/>\n</div>\n";
4500 print "<div class=\"log_body\">\n";
4501 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4505 print "<div class=\"page_nav\">\n";
4511 sub git_shortlog_body
{
4512 # uses global variable $project
4513 my ($commitlist, $from, $to, $refs, $extra) = @_;
4515 $from = 0 unless defined $from;
4516 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4518 print "<table class=\"shortlog\">\n";
4520 for (my $i = $from; $i <= $to; $i++) {
4521 my %co = %{$commitlist->[$i]};
4522 my $commit = $co{'id'};
4523 my $ref = format_ref_marker
($refs, $commit);
4525 print "<tr class=\"dark\">\n";
4527 print "<tr class=\"light\">\n";
4530 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4531 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4532 format_author_html
('td', \
%co, 10) . "<td>";
4533 print format_subject_html
($co{'title'}, $co{'title_short'},
4534 href
(action
=>"commit", hash
=>$commit), $ref);
4536 "<td class=\"link\">" .
4537 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4538 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4539 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4540 my $snapshot_links = format_snapshot_links
($commit);
4541 if (defined $snapshot_links) {
4542 print " | " . $snapshot_links;
4547 if (defined $extra) {
4549 "<td colspan=\"4\">$extra</td>\n" .
4555 sub git_history_body
{
4556 # Warning: assumes constant type (blob or tree) during history
4557 my ($commitlist, $from, $to, $refs, $extra,
4558 $file_name, $file_hash, $ftype) = @_;
4560 $from = 0 unless defined $from;
4561 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4563 print "<table class=\"history\">\n";
4565 for (my $i = $from; $i <= $to; $i++) {
4566 my %co = %{$commitlist->[$i]};
4570 my $commit = $co{'id'};
4572 my $ref = format_ref_marker
($refs, $commit);
4575 print "<tr class=\"dark\">\n";
4577 print "<tr class=\"light\">\n";
4580 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4581 # shortlog: format_author_html('td', \%co, 10)
4582 format_author_html
('td', \
%co, 15, 3) . "<td>";
4583 # originally git_history used chop_str($co{'title'}, 50)
4584 print format_subject_html
($co{'title'}, $co{'title_short'},
4585 href
(action
=>"commit", hash
=>$commit), $ref);
4587 "<td class=\"link\">" .
4588 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4589 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4591 if ($ftype eq 'blob') {
4592 my $blob_current = $file_hash;
4593 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4594 if (defined $blob_current && defined $blob_parent &&
4595 $blob_current ne $blob_parent) {
4597 $cgi->a({-href
=> href
(action
=>"blobdiff",
4598 hash
=>$blob_current, hash_parent
=>$blob_parent,
4599 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4600 file_name
=>$file_name)},
4607 if (defined $extra) {
4609 "<td colspan=\"4\">$extra</td>\n" .
4616 # uses global variable $project
4617 my ($taglist, $from, $to, $extra) = @_;
4618 $from = 0 unless defined $from;
4619 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4621 print "<table class=\"tags\">\n";
4623 for (my $i = $from; $i <= $to; $i++) {
4624 my $entry = $taglist->[$i];
4626 my $comment = $tag{'subject'};
4628 if (defined $comment) {
4629 $comment_short = chop_str
($comment, 30, 5);
4632 print "<tr class=\"dark\">\n";
4634 print "<tr class=\"light\">\n";
4637 if (defined $tag{'age'}) {
4638 print "<td><i>$tag{'age'}</i></td>\n";
4640 print "<td></td>\n";
4643 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4644 -class => "list name"}, esc_html
($tag{'name'})) .
4647 if (defined $comment) {
4648 print format_subject_html
($comment, $comment_short,
4649 href
(action
=>"tag", hash
=>$tag{'id'}));
4652 "<td class=\"selflink\">";
4653 if ($tag{'type'} eq "tag") {
4654 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4659 "<td class=\"link\">" . " | " .
4660 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4661 if ($tag{'reftype'} eq "commit") {
4662 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4663 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4664 } elsif ($tag{'reftype'} eq "blob") {
4665 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4670 if (defined $extra) {
4672 "<td colspan=\"5\">$extra</td>\n" .
4678 sub git_heads_body
{
4679 # uses global variable $project
4680 my ($headlist, $head, $from, $to, $extra) = @_;
4681 $from = 0 unless defined $from;
4682 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4684 print "<table class=\"heads\">\n";
4686 for (my $i = $from; $i <= $to; $i++) {
4687 my $entry = $headlist->[$i];
4689 my $curr = $ref{'id'} eq $head;
4691 print "<tr class=\"dark\">\n";
4693 print "<tr class=\"light\">\n";
4696 print "<td><i>$ref{'age'}</i></td>\n" .
4697 ($curr ? "<td class=\"current_head\">" : "<td>") .
4698 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4699 -class => "list name"},esc_html
($ref{'name'})) .
4701 "<td class=\"link\">" .
4702 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4703 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4704 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4708 if (defined $extra) {
4710 "<td colspan=\"3\">$extra</td>\n" .
4716 sub git_search_grep_body
{
4717 my ($commitlist, $from, $to, $extra) = @_;
4718 $from = 0 unless defined $from;
4719 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4721 print "<table class=\"commit_search\">\n";
4723 for (my $i = $from; $i <= $to; $i++) {
4724 my %co = %{$commitlist->[$i]};
4728 my $commit = $co{'id'};
4730 print "<tr class=\"dark\">\n";
4732 print "<tr class=\"light\">\n";
4735 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4736 format_author_html
('td', \
%co, 15, 5) .
4738 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4739 -class => "list subject"},
4740 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4741 my $comment = $co{'comment'};
4742 foreach my $line (@$comment) {
4743 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4744 my ($lead, $match, $trail) = ($1, $2, $3);
4745 $match = chop_str
($match, 70, 5, 'center');
4746 my $contextlen = int((80 - length($match))/2);
4747 $contextlen = 30 if ($contextlen > 30);
4748 $lead = chop_str
($lead, $contextlen, 10, 'left');
4749 $trail = chop_str
($trail, $contextlen, 10, 'right');
4751 $lead = esc_html
($lead);
4752 $match = esc_html
($match);
4753 $trail = esc_html
($trail);
4755 print "$lead<span class=\"match\">$match</span>$trail<br />";
4759 "<td class=\"link\">" .
4760 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4762 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4764 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4768 if (defined $extra) {
4770 "<td colspan=\"3\">$extra</td>\n" .
4776 ## ======================================================================
4777 ## ======================================================================
4780 sub git_project_list
{
4781 my $order = $input_params{'order'};
4782 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4783 die_error
(400, "Unknown order parameter");
4786 my @list = git_get_projects_list
();
4788 die_error
(404, "No projects found");
4792 if (defined $home_text && -f
$home_text) {
4793 print "<div class=\"index_include\">\n";
4794 insert_file
($home_text);
4797 print $cgi->startform(-method => "get") .
4798 "<p class=\"projsearch\">Search:\n" .
4799 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4801 $cgi->end_form() . "\n";
4802 git_project_list_body
(\
@list, $order);
4807 my $order = $input_params{'order'};
4808 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4809 die_error
(400, "Unknown order parameter");
4812 my @list = git_get_projects_list
($project);
4814 die_error
(404, "No forks found");
4818 git_print_page_nav
('','');
4819 git_print_header_div
('summary', "$project forks");
4820 git_project_list_body
(\
@list, $order);
4824 sub git_project_index
{
4825 my @projects = git_get_projects_list
($project);
4828 -type
=> 'text/plain',
4829 -charset
=> 'utf-8',
4830 -content_disposition
=> 'inline; filename="index.aux"');
4832 foreach my $pr (@projects) {
4833 if (!exists $pr->{'owner'}) {
4834 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4837 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4838 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4839 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4840 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4844 print "$path $owner\n";
4849 my $descr = git_get_project_description
($project) || "none";
4850 my %co = parse_commit
("HEAD");
4851 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4852 my $head = $co{'id'};
4854 my $owner = git_get_project_owner
($project);
4856 my $refs = git_get_references
();
4857 # These get_*_list functions return one more to allow us to see if
4858 # there are more ...
4859 my @taglist = git_get_tags_list
(16);
4860 my @headlist = git_get_heads_list
(16);
4862 my $check_forks = gitweb_check_feature
('forks');
4865 @forklist = git_get_projects_list
($project);
4869 git_print_page_nav
('summary','', $head);
4871 print "<div class=\"title\"> </div>\n";
4872 print "<table class=\"projects_list\">\n" .
4873 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4874 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4875 if (defined $cd{'rfc2822'}) {
4876 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4879 # use per project git URL list in $projectroot/$project/cloneurl
4880 # or make project git URL from git base URL and project name
4881 my $url_tag = "URL";
4882 my @url_list = git_get_project_url_list
($project);
4883 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4884 foreach my $git_url (@url_list) {
4885 next unless $git_url;
4886 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4891 my $show_ctags = gitweb_check_feature
('ctags');
4893 my $ctags = git_get_project_ctags
($project);
4894 my $cloud = git_populate_project_tagcloud
($ctags);
4895 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4896 print "</td>\n<td>" unless %$ctags;
4897 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4898 print "</td>\n<td>" if %$ctags;
4899 print git_show_project_tagcloud
($cloud, 48);
4905 # If XSS prevention is on, we don't include README.html.
4906 # TODO: Allow a readme in some safe format.
4907 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4908 print "<div class=\"title\">readme</div>\n" .
4909 "<div class=\"readme\">\n";
4910 insert_file
("$projectroot/$project/README.html");
4911 print "\n</div>\n"; # class="readme"
4914 # we need to request one more than 16 (0..15) to check if
4916 my @commitlist = $head ? parse_commits
($head, 17) : ();
4918 git_print_header_div
('shortlog');
4919 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4920 $#commitlist <= 15 ? undef :
4921 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4925 git_print_header_div
('tags');
4926 git_tags_body
(\
@taglist, 0, 15,
4927 $#taglist <= 15 ? undef :
4928 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4932 git_print_header_div
('heads');
4933 git_heads_body
(\
@headlist, $head, 0, 15,
4934 $#headlist <= 15 ? undef :
4935 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4939 git_print_header_div
('forks');
4940 git_project_list_body
(\
@forklist, 'age', 0, 15,
4941 $#forklist <= 15 ? undef :
4942 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4950 my $head = git_get_head_hash
($project);
4952 git_print_page_nav
('','', $head,undef,$head);
4953 my %tag = parse_tag
($hash);
4956 die_error
(404, "Unknown tag object");
4959 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4960 print "<div class=\"title_text\">\n" .
4961 "<table class=\"object_header\">\n" .
4963 "<td>object</td>\n" .
4964 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4965 $tag{'object'}) . "</td>\n" .
4966 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4967 $tag{'type'}) . "</td>\n" .
4969 if (defined($tag{'author'})) {
4970 git_print_authorship_rows
(\
%tag, 'author');
4972 print "</table>\n\n" .
4974 print "<div class=\"page_body\">";
4975 my $comment = $tag{'comment'};
4976 foreach my $line (@$comment) {
4978 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4984 sub git_blame_common
{
4985 my $format = shift || 'porcelain';
4986 if ($format eq 'porcelain' && $cgi->param('js')) {
4987 $format = 'incremental';
4988 $action = 'blame_incremental'; # for page title etc
4992 gitweb_check_feature
('blame')
4993 or die_error
(403, "Blame view not allowed");
4996 die_error
(400, "No file name given") unless $file_name;
4997 $hash_base ||= git_get_head_hash
($project);
4998 die_error
(404, "Couldn't find base commit") unless $hash_base;
4999 my %co = parse_commit
($hash_base)
5000 or die_error
(404, "Commit not found");
5002 if (!defined $hash) {
5003 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5004 or die_error
(404, "Error looking up file");
5006 $ftype = git_get_type
($hash);
5007 if ($ftype !~ "blob") {
5008 die_error
(400, "Object is not a blob");
5013 if ($format eq 'incremental') {
5014 # get file contents (as base)
5015 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5016 or die_error
(500, "Open git-cat-file failed");
5017 } elsif ($format eq 'data') {
5018 # run git-blame --incremental
5019 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5020 $hash_base, "--", $file_name
5021 or die_error
(500, "Open git-blame --incremental failed");
5023 # run git-blame --porcelain
5024 open $fd, "-|", git_cmd
(), "blame", '-p',
5025 $hash_base, '--', $file_name
5026 or die_error
(500, "Open git-blame --porcelain failed");
5029 # incremental blame data returns early
5030 if ($format eq 'data') {
5032 -type
=>"text/plain", -charset
=> "utf-8",
5033 -status
=> "200 OK");
5034 local $| = 1; # output autoflush
5037 or print "ERROR $!\n";
5040 if (defined $t0 && gitweb_check_feature
('timed')) {
5042 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5043 ' '.$number_of_git_cmds;
5053 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5056 if ($format eq 'incremental') {
5058 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5059 "blame") . " (non-incremental)";
5062 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5063 "blame") . " (incremental)";
5067 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5070 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5072 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5073 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5074 git_print_page_path
($file_name, $ftype, $hash_base);
5077 if ($format eq 'incremental') {
5078 print "<noscript>\n<div class=\"error\"><center><b>\n".
5079 "This page requires JavaScript to run.\n Use ".
5080 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5083 "</b></center></div>\n</noscript>\n";
5085 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5088 print qq
!<div
class="page_body">\n!;
5089 print qq
!<div id
="progress_info">... / ...</div
>\n!
5090 if ($format eq 'incremental');
5091 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5092 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5094 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5098 my @rev_color = qw(light dark);
5099 my $num_colors = scalar(@rev_color);
5100 my $current_color = 0;
5102 if ($format eq 'incremental') {
5103 my $color_class = $rev_color[$current_color];
5108 while (my $line = <$fd>) {
5112 print qq
!<tr id
="l$linenr" class="$color_class">!.
5113 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5114 qq
!<td
class="linenr">!.
5115 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5116 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5120 } else { # porcelain, i.e. ordinary blame
5121 my %metainfo = (); # saves information about commits
5125 while (my $line = <$fd>) {
5127 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5128 # no <lines in group> for subsequent lines in group of lines
5129 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5130 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5131 if (!exists $metainfo{$full_rev}) {
5132 $metainfo{$full_rev} = { 'nprevious' => 0 };
5134 my $meta = $metainfo{$full_rev};
5136 while ($data = <$fd>) {
5138 last if ($data =~ s/^\t//); # contents of line
5139 if ($data =~ /^(\S+)(?: (.*))?$/) {
5140 $meta->{$1} = $2 unless exists $meta->{$1};
5142 if ($data =~ /^previous /) {
5143 $meta->{'nprevious'}++;
5146 my $short_rev = substr($full_rev, 0, 8);
5147 my $author = $meta->{'author'};
5149 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5150 my $date = $date{'iso-tz'};
5152 $current_color = ($current_color + 1) % $num_colors;
5154 my $tr_class = $rev_color[$current_color];
5155 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5156 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5157 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5158 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5160 print "<td class=\"sha1\"";
5161 print " title=\"". esc_html
($author) . ", $date\"";
5162 print " rowspan=\"$group_size\"" if ($group_size > 1);
5164 print $cgi->a({-href
=> href
(action
=>"commit",
5166 file_name
=>$file_name)},
5167 esc_html
($short_rev));
5168 if ($group_size >= 2) {
5169 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5170 if (@author_initials) {
5172 esc_html
(join('', @author_initials));
5178 # 'previous' <sha1 of parent commit> <filename at commit>
5179 if (exists $meta->{'previous'} &&
5180 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5181 $meta->{'parent'} = $1;
5182 $meta->{'file_parent'} = unquote
($2);
5185 exists($meta->{'parent'}) ?
5186 $meta->{'parent'} : $full_rev;
5187 my $linenr_filename =
5188 exists($meta->{'file_parent'}) ?
5189 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5190 my $blamed = href
(action
=> 'blame',
5191 file_name
=> $linenr_filename,
5192 hash_base
=> $linenr_commit);
5193 print "<td class=\"linenr\">";
5194 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5195 -class => "linenr" },
5198 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5206 "</table>\n"; # class="blame"
5207 print "</div>\n"; # class="blame_body"
5209 or print "Reading blob failed\n";
5218 sub git_blame_incremental
{
5219 git_blame_common
('incremental');
5222 sub git_blame_data
{
5223 git_blame_common
('data');
5227 my $head = git_get_head_hash
($project);
5229 git_print_page_nav
('','', $head,undef,$head);
5230 git_print_header_div
('summary', $project);
5232 my @tagslist = git_get_tags_list
();
5234 git_tags_body
(\
@tagslist);
5240 my $head = git_get_head_hash
($project);
5242 git_print_page_nav
('','', $head,undef,$head);
5243 git_print_header_div
('summary', $project);
5245 my @headslist = git_get_heads_list
();
5247 git_heads_body
(\
@headslist, $head);
5252 sub git_blob_plain
{
5256 if (!defined $hash) {
5257 if (defined $file_name) {
5258 my $base = $hash_base || git_get_head_hash
($project);
5259 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5260 or die_error
(404, "Cannot find file");
5262 die_error
(400, "No file name defined");
5264 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5265 # blobs defined by non-textual hash id's can be cached
5269 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5270 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5272 # content-type (can include charset)
5273 $type = blob_contenttype
($fd, $file_name, $type);
5275 # "save as" filename, even when no $file_name is given
5276 my $save_as = "$hash";
5277 if (defined $file_name) {
5278 $save_as = $file_name;
5279 } elsif ($type =~ m/^text\//) {
5283 # With XSS prevention on, blobs of all types except a few known safe
5284 # ones are served with "Content-Disposition: attachment" to make sure
5285 # they don't run in our security domain. For certain image types,
5286 # blob view writes an <img> tag referring to blob_plain view, and we
5287 # want to be sure not to break that by serving the image as an
5288 # attachment (though Firefox 3 doesn't seem to care).
5289 my $sandbox = $prevent_xss &&
5290 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5294 -expires
=> $expires,
5295 -content_disposition
=>
5296 ($sandbox ? 'attachment' : 'inline')
5297 . '; filename="' . $save_as . '"');
5299 binmode STDOUT
, ':raw';
5301 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5308 if (!defined $hash) {
5309 if (defined $file_name) {
5310 my $base = $hash_base || git_get_head_hash
($project);
5311 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5312 or die_error
(404, "Cannot find file");
5314 die_error
(400, "No file name defined");
5316 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5317 # blobs defined by non-textual hash id's can be cached
5321 my $have_blame = gitweb_check_feature
('blame');
5322 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5323 or die_error
(500, "Couldn't cat $file_name, $hash");
5324 my $mimetype = blob_mimetype
($fd, $file_name);
5325 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5327 return git_blob_plain
($mimetype);
5329 # we can have blame only for text/* mimetype
5330 $have_blame &&= ($mimetype =~ m!^text/!);
5332 git_header_html
(undef, $expires);
5333 my $formats_nav = '';
5334 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5335 if (defined $file_name) {
5338 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5343 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5346 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5349 $cgi->a({-href
=> href
(action
=>"blob",
5350 hash_base
=>"HEAD", file_name
=>$file_name)},
5354 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5357 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5358 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5360 print "<div class=\"page_nav\">\n" .
5361 "<br/><br/></div>\n" .
5362 "<div class=\"title\">$hash</div>\n";
5364 git_print_page_path
($file_name, "blob", $hash_base);
5365 print "<div class=\"page_body\">\n";
5366 if ($mimetype =~ m!^image/!) {
5367 print qq
!<img type
="$mimetype"!;
5369 print qq
! alt
="$file_name" title
="$file_name"!;
5372 href(action=>"blob_plain
", hash=>$hash,
5373 hash_base=>$hash_base, file_name=>$file_name) .
5377 while (my $line = <$fd>) {
5380 $line = untabify
($line);
5381 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5382 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5383 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5387 or print "Reading blob failed.\n";
5393 if (!defined $hash_base) {
5394 $hash_base = "HEAD";
5396 if (!defined $hash) {
5397 if (defined $file_name) {
5398 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5403 die_error
(404, "No such tree") unless defined($hash);
5405 my $show_sizes = gitweb_check_feature
('show-sizes');
5406 my $have_blame = gitweb_check_feature
('blame');
5411 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5412 ($show_sizes ? '-l' : ()), @extra_options, $hash
5413 or die_error
(500, "Open git-ls-tree failed");
5414 @entries = map { chomp; $_ } <$fd>;
5416 or die_error
(404, "Reading tree failed");
5419 my $refs = git_get_references
();
5420 my $ref = format_ref_marker
($refs, $hash_base);
5423 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5425 if (defined $file_name) {
5427 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5429 $cgi->a({-href
=> href
(action
=>"tree",
5430 hash_base
=>"HEAD", file_name
=>$file_name)},
5433 my $snapshot_links = format_snapshot_links
($hash);
5434 if (defined $snapshot_links) {
5435 # FIXME: Should be available when we have no hash base as well.
5436 push @views_nav, $snapshot_links;
5438 git_print_page_nav
('tree','', $hash_base, undef, undef,
5439 join(' | ', @views_nav));
5440 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5443 print "<div class=\"page_nav\">\n";
5444 print "<br/><br/></div>\n";
5445 print "<div class=\"title\">$hash</div>\n";
5447 if (defined $file_name) {
5448 $basedir = $file_name;
5449 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5452 git_print_page_path
($file_name, 'tree', $hash_base);
5454 print "<div class=\"page_body\">\n";
5455 print "<table class=\"tree\">\n";
5457 # '..' (top directory) link if possible
5458 if (defined $hash_base &&
5459 defined $file_name && $file_name =~ m![^/]+$!) {
5461 print "<tr class=\"dark\">\n";
5463 print "<tr class=\"light\">\n";
5467 my $up = $file_name;
5468 $up =~ s!/?[^/]+$!!;
5469 undef $up unless $up;
5470 # based on git_print_tree_entry
5471 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5472 print '<td class="size"> </td>'."\n" if $show_sizes;
5473 print '<td class="list">';
5474 print $cgi->a({-href
=> href
(action
=>"tree",
5475 hash_base
=>$hash_base,
5479 print "<td class=\"link\"></td>\n";
5483 foreach my $line (@entries) {
5484 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5487 print "<tr class=\"dark\">\n";
5489 print "<tr class=\"light\">\n";
5493 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5497 print "</table>\n" .
5503 my ($project, $hash) = @_;
5505 # path/to/project.git -> project
5506 # path/to/project/.git -> project
5507 my $name = to_utf8
($project);
5508 $name =~ s
,([^/])/*\
.git
$,$1,;
5509 $name = basename
($name);
5511 $name =~ s/[[:cntrl:]]/?/g;
5514 if ($hash =~ /^[0-9a-fA-F]+$/) {
5515 # shorten SHA-1 hash
5516 my $full_hash = git_get_full_hash
($project, $hash);
5517 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5518 $ver = git_get_short_hash
($project, $hash);
5520 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5521 # tags don't need shortened SHA-1 hash
5524 # branches and other need shortened SHA-1 hash
5525 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5528 $ver .= '-' . git_get_short_hash
($project, $hash);
5530 # in case of hierarchical branch names
5533 # name = project-version_string
5534 $name = "$name-$ver";
5536 return wantarray ? ($name, $name) : $name;
5540 my $format = $input_params{'snapshot_format'};
5541 if (!@snapshot_fmts) {
5542 die_error
(403, "Snapshots not allowed");
5544 # default to first supported snapshot format
5545 $format ||= $snapshot_fmts[0];
5546 if ($format !~ m/^[a-z0-9]+$/) {
5547 die_error
(400, "Invalid snapshot format parameter");
5548 } elsif (!exists($known_snapshot_formats{$format})) {
5549 die_error
(400, "Unknown snapshot format");
5550 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5551 die_error
(403, "Snapshot format not allowed");
5552 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5553 die_error
(403, "Unsupported snapshot format");
5556 my $type = git_get_type
("$hash^{}");
5558 die_error
(404, 'Object does not exist');
5559 } elsif ($type eq 'blob') {
5560 die_error
(400, 'Object is not a tree-ish');
5563 my ($name, $prefix) = snapshot_name
($project, $hash);
5564 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5565 my $cmd = quote_command
(
5566 git_cmd
(), 'archive',
5567 "--format=$known_snapshot_formats{$format}{'format'}",
5568 "--prefix=$prefix/", $hash);
5569 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5570 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5573 $filename =~ s/(["\\])/\\$1/g;
5575 -type
=> $known_snapshot_formats{$format}{'type'},
5576 -content_disposition
=> 'inline; filename="' . $filename . '"',
5577 -status
=> '200 OK');
5579 open my $fd, "-|", $cmd
5580 or die_error
(500, "Execute git-archive failed");
5581 binmode STDOUT
, ':raw';
5583 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5587 sub git_log_generic
{
5588 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5590 my $head = git_get_head_hash
($project);
5591 if (!defined $base) {
5594 if (!defined $page) {
5597 my $refs = git_get_references
();
5599 my $commit_hash = $base;
5600 if (defined $parent) {
5601 $commit_hash = "$parent..$base";
5604 parse_commits
($commit_hash, 101, (100 * $page),
5605 defined $file_name ? ($file_name, "--full-history") : ());
5608 if (!defined $file_hash && defined $file_name) {
5609 # some commits could have deleted file in question,
5610 # and not have it in tree, but one of them has to have it
5611 for (my $i = 0; $i < @commitlist; $i++) {
5612 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5613 last if defined $file_hash;
5616 if (defined $file_hash) {
5617 $ftype = git_get_type
($file_hash);
5619 if (defined $file_name && !defined $ftype) {
5620 die_error
(500, "Unknown type of object");
5623 if (defined $file_name) {
5624 %co = parse_commit
($base)
5625 or die_error
(404, "Unknown commit object");
5629 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5631 if ($#commitlist >= 100) {
5633 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5634 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5636 my $patch_max = gitweb_get_feature
('patches');
5637 if ($patch_max && !defined $file_name) {
5638 if ($patch_max < 0 || @commitlist <= $patch_max) {
5639 $paging_nav .= " ⋅ " .
5640 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5646 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5647 if (defined $file_name) {
5648 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5650 git_print_header_div
('summary', $project)
5652 git_print_page_path
($file_name, $ftype, $hash_base)
5653 if (defined $file_name);
5655 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5656 $file_name, $file_hash, $ftype);
5662 git_log_generic
('log', \
&git_log_body
,
5663 $hash, $hash_parent);
5667 $hash ||= $hash_base || "HEAD";
5668 my %co = parse_commit
($hash)
5669 or die_error
(404, "Unknown commit object");
5671 my $parent = $co{'parent'};
5672 my $parents = $co{'parents'}; # listref
5674 # we need to prepare $formats_nav before any parameter munging
5676 if (!defined $parent) {
5678 $formats_nav .= '(initial)';
5679 } elsif (@$parents == 1) {
5680 # single parent commit
5683 $cgi->a({-href
=> href
(action
=>"commit",
5685 esc_html
(substr($parent, 0, 7))) .
5692 $cgi->a({-href
=> href
(action
=>"commit",
5694 esc_html
(substr($_, 0, 7)));
5698 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5699 $formats_nav .= " | " .
5700 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5704 if (!defined $parent) {
5708 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5710 (@$parents <= 1 ? $parent : '-c'),
5712 or die_error
(500, "Open git-diff-tree failed");
5713 @difftree = map { chomp; $_ } <$fd>;
5714 close $fd or die_error
(404, "Reading git-diff-tree failed");
5716 # non-textual hash id's can be cached
5718 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5721 my $refs = git_get_references
();
5722 my $ref = format_ref_marker
($refs, $co{'id'});
5724 git_header_html
(undef, $expires);
5725 git_print_page_nav
('commit', '',
5726 $hash, $co{'tree'}, $hash,
5729 if (defined $co{'parent'}) {
5730 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5732 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5734 print "<div class=\"title_text\">\n" .
5735 "<table class=\"object_header\">\n";
5736 git_print_authorship_rows
(\
%co);
5737 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5740 "<td class=\"sha1\">" .
5741 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5742 class => "list"}, $co{'tree'}) .
5744 "<td class=\"link\">" .
5745 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5747 my $snapshot_links = format_snapshot_links
($hash);
5748 if (defined $snapshot_links) {
5749 print " | " . $snapshot_links;
5754 foreach my $par (@$parents) {
5757 "<td class=\"sha1\">" .
5758 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5759 class => "list"}, $par) .
5761 "<td class=\"link\">" .
5762 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5764 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5771 print "<div class=\"page_body\">\n";
5772 git_print_log
($co{'comment'});
5775 git_difftree_body
(\
@difftree, $hash, @$parents);
5781 # object is defined by:
5782 # - hash or hash_base alone
5783 # - hash_base and file_name
5786 # - hash or hash_base alone
5787 if ($hash || ($hash_base && !defined $file_name)) {
5788 my $object_id = $hash || $hash_base;
5790 open my $fd, "-|", quote_command
(
5791 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5792 or die_error
(404, "Object does not exist");
5796 or die_error
(404, "Object does not exist");
5798 # - hash_base and file_name
5799 } elsif ($hash_base && defined $file_name) {
5800 $file_name =~ s
,/+$,,;
5802 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5803 or die_error
(404, "Base object does not exist");
5805 # here errors should not hapen
5806 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5807 or die_error
(500, "Open git-ls-tree failed");
5811 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5812 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5813 die_error
(404, "File or directory for given base does not exist");
5818 die_error
(400, "Not enough information to find object");
5821 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5822 hash
=>$hash, hash_base
=>$hash_base,
5823 file_name
=>$file_name),
5824 -status
=> '302 Found');
5828 my $format = shift || 'html';
5835 # preparing $fd and %diffinfo for git_patchset_body
5837 if (defined $hash_base && defined $hash_parent_base) {
5838 if (defined $file_name) {
5840 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5841 $hash_parent_base, $hash_base,
5842 "--", (defined $file_parent ? $file_parent : ()), $file_name
5843 or die_error
(500, "Open git-diff-tree failed");
5844 @difftree = map { chomp; $_ } <$fd>;
5846 or die_error
(404, "Reading git-diff-tree failed");
5848 or die_error
(404, "Blob diff not found");
5850 } elsif (defined $hash &&
5851 $hash =~ /[0-9a-fA-F]{40}/) {
5852 # try to find filename from $hash
5854 # read filtered raw output
5855 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5856 $hash_parent_base, $hash_base, "--"
5857 or die_error
(500, "Open git-diff-tree failed");
5859 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5861 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5862 map { chomp; $_ } <$fd>;
5864 or die_error
(404, "Reading git-diff-tree failed");
5866 or die_error
(404, "Blob diff not found");
5869 die_error
(400, "Missing one of the blob diff parameters");
5872 if (@difftree > 1) {
5873 die_error
(400, "Ambiguous blob diff specification");
5876 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5877 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5878 $file_name ||= $diffinfo{'to_file'};
5880 $hash_parent ||= $diffinfo{'from_id'};
5881 $hash ||= $diffinfo{'to_id'};
5883 # non-textual hash id's can be cached
5884 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5885 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5890 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5891 '-p', ($format eq 'html' ? "--full-index" : ()),
5892 $hash_parent_base, $hash_base,
5893 "--", (defined $file_parent ? $file_parent : ()), $file_name
5894 or die_error
(500, "Open git-diff-tree failed");
5897 # old/legacy style URI -- not generated anymore since 1.4.3.
5899 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5903 if ($format eq 'html') {
5905 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5907 git_header_html
(undef, $expires);
5908 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5909 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5910 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5912 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5913 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5915 if (defined $file_name) {
5916 git_print_page_path
($file_name, "blob", $hash_base);
5918 print "<div class=\"page_path\"></div>\n";
5921 } elsif ($format eq 'plain') {
5923 -type
=> 'text/plain',
5924 -charset
=> 'utf-8',
5925 -expires
=> $expires,
5926 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5928 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5931 die_error
(400, "Unknown blobdiff format");
5935 if ($format eq 'html') {
5936 print "<div class=\"page_body\">\n";
5938 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5941 print "</div>\n"; # class="page_body"
5945 while (my $line = <$fd>) {
5946 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5947 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5951 last if $line =~ m!^\+\+\+!;
5959 sub git_blobdiff_plain
{
5960 git_blobdiff
('plain');
5963 sub git_commitdiff
{
5965 my $format = $params{-format
} || 'html';
5967 my ($patch_max) = gitweb_get_feature
('patches');
5968 if ($format eq 'patch') {
5969 die_error
(403, "Patch view not allowed") unless $patch_max;
5972 $hash ||= $hash_base || "HEAD";
5973 my %co = parse_commit
($hash)
5974 or die_error
(404, "Unknown commit object");
5976 # choose format for commitdiff for merge
5977 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5978 $hash_parent = '--cc';
5980 # we need to prepare $formats_nav before almost any parameter munging
5982 if ($format eq 'html') {
5984 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5986 if ($patch_max && @{$co{'parents'}} <= 1) {
5987 $formats_nav .= " | " .
5988 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5992 if (defined $hash_parent &&
5993 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5994 # commitdiff with two commits given
5995 my $hash_parent_short = $hash_parent;
5996 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5997 $hash_parent_short = substr($hash_parent, 0, 7);
6001 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
6002 if ($co{'parents'}[$i] eq $hash_parent) {
6003 $formats_nav .= ' parent ' . ($i+1);
6007 $formats_nav .= ': ' .
6008 $cgi->a({-href
=> href
(action
=>"commitdiff",
6009 hash
=>$hash_parent)},
6010 esc_html
($hash_parent_short)) .
6012 } elsif (!$co{'parent'}) {
6014 $formats_nav .= ' (initial)';
6015 } elsif (scalar @{$co{'parents'}} == 1) {
6016 # single parent commit
6019 $cgi->a({-href
=> href
(action
=>"commitdiff",
6020 hash
=>$co{'parent'})},
6021 esc_html
(substr($co{'parent'}, 0, 7))) .
6025 if ($hash_parent eq '--cc') {
6026 $formats_nav .= ' | ' .
6027 $cgi->a({-href
=> href
(action
=>"commitdiff",
6028 hash
=>$hash, hash_parent
=>'-c')},
6030 } else { # $hash_parent eq '-c'
6031 $formats_nav .= ' | ' .
6032 $cgi->a({-href
=> href
(action
=>"commitdiff",
6033 hash
=>$hash, hash_parent
=>'--cc')},
6039 $cgi->a({-href
=> href
(action
=>"commitdiff",
6041 esc_html
(substr($_, 0, 7)));
6042 } @{$co{'parents'}} ) .
6047 my $hash_parent_param = $hash_parent;
6048 if (!defined $hash_parent_param) {
6049 # --cc for multiple parents, --root for parentless
6050 $hash_parent_param =
6051 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6057 if ($format eq 'html') {
6058 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6059 "--no-commit-id", "--patch-with-raw", "--full-index",
6060 $hash_parent_param, $hash, "--"
6061 or die_error
(500, "Open git-diff-tree failed");
6063 while (my $line = <$fd>) {
6065 # empty line ends raw part of diff-tree output
6067 push @difftree, scalar parse_difftree_raw_line
($line);
6070 } elsif ($format eq 'plain') {
6071 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6072 '-p', $hash_parent_param, $hash, "--"
6073 or die_error
(500, "Open git-diff-tree failed");
6074 } elsif ($format eq 'patch') {
6075 # For commit ranges, we limit the output to the number of
6076 # patches specified in the 'patches' feature.
6077 # For single commits, we limit the output to a single patch,
6078 # diverging from the git-format-patch default.
6079 my @commit_spec = ();
6081 if ($patch_max > 0) {
6082 push @commit_spec, "-$patch_max";
6084 push @commit_spec, '-n', "$hash_parent..$hash";
6086 if ($params{-single
}) {
6087 push @commit_spec, '-1';
6089 if ($patch_max > 0) {
6090 push @commit_spec, "-$patch_max";
6092 push @commit_spec, "-n";
6094 push @commit_spec, '--root', $hash;
6096 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6097 '--stdout', @commit_spec
6098 or die_error
(500, "Open git-format-patch failed");
6100 die_error
(400, "Unknown commitdiff format");
6103 # non-textual hash id's can be cached
6105 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6109 # write commit message
6110 if ($format eq 'html') {
6111 my $refs = git_get_references
();
6112 my $ref = format_ref_marker
($refs, $co{'id'});
6114 git_header_html
(undef, $expires);
6115 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6116 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6117 print "<div class=\"title_text\">\n" .
6118 "<table class=\"object_header\">\n";
6119 git_print_authorship_rows
(\
%co);
6122 print "<div class=\"page_body\">\n";
6123 if (@{$co{'comment'}} > 1) {
6124 print "<div class=\"log\">\n";
6125 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6126 print "</div>\n"; # class="log"
6129 } elsif ($format eq 'plain') {
6130 my $refs = git_get_references
("tags");
6131 my $tagname = git_get_rev_name_tags
($hash);
6132 my $filename = basename
($project) . "-$hash.patch";
6135 -type
=> 'text/plain',
6136 -charset
=> 'utf-8',
6137 -expires
=> $expires,
6138 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6139 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6140 print "From: " . to_utf8
($co{'author'}) . "\n";
6141 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6142 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6144 print "X-Git-Tag: $tagname\n" if $tagname;
6145 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6147 foreach my $line (@{$co{'comment'}}) {
6148 print to_utf8
($line) . "\n";
6151 } elsif ($format eq 'patch') {
6152 my $filename = basename
($project) . "-$hash.patch";
6155 -type
=> 'text/plain',
6156 -charset
=> 'utf-8',
6157 -expires
=> $expires,
6158 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6162 if ($format eq 'html') {
6163 my $use_parents = !defined $hash_parent ||
6164 $hash_parent eq '-c' || $hash_parent eq '--cc';
6165 git_difftree_body
(\
@difftree, $hash,
6166 $use_parents ? @{$co{'parents'}} : $hash_parent);
6169 git_patchset_body
($fd, \
@difftree, $hash,
6170 $use_parents ? @{$co{'parents'}} : $hash_parent);
6172 print "</div>\n"; # class="page_body"
6175 } elsif ($format eq 'plain') {
6179 or print "Reading git-diff-tree failed\n";
6180 } elsif ($format eq 'patch') {
6184 or print "Reading git-format-patch failed\n";
6188 sub git_commitdiff_plain
{
6189 git_commitdiff
(-format
=> 'plain');
6192 # format-patch-style patches
6194 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6198 git_commitdiff
(-format
=> 'patch');
6202 git_log_generic
('history', \
&git_history_body
,
6203 $hash_base, $hash_parent_base,
6208 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6209 if (!defined $searchtext) {
6210 die_error
(400, "Text field is empty");
6212 if (!defined $hash) {
6213 $hash = git_get_head_hash
($project);
6215 my %co = parse_commit
($hash);
6217 die_error
(404, "Unknown commit object");
6219 if (!defined $page) {
6223 $searchtype ||= 'commit';
6224 if ($searchtype eq 'pickaxe') {
6225 # pickaxe may take all resources of your box and run for several minutes
6226 # with every query - so decide by yourself how public you make this feature
6227 gitweb_check_feature
('pickaxe')
6228 or die_error
(403, "Pickaxe is disabled");
6230 if ($searchtype eq 'grep') {
6231 gitweb_check_feature
('grep')[0]
6232 or die_error
(403, "Grep is disabled");
6237 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6239 if ($searchtype eq 'commit') {
6240 $greptype = "--grep=";
6241 } elsif ($searchtype eq 'author') {
6242 $greptype = "--author=";
6243 } elsif ($searchtype eq 'committer') {
6244 $greptype = "--committer=";
6246 $greptype .= $searchtext;
6247 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6248 $greptype, '--regexp-ignore-case',
6249 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6251 my $paging_nav = '';
6254 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6255 searchtext
=>$searchtext,
6256 searchtype
=>$searchtype)},
6258 $paging_nav .= " ⋅ " .
6259 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6260 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6262 $paging_nav .= "first";
6263 $paging_nav .= " ⋅ prev";
6266 if ($#commitlist >= 100) {
6268 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6269 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6270 $paging_nav .= " ⋅ $next_link";
6272 $paging_nav .= " ⋅ next";
6275 if ($#commitlist >= 100) {
6278 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6279 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6280 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6283 if ($searchtype eq 'pickaxe') {
6284 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6285 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6287 print "<table class=\"pickaxe search\">\n";
6290 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6291 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6292 ($search_use_regexp ? '--pickaxe-regex' : ());
6295 while (my $line = <$fd>) {
6299 my %set = parse_difftree_raw_line
($line);
6300 if (defined $set{'commit'}) {
6301 # finish previous commit
6304 "<td class=\"link\">" .
6305 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6307 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6313 print "<tr class=\"dark\">\n";
6315 print "<tr class=\"light\">\n";
6318 %co = parse_commit
($set{'commit'});
6319 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6320 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6321 "<td><i>$author</i></td>\n" .
6323 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6324 -class => "list subject"},
6325 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6326 } elsif (defined $set{'to_id'}) {
6327 next if ($set{'to_id'} =~ m/^0{40}$/);
6329 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6330 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6332 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6338 # finish last commit (warning: repetition!)
6341 "<td class=\"link\">" .
6342 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6344 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6352 if ($searchtype eq 'grep') {
6353 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6354 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6356 print "<table class=\"grep_search\">\n";
6360 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6361 $search_use_regexp ? ('-E', '-i') : '-F',
6362 $searchtext, $co{'tree'};
6364 while (my $line = <$fd>) {
6366 my ($file, $lno, $ltext, $binary);
6367 last if ($matches++ > 1000);
6368 if ($line =~ /^Binary file (.+) matches$/) {
6372 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6374 if ($file ne $lastfile) {
6375 $lastfile and print "</td></tr>\n";
6377 print "<tr class=\"dark\">\n";
6379 print "<tr class=\"light\">\n";
6381 print "<td class=\"list\">".
6382 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6383 file_name
=>"$file"),
6384 -class => "list"}, esc_path
($file));
6385 print "</td><td>\n";
6389 print "<div class=\"binary\">Binary file</div>\n";
6391 $ltext = untabify
($ltext);
6392 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6393 $ltext = esc_html
($1, -nbsp
=>1);
6394 $ltext .= '<span class="match">';
6395 $ltext .= esc_html
($2, -nbsp
=>1);
6396 $ltext .= '</span>';
6397 $ltext .= esc_html
($3, -nbsp
=>1);
6399 $ltext = esc_html
($ltext, -nbsp
=>1);
6401 print "<div class=\"pre\">" .
6402 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6403 file_name
=>"$file").'#l'.$lno,
6404 -class => "linenr"}, sprintf('%4i', $lno))
6405 . ' ' . $ltext . "</div>\n";
6409 print "</td></tr>\n";
6410 if ($matches > 1000) {
6411 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6414 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6423 sub git_search_help
{
6425 git_print_page_nav
('','', $hash,$hash,$hash);
6427 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6428 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6429 the pattern entered is recognized as the POSIX extended
6430 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6433 <dt><b>commit</b></dt>
6434 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6436 my $have_grep = gitweb_check_feature
('grep');
6439 <dt><b>grep</b></dt>
6440 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6441 a different one) are searched for the given pattern. On large trees, this search can take
6442 a while and put some strain on the server, so please use it with some consideration. Note that
6443 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6444 case-sensitive.</dd>
6448 <dt><b>author</b></dt>
6449 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6450 <dt><b>committer</b></dt>
6451 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6453 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6454 if ($have_pickaxe) {
6456 <dt><b>pickaxe</b></dt>
6457 <dd>All commits that caused the string to appear or disappear from any file (changes that
6458 added, removed or "modified" the string) will be listed. This search can take a while and
6459 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6460 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6468 git_log_generic
('shortlog', \
&git_shortlog_body
,
6469 $hash, $hash_parent);
6472 ## ......................................................................
6473 ## feeds (RSS, Atom; OPML)
6476 my $format = shift || 'atom';
6477 my $have_blame = gitweb_check_feature
('blame');
6479 # Atom: http://www.atomenabled.org/developers/syndication/
6480 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6481 if ($format ne 'rss' && $format ne 'atom') {
6482 die_error
(400, "Unknown web feed format");
6485 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6486 my $head = $hash || 'HEAD';
6487 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6491 my $content_type = "application/$format+xml";
6492 if (defined $cgi->http('HTTP_ACCEPT') &&
6493 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6494 # browser (feed reader) prefers text/xml
6495 $content_type = 'text/xml';
6497 if (defined($commitlist[0])) {
6498 %latest_commit = %{$commitlist[0]};
6499 my $latest_epoch = $latest_commit{'committer_epoch'};
6500 %latest_date = parse_date
($latest_epoch);
6501 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6502 if (defined $if_modified) {
6504 if (eval { require HTTP
::Date
; 1; }) {
6505 $since = HTTP
::Date
::str2time
($if_modified);
6506 } elsif (eval { require Time
::ParseDate
; 1; }) {
6507 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6509 if (defined $since && $latest_epoch <= $since) {
6511 -type
=> $content_type,
6512 -charset
=> 'utf-8',
6513 -last_modified
=> $latest_date{'rfc2822'},
6514 -status
=> '304 Not Modified');
6519 -type
=> $content_type,
6520 -charset
=> 'utf-8',
6521 -last_modified
=> $latest_date{'rfc2822'});
6524 -type
=> $content_type,
6525 -charset
=> 'utf-8');
6528 # Optimization: skip generating the body if client asks only
6529 # for Last-Modified date.
6530 return if ($cgi->request_method() eq 'HEAD');
6533 my $title = "$site_name - $project/$action";
6534 my $feed_type = 'log';
6535 if (defined $hash) {
6536 $title .= " - '$hash'";
6537 $feed_type = 'branch log';
6538 if (defined $file_name) {
6539 $title .= " :: $file_name";
6540 $feed_type = 'history';
6542 } elsif (defined $file_name) {
6543 $title .= " - $file_name";
6544 $feed_type = 'history';
6546 $title .= " $feed_type";
6547 my $descr = git_get_project_description
($project);
6548 if (defined $descr) {
6549 $descr = esc_html
($descr);
6551 $descr = "$project " .
6552 ($format eq 'rss' ? 'RSS' : 'Atom') .
6555 my $owner = git_get_project_owner
($project);
6556 $owner = esc_html
($owner);
6560 if (defined $file_name) {
6561 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6562 } elsif (defined $hash) {
6563 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6565 $alt_url = href
(-full
=>1, action
=>"summary");
6567 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6568 if ($format eq 'rss') {
6570 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6573 print "<title>$title</title>\n" .
6574 "<link>$alt_url</link>\n" .
6575 "<description>$descr</description>\n" .
6576 "<language>en</language>\n" .
6577 # project owner is responsible for 'editorial' content
6578 "<managingEditor>$owner</managingEditor>\n";
6579 if (defined $logo || defined $favicon) {
6580 # prefer the logo to the favicon, since RSS
6581 # doesn't allow both
6582 my $img = esc_url
($logo || $favicon);
6584 "<url>$img</url>\n" .
6585 "<title>$title</title>\n" .
6586 "<link>$alt_url</link>\n" .
6590 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6591 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6593 print "<generator>gitweb v.$version/$git_version</generator>\n";
6594 } elsif ($format eq 'atom') {
6596 <feed xmlns="http://www.w3.org/2005/Atom">
6598 print "<title>$title</title>\n" .
6599 "<subtitle>$descr</subtitle>\n" .
6600 '<link rel="alternate" type="text/html" href="' .
6601 $alt_url . '" />' . "\n" .
6602 '<link rel="self" type="' . $content_type . '" href="' .
6603 $cgi->self_url() . '" />' . "\n" .
6604 "<id>" . href
(-full
=>1) . "</id>\n" .
6605 # use project owner for feed author
6606 "<author><name>$owner</name></author>\n";
6607 if (defined $favicon) {
6608 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6610 if (defined $logo_url) {
6611 # not twice as wide as tall: 72 x 27 pixels
6612 print "<logo>" . esc_url
($logo) . "</logo>\n";
6614 if (! %latest_date) {
6615 # dummy date to keep the feed valid until commits trickle in:
6616 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6618 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6620 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6624 for (my $i = 0; $i <= $#commitlist; $i++) {
6625 my %co = %{$commitlist[$i]};
6626 my $commit = $co{'id'};
6627 # we read 150, we always show 30 and the ones more recent than 48 hours
6628 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6631 my %cd = parse_date
($co{'author_epoch'});
6633 # get list of changed files
6634 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6635 $co{'parent'} || "--root",
6636 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6638 my @difftree = map { chomp; $_ } <$fd>;
6642 # print element (entry, item)
6643 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6644 if ($format eq 'rss') {
6646 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6647 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6648 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6649 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6650 "<link>$co_url</link>\n" .
6651 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6652 "<content:encoded>" .
6654 } elsif ($format eq 'atom') {
6656 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6657 "<updated>$cd{'iso-8601'}</updated>\n" .
6659 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6660 if ($co{'author_email'}) {
6661 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6663 print "</author>\n" .
6664 # use committer for contributor
6666 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6667 if ($co{'committer_email'}) {
6668 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6670 print "</contributor>\n" .
6671 "<published>$cd{'iso-8601'}</published>\n" .
6672 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6673 "<id>$co_url</id>\n" .
6674 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6675 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6677 my $comment = $co{'comment'};
6679 foreach my $line (@$comment) {
6680 $line = esc_html
($line);
6683 print "</pre><ul>\n";
6684 foreach my $difftree_line (@difftree) {
6685 my %difftree = parse_difftree_raw_line
($difftree_line);
6686 next if !$difftree{'from_id'};
6688 my $file = $difftree{'file'} || $difftree{'to_file'};
6692 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6693 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6694 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6695 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6696 -title
=> "diff"}, 'D');
6698 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6699 file_name
=>$file, hash_base
=>$commit),
6700 -title
=> "blame"}, 'B');
6702 # if this is not a feed of a file history
6703 if (!defined $file_name || $file_name ne $file) {
6704 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6705 file_name
=>$file, hash
=>$commit),
6706 -title
=> "history"}, 'H');
6708 $file = esc_path
($file);
6712 if ($format eq 'rss') {
6713 print "</ul>]]>\n" .
6714 "</content:encoded>\n" .
6716 } elsif ($format eq 'atom') {
6717 print "</ul>\n</div>\n" .
6724 if ($format eq 'rss') {
6725 print "</channel>\n</rss>\n";
6726 } elsif ($format eq 'atom') {
6740 my @list = git_get_projects_list
();
6743 -type
=> 'text/xml',
6744 -charset
=> 'utf-8',
6745 -content_disposition
=> 'inline; filename="opml.xml"');
6748 <?xml version="1.0" encoding="utf-8"?>
6749 <opml version="1.0">
6751 <title>$site_name OPML Export</title>
6754 <outline text="git RSS feeds">
6757 foreach my $pr (@list) {
6759 my $head = git_get_head_hash
($proj{'path'});
6760 if (!defined $head) {
6763 $git_dir = "$projectroot/$proj{'path'}";
6764 my %co = parse_commit
($head);
6769 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6770 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6771 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6772 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";