3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser set_message);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI-
>compile() if $ENV{'MOD_PERL'};
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 # project specific override is possible only if we have project
459 our $git_dir; # global variable, declared later
460 if (!$override || !defined $git_dir) {
464 warn "feature $name is not overridable";
467 return $sub->(@defaults);
470 # A wrapper to check if a given feature is enabled.
471 # With this, you can say
473 # my $bool_feat = gitweb_check_feature('bool_feat');
474 # gitweb_check_feature('bool_feat') or somecode;
478 # my ($bool_feat) = gitweb_get_feature('bool_feat');
479 # (gitweb_get_feature('bool_feat'))[0] or somecode;
481 sub gitweb_check_feature
{
482 return (gitweb_get_feature
(@_))[0];
488 my ($val) = git_get_project_config
($key, '--bool');
492 } elsif ($val eq 'true') {
494 } elsif ($val eq 'false') {
499 sub feature_snapshot
{
502 my ($val) = git_get_project_config
('snapshot');
505 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
511 sub feature_patches
{
512 my @val = (git_get_project_config
('patches', '--int'));
522 my @val = (git_get_project_config
('avatar'));
524 return @val ? @val : @_;
527 # checking HEAD file with -e is fragile if the repository was
528 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
530 sub check_head_link
{
532 my $headfile = "$dir/HEAD";
533 return ((-e
$headfile) ||
534 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
537 sub check_export_ok
{
539 return (check_head_link
($dir) &&
540 (!$export_ok || -e
"$dir/$export_ok") &&
541 (!$export_auth_hook || $export_auth_hook->($dir)));
544 # process alternate names for backward compatibility
545 # filter out unsupported (unknown) snapshot formats
546 sub filter_snapshot_fmts
{
550 exists $known_snapshot_format_aliases{$_} ?
551 $known_snapshot_format_aliases{$_} : $_} @fmts;
553 exists $known_snapshot_formats{$_} &&
554 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
557 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
558 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
559 # die if there are errors parsing config file
560 if (-e
$GITWEB_CONFIG) {
563 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
564 do $GITWEB_CONFIG_SYSTEM;
568 # Get loadavg of system, to compare against $maxload.
569 # Currently it requires '/proc/loadavg' present to get loadavg;
570 # if it is not present it returns 0, which means no load checking.
572 if( -e
'/proc/loadavg' ){
573 open my $fd, '<', '/proc/loadavg'
575 my @load = split(/\s+/, scalar <$fd>);
578 # The first three columns measure CPU and IO utilization of the last one,
579 # five, and 10 minute periods. The fourth column shows the number of
580 # currently running processes and the total number of processes in the m/n
581 # format. The last column displays the last process ID used.
582 return $load[0] || 0;
584 # additional checks for load average should go here for things that don't export
590 # version of the core git binary
591 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
592 $number_of_git_cmds++;
594 $projects_list ||= $projectroot;
596 if (defined $maxload && get_loadavg
() > $maxload) {
597 die_error
(503, "The load average on the server is too high");
600 # ======================================================================
601 # input validation and dispatch
603 # input parameters can be collected from a variety of sources (presently, CGI
604 # and PATH_INFO), so we define an %input_params hash that collects them all
605 # together during validation: this allows subsequent uses (e.g. href()) to be
606 # agnostic of the parameter origin
608 our %input_params = ();
610 # input parameters are stored with the long parameter name as key. This will
611 # also be used in the href subroutine to convert parameters to their CGI
612 # equivalent, and since the href() usage is the most frequent one, we store
613 # the name -> CGI key mapping here, instead of the reverse.
615 # XXX: Warning: If you touch this, check the search form for updating,
618 our @cgi_param_mapping = (
626 hash_parent_base
=> "hpb",
631 snapshot_format
=> "sf",
632 extra_options
=> "opt",
633 search_use_regexp
=> "sr",
634 # this must be last entry (for manipulation from JavaScript)
637 our %cgi_param_mapping = @cgi_param_mapping;
639 # we will also need to know the possible actions, for validation
641 "blame" => \
&git_blame
,
642 "blame_incremental" => \
&git_blame_incremental
,
643 "blame_data" => \
&git_blame_data
,
644 "blobdiff" => \
&git_blobdiff
,
645 "blobdiff_plain" => \
&git_blobdiff_plain
,
646 "blob" => \
&git_blob
,
647 "blob_plain" => \
&git_blob_plain
,
648 "commitdiff" => \
&git_commitdiff
,
649 "commitdiff_plain" => \
&git_commitdiff_plain
,
650 "commit" => \
&git_commit
,
651 "forks" => \
&git_forks
,
652 "heads" => \
&git_heads
,
653 "history" => \
&git_history
,
655 "patch" => \
&git_patch
,
656 "patches" => \
&git_patches
,
658 "atom" => \
&git_atom
,
659 "search" => \
&git_search
,
660 "search_help" => \
&git_search_help
,
661 "shortlog" => \
&git_shortlog
,
662 "summary" => \
&git_summary
,
664 "tags" => \
&git_tags
,
665 "tree" => \
&git_tree
,
666 "snapshot" => \
&git_snapshot
,
667 "object" => \
&git_object
,
668 # those below don't need $project
669 "opml" => \
&git_opml
,
670 "project_list" => \
&git_project_list
,
671 "project_index" => \
&git_project_index
,
674 # finally, we have the hash of allowed extra_options for the commands that
676 our %allowed_options = (
677 "--no-merges" => [ qw(rss atom log shortlog history) ],
680 # fill %input_params with the CGI parameters. All values except for 'opt'
681 # should be single values, but opt can be an array. We should probably
682 # build an array of parameters that can be multi-valued, but since for the time
683 # being it's only this one, we just single it out
684 while (my ($name, $symbol) = each %cgi_param_mapping) {
685 if ($symbol eq 'opt') {
686 $input_params{$name} = [ $cgi->param($symbol) ];
688 $input_params{$name} = $cgi->param($symbol);
692 # now read PATH_INFO and update the parameter list for missing parameters
693 sub evaluate_path_info
{
694 return if defined $input_params{'project'};
695 return if !$path_info;
696 $path_info =~ s
,^/+,,;
697 return if !$path_info;
699 # find which part of PATH_INFO is project
700 my $project = $path_info;
702 while ($project && !check_head_link
("$projectroot/$project")) {
703 $project =~ s
,/*[^/]*$,,;
705 return unless $project;
706 $input_params{'project'} = $project;
708 # do not change any parameters if an action is given using the query string
709 return if $input_params{'action'};
710 $path_info =~ s
,^\Q
$project\E
/*,,;
712 # next, check if we have an action
713 my $action = $path_info;
715 if (exists $actions{$action}) {
716 $path_info =~ s
,^$action/*,,;
717 $input_params{'action'} = $action;
720 # list of actions that want hash_base instead of hash, but can have no
721 # pathname (f) parameter
728 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
729 my ($parentrefname, $parentpathname, $refname, $pathname) =
730 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
732 # first, analyze the 'current' part
733 if (defined $pathname) {
734 # we got "branch:filename" or "branch:dir/"
735 # we could use git_get_type(branch:pathname), but:
736 # - it needs $git_dir
737 # - it does a git() call
738 # - the convention of terminating directories with a slash
739 # makes it superfluous
740 # - embedding the action in the PATH_INFO would make it even
742 $pathname =~ s
,^/+,,;
743 if (!$pathname || substr($pathname, -1) eq "/") {
744 $input_params{'action'} ||= "tree";
747 # the default action depends on whether we had parent info
749 if ($parentrefname) {
750 $input_params{'action'} ||= "blobdiff_plain";
752 $input_params{'action'} ||= "blob_plain";
755 $input_params{'hash_base'} ||= $refname;
756 $input_params{'file_name'} ||= $pathname;
757 } elsif (defined $refname) {
758 # we got "branch". In this case we have to choose if we have to
759 # set hash or hash_base.
761 # Most of the actions without a pathname only want hash to be
762 # set, except for the ones specified in @wants_base that want
763 # hash_base instead. It should also be noted that hand-crafted
764 # links having 'history' as an action and no pathname or hash
765 # set will fail, but that happens regardless of PATH_INFO.
766 $input_params{'action'} ||= "shortlog";
767 if (grep { $_ eq $input_params{'action'} } @wants_base) {
768 $input_params{'hash_base'} ||= $refname;
770 $input_params{'hash'} ||= $refname;
774 # next, handle the 'parent' part, if present
775 if (defined $parentrefname) {
776 # a missing pathspec defaults to the 'current' filename, allowing e.g.
777 # someproject/blobdiff/oldrev..newrev:/filename
778 if ($parentpathname) {
779 $parentpathname =~ s
,^/+,,;
780 $parentpathname =~ s
,/$,,;
781 $input_params{'file_parent'} ||= $parentpathname;
783 $input_params{'file_parent'} ||= $input_params{'file_name'};
785 # we assume that hash_parent_base is wanted if a path was specified,
786 # or if the action wants hash_base instead of hash
787 if (defined $input_params{'file_parent'} ||
788 grep { $_ eq $input_params{'action'} } @wants_base) {
789 $input_params{'hash_parent_base'} ||= $parentrefname;
791 $input_params{'hash_parent'} ||= $parentrefname;
795 # for the snapshot action, we allow URLs in the form
796 # $project/snapshot/$hash.ext
797 # where .ext determines the snapshot and gets removed from the
798 # passed $refname to provide the $hash.
800 # To be able to tell that $refname includes the format extension, we
801 # require the following two conditions to be satisfied:
802 # - the hash input parameter MUST have been set from the $refname part
803 # of the URL (i.e. they must be equal)
804 # - the snapshot format MUST NOT have been defined already (e.g. from
806 # It's also useless to try any matching unless $refname has a dot,
807 # so we check for that too
808 if (defined $input_params{'action'} &&
809 $input_params{'action'} eq 'snapshot' &&
810 defined $refname && index($refname, '.') != -1 &&
811 $refname eq $input_params{'hash'} &&
812 !defined $input_params{'snapshot_format'}) {
813 # We loop over the known snapshot formats, checking for
814 # extensions. Allowed extensions are both the defined suffix
815 # (which includes the initial dot already) and the snapshot
816 # format key itself, with a prepended dot
817 while (my ($fmt, $opt) = each %known_snapshot_formats) {
819 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
823 # a valid suffix was found, so set the snapshot format
824 # and reset the hash parameter
825 $input_params{'snapshot_format'} = $fmt;
826 $input_params{'hash'} = $hash;
827 # we also set the format suffix to the one requested
828 # in the URL: this way a request for e.g. .tgz returns
829 # a .tgz instead of a .tar.gz
830 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
835 evaluate_path_info
();
837 our $action = $input_params{'action'};
838 if (defined $action) {
839 if (!validate_action
($action)) {
840 die_error
(400, "Invalid action parameter");
844 # parameters which are pathnames
845 our $project = $input_params{'project'};
846 if (defined $project) {
847 if (!validate_project
($project)) {
849 die_error
(404, "No such project");
853 our $file_name = $input_params{'file_name'};
854 if (defined $file_name) {
855 if (!validate_pathname
($file_name)) {
856 die_error
(400, "Invalid file parameter");
860 our $file_parent = $input_params{'file_parent'};
861 if (defined $file_parent) {
862 if (!validate_pathname
($file_parent)) {
863 die_error
(400, "Invalid file parent parameter");
867 # parameters which are refnames
868 our $hash = $input_params{'hash'};
870 if (!validate_refname
($hash)) {
871 die_error
(400, "Invalid hash parameter");
875 our $hash_parent = $input_params{'hash_parent'};
876 if (defined $hash_parent) {
877 if (!validate_refname
($hash_parent)) {
878 die_error
(400, "Invalid hash parent parameter");
882 our $hash_base = $input_params{'hash_base'};
883 if (defined $hash_base) {
884 if (!validate_refname
($hash_base)) {
885 die_error
(400, "Invalid hash base parameter");
889 our @extra_options = @{$input_params{'extra_options'}};
890 # @extra_options is always defined, since it can only be (currently) set from
891 # CGI, and $cgi->param() returns the empty array in array context if the param
893 foreach my $opt (@extra_options) {
894 if (not exists $allowed_options{$opt}) {
895 die_error
(400, "Invalid option parameter");
897 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
898 die_error
(400, "Invalid option parameter for this action");
902 our $hash_parent_base = $input_params{'hash_parent_base'};
903 if (defined $hash_parent_base) {
904 if (!validate_refname
($hash_parent_base)) {
905 die_error
(400, "Invalid hash parent base parameter");
910 our $page = $input_params{'page'};
912 if ($page =~ m/[^0-9]/) {
913 die_error
(400, "Invalid page parameter");
917 our $searchtype = $input_params{'searchtype'};
918 if (defined $searchtype) {
919 if ($searchtype =~ m/[^a-z]/) {
920 die_error
(400, "Invalid searchtype parameter");
924 our $search_use_regexp = $input_params{'search_use_regexp'};
926 our $searchtext = $input_params{'searchtext'};
928 if (defined $searchtext) {
929 if (length($searchtext) < 2) {
930 die_error
(403, "At least two characters are required for search parameter");
932 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
935 # path to the current git repository
937 $git_dir = "$projectroot/$project" if $project;
939 # list of supported snapshot formats
940 our @snapshot_fmts = gitweb_get_feature
('snapshot');
941 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
943 # check that the avatar feature is set to a known provider name,
944 # and for each provider check if the dependencies are satisfied.
945 # if the provider name is invalid or the dependencies are not met,
946 # reset $git_avatar to the empty string.
947 our ($git_avatar) = gitweb_get_feature
('avatar');
948 if ($git_avatar eq 'gravatar') {
949 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
950 } elsif ($git_avatar eq 'picon') {
956 # custom error handler: 'die <message>' is Internal Server Error
957 sub handle_errors_html
{
958 my $msg = shift; # it is already HTML escaped
960 # to avoid infinite loop where error occurs in die_error,
961 # change handler to default handler, disabling handle_errors_html
962 set_message
("Error occured when inside die_error:\n$msg");
964 # you cannot jump out of die_error when called as error handler;
965 # the subroutine set via CGI::Carp::set_message is called _after_
966 # HTTP headers are already written, so it cannot write them itself
967 die_error
(undef, undef, $msg, -error_handler
=> 1, -no_http_header
=> 1);
969 set_message
(\
&handle_errors_html
);
972 if (!defined $action) {
974 $action = git_get_type
($hash);
975 } elsif (defined $hash_base && defined $file_name) {
976 $action = git_get_type
("$hash_base:$file_name");
977 } elsif (defined $project) {
980 $action = 'project_list';
983 if (!defined($actions{$action})) {
984 die_error
(400, "Unknown action");
986 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
988 die_error
(400, "Project needed");
990 $actions{$action}->();
994 ## ======================================================================
997 # possible values of extra options
998 # -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
999 # -replay => 1 - start from a current view (replay with modifications)
1000 # -path_info => 0|1 - don't use/use path_info URL (if possible)
1003 # default is to use -absolute url() i.e. $my_uri
1004 my $href = $params{-full
} ? $my_url : $my_uri;
1006 $params{'project'} = $project unless exists $params{'project'};
1008 if ($params{-replay
}) {
1009 while (my ($name, $symbol) = each %cgi_param_mapping) {
1010 if (!exists $params{$name}) {
1011 $params{$name} = $input_params{$name};
1016 my $use_pathinfo = gitweb_check_feature
('pathinfo');
1017 if (defined $params{'project'} &&
1018 (exists $params{-path_info
} ? $params{-path_info
} : $use_pathinfo)) {
1019 # try to put as many parameters as possible in PATH_INFO:
1022 # - hash_parent or hash_parent_base:/file_parent
1023 # - hash or hash_base:/filename
1024 # - the snapshot_format as an appropriate suffix
1026 # When the script is the root DirectoryIndex for the domain,
1027 # $href here would be something like http://gitweb.example.com/
1028 # Thus, we strip any trailing / from $href, to spare us double
1029 # slashes in the final URL
1032 # Then add the project name, if present
1033 $href .= "/".esc_url
($params{'project'});
1034 delete $params{'project'};
1036 # since we destructively absorb parameters, we keep this
1037 # boolean that remembers if we're handling a snapshot
1038 my $is_snapshot = $params{'action'} eq 'snapshot';
1040 # Summary just uses the project path URL, any other action is
1042 if (defined $params{'action'}) {
1043 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1044 delete $params{'action'};
1047 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1048 # stripping nonexistent or useless pieces
1049 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1050 || $params{'hash_parent'} || $params{'hash'});
1051 if (defined $params{'hash_base'}) {
1052 if (defined $params{'hash_parent_base'}) {
1053 $href .= esc_url
($params{'hash_parent_base'});
1054 # skip the file_parent if it's the same as the file_name
1055 if (defined $params{'file_parent'}) {
1056 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1057 delete $params{'file_parent'};
1058 } elsif ($params{'file_parent'} !~ /\.\./) {
1059 $href .= ":/".esc_url
($params{'file_parent'});
1060 delete $params{'file_parent'};
1064 delete $params{'hash_parent'};
1065 delete $params{'hash_parent_base'};
1066 } elsif (defined $params{'hash_parent'}) {
1067 $href .= esc_url
($params{'hash_parent'}). "..";
1068 delete $params{'hash_parent'};
1071 $href .= esc_url
($params{'hash_base'});
1072 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1073 $href .= ":/".esc_url
($params{'file_name'});
1074 delete $params{'file_name'};
1076 delete $params{'hash'};
1077 delete $params{'hash_base'};
1078 } elsif (defined $params{'hash'}) {
1079 $href .= esc_url
($params{'hash'});
1080 delete $params{'hash'};
1083 # If the action was a snapshot, we can absorb the
1084 # snapshot_format parameter too
1086 my $fmt = $params{'snapshot_format'};
1087 # snapshot_format should always be defined when href()
1088 # is called, but just in case some code forgets, we
1089 # fall back to the default
1090 $fmt ||= $snapshot_fmts[0];
1091 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1092 delete $params{'snapshot_format'};
1096 # now encode the parameters explicitly
1098 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1099 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1100 if (defined $params{$name}) {
1101 if (ref($params{$name}) eq "ARRAY") {
1102 foreach my $par (@{$params{$name}}) {
1103 push @result, $symbol . "=" . esc_param
($par);
1106 push @result, $symbol . "=" . esc_param
($params{$name});
1110 $href .= "?" . join(';', @result) if scalar @result;
1116 ## ======================================================================
1117 ## validation, quoting/unquoting and escaping
1119 sub validate_action
{
1120 my $input = shift || return undef;
1121 return undef unless exists $actions{$input};
1125 sub validate_project
{
1126 my $input = shift || return undef;
1127 if (!validate_pathname
($input) ||
1128 !(-d
"$projectroot/$input") ||
1129 !check_export_ok
("$projectroot/$input") ||
1130 ($strict_export && !project_in_list
($input))) {
1137 sub validate_pathname
{
1138 my $input = shift || return undef;
1140 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1141 # at the beginning, at the end, and between slashes.
1142 # also this catches doubled slashes
1143 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1146 # no null characters
1147 if ($input =~ m!\0!) {
1153 sub validate_refname
{
1154 my $input = shift || return undef;
1156 # textual hashes are O.K.
1157 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1160 # it must be correct pathname
1161 $input = validate_pathname
($input)
1163 # restrictions on ref name according to git-check-ref-format
1164 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1170 # decode sequences of octets in utf8 into Perl's internal form,
1171 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1172 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1175 return undef unless defined $str;
1176 if (utf8
::valid
($str)) {
1180 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1184 # quote unsafe chars, but keep the slash, even when it's not
1185 # correct, but quoted slashes look too horrible in bookmarks
1188 return undef unless defined $str;
1189 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1194 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1197 return undef unless defined $str;
1198 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1204 # replace invalid utf8 character with SUBSTITUTION sequence
1209 return undef unless defined $str;
1211 $str = to_utf8
($str);
1212 $str = $cgi->escapeHTML($str);
1213 if ($opts{'-nbsp'}) {
1214 $str =~ s/ / /g;
1216 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1220 # quote control characters and escape filename to HTML
1225 return undef unless defined $str;
1227 $str = to_utf8
($str);
1228 $str = $cgi->escapeHTML($str);
1229 if ($opts{'-nbsp'}) {
1230 $str =~ s/ / /g;
1232 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1236 # Make control characters "printable", using character escape codes (CEC)
1240 my %es = ( # character escape codes, aka escape sequences
1241 "\t" => '\t', # tab (HT)
1242 "\n" => '\n', # line feed (LF)
1243 "\r" => '\r', # carrige return (CR)
1244 "\f" => '\f', # form feed (FF)
1245 "\b" => '\b', # backspace (BS)
1246 "\a" => '\a', # alarm (bell) (BEL)
1247 "\e" => '\e', # escape (ESC)
1248 "\013" => '\v', # vertical tab (VT)
1249 "\000" => '\0', # nul character (NUL)
1251 my $chr = ( (exists $es{$cntrl})
1253 : sprintf('\%2x', ord($cntrl)) );
1254 if ($opts{-nohtml
}) {
1257 return "<span class=\"cntrl\">$chr</span>";
1261 # Alternatively use unicode control pictures codepoints,
1262 # Unicode "printable representation" (PR)
1267 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1268 if ($opts{-nohtml
}) {
1271 return "<span class=\"cntrl\">$chr</span>";
1275 # git may return quoted and escaped filenames
1281 my %es = ( # character escape codes, aka escape sequences
1282 't' => "\t", # tab (HT, TAB)
1283 'n' => "\n", # newline (NL)
1284 'r' => "\r", # return (CR)
1285 'f' => "\f", # form feed (FF)
1286 'b' => "\b", # backspace (BS)
1287 'a' => "\a", # alarm (bell) (BEL)
1288 'e' => "\e", # escape (ESC)
1289 'v' => "\013", # vertical tab (VT)
1292 if ($seq =~ m/^[0-7]{1,3}$/) {
1293 # octal char sequence
1294 return chr(oct($seq));
1295 } elsif (exists $es{$seq}) {
1296 # C escape sequence, aka character escape code
1299 # quoted ordinary character
1303 if ($str =~ m/^"(.*)"$/) {
1306 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1311 # escape tabs (convert tabs to spaces)
1315 while ((my $pos = index($line, "\t")) != -1) {
1316 if (my $count = (8 - ($pos % 8))) {
1317 my $spaces = ' ' x
$count;
1318 $line =~ s/\t/$spaces/;
1325 sub project_in_list
{
1326 my $project = shift;
1327 my @list = git_get_projects_list
();
1328 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1331 ## ----------------------------------------------------------------------
1332 ## HTML aware string manipulation
1334 # Try to chop given string on a word boundary between position
1335 # $len and $len+$add_len. If there is no word boundary there,
1336 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1337 # (marking chopped part) would be longer than given string.
1341 my $add_len = shift || 10;
1342 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1344 # Make sure perl knows it is utf8 encoded so we don't
1345 # cut in the middle of a utf8 multibyte char.
1346 $str = to_utf8
($str);
1348 # allow only $len chars, but don't cut a word if it would fit in $add_len
1349 # if it doesn't fit, cut it if it's still longer than the dots we would add
1350 # remove chopped character entities entirely
1352 # when chopping in the middle, distribute $len into left and right part
1353 # return early if chopping wouldn't make string shorter
1354 if ($where eq 'center') {
1355 return $str if ($len + 5 >= length($str)); # filler is length 5
1358 return $str if ($len + 4 >= length($str)); # filler is length 4
1361 # regexps: ending and beginning with word part up to $add_len
1362 my $endre = qr/.{$len}\w{0,$add_len}/;
1363 my $begre = qr/\w{0,$add_len}.{$len}/;
1365 if ($where eq 'left') {
1366 $str =~ m/^(.*?)($begre)$/;
1367 my ($lead, $body) = ($1, $2);
1368 if (length($lead) > 4) {
1371 return "$lead$body";
1373 } elsif ($where eq 'center') {
1374 $str =~ m/^($endre)(.*)$/;
1375 my ($left, $str) = ($1, $2);
1376 $str =~ m/^(.*?)($begre)$/;
1377 my ($mid, $right) = ($1, $2);
1378 if (length($mid) > 5) {
1381 return "$left$mid$right";
1384 $str =~ m/^($endre)(.*)$/;
1387 if (length($tail) > 4) {
1390 return "$body$tail";
1394 # takes the same arguments as chop_str, but also wraps a <span> around the
1395 # result with a title attribute if it does get chopped. Additionally, the
1396 # string is HTML-escaped.
1397 sub chop_and_escape_str
{
1400 my $chopped = chop_str
(@_);
1401 if ($chopped eq $str) {
1402 return esc_html
($chopped);
1404 $str =~ s/[[:cntrl:]]/?/g;
1405 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1409 ## ----------------------------------------------------------------------
1410 ## functions returning short strings
1412 # CSS class for given age value (in seconds)
1416 if (!defined $age) {
1418 } elsif ($age < 60*60*2) {
1420 } elsif ($age < 60*60*24*2) {
1427 # convert age in seconds to "nn units ago" string
1432 if ($age > 60*60*24*365*2) {
1433 $age_str = (int $age/60/60/24/365);
1434 $age_str .= " years ago";
1435 } elsif ($age > 60*60*24*(365/12)*2) {
1436 $age_str = int $age/60/60/24/(365/12);
1437 $age_str .= " months ago";
1438 } elsif ($age > 60*60*24*7*2) {
1439 $age_str = int $age/60/60/24/7;
1440 $age_str .= " weeks ago";
1441 } elsif ($age > 60*60*24*2) {
1442 $age_str = int $age/60/60/24;
1443 $age_str .= " days ago";
1444 } elsif ($age > 60*60*2) {
1445 $age_str = int $age/60/60;
1446 $age_str .= " hours ago";
1447 } elsif ($age > 60*2) {
1448 $age_str = int $age/60;
1449 $age_str .= " min ago";
1450 } elsif ($age > 2) {
1451 $age_str = int $age;
1452 $age_str .= " sec ago";
1454 $age_str .= " right now";
1460 S_IFINVALID
=> 0030000,
1461 S_IFGITLINK
=> 0160000,
1464 # submodule/subproject, a commit object reference
1468 return (($mode & S_IFMT
) == S_IFGITLINK
)
1471 # convert file mode in octal to symbolic file mode string
1473 my $mode = oct shift;
1475 if (S_ISGITLINK
($mode)) {
1476 return 'm---------';
1477 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1478 return 'drwxr-xr-x';
1479 } elsif (S_ISLNK
($mode)) {
1480 return 'lrwxrwxrwx';
1481 } elsif (S_ISREG
($mode)) {
1482 # git cares only about the executable bit
1483 if ($mode & S_IXUSR
) {
1484 return '-rwxr-xr-x';
1486 return '-rw-r--r--';
1489 return '----------';
1493 # convert file mode in octal to file type string
1497 if ($mode !~ m/^[0-7]+$/) {
1503 if (S_ISGITLINK
($mode)) {
1505 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1507 } elsif (S_ISLNK
($mode)) {
1509 } elsif (S_ISREG
($mode)) {
1516 # convert file mode in octal to file type description string
1517 sub file_type_long
{
1520 if ($mode !~ m/^[0-7]+$/) {
1526 if (S_ISGITLINK
($mode)) {
1528 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1530 } elsif (S_ISLNK
($mode)) {
1532 } elsif (S_ISREG
($mode)) {
1533 if ($mode & S_IXUSR
) {
1534 return "executable";
1544 ## ----------------------------------------------------------------------
1545 ## functions returning short HTML fragments, or transforming HTML fragments
1546 ## which don't belong to other sections
1548 # format line of commit message.
1549 sub format_log_line_html
{
1552 $line = esc_html
($line, -nbsp
=>1);
1553 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1554 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1555 -class => "text"}, $1);
1561 # format marker of refs pointing to given object
1563 # the destination action is chosen based on object type and current context:
1564 # - for annotated tags, we choose the tag view unless it's the current view
1565 # already, in which case we go to shortlog view
1566 # - for other refs, we keep the current view if we're in history, shortlog or
1567 # log view, and select shortlog otherwise
1568 sub format_ref_marker
{
1569 my ($refs, $id) = @_;
1572 if (defined $refs->{$id}) {
1573 foreach my $ref (@{$refs->{$id}}) {
1574 # this code exploits the fact that non-lightweight tags are the
1575 # only indirect objects, and that they are the only objects for which
1576 # we want to use tag instead of shortlog as action
1577 my ($type, $name) = qw();
1578 my $indirect = ($ref =~ s/\^\{\}$//);
1579 # e.g. tags/v2.6.11 or heads/next
1580 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1589 $class .= " indirect" if $indirect;
1591 my $dest_action = "shortlog";
1594 $dest_action = "tag" unless $action eq "tag";
1595 } elsif ($action =~ /^(history|(short)?log)$/) {
1596 $dest_action = $action;
1600 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1603 my $link = $cgi->a({
1605 action
=>$dest_action,
1609 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1615 return ' <span class="refs">'. $markers . '</span>';
1621 # format, perhaps shortened and with markers, title line
1622 sub format_subject_html
{
1623 my ($long, $short, $href, $extra) = @_;
1624 $extra = '' unless defined($extra);
1626 if (length($short) < length($long)) {
1627 $long =~ s/[[:cntrl:]]/?/g;
1628 return $cgi->a({-href
=> $href, -class => "list subject",
1629 -title
=> to_utf8
($long)},
1630 esc_html
($short)) . $extra;
1632 return $cgi->a({-href
=> $href, -class => "list subject"},
1633 esc_html
($long)) . $extra;
1637 # Rather than recomputing the url for an email multiple times, we cache it
1638 # after the first hit. This gives a visible benefit in views where the avatar
1639 # for the same email is used repeatedly (e.g. shortlog).
1640 # The cache is shared by all avatar engines (currently gravatar only), which
1641 # are free to use it as preferred. Since only one avatar engine is used for any
1642 # given page, there's no risk for cache conflicts.
1643 our %avatar_cache = ();
1645 # Compute the picon url for a given email, by using the picon search service over at
1646 # http://www.cs.indiana.edu/picons/search.html
1648 my $email = lc shift;
1649 if (!$avatar_cache{$email}) {
1650 my ($user, $domain) = split('@', $email);
1651 $avatar_cache{$email} =
1652 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1654 "users+domains+unknown/up/single";
1656 return $avatar_cache{$email};
1659 # Compute the gravatar url for a given email, if it's not in the cache already.
1660 # Gravatar stores only the part of the URL before the size, since that's the
1661 # one computationally more expensive. This also allows reuse of the cache for
1662 # different sizes (for this particular engine).
1664 my $email = lc shift;
1666 $avatar_cache{$email} ||=
1667 "http://www.gravatar.com/avatar/" .
1668 Digest
::MD5
::md5_hex
($email) . "?s=";
1669 return $avatar_cache{$email} . $size;
1672 # Insert an avatar for the given $email at the given $size if the feature
1674 sub git_get_avatar
{
1675 my ($email, %opts) = @_;
1676 my $pre_white = ($opts{-pad_before
} ? " " : "");
1677 my $post_white = ($opts{-pad_after
} ? " " : "");
1678 $opts{-size
} ||= 'default';
1679 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1681 if ($git_avatar eq 'gravatar') {
1682 $url = gravatar_url
($email, $size);
1683 } elsif ($git_avatar eq 'picon') {
1684 $url = picon_url
($email);
1686 # Other providers can be added by extending the if chain, defining $url
1687 # as needed. If no variant puts something in $url, we assume avatars
1688 # are completely disabled/unavailable.
1691 "<img width=\"$size\" " .
1692 "class=\"avatar\" " .
1701 sub format_search_author
{
1702 my ($author, $searchtype, $displaytext) = @_;
1703 my $have_search = gitweb_check_feature
('search');
1707 if ($searchtype eq 'author') {
1708 $performed = "authored";
1709 } elsif ($searchtype eq 'committer') {
1710 $performed = "committed";
1713 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1714 searchtext
=>$author,
1715 searchtype
=>$searchtype), class=>"list",
1716 title
=>"Search for commits $performed by $author"},
1720 return $displaytext;
1724 # format the author name of the given commit with the given tag
1725 # the author name is chopped and escaped according to the other
1726 # optional parameters (see chop_str).
1727 sub format_author_html
{
1730 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1731 return "<$tag class=\"author\">" .
1732 format_search_author
($co->{'author_name'}, "author",
1733 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1738 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1739 sub format_git_diff_header_line
{
1741 my $diffinfo = shift;
1742 my ($from, $to) = @_;
1744 if ($diffinfo->{'nparents'}) {
1746 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1747 if ($to->{'href'}) {
1748 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1749 esc_path
($to->{'file'}));
1750 } else { # file was deleted (no href)
1751 $line .= esc_path
($to->{'file'});
1755 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1756 if ($from->{'href'}) {
1757 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1758 'a/' . esc_path
($from->{'file'}));
1759 } else { # file was added (no href)
1760 $line .= 'a/' . esc_path
($from->{'file'});
1763 if ($to->{'href'}) {
1764 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1765 'b/' . esc_path
($to->{'file'}));
1766 } else { # file was deleted
1767 $line .= 'b/' . esc_path
($to->{'file'});
1771 return "<div class=\"diff header\">$line</div>\n";
1774 # format extended diff header line, before patch itself
1775 sub format_extended_diff_header_line
{
1777 my $diffinfo = shift;
1778 my ($from, $to) = @_;
1781 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1782 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1783 esc_path
($from->{'file'}));
1785 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1786 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1787 esc_path
($to->{'file'}));
1789 # match single <mode>
1790 if ($line =~ m/\s(\d{6})$/) {
1791 $line .= '<span class="info"> (' .
1792 file_type_long
($1) .
1796 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1797 # can match only for combined diff
1799 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1800 if ($from->{'href'}[$i]) {
1801 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1803 substr($diffinfo->{'from_id'}[$i],0,7));
1808 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1811 if ($to->{'href'}) {
1812 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1813 substr($diffinfo->{'to_id'},0,7));
1818 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1819 # can match only for ordinary diff
1820 my ($from_link, $to_link);
1821 if ($from->{'href'}) {
1822 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1823 substr($diffinfo->{'from_id'},0,7));
1825 $from_link = '0' x
7;
1827 if ($to->{'href'}) {
1828 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1829 substr($diffinfo->{'to_id'},0,7));
1833 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1834 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1837 return $line . "<br/>\n";
1840 # format from-file/to-file diff header
1841 sub format_diff_from_to_header
{
1842 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1847 #assert($line =~ m/^---/) if DEBUG;
1848 # no extra formatting for "^--- /dev/null"
1849 if (! $diffinfo->{'nparents'}) {
1850 # ordinary (single parent) diff
1851 if ($line =~ m!^--- "?a/!) {
1852 if ($from->{'href'}) {
1854 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1855 esc_path
($from->{'file'}));
1858 esc_path
($from->{'file'});
1861 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1864 # combined diff (merge commit)
1865 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1866 if ($from->{'href'}[$i]) {
1868 $cgi->a({-href
=>href
(action
=>"blobdiff",
1869 hash_parent
=>$diffinfo->{'from_id'}[$i],
1870 hash_parent_base
=>$parents[$i],
1871 file_parent
=>$from->{'file'}[$i],
1872 hash
=>$diffinfo->{'to_id'},
1874 file_name
=>$to->{'file'}),
1876 -title
=>"diff" . ($i+1)},
1879 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1880 esc_path
($from->{'file'}[$i]));
1882 $line = '--- /dev/null';
1884 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1889 #assert($line =~ m/^\+\+\+/) if DEBUG;
1890 # no extra formatting for "^+++ /dev/null"
1891 if ($line =~ m!^\+\+\+ "?b/!) {
1892 if ($to->{'href'}) {
1894 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1895 esc_path
($to->{'file'}));
1898 esc_path
($to->{'file'});
1901 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1906 # create note for patch simplified by combined diff
1907 sub format_diff_cc_simplified
{
1908 my ($diffinfo, @parents) = @_;
1911 $result .= "<div class=\"diff header\">" .
1913 if (!is_deleted
($diffinfo)) {
1914 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1916 hash
=>$diffinfo->{'to_id'},
1917 file_name
=>$diffinfo->{'to_file'}),
1919 esc_path
($diffinfo->{'to_file'}));
1921 $result .= esc_path
($diffinfo->{'to_file'});
1923 $result .= "</div>\n" . # class="diff header"
1924 "<div class=\"diff nodifferences\">" .
1926 "</div>\n"; # class="diff nodifferences"
1931 # format patch (diff) line (not to be used for diff headers)
1932 sub format_diff_line
{
1934 my ($from, $to) = @_;
1935 my $diff_class = "";
1939 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1941 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1942 if ($line =~ m/^\@{3}/) {
1943 $diff_class = " chunk_header";
1944 } elsif ($line =~ m/^\\/) {
1945 $diff_class = " incomplete";
1946 } elsif ($prefix =~ tr/+/+/) {
1947 $diff_class = " add";
1948 } elsif ($prefix =~ tr/-/-/) {
1949 $diff_class = " rem";
1952 # assume ordinary diff
1953 my $char = substr($line, 0, 1);
1955 $diff_class = " add";
1956 } elsif ($char eq '-') {
1957 $diff_class = " rem";
1958 } elsif ($char eq '@') {
1959 $diff_class = " chunk_header";
1960 } elsif ($char eq "\\") {
1961 $diff_class = " incomplete";
1964 $line = untabify
($line);
1965 if ($from && $to && $line =~ m/^\@{2} /) {
1966 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1967 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1969 $from_lines = 0 unless defined $from_lines;
1970 $to_lines = 0 unless defined $to_lines;
1972 if ($from->{'href'}) {
1973 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1974 -class=>"list"}, $from_text);
1976 if ($to->{'href'}) {
1977 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1978 -class=>"list"}, $to_text);
1980 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1981 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1982 return "<div class=\"diff$diff_class\">$line</div>\n";
1983 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1984 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1985 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1987 @from_text = split(' ', $ranges);
1988 for (my $i = 0; $i < @from_text; ++$i) {
1989 ($from_start[$i], $from_nlines[$i]) =
1990 (split(',', substr($from_text[$i], 1)), 0);
1993 $to_text = pop @from_text;
1994 $to_start = pop @from_start;
1995 $to_nlines = pop @from_nlines;
1997 $line = "<span class=\"chunk_info\">$prefix ";
1998 for (my $i = 0; $i < @from_text; ++$i) {
1999 if ($from->{'href'}[$i]) {
2000 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
2001 -class=>"list"}, $from_text[$i]);
2003 $line .= $from_text[$i];
2007 if ($to->{'href'}) {
2008 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
2009 -class=>"list"}, $to_text);
2013 $line .= " $prefix</span>" .
2014 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
2015 return "<div class=\"diff$diff_class\">$line</div>\n";
2017 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
2020 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
2021 # linked. Pass the hash of the tree/commit to snapshot.
2022 sub format_snapshot_links
{
2024 my $num_fmts = @snapshot_fmts;
2025 if ($num_fmts > 1) {
2026 # A parenthesized list of links bearing format names.
2027 # e.g. "snapshot (_tar.gz_ _zip_)"
2028 return "snapshot (" . join(' ', map
2035 }, $known_snapshot_formats{$_}{'display'})
2036 , @snapshot_fmts) . ")";
2037 } elsif ($num_fmts == 1) {
2038 # A single "snapshot" link whose tooltip bears the format name.
2040 my ($fmt) = @snapshot_fmts;
2046 snapshot_format
=>$fmt
2048 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2050 } else { # $num_fmts == 0
2055 ## ......................................................................
2056 ## functions returning values to be passed, perhaps after some
2057 ## transformation, to other functions; e.g. returning arguments to href()
2059 # returns hash to be passed to href to generate gitweb URL
2060 # in -title key it returns description of link
2062 my $format = shift || 'Atom';
2063 my %res = (action
=> lc($format));
2065 # feed links are possible only for project views
2066 return unless (defined $project);
2067 # some views should link to OPML, or to generic project feed,
2068 # or don't have specific feed yet (so they should use generic)
2069 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2072 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2073 # from tag links; this also makes possible to detect branch links
2074 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2075 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2078 # find log type for feed description (title)
2080 if (defined $file_name) {
2081 $type = "history of $file_name";
2082 $type .= "/" if ($action eq 'tree');
2083 $type .= " on '$branch'" if (defined $branch);
2085 $type = "log of $branch" if (defined $branch);
2088 $res{-title
} = $type;
2089 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2090 $res{'file_name'} = $file_name;
2095 ## ----------------------------------------------------------------------
2096 ## git utility subroutines, invoking git commands
2098 # returns path to the core git executable and the --git-dir parameter as list
2100 $number_of_git_cmds++;
2101 return $GIT, '--git-dir='.$git_dir;
2104 # quote the given arguments for passing them to the shell
2105 # quote_command("command", "arg 1", "arg with ' and ! characters")
2106 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2107 # Try to avoid using this function wherever possible.
2110 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2113 # get HEAD ref of given project as hash
2114 sub git_get_head_hash
{
2115 return git_get_full_hash
(shift, 'HEAD');
2118 sub git_get_full_hash
{
2119 return git_get_hash
(@_);
2122 sub git_get_short_hash
{
2123 return git_get_hash
(@_, '--short=7');
2127 my ($project, $hash, @options) = @_;
2128 my $o_git_dir = $git_dir;
2130 $git_dir = "$projectroot/$project";
2131 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2132 '--verify', '-q', @options, $hash) {
2134 chomp $retval if defined $retval;
2137 if (defined $o_git_dir) {
2138 $git_dir = $o_git_dir;
2143 # get type of given object
2147 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2149 close $fd or return;
2154 # repository configuration
2155 our $config_file = '';
2158 # store multiple values for single key as anonymous array reference
2159 # single values stored directly in the hash, not as [ <value> ]
2160 sub hash_set_multi
{
2161 my ($hash, $key, $value) = @_;
2163 if (!exists $hash->{$key}) {
2164 $hash->{$key} = $value;
2165 } elsif (!ref $hash->{$key}) {
2166 $hash->{$key} = [ $hash->{$key}, $value ];
2168 push @{$hash->{$key}}, $value;
2172 # return hash of git project configuration
2173 # optionally limited to some section, e.g. 'gitweb'
2174 sub git_parse_project_config
{
2175 my $section_regexp = shift;
2180 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2183 while (my $keyval = <$fh>) {
2185 my ($key, $value) = split(/\n/, $keyval, 2);
2187 hash_set_multi
(\
%config, $key, $value)
2188 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2195 # convert config value to boolean: 'true' or 'false'
2196 # no value, number > 0, 'true' and 'yes' values are true
2197 # rest of values are treated as false (never as error)
2198 sub config_to_bool
{
2201 return 1 if !defined $val; # section.key
2203 # strip leading and trailing whitespace
2207 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2208 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2211 # convert config value to simple decimal number
2212 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2213 # to be multiplied by 1024, 1048576, or 1073741824
2217 # strip leading and trailing whitespace
2221 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2223 # unknown unit is treated as 1
2224 return $num * ($unit eq 'g' ? 1073741824 :
2225 $unit eq 'm' ? 1048576 :
2226 $unit eq 'k' ? 1024 : 1);
2231 # convert config value to array reference, if needed
2232 sub config_to_multi
{
2235 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2238 sub git_get_project_config
{
2239 my ($key, $type) = @_;
2241 return unless defined $git_dir;
2244 return unless ($key);
2245 $key =~ s/^gitweb\.//;
2246 return if ($key =~ m/\W/);
2249 if (defined $type) {
2252 unless ($type eq 'bool' || $type eq 'int');
2256 if (!defined $config_file ||
2257 $config_file ne "$git_dir/config") {
2258 %config = git_parse_project_config
('gitweb');
2259 $config_file = "$git_dir/config";
2262 # check if config variable (key) exists
2263 return unless exists $config{"gitweb.$key"};
2266 if (!defined $type) {
2267 return $config{"gitweb.$key"};
2268 } elsif ($type eq 'bool') {
2269 # backward compatibility: 'git config --bool' returns true/false
2270 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2271 } elsif ($type eq 'int') {
2272 return config_to_int
($config{"gitweb.$key"});
2274 return $config{"gitweb.$key"};
2277 # get hash of given path at given ref
2278 sub git_get_hash_by_path
{
2280 my $path = shift || return undef;
2285 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2286 or die_error
(500, "Open git-ls-tree failed");
2288 close $fd or return undef;
2290 if (!defined $line) {
2291 # there is no tree or hash given by $path at $base
2295 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2296 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2297 if (defined $type && $type ne $2) {
2298 # type doesn't match
2304 # get path of entry with given hash at given tree-ish (ref)
2305 # used to get 'from' filename for combined diff (merge commit) for renames
2306 sub git_get_path_by_hash
{
2307 my $base = shift || return;
2308 my $hash = shift || return;
2312 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2314 while (my $line = <$fd>) {
2317 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2318 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2319 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2328 ## ......................................................................
2329 ## git utility functions, directly accessing git repository
2331 sub git_get_project_description
{
2334 $git_dir = "$projectroot/$path";
2335 open my $fd, '<', "$git_dir/description"
2336 or return git_get_project_config
('description');
2339 if (defined $descr) {
2345 sub git_get_project_ctags
{
2349 $git_dir = "$projectroot/$path";
2350 opendir my $dh, "$git_dir/ctags"
2352 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2353 open my $ct, '<', $_ or next;
2357 my $ctag = $_; $ctag =~ s
#.*/##;
2358 $ctags->{$ctag} = $val;
2364 sub git_populate_project_tagcloud
{
2367 # First, merge different-cased tags; tags vote on casing
2369 foreach (keys %$ctags) {
2370 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2371 if (not $ctags_lc{lc $_}->{topcount
}
2372 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2373 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2374 $ctags_lc{lc $_}->{topname
} = $_;
2379 if (eval { require HTML
::TagCloud
; 1; }) {
2380 $cloud = HTML
::TagCloud-
>new;
2381 foreach (sort keys %ctags_lc) {
2382 # Pad the title with spaces so that the cloud looks
2384 my $title = $ctags_lc{$_}->{topname
};
2385 $title =~ s/ / /g;
2386 $title =~ s/^/ /g;
2387 $title =~ s/$/ /g;
2388 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2391 $cloud = \
%ctags_lc;
2396 sub git_show_project_tagcloud
{
2397 my ($cloud, $count) = @_;
2398 print STDERR
ref($cloud)."..\n";
2399 if (ref $cloud eq 'HTML::TagCloud') {
2400 return $cloud->html_and_css($count);
2402 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2403 return '<p align="center">' . join (', ', map {
2404 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2405 } splice(@tags, 0, $count)) . '</p>';
2409 sub git_get_project_url_list
{
2412 $git_dir = "$projectroot/$path";
2413 open my $fd, '<', "$git_dir/cloneurl"
2414 or return wantarray ?
2415 @{ config_to_multi
(git_get_project_config
('url')) } :
2416 config_to_multi
(git_get_project_config
('url'));
2417 my @git_project_url_list = map { chomp; $_ } <$fd>;
2420 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2423 sub git_get_projects_list
{
2428 $filter =~ s/\.git$//;
2430 my $check_forks = gitweb_check_feature
('forks');
2432 if (-d
$projects_list) {
2433 # search in directory
2434 my $dir = $projects_list . ($filter ? "/$filter" : '');
2435 # remove the trailing "/"
2437 my $pfxlen = length("$dir");
2438 my $pfxdepth = ($dir =~ tr!/!!);
2441 follow_fast
=> 1, # follow symbolic links
2442 follow_skip
=> 2, # ignore duplicates
2443 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2445 # skip project-list toplevel, if we get it.
2446 return if (m!^[/.]$!);
2447 # only directories can be git repositories
2448 return unless (-d
$_);
2449 # don't traverse too deep (Find is super slow on os x)
2450 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2451 $File::Find
::prune
= 1;
2455 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2456 # we check related file in $projectroot
2457 my $path = ($filter ? "$filter/" : '') . $subdir;
2458 if (check_export_ok
("$projectroot/$path")) {
2459 push @list, { path
=> $path };
2460 $File::Find
::prune
= 1;
2465 } elsif (-f
$projects_list) {
2466 # read from file(url-encoded):
2467 # 'git%2Fgit.git Linus+Torvalds'
2468 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2469 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2471 open my $fd, '<', $projects_list or return;
2473 while (my $line = <$fd>) {
2475 my ($path, $owner) = split ' ', $line;
2476 $path = unescape
($path);
2477 $owner = unescape
($owner);
2478 if (!defined $path) {
2481 if ($filter ne '') {
2482 # looking for forks;
2483 my $pfx = substr($path, 0, length($filter));
2484 if ($pfx ne $filter) {
2487 my $sfx = substr($path, length($filter));
2488 if ($sfx !~ /^\/.*\
.git
$/) {
2491 } elsif ($check_forks) {
2493 foreach my $filter (keys %paths) {
2494 # looking for forks;
2495 my $pfx = substr($path, 0, length($filter));
2496 if ($pfx ne $filter) {
2499 my $sfx = substr($path, length($filter));
2500 if ($sfx !~ /^\/.*\
.git
$/) {
2503 # is a fork, don't include it in
2508 if (check_export_ok
("$projectroot/$path")) {
2511 owner
=> to_utf8
($owner),
2514 (my $forks_path = $path) =~ s/\.git$//;
2515 $paths{$forks_path}++;
2523 our $gitweb_project_owner = undef;
2524 sub git_get_project_list_from_file
{
2526 return if (defined $gitweb_project_owner);
2528 $gitweb_project_owner = {};
2529 # read from file (url-encoded):
2530 # 'git%2Fgit.git Linus+Torvalds'
2531 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2532 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2533 if (-f
$projects_list) {
2534 open(my $fd, '<', $projects_list);
2535 while (my $line = <$fd>) {
2537 my ($pr, $ow) = split ' ', $line;
2538 $pr = unescape
($pr);
2539 $ow = unescape
($ow);
2540 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2546 sub git_get_project_owner
{
2547 my $project = shift;
2550 return undef unless $project;
2551 $git_dir = "$projectroot/$project";
2553 if (!defined $gitweb_project_owner) {
2554 git_get_project_list_from_file
();
2557 if (exists $gitweb_project_owner->{$project}) {
2558 $owner = $gitweb_project_owner->{$project};
2560 if (!defined $owner){
2561 $owner = git_get_project_config
('owner');
2563 if (!defined $owner) {
2564 $owner = get_file_owner
("$git_dir");
2570 sub git_get_last_activity
{
2574 $git_dir = "$projectroot/$path";
2575 open($fd, "-|", git_cmd
(), 'for-each-ref',
2576 '--format=%(committer)',
2577 '--sort=-committerdate',
2579 'refs/heads') or return;
2580 my $most_recent = <$fd>;
2581 close $fd or return;
2582 if (defined $most_recent &&
2583 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2585 my $age = time - $timestamp;
2586 return ($age, age_string
($age));
2588 return (undef, undef);
2591 sub git_get_references
{
2592 my $type = shift || "";
2594 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2595 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2596 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2597 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2600 while (my $line = <$fd>) {
2602 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2603 if (defined $refs{$1}) {
2604 push @{$refs{$1}}, $2;
2610 close $fd or return;
2614 sub git_get_rev_name_tags
{
2615 my $hash = shift || return undef;
2617 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2619 my $name_rev = <$fd>;
2622 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2625 # catches also '$hash undefined' output
2630 ## ----------------------------------------------------------------------
2631 ## parse to hash functions
2635 my $tz = shift || "-0000";
2638 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2639 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2640 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2641 $date{'hour'} = $hour;
2642 $date{'minute'} = $min;
2643 $date{'mday'} = $mday;
2644 $date{'day'} = $days[$wday];
2645 $date{'month'} = $months[$mon];
2646 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2647 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2648 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2649 $mday, $months[$mon], $hour ,$min;
2650 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2651 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2653 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2654 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2655 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2656 $date{'hour_local'} = $hour;
2657 $date{'minute_local'} = $min;
2658 $date{'tz_local'} = $tz;
2659 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2660 1900+$year, $mon+1, $mday,
2661 $hour, $min, $sec, $tz);
2670 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2671 $tag{'id'} = $tag_id;
2672 while (my $line = <$fd>) {
2674 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2675 $tag{'object'} = $1;
2676 } elsif ($line =~ m/^type (.+)$/) {
2678 } elsif ($line =~ m/^tag (.+)$/) {
2680 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2681 $tag{'author'} = $1;
2682 $tag{'author_epoch'} = $2;
2683 $tag{'author_tz'} = $3;
2684 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2685 $tag{'author_name'} = $1;
2686 $tag{'author_email'} = $2;
2688 $tag{'author_name'} = $tag{'author'};
2690 } elsif ($line =~ m/--BEGIN/) {
2691 push @comment, $line;
2693 } elsif ($line eq "") {
2697 push @comment, <$fd>;
2698 $tag{'comment'} = \
@comment;
2699 close $fd or return;
2700 if (!defined $tag{'name'}) {
2706 sub parse_commit_text
{
2707 my ($commit_text, $withparents) = @_;
2708 my @commit_lines = split '\n', $commit_text;
2711 pop @commit_lines; # Remove '\0'
2713 if (! @commit_lines) {
2717 my $header = shift @commit_lines;
2718 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2721 ($co{'id'}, my @parents) = split ' ', $header;
2722 while (my $line = shift @commit_lines) {
2723 last if $line eq "\n";
2724 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2726 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2728 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2729 $co{'author'} = to_utf8
($1);
2730 $co{'author_epoch'} = $2;
2731 $co{'author_tz'} = $3;
2732 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2733 $co{'author_name'} = $1;
2734 $co{'author_email'} = $2;
2736 $co{'author_name'} = $co{'author'};
2738 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2739 $co{'committer'} = to_utf8
($1);
2740 $co{'committer_epoch'} = $2;
2741 $co{'committer_tz'} = $3;
2742 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2743 $co{'committer_name'} = $1;
2744 $co{'committer_email'} = $2;
2746 $co{'committer_name'} = $co{'committer'};
2750 if (!defined $co{'tree'}) {
2753 $co{'parents'} = \
@parents;
2754 $co{'parent'} = $parents[0];
2756 foreach my $title (@commit_lines) {
2759 $co{'title'} = chop_str
($title, 80, 5);
2760 # remove leading stuff of merges to make the interesting part visible
2761 if (length($title) > 50) {
2762 $title =~ s/^Automatic //;
2763 $title =~ s/^merge (of|with) /Merge ... /i;
2764 if (length($title) > 50) {
2765 $title =~ s/(http|rsync):\/\///;
2767 if (length($title) > 50) {
2768 $title =~ s/(master|www|rsync)\.//;
2770 if (length($title) > 50) {
2771 $title =~ s/kernel.org:?//;
2773 if (length($title) > 50) {
2774 $title =~ s/\/pub\/scm//;
2777 $co{'title_short'} = chop_str
($title, 50, 5);
2781 if (! defined $co{'title'} || $co{'title'} eq "") {
2782 $co{'title'} = $co{'title_short'} = '(no commit message)';
2784 # remove added spaces
2785 foreach my $line (@commit_lines) {
2788 $co{'comment'} = \
@commit_lines;
2790 my $age = time - $co{'committer_epoch'};
2792 $co{'age_string'} = age_string
($age);
2793 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2794 if ($age > 60*60*24*7*2) {
2795 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2796 $co{'age_string_age'} = $co{'age_string'};
2798 $co{'age_string_date'} = $co{'age_string'};
2799 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2805 my ($commit_id) = @_;
2810 open my $fd, "-|", git_cmd
(), "rev-list",
2816 or die_error
(500, "Open git-rev-list failed");
2817 %co = parse_commit_text
(<$fd>, 1);
2824 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2832 open my $fd, "-|", git_cmd
(), "rev-list",
2835 ("--max-count=" . $maxcount),
2836 ("--skip=" . $skip),
2840 ($filename ? ($filename) : ())
2841 or die_error
(500, "Open git-rev-list failed");
2842 while (my $line = <$fd>) {
2843 my %co = parse_commit_text
($line);
2848 return wantarray ? @cos : \
@cos;
2851 # parse line of git-diff-tree "raw" output
2852 sub parse_difftree_raw_line
{
2856 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2857 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2858 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2859 $res{'from_mode'} = $1;
2860 $res{'to_mode'} = $2;
2861 $res{'from_id'} = $3;
2863 $res{'status'} = $5;
2864 $res{'similarity'} = $6;
2865 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2866 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2868 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2871 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2872 # combined diff (for merge commit)
2873 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2874 $res{'nparents'} = length($1);
2875 $res{'from_mode'} = [ split(' ', $2) ];
2876 $res{'to_mode'} = pop @{$res{'from_mode'}};
2877 $res{'from_id'} = [ split(' ', $3) ];
2878 $res{'to_id'} = pop @{$res{'from_id'}};
2879 $res{'status'} = [ split('', $4) ];
2880 $res{'to_file'} = unquote
($5);
2882 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2883 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2884 $res{'commit'} = $1;
2887 return wantarray ? %res : \
%res;
2890 # wrapper: return parsed line of git-diff-tree "raw" output
2891 # (the argument might be raw line, or parsed info)
2892 sub parsed_difftree_line
{
2893 my $line_or_ref = shift;
2895 if (ref($line_or_ref) eq "HASH") {
2896 # pre-parsed (or generated by hand)
2897 return $line_or_ref;
2899 return parse_difftree_raw_line
($line_or_ref);
2903 # parse line of git-ls-tree output
2904 sub parse_ls_tree_line
{
2910 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2911 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2920 $res{'name'} = unquote
($5);
2923 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2924 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2932 $res{'name'} = unquote
($4);
2936 return wantarray ? %res : \
%res;
2939 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2940 sub parse_from_to_diffinfo
{
2941 my ($diffinfo, $from, $to, @parents) = @_;
2943 if ($diffinfo->{'nparents'}) {
2945 $from->{'file'} = [];
2946 $from->{'href'} = [];
2947 fill_from_file_info
($diffinfo, @parents)
2948 unless exists $diffinfo->{'from_file'};
2949 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2950 $from->{'file'}[$i] =
2951 defined $diffinfo->{'from_file'}[$i] ?
2952 $diffinfo->{'from_file'}[$i] :
2953 $diffinfo->{'to_file'};
2954 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2955 $from->{'href'}[$i] = href
(action
=>"blob",
2956 hash_base
=>$parents[$i],
2957 hash
=>$diffinfo->{'from_id'}[$i],
2958 file_name
=>$from->{'file'}[$i]);
2960 $from->{'href'}[$i] = undef;
2964 # ordinary (not combined) diff
2965 $from->{'file'} = $diffinfo->{'from_file'};
2966 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2967 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2968 hash
=>$diffinfo->{'from_id'},
2969 file_name
=>$from->{'file'});
2971 delete $from->{'href'};
2975 $to->{'file'} = $diffinfo->{'to_file'};
2976 if (!is_deleted
($diffinfo)) { # file exists in result
2977 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2978 hash
=>$diffinfo->{'to_id'},
2979 file_name
=>$to->{'file'});
2981 delete $to->{'href'};
2985 ## ......................................................................
2986 ## parse to array of hashes functions
2988 sub git_get_heads_list
{
2992 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2993 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2994 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2997 while (my $line = <$fd>) {
3001 my ($refinfo, $committerinfo) = split(/\0/, $line);
3002 my ($hash, $name, $title) = split(' ', $refinfo, 3);
3003 my ($committer, $epoch, $tz) =
3004 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
3005 $ref_item{'fullname'} = $name;
3006 $name =~ s!^refs/heads/!!;
3008 $ref_item{'name'} = $name;
3009 $ref_item{'id'} = $hash;
3010 $ref_item{'title'} = $title || '(no commit message)';
3011 $ref_item{'epoch'} = $epoch;
3013 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3015 $ref_item{'age'} = "unknown";
3018 push @headslist, \
%ref_item;
3022 return wantarray ? @headslist : \
@headslist;
3025 sub git_get_tags_list
{
3029 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3030 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
3031 '--format=%(objectname) %(objecttype) %(refname) '.
3032 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3035 while (my $line = <$fd>) {
3039 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3040 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3041 my ($creator, $epoch, $tz) =
3042 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3043 $ref_item{'fullname'} = $name;
3044 $name =~ s!^refs/tags/!!;
3046 $ref_item{'type'} = $type;
3047 $ref_item{'id'} = $id;
3048 $ref_item{'name'} = $name;
3049 if ($type eq "tag") {
3050 $ref_item{'subject'} = $title;
3051 $ref_item{'reftype'} = $reftype;
3052 $ref_item{'refid'} = $refid;
3054 $ref_item{'reftype'} = $type;
3055 $ref_item{'refid'} = $id;
3058 if ($type eq "tag" || $type eq "commit") {
3059 $ref_item{'epoch'} = $epoch;
3061 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3063 $ref_item{'age'} = "unknown";
3067 push @tagslist, \
%ref_item;
3071 return wantarray ? @tagslist : \
@tagslist;
3074 ## ----------------------------------------------------------------------
3075 ## filesystem-related functions
3077 sub get_file_owner
{
3080 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3081 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3082 if (!defined $gcos) {
3086 $owner =~ s/[,;].*$//;
3087 return to_utf8
($owner);
3090 # assume that file exists
3092 my $filename = shift;
3094 open my $fd, '<', $filename;
3095 print map { to_utf8
($_) } <$fd>;
3099 ## ......................................................................
3100 ## mimetype related functions
3102 sub mimetype_guess_file
{
3103 my $filename = shift;
3104 my $mimemap = shift;
3105 -r
$mimemap or return undef;
3108 open(my $mh, '<', $mimemap) or return undef;
3110 next if m/^#/; # skip comments
3111 my ($mimetype, $exts) = split(/\t+/);
3112 if (defined $exts) {
3113 my @exts = split(/\s+/, $exts);
3114 foreach my $ext (@exts) {
3115 $mimemap{$ext} = $mimetype;
3121 $filename =~ /\.([^.]*)$/;
3122 return $mimemap{$1};
3125 sub mimetype_guess
{
3126 my $filename = shift;
3128 $filename =~ /\./ or return undef;
3130 if ($mimetypes_file) {
3131 my $file = $mimetypes_file;
3132 if ($file !~ m!^/!) { # if it is relative path
3133 # it is relative to project
3134 $file = "$projectroot/$project/$file";
3136 $mime = mimetype_guess_file
($filename, $file);
3138 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3144 my $filename = shift;
3147 my $mime = mimetype_guess
($filename);
3148 $mime and return $mime;
3152 return $default_blob_plain_mimetype unless $fd;
3155 return 'text/plain';
3156 } elsif (! $filename) {
3157 return 'application/octet-stream';
3158 } elsif ($filename =~ m/\.png$/i) {
3160 } elsif ($filename =~ m/\.gif$/i) {
3162 } elsif ($filename =~ m/\.jpe?g$/i) {
3163 return 'image/jpeg';
3165 return 'application/octet-stream';
3169 sub blob_contenttype
{
3170 my ($fd, $file_name, $type) = @_;
3172 $type ||= blob_mimetype
($fd, $file_name);
3173 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3174 $type .= "; charset=$default_text_plain_charset";
3180 ## ======================================================================
3181 ## functions printing HTML: header, footer, error page
3183 sub get_page_title
{
3184 my $title = to_utf8
($site_name);
3186 return $title unless (defined $project);
3187 $title .= " - " . to_utf8
($project);
3189 return $title unless (defined $action);
3190 $title .= "/$action"; # $action is US-ASCII (7bit ASCII)
3192 return $title unless (defined $file_name);
3193 $title .= " - " . esc_path
($file_name);
3194 if ($action eq "tree" && $file_name !~ m
|/$|) {
3201 sub git_header_html
{
3202 my $status = shift || "200 OK";
3203 my $expires = shift;
3206 my $title = get_page_title
();
3208 # require explicit support from the UA if we are to send the page as
3209 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3210 # we have to do this because MSIE sometimes globs '*/*', pretending to
3211 # support xhtml+xml but choking when it gets what it asked for.
3212 if (defined $cgi->http('HTTP_ACCEPT') &&
3213 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3214 $cgi->Accept('application/xhtml+xml') != 0) {
3215 $content_type = 'application/xhtml+xml';
3217 $content_type = 'text/html';
3219 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3220 -status
=> $status, -expires
=> $expires)
3221 unless ($opts{'-no_http_headers'});
3222 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3224 <?xml version="1.0" encoding="utf-8"?>
3225 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3226 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3227 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3228 <!-- git core binaries version $git_version -->
3230 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3231 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3232 <meta name="robots" content="index, nofollow"/>
3233 <title>$title</title>
3235 # the stylesheet, favicon etc urls won't work correctly with path_info
3236 # unless we set the appropriate base URL
3237 if ($ENV{'PATH_INFO'}) {
3238 print "<base href=\"".esc_url
($base_url)."\" />\n";
3240 # print out each stylesheet that exist, providing backwards capability
3241 # for those people who defined $stylesheet in a config file
3242 if (defined $stylesheet) {
3243 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3245 foreach my $stylesheet (@stylesheets) {
3246 next unless $stylesheet;
3247 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3250 if (defined $project) {
3251 my %href_params = get_feed_info
();
3252 if (!exists $href_params{'-title'}) {
3253 $href_params{'-title'} = 'log';
3256 foreach my $format qw(RSS Atom) {
3257 my $type = lc($format);
3259 '-rel' => 'alternate',
3260 '-title' => "$project - $href_params{'-title'} - $format feed",
3261 '-type' => "application/$type+xml"
3264 $href_params{'action'} = $type;
3265 $link_attr{'-href'} = href
(%href_params);
3267 "rel=\"$link_attr{'-rel'}\" ".
3268 "title=\"$link_attr{'-title'}\" ".
3269 "href=\"$link_attr{'-href'}\" ".
3270 "type=\"$link_attr{'-type'}\" ".
3273 $href_params{'extra_options'} = '--no-merges';
3274 $link_attr{'-href'} = href
(%href_params);
3275 $link_attr{'-title'} .= ' (no merges)';
3277 "rel=\"$link_attr{'-rel'}\" ".
3278 "title=\"$link_attr{'-title'}\" ".
3279 "href=\"$link_attr{'-href'}\" ".
3280 "type=\"$link_attr{'-type'}\" ".
3285 printf('<link rel="alternate" title="%s projects list" '.
3286 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3287 $site_name, href
(project
=>undef, action
=>"project_index"));
3288 printf('<link rel="alternate" title="%s projects feeds" '.
3289 'href="%s" type="text/x-opml" />'."\n",
3290 $site_name, href
(project
=>undef, action
=>"opml"));
3292 if (defined $favicon) {
3293 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3299 if (defined $site_header && -f
$site_header) {
3300 insert_file
($site_header);
3303 print "<div class=\"page_header\">\n" .
3304 $cgi->a({-href
=> esc_url
($logo_url),
3305 -title
=> $logo_label},
3306 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3307 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3308 if (defined $project) {
3309 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3310 if (defined $action) {
3317 my $have_search = gitweb_check_feature
('search');
3318 if (defined $project && $have_search) {
3319 if (!defined $searchtext) {
3323 if (defined $hash_base) {
3324 $search_hash = $hash_base;
3325 } elsif (defined $hash) {
3326 $search_hash = $hash;
3328 $search_hash = "HEAD";
3330 my $action = $my_uri;
3331 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3332 if ($use_pathinfo) {
3333 $action .= "/".esc_url
($project);
3335 print $cgi->startform(-method => "get", -action
=> $action) .
3336 "<div class=\"search\">\n" .
3338 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3339 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3340 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3341 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3342 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3343 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3345 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3346 "<span title=\"Extended regular expression\">" .
3347 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3348 -checked
=> $search_use_regexp) .
3351 $cgi->end_form() . "\n";
3355 sub git_footer_html
{
3356 my $feed_class = 'rss_logo';
3358 print "<div class=\"page_footer\">\n";
3359 if (defined $project) {
3360 my $descr = git_get_project_description
($project);
3361 if (defined $descr) {
3362 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3365 my %href_params = get_feed_info
();
3366 if (!%href_params) {
3367 $feed_class .= ' generic';
3369 $href_params{'-title'} ||= 'log';
3371 foreach my $format qw(RSS Atom) {
3372 $href_params{'action'} = lc($format);
3373 print $cgi->a({-href
=> href
(%href_params),
3374 -title
=> "$href_params{'-title'} $format feed",
3375 -class => $feed_class}, $format)."\n";
3379 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3380 -class => $feed_class}, "OPML") . " ";
3381 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3382 -class => $feed_class}, "TXT") . "\n";
3384 print "</div>\n"; # class="page_footer"
3386 if (defined $t0 && gitweb_check_feature
('timed')) {
3387 print "<div id=\"generating_info\">\n";
3388 print 'This page took '.
3389 '<span id="generating_time" class="time_span">'.
3390 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3393 '<span id="generating_cmd">'.
3394 $number_of_git_cmds.
3395 '</span> git commands '.
3397 print "</div>\n"; # class="page_footer"
3400 if (defined $site_footer && -f
$site_footer) {
3401 insert_file
($site_footer);
3404 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3405 if (defined $action &&
3406 $action eq 'blame_incremental') {
3407 print qq
!<script type
="text/javascript">\n!.
3408 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3409 qq
! "!. href() .qq!");\n!.
3411 } elsif (gitweb_check_feature
('javascript-actions')) {
3412 print qq
!<script type
="text/javascript">\n!.
3413 qq
!window
.onload
= fixLinks
;\n!.
3421 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3422 # Example: die_error(404, 'Hash not found')
3423 # By convention, use the following status codes (as defined in RFC 2616):
3424 # 400: Invalid or missing CGI parameters, or
3425 # requested object exists but has wrong type.
3426 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3427 # this server or project.
3428 # 404: Requested object/revision/project doesn't exist.
3429 # 500: The server isn't configured properly, or
3430 # an internal error occurred (e.g. failed assertions caused by bugs), or
3431 # an unknown error occurred (e.g. the git binary died unexpectedly).
3432 # 503: The server is currently unavailable (because it is overloaded,
3433 # or down for maintenance). Generally, this is a temporary state.
3435 my $status = shift || 500;
3436 my $error = esc_html
(shift) || "Internal Server Error";
3440 my %http_responses = (
3441 400 => '400 Bad Request',
3442 403 => '403 Forbidden',
3443 404 => '404 Not Found',
3444 500 => '500 Internal Server Error',
3445 503 => '503 Service Unavailable',
3447 git_header_html
($http_responses{$status}, undef, %opts);
3449 <div class="page_body">
3454 if (defined $extra) {
3462 unless ($opts{'-error_handler'});
3465 ## ----------------------------------------------------------------------
3466 ## functions printing or outputting HTML: navigation
3468 sub git_print_page_nav
{
3469 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3470 $extra = '' if !defined $extra; # pager or formats
3472 my @navs = qw(summary shortlog log commit commitdiff tree);
3474 @navs = grep { $_ ne $suppress } @navs;
3477 my %arg = map { $_ => {action
=>$_} } @navs;
3478 if (defined $head) {
3479 for (qw(commit commitdiff)) {
3480 $arg{$_}{'hash'} = $head;
3482 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3483 for (qw(shortlog log)) {
3484 $arg{$_}{'hash'} = $head;
3489 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3490 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3492 my @actions = gitweb_get_feature
('actions');
3495 'n' => $project, # project name
3496 'f' => $git_dir, # project path within filesystem
3497 'h' => $treehead || '', # current hash ('h' parameter)
3498 'b' => $treebase || '', # hash base ('hb' parameter)
3501 my ($label, $link, $pos) = splice(@actions,0,3);
3503 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3505 $link =~ s/%([%nfhb])/$repl{$1}/g;
3506 $arg{$label}{'_href'} = $link;
3509 print "<div class=\"page_nav\">\n" .
3511 map { $_ eq $current ?
3512 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3514 print "<br/>\n$extra<br/>\n" .
3518 sub format_paging_nav
{
3519 my ($action, $page, $has_next_link) = @_;
3525 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3527 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3528 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3530 $paging_nav .= "first ⋅ prev";
3533 if ($has_next_link) {
3534 $paging_nav .= " ⋅ " .
3535 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3536 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3538 $paging_nav .= " ⋅ next";
3544 ## ......................................................................
3545 ## functions printing or outputting HTML: div
3547 sub git_print_header_div
{
3548 my ($action, $title, $hash, $hash_base) = @_;
3551 $args{'action'} = $action;
3552 $args{'hash'} = $hash if $hash;
3553 $args{'hash_base'} = $hash_base if $hash_base;
3555 print "<div class=\"header\">\n" .
3556 $cgi->a({-href
=> href
(%args), -class => "title"},
3557 $title ? $title : $action) .
3561 sub print_local_time
{
3562 print format_local_time
(@_);
3565 sub format_local_time
{
3568 if ($date{'hour_local'} < 6) {
3569 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3570 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3572 $localtime .= sprintf(" (%02d:%02d %s)",
3573 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3579 # Outputs the author name and date in long form
3580 sub git_print_authorship
{
3583 my $tag = $opts{-tag
} || 'div';
3584 my $author = $co->{'author_name'};
3586 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3587 print "<$tag class=\"author_date\">" .
3588 format_search_author
($author, "author", esc_html
($author)) .
3590 print_local_time
(%ad) if ($opts{-localtime});
3591 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3595 # Outputs table rows containing the full author or committer information,
3596 # in the format expected for 'commit' view (& similia).
3597 # Parameters are a commit hash reference, followed by the list of people
3598 # to output information for. If the list is empty it defalts to both
3599 # author and committer.
3600 sub git_print_authorship_rows
{
3602 # too bad we can't use @people = @_ || ('author', 'committer')
3604 @people = ('author', 'committer') unless @people;
3605 foreach my $who (@people) {
3606 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3607 print "<tr><td>$who</td><td>" .
3608 format_search_author
($co->{"${who}_name"}, $who,
3609 esc_html
($co->{"${who}_name"})) . " " .
3610 format_search_author
($co->{"${who}_email"}, $who,
3611 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3612 "</td><td rowspan=\"2\">" .
3613 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3616 "<td></td><td> $wd{'rfc2822'}";
3617 print_local_time
(%wd);
3623 sub git_print_page_path
{
3629 print "<div class=\"page_path\">";
3630 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3631 -title
=> 'tree root'}, to_utf8
("[$project]"));
3633 if (defined $name) {
3634 my @dirname = split '/', $name;
3635 my $basename = pop @dirname;
3638 foreach my $dir (@dirname) {
3639 $fullname .= ($fullname ? '/' : '') . $dir;
3640 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3642 -title
=> $fullname}, esc_path
($dir));
3645 if (defined $type && $type eq 'blob') {
3646 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3648 -title
=> $name}, esc_path
($basename));
3649 } elsif (defined $type && $type eq 'tree') {
3650 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3652 -title
=> $name}, esc_path
($basename));
3655 print esc_path
($basename);
3658 print "<br/></div>\n";
3665 if ($opts{'-remove_title'}) {
3666 # remove title, i.e. first line of log
3669 # remove leading empty lines
3670 while (defined $log->[0] && $log->[0] eq "") {
3677 foreach my $line (@$log) {
3678 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3681 if (! $opts{'-remove_signoff'}) {
3682 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3685 # remove signoff lines
3692 # print only one empty line
3693 # do not print empty line after signoff
3695 next if ($empty || $signoff);
3701 print format_log_line_html
($line) . "<br/>\n";
3704 if ($opts{'-final_empty_line'}) {
3705 # end with single empty line
3706 print "<br/>\n" unless $empty;
3710 # return link target (what link points to)
3711 sub git_get_link_target
{
3716 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3720 $link_target = <$fd>;
3725 return $link_target;
3728 # given link target, and the directory (basedir) the link is in,
3729 # return target of link relative to top directory (top tree);
3730 # return undef if it is not possible (including absolute links).
3731 sub normalize_link_target
{
3732 my ($link_target, $basedir) = @_;
3734 # absolute symlinks (beginning with '/') cannot be normalized
3735 return if (substr($link_target, 0, 1) eq '/');
3737 # normalize link target to path from top (root) tree (dir)
3740 $path = $basedir . '/' . $link_target;
3742 # we are in top (root) tree (dir)
3743 $path = $link_target;
3746 # remove //, /./, and /../
3748 foreach my $part (split('/', $path)) {
3749 # discard '.' and ''
3750 next if (!$part || $part eq '.');
3752 if ($part eq '..') {
3756 # link leads outside repository (outside top dir)
3760 push @path_parts, $part;
3763 $path = join('/', @path_parts);
3768 # print tree entry (row of git_tree), but without encompassing <tr> element
3769 sub git_print_tree_entry
{
3770 my ($t, $basedir, $hash_base, $have_blame) = @_;
3773 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3775 # The format of a table row is: mode list link. Where mode is
3776 # the mode of the entry, list is the name of the entry, an href,
3777 # and link is the action links of the entry.
3779 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3780 if (exists $t->{'size'}) {
3781 print "<td class=\"size\">$t->{'size'}</td>\n";
3783 if ($t->{'type'} eq "blob") {
3784 print "<td class=\"list\">" .
3785 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3786 file_name
=>"$basedir$t->{'name'}", %base_key),
3787 -class => "list"}, esc_path
($t->{'name'}));
3788 if (S_ISLNK
(oct $t->{'mode'})) {
3789 my $link_target = git_get_link_target
($t->{'hash'});
3791 my $norm_target = normalize_link_target
($link_target, $basedir);
3792 if (defined $norm_target) {
3794 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3795 file_name
=>$norm_target),
3796 -title
=> $norm_target}, esc_path
($link_target));
3798 print " -> " . esc_path
($link_target);
3803 print "<td class=\"link\">";
3804 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3805 file_name
=>"$basedir$t->{'name'}", %base_key)},
3809 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3810 file_name
=>"$basedir$t->{'name'}", %base_key)},
3813 if (defined $hash_base) {
3815 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3816 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3820 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3821 file_name
=>"$basedir$t->{'name'}")},
3825 } elsif ($t->{'type'} eq "tree") {
3826 print "<td class=\"list\">";
3827 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3828 file_name
=>"$basedir$t->{'name'}",
3830 esc_path
($t->{'name'}));
3832 print "<td class=\"link\">";
3833 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3834 file_name
=>"$basedir$t->{'name'}",
3837 if (defined $hash_base) {
3839 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3840 file_name
=>"$basedir$t->{'name'}")},
3845 # unknown object: we can only present history for it
3846 # (this includes 'commit' object, i.e. submodule support)
3847 print "<td class=\"list\">" .
3848 esc_path
($t->{'name'}) .
3850 print "<td class=\"link\">";
3851 if (defined $hash_base) {
3852 print $cgi->a({-href
=> href
(action
=>"history",
3853 hash_base
=>$hash_base,
3854 file_name
=>"$basedir$t->{'name'}")},
3861 ## ......................................................................
3862 ## functions printing large fragments of HTML
3864 # get pre-image filenames for merge (combined) diff
3865 sub fill_from_file_info
{
3866 my ($diff, @parents) = @_;
3868 $diff->{'from_file'} = [ ];
3869 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3870 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3871 if ($diff->{'status'}[$i] eq 'R' ||
3872 $diff->{'status'}[$i] eq 'C') {
3873 $diff->{'from_file'}[$i] =
3874 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3881 # is current raw difftree line of file deletion
3883 my $diffinfo = shift;
3885 return $diffinfo->{'to_id'} eq ('0' x
40);
3888 # does patch correspond to [previous] difftree raw line
3889 # $diffinfo - hashref of parsed raw diff format
3890 # $patchinfo - hashref of parsed patch diff format
3891 # (the same keys as in $diffinfo)
3892 sub is_patch_split
{
3893 my ($diffinfo, $patchinfo) = @_;
3895 return defined $diffinfo && defined $patchinfo
3896 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3900 sub git_difftree_body
{
3901 my ($difftree, $hash, @parents) = @_;
3902 my ($parent) = $parents[0];
3903 my $have_blame = gitweb_check_feature
('blame');
3904 print "<div class=\"list_head\">\n";
3905 if ($#{$difftree} > 10) {
3906 print(($#{$difftree} + 1) . " files changed:\n");
3910 print "<table class=\"" .
3911 (@parents > 1 ? "combined " : "") .
3914 # header only for combined diff in 'commitdiff' view
3915 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3918 print "<thead><tr>\n" .
3919 "<th></th><th></th>\n"; # filename, patchN link
3920 for (my $i = 0; $i < @parents; $i++) {
3921 my $par = $parents[$i];
3923 $cgi->a({-href
=> href
(action
=>"commitdiff",
3924 hash
=>$hash, hash_parent
=>$par),
3925 -title
=> 'commitdiff to parent number ' .
3926 ($i+1) . ': ' . substr($par,0,7)},
3930 print "</tr></thead>\n<tbody>\n";
3935 foreach my $line (@{$difftree}) {
3936 my $diff = parsed_difftree_line
($line);
3939 print "<tr class=\"dark\">\n";
3941 print "<tr class=\"light\">\n";
3945 if (exists $diff->{'nparents'}) { # combined diff
3947 fill_from_file_info
($diff, @parents)
3948 unless exists $diff->{'from_file'};
3950 if (!is_deleted
($diff)) {
3951 # file exists in the result (child) commit
3953 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3954 file_name
=>$diff->{'to_file'},
3956 -class => "list"}, esc_path
($diff->{'to_file'})) .
3960 esc_path
($diff->{'to_file'}) .
3964 if ($action eq 'commitdiff') {
3967 print "<td class=\"link\">" .
3968 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3973 my $has_history = 0;
3974 my $not_deleted = 0;
3975 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3976 my $hash_parent = $parents[$i];
3977 my $from_hash = $diff->{'from_id'}[$i];
3978 my $from_path = $diff->{'from_file'}[$i];
3979 my $status = $diff->{'status'}[$i];
3981 $has_history ||= ($status ne 'A');
3982 $not_deleted ||= ($status ne 'D');
3984 if ($status eq 'A') {
3985 print "<td class=\"link\" align=\"right\"> | </td>\n";
3986 } elsif ($status eq 'D') {
3987 print "<td class=\"link\">" .
3988 $cgi->a({-href
=> href
(action
=>"blob",
3991 file_name
=>$from_path)},
3995 if ($diff->{'to_id'} eq $from_hash) {
3996 print "<td class=\"link nochange\">";
3998 print "<td class=\"link\">";
4000 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4001 hash
=>$diff->{'to_id'},
4002 hash_parent
=>$from_hash,
4004 hash_parent_base
=>$hash_parent,
4005 file_name
=>$diff->{'to_file'},
4006 file_parent
=>$from_path)},
4012 print "<td class=\"link\">";
4014 print $cgi->a({-href
=> href
(action
=>"blob",
4015 hash
=>$diff->{'to_id'},
4016 file_name
=>$diff->{'to_file'},
4019 print " | " if ($has_history);
4022 print $cgi->a({-href
=> href
(action
=>"history",
4023 file_name
=>$diff->{'to_file'},
4030 next; # instead of 'else' clause, to avoid extra indent
4032 # else ordinary diff
4034 my ($to_mode_oct, $to_mode_str, $to_file_type);
4035 my ($from_mode_oct, $from_mode_str, $from_file_type);
4036 if ($diff->{'to_mode'} ne ('0' x
6)) {
4037 $to_mode_oct = oct $diff->{'to_mode'};
4038 if (S_ISREG
($to_mode_oct)) { # only for regular file
4039 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4041 $to_file_type = file_type
($diff->{'to_mode'});
4043 if ($diff->{'from_mode'} ne ('0' x
6)) {
4044 $from_mode_oct = oct $diff->{'from_mode'};
4045 if (S_ISREG
($to_mode_oct)) { # only for regular file
4046 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4048 $from_file_type = file_type
($diff->{'from_mode'});
4051 if ($diff->{'status'} eq "A") { # created
4052 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4053 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4054 $mode_chng .= "]</span>";
4056 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4057 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4058 -class => "list"}, esc_path
($diff->{'file'}));
4060 print "<td>$mode_chng</td>\n";
4061 print "<td class=\"link\">";
4062 if ($action eq 'commitdiff') {
4065 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4068 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4069 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4073 } elsif ($diff->{'status'} eq "D") { # deleted
4074 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4076 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4077 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4078 -class => "list"}, esc_path
($diff->{'file'}));
4080 print "<td>$mode_chng</td>\n";
4081 print "<td class=\"link\">";
4082 if ($action eq 'commitdiff') {
4085 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4088 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4089 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4092 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4093 file_name
=>$diff->{'file'})},
4096 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4097 file_name
=>$diff->{'file'})},
4101 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4102 my $mode_chnge = "";
4103 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4104 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4105 if ($from_file_type ne $to_file_type) {
4106 $mode_chnge .= " from $from_file_type to $to_file_type";
4108 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4109 if ($from_mode_str && $to_mode_str) {
4110 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4111 } elsif ($to_mode_str) {
4112 $mode_chnge .= " mode: $to_mode_str";
4115 $mode_chnge .= "]</span>\n";
4118 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4119 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4120 -class => "list"}, esc_path
($diff->{'file'}));
4122 print "<td>$mode_chnge</td>\n";
4123 print "<td class=\"link\">";
4124 if ($action eq 'commitdiff') {
4127 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4129 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4130 # "commit" view and modified file (not onlu mode changed)
4131 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4132 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4133 hash_base
=>$hash, hash_parent_base
=>$parent,
4134 file_name
=>$diff->{'file'})},
4138 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4139 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4142 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4143 file_name
=>$diff->{'file'})},
4146 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4147 file_name
=>$diff->{'file'})},
4151 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4152 my %status_name = ('R' => 'moved', 'C' => 'copied');
4153 my $nstatus = $status_name{$diff->{'status'}};
4155 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4156 # mode also for directories, so we cannot use $to_mode_str
4157 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4160 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4161 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4162 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4163 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4164 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4165 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4166 -class => "list"}, esc_path
($diff->{'from_file'})) .
4167 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4168 "<td class=\"link\">";
4169 if ($action eq 'commitdiff') {
4172 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4174 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4175 # "commit" view and modified file (not only pure rename or copy)
4176 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4177 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4178 hash_base
=>$hash, hash_parent_base
=>$parent,
4179 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4183 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4184 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4187 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4188 file_name
=>$diff->{'to_file'})},
4191 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4192 file_name
=>$diff->{'to_file'})},
4196 } # we should not encounter Unmerged (U) or Unknown (X) status
4199 print "</tbody>" if $has_header;
4203 sub git_patchset_body
{
4204 my ($fd, $difftree, $hash, @hash_parents) = @_;
4205 my ($hash_parent) = $hash_parents[0];
4207 my $is_combined = (@hash_parents > 1);
4209 my $patch_number = 0;
4215 print "<div class=\"patchset\">\n";
4217 # skip to first patch
4218 while ($patch_line = <$fd>) {
4221 last if ($patch_line =~ m/^diff /);
4225 while ($patch_line) {
4227 # parse "git diff" header line
4228 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4229 # $1 is from_name, which we do not use
4230 $to_name = unquote
($2);
4231 $to_name =~ s!^b/!!;
4232 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4233 # $1 is 'cc' or 'combined', which we do not use
4234 $to_name = unquote
($2);
4239 # check if current patch belong to current raw line
4240 # and parse raw git-diff line if needed
4241 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4242 # this is continuation of a split patch
4243 print "<div class=\"patch cont\">\n";
4245 # advance raw git-diff output if needed
4246 $patch_idx++ if defined $diffinfo;
4248 # read and prepare patch information
4249 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4251 # compact combined diff output can have some patches skipped
4252 # find which patch (using pathname of result) we are at now;
4254 while ($to_name ne $diffinfo->{'to_file'}) {
4255 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4256 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4257 "</div>\n"; # class="patch"
4262 last if $patch_idx > $#$difftree;
4263 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4267 # modifies %from, %to hashes
4268 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4270 # this is first patch for raw difftree line with $patch_idx index
4271 # we index @$difftree array from 0, but number patches from 1
4272 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4276 #assert($patch_line =~ m/^diff /) if DEBUG;
4277 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4279 # print "git diff" header
4280 print format_git_diff_header_line
($patch_line, $diffinfo,
4283 # print extended diff header
4284 print "<div class=\"diff extended_header\">\n";
4286 while ($patch_line = <$fd>) {
4289 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4291 print format_extended_diff_header_line
($patch_line, $diffinfo,
4294 print "</div>\n"; # class="diff extended_header"
4296 # from-file/to-file diff header
4297 if (! $patch_line) {
4298 print "</div>\n"; # class="patch"
4301 next PATCH
if ($patch_line =~ m/^diff /);
4302 #assert($patch_line =~ m/^---/) if DEBUG;
4304 my $last_patch_line = $patch_line;
4305 $patch_line = <$fd>;
4307 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4309 print format_diff_from_to_header
($last_patch_line, $patch_line,
4310 $diffinfo, \
%from, \
%to,
4315 while ($patch_line = <$fd>) {
4318 next PATCH
if ($patch_line =~ m/^diff /);
4320 print format_diff_line
($patch_line, \
%from, \
%to);
4324 print "</div>\n"; # class="patch"
4327 # for compact combined (--cc) format, with chunk and patch simpliciaction
4328 # patchset might be empty, but there might be unprocessed raw lines
4329 for (++$patch_idx if $patch_number > 0;
4330 $patch_idx < @$difftree;
4332 # read and prepare patch information
4333 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4335 # generate anchor for "patch" links in difftree / whatchanged part
4336 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4337 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4338 "</div>\n"; # class="patch"
4343 if ($patch_number == 0) {
4344 if (@hash_parents > 1) {
4345 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4347 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4351 print "</div>\n"; # class="patchset"
4354 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4356 # fills project list info (age, description, owner, forks) for each
4357 # project in the list, removing invalid projects from returned list
4358 # NOTE: modifies $projlist, but does not remove entries from it
4359 sub fill_project_list_info
{
4360 my ($projlist, $check_forks) = @_;
4363 my $show_ctags = gitweb_check_feature
('ctags');
4365 foreach my $pr (@$projlist) {
4366 my (@activity) = git_get_last_activity
($pr->{'path'});
4367 unless (@activity) {
4370 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4371 if (!defined $pr->{'descr'}) {
4372 my $descr = git_get_project_description
($pr->{'path'}) || "";
4373 $descr = to_utf8
($descr);
4374 $pr->{'descr_long'} = $descr;
4375 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4377 if (!defined $pr->{'owner'}) {
4378 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4381 my $pname = $pr->{'path'};
4382 if (($pname =~ s/\.git$//) &&
4383 ($pname !~ /\/$/) &&
4384 (-d
"$projectroot/$pname")) {
4385 $pr->{'forks'} = "-d $projectroot/$pname";
4390 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4391 push @projects, $pr;
4397 # print 'sort by' <th> element, generating 'sort by $name' replay link
4398 # if that order is not selected
4400 print format_sort_th
(@_);
4403 sub format_sort_th
{
4404 my ($name, $order, $header) = @_;
4406 $header ||= ucfirst($name);
4408 if ($order eq $name) {
4409 $sort_th .= "<th>$header</th>\n";
4411 $sort_th .= "<th>" .
4412 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4413 -class => "header"}, $header) .
4420 sub git_project_list_body
{
4421 # actually uses global variable $project
4422 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4424 my $check_forks = gitweb_check_feature
('forks');
4425 my @projects = fill_project_list_info
($projlist, $check_forks);
4427 $order ||= $default_projects_order;
4428 $from = 0 unless defined $from;
4429 $to = $#projects if (!defined $to || $#projects < $to);
4432 project
=> { key
=> 'path', type
=> 'str' },
4433 descr
=> { key
=> 'descr_long', type
=> 'str' },
4434 owner
=> { key
=> 'owner', type
=> 'str' },
4435 age
=> { key
=> 'age', type
=> 'num' }
4437 my $oi = $order_info{$order};
4438 if ($oi->{'type'} eq 'str') {
4439 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4441 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4444 my $show_ctags = gitweb_check_feature
('ctags');
4447 foreach my $p (@projects) {
4448 foreach my $ct (keys %{$p->{'ctags'}}) {
4449 $ctags{$ct} += $p->{'ctags'}->{$ct};
4452 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4453 print git_show_project_tagcloud
($cloud, 64);
4456 print "<table class=\"project_list\">\n";
4457 unless ($no_header) {
4460 print "<th></th>\n";
4462 print_sort_th
('project', $order, 'Project');
4463 print_sort_th
('descr', $order, 'Description');
4464 print_sort_th
('owner', $order, 'Owner');
4465 print_sort_th
('age', $order, 'Last Change');
4466 print "<th></th>\n" . # for links
4470 my $tagfilter = $cgi->param('by_tag');
4471 for (my $i = $from; $i <= $to; $i++) {
4472 my $pr = $projects[$i];
4474 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4475 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4476 and not $pr->{'descr_long'} =~ /$searchtext/;
4477 # Weed out forks or non-matching entries of search
4479 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4480 $forkbase="^$forkbase" if $forkbase;
4481 next if not $searchtext and not $tagfilter and $show_ctags
4482 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4486 print "<tr class=\"dark\">\n";
4488 print "<tr class=\"light\">\n";
4493 if ($pr->{'forks'}) {
4494 print "<!-- $pr->{'forks'} -->\n";
4495 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4499 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4500 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4501 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4502 -class => "list", -title
=> $pr->{'descr_long'}},
4503 esc_html
($pr->{'descr'})) . "</td>\n" .
4504 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4505 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4506 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4507 "<td class=\"link\">" .
4508 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4509 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4510 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4511 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4512 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4516 if (defined $extra) {
4519 print "<td></td>\n";
4521 print "<td colspan=\"5\">$extra</td>\n" .
4528 # uses global variable $project
4529 my ($commitlist, $from, $to, $refs, $extra) = @_;
4531 $from = 0 unless defined $from;
4532 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4534 for (my $i = 0; $i <= $to; $i++) {
4535 my %co = %{$commitlist->[$i]};
4537 my $commit = $co{'id'};
4538 my $ref = format_ref_marker
($refs, $commit);
4539 my %ad = parse_date
($co{'author_epoch'});
4540 git_print_header_div
('commit',
4541 "<span class=\"age\">$co{'age_string'}</span>" .
4542 esc_html
($co{'title'}) . $ref,
4544 print "<div class=\"title_text\">\n" .
4545 "<div class=\"log_link\">\n" .
4546 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4548 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4550 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4553 git_print_authorship
(\
%co, -tag
=> 'span');
4554 print "<br/>\n</div>\n";
4556 print "<div class=\"log_body\">\n";
4557 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4561 print "<div class=\"page_nav\">\n";
4567 sub git_shortlog_body
{
4568 # uses global variable $project
4569 my ($commitlist, $from, $to, $refs, $extra) = @_;
4571 $from = 0 unless defined $from;
4572 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4574 print "<table class=\"shortlog\">\n";
4576 for (my $i = $from; $i <= $to; $i++) {
4577 my %co = %{$commitlist->[$i]};
4578 my $commit = $co{'id'};
4579 my $ref = format_ref_marker
($refs, $commit);
4581 print "<tr class=\"dark\">\n";
4583 print "<tr class=\"light\">\n";
4586 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4587 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4588 format_author_html
('td', \
%co, 10) . "<td>";
4589 print format_subject_html
($co{'title'}, $co{'title_short'},
4590 href
(action
=>"commit", hash
=>$commit), $ref);
4592 "<td class=\"link\">" .
4593 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4594 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4595 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4596 my $snapshot_links = format_snapshot_links
($commit);
4597 if (defined $snapshot_links) {
4598 print " | " . $snapshot_links;
4603 if (defined $extra) {
4605 "<td colspan=\"4\">$extra</td>\n" .
4611 sub git_history_body
{
4612 # Warning: assumes constant type (blob or tree) during history
4613 my ($commitlist, $from, $to, $refs, $extra,
4614 $file_name, $file_hash, $ftype) = @_;
4616 $from = 0 unless defined $from;
4617 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4619 print "<table class=\"history\">\n";
4621 for (my $i = $from; $i <= $to; $i++) {
4622 my %co = %{$commitlist->[$i]};
4626 my $commit = $co{'id'};
4628 my $ref = format_ref_marker
($refs, $commit);
4631 print "<tr class=\"dark\">\n";
4633 print "<tr class=\"light\">\n";
4636 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4637 # shortlog: format_author_html('td', \%co, 10)
4638 format_author_html
('td', \
%co, 15, 3) . "<td>";
4639 # originally git_history used chop_str($co{'title'}, 50)
4640 print format_subject_html
($co{'title'}, $co{'title_short'},
4641 href
(action
=>"commit", hash
=>$commit), $ref);
4643 "<td class=\"link\">" .
4644 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4645 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4647 if ($ftype eq 'blob') {
4648 my $blob_current = $file_hash;
4649 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4650 if (defined $blob_current && defined $blob_parent &&
4651 $blob_current ne $blob_parent) {
4653 $cgi->a({-href
=> href
(action
=>"blobdiff",
4654 hash
=>$blob_current, hash_parent
=>$blob_parent,
4655 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4656 file_name
=>$file_name)},
4663 if (defined $extra) {
4665 "<td colspan=\"4\">$extra</td>\n" .
4672 # uses global variable $project
4673 my ($taglist, $from, $to, $extra) = @_;
4674 $from = 0 unless defined $from;
4675 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4677 print "<table class=\"tags\">\n";
4679 for (my $i = $from; $i <= $to; $i++) {
4680 my $entry = $taglist->[$i];
4682 my $comment = $tag{'subject'};
4684 if (defined $comment) {
4685 $comment_short = chop_str
($comment, 30, 5);
4688 print "<tr class=\"dark\">\n";
4690 print "<tr class=\"light\">\n";
4693 if (defined $tag{'age'}) {
4694 print "<td><i>$tag{'age'}</i></td>\n";
4696 print "<td></td>\n";
4699 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4700 -class => "list name"}, esc_html
($tag{'name'})) .
4703 if (defined $comment) {
4704 print format_subject_html
($comment, $comment_short,
4705 href
(action
=>"tag", hash
=>$tag{'id'}));
4708 "<td class=\"selflink\">";
4709 if ($tag{'type'} eq "tag") {
4710 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4715 "<td class=\"link\">" . " | " .
4716 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4717 if ($tag{'reftype'} eq "commit") {
4718 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4719 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4720 } elsif ($tag{'reftype'} eq "blob") {
4721 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4726 if (defined $extra) {
4728 "<td colspan=\"5\">$extra</td>\n" .
4734 sub git_heads_body
{
4735 # uses global variable $project
4736 my ($headlist, $head, $from, $to, $extra) = @_;
4737 $from = 0 unless defined $from;
4738 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4740 print "<table class=\"heads\">\n";
4742 for (my $i = $from; $i <= $to; $i++) {
4743 my $entry = $headlist->[$i];
4745 my $curr = $ref{'id'} eq $head;
4747 print "<tr class=\"dark\">\n";
4749 print "<tr class=\"light\">\n";
4752 print "<td><i>$ref{'age'}</i></td>\n" .
4753 ($curr ? "<td class=\"current_head\">" : "<td>") .
4754 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4755 -class => "list name"},esc_html
($ref{'name'})) .
4757 "<td class=\"link\">" .
4758 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4759 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4760 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4764 if (defined $extra) {
4766 "<td colspan=\"3\">$extra</td>\n" .
4772 sub git_search_grep_body
{
4773 my ($commitlist, $from, $to, $extra) = @_;
4774 $from = 0 unless defined $from;
4775 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4777 print "<table class=\"commit_search\">\n";
4779 for (my $i = $from; $i <= $to; $i++) {
4780 my %co = %{$commitlist->[$i]};
4784 my $commit = $co{'id'};
4786 print "<tr class=\"dark\">\n";
4788 print "<tr class=\"light\">\n";
4791 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4792 format_author_html
('td', \
%co, 15, 5) .
4794 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4795 -class => "list subject"},
4796 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4797 my $comment = $co{'comment'};
4798 foreach my $line (@$comment) {
4799 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4800 my ($lead, $match, $trail) = ($1, $2, $3);
4801 $match = chop_str
($match, 70, 5, 'center');
4802 my $contextlen = int((80 - length($match))/2);
4803 $contextlen = 30 if ($contextlen > 30);
4804 $lead = chop_str
($lead, $contextlen, 10, 'left');
4805 $trail = chop_str
($trail, $contextlen, 10, 'right');
4807 $lead = esc_html
($lead);
4808 $match = esc_html
($match);
4809 $trail = esc_html
($trail);
4811 print "$lead<span class=\"match\">$match</span>$trail<br />";
4815 "<td class=\"link\">" .
4816 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4818 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4820 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4824 if (defined $extra) {
4826 "<td colspan=\"3\">$extra</td>\n" .
4832 ## ======================================================================
4833 ## ======================================================================
4836 sub git_project_list
{
4837 my $order = $input_params{'order'};
4838 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4839 die_error
(400, "Unknown order parameter");
4842 my @list = git_get_projects_list
();
4844 die_error
(404, "No projects found");
4848 if (defined $home_text && -f
$home_text) {
4849 print "<div class=\"index_include\">\n";
4850 insert_file
($home_text);
4853 print $cgi->startform(-method => "get") .
4854 "<p class=\"projsearch\">Search:\n" .
4855 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4857 $cgi->end_form() . "\n";
4858 git_project_list_body
(\
@list, $order);
4863 my $order = $input_params{'order'};
4864 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4865 die_error
(400, "Unknown order parameter");
4868 my @list = git_get_projects_list
($project);
4870 die_error
(404, "No forks found");
4874 git_print_page_nav
('','');
4875 git_print_header_div
('summary', "$project forks");
4876 git_project_list_body
(\
@list, $order);
4880 sub git_project_index
{
4881 my @projects = git_get_projects_list
($project);
4884 -type
=> 'text/plain',
4885 -charset
=> 'utf-8',
4886 -content_disposition
=> 'inline; filename="index.aux"');
4888 foreach my $pr (@projects) {
4889 if (!exists $pr->{'owner'}) {
4890 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4893 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4894 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4895 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4896 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4900 print "$path $owner\n";
4905 my $descr = git_get_project_description
($project) || "none";
4906 my %co = parse_commit
("HEAD");
4907 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4908 my $head = $co{'id'};
4910 my $owner = git_get_project_owner
($project);
4912 my $refs = git_get_references
();
4913 # These get_*_list functions return one more to allow us to see if
4914 # there are more ...
4915 my @taglist = git_get_tags_list
(16);
4916 my @headlist = git_get_heads_list
(16);
4918 my $check_forks = gitweb_check_feature
('forks');
4921 @forklist = git_get_projects_list
($project);
4925 git_print_page_nav
('summary','', $head);
4927 print "<div class=\"title\"> </div>\n";
4928 print "<table class=\"projects_list\">\n" .
4929 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4930 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4931 if (defined $cd{'rfc2822'}) {
4932 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4935 # use per project git URL list in $projectroot/$project/cloneurl
4936 # or make project git URL from git base URL and project name
4937 my $url_tag = "URL";
4938 my @url_list = git_get_project_url_list
($project);
4939 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4940 foreach my $git_url (@url_list) {
4941 next unless $git_url;
4942 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4947 my $show_ctags = gitweb_check_feature
('ctags');
4949 my $ctags = git_get_project_ctags
($project);
4950 my $cloud = git_populate_project_tagcloud
($ctags);
4951 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4952 print "</td>\n<td>" unless %$ctags;
4953 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4954 print "</td>\n<td>" if %$ctags;
4955 print git_show_project_tagcloud
($cloud, 48);
4961 # If XSS prevention is on, we don't include README.html.
4962 # TODO: Allow a readme in some safe format.
4963 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4964 print "<div class=\"title\">readme</div>\n" .
4965 "<div class=\"readme\">\n";
4966 insert_file
("$projectroot/$project/README.html");
4967 print "\n</div>\n"; # class="readme"
4970 # we need to request one more than 16 (0..15) to check if
4972 my @commitlist = $head ? parse_commits
($head, 17) : ();
4974 git_print_header_div
('shortlog');
4975 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4976 $#commitlist <= 15 ? undef :
4977 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4981 git_print_header_div
('tags');
4982 git_tags_body
(\
@taglist, 0, 15,
4983 $#taglist <= 15 ? undef :
4984 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4988 git_print_header_div
('heads');
4989 git_heads_body
(\
@headlist, $head, 0, 15,
4990 $#headlist <= 15 ? undef :
4991 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4995 git_print_header_div
('forks');
4996 git_project_list_body
(\
@forklist, 'age', 0, 15,
4997 $#forklist <= 15 ? undef :
4998 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
5006 my $head = git_get_head_hash
($project);
5008 git_print_page_nav
('','', $head,undef,$head);
5009 my %tag = parse_tag
($hash);
5012 die_error
(404, "Unknown tag object");
5015 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
5016 print "<div class=\"title_text\">\n" .
5017 "<table class=\"object_header\">\n" .
5019 "<td>object</td>\n" .
5020 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5021 $tag{'object'}) . "</td>\n" .
5022 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
5023 $tag{'type'}) . "</td>\n" .
5025 if (defined($tag{'author'})) {
5026 git_print_authorship_rows
(\
%tag, 'author');
5028 print "</table>\n\n" .
5030 print "<div class=\"page_body\">";
5031 my $comment = $tag{'comment'};
5032 foreach my $line (@$comment) {
5034 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5040 sub git_blame_common
{
5041 my $format = shift || 'porcelain';
5042 if ($format eq 'porcelain' && $cgi->param('js')) {
5043 $format = 'incremental';
5044 $action = 'blame_incremental'; # for page title etc
5048 gitweb_check_feature
('blame')
5049 or die_error
(403, "Blame view not allowed");
5052 die_error
(400, "No file name given") unless $file_name;
5053 $hash_base ||= git_get_head_hash
($project);
5054 die_error
(404, "Couldn't find base commit") unless $hash_base;
5055 my %co = parse_commit
($hash_base)
5056 or die_error
(404, "Commit not found");
5058 if (!defined $hash) {
5059 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5060 or die_error
(404, "Error looking up file");
5062 $ftype = git_get_type
($hash);
5063 if ($ftype !~ "blob") {
5064 die_error
(400, "Object is not a blob");
5069 if ($format eq 'incremental') {
5070 # get file contents (as base)
5071 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5072 or die_error
(500, "Open git-cat-file failed");
5073 } elsif ($format eq 'data') {
5074 # run git-blame --incremental
5075 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5076 $hash_base, "--", $file_name
5077 or die_error
(500, "Open git-blame --incremental failed");
5079 # run git-blame --porcelain
5080 open $fd, "-|", git_cmd
(), "blame", '-p',
5081 $hash_base, '--', $file_name
5082 or die_error
(500, "Open git-blame --porcelain failed");
5085 # incremental blame data returns early
5086 if ($format eq 'data') {
5088 -type
=>"text/plain", -charset
=> "utf-8",
5089 -status
=> "200 OK");
5090 local $| = 1; # output autoflush
5093 or print "ERROR $!\n";
5096 if (defined $t0 && gitweb_check_feature
('timed')) {
5098 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5099 ' '.$number_of_git_cmds;
5109 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5112 if ($format eq 'incremental') {
5114 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5115 "blame") . " (non-incremental)";
5118 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5119 "blame") . " (incremental)";
5123 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5126 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5128 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5129 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5130 git_print_page_path
($file_name, $ftype, $hash_base);
5133 if ($format eq 'incremental') {
5134 print "<noscript>\n<div class=\"error\"><center><b>\n".
5135 "This page requires JavaScript to run.\n Use ".
5136 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5139 "</b></center></div>\n</noscript>\n";
5141 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5144 print qq
!<div
class="page_body">\n!;
5145 print qq
!<div id
="progress_info">... / ...</div
>\n!
5146 if ($format eq 'incremental');
5147 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5148 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5150 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5154 my @rev_color = qw(light dark);
5155 my $num_colors = scalar(@rev_color);
5156 my $current_color = 0;
5158 if ($format eq 'incremental') {
5159 my $color_class = $rev_color[$current_color];
5164 while (my $line = <$fd>) {
5168 print qq
!<tr id
="l$linenr" class="$color_class">!.
5169 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5170 qq
!<td
class="linenr">!.
5171 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5172 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5176 } else { # porcelain, i.e. ordinary blame
5177 my %metainfo = (); # saves information about commits
5181 while (my $line = <$fd>) {
5183 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5184 # no <lines in group> for subsequent lines in group of lines
5185 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5186 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5187 if (!exists $metainfo{$full_rev}) {
5188 $metainfo{$full_rev} = { 'nprevious' => 0 };
5190 my $meta = $metainfo{$full_rev};
5192 while ($data = <$fd>) {
5194 last if ($data =~ s/^\t//); # contents of line
5195 if ($data =~ /^(\S+)(?: (.*))?$/) {
5196 $meta->{$1} = $2 unless exists $meta->{$1};
5198 if ($data =~ /^previous /) {
5199 $meta->{'nprevious'}++;
5202 my $short_rev = substr($full_rev, 0, 8);
5203 my $author = $meta->{'author'};
5205 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5206 my $date = $date{'iso-tz'};
5208 $current_color = ($current_color + 1) % $num_colors;
5210 my $tr_class = $rev_color[$current_color];
5211 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5212 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5213 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5214 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5216 print "<td class=\"sha1\"";
5217 print " title=\"". esc_html
($author) . ", $date\"";
5218 print " rowspan=\"$group_size\"" if ($group_size > 1);
5220 print $cgi->a({-href
=> href
(action
=>"commit",
5222 file_name
=>$file_name)},
5223 esc_html
($short_rev));
5224 if ($group_size >= 2) {
5225 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5226 if (@author_initials) {
5228 esc_html
(join('', @author_initials));
5234 # 'previous' <sha1 of parent commit> <filename at commit>
5235 if (exists $meta->{'previous'} &&
5236 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5237 $meta->{'parent'} = $1;
5238 $meta->{'file_parent'} = unquote
($2);
5241 exists($meta->{'parent'}) ?
5242 $meta->{'parent'} : $full_rev;
5243 my $linenr_filename =
5244 exists($meta->{'file_parent'}) ?
5245 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5246 my $blamed = href
(action
=> 'blame',
5247 file_name
=> $linenr_filename,
5248 hash_base
=> $linenr_commit);
5249 print "<td class=\"linenr\">";
5250 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5251 -class => "linenr" },
5254 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5262 "</table>\n"; # class="blame"
5263 print "</div>\n"; # class="blame_body"
5265 or print "Reading blob failed\n";
5274 sub git_blame_incremental
{
5275 git_blame_common
('incremental');
5278 sub git_blame_data
{
5279 git_blame_common
('data');
5283 my $head = git_get_head_hash
($project);
5285 git_print_page_nav
('','', $head,undef,$head);
5286 git_print_header_div
('summary', $project);
5288 my @tagslist = git_get_tags_list
();
5290 git_tags_body
(\
@tagslist);
5296 my $head = git_get_head_hash
($project);
5298 git_print_page_nav
('','', $head,undef,$head);
5299 git_print_header_div
('summary', $project);
5301 my @headslist = git_get_heads_list
();
5303 git_heads_body
(\
@headslist, $head);
5308 sub git_blob_plain
{
5312 if (!defined $hash) {
5313 if (defined $file_name) {
5314 my $base = $hash_base || git_get_head_hash
($project);
5315 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5316 or die_error
(404, "Cannot find file");
5318 die_error
(400, "No file name defined");
5320 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5321 # blobs defined by non-textual hash id's can be cached
5325 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5326 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5328 # content-type (can include charset)
5329 $type = blob_contenttype
($fd, $file_name, $type);
5331 # "save as" filename, even when no $file_name is given
5332 my $save_as = "$hash";
5333 if (defined $file_name) {
5334 $save_as = $file_name;
5335 } elsif ($type =~ m/^text\//) {
5339 # With XSS prevention on, blobs of all types except a few known safe
5340 # ones are served with "Content-Disposition: attachment" to make sure
5341 # they don't run in our security domain. For certain image types,
5342 # blob view writes an <img> tag referring to blob_plain view, and we
5343 # want to be sure not to break that by serving the image as an
5344 # attachment (though Firefox 3 doesn't seem to care).
5345 my $sandbox = $prevent_xss &&
5346 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5350 -expires
=> $expires,
5351 -content_disposition
=>
5352 ($sandbox ? 'attachment' : 'inline')
5353 . '; filename="' . $save_as . '"');
5355 binmode STDOUT
, ':raw';
5357 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5364 if (!defined $hash) {
5365 if (defined $file_name) {
5366 my $base = $hash_base || git_get_head_hash
($project);
5367 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5368 or die_error
(404, "Cannot find file");
5370 die_error
(400, "No file name defined");
5372 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5373 # blobs defined by non-textual hash id's can be cached
5377 my $have_blame = gitweb_check_feature
('blame');
5378 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5379 or die_error
(500, "Couldn't cat $file_name, $hash");
5380 my $mimetype = blob_mimetype
($fd, $file_name);
5381 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5383 return git_blob_plain
($mimetype);
5385 # we can have blame only for text/* mimetype
5386 $have_blame &&= ($mimetype =~ m!^text/!);
5388 git_header_html
(undef, $expires);
5389 my $formats_nav = '';
5390 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5391 if (defined $file_name) {
5394 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5399 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5402 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5405 $cgi->a({-href
=> href
(action
=>"blob",
5406 hash_base
=>"HEAD", file_name
=>$file_name)},
5410 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5413 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5414 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5416 print "<div class=\"page_nav\">\n" .
5417 "<br/><br/></div>\n" .
5418 "<div class=\"title\">$hash</div>\n";
5420 git_print_page_path
($file_name, "blob", $hash_base);
5421 print "<div class=\"page_body\">\n";
5422 if ($mimetype =~ m!^image/!) {
5423 print qq
!<img type
="$mimetype"!;
5425 print qq
! alt
="$file_name" title
="$file_name"!;
5428 href(action=>"blob_plain
", hash=>$hash,
5429 hash_base=>$hash_base, file_name=>$file_name) .
5433 while (my $line = <$fd>) {
5436 $line = untabify
($line);
5437 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5438 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5439 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5443 or print "Reading blob failed.\n";
5449 if (!defined $hash_base) {
5450 $hash_base = "HEAD";
5452 if (!defined $hash) {
5453 if (defined $file_name) {
5454 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5459 die_error
(404, "No such tree") unless defined($hash);
5461 my $show_sizes = gitweb_check_feature
('show-sizes');
5462 my $have_blame = gitweb_check_feature
('blame');
5467 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5468 ($show_sizes ? '-l' : ()), @extra_options, $hash
5469 or die_error
(500, "Open git-ls-tree failed");
5470 @entries = map { chomp; $_ } <$fd>;
5472 or die_error
(404, "Reading tree failed");
5475 my $refs = git_get_references
();
5476 my $ref = format_ref_marker
($refs, $hash_base);
5479 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5481 if (defined $file_name) {
5483 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5485 $cgi->a({-href
=> href
(action
=>"tree",
5486 hash_base
=>"HEAD", file_name
=>$file_name)},
5489 my $snapshot_links = format_snapshot_links
($hash);
5490 if (defined $snapshot_links) {
5491 # FIXME: Should be available when we have no hash base as well.
5492 push @views_nav, $snapshot_links;
5494 git_print_page_nav
('tree','', $hash_base, undef, undef,
5495 join(' | ', @views_nav));
5496 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5499 print "<div class=\"page_nav\">\n";
5500 print "<br/><br/></div>\n";
5501 print "<div class=\"title\">$hash</div>\n";
5503 if (defined $file_name) {
5504 $basedir = $file_name;
5505 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5508 git_print_page_path
($file_name, 'tree', $hash_base);
5510 print "<div class=\"page_body\">\n";
5511 print "<table class=\"tree\">\n";
5513 # '..' (top directory) link if possible
5514 if (defined $hash_base &&
5515 defined $file_name && $file_name =~ m![^/]+$!) {
5517 print "<tr class=\"dark\">\n";
5519 print "<tr class=\"light\">\n";
5523 my $up = $file_name;
5524 $up =~ s!/?[^/]+$!!;
5525 undef $up unless $up;
5526 # based on git_print_tree_entry
5527 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5528 print '<td class="size"> </td>'."\n" if $show_sizes;
5529 print '<td class="list">';
5530 print $cgi->a({-href
=> href
(action
=>"tree",
5531 hash_base
=>$hash_base,
5535 print "<td class=\"link\"></td>\n";
5539 foreach my $line (@entries) {
5540 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5543 print "<tr class=\"dark\">\n";
5545 print "<tr class=\"light\">\n";
5549 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5553 print "</table>\n" .
5559 my ($project, $hash) = @_;
5561 # path/to/project.git -> project
5562 # path/to/project/.git -> project
5563 my $name = to_utf8
($project);
5564 $name =~ s
,([^/])/*\
.git
$,$1,;
5565 $name = basename
($name);
5567 $name =~ s/[[:cntrl:]]/?/g;
5570 if ($hash =~ /^[0-9a-fA-F]+$/) {
5571 # shorten SHA-1 hash
5572 my $full_hash = git_get_full_hash
($project, $hash);
5573 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5574 $ver = git_get_short_hash
($project, $hash);
5576 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5577 # tags don't need shortened SHA-1 hash
5580 # branches and other need shortened SHA-1 hash
5581 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5584 $ver .= '-' . git_get_short_hash
($project, $hash);
5586 # in case of hierarchical branch names
5589 # name = project-version_string
5590 $name = "$name-$ver";
5592 return wantarray ? ($name, $name) : $name;
5596 my $format = $input_params{'snapshot_format'};
5597 if (!@snapshot_fmts) {
5598 die_error
(403, "Snapshots not allowed");
5600 # default to first supported snapshot format
5601 $format ||= $snapshot_fmts[0];
5602 if ($format !~ m/^[a-z0-9]+$/) {
5603 die_error
(400, "Invalid snapshot format parameter");
5604 } elsif (!exists($known_snapshot_formats{$format})) {
5605 die_error
(400, "Unknown snapshot format");
5606 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5607 die_error
(403, "Snapshot format not allowed");
5608 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5609 die_error
(403, "Unsupported snapshot format");
5612 my $type = git_get_type
("$hash^{}");
5614 die_error
(404, 'Object does not exist');
5615 } elsif ($type eq 'blob') {
5616 die_error
(400, 'Object is not a tree-ish');
5619 my ($name, $prefix) = snapshot_name
($project, $hash);
5620 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5621 my $cmd = quote_command
(
5622 git_cmd
(), 'archive',
5623 "--format=$known_snapshot_formats{$format}{'format'}",
5624 "--prefix=$prefix/", $hash);
5625 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5626 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5629 $filename =~ s/(["\\])/\\$1/g;
5631 -type
=> $known_snapshot_formats{$format}{'type'},
5632 -content_disposition
=> 'inline; filename="' . $filename . '"',
5633 -status
=> '200 OK');
5635 open my $fd, "-|", $cmd
5636 or die_error
(500, "Execute git-archive failed");
5637 binmode STDOUT
, ':raw';
5639 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5643 sub git_log_generic
{
5644 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5646 my $head = git_get_head_hash
($project);
5647 if (!defined $base) {
5650 if (!defined $page) {
5653 my $refs = git_get_references
();
5655 my $commit_hash = $base;
5656 if (defined $parent) {
5657 $commit_hash = "$parent..$base";
5660 parse_commits
($commit_hash, 101, (100 * $page),
5661 defined $file_name ? ($file_name, "--full-history") : ());
5664 if (!defined $file_hash && defined $file_name) {
5665 # some commits could have deleted file in question,
5666 # and not have it in tree, but one of them has to have it
5667 for (my $i = 0; $i < @commitlist; $i++) {
5668 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5669 last if defined $file_hash;
5672 if (defined $file_hash) {
5673 $ftype = git_get_type
($file_hash);
5675 if (defined $file_name && !defined $ftype) {
5676 die_error
(500, "Unknown type of object");
5679 if (defined $file_name) {
5680 %co = parse_commit
($base)
5681 or die_error
(404, "Unknown commit object");
5685 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5687 if ($#commitlist >= 100) {
5689 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5690 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5692 my $patch_max = gitweb_get_feature
('patches');
5693 if ($patch_max && !defined $file_name) {
5694 if ($patch_max < 0 || @commitlist <= $patch_max) {
5695 $paging_nav .= " ⋅ " .
5696 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5702 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5703 if (defined $file_name) {
5704 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5706 git_print_header_div
('summary', $project)
5708 git_print_page_path
($file_name, $ftype, $hash_base)
5709 if (defined $file_name);
5711 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5712 $file_name, $file_hash, $ftype);
5718 git_log_generic
('log', \
&git_log_body
,
5719 $hash, $hash_parent);
5723 $hash ||= $hash_base || "HEAD";
5724 my %co = parse_commit
($hash)
5725 or die_error
(404, "Unknown commit object");
5727 my $parent = $co{'parent'};
5728 my $parents = $co{'parents'}; # listref
5730 # we need to prepare $formats_nav before any parameter munging
5732 if (!defined $parent) {
5734 $formats_nav .= '(initial)';
5735 } elsif (@$parents == 1) {
5736 # single parent commit
5739 $cgi->a({-href
=> href
(action
=>"commit",
5741 esc_html
(substr($parent, 0, 7))) .
5748 $cgi->a({-href
=> href
(action
=>"commit",
5750 esc_html
(substr($_, 0, 7)));
5754 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5755 $formats_nav .= " | " .
5756 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5760 if (!defined $parent) {
5764 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5766 (@$parents <= 1 ? $parent : '-c'),
5768 or die_error
(500, "Open git-diff-tree failed");
5769 @difftree = map { chomp; $_ } <$fd>;
5770 close $fd or die_error
(404, "Reading git-diff-tree failed");
5772 # non-textual hash id's can be cached
5774 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5777 my $refs = git_get_references
();
5778 my $ref = format_ref_marker
($refs, $co{'id'});
5780 git_header_html
(undef, $expires);
5781 git_print_page_nav
('commit', '',
5782 $hash, $co{'tree'}, $hash,
5785 if (defined $co{'parent'}) {
5786 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5788 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5790 print "<div class=\"title_text\">\n" .
5791 "<table class=\"object_header\">\n";
5792 git_print_authorship_rows
(\
%co);
5793 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5796 "<td class=\"sha1\">" .
5797 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5798 class => "list"}, $co{'tree'}) .
5800 "<td class=\"link\">" .
5801 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5803 my $snapshot_links = format_snapshot_links
($hash);
5804 if (defined $snapshot_links) {
5805 print " | " . $snapshot_links;
5810 foreach my $par (@$parents) {
5813 "<td class=\"sha1\">" .
5814 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5815 class => "list"}, $par) .
5817 "<td class=\"link\">" .
5818 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5820 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5827 print "<div class=\"page_body\">\n";
5828 git_print_log
($co{'comment'});
5831 git_difftree_body
(\
@difftree, $hash, @$parents);
5837 # object is defined by:
5838 # - hash or hash_base alone
5839 # - hash_base and file_name
5842 # - hash or hash_base alone
5843 if ($hash || ($hash_base && !defined $file_name)) {
5844 my $object_id = $hash || $hash_base;
5846 open my $fd, "-|", quote_command
(
5847 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5848 or die_error
(404, "Object does not exist");
5852 or die_error
(404, "Object does not exist");
5854 # - hash_base and file_name
5855 } elsif ($hash_base && defined $file_name) {
5856 $file_name =~ s
,/+$,,;
5858 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5859 or die_error
(404, "Base object does not exist");
5861 # here errors should not hapen
5862 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5863 or die_error
(500, "Open git-ls-tree failed");
5867 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5868 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5869 die_error
(404, "File or directory for given base does not exist");
5874 die_error
(400, "Not enough information to find object");
5877 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5878 hash
=>$hash, hash_base
=>$hash_base,
5879 file_name
=>$file_name),
5880 -status
=> '302 Found');
5884 my $format = shift || 'html';
5891 # preparing $fd and %diffinfo for git_patchset_body
5893 if (defined $hash_base && defined $hash_parent_base) {
5894 if (defined $file_name) {
5896 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5897 $hash_parent_base, $hash_base,
5898 "--", (defined $file_parent ? $file_parent : ()), $file_name
5899 or die_error
(500, "Open git-diff-tree failed");
5900 @difftree = map { chomp; $_ } <$fd>;
5902 or die_error
(404, "Reading git-diff-tree failed");
5904 or die_error
(404, "Blob diff not found");
5906 } elsif (defined $hash &&
5907 $hash =~ /[0-9a-fA-F]{40}/) {
5908 # try to find filename from $hash
5910 # read filtered raw output
5911 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5912 $hash_parent_base, $hash_base, "--"
5913 or die_error
(500, "Open git-diff-tree failed");
5915 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5917 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5918 map { chomp; $_ } <$fd>;
5920 or die_error
(404, "Reading git-diff-tree failed");
5922 or die_error
(404, "Blob diff not found");
5925 die_error
(400, "Missing one of the blob diff parameters");
5928 if (@difftree > 1) {
5929 die_error
(400, "Ambiguous blob diff specification");
5932 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5933 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5934 $file_name ||= $diffinfo{'to_file'};
5936 $hash_parent ||= $diffinfo{'from_id'};
5937 $hash ||= $diffinfo{'to_id'};
5939 # non-textual hash id's can be cached
5940 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5941 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5946 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5947 '-p', ($format eq 'html' ? "--full-index" : ()),
5948 $hash_parent_base, $hash_base,
5949 "--", (defined $file_parent ? $file_parent : ()), $file_name
5950 or die_error
(500, "Open git-diff-tree failed");
5953 # old/legacy style URI -- not generated anymore since 1.4.3.
5955 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5959 if ($format eq 'html') {
5961 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5963 git_header_html
(undef, $expires);
5964 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5965 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5966 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5968 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5969 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5971 if (defined $file_name) {
5972 git_print_page_path
($file_name, "blob", $hash_base);
5974 print "<div class=\"page_path\"></div>\n";
5977 } elsif ($format eq 'plain') {
5979 -type
=> 'text/plain',
5980 -charset
=> 'utf-8',
5981 -expires
=> $expires,
5982 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5984 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5987 die_error
(400, "Unknown blobdiff format");
5991 if ($format eq 'html') {
5992 print "<div class=\"page_body\">\n";
5994 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5997 print "</div>\n"; # class="page_body"
6001 while (my $line = <$fd>) {
6002 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
6003 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
6007 last if $line =~ m!^\+\+\+!;
6015 sub git_blobdiff_plain
{
6016 git_blobdiff
('plain');
6019 sub git_commitdiff
{
6021 my $format = $params{-format
} || 'html';
6023 my ($patch_max) = gitweb_get_feature
('patches');
6024 if ($format eq 'patch') {
6025 die_error
(403, "Patch view not allowed") unless $patch_max;
6028 $hash ||= $hash_base || "HEAD";
6029 my %co = parse_commit
($hash)
6030 or die_error
(404, "Unknown commit object");
6032 # choose format for commitdiff for merge
6033 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
6034 $hash_parent = '--cc';
6036 # we need to prepare $formats_nav before almost any parameter munging
6038 if ($format eq 'html') {
6040 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6042 if ($patch_max && @{$co{'parents'}} <= 1) {
6043 $formats_nav .= " | " .
6044 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6048 if (defined $hash_parent &&
6049 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6050 # commitdiff with two commits given
6051 my $hash_parent_short = $hash_parent;
6052 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6053 $hash_parent_short = substr($hash_parent, 0, 7);
6057 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
6058 if ($co{'parents'}[$i] eq $hash_parent) {
6059 $formats_nav .= ' parent ' . ($i+1);
6063 $formats_nav .= ': ' .
6064 $cgi->a({-href
=> href
(action
=>"commitdiff",
6065 hash
=>$hash_parent)},
6066 esc_html
($hash_parent_short)) .
6068 } elsif (!$co{'parent'}) {
6070 $formats_nav .= ' (initial)';
6071 } elsif (scalar @{$co{'parents'}} == 1) {
6072 # single parent commit
6075 $cgi->a({-href
=> href
(action
=>"commitdiff",
6076 hash
=>$co{'parent'})},
6077 esc_html
(substr($co{'parent'}, 0, 7))) .
6081 if ($hash_parent eq '--cc') {
6082 $formats_nav .= ' | ' .
6083 $cgi->a({-href
=> href
(action
=>"commitdiff",
6084 hash
=>$hash, hash_parent
=>'-c')},
6086 } else { # $hash_parent eq '-c'
6087 $formats_nav .= ' | ' .
6088 $cgi->a({-href
=> href
(action
=>"commitdiff",
6089 hash
=>$hash, hash_parent
=>'--cc')},
6095 $cgi->a({-href
=> href
(action
=>"commitdiff",
6097 esc_html
(substr($_, 0, 7)));
6098 } @{$co{'parents'}} ) .
6103 my $hash_parent_param = $hash_parent;
6104 if (!defined $hash_parent_param) {
6105 # --cc for multiple parents, --root for parentless
6106 $hash_parent_param =
6107 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6113 if ($format eq 'html') {
6114 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6115 "--no-commit-id", "--patch-with-raw", "--full-index",
6116 $hash_parent_param, $hash, "--"
6117 or die_error
(500, "Open git-diff-tree failed");
6119 while (my $line = <$fd>) {
6121 # empty line ends raw part of diff-tree output
6123 push @difftree, scalar parse_difftree_raw_line
($line);
6126 } elsif ($format eq 'plain') {
6127 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6128 '-p', $hash_parent_param, $hash, "--"
6129 or die_error
(500, "Open git-diff-tree failed");
6130 } elsif ($format eq 'patch') {
6131 # For commit ranges, we limit the output to the number of
6132 # patches specified in the 'patches' feature.
6133 # For single commits, we limit the output to a single patch,
6134 # diverging from the git-format-patch default.
6135 my @commit_spec = ();
6137 if ($patch_max > 0) {
6138 push @commit_spec, "-$patch_max";
6140 push @commit_spec, '-n', "$hash_parent..$hash";
6142 if ($params{-single
}) {
6143 push @commit_spec, '-1';
6145 if ($patch_max > 0) {
6146 push @commit_spec, "-$patch_max";
6148 push @commit_spec, "-n";
6150 push @commit_spec, '--root', $hash;
6152 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6153 '--stdout', @commit_spec
6154 or die_error
(500, "Open git-format-patch failed");
6156 die_error
(400, "Unknown commitdiff format");
6159 # non-textual hash id's can be cached
6161 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6165 # write commit message
6166 if ($format eq 'html') {
6167 my $refs = git_get_references
();
6168 my $ref = format_ref_marker
($refs, $co{'id'});
6170 git_header_html
(undef, $expires);
6171 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6172 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6173 print "<div class=\"title_text\">\n" .
6174 "<table class=\"object_header\">\n";
6175 git_print_authorship_rows
(\
%co);
6178 print "<div class=\"page_body\">\n";
6179 if (@{$co{'comment'}} > 1) {
6180 print "<div class=\"log\">\n";
6181 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6182 print "</div>\n"; # class="log"
6185 } elsif ($format eq 'plain') {
6186 my $refs = git_get_references
("tags");
6187 my $tagname = git_get_rev_name_tags
($hash);
6188 my $filename = basename
($project) . "-$hash.patch";
6191 -type
=> 'text/plain',
6192 -charset
=> 'utf-8',
6193 -expires
=> $expires,
6194 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6195 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6196 print "From: " . to_utf8
($co{'author'}) . "\n";
6197 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6198 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6200 print "X-Git-Tag: $tagname\n" if $tagname;
6201 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6203 foreach my $line (@{$co{'comment'}}) {
6204 print to_utf8
($line) . "\n";
6207 } elsif ($format eq 'patch') {
6208 my $filename = basename
($project) . "-$hash.patch";
6211 -type
=> 'text/plain',
6212 -charset
=> 'utf-8',
6213 -expires
=> $expires,
6214 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6218 if ($format eq 'html') {
6219 my $use_parents = !defined $hash_parent ||
6220 $hash_parent eq '-c' || $hash_parent eq '--cc';
6221 git_difftree_body
(\
@difftree, $hash,
6222 $use_parents ? @{$co{'parents'}} : $hash_parent);
6225 git_patchset_body
($fd, \
@difftree, $hash,
6226 $use_parents ? @{$co{'parents'}} : $hash_parent);
6228 print "</div>\n"; # class="page_body"
6231 } elsif ($format eq 'plain') {
6235 or print "Reading git-diff-tree failed\n";
6236 } elsif ($format eq 'patch') {
6240 or print "Reading git-format-patch failed\n";
6244 sub git_commitdiff_plain
{
6245 git_commitdiff
(-format
=> 'plain');
6248 # format-patch-style patches
6250 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6254 git_commitdiff
(-format
=> 'patch');
6258 git_log_generic
('history', \
&git_history_body
,
6259 $hash_base, $hash_parent_base,
6264 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6265 if (!defined $searchtext) {
6266 die_error
(400, "Text field is empty");
6268 if (!defined $hash) {
6269 $hash = git_get_head_hash
($project);
6271 my %co = parse_commit
($hash);
6273 die_error
(404, "Unknown commit object");
6275 if (!defined $page) {
6279 $searchtype ||= 'commit';
6280 if ($searchtype eq 'pickaxe') {
6281 # pickaxe may take all resources of your box and run for several minutes
6282 # with every query - so decide by yourself how public you make this feature
6283 gitweb_check_feature
('pickaxe')
6284 or die_error
(403, "Pickaxe is disabled");
6286 if ($searchtype eq 'grep') {
6287 gitweb_check_feature
('grep')[0]
6288 or die_error
(403, "Grep is disabled");
6293 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6295 if ($searchtype eq 'commit') {
6296 $greptype = "--grep=";
6297 } elsif ($searchtype eq 'author') {
6298 $greptype = "--author=";
6299 } elsif ($searchtype eq 'committer') {
6300 $greptype = "--committer=";
6302 $greptype .= $searchtext;
6303 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6304 $greptype, '--regexp-ignore-case',
6305 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6307 my $paging_nav = '';
6310 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6311 searchtext
=>$searchtext,
6312 searchtype
=>$searchtype)},
6314 $paging_nav .= " ⋅ " .
6315 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6316 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6318 $paging_nav .= "first";
6319 $paging_nav .= " ⋅ prev";
6322 if ($#commitlist >= 100) {
6324 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6325 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6326 $paging_nav .= " ⋅ $next_link";
6328 $paging_nav .= " ⋅ next";
6331 if ($#commitlist >= 100) {
6334 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6335 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6336 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6339 if ($searchtype eq 'pickaxe') {
6340 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6341 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6343 print "<table class=\"pickaxe search\">\n";
6346 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6347 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6348 ($search_use_regexp ? '--pickaxe-regex' : ());
6351 while (my $line = <$fd>) {
6355 my %set = parse_difftree_raw_line
($line);
6356 if (defined $set{'commit'}) {
6357 # finish previous commit
6360 "<td class=\"link\">" .
6361 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6363 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6369 print "<tr class=\"dark\">\n";
6371 print "<tr class=\"light\">\n";
6374 %co = parse_commit
($set{'commit'});
6375 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6376 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6377 "<td><i>$author</i></td>\n" .
6379 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6380 -class => "list subject"},
6381 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6382 } elsif (defined $set{'to_id'}) {
6383 next if ($set{'to_id'} =~ m/^0{40}$/);
6385 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6386 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6388 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6394 # finish last commit (warning: repetition!)
6397 "<td class=\"link\">" .
6398 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6400 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6408 if ($searchtype eq 'grep') {
6409 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6410 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6412 print "<table class=\"grep_search\">\n";
6416 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6417 $search_use_regexp ? ('-E', '-i') : '-F',
6418 $searchtext, $co{'tree'};
6420 while (my $line = <$fd>) {
6422 my ($file, $lno, $ltext, $binary);
6423 last if ($matches++ > 1000);
6424 if ($line =~ /^Binary file (.+) matches$/) {
6428 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6430 if ($file ne $lastfile) {
6431 $lastfile and print "</td></tr>\n";
6433 print "<tr class=\"dark\">\n";
6435 print "<tr class=\"light\">\n";
6437 print "<td class=\"list\">".
6438 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6439 file_name
=>"$file"),
6440 -class => "list"}, esc_path
($file));
6441 print "</td><td>\n";
6445 print "<div class=\"binary\">Binary file</div>\n";
6447 $ltext = untabify
($ltext);
6448 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6449 $ltext = esc_html
($1, -nbsp
=>1);
6450 $ltext .= '<span class="match">';
6451 $ltext .= esc_html
($2, -nbsp
=>1);
6452 $ltext .= '</span>';
6453 $ltext .= esc_html
($3, -nbsp
=>1);
6455 $ltext = esc_html
($ltext, -nbsp
=>1);
6457 print "<div class=\"pre\">" .
6458 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6459 file_name
=>"$file").'#l'.$lno,
6460 -class => "linenr"}, sprintf('%4i', $lno))
6461 . ' ' . $ltext . "</div>\n";
6465 print "</td></tr>\n";
6466 if ($matches > 1000) {
6467 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6470 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6479 sub git_search_help
{
6481 git_print_page_nav
('','', $hash,$hash,$hash);
6483 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6484 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6485 the pattern entered is recognized as the POSIX extended
6486 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6489 <dt><b>commit</b></dt>
6490 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6492 my $have_grep = gitweb_check_feature
('grep');
6495 <dt><b>grep</b></dt>
6496 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6497 a different one) are searched for the given pattern. On large trees, this search can take
6498 a while and put some strain on the server, so please use it with some consideration. Note that
6499 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6500 case-sensitive.</dd>
6504 <dt><b>author</b></dt>
6505 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6506 <dt><b>committer</b></dt>
6507 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6509 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6510 if ($have_pickaxe) {
6512 <dt><b>pickaxe</b></dt>
6513 <dd>All commits that caused the string to appear or disappear from any file (changes that
6514 added, removed or "modified" the string) will be listed. This search can take a while and
6515 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6516 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6524 git_log_generic
('shortlog', \
&git_shortlog_body
,
6525 $hash, $hash_parent);
6528 ## ......................................................................
6529 ## feeds (RSS, Atom; OPML)
6532 my $format = shift || 'atom';
6533 my $have_blame = gitweb_check_feature
('blame');
6535 # Atom: http://www.atomenabled.org/developers/syndication/
6536 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6537 if ($format ne 'rss' && $format ne 'atom') {
6538 die_error
(400, "Unknown web feed format");
6541 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6542 my $head = $hash || 'HEAD';
6543 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6547 my $content_type = "application/$format+xml";
6548 if (defined $cgi->http('HTTP_ACCEPT') &&
6549 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6550 # browser (feed reader) prefers text/xml
6551 $content_type = 'text/xml';
6553 if (defined($commitlist[0])) {
6554 %latest_commit = %{$commitlist[0]};
6555 my $latest_epoch = $latest_commit{'committer_epoch'};
6556 %latest_date = parse_date
($latest_epoch);
6557 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6558 if (defined $if_modified) {
6560 if (eval { require HTTP
::Date
; 1; }) {
6561 $since = HTTP
::Date
::str2time
($if_modified);
6562 } elsif (eval { require Time
::ParseDate
; 1; }) {
6563 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6565 if (defined $since && $latest_epoch <= $since) {
6567 -type
=> $content_type,
6568 -charset
=> 'utf-8',
6569 -last_modified
=> $latest_date{'rfc2822'},
6570 -status
=> '304 Not Modified');
6575 -type
=> $content_type,
6576 -charset
=> 'utf-8',
6577 -last_modified
=> $latest_date{'rfc2822'});
6580 -type
=> $content_type,
6581 -charset
=> 'utf-8');
6584 # Optimization: skip generating the body if client asks only
6585 # for Last-Modified date.
6586 return if ($cgi->request_method() eq 'HEAD');
6589 my $title = "$site_name - $project/$action";
6590 my $feed_type = 'log';
6591 if (defined $hash) {
6592 $title .= " - '$hash'";
6593 $feed_type = 'branch log';
6594 if (defined $file_name) {
6595 $title .= " :: $file_name";
6596 $feed_type = 'history';
6598 } elsif (defined $file_name) {
6599 $title .= " - $file_name";
6600 $feed_type = 'history';
6602 $title .= " $feed_type";
6603 my $descr = git_get_project_description
($project);
6604 if (defined $descr) {
6605 $descr = esc_html
($descr);
6607 $descr = "$project " .
6608 ($format eq 'rss' ? 'RSS' : 'Atom') .
6611 my $owner = git_get_project_owner
($project);
6612 $owner = esc_html
($owner);
6616 if (defined $file_name) {
6617 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6618 } elsif (defined $hash) {
6619 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6621 $alt_url = href
(-full
=>1, action
=>"summary");
6623 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6624 if ($format eq 'rss') {
6626 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6629 print "<title>$title</title>\n" .
6630 "<link>$alt_url</link>\n" .
6631 "<description>$descr</description>\n" .
6632 "<language>en</language>\n" .
6633 # project owner is responsible for 'editorial' content
6634 "<managingEditor>$owner</managingEditor>\n";
6635 if (defined $logo || defined $favicon) {
6636 # prefer the logo to the favicon, since RSS
6637 # doesn't allow both
6638 my $img = esc_url
($logo || $favicon);
6640 "<url>$img</url>\n" .
6641 "<title>$title</title>\n" .
6642 "<link>$alt_url</link>\n" .
6646 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6647 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6649 print "<generator>gitweb v.$version/$git_version</generator>\n";
6650 } elsif ($format eq 'atom') {
6652 <feed xmlns="http://www.w3.org/2005/Atom">
6654 print "<title>$title</title>\n" .
6655 "<subtitle>$descr</subtitle>\n" .
6656 '<link rel="alternate" type="text/html" href="' .
6657 $alt_url . '" />' . "\n" .
6658 '<link rel="self" type="' . $content_type . '" href="' .
6659 $cgi->self_url() . '" />' . "\n" .
6660 "<id>" . href
(-full
=>1) . "</id>\n" .
6661 # use project owner for feed author
6662 "<author><name>$owner</name></author>\n";
6663 if (defined $favicon) {
6664 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6666 if (defined $logo_url) {
6667 # not twice as wide as tall: 72 x 27 pixels
6668 print "<logo>" . esc_url
($logo) . "</logo>\n";
6670 if (! %latest_date) {
6671 # dummy date to keep the feed valid until commits trickle in:
6672 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6674 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6676 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6680 for (my $i = 0; $i <= $#commitlist; $i++) {
6681 my %co = %{$commitlist[$i]};
6682 my $commit = $co{'id'};
6683 # we read 150, we always show 30 and the ones more recent than 48 hours
6684 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6687 my %cd = parse_date
($co{'author_epoch'});
6689 # get list of changed files
6690 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6691 $co{'parent'} || "--root",
6692 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6694 my @difftree = map { chomp; $_ } <$fd>;
6698 # print element (entry, item)
6699 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6700 if ($format eq 'rss') {
6702 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6703 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6704 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6705 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6706 "<link>$co_url</link>\n" .
6707 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6708 "<content:encoded>" .
6710 } elsif ($format eq 'atom') {
6712 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6713 "<updated>$cd{'iso-8601'}</updated>\n" .
6715 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6716 if ($co{'author_email'}) {
6717 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6719 print "</author>\n" .
6720 # use committer for contributor
6722 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6723 if ($co{'committer_email'}) {
6724 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6726 print "</contributor>\n" .
6727 "<published>$cd{'iso-8601'}</published>\n" .
6728 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6729 "<id>$co_url</id>\n" .
6730 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6731 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6733 my $comment = $co{'comment'};
6735 foreach my $line (@$comment) {
6736 $line = esc_html
($line);
6739 print "</pre><ul>\n";
6740 foreach my $difftree_line (@difftree) {
6741 my %difftree = parse_difftree_raw_line
($difftree_line);
6742 next if !$difftree{'from_id'};
6744 my $file = $difftree{'file'} || $difftree{'to_file'};
6748 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6749 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6750 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6751 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6752 -title
=> "diff"}, 'D');
6754 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6755 file_name
=>$file, hash_base
=>$commit),
6756 -title
=> "blame"}, 'B');
6758 # if this is not a feed of a file history
6759 if (!defined $file_name || $file_name ne $file) {
6760 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6761 file_name
=>$file, hash
=>$commit),
6762 -title
=> "history"}, 'H');
6764 $file = esc_path
($file);
6768 if ($format eq 'rss') {
6769 print "</ul>]]>\n" .
6770 "</content:encoded>\n" .
6772 } elsif ($format eq 'atom') {
6773 print "</ul>\n</div>\n" .
6780 if ($format eq 'rss') {
6781 print "</channel>\n</rss>\n";
6782 } elsif ($format eq 'atom') {
6796 my @list = git_get_projects_list
();
6799 -type
=> 'text/xml',
6800 -charset
=> 'utf-8',
6801 -content_disposition
=> 'inline; filename="opml.xml"');
6804 <?xml version="1.0" encoding="utf-8"?>
6805 <opml version="1.0">
6807 <title>$site_name OPML Export</title>
6810 <outline text="git RSS feeds">
6813 foreach my $pr (@list) {
6815 my $head = git_get_head_hash
($proj{'path'});
6816 if (!defined $head) {
6819 $git_dir = "$projectroot/$proj{'path'}";
6820 my %co = parse_commit
($head);
6825 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6826 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6827 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6828 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";