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 # You define site-wide feature defaults here; override them with
225 # $GITWEB_CONFIG as necessary.
228 # 'sub' => feature-sub (subroutine),
229 # 'override' => allow-override (boolean),
230 # 'default' => [ default options...] (array reference)}
232 # if feature is overridable (it means that allow-override has true value),
233 # then feature-sub will be called with default options as parameters;
234 # return value of feature-sub indicates if to enable specified feature
236 # if there is no 'sub' key (no feature-sub), then feature cannot be
239 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
240 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
243 # Enable the 'blame' blob view, showing the last commit that modified
244 # each line in the file. This can be very CPU-intensive.
246 # To enable system wide have in $GITWEB_CONFIG
247 # $feature{'blame'}{'default'} = [1];
248 # To have project specific config enable override in $GITWEB_CONFIG
249 # $feature{'blame'}{'override'} = 1;
250 # and in project config gitweb.blame = 0|1;
252 'sub' => sub { feature_bool
('blame', @_) },
256 # Enable the 'snapshot' link, providing a compressed archive of any
257 # tree. This can potentially generate high traffic if you have large
260 # Value is a list of formats defined in %known_snapshot_formats that
262 # To disable system wide have in $GITWEB_CONFIG
263 # $feature{'snapshot'}{'default'} = [];
264 # To have project specific config enable override in $GITWEB_CONFIG
265 # $feature{'snapshot'}{'override'} = 1;
266 # and in project config, a comma-separated list of formats or "none"
267 # to disable. Example: gitweb.snapshot = tbz2,zip;
269 'sub' => \
&feature_snapshot
,
271 'default' => ['tgz']},
273 # Enable text search, which will list the commits which match author,
274 # committer or commit text to a given string. Enabled by default.
275 # Project specific override is not supported.
280 # Enable grep search, which will list the files in currently selected
281 # tree containing the given string. Enabled by default. This can be
282 # potentially CPU-intensive, of course.
284 # To enable system wide have in $GITWEB_CONFIG
285 # $feature{'grep'}{'default'} = [1];
286 # To have project specific config enable override in $GITWEB_CONFIG
287 # $feature{'grep'}{'override'} = 1;
288 # and in project config gitweb.grep = 0|1;
290 'sub' => sub { feature_bool
('grep', @_) },
294 # Enable the pickaxe search, which will list the commits that modified
295 # a given string in a file. This can be practical and quite faster
296 # alternative to 'blame', but still potentially CPU-intensive.
298 # To enable system wide have in $GITWEB_CONFIG
299 # $feature{'pickaxe'}{'default'} = [1];
300 # To have project specific config enable override in $GITWEB_CONFIG
301 # $feature{'pickaxe'}{'override'} = 1;
302 # and in project config gitweb.pickaxe = 0|1;
304 'sub' => sub { feature_bool
('pickaxe', @_) },
308 # Enable showing size of blobs in a 'tree' view, in a separate
309 # column, similar to what 'ls -l' does. This cost a bit of IO.
311 # To disable system wide have in $GITWEB_CONFIG
312 # $feature{'show-sizes'}{'default'} = [0];
313 # To have project specific config enable override in $GITWEB_CONFIG
314 # $feature{'show-sizes'}{'override'} = 1;
315 # and in project config gitweb.showsizes = 0|1;
317 'sub' => sub { feature_bool
('showsizes', @_) },
321 # Make gitweb use an alternative format of the URLs which can be
322 # more readable and natural-looking: project name is embedded
323 # directly in the path and the query string contains other
324 # auxiliary information. All gitweb installations recognize
325 # URL in either format; this configures in which formats gitweb
328 # To enable system wide have in $GITWEB_CONFIG
329 # $feature{'pathinfo'}{'default'} = [1];
330 # Project specific override is not supported.
332 # Note that you will need to change the default location of CSS,
333 # favicon, logo and possibly other files to an absolute URL. Also,
334 # if gitweb.cgi serves as your indexfile, you will need to force
335 # $my_uri to contain the script name in your $GITWEB_CONFIG.
340 # Make gitweb consider projects in project root subdirectories
341 # to be forks of existing projects. Given project $projname.git,
342 # projects matching $projname/*.git will not be shown in the main
343 # projects list, instead a '+' mark will be added to $projname
344 # there and a 'forks' view will be enabled for the project, listing
345 # all the forks. If project list is taken from a file, forks have
346 # to be listed after the main project.
348 # To enable system wide have in $GITWEB_CONFIG
349 # $feature{'forks'}{'default'} = [1];
350 # Project specific override is not supported.
355 # Insert custom links to the action bar of all project pages.
356 # This enables you mainly to link to third-party scripts integrating
357 # into gitweb; e.g. git-browser for graphical history representation
358 # or custom web-based repository administration interface.
360 # The 'default' value consists of a list of triplets in the form
361 # (label, link, position) where position is the label after which
362 # to insert the link and link is a format string where %n expands
363 # to the project name, %f to the project path within the filesystem,
364 # %h to the current hash (h gitweb parameter) and %b to the current
365 # hash base (hb gitweb parameter); %% expands to %.
367 # To enable system wide have in $GITWEB_CONFIG e.g.
368 # $feature{'actions'}{'default'} = [('graphiclog',
369 # '/git-browser/by-commit.html?r=%n', 'summary')];
370 # Project specific override is not supported.
375 # Allow gitweb scan project content tags described in ctags/
376 # of project repository, and display the popular Web 2.0-ish
377 # "tag cloud" near the project list. Note that this is something
378 # COMPLETELY different from the normal Git tags.
380 # gitweb by itself can show existing tags, but it does not handle
381 # tagging itself; you need an external application for that.
382 # For an example script, check Girocco's cgi/tagproj.cgi.
383 # You may want to install the HTML::TagCloud Perl module to get
384 # a pretty tag cloud instead of just a list of tags.
386 # To enable system wide have in $GITWEB_CONFIG
387 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
388 # Project specific override is not supported.
393 # The maximum number of patches in a patchset generated in patch
394 # view. Set this to 0 or undef to disable patch view, or to a
395 # negative number to remove any limit.
397 # To disable system wide have in $GITWEB_CONFIG
398 # $feature{'patches'}{'default'} = [0];
399 # To have project specific config enable override in $GITWEB_CONFIG
400 # $feature{'patches'}{'override'} = 1;
401 # and in project config gitweb.patches = 0|n;
402 # where n is the maximum number of patches allowed in a patchset.
404 'sub' => \
&feature_patches
,
408 # Avatar support. When this feature is enabled, views such as
409 # shortlog or commit will display an avatar associated with
410 # the email of the committer(s) and/or author(s).
412 # Currently available providers are gravatar and picon.
413 # If an unknown provider is specified, the feature is disabled.
415 # Gravatar depends on Digest::MD5.
416 # Picon currently relies on the indiana.edu database.
418 # To enable system wide have in $GITWEB_CONFIG
419 # $feature{'avatar'}{'default'} = ['<provider>'];
420 # where <provider> is either gravatar or picon.
421 # To have project specific config enable override in $GITWEB_CONFIG
422 # $feature{'avatar'}{'override'} = 1;
423 # and in project config gitweb.avatar = <provider>;
425 'sub' => \
&feature_avatar
,
429 # Enable displaying how much time and how many git commands
430 # it took to generate and display page. Disabled by default.
431 # Project specific override is not supported.
436 # Enable turning some links into links to actions which require
437 # JavaScript to run (like 'blame_incremental'). Not enabled by
438 # default. Project specific override is currently not supported.
439 'javascript-actions' => {
444 sub gitweb_get_feature
{
446 return unless exists $feature{$name};
447 my ($sub, $override, @defaults) = (
448 $feature{$name}{'sub'},
449 $feature{$name}{'override'},
450 @
{$feature{$name}{'default'}});
451 if (!$override) { return @defaults; }
453 warn "feature $name is not overridable";
456 return $sub->(@defaults);
459 # A wrapper to check if a given feature is enabled.
460 # With this, you can say
462 # my $bool_feat = gitweb_check_feature('bool_feat');
463 # gitweb_check_feature('bool_feat') or somecode;
467 # my ($bool_feat) = gitweb_get_feature('bool_feat');
468 # (gitweb_get_feature('bool_feat'))[0] or somecode;
470 sub gitweb_check_feature
{
471 return (gitweb_get_feature
(@_))[0];
477 my ($val) = git_get_project_config
($key, '--bool');
481 } elsif ($val eq 'true') {
483 } elsif ($val eq 'false') {
488 sub feature_snapshot
{
491 my ($val) = git_get_project_config
('snapshot');
494 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
500 sub feature_patches
{
501 my @val = (git_get_project_config
('patches', '--int'));
511 my @val = (git_get_project_config
('avatar'));
513 return @val ?
@val : @_;
516 # checking HEAD file with -e is fragile if the repository was
517 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
519 sub check_head_link
{
521 my $headfile = "$dir/HEAD";
522 return ((-e
$headfile) ||
523 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
526 sub check_export_ok
{
528 return (check_head_link
($dir) &&
529 (!$export_ok || -e
"$dir/$export_ok") &&
530 (!$export_auth_hook || $export_auth_hook->($dir)));
533 # process alternate names for backward compatibility
534 # filter out unsupported (unknown) snapshot formats
535 sub filter_snapshot_fmts
{
539 exists $known_snapshot_format_aliases{$_} ?
540 $known_snapshot_format_aliases{$_} : $_} @fmts;
542 exists $known_snapshot_formats{$_} &&
543 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
546 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
547 if (-e
$GITWEB_CONFIG) {
550 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
551 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
554 # version of the core git binary
555 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
556 $number_of_git_cmds++;
558 $projects_list ||= $projectroot;
560 # ======================================================================
561 # input validation and dispatch
563 # input parameters can be collected from a variety of sources (presently, CGI
564 # and PATH_INFO), so we define an %input_params hash that collects them all
565 # together during validation: this allows subsequent uses (e.g. href()) to be
566 # agnostic of the parameter origin
568 our %input_params = ();
570 # input parameters are stored with the long parameter name as key. This will
571 # also be used in the href subroutine to convert parameters to their CGI
572 # equivalent, and since the href() usage is the most frequent one, we store
573 # the name -> CGI key mapping here, instead of the reverse.
575 # XXX: Warning: If you touch this, check the search form for updating,
578 our @cgi_param_mapping = (
586 hash_parent_base
=> "hpb",
591 snapshot_format
=> "sf",
592 extra_options
=> "opt",
593 search_use_regexp
=> "sr",
594 # this must be last entry (for manipulation from JavaScript)
597 our %cgi_param_mapping = @cgi_param_mapping;
599 # we will also need to know the possible actions, for validation
601 "blame" => \
&git_blame
,
602 "blame_incremental" => \
&git_blame_incremental
,
603 "blame_data" => \
&git_blame_data
,
604 "blobdiff" => \
&git_blobdiff
,
605 "blobdiff_plain" => \
&git_blobdiff_plain
,
606 "blob" => \
&git_blob
,
607 "blob_plain" => \
&git_blob_plain
,
608 "commitdiff" => \
&git_commitdiff
,
609 "commitdiff_plain" => \
&git_commitdiff_plain
,
610 "commit" => \
&git_commit
,
611 "forks" => \
&git_forks
,
612 "heads" => \
&git_heads
,
613 "history" => \
&git_history
,
615 "patch" => \
&git_patch
,
616 "patches" => \
&git_patches
,
618 "atom" => \
&git_atom
,
619 "search" => \
&git_search
,
620 "search_help" => \
&git_search_help
,
621 "shortlog" => \
&git_shortlog
,
622 "summary" => \
&git_summary
,
624 "tags" => \
&git_tags
,
625 "tree" => \
&git_tree
,
626 "snapshot" => \
&git_snapshot
,
627 "object" => \
&git_object
,
628 # those below don't need $project
629 "opml" => \
&git_opml
,
630 "project_list" => \
&git_project_list
,
631 "project_index" => \
&git_project_index
,
634 # finally, we have the hash of allowed extra_options for the commands that
636 our %allowed_options = (
637 "--no-merges" => [ qw(rss atom log shortlog history) ],
640 # fill %input_params with the CGI parameters. All values except for 'opt'
641 # should be single values, but opt can be an array. We should probably
642 # build an array of parameters that can be multi-valued, but since for the time
643 # being it's only this one, we just single it out
644 while (my ($name, $symbol) = each %cgi_param_mapping) {
645 if ($symbol eq 'opt') {
646 $input_params{$name} = [ $cgi->param($symbol) ];
648 $input_params{$name} = $cgi->param($symbol);
652 # now read PATH_INFO and update the parameter list for missing parameters
653 sub evaluate_path_info
{
654 return if defined $input_params{'project'};
655 return if !$path_info;
656 $path_info =~ s
,^/+,,;
657 return if !$path_info;
659 # find which part of PATH_INFO is project
660 my $project = $path_info;
662 while ($project && !check_head_link
("$projectroot/$project")) {
663 $project =~ s
,/*[^/]*$,,;
665 return unless $project;
666 $input_params{'project'} = $project;
668 # do not change any parameters if an action is given using the query string
669 return if $input_params{'action'};
670 $path_info =~ s
,^\Q
$project\E
/*,,;
672 # next, check if we have an action
673 my $action = $path_info;
675 if (exists $actions{$action}) {
676 $path_info =~ s
,^$action/*,,;
677 $input_params{'action'} = $action;
680 # list of actions that want hash_base instead of hash, but can have no
681 # pathname (f) parameter
688 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
689 my ($parentrefname, $parentpathname, $refname, $pathname) =
690 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
692 # first, analyze the 'current' part
693 if (defined $pathname) {
694 # we got "branch:filename" or "branch:dir/"
695 # we could use git_get_type(branch:pathname), but:
696 # - it needs $git_dir
697 # - it does a git() call
698 # - the convention of terminating directories with a slash
699 # makes it superfluous
700 # - embedding the action in the PATH_INFO would make it even
702 $pathname =~ s
,^/+,,;
703 if (!$pathname || substr($pathname, -1) eq "/") {
704 $input_params{'action'} ||= "tree";
707 # the default action depends on whether we had parent info
709 if ($parentrefname) {
710 $input_params{'action'} ||= "blobdiff_plain";
712 $input_params{'action'} ||= "blob_plain";
715 $input_params{'hash_base'} ||= $refname;
716 $input_params{'file_name'} ||= $pathname;
717 } elsif (defined $refname) {
718 # we got "branch". In this case we have to choose if we have to
719 # set hash or hash_base.
721 # Most of the actions without a pathname only want hash to be
722 # set, except for the ones specified in @wants_base that want
723 # hash_base instead. It should also be noted that hand-crafted
724 # links having 'history' as an action and no pathname or hash
725 # set will fail, but that happens regardless of PATH_INFO.
726 $input_params{'action'} ||= "shortlog";
727 if (grep { $_ eq $input_params{'action'} } @wants_base) {
728 $input_params{'hash_base'} ||= $refname;
730 $input_params{'hash'} ||= $refname;
734 # next, handle the 'parent' part, if present
735 if (defined $parentrefname) {
736 # a missing pathspec defaults to the 'current' filename, allowing e.g.
737 # someproject/blobdiff/oldrev..newrev:/filename
738 if ($parentpathname) {
739 $parentpathname =~ s
,^/+,,;
740 $parentpathname =~ s
,/$,,;
741 $input_params{'file_parent'} ||= $parentpathname;
743 $input_params{'file_parent'} ||= $input_params{'file_name'};
745 # we assume that hash_parent_base is wanted if a path was specified,
746 # or if the action wants hash_base instead of hash
747 if (defined $input_params{'file_parent'} ||
748 grep { $_ eq $input_params{'action'} } @wants_base) {
749 $input_params{'hash_parent_base'} ||= $parentrefname;
751 $input_params{'hash_parent'} ||= $parentrefname;
755 # for the snapshot action, we allow URLs in the form
756 # $project/snapshot/$hash.ext
757 # where .ext determines the snapshot and gets removed from the
758 # passed $refname to provide the $hash.
760 # To be able to tell that $refname includes the format extension, we
761 # require the following two conditions to be satisfied:
762 # - the hash input parameter MUST have been set from the $refname part
763 # of the URL (i.e. they must be equal)
764 # - the snapshot format MUST NOT have been defined already (e.g. from
766 # It's also useless to try any matching unless $refname has a dot,
767 # so we check for that too
768 if (defined $input_params{'action'} &&
769 $input_params{'action'} eq 'snapshot' &&
770 defined $refname && index($refname, '.') != -1 &&
771 $refname eq $input_params{'hash'} &&
772 !defined $input_params{'snapshot_format'}) {
773 # We loop over the known snapshot formats, checking for
774 # extensions. Allowed extensions are both the defined suffix
775 # (which includes the initial dot already) and the snapshot
776 # format key itself, with a prepended dot
777 while (my ($fmt, $opt) = each %known_snapshot_formats) {
779 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
783 # a valid suffix was found, so set the snapshot format
784 # and reset the hash parameter
785 $input_params{'snapshot_format'} = $fmt;
786 $input_params{'hash'} = $hash;
787 # we also set the format suffix to the one requested
788 # in the URL: this way a request for e.g. .tgz returns
789 # a .tgz instead of a .tar.gz
790 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
795 evaluate_path_info
();
797 our $action = $input_params{'action'};
798 if (defined $action) {
799 if (!validate_action
($action)) {
800 die_error
(400, "Invalid action parameter");
804 # parameters which are pathnames
805 our $project = $input_params{'project'};
806 if (defined $project) {
807 if (!validate_project
($project)) {
809 die_error
(404, "No such project");
813 our $file_name = $input_params{'file_name'};
814 if (defined $file_name) {
815 if (!validate_pathname
($file_name)) {
816 die_error
(400, "Invalid file parameter");
820 our $file_parent = $input_params{'file_parent'};
821 if (defined $file_parent) {
822 if (!validate_pathname
($file_parent)) {
823 die_error
(400, "Invalid file parent parameter");
827 # parameters which are refnames
828 our $hash = $input_params{'hash'};
830 if (!validate_refname
($hash)) {
831 die_error
(400, "Invalid hash parameter");
835 our $hash_parent = $input_params{'hash_parent'};
836 if (defined $hash_parent) {
837 if (!validate_refname
($hash_parent)) {
838 die_error
(400, "Invalid hash parent parameter");
842 our $hash_base = $input_params{'hash_base'};
843 if (defined $hash_base) {
844 if (!validate_refname
($hash_base)) {
845 die_error
(400, "Invalid hash base parameter");
849 our @extra_options = @
{$input_params{'extra_options'}};
850 # @extra_options is always defined, since it can only be (currently) set from
851 # CGI, and $cgi->param() returns the empty array in array context if the param
853 foreach my $opt (@extra_options) {
854 if (not exists $allowed_options{$opt}) {
855 die_error
(400, "Invalid option parameter");
857 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
858 die_error
(400, "Invalid option parameter for this action");
862 our $hash_parent_base = $input_params{'hash_parent_base'};
863 if (defined $hash_parent_base) {
864 if (!validate_refname
($hash_parent_base)) {
865 die_error
(400, "Invalid hash parent base parameter");
870 our $page = $input_params{'page'};
872 if ($page =~ m/[^0-9]/) {
873 die_error
(400, "Invalid page parameter");
877 our $searchtype = $input_params{'searchtype'};
878 if (defined $searchtype) {
879 if ($searchtype =~ m/[^a-z]/) {
880 die_error
(400, "Invalid searchtype parameter");
884 our $search_use_regexp = $input_params{'search_use_regexp'};
886 our $searchtext = $input_params{'searchtext'};
888 if (defined $searchtext) {
889 if (length($searchtext) < 2) {
890 die_error
(403, "At least two characters are required for search parameter");
892 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
895 # path to the current git repository
897 $git_dir = "$projectroot/$project" if $project;
899 # list of supported snapshot formats
900 our @snapshot_fmts = gitweb_get_feature
('snapshot');
901 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
903 # check that the avatar feature is set to a known provider name,
904 # and for each provider check if the dependencies are satisfied.
905 # if the provider name is invalid or the dependencies are not met,
906 # reset $git_avatar to the empty string.
907 our ($git_avatar) = gitweb_get_feature
('avatar');
908 if ($git_avatar eq 'gravatar') {
909 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
910 } elsif ($git_avatar eq 'picon') {
917 if (!defined $action) {
919 $action = git_get_type
($hash);
920 } elsif (defined $hash_base && defined $file_name) {
921 $action = git_get_type
("$hash_base:$file_name");
922 } elsif (defined $project) {
925 $action = 'project_list';
928 if (!defined($actions{$action})) {
929 die_error
(400, "Unknown action");
931 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
933 die_error
(400, "Project needed");
935 $actions{$action}->();
938 ## ======================================================================
943 # default is to use -absolute url() i.e. $my_uri
944 my $href = $params{-full
} ?
$my_url : $my_uri;
946 $params{'project'} = $project unless exists $params{'project'};
948 if ($params{-replay
}) {
949 while (my ($name, $symbol) = each %cgi_param_mapping) {
950 if (!exists $params{$name}) {
951 $params{$name} = $input_params{$name};
956 my $use_pathinfo = gitweb_check_feature
('pathinfo');
957 if ($use_pathinfo and defined $params{'project'}) {
958 # try to put as many parameters as possible in PATH_INFO:
961 # - hash_parent or hash_parent_base:/file_parent
962 # - hash or hash_base:/filename
963 # - the snapshot_format as an appropriate suffix
965 # When the script is the root DirectoryIndex for the domain,
966 # $href here would be something like http://gitweb.example.com/
967 # Thus, we strip any trailing / from $href, to spare us double
968 # slashes in the final URL
971 # Then add the project name, if present
972 $href .= "/".esc_url
($params{'project'});
973 delete $params{'project'};
975 # since we destructively absorb parameters, we keep this
976 # boolean that remembers if we're handling a snapshot
977 my $is_snapshot = $params{'action'} eq 'snapshot';
979 # Summary just uses the project path URL, any other action is
981 if (defined $params{'action'}) {
982 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
983 delete $params{'action'};
986 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
987 # stripping nonexistent or useless pieces
988 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
989 || $params{'hash_parent'} || $params{'hash'});
990 if (defined $params{'hash_base'}) {
991 if (defined $params{'hash_parent_base'}) {
992 $href .= esc_url
($params{'hash_parent_base'});
993 # skip the file_parent if it's the same as the file_name
994 if (defined $params{'file_parent'}) {
995 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
996 delete $params{'file_parent'};
997 } elsif ($params{'file_parent'} !~ /\.\./) {
998 $href .= ":/".esc_url
($params{'file_parent'});
999 delete $params{'file_parent'};
1003 delete $params{'hash_parent'};
1004 delete $params{'hash_parent_base'};
1005 } elsif (defined $params{'hash_parent'}) {
1006 $href .= esc_url
($params{'hash_parent'}). "..";
1007 delete $params{'hash_parent'};
1010 $href .= esc_url
($params{'hash_base'});
1011 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1012 $href .= ":/".esc_url
($params{'file_name'});
1013 delete $params{'file_name'};
1015 delete $params{'hash'};
1016 delete $params{'hash_base'};
1017 } elsif (defined $params{'hash'}) {
1018 $href .= esc_url
($params{'hash'});
1019 delete $params{'hash'};
1022 # If the action was a snapshot, we can absorb the
1023 # snapshot_format parameter too
1025 my $fmt = $params{'snapshot_format'};
1026 # snapshot_format should always be defined when href()
1027 # is called, but just in case some code forgets, we
1028 # fall back to the default
1029 $fmt ||= $snapshot_fmts[0];
1030 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1031 delete $params{'snapshot_format'};
1035 # now encode the parameters explicitly
1037 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1038 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1039 if (defined $params{$name}) {
1040 if (ref($params{$name}) eq "ARRAY") {
1041 foreach my $par (@
{$params{$name}}) {
1042 push @result, $symbol . "=" . esc_param
($par);
1045 push @result, $symbol . "=" . esc_param
($params{$name});
1049 $href .= "?" . join(';', @result) if scalar @result;
1055 ## ======================================================================
1056 ## validation, quoting/unquoting and escaping
1058 sub validate_action
{
1059 my $input = shift || return undef;
1060 return undef unless exists $actions{$input};
1064 sub validate_project
{
1065 my $input = shift || return undef;
1066 if (!validate_pathname
($input) ||
1067 !(-d
"$projectroot/$input") ||
1068 !check_export_ok
("$projectroot/$input") ||
1069 ($strict_export && !project_in_list
($input))) {
1076 sub validate_pathname
{
1077 my $input = shift || return undef;
1079 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1080 # at the beginning, at the end, and between slashes.
1081 # also this catches doubled slashes
1082 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1085 # no null characters
1086 if ($input =~ m!\0!) {
1092 sub validate_refname
{
1093 my $input = shift || return undef;
1095 # textual hashes are O.K.
1096 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1099 # it must be correct pathname
1100 $input = validate_pathname
($input)
1102 # restrictions on ref name according to git-check-ref-format
1103 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1109 # decode sequences of octets in utf8 into Perl's internal form,
1110 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1111 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1114 if (utf8
::valid
($str)) {
1118 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1122 # quote unsafe chars, but keep the slash, even when it's not
1123 # correct, but quoted slashes look too horrible in bookmarks
1126 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1131 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1134 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1140 # quote unsafe characters in HTML attributes
1143 # for XHTML conformance escaping '"' to '"' is not enough
1144 return esc_html
(@_);
1147 # replace invalid utf8 character with SUBSTITUTION sequence
1152 $str = to_utf8
($str);
1153 $str = $cgi->escapeHTML($str);
1154 if ($opts{'-nbsp'}) {
1155 $str =~ s/ / /g;
1157 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1161 # quote control characters and escape filename to HTML
1166 $str = to_utf8
($str);
1167 $str = $cgi->escapeHTML($str);
1168 if ($opts{'-nbsp'}) {
1169 $str =~ s/ / /g;
1171 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1175 # Make control characters "printable", using character escape codes (CEC)
1179 my %es = ( # character escape codes, aka escape sequences
1180 "\t" => '\t', # tab (HT)
1181 "\n" => '\n', # line feed (LF)
1182 "\r" => '\r', # carrige return (CR)
1183 "\f" => '\f', # form feed (FF)
1184 "\b" => '\b', # backspace (BS)
1185 "\a" => '\a', # alarm (bell) (BEL)
1186 "\e" => '\e', # escape (ESC)
1187 "\013" => '\v', # vertical tab (VT)
1188 "\000" => '\0', # nul character (NUL)
1190 my $chr = ( (exists $es{$cntrl})
1192 : sprintf('\%2x', ord($cntrl)) );
1193 if ($opts{-nohtml
}) {
1196 return "<span class=\"cntrl\">$chr</span>";
1200 # Alternatively use unicode control pictures codepoints,
1201 # Unicode "printable representation" (PR)
1206 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1207 if ($opts{-nohtml
}) {
1210 return "<span class=\"cntrl\">$chr</span>";
1214 # git may return quoted and escaped filenames
1220 my %es = ( # character escape codes, aka escape sequences
1221 't' => "\t", # tab (HT, TAB)
1222 'n' => "\n", # newline (NL)
1223 'r' => "\r", # return (CR)
1224 'f' => "\f", # form feed (FF)
1225 'b' => "\b", # backspace (BS)
1226 'a' => "\a", # alarm (bell) (BEL)
1227 'e' => "\e", # escape (ESC)
1228 'v' => "\013", # vertical tab (VT)
1231 if ($seq =~ m/^[0-7]{1,3}$/) {
1232 # octal char sequence
1233 return chr(oct($seq));
1234 } elsif (exists $es{$seq}) {
1235 # C escape sequence, aka character escape code
1238 # quoted ordinary character
1242 if ($str =~ m/^"(.*)"$/) {
1245 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1250 # escape tabs (convert tabs to spaces)
1254 while ((my $pos = index($line, "\t")) != -1) {
1255 if (my $count = (8 - ($pos % 8))) {
1256 my $spaces = ' ' x
$count;
1257 $line =~ s/\t/$spaces/;
1264 sub project_in_list
{
1265 my $project = shift;
1266 my @list = git_get_projects_list
();
1267 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1270 ## ----------------------------------------------------------------------
1271 ## HTML aware string manipulation
1273 # Try to chop given string on a word boundary between position
1274 # $len and $len+$add_len. If there is no word boundary there,
1275 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1276 # (marking chopped part) would be longer than given string.
1280 my $add_len = shift || 10;
1281 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1283 # Make sure perl knows it is utf8 encoded so we don't
1284 # cut in the middle of a utf8 multibyte char.
1285 $str = to_utf8
($str);
1287 # allow only $len chars, but don't cut a word if it would fit in $add_len
1288 # if it doesn't fit, cut it if it's still longer than the dots we would add
1289 # remove chopped character entities entirely
1291 # when chopping in the middle, distribute $len into left and right part
1292 # return early if chopping wouldn't make string shorter
1293 if ($where eq 'center') {
1294 return $str if ($len + 5 >= length($str)); # filler is length 5
1297 return $str if ($len + 4 >= length($str)); # filler is length 4
1300 # regexps: ending and beginning with word part up to $add_len
1301 my $endre = qr/.{$len}\w{0,$add_len}/;
1302 my $begre = qr/\w{0,$add_len}.{$len}/;
1304 if ($where eq 'left') {
1305 $str =~ m/^(.*?)($begre)$/;
1306 my ($lead, $body) = ($1, $2);
1307 if (length($lead) > 4) {
1308 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1311 return "$lead$body";
1313 } elsif ($where eq 'center') {
1314 $str =~ m/^($endre)(.*)$/;
1315 my ($left, $str) = ($1, $2);
1316 $str =~ m/^(.*?)($begre)$/;
1317 my ($mid, $right) = ($1, $2);
1318 if (length($mid) > 5) {
1319 $left =~ s/&[^;]*$//;
1320 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1323 return "$left$mid$right";
1326 $str =~ m/^($endre)(.*)$/;
1329 if (length($tail) > 4) {
1330 $body =~ s/&[^;]*$//;
1333 return "$body$tail";
1337 # takes the same arguments as chop_str, but also wraps a <span> around the
1338 # result with a title attribute if it does get chopped. Additionally, the
1339 # string is HTML-escaped.
1340 sub chop_and_escape_str
{
1343 my $chopped = chop_str
(@_);
1344 if ($chopped eq $str) {
1345 return esc_html
($chopped);
1347 $str =~ s/[[:cntrl:]]/?/g;
1348 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1352 ## ----------------------------------------------------------------------
1353 ## functions returning short strings
1355 # CSS class for given age value (in seconds)
1359 if (!defined $age) {
1361 } elsif ($age < 60*60*2) {
1363 } elsif ($age < 60*60*24*2) {
1370 # convert age in seconds to "nn units ago" string
1375 if ($age > 60*60*24*365*2) {
1376 $age_str = (int $age/60/60/24/365);
1377 $age_str .= " years ago";
1378 } elsif ($age > 60*60*24*(365/12)*2) {
1379 $age_str = int $age/60/60/24/(365/12);
1380 $age_str .= " months ago";
1381 } elsif ($age > 60*60*24*7*2) {
1382 $age_str = int $age/60/60/24/7;
1383 $age_str .= " weeks ago";
1384 } elsif ($age > 60*60*24*2) {
1385 $age_str = int $age/60/60/24;
1386 $age_str .= " days ago";
1387 } elsif ($age > 60*60*2) {
1388 $age_str = int $age/60/60;
1389 $age_str .= " hours ago";
1390 } elsif ($age > 60*2) {
1391 $age_str = int $age/60;
1392 $age_str .= " min ago";
1393 } elsif ($age > 2) {
1394 $age_str = int $age;
1395 $age_str .= " sec ago";
1397 $age_str .= " right now";
1403 S_IFINVALID
=> 0030000,
1404 S_IFGITLINK
=> 0160000,
1407 # submodule/subproject, a commit object reference
1411 return (($mode & S_IFMT
) == S_IFGITLINK
)
1414 # convert file mode in octal to symbolic file mode string
1416 my $mode = oct shift;
1418 if (S_ISGITLINK
($mode)) {
1419 return 'm---------';
1420 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1421 return 'drwxr-xr-x';
1422 } elsif (S_ISLNK
($mode)) {
1423 return 'lrwxrwxrwx';
1424 } elsif (S_ISREG
($mode)) {
1425 # git cares only about the executable bit
1426 if ($mode & S_IXUSR
) {
1427 return '-rwxr-xr-x';
1429 return '-rw-r--r--';
1432 return '----------';
1436 # convert file mode in octal to file type string
1440 if ($mode !~ m/^[0-7]+$/) {
1446 if (S_ISGITLINK
($mode)) {
1448 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1450 } elsif (S_ISLNK
($mode)) {
1452 } elsif (S_ISREG
($mode)) {
1459 # convert file mode in octal to file type description string
1460 sub file_type_long
{
1463 if ($mode !~ m/^[0-7]+$/) {
1469 if (S_ISGITLINK
($mode)) {
1471 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1473 } elsif (S_ISLNK
($mode)) {
1475 } elsif (S_ISREG
($mode)) {
1476 if ($mode & S_IXUSR
) {
1477 return "executable";
1487 ## ----------------------------------------------------------------------
1488 ## functions returning short HTML fragments, or transforming HTML fragments
1489 ## which don't belong to other sections
1491 # format line of commit message.
1492 sub format_log_line_html
{
1495 $line = esc_html
($line, -nbsp
=>1);
1496 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1497 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1498 -class => "text"}, $1);
1504 # format marker of refs pointing to given object
1506 # the destination action is chosen based on object type and current context:
1507 # - for annotated tags, we choose the tag view unless it's the current view
1508 # already, in which case we go to shortlog view
1509 # - for other refs, we keep the current view if we're in history, shortlog or
1510 # log view, and select shortlog otherwise
1511 sub format_ref_marker
{
1512 my ($refs, $id) = @_;
1515 if (defined $refs->{$id}) {
1516 foreach my $ref (@
{$refs->{$id}}) {
1517 # this code exploits the fact that non-lightweight tags are the
1518 # only indirect objects, and that they are the only objects for which
1519 # we want to use tag instead of shortlog as action
1520 my ($type, $name) = qw();
1521 my $indirect = ($ref =~ s/\^\{\}$//);
1522 # e.g. tags/v2.6.11 or heads/next
1523 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1532 $class .= " indirect" if $indirect;
1534 my $dest_action = "shortlog";
1537 $dest_action = "tag" unless $action eq "tag";
1538 } elsif ($action =~ /^(history|(short)?log)$/) {
1539 $dest_action = $action;
1543 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1546 my $link = $cgi->a({
1548 action
=>$dest_action,
1552 $markers .= " <span class=\"".esc_attr
($class)."\" title=\"".esc_attr
($ref)."\">" .
1558 return ' <span class="refs">'. $markers . '</span>';
1564 # format, perhaps shortened and with markers, title line
1565 sub format_subject_html
{
1566 my ($long, $short, $href, $extra) = @_;
1567 $extra = '' unless defined($extra);
1569 if (length($short) < length($long)) {
1570 $long =~ s/[[:cntrl:]]/?/g;
1571 return $cgi->a({-href
=> $href, -class => "list subject",
1572 -title
=> to_utf8
($long)},
1573 esc_html
($short)) . $extra;
1575 return $cgi->a({-href
=> $href, -class => "list subject"},
1576 esc_html
($long)) . $extra;
1580 # Rather than recomputing the url for an email multiple times, we cache it
1581 # after the first hit. This gives a visible benefit in views where the avatar
1582 # for the same email is used repeatedly (e.g. shortlog).
1583 # The cache is shared by all avatar engines (currently gravatar only), which
1584 # are free to use it as preferred. Since only one avatar engine is used for any
1585 # given page, there's no risk for cache conflicts.
1586 our %avatar_cache = ();
1588 # Compute the picon url for a given email, by using the picon search service over at
1589 # http://www.cs.indiana.edu/picons/search.html
1591 my $email = lc shift;
1592 if (!$avatar_cache{$email}) {
1593 my ($user, $domain) = split('@', $email);
1594 $avatar_cache{$email} =
1595 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1597 "users+domains+unknown/up/single";
1599 return $avatar_cache{$email};
1602 # Compute the gravatar url for a given email, if it's not in the cache already.
1603 # Gravatar stores only the part of the URL before the size, since that's the
1604 # one computationally more expensive. This also allows reuse of the cache for
1605 # different sizes (for this particular engine).
1607 my $email = lc shift;
1609 $avatar_cache{$email} ||=
1610 "http://www.gravatar.com/avatar/" .
1611 Digest
::MD5
::md5_hex
($email) . "?s=";
1612 return $avatar_cache{$email} . $size;
1615 # Insert an avatar for the given $email at the given $size if the feature
1617 sub git_get_avatar
{
1618 my ($email, %opts) = @_;
1619 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1620 my $post_white = ($opts{-pad_after
} ?
" " : "");
1621 $opts{-size
} ||= 'default';
1622 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1624 if ($git_avatar eq 'gravatar') {
1625 $url = gravatar_url
($email, $size);
1626 } elsif ($git_avatar eq 'picon') {
1627 $url = picon_url
($email);
1629 # Other providers can be added by extending the if chain, defining $url
1630 # as needed. If no variant puts something in $url, we assume avatars
1631 # are completely disabled/unavailable.
1634 "<img width=\"$size\" " .
1635 "class=\"avatar\" " .
1636 "src=\"".esc_url
($url)."\" " .
1644 sub format_search_author
{
1645 my ($author, $searchtype, $displaytext) = @_;
1646 my $have_search = gitweb_check_feature
('search');
1650 if ($searchtype eq 'author') {
1651 $performed = "authored";
1652 } elsif ($searchtype eq 'committer') {
1653 $performed = "committed";
1656 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1657 searchtext
=>$author,
1658 searchtype
=>$searchtype), class=>"list",
1659 title
=>"Search for commits $performed by $author"},
1663 return $displaytext;
1667 # format the author name of the given commit with the given tag
1668 # the author name is chopped and escaped according to the other
1669 # optional parameters (see chop_str).
1670 sub format_author_html
{
1673 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1674 return "<$tag class=\"author\">" .
1675 format_search_author
($co->{'author_name'}, "author",
1676 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1681 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1682 sub format_git_diff_header_line
{
1684 my $diffinfo = shift;
1685 my ($from, $to) = @_;
1687 if ($diffinfo->{'nparents'}) {
1689 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1690 if ($to->{'href'}) {
1691 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1692 esc_path
($to->{'file'}));
1693 } else { # file was deleted (no href)
1694 $line .= esc_path
($to->{'file'});
1698 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1699 if ($from->{'href'}) {
1700 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1701 'a/' . esc_path
($from->{'file'}));
1702 } else { # file was added (no href)
1703 $line .= 'a/' . esc_path
($from->{'file'});
1706 if ($to->{'href'}) {
1707 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1708 'b/' . esc_path
($to->{'file'}));
1709 } else { # file was deleted
1710 $line .= 'b/' . esc_path
($to->{'file'});
1714 return "<div class=\"diff header\">$line</div>\n";
1717 # format extended diff header line, before patch itself
1718 sub format_extended_diff_header_line
{
1720 my $diffinfo = shift;
1721 my ($from, $to) = @_;
1724 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1725 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1726 esc_path
($from->{'file'}));
1728 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1729 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1730 esc_path
($to->{'file'}));
1732 # match single <mode>
1733 if ($line =~ m/\s(\d{6})$/) {
1734 $line .= '<span class="info"> (' .
1735 file_type_long
($1) .
1739 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1740 # can match only for combined diff
1742 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1743 if ($from->{'href'}[$i]) {
1744 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1746 substr($diffinfo->{'from_id'}[$i],0,7));
1751 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1754 if ($to->{'href'}) {
1755 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1756 substr($diffinfo->{'to_id'},0,7));
1761 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1762 # can match only for ordinary diff
1763 my ($from_link, $to_link);
1764 if ($from->{'href'}) {
1765 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1766 substr($diffinfo->{'from_id'},0,7));
1768 $from_link = '0' x
7;
1770 if ($to->{'href'}) {
1771 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1772 substr($diffinfo->{'to_id'},0,7));
1776 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1777 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1780 return $line . "<br/>\n";
1783 # format from-file/to-file diff header
1784 sub format_diff_from_to_header
{
1785 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1790 #assert($line =~ m/^---/) if DEBUG;
1791 # no extra formatting for "^--- /dev/null"
1792 if (! $diffinfo->{'nparents'}) {
1793 # ordinary (single parent) diff
1794 if ($line =~ m!^--- "?a/!) {
1795 if ($from->{'href'}) {
1797 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1798 esc_path
($from->{'file'}));
1801 esc_path
($from->{'file'});
1804 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1807 # combined diff (merge commit)
1808 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1809 if ($from->{'href'}[$i]) {
1811 $cgi->a({-href
=>href
(action
=>"blobdiff",
1812 hash_parent
=>$diffinfo->{'from_id'}[$i],
1813 hash_parent_base
=>$parents[$i],
1814 file_parent
=>$from->{'file'}[$i],
1815 hash
=>$diffinfo->{'to_id'},
1817 file_name
=>$to->{'file'}),
1819 -title
=>"diff" . ($i+1)},
1822 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1823 esc_path
($from->{'file'}[$i]));
1825 $line = '--- /dev/null';
1827 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1832 #assert($line =~ m/^\+\+\+/) if DEBUG;
1833 # no extra formatting for "^+++ /dev/null"
1834 if ($line =~ m!^\+\+\+ "?b/!) {
1835 if ($to->{'href'}) {
1837 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1838 esc_path
($to->{'file'}));
1841 esc_path
($to->{'file'});
1844 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1849 # create note for patch simplified by combined diff
1850 sub format_diff_cc_simplified
{
1851 my ($diffinfo, @parents) = @_;
1854 $result .= "<div class=\"diff header\">" .
1856 if (!is_deleted
($diffinfo)) {
1857 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1859 hash
=>$diffinfo->{'to_id'},
1860 file_name
=>$diffinfo->{'to_file'}),
1862 esc_path
($diffinfo->{'to_file'}));
1864 $result .= esc_path
($diffinfo->{'to_file'});
1866 $result .= "</div>\n" . # class="diff header"
1867 "<div class=\"diff nodifferences\">" .
1869 "</div>\n"; # class="diff nodifferences"
1874 # format patch (diff) line (not to be used for diff headers)
1875 sub format_diff_line
{
1877 my ($from, $to) = @_;
1878 my $diff_class = "";
1882 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1884 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1885 if ($line =~ m/^\@{3}/) {
1886 $diff_class = " chunk_header";
1887 } elsif ($line =~ m/^\\/) {
1888 $diff_class = " incomplete";
1889 } elsif ($prefix =~ tr/+/+/) {
1890 $diff_class = " add";
1891 } elsif ($prefix =~ tr/-/-/) {
1892 $diff_class = " rem";
1895 # assume ordinary diff
1896 my $char = substr($line, 0, 1);
1898 $diff_class = " add";
1899 } elsif ($char eq '-') {
1900 $diff_class = " rem";
1901 } elsif ($char eq '@') {
1902 $diff_class = " chunk_header";
1903 } elsif ($char eq "\\") {
1904 $diff_class = " incomplete";
1907 $line = untabify
($line);
1908 if ($from && $to && $line =~ m/^\@{2} /) {
1909 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1910 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1912 $from_lines = 0 unless defined $from_lines;
1913 $to_lines = 0 unless defined $to_lines;
1915 if ($from->{'href'}) {
1916 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1917 -class=>"list"}, $from_text);
1919 if ($to->{'href'}) {
1920 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1921 -class=>"list"}, $to_text);
1923 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1924 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1925 return "<div class=\"diff$diff_class\">$line</div>\n";
1926 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1927 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1928 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1930 @from_text = split(' ', $ranges);
1931 for (my $i = 0; $i < @from_text; ++$i) {
1932 ($from_start[$i], $from_nlines[$i]) =
1933 (split(',', substr($from_text[$i], 1)), 0);
1936 $to_text = pop @from_text;
1937 $to_start = pop @from_start;
1938 $to_nlines = pop @from_nlines;
1940 $line = "<span class=\"chunk_info\">$prefix ";
1941 for (my $i = 0; $i < @from_text; ++$i) {
1942 if ($from->{'href'}[$i]) {
1943 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1944 -class=>"list"}, $from_text[$i]);
1946 $line .= $from_text[$i];
1950 if ($to->{'href'}) {
1951 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1952 -class=>"list"}, $to_text);
1956 $line .= " $prefix</span>" .
1957 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1958 return "<div class=\"diff$diff_class\">$line</div>\n";
1960 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1963 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1964 # linked. Pass the hash of the tree/commit to snapshot.
1965 sub format_snapshot_links
{
1967 my $num_fmts = @snapshot_fmts;
1968 if ($num_fmts > 1) {
1969 # A parenthesized list of links bearing format names.
1970 # e.g. "snapshot (_tar.gz_ _zip_)"
1971 return "snapshot (" . join(' ', map
1978 }, $known_snapshot_formats{$_}{'display'})
1979 , @snapshot_fmts) . ")";
1980 } elsif ($num_fmts == 1) {
1981 # A single "snapshot" link whose tooltip bears the format name.
1983 my ($fmt) = @snapshot_fmts;
1989 snapshot_format
=>$fmt
1991 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1993 } else { # $num_fmts == 0
1998 ## ......................................................................
1999 ## functions returning values to be passed, perhaps after some
2000 ## transformation, to other functions; e.g. returning arguments to href()
2002 # returns hash to be passed to href to generate gitweb URL
2003 # in -title key it returns description of link
2005 my $format = shift || 'Atom';
2006 my %res = (action
=> lc($format));
2008 # feed links are possible only for project views
2009 return unless (defined $project);
2010 # some views should link to OPML, or to generic project feed,
2011 # or don't have specific feed yet (so they should use generic)
2012 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2015 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2016 # from tag links; this also makes possible to detect branch links
2017 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2018 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2021 # find log type for feed description (title)
2023 if (defined $file_name) {
2024 $type = "history of $file_name";
2025 $type .= "/" if ($action eq 'tree');
2026 $type .= " on '$branch'" if (defined $branch);
2028 $type = "log of $branch" if (defined $branch);
2031 $res{-title
} = $type;
2032 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
2033 $res{'file_name'} = $file_name;
2038 ## ----------------------------------------------------------------------
2039 ## git utility subroutines, invoking git commands
2041 # returns path to the core git executable and the --git-dir parameter as list
2043 $number_of_git_cmds++;
2044 return $GIT, '--git-dir='.$git_dir;
2047 # quote the given arguments for passing them to the shell
2048 # quote_command("command", "arg 1", "arg with ' and ! characters")
2049 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2050 # Try to avoid using this function wherever possible.
2053 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2056 # get HEAD ref of given project as hash
2057 sub git_get_head_hash
{
2058 return git_get_full_hash
(shift, 'HEAD');
2061 sub git_get_full_hash
{
2062 return git_get_hash
(@_);
2065 sub git_get_short_hash
{
2066 return git_get_hash
(@_, '--short=7');
2070 my ($project, $hash, @options) = @_;
2071 my $o_git_dir = $git_dir;
2073 $git_dir = "$projectroot/$project";
2074 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2075 '--verify', '-q', @options, $hash) {
2077 chomp $retval if defined $retval;
2080 if (defined $o_git_dir) {
2081 $git_dir = $o_git_dir;
2086 # get type of given object
2090 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2092 close $fd or return;
2097 # repository configuration
2098 our $config_file = '';
2101 # store multiple values for single key as anonymous array reference
2102 # single values stored directly in the hash, not as [ <value> ]
2103 sub hash_set_multi
{
2104 my ($hash, $key, $value) = @_;
2106 if (!exists $hash->{$key}) {
2107 $hash->{$key} = $value;
2108 } elsif (!ref $hash->{$key}) {
2109 $hash->{$key} = [ $hash->{$key}, $value ];
2111 push @
{$hash->{$key}}, $value;
2115 # return hash of git project configuration
2116 # optionally limited to some section, e.g. 'gitweb'
2117 sub git_parse_project_config
{
2118 my $section_regexp = shift;
2123 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2126 while (my $keyval = <$fh>) {
2128 my ($key, $value) = split(/\n/, $keyval, 2);
2130 hash_set_multi
(\
%config, $key, $value)
2131 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2138 # convert config value to boolean: 'true' or 'false'
2139 # no value, number > 0, 'true' and 'yes' values are true
2140 # rest of values are treated as false (never as error)
2141 sub config_to_bool
{
2144 return 1 if !defined $val; # section.key
2146 # strip leading and trailing whitespace
2150 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2151 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2154 # convert config value to simple decimal number
2155 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2156 # to be multiplied by 1024, 1048576, or 1073741824
2160 # strip leading and trailing whitespace
2164 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2166 # unknown unit is treated as 1
2167 return $num * ($unit eq 'g' ?
1073741824 :
2168 $unit eq 'm' ?
1048576 :
2169 $unit eq 'k' ?
1024 : 1);
2174 # convert config value to array reference, if needed
2175 sub config_to_multi
{
2178 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2181 sub git_get_project_config
{
2182 my ($key, $type) = @_;
2185 return unless ($key);
2186 $key =~ s/^gitweb\.//;
2187 return if ($key =~ m/\W/);
2190 if (defined $type) {
2193 unless ($type eq 'bool' || $type eq 'int');
2197 if (!defined $config_file ||
2198 $config_file ne "$git_dir/config") {
2199 %config = git_parse_project_config
('gitweb');
2200 $config_file = "$git_dir/config";
2203 # check if config variable (key) exists
2204 return unless exists $config{"gitweb.$key"};
2207 if (!defined $type) {
2208 return $config{"gitweb.$key"};
2209 } elsif ($type eq 'bool') {
2210 # backward compatibility: 'git config --bool' returns true/false
2211 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2212 } elsif ($type eq 'int') {
2213 return config_to_int
($config{"gitweb.$key"});
2215 return $config{"gitweb.$key"};
2218 # get hash of given path at given ref
2219 sub git_get_hash_by_path
{
2221 my $path = shift || return undef;
2226 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2227 or die_error
(500, "Open git-ls-tree failed");
2229 close $fd or return undef;
2231 if (!defined $line) {
2232 # there is no tree or hash given by $path at $base
2236 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2237 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2238 if (defined $type && $type ne $2) {
2239 # type doesn't match
2245 # get path of entry with given hash at given tree-ish (ref)
2246 # used to get 'from' filename for combined diff (merge commit) for renames
2247 sub git_get_path_by_hash
{
2248 my $base = shift || return;
2249 my $hash = shift || return;
2253 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2255 while (my $line = <$fd>) {
2258 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2259 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2260 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2269 ## ......................................................................
2270 ## git utility functions, directly accessing git repository
2272 sub git_get_project_description
{
2275 $git_dir = "$projectroot/$path";
2276 open my $fd, '<', "$git_dir/description"
2277 or return git_get_project_config
('description');
2280 if (defined $descr) {
2286 sub git_get_project_ctags
{
2290 $git_dir = "$projectroot/$path";
2291 opendir my $dh, "$git_dir/ctags"
2293 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2294 open my $ct, '<', $_ or next;
2298 my $ctag = $_; $ctag =~ s
#.*/##;
2299 $ctags->{$ctag} = $val;
2305 sub git_populate_project_tagcloud
{
2308 # First, merge different-cased tags; tags vote on casing
2310 foreach (keys %$ctags) {
2311 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2312 if (not $ctags_lc{lc $_}->{topcount
}
2313 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2314 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2315 $ctags_lc{lc $_}->{topname
} = $_;
2320 if (eval { require HTML
::TagCloud
; 1; }) {
2321 $cloud = HTML
::TagCloud
->new;
2322 foreach (sort keys %ctags_lc) {
2323 # Pad the title with spaces so that the cloud looks
2325 my $title = $ctags_lc{$_}->{topname
};
2326 $title =~ s/ / /g;
2327 $title =~ s/^/ /g;
2328 $title =~ s/$/ /g;
2329 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2332 $cloud = \
%ctags_lc;
2337 sub git_show_project_tagcloud
{
2338 my ($cloud, $count) = @_;
2339 print STDERR
ref($cloud)."..\n";
2340 if (ref $cloud eq 'HTML::TagCloud') {
2341 return $cloud->html_and_css($count);
2343 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2344 return '<p align="center">' . join (', ', map {
2345 $cgi->a({-href
=>"$home_link?by_tag=$_"}, $cloud->{$_}->{topname
})
2346 } splice(@tags, 0, $count)) . '</p>';
2350 sub git_get_project_url_list
{
2353 $git_dir = "$projectroot/$path";
2354 open my $fd, '<', "$git_dir/cloneurl"
2355 or return wantarray ?
2356 @
{ config_to_multi
(git_get_project_config
('url')) } :
2357 config_to_multi
(git_get_project_config
('url'));
2358 my @git_project_url_list = map { chomp; $_ } <$fd>;
2361 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2364 sub git_get_projects_list
{
2369 $filter =~ s/\.git$//;
2371 my $check_forks = gitweb_check_feature
('forks');
2373 if (-d
$projects_list) {
2374 # search in directory
2375 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2376 # remove the trailing "/"
2378 my $pfxlen = length("$dir");
2379 my $pfxdepth = ($dir =~ tr!/!!);
2382 follow_fast
=> 1, # follow symbolic links
2383 follow_skip
=> 2, # ignore duplicates
2384 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2386 # skip project-list toplevel, if we get it.
2387 return if (m!^[/.]$!);
2388 # only directories can be git repositories
2389 return unless (-d
$_);
2390 # don't traverse too deep (Find is super slow on os x)
2391 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2392 $File::Find
::prune
= 1;
2396 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2397 # we check related file in $projectroot
2398 my $path = ($filter ?
"$filter/" : '') . $subdir;
2399 if (check_export_ok
("$projectroot/$path")) {
2400 push @list, { path
=> $path };
2401 $File::Find
::prune
= 1;
2406 } elsif (-f
$projects_list) {
2407 # read from file(url-encoded):
2408 # 'git%2Fgit.git Linus+Torvalds'
2409 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2410 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2412 open my $fd, '<', $projects_list or return;
2414 while (my $line = <$fd>) {
2416 my ($path, $owner) = split ' ', $line;
2417 $path = unescape
($path);
2418 $owner = unescape
($owner);
2419 if (!defined $path) {
2422 if ($filter ne '') {
2423 # looking for forks;
2424 my $pfx = substr($path, 0, length($filter));
2425 if ($pfx ne $filter) {
2428 my $sfx = substr($path, length($filter));
2429 if ($sfx !~ /^\/.*\
.git
$/) {
2432 } elsif ($check_forks) {
2434 foreach my $filter (keys %paths) {
2435 # looking for forks;
2436 my $pfx = substr($path, 0, length($filter));
2437 if ($pfx ne $filter) {
2440 my $sfx = substr($path, length($filter));
2441 if ($sfx !~ /^\/.*\
.git
$/) {
2444 # is a fork, don't include it in
2449 if (check_export_ok
("$projectroot/$path")) {
2452 owner
=> to_utf8
($owner),
2455 (my $forks_path = $path) =~ s/\.git$//;
2456 $paths{$forks_path}++;
2464 our $gitweb_project_owner = undef;
2465 sub git_get_project_list_from_file
{
2467 return if (defined $gitweb_project_owner);
2469 $gitweb_project_owner = {};
2470 # read from file (url-encoded):
2471 # 'git%2Fgit.git Linus+Torvalds'
2472 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2473 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2474 if (-f
$projects_list) {
2475 open(my $fd, '<', $projects_list);
2476 while (my $line = <$fd>) {
2478 my ($pr, $ow) = split ' ', $line;
2479 $pr = unescape
($pr);
2480 $ow = unescape
($ow);
2481 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2487 sub git_get_project_owner
{
2488 my $project = shift;
2491 return undef unless $project;
2492 $git_dir = "$projectroot/$project";
2494 if (!defined $gitweb_project_owner) {
2495 git_get_project_list_from_file
();
2498 if (exists $gitweb_project_owner->{$project}) {
2499 $owner = $gitweb_project_owner->{$project};
2501 if (!defined $owner){
2502 $owner = git_get_project_config
('owner');
2504 if (!defined $owner) {
2505 $owner = get_file_owner
("$git_dir");
2511 sub git_get_last_activity
{
2515 $git_dir = "$projectroot/$path";
2516 open($fd, "-|", git_cmd
(), 'for-each-ref',
2517 '--format=%(committer)',
2518 '--sort=-committerdate',
2520 'refs/heads') or return;
2521 my $most_recent = <$fd>;
2522 close $fd or return;
2523 if (defined $most_recent &&
2524 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2526 my $age = time - $timestamp;
2527 return ($age, age_string
($age));
2529 return (undef, undef);
2532 sub git_get_references
{
2533 my $type = shift || "";
2535 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2536 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2537 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2538 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2541 while (my $line = <$fd>) {
2543 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2544 if (defined $refs{$1}) {
2545 push @
{$refs{$1}}, $2;
2551 close $fd or return;
2555 sub git_get_rev_name_tags
{
2556 my $hash = shift || return undef;
2558 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2560 my $name_rev = <$fd>;
2563 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2566 # catches also '$hash undefined' output
2571 ## ----------------------------------------------------------------------
2572 ## parse to hash functions
2576 my $tz = shift || "-0000";
2579 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2580 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2581 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2582 $date{'hour'} = $hour;
2583 $date{'minute'} = $min;
2584 $date{'mday'} = $mday;
2585 $date{'day'} = $days[$wday];
2586 $date{'month'} = $months[$mon];
2587 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2588 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2589 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2590 $mday, $months[$mon], $hour ,$min;
2591 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2592 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2594 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2595 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2596 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2597 $date{'hour_local'} = $hour;
2598 $date{'minute_local'} = $min;
2599 $date{'tz_local'} = $tz;
2600 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2601 1900+$year, $mon+1, $mday,
2602 $hour, $min, $sec, $tz);
2611 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2612 $tag{'id'} = $tag_id;
2613 while (my $line = <$fd>) {
2615 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2616 $tag{'object'} = $1;
2617 } elsif ($line =~ m/^type (.+)$/) {
2619 } elsif ($line =~ m/^tag (.+)$/) {
2621 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2622 $tag{'author'} = $1;
2623 $tag{'author_epoch'} = $2;
2624 $tag{'author_tz'} = $3;
2625 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2626 $tag{'author_name'} = $1;
2627 $tag{'author_email'} = $2;
2629 $tag{'author_name'} = $tag{'author'};
2631 } elsif ($line =~ m/--BEGIN/) {
2632 push @comment, $line;
2634 } elsif ($line eq "") {
2638 push @comment, <$fd>;
2639 $tag{'comment'} = \
@comment;
2640 close $fd or return;
2641 if (!defined $tag{'name'}) {
2647 sub parse_commit_text
{
2648 my ($commit_text, $withparents) = @_;
2649 my @commit_lines = split '\n', $commit_text;
2652 pop @commit_lines; # Remove '\0'
2654 if (! @commit_lines) {
2658 my $header = shift @commit_lines;
2659 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2662 ($co{'id'}, my @parents) = split ' ', $header;
2663 while (my $line = shift @commit_lines) {
2664 last if $line eq "\n";
2665 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2667 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2669 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2670 $co{'author'} = to_utf8
($1);
2671 $co{'author_epoch'} = $2;
2672 $co{'author_tz'} = $3;
2673 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2674 $co{'author_name'} = $1;
2675 $co{'author_email'} = $2;
2677 $co{'author_name'} = $co{'author'};
2679 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2680 $co{'committer'} = to_utf8
($1);
2681 $co{'committer_epoch'} = $2;
2682 $co{'committer_tz'} = $3;
2683 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2684 $co{'committer_name'} = $1;
2685 $co{'committer_email'} = $2;
2687 $co{'committer_name'} = $co{'committer'};
2691 if (!defined $co{'tree'}) {
2694 $co{'parents'} = \
@parents;
2695 $co{'parent'} = $parents[0];
2697 foreach my $title (@commit_lines) {
2700 $co{'title'} = chop_str
($title, 80, 5);
2701 # remove leading stuff of merges to make the interesting part visible
2702 if (length($title) > 50) {
2703 $title =~ s/^Automatic //;
2704 $title =~ s/^merge (of|with) /Merge ... /i;
2705 if (length($title) > 50) {
2706 $title =~ s/(http|rsync):\/\///;
2708 if (length($title) > 50) {
2709 $title =~ s/(master|www|rsync)\.//;
2711 if (length($title) > 50) {
2712 $title =~ s/kernel.org:?//;
2714 if (length($title) > 50) {
2715 $title =~ s/\/pub\/scm//;
2718 $co{'title_short'} = chop_str
($title, 50, 5);
2722 if (! defined $co{'title'} || $co{'title'} eq "") {
2723 $co{'title'} = $co{'title_short'} = '(no commit message)';
2725 # remove added spaces
2726 foreach my $line (@commit_lines) {
2729 $co{'comment'} = \
@commit_lines;
2731 my $age = time - $co{'committer_epoch'};
2733 $co{'age_string'} = age_string
($age);
2734 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2735 if ($age > 60*60*24*7*2) {
2736 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2737 $co{'age_string_age'} = $co{'age_string'};
2739 $co{'age_string_date'} = $co{'age_string'};
2740 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2746 my ($commit_id) = @_;
2751 open my $fd, "-|", git_cmd
(), "rev-list",
2757 or die_error
(500, "Open git-rev-list failed");
2758 %co = parse_commit_text
(<$fd>, 1);
2765 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2773 open my $fd, "-|", git_cmd
(), "rev-list",
2776 ("--max-count=" . $maxcount),
2777 ("--skip=" . $skip),
2781 ($filename ?
($filename) : ())
2782 or die_error
(500, "Open git-rev-list failed");
2783 while (my $line = <$fd>) {
2784 my %co = parse_commit_text
($line);
2789 return wantarray ?
@cos : \
@cos;
2792 # parse line of git-diff-tree "raw" output
2793 sub parse_difftree_raw_line
{
2797 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2798 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2799 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2800 $res{'from_mode'} = $1;
2801 $res{'to_mode'} = $2;
2802 $res{'from_id'} = $3;
2804 $res{'status'} = $5;
2805 $res{'similarity'} = $6;
2806 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2807 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2809 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2812 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2813 # combined diff (for merge commit)
2814 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2815 $res{'nparents'} = length($1);
2816 $res{'from_mode'} = [ split(' ', $2) ];
2817 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2818 $res{'from_id'} = [ split(' ', $3) ];
2819 $res{'to_id'} = pop @
{$res{'from_id'}};
2820 $res{'status'} = [ split('', $4) ];
2821 $res{'to_file'} = unquote
($5);
2823 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2824 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2825 $res{'commit'} = $1;
2828 return wantarray ?
%res : \
%res;
2831 # wrapper: return parsed line of git-diff-tree "raw" output
2832 # (the argument might be raw line, or parsed info)
2833 sub parsed_difftree_line
{
2834 my $line_or_ref = shift;
2836 if (ref($line_or_ref) eq "HASH") {
2837 # pre-parsed (or generated by hand)
2838 return $line_or_ref;
2840 return parse_difftree_raw_line
($line_or_ref);
2844 # parse line of git-ls-tree output
2845 sub parse_ls_tree_line
{
2851 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2852 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2861 $res{'name'} = unquote
($5);
2864 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2865 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2873 $res{'name'} = unquote
($4);
2877 return wantarray ?
%res : \
%res;
2880 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2881 sub parse_from_to_diffinfo
{
2882 my ($diffinfo, $from, $to, @parents) = @_;
2884 if ($diffinfo->{'nparents'}) {
2886 $from->{'file'} = [];
2887 $from->{'href'} = [];
2888 fill_from_file_info
($diffinfo, @parents)
2889 unless exists $diffinfo->{'from_file'};
2890 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2891 $from->{'file'}[$i] =
2892 defined $diffinfo->{'from_file'}[$i] ?
2893 $diffinfo->{'from_file'}[$i] :
2894 $diffinfo->{'to_file'};
2895 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2896 $from->{'href'}[$i] = href
(action
=>"blob",
2897 hash_base
=>$parents[$i],
2898 hash
=>$diffinfo->{'from_id'}[$i],
2899 file_name
=>$from->{'file'}[$i]);
2901 $from->{'href'}[$i] = undef;
2905 # ordinary (not combined) diff
2906 $from->{'file'} = $diffinfo->{'from_file'};
2907 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2908 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2909 hash
=>$diffinfo->{'from_id'},
2910 file_name
=>$from->{'file'});
2912 delete $from->{'href'};
2916 $to->{'file'} = $diffinfo->{'to_file'};
2917 if (!is_deleted
($diffinfo)) { # file exists in result
2918 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2919 hash
=>$diffinfo->{'to_id'},
2920 file_name
=>$to->{'file'});
2922 delete $to->{'href'};
2926 ## ......................................................................
2927 ## parse to array of hashes functions
2929 sub git_get_heads_list
{
2933 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2934 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2935 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2938 while (my $line = <$fd>) {
2942 my ($refinfo, $committerinfo) = split(/\0/, $line);
2943 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2944 my ($committer, $epoch, $tz) =
2945 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2946 $ref_item{'fullname'} = $name;
2947 $name =~ s!^refs/heads/!!;
2949 $ref_item{'name'} = $name;
2950 $ref_item{'id'} = $hash;
2951 $ref_item{'title'} = $title || '(no commit message)';
2952 $ref_item{'epoch'} = $epoch;
2954 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2956 $ref_item{'age'} = "unknown";
2959 push @headslist, \
%ref_item;
2963 return wantarray ?
@headslist : \
@headslist;
2966 sub git_get_tags_list
{
2970 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2971 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2972 '--format=%(objectname) %(objecttype) %(refname) '.
2973 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2976 while (my $line = <$fd>) {
2980 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2981 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2982 my ($creator, $epoch, $tz) =
2983 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2984 $ref_item{'fullname'} = $name;
2985 $name =~ s!^refs/tags/!!;
2987 $ref_item{'type'} = $type;
2988 $ref_item{'id'} = $id;
2989 $ref_item{'name'} = $name;
2990 if ($type eq "tag") {
2991 $ref_item{'subject'} = $title;
2992 $ref_item{'reftype'} = $reftype;
2993 $ref_item{'refid'} = $refid;
2995 $ref_item{'reftype'} = $type;
2996 $ref_item{'refid'} = $id;
2999 if ($type eq "tag" || $type eq "commit") {
3000 $ref_item{'epoch'} = $epoch;
3002 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
3004 $ref_item{'age'} = "unknown";
3008 push @tagslist, \
%ref_item;
3012 return wantarray ?
@tagslist : \
@tagslist;
3015 ## ----------------------------------------------------------------------
3016 ## filesystem-related functions
3018 sub get_file_owner
{
3021 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3022 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3023 if (!defined $gcos) {
3027 $owner =~ s/[,;].*$//;
3028 return to_utf8
($owner);
3031 # assume that file exists
3033 my $filename = shift;
3035 open my $fd, '<', $filename;
3036 print map { to_utf8
($_) } <$fd>;
3040 ## ......................................................................
3041 ## mimetype related functions
3043 sub mimetype_guess_file
{
3044 my $filename = shift;
3045 my $mimemap = shift;
3046 -r
$mimemap or return undef;
3049 open(my $mh, '<', $mimemap) or return undef;
3051 next if m/^#/; # skip comments
3052 my ($mimetype, $exts) = split(/\t+/);
3053 if (defined $exts) {
3054 my @exts = split(/\s+/, $exts);
3055 foreach my $ext (@exts) {
3056 $mimemap{$ext} = $mimetype;
3062 $filename =~ /\.([^.]*)$/;
3063 return $mimemap{$1};
3066 sub mimetype_guess
{
3067 my $filename = shift;
3069 $filename =~ /\./ or return undef;
3071 if ($mimetypes_file) {
3072 my $file = $mimetypes_file;
3073 if ($file !~ m!^/!) { # if it is relative path
3074 # it is relative to project
3075 $file = "$projectroot/$project/$file";
3077 $mime = mimetype_guess_file
($filename, $file);
3079 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3085 my $filename = shift;
3088 my $mime = mimetype_guess
($filename);
3089 $mime and return $mime;
3093 return $default_blob_plain_mimetype unless $fd;
3096 return 'text/plain';
3097 } elsif (! $filename) {
3098 return 'application/octet-stream';
3099 } elsif ($filename =~ m/\.png$/i) {
3101 } elsif ($filename =~ m/\.gif$/i) {
3103 } elsif ($filename =~ m/\.jpe?g$/i) {
3104 return 'image/jpeg';
3106 return 'application/octet-stream';
3110 sub blob_contenttype
{
3111 my ($fd, $file_name, $type) = @_;
3113 $type ||= blob_mimetype
($fd, $file_name);
3114 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3115 $type .= "; charset=$default_text_plain_charset";
3121 ## ======================================================================
3122 ## functions printing HTML: header, footer, error page
3124 sub git_header_html
{
3125 my $status = shift || "200 OK";
3126 my $expires = shift;
3128 my $title = "$site_name";
3129 if (defined $project) {
3130 $title .= " - " . to_utf8
($project);
3131 if (defined $action) {
3132 $title .= "/$action";
3133 if (defined $file_name) {
3134 $title .= " - " . esc_path
($file_name);
3135 if ($action eq "tree" && $file_name !~ m
|/$|) {
3142 # require explicit support from the UA if we are to send the page as
3143 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3144 # we have to do this because MSIE sometimes globs '*/*', pretending to
3145 # support xhtml+xml but choking when it gets what it asked for.
3146 if (defined $cgi->http('HTTP_ACCEPT') &&
3147 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3148 $cgi->Accept('application/xhtml+xml') != 0) {
3149 $content_type = 'application/xhtml+xml';
3151 $content_type = 'text/html';
3153 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3154 -status
=> $status, -expires
=> $expires);
3155 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3157 <?xml version="1.0" encoding="utf-8"?>
3158 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3159 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3160 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3161 <!-- git core binaries version $git_version -->
3163 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3164 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3165 <meta name="robots" content="index, nofollow"/>
3166 <title>$title</title>
3168 # the stylesheet, favicon etc urls won't work correctly with path_info
3169 # unless we set the appropriate base URL
3170 if ($ENV{'PATH_INFO'}) {
3171 print "<base href=\"".esc_url
($base_url)."\" />\n";
3173 # print out each stylesheet that exist, providing backwards capability
3174 # for those people who defined $stylesheet in a config file
3175 if (defined $stylesheet) {
3176 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3178 foreach my $stylesheet (@stylesheets) {
3179 next unless $stylesheet;
3180 print '<link rel="stylesheet" type="text/css" href="'.esc_url
($stylesheet).'"/>'."\n";
3183 if (defined $project) {
3184 my %href_params = get_feed_info
();
3185 if (!exists $href_params{'-title'}) {
3186 $href_params{'-title'} = 'log';
3189 foreach my $format qw(RSS Atom) {
3190 my $type = lc($format);
3192 '-rel' => 'alternate',
3193 '-title' => esc_attr
("$project - $href_params{'-title'} - $format feed"),
3194 '-type' => "application/$type+xml"
3197 $href_params{'action'} = $type;
3198 $link_attr{'-href'} = href
(%href_params);
3200 "rel=\"$link_attr{'-rel'}\" ".
3201 "title=\"$link_attr{'-title'}\" ".
3202 "href=\"$link_attr{'-href'}\" ".
3203 "type=\"$link_attr{'-type'}\" ".
3206 $href_params{'extra_options'} = '--no-merges';
3207 $link_attr{'-href'} = href
(%href_params);
3208 $link_attr{'-title'} .= ' (no merges)';
3210 "rel=\"$link_attr{'-rel'}\" ".
3211 "title=\"$link_attr{'-title'}\" ".
3212 "href=\"$link_attr{'-href'}\" ".
3213 "type=\"$link_attr{'-type'}\" ".
3218 printf('<link rel="alternate" title="%s projects list" '.
3219 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3220 esc_attr
($site_name), href
(project
=>undef, action
=>"project_index"));
3221 printf('<link rel="alternate" title="%s projects feeds" '.
3222 'href="%s" type="text/x-opml" />'."\n",
3223 esc_attr
($site_name), href
(project
=>undef, action
=>"opml"));
3225 if (defined $favicon) {
3226 print qq(<link rel
="shortcut icon" href
=").esc_url($favicon).qq(" type
="image/png" />\n);
3232 if (-f
$site_header) {
3233 insert_file
($site_header);
3236 print "<div class=\"page_header\">\n" .
3237 $cgi->a({-href
=> esc_url
($logo_url),
3238 -title
=> $logo_label},
3239 qq(<img src
=").esc_url($logo).qq(" width
="72" height
="27" alt
="git" class="logo"/>));
3240 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3241 if (defined $project) {
3242 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3243 if (defined $action) {
3250 my $have_search = gitweb_check_feature
('search');
3251 if (defined $project && $have_search) {
3252 if (!defined $searchtext) {
3256 if (defined $hash_base) {
3257 $search_hash = $hash_base;
3258 } elsif (defined $hash) {
3259 $search_hash = $hash;
3261 $search_hash = "HEAD";
3263 my $action = $my_uri;
3264 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3265 if ($use_pathinfo) {
3266 $action .= "/".esc_url
($project);
3268 print $cgi->startform(-method
=> "get", -action
=> $action) .
3269 "<div class=\"search\">\n" .
3271 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3272 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3273 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3274 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3275 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3276 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3278 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3279 "<span title=\"Extended regular expression\">" .
3280 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3281 -checked
=> $search_use_regexp) .
3284 $cgi->end_form() . "\n";
3288 sub git_footer_html
{
3289 my $feed_class = 'rss_logo';
3291 print "<div class=\"page_footer\">\n";
3292 if (defined $project) {
3293 my $descr = git_get_project_description
($project);
3294 if (defined $descr) {
3295 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3298 my %href_params = get_feed_info
();
3299 if (!%href_params) {
3300 $feed_class .= ' generic';
3302 $href_params{'-title'} ||= 'log';
3304 foreach my $format qw(RSS Atom) {
3305 $href_params{'action'} = lc($format);
3306 print $cgi->a({-href
=> href
(%href_params),
3307 -title
=> "$href_params{'-title'} $format feed",
3308 -class => $feed_class}, $format)."\n";
3312 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3313 -class => $feed_class}, "OPML") . " ";
3314 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3315 -class => $feed_class}, "TXT") . "\n";
3317 print "</div>\n"; # class="page_footer"
3319 if (defined $t0 && gitweb_check_feature
('timed')) {
3320 print "<div id=\"generating_info\">\n";
3321 print 'This page took '.
3322 '<span id="generating_time" class="time_span">'.
3323 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3326 '<span id="generating_cmd">'.
3327 $number_of_git_cmds.
3328 '</span> git commands '.
3330 print "</div>\n"; # class="page_footer"
3333 if (-f
$site_footer) {
3334 insert_file
($site_footer);
3337 print qq!<script type
="text/javascript" src
="!.esc_url($javascript).qq!"></script
>\n!;
3338 if ($action eq 'blame_incremental') {
3339 print qq!<script type
="text/javascript">\n!.
3340 qq!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3341 qq! "!. href() .qq!");\n!.
3343 } elsif (gitweb_check_feature
('javascript-actions')) {
3344 print qq!<script type
="text/javascript">\n!.
3345 qq!window
.onload
= fixLinks
;\n!.
3353 # die_error(<http_status_code>, <error_message>)
3354 # Example: die_error(404, 'Hash not found')
3355 # By convention, use the following status codes (as defined in RFC 2616):
3356 # 400: Invalid or missing CGI parameters, or
3357 # requested object exists but has wrong type.
3358 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3359 # this server or project.
3360 # 404: Requested object/revision/project doesn't exist.
3361 # 500: The server isn't configured properly, or
3362 # an internal error occurred (e.g. failed assertions caused by bugs), or
3363 # an unknown error occurred (e.g. the git binary died unexpectedly).
3365 my $status = shift || 500;
3366 my $error = shift || "Internal server error";
3368 my %http_responses = (400 => '400 Bad Request',
3369 403 => '403 Forbidden',
3370 404 => '404 Not Found',
3371 500 => '500 Internal Server Error');
3372 git_header_html
($http_responses{$status});
3374 <div class="page_body">
3384 ## ----------------------------------------------------------------------
3385 ## functions printing or outputting HTML: navigation
3387 sub git_print_page_nav
{
3388 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3389 $extra = '' if !defined $extra; # pager or formats
3391 my @navs = qw(summary shortlog log commit commitdiff tree);
3393 @navs = grep { $_ ne $suppress } @navs;
3396 my %arg = map { $_ => {action
=>$_} } @navs;
3397 if (defined $head) {
3398 for (qw(commit commitdiff)) {
3399 $arg{$_}{'hash'} = $head;
3401 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3402 for (qw(shortlog log)) {
3403 $arg{$_}{'hash'} = $head;
3408 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3409 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3411 my @actions = gitweb_get_feature
('actions');
3414 'n' => $project, # project name
3415 'f' => $git_dir, # project path within filesystem
3416 'h' => $treehead || '', # current hash ('h' parameter)
3417 'b' => $treebase || '', # hash base ('hb' parameter)
3420 my ($label, $link, $pos) = splice(@actions,0,3);
3422 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3424 $link =~ s/%([%nfhb])/$repl{$1}/g;
3425 $arg{$label}{'_href'} = $link;
3428 print "<div class=\"page_nav\">\n" .
3430 map { $_ eq $current ?
3431 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3433 print "<br/>\n$extra<br/>\n" .
3437 sub format_paging_nav
{
3438 my ($action, $page, $has_next_link) = @_;
3444 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3446 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3447 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3449 $paging_nav .= "first ⋅ prev";
3452 if ($has_next_link) {
3453 $paging_nav .= " ⋅ " .
3454 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3455 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3457 $paging_nav .= " ⋅ next";
3463 ## ......................................................................
3464 ## functions printing or outputting HTML: div
3466 sub git_print_header_div
{
3467 my ($action, $title, $hash, $hash_base) = @_;
3470 $args{'action'} = $action;
3471 $args{'hash'} = $hash if $hash;
3472 $args{'hash_base'} = $hash_base if $hash_base;
3474 print "<div class=\"header\">\n" .
3475 $cgi->a({-href
=> href
(%args), -class => "title"},
3476 $title ?
$title : $action) .
3480 sub print_local_time
{
3482 if ($date{'hour_local'} < 6) {
3483 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3484 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3486 printf(" (%02d:%02d %s)",
3487 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3491 # Outputs the author name and date in long form
3492 sub git_print_authorship
{
3495 my $tag = $opts{-tag
} || 'div';
3496 my $author = $co->{'author_name'};
3498 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3499 print "<$tag class=\"author_date\">" .
3500 format_search_author
($author, "author", esc_html
($author)) .
3502 print_local_time
(%ad) if ($opts{-localtime});
3503 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3507 # Outputs table rows containing the full author or committer information,
3508 # in the format expected for 'commit' view (& similia).
3509 # Parameters are a commit hash reference, followed by the list of people
3510 # to output information for. If the list is empty it defalts to both
3511 # author and committer.
3512 sub git_print_authorship_rows
{
3514 # too bad we can't use @people = @_ || ('author', 'committer')
3516 @people = ('author', 'committer') unless @people;
3517 foreach my $who (@people) {
3518 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3519 print "<tr><td>$who</td><td>" .
3520 format_search_author
($co->{"${who}_name"}, $who,
3521 esc_html
($co->{"${who}_name"})) . " " .
3522 format_search_author
($co->{"${who}_email"}, $who,
3523 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3524 "</td><td rowspan=\"2\">" .
3525 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3528 "<td></td><td> $wd{'rfc2822'}";
3529 print_local_time
(%wd);
3535 sub git_print_page_path
{
3541 print "<div class=\"page_path\">";
3542 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3543 -title
=> 'tree root'}, to_utf8
("[$project]"));
3545 if (defined $name) {
3546 my @dirname = split '/', $name;
3547 my $basename = pop @dirname;
3550 foreach my $dir (@dirname) {
3551 $fullname .= ($fullname ?
'/' : '') . $dir;
3552 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3554 -title
=> $fullname}, esc_path
($dir));
3557 if (defined $type && $type eq 'blob') {
3558 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3560 -title
=> $name}, esc_path
($basename));
3561 } elsif (defined $type && $type eq 'tree') {
3562 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3564 -title
=> $name}, esc_path
($basename));
3567 print esc_path
($basename);
3570 print "<br/></div>\n";
3577 if ($opts{'-remove_title'}) {
3578 # remove title, i.e. first line of log
3581 # remove leading empty lines
3582 while (defined $log->[0] && $log->[0] eq "") {
3589 foreach my $line (@
$log) {
3590 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3593 if (! $opts{'-remove_signoff'}) {
3594 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3597 # remove signoff lines
3604 # print only one empty line
3605 # do not print empty line after signoff
3607 next if ($empty || $signoff);
3613 print format_log_line_html
($line) . "<br/>\n";
3616 if ($opts{'-final_empty_line'}) {
3617 # end with single empty line
3618 print "<br/>\n" unless $empty;
3622 # return link target (what link points to)
3623 sub git_get_link_target
{
3628 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3632 $link_target = <$fd>;
3637 return $link_target;
3640 # given link target, and the directory (basedir) the link is in,
3641 # return target of link relative to top directory (top tree);
3642 # return undef if it is not possible (including absolute links).
3643 sub normalize_link_target
{
3644 my ($link_target, $basedir) = @_;
3646 # absolute symlinks (beginning with '/') cannot be normalized
3647 return if (substr($link_target, 0, 1) eq '/');
3649 # normalize link target to path from top (root) tree (dir)
3652 $path = $basedir . '/' . $link_target;
3654 # we are in top (root) tree (dir)
3655 $path = $link_target;
3658 # remove //, /./, and /../
3660 foreach my $part (split('/', $path)) {
3661 # discard '.' and ''
3662 next if (!$part || $part eq '.');
3664 if ($part eq '..') {
3668 # link leads outside repository (outside top dir)
3672 push @path_parts, $part;
3675 $path = join('/', @path_parts);
3680 # print tree entry (row of git_tree), but without encompassing <tr> element
3681 sub git_print_tree_entry
{
3682 my ($t, $basedir, $hash_base, $have_blame) = @_;
3685 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3687 # The format of a table row is: mode list link. Where mode is
3688 # the mode of the entry, list is the name of the entry, an href,
3689 # and link is the action links of the entry.
3691 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3692 if (exists $t->{'size'}) {
3693 print "<td class=\"size\">$t->{'size'}</td>\n";
3695 if ($t->{'type'} eq "blob") {
3696 print "<td class=\"list\">" .
3697 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3698 file_name
=>"$basedir$t->{'name'}", %base_key),
3699 -class => "list"}, esc_path
($t->{'name'}));
3700 if (S_ISLNK
(oct $t->{'mode'})) {
3701 my $link_target = git_get_link_target
($t->{'hash'});
3703 my $norm_target = normalize_link_target
($link_target, $basedir);
3704 if (defined $norm_target) {
3706 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3707 file_name
=>$norm_target),
3708 -title
=> $norm_target}, esc_path
($link_target));
3710 print " -> " . esc_path
($link_target);
3715 print "<td class=\"link\">";
3716 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3717 file_name
=>"$basedir$t->{'name'}", %base_key)},
3721 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3722 file_name
=>"$basedir$t->{'name'}", %base_key)},
3725 if (defined $hash_base) {
3727 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3728 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3732 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3733 file_name
=>"$basedir$t->{'name'}")},
3737 } elsif ($t->{'type'} eq "tree") {
3738 print "<td class=\"list\">";
3739 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3740 file_name
=>"$basedir$t->{'name'}",
3742 esc_path
($t->{'name'}));
3744 print "<td class=\"link\">";
3745 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3746 file_name
=>"$basedir$t->{'name'}",
3749 if (defined $hash_base) {
3751 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3752 file_name
=>"$basedir$t->{'name'}")},
3757 # unknown object: we can only present history for it
3758 # (this includes 'commit' object, i.e. submodule support)
3759 print "<td class=\"list\">" .
3760 esc_path
($t->{'name'}) .
3762 print "<td class=\"link\">";
3763 if (defined $hash_base) {
3764 print $cgi->a({-href
=> href
(action
=>"history",
3765 hash_base
=>$hash_base,
3766 file_name
=>"$basedir$t->{'name'}")},
3773 ## ......................................................................
3774 ## functions printing large fragments of HTML
3776 # get pre-image filenames for merge (combined) diff
3777 sub fill_from_file_info
{
3778 my ($diff, @parents) = @_;
3780 $diff->{'from_file'} = [ ];
3781 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3782 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3783 if ($diff->{'status'}[$i] eq 'R' ||
3784 $diff->{'status'}[$i] eq 'C') {
3785 $diff->{'from_file'}[$i] =
3786 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3793 # is current raw difftree line of file deletion
3795 my $diffinfo = shift;
3797 return $diffinfo->{'to_id'} eq ('0' x
40);
3800 # does patch correspond to [previous] difftree raw line
3801 # $diffinfo - hashref of parsed raw diff format
3802 # $patchinfo - hashref of parsed patch diff format
3803 # (the same keys as in $diffinfo)
3804 sub is_patch_split
{
3805 my ($diffinfo, $patchinfo) = @_;
3807 return defined $diffinfo && defined $patchinfo
3808 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3812 sub git_difftree_body
{
3813 my ($difftree, $hash, @parents) = @_;
3814 my ($parent) = $parents[0];
3815 my $have_blame = gitweb_check_feature
('blame');
3816 print "<div class=\"list_head\">\n";
3817 if ($#{$difftree} > 10) {
3818 print(($#{$difftree} + 1) . " files changed:\n");
3822 print "<table class=\"" .
3823 (@parents > 1 ?
"combined " : "") .
3826 # header only for combined diff in 'commitdiff' view
3827 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3830 print "<thead><tr>\n" .
3831 "<th></th><th></th>\n"; # filename, patchN link
3832 for (my $i = 0; $i < @parents; $i++) {
3833 my $par = $parents[$i];
3835 $cgi->a({-href
=> href
(action
=>"commitdiff",
3836 hash
=>$hash, hash_parent
=>$par),
3837 -title
=> 'commitdiff to parent number ' .
3838 ($i+1) . ': ' . substr($par,0,7)},
3842 print "</tr></thead>\n<tbody>\n";
3847 foreach my $line (@
{$difftree}) {
3848 my $diff = parsed_difftree_line
($line);
3851 print "<tr class=\"dark\">\n";
3853 print "<tr class=\"light\">\n";
3857 if (exists $diff->{'nparents'}) { # combined diff
3859 fill_from_file_info
($diff, @parents)
3860 unless exists $diff->{'from_file'};
3862 if (!is_deleted
($diff)) {
3863 # file exists in the result (child) commit
3865 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3866 file_name
=>$diff->{'to_file'},
3868 -class => "list"}, esc_path
($diff->{'to_file'})) .
3872 esc_path
($diff->{'to_file'}) .
3876 if ($action eq 'commitdiff') {
3879 print "<td class=\"link\">" .
3880 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3885 my $has_history = 0;
3886 my $not_deleted = 0;
3887 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3888 my $hash_parent = $parents[$i];
3889 my $from_hash = $diff->{'from_id'}[$i];
3890 my $from_path = $diff->{'from_file'}[$i];
3891 my $status = $diff->{'status'}[$i];
3893 $has_history ||= ($status ne 'A');
3894 $not_deleted ||= ($status ne 'D');
3896 if ($status eq 'A') {
3897 print "<td class=\"link\" align=\"right\"> | </td>\n";
3898 } elsif ($status eq 'D') {
3899 print "<td class=\"link\">" .
3900 $cgi->a({-href
=> href
(action
=>"blob",
3903 file_name
=>$from_path)},
3907 if ($diff->{'to_id'} eq $from_hash) {
3908 print "<td class=\"link nochange\">";
3910 print "<td class=\"link\">";
3912 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3913 hash
=>$diff->{'to_id'},
3914 hash_parent
=>$from_hash,
3916 hash_parent_base
=>$hash_parent,
3917 file_name
=>$diff->{'to_file'},
3918 file_parent
=>$from_path)},
3924 print "<td class=\"link\">";
3926 print $cgi->a({-href
=> href
(action
=>"blob",
3927 hash
=>$diff->{'to_id'},
3928 file_name
=>$diff->{'to_file'},
3931 print " | " if ($has_history);
3934 print $cgi->a({-href
=> href
(action
=>"history",
3935 file_name
=>$diff->{'to_file'},
3942 next; # instead of 'else' clause, to avoid extra indent
3944 # else ordinary diff
3946 my ($to_mode_oct, $to_mode_str, $to_file_type);
3947 my ($from_mode_oct, $from_mode_str, $from_file_type);
3948 if ($diff->{'to_mode'} ne ('0' x
6)) {
3949 $to_mode_oct = oct $diff->{'to_mode'};
3950 if (S_ISREG
($to_mode_oct)) { # only for regular file
3951 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3953 $to_file_type = file_type
($diff->{'to_mode'});
3955 if ($diff->{'from_mode'} ne ('0' x
6)) {
3956 $from_mode_oct = oct $diff->{'from_mode'};
3957 if (S_ISREG
($to_mode_oct)) { # only for regular file
3958 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3960 $from_file_type = file_type
($diff->{'from_mode'});
3963 if ($diff->{'status'} eq "A") { # created
3964 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3965 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3966 $mode_chng .= "]</span>";
3968 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3969 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3970 -class => "list"}, esc_path
($diff->{'file'}));
3972 print "<td>$mode_chng</td>\n";
3973 print "<td class=\"link\">";
3974 if ($action eq 'commitdiff') {
3977 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3980 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3981 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3985 } elsif ($diff->{'status'} eq "D") { # deleted
3986 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3988 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3989 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3990 -class => "list"}, esc_path
($diff->{'file'}));
3992 print "<td>$mode_chng</td>\n";
3993 print "<td class=\"link\">";
3994 if ($action eq 'commitdiff') {
3997 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
4000 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
4001 hash_base
=>$parent, file_name
=>$diff->{'file'})},
4004 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
4005 file_name
=>$diff->{'file'})},
4008 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4009 file_name
=>$diff->{'file'})},
4013 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4014 my $mode_chnge = "";
4015 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4016 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4017 if ($from_file_type ne $to_file_type) {
4018 $mode_chnge .= " from $from_file_type to $to_file_type";
4020 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4021 if ($from_mode_str && $to_mode_str) {
4022 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4023 } elsif ($to_mode_str) {
4024 $mode_chnge .= " mode: $to_mode_str";
4027 $mode_chnge .= "]</span>\n";
4030 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4031 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4032 -class => "list"}, esc_path
($diff->{'file'}));
4034 print "<td>$mode_chnge</td>\n";
4035 print "<td class=\"link\">";
4036 if ($action eq 'commitdiff') {
4039 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4041 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4042 # "commit" view and modified file (not onlu mode changed)
4043 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4044 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4045 hash_base
=>$hash, hash_parent_base
=>$parent,
4046 file_name
=>$diff->{'file'})},
4050 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4051 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4054 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4055 file_name
=>$diff->{'file'})},
4058 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4059 file_name
=>$diff->{'file'})},
4063 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4064 my %status_name = ('R' => 'moved', 'C' => 'copied');
4065 my $nstatus = $status_name{$diff->{'status'}};
4067 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4068 # mode also for directories, so we cannot use $to_mode_str
4069 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4072 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4073 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4074 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4075 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4076 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4077 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4078 -class => "list"}, esc_path
($diff->{'from_file'})) .
4079 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4080 "<td class=\"link\">";
4081 if ($action eq 'commitdiff') {
4084 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4086 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4087 # "commit" view and modified file (not only pure rename or copy)
4088 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4089 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4090 hash_base
=>$hash, hash_parent_base
=>$parent,
4091 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4095 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4096 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4099 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4100 file_name
=>$diff->{'to_file'})},
4103 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4104 file_name
=>$diff->{'to_file'})},
4108 } # we should not encounter Unmerged (U) or Unknown (X) status
4111 print "</tbody>" if $has_header;
4115 sub git_patchset_body
{
4116 my ($fd, $difftree, $hash, @hash_parents) = @_;
4117 my ($hash_parent) = $hash_parents[0];
4119 my $is_combined = (@hash_parents > 1);
4121 my $patch_number = 0;
4127 print "<div class=\"patchset\">\n";
4129 # skip to first patch
4130 while ($patch_line = <$fd>) {
4133 last if ($patch_line =~ m/^diff /);
4137 while ($patch_line) {
4139 # parse "git diff" header line
4140 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4141 # $1 is from_name, which we do not use
4142 $to_name = unquote
($2);
4143 $to_name =~ s!^b/!!;
4144 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4145 # $1 is 'cc' or 'combined', which we do not use
4146 $to_name = unquote
($2);
4151 # check if current patch belong to current raw line
4152 # and parse raw git-diff line if needed
4153 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4154 # this is continuation of a split patch
4155 print "<div class=\"patch cont\">\n";
4157 # advance raw git-diff output if needed
4158 $patch_idx++ if defined $diffinfo;
4160 # read and prepare patch information
4161 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4163 # compact combined diff output can have some patches skipped
4164 # find which patch (using pathname of result) we are at now;
4166 while ($to_name ne $diffinfo->{'to_file'}) {
4167 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4168 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4169 "</div>\n"; # class="patch"
4174 last if $patch_idx > $#$difftree;
4175 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4179 # modifies %from, %to hashes
4180 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4182 # this is first patch for raw difftree line with $patch_idx index
4183 # we index @$difftree array from 0, but number patches from 1
4184 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4188 #assert($patch_line =~ m/^diff /) if DEBUG;
4189 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4191 # print "git diff" header
4192 print format_git_diff_header_line
($patch_line, $diffinfo,
4195 # print extended diff header
4196 print "<div class=\"diff extended_header\">\n";
4198 while ($patch_line = <$fd>) {
4201 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4203 print format_extended_diff_header_line
($patch_line, $diffinfo,
4206 print "</div>\n"; # class="diff extended_header"
4208 # from-file/to-file diff header
4209 if (! $patch_line) {
4210 print "</div>\n"; # class="patch"
4213 next PATCH
if ($patch_line =~ m/^diff /);
4214 #assert($patch_line =~ m/^---/) if DEBUG;
4216 my $last_patch_line = $patch_line;
4217 $patch_line = <$fd>;
4219 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4221 print format_diff_from_to_header
($last_patch_line, $patch_line,
4222 $diffinfo, \
%from, \
%to,
4227 while ($patch_line = <$fd>) {
4230 next PATCH
if ($patch_line =~ m/^diff /);
4232 print format_diff_line
($patch_line, \
%from, \
%to);
4236 print "</div>\n"; # class="patch"
4239 # for compact combined (--cc) format, with chunk and patch simpliciaction
4240 # patchset might be empty, but there might be unprocessed raw lines
4241 for (++$patch_idx if $patch_number > 0;
4242 $patch_idx < @
$difftree;
4244 # read and prepare patch information
4245 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4247 # generate anchor for "patch" links in difftree / whatchanged part
4248 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4249 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4250 "</div>\n"; # class="patch"
4255 if ($patch_number == 0) {
4256 if (@hash_parents > 1) {
4257 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4259 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4263 print "</div>\n"; # class="patchset"
4266 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4268 # fills project list info (age, description, owner, forks) for each
4269 # project in the list, removing invalid projects from returned list
4270 # NOTE: modifies $projlist, but does not remove entries from it
4271 sub fill_project_list_info
{
4272 my ($projlist, $check_forks) = @_;
4275 my $show_ctags = gitweb_check_feature
('ctags');
4277 foreach my $pr (@
$projlist) {
4278 my (@activity) = git_get_last_activity
($pr->{'path'});
4279 unless (@activity) {
4282 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4283 if (!defined $pr->{'descr'}) {
4284 my $descr = git_get_project_description
($pr->{'path'}) || "";
4285 $descr = to_utf8
($descr);
4286 $pr->{'descr_long'} = $descr;
4287 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4289 if (!defined $pr->{'owner'}) {
4290 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4293 my $pname = $pr->{'path'};
4294 if (($pname =~ s/\.git$//) &&
4295 ($pname !~ /\/$/) &&
4296 (-d
"$projectroot/$pname")) {
4297 $pr->{'forks'} = "-d $projectroot/$pname";
4302 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4303 push @projects, $pr;
4309 # print 'sort by' <th> element, generating 'sort by $name' replay link
4310 # if that order is not selected
4312 my ($name, $order, $header) = @_;
4313 $header ||= ucfirst($name);
4315 if ($order eq $name) {
4316 print "<th>$header</th>\n";
4319 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4320 -class => "header"}, $header) .
4325 sub git_project_list_body
{
4326 # actually uses global variable $project
4327 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4329 my $check_forks = gitweb_check_feature
('forks');
4330 my @projects = fill_project_list_info
($projlist, $check_forks);
4332 $order ||= $default_projects_order;
4333 $from = 0 unless defined $from;
4334 $to = $#projects if (!defined $to || $#projects < $to);
4337 project
=> { key
=> 'path', type
=> 'str' },
4338 descr
=> { key
=> 'descr_long', type
=> 'str' },
4339 owner
=> { key
=> 'owner', type
=> 'str' },
4340 age
=> { key
=> 'age', type
=> 'num' }
4342 my $oi = $order_info{$order};
4343 if ($oi->{'type'} eq 'str') {
4344 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4346 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4349 my $show_ctags = gitweb_check_feature
('ctags');
4352 foreach my $p (@projects) {
4353 foreach my $ct (keys %{$p->{'ctags'}}) {
4354 $ctags{$ct} += $p->{'ctags'}->{$ct};
4357 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4358 print git_show_project_tagcloud
($cloud, 64);
4361 print "<table class=\"project_list\">\n";
4362 unless ($no_header) {
4365 print "<th></th>\n";
4367 print_sort_th
('project', $order, 'Project');
4368 print_sort_th
('descr', $order, 'Description');
4369 print_sort_th
('owner', $order, 'Owner');
4370 print_sort_th
('age', $order, 'Last Change');
4371 print "<th></th>\n" . # for links
4375 my $tagfilter = $cgi->param('by_tag');
4376 for (my $i = $from; $i <= $to; $i++) {
4377 my $pr = $projects[$i];
4379 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4380 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4381 and not $pr->{'descr_long'} =~ /$searchtext/;
4382 # Weed out forks or non-matching entries of search
4384 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4385 $forkbase="^$forkbase" if $forkbase;
4386 next if not $searchtext and not $tagfilter and $show_ctags
4387 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4391 print "<tr class=\"dark\">\n";
4393 print "<tr class=\"light\">\n";
4398 if ($pr->{'forks'}) {
4399 print "<!-- $pr->{'forks'} -->\n";
4400 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4404 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4405 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4406 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4407 -class => "list", -title
=> $pr->{'descr_long'}},
4408 esc_html
($pr->{'descr'})) . "</td>\n" .
4409 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4410 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4411 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4412 "<td class=\"link\">" .
4413 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4414 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4415 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4416 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4417 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4421 if (defined $extra) {
4424 print "<td></td>\n";
4426 print "<td colspan=\"5\">$extra</td>\n" .
4433 # uses global variable $project
4434 my ($commitlist, $from, $to, $refs, $extra) = @_;
4436 $from = 0 unless defined $from;
4437 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4439 for (my $i = 0; $i <= $to; $i++) {
4440 my %co = %{$commitlist->[$i]};
4442 my $commit = $co{'id'};
4443 my $ref = format_ref_marker
($refs, $commit);
4444 my %ad = parse_date
($co{'author_epoch'});
4445 git_print_header_div
('commit',
4446 "<span class=\"age\">$co{'age_string'}</span>" .
4447 esc_html
($co{'title'}) . $ref,
4449 print "<div class=\"title_text\">\n" .
4450 "<div class=\"log_link\">\n" .
4451 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4453 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4455 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4458 git_print_authorship
(\
%co, -tag
=> 'span');
4459 print "<br/>\n</div>\n";
4461 print "<div class=\"log_body\">\n";
4462 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4466 print "<div class=\"page_nav\">\n";
4472 sub git_shortlog_body
{
4473 # uses global variable $project
4474 my ($commitlist, $from, $to, $refs, $extra) = @_;
4476 $from = 0 unless defined $from;
4477 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4479 print "<table class=\"shortlog\">\n";
4481 for (my $i = $from; $i <= $to; $i++) {
4482 my %co = %{$commitlist->[$i]};
4483 my $commit = $co{'id'};
4484 my $ref = format_ref_marker
($refs, $commit);
4486 print "<tr class=\"dark\">\n";
4488 print "<tr class=\"light\">\n";
4491 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4492 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4493 format_author_html
('td', \
%co, 10) . "<td>";
4494 print format_subject_html
($co{'title'}, $co{'title_short'},
4495 href
(action
=>"commit", hash
=>$commit), $ref);
4497 "<td class=\"link\">" .
4498 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4499 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4500 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4501 my $snapshot_links = format_snapshot_links
($commit);
4502 if (defined $snapshot_links) {
4503 print " | " . $snapshot_links;
4508 if (defined $extra) {
4510 "<td colspan=\"4\">$extra</td>\n" .
4516 sub git_history_body
{
4517 # Warning: assumes constant type (blob or tree) during history
4518 my ($commitlist, $from, $to, $refs, $extra,
4519 $file_name, $file_hash, $ftype) = @_;
4521 $from = 0 unless defined $from;
4522 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4524 print "<table class=\"history\">\n";
4526 for (my $i = $from; $i <= $to; $i++) {
4527 my %co = %{$commitlist->[$i]};
4531 my $commit = $co{'id'};
4533 my $ref = format_ref_marker
($refs, $commit);
4536 print "<tr class=\"dark\">\n";
4538 print "<tr class=\"light\">\n";
4541 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4542 # shortlog: format_author_html('td', \%co, 10)
4543 format_author_html
('td', \
%co, 15, 3) . "<td>";
4544 # originally git_history used chop_str($co{'title'}, 50)
4545 print format_subject_html
($co{'title'}, $co{'title_short'},
4546 href
(action
=>"commit", hash
=>$commit), $ref);
4548 "<td class=\"link\">" .
4549 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4550 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4552 if ($ftype eq 'blob') {
4553 my $blob_current = $file_hash;
4554 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4555 if (defined $blob_current && defined $blob_parent &&
4556 $blob_current ne $blob_parent) {
4558 $cgi->a({-href
=> href
(action
=>"blobdiff",
4559 hash
=>$blob_current, hash_parent
=>$blob_parent,
4560 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4561 file_name
=>$file_name)},
4568 if (defined $extra) {
4570 "<td colspan=\"4\">$extra</td>\n" .
4577 # uses global variable $project
4578 my ($taglist, $from, $to, $extra) = @_;
4579 $from = 0 unless defined $from;
4580 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4582 print "<table class=\"tags\">\n";
4584 for (my $i = $from; $i <= $to; $i++) {
4585 my $entry = $taglist->[$i];
4587 my $comment = $tag{'subject'};
4589 if (defined $comment) {
4590 $comment_short = chop_str
($comment, 30, 5);
4593 print "<tr class=\"dark\">\n";
4595 print "<tr class=\"light\">\n";
4598 if (defined $tag{'age'}) {
4599 print "<td><i>$tag{'age'}</i></td>\n";
4601 print "<td></td>\n";
4604 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4605 -class => "list name"}, esc_html
($tag{'name'})) .
4608 if (defined $comment) {
4609 print format_subject_html
($comment, $comment_short,
4610 href
(action
=>"tag", hash
=>$tag{'id'}));
4613 "<td class=\"selflink\">";
4614 if ($tag{'type'} eq "tag") {
4615 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4620 "<td class=\"link\">" . " | " .
4621 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4622 if ($tag{'reftype'} eq "commit") {
4623 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4624 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4625 } elsif ($tag{'reftype'} eq "blob") {
4626 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4631 if (defined $extra) {
4633 "<td colspan=\"5\">$extra</td>\n" .
4639 sub git_heads_body
{
4640 # uses global variable $project
4641 my ($headlist, $head, $from, $to, $extra) = @_;
4642 $from = 0 unless defined $from;
4643 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4645 print "<table class=\"heads\">\n";
4647 for (my $i = $from; $i <= $to; $i++) {
4648 my $entry = $headlist->[$i];
4650 my $curr = $ref{'id'} eq $head;
4652 print "<tr class=\"dark\">\n";
4654 print "<tr class=\"light\">\n";
4657 print "<td><i>$ref{'age'}</i></td>\n" .
4658 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4659 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4660 -class => "list name"},esc_html
($ref{'name'})) .
4662 "<td class=\"link\">" .
4663 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4664 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4665 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4669 if (defined $extra) {
4671 "<td colspan=\"3\">$extra</td>\n" .
4677 sub git_search_grep_body
{
4678 my ($commitlist, $from, $to, $extra) = @_;
4679 $from = 0 unless defined $from;
4680 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4682 print "<table class=\"commit_search\">\n";
4684 for (my $i = $from; $i <= $to; $i++) {
4685 my %co = %{$commitlist->[$i]};
4689 my $commit = $co{'id'};
4691 print "<tr class=\"dark\">\n";
4693 print "<tr class=\"light\">\n";
4696 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4697 format_author_html
('td', \
%co, 15, 5) .
4699 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4700 -class => "list subject"},
4701 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4702 my $comment = $co{'comment'};
4703 foreach my $line (@
$comment) {
4704 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4705 my ($lead, $match, $trail) = ($1, $2, $3);
4706 $match = chop_str
($match, 70, 5, 'center');
4707 my $contextlen = int((80 - length($match))/2);
4708 $contextlen = 30 if ($contextlen > 30);
4709 $lead = chop_str
($lead, $contextlen, 10, 'left');
4710 $trail = chop_str
($trail, $contextlen, 10, 'right');
4712 $lead = esc_html
($lead);
4713 $match = esc_html
($match);
4714 $trail = esc_html
($trail);
4716 print "$lead<span class=\"match\">$match</span>$trail<br />";
4720 "<td class=\"link\">" .
4721 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4723 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4725 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4729 if (defined $extra) {
4731 "<td colspan=\"3\">$extra</td>\n" .
4737 ## ======================================================================
4738 ## ======================================================================
4741 sub git_project_list
{
4742 my $order = $input_params{'order'};
4743 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4744 die_error
(400, "Unknown order parameter");
4747 my @list = git_get_projects_list
();
4749 die_error
(404, "No projects found");
4753 if (-f
$home_text) {
4754 print "<div class=\"index_include\">\n";
4755 insert_file
($home_text);
4758 print $cgi->startform(-method
=> "get") .
4759 "<p class=\"projsearch\">Search:\n" .
4760 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4762 $cgi->end_form() . "\n";
4763 git_project_list_body
(\
@list, $order);
4768 my $order = $input_params{'order'};
4769 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4770 die_error
(400, "Unknown order parameter");
4773 my @list = git_get_projects_list
($project);
4775 die_error
(404, "No forks found");
4779 git_print_page_nav
('','');
4780 git_print_header_div
('summary', "$project forks");
4781 git_project_list_body
(\
@list, $order);
4785 sub git_project_index
{
4786 my @projects = git_get_projects_list
($project);
4789 -type
=> 'text/plain',
4790 -charset
=> 'utf-8',
4791 -content_disposition
=> 'inline; filename="index.aux"');
4793 foreach my $pr (@projects) {
4794 if (!exists $pr->{'owner'}) {
4795 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4798 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4799 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4800 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4801 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4805 print "$path $owner\n";
4810 my $descr = git_get_project_description
($project) || "none";
4811 my %co = parse_commit
("HEAD");
4812 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4813 my $head = $co{'id'};
4815 my $owner = git_get_project_owner
($project);
4817 my $refs = git_get_references
();
4818 # These get_*_list functions return one more to allow us to see if
4819 # there are more ...
4820 my @taglist = git_get_tags_list
(16);
4821 my @headlist = git_get_heads_list
(16);
4823 my $check_forks = gitweb_check_feature
('forks');
4826 @forklist = git_get_projects_list
($project);
4830 git_print_page_nav
('summary','', $head);
4832 print "<div class=\"title\"> </div>\n";
4833 print "<table class=\"projects_list\">\n" .
4834 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4835 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4836 if (defined $cd{'rfc2822'}) {
4837 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4840 # use per project git URL list in $projectroot/$project/cloneurl
4841 # or make project git URL from git base URL and project name
4842 my $url_tag = "URL";
4843 my @url_list = git_get_project_url_list
($project);
4844 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4845 foreach my $git_url (@url_list) {
4846 next unless $git_url;
4847 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4852 my $show_ctags = gitweb_check_feature
('ctags');
4854 my $ctags = git_get_project_ctags
($project);
4855 my $cloud = git_populate_project_tagcloud
($ctags);
4856 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4857 print "</td>\n<td>" unless %$ctags;
4858 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4859 print "</td>\n<td>" if %$ctags;
4860 print git_show_project_tagcloud
($cloud, 48);
4866 # If XSS prevention is on, we don't include README.html.
4867 # TODO: Allow a readme in some safe format.
4868 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4869 print "<div class=\"title\">readme</div>\n" .
4870 "<div class=\"readme\">\n";
4871 insert_file
("$projectroot/$project/README.html");
4872 print "\n</div>\n"; # class="readme"
4875 # we need to request one more than 16 (0..15) to check if
4877 my @commitlist = $head ? parse_commits
($head, 17) : ();
4879 git_print_header_div
('shortlog');
4880 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4881 $#commitlist <= 15 ?
undef :
4882 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4886 git_print_header_div
('tags');
4887 git_tags_body
(\
@taglist, 0, 15,
4888 $#taglist <= 15 ?
undef :
4889 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4893 git_print_header_div
('heads');
4894 git_heads_body
(\
@headlist, $head, 0, 15,
4895 $#headlist <= 15 ?
undef :
4896 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4900 git_print_header_div
('forks');
4901 git_project_list_body
(\
@forklist, 'age', 0, 15,
4902 $#forklist <= 15 ?
undef :
4903 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4911 my $head = git_get_head_hash
($project);
4913 git_print_page_nav
('','', $head,undef,$head);
4914 my %tag = parse_tag
($hash);
4917 die_error
(404, "Unknown tag object");
4920 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4921 print "<div class=\"title_text\">\n" .
4922 "<table class=\"object_header\">\n" .
4924 "<td>object</td>\n" .
4925 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4926 $tag{'object'}) . "</td>\n" .
4927 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4928 $tag{'type'}) . "</td>\n" .
4930 if (defined($tag{'author'})) {
4931 git_print_authorship_rows
(\
%tag, 'author');
4933 print "</table>\n\n" .
4935 print "<div class=\"page_body\">";
4936 my $comment = $tag{'comment'};
4937 foreach my $line (@
$comment) {
4939 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4945 sub git_blame_common
{
4946 my $format = shift || 'porcelain';
4947 if ($format eq 'porcelain' && $cgi->param('js')) {
4948 $format = 'incremental';
4949 $action = 'blame_incremental'; # for page title etc
4953 gitweb_check_feature
('blame')
4954 or die_error
(403, "Blame view not allowed");
4957 die_error
(400, "No file name given") unless $file_name;
4958 $hash_base ||= git_get_head_hash
($project);
4959 die_error
(404, "Couldn't find base commit") unless $hash_base;
4960 my %co = parse_commit
($hash_base)
4961 or die_error
(404, "Commit not found");
4963 if (!defined $hash) {
4964 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4965 or die_error
(404, "Error looking up file");
4967 $ftype = git_get_type
($hash);
4968 if ($ftype !~ "blob") {
4969 die_error
(400, "Object is not a blob");
4974 if ($format eq 'incremental') {
4975 # get file contents (as base)
4976 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
4977 or die_error
(500, "Open git-cat-file failed");
4978 } elsif ($format eq 'data') {
4979 # run git-blame --incremental
4980 open $fd, "-|", git_cmd
(), "blame", "--incremental",
4981 $hash_base, "--", $file_name
4982 or die_error
(500, "Open git-blame --incremental failed");
4984 # run git-blame --porcelain
4985 open $fd, "-|", git_cmd
(), "blame", '-p',
4986 $hash_base, '--', $file_name
4987 or die_error
(500, "Open git-blame --porcelain failed");
4990 # incremental blame data returns early
4991 if ($format eq 'data') {
4993 -type
=>"text/plain", -charset
=> "utf-8",
4994 -status
=> "200 OK");
4995 local $| = 1; # output autoflush
4998 or print "ERROR $!\n";
5001 if (defined $t0 && gitweb_check_feature
('timed')) {
5003 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
5004 ' '.$number_of_git_cmds;
5014 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5017 if ($format eq 'incremental') {
5019 $cgi->a({-href
=> href
(action
=>"blame", javascript
=>0, -replay
=>1)},
5020 "blame") . " (non-incremental)";
5023 $cgi->a({-href
=> href
(action
=>"blame_incremental", -replay
=>1)},
5024 "blame") . " (incremental)";
5028 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5031 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5033 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5034 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5035 git_print_page_path
($file_name, $ftype, $hash_base);
5038 if ($format eq 'incremental') {
5039 print "<noscript>\n<div class=\"error\"><center><b>\n".
5040 "This page requires JavaScript to run.\n Use ".
5041 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5044 "</b></center></div>\n</noscript>\n";
5046 print qq!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5049 print qq!<div
class="page_body">\n!;
5050 print qq!<div id
="progress_info">... / ...</div
>\n!
5051 if ($format eq 'incremental');
5052 print qq!<table id
="blame_table" class="blame" width
="100%">\n!.
5053 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5055 qq!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5059 my @rev_color = qw(light dark);
5060 my $num_colors = scalar(@rev_color);
5061 my $current_color = 0;
5063 if ($format eq 'incremental') {
5064 my $color_class = $rev_color[$current_color];
5069 while (my $line = <$fd>) {
5073 print qq!<tr id
="l$linenr" class="$color_class">!.
5074 qq!<td
class="sha1"><a href
=""> </a></td
>!.
5075 qq!<td
class="linenr">!.
5076 qq!<a
class="linenr" href
="">$linenr</a></td
>!;
5077 print qq!<td
class="pre">! . esc_html
($line) . "</td>\n";
5081 } else { # porcelain, i.e. ordinary blame
5082 my %metainfo = (); # saves information about commits
5086 while (my $line = <$fd>) {
5088 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5089 # no <lines in group> for subsequent lines in group of lines
5090 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5091 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5092 if (!exists $metainfo{$full_rev}) {
5093 $metainfo{$full_rev} = { 'nprevious' => 0 };
5095 my $meta = $metainfo{$full_rev};
5097 while ($data = <$fd>) {
5099 last if ($data =~ s/^\t//); # contents of line
5100 if ($data =~ /^(\S+)(?: (.*))?$/) {
5101 $meta->{$1} = $2 unless exists $meta->{$1};
5103 if ($data =~ /^previous /) {
5104 $meta->{'nprevious'}++;
5107 my $short_rev = substr($full_rev, 0, 8);
5108 my $author = $meta->{'author'};
5110 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5111 my $date = $date{'iso-tz'};
5113 $current_color = ($current_color + 1) % $num_colors;
5115 my $tr_class = $rev_color[$current_color];
5116 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5117 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5118 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5119 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5121 print "<td class=\"sha1\"";
5122 print " title=\"". esc_html
($author) . ", $date\"";
5123 print " rowspan=\"$group_size\"" if ($group_size > 1);
5125 print $cgi->a({-href
=> href
(action
=>"commit",
5127 file_name
=>$file_name)},
5128 esc_html
($short_rev));
5129 if ($group_size >= 2) {
5130 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5131 if (@author_initials) {
5133 esc_html
(join('', @author_initials));
5139 # 'previous' <sha1 of parent commit> <filename at commit>
5140 if (exists $meta->{'previous'} &&
5141 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5142 $meta->{'parent'} = $1;
5143 $meta->{'file_parent'} = unquote
($2);
5146 exists($meta->{'parent'}) ?
5147 $meta->{'parent'} : $full_rev;
5148 my $linenr_filename =
5149 exists($meta->{'file_parent'}) ?
5150 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5151 my $blamed = href
(action
=> 'blame',
5152 file_name
=> $linenr_filename,
5153 hash_base
=> $linenr_commit);
5154 print "<td class=\"linenr\">";
5155 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5156 -class => "linenr" },
5159 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5167 "</table>\n"; # class="blame"
5168 print "</div>\n"; # class="blame_body"
5170 or print "Reading blob failed\n";
5179 sub git_blame_incremental
{
5180 git_blame_common
('incremental');
5183 sub git_blame_data
{
5184 git_blame_common
('data');
5188 my $head = git_get_head_hash
($project);
5190 git_print_page_nav
('','', $head,undef,$head);
5191 git_print_header_div
('summary', $project);
5193 my @tagslist = git_get_tags_list
();
5195 git_tags_body
(\
@tagslist);
5201 my $head = git_get_head_hash
($project);
5203 git_print_page_nav
('','', $head,undef,$head);
5204 git_print_header_div
('summary', $project);
5206 my @headslist = git_get_heads_list
();
5208 git_heads_body
(\
@headslist, $head);
5213 sub git_blob_plain
{
5217 if (!defined $hash) {
5218 if (defined $file_name) {
5219 my $base = $hash_base || git_get_head_hash
($project);
5220 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5221 or die_error
(404, "Cannot find file");
5223 die_error
(400, "No file name defined");
5225 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5226 # blobs defined by non-textual hash id's can be cached
5230 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5231 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5233 # content-type (can include charset)
5234 $type = blob_contenttype
($fd, $file_name, $type);
5236 # "save as" filename, even when no $file_name is given
5237 my $save_as = "$hash";
5238 if (defined $file_name) {
5239 $save_as = $file_name;
5240 } elsif ($type =~ m/^text\//) {
5244 # With XSS prevention on, blobs of all types except a few known safe
5245 # ones are served with "Content-Disposition: attachment" to make sure
5246 # they don't run in our security domain. For certain image types,
5247 # blob view writes an <img> tag referring to blob_plain view, and we
5248 # want to be sure not to break that by serving the image as an
5249 # attachment (though Firefox 3 doesn't seem to care).
5250 my $sandbox = $prevent_xss &&
5251 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5255 -expires
=> $expires,
5256 -content_disposition
=>
5257 ($sandbox ?
'attachment' : 'inline')
5258 . '; filename="' . $save_as . '"');
5260 binmode STDOUT
, ':raw';
5262 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5269 if (!defined $hash) {
5270 if (defined $file_name) {
5271 my $base = $hash_base || git_get_head_hash
($project);
5272 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5273 or die_error
(404, "Cannot find file");
5275 die_error
(400, "No file name defined");
5277 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5278 # blobs defined by non-textual hash id's can be cached
5282 my $have_blame = gitweb_check_feature
('blame');
5283 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5284 or die_error
(500, "Couldn't cat $file_name, $hash");
5285 my $mimetype = blob_mimetype
($fd, $file_name);
5286 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5288 return git_blob_plain
($mimetype);
5290 # we can have blame only for text/* mimetype
5291 $have_blame &&= ($mimetype =~ m!^text/!);
5293 git_header_html
(undef, $expires);
5294 my $formats_nav = '';
5295 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5296 if (defined $file_name) {
5299 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5304 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5307 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5310 $cgi->a({-href
=> href
(action
=>"blob",
5311 hash_base
=>"HEAD", file_name
=>$file_name)},
5315 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5318 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5319 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5321 print "<div class=\"page_nav\">\n" .
5322 "<br/><br/></div>\n" .
5323 "<div class=\"title\">".esc_html
($hash)."</div>\n";
5325 git_print_page_path
($file_name, "blob", $hash_base);
5326 print "<div class=\"page_body\">\n";
5327 if ($mimetype =~ m!^image/!) {
5328 print qq!<img type
="!.esc_attr($mimetype).qq!"!;
5330 print qq! alt
="!.esc_attr($file_name).qq!" title
="!.esc_attr($file_name).qq!"!;
5333 href(action=>"blob_plain
", hash=>$hash,
5334 hash_base=>$hash_base, file_name=>$file_name) .
5338 while (my $line = <$fd>) {
5341 $line = untabify
($line);
5342 printf "<div class=\"pre\"><a id=\"l%i\" href=\""
5343 . esc_attr
(href
(-replay
=> 1))
5344 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5345 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5349 or print "Reading blob failed.\n";
5355 if (!defined $hash_base) {
5356 $hash_base = "HEAD";
5358 if (!defined $hash) {
5359 if (defined $file_name) {
5360 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5365 die_error
(404, "No such tree") unless defined($hash);
5367 my $show_sizes = gitweb_check_feature
('show-sizes');
5368 my $have_blame = gitweb_check_feature
('blame');
5373 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5374 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5375 or die_error
(500, "Open git-ls-tree failed");
5376 @entries = map { chomp; $_ } <$fd>;
5378 or die_error
(404, "Reading tree failed");
5381 my $refs = git_get_references
();
5382 my $ref = format_ref_marker
($refs, $hash_base);
5385 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5387 if (defined $file_name) {
5389 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5391 $cgi->a({-href
=> href
(action
=>"tree",
5392 hash_base
=>"HEAD", file_name
=>$file_name)},
5395 my $snapshot_links = format_snapshot_links
($hash);
5396 if (defined $snapshot_links) {
5397 # FIXME: Should be available when we have no hash base as well.
5398 push @views_nav, $snapshot_links;
5400 git_print_page_nav
('tree','', $hash_base, undef, undef,
5401 join(' | ', @views_nav));
5402 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5405 print "<div class=\"page_nav\">\n";
5406 print "<br/><br/></div>\n";
5407 print "<div class=\"title\">".esc_html
($hash)."</div>\n";
5409 if (defined $file_name) {
5410 $basedir = $file_name;
5411 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5414 git_print_page_path
($file_name, 'tree', $hash_base);
5416 print "<div class=\"page_body\">\n";
5417 print "<table class=\"tree\">\n";
5419 # '..' (top directory) link if possible
5420 if (defined $hash_base &&
5421 defined $file_name && $file_name =~ m![^/]+$!) {
5423 print "<tr class=\"dark\">\n";
5425 print "<tr class=\"light\">\n";
5429 my $up = $file_name;
5430 $up =~ s!/?[^/]+$!!;
5431 undef $up unless $up;
5432 # based on git_print_tree_entry
5433 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5434 print '<td class="size"> </td>'."\n" if $show_sizes;
5435 print '<td class="list">';
5436 print $cgi->a({-href
=> href
(action
=>"tree",
5437 hash_base
=>$hash_base,
5441 print "<td class=\"link\"></td>\n";
5445 foreach my $line (@entries) {
5446 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5449 print "<tr class=\"dark\">\n";
5451 print "<tr class=\"light\">\n";
5455 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5459 print "</table>\n" .
5465 my ($project, $hash) = @_;
5467 # path/to/project.git -> project
5468 # path/to/project/.git -> project
5469 my $name = to_utf8
($project);
5470 $name =~ s
,([^/])/*\
.git
$,$1,;
5471 $name = basename
($name);
5473 $name =~ s/[[:cntrl:]]/?/g;
5476 if ($hash =~ /^[0-9a-fA-F]+$/) {
5477 # shorten SHA-1 hash
5478 my $full_hash = git_get_full_hash
($project, $hash);
5479 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5480 $ver = git_get_short_hash
($project, $hash);
5482 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5483 # tags don't need shortened SHA-1 hash
5486 # branches and other need shortened SHA-1 hash
5487 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5490 $ver .= '-' . git_get_short_hash
($project, $hash);
5492 # in case of hierarchical branch names
5495 # name = project-version_string
5496 $name = "$name-$ver";
5498 return wantarray ?
($name, $name) : $name;
5502 my $format = $input_params{'snapshot_format'};
5503 if (!@snapshot_fmts) {
5504 die_error
(403, "Snapshots not allowed");
5506 # default to first supported snapshot format
5507 $format ||= $snapshot_fmts[0];
5508 if ($format !~ m/^[a-z0-9]+$/) {
5509 die_error
(400, "Invalid snapshot format parameter");
5510 } elsif (!exists($known_snapshot_formats{$format})) {
5511 die_error
(400, "Unknown snapshot format");
5512 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5513 die_error
(403, "Snapshot format not allowed");
5514 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5515 die_error
(403, "Unsupported snapshot format");
5518 my $type = git_get_type
("$hash^{}");
5520 die_error
(404, 'Object does not exist');
5521 } elsif ($type eq 'blob') {
5522 die_error
(400, 'Object is not a tree-ish');
5525 my ($name, $prefix) = snapshot_name
($project, $hash);
5526 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5527 my $cmd = quote_command
(
5528 git_cmd
(), 'archive',
5529 "--format=$known_snapshot_formats{$format}{'format'}",
5530 "--prefix=$prefix/", $hash);
5531 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5532 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5535 $filename =~ s/(["\\])/\\$1/g;
5537 -type
=> $known_snapshot_formats{$format}{'type'},
5538 -content_disposition
=> 'inline; filename="' . $filename . '"',
5539 -status
=> '200 OK');
5541 open my $fd, "-|", $cmd
5542 or die_error
(500, "Execute git-archive failed");
5543 binmode STDOUT
, ':raw';
5545 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5549 sub git_log_generic
{
5550 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5552 my $head = git_get_head_hash
($project);
5553 if (!defined $base) {
5556 if (!defined $page) {
5559 my $refs = git_get_references
();
5561 my $commit_hash = $base;
5562 if (defined $parent) {
5563 $commit_hash = "$parent..$base";
5566 parse_commits
($commit_hash, 101, (100 * $page),
5567 defined $file_name ?
($file_name, "--full-history") : ());
5570 if (!defined $file_hash && defined $file_name) {
5571 # some commits could have deleted file in question,
5572 # and not have it in tree, but one of them has to have it
5573 for (my $i = 0; $i < @commitlist; $i++) {
5574 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5575 last if defined $file_hash;
5578 if (defined $file_hash) {
5579 $ftype = git_get_type
($file_hash);
5581 if (defined $file_name && !defined $ftype) {
5582 die_error
(500, "Unknown type of object");
5585 if (defined $file_name) {
5586 %co = parse_commit
($base)
5587 or die_error
(404, "Unknown commit object");
5591 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5593 if ($#commitlist >= 100) {
5595 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5596 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5598 my $patch_max = gitweb_get_feature
('patches');
5599 if ($patch_max && !defined $file_name) {
5600 if ($patch_max < 0 || @commitlist <= $patch_max) {
5601 $paging_nav .= " ⋅ " .
5602 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5608 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5609 if (defined $file_name) {
5610 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5612 git_print_header_div
('summary', $project)
5614 git_print_page_path
($file_name, $ftype, $hash_base)
5615 if (defined $file_name);
5617 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5618 $file_name, $file_hash, $ftype);
5624 git_log_generic
('log', \
&git_log_body
,
5625 $hash, $hash_parent);
5629 $hash ||= $hash_base || "HEAD";
5630 my %co = parse_commit
($hash)
5631 or die_error
(404, "Unknown commit object");
5633 my $parent = $co{'parent'};
5634 my $parents = $co{'parents'}; # listref
5636 # we need to prepare $formats_nav before any parameter munging
5638 if (!defined $parent) {
5640 $formats_nav .= '(initial)';
5641 } elsif (@
$parents == 1) {
5642 # single parent commit
5645 $cgi->a({-href
=> href
(action
=>"commit",
5647 esc_html
(substr($parent, 0, 7))) .
5654 $cgi->a({-href
=> href
(action
=>"commit",
5656 esc_html
(substr($_, 0, 7)));
5660 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5661 $formats_nav .= " | " .
5662 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5666 if (!defined $parent) {
5670 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5672 (@
$parents <= 1 ?
$parent : '-c'),
5674 or die_error
(500, "Open git-diff-tree failed");
5675 @difftree = map { chomp; $_ } <$fd>;
5676 close $fd or die_error
(404, "Reading git-diff-tree failed");
5678 # non-textual hash id's can be cached
5680 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5683 my $refs = git_get_references
();
5684 my $ref = format_ref_marker
($refs, $co{'id'});
5686 git_header_html
(undef, $expires);
5687 git_print_page_nav
('commit', '',
5688 $hash, $co{'tree'}, $hash,
5691 if (defined $co{'parent'}) {
5692 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5694 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5696 print "<div class=\"title_text\">\n" .
5697 "<table class=\"object_header\">\n";
5698 git_print_authorship_rows
(\
%co);
5699 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5702 "<td class=\"sha1\">" .
5703 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5704 class => "list"}, $co{'tree'}) .
5706 "<td class=\"link\">" .
5707 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5709 my $snapshot_links = format_snapshot_links
($hash);
5710 if (defined $snapshot_links) {
5711 print " | " . $snapshot_links;
5716 foreach my $par (@
$parents) {
5719 "<td class=\"sha1\">" .
5720 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5721 class => "list"}, $par) .
5723 "<td class=\"link\">" .
5724 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5726 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5733 print "<div class=\"page_body\">\n";
5734 git_print_log
($co{'comment'});
5737 git_difftree_body
(\
@difftree, $hash, @
$parents);
5743 # object is defined by:
5744 # - hash or hash_base alone
5745 # - hash_base and file_name
5748 # - hash or hash_base alone
5749 if ($hash || ($hash_base && !defined $file_name)) {
5750 my $object_id = $hash || $hash_base;
5752 open my $fd, "-|", quote_command
(
5753 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5754 or die_error
(404, "Object does not exist");
5758 or die_error
(404, "Object does not exist");
5760 # - hash_base and file_name
5761 } elsif ($hash_base && defined $file_name) {
5762 $file_name =~ s
,/+$,,;
5764 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5765 or die_error
(404, "Base object does not exist");
5767 # here errors should not hapen
5768 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5769 or die_error
(500, "Open git-ls-tree failed");
5773 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5774 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5775 die_error
(404, "File or directory for given base does not exist");
5780 die_error
(400, "Not enough information to find object");
5783 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5784 hash
=>$hash, hash_base
=>$hash_base,
5785 file_name
=>$file_name),
5786 -status
=> '302 Found');
5790 my $format = shift || 'html';
5797 # preparing $fd and %diffinfo for git_patchset_body
5799 if (defined $hash_base && defined $hash_parent_base) {
5800 if (defined $file_name) {
5802 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5803 $hash_parent_base, $hash_base,
5804 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5805 or die_error
(500, "Open git-diff-tree failed");
5806 @difftree = map { chomp; $_ } <$fd>;
5808 or die_error
(404, "Reading git-diff-tree failed");
5810 or die_error
(404, "Blob diff not found");
5812 } elsif (defined $hash &&
5813 $hash =~ /[0-9a-fA-F]{40}/) {
5814 # try to find filename from $hash
5816 # read filtered raw output
5817 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5818 $hash_parent_base, $hash_base, "--"
5819 or die_error
(500, "Open git-diff-tree failed");
5821 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5823 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5824 map { chomp; $_ } <$fd>;
5826 or die_error
(404, "Reading git-diff-tree failed");
5828 or die_error
(404, "Blob diff not found");
5831 die_error
(400, "Missing one of the blob diff parameters");
5834 if (@difftree > 1) {
5835 die_error
(400, "Ambiguous blob diff specification");
5838 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5839 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5840 $file_name ||= $diffinfo{'to_file'};
5842 $hash_parent ||= $diffinfo{'from_id'};
5843 $hash ||= $diffinfo{'to_id'};
5845 # non-textual hash id's can be cached
5846 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5847 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5852 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5853 '-p', ($format eq 'html' ?
"--full-index" : ()),
5854 $hash_parent_base, $hash_base,
5855 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5856 or die_error
(500, "Open git-diff-tree failed");
5859 # old/legacy style URI -- not generated anymore since 1.4.3.
5861 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5865 if ($format eq 'html') {
5867 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5869 git_header_html
(undef, $expires);
5870 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5871 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5872 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5874 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5875 print "<div class=\"title\">".esc_html
("$hash vs $hash_parent")."</div>\n";
5877 if (defined $file_name) {
5878 git_print_page_path
($file_name, "blob", $hash_base);
5880 print "<div class=\"page_path\"></div>\n";
5883 } elsif ($format eq 'plain') {
5885 -type
=> 'text/plain',
5886 -charset
=> 'utf-8',
5887 -expires
=> $expires,
5888 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5890 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5893 die_error
(400, "Unknown blobdiff format");
5897 if ($format eq 'html') {
5898 print "<div class=\"page_body\">\n";
5900 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5903 print "</div>\n"; # class="page_body"
5907 while (my $line = <$fd>) {
5908 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5909 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5913 last if $line =~ m!^\+\+\+!;
5921 sub git_blobdiff_plain
{
5922 git_blobdiff
('plain');
5925 sub git_commitdiff
{
5927 my $format = $params{-format
} || 'html';
5929 my ($patch_max) = gitweb_get_feature
('patches');
5930 if ($format eq 'patch') {
5931 die_error
(403, "Patch view not allowed") unless $patch_max;
5934 $hash ||= $hash_base || "HEAD";
5935 my %co = parse_commit
($hash)
5936 or die_error
(404, "Unknown commit object");
5938 # choose format for commitdiff for merge
5939 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5940 $hash_parent = '--cc';
5942 # we need to prepare $formats_nav before almost any parameter munging
5944 if ($format eq 'html') {
5946 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5948 if ($patch_max && @
{$co{'parents'}} <= 1) {
5949 $formats_nav .= " | " .
5950 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5954 if (defined $hash_parent &&
5955 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5956 # commitdiff with two commits given
5957 my $hash_parent_short = $hash_parent;
5958 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5959 $hash_parent_short = substr($hash_parent, 0, 7);
5963 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5964 if ($co{'parents'}[$i] eq $hash_parent) {
5965 $formats_nav .= ' parent ' . ($i+1);
5969 $formats_nav .= ': ' .
5970 $cgi->a({-href
=> href
(action
=>"commitdiff",
5971 hash
=>$hash_parent)},
5972 esc_html
($hash_parent_short)) .
5974 } elsif (!$co{'parent'}) {
5976 $formats_nav .= ' (initial)';
5977 } elsif (scalar @
{$co{'parents'}} == 1) {
5978 # single parent commit
5981 $cgi->a({-href
=> href
(action
=>"commitdiff",
5982 hash
=>$co{'parent'})},
5983 esc_html
(substr($co{'parent'}, 0, 7))) .
5987 if ($hash_parent eq '--cc') {
5988 $formats_nav .= ' | ' .
5989 $cgi->a({-href
=> href
(action
=>"commitdiff",
5990 hash
=>$hash, hash_parent
=>'-c')},
5992 } else { # $hash_parent eq '-c'
5993 $formats_nav .= ' | ' .
5994 $cgi->a({-href
=> href
(action
=>"commitdiff",
5995 hash
=>$hash, hash_parent
=>'--cc')},
6001 $cgi->a({-href
=> href
(action
=>"commitdiff",
6003 esc_html
(substr($_, 0, 7)));
6004 } @
{$co{'parents'}} ) .
6009 my $hash_parent_param = $hash_parent;
6010 if (!defined $hash_parent_param) {
6011 # --cc for multiple parents, --root for parentless
6012 $hash_parent_param =
6013 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
6019 if ($format eq 'html') {
6020 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6021 "--no-commit-id", "--patch-with-raw", "--full-index",
6022 $hash_parent_param, $hash, "--"
6023 or die_error
(500, "Open git-diff-tree failed");
6025 while (my $line = <$fd>) {
6027 # empty line ends raw part of diff-tree output
6029 push @difftree, scalar parse_difftree_raw_line
($line);
6032 } elsif ($format eq 'plain') {
6033 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6034 '-p', $hash_parent_param, $hash, "--"
6035 or die_error
(500, "Open git-diff-tree failed");
6036 } elsif ($format eq 'patch') {
6037 # For commit ranges, we limit the output to the number of
6038 # patches specified in the 'patches' feature.
6039 # For single commits, we limit the output to a single patch,
6040 # diverging from the git-format-patch default.
6041 my @commit_spec = ();
6043 if ($patch_max > 0) {
6044 push @commit_spec, "-$patch_max";
6046 push @commit_spec, '-n', "$hash_parent..$hash";
6048 if ($params{-single
}) {
6049 push @commit_spec, '-1';
6051 if ($patch_max > 0) {
6052 push @commit_spec, "-$patch_max";
6054 push @commit_spec, "-n";
6056 push @commit_spec, '--root', $hash;
6058 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6059 '--stdout', @commit_spec
6060 or die_error
(500, "Open git-format-patch failed");
6062 die_error
(400, "Unknown commitdiff format");
6065 # non-textual hash id's can be cached
6067 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6071 # write commit message
6072 if ($format eq 'html') {
6073 my $refs = git_get_references
();
6074 my $ref = format_ref_marker
($refs, $co{'id'});
6076 git_header_html
(undef, $expires);
6077 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6078 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6079 print "<div class=\"title_text\">\n" .
6080 "<table class=\"object_header\">\n";
6081 git_print_authorship_rows
(\
%co);
6084 print "<div class=\"page_body\">\n";
6085 if (@
{$co{'comment'}} > 1) {
6086 print "<div class=\"log\">\n";
6087 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6088 print "</div>\n"; # class="log"
6091 } elsif ($format eq 'plain') {
6092 my $refs = git_get_references
("tags");
6093 my $tagname = git_get_rev_name_tags
($hash);
6094 my $filename = basename
($project) . "-$hash.patch";
6097 -type
=> 'text/plain',
6098 -charset
=> 'utf-8',
6099 -expires
=> $expires,
6100 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6101 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6102 print "From: " . to_utf8
($co{'author'}) . "\n";
6103 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6104 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6106 print "X-Git-Tag: $tagname\n" if $tagname;
6107 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6109 foreach my $line (@
{$co{'comment'}}) {
6110 print to_utf8
($line) . "\n";
6113 } elsif ($format eq 'patch') {
6114 my $filename = basename
($project) . "-$hash.patch";
6117 -type
=> 'text/plain',
6118 -charset
=> 'utf-8',
6119 -expires
=> $expires,
6120 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6124 if ($format eq 'html') {
6125 my $use_parents = !defined $hash_parent ||
6126 $hash_parent eq '-c' || $hash_parent eq '--cc';
6127 git_difftree_body
(\
@difftree, $hash,
6128 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6131 git_patchset_body
($fd, \
@difftree, $hash,
6132 $use_parents ? @
{$co{'parents'}} : $hash_parent);
6134 print "</div>\n"; # class="page_body"
6137 } elsif ($format eq 'plain') {
6141 or print "Reading git-diff-tree failed\n";
6142 } elsif ($format eq 'patch') {
6146 or print "Reading git-format-patch failed\n";
6150 sub git_commitdiff_plain
{
6151 git_commitdiff
(-format
=> 'plain');
6154 # format-patch-style patches
6156 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6160 git_commitdiff
(-format
=> 'patch');
6164 git_log_generic
('history', \
&git_history_body
,
6165 $hash_base, $hash_parent_base,
6170 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6171 if (!defined $searchtext) {
6172 die_error
(400, "Text field is empty");
6174 if (!defined $hash) {
6175 $hash = git_get_head_hash
($project);
6177 my %co = parse_commit
($hash);
6179 die_error
(404, "Unknown commit object");
6181 if (!defined $page) {
6185 $searchtype ||= 'commit';
6186 if ($searchtype eq 'pickaxe') {
6187 # pickaxe may take all resources of your box and run for several minutes
6188 # with every query - so decide by yourself how public you make this feature
6189 gitweb_check_feature
('pickaxe')
6190 or die_error
(403, "Pickaxe is disabled");
6192 if ($searchtype eq 'grep') {
6193 gitweb_check_feature
('grep')
6194 or die_error
(403, "Grep is disabled");
6199 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6201 if ($searchtype eq 'commit') {
6202 $greptype = "--grep=";
6203 } elsif ($searchtype eq 'author') {
6204 $greptype = "--author=";
6205 } elsif ($searchtype eq 'committer') {
6206 $greptype = "--committer=";
6208 $greptype .= $searchtext;
6209 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6210 $greptype, '--regexp-ignore-case',
6211 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
6213 my $paging_nav = '';
6216 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6217 searchtext
=>$searchtext,
6218 searchtype
=>$searchtype)},
6220 $paging_nav .= " ⋅ " .
6221 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6222 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6224 $paging_nav .= "first";
6225 $paging_nav .= " ⋅ prev";
6228 if ($#commitlist >= 100) {
6230 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6231 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6232 $paging_nav .= " ⋅ $next_link";
6234 $paging_nav .= " ⋅ next";
6237 if ($#commitlist >= 100) {
6240 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6241 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6242 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6245 if ($searchtype eq 'pickaxe') {
6246 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6247 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6249 print "<table class=\"pickaxe search\">\n";
6252 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6253 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6254 ($search_use_regexp ?
'--pickaxe-regex' : ());
6257 while (my $line = <$fd>) {
6261 my %set = parse_difftree_raw_line
($line);
6262 if (defined $set{'commit'}) {
6263 # finish previous commit
6266 "<td class=\"link\">" .
6267 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6269 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6275 print "<tr class=\"dark\">\n";
6277 print "<tr class=\"light\">\n";
6280 %co = parse_commit
($set{'commit'});
6281 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6282 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6283 "<td><i>$author</i></td>\n" .
6285 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6286 -class => "list subject"},
6287 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6288 } elsif (defined $set{'to_id'}) {
6289 next if ($set{'to_id'} =~ m/^0{40}$/);
6291 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6292 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6294 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6300 # finish last commit (warning: repetition!)
6303 "<td class=\"link\">" .
6304 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6306 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6314 if ($searchtype eq 'grep') {
6315 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6316 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6318 print "<table class=\"grep_search\">\n";
6322 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6323 $search_use_regexp ?
('-E', '-i') : '-F',
6324 $searchtext, $co{'tree'};
6326 while (my $line = <$fd>) {
6328 my ($file, $lno, $ltext, $binary);
6329 last if ($matches++ > 1000);
6330 if ($line =~ /^Binary file (.+) matches$/) {
6334 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6336 if ($file ne $lastfile) {
6337 $lastfile and print "</td></tr>\n";
6339 print "<tr class=\"dark\">\n";
6341 print "<tr class=\"light\">\n";
6343 print "<td class=\"list\">".
6344 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6345 file_name
=>"$file"),
6346 -class => "list"}, esc_path
($file));
6347 print "</td><td>\n";
6351 print "<div class=\"binary\">Binary file</div>\n";
6353 $ltext = untabify
($ltext);
6354 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6355 $ltext = esc_html
($1, -nbsp
=>1);
6356 $ltext .= '<span class="match">';
6357 $ltext .= esc_html
($2, -nbsp
=>1);
6358 $ltext .= '</span>';
6359 $ltext .= esc_html
($3, -nbsp
=>1);
6361 $ltext = esc_html
($ltext, -nbsp
=>1);
6363 print "<div class=\"pre\">" .
6364 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6365 file_name
=>"$file").'#l'.$lno,
6366 -class => "linenr"}, sprintf('%4i', $lno))
6367 . ' ' . $ltext . "</div>\n";
6371 print "</td></tr>\n";
6372 if ($matches > 1000) {
6373 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6376 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6385 sub git_search_help
{
6387 git_print_page_nav
('','', $hash,$hash,$hash);
6389 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6390 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6391 the pattern entered is recognized as the POSIX extended
6392 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6395 <dt><b>commit</b></dt>
6396 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6398 my $have_grep = gitweb_check_feature
('grep');
6401 <dt><b>grep</b></dt>
6402 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6403 a different one) are searched for the given pattern. On large trees, this search can take
6404 a while and put some strain on the server, so please use it with some consideration. Note that
6405 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6406 case-sensitive.</dd>
6410 <dt><b>author</b></dt>
6411 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6412 <dt><b>committer</b></dt>
6413 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6415 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6416 if ($have_pickaxe) {
6418 <dt><b>pickaxe</b></dt>
6419 <dd>All commits that caused the string to appear or disappear from any file (changes that
6420 added, removed or "modified" the string) will be listed. This search can take a while and
6421 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6422 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6430 git_log_generic
('shortlog', \
&git_shortlog_body
,
6431 $hash, $hash_parent);
6434 ## ......................................................................
6435 ## feeds (RSS, Atom; OPML)
6438 my $format = shift || 'atom';
6439 my $have_blame = gitweb_check_feature
('blame');
6441 # Atom: http://www.atomenabled.org/developers/syndication/
6442 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6443 if ($format ne 'rss' && $format ne 'atom') {
6444 die_error
(400, "Unknown web feed format");
6447 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6448 my $head = $hash || 'HEAD';
6449 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6453 my $content_type = "application/$format+xml";
6454 if (defined $cgi->http('HTTP_ACCEPT') &&
6455 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6456 # browser (feed reader) prefers text/xml
6457 $content_type = 'text/xml';
6459 if (defined($commitlist[0])) {
6460 %latest_commit = %{$commitlist[0]};
6461 my $latest_epoch = $latest_commit{'committer_epoch'};
6462 %latest_date = parse_date
($latest_epoch);
6463 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6464 if (defined $if_modified) {
6466 if (eval { require HTTP
::Date
; 1; }) {
6467 $since = HTTP
::Date
::str2time
($if_modified);
6468 } elsif (eval { require Time
::ParseDate
; 1; }) {
6469 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6471 if (defined $since && $latest_epoch <= $since) {
6473 -type
=> $content_type,
6474 -charset
=> 'utf-8',
6475 -last_modified
=> $latest_date{'rfc2822'},
6476 -status
=> '304 Not Modified');
6481 -type
=> $content_type,
6482 -charset
=> 'utf-8',
6483 -last_modified
=> $latest_date{'rfc2822'});
6486 -type
=> $content_type,
6487 -charset
=> 'utf-8');
6490 # Optimization: skip generating the body if client asks only
6491 # for Last-Modified date.
6492 return if ($cgi->request_method() eq 'HEAD');
6495 my $title = "$site_name - $project/$action";
6496 my $feed_type = 'log';
6497 if (defined $hash) {
6498 $title .= " - '$hash'";
6499 $feed_type = 'branch log';
6500 if (defined $file_name) {
6501 $title .= " :: $file_name";
6502 $feed_type = 'history';
6504 } elsif (defined $file_name) {
6505 $title .= " - $file_name";
6506 $feed_type = 'history';
6508 $title .= " $feed_type";
6509 my $descr = git_get_project_description
($project);
6510 if (defined $descr) {
6511 $descr = esc_html
($descr);
6513 $descr = "$project " .
6514 ($format eq 'rss' ?
'RSS' : 'Atom') .
6517 my $owner = git_get_project_owner
($project);
6518 $owner = esc_html
($owner);
6522 if (defined $file_name) {
6523 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6524 } elsif (defined $hash) {
6525 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6527 $alt_url = href
(-full
=>1, action
=>"summary");
6529 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6530 if ($format eq 'rss') {
6532 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6535 print "<title>$title</title>\n" .
6536 "<link>$alt_url</link>\n" .
6537 "<description>$descr</description>\n" .
6538 "<language>en</language>\n" .
6539 # project owner is responsible for 'editorial' content
6540 "<managingEditor>$owner</managingEditor>\n";
6541 if (defined $logo || defined $favicon) {
6542 # prefer the logo to the favicon, since RSS
6543 # doesn't allow both
6544 my $img = esc_url
($logo || $favicon);
6546 "<url>$img</url>\n" .
6547 "<title>$title</title>\n" .
6548 "<link>$alt_url</link>\n" .
6552 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6553 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6555 print "<generator>gitweb v.$version/$git_version</generator>\n";
6556 } elsif ($format eq 'atom') {
6558 <feed xmlns="http://www.w3.org/2005/Atom">
6560 print "<title>$title</title>\n" .
6561 "<subtitle>$descr</subtitle>\n" .
6562 '<link rel="alternate" type="text/html" href="' .
6563 $alt_url . '" />' . "\n" .
6564 '<link rel="self" type="' . $content_type . '" href="' .
6565 $cgi->self_url() . '" />' . "\n" .
6566 "<id>" . href
(-full
=>1) . "</id>\n" .
6567 # use project owner for feed author
6568 "<author><name>$owner</name></author>\n";
6569 if (defined $favicon) {
6570 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6572 if (defined $logo_url) {
6573 # not twice as wide as tall: 72 x 27 pixels
6574 print "<logo>" . esc_url
($logo) . "</logo>\n";
6576 if (! %latest_date) {
6577 # dummy date to keep the feed valid until commits trickle in:
6578 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6580 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6582 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6586 for (my $i = 0; $i <= $#commitlist; $i++) {
6587 my %co = %{$commitlist[$i]};
6588 my $commit = $co{'id'};
6589 # we read 150, we always show 30 and the ones more recent than 48 hours
6590 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6593 my %cd = parse_date
($co{'author_epoch'});
6595 # get list of changed files
6596 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6597 $co{'parent'} || "--root",
6598 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6600 my @difftree = map { chomp; $_ } <$fd>;
6604 # print element (entry, item)
6605 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6606 if ($format eq 'rss') {
6608 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6609 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6610 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6611 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6612 "<link>$co_url</link>\n" .
6613 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6614 "<content:encoded>" .
6616 } elsif ($format eq 'atom') {
6618 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6619 "<updated>$cd{'iso-8601'}</updated>\n" .
6621 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6622 if ($co{'author_email'}) {
6623 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6625 print "</author>\n" .
6626 # use committer for contributor
6628 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6629 if ($co{'committer_email'}) {
6630 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6632 print "</contributor>\n" .
6633 "<published>$cd{'iso-8601'}</published>\n" .
6634 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6635 "<id>$co_url</id>\n" .
6636 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6637 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6639 my $comment = $co{'comment'};
6641 foreach my $line (@
$comment) {
6642 $line = esc_html
($line);
6645 print "</pre><ul>\n";
6646 foreach my $difftree_line (@difftree) {
6647 my %difftree = parse_difftree_raw_line
($difftree_line);
6648 next if !$difftree{'from_id'};
6650 my $file = $difftree{'file'} || $difftree{'to_file'};
6654 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6655 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6656 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6657 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6658 -title
=> "diff"}, 'D');
6660 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6661 file_name
=>$file, hash_base
=>$commit),
6662 -title
=> "blame"}, 'B');
6664 # if this is not a feed of a file history
6665 if (!defined $file_name || $file_name ne $file) {
6666 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6667 file_name
=>$file, hash
=>$commit),
6668 -title
=> "history"}, 'H');
6670 $file = esc_path
($file);
6674 if ($format eq 'rss') {
6675 print "</ul>]]>\n" .
6676 "</content:encoded>\n" .
6678 } elsif ($format eq 'atom') {
6679 print "</ul>\n</div>\n" .
6686 if ($format eq 'rss') {
6687 print "</channel>\n</rss>\n";
6688 } elsif ($format eq 'atom') {
6702 my @list = git_get_projects_list
();
6705 -type
=> 'text/xml',
6706 -charset
=> 'utf-8',
6707 -content_disposition
=> 'inline; filename="opml.xml"');
6710 <?xml version="1.0" encoding="utf-8"?>
6711 <opml version="1.0">
6713 <title>$site_name OPML Export</title>
6716 <outline text="git RSS feeds">
6719 foreach my $pr (@list) {
6721 my $head = git_get_head_hash
($proj{'path'});
6722 if (!defined $head) {
6725 $git_dir = "$projectroot/$proj{'path'}";
6726 my %co = parse_commit
($head);
6731 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6732 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6733 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6734 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";