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)}
167 'display' => 'tar.gz',
168 'type' => 'application/x-gzip',
169 'suffix' => '.tar.gz',
171 'compressor' => ['gzip']},
174 'display' => 'tar.bz2',
175 'type' => 'application/x-bzip2',
176 'suffix' => '.tar.bz2',
178 'compressor' => ['bzip2']},
182 'type' => 'application/x-zip',
187 # Aliases so we understand old gitweb.snapshot values in repository
189 our %known_snapshot_format_aliases = (
193 # backward compatibility: legacy gitweb config support
194 'x-gzip' => undef, 'gz' => undef,
195 'x-bzip2' => undef, 'bz2' => undef,
196 'x-zip' => undef, '' => undef,
199 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
200 # are changed, it may be appropriate to change these values too via
207 # You define site-wide feature defaults here; override them with
208 # $GITWEB_CONFIG as necessary.
211 # 'sub' => feature-sub (subroutine),
212 # 'override' => allow-override (boolean),
213 # 'default' => [ default options...] (array reference)}
215 # if feature is overridable (it means that allow-override has true value),
216 # then feature-sub will be called with default options as parameters;
217 # return value of feature-sub indicates if to enable specified feature
219 # if there is no 'sub' key (no feature-sub), then feature cannot be
222 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
223 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
226 # Enable the 'blame' blob view, showing the last commit that modified
227 # each line in the file. This can be very CPU-intensive.
229 # To enable system wide have in $GITWEB_CONFIG
230 # $feature{'blame'}{'default'} = [1];
231 # To have project specific config enable override in $GITWEB_CONFIG
232 # $feature{'blame'}{'override'} = 1;
233 # and in project config gitweb.blame = 0|1;
235 'sub' => sub { feature_bool
('blame', @_) },
239 # Enable the 'snapshot' link, providing a compressed archive of any
240 # tree. This can potentially generate high traffic if you have large
243 # Value is a list of formats defined in %known_snapshot_formats that
245 # To disable system wide have in $GITWEB_CONFIG
246 # $feature{'snapshot'}{'default'} = [];
247 # To have project specific config enable override in $GITWEB_CONFIG
248 # $feature{'snapshot'}{'override'} = 1;
249 # and in project config, a comma-separated list of formats or "none"
250 # to disable. Example: gitweb.snapshot = tbz2,zip;
252 'sub' => \
&feature_snapshot
,
254 'default' => ['tgz']},
256 # Enable text search, which will list the commits which match author,
257 # committer or commit text to a given string. Enabled by default.
258 # Project specific override is not supported.
263 # Enable grep search, which will list the files in currently selected
264 # tree containing the given string. Enabled by default. This can be
265 # potentially CPU-intensive, of course.
267 # To enable system wide have in $GITWEB_CONFIG
268 # $feature{'grep'}{'default'} = [1];
269 # To have project specific config enable override in $GITWEB_CONFIG
270 # $feature{'grep'}{'override'} = 1;
271 # and in project config gitweb.grep = 0|1;
273 'sub' => sub { feature_bool
('grep', @_) },
277 # Enable the pickaxe search, which will list the commits that modified
278 # a given string in a file. This can be practical and quite faster
279 # alternative to 'blame', but still potentially CPU-intensive.
281 # To enable system wide have in $GITWEB_CONFIG
282 # $feature{'pickaxe'}{'default'} = [1];
283 # To have project specific config enable override in $GITWEB_CONFIG
284 # $feature{'pickaxe'}{'override'} = 1;
285 # and in project config gitweb.pickaxe = 0|1;
287 'sub' => sub { feature_bool
('pickaxe', @_) },
291 # Make gitweb use an alternative format of the URLs which can be
292 # more readable and natural-looking: project name is embedded
293 # directly in the path and the query string contains other
294 # auxiliary information. All gitweb installations recognize
295 # URL in either format; this configures in which formats gitweb
298 # To enable system wide have in $GITWEB_CONFIG
299 # $feature{'pathinfo'}{'default'} = [1];
300 # Project specific override is not supported.
302 # Note that you will need to change the default location of CSS,
303 # favicon, logo and possibly other files to an absolute URL. Also,
304 # if gitweb.cgi serves as your indexfile, you will need to force
305 # $my_uri to contain the script name in your $GITWEB_CONFIG.
310 # Make gitweb consider projects in project root subdirectories
311 # to be forks of existing projects. Given project $projname.git,
312 # projects matching $projname/*.git will not be shown in the main
313 # projects list, instead a '+' mark will be added to $projname
314 # there and a 'forks' view will be enabled for the project, listing
315 # all the forks. If project list is taken from a file, forks have
316 # to be listed after the main project.
318 # To enable system wide have in $GITWEB_CONFIG
319 # $feature{'forks'}{'default'} = [1];
320 # Project specific override is not supported.
325 # Insert custom links to the action bar of all project pages.
326 # This enables you mainly to link to third-party scripts integrating
327 # into gitweb; e.g. git-browser for graphical history representation
328 # or custom web-based repository administration interface.
330 # The 'default' value consists of a list of triplets in the form
331 # (label, link, position) where position is the label after which
332 # to insert the link and link is a format string where %n expands
333 # to the project name, %f to the project path within the filesystem,
334 # %h to the current hash (h gitweb parameter) and %b to the current
335 # hash base (hb gitweb parameter); %% expands to %.
337 # To enable system wide have in $GITWEB_CONFIG e.g.
338 # $feature{'actions'}{'default'} = [('graphiclog',
339 # '/git-browser/by-commit.html?r=%n', 'summary')];
340 # Project specific override is not supported.
345 # Allow gitweb scan project content tags described in ctags/
346 # of project repository, and display the popular Web 2.0-ish
347 # "tag cloud" near the project list. Note that this is something
348 # COMPLETELY different from the normal Git tags.
350 # gitweb by itself can show existing tags, but it does not handle
351 # tagging itself; you need an external application for that.
352 # For an example script, check Girocco's cgi/tagproj.cgi.
353 # You may want to install the HTML::TagCloud Perl module to get
354 # a pretty tag cloud instead of just a list of tags.
356 # To enable system wide have in $GITWEB_CONFIG
357 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
358 # Project specific override is not supported.
363 # The maximum number of patches in a patchset generated in patch
364 # view. Set this to 0 or undef to disable patch view, or to a
365 # negative number to remove any limit.
367 # To disable system wide have in $GITWEB_CONFIG
368 # $feature{'patches'}{'default'} = [0];
369 # To have project specific config enable override in $GITWEB_CONFIG
370 # $feature{'patches'}{'override'} = 1;
371 # and in project config gitweb.patches = 0|n;
372 # where n is the maximum number of patches allowed in a patchset.
374 'sub' => \
&feature_patches
,
378 # Avatar support. When this feature is enabled, views such as
379 # shortlog or commit will display an avatar associated with
380 # the email of the committer(s) and/or author(s).
382 # Currently available providers are gravatar and picon.
383 # If an unknown provider is specified, the feature is disabled.
385 # Gravatar depends on Digest::MD5.
386 # Picon currently relies on the indiana.edu database.
388 # To enable system wide have in $GITWEB_CONFIG
389 # $feature{'avatar'}{'default'} = ['<provider>'];
390 # where <provider> is either gravatar or picon.
391 # To have project specific config enable override in $GITWEB_CONFIG
392 # $feature{'avatar'}{'override'} = 1;
393 # and in project config gitweb.avatar = <provider>;
395 'sub' => \
&feature_avatar
,
400 sub gitweb_get_feature
{
402 return unless exists $feature{$name};
403 my ($sub, $override, @defaults) = (
404 $feature{$name}{'sub'},
405 $feature{$name}{'override'},
406 @{$feature{$name}{'default'}});
407 if (!$override) { return @defaults; }
409 warn "feature $name is not overrideable";
412 return $sub->(@defaults);
415 # A wrapper to check if a given feature is enabled.
416 # With this, you can say
418 # my $bool_feat = gitweb_check_feature('bool_feat');
419 # gitweb_check_feature('bool_feat') or somecode;
423 # my ($bool_feat) = gitweb_get_feature('bool_feat');
424 # (gitweb_get_feature('bool_feat'))[0] or somecode;
426 sub gitweb_check_feature
{
427 return (gitweb_get_feature
(@_))[0];
433 my ($val) = git_get_project_config
($key, '--bool');
437 } elsif ($val eq 'true') {
439 } elsif ($val eq 'false') {
444 sub feature_snapshot
{
447 my ($val) = git_get_project_config
('snapshot');
450 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
456 sub feature_patches
{
457 my @val = (git_get_project_config
('patches', '--int'));
467 my @val = (git_get_project_config
('avatar'));
469 return @val ? @val : @_;
472 # checking HEAD file with -e is fragile if the repository was
473 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
475 sub check_head_link
{
477 my $headfile = "$dir/HEAD";
478 return ((-e
$headfile) ||
479 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
482 sub check_export_ok
{
484 return (check_head_link
($dir) &&
485 (!$export_ok || -e
"$dir/$export_ok") &&
486 (!$export_auth_hook || $export_auth_hook->($dir)));
489 # process alternate names for backward compatibility
490 # filter out unsupported (unknown) snapshot formats
491 sub filter_snapshot_fmts
{
495 exists $known_snapshot_format_aliases{$_} ?
496 $known_snapshot_format_aliases{$_} : $_} @fmts;
498 exists $known_snapshot_formats{$_} } @fmts;
501 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
502 if (-e
$GITWEB_CONFIG) {
505 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
506 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
509 # version of the core git binary
510 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
512 $projects_list ||= $projectroot;
514 # ======================================================================
515 # input validation and dispatch
517 # input parameters can be collected from a variety of sources (presently, CGI
518 # and PATH_INFO), so we define an %input_params hash that collects them all
519 # together during validation: this allows subsequent uses (e.g. href()) to be
520 # agnostic of the parameter origin
522 our %input_params = ();
524 # input parameters are stored with the long parameter name as key. This will
525 # also be used in the href subroutine to convert parameters to their CGI
526 # equivalent, and since the href() usage is the most frequent one, we store
527 # the name -> CGI key mapping here, instead of the reverse.
529 # XXX: Warning: If you touch this, check the search form for updating,
532 our @cgi_param_mapping = (
540 hash_parent_base
=> "hpb",
545 snapshot_format
=> "sf",
546 extra_options
=> "opt",
547 search_use_regexp
=> "sr",
549 our %cgi_param_mapping = @cgi_param_mapping;
551 # we will also need to know the possible actions, for validation
553 "blame" => \
&git_blame
,
554 "blobdiff" => \
&git_blobdiff
,
555 "blobdiff_plain" => \
&git_blobdiff_plain
,
556 "blob" => \
&git_blob
,
557 "blob_plain" => \
&git_blob_plain
,
558 "commitdiff" => \
&git_commitdiff
,
559 "commitdiff_plain" => \
&git_commitdiff_plain
,
560 "commit" => \
&git_commit
,
561 "forks" => \
&git_forks
,
562 "heads" => \
&git_heads
,
563 "history" => \
&git_history
,
565 "patch" => \
&git_patch
,
566 "patches" => \
&git_patches
,
568 "atom" => \
&git_atom
,
569 "search" => \
&git_search
,
570 "search_help" => \
&git_search_help
,
571 "shortlog" => \
&git_shortlog
,
572 "summary" => \
&git_summary
,
574 "tags" => \
&git_tags
,
575 "tree" => \
&git_tree
,
576 "snapshot" => \
&git_snapshot
,
577 "object" => \
&git_object
,
578 # those below don't need $project
579 "opml" => \
&git_opml
,
580 "project_list" => \
&git_project_list
,
581 "project_index" => \
&git_project_index
,
584 # finally, we have the hash of allowed extra_options for the commands that
586 our %allowed_options = (
587 "--no-merges" => [ qw(rss atom log shortlog history) ],
590 # fill %input_params with the CGI parameters. All values except for 'opt'
591 # should be single values, but opt can be an array. We should probably
592 # build an array of parameters that can be multi-valued, but since for the time
593 # being it's only this one, we just single it out
594 while (my ($name, $symbol) = each %cgi_param_mapping) {
595 if ($symbol eq 'opt') {
596 $input_params{$name} = [ $cgi->param($symbol) ];
598 $input_params{$name} = $cgi->param($symbol);
602 # now read PATH_INFO and update the parameter list for missing parameters
603 sub evaluate_path_info
{
604 return if defined $input_params{'project'};
605 return if !$path_info;
606 $path_info =~ s
,^/+,,;
607 return if !$path_info;
609 # find which part of PATH_INFO is project
610 my $project = $path_info;
612 while ($project && !check_head_link
("$projectroot/$project")) {
613 $project =~ s
,/*[^/]*$,,;
615 return unless $project;
616 $input_params{'project'} = $project;
618 # do not change any parameters if an action is given using the query string
619 return if $input_params{'action'};
620 $path_info =~ s
,^\Q
$project\E
/*,,;
622 # next, check if we have an action
623 my $action = $path_info;
625 if (exists $actions{$action}) {
626 $path_info =~ s
,^$action/*,,;
627 $input_params{'action'} = $action;
630 # list of actions that want hash_base instead of hash, but can have no
631 # pathname (f) parameter
638 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
639 my ($parentrefname, $parentpathname, $refname, $pathname) =
640 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
642 # first, analyze the 'current' part
643 if (defined $pathname) {
644 # we got "branch:filename" or "branch:dir/"
645 # we could use git_get_type(branch:pathname), but:
646 # - it needs $git_dir
647 # - it does a git() call
648 # - the convention of terminating directories with a slash
649 # makes it superfluous
650 # - embedding the action in the PATH_INFO would make it even
652 $pathname =~ s
,^/+,,;
653 if (!$pathname || substr($pathname, -1) eq "/") {
654 $input_params{'action'} ||= "tree";
657 # the default action depends on whether we had parent info
659 if ($parentrefname) {
660 $input_params{'action'} ||= "blobdiff_plain";
662 $input_params{'action'} ||= "blob_plain";
665 $input_params{'hash_base'} ||= $refname;
666 $input_params{'file_name'} ||= $pathname;
667 } elsif (defined $refname) {
668 # we got "branch". In this case we have to choose if we have to
669 # set hash or hash_base.
671 # Most of the actions without a pathname only want hash to be
672 # set, except for the ones specified in @wants_base that want
673 # hash_base instead. It should also be noted that hand-crafted
674 # links having 'history' as an action and no pathname or hash
675 # set will fail, but that happens regardless of PATH_INFO.
676 $input_params{'action'} ||= "shortlog";
677 if (grep { $_ eq $input_params{'action'} } @wants_base) {
678 $input_params{'hash_base'} ||= $refname;
680 $input_params{'hash'} ||= $refname;
684 # next, handle the 'parent' part, if present
685 if (defined $parentrefname) {
686 # a missing pathspec defaults to the 'current' filename, allowing e.g.
687 # someproject/blobdiff/oldrev..newrev:/filename
688 if ($parentpathname) {
689 $parentpathname =~ s
,^/+,,;
690 $parentpathname =~ s
,/$,,;
691 $input_params{'file_parent'} ||= $parentpathname;
693 $input_params{'file_parent'} ||= $input_params{'file_name'};
695 # we assume that hash_parent_base is wanted if a path was specified,
696 # or if the action wants hash_base instead of hash
697 if (defined $input_params{'file_parent'} ||
698 grep { $_ eq $input_params{'action'} } @wants_base) {
699 $input_params{'hash_parent_base'} ||= $parentrefname;
701 $input_params{'hash_parent'} ||= $parentrefname;
705 # for the snapshot action, we allow URLs in the form
706 # $project/snapshot/$hash.ext
707 # where .ext determines the snapshot and gets removed from the
708 # passed $refname to provide the $hash.
710 # To be able to tell that $refname includes the format extension, we
711 # require the following two conditions to be satisfied:
712 # - the hash input parameter MUST have been set from the $refname part
713 # of the URL (i.e. they must be equal)
714 # - the snapshot format MUST NOT have been defined already (e.g. from
716 # It's also useless to try any matching unless $refname has a dot,
717 # so we check for that too
718 if (defined $input_params{'action'} &&
719 $input_params{'action'} eq 'snapshot' &&
720 defined $refname && index($refname, '.') != -1 &&
721 $refname eq $input_params{'hash'} &&
722 !defined $input_params{'snapshot_format'}) {
723 # We loop over the known snapshot formats, checking for
724 # extensions. Allowed extensions are both the defined suffix
725 # (which includes the initial dot already) and the snapshot
726 # format key itself, with a prepended dot
727 while (my ($fmt, $opt) = each %known_snapshot_formats) {
729 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
733 # a valid suffix was found, so set the snapshot format
734 # and reset the hash parameter
735 $input_params{'snapshot_format'} = $fmt;
736 $input_params{'hash'} = $hash;
737 # we also set the format suffix to the one requested
738 # in the URL: this way a request for e.g. .tgz returns
739 # a .tgz instead of a .tar.gz
740 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
745 evaluate_path_info
();
747 our $action = $input_params{'action'};
748 if (defined $action) {
749 if (!validate_action
($action)) {
750 die_error
(400, "Invalid action parameter");
754 # parameters which are pathnames
755 our $project = $input_params{'project'};
756 if (defined $project) {
757 if (!validate_project
($project)) {
759 die_error
(404, "No such project");
763 our $file_name = $input_params{'file_name'};
764 if (defined $file_name) {
765 if (!validate_pathname
($file_name)) {
766 die_error
(400, "Invalid file parameter");
770 our $file_parent = $input_params{'file_parent'};
771 if (defined $file_parent) {
772 if (!validate_pathname
($file_parent)) {
773 die_error
(400, "Invalid file parent parameter");
777 # parameters which are refnames
778 our $hash = $input_params{'hash'};
780 if (!validate_refname
($hash)) {
781 die_error
(400, "Invalid hash parameter");
785 our $hash_parent = $input_params{'hash_parent'};
786 if (defined $hash_parent) {
787 if (!validate_refname
($hash_parent)) {
788 die_error
(400, "Invalid hash parent parameter");
792 our $hash_base = $input_params{'hash_base'};
793 if (defined $hash_base) {
794 if (!validate_refname
($hash_base)) {
795 die_error
(400, "Invalid hash base parameter");
799 our @extra_options = @{$input_params{'extra_options'}};
800 # @extra_options is always defined, since it can only be (currently) set from
801 # CGI, and $cgi->param() returns the empty array in array context if the param
803 foreach my $opt (@extra_options) {
804 if (not exists $allowed_options{$opt}) {
805 die_error
(400, "Invalid option parameter");
807 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
808 die_error
(400, "Invalid option parameter for this action");
812 our $hash_parent_base = $input_params{'hash_parent_base'};
813 if (defined $hash_parent_base) {
814 if (!validate_refname
($hash_parent_base)) {
815 die_error
(400, "Invalid hash parent base parameter");
820 our $page = $input_params{'page'};
822 if ($page =~ m/[^0-9]/) {
823 die_error
(400, "Invalid page parameter");
827 our $searchtype = $input_params{'searchtype'};
828 if (defined $searchtype) {
829 if ($searchtype =~ m/[^a-z]/) {
830 die_error
(400, "Invalid searchtype parameter");
834 our $search_use_regexp = $input_params{'search_use_regexp'};
836 our $searchtext = $input_params{'searchtext'};
838 if (defined $searchtext) {
839 if (length($searchtext) < 2) {
840 die_error
(403, "At least two characters are required for search parameter");
842 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
845 # path to the current git repository
847 $git_dir = "$projectroot/$project" if $project;
849 # list of supported snapshot formats
850 our @snapshot_fmts = gitweb_get_feature
('snapshot');
851 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
853 # check that the avatar feature is set to a known provider name,
854 # and for each provider check if the dependencies are satisfied.
855 # if the provider name is invalid or the dependencies are not met,
856 # reset $git_avatar to the empty string.
857 our ($git_avatar) = gitweb_get_feature
('avatar');
858 if ($git_avatar eq 'gravatar') {
859 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
860 } elsif ($git_avatar eq 'picon') {
867 if (!defined $action) {
869 $action = git_get_type
($hash);
870 } elsif (defined $hash_base && defined $file_name) {
871 $action = git_get_type
("$hash_base:$file_name");
872 } elsif (defined $project) {
875 $action = 'project_list';
878 if (!defined($actions{$action})) {
879 die_error
(400, "Unknown action");
881 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
883 die_error
(400, "Project needed");
885 $actions{$action}->();
888 ## ======================================================================
893 # default is to use -absolute url() i.e. $my_uri
894 my $href = $params{-full
} ? $my_url : $my_uri;
896 $params{'project'} = $project unless exists $params{'project'};
898 if ($params{-replay
}) {
899 while (my ($name, $symbol) = each %cgi_param_mapping) {
900 if (!exists $params{$name}) {
901 $params{$name} = $input_params{$name};
906 my $use_pathinfo = gitweb_check_feature
('pathinfo');
907 if ($use_pathinfo and defined $params{'project'}) {
908 # try to put as many parameters as possible in PATH_INFO:
911 # - hash_parent or hash_parent_base:/file_parent
912 # - hash or hash_base:/filename
913 # - the snapshot_format as an appropriate suffix
915 # When the script is the root DirectoryIndex for the domain,
916 # $href here would be something like http://gitweb.example.com/
917 # Thus, we strip any trailing / from $href, to spare us double
918 # slashes in the final URL
921 # Then add the project name, if present
922 $href .= "/".esc_url
($params{'project'});
923 delete $params{'project'};
925 # since we destructively absorb parameters, we keep this
926 # boolean that remembers if we're handling a snapshot
927 my $is_snapshot = $params{'action'} eq 'snapshot';
929 # Summary just uses the project path URL, any other action is
931 if (defined $params{'action'}) {
932 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
933 delete $params{'action'};
936 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
937 # stripping nonexistent or useless pieces
938 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
939 || $params{'hash_parent'} || $params{'hash'});
940 if (defined $params{'hash_base'}) {
941 if (defined $params{'hash_parent_base'}) {
942 $href .= esc_url
($params{'hash_parent_base'});
943 # skip the file_parent if it's the same as the file_name
944 if (defined $params{'file_parent'}) {
945 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
946 delete $params{'file_parent'};
947 } elsif ($params{'file_parent'} !~ /\.\./) {
948 $href .= ":/".esc_url
($params{'file_parent'});
949 delete $params{'file_parent'};
953 delete $params{'hash_parent'};
954 delete $params{'hash_parent_base'};
955 } elsif (defined $params{'hash_parent'}) {
956 $href .= esc_url
($params{'hash_parent'}). "..";
957 delete $params{'hash_parent'};
960 $href .= esc_url
($params{'hash_base'});
961 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
962 $href .= ":/".esc_url
($params{'file_name'});
963 delete $params{'file_name'};
965 delete $params{'hash'};
966 delete $params{'hash_base'};
967 } elsif (defined $params{'hash'}) {
968 $href .= esc_url
($params{'hash'});
969 delete $params{'hash'};
972 # If the action was a snapshot, we can absorb the
973 # snapshot_format parameter too
975 my $fmt = $params{'snapshot_format'};
976 # snapshot_format should always be defined when href()
977 # is called, but just in case some code forgets, we
978 # fall back to the default
979 $fmt ||= $snapshot_fmts[0];
980 $href .= $known_snapshot_formats{$fmt}{'suffix'};
981 delete $params{'snapshot_format'};
985 # now encode the parameters explicitly
987 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
988 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
989 if (defined $params{$name}) {
990 if (ref($params{$name}) eq "ARRAY") {
991 foreach my $par (@{$params{$name}}) {
992 push @result, $symbol . "=" . esc_param
($par);
995 push @result, $symbol . "=" . esc_param
($params{$name});
999 $href .= "?" . join(';', @result) if scalar @result;
1005 ## ======================================================================
1006 ## validation, quoting/unquoting and escaping
1008 sub validate_action
{
1009 my $input = shift || return undef;
1010 return undef unless exists $actions{$input};
1014 sub validate_project
{
1015 my $input = shift || return undef;
1016 if (!validate_pathname
($input) ||
1017 !(-d
"$projectroot/$input") ||
1018 !check_export_ok
("$projectroot/$input") ||
1019 ($strict_export && !project_in_list
($input))) {
1026 sub validate_pathname
{
1027 my $input = shift || return undef;
1029 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1030 # at the beginning, at the end, and between slashes.
1031 # also this catches doubled slashes
1032 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1035 # no null characters
1036 if ($input =~ m!\0!) {
1042 sub validate_refname
{
1043 my $input = shift || return undef;
1045 # textual hashes are O.K.
1046 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1049 # it must be correct pathname
1050 $input = validate_pathname
($input)
1052 # restrictions on ref name according to git-check-ref-format
1053 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1059 # decode sequences of octets in utf8 into Perl's internal form,
1060 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1061 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1064 if (utf8
::valid
($str)) {
1068 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1072 # quote unsafe chars, but keep the slash, even when it's not
1073 # correct, but quoted slashes look too horrible in bookmarks
1076 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1082 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1085 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1091 # replace invalid utf8 character with SUBSTITUTION sequence
1096 $str = to_utf8
($str);
1097 $str = $cgi->escapeHTML($str);
1098 if ($opts{'-nbsp'}) {
1099 $str =~ s/ / /g;
1101 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1105 # quote control characters and escape filename to HTML
1110 $str = to_utf8
($str);
1111 $str = $cgi->escapeHTML($str);
1112 if ($opts{'-nbsp'}) {
1113 $str =~ s/ / /g;
1115 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1119 # Make control characters "printable", using character escape codes (CEC)
1123 my %es = ( # character escape codes, aka escape sequences
1124 "\t" => '\t', # tab (HT)
1125 "\n" => '\n', # line feed (LF)
1126 "\r" => '\r', # carrige return (CR)
1127 "\f" => '\f', # form feed (FF)
1128 "\b" => '\b', # backspace (BS)
1129 "\a" => '\a', # alarm (bell) (BEL)
1130 "\e" => '\e', # escape (ESC)
1131 "\013" => '\v', # vertical tab (VT)
1132 "\000" => '\0', # nul character (NUL)
1134 my $chr = ( (exists $es{$cntrl})
1136 : sprintf('\%2x', ord($cntrl)) );
1137 if ($opts{-nohtml
}) {
1140 return "<span class=\"cntrl\">$chr</span>";
1144 # Alternatively use unicode control pictures codepoints,
1145 # Unicode "printable representation" (PR)
1150 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1151 if ($opts{-nohtml
}) {
1154 return "<span class=\"cntrl\">$chr</span>";
1158 # git may return quoted and escaped filenames
1164 my %es = ( # character escape codes, aka escape sequences
1165 't' => "\t", # tab (HT, TAB)
1166 'n' => "\n", # newline (NL)
1167 'r' => "\r", # return (CR)
1168 'f' => "\f", # form feed (FF)
1169 'b' => "\b", # backspace (BS)
1170 'a' => "\a", # alarm (bell) (BEL)
1171 'e' => "\e", # escape (ESC)
1172 'v' => "\013", # vertical tab (VT)
1175 if ($seq =~ m/^[0-7]{1,3}$/) {
1176 # octal char sequence
1177 return chr(oct($seq));
1178 } elsif (exists $es{$seq}) {
1179 # C escape sequence, aka character escape code
1182 # quoted ordinary character
1186 if ($str =~ m/^"(.*)"$/) {
1189 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1194 # escape tabs (convert tabs to spaces)
1198 while ((my $pos = index($line, "\t")) != -1) {
1199 if (my $count = (8 - ($pos % 8))) {
1200 my $spaces = ' ' x
$count;
1201 $line =~ s/\t/$spaces/;
1208 sub project_in_list
{
1209 my $project = shift;
1210 my @list = git_get_projects_list
();
1211 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1214 ## ----------------------------------------------------------------------
1215 ## HTML aware string manipulation
1217 # Try to chop given string on a word boundary between position
1218 # $len and $len+$add_len. If there is no word boundary there,
1219 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1220 # (marking chopped part) would be longer than given string.
1224 my $add_len = shift || 10;
1225 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1227 # Make sure perl knows it is utf8 encoded so we don't
1228 # cut in the middle of a utf8 multibyte char.
1229 $str = to_utf8
($str);
1231 # allow only $len chars, but don't cut a word if it would fit in $add_len
1232 # if it doesn't fit, cut it if it's still longer than the dots we would add
1233 # remove chopped character entities entirely
1235 # when chopping in the middle, distribute $len into left and right part
1236 # return early if chopping wouldn't make string shorter
1237 if ($where eq 'center') {
1238 return $str if ($len + 5 >= length($str)); # filler is length 5
1241 return $str if ($len + 4 >= length($str)); # filler is length 4
1244 # regexps: ending and beginning with word part up to $add_len
1245 my $endre = qr/.{$len}\w{0,$add_len}/;
1246 my $begre = qr/\w{0,$add_len}.{$len}/;
1248 if ($where eq 'left') {
1249 $str =~ m/^(.*?)($begre)$/;
1250 my ($lead, $body) = ($1, $2);
1251 if (length($lead) > 4) {
1252 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1255 return "$lead$body";
1257 } elsif ($where eq 'center') {
1258 $str =~ m/^($endre)(.*)$/;
1259 my ($left, $str) = ($1, $2);
1260 $str =~ m/^(.*?)($begre)$/;
1261 my ($mid, $right) = ($1, $2);
1262 if (length($mid) > 5) {
1263 $left =~ s/&[^;]*$//;
1264 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1267 return "$left$mid$right";
1270 $str =~ m/^($endre)(.*)$/;
1273 if (length($tail) > 4) {
1274 $body =~ s/&[^;]*$//;
1277 return "$body$tail";
1281 # takes the same arguments as chop_str, but also wraps a <span> around the
1282 # result with a title attribute if it does get chopped. Additionally, the
1283 # string is HTML-escaped.
1284 sub chop_and_escape_str
{
1287 my $chopped = chop_str
(@_);
1288 if ($chopped eq $str) {
1289 return esc_html
($chopped);
1291 $str =~ s/[[:cntrl:]]/?/g;
1292 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1296 ## ----------------------------------------------------------------------
1297 ## functions returning short strings
1299 # CSS class for given age value (in seconds)
1303 if (!defined $age) {
1305 } elsif ($age < 60*60*2) {
1307 } elsif ($age < 60*60*24*2) {
1314 # convert age in seconds to "nn units ago" string
1319 if ($age > 60*60*24*365*2) {
1320 $age_str = (int $age/60/60/24/365);
1321 $age_str .= " years ago";
1322 } elsif ($age > 60*60*24*(365/12)*2) {
1323 $age_str = int $age/60/60/24/(365/12);
1324 $age_str .= " months ago";
1325 } elsif ($age > 60*60*24*7*2) {
1326 $age_str = int $age/60/60/24/7;
1327 $age_str .= " weeks ago";
1328 } elsif ($age > 60*60*24*2) {
1329 $age_str = int $age/60/60/24;
1330 $age_str .= " days ago";
1331 } elsif ($age > 60*60*2) {
1332 $age_str = int $age/60/60;
1333 $age_str .= " hours ago";
1334 } elsif ($age > 60*2) {
1335 $age_str = int $age/60;
1336 $age_str .= " min ago";
1337 } elsif ($age > 2) {
1338 $age_str = int $age;
1339 $age_str .= " sec ago";
1341 $age_str .= " right now";
1347 S_IFINVALID
=> 0030000,
1348 S_IFGITLINK
=> 0160000,
1351 # submodule/subproject, a commit object reference
1355 return (($mode & S_IFMT
) == S_IFGITLINK
)
1358 # convert file mode in octal to symbolic file mode string
1360 my $mode = oct shift;
1362 if (S_ISGITLINK
($mode)) {
1363 return 'm---------';
1364 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1365 return 'drwxr-xr-x';
1366 } elsif (S_ISLNK
($mode)) {
1367 return 'lrwxrwxrwx';
1368 } elsif (S_ISREG
($mode)) {
1369 # git cares only about the executable bit
1370 if ($mode & S_IXUSR
) {
1371 return '-rwxr-xr-x';
1373 return '-rw-r--r--';
1376 return '----------';
1380 # convert file mode in octal to file type string
1384 if ($mode !~ m/^[0-7]+$/) {
1390 if (S_ISGITLINK
($mode)) {
1392 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1394 } elsif (S_ISLNK
($mode)) {
1396 } elsif (S_ISREG
($mode)) {
1403 # convert file mode in octal to file type description string
1404 sub file_type_long
{
1407 if ($mode !~ m/^[0-7]+$/) {
1413 if (S_ISGITLINK
($mode)) {
1415 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1417 } elsif (S_ISLNK
($mode)) {
1419 } elsif (S_ISREG
($mode)) {
1420 if ($mode & S_IXUSR
) {
1421 return "executable";
1431 ## ----------------------------------------------------------------------
1432 ## functions returning short HTML fragments, or transforming HTML fragments
1433 ## which don't belong to other sections
1435 # format line of commit message.
1436 sub format_log_line_html
{
1439 $line = esc_html
($line, -nbsp
=>1);
1440 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1441 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1442 -class => "text"}, $1);
1448 # format marker of refs pointing to given object
1450 # the destination action is chosen based on object type and current context:
1451 # - for annotated tags, we choose the tag view unless it's the current view
1452 # already, in which case we go to shortlog view
1453 # - for other refs, we keep the current view if we're in history, shortlog or
1454 # log view, and select shortlog otherwise
1455 sub format_ref_marker
{
1456 my ($refs, $id) = @_;
1459 if (defined $refs->{$id}) {
1460 foreach my $ref (@{$refs->{$id}}) {
1461 # this code exploits the fact that non-lightweight tags are the
1462 # only indirect objects, and that they are the only objects for which
1463 # we want to use tag instead of shortlog as action
1464 my ($type, $name) = qw();
1465 my $indirect = ($ref =~ s/\^\{\}$//);
1466 # e.g. tags/v2.6.11 or heads/next
1467 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1476 $class .= " indirect" if $indirect;
1478 my $dest_action = "shortlog";
1481 $dest_action = "tag" unless $action eq "tag";
1482 } elsif ($action =~ /^(history|(short)?log)$/) {
1483 $dest_action = $action;
1487 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1490 my $link = $cgi->a({
1492 action
=>$dest_action,
1496 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1502 return ' <span class="refs">'. $markers . '</span>';
1508 # format, perhaps shortened and with markers, title line
1509 sub format_subject_html
{
1510 my ($long, $short, $href, $extra) = @_;
1511 $extra = '' unless defined($extra);
1513 if (length($short) < length($long)) {
1514 $long =~ s/[[:cntrl:]]/?/g;
1515 return $cgi->a({-href
=> $href, -class => "list subject",
1516 -title
=> to_utf8
($long)},
1517 esc_html
($short) . $extra);
1519 return $cgi->a({-href
=> $href, -class => "list subject"},
1520 esc_html
($long) . $extra);
1524 # Rather than recomputing the url for an email multiple times, we cache it
1525 # after the first hit. This gives a visible benefit in views where the avatar
1526 # for the same email is used repeatedly (e.g. shortlog).
1527 # The cache is shared by all avatar engines (currently gravatar only), which
1528 # are free to use it as preferred. Since only one avatar engine is used for any
1529 # given page, there's no risk for cache conflicts.
1530 our %avatar_cache = ();
1532 # Compute the picon url for a given email, by using the picon search service over at
1533 # http://www.cs.indiana.edu/picons/search.html
1535 my $email = lc shift;
1536 if (!$avatar_cache{$email}) {
1537 my ($user, $domain) = split('@', $email);
1538 $avatar_cache{$email} =
1539 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1541 "users+domains+unknown/up/single";
1543 return $avatar_cache{$email};
1546 # Compute the gravatar url for a given email, if it's not in the cache already.
1547 # Gravatar stores only the part of the URL before the size, since that's the
1548 # one computationally more expensive. This also allows reuse of the cache for
1549 # different sizes (for this particular engine).
1551 my $email = lc shift;
1553 $avatar_cache{$email} ||=
1554 "http://www.gravatar.com/avatar/" .
1555 Digest
::MD5
::md5_hex
($email) . "?s=";
1556 return $avatar_cache{$email} . $size;
1559 # Insert an avatar for the given $email at the given $size if the feature
1561 sub git_get_avatar
{
1562 my ($email, %opts) = @_;
1563 my $pre_white = ($opts{-pad_before
} ? " " : "");
1564 my $post_white = ($opts{-pad_after
} ? " " : "");
1565 $opts{-size
} ||= 'default';
1566 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1568 if ($git_avatar eq 'gravatar') {
1569 $url = gravatar_url
($email, $size);
1570 } elsif ($git_avatar eq 'picon') {
1571 $url = picon_url
($email);
1573 # Other providers can be added by extending the if chain, defining $url
1574 # as needed. If no variant puts something in $url, we assume avatars
1575 # are completely disabled/unavailable.
1578 "<img width=\"$size\" " .
1579 "class=\"avatar\" " .
1588 # format the author name of the given commit with the given tag
1589 # the author name is chopped and escaped according to the other
1590 # optional parameters (see chop_str).
1591 sub format_author_html
{
1594 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1595 return "<$tag class=\"author\">" .
1596 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1597 $author . "</$tag>";
1600 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1601 sub format_git_diff_header_line
{
1603 my $diffinfo = shift;
1604 my ($from, $to) = @_;
1606 if ($diffinfo->{'nparents'}) {
1608 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1609 if ($to->{'href'}) {
1610 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1611 esc_path
($to->{'file'}));
1612 } else { # file was deleted (no href)
1613 $line .= esc_path
($to->{'file'});
1617 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1618 if ($from->{'href'}) {
1619 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1620 'a/' . esc_path
($from->{'file'}));
1621 } else { # file was added (no href)
1622 $line .= 'a/' . esc_path
($from->{'file'});
1625 if ($to->{'href'}) {
1626 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1627 'b/' . esc_path
($to->{'file'}));
1628 } else { # file was deleted
1629 $line .= 'b/' . esc_path
($to->{'file'});
1633 return "<div class=\"diff header\">$line</div>\n";
1636 # format extended diff header line, before patch itself
1637 sub format_extended_diff_header_line
{
1639 my $diffinfo = shift;
1640 my ($from, $to) = @_;
1643 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1644 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1645 esc_path
($from->{'file'}));
1647 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1648 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1649 esc_path
($to->{'file'}));
1651 # match single <mode>
1652 if ($line =~ m/\s(\d{6})$/) {
1653 $line .= '<span class="info"> (' .
1654 file_type_long
($1) .
1658 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1659 # can match only for combined diff
1661 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1662 if ($from->{'href'}[$i]) {
1663 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1665 substr($diffinfo->{'from_id'}[$i],0,7));
1670 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1673 if ($to->{'href'}) {
1674 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1675 substr($diffinfo->{'to_id'},0,7));
1680 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1681 # can match only for ordinary diff
1682 my ($from_link, $to_link);
1683 if ($from->{'href'}) {
1684 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1685 substr($diffinfo->{'from_id'},0,7));
1687 $from_link = '0' x
7;
1689 if ($to->{'href'}) {
1690 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1691 substr($diffinfo->{'to_id'},0,7));
1695 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1696 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1699 return $line . "<br/>\n";
1702 # format from-file/to-file diff header
1703 sub format_diff_from_to_header
{
1704 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1709 #assert($line =~ m/^---/) if DEBUG;
1710 # no extra formatting for "^--- /dev/null"
1711 if (! $diffinfo->{'nparents'}) {
1712 # ordinary (single parent) diff
1713 if ($line =~ m!^--- "?a/!) {
1714 if ($from->{'href'}) {
1716 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1717 esc_path
($from->{'file'}));
1720 esc_path
($from->{'file'});
1723 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1726 # combined diff (merge commit)
1727 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1728 if ($from->{'href'}[$i]) {
1730 $cgi->a({-href
=>href
(action
=>"blobdiff",
1731 hash_parent
=>$diffinfo->{'from_id'}[$i],
1732 hash_parent_base
=>$parents[$i],
1733 file_parent
=>$from->{'file'}[$i],
1734 hash
=>$diffinfo->{'to_id'},
1736 file_name
=>$to->{'file'}),
1738 -title
=>"diff" . ($i+1)},
1741 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1742 esc_path
($from->{'file'}[$i]));
1744 $line = '--- /dev/null';
1746 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1751 #assert($line =~ m/^\+\+\+/) if DEBUG;
1752 # no extra formatting for "^+++ /dev/null"
1753 if ($line =~ m!^\+\+\+ "?b/!) {
1754 if ($to->{'href'}) {
1756 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1757 esc_path
($to->{'file'}));
1760 esc_path
($to->{'file'});
1763 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1768 # create note for patch simplified by combined diff
1769 sub format_diff_cc_simplified
{
1770 my ($diffinfo, @parents) = @_;
1773 $result .= "<div class=\"diff header\">" .
1775 if (!is_deleted
($diffinfo)) {
1776 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1778 hash
=>$diffinfo->{'to_id'},
1779 file_name
=>$diffinfo->{'to_file'}),
1781 esc_path
($diffinfo->{'to_file'}));
1783 $result .= esc_path
($diffinfo->{'to_file'});
1785 $result .= "</div>\n" . # class="diff header"
1786 "<div class=\"diff nodifferences\">" .
1788 "</div>\n"; # class="diff nodifferences"
1793 # format patch (diff) line (not to be used for diff headers)
1794 sub format_diff_line
{
1796 my ($from, $to) = @_;
1797 my $diff_class = "";
1801 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1803 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1804 if ($line =~ m/^\@{3}/) {
1805 $diff_class = " chunk_header";
1806 } elsif ($line =~ m/^\\/) {
1807 $diff_class = " incomplete";
1808 } elsif ($prefix =~ tr/+/+/) {
1809 $diff_class = " add";
1810 } elsif ($prefix =~ tr/-/-/) {
1811 $diff_class = " rem";
1814 # assume ordinary diff
1815 my $char = substr($line, 0, 1);
1817 $diff_class = " add";
1818 } elsif ($char eq '-') {
1819 $diff_class = " rem";
1820 } elsif ($char eq '@') {
1821 $diff_class = " chunk_header";
1822 } elsif ($char eq "\\") {
1823 $diff_class = " incomplete";
1826 $line = untabify
($line);
1827 if ($from && $to && $line =~ m/^\@{2} /) {
1828 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1829 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1831 $from_lines = 0 unless defined $from_lines;
1832 $to_lines = 0 unless defined $to_lines;
1834 if ($from->{'href'}) {
1835 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1836 -class=>"list"}, $from_text);
1838 if ($to->{'href'}) {
1839 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1840 -class=>"list"}, $to_text);
1842 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1843 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1844 return "<div class=\"diff$diff_class\">$line</div>\n";
1845 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1846 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1847 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1849 @from_text = split(' ', $ranges);
1850 for (my $i = 0; $i < @from_text; ++$i) {
1851 ($from_start[$i], $from_nlines[$i]) =
1852 (split(',', substr($from_text[$i], 1)), 0);
1855 $to_text = pop @from_text;
1856 $to_start = pop @from_start;
1857 $to_nlines = pop @from_nlines;
1859 $line = "<span class=\"chunk_info\">$prefix ";
1860 for (my $i = 0; $i < @from_text; ++$i) {
1861 if ($from->{'href'}[$i]) {
1862 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1863 -class=>"list"}, $from_text[$i]);
1865 $line .= $from_text[$i];
1869 if ($to->{'href'}) {
1870 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1871 -class=>"list"}, $to_text);
1875 $line .= " $prefix</span>" .
1876 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1877 return "<div class=\"diff$diff_class\">$line</div>\n";
1879 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1882 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1883 # linked. Pass the hash of the tree/commit to snapshot.
1884 sub format_snapshot_links
{
1886 my $num_fmts = @snapshot_fmts;
1887 if ($num_fmts > 1) {
1888 # A parenthesized list of links bearing format names.
1889 # e.g. "snapshot (_tar.gz_ _zip_)"
1890 return "snapshot (" . join(' ', map
1897 }, $known_snapshot_formats{$_}{'display'})
1898 , @snapshot_fmts) . ")";
1899 } elsif ($num_fmts == 1) {
1900 # A single "snapshot" link whose tooltip bears the format name.
1902 my ($fmt) = @snapshot_fmts;
1908 snapshot_format
=>$fmt
1910 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1912 } else { # $num_fmts == 0
1917 ## ......................................................................
1918 ## functions returning values to be passed, perhaps after some
1919 ## transformation, to other functions; e.g. returning arguments to href()
1921 # returns hash to be passed to href to generate gitweb URL
1922 # in -title key it returns description of link
1924 my $format = shift || 'Atom';
1925 my %res = (action
=> lc($format));
1927 # feed links are possible only for project views
1928 return unless (defined $project);
1929 # some views should link to OPML, or to generic project feed,
1930 # or don't have specific feed yet (so they should use generic)
1931 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1934 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1935 # from tag links; this also makes possible to detect branch links
1936 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1937 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1940 # find log type for feed description (title)
1942 if (defined $file_name) {
1943 $type = "history of $file_name";
1944 $type .= "/" if ($action eq 'tree');
1945 $type .= " on '$branch'" if (defined $branch);
1947 $type = "log of $branch" if (defined $branch);
1950 $res{-title
} = $type;
1951 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1952 $res{'file_name'} = $file_name;
1957 ## ----------------------------------------------------------------------
1958 ## git utility subroutines, invoking git commands
1960 # returns path to the core git executable and the --git-dir parameter as list
1962 return $GIT, '--git-dir='.$git_dir;
1965 # quote the given arguments for passing them to the shell
1966 # quote_command("command", "arg 1", "arg with ' and ! characters")
1967 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1968 # Try to avoid using this function wherever possible.
1971 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1974 # get HEAD ref of given project as hash
1975 sub git_get_head_hash
{
1976 my $project = shift;
1977 my $o_git_dir = $git_dir;
1979 $git_dir = "$projectroot/$project";
1980 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1983 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1987 if (defined $o_git_dir) {
1988 $git_dir = $o_git_dir;
1993 # get type of given object
1997 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1999 close $fd or return;
2004 # repository configuration
2005 our $config_file = '';
2008 # store multiple values for single key as anonymous array reference
2009 # single values stored directly in the hash, not as [ <value> ]
2010 sub hash_set_multi
{
2011 my ($hash, $key, $value) = @_;
2013 if (!exists $hash->{$key}) {
2014 $hash->{$key} = $value;
2015 } elsif (!ref $hash->{$key}) {
2016 $hash->{$key} = [ $hash->{$key}, $value ];
2018 push @{$hash->{$key}}, $value;
2022 # return hash of git project configuration
2023 # optionally limited to some section, e.g. 'gitweb'
2024 sub git_parse_project_config
{
2025 my $section_regexp = shift;
2030 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2033 while (my $keyval = <$fh>) {
2035 my ($key, $value) = split(/\n/, $keyval, 2);
2037 hash_set_multi
(\
%config, $key, $value)
2038 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2045 # convert config value to boolean: 'true' or 'false'
2046 # no value, number > 0, 'true' and 'yes' values are true
2047 # rest of values are treated as false (never as error)
2048 sub config_to_bool
{
2051 return 1 if !defined $val; # section.key
2053 # strip leading and trailing whitespace
2057 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2058 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2061 # convert config value to simple decimal number
2062 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2063 # to be multiplied by 1024, 1048576, or 1073741824
2067 # strip leading and trailing whitespace
2071 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2073 # unknown unit is treated as 1
2074 return $num * ($unit eq 'g' ? 1073741824 :
2075 $unit eq 'm' ? 1048576 :
2076 $unit eq 'k' ? 1024 : 1);
2081 # convert config value to array reference, if needed
2082 sub config_to_multi
{
2085 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2088 sub git_get_project_config
{
2089 my ($key, $type) = @_;
2092 return unless ($key);
2093 $key =~ s/^gitweb\.//;
2094 return if ($key =~ m/\W/);
2097 if (defined $type) {
2100 unless ($type eq 'bool' || $type eq 'int');
2104 if (!defined $config_file ||
2105 $config_file ne "$git_dir/config") {
2106 %config = git_parse_project_config
('gitweb');
2107 $config_file = "$git_dir/config";
2110 # check if config variable (key) exists
2111 return unless exists $config{"gitweb.$key"};
2114 if (!defined $type) {
2115 return $config{"gitweb.$key"};
2116 } elsif ($type eq 'bool') {
2117 # backward compatibility: 'git config --bool' returns true/false
2118 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2119 } elsif ($type eq 'int') {
2120 return config_to_int
($config{"gitweb.$key"});
2122 return $config{"gitweb.$key"};
2125 # get hash of given path at given ref
2126 sub git_get_hash_by_path
{
2128 my $path = shift || return undef;
2133 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2134 or die_error
(500, "Open git-ls-tree failed");
2136 close $fd or return undef;
2138 if (!defined $line) {
2139 # there is no tree or hash given by $path at $base
2143 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2144 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2145 if (defined $type && $type ne $2) {
2146 # type doesn't match
2152 # get path of entry with given hash at given tree-ish (ref)
2153 # used to get 'from' filename for combined diff (merge commit) for renames
2154 sub git_get_path_by_hash
{
2155 my $base = shift || return;
2156 my $hash = shift || return;
2160 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2162 while (my $line = <$fd>) {
2165 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2166 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2167 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2176 ## ......................................................................
2177 ## git utility functions, directly accessing git repository
2179 sub git_get_project_description
{
2182 $git_dir = "$projectroot/$path";
2183 open my $fd, '<', "$git_dir/description"
2184 or return git_get_project_config
('description');
2187 if (defined $descr) {
2193 sub git_get_project_ctags
{
2197 $git_dir = "$projectroot/$path";
2198 opendir my $dh, "$git_dir/ctags"
2200 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2201 open my $ct, '<', $_ or next;
2205 my $ctag = $_; $ctag =~ s
#.*/##;
2206 $ctags->{$ctag} = $val;
2212 sub git_populate_project_tagcloud
{
2215 # First, merge different-cased tags; tags vote on casing
2217 foreach (keys %$ctags) {
2218 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2219 if (not $ctags_lc{lc $_}->{topcount
}
2220 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2221 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2222 $ctags_lc{lc $_}->{topname
} = $_;
2227 if (eval { require HTML
::TagCloud
; 1; }) {
2228 $cloud = HTML
::TagCloud-
>new;
2229 foreach (sort keys %ctags_lc) {
2230 # Pad the title with spaces so that the cloud looks
2232 my $title = $ctags_lc{$_}->{topname
};
2233 $title =~ s/ / /g;
2234 $title =~ s/^/ /g;
2235 $title =~ s/$/ /g;
2236 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2239 $cloud = \
%ctags_lc;
2244 sub git_show_project_tagcloud
{
2245 my ($cloud, $count) = @_;
2246 print STDERR
ref($cloud)."..\n";
2247 if (ref $cloud eq 'HTML::TagCloud') {
2248 return $cloud->html_and_css($count);
2250 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2251 return '<p align="center">' . join (', ', map {
2252 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2253 } splice(@tags, 0, $count)) . '</p>';
2257 sub git_get_project_url_list
{
2260 $git_dir = "$projectroot/$path";
2261 open my $fd, '<', "$git_dir/cloneurl"
2262 or return wantarray ?
2263 @{ config_to_multi
(git_get_project_config
('url')) } :
2264 config_to_multi
(git_get_project_config
('url'));
2265 my @git_project_url_list = map { chomp; $_ } <$fd>;
2268 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2271 sub git_get_projects_list
{
2276 $filter =~ s/\.git$//;
2278 my $check_forks = gitweb_check_feature
('forks');
2280 if (-d
$projects_list) {
2281 # search in directory
2282 my $dir = $projects_list . ($filter ? "/$filter" : '');
2283 # remove the trailing "/"
2285 my $pfxlen = length("$dir");
2286 my $pfxdepth = ($dir =~ tr!/!!);
2289 follow_fast
=> 1, # follow symbolic links
2290 follow_skip
=> 2, # ignore duplicates
2291 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2293 # skip project-list toplevel, if we get it.
2294 return if (m!^[/.]$!);
2295 # only directories can be git repositories
2296 return unless (-d
$_);
2297 # don't traverse too deep (Find is super slow on os x)
2298 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2299 $File::Find
::prune
= 1;
2303 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2304 # we check related file in $projectroot
2305 my $path = ($filter ? "$filter/" : '') . $subdir;
2306 if (check_export_ok
("$projectroot/$path")) {
2307 push @list, { path
=> $path };
2308 $File::Find
::prune
= 1;
2313 } elsif (-f
$projects_list) {
2314 # read from file(url-encoded):
2315 # 'git%2Fgit.git Linus+Torvalds'
2316 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2317 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2319 open my $fd, '<', $projects_list or return;
2321 while (my $line = <$fd>) {
2323 my ($path, $owner) = split ' ', $line;
2324 $path = unescape
($path);
2325 $owner = unescape
($owner);
2326 if (!defined $path) {
2329 if ($filter ne '') {
2330 # looking for forks;
2331 my $pfx = substr($path, 0, length($filter));
2332 if ($pfx ne $filter) {
2335 my $sfx = substr($path, length($filter));
2336 if ($sfx !~ /^\/.*\
.git
$/) {
2339 } elsif ($check_forks) {
2341 foreach my $filter (keys %paths) {
2342 # looking for forks;
2343 my $pfx = substr($path, 0, length($filter));
2344 if ($pfx ne $filter) {
2347 my $sfx = substr($path, length($filter));
2348 if ($sfx !~ /^\/.*\
.git
$/) {
2351 # is a fork, don't include it in
2356 if (check_export_ok
("$projectroot/$path")) {
2359 owner
=> to_utf8
($owner),
2362 (my $forks_path = $path) =~ s/\.git$//;
2363 $paths{$forks_path}++;
2371 our $gitweb_project_owner = undef;
2372 sub git_get_project_list_from_file
{
2374 return if (defined $gitweb_project_owner);
2376 $gitweb_project_owner = {};
2377 # read from file (url-encoded):
2378 # 'git%2Fgit.git Linus+Torvalds'
2379 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2380 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2381 if (-f
$projects_list) {
2382 open(my $fd, '<', $projects_list);
2383 while (my $line = <$fd>) {
2385 my ($pr, $ow) = split ' ', $line;
2386 $pr = unescape
($pr);
2387 $ow = unescape
($ow);
2388 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2394 sub git_get_project_owner
{
2395 my $project = shift;
2398 return undef unless $project;
2399 $git_dir = "$projectroot/$project";
2401 if (!defined $gitweb_project_owner) {
2402 git_get_project_list_from_file
();
2405 if (exists $gitweb_project_owner->{$project}) {
2406 $owner = $gitweb_project_owner->{$project};
2408 if (!defined $owner){
2409 $owner = git_get_project_config
('owner');
2411 if (!defined $owner) {
2412 $owner = get_file_owner
("$git_dir");
2418 sub git_get_last_activity
{
2422 $git_dir = "$projectroot/$path";
2423 open($fd, "-|", git_cmd
(), 'for-each-ref',
2424 '--format=%(committer)',
2425 '--sort=-committerdate',
2427 'refs/heads') or return;
2428 my $most_recent = <$fd>;
2429 close $fd or return;
2430 if (defined $most_recent &&
2431 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2433 my $age = time - $timestamp;
2434 return ($age, age_string
($age));
2436 return (undef, undef);
2439 sub git_get_references
{
2440 my $type = shift || "";
2442 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2443 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2444 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2445 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2448 while (my $line = <$fd>) {
2450 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2451 if (defined $refs{$1}) {
2452 push @{$refs{$1}}, $2;
2458 close $fd or return;
2462 sub git_get_rev_name_tags
{
2463 my $hash = shift || return undef;
2465 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2467 my $name_rev = <$fd>;
2470 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2473 # catches also '$hash undefined' output
2478 ## ----------------------------------------------------------------------
2479 ## parse to hash functions
2483 my $tz = shift || "-0000";
2486 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2487 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2488 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2489 $date{'hour'} = $hour;
2490 $date{'minute'} = $min;
2491 $date{'mday'} = $mday;
2492 $date{'day'} = $days[$wday];
2493 $date{'month'} = $months[$mon];
2494 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2495 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2496 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2497 $mday, $months[$mon], $hour ,$min;
2498 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2499 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2501 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2502 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2503 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2504 $date{'hour_local'} = $hour;
2505 $date{'minute_local'} = $min;
2506 $date{'tz_local'} = $tz;
2507 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2508 1900+$year, $mon+1, $mday,
2509 $hour, $min, $sec, $tz);
2518 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2519 $tag{'id'} = $tag_id;
2520 while (my $line = <$fd>) {
2522 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2523 $tag{'object'} = $1;
2524 } elsif ($line =~ m/^type (.+)$/) {
2526 } elsif ($line =~ m/^tag (.+)$/) {
2528 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2529 $tag{'author'} = $1;
2530 $tag{'author_epoch'} = $2;
2531 $tag{'author_tz'} = $3;
2532 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2533 $tag{'author_name'} = $1;
2534 $tag{'author_email'} = $2;
2536 $tag{'author_name'} = $tag{'author'};
2538 } elsif ($line =~ m/--BEGIN/) {
2539 push @comment, $line;
2541 } elsif ($line eq "") {
2545 push @comment, <$fd>;
2546 $tag{'comment'} = \
@comment;
2547 close $fd or return;
2548 if (!defined $tag{'name'}) {
2554 sub parse_commit_text
{
2555 my ($commit_text, $withparents) = @_;
2556 my @commit_lines = split '\n', $commit_text;
2559 pop @commit_lines; # Remove '\0'
2561 if (! @commit_lines) {
2565 my $header = shift @commit_lines;
2566 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2569 ($co{'id'}, my @parents) = split ' ', $header;
2570 while (my $line = shift @commit_lines) {
2571 last if $line eq "\n";
2572 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2574 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2576 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2577 $co{'author'} = to_utf8
($1);
2578 $co{'author_epoch'} = $2;
2579 $co{'author_tz'} = $3;
2580 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2581 $co{'author_name'} = $1;
2582 $co{'author_email'} = $2;
2584 $co{'author_name'} = $co{'author'};
2586 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2587 $co{'committer'} = to_utf8
($1);
2588 $co{'committer_epoch'} = $2;
2589 $co{'committer_tz'} = $3;
2590 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2591 $co{'committer_name'} = $1;
2592 $co{'committer_email'} = $2;
2594 $co{'committer_name'} = $co{'committer'};
2598 if (!defined $co{'tree'}) {
2601 $co{'parents'} = \
@parents;
2602 $co{'parent'} = $parents[0];
2604 foreach my $title (@commit_lines) {
2607 $co{'title'} = chop_str
($title, 80, 5);
2608 # remove leading stuff of merges to make the interesting part visible
2609 if (length($title) > 50) {
2610 $title =~ s/^Automatic //;
2611 $title =~ s/^merge (of|with) /Merge ... /i;
2612 if (length($title) > 50) {
2613 $title =~ s/(http|rsync):\/\///;
2615 if (length($title) > 50) {
2616 $title =~ s/(master|www|rsync)\.//;
2618 if (length($title) > 50) {
2619 $title =~ s/kernel.org:?//;
2621 if (length($title) > 50) {
2622 $title =~ s/\/pub\/scm//;
2625 $co{'title_short'} = chop_str
($title, 50, 5);
2629 if (! defined $co{'title'} || $co{'title'} eq "") {
2630 $co{'title'} = $co{'title_short'} = '(no commit message)';
2632 # remove added spaces
2633 foreach my $line (@commit_lines) {
2636 $co{'comment'} = \
@commit_lines;
2638 my $age = time - $co{'committer_epoch'};
2640 $co{'age_string'} = age_string
($age);
2641 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2642 if ($age > 60*60*24*7*2) {
2643 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2644 $co{'age_string_age'} = $co{'age_string'};
2646 $co{'age_string_date'} = $co{'age_string'};
2647 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2653 my ($commit_id) = @_;
2658 open my $fd, "-|", git_cmd
(), "rev-list",
2664 or die_error
(500, "Open git-rev-list failed");
2665 %co = parse_commit_text
(<$fd>, 1);
2672 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2680 open my $fd, "-|", git_cmd
(), "rev-list",
2683 ("--max-count=" . $maxcount),
2684 ("--skip=" . $skip),
2688 ($filename ? ($filename) : ())
2689 or die_error
(500, "Open git-rev-list failed");
2690 while (my $line = <$fd>) {
2691 my %co = parse_commit_text
($line);
2696 return wantarray ? @cos : \
@cos;
2699 # parse line of git-diff-tree "raw" output
2700 sub parse_difftree_raw_line
{
2704 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2705 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2706 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2707 $res{'from_mode'} = $1;
2708 $res{'to_mode'} = $2;
2709 $res{'from_id'} = $3;
2711 $res{'status'} = $5;
2712 $res{'similarity'} = $6;
2713 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2714 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2716 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2719 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2720 # combined diff (for merge commit)
2721 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2722 $res{'nparents'} = length($1);
2723 $res{'from_mode'} = [ split(' ', $2) ];
2724 $res{'to_mode'} = pop @{$res{'from_mode'}};
2725 $res{'from_id'} = [ split(' ', $3) ];
2726 $res{'to_id'} = pop @{$res{'from_id'}};
2727 $res{'status'} = [ split('', $4) ];
2728 $res{'to_file'} = unquote
($5);
2730 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2731 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2732 $res{'commit'} = $1;
2735 return wantarray ? %res : \
%res;
2738 # wrapper: return parsed line of git-diff-tree "raw" output
2739 # (the argument might be raw line, or parsed info)
2740 sub parsed_difftree_line
{
2741 my $line_or_ref = shift;
2743 if (ref($line_or_ref) eq "HASH") {
2744 # pre-parsed (or generated by hand)
2745 return $line_or_ref;
2747 return parse_difftree_raw_line
($line_or_ref);
2751 # parse line of git-ls-tree output
2752 sub parse_ls_tree_line
{
2757 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2758 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2766 $res{'name'} = unquote
($4);
2769 return wantarray ? %res : \
%res;
2772 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2773 sub parse_from_to_diffinfo
{
2774 my ($diffinfo, $from, $to, @parents) = @_;
2776 if ($diffinfo->{'nparents'}) {
2778 $from->{'file'} = [];
2779 $from->{'href'} = [];
2780 fill_from_file_info
($diffinfo, @parents)
2781 unless exists $diffinfo->{'from_file'};
2782 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2783 $from->{'file'}[$i] =
2784 defined $diffinfo->{'from_file'}[$i] ?
2785 $diffinfo->{'from_file'}[$i] :
2786 $diffinfo->{'to_file'};
2787 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2788 $from->{'href'}[$i] = href
(action
=>"blob",
2789 hash_base
=>$parents[$i],
2790 hash
=>$diffinfo->{'from_id'}[$i],
2791 file_name
=>$from->{'file'}[$i]);
2793 $from->{'href'}[$i] = undef;
2797 # ordinary (not combined) diff
2798 $from->{'file'} = $diffinfo->{'from_file'};
2799 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2800 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2801 hash
=>$diffinfo->{'from_id'},
2802 file_name
=>$from->{'file'});
2804 delete $from->{'href'};
2808 $to->{'file'} = $diffinfo->{'to_file'};
2809 if (!is_deleted
($diffinfo)) { # file exists in result
2810 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2811 hash
=>$diffinfo->{'to_id'},
2812 file_name
=>$to->{'file'});
2814 delete $to->{'href'};
2818 ## ......................................................................
2819 ## parse to array of hashes functions
2821 sub git_get_heads_list
{
2825 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2826 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2827 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2830 while (my $line = <$fd>) {
2834 my ($refinfo, $committerinfo) = split(/\0/, $line);
2835 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2836 my ($committer, $epoch, $tz) =
2837 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2838 $ref_item{'fullname'} = $name;
2839 $name =~ s!^refs/heads/!!;
2841 $ref_item{'name'} = $name;
2842 $ref_item{'id'} = $hash;
2843 $ref_item{'title'} = $title || '(no commit message)';
2844 $ref_item{'epoch'} = $epoch;
2846 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2848 $ref_item{'age'} = "unknown";
2851 push @headslist, \
%ref_item;
2855 return wantarray ? @headslist : \
@headslist;
2858 sub git_get_tags_list
{
2862 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2863 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2864 '--format=%(objectname) %(objecttype) %(refname) '.
2865 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2868 while (my $line = <$fd>) {
2872 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2873 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2874 my ($creator, $epoch, $tz) =
2875 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2876 $ref_item{'fullname'} = $name;
2877 $name =~ s!^refs/tags/!!;
2879 $ref_item{'type'} = $type;
2880 $ref_item{'id'} = $id;
2881 $ref_item{'name'} = $name;
2882 if ($type eq "tag") {
2883 $ref_item{'subject'} = $title;
2884 $ref_item{'reftype'} = $reftype;
2885 $ref_item{'refid'} = $refid;
2887 $ref_item{'reftype'} = $type;
2888 $ref_item{'refid'} = $id;
2891 if ($type eq "tag" || $type eq "commit") {
2892 $ref_item{'epoch'} = $epoch;
2894 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2896 $ref_item{'age'} = "unknown";
2900 push @tagslist, \
%ref_item;
2904 return wantarray ? @tagslist : \
@tagslist;
2907 ## ----------------------------------------------------------------------
2908 ## filesystem-related functions
2910 sub get_file_owner
{
2913 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2914 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2915 if (!defined $gcos) {
2919 $owner =~ s/[,;].*$//;
2920 return to_utf8
($owner);
2923 # assume that file exists
2925 my $filename = shift;
2927 open my $fd, '<', $filename;
2928 print map { to_utf8
($_) } <$fd>;
2932 ## ......................................................................
2933 ## mimetype related functions
2935 sub mimetype_guess_file
{
2936 my $filename = shift;
2937 my $mimemap = shift;
2938 -r
$mimemap or return undef;
2941 open(my $mh, '<', $mimemap) or return undef;
2943 next if m/^#/; # skip comments
2944 my ($mimetype, $exts) = split(/\t+/);
2945 if (defined $exts) {
2946 my @exts = split(/\s+/, $exts);
2947 foreach my $ext (@exts) {
2948 $mimemap{$ext} = $mimetype;
2954 $filename =~ /\.([^.]*)$/;
2955 return $mimemap{$1};
2958 sub mimetype_guess
{
2959 my $filename = shift;
2961 $filename =~ /\./ or return undef;
2963 if ($mimetypes_file) {
2964 my $file = $mimetypes_file;
2965 if ($file !~ m!^/!) { # if it is relative path
2966 # it is relative to project
2967 $file = "$projectroot/$project/$file";
2969 $mime = mimetype_guess_file
($filename, $file);
2971 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2977 my $filename = shift;
2980 my $mime = mimetype_guess
($filename);
2981 $mime and return $mime;
2985 return $default_blob_plain_mimetype unless $fd;
2988 return 'text/plain';
2989 } elsif (! $filename) {
2990 return 'application/octet-stream';
2991 } elsif ($filename =~ m/\.png$/i) {
2993 } elsif ($filename =~ m/\.gif$/i) {
2995 } elsif ($filename =~ m/\.jpe?g$/i) {
2996 return 'image/jpeg';
2998 return 'application/octet-stream';
3002 sub blob_contenttype
{
3003 my ($fd, $file_name, $type) = @_;
3005 $type ||= blob_mimetype
($fd, $file_name);
3006 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3007 $type .= "; charset=$default_text_plain_charset";
3013 ## ======================================================================
3014 ## functions printing HTML: header, footer, error page
3016 sub git_header_html
{
3017 my $status = shift || "200 OK";
3018 my $expires = shift;
3020 my $title = "$site_name";
3021 if (defined $project) {
3022 $title .= " - " . to_utf8
($project);
3023 if (defined $action) {
3024 $title .= "/$action";
3025 if (defined $file_name) {
3026 $title .= " - " . esc_path
($file_name);
3027 if ($action eq "tree" && $file_name !~ m
|/$|) {
3034 # require explicit support from the UA if we are to send the page as
3035 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3036 # we have to do this because MSIE sometimes globs '*/*', pretending to
3037 # support xhtml+xml but choking when it gets what it asked for.
3038 if (defined $cgi->http('HTTP_ACCEPT') &&
3039 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3040 $cgi->Accept('application/xhtml+xml') != 0) {
3041 $content_type = 'application/xhtml+xml';
3043 $content_type = 'text/html';
3045 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3046 -status
=> $status, -expires
=> $expires);
3047 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3049 <?xml version="1.0" encoding="utf-8"?>
3050 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3051 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3052 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3053 <!-- git core binaries version $git_version -->
3055 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3056 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3057 <meta name="robots" content="index, nofollow"/>
3058 <title>$title</title>
3060 # the stylesheet, favicon etc urls won't work correctly with path_info
3061 # unless we set the appropriate base URL
3062 if ($ENV{'PATH_INFO'}) {
3063 print "<base href=\"".esc_url
($base_url)."\" />\n";
3065 # print out each stylesheet that exist, providing backwards capability
3066 # for those people who defined $stylesheet in a config file
3067 if (defined $stylesheet) {
3068 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3070 foreach my $stylesheet (@stylesheets) {
3071 next unless $stylesheet;
3072 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3075 if (defined $project) {
3076 my %href_params = get_feed_info
();
3077 if (!exists $href_params{'-title'}) {
3078 $href_params{'-title'} = 'log';
3081 foreach my $format qw(RSS Atom) {
3082 my $type = lc($format);
3084 '-rel' => 'alternate',
3085 '-title' => "$project - $href_params{'-title'} - $format feed",
3086 '-type' => "application/$type+xml"
3089 $href_params{'action'} = $type;
3090 $link_attr{'-href'} = href
(%href_params);
3092 "rel=\"$link_attr{'-rel'}\" ".
3093 "title=\"$link_attr{'-title'}\" ".
3094 "href=\"$link_attr{'-href'}\" ".
3095 "type=\"$link_attr{'-type'}\" ".
3098 $href_params{'extra_options'} = '--no-merges';
3099 $link_attr{'-href'} = href
(%href_params);
3100 $link_attr{'-title'} .= ' (no merges)';
3102 "rel=\"$link_attr{'-rel'}\" ".
3103 "title=\"$link_attr{'-title'}\" ".
3104 "href=\"$link_attr{'-href'}\" ".
3105 "type=\"$link_attr{'-type'}\" ".
3110 printf('<link rel="alternate" title="%s projects list" '.
3111 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3112 $site_name, href
(project
=>undef, action
=>"project_index"));
3113 printf('<link rel="alternate" title="%s projects feeds" '.
3114 'href="%s" type="text/x-opml" />'."\n",
3115 $site_name, href
(project
=>undef, action
=>"opml"));
3117 if (defined $favicon) {
3118 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3124 if (-f
$site_header) {
3125 insert_file
($site_header);
3128 print "<div class=\"page_header\">\n" .
3129 $cgi->a({-href
=> esc_url
($logo_url),
3130 -title
=> $logo_label},
3131 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3132 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3133 if (defined $project) {
3134 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3135 if (defined $action) {
3142 my $have_search = gitweb_check_feature
('search');
3143 if (defined $project && $have_search) {
3144 if (!defined $searchtext) {
3148 if (defined $hash_base) {
3149 $search_hash = $hash_base;
3150 } elsif (defined $hash) {
3151 $search_hash = $hash;
3153 $search_hash = "HEAD";
3155 my $action = $my_uri;
3156 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3157 if ($use_pathinfo) {
3158 $action .= "/".esc_url
($project);
3160 print $cgi->startform(-method => "get", -action
=> $action) .
3161 "<div class=\"search\">\n" .
3163 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3164 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3165 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3166 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3167 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3168 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3170 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3171 "<span title=\"Extended regular expression\">" .
3172 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3173 -checked
=> $search_use_regexp) .
3176 $cgi->end_form() . "\n";
3180 sub git_footer_html
{
3181 my $feed_class = 'rss_logo';
3183 print "<div class=\"page_footer\">\n";
3184 if (defined $project) {
3185 my $descr = git_get_project_description
($project);
3186 if (defined $descr) {
3187 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3190 my %href_params = get_feed_info
();
3191 if (!%href_params) {
3192 $feed_class .= ' generic';
3194 $href_params{'-title'} ||= 'log';
3196 foreach my $format qw(RSS Atom) {
3197 $href_params{'action'} = lc($format);
3198 print $cgi->a({-href
=> href
(%href_params),
3199 -title
=> "$href_params{'-title'} $format feed",
3200 -class => $feed_class}, $format)."\n";
3204 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3205 -class => $feed_class}, "OPML") . " ";
3206 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3207 -class => $feed_class}, "TXT") . "\n";
3209 print "</div>\n"; # class="page_footer"
3211 if (-f
$site_footer) {
3212 insert_file
($site_footer);
3219 # die_error(<http_status_code>, <error_message>)
3220 # Example: die_error(404, 'Hash not found')
3221 # By convention, use the following status codes (as defined in RFC 2616):
3222 # 400: Invalid or missing CGI parameters, or
3223 # requested object exists but has wrong type.
3224 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3225 # this server or project.
3226 # 404: Requested object/revision/project doesn't exist.
3227 # 500: The server isn't configured properly, or
3228 # an internal error occurred (e.g. failed assertions caused by bugs), or
3229 # an unknown error occurred (e.g. the git binary died unexpectedly).
3231 my $status = shift || 500;
3232 my $error = shift || "Internal server error";
3234 my %http_responses = (400 => '400 Bad Request',
3235 403 => '403 Forbidden',
3236 404 => '404 Not Found',
3237 500 => '500 Internal Server Error');
3238 git_header_html
($http_responses{$status});
3240 <div class="page_body">
3250 ## ----------------------------------------------------------------------
3251 ## functions printing or outputting HTML: navigation
3253 sub git_print_page_nav
{
3254 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3255 $extra = '' if !defined $extra; # pager or formats
3257 my @navs = qw(summary shortlog log commit commitdiff tree);
3259 @navs = grep { $_ ne $suppress } @navs;
3262 my %arg = map { $_ => {action
=>$_} } @navs;
3263 if (defined $head) {
3264 for (qw(commit commitdiff)) {
3265 $arg{$_}{'hash'} = $head;
3267 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3268 for (qw(shortlog log)) {
3269 $arg{$_}{'hash'} = $head;
3274 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3275 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3277 my @actions = gitweb_get_feature
('actions');
3280 'n' => $project, # project name
3281 'f' => $git_dir, # project path within filesystem
3282 'h' => $treehead || '', # current hash ('h' parameter)
3283 'b' => $treebase || '', # hash base ('hb' parameter)
3286 my ($label, $link, $pos) = splice(@actions,0,3);
3288 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3290 $link =~ s/%([%nfhb])/$repl{$1}/g;
3291 $arg{$label}{'_href'} = $link;
3294 print "<div class=\"page_nav\">\n" .
3296 map { $_ eq $current ?
3297 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3299 print "<br/>\n$extra<br/>\n" .
3303 sub format_paging_nav
{
3304 my ($action, $hash, $head, $page, $has_next_link) = @_;
3308 if ($hash ne $head || $page) {
3309 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3311 $paging_nav .= "HEAD";
3315 $paging_nav .= " ⋅ " .
3316 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3317 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3319 $paging_nav .= " ⋅ prev";
3322 if ($has_next_link) {
3323 $paging_nav .= " ⋅ " .
3324 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3325 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3327 $paging_nav .= " ⋅ next";
3333 ## ......................................................................
3334 ## functions printing or outputting HTML: div
3336 sub git_print_header_div
{
3337 my ($action, $title, $hash, $hash_base) = @_;
3340 $args{'action'} = $action;
3341 $args{'hash'} = $hash if $hash;
3342 $args{'hash_base'} = $hash_base if $hash_base;
3344 print "<div class=\"header\">\n" .
3345 $cgi->a({-href
=> href
(%args), -class => "title"},
3346 $title ? $title : $action) .
3350 sub print_local_time
{
3352 if ($date{'hour_local'} < 6) {
3353 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3354 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3356 printf(" (%02d:%02d %s)",
3357 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3361 # Outputs the author name and date in long form
3362 sub git_print_authorship
{
3365 my $tag = $opts{-tag
} || 'div';
3367 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3368 print "<$tag class=\"author_date\">" .
3369 esc_html
($co->{'author_name'}) .
3371 print_local_time
(%ad) if ($opts{-localtime});
3372 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3376 # Outputs table rows containing the full author or committer information,
3377 # in the format expected for 'commit' view (& similia).
3378 # Parameters are a commit hash reference, followed by the list of people
3379 # to output information for. If the list is empty it defalts to both
3380 # author and committer.
3381 sub git_print_authorship_rows
{
3383 # too bad we can't use @people = @_ || ('author', 'committer')
3385 @people = ('author', 'committer') unless @people;
3386 foreach my $who (@people) {
3387 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3388 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3389 "<td rowspan=\"2\">" .
3390 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3393 "<td></td><td> $wd{'rfc2822'}";
3394 print_local_time
(%wd);
3400 sub git_print_page_path
{
3406 print "<div class=\"page_path\">";
3407 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3408 -title
=> 'tree root'}, to_utf8
("[$project]"));
3410 if (defined $name) {
3411 my @dirname = split '/', $name;
3412 my $basename = pop @dirname;
3415 foreach my $dir (@dirname) {
3416 $fullname .= ($fullname ? '/' : '') . $dir;
3417 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3419 -title
=> $fullname}, esc_path
($dir));
3422 if (defined $type && $type eq 'blob') {
3423 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3425 -title
=> $name}, esc_path
($basename));
3426 } elsif (defined $type && $type eq 'tree') {
3427 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3429 -title
=> $name}, esc_path
($basename));
3432 print esc_path
($basename);
3435 print "<br/></div>\n";
3442 if ($opts{'-remove_title'}) {
3443 # remove title, i.e. first line of log
3446 # remove leading empty lines
3447 while (defined $log->[0] && $log->[0] eq "") {
3454 foreach my $line (@$log) {
3455 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3458 if (! $opts{'-remove_signoff'}) {
3459 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3462 # remove signoff lines
3469 # print only one empty line
3470 # do not print empty line after signoff
3472 next if ($empty || $signoff);
3478 print format_log_line_html
($line) . "<br/>\n";
3481 if ($opts{'-final_empty_line'}) {
3482 # end with single empty line
3483 print "<br/>\n" unless $empty;
3487 # return link target (what link points to)
3488 sub git_get_link_target
{
3493 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3497 $link_target = <$fd>;
3502 return $link_target;
3505 # given link target, and the directory (basedir) the link is in,
3506 # return target of link relative to top directory (top tree);
3507 # return undef if it is not possible (including absolute links).
3508 sub normalize_link_target
{
3509 my ($link_target, $basedir) = @_;
3511 # absolute symlinks (beginning with '/') cannot be normalized
3512 return if (substr($link_target, 0, 1) eq '/');
3514 # normalize link target to path from top (root) tree (dir)
3517 $path = $basedir . '/' . $link_target;
3519 # we are in top (root) tree (dir)
3520 $path = $link_target;
3523 # remove //, /./, and /../
3525 foreach my $part (split('/', $path)) {
3526 # discard '.' and ''
3527 next if (!$part || $part eq '.');
3529 if ($part eq '..') {
3533 # link leads outside repository (outside top dir)
3537 push @path_parts, $part;
3540 $path = join('/', @path_parts);
3545 # print tree entry (row of git_tree), but without encompassing <tr> element
3546 sub git_print_tree_entry
{
3547 my ($t, $basedir, $hash_base, $have_blame) = @_;
3550 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3552 # The format of a table row is: mode list link. Where mode is
3553 # the mode of the entry, list is the name of the entry, an href,
3554 # and link is the action links of the entry.
3556 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3557 if ($t->{'type'} eq "blob") {
3558 print "<td class=\"list\">" .
3559 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3560 file_name
=>"$basedir$t->{'name'}", %base_key),
3561 -class => "list"}, esc_path
($t->{'name'}));
3562 if (S_ISLNK
(oct $t->{'mode'})) {
3563 my $link_target = git_get_link_target
($t->{'hash'});
3565 my $norm_target = normalize_link_target
($link_target, $basedir);
3566 if (defined $norm_target) {
3568 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3569 file_name
=>$norm_target),
3570 -title
=> $norm_target}, esc_path
($link_target));
3572 print " -> " . esc_path
($link_target);
3577 print "<td class=\"link\">";
3578 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3579 file_name
=>"$basedir$t->{'name'}", %base_key)},
3583 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3584 file_name
=>"$basedir$t->{'name'}", %base_key)},
3587 if (defined $hash_base) {
3589 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3590 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3594 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3595 file_name
=>"$basedir$t->{'name'}")},
3599 } elsif ($t->{'type'} eq "tree") {
3600 print "<td class=\"list\">";
3601 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3602 file_name
=>"$basedir$t->{'name'}", %base_key)},
3603 esc_path
($t->{'name'}));
3605 print "<td class=\"link\">";
3606 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3607 file_name
=>"$basedir$t->{'name'}", %base_key)},
3609 if (defined $hash_base) {
3611 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3612 file_name
=>"$basedir$t->{'name'}")},
3617 # unknown object: we can only present history for it
3618 # (this includes 'commit' object, i.e. submodule support)
3619 print "<td class=\"list\">" .
3620 esc_path
($t->{'name'}) .
3622 print "<td class=\"link\">";
3623 if (defined $hash_base) {
3624 print $cgi->a({-href
=> href
(action
=>"history",
3625 hash_base
=>$hash_base,
3626 file_name
=>"$basedir$t->{'name'}")},
3633 ## ......................................................................
3634 ## functions printing large fragments of HTML
3636 # get pre-image filenames for merge (combined) diff
3637 sub fill_from_file_info
{
3638 my ($diff, @parents) = @_;
3640 $diff->{'from_file'} = [ ];
3641 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3642 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3643 if ($diff->{'status'}[$i] eq 'R' ||
3644 $diff->{'status'}[$i] eq 'C') {
3645 $diff->{'from_file'}[$i] =
3646 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3653 # is current raw difftree line of file deletion
3655 my $diffinfo = shift;
3657 return $diffinfo->{'to_id'} eq ('0' x
40);
3660 # does patch correspond to [previous] difftree raw line
3661 # $diffinfo - hashref of parsed raw diff format
3662 # $patchinfo - hashref of parsed patch diff format
3663 # (the same keys as in $diffinfo)
3664 sub is_patch_split
{
3665 my ($diffinfo, $patchinfo) = @_;
3667 return defined $diffinfo && defined $patchinfo
3668 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3672 sub git_difftree_body
{
3673 my ($difftree, $hash, @parents) = @_;
3674 my ($parent) = $parents[0];
3675 my $have_blame = gitweb_check_feature
('blame');
3676 print "<div class=\"list_head\">\n";
3677 if ($#{$difftree} > 10) {
3678 print(($#{$difftree} + 1) . " files changed:\n");
3682 print "<table class=\"" .
3683 (@parents > 1 ? "combined " : "") .
3686 # header only for combined diff in 'commitdiff' view
3687 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3690 print "<thead><tr>\n" .
3691 "<th></th><th></th>\n"; # filename, patchN link
3692 for (my $i = 0; $i < @parents; $i++) {
3693 my $par = $parents[$i];
3695 $cgi->a({-href
=> href
(action
=>"commitdiff",
3696 hash
=>$hash, hash_parent
=>$par),
3697 -title
=> 'commitdiff to parent number ' .
3698 ($i+1) . ': ' . substr($par,0,7)},
3702 print "</tr></thead>\n<tbody>\n";
3707 foreach my $line (@{$difftree}) {
3708 my $diff = parsed_difftree_line
($line);
3711 print "<tr class=\"dark\">\n";
3713 print "<tr class=\"light\">\n";
3717 if (exists $diff->{'nparents'}) { # combined diff
3719 fill_from_file_info
($diff, @parents)
3720 unless exists $diff->{'from_file'};
3722 if (!is_deleted
($diff)) {
3723 # file exists in the result (child) commit
3725 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3726 file_name
=>$diff->{'to_file'},
3728 -class => "list"}, esc_path
($diff->{'to_file'})) .
3732 esc_path
($diff->{'to_file'}) .
3736 if ($action eq 'commitdiff') {
3739 print "<td class=\"link\">" .
3740 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3745 my $has_history = 0;
3746 my $not_deleted = 0;
3747 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3748 my $hash_parent = $parents[$i];
3749 my $from_hash = $diff->{'from_id'}[$i];
3750 my $from_path = $diff->{'from_file'}[$i];
3751 my $status = $diff->{'status'}[$i];
3753 $has_history ||= ($status ne 'A');
3754 $not_deleted ||= ($status ne 'D');
3756 if ($status eq 'A') {
3757 print "<td class=\"link\" align=\"right\"> | </td>\n";
3758 } elsif ($status eq 'D') {
3759 print "<td class=\"link\">" .
3760 $cgi->a({-href
=> href
(action
=>"blob",
3763 file_name
=>$from_path)},
3767 if ($diff->{'to_id'} eq $from_hash) {
3768 print "<td class=\"link nochange\">";
3770 print "<td class=\"link\">";
3772 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3773 hash
=>$diff->{'to_id'},
3774 hash_parent
=>$from_hash,
3776 hash_parent_base
=>$hash_parent,
3777 file_name
=>$diff->{'to_file'},
3778 file_parent
=>$from_path)},
3784 print "<td class=\"link\">";
3786 print $cgi->a({-href
=> href
(action
=>"blob",
3787 hash
=>$diff->{'to_id'},
3788 file_name
=>$diff->{'to_file'},
3791 print " | " if ($has_history);
3794 print $cgi->a({-href
=> href
(action
=>"history",
3795 file_name
=>$diff->{'to_file'},
3802 next; # instead of 'else' clause, to avoid extra indent
3804 # else ordinary diff
3806 my ($to_mode_oct, $to_mode_str, $to_file_type);
3807 my ($from_mode_oct, $from_mode_str, $from_file_type);
3808 if ($diff->{'to_mode'} ne ('0' x
6)) {
3809 $to_mode_oct = oct $diff->{'to_mode'};
3810 if (S_ISREG
($to_mode_oct)) { # only for regular file
3811 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3813 $to_file_type = file_type
($diff->{'to_mode'});
3815 if ($diff->{'from_mode'} ne ('0' x
6)) {
3816 $from_mode_oct = oct $diff->{'from_mode'};
3817 if (S_ISREG
($to_mode_oct)) { # only for regular file
3818 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3820 $from_file_type = file_type
($diff->{'from_mode'});
3823 if ($diff->{'status'} eq "A") { # created
3824 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3825 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3826 $mode_chng .= "]</span>";
3828 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3829 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3830 -class => "list"}, esc_path
($diff->{'file'}));
3832 print "<td>$mode_chng</td>\n";
3833 print "<td class=\"link\">";
3834 if ($action eq 'commitdiff') {
3837 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3840 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3841 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3845 } elsif ($diff->{'status'} eq "D") { # deleted
3846 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3848 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3849 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3850 -class => "list"}, esc_path
($diff->{'file'}));
3852 print "<td>$mode_chng</td>\n";
3853 print "<td class=\"link\">";
3854 if ($action eq 'commitdiff') {
3857 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3860 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3861 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3864 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3865 file_name
=>$diff->{'file'})},
3868 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3869 file_name
=>$diff->{'file'})},
3873 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3874 my $mode_chnge = "";
3875 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3876 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3877 if ($from_file_type ne $to_file_type) {
3878 $mode_chnge .= " from $from_file_type to $to_file_type";
3880 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3881 if ($from_mode_str && $to_mode_str) {
3882 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3883 } elsif ($to_mode_str) {
3884 $mode_chnge .= " mode: $to_mode_str";
3887 $mode_chnge .= "]</span>\n";
3890 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3891 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3892 -class => "list"}, esc_path
($diff->{'file'}));
3894 print "<td>$mode_chnge</td>\n";
3895 print "<td class=\"link\">";
3896 if ($action eq 'commitdiff') {
3899 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3901 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3902 # "commit" view and modified file (not onlu mode changed)
3903 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3904 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3905 hash_base
=>$hash, hash_parent_base
=>$parent,
3906 file_name
=>$diff->{'file'})},
3910 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3911 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3914 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3915 file_name
=>$diff->{'file'})},
3918 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3919 file_name
=>$diff->{'file'})},
3923 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3924 my %status_name = ('R' => 'moved', 'C' => 'copied');
3925 my $nstatus = $status_name{$diff->{'status'}};
3927 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3928 # mode also for directories, so we cannot use $to_mode_str
3929 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3932 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3933 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3934 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3935 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3936 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3937 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3938 -class => "list"}, esc_path
($diff->{'from_file'})) .
3939 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3940 "<td class=\"link\">";
3941 if ($action eq 'commitdiff') {
3944 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3946 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3947 # "commit" view and modified file (not only pure rename or copy)
3948 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3949 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3950 hash_base
=>$hash, hash_parent_base
=>$parent,
3951 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3955 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3956 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3959 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3960 file_name
=>$diff->{'to_file'})},
3963 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3964 file_name
=>$diff->{'to_file'})},
3968 } # we should not encounter Unmerged (U) or Unknown (X) status
3971 print "</tbody>" if $has_header;
3975 sub git_patchset_body
{
3976 my ($fd, $difftree, $hash, @hash_parents) = @_;
3977 my ($hash_parent) = $hash_parents[0];
3979 my $is_combined = (@hash_parents > 1);
3981 my $patch_number = 0;
3987 print "<div class=\"patchset\">\n";
3989 # skip to first patch
3990 while ($patch_line = <$fd>) {
3993 last if ($patch_line =~ m/^diff /);
3997 while ($patch_line) {
3999 # parse "git diff" header line
4000 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4001 # $1 is from_name, which we do not use
4002 $to_name = unquote
($2);
4003 $to_name =~ s!^b/!!;
4004 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4005 # $1 is 'cc' or 'combined', which we do not use
4006 $to_name = unquote
($2);
4011 # check if current patch belong to current raw line
4012 # and parse raw git-diff line if needed
4013 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4014 # this is continuation of a split patch
4015 print "<div class=\"patch cont\">\n";
4017 # advance raw git-diff output if needed
4018 $patch_idx++ if defined $diffinfo;
4020 # read and prepare patch information
4021 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4023 # compact combined diff output can have some patches skipped
4024 # find which patch (using pathname of result) we are at now;
4026 while ($to_name ne $diffinfo->{'to_file'}) {
4027 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4028 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4029 "</div>\n"; # class="patch"
4034 last if $patch_idx > $#$difftree;
4035 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4039 # modifies %from, %to hashes
4040 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4042 # this is first patch for raw difftree line with $patch_idx index
4043 # we index @$difftree array from 0, but number patches from 1
4044 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4048 #assert($patch_line =~ m/^diff /) if DEBUG;
4049 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4051 # print "git diff" header
4052 print format_git_diff_header_line
($patch_line, $diffinfo,
4055 # print extended diff header
4056 print "<div class=\"diff extended_header\">\n";
4058 while ($patch_line = <$fd>) {
4061 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4063 print format_extended_diff_header_line
($patch_line, $diffinfo,
4066 print "</div>\n"; # class="diff extended_header"
4068 # from-file/to-file diff header
4069 if (! $patch_line) {
4070 print "</div>\n"; # class="patch"
4073 next PATCH
if ($patch_line =~ m/^diff /);
4074 #assert($patch_line =~ m/^---/) if DEBUG;
4076 my $last_patch_line = $patch_line;
4077 $patch_line = <$fd>;
4079 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4081 print format_diff_from_to_header
($last_patch_line, $patch_line,
4082 $diffinfo, \
%from, \
%to,
4087 while ($patch_line = <$fd>) {
4090 next PATCH
if ($patch_line =~ m/^diff /);
4092 print format_diff_line
($patch_line, \
%from, \
%to);
4096 print "</div>\n"; # class="patch"
4099 # for compact combined (--cc) format, with chunk and patch simpliciaction
4100 # patchset might be empty, but there might be unprocessed raw lines
4101 for (++$patch_idx if $patch_number > 0;
4102 $patch_idx < @$difftree;
4104 # read and prepare patch information
4105 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4107 # generate anchor for "patch" links in difftree / whatchanged part
4108 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4109 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4110 "</div>\n"; # class="patch"
4115 if ($patch_number == 0) {
4116 if (@hash_parents > 1) {
4117 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4119 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4123 print "</div>\n"; # class="patchset"
4126 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4128 # fills project list info (age, description, owner, forks) for each
4129 # project in the list, removing invalid projects from returned list
4130 # NOTE: modifies $projlist, but does not remove entries from it
4131 sub fill_project_list_info
{
4132 my ($projlist, $check_forks) = @_;
4135 my $show_ctags = gitweb_check_feature
('ctags');
4137 foreach my $pr (@$projlist) {
4138 my (@activity) = git_get_last_activity
($pr->{'path'});
4139 unless (@activity) {
4142 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4143 if (!defined $pr->{'descr'}) {
4144 my $descr = git_get_project_description
($pr->{'path'}) || "";
4145 $descr = to_utf8
($descr);
4146 $pr->{'descr_long'} = $descr;
4147 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4149 if (!defined $pr->{'owner'}) {
4150 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4153 my $pname = $pr->{'path'};
4154 if (($pname =~ s/\.git$//) &&
4155 ($pname !~ /\/$/) &&
4156 (-d
"$projectroot/$pname")) {
4157 $pr->{'forks'} = "-d $projectroot/$pname";
4162 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4163 push @projects, $pr;
4169 # print 'sort by' <th> element, generating 'sort by $name' replay link
4170 # if that order is not selected
4172 my ($name, $order, $header) = @_;
4173 $header ||= ucfirst($name);
4175 if ($order eq $name) {
4176 print "<th>$header</th>\n";
4179 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4180 -class => "header"}, $header) .
4185 sub git_project_list_body
{
4186 # actually uses global variable $project
4187 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4189 my $check_forks = gitweb_check_feature
('forks');
4190 my @projects = fill_project_list_info
($projlist, $check_forks);
4192 $order ||= $default_projects_order;
4193 $from = 0 unless defined $from;
4194 $to = $#projects if (!defined $to || $#projects < $to);
4197 project
=> { key
=> 'path', type
=> 'str' },
4198 descr
=> { key
=> 'descr_long', type
=> 'str' },
4199 owner
=> { key
=> 'owner', type
=> 'str' },
4200 age
=> { key
=> 'age', type
=> 'num' }
4202 my $oi = $order_info{$order};
4203 if ($oi->{'type'} eq 'str') {
4204 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4206 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4209 my $show_ctags = gitweb_check_feature
('ctags');
4212 foreach my $p (@projects) {
4213 foreach my $ct (keys %{$p->{'ctags'}}) {
4214 $ctags{$ct} += $p->{'ctags'}->{$ct};
4217 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4218 print git_show_project_tagcloud
($cloud, 64);
4221 print "<table class=\"project_list\">\n";
4222 unless ($no_header) {
4225 print "<th></th>\n";
4227 print_sort_th
('project', $order, 'Project');
4228 print_sort_th
('descr', $order, 'Description');
4229 print_sort_th
('owner', $order, 'Owner');
4230 print_sort_th
('age', $order, 'Last Change');
4231 print "<th></th>\n" . # for links
4235 my $tagfilter = $cgi->param('by_tag');
4236 for (my $i = $from; $i <= $to; $i++) {
4237 my $pr = $projects[$i];
4239 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4240 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4241 and not $pr->{'descr_long'} =~ /$searchtext/;
4242 # Weed out forks or non-matching entries of search
4244 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4245 $forkbase="^$forkbase" if $forkbase;
4246 next if not $searchtext and not $tagfilter and $show_ctags
4247 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4251 print "<tr class=\"dark\">\n";
4253 print "<tr class=\"light\">\n";
4258 if ($pr->{'forks'}) {
4259 print "<!-- $pr->{'forks'} -->\n";
4260 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4264 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4265 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4266 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4267 -class => "list", -title
=> $pr->{'descr_long'}},
4268 esc_html
($pr->{'descr'})) . "</td>\n" .
4269 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4270 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4271 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4272 "<td class=\"link\">" .
4273 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4274 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4275 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4276 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4277 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4281 if (defined $extra) {
4284 print "<td></td>\n";
4286 print "<td colspan=\"5\">$extra</td>\n" .
4292 sub git_shortlog_body
{
4293 # uses global variable $project
4294 my ($commitlist, $from, $to, $refs, $extra) = @_;
4296 $from = 0 unless defined $from;
4297 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4299 print "<table class=\"shortlog\">\n";
4301 for (my $i = $from; $i <= $to; $i++) {
4302 my %co = %{$commitlist->[$i]};
4303 my $commit = $co{'id'};
4304 my $ref = format_ref_marker
($refs, $commit);
4306 print "<tr class=\"dark\">\n";
4308 print "<tr class=\"light\">\n";
4311 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4312 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4313 format_author_html
('td', \
%co, 10) . "<td>";
4314 print format_subject_html
($co{'title'}, $co{'title_short'},
4315 href
(action
=>"commit", hash
=>$commit), $ref);
4317 "<td class=\"link\">" .
4318 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4319 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4320 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4321 my $snapshot_links = format_snapshot_links
($commit);
4322 if (defined $snapshot_links) {
4323 print " | " . $snapshot_links;
4328 if (defined $extra) {
4330 "<td colspan=\"4\">$extra</td>\n" .
4336 sub git_history_body
{
4337 # Warning: assumes constant type (blob or tree) during history
4338 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4340 $from = 0 unless defined $from;
4341 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4343 print "<table class=\"history\">\n";
4345 for (my $i = $from; $i <= $to; $i++) {
4346 my %co = %{$commitlist->[$i]};
4350 my $commit = $co{'id'};
4352 my $ref = format_ref_marker
($refs, $commit);
4355 print "<tr class=\"dark\">\n";
4357 print "<tr class=\"light\">\n";
4360 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4361 # shortlog: format_author_html('td', \%co, 10)
4362 format_author_html
('td', \
%co, 15, 3) . "<td>";
4363 # originally git_history used chop_str($co{'title'}, 50)
4364 print format_subject_html
($co{'title'}, $co{'title_short'},
4365 href
(action
=>"commit", hash
=>$commit), $ref);
4367 "<td class=\"link\">" .
4368 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4369 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4371 if ($ftype eq 'blob') {
4372 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4373 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4374 if (defined $blob_current && defined $blob_parent &&
4375 $blob_current ne $blob_parent) {
4377 $cgi->a({-href
=> href
(action
=>"blobdiff",
4378 hash
=>$blob_current, hash_parent
=>$blob_parent,
4379 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4380 file_name
=>$file_name)},
4387 if (defined $extra) {
4389 "<td colspan=\"4\">$extra</td>\n" .
4396 # uses global variable $project
4397 my ($taglist, $from, $to, $extra) = @_;
4398 $from = 0 unless defined $from;
4399 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4401 print "<table class=\"tags\">\n";
4403 for (my $i = $from; $i <= $to; $i++) {
4404 my $entry = $taglist->[$i];
4406 my $comment = $tag{'subject'};
4408 if (defined $comment) {
4409 $comment_short = chop_str
($comment, 30, 5);
4412 print "<tr class=\"dark\">\n";
4414 print "<tr class=\"light\">\n";
4417 if (defined $tag{'age'}) {
4418 print "<td><i>$tag{'age'}</i></td>\n";
4420 print "<td></td>\n";
4423 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4424 -class => "list name"}, esc_html
($tag{'name'})) .
4427 if (defined $comment) {
4428 print format_subject_html
($comment, $comment_short,
4429 href
(action
=>"tag", hash
=>$tag{'id'}));
4432 "<td class=\"selflink\">";
4433 if ($tag{'type'} eq "tag") {
4434 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4439 "<td class=\"link\">" . " | " .
4440 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4441 if ($tag{'reftype'} eq "commit") {
4442 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4443 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4444 } elsif ($tag{'reftype'} eq "blob") {
4445 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4450 if (defined $extra) {
4452 "<td colspan=\"5\">$extra</td>\n" .
4458 sub git_heads_body
{
4459 # uses global variable $project
4460 my ($headlist, $head, $from, $to, $extra) = @_;
4461 $from = 0 unless defined $from;
4462 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4464 print "<table class=\"heads\">\n";
4466 for (my $i = $from; $i <= $to; $i++) {
4467 my $entry = $headlist->[$i];
4469 my $curr = $ref{'id'} eq $head;
4471 print "<tr class=\"dark\">\n";
4473 print "<tr class=\"light\">\n";
4476 print "<td><i>$ref{'age'}</i></td>\n" .
4477 ($curr ? "<td class=\"current_head\">" : "<td>") .
4478 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4479 -class => "list name"},esc_html
($ref{'name'})) .
4481 "<td class=\"link\">" .
4482 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4483 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4484 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4488 if (defined $extra) {
4490 "<td colspan=\"3\">$extra</td>\n" .
4496 sub git_search_grep_body
{
4497 my ($commitlist, $from, $to, $extra) = @_;
4498 $from = 0 unless defined $from;
4499 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4501 print "<table class=\"commit_search\">\n";
4503 for (my $i = $from; $i <= $to; $i++) {
4504 my %co = %{$commitlist->[$i]};
4508 my $commit = $co{'id'};
4510 print "<tr class=\"dark\">\n";
4512 print "<tr class=\"light\">\n";
4515 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4516 format_author_html
('td', \
%co, 15, 5) .
4518 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4519 -class => "list subject"},
4520 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4521 my $comment = $co{'comment'};
4522 foreach my $line (@$comment) {
4523 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4524 my ($lead, $match, $trail) = ($1, $2, $3);
4525 $match = chop_str
($match, 70, 5, 'center');
4526 my $contextlen = int((80 - length($match))/2);
4527 $contextlen = 30 if ($contextlen > 30);
4528 $lead = chop_str
($lead, $contextlen, 10, 'left');
4529 $trail = chop_str
($trail, $contextlen, 10, 'right');
4531 $lead = esc_html
($lead);
4532 $match = esc_html
($match);
4533 $trail = esc_html
($trail);
4535 print "$lead<span class=\"match\">$match</span>$trail<br />";
4539 "<td class=\"link\">" .
4540 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4542 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4544 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4548 if (defined $extra) {
4550 "<td colspan=\"3\">$extra</td>\n" .
4556 ## ======================================================================
4557 ## ======================================================================
4560 sub git_project_list
{
4561 my $order = $input_params{'order'};
4562 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4563 die_error
(400, "Unknown order parameter");
4566 my @list = git_get_projects_list
();
4568 die_error
(404, "No projects found");
4572 if (-f
$home_text) {
4573 print "<div class=\"index_include\">\n";
4574 insert_file
($home_text);
4577 print $cgi->startform(-method => "get") .
4578 "<p class=\"projsearch\">Search:\n" .
4579 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4581 $cgi->end_form() . "\n";
4582 git_project_list_body
(\
@list, $order);
4587 my $order = $input_params{'order'};
4588 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4589 die_error
(400, "Unknown order parameter");
4592 my @list = git_get_projects_list
($project);
4594 die_error
(404, "No forks found");
4598 git_print_page_nav
('','');
4599 git_print_header_div
('summary', "$project forks");
4600 git_project_list_body
(\
@list, $order);
4604 sub git_project_index
{
4605 my @projects = git_get_projects_list
($project);
4608 -type
=> 'text/plain',
4609 -charset
=> 'utf-8',
4610 -content_disposition
=> 'inline; filename="index.aux"');
4612 foreach my $pr (@projects) {
4613 if (!exists $pr->{'owner'}) {
4614 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4617 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4618 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4619 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4620 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4624 print "$path $owner\n";
4629 my $descr = git_get_project_description
($project) || "none";
4630 my %co = parse_commit
("HEAD");
4631 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4632 my $head = $co{'id'};
4634 my $owner = git_get_project_owner
($project);
4636 my $refs = git_get_references
();
4637 # These get_*_list functions return one more to allow us to see if
4638 # there are more ...
4639 my @taglist = git_get_tags_list
(16);
4640 my @headlist = git_get_heads_list
(16);
4642 my $check_forks = gitweb_check_feature
('forks');
4645 @forklist = git_get_projects_list
($project);
4649 git_print_page_nav
('summary','', $head);
4651 print "<div class=\"title\"> </div>\n";
4652 print "<table class=\"projects_list\">\n" .
4653 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4654 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4655 if (defined $cd{'rfc2822'}) {
4656 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4659 # use per project git URL list in $projectroot/$project/cloneurl
4660 # or make project git URL from git base URL and project name
4661 my $url_tag = "URL";
4662 my @url_list = git_get_project_url_list
($project);
4663 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4664 foreach my $git_url (@url_list) {
4665 next unless $git_url;
4666 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4671 my $show_ctags = gitweb_check_feature
('ctags');
4673 my $ctags = git_get_project_ctags
($project);
4674 my $cloud = git_populate_project_tagcloud
($ctags);
4675 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4676 print "</td>\n<td>" unless %$ctags;
4677 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4678 print "</td>\n<td>" if %$ctags;
4679 print git_show_project_tagcloud
($cloud, 48);
4685 # If XSS prevention is on, we don't include README.html.
4686 # TODO: Allow a readme in some safe format.
4687 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4688 print "<div class=\"title\">readme</div>\n" .
4689 "<div class=\"readme\">\n";
4690 insert_file
("$projectroot/$project/README.html");
4691 print "\n</div>\n"; # class="readme"
4694 # we need to request one more than 16 (0..15) to check if
4696 my @commitlist = $head ? parse_commits
($head, 17) : ();
4698 git_print_header_div
('shortlog');
4699 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4700 $#commitlist <= 15 ? undef :
4701 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4705 git_print_header_div
('tags');
4706 git_tags_body
(\
@taglist, 0, 15,
4707 $#taglist <= 15 ? undef :
4708 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4712 git_print_header_div
('heads');
4713 git_heads_body
(\
@headlist, $head, 0, 15,
4714 $#headlist <= 15 ? undef :
4715 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4719 git_print_header_div
('forks');
4720 git_project_list_body
(\
@forklist, 'age', 0, 15,
4721 $#forklist <= 15 ? undef :
4722 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4730 my $head = git_get_head_hash
($project);
4732 git_print_page_nav
('','', $head,undef,$head);
4733 my %tag = parse_tag
($hash);
4736 die_error
(404, "Unknown tag object");
4739 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4740 print "<div class=\"title_text\">\n" .
4741 "<table class=\"object_header\">\n" .
4743 "<td>object</td>\n" .
4744 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4745 $tag{'object'}) . "</td>\n" .
4746 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4747 $tag{'type'}) . "</td>\n" .
4749 if (defined($tag{'author'})) {
4750 git_print_authorship_rows
(\
%tag, 'author');
4752 print "</table>\n\n" .
4754 print "<div class=\"page_body\">";
4755 my $comment = $tag{'comment'};
4756 foreach my $line (@$comment) {
4758 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4766 gitweb_check_feature
('blame')
4767 or die_error
(403, "Blame view not allowed");
4770 die_error
(400, "No file name given") unless $file_name;
4771 $hash_base ||= git_get_head_hash
($project);
4772 die_error
(404, "Couldn't find base commit") unless $hash_base;
4773 my %co = parse_commit
($hash_base)
4774 or die_error
(404, "Commit not found");
4776 if (!defined $hash) {
4777 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4778 or die_error
(404, "Error looking up file");
4780 $ftype = git_get_type
($hash);
4781 if ($ftype !~ "blob") {
4782 die_error
(400, "Object is not a blob");
4786 # run git-blame --porcelain
4787 open my $fd, "-|", git_cmd
(), "blame", '-p',
4788 $hash_base, '--', $file_name
4789 or die_error
(500, "Open git-blame failed");
4794 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4797 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4800 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4802 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4803 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4804 git_print_page_path
($file_name, $ftype, $hash_base);
4807 my @rev_color = qw(light dark);
4808 my $num_colors = scalar(@rev_color);
4809 my $current_color = 0;
4813 <div class="page_body">
4814 <table class="blame">
4815 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4818 while (my $line = <$fd>) {
4820 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4821 # no <lines in group> for subsequent lines in group of lines
4822 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4823 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4824 if (!exists $metainfo{$full_rev}) {
4825 $metainfo{$full_rev} = { 'nprevious' => 0 };
4827 my $meta = $metainfo{$full_rev};
4829 while ($data = <$fd>) {
4831 last if ($data =~ s/^\t//); # contents of line
4832 if ($data =~ /^(\S+)(?: (.*))?$/) {
4833 $meta->{$1} = $2 unless exists $meta->{$1};
4835 if ($data =~ /^previous /) {
4836 $meta->{'nprevious'}++;
4839 my $short_rev = substr($full_rev, 0, 8);
4840 my $author = $meta->{'author'};
4842 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4843 my $date = $date{'iso-tz'};
4845 $current_color = ($current_color + 1) % $num_colors;
4847 my $tr_class = $rev_color[$current_color];
4848 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4849 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4850 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4851 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4853 print "<td class=\"sha1\"";
4854 print " title=\"". esc_html
($author) . ", $date\"";
4855 print " rowspan=\"$group_size\"" if ($group_size > 1);
4857 print $cgi->a({-href
=> href
(action
=>"commit",
4859 file_name
=>$file_name)},
4860 esc_html
($short_rev));
4861 if ($group_size >= 2) {
4862 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
4863 if (@author_initials) {
4865 esc_html
(join('', @author_initials));
4871 # 'previous' <sha1 of parent commit> <filename at commit>
4872 if (exists $meta->{'previous'} &&
4873 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
4874 $meta->{'parent'} = $1;
4875 $meta->{'file_parent'} = unquote
($2);
4878 exists($meta->{'parent'}) ?
4879 $meta->{'parent'} : $full_rev;
4880 my $linenr_filename =
4881 exists($meta->{'file_parent'}) ?
4882 $meta->{'file_parent'} : unquote
($meta->{'filename'});
4883 my $blamed = href
(action
=> 'blame',
4884 file_name
=> $linenr_filename,
4885 hash_base
=> $linenr_commit);
4886 print "<td class=\"linenr\">";
4887 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4888 -class => "linenr" },
4891 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4897 or print "Reading blob failed\n";
4904 my $head = git_get_head_hash
($project);
4906 git_print_page_nav
('','', $head,undef,$head);
4907 git_print_header_div
('summary', $project);
4909 my @tagslist = git_get_tags_list
();
4911 git_tags_body
(\
@tagslist);
4917 my $head = git_get_head_hash
($project);
4919 git_print_page_nav
('','', $head,undef,$head);
4920 git_print_header_div
('summary', $project);
4922 my @headslist = git_get_heads_list
();
4924 git_heads_body
(\
@headslist, $head);
4929 sub git_blob_plain
{
4933 if (!defined $hash) {
4934 if (defined $file_name) {
4935 my $base = $hash_base || git_get_head_hash
($project);
4936 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4937 or die_error
(404, "Cannot find file");
4939 die_error
(400, "No file name defined");
4941 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4942 # blobs defined by non-textual hash id's can be cached
4946 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4947 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4949 # content-type (can include charset)
4950 $type = blob_contenttype
($fd, $file_name, $type);
4952 # "save as" filename, even when no $file_name is given
4953 my $save_as = "$hash";
4954 if (defined $file_name) {
4955 $save_as = $file_name;
4956 } elsif ($type =~ m/^text\//) {
4960 # With XSS prevention on, blobs of all types except a few known safe
4961 # ones are served with "Content-Disposition: attachment" to make sure
4962 # they don't run in our security domain. For certain image types,
4963 # blob view writes an <img> tag referring to blob_plain view, and we
4964 # want to be sure not to break that by serving the image as an
4965 # attachment (though Firefox 3 doesn't seem to care).
4966 my $sandbox = $prevent_xss &&
4967 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4971 -expires
=> $expires,
4972 -content_disposition
=>
4973 ($sandbox ? 'attachment' : 'inline')
4974 . '; filename="' . $save_as . '"');
4976 binmode STDOUT
, ':raw';
4978 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4985 if (!defined $hash) {
4986 if (defined $file_name) {
4987 my $base = $hash_base || git_get_head_hash
($project);
4988 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4989 or die_error
(404, "Cannot find file");
4991 die_error
(400, "No file name defined");
4993 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4994 # blobs defined by non-textual hash id's can be cached
4998 my $have_blame = gitweb_check_feature
('blame');
4999 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5000 or die_error
(500, "Couldn't cat $file_name, $hash");
5001 my $mimetype = blob_mimetype
($fd, $file_name);
5002 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5004 return git_blob_plain
($mimetype);
5006 # we can have blame only for text/* mimetype
5007 $have_blame &&= ($mimetype =~ m!^text/!);
5009 git_header_html
(undef, $expires);
5010 my $formats_nav = '';
5011 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5012 if (defined $file_name) {
5015 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5020 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5023 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5026 $cgi->a({-href
=> href
(action
=>"blob",
5027 hash_base
=>"HEAD", file_name
=>$file_name)},
5031 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5034 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5035 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5037 print "<div class=\"page_nav\">\n" .
5038 "<br/><br/></div>\n" .
5039 "<div class=\"title\">$hash</div>\n";
5041 git_print_page_path
($file_name, "blob", $hash_base);
5042 print "<div class=\"page_body\">\n";
5043 if ($mimetype =~ m!^image/!) {
5044 print qq
!<img type
="$mimetype"!;
5046 print qq
! alt
="$file_name" title
="$file_name"!;
5049 href(action=>"blob_plain
", hash=>$hash,
5050 hash_base=>$hash_base, file_name=>$file_name) .
5054 while (my $line = <$fd>) {
5057 $line = untabify
($line);
5058 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5059 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5063 or print "Reading blob failed.\n";
5069 if (!defined $hash_base) {
5070 $hash_base = "HEAD";
5072 if (!defined $hash) {
5073 if (defined $file_name) {
5074 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5079 die_error
(404, "No such tree") unless defined($hash);
5084 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5085 or die_error
(500, "Open git-ls-tree failed");
5086 @entries = map { chomp; $_ } <$fd>;
5088 or die_error
(404, "Reading tree failed");
5091 my $refs = git_get_references
();
5092 my $ref = format_ref_marker
($refs, $hash_base);
5095 my $have_blame = gitweb_check_feature
('blame');
5096 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5098 if (defined $file_name) {
5100 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5102 $cgi->a({-href
=> href
(action
=>"tree",
5103 hash_base
=>"HEAD", file_name
=>$file_name)},
5106 my $snapshot_links = format_snapshot_links
($hash);
5107 if (defined $snapshot_links) {
5108 # FIXME: Should be available when we have no hash base as well.
5109 push @views_nav, $snapshot_links;
5111 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5112 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5115 print "<div class=\"page_nav\">\n";
5116 print "<br/><br/></div>\n";
5117 print "<div class=\"title\">$hash</div>\n";
5119 if (defined $file_name) {
5120 $basedir = $file_name;
5121 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5124 git_print_page_path
($file_name, 'tree', $hash_base);
5126 print "<div class=\"page_body\">\n";
5127 print "<table class=\"tree\">\n";
5129 # '..' (top directory) link if possible
5130 if (defined $hash_base &&
5131 defined $file_name && $file_name =~ m![^/]+$!) {
5133 print "<tr class=\"dark\">\n";
5135 print "<tr class=\"light\">\n";
5139 my $up = $file_name;
5140 $up =~ s!/?[^/]+$!!;
5141 undef $up unless $up;
5142 # based on git_print_tree_entry
5143 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5144 print '<td class="list">';
5145 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5149 print "<td class=\"link\"></td>\n";
5153 foreach my $line (@entries) {
5154 my %t = parse_ls_tree_line
($line, -z
=> 1);
5157 print "<tr class=\"dark\">\n";
5159 print "<tr class=\"light\">\n";
5163 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5167 print "</table>\n" .
5173 my $format = $input_params{'snapshot_format'};
5174 if (!@snapshot_fmts) {
5175 die_error
(403, "Snapshots not allowed");
5177 # default to first supported snapshot format
5178 $format ||= $snapshot_fmts[0];
5179 if ($format !~ m/^[a-z0-9]+$/) {
5180 die_error
(400, "Invalid snapshot format parameter");
5181 } elsif (!exists($known_snapshot_formats{$format})) {
5182 die_error
(400, "Unknown snapshot format");
5183 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5184 die_error
(403, "Unsupported snapshot format");
5187 if (!defined $hash) {
5188 $hash = git_get_head_hash
($project);
5191 my $name = $project;
5192 $name =~ s
,([^/])/*\
.git
$,$1,;
5193 $name = basename
($name);
5194 my $filename = to_utf8
($name);
5195 $name =~ s/\047/\047\\\047\047/g;
5197 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5198 $cmd = quote_command
(
5199 git_cmd
(), 'archive',
5200 "--format=$known_snapshot_formats{$format}{'format'}",
5201 "--prefix=$name/", $hash);
5202 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5203 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5207 -type
=> $known_snapshot_formats{$format}{'type'},
5208 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5209 -status
=> '200 OK');
5211 open my $fd, "-|", $cmd
5212 or die_error
(500, "Execute git-archive failed");
5213 binmode STDOUT
, ':raw';
5215 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5220 my $head = git_get_head_hash
($project);
5221 if (!defined $hash) {
5224 if (!defined $page) {
5227 my $refs = git_get_references
();
5229 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5231 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5233 my ($patch_max) = gitweb_get_feature
('patches');
5235 if ($patch_max < 0 || @commitlist <= $patch_max) {
5236 $paging_nav .= " ⋅ " .
5237 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5243 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5246 my %co = parse_commit
($hash);
5248 git_print_header_div
('summary', $project);
5249 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5251 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5252 for (my $i = 0; $i <= $to; $i++) {
5253 my %co = %{$commitlist[$i]};
5255 my $commit = $co{'id'};
5256 my $ref = format_ref_marker
($refs, $commit);
5257 my %ad = parse_date
($co{'author_epoch'});
5258 git_print_header_div
('commit',
5259 "<span class=\"age\">$co{'age_string'}</span>" .
5260 esc_html
($co{'title'}) . $ref,
5262 print "<div class=\"title_text\">\n" .
5263 "<div class=\"log_link\">\n" .
5264 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5266 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5268 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5271 git_print_authorship
(\
%co, -tag
=> 'span');
5272 print "<br/>\n</div>\n";
5274 print "<div class=\"log_body\">\n";
5275 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5278 if ($#commitlist >= 100) {
5279 print "<div class=\"page_nav\">\n";
5280 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5281 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5288 $hash ||= $hash_base || "HEAD";
5289 my %co = parse_commit
($hash)
5290 or die_error
(404, "Unknown commit object");
5292 my $parent = $co{'parent'};
5293 my $parents = $co{'parents'}; # listref
5295 # we need to prepare $formats_nav before any parameter munging
5297 if (!defined $parent) {
5299 $formats_nav .= '(initial)';
5300 } elsif (@$parents == 1) {
5301 # single parent commit
5304 $cgi->a({-href
=> href
(action
=>"commit",
5306 esc_html
(substr($parent, 0, 7))) .
5313 $cgi->a({-href
=> href
(action
=>"commit",
5315 esc_html
(substr($_, 0, 7)));
5319 if (gitweb_check_feature
('patches')) {
5320 $formats_nav .= " | " .
5321 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5325 if (!defined $parent) {
5329 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5331 (@$parents <= 1 ? $parent : '-c'),
5333 or die_error
(500, "Open git-diff-tree failed");
5334 @difftree = map { chomp; $_ } <$fd>;
5335 close $fd or die_error
(404, "Reading git-diff-tree failed");
5337 # non-textual hash id's can be cached
5339 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5342 my $refs = git_get_references
();
5343 my $ref = format_ref_marker
($refs, $co{'id'});
5345 git_header_html
(undef, $expires);
5346 git_print_page_nav
('commit', '',
5347 $hash, $co{'tree'}, $hash,
5350 if (defined $co{'parent'}) {
5351 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5353 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5355 print "<div class=\"title_text\">\n" .
5356 "<table class=\"object_header\">\n";
5357 git_print_authorship_rows
(\
%co);
5358 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5361 "<td class=\"sha1\">" .
5362 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5363 class => "list"}, $co{'tree'}) .
5365 "<td class=\"link\">" .
5366 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5368 my $snapshot_links = format_snapshot_links
($hash);
5369 if (defined $snapshot_links) {
5370 print " | " . $snapshot_links;
5375 foreach my $par (@$parents) {
5378 "<td class=\"sha1\">" .
5379 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5380 class => "list"}, $par) .
5382 "<td class=\"link\">" .
5383 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5385 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5392 print "<div class=\"page_body\">\n";
5393 git_print_log
($co{'comment'});
5396 git_difftree_body
(\
@difftree, $hash, @$parents);
5402 # object is defined by:
5403 # - hash or hash_base alone
5404 # - hash_base and file_name
5407 # - hash or hash_base alone
5408 if ($hash || ($hash_base && !defined $file_name)) {
5409 my $object_id = $hash || $hash_base;
5411 open my $fd, "-|", quote_command
(
5412 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5413 or die_error
(404, "Object does not exist");
5417 or die_error
(404, "Object does not exist");
5419 # - hash_base and file_name
5420 } elsif ($hash_base && defined $file_name) {
5421 $file_name =~ s
,/+$,,;
5423 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5424 or die_error
(404, "Base object does not exist");
5426 # here errors should not hapen
5427 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5428 or die_error
(500, "Open git-ls-tree failed");
5432 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5433 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5434 die_error
(404, "File or directory for given base does not exist");
5439 die_error
(400, "Not enough information to find object");
5442 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5443 hash
=>$hash, hash_base
=>$hash_base,
5444 file_name
=>$file_name),
5445 -status
=> '302 Found');
5449 my $format = shift || 'html';
5456 # preparing $fd and %diffinfo for git_patchset_body
5458 if (defined $hash_base && defined $hash_parent_base) {
5459 if (defined $file_name) {
5461 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5462 $hash_parent_base, $hash_base,
5463 "--", (defined $file_parent ? $file_parent : ()), $file_name
5464 or die_error
(500, "Open git-diff-tree failed");
5465 @difftree = map { chomp; $_ } <$fd>;
5467 or die_error
(404, "Reading git-diff-tree failed");
5469 or die_error
(404, "Blob diff not found");
5471 } elsif (defined $hash &&
5472 $hash =~ /[0-9a-fA-F]{40}/) {
5473 # try to find filename from $hash
5475 # read filtered raw output
5476 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5477 $hash_parent_base, $hash_base, "--"
5478 or die_error
(500, "Open git-diff-tree failed");
5480 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5482 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5483 map { chomp; $_ } <$fd>;
5485 or die_error
(404, "Reading git-diff-tree failed");
5487 or die_error
(404, "Blob diff not found");
5490 die_error
(400, "Missing one of the blob diff parameters");
5493 if (@difftree > 1) {
5494 die_error
(400, "Ambiguous blob diff specification");
5497 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5498 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5499 $file_name ||= $diffinfo{'to_file'};
5501 $hash_parent ||= $diffinfo{'from_id'};
5502 $hash ||= $diffinfo{'to_id'};
5504 # non-textual hash id's can be cached
5505 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5506 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5511 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5512 '-p', ($format eq 'html' ? "--full-index" : ()),
5513 $hash_parent_base, $hash_base,
5514 "--", (defined $file_parent ? $file_parent : ()), $file_name
5515 or die_error
(500, "Open git-diff-tree failed");
5518 # old/legacy style URI -- not generated anymore since 1.4.3.
5520 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5524 if ($format eq 'html') {
5526 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5528 git_header_html
(undef, $expires);
5529 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5530 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5531 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5533 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5534 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5536 if (defined $file_name) {
5537 git_print_page_path
($file_name, "blob", $hash_base);
5539 print "<div class=\"page_path\"></div>\n";
5542 } elsif ($format eq 'plain') {
5544 -type
=> 'text/plain',
5545 -charset
=> 'utf-8',
5546 -expires
=> $expires,
5547 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5549 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5552 die_error
(400, "Unknown blobdiff format");
5556 if ($format eq 'html') {
5557 print "<div class=\"page_body\">\n";
5559 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5562 print "</div>\n"; # class="page_body"
5566 while (my $line = <$fd>) {
5567 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5568 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5572 last if $line =~ m!^\+\+\+!;
5580 sub git_blobdiff_plain
{
5581 git_blobdiff
('plain');
5584 sub git_commitdiff
{
5586 my $format = $params{-format
} || 'html';
5588 my ($patch_max) = gitweb_get_feature
('patches');
5589 if ($format eq 'patch') {
5590 die_error
(403, "Patch view not allowed") unless $patch_max;
5593 $hash ||= $hash_base || "HEAD";
5594 my %co = parse_commit
($hash)
5595 or die_error
(404, "Unknown commit object");
5597 # choose format for commitdiff for merge
5598 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5599 $hash_parent = '--cc';
5601 # we need to prepare $formats_nav before almost any parameter munging
5603 if ($format eq 'html') {
5605 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5608 $formats_nav .= " | " .
5609 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5613 if (defined $hash_parent &&
5614 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5615 # commitdiff with two commits given
5616 my $hash_parent_short = $hash_parent;
5617 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5618 $hash_parent_short = substr($hash_parent, 0, 7);
5622 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5623 if ($co{'parents'}[$i] eq $hash_parent) {
5624 $formats_nav .= ' parent ' . ($i+1);
5628 $formats_nav .= ': ' .
5629 $cgi->a({-href
=> href
(action
=>"commitdiff",
5630 hash
=>$hash_parent)},
5631 esc_html
($hash_parent_short)) .
5633 } elsif (!$co{'parent'}) {
5635 $formats_nav .= ' (initial)';
5636 } elsif (scalar @{$co{'parents'}} == 1) {
5637 # single parent commit
5640 $cgi->a({-href
=> href
(action
=>"commitdiff",
5641 hash
=>$co{'parent'})},
5642 esc_html
(substr($co{'parent'}, 0, 7))) .
5646 if ($hash_parent eq '--cc') {
5647 $formats_nav .= ' | ' .
5648 $cgi->a({-href
=> href
(action
=>"commitdiff",
5649 hash
=>$hash, hash_parent
=>'-c')},
5651 } else { # $hash_parent eq '-c'
5652 $formats_nav .= ' | ' .
5653 $cgi->a({-href
=> href
(action
=>"commitdiff",
5654 hash
=>$hash, hash_parent
=>'--cc')},
5660 $cgi->a({-href
=> href
(action
=>"commitdiff",
5662 esc_html
(substr($_, 0, 7)));
5663 } @{$co{'parents'}} ) .
5668 my $hash_parent_param = $hash_parent;
5669 if (!defined $hash_parent_param) {
5670 # --cc for multiple parents, --root for parentless
5671 $hash_parent_param =
5672 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5678 if ($format eq 'html') {
5679 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5680 "--no-commit-id", "--patch-with-raw", "--full-index",
5681 $hash_parent_param, $hash, "--"
5682 or die_error
(500, "Open git-diff-tree failed");
5684 while (my $line = <$fd>) {
5686 # empty line ends raw part of diff-tree output
5688 push @difftree, scalar parse_difftree_raw_line
($line);
5691 } elsif ($format eq 'plain') {
5692 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5693 '-p', $hash_parent_param, $hash, "--"
5694 or die_error
(500, "Open git-diff-tree failed");
5695 } elsif ($format eq 'patch') {
5696 # For commit ranges, we limit the output to the number of
5697 # patches specified in the 'patches' feature.
5698 # For single commits, we limit the output to a single patch,
5699 # diverging from the git-format-patch default.
5700 my @commit_spec = ();
5702 if ($patch_max > 0) {
5703 push @commit_spec, "-$patch_max";
5705 push @commit_spec, '-n', "$hash_parent..$hash";
5707 if ($params{-single
}) {
5708 push @commit_spec, '-1';
5710 if ($patch_max > 0) {
5711 push @commit_spec, "-$patch_max";
5713 push @commit_spec, "-n";
5715 push @commit_spec, '--root', $hash;
5717 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5718 '--stdout', @commit_spec
5719 or die_error
(500, "Open git-format-patch failed");
5721 die_error
(400, "Unknown commitdiff format");
5724 # non-textual hash id's can be cached
5726 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5730 # write commit message
5731 if ($format eq 'html') {
5732 my $refs = git_get_references
();
5733 my $ref = format_ref_marker
($refs, $co{'id'});
5735 git_header_html
(undef, $expires);
5736 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5737 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5738 print "<div class=\"title_text\">\n" .
5739 "<table class=\"object_header\">\n";
5740 git_print_authorship_rows
(\
%co);
5743 print "<div class=\"page_body\">\n";
5744 if (@{$co{'comment'}} > 1) {
5745 print "<div class=\"log\">\n";
5746 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5747 print "</div>\n"; # class="log"
5750 } elsif ($format eq 'plain') {
5751 my $refs = git_get_references
("tags");
5752 my $tagname = git_get_rev_name_tags
($hash);
5753 my $filename = basename
($project) . "-$hash.patch";
5756 -type
=> 'text/plain',
5757 -charset
=> 'utf-8',
5758 -expires
=> $expires,
5759 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5760 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5761 print "From: " . to_utf8
($co{'author'}) . "\n";
5762 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5763 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5765 print "X-Git-Tag: $tagname\n" if $tagname;
5766 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5768 foreach my $line (@{$co{'comment'}}) {
5769 print to_utf8
($line) . "\n";
5772 } elsif ($format eq 'patch') {
5773 my $filename = basename
($project) . "-$hash.patch";
5776 -type
=> 'text/plain',
5777 -charset
=> 'utf-8',
5778 -expires
=> $expires,
5779 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5783 if ($format eq 'html') {
5784 my $use_parents = !defined $hash_parent ||
5785 $hash_parent eq '-c' || $hash_parent eq '--cc';
5786 git_difftree_body
(\
@difftree, $hash,
5787 $use_parents ? @{$co{'parents'}} : $hash_parent);
5790 git_patchset_body
($fd, \
@difftree, $hash,
5791 $use_parents ? @{$co{'parents'}} : $hash_parent);
5793 print "</div>\n"; # class="page_body"
5796 } elsif ($format eq 'plain') {
5800 or print "Reading git-diff-tree failed\n";
5801 } elsif ($format eq 'patch') {
5805 or print "Reading git-format-patch failed\n";
5809 sub git_commitdiff_plain
{
5810 git_commitdiff
(-format
=> 'plain');
5813 # format-patch-style patches
5815 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5819 git_commitdiff
(-format
=> 'patch');
5823 if (!defined $hash_base) {
5824 $hash_base = git_get_head_hash
($project);
5826 if (!defined $page) {
5830 my %co = parse_commit
($hash_base)
5831 or die_error
(404, "Unknown commit object");
5833 my $refs = git_get_references
();
5834 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5836 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5837 $file_name, "--full-history")
5838 or die_error
(404, "No such file or directory on given branch");
5840 if (!defined $hash && defined $file_name) {
5841 # some commits could have deleted file in question,
5842 # and not have it in tree, but one of them has to have it
5843 for (my $i = 0; $i <= @commitlist; $i++) {
5844 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5845 last if defined $hash;
5848 if (defined $hash) {
5849 $ftype = git_get_type
($hash);
5851 if (!defined $ftype) {
5852 die_error
(500, "Unknown type of object");
5855 my $paging_nav = '';
5858 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5859 file_name
=>$file_name)},
5861 $paging_nav .= " ⋅ " .
5862 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5863 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5865 $paging_nav .= "first";
5866 $paging_nav .= " ⋅ prev";
5869 if ($#commitlist >= 100) {
5871 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5872 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5873 $paging_nav .= " ⋅ $next_link";
5875 $paging_nav .= " ⋅ next";
5879 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5880 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5881 git_print_page_path
($file_name, $ftype, $hash_base);
5883 git_history_body
(\
@commitlist, 0, 99,
5884 $refs, $hash_base, $ftype, $next_link);
5890 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5891 if (!defined $searchtext) {
5892 die_error
(400, "Text field is empty");
5894 if (!defined $hash) {
5895 $hash = git_get_head_hash
($project);
5897 my %co = parse_commit
($hash);
5899 die_error
(404, "Unknown commit object");
5901 if (!defined $page) {
5905 $searchtype ||= 'commit';
5906 if ($searchtype eq 'pickaxe') {
5907 # pickaxe may take all resources of your box and run for several minutes
5908 # with every query - so decide by yourself how public you make this feature
5909 gitweb_check_feature
('pickaxe')
5910 or die_error
(403, "Pickaxe is disabled");
5912 if ($searchtype eq 'grep') {
5913 gitweb_check_feature
('grep')[0]
5914 or die_error
(403, "Grep is disabled");
5919 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5921 if ($searchtype eq 'commit') {
5922 $greptype = "--grep=";
5923 } elsif ($searchtype eq 'author') {
5924 $greptype = "--author=";
5925 } elsif ($searchtype eq 'committer') {
5926 $greptype = "--committer=";
5928 $greptype .= $searchtext;
5929 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5930 $greptype, '--regexp-ignore-case',
5931 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5933 my $paging_nav = '';
5936 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5937 searchtext
=>$searchtext,
5938 searchtype
=>$searchtype)},
5940 $paging_nav .= " ⋅ " .
5941 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5942 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5944 $paging_nav .= "first";
5945 $paging_nav .= " ⋅ prev";
5948 if ($#commitlist >= 100) {
5950 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5951 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5952 $paging_nav .= " ⋅ $next_link";
5954 $paging_nav .= " ⋅ next";
5957 if ($#commitlist >= 100) {
5960 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5961 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5962 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5965 if ($searchtype eq 'pickaxe') {
5966 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5967 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5969 print "<table class=\"pickaxe search\">\n";
5972 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5973 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5974 ($search_use_regexp ? '--pickaxe-regex' : ());
5977 while (my $line = <$fd>) {
5981 my %set = parse_difftree_raw_line
($line);
5982 if (defined $set{'commit'}) {
5983 # finish previous commit
5986 "<td class=\"link\">" .
5987 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5989 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5995 print "<tr class=\"dark\">\n";
5997 print "<tr class=\"light\">\n";
6000 %co = parse_commit
($set{'commit'});
6001 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6002 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6003 "<td><i>$author</i></td>\n" .
6005 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6006 -class => "list subject"},
6007 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6008 } elsif (defined $set{'to_id'}) {
6009 next if ($set{'to_id'} =~ m/^0{40}$/);
6011 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6012 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6014 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6020 # finish last commit (warning: repetition!)
6023 "<td class=\"link\">" .
6024 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6026 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6034 if ($searchtype eq 'grep') {
6035 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6036 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6038 print "<table class=\"grep_search\">\n";
6042 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6043 $search_use_regexp ? ('-E', '-i') : '-F',
6044 $searchtext, $co{'tree'};
6046 while (my $line = <$fd>) {
6048 my ($file, $lno, $ltext, $binary);
6049 last if ($matches++ > 1000);
6050 if ($line =~ /^Binary file (.+) matches$/) {
6054 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6056 if ($file ne $lastfile) {
6057 $lastfile and print "</td></tr>\n";
6059 print "<tr class=\"dark\">\n";
6061 print "<tr class=\"light\">\n";
6063 print "<td class=\"list\">".
6064 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6065 file_name
=>"$file"),
6066 -class => "list"}, esc_path
($file));
6067 print "</td><td>\n";
6071 print "<div class=\"binary\">Binary file</div>\n";
6073 $ltext = untabify
($ltext);
6074 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6075 $ltext = esc_html
($1, -nbsp
=>1);
6076 $ltext .= '<span class="match">';
6077 $ltext .= esc_html
($2, -nbsp
=>1);
6078 $ltext .= '</span>';
6079 $ltext .= esc_html
($3, -nbsp
=>1);
6081 $ltext = esc_html
($ltext, -nbsp
=>1);
6083 print "<div class=\"pre\">" .
6084 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6085 file_name
=>"$file").'#l'.$lno,
6086 -class => "linenr"}, sprintf('%4i', $lno))
6087 . ' ' . $ltext . "</div>\n";
6091 print "</td></tr>\n";
6092 if ($matches > 1000) {
6093 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6096 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6105 sub git_search_help
{
6107 git_print_page_nav
('','', $hash,$hash,$hash);
6109 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6110 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6111 the pattern entered is recognized as the POSIX extended
6112 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6115 <dt><b>commit</b></dt>
6116 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6118 my $have_grep = gitweb_check_feature
('grep');
6121 <dt><b>grep</b></dt>
6122 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6123 a different one) are searched for the given pattern. On large trees, this search can take
6124 a while and put some strain on the server, so please use it with some consideration. Note that
6125 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6126 case-sensitive.</dd>
6130 <dt><b>author</b></dt>
6131 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6132 <dt><b>committer</b></dt>
6133 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6135 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6136 if ($have_pickaxe) {
6138 <dt><b>pickaxe</b></dt>
6139 <dd>All commits that caused the string to appear or disappear from any file (changes that
6140 added, removed or "modified" the string) will be listed. This search can take a while and
6141 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6142 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6150 my $head = git_get_head_hash
($project);
6151 if (!defined $hash) {
6154 if (!defined $page) {
6157 my $refs = git_get_references
();
6159 my $commit_hash = $hash;
6160 if (defined $hash_parent) {
6161 $commit_hash = "$hash_parent..$hash";
6163 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6165 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6167 if ($#commitlist >= 100) {
6169 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6170 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6172 my $patch_max = gitweb_check_feature
('patches');
6174 if ($patch_max < 0 || @commitlist <= $patch_max) {
6175 $paging_nav .= " ⋅ " .
6176 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6182 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6183 git_print_header_div
('summary', $project);
6185 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6190 ## ......................................................................
6191 ## feeds (RSS, Atom; OPML)
6194 my $format = shift || 'atom';
6195 my $have_blame = gitweb_check_feature
('blame');
6197 # Atom: http://www.atomenabled.org/developers/syndication/
6198 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6199 if ($format ne 'rss' && $format ne 'atom') {
6200 die_error
(400, "Unknown web feed format");
6203 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6204 my $head = $hash || 'HEAD';
6205 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6209 my $content_type = "application/$format+xml";
6210 if (defined $cgi->http('HTTP_ACCEPT') &&
6211 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6212 # browser (feed reader) prefers text/xml
6213 $content_type = 'text/xml';
6215 if (defined($commitlist[0])) {
6216 %latest_commit = %{$commitlist[0]};
6217 my $latest_epoch = $latest_commit{'committer_epoch'};
6218 %latest_date = parse_date
($latest_epoch);
6219 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6220 if (defined $if_modified) {
6222 if (eval { require HTTP
::Date
; 1; }) {
6223 $since = HTTP
::Date
::str2time
($if_modified);
6224 } elsif (eval { require Time
::ParseDate
; 1; }) {
6225 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6227 if (defined $since && $latest_epoch <= $since) {
6229 -type
=> $content_type,
6230 -charset
=> 'utf-8',
6231 -last_modified
=> $latest_date{'rfc2822'},
6232 -status
=> '304 Not Modified');
6237 -type
=> $content_type,
6238 -charset
=> 'utf-8',
6239 -last_modified
=> $latest_date{'rfc2822'});
6242 -type
=> $content_type,
6243 -charset
=> 'utf-8');
6246 # Optimization: skip generating the body if client asks only
6247 # for Last-Modified date.
6248 return if ($cgi->request_method() eq 'HEAD');
6251 my $title = "$site_name - $project/$action";
6252 my $feed_type = 'log';
6253 if (defined $hash) {
6254 $title .= " - '$hash'";
6255 $feed_type = 'branch log';
6256 if (defined $file_name) {
6257 $title .= " :: $file_name";
6258 $feed_type = 'history';
6260 } elsif (defined $file_name) {
6261 $title .= " - $file_name";
6262 $feed_type = 'history';
6264 $title .= " $feed_type";
6265 my $descr = git_get_project_description
($project);
6266 if (defined $descr) {
6267 $descr = esc_html
($descr);
6269 $descr = "$project " .
6270 ($format eq 'rss' ? 'RSS' : 'Atom') .
6273 my $owner = git_get_project_owner
($project);
6274 $owner = esc_html
($owner);
6278 if (defined $file_name) {
6279 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6280 } elsif (defined $hash) {
6281 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6283 $alt_url = href
(-full
=>1, action
=>"summary");
6285 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6286 if ($format eq 'rss') {
6288 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6291 print "<title>$title</title>\n" .
6292 "<link>$alt_url</link>\n" .
6293 "<description>$descr</description>\n" .
6294 "<language>en</language>\n" .
6295 # project owner is responsible for 'editorial' content
6296 "<managingEditor>$owner</managingEditor>\n";
6297 if (defined $logo || defined $favicon) {
6298 # prefer the logo to the favicon, since RSS
6299 # doesn't allow both
6300 my $img = esc_url
($logo || $favicon);
6302 "<url>$img</url>\n" .
6303 "<title>$title</title>\n" .
6304 "<link>$alt_url</link>\n" .
6308 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6309 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6311 print "<generator>gitweb v.$version/$git_version</generator>\n";
6312 } elsif ($format eq 'atom') {
6314 <feed xmlns="http://www.w3.org/2005/Atom">
6316 print "<title>$title</title>\n" .
6317 "<subtitle>$descr</subtitle>\n" .
6318 '<link rel="alternate" type="text/html" href="' .
6319 $alt_url . '" />' . "\n" .
6320 '<link rel="self" type="' . $content_type . '" href="' .
6321 $cgi->self_url() . '" />' . "\n" .
6322 "<id>" . href
(-full
=>1) . "</id>\n" .
6323 # use project owner for feed author
6324 "<author><name>$owner</name></author>\n";
6325 if (defined $favicon) {
6326 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6328 if (defined $logo_url) {
6329 # not twice as wide as tall: 72 x 27 pixels
6330 print "<logo>" . esc_url
($logo) . "</logo>\n";
6332 if (! %latest_date) {
6333 # dummy date to keep the feed valid until commits trickle in:
6334 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6336 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6338 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6342 for (my $i = 0; $i <= $#commitlist; $i++) {
6343 my %co = %{$commitlist[$i]};
6344 my $commit = $co{'id'};
6345 # we read 150, we always show 30 and the ones more recent than 48 hours
6346 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6349 my %cd = parse_date
($co{'author_epoch'});
6351 # get list of changed files
6352 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6353 $co{'parent'} || "--root",
6354 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6356 my @difftree = map { chomp; $_ } <$fd>;
6360 # print element (entry, item)
6361 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6362 if ($format eq 'rss') {
6364 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6365 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6366 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6367 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6368 "<link>$co_url</link>\n" .
6369 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6370 "<content:encoded>" .
6372 } elsif ($format eq 'atom') {
6374 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6375 "<updated>$cd{'iso-8601'}</updated>\n" .
6377 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6378 if ($co{'author_email'}) {
6379 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6381 print "</author>\n" .
6382 # use committer for contributor
6384 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6385 if ($co{'committer_email'}) {
6386 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6388 print "</contributor>\n" .
6389 "<published>$cd{'iso-8601'}</published>\n" .
6390 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6391 "<id>$co_url</id>\n" .
6392 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6393 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6395 my $comment = $co{'comment'};
6397 foreach my $line (@$comment) {
6398 $line = esc_html
($line);
6401 print "</pre><ul>\n";
6402 foreach my $difftree_line (@difftree) {
6403 my %difftree = parse_difftree_raw_line
($difftree_line);
6404 next if !$difftree{'from_id'};
6406 my $file = $difftree{'file'} || $difftree{'to_file'};
6410 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6411 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6412 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6413 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6414 -title
=> "diff"}, 'D');
6416 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6417 file_name
=>$file, hash_base
=>$commit),
6418 -title
=> "blame"}, 'B');
6420 # if this is not a feed of a file history
6421 if (!defined $file_name || $file_name ne $file) {
6422 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6423 file_name
=>$file, hash
=>$commit),
6424 -title
=> "history"}, 'H');
6426 $file = esc_path
($file);
6430 if ($format eq 'rss') {
6431 print "</ul>]]>\n" .
6432 "</content:encoded>\n" .
6434 } elsif ($format eq 'atom') {
6435 print "</ul>\n</div>\n" .
6442 if ($format eq 'rss') {
6443 print "</channel>\n</rss>\n";
6444 } elsif ($format eq 'atom') {
6458 my @list = git_get_projects_list
();
6461 -type
=> 'text/xml',
6462 -charset
=> 'utf-8',
6463 -content_disposition
=> 'inline; filename="opml.xml"');
6466 <?xml version="1.0" encoding="utf-8"?>
6467 <opml version="1.0">
6469 <title>$site_name OPML Export</title>
6472 <outline text="git RSS feeds">
6475 foreach my $pr (@list) {
6477 my $head = git_get_head_hash
($proj{'path'});
6478 if (!defined $head) {
6481 $git_dir = "$projectroot/$proj{'path'}";
6482 my %co = parse_commit
($head);
6487 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6488 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6489 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6490 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";