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;
90 # URI of GIT logo (72x27 size)
91 our $logo = "++GITWEB_LOGO++";
92 # URI of GIT favicon, assumed to be image/png type
93 our $favicon = "++GITWEB_FAVICON++";
95 # URI and label (title) of GIT logo link
96 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
97 #our $logo_label = "git documentation";
98 our $logo_url = "http://git-scm.com/";
99 our $logo_label = "git homepage";
101 # source of projects list
102 our $projects_list = "++GITWEB_LIST++";
104 # the width (in characters) of the projects list "Description" column
105 our $projects_list_description_width = 25;
107 # default order of projects list
108 # valid values are none, project, descr, owner, and age
109 our $default_projects_order = "project";
111 # show repository only if this file exists
112 # (only effective if this variable evaluates to true)
113 our $export_ok = "++GITWEB_EXPORT_OK++";
115 # show repository only if this subroutine returns true
116 # when given the path to the project, for example:
117 # sub { return -e "$_[0]/git-daemon-export-ok"; }
118 our $export_auth_hook = undef;
120 # only allow viewing of repositories also shown on the overview page
121 our $strict_export = "++GITWEB_STRICT_EXPORT++";
123 # list of git base URLs used for URL to where fetch project from,
124 # i.e. full URL is "$git_base_url/$project"
125 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
127 # default blob_plain mimetype and default charset for text/plain blob
128 our $default_blob_plain_mimetype = 'text/plain';
129 our $default_text_plain_charset = undef;
131 # file to use for guessing MIME types before trying /etc/mime.types
132 # (relative to the current git repository)
133 our $mimetypes_file = undef;
135 # assume this charset if line contains non-UTF-8 characters;
136 # it should be valid encoding (see Encoding::Supported(3pm) for list),
137 # for which encoding all byte sequences are valid, for example
138 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
139 # could be even 'utf-8' for the old behavior)
140 our $fallback_encoding = 'latin1';
142 # rename detection options for git-diff and git-diff-tree
143 # - default is '-M', with the cost proportional to
144 # (number of removed files) * (number of new files).
145 # - more costly is '-C' (which implies '-M'), with the cost proportional to
146 # (number of changed files + number of removed files) * (number of new files)
147 # - even more costly is '-C', '--find-copies-harder' with cost
148 # (number of files in the original tree) * (number of new files)
149 # - one might want to include '-B' option, e.g. '-B', '-M'
150 our @diff_opts = ('-M'); # taken from git_commit
152 # Disables features that would allow repository owners to inject script into
154 our $prevent_xss = 0;
156 # information about snapshot formats that gitweb is capable of serving
157 our %known_snapshot_formats = (
159 # 'display' => display name,
160 # 'type' => mime type,
161 # 'suffix' => filename suffix,
162 # 'format' => --format for git-archive,
163 # 'compressor' => [compressor command and arguments]
164 # (array reference, optional)
165 # 'disabled' => boolean (optional)}
168 'display' => 'tar.gz',
169 'type' => 'application/x-gzip',
170 'suffix' => '.tar.gz',
172 'compressor' => ['gzip']},
175 'display' => 'tar.bz2',
176 'type' => 'application/x-bzip2',
177 'suffix' => '.tar.bz2',
179 'compressor' => ['bzip2']},
183 'type' => 'application/x-zip',
188 # Aliases so we understand old gitweb.snapshot values in repository
190 our %known_snapshot_format_aliases = (
194 # backward compatibility: legacy gitweb config support
195 'x-gzip' => undef, 'gz' => undef,
196 'x-bzip2' => undef, 'bz2' => undef,
197 'x-zip' => undef, '' => undef,
200 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
201 # are changed, it may be appropriate to change these values too via
208 # You define site-wide feature defaults here; override them with
209 # $GITWEB_CONFIG as necessary.
212 # 'sub' => feature-sub (subroutine),
213 # 'override' => allow-override (boolean),
214 # 'default' => [ default options...] (array reference)}
216 # if feature is overridable (it means that allow-override has true value),
217 # then feature-sub will be called with default options as parameters;
218 # return value of feature-sub indicates if to enable specified feature
220 # if there is no 'sub' key (no feature-sub), then feature cannot be
223 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
224 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
227 # Enable the 'blame' blob view, showing the last commit that modified
228 # each line in the file. This can be very CPU-intensive.
230 # To enable system wide have in $GITWEB_CONFIG
231 # $feature{'blame'}{'default'} = [1];
232 # To have project specific config enable override in $GITWEB_CONFIG
233 # $feature{'blame'}{'override'} = 1;
234 # and in project config gitweb.blame = 0|1;
236 'sub' => sub { feature_bool
('blame', @_) },
240 # Enable the 'snapshot' link, providing a compressed archive of any
241 # tree. This can potentially generate high traffic if you have large
244 # Value is a list of formats defined in %known_snapshot_formats that
246 # To disable system wide have in $GITWEB_CONFIG
247 # $feature{'snapshot'}{'default'} = [];
248 # To have project specific config enable override in $GITWEB_CONFIG
249 # $feature{'snapshot'}{'override'} = 1;
250 # and in project config, a comma-separated list of formats or "none"
251 # to disable. Example: gitweb.snapshot = tbz2,zip;
253 'sub' => \
&feature_snapshot
,
255 'default' => ['tgz']},
257 # Enable text search, which will list the commits which match author,
258 # committer or commit text to a given string. Enabled by default.
259 # Project specific override is not supported.
264 # Enable grep search, which will list the files in currently selected
265 # tree containing the given string. Enabled by default. This can be
266 # potentially CPU-intensive, of course.
268 # To enable system wide have in $GITWEB_CONFIG
269 # $feature{'grep'}{'default'} = [1];
270 # To have project specific config enable override in $GITWEB_CONFIG
271 # $feature{'grep'}{'override'} = 1;
272 # and in project config gitweb.grep = 0|1;
274 'sub' => sub { feature_bool
('grep', @_) },
278 # Enable the pickaxe search, which will list the commits that modified
279 # a given string in a file. This can be practical and quite faster
280 # alternative to 'blame', but still potentially CPU-intensive.
282 # To enable system wide have in $GITWEB_CONFIG
283 # $feature{'pickaxe'}{'default'} = [1];
284 # To have project specific config enable override in $GITWEB_CONFIG
285 # $feature{'pickaxe'}{'override'} = 1;
286 # and in project config gitweb.pickaxe = 0|1;
288 'sub' => sub { feature_bool
('pickaxe', @_) },
292 # Make gitweb use an alternative format of the URLs which can be
293 # more readable and natural-looking: project name is embedded
294 # directly in the path and the query string contains other
295 # auxiliary information. All gitweb installations recognize
296 # URL in either format; this configures in which formats gitweb
299 # To enable system wide have in $GITWEB_CONFIG
300 # $feature{'pathinfo'}{'default'} = [1];
301 # Project specific override is not supported.
303 # Note that you will need to change the default location of CSS,
304 # favicon, logo and possibly other files to an absolute URL. Also,
305 # if gitweb.cgi serves as your indexfile, you will need to force
306 # $my_uri to contain the script name in your $GITWEB_CONFIG.
311 # Make gitweb consider projects in project root subdirectories
312 # to be forks of existing projects. Given project $projname.git,
313 # projects matching $projname/*.git will not be shown in the main
314 # projects list, instead a '+' mark will be added to $projname
315 # there and a 'forks' view will be enabled for the project, listing
316 # all the forks. If project list is taken from a file, forks have
317 # to be listed after the main project.
319 # To enable system wide have in $GITWEB_CONFIG
320 # $feature{'forks'}{'default'} = [1];
321 # Project specific override is not supported.
326 # Insert custom links to the action bar of all project pages.
327 # This enables you mainly to link to third-party scripts integrating
328 # into gitweb; e.g. git-browser for graphical history representation
329 # or custom web-based repository administration interface.
331 # The 'default' value consists of a list of triplets in the form
332 # (label, link, position) where position is the label after which
333 # to insert the link and link is a format string where %n expands
334 # to the project name, %f to the project path within the filesystem,
335 # %h to the current hash (h gitweb parameter) and %b to the current
336 # hash base (hb gitweb parameter); %% expands to %.
338 # To enable system wide have in $GITWEB_CONFIG e.g.
339 # $feature{'actions'}{'default'} = [('graphiclog',
340 # '/git-browser/by-commit.html?r=%n', 'summary')];
341 # Project specific override is not supported.
346 # Allow gitweb scan project content tags described in ctags/
347 # of project repository, and display the popular Web 2.0-ish
348 # "tag cloud" near the project list. Note that this is something
349 # COMPLETELY different from the normal Git tags.
351 # gitweb by itself can show existing tags, but it does not handle
352 # tagging itself; you need an external application for that.
353 # For an example script, check Girocco's cgi/tagproj.cgi.
354 # You may want to install the HTML::TagCloud Perl module to get
355 # a pretty tag cloud instead of just a list of tags.
357 # To enable system wide have in $GITWEB_CONFIG
358 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
359 # Project specific override is not supported.
364 # The maximum number of patches in a patchset generated in patch
365 # view. Set this to 0 or undef to disable patch view, or to a
366 # negative number to remove any limit.
368 # To disable system wide have in $GITWEB_CONFIG
369 # $feature{'patches'}{'default'} = [0];
370 # To have project specific config enable override in $GITWEB_CONFIG
371 # $feature{'patches'}{'override'} = 1;
372 # and in project config gitweb.patches = 0|n;
373 # where n is the maximum number of patches allowed in a patchset.
375 'sub' => \
&feature_patches
,
379 # Avatar support. When this feature is enabled, views such as
380 # shortlog or commit will display an avatar associated with
381 # the email of the committer(s) and/or author(s).
383 # Currently available providers are gravatar and picon.
384 # If an unknown provider is specified, the feature is disabled.
386 # Gravatar depends on Digest::MD5.
387 # Picon currently relies on the indiana.edu database.
389 # To enable system wide have in $GITWEB_CONFIG
390 # $feature{'avatar'}{'default'} = ['<provider>'];
391 # where <provider> is either gravatar or picon.
392 # To have project specific config enable override in $GITWEB_CONFIG
393 # $feature{'avatar'}{'override'} = 1;
394 # and in project config gitweb.avatar = <provider>;
396 'sub' => \
&feature_avatar
,
401 sub gitweb_get_feature
{
403 return unless exists $feature{$name};
404 my ($sub, $override, @defaults) = (
405 $feature{$name}{'sub'},
406 $feature{$name}{'override'},
407 @{$feature{$name}{'default'}});
408 if (!$override) { return @defaults; }
410 warn "feature $name is not overrideable";
413 return $sub->(@defaults);
416 # A wrapper to check if a given feature is enabled.
417 # With this, you can say
419 # my $bool_feat = gitweb_check_feature('bool_feat');
420 # gitweb_check_feature('bool_feat') or somecode;
424 # my ($bool_feat) = gitweb_get_feature('bool_feat');
425 # (gitweb_get_feature('bool_feat'))[0] or somecode;
427 sub gitweb_check_feature
{
428 return (gitweb_get_feature
(@_))[0];
434 my ($val) = git_get_project_config
($key, '--bool');
438 } elsif ($val eq 'true') {
440 } elsif ($val eq 'false') {
445 sub feature_snapshot
{
448 my ($val) = git_get_project_config
('snapshot');
451 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
457 sub feature_patches
{
458 my @val = (git_get_project_config
('patches', '--int'));
468 my @val = (git_get_project_config
('avatar'));
470 return @val ? @val : @_;
473 # checking HEAD file with -e is fragile if the repository was
474 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
476 sub check_head_link
{
478 my $headfile = "$dir/HEAD";
479 return ((-e
$headfile) ||
480 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
483 sub check_export_ok
{
485 return (check_head_link
($dir) &&
486 (!$export_ok || -e
"$dir/$export_ok") &&
487 (!$export_auth_hook || $export_auth_hook->($dir)));
490 # process alternate names for backward compatibility
491 # filter out unsupported (unknown) snapshot formats
492 sub filter_snapshot_fmts
{
496 exists $known_snapshot_format_aliases{$_} ?
497 $known_snapshot_format_aliases{$_} : $_} @fmts;
499 exists $known_snapshot_formats{$_} &&
500 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
503 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
504 if (-e
$GITWEB_CONFIG) {
507 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
508 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
511 # version of the core git binary
512 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
514 $projects_list ||= $projectroot;
516 # ======================================================================
517 # input validation and dispatch
519 # input parameters can be collected from a variety of sources (presently, CGI
520 # and PATH_INFO), so we define an %input_params hash that collects them all
521 # together during validation: this allows subsequent uses (e.g. href()) to be
522 # agnostic of the parameter origin
524 our %input_params = ();
526 # input parameters are stored with the long parameter name as key. This will
527 # also be used in the href subroutine to convert parameters to their CGI
528 # equivalent, and since the href() usage is the most frequent one, we store
529 # the name -> CGI key mapping here, instead of the reverse.
531 # XXX: Warning: If you touch this, check the search form for updating,
534 our @cgi_param_mapping = (
542 hash_parent_base
=> "hpb",
547 snapshot_format
=> "sf",
548 extra_options
=> "opt",
549 search_use_regexp
=> "sr",
551 our %cgi_param_mapping = @cgi_param_mapping;
553 # we will also need to know the possible actions, for validation
555 "blame" => \
&git_blame
,
556 "blobdiff" => \
&git_blobdiff
,
557 "blobdiff_plain" => \
&git_blobdiff_plain
,
558 "blob" => \
&git_blob
,
559 "blob_plain" => \
&git_blob_plain
,
560 "commitdiff" => \
&git_commitdiff
,
561 "commitdiff_plain" => \
&git_commitdiff_plain
,
562 "commit" => \
&git_commit
,
563 "forks" => \
&git_forks
,
564 "heads" => \
&git_heads
,
565 "history" => \
&git_history
,
567 "patch" => \
&git_patch
,
568 "patches" => \
&git_patches
,
570 "atom" => \
&git_atom
,
571 "search" => \
&git_search
,
572 "search_help" => \
&git_search_help
,
573 "shortlog" => \
&git_shortlog
,
574 "summary" => \
&git_summary
,
576 "tags" => \
&git_tags
,
577 "tree" => \
&git_tree
,
578 "snapshot" => \
&git_snapshot
,
579 "object" => \
&git_object
,
580 # those below don't need $project
581 "opml" => \
&git_opml
,
582 "project_list" => \
&git_project_list
,
583 "project_index" => \
&git_project_index
,
586 # finally, we have the hash of allowed extra_options for the commands that
588 our %allowed_options = (
589 "--no-merges" => [ qw(rss atom log shortlog history) ],
592 # fill %input_params with the CGI parameters. All values except for 'opt'
593 # should be single values, but opt can be an array. We should probably
594 # build an array of parameters that can be multi-valued, but since for the time
595 # being it's only this one, we just single it out
596 while (my ($name, $symbol) = each %cgi_param_mapping) {
597 if ($symbol eq 'opt') {
598 $input_params{$name} = [ $cgi->param($symbol) ];
600 $input_params{$name} = $cgi->param($symbol);
604 # now read PATH_INFO and update the parameter list for missing parameters
605 sub evaluate_path_info
{
606 return if defined $input_params{'project'};
607 return if !$path_info;
608 $path_info =~ s
,^/+,,;
609 return if !$path_info;
611 # find which part of PATH_INFO is project
612 my $project = $path_info;
614 while ($project && !check_head_link
("$projectroot/$project")) {
615 $project =~ s
,/*[^/]*$,,;
617 return unless $project;
618 $input_params{'project'} = $project;
620 # do not change any parameters if an action is given using the query string
621 return if $input_params{'action'};
622 $path_info =~ s
,^\Q
$project\E
/*,,;
624 # next, check if we have an action
625 my $action = $path_info;
627 if (exists $actions{$action}) {
628 $path_info =~ s
,^$action/*,,;
629 $input_params{'action'} = $action;
632 # list of actions that want hash_base instead of hash, but can have no
633 # pathname (f) parameter
640 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
641 my ($parentrefname, $parentpathname, $refname, $pathname) =
642 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
644 # first, analyze the 'current' part
645 if (defined $pathname) {
646 # we got "branch:filename" or "branch:dir/"
647 # we could use git_get_type(branch:pathname), but:
648 # - it needs $git_dir
649 # - it does a git() call
650 # - the convention of terminating directories with a slash
651 # makes it superfluous
652 # - embedding the action in the PATH_INFO would make it even
654 $pathname =~ s
,^/+,,;
655 if (!$pathname || substr($pathname, -1) eq "/") {
656 $input_params{'action'} ||= "tree";
659 # the default action depends on whether we had parent info
661 if ($parentrefname) {
662 $input_params{'action'} ||= "blobdiff_plain";
664 $input_params{'action'} ||= "blob_plain";
667 $input_params{'hash_base'} ||= $refname;
668 $input_params{'file_name'} ||= $pathname;
669 } elsif (defined $refname) {
670 # we got "branch". In this case we have to choose if we have to
671 # set hash or hash_base.
673 # Most of the actions without a pathname only want hash to be
674 # set, except for the ones specified in @wants_base that want
675 # hash_base instead. It should also be noted that hand-crafted
676 # links having 'history' as an action and no pathname or hash
677 # set will fail, but that happens regardless of PATH_INFO.
678 $input_params{'action'} ||= "shortlog";
679 if (grep { $_ eq $input_params{'action'} } @wants_base) {
680 $input_params{'hash_base'} ||= $refname;
682 $input_params{'hash'} ||= $refname;
686 # next, handle the 'parent' part, if present
687 if (defined $parentrefname) {
688 # a missing pathspec defaults to the 'current' filename, allowing e.g.
689 # someproject/blobdiff/oldrev..newrev:/filename
690 if ($parentpathname) {
691 $parentpathname =~ s
,^/+,,;
692 $parentpathname =~ s
,/$,,;
693 $input_params{'file_parent'} ||= $parentpathname;
695 $input_params{'file_parent'} ||= $input_params{'file_name'};
697 # we assume that hash_parent_base is wanted if a path was specified,
698 # or if the action wants hash_base instead of hash
699 if (defined $input_params{'file_parent'} ||
700 grep { $_ eq $input_params{'action'} } @wants_base) {
701 $input_params{'hash_parent_base'} ||= $parentrefname;
703 $input_params{'hash_parent'} ||= $parentrefname;
707 # for the snapshot action, we allow URLs in the form
708 # $project/snapshot/$hash.ext
709 # where .ext determines the snapshot and gets removed from the
710 # passed $refname to provide the $hash.
712 # To be able to tell that $refname includes the format extension, we
713 # require the following two conditions to be satisfied:
714 # - the hash input parameter MUST have been set from the $refname part
715 # of the URL (i.e. they must be equal)
716 # - the snapshot format MUST NOT have been defined already (e.g. from
718 # It's also useless to try any matching unless $refname has a dot,
719 # so we check for that too
720 if (defined $input_params{'action'} &&
721 $input_params{'action'} eq 'snapshot' &&
722 defined $refname && index($refname, '.') != -1 &&
723 $refname eq $input_params{'hash'} &&
724 !defined $input_params{'snapshot_format'}) {
725 # We loop over the known snapshot formats, checking for
726 # extensions. Allowed extensions are both the defined suffix
727 # (which includes the initial dot already) and the snapshot
728 # format key itself, with a prepended dot
729 while (my ($fmt, $opt) = each %known_snapshot_formats) {
731 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
735 # a valid suffix was found, so set the snapshot format
736 # and reset the hash parameter
737 $input_params{'snapshot_format'} = $fmt;
738 $input_params{'hash'} = $hash;
739 # we also set the format suffix to the one requested
740 # in the URL: this way a request for e.g. .tgz returns
741 # a .tgz instead of a .tar.gz
742 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
747 evaluate_path_info
();
749 our $action = $input_params{'action'};
750 if (defined $action) {
751 if (!validate_action
($action)) {
752 die_error
(400, "Invalid action parameter");
756 # parameters which are pathnames
757 our $project = $input_params{'project'};
758 if (defined $project) {
759 if (!validate_project
($project)) {
761 die_error
(404, "No such project");
765 our $file_name = $input_params{'file_name'};
766 if (defined $file_name) {
767 if (!validate_pathname
($file_name)) {
768 die_error
(400, "Invalid file parameter");
772 our $file_parent = $input_params{'file_parent'};
773 if (defined $file_parent) {
774 if (!validate_pathname
($file_parent)) {
775 die_error
(400, "Invalid file parent parameter");
779 # parameters which are refnames
780 our $hash = $input_params{'hash'};
782 if (!validate_refname
($hash)) {
783 die_error
(400, "Invalid hash parameter");
787 our $hash_parent = $input_params{'hash_parent'};
788 if (defined $hash_parent) {
789 if (!validate_refname
($hash_parent)) {
790 die_error
(400, "Invalid hash parent parameter");
794 our $hash_base = $input_params{'hash_base'};
795 if (defined $hash_base) {
796 if (!validate_refname
($hash_base)) {
797 die_error
(400, "Invalid hash base parameter");
801 our @extra_options = @{$input_params{'extra_options'}};
802 # @extra_options is always defined, since it can only be (currently) set from
803 # CGI, and $cgi->param() returns the empty array in array context if the param
805 foreach my $opt (@extra_options) {
806 if (not exists $allowed_options{$opt}) {
807 die_error
(400, "Invalid option parameter");
809 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
810 die_error
(400, "Invalid option parameter for this action");
814 our $hash_parent_base = $input_params{'hash_parent_base'};
815 if (defined $hash_parent_base) {
816 if (!validate_refname
($hash_parent_base)) {
817 die_error
(400, "Invalid hash parent base parameter");
822 our $page = $input_params{'page'};
824 if ($page =~ m/[^0-9]/) {
825 die_error
(400, "Invalid page parameter");
829 our $searchtype = $input_params{'searchtype'};
830 if (defined $searchtype) {
831 if ($searchtype =~ m/[^a-z]/) {
832 die_error
(400, "Invalid searchtype parameter");
836 our $search_use_regexp = $input_params{'search_use_regexp'};
838 our $searchtext = $input_params{'searchtext'};
840 if (defined $searchtext) {
841 if (length($searchtext) < 2) {
842 die_error
(403, "At least two characters are required for search parameter");
844 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
847 # path to the current git repository
849 $git_dir = "$projectroot/$project" if $project;
851 # list of supported snapshot formats
852 our @snapshot_fmts = gitweb_get_feature
('snapshot');
853 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
855 # check that the avatar feature is set to a known provider name,
856 # and for each provider check if the dependencies are satisfied.
857 # if the provider name is invalid or the dependencies are not met,
858 # reset $git_avatar to the empty string.
859 our ($git_avatar) = gitweb_get_feature
('avatar');
860 if ($git_avatar eq 'gravatar') {
861 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
862 } elsif ($git_avatar eq 'picon') {
869 if (!defined $action) {
871 $action = git_get_type
($hash);
872 } elsif (defined $hash_base && defined $file_name) {
873 $action = git_get_type
("$hash_base:$file_name");
874 } elsif (defined $project) {
877 $action = 'project_list';
880 if (!defined($actions{$action})) {
881 die_error
(400, "Unknown action");
883 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
885 die_error
(400, "Project needed");
887 $actions{$action}->();
890 ## ======================================================================
895 # default is to use -absolute url() i.e. $my_uri
896 my $href = $params{-full
} ? $my_url : $my_uri;
898 $params{'project'} = $project unless exists $params{'project'};
900 if ($params{-replay
}) {
901 while (my ($name, $symbol) = each %cgi_param_mapping) {
902 if (!exists $params{$name}) {
903 $params{$name} = $input_params{$name};
908 my $use_pathinfo = gitweb_check_feature
('pathinfo');
909 if ($use_pathinfo and defined $params{'project'}) {
910 # try to put as many parameters as possible in PATH_INFO:
913 # - hash_parent or hash_parent_base:/file_parent
914 # - hash or hash_base:/filename
915 # - the snapshot_format as an appropriate suffix
917 # When the script is the root DirectoryIndex for the domain,
918 # $href here would be something like http://gitweb.example.com/
919 # Thus, we strip any trailing / from $href, to spare us double
920 # slashes in the final URL
923 # Then add the project name, if present
924 $href .= "/".esc_url
($params{'project'});
925 delete $params{'project'};
927 # since we destructively absorb parameters, we keep this
928 # boolean that remembers if we're handling a snapshot
929 my $is_snapshot = $params{'action'} eq 'snapshot';
931 # Summary just uses the project path URL, any other action is
933 if (defined $params{'action'}) {
934 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
935 delete $params{'action'};
938 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
939 # stripping nonexistent or useless pieces
940 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
941 || $params{'hash_parent'} || $params{'hash'});
942 if (defined $params{'hash_base'}) {
943 if (defined $params{'hash_parent_base'}) {
944 $href .= esc_url
($params{'hash_parent_base'});
945 # skip the file_parent if it's the same as the file_name
946 if (defined $params{'file_parent'}) {
947 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
948 delete $params{'file_parent'};
949 } elsif ($params{'file_parent'} !~ /\.\./) {
950 $href .= ":/".esc_url
($params{'file_parent'});
951 delete $params{'file_parent'};
955 delete $params{'hash_parent'};
956 delete $params{'hash_parent_base'};
957 } elsif (defined $params{'hash_parent'}) {
958 $href .= esc_url
($params{'hash_parent'}). "..";
959 delete $params{'hash_parent'};
962 $href .= esc_url
($params{'hash_base'});
963 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
964 $href .= ":/".esc_url
($params{'file_name'});
965 delete $params{'file_name'};
967 delete $params{'hash'};
968 delete $params{'hash_base'};
969 } elsif (defined $params{'hash'}) {
970 $href .= esc_url
($params{'hash'});
971 delete $params{'hash'};
974 # If the action was a snapshot, we can absorb the
975 # snapshot_format parameter too
977 my $fmt = $params{'snapshot_format'};
978 # snapshot_format should always be defined when href()
979 # is called, but just in case some code forgets, we
980 # fall back to the default
981 $fmt ||= $snapshot_fmts[0];
982 $href .= $known_snapshot_formats{$fmt}{'suffix'};
983 delete $params{'snapshot_format'};
987 # now encode the parameters explicitly
989 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
990 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
991 if (defined $params{$name}) {
992 if (ref($params{$name}) eq "ARRAY") {
993 foreach my $par (@{$params{$name}}) {
994 push @result, $symbol . "=" . esc_param
($par);
997 push @result, $symbol . "=" . esc_param
($params{$name});
1001 $href .= "?" . join(';', @result) if scalar @result;
1007 ## ======================================================================
1008 ## validation, quoting/unquoting and escaping
1010 sub validate_action
{
1011 my $input = shift || return undef;
1012 return undef unless exists $actions{$input};
1016 sub validate_project
{
1017 my $input = shift || return undef;
1018 if (!validate_pathname
($input) ||
1019 !(-d
"$projectroot/$input") ||
1020 !check_export_ok
("$projectroot/$input") ||
1021 ($strict_export && !project_in_list
($input))) {
1028 sub validate_pathname
{
1029 my $input = shift || return undef;
1031 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1032 # at the beginning, at the end, and between slashes.
1033 # also this catches doubled slashes
1034 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1037 # no null characters
1038 if ($input =~ m!\0!) {
1044 sub validate_refname
{
1045 my $input = shift || return undef;
1047 # textual hashes are O.K.
1048 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1051 # it must be correct pathname
1052 $input = validate_pathname
($input)
1054 # restrictions on ref name according to git-check-ref-format
1055 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1061 # decode sequences of octets in utf8 into Perl's internal form,
1062 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1063 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1066 if (utf8
::valid
($str)) {
1070 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1074 # quote unsafe chars, but keep the slash, even when it's not
1075 # correct, but quoted slashes look too horrible in bookmarks
1078 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1084 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1087 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1093 # replace invalid utf8 character with SUBSTITUTION sequence
1098 $str = to_utf8
($str);
1099 $str = $cgi->escapeHTML($str);
1100 if ($opts{'-nbsp'}) {
1101 $str =~ s/ / /g;
1103 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1107 # quote control characters and escape filename to HTML
1112 $str = to_utf8
($str);
1113 $str = $cgi->escapeHTML($str);
1114 if ($opts{'-nbsp'}) {
1115 $str =~ s/ / /g;
1117 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1121 # Make control characters "printable", using character escape codes (CEC)
1125 my %es = ( # character escape codes, aka escape sequences
1126 "\t" => '\t', # tab (HT)
1127 "\n" => '\n', # line feed (LF)
1128 "\r" => '\r', # carrige return (CR)
1129 "\f" => '\f', # form feed (FF)
1130 "\b" => '\b', # backspace (BS)
1131 "\a" => '\a', # alarm (bell) (BEL)
1132 "\e" => '\e', # escape (ESC)
1133 "\013" => '\v', # vertical tab (VT)
1134 "\000" => '\0', # nul character (NUL)
1136 my $chr = ( (exists $es{$cntrl})
1138 : sprintf('\%2x', ord($cntrl)) );
1139 if ($opts{-nohtml
}) {
1142 return "<span class=\"cntrl\">$chr</span>";
1146 # Alternatively use unicode control pictures codepoints,
1147 # Unicode "printable representation" (PR)
1152 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1153 if ($opts{-nohtml
}) {
1156 return "<span class=\"cntrl\">$chr</span>";
1160 # git may return quoted and escaped filenames
1166 my %es = ( # character escape codes, aka escape sequences
1167 't' => "\t", # tab (HT, TAB)
1168 'n' => "\n", # newline (NL)
1169 'r' => "\r", # return (CR)
1170 'f' => "\f", # form feed (FF)
1171 'b' => "\b", # backspace (BS)
1172 'a' => "\a", # alarm (bell) (BEL)
1173 'e' => "\e", # escape (ESC)
1174 'v' => "\013", # vertical tab (VT)
1177 if ($seq =~ m/^[0-7]{1,3}$/) {
1178 # octal char sequence
1179 return chr(oct($seq));
1180 } elsif (exists $es{$seq}) {
1181 # C escape sequence, aka character escape code
1184 # quoted ordinary character
1188 if ($str =~ m/^"(.*)"$/) {
1191 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1196 # escape tabs (convert tabs to spaces)
1200 while ((my $pos = index($line, "\t")) != -1) {
1201 if (my $count = (8 - ($pos % 8))) {
1202 my $spaces = ' ' x
$count;
1203 $line =~ s/\t/$spaces/;
1210 sub project_in_list
{
1211 my $project = shift;
1212 my @list = git_get_projects_list
();
1213 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1216 ## ----------------------------------------------------------------------
1217 ## HTML aware string manipulation
1219 # Try to chop given string on a word boundary between position
1220 # $len and $len+$add_len. If there is no word boundary there,
1221 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1222 # (marking chopped part) would be longer than given string.
1226 my $add_len = shift || 10;
1227 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1229 # Make sure perl knows it is utf8 encoded so we don't
1230 # cut in the middle of a utf8 multibyte char.
1231 $str = to_utf8
($str);
1233 # allow only $len chars, but don't cut a word if it would fit in $add_len
1234 # if it doesn't fit, cut it if it's still longer than the dots we would add
1235 # remove chopped character entities entirely
1237 # when chopping in the middle, distribute $len into left and right part
1238 # return early if chopping wouldn't make string shorter
1239 if ($where eq 'center') {
1240 return $str if ($len + 5 >= length($str)); # filler is length 5
1243 return $str if ($len + 4 >= length($str)); # filler is length 4
1246 # regexps: ending and beginning with word part up to $add_len
1247 my $endre = qr/.{$len}\w{0,$add_len}/;
1248 my $begre = qr/\w{0,$add_len}.{$len}/;
1250 if ($where eq 'left') {
1251 $str =~ m/^(.*?)($begre)$/;
1252 my ($lead, $body) = ($1, $2);
1253 if (length($lead) > 4) {
1254 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1257 return "$lead$body";
1259 } elsif ($where eq 'center') {
1260 $str =~ m/^($endre)(.*)$/;
1261 my ($left, $str) = ($1, $2);
1262 $str =~ m/^(.*?)($begre)$/;
1263 my ($mid, $right) = ($1, $2);
1264 if (length($mid) > 5) {
1265 $left =~ s/&[^;]*$//;
1266 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1269 return "$left$mid$right";
1272 $str =~ m/^($endre)(.*)$/;
1275 if (length($tail) > 4) {
1276 $body =~ s/&[^;]*$//;
1279 return "$body$tail";
1283 # takes the same arguments as chop_str, but also wraps a <span> around the
1284 # result with a title attribute if it does get chopped. Additionally, the
1285 # string is HTML-escaped.
1286 sub chop_and_escape_str
{
1289 my $chopped = chop_str
(@_);
1290 if ($chopped eq $str) {
1291 return esc_html
($chopped);
1293 $str =~ s/[[:cntrl:]]/?/g;
1294 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1298 ## ----------------------------------------------------------------------
1299 ## functions returning short strings
1301 # CSS class for given age value (in seconds)
1305 if (!defined $age) {
1307 } elsif ($age < 60*60*2) {
1309 } elsif ($age < 60*60*24*2) {
1316 # convert age in seconds to "nn units ago" string
1321 if ($age > 60*60*24*365*2) {
1322 $age_str = (int $age/60/60/24/365);
1323 $age_str .= " years ago";
1324 } elsif ($age > 60*60*24*(365/12)*2) {
1325 $age_str = int $age/60/60/24/(365/12);
1326 $age_str .= " months ago";
1327 } elsif ($age > 60*60*24*7*2) {
1328 $age_str = int $age/60/60/24/7;
1329 $age_str .= " weeks ago";
1330 } elsif ($age > 60*60*24*2) {
1331 $age_str = int $age/60/60/24;
1332 $age_str .= " days ago";
1333 } elsif ($age > 60*60*2) {
1334 $age_str = int $age/60/60;
1335 $age_str .= " hours ago";
1336 } elsif ($age > 60*2) {
1337 $age_str = int $age/60;
1338 $age_str .= " min ago";
1339 } elsif ($age > 2) {
1340 $age_str = int $age;
1341 $age_str .= " sec ago";
1343 $age_str .= " right now";
1349 S_IFINVALID
=> 0030000,
1350 S_IFGITLINK
=> 0160000,
1353 # submodule/subproject, a commit object reference
1357 return (($mode & S_IFMT
) == S_IFGITLINK
)
1360 # convert file mode in octal to symbolic file mode string
1362 my $mode = oct shift;
1364 if (S_ISGITLINK
($mode)) {
1365 return 'm---------';
1366 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1367 return 'drwxr-xr-x';
1368 } elsif (S_ISLNK
($mode)) {
1369 return 'lrwxrwxrwx';
1370 } elsif (S_ISREG
($mode)) {
1371 # git cares only about the executable bit
1372 if ($mode & S_IXUSR
) {
1373 return '-rwxr-xr-x';
1375 return '-rw-r--r--';
1378 return '----------';
1382 # convert file mode in octal to file type string
1386 if ($mode !~ m/^[0-7]+$/) {
1392 if (S_ISGITLINK
($mode)) {
1394 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1396 } elsif (S_ISLNK
($mode)) {
1398 } elsif (S_ISREG
($mode)) {
1405 # convert file mode in octal to file type description string
1406 sub file_type_long
{
1409 if ($mode !~ m/^[0-7]+$/) {
1415 if (S_ISGITLINK
($mode)) {
1417 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1419 } elsif (S_ISLNK
($mode)) {
1421 } elsif (S_ISREG
($mode)) {
1422 if ($mode & S_IXUSR
) {
1423 return "executable";
1433 ## ----------------------------------------------------------------------
1434 ## functions returning short HTML fragments, or transforming HTML fragments
1435 ## which don't belong to other sections
1437 # format line of commit message.
1438 sub format_log_line_html
{
1441 $line = esc_html
($line, -nbsp
=>1);
1442 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1443 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1444 -class => "text"}, $1);
1450 # format marker of refs pointing to given object
1452 # the destination action is chosen based on object type and current context:
1453 # - for annotated tags, we choose the tag view unless it's the current view
1454 # already, in which case we go to shortlog view
1455 # - for other refs, we keep the current view if we're in history, shortlog or
1456 # log view, and select shortlog otherwise
1457 sub format_ref_marker
{
1458 my ($refs, $id) = @_;
1461 if (defined $refs->{$id}) {
1462 foreach my $ref (@{$refs->{$id}}) {
1463 # this code exploits the fact that non-lightweight tags are the
1464 # only indirect objects, and that they are the only objects for which
1465 # we want to use tag instead of shortlog as action
1466 my ($type, $name) = qw();
1467 my $indirect = ($ref =~ s/\^\{\}$//);
1468 # e.g. tags/v2.6.11 or heads/next
1469 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1478 $class .= " indirect" if $indirect;
1480 my $dest_action = "shortlog";
1483 $dest_action = "tag" unless $action eq "tag";
1484 } elsif ($action =~ /^(history|(short)?log)$/) {
1485 $dest_action = $action;
1489 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1492 my $link = $cgi->a({
1494 action
=>$dest_action,
1498 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1504 return ' <span class="refs">'. $markers . '</span>';
1510 # format, perhaps shortened and with markers, title line
1511 sub format_subject_html
{
1512 my ($long, $short, $href, $extra) = @_;
1513 $extra = '' unless defined($extra);
1515 if (length($short) < length($long)) {
1516 $long =~ s/[[:cntrl:]]/?/g;
1517 return $cgi->a({-href
=> $href, -class => "list subject",
1518 -title
=> to_utf8
($long)},
1519 esc_html
($short) . $extra);
1521 return $cgi->a({-href
=> $href, -class => "list subject"},
1522 esc_html
($long) . $extra);
1526 # Rather than recomputing the url for an email multiple times, we cache it
1527 # after the first hit. This gives a visible benefit in views where the avatar
1528 # for the same email is used repeatedly (e.g. shortlog).
1529 # The cache is shared by all avatar engines (currently gravatar only), which
1530 # are free to use it as preferred. Since only one avatar engine is used for any
1531 # given page, there's no risk for cache conflicts.
1532 our %avatar_cache = ();
1534 # Compute the picon url for a given email, by using the picon search service over at
1535 # http://www.cs.indiana.edu/picons/search.html
1537 my $email = lc shift;
1538 if (!$avatar_cache{$email}) {
1539 my ($user, $domain) = split('@', $email);
1540 $avatar_cache{$email} =
1541 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1543 "users+domains+unknown/up/single";
1545 return $avatar_cache{$email};
1548 # Compute the gravatar url for a given email, if it's not in the cache already.
1549 # Gravatar stores only the part of the URL before the size, since that's the
1550 # one computationally more expensive. This also allows reuse of the cache for
1551 # different sizes (for this particular engine).
1553 my $email = lc shift;
1555 $avatar_cache{$email} ||=
1556 "http://www.gravatar.com/avatar/" .
1557 Digest
::MD5
::md5_hex
($email) . "?s=";
1558 return $avatar_cache{$email} . $size;
1561 # Insert an avatar for the given $email at the given $size if the feature
1563 sub git_get_avatar
{
1564 my ($email, %opts) = @_;
1565 my $pre_white = ($opts{-pad_before
} ? " " : "");
1566 my $post_white = ($opts{-pad_after
} ? " " : "");
1567 $opts{-size
} ||= 'default';
1568 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1570 if ($git_avatar eq 'gravatar') {
1571 $url = gravatar_url
($email, $size);
1572 } elsif ($git_avatar eq 'picon') {
1573 $url = picon_url
($email);
1575 # Other providers can be added by extending the if chain, defining $url
1576 # as needed. If no variant puts something in $url, we assume avatars
1577 # are completely disabled/unavailable.
1580 "<img width=\"$size\" " .
1581 "class=\"avatar\" " .
1590 # format the author name of the given commit with the given tag
1591 # the author name is chopped and escaped according to the other
1592 # optional parameters (see chop_str).
1593 sub format_author_html
{
1596 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1597 return "<$tag class=\"author\">" .
1598 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1599 $author . "</$tag>";
1602 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1603 sub format_git_diff_header_line
{
1605 my $diffinfo = shift;
1606 my ($from, $to) = @_;
1608 if ($diffinfo->{'nparents'}) {
1610 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1611 if ($to->{'href'}) {
1612 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1613 esc_path
($to->{'file'}));
1614 } else { # file was deleted (no href)
1615 $line .= esc_path
($to->{'file'});
1619 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1620 if ($from->{'href'}) {
1621 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1622 'a/' . esc_path
($from->{'file'}));
1623 } else { # file was added (no href)
1624 $line .= 'a/' . esc_path
($from->{'file'});
1627 if ($to->{'href'}) {
1628 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1629 'b/' . esc_path
($to->{'file'}));
1630 } else { # file was deleted
1631 $line .= 'b/' . esc_path
($to->{'file'});
1635 return "<div class=\"diff header\">$line</div>\n";
1638 # format extended diff header line, before patch itself
1639 sub format_extended_diff_header_line
{
1641 my $diffinfo = shift;
1642 my ($from, $to) = @_;
1645 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1646 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1647 esc_path
($from->{'file'}));
1649 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1650 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1651 esc_path
($to->{'file'}));
1653 # match single <mode>
1654 if ($line =~ m/\s(\d{6})$/) {
1655 $line .= '<span class="info"> (' .
1656 file_type_long
($1) .
1660 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1661 # can match only for combined diff
1663 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1664 if ($from->{'href'}[$i]) {
1665 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1667 substr($diffinfo->{'from_id'}[$i],0,7));
1672 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1675 if ($to->{'href'}) {
1676 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1677 substr($diffinfo->{'to_id'},0,7));
1682 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1683 # can match only for ordinary diff
1684 my ($from_link, $to_link);
1685 if ($from->{'href'}) {
1686 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1687 substr($diffinfo->{'from_id'},0,7));
1689 $from_link = '0' x
7;
1691 if ($to->{'href'}) {
1692 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1693 substr($diffinfo->{'to_id'},0,7));
1697 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1698 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1701 return $line . "<br/>\n";
1704 # format from-file/to-file diff header
1705 sub format_diff_from_to_header
{
1706 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1711 #assert($line =~ m/^---/) if DEBUG;
1712 # no extra formatting for "^--- /dev/null"
1713 if (! $diffinfo->{'nparents'}) {
1714 # ordinary (single parent) diff
1715 if ($line =~ m!^--- "?a/!) {
1716 if ($from->{'href'}) {
1718 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1719 esc_path
($from->{'file'}));
1722 esc_path
($from->{'file'});
1725 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1728 # combined diff (merge commit)
1729 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1730 if ($from->{'href'}[$i]) {
1732 $cgi->a({-href
=>href
(action
=>"blobdiff",
1733 hash_parent
=>$diffinfo->{'from_id'}[$i],
1734 hash_parent_base
=>$parents[$i],
1735 file_parent
=>$from->{'file'}[$i],
1736 hash
=>$diffinfo->{'to_id'},
1738 file_name
=>$to->{'file'}),
1740 -title
=>"diff" . ($i+1)},
1743 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1744 esc_path
($from->{'file'}[$i]));
1746 $line = '--- /dev/null';
1748 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1753 #assert($line =~ m/^\+\+\+/) if DEBUG;
1754 # no extra formatting for "^+++ /dev/null"
1755 if ($line =~ m!^\+\+\+ "?b/!) {
1756 if ($to->{'href'}) {
1758 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1759 esc_path
($to->{'file'}));
1762 esc_path
($to->{'file'});
1765 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1770 # create note for patch simplified by combined diff
1771 sub format_diff_cc_simplified
{
1772 my ($diffinfo, @parents) = @_;
1775 $result .= "<div class=\"diff header\">" .
1777 if (!is_deleted
($diffinfo)) {
1778 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1780 hash
=>$diffinfo->{'to_id'},
1781 file_name
=>$diffinfo->{'to_file'}),
1783 esc_path
($diffinfo->{'to_file'}));
1785 $result .= esc_path
($diffinfo->{'to_file'});
1787 $result .= "</div>\n" . # class="diff header"
1788 "<div class=\"diff nodifferences\">" .
1790 "</div>\n"; # class="diff nodifferences"
1795 # format patch (diff) line (not to be used for diff headers)
1796 sub format_diff_line
{
1798 my ($from, $to) = @_;
1799 my $diff_class = "";
1803 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1805 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1806 if ($line =~ m/^\@{3}/) {
1807 $diff_class = " chunk_header";
1808 } elsif ($line =~ m/^\\/) {
1809 $diff_class = " incomplete";
1810 } elsif ($prefix =~ tr/+/+/) {
1811 $diff_class = " add";
1812 } elsif ($prefix =~ tr/-/-/) {
1813 $diff_class = " rem";
1816 # assume ordinary diff
1817 my $char = substr($line, 0, 1);
1819 $diff_class = " add";
1820 } elsif ($char eq '-') {
1821 $diff_class = " rem";
1822 } elsif ($char eq '@') {
1823 $diff_class = " chunk_header";
1824 } elsif ($char eq "\\") {
1825 $diff_class = " incomplete";
1828 $line = untabify
($line);
1829 if ($from && $to && $line =~ m/^\@{2} /) {
1830 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1831 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1833 $from_lines = 0 unless defined $from_lines;
1834 $to_lines = 0 unless defined $to_lines;
1836 if ($from->{'href'}) {
1837 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1838 -class=>"list"}, $from_text);
1840 if ($to->{'href'}) {
1841 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1842 -class=>"list"}, $to_text);
1844 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1845 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1846 return "<div class=\"diff$diff_class\">$line</div>\n";
1847 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1848 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1849 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1851 @from_text = split(' ', $ranges);
1852 for (my $i = 0; $i < @from_text; ++$i) {
1853 ($from_start[$i], $from_nlines[$i]) =
1854 (split(',', substr($from_text[$i], 1)), 0);
1857 $to_text = pop @from_text;
1858 $to_start = pop @from_start;
1859 $to_nlines = pop @from_nlines;
1861 $line = "<span class=\"chunk_info\">$prefix ";
1862 for (my $i = 0; $i < @from_text; ++$i) {
1863 if ($from->{'href'}[$i]) {
1864 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1865 -class=>"list"}, $from_text[$i]);
1867 $line .= $from_text[$i];
1871 if ($to->{'href'}) {
1872 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1873 -class=>"list"}, $to_text);
1877 $line .= " $prefix</span>" .
1878 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1879 return "<div class=\"diff$diff_class\">$line</div>\n";
1881 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1884 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1885 # linked. Pass the hash of the tree/commit to snapshot.
1886 sub format_snapshot_links
{
1888 my $num_fmts = @snapshot_fmts;
1889 if ($num_fmts > 1) {
1890 # A parenthesized list of links bearing format names.
1891 # e.g. "snapshot (_tar.gz_ _zip_)"
1892 return "snapshot (" . join(' ', map
1899 }, $known_snapshot_formats{$_}{'display'})
1900 , @snapshot_fmts) . ")";
1901 } elsif ($num_fmts == 1) {
1902 # A single "snapshot" link whose tooltip bears the format name.
1904 my ($fmt) = @snapshot_fmts;
1910 snapshot_format
=>$fmt
1912 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1914 } else { # $num_fmts == 0
1919 ## ......................................................................
1920 ## functions returning values to be passed, perhaps after some
1921 ## transformation, to other functions; e.g. returning arguments to href()
1923 # returns hash to be passed to href to generate gitweb URL
1924 # in -title key it returns description of link
1926 my $format = shift || 'Atom';
1927 my %res = (action
=> lc($format));
1929 # feed links are possible only for project views
1930 return unless (defined $project);
1931 # some views should link to OPML, or to generic project feed,
1932 # or don't have specific feed yet (so they should use generic)
1933 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1936 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1937 # from tag links; this also makes possible to detect branch links
1938 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1939 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1942 # find log type for feed description (title)
1944 if (defined $file_name) {
1945 $type = "history of $file_name";
1946 $type .= "/" if ($action eq 'tree');
1947 $type .= " on '$branch'" if (defined $branch);
1949 $type = "log of $branch" if (defined $branch);
1952 $res{-title
} = $type;
1953 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1954 $res{'file_name'} = $file_name;
1959 ## ----------------------------------------------------------------------
1960 ## git utility subroutines, invoking git commands
1962 # returns path to the core git executable and the --git-dir parameter as list
1964 return $GIT, '--git-dir='.$git_dir;
1967 # quote the given arguments for passing them to the shell
1968 # quote_command("command", "arg 1", "arg with ' and ! characters")
1969 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1970 # Try to avoid using this function wherever possible.
1973 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1976 # get HEAD ref of given project as hash
1977 sub git_get_head_hash
{
1978 my $project = shift;
1979 my $o_git_dir = $git_dir;
1981 $git_dir = "$projectroot/$project";
1982 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1985 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1989 if (defined $o_git_dir) {
1990 $git_dir = $o_git_dir;
1995 # get type of given object
1999 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2001 close $fd or return;
2006 # repository configuration
2007 our $config_file = '';
2010 # store multiple values for single key as anonymous array reference
2011 # single values stored directly in the hash, not as [ <value> ]
2012 sub hash_set_multi
{
2013 my ($hash, $key, $value) = @_;
2015 if (!exists $hash->{$key}) {
2016 $hash->{$key} = $value;
2017 } elsif (!ref $hash->{$key}) {
2018 $hash->{$key} = [ $hash->{$key}, $value ];
2020 push @{$hash->{$key}}, $value;
2024 # return hash of git project configuration
2025 # optionally limited to some section, e.g. 'gitweb'
2026 sub git_parse_project_config
{
2027 my $section_regexp = shift;
2032 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2035 while (my $keyval = <$fh>) {
2037 my ($key, $value) = split(/\n/, $keyval, 2);
2039 hash_set_multi
(\
%config, $key, $value)
2040 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2047 # convert config value to boolean: 'true' or 'false'
2048 # no value, number > 0, 'true' and 'yes' values are true
2049 # rest of values are treated as false (never as error)
2050 sub config_to_bool
{
2053 return 1 if !defined $val; # section.key
2055 # strip leading and trailing whitespace
2059 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2060 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2063 # convert config value to simple decimal number
2064 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2065 # to be multiplied by 1024, 1048576, or 1073741824
2069 # strip leading and trailing whitespace
2073 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2075 # unknown unit is treated as 1
2076 return $num * ($unit eq 'g' ? 1073741824 :
2077 $unit eq 'm' ? 1048576 :
2078 $unit eq 'k' ? 1024 : 1);
2083 # convert config value to array reference, if needed
2084 sub config_to_multi
{
2087 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2090 sub git_get_project_config
{
2091 my ($key, $type) = @_;
2094 return unless ($key);
2095 $key =~ s/^gitweb\.//;
2096 return if ($key =~ m/\W/);
2099 if (defined $type) {
2102 unless ($type eq 'bool' || $type eq 'int');
2106 if (!defined $config_file ||
2107 $config_file ne "$git_dir/config") {
2108 %config = git_parse_project_config
('gitweb');
2109 $config_file = "$git_dir/config";
2112 # check if config variable (key) exists
2113 return unless exists $config{"gitweb.$key"};
2116 if (!defined $type) {
2117 return $config{"gitweb.$key"};
2118 } elsif ($type eq 'bool') {
2119 # backward compatibility: 'git config --bool' returns true/false
2120 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2121 } elsif ($type eq 'int') {
2122 return config_to_int
($config{"gitweb.$key"});
2124 return $config{"gitweb.$key"};
2127 # get hash of given path at given ref
2128 sub git_get_hash_by_path
{
2130 my $path = shift || return undef;
2135 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2136 or die_error
(500, "Open git-ls-tree failed");
2138 close $fd or return undef;
2140 if (!defined $line) {
2141 # there is no tree or hash given by $path at $base
2145 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2146 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2147 if (defined $type && $type ne $2) {
2148 # type doesn't match
2154 # get path of entry with given hash at given tree-ish (ref)
2155 # used to get 'from' filename for combined diff (merge commit) for renames
2156 sub git_get_path_by_hash
{
2157 my $base = shift || return;
2158 my $hash = shift || return;
2162 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2164 while (my $line = <$fd>) {
2167 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2168 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2169 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2178 ## ......................................................................
2179 ## git utility functions, directly accessing git repository
2181 sub git_get_project_description
{
2184 $git_dir = "$projectroot/$path";
2185 open my $fd, '<', "$git_dir/description"
2186 or return git_get_project_config
('description');
2189 if (defined $descr) {
2195 sub git_get_project_ctags
{
2199 $git_dir = "$projectroot/$path";
2200 opendir my $dh, "$git_dir/ctags"
2202 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2203 open my $ct, '<', $_ or next;
2207 my $ctag = $_; $ctag =~ s
#.*/##;
2208 $ctags->{$ctag} = $val;
2214 sub git_populate_project_tagcloud
{
2217 # First, merge different-cased tags; tags vote on casing
2219 foreach (keys %$ctags) {
2220 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2221 if (not $ctags_lc{lc $_}->{topcount
}
2222 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2223 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2224 $ctags_lc{lc $_}->{topname
} = $_;
2229 if (eval { require HTML
::TagCloud
; 1; }) {
2230 $cloud = HTML
::TagCloud-
>new;
2231 foreach (sort keys %ctags_lc) {
2232 # Pad the title with spaces so that the cloud looks
2234 my $title = $ctags_lc{$_}->{topname
};
2235 $title =~ s/ / /g;
2236 $title =~ s/^/ /g;
2237 $title =~ s/$/ /g;
2238 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2241 $cloud = \
%ctags_lc;
2246 sub git_show_project_tagcloud
{
2247 my ($cloud, $count) = @_;
2248 print STDERR
ref($cloud)."..\n";
2249 if (ref $cloud eq 'HTML::TagCloud') {
2250 return $cloud->html_and_css($count);
2252 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2253 return '<p align="center">' . join (', ', map {
2254 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2255 } splice(@tags, 0, $count)) . '</p>';
2259 sub git_get_project_url_list
{
2262 $git_dir = "$projectroot/$path";
2263 open my $fd, '<', "$git_dir/cloneurl"
2264 or return wantarray ?
2265 @{ config_to_multi
(git_get_project_config
('url')) } :
2266 config_to_multi
(git_get_project_config
('url'));
2267 my @git_project_url_list = map { chomp; $_ } <$fd>;
2270 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2273 sub git_get_projects_list
{
2278 $filter =~ s/\.git$//;
2280 my $check_forks = gitweb_check_feature
('forks');
2282 if (-d
$projects_list) {
2283 # search in directory
2284 my $dir = $projects_list . ($filter ? "/$filter" : '');
2285 # remove the trailing "/"
2287 my $pfxlen = length("$dir");
2288 my $pfxdepth = ($dir =~ tr!/!!);
2291 follow_fast
=> 1, # follow symbolic links
2292 follow_skip
=> 2, # ignore duplicates
2293 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2295 # skip project-list toplevel, if we get it.
2296 return if (m!^[/.]$!);
2297 # only directories can be git repositories
2298 return unless (-d
$_);
2299 # don't traverse too deep (Find is super slow on os x)
2300 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2301 $File::Find
::prune
= 1;
2305 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2306 # we check related file in $projectroot
2307 my $path = ($filter ? "$filter/" : '') . $subdir;
2308 if (check_export_ok
("$projectroot/$path")) {
2309 push @list, { path
=> $path };
2310 $File::Find
::prune
= 1;
2315 } elsif (-f
$projects_list) {
2316 # read from file(url-encoded):
2317 # 'git%2Fgit.git Linus+Torvalds'
2318 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2319 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2321 open my $fd, '<', $projects_list or return;
2323 while (my $line = <$fd>) {
2325 my ($path, $owner) = split ' ', $line;
2326 $path = unescape
($path);
2327 $owner = unescape
($owner);
2328 if (!defined $path) {
2331 if ($filter ne '') {
2332 # looking for forks;
2333 my $pfx = substr($path, 0, length($filter));
2334 if ($pfx ne $filter) {
2337 my $sfx = substr($path, length($filter));
2338 if ($sfx !~ /^\/.*\
.git
$/) {
2341 } elsif ($check_forks) {
2343 foreach my $filter (keys %paths) {
2344 # looking for forks;
2345 my $pfx = substr($path, 0, length($filter));
2346 if ($pfx ne $filter) {
2349 my $sfx = substr($path, length($filter));
2350 if ($sfx !~ /^\/.*\
.git
$/) {
2353 # is a fork, don't include it in
2358 if (check_export_ok
("$projectroot/$path")) {
2361 owner
=> to_utf8
($owner),
2364 (my $forks_path = $path) =~ s/\.git$//;
2365 $paths{$forks_path}++;
2373 our $gitweb_project_owner = undef;
2374 sub git_get_project_list_from_file
{
2376 return if (defined $gitweb_project_owner);
2378 $gitweb_project_owner = {};
2379 # read from file (url-encoded):
2380 # 'git%2Fgit.git Linus+Torvalds'
2381 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2382 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2383 if (-f
$projects_list) {
2384 open(my $fd, '<', $projects_list);
2385 while (my $line = <$fd>) {
2387 my ($pr, $ow) = split ' ', $line;
2388 $pr = unescape
($pr);
2389 $ow = unescape
($ow);
2390 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2396 sub git_get_project_owner
{
2397 my $project = shift;
2400 return undef unless $project;
2401 $git_dir = "$projectroot/$project";
2403 if (!defined $gitweb_project_owner) {
2404 git_get_project_list_from_file
();
2407 if (exists $gitweb_project_owner->{$project}) {
2408 $owner = $gitweb_project_owner->{$project};
2410 if (!defined $owner){
2411 $owner = git_get_project_config
('owner');
2413 if (!defined $owner) {
2414 $owner = get_file_owner
("$git_dir");
2420 sub git_get_last_activity
{
2424 $git_dir = "$projectroot/$path";
2425 open($fd, "-|", git_cmd
(), 'for-each-ref',
2426 '--format=%(committer)',
2427 '--sort=-committerdate',
2429 'refs/heads') or return;
2430 my $most_recent = <$fd>;
2431 close $fd or return;
2432 if (defined $most_recent &&
2433 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2435 my $age = time - $timestamp;
2436 return ($age, age_string
($age));
2438 return (undef, undef);
2441 sub git_get_references
{
2442 my $type = shift || "";
2444 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2445 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2446 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2447 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2450 while (my $line = <$fd>) {
2452 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2453 if (defined $refs{$1}) {
2454 push @{$refs{$1}}, $2;
2460 close $fd or return;
2464 sub git_get_rev_name_tags
{
2465 my $hash = shift || return undef;
2467 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2469 my $name_rev = <$fd>;
2472 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2475 # catches also '$hash undefined' output
2480 ## ----------------------------------------------------------------------
2481 ## parse to hash functions
2485 my $tz = shift || "-0000";
2488 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2489 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2490 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2491 $date{'hour'} = $hour;
2492 $date{'minute'} = $min;
2493 $date{'mday'} = $mday;
2494 $date{'day'} = $days[$wday];
2495 $date{'month'} = $months[$mon];
2496 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2497 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2498 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2499 $mday, $months[$mon], $hour ,$min;
2500 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2501 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2503 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2504 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2505 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2506 $date{'hour_local'} = $hour;
2507 $date{'minute_local'} = $min;
2508 $date{'tz_local'} = $tz;
2509 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2510 1900+$year, $mon+1, $mday,
2511 $hour, $min, $sec, $tz);
2520 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2521 $tag{'id'} = $tag_id;
2522 while (my $line = <$fd>) {
2524 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2525 $tag{'object'} = $1;
2526 } elsif ($line =~ m/^type (.+)$/) {
2528 } elsif ($line =~ m/^tag (.+)$/) {
2530 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2531 $tag{'author'} = $1;
2532 $tag{'author_epoch'} = $2;
2533 $tag{'author_tz'} = $3;
2534 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2535 $tag{'author_name'} = $1;
2536 $tag{'author_email'} = $2;
2538 $tag{'author_name'} = $tag{'author'};
2540 } elsif ($line =~ m/--BEGIN/) {
2541 push @comment, $line;
2543 } elsif ($line eq "") {
2547 push @comment, <$fd>;
2548 $tag{'comment'} = \
@comment;
2549 close $fd or return;
2550 if (!defined $tag{'name'}) {
2556 sub parse_commit_text
{
2557 my ($commit_text, $withparents) = @_;
2558 my @commit_lines = split '\n', $commit_text;
2561 pop @commit_lines; # Remove '\0'
2563 if (! @commit_lines) {
2567 my $header = shift @commit_lines;
2568 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2571 ($co{'id'}, my @parents) = split ' ', $header;
2572 while (my $line = shift @commit_lines) {
2573 last if $line eq "\n";
2574 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2576 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2578 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2579 $co{'author'} = to_utf8
($1);
2580 $co{'author_epoch'} = $2;
2581 $co{'author_tz'} = $3;
2582 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2583 $co{'author_name'} = $1;
2584 $co{'author_email'} = $2;
2586 $co{'author_name'} = $co{'author'};
2588 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2589 $co{'committer'} = to_utf8
($1);
2590 $co{'committer_epoch'} = $2;
2591 $co{'committer_tz'} = $3;
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(light dark);
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} = { 'nprevious' => 0 };
4829 my $meta = $metainfo{$full_rev};
4831 while ($data = <$fd>) {
4833 last if ($data =~ s/^\t//); # contents of line
4834 if ($data =~ /^(\S+)(?: (.*))?$/) {
4835 $meta->{$1} = $2 unless exists $meta->{$1};
4837 if ($data =~ /^previous /) {
4838 $meta->{'nprevious'}++;
4841 my $short_rev = substr($full_rev, 0, 8);
4842 my $author = $meta->{'author'};
4844 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4845 my $date = $date{'iso-tz'};
4847 $current_color = ($current_color + 1) % $num_colors;
4849 my $tr_class = $rev_color[$current_color];
4850 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4851 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4852 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4853 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4855 print "<td class=\"sha1\"";
4856 print " title=\"". esc_html
($author) . ", $date\"";
4857 print " rowspan=\"$group_size\"" if ($group_size > 1);
4859 print $cgi->a({-href
=> href
(action
=>"commit",
4861 file_name
=>$file_name)},
4862 esc_html
($short_rev));
4863 if ($group_size >= 2) {
4864 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
4865 if (@author_initials) {
4867 esc_html
(join('', @author_initials));
4873 # 'previous' <sha1 of parent commit> <filename at commit>
4874 if (exists $meta->{'previous'} &&
4875 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
4876 $meta->{'parent'} = $1;
4877 $meta->{'file_parent'} = unquote
($2);
4880 exists($meta->{'parent'}) ?
4881 $meta->{'parent'} : $full_rev;
4882 my $linenr_filename =
4883 exists($meta->{'file_parent'}) ?
4884 $meta->{'file_parent'} : unquote
($meta->{'filename'});
4885 my $blamed = href
(action
=> 'blame',
4886 file_name
=> $linenr_filename,
4887 hash_base
=> $linenr_commit);
4888 print "<td class=\"linenr\">";
4889 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4890 -class => "linenr" },
4893 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4899 or print "Reading blob failed\n";
4906 my $head = git_get_head_hash
($project);
4908 git_print_page_nav
('','', $head,undef,$head);
4909 git_print_header_div
('summary', $project);
4911 my @tagslist = git_get_tags_list
();
4913 git_tags_body
(\
@tagslist);
4919 my $head = git_get_head_hash
($project);
4921 git_print_page_nav
('','', $head,undef,$head);
4922 git_print_header_div
('summary', $project);
4924 my @headslist = git_get_heads_list
();
4926 git_heads_body
(\
@headslist, $head);
4931 sub git_blob_plain
{
4935 if (!defined $hash) {
4936 if (defined $file_name) {
4937 my $base = $hash_base || git_get_head_hash
($project);
4938 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4939 or die_error
(404, "Cannot find file");
4941 die_error
(400, "No file name defined");
4943 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4944 # blobs defined by non-textual hash id's can be cached
4948 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4949 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4951 # content-type (can include charset)
4952 $type = blob_contenttype
($fd, $file_name, $type);
4954 # "save as" filename, even when no $file_name is given
4955 my $save_as = "$hash";
4956 if (defined $file_name) {
4957 $save_as = $file_name;
4958 } elsif ($type =~ m/^text\//) {
4962 # With XSS prevention on, blobs of all types except a few known safe
4963 # ones are served with "Content-Disposition: attachment" to make sure
4964 # they don't run in our security domain. For certain image types,
4965 # blob view writes an <img> tag referring to blob_plain view, and we
4966 # want to be sure not to break that by serving the image as an
4967 # attachment (though Firefox 3 doesn't seem to care).
4968 my $sandbox = $prevent_xss &&
4969 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4973 -expires
=> $expires,
4974 -content_disposition
=>
4975 ($sandbox ? 'attachment' : 'inline')
4976 . '; filename="' . $save_as . '"');
4978 binmode STDOUT
, ':raw';
4980 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4987 if (!defined $hash) {
4988 if (defined $file_name) {
4989 my $base = $hash_base || git_get_head_hash
($project);
4990 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4991 or die_error
(404, "Cannot find file");
4993 die_error
(400, "No file name defined");
4995 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4996 # blobs defined by non-textual hash id's can be cached
5000 my $have_blame = gitweb_check_feature
('blame');
5001 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5002 or die_error
(500, "Couldn't cat $file_name, $hash");
5003 my $mimetype = blob_mimetype
($fd, $file_name);
5004 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5006 return git_blob_plain
($mimetype);
5008 # we can have blame only for text/* mimetype
5009 $have_blame &&= ($mimetype =~ m!^text/!);
5011 git_header_html
(undef, $expires);
5012 my $formats_nav = '';
5013 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5014 if (defined $file_name) {
5017 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5022 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5025 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5028 $cgi->a({-href
=> href
(action
=>"blob",
5029 hash_base
=>"HEAD", file_name
=>$file_name)},
5033 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5036 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5037 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5039 print "<div class=\"page_nav\">\n" .
5040 "<br/><br/></div>\n" .
5041 "<div class=\"title\">$hash</div>\n";
5043 git_print_page_path
($file_name, "blob", $hash_base);
5044 print "<div class=\"page_body\">\n";
5045 if ($mimetype =~ m!^image/!) {
5046 print qq
!<img type
="$mimetype"!;
5048 print qq
! alt
="$file_name" title
="$file_name"!;
5051 href(action=>"blob_plain
", hash=>$hash,
5052 hash_base=>$hash_base, file_name=>$file_name) .
5056 while (my $line = <$fd>) {
5059 $line = untabify
($line);
5060 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5061 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5065 or print "Reading blob failed.\n";
5071 if (!defined $hash_base) {
5072 $hash_base = "HEAD";
5074 if (!defined $hash) {
5075 if (defined $file_name) {
5076 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5081 die_error
(404, "No such tree") unless defined($hash);
5086 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5087 or die_error
(500, "Open git-ls-tree failed");
5088 @entries = map { chomp; $_ } <$fd>;
5090 or die_error
(404, "Reading tree failed");
5093 my $refs = git_get_references
();
5094 my $ref = format_ref_marker
($refs, $hash_base);
5097 my $have_blame = gitweb_check_feature
('blame');
5098 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5100 if (defined $file_name) {
5102 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5104 $cgi->a({-href
=> href
(action
=>"tree",
5105 hash_base
=>"HEAD", file_name
=>$file_name)},
5108 my $snapshot_links = format_snapshot_links
($hash);
5109 if (defined $snapshot_links) {
5110 # FIXME: Should be available when we have no hash base as well.
5111 push @views_nav, $snapshot_links;
5113 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5114 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5117 print "<div class=\"page_nav\">\n";
5118 print "<br/><br/></div>\n";
5119 print "<div class=\"title\">$hash</div>\n";
5121 if (defined $file_name) {
5122 $basedir = $file_name;
5123 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5126 git_print_page_path
($file_name, 'tree', $hash_base);
5128 print "<div class=\"page_body\">\n";
5129 print "<table class=\"tree\">\n";
5131 # '..' (top directory) link if possible
5132 if (defined $hash_base &&
5133 defined $file_name && $file_name =~ m![^/]+$!) {
5135 print "<tr class=\"dark\">\n";
5137 print "<tr class=\"light\">\n";
5141 my $up = $file_name;
5142 $up =~ s!/?[^/]+$!!;
5143 undef $up unless $up;
5144 # based on git_print_tree_entry
5145 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5146 print '<td class="list">';
5147 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5151 print "<td class=\"link\"></td>\n";
5155 foreach my $line (@entries) {
5156 my %t = parse_ls_tree_line
($line, -z
=> 1);
5159 print "<tr class=\"dark\">\n";
5161 print "<tr class=\"light\">\n";
5165 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5169 print "</table>\n" .
5175 my $format = $input_params{'snapshot_format'};
5176 if (!@snapshot_fmts) {
5177 die_error
(403, "Snapshots not allowed");
5179 # default to first supported snapshot format
5180 $format ||= $snapshot_fmts[0];
5181 if ($format !~ m/^[a-z0-9]+$/) {
5182 die_error
(400, "Invalid snapshot format parameter");
5183 } elsif (!exists($known_snapshot_formats{$format})) {
5184 die_error
(400, "Unknown snapshot format");
5185 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5186 die_error
(403, "Unsupported snapshot format");
5187 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5188 die_error
(403, "Snapshot format not allowed");
5191 if (!defined $hash) {
5192 $hash = git_get_head_hash
($project);
5195 my $name = $project;
5196 $name =~ s
,([^/])/*\
.git
$,$1,;
5197 $name = basename
($name);
5198 my $filename = to_utf8
($name);
5199 $name =~ s/\047/\047\\\047\047/g;
5201 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5202 $cmd = quote_command
(
5203 git_cmd
(), 'archive',
5204 "--format=$known_snapshot_formats{$format}{'format'}",
5205 "--prefix=$name/", $hash);
5206 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5207 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5211 -type
=> $known_snapshot_formats{$format}{'type'},
5212 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5213 -status
=> '200 OK');
5215 open my $fd, "-|", $cmd
5216 or die_error
(500, "Execute git-archive failed");
5217 binmode STDOUT
, ':raw';
5219 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5224 my $head = git_get_head_hash
($project);
5225 if (!defined $hash) {
5228 if (!defined $page) {
5231 my $refs = git_get_references
();
5233 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5235 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5237 my ($patch_max) = gitweb_get_feature
('patches');
5239 if ($patch_max < 0 || @commitlist <= $patch_max) {
5240 $paging_nav .= " ⋅ " .
5241 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5247 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5250 my %co = parse_commit
($hash);
5252 git_print_header_div
('summary', $project);
5253 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5255 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5256 for (my $i = 0; $i <= $to; $i++) {
5257 my %co = %{$commitlist[$i]};
5259 my $commit = $co{'id'};
5260 my $ref = format_ref_marker
($refs, $commit);
5261 my %ad = parse_date
($co{'author_epoch'});
5262 git_print_header_div
('commit',
5263 "<span class=\"age\">$co{'age_string'}</span>" .
5264 esc_html
($co{'title'}) . $ref,
5266 print "<div class=\"title_text\">\n" .
5267 "<div class=\"log_link\">\n" .
5268 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5270 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5272 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5275 git_print_authorship
(\
%co, -tag
=> 'span');
5276 print "<br/>\n</div>\n";
5278 print "<div class=\"log_body\">\n";
5279 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5282 if ($#commitlist >= 100) {
5283 print "<div class=\"page_nav\">\n";
5284 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5285 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5292 $hash ||= $hash_base || "HEAD";
5293 my %co = parse_commit
($hash)
5294 or die_error
(404, "Unknown commit object");
5296 my $parent = $co{'parent'};
5297 my $parents = $co{'parents'}; # listref
5299 # we need to prepare $formats_nav before any parameter munging
5301 if (!defined $parent) {
5303 $formats_nav .= '(initial)';
5304 } elsif (@$parents == 1) {
5305 # single parent commit
5308 $cgi->a({-href
=> href
(action
=>"commit",
5310 esc_html
(substr($parent, 0, 7))) .
5317 $cgi->a({-href
=> href
(action
=>"commit",
5319 esc_html
(substr($_, 0, 7)));
5323 if (gitweb_check_feature
('patches')) {
5324 $formats_nav .= " | " .
5325 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5329 if (!defined $parent) {
5333 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5335 (@$parents <= 1 ? $parent : '-c'),
5337 or die_error
(500, "Open git-diff-tree failed");
5338 @difftree = map { chomp; $_ } <$fd>;
5339 close $fd or die_error
(404, "Reading git-diff-tree failed");
5341 # non-textual hash id's can be cached
5343 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5346 my $refs = git_get_references
();
5347 my $ref = format_ref_marker
($refs, $co{'id'});
5349 git_header_html
(undef, $expires);
5350 git_print_page_nav
('commit', '',
5351 $hash, $co{'tree'}, $hash,
5354 if (defined $co{'parent'}) {
5355 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5357 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5359 print "<div class=\"title_text\">\n" .
5360 "<table class=\"object_header\">\n";
5361 git_print_authorship_rows
(\
%co);
5362 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5365 "<td class=\"sha1\">" .
5366 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5367 class => "list"}, $co{'tree'}) .
5369 "<td class=\"link\">" .
5370 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5372 my $snapshot_links = format_snapshot_links
($hash);
5373 if (defined $snapshot_links) {
5374 print " | " . $snapshot_links;
5379 foreach my $par (@$parents) {
5382 "<td class=\"sha1\">" .
5383 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5384 class => "list"}, $par) .
5386 "<td class=\"link\">" .
5387 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5389 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5396 print "<div class=\"page_body\">\n";
5397 git_print_log
($co{'comment'});
5400 git_difftree_body
(\
@difftree, $hash, @$parents);
5406 # object is defined by:
5407 # - hash or hash_base alone
5408 # - hash_base and file_name
5411 # - hash or hash_base alone
5412 if ($hash || ($hash_base && !defined $file_name)) {
5413 my $object_id = $hash || $hash_base;
5415 open my $fd, "-|", quote_command
(
5416 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5417 or die_error
(404, "Object does not exist");
5421 or die_error
(404, "Object does not exist");
5423 # - hash_base and file_name
5424 } elsif ($hash_base && defined $file_name) {
5425 $file_name =~ s
,/+$,,;
5427 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5428 or die_error
(404, "Base object does not exist");
5430 # here errors should not hapen
5431 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5432 or die_error
(500, "Open git-ls-tree failed");
5436 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5437 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5438 die_error
(404, "File or directory for given base does not exist");
5443 die_error
(400, "Not enough information to find object");
5446 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5447 hash
=>$hash, hash_base
=>$hash_base,
5448 file_name
=>$file_name),
5449 -status
=> '302 Found');
5453 my $format = shift || 'html';
5460 # preparing $fd and %diffinfo for git_patchset_body
5462 if (defined $hash_base && defined $hash_parent_base) {
5463 if (defined $file_name) {
5465 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5466 $hash_parent_base, $hash_base,
5467 "--", (defined $file_parent ? $file_parent : ()), $file_name
5468 or die_error
(500, "Open git-diff-tree failed");
5469 @difftree = map { chomp; $_ } <$fd>;
5471 or die_error
(404, "Reading git-diff-tree failed");
5473 or die_error
(404, "Blob diff not found");
5475 } elsif (defined $hash &&
5476 $hash =~ /[0-9a-fA-F]{40}/) {
5477 # try to find filename from $hash
5479 # read filtered raw output
5480 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5481 $hash_parent_base, $hash_base, "--"
5482 or die_error
(500, "Open git-diff-tree failed");
5484 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5486 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5487 map { chomp; $_ } <$fd>;
5489 or die_error
(404, "Reading git-diff-tree failed");
5491 or die_error
(404, "Blob diff not found");
5494 die_error
(400, "Missing one of the blob diff parameters");
5497 if (@difftree > 1) {
5498 die_error
(400, "Ambiguous blob diff specification");
5501 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5502 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5503 $file_name ||= $diffinfo{'to_file'};
5505 $hash_parent ||= $diffinfo{'from_id'};
5506 $hash ||= $diffinfo{'to_id'};
5508 # non-textual hash id's can be cached
5509 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5510 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5515 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5516 '-p', ($format eq 'html' ? "--full-index" : ()),
5517 $hash_parent_base, $hash_base,
5518 "--", (defined $file_parent ? $file_parent : ()), $file_name
5519 or die_error
(500, "Open git-diff-tree failed");
5522 # old/legacy style URI -- not generated anymore since 1.4.3.
5524 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5528 if ($format eq 'html') {
5530 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5532 git_header_html
(undef, $expires);
5533 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5534 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5535 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5537 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5538 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5540 if (defined $file_name) {
5541 git_print_page_path
($file_name, "blob", $hash_base);
5543 print "<div class=\"page_path\"></div>\n";
5546 } elsif ($format eq 'plain') {
5548 -type
=> 'text/plain',
5549 -charset
=> 'utf-8',
5550 -expires
=> $expires,
5551 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5553 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5556 die_error
(400, "Unknown blobdiff format");
5560 if ($format eq 'html') {
5561 print "<div class=\"page_body\">\n";
5563 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5566 print "</div>\n"; # class="page_body"
5570 while (my $line = <$fd>) {
5571 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5572 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5576 last if $line =~ m!^\+\+\+!;
5584 sub git_blobdiff_plain
{
5585 git_blobdiff
('plain');
5588 sub git_commitdiff
{
5590 my $format = $params{-format
} || 'html';
5592 my ($patch_max) = gitweb_get_feature
('patches');
5593 if ($format eq 'patch') {
5594 die_error
(403, "Patch view not allowed") unless $patch_max;
5597 $hash ||= $hash_base || "HEAD";
5598 my %co = parse_commit
($hash)
5599 or die_error
(404, "Unknown commit object");
5601 # choose format for commitdiff for merge
5602 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5603 $hash_parent = '--cc';
5605 # we need to prepare $formats_nav before almost any parameter munging
5607 if ($format eq 'html') {
5609 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5612 $formats_nav .= " | " .
5613 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5617 if (defined $hash_parent &&
5618 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5619 # commitdiff with two commits given
5620 my $hash_parent_short = $hash_parent;
5621 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5622 $hash_parent_short = substr($hash_parent, 0, 7);
5626 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5627 if ($co{'parents'}[$i] eq $hash_parent) {
5628 $formats_nav .= ' parent ' . ($i+1);
5632 $formats_nav .= ': ' .
5633 $cgi->a({-href
=> href
(action
=>"commitdiff",
5634 hash
=>$hash_parent)},
5635 esc_html
($hash_parent_short)) .
5637 } elsif (!$co{'parent'}) {
5639 $formats_nav .= ' (initial)';
5640 } elsif (scalar @{$co{'parents'}} == 1) {
5641 # single parent commit
5644 $cgi->a({-href
=> href
(action
=>"commitdiff",
5645 hash
=>$co{'parent'})},
5646 esc_html
(substr($co{'parent'}, 0, 7))) .
5650 if ($hash_parent eq '--cc') {
5651 $formats_nav .= ' | ' .
5652 $cgi->a({-href
=> href
(action
=>"commitdiff",
5653 hash
=>$hash, hash_parent
=>'-c')},
5655 } else { # $hash_parent eq '-c'
5656 $formats_nav .= ' | ' .
5657 $cgi->a({-href
=> href
(action
=>"commitdiff",
5658 hash
=>$hash, hash_parent
=>'--cc')},
5664 $cgi->a({-href
=> href
(action
=>"commitdiff",
5666 esc_html
(substr($_, 0, 7)));
5667 } @{$co{'parents'}} ) .
5672 my $hash_parent_param = $hash_parent;
5673 if (!defined $hash_parent_param) {
5674 # --cc for multiple parents, --root for parentless
5675 $hash_parent_param =
5676 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5682 if ($format eq 'html') {
5683 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5684 "--no-commit-id", "--patch-with-raw", "--full-index",
5685 $hash_parent_param, $hash, "--"
5686 or die_error
(500, "Open git-diff-tree failed");
5688 while (my $line = <$fd>) {
5690 # empty line ends raw part of diff-tree output
5692 push @difftree, scalar parse_difftree_raw_line
($line);
5695 } elsif ($format eq 'plain') {
5696 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5697 '-p', $hash_parent_param, $hash, "--"
5698 or die_error
(500, "Open git-diff-tree failed");
5699 } elsif ($format eq 'patch') {
5700 # For commit ranges, we limit the output to the number of
5701 # patches specified in the 'patches' feature.
5702 # For single commits, we limit the output to a single patch,
5703 # diverging from the git-format-patch default.
5704 my @commit_spec = ();
5706 if ($patch_max > 0) {
5707 push @commit_spec, "-$patch_max";
5709 push @commit_spec, '-n', "$hash_parent..$hash";
5711 if ($params{-single
}) {
5712 push @commit_spec, '-1';
5714 if ($patch_max > 0) {
5715 push @commit_spec, "-$patch_max";
5717 push @commit_spec, "-n";
5719 push @commit_spec, '--root', $hash;
5721 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5722 '--stdout', @commit_spec
5723 or die_error
(500, "Open git-format-patch failed");
5725 die_error
(400, "Unknown commitdiff format");
5728 # non-textual hash id's can be cached
5730 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5734 # write commit message
5735 if ($format eq 'html') {
5736 my $refs = git_get_references
();
5737 my $ref = format_ref_marker
($refs, $co{'id'});
5739 git_header_html
(undef, $expires);
5740 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5741 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5742 print "<div class=\"title_text\">\n" .
5743 "<table class=\"object_header\">\n";
5744 git_print_authorship_rows
(\
%co);
5747 print "<div class=\"page_body\">\n";
5748 if (@{$co{'comment'}} > 1) {
5749 print "<div class=\"log\">\n";
5750 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5751 print "</div>\n"; # class="log"
5754 } elsif ($format eq 'plain') {
5755 my $refs = git_get_references
("tags");
5756 my $tagname = git_get_rev_name_tags
($hash);
5757 my $filename = basename
($project) . "-$hash.patch";
5760 -type
=> 'text/plain',
5761 -charset
=> 'utf-8',
5762 -expires
=> $expires,
5763 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5764 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5765 print "From: " . to_utf8
($co{'author'}) . "\n";
5766 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5767 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5769 print "X-Git-Tag: $tagname\n" if $tagname;
5770 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5772 foreach my $line (@{$co{'comment'}}) {
5773 print to_utf8
($line) . "\n";
5776 } elsif ($format eq 'patch') {
5777 my $filename = basename
($project) . "-$hash.patch";
5780 -type
=> 'text/plain',
5781 -charset
=> 'utf-8',
5782 -expires
=> $expires,
5783 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5787 if ($format eq 'html') {
5788 my $use_parents = !defined $hash_parent ||
5789 $hash_parent eq '-c' || $hash_parent eq '--cc';
5790 git_difftree_body
(\
@difftree, $hash,
5791 $use_parents ? @{$co{'parents'}} : $hash_parent);
5794 git_patchset_body
($fd, \
@difftree, $hash,
5795 $use_parents ? @{$co{'parents'}} : $hash_parent);
5797 print "</div>\n"; # class="page_body"
5800 } elsif ($format eq 'plain') {
5804 or print "Reading git-diff-tree failed\n";
5805 } elsif ($format eq 'patch') {
5809 or print "Reading git-format-patch failed\n";
5813 sub git_commitdiff_plain
{
5814 git_commitdiff
(-format
=> 'plain');
5817 # format-patch-style patches
5819 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5823 git_commitdiff
(-format
=> 'patch');
5827 if (!defined $hash_base) {
5828 $hash_base = git_get_head_hash
($project);
5830 if (!defined $page) {
5834 my %co = parse_commit
($hash_base)
5835 or die_error
(404, "Unknown commit object");
5837 my $refs = git_get_references
();
5838 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5840 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5841 $file_name, "--full-history")
5842 or die_error
(404, "No such file or directory on given branch");
5844 if (!defined $hash && defined $file_name) {
5845 # some commits could have deleted file in question,
5846 # and not have it in tree, but one of them has to have it
5847 for (my $i = 0; $i <= @commitlist; $i++) {
5848 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5849 last if defined $hash;
5852 if (defined $hash) {
5853 $ftype = git_get_type
($hash);
5855 if (!defined $ftype) {
5856 die_error
(500, "Unknown type of object");
5859 my $paging_nav = '';
5862 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5863 file_name
=>$file_name)},
5865 $paging_nav .= " ⋅ " .
5866 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5867 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5869 $paging_nav .= "first";
5870 $paging_nav .= " ⋅ prev";
5873 if ($#commitlist >= 100) {
5875 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5876 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5877 $paging_nav .= " ⋅ $next_link";
5879 $paging_nav .= " ⋅ next";
5883 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5884 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5885 git_print_page_path
($file_name, $ftype, $hash_base);
5887 git_history_body
(\
@commitlist, 0, 99,
5888 $refs, $hash_base, $ftype, $next_link);
5894 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5895 if (!defined $searchtext) {
5896 die_error
(400, "Text field is empty");
5898 if (!defined $hash) {
5899 $hash = git_get_head_hash
($project);
5901 my %co = parse_commit
($hash);
5903 die_error
(404, "Unknown commit object");
5905 if (!defined $page) {
5909 $searchtype ||= 'commit';
5910 if ($searchtype eq 'pickaxe') {
5911 # pickaxe may take all resources of your box and run for several minutes
5912 # with every query - so decide by yourself how public you make this feature
5913 gitweb_check_feature
('pickaxe')
5914 or die_error
(403, "Pickaxe is disabled");
5916 if ($searchtype eq 'grep') {
5917 gitweb_check_feature
('grep')[0]
5918 or die_error
(403, "Grep is disabled");
5923 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5925 if ($searchtype eq 'commit') {
5926 $greptype = "--grep=";
5927 } elsif ($searchtype eq 'author') {
5928 $greptype = "--author=";
5929 } elsif ($searchtype eq 'committer') {
5930 $greptype = "--committer=";
5932 $greptype .= $searchtext;
5933 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5934 $greptype, '--regexp-ignore-case',
5935 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5937 my $paging_nav = '';
5940 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5941 searchtext
=>$searchtext,
5942 searchtype
=>$searchtype)},
5944 $paging_nav .= " ⋅ " .
5945 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5946 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5948 $paging_nav .= "first";
5949 $paging_nav .= " ⋅ prev";
5952 if ($#commitlist >= 100) {
5954 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5955 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5956 $paging_nav .= " ⋅ $next_link";
5958 $paging_nav .= " ⋅ next";
5961 if ($#commitlist >= 100) {
5964 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5965 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5966 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5969 if ($searchtype eq 'pickaxe') {
5970 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5971 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5973 print "<table class=\"pickaxe search\">\n";
5976 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5977 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5978 ($search_use_regexp ? '--pickaxe-regex' : ());
5981 while (my $line = <$fd>) {
5985 my %set = parse_difftree_raw_line
($line);
5986 if (defined $set{'commit'}) {
5987 # finish previous commit
5990 "<td class=\"link\">" .
5991 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5993 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5999 print "<tr class=\"dark\">\n";
6001 print "<tr class=\"light\">\n";
6004 %co = parse_commit
($set{'commit'});
6005 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6006 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6007 "<td><i>$author</i></td>\n" .
6009 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6010 -class => "list subject"},
6011 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6012 } elsif (defined $set{'to_id'}) {
6013 next if ($set{'to_id'} =~ m/^0{40}$/);
6015 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6016 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6018 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6024 # finish last commit (warning: repetition!)
6027 "<td class=\"link\">" .
6028 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6030 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6038 if ($searchtype eq 'grep') {
6039 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6040 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6042 print "<table class=\"grep_search\">\n";
6046 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6047 $search_use_regexp ? ('-E', '-i') : '-F',
6048 $searchtext, $co{'tree'};
6050 while (my $line = <$fd>) {
6052 my ($file, $lno, $ltext, $binary);
6053 last if ($matches++ > 1000);
6054 if ($line =~ /^Binary file (.+) matches$/) {
6058 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6060 if ($file ne $lastfile) {
6061 $lastfile and print "</td></tr>\n";
6063 print "<tr class=\"dark\">\n";
6065 print "<tr class=\"light\">\n";
6067 print "<td class=\"list\">".
6068 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6069 file_name
=>"$file"),
6070 -class => "list"}, esc_path
($file));
6071 print "</td><td>\n";
6075 print "<div class=\"binary\">Binary file</div>\n";
6077 $ltext = untabify
($ltext);
6078 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6079 $ltext = esc_html
($1, -nbsp
=>1);
6080 $ltext .= '<span class="match">';
6081 $ltext .= esc_html
($2, -nbsp
=>1);
6082 $ltext .= '</span>';
6083 $ltext .= esc_html
($3, -nbsp
=>1);
6085 $ltext = esc_html
($ltext, -nbsp
=>1);
6087 print "<div class=\"pre\">" .
6088 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6089 file_name
=>"$file").'#l'.$lno,
6090 -class => "linenr"}, sprintf('%4i', $lno))
6091 . ' ' . $ltext . "</div>\n";
6095 print "</td></tr>\n";
6096 if ($matches > 1000) {
6097 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6100 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6109 sub git_search_help
{
6111 git_print_page_nav
('','', $hash,$hash,$hash);
6113 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6114 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6115 the pattern entered is recognized as the POSIX extended
6116 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6119 <dt><b>commit</b></dt>
6120 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6122 my $have_grep = gitweb_check_feature
('grep');
6125 <dt><b>grep</b></dt>
6126 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6127 a different one) are searched for the given pattern. On large trees, this search can take
6128 a while and put some strain on the server, so please use it with some consideration. Note that
6129 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6130 case-sensitive.</dd>
6134 <dt><b>author</b></dt>
6135 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6136 <dt><b>committer</b></dt>
6137 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6139 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6140 if ($have_pickaxe) {
6142 <dt><b>pickaxe</b></dt>
6143 <dd>All commits that caused the string to appear or disappear from any file (changes that
6144 added, removed or "modified" the string) will be listed. This search can take a while and
6145 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6146 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6154 my $head = git_get_head_hash
($project);
6155 if (!defined $hash) {
6158 if (!defined $page) {
6161 my $refs = git_get_references
();
6163 my $commit_hash = $hash;
6164 if (defined $hash_parent) {
6165 $commit_hash = "$hash_parent..$hash";
6167 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6169 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6171 if ($#commitlist >= 100) {
6173 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6174 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6176 my $patch_max = gitweb_check_feature
('patches');
6178 if ($patch_max < 0 || @commitlist <= $patch_max) {
6179 $paging_nav .= " ⋅ " .
6180 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6186 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6187 git_print_header_div
('summary', $project);
6189 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6194 ## ......................................................................
6195 ## feeds (RSS, Atom; OPML)
6198 my $format = shift || 'atom';
6199 my $have_blame = gitweb_check_feature
('blame');
6201 # Atom: http://www.atomenabled.org/developers/syndication/
6202 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6203 if ($format ne 'rss' && $format ne 'atom') {
6204 die_error
(400, "Unknown web feed format");
6207 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6208 my $head = $hash || 'HEAD';
6209 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6213 my $content_type = "application/$format+xml";
6214 if (defined $cgi->http('HTTP_ACCEPT') &&
6215 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6216 # browser (feed reader) prefers text/xml
6217 $content_type = 'text/xml';
6219 if (defined($commitlist[0])) {
6220 %latest_commit = %{$commitlist[0]};
6221 my $latest_epoch = $latest_commit{'committer_epoch'};
6222 %latest_date = parse_date
($latest_epoch);
6223 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6224 if (defined $if_modified) {
6226 if (eval { require HTTP
::Date
; 1; }) {
6227 $since = HTTP
::Date
::str2time
($if_modified);
6228 } elsif (eval { require Time
::ParseDate
; 1; }) {
6229 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6231 if (defined $since && $latest_epoch <= $since) {
6233 -type
=> $content_type,
6234 -charset
=> 'utf-8',
6235 -last_modified
=> $latest_date{'rfc2822'},
6236 -status
=> '304 Not Modified');
6241 -type
=> $content_type,
6242 -charset
=> 'utf-8',
6243 -last_modified
=> $latest_date{'rfc2822'});
6246 -type
=> $content_type,
6247 -charset
=> 'utf-8');
6250 # Optimization: skip generating the body if client asks only
6251 # for Last-Modified date.
6252 return if ($cgi->request_method() eq 'HEAD');
6255 my $title = "$site_name - $project/$action";
6256 my $feed_type = 'log';
6257 if (defined $hash) {
6258 $title .= " - '$hash'";
6259 $feed_type = 'branch log';
6260 if (defined $file_name) {
6261 $title .= " :: $file_name";
6262 $feed_type = 'history';
6264 } elsif (defined $file_name) {
6265 $title .= " - $file_name";
6266 $feed_type = 'history';
6268 $title .= " $feed_type";
6269 my $descr = git_get_project_description
($project);
6270 if (defined $descr) {
6271 $descr = esc_html
($descr);
6273 $descr = "$project " .
6274 ($format eq 'rss' ? 'RSS' : 'Atom') .
6277 my $owner = git_get_project_owner
($project);
6278 $owner = esc_html
($owner);
6282 if (defined $file_name) {
6283 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6284 } elsif (defined $hash) {
6285 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6287 $alt_url = href
(-full
=>1, action
=>"summary");
6289 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6290 if ($format eq 'rss') {
6292 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6295 print "<title>$title</title>\n" .
6296 "<link>$alt_url</link>\n" .
6297 "<description>$descr</description>\n" .
6298 "<language>en</language>\n" .
6299 # project owner is responsible for 'editorial' content
6300 "<managingEditor>$owner</managingEditor>\n";
6301 if (defined $logo || defined $favicon) {
6302 # prefer the logo to the favicon, since RSS
6303 # doesn't allow both
6304 my $img = esc_url
($logo || $favicon);
6306 "<url>$img</url>\n" .
6307 "<title>$title</title>\n" .
6308 "<link>$alt_url</link>\n" .
6312 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6313 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6315 print "<generator>gitweb v.$version/$git_version</generator>\n";
6316 } elsif ($format eq 'atom') {
6318 <feed xmlns="http://www.w3.org/2005/Atom">
6320 print "<title>$title</title>\n" .
6321 "<subtitle>$descr</subtitle>\n" .
6322 '<link rel="alternate" type="text/html" href="' .
6323 $alt_url . '" />' . "\n" .
6324 '<link rel="self" type="' . $content_type . '" href="' .
6325 $cgi->self_url() . '" />' . "\n" .
6326 "<id>" . href
(-full
=>1) . "</id>\n" .
6327 # use project owner for feed author
6328 "<author><name>$owner</name></author>\n";
6329 if (defined $favicon) {
6330 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6332 if (defined $logo_url) {
6333 # not twice as wide as tall: 72 x 27 pixels
6334 print "<logo>" . esc_url
($logo) . "</logo>\n";
6336 if (! %latest_date) {
6337 # dummy date to keep the feed valid until commits trickle in:
6338 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6340 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6342 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6346 for (my $i = 0; $i <= $#commitlist; $i++) {
6347 my %co = %{$commitlist[$i]};
6348 my $commit = $co{'id'};
6349 # we read 150, we always show 30 and the ones more recent than 48 hours
6350 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6353 my %cd = parse_date
($co{'author_epoch'});
6355 # get list of changed files
6356 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6357 $co{'parent'} || "--root",
6358 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6360 my @difftree = map { chomp; $_ } <$fd>;
6364 # print element (entry, item)
6365 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6366 if ($format eq 'rss') {
6368 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6369 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6370 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6371 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6372 "<link>$co_url</link>\n" .
6373 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6374 "<content:encoded>" .
6376 } elsif ($format eq 'atom') {
6378 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6379 "<updated>$cd{'iso-8601'}</updated>\n" .
6381 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6382 if ($co{'author_email'}) {
6383 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6385 print "</author>\n" .
6386 # use committer for contributor
6388 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6389 if ($co{'committer_email'}) {
6390 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6392 print "</contributor>\n" .
6393 "<published>$cd{'iso-8601'}</published>\n" .
6394 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6395 "<id>$co_url</id>\n" .
6396 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6397 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6399 my $comment = $co{'comment'};
6401 foreach my $line (@$comment) {
6402 $line = esc_html
($line);
6405 print "</pre><ul>\n";
6406 foreach my $difftree_line (@difftree) {
6407 my %difftree = parse_difftree_raw_line
($difftree_line);
6408 next if !$difftree{'from_id'};
6410 my $file = $difftree{'file'} || $difftree{'to_file'};
6414 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6415 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6416 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6417 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6418 -title
=> "diff"}, 'D');
6420 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6421 file_name
=>$file, hash_base
=>$commit),
6422 -title
=> "blame"}, 'B');
6424 # if this is not a feed of a file history
6425 if (!defined $file_name || $file_name ne $file) {
6426 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6427 file_name
=>$file, hash
=>$commit),
6428 -title
=> "history"}, 'H');
6430 $file = esc_path
($file);
6434 if ($format eq 'rss') {
6435 print "</ul>]]>\n" .
6436 "</content:encoded>\n" .
6438 } elsif ($format eq 'atom') {
6439 print "</ul>\n</div>\n" .
6446 if ($format eq 'rss') {
6447 print "</channel>\n</rss>\n";
6448 } elsif ($format eq 'atom') {
6462 my @list = git_get_projects_list
();
6465 -type
=> 'text/xml',
6466 -charset
=> 'utf-8',
6467 -content_disposition
=> 'inline; filename="opml.xml"');
6470 <?xml version="1.0" encoding="utf-8"?>
6471 <opml version="1.0">
6473 <title>$site_name OPML Export</title>
6476 <outline text="git RSS feeds">
6479 foreach my $pr (@list) {
6481 my $head = git_get_head_hash
($proj{'path'});
6482 if (!defined $head) {
6485 $git_dir = "$projectroot/$proj{'path'}";
6486 my %co = parse_commit
($head);
6491 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6492 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6493 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6494 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";