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;
95 # URI of GIT logo (72x27 size)
96 our $logo = "++GITWEB_LOGO++";
97 # URI of GIT favicon, assumed to be image/png type
98 our $favicon = "++GITWEB_FAVICON++";
99 # URI of gitweb.js (JavaScript code for gitweb)
100 our $javascript = "++GITWEB_JS++";
102 # URI and label (title) of GIT logo link
103 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
104 #our $logo_label = "git documentation";
105 our $logo_url = "http://git-scm.com/";
106 our $logo_label = "git homepage";
108 # source of projects list
109 our $projects_list = "++GITWEB_LIST++";
111 # the width (in characters) of the projects list "Description" column
112 our $projects_list_description_width = 25;
114 # default order of projects list
115 # valid values are none, project, descr, owner, and age
116 our $default_projects_order = "project";
118 # show repository only if this file exists
119 # (only effective if this variable evaluates to true)
120 our $export_ok = "++GITWEB_EXPORT_OK++";
122 # show repository only if this subroutine returns true
123 # when given the path to the project, for example:
124 # sub { return -e "$_[0]/git-daemon-export-ok"; }
125 our $export_auth_hook = undef;
127 # only allow viewing of repositories also shown on the overview page
128 our $strict_export = "++GITWEB_STRICT_EXPORT++";
130 # list of git base URLs used for URL to where fetch project from,
131 # i.e. full URL is "$git_base_url/$project"
132 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
134 # default blob_plain mimetype and default charset for text/plain blob
135 our $default_blob_plain_mimetype = 'text/plain';
136 our $default_text_plain_charset = undef;
138 # file to use for guessing MIME types before trying /etc/mime.types
139 # (relative to the current git repository)
140 our $mimetypes_file = undef;
142 # assume this charset if line contains non-UTF-8 characters;
143 # it should be valid encoding (see Encoding::Supported(3pm) for list),
144 # for which encoding all byte sequences are valid, for example
145 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
146 # could be even 'utf-8' for the old behavior)
147 our $fallback_encoding = 'latin1';
149 # rename detection options for git-diff and git-diff-tree
150 # - default is '-M', with the cost proportional to
151 # (number of removed files) * (number of new files).
152 # - more costly is '-C' (which implies '-M'), with the cost proportional to
153 # (number of changed files + number of removed files) * (number of new files)
154 # - even more costly is '-C', '--find-copies-harder' with cost
155 # (number of files in the original tree) * (number of new files)
156 # - one might want to include '-B' option, e.g. '-B', '-M'
157 our @diff_opts = ('-M'); # taken from git_commit
159 # Disables features that would allow repository owners to inject script into
161 our $prevent_xss = 0;
163 # information about snapshot formats that gitweb is capable of serving
164 our %known_snapshot_formats = (
166 # 'display' => display name,
167 # 'type' => mime type,
168 # 'suffix' => filename suffix,
169 # 'format' => --format for git-archive,
170 # 'compressor' => [compressor command and arguments]
171 # (array reference, optional)
172 # 'disabled' => boolean (optional)}
175 'display' => 'tar.gz',
176 'type' => 'application/x-gzip',
177 'suffix' => '.tar.gz',
179 'compressor' => ['gzip']},
182 'display' => 'tar.bz2',
183 'type' => 'application/x-bzip2',
184 'suffix' => '.tar.bz2',
186 'compressor' => ['bzip2']},
189 'display' => 'tar.xz',
190 'type' => 'application/x-xz',
191 'suffix' => '.tar.xz',
193 'compressor' => ['xz'],
198 'type' => 'application/x-zip',
203 # Aliases so we understand old gitweb.snapshot values in repository
205 our %known_snapshot_format_aliases = (
210 # backward compatibility: legacy gitweb config support
211 'x-gzip' => undef, 'gz' => undef,
212 'x-bzip2' => undef, 'bz2' => undef,
213 'x-zip' => undef, '' => undef,
216 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
217 # are changed, it may be appropriate to change these values too via
224 # Used to set the maximum load that we will still respond to gitweb queries.
225 # If server load exceed this value then return "503 server busy" error.
226 # If gitweb cannot determined server load, it is taken to be 0.
227 # Leave it undefined (or set to 'undef') to turn off load checking.
230 # You define site-wide feature defaults here; override them with
231 # $GITWEB_CONFIG as necessary.
234 # 'sub' => feature-sub (subroutine),
235 # 'override' => allow-override (boolean),
236 # 'default' => [ default options...] (array reference)}
238 # if feature is overridable (it means that allow-override has true value),
239 # then feature-sub will be called with default options as parameters;
240 # return value of feature-sub indicates if to enable specified feature
242 # if there is no 'sub' key (no feature-sub), then feature cannot be
245 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
246 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
249 # Enable the 'blame' blob view, showing the last commit that modified
250 # each line in the file. This can be very CPU-intensive.
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'blame'}{'default'} = [1];
254 # To have project specific config enable override in $GITWEB_CONFIG
255 # $feature{'blame'}{'override'} = 1;
256 # and in project config gitweb.blame = 0|1;
258 'sub' => sub { feature_bool
('blame', @_) },
262 # Enable the 'snapshot' link, providing a compressed archive of any
263 # tree. This can potentially generate high traffic if you have large
266 # Value is a list of formats defined in %known_snapshot_formats that
268 # To disable system wide have in $GITWEB_CONFIG
269 # $feature{'snapshot'}{'default'} = [];
270 # To have project specific config enable override in $GITWEB_CONFIG
271 # $feature{'snapshot'}{'override'} = 1;
272 # and in project config, a comma-separated list of formats or "none"
273 # to disable. Example: gitweb.snapshot = tbz2,zip;
275 'sub' => \
&feature_snapshot
,
277 'default' => ['tgz']},
279 # Enable text search, which will list the commits which match author,
280 # committer or commit text to a given string. Enabled by default.
281 # Project specific override is not supported.
286 # Enable grep search, which will list the files in currently selected
287 # tree containing the given string. Enabled by default. This can be
288 # potentially CPU-intensive, of course.
290 # To enable system wide have in $GITWEB_CONFIG
291 # $feature{'grep'}{'default'} = [1];
292 # To have project specific config enable override in $GITWEB_CONFIG
293 # $feature{'grep'}{'override'} = 1;
294 # and in project config gitweb.grep = 0|1;
296 'sub' => sub { feature_bool
('grep', @_) },
300 # Enable the pickaxe search, which will list the commits that modified
301 # a given string in a file. This can be practical and quite faster
302 # alternative to 'blame', but still potentially CPU-intensive.
304 # To enable system wide have in $GITWEB_CONFIG
305 # $feature{'pickaxe'}{'default'} = [1];
306 # To have project specific config enable override in $GITWEB_CONFIG
307 # $feature{'pickaxe'}{'override'} = 1;
308 # and in project config gitweb.pickaxe = 0|1;
310 'sub' => sub { feature_bool
('pickaxe', @_) },
314 # Enable showing size of blobs in a 'tree' view, in a separate
315 # column, similar to what 'ls -l' does. This cost a bit of IO.
317 # To disable system wide have in $GITWEB_CONFIG
318 # $feature{'show-sizes'}{'default'} = [0];
319 # To have project specific config enable override in $GITWEB_CONFIG
320 # $feature{'show-sizes'}{'override'} = 1;
321 # and in project config gitweb.showsizes = 0|1;
323 'sub' => sub { feature_bool
('showsizes', @_) },
327 # Make gitweb use an alternative format of the URLs which can be
328 # more readable and natural-looking: project name is embedded
329 # directly in the path and the query string contains other
330 # auxiliary information. All gitweb installations recognize
331 # URL in either format; this configures in which formats gitweb
334 # To enable system wide have in $GITWEB_CONFIG
335 # $feature{'pathinfo'}{'default'} = [1];
336 # Project specific override is not supported.
338 # Note that you will need to change the default location of CSS,
339 # favicon, logo and possibly other files to an absolute URL. Also,
340 # if gitweb.cgi serves as your indexfile, you will need to force
341 # $my_uri to contain the script name in your $GITWEB_CONFIG.
346 # Make gitweb consider projects in project root subdirectories
347 # to be forks of existing projects. Given project $projname.git,
348 # projects matching $projname/*.git will not be shown in the main
349 # projects list, instead a '+' mark will be added to $projname
350 # there and a 'forks' view will be enabled for the project, listing
351 # all the forks. If project list is taken from a file, forks have
352 # to be listed after the main project.
354 # To enable system wide have in $GITWEB_CONFIG
355 # $feature{'forks'}{'default'} = [1];
356 # Project specific override is not supported.
361 # Insert custom links to the action bar of all project pages.
362 # This enables you mainly to link to third-party scripts integrating
363 # into gitweb; e.g. git-browser for graphical history representation
364 # or custom web-based repository administration interface.
366 # The 'default' value consists of a list of triplets in the form
367 # (label, link, position) where position is the label after which
368 # to insert the link and link is a format string where %n expands
369 # to the project name, %f to the project path within the filesystem,
370 # %h to the current hash (h gitweb parameter) and %b to the current
371 # hash base (hb gitweb parameter); %% expands to %.
373 # To enable system wide have in $GITWEB_CONFIG e.g.
374 # $feature{'actions'}{'default'} = [('graphiclog',
375 # '/git-browser/by-commit.html?r=%n', 'summary')];
376 # Project specific override is not supported.
381 # Allow gitweb scan project content tags described in ctags/
382 # of project repository, and display the popular Web 2.0-ish
383 # "tag cloud" near the project list. Note that this is something
384 # COMPLETELY different from the normal Git tags.
386 # gitweb by itself can show existing tags, but it does not handle
387 # tagging itself; you need an external application for that.
388 # For an example script, check Girocco's cgi/tagproj.cgi.
389 # You may want to install the HTML::TagCloud Perl module to get
390 # a pretty tag cloud instead of just a list of tags.
392 # To enable system wide have in $GITWEB_CONFIG
393 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
394 # Project specific override is not supported.
399 # The maximum number of patches in a patchset generated in patch
400 # view. Set this to 0 or undef to disable patch view, or to a
401 # negative number to remove any limit.
403 # To disable system wide have in $GITWEB_CONFIG
404 # $feature{'patches'}{'default'} = [0];
405 # To have project specific config enable override in $GITWEB_CONFIG
406 # $feature{'patches'}{'override'} = 1;
407 # and in project config gitweb.patches = 0|n;
408 # where n is the maximum number of patches allowed in a patchset.
410 'sub' => \
&feature_patches
,
414 # Avatar support. When this feature is enabled, views such as
415 # shortlog or commit will display an avatar associated with
416 # the email of the committer(s) and/or author(s).
418 # Currently available providers are gravatar and picon.
419 # If an unknown provider is specified, the feature is disabled.
421 # Gravatar depends on Digest::MD5.
422 # Picon currently relies on the indiana.edu database.
424 # To enable system wide have in $GITWEB_CONFIG
425 # $feature{'avatar'}{'default'} = ['<provider>'];
426 # where <provider> is either gravatar or picon.
427 # To have project specific config enable override in $GITWEB_CONFIG
428 # $feature{'avatar'}{'override'} = 1;
429 # and in project config gitweb.avatar = <provider>;
431 'sub' => \
&feature_avatar
,
435 # Enable displaying how much time and how many git commands
436 # it took to generate and display page. Disabled by default.
437 # Project specific override is not supported.
442 # Enable turning some links into links to actions which require
443 # JavaScript to run (like 'blame_incremental'). Not enabled by
444 # default. Project specific override is currently not supported.
445 'javascript-actions' => {
450 sub gitweb_get_feature
{
452 return unless exists $feature{$name};
453 my ($sub, $override, @defaults) = (
454 $feature{$name}{'sub'},
455 $feature{$name}{'override'},
456 @
{$feature{$name}{'default'}});
457 # project specific override is possible only if we have project
458 our $git_dir; # global variable, declared later
459 if (!$override || !defined $git_dir) {
463 warn "feature $name is not overridable";
466 return $sub->(@defaults);
469 # A wrapper to check if a given feature is enabled.
470 # With this, you can say
472 # my $bool_feat = gitweb_check_feature('bool_feat');
473 # gitweb_check_feature('bool_feat') or somecode;
477 # my ($bool_feat) = gitweb_get_feature('bool_feat');
478 # (gitweb_get_feature('bool_feat'))[0] or somecode;
480 sub gitweb_check_feature
{
481 return (gitweb_get_feature
(@_))[0];
487 my ($val) = git_get_project_config
($key, '--bool');
491 } elsif ($val eq 'true') {
493 } elsif ($val eq 'false') {
498 sub feature_snapshot
{
501 my ($val) = git_get_project_config
('snapshot');
504 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
510 sub feature_patches
{
511 my @val = (git_get_project_config
('patches', '--int'));
521 my @val = (git_get_project_config
('avatar'));
523 return @val ?
@val : @_;
526 # checking HEAD file with -e is fragile if the repository was
527 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
529 sub check_head_link
{
531 my $headfile = "$dir/HEAD";
532 return ((-e
$headfile) ||
533 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
536 sub check_export_ok
{
538 return (check_head_link
($dir) &&
539 (!$export_ok || -e
"$dir/$export_ok") &&
540 (!$export_auth_hook || $export_auth_hook->($dir)));
543 # process alternate names for backward compatibility
544 # filter out unsupported (unknown) snapshot formats
545 sub filter_snapshot_fmts
{
549 exists $known_snapshot_format_aliases{$_} ?
550 $known_snapshot_format_aliases{$_} : $_} @fmts;
552 exists $known_snapshot_formats{$_} &&
553 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
556 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
557 if (-e
$GITWEB_CONFIG) {
560 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
561 do $GITWEB_CONFIG_SYSTEM if -e
$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 if (utf8
::valid
($str)) {
1154 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1158 # quote unsafe chars, but keep the slash, even when it's not
1159 # correct, but quoted slashes look too horrible in bookmarks
1162 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1167 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1170 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1176 # replace invalid utf8 character with SUBSTITUTION sequence
1181 $str = to_utf8
($str);
1182 $str = $cgi->escapeHTML($str);
1183 if ($opts{'-nbsp'}) {
1184 $str =~ s/ / /g;
1186 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1190 # quote control characters and escape filename to HTML
1195 $str = to_utf8
($str);
1196 $str = $cgi->escapeHTML($str);
1197 if ($opts{'-nbsp'}) {
1198 $str =~ s/ / /g;
1200 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1204 # Make control characters "printable", using character escape codes (CEC)
1208 my %es = ( # character escape codes, aka escape sequences
1209 "\t" => '\t', # tab (HT)
1210 "\n" => '\n', # line feed (LF)
1211 "\r" => '\r', # carrige return (CR)
1212 "\f" => '\f', # form feed (FF)
1213 "\b" => '\b', # backspace (BS)
1214 "\a" => '\a', # alarm (bell) (BEL)
1215 "\e" => '\e', # escape (ESC)
1216 "\013" => '\v', # vertical tab (VT)
1217 "\000" => '\0', # nul character (NUL)
1219 my $chr = ( (exists $es{$cntrl})
1221 : sprintf('\%2x', ord($cntrl)) );
1222 if ($opts{-nohtml
}) {
1225 return "<span class=\"cntrl\">$chr</span>";
1229 # Alternatively use unicode control pictures codepoints,
1230 # Unicode "printable representation" (PR)
1235 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1236 if ($opts{-nohtml
}) {
1239 return "<span class=\"cntrl\">$chr</span>";
1243 # git may return quoted and escaped filenames
1249 my %es = ( # character escape codes, aka escape sequences
1250 't' => "\t", # tab (HT, TAB)
1251 'n' => "\n", # newline (NL)
1252 'r' => "\r", # return (CR)
1253 'f' => "\f", # form feed (FF)
1254 'b' => "\b", # backspace (BS)
1255 'a' => "\a", # alarm (bell) (BEL)
1256 'e' => "\e", # escape (ESC)
1257 'v' => "\013", # vertical tab (VT)
1260 if ($seq =~ m/^[0-7]{1,3}$/) {
1261 # octal char sequence
1262 return chr(oct($seq));
1263 } elsif (exists $es{$seq}) {
1264 # C escape sequence, aka character escape code
1267 # quoted ordinary character
1271 if ($str =~ m/^"(.*)"$/) {
1274 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1279 # escape tabs (convert tabs to spaces)
1283 while ((my $pos = index($line, "\t")) != -1) {
1284 if (my $count = (8 - ($pos % 8))) {
1285 my $spaces = ' ' x
$count;
1286 $line =~ s/\t/$spaces/;
1293 sub project_in_list
{
1294 my $project = shift;
1295 my @list = git_get_projects_list
();
1296 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1299 ## ----------------------------------------------------------------------
1300 ## HTML aware string manipulation
1302 # Try to chop given string on a word boundary between position
1303 # $len and $len+$add_len. If there is no word boundary there,
1304 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1305 # (marking chopped part) would be longer than given string.
1309 my $add_len = shift || 10;
1310 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1312 # Make sure perl knows it is utf8 encoded so we don't
1313 # cut in the middle of a utf8 multibyte char.
1314 $str = to_utf8
($str);
1316 # allow only $len chars, but don't cut a word if it would fit in $add_len
1317 # if it doesn't fit, cut it if it's still longer than the dots we would add
1318 # remove chopped character entities entirely
1320 # when chopping in the middle, distribute $len into left and right part
1321 # return early if chopping wouldn't make string shorter
1322 if ($where eq 'center') {
1323 return $str if ($len + 5 >= length($str)); # filler is length 5
1326 return $str if ($len + 4 >= length($str)); # filler is length 4
1329 # regexps: ending and beginning with word part up to $add_len
1330 my $endre = qr/.{$len}\w{0,$add_len}/;
1331 my $begre = qr/\w{0,$add_len}.{$len}/;
1333 if ($where eq 'left') {
1334 $str =~ m/^(.*?)($begre)$/;
1335 my ($lead, $body) = ($1, $2);
1336 if (length($lead) > 4) {
1339 return "$lead$body";
1341 } elsif ($where eq 'center') {
1342 $str =~ m/^($endre)(.*)$/;
1343 my ($left, $str) = ($1, $2);
1344 $str =~ m/^(.*?)($begre)$/;
1345 my ($mid, $right) = ($1, $2);
1346 if (length($mid) > 5) {
1349 return "$left$mid$right";
1352 $str =~ m/^($endre)(.*)$/;
1355 if (length($tail) > 4) {
1358 return "$body$tail";
1362 # takes the same arguments as chop_str, but also wraps a <span> around the
1363 # result with a title attribute if it does get chopped. Additionally, the
1364 # string is HTML-escaped.
1365 sub chop_and_escape_str
{
1368 my $chopped = chop_str
(@_);
1369 if ($chopped eq $str) {
1370 return esc_html
($chopped);
1372 $str =~ s/[[:cntrl:]]/?/g;
1373 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1377 ## ----------------------------------------------------------------------
1378 ## functions returning short strings
1380 # CSS class for given age value (in seconds)
1384 if (!defined $age) {
1386 } elsif ($age < 60*60*2) {
1388 } elsif ($age < 60*60*24*2) {
1395 # convert age in seconds to "nn units ago" string
1400 if ($age > 60*60*24*365*2) {
1401 $age_str = (int $age/60/60/24/365);
1402 $age_str .= " years ago";
1403 } elsif ($age > 60*60*24*(365/12)*2) {
1404 $age_str = int $age/60/60/24/(365/12);
1405 $age_str .= " months ago";
1406 } elsif ($age > 60*60*24*7*2) {
1407 $age_str = int $age/60/60/24/7;
1408 $age_str .= " weeks ago";
1409 } elsif ($age > 60*60*24*2) {
1410 $age_str = int $age/60/60/24;
1411 $age_str .= " days ago";
1412 } elsif ($age > 60*60*2) {
1413 $age_str = int $age/60/60;
1414 $age_str .= " hours ago";
1415 } elsif ($age > 60*2) {
1416 $age_str = int $age/60;
1417 $age_str .= " min ago";
1418 } elsif ($age > 2) {
1419 $age_str = int $age;
1420 $age_str .= " sec ago";
1422 $age_str .= " right now";
1428 S_IFINVALID
=> 0030000,
1429 S_IFGITLINK
=> 0160000,
1432 # submodule/subproject, a commit object reference
1436 return (($mode & S_IFMT
) == S_IFGITLINK
)
1439 # convert file mode in octal to symbolic file mode string
1441 my $mode = oct shift;
1443 if (S_ISGITLINK
($mode)) {
1444 return 'm---------';
1445 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1446 return 'drwxr-xr-x';
1447 } elsif (S_ISLNK
($mode)) {
1448 return 'lrwxrwxrwx';
1449 } elsif (S_ISREG
($mode)) {
1450 # git cares only about the executable bit
1451 if ($mode & S_IXUSR
) {
1452 return '-rwxr-xr-x';
1454 return '-rw-r--r--';
1457 return '----------';
1461 # convert file mode in octal to file type string
1465 if ($mode !~ m/^[0-7]+$/) {
1471 if (S_ISGITLINK
($mode)) {
1473 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1475 } elsif (S_ISLNK
($mode)) {
1477 } elsif (S_ISREG
($mode)) {
1484 # convert file mode in octal to file type description string
1485 sub file_type_long
{
1488 if ($mode !~ m/^[0-7]+$/) {
1494 if (S_ISGITLINK
($mode)) {
1496 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1498 } elsif (S_ISLNK
($mode)) {
1500 } elsif (S_ISREG
($mode)) {
1501 if ($mode & S_IXUSR
) {
1502 return "executable";
1512 ## ----------------------------------------------------------------------
1513 ## functions returning short HTML fragments, or transforming HTML fragments
1514 ## which don't belong to other sections
1516 # format line of commit message.
1517 sub format_log_line_html
{
1520 $line = esc_html
($line, -nbsp
=>1);
1521 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1522 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1523 -class => "text"}, $1);
1529 # format marker of refs pointing to given object
1531 # the destination action is chosen based on object type and current context:
1532 # - for annotated tags, we choose the tag view unless it's the current view
1533 # already, in which case we go to shortlog view
1534 # - for other refs, we keep the current view if we're in history, shortlog or
1535 # log view, and select shortlog otherwise
1536 sub format_ref_marker
{
1537 my ($refs, $id) = @_;
1540 if (defined $refs->{$id}) {
1541 foreach my $ref (@
{$refs->{$id}}) {
1542 # this code exploits the fact that non-lightweight tags are the
1543 # only indirect objects, and that they are the only objects for which
1544 # we want to use tag instead of shortlog as action
1545 my ($type, $name) = qw();
1546 my $indirect = ($ref =~ s/\^\{\}$//);
1547 # e.g. tags/v2.6.11 or heads/next
1548 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1557 $class .= " indirect" if $indirect;
1559 my $dest_action = "shortlog";
1562 $dest_action = "tag" unless $action eq "tag";
1563 } elsif ($action =~ /^(history|(short)?log)$/) {
1564 $dest_action = $action;
1568 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1571 my $link = $cgi->a({
1573 action
=>$dest_action,
1577 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1583 return ' <span class="refs">'. $markers . '</span>';
1589 # format, perhaps shortened and with markers, title line
1590 sub format_subject_html
{
1591 my ($long, $short, $href, $extra) = @_;
1592 $extra = '' unless defined($extra);
1594 if (length($short) < length($long)) {
1595 $long =~ s/[[:cntrl:]]/?/g;
1596 return $cgi->a({-href
=> $href, -class => "list subject",
1597 -title
=> to_utf8
($long)},
1598 esc_html
($short)) . $extra;
1600 return $cgi->a({-href
=> $href, -class => "list subject"},
1601 esc_html
($long)) . $extra;
1605 # Rather than recomputing the url for an email multiple times, we cache it
1606 # after the first hit. This gives a visible benefit in views where the avatar
1607 # for the same email is used repeatedly (e.g. shortlog).
1608 # The cache is shared by all avatar engines (currently gravatar only), which
1609 # are free to use it as preferred. Since only one avatar engine is used for any
1610 # given page, there's no risk for cache conflicts.
1611 our %avatar_cache = ();
1613 # Compute the picon url for a given email, by using the picon search service over at
1614 # http://www.cs.indiana.edu/picons/search.html
1616 my $email = lc shift;
1617 if (!$avatar_cache{$email}) {
1618 my ($user, $domain) = split('@', $email);
1619 $avatar_cache{$email} =
1620 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1622 "users+domains+unknown/up/single";
1624 return $avatar_cache{$email};
1627 # Compute the gravatar url for a given email, if it's not in the cache already.
1628 # Gravatar stores only the part of the URL before the size, since that's the
1629 # one computationally more expensive. This also allows reuse of the cache for
1630 # different sizes (for this particular engine).
1632 my $email = lc shift;
1634 $avatar_cache{$email} ||=
1635 "http://www.gravatar.com/avatar/" .
1636 Digest
::MD5
::md5_hex
($email) . "?s=";
1637 return $avatar_cache{$email} . $size;
1640 # Insert an avatar for the given $email at the given $size if the feature
1642 sub git_get_avatar
{
1643 my ($email, %opts) = @_;
1644 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1645 my $post_white = ($opts{-pad_after
} ?
" " : "");
1646 $opts{-size
} ||= 'default';
1647 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1649 if ($git_avatar eq 'gravatar') {
1650 $url = gravatar_url
($email, $size);
1651 } elsif ($git_avatar eq 'picon') {
1652 $url = picon_url
($email);
1654 # Other providers can be added by extending the if chain, defining $url
1655 # as needed. If no variant puts something in $url, we assume avatars
1656 # are completely disabled/unavailable.
1659 "<img width=\"$size\" " .
1660 "class=\"avatar\" " .
1669 sub format_search_author
{
1670 my ($author, $searchtype, $displaytext) = @_;
1671 my $have_search = gitweb_check_feature
('search');
1675 if ($searchtype eq 'author') {
1676 $performed = "authored";
1677 } elsif ($searchtype eq 'committer') {
1678 $performed = "committed";
1681 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1682 searchtext
=>$author,
1683 searchtype
=>$searchtype), class=>"list",
1684 title
=>"Search for commits $performed by $author"},
1688 return $displaytext;
1692 # format the author name of the given commit with the given tag
1693 # the author name is chopped and escaped according to the other
1694 # optional parameters (see chop_str).
1695 sub format_author_html
{
1698 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1699 return "<$tag class=\"author\">" .
1700 format_search_author
($co->{'author_name'}, "author",
1701 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1706 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1707 sub format_git_diff_header_line
{
1709 my $diffinfo = shift;
1710 my ($from, $to) = @_;
1712 if ($diffinfo->{'nparents'}) {
1714 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1715 if ($to->{'href'}) {
1716 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1717 esc_path
($to->{'file'}));
1718 } else { # file was deleted (no href)
1719 $line .= esc_path
($to->{'file'});
1723 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1724 if ($from->{'href'}) {
1725 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1726 'a/' . esc_path
($from->{'file'}));
1727 } else { # file was added (no href)
1728 $line .= 'a/' . esc_path
($from->{'file'});
1731 if ($to->{'href'}) {
1732 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1733 'b/' . esc_path
($to->{'file'}));
1734 } else { # file was deleted
1735 $line .= 'b/' . esc_path
($to->{'file'});
1739 return "<div class=\"diff header\">$line</div>\n";
1742 # format extended diff header line, before patch itself
1743 sub format_extended_diff_header_line
{
1745 my $diffinfo = shift;
1746 my ($from, $to) = @_;
1749 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1750 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1751 esc_path
($from->{'file'}));
1753 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1754 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1755 esc_path
($to->{'file'}));
1757 # match single <mode>
1758 if ($line =~ m/\s(\d{6})$/) {
1759 $line .= '<span class="info"> (' .
1760 file_type_long
($1) .
1764 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1765 # can match only for combined diff
1767 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1768 if ($from->{'href'}[$i]) {
1769 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1771 substr($diffinfo->{'from_id'}[$i],0,7));
1776 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1779 if ($to->{'href'}) {
1780 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1781 substr($diffinfo->{'to_id'},0,7));
1786 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1787 # can match only for ordinary diff
1788 my ($from_link, $to_link);
1789 if ($from->{'href'}) {
1790 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1791 substr($diffinfo->{'from_id'},0,7));
1793 $from_link = '0' x
7;
1795 if ($to->{'href'}) {
1796 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1797 substr($diffinfo->{'to_id'},0,7));
1801 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1802 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1805 return $line . "<br/>\n";
1808 # format from-file/to-file diff header
1809 sub format_diff_from_to_header
{
1810 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1815 #assert($line =~ m/^---/) if DEBUG;
1816 # no extra formatting for "^--- /dev/null"
1817 if (! $diffinfo->{'nparents'}) {
1818 # ordinary (single parent) diff
1819 if ($line =~ m!^--- "?a/!) {
1820 if ($from->{'href'}) {
1822 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1823 esc_path
($from->{'file'}));
1826 esc_path
($from->{'file'});
1829 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1832 # combined diff (merge commit)
1833 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1834 if ($from->{'href'}[$i]) {
1836 $cgi->a({-href
=>href
(action
=>"blobdiff",
1837 hash_parent
=>$diffinfo->{'from_id'}[$i],
1838 hash_parent_base
=>$parents[$i],
1839 file_parent
=>$from->{'file'}[$i],
1840 hash
=>$diffinfo->{'to_id'},
1842 file_name
=>$to->{'file'}),
1844 -title
=>"diff" . ($i+1)},
1847 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1848 esc_path
($from->{'file'}[$i]));
1850 $line = '--- /dev/null';
1852 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1857 #assert($line =~ m/^\+\+\+/) if DEBUG;
1858 # no extra formatting for "^+++ /dev/null"
1859 if ($line =~ m!^\+\+\+ "?b/!) {
1860 if ($to->{'href'}) {
1862 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1863 esc_path
($to->{'file'}));
1866 esc_path
($to->{'file'});
1869 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1874 # create note for patch simplified by combined diff
1875 sub format_diff_cc_simplified
{
1876 my ($diffinfo, @parents) = @_;
1879 $result .= "<div class=\"diff header\">" .
1881 if (!is_deleted
($diffinfo)) {
1882 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1884 hash
=>$diffinfo->{'to_id'},
1885 file_name
=>$diffinfo->{'to_file'}),
1887 esc_path
($diffinfo->{'to_file'}));
1889 $result .= esc_path
($diffinfo->{'to_file'});
1891 $result .= "</div>\n" . # class="diff header"
1892 "<div class=\"diff nodifferences\">" .
1894 "</div>\n"; # class="diff nodifferences"
1899 # format patch (diff) line (not to be used for diff headers)
1900 sub format_diff_line
{
1902 my ($from, $to) = @_;
1903 my $diff_class = "";
1907 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1909 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1910 if ($line =~ m/^\@{3}/) {
1911 $diff_class = " chunk_header";
1912 } elsif ($line =~ m/^\\/) {
1913 $diff_class = " incomplete";
1914 } elsif ($prefix =~ tr/+/+/) {
1915 $diff_class = " add";
1916 } elsif ($prefix =~ tr/-/-/) {
1917 $diff_class = " rem";
1920 # assume ordinary diff
1921 my $char = substr($line, 0, 1);
1923 $diff_class = " add";
1924 } elsif ($char eq '-') {
1925 $diff_class = " rem";
1926 } elsif ($char eq '@') {
1927 $diff_class = " chunk_header";
1928 } elsif ($char eq "\\") {
1929 $diff_class = " incomplete";
1932 $line = untabify
($line);
1933 if ($from && $to && $line =~ m/^\@{2} /) {
1934 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1935 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1937 $from_lines = 0 unless defined $from_lines;
1938 $to_lines = 0 unless defined $to_lines;
1940 if ($from->{'href'}) {
1941 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1942 -class=>"list"}, $from_text);
1944 if ($to->{'href'}) {
1945 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1946 -class=>"list"}, $to_text);
1948 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1949 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1950 return "<div class=\"diff$diff_class\">$line</div>\n";
1951 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1952 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1953 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1955 @from_text = split(' ', $ranges);
1956 for (my $i = 0; $i < @from_text; ++$i) {
1957 ($from_start[$i], $from_nlines[$i]) =
1958 (split(',', substr($from_text[$i], 1)), 0);
1961 $to_text = pop @from_text;
1962 $to_start = pop @from_start;
1963 $to_nlines = pop @from_nlines;
1965 $line = "<span class=\"chunk_info\">$prefix ";
1966 for (my $i = 0; $i < @from_text; ++$i) {
1967 if ($from->{'href'}[$i]) {
1968 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1969 -class=>"list"}, $from_text[$i]);
1971 $line .= $from_text[$i];
1975 if ($to->{'href'}) {
1976 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1977 -class=>"list"}, $to_text);
1981 $line .= " $prefix</span>" .
1982 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1983 return "<div class=\"diff$diff_class\">$line</div>\n";
1985 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1988 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1989 # linked. Pass the hash of the tree/commit to snapshot.
1990 sub format_snapshot_links
{
1992 my $num_fmts = @snapshot_fmts;
1993 if ($num_fmts > 1) {
1994 # A parenthesized list of links bearing format names.
1995 # e.g. "snapshot (_tar.gz_ _zip_)"
1996 return "snapshot (" . join(' ', map
2003 }, $known_snapshot_formats{$_}{'display'})
2004 , @snapshot_fmts) . ")";
2005 } elsif ($num_fmts == 1) {
2006 # A single "snapshot" link whose tooltip bears the format name.
2008 my ($fmt) = @snapshot_fmts;
2014 snapshot_format
=>$fmt
2016 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
2018 } else { # $num_fmts == 0
2023 ## ......................................................................
2024 ## functions returning values to be passed, perhaps after some
2025 ## transformation, to other functions; e.g. returning arguments to href()
2027 # returns hash to be passed to href to generate gitweb URL
2028 # in -title key it returns description of link
2030 my $format = shift || 'Atom';
2031 my %res = (action
=> lc($format));
2033 # feed links are possible only for project views
2034 return unless (defined $project);
2035 # some views should link to OPML, or to generic project feed,
2036 # or don't have specific feed yet (so they should use generic)
2037 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2040 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2041 # from tag links; this also makes possible to detect branch links
2042 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2043 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2046 # find log type for feed description (title)
2048 if (defined $file_name) {
2049 $type = "history of $file_name";
2050 $type .= "/" if ($action eq 'tree');
2051 $type .= " on '$branch'" if (defined $branch);
2053 $type = "log of $branch" if (defined $branch);
2056 $res{-title
} = $type;
2057 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2058 $res{'file_name'} = $file_name;
2063 ## ----------------------------------------------------------------------
2064 ## git utility subroutines, invoking git commands
2066 # returns path to the core git executable and the --git-dir parameter as list
2068 $number_of_git_cmds++;
2069 return $GIT, '--git-dir='.$git_dir;
2072 # quote the given arguments for passing them to the shell
2073 # quote_command("command", "arg 1", "arg with ' and ! characters")
2074 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2075 # Try to avoid using this function wherever possible.
2078 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2081 # get HEAD ref of given project as hash
2082 sub git_get_head_hash
{
2083 return git_get_full_hash
(shift, 'HEAD');
2086 sub git_get_full_hash
{
2087 return git_get_hash
(@_);
2090 sub git_get_short_hash
{
2091 return git_get_hash
(@_, '--short=7');
2095 my ($project, $hash, @options) = @_;
2096 my $o_git_dir = $git_dir;
2098 $git_dir = "$projectroot/$project";
2099 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2100 '--verify', '-q', @options, $hash) {
2102 chomp $retval if defined $retval;
2105 if (defined $o_git_dir) {
2106 $git_dir = $o_git_dir;
2111 # get type of given object
2115 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2117 close $fd or return;
2122 # repository configuration
2123 our $config_file = '';
2126 # store multiple values for single key as anonymous array reference
2127 # single values stored directly in the hash, not as [ <value> ]
2128 sub hash_set_multi
{
2129 my ($hash, $key, $value) = @_;
2131 if (!exists $hash->{$key}) {
2132 $hash->{$key} = $value;
2133 } elsif (!ref $hash->{$key}) {
2134 $hash->{$key} = [ $hash->{$key}, $value ];
2136 push @
{$hash->{$key}}, $value;
2140 # return hash of git project configuration
2141 # optionally limited to some section, e.g. 'gitweb'
2142 sub git_parse_project_config
{
2143 my $section_regexp = shift;
2148 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2151 while (my $keyval = <$fh>) {
2153 my ($key, $value) = split(/\n/, $keyval, 2);
2155 hash_set_multi
(\
%config, $key, $value)
2156 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2163 # convert config value to boolean: 'true' or 'false'
2164 # no value, number > 0, 'true' and 'yes' values are true
2165 # rest of values are treated as false (never as error)
2166 sub config_to_bool
{
2169 return 1 if !defined $val; # section.key
2171 # strip leading and trailing whitespace
2175 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2176 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2179 # convert config value to simple decimal number
2180 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2181 # to be multiplied by 1024, 1048576, or 1073741824
2185 # strip leading and trailing whitespace
2189 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2191 # unknown unit is treated as 1
2192 return $num * ($unit eq 'g' ?
1073741824 :
2193 $unit eq 'm' ?
1048576 :
2194 $unit eq 'k' ?
1024 : 1);
2199 # convert config value to array reference, if needed
2200 sub config_to_multi
{
2203 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2206 sub git_get_project_config
{
2207 my ($key, $type) = @_;
2209 # do we have project
2210 return unless (defined $project && defined $git_dir);
2213 return unless ($key);
2214 $key =~ s/^gitweb\.//;
2215 return if ($key =~ m/\W/);
2218 if (defined $type) {
2221 unless ($type eq 'bool' || $type eq 'int');
2225 if (!defined $config_file ||
2226 $config_file ne "$git_dir/config") {
2227 %config = git_parse_project_config
('gitweb');
2228 $config_file = "$git_dir/config";
2231 # check if config variable (key) exists
2232 return unless exists $config{"gitweb.$key"};
2235 if (!defined $type) {
2236 return $config{"gitweb.$key"};
2237 } elsif ($type eq 'bool') {
2238 # backward compatibility: 'git config --bool' returns true/false
2239 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2240 } elsif ($type eq 'int') {
2241 return config_to_int
($config{"gitweb.$key"});
2243 return $config{"gitweb.$key"};
2246 # get hash of given path at given ref
2247 sub git_get_hash_by_path
{
2249 my $path = shift || return undef;
2254 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2255 or die_error
(500, "Open git-ls-tree failed");
2257 close $fd or return undef;
2259 if (!defined $line) {
2260 # there is no tree or hash given by $path at $base
2264 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2265 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2266 if (defined $type && $type ne $2) {
2267 # type doesn't match
2273 # get path of entry with given hash at given tree-ish (ref)
2274 # used to get 'from' filename for combined diff (merge commit) for renames
2275 sub git_get_path_by_hash
{
2276 my $base = shift || return;
2277 my $hash = shift || return;
2281 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2283 while (my $line = <$fd>) {
2286 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2287 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2288 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2297 ## ......................................................................
2298 ## git utility functions, directly accessing git repository
2300 sub git_get_project_description
{
2303 $git_dir = "$projectroot/$path";
2304 open my $fd, '<', "$git_dir/description"
2305 or return git_get_project_config
('description');
2308 if (defined $descr) {
2314 sub git_get_project_ctags
{
2318 $git_dir = "$projectroot/$path";
2319 opendir my $dh, "$git_dir/ctags"
2321 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2322 open my $ct, '<', $_ or next;
2326 my $ctag = $_; $ctag =~ s
#.*/##;
2327 $ctags->{$ctag} = $val;
2333 sub git_populate_project_tagcloud
{
2336 # First, merge different-cased tags; tags vote on casing
2338 foreach (keys %$ctags) {
2339 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2340 if (not $ctags_lc{lc $_}->{topcount
}
2341 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2342 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2343 $ctags_lc{lc $_}->{topname
} = $_;
2348 if (eval { require HTML
::TagCloud
; 1; }) {
2349 $cloud = HTML
::TagCloud
->new;
2350 foreach (sort keys %ctags_lc) {
2351 # Pad the title with spaces so that the cloud looks
2353 my $title = $ctags_lc{$_}->{topname
};
2354 $title =~ s/ / /g;
2355 $title =~ s/^/ /g;
2356 $title =~ s/$/ /g;
2357 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2360 $cloud = \
%ctags_lc;
2365 sub git_show_project_tagcloud
{
2366 my ($cloud, $count) = @_;
2367 print STDERR
ref($cloud)."..\n";
2368 if (ref $cloud eq 'HTML::TagCloud') {
2369 return $cloud->html_and_css($count);
2371 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2372 return '<p align="center">' . join (', ', map {
2373 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2374 } splice(@tags, 0, $count)) . '</p>';
2378 sub git_get_project_url_list
{
2381 $git_dir = "$projectroot/$path";
2382 open my $fd, '<', "$git_dir/cloneurl"
2383 or return wantarray ?
2384 @
{ config_to_multi
(git_get_project_config
('url')) } :
2385 config_to_multi
(git_get_project_config
('url'));
2386 my @git_project_url_list = map { chomp; $_ } <$fd>;
2389 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2392 sub git_get_projects_list
{
2397 $filter =~ s/\.git$//;
2399 my $check_forks = gitweb_check_feature
('forks');
2401 if (-d
$projects_list) {
2402 # search in directory
2403 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2404 # remove the trailing "/"
2406 my $pfxlen = length("$dir");
2407 my $pfxdepth = ($dir =~ tr!/!!);
2410 follow_fast
=> 1, # follow symbolic links
2411 follow_skip
=> 2, # ignore duplicates
2412 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2414 # skip project-list toplevel, if we get it.
2415 return if (m!^[/.]$!);
2416 # only directories can be git repositories
2417 return unless (-d
$_);
2418 # don't traverse too deep (Find is super slow on os x)
2419 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2420 $File::Find
::prune
= 1;
2424 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2425 # we check related file in $projectroot
2426 my $path = ($filter ?
"$filter/" : '') . $subdir;
2427 if (check_export_ok
("$projectroot/$path")) {
2428 push @list, { path
=> $path };
2429 $File::Find
::prune
= 1;
2434 } elsif (-f
$projects_list) {
2435 # read from file(url-encoded):
2436 # 'git%2Fgit.git Linus+Torvalds'
2437 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2438 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2440 open my $fd, '<', $projects_list or return;
2442 while (my $line = <$fd>) {
2444 my ($path, $owner) = split ' ', $line;
2445 $path = unescape
($path);
2446 $owner = unescape
($owner);
2447 if (!defined $path) {
2450 if ($filter ne '') {
2451 # looking for forks;
2452 my $pfx = substr($path, 0, length($filter));
2453 if ($pfx ne $filter) {
2456 my $sfx = substr($path, length($filter));
2457 if ($sfx !~ /^\/.*\
.git
$/) {
2460 } elsif ($check_forks) {
2462 foreach my $filter (keys %paths) {
2463 # looking for forks;
2464 my $pfx = substr($path, 0, length($filter));
2465 if ($pfx ne $filter) {
2468 my $sfx = substr($path, length($filter));
2469 if ($sfx !~ /^\/.*\
.git
$/) {
2472 # is a fork, don't include it in
2477 if (check_export_ok
("$projectroot/$path")) {
2480 owner
=> to_utf8
($owner),
2483 (my $forks_path = $path) =~ s/\.git$//;
2484 $paths{$forks_path}++;
2492 our $gitweb_project_owner = undef;
2493 sub git_get_project_list_from_file
{
2495 return if (defined $gitweb_project_owner);
2497 $gitweb_project_owner = {};
2498 # read from file (url-encoded):
2499 # 'git%2Fgit.git Linus+Torvalds'
2500 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2501 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2502 if (-f
$projects_list) {
2503 open(my $fd, '<', $projects_list);
2504 while (my $line = <$fd>) {
2506 my ($pr, $ow) = split ' ', $line;
2507 $pr = unescape
($pr);
2508 $ow = unescape
($ow);
2509 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2515 sub git_get_project_owner
{
2516 my $project = shift;
2519 return undef unless $project;
2520 $git_dir = "$projectroot/$project";
2522 if (!defined $gitweb_project_owner) {
2523 git_get_project_list_from_file
();
2526 if (exists $gitweb_project_owner->{$project}) {
2527 $owner = $gitweb_project_owner->{$project};
2529 if (!defined $owner){
2530 $owner = git_get_project_config
('owner');
2532 if (!defined $owner) {
2533 $owner = get_file_owner
("$git_dir");
2539 sub git_get_last_activity
{
2543 $git_dir = "$projectroot/$path";
2544 open($fd, "-|", git_cmd
(), 'for-each-ref',
2545 '--format=%(committer)',
2546 '--sort=-committerdate',
2548 'refs/heads') or return;
2549 my $most_recent = <$fd>;
2550 close $fd or return;
2551 if (defined $most_recent &&
2552 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2554 my $age = time - $timestamp;
2555 return ($age, age_string
($age));
2557 return (undef, undef);
2560 sub git_get_references
{
2561 my $type = shift || "";
2563 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2564 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2565 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2566 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2569 while (my $line = <$fd>) {
2571 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2572 if (defined $refs{$1}) {
2573 push @
{$refs{$1}}, $2;
2579 close $fd or return;
2583 sub git_get_rev_name_tags
{
2584 my $hash = shift || return undef;
2586 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2588 my $name_rev = <$fd>;
2591 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2594 # catches also '$hash undefined' output
2599 ## ----------------------------------------------------------------------
2600 ## parse to hash functions
2604 my $tz = shift || "-0000";
2607 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2608 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2609 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2610 $date{'hour'} = $hour;
2611 $date{'minute'} = $min;
2612 $date{'mday'} = $mday;
2613 $date{'day'} = $days[$wday];
2614 $date{'month'} = $months[$mon];
2615 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2616 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2617 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2618 $mday, $months[$mon], $hour ,$min;
2619 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2620 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2622 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2623 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2624 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2625 $date{'hour_local'} = $hour;
2626 $date{'minute_local'} = $min;
2627 $date{'tz_local'} = $tz;
2628 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2629 1900+$year, $mon+1, $mday,
2630 $hour, $min, $sec, $tz);
2639 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2640 $tag{'id'} = $tag_id;
2641 while (my $line = <$fd>) {
2643 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2644 $tag{'object'} = $1;
2645 } elsif ($line =~ m/^type (.+)$/) {
2647 } elsif ($line =~ m/^tag (.+)$/) {
2649 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2650 $tag{'author'} = $1;
2651 $tag{'author_epoch'} = $2;
2652 $tag{'author_tz'} = $3;
2653 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2654 $tag{'author_name'} = $1;
2655 $tag{'author_email'} = $2;
2657 $tag{'author_name'} = $tag{'author'};
2659 } elsif ($line =~ m/--BEGIN/) {
2660 push @comment, $line;
2662 } elsif ($line eq "") {
2666 push @comment, <$fd>;
2667 $tag{'comment'} = \
@comment;
2668 close $fd or return;
2669 if (!defined $tag{'name'}) {
2675 sub parse_commit_text
{
2676 my ($commit_text, $withparents) = @_;
2677 my @commit_lines = split '\n', $commit_text;
2680 pop @commit_lines; # Remove '\0'
2682 if (! @commit_lines) {
2686 my $header = shift @commit_lines;
2687 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2690 ($co{'id'}, my @parents) = split ' ', $header;
2691 while (my $line = shift @commit_lines) {
2692 last if $line eq "\n";
2693 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2695 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2697 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2698 $co{'author'} = to_utf8
($1);
2699 $co{'author_epoch'} = $2;
2700 $co{'author_tz'} = $3;
2701 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2702 $co{'author_name'} = $1;
2703 $co{'author_email'} = $2;
2705 $co{'author_name'} = $co{'author'};
2707 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2708 $co{'committer'} = to_utf8
($1);
2709 $co{'committer_epoch'} = $2;
2710 $co{'committer_tz'} = $3;
2711 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2712 $co{'committer_name'} = $1;
2713 $co{'committer_email'} = $2;
2715 $co{'committer_name'} = $co{'committer'};
2719 if (!defined $co{'tree'}) {
2722 $co{'parents'} = \
@parents;
2723 $co{'parent'} = $parents[0];
2725 foreach my $title (@commit_lines) {
2728 $co{'title'} = chop_str
($title, 80, 5);
2729 # remove leading stuff of merges to make the interesting part visible
2730 if (length($title) > 50) {
2731 $title =~ s/^Automatic //;
2732 $title =~ s/^merge (of|with) /Merge ... /i;
2733 if (length($title) > 50) {
2734 $title =~ s/(http|rsync):\/\///;
2736 if (length($title) > 50) {
2737 $title =~ s/(master|www|rsync)\.//;
2739 if (length($title) > 50) {
2740 $title =~ s/kernel.org:?//;
2742 if (length($title) > 50) {
2743 $title =~ s/\/pub\/scm//;
2746 $co{'title_short'} = chop_str
($title, 50, 5);
2750 if (! defined $co{'title'} || $co{'title'} eq "") {
2751 $co{'title'} = $co{'title_short'} = '(no commit message)';
2753 # remove added spaces
2754 foreach my $line (@commit_lines) {
2757 $co{'comment'} = \
@commit_lines;
2759 my $age = time - $co{'committer_epoch'};
2761 $co{'age_string'} = age_string
($age);
2762 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2763 if ($age > 60*60*24*7*2) {
2764 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2765 $co{'age_string_age'} = $co{'age_string'};
2767 $co{'age_string_date'} = $co{'age_string'};
2768 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2774 my ($commit_id) = @_;
2779 open my $fd, "-|", git_cmd
(), "rev-list",
2785 or die_error
(500, "Open git-rev-list failed");
2786 %co = parse_commit_text
(<$fd>, 1);
2793 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2801 open my $fd, "-|", git_cmd
(), "rev-list",
2804 ("--max-count=" . $maxcount),
2805 ("--skip=" . $skip),
2809 ($filename ?
($filename) : ())
2810 or die_error
(500, "Open git-rev-list failed");
2811 while (my $line = <$fd>) {
2812 my %co = parse_commit_text
($line);
2817 return wantarray ?
@cos : \
@cos;
2820 # parse line of git-diff-tree "raw" output
2821 sub parse_difftree_raw_line
{
2825 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2826 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2827 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2828 $res{'from_mode'} = $1;
2829 $res{'to_mode'} = $2;
2830 $res{'from_id'} = $3;
2832 $res{'status'} = $5;
2833 $res{'similarity'} = $6;
2834 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2835 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2837 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2840 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2841 # combined diff (for merge commit)
2842 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2843 $res{'nparents'} = length($1);
2844 $res{'from_mode'} = [ split(' ', $2) ];
2845 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2846 $res{'from_id'} = [ split(' ', $3) ];
2847 $res{'to_id'} = pop @
{$res{'from_id'}};
2848 $res{'status'} = [ split('', $4) ];
2849 $res{'to_file'} = unquote
($5);
2851 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2852 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2853 $res{'commit'} = $1;
2856 return wantarray ?
%res : \
%res;
2859 # wrapper: return parsed line of git-diff-tree "raw" output
2860 # (the argument might be raw line, or parsed info)
2861 sub parsed_difftree_line
{
2862 my $line_or_ref = shift;
2864 if (ref($line_or_ref) eq "HASH") {
2865 # pre-parsed (or generated by hand)
2866 return $line_or_ref;
2868 return parse_difftree_raw_line
($line_or_ref);
2872 # parse line of git-ls-tree output
2873 sub parse_ls_tree_line
{
2879 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2880 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2889 $res{'name'} = unquote
($5);
2892 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2893 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2901 $res{'name'} = unquote
($4);
2905 return wantarray ?
%res : \
%res;
2908 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2909 sub parse_from_to_diffinfo
{
2910 my ($diffinfo, $from, $to, @parents) = @_;
2912 if ($diffinfo->{'nparents'}) {
2914 $from->{'file'} = [];
2915 $from->{'href'} = [];
2916 fill_from_file_info
($diffinfo, @parents)
2917 unless exists $diffinfo->{'from_file'};
2918 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2919 $from->{'file'}[$i] =
2920 defined $diffinfo->{'from_file'}[$i] ?
2921 $diffinfo->{'from_file'}[$i] :
2922 $diffinfo->{'to_file'};
2923 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2924 $from->{'href'}[$i] = href
(action
=>"blob",
2925 hash_base
=>$parents[$i],
2926 hash
=>$diffinfo->{'from_id'}[$i],
2927 file_name
=>$from->{'file'}[$i]);
2929 $from->{'href'}[$i] = undef;
2933 # ordinary (not combined) diff
2934 $from->{'file'} = $diffinfo->{'from_file'};
2935 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2936 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2937 hash
=>$diffinfo->{'from_id'},
2938 file_name
=>$from->{'file'});
2940 delete $from->{'href'};
2944 $to->{'file'} = $diffinfo->{'to_file'};
2945 if (!is_deleted
($diffinfo)) { # file exists in result
2946 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2947 hash
=>$diffinfo->{'to_id'},
2948 file_name
=>$to->{'file'});
2950 delete $to->{'href'};
2954 ## ......................................................................
2955 ## parse to array of hashes functions
2957 sub git_get_heads_list
{
2961 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2962 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2963 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2966 while (my $line = <$fd>) {
2970 my ($refinfo, $committerinfo) = split(/\0/, $line);
2971 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2972 my ($committer, $epoch, $tz) =
2973 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2974 $ref_item{'fullname'} = $name;
2975 $name =~ s!^refs/heads/!!;
2977 $ref_item{'name'} = $name;
2978 $ref_item{'id'} = $hash;
2979 $ref_item{'title'} = $title || '(no commit message)';
2980 $ref_item{'epoch'} = $epoch;
2982 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2984 $ref_item{'age'} = "unknown";
2987 push @headslist, \
%ref_item;
2991 return wantarray ?
@headslist : \
@headslist;
2994 sub git_get_tags_list
{
2998 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2999 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
3000 '--format=%(objectname) %(objecttype) %(refname) '.
3001 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
3004 while (my $line = <$fd>) {
3008 my ($refinfo, $creatorinfo) = split(/\0/, $line);
3009 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
3010 my ($creator, $epoch, $tz) =
3011 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
3012 $ref_item{'fullname'} = $name;
3013 $name =~ s!^refs/tags/!!;
3015 $ref_item{'type'} = $type;
3016 $ref_item{'id'} = $id;
3017 $ref_item{'name'} = $name;
3018 if ($type eq "tag") {
3019 $ref_item{'subject'} = $title;
3020 $ref_item{'reftype'} = $reftype;
3021 $ref_item{'refid'} = $refid;
3023 $ref_item{'reftype'} = $type;
3024 $ref_item{'refid'} = $id;
3027 if ($type eq "tag" || $type eq "commit") {
3028 $ref_item{'epoch'} = $epoch;
3030 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3032 $ref_item{'age'} = "unknown";
3036 push @tagslist, \
%ref_item;
3040 return wantarray ?
@tagslist : \
@tagslist;
3043 ## ----------------------------------------------------------------------
3044 ## filesystem-related functions
3046 sub get_file_owner
{
3049 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3050 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3051 if (!defined $gcos) {
3055 $owner =~ s/[,;].*$//;
3056 return to_utf8
($owner);
3059 # assume that file exists
3061 my $filename = shift;
3063 open my $fd, '<', $filename;
3064 print map { to_utf8
($_) } <$fd>;
3068 ## ......................................................................
3069 ## mimetype related functions
3071 sub mimetype_guess_file
{
3072 my $filename = shift;
3073 my $mimemap = shift;
3074 -r
$mimemap or return undef;
3077 open(my $mh, '<', $mimemap) or return undef;
3079 next if m/^#/; # skip comments
3080 my ($mimetype, $exts) = split(/\t+/);
3081 if (defined $exts) {
3082 my @exts = split(/\s+/, $exts);
3083 foreach my $ext (@exts) {
3084 $mimemap{$ext} = $mimetype;
3090 $filename =~ /\.([^.]*)$/;
3091 return $mimemap{$1};
3094 sub mimetype_guess
{
3095 my $filename = shift;
3097 $filename =~ /\./ or return undef;
3099 if ($mimetypes_file) {
3100 my $file = $mimetypes_file;
3101 if ($file !~ m!^/!) { # if it is relative path
3102 # it is relative to project
3103 $file = "$projectroot/$project/$file";
3105 $mime = mimetype_guess_file
($filename, $file);
3107 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3113 my $filename = shift;
3116 my $mime = mimetype_guess
($filename);
3117 $mime and return $mime;
3121 return $default_blob_plain_mimetype unless $fd;
3124 return 'text/plain';
3125 } elsif (! $filename) {
3126 return 'application/octet-stream';
3127 } elsif ($filename =~ m/\.png$/i) {
3129 } elsif ($filename =~ m/\.gif$/i) {
3131 } elsif ($filename =~ m/\.jpe?g$/i) {
3132 return 'image/jpeg';
3134 return 'application/octet-stream';
3138 sub blob_contenttype
{
3139 my ($fd, $file_name, $type) = @_;
3141 $type ||= blob_mimetype
($fd, $file_name);
3142 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3143 $type .= "; charset=$default_text_plain_charset";
3149 ## ======================================================================
3150 ## functions printing HTML: header, footer, error page
3152 sub git_header_html
{
3153 my $status = shift || "200 OK";
3154 my $expires = shift;
3156 my $title = "$site_name";
3157 if (defined $project) {
3158 $title .= " - " . to_utf8
($project);
3159 if (defined $action) {
3160 $title .= "/$action";
3161 if (defined $file_name) {
3162 $title .= " - " . esc_path
($file_name);
3163 if ($action eq "tree" && $file_name !~ m
|/$|) {
3170 # require explicit support from the UA if we are to send the page as
3171 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3172 # we have to do this because MSIE sometimes globs '*/*', pretending to
3173 # support xhtml+xml but choking when it gets what it asked for.
3174 if (defined $cgi->http('HTTP_ACCEPT') &&
3175 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3176 $cgi->Accept('application/xhtml+xml') != 0) {
3177 $content_type = 'application/xhtml+xml';
3179 $content_type = 'text/html';
3181 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3182 -status
=> $status, -expires
=> $expires);
3183 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3185 <?xml version="1.0" encoding="utf-8"?>
3186 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3187 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3188 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3189 <!-- git core binaries version $git_version -->
3191 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3192 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3193 <meta name="robots" content="index, nofollow"/>
3194 <title>$title</title>
3196 # the stylesheet, favicon etc urls won't work correctly with path_info
3197 # unless we set the appropriate base URL
3198 if ($ENV{'PATH_INFO'}) {
3199 print "<base href=\"".esc_url
($base_url)."\" />\n";
3201 # print out each stylesheet that exist, providing backwards capability
3202 # for those people who defined $stylesheet in a config file
3203 if (defined $stylesheet) {
3204 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3206 foreach my $stylesheet (@stylesheets) {
3207 next unless $stylesheet;
3208 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3211 if (defined $project) {
3212 my %href_params = get_feed_info
();
3213 if (!exists $href_params{'-title'}) {
3214 $href_params{'-title'} = 'log';
3217 foreach my $format qw(RSS Atom) {
3218 my $type = lc($format);
3220 '-rel' => 'alternate',
3221 '-title' => "$project - $href_params{'-title'} - $format feed",
3222 '-type' => "application/$type+xml"
3225 $href_params{'action'} = $type;
3226 $link_attr{'-href'} = href
(%href_params);
3228 "rel=\"$link_attr{'-rel'}\" ".
3229 "title=\"$link_attr{'-title'}\" ".
3230 "href=\"$link_attr{'-href'}\" ".
3231 "type=\"$link_attr{'-type'}\" ".
3234 $href_params{'extra_options'} = '--no-merges';
3235 $link_attr{'-href'} = href
(%href_params);
3236 $link_attr{'-title'} .= ' (no merges)';
3238 "rel=\"$link_attr{'-rel'}\" ".
3239 "title=\"$link_attr{'-title'}\" ".
3240 "href=\"$link_attr{'-href'}\" ".
3241 "type=\"$link_attr{'-type'}\" ".
3246 printf('<link rel="alternate" title="%s projects list" '.
3247 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3248 $site_name, href
(project
=>undef, action
=>"project_index"));
3249 printf('<link rel="alternate" title="%s projects feeds" '.
3250 'href="%s" type="text/x-opml" />'."\n",
3251 $site_name, href
(project
=>undef, action
=>"opml"));
3253 if (defined $favicon) {
3254 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3260 if (defined $site_header && -f
$site_header) {
3261 insert_file
($site_header);
3264 print "<div class=\"page_header\">\n" .
3265 $cgi->a({-href
=> esc_url
($logo_url),
3266 -title
=> $logo_label},
3267 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3268 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3269 if (defined $project) {
3270 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3271 if (defined $action) {
3278 my $have_search = gitweb_check_feature
('search');
3279 if (defined $project && $have_search) {
3280 if (!defined $searchtext) {
3284 if (defined $hash_base) {
3285 $search_hash = $hash_base;
3286 } elsif (defined $hash) {
3287 $search_hash = $hash;
3289 $search_hash = "HEAD";
3291 my $action = $my_uri;
3292 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3293 if ($use_pathinfo) {
3294 $action .= "/".esc_url
($project);
3296 print $cgi->startform(-method
=> "get", -action
=> $action) .
3297 "<div class=\"search\">\n" .
3299 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3300 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3301 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3302 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3303 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3304 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3306 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3307 "<span title=\"Extended regular expression\">" .
3308 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3309 -checked
=> $search_use_regexp) .
3312 $cgi->end_form() . "\n";
3316 sub git_footer_html
{
3317 my $feed_class = 'rss_logo';
3319 print "<div class=\"page_footer\">\n";
3320 if (defined $project) {
3321 my $descr = git_get_project_description
($project);
3322 if (defined $descr) {
3323 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3326 my %href_params = get_feed_info
();
3327 if (!%href_params) {
3328 $feed_class .= ' generic';
3330 $href_params{'-title'} ||= 'log';
3332 foreach my $format qw(RSS Atom) {
3333 $href_params{'action'} = lc($format);
3334 print $cgi->a({-href
=> href
(%href_params),
3335 -title
=> "$href_params{'-title'} $format feed",
3336 -class => $feed_class}, $format)."\n";
3340 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3341 -class => $feed_class}, "OPML") . " ";
3342 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3343 -class => $feed_class}, "TXT") . "\n";
3345 print "</div>\n"; # class="page_footer"
3347 if (defined $t0 && gitweb_check_feature
('timed')) {
3348 print "<div id=\"generating_info\">\n";
3349 print 'This page took '.
3350 '<span id="generating_time" class="time_span">'.
3351 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3354 '<span id="generating_cmd">'.
3355 $number_of_git_cmds.
3356 '</span> git commands '.
3358 print "</div>\n"; # class="page_footer"
3361 if (defined $site_footer && -f
$site_footer) {
3362 insert_file
($site_footer);
3365 print qq!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3366 if (defined $action &&
3367 $action eq 'blame_incremental') {
3368 print qq!<script type
="text/javascript">\n!.
3369 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3370 qq! "!. href() .qq!");\n!.
3372 } elsif (gitweb_check_feature
('javascript-actions')) {
3373 print qq!<script type
="text/javascript">\n!.
3374 qq!window
.onload
= fixLinks
;\n!.
3382 # die_error(<http_status_code>, <error_message>)
3383 # Example: die_error(404, 'Hash not found')
3384 # By convention, use the following status codes (as defined in RFC 2616):
3385 # 400: Invalid or missing CGI parameters, or
3386 # requested object exists but has wrong type.
3387 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3388 # this server or project.
3389 # 404: Requested object/revision/project doesn't exist.
3390 # 500: The server isn't configured properly, or
3391 # an internal error occurred (e.g. failed assertions caused by bugs), or
3392 # an unknown error occurred (e.g. the git binary died unexpectedly).
3393 # 503: The server is currently unavailable (because it is overloaded,
3394 # or down for maintenance). Generally, this is a temporary state.
3396 my $status = shift || 500;
3397 my $error = shift || "Internal server error";
3400 my %http_responses = (
3401 400 => '400 Bad Request',
3402 403 => '403 Forbidden',
3403 404 => '404 Not Found',
3404 500 => '500 Internal Server Error',
3405 503 => '503 Service Unavailable',
3407 git_header_html
($http_responses{$status});
3409 <div class="page_body">
3414 if (defined $extra) {
3424 ## ----------------------------------------------------------------------
3425 ## functions printing or outputting HTML: navigation
3427 sub git_print_page_nav
{
3428 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3429 $extra = '' if !defined $extra; # pager or formats
3431 my @navs = qw(summary shortlog log commit commitdiff tree);
3433 @navs = grep { $_ ne $suppress } @navs;
3436 my %arg = map { $_ => {action
=>$_} } @navs;
3437 if (defined $head) {
3438 for (qw(commit commitdiff)) {
3439 $arg{$_}{'hash'} = $head;
3441 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3442 for (qw(shortlog log)) {
3443 $arg{$_}{'hash'} = $head;
3448 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3449 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3451 my @actions = gitweb_get_feature
('actions');
3454 'n' => $project, # project name
3455 'f' => $git_dir, # project path within filesystem
3456 'h' => $treehead || '', # current hash ('h' parameter)
3457 'b' => $treebase || '', # hash base ('hb' parameter)
3460 my ($label, $link, $pos) = splice(@actions,0,3);
3462 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3464 $link =~ s/%([%nfhb])/$repl{$1}/g;
3465 $arg{$label}{'_href'} = $link;
3468 print "<div class=\"page_nav\">\n" .
3470 map { $_ eq $current ?
3471 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3473 print "<br/>\n$extra<br/>\n" .
3477 sub format_paging_nav
{
3478 my ($action, $page, $has_next_link) = @_;
3484 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3486 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3487 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3489 $paging_nav .= "first ⋅ prev";
3492 if ($has_next_link) {
3493 $paging_nav .= " ⋅ " .
3494 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3495 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3497 $paging_nav .= " ⋅ next";
3503 ## ......................................................................
3504 ## functions printing or outputting HTML: div
3506 sub git_print_header_div
{
3507 my ($action, $title, $hash, $hash_base) = @_;
3510 $args{'action'} = $action;
3511 $args{'hash'} = $hash if $hash;
3512 $args{'hash_base'} = $hash_base if $hash_base;
3514 print "<div class=\"header\">\n" .
3515 $cgi->a({-href
=> href
(%args), -class => "title"},
3516 $title ?
$title : $action) .
3520 sub print_local_time
{
3521 print format_local_time
(@_);
3524 sub format_local_time
{
3527 if ($date{'hour_local'} < 6) {
3528 $localtime .= sprintf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3529 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3531 $localtime .= sprintf(" (%02d:%02d %s)",
3532 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3538 # Outputs the author name and date in long form
3539 sub git_print_authorship
{
3542 my $tag = $opts{-tag
} || 'div';
3543 my $author = $co->{'author_name'};
3545 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3546 print "<$tag class=\"author_date\">" .
3547 format_search_author
($author, "author", esc_html
($author)) .
3549 print_local_time
(%ad) if ($opts{-localtime});
3550 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3554 # Outputs table rows containing the full author or committer information,
3555 # in the format expected for 'commit' view (& similia).
3556 # Parameters are a commit hash reference, followed by the list of people
3557 # to output information for. If the list is empty it defalts to both
3558 # author and committer.
3559 sub git_print_authorship_rows
{
3561 # too bad we can't use @people = @_ || ('author', 'committer')
3563 @people = ('author', 'committer') unless @people;
3564 foreach my $who (@people) {
3565 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3566 print "<tr><td>$who</td><td>" .
3567 format_search_author
($co->{"${who}_name"}, $who,
3568 esc_html
($co->{"${who}_name"})) . " " .
3569 format_search_author
($co->{"${who}_email"}, $who,
3570 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3571 "</td><td rowspan=\"2\">" .
3572 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3575 "<td></td><td> $wd{'rfc2822'}";
3576 print_local_time
(%wd);
3582 sub git_print_page_path
{
3588 print "<div class=\"page_path\">";
3589 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3590 -title
=> 'tree root'}, to_utf8
("[$project]"));
3592 if (defined $name) {
3593 my @dirname = split '/', $name;
3594 my $basename = pop @dirname;
3597 foreach my $dir (@dirname) {
3598 $fullname .= ($fullname ?
'/' : '') . $dir;
3599 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3601 -title
=> $fullname}, esc_path
($dir));
3604 if (defined $type && $type eq 'blob') {
3605 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3607 -title
=> $name}, esc_path
($basename));
3608 } elsif (defined $type && $type eq 'tree') {
3609 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3611 -title
=> $name}, esc_path
($basename));
3614 print esc_path
($basename);
3617 print "<br/></div>\n";
3624 if ($opts{'-remove_title'}) {
3625 # remove title, i.e. first line of log
3628 # remove leading empty lines
3629 while (defined $log->[0] && $log->[0] eq "") {
3636 foreach my $line (@
$log) {
3637 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3640 if (! $opts{'-remove_signoff'}) {
3641 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3644 # remove signoff lines
3651 # print only one empty line
3652 # do not print empty line after signoff
3654 next if ($empty || $signoff);
3660 print format_log_line_html
($line) . "<br/>\n";
3663 if ($opts{'-final_empty_line'}) {
3664 # end with single empty line
3665 print "<br/>\n" unless $empty;
3669 # return link target (what link points to)
3670 sub git_get_link_target
{
3675 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3679 $link_target = <$fd>;
3684 return $link_target;
3687 # given link target, and the directory (basedir) the link is in,
3688 # return target of link relative to top directory (top tree);
3689 # return undef if it is not possible (including absolute links).
3690 sub normalize_link_target
{
3691 my ($link_target, $basedir) = @_;
3693 # absolute symlinks (beginning with '/') cannot be normalized
3694 return if (substr($link_target, 0, 1) eq '/');
3696 # normalize link target to path from top (root) tree (dir)
3699 $path = $basedir . '/' . $link_target;
3701 # we are in top (root) tree (dir)
3702 $path = $link_target;
3705 # remove //, /./, and /../
3707 foreach my $part (split('/', $path)) {
3708 # discard '.' and ''
3709 next if (!$part || $part eq '.');
3711 if ($part eq '..') {
3715 # link leads outside repository (outside top dir)
3719 push @path_parts, $part;
3722 $path = join('/', @path_parts);
3727 # print tree entry (row of git_tree), but without encompassing <tr> element
3728 sub git_print_tree_entry
{
3729 my ($t, $basedir, $hash_base, $have_blame) = @_;
3732 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3734 # The format of a table row is: mode list link. Where mode is
3735 # the mode of the entry, list is the name of the entry, an href,
3736 # and link is the action links of the entry.
3738 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3739 if (exists $t->{'size'}) {
3740 print "<td class=\"size\">$t->{'size'}</td>\n";
3742 if ($t->{'type'} eq "blob") {
3743 print "<td class=\"list\">" .
3744 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3745 file_name
=>"$basedir$t->{'name'}", %base_key),
3746 -class => "list"}, esc_path
($t->{'name'}));
3747 if (S_ISLNK
(oct $t->{'mode'})) {
3748 my $link_target = git_get_link_target
($t->{'hash'});
3750 my $norm_target = normalize_link_target
($link_target, $basedir);
3751 if (defined $norm_target) {
3753 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3754 file_name
=>$norm_target),
3755 -title
=> $norm_target}, esc_path
($link_target));
3757 print " -> " . esc_path
($link_target);
3762 print "<td class=\"link\">";
3763 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3764 file_name
=>"$basedir$t->{'name'}", %base_key)},
3768 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3769 file_name
=>"$basedir$t->{'name'}", %base_key)},
3772 if (defined $hash_base) {
3774 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3775 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3779 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3780 file_name
=>"$basedir$t->{'name'}")},
3784 } elsif ($t->{'type'} eq "tree") {
3785 print "<td class=\"list\">";
3786 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3787 file_name
=>"$basedir$t->{'name'}",
3789 esc_path
($t->{'name'}));
3791 print "<td class=\"link\">";
3792 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3793 file_name
=>"$basedir$t->{'name'}",
3796 if (defined $hash_base) {
3798 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3799 file_name
=>"$basedir$t->{'name'}")},
3804 # unknown object: we can only present history for it
3805 # (this includes 'commit' object, i.e. submodule support)
3806 print "<td class=\"list\">" .
3807 esc_path
($t->{'name'}) .
3809 print "<td class=\"link\">";
3810 if (defined $hash_base) {
3811 print $cgi->a({-href
=> href
(action
=>"history",
3812 hash_base
=>$hash_base,
3813 file_name
=>"$basedir$t->{'name'}")},
3820 ## ......................................................................
3821 ## functions printing large fragments of HTML
3823 # get pre-image filenames for merge (combined) diff
3824 sub fill_from_file_info
{
3825 my ($diff, @parents) = @_;
3827 $diff->{'from_file'} = [ ];
3828 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3829 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3830 if ($diff->{'status'}[$i] eq 'R' ||
3831 $diff->{'status'}[$i] eq 'C') {
3832 $diff->{'from_file'}[$i] =
3833 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3840 # is current raw difftree line of file deletion
3842 my $diffinfo = shift;
3844 return $diffinfo->{'to_id'} eq ('0' x
40);
3847 # does patch correspond to [previous] difftree raw line
3848 # $diffinfo - hashref of parsed raw diff format
3849 # $patchinfo - hashref of parsed patch diff format
3850 # (the same keys as in $diffinfo)
3851 sub is_patch_split
{
3852 my ($diffinfo, $patchinfo) = @_;
3854 return defined $diffinfo && defined $patchinfo
3855 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3859 sub git_difftree_body
{
3860 my ($difftree, $hash, @parents) = @_;
3861 my ($parent) = $parents[0];
3862 my $have_blame = gitweb_check_feature
('blame');
3863 print "<div class=\"list_head\">\n";
3864 if ($#{$difftree} > 10) {
3865 print(($#{$difftree} + 1) . " files changed:\n");
3869 print "<table class=\"" .
3870 (@parents > 1 ?
"combined " : "") .
3873 # header only for combined diff in 'commitdiff' view
3874 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3877 print "<thead><tr>\n" .
3878 "<th></th><th></th>\n"; # filename, patchN link
3879 for (my $i = 0; $i < @parents; $i++) {
3880 my $par = $parents[$i];
3882 $cgi->a({-href
=> href
(action
=>"commitdiff",
3883 hash
=>$hash, hash_parent
=>$par),
3884 -title
=> 'commitdiff to parent number ' .
3885 ($i+1) . ': ' . substr($par,0,7)},
3889 print "</tr></thead>\n<tbody>\n";
3894 foreach my $line (@
{$difftree}) {
3895 my $diff = parsed_difftree_line
($line);
3898 print "<tr class=\"dark\">\n";
3900 print "<tr class=\"light\">\n";
3904 if (exists $diff->{'nparents'}) { # combined diff
3906 fill_from_file_info
($diff, @parents)
3907 unless exists $diff->{'from_file'};
3909 if (!is_deleted
($diff)) {
3910 # file exists in the result (child) commit
3912 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3913 file_name
=>$diff->{'to_file'},
3915 -class => "list"}, esc_path
($diff->{'to_file'})) .
3919 esc_path
($diff->{'to_file'}) .
3923 if ($action eq 'commitdiff') {
3926 print "<td class=\"link\">" .
3927 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3932 my $has_history = 0;
3933 my $not_deleted = 0;
3934 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3935 my $hash_parent = $parents[$i];
3936 my $from_hash = $diff->{'from_id'}[$i];
3937 my $from_path = $diff->{'from_file'}[$i];
3938 my $status = $diff->{'status'}[$i];
3940 $has_history ||= ($status ne 'A');
3941 $not_deleted ||= ($status ne 'D');
3943 if ($status eq 'A') {
3944 print "<td class=\"link\" align=\"right\"> | </td>\n";
3945 } elsif ($status eq 'D') {
3946 print "<td class=\"link\">" .
3947 $cgi->a({-href
=> href
(action
=>"blob",
3950 file_name
=>$from_path)},
3954 if ($diff->{'to_id'} eq $from_hash) {
3955 print "<td class=\"link nochange\">";
3957 print "<td class=\"link\">";
3959 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3960 hash
=>$diff->{'to_id'},
3961 hash_parent
=>$from_hash,
3963 hash_parent_base
=>$hash_parent,
3964 file_name
=>$diff->{'to_file'},
3965 file_parent
=>$from_path)},
3971 print "<td class=\"link\">";
3973 print $cgi->a({-href
=> href
(action
=>"blob",
3974 hash
=>$diff->{'to_id'},
3975 file_name
=>$diff->{'to_file'},
3978 print " | " if ($has_history);
3981 print $cgi->a({-href
=> href
(action
=>"history",
3982 file_name
=>$diff->{'to_file'},
3989 next; # instead of 'else' clause, to avoid extra indent
3991 # else ordinary diff
3993 my ($to_mode_oct, $to_mode_str, $to_file_type);
3994 my ($from_mode_oct, $from_mode_str, $from_file_type);
3995 if ($diff->{'to_mode'} ne ('0' x
6)) {
3996 $to_mode_oct = oct $diff->{'to_mode'};
3997 if (S_ISREG
($to_mode_oct)) { # only for regular file
3998 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
4000 $to_file_type = file_type
($diff->{'to_mode'});
4002 if ($diff->{'from_mode'} ne ('0' x
6)) {
4003 $from_mode_oct = oct $diff->{'from_mode'};
4004 if (S_ISREG
($to_mode_oct)) { # only for regular file
4005 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
4007 $from_file_type = file_type
($diff->{'from_mode'});
4010 if ($diff->{'status'} eq "A") { # created
4011 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
4012 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
4013 $mode_chng .= "]</span>";
4015 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4016 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4017 -class => "list"}, esc_path
($diff->{'file'}));
4019 print "<td>$mode_chng</td>\n";
4020 print "<td class=\"link\">";
4021 if ($action eq 'commitdiff') {
4024 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4027 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4028 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4032 } elsif ($diff->{'status'} eq "D") { # deleted
4033 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
4035 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4036 hash_base
=>$parent, file_name
=>$diff->{'file'}),
4037 -class => "list"}, esc_path
($diff->{'file'}));
4039 print "<td>$mode_chng</td>\n";
4040 print "<td class=\"link\">";
4041 if ($action eq 'commitdiff') {
4044 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4047 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4048 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4051 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4052 file_name
=>$diff->{'file'})},
4055 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4056 file_name
=>$diff->{'file'})},
4060 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4061 my $mode_chnge = "";
4062 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4063 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4064 if ($from_file_type ne $to_file_type) {
4065 $mode_chnge .= " from $from_file_type to $to_file_type";
4067 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4068 if ($from_mode_str && $to_mode_str) {
4069 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4070 } elsif ($to_mode_str) {
4071 $mode_chnge .= " mode: $to_mode_str";
4074 $mode_chnge .= "]</span>\n";
4077 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4078 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4079 -class => "list"}, esc_path
($diff->{'file'}));
4081 print "<td>$mode_chnge</td>\n";
4082 print "<td class=\"link\">";
4083 if ($action eq 'commitdiff') {
4086 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4088 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4089 # "commit" view and modified file (not onlu mode changed)
4090 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4091 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4092 hash_base
=>$hash, hash_parent_base
=>$parent,
4093 file_name
=>$diff->{'file'})},
4097 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4098 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4101 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4102 file_name
=>$diff->{'file'})},
4105 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4106 file_name
=>$diff->{'file'})},
4110 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4111 my %status_name = ('R' => 'moved', 'C' => 'copied');
4112 my $nstatus = $status_name{$diff->{'status'}};
4114 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4115 # mode also for directories, so we cannot use $to_mode_str
4116 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4119 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4120 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4121 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4122 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4123 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4124 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4125 -class => "list"}, esc_path
($diff->{'from_file'})) .
4126 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4127 "<td class=\"link\">";
4128 if ($action eq 'commitdiff') {
4131 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4133 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4134 # "commit" view and modified file (not only pure rename or copy)
4135 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4136 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4137 hash_base
=>$hash, hash_parent_base
=>$parent,
4138 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4142 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4143 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4146 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4147 file_name
=>$diff->{'to_file'})},
4150 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4151 file_name
=>$diff->{'to_file'})},
4155 } # we should not encounter Unmerged (U) or Unknown (X) status
4158 print "</tbody>" if $has_header;
4162 sub git_patchset_body
{
4163 my ($fd, $difftree, $hash, @hash_parents) = @_;
4164 my ($hash_parent) = $hash_parents[0];
4166 my $is_combined = (@hash_parents > 1);
4168 my $patch_number = 0;
4174 print "<div class=\"patchset\">\n";
4176 # skip to first patch
4177 while ($patch_line = <$fd>) {
4180 last if ($patch_line =~ m/^diff /);
4184 while ($patch_line) {
4186 # parse "git diff" header line
4187 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4188 # $1 is from_name, which we do not use
4189 $to_name = unquote
($2);
4190 $to_name =~ s!^b/!!;
4191 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4192 # $1 is 'cc' or 'combined', which we do not use
4193 $to_name = unquote
($2);
4198 # check if current patch belong to current raw line
4199 # and parse raw git-diff line if needed
4200 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4201 # this is continuation of a split patch
4202 print "<div class=\"patch cont\">\n";
4204 # advance raw git-diff output if needed
4205 $patch_idx++ if defined $diffinfo;
4207 # read and prepare patch information
4208 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4210 # compact combined diff output can have some patches skipped
4211 # find which patch (using pathname of result) we are at now;
4213 while ($to_name ne $diffinfo->{'to_file'}) {
4214 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4215 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4216 "</div>\n"; # class="patch"
4221 last if $patch_idx > $#$difftree;
4222 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4226 # modifies %from, %to hashes
4227 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4229 # this is first patch for raw difftree line with $patch_idx index
4230 # we index @$difftree array from 0, but number patches from 1
4231 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4235 #assert($patch_line =~ m/^diff /) if DEBUG;
4236 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4238 # print "git diff" header
4239 print format_git_diff_header_line
($patch_line, $diffinfo,
4242 # print extended diff header
4243 print "<div class=\"diff extended_header\">\n";
4245 while ($patch_line = <$fd>) {
4248 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4250 print format_extended_diff_header_line
($patch_line, $diffinfo,
4253 print "</div>\n"; # class="diff extended_header"
4255 # from-file/to-file diff header
4256 if (! $patch_line) {
4257 print "</div>\n"; # class="patch"
4260 next PATCH
if ($patch_line =~ m/^diff /);
4261 #assert($patch_line =~ m/^---/) if DEBUG;
4263 my $last_patch_line = $patch_line;
4264 $patch_line = <$fd>;
4266 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4268 print format_diff_from_to_header
($last_patch_line, $patch_line,
4269 $diffinfo, \
%from, \
%to,
4274 while ($patch_line = <$fd>) {
4277 next PATCH
if ($patch_line =~ m/^diff /);
4279 print format_diff_line
($patch_line, \
%from, \
%to);
4283 print "</div>\n"; # class="patch"
4286 # for compact combined (--cc) format, with chunk and patch simpliciaction
4287 # patchset might be empty, but there might be unprocessed raw lines
4288 for (++$patch_idx if $patch_number > 0;
4289 $patch_idx < @
$difftree;
4291 # read and prepare patch information
4292 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4294 # generate anchor for "patch" links in difftree / whatchanged part
4295 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4296 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4297 "</div>\n"; # class="patch"
4302 if ($patch_number == 0) {
4303 if (@hash_parents > 1) {
4304 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4306 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4310 print "</div>\n"; # class="patchset"
4313 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4315 # fills project list info (age, description, owner, forks) for each
4316 # project in the list, removing invalid projects from returned list
4317 # NOTE: modifies $projlist, but does not remove entries from it
4318 sub fill_project_list_info
{
4319 my ($projlist, $check_forks) = @_;
4322 my $show_ctags = gitweb_check_feature
('ctags');
4324 foreach my $pr (@
$projlist) {
4325 my (@activity) = git_get_last_activity
($pr->{'path'});
4326 unless (@activity) {
4329 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4330 if (!defined $pr->{'descr'}) {
4331 my $descr = git_get_project_description
($pr->{'path'}) || "";
4332 $descr = to_utf8
($descr);
4333 $pr->{'descr_long'} = $descr;
4334 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4336 if (!defined $pr->{'owner'}) {
4337 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4340 my $pname = $pr->{'path'};
4341 if (($pname =~ s/\.git$//) &&
4342 ($pname !~ /\/$/) &&
4343 (-d
"$projectroot/$pname")) {
4344 $pr->{'forks'} = "-d $projectroot/$pname";
4349 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4350 push @projects, $pr;
4356 # print 'sort by' <th> element, generating 'sort by $name' replay link
4357 # if that order is not selected
4359 print format_sort_th
(@_);
4362 sub format_sort_th
{
4363 my ($name, $order, $header) = @_;
4365 $header ||= ucfirst($name);
4367 if ($order eq $name) {
4368 $sort_th .= "<th>$header</th>\n";
4370 $sort_th .= "<th>" .
4371 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4372 -class => "header"}, $header) .
4379 sub git_project_list_body
{
4380 # actually uses global variable $project
4381 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4383 my $check_forks = gitweb_check_feature
('forks');
4384 my @projects = fill_project_list_info
($projlist, $check_forks);
4386 $order ||= $default_projects_order;
4387 $from = 0 unless defined $from;
4388 $to = $#projects if (!defined $to || $#projects < $to);
4391 project
=> { key
=> 'path', type
=> 'str' },
4392 descr
=> { key
=> 'descr_long', type
=> 'str' },
4393 owner
=> { key
=> 'owner', type
=> 'str' },
4394 age
=> { key
=> 'age', type
=> 'num' }
4396 my $oi = $order_info{$order};
4397 if ($oi->{'type'} eq 'str') {
4398 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4400 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4403 my $show_ctags = gitweb_check_feature
('ctags');
4406 foreach my $p (@projects) {
4407 foreach my $ct (keys %{$p->{'ctags'}}) {
4408 $ctags{$ct} += $p->{'ctags'}->{$ct};
4411 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4412 print git_show_project_tagcloud
($cloud, 64);
4415 print "<table class=\"project_list\">\n";
4416 unless ($no_header) {
4419 print "<th></th>\n";
4421 print_sort_th
('project', $order, 'Project');
4422 print_sort_th
('descr', $order, 'Description');
4423 print_sort_th
('owner', $order, 'Owner');
4424 print_sort_th
('age', $order, 'Last Change');
4425 print "<th></th>\n" . # for links
4429 my $tagfilter = $cgi->param('by_tag');
4430 for (my $i = $from; $i <= $to; $i++) {
4431 my $pr = $projects[$i];
4433 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4434 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4435 and not $pr->{'descr_long'} =~ /$searchtext/;
4436 # Weed out forks or non-matching entries of search
4438 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4439 $forkbase="^$forkbase" if $forkbase;
4440 next if not $searchtext and not $tagfilter and $show_ctags
4441 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4445 print "<tr class=\"dark\">\n";
4447 print "<tr class=\"light\">\n";
4452 if ($pr->{'forks'}) {
4453 print "<!-- $pr->{'forks'} -->\n";
4454 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4458 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4459 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4460 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4461 -class => "list", -title
=> $pr->{'descr_long'}},
4462 esc_html
($pr->{'descr'})) . "</td>\n" .
4463 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4464 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4465 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4466 "<td class=\"link\">" .
4467 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4468 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4469 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4470 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4471 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4475 if (defined $extra) {
4478 print "<td></td>\n";
4480 print "<td colspan=\"5\">$extra</td>\n" .
4487 # uses global variable $project
4488 my ($commitlist, $from, $to, $refs, $extra) = @_;
4490 $from = 0 unless defined $from;
4491 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4493 for (my $i = 0; $i <= $to; $i++) {
4494 my %co = %{$commitlist->[$i]};
4496 my $commit = $co{'id'};
4497 my $ref = format_ref_marker
($refs, $commit);
4498 my %ad = parse_date
($co{'author_epoch'});
4499 git_print_header_div
('commit',
4500 "<span class=\"age\">$co{'age_string'}</span>" .
4501 esc_html
($co{'title'}) . $ref,
4503 print "<div class=\"title_text\">\n" .
4504 "<div class=\"log_link\">\n" .
4505 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4507 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4509 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4512 git_print_authorship
(\
%co, -tag
=> 'span');
4513 print "<br/>\n</div>\n";
4515 print "<div class=\"log_body\">\n";
4516 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4520 print "<div class=\"page_nav\">\n";
4526 sub git_shortlog_body
{
4527 # uses global variable $project
4528 my ($commitlist, $from, $to, $refs, $extra) = @_;
4530 $from = 0 unless defined $from;
4531 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4533 print "<table class=\"shortlog\">\n";
4535 for (my $i = $from; $i <= $to; $i++) {
4536 my %co = %{$commitlist->[$i]};
4537 my $commit = $co{'id'};
4538 my $ref = format_ref_marker
($refs, $commit);
4540 print "<tr class=\"dark\">\n";
4542 print "<tr class=\"light\">\n";
4545 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4546 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4547 format_author_html
('td', \
%co, 10) . "<td>";
4548 print format_subject_html
($co{'title'}, $co{'title_short'},
4549 href
(action
=>"commit", hash
=>$commit), $ref);
4551 "<td class=\"link\">" .
4552 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4553 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4554 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4555 my $snapshot_links = format_snapshot_links
($commit);
4556 if (defined $snapshot_links) {
4557 print " | " . $snapshot_links;
4562 if (defined $extra) {
4564 "<td colspan=\"4\">$extra</td>\n" .
4570 sub git_history_body
{
4571 # Warning: assumes constant type (blob or tree) during history
4572 my ($commitlist, $from, $to, $refs, $extra,
4573 $file_name, $file_hash, $ftype) = @_;
4575 $from = 0 unless defined $from;
4576 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4578 print "<table class=\"history\">\n";
4580 for (my $i = $from; $i <= $to; $i++) {
4581 my %co = %{$commitlist->[$i]};
4585 my $commit = $co{'id'};
4587 my $ref = format_ref_marker
($refs, $commit);
4590 print "<tr class=\"dark\">\n";
4592 print "<tr class=\"light\">\n";
4595 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4596 # shortlog: format_author_html('td', \%co, 10)
4597 format_author_html
('td', \
%co, 15, 3) . "<td>";
4598 # originally git_history used chop_str($co{'title'}, 50)
4599 print format_subject_html
($co{'title'}, $co{'title_short'},
4600 href
(action
=>"commit", hash
=>$commit), $ref);
4602 "<td class=\"link\">" .
4603 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4604 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4606 if ($ftype eq 'blob') {
4607 my $blob_current = $file_hash;
4608 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4609 if (defined $blob_current && defined $blob_parent &&
4610 $blob_current ne $blob_parent) {
4612 $cgi->a({-href
=> href
(action
=>"blobdiff",
4613 hash
=>$blob_current, hash_parent
=>$blob_parent,
4614 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4615 file_name
=>$file_name)},
4622 if (defined $extra) {
4624 "<td colspan=\"4\">$extra</td>\n" .
4631 # uses global variable $project
4632 my ($taglist, $from, $to, $extra) = @_;
4633 $from = 0 unless defined $from;
4634 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4636 print "<table class=\"tags\">\n";
4638 for (my $i = $from; $i <= $to; $i++) {
4639 my $entry = $taglist->[$i];
4641 my $comment = $tag{'subject'};
4643 if (defined $comment) {
4644 $comment_short = chop_str
($comment, 30, 5);
4647 print "<tr class=\"dark\">\n";
4649 print "<tr class=\"light\">\n";
4652 if (defined $tag{'age'}) {
4653 print "<td><i>$tag{'age'}</i></td>\n";
4655 print "<td></td>\n";
4658 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4659 -class => "list name"}, esc_html
($tag{'name'})) .
4662 if (defined $comment) {
4663 print format_subject_html
($comment, $comment_short,
4664 href
(action
=>"tag", hash
=>$tag{'id'}));
4667 "<td class=\"selflink\">";
4668 if ($tag{'type'} eq "tag") {
4669 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4674 "<td class=\"link\">" . " | " .
4675 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4676 if ($tag{'reftype'} eq "commit") {
4677 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4678 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4679 } elsif ($tag{'reftype'} eq "blob") {
4680 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4685 if (defined $extra) {
4687 "<td colspan=\"5\">$extra</td>\n" .
4693 sub git_heads_body
{
4694 # uses global variable $project
4695 my ($headlist, $head, $from, $to, $extra) = @_;
4696 $from = 0 unless defined $from;
4697 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4699 print "<table class=\"heads\">\n";
4701 for (my $i = $from; $i <= $to; $i++) {
4702 my $entry = $headlist->[$i];
4704 my $curr = $ref{'id'} eq $head;
4706 print "<tr class=\"dark\">\n";
4708 print "<tr class=\"light\">\n";
4711 print "<td><i>$ref{'age'}</i></td>\n" .
4712 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4713 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4714 -class => "list name"},esc_html
($ref{'name'})) .
4716 "<td class=\"link\">" .
4717 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4718 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4719 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4723 if (defined $extra) {
4725 "<td colspan=\"3\">$extra</td>\n" .
4731 sub git_search_grep_body
{
4732 my ($commitlist, $from, $to, $extra) = @_;
4733 $from = 0 unless defined $from;
4734 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4736 print "<table class=\"commit_search\">\n";
4738 for (my $i = $from; $i <= $to; $i++) {
4739 my %co = %{$commitlist->[$i]};
4743 my $commit = $co{'id'};
4745 print "<tr class=\"dark\">\n";
4747 print "<tr class=\"light\">\n";
4750 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4751 format_author_html
('td', \
%co, 15, 5) .
4753 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4754 -class => "list subject"},
4755 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4756 my $comment = $co{'comment'};
4757 foreach my $line (@
$comment) {
4758 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4759 my ($lead, $match, $trail) = ($1, $2, $3);
4760 $match = chop_str
($match, 70, 5, 'center');
4761 my $contextlen = int((80 - length($match))/2);
4762 $contextlen = 30 if ($contextlen > 30);
4763 $lead = chop_str
($lead, $contextlen, 10, 'left');
4764 $trail = chop_str
($trail, $contextlen, 10, 'right');
4766 $lead = esc_html
($lead);
4767 $match = esc_html
($match);
4768 $trail = esc_html
($trail);
4770 print "$lead<span class=\"match\">$match</span>$trail<br />";
4774 "<td class=\"link\">" .
4775 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4777 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4779 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4783 if (defined $extra) {
4785 "<td colspan=\"3\">$extra</td>\n" .
4791 ## ======================================================================
4792 ## ======================================================================
4795 sub git_project_list
{
4796 my $order = $input_params{'order'};
4797 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4798 die_error
(400, "Unknown order parameter");
4801 my @list = git_get_projects_list
();
4803 die_error
(404, "No projects found");
4807 if (defined $home_text && -f
$home_text) {
4808 print "<div class=\"index_include\">\n";
4809 insert_file
($home_text);
4812 print $cgi->startform(-method
=> "get") .
4813 "<p class=\"projsearch\">Search:\n" .
4814 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4816 $cgi->end_form() . "\n";
4817 git_project_list_body
(\
@list, $order);
4822 my $order = $input_params{'order'};
4823 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4824 die_error
(400, "Unknown order parameter");
4827 my @list = git_get_projects_list
($project);
4829 die_error
(404, "No forks found");
4833 git_print_page_nav
('','');
4834 git_print_header_div
('summary', "$project forks");
4835 git_project_list_body
(\
@list, $order);
4839 sub git_project_index
{
4840 my @projects = git_get_projects_list
($project);
4843 -type
=> 'text/plain',
4844 -charset
=> 'utf-8',
4845 -content_disposition
=> 'inline; filename="index.aux"');
4847 foreach my $pr (@projects) {
4848 if (!exists $pr->{'owner'}) {
4849 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4852 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4853 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4854 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4855 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4859 print "$path $owner\n";
4864 my $descr = git_get_project_description
($project) || "none";
4865 my %co = parse_commit
("HEAD");
4866 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4867 my $head = $co{'id'};
4869 my $owner = git_get_project_owner
($project);
4871 my $refs = git_get_references
();
4872 # These get_*_list functions return one more to allow us to see if
4873 # there are more ...
4874 my @taglist = git_get_tags_list
(16);
4875 my @headlist = git_get_heads_list
(16);
4877 my $check_forks = gitweb_check_feature
('forks');
4880 @forklist = git_get_projects_list
($project);
4884 git_print_page_nav
('summary','', $head);
4886 print "<div class=\"title\"> </div>\n";
4887 print "<table class=\"projects_list\">\n" .
4888 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4889 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4890 if (defined $cd{'rfc2822'}) {
4891 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4894 # use per project git URL list in $projectroot/$project/cloneurl
4895 # or make project git URL from git base URL and project name
4896 my $url_tag = "URL";
4897 my @url_list = git_get_project_url_list
($project);
4898 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4899 foreach my $git_url (@url_list) {
4900 next unless $git_url;
4901 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4906 my $show_ctags = gitweb_check_feature
('ctags');
4908 my $ctags = git_get_project_ctags
($project);
4909 my $cloud = git_populate_project_tagcloud
($ctags);
4910 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4911 print "</td>\n<td>" unless %$ctags;
4912 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4913 print "</td>\n<td>" if %$ctags;
4914 print git_show_project_tagcloud
($cloud, 48);
4920 # If XSS prevention is on, we don't include README.html.
4921 # TODO: Allow a readme in some safe format.
4922 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4923 print "<div class=\"title\">readme</div>\n" .
4924 "<div class=\"readme\">\n";
4925 insert_file
("$projectroot/$project/README.html");
4926 print "\n</div>\n"; # class="readme"
4929 # we need to request one more than 16 (0..15) to check if
4931 my @commitlist = $head ? parse_commits
($head, 17) : ();
4933 git_print_header_div
('shortlog');
4934 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4935 $#commitlist <= 15 ?
undef :
4936 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4940 git_print_header_div
('tags');
4941 git_tags_body
(\
@taglist, 0, 15,
4942 $#taglist <= 15 ?
undef :
4943 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4947 git_print_header_div
('heads');
4948 git_heads_body
(\
@headlist, $head, 0, 15,
4949 $#headlist <= 15 ?
undef :
4950 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4954 git_print_header_div
('forks');
4955 git_project_list_body
(\
@forklist, 'age', 0, 15,
4956 $#forklist <= 15 ?
undef :
4957 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4965 my $head = git_get_head_hash
($project);
4967 git_print_page_nav
('','', $head,undef,$head);
4968 my %tag = parse_tag
($hash);
4971 die_error
(404, "Unknown tag object");
4974 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4975 print "<div class=\"title_text\">\n" .
4976 "<table class=\"object_header\">\n" .
4978 "<td>object</td>\n" .
4979 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4980 $tag{'object'}) . "</td>\n" .
4981 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4982 $tag{'type'}) . "</td>\n" .
4984 if (defined($tag{'author'})) {
4985 git_print_authorship_rows
(\
%tag, 'author');
4987 print "</table>\n\n" .
4989 print "<div class=\"page_body\">";
4990 my $comment = $tag{'comment'};
4991 foreach my $line (@
$comment) {
4993 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4999 sub git_blame_common
{
5000 my $format = shift || 'porcelain';
5001 if ($format eq 'porcelain' && $cgi->param('js')) {
5002 $format = 'incremental';
5003 $action = 'blame_incremental'; # for page title etc
5007 gitweb_check_feature
('blame')
5008 or die_error
(403, "Blame view not allowed");
5011 die_error
(400, "No file name given") unless $file_name;
5012 $hash_base ||= git_get_head_hash
($project);
5013 die_error
(404, "Couldn't find base commit") unless $hash_base;
5014 my %co = parse_commit
($hash_base)
5015 or die_error
(404, "Commit not found");
5017 if (!defined $hash) {
5018 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
5019 or die_error
(404, "Error looking up file");
5021 $ftype = git_get_type
($hash);
5022 if ($ftype !~ "blob") {
5023 die_error
(400, "Object is not a blob");
5028 if ($format eq 'incremental') {
5029 # get file contents (as base)
5030 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
5031 or die_error
(500, "Open git-cat-file failed");
5032 } elsif ($format eq 'data') {
5033 # run git-blame --incremental
5034 open $fd, "-|", git_cmd
(), "blame", "--incremental",
5035 $hash_base, "--", $file_name
5036 or die_error
(500, "Open git-blame --incremental failed");
5038 # run git-blame --porcelain
5039 open $fd, "-|", git_cmd
(), "blame", '-p',
5040 $hash_base, '--', $file_name
5041 or die_error
(500, "Open git-blame --porcelain failed");
5044 # incremental blame data returns early
5045 if ($format eq 'data') {
5047 -type
=>"text/plain", -charset
=> "utf-8",
5048 -status
=> "200 OK");
5049 local $| = 1; # output autoflush
5052 or print "ERROR $!\n";
5055 if (defined $t0 && gitweb_check_feature
('timed')) {
5057 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5058 ' '.$number_of_git_cmds;
5068 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5071 if ($format eq 'incremental') {
5073 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5074 "blame") . " (non-incremental)";
5077 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5078 "blame") . " (incremental)";
5082 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5085 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5087 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5088 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5089 git_print_page_path
($file_name, $ftype, $hash_base);
5092 if ($format eq 'incremental') {
5093 print "<noscript>\n<div class=\"error\"><center><b>\n".
5094 "This page requires JavaScript to run.\n Use ".
5095 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5098 "</b></center></div>\n</noscript>\n";
5100 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5103 print qq!<div
class="page_body">\n!;
5104 print qq!<div id
="progress_info">... / ...</div
>\n!
5105 if ($format eq 'incremental');
5106 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5107 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5109 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5113 my @rev_color = qw(light dark);
5114 my $num_colors = scalar(@rev_color);
5115 my $current_color = 0;
5117 if ($format eq 'incremental') {
5118 my $color_class = $rev_color[$current_color];
5123 while (my $line = <$fd>) {
5127 print qq!<tr id
="l$linenr" class="$color_class">!.
5128 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5129 qq!<td
class="linenr">!.
5130 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5131 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5135 } else { # porcelain, i.e. ordinary blame
5136 my %metainfo = (); # saves information about commits
5140 while (my $line = <$fd>) {
5142 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5143 # no <lines in group> for subsequent lines in group of lines
5144 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5145 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5146 if (!exists $metainfo{$full_rev}) {
5147 $metainfo{$full_rev} = { 'nprevious' => 0 };
5149 my $meta = $metainfo{$full_rev};
5151 while ($data = <$fd>) {
5153 last if ($data =~ s/^\t//); # contents of line
5154 if ($data =~ /^(\S+)(?: (.*))?$/) {
5155 $meta->{$1} = $2 unless exists $meta->{$1};
5157 if ($data =~ /^previous /) {
5158 $meta->{'nprevious'}++;
5161 my $short_rev = substr($full_rev, 0, 8);
5162 my $author = $meta->{'author'};
5164 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5165 my $date = $date{'iso-tz'};
5167 $current_color = ($current_color + 1) % $num_colors;
5169 my $tr_class = $rev_color[$current_color];
5170 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5171 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5172 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5173 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5175 print "<td class=\"sha1\"";
5176 print " title=\"". esc_html
($author) . ", $date\"";
5177 print " rowspan=\"$group_size\"" if ($group_size > 1);
5179 print $cgi->a({-href
=> href
(action
=>"commit",
5181 file_name
=>$file_name)},
5182 esc_html
($short_rev));
5183 if ($group_size >= 2) {
5184 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5185 if (@author_initials) {
5187 esc_html
(join('', @author_initials));
5193 # 'previous' <sha1 of parent commit> <filename at commit>
5194 if (exists $meta->{'previous'} &&
5195 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5196 $meta->{'parent'} = $1;
5197 $meta->{'file_parent'} = unquote
($2);
5200 exists($meta->{'parent'}) ?
5201 $meta->{'parent'} : $full_rev;
5202 my $linenr_filename =
5203 exists($meta->{'file_parent'}) ?
5204 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5205 my $blamed = href
(action
=> 'blame',
5206 file_name
=> $linenr_filename,
5207 hash_base
=> $linenr_commit);
5208 print "<td class=\"linenr\">";
5209 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5210 -class => "linenr" },
5213 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5221 "</table>\n"; # class="blame"
5222 print "</div>\n"; # class="blame_body"
5224 or print "Reading blob failed\n";
5233 sub git_blame_incremental
{
5234 git_blame_common
('incremental');
5237 sub git_blame_data
{
5238 git_blame_common
('data');
5242 my $head = git_get_head_hash
($project);
5244 git_print_page_nav
('','', $head,undef,$head);
5245 git_print_header_div
('summary', $project);
5247 my @tagslist = git_get_tags_list
();
5249 git_tags_body
(\
@tagslist);
5255 my $head = git_get_head_hash
($project);
5257 git_print_page_nav
('','', $head,undef,$head);
5258 git_print_header_div
('summary', $project);
5260 my @headslist = git_get_heads_list
();
5262 git_heads_body
(\
@headslist, $head);
5267 sub git_blob_plain
{
5271 if (!defined $hash) {
5272 if (defined $file_name) {
5273 my $base = $hash_base || git_get_head_hash
($project);
5274 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5275 or die_error
(404, "Cannot find file");
5277 die_error
(400, "No file name defined");
5279 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5280 # blobs defined by non-textual hash id's can be cached
5284 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5285 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5287 # content-type (can include charset)
5288 $type = blob_contenttype
($fd, $file_name, $type);
5290 # "save as" filename, even when no $file_name is given
5291 my $save_as = "$hash";
5292 if (defined $file_name) {
5293 $save_as = $file_name;
5294 } elsif ($type =~ m/^text\//) {
5298 # With XSS prevention on, blobs of all types except a few known safe
5299 # ones are served with "Content-Disposition: attachment" to make sure
5300 # they don't run in our security domain. For certain image types,
5301 # blob view writes an <img> tag referring to blob_plain view, and we
5302 # want to be sure not to break that by serving the image as an
5303 # attachment (though Firefox 3 doesn't seem to care).
5304 my $sandbox = $prevent_xss &&
5305 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5309 -expires
=> $expires,
5310 -content_disposition
=>
5311 ($sandbox ?
'attachment' : 'inline')
5312 . '; filename="' . $save_as . '"');
5314 binmode STDOUT
, ':raw';
5316 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5323 if (!defined $hash) {
5324 if (defined $file_name) {
5325 my $base = $hash_base || git_get_head_hash
($project);
5326 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5327 or die_error
(404, "Cannot find file");
5329 die_error
(400, "No file name defined");
5331 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5332 # blobs defined by non-textual hash id's can be cached
5336 my $have_blame = gitweb_check_feature
('blame');
5337 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5338 or die_error
(500, "Couldn't cat $file_name, $hash");
5339 my $mimetype = blob_mimetype
($fd, $file_name);
5340 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5342 return git_blob_plain
($mimetype);
5344 # we can have blame only for text/* mimetype
5345 $have_blame &&= ($mimetype =~ m!^text/!);
5347 git_header_html
(undef, $expires);
5348 my $formats_nav = '';
5349 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5350 if (defined $file_name) {
5353 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5358 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5361 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5364 $cgi->a({-href
=> href
(action
=>"blob",
5365 hash_base
=>"HEAD", file_name
=>$file_name)},
5369 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5372 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5373 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5375 print "<div class=\"page_nav\">\n" .
5376 "<br/><br/></div>\n" .
5377 "<div class=\"title\">$hash</div>\n";
5379 git_print_page_path
($file_name, "blob", $hash_base);
5380 print "<div class=\"page_body\">\n";
5381 if ($mimetype =~ m!^image/!) {
5382 print qq!<img type
="$mimetype"!;
5384 print qq! alt
="$file_name" title
="$file_name"!;
5387 href(action=>"blob_plain
", hash=>$hash,
5388 hash_base=>$hash_base, file_name=>$file_name) .
5392 while (my $line = <$fd>) {
5395 $line = untabify
($line);
5396 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5397 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5398 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5402 or print "Reading blob failed.\n";
5408 if (!defined $hash_base) {
5409 $hash_base = "HEAD";
5411 if (!defined $hash) {
5412 if (defined $file_name) {
5413 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5418 die_error
(404, "No such tree") unless defined($hash);
5420 my $show_sizes = gitweb_check_feature
('show-sizes');
5421 my $have_blame = gitweb_check_feature
('blame');
5426 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5427 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5428 or die_error
(500, "Open git-ls-tree failed");
5429 @entries = map { chomp; $_ } <$fd>;
5431 or die_error
(404, "Reading tree failed");
5434 my $refs = git_get_references
();
5435 my $ref = format_ref_marker
($refs, $hash_base);
5438 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5440 if (defined $file_name) {
5442 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5444 $cgi->a({-href
=> href
(action
=>"tree",
5445 hash_base
=>"HEAD", file_name
=>$file_name)},
5448 my $snapshot_links = format_snapshot_links
($hash);
5449 if (defined $snapshot_links) {
5450 # FIXME: Should be available when we have no hash base as well.
5451 push @views_nav, $snapshot_links;
5453 git_print_page_nav
('tree','', $hash_base, undef, undef,
5454 join(' | ', @views_nav));
5455 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5458 print "<div class=\"page_nav\">\n";
5459 print "<br/><br/></div>\n";
5460 print "<div class=\"title\">$hash</div>\n";
5462 if (defined $file_name) {
5463 $basedir = $file_name;
5464 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5467 git_print_page_path
($file_name, 'tree', $hash_base);
5469 print "<div class=\"page_body\">\n";
5470 print "<table class=\"tree\">\n";
5472 # '..' (top directory) link if possible
5473 if (defined $hash_base &&
5474 defined $file_name && $file_name =~ m![^/]+$!) {
5476 print "<tr class=\"dark\">\n";
5478 print "<tr class=\"light\">\n";
5482 my $up = $file_name;
5483 $up =~ s!/?[^/]+$!!;
5484 undef $up unless $up;
5485 # based on git_print_tree_entry
5486 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5487 print '<td class="size"> </td>'."\n" if $show_sizes;
5488 print '<td class="list">';
5489 print $cgi->a({-href
=> href
(action
=>"tree",
5490 hash_base
=>$hash_base,
5494 print "<td class=\"link\"></td>\n";
5498 foreach my $line (@entries) {
5499 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5502 print "<tr class=\"dark\">\n";
5504 print "<tr class=\"light\">\n";
5508 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5512 print "</table>\n" .
5518 my ($project, $hash) = @_;
5520 # path/to/project.git -> project
5521 # path/to/project/.git -> project
5522 my $name = to_utf8
($project);
5523 $name =~ s
,([^/])/*\
.git
$,$1,;
5524 $name = basename
($name);
5526 $name =~ s/[[:cntrl:]]/?/g;
5529 if ($hash =~ /^[0-9a-fA-F]+$/) {
5530 # shorten SHA-1 hash
5531 my $full_hash = git_get_full_hash
($project, $hash);
5532 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5533 $ver = git_get_short_hash
($project, $hash);
5535 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5536 # tags don't need shortened SHA-1 hash
5539 # branches and other need shortened SHA-1 hash
5540 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5543 $ver .= '-' . git_get_short_hash
($project, $hash);
5545 # in case of hierarchical branch names
5548 # name = project-version_string
5549 $name = "$name-$ver";
5551 return wantarray ?
($name, $name) : $name;
5555 my $format = $input_params{'snapshot_format'};
5556 if (!@snapshot_fmts) {
5557 die_error
(403, "Snapshots not allowed");
5559 # default to first supported snapshot format
5560 $format ||= $snapshot_fmts[0];
5561 if ($format !~ m/^[a-z0-9]+$/) {
5562 die_error
(400, "Invalid snapshot format parameter");
5563 } elsif (!exists($known_snapshot_formats{$format})) {
5564 die_error
(400, "Unknown snapshot format");
5565 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5566 die_error
(403, "Snapshot format not allowed");
5567 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5568 die_error
(403, "Unsupported snapshot format");
5571 my $type = git_get_type
("$hash^{}");
5573 die_error
(404, 'Object does not exist');
5574 } elsif ($type eq 'blob') {
5575 die_error
(400, 'Object is not a tree-ish');
5578 my ($name, $prefix) = snapshot_name
($project, $hash);
5579 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5580 my $cmd = quote_command
(
5581 git_cmd
(), 'archive',
5582 "--format=$known_snapshot_formats{$format}{'format'}",
5583 "--prefix=$prefix/", $hash);
5584 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5585 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5588 $filename =~ s/(["\\])/\\$1/g;
5590 -type
=> $known_snapshot_formats{$format}{'type'},
5591 -content_disposition
=> 'inline; filename="' . $filename . '"',
5592 -status
=> '200 OK');
5594 open my $fd, "-|", $cmd
5595 or die_error
(500, "Execute git-archive failed");
5596 binmode STDOUT
, ':raw';
5598 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5602 sub git_log_generic
{
5603 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5605 my $head = git_get_head_hash
($project);
5606 if (!defined $base) {
5609 if (!defined $page) {
5612 my $refs = git_get_references
();
5614 my $commit_hash = $base;
5615 if (defined $parent) {
5616 $commit_hash = "$parent..$base";
5619 parse_commits
($commit_hash, 101, (100 * $page),
5620 defined $file_name ?
($file_name, "--full-history") : ());
5623 if (!defined $file_hash && defined $file_name) {
5624 # some commits could have deleted file in question,
5625 # and not have it in tree, but one of them has to have it
5626 for (my $i = 0; $i < @commitlist; $i++) {
5627 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5628 last if defined $file_hash;
5631 if (defined $file_hash) {
5632 $ftype = git_get_type
($file_hash);
5634 if (defined $file_name && !defined $ftype) {
5635 die_error
(500, "Unknown type of object");
5638 if (defined $file_name) {
5639 %co = parse_commit
($base)
5640 or die_error
(404, "Unknown commit object");
5644 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5646 if ($#commitlist >= 100) {
5648 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5649 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5651 my $patch_max = gitweb_get_feature
('patches');
5652 if ($patch_max && !defined $file_name) {
5653 if ($patch_max < 0 || @commitlist <= $patch_max) {
5654 $paging_nav .= " ⋅ " .
5655 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5661 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5662 if (defined $file_name) {
5663 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5665 git_print_header_div
('summary', $project)
5667 git_print_page_path
($file_name, $ftype, $hash_base)
5668 if (defined $file_name);
5670 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5671 $file_name, $file_hash, $ftype);
5677 git_log_generic
('log', \
&git_log_body
,
5678 $hash, $hash_parent);
5682 $hash ||= $hash_base || "HEAD";
5683 my %co = parse_commit
($hash)
5684 or die_error
(404, "Unknown commit object");
5686 my $parent = $co{'parent'};
5687 my $parents = $co{'parents'}; # listref
5689 # we need to prepare $formats_nav before any parameter munging
5691 if (!defined $parent) {
5693 $formats_nav .= '(initial)';
5694 } elsif (@
$parents == 1) {
5695 # single parent commit
5698 $cgi->a({-href
=> href
(action
=>"commit",
5700 esc_html
(substr($parent, 0, 7))) .
5707 $cgi->a({-href
=> href
(action
=>"commit",
5709 esc_html
(substr($_, 0, 7)));
5713 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5714 $formats_nav .= " | " .
5715 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5719 if (!defined $parent) {
5723 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5725 (@
$parents <= 1 ?
$parent : '-c'),
5727 or die_error
(500, "Open git-diff-tree failed");
5728 @difftree = map { chomp; $_ } <$fd>;
5729 close $fd or die_error
(404, "Reading git-diff-tree failed");
5731 # non-textual hash id's can be cached
5733 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5736 my $refs = git_get_references
();
5737 my $ref = format_ref_marker
($refs, $co{'id'});
5739 git_header_html
(undef, $expires);
5740 git_print_page_nav
('commit', '',
5741 $hash, $co{'tree'}, $hash,
5744 if (defined $co{'parent'}) {
5745 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5747 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5749 print "<div class=\"title_text\">\n" .
5750 "<table class=\"object_header\">\n";
5751 git_print_authorship_rows
(\
%co);
5752 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5755 "<td class=\"sha1\">" .
5756 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5757 class => "list"}, $co{'tree'}) .
5759 "<td class=\"link\">" .
5760 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5762 my $snapshot_links = format_snapshot_links
($hash);
5763 if (defined $snapshot_links) {
5764 print " | " . $snapshot_links;
5769 foreach my $par (@
$parents) {
5772 "<td class=\"sha1\">" .
5773 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5774 class => "list"}, $par) .
5776 "<td class=\"link\">" .
5777 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5779 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5786 print "<div class=\"page_body\">\n";
5787 git_print_log
($co{'comment'});
5790 git_difftree_body
(\
@difftree, $hash, @
$parents);
5796 # object is defined by:
5797 # - hash or hash_base alone
5798 # - hash_base and file_name
5801 # - hash or hash_base alone
5802 if ($hash || ($hash_base && !defined $file_name)) {
5803 my $object_id = $hash || $hash_base;
5805 open my $fd, "-|", quote_command
(
5806 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5807 or die_error
(404, "Object does not exist");
5811 or die_error
(404, "Object does not exist");
5813 # - hash_base and file_name
5814 } elsif ($hash_base && defined $file_name) {
5815 $file_name =~ s
,/+$,,;
5817 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5818 or die_error
(404, "Base object does not exist");
5820 # here errors should not hapen
5821 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5822 or die_error
(500, "Open git-ls-tree failed");
5826 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5827 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5828 die_error
(404, "File or directory for given base does not exist");
5833 die_error
(400, "Not enough information to find object");
5836 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5837 hash
=>$hash, hash_base
=>$hash_base,
5838 file_name
=>$file_name),
5839 -status
=> '302 Found');
5843 my $format = shift || 'html';
5850 # preparing $fd and %diffinfo for git_patchset_body
5852 if (defined $hash_base && defined $hash_parent_base) {
5853 if (defined $file_name) {
5855 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5856 $hash_parent_base, $hash_base,
5857 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5858 or die_error
(500, "Open git-diff-tree failed");
5859 @difftree = map { chomp; $_ } <$fd>;
5861 or die_error
(404, "Reading git-diff-tree failed");
5863 or die_error
(404, "Blob diff not found");
5865 } elsif (defined $hash &&
5866 $hash =~ /[0-9a-fA-F]{40}/) {
5867 # try to find filename from $hash
5869 # read filtered raw output
5870 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5871 $hash_parent_base, $hash_base, "--"
5872 or die_error
(500, "Open git-diff-tree failed");
5874 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5876 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5877 map { chomp; $_ } <$fd>;
5879 or die_error
(404, "Reading git-diff-tree failed");
5881 or die_error
(404, "Blob diff not found");
5884 die_error
(400, "Missing one of the blob diff parameters");
5887 if (@difftree > 1) {
5888 die_error
(400, "Ambiguous blob diff specification");
5891 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5892 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5893 $file_name ||= $diffinfo{'to_file'};
5895 $hash_parent ||= $diffinfo{'from_id'};
5896 $hash ||= $diffinfo{'to_id'};
5898 # non-textual hash id's can be cached
5899 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5900 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5905 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5906 '-p', ($format eq 'html' ?
"--full-index" : ()),
5907 $hash_parent_base, $hash_base,
5908 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5909 or die_error
(500, "Open git-diff-tree failed");
5912 # old/legacy style URI -- not generated anymore since 1.4.3.
5914 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5918 if ($format eq 'html') {
5920 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5922 git_header_html
(undef, $expires);
5923 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5924 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5925 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5927 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5928 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5930 if (defined $file_name) {
5931 git_print_page_path
($file_name, "blob", $hash_base);
5933 print "<div class=\"page_path\"></div>\n";
5936 } elsif ($format eq 'plain') {
5938 -type
=> 'text/plain',
5939 -charset
=> 'utf-8',
5940 -expires
=> $expires,
5941 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5943 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5946 die_error
(400, "Unknown blobdiff format");
5950 if ($format eq 'html') {
5951 print "<div class=\"page_body\">\n";
5953 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5956 print "</div>\n"; # class="page_body"
5960 while (my $line = <$fd>) {
5961 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5962 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5966 last if $line =~ m!^\+\+\+!;
5974 sub git_blobdiff_plain
{
5975 git_blobdiff
('plain');
5978 sub git_commitdiff
{
5980 my $format = $params{-format
} || 'html';
5982 my ($patch_max) = gitweb_get_feature
('patches');
5983 if ($format eq 'patch') {
5984 die_error
(403, "Patch view not allowed") unless $patch_max;
5987 $hash ||= $hash_base || "HEAD";
5988 my %co = parse_commit
($hash)
5989 or die_error
(404, "Unknown commit object");
5991 # choose format for commitdiff for merge
5992 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5993 $hash_parent = '--cc';
5995 # we need to prepare $formats_nav before almost any parameter munging
5997 if ($format eq 'html') {
5999 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
6001 if ($patch_max && @
{$co{'parents'}} <= 1) {
6002 $formats_nav .= " | " .
6003 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
6007 if (defined $hash_parent &&
6008 $hash_parent ne '-c' && $hash_parent ne '--cc') {
6009 # commitdiff with two commits given
6010 my $hash_parent_short = $hash_parent;
6011 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
6012 $hash_parent_short = substr($hash_parent, 0, 7);
6016 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
6017 if ($co{'parents'}[$i] eq $hash_parent) {
6018 $formats_nav .= ' parent ' . ($i+1);
6022 $formats_nav .= ': ' .
6023 $cgi->a({-href
=> href
(action
=>"commitdiff",
6024 hash
=>$hash_parent)},
6025 esc_html
($hash_parent_short)) .
6027 } elsif (!$co{'parent'}) {
6029 $formats_nav .= ' (initial)';
6030 } elsif (scalar @
{$co{'parents'}} == 1) {
6031 # single parent commit
6034 $cgi->a({-href
=> href
(action
=>"commitdiff",
6035 hash
=>$co{'parent'})},
6036 esc_html
(substr($co{'parent'}, 0, 7))) .
6040 if ($hash_parent eq '--cc') {
6041 $formats_nav .= ' | ' .
6042 $cgi->a({-href
=> href
(action
=>"commitdiff",
6043 hash
=>$hash, hash_parent
=>'-c')},
6045 } else { # $hash_parent eq '-c'
6046 $formats_nav .= ' | ' .
6047 $cgi->a({-href
=> href
(action
=>"commitdiff",
6048 hash
=>$hash, hash_parent
=>'--cc')},
6054 $cgi->a({-href
=> href
(action
=>"commitdiff",
6056 esc_html
(substr($_, 0, 7)));
6057 } @
{$co{'parents'}} ) .
6062 my $hash_parent_param = $hash_parent;
6063 if (!defined $hash_parent_param) {
6064 # --cc for multiple parents, --root for parentless
6065 $hash_parent_param =
6066 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6072 if ($format eq 'html') {
6073 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6074 "--no-commit-id", "--patch-with-raw", "--full-index",
6075 $hash_parent_param, $hash, "--"
6076 or die_error
(500, "Open git-diff-tree failed");
6078 while (my $line = <$fd>) {
6080 # empty line ends raw part of diff-tree output
6082 push @difftree, scalar parse_difftree_raw_line
($line);
6085 } elsif ($format eq 'plain') {
6086 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6087 '-p', $hash_parent_param, $hash, "--"
6088 or die_error
(500, "Open git-diff-tree failed");
6089 } elsif ($format eq 'patch') {
6090 # For commit ranges, we limit the output to the number of
6091 # patches specified in the 'patches' feature.
6092 # For single commits, we limit the output to a single patch,
6093 # diverging from the git-format-patch default.
6094 my @commit_spec = ();
6096 if ($patch_max > 0) {
6097 push @commit_spec, "-$patch_max";
6099 push @commit_spec, '-n', "$hash_parent..$hash";
6101 if ($params{-single
}) {
6102 push @commit_spec, '-1';
6104 if ($patch_max > 0) {
6105 push @commit_spec, "-$patch_max";
6107 push @commit_spec, "-n";
6109 push @commit_spec, '--root', $hash;
6111 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6112 '--stdout', @commit_spec
6113 or die_error
(500, "Open git-format-patch failed");
6115 die_error
(400, "Unknown commitdiff format");
6118 # non-textual hash id's can be cached
6120 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6124 # write commit message
6125 if ($format eq 'html') {
6126 my $refs = git_get_references
();
6127 my $ref = format_ref_marker
($refs, $co{'id'});
6129 git_header_html
(undef, $expires);
6130 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6131 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6132 print "<div class=\"title_text\">\n" .
6133 "<table class=\"object_header\">\n";
6134 git_print_authorship_rows
(\
%co);
6137 print "<div class=\"page_body\">\n";
6138 if (@
{$co{'comment'}} > 1) {
6139 print "<div class=\"log\">\n";
6140 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6141 print "</div>\n"; # class="log"
6144 } elsif ($format eq 'plain') {
6145 my $refs = git_get_references
("tags");
6146 my $tagname = git_get_rev_name_tags
($hash);
6147 my $filename = basename
($project) . "-$hash.patch";
6150 -type
=> 'text/plain',
6151 -charset
=> 'utf-8',
6152 -expires
=> $expires,
6153 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6154 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6155 print "From: " . to_utf8
($co{'author'}) . "\n";
6156 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6157 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6159 print "X-Git-Tag: $tagname\n" if $tagname;
6160 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6162 foreach my $line (@
{$co{'comment'}}) {
6163 print to_utf8
($line) . "\n";
6166 } elsif ($format eq 'patch') {
6167 my $filename = basename
($project) . "-$hash.patch";
6170 -type
=> 'text/plain',
6171 -charset
=> 'utf-8',
6172 -expires
=> $expires,
6173 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6177 if ($format eq 'html') {
6178 my $use_parents = !defined $hash_parent ||
6179 $hash_parent eq '-c' || $hash_parent eq '--cc';
6180 git_difftree_body
(\
@difftree, $hash,
6181 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6184 git_patchset_body
($fd, \
@difftree, $hash,
6185 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6187 print "</div>\n"; # class="page_body"
6190 } elsif ($format eq 'plain') {
6194 or print "Reading git-diff-tree failed\n";
6195 } elsif ($format eq 'patch') {
6199 or print "Reading git-format-patch failed\n";
6203 sub git_commitdiff_plain
{
6204 git_commitdiff
(-format
=> 'plain');
6207 # format-patch-style patches
6209 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6213 git_commitdiff
(-format
=> 'patch');
6217 git_log_generic
('history', \
&git_history_body
,
6218 $hash_base, $hash_parent_base,
6223 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6224 if (!defined $searchtext) {
6225 die_error
(400, "Text field is empty");
6227 if (!defined $hash) {
6228 $hash = git_get_head_hash
($project);
6230 my %co = parse_commit
($hash);
6232 die_error
(404, "Unknown commit object");
6234 if (!defined $page) {
6238 $searchtype ||= 'commit';
6239 if ($searchtype eq 'pickaxe') {
6240 # pickaxe may take all resources of your box and run for several minutes
6241 # with every query - so decide by yourself how public you make this feature
6242 gitweb_check_feature
('pickaxe')
6243 or die_error
(403, "Pickaxe is disabled");
6245 if ($searchtype eq 'grep') {
6246 gitweb_check_feature
('grep')
6247 or die_error
(403, "Grep is disabled");
6252 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6254 if ($searchtype eq 'commit') {
6255 $greptype = "--grep=";
6256 } elsif ($searchtype eq 'author') {
6257 $greptype = "--author=";
6258 } elsif ($searchtype eq 'committer') {
6259 $greptype = "--committer=";
6261 $greptype .= $searchtext;
6262 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6263 $greptype, '--regexp-ignore-case',
6264 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6266 my $paging_nav = '';
6269 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6270 searchtext
=>$searchtext,
6271 searchtype
=>$searchtype)},
6273 $paging_nav .= " ⋅ " .
6274 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6275 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6277 $paging_nav .= "first";
6278 $paging_nav .= " ⋅ prev";
6281 if ($#commitlist >= 100) {
6283 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6284 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6285 $paging_nav .= " ⋅ $next_link";
6287 $paging_nav .= " ⋅ next";
6290 if ($#commitlist >= 100) {
6293 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6294 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6295 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6298 if ($searchtype eq 'pickaxe') {
6299 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6300 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6302 print "<table class=\"pickaxe search\">\n";
6305 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6306 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6307 ($search_use_regexp ?
'--pickaxe-regex' : ());
6310 while (my $line = <$fd>) {
6314 my %set = parse_difftree_raw_line
($line);
6315 if (defined $set{'commit'}) {
6316 # finish previous commit
6319 "<td class=\"link\">" .
6320 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6322 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6328 print "<tr class=\"dark\">\n";
6330 print "<tr class=\"light\">\n";
6333 %co = parse_commit
($set{'commit'});
6334 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6335 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6336 "<td><i>$author</i></td>\n" .
6338 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6339 -class => "list subject"},
6340 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6341 } elsif (defined $set{'to_id'}) {
6342 next if ($set{'to_id'} =~ m/^0{40}$/);
6344 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6345 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6347 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6353 # finish last commit (warning: repetition!)
6356 "<td class=\"link\">" .
6357 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6359 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6367 if ($searchtype eq 'grep') {
6368 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6369 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6371 print "<table class=\"grep_search\">\n";
6375 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6376 $search_use_regexp ?
('-E', '-i') : '-F',
6377 $searchtext, $co{'tree'};
6379 while (my $line = <$fd>) {
6381 my ($file, $lno, $ltext, $binary);
6382 last if ($matches++ > 1000);
6383 if ($line =~ /^Binary file (.+) matches$/) {
6387 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6389 if ($file ne $lastfile) {
6390 $lastfile and print "</td></tr>\n";
6392 print "<tr class=\"dark\">\n";
6394 print "<tr class=\"light\">\n";
6396 print "<td class=\"list\">".
6397 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6398 file_name
=>"$file"),
6399 -class => "list"}, esc_path
($file));
6400 print "</td><td>\n";
6404 print "<div class=\"binary\">Binary file</div>\n";
6406 $ltext = untabify
($ltext);
6407 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6408 $ltext = esc_html
($1, -nbsp
=>1);
6409 $ltext .= '<span class="match">';
6410 $ltext .= esc_html
($2, -nbsp
=>1);
6411 $ltext .= '</span>';
6412 $ltext .= esc_html
($3, -nbsp
=>1);
6414 $ltext = esc_html
($ltext, -nbsp
=>1);
6416 print "<div class=\"pre\">" .
6417 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6418 file_name
=>"$file").'#l'.$lno,
6419 -class => "linenr"}, sprintf('%4i', $lno))
6420 . ' ' . $ltext . "</div>\n";
6424 print "</td></tr>\n";
6425 if ($matches > 1000) {
6426 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6429 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6438 sub git_search_help
{
6440 git_print_page_nav
('','', $hash,$hash,$hash);
6442 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6443 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6444 the pattern entered is recognized as the POSIX extended
6445 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6448 <dt><b>commit</b></dt>
6449 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6451 my $have_grep = gitweb_check_feature
('grep');
6454 <dt><b>grep</b></dt>
6455 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6456 a different one) are searched for the given pattern. On large trees, this search can take
6457 a while and put some strain on the server, so please use it with some consideration. Note that
6458 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6459 case-sensitive.</dd>
6463 <dt><b>author</b></dt>
6464 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6465 <dt><b>committer</b></dt>
6466 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6468 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6469 if ($have_pickaxe) {
6471 <dt><b>pickaxe</b></dt>
6472 <dd>All commits that caused the string to appear or disappear from any file (changes that
6473 added, removed or "modified" the string) will be listed. This search can take a while and
6474 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6475 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6483 git_log_generic
('shortlog', \
&git_shortlog_body
,
6484 $hash, $hash_parent);
6487 ## ......................................................................
6488 ## feeds (RSS, Atom; OPML)
6491 my $format = shift || 'atom';
6492 my $have_blame = gitweb_check_feature
('blame');
6494 # Atom: http://www.atomenabled.org/developers/syndication/
6495 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6496 if ($format ne 'rss' && $format ne 'atom') {
6497 die_error
(400, "Unknown web feed format");
6500 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6501 my $head = $hash || 'HEAD';
6502 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6506 my $content_type = "application/$format+xml";
6507 if (defined $cgi->http('HTTP_ACCEPT') &&
6508 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6509 # browser (feed reader) prefers text/xml
6510 $content_type = 'text/xml';
6512 if (defined($commitlist[0])) {
6513 %latest_commit = %{$commitlist[0]};
6514 my $latest_epoch = $latest_commit{'committer_epoch'};
6515 %latest_date = parse_date
($latest_epoch);
6516 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6517 if (defined $if_modified) {
6519 if (eval { require HTTP
::Date
; 1; }) {
6520 $since = HTTP
::Date
::str2time
($if_modified);
6521 } elsif (eval { require Time
::ParseDate
; 1; }) {
6522 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6524 if (defined $since && $latest_epoch <= $since) {
6526 -type
=> $content_type,
6527 -charset
=> 'utf-8',
6528 -last_modified
=> $latest_date{'rfc2822'},
6529 -status
=> '304 Not Modified');
6534 -type
=> $content_type,
6535 -charset
=> 'utf-8',
6536 -last_modified
=> $latest_date{'rfc2822'});
6539 -type
=> $content_type,
6540 -charset
=> 'utf-8');
6543 # Optimization: skip generating the body if client asks only
6544 # for Last-Modified date.
6545 return if ($cgi->request_method() eq 'HEAD');
6548 my $title = "$site_name - $project/$action";
6549 my $feed_type = 'log';
6550 if (defined $hash) {
6551 $title .= " - '$hash'";
6552 $feed_type = 'branch log';
6553 if (defined $file_name) {
6554 $title .= " :: $file_name";
6555 $feed_type = 'history';
6557 } elsif (defined $file_name) {
6558 $title .= " - $file_name";
6559 $feed_type = 'history';
6561 $title .= " $feed_type";
6562 my $descr = git_get_project_description
($project);
6563 if (defined $descr) {
6564 $descr = esc_html
($descr);
6566 $descr = "$project " .
6567 ($format eq 'rss' ?
'RSS' : 'Atom') .
6570 my $owner = git_get_project_owner
($project);
6571 $owner = esc_html
($owner);
6575 if (defined $file_name) {
6576 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6577 } elsif (defined $hash) {
6578 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6580 $alt_url = href
(-full
=>1, action
=>"summary");
6582 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6583 if ($format eq 'rss') {
6585 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6588 print "<title>$title</title>\n" .
6589 "<link>$alt_url</link>\n" .
6590 "<description>$descr</description>\n" .
6591 "<language>en</language>\n" .
6592 # project owner is responsible for 'editorial' content
6593 "<managingEditor>$owner</managingEditor>\n";
6594 if (defined $logo || defined $favicon) {
6595 # prefer the logo to the favicon, since RSS
6596 # doesn't allow both
6597 my $img = esc_url
($logo || $favicon);
6599 "<url>$img</url>\n" .
6600 "<title>$title</title>\n" .
6601 "<link>$alt_url</link>\n" .
6605 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6606 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6608 print "<generator>gitweb v.$version/$git_version</generator>\n";
6609 } elsif ($format eq 'atom') {
6611 <feed xmlns="http://www.w3.org/2005/Atom">
6613 print "<title>$title</title>\n" .
6614 "<subtitle>$descr</subtitle>\n" .
6615 '<link rel="alternate" type="text/html" href="' .
6616 $alt_url . '" />' . "\n" .
6617 '<link rel="self" type="' . $content_type . '" href="' .
6618 $cgi->self_url() . '" />' . "\n" .
6619 "<id>" . href
(-full
=>1) . "</id>\n" .
6620 # use project owner for feed author
6621 "<author><name>$owner</name></author>\n";
6622 if (defined $favicon) {
6623 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6625 if (defined $logo_url) {
6626 # not twice as wide as tall: 72 x 27 pixels
6627 print "<logo>" . esc_url
($logo) . "</logo>\n";
6629 if (! %latest_date) {
6630 # dummy date to keep the feed valid until commits trickle in:
6631 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6633 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6635 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6639 for (my $i = 0; $i <= $#commitlist; $i++) {
6640 my %co = %{$commitlist[$i]};
6641 my $commit = $co{'id'};
6642 # we read 150, we always show 30 and the ones more recent than 48 hours
6643 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6646 my %cd = parse_date
($co{'author_epoch'});
6648 # get list of changed files
6649 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6650 $co{'parent'} || "--root",
6651 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6653 my @difftree = map { chomp; $_ } <$fd>;
6657 # print element (entry, item)
6658 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6659 if ($format eq 'rss') {
6661 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6662 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6663 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6664 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6665 "<link>$co_url</link>\n" .
6666 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6667 "<content:encoded>" .
6669 } elsif ($format eq 'atom') {
6671 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6672 "<updated>$cd{'iso-8601'}</updated>\n" .
6674 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6675 if ($co{'author_email'}) {
6676 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6678 print "</author>\n" .
6679 # use committer for contributor
6681 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6682 if ($co{'committer_email'}) {
6683 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6685 print "</contributor>\n" .
6686 "<published>$cd{'iso-8601'}</published>\n" .
6687 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6688 "<id>$co_url</id>\n" .
6689 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6690 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6692 my $comment = $co{'comment'};
6694 foreach my $line (@
$comment) {
6695 $line = esc_html
($line);
6698 print "</pre><ul>\n";
6699 foreach my $difftree_line (@difftree) {
6700 my %difftree = parse_difftree_raw_line
($difftree_line);
6701 next if !$difftree{'from_id'};
6703 my $file = $difftree{'file'} || $difftree{'to_file'};
6707 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6708 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6709 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6710 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6711 -title
=> "diff"}, 'D');
6713 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6714 file_name
=>$file, hash_base
=>$commit),
6715 -title
=> "blame"}, 'B');
6717 # if this is not a feed of a file history
6718 if (!defined $file_name || $file_name ne $file) {
6719 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6720 file_name
=>$file, hash
=>$commit),
6721 -title
=> "history"}, 'H');
6723 $file = esc_path
($file);
6727 if ($format eq 'rss') {
6728 print "</ul>]]>\n" .
6729 "</content:encoded>\n" .
6731 } elsif ($format eq 'atom') {
6732 print "</ul>\n</div>\n" .
6739 if ($format eq 'rss') {
6740 print "</channel>\n</rss>\n";
6741 } elsif ($format eq 'atom') {
6755 my @list = git_get_projects_list
();
6758 -type
=> 'text/xml',
6759 -charset
=> 'utf-8',
6760 -content_disposition
=> 'inline; filename="opml.xml"');
6763 <?xml version="1.0" encoding="utf-8"?>
6764 <opml version="1.0">
6766 <title>$site_name OPML Export</title>
6769 <outline text="git RSS feeds">
6772 foreach my $pr (@list) {
6774 my $head = git_get_head_hash
($proj{'path'});
6775 if (!defined $head) {
6778 $git_dir = "$projectroot/$proj{'path'}";
6779 my %co = parse_commit
($head);
6784 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6785 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6786 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6787 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";