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 = "1.6.5.5";
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 = "/usr/bin/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "/home/mmay/projects/";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = 2007;
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 = "projects";
72 our $home_link_str = "packages";
74 # name of your site or organization to appear in page titles
75 # replace this with something more descriptive for clearer bookmarks
77 # || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 our $site_name = "ArchServer Project - Repositories - " . " Git";
80 # filename of html text to include at top of each page
81 #our $site_header = "";
82 our $site_header = "archserver-header.html";
83 # html text to include at home page
84 our $home_text = "indextext.html";
85 # filename of html text to include at bottom of each page
86 #our $site_footer = "";
87 our $site_footer = "archserver-footer.html";
90 our @stylesheets = ("gitweb.css");
91 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
92 our $stylesheet = undef;
93 # URI of GIT logo (72x27 size)
94 our $logo = "git-logo.png";
95 # URI of GIT favicon, assumed to be image/png type
96 #our $favicon = "git-favicon.png";
97 our $favicon = "archserver.ico";
99 # URI and label (title) of GIT logo link
100 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
101 #our $logo_label = "git documentation";
102 our $logo_url = "http://git-scm.com/";
103 our $logo_label = "git homepage";
105 # source of projects list
106 our $projects_list = "";
108 # the width (in characters) of the projects list "Description" column
109 our $projects_list_description_width = 25;
111 # default order of projects list
112 # valid values are none, project, descr, owner, and age
113 our $default_projects_order = "project";
115 # show repository only if this file exists
116 # (only effective if this variable evaluates to true)
119 # show repository only if this subroutine returns true
120 # when given the path to the project, for example:
121 # sub { return -e "$_[0]/git-daemon-export-ok"; }
122 our $export_auth_hook = undef;
124 # only allow viewing of repositories also shown on the overview page
125 our $strict_export = "";
127 # list of git base URLs used for URL to where fetch project from,
128 # i.e. full URL is "$git_base_url/$project"
129 our @git_base_url_list = grep { $_ ne '' } ("");
131 # default blob_plain mimetype and default charset for text/plain blob
132 our $default_blob_plain_mimetype = 'text/plain';
133 our $default_text_plain_charset = undef;
135 # file to use for guessing MIME types before trying /etc/mime.types
136 # (relative to the current git repository)
137 our $mimetypes_file = undef;
139 # assume this charset if line contains non-UTF-8 characters;
140 # it should be valid encoding (see Encoding::Supported(3pm) for list),
141 # for which encoding all byte sequences are valid, for example
142 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
143 # could be even 'utf-8' for the old behavior)
144 our $fallback_encoding = 'latin1';
146 # rename detection options for git-diff and git-diff-tree
147 # - default is '-M', with the cost proportional to
148 # (number of removed files) * (number of new files).
149 # - more costly is '-C' (which implies '-M'), with the cost proportional to
150 # (number of changed files + number of removed files) * (number of new files)
151 # - even more costly is '-C', '--find-copies-harder' with cost
152 # (number of files in the original tree) * (number of new files)
153 # - one might want to include '-B' option, e.g. '-B', '-M'
154 our @diff_opts = ('-M'); # taken from git_commit
156 # Disables features that would allow repository owners to inject script into
158 our $prevent_xss = 0;
160 # information about snapshot formats that gitweb is capable of serving
161 our %known_snapshot_formats = (
163 # 'display' => display name,
164 # 'type' => mime type,
165 # 'suffix' => filename suffix,
166 # 'format' => --format for git-archive,
167 # 'compressor' => [compressor command and arguments]
168 # (array reference, optional)
169 # 'disabled' => boolean (optional)}
172 'display' => 'tar.gz',
173 'type' => 'application/x-gzip',
174 'suffix' => '.tar.gz',
176 'compressor' => ['gzip']},
179 'display' => 'tar.bz2',
180 'type' => 'application/x-bzip2',
181 'suffix' => '.tar.bz2',
183 'compressor' => ['bzip2']},
186 'display' => 'tar.xz',
187 'type' => 'application/x-xz',
188 'suffix' => '.tar.xz',
190 'compressor' => ['xz'],
195 'type' => 'application/x-zip',
200 # Aliases so we understand old gitweb.snapshot values in repository
202 our %known_snapshot_format_aliases = (
207 # backward compatibility: legacy gitweb config support
208 'x-gzip' => undef, 'gz' => undef,
209 'x-bzip2' => undef, 'bz2' => undef,
210 'x-zip' => undef, '' => undef,
213 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
214 # are changed, it may be appropriate to change these values too via
221 # You define site-wide feature defaults here; override them with
222 # $GITWEB_CONFIG as necessary.
225 # 'sub' => feature-sub (subroutine),
226 # 'override' => allow-override (boolean),
227 # 'default' => [ default options...] (array reference)}
229 # if feature is overridable (it means that allow-override has true value),
230 # then feature-sub will be called with default options as parameters;
231 # return value of feature-sub indicates if to enable specified feature
233 # if there is no 'sub' key (no feature-sub), then feature cannot be
236 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
237 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
240 # Enable the 'blame' blob view, showing the last commit that modified
241 # each line in the file. This can be very CPU-intensive.
243 # To enable system wide have in $GITWEB_CONFIG
244 # $feature{'blame'}{'default'} = [1];
245 # To have project specific config enable override in $GITWEB_CONFIG
246 # $feature{'blame'}{'override'} = 1;
247 # and in project config gitweb.blame = 0|1;
249 'sub' => sub { feature_bool
('blame', @_) },
253 # Enable the 'snapshot' link, providing a compressed archive of any
254 # tree. This can potentially generate high traffic if you have large
257 # Value is a list of formats defined in %known_snapshot_formats that
259 # To disable system wide have in $GITWEB_CONFIG
260 # $feature{'snapshot'}{'default'} = [];
261 # To have project specific config enable override in $GITWEB_CONFIG
262 # $feature{'snapshot'}{'override'} = 1;
263 # and in project config, a comma-separated list of formats or "none"
264 # to disable. Example: gitweb.snapshot = tbz2,zip;
266 'sub' => \
&feature_snapshot
,
268 'default' => ['tgz']},
270 # Enable text search, which will list the commits which match author,
271 # committer or commit text to a given string. Enabled by default.
272 # Project specific override is not supported.
277 # Enable grep search, which will list the files in currently selected
278 # tree containing the given string. Enabled by default. This can be
279 # potentially CPU-intensive, of course.
281 # To enable system wide have in $GITWEB_CONFIG
282 # $feature{'grep'}{'default'} = [1];
283 # To have project specific config enable override in $GITWEB_CONFIG
284 # $feature{'grep'}{'override'} = 1;
285 # and in project config gitweb.grep = 0|1;
287 'sub' => sub { feature_bool
('grep', @_) },
291 # Enable the pickaxe search, which will list the commits that modified
292 # a given string in a file. This can be practical and quite faster
293 # alternative to 'blame', but still potentially CPU-intensive.
295 # To enable system wide have in $GITWEB_CONFIG
296 # $feature{'pickaxe'}{'default'} = [1];
297 # To have project specific config enable override in $GITWEB_CONFIG
298 # $feature{'pickaxe'}{'override'} = 1;
299 # and in project config gitweb.pickaxe = 0|1;
301 'sub' => sub { feature_bool
('pickaxe', @_) },
305 # Make gitweb use an alternative format of the URLs which can be
306 # more readable and natural-looking: project name is embedded
307 # directly in the path and the query string contains other
308 # auxiliary information. All gitweb installations recognize
309 # URL in either format; this configures in which formats gitweb
312 # To enable system wide have in $GITWEB_CONFIG
313 # $feature{'pathinfo'}{'default'} = [1];
314 # Project specific override is not supported.
316 # Note that you will need to change the default location of CSS,
317 # favicon, logo and possibly other files to an absolute URL. Also,
318 # if gitweb.cgi serves as your indexfile, you will need to force
319 # $my_uri to contain the script name in your $GITWEB_CONFIG.
324 # Make gitweb consider projects in project root subdirectories
325 # to be forks of existing projects. Given project $projname.git,
326 # projects matching $projname/*.git will not be shown in the main
327 # projects list, instead a '+' mark will be added to $projname
328 # there and a 'forks' view will be enabled for the project, listing
329 # all the forks. If project list is taken from a file, forks have
330 # to be listed after the main project.
332 # To enable system wide have in $GITWEB_CONFIG
333 # $feature{'forks'}{'default'} = [1];
334 # Project specific override is not supported.
339 # Insert custom links to the action bar of all project pages.
340 # This enables you mainly to link to third-party scripts integrating
341 # into gitweb; e.g. git-browser for graphical history representation
342 # or custom web-based repository administration interface.
344 # The 'default' value consists of a list of triplets in the form
345 # (label, link, position) where position is the label after which
346 # to insert the link and link is a format string where %n expands
347 # to the project name, %f to the project path within the filesystem,
348 # %h to the current hash (h gitweb parameter) and %b to the current
349 # hash base (hb gitweb parameter); %% expands to %.
351 # To enable system wide have in $GITWEB_CONFIG e.g.
352 # $feature{'actions'}{'default'} = [('graphiclog',
353 # '/git-browser/by-commit.html?r=%n', 'summary')];
354 # Project specific override is not supported.
359 # Allow gitweb scan project content tags described in ctags/
360 # of project repository, and display the popular Web 2.0-ish
361 # "tag cloud" near the project list. Note that this is something
362 # COMPLETELY different from the normal Git tags.
364 # gitweb by itself can show existing tags, but it does not handle
365 # tagging itself; you need an external application for that.
366 # For an example script, check Girocco's cgi/tagproj.cgi.
367 # You may want to install the HTML::TagCloud Perl module to get
368 # a pretty tag cloud instead of just a list of tags.
370 # To enable system wide have in $GITWEB_CONFIG
371 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
372 # Project specific override is not supported.
377 # The maximum number of patches in a patchset generated in patch
378 # view. Set this to 0 or undef to disable patch view, or to a
379 # negative number to remove any limit.
381 # To disable system wide have in $GITWEB_CONFIG
382 # $feature{'patches'}{'default'} = [0];
383 # To have project specific config enable override in $GITWEB_CONFIG
384 # $feature{'patches'}{'override'} = 1;
385 # and in project config gitweb.patches = 0|n;
386 # where n is the maximum number of patches allowed in a patchset.
388 'sub' => \
&feature_patches
,
392 # Avatar support. When this feature is enabled, views such as
393 # shortlog or commit will display an avatar associated with
394 # the email of the committer(s) and/or author(s).
396 # Currently available providers are gravatar and picon.
397 # If an unknown provider is specified, the feature is disabled.
399 # Gravatar depends on Digest::MD5.
400 # Picon currently relies on the indiana.edu database.
402 # To enable system wide have in $GITWEB_CONFIG
403 # $feature{'avatar'}{'default'} = ['<provider>'];
404 # where <provider> is either gravatar or picon.
405 # To have project specific config enable override in $GITWEB_CONFIG
406 # $feature{'avatar'}{'override'} = 1;
407 # and in project config gitweb.avatar = <provider>;
409 'sub' => \
&feature_avatar
,
414 sub gitweb_get_feature
{
416 return unless exists $feature{$name};
417 my ($sub, $override, @defaults) = (
418 $feature{$name}{'sub'},
419 $feature{$name}{'override'},
420 @
{$feature{$name}{'default'}});
421 if (!$override) { return @defaults; }
423 warn "feature $name is not overridable";
426 return $sub->(@defaults);
429 # A wrapper to check if a given feature is enabled.
430 # With this, you can say
432 # my $bool_feat = gitweb_check_feature('bool_feat');
433 # gitweb_check_feature('bool_feat') or somecode;
437 # my ($bool_feat) = gitweb_get_feature('bool_feat');
438 # (gitweb_get_feature('bool_feat'))[0] or somecode;
440 sub gitweb_check_feature
{
441 return (gitweb_get_feature
(@_))[0];
447 my ($val) = git_get_project_config
($key, '--bool');
451 } elsif ($val eq 'true') {
453 } elsif ($val eq 'false') {
458 sub feature_snapshot
{
461 my ($val) = git_get_project_config
('snapshot');
464 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
470 sub feature_patches
{
471 my @val = (git_get_project_config
('patches', '--int'));
481 my @val = (git_get_project_config
('avatar'));
483 return @val ?
@val : @_;
486 # checking HEAD file with -e is fragile if the repository was
487 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
489 sub check_head_link
{
491 my $headfile = "$dir/HEAD";
492 return ((-e
$headfile) ||
493 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
496 sub check_export_ok
{
498 return (check_head_link
($dir) &&
499 (!$export_ok || -e
"$dir/$export_ok") &&
500 (!$export_auth_hook || $export_auth_hook->($dir)));
503 # process alternate names for backward compatibility
504 # filter out unsupported (unknown) snapshot formats
505 sub filter_snapshot_fmts
{
509 exists $known_snapshot_format_aliases{$_} ?
510 $known_snapshot_format_aliases{$_} : $_} @fmts;
512 exists $known_snapshot_formats{$_} &&
513 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
516 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
517 if (-e
$GITWEB_CONFIG) {
520 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "/etc/gitweb.conf";
521 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
524 # version of the core git binary
525 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
527 $projects_list ||= $projectroot;
529 # ======================================================================
530 # input validation and dispatch
532 # input parameters can be collected from a variety of sources (presently, CGI
533 # and PATH_INFO), so we define an %input_params hash that collects them all
534 # together during validation: this allows subsequent uses (e.g. href()) to be
535 # agnostic of the parameter origin
537 our %input_params = ();
539 # input parameters are stored with the long parameter name as key. This will
540 # also be used in the href subroutine to convert parameters to their CGI
541 # equivalent, and since the href() usage is the most frequent one, we store
542 # the name -> CGI key mapping here, instead of the reverse.
544 # XXX: Warning: If you touch this, check the search form for updating,
547 our @cgi_param_mapping = (
555 hash_parent_base
=> "hpb",
560 snapshot_format
=> "sf",
561 extra_options
=> "opt",
562 search_use_regexp
=> "sr",
564 our %cgi_param_mapping = @cgi_param_mapping;
566 # we will also need to know the possible actions, for validation
568 "blame" => \
&git_blame
,
569 "blobdiff" => \
&git_blobdiff
,
570 "blobdiff_plain" => \
&git_blobdiff_plain
,
571 "blob" => \
&git_blob
,
572 "blob_plain" => \
&git_blob_plain
,
573 "commitdiff" => \
&git_commitdiff
,
574 "commitdiff_plain" => \
&git_commitdiff_plain
,
575 "commit" => \
&git_commit
,
576 "forks" => \
&git_forks
,
577 "heads" => \
&git_heads
,
578 "history" => \
&git_history
,
580 "patch" => \
&git_patch
,
581 "patches" => \
&git_patches
,
583 "atom" => \
&git_atom
,
584 "search" => \
&git_search
,
585 "search_help" => \
&git_search_help
,
586 "shortlog" => \
&git_shortlog
,
587 "summary" => \
&git_summary
,
589 "tags" => \
&git_tags
,
590 "tree" => \
&git_tree
,
591 "snapshot" => \
&git_snapshot
,
592 "object" => \
&git_object
,
593 # those below don't need $project
594 "opml" => \
&git_opml
,
595 "project_list" => \
&git_project_list
,
596 "project_index" => \
&git_project_index
,
599 # finally, we have the hash of allowed extra_options for the commands that
601 our %allowed_options = (
602 "--no-merges" => [ qw(rss atom log shortlog history) ],
605 # fill %input_params with the CGI parameters. All values except for 'opt'
606 # should be single values, but opt can be an array. We should probably
607 # build an array of parameters that can be multi-valued, but since for the time
608 # being it's only this one, we just single it out
609 while (my ($name, $symbol) = each %cgi_param_mapping) {
610 if ($symbol eq 'opt') {
611 $input_params{$name} = [ $cgi->param($symbol) ];
613 $input_params{$name} = $cgi->param($symbol);
617 # now read PATH_INFO and update the parameter list for missing parameters
618 sub evaluate_path_info
{
619 return if defined $input_params{'project'};
620 return if !$path_info;
621 $path_info =~ s
,^/+,,;
622 return if !$path_info;
624 # find which part of PATH_INFO is project
625 my $project = $path_info;
627 while ($project && !check_head_link
("$projectroot/$project")) {
628 $project =~ s
,/*[^/]*$,,;
630 return unless $project;
631 $input_params{'project'} = $project;
633 # do not change any parameters if an action is given using the query string
634 return if $input_params{'action'};
635 $path_info =~ s
,^\Q
$project\E
/*,,;
637 # next, check if we have an action
638 my $action = $path_info;
640 if (exists $actions{$action}) {
641 $path_info =~ s
,^$action/*,,;
642 $input_params{'action'} = $action;
645 # list of actions that want hash_base instead of hash, but can have no
646 # pathname (f) parameter
653 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
654 my ($parentrefname, $parentpathname, $refname, $pathname) =
655 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
657 # first, analyze the 'current' part
658 if (defined $pathname) {
659 # we got "branch:filename" or "branch:dir/"
660 # we could use git_get_type(branch:pathname), but:
661 # - it needs $git_dir
662 # - it does a git() call
663 # - the convention of terminating directories with a slash
664 # makes it superfluous
665 # - embedding the action in the PATH_INFO would make it even
667 $pathname =~ s
,^/+,,;
668 if (!$pathname || substr($pathname, -1) eq "/") {
669 $input_params{'action'} ||= "tree";
672 # the default action depends on whether we had parent info
674 if ($parentrefname) {
675 $input_params{'action'} ||= "blobdiff_plain";
677 $input_params{'action'} ||= "blob_plain";
680 $input_params{'hash_base'} ||= $refname;
681 $input_params{'file_name'} ||= $pathname;
682 } elsif (defined $refname) {
683 # we got "branch". In this case we have to choose if we have to
684 # set hash or hash_base.
686 # Most of the actions without a pathname only want hash to be
687 # set, except for the ones specified in @wants_base that want
688 # hash_base instead. It should also be noted that hand-crafted
689 # links having 'history' as an action and no pathname or hash
690 # set will fail, but that happens regardless of PATH_INFO.
691 $input_params{'action'} ||= "shortlog";
692 if (grep { $_ eq $input_params{'action'} } @wants_base) {
693 $input_params{'hash_base'} ||= $refname;
695 $input_params{'hash'} ||= $refname;
699 # next, handle the 'parent' part, if present
700 if (defined $parentrefname) {
701 # a missing pathspec defaults to the 'current' filename, allowing e.g.
702 # someproject/blobdiff/oldrev..newrev:/filename
703 if ($parentpathname) {
704 $parentpathname =~ s
,^/+,,;
705 $parentpathname =~ s
,/$,,;
706 $input_params{'file_parent'} ||= $parentpathname;
708 $input_params{'file_parent'} ||= $input_params{'file_name'};
710 # we assume that hash_parent_base is wanted if a path was specified,
711 # or if the action wants hash_base instead of hash
712 if (defined $input_params{'file_parent'} ||
713 grep { $_ eq $input_params{'action'} } @wants_base) {
714 $input_params{'hash_parent_base'} ||= $parentrefname;
716 $input_params{'hash_parent'} ||= $parentrefname;
720 # for the snapshot action, we allow URLs in the form
721 # $project/snapshot/$hash.ext
722 # where .ext determines the snapshot and gets removed from the
723 # passed $refname to provide the $hash.
725 # To be able to tell that $refname includes the format extension, we
726 # require the following two conditions to be satisfied:
727 # - the hash input parameter MUST have been set from the $refname part
728 # of the URL (i.e. they must be equal)
729 # - the snapshot format MUST NOT have been defined already (e.g. from
731 # It's also useless to try any matching unless $refname has a dot,
732 # so we check for that too
733 if (defined $input_params{'action'} &&
734 $input_params{'action'} eq 'snapshot' &&
735 defined $refname && index($refname, '.') != -1 &&
736 $refname eq $input_params{'hash'} &&
737 !defined $input_params{'snapshot_format'}) {
738 # We loop over the known snapshot formats, checking for
739 # extensions. Allowed extensions are both the defined suffix
740 # (which includes the initial dot already) and the snapshot
741 # format key itself, with a prepended dot
742 while (my ($fmt, $opt) = each %known_snapshot_formats) {
744 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
748 # a valid suffix was found, so set the snapshot format
749 # and reset the hash parameter
750 $input_params{'snapshot_format'} = $fmt;
751 $input_params{'hash'} = $hash;
752 # we also set the format suffix to the one requested
753 # in the URL: this way a request for e.g. .tgz returns
754 # a .tgz instead of a .tar.gz
755 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
760 evaluate_path_info
();
762 our $action = $input_params{'action'};
763 if (defined $action) {
764 if (!validate_action
($action)) {
765 die_error
(400, "Invalid action parameter");
769 # parameters which are pathnames
770 our $project = $input_params{'project'};
771 if (defined $project) {
772 if (!validate_project
($project)) {
774 die_error
(404, "No such project");
778 our $file_name = $input_params{'file_name'};
779 if (defined $file_name) {
780 if (!validate_pathname
($file_name)) {
781 die_error
(400, "Invalid file parameter");
785 our $file_parent = $input_params{'file_parent'};
786 if (defined $file_parent) {
787 if (!validate_pathname
($file_parent)) {
788 die_error
(400, "Invalid file parent parameter");
792 # parameters which are refnames
793 our $hash = $input_params{'hash'};
795 if (!validate_refname
($hash)) {
796 die_error
(400, "Invalid hash parameter");
800 our $hash_parent = $input_params{'hash_parent'};
801 if (defined $hash_parent) {
802 if (!validate_refname
($hash_parent)) {
803 die_error
(400, "Invalid hash parent parameter");
807 our $hash_base = $input_params{'hash_base'};
808 if (defined $hash_base) {
809 if (!validate_refname
($hash_base)) {
810 die_error
(400, "Invalid hash base parameter");
814 our @extra_options = @
{$input_params{'extra_options'}};
815 # @extra_options is always defined, since it can only be (currently) set from
816 # CGI, and $cgi->param() returns the empty array in array context if the param
818 foreach my $opt (@extra_options) {
819 if (not exists $allowed_options{$opt}) {
820 die_error
(400, "Invalid option parameter");
822 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
823 die_error
(400, "Invalid option parameter for this action");
827 our $hash_parent_base = $input_params{'hash_parent_base'};
828 if (defined $hash_parent_base) {
829 if (!validate_refname
($hash_parent_base)) {
830 die_error
(400, "Invalid hash parent base parameter");
835 our $page = $input_params{'page'};
837 if ($page =~ m/[^0-9]/) {
838 die_error
(400, "Invalid page parameter");
842 our $searchtype = $input_params{'searchtype'};
843 if (defined $searchtype) {
844 if ($searchtype =~ m/[^a-z]/) {
845 die_error
(400, "Invalid searchtype parameter");
849 our $search_use_regexp = $input_params{'search_use_regexp'};
851 our $searchtext = $input_params{'searchtext'};
853 if (defined $searchtext) {
854 if (length($searchtext) < 2) {
855 die_error
(403, "At least two characters are required for search parameter");
857 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
860 # path to the current git repository
862 $git_dir = "$projectroot/$project" if $project;
864 # list of supported snapshot formats
865 our @snapshot_fmts = gitweb_get_feature
('snapshot');
866 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
868 # check that the avatar feature is set to a known provider name,
869 # and for each provider check if the dependencies are satisfied.
870 # if the provider name is invalid or the dependencies are not met,
871 # reset $git_avatar to the empty string.
872 our ($git_avatar) = gitweb_get_feature
('avatar');
873 if ($git_avatar eq 'gravatar') {
874 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
875 } elsif ($git_avatar eq 'picon') {
882 if (!defined $action) {
884 $action = git_get_type
($hash);
885 } elsif (defined $hash_base && defined $file_name) {
886 $action = git_get_type
("$hash_base:$file_name");
887 } elsif (defined $project) {
890 $action = 'project_list';
893 if (!defined($actions{$action})) {
894 die_error
(400, "Unknown action");
896 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
898 die_error
(400, "Project needed");
900 $actions{$action}->();
903 ## ======================================================================
908 # default is to use -absolute url() i.e. $my_uri
909 my $href = $params{-full
} ?
$my_url : $my_uri;
911 $params{'project'} = $project unless exists $params{'project'};
913 if ($params{-replay
}) {
914 while (my ($name, $symbol) = each %cgi_param_mapping) {
915 if (!exists $params{$name}) {
916 $params{$name} = $input_params{$name};
921 my $use_pathinfo = gitweb_check_feature
('pathinfo');
922 if ($use_pathinfo and defined $params{'project'}) {
923 # try to put as many parameters as possible in PATH_INFO:
926 # - hash_parent or hash_parent_base:/file_parent
927 # - hash or hash_base:/filename
928 # - the snapshot_format as an appropriate suffix
930 # When the script is the root DirectoryIndex for the domain,
931 # $href here would be something like http://gitweb.example.com/
932 # Thus, we strip any trailing / from $href, to spare us double
933 # slashes in the final URL
936 # Then add the project name, if present
937 $href .= "/".esc_url
($params{'project'});
938 delete $params{'project'};
940 # since we destructively absorb parameters, we keep this
941 # boolean that remembers if we're handling a snapshot
942 my $is_snapshot = $params{'action'} eq 'snapshot';
944 # Summary just uses the project path URL, any other action is
946 if (defined $params{'action'}) {
947 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
948 delete $params{'action'};
951 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
952 # stripping nonexistent or useless pieces
953 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
954 || $params{'hash_parent'} || $params{'hash'});
955 if (defined $params{'hash_base'}) {
956 if (defined $params{'hash_parent_base'}) {
957 $href .= esc_url
($params{'hash_parent_base'});
958 # skip the file_parent if it's the same as the file_name
959 if (defined $params{'file_parent'}) {
960 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
961 delete $params{'file_parent'};
962 } elsif ($params{'file_parent'} !~ /\.\./) {
963 $href .= ":/".esc_url
($params{'file_parent'});
964 delete $params{'file_parent'};
968 delete $params{'hash_parent'};
969 delete $params{'hash_parent_base'};
970 } elsif (defined $params{'hash_parent'}) {
971 $href .= esc_url
($params{'hash_parent'}). "..";
972 delete $params{'hash_parent'};
975 $href .= esc_url
($params{'hash_base'});
976 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
977 $href .= ":/".esc_url
($params{'file_name'});
978 delete $params{'file_name'};
980 delete $params{'hash'};
981 delete $params{'hash_base'};
982 } elsif (defined $params{'hash'}) {
983 $href .= esc_url
($params{'hash'});
984 delete $params{'hash'};
987 # If the action was a snapshot, we can absorb the
988 # snapshot_format parameter too
990 my $fmt = $params{'snapshot_format'};
991 # snapshot_format should always be defined when href()
992 # is called, but just in case some code forgets, we
993 # fall back to the default
994 $fmt ||= $snapshot_fmts[0];
995 $href .= $known_snapshot_formats{$fmt}{'suffix'};
996 delete $params{'snapshot_format'};
1000 # now encode the parameters explicitly
1002 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1003 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1004 if (defined $params{$name}) {
1005 if (ref($params{$name}) eq "ARRAY") {
1006 foreach my $par (@
{$params{$name}}) {
1007 push @result, $symbol . "=" . esc_param
($par);
1010 push @result, $symbol . "=" . esc_param
($params{$name});
1014 $href .= "?" . join(';', @result) if scalar @result;
1020 ## ======================================================================
1021 ## validation, quoting/unquoting and escaping
1023 sub validate_action
{
1024 my $input = shift || return undef;
1025 return undef unless exists $actions{$input};
1029 sub validate_project
{
1030 my $input = shift || return undef;
1031 if (!validate_pathname
($input) ||
1032 !(-d
"$projectroot/$input") ||
1033 !check_export_ok
("$projectroot/$input") ||
1034 ($strict_export && !project_in_list
($input))) {
1041 sub validate_pathname
{
1042 my $input = shift || return undef;
1044 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1045 # at the beginning, at the end, and between slashes.
1046 # also this catches doubled slashes
1047 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1050 # no null characters
1051 if ($input =~ m!\0!) {
1057 sub validate_refname
{
1058 my $input = shift || return undef;
1060 # textual hashes are O.K.
1061 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1064 # it must be correct pathname
1065 $input = validate_pathname
($input)
1067 # restrictions on ref name according to git-check-ref-format
1068 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1074 # decode sequences of octets in utf8 into Perl's internal form,
1075 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1076 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1079 if (utf8
::valid
($str)) {
1083 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1087 # quote unsafe chars, but keep the slash, even when it's not
1088 # correct, but quoted slashes look too horrible in bookmarks
1091 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1096 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1099 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1105 # replace invalid utf8 character with SUBSTITUTION sequence
1110 $str = to_utf8
($str);
1111 $str = $cgi->escapeHTML($str);
1112 if ($opts{'-nbsp'}) {
1113 $str =~ s/ / /g;
1115 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1119 # quote control characters and escape filename to HTML
1124 $str = to_utf8
($str);
1125 $str = $cgi->escapeHTML($str);
1126 if ($opts{'-nbsp'}) {
1127 $str =~ s/ / /g;
1129 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1133 # Make control characters "printable", using character escape codes (CEC)
1137 my %es = ( # character escape codes, aka escape sequences
1138 "\t" => '\t', # tab (HT)
1139 "\n" => '\n', # line feed (LF)
1140 "\r" => '\r', # carrige return (CR)
1141 "\f" => '\f', # form feed (FF)
1142 "\b" => '\b', # backspace (BS)
1143 "\a" => '\a', # alarm (bell) (BEL)
1144 "\e" => '\e', # escape (ESC)
1145 "\013" => '\v', # vertical tab (VT)
1146 "\000" => '\0', # nul character (NUL)
1148 my $chr = ( (exists $es{$cntrl})
1150 : sprintf('\%2x', ord($cntrl)) );
1151 if ($opts{-nohtml
}) {
1154 return "<span class=\"cntrl\">$chr</span>";
1158 # Alternatively use unicode control pictures codepoints,
1159 # Unicode "printable representation" (PR)
1164 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1165 if ($opts{-nohtml
}) {
1168 return "<span class=\"cntrl\">$chr</span>";
1172 # git may return quoted and escaped filenames
1178 my %es = ( # character escape codes, aka escape sequences
1179 't' => "\t", # tab (HT, TAB)
1180 'n' => "\n", # newline (NL)
1181 'r' => "\r", # return (CR)
1182 'f' => "\f", # form feed (FF)
1183 'b' => "\b", # backspace (BS)
1184 'a' => "\a", # alarm (bell) (BEL)
1185 'e' => "\e", # escape (ESC)
1186 'v' => "\013", # vertical tab (VT)
1189 if ($seq =~ m/^[0-7]{1,3}$/) {
1190 # octal char sequence
1191 return chr(oct($seq));
1192 } elsif (exists $es{$seq}) {
1193 # C escape sequence, aka character escape code
1196 # quoted ordinary character
1200 if ($str =~ m/^"(.*)"$/) {
1203 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1208 # escape tabs (convert tabs to spaces)
1212 while ((my $pos = index($line, "\t")) != -1) {
1213 if (my $count = (8 - ($pos % 8))) {
1214 my $spaces = ' ' x
$count;
1215 $line =~ s/\t/$spaces/;
1222 sub project_in_list
{
1223 my $project = shift;
1224 my @list = git_get_projects_list
();
1225 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1228 ## ----------------------------------------------------------------------
1229 ## HTML aware string manipulation
1231 # Try to chop given string on a word boundary between position
1232 # $len and $len+$add_len. If there is no word boundary there,
1233 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1234 # (marking chopped part) would be longer than given string.
1238 my $add_len = shift || 10;
1239 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1241 # Make sure perl knows it is utf8 encoded so we don't
1242 # cut in the middle of a utf8 multibyte char.
1243 $str = to_utf8
($str);
1245 # allow only $len chars, but don't cut a word if it would fit in $add_len
1246 # if it doesn't fit, cut it if it's still longer than the dots we would add
1247 # remove chopped character entities entirely
1249 # when chopping in the middle, distribute $len into left and right part
1250 # return early if chopping wouldn't make string shorter
1251 if ($where eq 'center') {
1252 return $str if ($len + 5 >= length($str)); # filler is length 5
1255 return $str if ($len + 4 >= length($str)); # filler is length 4
1258 # regexps: ending and beginning with word part up to $add_len
1259 my $endre = qr/.{$len}\w{0,$add_len}/;
1260 my $begre = qr/\w{0,$add_len}.{$len}/;
1262 if ($where eq 'left') {
1263 $str =~ m/^(.*?)($begre)$/;
1264 my ($lead, $body) = ($1, $2);
1265 if (length($lead) > 4) {
1266 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1269 return "$lead$body";
1271 } elsif ($where eq 'center') {
1272 $str =~ m/^($endre)(.*)$/;
1273 my ($left, $str) = ($1, $2);
1274 $str =~ m/^(.*?)($begre)$/;
1275 my ($mid, $right) = ($1, $2);
1276 if (length($mid) > 5) {
1277 $left =~ s/&[^;]*$//;
1278 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1281 return "$left$mid$right";
1284 $str =~ m/^($endre)(.*)$/;
1287 if (length($tail) > 4) {
1288 $body =~ s/&[^;]*$//;
1291 return "$body$tail";
1295 # takes the same arguments as chop_str, but also wraps a <span> around the
1296 # result with a title attribute if it does get chopped. Additionally, the
1297 # string is HTML-escaped.
1298 sub chop_and_escape_str
{
1301 my $chopped = chop_str
(@_);
1302 if ($chopped eq $str) {
1303 return esc_html
($chopped);
1305 $str =~ s/[[:cntrl:]]/?/g;
1306 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1310 ## ----------------------------------------------------------------------
1311 ## functions returning short strings
1313 # CSS class for given age value (in seconds)
1317 if (!defined $age) {
1319 } elsif ($age < 60*60*2) {
1321 } elsif ($age < 60*60*24*2) {
1328 # convert age in seconds to "nn units ago" string
1333 if ($age > 60*60*24*365*2) {
1334 $age_str = (int $age/60/60/24/365);
1335 $age_str .= " years ago";
1336 } elsif ($age > 60*60*24*(365/12)*2) {
1337 $age_str = int $age/60/60/24/(365/12);
1338 $age_str .= " months ago";
1339 } elsif ($age > 60*60*24*7*2) {
1340 $age_str = int $age/60/60/24/7;
1341 $age_str .= " weeks ago";
1342 } elsif ($age > 60*60*24*2) {
1343 $age_str = int $age/60/60/24;
1344 $age_str .= " days ago";
1345 } elsif ($age > 60*60*2) {
1346 $age_str = int $age/60/60;
1347 $age_str .= " hours ago";
1348 } elsif ($age > 60*2) {
1349 $age_str = int $age/60;
1350 $age_str .= " min ago";
1351 } elsif ($age > 2) {
1352 $age_str = int $age;
1353 $age_str .= " sec ago";
1355 $age_str .= " right now";
1361 S_IFINVALID
=> 0030000,
1362 S_IFGITLINK
=> 0160000,
1365 # submodule/subproject, a commit object reference
1369 return (($mode & S_IFMT
) == S_IFGITLINK
)
1372 # convert file mode in octal to symbolic file mode string
1374 my $mode = oct shift;
1376 if (S_ISGITLINK
($mode)) {
1377 return 'm---------';
1378 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1379 return 'drwxr-xr-x';
1380 } elsif (S_ISLNK
($mode)) {
1381 return 'lrwxrwxrwx';
1382 } elsif (S_ISREG
($mode)) {
1383 # git cares only about the executable bit
1384 if ($mode & S_IXUSR
) {
1385 return '-rwxr-xr-x';
1387 return '-rw-r--r--';
1390 return '----------';
1394 # convert file mode in octal to file type string
1398 if ($mode !~ m/^[0-7]+$/) {
1404 if (S_ISGITLINK
($mode)) {
1406 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1408 } elsif (S_ISLNK
($mode)) {
1410 } elsif (S_ISREG
($mode)) {
1417 # convert file mode in octal to file type description string
1418 sub file_type_long
{
1421 if ($mode !~ m/^[0-7]+$/) {
1427 if (S_ISGITLINK
($mode)) {
1429 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1431 } elsif (S_ISLNK
($mode)) {
1433 } elsif (S_ISREG
($mode)) {
1434 if ($mode & S_IXUSR
) {
1435 return "executable";
1445 ## ----------------------------------------------------------------------
1446 ## functions returning short HTML fragments, or transforming HTML fragments
1447 ## which don't belong to other sections
1449 # format line of commit message.
1450 sub format_log_line_html
{
1453 $line = esc_html
($line, -nbsp
=>1);
1454 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1455 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1456 -class => "text"}, $1);
1462 # format marker of refs pointing to given object
1464 # the destination action is chosen based on object type and current context:
1465 # - for annotated tags, we choose the tag view unless it's the current view
1466 # already, in which case we go to shortlog view
1467 # - for other refs, we keep the current view if we're in history, shortlog or
1468 # log view, and select shortlog otherwise
1469 sub format_ref_marker
{
1470 my ($refs, $id) = @_;
1473 if (defined $refs->{$id}) {
1474 foreach my $ref (@
{$refs->{$id}}) {
1475 # this code exploits the fact that non-lightweight tags are the
1476 # only indirect objects, and that they are the only objects for which
1477 # we want to use tag instead of shortlog as action
1478 my ($type, $name) = qw();
1479 my $indirect = ($ref =~ s/\^\{\}$//);
1480 # e.g. tags/v2.6.11 or heads/next
1481 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1490 $class .= " indirect" if $indirect;
1492 my $dest_action = "shortlog";
1495 $dest_action = "tag" unless $action eq "tag";
1496 } elsif ($action =~ /^(history|(short)?log)$/) {
1497 $dest_action = $action;
1501 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1504 my $link = $cgi->a({
1506 action
=>$dest_action,
1510 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1516 return ' <span class="refs">'. $markers . '</span>';
1522 # format, perhaps shortened and with markers, title line
1523 sub format_subject_html
{
1524 my ($long, $short, $href, $extra) = @_;
1525 $extra = '' unless defined($extra);
1527 if (length($short) < length($long)) {
1528 $long =~ s/[[:cntrl:]]/?/g;
1529 return $cgi->a({-href
=> $href, -class => "list subject",
1530 -title
=> to_utf8
($long)},
1531 esc_html
($short)) . $extra;
1533 return $cgi->a({-href
=> $href, -class => "list subject"},
1534 esc_html
($long)) . $extra;
1538 # Rather than recomputing the url for an email multiple times, we cache it
1539 # after the first hit. This gives a visible benefit in views where the avatar
1540 # for the same email is used repeatedly (e.g. shortlog).
1541 # The cache is shared by all avatar engines (currently gravatar only), which
1542 # are free to use it as preferred. Since only one avatar engine is used for any
1543 # given page, there's no risk for cache conflicts.
1544 our %avatar_cache = ();
1546 # Compute the picon url for a given email, by using the picon search service over at
1547 # http://www.cs.indiana.edu/picons/search.html
1549 my $email = lc shift;
1550 if (!$avatar_cache{$email}) {
1551 my ($user, $domain) = split('@', $email);
1552 $avatar_cache{$email} =
1553 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1555 "users+domains+unknown/up/single";
1557 return $avatar_cache{$email};
1560 # Compute the gravatar url for a given email, if it's not in the cache already.
1561 # Gravatar stores only the part of the URL before the size, since that's the
1562 # one computationally more expensive. This also allows reuse of the cache for
1563 # different sizes (for this particular engine).
1565 my $email = lc shift;
1567 $avatar_cache{$email} ||=
1568 "http://www.gravatar.com/avatar/" .
1569 Digest
::MD5
::md5_hex
($email) . "?s=";
1570 return $avatar_cache{$email} . $size;
1573 # Insert an avatar for the given $email at the given $size if the feature
1575 sub git_get_avatar
{
1576 my ($email, %opts) = @_;
1577 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1578 my $post_white = ($opts{-pad_after
} ?
" " : "");
1579 $opts{-size
} ||= 'default';
1580 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1582 if ($git_avatar eq 'gravatar') {
1583 $url = gravatar_url
($email, $size);
1584 } elsif ($git_avatar eq 'picon') {
1585 $url = picon_url
($email);
1587 # Other providers can be added by extending the if chain, defining $url
1588 # as needed. If no variant puts something in $url, we assume avatars
1589 # are completely disabled/unavailable.
1592 "<img width=\"$size\" " .
1593 "class=\"avatar\" " .
1602 # format the author name of the given commit with the given tag
1603 # the author name is chopped and escaped according to the other
1604 # optional parameters (see chop_str).
1605 sub format_author_html
{
1608 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1609 return "<$tag class=\"author\">" .
1610 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1611 $author . "</$tag>";
1614 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1615 sub format_git_diff_header_line
{
1617 my $diffinfo = shift;
1618 my ($from, $to) = @_;
1620 if ($diffinfo->{'nparents'}) {
1622 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1623 if ($to->{'href'}) {
1624 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1625 esc_path
($to->{'file'}));
1626 } else { # file was deleted (no href)
1627 $line .= esc_path
($to->{'file'});
1631 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1632 if ($from->{'href'}) {
1633 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1634 'a/' . esc_path
($from->{'file'}));
1635 } else { # file was added (no href)
1636 $line .= 'a/' . esc_path
($from->{'file'});
1639 if ($to->{'href'}) {
1640 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1641 'b/' . esc_path
($to->{'file'}));
1642 } else { # file was deleted
1643 $line .= 'b/' . esc_path
($to->{'file'});
1647 return "<div class=\"diff header\">$line</div>\n";
1650 # format extended diff header line, before patch itself
1651 sub format_extended_diff_header_line
{
1653 my $diffinfo = shift;
1654 my ($from, $to) = @_;
1657 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1658 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1659 esc_path
($from->{'file'}));
1661 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1662 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1663 esc_path
($to->{'file'}));
1665 # match single <mode>
1666 if ($line =~ m/\s(\d{6})$/) {
1667 $line .= '<span class="info"> (' .
1668 file_type_long
($1) .
1672 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1673 # can match only for combined diff
1675 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1676 if ($from->{'href'}[$i]) {
1677 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1679 substr($diffinfo->{'from_id'}[$i],0,7));
1684 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1687 if ($to->{'href'}) {
1688 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1689 substr($diffinfo->{'to_id'},0,7));
1694 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1695 # can match only for ordinary diff
1696 my ($from_link, $to_link);
1697 if ($from->{'href'}) {
1698 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1699 substr($diffinfo->{'from_id'},0,7));
1701 $from_link = '0' x
7;
1703 if ($to->{'href'}) {
1704 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1705 substr($diffinfo->{'to_id'},0,7));
1709 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1710 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1713 return $line . "<br/>\n";
1716 # format from-file/to-file diff header
1717 sub format_diff_from_to_header
{
1718 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1723 #assert($line =~ m/^---/) if DEBUG;
1724 # no extra formatting for "^--- /dev/null"
1725 if (! $diffinfo->{'nparents'}) {
1726 # ordinary (single parent) diff
1727 if ($line =~ m!^--- "?a/!) {
1728 if ($from->{'href'}) {
1730 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1731 esc_path
($from->{'file'}));
1734 esc_path
($from->{'file'});
1737 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1740 # combined diff (merge commit)
1741 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1742 if ($from->{'href'}[$i]) {
1744 $cgi->a({-href
=>href
(action
=>"blobdiff",
1745 hash_parent
=>$diffinfo->{'from_id'}[$i],
1746 hash_parent_base
=>$parents[$i],
1747 file_parent
=>$from->{'file'}[$i],
1748 hash
=>$diffinfo->{'to_id'},
1750 file_name
=>$to->{'file'}),
1752 -title
=>"diff" . ($i+1)},
1755 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1756 esc_path
($from->{'file'}[$i]));
1758 $line = '--- /dev/null';
1760 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1765 #assert($line =~ m/^\+\+\+/) if DEBUG;
1766 # no extra formatting for "^+++ /dev/null"
1767 if ($line =~ m!^\+\+\+ "?b/!) {
1768 if ($to->{'href'}) {
1770 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1771 esc_path
($to->{'file'}));
1774 esc_path
($to->{'file'});
1777 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1782 # create note for patch simplified by combined diff
1783 sub format_diff_cc_simplified
{
1784 my ($diffinfo, @parents) = @_;
1787 $result .= "<div class=\"diff header\">" .
1789 if (!is_deleted
($diffinfo)) {
1790 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1792 hash
=>$diffinfo->{'to_id'},
1793 file_name
=>$diffinfo->{'to_file'}),
1795 esc_path
($diffinfo->{'to_file'}));
1797 $result .= esc_path
($diffinfo->{'to_file'});
1799 $result .= "</div>\n" . # class="diff header"
1800 "<div class=\"diff nodifferences\">" .
1802 "</div>\n"; # class="diff nodifferences"
1807 # format patch (diff) line (not to be used for diff headers)
1808 sub format_diff_line
{
1810 my ($from, $to) = @_;
1811 my $diff_class = "";
1815 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1817 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1818 if ($line =~ m/^\@{3}/) {
1819 $diff_class = " chunk_header";
1820 } elsif ($line =~ m/^\\/) {
1821 $diff_class = " incomplete";
1822 } elsif ($prefix =~ tr/+/+/) {
1823 $diff_class = " add";
1824 } elsif ($prefix =~ tr/-/-/) {
1825 $diff_class = " rem";
1828 # assume ordinary diff
1829 my $char = substr($line, 0, 1);
1831 $diff_class = " add";
1832 } elsif ($char eq '-') {
1833 $diff_class = " rem";
1834 } elsif ($char eq '@') {
1835 $diff_class = " chunk_header";
1836 } elsif ($char eq "\\") {
1837 $diff_class = " incomplete";
1840 $line = untabify
($line);
1841 if ($from && $to && $line =~ m/^\@{2} /) {
1842 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1843 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1845 $from_lines = 0 unless defined $from_lines;
1846 $to_lines = 0 unless defined $to_lines;
1848 if ($from->{'href'}) {
1849 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1850 -class=>"list"}, $from_text);
1852 if ($to->{'href'}) {
1853 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1854 -class=>"list"}, $to_text);
1856 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1857 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1858 return "<div class=\"diff$diff_class\">$line</div>\n";
1859 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1860 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1861 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1863 @from_text = split(' ', $ranges);
1864 for (my $i = 0; $i < @from_text; ++$i) {
1865 ($from_start[$i], $from_nlines[$i]) =
1866 (split(',', substr($from_text[$i], 1)), 0);
1869 $to_text = pop @from_text;
1870 $to_start = pop @from_start;
1871 $to_nlines = pop @from_nlines;
1873 $line = "<span class=\"chunk_info\">$prefix ";
1874 for (my $i = 0; $i < @from_text; ++$i) {
1875 if ($from->{'href'}[$i]) {
1876 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1877 -class=>"list"}, $from_text[$i]);
1879 $line .= $from_text[$i];
1883 if ($to->{'href'}) {
1884 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1885 -class=>"list"}, $to_text);
1889 $line .= " $prefix</span>" .
1890 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1891 return "<div class=\"diff$diff_class\">$line</div>\n";
1893 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1896 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1897 # linked. Pass the hash of the tree/commit to snapshot.
1898 sub format_snapshot_links
{
1900 my $num_fmts = @snapshot_fmts;
1901 if ($num_fmts > 1) {
1902 # A parenthesized list of links bearing format names.
1903 # e.g. "snapshot (_tar.gz_ _zip_)"
1904 return "snapshot (" . join(' ', map
1911 }, $known_snapshot_formats{$_}{'display'})
1912 , @snapshot_fmts) . ")";
1913 } elsif ($num_fmts == 1) {
1914 # A single "snapshot" link whose tooltip bears the format name.
1916 my ($fmt) = @snapshot_fmts;
1922 snapshot_format
=>$fmt
1924 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1926 } else { # $num_fmts == 0
1931 ## ......................................................................
1932 ## functions returning values to be passed, perhaps after some
1933 ## transformation, to other functions; e.g. returning arguments to href()
1935 # returns hash to be passed to href to generate gitweb URL
1936 # in -title key it returns description of link
1938 my $format = shift || 'Atom';
1939 my %res = (action
=> lc($format));
1941 # feed links are possible only for project views
1942 return unless (defined $project);
1943 # some views should link to OPML, or to generic project feed,
1944 # or don't have specific feed yet (so they should use generic)
1945 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1948 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1949 # from tag links; this also makes possible to detect branch links
1950 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1951 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1954 # find log type for feed description (title)
1956 if (defined $file_name) {
1957 $type = "history of $file_name";
1958 $type .= "/" if ($action eq 'tree');
1959 $type .= " on '$branch'" if (defined $branch);
1961 $type = "log of $branch" if (defined $branch);
1964 $res{-title
} = $type;
1965 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1966 $res{'file_name'} = $file_name;
1971 ## ----------------------------------------------------------------------
1972 ## git utility subroutines, invoking git commands
1974 # returns path to the core git executable and the --git-dir parameter as list
1976 return $GIT, '--git-dir='.$git_dir;
1979 # quote the given arguments for passing them to the shell
1980 # quote_command("command", "arg 1", "arg with ' and ! characters")
1981 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1982 # Try to avoid using this function wherever possible.
1985 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1988 # get HEAD ref of given project as hash
1989 sub git_get_head_hash
{
1990 my $project = shift;
1991 my $o_git_dir = $git_dir;
1993 $git_dir = "$projectroot/$project";
1994 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1997 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
2001 if (defined $o_git_dir) {
2002 $git_dir = $o_git_dir;
2007 # get type of given object
2011 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2013 close $fd or return;
2018 # repository configuration
2019 our $config_file = '';
2022 # store multiple values for single key as anonymous array reference
2023 # single values stored directly in the hash, not as [ <value> ]
2024 sub hash_set_multi
{
2025 my ($hash, $key, $value) = @_;
2027 if (!exists $hash->{$key}) {
2028 $hash->{$key} = $value;
2029 } elsif (!ref $hash->{$key}) {
2030 $hash->{$key} = [ $hash->{$key}, $value ];
2032 push @
{$hash->{$key}}, $value;
2036 # return hash of git project configuration
2037 # optionally limited to some section, e.g. 'gitweb'
2038 sub git_parse_project_config
{
2039 my $section_regexp = shift;
2044 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2047 while (my $keyval = <$fh>) {
2049 my ($key, $value) = split(/\n/, $keyval, 2);
2051 hash_set_multi
(\
%config, $key, $value)
2052 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2059 # convert config value to boolean: 'true' or 'false'
2060 # no value, number > 0, 'true' and 'yes' values are true
2061 # rest of values are treated as false (never as error)
2062 sub config_to_bool
{
2065 return 1 if !defined $val; # section.key
2067 # strip leading and trailing whitespace
2071 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2072 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2075 # convert config value to simple decimal number
2076 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2077 # to be multiplied by 1024, 1048576, or 1073741824
2081 # strip leading and trailing whitespace
2085 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2087 # unknown unit is treated as 1
2088 return $num * ($unit eq 'g' ?
1073741824 :
2089 $unit eq 'm' ?
1048576 :
2090 $unit eq 'k' ?
1024 : 1);
2095 # convert config value to array reference, if needed
2096 sub config_to_multi
{
2099 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2102 sub git_get_project_config
{
2103 my ($key, $type) = @_;
2106 return unless ($key);
2107 $key =~ s/^gitweb\.//;
2108 return if ($key =~ m/\W/);
2111 if (defined $type) {
2114 unless ($type eq 'bool' || $type eq 'int');
2118 if (!defined $config_file ||
2119 $config_file ne "$git_dir/config") {
2120 %config = git_parse_project_config
('gitweb');
2121 $config_file = "$git_dir/config";
2124 # check if config variable (key) exists
2125 return unless exists $config{"gitweb.$key"};
2128 if (!defined $type) {
2129 return $config{"gitweb.$key"};
2130 } elsif ($type eq 'bool') {
2131 # backward compatibility: 'git config --bool' returns true/false
2132 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2133 } elsif ($type eq 'int') {
2134 return config_to_int
($config{"gitweb.$key"});
2136 return $config{"gitweb.$key"};
2139 # get hash of given path at given ref
2140 sub git_get_hash_by_path
{
2142 my $path = shift || return undef;
2147 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2148 or die_error
(500, "Open git-ls-tree failed");
2150 close $fd or return undef;
2152 if (!defined $line) {
2153 # there is no tree or hash given by $path at $base
2157 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2158 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2159 if (defined $type && $type ne $2) {
2160 # type doesn't match
2166 # get path of entry with given hash at given tree-ish (ref)
2167 # used to get 'from' filename for combined diff (merge commit) for renames
2168 sub git_get_path_by_hash
{
2169 my $base = shift || return;
2170 my $hash = shift || return;
2174 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2176 while (my $line = <$fd>) {
2179 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2180 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2181 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2190 ## ......................................................................
2191 ## git utility functions, directly accessing git repository
2193 sub git_get_project_description
{
2196 $git_dir = "$projectroot/$path";
2197 open my $fd, '<', "$git_dir/description"
2198 or return git_get_project_config
('description');
2201 if (defined $descr) {
2207 sub git_get_project_ctags
{
2211 $git_dir = "$projectroot/$path";
2212 opendir my $dh, "$git_dir/ctags"
2214 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2215 open my $ct, '<', $_ or next;
2219 my $ctag = $_; $ctag =~ s
#.*/##;
2220 $ctags->{$ctag} = $val;
2226 sub git_populate_project_tagcloud
{
2229 # First, merge different-cased tags; tags vote on casing
2231 foreach (keys %$ctags) {
2232 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2233 if (not $ctags_lc{lc $_}->{topcount
}
2234 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2235 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2236 $ctags_lc{lc $_}->{topname
} = $_;
2241 if (eval { require HTML
::TagCloud
; 1; }) {
2242 $cloud = HTML
::TagCloud
->new;
2243 foreach (sort keys %ctags_lc) {
2244 # Pad the title with spaces so that the cloud looks
2246 my $title = $ctags_lc{$_}->{topname
};
2247 $title =~ s/ / /g;
2248 $title =~ s/^/ /g;
2249 $title =~ s/$/ /g;
2250 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2253 $cloud = \
%ctags_lc;
2258 sub git_show_project_tagcloud
{
2259 my ($cloud, $count) = @_;
2260 print STDERR
ref($cloud)."..\n";
2261 if (ref $cloud eq 'HTML::TagCloud') {
2262 return $cloud->html_and_css($count);
2264 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2265 return '<p align="center">' . join (', ', map {
2266 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2267 } splice(@tags, 0, $count)) . '</p>';
2271 sub git_get_project_url_list
{
2274 $git_dir = "$projectroot/$path";
2275 open my $fd, '<', "$git_dir/cloneurl"
2276 or return wantarray ?
2277 @
{ config_to_multi
(git_get_project_config
('url')) } :
2278 config_to_multi
(git_get_project_config
('url'));
2279 my @git_project_url_list = map { chomp; $_ } <$fd>;
2282 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2285 sub git_get_projects_list
{
2290 $filter =~ s/\.git$//;
2292 my $check_forks = gitweb_check_feature
('forks');
2294 if (-d
$projects_list) {
2295 # search in directory
2296 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2297 # remove the trailing "/"
2299 my $pfxlen = length("$dir");
2300 my $pfxdepth = ($dir =~ tr!/!!);
2303 follow_fast
=> 1, # follow symbolic links
2304 follow_skip
=> 2, # ignore duplicates
2305 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2307 # skip project-list toplevel, if we get it.
2308 return if (m!^[/.]$!);
2309 # only directories can be git repositories
2310 return unless (-d
$_);
2311 # don't traverse too deep (Find is super slow on os x)
2312 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2313 $File::Find
::prune
= 1;
2317 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2318 # we check related file in $projectroot
2319 my $path = ($filter ?
"$filter/" : '') . $subdir;
2320 if (check_export_ok
("$projectroot/$path")) {
2321 push @list, { path
=> $path };
2322 $File::Find
::prune
= 1;
2327 } elsif (-f
$projects_list) {
2328 # read from file(url-encoded):
2329 # 'git%2Fgit.git Linus+Torvalds'
2330 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2331 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2333 open my $fd, '<', $projects_list or return;
2335 while (my $line = <$fd>) {
2337 my ($path, $owner) = split ' ', $line;
2338 $path = unescape
($path);
2339 $owner = unescape
($owner);
2340 if (!defined $path) {
2343 if ($filter ne '') {
2344 # looking for forks;
2345 my $pfx = substr($path, 0, length($filter));
2346 if ($pfx ne $filter) {
2349 my $sfx = substr($path, length($filter));
2350 if ($sfx !~ /^\/.*\
.git
$/) {
2353 } elsif ($check_forks) {
2355 foreach my $filter (keys %paths) {
2356 # looking for forks;
2357 my $pfx = substr($path, 0, length($filter));
2358 if ($pfx ne $filter) {
2361 my $sfx = substr($path, length($filter));
2362 if ($sfx !~ /^\/.*\
.git
$/) {
2365 # is a fork, don't include it in
2370 if (check_export_ok
("$projectroot/$path")) {
2373 owner
=> to_utf8
($owner),
2376 (my $forks_path = $path) =~ s/\.git$//;
2377 $paths{$forks_path}++;
2385 our $gitweb_project_owner = undef;
2386 sub git_get_project_list_from_file
{
2388 return if (defined $gitweb_project_owner);
2390 $gitweb_project_owner = {};
2391 # read from file (url-encoded):
2392 # 'git%2Fgit.git Linus+Torvalds'
2393 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2394 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2395 if (-f
$projects_list) {
2396 open(my $fd, '<', $projects_list);
2397 while (my $line = <$fd>) {
2399 my ($pr, $ow) = split ' ', $line;
2400 $pr = unescape
($pr);
2401 $ow = unescape
($ow);
2402 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2408 sub git_get_project_owner
{
2409 my $project = shift;
2412 return undef unless $project;
2413 $git_dir = "$projectroot/$project";
2415 if (!defined $gitweb_project_owner) {
2416 git_get_project_list_from_file
();
2419 if (exists $gitweb_project_owner->{$project}) {
2420 $owner = $gitweb_project_owner->{$project};
2422 if (!defined $owner){
2423 $owner = git_get_project_config
('owner');
2425 if (!defined $owner) {
2426 $owner = get_file_owner
("$git_dir");
2432 sub git_get_last_activity
{
2436 $git_dir = "$projectroot/$path";
2437 open($fd, "-|", git_cmd
(), 'for-each-ref',
2438 '--format=%(committer)',
2439 '--sort=-committerdate',
2441 'refs/heads') or return;
2442 my $most_recent = <$fd>;
2443 close $fd or return;
2444 if (defined $most_recent &&
2445 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2447 my $age = time - $timestamp;
2448 return ($age, age_string
($age));
2450 return (undef, undef);
2453 sub git_get_references
{
2454 my $type = shift || "";
2456 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2457 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2458 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2459 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2462 while (my $line = <$fd>) {
2464 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2465 if (defined $refs{$1}) {
2466 push @
{$refs{$1}}, $2;
2472 close $fd or return;
2476 sub git_get_rev_name_tags
{
2477 my $hash = shift || return undef;
2479 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2481 my $name_rev = <$fd>;
2484 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2487 # catches also '$hash undefined' output
2492 ## ----------------------------------------------------------------------
2493 ## parse to hash functions
2497 my $tz = shift || "-0000";
2500 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2501 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2502 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2503 $date{'hour'} = $hour;
2504 $date{'minute'} = $min;
2505 $date{'mday'} = $mday;
2506 $date{'day'} = $days[$wday];
2507 $date{'month'} = $months[$mon];
2508 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2509 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2510 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2511 $mday, $months[$mon], $hour ,$min;
2512 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2513 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2515 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2516 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2517 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2518 $date{'hour_local'} = $hour;
2519 $date{'minute_local'} = $min;
2520 $date{'tz_local'} = $tz;
2521 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2522 1900+$year, $mon+1, $mday,
2523 $hour, $min, $sec, $tz);
2532 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2533 $tag{'id'} = $tag_id;
2534 while (my $line = <$fd>) {
2536 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2537 $tag{'object'} = $1;
2538 } elsif ($line =~ m/^type (.+)$/) {
2540 } elsif ($line =~ m/^tag (.+)$/) {
2542 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2543 $tag{'author'} = $1;
2544 $tag{'author_epoch'} = $2;
2545 $tag{'author_tz'} = $3;
2546 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2547 $tag{'author_name'} = $1;
2548 $tag{'author_email'} = $2;
2550 $tag{'author_name'} = $tag{'author'};
2552 } elsif ($line =~ m/--BEGIN/) {
2553 push @comment, $line;
2555 } elsif ($line eq "") {
2559 push @comment, <$fd>;
2560 $tag{'comment'} = \
@comment;
2561 close $fd or return;
2562 if (!defined $tag{'name'}) {
2568 sub parse_commit_text
{
2569 my ($commit_text, $withparents) = @_;
2570 my @commit_lines = split '\n', $commit_text;
2573 pop @commit_lines; # Remove '\0'
2575 if (! @commit_lines) {
2579 my $header = shift @commit_lines;
2580 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2583 ($co{'id'}, my @parents) = split ' ', $header;
2584 while (my $line = shift @commit_lines) {
2585 last if $line eq "\n";
2586 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2588 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2590 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2591 $co{'author'} = to_utf8
($1);
2592 $co{'author_epoch'} = $2;
2593 $co{'author_tz'} = $3;
2594 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2595 $co{'author_name'} = $1;
2596 $co{'author_email'} = $2;
2598 $co{'author_name'} = $co{'author'};
2600 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2601 $co{'committer'} = to_utf8
($1);
2602 $co{'committer_epoch'} = $2;
2603 $co{'committer_tz'} = $3;
2604 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2605 $co{'committer_name'} = $1;
2606 $co{'committer_email'} = $2;
2608 $co{'committer_name'} = $co{'committer'};
2612 if (!defined $co{'tree'}) {
2615 $co{'parents'} = \
@parents;
2616 $co{'parent'} = $parents[0];
2618 foreach my $title (@commit_lines) {
2621 $co{'title'} = chop_str
($title, 80, 5);
2622 # remove leading stuff of merges to make the interesting part visible
2623 if (length($title) > 50) {
2624 $title =~ s/^Automatic //;
2625 $title =~ s/^merge (of|with) /Merge ... /i;
2626 if (length($title) > 50) {
2627 $title =~ s/(http|rsync):\/\///;
2629 if (length($title) > 50) {
2630 $title =~ s/(master|www|rsync)\.//;
2632 if (length($title) > 50) {
2633 $title =~ s/kernel.org:?//;
2635 if (length($title) > 50) {
2636 $title =~ s/\/pub\/scm//;
2639 $co{'title_short'} = chop_str
($title, 50, 5);
2643 if (! defined $co{'title'} || $co{'title'} eq "") {
2644 $co{'title'} = $co{'title_short'} = '(no commit message)';
2646 # remove added spaces
2647 foreach my $line (@commit_lines) {
2650 $co{'comment'} = \
@commit_lines;
2652 my $age = time - $co{'committer_epoch'};
2654 $co{'age_string'} = age_string
($age);
2655 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2656 if ($age > 60*60*24*7*2) {
2657 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2658 $co{'age_string_age'} = $co{'age_string'};
2660 $co{'age_string_date'} = $co{'age_string'};
2661 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2667 my ($commit_id) = @_;
2672 open my $fd, "-|", git_cmd
(), "rev-list",
2678 or die_error
(500, "Open git-rev-list failed");
2679 %co = parse_commit_text
(<$fd>, 1);
2686 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2694 open my $fd, "-|", git_cmd
(), "rev-list",
2697 ("--max-count=" . $maxcount),
2698 ("--skip=" . $skip),
2702 ($filename ?
($filename) : ())
2703 or die_error
(500, "Open git-rev-list failed");
2704 while (my $line = <$fd>) {
2705 my %co = parse_commit_text
($line);
2710 return wantarray ?
@cos : \
@cos;
2713 # parse line of git-diff-tree "raw" output
2714 sub parse_difftree_raw_line
{
2718 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2719 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2720 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2721 $res{'from_mode'} = $1;
2722 $res{'to_mode'} = $2;
2723 $res{'from_id'} = $3;
2725 $res{'status'} = $5;
2726 $res{'similarity'} = $6;
2727 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2728 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2730 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2733 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2734 # combined diff (for merge commit)
2735 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2736 $res{'nparents'} = length($1);
2737 $res{'from_mode'} = [ split(' ', $2) ];
2738 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2739 $res{'from_id'} = [ split(' ', $3) ];
2740 $res{'to_id'} = pop @
{$res{'from_id'}};
2741 $res{'status'} = [ split('', $4) ];
2742 $res{'to_file'} = unquote
($5);
2744 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2745 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2746 $res{'commit'} = $1;
2749 return wantarray ?
%res : \
%res;
2752 # wrapper: return parsed line of git-diff-tree "raw" output
2753 # (the argument might be raw line, or parsed info)
2754 sub parsed_difftree_line
{
2755 my $line_or_ref = shift;
2757 if (ref($line_or_ref) eq "HASH") {
2758 # pre-parsed (or generated by hand)
2759 return $line_or_ref;
2761 return parse_difftree_raw_line
($line_or_ref);
2765 # parse line of git-ls-tree output
2766 sub parse_ls_tree_line
{
2771 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2772 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2780 $res{'name'} = unquote
($4);
2783 return wantarray ?
%res : \
%res;
2786 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2787 sub parse_from_to_diffinfo
{
2788 my ($diffinfo, $from, $to, @parents) = @_;
2790 if ($diffinfo->{'nparents'}) {
2792 $from->{'file'} = [];
2793 $from->{'href'} = [];
2794 fill_from_file_info
($diffinfo, @parents)
2795 unless exists $diffinfo->{'from_file'};
2796 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2797 $from->{'file'}[$i] =
2798 defined $diffinfo->{'from_file'}[$i] ?
2799 $diffinfo->{'from_file'}[$i] :
2800 $diffinfo->{'to_file'};
2801 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2802 $from->{'href'}[$i] = href
(action
=>"blob",
2803 hash_base
=>$parents[$i],
2804 hash
=>$diffinfo->{'from_id'}[$i],
2805 file_name
=>$from->{'file'}[$i]);
2807 $from->{'href'}[$i] = undef;
2811 # ordinary (not combined) diff
2812 $from->{'file'} = $diffinfo->{'from_file'};
2813 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2814 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2815 hash
=>$diffinfo->{'from_id'},
2816 file_name
=>$from->{'file'});
2818 delete $from->{'href'};
2822 $to->{'file'} = $diffinfo->{'to_file'};
2823 if (!is_deleted
($diffinfo)) { # file exists in result
2824 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2825 hash
=>$diffinfo->{'to_id'},
2826 file_name
=>$to->{'file'});
2828 delete $to->{'href'};
2832 ## ......................................................................
2833 ## parse to array of hashes functions
2835 sub git_get_heads_list
{
2839 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2840 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2841 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2844 while (my $line = <$fd>) {
2848 my ($refinfo, $committerinfo) = split(/\0/, $line);
2849 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2850 my ($committer, $epoch, $tz) =
2851 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2852 $ref_item{'fullname'} = $name;
2853 $name =~ s!^refs/heads/!!;
2855 $ref_item{'name'} = $name;
2856 $ref_item{'id'} = $hash;
2857 $ref_item{'title'} = $title || '(no commit message)';
2858 $ref_item{'epoch'} = $epoch;
2860 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2862 $ref_item{'age'} = "unknown";
2865 push @headslist, \
%ref_item;
2869 return wantarray ?
@headslist : \
@headslist;
2872 sub git_get_tags_list
{
2876 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2877 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2878 '--format=%(objectname) %(objecttype) %(refname) '.
2879 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2882 while (my $line = <$fd>) {
2886 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2887 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2888 my ($creator, $epoch, $tz) =
2889 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2890 $ref_item{'fullname'} = $name;
2891 $name =~ s!^refs/tags/!!;
2893 $ref_item{'type'} = $type;
2894 $ref_item{'id'} = $id;
2895 $ref_item{'name'} = $name;
2896 if ($type eq "tag") {
2897 $ref_item{'subject'} = $title;
2898 $ref_item{'reftype'} = $reftype;
2899 $ref_item{'refid'} = $refid;
2901 $ref_item{'reftype'} = $type;
2902 $ref_item{'refid'} = $id;
2905 if ($type eq "tag" || $type eq "commit") {
2906 $ref_item{'epoch'} = $epoch;
2908 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2910 $ref_item{'age'} = "unknown";
2914 push @tagslist, \
%ref_item;
2918 return wantarray ?
@tagslist : \
@tagslist;
2921 ## ----------------------------------------------------------------------
2922 ## filesystem-related functions
2924 sub get_file_owner
{
2927 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2928 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2929 if (!defined $gcos) {
2933 $owner =~ s/[,;].*$//;
2934 return to_utf8
($owner);
2937 # assume that file exists
2939 my $filename = shift;
2941 open my $fd, '<', $filename;
2942 print map { to_utf8
($_) } <$fd>;
2946 ## ......................................................................
2947 ## mimetype related functions
2949 sub mimetype_guess_file
{
2950 my $filename = shift;
2951 my $mimemap = shift;
2952 -r
$mimemap or return undef;
2955 open(my $mh, '<', $mimemap) or return undef;
2957 next if m/^#/; # skip comments
2958 my ($mimetype, $exts) = split(/\t+/);
2959 if (defined $exts) {
2960 my @exts = split(/\s+/, $exts);
2961 foreach my $ext (@exts) {
2962 $mimemap{$ext} = $mimetype;
2968 $filename =~ /\.([^.]*)$/;
2969 return $mimemap{$1};
2972 sub mimetype_guess
{
2973 my $filename = shift;
2975 $filename =~ /\./ or return undef;
2977 if ($mimetypes_file) {
2978 my $file = $mimetypes_file;
2979 if ($file !~ m!^/!) { # if it is relative path
2980 # it is relative to project
2981 $file = "$projectroot/$project/$file";
2983 $mime = mimetype_guess_file
($filename, $file);
2985 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2991 my $filename = shift;
2994 my $mime = mimetype_guess
($filename);
2995 $mime and return $mime;
2999 return $default_blob_plain_mimetype unless $fd;
3002 return 'text/plain';
3003 } elsif (! $filename) {
3004 return 'application/octet-stream';
3005 } elsif ($filename =~ m/\.png$/i) {
3007 } elsif ($filename =~ m/\.gif$/i) {
3009 } elsif ($filename =~ m/\.jpe?g$/i) {
3010 return 'image/jpeg';
3012 return 'application/octet-stream';
3016 sub blob_contenttype
{
3017 my ($fd, $file_name, $type) = @_;
3019 $type ||= blob_mimetype
($fd, $file_name);
3020 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3021 $type .= "; charset=$default_text_plain_charset";
3027 ## ======================================================================
3028 ## functions printing HTML: header, footer, error page
3030 sub git_header_html
{
3031 my $status = shift || "200 OK";
3032 my $expires = shift;
3034 my $title = "$site_name";
3035 if (defined $project) {
3036 $title .= " - " . to_utf8
($project);
3037 if (defined $action) {
3038 $title .= "/$action";
3039 if (defined $file_name) {
3040 $title .= " - " . esc_path
($file_name);
3041 if ($action eq "tree" && $file_name !~ m
|/$|) {
3048 # require explicit support from the UA if we are to send the page as
3049 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3050 # we have to do this because MSIE sometimes globs '*/*', pretending to
3051 # support xhtml+xml but choking when it gets what it asked for.
3052 if (defined $cgi->http('HTTP_ACCEPT') &&
3053 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3054 $cgi->Accept('application/xhtml+xml') != 0) {
3055 $content_type = 'application/xhtml+xml';
3057 $content_type = 'text/html';
3059 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3060 -status
=> $status, -expires
=> $expires);
3061 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3063 <?xml version="1.0" encoding="utf-8"?>
3064 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3065 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3066 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3067 <!-- git core binaries version $git_version -->
3069 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3070 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3071 <meta name="robots" content="index, nofollow"/>
3072 <title>$title</title>
3074 # the stylesheet, favicon etc urls won't work correctly with path_info
3075 # unless we set the appropriate base URL
3076 if ($ENV{'PATH_INFO'}) {
3077 print "<base href=\"".esc_url
($base_url)."\" />\n";
3079 # print out each stylesheet that exist, providing backwards capability
3080 # for those people who defined $stylesheet in a config file
3081 if (defined $stylesheet) {
3082 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3084 foreach my $stylesheet (@stylesheets) {
3085 next unless $stylesheet;
3086 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3089 if (defined $project) {
3090 my %href_params = get_feed_info
();
3091 if (!exists $href_params{'-title'}) {
3092 $href_params{'-title'} = 'log';
3095 foreach my $format qw(RSS Atom) {
3096 my $type = lc($format);
3098 '-rel' => 'alternate',
3099 '-title' => "$project - $href_params{'-title'} - $format feed",
3100 '-type' => "application/$type+xml"
3103 $href_params{'action'} = $type;
3104 $link_attr{'-href'} = href
(%href_params);
3106 "rel=\"$link_attr{'-rel'}\" ".
3107 "title=\"$link_attr{'-title'}\" ".
3108 "href=\"$link_attr{'-href'}\" ".
3109 "type=\"$link_attr{'-type'}\" ".
3112 $href_params{'extra_options'} = '--no-merges';
3113 $link_attr{'-href'} = href
(%href_params);
3114 $link_attr{'-title'} .= ' (no merges)';
3116 "rel=\"$link_attr{'-rel'}\" ".
3117 "title=\"$link_attr{'-title'}\" ".
3118 "href=\"$link_attr{'-href'}\" ".
3119 "type=\"$link_attr{'-type'}\" ".
3124 printf('<link rel="alternate" title="%s projects list" '.
3125 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3126 $site_name, href
(project
=>undef, action
=>"project_index"));
3127 printf('<link rel="alternate" title="%s projects feeds" '.
3128 'href="%s" type="text/x-opml" />'."\n",
3129 $site_name, href
(project
=>undef, action
=>"opml"));
3131 if (defined $favicon) {
3132 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3138 if (-f
$site_header) {
3139 insert_file
($site_header);
3142 print "<div class=\"page_header\">\n" .
3143 $cgi->a({-href
=> esc_url
($logo_url),
3144 -title
=> $logo_label},
3145 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3146 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3147 if (defined $project) {
3148 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3149 if (defined $action) {
3156 my $have_search = gitweb_check_feature
('search');
3157 if (defined $project && $have_search) {
3158 if (!defined $searchtext) {
3162 if (defined $hash_base) {
3163 $search_hash = $hash_base;
3164 } elsif (defined $hash) {
3165 $search_hash = $hash;
3167 $search_hash = "HEAD";
3169 my $action = $my_uri;
3170 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3171 if ($use_pathinfo) {
3172 $action .= "/".esc_url
($project);
3174 print $cgi->startform(-method
=> "get", -action
=> $action) .
3175 "<div class=\"search\">\n" .
3177 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3178 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3179 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3180 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3181 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3182 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3184 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3185 "<span title=\"Extended regular expression\">" .
3186 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3187 -checked
=> $search_use_regexp) .
3190 $cgi->end_form() . "\n";
3194 sub git_footer_html
{
3195 my $feed_class = 'rss_logo';
3197 print "<div class=\"page_footer\">\n";
3198 if (defined $project) {
3199 my $descr = git_get_project_description
($project);
3200 if (defined $descr) {
3201 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3204 my %href_params = get_feed_info
();
3205 if (!%href_params) {
3206 $feed_class .= ' generic';
3208 $href_params{'-title'} ||= 'log';
3210 foreach my $format qw(RSS Atom) {
3211 $href_params{'action'} = lc($format);
3212 print $cgi->a({-href
=> href
(%href_params),
3213 -title
=> "$href_params{'-title'} $format feed",
3214 -class => $feed_class}, $format)."\n";
3218 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3219 -class => $feed_class}, "OPML") . " ";
3220 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3221 -class => $feed_class}, "TXT") . "\n";
3223 print "</div>\n"; # class="page_footer"
3225 if (-f
$site_footer) {
3226 insert_file
($site_footer);
3233 # die_error(<http_status_code>, <error_message>)
3234 # Example: die_error(404, 'Hash not found')
3235 # By convention, use the following status codes (as defined in RFC 2616):
3236 # 400: Invalid or missing CGI parameters, or
3237 # requested object exists but has wrong type.
3238 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3239 # this server or project.
3240 # 404: Requested object/revision/project doesn't exist.
3241 # 500: The server isn't configured properly, or
3242 # an internal error occurred (e.g. failed assertions caused by bugs), or
3243 # an unknown error occurred (e.g. the git binary died unexpectedly).
3245 my $status = shift || 500;
3246 my $error = shift || "Internal server error";
3248 my %http_responses = (400 => '400 Bad Request',
3249 403 => '403 Forbidden',
3250 404 => '404 Not Found',
3251 500 => '500 Internal Server Error');
3252 git_header_html
($http_responses{$status});
3254 <div class="page_body">
3264 ## ----------------------------------------------------------------------
3265 ## functions printing or outputting HTML: navigation
3267 sub git_print_page_nav
{
3268 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3269 $extra = '' if !defined $extra; # pager or formats
3271 my @navs = qw(summary shortlog log commit commitdiff tree);
3273 @navs = grep { $_ ne $suppress } @navs;
3276 my %arg = map { $_ => {action
=>$_} } @navs;
3277 if (defined $head) {
3278 for (qw(commit commitdiff)) {
3279 $arg{$_}{'hash'} = $head;
3281 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3282 for (qw(shortlog log)) {
3283 $arg{$_}{'hash'} = $head;
3288 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3289 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3291 my @actions = gitweb_get_feature
('actions');
3294 'n' => $project, # project name
3295 'f' => $git_dir, # project path within filesystem
3296 'h' => $treehead || '', # current hash ('h' parameter)
3297 'b' => $treebase || '', # hash base ('hb' parameter)
3300 my ($label, $link, $pos) = splice(@actions,0,3);
3302 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3304 $link =~ s/%([%nfhb])/$repl{$1}/g;
3305 $arg{$label}{'_href'} = $link;
3308 print "<div class=\"page_nav\">\n" .
3310 map { $_ eq $current ?
3311 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3313 print "<br/>\n$extra<br/>\n" .
3317 sub format_paging_nav
{
3318 my ($action, $hash, $head, $page, $has_next_link) = @_;
3322 if ($hash ne $head || $page) {
3323 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3325 $paging_nav .= "HEAD";
3329 $paging_nav .= " ⋅ " .
3330 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3331 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3333 $paging_nav .= " ⋅ prev";
3336 if ($has_next_link) {
3337 $paging_nav .= " ⋅ " .
3338 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3339 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3341 $paging_nav .= " ⋅ next";
3347 ## ......................................................................
3348 ## functions printing or outputting HTML: div
3350 sub git_print_header_div
{
3351 my ($action, $title, $hash, $hash_base) = @_;
3354 $args{'action'} = $action;
3355 $args{'hash'} = $hash if $hash;
3356 $args{'hash_base'} = $hash_base if $hash_base;
3358 print "<div class=\"header\">\n" .
3359 $cgi->a({-href
=> href
(%args), -class => "title"},
3360 $title ?
$title : $action) .
3364 sub print_local_time
{
3366 if ($date{'hour_local'} < 6) {
3367 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3368 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3370 printf(" (%02d:%02d %s)",
3371 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3375 # Outputs the author name and date in long form
3376 sub git_print_authorship
{
3379 my $tag = $opts{-tag
} || 'div';
3381 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3382 print "<$tag class=\"author_date\">" .
3383 esc_html
($co->{'author_name'}) .
3385 print_local_time
(%ad) if ($opts{-localtime});
3386 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3390 # Outputs table rows containing the full author or committer information,
3391 # in the format expected for 'commit' view (& similia).
3392 # Parameters are a commit hash reference, followed by the list of people
3393 # to output information for. If the list is empty it defalts to both
3394 # author and committer.
3395 sub git_print_authorship_rows
{
3397 # too bad we can't use @people = @_ || ('author', 'committer')
3399 @people = ('author', 'committer') unless @people;
3400 foreach my $who (@people) {
3401 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3402 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3403 "<td rowspan=\"2\">" .
3404 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3407 "<td></td><td> $wd{'rfc2822'}";
3408 print_local_time
(%wd);
3414 sub git_print_page_path
{
3420 print "<div class=\"page_path\">";
3421 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3422 -title
=> 'tree root'}, to_utf8
("[$project]"));
3424 if (defined $name) {
3425 my @dirname = split '/', $name;
3426 my $basename = pop @dirname;
3429 foreach my $dir (@dirname) {
3430 $fullname .= ($fullname ?
'/' : '') . $dir;
3431 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3433 -title
=> $fullname}, esc_path
($dir));
3436 if (defined $type && $type eq 'blob') {
3437 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3439 -title
=> $name}, esc_path
($basename));
3440 } elsif (defined $type && $type eq 'tree') {
3441 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3443 -title
=> $name}, esc_path
($basename));
3446 print esc_path
($basename);
3449 print "<br/></div>\n";
3456 if ($opts{'-remove_title'}) {
3457 # remove title, i.e. first line of log
3460 # remove leading empty lines
3461 while (defined $log->[0] && $log->[0] eq "") {
3468 foreach my $line (@
$log) {
3469 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3472 if (! $opts{'-remove_signoff'}) {
3473 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3476 # remove signoff lines
3483 # print only one empty line
3484 # do not print empty line after signoff
3486 next if ($empty || $signoff);
3492 print format_log_line_html
($line) . "<br/>\n";
3495 if ($opts{'-final_empty_line'}) {
3496 # end with single empty line
3497 print "<br/>\n" unless $empty;
3501 # return link target (what link points to)
3502 sub git_get_link_target
{
3507 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3511 $link_target = <$fd>;
3516 return $link_target;
3519 # given link target, and the directory (basedir) the link is in,
3520 # return target of link relative to top directory (top tree);
3521 # return undef if it is not possible (including absolute links).
3522 sub normalize_link_target
{
3523 my ($link_target, $basedir) = @_;
3525 # absolute symlinks (beginning with '/') cannot be normalized
3526 return if (substr($link_target, 0, 1) eq '/');
3528 # normalize link target to path from top (root) tree (dir)
3531 $path = $basedir . '/' . $link_target;
3533 # we are in top (root) tree (dir)
3534 $path = $link_target;
3537 # remove //, /./, and /../
3539 foreach my $part (split('/', $path)) {
3540 # discard '.' and ''
3541 next if (!$part || $part eq '.');
3543 if ($part eq '..') {
3547 # link leads outside repository (outside top dir)
3551 push @path_parts, $part;
3554 $path = join('/', @path_parts);
3559 # print tree entry (row of git_tree), but without encompassing <tr> element
3560 sub git_print_tree_entry
{
3561 my ($t, $basedir, $hash_base, $have_blame) = @_;
3564 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3566 # The format of a table row is: mode list link. Where mode is
3567 # the mode of the entry, list is the name of the entry, an href,
3568 # and link is the action links of the entry.
3570 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3571 if ($t->{'type'} eq "blob") {
3572 print "<td class=\"list\">" .
3573 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3574 file_name
=>"$basedir$t->{'name'}", %base_key),
3575 -class => "list"}, esc_path
($t->{'name'}));
3576 if (S_ISLNK
(oct $t->{'mode'})) {
3577 my $link_target = git_get_link_target
($t->{'hash'});
3579 my $norm_target = normalize_link_target
($link_target, $basedir);
3580 if (defined $norm_target) {
3582 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3583 file_name
=>$norm_target),
3584 -title
=> $norm_target}, esc_path
($link_target));
3586 print " -> " . esc_path
($link_target);
3591 print "<td class=\"link\">";
3592 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3593 file_name
=>"$basedir$t->{'name'}", %base_key)},
3597 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3598 file_name
=>"$basedir$t->{'name'}", %base_key)},
3601 if (defined $hash_base) {
3603 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3604 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3608 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3609 file_name
=>"$basedir$t->{'name'}")},
3613 } elsif ($t->{'type'} eq "tree") {
3614 print "<td class=\"list\">";
3615 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3616 file_name
=>"$basedir$t->{'name'}", %base_key)},
3617 esc_path
($t->{'name'}));
3619 print "<td class=\"link\">";
3620 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3621 file_name
=>"$basedir$t->{'name'}", %base_key)},
3623 if (defined $hash_base) {
3625 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3626 file_name
=>"$basedir$t->{'name'}")},
3631 # unknown object: we can only present history for it
3632 # (this includes 'commit' object, i.e. submodule support)
3633 print "<td class=\"list\">" .
3634 esc_path
($t->{'name'}) .
3636 print "<td class=\"link\">";
3637 if (defined $hash_base) {
3638 print $cgi->a({-href
=> href
(action
=>"history",
3639 hash_base
=>$hash_base,
3640 file_name
=>"$basedir$t->{'name'}")},
3647 ## ......................................................................
3648 ## functions printing large fragments of HTML
3650 # get pre-image filenames for merge (combined) diff
3651 sub fill_from_file_info
{
3652 my ($diff, @parents) = @_;
3654 $diff->{'from_file'} = [ ];
3655 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3656 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3657 if ($diff->{'status'}[$i] eq 'R' ||
3658 $diff->{'status'}[$i] eq 'C') {
3659 $diff->{'from_file'}[$i] =
3660 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3667 # is current raw difftree line of file deletion
3669 my $diffinfo = shift;
3671 return $diffinfo->{'to_id'} eq ('0' x
40);
3674 # does patch correspond to [previous] difftree raw line
3675 # $diffinfo - hashref of parsed raw diff format
3676 # $patchinfo - hashref of parsed patch diff format
3677 # (the same keys as in $diffinfo)
3678 sub is_patch_split
{
3679 my ($diffinfo, $patchinfo) = @_;
3681 return defined $diffinfo && defined $patchinfo
3682 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3686 sub git_difftree_body
{
3687 my ($difftree, $hash, @parents) = @_;
3688 my ($parent) = $parents[0];
3689 my $have_blame = gitweb_check_feature
('blame');
3690 print "<div class=\"list_head\">\n";
3691 if ($#{$difftree} > 10) {
3692 print(($#{$difftree} + 1) . " files changed:\n");
3696 print "<table class=\"" .
3697 (@parents > 1 ?
"combined " : "") .
3700 # header only for combined diff in 'commitdiff' view
3701 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3704 print "<thead><tr>\n" .
3705 "<th></th><th></th>\n"; # filename, patchN link
3706 for (my $i = 0; $i < @parents; $i++) {
3707 my $par = $parents[$i];
3709 $cgi->a({-href
=> href
(action
=>"commitdiff",
3710 hash
=>$hash, hash_parent
=>$par),
3711 -title
=> 'commitdiff to parent number ' .
3712 ($i+1) . ': ' . substr($par,0,7)},
3716 print "</tr></thead>\n<tbody>\n";
3721 foreach my $line (@
{$difftree}) {
3722 my $diff = parsed_difftree_line
($line);
3725 print "<tr class=\"dark\">\n";
3727 print "<tr class=\"light\">\n";
3731 if (exists $diff->{'nparents'}) { # combined diff
3733 fill_from_file_info
($diff, @parents)
3734 unless exists $diff->{'from_file'};
3736 if (!is_deleted
($diff)) {
3737 # file exists in the result (child) commit
3739 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3740 file_name
=>$diff->{'to_file'},
3742 -class => "list"}, esc_path
($diff->{'to_file'})) .
3746 esc_path
($diff->{'to_file'}) .
3750 if ($action eq 'commitdiff') {
3753 print "<td class=\"link\">" .
3754 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3759 my $has_history = 0;
3760 my $not_deleted = 0;
3761 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3762 my $hash_parent = $parents[$i];
3763 my $from_hash = $diff->{'from_id'}[$i];
3764 my $from_path = $diff->{'from_file'}[$i];
3765 my $status = $diff->{'status'}[$i];
3767 $has_history ||= ($status ne 'A');
3768 $not_deleted ||= ($status ne 'D');
3770 if ($status eq 'A') {
3771 print "<td class=\"link\" align=\"right\"> | </td>\n";
3772 } elsif ($status eq 'D') {
3773 print "<td class=\"link\">" .
3774 $cgi->a({-href
=> href
(action
=>"blob",
3777 file_name
=>$from_path)},
3781 if ($diff->{'to_id'} eq $from_hash) {
3782 print "<td class=\"link nochange\">";
3784 print "<td class=\"link\">";
3786 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3787 hash
=>$diff->{'to_id'},
3788 hash_parent
=>$from_hash,
3790 hash_parent_base
=>$hash_parent,
3791 file_name
=>$diff->{'to_file'},
3792 file_parent
=>$from_path)},
3798 print "<td class=\"link\">";
3800 print $cgi->a({-href
=> href
(action
=>"blob",
3801 hash
=>$diff->{'to_id'},
3802 file_name
=>$diff->{'to_file'},
3805 print " | " if ($has_history);
3808 print $cgi->a({-href
=> href
(action
=>"history",
3809 file_name
=>$diff->{'to_file'},
3816 next; # instead of 'else' clause, to avoid extra indent
3818 # else ordinary diff
3820 my ($to_mode_oct, $to_mode_str, $to_file_type);
3821 my ($from_mode_oct, $from_mode_str, $from_file_type);
3822 if ($diff->{'to_mode'} ne ('0' x
6)) {
3823 $to_mode_oct = oct $diff->{'to_mode'};
3824 if (S_ISREG
($to_mode_oct)) { # only for regular file
3825 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3827 $to_file_type = file_type
($diff->{'to_mode'});
3829 if ($diff->{'from_mode'} ne ('0' x
6)) {
3830 $from_mode_oct = oct $diff->{'from_mode'};
3831 if (S_ISREG
($to_mode_oct)) { # only for regular file
3832 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3834 $from_file_type = file_type
($diff->{'from_mode'});
3837 if ($diff->{'status'} eq "A") { # created
3838 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3839 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3840 $mode_chng .= "]</span>";
3842 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3843 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3844 -class => "list"}, esc_path
($diff->{'file'}));
3846 print "<td>$mode_chng</td>\n";
3847 print "<td class=\"link\">";
3848 if ($action eq 'commitdiff') {
3851 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3854 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3855 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3859 } elsif ($diff->{'status'} eq "D") { # deleted
3860 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3862 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3863 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3864 -class => "list"}, esc_path
($diff->{'file'}));
3866 print "<td>$mode_chng</td>\n";
3867 print "<td class=\"link\">";
3868 if ($action eq 'commitdiff') {
3871 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3874 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3875 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3878 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3879 file_name
=>$diff->{'file'})},
3882 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3883 file_name
=>$diff->{'file'})},
3887 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3888 my $mode_chnge = "";
3889 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3890 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3891 if ($from_file_type ne $to_file_type) {
3892 $mode_chnge .= " from $from_file_type to $to_file_type";
3894 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3895 if ($from_mode_str && $to_mode_str) {
3896 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3897 } elsif ($to_mode_str) {
3898 $mode_chnge .= " mode: $to_mode_str";
3901 $mode_chnge .= "]</span>\n";
3904 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3905 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3906 -class => "list"}, esc_path
($diff->{'file'}));
3908 print "<td>$mode_chnge</td>\n";
3909 print "<td class=\"link\">";
3910 if ($action eq 'commitdiff') {
3913 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3915 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3916 # "commit" view and modified file (not onlu mode changed)
3917 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3918 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3919 hash_base
=>$hash, hash_parent_base
=>$parent,
3920 file_name
=>$diff->{'file'})},
3924 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3925 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3928 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3929 file_name
=>$diff->{'file'})},
3932 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3933 file_name
=>$diff->{'file'})},
3937 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3938 my %status_name = ('R' => 'moved', 'C' => 'copied');
3939 my $nstatus = $status_name{$diff->{'status'}};
3941 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3942 # mode also for directories, so we cannot use $to_mode_str
3943 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3946 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3947 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3948 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3949 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3950 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3951 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3952 -class => "list"}, esc_path
($diff->{'from_file'})) .
3953 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3954 "<td class=\"link\">";
3955 if ($action eq 'commitdiff') {
3958 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3960 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3961 # "commit" view and modified file (not only pure rename or copy)
3962 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3963 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3964 hash_base
=>$hash, hash_parent_base
=>$parent,
3965 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3969 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3970 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3973 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3974 file_name
=>$diff->{'to_file'})},
3977 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3978 file_name
=>$diff->{'to_file'})},
3982 } # we should not encounter Unmerged (U) or Unknown (X) status
3985 print "</tbody>" if $has_header;
3989 sub git_patchset_body
{
3990 my ($fd, $difftree, $hash, @hash_parents) = @_;
3991 my ($hash_parent) = $hash_parents[0];
3993 my $is_combined = (@hash_parents > 1);
3995 my $patch_number = 0;
4001 print "<div class=\"patchset\">\n";
4003 # skip to first patch
4004 while ($patch_line = <$fd>) {
4007 last if ($patch_line =~ m/^diff /);
4011 while ($patch_line) {
4013 # parse "git diff" header line
4014 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4015 # $1 is from_name, which we do not use
4016 $to_name = unquote
($2);
4017 $to_name =~ s!^b/!!;
4018 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4019 # $1 is 'cc' or 'combined', which we do not use
4020 $to_name = unquote
($2);
4025 # check if current patch belong to current raw line
4026 # and parse raw git-diff line if needed
4027 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4028 # this is continuation of a split patch
4029 print "<div class=\"patch cont\">\n";
4031 # advance raw git-diff output if needed
4032 $patch_idx++ if defined $diffinfo;
4034 # read and prepare patch information
4035 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4037 # compact combined diff output can have some patches skipped
4038 # find which patch (using pathname of result) we are at now;
4040 while ($to_name ne $diffinfo->{'to_file'}) {
4041 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4042 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4043 "</div>\n"; # class="patch"
4048 last if $patch_idx > $#$difftree;
4049 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4053 # modifies %from, %to hashes
4054 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4056 # this is first patch for raw difftree line with $patch_idx index
4057 # we index @$difftree array from 0, but number patches from 1
4058 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4062 #assert($patch_line =~ m/^diff /) if DEBUG;
4063 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4065 # print "git diff" header
4066 print format_git_diff_header_line
($patch_line, $diffinfo,
4069 # print extended diff header
4070 print "<div class=\"diff extended_header\">\n";
4072 while ($patch_line = <$fd>) {
4075 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4077 print format_extended_diff_header_line
($patch_line, $diffinfo,
4080 print "</div>\n"; # class="diff extended_header"
4082 # from-file/to-file diff header
4083 if (! $patch_line) {
4084 print "</div>\n"; # class="patch"
4087 next PATCH
if ($patch_line =~ m/^diff /);
4088 #assert($patch_line =~ m/^---/) if DEBUG;
4090 my $last_patch_line = $patch_line;
4091 $patch_line = <$fd>;
4093 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4095 print format_diff_from_to_header
($last_patch_line, $patch_line,
4096 $diffinfo, \
%from, \
%to,
4101 while ($patch_line = <$fd>) {
4104 next PATCH
if ($patch_line =~ m/^diff /);
4106 print format_diff_line
($patch_line, \
%from, \
%to);
4110 print "</div>\n"; # class="patch"
4113 # for compact combined (--cc) format, with chunk and patch simpliciaction
4114 # patchset might be empty, but there might be unprocessed raw lines
4115 for (++$patch_idx if $patch_number > 0;
4116 $patch_idx < @
$difftree;
4118 # read and prepare patch information
4119 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4121 # generate anchor for "patch" links in difftree / whatchanged part
4122 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4123 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4124 "</div>\n"; # class="patch"
4129 if ($patch_number == 0) {
4130 if (@hash_parents > 1) {
4131 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4133 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4137 print "</div>\n"; # class="patchset"
4140 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4142 # fills project list info (age, description, owner, forks) for each
4143 # project in the list, removing invalid projects from returned list
4144 # NOTE: modifies $projlist, but does not remove entries from it
4145 sub fill_project_list_info
{
4146 my ($projlist, $check_forks) = @_;
4149 my $show_ctags = gitweb_check_feature
('ctags');
4151 foreach my $pr (@
$projlist) {
4152 my (@activity) = git_get_last_activity
($pr->{'path'});
4153 unless (@activity) {
4156 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4157 if (!defined $pr->{'descr'}) {
4158 my $descr = git_get_project_description
($pr->{'path'}) || "";
4159 $descr = to_utf8
($descr);
4160 $pr->{'descr_long'} = $descr;
4161 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4163 if (!defined $pr->{'owner'}) {
4164 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4167 my $pname = $pr->{'path'};
4168 if (($pname =~ s/\.git$//) &&
4169 ($pname !~ /\/$/) &&
4170 (-d
"$projectroot/$pname")) {
4171 $pr->{'forks'} = "-d $projectroot/$pname";
4176 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4177 push @projects, $pr;
4183 # print 'sort by' <th> element, generating 'sort by $name' replay link
4184 # if that order is not selected
4186 my ($name, $order, $header) = @_;
4187 $header ||= ucfirst($name);
4189 if ($order eq $name) {
4190 print "<th>$header</th>\n";
4193 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4194 -class => "header"}, $header) .
4199 sub git_project_list_body
{
4200 # actually uses global variable $project
4201 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4203 my $check_forks = gitweb_check_feature
('forks');
4204 my @projects = fill_project_list_info
($projlist, $check_forks);
4206 $order ||= $default_projects_order;
4207 $from = 0 unless defined $from;
4208 $to = $#projects if (!defined $to || $#projects < $to);
4211 project
=> { key
=> 'path', type
=> 'str' },
4212 descr
=> { key
=> 'descr_long', type
=> 'str' },
4213 owner
=> { key
=> 'owner', type
=> 'str' },
4214 age
=> { key
=> 'age', type
=> 'num' }
4216 my $oi = $order_info{$order};
4217 if ($oi->{'type'} eq 'str') {
4218 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4220 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4223 my $show_ctags = gitweb_check_feature
('ctags');
4226 foreach my $p (@projects) {
4227 foreach my $ct (keys %{$p->{'ctags'}}) {
4228 $ctags{$ct} += $p->{'ctags'}->{$ct};
4231 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4232 print git_show_project_tagcloud
($cloud, 64);
4235 print "<table class=\"project_list\">\n";
4236 unless ($no_header) {
4239 print "<th></th>\n";
4241 print_sort_th
('project', $order, 'Project');
4242 print_sort_th
('descr', $order, 'Description');
4243 print_sort_th
('owner', $order, 'Owner');
4244 print_sort_th
('age', $order, 'Last Change');
4245 print "<th></th>\n" . # for links
4249 my $tagfilter = $cgi->param('by_tag');
4250 for (my $i = $from; $i <= $to; $i++) {
4251 my $pr = $projects[$i];
4253 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4254 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4255 and not $pr->{'descr_long'} =~ /$searchtext/;
4256 # Weed out forks or non-matching entries of search
4258 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4259 $forkbase="^$forkbase" if $forkbase;
4260 next if not $searchtext and not $tagfilter and $show_ctags
4261 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4265 print "<tr class=\"dark\">\n";
4267 print "<tr class=\"light\">\n";
4272 if ($pr->{'forks'}) {
4273 print "<!-- $pr->{'forks'} -->\n";
4274 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4278 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4279 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4280 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4281 -class => "list", -title
=> $pr->{'descr_long'}},
4282 esc_html
($pr->{'descr'})) . "</td>\n" .
4283 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4284 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4285 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4286 "<td class=\"link\">" .
4287 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4288 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4289 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4290 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4291 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4295 if (defined $extra) {
4298 print "<td></td>\n";
4300 print "<td colspan=\"5\">$extra</td>\n" .
4306 sub git_shortlog_body
{
4307 # uses global variable $project
4308 my ($commitlist, $from, $to, $refs, $extra) = @_;
4310 $from = 0 unless defined $from;
4311 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4313 print "<table class=\"shortlog\">\n";
4315 for (my $i = $from; $i <= $to; $i++) {
4316 my %co = %{$commitlist->[$i]};
4317 my $commit = $co{'id'};
4318 my $ref = format_ref_marker
($refs, $commit);
4320 print "<tr class=\"dark\">\n";
4322 print "<tr class=\"light\">\n";
4325 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4326 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4327 format_author_html
('td', \
%co, 10) . "<td>";
4328 print format_subject_html
($co{'title'}, $co{'title_short'},
4329 href
(action
=>"commit", hash
=>$commit), $ref);
4331 "<td class=\"link\">" .
4332 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4333 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4334 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4335 my $snapshot_links = format_snapshot_links
($commit);
4336 if (defined $snapshot_links) {
4337 print " | " . $snapshot_links;
4342 if (defined $extra) {
4344 "<td colspan=\"4\">$extra</td>\n" .
4350 sub git_history_body
{
4351 # Warning: assumes constant type (blob or tree) during history
4352 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4354 $from = 0 unless defined $from;
4355 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4357 print "<table class=\"history\">\n";
4359 for (my $i = $from; $i <= $to; $i++) {
4360 my %co = %{$commitlist->[$i]};
4364 my $commit = $co{'id'};
4366 my $ref = format_ref_marker
($refs, $commit);
4369 print "<tr class=\"dark\">\n";
4371 print "<tr class=\"light\">\n";
4374 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4375 # shortlog: format_author_html('td', \%co, 10)
4376 format_author_html
('td', \
%co, 15, 3) . "<td>";
4377 # originally git_history used chop_str($co{'title'}, 50)
4378 print format_subject_html
($co{'title'}, $co{'title_short'},
4379 href
(action
=>"commit", hash
=>$commit), $ref);
4381 "<td class=\"link\">" .
4382 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4383 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4385 if ($ftype eq 'blob') {
4386 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4387 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4388 if (defined $blob_current && defined $blob_parent &&
4389 $blob_current ne $blob_parent) {
4391 $cgi->a({-href
=> href
(action
=>"blobdiff",
4392 hash
=>$blob_current, hash_parent
=>$blob_parent,
4393 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4394 file_name
=>$file_name)},
4401 if (defined $extra) {
4403 "<td colspan=\"4\">$extra</td>\n" .
4410 # uses global variable $project
4411 my ($taglist, $from, $to, $extra) = @_;
4412 $from = 0 unless defined $from;
4413 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4415 print "<table class=\"tags\">\n";
4417 for (my $i = $from; $i <= $to; $i++) {
4418 my $entry = $taglist->[$i];
4420 my $comment = $tag{'subject'};
4422 if (defined $comment) {
4423 $comment_short = chop_str
($comment, 30, 5);
4426 print "<tr class=\"dark\">\n";
4428 print "<tr class=\"light\">\n";
4431 if (defined $tag{'age'}) {
4432 print "<td><i>$tag{'age'}</i></td>\n";
4434 print "<td></td>\n";
4437 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4438 -class => "list name"}, esc_html
($tag{'name'})) .
4441 if (defined $comment) {
4442 print format_subject_html
($comment, $comment_short,
4443 href
(action
=>"tag", hash
=>$tag{'id'}));
4446 "<td class=\"selflink\">";
4447 if ($tag{'type'} eq "tag") {
4448 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4453 "<td class=\"link\">" . " | " .
4454 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4455 if ($tag{'reftype'} eq "commit") {
4456 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4457 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4458 } elsif ($tag{'reftype'} eq "blob") {
4459 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4464 if (defined $extra) {
4466 "<td colspan=\"5\">$extra</td>\n" .
4472 sub git_heads_body
{
4473 # uses global variable $project
4474 my ($headlist, $head, $from, $to, $extra) = @_;
4475 $from = 0 unless defined $from;
4476 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4478 print "<table class=\"heads\">\n";
4480 for (my $i = $from; $i <= $to; $i++) {
4481 my $entry = $headlist->[$i];
4483 my $curr = $ref{'id'} eq $head;
4485 print "<tr class=\"dark\">\n";
4487 print "<tr class=\"light\">\n";
4490 print "<td><i>$ref{'age'}</i></td>\n" .
4491 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4492 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4493 -class => "list name"},esc_html
($ref{'name'})) .
4495 "<td class=\"link\">" .
4496 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4497 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4498 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4502 if (defined $extra) {
4504 "<td colspan=\"3\">$extra</td>\n" .
4510 sub git_search_grep_body
{
4511 my ($commitlist, $from, $to, $extra) = @_;
4512 $from = 0 unless defined $from;
4513 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4515 print "<table class=\"commit_search\">\n";
4517 for (my $i = $from; $i <= $to; $i++) {
4518 my %co = %{$commitlist->[$i]};
4522 my $commit = $co{'id'};
4524 print "<tr class=\"dark\">\n";
4526 print "<tr class=\"light\">\n";
4529 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4530 format_author_html
('td', \
%co, 15, 5) .
4532 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4533 -class => "list subject"},
4534 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4535 my $comment = $co{'comment'};
4536 foreach my $line (@
$comment) {
4537 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4538 my ($lead, $match, $trail) = ($1, $2, $3);
4539 $match = chop_str
($match, 70, 5, 'center');
4540 my $contextlen = int((80 - length($match))/2);
4541 $contextlen = 30 if ($contextlen > 30);
4542 $lead = chop_str
($lead, $contextlen, 10, 'left');
4543 $trail = chop_str
($trail, $contextlen, 10, 'right');
4545 $lead = esc_html
($lead);
4546 $match = esc_html
($match);
4547 $trail = esc_html
($trail);
4549 print "$lead<span class=\"match\">$match</span>$trail<br />";
4553 "<td class=\"link\">" .
4554 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4556 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4558 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4562 if (defined $extra) {
4564 "<td colspan=\"3\">$extra</td>\n" .
4570 ## ======================================================================
4571 ## ======================================================================
4574 sub git_project_list
{
4575 my $order = $input_params{'order'};
4576 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4577 die_error
(400, "Unknown order parameter");
4580 my @list = git_get_projects_list
();
4582 die_error
(404, "No projects found");
4586 if (-f
$home_text) {
4587 print "<div class=\"index_include\">\n";
4588 insert_file
($home_text);
4591 print $cgi->startform(-method
=> "get") .
4592 "<p class=\"projsearch\">Search:\n" .
4593 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4595 $cgi->end_form() . "\n";
4596 git_project_list_body
(\
@list, $order);
4601 my $order = $input_params{'order'};
4602 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4603 die_error
(400, "Unknown order parameter");
4606 my @list = git_get_projects_list
($project);
4608 die_error
(404, "No forks found");
4612 git_print_page_nav
('','');
4613 git_print_header_div
('summary', "$project forks");
4614 git_project_list_body
(\
@list, $order);
4618 sub git_project_index
{
4619 my @projects = git_get_projects_list
($project);
4622 -type
=> 'text/plain',
4623 -charset
=> 'utf-8',
4624 -content_disposition
=> 'inline; filename="index.aux"');
4626 foreach my $pr (@projects) {
4627 if (!exists $pr->{'owner'}) {
4628 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4631 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4632 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4633 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4634 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4638 print "$path $owner\n";
4643 my $descr = git_get_project_description
($project) || "none";
4644 my %co = parse_commit
("HEAD");
4645 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4646 my $head = $co{'id'};
4648 my $owner = git_get_project_owner
($project);
4650 my $refs = git_get_references
();
4651 # These get_*_list functions return one more to allow us to see if
4652 # there are more ...
4653 my @taglist = git_get_tags_list
(16);
4654 my @headlist = git_get_heads_list
(16);
4656 my $check_forks = gitweb_check_feature
('forks');
4659 @forklist = git_get_projects_list
($project);
4663 git_print_page_nav
('summary','', $head);
4665 print "<div class=\"title\"> </div>\n";
4666 print "<table class=\"projects_list\">\n" .
4667 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4668 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4669 if (defined $cd{'rfc2822'}) {
4670 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4673 # use per project git URL list in $projectroot/$project/cloneurl
4674 # or make project git URL from git base URL and project name
4675 my $url_tag = "URL";
4676 my @url_list = git_get_project_url_list
($project);
4677 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4678 foreach my $git_url (@url_list) {
4679 next unless $git_url;
4680 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4685 my $show_ctags = gitweb_check_feature
('ctags');
4687 my $ctags = git_get_project_ctags
($project);
4688 my $cloud = git_populate_project_tagcloud
($ctags);
4689 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4690 print "</td>\n<td>" unless %$ctags;
4691 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4692 print "</td>\n<td>" if %$ctags;
4693 print git_show_project_tagcloud
($cloud, 48);
4699 # If XSS prevention is on, we don't include README.html.
4700 # TODO: Allow a readme in some safe format.
4701 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4702 print "<div class=\"title\">readme</div>\n" .
4703 "<div class=\"readme\">\n";
4704 insert_file
("$projectroot/$project/README.html");
4705 print "\n</div>\n"; # class="readme"
4708 # we need to request one more than 16 (0..15) to check if
4710 my @commitlist = $head ? parse_commits
($head, 17) : ();
4712 git_print_header_div
('shortlog');
4713 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4714 $#commitlist <= 15 ?
undef :
4715 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4719 git_print_header_div
('tags');
4720 git_tags_body
(\
@taglist, 0, 15,
4721 $#taglist <= 15 ?
undef :
4722 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4726 git_print_header_div
('heads');
4727 git_heads_body
(\
@headlist, $head, 0, 15,
4728 $#headlist <= 15 ?
undef :
4729 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4733 git_print_header_div
('forks');
4734 git_project_list_body
(\
@forklist, 'age', 0, 15,
4735 $#forklist <= 15 ?
undef :
4736 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4744 my $head = git_get_head_hash
($project);
4746 git_print_page_nav
('','', $head,undef,$head);
4747 my %tag = parse_tag
($hash);
4750 die_error
(404, "Unknown tag object");
4753 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4754 print "<div class=\"title_text\">\n" .
4755 "<table class=\"object_header\">\n" .
4757 "<td>object</td>\n" .
4758 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4759 $tag{'object'}) . "</td>\n" .
4760 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4761 $tag{'type'}) . "</td>\n" .
4763 if (defined($tag{'author'})) {
4764 git_print_authorship_rows
(\
%tag, 'author');
4766 print "</table>\n\n" .
4768 print "<div class=\"page_body\">";
4769 my $comment = $tag{'comment'};
4770 foreach my $line (@
$comment) {
4772 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4780 gitweb_check_feature
('blame')
4781 or die_error
(403, "Blame view not allowed");
4784 die_error
(400, "No file name given") unless $file_name;
4785 $hash_base ||= git_get_head_hash
($project);
4786 die_error
(404, "Couldn't find base commit") unless $hash_base;
4787 my %co = parse_commit
($hash_base)
4788 or die_error
(404, "Commit not found");
4790 if (!defined $hash) {
4791 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4792 or die_error
(404, "Error looking up file");
4794 $ftype = git_get_type
($hash);
4795 if ($ftype !~ "blob") {
4796 die_error
(400, "Object is not a blob");
4800 # run git-blame --porcelain
4801 open my $fd, "-|", git_cmd
(), "blame", '-p',
4802 $hash_base, '--', $file_name
4803 or die_error
(500, "Open git-blame failed");
4808 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4811 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4814 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4816 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4817 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4818 git_print_page_path
($file_name, $ftype, $hash_base);
4821 my @rev_color = qw(light dark);
4822 my $num_colors = scalar(@rev_color);
4823 my $current_color = 0;
4827 <div class="page_body">
4828 <table class="blame">
4829 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4832 while (my $line = <$fd>) {
4834 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4835 # no <lines in group> for subsequent lines in group of lines
4836 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4837 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4838 if (!exists $metainfo{$full_rev}) {
4839 $metainfo{$full_rev} = { 'nprevious' => 0 };
4841 my $meta = $metainfo{$full_rev};
4843 while ($data = <$fd>) {
4845 last if ($data =~ s/^\t//); # contents of line
4846 if ($data =~ /^(\S+)(?: (.*))?$/) {
4847 $meta->{$1} = $2 unless exists $meta->{$1};
4849 if ($data =~ /^previous /) {
4850 $meta->{'nprevious'}++;
4853 my $short_rev = substr($full_rev, 0, 8);
4854 my $author = $meta->{'author'};
4856 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4857 my $date = $date{'iso-tz'};
4859 $current_color = ($current_color + 1) % $num_colors;
4861 my $tr_class = $rev_color[$current_color];
4862 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4863 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4864 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4865 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4867 print "<td class=\"sha1\"";
4868 print " title=\"". esc_html
($author) . ", $date\"";
4869 print " rowspan=\"$group_size\"" if ($group_size > 1);
4871 print $cgi->a({-href
=> href
(action
=>"commit",
4873 file_name
=>$file_name)},
4874 esc_html
($short_rev));
4875 if ($group_size >= 2) {
4876 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
4877 if (@author_initials) {
4879 esc_html
(join('', @author_initials));
4885 # 'previous' <sha1 of parent commit> <filename at commit>
4886 if (exists $meta->{'previous'} &&
4887 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
4888 $meta->{'parent'} = $1;
4889 $meta->{'file_parent'} = unquote
($2);
4892 exists($meta->{'parent'}) ?
4893 $meta->{'parent'} : $full_rev;
4894 my $linenr_filename =
4895 exists($meta->{'file_parent'}) ?
4896 $meta->{'file_parent'} : unquote
($meta->{'filename'});
4897 my $blamed = href
(action
=> 'blame',
4898 file_name
=> $linenr_filename,
4899 hash_base
=> $linenr_commit);
4900 print "<td class=\"linenr\">";
4901 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4902 -class => "linenr" },
4905 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4911 or print "Reading blob failed\n";
4918 my $head = git_get_head_hash
($project);
4920 git_print_page_nav
('','', $head,undef,$head);
4921 git_print_header_div
('summary', $project);
4923 my @tagslist = git_get_tags_list
();
4925 git_tags_body
(\
@tagslist);
4931 my $head = git_get_head_hash
($project);
4933 git_print_page_nav
('','', $head,undef,$head);
4934 git_print_header_div
('summary', $project);
4936 my @headslist = git_get_heads_list
();
4938 git_heads_body
(\
@headslist, $head);
4943 sub git_blob_plain
{
4947 if (!defined $hash) {
4948 if (defined $file_name) {
4949 my $base = $hash_base || git_get_head_hash
($project);
4950 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4951 or die_error
(404, "Cannot find file");
4953 die_error
(400, "No file name defined");
4955 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4956 # blobs defined by non-textual hash id's can be cached
4960 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4961 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4963 # content-type (can include charset)
4964 $type = blob_contenttype
($fd, $file_name, $type);
4966 # "save as" filename, even when no $file_name is given
4967 my $save_as = "$hash";
4968 if (defined $file_name) {
4969 $save_as = $file_name;
4970 } elsif ($type =~ m/^text\//) {
4974 # With XSS prevention on, blobs of all types except a few known safe
4975 # ones are served with "Content-Disposition: attachment" to make sure
4976 # they don't run in our security domain. For certain image types,
4977 # blob view writes an <img> tag referring to blob_plain view, and we
4978 # want to be sure not to break that by serving the image as an
4979 # attachment (though Firefox 3 doesn't seem to care).
4980 my $sandbox = $prevent_xss &&
4981 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4985 -expires
=> $expires,
4986 -content_disposition
=>
4987 ($sandbox ?
'attachment' : 'inline')
4988 . '; filename="' . $save_as . '"');
4990 binmode STDOUT
, ':raw';
4992 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4999 if (!defined $hash) {
5000 if (defined $file_name) {
5001 my $base = $hash_base || git_get_head_hash
($project);
5002 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5003 or die_error
(404, "Cannot find file");
5005 die_error
(400, "No file name defined");
5007 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5008 # blobs defined by non-textual hash id's can be cached
5012 my $have_blame = gitweb_check_feature
('blame');
5013 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5014 or die_error
(500, "Couldn't cat $file_name, $hash");
5015 my $mimetype = blob_mimetype
($fd, $file_name);
5016 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5018 return git_blob_plain
($mimetype);
5020 # we can have blame only for text/* mimetype
5021 $have_blame &&= ($mimetype =~ m!^text/!);
5023 git_header_html
(undef, $expires);
5024 my $formats_nav = '';
5025 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5026 if (defined $file_name) {
5029 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5034 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5037 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5040 $cgi->a({-href
=> href
(action
=>"blob",
5041 hash_base
=>"HEAD", file_name
=>$file_name)},
5045 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5048 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5049 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5051 print "<div class=\"page_nav\">\n" .
5052 "<br/><br/></div>\n" .
5053 "<div class=\"title\">$hash</div>\n";
5055 git_print_page_path
($file_name, "blob", $hash_base);
5056 print "<div class=\"page_body\">\n";
5057 if ($mimetype =~ m!^image/!) {
5058 print qq!<img type
="$mimetype"!;
5060 print qq! alt
="$file_name" title
="$file_name"!;
5063 href(action=>"blob_plain
", hash=>$hash,
5064 hash_base=>$hash_base, file_name=>$file_name) .
5068 while (my $line = <$fd>) {
5071 $line = untabify
($line);
5072 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5073 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5074 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5078 or print "Reading blob failed.\n";
5084 if (!defined $hash_base) {
5085 $hash_base = "HEAD";
5087 if (!defined $hash) {
5088 if (defined $file_name) {
5089 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5094 die_error
(404, "No such tree") unless defined($hash);
5099 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5100 or die_error
(500, "Open git-ls-tree failed");
5101 @entries = map { chomp; $_ } <$fd>;
5103 or die_error
(404, "Reading tree failed");
5106 my $refs = git_get_references
();
5107 my $ref = format_ref_marker
($refs, $hash_base);
5110 my $have_blame = gitweb_check_feature
('blame');
5111 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5113 if (defined $file_name) {
5115 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5117 $cgi->a({-href
=> href
(action
=>"tree",
5118 hash_base
=>"HEAD", file_name
=>$file_name)},
5121 my $snapshot_links = format_snapshot_links
($hash);
5122 if (defined $snapshot_links) {
5123 # FIXME: Should be available when we have no hash base as well.
5124 push @views_nav, $snapshot_links;
5126 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5127 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5130 print "<div class=\"page_nav\">\n";
5131 print "<br/><br/></div>\n";
5132 print "<div class=\"title\">$hash</div>\n";
5134 if (defined $file_name) {
5135 $basedir = $file_name;
5136 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5139 git_print_page_path
($file_name, 'tree', $hash_base);
5141 print "<div class=\"page_body\">\n";
5142 print "<table class=\"tree\">\n";
5144 # '..' (top directory) link if possible
5145 if (defined $hash_base &&
5146 defined $file_name && $file_name =~ m![^/]+$!) {
5148 print "<tr class=\"dark\">\n";
5150 print "<tr class=\"light\">\n";
5154 my $up = $file_name;
5155 $up =~ s!/?[^/]+$!!;
5156 undef $up unless $up;
5157 # based on git_print_tree_entry
5158 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5159 print '<td class="list">';
5160 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5164 print "<td class=\"link\"></td>\n";
5168 foreach my $line (@entries) {
5169 my %t = parse_ls_tree_line
($line, -z
=> 1);
5172 print "<tr class=\"dark\">\n";
5174 print "<tr class=\"light\">\n";
5178 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5182 print "</table>\n" .
5188 my $format = $input_params{'snapshot_format'};
5189 if (!@snapshot_fmts) {
5190 die_error
(403, "Snapshots not allowed");
5192 # default to first supported snapshot format
5193 $format ||= $snapshot_fmts[0];
5194 if ($format !~ m/^[a-z0-9]+$/) {
5195 die_error
(400, "Invalid snapshot format parameter");
5196 } elsif (!exists($known_snapshot_formats{$format})) {
5197 die_error
(400, "Unknown snapshot format");
5198 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5199 die_error
(403, "Snapshot format not allowed");
5200 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5201 die_error
(403, "Unsupported snapshot format");
5204 if (!defined $hash) {
5205 $hash = git_get_head_hash
($project);
5208 my $name = $project;
5209 $name =~ s
,([^/])/*\
.git
$,$1,;
5210 $name = basename
($name);
5211 my $filename = to_utf8
($name);
5212 $name =~ s/\047/\047\\\047\047/g;
5214 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5215 $cmd = quote_command
(
5216 git_cmd
(), 'archive',
5217 "--format=$known_snapshot_formats{$format}{'format'}",
5218 "--prefix=$name/", $hash);
5219 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5220 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5224 -type
=> $known_snapshot_formats{$format}{'type'},
5225 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5226 -status
=> '200 OK');
5228 open my $fd, "-|", $cmd
5229 or die_error
(500, "Execute git-archive failed");
5230 binmode STDOUT
, ':raw';
5232 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5237 my $head = git_get_head_hash
($project);
5238 if (!defined $hash) {
5241 if (!defined $page) {
5244 my $refs = git_get_references
();
5246 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5248 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5250 my ($patch_max) = gitweb_get_feature
('patches');
5252 if ($patch_max < 0 || @commitlist <= $patch_max) {
5253 $paging_nav .= " ⋅ " .
5254 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5260 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5263 my %co = parse_commit
($hash);
5265 git_print_header_div
('summary', $project);
5266 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5268 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5269 for (my $i = 0; $i <= $to; $i++) {
5270 my %co = %{$commitlist[$i]};
5272 my $commit = $co{'id'};
5273 my $ref = format_ref_marker
($refs, $commit);
5274 my %ad = parse_date
($co{'author_epoch'});
5275 git_print_header_div
('commit',
5276 "<span class=\"age\">$co{'age_string'}</span>" .
5277 esc_html
($co{'title'}) . $ref,
5279 print "<div class=\"title_text\">\n" .
5280 "<div class=\"log_link\">\n" .
5281 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5283 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5285 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5288 git_print_authorship
(\
%co, -tag
=> 'span');
5289 print "<br/>\n</div>\n";
5291 print "<div class=\"log_body\">\n";
5292 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5295 if ($#commitlist >= 100) {
5296 print "<div class=\"page_nav\">\n";
5297 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5298 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5305 $hash ||= $hash_base || "HEAD";
5306 my %co = parse_commit
($hash)
5307 or die_error
(404, "Unknown commit object");
5309 my $parent = $co{'parent'};
5310 my $parents = $co{'parents'}; # listref
5312 # we need to prepare $formats_nav before any parameter munging
5314 if (!defined $parent) {
5316 $formats_nav .= '(initial)';
5317 } elsif (@
$parents == 1) {
5318 # single parent commit
5321 $cgi->a({-href
=> href
(action
=>"commit",
5323 esc_html
(substr($parent, 0, 7))) .
5330 $cgi->a({-href
=> href
(action
=>"commit",
5332 esc_html
(substr($_, 0, 7)));
5336 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5337 $formats_nav .= " | " .
5338 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5342 if (!defined $parent) {
5346 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5348 (@
$parents <= 1 ?
$parent : '-c'),
5350 or die_error
(500, "Open git-diff-tree failed");
5351 @difftree = map { chomp; $_ } <$fd>;
5352 close $fd or die_error
(404, "Reading git-diff-tree failed");
5354 # non-textual hash id's can be cached
5356 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5359 my $refs = git_get_references
();
5360 my $ref = format_ref_marker
($refs, $co{'id'});
5362 git_header_html
(undef, $expires);
5363 git_print_page_nav
('commit', '',
5364 $hash, $co{'tree'}, $hash,
5367 if (defined $co{'parent'}) {
5368 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5370 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5372 print "<div class=\"title_text\">\n" .
5373 "<table class=\"object_header\">\n";
5374 git_print_authorship_rows
(\
%co);
5375 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5378 "<td class=\"sha1\">" .
5379 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5380 class => "list"}, $co{'tree'}) .
5382 "<td class=\"link\">" .
5383 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5385 my $snapshot_links = format_snapshot_links
($hash);
5386 if (defined $snapshot_links) {
5387 print " | " . $snapshot_links;
5392 foreach my $par (@
$parents) {
5395 "<td class=\"sha1\">" .
5396 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5397 class => "list"}, $par) .
5399 "<td class=\"link\">" .
5400 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5402 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5409 print "<div class=\"page_body\">\n";
5410 git_print_log
($co{'comment'});
5413 git_difftree_body
(\
@difftree, $hash, @
$parents);
5419 # object is defined by:
5420 # - hash or hash_base alone
5421 # - hash_base and file_name
5424 # - hash or hash_base alone
5425 if ($hash || ($hash_base && !defined $file_name)) {
5426 my $object_id = $hash || $hash_base;
5428 open my $fd, "-|", quote_command
(
5429 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5430 or die_error
(404, "Object does not exist");
5434 or die_error
(404, "Object does not exist");
5436 # - hash_base and file_name
5437 } elsif ($hash_base && defined $file_name) {
5438 $file_name =~ s
,/+$,,;
5440 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5441 or die_error
(404, "Base object does not exist");
5443 # here errors should not hapen
5444 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5445 or die_error
(500, "Open git-ls-tree failed");
5449 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5450 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5451 die_error
(404, "File or directory for given base does not exist");
5456 die_error
(400, "Not enough information to find object");
5459 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5460 hash
=>$hash, hash_base
=>$hash_base,
5461 file_name
=>$file_name),
5462 -status
=> '302 Found');
5466 my $format = shift || 'html';
5473 # preparing $fd and %diffinfo for git_patchset_body
5475 if (defined $hash_base && defined $hash_parent_base) {
5476 if (defined $file_name) {
5478 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5479 $hash_parent_base, $hash_base,
5480 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5481 or die_error
(500, "Open git-diff-tree failed");
5482 @difftree = map { chomp; $_ } <$fd>;
5484 or die_error
(404, "Reading git-diff-tree failed");
5486 or die_error
(404, "Blob diff not found");
5488 } elsif (defined $hash &&
5489 $hash =~ /[0-9a-fA-F]{40}/) {
5490 # try to find filename from $hash
5492 # read filtered raw output
5493 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5494 $hash_parent_base, $hash_base, "--"
5495 or die_error
(500, "Open git-diff-tree failed");
5497 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5499 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5500 map { chomp; $_ } <$fd>;
5502 or die_error
(404, "Reading git-diff-tree failed");
5504 or die_error
(404, "Blob diff not found");
5507 die_error
(400, "Missing one of the blob diff parameters");
5510 if (@difftree > 1) {
5511 die_error
(400, "Ambiguous blob diff specification");
5514 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5515 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5516 $file_name ||= $diffinfo{'to_file'};
5518 $hash_parent ||= $diffinfo{'from_id'};
5519 $hash ||= $diffinfo{'to_id'};
5521 # non-textual hash id's can be cached
5522 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5523 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5528 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5529 '-p', ($format eq 'html' ?
"--full-index" : ()),
5530 $hash_parent_base, $hash_base,
5531 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5532 or die_error
(500, "Open git-diff-tree failed");
5535 # old/legacy style URI -- not generated anymore since 1.4.3.
5537 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5541 if ($format eq 'html') {
5543 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5545 git_header_html
(undef, $expires);
5546 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5547 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5548 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5550 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5551 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5553 if (defined $file_name) {
5554 git_print_page_path
($file_name, "blob", $hash_base);
5556 print "<div class=\"page_path\"></div>\n";
5559 } elsif ($format eq 'plain') {
5561 -type
=> 'text/plain',
5562 -charset
=> 'utf-8',
5563 -expires
=> $expires,
5564 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5566 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5569 die_error
(400, "Unknown blobdiff format");
5573 if ($format eq 'html') {
5574 print "<div class=\"page_body\">\n";
5576 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5579 print "</div>\n"; # class="page_body"
5583 while (my $line = <$fd>) {
5584 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5585 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5589 last if $line =~ m!^\+\+\+!;
5597 sub git_blobdiff_plain
{
5598 git_blobdiff
('plain');
5601 sub git_commitdiff
{
5603 my $format = $params{-format
} || 'html';
5605 my ($patch_max) = gitweb_get_feature
('patches');
5606 if ($format eq 'patch') {
5607 die_error
(403, "Patch view not allowed") unless $patch_max;
5610 $hash ||= $hash_base || "HEAD";
5611 my %co = parse_commit
($hash)
5612 or die_error
(404, "Unknown commit object");
5614 # choose format for commitdiff for merge
5615 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5616 $hash_parent = '--cc';
5618 # we need to prepare $formats_nav before almost any parameter munging
5620 if ($format eq 'html') {
5622 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5624 if ($patch_max && @
{$co{'parents'}} <= 1) {
5625 $formats_nav .= " | " .
5626 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5630 if (defined $hash_parent &&
5631 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5632 # commitdiff with two commits given
5633 my $hash_parent_short = $hash_parent;
5634 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5635 $hash_parent_short = substr($hash_parent, 0, 7);
5639 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5640 if ($co{'parents'}[$i] eq $hash_parent) {
5641 $formats_nav .= ' parent ' . ($i+1);
5645 $formats_nav .= ': ' .
5646 $cgi->a({-href
=> href
(action
=>"commitdiff",
5647 hash
=>$hash_parent)},
5648 esc_html
($hash_parent_short)) .
5650 } elsif (!$co{'parent'}) {
5652 $formats_nav .= ' (initial)';
5653 } elsif (scalar @
{$co{'parents'}} == 1) {
5654 # single parent commit
5657 $cgi->a({-href
=> href
(action
=>"commitdiff",
5658 hash
=>$co{'parent'})},
5659 esc_html
(substr($co{'parent'}, 0, 7))) .
5663 if ($hash_parent eq '--cc') {
5664 $formats_nav .= ' | ' .
5665 $cgi->a({-href
=> href
(action
=>"commitdiff",
5666 hash
=>$hash, hash_parent
=>'-c')},
5668 } else { # $hash_parent eq '-c'
5669 $formats_nav .= ' | ' .
5670 $cgi->a({-href
=> href
(action
=>"commitdiff",
5671 hash
=>$hash, hash_parent
=>'--cc')},
5677 $cgi->a({-href
=> href
(action
=>"commitdiff",
5679 esc_html
(substr($_, 0, 7)));
5680 } @
{$co{'parents'}} ) .
5685 my $hash_parent_param = $hash_parent;
5686 if (!defined $hash_parent_param) {
5687 # --cc for multiple parents, --root for parentless
5688 $hash_parent_param =
5689 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5695 if ($format eq 'html') {
5696 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5697 "--no-commit-id", "--patch-with-raw", "--full-index",
5698 $hash_parent_param, $hash, "--"
5699 or die_error
(500, "Open git-diff-tree failed");
5701 while (my $line = <$fd>) {
5703 # empty line ends raw part of diff-tree output
5705 push @difftree, scalar parse_difftree_raw_line
($line);
5708 } elsif ($format eq 'plain') {
5709 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5710 '-p', $hash_parent_param, $hash, "--"
5711 or die_error
(500, "Open git-diff-tree failed");
5712 } elsif ($format eq 'patch') {
5713 # For commit ranges, we limit the output to the number of
5714 # patches specified in the 'patches' feature.
5715 # For single commits, we limit the output to a single patch,
5716 # diverging from the git-format-patch default.
5717 my @commit_spec = ();
5719 if ($patch_max > 0) {
5720 push @commit_spec, "-$patch_max";
5722 push @commit_spec, '-n', "$hash_parent..$hash";
5724 if ($params{-single
}) {
5725 push @commit_spec, '-1';
5727 if ($patch_max > 0) {
5728 push @commit_spec, "-$patch_max";
5730 push @commit_spec, "-n";
5732 push @commit_spec, '--root', $hash;
5734 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5735 '--stdout', @commit_spec
5736 or die_error
(500, "Open git-format-patch failed");
5738 die_error
(400, "Unknown commitdiff format");
5741 # non-textual hash id's can be cached
5743 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5747 # write commit message
5748 if ($format eq 'html') {
5749 my $refs = git_get_references
();
5750 my $ref = format_ref_marker
($refs, $co{'id'});
5752 git_header_html
(undef, $expires);
5753 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5754 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5755 print "<div class=\"title_text\">\n" .
5756 "<table class=\"object_header\">\n";
5757 git_print_authorship_rows
(\
%co);
5760 print "<div class=\"page_body\">\n";
5761 if (@
{$co{'comment'}} > 1) {
5762 print "<div class=\"log\">\n";
5763 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5764 print "</div>\n"; # class="log"
5767 } elsif ($format eq 'plain') {
5768 my $refs = git_get_references
("tags");
5769 my $tagname = git_get_rev_name_tags
($hash);
5770 my $filename = basename
($project) . "-$hash.patch";
5773 -type
=> 'text/plain',
5774 -charset
=> 'utf-8',
5775 -expires
=> $expires,
5776 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5777 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5778 print "From: " . to_utf8
($co{'author'}) . "\n";
5779 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5780 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5782 print "X-Git-Tag: $tagname\n" if $tagname;
5783 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5785 foreach my $line (@
{$co{'comment'}}) {
5786 print to_utf8
($line) . "\n";
5789 } elsif ($format eq 'patch') {
5790 my $filename = basename
($project) . "-$hash.patch";
5793 -type
=> 'text/plain',
5794 -charset
=> 'utf-8',
5795 -expires
=> $expires,
5796 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5800 if ($format eq 'html') {
5801 my $use_parents = !defined $hash_parent ||
5802 $hash_parent eq '-c' || $hash_parent eq '--cc';
5803 git_difftree_body
(\
@difftree, $hash,
5804 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5807 git_patchset_body
($fd, \
@difftree, $hash,
5808 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5810 print "</div>\n"; # class="page_body"
5813 } elsif ($format eq 'plain') {
5817 or print "Reading git-diff-tree failed\n";
5818 } elsif ($format eq 'patch') {
5822 or print "Reading git-format-patch failed\n";
5826 sub git_commitdiff_plain
{
5827 git_commitdiff
(-format
=> 'plain');
5830 # format-patch-style patches
5832 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5836 git_commitdiff
(-format
=> 'patch');
5840 if (!defined $hash_base) {
5841 $hash_base = git_get_head_hash
($project);
5843 if (!defined $page) {
5847 my %co = parse_commit
($hash_base)
5848 or die_error
(404, "Unknown commit object");
5850 my $refs = git_get_references
();
5851 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5853 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5854 $file_name, "--full-history")
5855 or die_error
(404, "No such file or directory on given branch");
5857 if (!defined $hash && defined $file_name) {
5858 # some commits could have deleted file in question,
5859 # and not have it in tree, but one of them has to have it
5860 for (my $i = 0; $i <= @commitlist; $i++) {
5861 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5862 last if defined $hash;
5865 if (defined $hash) {
5866 $ftype = git_get_type
($hash);
5868 if (!defined $ftype) {
5869 die_error
(500, "Unknown type of object");
5872 my $paging_nav = '';
5875 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5876 file_name
=>$file_name)},
5878 $paging_nav .= " ⋅ " .
5879 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5880 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5882 $paging_nav .= "first";
5883 $paging_nav .= " ⋅ prev";
5886 if ($#commitlist >= 100) {
5888 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5889 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5890 $paging_nav .= " ⋅ $next_link";
5892 $paging_nav .= " ⋅ next";
5896 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5897 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5898 git_print_page_path
($file_name, $ftype, $hash_base);
5900 git_history_body
(\
@commitlist, 0, 99,
5901 $refs, $hash_base, $ftype, $next_link);
5907 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5908 if (!defined $searchtext) {
5909 die_error
(400, "Text field is empty");
5911 if (!defined $hash) {
5912 $hash = git_get_head_hash
($project);
5914 my %co = parse_commit
($hash);
5916 die_error
(404, "Unknown commit object");
5918 if (!defined $page) {
5922 $searchtype ||= 'commit';
5923 if ($searchtype eq 'pickaxe') {
5924 # pickaxe may take all resources of your box and run for several minutes
5925 # with every query - so decide by yourself how public you make this feature
5926 gitweb_check_feature
('pickaxe')
5927 or die_error
(403, "Pickaxe is disabled");
5929 if ($searchtype eq 'grep') {
5930 gitweb_check_feature
('grep')
5931 or die_error
(403, "Grep is disabled");
5936 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5938 if ($searchtype eq 'commit') {
5939 $greptype = "--grep=";
5940 } elsif ($searchtype eq 'author') {
5941 $greptype = "--author=";
5942 } elsif ($searchtype eq 'committer') {
5943 $greptype = "--committer=";
5945 $greptype .= $searchtext;
5946 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5947 $greptype, '--regexp-ignore-case',
5948 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5950 my $paging_nav = '';
5953 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5954 searchtext
=>$searchtext,
5955 searchtype
=>$searchtype)},
5957 $paging_nav .= " ⋅ " .
5958 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5959 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5961 $paging_nav .= "first";
5962 $paging_nav .= " ⋅ prev";
5965 if ($#commitlist >= 100) {
5967 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5968 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5969 $paging_nav .= " ⋅ $next_link";
5971 $paging_nav .= " ⋅ next";
5974 if ($#commitlist >= 100) {
5977 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5978 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5979 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5982 if ($searchtype eq 'pickaxe') {
5983 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5984 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5986 print "<table class=\"pickaxe search\">\n";
5989 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5990 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5991 ($search_use_regexp ?
'--pickaxe-regex' : ());
5994 while (my $line = <$fd>) {
5998 my %set = parse_difftree_raw_line
($line);
5999 if (defined $set{'commit'}) {
6000 # finish previous commit
6003 "<td class=\"link\">" .
6004 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6006 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6012 print "<tr class=\"dark\">\n";
6014 print "<tr class=\"light\">\n";
6017 %co = parse_commit
($set{'commit'});
6018 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6019 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6020 "<td><i>$author</i></td>\n" .
6022 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6023 -class => "list subject"},
6024 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6025 } elsif (defined $set{'to_id'}) {
6026 next if ($set{'to_id'} =~ m/^0{40}$/);
6028 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6029 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6031 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6037 # finish last commit (warning: repetition!)
6040 "<td class=\"link\">" .
6041 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6043 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6051 if ($searchtype eq 'grep') {
6052 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6053 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6055 print "<table class=\"grep_search\">\n";
6059 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6060 $search_use_regexp ?
('-E', '-i') : '-F',
6061 $searchtext, $co{'tree'};
6063 while (my $line = <$fd>) {
6065 my ($file, $lno, $ltext, $binary);
6066 last if ($matches++ > 1000);
6067 if ($line =~ /^Binary file (.+) matches$/) {
6071 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6073 if ($file ne $lastfile) {
6074 $lastfile and print "</td></tr>\n";
6076 print "<tr class=\"dark\">\n";
6078 print "<tr class=\"light\">\n";
6080 print "<td class=\"list\">".
6081 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6082 file_name
=>"$file"),
6083 -class => "list"}, esc_path
($file));
6084 print "</td><td>\n";
6088 print "<div class=\"binary\">Binary file</div>\n";
6090 $ltext = untabify
($ltext);
6091 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6092 $ltext = esc_html
($1, -nbsp
=>1);
6093 $ltext .= '<span class="match">';
6094 $ltext .= esc_html
($2, -nbsp
=>1);
6095 $ltext .= '</span>';
6096 $ltext .= esc_html
($3, -nbsp
=>1);
6098 $ltext = esc_html
($ltext, -nbsp
=>1);
6100 print "<div class=\"pre\">" .
6101 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6102 file_name
=>"$file").'#l'.$lno,
6103 -class => "linenr"}, sprintf('%4i', $lno))
6104 . ' ' . $ltext . "</div>\n";
6108 print "</td></tr>\n";
6109 if ($matches > 1000) {
6110 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6113 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6122 sub git_search_help
{
6124 git_print_page_nav
('','', $hash,$hash,$hash);
6126 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6127 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6128 the pattern entered is recognized as the POSIX extended
6129 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6132 <dt><b>commit</b></dt>
6133 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6135 my $have_grep = gitweb_check_feature
('grep');
6138 <dt><b>grep</b></dt>
6139 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6140 a different one) are searched for the given pattern. On large trees, this search can take
6141 a while and put some strain on the server, so please use it with some consideration. Note that
6142 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6143 case-sensitive.</dd>
6147 <dt><b>author</b></dt>
6148 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6149 <dt><b>committer</b></dt>
6150 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6152 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6153 if ($have_pickaxe) {
6155 <dt><b>pickaxe</b></dt>
6156 <dd>All commits that caused the string to appear or disappear from any file (changes that
6157 added, removed or "modified" the string) will be listed. This search can take a while and
6158 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6159 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6167 my $head = git_get_head_hash
($project);
6168 if (!defined $hash) {
6171 if (!defined $page) {
6174 my $refs = git_get_references
();
6176 my $commit_hash = $hash;
6177 if (defined $hash_parent) {
6178 $commit_hash = "$hash_parent..$hash";
6180 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6182 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6184 if ($#commitlist >= 100) {
6186 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6187 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6189 my $patch_max = gitweb_check_feature
('patches');
6191 if ($patch_max < 0 || @commitlist <= $patch_max) {
6192 $paging_nav .= " ⋅ " .
6193 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6199 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6200 git_print_header_div
('summary', $project);
6202 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6207 ## ......................................................................
6208 ## feeds (RSS, Atom; OPML)
6211 my $format = shift || 'atom';
6212 my $have_blame = gitweb_check_feature
('blame');
6214 # Atom: http://www.atomenabled.org/developers/syndication/
6215 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6216 if ($format ne 'rss' && $format ne 'atom') {
6217 die_error
(400, "Unknown web feed format");
6220 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6221 my $head = $hash || 'HEAD';
6222 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6226 my $content_type = "application/$format+xml";
6227 if (defined $cgi->http('HTTP_ACCEPT') &&
6228 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6229 # browser (feed reader) prefers text/xml
6230 $content_type = 'text/xml';
6232 if (defined($commitlist[0])) {
6233 %latest_commit = %{$commitlist[0]};
6234 my $latest_epoch = $latest_commit{'committer_epoch'};
6235 %latest_date = parse_date
($latest_epoch);
6236 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6237 if (defined $if_modified) {
6239 if (eval { require HTTP
::Date
; 1; }) {
6240 $since = HTTP
::Date
::str2time
($if_modified);
6241 } elsif (eval { require Time
::ParseDate
; 1; }) {
6242 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6244 if (defined $since && $latest_epoch <= $since) {
6246 -type
=> $content_type,
6247 -charset
=> 'utf-8',
6248 -last_modified
=> $latest_date{'rfc2822'},
6249 -status
=> '304 Not Modified');
6254 -type
=> $content_type,
6255 -charset
=> 'utf-8',
6256 -last_modified
=> $latest_date{'rfc2822'});
6259 -type
=> $content_type,
6260 -charset
=> 'utf-8');
6263 # Optimization: skip generating the body if client asks only
6264 # for Last-Modified date.
6265 return if ($cgi->request_method() eq 'HEAD');
6268 my $title = "$site_name - $project/$action";
6269 my $feed_type = 'log';
6270 if (defined $hash) {
6271 $title .= " - '$hash'";
6272 $feed_type = 'branch log';
6273 if (defined $file_name) {
6274 $title .= " :: $file_name";
6275 $feed_type = 'history';
6277 } elsif (defined $file_name) {
6278 $title .= " - $file_name";
6279 $feed_type = 'history';
6281 $title .= " $feed_type";
6282 my $descr = git_get_project_description
($project);
6283 if (defined $descr) {
6284 $descr = esc_html
($descr);
6286 $descr = "$project " .
6287 ($format eq 'rss' ?
'RSS' : 'Atom') .
6290 my $owner = git_get_project_owner
($project);
6291 $owner = esc_html
($owner);
6295 if (defined $file_name) {
6296 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6297 } elsif (defined $hash) {
6298 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6300 $alt_url = href
(-full
=>1, action
=>"summary");
6302 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6303 if ($format eq 'rss') {
6305 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6308 print "<title>$title</title>\n" .
6309 "<link>$alt_url</link>\n" .
6310 "<description>$descr</description>\n" .
6311 "<language>en</language>\n" .
6312 # project owner is responsible for 'editorial' content
6313 "<managingEditor>$owner</managingEditor>\n";
6314 if (defined $logo || defined $favicon) {
6315 # prefer the logo to the favicon, since RSS
6316 # doesn't allow both
6317 my $img = esc_url
($logo || $favicon);
6319 "<url>$img</url>\n" .
6320 "<title>$title</title>\n" .
6321 "<link>$alt_url</link>\n" .
6325 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6326 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6328 print "<generator>gitweb v.$version/$git_version</generator>\n";
6329 } elsif ($format eq 'atom') {
6331 <feed xmlns="http://www.w3.org/2005/Atom">
6333 print "<title>$title</title>\n" .
6334 "<subtitle>$descr</subtitle>\n" .
6335 '<link rel="alternate" type="text/html" href="' .
6336 $alt_url . '" />' . "\n" .
6337 '<link rel="self" type="' . $content_type . '" href="' .
6338 $cgi->self_url() . '" />' . "\n" .
6339 "<id>" . href
(-full
=>1) . "</id>\n" .
6340 # use project owner for feed author
6341 "<author><name>$owner</name></author>\n";
6342 if (defined $favicon) {
6343 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6345 if (defined $logo_url) {
6346 # not twice as wide as tall: 72 x 27 pixels
6347 print "<logo>" . esc_url
($logo) . "</logo>\n";
6349 if (! %latest_date) {
6350 # dummy date to keep the feed valid until commits trickle in:
6351 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6353 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6355 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6359 for (my $i = 0; $i <= $#commitlist; $i++) {
6360 my %co = %{$commitlist[$i]};
6361 my $commit = $co{'id'};
6362 # we read 150, we always show 30 and the ones more recent than 48 hours
6363 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6366 my %cd = parse_date
($co{'author_epoch'});
6368 # get list of changed files
6369 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6370 $co{'parent'} || "--root",
6371 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6373 my @difftree = map { chomp; $_ } <$fd>;
6377 # print element (entry, item)
6378 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6379 if ($format eq 'rss') {
6381 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6382 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6383 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6384 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6385 "<link>$co_url</link>\n" .
6386 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6387 "<content:encoded>" .
6389 } elsif ($format eq 'atom') {
6391 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6392 "<updated>$cd{'iso-8601'}</updated>\n" .
6394 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6395 if ($co{'author_email'}) {
6396 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6398 print "</author>\n" .
6399 # use committer for contributor
6401 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6402 if ($co{'committer_email'}) {
6403 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6405 print "</contributor>\n" .
6406 "<published>$cd{'iso-8601'}</published>\n" .
6407 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6408 "<id>$co_url</id>\n" .
6409 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6410 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6412 my $comment = $co{'comment'};
6414 foreach my $line (@
$comment) {
6415 $line = esc_html
($line);
6418 print "</pre><ul>\n";
6419 foreach my $difftree_line (@difftree) {
6420 my %difftree = parse_difftree_raw_line
($difftree_line);
6421 next if !$difftree{'from_id'};
6423 my $file = $difftree{'file'} || $difftree{'to_file'};
6427 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6428 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6429 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6430 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6431 -title
=> "diff"}, 'D');
6433 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6434 file_name
=>$file, hash_base
=>$commit),
6435 -title
=> "blame"}, 'B');
6437 # if this is not a feed of a file history
6438 if (!defined $file_name || $file_name ne $file) {
6439 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6440 file_name
=>$file, hash
=>$commit),
6441 -title
=> "history"}, 'H');
6443 $file = esc_path
($file);
6447 if ($format eq 'rss') {
6448 print "</ul>]]>\n" .
6449 "</content:encoded>\n" .
6451 } elsif ($format eq 'atom') {
6452 print "</ul>\n</div>\n" .
6459 if ($format eq 'rss') {
6460 print "</channel>\n</rss>\n";
6461 } elsif ($format eq 'atom') {
6475 my @list = git_get_projects_list
();
6478 -type
=> 'text/xml',
6479 -charset
=> 'utf-8',
6480 -content_disposition
=> 'inline; filename="opml.xml"');
6483 <?xml version="1.0" encoding="utf-8"?>
6484 <opml version="1.0">
6486 <title>$site_name OPML Export</title>
6489 <outline text="git RSS feeds">
6492 foreach my $pr (@list) {
6494 my $head = git_get_head_hash
($proj{'path'});
6495 if (!defined $head) {
6498 $git_dir = "$projectroot/$proj{'path'}";
6499 my %co = parse_commit
($head);
6504 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6505 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6506 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6507 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";