3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31 # needed and used only for URLs with nonempty PATH_INFO
32 our $base_url = $my_url;
34 # When the script is used as DirectoryIndex, the URL does not contain the name
35 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36 # have to do it ourselves. We make $path_info global because it's also used
39 # Another issue with the script being the DirectoryIndex is that the resulting
40 # $my_url data is not the full script URL: this is good, because we want
41 # generated links to keep implying the script name if it wasn't explicitly
42 # indicated in the URL we're handling, but it means that $my_url cannot be used
44 # Therefore, if we needed to strip PATH_INFO, then we know that we have
45 # to build the base URL ourselves:
46 our $path_info = $ENV{"PATH_INFO"};
48 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
49 $my_uri =~ s
,\Q
$path_info\E
$,, &&
50 defined $ENV{'SCRIPT_NAME'}) {
51 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
55 # core git executable to use
56 # this can just be "git" if your webserver has a sensible PATH
57 our $GIT = "++GIT_BINDIR++/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "++GITWEB_PROJECTROOT++";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
67 # target of the home link on top of all pages
68 our $home_link = $my_uri || "/";
70 # string of the home link on top of all pages
71 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
73 # name of your site or organization to appear in page titles
74 # replace this with something more descriptive for clearer bookmarks
75 our $site_name = "++GITWEB_SITENAME++"
76 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 # filename of html text to include at top of each page
79 our $site_header = "++GITWEB_SITE_HEADER++";
80 # html text to include at home page
81 our $home_text = "++GITWEB_HOMETEXT++";
82 # filename of html text to include at bottom of each page
83 our $site_footer = "++GITWEB_SITE_FOOTER++";
86 our @stylesheets = ("++GITWEB_CSS++");
87 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
88 our $stylesheet = undef;
89 # URI of GIT logo (72x27 size)
90 our $logo = "++GITWEB_LOGO++";
91 # URI of GIT favicon, assumed to be image/png type
92 our $favicon = "++GITWEB_FAVICON++";
94 # URI and label (title) of GIT logo link
95 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
96 #our $logo_label = "git documentation";
97 our $logo_url = "http://git-scm.com/";
98 our $logo_label = "git homepage";
100 # source of projects list
101 our $projects_list = "++GITWEB_LIST++";
103 # the width (in characters) of the projects list "Description" column
104 our $projects_list_description_width = 25;
106 # default order of projects list
107 # valid values are none, project, descr, owner, and age
108 our $default_projects_order = "project";
110 # show repository only if this file exists
111 # (only effective if this variable evaluates to true)
112 our $export_ok = "++GITWEB_EXPORT_OK++";
114 # show repository only if this subroutine returns true
115 # when given the path to the project, for example:
116 # sub { return -e "$_[0]/git-daemon-export-ok"; }
117 our $export_auth_hook = undef;
119 # only allow viewing of repositories also shown on the overview page
120 our $strict_export = "++GITWEB_STRICT_EXPORT++";
122 # list of git base URLs used for URL to where fetch project from,
123 # i.e. full URL is "$git_base_url/$project"
124 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
126 # default blob_plain mimetype and default charset for text/plain blob
127 our $default_blob_plain_mimetype = 'text/plain';
128 our $default_text_plain_charset = undef;
130 # file to use for guessing MIME types before trying /etc/mime.types
131 # (relative to the current git repository)
132 our $mimetypes_file = undef;
134 # assume this charset if line contains non-UTF-8 characters;
135 # it should be valid encoding (see Encoding::Supported(3pm) for list),
136 # for which encoding all byte sequences are valid, for example
137 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
138 # could be even 'utf-8' for the old behavior)
139 our $fallback_encoding = 'latin1';
141 # rename detection options for git-diff and git-diff-tree
142 # - default is '-M', with the cost proportional to
143 # (number of removed files) * (number of new files).
144 # - more costly is '-C' (which implies '-M'), with the cost proportional to
145 # (number of changed files + number of removed files) * (number of new files)
146 # - even more costly is '-C', '--find-copies-harder' with cost
147 # (number of files in the original tree) * (number of new files)
148 # - one might want to include '-B' option, e.g. '-B', '-M'
149 our @diff_opts = ('-M'); # taken from git_commit
151 # Disables features that would allow repository owners to inject script into
153 our $prevent_xss = 0;
155 # information about snapshot formats that gitweb is capable of serving
156 our %known_snapshot_formats = (
158 # 'display' => display name,
159 # 'type' => mime type,
160 # 'suffix' => filename suffix,
161 # 'format' => --format for git-archive,
162 # 'compressor' => [compressor command and arguments]
163 # (array reference, optional)
164 # 'disabled' => boolean (optional)}
167 'display' => 'tar.gz',
168 'type' => 'application/x-gzip',
169 'suffix' => '.tar.gz',
171 'compressor' => ['gzip']},
174 'display' => 'tar.bz2',
175 'type' => 'application/x-bzip2',
176 'suffix' => '.tar.bz2',
178 'compressor' => ['bzip2']},
181 'display' => 'tar.xz',
182 'type' => 'application/x-xz',
183 'suffix' => '.tar.xz',
185 'compressor' => ['xz'],
190 'type' => 'application/x-zip',
195 # Aliases so we understand old gitweb.snapshot values in repository
197 our %known_snapshot_format_aliases = (
202 # backward compatibility: legacy gitweb config support
203 'x-gzip' => undef, 'gz' => undef,
204 'x-bzip2' => undef, 'bz2' => undef,
205 'x-zip' => undef, '' => undef,
208 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
209 # are changed, it may be appropriate to change these values too via
216 # You define site-wide feature defaults here; override them with
217 # $GITWEB_CONFIG as necessary.
220 # 'sub' => feature-sub (subroutine),
221 # 'override' => allow-override (boolean),
222 # 'default' => [ default options...] (array reference)}
224 # if feature is overridable (it means that allow-override has true value),
225 # then feature-sub will be called with default options as parameters;
226 # return value of feature-sub indicates if to enable specified feature
228 # if there is no 'sub' key (no feature-sub), then feature cannot be
231 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
232 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
235 # Enable the 'blame' blob view, showing the last commit that modified
236 # each line in the file. This can be very CPU-intensive.
238 # To enable system wide have in $GITWEB_CONFIG
239 # $feature{'blame'}{'default'} = [1];
240 # To have project specific config enable override in $GITWEB_CONFIG
241 # $feature{'blame'}{'override'} = 1;
242 # and in project config gitweb.blame = 0|1;
244 'sub' => sub { feature_bool
('blame', @_) },
248 # Enable the 'snapshot' link, providing a compressed archive of any
249 # tree. This can potentially generate high traffic if you have large
252 # Value is a list of formats defined in %known_snapshot_formats that
254 # To disable system wide have in $GITWEB_CONFIG
255 # $feature{'snapshot'}{'default'} = [];
256 # To have project specific config enable override in $GITWEB_CONFIG
257 # $feature{'snapshot'}{'override'} = 1;
258 # and in project config, a comma-separated list of formats or "none"
259 # to disable. Example: gitweb.snapshot = tbz2,zip;
261 'sub' => \
&feature_snapshot
,
263 'default' => ['tgz']},
265 # Enable text search, which will list the commits which match author,
266 # committer or commit text to a given string. Enabled by default.
267 # Project specific override is not supported.
272 # Enable grep search, which will list the files in currently selected
273 # tree containing the given string. Enabled by default. This can be
274 # potentially CPU-intensive, of course.
276 # To enable system wide have in $GITWEB_CONFIG
277 # $feature{'grep'}{'default'} = [1];
278 # To have project specific config enable override in $GITWEB_CONFIG
279 # $feature{'grep'}{'override'} = 1;
280 # and in project config gitweb.grep = 0|1;
282 'sub' => sub { feature_bool
('grep', @_) },
286 # Enable the pickaxe search, which will list the commits that modified
287 # a given string in a file. This can be practical and quite faster
288 # alternative to 'blame', but still potentially CPU-intensive.
290 # To enable system wide have in $GITWEB_CONFIG
291 # $feature{'pickaxe'}{'default'} = [1];
292 # To have project specific config enable override in $GITWEB_CONFIG
293 # $feature{'pickaxe'}{'override'} = 1;
294 # and in project config gitweb.pickaxe = 0|1;
296 'sub' => sub { feature_bool
('pickaxe', @_) },
300 # Enable showing size of blobs in a 'tree' view, in a separate
301 # column, similar to what 'ls -l' does. This cost a bit of IO.
303 # To disable system wide have in $GITWEB_CONFIG
304 # $feature{'show-sizes'}{'default'} = [0];
305 # To have project specific config enable override in $GITWEB_CONFIG
306 # $feature{'show-sizes'}{'override'} = 1;
307 # and in project config gitweb.showsizes = 0|1;
309 'sub' => sub { feature_bool
('showsizes', @_) },
313 # Make gitweb use an alternative format of the URLs which can be
314 # more readable and natural-looking: project name is embedded
315 # directly in the path and the query string contains other
316 # auxiliary information. All gitweb installations recognize
317 # URL in either format; this configures in which formats gitweb
320 # To enable system wide have in $GITWEB_CONFIG
321 # $feature{'pathinfo'}{'default'} = [1];
322 # Project specific override is not supported.
324 # Note that you will need to change the default location of CSS,
325 # favicon, logo and possibly other files to an absolute URL. Also,
326 # if gitweb.cgi serves as your indexfile, you will need to force
327 # $my_uri to contain the script name in your $GITWEB_CONFIG.
332 # Make gitweb consider projects in project root subdirectories
333 # to be forks of existing projects. Given project $projname.git,
334 # projects matching $projname/*.git will not be shown in the main
335 # projects list, instead a '+' mark will be added to $projname
336 # there and a 'forks' view will be enabled for the project, listing
337 # all the forks. If project list is taken from a file, forks have
338 # to be listed after the main project.
340 # To enable system wide have in $GITWEB_CONFIG
341 # $feature{'forks'}{'default'} = [1];
342 # Project specific override is not supported.
347 # Insert custom links to the action bar of all project pages.
348 # This enables you mainly to link to third-party scripts integrating
349 # into gitweb; e.g. git-browser for graphical history representation
350 # or custom web-based repository administration interface.
352 # The 'default' value consists of a list of triplets in the form
353 # (label, link, position) where position is the label after which
354 # to insert the link and link is a format string where %n expands
355 # to the project name, %f to the project path within the filesystem,
356 # %h to the current hash (h gitweb parameter) and %b to the current
357 # hash base (hb gitweb parameter); %% expands to %.
359 # To enable system wide have in $GITWEB_CONFIG e.g.
360 # $feature{'actions'}{'default'} = [('graphiclog',
361 # '/git-browser/by-commit.html?r=%n', 'summary')];
362 # Project specific override is not supported.
367 # Allow gitweb scan project content tags described in ctags/
368 # of project repository, and display the popular Web 2.0-ish
369 # "tag cloud" near the project list. Note that this is something
370 # COMPLETELY different from the normal Git tags.
372 # gitweb by itself can show existing tags, but it does not handle
373 # tagging itself; you need an external application for that.
374 # For an example script, check Girocco's cgi/tagproj.cgi.
375 # You may want to install the HTML::TagCloud Perl module to get
376 # a pretty tag cloud instead of just a list of tags.
378 # To enable system wide have in $GITWEB_CONFIG
379 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
380 # Project specific override is not supported.
385 # The maximum number of patches in a patchset generated in patch
386 # view. Set this to 0 or undef to disable patch view, or to a
387 # negative number to remove any limit.
389 # To disable system wide have in $GITWEB_CONFIG
390 # $feature{'patches'}{'default'} = [0];
391 # To have project specific config enable override in $GITWEB_CONFIG
392 # $feature{'patches'}{'override'} = 1;
393 # and in project config gitweb.patches = 0|n;
394 # where n is the maximum number of patches allowed in a patchset.
396 'sub' => \
&feature_patches
,
400 # Avatar support. When this feature is enabled, views such as
401 # shortlog or commit will display an avatar associated with
402 # the email of the committer(s) and/or author(s).
404 # Currently available providers are gravatar and picon.
405 # If an unknown provider is specified, the feature is disabled.
407 # Gravatar depends on Digest::MD5.
408 # Picon currently relies on the indiana.edu database.
410 # To enable system wide have in $GITWEB_CONFIG
411 # $feature{'avatar'}{'default'} = ['<provider>'];
412 # where <provider> is either gravatar or picon.
413 # To have project specific config enable override in $GITWEB_CONFIG
414 # $feature{'avatar'}{'override'} = 1;
415 # and in project config gitweb.avatar = <provider>;
417 'sub' => \
&feature_avatar
,
422 sub gitweb_get_feature
{
424 return unless exists $feature{$name};
425 my ($sub, $override, @defaults) = (
426 $feature{$name}{'sub'},
427 $feature{$name}{'override'},
428 @
{$feature{$name}{'default'}});
429 if (!$override) { return @defaults; }
431 warn "feature $name is not overridable";
434 return $sub->(@defaults);
437 # A wrapper to check if a given feature is enabled.
438 # With this, you can say
440 # my $bool_feat = gitweb_check_feature('bool_feat');
441 # gitweb_check_feature('bool_feat') or somecode;
445 # my ($bool_feat) = gitweb_get_feature('bool_feat');
446 # (gitweb_get_feature('bool_feat'))[0] or somecode;
448 sub gitweb_check_feature
{
449 return (gitweb_get_feature
(@_))[0];
455 my ($val) = git_get_project_config
($key, '--bool');
459 } elsif ($val eq 'true') {
461 } elsif ($val eq 'false') {
466 sub feature_snapshot
{
469 my ($val) = git_get_project_config
('snapshot');
472 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
478 sub feature_patches
{
479 my @val = (git_get_project_config
('patches', '--int'));
489 my @val = (git_get_project_config
('avatar'));
491 return @val ?
@val : @_;
494 # checking HEAD file with -e is fragile if the repository was
495 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
497 sub check_head_link
{
499 my $headfile = "$dir/HEAD";
500 return ((-e
$headfile) ||
501 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
504 sub check_export_ok
{
506 return (check_head_link
($dir) &&
507 (!$export_ok || -e
"$dir/$export_ok") &&
508 (!$export_auth_hook || $export_auth_hook->($dir)));
511 # process alternate names for backward compatibility
512 # filter out unsupported (unknown) snapshot formats
513 sub filter_snapshot_fmts
{
517 exists $known_snapshot_format_aliases{$_} ?
518 $known_snapshot_format_aliases{$_} : $_} @fmts;
520 exists $known_snapshot_formats{$_} &&
521 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
524 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
525 if (-e
$GITWEB_CONFIG) {
528 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
529 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
532 # version of the core git binary
533 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
535 $projects_list ||= $projectroot;
537 # ======================================================================
538 # input validation and dispatch
540 # input parameters can be collected from a variety of sources (presently, CGI
541 # and PATH_INFO), so we define an %input_params hash that collects them all
542 # together during validation: this allows subsequent uses (e.g. href()) to be
543 # agnostic of the parameter origin
545 our %input_params = ();
547 # input parameters are stored with the long parameter name as key. This will
548 # also be used in the href subroutine to convert parameters to their CGI
549 # equivalent, and since the href() usage is the most frequent one, we store
550 # the name -> CGI key mapping here, instead of the reverse.
552 # XXX: Warning: If you touch this, check the search form for updating,
555 our @cgi_param_mapping = (
563 hash_parent_base
=> "hpb",
568 snapshot_format
=> "sf",
569 extra_options
=> "opt",
570 search_use_regexp
=> "sr",
572 our %cgi_param_mapping = @cgi_param_mapping;
574 # we will also need to know the possible actions, for validation
576 "blame" => \
&git_blame
,
577 "blobdiff" => \
&git_blobdiff
,
578 "blobdiff_plain" => \
&git_blobdiff_plain
,
579 "blob" => \
&git_blob
,
580 "blob_plain" => \
&git_blob_plain
,
581 "commitdiff" => \
&git_commitdiff
,
582 "commitdiff_plain" => \
&git_commitdiff_plain
,
583 "commit" => \
&git_commit
,
584 "forks" => \
&git_forks
,
585 "heads" => \
&git_heads
,
586 "history" => \
&git_history
,
588 "patch" => \
&git_patch
,
589 "patches" => \
&git_patches
,
591 "atom" => \
&git_atom
,
592 "search" => \
&git_search
,
593 "search_help" => \
&git_search_help
,
594 "shortlog" => \
&git_shortlog
,
595 "summary" => \
&git_summary
,
597 "tags" => \
&git_tags
,
598 "tree" => \
&git_tree
,
599 "snapshot" => \
&git_snapshot
,
600 "object" => \
&git_object
,
601 # those below don't need $project
602 "opml" => \
&git_opml
,
603 "project_list" => \
&git_project_list
,
604 "project_index" => \
&git_project_index
,
607 # finally, we have the hash of allowed extra_options for the commands that
609 our %allowed_options = (
610 "--no-merges" => [ qw(rss atom log shortlog history) ],
613 # fill %input_params with the CGI parameters. All values except for 'opt'
614 # should be single values, but opt can be an array. We should probably
615 # build an array of parameters that can be multi-valued, but since for the time
616 # being it's only this one, we just single it out
617 while (my ($name, $symbol) = each %cgi_param_mapping) {
618 if ($symbol eq 'opt') {
619 $input_params{$name} = [ $cgi->param($symbol) ];
621 $input_params{$name} = $cgi->param($symbol);
625 # now read PATH_INFO and update the parameter list for missing parameters
626 sub evaluate_path_info
{
627 return if defined $input_params{'project'};
628 return if !$path_info;
629 $path_info =~ s
,^/+,,;
630 return if !$path_info;
632 # find which part of PATH_INFO is project
633 my $project = $path_info;
635 while ($project && !check_head_link
("$projectroot/$project")) {
636 $project =~ s
,/*[^/]*$,,;
638 return unless $project;
639 $input_params{'project'} = $project;
641 # do not change any parameters if an action is given using the query string
642 return if $input_params{'action'};
643 $path_info =~ s
,^\Q
$project\E
/*,,;
645 # next, check if we have an action
646 my $action = $path_info;
648 if (exists $actions{$action}) {
649 $path_info =~ s
,^$action/*,,;
650 $input_params{'action'} = $action;
653 # list of actions that want hash_base instead of hash, but can have no
654 # pathname (f) parameter
661 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
662 my ($parentrefname, $parentpathname, $refname, $pathname) =
663 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
665 # first, analyze the 'current' part
666 if (defined $pathname) {
667 # we got "branch:filename" or "branch:dir/"
668 # we could use git_get_type(branch:pathname), but:
669 # - it needs $git_dir
670 # - it does a git() call
671 # - the convention of terminating directories with a slash
672 # makes it superfluous
673 # - embedding the action in the PATH_INFO would make it even
675 $pathname =~ s
,^/+,,;
676 if (!$pathname || substr($pathname, -1) eq "/") {
677 $input_params{'action'} ||= "tree";
680 # the default action depends on whether we had parent info
682 if ($parentrefname) {
683 $input_params{'action'} ||= "blobdiff_plain";
685 $input_params{'action'} ||= "blob_plain";
688 $input_params{'hash_base'} ||= $refname;
689 $input_params{'file_name'} ||= $pathname;
690 } elsif (defined $refname) {
691 # we got "branch". In this case we have to choose if we have to
692 # set hash or hash_base.
694 # Most of the actions without a pathname only want hash to be
695 # set, except for the ones specified in @wants_base that want
696 # hash_base instead. It should also be noted that hand-crafted
697 # links having 'history' as an action and no pathname or hash
698 # set will fail, but that happens regardless of PATH_INFO.
699 $input_params{'action'} ||= "shortlog";
700 if (grep { $_ eq $input_params{'action'} } @wants_base) {
701 $input_params{'hash_base'} ||= $refname;
703 $input_params{'hash'} ||= $refname;
707 # next, handle the 'parent' part, if present
708 if (defined $parentrefname) {
709 # a missing pathspec defaults to the 'current' filename, allowing e.g.
710 # someproject/blobdiff/oldrev..newrev:/filename
711 if ($parentpathname) {
712 $parentpathname =~ s
,^/+,,;
713 $parentpathname =~ s
,/$,,;
714 $input_params{'file_parent'} ||= $parentpathname;
716 $input_params{'file_parent'} ||= $input_params{'file_name'};
718 # we assume that hash_parent_base is wanted if a path was specified,
719 # or if the action wants hash_base instead of hash
720 if (defined $input_params{'file_parent'} ||
721 grep { $_ eq $input_params{'action'} } @wants_base) {
722 $input_params{'hash_parent_base'} ||= $parentrefname;
724 $input_params{'hash_parent'} ||= $parentrefname;
728 # for the snapshot action, we allow URLs in the form
729 # $project/snapshot/$hash.ext
730 # where .ext determines the snapshot and gets removed from the
731 # passed $refname to provide the $hash.
733 # To be able to tell that $refname includes the format extension, we
734 # require the following two conditions to be satisfied:
735 # - the hash input parameter MUST have been set from the $refname part
736 # of the URL (i.e. they must be equal)
737 # - the snapshot format MUST NOT have been defined already (e.g. from
739 # It's also useless to try any matching unless $refname has a dot,
740 # so we check for that too
741 if (defined $input_params{'action'} &&
742 $input_params{'action'} eq 'snapshot' &&
743 defined $refname && index($refname, '.') != -1 &&
744 $refname eq $input_params{'hash'} &&
745 !defined $input_params{'snapshot_format'}) {
746 # We loop over the known snapshot formats, checking for
747 # extensions. Allowed extensions are both the defined suffix
748 # (which includes the initial dot already) and the snapshot
749 # format key itself, with a prepended dot
750 while (my ($fmt, $opt) = each %known_snapshot_formats) {
752 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
756 # a valid suffix was found, so set the snapshot format
757 # and reset the hash parameter
758 $input_params{'snapshot_format'} = $fmt;
759 $input_params{'hash'} = $hash;
760 # we also set the format suffix to the one requested
761 # in the URL: this way a request for e.g. .tgz returns
762 # a .tgz instead of a .tar.gz
763 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
768 evaluate_path_info
();
770 our $action = $input_params{'action'};
771 if (defined $action) {
772 if (!validate_action
($action)) {
773 die_error
(400, "Invalid action parameter");
777 # parameters which are pathnames
778 our $project = $input_params{'project'};
779 if (defined $project) {
780 if (!validate_project
($project)) {
782 die_error
(404, "No such project");
786 our $file_name = $input_params{'file_name'};
787 if (defined $file_name) {
788 if (!validate_pathname
($file_name)) {
789 die_error
(400, "Invalid file parameter");
793 our $file_parent = $input_params{'file_parent'};
794 if (defined $file_parent) {
795 if (!validate_pathname
($file_parent)) {
796 die_error
(400, "Invalid file parent parameter");
800 # parameters which are refnames
801 our $hash = $input_params{'hash'};
803 if (!validate_refname
($hash)) {
804 die_error
(400, "Invalid hash parameter");
808 our $hash_parent = $input_params{'hash_parent'};
809 if (defined $hash_parent) {
810 if (!validate_refname
($hash_parent)) {
811 die_error
(400, "Invalid hash parent parameter");
815 our $hash_base = $input_params{'hash_base'};
816 if (defined $hash_base) {
817 if (!validate_refname
($hash_base)) {
818 die_error
(400, "Invalid hash base parameter");
822 our @extra_options = @
{$input_params{'extra_options'}};
823 # @extra_options is always defined, since it can only be (currently) set from
824 # CGI, and $cgi->param() returns the empty array in array context if the param
826 foreach my $opt (@extra_options) {
827 if (not exists $allowed_options{$opt}) {
828 die_error
(400, "Invalid option parameter");
830 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
831 die_error
(400, "Invalid option parameter for this action");
835 our $hash_parent_base = $input_params{'hash_parent_base'};
836 if (defined $hash_parent_base) {
837 if (!validate_refname
($hash_parent_base)) {
838 die_error
(400, "Invalid hash parent base parameter");
843 our $page = $input_params{'page'};
845 if ($page =~ m/[^0-9]/) {
846 die_error
(400, "Invalid page parameter");
850 our $searchtype = $input_params{'searchtype'};
851 if (defined $searchtype) {
852 if ($searchtype =~ m/[^a-z]/) {
853 die_error
(400, "Invalid searchtype parameter");
857 our $search_use_regexp = $input_params{'search_use_regexp'};
859 our $searchtext = $input_params{'searchtext'};
861 if (defined $searchtext) {
862 if (length($searchtext) < 2) {
863 die_error
(403, "At least two characters are required for search parameter");
865 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
868 # path to the current git repository
870 $git_dir = "$projectroot/$project" if $project;
872 # list of supported snapshot formats
873 our @snapshot_fmts = gitweb_get_feature
('snapshot');
874 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
876 # check that the avatar feature is set to a known provider name,
877 # and for each provider check if the dependencies are satisfied.
878 # if the provider name is invalid or the dependencies are not met,
879 # reset $git_avatar to the empty string.
880 our ($git_avatar) = gitweb_get_feature
('avatar');
881 if ($git_avatar eq 'gravatar') {
882 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
883 } elsif ($git_avatar eq 'picon') {
890 if (!defined $action) {
892 $action = git_get_type
($hash);
893 } elsif (defined $hash_base && defined $file_name) {
894 $action = git_get_type
("$hash_base:$file_name");
895 } elsif (defined $project) {
898 $action = 'project_list';
901 if (!defined($actions{$action})) {
902 die_error
(400, "Unknown action");
904 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
906 die_error
(400, "Project needed");
908 $actions{$action}->();
911 ## ======================================================================
916 # default is to use -absolute url() i.e. $my_uri
917 my $href = $params{-full
} ?
$my_url : $my_uri;
919 $params{'project'} = $project unless exists $params{'project'};
921 if ($params{-replay
}) {
922 while (my ($name, $symbol) = each %cgi_param_mapping) {
923 if (!exists $params{$name}) {
924 $params{$name} = $input_params{$name};
929 my $use_pathinfo = gitweb_check_feature
('pathinfo');
930 if ($use_pathinfo and defined $params{'project'}) {
931 # try to put as many parameters as possible in PATH_INFO:
934 # - hash_parent or hash_parent_base:/file_parent
935 # - hash or hash_base:/filename
936 # - the snapshot_format as an appropriate suffix
938 # When the script is the root DirectoryIndex for the domain,
939 # $href here would be something like http://gitweb.example.com/
940 # Thus, we strip any trailing / from $href, to spare us double
941 # slashes in the final URL
944 # Then add the project name, if present
945 $href .= "/".esc_url
($params{'project'});
946 delete $params{'project'};
948 # since we destructively absorb parameters, we keep this
949 # boolean that remembers if we're handling a snapshot
950 my $is_snapshot = $params{'action'} eq 'snapshot';
952 # Summary just uses the project path URL, any other action is
954 if (defined $params{'action'}) {
955 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
956 delete $params{'action'};
959 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
960 # stripping nonexistent or useless pieces
961 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
962 || $params{'hash_parent'} || $params{'hash'});
963 if (defined $params{'hash_base'}) {
964 if (defined $params{'hash_parent_base'}) {
965 $href .= esc_url
($params{'hash_parent_base'});
966 # skip the file_parent if it's the same as the file_name
967 if (defined $params{'file_parent'}) {
968 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
969 delete $params{'file_parent'};
970 } elsif ($params{'file_parent'} !~ /\.\./) {
971 $href .= ":/".esc_url
($params{'file_parent'});
972 delete $params{'file_parent'};
976 delete $params{'hash_parent'};
977 delete $params{'hash_parent_base'};
978 } elsif (defined $params{'hash_parent'}) {
979 $href .= esc_url
($params{'hash_parent'}). "..";
980 delete $params{'hash_parent'};
983 $href .= esc_url
($params{'hash_base'});
984 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
985 $href .= ":/".esc_url
($params{'file_name'});
986 delete $params{'file_name'};
988 delete $params{'hash'};
989 delete $params{'hash_base'};
990 } elsif (defined $params{'hash'}) {
991 $href .= esc_url
($params{'hash'});
992 delete $params{'hash'};
995 # If the action was a snapshot, we can absorb the
996 # snapshot_format parameter too
998 my $fmt = $params{'snapshot_format'};
999 # snapshot_format should always be defined when href()
1000 # is called, but just in case some code forgets, we
1001 # fall back to the default
1002 $fmt ||= $snapshot_fmts[0];
1003 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1004 delete $params{'snapshot_format'};
1008 # now encode the parameters explicitly
1010 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1011 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1012 if (defined $params{$name}) {
1013 if (ref($params{$name}) eq "ARRAY") {
1014 foreach my $par (@
{$params{$name}}) {
1015 push @result, $symbol . "=" . esc_param
($par);
1018 push @result, $symbol . "=" . esc_param
($params{$name});
1022 $href .= "?" . join(';', @result) if scalar @result;
1028 ## ======================================================================
1029 ## validation, quoting/unquoting and escaping
1031 sub validate_action
{
1032 my $input = shift || return undef;
1033 return undef unless exists $actions{$input};
1037 sub validate_project
{
1038 my $input = shift || return undef;
1039 if (!validate_pathname
($input) ||
1040 !(-d
"$projectroot/$input") ||
1041 !check_export_ok
("$projectroot/$input") ||
1042 ($strict_export && !project_in_list
($input))) {
1049 sub validate_pathname
{
1050 my $input = shift || return undef;
1052 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1053 # at the beginning, at the end, and between slashes.
1054 # also this catches doubled slashes
1055 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1058 # no null characters
1059 if ($input =~ m!\0!) {
1065 sub validate_refname
{
1066 my $input = shift || return undef;
1068 # textual hashes are O.K.
1069 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1072 # it must be correct pathname
1073 $input = validate_pathname
($input)
1075 # restrictions on ref name according to git-check-ref-format
1076 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1082 # decode sequences of octets in utf8 into Perl's internal form,
1083 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1084 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1087 if (utf8
::valid
($str)) {
1091 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1095 # quote unsafe chars, but keep the slash, even when it's not
1096 # correct, but quoted slashes look too horrible in bookmarks
1099 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1104 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1107 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1113 # replace invalid utf8 character with SUBSTITUTION sequence
1118 $str = to_utf8
($str);
1119 $str = $cgi->escapeHTML($str);
1120 if ($opts{'-nbsp'}) {
1121 $str =~ s/ / /g;
1123 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1127 # quote control characters and escape filename to HTML
1132 $str = to_utf8
($str);
1133 $str = $cgi->escapeHTML($str);
1134 if ($opts{'-nbsp'}) {
1135 $str =~ s/ / /g;
1137 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1141 # Make control characters "printable", using character escape codes (CEC)
1145 my %es = ( # character escape codes, aka escape sequences
1146 "\t" => '\t', # tab (HT)
1147 "\n" => '\n', # line feed (LF)
1148 "\r" => '\r', # carrige return (CR)
1149 "\f" => '\f', # form feed (FF)
1150 "\b" => '\b', # backspace (BS)
1151 "\a" => '\a', # alarm (bell) (BEL)
1152 "\e" => '\e', # escape (ESC)
1153 "\013" => '\v', # vertical tab (VT)
1154 "\000" => '\0', # nul character (NUL)
1156 my $chr = ( (exists $es{$cntrl})
1158 : sprintf('\%2x', ord($cntrl)) );
1159 if ($opts{-nohtml
}) {
1162 return "<span class=\"cntrl\">$chr</span>";
1166 # Alternatively use unicode control pictures codepoints,
1167 # Unicode "printable representation" (PR)
1172 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1173 if ($opts{-nohtml
}) {
1176 return "<span class=\"cntrl\">$chr</span>";
1180 # git may return quoted and escaped filenames
1186 my %es = ( # character escape codes, aka escape sequences
1187 't' => "\t", # tab (HT, TAB)
1188 'n' => "\n", # newline (NL)
1189 'r' => "\r", # return (CR)
1190 'f' => "\f", # form feed (FF)
1191 'b' => "\b", # backspace (BS)
1192 'a' => "\a", # alarm (bell) (BEL)
1193 'e' => "\e", # escape (ESC)
1194 'v' => "\013", # vertical tab (VT)
1197 if ($seq =~ m/^[0-7]{1,3}$/) {
1198 # octal char sequence
1199 return chr(oct($seq));
1200 } elsif (exists $es{$seq}) {
1201 # C escape sequence, aka character escape code
1204 # quoted ordinary character
1208 if ($str =~ m/^"(.*)"$/) {
1211 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1216 # escape tabs (convert tabs to spaces)
1220 while ((my $pos = index($line, "\t")) != -1) {
1221 if (my $count = (8 - ($pos % 8))) {
1222 my $spaces = ' ' x
$count;
1223 $line =~ s/\t/$spaces/;
1230 sub project_in_list
{
1231 my $project = shift;
1232 my @list = git_get_projects_list
();
1233 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1236 ## ----------------------------------------------------------------------
1237 ## HTML aware string manipulation
1239 # Try to chop given string on a word boundary between position
1240 # $len and $len+$add_len. If there is no word boundary there,
1241 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1242 # (marking chopped part) would be longer than given string.
1246 my $add_len = shift || 10;
1247 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1249 # Make sure perl knows it is utf8 encoded so we don't
1250 # cut in the middle of a utf8 multibyte char.
1251 $str = to_utf8
($str);
1253 # allow only $len chars, but don't cut a word if it would fit in $add_len
1254 # if it doesn't fit, cut it if it's still longer than the dots we would add
1255 # remove chopped character entities entirely
1257 # when chopping in the middle, distribute $len into left and right part
1258 # return early if chopping wouldn't make string shorter
1259 if ($where eq 'center') {
1260 return $str if ($len + 5 >= length($str)); # filler is length 5
1263 return $str if ($len + 4 >= length($str)); # filler is length 4
1266 # regexps: ending and beginning with word part up to $add_len
1267 my $endre = qr/.{$len}\w{0,$add_len}/;
1268 my $begre = qr/\w{0,$add_len}.{$len}/;
1270 if ($where eq 'left') {
1271 $str =~ m/^(.*?)($begre)$/;
1272 my ($lead, $body) = ($1, $2);
1273 if (length($lead) > 4) {
1274 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1277 return "$lead$body";
1279 } elsif ($where eq 'center') {
1280 $str =~ m/^($endre)(.*)$/;
1281 my ($left, $str) = ($1, $2);
1282 $str =~ m/^(.*?)($begre)$/;
1283 my ($mid, $right) = ($1, $2);
1284 if (length($mid) > 5) {
1285 $left =~ s/&[^;]*$//;
1286 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1289 return "$left$mid$right";
1292 $str =~ m/^($endre)(.*)$/;
1295 if (length($tail) > 4) {
1296 $body =~ s/&[^;]*$//;
1299 return "$body$tail";
1303 # takes the same arguments as chop_str, but also wraps a <span> around the
1304 # result with a title attribute if it does get chopped. Additionally, the
1305 # string is HTML-escaped.
1306 sub chop_and_escape_str
{
1309 my $chopped = chop_str
(@_);
1310 if ($chopped eq $str) {
1311 return esc_html
($chopped);
1313 $str =~ s/[[:cntrl:]]/?/g;
1314 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1318 ## ----------------------------------------------------------------------
1319 ## functions returning short strings
1321 # CSS class for given age value (in seconds)
1325 if (!defined $age) {
1327 } elsif ($age < 60*60*2) {
1329 } elsif ($age < 60*60*24*2) {
1336 # convert age in seconds to "nn units ago" string
1341 if ($age > 60*60*24*365*2) {
1342 $age_str = (int $age/60/60/24/365);
1343 $age_str .= " years ago";
1344 } elsif ($age > 60*60*24*(365/12)*2) {
1345 $age_str = int $age/60/60/24/(365/12);
1346 $age_str .= " months ago";
1347 } elsif ($age > 60*60*24*7*2) {
1348 $age_str = int $age/60/60/24/7;
1349 $age_str .= " weeks ago";
1350 } elsif ($age > 60*60*24*2) {
1351 $age_str = int $age/60/60/24;
1352 $age_str .= " days ago";
1353 } elsif ($age > 60*60*2) {
1354 $age_str = int $age/60/60;
1355 $age_str .= " hours ago";
1356 } elsif ($age > 60*2) {
1357 $age_str = int $age/60;
1358 $age_str .= " min ago";
1359 } elsif ($age > 2) {
1360 $age_str = int $age;
1361 $age_str .= " sec ago";
1363 $age_str .= " right now";
1369 S_IFINVALID
=> 0030000,
1370 S_IFGITLINK
=> 0160000,
1373 # submodule/subproject, a commit object reference
1377 return (($mode & S_IFMT
) == S_IFGITLINK
)
1380 # convert file mode in octal to symbolic file mode string
1382 my $mode = oct shift;
1384 if (S_ISGITLINK
($mode)) {
1385 return 'm---------';
1386 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1387 return 'drwxr-xr-x';
1388 } elsif (S_ISLNK
($mode)) {
1389 return 'lrwxrwxrwx';
1390 } elsif (S_ISREG
($mode)) {
1391 # git cares only about the executable bit
1392 if ($mode & S_IXUSR
) {
1393 return '-rwxr-xr-x';
1395 return '-rw-r--r--';
1398 return '----------';
1402 # convert file mode in octal to file type string
1406 if ($mode !~ m/^[0-7]+$/) {
1412 if (S_ISGITLINK
($mode)) {
1414 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1416 } elsif (S_ISLNK
($mode)) {
1418 } elsif (S_ISREG
($mode)) {
1425 # convert file mode in octal to file type description string
1426 sub file_type_long
{
1429 if ($mode !~ m/^[0-7]+$/) {
1435 if (S_ISGITLINK
($mode)) {
1437 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1439 } elsif (S_ISLNK
($mode)) {
1441 } elsif (S_ISREG
($mode)) {
1442 if ($mode & S_IXUSR
) {
1443 return "executable";
1453 ## ----------------------------------------------------------------------
1454 ## functions returning short HTML fragments, or transforming HTML fragments
1455 ## which don't belong to other sections
1457 # format line of commit message.
1458 sub format_log_line_html
{
1461 $line = esc_html
($line, -nbsp
=>1);
1462 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1463 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1464 -class => "text"}, $1);
1470 # format marker of refs pointing to given object
1472 # the destination action is chosen based on object type and current context:
1473 # - for annotated tags, we choose the tag view unless it's the current view
1474 # already, in which case we go to shortlog view
1475 # - for other refs, we keep the current view if we're in history, shortlog or
1476 # log view, and select shortlog otherwise
1477 sub format_ref_marker
{
1478 my ($refs, $id) = @_;
1481 if (defined $refs->{$id}) {
1482 foreach my $ref (@
{$refs->{$id}}) {
1483 # this code exploits the fact that non-lightweight tags are the
1484 # only indirect objects, and that they are the only objects for which
1485 # we want to use tag instead of shortlog as action
1486 my ($type, $name) = qw();
1487 my $indirect = ($ref =~ s/\^\{\}$//);
1488 # e.g. tags/v2.6.11 or heads/next
1489 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1498 $class .= " indirect" if $indirect;
1500 my $dest_action = "shortlog";
1503 $dest_action = "tag" unless $action eq "tag";
1504 } elsif ($action =~ /^(history|(short)?log)$/) {
1505 $dest_action = $action;
1509 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1512 my $link = $cgi->a({
1514 action
=>$dest_action,
1518 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1524 return ' <span class="refs">'. $markers . '</span>';
1530 # format, perhaps shortened and with markers, title line
1531 sub format_subject_html
{
1532 my ($long, $short, $href, $extra) = @_;
1533 $extra = '' unless defined($extra);
1535 if (length($short) < length($long)) {
1536 $long =~ s/[[:cntrl:]]/?/g;
1537 return $cgi->a({-href
=> $href, -class => "list subject",
1538 -title
=> to_utf8
($long)},
1539 esc_html
($short)) . $extra;
1541 return $cgi->a({-href
=> $href, -class => "list subject"},
1542 esc_html
($long)) . $extra;
1546 # Rather than recomputing the url for an email multiple times, we cache it
1547 # after the first hit. This gives a visible benefit in views where the avatar
1548 # for the same email is used repeatedly (e.g. shortlog).
1549 # The cache is shared by all avatar engines (currently gravatar only), which
1550 # are free to use it as preferred. Since only one avatar engine is used for any
1551 # given page, there's no risk for cache conflicts.
1552 our %avatar_cache = ();
1554 # Compute the picon url for a given email, by using the picon search service over at
1555 # http://www.cs.indiana.edu/picons/search.html
1557 my $email = lc shift;
1558 if (!$avatar_cache{$email}) {
1559 my ($user, $domain) = split('@', $email);
1560 $avatar_cache{$email} =
1561 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1563 "users+domains+unknown/up/single";
1565 return $avatar_cache{$email};
1568 # Compute the gravatar url for a given email, if it's not in the cache already.
1569 # Gravatar stores only the part of the URL before the size, since that's the
1570 # one computationally more expensive. This also allows reuse of the cache for
1571 # different sizes (for this particular engine).
1573 my $email = lc shift;
1575 $avatar_cache{$email} ||=
1576 "http://www.gravatar.com/avatar/" .
1577 Digest
::MD5
::md5_hex
($email) . "?s=";
1578 return $avatar_cache{$email} . $size;
1581 # Insert an avatar for the given $email at the given $size if the feature
1583 sub git_get_avatar
{
1584 my ($email, %opts) = @_;
1585 my $pre_white = ($opts{-pad_before
} ?
" " : "");
1586 my $post_white = ($opts{-pad_after
} ?
" " : "");
1587 $opts{-size
} ||= 'default';
1588 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1590 if ($git_avatar eq 'gravatar') {
1591 $url = gravatar_url
($email, $size);
1592 } elsif ($git_avatar eq 'picon') {
1593 $url = picon_url
($email);
1595 # Other providers can be added by extending the if chain, defining $url
1596 # as needed. If no variant puts something in $url, we assume avatars
1597 # are completely disabled/unavailable.
1600 "<img width=\"$size\" " .
1601 "class=\"avatar\" " .
1610 # format the author name of the given commit with the given tag
1611 # the author name is chopped and escaped according to the other
1612 # optional parameters (see chop_str).
1613 sub format_author_html
{
1616 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1617 return "<$tag class=\"author\">" .
1618 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1619 $author . "</$tag>";
1622 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1623 sub format_git_diff_header_line
{
1625 my $diffinfo = shift;
1626 my ($from, $to) = @_;
1628 if ($diffinfo->{'nparents'}) {
1630 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1631 if ($to->{'href'}) {
1632 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1633 esc_path
($to->{'file'}));
1634 } else { # file was deleted (no href)
1635 $line .= esc_path
($to->{'file'});
1639 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1640 if ($from->{'href'}) {
1641 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1642 'a/' . esc_path
($from->{'file'}));
1643 } else { # file was added (no href)
1644 $line .= 'a/' . esc_path
($from->{'file'});
1647 if ($to->{'href'}) {
1648 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1649 'b/' . esc_path
($to->{'file'}));
1650 } else { # file was deleted
1651 $line .= 'b/' . esc_path
($to->{'file'});
1655 return "<div class=\"diff header\">$line</div>\n";
1658 # format extended diff header line, before patch itself
1659 sub format_extended_diff_header_line
{
1661 my $diffinfo = shift;
1662 my ($from, $to) = @_;
1665 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1666 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1667 esc_path
($from->{'file'}));
1669 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1670 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1671 esc_path
($to->{'file'}));
1673 # match single <mode>
1674 if ($line =~ m/\s(\d{6})$/) {
1675 $line .= '<span class="info"> (' .
1676 file_type_long
($1) .
1680 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1681 # can match only for combined diff
1683 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1684 if ($from->{'href'}[$i]) {
1685 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1687 substr($diffinfo->{'from_id'}[$i],0,7));
1692 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1695 if ($to->{'href'}) {
1696 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1697 substr($diffinfo->{'to_id'},0,7));
1702 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1703 # can match only for ordinary diff
1704 my ($from_link, $to_link);
1705 if ($from->{'href'}) {
1706 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1707 substr($diffinfo->{'from_id'},0,7));
1709 $from_link = '0' x
7;
1711 if ($to->{'href'}) {
1712 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1713 substr($diffinfo->{'to_id'},0,7));
1717 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1718 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1721 return $line . "<br/>\n";
1724 # format from-file/to-file diff header
1725 sub format_diff_from_to_header
{
1726 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1731 #assert($line =~ m/^---/) if DEBUG;
1732 # no extra formatting for "^--- /dev/null"
1733 if (! $diffinfo->{'nparents'}) {
1734 # ordinary (single parent) diff
1735 if ($line =~ m!^--- "?a/!) {
1736 if ($from->{'href'}) {
1738 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1739 esc_path
($from->{'file'}));
1742 esc_path
($from->{'file'});
1745 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1748 # combined diff (merge commit)
1749 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1750 if ($from->{'href'}[$i]) {
1752 $cgi->a({-href
=>href
(action
=>"blobdiff",
1753 hash_parent
=>$diffinfo->{'from_id'}[$i],
1754 hash_parent_base
=>$parents[$i],
1755 file_parent
=>$from->{'file'}[$i],
1756 hash
=>$diffinfo->{'to_id'},
1758 file_name
=>$to->{'file'}),
1760 -title
=>"diff" . ($i+1)},
1763 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1764 esc_path
($from->{'file'}[$i]));
1766 $line = '--- /dev/null';
1768 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1773 #assert($line =~ m/^\+\+\+/) if DEBUG;
1774 # no extra formatting for "^+++ /dev/null"
1775 if ($line =~ m!^\+\+\+ "?b/!) {
1776 if ($to->{'href'}) {
1778 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1779 esc_path
($to->{'file'}));
1782 esc_path
($to->{'file'});
1785 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1790 # create note for patch simplified by combined diff
1791 sub format_diff_cc_simplified
{
1792 my ($diffinfo, @parents) = @_;
1795 $result .= "<div class=\"diff header\">" .
1797 if (!is_deleted
($diffinfo)) {
1798 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1800 hash
=>$diffinfo->{'to_id'},
1801 file_name
=>$diffinfo->{'to_file'}),
1803 esc_path
($diffinfo->{'to_file'}));
1805 $result .= esc_path
($diffinfo->{'to_file'});
1807 $result .= "</div>\n" . # class="diff header"
1808 "<div class=\"diff nodifferences\">" .
1810 "</div>\n"; # class="diff nodifferences"
1815 # format patch (diff) line (not to be used for diff headers)
1816 sub format_diff_line
{
1818 my ($from, $to) = @_;
1819 my $diff_class = "";
1823 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1825 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1826 if ($line =~ m/^\@{3}/) {
1827 $diff_class = " chunk_header";
1828 } elsif ($line =~ m/^\\/) {
1829 $diff_class = " incomplete";
1830 } elsif ($prefix =~ tr/+/+/) {
1831 $diff_class = " add";
1832 } elsif ($prefix =~ tr/-/-/) {
1833 $diff_class = " rem";
1836 # assume ordinary diff
1837 my $char = substr($line, 0, 1);
1839 $diff_class = " add";
1840 } elsif ($char eq '-') {
1841 $diff_class = " rem";
1842 } elsif ($char eq '@') {
1843 $diff_class = " chunk_header";
1844 } elsif ($char eq "\\") {
1845 $diff_class = " incomplete";
1848 $line = untabify
($line);
1849 if ($from && $to && $line =~ m/^\@{2} /) {
1850 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1851 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1853 $from_lines = 0 unless defined $from_lines;
1854 $to_lines = 0 unless defined $to_lines;
1856 if ($from->{'href'}) {
1857 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1858 -class=>"list"}, $from_text);
1860 if ($to->{'href'}) {
1861 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1862 -class=>"list"}, $to_text);
1864 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1865 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1866 return "<div class=\"diff$diff_class\">$line</div>\n";
1867 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1868 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1869 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1871 @from_text = split(' ', $ranges);
1872 for (my $i = 0; $i < @from_text; ++$i) {
1873 ($from_start[$i], $from_nlines[$i]) =
1874 (split(',', substr($from_text[$i], 1)), 0);
1877 $to_text = pop @from_text;
1878 $to_start = pop @from_start;
1879 $to_nlines = pop @from_nlines;
1881 $line = "<span class=\"chunk_info\">$prefix ";
1882 for (my $i = 0; $i < @from_text; ++$i) {
1883 if ($from->{'href'}[$i]) {
1884 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1885 -class=>"list"}, $from_text[$i]);
1887 $line .= $from_text[$i];
1891 if ($to->{'href'}) {
1892 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1893 -class=>"list"}, $to_text);
1897 $line .= " $prefix</span>" .
1898 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1899 return "<div class=\"diff$diff_class\">$line</div>\n";
1901 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1904 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1905 # linked. Pass the hash of the tree/commit to snapshot.
1906 sub format_snapshot_links
{
1908 my $num_fmts = @snapshot_fmts;
1909 if ($num_fmts > 1) {
1910 # A parenthesized list of links bearing format names.
1911 # e.g. "snapshot (_tar.gz_ _zip_)"
1912 return "snapshot (" . join(' ', map
1919 }, $known_snapshot_formats{$_}{'display'})
1920 , @snapshot_fmts) . ")";
1921 } elsif ($num_fmts == 1) {
1922 # A single "snapshot" link whose tooltip bears the format name.
1924 my ($fmt) = @snapshot_fmts;
1930 snapshot_format
=>$fmt
1932 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1934 } else { # $num_fmts == 0
1939 ## ......................................................................
1940 ## functions returning values to be passed, perhaps after some
1941 ## transformation, to other functions; e.g. returning arguments to href()
1943 # returns hash to be passed to href to generate gitweb URL
1944 # in -title key it returns description of link
1946 my $format = shift || 'Atom';
1947 my %res = (action
=> lc($format));
1949 # feed links are possible only for project views
1950 return unless (defined $project);
1951 # some views should link to OPML, or to generic project feed,
1952 # or don't have specific feed yet (so they should use generic)
1953 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1956 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1957 # from tag links; this also makes possible to detect branch links
1958 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1959 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1962 # find log type for feed description (title)
1964 if (defined $file_name) {
1965 $type = "history of $file_name";
1966 $type .= "/" if ($action eq 'tree');
1967 $type .= " on '$branch'" if (defined $branch);
1969 $type = "log of $branch" if (defined $branch);
1972 $res{-title
} = $type;
1973 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1974 $res{'file_name'} = $file_name;
1979 ## ----------------------------------------------------------------------
1980 ## git utility subroutines, invoking git commands
1982 # returns path to the core git executable and the --git-dir parameter as list
1984 return $GIT, '--git-dir='.$git_dir;
1987 # quote the given arguments for passing them to the shell
1988 # quote_command("command", "arg 1", "arg with ' and ! characters")
1989 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1990 # Try to avoid using this function wherever possible.
1993 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1996 # get HEAD ref of given project as hash
1997 sub git_get_head_hash
{
1998 my $project = shift;
1999 my $o_git_dir = $git_dir;
2001 $git_dir = "$projectroot/$project";
2002 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
2005 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
2009 if (defined $o_git_dir) {
2010 $git_dir = $o_git_dir;
2015 # get type of given object
2019 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2021 close $fd or return;
2026 # repository configuration
2027 our $config_file = '';
2030 # store multiple values for single key as anonymous array reference
2031 # single values stored directly in the hash, not as [ <value> ]
2032 sub hash_set_multi
{
2033 my ($hash, $key, $value) = @_;
2035 if (!exists $hash->{$key}) {
2036 $hash->{$key} = $value;
2037 } elsif (!ref $hash->{$key}) {
2038 $hash->{$key} = [ $hash->{$key}, $value ];
2040 push @
{$hash->{$key}}, $value;
2044 # return hash of git project configuration
2045 # optionally limited to some section, e.g. 'gitweb'
2046 sub git_parse_project_config
{
2047 my $section_regexp = shift;
2052 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2055 while (my $keyval = <$fh>) {
2057 my ($key, $value) = split(/\n/, $keyval, 2);
2059 hash_set_multi
(\
%config, $key, $value)
2060 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2067 # convert config value to boolean: 'true' or 'false'
2068 # no value, number > 0, 'true' and 'yes' values are true
2069 # rest of values are treated as false (never as error)
2070 sub config_to_bool
{
2073 return 1 if !defined $val; # section.key
2075 # strip leading and trailing whitespace
2079 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2080 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2083 # convert config value to simple decimal number
2084 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2085 # to be multiplied by 1024, 1048576, or 1073741824
2089 # strip leading and trailing whitespace
2093 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2095 # unknown unit is treated as 1
2096 return $num * ($unit eq 'g' ?
1073741824 :
2097 $unit eq 'm' ?
1048576 :
2098 $unit eq 'k' ?
1024 : 1);
2103 # convert config value to array reference, if needed
2104 sub config_to_multi
{
2107 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
2110 sub git_get_project_config
{
2111 my ($key, $type) = @_;
2114 return unless ($key);
2115 $key =~ s/^gitweb\.//;
2116 return if ($key =~ m/\W/);
2119 if (defined $type) {
2122 unless ($type eq 'bool' || $type eq 'int');
2126 if (!defined $config_file ||
2127 $config_file ne "$git_dir/config") {
2128 %config = git_parse_project_config
('gitweb');
2129 $config_file = "$git_dir/config";
2132 # check if config variable (key) exists
2133 return unless exists $config{"gitweb.$key"};
2136 if (!defined $type) {
2137 return $config{"gitweb.$key"};
2138 } elsif ($type eq 'bool') {
2139 # backward compatibility: 'git config --bool' returns true/false
2140 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
2141 } elsif ($type eq 'int') {
2142 return config_to_int
($config{"gitweb.$key"});
2144 return $config{"gitweb.$key"};
2147 # get hash of given path at given ref
2148 sub git_get_hash_by_path
{
2150 my $path = shift || return undef;
2155 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2156 or die_error
(500, "Open git-ls-tree failed");
2158 close $fd or return undef;
2160 if (!defined $line) {
2161 # there is no tree or hash given by $path at $base
2165 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2166 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2167 if (defined $type && $type ne $2) {
2168 # type doesn't match
2174 # get path of entry with given hash at given tree-ish (ref)
2175 # used to get 'from' filename for combined diff (merge commit) for renames
2176 sub git_get_path_by_hash
{
2177 my $base = shift || return;
2178 my $hash = shift || return;
2182 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2184 while (my $line = <$fd>) {
2187 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2188 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2189 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2198 ## ......................................................................
2199 ## git utility functions, directly accessing git repository
2201 sub git_get_project_description
{
2204 $git_dir = "$projectroot/$path";
2205 open my $fd, '<', "$git_dir/description"
2206 or return git_get_project_config
('description');
2209 if (defined $descr) {
2215 sub git_get_project_ctags
{
2219 $git_dir = "$projectroot/$path";
2220 opendir my $dh, "$git_dir/ctags"
2222 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2223 open my $ct, '<', $_ or next;
2227 my $ctag = $_; $ctag =~ s
#.*/##;
2228 $ctags->{$ctag} = $val;
2234 sub git_populate_project_tagcloud
{
2237 # First, merge different-cased tags; tags vote on casing
2239 foreach (keys %$ctags) {
2240 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2241 if (not $ctags_lc{lc $_}->{topcount
}
2242 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2243 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2244 $ctags_lc{lc $_}->{topname
} = $_;
2249 if (eval { require HTML
::TagCloud
; 1; }) {
2250 $cloud = HTML
::TagCloud
->new;
2251 foreach (sort keys %ctags_lc) {
2252 # Pad the title with spaces so that the cloud looks
2254 my $title = $ctags_lc{$_}->{topname
};
2255 $title =~ s/ / /g;
2256 $title =~ s/^/ /g;
2257 $title =~ s/$/ /g;
2258 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2261 $cloud = \
%ctags_lc;
2266 sub git_show_project_tagcloud
{
2267 my ($cloud, $count) = @_;
2268 print STDERR
ref($cloud)."..\n";
2269 if (ref $cloud eq 'HTML::TagCloud') {
2270 return $cloud->html_and_css($count);
2272 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2273 return '<p align="center">' . join (', ', map {
2274 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2275 } splice(@tags, 0, $count)) . '</p>';
2279 sub git_get_project_url_list
{
2282 $git_dir = "$projectroot/$path";
2283 open my $fd, '<', "$git_dir/cloneurl"
2284 or return wantarray ?
2285 @
{ config_to_multi
(git_get_project_config
('url')) } :
2286 config_to_multi
(git_get_project_config
('url'));
2287 my @git_project_url_list = map { chomp; $_ } <$fd>;
2290 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2293 sub git_get_projects_list
{
2298 $filter =~ s/\.git$//;
2300 my $check_forks = gitweb_check_feature
('forks');
2302 if (-d
$projects_list) {
2303 # search in directory
2304 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2305 # remove the trailing "/"
2307 my $pfxlen = length("$dir");
2308 my $pfxdepth = ($dir =~ tr!/!!);
2311 follow_fast
=> 1, # follow symbolic links
2312 follow_skip
=> 2, # ignore duplicates
2313 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2315 # skip project-list toplevel, if we get it.
2316 return if (m!^[/.]$!);
2317 # only directories can be git repositories
2318 return unless (-d
$_);
2319 # don't traverse too deep (Find is super slow on os x)
2320 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2321 $File::Find
::prune
= 1;
2325 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2326 # we check related file in $projectroot
2327 my $path = ($filter ?
"$filter/" : '') . $subdir;
2328 if (check_export_ok
("$projectroot/$path")) {
2329 push @list, { path
=> $path };
2330 $File::Find
::prune
= 1;
2335 } elsif (-f
$projects_list) {
2336 # read from file(url-encoded):
2337 # 'git%2Fgit.git Linus+Torvalds'
2338 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2339 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2341 open my $fd, '<', $projects_list or return;
2343 while (my $line = <$fd>) {
2345 my ($path, $owner) = split ' ', $line;
2346 $path = unescape
($path);
2347 $owner = unescape
($owner);
2348 if (!defined $path) {
2351 if ($filter ne '') {
2352 # looking for forks;
2353 my $pfx = substr($path, 0, length($filter));
2354 if ($pfx ne $filter) {
2357 my $sfx = substr($path, length($filter));
2358 if ($sfx !~ /^\/.*\
.git
$/) {
2361 } elsif ($check_forks) {
2363 foreach my $filter (keys %paths) {
2364 # looking for forks;
2365 my $pfx = substr($path, 0, length($filter));
2366 if ($pfx ne $filter) {
2369 my $sfx = substr($path, length($filter));
2370 if ($sfx !~ /^\/.*\
.git
$/) {
2373 # is a fork, don't include it in
2378 if (check_export_ok
("$projectroot/$path")) {
2381 owner
=> to_utf8
($owner),
2384 (my $forks_path = $path) =~ s/\.git$//;
2385 $paths{$forks_path}++;
2393 our $gitweb_project_owner = undef;
2394 sub git_get_project_list_from_file
{
2396 return if (defined $gitweb_project_owner);
2398 $gitweb_project_owner = {};
2399 # read from file (url-encoded):
2400 # 'git%2Fgit.git Linus+Torvalds'
2401 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2402 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2403 if (-f
$projects_list) {
2404 open(my $fd, '<', $projects_list);
2405 while (my $line = <$fd>) {
2407 my ($pr, $ow) = split ' ', $line;
2408 $pr = unescape
($pr);
2409 $ow = unescape
($ow);
2410 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2416 sub git_get_project_owner
{
2417 my $project = shift;
2420 return undef unless $project;
2421 $git_dir = "$projectroot/$project";
2423 if (!defined $gitweb_project_owner) {
2424 git_get_project_list_from_file
();
2427 if (exists $gitweb_project_owner->{$project}) {
2428 $owner = $gitweb_project_owner->{$project};
2430 if (!defined $owner){
2431 $owner = git_get_project_config
('owner');
2433 if (!defined $owner) {
2434 $owner = get_file_owner
("$git_dir");
2440 sub git_get_last_activity
{
2444 $git_dir = "$projectroot/$path";
2445 open($fd, "-|", git_cmd
(), 'for-each-ref',
2446 '--format=%(committer)',
2447 '--sort=-committerdate',
2449 'refs/heads') or return;
2450 my $most_recent = <$fd>;
2451 close $fd or return;
2452 if (defined $most_recent &&
2453 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2455 my $age = time - $timestamp;
2456 return ($age, age_string
($age));
2458 return (undef, undef);
2461 sub git_get_references
{
2462 my $type = shift || "";
2464 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2465 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2466 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2467 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2470 while (my $line = <$fd>) {
2472 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2473 if (defined $refs{$1}) {
2474 push @
{$refs{$1}}, $2;
2480 close $fd or return;
2484 sub git_get_rev_name_tags
{
2485 my $hash = shift || return undef;
2487 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2489 my $name_rev = <$fd>;
2492 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2495 # catches also '$hash undefined' output
2500 ## ----------------------------------------------------------------------
2501 ## parse to hash functions
2505 my $tz = shift || "-0000";
2508 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2509 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2510 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2511 $date{'hour'} = $hour;
2512 $date{'minute'} = $min;
2513 $date{'mday'} = $mday;
2514 $date{'day'} = $days[$wday];
2515 $date{'month'} = $months[$mon];
2516 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2517 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2518 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2519 $mday, $months[$mon], $hour ,$min;
2520 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2521 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2523 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2524 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2525 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2526 $date{'hour_local'} = $hour;
2527 $date{'minute_local'} = $min;
2528 $date{'tz_local'} = $tz;
2529 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2530 1900+$year, $mon+1, $mday,
2531 $hour, $min, $sec, $tz);
2540 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2541 $tag{'id'} = $tag_id;
2542 while (my $line = <$fd>) {
2544 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2545 $tag{'object'} = $1;
2546 } elsif ($line =~ m/^type (.+)$/) {
2548 } elsif ($line =~ m/^tag (.+)$/) {
2550 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2551 $tag{'author'} = $1;
2552 $tag{'author_epoch'} = $2;
2553 $tag{'author_tz'} = $3;
2554 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2555 $tag{'author_name'} = $1;
2556 $tag{'author_email'} = $2;
2558 $tag{'author_name'} = $tag{'author'};
2560 } elsif ($line =~ m/--BEGIN/) {
2561 push @comment, $line;
2563 } elsif ($line eq "") {
2567 push @comment, <$fd>;
2568 $tag{'comment'} = \
@comment;
2569 close $fd or return;
2570 if (!defined $tag{'name'}) {
2576 sub parse_commit_text
{
2577 my ($commit_text, $withparents) = @_;
2578 my @commit_lines = split '\n', $commit_text;
2581 pop @commit_lines; # Remove '\0'
2583 if (! @commit_lines) {
2587 my $header = shift @commit_lines;
2588 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2591 ($co{'id'}, my @parents) = split ' ', $header;
2592 while (my $line = shift @commit_lines) {
2593 last if $line eq "\n";
2594 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2596 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2598 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2599 $co{'author'} = to_utf8
($1);
2600 $co{'author_epoch'} = $2;
2601 $co{'author_tz'} = $3;
2602 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2603 $co{'author_name'} = $1;
2604 $co{'author_email'} = $2;
2606 $co{'author_name'} = $co{'author'};
2608 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2609 $co{'committer'} = to_utf8
($1);
2610 $co{'committer_epoch'} = $2;
2611 $co{'committer_tz'} = $3;
2612 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2613 $co{'committer_name'} = $1;
2614 $co{'committer_email'} = $2;
2616 $co{'committer_name'} = $co{'committer'};
2620 if (!defined $co{'tree'}) {
2623 $co{'parents'} = \
@parents;
2624 $co{'parent'} = $parents[0];
2626 foreach my $title (@commit_lines) {
2629 $co{'title'} = chop_str
($title, 80, 5);
2630 # remove leading stuff of merges to make the interesting part visible
2631 if (length($title) > 50) {
2632 $title =~ s/^Automatic //;
2633 $title =~ s/^merge (of|with) /Merge ... /i;
2634 if (length($title) > 50) {
2635 $title =~ s/(http|rsync):\/\///;
2637 if (length($title) > 50) {
2638 $title =~ s/(master|www|rsync)\.//;
2640 if (length($title) > 50) {
2641 $title =~ s/kernel.org:?//;
2643 if (length($title) > 50) {
2644 $title =~ s/\/pub\/scm//;
2647 $co{'title_short'} = chop_str
($title, 50, 5);
2651 if (! defined $co{'title'} || $co{'title'} eq "") {
2652 $co{'title'} = $co{'title_short'} = '(no commit message)';
2654 # remove added spaces
2655 foreach my $line (@commit_lines) {
2658 $co{'comment'} = \
@commit_lines;
2660 my $age = time - $co{'committer_epoch'};
2662 $co{'age_string'} = age_string
($age);
2663 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2664 if ($age > 60*60*24*7*2) {
2665 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2666 $co{'age_string_age'} = $co{'age_string'};
2668 $co{'age_string_date'} = $co{'age_string'};
2669 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2675 my ($commit_id) = @_;
2680 open my $fd, "-|", git_cmd
(), "rev-list",
2686 or die_error
(500, "Open git-rev-list failed");
2687 %co = parse_commit_text
(<$fd>, 1);
2694 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2702 open my $fd, "-|", git_cmd
(), "rev-list",
2705 ("--max-count=" . $maxcount),
2706 ("--skip=" . $skip),
2710 ($filename ?
($filename) : ())
2711 or die_error
(500, "Open git-rev-list failed");
2712 while (my $line = <$fd>) {
2713 my %co = parse_commit_text
($line);
2718 return wantarray ?
@cos : \
@cos;
2721 # parse line of git-diff-tree "raw" output
2722 sub parse_difftree_raw_line
{
2726 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2727 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2728 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2729 $res{'from_mode'} = $1;
2730 $res{'to_mode'} = $2;
2731 $res{'from_id'} = $3;
2733 $res{'status'} = $5;
2734 $res{'similarity'} = $6;
2735 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2736 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2738 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2741 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2742 # combined diff (for merge commit)
2743 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2744 $res{'nparents'} = length($1);
2745 $res{'from_mode'} = [ split(' ', $2) ];
2746 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2747 $res{'from_id'} = [ split(' ', $3) ];
2748 $res{'to_id'} = pop @
{$res{'from_id'}};
2749 $res{'status'} = [ split('', $4) ];
2750 $res{'to_file'} = unquote
($5);
2752 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2753 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2754 $res{'commit'} = $1;
2757 return wantarray ?
%res : \
%res;
2760 # wrapper: return parsed line of git-diff-tree "raw" output
2761 # (the argument might be raw line, or parsed info)
2762 sub parsed_difftree_line
{
2763 my $line_or_ref = shift;
2765 if (ref($line_or_ref) eq "HASH") {
2766 # pre-parsed (or generated by hand)
2767 return $line_or_ref;
2769 return parse_difftree_raw_line
($line_or_ref);
2773 # parse line of git-ls-tree output
2774 sub parse_ls_tree_line
{
2780 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2781 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2790 $res{'name'} = unquote
($5);
2793 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2794 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2802 $res{'name'} = unquote
($4);
2806 return wantarray ?
%res : \
%res;
2809 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2810 sub parse_from_to_diffinfo
{
2811 my ($diffinfo, $from, $to, @parents) = @_;
2813 if ($diffinfo->{'nparents'}) {
2815 $from->{'file'} = [];
2816 $from->{'href'} = [];
2817 fill_from_file_info
($diffinfo, @parents)
2818 unless exists $diffinfo->{'from_file'};
2819 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2820 $from->{'file'}[$i] =
2821 defined $diffinfo->{'from_file'}[$i] ?
2822 $diffinfo->{'from_file'}[$i] :
2823 $diffinfo->{'to_file'};
2824 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2825 $from->{'href'}[$i] = href
(action
=>"blob",
2826 hash_base
=>$parents[$i],
2827 hash
=>$diffinfo->{'from_id'}[$i],
2828 file_name
=>$from->{'file'}[$i]);
2830 $from->{'href'}[$i] = undef;
2834 # ordinary (not combined) diff
2835 $from->{'file'} = $diffinfo->{'from_file'};
2836 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2837 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2838 hash
=>$diffinfo->{'from_id'},
2839 file_name
=>$from->{'file'});
2841 delete $from->{'href'};
2845 $to->{'file'} = $diffinfo->{'to_file'};
2846 if (!is_deleted
($diffinfo)) { # file exists in result
2847 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2848 hash
=>$diffinfo->{'to_id'},
2849 file_name
=>$to->{'file'});
2851 delete $to->{'href'};
2855 ## ......................................................................
2856 ## parse to array of hashes functions
2858 sub git_get_heads_list
{
2862 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2863 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2864 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2867 while (my $line = <$fd>) {
2871 my ($refinfo, $committerinfo) = split(/\0/, $line);
2872 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2873 my ($committer, $epoch, $tz) =
2874 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2875 $ref_item{'fullname'} = $name;
2876 $name =~ s!^refs/heads/!!;
2878 $ref_item{'name'} = $name;
2879 $ref_item{'id'} = $hash;
2880 $ref_item{'title'} = $title || '(no commit message)';
2881 $ref_item{'epoch'} = $epoch;
2883 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2885 $ref_item{'age'} = "unknown";
2888 push @headslist, \
%ref_item;
2892 return wantarray ?
@headslist : \
@headslist;
2895 sub git_get_tags_list
{
2899 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2900 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2901 '--format=%(objectname) %(objecttype) %(refname) '.
2902 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2905 while (my $line = <$fd>) {
2909 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2910 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2911 my ($creator, $epoch, $tz) =
2912 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2913 $ref_item{'fullname'} = $name;
2914 $name =~ s!^refs/tags/!!;
2916 $ref_item{'type'} = $type;
2917 $ref_item{'id'} = $id;
2918 $ref_item{'name'} = $name;
2919 if ($type eq "tag") {
2920 $ref_item{'subject'} = $title;
2921 $ref_item{'reftype'} = $reftype;
2922 $ref_item{'refid'} = $refid;
2924 $ref_item{'reftype'} = $type;
2925 $ref_item{'refid'} = $id;
2928 if ($type eq "tag" || $type eq "commit") {
2929 $ref_item{'epoch'} = $epoch;
2931 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2933 $ref_item{'age'} = "unknown";
2937 push @tagslist, \
%ref_item;
2941 return wantarray ?
@tagslist : \
@tagslist;
2944 ## ----------------------------------------------------------------------
2945 ## filesystem-related functions
2947 sub get_file_owner
{
2950 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2951 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2952 if (!defined $gcos) {
2956 $owner =~ s/[,;].*$//;
2957 return to_utf8
($owner);
2960 # assume that file exists
2962 my $filename = shift;
2964 open my $fd, '<', $filename;
2965 print map { to_utf8
($_) } <$fd>;
2969 ## ......................................................................
2970 ## mimetype related functions
2972 sub mimetype_guess_file
{
2973 my $filename = shift;
2974 my $mimemap = shift;
2975 -r
$mimemap or return undef;
2978 open(my $mh, '<', $mimemap) or return undef;
2980 next if m/^#/; # skip comments
2981 my ($mimetype, $exts) = split(/\t+/);
2982 if (defined $exts) {
2983 my @exts = split(/\s+/, $exts);
2984 foreach my $ext (@exts) {
2985 $mimemap{$ext} = $mimetype;
2991 $filename =~ /\.([^.]*)$/;
2992 return $mimemap{$1};
2995 sub mimetype_guess
{
2996 my $filename = shift;
2998 $filename =~ /\./ or return undef;
3000 if ($mimetypes_file) {
3001 my $file = $mimetypes_file;
3002 if ($file !~ m!^/!) { # if it is relative path
3003 # it is relative to project
3004 $file = "$projectroot/$project/$file";
3006 $mime = mimetype_guess_file
($filename, $file);
3008 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3014 my $filename = shift;
3017 my $mime = mimetype_guess
($filename);
3018 $mime and return $mime;
3022 return $default_blob_plain_mimetype unless $fd;
3025 return 'text/plain';
3026 } elsif (! $filename) {
3027 return 'application/octet-stream';
3028 } elsif ($filename =~ m/\.png$/i) {
3030 } elsif ($filename =~ m/\.gif$/i) {
3032 } elsif ($filename =~ m/\.jpe?g$/i) {
3033 return 'image/jpeg';
3035 return 'application/octet-stream';
3039 sub blob_contenttype
{
3040 my ($fd, $file_name, $type) = @_;
3042 $type ||= blob_mimetype
($fd, $file_name);
3043 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3044 $type .= "; charset=$default_text_plain_charset";
3050 ## ======================================================================
3051 ## functions printing HTML: header, footer, error page
3053 sub git_header_html
{
3054 my $status = shift || "200 OK";
3055 my $expires = shift;
3057 my $title = "$site_name";
3058 if (defined $project) {
3059 $title .= " - " . to_utf8
($project);
3060 if (defined $action) {
3061 $title .= "/$action";
3062 if (defined $file_name) {
3063 $title .= " - " . esc_path
($file_name);
3064 if ($action eq "tree" && $file_name !~ m
|/$|) {
3071 # require explicit support from the UA if we are to send the page as
3072 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3073 # we have to do this because MSIE sometimes globs '*/*', pretending to
3074 # support xhtml+xml but choking when it gets what it asked for.
3075 if (defined $cgi->http('HTTP_ACCEPT') &&
3076 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3077 $cgi->Accept('application/xhtml+xml') != 0) {
3078 $content_type = 'application/xhtml+xml';
3080 $content_type = 'text/html';
3082 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3083 -status
=> $status, -expires
=> $expires);
3084 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
3086 <?xml version="1.0" encoding="utf-8"?>
3087 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3088 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3089 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3090 <!-- git core binaries version $git_version -->
3092 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3093 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3094 <meta name="robots" content="index, nofollow"/>
3095 <title>$title</title>
3097 # the stylesheet, favicon etc urls won't work correctly with path_info
3098 # unless we set the appropriate base URL
3099 if ($ENV{'PATH_INFO'}) {
3100 print "<base href=\"".esc_url
($base_url)."\" />\n";
3102 # print out each stylesheet that exist, providing backwards capability
3103 # for those people who defined $stylesheet in a config file
3104 if (defined $stylesheet) {
3105 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3107 foreach my $stylesheet (@stylesheets) {
3108 next unless $stylesheet;
3109 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3112 if (defined $project) {
3113 my %href_params = get_feed_info
();
3114 if (!exists $href_params{'-title'}) {
3115 $href_params{'-title'} = 'log';
3118 foreach my $format qw(RSS Atom) {
3119 my $type = lc($format);
3121 '-rel' => 'alternate',
3122 '-title' => "$project - $href_params{'-title'} - $format feed",
3123 '-type' => "application/$type+xml"
3126 $href_params{'action'} = $type;
3127 $link_attr{'-href'} = href
(%href_params);
3129 "rel=\"$link_attr{'-rel'}\" ".
3130 "title=\"$link_attr{'-title'}\" ".
3131 "href=\"$link_attr{'-href'}\" ".
3132 "type=\"$link_attr{'-type'}\" ".
3135 $href_params{'extra_options'} = '--no-merges';
3136 $link_attr{'-href'} = href
(%href_params);
3137 $link_attr{'-title'} .= ' (no merges)';
3139 "rel=\"$link_attr{'-rel'}\" ".
3140 "title=\"$link_attr{'-title'}\" ".
3141 "href=\"$link_attr{'-href'}\" ".
3142 "type=\"$link_attr{'-type'}\" ".
3147 printf('<link rel="alternate" title="%s projects list" '.
3148 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3149 $site_name, href
(project
=>undef, action
=>"project_index"));
3150 printf('<link rel="alternate" title="%s projects feeds" '.
3151 'href="%s" type="text/x-opml" />'."\n",
3152 $site_name, href
(project
=>undef, action
=>"opml"));
3154 if (defined $favicon) {
3155 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
3161 if (-f
$site_header) {
3162 insert_file
($site_header);
3165 print "<div class=\"page_header\">\n" .
3166 $cgi->a({-href
=> esc_url
($logo_url),
3167 -title
=> $logo_label},
3168 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3169 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3170 if (defined $project) {
3171 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3172 if (defined $action) {
3179 my $have_search = gitweb_check_feature
('search');
3180 if (defined $project && $have_search) {
3181 if (!defined $searchtext) {
3185 if (defined $hash_base) {
3186 $search_hash = $hash_base;
3187 } elsif (defined $hash) {
3188 $search_hash = $hash;
3190 $search_hash = "HEAD";
3192 my $action = $my_uri;
3193 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3194 if ($use_pathinfo) {
3195 $action .= "/".esc_url
($project);
3197 print $cgi->startform(-method
=> "get", -action
=> $action) .
3198 "<div class=\"search\">\n" .
3200 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3201 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3202 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3203 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3204 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3205 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3207 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3208 "<span title=\"Extended regular expression\">" .
3209 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3210 -checked
=> $search_use_regexp) .
3213 $cgi->end_form() . "\n";
3217 sub git_footer_html
{
3218 my $feed_class = 'rss_logo';
3220 print "<div class=\"page_footer\">\n";
3221 if (defined $project) {
3222 my $descr = git_get_project_description
($project);
3223 if (defined $descr) {
3224 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3227 my %href_params = get_feed_info
();
3228 if (!%href_params) {
3229 $feed_class .= ' generic';
3231 $href_params{'-title'} ||= 'log';
3233 foreach my $format qw(RSS Atom) {
3234 $href_params{'action'} = lc($format);
3235 print $cgi->a({-href
=> href
(%href_params),
3236 -title
=> "$href_params{'-title'} $format feed",
3237 -class => $feed_class}, $format)."\n";
3241 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3242 -class => $feed_class}, "OPML") . " ";
3243 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3244 -class => $feed_class}, "TXT") . "\n";
3246 print "</div>\n"; # class="page_footer"
3248 if (-f
$site_footer) {
3249 insert_file
($site_footer);
3256 # die_error(<http_status_code>, <error_message>)
3257 # Example: die_error(404, 'Hash not found')
3258 # By convention, use the following status codes (as defined in RFC 2616):
3259 # 400: Invalid or missing CGI parameters, or
3260 # requested object exists but has wrong type.
3261 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3262 # this server or project.
3263 # 404: Requested object/revision/project doesn't exist.
3264 # 500: The server isn't configured properly, or
3265 # an internal error occurred (e.g. failed assertions caused by bugs), or
3266 # an unknown error occurred (e.g. the git binary died unexpectedly).
3268 my $status = shift || 500;
3269 my $error = shift || "Internal server error";
3271 my %http_responses = (400 => '400 Bad Request',
3272 403 => '403 Forbidden',
3273 404 => '404 Not Found',
3274 500 => '500 Internal Server Error');
3275 git_header_html
($http_responses{$status});
3277 <div class="page_body">
3287 ## ----------------------------------------------------------------------
3288 ## functions printing or outputting HTML: navigation
3290 sub git_print_page_nav
{
3291 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3292 $extra = '' if !defined $extra; # pager or formats
3294 my @navs = qw(summary shortlog log commit commitdiff tree);
3296 @navs = grep { $_ ne $suppress } @navs;
3299 my %arg = map { $_ => {action
=>$_} } @navs;
3300 if (defined $head) {
3301 for (qw(commit commitdiff)) {
3302 $arg{$_}{'hash'} = $head;
3304 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3305 for (qw(shortlog log)) {
3306 $arg{$_}{'hash'} = $head;
3311 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3312 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3314 my @actions = gitweb_get_feature
('actions');
3317 'n' => $project, # project name
3318 'f' => $git_dir, # project path within filesystem
3319 'h' => $treehead || '', # current hash ('h' parameter)
3320 'b' => $treebase || '', # hash base ('hb' parameter)
3323 my ($label, $link, $pos) = splice(@actions,0,3);
3325 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3327 $link =~ s/%([%nfhb])/$repl{$1}/g;
3328 $arg{$label}{'_href'} = $link;
3331 print "<div class=\"page_nav\">\n" .
3333 map { $_ eq $current ?
3334 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3336 print "<br/>\n$extra<br/>\n" .
3340 sub format_paging_nav
{
3341 my ($action, $hash, $head, $page, $has_next_link) = @_;
3345 if ($hash ne $head || $page) {
3346 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3348 $paging_nav .= "HEAD";
3352 $paging_nav .= " ⋅ " .
3353 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3354 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3356 $paging_nav .= " ⋅ prev";
3359 if ($has_next_link) {
3360 $paging_nav .= " ⋅ " .
3361 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3362 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3364 $paging_nav .= " ⋅ next";
3370 ## ......................................................................
3371 ## functions printing or outputting HTML: div
3373 sub git_print_header_div
{
3374 my ($action, $title, $hash, $hash_base) = @_;
3377 $args{'action'} = $action;
3378 $args{'hash'} = $hash if $hash;
3379 $args{'hash_base'} = $hash_base if $hash_base;
3381 print "<div class=\"header\">\n" .
3382 $cgi->a({-href
=> href
(%args), -class => "title"},
3383 $title ?
$title : $action) .
3387 sub print_local_time
{
3389 if ($date{'hour_local'} < 6) {
3390 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3391 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3393 printf(" (%02d:%02d %s)",
3394 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3398 # Outputs the author name and date in long form
3399 sub git_print_authorship
{
3402 my $tag = $opts{-tag
} || 'div';
3404 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3405 print "<$tag class=\"author_date\">" .
3406 esc_html
($co->{'author_name'}) .
3408 print_local_time
(%ad) if ($opts{-localtime});
3409 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3413 # Outputs table rows containing the full author or committer information,
3414 # in the format expected for 'commit' view (& similia).
3415 # Parameters are a commit hash reference, followed by the list of people
3416 # to output information for. If the list is empty it defalts to both
3417 # author and committer.
3418 sub git_print_authorship_rows
{
3420 # too bad we can't use @people = @_ || ('author', 'committer')
3422 @people = ('author', 'committer') unless @people;
3423 foreach my $who (@people) {
3424 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3425 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3426 "<td rowspan=\"2\">" .
3427 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3430 "<td></td><td> $wd{'rfc2822'}";
3431 print_local_time
(%wd);
3437 sub git_print_page_path
{
3443 print "<div class=\"page_path\">";
3444 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3445 -title
=> 'tree root'}, to_utf8
("[$project]"));
3447 if (defined $name) {
3448 my @dirname = split '/', $name;
3449 my $basename = pop @dirname;
3452 foreach my $dir (@dirname) {
3453 $fullname .= ($fullname ?
'/' : '') . $dir;
3454 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3456 -title
=> $fullname}, esc_path
($dir));
3459 if (defined $type && $type eq 'blob') {
3460 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3462 -title
=> $name}, esc_path
($basename));
3463 } elsif (defined $type && $type eq 'tree') {
3464 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3466 -title
=> $name}, esc_path
($basename));
3469 print esc_path
($basename);
3472 print "<br/></div>\n";
3479 if ($opts{'-remove_title'}) {
3480 # remove title, i.e. first line of log
3483 # remove leading empty lines
3484 while (defined $log->[0] && $log->[0] eq "") {
3491 foreach my $line (@
$log) {
3492 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3495 if (! $opts{'-remove_signoff'}) {
3496 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3499 # remove signoff lines
3506 # print only one empty line
3507 # do not print empty line after signoff
3509 next if ($empty || $signoff);
3515 print format_log_line_html
($line) . "<br/>\n";
3518 if ($opts{'-final_empty_line'}) {
3519 # end with single empty line
3520 print "<br/>\n" unless $empty;
3524 # return link target (what link points to)
3525 sub git_get_link_target
{
3530 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3534 $link_target = <$fd>;
3539 return $link_target;
3542 # given link target, and the directory (basedir) the link is in,
3543 # return target of link relative to top directory (top tree);
3544 # return undef if it is not possible (including absolute links).
3545 sub normalize_link_target
{
3546 my ($link_target, $basedir) = @_;
3548 # absolute symlinks (beginning with '/') cannot be normalized
3549 return if (substr($link_target, 0, 1) eq '/');
3551 # normalize link target to path from top (root) tree (dir)
3554 $path = $basedir . '/' . $link_target;
3556 # we are in top (root) tree (dir)
3557 $path = $link_target;
3560 # remove //, /./, and /../
3562 foreach my $part (split('/', $path)) {
3563 # discard '.' and ''
3564 next if (!$part || $part eq '.');
3566 if ($part eq '..') {
3570 # link leads outside repository (outside top dir)
3574 push @path_parts, $part;
3577 $path = join('/', @path_parts);
3582 # print tree entry (row of git_tree), but without encompassing <tr> element
3583 sub git_print_tree_entry
{
3584 my ($t, $basedir, $hash_base, $have_blame) = @_;
3587 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3589 # The format of a table row is: mode list link. Where mode is
3590 # the mode of the entry, list is the name of the entry, an href,
3591 # and link is the action links of the entry.
3593 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3594 if (exists $t->{'size'}) {
3595 print "<td class=\"size\">$t->{'size'}</td>\n";
3597 if ($t->{'type'} eq "blob") {
3598 print "<td class=\"list\">" .
3599 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3600 file_name
=>"$basedir$t->{'name'}", %base_key),
3601 -class => "list"}, esc_path
($t->{'name'}));
3602 if (S_ISLNK
(oct $t->{'mode'})) {
3603 my $link_target = git_get_link_target
($t->{'hash'});
3605 my $norm_target = normalize_link_target
($link_target, $basedir);
3606 if (defined $norm_target) {
3608 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3609 file_name
=>$norm_target),
3610 -title
=> $norm_target}, esc_path
($link_target));
3612 print " -> " . esc_path
($link_target);
3617 print "<td class=\"link\">";
3618 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3619 file_name
=>"$basedir$t->{'name'}", %base_key)},
3623 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3624 file_name
=>"$basedir$t->{'name'}", %base_key)},
3627 if (defined $hash_base) {
3629 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3630 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3634 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3635 file_name
=>"$basedir$t->{'name'}")},
3639 } elsif ($t->{'type'} eq "tree") {
3640 print "<td class=\"list\">";
3641 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3642 file_name
=>"$basedir$t->{'name'}",
3644 esc_path
($t->{'name'}));
3646 print "<td class=\"link\">";
3647 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3648 file_name
=>"$basedir$t->{'name'}",
3651 if (defined $hash_base) {
3653 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3654 file_name
=>"$basedir$t->{'name'}")},
3659 # unknown object: we can only present history for it
3660 # (this includes 'commit' object, i.e. submodule support)
3661 print "<td class=\"list\">" .
3662 esc_path
($t->{'name'}) .
3664 print "<td class=\"link\">";
3665 if (defined $hash_base) {
3666 print $cgi->a({-href
=> href
(action
=>"history",
3667 hash_base
=>$hash_base,
3668 file_name
=>"$basedir$t->{'name'}")},
3675 ## ......................................................................
3676 ## functions printing large fragments of HTML
3678 # get pre-image filenames for merge (combined) diff
3679 sub fill_from_file_info
{
3680 my ($diff, @parents) = @_;
3682 $diff->{'from_file'} = [ ];
3683 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3684 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3685 if ($diff->{'status'}[$i] eq 'R' ||
3686 $diff->{'status'}[$i] eq 'C') {
3687 $diff->{'from_file'}[$i] =
3688 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3695 # is current raw difftree line of file deletion
3697 my $diffinfo = shift;
3699 return $diffinfo->{'to_id'} eq ('0' x
40);
3702 # does patch correspond to [previous] difftree raw line
3703 # $diffinfo - hashref of parsed raw diff format
3704 # $patchinfo - hashref of parsed patch diff format
3705 # (the same keys as in $diffinfo)
3706 sub is_patch_split
{
3707 my ($diffinfo, $patchinfo) = @_;
3709 return defined $diffinfo && defined $patchinfo
3710 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3714 sub git_difftree_body
{
3715 my ($difftree, $hash, @parents) = @_;
3716 my ($parent) = $parents[0];
3717 my $have_blame = gitweb_check_feature
('blame');
3718 print "<div class=\"list_head\">\n";
3719 if ($#{$difftree} > 10) {
3720 print(($#{$difftree} + 1) . " files changed:\n");
3724 print "<table class=\"" .
3725 (@parents > 1 ?
"combined " : "") .
3728 # header only for combined diff in 'commitdiff' view
3729 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3732 print "<thead><tr>\n" .
3733 "<th></th><th></th>\n"; # filename, patchN link
3734 for (my $i = 0; $i < @parents; $i++) {
3735 my $par = $parents[$i];
3737 $cgi->a({-href
=> href
(action
=>"commitdiff",
3738 hash
=>$hash, hash_parent
=>$par),
3739 -title
=> 'commitdiff to parent number ' .
3740 ($i+1) . ': ' . substr($par,0,7)},
3744 print "</tr></thead>\n<tbody>\n";
3749 foreach my $line (@
{$difftree}) {
3750 my $diff = parsed_difftree_line
($line);
3753 print "<tr class=\"dark\">\n";
3755 print "<tr class=\"light\">\n";
3759 if (exists $diff->{'nparents'}) { # combined diff
3761 fill_from_file_info
($diff, @parents)
3762 unless exists $diff->{'from_file'};
3764 if (!is_deleted
($diff)) {
3765 # file exists in the result (child) commit
3767 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3768 file_name
=>$diff->{'to_file'},
3770 -class => "list"}, esc_path
($diff->{'to_file'})) .
3774 esc_path
($diff->{'to_file'}) .
3778 if ($action eq 'commitdiff') {
3781 print "<td class=\"link\">" .
3782 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3787 my $has_history = 0;
3788 my $not_deleted = 0;
3789 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3790 my $hash_parent = $parents[$i];
3791 my $from_hash = $diff->{'from_id'}[$i];
3792 my $from_path = $diff->{'from_file'}[$i];
3793 my $status = $diff->{'status'}[$i];
3795 $has_history ||= ($status ne 'A');
3796 $not_deleted ||= ($status ne 'D');
3798 if ($status eq 'A') {
3799 print "<td class=\"link\" align=\"right\"> | </td>\n";
3800 } elsif ($status eq 'D') {
3801 print "<td class=\"link\">" .
3802 $cgi->a({-href
=> href
(action
=>"blob",
3805 file_name
=>$from_path)},
3809 if ($diff->{'to_id'} eq $from_hash) {
3810 print "<td class=\"link nochange\">";
3812 print "<td class=\"link\">";
3814 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3815 hash
=>$diff->{'to_id'},
3816 hash_parent
=>$from_hash,
3818 hash_parent_base
=>$hash_parent,
3819 file_name
=>$diff->{'to_file'},
3820 file_parent
=>$from_path)},
3826 print "<td class=\"link\">";
3828 print $cgi->a({-href
=> href
(action
=>"blob",
3829 hash
=>$diff->{'to_id'},
3830 file_name
=>$diff->{'to_file'},
3833 print " | " if ($has_history);
3836 print $cgi->a({-href
=> href
(action
=>"history",
3837 file_name
=>$diff->{'to_file'},
3844 next; # instead of 'else' clause, to avoid extra indent
3846 # else ordinary diff
3848 my ($to_mode_oct, $to_mode_str, $to_file_type);
3849 my ($from_mode_oct, $from_mode_str, $from_file_type);
3850 if ($diff->{'to_mode'} ne ('0' x
6)) {
3851 $to_mode_oct = oct $diff->{'to_mode'};
3852 if (S_ISREG
($to_mode_oct)) { # only for regular file
3853 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3855 $to_file_type = file_type
($diff->{'to_mode'});
3857 if ($diff->{'from_mode'} ne ('0' x
6)) {
3858 $from_mode_oct = oct $diff->{'from_mode'};
3859 if (S_ISREG
($to_mode_oct)) { # only for regular file
3860 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3862 $from_file_type = file_type
($diff->{'from_mode'});
3865 if ($diff->{'status'} eq "A") { # created
3866 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3867 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3868 $mode_chng .= "]</span>";
3870 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3871 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3872 -class => "list"}, esc_path
($diff->{'file'}));
3874 print "<td>$mode_chng</td>\n";
3875 print "<td class=\"link\">";
3876 if ($action eq 'commitdiff') {
3879 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3882 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3883 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3887 } elsif ($diff->{'status'} eq "D") { # deleted
3888 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3890 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3891 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3892 -class => "list"}, esc_path
($diff->{'file'}));
3894 print "<td>$mode_chng</td>\n";
3895 print "<td class=\"link\">";
3896 if ($action eq 'commitdiff') {
3899 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3902 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3903 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3906 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3907 file_name
=>$diff->{'file'})},
3910 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3911 file_name
=>$diff->{'file'})},
3915 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3916 my $mode_chnge = "";
3917 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3918 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3919 if ($from_file_type ne $to_file_type) {
3920 $mode_chnge .= " from $from_file_type to $to_file_type";
3922 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3923 if ($from_mode_str && $to_mode_str) {
3924 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3925 } elsif ($to_mode_str) {
3926 $mode_chnge .= " mode: $to_mode_str";
3929 $mode_chnge .= "]</span>\n";
3932 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3933 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3934 -class => "list"}, esc_path
($diff->{'file'}));
3936 print "<td>$mode_chnge</td>\n";
3937 print "<td class=\"link\">";
3938 if ($action eq 'commitdiff') {
3941 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3943 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3944 # "commit" view and modified file (not onlu mode changed)
3945 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3946 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3947 hash_base
=>$hash, hash_parent_base
=>$parent,
3948 file_name
=>$diff->{'file'})},
3952 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3953 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3956 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3957 file_name
=>$diff->{'file'})},
3960 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3961 file_name
=>$diff->{'file'})},
3965 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3966 my %status_name = ('R' => 'moved', 'C' => 'copied');
3967 my $nstatus = $status_name{$diff->{'status'}};
3969 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3970 # mode also for directories, so we cannot use $to_mode_str
3971 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3974 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3975 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3976 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3977 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3978 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3979 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3980 -class => "list"}, esc_path
($diff->{'from_file'})) .
3981 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3982 "<td class=\"link\">";
3983 if ($action eq 'commitdiff') {
3986 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3988 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3989 # "commit" view and modified file (not only pure rename or copy)
3990 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3991 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3992 hash_base
=>$hash, hash_parent_base
=>$parent,
3993 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3997 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3998 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4001 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4002 file_name
=>$diff->{'to_file'})},
4005 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4006 file_name
=>$diff->{'to_file'})},
4010 } # we should not encounter Unmerged (U) or Unknown (X) status
4013 print "</tbody>" if $has_header;
4017 sub git_patchset_body
{
4018 my ($fd, $difftree, $hash, @hash_parents) = @_;
4019 my ($hash_parent) = $hash_parents[0];
4021 my $is_combined = (@hash_parents > 1);
4023 my $patch_number = 0;
4029 print "<div class=\"patchset\">\n";
4031 # skip to first patch
4032 while ($patch_line = <$fd>) {
4035 last if ($patch_line =~ m/^diff /);
4039 while ($patch_line) {
4041 # parse "git diff" header line
4042 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4043 # $1 is from_name, which we do not use
4044 $to_name = unquote
($2);
4045 $to_name =~ s!^b/!!;
4046 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4047 # $1 is 'cc' or 'combined', which we do not use
4048 $to_name = unquote
($2);
4053 # check if current patch belong to current raw line
4054 # and parse raw git-diff line if needed
4055 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4056 # this is continuation of a split patch
4057 print "<div class=\"patch cont\">\n";
4059 # advance raw git-diff output if needed
4060 $patch_idx++ if defined $diffinfo;
4062 # read and prepare patch information
4063 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4065 # compact combined diff output can have some patches skipped
4066 # find which patch (using pathname of result) we are at now;
4068 while ($to_name ne $diffinfo->{'to_file'}) {
4069 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4070 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4071 "</div>\n"; # class="patch"
4076 last if $patch_idx > $#$difftree;
4077 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4081 # modifies %from, %to hashes
4082 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4084 # this is first patch for raw difftree line with $patch_idx index
4085 # we index @$difftree array from 0, but number patches from 1
4086 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4090 #assert($patch_line =~ m/^diff /) if DEBUG;
4091 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4093 # print "git diff" header
4094 print format_git_diff_header_line
($patch_line, $diffinfo,
4097 # print extended diff header
4098 print "<div class=\"diff extended_header\">\n";
4100 while ($patch_line = <$fd>) {
4103 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4105 print format_extended_diff_header_line
($patch_line, $diffinfo,
4108 print "</div>\n"; # class="diff extended_header"
4110 # from-file/to-file diff header
4111 if (! $patch_line) {
4112 print "</div>\n"; # class="patch"
4115 next PATCH
if ($patch_line =~ m/^diff /);
4116 #assert($patch_line =~ m/^---/) if DEBUG;
4118 my $last_patch_line = $patch_line;
4119 $patch_line = <$fd>;
4121 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4123 print format_diff_from_to_header
($last_patch_line, $patch_line,
4124 $diffinfo, \
%from, \
%to,
4129 while ($patch_line = <$fd>) {
4132 next PATCH
if ($patch_line =~ m/^diff /);
4134 print format_diff_line
($patch_line, \
%from, \
%to);
4138 print "</div>\n"; # class="patch"
4141 # for compact combined (--cc) format, with chunk and patch simpliciaction
4142 # patchset might be empty, but there might be unprocessed raw lines
4143 for (++$patch_idx if $patch_number > 0;
4144 $patch_idx < @
$difftree;
4146 # read and prepare patch information
4147 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4149 # generate anchor for "patch" links in difftree / whatchanged part
4150 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4151 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4152 "</div>\n"; # class="patch"
4157 if ($patch_number == 0) {
4158 if (@hash_parents > 1) {
4159 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4161 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4165 print "</div>\n"; # class="patchset"
4168 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4170 # fills project list info (age, description, owner, forks) for each
4171 # project in the list, removing invalid projects from returned list
4172 # NOTE: modifies $projlist, but does not remove entries from it
4173 sub fill_project_list_info
{
4174 my ($projlist, $check_forks) = @_;
4177 my $show_ctags = gitweb_check_feature
('ctags');
4179 foreach my $pr (@
$projlist) {
4180 my (@activity) = git_get_last_activity
($pr->{'path'});
4181 unless (@activity) {
4184 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4185 if (!defined $pr->{'descr'}) {
4186 my $descr = git_get_project_description
($pr->{'path'}) || "";
4187 $descr = to_utf8
($descr);
4188 $pr->{'descr_long'} = $descr;
4189 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4191 if (!defined $pr->{'owner'}) {
4192 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4195 my $pname = $pr->{'path'};
4196 if (($pname =~ s/\.git$//) &&
4197 ($pname !~ /\/$/) &&
4198 (-d
"$projectroot/$pname")) {
4199 $pr->{'forks'} = "-d $projectroot/$pname";
4204 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4205 push @projects, $pr;
4211 # print 'sort by' <th> element, generating 'sort by $name' replay link
4212 # if that order is not selected
4214 my ($name, $order, $header) = @_;
4215 $header ||= ucfirst($name);
4217 if ($order eq $name) {
4218 print "<th>$header</th>\n";
4221 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4222 -class => "header"}, $header) .
4227 sub git_project_list_body
{
4228 # actually uses global variable $project
4229 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4231 my $check_forks = gitweb_check_feature
('forks');
4232 my @projects = fill_project_list_info
($projlist, $check_forks);
4234 $order ||= $default_projects_order;
4235 $from = 0 unless defined $from;
4236 $to = $#projects if (!defined $to || $#projects < $to);
4239 project
=> { key
=> 'path', type
=> 'str' },
4240 descr
=> { key
=> 'descr_long', type
=> 'str' },
4241 owner
=> { key
=> 'owner', type
=> 'str' },
4242 age
=> { key
=> 'age', type
=> 'num' }
4244 my $oi = $order_info{$order};
4245 if ($oi->{'type'} eq 'str') {
4246 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4248 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4251 my $show_ctags = gitweb_check_feature
('ctags');
4254 foreach my $p (@projects) {
4255 foreach my $ct (keys %{$p->{'ctags'}}) {
4256 $ctags{$ct} += $p->{'ctags'}->{$ct};
4259 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4260 print git_show_project_tagcloud
($cloud, 64);
4263 print "<table class=\"project_list\">\n";
4264 unless ($no_header) {
4267 print "<th></th>\n";
4269 print_sort_th
('project', $order, 'Project');
4270 print_sort_th
('descr', $order, 'Description');
4271 print_sort_th
('owner', $order, 'Owner');
4272 print_sort_th
('age', $order, 'Last Change');
4273 print "<th></th>\n" . # for links
4277 my $tagfilter = $cgi->param('by_tag');
4278 for (my $i = $from; $i <= $to; $i++) {
4279 my $pr = $projects[$i];
4281 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4282 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4283 and not $pr->{'descr_long'} =~ /$searchtext/;
4284 # Weed out forks or non-matching entries of search
4286 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4287 $forkbase="^$forkbase" if $forkbase;
4288 next if not $searchtext and not $tagfilter and $show_ctags
4289 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4293 print "<tr class=\"dark\">\n";
4295 print "<tr class=\"light\">\n";
4300 if ($pr->{'forks'}) {
4301 print "<!-- $pr->{'forks'} -->\n";
4302 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4306 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4307 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4308 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4309 -class => "list", -title
=> $pr->{'descr_long'}},
4310 esc_html
($pr->{'descr'})) . "</td>\n" .
4311 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4312 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4313 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4314 "<td class=\"link\">" .
4315 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4316 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4317 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4318 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4319 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4323 if (defined $extra) {
4326 print "<td></td>\n";
4328 print "<td colspan=\"5\">$extra</td>\n" .
4334 sub git_shortlog_body
{
4335 # uses global variable $project
4336 my ($commitlist, $from, $to, $refs, $extra) = @_;
4338 $from = 0 unless defined $from;
4339 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4341 print "<table class=\"shortlog\">\n";
4343 for (my $i = $from; $i <= $to; $i++) {
4344 my %co = %{$commitlist->[$i]};
4345 my $commit = $co{'id'};
4346 my $ref = format_ref_marker
($refs, $commit);
4348 print "<tr class=\"dark\">\n";
4350 print "<tr class=\"light\">\n";
4353 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4354 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4355 format_author_html
('td', \
%co, 10) . "<td>";
4356 print format_subject_html
($co{'title'}, $co{'title_short'},
4357 href
(action
=>"commit", hash
=>$commit), $ref);
4359 "<td class=\"link\">" .
4360 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4361 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4362 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4363 my $snapshot_links = format_snapshot_links
($commit);
4364 if (defined $snapshot_links) {
4365 print " | " . $snapshot_links;
4370 if (defined $extra) {
4372 "<td colspan=\"4\">$extra</td>\n" .
4378 sub git_history_body
{
4379 # Warning: assumes constant type (blob or tree) during history
4380 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4382 $from = 0 unless defined $from;
4383 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4385 print "<table class=\"history\">\n";
4387 for (my $i = $from; $i <= $to; $i++) {
4388 my %co = %{$commitlist->[$i]};
4392 my $commit = $co{'id'};
4394 my $ref = format_ref_marker
($refs, $commit);
4397 print "<tr class=\"dark\">\n";
4399 print "<tr class=\"light\">\n";
4402 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4403 # shortlog: format_author_html('td', \%co, 10)
4404 format_author_html
('td', \
%co, 15, 3) . "<td>";
4405 # originally git_history used chop_str($co{'title'}, 50)
4406 print format_subject_html
($co{'title'}, $co{'title_short'},
4407 href
(action
=>"commit", hash
=>$commit), $ref);
4409 "<td class=\"link\">" .
4410 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4411 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4413 if ($ftype eq 'blob') {
4414 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4415 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4416 if (defined $blob_current && defined $blob_parent &&
4417 $blob_current ne $blob_parent) {
4419 $cgi->a({-href
=> href
(action
=>"blobdiff",
4420 hash
=>$blob_current, hash_parent
=>$blob_parent,
4421 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4422 file_name
=>$file_name)},
4429 if (defined $extra) {
4431 "<td colspan=\"4\">$extra</td>\n" .
4438 # uses global variable $project
4439 my ($taglist, $from, $to, $extra) = @_;
4440 $from = 0 unless defined $from;
4441 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4443 print "<table class=\"tags\">\n";
4445 for (my $i = $from; $i <= $to; $i++) {
4446 my $entry = $taglist->[$i];
4448 my $comment = $tag{'subject'};
4450 if (defined $comment) {
4451 $comment_short = chop_str
($comment, 30, 5);
4454 print "<tr class=\"dark\">\n";
4456 print "<tr class=\"light\">\n";
4459 if (defined $tag{'age'}) {
4460 print "<td><i>$tag{'age'}</i></td>\n";
4462 print "<td></td>\n";
4465 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4466 -class => "list name"}, esc_html
($tag{'name'})) .
4469 if (defined $comment) {
4470 print format_subject_html
($comment, $comment_short,
4471 href
(action
=>"tag", hash
=>$tag{'id'}));
4474 "<td class=\"selflink\">";
4475 if ($tag{'type'} eq "tag") {
4476 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4481 "<td class=\"link\">" . " | " .
4482 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4483 if ($tag{'reftype'} eq "commit") {
4484 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4485 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4486 } elsif ($tag{'reftype'} eq "blob") {
4487 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4492 if (defined $extra) {
4494 "<td colspan=\"5\">$extra</td>\n" .
4500 sub git_heads_body
{
4501 # uses global variable $project
4502 my ($headlist, $head, $from, $to, $extra) = @_;
4503 $from = 0 unless defined $from;
4504 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4506 print "<table class=\"heads\">\n";
4508 for (my $i = $from; $i <= $to; $i++) {
4509 my $entry = $headlist->[$i];
4511 my $curr = $ref{'id'} eq $head;
4513 print "<tr class=\"dark\">\n";
4515 print "<tr class=\"light\">\n";
4518 print "<td><i>$ref{'age'}</i></td>\n" .
4519 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4520 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4521 -class => "list name"},esc_html
($ref{'name'})) .
4523 "<td class=\"link\">" .
4524 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4525 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4526 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4530 if (defined $extra) {
4532 "<td colspan=\"3\">$extra</td>\n" .
4538 sub git_search_grep_body
{
4539 my ($commitlist, $from, $to, $extra) = @_;
4540 $from = 0 unless defined $from;
4541 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4543 print "<table class=\"commit_search\">\n";
4545 for (my $i = $from; $i <= $to; $i++) {
4546 my %co = %{$commitlist->[$i]};
4550 my $commit = $co{'id'};
4552 print "<tr class=\"dark\">\n";
4554 print "<tr class=\"light\">\n";
4557 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4558 format_author_html
('td', \
%co, 15, 5) .
4560 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4561 -class => "list subject"},
4562 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4563 my $comment = $co{'comment'};
4564 foreach my $line (@
$comment) {
4565 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4566 my ($lead, $match, $trail) = ($1, $2, $3);
4567 $match = chop_str
($match, 70, 5, 'center');
4568 my $contextlen = int((80 - length($match))/2);
4569 $contextlen = 30 if ($contextlen > 30);
4570 $lead = chop_str
($lead, $contextlen, 10, 'left');
4571 $trail = chop_str
($trail, $contextlen, 10, 'right');
4573 $lead = esc_html
($lead);
4574 $match = esc_html
($match);
4575 $trail = esc_html
($trail);
4577 print "$lead<span class=\"match\">$match</span>$trail<br />";
4581 "<td class=\"link\">" .
4582 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4584 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4586 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4590 if (defined $extra) {
4592 "<td colspan=\"3\">$extra</td>\n" .
4598 ## ======================================================================
4599 ## ======================================================================
4602 sub git_project_list
{
4603 my $order = $input_params{'order'};
4604 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4605 die_error
(400, "Unknown order parameter");
4608 my @list = git_get_projects_list
();
4610 die_error
(404, "No projects found");
4614 if (-f
$home_text) {
4615 print "<div class=\"index_include\">\n";
4616 insert_file
($home_text);
4619 print $cgi->startform(-method
=> "get") .
4620 "<p class=\"projsearch\">Search:\n" .
4621 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4623 $cgi->end_form() . "\n";
4624 git_project_list_body
(\
@list, $order);
4629 my $order = $input_params{'order'};
4630 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4631 die_error
(400, "Unknown order parameter");
4634 my @list = git_get_projects_list
($project);
4636 die_error
(404, "No forks found");
4640 git_print_page_nav
('','');
4641 git_print_header_div
('summary', "$project forks");
4642 git_project_list_body
(\
@list, $order);
4646 sub git_project_index
{
4647 my @projects = git_get_projects_list
($project);
4650 -type
=> 'text/plain',
4651 -charset
=> 'utf-8',
4652 -content_disposition
=> 'inline; filename="index.aux"');
4654 foreach my $pr (@projects) {
4655 if (!exists $pr->{'owner'}) {
4656 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4659 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4660 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4661 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4662 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4666 print "$path $owner\n";
4671 my $descr = git_get_project_description
($project) || "none";
4672 my %co = parse_commit
("HEAD");
4673 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4674 my $head = $co{'id'};
4676 my $owner = git_get_project_owner
($project);
4678 my $refs = git_get_references
();
4679 # These get_*_list functions return one more to allow us to see if
4680 # there are more ...
4681 my @taglist = git_get_tags_list
(16);
4682 my @headlist = git_get_heads_list
(16);
4684 my $check_forks = gitweb_check_feature
('forks');
4687 @forklist = git_get_projects_list
($project);
4691 git_print_page_nav
('summary','', $head);
4693 print "<div class=\"title\"> </div>\n";
4694 print "<table class=\"projects_list\">\n" .
4695 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4696 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4697 if (defined $cd{'rfc2822'}) {
4698 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4701 # use per project git URL list in $projectroot/$project/cloneurl
4702 # or make project git URL from git base URL and project name
4703 my $url_tag = "URL";
4704 my @url_list = git_get_project_url_list
($project);
4705 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4706 foreach my $git_url (@url_list) {
4707 next unless $git_url;
4708 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4713 my $show_ctags = gitweb_check_feature
('ctags');
4715 my $ctags = git_get_project_ctags
($project);
4716 my $cloud = git_populate_project_tagcloud
($ctags);
4717 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4718 print "</td>\n<td>" unless %$ctags;
4719 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4720 print "</td>\n<td>" if %$ctags;
4721 print git_show_project_tagcloud
($cloud, 48);
4727 # If XSS prevention is on, we don't include README.html.
4728 # TODO: Allow a readme in some safe format.
4729 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4730 print "<div class=\"title\">readme</div>\n" .
4731 "<div class=\"readme\">\n";
4732 insert_file
("$projectroot/$project/README.html");
4733 print "\n</div>\n"; # class="readme"
4736 # we need to request one more than 16 (0..15) to check if
4738 my @commitlist = $head ? parse_commits
($head, 17) : ();
4740 git_print_header_div
('shortlog');
4741 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4742 $#commitlist <= 15 ?
undef :
4743 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4747 git_print_header_div
('tags');
4748 git_tags_body
(\
@taglist, 0, 15,
4749 $#taglist <= 15 ?
undef :
4750 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4754 git_print_header_div
('heads');
4755 git_heads_body
(\
@headlist, $head, 0, 15,
4756 $#headlist <= 15 ?
undef :
4757 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4761 git_print_header_div
('forks');
4762 git_project_list_body
(\
@forklist, 'age', 0, 15,
4763 $#forklist <= 15 ?
undef :
4764 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4772 my $head = git_get_head_hash
($project);
4774 git_print_page_nav
('','', $head,undef,$head);
4775 my %tag = parse_tag
($hash);
4778 die_error
(404, "Unknown tag object");
4781 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4782 print "<div class=\"title_text\">\n" .
4783 "<table class=\"object_header\">\n" .
4785 "<td>object</td>\n" .
4786 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4787 $tag{'object'}) . "</td>\n" .
4788 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4789 $tag{'type'}) . "</td>\n" .
4791 if (defined($tag{'author'})) {
4792 git_print_authorship_rows
(\
%tag, 'author');
4794 print "</table>\n\n" .
4796 print "<div class=\"page_body\">";
4797 my $comment = $tag{'comment'};
4798 foreach my $line (@
$comment) {
4800 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4808 gitweb_check_feature
('blame')
4809 or die_error
(403, "Blame view not allowed");
4812 die_error
(400, "No file name given") unless $file_name;
4813 $hash_base ||= git_get_head_hash
($project);
4814 die_error
(404, "Couldn't find base commit") unless $hash_base;
4815 my %co = parse_commit
($hash_base)
4816 or die_error
(404, "Commit not found");
4818 if (!defined $hash) {
4819 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4820 or die_error
(404, "Error looking up file");
4822 $ftype = git_get_type
($hash);
4823 if ($ftype !~ "blob") {
4824 die_error
(400, "Object is not a blob");
4828 # run git-blame --porcelain
4829 open my $fd, "-|", git_cmd
(), "blame", '-p',
4830 $hash_base, '--', $file_name
4831 or die_error
(500, "Open git-blame failed");
4836 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4839 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4842 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4844 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4845 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4846 git_print_page_path
($file_name, $ftype, $hash_base);
4849 my @rev_color = qw(light dark);
4850 my $num_colors = scalar(@rev_color);
4851 my $current_color = 0;
4855 <div class="page_body">
4856 <table class="blame">
4857 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4860 while (my $line = <$fd>) {
4862 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4863 # no <lines in group> for subsequent lines in group of lines
4864 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4865 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4866 if (!exists $metainfo{$full_rev}) {
4867 $metainfo{$full_rev} = { 'nprevious' => 0 };
4869 my $meta = $metainfo{$full_rev};
4871 while ($data = <$fd>) {
4873 last if ($data =~ s/^\t//); # contents of line
4874 if ($data =~ /^(\S+)(?: (.*))?$/) {
4875 $meta->{$1} = $2 unless exists $meta->{$1};
4877 if ($data =~ /^previous /) {
4878 $meta->{'nprevious'}++;
4881 my $short_rev = substr($full_rev, 0, 8);
4882 my $author = $meta->{'author'};
4884 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4885 my $date = $date{'iso-tz'};
4887 $current_color = ($current_color + 1) % $num_colors;
4889 my $tr_class = $rev_color[$current_color];
4890 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4891 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4892 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4893 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4895 print "<td class=\"sha1\"";
4896 print " title=\"". esc_html
($author) . ", $date\"";
4897 print " rowspan=\"$group_size\"" if ($group_size > 1);
4899 print $cgi->a({-href
=> href
(action
=>"commit",
4901 file_name
=>$file_name)},
4902 esc_html
($short_rev));
4903 if ($group_size >= 2) {
4904 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
4905 if (@author_initials) {
4907 esc_html
(join('', @author_initials));
4913 # 'previous' <sha1 of parent commit> <filename at commit>
4914 if (exists $meta->{'previous'} &&
4915 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
4916 $meta->{'parent'} = $1;
4917 $meta->{'file_parent'} = unquote
($2);
4920 exists($meta->{'parent'}) ?
4921 $meta->{'parent'} : $full_rev;
4922 my $linenr_filename =
4923 exists($meta->{'file_parent'}) ?
4924 $meta->{'file_parent'} : unquote
($meta->{'filename'});
4925 my $blamed = href
(action
=> 'blame',
4926 file_name
=> $linenr_filename,
4927 hash_base
=> $linenr_commit);
4928 print "<td class=\"linenr\">";
4929 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4930 -class => "linenr" },
4933 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4939 or print "Reading blob failed\n";
4946 my $head = git_get_head_hash
($project);
4948 git_print_page_nav
('','', $head,undef,$head);
4949 git_print_header_div
('summary', $project);
4951 my @tagslist = git_get_tags_list
();
4953 git_tags_body
(\
@tagslist);
4959 my $head = git_get_head_hash
($project);
4961 git_print_page_nav
('','', $head,undef,$head);
4962 git_print_header_div
('summary', $project);
4964 my @headslist = git_get_heads_list
();
4966 git_heads_body
(\
@headslist, $head);
4971 sub git_blob_plain
{
4975 if (!defined $hash) {
4976 if (defined $file_name) {
4977 my $base = $hash_base || git_get_head_hash
($project);
4978 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4979 or die_error
(404, "Cannot find file");
4981 die_error
(400, "No file name defined");
4983 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4984 # blobs defined by non-textual hash id's can be cached
4988 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4989 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4991 # content-type (can include charset)
4992 $type = blob_contenttype
($fd, $file_name, $type);
4994 # "save as" filename, even when no $file_name is given
4995 my $save_as = "$hash";
4996 if (defined $file_name) {
4997 $save_as = $file_name;
4998 } elsif ($type =~ m/^text\//) {
5002 # With XSS prevention on, blobs of all types except a few known safe
5003 # ones are served with "Content-Disposition: attachment" to make sure
5004 # they don't run in our security domain. For certain image types,
5005 # blob view writes an <img> tag referring to blob_plain view, and we
5006 # want to be sure not to break that by serving the image as an
5007 # attachment (though Firefox 3 doesn't seem to care).
5008 my $sandbox = $prevent_xss &&
5009 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5013 -expires
=> $expires,
5014 -content_disposition
=>
5015 ($sandbox ?
'attachment' : 'inline')
5016 . '; filename="' . $save_as . '"');
5018 binmode STDOUT
, ':raw';
5020 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5027 if (!defined $hash) {
5028 if (defined $file_name) {
5029 my $base = $hash_base || git_get_head_hash
($project);
5030 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5031 or die_error
(404, "Cannot find file");
5033 die_error
(400, "No file name defined");
5035 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5036 # blobs defined by non-textual hash id's can be cached
5040 my $have_blame = gitweb_check_feature
('blame');
5041 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5042 or die_error
(500, "Couldn't cat $file_name, $hash");
5043 my $mimetype = blob_mimetype
($fd, $file_name);
5044 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5046 return git_blob_plain
($mimetype);
5048 # we can have blame only for text/* mimetype
5049 $have_blame &&= ($mimetype =~ m!^text/!);
5051 git_header_html
(undef, $expires);
5052 my $formats_nav = '';
5053 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5054 if (defined $file_name) {
5057 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5062 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5065 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5068 $cgi->a({-href
=> href
(action
=>"blob",
5069 hash_base
=>"HEAD", file_name
=>$file_name)},
5073 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5076 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5077 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5079 print "<div class=\"page_nav\">\n" .
5080 "<br/><br/></div>\n" .
5081 "<div class=\"title\">$hash</div>\n";
5083 git_print_page_path
($file_name, "blob", $hash_base);
5084 print "<div class=\"page_body\">\n";
5085 if ($mimetype =~ m!^image/!) {
5086 print qq!<img type
="$mimetype"!;
5088 print qq! alt
="$file_name" title
="$file_name"!;
5091 href(action=>"blob_plain
", hash=>$hash,
5092 hash_base=>$hash_base, file_name=>$file_name) .
5096 while (my $line = <$fd>) {
5099 $line = untabify
($line);
5100 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5101 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5105 or print "Reading blob failed.\n";
5111 if (!defined $hash_base) {
5112 $hash_base = "HEAD";
5114 if (!defined $hash) {
5115 if (defined $file_name) {
5116 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5121 die_error
(404, "No such tree") unless defined($hash);
5123 my $show_sizes = gitweb_check_feature
('show-sizes');
5124 my $have_blame = gitweb_check_feature
('blame');
5129 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5130 ($show_sizes ?
'-l' : ()), @extra_options, $hash
5131 or die_error
(500, "Open git-ls-tree failed");
5132 @entries = map { chomp; $_ } <$fd>;
5134 or die_error
(404, "Reading tree failed");
5137 my $refs = git_get_references
();
5138 my $ref = format_ref_marker
($refs, $hash_base);
5141 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5143 if (defined $file_name) {
5145 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5147 $cgi->a({-href
=> href
(action
=>"tree",
5148 hash_base
=>"HEAD", file_name
=>$file_name)},
5151 my $snapshot_links = format_snapshot_links
($hash);
5152 if (defined $snapshot_links) {
5153 # FIXME: Should be available when we have no hash base as well.
5154 push @views_nav, $snapshot_links;
5156 git_print_page_nav
('tree','', $hash_base, undef, undef,
5157 join(' | ', @views_nav));
5158 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5161 print "<div class=\"page_nav\">\n";
5162 print "<br/><br/></div>\n";
5163 print "<div class=\"title\">$hash</div>\n";
5165 if (defined $file_name) {
5166 $basedir = $file_name;
5167 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5170 git_print_page_path
($file_name, 'tree', $hash_base);
5172 print "<div class=\"page_body\">\n";
5173 print "<table class=\"tree\">\n";
5175 # '..' (top directory) link if possible
5176 if (defined $hash_base &&
5177 defined $file_name && $file_name =~ m![^/]+$!) {
5179 print "<tr class=\"dark\">\n";
5181 print "<tr class=\"light\">\n";
5185 my $up = $file_name;
5186 $up =~ s!/?[^/]+$!!;
5187 undef $up unless $up;
5188 # based on git_print_tree_entry
5189 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5190 print '<td class="size"> </td>'."\n" if $show_sizes;
5191 print '<td class="list">';
5192 print $cgi->a({-href
=> href
(action
=>"tree",
5193 hash_base
=>$hash_base,
5197 print "<td class=\"link\"></td>\n";
5201 foreach my $line (@entries) {
5202 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5205 print "<tr class=\"dark\">\n";
5207 print "<tr class=\"light\">\n";
5211 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5215 print "</table>\n" .
5221 my $format = $input_params{'snapshot_format'};
5222 if (!@snapshot_fmts) {
5223 die_error
(403, "Snapshots not allowed");
5225 # default to first supported snapshot format
5226 $format ||= $snapshot_fmts[0];
5227 if ($format !~ m/^[a-z0-9]+$/) {
5228 die_error
(400, "Invalid snapshot format parameter");
5229 } elsif (!exists($known_snapshot_formats{$format})) {
5230 die_error
(400, "Unknown snapshot format");
5231 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5232 die_error
(403, "Snapshot format not allowed");
5233 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5234 die_error
(403, "Unsupported snapshot format");
5237 if (!defined $hash) {
5238 $hash = git_get_head_hash
($project);
5241 my $name = $project;
5242 $name =~ s
,([^/])/*\
.git
$,$1,;
5243 $name = basename
($name);
5244 my $filename = to_utf8
($name);
5245 $name =~ s/\047/\047\\\047\047/g;
5247 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5248 $cmd = quote_command
(
5249 git_cmd
(), 'archive',
5250 "--format=$known_snapshot_formats{$format}{'format'}",
5251 "--prefix=$name/", $hash);
5252 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5253 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5257 -type
=> $known_snapshot_formats{$format}{'type'},
5258 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5259 -status
=> '200 OK');
5261 open my $fd, "-|", $cmd
5262 or die_error
(500, "Execute git-archive failed");
5263 binmode STDOUT
, ':raw';
5265 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5270 my $head = git_get_head_hash
($project);
5271 if (!defined $hash) {
5274 if (!defined $page) {
5277 my $refs = git_get_references
();
5279 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5281 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5283 my ($patch_max) = gitweb_get_feature
('patches');
5285 if ($patch_max < 0 || @commitlist <= $patch_max) {
5286 $paging_nav .= " ⋅ " .
5287 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5293 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5296 my %co = parse_commit
($hash);
5298 git_print_header_div
('summary', $project);
5299 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5301 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5302 for (my $i = 0; $i <= $to; $i++) {
5303 my %co = %{$commitlist[$i]};
5305 my $commit = $co{'id'};
5306 my $ref = format_ref_marker
($refs, $commit);
5307 my %ad = parse_date
($co{'author_epoch'});
5308 git_print_header_div
('commit',
5309 "<span class=\"age\">$co{'age_string'}</span>" .
5310 esc_html
($co{'title'}) . $ref,
5312 print "<div class=\"title_text\">\n" .
5313 "<div class=\"log_link\">\n" .
5314 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5316 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5318 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5321 git_print_authorship
(\
%co, -tag
=> 'span');
5322 print "<br/>\n</div>\n";
5324 print "<div class=\"log_body\">\n";
5325 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5328 if ($#commitlist >= 100) {
5329 print "<div class=\"page_nav\">\n";
5330 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5331 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5338 $hash ||= $hash_base || "HEAD";
5339 my %co = parse_commit
($hash)
5340 or die_error
(404, "Unknown commit object");
5342 my $parent = $co{'parent'};
5343 my $parents = $co{'parents'}; # listref
5345 # we need to prepare $formats_nav before any parameter munging
5347 if (!defined $parent) {
5349 $formats_nav .= '(initial)';
5350 } elsif (@
$parents == 1) {
5351 # single parent commit
5354 $cgi->a({-href
=> href
(action
=>"commit",
5356 esc_html
(substr($parent, 0, 7))) .
5363 $cgi->a({-href
=> href
(action
=>"commit",
5365 esc_html
(substr($_, 0, 7)));
5369 if (gitweb_check_feature
('patches') && @
$parents <= 1) {
5370 $formats_nav .= " | " .
5371 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5375 if (!defined $parent) {
5379 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5381 (@
$parents <= 1 ?
$parent : '-c'),
5383 or die_error
(500, "Open git-diff-tree failed");
5384 @difftree = map { chomp; $_ } <$fd>;
5385 close $fd or die_error
(404, "Reading git-diff-tree failed");
5387 # non-textual hash id's can be cached
5389 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5392 my $refs = git_get_references
();
5393 my $ref = format_ref_marker
($refs, $co{'id'});
5395 git_header_html
(undef, $expires);
5396 git_print_page_nav
('commit', '',
5397 $hash, $co{'tree'}, $hash,
5400 if (defined $co{'parent'}) {
5401 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5403 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5405 print "<div class=\"title_text\">\n" .
5406 "<table class=\"object_header\">\n";
5407 git_print_authorship_rows
(\
%co);
5408 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5411 "<td class=\"sha1\">" .
5412 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5413 class => "list"}, $co{'tree'}) .
5415 "<td class=\"link\">" .
5416 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5418 my $snapshot_links = format_snapshot_links
($hash);
5419 if (defined $snapshot_links) {
5420 print " | " . $snapshot_links;
5425 foreach my $par (@
$parents) {
5428 "<td class=\"sha1\">" .
5429 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5430 class => "list"}, $par) .
5432 "<td class=\"link\">" .
5433 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5435 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5442 print "<div class=\"page_body\">\n";
5443 git_print_log
($co{'comment'});
5446 git_difftree_body
(\
@difftree, $hash, @
$parents);
5452 # object is defined by:
5453 # - hash or hash_base alone
5454 # - hash_base and file_name
5457 # - hash or hash_base alone
5458 if ($hash || ($hash_base && !defined $file_name)) {
5459 my $object_id = $hash || $hash_base;
5461 open my $fd, "-|", quote_command
(
5462 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5463 or die_error
(404, "Object does not exist");
5467 or die_error
(404, "Object does not exist");
5469 # - hash_base and file_name
5470 } elsif ($hash_base && defined $file_name) {
5471 $file_name =~ s
,/+$,,;
5473 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5474 or die_error
(404, "Base object does not exist");
5476 # here errors should not hapen
5477 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5478 or die_error
(500, "Open git-ls-tree failed");
5482 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5483 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5484 die_error
(404, "File or directory for given base does not exist");
5489 die_error
(400, "Not enough information to find object");
5492 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5493 hash
=>$hash, hash_base
=>$hash_base,
5494 file_name
=>$file_name),
5495 -status
=> '302 Found');
5499 my $format = shift || 'html';
5506 # preparing $fd and %diffinfo for git_patchset_body
5508 if (defined $hash_base && defined $hash_parent_base) {
5509 if (defined $file_name) {
5511 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5512 $hash_parent_base, $hash_base,
5513 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5514 or die_error
(500, "Open git-diff-tree failed");
5515 @difftree = map { chomp; $_ } <$fd>;
5517 or die_error
(404, "Reading git-diff-tree failed");
5519 or die_error
(404, "Blob diff not found");
5521 } elsif (defined $hash &&
5522 $hash =~ /[0-9a-fA-F]{40}/) {
5523 # try to find filename from $hash
5525 # read filtered raw output
5526 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5527 $hash_parent_base, $hash_base, "--"
5528 or die_error
(500, "Open git-diff-tree failed");
5530 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5532 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5533 map { chomp; $_ } <$fd>;
5535 or die_error
(404, "Reading git-diff-tree failed");
5537 or die_error
(404, "Blob diff not found");
5540 die_error
(400, "Missing one of the blob diff parameters");
5543 if (@difftree > 1) {
5544 die_error
(400, "Ambiguous blob diff specification");
5547 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5548 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5549 $file_name ||= $diffinfo{'to_file'};
5551 $hash_parent ||= $diffinfo{'from_id'};
5552 $hash ||= $diffinfo{'to_id'};
5554 # non-textual hash id's can be cached
5555 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5556 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5561 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5562 '-p', ($format eq 'html' ?
"--full-index" : ()),
5563 $hash_parent_base, $hash_base,
5564 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5565 or die_error
(500, "Open git-diff-tree failed");
5568 # old/legacy style URI -- not generated anymore since 1.4.3.
5570 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5574 if ($format eq 'html') {
5576 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5578 git_header_html
(undef, $expires);
5579 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5580 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5581 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5583 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5584 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5586 if (defined $file_name) {
5587 git_print_page_path
($file_name, "blob", $hash_base);
5589 print "<div class=\"page_path\"></div>\n";
5592 } elsif ($format eq 'plain') {
5594 -type
=> 'text/plain',
5595 -charset
=> 'utf-8',
5596 -expires
=> $expires,
5597 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5599 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5602 die_error
(400, "Unknown blobdiff format");
5606 if ($format eq 'html') {
5607 print "<div class=\"page_body\">\n";
5609 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5612 print "</div>\n"; # class="page_body"
5616 while (my $line = <$fd>) {
5617 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5618 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5622 last if $line =~ m!^\+\+\+!;
5630 sub git_blobdiff_plain
{
5631 git_blobdiff
('plain');
5634 sub git_commitdiff
{
5636 my $format = $params{-format
} || 'html';
5638 my ($patch_max) = gitweb_get_feature
('patches');
5639 if ($format eq 'patch') {
5640 die_error
(403, "Patch view not allowed") unless $patch_max;
5643 $hash ||= $hash_base || "HEAD";
5644 my %co = parse_commit
($hash)
5645 or die_error
(404, "Unknown commit object");
5647 # choose format for commitdiff for merge
5648 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5649 $hash_parent = '--cc';
5651 # we need to prepare $formats_nav before almost any parameter munging
5653 if ($format eq 'html') {
5655 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5657 if ($patch_max && @
{$co{'parents'}} <= 1) {
5658 $formats_nav .= " | " .
5659 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5663 if (defined $hash_parent &&
5664 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5665 # commitdiff with two commits given
5666 my $hash_parent_short = $hash_parent;
5667 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5668 $hash_parent_short = substr($hash_parent, 0, 7);
5672 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5673 if ($co{'parents'}[$i] eq $hash_parent) {
5674 $formats_nav .= ' parent ' . ($i+1);
5678 $formats_nav .= ': ' .
5679 $cgi->a({-href
=> href
(action
=>"commitdiff",
5680 hash
=>$hash_parent)},
5681 esc_html
($hash_parent_short)) .
5683 } elsif (!$co{'parent'}) {
5685 $formats_nav .= ' (initial)';
5686 } elsif (scalar @
{$co{'parents'}} == 1) {
5687 # single parent commit
5690 $cgi->a({-href
=> href
(action
=>"commitdiff",
5691 hash
=>$co{'parent'})},
5692 esc_html
(substr($co{'parent'}, 0, 7))) .
5696 if ($hash_parent eq '--cc') {
5697 $formats_nav .= ' | ' .
5698 $cgi->a({-href
=> href
(action
=>"commitdiff",
5699 hash
=>$hash, hash_parent
=>'-c')},
5701 } else { # $hash_parent eq '-c'
5702 $formats_nav .= ' | ' .
5703 $cgi->a({-href
=> href
(action
=>"commitdiff",
5704 hash
=>$hash, hash_parent
=>'--cc')},
5710 $cgi->a({-href
=> href
(action
=>"commitdiff",
5712 esc_html
(substr($_, 0, 7)));
5713 } @
{$co{'parents'}} ) .
5718 my $hash_parent_param = $hash_parent;
5719 if (!defined $hash_parent_param) {
5720 # --cc for multiple parents, --root for parentless
5721 $hash_parent_param =
5722 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5728 if ($format eq 'html') {
5729 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5730 "--no-commit-id", "--patch-with-raw", "--full-index",
5731 $hash_parent_param, $hash, "--"
5732 or die_error
(500, "Open git-diff-tree failed");
5734 while (my $line = <$fd>) {
5736 # empty line ends raw part of diff-tree output
5738 push @difftree, scalar parse_difftree_raw_line
($line);
5741 } elsif ($format eq 'plain') {
5742 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5743 '-p', $hash_parent_param, $hash, "--"
5744 or die_error
(500, "Open git-diff-tree failed");
5745 } elsif ($format eq 'patch') {
5746 # For commit ranges, we limit the output to the number of
5747 # patches specified in the 'patches' feature.
5748 # For single commits, we limit the output to a single patch,
5749 # diverging from the git-format-patch default.
5750 my @commit_spec = ();
5752 if ($patch_max > 0) {
5753 push @commit_spec, "-$patch_max";
5755 push @commit_spec, '-n', "$hash_parent..$hash";
5757 if ($params{-single
}) {
5758 push @commit_spec, '-1';
5760 if ($patch_max > 0) {
5761 push @commit_spec, "-$patch_max";
5763 push @commit_spec, "-n";
5765 push @commit_spec, '--root', $hash;
5767 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5768 '--stdout', @commit_spec
5769 or die_error
(500, "Open git-format-patch failed");
5771 die_error
(400, "Unknown commitdiff format");
5774 # non-textual hash id's can be cached
5776 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5780 # write commit message
5781 if ($format eq 'html') {
5782 my $refs = git_get_references
();
5783 my $ref = format_ref_marker
($refs, $co{'id'});
5785 git_header_html
(undef, $expires);
5786 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5787 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5788 print "<div class=\"title_text\">\n" .
5789 "<table class=\"object_header\">\n";
5790 git_print_authorship_rows
(\
%co);
5793 print "<div class=\"page_body\">\n";
5794 if (@
{$co{'comment'}} > 1) {
5795 print "<div class=\"log\">\n";
5796 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5797 print "</div>\n"; # class="log"
5800 } elsif ($format eq 'plain') {
5801 my $refs = git_get_references
("tags");
5802 my $tagname = git_get_rev_name_tags
($hash);
5803 my $filename = basename
($project) . "-$hash.patch";
5806 -type
=> 'text/plain',
5807 -charset
=> 'utf-8',
5808 -expires
=> $expires,
5809 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5810 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5811 print "From: " . to_utf8
($co{'author'}) . "\n";
5812 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5813 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5815 print "X-Git-Tag: $tagname\n" if $tagname;
5816 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5818 foreach my $line (@
{$co{'comment'}}) {
5819 print to_utf8
($line) . "\n";
5822 } elsif ($format eq 'patch') {
5823 my $filename = basename
($project) . "-$hash.patch";
5826 -type
=> 'text/plain',
5827 -charset
=> 'utf-8',
5828 -expires
=> $expires,
5829 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5833 if ($format eq 'html') {
5834 my $use_parents = !defined $hash_parent ||
5835 $hash_parent eq '-c' || $hash_parent eq '--cc';
5836 git_difftree_body
(\
@difftree, $hash,
5837 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5840 git_patchset_body
($fd, \
@difftree, $hash,
5841 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5843 print "</div>\n"; # class="page_body"
5846 } elsif ($format eq 'plain') {
5850 or print "Reading git-diff-tree failed\n";
5851 } elsif ($format eq 'patch') {
5855 or print "Reading git-format-patch failed\n";
5859 sub git_commitdiff_plain
{
5860 git_commitdiff
(-format
=> 'plain');
5863 # format-patch-style patches
5865 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5869 git_commitdiff
(-format
=> 'patch');
5873 if (!defined $hash_base) {
5874 $hash_base = git_get_head_hash
($project);
5876 if (!defined $page) {
5880 my %co = parse_commit
($hash_base)
5881 or die_error
(404, "Unknown commit object");
5883 my $refs = git_get_references
();
5884 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5886 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5887 $file_name, "--full-history")
5888 or die_error
(404, "No such file or directory on given branch");
5890 if (!defined $hash && defined $file_name) {
5891 # some commits could have deleted file in question,
5892 # and not have it in tree, but one of them has to have it
5893 for (my $i = 0; $i <= @commitlist; $i++) {
5894 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5895 last if defined $hash;
5898 if (defined $hash) {
5899 $ftype = git_get_type
($hash);
5901 if (!defined $ftype) {
5902 die_error
(500, "Unknown type of object");
5905 my $paging_nav = '';
5908 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5909 file_name
=>$file_name)},
5911 $paging_nav .= " ⋅ " .
5912 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5913 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5915 $paging_nav .= "first";
5916 $paging_nav .= " ⋅ prev";
5919 if ($#commitlist >= 100) {
5921 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5922 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5923 $paging_nav .= " ⋅ $next_link";
5925 $paging_nav .= " ⋅ next";
5929 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5930 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5931 git_print_page_path
($file_name, $ftype, $hash_base);
5933 git_history_body
(\
@commitlist, 0, 99,
5934 $refs, $hash_base, $ftype, $next_link);
5940 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5941 if (!defined $searchtext) {
5942 die_error
(400, "Text field is empty");
5944 if (!defined $hash) {
5945 $hash = git_get_head_hash
($project);
5947 my %co = parse_commit
($hash);
5949 die_error
(404, "Unknown commit object");
5951 if (!defined $page) {
5955 $searchtype ||= 'commit';
5956 if ($searchtype eq 'pickaxe') {
5957 # pickaxe may take all resources of your box and run for several minutes
5958 # with every query - so decide by yourself how public you make this feature
5959 gitweb_check_feature
('pickaxe')
5960 or die_error
(403, "Pickaxe is disabled");
5962 if ($searchtype eq 'grep') {
5963 gitweb_check_feature
('grep')
5964 or die_error
(403, "Grep is disabled");
5969 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5971 if ($searchtype eq 'commit') {
5972 $greptype = "--grep=";
5973 } elsif ($searchtype eq 'author') {
5974 $greptype = "--author=";
5975 } elsif ($searchtype eq 'committer') {
5976 $greptype = "--committer=";
5978 $greptype .= $searchtext;
5979 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5980 $greptype, '--regexp-ignore-case',
5981 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5983 my $paging_nav = '';
5986 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5987 searchtext
=>$searchtext,
5988 searchtype
=>$searchtype)},
5990 $paging_nav .= " ⋅ " .
5991 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5992 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5994 $paging_nav .= "first";
5995 $paging_nav .= " ⋅ prev";
5998 if ($#commitlist >= 100) {
6000 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6001 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6002 $paging_nav .= " ⋅ $next_link";
6004 $paging_nav .= " ⋅ next";
6007 if ($#commitlist >= 100) {
6010 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6011 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6012 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6015 if ($searchtype eq 'pickaxe') {
6016 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6017 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6019 print "<table class=\"pickaxe search\">\n";
6022 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6023 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6024 ($search_use_regexp ?
'--pickaxe-regex' : ());
6027 while (my $line = <$fd>) {
6031 my %set = parse_difftree_raw_line
($line);
6032 if (defined $set{'commit'}) {
6033 # finish previous commit
6036 "<td class=\"link\">" .
6037 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6039 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6045 print "<tr class=\"dark\">\n";
6047 print "<tr class=\"light\">\n";
6050 %co = parse_commit
($set{'commit'});
6051 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6052 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6053 "<td><i>$author</i></td>\n" .
6055 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6056 -class => "list subject"},
6057 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6058 } elsif (defined $set{'to_id'}) {
6059 next if ($set{'to_id'} =~ m/^0{40}$/);
6061 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6062 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6064 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6070 # finish last commit (warning: repetition!)
6073 "<td class=\"link\">" .
6074 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6076 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6084 if ($searchtype eq 'grep') {
6085 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6086 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6088 print "<table class=\"grep_search\">\n";
6092 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6093 $search_use_regexp ?
('-E', '-i') : '-F',
6094 $searchtext, $co{'tree'};
6096 while (my $line = <$fd>) {
6098 my ($file, $lno, $ltext, $binary);
6099 last if ($matches++ > 1000);
6100 if ($line =~ /^Binary file (.+) matches$/) {
6104 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6106 if ($file ne $lastfile) {
6107 $lastfile and print "</td></tr>\n";
6109 print "<tr class=\"dark\">\n";
6111 print "<tr class=\"light\">\n";
6113 print "<td class=\"list\">".
6114 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6115 file_name
=>"$file"),
6116 -class => "list"}, esc_path
($file));
6117 print "</td><td>\n";
6121 print "<div class=\"binary\">Binary file</div>\n";
6123 $ltext = untabify
($ltext);
6124 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6125 $ltext = esc_html
($1, -nbsp
=>1);
6126 $ltext .= '<span class="match">';
6127 $ltext .= esc_html
($2, -nbsp
=>1);
6128 $ltext .= '</span>';
6129 $ltext .= esc_html
($3, -nbsp
=>1);
6131 $ltext = esc_html
($ltext, -nbsp
=>1);
6133 print "<div class=\"pre\">" .
6134 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6135 file_name
=>"$file").'#l'.$lno,
6136 -class => "linenr"}, sprintf('%4i', $lno))
6137 . ' ' . $ltext . "</div>\n";
6141 print "</td></tr>\n";
6142 if ($matches > 1000) {
6143 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6146 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6155 sub git_search_help
{
6157 git_print_page_nav
('','', $hash,$hash,$hash);
6159 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6160 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6161 the pattern entered is recognized as the POSIX extended
6162 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6165 <dt><b>commit</b></dt>
6166 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6168 my $have_grep = gitweb_check_feature
('grep');
6171 <dt><b>grep</b></dt>
6172 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6173 a different one) are searched for the given pattern. On large trees, this search can take
6174 a while and put some strain on the server, so please use it with some consideration. Note that
6175 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6176 case-sensitive.</dd>
6180 <dt><b>author</b></dt>
6181 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6182 <dt><b>committer</b></dt>
6183 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6185 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6186 if ($have_pickaxe) {
6188 <dt><b>pickaxe</b></dt>
6189 <dd>All commits that caused the string to appear or disappear from any file (changes that
6190 added, removed or "modified" the string) will be listed. This search can take a while and
6191 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6192 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6200 my $head = git_get_head_hash
($project);
6201 if (!defined $hash) {
6204 if (!defined $page) {
6207 my $refs = git_get_references
();
6209 my $commit_hash = $hash;
6210 if (defined $hash_parent) {
6211 $commit_hash = "$hash_parent..$hash";
6213 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6215 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6217 if ($#commitlist >= 100) {
6219 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6220 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6222 my $patch_max = gitweb_check_feature
('patches');
6224 if ($patch_max < 0 || @commitlist <= $patch_max) {
6225 $paging_nav .= " ⋅ " .
6226 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6232 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6233 git_print_header_div
('summary', $project);
6235 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6240 ## ......................................................................
6241 ## feeds (RSS, Atom; OPML)
6244 my $format = shift || 'atom';
6245 my $have_blame = gitweb_check_feature
('blame');
6247 # Atom: http://www.atomenabled.org/developers/syndication/
6248 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6249 if ($format ne 'rss' && $format ne 'atom') {
6250 die_error
(400, "Unknown web feed format");
6253 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6254 my $head = $hash || 'HEAD';
6255 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6259 my $content_type = "application/$format+xml";
6260 if (defined $cgi->http('HTTP_ACCEPT') &&
6261 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6262 # browser (feed reader) prefers text/xml
6263 $content_type = 'text/xml';
6265 if (defined($commitlist[0])) {
6266 %latest_commit = %{$commitlist[0]};
6267 my $latest_epoch = $latest_commit{'committer_epoch'};
6268 %latest_date = parse_date
($latest_epoch);
6269 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6270 if (defined $if_modified) {
6272 if (eval { require HTTP
::Date
; 1; }) {
6273 $since = HTTP
::Date
::str2time
($if_modified);
6274 } elsif (eval { require Time
::ParseDate
; 1; }) {
6275 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6277 if (defined $since && $latest_epoch <= $since) {
6279 -type
=> $content_type,
6280 -charset
=> 'utf-8',
6281 -last_modified
=> $latest_date{'rfc2822'},
6282 -status
=> '304 Not Modified');
6287 -type
=> $content_type,
6288 -charset
=> 'utf-8',
6289 -last_modified
=> $latest_date{'rfc2822'});
6292 -type
=> $content_type,
6293 -charset
=> 'utf-8');
6296 # Optimization: skip generating the body if client asks only
6297 # for Last-Modified date.
6298 return if ($cgi->request_method() eq 'HEAD');
6301 my $title = "$site_name - $project/$action";
6302 my $feed_type = 'log';
6303 if (defined $hash) {
6304 $title .= " - '$hash'";
6305 $feed_type = 'branch log';
6306 if (defined $file_name) {
6307 $title .= " :: $file_name";
6308 $feed_type = 'history';
6310 } elsif (defined $file_name) {
6311 $title .= " - $file_name";
6312 $feed_type = 'history';
6314 $title .= " $feed_type";
6315 my $descr = git_get_project_description
($project);
6316 if (defined $descr) {
6317 $descr = esc_html
($descr);
6319 $descr = "$project " .
6320 ($format eq 'rss' ?
'RSS' : 'Atom') .
6323 my $owner = git_get_project_owner
($project);
6324 $owner = esc_html
($owner);
6328 if (defined $file_name) {
6329 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6330 } elsif (defined $hash) {
6331 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6333 $alt_url = href
(-full
=>1, action
=>"summary");
6335 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6336 if ($format eq 'rss') {
6338 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6341 print "<title>$title</title>\n" .
6342 "<link>$alt_url</link>\n" .
6343 "<description>$descr</description>\n" .
6344 "<language>en</language>\n" .
6345 # project owner is responsible for 'editorial' content
6346 "<managingEditor>$owner</managingEditor>\n";
6347 if (defined $logo || defined $favicon) {
6348 # prefer the logo to the favicon, since RSS
6349 # doesn't allow both
6350 my $img = esc_url
($logo || $favicon);
6352 "<url>$img</url>\n" .
6353 "<title>$title</title>\n" .
6354 "<link>$alt_url</link>\n" .
6358 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6359 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6361 print "<generator>gitweb v.$version/$git_version</generator>\n";
6362 } elsif ($format eq 'atom') {
6364 <feed xmlns="http://www.w3.org/2005/Atom">
6366 print "<title>$title</title>\n" .
6367 "<subtitle>$descr</subtitle>\n" .
6368 '<link rel="alternate" type="text/html" href="' .
6369 $alt_url . '" />' . "\n" .
6370 '<link rel="self" type="' . $content_type . '" href="' .
6371 $cgi->self_url() . '" />' . "\n" .
6372 "<id>" . href
(-full
=>1) . "</id>\n" .
6373 # use project owner for feed author
6374 "<author><name>$owner</name></author>\n";
6375 if (defined $favicon) {
6376 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6378 if (defined $logo_url) {
6379 # not twice as wide as tall: 72 x 27 pixels
6380 print "<logo>" . esc_url
($logo) . "</logo>\n";
6382 if (! %latest_date) {
6383 # dummy date to keep the feed valid until commits trickle in:
6384 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6386 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6388 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6392 for (my $i = 0; $i <= $#commitlist; $i++) {
6393 my %co = %{$commitlist[$i]};
6394 my $commit = $co{'id'};
6395 # we read 150, we always show 30 and the ones more recent than 48 hours
6396 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6399 my %cd = parse_date
($co{'author_epoch'});
6401 # get list of changed files
6402 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6403 $co{'parent'} || "--root",
6404 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6406 my @difftree = map { chomp; $_ } <$fd>;
6410 # print element (entry, item)
6411 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6412 if ($format eq 'rss') {
6414 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6415 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6416 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6417 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6418 "<link>$co_url</link>\n" .
6419 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6420 "<content:encoded>" .
6422 } elsif ($format eq 'atom') {
6424 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6425 "<updated>$cd{'iso-8601'}</updated>\n" .
6427 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6428 if ($co{'author_email'}) {
6429 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6431 print "</author>\n" .
6432 # use committer for contributor
6434 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6435 if ($co{'committer_email'}) {
6436 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6438 print "</contributor>\n" .
6439 "<published>$cd{'iso-8601'}</published>\n" .
6440 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6441 "<id>$co_url</id>\n" .
6442 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6443 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6445 my $comment = $co{'comment'};
6447 foreach my $line (@
$comment) {
6448 $line = esc_html
($line);
6451 print "</pre><ul>\n";
6452 foreach my $difftree_line (@difftree) {
6453 my %difftree = parse_difftree_raw_line
($difftree_line);
6454 next if !$difftree{'from_id'};
6456 my $file = $difftree{'file'} || $difftree{'to_file'};
6460 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6461 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6462 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6463 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6464 -title
=> "diff"}, 'D');
6466 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6467 file_name
=>$file, hash_base
=>$commit),
6468 -title
=> "blame"}, 'B');
6470 # if this is not a feed of a file history
6471 if (!defined $file_name || $file_name ne $file) {
6472 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6473 file_name
=>$file, hash
=>$commit),
6474 -title
=> "history"}, 'H');
6476 $file = esc_path
($file);
6480 if ($format eq 'rss') {
6481 print "</ul>]]>\n" .
6482 "</content:encoded>\n" .
6484 } elsif ($format eq 'atom') {
6485 print "</ul>\n</div>\n" .
6492 if ($format eq 'rss') {
6493 print "</channel>\n</rss>\n";
6494 } elsif ($format eq 'atom') {
6508 my @list = git_get_projects_list
();
6511 -type
=> 'text/xml',
6512 -charset
=> 'utf-8',
6513 -content_disposition
=> 'inline; filename="opml.xml"');
6516 <?xml version="1.0" encoding="utf-8"?>
6517 <opml version="1.0">
6519 <title>$site_name OPML Export</title>
6522 <outline text="git RSS feeds">
6525 foreach my $pr (@list) {
6527 my $head = git_get_head_hash
($proj{'path'});
6528 if (!defined $head) {
6531 $git_dir = "$projectroot/$proj{'path'}";
6532 my %co = parse_commit
($head);
6537 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6538 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6539 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6540 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";