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 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
945 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
946 $href .= ":/".esc_url
($params{'file_parent'});
947 delete $params{'file_parent'};
950 delete $params{'hash_parent'};
951 delete $params{'hash_parent_base'};
952 } elsif (defined $params{'hash_parent'}) {
953 $href .= esc_url
($params{'hash_parent'}). "..";
954 delete $params{'hash_parent'};
957 $href .= esc_url
($params{'hash_base'});
958 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
959 $href .= ":/".esc_url
($params{'file_name'});
960 delete $params{'file_name'};
962 delete $params{'hash'};
963 delete $params{'hash_base'};
964 } elsif (defined $params{'hash'}) {
965 $href .= esc_url
($params{'hash'});
966 delete $params{'hash'};
969 # If the action was a snapshot, we can absorb the
970 # snapshot_format parameter too
972 my $fmt = $params{'snapshot_format'};
973 # snapshot_format should always be defined when href()
974 # is called, but just in case some code forgets, we
975 # fall back to the default
976 $fmt ||= $snapshot_fmts[0];
977 $href .= $known_snapshot_formats{$fmt}{'suffix'};
978 delete $params{'snapshot_format'};
982 # now encode the parameters explicitly
984 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
985 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
986 if (defined $params{$name}) {
987 if (ref($params{$name}) eq "ARRAY") {
988 foreach my $par (@{$params{$name}}) {
989 push @result, $symbol . "=" . esc_param
($par);
992 push @result, $symbol . "=" . esc_param
($params{$name});
996 $href .= "?" . join(';', @result) if scalar @result;
1002 ## ======================================================================
1003 ## validation, quoting/unquoting and escaping
1005 sub validate_action
{
1006 my $input = shift || return undef;
1007 return undef unless exists $actions{$input};
1011 sub validate_project
{
1012 my $input = shift || return undef;
1013 if (!validate_pathname
($input) ||
1014 !(-d
"$projectroot/$input") ||
1015 !check_export_ok
("$projectroot/$input") ||
1016 ($strict_export && !project_in_list
($input))) {
1023 sub validate_pathname
{
1024 my $input = shift || return undef;
1026 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1027 # at the beginning, at the end, and between slashes.
1028 # also this catches doubled slashes
1029 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1032 # no null characters
1033 if ($input =~ m!\0!) {
1039 sub validate_refname
{
1040 my $input = shift || return undef;
1042 # textual hashes are O.K.
1043 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1046 # it must be correct pathname
1047 $input = validate_pathname
($input)
1049 # restrictions on ref name according to git-check-ref-format
1050 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1056 # decode sequences of octets in utf8 into Perl's internal form,
1057 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1058 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1061 if (utf8
::valid
($str)) {
1065 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1069 # quote unsafe chars, but keep the slash, even when it's not
1070 # correct, but quoted slashes look too horrible in bookmarks
1073 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1079 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1082 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1088 # replace invalid utf8 character with SUBSTITUTION sequence
1093 $str = to_utf8
($str);
1094 $str = $cgi->escapeHTML($str);
1095 if ($opts{'-nbsp'}) {
1096 $str =~ s/ / /g;
1098 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1102 # quote control characters and escape filename to HTML
1107 $str = to_utf8
($str);
1108 $str = $cgi->escapeHTML($str);
1109 if ($opts{'-nbsp'}) {
1110 $str =~ s/ / /g;
1112 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1116 # Make control characters "printable", using character escape codes (CEC)
1120 my %es = ( # character escape codes, aka escape sequences
1121 "\t" => '\t', # tab (HT)
1122 "\n" => '\n', # line feed (LF)
1123 "\r" => '\r', # carrige return (CR)
1124 "\f" => '\f', # form feed (FF)
1125 "\b" => '\b', # backspace (BS)
1126 "\a" => '\a', # alarm (bell) (BEL)
1127 "\e" => '\e', # escape (ESC)
1128 "\013" => '\v', # vertical tab (VT)
1129 "\000" => '\0', # nul character (NUL)
1131 my $chr = ( (exists $es{$cntrl})
1133 : sprintf('\%2x', ord($cntrl)) );
1134 if ($opts{-nohtml
}) {
1137 return "<span class=\"cntrl\">$chr</span>";
1141 # Alternatively use unicode control pictures codepoints,
1142 # Unicode "printable representation" (PR)
1147 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1148 if ($opts{-nohtml
}) {
1151 return "<span class=\"cntrl\">$chr</span>";
1155 # git may return quoted and escaped filenames
1161 my %es = ( # character escape codes, aka escape sequences
1162 't' => "\t", # tab (HT, TAB)
1163 'n' => "\n", # newline (NL)
1164 'r' => "\r", # return (CR)
1165 'f' => "\f", # form feed (FF)
1166 'b' => "\b", # backspace (BS)
1167 'a' => "\a", # alarm (bell) (BEL)
1168 'e' => "\e", # escape (ESC)
1169 'v' => "\013", # vertical tab (VT)
1172 if ($seq =~ m/^[0-7]{1,3}$/) {
1173 # octal char sequence
1174 return chr(oct($seq));
1175 } elsif (exists $es{$seq}) {
1176 # C escape sequence, aka character escape code
1179 # quoted ordinary character
1183 if ($str =~ m/^"(.*)"$/) {
1186 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1191 # escape tabs (convert tabs to spaces)
1195 while ((my $pos = index($line, "\t")) != -1) {
1196 if (my $count = (8 - ($pos % 8))) {
1197 my $spaces = ' ' x
$count;
1198 $line =~ s/\t/$spaces/;
1205 sub project_in_list
{
1206 my $project = shift;
1207 my @list = git_get_projects_list
();
1208 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1211 ## ----------------------------------------------------------------------
1212 ## HTML aware string manipulation
1214 # Try to chop given string on a word boundary between position
1215 # $len and $len+$add_len. If there is no word boundary there,
1216 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1217 # (marking chopped part) would be longer than given string.
1221 my $add_len = shift || 10;
1222 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1224 # Make sure perl knows it is utf8 encoded so we don't
1225 # cut in the middle of a utf8 multibyte char.
1226 $str = to_utf8
($str);
1228 # allow only $len chars, but don't cut a word if it would fit in $add_len
1229 # if it doesn't fit, cut it if it's still longer than the dots we would add
1230 # remove chopped character entities entirely
1232 # when chopping in the middle, distribute $len into left and right part
1233 # return early if chopping wouldn't make string shorter
1234 if ($where eq 'center') {
1235 return $str if ($len + 5 >= length($str)); # filler is length 5
1238 return $str if ($len + 4 >= length($str)); # filler is length 4
1241 # regexps: ending and beginning with word part up to $add_len
1242 my $endre = qr/.{$len}\w{0,$add_len}/;
1243 my $begre = qr/\w{0,$add_len}.{$len}/;
1245 if ($where eq 'left') {
1246 $str =~ m/^(.*?)($begre)$/;
1247 my ($lead, $body) = ($1, $2);
1248 if (length($lead) > 4) {
1249 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1252 return "$lead$body";
1254 } elsif ($where eq 'center') {
1255 $str =~ m/^($endre)(.*)$/;
1256 my ($left, $str) = ($1, $2);
1257 $str =~ m/^(.*?)($begre)$/;
1258 my ($mid, $right) = ($1, $2);
1259 if (length($mid) > 5) {
1260 $left =~ s/&[^;]*$//;
1261 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1264 return "$left$mid$right";
1267 $str =~ m/^($endre)(.*)$/;
1270 if (length($tail) > 4) {
1271 $body =~ s/&[^;]*$//;
1274 return "$body$tail";
1278 # takes the same arguments as chop_str, but also wraps a <span> around the
1279 # result with a title attribute if it does get chopped. Additionally, the
1280 # string is HTML-escaped.
1281 sub chop_and_escape_str
{
1284 my $chopped = chop_str
(@_);
1285 if ($chopped eq $str) {
1286 return esc_html
($chopped);
1288 $str =~ s/[[:cntrl:]]/?/g;
1289 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1293 ## ----------------------------------------------------------------------
1294 ## functions returning short strings
1296 # CSS class for given age value (in seconds)
1300 if (!defined $age) {
1302 } elsif ($age < 60*60*2) {
1304 } elsif ($age < 60*60*24*2) {
1311 # convert age in seconds to "nn units ago" string
1316 if ($age > 60*60*24*365*2) {
1317 $age_str = (int $age/60/60/24/365);
1318 $age_str .= " years ago";
1319 } elsif ($age > 60*60*24*(365/12)*2) {
1320 $age_str = int $age/60/60/24/(365/12);
1321 $age_str .= " months ago";
1322 } elsif ($age > 60*60*24*7*2) {
1323 $age_str = int $age/60/60/24/7;
1324 $age_str .= " weeks ago";
1325 } elsif ($age > 60*60*24*2) {
1326 $age_str = int $age/60/60/24;
1327 $age_str .= " days ago";
1328 } elsif ($age > 60*60*2) {
1329 $age_str = int $age/60/60;
1330 $age_str .= " hours ago";
1331 } elsif ($age > 60*2) {
1332 $age_str = int $age/60;
1333 $age_str .= " min ago";
1334 } elsif ($age > 2) {
1335 $age_str = int $age;
1336 $age_str .= " sec ago";
1338 $age_str .= " right now";
1344 S_IFINVALID
=> 0030000,
1345 S_IFGITLINK
=> 0160000,
1348 # submodule/subproject, a commit object reference
1352 return (($mode & S_IFMT
) == S_IFGITLINK
)
1355 # convert file mode in octal to symbolic file mode string
1357 my $mode = oct shift;
1359 if (S_ISGITLINK
($mode)) {
1360 return 'm---------';
1361 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1362 return 'drwxr-xr-x';
1363 } elsif (S_ISLNK
($mode)) {
1364 return 'lrwxrwxrwx';
1365 } elsif (S_ISREG
($mode)) {
1366 # git cares only about the executable bit
1367 if ($mode & S_IXUSR
) {
1368 return '-rwxr-xr-x';
1370 return '-rw-r--r--';
1373 return '----------';
1377 # convert file mode in octal to file type string
1381 if ($mode !~ m/^[0-7]+$/) {
1387 if (S_ISGITLINK
($mode)) {
1389 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1391 } elsif (S_ISLNK
($mode)) {
1393 } elsif (S_ISREG
($mode)) {
1400 # convert file mode in octal to file type description string
1401 sub file_type_long
{
1404 if ($mode !~ m/^[0-7]+$/) {
1410 if (S_ISGITLINK
($mode)) {
1412 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1414 } elsif (S_ISLNK
($mode)) {
1416 } elsif (S_ISREG
($mode)) {
1417 if ($mode & S_IXUSR
) {
1418 return "executable";
1428 ## ----------------------------------------------------------------------
1429 ## functions returning short HTML fragments, or transforming HTML fragments
1430 ## which don't belong to other sections
1432 # format line of commit message.
1433 sub format_log_line_html
{
1436 $line = esc_html
($line, -nbsp
=>1);
1437 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1438 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1439 -class => "text"}, $1);
1445 # format marker of refs pointing to given object
1447 # the destination action is chosen based on object type and current context:
1448 # - for annotated tags, we choose the tag view unless it's the current view
1449 # already, in which case we go to shortlog view
1450 # - for other refs, we keep the current view if we're in history, shortlog or
1451 # log view, and select shortlog otherwise
1452 sub format_ref_marker
{
1453 my ($refs, $id) = @_;
1456 if (defined $refs->{$id}) {
1457 foreach my $ref (@{$refs->{$id}}) {
1458 # this code exploits the fact that non-lightweight tags are the
1459 # only indirect objects, and that they are the only objects for which
1460 # we want to use tag instead of shortlog as action
1461 my ($type, $name) = qw();
1462 my $indirect = ($ref =~ s/\^\{\}$//);
1463 # e.g. tags/v2.6.11 or heads/next
1464 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1473 $class .= " indirect" if $indirect;
1475 my $dest_action = "shortlog";
1478 $dest_action = "tag" unless $action eq "tag";
1479 } elsif ($action =~ /^(history|(short)?log)$/) {
1480 $dest_action = $action;
1484 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1487 my $link = $cgi->a({
1489 action
=>$dest_action,
1493 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1499 return ' <span class="refs">'. $markers . '</span>';
1505 # format, perhaps shortened and with markers, title line
1506 sub format_subject_html
{
1507 my ($long, $short, $href, $extra) = @_;
1508 $extra = '' unless defined($extra);
1510 if (length($short) < length($long)) {
1511 $long =~ s/[[:cntrl:]]/?/g;
1512 return $cgi->a({-href
=> $href, -class => "list subject",
1513 -title
=> to_utf8
($long)},
1514 esc_html
($short) . $extra);
1516 return $cgi->a({-href
=> $href, -class => "list subject"},
1517 esc_html
($long) . $extra);
1521 # Rather than recomputing the url for an email multiple times, we cache it
1522 # after the first hit. This gives a visible benefit in views where the avatar
1523 # for the same email is used repeatedly (e.g. shortlog).
1524 # The cache is shared by all avatar engines (currently gravatar only), which
1525 # are free to use it as preferred. Since only one avatar engine is used for any
1526 # given page, there's no risk for cache conflicts.
1527 our %avatar_cache = ();
1529 # Compute the picon url for a given email, by using the picon search service over at
1530 # http://www.cs.indiana.edu/picons/search.html
1532 my $email = lc shift;
1533 if (!$avatar_cache{$email}) {
1534 my ($user, $domain) = split('@', $email);
1535 $avatar_cache{$email} =
1536 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1538 "users+domains+unknown/up/single";
1540 return $avatar_cache{$email};
1543 # Compute the gravatar url for a given email, if it's not in the cache already.
1544 # Gravatar stores only the part of the URL before the size, since that's the
1545 # one computationally more expensive. This also allows reuse of the cache for
1546 # different sizes (for this particular engine).
1548 my $email = lc shift;
1550 $avatar_cache{$email} ||=
1551 "http://www.gravatar.com/avatar/" .
1552 Digest
::MD5
::md5_hex
($email) . "?s=";
1553 return $avatar_cache{$email} . $size;
1556 # Insert an avatar for the given $email at the given $size if the feature
1558 sub git_get_avatar
{
1559 my ($email, %opts) = @_;
1560 my $pre_white = ($opts{-pad_before
} ? " " : "");
1561 my $post_white = ($opts{-pad_after
} ? " " : "");
1562 $opts{-size
} ||= 'default';
1563 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1565 if ($git_avatar eq 'gravatar') {
1566 $url = gravatar_url
($email, $size);
1567 } elsif ($git_avatar eq 'picon') {
1568 $url = picon_url
($email);
1570 # Other providers can be added by extending the if chain, defining $url
1571 # as needed. If no variant puts something in $url, we assume avatars
1572 # are completely disabled/unavailable.
1575 "<img width=\"$size\" " .
1576 "class=\"avatar\" " .
1585 # format the author name of the given commit with the given tag
1586 # the author name is chopped and escaped according to the other
1587 # optional parameters (see chop_str).
1588 sub format_author_html
{
1591 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1592 return "<$tag class=\"author\">" .
1593 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1594 $author . "</$tag>";
1597 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1598 sub format_git_diff_header_line
{
1600 my $diffinfo = shift;
1601 my ($from, $to) = @_;
1603 if ($diffinfo->{'nparents'}) {
1605 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1606 if ($to->{'href'}) {
1607 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1608 esc_path
($to->{'file'}));
1609 } else { # file was deleted (no href)
1610 $line .= esc_path
($to->{'file'});
1614 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1615 if ($from->{'href'}) {
1616 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1617 'a/' . esc_path
($from->{'file'}));
1618 } else { # file was added (no href)
1619 $line .= 'a/' . esc_path
($from->{'file'});
1622 if ($to->{'href'}) {
1623 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1624 'b/' . esc_path
($to->{'file'}));
1625 } else { # file was deleted
1626 $line .= 'b/' . esc_path
($to->{'file'});
1630 return "<div class=\"diff header\">$line</div>\n";
1633 # format extended diff header line, before patch itself
1634 sub format_extended_diff_header_line
{
1636 my $diffinfo = shift;
1637 my ($from, $to) = @_;
1640 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1641 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1642 esc_path
($from->{'file'}));
1644 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1645 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1646 esc_path
($to->{'file'}));
1648 # match single <mode>
1649 if ($line =~ m/\s(\d{6})$/) {
1650 $line .= '<span class="info"> (' .
1651 file_type_long
($1) .
1655 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1656 # can match only for combined diff
1658 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1659 if ($from->{'href'}[$i]) {
1660 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1662 substr($diffinfo->{'from_id'}[$i],0,7));
1667 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1670 if ($to->{'href'}) {
1671 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1672 substr($diffinfo->{'to_id'},0,7));
1677 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1678 # can match only for ordinary diff
1679 my ($from_link, $to_link);
1680 if ($from->{'href'}) {
1681 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1682 substr($diffinfo->{'from_id'},0,7));
1684 $from_link = '0' x
7;
1686 if ($to->{'href'}) {
1687 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1688 substr($diffinfo->{'to_id'},0,7));
1692 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1693 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1696 return $line . "<br/>\n";
1699 # format from-file/to-file diff header
1700 sub format_diff_from_to_header
{
1701 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1706 #assert($line =~ m/^---/) if DEBUG;
1707 # no extra formatting for "^--- /dev/null"
1708 if (! $diffinfo->{'nparents'}) {
1709 # ordinary (single parent) diff
1710 if ($line =~ m!^--- "?a/!) {
1711 if ($from->{'href'}) {
1713 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1714 esc_path
($from->{'file'}));
1717 esc_path
($from->{'file'});
1720 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1723 # combined diff (merge commit)
1724 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1725 if ($from->{'href'}[$i]) {
1727 $cgi->a({-href
=>href
(action
=>"blobdiff",
1728 hash_parent
=>$diffinfo->{'from_id'}[$i],
1729 hash_parent_base
=>$parents[$i],
1730 file_parent
=>$from->{'file'}[$i],
1731 hash
=>$diffinfo->{'to_id'},
1733 file_name
=>$to->{'file'}),
1735 -title
=>"diff" . ($i+1)},
1738 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1739 esc_path
($from->{'file'}[$i]));
1741 $line = '--- /dev/null';
1743 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1748 #assert($line =~ m/^\+\+\+/) if DEBUG;
1749 # no extra formatting for "^+++ /dev/null"
1750 if ($line =~ m!^\+\+\+ "?b/!) {
1751 if ($to->{'href'}) {
1753 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1754 esc_path
($to->{'file'}));
1757 esc_path
($to->{'file'});
1760 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1765 # create note for patch simplified by combined diff
1766 sub format_diff_cc_simplified
{
1767 my ($diffinfo, @parents) = @_;
1770 $result .= "<div class=\"diff header\">" .
1772 if (!is_deleted
($diffinfo)) {
1773 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1775 hash
=>$diffinfo->{'to_id'},
1776 file_name
=>$diffinfo->{'to_file'}),
1778 esc_path
($diffinfo->{'to_file'}));
1780 $result .= esc_path
($diffinfo->{'to_file'});
1782 $result .= "</div>\n" . # class="diff header"
1783 "<div class=\"diff nodifferences\">" .
1785 "</div>\n"; # class="diff nodifferences"
1790 # format patch (diff) line (not to be used for diff headers)
1791 sub format_diff_line
{
1793 my ($from, $to) = @_;
1794 my $diff_class = "";
1798 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1800 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1801 if ($line =~ m/^\@{3}/) {
1802 $diff_class = " chunk_header";
1803 } elsif ($line =~ m/^\\/) {
1804 $diff_class = " incomplete";
1805 } elsif ($prefix =~ tr/+/+/) {
1806 $diff_class = " add";
1807 } elsif ($prefix =~ tr/-/-/) {
1808 $diff_class = " rem";
1811 # assume ordinary diff
1812 my $char = substr($line, 0, 1);
1814 $diff_class = " add";
1815 } elsif ($char eq '-') {
1816 $diff_class = " rem";
1817 } elsif ($char eq '@') {
1818 $diff_class = " chunk_header";
1819 } elsif ($char eq "\\") {
1820 $diff_class = " incomplete";
1823 $line = untabify
($line);
1824 if ($from && $to && $line =~ m/^\@{2} /) {
1825 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1826 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1828 $from_lines = 0 unless defined $from_lines;
1829 $to_lines = 0 unless defined $to_lines;
1831 if ($from->{'href'}) {
1832 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1833 -class=>"list"}, $from_text);
1835 if ($to->{'href'}) {
1836 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1837 -class=>"list"}, $to_text);
1839 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1840 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1841 return "<div class=\"diff$diff_class\">$line</div>\n";
1842 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1843 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1844 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1846 @from_text = split(' ', $ranges);
1847 for (my $i = 0; $i < @from_text; ++$i) {
1848 ($from_start[$i], $from_nlines[$i]) =
1849 (split(',', substr($from_text[$i], 1)), 0);
1852 $to_text = pop @from_text;
1853 $to_start = pop @from_start;
1854 $to_nlines = pop @from_nlines;
1856 $line = "<span class=\"chunk_info\">$prefix ";
1857 for (my $i = 0; $i < @from_text; ++$i) {
1858 if ($from->{'href'}[$i]) {
1859 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1860 -class=>"list"}, $from_text[$i]);
1862 $line .= $from_text[$i];
1866 if ($to->{'href'}) {
1867 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1868 -class=>"list"}, $to_text);
1872 $line .= " $prefix</span>" .
1873 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1874 return "<div class=\"diff$diff_class\">$line</div>\n";
1876 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1879 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1880 # linked. Pass the hash of the tree/commit to snapshot.
1881 sub format_snapshot_links
{
1883 my $num_fmts = @snapshot_fmts;
1884 if ($num_fmts > 1) {
1885 # A parenthesized list of links bearing format names.
1886 # e.g. "snapshot (_tar.gz_ _zip_)"
1887 return "snapshot (" . join(' ', map
1894 }, $known_snapshot_formats{$_}{'display'})
1895 , @snapshot_fmts) . ")";
1896 } elsif ($num_fmts == 1) {
1897 # A single "snapshot" link whose tooltip bears the format name.
1899 my ($fmt) = @snapshot_fmts;
1905 snapshot_format
=>$fmt
1907 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1909 } else { # $num_fmts == 0
1914 ## ......................................................................
1915 ## functions returning values to be passed, perhaps after some
1916 ## transformation, to other functions; e.g. returning arguments to href()
1918 # returns hash to be passed to href to generate gitweb URL
1919 # in -title key it returns description of link
1921 my $format = shift || 'Atom';
1922 my %res = (action
=> lc($format));
1924 # feed links are possible only for project views
1925 return unless (defined $project);
1926 # some views should link to OPML, or to generic project feed,
1927 # or don't have specific feed yet (so they should use generic)
1928 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1931 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1932 # from tag links; this also makes possible to detect branch links
1933 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1934 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1937 # find log type for feed description (title)
1939 if (defined $file_name) {
1940 $type = "history of $file_name";
1941 $type .= "/" if ($action eq 'tree');
1942 $type .= " on '$branch'" if (defined $branch);
1944 $type = "log of $branch" if (defined $branch);
1947 $res{-title
} = $type;
1948 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1949 $res{'file_name'} = $file_name;
1954 ## ----------------------------------------------------------------------
1955 ## git utility subroutines, invoking git commands
1957 # returns path to the core git executable and the --git-dir parameter as list
1959 return $GIT, '--git-dir='.$git_dir;
1962 # quote the given arguments for passing them to the shell
1963 # quote_command("command", "arg 1", "arg with ' and ! characters")
1964 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1965 # Try to avoid using this function wherever possible.
1968 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1971 # get HEAD ref of given project as hash
1972 sub git_get_head_hash
{
1973 my $project = shift;
1974 my $o_git_dir = $git_dir;
1976 $git_dir = "$projectroot/$project";
1977 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1980 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1984 if (defined $o_git_dir) {
1985 $git_dir = $o_git_dir;
1990 # get type of given object
1994 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1996 close $fd or return;
2001 # repository configuration
2002 our $config_file = '';
2005 # store multiple values for single key as anonymous array reference
2006 # single values stored directly in the hash, not as [ <value> ]
2007 sub hash_set_multi
{
2008 my ($hash, $key, $value) = @_;
2010 if (!exists $hash->{$key}) {
2011 $hash->{$key} = $value;
2012 } elsif (!ref $hash->{$key}) {
2013 $hash->{$key} = [ $hash->{$key}, $value ];
2015 push @{$hash->{$key}}, $value;
2019 # return hash of git project configuration
2020 # optionally limited to some section, e.g. 'gitweb'
2021 sub git_parse_project_config
{
2022 my $section_regexp = shift;
2027 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2030 while (my $keyval = <$fh>) {
2032 my ($key, $value) = split(/\n/, $keyval, 2);
2034 hash_set_multi
(\
%config, $key, $value)
2035 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2042 # convert config value to boolean: 'true' or 'false'
2043 # no value, number > 0, 'true' and 'yes' values are true
2044 # rest of values are treated as false (never as error)
2045 sub config_to_bool
{
2048 return 1 if !defined $val; # section.key
2050 # strip leading and trailing whitespace
2054 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2055 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2058 # convert config value to simple decimal number
2059 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2060 # to be multiplied by 1024, 1048576, or 1073741824
2064 # strip leading and trailing whitespace
2068 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2070 # unknown unit is treated as 1
2071 return $num * ($unit eq 'g' ? 1073741824 :
2072 $unit eq 'm' ? 1048576 :
2073 $unit eq 'k' ? 1024 : 1);
2078 # convert config value to array reference, if needed
2079 sub config_to_multi
{
2082 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2085 sub git_get_project_config
{
2086 my ($key, $type) = @_;
2089 return unless ($key);
2090 $key =~ s/^gitweb\.//;
2091 return if ($key =~ m/\W/);
2094 if (defined $type) {
2097 unless ($type eq 'bool' || $type eq 'int');
2101 if (!defined $config_file ||
2102 $config_file ne "$git_dir/config") {
2103 %config = git_parse_project_config
('gitweb');
2104 $config_file = "$git_dir/config";
2107 # check if config variable (key) exists
2108 return unless exists $config{"gitweb.$key"};
2111 if (!defined $type) {
2112 return $config{"gitweb.$key"};
2113 } elsif ($type eq 'bool') {
2114 # backward compatibility: 'git config --bool' returns true/false
2115 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2116 } elsif ($type eq 'int') {
2117 return config_to_int
($config{"gitweb.$key"});
2119 return $config{"gitweb.$key"};
2122 # get hash of given path at given ref
2123 sub git_get_hash_by_path
{
2125 my $path = shift || return undef;
2130 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2131 or die_error
(500, "Open git-ls-tree failed");
2133 close $fd or return undef;
2135 if (!defined $line) {
2136 # there is no tree or hash given by $path at $base
2140 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2141 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2142 if (defined $type && $type ne $2) {
2143 # type doesn't match
2149 # get path of entry with given hash at given tree-ish (ref)
2150 # used to get 'from' filename for combined diff (merge commit) for renames
2151 sub git_get_path_by_hash
{
2152 my $base = shift || return;
2153 my $hash = shift || return;
2157 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2159 while (my $line = <$fd>) {
2162 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2163 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2164 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2173 ## ......................................................................
2174 ## git utility functions, directly accessing git repository
2176 sub git_get_project_description
{
2179 $git_dir = "$projectroot/$path";
2180 open my $fd, '<', "$git_dir/description"
2181 or return git_get_project_config
('description');
2184 if (defined $descr) {
2190 sub git_get_project_ctags
{
2194 $git_dir = "$projectroot/$path";
2195 opendir my $dh, "$git_dir/ctags"
2197 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2198 open my $ct, '<', $_ or next;
2202 my $ctag = $_; $ctag =~ s
#.*/##;
2203 $ctags->{$ctag} = $val;
2209 sub git_populate_project_tagcloud
{
2212 # First, merge different-cased tags; tags vote on casing
2214 foreach (keys %$ctags) {
2215 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2216 if (not $ctags_lc{lc $_}->{topcount
}
2217 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2218 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2219 $ctags_lc{lc $_}->{topname
} = $_;
2224 if (eval { require HTML
::TagCloud
; 1; }) {
2225 $cloud = HTML
::TagCloud-
>new;
2226 foreach (sort keys %ctags_lc) {
2227 # Pad the title with spaces so that the cloud looks
2229 my $title = $ctags_lc{$_}->{topname
};
2230 $title =~ s/ / /g;
2231 $title =~ s/^/ /g;
2232 $title =~ s/$/ /g;
2233 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2236 $cloud = \
%ctags_lc;
2241 sub git_show_project_tagcloud
{
2242 my ($cloud, $count) = @_;
2243 print STDERR
ref($cloud)."..\n";
2244 if (ref $cloud eq 'HTML::TagCloud') {
2245 return $cloud->html_and_css($count);
2247 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2248 return '<p align="center">' . join (', ', map {
2249 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2250 } splice(@tags, 0, $count)) . '</p>';
2254 sub git_get_project_url_list
{
2257 $git_dir = "$projectroot/$path";
2258 open my $fd, '<', "$git_dir/cloneurl"
2259 or return wantarray ?
2260 @{ config_to_multi
(git_get_project_config
('url')) } :
2261 config_to_multi
(git_get_project_config
('url'));
2262 my @git_project_url_list = map { chomp; $_ } <$fd>;
2265 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2268 sub git_get_projects_list
{
2273 $filter =~ s/\.git$//;
2275 my $check_forks = gitweb_check_feature
('forks');
2277 if (-d
$projects_list) {
2278 # search in directory
2279 my $dir = $projects_list . ($filter ? "/$filter" : '');
2280 # remove the trailing "/"
2282 my $pfxlen = length("$dir");
2283 my $pfxdepth = ($dir =~ tr!/!!);
2286 follow_fast
=> 1, # follow symbolic links
2287 follow_skip
=> 2, # ignore duplicates
2288 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2290 # skip project-list toplevel, if we get it.
2291 return if (m!^[/.]$!);
2292 # only directories can be git repositories
2293 return unless (-d
$_);
2294 # don't traverse too deep (Find is super slow on os x)
2295 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2296 $File::Find
::prune
= 1;
2300 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2301 # we check related file in $projectroot
2302 my $path = ($filter ? "$filter/" : '') . $subdir;
2303 if (check_export_ok
("$projectroot/$path")) {
2304 push @list, { path
=> $path };
2305 $File::Find
::prune
= 1;
2310 } elsif (-f
$projects_list) {
2311 # read from file(url-encoded):
2312 # 'git%2Fgit.git Linus+Torvalds'
2313 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2314 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2316 open my $fd, '<', $projects_list or return;
2318 while (my $line = <$fd>) {
2320 my ($path, $owner) = split ' ', $line;
2321 $path = unescape
($path);
2322 $owner = unescape
($owner);
2323 if (!defined $path) {
2326 if ($filter ne '') {
2327 # looking for forks;
2328 my $pfx = substr($path, 0, length($filter));
2329 if ($pfx ne $filter) {
2332 my $sfx = substr($path, length($filter));
2333 if ($sfx !~ /^\/.*\
.git
$/) {
2336 } elsif ($check_forks) {
2338 foreach my $filter (keys %paths) {
2339 # looking for forks;
2340 my $pfx = substr($path, 0, length($filter));
2341 if ($pfx ne $filter) {
2344 my $sfx = substr($path, length($filter));
2345 if ($sfx !~ /^\/.*\
.git
$/) {
2348 # is a fork, don't include it in
2353 if (check_export_ok
("$projectroot/$path")) {
2356 owner
=> to_utf8
($owner),
2359 (my $forks_path = $path) =~ s/\.git$//;
2360 $paths{$forks_path}++;
2368 our $gitweb_project_owner = undef;
2369 sub git_get_project_list_from_file
{
2371 return if (defined $gitweb_project_owner);
2373 $gitweb_project_owner = {};
2374 # read from file (url-encoded):
2375 # 'git%2Fgit.git Linus+Torvalds'
2376 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2377 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2378 if (-f
$projects_list) {
2379 open(my $fd, '<', $projects_list);
2380 while (my $line = <$fd>) {
2382 my ($pr, $ow) = split ' ', $line;
2383 $pr = unescape
($pr);
2384 $ow = unescape
($ow);
2385 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2391 sub git_get_project_owner
{
2392 my $project = shift;
2395 return undef unless $project;
2396 $git_dir = "$projectroot/$project";
2398 if (!defined $gitweb_project_owner) {
2399 git_get_project_list_from_file
();
2402 if (exists $gitweb_project_owner->{$project}) {
2403 $owner = $gitweb_project_owner->{$project};
2405 if (!defined $owner){
2406 $owner = git_get_project_config
('owner');
2408 if (!defined $owner) {
2409 $owner = get_file_owner
("$git_dir");
2415 sub git_get_last_activity
{
2419 $git_dir = "$projectroot/$path";
2420 open($fd, "-|", git_cmd
(), 'for-each-ref',
2421 '--format=%(committer)',
2422 '--sort=-committerdate',
2424 'refs/heads') or return;
2425 my $most_recent = <$fd>;
2426 close $fd or return;
2427 if (defined $most_recent &&
2428 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2430 my $age = time - $timestamp;
2431 return ($age, age_string
($age));
2433 return (undef, undef);
2436 sub git_get_references
{
2437 my $type = shift || "";
2439 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2440 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2441 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2442 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2445 while (my $line = <$fd>) {
2447 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2448 if (defined $refs{$1}) {
2449 push @{$refs{$1}}, $2;
2455 close $fd or return;
2459 sub git_get_rev_name_tags
{
2460 my $hash = shift || return undef;
2462 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2464 my $name_rev = <$fd>;
2467 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2470 # catches also '$hash undefined' output
2475 ## ----------------------------------------------------------------------
2476 ## parse to hash functions
2480 my $tz = shift || "-0000";
2483 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2484 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2485 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2486 $date{'hour'} = $hour;
2487 $date{'minute'} = $min;
2488 $date{'mday'} = $mday;
2489 $date{'day'} = $days[$wday];
2490 $date{'month'} = $months[$mon];
2491 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2492 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2493 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2494 $mday, $months[$mon], $hour ,$min;
2495 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2496 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2498 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2499 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2500 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2501 $date{'hour_local'} = $hour;
2502 $date{'minute_local'} = $min;
2503 $date{'tz_local'} = $tz;
2504 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2505 1900+$year, $mon+1, $mday,
2506 $hour, $min, $sec, $tz);
2515 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2516 $tag{'id'} = $tag_id;
2517 while (my $line = <$fd>) {
2519 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2520 $tag{'object'} = $1;
2521 } elsif ($line =~ m/^type (.+)$/) {
2523 } elsif ($line =~ m/^tag (.+)$/) {
2525 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2526 $tag{'author'} = $1;
2527 $tag{'author_epoch'} = $2;
2528 $tag{'author_tz'} = $3;
2529 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2530 $tag{'author_name'} = $1;
2531 $tag{'author_email'} = $2;
2533 $tag{'author_name'} = $tag{'author'};
2535 } elsif ($line =~ m/--BEGIN/) {
2536 push @comment, $line;
2538 } elsif ($line eq "") {
2542 push @comment, <$fd>;
2543 $tag{'comment'} = \
@comment;
2544 close $fd or return;
2545 if (!defined $tag{'name'}) {
2551 sub parse_commit_text
{
2552 my ($commit_text, $withparents) = @_;
2553 my @commit_lines = split '\n', $commit_text;
2556 pop @commit_lines; # Remove '\0'
2558 if (! @commit_lines) {
2562 my $header = shift @commit_lines;
2563 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2566 ($co{'id'}, my @parents) = split ' ', $header;
2567 while (my $line = shift @commit_lines) {
2568 last if $line eq "\n";
2569 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2571 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2573 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2575 $co{'author_epoch'} = $2;
2576 $co{'author_tz'} = $3;
2577 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2578 $co{'author_name'} = $1;
2579 $co{'author_email'} = $2;
2581 $co{'author_name'} = $co{'author'};
2583 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2584 $co{'committer'} = $1;
2585 $co{'committer_epoch'} = $2;
2586 $co{'committer_tz'} = $3;
2587 $co{'committer_name'} = $co{'committer'};
2588 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2589 $co{'committer_name'} = $1;
2590 $co{'committer_email'} = $2;
2592 $co{'committer_name'} = $co{'committer'};
2596 if (!defined $co{'tree'}) {
2599 $co{'parents'} = \
@parents;
2600 $co{'parent'} = $parents[0];
2602 foreach my $title (@commit_lines) {
2605 $co{'title'} = chop_str
($title, 80, 5);
2606 # remove leading stuff of merges to make the interesting part visible
2607 if (length($title) > 50) {
2608 $title =~ s/^Automatic //;
2609 $title =~ s/^merge (of|with) /Merge ... /i;
2610 if (length($title) > 50) {
2611 $title =~ s/(http|rsync):\/\///;
2613 if (length($title) > 50) {
2614 $title =~ s/(master|www|rsync)\.//;
2616 if (length($title) > 50) {
2617 $title =~ s/kernel.org:?//;
2619 if (length($title) > 50) {
2620 $title =~ s/\/pub\/scm//;
2623 $co{'title_short'} = chop_str
($title, 50, 5);
2627 if (! defined $co{'title'} || $co{'title'} eq "") {
2628 $co{'title'} = $co{'title_short'} = '(no commit message)';
2630 # remove added spaces
2631 foreach my $line (@commit_lines) {
2634 $co{'comment'} = \
@commit_lines;
2636 my $age = time - $co{'committer_epoch'};
2638 $co{'age_string'} = age_string
($age);
2639 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2640 if ($age > 60*60*24*7*2) {
2641 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2642 $co{'age_string_age'} = $co{'age_string'};
2644 $co{'age_string_date'} = $co{'age_string'};
2645 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2651 my ($commit_id) = @_;
2656 open my $fd, "-|", git_cmd
(), "rev-list",
2662 or die_error
(500, "Open git-rev-list failed");
2663 %co = parse_commit_text
(<$fd>, 1);
2670 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2678 open my $fd, "-|", git_cmd
(), "rev-list",
2681 ("--max-count=" . $maxcount),
2682 ("--skip=" . $skip),
2686 ($filename ? ($filename) : ())
2687 or die_error
(500, "Open git-rev-list failed");
2688 while (my $line = <$fd>) {
2689 my %co = parse_commit_text
($line);
2694 return wantarray ? @cos : \
@cos;
2697 # parse line of git-diff-tree "raw" output
2698 sub parse_difftree_raw_line
{
2702 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2703 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2704 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2705 $res{'from_mode'} = $1;
2706 $res{'to_mode'} = $2;
2707 $res{'from_id'} = $3;
2709 $res{'status'} = $5;
2710 $res{'similarity'} = $6;
2711 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2712 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2714 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2717 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2718 # combined diff (for merge commit)
2719 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2720 $res{'nparents'} = length($1);
2721 $res{'from_mode'} = [ split(' ', $2) ];
2722 $res{'to_mode'} = pop @{$res{'from_mode'}};
2723 $res{'from_id'} = [ split(' ', $3) ];
2724 $res{'to_id'} = pop @{$res{'from_id'}};
2725 $res{'status'} = [ split('', $4) ];
2726 $res{'to_file'} = unquote
($5);
2728 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2729 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2730 $res{'commit'} = $1;
2733 return wantarray ? %res : \
%res;
2736 # wrapper: return parsed line of git-diff-tree "raw" output
2737 # (the argument might be raw line, or parsed info)
2738 sub parsed_difftree_line
{
2739 my $line_or_ref = shift;
2741 if (ref($line_or_ref) eq "HASH") {
2742 # pre-parsed (or generated by hand)
2743 return $line_or_ref;
2745 return parse_difftree_raw_line
($line_or_ref);
2749 # parse line of git-ls-tree output
2750 sub parse_ls_tree_line
{
2755 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2756 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2764 $res{'name'} = unquote
($4);
2767 return wantarray ? %res : \
%res;
2770 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2771 sub parse_from_to_diffinfo
{
2772 my ($diffinfo, $from, $to, @parents) = @_;
2774 if ($diffinfo->{'nparents'}) {
2776 $from->{'file'} = [];
2777 $from->{'href'} = [];
2778 fill_from_file_info
($diffinfo, @parents)
2779 unless exists $diffinfo->{'from_file'};
2780 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2781 $from->{'file'}[$i] =
2782 defined $diffinfo->{'from_file'}[$i] ?
2783 $diffinfo->{'from_file'}[$i] :
2784 $diffinfo->{'to_file'};
2785 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2786 $from->{'href'}[$i] = href
(action
=>"blob",
2787 hash_base
=>$parents[$i],
2788 hash
=>$diffinfo->{'from_id'}[$i],
2789 file_name
=>$from->{'file'}[$i]);
2791 $from->{'href'}[$i] = undef;
2795 # ordinary (not combined) diff
2796 $from->{'file'} = $diffinfo->{'from_file'};
2797 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2798 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2799 hash
=>$diffinfo->{'from_id'},
2800 file_name
=>$from->{'file'});
2802 delete $from->{'href'};
2806 $to->{'file'} = $diffinfo->{'to_file'};
2807 if (!is_deleted
($diffinfo)) { # file exists in result
2808 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2809 hash
=>$diffinfo->{'to_id'},
2810 file_name
=>$to->{'file'});
2812 delete $to->{'href'};
2816 ## ......................................................................
2817 ## parse to array of hashes functions
2819 sub git_get_heads_list
{
2823 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2824 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2825 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2828 while (my $line = <$fd>) {
2832 my ($refinfo, $committerinfo) = split(/\0/, $line);
2833 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2834 my ($committer, $epoch, $tz) =
2835 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2836 $ref_item{'fullname'} = $name;
2837 $name =~ s!^refs/heads/!!;
2839 $ref_item{'name'} = $name;
2840 $ref_item{'id'} = $hash;
2841 $ref_item{'title'} = $title || '(no commit message)';
2842 $ref_item{'epoch'} = $epoch;
2844 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2846 $ref_item{'age'} = "unknown";
2849 push @headslist, \
%ref_item;
2853 return wantarray ? @headslist : \
@headslist;
2856 sub git_get_tags_list
{
2860 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2861 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2862 '--format=%(objectname) %(objecttype) %(refname) '.
2863 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2866 while (my $line = <$fd>) {
2870 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2871 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2872 my ($creator, $epoch, $tz) =
2873 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2874 $ref_item{'fullname'} = $name;
2875 $name =~ s!^refs/tags/!!;
2877 $ref_item{'type'} = $type;
2878 $ref_item{'id'} = $id;
2879 $ref_item{'name'} = $name;
2880 if ($type eq "tag") {
2881 $ref_item{'subject'} = $title;
2882 $ref_item{'reftype'} = $reftype;
2883 $ref_item{'refid'} = $refid;
2885 $ref_item{'reftype'} = $type;
2886 $ref_item{'refid'} = $id;
2889 if ($type eq "tag" || $type eq "commit") {
2890 $ref_item{'epoch'} = $epoch;
2892 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2894 $ref_item{'age'} = "unknown";
2898 push @tagslist, \
%ref_item;
2902 return wantarray ? @tagslist : \
@tagslist;
2905 ## ----------------------------------------------------------------------
2906 ## filesystem-related functions
2908 sub get_file_owner
{
2911 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2912 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2913 if (!defined $gcos) {
2917 $owner =~ s/[,;].*$//;
2918 return to_utf8
($owner);
2921 # assume that file exists
2923 my $filename = shift;
2925 open my $fd, '<', $filename;
2926 print map { to_utf8
($_) } <$fd>;
2930 ## ......................................................................
2931 ## mimetype related functions
2933 sub mimetype_guess_file
{
2934 my $filename = shift;
2935 my $mimemap = shift;
2936 -r
$mimemap or return undef;
2939 open(my $mh, '<', $mimemap) or return undef;
2941 next if m/^#/; # skip comments
2942 my ($mimetype, $exts) = split(/\t+/);
2943 if (defined $exts) {
2944 my @exts = split(/\s+/, $exts);
2945 foreach my $ext (@exts) {
2946 $mimemap{$ext} = $mimetype;
2952 $filename =~ /\.([^.]*)$/;
2953 return $mimemap{$1};
2956 sub mimetype_guess
{
2957 my $filename = shift;
2959 $filename =~ /\./ or return undef;
2961 if ($mimetypes_file) {
2962 my $file = $mimetypes_file;
2963 if ($file !~ m!^/!) { # if it is relative path
2964 # it is relative to project
2965 $file = "$projectroot/$project/$file";
2967 $mime = mimetype_guess_file
($filename, $file);
2969 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2975 my $filename = shift;
2978 my $mime = mimetype_guess
($filename);
2979 $mime and return $mime;
2983 return $default_blob_plain_mimetype unless $fd;
2986 return 'text/plain';
2987 } elsif (! $filename) {
2988 return 'application/octet-stream';
2989 } elsif ($filename =~ m/\.png$/i) {
2991 } elsif ($filename =~ m/\.gif$/i) {
2993 } elsif ($filename =~ m/\.jpe?g$/i) {
2994 return 'image/jpeg';
2996 return 'application/octet-stream';
3000 sub blob_contenttype
{
3001 my ($fd, $file_name, $type) = @_;
3003 $type ||= blob_mimetype
($fd, $file_name);
3004 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3005 $type .= "; charset=$default_text_plain_charset";
3011 ## ======================================================================
3012 ## functions printing HTML: header, footer, error page
3014 sub git_header_html
{
3015 my $status = shift || "200 OK";
3016 my $expires = shift;
3018 my $title = "$site_name";
3019 if (defined $project) {
3020 $title .= " - " . to_utf8
($project);
3021 if (defined $action) {
3022 $title .= "/$action";
3023 if (defined $file_name) {
3024 $title .= " - " . esc_path
($file_name);
3025 if ($action eq "tree" && $file_name !~ m
|/$|) {
3032 # require explicit support from the UA if we are to send the page as
3033 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3034 # we have to do this because MSIE sometimes globs '*/*', pretending to
3035 # support xhtml+xml but choking when it gets what it asked for.
3036 if (defined $cgi->http('HTTP_ACCEPT') &&
3037 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3038 $cgi->Accept('application/xhtml+xml') != 0) {
3039 $content_type = 'application/xhtml+xml';
3041 $content_type = 'text/html';
3043 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3044 -status
=> $status, -expires
=> $expires);
3045 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3047 <?xml version="1.0" encoding="utf-8"?>
3048 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3049 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3050 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3051 <!-- git core binaries version $git_version -->
3053 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3054 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3055 <meta name="robots" content="index, nofollow"/>
3056 <title>$title</title>
3058 # the stylesheet, favicon etc urls won't work correctly with path_info
3059 # unless we set the appropriate base URL
3060 if ($ENV{'PATH_INFO'}) {
3061 print "<base href=\"".esc_url
($base_url)."\" />\n";
3063 # print out each stylesheet that exist, providing backwards capability
3064 # for those people who defined $stylesheet in a config file
3065 if (defined $stylesheet) {
3066 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3068 foreach my $stylesheet (@stylesheets) {
3069 next unless $stylesheet;
3070 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3073 if (defined $project) {
3074 my %href_params = get_feed_info
();
3075 if (!exists $href_params{'-title'}) {
3076 $href_params{'-title'} = 'log';
3079 foreach my $format qw(RSS Atom) {
3080 my $type = lc($format);
3082 '-rel' => 'alternate',
3083 '-title' => "$project - $href_params{'-title'} - $format feed",
3084 '-type' => "application/$type+xml"
3087 $href_params{'action'} = $type;
3088 $link_attr{'-href'} = href
(%href_params);
3090 "rel=\"$link_attr{'-rel'}\" ".
3091 "title=\"$link_attr{'-title'}\" ".
3092 "href=\"$link_attr{'-href'}\" ".
3093 "type=\"$link_attr{'-type'}\" ".
3096 $href_params{'extra_options'} = '--no-merges';
3097 $link_attr{'-href'} = href
(%href_params);
3098 $link_attr{'-title'} .= ' (no merges)';
3100 "rel=\"$link_attr{'-rel'}\" ".
3101 "title=\"$link_attr{'-title'}\" ".
3102 "href=\"$link_attr{'-href'}\" ".
3103 "type=\"$link_attr{'-type'}\" ".
3108 printf('<link rel="alternate" title="%s projects list" '.
3109 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3110 $site_name, href
(project
=>undef, action
=>"project_index"));
3111 printf('<link rel="alternate" title="%s projects feeds" '.
3112 'href="%s" type="text/x-opml" />'."\n",
3113 $site_name, href
(project
=>undef, action
=>"opml"));
3115 if (defined $favicon) {
3116 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3122 if (-f
$site_header) {
3123 insert_file
($site_header);
3126 print "<div class=\"page_header\">\n" .
3127 $cgi->a({-href
=> esc_url
($logo_url),
3128 -title
=> $logo_label},
3129 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3130 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3131 if (defined $project) {
3132 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3133 if (defined $action) {
3140 my $have_search = gitweb_check_feature
('search');
3141 if (defined $project && $have_search) {
3142 if (!defined $searchtext) {
3146 if (defined $hash_base) {
3147 $search_hash = $hash_base;
3148 } elsif (defined $hash) {
3149 $search_hash = $hash;
3151 $search_hash = "HEAD";
3153 my $action = $my_uri;
3154 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3155 if ($use_pathinfo) {
3156 $action .= "/".esc_url
($project);
3158 print $cgi->startform(-method => "get", -action
=> $action) .
3159 "<div class=\"search\">\n" .
3161 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3162 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3163 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3164 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3165 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3166 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3168 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3169 "<span title=\"Extended regular expression\">" .
3170 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3171 -checked
=> $search_use_regexp) .
3174 $cgi->end_form() . "\n";
3178 sub git_footer_html
{
3179 my $feed_class = 'rss_logo';
3181 print "<div class=\"page_footer\">\n";
3182 if (defined $project) {
3183 my $descr = git_get_project_description
($project);
3184 if (defined $descr) {
3185 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3188 my %href_params = get_feed_info
();
3189 if (!%href_params) {
3190 $feed_class .= ' generic';
3192 $href_params{'-title'} ||= 'log';
3194 foreach my $format qw(RSS Atom) {
3195 $href_params{'action'} = lc($format);
3196 print $cgi->a({-href
=> href
(%href_params),
3197 -title
=> "$href_params{'-title'} $format feed",
3198 -class => $feed_class}, $format)."\n";
3202 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3203 -class => $feed_class}, "OPML") . " ";
3204 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3205 -class => $feed_class}, "TXT") . "\n";
3207 print "</div>\n"; # class="page_footer"
3209 if (-f
$site_footer) {
3210 insert_file
($site_footer);
3217 # die_error(<http_status_code>, <error_message>)
3218 # Example: die_error(404, 'Hash not found')
3219 # By convention, use the following status codes (as defined in RFC 2616):
3220 # 400: Invalid or missing CGI parameters, or
3221 # requested object exists but has wrong type.
3222 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3223 # this server or project.
3224 # 404: Requested object/revision/project doesn't exist.
3225 # 500: The server isn't configured properly, or
3226 # an internal error occurred (e.g. failed assertions caused by bugs), or
3227 # an unknown error occurred (e.g. the git binary died unexpectedly).
3229 my $status = shift || 500;
3230 my $error = shift || "Internal server error";
3232 my %http_responses = (400 => '400 Bad Request',
3233 403 => '403 Forbidden',
3234 404 => '404 Not Found',
3235 500 => '500 Internal Server Error');
3236 git_header_html
($http_responses{$status});
3238 <div class="page_body">
3248 ## ----------------------------------------------------------------------
3249 ## functions printing or outputting HTML: navigation
3251 sub git_print_page_nav
{
3252 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3253 $extra = '' if !defined $extra; # pager or formats
3255 my @navs = qw(summary shortlog log commit commitdiff tree);
3257 @navs = grep { $_ ne $suppress } @navs;
3260 my %arg = map { $_ => {action
=>$_} } @navs;
3261 if (defined $head) {
3262 for (qw(commit commitdiff)) {
3263 $arg{$_}{'hash'} = $head;
3265 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3266 for (qw(shortlog log)) {
3267 $arg{$_}{'hash'} = $head;
3272 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3273 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3275 my @actions = gitweb_get_feature
('actions');
3278 'n' => $project, # project name
3279 'f' => $git_dir, # project path within filesystem
3280 'h' => $treehead || '', # current hash ('h' parameter)
3281 'b' => $treebase || '', # hash base ('hb' parameter)
3284 my ($label, $link, $pos) = splice(@actions,0,3);
3286 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3288 $link =~ s/%([%nfhb])/$repl{$1}/g;
3289 $arg{$label}{'_href'} = $link;
3292 print "<div class=\"page_nav\">\n" .
3294 map { $_ eq $current ?
3295 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3297 print "<br/>\n$extra<br/>\n" .
3301 sub format_paging_nav
{
3302 my ($action, $hash, $head, $page, $has_next_link) = @_;
3306 if ($hash ne $head || $page) {
3307 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3309 $paging_nav .= "HEAD";
3313 $paging_nav .= " ⋅ " .
3314 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3315 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3317 $paging_nav .= " ⋅ prev";
3320 if ($has_next_link) {
3321 $paging_nav .= " ⋅ " .
3322 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3323 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3325 $paging_nav .= " ⋅ next";
3331 ## ......................................................................
3332 ## functions printing or outputting HTML: div
3334 sub git_print_header_div
{
3335 my ($action, $title, $hash, $hash_base) = @_;
3338 $args{'action'} = $action;
3339 $args{'hash'} = $hash if $hash;
3340 $args{'hash_base'} = $hash_base if $hash_base;
3342 print "<div class=\"header\">\n" .
3343 $cgi->a({-href
=> href
(%args), -class => "title"},
3344 $title ? $title : $action) .
3348 sub print_local_time
{
3350 if ($date{'hour_local'} < 6) {
3351 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3352 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3354 printf(" (%02d:%02d %s)",
3355 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3359 # Outputs the author name and date in long form
3360 sub git_print_authorship
{
3363 my $tag = $opts{-tag
} || 'div';
3365 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3366 print "<$tag class=\"author_date\">" .
3367 esc_html
($co->{'author_name'}) .
3369 print_local_time
(%ad) if ($opts{-localtime});
3370 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3374 # Outputs table rows containing the full author or committer information,
3375 # in the format expected for 'commit' view (& similia).
3376 # Parameters are a commit hash reference, followed by the list of people
3377 # to output information for. If the list is empty it defalts to both
3378 # author and committer.
3379 sub git_print_authorship_rows
{
3381 # too bad we can't use @people = @_ || ('author', 'committer')
3383 @people = ('author', 'committer') unless @people;
3384 foreach my $who (@people) {
3385 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3386 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3387 "<td rowspan=\"2\">" .
3388 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3391 "<td></td><td> $wd{'rfc2822'}";
3392 print_local_time
(%wd);
3398 sub git_print_page_path
{
3404 print "<div class=\"page_path\">";
3405 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3406 -title
=> 'tree root'}, to_utf8
("[$project]"));
3408 if (defined $name) {
3409 my @dirname = split '/', $name;
3410 my $basename = pop @dirname;
3413 foreach my $dir (@dirname) {
3414 $fullname .= ($fullname ? '/' : '') . $dir;
3415 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3417 -title
=> $fullname}, esc_path
($dir));
3420 if (defined $type && $type eq 'blob') {
3421 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3423 -title
=> $name}, esc_path
($basename));
3424 } elsif (defined $type && $type eq 'tree') {
3425 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3427 -title
=> $name}, esc_path
($basename));
3430 print esc_path
($basename);
3433 print "<br/></div>\n";
3440 if ($opts{'-remove_title'}) {
3441 # remove title, i.e. first line of log
3444 # remove leading empty lines
3445 while (defined $log->[0] && $log->[0] eq "") {
3452 foreach my $line (@$log) {
3453 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3456 if (! $opts{'-remove_signoff'}) {
3457 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3460 # remove signoff lines
3467 # print only one empty line
3468 # do not print empty line after signoff
3470 next if ($empty || $signoff);
3476 print format_log_line_html
($line) . "<br/>\n";
3479 if ($opts{'-final_empty_line'}) {
3480 # end with single empty line
3481 print "<br/>\n" unless $empty;
3485 # return link target (what link points to)
3486 sub git_get_link_target
{
3491 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3495 $link_target = <$fd>;
3500 return $link_target;
3503 # given link target, and the directory (basedir) the link is in,
3504 # return target of link relative to top directory (top tree);
3505 # return undef if it is not possible (including absolute links).
3506 sub normalize_link_target
{
3507 my ($link_target, $basedir) = @_;
3509 # absolute symlinks (beginning with '/') cannot be normalized
3510 return if (substr($link_target, 0, 1) eq '/');
3512 # normalize link target to path from top (root) tree (dir)
3515 $path = $basedir . '/' . $link_target;
3517 # we are in top (root) tree (dir)
3518 $path = $link_target;
3521 # remove //, /./, and /../
3523 foreach my $part (split('/', $path)) {
3524 # discard '.' and ''
3525 next if (!$part || $part eq '.');
3527 if ($part eq '..') {
3531 # link leads outside repository (outside top dir)
3535 push @path_parts, $part;
3538 $path = join('/', @path_parts);
3543 # print tree entry (row of git_tree), but without encompassing <tr> element
3544 sub git_print_tree_entry
{
3545 my ($t, $basedir, $hash_base, $have_blame) = @_;
3548 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3550 # The format of a table row is: mode list link. Where mode is
3551 # the mode of the entry, list is the name of the entry, an href,
3552 # and link is the action links of the entry.
3554 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3555 if ($t->{'type'} eq "blob") {
3556 print "<td class=\"list\">" .
3557 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3558 file_name
=>"$basedir$t->{'name'}", %base_key),
3559 -class => "list"}, esc_path
($t->{'name'}));
3560 if (S_ISLNK
(oct $t->{'mode'})) {
3561 my $link_target = git_get_link_target
($t->{'hash'});
3563 my $norm_target = normalize_link_target
($link_target, $basedir);
3564 if (defined $norm_target) {
3566 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3567 file_name
=>$norm_target),
3568 -title
=> $norm_target}, esc_path
($link_target));
3570 print " -> " . esc_path
($link_target);
3575 print "<td class=\"link\">";
3576 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3577 file_name
=>"$basedir$t->{'name'}", %base_key)},
3581 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3582 file_name
=>"$basedir$t->{'name'}", %base_key)},
3585 if (defined $hash_base) {
3587 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3588 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3592 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3593 file_name
=>"$basedir$t->{'name'}")},
3597 } elsif ($t->{'type'} eq "tree") {
3598 print "<td class=\"list\">";
3599 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3600 file_name
=>"$basedir$t->{'name'}", %base_key)},
3601 esc_path
($t->{'name'}));
3603 print "<td class=\"link\">";
3604 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3605 file_name
=>"$basedir$t->{'name'}", %base_key)},
3607 if (defined $hash_base) {
3609 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3610 file_name
=>"$basedir$t->{'name'}")},
3615 # unknown object: we can only present history for it
3616 # (this includes 'commit' object, i.e. submodule support)
3617 print "<td class=\"list\">" .
3618 esc_path
($t->{'name'}) .
3620 print "<td class=\"link\">";
3621 if (defined $hash_base) {
3622 print $cgi->a({-href
=> href
(action
=>"history",
3623 hash_base
=>$hash_base,
3624 file_name
=>"$basedir$t->{'name'}")},
3631 ## ......................................................................
3632 ## functions printing large fragments of HTML
3634 # get pre-image filenames for merge (combined) diff
3635 sub fill_from_file_info
{
3636 my ($diff, @parents) = @_;
3638 $diff->{'from_file'} = [ ];
3639 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3640 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3641 if ($diff->{'status'}[$i] eq 'R' ||
3642 $diff->{'status'}[$i] eq 'C') {
3643 $diff->{'from_file'}[$i] =
3644 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3651 # is current raw difftree line of file deletion
3653 my $diffinfo = shift;
3655 return $diffinfo->{'to_id'} eq ('0' x
40);
3658 # does patch correspond to [previous] difftree raw line
3659 # $diffinfo - hashref of parsed raw diff format
3660 # $patchinfo - hashref of parsed patch diff format
3661 # (the same keys as in $diffinfo)
3662 sub is_patch_split
{
3663 my ($diffinfo, $patchinfo) = @_;
3665 return defined $diffinfo && defined $patchinfo
3666 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3670 sub git_difftree_body
{
3671 my ($difftree, $hash, @parents) = @_;
3672 my ($parent) = $parents[0];
3673 my $have_blame = gitweb_check_feature
('blame');
3674 print "<div class=\"list_head\">\n";
3675 if ($#{$difftree} > 10) {
3676 print(($#{$difftree} + 1) . " files changed:\n");
3680 print "<table class=\"" .
3681 (@parents > 1 ? "combined " : "") .
3684 # header only for combined diff in 'commitdiff' view
3685 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3688 print "<thead><tr>\n" .
3689 "<th></th><th></th>\n"; # filename, patchN link
3690 for (my $i = 0; $i < @parents; $i++) {
3691 my $par = $parents[$i];
3693 $cgi->a({-href
=> href
(action
=>"commitdiff",
3694 hash
=>$hash, hash_parent
=>$par),
3695 -title
=> 'commitdiff to parent number ' .
3696 ($i+1) . ': ' . substr($par,0,7)},
3700 print "</tr></thead>\n<tbody>\n";
3705 foreach my $line (@{$difftree}) {
3706 my $diff = parsed_difftree_line
($line);
3709 print "<tr class=\"dark\">\n";
3711 print "<tr class=\"light\">\n";
3715 if (exists $diff->{'nparents'}) { # combined diff
3717 fill_from_file_info
($diff, @parents)
3718 unless exists $diff->{'from_file'};
3720 if (!is_deleted
($diff)) {
3721 # file exists in the result (child) commit
3723 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3724 file_name
=>$diff->{'to_file'},
3726 -class => "list"}, esc_path
($diff->{'to_file'})) .
3730 esc_path
($diff->{'to_file'}) .
3734 if ($action eq 'commitdiff') {
3737 print "<td class=\"link\">" .
3738 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3743 my $has_history = 0;
3744 my $not_deleted = 0;
3745 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3746 my $hash_parent = $parents[$i];
3747 my $from_hash = $diff->{'from_id'}[$i];
3748 my $from_path = $diff->{'from_file'}[$i];
3749 my $status = $diff->{'status'}[$i];
3751 $has_history ||= ($status ne 'A');
3752 $not_deleted ||= ($status ne 'D');
3754 if ($status eq 'A') {
3755 print "<td class=\"link\" align=\"right\"> | </td>\n";
3756 } elsif ($status eq 'D') {
3757 print "<td class=\"link\">" .
3758 $cgi->a({-href
=> href
(action
=>"blob",
3761 file_name
=>$from_path)},
3765 if ($diff->{'to_id'} eq $from_hash) {
3766 print "<td class=\"link nochange\">";
3768 print "<td class=\"link\">";
3770 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3771 hash
=>$diff->{'to_id'},
3772 hash_parent
=>$from_hash,
3774 hash_parent_base
=>$hash_parent,
3775 file_name
=>$diff->{'to_file'},
3776 file_parent
=>$from_path)},
3782 print "<td class=\"link\">";
3784 print $cgi->a({-href
=> href
(action
=>"blob",
3785 hash
=>$diff->{'to_id'},
3786 file_name
=>$diff->{'to_file'},
3789 print " | " if ($has_history);
3792 print $cgi->a({-href
=> href
(action
=>"history",
3793 file_name
=>$diff->{'to_file'},
3800 next; # instead of 'else' clause, to avoid extra indent
3802 # else ordinary diff
3804 my ($to_mode_oct, $to_mode_str, $to_file_type);
3805 my ($from_mode_oct, $from_mode_str, $from_file_type);
3806 if ($diff->{'to_mode'} ne ('0' x
6)) {
3807 $to_mode_oct = oct $diff->{'to_mode'};
3808 if (S_ISREG
($to_mode_oct)) { # only for regular file
3809 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3811 $to_file_type = file_type
($diff->{'to_mode'});
3813 if ($diff->{'from_mode'} ne ('0' x
6)) {
3814 $from_mode_oct = oct $diff->{'from_mode'};
3815 if (S_ISREG
($to_mode_oct)) { # only for regular file
3816 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3818 $from_file_type = file_type
($diff->{'from_mode'});
3821 if ($diff->{'status'} eq "A") { # created
3822 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3823 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3824 $mode_chng .= "]</span>";
3826 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3827 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3828 -class => "list"}, esc_path
($diff->{'file'}));
3830 print "<td>$mode_chng</td>\n";
3831 print "<td class=\"link\">";
3832 if ($action eq 'commitdiff') {
3835 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3838 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3839 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3843 } elsif ($diff->{'status'} eq "D") { # deleted
3844 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3846 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3847 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3848 -class => "list"}, esc_path
($diff->{'file'}));
3850 print "<td>$mode_chng</td>\n";
3851 print "<td class=\"link\">";
3852 if ($action eq 'commitdiff') {
3855 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3858 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3859 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3862 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3863 file_name
=>$diff->{'file'})},
3866 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3867 file_name
=>$diff->{'file'})},
3871 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3872 my $mode_chnge = "";
3873 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3874 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3875 if ($from_file_type ne $to_file_type) {
3876 $mode_chnge .= " from $from_file_type to $to_file_type";
3878 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3879 if ($from_mode_str && $to_mode_str) {
3880 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3881 } elsif ($to_mode_str) {
3882 $mode_chnge .= " mode: $to_mode_str";
3885 $mode_chnge .= "]</span>\n";
3888 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3889 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3890 -class => "list"}, esc_path
($diff->{'file'}));
3892 print "<td>$mode_chnge</td>\n";
3893 print "<td class=\"link\">";
3894 if ($action eq 'commitdiff') {
3897 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3899 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3900 # "commit" view and modified file (not onlu mode changed)
3901 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3902 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3903 hash_base
=>$hash, hash_parent_base
=>$parent,
3904 file_name
=>$diff->{'file'})},
3908 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3909 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3912 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3913 file_name
=>$diff->{'file'})},
3916 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3917 file_name
=>$diff->{'file'})},
3921 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3922 my %status_name = ('R' => 'moved', 'C' => 'copied');
3923 my $nstatus = $status_name{$diff->{'status'}};
3925 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3926 # mode also for directories, so we cannot use $to_mode_str
3927 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3930 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3931 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3932 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3933 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3934 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3935 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3936 -class => "list"}, esc_path
($diff->{'from_file'})) .
3937 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3938 "<td class=\"link\">";
3939 if ($action eq 'commitdiff') {
3942 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3944 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3945 # "commit" view and modified file (not only pure rename or copy)
3946 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3947 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3948 hash_base
=>$hash, hash_parent_base
=>$parent,
3949 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3953 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3954 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3957 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3958 file_name
=>$diff->{'to_file'})},
3961 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3962 file_name
=>$diff->{'to_file'})},
3966 } # we should not encounter Unmerged (U) or Unknown (X) status
3969 print "</tbody>" if $has_header;
3973 sub git_patchset_body
{
3974 my ($fd, $difftree, $hash, @hash_parents) = @_;
3975 my ($hash_parent) = $hash_parents[0];
3977 my $is_combined = (@hash_parents > 1);
3979 my $patch_number = 0;
3985 print "<div class=\"patchset\">\n";
3987 # skip to first patch
3988 while ($patch_line = <$fd>) {
3991 last if ($patch_line =~ m/^diff /);
3995 while ($patch_line) {
3997 # parse "git diff" header line
3998 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3999 # $1 is from_name, which we do not use
4000 $to_name = unquote
($2);
4001 $to_name =~ s!^b/!!;
4002 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4003 # $1 is 'cc' or 'combined', which we do not use
4004 $to_name = unquote
($2);
4009 # check if current patch belong to current raw line
4010 # and parse raw git-diff line if needed
4011 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4012 # this is continuation of a split patch
4013 print "<div class=\"patch cont\">\n";
4015 # advance raw git-diff output if needed
4016 $patch_idx++ if defined $diffinfo;
4018 # read and prepare patch information
4019 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4021 # compact combined diff output can have some patches skipped
4022 # find which patch (using pathname of result) we are at now;
4024 while ($to_name ne $diffinfo->{'to_file'}) {
4025 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4026 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4027 "</div>\n"; # class="patch"
4032 last if $patch_idx > $#$difftree;
4033 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4037 # modifies %from, %to hashes
4038 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4040 # this is first patch for raw difftree line with $patch_idx index
4041 # we index @$difftree array from 0, but number patches from 1
4042 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4046 #assert($patch_line =~ m/^diff /) if DEBUG;
4047 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4049 # print "git diff" header
4050 print format_git_diff_header_line
($patch_line, $diffinfo,
4053 # print extended diff header
4054 print "<div class=\"diff extended_header\">\n";
4056 while ($patch_line = <$fd>) {
4059 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4061 print format_extended_diff_header_line
($patch_line, $diffinfo,
4064 print "</div>\n"; # class="diff extended_header"
4066 # from-file/to-file diff header
4067 if (! $patch_line) {
4068 print "</div>\n"; # class="patch"
4071 next PATCH
if ($patch_line =~ m/^diff /);
4072 #assert($patch_line =~ m/^---/) if DEBUG;
4074 my $last_patch_line = $patch_line;
4075 $patch_line = <$fd>;
4077 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4079 print format_diff_from_to_header
($last_patch_line, $patch_line,
4080 $diffinfo, \
%from, \
%to,
4085 while ($patch_line = <$fd>) {
4088 next PATCH
if ($patch_line =~ m/^diff /);
4090 print format_diff_line
($patch_line, \
%from, \
%to);
4094 print "</div>\n"; # class="patch"
4097 # for compact combined (--cc) format, with chunk and patch simpliciaction
4098 # patchset might be empty, but there might be unprocessed raw lines
4099 for (++$patch_idx if $patch_number > 0;
4100 $patch_idx < @$difftree;
4102 # read and prepare patch information
4103 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4105 # generate anchor for "patch" links in difftree / whatchanged part
4106 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4107 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4108 "</div>\n"; # class="patch"
4113 if ($patch_number == 0) {
4114 if (@hash_parents > 1) {
4115 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4117 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4121 print "</div>\n"; # class="patchset"
4124 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4126 # fills project list info (age, description, owner, forks) for each
4127 # project in the list, removing invalid projects from returned list
4128 # NOTE: modifies $projlist, but does not remove entries from it
4129 sub fill_project_list_info
{
4130 my ($projlist, $check_forks) = @_;
4133 my $show_ctags = gitweb_check_feature
('ctags');
4135 foreach my $pr (@$projlist) {
4136 my (@activity) = git_get_last_activity
($pr->{'path'});
4137 unless (@activity) {
4140 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4141 if (!defined $pr->{'descr'}) {
4142 my $descr = git_get_project_description
($pr->{'path'}) || "";
4143 $descr = to_utf8
($descr);
4144 $pr->{'descr_long'} = $descr;
4145 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4147 if (!defined $pr->{'owner'}) {
4148 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4151 my $pname = $pr->{'path'};
4152 if (($pname =~ s/\.git$//) &&
4153 ($pname !~ /\/$/) &&
4154 (-d
"$projectroot/$pname")) {
4155 $pr->{'forks'} = "-d $projectroot/$pname";
4160 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4161 push @projects, $pr;
4167 # print 'sort by' <th> element, generating 'sort by $name' replay link
4168 # if that order is not selected
4170 my ($name, $order, $header) = @_;
4171 $header ||= ucfirst($name);
4173 if ($order eq $name) {
4174 print "<th>$header</th>\n";
4177 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4178 -class => "header"}, $header) .
4183 sub git_project_list_body
{
4184 # actually uses global variable $project
4185 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4187 my $check_forks = gitweb_check_feature
('forks');
4188 my @projects = fill_project_list_info
($projlist, $check_forks);
4190 $order ||= $default_projects_order;
4191 $from = 0 unless defined $from;
4192 $to = $#projects if (!defined $to || $#projects < $to);
4195 project
=> { key
=> 'path', type
=> 'str' },
4196 descr
=> { key
=> 'descr_long', type
=> 'str' },
4197 owner
=> { key
=> 'owner', type
=> 'str' },
4198 age
=> { key
=> 'age', type
=> 'num' }
4200 my $oi = $order_info{$order};
4201 if ($oi->{'type'} eq 'str') {
4202 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4204 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4207 my $show_ctags = gitweb_check_feature
('ctags');
4210 foreach my $p (@projects) {
4211 foreach my $ct (keys %{$p->{'ctags'}}) {
4212 $ctags{$ct} += $p->{'ctags'}->{$ct};
4215 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4216 print git_show_project_tagcloud
($cloud, 64);
4219 print "<table class=\"project_list\">\n";
4220 unless ($no_header) {
4223 print "<th></th>\n";
4225 print_sort_th
('project', $order, 'Project');
4226 print_sort_th
('descr', $order, 'Description');
4227 print_sort_th
('owner', $order, 'Owner');
4228 print_sort_th
('age', $order, 'Last Change');
4229 print "<th></th>\n" . # for links
4233 my $tagfilter = $cgi->param('by_tag');
4234 for (my $i = $from; $i <= $to; $i++) {
4235 my $pr = $projects[$i];
4237 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4238 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4239 and not $pr->{'descr_long'} =~ /$searchtext/;
4240 # Weed out forks or non-matching entries of search
4242 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4243 $forkbase="^$forkbase" if $forkbase;
4244 next if not $searchtext and not $tagfilter and $show_ctags
4245 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4249 print "<tr class=\"dark\">\n";
4251 print "<tr class=\"light\">\n";
4256 if ($pr->{'forks'}) {
4257 print "<!-- $pr->{'forks'} -->\n";
4258 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4262 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4263 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4264 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4265 -class => "list", -title
=> $pr->{'descr_long'}},
4266 esc_html
($pr->{'descr'})) . "</td>\n" .
4267 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4268 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4269 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4270 "<td class=\"link\">" .
4271 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4272 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4273 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4274 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4275 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4279 if (defined $extra) {
4282 print "<td></td>\n";
4284 print "<td colspan=\"5\">$extra</td>\n" .
4290 sub git_shortlog_body
{
4291 # uses global variable $project
4292 my ($commitlist, $from, $to, $refs, $extra) = @_;
4294 $from = 0 unless defined $from;
4295 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4297 print "<table class=\"shortlog\">\n";
4299 for (my $i = $from; $i <= $to; $i++) {
4300 my %co = %{$commitlist->[$i]};
4301 my $commit = $co{'id'};
4302 my $ref = format_ref_marker
($refs, $commit);
4304 print "<tr class=\"dark\">\n";
4306 print "<tr class=\"light\">\n";
4309 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4310 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4311 format_author_html
('td', \
%co, 10) . "<td>";
4312 print format_subject_html
($co{'title'}, $co{'title_short'},
4313 href
(action
=>"commit", hash
=>$commit), $ref);
4315 "<td class=\"link\">" .
4316 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4317 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4318 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4319 my $snapshot_links = format_snapshot_links
($commit);
4320 if (defined $snapshot_links) {
4321 print " | " . $snapshot_links;
4326 if (defined $extra) {
4328 "<td colspan=\"4\">$extra</td>\n" .
4334 sub git_history_body
{
4335 # Warning: assumes constant type (blob or tree) during history
4336 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4338 $from = 0 unless defined $from;
4339 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4341 print "<table class=\"history\">\n";
4343 for (my $i = $from; $i <= $to; $i++) {
4344 my %co = %{$commitlist->[$i]};
4348 my $commit = $co{'id'};
4350 my $ref = format_ref_marker
($refs, $commit);
4353 print "<tr class=\"dark\">\n";
4355 print "<tr class=\"light\">\n";
4358 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4359 # shortlog: format_author_html('td', \%co, 10)
4360 format_author_html
('td', \
%co, 15, 3) . "<td>";
4361 # originally git_history used chop_str($co{'title'}, 50)
4362 print format_subject_html
($co{'title'}, $co{'title_short'},
4363 href
(action
=>"commit", hash
=>$commit), $ref);
4365 "<td class=\"link\">" .
4366 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4367 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4369 if ($ftype eq 'blob') {
4370 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4371 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4372 if (defined $blob_current && defined $blob_parent &&
4373 $blob_current ne $blob_parent) {
4375 $cgi->a({-href
=> href
(action
=>"blobdiff",
4376 hash
=>$blob_current, hash_parent
=>$blob_parent,
4377 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4378 file_name
=>$file_name)},
4385 if (defined $extra) {
4387 "<td colspan=\"4\">$extra</td>\n" .
4394 # uses global variable $project
4395 my ($taglist, $from, $to, $extra) = @_;
4396 $from = 0 unless defined $from;
4397 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4399 print "<table class=\"tags\">\n";
4401 for (my $i = $from; $i <= $to; $i++) {
4402 my $entry = $taglist->[$i];
4404 my $comment = $tag{'subject'};
4406 if (defined $comment) {
4407 $comment_short = chop_str
($comment, 30, 5);
4410 print "<tr class=\"dark\">\n";
4412 print "<tr class=\"light\">\n";
4415 if (defined $tag{'age'}) {
4416 print "<td><i>$tag{'age'}</i></td>\n";
4418 print "<td></td>\n";
4421 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4422 -class => "list name"}, esc_html
($tag{'name'})) .
4425 if (defined $comment) {
4426 print format_subject_html
($comment, $comment_short,
4427 href
(action
=>"tag", hash
=>$tag{'id'}));
4430 "<td class=\"selflink\">";
4431 if ($tag{'type'} eq "tag") {
4432 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4437 "<td class=\"link\">" . " | " .
4438 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4439 if ($tag{'reftype'} eq "commit") {
4440 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4441 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4442 } elsif ($tag{'reftype'} eq "blob") {
4443 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4448 if (defined $extra) {
4450 "<td colspan=\"5\">$extra</td>\n" .
4456 sub git_heads_body
{
4457 # uses global variable $project
4458 my ($headlist, $head, $from, $to, $extra) = @_;
4459 $from = 0 unless defined $from;
4460 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4462 print "<table class=\"heads\">\n";
4464 for (my $i = $from; $i <= $to; $i++) {
4465 my $entry = $headlist->[$i];
4467 my $curr = $ref{'id'} eq $head;
4469 print "<tr class=\"dark\">\n";
4471 print "<tr class=\"light\">\n";
4474 print "<td><i>$ref{'age'}</i></td>\n" .
4475 ($curr ? "<td class=\"current_head\">" : "<td>") .
4476 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4477 -class => "list name"},esc_html
($ref{'name'})) .
4479 "<td class=\"link\">" .
4480 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4481 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4482 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4486 if (defined $extra) {
4488 "<td colspan=\"3\">$extra</td>\n" .
4494 sub git_search_grep_body
{
4495 my ($commitlist, $from, $to, $extra) = @_;
4496 $from = 0 unless defined $from;
4497 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4499 print "<table class=\"commit_search\">\n";
4501 for (my $i = $from; $i <= $to; $i++) {
4502 my %co = %{$commitlist->[$i]};
4506 my $commit = $co{'id'};
4508 print "<tr class=\"dark\">\n";
4510 print "<tr class=\"light\">\n";
4513 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4514 format_author_html
('td', \
%co, 15, 5) .
4516 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4517 -class => "list subject"},
4518 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4519 my $comment = $co{'comment'};
4520 foreach my $line (@$comment) {
4521 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4522 my ($lead, $match, $trail) = ($1, $2, $3);
4523 $match = chop_str
($match, 70, 5, 'center');
4524 my $contextlen = int((80 - length($match))/2);
4525 $contextlen = 30 if ($contextlen > 30);
4526 $lead = chop_str
($lead, $contextlen, 10, 'left');
4527 $trail = chop_str
($trail, $contextlen, 10, 'right');
4529 $lead = esc_html
($lead);
4530 $match = esc_html
($match);
4531 $trail = esc_html
($trail);
4533 print "$lead<span class=\"match\">$match</span>$trail<br />";
4537 "<td class=\"link\">" .
4538 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4540 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4542 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4546 if (defined $extra) {
4548 "<td colspan=\"3\">$extra</td>\n" .
4554 ## ======================================================================
4555 ## ======================================================================
4558 sub git_project_list
{
4559 my $order = $input_params{'order'};
4560 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4561 die_error
(400, "Unknown order parameter");
4564 my @list = git_get_projects_list
();
4566 die_error
(404, "No projects found");
4570 if (-f
$home_text) {
4571 print "<div class=\"index_include\">\n";
4572 insert_file
($home_text);
4575 print $cgi->startform(-method => "get") .
4576 "<p class=\"projsearch\">Search:\n" .
4577 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4579 $cgi->end_form() . "\n";
4580 git_project_list_body
(\
@list, $order);
4585 my $order = $input_params{'order'};
4586 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4587 die_error
(400, "Unknown order parameter");
4590 my @list = git_get_projects_list
($project);
4592 die_error
(404, "No forks found");
4596 git_print_page_nav
('','');
4597 git_print_header_div
('summary', "$project forks");
4598 git_project_list_body
(\
@list, $order);
4602 sub git_project_index
{
4603 my @projects = git_get_projects_list
($project);
4606 -type
=> 'text/plain',
4607 -charset
=> 'utf-8',
4608 -content_disposition
=> 'inline; filename="index.aux"');
4610 foreach my $pr (@projects) {
4611 if (!exists $pr->{'owner'}) {
4612 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4615 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4616 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4617 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4618 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4622 print "$path $owner\n";
4627 my $descr = git_get_project_description
($project) || "none";
4628 my %co = parse_commit
("HEAD");
4629 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4630 my $head = $co{'id'};
4632 my $owner = git_get_project_owner
($project);
4634 my $refs = git_get_references
();
4635 # These get_*_list functions return one more to allow us to see if
4636 # there are more ...
4637 my @taglist = git_get_tags_list
(16);
4638 my @headlist = git_get_heads_list
(16);
4640 my $check_forks = gitweb_check_feature
('forks');
4643 @forklist = git_get_projects_list
($project);
4647 git_print_page_nav
('summary','', $head);
4649 print "<div class=\"title\"> </div>\n";
4650 print "<table class=\"projects_list\">\n" .
4651 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4652 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4653 if (defined $cd{'rfc2822'}) {
4654 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4657 # use per project git URL list in $projectroot/$project/cloneurl
4658 # or make project git URL from git base URL and project name
4659 my $url_tag = "URL";
4660 my @url_list = git_get_project_url_list
($project);
4661 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4662 foreach my $git_url (@url_list) {
4663 next unless $git_url;
4664 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4669 my $show_ctags = gitweb_check_feature
('ctags');
4671 my $ctags = git_get_project_ctags
($project);
4672 my $cloud = git_populate_project_tagcloud
($ctags);
4673 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4674 print "</td>\n<td>" unless %$ctags;
4675 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4676 print "</td>\n<td>" if %$ctags;
4677 print git_show_project_tagcloud
($cloud, 48);
4683 # If XSS prevention is on, we don't include README.html.
4684 # TODO: Allow a readme in some safe format.
4685 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4686 print "<div class=\"title\">readme</div>\n" .
4687 "<div class=\"readme\">\n";
4688 insert_file
("$projectroot/$project/README.html");
4689 print "\n</div>\n"; # class="readme"
4692 # we need to request one more than 16 (0..15) to check if
4694 my @commitlist = $head ? parse_commits
($head, 17) : ();
4696 git_print_header_div
('shortlog');
4697 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4698 $#commitlist <= 15 ? undef :
4699 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4703 git_print_header_div
('tags');
4704 git_tags_body
(\
@taglist, 0, 15,
4705 $#taglist <= 15 ? undef :
4706 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4710 git_print_header_div
('heads');
4711 git_heads_body
(\
@headlist, $head, 0, 15,
4712 $#headlist <= 15 ? undef :
4713 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4717 git_print_header_div
('forks');
4718 git_project_list_body
(\
@forklist, 'age', 0, 15,
4719 $#forklist <= 15 ? undef :
4720 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4728 my $head = git_get_head_hash
($project);
4730 git_print_page_nav
('','', $head,undef,$head);
4731 my %tag = parse_tag
($hash);
4734 die_error
(404, "Unknown tag object");
4737 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4738 print "<div class=\"title_text\">\n" .
4739 "<table class=\"object_header\">\n" .
4741 "<td>object</td>\n" .
4742 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4743 $tag{'object'}) . "</td>\n" .
4744 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4745 $tag{'type'}) . "</td>\n" .
4747 if (defined($tag{'author'})) {
4748 git_print_authorship_rows
(\
%tag, 'author');
4750 print "</table>\n\n" .
4752 print "<div class=\"page_body\">";
4753 my $comment = $tag{'comment'};
4754 foreach my $line (@$comment) {
4756 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4764 gitweb_check_feature
('blame')
4765 or die_error
(403, "Blame view not allowed");
4768 die_error
(400, "No file name given") unless $file_name;
4769 $hash_base ||= git_get_head_hash
($project);
4770 die_error
(404, "Couldn't find base commit") unless $hash_base;
4771 my %co = parse_commit
($hash_base)
4772 or die_error
(404, "Commit not found");
4774 if (!defined $hash) {
4775 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4776 or die_error
(404, "Error looking up file");
4778 $ftype = git_get_type
($hash);
4779 if ($ftype !~ "blob") {
4780 die_error
(400, "Object is not a blob");
4784 # run git-blame --porcelain
4785 open my $fd, "-|", git_cmd
(), "blame", '-p',
4786 $hash_base, '--', $file_name
4787 or die_error
(500, "Open git-blame failed");
4792 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4795 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4798 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4800 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4801 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4802 git_print_page_path
($file_name, $ftype, $hash_base);
4805 my @rev_color = qw(light2 dark2);
4806 my $num_colors = scalar(@rev_color);
4807 my $current_color = 0;
4811 <div class="page_body">
4812 <table class="blame">
4813 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4816 while (my $line = <$fd>) {
4818 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4819 # no <lines in group> for subsequent lines in group of lines
4820 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4821 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4822 if (!exists $metainfo{$full_rev}) {
4823 $metainfo{$full_rev} = { 'nprevious' => 0 };
4825 my $meta = $metainfo{$full_rev};
4827 while ($data = <$fd>) {
4829 last if ($data =~ s/^\t//); # contents of line
4830 if ($data =~ /^(\S+)(?: (.*))?$/) {
4831 $meta->{$1} = $2 unless exists $meta->{$1};
4833 if ($data =~ /^previous /) {
4834 $meta->{'nprevious'}++;
4837 my $short_rev = substr($full_rev, 0, 8);
4838 my $author = $meta->{'author'};
4840 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4841 my $date = $date{'iso-tz'};
4843 $current_color = ($current_color + 1) % $num_colors;
4845 my $tr_class = $rev_color[$current_color];
4846 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4847 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4848 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4849 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4851 print "<td class=\"sha1\"";
4852 print " title=\"". esc_html
($author) . ", $date\"";
4853 print " rowspan=\"$group_size\"" if ($group_size > 1);
4855 print $cgi->a({-href
=> href
(action
=>"commit",
4857 file_name
=>$file_name)},
4858 esc_html
($short_rev));
4861 # 'previous' <sha1 of parent commit> <filename at commit>
4862 if (exists $meta->{'previous'} &&
4863 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
4864 $meta->{'parent'} = $1;
4865 $meta->{'file_parent'} = unquote
($2);
4868 exists($meta->{'parent'}) ?
4869 $meta->{'parent'} : $full_rev;
4870 my $linenr_filename =
4871 exists($meta->{'file_parent'}) ?
4872 $meta->{'file_parent'} : unquote
($meta->{'filename'});
4873 my $blamed = href
(action
=> 'blame',
4874 file_name
=> $linenr_filename,
4875 hash_base
=> $linenr_commit);
4876 print "<td class=\"linenr\">";
4877 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4878 -class => "linenr" },
4881 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4887 or print "Reading blob failed\n";
4894 my $head = git_get_head_hash
($project);
4896 git_print_page_nav
('','', $head,undef,$head);
4897 git_print_header_div
('summary', $project);
4899 my @tagslist = git_get_tags_list
();
4901 git_tags_body
(\
@tagslist);
4907 my $head = git_get_head_hash
($project);
4909 git_print_page_nav
('','', $head,undef,$head);
4910 git_print_header_div
('summary', $project);
4912 my @headslist = git_get_heads_list
();
4914 git_heads_body
(\
@headslist, $head);
4919 sub git_blob_plain
{
4923 if (!defined $hash) {
4924 if (defined $file_name) {
4925 my $base = $hash_base || git_get_head_hash
($project);
4926 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4927 or die_error
(404, "Cannot find file");
4929 die_error
(400, "No file name defined");
4931 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4932 # blobs defined by non-textual hash id's can be cached
4936 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4937 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4939 # content-type (can include charset)
4940 $type = blob_contenttype
($fd, $file_name, $type);
4942 # "save as" filename, even when no $file_name is given
4943 my $save_as = "$hash";
4944 if (defined $file_name) {
4945 $save_as = $file_name;
4946 } elsif ($type =~ m/^text\//) {
4950 # With XSS prevention on, blobs of all types except a few known safe
4951 # ones are served with "Content-Disposition: attachment" to make sure
4952 # they don't run in our security domain. For certain image types,
4953 # blob view writes an <img> tag referring to blob_plain view, and we
4954 # want to be sure not to break that by serving the image as an
4955 # attachment (though Firefox 3 doesn't seem to care).
4956 my $sandbox = $prevent_xss &&
4957 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4961 -expires
=> $expires,
4962 -content_disposition
=>
4963 ($sandbox ? 'attachment' : 'inline')
4964 . '; filename="' . $save_as . '"');
4966 binmode STDOUT
, ':raw';
4968 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4975 if (!defined $hash) {
4976 if (defined $file_name) {
4977 my $base = $hash_base || git_get_head_hash
($project);
4978 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4979 or die_error
(404, "Cannot find file");
4981 die_error
(400, "No file name defined");
4983 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4984 # blobs defined by non-textual hash id's can be cached
4988 my $have_blame = gitweb_check_feature
('blame');
4989 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4990 or die_error
(500, "Couldn't cat $file_name, $hash");
4991 my $mimetype = blob_mimetype
($fd, $file_name);
4992 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4994 return git_blob_plain
($mimetype);
4996 # we can have blame only for text/* mimetype
4997 $have_blame &&= ($mimetype =~ m!^text/!);
4999 git_header_html
(undef, $expires);
5000 my $formats_nav = '';
5001 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5002 if (defined $file_name) {
5005 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5010 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5013 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5016 $cgi->a({-href
=> href
(action
=>"blob",
5017 hash_base
=>"HEAD", file_name
=>$file_name)},
5021 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5024 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5025 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5027 print "<div class=\"page_nav\">\n" .
5028 "<br/><br/></div>\n" .
5029 "<div class=\"title\">$hash</div>\n";
5031 git_print_page_path
($file_name, "blob", $hash_base);
5032 print "<div class=\"page_body\">\n";
5033 if ($mimetype =~ m!^image/!) {
5034 print qq
!<img type
="$mimetype"!;
5036 print qq
! alt
="$file_name" title
="$file_name"!;
5039 href(action=>"blob_plain
", hash=>$hash,
5040 hash_base=>$hash_base, file_name=>$file_name) .
5044 while (my $line = <$fd>) {
5047 $line = untabify
($line);
5048 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5049 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5053 or print "Reading blob failed.\n";
5059 if (!defined $hash_base) {
5060 $hash_base = "HEAD";
5062 if (!defined $hash) {
5063 if (defined $file_name) {
5064 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5069 die_error
(404, "No such tree") unless defined($hash);
5074 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5075 or die_error
(500, "Open git-ls-tree failed");
5076 @entries = map { chomp; $_ } <$fd>;
5078 or die_error
(404, "Reading tree failed");
5081 my $refs = git_get_references
();
5082 my $ref = format_ref_marker
($refs, $hash_base);
5085 my $have_blame = gitweb_check_feature
('blame');
5086 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5088 if (defined $file_name) {
5090 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5092 $cgi->a({-href
=> href
(action
=>"tree",
5093 hash_base
=>"HEAD", file_name
=>$file_name)},
5096 my $snapshot_links = format_snapshot_links
($hash);
5097 if (defined $snapshot_links) {
5098 # FIXME: Should be available when we have no hash base as well.
5099 push @views_nav, $snapshot_links;
5101 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5102 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5105 print "<div class=\"page_nav\">\n";
5106 print "<br/><br/></div>\n";
5107 print "<div class=\"title\">$hash</div>\n";
5109 if (defined $file_name) {
5110 $basedir = $file_name;
5111 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5114 git_print_page_path
($file_name, 'tree', $hash_base);
5116 print "<div class=\"page_body\">\n";
5117 print "<table class=\"tree\">\n";
5119 # '..' (top directory) link if possible
5120 if (defined $hash_base &&
5121 defined $file_name && $file_name =~ m![^/]+$!) {
5123 print "<tr class=\"dark\">\n";
5125 print "<tr class=\"light\">\n";
5129 my $up = $file_name;
5130 $up =~ s!/?[^/]+$!!;
5131 undef $up unless $up;
5132 # based on git_print_tree_entry
5133 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5134 print '<td class="list">';
5135 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5139 print "<td class=\"link\"></td>\n";
5143 foreach my $line (@entries) {
5144 my %t = parse_ls_tree_line
($line, -z
=> 1);
5147 print "<tr class=\"dark\">\n";
5149 print "<tr class=\"light\">\n";
5153 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5157 print "</table>\n" .
5163 my $format = $input_params{'snapshot_format'};
5164 if (!@snapshot_fmts) {
5165 die_error
(403, "Snapshots not allowed");
5167 # default to first supported snapshot format
5168 $format ||= $snapshot_fmts[0];
5169 if ($format !~ m/^[a-z0-9]+$/) {
5170 die_error
(400, "Invalid snapshot format parameter");
5171 } elsif (!exists($known_snapshot_formats{$format})) {
5172 die_error
(400, "Unknown snapshot format");
5173 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5174 die_error
(403, "Unsupported snapshot format");
5177 if (!defined $hash) {
5178 $hash = git_get_head_hash
($project);
5181 my $name = $project;
5182 $name =~ s
,([^/])/*\
.git
$,$1,;
5183 $name = basename
($name);
5184 my $filename = to_utf8
($name);
5185 $name =~ s/\047/\047\\\047\047/g;
5187 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5188 $cmd = quote_command
(
5189 git_cmd
(), 'archive',
5190 "--format=$known_snapshot_formats{$format}{'format'}",
5191 "--prefix=$name/", $hash);
5192 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5193 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5197 -type
=> $known_snapshot_formats{$format}{'type'},
5198 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5199 -status
=> '200 OK');
5201 open my $fd, "-|", $cmd
5202 or die_error
(500, "Execute git-archive failed");
5203 binmode STDOUT
, ':raw';
5205 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5210 my $head = git_get_head_hash
($project);
5211 if (!defined $hash) {
5214 if (!defined $page) {
5217 my $refs = git_get_references
();
5219 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5221 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5223 my ($patch_max) = gitweb_get_feature
('patches');
5225 if ($patch_max < 0 || @commitlist <= $patch_max) {
5226 $paging_nav .= " ⋅ " .
5227 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5233 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5236 my %co = parse_commit
($hash);
5238 git_print_header_div
('summary', $project);
5239 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5241 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5242 for (my $i = 0; $i <= $to; $i++) {
5243 my %co = %{$commitlist[$i]};
5245 my $commit = $co{'id'};
5246 my $ref = format_ref_marker
($refs, $commit);
5247 my %ad = parse_date
($co{'author_epoch'});
5248 git_print_header_div
('commit',
5249 "<span class=\"age\">$co{'age_string'}</span>" .
5250 esc_html
($co{'title'}) . $ref,
5252 print "<div class=\"title_text\">\n" .
5253 "<div class=\"log_link\">\n" .
5254 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5256 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5258 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5261 git_print_authorship
(\
%co, -tag
=> 'span');
5262 print "<br/>\n</div>\n";
5264 print "<div class=\"log_body\">\n";
5265 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5268 if ($#commitlist >= 100) {
5269 print "<div class=\"page_nav\">\n";
5270 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5271 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5278 $hash ||= $hash_base || "HEAD";
5279 my %co = parse_commit
($hash)
5280 or die_error
(404, "Unknown commit object");
5282 my $parent = $co{'parent'};
5283 my $parents = $co{'parents'}; # listref
5285 # we need to prepare $formats_nav before any parameter munging
5287 if (!defined $parent) {
5289 $formats_nav .= '(initial)';
5290 } elsif (@$parents == 1) {
5291 # single parent commit
5294 $cgi->a({-href
=> href
(action
=>"commit",
5296 esc_html
(substr($parent, 0, 7))) .
5303 $cgi->a({-href
=> href
(action
=>"commit",
5305 esc_html
(substr($_, 0, 7)));
5309 if (gitweb_check_feature
('patches')) {
5310 $formats_nav .= " | " .
5311 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5315 if (!defined $parent) {
5319 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5321 (@$parents <= 1 ? $parent : '-c'),
5323 or die_error
(500, "Open git-diff-tree failed");
5324 @difftree = map { chomp; $_ } <$fd>;
5325 close $fd or die_error
(404, "Reading git-diff-tree failed");
5327 # non-textual hash id's can be cached
5329 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5332 my $refs = git_get_references
();
5333 my $ref = format_ref_marker
($refs, $co{'id'});
5335 git_header_html
(undef, $expires);
5336 git_print_page_nav
('commit', '',
5337 $hash, $co{'tree'}, $hash,
5340 if (defined $co{'parent'}) {
5341 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5343 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5345 print "<div class=\"title_text\">\n" .
5346 "<table class=\"object_header\">\n";
5347 git_print_authorship_rows
(\
%co);
5348 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5351 "<td class=\"sha1\">" .
5352 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5353 class => "list"}, $co{'tree'}) .
5355 "<td class=\"link\">" .
5356 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5358 my $snapshot_links = format_snapshot_links
($hash);
5359 if (defined $snapshot_links) {
5360 print " | " . $snapshot_links;
5365 foreach my $par (@$parents) {
5368 "<td class=\"sha1\">" .
5369 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5370 class => "list"}, $par) .
5372 "<td class=\"link\">" .
5373 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5375 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5382 print "<div class=\"page_body\">\n";
5383 git_print_log
($co{'comment'});
5386 git_difftree_body
(\
@difftree, $hash, @$parents);
5392 # object is defined by:
5393 # - hash or hash_base alone
5394 # - hash_base and file_name
5397 # - hash or hash_base alone
5398 if ($hash || ($hash_base && !defined $file_name)) {
5399 my $object_id = $hash || $hash_base;
5401 open my $fd, "-|", quote_command
(
5402 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5403 or die_error
(404, "Object does not exist");
5407 or die_error
(404, "Object does not exist");
5409 # - hash_base and file_name
5410 } elsif ($hash_base && defined $file_name) {
5411 $file_name =~ s
,/+$,,;
5413 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5414 or die_error
(404, "Base object does not exist");
5416 # here errors should not hapen
5417 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5418 or die_error
(500, "Open git-ls-tree failed");
5422 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5423 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5424 die_error
(404, "File or directory for given base does not exist");
5429 die_error
(400, "Not enough information to find object");
5432 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5433 hash
=>$hash, hash_base
=>$hash_base,
5434 file_name
=>$file_name),
5435 -status
=> '302 Found');
5439 my $format = shift || 'html';
5446 # preparing $fd and %diffinfo for git_patchset_body
5448 if (defined $hash_base && defined $hash_parent_base) {
5449 if (defined $file_name) {
5451 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5452 $hash_parent_base, $hash_base,
5453 "--", (defined $file_parent ? $file_parent : ()), $file_name
5454 or die_error
(500, "Open git-diff-tree failed");
5455 @difftree = map { chomp; $_ } <$fd>;
5457 or die_error
(404, "Reading git-diff-tree failed");
5459 or die_error
(404, "Blob diff not found");
5461 } elsif (defined $hash &&
5462 $hash =~ /[0-9a-fA-F]{40}/) {
5463 # try to find filename from $hash
5465 # read filtered raw output
5466 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5467 $hash_parent_base, $hash_base, "--"
5468 or die_error
(500, "Open git-diff-tree failed");
5470 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5472 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5473 map { chomp; $_ } <$fd>;
5475 or die_error
(404, "Reading git-diff-tree failed");
5477 or die_error
(404, "Blob diff not found");
5480 die_error
(400, "Missing one of the blob diff parameters");
5483 if (@difftree > 1) {
5484 die_error
(400, "Ambiguous blob diff specification");
5487 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5488 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5489 $file_name ||= $diffinfo{'to_file'};
5491 $hash_parent ||= $diffinfo{'from_id'};
5492 $hash ||= $diffinfo{'to_id'};
5494 # non-textual hash id's can be cached
5495 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5496 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5501 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5502 '-p', ($format eq 'html' ? "--full-index" : ()),
5503 $hash_parent_base, $hash_base,
5504 "--", (defined $file_parent ? $file_parent : ()), $file_name
5505 or die_error
(500, "Open git-diff-tree failed");
5508 # old/legacy style URI -- not generated anymore since 1.4.3.
5510 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5514 if ($format eq 'html') {
5516 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5518 git_header_html
(undef, $expires);
5519 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5520 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5521 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5523 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5524 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5526 if (defined $file_name) {
5527 git_print_page_path
($file_name, "blob", $hash_base);
5529 print "<div class=\"page_path\"></div>\n";
5532 } elsif ($format eq 'plain') {
5534 -type
=> 'text/plain',
5535 -charset
=> 'utf-8',
5536 -expires
=> $expires,
5537 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5539 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5542 die_error
(400, "Unknown blobdiff format");
5546 if ($format eq 'html') {
5547 print "<div class=\"page_body\">\n";
5549 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5552 print "</div>\n"; # class="page_body"
5556 while (my $line = <$fd>) {
5557 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5558 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5562 last if $line =~ m!^\+\+\+!;
5570 sub git_blobdiff_plain
{
5571 git_blobdiff
('plain');
5574 sub git_commitdiff
{
5576 my $format = $params{-format
} || 'html';
5578 my ($patch_max) = gitweb_get_feature
('patches');
5579 if ($format eq 'patch') {
5580 die_error
(403, "Patch view not allowed") unless $patch_max;
5583 $hash ||= $hash_base || "HEAD";
5584 my %co = parse_commit
($hash)
5585 or die_error
(404, "Unknown commit object");
5587 # choose format for commitdiff for merge
5588 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5589 $hash_parent = '--cc';
5591 # we need to prepare $formats_nav before almost any parameter munging
5593 if ($format eq 'html') {
5595 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5598 $formats_nav .= " | " .
5599 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5603 if (defined $hash_parent &&
5604 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5605 # commitdiff with two commits given
5606 my $hash_parent_short = $hash_parent;
5607 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5608 $hash_parent_short = substr($hash_parent, 0, 7);
5612 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5613 if ($co{'parents'}[$i] eq $hash_parent) {
5614 $formats_nav .= ' parent ' . ($i+1);
5618 $formats_nav .= ': ' .
5619 $cgi->a({-href
=> href
(action
=>"commitdiff",
5620 hash
=>$hash_parent)},
5621 esc_html
($hash_parent_short)) .
5623 } elsif (!$co{'parent'}) {
5625 $formats_nav .= ' (initial)';
5626 } elsif (scalar @{$co{'parents'}} == 1) {
5627 # single parent commit
5630 $cgi->a({-href
=> href
(action
=>"commitdiff",
5631 hash
=>$co{'parent'})},
5632 esc_html
(substr($co{'parent'}, 0, 7))) .
5636 if ($hash_parent eq '--cc') {
5637 $formats_nav .= ' | ' .
5638 $cgi->a({-href
=> href
(action
=>"commitdiff",
5639 hash
=>$hash, hash_parent
=>'-c')},
5641 } else { # $hash_parent eq '-c'
5642 $formats_nav .= ' | ' .
5643 $cgi->a({-href
=> href
(action
=>"commitdiff",
5644 hash
=>$hash, hash_parent
=>'--cc')},
5650 $cgi->a({-href
=> href
(action
=>"commitdiff",
5652 esc_html
(substr($_, 0, 7)));
5653 } @{$co{'parents'}} ) .
5658 my $hash_parent_param = $hash_parent;
5659 if (!defined $hash_parent_param) {
5660 # --cc for multiple parents, --root for parentless
5661 $hash_parent_param =
5662 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5668 if ($format eq 'html') {
5669 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5670 "--no-commit-id", "--patch-with-raw", "--full-index",
5671 $hash_parent_param, $hash, "--"
5672 or die_error
(500, "Open git-diff-tree failed");
5674 while (my $line = <$fd>) {
5676 # empty line ends raw part of diff-tree output
5678 push @difftree, scalar parse_difftree_raw_line
($line);
5681 } elsif ($format eq 'plain') {
5682 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5683 '-p', $hash_parent_param, $hash, "--"
5684 or die_error
(500, "Open git-diff-tree failed");
5685 } elsif ($format eq 'patch') {
5686 # For commit ranges, we limit the output to the number of
5687 # patches specified in the 'patches' feature.
5688 # For single commits, we limit the output to a single patch,
5689 # diverging from the git-format-patch default.
5690 my @commit_spec = ();
5692 if ($patch_max > 0) {
5693 push @commit_spec, "-$patch_max";
5695 push @commit_spec, '-n', "$hash_parent..$hash";
5697 if ($params{-single
}) {
5698 push @commit_spec, '-1';
5700 if ($patch_max > 0) {
5701 push @commit_spec, "-$patch_max";
5703 push @commit_spec, "-n";
5705 push @commit_spec, '--root', $hash;
5707 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5708 '--stdout', @commit_spec
5709 or die_error
(500, "Open git-format-patch failed");
5711 die_error
(400, "Unknown commitdiff format");
5714 # non-textual hash id's can be cached
5716 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5720 # write commit message
5721 if ($format eq 'html') {
5722 my $refs = git_get_references
();
5723 my $ref = format_ref_marker
($refs, $co{'id'});
5725 git_header_html
(undef, $expires);
5726 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5727 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5728 print "<div class=\"title_text\">\n" .
5729 "<table class=\"object_header\">\n";
5730 git_print_authorship_rows
(\
%co);
5733 print "<div class=\"page_body\">\n";
5734 if (@{$co{'comment'}} > 1) {
5735 print "<div class=\"log\">\n";
5736 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5737 print "</div>\n"; # class="log"
5740 } elsif ($format eq 'plain') {
5741 my $refs = git_get_references
("tags");
5742 my $tagname = git_get_rev_name_tags
($hash);
5743 my $filename = basename
($project) . "-$hash.patch";
5746 -type
=> 'text/plain',
5747 -charset
=> 'utf-8',
5748 -expires
=> $expires,
5749 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5750 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5751 print "From: " . to_utf8
($co{'author'}) . "\n";
5752 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5753 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5755 print "X-Git-Tag: $tagname\n" if $tagname;
5756 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5758 foreach my $line (@{$co{'comment'}}) {
5759 print to_utf8
($line) . "\n";
5762 } elsif ($format eq 'patch') {
5763 my $filename = basename
($project) . "-$hash.patch";
5766 -type
=> 'text/plain',
5767 -charset
=> 'utf-8',
5768 -expires
=> $expires,
5769 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5773 if ($format eq 'html') {
5774 my $use_parents = !defined $hash_parent ||
5775 $hash_parent eq '-c' || $hash_parent eq '--cc';
5776 git_difftree_body
(\
@difftree, $hash,
5777 $use_parents ? @{$co{'parents'}} : $hash_parent);
5780 git_patchset_body
($fd, \
@difftree, $hash,
5781 $use_parents ? @{$co{'parents'}} : $hash_parent);
5783 print "</div>\n"; # class="page_body"
5786 } elsif ($format eq 'plain') {
5790 or print "Reading git-diff-tree failed\n";
5791 } elsif ($format eq 'patch') {
5795 or print "Reading git-format-patch failed\n";
5799 sub git_commitdiff_plain
{
5800 git_commitdiff
(-format
=> 'plain');
5803 # format-patch-style patches
5805 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5809 git_commitdiff
(-format
=> 'patch');
5813 if (!defined $hash_base) {
5814 $hash_base = git_get_head_hash
($project);
5816 if (!defined $page) {
5820 my %co = parse_commit
($hash_base)
5821 or die_error
(404, "Unknown commit object");
5823 my $refs = git_get_references
();
5824 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5826 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5827 $file_name, "--full-history")
5828 or die_error
(404, "No such file or directory on given branch");
5830 if (!defined $hash && defined $file_name) {
5831 # some commits could have deleted file in question,
5832 # and not have it in tree, but one of them has to have it
5833 for (my $i = 0; $i <= @commitlist; $i++) {
5834 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5835 last if defined $hash;
5838 if (defined $hash) {
5839 $ftype = git_get_type
($hash);
5841 if (!defined $ftype) {
5842 die_error
(500, "Unknown type of object");
5845 my $paging_nav = '';
5848 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5849 file_name
=>$file_name)},
5851 $paging_nav .= " ⋅ " .
5852 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5853 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5855 $paging_nav .= "first";
5856 $paging_nav .= " ⋅ prev";
5859 if ($#commitlist >= 100) {
5861 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5862 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5863 $paging_nav .= " ⋅ $next_link";
5865 $paging_nav .= " ⋅ next";
5869 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5870 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5871 git_print_page_path
($file_name, $ftype, $hash_base);
5873 git_history_body
(\
@commitlist, 0, 99,
5874 $refs, $hash_base, $ftype, $next_link);
5880 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5881 if (!defined $searchtext) {
5882 die_error
(400, "Text field is empty");
5884 if (!defined $hash) {
5885 $hash = git_get_head_hash
($project);
5887 my %co = parse_commit
($hash);
5889 die_error
(404, "Unknown commit object");
5891 if (!defined $page) {
5895 $searchtype ||= 'commit';
5896 if ($searchtype eq 'pickaxe') {
5897 # pickaxe may take all resources of your box and run for several minutes
5898 # with every query - so decide by yourself how public you make this feature
5899 gitweb_check_feature
('pickaxe')
5900 or die_error
(403, "Pickaxe is disabled");
5902 if ($searchtype eq 'grep') {
5903 gitweb_check_feature
('grep')[0]
5904 or die_error
(403, "Grep is disabled");
5909 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5911 if ($searchtype eq 'commit') {
5912 $greptype = "--grep=";
5913 } elsif ($searchtype eq 'author') {
5914 $greptype = "--author=";
5915 } elsif ($searchtype eq 'committer') {
5916 $greptype = "--committer=";
5918 $greptype .= $searchtext;
5919 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5920 $greptype, '--regexp-ignore-case',
5921 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5923 my $paging_nav = '';
5926 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5927 searchtext
=>$searchtext,
5928 searchtype
=>$searchtype)},
5930 $paging_nav .= " ⋅ " .
5931 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5932 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5934 $paging_nav .= "first";
5935 $paging_nav .= " ⋅ prev";
5938 if ($#commitlist >= 100) {
5940 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5941 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5942 $paging_nav .= " ⋅ $next_link";
5944 $paging_nav .= " ⋅ next";
5947 if ($#commitlist >= 100) {
5950 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5951 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5952 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5955 if ($searchtype eq 'pickaxe') {
5956 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5957 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5959 print "<table class=\"pickaxe search\">\n";
5962 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5963 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5964 ($search_use_regexp ? '--pickaxe-regex' : ());
5967 while (my $line = <$fd>) {
5971 my %set = parse_difftree_raw_line
($line);
5972 if (defined $set{'commit'}) {
5973 # finish previous commit
5976 "<td class=\"link\">" .
5977 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5979 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5985 print "<tr class=\"dark\">\n";
5987 print "<tr class=\"light\">\n";
5990 %co = parse_commit
($set{'commit'});
5991 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5992 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5993 "<td><i>$author</i></td>\n" .
5995 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5996 -class => "list subject"},
5997 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5998 } elsif (defined $set{'to_id'}) {
5999 next if ($set{'to_id'} =~ m/^0{40}$/);
6001 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6002 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6004 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6010 # finish last commit (warning: repetition!)
6013 "<td class=\"link\">" .
6014 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6016 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6024 if ($searchtype eq 'grep') {
6025 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6026 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6028 print "<table class=\"grep_search\">\n";
6032 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6033 $search_use_regexp ? ('-E', '-i') : '-F',
6034 $searchtext, $co{'tree'};
6036 while (my $line = <$fd>) {
6038 my ($file, $lno, $ltext, $binary);
6039 last if ($matches++ > 1000);
6040 if ($line =~ /^Binary file (.+) matches$/) {
6044 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6046 if ($file ne $lastfile) {
6047 $lastfile and print "</td></tr>\n";
6049 print "<tr class=\"dark\">\n";
6051 print "<tr class=\"light\">\n";
6053 print "<td class=\"list\">".
6054 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6055 file_name
=>"$file"),
6056 -class => "list"}, esc_path
($file));
6057 print "</td><td>\n";
6061 print "<div class=\"binary\">Binary file</div>\n";
6063 $ltext = untabify
($ltext);
6064 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6065 $ltext = esc_html
($1, -nbsp
=>1);
6066 $ltext .= '<span class="match">';
6067 $ltext .= esc_html
($2, -nbsp
=>1);
6068 $ltext .= '</span>';
6069 $ltext .= esc_html
($3, -nbsp
=>1);
6071 $ltext = esc_html
($ltext, -nbsp
=>1);
6073 print "<div class=\"pre\">" .
6074 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6075 file_name
=>"$file").'#l'.$lno,
6076 -class => "linenr"}, sprintf('%4i', $lno))
6077 . ' ' . $ltext . "</div>\n";
6081 print "</td></tr>\n";
6082 if ($matches > 1000) {
6083 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6086 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6095 sub git_search_help
{
6097 git_print_page_nav
('','', $hash,$hash,$hash);
6099 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6100 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6101 the pattern entered is recognized as the POSIX extended
6102 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6105 <dt><b>commit</b></dt>
6106 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6108 my $have_grep = gitweb_check_feature
('grep');
6111 <dt><b>grep</b></dt>
6112 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6113 a different one) are searched for the given pattern. On large trees, this search can take
6114 a while and put some strain on the server, so please use it with some consideration. Note that
6115 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6116 case-sensitive.</dd>
6120 <dt><b>author</b></dt>
6121 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6122 <dt><b>committer</b></dt>
6123 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6125 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6126 if ($have_pickaxe) {
6128 <dt><b>pickaxe</b></dt>
6129 <dd>All commits that caused the string to appear or disappear from any file (changes that
6130 added, removed or "modified" the string) will be listed. This search can take a while and
6131 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6132 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6140 my $head = git_get_head_hash
($project);
6141 if (!defined $hash) {
6144 if (!defined $page) {
6147 my $refs = git_get_references
();
6149 my $commit_hash = $hash;
6150 if (defined $hash_parent) {
6151 $commit_hash = "$hash_parent..$hash";
6153 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6155 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6157 if ($#commitlist >= 100) {
6159 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6160 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6162 my $patch_max = gitweb_check_feature
('patches');
6164 if ($patch_max < 0 || @commitlist <= $patch_max) {
6165 $paging_nav .= " ⋅ " .
6166 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6172 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6173 git_print_header_div
('summary', $project);
6175 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6180 ## ......................................................................
6181 ## feeds (RSS, Atom; OPML)
6184 my $format = shift || 'atom';
6185 my $have_blame = gitweb_check_feature
('blame');
6187 # Atom: http://www.atomenabled.org/developers/syndication/
6188 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6189 if ($format ne 'rss' && $format ne 'atom') {
6190 die_error
(400, "Unknown web feed format");
6193 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6194 my $head = $hash || 'HEAD';
6195 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6199 my $content_type = "application/$format+xml";
6200 if (defined $cgi->http('HTTP_ACCEPT') &&
6201 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6202 # browser (feed reader) prefers text/xml
6203 $content_type = 'text/xml';
6205 if (defined($commitlist[0])) {
6206 %latest_commit = %{$commitlist[0]};
6207 my $latest_epoch = $latest_commit{'committer_epoch'};
6208 %latest_date = parse_date
($latest_epoch);
6209 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6210 if (defined $if_modified) {
6212 if (eval { require HTTP
::Date
; 1; }) {
6213 $since = HTTP
::Date
::str2time
($if_modified);
6214 } elsif (eval { require Time
::ParseDate
; 1; }) {
6215 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6217 if (defined $since && $latest_epoch <= $since) {
6219 -type
=> $content_type,
6220 -charset
=> 'utf-8',
6221 -last_modified
=> $latest_date{'rfc2822'},
6222 -status
=> '304 Not Modified');
6227 -type
=> $content_type,
6228 -charset
=> 'utf-8',
6229 -last_modified
=> $latest_date{'rfc2822'});
6232 -type
=> $content_type,
6233 -charset
=> 'utf-8');
6236 # Optimization: skip generating the body if client asks only
6237 # for Last-Modified date.
6238 return if ($cgi->request_method() eq 'HEAD');
6241 my $title = "$site_name - $project/$action";
6242 my $feed_type = 'log';
6243 if (defined $hash) {
6244 $title .= " - '$hash'";
6245 $feed_type = 'branch log';
6246 if (defined $file_name) {
6247 $title .= " :: $file_name";
6248 $feed_type = 'history';
6250 } elsif (defined $file_name) {
6251 $title .= " - $file_name";
6252 $feed_type = 'history';
6254 $title .= " $feed_type";
6255 my $descr = git_get_project_description
($project);
6256 if (defined $descr) {
6257 $descr = esc_html
($descr);
6259 $descr = "$project " .
6260 ($format eq 'rss' ? 'RSS' : 'Atom') .
6263 my $owner = git_get_project_owner
($project);
6264 $owner = esc_html
($owner);
6268 if (defined $file_name) {
6269 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6270 } elsif (defined $hash) {
6271 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6273 $alt_url = href
(-full
=>1, action
=>"summary");
6275 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6276 if ($format eq 'rss') {
6278 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6281 print "<title>$title</title>\n" .
6282 "<link>$alt_url</link>\n" .
6283 "<description>$descr</description>\n" .
6284 "<language>en</language>\n" .
6285 # project owner is responsible for 'editorial' content
6286 "<managingEditor>$owner</managingEditor>\n";
6287 if (defined $logo || defined $favicon) {
6288 # prefer the logo to the favicon, since RSS
6289 # doesn't allow both
6290 my $img = esc_url
($logo || $favicon);
6292 "<url>$img</url>\n" .
6293 "<title>$title</title>\n" .
6294 "<link>$alt_url</link>\n" .
6298 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6299 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6301 print "<generator>gitweb v.$version/$git_version</generator>\n";
6302 } elsif ($format eq 'atom') {
6304 <feed xmlns="http://www.w3.org/2005/Atom">
6306 print "<title>$title</title>\n" .
6307 "<subtitle>$descr</subtitle>\n" .
6308 '<link rel="alternate" type="text/html" href="' .
6309 $alt_url . '" />' . "\n" .
6310 '<link rel="self" type="' . $content_type . '" href="' .
6311 $cgi->self_url() . '" />' . "\n" .
6312 "<id>" . href
(-full
=>1) . "</id>\n" .
6313 # use project owner for feed author
6314 "<author><name>$owner</name></author>\n";
6315 if (defined $favicon) {
6316 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6318 if (defined $logo_url) {
6319 # not twice as wide as tall: 72 x 27 pixels
6320 print "<logo>" . esc_url
($logo) . "</logo>\n";
6322 if (! %latest_date) {
6323 # dummy date to keep the feed valid until commits trickle in:
6324 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6326 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6328 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6332 for (my $i = 0; $i <= $#commitlist; $i++) {
6333 my %co = %{$commitlist[$i]};
6334 my $commit = $co{'id'};
6335 # we read 150, we always show 30 and the ones more recent than 48 hours
6336 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6339 my %cd = parse_date
($co{'author_epoch'});
6341 # get list of changed files
6342 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6343 $co{'parent'} || "--root",
6344 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6346 my @difftree = map { chomp; $_ } <$fd>;
6350 # print element (entry, item)
6351 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6352 if ($format eq 'rss') {
6354 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6355 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6356 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6357 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6358 "<link>$co_url</link>\n" .
6359 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6360 "<content:encoded>" .
6362 } elsif ($format eq 'atom') {
6364 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6365 "<updated>$cd{'iso-8601'}</updated>\n" .
6367 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6368 if ($co{'author_email'}) {
6369 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6371 print "</author>\n" .
6372 # use committer for contributor
6374 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6375 if ($co{'committer_email'}) {
6376 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6378 print "</contributor>\n" .
6379 "<published>$cd{'iso-8601'}</published>\n" .
6380 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6381 "<id>$co_url</id>\n" .
6382 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6383 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6385 my $comment = $co{'comment'};
6387 foreach my $line (@$comment) {
6388 $line = esc_html
($line);
6391 print "</pre><ul>\n";
6392 foreach my $difftree_line (@difftree) {
6393 my %difftree = parse_difftree_raw_line
($difftree_line);
6394 next if !$difftree{'from_id'};
6396 my $file = $difftree{'file'} || $difftree{'to_file'};
6400 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6401 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6402 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6403 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6404 -title
=> "diff"}, 'D');
6406 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6407 file_name
=>$file, hash_base
=>$commit),
6408 -title
=> "blame"}, 'B');
6410 # if this is not a feed of a file history
6411 if (!defined $file_name || $file_name ne $file) {
6412 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6413 file_name
=>$file, hash
=>$commit),
6414 -title
=> "history"}, 'H');
6416 $file = esc_path
($file);
6420 if ($format eq 'rss') {
6421 print "</ul>]]>\n" .
6422 "</content:encoded>\n" .
6424 } elsif ($format eq 'atom') {
6425 print "</ul>\n</div>\n" .
6432 if ($format eq 'rss') {
6433 print "</channel>\n</rss>\n";
6434 } elsif ($format eq 'atom') {
6448 my @list = git_get_projects_list
();
6451 -type
=> 'text/xml',
6452 -charset
=> 'utf-8',
6453 -content_disposition
=> 'inline; filename="opml.xml"');
6456 <?xml version="1.0" encoding="utf-8"?>
6457 <opml version="1.0">
6459 <title>$site_name OPML Export</title>
6462 <outline text="git RSS feeds">
6465 foreach my $pr (@list) {
6467 my $head = git_get_head_hash
($proj{'path'});
6468 if (!defined $head) {
6471 $git_dir = "$projectroot/$proj{'path'}";
6472 my %co = parse_commit
($head);
6477 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6478 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6479 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6480 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";