3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI-
>compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
33 our $my_url = $cgi->url();
34 our $my_uri = $cgi->url(-absolute
=> 1);
36 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
37 # needed and used only for URLs with nonempty PATH_INFO
38 our $base_url = $my_url;
40 # When the script is used as DirectoryIndex, the URL does not contain the name
41 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
42 # have to do it ourselves. We make $path_info global because it's also used
45 # Another issue with the script being the DirectoryIndex is that the resulting
46 # $my_url data is not the full script URL: this is good, because we want
47 # generated links to keep implying the script name if it wasn't explicitly
48 # indicated in the URL we're handling, but it means that $my_url cannot be used
50 # Therefore, if we needed to strip PATH_INFO, then we know that we have
51 # to build the base URL ourselves:
52 our $path_info = $ENV{"PATH_INFO"};
54 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
55 $my_uri =~ s
,\Q
$path_info\E
$,, &&
56 defined $ENV{'SCRIPT_NAME'}) {
57 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
61 # core git executable to use
62 # this can just be "git" if your webserver has a sensible PATH
63 our $GIT = "++GIT_BINDIR++/git";
65 # absolute fs-path which will be prepended to the project path
66 #our $projectroot = "/pub/scm";
67 our $projectroot = "++GITWEB_PROJECTROOT++";
69 # fs traversing limit for getting project list
70 # the number is relative to the projectroot
71 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
73 # target of the home link on top of all pages
74 our $home_link = $my_uri || "/";
76 # string of the home link on top of all pages
77 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
79 # name of your site or organization to appear in page titles
80 # replace this with something more descriptive for clearer bookmarks
81 our $site_name = "++GITWEB_SITENAME++"
82 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
84 # filename of html text to include at top of each page
85 our $site_header = "++GITWEB_SITE_HEADER++";
86 # html text to include at home page
87 our $home_text = "++GITWEB_HOMETEXT++";
88 # filename of html text to include at bottom of each page
89 our $site_footer = "++GITWEB_SITE_FOOTER++";
92 our @stylesheets = ("++GITWEB_CSS++");
93 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
94 our $stylesheet = undef;
96 # URI of GIT logo (72x27 size)
97 our $logo = "++GITWEB_LOGO++";
98 # URI of GIT favicon, assumed to be image/png type
99 our $favicon = "++GITWEB_FAVICON++";
100 # URI of gitweb.js (JavaScript code for gitweb)
101 our $javascript = "++GITWEB_JS++";
103 # URI and label (title) of GIT logo link
104 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
105 #our $logo_label = "git documentation";
106 our $logo_url = "http://git-scm.com/";
107 our $logo_label = "git homepage";
109 # source of projects list
110 our $projects_list = "++GITWEB_LIST++";
112 # the width (in characters) of the projects list "Description" column
113 our $projects_list_description_width = 25;
115 # default order of projects list
116 # valid values are none, project, descr, owner, and age
117 our $default_projects_order = "project";
119 # show repository only if this file exists
120 # (only effective if this variable evaluates to true)
121 our $export_ok = "++GITWEB_EXPORT_OK++";
123 # show repository only if this subroutine returns true
124 # when given the path to the project, for example:
125 # sub { return -e "$_[0]/git-daemon-export-ok"; }
126 our $export_auth_hook = undef;
128 # only allow viewing of repositories also shown on the overview page
129 our $strict_export = "++GITWEB_STRICT_EXPORT++";
131 # list of git base URLs used for URL to where fetch project from,
132 # i.e. full URL is "$git_base_url/$project"
133 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
135 # default blob_plain mimetype and default charset for text/plain blob
136 our $default_blob_plain_mimetype = 'text/plain';
137 our $default_text_plain_charset = undef;
139 # file to use for guessing MIME types before trying /etc/mime.types
140 # (relative to the current git repository)
141 our $mimetypes_file = undef;
143 # assume this charset if line contains non-UTF-8 characters;
144 # it should be valid encoding (see Encoding::Supported(3pm) for list),
145 # for which encoding all byte sequences are valid, for example
146 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
147 # could be even 'utf-8' for the old behavior)
148 our $fallback_encoding = 'latin1';
150 # rename detection options for git-diff and git-diff-tree
151 # - default is '-M', with the cost proportional to
152 # (number of removed files) * (number of new files).
153 # - more costly is '-C' (which implies '-M'), with the cost proportional to
154 # (number of changed files + number of removed files) * (number of new files)
155 # - even more costly is '-C', '--find-copies-harder' with cost
156 # (number of files in the original tree) * (number of new files)
157 # - one might want to include '-B' option, e.g. '-B', '-M'
158 our @diff_opts = ('-M'); # taken from git_commit
160 # Disables features that would allow repository owners to inject script into
162 our $prevent_xss = 0;
164 # information about snapshot formats that gitweb is capable of serving
165 our %known_snapshot_formats = (
167 # 'display' => display name,
168 # 'type' => mime type,
169 # 'suffix' => filename suffix,
170 # 'format' => --format for git-archive,
171 # 'compressor' => [compressor command and arguments]
172 # (array reference, optional)
173 # 'disabled' => boolean (optional)}
176 'display' => 'tar.gz',
177 'type' => 'application/x-gzip',
178 'suffix' => '.tar.gz',
180 'compressor' => ['gzip']},
183 'display' => 'tar.bz2',
184 'type' => 'application/x-bzip2',
185 'suffix' => '.tar.bz2',
187 'compressor' => ['bzip2']},
190 'display' => 'tar.xz',
191 'type' => 'application/x-xz',
192 'suffix' => '.tar.xz',
194 'compressor' => ['xz'],
199 'type' => 'application/x-zip',
204 # Aliases so we understand old gitweb.snapshot values in repository
206 our %known_snapshot_format_aliases = (
211 # backward compatibility: legacy gitweb config support
212 'x-gzip' => undef, 'gz' => undef,
213 'x-bzip2' => undef, 'bz2' => undef,
214 'x-zip' => undef, '' => undef,
217 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
218 # are changed, it may be appropriate to change these values too via
225 # Used to set the maximum load that we will still respond to gitweb queries.
226 # If server load exceed this value then return "503 server busy" error.
227 # If gitweb cannot determined server load, it is taken to be 0.
228 # Leave it undefined (or set to 'undef') to turn off load checking.
231 # You define site-wide feature defaults here; override them with
232 # $GITWEB_CONFIG as necessary.
235 # 'sub' => feature-sub (subroutine),
236 # 'override' => allow-override (boolean),
237 # 'default' => [ default options...] (array reference)}
239 # if feature is overridable (it means that allow-override has true value),
240 # then feature-sub will be called with default options as parameters;
241 # return value of feature-sub indicates if to enable specified feature
243 # if there is no 'sub' key (no feature-sub), then feature cannot be
246 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
247 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
250 # Enable the 'blame' blob view, showing the last commit that modified
251 # each line in the file. This can be very CPU-intensive.
253 # To enable system wide have in $GITWEB_CONFIG
254 # $feature{'blame'}{'default'} = [1];
255 # To have project specific config enable override in $GITWEB_CONFIG
256 # $feature{'blame'}{'override'} = 1;
257 # and in project config gitweb.blame = 0|1;
259 'sub' => sub { feature_bool
('blame', @_) },
263 # Enable the 'snapshot' link, providing a compressed archive of any
264 # tree. This can potentially generate high traffic if you have large
267 # Value is a list of formats defined in %known_snapshot_formats that
269 # To disable system wide have in $GITWEB_CONFIG
270 # $feature{'snapshot'}{'default'} = [];
271 # To have project specific config enable override in $GITWEB_CONFIG
272 # $feature{'snapshot'}{'override'} = 1;
273 # and in project config, a comma-separated list of formats or "none"
274 # to disable. Example: gitweb.snapshot = tbz2,zip;
276 'sub' => \
&feature_snapshot
,
278 'default' => ['tgz']},
280 # Enable text search, which will list the commits which match author,
281 # committer or commit text to a given string. Enabled by default.
282 # Project specific override is not supported.
287 # Enable grep search, which will list the files in currently selected
288 # tree containing the given string. Enabled by default. This can be
289 # potentially CPU-intensive, of course.
291 # To enable system wide have in $GITWEB_CONFIG
292 # $feature{'grep'}{'default'} = [1];
293 # To have project specific config enable override in $GITWEB_CONFIG
294 # $feature{'grep'}{'override'} = 1;
295 # and in project config gitweb.grep = 0|1;
297 'sub' => sub { feature_bool
('grep', @_) },
301 # Enable the pickaxe search, which will list the commits that modified
302 # a given string in a file. This can be practical and quite faster
303 # alternative to 'blame', but still potentially CPU-intensive.
305 # To enable system wide have in $GITWEB_CONFIG
306 # $feature{'pickaxe'}{'default'} = [1];
307 # To have project specific config enable override in $GITWEB_CONFIG
308 # $feature{'pickaxe'}{'override'} = 1;
309 # and in project config gitweb.pickaxe = 0|1;
311 'sub' => sub { feature_bool
('pickaxe', @_) },
315 # Enable showing size of blobs in a 'tree' view, in a separate
316 # column, similar to what 'ls -l' does. This cost a bit of IO.
318 # To disable system wide have in $GITWEB_CONFIG
319 # $feature{'show-sizes'}{'default'} = [0];
320 # To have project specific config enable override in $GITWEB_CONFIG
321 # $feature{'show-sizes'}{'override'} = 1;
322 # and in project config gitweb.showsizes = 0|1;
324 'sub' => sub { feature_bool
('showsizes', @_) },
328 # Make gitweb use an alternative format of the URLs which can be
329 # more readable and natural-looking: project name is embedded
330 # directly in the path and the query string contains other
331 # auxiliary information. All gitweb installations recognize
332 # URL in either format; this configures in which formats gitweb
335 # To enable system wide have in $GITWEB_CONFIG
336 # $feature{'pathinfo'}{'default'} = [1];
337 # Project specific override is not supported.
339 # Note that you will need to change the default location of CSS,
340 # favicon, logo and possibly other files to an absolute URL. Also,
341 # if gitweb.cgi serves as your indexfile, you will need to force
342 # $my_uri to contain the script name in your $GITWEB_CONFIG.
347 # Make gitweb consider projects in project root subdirectories
348 # to be forks of existing projects. Given project $projname.git,
349 # projects matching $projname/*.git will not be shown in the main
350 # projects list, instead a '+' mark will be added to $projname
351 # there and a 'forks' view will be enabled for the project, listing
352 # all the forks. If project list is taken from a file, forks have
353 # to be listed after the main project.
355 # To enable system wide have in $GITWEB_CONFIG
356 # $feature{'forks'}{'default'} = [1];
357 # Project specific override is not supported.
362 # Insert custom links to the action bar of all project pages.
363 # This enables you mainly to link to third-party scripts integrating
364 # into gitweb; e.g. git-browser for graphical history representation
365 # or custom web-based repository administration interface.
367 # The 'default' value consists of a list of triplets in the form
368 # (label, link, position) where position is the label after which
369 # to insert the link and link is a format string where %n expands
370 # to the project name, %f to the project path within the filesystem,
371 # %h to the current hash (h gitweb parameter) and %b to the current
372 # hash base (hb gitweb parameter); %% expands to %.
374 # To enable system wide have in $GITWEB_CONFIG e.g.
375 # $feature{'actions'}{'default'} = [('graphiclog',
376 # '/git-browser/by-commit.html?r=%n', 'summary')];
377 # Project specific override is not supported.
382 # Allow gitweb scan project content tags described in ctags/
383 # of project repository, and display the popular Web 2.0-ish
384 # "tag cloud" near the project list. Note that this is something
385 # COMPLETELY different from the normal Git tags.
387 # gitweb by itself can show existing tags, but it does not handle
388 # tagging itself; you need an external application for that.
389 # For an example script, check Girocco's cgi/tagproj.cgi.
390 # You may want to install the HTML::TagCloud Perl module to get
391 # a pretty tag cloud instead of just a list of tags.
393 # To enable system wide have in $GITWEB_CONFIG
394 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
395 # Project specific override is not supported.
400 # The maximum number of patches in a patchset generated in patch
401 # view. Set this to 0 or undef to disable patch view, or to a
402 # negative number to remove any limit.
404 # To disable system wide have in $GITWEB_CONFIG
405 # $feature{'patches'}{'default'} = [0];
406 # To have project specific config enable override in $GITWEB_CONFIG
407 # $feature{'patches'}{'override'} = 1;
408 # and in project config gitweb.patches = 0|n;
409 # where n is the maximum number of patches allowed in a patchset.
411 'sub' => \
&feature_patches
,
415 # Avatar support. When this feature is enabled, views such as
416 # shortlog or commit will display an avatar associated with
417 # the email of the committer(s) and/or author(s).
419 # Currently available providers are gravatar and picon.
420 # If an unknown provider is specified, the feature is disabled.
422 # Gravatar depends on Digest::MD5.
423 # Picon currently relies on the indiana.edu database.
425 # To enable system wide have in $GITWEB_CONFIG
426 # $feature{'avatar'}{'default'} = ['<provider>'];
427 # where <provider> is either gravatar or picon.
428 # To have project specific config enable override in $GITWEB_CONFIG
429 # $feature{'avatar'}{'override'} = 1;
430 # and in project config gitweb.avatar = <provider>;
432 'sub' => \
&feature_avatar
,
436 # Enable displaying how much time and how many git commands
437 # it took to generate and display page. Disabled by default.
438 # Project specific override is not supported.
443 # Enable turning some links into links to actions which require
444 # JavaScript to run (like 'blame_incremental'). Not enabled by
445 # default. Project specific override is currently not supported.
446 'javascript-actions' => {
451 sub gitweb_get_feature
{
453 return unless exists $feature{$name};
454 my ($sub, $override, @defaults) = (
455 $feature{$name}{'sub'},
456 $feature{$name}{'override'},
457 @{$feature{$name}{'default'}});
458 if (!$override) { return @defaults; }
460 warn "feature $name is not overridable";
463 return $sub->(@defaults);
466 # A wrapper to check if a given feature is enabled.
467 # With this, you can say
469 # my $bool_feat = gitweb_check_feature('bool_feat');
470 # gitweb_check_feature('bool_feat') or somecode;
474 # my ($bool_feat) = gitweb_get_feature('bool_feat');
475 # (gitweb_get_feature('bool_feat'))[0] or somecode;
477 sub gitweb_check_feature
{
478 return (gitweb_get_feature
(@_))[0];
484 my ($val) = git_get_project_config
($key, '--bool');
488 } elsif ($val eq 'true') {
490 } elsif ($val eq 'false') {
495 sub feature_snapshot
{
498 my ($val) = git_get_project_config
('snapshot');
501 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
507 sub feature_patches
{
508 my @val = (git_get_project_config
('patches', '--int'));
518 my @val = (git_get_project_config
('avatar'));
520 return @val ? @val : @_;
523 # checking HEAD file with -e is fragile if the repository was
524 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
526 sub check_head_link
{
528 my $headfile = "$dir/HEAD";
529 return ((-e
$headfile) ||
530 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
533 sub check_export_ok
{
535 return (check_head_link
($dir) &&
536 (!$export_ok || -e
"$dir/$export_ok") &&
537 (!$export_auth_hook || $export_auth_hook->($dir)));
540 # process alternate names for backward compatibility
541 # filter out unsupported (unknown) snapshot formats
542 sub filter_snapshot_fmts
{
546 exists $known_snapshot_format_aliases{$_} ?
547 $known_snapshot_format_aliases{$_} : $_} @fmts;
549 exists $known_snapshot_formats{$_} &&
550 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
553 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
554 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
555 # die if there are errors parsing config file
556 if (-e
$GITWEB_CONFIG) {
559 } elsif (-e
$GITWEB_CONFIG_SYSTEM) {
560 do $GITWEB_CONFIG_SYSTEM;
564 # Get loadavg of system, to compare against $maxload.
565 # Currently it requires '/proc/loadavg' present to get loadavg;
566 # if it is not present it returns 0, which means no load checking.
568 if( -e
'/proc/loadavg' ){
569 open my $fd, '<', '/proc/loadavg'
571 my @load = split(/\s+/, scalar <$fd>);
574 # The first three columns measure CPU and IO utilization of the last one,
575 # five, and 10 minute periods. The fourth column shows the number of
576 # currently running processes and the total number of processes in the m/n
577 # format. The last column displays the last process ID used.
578 return $load[0] || 0;
580 # additional checks for load average should go here for things that don't export
586 # version of the core git binary
587 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
588 $number_of_git_cmds++;
590 $projects_list ||= $projectroot;
592 if (defined $maxload && get_loadavg
() > $maxload) {
593 die_error
(503, "The load average on the server is too high");
596 # ======================================================================
597 # input validation and dispatch
599 # input parameters can be collected from a variety of sources (presently, CGI
600 # and PATH_INFO), so we define an %input_params hash that collects them all
601 # together during validation: this allows subsequent uses (e.g. href()) to be
602 # agnostic of the parameter origin
604 our %input_params = ();
606 # input parameters are stored with the long parameter name as key. This will
607 # also be used in the href subroutine to convert parameters to their CGI
608 # equivalent, and since the href() usage is the most frequent one, we store
609 # the name -> CGI key mapping here, instead of the reverse.
611 # XXX: Warning: If you touch this, check the search form for updating,
614 our @cgi_param_mapping = (
622 hash_parent_base
=> "hpb",
627 snapshot_format
=> "sf",
628 extra_options
=> "opt",
629 search_use_regexp
=> "sr",
630 # this must be last entry (for manipulation from JavaScript)
633 our %cgi_param_mapping = @cgi_param_mapping;
635 # we will also need to know the possible actions, for validation
637 "blame" => \
&git_blame
,
638 "blame_incremental" => \
&git_blame_incremental
,
639 "blame_data" => \
&git_blame_data
,
640 "blobdiff" => \
&git_blobdiff
,
641 "blobdiff_plain" => \
&git_blobdiff_plain
,
642 "blob" => \
&git_blob
,
643 "blob_plain" => \
&git_blob_plain
,
644 "commitdiff" => \
&git_commitdiff
,
645 "commitdiff_plain" => \
&git_commitdiff_plain
,
646 "commit" => \
&git_commit
,
647 "forks" => \
&git_forks
,
648 "heads" => \
&git_heads
,
649 "history" => \
&git_history
,
651 "patch" => \
&git_patch
,
652 "patches" => \
&git_patches
,
654 "atom" => \
&git_atom
,
655 "search" => \
&git_search
,
656 "search_help" => \
&git_search_help
,
657 "shortlog" => \
&git_shortlog
,
658 "summary" => \
&git_summary
,
660 "tags" => \
&git_tags
,
661 "tree" => \
&git_tree
,
662 "snapshot" => \
&git_snapshot
,
663 "object" => \
&git_object
,
664 # those below don't need $project
665 "opml" => \
&git_opml
,
666 "project_list" => \
&git_project_list
,
667 "project_index" => \
&git_project_index
,
670 # finally, we have the hash of allowed extra_options for the commands that
672 our %allowed_options = (
673 "--no-merges" => [ qw(rss atom log shortlog history) ],
676 # fill %input_params with the CGI parameters. All values except for 'opt'
677 # should be single values, but opt can be an array. We should probably
678 # build an array of parameters that can be multi-valued, but since for the time
679 # being it's only this one, we just single it out
680 while (my ($name, $symbol) = each %cgi_param_mapping) {
681 if ($symbol eq 'opt') {
682 $input_params{$name} = [ $cgi->param($symbol) ];
684 $input_params{$name} = $cgi->param($symbol);
688 # now read PATH_INFO and update the parameter list for missing parameters
689 sub evaluate_path_info
{
690 return if defined $input_params{'project'};
691 return if !$path_info;
692 $path_info =~ s
,^/+,,;
693 return if !$path_info;
695 # find which part of PATH_INFO is project
696 my $project = $path_info;
698 while ($project && !check_head_link
("$projectroot/$project")) {
699 $project =~ s
,/*[^/]*$,,;
701 return unless $project;
702 $input_params{'project'} = $project;
704 # do not change any parameters if an action is given using the query string
705 return if $input_params{'action'};
706 $path_info =~ s
,^\Q
$project\E
/*,,;
708 # next, check if we have an action
709 my $action = $path_info;
711 if (exists $actions{$action}) {
712 $path_info =~ s
,^$action/*,,;
713 $input_params{'action'} = $action;
716 # list of actions that want hash_base instead of hash, but can have no
717 # pathname (f) parameter
724 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
725 my ($parentrefname, $parentpathname, $refname, $pathname) =
726 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
728 # first, analyze the 'current' part
729 if (defined $pathname) {
730 # we got "branch:filename" or "branch:dir/"
731 # we could use git_get_type(branch:pathname), but:
732 # - it needs $git_dir
733 # - it does a git() call
734 # - the convention of terminating directories with a slash
735 # makes it superfluous
736 # - embedding the action in the PATH_INFO would make it even
738 $pathname =~ s
,^/+,,;
739 if (!$pathname || substr($pathname, -1) eq "/") {
740 $input_params{'action'} ||= "tree";
743 # the default action depends on whether we had parent info
745 if ($parentrefname) {
746 $input_params{'action'} ||= "blobdiff_plain";
748 $input_params{'action'} ||= "blob_plain";
751 $input_params{'hash_base'} ||= $refname;
752 $input_params{'file_name'} ||= $pathname;
753 } elsif (defined $refname) {
754 # we got "branch". In this case we have to choose if we have to
755 # set hash or hash_base.
757 # Most of the actions without a pathname only want hash to be
758 # set, except for the ones specified in @wants_base that want
759 # hash_base instead. It should also be noted that hand-crafted
760 # links having 'history' as an action and no pathname or hash
761 # set will fail, but that happens regardless of PATH_INFO.
762 $input_params{'action'} ||= "shortlog";
763 if (grep { $_ eq $input_params{'action'} } @wants_base) {
764 $input_params{'hash_base'} ||= $refname;
766 $input_params{'hash'} ||= $refname;
770 # next, handle the 'parent' part, if present
771 if (defined $parentrefname) {
772 # a missing pathspec defaults to the 'current' filename, allowing e.g.
773 # someproject/blobdiff/oldrev..newrev:/filename
774 if ($parentpathname) {
775 $parentpathname =~ s
,^/+,,;
776 $parentpathname =~ s
,/$,,;
777 $input_params{'file_parent'} ||= $parentpathname;
779 $input_params{'file_parent'} ||= $input_params{'file_name'};
781 # we assume that hash_parent_base is wanted if a path was specified,
782 # or if the action wants hash_base instead of hash
783 if (defined $input_params{'file_parent'} ||
784 grep { $_ eq $input_params{'action'} } @wants_base) {
785 $input_params{'hash_parent_base'} ||= $parentrefname;
787 $input_params{'hash_parent'} ||= $parentrefname;
791 # for the snapshot action, we allow URLs in the form
792 # $project/snapshot/$hash.ext
793 # where .ext determines the snapshot and gets removed from the
794 # passed $refname to provide the $hash.
796 # To be able to tell that $refname includes the format extension, we
797 # require the following two conditions to be satisfied:
798 # - the hash input parameter MUST have been set from the $refname part
799 # of the URL (i.e. they must be equal)
800 # - the snapshot format MUST NOT have been defined already (e.g. from
802 # It's also useless to try any matching unless $refname has a dot,
803 # so we check for that too
804 if (defined $input_params{'action'} &&
805 $input_params{'action'} eq 'snapshot' &&
806 defined $refname && index($refname, '.') != -1 &&
807 $refname eq $input_params{'hash'} &&
808 !defined $input_params{'snapshot_format'}) {
809 # We loop over the known snapshot formats, checking for
810 # extensions. Allowed extensions are both the defined suffix
811 # (which includes the initial dot already) and the snapshot
812 # format key itself, with a prepended dot
813 while (my ($fmt, $opt) = each %known_snapshot_formats) {
815 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
819 # a valid suffix was found, so set the snapshot format
820 # and reset the hash parameter
821 $input_params{'snapshot_format'} = $fmt;
822 $input_params{'hash'} = $hash;
823 # we also set the format suffix to the one requested
824 # in the URL: this way a request for e.g. .tgz returns
825 # a .tgz instead of a .tar.gz
826 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
831 evaluate_path_info
();
833 our $action = $input_params{'action'};
834 if (defined $action) {
835 if (!validate_action
($action)) {
836 die_error
(400, "Invalid action parameter");
840 # parameters which are pathnames
841 our $project = $input_params{'project'};
842 if (defined $project) {
843 if (!validate_project
($project)) {
845 die_error
(404, "No such project");
849 our $file_name = $input_params{'file_name'};
850 if (defined $file_name) {
851 if (!validate_pathname
($file_name)) {
852 die_error
(400, "Invalid file parameter");
856 our $file_parent = $input_params{'file_parent'};
857 if (defined $file_parent) {
858 if (!validate_pathname
($file_parent)) {
859 die_error
(400, "Invalid file parent parameter");
863 # parameters which are refnames
864 our $hash = $input_params{'hash'};
866 if (!validate_refname
($hash)) {
867 die_error
(400, "Invalid hash parameter");
871 our $hash_parent = $input_params{'hash_parent'};
872 if (defined $hash_parent) {
873 if (!validate_refname
($hash_parent)) {
874 die_error
(400, "Invalid hash parent parameter");
878 our $hash_base = $input_params{'hash_base'};
879 if (defined $hash_base) {
880 if (!validate_refname
($hash_base)) {
881 die_error
(400, "Invalid hash base parameter");
885 our @extra_options = @{$input_params{'extra_options'}};
886 # @extra_options is always defined, since it can only be (currently) set from
887 # CGI, and $cgi->param() returns the empty array in array context if the param
889 foreach my $opt (@extra_options) {
890 if (not exists $allowed_options{$opt}) {
891 die_error
(400, "Invalid option parameter");
893 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
894 die_error
(400, "Invalid option parameter for this action");
898 our $hash_parent_base = $input_params{'hash_parent_base'};
899 if (defined $hash_parent_base) {
900 if (!validate_refname
($hash_parent_base)) {
901 die_error
(400, "Invalid hash parent base parameter");
906 our $page = $input_params{'page'};
908 if ($page =~ m/[^0-9]/) {
909 die_error
(400, "Invalid page parameter");
913 our $searchtype = $input_params{'searchtype'};
914 if (defined $searchtype) {
915 if ($searchtype =~ m/[^a-z]/) {
916 die_error
(400, "Invalid searchtype parameter");
920 our $search_use_regexp = $input_params{'search_use_regexp'};
922 our $searchtext = $input_params{'searchtext'};
924 if (defined $searchtext) {
925 if (length($searchtext) < 2) {
926 die_error
(403, "At least two characters are required for search parameter");
928 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
931 # path to the current git repository
933 $git_dir = "$projectroot/$project" if $project;
935 # list of supported snapshot formats
936 our @snapshot_fmts = gitweb_get_feature
('snapshot');
937 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
939 # check that the avatar feature is set to a known provider name,
940 # and for each provider check if the dependencies are satisfied.
941 # if the provider name is invalid or the dependencies are not met,
942 # reset $git_avatar to the empty string.
943 our ($git_avatar) = gitweb_get_feature
('avatar');
944 if ($git_avatar eq 'gravatar') {
945 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
946 } elsif ($git_avatar eq 'picon') {
953 if (!defined $action) {
955 $action = git_get_type
($hash);
956 } elsif (defined $hash_base && defined $file_name) {
957 $action = git_get_type
("$hash_base:$file_name");
958 } elsif (defined $project) {
961 $action = 'project_list';
964 if (!defined($actions{$action})) {
965 die_error
(400, "Unknown action");
967 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
969 die_error
(400, "Project needed");
971 $actions{$action}->();
974 ## ======================================================================
979 # default is to use -absolute url() i.e. $my_uri
980 my $href = $params{-full
} ? $my_url : $my_uri;
982 $params{'project'} = $project unless exists $params{'project'};
984 if ($params{-replay
}) {
985 while (my ($name, $symbol) = each %cgi_param_mapping) {
986 if (!exists $params{$name}) {
987 $params{$name} = $input_params{$name};
992 my $use_pathinfo = gitweb_check_feature
('pathinfo');
993 if ($use_pathinfo and defined $params{'project'}) {
994 # try to put as many parameters as possible in PATH_INFO:
997 # - hash_parent or hash_parent_base:/file_parent
998 # - hash or hash_base:/filename
999 # - the snapshot_format as an appropriate suffix
1001 # When the script is the root DirectoryIndex for the domain,
1002 # $href here would be something like http://gitweb.example.com/
1003 # Thus, we strip any trailing / from $href, to spare us double
1004 # slashes in the final URL
1007 # Then add the project name, if present
1008 $href .= "/".esc_url
($params{'project'});
1009 delete $params{'project'};
1011 # since we destructively absorb parameters, we keep this
1012 # boolean that remembers if we're handling a snapshot
1013 my $is_snapshot = $params{'action'} eq 'snapshot';
1015 # Summary just uses the project path URL, any other action is
1017 if (defined $params{'action'}) {
1018 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
1019 delete $params{'action'};
1022 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
1023 # stripping nonexistent or useless pieces
1024 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
1025 || $params{'hash_parent'} || $params{'hash'});
1026 if (defined $params{'hash_base'}) {
1027 if (defined $params{'hash_parent_base'}) {
1028 $href .= esc_url
($params{'hash_parent_base'});
1029 # skip the file_parent if it's the same as the file_name
1030 if (defined $params{'file_parent'}) {
1031 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
1032 delete $params{'file_parent'};
1033 } elsif ($params{'file_parent'} !~ /\.\./) {
1034 $href .= ":/".esc_url
($params{'file_parent'});
1035 delete $params{'file_parent'};
1039 delete $params{'hash_parent'};
1040 delete $params{'hash_parent_base'};
1041 } elsif (defined $params{'hash_parent'}) {
1042 $href .= esc_url
($params{'hash_parent'}). "..";
1043 delete $params{'hash_parent'};
1046 $href .= esc_url
($params{'hash_base'});
1047 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1048 $href .= ":/".esc_url
($params{'file_name'});
1049 delete $params{'file_name'};
1051 delete $params{'hash'};
1052 delete $params{'hash_base'};
1053 } elsif (defined $params{'hash'}) {
1054 $href .= esc_url
($params{'hash'});
1055 delete $params{'hash'};
1058 # If the action was a snapshot, we can absorb the
1059 # snapshot_format parameter too
1061 my $fmt = $params{'snapshot_format'};
1062 # snapshot_format should always be defined when href()
1063 # is called, but just in case some code forgets, we
1064 # fall back to the default
1065 $fmt ||= $snapshot_fmts[0];
1066 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1067 delete $params{'snapshot_format'};
1071 # now encode the parameters explicitly
1073 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1074 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1075 if (defined $params{$name}) {
1076 if (ref($params{$name}) eq "ARRAY") {
1077 foreach my $par (@{$params{$name}}) {
1078 push @result, $symbol . "=" . esc_param
($par);
1081 push @result, $symbol . "=" . esc_param
($params{$name});
1085 $href .= "?" . join(';', @result) if scalar @result;
1091 ## ======================================================================
1092 ## validation, quoting/unquoting and escaping
1094 sub validate_action
{
1095 my $input = shift || return undef;
1096 return undef unless exists $actions{$input};
1100 sub validate_project
{
1101 my $input = shift || return undef;
1102 if (!validate_pathname
($input) ||
1103 !(-d
"$projectroot/$input") ||
1104 !check_export_ok
("$projectroot/$input") ||
1105 ($strict_export && !project_in_list
($input))) {
1112 sub validate_pathname
{
1113 my $input = shift || return undef;
1115 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1116 # at the beginning, at the end, and between slashes.
1117 # also this catches doubled slashes
1118 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1121 # no null characters
1122 if ($input =~ m!\0!) {
1128 sub validate_refname
{
1129 my $input = shift || return undef;
1131 # textual hashes are O.K.
1132 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1135 # it must be correct pathname
1136 $input = validate_pathname
($input)
1138 # restrictions on ref name according to git-check-ref-format
1139 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1145 # decode sequences of octets in utf8 into Perl's internal form,
1146 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1147 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1150 return undef unless defined $str;
1151 if (utf8
::valid
($str)) {
1155 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1159 # quote unsafe chars, but keep the slash, even when it's not
1160 # correct, but quoted slashes look too horrible in bookmarks
1163 return undef unless defined $str;
1164 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1169 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1172 return undef unless defined $str;
1173 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1179 # replace invalid utf8 character with SUBSTITUTION sequence
1184 return undef unless defined $str;
1186 $str = to_utf8
($str);
1187 $str = $cgi->escapeHTML($str);
1188 if ($opts{'-nbsp'}) {
1189 $str =~ s/ / /g;
1191 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1195 # quote control characters and escape filename to HTML
1200 return undef unless defined $str;
1202 $str = to_utf8
($str);
1203 $str = $cgi->escapeHTML($str);
1204 if ($opts{'-nbsp'}) {
1205 $str =~ s/ / /g;
1207 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1211 # Make control characters "printable", using character escape codes (CEC)
1215 my %es = ( # character escape codes, aka escape sequences
1216 "\t" => '\t', # tab (HT)
1217 "\n" => '\n', # line feed (LF)
1218 "\r" => '\r', # carrige return (CR)
1219 "\f" => '\f', # form feed (FF)
1220 "\b" => '\b', # backspace (BS)
1221 "\a" => '\a', # alarm (bell) (BEL)
1222 "\e" => '\e', # escape (ESC)
1223 "\013" => '\v', # vertical tab (VT)
1224 "\000" => '\0', # nul character (NUL)
1226 my $chr = ( (exists $es{$cntrl})
1228 : sprintf('\%2x', ord($cntrl)) );
1229 if ($opts{-nohtml
}) {
1232 return "<span class=\"cntrl\">$chr</span>";
1236 # Alternatively use unicode control pictures codepoints,
1237 # Unicode "printable representation" (PR)
1242 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1243 if ($opts{-nohtml
}) {
1246 return "<span class=\"cntrl\">$chr</span>";
1250 # git may return quoted and escaped filenames
1256 my %es = ( # character escape codes, aka escape sequences
1257 't' => "\t", # tab (HT, TAB)
1258 'n' => "\n", # newline (NL)
1259 'r' => "\r", # return (CR)
1260 'f' => "\f", # form feed (FF)
1261 'b' => "\b", # backspace (BS)
1262 'a' => "\a", # alarm (bell) (BEL)
1263 'e' => "\e", # escape (ESC)
1264 'v' => "\013", # vertical tab (VT)
1267 if ($seq =~ m/^[0-7]{1,3}$/) {
1268 # octal char sequence
1269 return chr(oct($seq));
1270 } elsif (exists $es{$seq}) {
1271 # C escape sequence, aka character escape code
1274 # quoted ordinary character
1278 if ($str =~ m/^"(.*)"$/) {
1281 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1286 # escape tabs (convert tabs to spaces)
1290 while ((my $pos = index($line, "\t")) != -1) {
1291 if (my $count = (8 - ($pos % 8))) {
1292 my $spaces = ' ' x
$count;
1293 $line =~ s/\t/$spaces/;
1300 sub project_in_list
{
1301 my $project = shift;
1302 my @list = git_get_projects_list
();
1303 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1306 ## ----------------------------------------------------------------------
1307 ## HTML aware string manipulation
1309 # Try to chop given string on a word boundary between position
1310 # $len and $len+$add_len. If there is no word boundary there,
1311 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1312 # (marking chopped part) would be longer than given string.
1316 my $add_len = shift || 10;
1317 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1319 # Make sure perl knows it is utf8 encoded so we don't
1320 # cut in the middle of a utf8 multibyte char.
1321 $str = to_utf8
($str);
1323 # allow only $len chars, but don't cut a word if it would fit in $add_len
1324 # if it doesn't fit, cut it if it's still longer than the dots we would add
1325 # remove chopped character entities entirely
1327 # when chopping in the middle, distribute $len into left and right part
1328 # return early if chopping wouldn't make string shorter
1329 if ($where eq 'center') {
1330 return $str if ($len + 5 >= length($str)); # filler is length 5
1333 return $str if ($len + 4 >= length($str)); # filler is length 4
1336 # regexps: ending and beginning with word part up to $add_len
1337 my $endre = qr/.{$len}\w{0,$add_len}/;
1338 my $begre = qr/\w{0,$add_len}.{$len}/;
1340 if ($where eq 'left') {
1341 $str =~ m/^(.*?)($begre)$/;
1342 my ($lead, $body) = ($1, $2);
1343 if (length($lead) > 4) {
1346 return "$lead$body";
1348 } elsif ($where eq 'center') {
1349 $str =~ m/^($endre)(.*)$/;
1350 my ($left, $str) = ($1, $2);
1351 $str =~ m/^(.*?)($begre)$/;
1352 my ($mid, $right) = ($1, $2);
1353 if (length($mid) > 5) {
1356 return "$left$mid$right";
1359 $str =~ m/^($endre)(.*)$/;
1362 if (length($tail) > 4) {
1365 return "$body$tail";
1369 # takes the same arguments as chop_str, but also wraps a <span> around the
1370 # result with a title attribute if it does get chopped. Additionally, the
1371 # string is HTML-escaped.
1372 sub chop_and_escape_str
{
1375 my $chopped = chop_str
(@_);
1376 if ($chopped eq $str) {
1377 return esc_html
($chopped);
1379 $str =~ s/[[:cntrl:]]/?/g;
1380 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1384 ## ----------------------------------------------------------------------
1385 ## functions returning short strings
1387 # CSS class for given age value (in seconds)
1391 if (!defined $age) {
1393 } elsif ($age < 60*60*2) {
1395 } elsif ($age < 60*60*24*2) {
1402 # convert age in seconds to "nn units ago" string
1407 if ($age > 60*60*24*365*2) {
1408 $age_str = (int $age/60/60/24/365);
1409 $age_str .= " years ago";
1410 } elsif ($age > 60*60*24*(365/12)*2) {
1411 $age_str = int $age/60/60/24/(365/12);
1412 $age_str .= " months ago";
1413 } elsif ($age > 60*60*24*7*2) {
1414 $age_str = int $age/60/60/24/7;
1415 $age_str .= " weeks ago";
1416 } elsif ($age > 60*60*24*2) {
1417 $age_str = int $age/60/60/24;
1418 $age_str .= " days ago";
1419 } elsif ($age > 60*60*2) {
1420 $age_str = int $age/60/60;
1421 $age_str .= " hours ago";
1422 } elsif ($age > 60*2) {
1423 $age_str = int $age/60;
1424 $age_str .= " min ago";
1425 } elsif ($age > 2) {
1426 $age_str = int $age;
1427 $age_str .= " sec ago";
1429 $age_str .= " right now";
1435 S_IFINVALID
=> 0030000,
1436 S_IFGITLINK
=> 0160000,
1439 # submodule/subproject, a commit object reference
1443 return (($mode & S_IFMT
) == S_IFGITLINK
)
1446 # convert file mode in octal to symbolic file mode string
1448 my $mode = oct shift;
1450 if (S_ISGITLINK
($mode)) {
1451 return 'm---------';
1452 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1453 return 'drwxr-xr-x';
1454 } elsif (S_ISLNK
($mode)) {
1455 return 'lrwxrwxrwx';
1456 } elsif (S_ISREG
($mode)) {
1457 # git cares only about the executable bit
1458 if ($mode & S_IXUSR
) {
1459 return '-rwxr-xr-x';
1461 return '-rw-r--r--';
1464 return '----------';
1468 # convert file mode in octal to file type string
1472 if ($mode !~ m/^[0-7]+$/) {
1478 if (S_ISGITLINK
($mode)) {
1480 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1482 } elsif (S_ISLNK
($mode)) {
1484 } elsif (S_ISREG
($mode)) {
1491 # convert file mode in octal to file type description string
1492 sub file_type_long
{
1495 if ($mode !~ m/^[0-7]+$/) {
1501 if (S_ISGITLINK
($mode)) {
1503 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1505 } elsif (S_ISLNK
($mode)) {
1507 } elsif (S_ISREG
($mode)) {
1508 if ($mode & S_IXUSR
) {
1509 return "executable";
1519 ## ----------------------------------------------------------------------
1520 ## functions returning short HTML fragments, or transforming HTML fragments
1521 ## which don't belong to other sections
1523 # format line of commit message.
1524 sub format_log_line_html
{
1527 $line = esc_html
($line, -nbsp
=>1);
1528 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1529 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1530 -class => "text"}, $1);
1536 # format marker of refs pointing to given object
1538 # the destination action is chosen based on object type and current context:
1539 # - for annotated tags, we choose the tag view unless it's the current view
1540 # already, in which case we go to shortlog view
1541 # - for other refs, we keep the current view if we're in history, shortlog or
1542 # log view, and select shortlog otherwise
1543 sub format_ref_marker
{
1544 my ($refs, $id) = @_;
1547 if (defined $refs->{$id}) {
1548 foreach my $ref (@{$refs->{$id}}) {
1549 # this code exploits the fact that non-lightweight tags are the
1550 # only indirect objects, and that they are the only objects for which
1551 # we want to use tag instead of shortlog as action
1552 my ($type, $name) = qw();
1553 my $indirect = ($ref =~ s/\^\{\}$//);
1554 # e.g. tags/v2.6.11 or heads/next
1555 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1564 $class .= " indirect" if $indirect;
1566 my $dest_action = "shortlog";
1569 $dest_action = "tag" unless $action eq "tag";
1570 } elsif ($action =~ /^(history|(short)?log)$/) {
1571 $dest_action = $action;
1575 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1578 my $link = $cgi->a({
1580 action
=>$dest_action,
1584 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1590 return ' <span class="refs">'. $markers . '</span>';
1596 # format, perhaps shortened and with markers, title line
1597 sub format_subject_html
{
1598 my ($long, $short, $href, $extra) = @_;
1599 $extra = '' unless defined($extra);
1601 if (length($short) < length($long)) {
1602 $long =~ s/[[:cntrl:]]/?/g;
1603 return $cgi->a({-href
=> $href, -class => "list subject",
1604 -title
=> to_utf8
($long)},
1605 esc_html
($short)) . $extra;
1607 return $cgi->a({-href
=> $href, -class => "list subject"},
1608 esc_html
($long)) . $extra;
1612 # Rather than recomputing the url for an email multiple times, we cache it
1613 # after the first hit. This gives a visible benefit in views where the avatar
1614 # for the same email is used repeatedly (e.g. shortlog).
1615 # The cache is shared by all avatar engines (currently gravatar only), which
1616 # are free to use it as preferred. Since only one avatar engine is used for any
1617 # given page, there's no risk for cache conflicts.
1618 our %avatar_cache = ();
1620 # Compute the picon url for a given email, by using the picon search service over at
1621 # http://www.cs.indiana.edu/picons/search.html
1623 my $email = lc shift;
1624 if (!$avatar_cache{$email}) {
1625 my ($user, $domain) = split('@', $email);
1626 $avatar_cache{$email} =
1627 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1629 "users+domains+unknown/up/single";
1631 return $avatar_cache{$email};
1634 # Compute the gravatar url for a given email, if it's not in the cache already.
1635 # Gravatar stores only the part of the URL before the size, since that's the
1636 # one computationally more expensive. This also allows reuse of the cache for
1637 # different sizes (for this particular engine).
1639 my $email = lc shift;
1641 $avatar_cache{$email} ||=
1642 "http://www.gravatar.com/avatar/" .
1643 Digest
::MD5
::md5_hex
($email) . "?s=";
1644 return $avatar_cache{$email} . $size;
1647 # Insert an avatar for the given $email at the given $size if the feature
1649 sub git_get_avatar
{
1650 my ($email, %opts) = @_;
1651 my $pre_white = ($opts{-pad_before
} ? " " : "");
1652 my $post_white = ($opts{-pad_after
} ? " " : "");
1653 $opts{-size
} ||= 'default';
1654 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1656 if ($git_avatar eq 'gravatar') {
1657 $url = gravatar_url
($email, $size);
1658 } elsif ($git_avatar eq 'picon') {
1659 $url = picon_url
($email);
1661 # Other providers can be added by extending the if chain, defining $url
1662 # as needed. If no variant puts something in $url, we assume avatars
1663 # are completely disabled/unavailable.
1666 "<img width=\"$size\" " .
1667 "class=\"avatar\" " .
1676 sub format_search_author
{
1677 my ($author, $searchtype, $displaytext) = @_;
1678 my $have_search = gitweb_check_feature
('search');
1682 if ($searchtype eq 'author') {
1683 $performed = "authored";
1684 } elsif ($searchtype eq 'committer') {
1685 $performed = "committed";
1688 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1689 searchtext
=>$author,
1690 searchtype
=>$searchtype), class=>"list",
1691 title
=>"Search for commits $performed by $author"},
1695 return $displaytext;
1699 # format the author name of the given commit with the given tag
1700 # the author name is chopped and escaped according to the other
1701 # optional parameters (see chop_str).
1702 sub format_author_html
{
1705 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1706 return "<$tag class=\"author\">" .
1707 format_search_author
($co->{'author_name'}, "author",
1708 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1713 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1714 sub format_git_diff_header_line
{
1716 my $diffinfo = shift;
1717 my ($from, $to) = @_;
1719 if ($diffinfo->{'nparents'}) {
1721 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1722 if ($to->{'href'}) {
1723 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1724 esc_path
($to->{'file'}));
1725 } else { # file was deleted (no href)
1726 $line .= esc_path
($to->{'file'});
1730 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1731 if ($from->{'href'}) {
1732 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1733 'a/' . esc_path
($from->{'file'}));
1734 } else { # file was added (no href)
1735 $line .= 'a/' . esc_path
($from->{'file'});
1738 if ($to->{'href'}) {
1739 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1740 'b/' . esc_path
($to->{'file'}));
1741 } else { # file was deleted
1742 $line .= 'b/' . esc_path
($to->{'file'});
1746 return "<div class=\"diff header\">$line</div>\n";
1749 # format extended diff header line, before patch itself
1750 sub format_extended_diff_header_line
{
1752 my $diffinfo = shift;
1753 my ($from, $to) = @_;
1756 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1757 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1758 esc_path
($from->{'file'}));
1760 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1761 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1762 esc_path
($to->{'file'}));
1764 # match single <mode>
1765 if ($line =~ m/\s(\d{6})$/) {
1766 $line .= '<span class="info"> (' .
1767 file_type_long
($1) .
1771 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1772 # can match only for combined diff
1774 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1775 if ($from->{'href'}[$i]) {
1776 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1778 substr($diffinfo->{'from_id'}[$i],0,7));
1783 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1786 if ($to->{'href'}) {
1787 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1788 substr($diffinfo->{'to_id'},0,7));
1793 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1794 # can match only for ordinary diff
1795 my ($from_link, $to_link);
1796 if ($from->{'href'}) {
1797 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1798 substr($diffinfo->{'from_id'},0,7));
1800 $from_link = '0' x
7;
1802 if ($to->{'href'}) {
1803 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1804 substr($diffinfo->{'to_id'},0,7));
1808 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1809 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1812 return $line . "<br/>\n";
1815 # format from-file/to-file diff header
1816 sub format_diff_from_to_header
{
1817 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1822 #assert($line =~ m/^---/) if DEBUG;
1823 # no extra formatting for "^--- /dev/null"
1824 if (! $diffinfo->{'nparents'}) {
1825 # ordinary (single parent) diff
1826 if ($line =~ m!^--- "?a/!) {
1827 if ($from->{'href'}) {
1829 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1830 esc_path
($from->{'file'}));
1833 esc_path
($from->{'file'});
1836 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1839 # combined diff (merge commit)
1840 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1841 if ($from->{'href'}[$i]) {
1843 $cgi->a({-href
=>href
(action
=>"blobdiff",
1844 hash_parent
=>$diffinfo->{'from_id'}[$i],
1845 hash_parent_base
=>$parents[$i],
1846 file_parent
=>$from->{'file'}[$i],
1847 hash
=>$diffinfo->{'to_id'},
1849 file_name
=>$to->{'file'}),
1851 -title
=>"diff" . ($i+1)},
1854 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1855 esc_path
($from->{'file'}[$i]));
1857 $line = '--- /dev/null';
1859 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1864 #assert($line =~ m/^\+\+\+/) if DEBUG;
1865 # no extra formatting for "^+++ /dev/null"
1866 if ($line =~ m!^\+\+\+ "?b/!) {
1867 if ($to->{'href'}) {
1869 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1870 esc_path
($to->{'file'}));
1873 esc_path
($to->{'file'});
1876 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1881 # create note for patch simplified by combined diff
1882 sub format_diff_cc_simplified
{
1883 my ($diffinfo, @parents) = @_;
1886 $result .= "<div class=\"diff header\">" .
1888 if (!is_deleted
($diffinfo)) {
1889 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1891 hash
=>$diffinfo->{'to_id'},
1892 file_name
=>$diffinfo->{'to_file'}),
1894 esc_path
($diffinfo->{'to_file'}));
1896 $result .= esc_path
($diffinfo->{'to_file'});
1898 $result .= "</div>\n" . # class="diff header"
1899 "<div class=\"diff nodifferences\">" .
1901 "</div>\n"; # class="diff nodifferences"
1906 # format patch (diff) line (not to be used for diff headers)
1907 sub format_diff_line
{
1909 my ($from, $to) = @_;
1910 my $diff_class = "";
1914 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1916 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1917 if ($line =~ m/^\@{3}/) {
1918 $diff_class = " chunk_header";
1919 } elsif ($line =~ m/^\\/) {
1920 $diff_class = " incomplete";
1921 } elsif ($prefix =~ tr/+/+/) {
1922 $diff_class = " add";
1923 } elsif ($prefix =~ tr/-/-/) {
1924 $diff_class = " rem";
1927 # assume ordinary diff
1928 my $char = substr($line, 0, 1);
1930 $diff_class = " add";
1931 } elsif ($char eq '-') {
1932 $diff_class = " rem";
1933 } elsif ($char eq '@') {
1934 $diff_class = " chunk_header";
1935 } elsif ($char eq "\\") {
1936 $diff_class = " incomplete";
1939 $line = untabify
($line);
1940 if ($from && $to && $line =~ m/^\@{2} /) {
1941 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1942 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1944 $from_lines = 0 unless defined $from_lines;
1945 $to_lines = 0 unless defined $to_lines;
1947 if ($from->{'href'}) {
1948 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1949 -class=>"list"}, $from_text);
1951 if ($to->{'href'}) {
1952 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1953 -class=>"list"}, $to_text);
1955 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1956 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1957 return "<div class=\"diff$diff_class\">$line</div>\n";
1958 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1959 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1960 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1962 @from_text = split(' ', $ranges);
1963 for (my $i = 0; $i < @from_text; ++$i) {
1964 ($from_start[$i], $from_nlines[$i]) =
1965 (split(',', substr($from_text[$i], 1)), 0);
1968 $to_text = pop @from_text;
1969 $to_start = pop @from_start;
1970 $to_nlines = pop @from_nlines;
1972 $line = "<span class=\"chunk_info\">$prefix ";
1973 for (my $i = 0; $i < @from_text; ++$i) {
1974 if ($from->{'href'}[$i]) {
1975 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1976 -class=>"list"}, $from_text[$i]);
1978 $line .= $from_text[$i];
1982 if ($to->{'href'}) {
1983 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1984 -class=>"list"}, $to_text);
1988 $line .= " $prefix</span>" .
1989 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1990 return "<div class=\"diff$diff_class\">$line</div>\n";
1992 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1995 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1996 # linked. Pass the hash of the tree/commit to snapshot.
1997 sub format_snapshot_links
{
1999 my $num_fmts = @snapshot_fmts;
2000 if ($num_fmts > 1) {
2001 # A parenthesized list of links bearing format names.
2002 # e.g. "snapshot (_tar.gz_ _zip_)"
2003 return "snapshot (" . join(' ', map
2010 }, $known_snapshot_formats{$_}{'display'})
2011 , @snapshot_fmts) . ")";
2012 } elsif ($num_fmts == 1) {
2013 # A single "snapshot" link whose tooltip bears the format name.
2015 my ($fmt) = @snapshot_fmts;
2021 snapshot_format
=>$fmt
2023 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2025 } else { # $num_fmts == 0
2030 ## ......................................................................
2031 ## functions returning values to be passed, perhaps after some
2032 ## transformation, to other functions; e.g. returning arguments to href()
2034 # returns hash to be passed to href to generate gitweb URL
2035 # in -title key it returns description of link
2037 my $format = shift || 'Atom';
2038 my %res = (action
=> lc($format));
2040 # feed links are possible only for project views
2041 return unless (defined $project);
2042 # some views should link to OPML, or to generic project feed,
2043 # or don't have specific feed yet (so they should use generic)
2044 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2047 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2048 # from tag links; this also makes possible to detect branch links
2049 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2050 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2053 # find log type for feed description (title)
2055 if (defined $file_name) {
2056 $type = "history of $file_name";
2057 $type .= "/" if ($action eq 'tree');
2058 $type .= " on '$branch'" if (defined $branch);
2060 $type = "log of $branch" if (defined $branch);
2063 $res{-title
} = $type;
2064 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2065 $res{'file_name'} = $file_name;
2070 ## ----------------------------------------------------------------------
2071 ## git utility subroutines, invoking git commands
2073 # returns path to the core git executable and the --git-dir parameter as list
2075 $number_of_git_cmds++;
2076 return $GIT, '--git-dir='.$git_dir;
2079 # quote the given arguments for passing them to the shell
2080 # quote_command("command", "arg 1", "arg with ' and ! characters")
2081 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2082 # Try to avoid using this function wherever possible.
2085 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2088 # get HEAD ref of given project as hash
2089 sub git_get_head_hash
{
2090 return git_get_full_hash
(shift, 'HEAD');
2093 sub git_get_full_hash
{
2094 return git_get_hash
(@_);
2097 sub git_get_short_hash
{
2098 return git_get_hash
(@_, '--short=7');
2102 my ($project, $hash, @options) = @_;
2103 my $o_git_dir = $git_dir;
2105 $git_dir = "$projectroot/$project";
2106 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2107 '--verify', '-q', @options, $hash) {
2109 chomp $retval if defined $retval;
2112 if (defined $o_git_dir) {
2113 $git_dir = $o_git_dir;
2118 # get type of given object
2122 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2124 close $fd or return;
2129 # repository configuration
2130 our $config_file = '';
2133 # store multiple values for single key as anonymous array reference
2134 # single values stored directly in the hash, not as [ <value> ]
2135 sub hash_set_multi
{
2136 my ($hash, $key, $value) = @_;
2138 if (!exists $hash->{$key}) {
2139 $hash->{$key} = $value;
2140 } elsif (!ref $hash->{$key}) {
2141 $hash->{$key} = [ $hash->{$key}, $value ];
2143 push @{$hash->{$key}}, $value;
2147 # return hash of git project configuration
2148 # optionally limited to some section, e.g. 'gitweb'
2149 sub git_parse_project_config
{
2150 my $section_regexp = shift;
2155 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2158 while (my $keyval = <$fh>) {
2160 my ($key, $value) = split(/\n/, $keyval, 2);
2162 hash_set_multi
(\
%config, $key, $value)
2163 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2170 # convert config value to boolean: 'true' or 'false'
2171 # no value, number > 0, 'true' and 'yes' values are true
2172 # rest of values are treated as false (never as error)
2173 sub config_to_bool
{
2176 return 1 if !defined $val; # section.key
2178 # strip leading and trailing whitespace
2182 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2183 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2186 # convert config value to simple decimal number
2187 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2188 # to be multiplied by 1024, 1048576, or 1073741824
2192 # strip leading and trailing whitespace
2196 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2198 # unknown unit is treated as 1
2199 return $num * ($unit eq 'g' ? 1073741824 :
2200 $unit eq 'm' ? 1048576 :
2201 $unit eq 'k' ? 1024 : 1);
2206 # convert config value to array reference, if needed
2207 sub config_to_multi
{
2210 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2213 sub git_get_project_config
{
2214 my ($key, $type) = @_;
2217 return unless ($key);
2218 $key =~ s/^gitweb\.//;
2219 return if ($key =~ m/\W/);
2222 if (defined $type) {
2225 unless ($type eq 'bool' || $type eq 'int');
2229 if (!defined $config_file ||
2230 $config_file ne "$git_dir/config") {
2231 %config = git_parse_project_config
('gitweb');
2232 $config_file = "$git_dir/config";
2235 # check if config variable (key) exists
2236 return unless exists $config{"gitweb.$key"};
2239 if (!defined $type) {
2240 return $config{"gitweb.$key"};
2241 } elsif ($type eq 'bool') {
2242 # backward compatibility: 'git config --bool' returns true/false
2243 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2244 } elsif ($type eq 'int') {
2245 return config_to_int
($config{"gitweb.$key"});
2247 return $config{"gitweb.$key"};
2250 # get hash of given path at given ref
2251 sub git_get_hash_by_path
{
2253 my $path = shift || return undef;
2258 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2259 or die_error
(500, "Open git-ls-tree failed");
2261 close $fd or return undef;
2263 if (!defined $line) {
2264 # there is no tree or hash given by $path at $base
2268 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2269 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2270 if (defined $type && $type ne $2) {
2271 # type doesn't match
2277 # get path of entry with given hash at given tree-ish (ref)
2278 # used to get 'from' filename for combined diff (merge commit) for renames
2279 sub git_get_path_by_hash
{
2280 my $base = shift || return;
2281 my $hash = shift || return;
2285 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2287 while (my $line = <$fd>) {
2290 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2291 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2292 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2301 ## ......................................................................
2302 ## git utility functions, directly accessing git repository
2304 sub git_get_project_description
{
2307 $git_dir = "$projectroot/$path";
2308 open my $fd, '<', "$git_dir/description"
2309 or return git_get_project_config
('description');
2312 if (defined $descr) {
2318 sub git_get_project_ctags
{
2322 $git_dir = "$projectroot/$path";
2323 opendir my $dh, "$git_dir/ctags"
2325 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2326 open my $ct, '<', $_ or next;
2330 my $ctag = $_; $ctag =~ s
#.*/##;
2331 $ctags->{$ctag} = $val;
2337 sub git_populate_project_tagcloud
{
2340 # First, merge different-cased tags; tags vote on casing
2342 foreach (keys %$ctags) {
2343 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2344 if (not $ctags_lc{lc $_}->{topcount
}
2345 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2346 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2347 $ctags_lc{lc $_}->{topname
} = $_;
2352 if (eval { require HTML
::TagCloud
; 1; }) {
2353 $cloud = HTML
::TagCloud-
>new;
2354 foreach (sort keys %ctags_lc) {
2355 # Pad the title with spaces so that the cloud looks
2357 my $title = $ctags_lc{$_}->{topname
};
2358 $title =~ s/ / /g;
2359 $title =~ s/^/ /g;
2360 $title =~ s/$/ /g;
2361 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2364 $cloud = \
%ctags_lc;
2369 sub git_show_project_tagcloud
{
2370 my ($cloud, $count) = @_;
2371 print STDERR
ref($cloud)."..\n";
2372 if (ref $cloud eq 'HTML::TagCloud') {
2373 return $cloud->html_and_css($count);
2375 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2376 return '<p align="center">' . join (', ', map {
2377 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2378 } splice(@tags, 0, $count)) . '</p>';
2382 sub git_get_project_url_list
{
2385 $git_dir = "$projectroot/$path";
2386 open my $fd, '<', "$git_dir/cloneurl"
2387 or return wantarray ?
2388 @{ config_to_multi
(git_get_project_config
('url')) } :
2389 config_to_multi
(git_get_project_config
('url'));
2390 my @git_project_url_list = map { chomp; $_ } <$fd>;
2393 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2396 sub git_get_projects_list
{
2401 $filter =~ s/\.git$//;
2403 my $check_forks = gitweb_check_feature
('forks');
2405 if (-d
$projects_list) {
2406 # search in directory
2407 my $dir = $projects_list . ($filter ? "/$filter" : '');
2408 # remove the trailing "/"
2410 my $pfxlen = length("$dir");
2411 my $pfxdepth = ($dir =~ tr!/!!);
2414 follow_fast
=> 1, # follow symbolic links
2415 follow_skip
=> 2, # ignore duplicates
2416 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2418 # skip project-list toplevel, if we get it.
2419 return if (m!^[/.]$!);
2420 # only directories can be git repositories
2421 return unless (-d
$_);
2422 # don't traverse too deep (Find is super slow on os x)
2423 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2424 $File::Find
::prune
= 1;
2428 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2429 # we check related file in $projectroot
2430 my $path = ($filter ? "$filter/" : '') . $subdir;
2431 if (check_export_ok
("$projectroot/$path")) {
2432 push @list, { path
=> $path };
2433 $File::Find
::prune
= 1;
2438 } elsif (-f
$projects_list) {
2439 # read from file(url-encoded):
2440 # 'git%2Fgit.git Linus+Torvalds'
2441 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2442 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2444 open my $fd, '<', $projects_list or return;
2446 while (my $line = <$fd>) {
2448 my ($path, $owner) = split ' ', $line;
2449 $path = unescape
($path);
2450 $owner = unescape
($owner);
2451 if (!defined $path) {
2454 if ($filter ne '') {
2455 # looking for forks;
2456 my $pfx = substr($path, 0, length($filter));
2457 if ($pfx ne $filter) {
2460 my $sfx = substr($path, length($filter));
2461 if ($sfx !~ /^\/.*\
.git
$/) {
2464 } elsif ($check_forks) {
2466 foreach my $filter (keys %paths) {
2467 # looking for forks;
2468 my $pfx = substr($path, 0, length($filter));
2469 if ($pfx ne $filter) {
2472 my $sfx = substr($path, length($filter));
2473 if ($sfx !~ /^\/.*\
.git
$/) {
2476 # is a fork, don't include it in
2481 if (check_export_ok
("$projectroot/$path")) {
2484 owner
=> to_utf8
($owner),
2487 (my $forks_path = $path) =~ s/\.git$//;
2488 $paths{$forks_path}++;
2496 our $gitweb_project_owner = undef;
2497 sub git_get_project_list_from_file
{
2499 return if (defined $gitweb_project_owner);
2501 $gitweb_project_owner = {};
2502 # read from file (url-encoded):
2503 # 'git%2Fgit.git Linus+Torvalds'
2504 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2505 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2506 if (-f
$projects_list) {
2507 open(my $fd, '<', $projects_list);
2508 while (my $line = <$fd>) {
2510 my ($pr, $ow) = split ' ', $line;
2511 $pr = unescape
($pr);
2512 $ow = unescape
($ow);
2513 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2519 sub git_get_project_owner
{
2520 my $project = shift;
2523 return undef unless $project;
2524 $git_dir = "$projectroot/$project";
2526 if (!defined $gitweb_project_owner) {
2527 git_get_project_list_from_file
();
2530 if (exists $gitweb_project_owner->{$project}) {
2531 $owner = $gitweb_project_owner->{$project};
2533 if (!defined $owner){
2534 $owner = git_get_project_config
('owner');
2536 if (!defined $owner) {
2537 $owner = get_file_owner
("$git_dir");
2543 sub git_get_last_activity
{
2547 $git_dir = "$projectroot/$path";
2548 open($fd, "-|", git_cmd
(), 'for-each-ref',
2549 '--format=%(committer)',
2550 '--sort=-committerdate',
2552 'refs/heads') or return;
2553 my $most_recent = <$fd>;
2554 close $fd or return;
2555 if (defined $most_recent &&
2556 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2558 my $age = time - $timestamp;
2559 return ($age, age_string
($age));
2561 return (undef, undef);
2564 sub git_get_references
{
2565 my $type = shift || "";
2567 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2568 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2569 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2570 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2573 while (my $line = <$fd>) {
2575 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2576 if (defined $refs{$1}) {
2577 push @{$refs{$1}}, $2;
2583 close $fd or return;
2587 sub git_get_rev_name_tags
{
2588 my $hash = shift || return undef;
2590 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2592 my $name_rev = <$fd>;
2595 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2598 # catches also '$hash undefined' output
2603 ## ----------------------------------------------------------------------
2604 ## parse to hash functions
2608 my $tz = shift || "-0000";
2611 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2612 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2613 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2614 $date{'hour'} = $hour;
2615 $date{'minute'} = $min;
2616 $date{'mday'} = $mday;
2617 $date{'day'} = $days[$wday];
2618 $date{'month'} = $months[$mon];
2619 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2620 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2621 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2622 $mday, $months[$mon], $hour ,$min;
2623 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2624 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2626 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2627 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2628 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2629 $date{'hour_local'} = $hour;
2630 $date{'minute_local'} = $min;
2631 $date{'tz_local'} = $tz;
2632 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2633 1900+$year, $mon+1, $mday,
2634 $hour, $min, $sec, $tz);
2643 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2644 $tag{'id'} = $tag_id;
2645 while (my $line = <$fd>) {
2647 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2648 $tag{'object'} = $1;
2649 } elsif ($line =~ m/^type (.+)$/) {
2651 } elsif ($line =~ m/^tag (.+)$/) {
2653 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2654 $tag{'author'} = $1;
2655 $tag{'author_epoch'} = $2;
2656 $tag{'author_tz'} = $3;
2657 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2658 $tag{'author_name'} = $1;
2659 $tag{'author_email'} = $2;
2661 $tag{'author_name'} = $tag{'author'};
2663 } elsif ($line =~ m/--BEGIN/) {
2664 push @comment, $line;
2666 } elsif ($line eq "") {
2670 push @comment, <$fd>;
2671 $tag{'comment'} = \
@comment;
2672 close $fd or return;
2673 if (!defined $tag{'name'}) {
2679 sub parse_commit_text
{
2680 my ($commit_text, $withparents) = @_;
2681 my @commit_lines = split '\n', $commit_text;
2684 pop @commit_lines; # Remove '\0'
2686 if (! @commit_lines) {
2690 my $header = shift @commit_lines;
2691 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2694 ($co{'id'}, my @parents) = split ' ', $header;
2695 while (my $line = shift @commit_lines) {
2696 last if $line eq "\n";
2697 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2699 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2701 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2702 $co{'author'} = to_utf8
($1);
2703 $co{'author_epoch'} = $2;
2704 $co{'author_tz'} = $3;
2705 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2706 $co{'author_name'} = $1;
2707 $co{'author_email'} = $2;
2709 $co{'author_name'} = $co{'author'};
2711 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2712 $co{'committer'} = to_utf8
($1);
2713 $co{'committer_epoch'} = $2;
2714 $co{'committer_tz'} = $3;
2715 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2716 $co{'committer_name'} = $1;
2717 $co{'committer_email'} = $2;
2719 $co{'committer_name'} = $co{'committer'};
2723 if (!defined $co{'tree'}) {
2726 $co{'parents'} = \
@parents;
2727 $co{'parent'} = $parents[0];
2729 foreach my $title (@commit_lines) {
2732 $co{'title'} = chop_str
($title, 80, 5);
2733 # remove leading stuff of merges to make the interesting part visible
2734 if (length($title) > 50) {
2735 $title =~ s/^Automatic //;
2736 $title =~ s/^merge (of|with) /Merge ... /i;
2737 if (length($title) > 50) {
2738 $title =~ s/(http|rsync):\/\///;
2740 if (length($title) > 50) {
2741 $title =~ s/(master|www|rsync)\.//;
2743 if (length($title) > 50) {
2744 $title =~ s/kernel.org:?//;
2746 if (length($title) > 50) {
2747 $title =~ s/\/pub\/scm//;
2750 $co{'title_short'} = chop_str
($title, 50, 5);
2754 if (! defined $co{'title'} || $co{'title'} eq "") {
2755 $co{'title'} = $co{'title_short'} = '(no commit message)';
2757 # remove added spaces
2758 foreach my $line (@commit_lines) {
2761 $co{'comment'} = \
@commit_lines;
2763 my $age = time - $co{'committer_epoch'};
2765 $co{'age_string'} = age_string
($age);
2766 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2767 if ($age > 60*60*24*7*2) {
2768 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2769 $co{'age_string_age'} = $co{'age_string'};
2771 $co{'age_string_date'} = $co{'age_string'};
2772 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2778 my ($commit_id) = @_;
2783 open my $fd, "-|", git_cmd
(), "rev-list",
2789 or die_error
(500, "Open git-rev-list failed");
2790 %co = parse_commit_text
(<$fd>, 1);
2797 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2805 open my $fd, "-|", git_cmd
(), "rev-list",
2808 ("--max-count=" . $maxcount),
2809 ("--skip=" . $skip),
2813 ($filename ? ($filename) : ())
2814 or die_error
(500, "Open git-rev-list failed");
2815 while (my $line = <$fd>) {
2816 my %co = parse_commit_text
($line);
2821 return wantarray ? @cos : \
@cos;
2824 # parse line of git-diff-tree "raw" output
2825 sub parse_difftree_raw_line
{
2829 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2830 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2831 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2832 $res{'from_mode'} = $1;
2833 $res{'to_mode'} = $2;
2834 $res{'from_id'} = $3;
2836 $res{'status'} = $5;
2837 $res{'similarity'} = $6;
2838 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2839 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2841 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2844 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2845 # combined diff (for merge commit)
2846 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2847 $res{'nparents'} = length($1);
2848 $res{'from_mode'} = [ split(' ', $2) ];
2849 $res{'to_mode'} = pop @{$res{'from_mode'}};
2850 $res{'from_id'} = [ split(' ', $3) ];
2851 $res{'to_id'} = pop @{$res{'from_id'}};
2852 $res{'status'} = [ split('', $4) ];
2853 $res{'to_file'} = unquote
($5);
2855 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2856 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2857 $res{'commit'} = $1;
2860 return wantarray ? %res : \
%res;
2863 # wrapper: return parsed line of git-diff-tree "raw" output
2864 # (the argument might be raw line, or parsed info)
2865 sub parsed_difftree_line
{
2866 my $line_or_ref = shift;
2868 if (ref($line_or_ref) eq "HASH") {
2869 # pre-parsed (or generated by hand)
2870 return $line_or_ref;
2872 return parse_difftree_raw_line
($line_or_ref);
2876 # parse line of git-ls-tree output
2877 sub parse_ls_tree_line
{
2883 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2884 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2893 $res{'name'} = unquote
($5);
2896 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2897 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2905 $res{'name'} = unquote
($4);
2909 return wantarray ? %res : \
%res;
2912 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2913 sub parse_from_to_diffinfo
{
2914 my ($diffinfo, $from, $to, @parents) = @_;
2916 if ($diffinfo->{'nparents'}) {
2918 $from->{'file'} = [];
2919 $from->{'href'} = [];
2920 fill_from_file_info
($diffinfo, @parents)
2921 unless exists $diffinfo->{'from_file'};
2922 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2923 $from->{'file'}[$i] =
2924 defined $diffinfo->{'from_file'}[$i] ?
2925 $diffinfo->{'from_file'}[$i] :
2926 $diffinfo->{'to_file'};
2927 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2928 $from->{'href'}[$i] = href
(action
=>"blob",
2929 hash_base
=>$parents[$i],
2930 hash
=>$diffinfo->{'from_id'}[$i],
2931 file_name
=>$from->{'file'}[$i]);
2933 $from->{'href'}[$i] = undef;
2937 # ordinary (not combined) diff
2938 $from->{'file'} = $diffinfo->{'from_file'};
2939 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2940 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2941 hash
=>$diffinfo->{'from_id'},
2942 file_name
=>$from->{'file'});
2944 delete $from->{'href'};
2948 $to->{'file'} = $diffinfo->{'to_file'};
2949 if (!is_deleted
($diffinfo)) { # file exists in result
2950 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2951 hash
=>$diffinfo->{'to_id'},
2952 file_name
=>$to->{'file'});
2954 delete $to->{'href'};
2958 ## ......................................................................
2959 ## parse to array of hashes functions
2961 sub git_get_heads_list
{
2965 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2966 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2967 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2970 while (my $line = <$fd>) {
2974 my ($refinfo, $committerinfo) = split(/\0/, $line);
2975 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2976 my ($committer, $epoch, $tz) =
2977 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2978 $ref_item{'fullname'} = $name;
2979 $name =~ s!^refs/heads/!!;
2981 $ref_item{'name'} = $name;
2982 $ref_item{'id'} = $hash;
2983 $ref_item{'title'} = $title || '(no commit message)';
2984 $ref_item{'epoch'} = $epoch;
2986 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2988 $ref_item{'age'} = "unknown";
2991 push @headslist, \
%ref_item;
2995 return wantarray ? @headslist : \
@headslist;
2998 sub git_get_tags_list
{
3002 open my $fd, '-|', git_cmd
(), 'for-each-ref',
3003 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
3004 '--format=%(objectname) %(objecttype) %(refname) '.
3005 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3008 while (my $line = <$fd>) {
3012 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3013 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3014 my ($creator, $epoch, $tz) =
3015 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3016 $ref_item{'fullname'} = $name;
3017 $name =~ s!^refs/tags/!!;
3019 $ref_item{'type'} = $type;
3020 $ref_item{'id'} = $id;
3021 $ref_item{'name'} = $name;
3022 if ($type eq "tag") {
3023 $ref_item{'subject'} = $title;
3024 $ref_item{'reftype'} = $reftype;
3025 $ref_item{'refid'} = $refid;
3027 $ref_item{'reftype'} = $type;
3028 $ref_item{'refid'} = $id;
3031 if ($type eq "tag" || $type eq "commit") {
3032 $ref_item{'epoch'} = $epoch;
3034 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3036 $ref_item{'age'} = "unknown";
3040 push @tagslist, \
%ref_item;
3044 return wantarray ? @tagslist : \
@tagslist;
3047 ## ----------------------------------------------------------------------
3048 ## filesystem-related functions
3050 sub get_file_owner
{
3053 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3054 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3055 if (!defined $gcos) {
3059 $owner =~ s/[,;].*$//;
3060 return to_utf8
($owner);
3063 # assume that file exists
3065 my $filename = shift;
3067 open my $fd, '<', $filename;
3068 print map { to_utf8
($_) } <$fd>;
3072 ## ......................................................................
3073 ## mimetype related functions
3075 sub mimetype_guess_file
{
3076 my $filename = shift;
3077 my $mimemap = shift;
3078 -r
$mimemap or return undef;
3081 open(my $mh, '<', $mimemap) or return undef;
3083 next if m/^#/; # skip comments
3084 my ($mimetype, $exts) = split(/\t+/);
3085 if (defined $exts) {
3086 my @exts = split(/\s+/, $exts);
3087 foreach my $ext (@exts) {
3088 $mimemap{$ext} = $mimetype;
3094 $filename =~ /\.([^.]*)$/;
3095 return $mimemap{$1};
3098 sub mimetype_guess
{
3099 my $filename = shift;
3101 $filename =~ /\./ or return undef;
3103 if ($mimetypes_file) {
3104 my $file = $mimetypes_file;
3105 if ($file !~ m!^/!) { # if it is relative path
3106 # it is relative to project
3107 $file = "$projectroot/$project/$file";
3109 $mime = mimetype_guess_file
($filename, $file);
3111 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3117 my $filename = shift;
3120 my $mime = mimetype_guess
($filename);
3121 $mime and return $mime;
3125 return $default_blob_plain_mimetype unless $fd;
3128 return 'text/plain';
3129 } elsif (! $filename) {
3130 return 'application/octet-stream';
3131 } elsif ($filename =~ m/\.png$/i) {
3133 } elsif ($filename =~ m/\.gif$/i) {
3135 } elsif ($filename =~ m/\.jpe?g$/i) {
3136 return 'image/jpeg';
3138 return 'application/octet-stream';
3142 sub blob_contenttype
{
3143 my ($fd, $file_name, $type) = @_;
3145 $type ||= blob_mimetype
($fd, $file_name);
3146 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3147 $type .= "; charset=$default_text_plain_charset";
3153 ## ======================================================================
3154 ## functions printing HTML: header, footer, error page
3156 sub git_header_html
{
3157 my $status = shift || "200 OK";
3158 my $expires = shift;
3160 my $title = "$site_name";
3161 if (defined $project) {
3162 $title .= " - " . to_utf8
($project);
3163 if (defined $action) {
3164 $title .= "/$action";
3165 if (defined $file_name) {
3166 $title .= " - " . esc_path
($file_name);
3167 if ($action eq "tree" && $file_name !~ m
|/$|) {
3174 # require explicit support from the UA if we are to send the page as
3175 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3176 # we have to do this because MSIE sometimes globs '*/*', pretending to
3177 # support xhtml+xml but choking when it gets what it asked for.
3178 if (defined $cgi->http('HTTP_ACCEPT') &&
3179 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3180 $cgi->Accept('application/xhtml+xml') != 0) {
3181 $content_type = 'application/xhtml+xml';
3183 $content_type = 'text/html';
3185 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3186 -status
=> $status, -expires
=> $expires);
3187 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3189 <?xml version="1.0" encoding="utf-8"?>
3190 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3191 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3192 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3193 <!-- git core binaries version $git_version -->
3195 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3196 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3197 <meta name="robots" content="index, nofollow"/>
3198 <title>$title</title>
3200 # the stylesheet, favicon etc urls won't work correctly with path_info
3201 # unless we set the appropriate base URL
3202 if ($ENV{'PATH_INFO'}) {
3203 print "<base href=\"".esc_url
($base_url)."\" />\n";
3205 # print out each stylesheet that exist, providing backwards capability
3206 # for those people who defined $stylesheet in a config file
3207 if (defined $stylesheet) {
3208 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3210 foreach my $stylesheet (@stylesheets) {
3211 next unless $stylesheet;
3212 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3215 if (defined $project) {
3216 my %href_params = get_feed_info
();
3217 if (!exists $href_params{'-title'}) {
3218 $href_params{'-title'} = 'log';
3221 foreach my $format qw(RSS Atom) {
3222 my $type = lc($format);
3224 '-rel' => 'alternate',
3225 '-title' => "$project - $href_params{'-title'} - $format feed",
3226 '-type' => "application/$type+xml"
3229 $href_params{'action'} = $type;
3230 $link_attr{'-href'} = href
(%href_params);
3232 "rel=\"$link_attr{'-rel'}\" ".
3233 "title=\"$link_attr{'-title'}\" ".
3234 "href=\"$link_attr{'-href'}\" ".
3235 "type=\"$link_attr{'-type'}\" ".
3238 $href_params{'extra_options'} = '--no-merges';
3239 $link_attr{'-href'} = href
(%href_params);
3240 $link_attr{'-title'} .= ' (no merges)';
3242 "rel=\"$link_attr{'-rel'}\" ".
3243 "title=\"$link_attr{'-title'}\" ".
3244 "href=\"$link_attr{'-href'}\" ".
3245 "type=\"$link_attr{'-type'}\" ".
3250 printf('<link rel="alternate" title="%s projects list" '.
3251 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3252 $site_name, href
(project
=>undef, action
=>"project_index"));
3253 printf('<link rel="alternate" title="%s projects feeds" '.
3254 'href="%s" type="text/x-opml" />'."\n",
3255 $site_name, href
(project
=>undef, action
=>"opml"));
3257 if (defined $favicon) {
3258 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3264 if (defined $site_header && -f
$site_header) {
3265 insert_file
($site_header);
3268 print "<div class=\"page_header\">\n" .
3269 $cgi->a({-href
=> esc_url
($logo_url),
3270 -title
=> $logo_label},
3271 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3272 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3273 if (defined $project) {
3274 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3275 if (defined $action) {
3282 my $have_search = gitweb_check_feature
('search');
3283 if (defined $project && $have_search) {
3284 if (!defined $searchtext) {
3288 if (defined $hash_base) {
3289 $search_hash = $hash_base;
3290 } elsif (defined $hash) {
3291 $search_hash = $hash;
3293 $search_hash = "HEAD";
3295 my $action = $my_uri;
3296 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3297 if ($use_pathinfo) {
3298 $action .= "/".esc_url
($project);
3300 print $cgi->startform(-method => "get", -action
=> $action) .
3301 "<div class=\"search\">\n" .
3303 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3304 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3305 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3306 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3307 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3308 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3310 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3311 "<span title=\"Extended regular expression\">" .
3312 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3313 -checked
=> $search_use_regexp) .
3316 $cgi->end_form() . "\n";
3320 sub git_footer_html
{
3321 my $feed_class = 'rss_logo';
3323 print "<div class=\"page_footer\">\n";
3324 if (defined $project) {
3325 my $descr = git_get_project_description
($project);
3326 if (defined $descr) {
3327 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3330 my %href_params = get_feed_info
();
3331 if (!%href_params) {
3332 $feed_class .= ' generic';
3334 $href_params{'-title'} ||= 'log';
3336 foreach my $format qw(RSS Atom) {
3337 $href_params{'action'} = lc($format);
3338 print $cgi->a({-href
=> href
(%href_params),
3339 -title
=> "$href_params{'-title'} $format feed",
3340 -class => $feed_class}, $format)."\n";
3344 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3345 -class => $feed_class}, "OPML") . " ";
3346 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3347 -class => $feed_class}, "TXT") . "\n";
3349 print "</div>\n"; # class="page_footer"
3351 if (defined $t0 && gitweb_check_feature
('timed')) {
3352 print "<div id=\"generating_info\">\n";
3353 print 'This page took '.
3354 '<span id="generating_time" class="time_span">'.
3355 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3358 '<span id="generating_cmd">'.
3359 $number_of_git_cmds.
3360 '</span> git commands '.
3362 print "</div>\n"; # class="page_footer"
3365 if (defined $site_footer && -f
$site_footer) {
3366 insert_file
($site_footer);
3369 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3370 if (defined $action &&
3371 $action eq 'blame_incremental') {
3372 print qq
!<script type
="text/javascript">\n!.
3373 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3374 qq
! "!. href() .qq!");\n!.
3376 } elsif (gitweb_check_feature
('javascript-actions')) {
3377 print qq
!<script type
="text/javascript">\n!.
3378 qq
!window
.onload
= fixLinks
;\n!.
3386 # die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
3387 # Example: die_error(404, 'Hash not found')
3388 # By convention, use the following status codes (as defined in RFC 2616):
3389 # 400: Invalid or missing CGI parameters, or
3390 # requested object exists but has wrong type.
3391 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3392 # this server or project.
3393 # 404: Requested object/revision/project doesn't exist.
3394 # 500: The server isn't configured properly, or
3395 # an internal error occurred (e.g. failed assertions caused by bugs), or
3396 # an unknown error occurred (e.g. the git binary died unexpectedly).
3397 # 503: The server is currently unavailable (because it is overloaded,
3398 # or down for maintenance). Generally, this is a temporary state.
3400 my $status = shift || 500;
3401 my $error = esc_html
(shift) || "Internal Server Error";
3404 my %http_responses = (
3405 400 => '400 Bad Request',
3406 403 => '403 Forbidden',
3407 404 => '404 Not Found',
3408 500 => '500 Internal Server Error',
3409 503 => '503 Service Unavailable',
3411 git_header_html
($http_responses{$status});
3413 <div class="page_body">
3418 if (defined $extra) {
3428 ## ----------------------------------------------------------------------
3429 ## functions printing or outputting HTML: navigation
3431 sub git_print_page_nav
{
3432 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3433 $extra = '' if !defined $extra; # pager or formats
3435 my @navs = qw(summary shortlog log commit commitdiff tree);
3437 @navs = grep { $_ ne $suppress } @navs;
3440 my %arg = map { $_ => {action
=>$_} } @navs;
3441 if (defined $head) {
3442 for (qw(commit commitdiff)) {
3443 $arg{$_}{'hash'} = $head;
3445 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3446 for (qw(shortlog log)) {
3447 $arg{$_}{'hash'} = $head;
3452 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3453 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3455 my @actions = gitweb_get_feature
('actions');
3458 'n' => $project, # project name
3459 'f' => $git_dir, # project path within filesystem
3460 'h' => $treehead || '', # current hash ('h' parameter)
3461 'b' => $treebase || '', # hash base ('hb' parameter)
3464 my ($label, $link, $pos) = splice(@actions,0,3);
3466 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3468 $link =~ s/%([%nfhb])/$repl{$1}/g;
3469 $arg{$label}{'_href'} = $link;
3472 print "<div class=\"page_nav\">\n" .
3474 map { $_ eq $current ?
3475 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3477 print "<br/>\n$extra<br/>\n" .
3481 sub format_paging_nav
{
3482 my ($action, $page, $has_next_link) = @_;
3488 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3490 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3491 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3493 $paging_nav .= "first ⋅ prev";
3496 if ($has_next_link) {
3497 $paging_nav .= " ⋅ " .
3498 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3499 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3501 $paging_nav .= " ⋅ next";
3507 ## ......................................................................
3508 ## functions printing or outputting HTML: div
3510 sub git_print_header_div
{
3511 my ($action, $title, $hash, $hash_base) = @_;
3514 $args{'action'} = $action;
3515 $args{'hash'} = $hash if $hash;
3516 $args{'hash_base'} = $hash_base if $hash_base;
3518 print "<div class=\"header\">\n" .
3519 $cgi->a({-href
=> href
(%args), -class => "title"},
3520 $title ? $title : $action) .
3524 sub print_local_time
{
3525 print format_local_time
(@_);
3528 sub format_local_time
{
3531 if ($date{'hour_local'} < 6) {
3532 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3533 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3535 $localtime .= sprintf(" (%02d:%02d %s)",
3536 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3542 # Outputs the author name and date in long form
3543 sub git_print_authorship
{
3546 my $tag = $opts{-tag
} || 'div';
3547 my $author = $co->{'author_name'};
3549 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3550 print "<$tag class=\"author_date\">" .
3551 format_search_author
($author, "author", esc_html
($author)) .
3553 print_local_time
(%ad) if ($opts{-localtime});
3554 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3558 # Outputs table rows containing the full author or committer information,
3559 # in the format expected for 'commit' view (& similia).
3560 # Parameters are a commit hash reference, followed by the list of people
3561 # to output information for. If the list is empty it defalts to both
3562 # author and committer.
3563 sub git_print_authorship_rows
{
3565 # too bad we can't use @people = @_ || ('author', 'committer')
3567 @people = ('author', 'committer') unless @people;
3568 foreach my $who (@people) {
3569 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3570 print "<tr><td>$who</td><td>" .
3571 format_search_author
($co->{"${who}_name"}, $who,
3572 esc_html
($co->{"${who}_name"})) . " " .
3573 format_search_author
($co->{"${who}_email"}, $who,
3574 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3575 "</td><td rowspan=\"2\">" .
3576 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3579 "<td></td><td> $wd{'rfc2822'}";
3580 print_local_time
(%wd);
3586 sub git_print_page_path
{
3592 print "<div class=\"page_path\">";
3593 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3594 -title
=> 'tree root'}, to_utf8
("[$project]"));
3596 if (defined $name) {
3597 my @dirname = split '/', $name;
3598 my $basename = pop @dirname;
3601 foreach my $dir (@dirname) {
3602 $fullname .= ($fullname ? '/' : '') . $dir;
3603 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3605 -title
=> $fullname}, esc_path
($dir));
3608 if (defined $type && $type eq 'blob') {
3609 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3611 -title
=> $name}, esc_path
($basename));
3612 } elsif (defined $type && $type eq 'tree') {
3613 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3615 -title
=> $name}, esc_path
($basename));
3618 print esc_path
($basename);
3621 print "<br/></div>\n";
3628 if ($opts{'-remove_title'}) {
3629 # remove title, i.e. first line of log
3632 # remove leading empty lines
3633 while (defined $log->[0] && $log->[0] eq "") {
3640 foreach my $line (@$log) {
3641 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3644 if (! $opts{'-remove_signoff'}) {
3645 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3648 # remove signoff lines
3655 # print only one empty line
3656 # do not print empty line after signoff
3658 next if ($empty || $signoff);
3664 print format_log_line_html
($line) . "<br/>\n";
3667 if ($opts{'-final_empty_line'}) {
3668 # end with single empty line
3669 print "<br/>\n" unless $empty;
3673 # return link target (what link points to)
3674 sub git_get_link_target
{
3679 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3683 $link_target = <$fd>;
3688 return $link_target;
3691 # given link target, and the directory (basedir) the link is in,
3692 # return target of link relative to top directory (top tree);
3693 # return undef if it is not possible (including absolute links).
3694 sub normalize_link_target
{
3695 my ($link_target, $basedir) = @_;
3697 # absolute symlinks (beginning with '/') cannot be normalized
3698 return if (substr($link_target, 0, 1) eq '/');
3700 # normalize link target to path from top (root) tree (dir)
3703 $path = $basedir . '/' . $link_target;
3705 # we are in top (root) tree (dir)
3706 $path = $link_target;
3709 # remove //, /./, and /../
3711 foreach my $part (split('/', $path)) {
3712 # discard '.' and ''
3713 next if (!$part || $part eq '.');
3715 if ($part eq '..') {
3719 # link leads outside repository (outside top dir)
3723 push @path_parts, $part;
3726 $path = join('/', @path_parts);
3731 # print tree entry (row of git_tree), but without encompassing <tr> element
3732 sub git_print_tree_entry
{
3733 my ($t, $basedir, $hash_base, $have_blame) = @_;
3736 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3738 # The format of a table row is: mode list link. Where mode is
3739 # the mode of the entry, list is the name of the entry, an href,
3740 # and link is the action links of the entry.
3742 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3743 if (exists $t->{'size'}) {
3744 print "<td class=\"size\">$t->{'size'}</td>\n";
3746 if ($t->{'type'} eq "blob") {
3747 print "<td class=\"list\">" .
3748 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3749 file_name
=>"$basedir$t->{'name'}", %base_key),
3750 -class => "list"}, esc_path
($t->{'name'}));
3751 if (S_ISLNK
(oct $t->{'mode'})) {
3752 my $link_target = git_get_link_target
($t->{'hash'});
3754 my $norm_target = normalize_link_target
($link_target, $basedir);
3755 if (defined $norm_target) {
3757 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3758 file_name
=>$norm_target),
3759 -title
=> $norm_target}, esc_path
($link_target));
3761 print " -> " . esc_path
($link_target);
3766 print "<td class=\"link\">";
3767 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3768 file_name
=>"$basedir$t->{'name'}", %base_key)},
3772 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3773 file_name
=>"$basedir$t->{'name'}", %base_key)},
3776 if (defined $hash_base) {
3778 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3779 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3783 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3784 file_name
=>"$basedir$t->{'name'}")},
3788 } elsif ($t->{'type'} eq "tree") {
3789 print "<td class=\"list\">";
3790 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3791 file_name
=>"$basedir$t->{'name'}",
3793 esc_path
($t->{'name'}));
3795 print "<td class=\"link\">";
3796 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3797 file_name
=>"$basedir$t->{'name'}",
3800 if (defined $hash_base) {
3802 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3803 file_name
=>"$basedir$t->{'name'}")},
3808 # unknown object: we can only present history for it
3809 # (this includes 'commit' object, i.e. submodule support)
3810 print "<td class=\"list\">" .
3811 esc_path
($t->{'name'}) .
3813 print "<td class=\"link\">";
3814 if (defined $hash_base) {
3815 print $cgi->a({-href
=> href
(action
=>"history",
3816 hash_base
=>$hash_base,
3817 file_name
=>"$basedir$t->{'name'}")},
3824 ## ......................................................................
3825 ## functions printing large fragments of HTML
3827 # get pre-image filenames for merge (combined) diff
3828 sub fill_from_file_info
{
3829 my ($diff, @parents) = @_;
3831 $diff->{'from_file'} = [ ];
3832 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3833 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3834 if ($diff->{'status'}[$i] eq 'R' ||
3835 $diff->{'status'}[$i] eq 'C') {
3836 $diff->{'from_file'}[$i] =
3837 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3844 # is current raw difftree line of file deletion
3846 my $diffinfo = shift;
3848 return $diffinfo->{'to_id'} eq ('0' x
40);
3851 # does patch correspond to [previous] difftree raw line
3852 # $diffinfo - hashref of parsed raw diff format
3853 # $patchinfo - hashref of parsed patch diff format
3854 # (the same keys as in $diffinfo)
3855 sub is_patch_split
{
3856 my ($diffinfo, $patchinfo) = @_;
3858 return defined $diffinfo && defined $patchinfo
3859 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3863 sub git_difftree_body
{
3864 my ($difftree, $hash, @parents) = @_;
3865 my ($parent) = $parents[0];
3866 my $have_blame = gitweb_check_feature
('blame');
3867 print "<div class=\"list_head\">\n";
3868 if ($#{$difftree} > 10) {
3869 print(($#{$difftree} + 1) . " files changed:\n");
3873 print "<table class=\"" .
3874 (@parents > 1 ? "combined " : "") .
3877 # header only for combined diff in 'commitdiff' view
3878 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3881 print "<thead><tr>\n" .
3882 "<th></th><th></th>\n"; # filename, patchN link
3883 for (my $i = 0; $i < @parents; $i++) {
3884 my $par = $parents[$i];
3886 $cgi->a({-href
=> href
(action
=>"commitdiff",
3887 hash
=>$hash, hash_parent
=>$par),
3888 -title
=> 'commitdiff to parent number ' .
3889 ($i+1) . ': ' . substr($par,0,7)},
3893 print "</tr></thead>\n<tbody>\n";
3898 foreach my $line (@{$difftree}) {
3899 my $diff = parsed_difftree_line
($line);
3902 print "<tr class=\"dark\">\n";
3904 print "<tr class=\"light\">\n";
3908 if (exists $diff->{'nparents'}) { # combined diff
3910 fill_from_file_info
($diff, @parents)
3911 unless exists $diff->{'from_file'};
3913 if (!is_deleted
($diff)) {
3914 # file exists in the result (child) commit
3916 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3917 file_name
=>$diff->{'to_file'},
3919 -class => "list"}, esc_path
($diff->{'to_file'})) .
3923 esc_path
($diff->{'to_file'}) .
3927 if ($action eq 'commitdiff') {
3930 print "<td class=\"link\">" .
3931 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3936 my $has_history = 0;
3937 my $not_deleted = 0;
3938 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3939 my $hash_parent = $parents[$i];
3940 my $from_hash = $diff->{'from_id'}[$i];
3941 my $from_path = $diff->{'from_file'}[$i];
3942 my $status = $diff->{'status'}[$i];
3944 $has_history ||= ($status ne 'A');
3945 $not_deleted ||= ($status ne 'D');
3947 if ($status eq 'A') {
3948 print "<td class=\"link\" align=\"right\"> | </td>\n";
3949 } elsif ($status eq 'D') {
3950 print "<td class=\"link\">" .
3951 $cgi->a({-href
=> href
(action
=>"blob",
3954 file_name
=>$from_path)},
3958 if ($diff->{'to_id'} eq $from_hash) {
3959 print "<td class=\"link nochange\">";
3961 print "<td class=\"link\">";
3963 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3964 hash
=>$diff->{'to_id'},
3965 hash_parent
=>$from_hash,
3967 hash_parent_base
=>$hash_parent,
3968 file_name
=>$diff->{'to_file'},
3969 file_parent
=>$from_path)},
3975 print "<td class=\"link\">";
3977 print $cgi->a({-href
=> href
(action
=>"blob",
3978 hash
=>$diff->{'to_id'},
3979 file_name
=>$diff->{'to_file'},
3982 print " | " if ($has_history);
3985 print $cgi->a({-href
=> href
(action
=>"history",
3986 file_name
=>$diff->{'to_file'},
3993 next; # instead of 'else' clause, to avoid extra indent
3995 # else ordinary diff
3997 my ($to_mode_oct, $to_mode_str, $to_file_type);
3998 my ($from_mode_oct, $from_mode_str, $from_file_type);
3999 if ($diff->{'to_mode'} ne ('0' x
6)) {
4000 $to_mode_oct = oct $diff->{'to_mode'};
4001 if (S_ISREG
($to_mode_oct)) { # only for regular file
4002 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4004 $to_file_type = file_type
($diff->{'to_mode'});
4006 if ($diff->{'from_mode'} ne ('0' x
6)) {
4007 $from_mode_oct = oct $diff->{'from_mode'};
4008 if (S_ISREG
($to_mode_oct)) { # only for regular file
4009 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4011 $from_file_type = file_type
($diff->{'from_mode'});
4014 if ($diff->{'status'} eq "A") { # created
4015 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4016 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4017 $mode_chng .= "]</span>";
4019 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4020 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4021 -class => "list"}, esc_path
($diff->{'file'}));
4023 print "<td>$mode_chng</td>\n";
4024 print "<td class=\"link\">";
4025 if ($action eq 'commitdiff') {
4028 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4031 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4032 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4036 } elsif ($diff->{'status'} eq "D") { # deleted
4037 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4039 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4040 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4041 -class => "list"}, esc_path
($diff->{'file'}));
4043 print "<td>$mode_chng</td>\n";
4044 print "<td class=\"link\">";
4045 if ($action eq 'commitdiff') {
4048 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4051 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4052 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4055 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4056 file_name
=>$diff->{'file'})},
4059 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4060 file_name
=>$diff->{'file'})},
4064 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4065 my $mode_chnge = "";
4066 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4067 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4068 if ($from_file_type ne $to_file_type) {
4069 $mode_chnge .= " from $from_file_type to $to_file_type";
4071 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4072 if ($from_mode_str && $to_mode_str) {
4073 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4074 } elsif ($to_mode_str) {
4075 $mode_chnge .= " mode: $to_mode_str";
4078 $mode_chnge .= "]</span>\n";
4081 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4082 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4083 -class => "list"}, esc_path
($diff->{'file'}));
4085 print "<td>$mode_chnge</td>\n";
4086 print "<td class=\"link\">";
4087 if ($action eq 'commitdiff') {
4090 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4092 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4093 # "commit" view and modified file (not onlu mode changed)
4094 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4095 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4096 hash_base
=>$hash, hash_parent_base
=>$parent,
4097 file_name
=>$diff->{'file'})},
4101 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4102 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4105 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4106 file_name
=>$diff->{'file'})},
4109 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4110 file_name
=>$diff->{'file'})},
4114 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4115 my %status_name = ('R' => 'moved', 'C' => 'copied');
4116 my $nstatus = $status_name{$diff->{'status'}};
4118 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4119 # mode also for directories, so we cannot use $to_mode_str
4120 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4123 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4124 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4125 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4126 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4127 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4128 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4129 -class => "list"}, esc_path
($diff->{'from_file'})) .
4130 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4131 "<td class=\"link\">";
4132 if ($action eq 'commitdiff') {
4135 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4137 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4138 # "commit" view and modified file (not only pure rename or copy)
4139 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4140 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4141 hash_base
=>$hash, hash_parent_base
=>$parent,
4142 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4146 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4147 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4150 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4151 file_name
=>$diff->{'to_file'})},
4154 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4155 file_name
=>$diff->{'to_file'})},
4159 } # we should not encounter Unmerged (U) or Unknown (X) status
4162 print "</tbody>" if $has_header;
4166 sub git_patchset_body
{
4167 my ($fd, $difftree, $hash, @hash_parents) = @_;
4168 my ($hash_parent) = $hash_parents[0];
4170 my $is_combined = (@hash_parents > 1);
4172 my $patch_number = 0;
4178 print "<div class=\"patchset\">\n";
4180 # skip to first patch
4181 while ($patch_line = <$fd>) {
4184 last if ($patch_line =~ m/^diff /);
4188 while ($patch_line) {
4190 # parse "git diff" header line
4191 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4192 # $1 is from_name, which we do not use
4193 $to_name = unquote
($2);
4194 $to_name =~ s!^b/!!;
4195 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4196 # $1 is 'cc' or 'combined', which we do not use
4197 $to_name = unquote
($2);
4202 # check if current patch belong to current raw line
4203 # and parse raw git-diff line if needed
4204 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4205 # this is continuation of a split patch
4206 print "<div class=\"patch cont\">\n";
4208 # advance raw git-diff output if needed
4209 $patch_idx++ if defined $diffinfo;
4211 # read and prepare patch information
4212 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4214 # compact combined diff output can have some patches skipped
4215 # find which patch (using pathname of result) we are at now;
4217 while ($to_name ne $diffinfo->{'to_file'}) {
4218 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4219 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4220 "</div>\n"; # class="patch"
4225 last if $patch_idx > $#$difftree;
4226 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4230 # modifies %from, %to hashes
4231 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4233 # this is first patch for raw difftree line with $patch_idx index
4234 # we index @$difftree array from 0, but number patches from 1
4235 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4239 #assert($patch_line =~ m/^diff /) if DEBUG;
4240 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4242 # print "git diff" header
4243 print format_git_diff_header_line
($patch_line, $diffinfo,
4246 # print extended diff header
4247 print "<div class=\"diff extended_header\">\n";
4249 while ($patch_line = <$fd>) {
4252 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4254 print format_extended_diff_header_line
($patch_line, $diffinfo,
4257 print "</div>\n"; # class="diff extended_header"
4259 # from-file/to-file diff header
4260 if (! $patch_line) {
4261 print "</div>\n"; # class="patch"
4264 next PATCH
if ($patch_line =~ m/^diff /);
4265 #assert($patch_line =~ m/^---/) if DEBUG;
4267 my $last_patch_line = $patch_line;
4268 $patch_line = <$fd>;
4270 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4272 print format_diff_from_to_header
($last_patch_line, $patch_line,
4273 $diffinfo, \
%from, \
%to,
4278 while ($patch_line = <$fd>) {
4281 next PATCH
if ($patch_line =~ m/^diff /);
4283 print format_diff_line
($patch_line, \
%from, \
%to);
4287 print "</div>\n"; # class="patch"
4290 # for compact combined (--cc) format, with chunk and patch simpliciaction
4291 # patchset might be empty, but there might be unprocessed raw lines
4292 for (++$patch_idx if $patch_number > 0;
4293 $patch_idx < @$difftree;
4295 # read and prepare patch information
4296 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4298 # generate anchor for "patch" links in difftree / whatchanged part
4299 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4300 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4301 "</div>\n"; # class="patch"
4306 if ($patch_number == 0) {
4307 if (@hash_parents > 1) {
4308 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4310 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4314 print "</div>\n"; # class="patchset"
4317 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4319 # fills project list info (age, description, owner, forks) for each
4320 # project in the list, removing invalid projects from returned list
4321 # NOTE: modifies $projlist, but does not remove entries from it
4322 sub fill_project_list_info
{
4323 my ($projlist, $check_forks) = @_;
4326 my $show_ctags = gitweb_check_feature
('ctags');
4328 foreach my $pr (@$projlist) {
4329 my (@activity) = git_get_last_activity
($pr->{'path'});
4330 unless (@activity) {
4333 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4334 if (!defined $pr->{'descr'}) {
4335 my $descr = git_get_project_description
($pr->{'path'}) || "";
4336 $descr = to_utf8
($descr);
4337 $pr->{'descr_long'} = $descr;
4338 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4340 if (!defined $pr->{'owner'}) {
4341 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4344 my $pname = $pr->{'path'};
4345 if (($pname =~ s/\.git$//) &&
4346 ($pname !~ /\/$/) &&
4347 (-d
"$projectroot/$pname")) {
4348 $pr->{'forks'} = "-d $projectroot/$pname";
4353 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4354 push @projects, $pr;
4360 # print 'sort by' <th> element, generating 'sort by $name' replay link
4361 # if that order is not selected
4363 print format_sort_th
(@_);
4366 sub format_sort_th
{
4367 my ($name, $order, $header) = @_;
4369 $header ||= ucfirst($name);
4371 if ($order eq $name) {
4372 $sort_th .= "<th>$header</th>\n";
4374 $sort_th .= "<th>" .
4375 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4376 -class => "header"}, $header) .
4383 sub git_project_list_body
{
4384 # actually uses global variable $project
4385 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4387 my $check_forks = gitweb_check_feature
('forks');
4388 my @projects = fill_project_list_info
($projlist, $check_forks);
4390 $order ||= $default_projects_order;
4391 $from = 0 unless defined $from;
4392 $to = $#projects if (!defined $to || $#projects < $to);
4395 project
=> { key
=> 'path', type
=> 'str' },
4396 descr
=> { key
=> 'descr_long', type
=> 'str' },
4397 owner
=> { key
=> 'owner', type
=> 'str' },
4398 age
=> { key
=> 'age', type
=> 'num' }
4400 my $oi = $order_info{$order};
4401 if ($oi->{'type'} eq 'str') {
4402 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4404 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4407 my $show_ctags = gitweb_check_feature
('ctags');
4410 foreach my $p (@projects) {
4411 foreach my $ct (keys %{$p->{'ctags'}}) {
4412 $ctags{$ct} += $p->{'ctags'}->{$ct};
4415 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4416 print git_show_project_tagcloud
($cloud, 64);
4419 print "<table class=\"project_list\">\n";
4420 unless ($no_header) {
4423 print "<th></th>\n";
4425 print_sort_th
('project', $order, 'Project');
4426 print_sort_th
('descr', $order, 'Description');
4427 print_sort_th
('owner', $order, 'Owner');
4428 print_sort_th
('age', $order, 'Last Change');
4429 print "<th></th>\n" . # for links
4433 my $tagfilter = $cgi->param('by_tag');
4434 for (my $i = $from; $i <= $to; $i++) {
4435 my $pr = $projects[$i];
4437 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4438 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4439 and not $pr->{'descr_long'} =~ /$searchtext/;
4440 # Weed out forks or non-matching entries of search
4442 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4443 $forkbase="^$forkbase" if $forkbase;
4444 next if not $searchtext and not $tagfilter and $show_ctags
4445 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4449 print "<tr class=\"dark\">\n";
4451 print "<tr class=\"light\">\n";
4456 if ($pr->{'forks'}) {
4457 print "<!-- $pr->{'forks'} -->\n";
4458 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4462 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4463 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4464 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4465 -class => "list", -title
=> $pr->{'descr_long'}},
4466 esc_html
($pr->{'descr'})) . "</td>\n" .
4467 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4468 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4469 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4470 "<td class=\"link\">" .
4471 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4472 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4473 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4474 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4475 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4479 if (defined $extra) {
4482 print "<td></td>\n";
4484 print "<td colspan=\"5\">$extra</td>\n" .
4491 # uses global variable $project
4492 my ($commitlist, $from, $to, $refs, $extra) = @_;
4494 $from = 0 unless defined $from;
4495 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4497 for (my $i = 0; $i <= $to; $i++) {
4498 my %co = %{$commitlist->[$i]};
4500 my $commit = $co{'id'};
4501 my $ref = format_ref_marker
($refs, $commit);
4502 my %ad = parse_date
($co{'author_epoch'});
4503 git_print_header_div
('commit',
4504 "<span class=\"age\">$co{'age_string'}</span>" .
4505 esc_html
($co{'title'}) . $ref,
4507 print "<div class=\"title_text\">\n" .
4508 "<div class=\"log_link\">\n" .
4509 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4511 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4513 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4516 git_print_authorship
(\
%co, -tag
=> 'span');
4517 print "<br/>\n</div>\n";
4519 print "<div class=\"log_body\">\n";
4520 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4524 print "<div class=\"page_nav\">\n";
4530 sub git_shortlog_body
{
4531 # uses global variable $project
4532 my ($commitlist, $from, $to, $refs, $extra) = @_;
4534 $from = 0 unless defined $from;
4535 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4537 print "<table class=\"shortlog\">\n";
4539 for (my $i = $from; $i <= $to; $i++) {
4540 my %co = %{$commitlist->[$i]};
4541 my $commit = $co{'id'};
4542 my $ref = format_ref_marker
($refs, $commit);
4544 print "<tr class=\"dark\">\n";
4546 print "<tr class=\"light\">\n";
4549 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4550 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4551 format_author_html
('td', \
%co, 10) . "<td>";
4552 print format_subject_html
($co{'title'}, $co{'title_short'},
4553 href
(action
=>"commit", hash
=>$commit), $ref);
4555 "<td class=\"link\">" .
4556 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4557 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4558 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4559 my $snapshot_links = format_snapshot_links
($commit);
4560 if (defined $snapshot_links) {
4561 print " | " . $snapshot_links;
4566 if (defined $extra) {
4568 "<td colspan=\"4\">$extra</td>\n" .
4574 sub git_history_body
{
4575 # Warning: assumes constant type (blob or tree) during history
4576 my ($commitlist, $from, $to, $refs, $extra,
4577 $file_name, $file_hash, $ftype) = @_;
4579 $from = 0 unless defined $from;
4580 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4582 print "<table class=\"history\">\n";
4584 for (my $i = $from; $i <= $to; $i++) {
4585 my %co = %{$commitlist->[$i]};
4589 my $commit = $co{'id'};
4591 my $ref = format_ref_marker
($refs, $commit);
4594 print "<tr class=\"dark\">\n";
4596 print "<tr class=\"light\">\n";
4599 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4600 # shortlog: format_author_html('td', \%co, 10)
4601 format_author_html
('td', \
%co, 15, 3) . "<td>";
4602 # originally git_history used chop_str($co{'title'}, 50)
4603 print format_subject_html
($co{'title'}, $co{'title_short'},
4604 href
(action
=>"commit", hash
=>$commit), $ref);
4606 "<td class=\"link\">" .
4607 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4608 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4610 if ($ftype eq 'blob') {
4611 my $blob_current = $file_hash;
4612 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4613 if (defined $blob_current && defined $blob_parent &&
4614 $blob_current ne $blob_parent) {
4616 $cgi->a({-href
=> href
(action
=>"blobdiff",
4617 hash
=>$blob_current, hash_parent
=>$blob_parent,
4618 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4619 file_name
=>$file_name)},
4626 if (defined $extra) {
4628 "<td colspan=\"4\">$extra</td>\n" .
4635 # uses global variable $project
4636 my ($taglist, $from, $to, $extra) = @_;
4637 $from = 0 unless defined $from;
4638 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4640 print "<table class=\"tags\">\n";
4642 for (my $i = $from; $i <= $to; $i++) {
4643 my $entry = $taglist->[$i];
4645 my $comment = $tag{'subject'};
4647 if (defined $comment) {
4648 $comment_short = chop_str
($comment, 30, 5);
4651 print "<tr class=\"dark\">\n";
4653 print "<tr class=\"light\">\n";
4656 if (defined $tag{'age'}) {
4657 print "<td><i>$tag{'age'}</i></td>\n";
4659 print "<td></td>\n";
4662 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4663 -class => "list name"}, esc_html
($tag{'name'})) .
4666 if (defined $comment) {
4667 print format_subject_html
($comment, $comment_short,
4668 href
(action
=>"tag", hash
=>$tag{'id'}));
4671 "<td class=\"selflink\">";
4672 if ($tag{'type'} eq "tag") {
4673 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4678 "<td class=\"link\">" . " | " .
4679 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4680 if ($tag{'reftype'} eq "commit") {
4681 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4682 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4683 } elsif ($tag{'reftype'} eq "blob") {
4684 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4689 if (defined $extra) {
4691 "<td colspan=\"5\">$extra</td>\n" .
4697 sub git_heads_body
{
4698 # uses global variable $project
4699 my ($headlist, $head, $from, $to, $extra) = @_;
4700 $from = 0 unless defined $from;
4701 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4703 print "<table class=\"heads\">\n";
4705 for (my $i = $from; $i <= $to; $i++) {
4706 my $entry = $headlist->[$i];
4708 my $curr = $ref{'id'} eq $head;
4710 print "<tr class=\"dark\">\n";
4712 print "<tr class=\"light\">\n";
4715 print "<td><i>$ref{'age'}</i></td>\n" .
4716 ($curr ? "<td class=\"current_head\">" : "<td>") .
4717 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4718 -class => "list name"},esc_html
($ref{'name'})) .
4720 "<td class=\"link\">" .
4721 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4722 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4723 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4727 if (defined $extra) {
4729 "<td colspan=\"3\">$extra</td>\n" .
4735 sub git_search_grep_body
{
4736 my ($commitlist, $from, $to, $extra) = @_;
4737 $from = 0 unless defined $from;
4738 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4740 print "<table class=\"commit_search\">\n";
4742 for (my $i = $from; $i <= $to; $i++) {
4743 my %co = %{$commitlist->[$i]};
4747 my $commit = $co{'id'};
4749 print "<tr class=\"dark\">\n";
4751 print "<tr class=\"light\">\n";
4754 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4755 format_author_html
('td', \
%co, 15, 5) .
4757 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4758 -class => "list subject"},
4759 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4760 my $comment = $co{'comment'};
4761 foreach my $line (@$comment) {
4762 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4763 my ($lead, $match, $trail) = ($1, $2, $3);
4764 $match = chop_str
($match, 70, 5, 'center');
4765 my $contextlen = int((80 - length($match))/2);
4766 $contextlen = 30 if ($contextlen > 30);
4767 $lead = chop_str
($lead, $contextlen, 10, 'left');
4768 $trail = chop_str
($trail, $contextlen, 10, 'right');
4770 $lead = esc_html
($lead);
4771 $match = esc_html
($match);
4772 $trail = esc_html
($trail);
4774 print "$lead<span class=\"match\">$match</span>$trail<br />";
4778 "<td class=\"link\">" .
4779 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4781 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4783 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4787 if (defined $extra) {
4789 "<td colspan=\"3\">$extra</td>\n" .
4795 ## ======================================================================
4796 ## ======================================================================
4799 sub git_project_list
{
4800 my $order = $input_params{'order'};
4801 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4802 die_error
(400, "Unknown order parameter");
4805 my @list = git_get_projects_list
();
4807 die_error
(404, "No projects found");
4811 if (defined $home_text && -f
$home_text) {
4812 print "<div class=\"index_include\">\n";
4813 insert_file
($home_text);
4816 print $cgi->startform(-method => "get") .
4817 "<p class=\"projsearch\">Search:\n" .
4818 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4820 $cgi->end_form() . "\n";
4821 git_project_list_body
(\
@list, $order);
4826 my $order = $input_params{'order'};
4827 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4828 die_error
(400, "Unknown order parameter");
4831 my @list = git_get_projects_list
($project);
4833 die_error
(404, "No forks found");
4837 git_print_page_nav
('','');
4838 git_print_header_div
('summary', "$project forks");
4839 git_project_list_body
(\
@list, $order);
4843 sub git_project_index
{
4844 my @projects = git_get_projects_list
($project);
4847 -type
=> 'text/plain',
4848 -charset
=> 'utf-8',
4849 -content_disposition
=> 'inline; filename="index.aux"');
4851 foreach my $pr (@projects) {
4852 if (!exists $pr->{'owner'}) {
4853 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4856 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4857 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4858 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4859 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4863 print "$path $owner\n";
4868 my $descr = git_get_project_description
($project) || "none";
4869 my %co = parse_commit
("HEAD");
4870 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4871 my $head = $co{'id'};
4873 my $owner = git_get_project_owner
($project);
4875 my $refs = git_get_references
();
4876 # These get_*_list functions return one more to allow us to see if
4877 # there are more ...
4878 my @taglist = git_get_tags_list
(16);
4879 my @headlist = git_get_heads_list
(16);
4881 my $check_forks = gitweb_check_feature
('forks');
4884 @forklist = git_get_projects_list
($project);
4888 git_print_page_nav
('summary','', $head);
4890 print "<div class=\"title\"> </div>\n";
4891 print "<table class=\"projects_list\">\n" .
4892 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4893 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4894 if (defined $cd{'rfc2822'}) {
4895 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4898 # use per project git URL list in $projectroot/$project/cloneurl
4899 # or make project git URL from git base URL and project name
4900 my $url_tag = "URL";
4901 my @url_list = git_get_project_url_list
($project);
4902 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4903 foreach my $git_url (@url_list) {
4904 next unless $git_url;
4905 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4910 my $show_ctags = gitweb_check_feature
('ctags');
4912 my $ctags = git_get_project_ctags
($project);
4913 my $cloud = git_populate_project_tagcloud
($ctags);
4914 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4915 print "</td>\n<td>" unless %$ctags;
4916 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4917 print "</td>\n<td>" if %$ctags;
4918 print git_show_project_tagcloud
($cloud, 48);
4924 # If XSS prevention is on, we don't include README.html.
4925 # TODO: Allow a readme in some safe format.
4926 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4927 print "<div class=\"title\">readme</div>\n" .
4928 "<div class=\"readme\">\n";
4929 insert_file
("$projectroot/$project/README.html");
4930 print "\n</div>\n"; # class="readme"
4933 # we need to request one more than 16 (0..15) to check if
4935 my @commitlist = $head ? parse_commits
($head, 17) : ();
4937 git_print_header_div
('shortlog');
4938 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4939 $#commitlist <= 15 ? undef :
4940 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4944 git_print_header_div
('tags');
4945 git_tags_body
(\
@taglist, 0, 15,
4946 $#taglist <= 15 ? undef :
4947 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4951 git_print_header_div
('heads');
4952 git_heads_body
(\
@headlist, $head, 0, 15,
4953 $#headlist <= 15 ? undef :
4954 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4958 git_print_header_div
('forks');
4959 git_project_list_body
(\
@forklist, 'age', 0, 15,
4960 $#forklist <= 15 ? undef :
4961 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4969 my $head = git_get_head_hash
($project);
4971 git_print_page_nav
('','', $head,undef,$head);
4972 my %tag = parse_tag
($hash);
4975 die_error
(404, "Unknown tag object");
4978 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4979 print "<div class=\"title_text\">\n" .
4980 "<table class=\"object_header\">\n" .
4982 "<td>object</td>\n" .
4983 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4984 $tag{'object'}) . "</td>\n" .
4985 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4986 $tag{'type'}) . "</td>\n" .
4988 if (defined($tag{'author'})) {
4989 git_print_authorship_rows
(\
%tag, 'author');
4991 print "</table>\n\n" .
4993 print "<div class=\"page_body\">";
4994 my $comment = $tag{'comment'};
4995 foreach my $line (@$comment) {
4997 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
5003 sub git_blame_common
{
5004 my $format = shift || 'porcelain';
5005 if ($format eq 'porcelain' && $cgi->param('js')) {
5006 $format = 'incremental';
5007 $action = 'blame_incremental'; # for page title etc
5011 gitweb_check_feature
('blame')
5012 or die_error
(403, "Blame view not allowed");
5015 die_error
(400, "No file name given") unless $file_name;
5016 $hash_base ||= git_get_head_hash
($project);
5017 die_error
(404, "Couldn't find base commit") unless $hash_base;
5018 my %co = parse_commit
($hash_base)
5019 or die_error
(404, "Commit not found");
5021 if (!defined $hash) {
5022 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5023 or die_error
(404, "Error looking up file");
5025 $ftype = git_get_type
($hash);
5026 if ($ftype !~ "blob") {
5027 die_error
(400, "Object is not a blob");
5032 if ($format eq 'incremental') {
5033 # get file contents (as base)
5034 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5035 or die_error
(500, "Open git-cat-file failed");
5036 } elsif ($format eq 'data') {
5037 # run git-blame --incremental
5038 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5039 $hash_base, "--", $file_name
5040 or die_error
(500, "Open git-blame --incremental failed");
5042 # run git-blame --porcelain
5043 open $fd, "-|", git_cmd
(), "blame", '-p',
5044 $hash_base, '--', $file_name
5045 or die_error
(500, "Open git-blame --porcelain failed");
5048 # incremental blame data returns early
5049 if ($format eq 'data') {
5051 -type
=>"text/plain", -charset
=> "utf-8",
5052 -status
=> "200 OK");
5053 local $| = 1; # output autoflush
5056 or print "ERROR $!\n";
5059 if (defined $t0 && gitweb_check_feature
('timed')) {
5061 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5062 ' '.$number_of_git_cmds;
5072 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5075 if ($format eq 'incremental') {
5077 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5078 "blame") . " (non-incremental)";
5081 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5082 "blame") . " (incremental)";
5086 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5089 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5091 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5092 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5093 git_print_page_path
($file_name, $ftype, $hash_base);
5096 if ($format eq 'incremental') {
5097 print "<noscript>\n<div class=\"error\"><center><b>\n".
5098 "This page requires JavaScript to run.\n Use ".
5099 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5102 "</b></center></div>\n</noscript>\n";
5104 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5107 print qq
!<div
class="page_body">\n!;
5108 print qq
!<div id
="progress_info">... / ...</div
>\n!
5109 if ($format eq 'incremental');
5110 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5111 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5113 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5117 my @rev_color = qw(light dark);
5118 my $num_colors = scalar(@rev_color);
5119 my $current_color = 0;
5121 if ($format eq 'incremental') {
5122 my $color_class = $rev_color[$current_color];
5127 while (my $line = <$fd>) {
5131 print qq
!<tr id
="l$linenr" class="$color_class">!.
5132 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5133 qq
!<td
class="linenr">!.
5134 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5135 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5139 } else { # porcelain, i.e. ordinary blame
5140 my %metainfo = (); # saves information about commits
5144 while (my $line = <$fd>) {
5146 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5147 # no <lines in group> for subsequent lines in group of lines
5148 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5149 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5150 if (!exists $metainfo{$full_rev}) {
5151 $metainfo{$full_rev} = { 'nprevious' => 0 };
5153 my $meta = $metainfo{$full_rev};
5155 while ($data = <$fd>) {
5157 last if ($data =~ s/^\t//); # contents of line
5158 if ($data =~ /^(\S+)(?: (.*))?$/) {
5159 $meta->{$1} = $2 unless exists $meta->{$1};
5161 if ($data =~ /^previous /) {
5162 $meta->{'nprevious'}++;
5165 my $short_rev = substr($full_rev, 0, 8);
5166 my $author = $meta->{'author'};
5168 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5169 my $date = $date{'iso-tz'};
5171 $current_color = ($current_color + 1) % $num_colors;
5173 my $tr_class = $rev_color[$current_color];
5174 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5175 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5176 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5177 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5179 print "<td class=\"sha1\"";
5180 print " title=\"". esc_html
($author) . ", $date\"";
5181 print " rowspan=\"$group_size\"" if ($group_size > 1);
5183 print $cgi->a({-href
=> href
(action
=>"commit",
5185 file_name
=>$file_name)},
5186 esc_html
($short_rev));
5187 if ($group_size >= 2) {
5188 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5189 if (@author_initials) {
5191 esc_html
(join('', @author_initials));
5197 # 'previous' <sha1 of parent commit> <filename at commit>
5198 if (exists $meta->{'previous'} &&
5199 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5200 $meta->{'parent'} = $1;
5201 $meta->{'file_parent'} = unquote
($2);
5204 exists($meta->{'parent'}) ?
5205 $meta->{'parent'} : $full_rev;
5206 my $linenr_filename =
5207 exists($meta->{'file_parent'}) ?
5208 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5209 my $blamed = href
(action
=> 'blame',
5210 file_name
=> $linenr_filename,
5211 hash_base
=> $linenr_commit);
5212 print "<td class=\"linenr\">";
5213 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5214 -class => "linenr" },
5217 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5225 "</table>\n"; # class="blame"
5226 print "</div>\n"; # class="blame_body"
5228 or print "Reading blob failed\n";
5237 sub git_blame_incremental
{
5238 git_blame_common
('incremental');
5241 sub git_blame_data
{
5242 git_blame_common
('data');
5246 my $head = git_get_head_hash
($project);
5248 git_print_page_nav
('','', $head,undef,$head);
5249 git_print_header_div
('summary', $project);
5251 my @tagslist = git_get_tags_list
();
5253 git_tags_body
(\
@tagslist);
5259 my $head = git_get_head_hash
($project);
5261 git_print_page_nav
('','', $head,undef,$head);
5262 git_print_header_div
('summary', $project);
5264 my @headslist = git_get_heads_list
();
5266 git_heads_body
(\
@headslist, $head);
5271 sub git_blob_plain
{
5275 if (!defined $hash) {
5276 if (defined $file_name) {
5277 my $base = $hash_base || git_get_head_hash
($project);
5278 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5279 or die_error
(404, "Cannot find file");
5281 die_error
(400, "No file name defined");
5283 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5284 # blobs defined by non-textual hash id's can be cached
5288 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5289 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5291 # content-type (can include charset)
5292 $type = blob_contenttype
($fd, $file_name, $type);
5294 # "save as" filename, even when no $file_name is given
5295 my $save_as = "$hash";
5296 if (defined $file_name) {
5297 $save_as = $file_name;
5298 } elsif ($type =~ m/^text\//) {
5302 # With XSS prevention on, blobs of all types except a few known safe
5303 # ones are served with "Content-Disposition: attachment" to make sure
5304 # they don't run in our security domain. For certain image types,
5305 # blob view writes an <img> tag referring to blob_plain view, and we
5306 # want to be sure not to break that by serving the image as an
5307 # attachment (though Firefox 3 doesn't seem to care).
5308 my $sandbox = $prevent_xss &&
5309 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5313 -expires
=> $expires,
5314 -content_disposition
=>
5315 ($sandbox ? 'attachment' : 'inline')
5316 . '; filename="' . $save_as . '"');
5318 binmode STDOUT
, ':raw';
5320 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5327 if (!defined $hash) {
5328 if (defined $file_name) {
5329 my $base = $hash_base || git_get_head_hash
($project);
5330 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5331 or die_error
(404, "Cannot find file");
5333 die_error
(400, "No file name defined");
5335 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5336 # blobs defined by non-textual hash id's can be cached
5340 my $have_blame = gitweb_check_feature
('blame');
5341 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5342 or die_error
(500, "Couldn't cat $file_name, $hash");
5343 my $mimetype = blob_mimetype
($fd, $file_name);
5344 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5346 return git_blob_plain
($mimetype);
5348 # we can have blame only for text/* mimetype
5349 $have_blame &&= ($mimetype =~ m!^text/!);
5351 git_header_html
(undef, $expires);
5352 my $formats_nav = '';
5353 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5354 if (defined $file_name) {
5357 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5362 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5365 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5368 $cgi->a({-href
=> href
(action
=>"blob",
5369 hash_base
=>"HEAD", file_name
=>$file_name)},
5373 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5376 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5377 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5379 print "<div class=\"page_nav\">\n" .
5380 "<br/><br/></div>\n" .
5381 "<div class=\"title\">$hash</div>\n";
5383 git_print_page_path
($file_name, "blob", $hash_base);
5384 print "<div class=\"page_body\">\n";
5385 if ($mimetype =~ m!^image/!) {
5386 print qq
!<img type
="$mimetype"!;
5388 print qq
! alt
="$file_name" title
="$file_name"!;
5391 href(action=>"blob_plain
", hash=>$hash,
5392 hash_base=>$hash_base, file_name=>$file_name) .
5396 while (my $line = <$fd>) {
5399 $line = untabify
($line);
5400 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5401 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5402 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5406 or print "Reading blob failed.\n";
5412 if (!defined $hash_base) {
5413 $hash_base = "HEAD";
5415 if (!defined $hash) {
5416 if (defined $file_name) {
5417 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5422 die_error
(404, "No such tree") unless defined($hash);
5424 my $show_sizes = gitweb_check_feature
('show-sizes');
5425 my $have_blame = gitweb_check_feature
('blame');
5430 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5431 ($show_sizes ? '-l' : ()), @extra_options, $hash
5432 or die_error
(500, "Open git-ls-tree failed");
5433 @entries = map { chomp; $_ } <$fd>;
5435 or die_error
(404, "Reading tree failed");
5438 my $refs = git_get_references
();
5439 my $ref = format_ref_marker
($refs, $hash_base);
5442 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5444 if (defined $file_name) {
5446 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5448 $cgi->a({-href
=> href
(action
=>"tree",
5449 hash_base
=>"HEAD", file_name
=>$file_name)},
5452 my $snapshot_links = format_snapshot_links
($hash);
5453 if (defined $snapshot_links) {
5454 # FIXME: Should be available when we have no hash base as well.
5455 push @views_nav, $snapshot_links;
5457 git_print_page_nav
('tree','', $hash_base, undef, undef,
5458 join(' | ', @views_nav));
5459 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5462 print "<div class=\"page_nav\">\n";
5463 print "<br/><br/></div>\n";
5464 print "<div class=\"title\">$hash</div>\n";
5466 if (defined $file_name) {
5467 $basedir = $file_name;
5468 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5471 git_print_page_path
($file_name, 'tree', $hash_base);
5473 print "<div class=\"page_body\">\n";
5474 print "<table class=\"tree\">\n";
5476 # '..' (top directory) link if possible
5477 if (defined $hash_base &&
5478 defined $file_name && $file_name =~ m![^/]+$!) {
5480 print "<tr class=\"dark\">\n";
5482 print "<tr class=\"light\">\n";
5486 my $up = $file_name;
5487 $up =~ s!/?[^/]+$!!;
5488 undef $up unless $up;
5489 # based on git_print_tree_entry
5490 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5491 print '<td class="size"> </td>'."\n" if $show_sizes;
5492 print '<td class="list">';
5493 print $cgi->a({-href
=> href
(action
=>"tree",
5494 hash_base
=>$hash_base,
5498 print "<td class=\"link\"></td>\n";
5502 foreach my $line (@entries) {
5503 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5506 print "<tr class=\"dark\">\n";
5508 print "<tr class=\"light\">\n";
5512 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5516 print "</table>\n" .
5522 my ($project, $hash) = @_;
5524 # path/to/project.git -> project
5525 # path/to/project/.git -> project
5526 my $name = to_utf8
($project);
5527 $name =~ s
,([^/])/*\
.git
$,$1,;
5528 $name = basename
($name);
5530 $name =~ s/[[:cntrl:]]/?/g;
5533 if ($hash =~ /^[0-9a-fA-F]+$/) {
5534 # shorten SHA-1 hash
5535 my $full_hash = git_get_full_hash
($project, $hash);
5536 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5537 $ver = git_get_short_hash
($project, $hash);
5539 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5540 # tags don't need shortened SHA-1 hash
5543 # branches and other need shortened SHA-1 hash
5544 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5547 $ver .= '-' . git_get_short_hash
($project, $hash);
5549 # in case of hierarchical branch names
5552 # name = project-version_string
5553 $name = "$name-$ver";
5555 return wantarray ? ($name, $name) : $name;
5559 my $format = $input_params{'snapshot_format'};
5560 if (!@snapshot_fmts) {
5561 die_error
(403, "Snapshots not allowed");
5563 # default to first supported snapshot format
5564 $format ||= $snapshot_fmts[0];
5565 if ($format !~ m/^[a-z0-9]+$/) {
5566 die_error
(400, "Invalid snapshot format parameter");
5567 } elsif (!exists($known_snapshot_formats{$format})) {
5568 die_error
(400, "Unknown snapshot format");
5569 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5570 die_error
(403, "Snapshot format not allowed");
5571 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5572 die_error
(403, "Unsupported snapshot format");
5575 my $type = git_get_type
("$hash^{}");
5577 die_error
(404, 'Object does not exist');
5578 } elsif ($type eq 'blob') {
5579 die_error
(400, 'Object is not a tree-ish');
5582 my ($name, $prefix) = snapshot_name
($project, $hash);
5583 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5584 my $cmd = quote_command
(
5585 git_cmd
(), 'archive',
5586 "--format=$known_snapshot_formats{$format}{'format'}",
5587 "--prefix=$prefix/", $hash);
5588 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5589 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5592 $filename =~ s/(["\\])/\\$1/g;
5594 -type
=> $known_snapshot_formats{$format}{'type'},
5595 -content_disposition
=> 'inline; filename="' . $filename . '"',
5596 -status
=> '200 OK');
5598 open my $fd, "-|", $cmd
5599 or die_error
(500, "Execute git-archive failed");
5600 binmode STDOUT
, ':raw';
5602 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5606 sub git_log_generic
{
5607 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5609 my $head = git_get_head_hash
($project);
5610 if (!defined $base) {
5613 if (!defined $page) {
5616 my $refs = git_get_references
();
5618 my $commit_hash = $base;
5619 if (defined $parent) {
5620 $commit_hash = "$parent..$base";
5623 parse_commits
($commit_hash, 101, (100 * $page),
5624 defined $file_name ? ($file_name, "--full-history") : ());
5627 if (!defined $file_hash && defined $file_name) {
5628 # some commits could have deleted file in question,
5629 # and not have it in tree, but one of them has to have it
5630 for (my $i = 0; $i < @commitlist; $i++) {
5631 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5632 last if defined $file_hash;
5635 if (defined $file_hash) {
5636 $ftype = git_get_type
($file_hash);
5638 if (defined $file_name && !defined $ftype) {
5639 die_error
(500, "Unknown type of object");
5642 if (defined $file_name) {
5643 %co = parse_commit
($base)
5644 or die_error
(404, "Unknown commit object");
5648 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5650 if ($#commitlist >= 100) {
5652 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5653 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5655 my $patch_max = gitweb_get_feature
('patches');
5656 if ($patch_max && !defined $file_name) {
5657 if ($patch_max < 0 || @commitlist <= $patch_max) {
5658 $paging_nav .= " ⋅ " .
5659 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5665 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5666 if (defined $file_name) {
5667 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5669 git_print_header_div
('summary', $project)
5671 git_print_page_path
($file_name, $ftype, $hash_base)
5672 if (defined $file_name);
5674 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5675 $file_name, $file_hash, $ftype);
5681 git_log_generic
('log', \
&git_log_body
,
5682 $hash, $hash_parent);
5686 $hash ||= $hash_base || "HEAD";
5687 my %co = parse_commit
($hash)
5688 or die_error
(404, "Unknown commit object");
5690 my $parent = $co{'parent'};
5691 my $parents = $co{'parents'}; # listref
5693 # we need to prepare $formats_nav before any parameter munging
5695 if (!defined $parent) {
5697 $formats_nav .= '(initial)';
5698 } elsif (@$parents == 1) {
5699 # single parent commit
5702 $cgi->a({-href
=> href
(action
=>"commit",
5704 esc_html
(substr($parent, 0, 7))) .
5711 $cgi->a({-href
=> href
(action
=>"commit",
5713 esc_html
(substr($_, 0, 7)));
5717 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5718 $formats_nav .= " | " .
5719 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5723 if (!defined $parent) {
5727 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5729 (@$parents <= 1 ? $parent : '-c'),
5731 or die_error
(500, "Open git-diff-tree failed");
5732 @difftree = map { chomp; $_ } <$fd>;
5733 close $fd or die_error
(404, "Reading git-diff-tree failed");
5735 # non-textual hash id's can be cached
5737 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5740 my $refs = git_get_references
();
5741 my $ref = format_ref_marker
($refs, $co{'id'});
5743 git_header_html
(undef, $expires);
5744 git_print_page_nav
('commit', '',
5745 $hash, $co{'tree'}, $hash,
5748 if (defined $co{'parent'}) {
5749 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5751 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5753 print "<div class=\"title_text\">\n" .
5754 "<table class=\"object_header\">\n";
5755 git_print_authorship_rows
(\
%co);
5756 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5759 "<td class=\"sha1\">" .
5760 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5761 class => "list"}, $co{'tree'}) .
5763 "<td class=\"link\">" .
5764 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5766 my $snapshot_links = format_snapshot_links
($hash);
5767 if (defined $snapshot_links) {
5768 print " | " . $snapshot_links;
5773 foreach my $par (@$parents) {
5776 "<td class=\"sha1\">" .
5777 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5778 class => "list"}, $par) .
5780 "<td class=\"link\">" .
5781 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5783 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5790 print "<div class=\"page_body\">\n";
5791 git_print_log
($co{'comment'});
5794 git_difftree_body
(\
@difftree, $hash, @$parents);
5800 # object is defined by:
5801 # - hash or hash_base alone
5802 # - hash_base and file_name
5805 # - hash or hash_base alone
5806 if ($hash || ($hash_base && !defined $file_name)) {
5807 my $object_id = $hash || $hash_base;
5809 open my $fd, "-|", quote_command
(
5810 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5811 or die_error
(404, "Object does not exist");
5815 or die_error
(404, "Object does not exist");
5817 # - hash_base and file_name
5818 } elsif ($hash_base && defined $file_name) {
5819 $file_name =~ s
,/+$,,;
5821 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5822 or die_error
(404, "Base object does not exist");
5824 # here errors should not hapen
5825 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5826 or die_error
(500, "Open git-ls-tree failed");
5830 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5831 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5832 die_error
(404, "File or directory for given base does not exist");
5837 die_error
(400, "Not enough information to find object");
5840 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5841 hash
=>$hash, hash_base
=>$hash_base,
5842 file_name
=>$file_name),
5843 -status
=> '302 Found');
5847 my $format = shift || 'html';
5854 # preparing $fd and %diffinfo for git_patchset_body
5856 if (defined $hash_base && defined $hash_parent_base) {
5857 if (defined $file_name) {
5859 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5860 $hash_parent_base, $hash_base,
5861 "--", (defined $file_parent ? $file_parent : ()), $file_name
5862 or die_error
(500, "Open git-diff-tree failed");
5863 @difftree = map { chomp; $_ } <$fd>;
5865 or die_error
(404, "Reading git-diff-tree failed");
5867 or die_error
(404, "Blob diff not found");
5869 } elsif (defined $hash &&
5870 $hash =~ /[0-9a-fA-F]{40}/) {
5871 # try to find filename from $hash
5873 # read filtered raw output
5874 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5875 $hash_parent_base, $hash_base, "--"
5876 or die_error
(500, "Open git-diff-tree failed");
5878 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5880 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5881 map { chomp; $_ } <$fd>;
5883 or die_error
(404, "Reading git-diff-tree failed");
5885 or die_error
(404, "Blob diff not found");
5888 die_error
(400, "Missing one of the blob diff parameters");
5891 if (@difftree > 1) {
5892 die_error
(400, "Ambiguous blob diff specification");
5895 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5896 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5897 $file_name ||= $diffinfo{'to_file'};
5899 $hash_parent ||= $diffinfo{'from_id'};
5900 $hash ||= $diffinfo{'to_id'};
5902 # non-textual hash id's can be cached
5903 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5904 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5909 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5910 '-p', ($format eq 'html' ? "--full-index" : ()),
5911 $hash_parent_base, $hash_base,
5912 "--", (defined $file_parent ? $file_parent : ()), $file_name
5913 or die_error
(500, "Open git-diff-tree failed");
5916 # old/legacy style URI -- not generated anymore since 1.4.3.
5918 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5922 if ($format eq 'html') {
5924 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5926 git_header_html
(undef, $expires);
5927 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5928 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5929 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5931 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5932 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5934 if (defined $file_name) {
5935 git_print_page_path
($file_name, "blob", $hash_base);
5937 print "<div class=\"page_path\"></div>\n";
5940 } elsif ($format eq 'plain') {
5942 -type
=> 'text/plain',
5943 -charset
=> 'utf-8',
5944 -expires
=> $expires,
5945 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5947 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5950 die_error
(400, "Unknown blobdiff format");
5954 if ($format eq 'html') {
5955 print "<div class=\"page_body\">\n";
5957 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5960 print "</div>\n"; # class="page_body"
5964 while (my $line = <$fd>) {
5965 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5966 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5970 last if $line =~ m!^\+\+\+!;
5978 sub git_blobdiff_plain
{
5979 git_blobdiff
('plain');
5982 sub git_commitdiff
{
5984 my $format = $params{-format
} || 'html';
5986 my ($patch_max) = gitweb_get_feature
('patches');
5987 if ($format eq 'patch') {
5988 die_error
(403, "Patch view not allowed") unless $patch_max;
5991 $hash ||= $hash_base || "HEAD";
5992 my %co = parse_commit
($hash)
5993 or die_error
(404, "Unknown commit object");
5995 # choose format for commitdiff for merge
5996 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5997 $hash_parent = '--cc';
5999 # we need to prepare $formats_nav before almost any parameter munging
6001 if ($format eq 'html') {
6003 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6005 if ($patch_max && @{$co{'parents'}} <= 1) {
6006 $formats_nav .= " | " .
6007 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6011 if (defined $hash_parent &&
6012 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6013 # commitdiff with two commits given
6014 my $hash_parent_short = $hash_parent;
6015 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6016 $hash_parent_short = substr($hash_parent, 0, 7);
6020 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
6021 if ($co{'parents'}[$i] eq $hash_parent) {
6022 $formats_nav .= ' parent ' . ($i+1);
6026 $formats_nav .= ': ' .
6027 $cgi->a({-href
=> href
(action
=>"commitdiff",
6028 hash
=>$hash_parent)},
6029 esc_html
($hash_parent_short)) .
6031 } elsif (!$co{'parent'}) {
6033 $formats_nav .= ' (initial)';
6034 } elsif (scalar @{$co{'parents'}} == 1) {
6035 # single parent commit
6038 $cgi->a({-href
=> href
(action
=>"commitdiff",
6039 hash
=>$co{'parent'})},
6040 esc_html
(substr($co{'parent'}, 0, 7))) .
6044 if ($hash_parent eq '--cc') {
6045 $formats_nav .= ' | ' .
6046 $cgi->a({-href
=> href
(action
=>"commitdiff",
6047 hash
=>$hash, hash_parent
=>'-c')},
6049 } else { # $hash_parent eq '-c'
6050 $formats_nav .= ' | ' .
6051 $cgi->a({-href
=> href
(action
=>"commitdiff",
6052 hash
=>$hash, hash_parent
=>'--cc')},
6058 $cgi->a({-href
=> href
(action
=>"commitdiff",
6060 esc_html
(substr($_, 0, 7)));
6061 } @{$co{'parents'}} ) .
6066 my $hash_parent_param = $hash_parent;
6067 if (!defined $hash_parent_param) {
6068 # --cc for multiple parents, --root for parentless
6069 $hash_parent_param =
6070 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6076 if ($format eq 'html') {
6077 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6078 "--no-commit-id", "--patch-with-raw", "--full-index",
6079 $hash_parent_param, $hash, "--"
6080 or die_error
(500, "Open git-diff-tree failed");
6082 while (my $line = <$fd>) {
6084 # empty line ends raw part of diff-tree output
6086 push @difftree, scalar parse_difftree_raw_line
($line);
6089 } elsif ($format eq 'plain') {
6090 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6091 '-p', $hash_parent_param, $hash, "--"
6092 or die_error
(500, "Open git-diff-tree failed");
6093 } elsif ($format eq 'patch') {
6094 # For commit ranges, we limit the output to the number of
6095 # patches specified in the 'patches' feature.
6096 # For single commits, we limit the output to a single patch,
6097 # diverging from the git-format-patch default.
6098 my @commit_spec = ();
6100 if ($patch_max > 0) {
6101 push @commit_spec, "-$patch_max";
6103 push @commit_spec, '-n', "$hash_parent..$hash";
6105 if ($params{-single
}) {
6106 push @commit_spec, '-1';
6108 if ($patch_max > 0) {
6109 push @commit_spec, "-$patch_max";
6111 push @commit_spec, "-n";
6113 push @commit_spec, '--root', $hash;
6115 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6116 '--stdout', @commit_spec
6117 or die_error
(500, "Open git-format-patch failed");
6119 die_error
(400, "Unknown commitdiff format");
6122 # non-textual hash id's can be cached
6124 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6128 # write commit message
6129 if ($format eq 'html') {
6130 my $refs = git_get_references
();
6131 my $ref = format_ref_marker
($refs, $co{'id'});
6133 git_header_html
(undef, $expires);
6134 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6135 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6136 print "<div class=\"title_text\">\n" .
6137 "<table class=\"object_header\">\n";
6138 git_print_authorship_rows
(\
%co);
6141 print "<div class=\"page_body\">\n";
6142 if (@{$co{'comment'}} > 1) {
6143 print "<div class=\"log\">\n";
6144 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6145 print "</div>\n"; # class="log"
6148 } elsif ($format eq 'plain') {
6149 my $refs = git_get_references
("tags");
6150 my $tagname = git_get_rev_name_tags
($hash);
6151 my $filename = basename
($project) . "-$hash.patch";
6154 -type
=> 'text/plain',
6155 -charset
=> 'utf-8',
6156 -expires
=> $expires,
6157 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6158 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6159 print "From: " . to_utf8
($co{'author'}) . "\n";
6160 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6161 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6163 print "X-Git-Tag: $tagname\n" if $tagname;
6164 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6166 foreach my $line (@{$co{'comment'}}) {
6167 print to_utf8
($line) . "\n";
6170 } elsif ($format eq 'patch') {
6171 my $filename = basename
($project) . "-$hash.patch";
6174 -type
=> 'text/plain',
6175 -charset
=> 'utf-8',
6176 -expires
=> $expires,
6177 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6181 if ($format eq 'html') {
6182 my $use_parents = !defined $hash_parent ||
6183 $hash_parent eq '-c' || $hash_parent eq '--cc';
6184 git_difftree_body
(\
@difftree, $hash,
6185 $use_parents ? @{$co{'parents'}} : $hash_parent);
6188 git_patchset_body
($fd, \
@difftree, $hash,
6189 $use_parents ? @{$co{'parents'}} : $hash_parent);
6191 print "</div>\n"; # class="page_body"
6194 } elsif ($format eq 'plain') {
6198 or print "Reading git-diff-tree failed\n";
6199 } elsif ($format eq 'patch') {
6203 or print "Reading git-format-patch failed\n";
6207 sub git_commitdiff_plain
{
6208 git_commitdiff
(-format
=> 'plain');
6211 # format-patch-style patches
6213 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6217 git_commitdiff
(-format
=> 'patch');
6221 git_log_generic
('history', \
&git_history_body
,
6222 $hash_base, $hash_parent_base,
6227 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6228 if (!defined $searchtext) {
6229 die_error
(400, "Text field is empty");
6231 if (!defined $hash) {
6232 $hash = git_get_head_hash
($project);
6234 my %co = parse_commit
($hash);
6236 die_error
(404, "Unknown commit object");
6238 if (!defined $page) {
6242 $searchtype ||= 'commit';
6243 if ($searchtype eq 'pickaxe') {
6244 # pickaxe may take all resources of your box and run for several minutes
6245 # with every query - so decide by yourself how public you make this feature
6246 gitweb_check_feature
('pickaxe')
6247 or die_error
(403, "Pickaxe is disabled");
6249 if ($searchtype eq 'grep') {
6250 gitweb_check_feature
('grep')[0]
6251 or die_error
(403, "Grep is disabled");
6256 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6258 if ($searchtype eq 'commit') {
6259 $greptype = "--grep=";
6260 } elsif ($searchtype eq 'author') {
6261 $greptype = "--author=";
6262 } elsif ($searchtype eq 'committer') {
6263 $greptype = "--committer=";
6265 $greptype .= $searchtext;
6266 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6267 $greptype, '--regexp-ignore-case',
6268 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6270 my $paging_nav = '';
6273 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6274 searchtext
=>$searchtext,
6275 searchtype
=>$searchtype)},
6277 $paging_nav .= " ⋅ " .
6278 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6279 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6281 $paging_nav .= "first";
6282 $paging_nav .= " ⋅ prev";
6285 if ($#commitlist >= 100) {
6287 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6288 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6289 $paging_nav .= " ⋅ $next_link";
6291 $paging_nav .= " ⋅ next";
6294 if ($#commitlist >= 100) {
6297 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6298 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6299 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6302 if ($searchtype eq 'pickaxe') {
6303 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6304 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6306 print "<table class=\"pickaxe search\">\n";
6309 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6310 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6311 ($search_use_regexp ? '--pickaxe-regex' : ());
6314 while (my $line = <$fd>) {
6318 my %set = parse_difftree_raw_line
($line);
6319 if (defined $set{'commit'}) {
6320 # finish previous commit
6323 "<td class=\"link\">" .
6324 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6326 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6332 print "<tr class=\"dark\">\n";
6334 print "<tr class=\"light\">\n";
6337 %co = parse_commit
($set{'commit'});
6338 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6339 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6340 "<td><i>$author</i></td>\n" .
6342 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6343 -class => "list subject"},
6344 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6345 } elsif (defined $set{'to_id'}) {
6346 next if ($set{'to_id'} =~ m/^0{40}$/);
6348 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6349 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6351 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6357 # finish last commit (warning: repetition!)
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");
6371 if ($searchtype eq 'grep') {
6372 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6373 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6375 print "<table class=\"grep_search\">\n";
6379 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6380 $search_use_regexp ? ('-E', '-i') : '-F',
6381 $searchtext, $co{'tree'};
6383 while (my $line = <$fd>) {
6385 my ($file, $lno, $ltext, $binary);
6386 last if ($matches++ > 1000);
6387 if ($line =~ /^Binary file (.+) matches$/) {
6391 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6393 if ($file ne $lastfile) {
6394 $lastfile and print "</td></tr>\n";
6396 print "<tr class=\"dark\">\n";
6398 print "<tr class=\"light\">\n";
6400 print "<td class=\"list\">".
6401 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6402 file_name
=>"$file"),
6403 -class => "list"}, esc_path
($file));
6404 print "</td><td>\n";
6408 print "<div class=\"binary\">Binary file</div>\n";
6410 $ltext = untabify
($ltext);
6411 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6412 $ltext = esc_html
($1, -nbsp
=>1);
6413 $ltext .= '<span class="match">';
6414 $ltext .= esc_html
($2, -nbsp
=>1);
6415 $ltext .= '</span>';
6416 $ltext .= esc_html
($3, -nbsp
=>1);
6418 $ltext = esc_html
($ltext, -nbsp
=>1);
6420 print "<div class=\"pre\">" .
6421 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6422 file_name
=>"$file").'#l'.$lno,
6423 -class => "linenr"}, sprintf('%4i', $lno))
6424 . ' ' . $ltext . "</div>\n";
6428 print "</td></tr>\n";
6429 if ($matches > 1000) {
6430 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6433 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6442 sub git_search_help
{
6444 git_print_page_nav
('','', $hash,$hash,$hash);
6446 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6447 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6448 the pattern entered is recognized as the POSIX extended
6449 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6452 <dt><b>commit</b></dt>
6453 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6455 my $have_grep = gitweb_check_feature
('grep');
6458 <dt><b>grep</b></dt>
6459 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6460 a different one) are searched for the given pattern. On large trees, this search can take
6461 a while and put some strain on the server, so please use it with some consideration. Note that
6462 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6463 case-sensitive.</dd>
6467 <dt><b>author</b></dt>
6468 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6469 <dt><b>committer</b></dt>
6470 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6472 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6473 if ($have_pickaxe) {
6475 <dt><b>pickaxe</b></dt>
6476 <dd>All commits that caused the string to appear or disappear from any file (changes that
6477 added, removed or "modified" the string) will be listed. This search can take a while and
6478 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6479 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6487 git_log_generic
('shortlog', \
&git_shortlog_body
,
6488 $hash, $hash_parent);
6491 ## ......................................................................
6492 ## feeds (RSS, Atom; OPML)
6495 my $format = shift || 'atom';
6496 my $have_blame = gitweb_check_feature
('blame');
6498 # Atom: http://www.atomenabled.org/developers/syndication/
6499 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6500 if ($format ne 'rss' && $format ne 'atom') {
6501 die_error
(400, "Unknown web feed format");
6504 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6505 my $head = $hash || 'HEAD';
6506 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6510 my $content_type = "application/$format+xml";
6511 if (defined $cgi->http('HTTP_ACCEPT') &&
6512 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6513 # browser (feed reader) prefers text/xml
6514 $content_type = 'text/xml';
6516 if (defined($commitlist[0])) {
6517 %latest_commit = %{$commitlist[0]};
6518 my $latest_epoch = $latest_commit{'committer_epoch'};
6519 %latest_date = parse_date
($latest_epoch);
6520 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6521 if (defined $if_modified) {
6523 if (eval { require HTTP
::Date
; 1; }) {
6524 $since = HTTP
::Date
::str2time
($if_modified);
6525 } elsif (eval { require Time
::ParseDate
; 1; }) {
6526 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6528 if (defined $since && $latest_epoch <= $since) {
6530 -type
=> $content_type,
6531 -charset
=> 'utf-8',
6532 -last_modified
=> $latest_date{'rfc2822'},
6533 -status
=> '304 Not Modified');
6538 -type
=> $content_type,
6539 -charset
=> 'utf-8',
6540 -last_modified
=> $latest_date{'rfc2822'});
6543 -type
=> $content_type,
6544 -charset
=> 'utf-8');
6547 # Optimization: skip generating the body if client asks only
6548 # for Last-Modified date.
6549 return if ($cgi->request_method() eq 'HEAD');
6552 my $title = "$site_name - $project/$action";
6553 my $feed_type = 'log';
6554 if (defined $hash) {
6555 $title .= " - '$hash'";
6556 $feed_type = 'branch log';
6557 if (defined $file_name) {
6558 $title .= " :: $file_name";
6559 $feed_type = 'history';
6561 } elsif (defined $file_name) {
6562 $title .= " - $file_name";
6563 $feed_type = 'history';
6565 $title .= " $feed_type";
6566 my $descr = git_get_project_description
($project);
6567 if (defined $descr) {
6568 $descr = esc_html
($descr);
6570 $descr = "$project " .
6571 ($format eq 'rss' ? 'RSS' : 'Atom') .
6574 my $owner = git_get_project_owner
($project);
6575 $owner = esc_html
($owner);
6579 if (defined $file_name) {
6580 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6581 } elsif (defined $hash) {
6582 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6584 $alt_url = href
(-full
=>1, action
=>"summary");
6586 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6587 if ($format eq 'rss') {
6589 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6592 print "<title>$title</title>\n" .
6593 "<link>$alt_url</link>\n" .
6594 "<description>$descr</description>\n" .
6595 "<language>en</language>\n" .
6596 # project owner is responsible for 'editorial' content
6597 "<managingEditor>$owner</managingEditor>\n";
6598 if (defined $logo || defined $favicon) {
6599 # prefer the logo to the favicon, since RSS
6600 # doesn't allow both
6601 my $img = esc_url
($logo || $favicon);
6603 "<url>$img</url>\n" .
6604 "<title>$title</title>\n" .
6605 "<link>$alt_url</link>\n" .
6609 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6610 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6612 print "<generator>gitweb v.$version/$git_version</generator>\n";
6613 } elsif ($format eq 'atom') {
6615 <feed xmlns="http://www.w3.org/2005/Atom">
6617 print "<title>$title</title>\n" .
6618 "<subtitle>$descr</subtitle>\n" .
6619 '<link rel="alternate" type="text/html" href="' .
6620 $alt_url . '" />' . "\n" .
6621 '<link rel="self" type="' . $content_type . '" href="' .
6622 $cgi->self_url() . '" />' . "\n" .
6623 "<id>" . href
(-full
=>1) . "</id>\n" .
6624 # use project owner for feed author
6625 "<author><name>$owner</name></author>\n";
6626 if (defined $favicon) {
6627 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6629 if (defined $logo_url) {
6630 # not twice as wide as tall: 72 x 27 pixels
6631 print "<logo>" . esc_url
($logo) . "</logo>\n";
6633 if (! %latest_date) {
6634 # dummy date to keep the feed valid until commits trickle in:
6635 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6637 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6639 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6643 for (my $i = 0; $i <= $#commitlist; $i++) {
6644 my %co = %{$commitlist[$i]};
6645 my $commit = $co{'id'};
6646 # we read 150, we always show 30 and the ones more recent than 48 hours
6647 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6650 my %cd = parse_date
($co{'author_epoch'});
6652 # get list of changed files
6653 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6654 $co{'parent'} || "--root",
6655 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6657 my @difftree = map { chomp; $_ } <$fd>;
6661 # print element (entry, item)
6662 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6663 if ($format eq 'rss') {
6665 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6666 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6667 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6668 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6669 "<link>$co_url</link>\n" .
6670 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6671 "<content:encoded>" .
6673 } elsif ($format eq 'atom') {
6675 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6676 "<updated>$cd{'iso-8601'}</updated>\n" .
6678 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6679 if ($co{'author_email'}) {
6680 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6682 print "</author>\n" .
6683 # use committer for contributor
6685 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6686 if ($co{'committer_email'}) {
6687 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6689 print "</contributor>\n" .
6690 "<published>$cd{'iso-8601'}</published>\n" .
6691 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6692 "<id>$co_url</id>\n" .
6693 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6694 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6696 my $comment = $co{'comment'};
6698 foreach my $line (@$comment) {
6699 $line = esc_html
($line);
6702 print "</pre><ul>\n";
6703 foreach my $difftree_line (@difftree) {
6704 my %difftree = parse_difftree_raw_line
($difftree_line);
6705 next if !$difftree{'from_id'};
6707 my $file = $difftree{'file'} || $difftree{'to_file'};
6711 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6712 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6713 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6714 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6715 -title
=> "diff"}, 'D');
6717 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6718 file_name
=>$file, hash_base
=>$commit),
6719 -title
=> "blame"}, 'B');
6721 # if this is not a feed of a file history
6722 if (!defined $file_name || $file_name ne $file) {
6723 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6724 file_name
=>$file, hash
=>$commit),
6725 -title
=> "history"}, 'H');
6727 $file = esc_path
($file);
6731 if ($format eq 'rss') {
6732 print "</ul>]]>\n" .
6733 "</content:encoded>\n" .
6735 } elsif ($format eq 'atom') {
6736 print "</ul>\n</div>\n" .
6743 if ($format eq 'rss') {
6744 print "</channel>\n</rss>\n";
6745 } elsif ($format eq 'atom') {
6759 my @list = git_get_projects_list
();
6762 -type
=> 'text/xml',
6763 -charset
=> 'utf-8',
6764 -content_disposition
=> 'inline; filename="opml.xml"');
6767 <?xml version="1.0" encoding="utf-8"?>
6768 <opml version="1.0">
6770 <title>$site_name OPML Export</title>
6773 <outline text="git RSS feeds">
6776 foreach my $pr (@list) {
6778 my $head = git_get_head_hash
($proj{'path'});
6779 if (!defined $head) {
6782 $git_dir = "$projectroot/$proj{'path'}";
6783 my %co = parse_commit
($head);
6788 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6789 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6790 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6791 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";