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 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31 # needed and used only for URLs with nonempty PATH_INFO
32 our $base_url = $my_url;
34 # When the script is used as DirectoryIndex, the URL does not contain the name
35 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36 # have to do it ourselves. We make $path_info global because it's also used
39 # Another issue with the script being the DirectoryIndex is that the resulting
40 # $my_url data is not the full script URL: this is good, because we want
41 # generated links to keep implying the script name if it wasn't explicitly
42 # indicated in the URL we're handling, but it means that $my_url cannot be used
44 # Therefore, if we needed to strip PATH_INFO, then we know that we have
45 # to build the base URL ourselves:
46 our $path_info = $ENV{"PATH_INFO"};
48 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
49 $my_uri =~ s
,\Q
$path_info\E
$,, &&
50 defined $ENV{'SCRIPT_NAME'}) {
51 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
55 # core git executable to use
56 # this can just be "git" if your webserver has a sensible PATH
57 our $GIT = "++GIT_BINDIR++/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "++GITWEB_PROJECTROOT++";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
67 # target of the home link on top of all pages
68 our $home_link = $my_uri || "/";
70 # string of the home link on top of all pages
71 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
73 # name of your site or organization to appear in page titles
74 # replace this with something more descriptive for clearer bookmarks
75 our $site_name = "++GITWEB_SITENAME++"
76 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 # filename of html text to include at top of each page
79 our $site_header = "++GITWEB_SITE_HEADER++";
80 # html text to include at home page
81 our $home_text = "++GITWEB_HOMETEXT++";
82 # filename of html text to include at bottom of each page
83 our $site_footer = "++GITWEB_SITE_FOOTER++";
86 our @stylesheets = ("++GITWEB_CSS++");
87 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
88 our $stylesheet = undef;
89 # URI of GIT logo (72x27 size)
90 our $logo = "++GITWEB_LOGO++";
91 # URI of GIT favicon, assumed to be image/png type
92 our $favicon = "++GITWEB_FAVICON++";
94 # URI and label (title) of GIT logo link
95 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
96 #our $logo_label = "git documentation";
97 our $logo_url = "http://git-scm.com/";
98 our $logo_label = "git homepage";
100 # source of projects list
101 our $projects_list = "++GITWEB_LIST++";
103 # the width (in characters) of the projects list "Description" column
104 our $projects_list_description_width = 25;
106 # default order of projects list
107 # valid values are none, project, descr, owner, and age
108 our $default_projects_order = "project";
110 # show repository only if this file exists
111 # (only effective if this variable evaluates to true)
112 our $export_ok = "++GITWEB_EXPORT_OK++";
114 # show repository only if this subroutine returns true
115 # when given the path to the project, for example:
116 # sub { return -e "$_[0]/git-daemon-export-ok"; }
117 our $export_auth_hook = undef;
119 # only allow viewing of repositories also shown on the overview page
120 our $strict_export = "++GITWEB_STRICT_EXPORT++";
122 # list of git base URLs used for URL to where fetch project from,
123 # i.e. full URL is "$git_base_url/$project"
124 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
126 # default blob_plain mimetype and default charset for text/plain blob
127 our $default_blob_plain_mimetype = 'text/plain';
128 our $default_text_plain_charset = undef;
130 # file to use for guessing MIME types before trying /etc/mime.types
131 # (relative to the current git repository)
132 our $mimetypes_file = undef;
134 # assume this charset if line contains non-UTF-8 characters;
135 # it should be valid encoding (see Encoding::Supported(3pm) for list),
136 # for which encoding all byte sequences are valid, for example
137 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
138 # could be even 'utf-8' for the old behavior)
139 our $fallback_encoding = 'latin1';
141 # rename detection options for git-diff and git-diff-tree
142 # - default is '-M', with the cost proportional to
143 # (number of removed files) * (number of new files).
144 # - more costly is '-C' (which implies '-M'), with the cost proportional to
145 # (number of changed files + number of removed files) * (number of new files)
146 # - even more costly is '-C', '--find-copies-harder' with cost
147 # (number of files in the original tree) * (number of new files)
148 # - one might want to include '-B' option, e.g. '-B', '-M'
149 our @diff_opts = ('-M'); # taken from git_commit
151 # Disables features that would allow repository owners to inject script into
153 our $prevent_xss = 0;
155 # information about snapshot formats that gitweb is capable of serving
156 our %known_snapshot_formats = (
158 # 'display' => display name,
159 # 'type' => mime type,
160 # 'suffix' => filename suffix,
161 # 'format' => --format for git-archive,
162 # 'compressor' => [compressor command and arguments]
163 # (array reference, optional)
164 # 'disabled' => boolean (optional)}
167 'display' => 'tar.gz',
168 'type' => 'application/x-gzip',
169 'suffix' => '.tar.gz',
171 'compressor' => ['gzip']},
174 'display' => 'tar.bz2',
175 'type' => 'application/x-bzip2',
176 'suffix' => '.tar.bz2',
178 'compressor' => ['bzip2']},
182 'type' => 'application/x-zip',
187 # Aliases so we understand old gitweb.snapshot values in repository
189 our %known_snapshot_format_aliases = (
193 # backward compatibility: legacy gitweb config support
194 'x-gzip' => undef, 'gz' => undef,
195 'x-bzip2' => undef, 'bz2' => undef,
196 'x-zip' => undef, '' => undef,
199 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
200 # are changed, it may be appropriate to change these values too via
207 # You define site-wide feature defaults here; override them with
208 # $GITWEB_CONFIG as necessary.
211 # 'sub' => feature-sub (subroutine),
212 # 'override' => allow-override (boolean),
213 # 'default' => [ default options...] (array reference)}
215 # if feature is overridable (it means that allow-override has true value),
216 # then feature-sub will be called with default options as parameters;
217 # return value of feature-sub indicates if to enable specified feature
219 # if there is no 'sub' key (no feature-sub), then feature cannot be
222 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
223 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
226 # Enable the 'blame' blob view, showing the last commit that modified
227 # each line in the file. This can be very CPU-intensive.
229 # To enable system wide have in $GITWEB_CONFIG
230 # $feature{'blame'}{'default'} = [1];
231 # To have project specific config enable override in $GITWEB_CONFIG
232 # $feature{'blame'}{'override'} = 1;
233 # and in project config gitweb.blame = 0|1;
235 'sub' => sub { feature_bool
('blame', @_) },
239 # Enable the 'snapshot' link, providing a compressed archive of any
240 # tree. This can potentially generate high traffic if you have large
243 # Value is a list of formats defined in %known_snapshot_formats that
245 # To disable system wide have in $GITWEB_CONFIG
246 # $feature{'snapshot'}{'default'} = [];
247 # To have project specific config enable override in $GITWEB_CONFIG
248 # $feature{'snapshot'}{'override'} = 1;
249 # and in project config, a comma-separated list of formats or "none"
250 # to disable. Example: gitweb.snapshot = tbz2,zip;
252 'sub' => \
&feature_snapshot
,
254 'default' => ['tgz']},
256 # Enable text search, which will list the commits which match author,
257 # committer or commit text to a given string. Enabled by default.
258 # Project specific override is not supported.
263 # Enable grep search, which will list the files in currently selected
264 # tree containing the given string. Enabled by default. This can be
265 # potentially CPU-intensive, of course.
267 # To enable system wide have in $GITWEB_CONFIG
268 # $feature{'grep'}{'default'} = [1];
269 # To have project specific config enable override in $GITWEB_CONFIG
270 # $feature{'grep'}{'override'} = 1;
271 # and in project config gitweb.grep = 0|1;
273 'sub' => sub { feature_bool
('grep', @_) },
277 # Enable the pickaxe search, which will list the commits that modified
278 # a given string in a file. This can be practical and quite faster
279 # alternative to 'blame', but still potentially CPU-intensive.
281 # To enable system wide have in $GITWEB_CONFIG
282 # $feature{'pickaxe'}{'default'} = [1];
283 # To have project specific config enable override in $GITWEB_CONFIG
284 # $feature{'pickaxe'}{'override'} = 1;
285 # and in project config gitweb.pickaxe = 0|1;
287 'sub' => sub { feature_bool
('pickaxe', @_) },
291 # Make gitweb use an alternative format of the URLs which can be
292 # more readable and natural-looking: project name is embedded
293 # directly in the path and the query string contains other
294 # auxiliary information. All gitweb installations recognize
295 # URL in either format; this configures in which formats gitweb
298 # To enable system wide have in $GITWEB_CONFIG
299 # $feature{'pathinfo'}{'default'} = [1];
300 # Project specific override is not supported.
302 # Note that you will need to change the default location of CSS,
303 # favicon, logo and possibly other files to an absolute URL. Also,
304 # if gitweb.cgi serves as your indexfile, you will need to force
305 # $my_uri to contain the script name in your $GITWEB_CONFIG.
310 # Make gitweb consider projects in project root subdirectories
311 # to be forks of existing projects. Given project $projname.git,
312 # projects matching $projname/*.git will not be shown in the main
313 # projects list, instead a '+' mark will be added to $projname
314 # there and a 'forks' view will be enabled for the project, listing
315 # all the forks. If project list is taken from a file, forks have
316 # to be listed after the main project.
318 # To enable system wide have in $GITWEB_CONFIG
319 # $feature{'forks'}{'default'} = [1];
320 # Project specific override is not supported.
325 # Insert custom links to the action bar of all project pages.
326 # This enables you mainly to link to third-party scripts integrating
327 # into gitweb; e.g. git-browser for graphical history representation
328 # or custom web-based repository administration interface.
330 # The 'default' value consists of a list of triplets in the form
331 # (label, link, position) where position is the label after which
332 # to insert the link and link is a format string where %n expands
333 # to the project name, %f to the project path within the filesystem,
334 # %h to the current hash (h gitweb parameter) and %b to the current
335 # hash base (hb gitweb parameter); %% expands to %.
337 # To enable system wide have in $GITWEB_CONFIG e.g.
338 # $feature{'actions'}{'default'} = [('graphiclog',
339 # '/git-browser/by-commit.html?r=%n', 'summary')];
340 # Project specific override is not supported.
345 # Allow gitweb scan project content tags described in ctags/
346 # of project repository, and display the popular Web 2.0-ish
347 # "tag cloud" near the project list. Note that this is something
348 # COMPLETELY different from the normal Git tags.
350 # gitweb by itself can show existing tags, but it does not handle
351 # tagging itself; you need an external application for that.
352 # For an example script, check Girocco's cgi/tagproj.cgi.
353 # You may want to install the HTML::TagCloud Perl module to get
354 # a pretty tag cloud instead of just a list of tags.
356 # To enable system wide have in $GITWEB_CONFIG
357 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
358 # Project specific override is not supported.
363 # The maximum number of patches in a patchset generated in patch
364 # view. Set this to 0 or undef to disable patch view, or to a
365 # negative number to remove any limit.
367 # To disable system wide have in $GITWEB_CONFIG
368 # $feature{'patches'}{'default'} = [0];
369 # To have project specific config enable override in $GITWEB_CONFIG
370 # $feature{'patches'}{'override'} = 1;
371 # and in project config gitweb.patches = 0|n;
372 # where n is the maximum number of patches allowed in a patchset.
374 'sub' => \
&feature_patches
,
378 # Avatar support. When this feature is enabled, views such as
379 # shortlog or commit will display an avatar associated with
380 # the email of the committer(s) and/or author(s).
382 # Currently available providers are gravatar and picon.
383 # If an unknown provider is specified, the feature is disabled.
385 # Gravatar depends on Digest::MD5.
386 # Picon currently relies on the indiana.edu database.
388 # To enable system wide have in $GITWEB_CONFIG
389 # $feature{'avatar'}{'default'} = ['<provider>'];
390 # where <provider> is either gravatar or picon.
391 # To have project specific config enable override in $GITWEB_CONFIG
392 # $feature{'avatar'}{'override'} = 1;
393 # and in project config gitweb.avatar = <provider>;
395 'sub' => \
&feature_avatar
,
400 sub gitweb_get_feature
{
402 return unless exists $feature{$name};
403 my ($sub, $override, @defaults) = (
404 $feature{$name}{'sub'},
405 $feature{$name}{'override'},
406 @
{$feature{$name}{'default'}});
407 if (!$override) { return @defaults; }
409 warn "feature $name is not overrideable";
412 return $sub->(@defaults);
415 # A wrapper to check if a given feature is enabled.
416 # With this, you can say
418 # my $bool_feat = gitweb_check_feature('bool_feat');
419 # gitweb_check_feature('bool_feat') or somecode;
423 # my ($bool_feat) = gitweb_get_feature('bool_feat');
424 # (gitweb_get_feature('bool_feat'))[0] or somecode;
426 sub gitweb_check_feature
{
427 return (gitweb_get_feature
(@_))[0];
433 my ($val) = git_get_project_config
($key, '--bool');
437 } elsif ($val eq 'true') {
439 } elsif ($val eq 'false') {
444 sub feature_snapshot
{
447 my ($val) = git_get_project_config
('snapshot');
450 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
456 sub feature_patches
{
457 my @val = (git_get_project_config
('patches', '--int'));
467 my @val = (git_get_project_config
('avatar'));
469 return @val ?
@val : @_;
472 # checking HEAD file with -e is fragile if the repository was
473 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
475 sub check_head_link
{
477 my $headfile = "$dir/HEAD";
478 return ((-e
$headfile) ||
479 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
482 sub check_export_ok
{
484 return (check_head_link
($dir) &&
485 (!$export_ok || -e
"$dir/$export_ok") &&
486 (!$export_auth_hook || $export_auth_hook->($dir)));
489 # process alternate names for backward compatibility
490 # filter out unsupported (unknown) snapshot formats
491 sub filter_snapshot_fmts
{
495 exists $known_snapshot_format_aliases{$_} ?
496 $known_snapshot_format_aliases{$_} : $_} @fmts;
498 exists $known_snapshot_formats{$_} &&
499 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
502 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
503 if (-e
$GITWEB_CONFIG) {
506 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
507 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
510 # version of the core git binary
511 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
513 $projects_list ||= $projectroot;
515 # ======================================================================
516 # input validation and dispatch
518 # input parameters can be collected from a variety of sources (presently, CGI
519 # and PATH_INFO), so we define an %input_params hash that collects them all
520 # together during validation: this allows subsequent uses (e.g. href()) to be
521 # agnostic of the parameter origin
523 our %input_params = ();
525 # input parameters are stored with the long parameter name as key. This will
526 # also be used in the href subroutine to convert parameters to their CGI
527 # equivalent, and since the href() usage is the most frequent one, we store
528 # the name -> CGI key mapping here, instead of the reverse.
530 # XXX: Warning: If you touch this, check the search form for updating,
533 our @cgi_param_mapping = (
541 hash_parent_base
=> "hpb",
546 snapshot_format
=> "sf",
547 extra_options
=> "opt",
548 search_use_regexp
=> "sr",
550 our %cgi_param_mapping = @cgi_param_mapping;
552 # we will also need to know the possible actions, for validation
554 "blame" => \
&git_blame
,
555 "blobdiff" => \
&git_blobdiff
,
556 "blobdiff_plain" => \
&git_blobdiff_plain
,
557 "blob" => \
&git_blob
,
558 "blob_plain" => \
&git_blob_plain
,
559 "commitdiff" => \
&git_commitdiff
,
560 "commitdiff_plain" => \
&git_commitdiff_plain
,
561 "commit" => \
&git_commit
,
562 "forks" => \
&git_forks
,
563 "heads" => \
&git_heads
,
564 "history" => \
&git_history
,
566 "patch" => \
&git_patch
,
567 "patches" => \
&git_patches
,
569 "atom" => \
&git_atom
,
570 "search" => \
&git_search
,
571 "search_help" => \
&git_search_help
,
572 "shortlog" => \
&git_shortlog
,
573 "summary" => \
&git_summary
,
575 "tags" => \
&git_tags
,
576 "tree" => \
&git_tree
,
577 "snapshot" => \
&git_snapshot
,
578 "object" => \
&git_object
,
579 # those below don't need $project
580 "opml" => \
&git_opml
,
581 "project_list" => \
&git_project_list
,
582 "project_index" => \
&git_project_index
,
585 # finally, we have the hash of allowed extra_options for the commands that
587 our %allowed_options = (
588 "--no-merges" => [ qw(rss atom log shortlog history) ],
591 # fill %input_params with the CGI parameters. All values except for 'opt'
592 # should be single values, but opt can be an array. We should probably
593 # build an array of parameters that can be multi-valued, but since for the time
594 # being it's only this one, we just single it out
595 while (my ($name, $symbol) = each %cgi_param_mapping) {
596 if ($symbol eq 'opt') {
597 $input_params{$name} = [ $cgi->param($symbol) ];
599 $input_params{$name} = $cgi->param($symbol);
603 # now read PATH_INFO and update the parameter list for missing parameters
604 sub evaluate_path_info
{
605 return if defined $input_params{'project'};
606 return if !$path_info;
607 $path_info =~ s
,^/+,,;
608 return if !$path_info;
610 # find which part of PATH_INFO is project
611 my $project = $path_info;
613 while ($project && !check_head_link
("$projectroot/$project")) {
614 $project =~ s
,/*[^/]*$,,;
616 return unless $project;
617 $input_params{'project'} = $project;
619 # do not change any parameters if an action is given using the query string
620 return if $input_params{'action'};
621 $path_info =~ s
,^\Q
$project\E
/*,,;
623 # next, check if we have an action
624 my $action = $path_info;
626 if (exists $actions{$action}) {
627 $path_info =~ s
,^$action/*,,;
628 $input_params{'action'} = $action;
631 # list of actions that want hash_base instead of hash, but can have no
632 # pathname (f) parameter
639 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
640 my ($parentrefname, $parentpathname, $refname, $pathname) =
641 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
643 # first, analyze the 'current' part
644 if (defined $pathname) {
645 # we got "branch:filename" or "branch:dir/"
646 # we could use git_get_type(branch:pathname), but:
647 # - it needs $git_dir
648 # - it does a git() call
649 # - the convention of terminating directories with a slash
650 # makes it superfluous
651 # - embedding the action in the PATH_INFO would make it even
653 $pathname =~ s
,^/+,,;
654 if (!$pathname || substr($pathname, -1) eq "/") {
655 $input_params{'action'} ||= "tree";
658 # the default action depends on whether we had parent info
660 if ($parentrefname) {
661 $input_params{'action'} ||= "blobdiff_plain";
663 $input_params{'action'} ||= "blob_plain";
666 $input_params{'hash_base'} ||= $refname;
667 $input_params{'file_name'} ||= $pathname;
668 } elsif (defined $refname) {
669 # we got "branch". In this case we have to choose if we have to
670 # set hash or hash_base.
672 # Most of the actions without a pathname only want hash to be
673 # set, except for the ones specified in @wants_base that want
674 # hash_base instead. It should also be noted that hand-crafted
675 # links having 'history' as an action and no pathname or hash
676 # set will fail, but that happens regardless of PATH_INFO.
677 $input_params{'action'} ||= "shortlog";
678 if (grep { $_ eq $input_params{'action'} } @wants_base) {
679 $input_params{'hash_base'} ||= $refname;
681 $input_params{'hash'} ||= $refname;
685 # next, handle the 'parent' part, if present
686 if (defined $parentrefname) {
687 # a missing pathspec defaults to the 'current' filename, allowing e.g.
688 # someproject/blobdiff/oldrev..newrev:/filename
689 if ($parentpathname) {
690 $parentpathname =~ s
,^/+,,;
691 $parentpathname =~ s
,/$,,;
692 $input_params{'file_parent'} ||= $parentpathname;
694 $input_params{'file_parent'} ||= $input_params{'file_name'};
696 # we assume that hash_parent_base is wanted if a path was specified,
697 # or if the action wants hash_base instead of hash
698 if (defined $input_params{'file_parent'} ||
699 grep { $_ eq $input_params{'action'} } @wants_base) {
700 $input_params{'hash_parent_base'} ||= $parentrefname;
702 $input_params{'hash_parent'} ||= $parentrefname;
706 # for the snapshot action, we allow URLs in the form
707 # $project/snapshot/$hash.ext
708 # where .ext determines the snapshot and gets removed from the
709 # passed $refname to provide the $hash.
711 # To be able to tell that $refname includes the format extension, we
712 # require the following two conditions to be satisfied:
713 # - the hash input parameter MUST have been set from the $refname part
714 # of the URL (i.e. they must be equal)
715 # - the snapshot format MUST NOT have been defined already (e.g. from
717 # It's also useless to try any matching unless $refname has a dot,
718 # so we check for that too
719 if (defined $input_params{'action'} &&
720 $input_params{'action'} eq 'snapshot' &&
721 defined $refname && index($refname, '.') != -1 &&
722 $refname eq $input_params{'hash'} &&
723 !defined $input_params{'snapshot_format'}) {
724 # We loop over the known snapshot formats, checking for
725 # extensions. Allowed extensions are both the defined suffix
726 # (which includes the initial dot already) and the snapshot
727 # format key itself, with a prepended dot
728 while (my ($fmt, $opt) = each %known_snapshot_formats) {
730 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
734 # a valid suffix was found, so set the snapshot format
735 # and reset the hash parameter
736 $input_params{'snapshot_format'} = $fmt;
737 $input_params{'hash'} = $hash;
738 # we also set the format suffix to the one requested
739 # in the URL: this way a request for e.g. .tgz returns
740 # a .tgz instead of a .tar.gz
741 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
746 evaluate_path_info
();
748 our $action = $input_params{'action'};
749 if (defined $action) {
750 if (!validate_action
($action)) {
751 die_error
(400, "Invalid action parameter");
755 # parameters which are pathnames
756 our $project = $input_params{'project'};
757 if (defined $project) {
758 if (!validate_project
($project)) {
760 die_error
(404, "No such project");
764 our $file_name = $input_params{'file_name'};
765 if (defined $file_name) {
766 if (!validate_pathname
($file_name)) {
767 die_error
(400, "Invalid file parameter");
771 our $file_parent = $input_params{'file_parent'};
772 if (defined $file_parent) {
773 if (!validate_pathname
($file_parent)) {
774 die_error
(400, "Invalid file parent parameter");
778 # parameters which are refnames
779 our $hash = $input_params{'hash'};
781 if (!validate_refname
($hash)) {
782 die_error
(400, "Invalid hash parameter");
786 our $hash_parent = $input_params{'hash_parent'};
787 if (defined $hash_parent) {
788 if (!validate_refname
($hash_parent)) {
789 die_error
(400, "Invalid hash parent parameter");
793 our $hash_base = $input_params{'hash_base'};
794 if (defined $hash_base) {
795 if (!validate_refname
($hash_base)) {
796 die_error
(400, "Invalid hash base parameter");
800 our @extra_options = @
{$input_params{'extra_options'}};
801 # @extra_options is always defined, since it can only be (currently) set from
802 # CGI, and $cgi->param() returns the empty array in array context if the param
804 foreach my $opt (@extra_options) {
805 if (not exists $allowed_options{$opt}) {
806 die_error
(400, "Invalid option parameter");
808 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
809 die_error
(400, "Invalid option parameter for this action");
813 our $hash_parent_base = $input_params{'hash_parent_base'};
814 if (defined $hash_parent_base) {
815 if (!validate_refname
($hash_parent_base)) {
816 die_error
(400, "Invalid hash parent base parameter");
821 our $page = $input_params{'page'};
823 if ($page =~ m/[^0-9]/) {
824 die_error
(400, "Invalid page parameter");
828 our $searchtype = $input_params{'searchtype'};
829 if (defined $searchtype) {
830 if ($searchtype =~ m/[^a-z]/) {
831 die_error
(400, "Invalid searchtype parameter");
835 our $search_use_regexp = $input_params{'search_use_regexp'};
837 our $searchtext = $input_params{'searchtext'};
839 if (defined $searchtext) {
840 if (length($searchtext) < 2) {
841 die_error
(403, "At least two characters are required for search parameter");
843 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
846 # path to the current git repository
848 $git_dir = "$projectroot/$project" if $project;
850 # list of supported snapshot formats
851 our @snapshot_fmts = gitweb_get_feature
('snapshot');
852 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
854 # check that the avatar feature is set to a known provider name,
855 # and for each provider check if the dependencies are satisfied.
856 # if the provider name is invalid or the dependencies are not met,
857 # reset $git_avatar to the empty string.
858 our ($git_avatar) = gitweb_get_feature
('avatar');
859 if ($git_avatar eq 'gravatar') {
860 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
861 } elsif ($git_avatar eq 'picon') {
868 if (!defined $action) {
870 $action = git_get_type
($hash);
871 } elsif (defined $hash_base && defined $file_name) {
872 $action = git_get_type
("$hash_base:$file_name");
873 } elsif (defined $project) {
876 $action = 'project_list';
879 if (!defined($actions{$action})) {
880 die_error
(400, "Unknown action");
882 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
884 die_error
(400, "Project needed");
886 $actions{$action}->();
889 ## ======================================================================
894 # default is to use -absolute url() i.e. $my_uri
895 my $href = $params{-full
} ?
$my_url : $my_uri;
897 $params{'project'} = $project unless exists $params{'project'};
899 if ($params{-replay
}) {
900 while (my ($name, $symbol) = each %cgi_param_mapping) {
901 if (!exists $params{$name}) {
902 $params{$name} = $input_params{$name};
907 my $use_pathinfo = gitweb_check_feature
('pathinfo');
908 if ($use_pathinfo and defined $params{'project'}) {
909 # try to put as many parameters as possible in PATH_INFO:
912 # - hash_parent or hash_parent_base:/file_parent
913 # - hash or hash_base:/filename
914 # - the snapshot_format as an appropriate suffix
916 # When the script is the root DirectoryIndex for the domain,
917 # $href here would be something like http://gitweb.example.com/
918 # Thus, we strip any trailing / from $href, to spare us double
919 # slashes in the final URL
922 # Then add the project name, if present
923 $href .= "/".esc_url
($params{'project'});
924 delete $params{'project'};
926 # since we destructively absorb parameters, we keep this
927 # boolean that remembers if we're handling a snapshot
928 my $is_snapshot = $params{'action'} eq 'snapshot';
930 # Summary just uses the project path URL, any other action is
932 if (defined $params{'action'}) {
933 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
934 delete $params{'action'};
937 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
938 # stripping nonexistent or useless pieces
939 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
940 || $params{'hash_parent'} || $params{'hash'});
941 if (defined $params{'hash_base'}) {
942 if (defined $params{'hash_parent_base'}) {
943 $href .= esc_url
($params{'hash_parent_base'});
944 # skip the file_parent if it's the same as the file_name
945 if (defined $params{'file_parent'}) {
946 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
947 delete $params{'file_parent'};
948 } elsif ($params{'file_parent'} !~ /\.\./) {
949 $href .= ":/".esc_url
($params{'file_parent'});
950 delete $params{'file_parent'};
954 delete $params{'hash_parent'};
955 delete $params{'hash_parent_base'};
956 } elsif (defined $params{'hash_parent'}) {
957 $href .= esc_url
($params{'hash_parent'}). "..";
958 delete $params{'hash_parent'};
961 $href .= esc_url
($params{'hash_base'});
962 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
963 $href .= ":/".esc_url
($params{'file_name'});
964 delete $params{'file_name'};
966 delete $params{'hash'};
967 delete $params{'hash_base'};
968 } elsif (defined $params{'hash'}) {
969 $href .= esc_url
($params{'hash'});
970 delete $params{'hash'};
973 # If the action was a snapshot, we can absorb the
974 # snapshot_format parameter too
976 my $fmt = $params{'snapshot_format'};
977 # snapshot_format should always be defined when href()
978 # is called, but just in case some code forgets, we
979 # fall back to the default
980 $fmt ||= $snapshot_fmts[0];
981 $href .= $known_snapshot_formats{$fmt}{'suffix'};
982 delete $params{'snapshot_format'};
986 # now encode the parameters explicitly
988 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
989 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
990 if (defined $params{$name}) {
991 if (ref($params{$name}) eq "ARRAY") {
992 foreach my $par (@
{$params{$name}}) {
993 push @result, $symbol . "=" . esc_param
($par);
996 push @result, $symbol . "=" . esc_param
($params{$name});
1000 $href .= "?" . join(';', @result) if scalar @result;
1006 ## ======================================================================
1007 ## validation, quoting/unquoting and escaping
1009 sub validate_action
{
1010 my $input = shift || return undef;
1011 return undef unless exists $actions{$input};
1015 sub validate_project
{
1016 my $input = shift || return undef;
1017 if (!validate_pathname
($input) ||
1018 !(-d
"$projectroot/$input") ||
1019 !check_export_ok
("$projectroot/$input") ||
1020 ($strict_export && !project_in_list
($input))) {
1027 sub validate_pathname
{
1028 my $input = shift || return undef;
1030 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1031 # at the beginning, at the end, and between slashes.
1032 # also this catches doubled slashes
1033 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1036 # no null characters
1037 if ($input =~ m!\0!) {
1043 sub validate_refname
{
1044 my $input = shift || return undef;
1046 # textual hashes are O.K.
1047 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1050 # it must be correct pathname
1051 $input = validate_pathname
($input)
1053 # restrictions on ref name according to git-check-ref-format
1054 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1060 # decode sequences of octets in utf8 into Perl's internal form,
1061 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1062 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1065 if (utf8
::valid
($str)) {
1069 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1073 # quote unsafe chars, but keep the slash, even when it's not
1074 # correct, but quoted slashes look too horrible in bookmarks
1077 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1083 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1086 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1092 # replace invalid utf8 character with SUBSTITUTION sequence
1097 $str = to_utf8
($str);
1098 $str = $cgi->escapeHTML($str);
1099 if ($opts{'-nbsp'}) {
1100 $str =~ s/ / /g;
1102 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1106 # quote control characters and escape filename to HTML
1111 $str = to_utf8
($str);
1112 $str = $cgi->escapeHTML($str);
1113 if ($opts{'-nbsp'}) {
1114 $str =~ s/ / /g;
1116 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1120 # Make control characters "printable", using character escape codes (CEC)
1124 my %es = ( # character escape codes, aka escape sequences
1125 "\t" => '\t', # tab (HT)
1126 "\n" => '\n', # line feed (LF)
1127 "\r" => '\r', # carrige return (CR)
1128 "\f" => '\f', # form feed (FF)
1129 "\b" => '\b', # backspace (BS)
1130 "\a" => '\a', # alarm (bell) (BEL)
1131 "\e" => '\e', # escape (ESC)
1132 "\013" => '\v', # vertical tab (VT)
1133 "\000" => '\0', # nul character (NUL)
1135 my $chr = ( (exists $es{$cntrl})
1137 : sprintf('\%2x', ord($cntrl)) );
1138 if ($opts{-nohtml
}) {
1141 return "<span class=\"cntrl\">$chr</span>";
1145 # Alternatively use unicode control pictures codepoints,
1146 # Unicode "printable representation" (PR)
1151 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1152 if ($opts{-nohtml
}) {
1155 return "<span class=\"cntrl\">$chr</span>";
1159 # git may return quoted and escaped filenames
1165 my %es = ( # character escape codes, aka escape sequences
1166 't' => "\t", # tab (HT, TAB)
1167 'n' => "\n", # newline (NL)
1168 'r' => "\r", # return (CR)
1169 'f' => "\f", # form feed (FF)
1170 'b' => "\b", # backspace (BS)
1171 'a' => "\a", # alarm (bell) (BEL)
1172 'e' => "\e", # escape (ESC)
1173 'v' => "\013", # vertical tab (VT)
1176 if ($seq =~ m/^[0-7]{1,3}$/) {
1177 # octal char sequence
1178 return chr(oct($seq));
1179 } elsif (exists $es{$seq}) {
1180 # C escape sequence, aka character escape code
1183 # quoted ordinary character
1187 if ($str =~ m/^"(.*)"$/) {
1190 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1195 # escape tabs (convert tabs to spaces)
1199 while ((my $pos = index($line, "\t")) != -1) {
1200 if (my $count = (8 - ($pos % 8))) {
1201 my $spaces = ' ' x
$count;
1202 $line =~ s/\t/$spaces/;
1209 sub project_in_list
{
1210 my $project = shift;
1211 my @list = git_get_projects_list
();
1212 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1215 ## ----------------------------------------------------------------------
1216 ## HTML aware string manipulation
1218 # Try to chop given string on a word boundary between position
1219 # $len and $len+$add_len. If there is no word boundary there,
1220 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1221 # (marking chopped part) would be longer than given string.
1225 my $add_len = shift || 10;
1226 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1228 # Make sure perl knows it is utf8 encoded so we don't
1229 # cut in the middle of a utf8 multibyte char.
1230 $str = to_utf8
($str);
1232 # allow only $len chars, but don't cut a word if it would fit in $add_len
1233 # if it doesn't fit, cut it if it's still longer than the dots we would add
1234 # remove chopped character entities entirely
1236 # when chopping in the middle, distribute $len into left and right part
1237 # return early if chopping wouldn't make string shorter
1238 if ($where eq 'center') {
1239 return $str if ($len + 5 >= length($str)); # filler is length 5
1242 return $str if ($len + 4 >= length($str)); # filler is length 4
1245 # regexps: ending and beginning with word part up to $add_len
1246 my $endre = qr/.{$len}\w{0,$add_len}/;
1247 my $begre = qr/\w{0,$add_len}.{$len}/;
1249 if ($where eq 'left') {
1250 $str =~ m/^(.*?)($begre)$/;
1251 my ($lead, $body) = ($1, $2);
1252 if (length($lead) > 4) {
1253 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1256 return "$lead$body";
1258 } elsif ($where eq 'center') {
1259 $str =~ m/^($endre)(.*)$/;
1260 my ($left, $str) = ($1, $2);
1261 $str =~ m/^(.*?)($begre)$/;
1262 my ($mid, $right) = ($1, $2);
1263 if (length($mid) > 5) {
1264 $left =~ s/&[^;]*$//;
1265 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1268 return "$left$mid$right";
1271 $str =~ m/^($endre)(.*)$/;
1274 if (length($tail) > 4) {
1275 $body =~ s/&[^;]*$//;
1278 return "$body$tail";
1282 # takes the same arguments as chop_str, but also wraps a <span> around the
1283 # result with a title attribute if it does get chopped. Additionally, the
1284 # string is HTML-escaped.
1285 sub chop_and_escape_str
{
1288 my $chopped = chop_str
(@_);
1289 if ($chopped eq $str) {
1290 return esc_html
($chopped);
1292 $str =~ s/[[:cntrl:]]/?/g;
1293 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1297 ## ----------------------------------------------------------------------
1298 ## functions returning short strings
1300 # CSS class for given age value (in seconds)
1304 if (!defined $age) {
1306 } elsif ($age < 60*60*2) {
1308 } elsif ($age < 60*60*24*2) {
1315 # convert age in seconds to "nn units ago" string
1320 if ($age > 60*60*24*365*2) {
1321 $age_str = (int $age/60/60/24/365);
1322 $age_str .= " years ago";
1323 } elsif ($age > 60*60*24*(365/12)*2) {
1324 $age_str = int $age/60/60/24/(365/12);
1325 $age_str .= " months ago";
1326 } elsif ($age > 60*60*24*7*2) {
1327 $age_str = int $age/60/60/24/7;
1328 $age_str .= " weeks ago";
1329 } elsif ($age > 60*60*24*2) {
1330 $age_str = int $age/60/60/24;
1331 $age_str .= " days ago";
1332 } elsif ($age > 60*60*2) {
1333 $age_str = int $age/60/60;
1334 $age_str .= " hours ago";
1335 } elsif ($age > 60*2) {
1336 $age_str = int $age/60;
1337 $age_str .= " min ago";
1338 } elsif ($age > 2) {
1339 $age_str = int $age;
1340 $age_str .= " sec ago";
1342 $age_str .= " right now";
1348 S_IFINVALID
=> 0030000,
1349 S_IFGITLINK
=> 0160000,
1352 # submodule/subproject, a commit object reference
1356 return (($mode & S_IFMT
) == S_IFGITLINK
)
1359 # convert file mode in octal to symbolic file mode string
1361 my $mode = oct shift;
1363 if (S_ISGITLINK
($mode)) {
1364 return 'm---------';
1365 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1366 return 'drwxr-xr-x';
1367 } elsif (S_ISLNK
($mode)) {
1368 return 'lrwxrwxrwx';
1369 } elsif (S_ISREG
($mode)) {
1370 # git cares only about the executable bit
1371 if ($mode & S_IXUSR
) {
1372 return '-rwxr-xr-x';
1374 return '-rw-r--r--';
1377 return '----------';
1381 # convert file mode in octal to file type string
1385 if ($mode !~ m/^[0-7]+$/) {
1391 if (S_ISGITLINK
($mode)) {
1393 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1395 } elsif (S_ISLNK
($mode)) {
1397 } elsif (S_ISREG
($mode)) {
1404 # convert file mode in octal to file type description string
1405 sub file_type_long
{
1408 if ($mode !~ m/^[0-7]+$/) {
1414 if (S_ISGITLINK
($mode)) {
1416 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1418 } elsif (S_ISLNK
($mode)) {
1420 } elsif (S_ISREG
($mode)) {
1421 if ($mode & S_IXUSR
) {
1422 return "executable";
1432 ## ----------------------------------------------------------------------
1433 ## functions returning short HTML fragments, or transforming HTML fragments
1434 ## which don't belong to other sections
1436 # format line of commit message.
1437 sub format_log_line_html
{
1440 $line = esc_html
($line, -nbsp
=>1);
1441 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1442 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1443 -class => "text"}, $1);
1449 # format marker of refs pointing to given object
1451 # the destination action is chosen based on object type and current context:
1452 # - for annotated tags, we choose the tag view unless it's the current view
1453 # already, in which case we go to shortlog view
1454 # - for other refs, we keep the current view if we're in history, shortlog or
1455 # log view, and select shortlog otherwise
1456 sub format_ref_marker
{
1457 my ($refs, $id) = @_;
1460 if (defined $refs->{$id}) {
1461 foreach my $ref (@
{$refs->{$id}}) {
1462 # this code exploits the fact that non-lightweight tags are the
1463 # only indirect objects, and that they are the only objects for which
1464 # we want to use tag instead of shortlog as action
1465 my ($type, $name) = qw();
1466 my $indirect = ($ref =~ s/\^\{\}$//);
1467 # e.g. tags/v2.6.11 or heads/next
1468 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1477 $class .= " indirect" if $indirect;
1479 my $dest_action = "shortlog";
1482 $dest_action = "tag" unless $action eq "tag";
1483 } elsif ($action =~ /^(history|(short)?log)$/) {
1484 $dest_action = $action;
1488 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1491 my $link = $cgi->a({
1493 action
=>$dest_action,
1497 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1503 return ' <span class="refs">'. $markers . '</span>';
1509 # format, perhaps shortened and with markers, title line
1510 sub format_subject_html
{
1511 my ($long, $short, $href, $extra) = @_;
1512 $extra = '' unless defined($extra);
1514 if (length($short) < length($long)) {
1515 $long =~ s/[[:cntrl:]]/?/g;
1516 return $cgi->a({-href
=> $href, -class => "list subject",
1517 -title
=> to_utf8
($long)},
1518 esc_html
($short) . $extra);
1520 return $cgi->a({-href
=> $href, -class => "list subject"},
1521 esc_html
($long) . $extra);
1525 # Rather than recomputing the url for an email multiple times, we cache it
1526 # after the first hit. This gives a visible benefit in views where the avatar
1527 # for the same email is used repeatedly (e.g. shortlog).
1528 # The cache is shared by all avatar engines (currently gravatar only), which
1529 # are free to use it as preferred. Since only one avatar engine is used for any
1530 # given page, there's no risk for cache conflicts.
1531 our %avatar_cache = ();
1533 # Compute the picon url for a given email, by using the picon search service over at
1534 # http://www.cs.indiana.edu/picons/search.html
1536 my $email = lc shift;
1537 if (!$avatar_cache{$email}) {
1538 my ($user, $domain) = split('@', $email);
1539 $avatar_cache{$email} =
1540 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1542 "users+domains+unknown/up/single";
1544 return $avatar_cache{$email};
1547 # Compute the gravatar url for a given email, if it's not in the cache already.
1548 # Gravatar stores only the part of the URL before the size, since that's the
1549 # one computationally more expensive. This also allows reuse of the cache for
1550 # different sizes (for this particular engine).
1552 my $email = lc shift;
1554 $avatar_cache{$email} ||=
1555 "http://www.gravatar.com/avatar/" .
1556 Digest
::MD5
::md5_hex
($email) . "?s=";
1557 return $avatar_cache{$email} . $size;
1560 # Insert an avatar for the given $email at the given $size if the feature
1562 sub git_get_avatar
{
1563 my ($email, %opts) = @_;
1564 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1565 my $post_white = ($opts{-pad_after
} ?
" " : "");
1566 $opts{-size
} ||= 'default';
1567 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1569 if ($git_avatar eq 'gravatar') {
1570 $url = gravatar_url
($email, $size);
1571 } elsif ($git_avatar eq 'picon') {
1572 $url = picon_url
($email);
1574 # Other providers can be added by extending the if chain, defining $url
1575 # as needed. If no variant puts something in $url, we assume avatars
1576 # are completely disabled/unavailable.
1579 "<img width=\"$size\" " .
1580 "class=\"avatar\" " .
1589 # format the author name of the given commit with the given tag
1590 # the author name is chopped and escaped according to the other
1591 # optional parameters (see chop_str).
1592 sub format_author_html
{
1595 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1596 return "<$tag class=\"author\">" .
1597 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1598 $author . "</$tag>";
1601 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1602 sub format_git_diff_header_line
{
1604 my $diffinfo = shift;
1605 my ($from, $to) = @_;
1607 if ($diffinfo->{'nparents'}) {
1609 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1610 if ($to->{'href'}) {
1611 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1612 esc_path
($to->{'file'}));
1613 } else { # file was deleted (no href)
1614 $line .= esc_path
($to->{'file'});
1618 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1619 if ($from->{'href'}) {
1620 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1621 'a/' . esc_path
($from->{'file'}));
1622 } else { # file was added (no href)
1623 $line .= 'a/' . esc_path
($from->{'file'});
1626 if ($to->{'href'}) {
1627 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1628 'b/' . esc_path
($to->{'file'}));
1629 } else { # file was deleted
1630 $line .= 'b/' . esc_path
($to->{'file'});
1634 return "<div class=\"diff header\">$line</div>\n";
1637 # format extended diff header line, before patch itself
1638 sub format_extended_diff_header_line
{
1640 my $diffinfo = shift;
1641 my ($from, $to) = @_;
1644 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1645 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1646 esc_path
($from->{'file'}));
1648 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1649 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1650 esc_path
($to->{'file'}));
1652 # match single <mode>
1653 if ($line =~ m/\s(\d{6})$/) {
1654 $line .= '<span class="info"> (' .
1655 file_type_long
($1) .
1659 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1660 # can match only for combined diff
1662 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1663 if ($from->{'href'}[$i]) {
1664 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1666 substr($diffinfo->{'from_id'}[$i],0,7));
1671 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1674 if ($to->{'href'}) {
1675 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1676 substr($diffinfo->{'to_id'},0,7));
1681 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1682 # can match only for ordinary diff
1683 my ($from_link, $to_link);
1684 if ($from->{'href'}) {
1685 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1686 substr($diffinfo->{'from_id'},0,7));
1688 $from_link = '0' x
7;
1690 if ($to->{'href'}) {
1691 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1692 substr($diffinfo->{'to_id'},0,7));
1696 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1697 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1700 return $line . "<br/>\n";
1703 # format from-file/to-file diff header
1704 sub format_diff_from_to_header
{
1705 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1710 #assert($line =~ m/^---/) if DEBUG;
1711 # no extra formatting for "^--- /dev/null"
1712 if (! $diffinfo->{'nparents'}) {
1713 # ordinary (single parent) diff
1714 if ($line =~ m!^--- "?a/!) {
1715 if ($from->{'href'}) {
1717 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1718 esc_path
($from->{'file'}));
1721 esc_path
($from->{'file'});
1724 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1727 # combined diff (merge commit)
1728 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1729 if ($from->{'href'}[$i]) {
1731 $cgi->a({-href
=>href
(action
=>"blobdiff",
1732 hash_parent
=>$diffinfo->{'from_id'}[$i],
1733 hash_parent_base
=>$parents[$i],
1734 file_parent
=>$from->{'file'}[$i],
1735 hash
=>$diffinfo->{'to_id'},
1737 file_name
=>$to->{'file'}),
1739 -title
=>"diff" . ($i+1)},
1742 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1743 esc_path
($from->{'file'}[$i]));
1745 $line = '--- /dev/null';
1747 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1752 #assert($line =~ m/^\+\+\+/) if DEBUG;
1753 # no extra formatting for "^+++ /dev/null"
1754 if ($line =~ m!^\+\+\+ "?b/!) {
1755 if ($to->{'href'}) {
1757 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1758 esc_path
($to->{'file'}));
1761 esc_path
($to->{'file'});
1764 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1769 # create note for patch simplified by combined diff
1770 sub format_diff_cc_simplified
{
1771 my ($diffinfo, @parents) = @_;
1774 $result .= "<div class=\"diff header\">" .
1776 if (!is_deleted
($diffinfo)) {
1777 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1779 hash
=>$diffinfo->{'to_id'},
1780 file_name
=>$diffinfo->{'to_file'}),
1782 esc_path
($diffinfo->{'to_file'}));
1784 $result .= esc_path
($diffinfo->{'to_file'});
1786 $result .= "</div>\n" . # class="diff header"
1787 "<div class=\"diff nodifferences\">" .
1789 "</div>\n"; # class="diff nodifferences"
1794 # format patch (diff) line (not to be used for diff headers)
1795 sub format_diff_line
{
1797 my ($from, $to) = @_;
1798 my $diff_class = "";
1802 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1804 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1805 if ($line =~ m/^\@{3}/) {
1806 $diff_class = " chunk_header";
1807 } elsif ($line =~ m/^\\/) {
1808 $diff_class = " incomplete";
1809 } elsif ($prefix =~ tr/+/+/) {
1810 $diff_class = " add";
1811 } elsif ($prefix =~ tr/-/-/) {
1812 $diff_class = " rem";
1815 # assume ordinary diff
1816 my $char = substr($line, 0, 1);
1818 $diff_class = " add";
1819 } elsif ($char eq '-') {
1820 $diff_class = " rem";
1821 } elsif ($char eq '@') {
1822 $diff_class = " chunk_header";
1823 } elsif ($char eq "\\") {
1824 $diff_class = " incomplete";
1827 $line = untabify
($line);
1828 if ($from && $to && $line =~ m/^\@{2} /) {
1829 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1830 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1832 $from_lines = 0 unless defined $from_lines;
1833 $to_lines = 0 unless defined $to_lines;
1835 if ($from->{'href'}) {
1836 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1837 -class=>"list"}, $from_text);
1839 if ($to->{'href'}) {
1840 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1841 -class=>"list"}, $to_text);
1843 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1844 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1845 return "<div class=\"diff$diff_class\">$line</div>\n";
1846 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1847 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1848 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1850 @from_text = split(' ', $ranges);
1851 for (my $i = 0; $i < @from_text; ++$i) {
1852 ($from_start[$i], $from_nlines[$i]) =
1853 (split(',', substr($from_text[$i], 1)), 0);
1856 $to_text = pop @from_text;
1857 $to_start = pop @from_start;
1858 $to_nlines = pop @from_nlines;
1860 $line = "<span class=\"chunk_info\">$prefix ";
1861 for (my $i = 0; $i < @from_text; ++$i) {
1862 if ($from->{'href'}[$i]) {
1863 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1864 -class=>"list"}, $from_text[$i]);
1866 $line .= $from_text[$i];
1870 if ($to->{'href'}) {
1871 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1872 -class=>"list"}, $to_text);
1876 $line .= " $prefix</span>" .
1877 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1878 return "<div class=\"diff$diff_class\">$line</div>\n";
1880 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1883 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1884 # linked. Pass the hash of the tree/commit to snapshot.
1885 sub format_snapshot_links
{
1887 my $num_fmts = @snapshot_fmts;
1888 if ($num_fmts > 1) {
1889 # A parenthesized list of links bearing format names.
1890 # e.g. "snapshot (_tar.gz_ _zip_)"
1891 return "snapshot (" . join(' ', map
1898 }, $known_snapshot_formats{$_}{'display'})
1899 , @snapshot_fmts) . ")";
1900 } elsif ($num_fmts == 1) {
1901 # A single "snapshot" link whose tooltip bears the format name.
1903 my ($fmt) = @snapshot_fmts;
1909 snapshot_format
=>$fmt
1911 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1913 } else { # $num_fmts == 0
1918 ## ......................................................................
1919 ## functions returning values to be passed, perhaps after some
1920 ## transformation, to other functions; e.g. returning arguments to href()
1922 # returns hash to be passed to href to generate gitweb URL
1923 # in -title key it returns description of link
1925 my $format = shift || 'Atom';
1926 my %res = (action
=> lc($format));
1928 # feed links are possible only for project views
1929 return unless (defined $project);
1930 # some views should link to OPML, or to generic project feed,
1931 # or don't have specific feed yet (so they should use generic)
1932 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1935 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1936 # from tag links; this also makes possible to detect branch links
1937 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1938 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1941 # find log type for feed description (title)
1943 if (defined $file_name) {
1944 $type = "history of $file_name";
1945 $type .= "/" if ($action eq 'tree');
1946 $type .= " on '$branch'" if (defined $branch);
1948 $type = "log of $branch" if (defined $branch);
1951 $res{-title
} = $type;
1952 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1953 $res{'file_name'} = $file_name;
1958 ## ----------------------------------------------------------------------
1959 ## git utility subroutines, invoking git commands
1961 # returns path to the core git executable and the --git-dir parameter as list
1963 return $GIT, '--git-dir='.$git_dir;
1966 # quote the given arguments for passing them to the shell
1967 # quote_command("command", "arg 1", "arg with ' and ! characters")
1968 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1969 # Try to avoid using this function wherever possible.
1972 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1975 # get HEAD ref of given project as hash
1976 sub git_get_head_hash
{
1977 my $project = shift;
1978 my $o_git_dir = $git_dir;
1980 $git_dir = "$projectroot/$project";
1981 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1984 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1988 if (defined $o_git_dir) {
1989 $git_dir = $o_git_dir;
1994 # get type of given object
1998 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2000 close $fd or return;
2005 # repository configuration
2006 our $config_file = '';
2009 # store multiple values for single key as anonymous array reference
2010 # single values stored directly in the hash, not as [ <value> ]
2011 sub hash_set_multi
{
2012 my ($hash, $key, $value) = @_;
2014 if (!exists $hash->{$key}) {
2015 $hash->{$key} = $value;
2016 } elsif (!ref $hash->{$key}) {
2017 $hash->{$key} = [ $hash->{$key}, $value ];
2019 push @
{$hash->{$key}}, $value;
2023 # return hash of git project configuration
2024 # optionally limited to some section, e.g. 'gitweb'
2025 sub git_parse_project_config
{
2026 my $section_regexp = shift;
2031 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2034 while (my $keyval = <$fh>) {
2036 my ($key, $value) = split(/\n/, $keyval, 2);
2038 hash_set_multi
(\
%config, $key, $value)
2039 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2046 # convert config value to boolean: 'true' or 'false'
2047 # no value, number > 0, 'true' and 'yes' values are true
2048 # rest of values are treated as false (never as error)
2049 sub config_to_bool
{
2052 return 1 if !defined $val; # section.key
2054 # strip leading and trailing whitespace
2058 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2059 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2062 # convert config value to simple decimal number
2063 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2064 # to be multiplied by 1024, 1048576, or 1073741824
2068 # strip leading and trailing whitespace
2072 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2074 # unknown unit is treated as 1
2075 return $num * ($unit eq 'g' ?
1073741824 :
2076 $unit eq 'm' ?
1048576 :
2077 $unit eq 'k' ?
1024 : 1);
2082 # convert config value to array reference, if needed
2083 sub config_to_multi
{
2086 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2089 sub git_get_project_config
{
2090 my ($key, $type) = @_;
2093 return unless ($key);
2094 $key =~ s/^gitweb\.//;
2095 return if ($key =~ m/\W/);
2098 if (defined $type) {
2101 unless ($type eq 'bool' || $type eq 'int');
2105 if (!defined $config_file ||
2106 $config_file ne "$git_dir/config") {
2107 %config = git_parse_project_config
('gitweb');
2108 $config_file = "$git_dir/config";
2111 # check if config variable (key) exists
2112 return unless exists $config{"gitweb.$key"};
2115 if (!defined $type) {
2116 return $config{"gitweb.$key"};
2117 } elsif ($type eq 'bool') {
2118 # backward compatibility: 'git config --bool' returns true/false
2119 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2120 } elsif ($type eq 'int') {
2121 return config_to_int
($config{"gitweb.$key"});
2123 return $config{"gitweb.$key"};
2126 # get hash of given path at given ref
2127 sub git_get_hash_by_path
{
2129 my $path = shift || return undef;
2134 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2135 or die_error
(500, "Open git-ls-tree failed");
2137 close $fd or return undef;
2139 if (!defined $line) {
2140 # there is no tree or hash given by $path at $base
2144 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2145 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2146 if (defined $type && $type ne $2) {
2147 # type doesn't match
2153 # get path of entry with given hash at given tree-ish (ref)
2154 # used to get 'from' filename for combined diff (merge commit) for renames
2155 sub git_get_path_by_hash
{
2156 my $base = shift || return;
2157 my $hash = shift || return;
2161 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2163 while (my $line = <$fd>) {
2166 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2167 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2168 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2177 ## ......................................................................
2178 ## git utility functions, directly accessing git repository
2180 sub git_get_project_description
{
2183 $git_dir = "$projectroot/$path";
2184 open my $fd, '<', "$git_dir/description"
2185 or return git_get_project_config
('description');
2188 if (defined $descr) {
2194 sub git_get_project_ctags
{
2198 $git_dir = "$projectroot/$path";
2199 opendir my $dh, "$git_dir/ctags"
2201 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2202 open my $ct, '<', $_ or next;
2206 my $ctag = $_; $ctag =~ s
#.*/##;
2207 $ctags->{$ctag} = $val;
2213 sub git_populate_project_tagcloud
{
2216 # First, merge different-cased tags; tags vote on casing
2218 foreach (keys %$ctags) {
2219 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2220 if (not $ctags_lc{lc $_}->{topcount
}
2221 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2222 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2223 $ctags_lc{lc $_}->{topname
} = $_;
2228 if (eval { require HTML
::TagCloud
; 1; }) {
2229 $cloud = HTML
::TagCloud
->new;
2230 foreach (sort keys %ctags_lc) {
2231 # Pad the title with spaces so that the cloud looks
2233 my $title = $ctags_lc{$_}->{topname
};
2234 $title =~ s/ / /g;
2235 $title =~ s/^/ /g;
2236 $title =~ s/$/ /g;
2237 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2240 $cloud = \
%ctags_lc;
2245 sub git_show_project_tagcloud
{
2246 my ($cloud, $count) = @_;
2247 print STDERR
ref($cloud)."..\n";
2248 if (ref $cloud eq 'HTML::TagCloud') {
2249 return $cloud->html_and_css($count);
2251 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2252 return '<p align="center">' . join (', ', map {
2253 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2254 } splice(@tags, 0, $count)) . '</p>';
2258 sub git_get_project_url_list
{
2261 $git_dir = "$projectroot/$path";
2262 open my $fd, '<', "$git_dir/cloneurl"
2263 or return wantarray ?
2264 @
{ config_to_multi
(git_get_project_config
('url')) } :
2265 config_to_multi
(git_get_project_config
('url'));
2266 my @git_project_url_list = map { chomp; $_ } <$fd>;
2269 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2272 sub git_get_projects_list
{
2277 $filter =~ s/\.git$//;
2279 my $check_forks = gitweb_check_feature
('forks');
2281 if (-d
$projects_list) {
2282 # search in directory
2283 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2284 # remove the trailing "/"
2286 my $pfxlen = length("$dir");
2287 my $pfxdepth = ($dir =~ tr!/!!);
2290 follow_fast
=> 1, # follow symbolic links
2291 follow_skip
=> 2, # ignore duplicates
2292 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2294 # skip project-list toplevel, if we get it.
2295 return if (m!^[/.]$!);
2296 # only directories can be git repositories
2297 return unless (-d
$_);
2298 # don't traverse too deep (Find is super slow on os x)
2299 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2300 $File::Find
::prune
= 1;
2304 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2305 # we check related file in $projectroot
2306 my $path = ($filter ?
"$filter/" : '') . $subdir;
2307 if (check_export_ok
("$projectroot/$path")) {
2308 push @list, { path
=> $path };
2309 $File::Find
::prune
= 1;
2314 } elsif (-f
$projects_list) {
2315 # read from file(url-encoded):
2316 # 'git%2Fgit.git Linus+Torvalds'
2317 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2318 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2320 open my $fd, '<', $projects_list or return;
2322 while (my $line = <$fd>) {
2324 my ($path, $owner) = split ' ', $line;
2325 $path = unescape
($path);
2326 $owner = unescape
($owner);
2327 if (!defined $path) {
2330 if ($filter ne '') {
2331 # looking for forks;
2332 my $pfx = substr($path, 0, length($filter));
2333 if ($pfx ne $filter) {
2336 my $sfx = substr($path, length($filter));
2337 if ($sfx !~ /^\/.*\
.git
$/) {
2340 } elsif ($check_forks) {
2342 foreach my $filter (keys %paths) {
2343 # looking for forks;
2344 my $pfx = substr($path, 0, length($filter));
2345 if ($pfx ne $filter) {
2348 my $sfx = substr($path, length($filter));
2349 if ($sfx !~ /^\/.*\
.git
$/) {
2352 # is a fork, don't include it in
2357 if (check_export_ok
("$projectroot/$path")) {
2360 owner
=> to_utf8
($owner),
2363 (my $forks_path = $path) =~ s/\.git$//;
2364 $paths{$forks_path}++;
2372 our $gitweb_project_owner = undef;
2373 sub git_get_project_list_from_file
{
2375 return if (defined $gitweb_project_owner);
2377 $gitweb_project_owner = {};
2378 # read from file (url-encoded):
2379 # 'git%2Fgit.git Linus+Torvalds'
2380 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2381 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2382 if (-f
$projects_list) {
2383 open(my $fd, '<', $projects_list);
2384 while (my $line = <$fd>) {
2386 my ($pr, $ow) = split ' ', $line;
2387 $pr = unescape
($pr);
2388 $ow = unescape
($ow);
2389 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2395 sub git_get_project_owner
{
2396 my $project = shift;
2399 return undef unless $project;
2400 $git_dir = "$projectroot/$project";
2402 if (!defined $gitweb_project_owner) {
2403 git_get_project_list_from_file
();
2406 if (exists $gitweb_project_owner->{$project}) {
2407 $owner = $gitweb_project_owner->{$project};
2409 if (!defined $owner){
2410 $owner = git_get_project_config
('owner');
2412 if (!defined $owner) {
2413 $owner = get_file_owner
("$git_dir");
2419 sub git_get_last_activity
{
2423 $git_dir = "$projectroot/$path";
2424 open($fd, "-|", git_cmd
(), 'for-each-ref',
2425 '--format=%(committer)',
2426 '--sort=-committerdate',
2428 'refs/heads') or return;
2429 my $most_recent = <$fd>;
2430 close $fd or return;
2431 if (defined $most_recent &&
2432 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2434 my $age = time - $timestamp;
2435 return ($age, age_string
($age));
2437 return (undef, undef);
2440 sub git_get_references
{
2441 my $type = shift || "";
2443 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2444 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2445 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2446 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2449 while (my $line = <$fd>) {
2451 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2452 if (defined $refs{$1}) {
2453 push @
{$refs{$1}}, $2;
2459 close $fd or return;
2463 sub git_get_rev_name_tags
{
2464 my $hash = shift || return undef;
2466 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2468 my $name_rev = <$fd>;
2471 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2474 # catches also '$hash undefined' output
2479 ## ----------------------------------------------------------------------
2480 ## parse to hash functions
2484 my $tz = shift || "-0000";
2487 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2488 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2489 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2490 $date{'hour'} = $hour;
2491 $date{'minute'} = $min;
2492 $date{'mday'} = $mday;
2493 $date{'day'} = $days[$wday];
2494 $date{'month'} = $months[$mon];
2495 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2496 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2497 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2498 $mday, $months[$mon], $hour ,$min;
2499 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2500 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2502 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2503 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2504 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2505 $date{'hour_local'} = $hour;
2506 $date{'minute_local'} = $min;
2507 $date{'tz_local'} = $tz;
2508 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2509 1900+$year, $mon+1, $mday,
2510 $hour, $min, $sec, $tz);
2519 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2520 $tag{'id'} = $tag_id;
2521 while (my $line = <$fd>) {
2523 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2524 $tag{'object'} = $1;
2525 } elsif ($line =~ m/^type (.+)$/) {
2527 } elsif ($line =~ m/^tag (.+)$/) {
2529 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2530 $tag{'author'} = $1;
2531 $tag{'author_epoch'} = $2;
2532 $tag{'author_tz'} = $3;
2533 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2534 $tag{'author_name'} = $1;
2535 $tag{'author_email'} = $2;
2537 $tag{'author_name'} = $tag{'author'};
2539 } elsif ($line =~ m/--BEGIN/) {
2540 push @comment, $line;
2542 } elsif ($line eq "") {
2546 push @comment, <$fd>;
2547 $tag{'comment'} = \
@comment;
2548 close $fd or return;
2549 if (!defined $tag{'name'}) {
2555 sub parse_commit_text
{
2556 my ($commit_text, $withparents) = @_;
2557 my @commit_lines = split '\n', $commit_text;
2560 pop @commit_lines; # Remove '\0'
2562 if (! @commit_lines) {
2566 my $header = shift @commit_lines;
2567 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2570 ($co{'id'}, my @parents) = split ' ', $header;
2571 while (my $line = shift @commit_lines) {
2572 last if $line eq "\n";
2573 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2575 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2577 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2579 $co{'author_epoch'} = $2;
2580 $co{'author_tz'} = $3;
2581 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2582 $co{'author_name'} = $1;
2583 $co{'author_email'} = $2;
2585 $co{'author_name'} = $co{'author'};
2587 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2588 $co{'committer'} = $1;
2589 $co{'committer_epoch'} = $2;
2590 $co{'committer_tz'} = $3;
2591 $co{'committer_name'} = $co{'committer'};
2592 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2593 $co{'committer_name'} = $1;
2594 $co{'committer_email'} = $2;
2596 $co{'committer_name'} = $co{'committer'};
2600 if (!defined $co{'tree'}) {
2603 $co{'parents'} = \
@parents;
2604 $co{'parent'} = $parents[0];
2606 foreach my $title (@commit_lines) {
2609 $co{'title'} = chop_str
($title, 80, 5);
2610 # remove leading stuff of merges to make the interesting part visible
2611 if (length($title) > 50) {
2612 $title =~ s/^Automatic //;
2613 $title =~ s/^merge (of|with) /Merge ... /i;
2614 if (length($title) > 50) {
2615 $title =~ s/(http|rsync):\/\///;
2617 if (length($title) > 50) {
2618 $title =~ s/(master|www|rsync)\.//;
2620 if (length($title) > 50) {
2621 $title =~ s/kernel.org:?//;
2623 if (length($title) > 50) {
2624 $title =~ s/\/pub\/scm//;
2627 $co{'title_short'} = chop_str
($title, 50, 5);
2631 if (! defined $co{'title'} || $co{'title'} eq "") {
2632 $co{'title'} = $co{'title_short'} = '(no commit message)';
2634 # remove added spaces
2635 foreach my $line (@commit_lines) {
2638 $co{'comment'} = \
@commit_lines;
2640 my $age = time - $co{'committer_epoch'};
2642 $co{'age_string'} = age_string
($age);
2643 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2644 if ($age > 60*60*24*7*2) {
2645 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2646 $co{'age_string_age'} = $co{'age_string'};
2648 $co{'age_string_date'} = $co{'age_string'};
2649 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2655 my ($commit_id) = @_;
2660 open my $fd, "-|", git_cmd
(), "rev-list",
2666 or die_error
(500, "Open git-rev-list failed");
2667 %co = parse_commit_text
(<$fd>, 1);
2674 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2682 open my $fd, "-|", git_cmd
(), "rev-list",
2685 ("--max-count=" . $maxcount),
2686 ("--skip=" . $skip),
2690 ($filename ?
($filename) : ())
2691 or die_error
(500, "Open git-rev-list failed");
2692 while (my $line = <$fd>) {
2693 my %co = parse_commit_text
($line);
2698 return wantarray ?
@cos : \
@cos;
2701 # parse line of git-diff-tree "raw" output
2702 sub parse_difftree_raw_line
{
2706 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2707 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2708 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2709 $res{'from_mode'} = $1;
2710 $res{'to_mode'} = $2;
2711 $res{'from_id'} = $3;
2713 $res{'status'} = $5;
2714 $res{'similarity'} = $6;
2715 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2716 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2718 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2721 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2722 # combined diff (for merge commit)
2723 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2724 $res{'nparents'} = length($1);
2725 $res{'from_mode'} = [ split(' ', $2) ];
2726 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2727 $res{'from_id'} = [ split(' ', $3) ];
2728 $res{'to_id'} = pop @
{$res{'from_id'}};
2729 $res{'status'} = [ split('', $4) ];
2730 $res{'to_file'} = unquote
($5);
2732 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2733 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2734 $res{'commit'} = $1;
2737 return wantarray ?
%res : \
%res;
2740 # wrapper: return parsed line of git-diff-tree "raw" output
2741 # (the argument might be raw line, or parsed info)
2742 sub parsed_difftree_line
{
2743 my $line_or_ref = shift;
2745 if (ref($line_or_ref) eq "HASH") {
2746 # pre-parsed (or generated by hand)
2747 return $line_or_ref;
2749 return parse_difftree_raw_line
($line_or_ref);
2753 # parse line of git-ls-tree output
2754 sub parse_ls_tree_line
{
2759 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2760 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2768 $res{'name'} = unquote
($4);
2771 return wantarray ?
%res : \
%res;
2774 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2775 sub parse_from_to_diffinfo
{
2776 my ($diffinfo, $from, $to, @parents) = @_;
2778 if ($diffinfo->{'nparents'}) {
2780 $from->{'file'} = [];
2781 $from->{'href'} = [];
2782 fill_from_file_info
($diffinfo, @parents)
2783 unless exists $diffinfo->{'from_file'};
2784 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2785 $from->{'file'}[$i] =
2786 defined $diffinfo->{'from_file'}[$i] ?
2787 $diffinfo->{'from_file'}[$i] :
2788 $diffinfo->{'to_file'};
2789 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2790 $from->{'href'}[$i] = href
(action
=>"blob",
2791 hash_base
=>$parents[$i],
2792 hash
=>$diffinfo->{'from_id'}[$i],
2793 file_name
=>$from->{'file'}[$i]);
2795 $from->{'href'}[$i] = undef;
2799 # ordinary (not combined) diff
2800 $from->{'file'} = $diffinfo->{'from_file'};
2801 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2802 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2803 hash
=>$diffinfo->{'from_id'},
2804 file_name
=>$from->{'file'});
2806 delete $from->{'href'};
2810 $to->{'file'} = $diffinfo->{'to_file'};
2811 if (!is_deleted
($diffinfo)) { # file exists in result
2812 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2813 hash
=>$diffinfo->{'to_id'},
2814 file_name
=>$to->{'file'});
2816 delete $to->{'href'};
2820 ## ......................................................................
2821 ## parse to array of hashes functions
2823 sub git_get_heads_list
{
2827 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2828 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2829 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2832 while (my $line = <$fd>) {
2836 my ($refinfo, $committerinfo) = split(/\0/, $line);
2837 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2838 my ($committer, $epoch, $tz) =
2839 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2840 $ref_item{'fullname'} = $name;
2841 $name =~ s!^refs/heads/!!;
2843 $ref_item{'name'} = $name;
2844 $ref_item{'id'} = $hash;
2845 $ref_item{'title'} = $title || '(no commit message)';
2846 $ref_item{'epoch'} = $epoch;
2848 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2850 $ref_item{'age'} = "unknown";
2853 push @headslist, \
%ref_item;
2857 return wantarray ?
@headslist : \
@headslist;
2860 sub git_get_tags_list
{
2864 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2865 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2866 '--format=%(objectname) %(objecttype) %(refname) '.
2867 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2870 while (my $line = <$fd>) {
2874 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2875 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2876 my ($creator, $epoch, $tz) =
2877 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2878 $ref_item{'fullname'} = $name;
2879 $name =~ s!^refs/tags/!!;
2881 $ref_item{'type'} = $type;
2882 $ref_item{'id'} = $id;
2883 $ref_item{'name'} = $name;
2884 if ($type eq "tag") {
2885 $ref_item{'subject'} = $title;
2886 $ref_item{'reftype'} = $reftype;
2887 $ref_item{'refid'} = $refid;
2889 $ref_item{'reftype'} = $type;
2890 $ref_item{'refid'} = $id;
2893 if ($type eq "tag" || $type eq "commit") {
2894 $ref_item{'epoch'} = $epoch;
2896 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2898 $ref_item{'age'} = "unknown";
2902 push @tagslist, \
%ref_item;
2906 return wantarray ?
@tagslist : \
@tagslist;
2909 ## ----------------------------------------------------------------------
2910 ## filesystem-related functions
2912 sub get_file_owner
{
2915 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2916 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2917 if (!defined $gcos) {
2921 $owner =~ s/[,;].*$//;
2922 return to_utf8
($owner);
2925 # assume that file exists
2927 my $filename = shift;
2929 open my $fd, '<', $filename;
2930 print map { to_utf8
($_) } <$fd>;
2934 ## ......................................................................
2935 ## mimetype related functions
2937 sub mimetype_guess_file
{
2938 my $filename = shift;
2939 my $mimemap = shift;
2940 -r
$mimemap or return undef;
2943 open(my $mh, '<', $mimemap) or return undef;
2945 next if m/^#/; # skip comments
2946 my ($mimetype, $exts) = split(/\t+/);
2947 if (defined $exts) {
2948 my @exts = split(/\s+/, $exts);
2949 foreach my $ext (@exts) {
2950 $mimemap{$ext} = $mimetype;
2956 $filename =~ /\.([^.]*)$/;
2957 return $mimemap{$1};
2960 sub mimetype_guess
{
2961 my $filename = shift;
2963 $filename =~ /\./ or return undef;
2965 if ($mimetypes_file) {
2966 my $file = $mimetypes_file;
2967 if ($file !~ m!^/!) { # if it is relative path
2968 # it is relative to project
2969 $file = "$projectroot/$project/$file";
2971 $mime = mimetype_guess_file
($filename, $file);
2973 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2979 my $filename = shift;
2982 my $mime = mimetype_guess
($filename);
2983 $mime and return $mime;
2987 return $default_blob_plain_mimetype unless $fd;
2990 return 'text/plain';
2991 } elsif (! $filename) {
2992 return 'application/octet-stream';
2993 } elsif ($filename =~ m/\.png$/i) {
2995 } elsif ($filename =~ m/\.gif$/i) {
2997 } elsif ($filename =~ m/\.jpe?g$/i) {
2998 return 'image/jpeg';
3000 return 'application/octet-stream';
3004 sub blob_contenttype
{
3005 my ($fd, $file_name, $type) = @_;
3007 $type ||= blob_mimetype
($fd, $file_name);
3008 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3009 $type .= "; charset=$default_text_plain_charset";
3015 ## ======================================================================
3016 ## functions printing HTML: header, footer, error page
3018 sub git_header_html
{
3019 my $status = shift || "200 OK";
3020 my $expires = shift;
3022 my $title = "$site_name";
3023 if (defined $project) {
3024 $title .= " - " . to_utf8
($project);
3025 if (defined $action) {
3026 $title .= "/$action";
3027 if (defined $file_name) {
3028 $title .= " - " . esc_path
($file_name);
3029 if ($action eq "tree" && $file_name !~ m
|/$|) {
3036 # require explicit support from the UA if we are to send the page as
3037 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3038 # we have to do this because MSIE sometimes globs '*/*', pretending to
3039 # support xhtml+xml but choking when it gets what it asked for.
3040 if (defined $cgi->http('HTTP_ACCEPT') &&
3041 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3042 $cgi->Accept('application/xhtml+xml') != 0) {
3043 $content_type = 'application/xhtml+xml';
3045 $content_type = 'text/html';
3047 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3048 -status
=> $status, -expires
=> $expires);
3049 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3051 <?xml version="1.0" encoding="utf-8"?>
3052 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3053 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3054 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3055 <!-- git core binaries version $git_version -->
3057 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3058 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3059 <meta name="robots" content="index, nofollow"/>
3060 <title>$title</title>
3062 # the stylesheet, favicon etc urls won't work correctly with path_info
3063 # unless we set the appropriate base URL
3064 if ($ENV{'PATH_INFO'}) {
3065 print "<base href=\"".esc_url
($base_url)."\" />\n";
3067 # print out each stylesheet that exist, providing backwards capability
3068 # for those people who defined $stylesheet in a config file
3069 if (defined $stylesheet) {
3070 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3072 foreach my $stylesheet (@stylesheets) {
3073 next unless $stylesheet;
3074 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3077 if (defined $project) {
3078 my %href_params = get_feed_info
();
3079 if (!exists $href_params{'-title'}) {
3080 $href_params{'-title'} = 'log';
3083 foreach my $format qw(RSS Atom) {
3084 my $type = lc($format);
3086 '-rel' => 'alternate',
3087 '-title' => "$project - $href_params{'-title'} - $format feed",
3088 '-type' => "application/$type+xml"
3091 $href_params{'action'} = $type;
3092 $link_attr{'-href'} = href
(%href_params);
3094 "rel=\"$link_attr{'-rel'}\" ".
3095 "title=\"$link_attr{'-title'}\" ".
3096 "href=\"$link_attr{'-href'}\" ".
3097 "type=\"$link_attr{'-type'}\" ".
3100 $href_params{'extra_options'} = '--no-merges';
3101 $link_attr{'-href'} = href
(%href_params);
3102 $link_attr{'-title'} .= ' (no merges)';
3104 "rel=\"$link_attr{'-rel'}\" ".
3105 "title=\"$link_attr{'-title'}\" ".
3106 "href=\"$link_attr{'-href'}\" ".
3107 "type=\"$link_attr{'-type'}\" ".
3112 printf('<link rel="alternate" title="%s projects list" '.
3113 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3114 $site_name, href
(project
=>undef, action
=>"project_index"));
3115 printf('<link rel="alternate" title="%s projects feeds" '.
3116 'href="%s" type="text/x-opml" />'."\n",
3117 $site_name, href
(project
=>undef, action
=>"opml"));
3119 if (defined $favicon) {
3120 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3126 if (-f
$site_header) {
3127 insert_file
($site_header);
3130 print "<div class=\"page_header\">\n" .
3131 $cgi->a({-href
=> esc_url
($logo_url),
3132 -title
=> $logo_label},
3133 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3134 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3135 if (defined $project) {
3136 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3137 if (defined $action) {
3144 my $have_search = gitweb_check_feature
('search');
3145 if (defined $project && $have_search) {
3146 if (!defined $searchtext) {
3150 if (defined $hash_base) {
3151 $search_hash = $hash_base;
3152 } elsif (defined $hash) {
3153 $search_hash = $hash;
3155 $search_hash = "HEAD";
3157 my $action = $my_uri;
3158 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3159 if ($use_pathinfo) {
3160 $action .= "/".esc_url
($project);
3162 print $cgi->startform(-method
=> "get", -action
=> $action) .
3163 "<div class=\"search\">\n" .
3165 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3166 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3167 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3168 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3169 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3170 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3172 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3173 "<span title=\"Extended regular expression\">" .
3174 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3175 -checked
=> $search_use_regexp) .
3178 $cgi->end_form() . "\n";
3182 sub git_footer_html
{
3183 my $feed_class = 'rss_logo';
3185 print "<div class=\"page_footer\">\n";
3186 if (defined $project) {
3187 my $descr = git_get_project_description
($project);
3188 if (defined $descr) {
3189 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3192 my %href_params = get_feed_info
();
3193 if (!%href_params) {
3194 $feed_class .= ' generic';
3196 $href_params{'-title'} ||= 'log';
3198 foreach my $format qw(RSS Atom) {
3199 $href_params{'action'} = lc($format);
3200 print $cgi->a({-href
=> href
(%href_params),
3201 -title
=> "$href_params{'-title'} $format feed",
3202 -class => $feed_class}, $format)."\n";
3206 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3207 -class => $feed_class}, "OPML") . " ";
3208 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3209 -class => $feed_class}, "TXT") . "\n";
3211 print "</div>\n"; # class="page_footer"
3213 if (-f
$site_footer) {
3214 insert_file
($site_footer);
3221 # die_error(<http_status_code>, <error_message>)
3222 # Example: die_error(404, 'Hash not found')
3223 # By convention, use the following status codes (as defined in RFC 2616):
3224 # 400: Invalid or missing CGI parameters, or
3225 # requested object exists but has wrong type.
3226 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3227 # this server or project.
3228 # 404: Requested object/revision/project doesn't exist.
3229 # 500: The server isn't configured properly, or
3230 # an internal error occurred (e.g. failed assertions caused by bugs), or
3231 # an unknown error occurred (e.g. the git binary died unexpectedly).
3233 my $status = shift || 500;
3234 my $error = shift || "Internal server error";
3236 my %http_responses = (400 => '400 Bad Request',
3237 403 => '403 Forbidden',
3238 404 => '404 Not Found',
3239 500 => '500 Internal Server Error');
3240 git_header_html
($http_responses{$status});
3242 <div class="page_body">
3252 ## ----------------------------------------------------------------------
3253 ## functions printing or outputting HTML: navigation
3255 sub git_print_page_nav
{
3256 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3257 $extra = '' if !defined $extra; # pager or formats
3259 my @navs = qw(summary shortlog log commit commitdiff tree);
3261 @navs = grep { $_ ne $suppress } @navs;
3264 my %arg = map { $_ => {action
=>$_} } @navs;
3265 if (defined $head) {
3266 for (qw(commit commitdiff)) {
3267 $arg{$_}{'hash'} = $head;
3269 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3270 for (qw(shortlog log)) {
3271 $arg{$_}{'hash'} = $head;
3276 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3277 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3279 my @actions = gitweb_get_feature
('actions');
3282 'n' => $project, # project name
3283 'f' => $git_dir, # project path within filesystem
3284 'h' => $treehead || '', # current hash ('h' parameter)
3285 'b' => $treebase || '', # hash base ('hb' parameter)
3288 my ($label, $link, $pos) = splice(@actions,0,3);
3290 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3292 $link =~ s/%([%nfhb])/$repl{$1}/g;
3293 $arg{$label}{'_href'} = $link;
3296 print "<div class=\"page_nav\">\n" .
3298 map { $_ eq $current ?
3299 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3301 print "<br/>\n$extra<br/>\n" .
3305 sub format_paging_nav
{
3306 my ($action, $hash, $head, $page, $has_next_link) = @_;
3310 if ($hash ne $head || $page) {
3311 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3313 $paging_nav .= "HEAD";
3317 $paging_nav .= " ⋅ " .
3318 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3319 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3321 $paging_nav .= " ⋅ prev";
3324 if ($has_next_link) {
3325 $paging_nav .= " ⋅ " .
3326 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3327 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3329 $paging_nav .= " ⋅ next";
3335 ## ......................................................................
3336 ## functions printing or outputting HTML: div
3338 sub git_print_header_div
{
3339 my ($action, $title, $hash, $hash_base) = @_;
3342 $args{'action'} = $action;
3343 $args{'hash'} = $hash if $hash;
3344 $args{'hash_base'} = $hash_base if $hash_base;
3346 print "<div class=\"header\">\n" .
3347 $cgi->a({-href
=> href
(%args), -class => "title"},
3348 $title ?
$title : $action) .
3352 sub print_local_time
{
3354 if ($date{'hour_local'} < 6) {
3355 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3356 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3358 printf(" (%02d:%02d %s)",
3359 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3363 # Outputs the author name and date in long form
3364 sub git_print_authorship
{
3367 my $tag = $opts{-tag
} || 'div';
3369 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3370 print "<$tag class=\"author_date\">" .
3371 esc_html
($co->{'author_name'}) .
3373 print_local_time
(%ad) if ($opts{-localtime});
3374 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3378 # Outputs table rows containing the full author or committer information,
3379 # in the format expected for 'commit' view (& similia).
3380 # Parameters are a commit hash reference, followed by the list of people
3381 # to output information for. If the list is empty it defalts to both
3382 # author and committer.
3383 sub git_print_authorship_rows
{
3385 # too bad we can't use @people = @_ || ('author', 'committer')
3387 @people = ('author', 'committer') unless @people;
3388 foreach my $who (@people) {
3389 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3390 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3391 "<td rowspan=\"2\">" .
3392 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3395 "<td></td><td> $wd{'rfc2822'}";
3396 print_local_time
(%wd);
3402 sub git_print_page_path
{
3408 print "<div class=\"page_path\">";
3409 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3410 -title
=> 'tree root'}, to_utf8
("[$project]"));
3412 if (defined $name) {
3413 my @dirname = split '/', $name;
3414 my $basename = pop @dirname;
3417 foreach my $dir (@dirname) {
3418 $fullname .= ($fullname ?
'/' : '') . $dir;
3419 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3421 -title
=> $fullname}, esc_path
($dir));
3424 if (defined $type && $type eq 'blob') {
3425 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3427 -title
=> $name}, esc_path
($basename));
3428 } elsif (defined $type && $type eq 'tree') {
3429 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3431 -title
=> $name}, esc_path
($basename));
3434 print esc_path
($basename);
3437 print "<br/></div>\n";
3444 if ($opts{'-remove_title'}) {
3445 # remove title, i.e. first line of log
3448 # remove leading empty lines
3449 while (defined $log->[0] && $log->[0] eq "") {
3456 foreach my $line (@
$log) {
3457 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3460 if (! $opts{'-remove_signoff'}) {
3461 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3464 # remove signoff lines
3471 # print only one empty line
3472 # do not print empty line after signoff
3474 next if ($empty || $signoff);
3480 print format_log_line_html
($line) . "<br/>\n";
3483 if ($opts{'-final_empty_line'}) {
3484 # end with single empty line
3485 print "<br/>\n" unless $empty;
3489 # return link target (what link points to)
3490 sub git_get_link_target
{
3495 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3499 $link_target = <$fd>;
3504 return $link_target;
3507 # given link target, and the directory (basedir) the link is in,
3508 # return target of link relative to top directory (top tree);
3509 # return undef if it is not possible (including absolute links).
3510 sub normalize_link_target
{
3511 my ($link_target, $basedir) = @_;
3513 # absolute symlinks (beginning with '/') cannot be normalized
3514 return if (substr($link_target, 0, 1) eq '/');
3516 # normalize link target to path from top (root) tree (dir)
3519 $path = $basedir . '/' . $link_target;
3521 # we are in top (root) tree (dir)
3522 $path = $link_target;
3525 # remove //, /./, and /../
3527 foreach my $part (split('/', $path)) {
3528 # discard '.' and ''
3529 next if (!$part || $part eq '.');
3531 if ($part eq '..') {
3535 # link leads outside repository (outside top dir)
3539 push @path_parts, $part;
3542 $path = join('/', @path_parts);
3547 # print tree entry (row of git_tree), but without encompassing <tr> element
3548 sub git_print_tree_entry
{
3549 my ($t, $basedir, $hash_base, $have_blame) = @_;
3552 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3554 # The format of a table row is: mode list link. Where mode is
3555 # the mode of the entry, list is the name of the entry, an href,
3556 # and link is the action links of the entry.
3558 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3559 if ($t->{'type'} eq "blob") {
3560 print "<td class=\"list\">" .
3561 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3562 file_name
=>"$basedir$t->{'name'}", %base_key),
3563 -class => "list"}, esc_path
($t->{'name'}));
3564 if (S_ISLNK
(oct $t->{'mode'})) {
3565 my $link_target = git_get_link_target
($t->{'hash'});
3567 my $norm_target = normalize_link_target
($link_target, $basedir);
3568 if (defined $norm_target) {
3570 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3571 file_name
=>$norm_target),
3572 -title
=> $norm_target}, esc_path
($link_target));
3574 print " -> " . esc_path
($link_target);
3579 print "<td class=\"link\">";
3580 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3581 file_name
=>"$basedir$t->{'name'}", %base_key)},
3585 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3586 file_name
=>"$basedir$t->{'name'}", %base_key)},
3589 if (defined $hash_base) {
3591 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3592 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3596 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3597 file_name
=>"$basedir$t->{'name'}")},
3601 } elsif ($t->{'type'} eq "tree") {
3602 print "<td class=\"list\">";
3603 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3604 file_name
=>"$basedir$t->{'name'}", %base_key)},
3605 esc_path
($t->{'name'}));
3607 print "<td class=\"link\">";
3608 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3609 file_name
=>"$basedir$t->{'name'}", %base_key)},
3611 if (defined $hash_base) {
3613 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3614 file_name
=>"$basedir$t->{'name'}")},
3619 # unknown object: we can only present history for it
3620 # (this includes 'commit' object, i.e. submodule support)
3621 print "<td class=\"list\">" .
3622 esc_path
($t->{'name'}) .
3624 print "<td class=\"link\">";
3625 if (defined $hash_base) {
3626 print $cgi->a({-href
=> href
(action
=>"history",
3627 hash_base
=>$hash_base,
3628 file_name
=>"$basedir$t->{'name'}")},
3635 ## ......................................................................
3636 ## functions printing large fragments of HTML
3638 # get pre-image filenames for merge (combined) diff
3639 sub fill_from_file_info
{
3640 my ($diff, @parents) = @_;
3642 $diff->{'from_file'} = [ ];
3643 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3644 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3645 if ($diff->{'status'}[$i] eq 'R' ||
3646 $diff->{'status'}[$i] eq 'C') {
3647 $diff->{'from_file'}[$i] =
3648 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3655 # is current raw difftree line of file deletion
3657 my $diffinfo = shift;
3659 return $diffinfo->{'to_id'} eq ('0' x
40);
3662 # does patch correspond to [previous] difftree raw line
3663 # $diffinfo - hashref of parsed raw diff format
3664 # $patchinfo - hashref of parsed patch diff format
3665 # (the same keys as in $diffinfo)
3666 sub is_patch_split
{
3667 my ($diffinfo, $patchinfo) = @_;
3669 return defined $diffinfo && defined $patchinfo
3670 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3674 sub git_difftree_body
{
3675 my ($difftree, $hash, @parents) = @_;
3676 my ($parent) = $parents[0];
3677 my $have_blame = gitweb_check_feature
('blame');
3678 print "<div class=\"list_head\">\n";
3679 if ($#{$difftree} > 10) {
3680 print(($#{$difftree} + 1) . " files changed:\n");
3684 print "<table class=\"" .
3685 (@parents > 1 ?
"combined " : "") .
3688 # header only for combined diff in 'commitdiff' view
3689 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3692 print "<thead><tr>\n" .
3693 "<th></th><th></th>\n"; # filename, patchN link
3694 for (my $i = 0; $i < @parents; $i++) {
3695 my $par = $parents[$i];
3697 $cgi->a({-href
=> href
(action
=>"commitdiff",
3698 hash
=>$hash, hash_parent
=>$par),
3699 -title
=> 'commitdiff to parent number ' .
3700 ($i+1) . ': ' . substr($par,0,7)},
3704 print "</tr></thead>\n<tbody>\n";
3709 foreach my $line (@
{$difftree}) {
3710 my $diff = parsed_difftree_line
($line);
3713 print "<tr class=\"dark\">\n";
3715 print "<tr class=\"light\">\n";
3719 if (exists $diff->{'nparents'}) { # combined diff
3721 fill_from_file_info
($diff, @parents)
3722 unless exists $diff->{'from_file'};
3724 if (!is_deleted
($diff)) {
3725 # file exists in the result (child) commit
3727 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3728 file_name
=>$diff->{'to_file'},
3730 -class => "list"}, esc_path
($diff->{'to_file'})) .
3734 esc_path
($diff->{'to_file'}) .
3738 if ($action eq 'commitdiff') {
3741 print "<td class=\"link\">" .
3742 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3747 my $has_history = 0;
3748 my $not_deleted = 0;
3749 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3750 my $hash_parent = $parents[$i];
3751 my $from_hash = $diff->{'from_id'}[$i];
3752 my $from_path = $diff->{'from_file'}[$i];
3753 my $status = $diff->{'status'}[$i];
3755 $has_history ||= ($status ne 'A');
3756 $not_deleted ||= ($status ne 'D');
3758 if ($status eq 'A') {
3759 print "<td class=\"link\" align=\"right\"> | </td>\n";
3760 } elsif ($status eq 'D') {
3761 print "<td class=\"link\">" .
3762 $cgi->a({-href
=> href
(action
=>"blob",
3765 file_name
=>$from_path)},
3769 if ($diff->{'to_id'} eq $from_hash) {
3770 print "<td class=\"link nochange\">";
3772 print "<td class=\"link\">";
3774 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3775 hash
=>$diff->{'to_id'},
3776 hash_parent
=>$from_hash,
3778 hash_parent_base
=>$hash_parent,
3779 file_name
=>$diff->{'to_file'},
3780 file_parent
=>$from_path)},
3786 print "<td class=\"link\">";
3788 print $cgi->a({-href
=> href
(action
=>"blob",
3789 hash
=>$diff->{'to_id'},
3790 file_name
=>$diff->{'to_file'},
3793 print " | " if ($has_history);
3796 print $cgi->a({-href
=> href
(action
=>"history",
3797 file_name
=>$diff->{'to_file'},
3804 next; # instead of 'else' clause, to avoid extra indent
3806 # else ordinary diff
3808 my ($to_mode_oct, $to_mode_str, $to_file_type);
3809 my ($from_mode_oct, $from_mode_str, $from_file_type);
3810 if ($diff->{'to_mode'} ne ('0' x
6)) {
3811 $to_mode_oct = oct $diff->{'to_mode'};
3812 if (S_ISREG
($to_mode_oct)) { # only for regular file
3813 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3815 $to_file_type = file_type
($diff->{'to_mode'});
3817 if ($diff->{'from_mode'} ne ('0' x
6)) {
3818 $from_mode_oct = oct $diff->{'from_mode'};
3819 if (S_ISREG
($to_mode_oct)) { # only for regular file
3820 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3822 $from_file_type = file_type
($diff->{'from_mode'});
3825 if ($diff->{'status'} eq "A") { # created
3826 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3827 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3828 $mode_chng .= "]</span>";
3830 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3831 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3832 -class => "list"}, esc_path
($diff->{'file'}));
3834 print "<td>$mode_chng</td>\n";
3835 print "<td class=\"link\">";
3836 if ($action eq 'commitdiff') {
3839 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3842 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3843 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3847 } elsif ($diff->{'status'} eq "D") { # deleted
3848 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3850 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3851 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3852 -class => "list"}, esc_path
($diff->{'file'}));
3854 print "<td>$mode_chng</td>\n";
3855 print "<td class=\"link\">";
3856 if ($action eq 'commitdiff') {
3859 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3862 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3863 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3866 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3867 file_name
=>$diff->{'file'})},
3870 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3871 file_name
=>$diff->{'file'})},
3875 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3876 my $mode_chnge = "";
3877 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3878 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3879 if ($from_file_type ne $to_file_type) {
3880 $mode_chnge .= " from $from_file_type to $to_file_type";
3882 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3883 if ($from_mode_str && $to_mode_str) {
3884 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3885 } elsif ($to_mode_str) {
3886 $mode_chnge .= " mode: $to_mode_str";
3889 $mode_chnge .= "]</span>\n";
3892 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3893 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3894 -class => "list"}, esc_path
($diff->{'file'}));
3896 print "<td>$mode_chnge</td>\n";
3897 print "<td class=\"link\">";
3898 if ($action eq 'commitdiff') {
3901 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3903 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3904 # "commit" view and modified file (not onlu mode changed)
3905 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3906 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3907 hash_base
=>$hash, hash_parent_base
=>$parent,
3908 file_name
=>$diff->{'file'})},
3912 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3913 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3916 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3917 file_name
=>$diff->{'file'})},
3920 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3921 file_name
=>$diff->{'file'})},
3925 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3926 my %status_name = ('R' => 'moved', 'C' => 'copied');
3927 my $nstatus = $status_name{$diff->{'status'}};
3929 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3930 # mode also for directories, so we cannot use $to_mode_str
3931 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3934 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3935 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3936 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3937 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3938 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3939 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3940 -class => "list"}, esc_path
($diff->{'from_file'})) .
3941 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3942 "<td class=\"link\">";
3943 if ($action eq 'commitdiff') {
3946 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3948 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3949 # "commit" view and modified file (not only pure rename or copy)
3950 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3951 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3952 hash_base
=>$hash, hash_parent_base
=>$parent,
3953 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3957 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3958 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3961 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3962 file_name
=>$diff->{'to_file'})},
3965 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3966 file_name
=>$diff->{'to_file'})},
3970 } # we should not encounter Unmerged (U) or Unknown (X) status
3973 print "</tbody>" if $has_header;
3977 sub git_patchset_body
{
3978 my ($fd, $difftree, $hash, @hash_parents) = @_;
3979 my ($hash_parent) = $hash_parents[0];
3981 my $is_combined = (@hash_parents > 1);
3983 my $patch_number = 0;
3989 print "<div class=\"patchset\">\n";
3991 # skip to first patch
3992 while ($patch_line = <$fd>) {
3995 last if ($patch_line =~ m/^diff /);
3999 while ($patch_line) {
4001 # parse "git diff" header line
4002 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4003 # $1 is from_name, which we do not use
4004 $to_name = unquote
($2);
4005 $to_name =~ s!^b/!!;
4006 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4007 # $1 is 'cc' or 'combined', which we do not use
4008 $to_name = unquote
($2);
4013 # check if current patch belong to current raw line
4014 # and parse raw git-diff line if needed
4015 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4016 # this is continuation of a split patch
4017 print "<div class=\"patch cont\">\n";
4019 # advance raw git-diff output if needed
4020 $patch_idx++ if defined $diffinfo;
4022 # read and prepare patch information
4023 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4025 # compact combined diff output can have some patches skipped
4026 # find which patch (using pathname of result) we are at now;
4028 while ($to_name ne $diffinfo->{'to_file'}) {
4029 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4030 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4031 "</div>\n"; # class="patch"
4036 last if $patch_idx > $#$difftree;
4037 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4041 # modifies %from, %to hashes
4042 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4044 # this is first patch for raw difftree line with $patch_idx index
4045 # we index @$difftree array from 0, but number patches from 1
4046 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4050 #assert($patch_line =~ m/^diff /) if DEBUG;
4051 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4053 # print "git diff" header
4054 print format_git_diff_header_line
($patch_line, $diffinfo,
4057 # print extended diff header
4058 print "<div class=\"diff extended_header\">\n";
4060 while ($patch_line = <$fd>) {
4063 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4065 print format_extended_diff_header_line
($patch_line, $diffinfo,
4068 print "</div>\n"; # class="diff extended_header"
4070 # from-file/to-file diff header
4071 if (! $patch_line) {
4072 print "</div>\n"; # class="patch"
4075 next PATCH
if ($patch_line =~ m/^diff /);
4076 #assert($patch_line =~ m/^---/) if DEBUG;
4078 my $last_patch_line = $patch_line;
4079 $patch_line = <$fd>;
4081 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4083 print format_diff_from_to_header
($last_patch_line, $patch_line,
4084 $diffinfo, \
%from, \
%to,
4089 while ($patch_line = <$fd>) {
4092 next PATCH
if ($patch_line =~ m/^diff /);
4094 print format_diff_line
($patch_line, \
%from, \
%to);
4098 print "</div>\n"; # class="patch"
4101 # for compact combined (--cc) format, with chunk and patch simpliciaction
4102 # patchset might be empty, but there might be unprocessed raw lines
4103 for (++$patch_idx if $patch_number > 0;
4104 $patch_idx < @
$difftree;
4106 # read and prepare patch information
4107 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4109 # generate anchor for "patch" links in difftree / whatchanged part
4110 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4111 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4112 "</div>\n"; # class="patch"
4117 if ($patch_number == 0) {
4118 if (@hash_parents > 1) {
4119 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4121 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4125 print "</div>\n"; # class="patchset"
4128 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4130 # fills project list info (age, description, owner, forks) for each
4131 # project in the list, removing invalid projects from returned list
4132 # NOTE: modifies $projlist, but does not remove entries from it
4133 sub fill_project_list_info
{
4134 my ($projlist, $check_forks) = @_;
4137 my $show_ctags = gitweb_check_feature
('ctags');
4139 foreach my $pr (@
$projlist) {
4140 my (@activity) = git_get_last_activity
($pr->{'path'});
4141 unless (@activity) {
4144 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4145 if (!defined $pr->{'descr'}) {
4146 my $descr = git_get_project_description
($pr->{'path'}) || "";
4147 $descr = to_utf8
($descr);
4148 $pr->{'descr_long'} = $descr;
4149 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4151 if (!defined $pr->{'owner'}) {
4152 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4155 my $pname = $pr->{'path'};
4156 if (($pname =~ s/\.git$//) &&
4157 ($pname !~ /\/$/) &&
4158 (-d
"$projectroot/$pname")) {
4159 $pr->{'forks'} = "-d $projectroot/$pname";
4164 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4165 push @projects, $pr;
4171 # print 'sort by' <th> element, generating 'sort by $name' replay link
4172 # if that order is not selected
4174 my ($name, $order, $header) = @_;
4175 $header ||= ucfirst($name);
4177 if ($order eq $name) {
4178 print "<th>$header</th>\n";
4181 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4182 -class => "header"}, $header) .
4187 sub git_project_list_body
{
4188 # actually uses global variable $project
4189 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4191 my $check_forks = gitweb_check_feature
('forks');
4192 my @projects = fill_project_list_info
($projlist, $check_forks);
4194 $order ||= $default_projects_order;
4195 $from = 0 unless defined $from;
4196 $to = $#projects if (!defined $to || $#projects < $to);
4199 project
=> { key
=> 'path', type
=> 'str' },
4200 descr
=> { key
=> 'descr_long', type
=> 'str' },
4201 owner
=> { key
=> 'owner', type
=> 'str' },
4202 age
=> { key
=> 'age', type
=> 'num' }
4204 my $oi = $order_info{$order};
4205 if ($oi->{'type'} eq 'str') {
4206 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4208 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4211 my $show_ctags = gitweb_check_feature
('ctags');
4214 foreach my $p (@projects) {
4215 foreach my $ct (keys %{$p->{'ctags'}}) {
4216 $ctags{$ct} += $p->{'ctags'}->{$ct};
4219 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4220 print git_show_project_tagcloud
($cloud, 64);
4223 print "<table class=\"project_list\">\n";
4224 unless ($no_header) {
4227 print "<th></th>\n";
4229 print_sort_th
('project', $order, 'Project');
4230 print_sort_th
('descr', $order, 'Description');
4231 print_sort_th
('owner', $order, 'Owner');
4232 print_sort_th
('age', $order, 'Last Change');
4233 print "<th></th>\n" . # for links
4237 my $tagfilter = $cgi->param('by_tag');
4238 for (my $i = $from; $i <= $to; $i++) {
4239 my $pr = $projects[$i];
4241 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4242 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4243 and not $pr->{'descr_long'} =~ /$searchtext/;
4244 # Weed out forks or non-matching entries of search
4246 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4247 $forkbase="^$forkbase" if $forkbase;
4248 next if not $searchtext and not $tagfilter and $show_ctags
4249 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4253 print "<tr class=\"dark\">\n";
4255 print "<tr class=\"light\">\n";
4260 if ($pr->{'forks'}) {
4261 print "<!-- $pr->{'forks'} -->\n";
4262 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4266 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4267 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4268 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4269 -class => "list", -title
=> $pr->{'descr_long'}},
4270 esc_html
($pr->{'descr'})) . "</td>\n" .
4271 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4272 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4273 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4274 "<td class=\"link\">" .
4275 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4276 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4277 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4278 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4279 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4283 if (defined $extra) {
4286 print "<td></td>\n";
4288 print "<td colspan=\"5\">$extra</td>\n" .
4294 sub git_shortlog_body
{
4295 # uses global variable $project
4296 my ($commitlist, $from, $to, $refs, $extra) = @_;
4298 $from = 0 unless defined $from;
4299 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4301 print "<table class=\"shortlog\">\n";
4303 for (my $i = $from; $i <= $to; $i++) {
4304 my %co = %{$commitlist->[$i]};
4305 my $commit = $co{'id'};
4306 my $ref = format_ref_marker
($refs, $commit);
4308 print "<tr class=\"dark\">\n";
4310 print "<tr class=\"light\">\n";
4313 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4314 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4315 format_author_html
('td', \
%co, 10) . "<td>";
4316 print format_subject_html
($co{'title'}, $co{'title_short'},
4317 href
(action
=>"commit", hash
=>$commit), $ref);
4319 "<td class=\"link\">" .
4320 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4321 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4322 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4323 my $snapshot_links = format_snapshot_links
($commit);
4324 if (defined $snapshot_links) {
4325 print " | " . $snapshot_links;
4330 if (defined $extra) {
4332 "<td colspan=\"4\">$extra</td>\n" .
4338 sub git_history_body
{
4339 # Warning: assumes constant type (blob or tree) during history
4340 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4342 $from = 0 unless defined $from;
4343 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4345 print "<table class=\"history\">\n";
4347 for (my $i = $from; $i <= $to; $i++) {
4348 my %co = %{$commitlist->[$i]};
4352 my $commit = $co{'id'};
4354 my $ref = format_ref_marker
($refs, $commit);
4357 print "<tr class=\"dark\">\n";
4359 print "<tr class=\"light\">\n";
4362 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4363 # shortlog: format_author_html('td', \%co, 10)
4364 format_author_html
('td', \
%co, 15, 3) . "<td>";
4365 # originally git_history used chop_str($co{'title'}, 50)
4366 print format_subject_html
($co{'title'}, $co{'title_short'},
4367 href
(action
=>"commit", hash
=>$commit), $ref);
4369 "<td class=\"link\">" .
4370 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4371 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4373 if ($ftype eq 'blob') {
4374 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4375 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4376 if (defined $blob_current && defined $blob_parent &&
4377 $blob_current ne $blob_parent) {
4379 $cgi->a({-href
=> href
(action
=>"blobdiff",
4380 hash
=>$blob_current, hash_parent
=>$blob_parent,
4381 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4382 file_name
=>$file_name)},
4389 if (defined $extra) {
4391 "<td colspan=\"4\">$extra</td>\n" .
4398 # uses global variable $project
4399 my ($taglist, $from, $to, $extra) = @_;
4400 $from = 0 unless defined $from;
4401 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4403 print "<table class=\"tags\">\n";
4405 for (my $i = $from; $i <= $to; $i++) {
4406 my $entry = $taglist->[$i];
4408 my $comment = $tag{'subject'};
4410 if (defined $comment) {
4411 $comment_short = chop_str
($comment, 30, 5);
4414 print "<tr class=\"dark\">\n";
4416 print "<tr class=\"light\">\n";
4419 if (defined $tag{'age'}) {
4420 print "<td><i>$tag{'age'}</i></td>\n";
4422 print "<td></td>\n";
4425 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4426 -class => "list name"}, esc_html
($tag{'name'})) .
4429 if (defined $comment) {
4430 print format_subject_html
($comment, $comment_short,
4431 href
(action
=>"tag", hash
=>$tag{'id'}));
4434 "<td class=\"selflink\">";
4435 if ($tag{'type'} eq "tag") {
4436 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4441 "<td class=\"link\">" . " | " .
4442 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4443 if ($tag{'reftype'} eq "commit") {
4444 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4445 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4446 } elsif ($tag{'reftype'} eq "blob") {
4447 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4452 if (defined $extra) {
4454 "<td colspan=\"5\">$extra</td>\n" .
4460 sub git_heads_body
{
4461 # uses global variable $project
4462 my ($headlist, $head, $from, $to, $extra) = @_;
4463 $from = 0 unless defined $from;
4464 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4466 print "<table class=\"heads\">\n";
4468 for (my $i = $from; $i <= $to; $i++) {
4469 my $entry = $headlist->[$i];
4471 my $curr = $ref{'id'} eq $head;
4473 print "<tr class=\"dark\">\n";
4475 print "<tr class=\"light\">\n";
4478 print "<td><i>$ref{'age'}</i></td>\n" .
4479 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4480 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4481 -class => "list name"},esc_html
($ref{'name'})) .
4483 "<td class=\"link\">" .
4484 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4485 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4486 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4490 if (defined $extra) {
4492 "<td colspan=\"3\">$extra</td>\n" .
4498 sub git_search_grep_body
{
4499 my ($commitlist, $from, $to, $extra) = @_;
4500 $from = 0 unless defined $from;
4501 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4503 print "<table class=\"commit_search\">\n";
4505 for (my $i = $from; $i <= $to; $i++) {
4506 my %co = %{$commitlist->[$i]};
4510 my $commit = $co{'id'};
4512 print "<tr class=\"dark\">\n";
4514 print "<tr class=\"light\">\n";
4517 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4518 format_author_html
('td', \
%co, 15, 5) .
4520 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4521 -class => "list subject"},
4522 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4523 my $comment = $co{'comment'};
4524 foreach my $line (@
$comment) {
4525 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4526 my ($lead, $match, $trail) = ($1, $2, $3);
4527 $match = chop_str
($match, 70, 5, 'center');
4528 my $contextlen = int((80 - length($match))/2);
4529 $contextlen = 30 if ($contextlen > 30);
4530 $lead = chop_str
($lead, $contextlen, 10, 'left');
4531 $trail = chop_str
($trail, $contextlen, 10, 'right');
4533 $lead = esc_html
($lead);
4534 $match = esc_html
($match);
4535 $trail = esc_html
($trail);
4537 print "$lead<span class=\"match\">$match</span>$trail<br />";
4541 "<td class=\"link\">" .
4542 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4544 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4546 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4550 if (defined $extra) {
4552 "<td colspan=\"3\">$extra</td>\n" .
4558 ## ======================================================================
4559 ## ======================================================================
4562 sub git_project_list
{
4563 my $order = $input_params{'order'};
4564 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4565 die_error
(400, "Unknown order parameter");
4568 my @list = git_get_projects_list
();
4570 die_error
(404, "No projects found");
4574 if (-f
$home_text) {
4575 print "<div class=\"index_include\">\n";
4576 insert_file
($home_text);
4579 print $cgi->startform(-method
=> "get") .
4580 "<p class=\"projsearch\">Search:\n" .
4581 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4583 $cgi->end_form() . "\n";
4584 git_project_list_body
(\
@list, $order);
4589 my $order = $input_params{'order'};
4590 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4591 die_error
(400, "Unknown order parameter");
4594 my @list = git_get_projects_list
($project);
4596 die_error
(404, "No forks found");
4600 git_print_page_nav
('','');
4601 git_print_header_div
('summary', "$project forks");
4602 git_project_list_body
(\
@list, $order);
4606 sub git_project_index
{
4607 my @projects = git_get_projects_list
($project);
4610 -type
=> 'text/plain',
4611 -charset
=> 'utf-8',
4612 -content_disposition
=> 'inline; filename="index.aux"');
4614 foreach my $pr (@projects) {
4615 if (!exists $pr->{'owner'}) {
4616 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4619 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4620 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4621 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4622 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4626 print "$path $owner\n";
4631 my $descr = git_get_project_description
($project) || "none";
4632 my %co = parse_commit
("HEAD");
4633 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4634 my $head = $co{'id'};
4636 my $owner = git_get_project_owner
($project);
4638 my $refs = git_get_references
();
4639 # These get_*_list functions return one more to allow us to see if
4640 # there are more ...
4641 my @taglist = git_get_tags_list
(16);
4642 my @headlist = git_get_heads_list
(16);
4644 my $check_forks = gitweb_check_feature
('forks');
4647 @forklist = git_get_projects_list
($project);
4651 git_print_page_nav
('summary','', $head);
4653 print "<div class=\"title\"> </div>\n";
4654 print "<table class=\"projects_list\">\n" .
4655 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4656 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4657 if (defined $cd{'rfc2822'}) {
4658 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4661 # use per project git URL list in $projectroot/$project/cloneurl
4662 # or make project git URL from git base URL and project name
4663 my $url_tag = "URL";
4664 my @url_list = git_get_project_url_list
($project);
4665 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4666 foreach my $git_url (@url_list) {
4667 next unless $git_url;
4668 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4673 my $show_ctags = gitweb_check_feature
('ctags');
4675 my $ctags = git_get_project_ctags
($project);
4676 my $cloud = git_populate_project_tagcloud
($ctags);
4677 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4678 print "</td>\n<td>" unless %$ctags;
4679 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4680 print "</td>\n<td>" if %$ctags;
4681 print git_show_project_tagcloud
($cloud, 48);
4687 # If XSS prevention is on, we don't include README.html.
4688 # TODO: Allow a readme in some safe format.
4689 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4690 print "<div class=\"title\">readme</div>\n" .
4691 "<div class=\"readme\">\n";
4692 insert_file
("$projectroot/$project/README.html");
4693 print "\n</div>\n"; # class="readme"
4696 # we need to request one more than 16 (0..15) to check if
4698 my @commitlist = $head ? parse_commits
($head, 17) : ();
4700 git_print_header_div
('shortlog');
4701 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4702 $#commitlist <= 15 ?
undef :
4703 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4707 git_print_header_div
('tags');
4708 git_tags_body
(\
@taglist, 0, 15,
4709 $#taglist <= 15 ?
undef :
4710 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4714 git_print_header_div
('heads');
4715 git_heads_body
(\
@headlist, $head, 0, 15,
4716 $#headlist <= 15 ?
undef :
4717 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4721 git_print_header_div
('forks');
4722 git_project_list_body
(\
@forklist, 'age', 0, 15,
4723 $#forklist <= 15 ?
undef :
4724 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4732 my $head = git_get_head_hash
($project);
4734 git_print_page_nav
('','', $head,undef,$head);
4735 my %tag = parse_tag
($hash);
4738 die_error
(404, "Unknown tag object");
4741 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4742 print "<div class=\"title_text\">\n" .
4743 "<table class=\"object_header\">\n" .
4745 "<td>object</td>\n" .
4746 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4747 $tag{'object'}) . "</td>\n" .
4748 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4749 $tag{'type'}) . "</td>\n" .
4751 if (defined($tag{'author'})) {
4752 git_print_authorship_rows
(\
%tag, 'author');
4754 print "</table>\n\n" .
4756 print "<div class=\"page_body\">";
4757 my $comment = $tag{'comment'};
4758 foreach my $line (@
$comment) {
4760 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4768 gitweb_check_feature
('blame')
4769 or die_error
(403, "Blame view not allowed");
4772 die_error
(400, "No file name given") unless $file_name;
4773 $hash_base ||= git_get_head_hash
($project);
4774 die_error
(404, "Couldn't find base commit") unless $hash_base;
4775 my %co = parse_commit
($hash_base)
4776 or die_error
(404, "Commit not found");
4778 if (!defined $hash) {
4779 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4780 or die_error
(404, "Error looking up file");
4782 $ftype = git_get_type
($hash);
4783 if ($ftype !~ "blob") {
4784 die_error
(400, "Object is not a blob");
4788 # run git-blame --porcelain
4789 open my $fd, "-|", git_cmd
(), "blame", '-p',
4790 $hash_base, '--', $file_name
4791 or die_error
(500, "Open git-blame failed");
4796 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4799 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4802 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4804 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4805 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4806 git_print_page_path
($file_name, $ftype, $hash_base);
4809 my @rev_color = qw(light2 dark2);
4810 my $num_colors = scalar(@rev_color);
4811 my $current_color = 0;
4815 <div class="page_body">
4816 <table class="blame">
4817 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4820 while (my $line = <$fd>) {
4822 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4823 # no <lines in group> for subsequent lines in group of lines
4824 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4825 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4826 if (!exists $metainfo{$full_rev}) {
4827 $metainfo{$full_rev} = {};
4829 my $meta = $metainfo{$full_rev};
4831 while ($data = <$fd>) {
4833 last if ($data =~ s/^\t//); # contents of line
4834 if ($data =~ /^(\S+) (.*)$/) {
4838 my $short_rev = substr($full_rev, 0, 8);
4839 my $author = $meta->{'author'};
4841 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4842 my $date = $date{'iso-tz'};
4844 $current_color = ($current_color + 1) % $num_colors;
4846 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4848 print "<td class=\"sha1\"";
4849 print " title=\"". esc_html
($author) . ", $date\"";
4850 print " rowspan=\"$group_size\"" if ($group_size > 1);
4852 print $cgi->a({-href
=> href
(action
=>"commit",
4854 file_name
=>$file_name)},
4855 esc_html
($short_rev));
4859 if (!exists $meta->{'parent'}) {
4860 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4861 or die_error
(500, "Open git-rev-parse failed");
4862 $parent_commit = <$dd>;
4864 chomp($parent_commit);
4865 $meta->{'parent'} = $parent_commit;
4867 $parent_commit = $meta->{'parent'};
4869 my $blamed = href
(action
=> 'blame',
4870 file_name
=> $meta->{'filename'},
4871 hash_base
=> $parent_commit);
4872 print "<td class=\"linenr\">";
4873 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4874 -class => "linenr" },
4877 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4883 or print "Reading blob failed\n";
4890 my $head = git_get_head_hash
($project);
4892 git_print_page_nav
('','', $head,undef,$head);
4893 git_print_header_div
('summary', $project);
4895 my @tagslist = git_get_tags_list
();
4897 git_tags_body
(\
@tagslist);
4903 my $head = git_get_head_hash
($project);
4905 git_print_page_nav
('','', $head,undef,$head);
4906 git_print_header_div
('summary', $project);
4908 my @headslist = git_get_heads_list
();
4910 git_heads_body
(\
@headslist, $head);
4915 sub git_blob_plain
{
4919 if (!defined $hash) {
4920 if (defined $file_name) {
4921 my $base = $hash_base || git_get_head_hash
($project);
4922 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4923 or die_error
(404, "Cannot find file");
4925 die_error
(400, "No file name defined");
4927 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4928 # blobs defined by non-textual hash id's can be cached
4932 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4933 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4935 # content-type (can include charset)
4936 $type = blob_contenttype
($fd, $file_name, $type);
4938 # "save as" filename, even when no $file_name is given
4939 my $save_as = "$hash";
4940 if (defined $file_name) {
4941 $save_as = $file_name;
4942 } elsif ($type =~ m/^text\//) {
4946 # With XSS prevention on, blobs of all types except a few known safe
4947 # ones are served with "Content-Disposition: attachment" to make sure
4948 # they don't run in our security domain. For certain image types,
4949 # blob view writes an <img> tag referring to blob_plain view, and we
4950 # want to be sure not to break that by serving the image as an
4951 # attachment (though Firefox 3 doesn't seem to care).
4952 my $sandbox = $prevent_xss &&
4953 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4957 -expires
=> $expires,
4958 -content_disposition
=>
4959 ($sandbox ?
'attachment' : 'inline')
4960 . '; filename="' . $save_as . '"');
4962 binmode STDOUT
, ':raw';
4964 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4971 if (!defined $hash) {
4972 if (defined $file_name) {
4973 my $base = $hash_base || git_get_head_hash
($project);
4974 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4975 or die_error
(404, "Cannot find file");
4977 die_error
(400, "No file name defined");
4979 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4980 # blobs defined by non-textual hash id's can be cached
4984 my $have_blame = gitweb_check_feature
('blame');
4985 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4986 or die_error
(500, "Couldn't cat $file_name, $hash");
4987 my $mimetype = blob_mimetype
($fd, $file_name);
4988 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4990 return git_blob_plain
($mimetype);
4992 # we can have blame only for text/* mimetype
4993 $have_blame &&= ($mimetype =~ m!^text/!);
4995 git_header_html
(undef, $expires);
4996 my $formats_nav = '';
4997 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4998 if (defined $file_name) {
5001 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5006 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5009 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5012 $cgi->a({-href
=> href
(action
=>"blob",
5013 hash_base
=>"HEAD", file_name
=>$file_name)},
5017 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5020 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5021 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5023 print "<div class=\"page_nav\">\n" .
5024 "<br/><br/></div>\n" .
5025 "<div class=\"title\">$hash</div>\n";
5027 git_print_page_path
($file_name, "blob", $hash_base);
5028 print "<div class=\"page_body\">\n";
5029 if ($mimetype =~ m!^image/!) {
5030 print qq!<img type
="$mimetype"!;
5032 print qq! alt
="$file_name" title
="$file_name"!;
5035 href(action=>"blob_plain
", hash=>$hash,
5036 hash_base=>$hash_base, file_name=>$file_name) .
5040 while (my $line = <$fd>) {
5043 $line = untabify
($line);
5044 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5045 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5049 or print "Reading blob failed.\n";
5055 if (!defined $hash_base) {
5056 $hash_base = "HEAD";
5058 if (!defined $hash) {
5059 if (defined $file_name) {
5060 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5065 die_error
(404, "No such tree") unless defined($hash);
5070 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5071 or die_error
(500, "Open git-ls-tree failed");
5072 @entries = map { chomp; $_ } <$fd>;
5074 or die_error
(404, "Reading tree failed");
5077 my $refs = git_get_references
();
5078 my $ref = format_ref_marker
($refs, $hash_base);
5081 my $have_blame = gitweb_check_feature
('blame');
5082 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5084 if (defined $file_name) {
5086 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5088 $cgi->a({-href
=> href
(action
=>"tree",
5089 hash_base
=>"HEAD", file_name
=>$file_name)},
5092 my $snapshot_links = format_snapshot_links
($hash);
5093 if (defined $snapshot_links) {
5094 # FIXME: Should be available when we have no hash base as well.
5095 push @views_nav, $snapshot_links;
5097 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5098 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5101 print "<div class=\"page_nav\">\n";
5102 print "<br/><br/></div>\n";
5103 print "<div class=\"title\">$hash</div>\n";
5105 if (defined $file_name) {
5106 $basedir = $file_name;
5107 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5110 git_print_page_path
($file_name, 'tree', $hash_base);
5112 print "<div class=\"page_body\">\n";
5113 print "<table class=\"tree\">\n";
5115 # '..' (top directory) link if possible
5116 if (defined $hash_base &&
5117 defined $file_name && $file_name =~ m![^/]+$!) {
5119 print "<tr class=\"dark\">\n";
5121 print "<tr class=\"light\">\n";
5125 my $up = $file_name;
5126 $up =~ s!/?[^/]+$!!;
5127 undef $up unless $up;
5128 # based on git_print_tree_entry
5129 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5130 print '<td class="list">';
5131 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5135 print "<td class=\"link\"></td>\n";
5139 foreach my $line (@entries) {
5140 my %t = parse_ls_tree_line
($line, -z
=> 1);
5143 print "<tr class=\"dark\">\n";
5145 print "<tr class=\"light\">\n";
5149 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5153 print "</table>\n" .
5159 my $format = $input_params{'snapshot_format'};
5160 if (!@snapshot_fmts) {
5161 die_error
(403, "Snapshots not allowed");
5163 # default to first supported snapshot format
5164 $format ||= $snapshot_fmts[0];
5165 if ($format !~ m/^[a-z0-9]+$/) {
5166 die_error
(400, "Invalid snapshot format parameter");
5167 } elsif (!exists($known_snapshot_formats{$format})) {
5168 die_error
(400, "Unknown snapshot format");
5169 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5170 die_error
(403, "Unsupported snapshot format");
5171 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5172 die_error
(403, "Snapshot format not allowed");
5175 if (!defined $hash) {
5176 $hash = git_get_head_hash
($project);
5179 my $name = $project;
5180 $name =~ s
,([^/])/*\
.git
$,$1,;
5181 $name = basename
($name);
5182 my $filename = to_utf8
($name);
5183 $name =~ s/\047/\047\\\047\047/g;
5185 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5186 $cmd = quote_command
(
5187 git_cmd
(), 'archive',
5188 "--format=$known_snapshot_formats{$format}{'format'}",
5189 "--prefix=$name/", $hash);
5190 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5191 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5195 -type
=> $known_snapshot_formats{$format}{'type'},
5196 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5197 -status
=> '200 OK');
5199 open my $fd, "-|", $cmd
5200 or die_error
(500, "Execute git-archive failed");
5201 binmode STDOUT
, ':raw';
5203 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5208 my $head = git_get_head_hash
($project);
5209 if (!defined $hash) {
5212 if (!defined $page) {
5215 my $refs = git_get_references
();
5217 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5219 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5221 my ($patch_max) = gitweb_get_feature
('patches');
5223 if ($patch_max < 0 || @commitlist <= $patch_max) {
5224 $paging_nav .= " ⋅ " .
5225 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5231 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5234 my %co = parse_commit
($hash);
5236 git_print_header_div
('summary', $project);
5237 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5239 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5240 for (my $i = 0; $i <= $to; $i++) {
5241 my %co = %{$commitlist[$i]};
5243 my $commit = $co{'id'};
5244 my $ref = format_ref_marker
($refs, $commit);
5245 my %ad = parse_date
($co{'author_epoch'});
5246 git_print_header_div
('commit',
5247 "<span class=\"age\">$co{'age_string'}</span>" .
5248 esc_html
($co{'title'}) . $ref,
5250 print "<div class=\"title_text\">\n" .
5251 "<div class=\"log_link\">\n" .
5252 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5254 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5256 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5259 git_print_authorship
(\
%co, -tag
=> 'span');
5260 print "<br/>\n</div>\n";
5262 print "<div class=\"log_body\">\n";
5263 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5266 if ($#commitlist >= 100) {
5267 print "<div class=\"page_nav\">\n";
5268 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5269 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5276 $hash ||= $hash_base || "HEAD";
5277 my %co = parse_commit
($hash)
5278 or die_error
(404, "Unknown commit object");
5280 my $parent = $co{'parent'};
5281 my $parents = $co{'parents'}; # listref
5283 # we need to prepare $formats_nav before any parameter munging
5285 if (!defined $parent) {
5287 $formats_nav .= '(initial)';
5288 } elsif (@
$parents == 1) {
5289 # single parent commit
5292 $cgi->a({-href
=> href
(action
=>"commit",
5294 esc_html
(substr($parent, 0, 7))) .
5301 $cgi->a({-href
=> href
(action
=>"commit",
5303 esc_html
(substr($_, 0, 7)));
5307 if (gitweb_check_feature
('patches')) {
5308 $formats_nav .= " | " .
5309 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5313 if (!defined $parent) {
5317 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5319 (@
$parents <= 1 ?
$parent : '-c'),
5321 or die_error
(500, "Open git-diff-tree failed");
5322 @difftree = map { chomp; $_ } <$fd>;
5323 close $fd or die_error
(404, "Reading git-diff-tree failed");
5325 # non-textual hash id's can be cached
5327 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5330 my $refs = git_get_references
();
5331 my $ref = format_ref_marker
($refs, $co{'id'});
5333 git_header_html
(undef, $expires);
5334 git_print_page_nav
('commit', '',
5335 $hash, $co{'tree'}, $hash,
5338 if (defined $co{'parent'}) {
5339 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5341 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5343 print "<div class=\"title_text\">\n" .
5344 "<table class=\"object_header\">\n";
5345 git_print_authorship_rows
(\
%co);
5346 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5349 "<td class=\"sha1\">" .
5350 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5351 class => "list"}, $co{'tree'}) .
5353 "<td class=\"link\">" .
5354 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5356 my $snapshot_links = format_snapshot_links
($hash);
5357 if (defined $snapshot_links) {
5358 print " | " . $snapshot_links;
5363 foreach my $par (@
$parents) {
5366 "<td class=\"sha1\">" .
5367 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5368 class => "list"}, $par) .
5370 "<td class=\"link\">" .
5371 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5373 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5380 print "<div class=\"page_body\">\n";
5381 git_print_log
($co{'comment'});
5384 git_difftree_body
(\
@difftree, $hash, @
$parents);
5390 # object is defined by:
5391 # - hash or hash_base alone
5392 # - hash_base and file_name
5395 # - hash or hash_base alone
5396 if ($hash || ($hash_base && !defined $file_name)) {
5397 my $object_id = $hash || $hash_base;
5399 open my $fd, "-|", quote_command
(
5400 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5401 or die_error
(404, "Object does not exist");
5405 or die_error
(404, "Object does not exist");
5407 # - hash_base and file_name
5408 } elsif ($hash_base && defined $file_name) {
5409 $file_name =~ s
,/+$,,;
5411 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5412 or die_error
(404, "Base object does not exist");
5414 # here errors should not hapen
5415 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5416 or die_error
(500, "Open git-ls-tree failed");
5420 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5421 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5422 die_error
(404, "File or directory for given base does not exist");
5427 die_error
(400, "Not enough information to find object");
5430 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5431 hash
=>$hash, hash_base
=>$hash_base,
5432 file_name
=>$file_name),
5433 -status
=> '302 Found');
5437 my $format = shift || 'html';
5444 # preparing $fd and %diffinfo for git_patchset_body
5446 if (defined $hash_base && defined $hash_parent_base) {
5447 if (defined $file_name) {
5449 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5450 $hash_parent_base, $hash_base,
5451 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5452 or die_error
(500, "Open git-diff-tree failed");
5453 @difftree = map { chomp; $_ } <$fd>;
5455 or die_error
(404, "Reading git-diff-tree failed");
5457 or die_error
(404, "Blob diff not found");
5459 } elsif (defined $hash &&
5460 $hash =~ /[0-9a-fA-F]{40}/) {
5461 # try to find filename from $hash
5463 # read filtered raw output
5464 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5465 $hash_parent_base, $hash_base, "--"
5466 or die_error
(500, "Open git-diff-tree failed");
5468 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5470 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5471 map { chomp; $_ } <$fd>;
5473 or die_error
(404, "Reading git-diff-tree failed");
5475 or die_error
(404, "Blob diff not found");
5478 die_error
(400, "Missing one of the blob diff parameters");
5481 if (@difftree > 1) {
5482 die_error
(400, "Ambiguous blob diff specification");
5485 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5486 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5487 $file_name ||= $diffinfo{'to_file'};
5489 $hash_parent ||= $diffinfo{'from_id'};
5490 $hash ||= $diffinfo{'to_id'};
5492 # non-textual hash id's can be cached
5493 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5494 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5499 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5500 '-p', ($format eq 'html' ?
"--full-index" : ()),
5501 $hash_parent_base, $hash_base,
5502 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5503 or die_error
(500, "Open git-diff-tree failed");
5506 # old/legacy style URI -- not generated anymore since 1.4.3.
5508 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5512 if ($format eq 'html') {
5514 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5516 git_header_html
(undef, $expires);
5517 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5518 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5519 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5521 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5522 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5524 if (defined $file_name) {
5525 git_print_page_path
($file_name, "blob", $hash_base);
5527 print "<div class=\"page_path\"></div>\n";
5530 } elsif ($format eq 'plain') {
5532 -type
=> 'text/plain',
5533 -charset
=> 'utf-8',
5534 -expires
=> $expires,
5535 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5537 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5540 die_error
(400, "Unknown blobdiff format");
5544 if ($format eq 'html') {
5545 print "<div class=\"page_body\">\n";
5547 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5550 print "</div>\n"; # class="page_body"
5554 while (my $line = <$fd>) {
5555 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5556 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5560 last if $line =~ m!^\+\+\+!;
5568 sub git_blobdiff_plain
{
5569 git_blobdiff
('plain');
5572 sub git_commitdiff
{
5574 my $format = $params{-format
} || 'html';
5576 my ($patch_max) = gitweb_get_feature
('patches');
5577 if ($format eq 'patch') {
5578 die_error
(403, "Patch view not allowed") unless $patch_max;
5581 $hash ||= $hash_base || "HEAD";
5582 my %co = parse_commit
($hash)
5583 or die_error
(404, "Unknown commit object");
5585 # choose format for commitdiff for merge
5586 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5587 $hash_parent = '--cc';
5589 # we need to prepare $formats_nav before almost any parameter munging
5591 if ($format eq 'html') {
5593 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5596 $formats_nav .= " | " .
5597 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5601 if (defined $hash_parent &&
5602 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5603 # commitdiff with two commits given
5604 my $hash_parent_short = $hash_parent;
5605 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5606 $hash_parent_short = substr($hash_parent, 0, 7);
5610 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5611 if ($co{'parents'}[$i] eq $hash_parent) {
5612 $formats_nav .= ' parent ' . ($i+1);
5616 $formats_nav .= ': ' .
5617 $cgi->a({-href
=> href
(action
=>"commitdiff",
5618 hash
=>$hash_parent)},
5619 esc_html
($hash_parent_short)) .
5621 } elsif (!$co{'parent'}) {
5623 $formats_nav .= ' (initial)';
5624 } elsif (scalar @
{$co{'parents'}} == 1) {
5625 # single parent commit
5628 $cgi->a({-href
=> href
(action
=>"commitdiff",
5629 hash
=>$co{'parent'})},
5630 esc_html
(substr($co{'parent'}, 0, 7))) .
5634 if ($hash_parent eq '--cc') {
5635 $formats_nav .= ' | ' .
5636 $cgi->a({-href
=> href
(action
=>"commitdiff",
5637 hash
=>$hash, hash_parent
=>'-c')},
5639 } else { # $hash_parent eq '-c'
5640 $formats_nav .= ' | ' .
5641 $cgi->a({-href
=> href
(action
=>"commitdiff",
5642 hash
=>$hash, hash_parent
=>'--cc')},
5648 $cgi->a({-href
=> href
(action
=>"commitdiff",
5650 esc_html
(substr($_, 0, 7)));
5651 } @
{$co{'parents'}} ) .
5656 my $hash_parent_param = $hash_parent;
5657 if (!defined $hash_parent_param) {
5658 # --cc for multiple parents, --root for parentless
5659 $hash_parent_param =
5660 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5666 if ($format eq 'html') {
5667 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5668 "--no-commit-id", "--patch-with-raw", "--full-index",
5669 $hash_parent_param, $hash, "--"
5670 or die_error
(500, "Open git-diff-tree failed");
5672 while (my $line = <$fd>) {
5674 # empty line ends raw part of diff-tree output
5676 push @difftree, scalar parse_difftree_raw_line
($line);
5679 } elsif ($format eq 'plain') {
5680 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5681 '-p', $hash_parent_param, $hash, "--"
5682 or die_error
(500, "Open git-diff-tree failed");
5683 } elsif ($format eq 'patch') {
5684 # For commit ranges, we limit the output to the number of
5685 # patches specified in the 'patches' feature.
5686 # For single commits, we limit the output to a single patch,
5687 # diverging from the git-format-patch default.
5688 my @commit_spec = ();
5690 if ($patch_max > 0) {
5691 push @commit_spec, "-$patch_max";
5693 push @commit_spec, '-n', "$hash_parent..$hash";
5695 if ($params{-single
}) {
5696 push @commit_spec, '-1';
5698 if ($patch_max > 0) {
5699 push @commit_spec, "-$patch_max";
5701 push @commit_spec, "-n";
5703 push @commit_spec, '--root', $hash;
5705 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5706 '--stdout', @commit_spec
5707 or die_error
(500, "Open git-format-patch failed");
5709 die_error
(400, "Unknown commitdiff format");
5712 # non-textual hash id's can be cached
5714 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5718 # write commit message
5719 if ($format eq 'html') {
5720 my $refs = git_get_references
();
5721 my $ref = format_ref_marker
($refs, $co{'id'});
5723 git_header_html
(undef, $expires);
5724 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5725 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5726 print "<div class=\"title_text\">\n" .
5727 "<table class=\"object_header\">\n";
5728 git_print_authorship_rows
(\
%co);
5731 print "<div class=\"page_body\">\n";
5732 if (@
{$co{'comment'}} > 1) {
5733 print "<div class=\"log\">\n";
5734 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5735 print "</div>\n"; # class="log"
5738 } elsif ($format eq 'plain') {
5739 my $refs = git_get_references
("tags");
5740 my $tagname = git_get_rev_name_tags
($hash);
5741 my $filename = basename
($project) . "-$hash.patch";
5744 -type
=> 'text/plain',
5745 -charset
=> 'utf-8',
5746 -expires
=> $expires,
5747 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5748 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5749 print "From: " . to_utf8
($co{'author'}) . "\n";
5750 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5751 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5753 print "X-Git-Tag: $tagname\n" if $tagname;
5754 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5756 foreach my $line (@
{$co{'comment'}}) {
5757 print to_utf8
($line) . "\n";
5760 } elsif ($format eq 'patch') {
5761 my $filename = basename
($project) . "-$hash.patch";
5764 -type
=> 'text/plain',
5765 -charset
=> 'utf-8',
5766 -expires
=> $expires,
5767 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5771 if ($format eq 'html') {
5772 my $use_parents = !defined $hash_parent ||
5773 $hash_parent eq '-c' || $hash_parent eq '--cc';
5774 git_difftree_body
(\
@difftree, $hash,
5775 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5778 git_patchset_body
($fd, \
@difftree, $hash,
5779 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5781 print "</div>\n"; # class="page_body"
5784 } elsif ($format eq 'plain') {
5788 or print "Reading git-diff-tree failed\n";
5789 } elsif ($format eq 'patch') {
5793 or print "Reading git-format-patch failed\n";
5797 sub git_commitdiff_plain
{
5798 git_commitdiff
(-format
=> 'plain');
5801 # format-patch-style patches
5803 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5807 git_commitdiff
(-format
=> 'patch');
5811 if (!defined $hash_base) {
5812 $hash_base = git_get_head_hash
($project);
5814 if (!defined $page) {
5818 my %co = parse_commit
($hash_base)
5819 or die_error
(404, "Unknown commit object");
5821 my $refs = git_get_references
();
5822 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5824 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5825 $file_name, "--full-history")
5826 or die_error
(404, "No such file or directory on given branch");
5828 if (!defined $hash && defined $file_name) {
5829 # some commits could have deleted file in question,
5830 # and not have it in tree, but one of them has to have it
5831 for (my $i = 0; $i <= @commitlist; $i++) {
5832 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5833 last if defined $hash;
5836 if (defined $hash) {
5837 $ftype = git_get_type
($hash);
5839 if (!defined $ftype) {
5840 die_error
(500, "Unknown type of object");
5843 my $paging_nav = '';
5846 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5847 file_name
=>$file_name)},
5849 $paging_nav .= " ⋅ " .
5850 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5851 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5853 $paging_nav .= "first";
5854 $paging_nav .= " ⋅ prev";
5857 if ($#commitlist >= 100) {
5859 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5860 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5861 $paging_nav .= " ⋅ $next_link";
5863 $paging_nav .= " ⋅ next";
5867 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5868 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5869 git_print_page_path
($file_name, $ftype, $hash_base);
5871 git_history_body
(\
@commitlist, 0, 99,
5872 $refs, $hash_base, $ftype, $next_link);
5878 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5879 if (!defined $searchtext) {
5880 die_error
(400, "Text field is empty");
5882 if (!defined $hash) {
5883 $hash = git_get_head_hash
($project);
5885 my %co = parse_commit
($hash);
5887 die_error
(404, "Unknown commit object");
5889 if (!defined $page) {
5893 $searchtype ||= 'commit';
5894 if ($searchtype eq 'pickaxe') {
5895 # pickaxe may take all resources of your box and run for several minutes
5896 # with every query - so decide by yourself how public you make this feature
5897 gitweb_check_feature
('pickaxe')
5898 or die_error
(403, "Pickaxe is disabled");
5900 if ($searchtype eq 'grep') {
5901 gitweb_check_feature
('grep')
5902 or die_error
(403, "Grep is disabled");
5907 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5909 if ($searchtype eq 'commit') {
5910 $greptype = "--grep=";
5911 } elsif ($searchtype eq 'author') {
5912 $greptype = "--author=";
5913 } elsif ($searchtype eq 'committer') {
5914 $greptype = "--committer=";
5916 $greptype .= $searchtext;
5917 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5918 $greptype, '--regexp-ignore-case',
5919 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5921 my $paging_nav = '';
5924 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5925 searchtext
=>$searchtext,
5926 searchtype
=>$searchtype)},
5928 $paging_nav .= " ⋅ " .
5929 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5930 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5932 $paging_nav .= "first";
5933 $paging_nav .= " ⋅ prev";
5936 if ($#commitlist >= 100) {
5938 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5939 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5940 $paging_nav .= " ⋅ $next_link";
5942 $paging_nav .= " ⋅ next";
5945 if ($#commitlist >= 100) {
5948 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5949 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5950 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5953 if ($searchtype eq 'pickaxe') {
5954 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5955 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5957 print "<table class=\"pickaxe search\">\n";
5960 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5961 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5962 ($search_use_regexp ?
'--pickaxe-regex' : ());
5965 while (my $line = <$fd>) {
5969 my %set = parse_difftree_raw_line
($line);
5970 if (defined $set{'commit'}) {
5971 # finish previous commit
5974 "<td class=\"link\">" .
5975 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5977 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5983 print "<tr class=\"dark\">\n";
5985 print "<tr class=\"light\">\n";
5988 %co = parse_commit
($set{'commit'});
5989 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5990 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5991 "<td><i>$author</i></td>\n" .
5993 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5994 -class => "list subject"},
5995 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5996 } elsif (defined $set{'to_id'}) {
5997 next if ($set{'to_id'} =~ m/^0{40}$/);
5999 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6000 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6002 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6008 # finish last commit (warning: repetition!)
6011 "<td class=\"link\">" .
6012 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6014 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6022 if ($searchtype eq 'grep') {
6023 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6024 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6026 print "<table class=\"grep_search\">\n";
6030 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6031 $search_use_regexp ?
('-E', '-i') : '-F',
6032 $searchtext, $co{'tree'};
6034 while (my $line = <$fd>) {
6036 my ($file, $lno, $ltext, $binary);
6037 last if ($matches++ > 1000);
6038 if ($line =~ /^Binary file (.+) matches$/) {
6042 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6044 if ($file ne $lastfile) {
6045 $lastfile and print "</td></tr>\n";
6047 print "<tr class=\"dark\">\n";
6049 print "<tr class=\"light\">\n";
6051 print "<td class=\"list\">".
6052 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6053 file_name
=>"$file"),
6054 -class => "list"}, esc_path
($file));
6055 print "</td><td>\n";
6059 print "<div class=\"binary\">Binary file</div>\n";
6061 $ltext = untabify
($ltext);
6062 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6063 $ltext = esc_html
($1, -nbsp
=>1);
6064 $ltext .= '<span class="match">';
6065 $ltext .= esc_html
($2, -nbsp
=>1);
6066 $ltext .= '</span>';
6067 $ltext .= esc_html
($3, -nbsp
=>1);
6069 $ltext = esc_html
($ltext, -nbsp
=>1);
6071 print "<div class=\"pre\">" .
6072 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6073 file_name
=>"$file").'#l'.$lno,
6074 -class => "linenr"}, sprintf('%4i', $lno))
6075 . ' ' . $ltext . "</div>\n";
6079 print "</td></tr>\n";
6080 if ($matches > 1000) {
6081 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6084 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6093 sub git_search_help
{
6095 git_print_page_nav
('','', $hash,$hash,$hash);
6097 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6098 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6099 the pattern entered is recognized as the POSIX extended
6100 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6103 <dt><b>commit</b></dt>
6104 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6106 my $have_grep = gitweb_check_feature
('grep');
6109 <dt><b>grep</b></dt>
6110 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6111 a different one) are searched for the given pattern. On large trees, this search can take
6112 a while and put some strain on the server, so please use it with some consideration. Note that
6113 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6114 case-sensitive.</dd>
6118 <dt><b>author</b></dt>
6119 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6120 <dt><b>committer</b></dt>
6121 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6123 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6124 if ($have_pickaxe) {
6126 <dt><b>pickaxe</b></dt>
6127 <dd>All commits that caused the string to appear or disappear from any file (changes that
6128 added, removed or "modified" the string) will be listed. This search can take a while and
6129 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6130 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6138 my $head = git_get_head_hash
($project);
6139 if (!defined $hash) {
6142 if (!defined $page) {
6145 my $refs = git_get_references
();
6147 my $commit_hash = $hash;
6148 if (defined $hash_parent) {
6149 $commit_hash = "$hash_parent..$hash";
6151 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6153 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6155 if ($#commitlist >= 100) {
6157 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6158 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6160 my $patch_max = gitweb_check_feature
('patches');
6162 if ($patch_max < 0 || @commitlist <= $patch_max) {
6163 $paging_nav .= " ⋅ " .
6164 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6170 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6171 git_print_header_div
('summary', $project);
6173 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6178 ## ......................................................................
6179 ## feeds (RSS, Atom; OPML)
6182 my $format = shift || 'atom';
6183 my $have_blame = gitweb_check_feature
('blame');
6185 # Atom: http://www.atomenabled.org/developers/syndication/
6186 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6187 if ($format ne 'rss' && $format ne 'atom') {
6188 die_error
(400, "Unknown web feed format");
6191 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6192 my $head = $hash || 'HEAD';
6193 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6197 my $content_type = "application/$format+xml";
6198 if (defined $cgi->http('HTTP_ACCEPT') &&
6199 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6200 # browser (feed reader) prefers text/xml
6201 $content_type = 'text/xml';
6203 if (defined($commitlist[0])) {
6204 %latest_commit = %{$commitlist[0]};
6205 my $latest_epoch = $latest_commit{'committer_epoch'};
6206 %latest_date = parse_date
($latest_epoch);
6207 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6208 if (defined $if_modified) {
6210 if (eval { require HTTP
::Date
; 1; }) {
6211 $since = HTTP
::Date
::str2time
($if_modified);
6212 } elsif (eval { require Time
::ParseDate
; 1; }) {
6213 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6215 if (defined $since && $latest_epoch <= $since) {
6217 -type
=> $content_type,
6218 -charset
=> 'utf-8',
6219 -last_modified
=> $latest_date{'rfc2822'},
6220 -status
=> '304 Not Modified');
6225 -type
=> $content_type,
6226 -charset
=> 'utf-8',
6227 -last_modified
=> $latest_date{'rfc2822'});
6230 -type
=> $content_type,
6231 -charset
=> 'utf-8');
6234 # Optimization: skip generating the body if client asks only
6235 # for Last-Modified date.
6236 return if ($cgi->request_method() eq 'HEAD');
6239 my $title = "$site_name - $project/$action";
6240 my $feed_type = 'log';
6241 if (defined $hash) {
6242 $title .= " - '$hash'";
6243 $feed_type = 'branch log';
6244 if (defined $file_name) {
6245 $title .= " :: $file_name";
6246 $feed_type = 'history';
6248 } elsif (defined $file_name) {
6249 $title .= " - $file_name";
6250 $feed_type = 'history';
6252 $title .= " $feed_type";
6253 my $descr = git_get_project_description
($project);
6254 if (defined $descr) {
6255 $descr = esc_html
($descr);
6257 $descr = "$project " .
6258 ($format eq 'rss' ?
'RSS' : 'Atom') .
6261 my $owner = git_get_project_owner
($project);
6262 $owner = esc_html
($owner);
6266 if (defined $file_name) {
6267 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6268 } elsif (defined $hash) {
6269 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6271 $alt_url = href
(-full
=>1, action
=>"summary");
6273 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6274 if ($format eq 'rss') {
6276 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6279 print "<title>$title</title>\n" .
6280 "<link>$alt_url</link>\n" .
6281 "<description>$descr</description>\n" .
6282 "<language>en</language>\n" .
6283 # project owner is responsible for 'editorial' content
6284 "<managingEditor>$owner</managingEditor>\n";
6285 if (defined $logo || defined $favicon) {
6286 # prefer the logo to the favicon, since RSS
6287 # doesn't allow both
6288 my $img = esc_url
($logo || $favicon);
6290 "<url>$img</url>\n" .
6291 "<title>$title</title>\n" .
6292 "<link>$alt_url</link>\n" .
6296 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6297 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6299 print "<generator>gitweb v.$version/$git_version</generator>\n";
6300 } elsif ($format eq 'atom') {
6302 <feed xmlns="http://www.w3.org/2005/Atom">
6304 print "<title>$title</title>\n" .
6305 "<subtitle>$descr</subtitle>\n" .
6306 '<link rel="alternate" type="text/html" href="' .
6307 $alt_url . '" />' . "\n" .
6308 '<link rel="self" type="' . $content_type . '" href="' .
6309 $cgi->self_url() . '" />' . "\n" .
6310 "<id>" . href
(-full
=>1) . "</id>\n" .
6311 # use project owner for feed author
6312 "<author><name>$owner</name></author>\n";
6313 if (defined $favicon) {
6314 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6316 if (defined $logo_url) {
6317 # not twice as wide as tall: 72 x 27 pixels
6318 print "<logo>" . esc_url
($logo) . "</logo>\n";
6320 if (! %latest_date) {
6321 # dummy date to keep the feed valid until commits trickle in:
6322 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6324 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6326 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6330 for (my $i = 0; $i <= $#commitlist; $i++) {
6331 my %co = %{$commitlist[$i]};
6332 my $commit = $co{'id'};
6333 # we read 150, we always show 30 and the ones more recent than 48 hours
6334 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6337 my %cd = parse_date
($co{'author_epoch'});
6339 # get list of changed files
6340 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6341 $co{'parent'} || "--root",
6342 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6344 my @difftree = map { chomp; $_ } <$fd>;
6348 # print element (entry, item)
6349 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6350 if ($format eq 'rss') {
6352 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6353 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6354 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6355 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6356 "<link>$co_url</link>\n" .
6357 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6358 "<content:encoded>" .
6360 } elsif ($format eq 'atom') {
6362 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6363 "<updated>$cd{'iso-8601'}</updated>\n" .
6365 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6366 if ($co{'author_email'}) {
6367 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6369 print "</author>\n" .
6370 # use committer for contributor
6372 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6373 if ($co{'committer_email'}) {
6374 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6376 print "</contributor>\n" .
6377 "<published>$cd{'iso-8601'}</published>\n" .
6378 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6379 "<id>$co_url</id>\n" .
6380 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6381 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6383 my $comment = $co{'comment'};
6385 foreach my $line (@
$comment) {
6386 $line = esc_html
($line);
6389 print "</pre><ul>\n";
6390 foreach my $difftree_line (@difftree) {
6391 my %difftree = parse_difftree_raw_line
($difftree_line);
6392 next if !$difftree{'from_id'};
6394 my $file = $difftree{'file'} || $difftree{'to_file'};
6398 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6399 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6400 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6401 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6402 -title
=> "diff"}, 'D');
6404 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6405 file_name
=>$file, hash_base
=>$commit),
6406 -title
=> "blame"}, 'B');
6408 # if this is not a feed of a file history
6409 if (!defined $file_name || $file_name ne $file) {
6410 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6411 file_name
=>$file, hash
=>$commit),
6412 -title
=> "history"}, 'H');
6414 $file = esc_path
($file);
6418 if ($format eq 'rss') {
6419 print "</ul>]]>\n" .
6420 "</content:encoded>\n" .
6422 } elsif ($format eq 'atom') {
6423 print "</ul>\n</div>\n" .
6430 if ($format eq 'rss') {
6431 print "</channel>\n</rss>\n";
6432 } elsif ($format eq 'atom') {
6446 my @list = git_get_projects_list
();
6449 -type
=> 'text/xml',
6450 -charset
=> 'utf-8',
6451 -content_disposition
=> 'inline; filename="opml.xml"');
6454 <?xml version="1.0" encoding="utf-8"?>
6455 <opml version="1.0">
6457 <title>$site_name OPML Export</title>
6460 <outline text="git RSS feeds">
6463 foreach my $pr (@list) {
6465 my $head = git_get_head_hash
($proj{'path'});
6466 if (!defined $head) {
6469 $git_dir = "$projectroot/$proj{'path'}";
6470 my %co = parse_commit
($head);
6475 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6476 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6477 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6478 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";