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 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI-
>compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
33 our $my_url = $cgi->url();
34 our $my_uri = $cgi->url(-absolute
=> 1);
36 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
37 # needed and used only for URLs with nonempty PATH_INFO
38 our $base_url = $my_url;
40 # When the script is used as DirectoryIndex, the URL does not contain the name
41 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
42 # have to do it ourselves. We make $path_info global because it's also used
45 # Another issue with the script being the DirectoryIndex is that the resulting
46 # $my_url data is not the full script URL: this is good, because we want
47 # generated links to keep implying the script name if it wasn't explicitly
48 # indicated in the URL we're handling, but it means that $my_url cannot be used
50 # Therefore, if we needed to strip PATH_INFO, then we know that we have
51 # to build the base URL ourselves:
52 our $path_info = $ENV{"PATH_INFO"};
54 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
55 $my_uri =~ s
,\Q
$path_info\E
$,, &&
56 defined $ENV{'SCRIPT_NAME'}) {
57 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
61 # core git executable to use
62 # this can just be "git" if your webserver has a sensible PATH
63 our $GIT = "++GIT_BINDIR++/git";
65 # absolute fs-path which will be prepended to the project path
66 #our $projectroot = "/pub/scm";
67 our $projectroot = "++GITWEB_PROJECTROOT++";
69 # fs traversing limit for getting project list
70 # the number is relative to the projectroot
71 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
73 # target of the home link on top of all pages
74 our $home_link = $my_uri || "/";
76 # string of the home link on top of all pages
77 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
79 # name of your site or organization to appear in page titles
80 # replace this with something more descriptive for clearer bookmarks
81 our $site_name = "++GITWEB_SITENAME++"
82 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
84 # filename of html text to include at top of each page
85 our $site_header = "++GITWEB_SITE_HEADER++";
86 # html text to include at home page
87 our $home_text = "++GITWEB_HOMETEXT++";
88 # filename of html text to include at bottom of each page
89 our $site_footer = "++GITWEB_SITE_FOOTER++";
92 our @stylesheets = ("++GITWEB_CSS++");
93 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
94 our $stylesheet = undef;
96 # URI of GIT logo (72x27 size)
97 our $logo = "++GITWEB_LOGO++";
98 # URI of GIT favicon, assumed to be image/png type
99 our $favicon = "++GITWEB_FAVICON++";
100 # URI of gitweb.js (JavaScript code for gitweb)
101 our $javascript = "++GITWEB_JS++";
103 # URI and label (title) of GIT logo link
104 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
105 #our $logo_label = "git documentation";
106 our $logo_url = "http://git-scm.com/";
107 our $logo_label = "git homepage";
109 # source of projects list
110 our $projects_list = "++GITWEB_LIST++";
112 # the width (in characters) of the projects list "Description" column
113 our $projects_list_description_width = 25;
115 # default order of projects list
116 # valid values are none, project, descr, owner, and age
117 our $default_projects_order = "project";
119 # show repository only if this file exists
120 # (only effective if this variable evaluates to true)
121 our $export_ok = "++GITWEB_EXPORT_OK++";
123 # show repository only if this subroutine returns true
124 # when given the path to the project, for example:
125 # sub { return -e "$_[0]/git-daemon-export-ok"; }
126 our $export_auth_hook = undef;
128 # only allow viewing of repositories also shown on the overview page
129 our $strict_export = "++GITWEB_STRICT_EXPORT++";
131 # list of git base URLs used for URL to where fetch project from,
132 # i.e. full URL is "$git_base_url/$project"
133 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
135 # default blob_plain mimetype and default charset for text/plain blob
136 our $default_blob_plain_mimetype = 'text/plain';
137 our $default_text_plain_charset = undef;
139 # file to use for guessing MIME types before trying /etc/mime.types
140 # (relative to the current git repository)
141 our $mimetypes_file = undef;
143 # assume this charset if line contains non-UTF-8 characters;
144 # it should be valid encoding (see Encoding::Supported(3pm) for list),
145 # for which encoding all byte sequences are valid, for example
146 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
147 # could be even 'utf-8' for the old behavior)
148 our $fallback_encoding = 'latin1';
150 # rename detection options for git-diff and git-diff-tree
151 # - default is '-M', with the cost proportional to
152 # (number of removed files) * (number of new files).
153 # - more costly is '-C' (which implies '-M'), with the cost proportional to
154 # (number of changed files + number of removed files) * (number of new files)
155 # - even more costly is '-C', '--find-copies-harder' with cost
156 # (number of files in the original tree) * (number of new files)
157 # - one might want to include '-B' option, e.g. '-B', '-M'
158 our @diff_opts = ('-M'); # taken from git_commit
160 # Disables features that would allow repository owners to inject script into
162 our $prevent_xss = 0;
164 # information about snapshot formats that gitweb is capable of serving
165 our %known_snapshot_formats = (
167 # 'display' => display name,
168 # 'type' => mime type,
169 # 'suffix' => filename suffix,
170 # 'format' => --format for git-archive,
171 # 'compressor' => [compressor command and arguments]
172 # (array reference, optional)
173 # 'disabled' => boolean (optional)}
176 'display' => 'tar.gz',
177 'type' => 'application/x-gzip',
178 'suffix' => '.tar.gz',
180 'compressor' => ['gzip']},
183 'display' => 'tar.bz2',
184 'type' => 'application/x-bzip2',
185 'suffix' => '.tar.bz2',
187 'compressor' => ['bzip2']},
190 'display' => 'tar.xz',
191 'type' => 'application/x-xz',
192 'suffix' => '.tar.xz',
194 'compressor' => ['xz'],
199 'type' => 'application/x-zip',
204 # Aliases so we understand old gitweb.snapshot values in repository
206 our %known_snapshot_format_aliases = (
211 # backward compatibility: legacy gitweb config support
212 'x-gzip' => undef, 'gz' => undef,
213 'x-bzip2' => undef, 'bz2' => undef,
214 'x-zip' => undef, '' => undef,
217 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
218 # are changed, it may be appropriate to change these values too via
225 # You define site-wide feature defaults here; override them with
226 # $GITWEB_CONFIG as necessary.
229 # 'sub' => feature-sub (subroutine),
230 # 'override' => allow-override (boolean),
231 # 'default' => [ default options...] (array reference)}
233 # if feature is overridable (it means that allow-override has true value),
234 # then feature-sub will be called with default options as parameters;
235 # return value of feature-sub indicates if to enable specified feature
237 # if there is no 'sub' key (no feature-sub), then feature cannot be
240 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
241 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
244 # Enable the 'blame' blob view, showing the last commit that modified
245 # each line in the file. This can be very CPU-intensive.
247 # To enable system wide have in $GITWEB_CONFIG
248 # $feature{'blame'}{'default'} = [1];
249 # To have project specific config enable override in $GITWEB_CONFIG
250 # $feature{'blame'}{'override'} = 1;
251 # and in project config gitweb.blame = 0|1;
253 'sub' => sub { feature_bool
('blame', @_) },
257 # Enable the 'snapshot' link, providing a compressed archive of any
258 # tree. This can potentially generate high traffic if you have large
261 # Value is a list of formats defined in %known_snapshot_formats that
263 # To disable system wide have in $GITWEB_CONFIG
264 # $feature{'snapshot'}{'default'} = [];
265 # To have project specific config enable override in $GITWEB_CONFIG
266 # $feature{'snapshot'}{'override'} = 1;
267 # and in project config, a comma-separated list of formats or "none"
268 # to disable. Example: gitweb.snapshot = tbz2,zip;
270 'sub' => \
&feature_snapshot
,
272 'default' => ['tgz']},
274 # Enable text search, which will list the commits which match author,
275 # committer or commit text to a given string. Enabled by default.
276 # Project specific override is not supported.
281 # Enable grep search, which will list the files in currently selected
282 # tree containing the given string. Enabled by default. This can be
283 # potentially CPU-intensive, of course.
285 # To enable system wide have in $GITWEB_CONFIG
286 # $feature{'grep'}{'default'} = [1];
287 # To have project specific config enable override in $GITWEB_CONFIG
288 # $feature{'grep'}{'override'} = 1;
289 # and in project config gitweb.grep = 0|1;
291 'sub' => sub { feature_bool
('grep', @_) },
295 # Enable the pickaxe search, which will list the commits that modified
296 # a given string in a file. This can be practical and quite faster
297 # alternative to 'blame', but still potentially CPU-intensive.
299 # To enable system wide have in $GITWEB_CONFIG
300 # $feature{'pickaxe'}{'default'} = [1];
301 # To have project specific config enable override in $GITWEB_CONFIG
302 # $feature{'pickaxe'}{'override'} = 1;
303 # and in project config gitweb.pickaxe = 0|1;
305 'sub' => sub { feature_bool
('pickaxe', @_) },
309 # Enable showing size of blobs in a 'tree' view, in a separate
310 # column, similar to what 'ls -l' does. This cost a bit of IO.
312 # To disable system wide have in $GITWEB_CONFIG
313 # $feature{'show-sizes'}{'default'} = [0];
314 # To have project specific config enable override in $GITWEB_CONFIG
315 # $feature{'show-sizes'}{'override'} = 1;
316 # and in project config gitweb.showsizes = 0|1;
318 'sub' => sub { feature_bool
('showsizes', @_) },
322 # Make gitweb use an alternative format of the URLs which can be
323 # more readable and natural-looking: project name is embedded
324 # directly in the path and the query string contains other
325 # auxiliary information. All gitweb installations recognize
326 # URL in either format; this configures in which formats gitweb
329 # To enable system wide have in $GITWEB_CONFIG
330 # $feature{'pathinfo'}{'default'} = [1];
331 # Project specific override is not supported.
333 # Note that you will need to change the default location of CSS,
334 # favicon, logo and possibly other files to an absolute URL. Also,
335 # if gitweb.cgi serves as your indexfile, you will need to force
336 # $my_uri to contain the script name in your $GITWEB_CONFIG.
341 # Make gitweb consider projects in project root subdirectories
342 # to be forks of existing projects. Given project $projname.git,
343 # projects matching $projname/*.git will not be shown in the main
344 # projects list, instead a '+' mark will be added to $projname
345 # there and a 'forks' view will be enabled for the project, listing
346 # all the forks. If project list is taken from a file, forks have
347 # to be listed after the main project.
349 # To enable system wide have in $GITWEB_CONFIG
350 # $feature{'forks'}{'default'} = [1];
351 # Project specific override is not supported.
356 # Insert custom links to the action bar of all project pages.
357 # This enables you mainly to link to third-party scripts integrating
358 # into gitweb; e.g. git-browser for graphical history representation
359 # or custom web-based repository administration interface.
361 # The 'default' value consists of a list of triplets in the form
362 # (label, link, position) where position is the label after which
363 # to insert the link and link is a format string where %n expands
364 # to the project name, %f to the project path within the filesystem,
365 # %h to the current hash (h gitweb parameter) and %b to the current
366 # hash base (hb gitweb parameter); %% expands to %.
368 # To enable system wide have in $GITWEB_CONFIG e.g.
369 # $feature{'actions'}{'default'} = [('graphiclog',
370 # '/git-browser/by-commit.html?r=%n', 'summary')];
371 # Project specific override is not supported.
376 # Allow gitweb scan project content tags described in ctags/
377 # of project repository, and display the popular Web 2.0-ish
378 # "tag cloud" near the project list. Note that this is something
379 # COMPLETELY different from the normal Git tags.
381 # gitweb by itself can show existing tags, but it does not handle
382 # tagging itself; you need an external application for that.
383 # For an example script, check Girocco's cgi/tagproj.cgi.
384 # You may want to install the HTML::TagCloud Perl module to get
385 # a pretty tag cloud instead of just a list of tags.
387 # To enable system wide have in $GITWEB_CONFIG
388 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
389 # Project specific override is not supported.
394 # The maximum number of patches in a patchset generated in patch
395 # view. Set this to 0 or undef to disable patch view, or to a
396 # negative number to remove any limit.
398 # To disable system wide have in $GITWEB_CONFIG
399 # $feature{'patches'}{'default'} = [0];
400 # To have project specific config enable override in $GITWEB_CONFIG
401 # $feature{'patches'}{'override'} = 1;
402 # and in project config gitweb.patches = 0|n;
403 # where n is the maximum number of patches allowed in a patchset.
405 'sub' => \
&feature_patches
,
409 # Avatar support. When this feature is enabled, views such as
410 # shortlog or commit will display an avatar associated with
411 # the email of the committer(s) and/or author(s).
413 # Currently available providers are gravatar and picon.
414 # If an unknown provider is specified, the feature is disabled.
416 # Gravatar depends on Digest::MD5.
417 # Picon currently relies on the indiana.edu database.
419 # To enable system wide have in $GITWEB_CONFIG
420 # $feature{'avatar'}{'default'} = ['<provider>'];
421 # where <provider> is either gravatar or picon.
422 # To have project specific config enable override in $GITWEB_CONFIG
423 # $feature{'avatar'}{'override'} = 1;
424 # and in project config gitweb.avatar = <provider>;
426 'sub' => \
&feature_avatar
,
430 # Enable displaying how much time and how many git commands
431 # it took to generate and display page. Disabled by default.
432 # Project specific override is not supported.
438 sub gitweb_get_feature
{
440 return unless exists $feature{$name};
441 my ($sub, $override, @defaults) = (
442 $feature{$name}{'sub'},
443 $feature{$name}{'override'},
444 @{$feature{$name}{'default'}});
445 if (!$override) { return @defaults; }
447 warn "feature $name is not overridable";
450 return $sub->(@defaults);
453 # A wrapper to check if a given feature is enabled.
454 # With this, you can say
456 # my $bool_feat = gitweb_check_feature('bool_feat');
457 # gitweb_check_feature('bool_feat') or somecode;
461 # my ($bool_feat) = gitweb_get_feature('bool_feat');
462 # (gitweb_get_feature('bool_feat'))[0] or somecode;
464 sub gitweb_check_feature
{
465 return (gitweb_get_feature
(@_))[0];
471 my ($val) = git_get_project_config
($key, '--bool');
475 } elsif ($val eq 'true') {
477 } elsif ($val eq 'false') {
482 sub feature_snapshot
{
485 my ($val) = git_get_project_config
('snapshot');
488 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
494 sub feature_patches
{
495 my @val = (git_get_project_config
('patches', '--int'));
505 my @val = (git_get_project_config
('avatar'));
507 return @val ? @val : @_;
510 # checking HEAD file with -e is fragile if the repository was
511 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
513 sub check_head_link
{
515 my $headfile = "$dir/HEAD";
516 return ((-e
$headfile) ||
517 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
520 sub check_export_ok
{
522 return (check_head_link
($dir) &&
523 (!$export_ok || -e
"$dir/$export_ok") &&
524 (!$export_auth_hook || $export_auth_hook->($dir)));
527 # process alternate names for backward compatibility
528 # filter out unsupported (unknown) snapshot formats
529 sub filter_snapshot_fmts
{
533 exists $known_snapshot_format_aliases{$_} ?
534 $known_snapshot_format_aliases{$_} : $_} @fmts;
536 exists $known_snapshot_formats{$_} &&
537 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
540 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
541 if (-e
$GITWEB_CONFIG) {
544 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
545 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
548 # version of the core git binary
549 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
550 $number_of_git_cmds++;
552 $projects_list ||= $projectroot;
554 # ======================================================================
555 # input validation and dispatch
557 # input parameters can be collected from a variety of sources (presently, CGI
558 # and PATH_INFO), so we define an %input_params hash that collects them all
559 # together during validation: this allows subsequent uses (e.g. href()) to be
560 # agnostic of the parameter origin
562 our %input_params = ();
564 # input parameters are stored with the long parameter name as key. This will
565 # also be used in the href subroutine to convert parameters to their CGI
566 # equivalent, and since the href() usage is the most frequent one, we store
567 # the name -> CGI key mapping here, instead of the reverse.
569 # XXX: Warning: If you touch this, check the search form for updating,
572 our @cgi_param_mapping = (
580 hash_parent_base
=> "hpb",
585 snapshot_format
=> "sf",
586 extra_options
=> "opt",
587 search_use_regexp
=> "sr",
588 # this must be last entry (for manipulation from JavaScript)
591 our %cgi_param_mapping = @cgi_param_mapping;
593 # we will also need to know the possible actions, for validation
595 "blame" => \
&git_blame
,
596 "blame_incremental" => \
&git_blame_incremental
,
597 "blame_data" => \
&git_blame_data
,
598 "blobdiff" => \
&git_blobdiff
,
599 "blobdiff_plain" => \
&git_blobdiff_plain
,
600 "blob" => \
&git_blob
,
601 "blob_plain" => \
&git_blob_plain
,
602 "commitdiff" => \
&git_commitdiff
,
603 "commitdiff_plain" => \
&git_commitdiff_plain
,
604 "commit" => \
&git_commit
,
605 "forks" => \
&git_forks
,
606 "heads" => \
&git_heads
,
607 "history" => \
&git_history
,
609 "patch" => \
&git_patch
,
610 "patches" => \
&git_patches
,
612 "atom" => \
&git_atom
,
613 "search" => \
&git_search
,
614 "search_help" => \
&git_search_help
,
615 "shortlog" => \
&git_shortlog
,
616 "summary" => \
&git_summary
,
618 "tags" => \
&git_tags
,
619 "tree" => \
&git_tree
,
620 "snapshot" => \
&git_snapshot
,
621 "object" => \
&git_object
,
622 # those below don't need $project
623 "opml" => \
&git_opml
,
624 "project_list" => \
&git_project_list
,
625 "project_index" => \
&git_project_index
,
628 # finally, we have the hash of allowed extra_options for the commands that
630 our %allowed_options = (
631 "--no-merges" => [ qw(rss atom log shortlog history) ],
634 # fill %input_params with the CGI parameters. All values except for 'opt'
635 # should be single values, but opt can be an array. We should probably
636 # build an array of parameters that can be multi-valued, but since for the time
637 # being it's only this one, we just single it out
638 while (my ($name, $symbol) = each %cgi_param_mapping) {
639 if ($symbol eq 'opt') {
640 $input_params{$name} = [ $cgi->param($symbol) ];
642 $input_params{$name} = $cgi->param($symbol);
646 # now read PATH_INFO and update the parameter list for missing parameters
647 sub evaluate_path_info
{
648 return if defined $input_params{'project'};
649 return if !$path_info;
650 $path_info =~ s
,^/+,,;
651 return if !$path_info;
653 # find which part of PATH_INFO is project
654 my $project = $path_info;
656 while ($project && !check_head_link
("$projectroot/$project")) {
657 $project =~ s
,/*[^/]*$,,;
659 return unless $project;
660 $input_params{'project'} = $project;
662 # do not change any parameters if an action is given using the query string
663 return if $input_params{'action'};
664 $path_info =~ s
,^\Q
$project\E
/*,,;
666 # next, check if we have an action
667 my $action = $path_info;
669 if (exists $actions{$action}) {
670 $path_info =~ s
,^$action/*,,;
671 $input_params{'action'} = $action;
674 # list of actions that want hash_base instead of hash, but can have no
675 # pathname (f) parameter
682 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
683 my ($parentrefname, $parentpathname, $refname, $pathname) =
684 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
686 # first, analyze the 'current' part
687 if (defined $pathname) {
688 # we got "branch:filename" or "branch:dir/"
689 # we could use git_get_type(branch:pathname), but:
690 # - it needs $git_dir
691 # - it does a git() call
692 # - the convention of terminating directories with a slash
693 # makes it superfluous
694 # - embedding the action in the PATH_INFO would make it even
696 $pathname =~ s
,^/+,,;
697 if (!$pathname || substr($pathname, -1) eq "/") {
698 $input_params{'action'} ||= "tree";
701 # the default action depends on whether we had parent info
703 if ($parentrefname) {
704 $input_params{'action'} ||= "blobdiff_plain";
706 $input_params{'action'} ||= "blob_plain";
709 $input_params{'hash_base'} ||= $refname;
710 $input_params{'file_name'} ||= $pathname;
711 } elsif (defined $refname) {
712 # we got "branch". In this case we have to choose if we have to
713 # set hash or hash_base.
715 # Most of the actions without a pathname only want hash to be
716 # set, except for the ones specified in @wants_base that want
717 # hash_base instead. It should also be noted that hand-crafted
718 # links having 'history' as an action and no pathname or hash
719 # set will fail, but that happens regardless of PATH_INFO.
720 $input_params{'action'} ||= "shortlog";
721 if (grep { $_ eq $input_params{'action'} } @wants_base) {
722 $input_params{'hash_base'} ||= $refname;
724 $input_params{'hash'} ||= $refname;
728 # next, handle the 'parent' part, if present
729 if (defined $parentrefname) {
730 # a missing pathspec defaults to the 'current' filename, allowing e.g.
731 # someproject/blobdiff/oldrev..newrev:/filename
732 if ($parentpathname) {
733 $parentpathname =~ s
,^/+,,;
734 $parentpathname =~ s
,/$,,;
735 $input_params{'file_parent'} ||= $parentpathname;
737 $input_params{'file_parent'} ||= $input_params{'file_name'};
739 # we assume that hash_parent_base is wanted if a path was specified,
740 # or if the action wants hash_base instead of hash
741 if (defined $input_params{'file_parent'} ||
742 grep { $_ eq $input_params{'action'} } @wants_base) {
743 $input_params{'hash_parent_base'} ||= $parentrefname;
745 $input_params{'hash_parent'} ||= $parentrefname;
749 # for the snapshot action, we allow URLs in the form
750 # $project/snapshot/$hash.ext
751 # where .ext determines the snapshot and gets removed from the
752 # passed $refname to provide the $hash.
754 # To be able to tell that $refname includes the format extension, we
755 # require the following two conditions to be satisfied:
756 # - the hash input parameter MUST have been set from the $refname part
757 # of the URL (i.e. they must be equal)
758 # - the snapshot format MUST NOT have been defined already (e.g. from
760 # It's also useless to try any matching unless $refname has a dot,
761 # so we check for that too
762 if (defined $input_params{'action'} &&
763 $input_params{'action'} eq 'snapshot' &&
764 defined $refname && index($refname, '.') != -1 &&
765 $refname eq $input_params{'hash'} &&
766 !defined $input_params{'snapshot_format'}) {
767 # We loop over the known snapshot formats, checking for
768 # extensions. Allowed extensions are both the defined suffix
769 # (which includes the initial dot already) and the snapshot
770 # format key itself, with a prepended dot
771 while (my ($fmt, $opt) = each %known_snapshot_formats) {
773 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
777 # a valid suffix was found, so set the snapshot format
778 # and reset the hash parameter
779 $input_params{'snapshot_format'} = $fmt;
780 $input_params{'hash'} = $hash;
781 # we also set the format suffix to the one requested
782 # in the URL: this way a request for e.g. .tgz returns
783 # a .tgz instead of a .tar.gz
784 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
789 evaluate_path_info
();
791 our $action = $input_params{'action'};
792 if (defined $action) {
793 if (!validate_action
($action)) {
794 die_error
(400, "Invalid action parameter");
798 # parameters which are pathnames
799 our $project = $input_params{'project'};
800 if (defined $project) {
801 if (!validate_project
($project)) {
803 die_error
(404, "No such project");
807 our $file_name = $input_params{'file_name'};
808 if (defined $file_name) {
809 if (!validate_pathname
($file_name)) {
810 die_error
(400, "Invalid file parameter");
814 our $file_parent = $input_params{'file_parent'};
815 if (defined $file_parent) {
816 if (!validate_pathname
($file_parent)) {
817 die_error
(400, "Invalid file parent parameter");
821 # parameters which are refnames
822 our $hash = $input_params{'hash'};
824 if (!validate_refname
($hash)) {
825 die_error
(400, "Invalid hash parameter");
829 our $hash_parent = $input_params{'hash_parent'};
830 if (defined $hash_parent) {
831 if (!validate_refname
($hash_parent)) {
832 die_error
(400, "Invalid hash parent parameter");
836 our $hash_base = $input_params{'hash_base'};
837 if (defined $hash_base) {
838 if (!validate_refname
($hash_base)) {
839 die_error
(400, "Invalid hash base parameter");
843 our @extra_options = @{$input_params{'extra_options'}};
844 # @extra_options is always defined, since it can only be (currently) set from
845 # CGI, and $cgi->param() returns the empty array in array context if the param
847 foreach my $opt (@extra_options) {
848 if (not exists $allowed_options{$opt}) {
849 die_error
(400, "Invalid option parameter");
851 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
852 die_error
(400, "Invalid option parameter for this action");
856 our $hash_parent_base = $input_params{'hash_parent_base'};
857 if (defined $hash_parent_base) {
858 if (!validate_refname
($hash_parent_base)) {
859 die_error
(400, "Invalid hash parent base parameter");
864 our $page = $input_params{'page'};
866 if ($page =~ m/[^0-9]/) {
867 die_error
(400, "Invalid page parameter");
871 our $searchtype = $input_params{'searchtype'};
872 if (defined $searchtype) {
873 if ($searchtype =~ m/[^a-z]/) {
874 die_error
(400, "Invalid searchtype parameter");
878 our $search_use_regexp = $input_params{'search_use_regexp'};
880 our $searchtext = $input_params{'searchtext'};
882 if (defined $searchtext) {
883 if (length($searchtext) < 2) {
884 die_error
(403, "At least two characters are required for search parameter");
886 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
889 # path to the current git repository
891 $git_dir = "$projectroot/$project" if $project;
893 # list of supported snapshot formats
894 our @snapshot_fmts = gitweb_get_feature
('snapshot');
895 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
897 # check that the avatar feature is set to a known provider name,
898 # and for each provider check if the dependencies are satisfied.
899 # if the provider name is invalid or the dependencies are not met,
900 # reset $git_avatar to the empty string.
901 our ($git_avatar) = gitweb_get_feature
('avatar');
902 if ($git_avatar eq 'gravatar') {
903 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
904 } elsif ($git_avatar eq 'picon') {
911 if (!defined $action) {
913 $action = git_get_type
($hash);
914 } elsif (defined $hash_base && defined $file_name) {
915 $action = git_get_type
("$hash_base:$file_name");
916 } elsif (defined $project) {
919 $action = 'project_list';
922 if (!defined($actions{$action})) {
923 die_error
(400, "Unknown action");
925 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
927 die_error
(400, "Project needed");
929 $actions{$action}->();
932 ## ======================================================================
937 # default is to use -absolute url() i.e. $my_uri
938 my $href = $params{-full
} ? $my_url : $my_uri;
940 $params{'project'} = $project unless exists $params{'project'};
942 if ($params{-replay
}) {
943 while (my ($name, $symbol) = each %cgi_param_mapping) {
944 if (!exists $params{$name}) {
945 $params{$name} = $input_params{$name};
950 my $use_pathinfo = gitweb_check_feature
('pathinfo');
951 if ($use_pathinfo and defined $params{'project'}) {
952 # try to put as many parameters as possible in PATH_INFO:
955 # - hash_parent or hash_parent_base:/file_parent
956 # - hash or hash_base:/filename
957 # - the snapshot_format as an appropriate suffix
959 # When the script is the root DirectoryIndex for the domain,
960 # $href here would be something like http://gitweb.example.com/
961 # Thus, we strip any trailing / from $href, to spare us double
962 # slashes in the final URL
965 # Then add the project name, if present
966 $href .= "/".esc_url
($params{'project'});
967 delete $params{'project'};
969 # since we destructively absorb parameters, we keep this
970 # boolean that remembers if we're handling a snapshot
971 my $is_snapshot = $params{'action'} eq 'snapshot';
973 # Summary just uses the project path URL, any other action is
975 if (defined $params{'action'}) {
976 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
977 delete $params{'action'};
980 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
981 # stripping nonexistent or useless pieces
982 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
983 || $params{'hash_parent'} || $params{'hash'});
984 if (defined $params{'hash_base'}) {
985 if (defined $params{'hash_parent_base'}) {
986 $href .= esc_url
($params{'hash_parent_base'});
987 # skip the file_parent if it's the same as the file_name
988 if (defined $params{'file_parent'}) {
989 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
990 delete $params{'file_parent'};
991 } elsif ($params{'file_parent'} !~ /\.\./) {
992 $href .= ":/".esc_url
($params{'file_parent'});
993 delete $params{'file_parent'};
997 delete $params{'hash_parent'};
998 delete $params{'hash_parent_base'};
999 } elsif (defined $params{'hash_parent'}) {
1000 $href .= esc_url
($params{'hash_parent'}). "..";
1001 delete $params{'hash_parent'};
1004 $href .= esc_url
($params{'hash_base'});
1005 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1006 $href .= ":/".esc_url
($params{'file_name'});
1007 delete $params{'file_name'};
1009 delete $params{'hash'};
1010 delete $params{'hash_base'};
1011 } elsif (defined $params{'hash'}) {
1012 $href .= esc_url
($params{'hash'});
1013 delete $params{'hash'};
1016 # If the action was a snapshot, we can absorb the
1017 # snapshot_format parameter too
1019 my $fmt = $params{'snapshot_format'};
1020 # snapshot_format should always be defined when href()
1021 # is called, but just in case some code forgets, we
1022 # fall back to the default
1023 $fmt ||= $snapshot_fmts[0];
1024 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1025 delete $params{'snapshot_format'};
1029 # now encode the parameters explicitly
1031 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1032 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1033 if (defined $params{$name}) {
1034 if (ref($params{$name}) eq "ARRAY") {
1035 foreach my $par (@{$params{$name}}) {
1036 push @result, $symbol . "=" . esc_param
($par);
1039 push @result, $symbol . "=" . esc_param
($params{$name});
1043 $href .= "?" . join(';', @result) if scalar @result;
1049 ## ======================================================================
1050 ## validation, quoting/unquoting and escaping
1052 sub validate_action
{
1053 my $input = shift || return undef;
1054 return undef unless exists $actions{$input};
1058 sub validate_project
{
1059 my $input = shift || return undef;
1060 if (!validate_pathname
($input) ||
1061 !(-d
"$projectroot/$input") ||
1062 !check_export_ok
("$projectroot/$input") ||
1063 ($strict_export && !project_in_list
($input))) {
1070 sub validate_pathname
{
1071 my $input = shift || return undef;
1073 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1074 # at the beginning, at the end, and between slashes.
1075 # also this catches doubled slashes
1076 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1079 # no null characters
1080 if ($input =~ m!\0!) {
1086 sub validate_refname
{
1087 my $input = shift || return undef;
1089 # textual hashes are O.K.
1090 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1093 # it must be correct pathname
1094 $input = validate_pathname
($input)
1096 # restrictions on ref name according to git-check-ref-format
1097 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1103 # decode sequences of octets in utf8 into Perl's internal form,
1104 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1105 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1108 if (utf8
::valid
($str)) {
1112 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1116 # quote unsafe chars, but keep the slash, even when it's not
1117 # correct, but quoted slashes look too horrible in bookmarks
1120 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1125 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1128 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1134 # replace invalid utf8 character with SUBSTITUTION sequence
1139 $str = to_utf8
($str);
1140 $str = $cgi->escapeHTML($str);
1141 if ($opts{'-nbsp'}) {
1142 $str =~ s/ / /g;
1144 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1148 # quote control characters and escape filename to HTML
1153 $str = to_utf8
($str);
1154 $str = $cgi->escapeHTML($str);
1155 if ($opts{'-nbsp'}) {
1156 $str =~ s/ / /g;
1158 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1162 # Make control characters "printable", using character escape codes (CEC)
1166 my %es = ( # character escape codes, aka escape sequences
1167 "\t" => '\t', # tab (HT)
1168 "\n" => '\n', # line feed (LF)
1169 "\r" => '\r', # carrige return (CR)
1170 "\f" => '\f', # form feed (FF)
1171 "\b" => '\b', # backspace (BS)
1172 "\a" => '\a', # alarm (bell) (BEL)
1173 "\e" => '\e', # escape (ESC)
1174 "\013" => '\v', # vertical tab (VT)
1175 "\000" => '\0', # nul character (NUL)
1177 my $chr = ( (exists $es{$cntrl})
1179 : sprintf('\%2x', ord($cntrl)) );
1180 if ($opts{-nohtml
}) {
1183 return "<span class=\"cntrl\">$chr</span>";
1187 # Alternatively use unicode control pictures codepoints,
1188 # Unicode "printable representation" (PR)
1193 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1194 if ($opts{-nohtml
}) {
1197 return "<span class=\"cntrl\">$chr</span>";
1201 # git may return quoted and escaped filenames
1207 my %es = ( # character escape codes, aka escape sequences
1208 't' => "\t", # tab (HT, TAB)
1209 'n' => "\n", # newline (NL)
1210 'r' => "\r", # return (CR)
1211 'f' => "\f", # form feed (FF)
1212 'b' => "\b", # backspace (BS)
1213 'a' => "\a", # alarm (bell) (BEL)
1214 'e' => "\e", # escape (ESC)
1215 'v' => "\013", # vertical tab (VT)
1218 if ($seq =~ m/^[0-7]{1,3}$/) {
1219 # octal char sequence
1220 return chr(oct($seq));
1221 } elsif (exists $es{$seq}) {
1222 # C escape sequence, aka character escape code
1225 # quoted ordinary character
1229 if ($str =~ m/^"(.*)"$/) {
1232 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1237 # escape tabs (convert tabs to spaces)
1241 while ((my $pos = index($line, "\t")) != -1) {
1242 if (my $count = (8 - ($pos % 8))) {
1243 my $spaces = ' ' x
$count;
1244 $line =~ s/\t/$spaces/;
1251 sub project_in_list
{
1252 my $project = shift;
1253 my @list = git_get_projects_list
();
1254 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1257 ## ----------------------------------------------------------------------
1258 ## HTML aware string manipulation
1260 # Try to chop given string on a word boundary between position
1261 # $len and $len+$add_len. If there is no word boundary there,
1262 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1263 # (marking chopped part) would be longer than given string.
1267 my $add_len = shift || 10;
1268 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1270 # Make sure perl knows it is utf8 encoded so we don't
1271 # cut in the middle of a utf8 multibyte char.
1272 $str = to_utf8
($str);
1274 # allow only $len chars, but don't cut a word if it would fit in $add_len
1275 # if it doesn't fit, cut it if it's still longer than the dots we would add
1276 # remove chopped character entities entirely
1278 # when chopping in the middle, distribute $len into left and right part
1279 # return early if chopping wouldn't make string shorter
1280 if ($where eq 'center') {
1281 return $str if ($len + 5 >= length($str)); # filler is length 5
1284 return $str if ($len + 4 >= length($str)); # filler is length 4
1287 # regexps: ending and beginning with word part up to $add_len
1288 my $endre = qr/.{$len}\w{0,$add_len}/;
1289 my $begre = qr/\w{0,$add_len}.{$len}/;
1291 if ($where eq 'left') {
1292 $str =~ m/^(.*?)($begre)$/;
1293 my ($lead, $body) = ($1, $2);
1294 if (length($lead) > 4) {
1295 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1298 return "$lead$body";
1300 } elsif ($where eq 'center') {
1301 $str =~ m/^($endre)(.*)$/;
1302 my ($left, $str) = ($1, $2);
1303 $str =~ m/^(.*?)($begre)$/;
1304 my ($mid, $right) = ($1, $2);
1305 if (length($mid) > 5) {
1306 $left =~ s/&[^;]*$//;
1307 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1310 return "$left$mid$right";
1313 $str =~ m/^($endre)(.*)$/;
1316 if (length($tail) > 4) {
1317 $body =~ s/&[^;]*$//;
1320 return "$body$tail";
1324 # takes the same arguments as chop_str, but also wraps a <span> around the
1325 # result with a title attribute if it does get chopped. Additionally, the
1326 # string is HTML-escaped.
1327 sub chop_and_escape_str
{
1330 my $chopped = chop_str
(@_);
1331 if ($chopped eq $str) {
1332 return esc_html
($chopped);
1334 $str =~ s/[[:cntrl:]]/?/g;
1335 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1339 ## ----------------------------------------------------------------------
1340 ## functions returning short strings
1342 # CSS class for given age value (in seconds)
1346 if (!defined $age) {
1348 } elsif ($age < 60*60*2) {
1350 } elsif ($age < 60*60*24*2) {
1357 # convert age in seconds to "nn units ago" string
1362 if ($age > 60*60*24*365*2) {
1363 $age_str = (int $age/60/60/24/365);
1364 $age_str .= " years ago";
1365 } elsif ($age > 60*60*24*(365/12)*2) {
1366 $age_str = int $age/60/60/24/(365/12);
1367 $age_str .= " months ago";
1368 } elsif ($age > 60*60*24*7*2) {
1369 $age_str = int $age/60/60/24/7;
1370 $age_str .= " weeks ago";
1371 } elsif ($age > 60*60*24*2) {
1372 $age_str = int $age/60/60/24;
1373 $age_str .= " days ago";
1374 } elsif ($age > 60*60*2) {
1375 $age_str = int $age/60/60;
1376 $age_str .= " hours ago";
1377 } elsif ($age > 60*2) {
1378 $age_str = int $age/60;
1379 $age_str .= " min ago";
1380 } elsif ($age > 2) {
1381 $age_str = int $age;
1382 $age_str .= " sec ago";
1384 $age_str .= " right now";
1390 S_IFINVALID
=> 0030000,
1391 S_IFGITLINK
=> 0160000,
1394 # submodule/subproject, a commit object reference
1398 return (($mode & S_IFMT
) == S_IFGITLINK
)
1401 # convert file mode in octal to symbolic file mode string
1403 my $mode = oct shift;
1405 if (S_ISGITLINK
($mode)) {
1406 return 'm---------';
1407 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1408 return 'drwxr-xr-x';
1409 } elsif (S_ISLNK
($mode)) {
1410 return 'lrwxrwxrwx';
1411 } elsif (S_ISREG
($mode)) {
1412 # git cares only about the executable bit
1413 if ($mode & S_IXUSR
) {
1414 return '-rwxr-xr-x';
1416 return '-rw-r--r--';
1419 return '----------';
1423 # convert file mode in octal to file type string
1427 if ($mode !~ m/^[0-7]+$/) {
1433 if (S_ISGITLINK
($mode)) {
1435 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1437 } elsif (S_ISLNK
($mode)) {
1439 } elsif (S_ISREG
($mode)) {
1446 # convert file mode in octal to file type description string
1447 sub file_type_long
{
1450 if ($mode !~ m/^[0-7]+$/) {
1456 if (S_ISGITLINK
($mode)) {
1458 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1460 } elsif (S_ISLNK
($mode)) {
1462 } elsif (S_ISREG
($mode)) {
1463 if ($mode & S_IXUSR
) {
1464 return "executable";
1474 ## ----------------------------------------------------------------------
1475 ## functions returning short HTML fragments, or transforming HTML fragments
1476 ## which don't belong to other sections
1478 # format line of commit message.
1479 sub format_log_line_html
{
1482 $line = esc_html
($line, -nbsp
=>1);
1483 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1484 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1485 -class => "text"}, $1);
1491 # format marker of refs pointing to given object
1493 # the destination action is chosen based on object type and current context:
1494 # - for annotated tags, we choose the tag view unless it's the current view
1495 # already, in which case we go to shortlog view
1496 # - for other refs, we keep the current view if we're in history, shortlog or
1497 # log view, and select shortlog otherwise
1498 sub format_ref_marker
{
1499 my ($refs, $id) = @_;
1502 if (defined $refs->{$id}) {
1503 foreach my $ref (@{$refs->{$id}}) {
1504 # this code exploits the fact that non-lightweight tags are the
1505 # only indirect objects, and that they are the only objects for which
1506 # we want to use tag instead of shortlog as action
1507 my ($type, $name) = qw();
1508 my $indirect = ($ref =~ s/\^\{\}$//);
1509 # e.g. tags/v2.6.11 or heads/next
1510 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1519 $class .= " indirect" if $indirect;
1521 my $dest_action = "shortlog";
1524 $dest_action = "tag" unless $action eq "tag";
1525 } elsif ($action =~ /^(history|(short)?log)$/) {
1526 $dest_action = $action;
1530 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1533 my $link = $cgi->a({
1535 action
=>$dest_action,
1539 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1545 return ' <span class="refs">'. $markers . '</span>';
1551 # format, perhaps shortened and with markers, title line
1552 sub format_subject_html
{
1553 my ($long, $short, $href, $extra) = @_;
1554 $extra = '' unless defined($extra);
1556 if (length($short) < length($long)) {
1557 $long =~ s/[[:cntrl:]]/?/g;
1558 return $cgi->a({-href
=> $href, -class => "list subject",
1559 -title
=> to_utf8
($long)},
1560 esc_html
($short)) . $extra;
1562 return $cgi->a({-href
=> $href, -class => "list subject"},
1563 esc_html
($long)) . $extra;
1567 # Rather than recomputing the url for an email multiple times, we cache it
1568 # after the first hit. This gives a visible benefit in views where the avatar
1569 # for the same email is used repeatedly (e.g. shortlog).
1570 # The cache is shared by all avatar engines (currently gravatar only), which
1571 # are free to use it as preferred. Since only one avatar engine is used for any
1572 # given page, there's no risk for cache conflicts.
1573 our %avatar_cache = ();
1575 # Compute the picon url for a given email, by using the picon search service over at
1576 # http://www.cs.indiana.edu/picons/search.html
1578 my $email = lc shift;
1579 if (!$avatar_cache{$email}) {
1580 my ($user, $domain) = split('@', $email);
1581 $avatar_cache{$email} =
1582 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1584 "users+domains+unknown/up/single";
1586 return $avatar_cache{$email};
1589 # Compute the gravatar url for a given email, if it's not in the cache already.
1590 # Gravatar stores only the part of the URL before the size, since that's the
1591 # one computationally more expensive. This also allows reuse of the cache for
1592 # different sizes (for this particular engine).
1594 my $email = lc shift;
1596 $avatar_cache{$email} ||=
1597 "http://www.gravatar.com/avatar/" .
1598 Digest
::MD5
::md5_hex
($email) . "?s=";
1599 return $avatar_cache{$email} . $size;
1602 # Insert an avatar for the given $email at the given $size if the feature
1604 sub git_get_avatar
{
1605 my ($email, %opts) = @_;
1606 my $pre_white = ($opts{-pad_before
} ? " " : "");
1607 my $post_white = ($opts{-pad_after
} ? " " : "");
1608 $opts{-size
} ||= 'default';
1609 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1611 if ($git_avatar eq 'gravatar') {
1612 $url = gravatar_url
($email, $size);
1613 } elsif ($git_avatar eq 'picon') {
1614 $url = picon_url
($email);
1616 # Other providers can be added by extending the if chain, defining $url
1617 # as needed. If no variant puts something in $url, we assume avatars
1618 # are completely disabled/unavailable.
1621 "<img width=\"$size\" " .
1622 "class=\"avatar\" " .
1631 sub format_search_author
{
1632 my ($author, $searchtype, $displaytext) = @_;
1633 my $have_search = gitweb_check_feature
('search');
1637 if ($searchtype eq 'author') {
1638 $performed = "authored";
1639 } elsif ($searchtype eq 'committer') {
1640 $performed = "committed";
1643 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1644 searchtext
=>$author,
1645 searchtype
=>$searchtype), class=>"list",
1646 title
=>"Search for commits $performed by $author"},
1650 return $displaytext;
1654 # format the author name of the given commit with the given tag
1655 # the author name is chopped and escaped according to the other
1656 # optional parameters (see chop_str).
1657 sub format_author_html
{
1660 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1661 return "<$tag class=\"author\">" .
1662 format_search_author
($co->{'author_name'}, "author",
1663 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1668 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1669 sub format_git_diff_header_line
{
1671 my $diffinfo = shift;
1672 my ($from, $to) = @_;
1674 if ($diffinfo->{'nparents'}) {
1676 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1677 if ($to->{'href'}) {
1678 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1679 esc_path
($to->{'file'}));
1680 } else { # file was deleted (no href)
1681 $line .= esc_path
($to->{'file'});
1685 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1686 if ($from->{'href'}) {
1687 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1688 'a/' . esc_path
($from->{'file'}));
1689 } else { # file was added (no href)
1690 $line .= 'a/' . esc_path
($from->{'file'});
1693 if ($to->{'href'}) {
1694 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1695 'b/' . esc_path
($to->{'file'}));
1696 } else { # file was deleted
1697 $line .= 'b/' . esc_path
($to->{'file'});
1701 return "<div class=\"diff header\">$line</div>\n";
1704 # format extended diff header line, before patch itself
1705 sub format_extended_diff_header_line
{
1707 my $diffinfo = shift;
1708 my ($from, $to) = @_;
1711 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1712 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1713 esc_path
($from->{'file'}));
1715 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1716 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1717 esc_path
($to->{'file'}));
1719 # match single <mode>
1720 if ($line =~ m/\s(\d{6})$/) {
1721 $line .= '<span class="info"> (' .
1722 file_type_long
($1) .
1726 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1727 # can match only for combined diff
1729 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1730 if ($from->{'href'}[$i]) {
1731 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1733 substr($diffinfo->{'from_id'}[$i],0,7));
1738 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1741 if ($to->{'href'}) {
1742 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1743 substr($diffinfo->{'to_id'},0,7));
1748 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1749 # can match only for ordinary diff
1750 my ($from_link, $to_link);
1751 if ($from->{'href'}) {
1752 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1753 substr($diffinfo->{'from_id'},0,7));
1755 $from_link = '0' x
7;
1757 if ($to->{'href'}) {
1758 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1759 substr($diffinfo->{'to_id'},0,7));
1763 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1764 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1767 return $line . "<br/>\n";
1770 # format from-file/to-file diff header
1771 sub format_diff_from_to_header
{
1772 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1777 #assert($line =~ m/^---/) if DEBUG;
1778 # no extra formatting for "^--- /dev/null"
1779 if (! $diffinfo->{'nparents'}) {
1780 # ordinary (single parent) diff
1781 if ($line =~ m!^--- "?a/!) {
1782 if ($from->{'href'}) {
1784 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1785 esc_path
($from->{'file'}));
1788 esc_path
($from->{'file'});
1791 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1794 # combined diff (merge commit)
1795 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1796 if ($from->{'href'}[$i]) {
1798 $cgi->a({-href
=>href
(action
=>"blobdiff",
1799 hash_parent
=>$diffinfo->{'from_id'}[$i],
1800 hash_parent_base
=>$parents[$i],
1801 file_parent
=>$from->{'file'}[$i],
1802 hash
=>$diffinfo->{'to_id'},
1804 file_name
=>$to->{'file'}),
1806 -title
=>"diff" . ($i+1)},
1809 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1810 esc_path
($from->{'file'}[$i]));
1812 $line = '--- /dev/null';
1814 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1819 #assert($line =~ m/^\+\+\+/) if DEBUG;
1820 # no extra formatting for "^+++ /dev/null"
1821 if ($line =~ m!^\+\+\+ "?b/!) {
1822 if ($to->{'href'}) {
1824 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1825 esc_path
($to->{'file'}));
1828 esc_path
($to->{'file'});
1831 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1836 # create note for patch simplified by combined diff
1837 sub format_diff_cc_simplified
{
1838 my ($diffinfo, @parents) = @_;
1841 $result .= "<div class=\"diff header\">" .
1843 if (!is_deleted
($diffinfo)) {
1844 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1846 hash
=>$diffinfo->{'to_id'},
1847 file_name
=>$diffinfo->{'to_file'}),
1849 esc_path
($diffinfo->{'to_file'}));
1851 $result .= esc_path
($diffinfo->{'to_file'});
1853 $result .= "</div>\n" . # class="diff header"
1854 "<div class=\"diff nodifferences\">" .
1856 "</div>\n"; # class="diff nodifferences"
1861 # format patch (diff) line (not to be used for diff headers)
1862 sub format_diff_line
{
1864 my ($from, $to) = @_;
1865 my $diff_class = "";
1869 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1871 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1872 if ($line =~ m/^\@{3}/) {
1873 $diff_class = " chunk_header";
1874 } elsif ($line =~ m/^\\/) {
1875 $diff_class = " incomplete";
1876 } elsif ($prefix =~ tr/+/+/) {
1877 $diff_class = " add";
1878 } elsif ($prefix =~ tr/-/-/) {
1879 $diff_class = " rem";
1882 # assume ordinary diff
1883 my $char = substr($line, 0, 1);
1885 $diff_class = " add";
1886 } elsif ($char eq '-') {
1887 $diff_class = " rem";
1888 } elsif ($char eq '@') {
1889 $diff_class = " chunk_header";
1890 } elsif ($char eq "\\") {
1891 $diff_class = " incomplete";
1894 $line = untabify
($line);
1895 if ($from && $to && $line =~ m/^\@{2} /) {
1896 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1897 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1899 $from_lines = 0 unless defined $from_lines;
1900 $to_lines = 0 unless defined $to_lines;
1902 if ($from->{'href'}) {
1903 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1904 -class=>"list"}, $from_text);
1906 if ($to->{'href'}) {
1907 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1908 -class=>"list"}, $to_text);
1910 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1911 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1912 return "<div class=\"diff$diff_class\">$line</div>\n";
1913 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1914 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1915 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1917 @from_text = split(' ', $ranges);
1918 for (my $i = 0; $i < @from_text; ++$i) {
1919 ($from_start[$i], $from_nlines[$i]) =
1920 (split(',', substr($from_text[$i], 1)), 0);
1923 $to_text = pop @from_text;
1924 $to_start = pop @from_start;
1925 $to_nlines = pop @from_nlines;
1927 $line = "<span class=\"chunk_info\">$prefix ";
1928 for (my $i = 0; $i < @from_text; ++$i) {
1929 if ($from->{'href'}[$i]) {
1930 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1931 -class=>"list"}, $from_text[$i]);
1933 $line .= $from_text[$i];
1937 if ($to->{'href'}) {
1938 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1939 -class=>"list"}, $to_text);
1943 $line .= " $prefix</span>" .
1944 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1945 return "<div class=\"diff$diff_class\">$line</div>\n";
1947 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1950 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1951 # linked. Pass the hash of the tree/commit to snapshot.
1952 sub format_snapshot_links
{
1954 my $num_fmts = @snapshot_fmts;
1955 if ($num_fmts > 1) {
1956 # A parenthesized list of links bearing format names.
1957 # e.g. "snapshot (_tar.gz_ _zip_)"
1958 return "snapshot (" . join(' ', map
1965 }, $known_snapshot_formats{$_}{'display'})
1966 , @snapshot_fmts) . ")";
1967 } elsif ($num_fmts == 1) {
1968 # A single "snapshot" link whose tooltip bears the format name.
1970 my ($fmt) = @snapshot_fmts;
1976 snapshot_format
=>$fmt
1978 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1980 } else { # $num_fmts == 0
1985 ## ......................................................................
1986 ## functions returning values to be passed, perhaps after some
1987 ## transformation, to other functions; e.g. returning arguments to href()
1989 # returns hash to be passed to href to generate gitweb URL
1990 # in -title key it returns description of link
1992 my $format = shift || 'Atom';
1993 my %res = (action
=> lc($format));
1995 # feed links are possible only for project views
1996 return unless (defined $project);
1997 # some views should link to OPML, or to generic project feed,
1998 # or don't have specific feed yet (so they should use generic)
1999 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2002 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2003 # from tag links; this also makes possible to detect branch links
2004 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2005 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2008 # find log type for feed description (title)
2010 if (defined $file_name) {
2011 $type = "history of $file_name";
2012 $type .= "/" if ($action eq 'tree');
2013 $type .= " on '$branch'" if (defined $branch);
2015 $type = "log of $branch" if (defined $branch);
2018 $res{-title
} = $type;
2019 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2020 $res{'file_name'} = $file_name;
2025 ## ----------------------------------------------------------------------
2026 ## git utility subroutines, invoking git commands
2028 # returns path to the core git executable and the --git-dir parameter as list
2030 $number_of_git_cmds++;
2031 return $GIT, '--git-dir='.$git_dir;
2034 # quote the given arguments for passing them to the shell
2035 # quote_command("command", "arg 1", "arg with ' and ! characters")
2036 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2037 # Try to avoid using this function wherever possible.
2040 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2043 # get HEAD ref of given project as hash
2044 sub git_get_head_hash
{
2045 return git_get_full_hash
(shift, 'HEAD');
2048 sub git_get_full_hash
{
2049 return git_get_hash
(@_);
2052 sub git_get_short_hash
{
2053 return git_get_hash
(@_, '--short=7');
2057 my ($project, $hash, @options) = @_;
2058 my $o_git_dir = $git_dir;
2060 $git_dir = "$projectroot/$project";
2061 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2062 '--verify', '-q', @options, $hash) {
2064 chomp $retval if defined $retval;
2067 if (defined $o_git_dir) {
2068 $git_dir = $o_git_dir;
2073 # get type of given object
2077 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2079 close $fd or return;
2084 # repository configuration
2085 our $config_file = '';
2088 # store multiple values for single key as anonymous array reference
2089 # single values stored directly in the hash, not as [ <value> ]
2090 sub hash_set_multi
{
2091 my ($hash, $key, $value) = @_;
2093 if (!exists $hash->{$key}) {
2094 $hash->{$key} = $value;
2095 } elsif (!ref $hash->{$key}) {
2096 $hash->{$key} = [ $hash->{$key}, $value ];
2098 push @{$hash->{$key}}, $value;
2102 # return hash of git project configuration
2103 # optionally limited to some section, e.g. 'gitweb'
2104 sub git_parse_project_config
{
2105 my $section_regexp = shift;
2110 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2113 while (my $keyval = <$fh>) {
2115 my ($key, $value) = split(/\n/, $keyval, 2);
2117 hash_set_multi
(\
%config, $key, $value)
2118 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2125 # convert config value to boolean: 'true' or 'false'
2126 # no value, number > 0, 'true' and 'yes' values are true
2127 # rest of values are treated as false (never as error)
2128 sub config_to_bool
{
2131 return 1 if !defined $val; # section.key
2133 # strip leading and trailing whitespace
2137 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2138 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2141 # convert config value to simple decimal number
2142 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2143 # to be multiplied by 1024, 1048576, or 1073741824
2147 # strip leading and trailing whitespace
2151 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2153 # unknown unit is treated as 1
2154 return $num * ($unit eq 'g' ? 1073741824 :
2155 $unit eq 'm' ? 1048576 :
2156 $unit eq 'k' ? 1024 : 1);
2161 # convert config value to array reference, if needed
2162 sub config_to_multi
{
2165 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2168 sub git_get_project_config
{
2169 my ($key, $type) = @_;
2172 return unless ($key);
2173 $key =~ s/^gitweb\.//;
2174 return if ($key =~ m/\W/);
2177 if (defined $type) {
2180 unless ($type eq 'bool' || $type eq 'int');
2184 if (!defined $config_file ||
2185 $config_file ne "$git_dir/config") {
2186 %config = git_parse_project_config
('gitweb');
2187 $config_file = "$git_dir/config";
2190 # check if config variable (key) exists
2191 return unless exists $config{"gitweb.$key"};
2194 if (!defined $type) {
2195 return $config{"gitweb.$key"};
2196 } elsif ($type eq 'bool') {
2197 # backward compatibility: 'git config --bool' returns true/false
2198 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2199 } elsif ($type eq 'int') {
2200 return config_to_int
($config{"gitweb.$key"});
2202 return $config{"gitweb.$key"};
2205 # get hash of given path at given ref
2206 sub git_get_hash_by_path
{
2208 my $path = shift || return undef;
2213 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2214 or die_error
(500, "Open git-ls-tree failed");
2216 close $fd or return undef;
2218 if (!defined $line) {
2219 # there is no tree or hash given by $path at $base
2223 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2224 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2225 if (defined $type && $type ne $2) {
2226 # type doesn't match
2232 # get path of entry with given hash at given tree-ish (ref)
2233 # used to get 'from' filename for combined diff (merge commit) for renames
2234 sub git_get_path_by_hash
{
2235 my $base = shift || return;
2236 my $hash = shift || return;
2240 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2242 while (my $line = <$fd>) {
2245 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2246 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2247 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2256 ## ......................................................................
2257 ## git utility functions, directly accessing git repository
2259 sub git_get_project_description
{
2262 $git_dir = "$projectroot/$path";
2263 open my $fd, '<', "$git_dir/description"
2264 or return git_get_project_config
('description');
2267 if (defined $descr) {
2273 sub git_get_project_ctags
{
2277 $git_dir = "$projectroot/$path";
2278 opendir my $dh, "$git_dir/ctags"
2280 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2281 open my $ct, '<', $_ or next;
2285 my $ctag = $_; $ctag =~ s
#.*/##;
2286 $ctags->{$ctag} = $val;
2292 sub git_populate_project_tagcloud
{
2295 # First, merge different-cased tags; tags vote on casing
2297 foreach (keys %$ctags) {
2298 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2299 if (not $ctags_lc{lc $_}->{topcount
}
2300 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2301 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2302 $ctags_lc{lc $_}->{topname
} = $_;
2307 if (eval { require HTML
::TagCloud
; 1; }) {
2308 $cloud = HTML
::TagCloud-
>new;
2309 foreach (sort keys %ctags_lc) {
2310 # Pad the title with spaces so that the cloud looks
2312 my $title = $ctags_lc{$_}->{topname
};
2313 $title =~ s/ / /g;
2314 $title =~ s/^/ /g;
2315 $title =~ s/$/ /g;
2316 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2319 $cloud = \
%ctags_lc;
2324 sub git_show_project_tagcloud
{
2325 my ($cloud, $count) = @_;
2326 print STDERR
ref($cloud)."..\n";
2327 if (ref $cloud eq 'HTML::TagCloud') {
2328 return $cloud->html_and_css($count);
2330 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2331 return '<p align="center">' . join (', ', map {
2332 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2333 } splice(@tags, 0, $count)) . '</p>';
2337 sub git_get_project_url_list
{
2340 $git_dir = "$projectroot/$path";
2341 open my $fd, '<', "$git_dir/cloneurl"
2342 or return wantarray ?
2343 @{ config_to_multi
(git_get_project_config
('url')) } :
2344 config_to_multi
(git_get_project_config
('url'));
2345 my @git_project_url_list = map { chomp; $_ } <$fd>;
2348 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2351 sub git_get_projects_list
{
2356 $filter =~ s/\.git$//;
2358 my $check_forks = gitweb_check_feature
('forks');
2360 if (-d
$projects_list) {
2361 # search in directory
2362 my $dir = $projects_list . ($filter ? "/$filter" : '');
2363 # remove the trailing "/"
2365 my $pfxlen = length("$dir");
2366 my $pfxdepth = ($dir =~ tr!/!!);
2369 follow_fast
=> 1, # follow symbolic links
2370 follow_skip
=> 2, # ignore duplicates
2371 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2373 # skip project-list toplevel, if we get it.
2374 return if (m!^[/.]$!);
2375 # only directories can be git repositories
2376 return unless (-d
$_);
2377 # don't traverse too deep (Find is super slow on os x)
2378 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2379 $File::Find
::prune
= 1;
2383 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2384 # we check related file in $projectroot
2385 my $path = ($filter ? "$filter/" : '') . $subdir;
2386 if (check_export_ok
("$projectroot/$path")) {
2387 push @list, { path
=> $path };
2388 $File::Find
::prune
= 1;
2393 } elsif (-f
$projects_list) {
2394 # read from file(url-encoded):
2395 # 'git%2Fgit.git Linus+Torvalds'
2396 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2397 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2399 open my $fd, '<', $projects_list or return;
2401 while (my $line = <$fd>) {
2403 my ($path, $owner) = split ' ', $line;
2404 $path = unescape
($path);
2405 $owner = unescape
($owner);
2406 if (!defined $path) {
2409 if ($filter ne '') {
2410 # looking for forks;
2411 my $pfx = substr($path, 0, length($filter));
2412 if ($pfx ne $filter) {
2415 my $sfx = substr($path, length($filter));
2416 if ($sfx !~ /^\/.*\
.git
$/) {
2419 } elsif ($check_forks) {
2421 foreach my $filter (keys %paths) {
2422 # looking for forks;
2423 my $pfx = substr($path, 0, length($filter));
2424 if ($pfx ne $filter) {
2427 my $sfx = substr($path, length($filter));
2428 if ($sfx !~ /^\/.*\
.git
$/) {
2431 # is a fork, don't include it in
2436 if (check_export_ok
("$projectroot/$path")) {
2439 owner
=> to_utf8
($owner),
2442 (my $forks_path = $path) =~ s/\.git$//;
2443 $paths{$forks_path}++;
2451 our $gitweb_project_owner = undef;
2452 sub git_get_project_list_from_file
{
2454 return if (defined $gitweb_project_owner);
2456 $gitweb_project_owner = {};
2457 # read from file (url-encoded):
2458 # 'git%2Fgit.git Linus+Torvalds'
2459 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2460 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2461 if (-f
$projects_list) {
2462 open(my $fd, '<', $projects_list);
2463 while (my $line = <$fd>) {
2465 my ($pr, $ow) = split ' ', $line;
2466 $pr = unescape
($pr);
2467 $ow = unescape
($ow);
2468 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2474 sub git_get_project_owner
{
2475 my $project = shift;
2478 return undef unless $project;
2479 $git_dir = "$projectroot/$project";
2481 if (!defined $gitweb_project_owner) {
2482 git_get_project_list_from_file
();
2485 if (exists $gitweb_project_owner->{$project}) {
2486 $owner = $gitweb_project_owner->{$project};
2488 if (!defined $owner){
2489 $owner = git_get_project_config
('owner');
2491 if (!defined $owner) {
2492 $owner = get_file_owner
("$git_dir");
2498 sub git_get_last_activity
{
2502 $git_dir = "$projectroot/$path";
2503 open($fd, "-|", git_cmd
(), 'for-each-ref',
2504 '--format=%(committer)',
2505 '--sort=-committerdate',
2507 'refs/heads') or return;
2508 my $most_recent = <$fd>;
2509 close $fd or return;
2510 if (defined $most_recent &&
2511 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2513 my $age = time - $timestamp;
2514 return ($age, age_string
($age));
2516 return (undef, undef);
2519 sub git_get_references
{
2520 my $type = shift || "";
2522 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2523 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2524 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2525 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2528 while (my $line = <$fd>) {
2530 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2531 if (defined $refs{$1}) {
2532 push @{$refs{$1}}, $2;
2538 close $fd or return;
2542 sub git_get_rev_name_tags
{
2543 my $hash = shift || return undef;
2545 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2547 my $name_rev = <$fd>;
2550 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2553 # catches also '$hash undefined' output
2558 ## ----------------------------------------------------------------------
2559 ## parse to hash functions
2563 my $tz = shift || "-0000";
2566 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2567 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2568 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2569 $date{'hour'} = $hour;
2570 $date{'minute'} = $min;
2571 $date{'mday'} = $mday;
2572 $date{'day'} = $days[$wday];
2573 $date{'month'} = $months[$mon];
2574 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2575 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2576 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2577 $mday, $months[$mon], $hour ,$min;
2578 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2579 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2581 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2582 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2583 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2584 $date{'hour_local'} = $hour;
2585 $date{'minute_local'} = $min;
2586 $date{'tz_local'} = $tz;
2587 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2588 1900+$year, $mon+1, $mday,
2589 $hour, $min, $sec, $tz);
2598 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2599 $tag{'id'} = $tag_id;
2600 while (my $line = <$fd>) {
2602 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2603 $tag{'object'} = $1;
2604 } elsif ($line =~ m/^type (.+)$/) {
2606 } elsif ($line =~ m/^tag (.+)$/) {
2608 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2609 $tag{'author'} = $1;
2610 $tag{'author_epoch'} = $2;
2611 $tag{'author_tz'} = $3;
2612 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2613 $tag{'author_name'} = $1;
2614 $tag{'author_email'} = $2;
2616 $tag{'author_name'} = $tag{'author'};
2618 } elsif ($line =~ m/--BEGIN/) {
2619 push @comment, $line;
2621 } elsif ($line eq "") {
2625 push @comment, <$fd>;
2626 $tag{'comment'} = \
@comment;
2627 close $fd or return;
2628 if (!defined $tag{'name'}) {
2634 sub parse_commit_text
{
2635 my ($commit_text, $withparents) = @_;
2636 my @commit_lines = split '\n', $commit_text;
2639 pop @commit_lines; # Remove '\0'
2641 if (! @commit_lines) {
2645 my $header = shift @commit_lines;
2646 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2649 ($co{'id'}, my @parents) = split ' ', $header;
2650 while (my $line = shift @commit_lines) {
2651 last if $line eq "\n";
2652 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2654 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2656 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2657 $co{'author'} = to_utf8
($1);
2658 $co{'author_epoch'} = $2;
2659 $co{'author_tz'} = $3;
2660 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2661 $co{'author_name'} = $1;
2662 $co{'author_email'} = $2;
2664 $co{'author_name'} = $co{'author'};
2666 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2667 $co{'committer'} = to_utf8
($1);
2668 $co{'committer_epoch'} = $2;
2669 $co{'committer_tz'} = $3;
2670 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2671 $co{'committer_name'} = $1;
2672 $co{'committer_email'} = $2;
2674 $co{'committer_name'} = $co{'committer'};
2678 if (!defined $co{'tree'}) {
2681 $co{'parents'} = \
@parents;
2682 $co{'parent'} = $parents[0];
2684 foreach my $title (@commit_lines) {
2687 $co{'title'} = chop_str
($title, 80, 5);
2688 # remove leading stuff of merges to make the interesting part visible
2689 if (length($title) > 50) {
2690 $title =~ s/^Automatic //;
2691 $title =~ s/^merge (of|with) /Merge ... /i;
2692 if (length($title) > 50) {
2693 $title =~ s/(http|rsync):\/\///;
2695 if (length($title) > 50) {
2696 $title =~ s/(master|www|rsync)\.//;
2698 if (length($title) > 50) {
2699 $title =~ s/kernel.org:?//;
2701 if (length($title) > 50) {
2702 $title =~ s/\/pub\/scm//;
2705 $co{'title_short'} = chop_str
($title, 50, 5);
2709 if (! defined $co{'title'} || $co{'title'} eq "") {
2710 $co{'title'} = $co{'title_short'} = '(no commit message)';
2712 # remove added spaces
2713 foreach my $line (@commit_lines) {
2716 $co{'comment'} = \
@commit_lines;
2718 my $age = time - $co{'committer_epoch'};
2720 $co{'age_string'} = age_string
($age);
2721 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2722 if ($age > 60*60*24*7*2) {
2723 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2724 $co{'age_string_age'} = $co{'age_string'};
2726 $co{'age_string_date'} = $co{'age_string'};
2727 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2733 my ($commit_id) = @_;
2738 open my $fd, "-|", git_cmd
(), "rev-list",
2744 or die_error
(500, "Open git-rev-list failed");
2745 %co = parse_commit_text
(<$fd>, 1);
2752 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2760 open my $fd, "-|", git_cmd
(), "rev-list",
2763 ("--max-count=" . $maxcount),
2764 ("--skip=" . $skip),
2768 ($filename ? ($filename) : ())
2769 or die_error
(500, "Open git-rev-list failed");
2770 while (my $line = <$fd>) {
2771 my %co = parse_commit_text
($line);
2776 return wantarray ? @cos : \
@cos;
2779 # parse line of git-diff-tree "raw" output
2780 sub parse_difftree_raw_line
{
2784 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2785 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2786 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2787 $res{'from_mode'} = $1;
2788 $res{'to_mode'} = $2;
2789 $res{'from_id'} = $3;
2791 $res{'status'} = $5;
2792 $res{'similarity'} = $6;
2793 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2794 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2796 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2799 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2800 # combined diff (for merge commit)
2801 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2802 $res{'nparents'} = length($1);
2803 $res{'from_mode'} = [ split(' ', $2) ];
2804 $res{'to_mode'} = pop @{$res{'from_mode'}};
2805 $res{'from_id'} = [ split(' ', $3) ];
2806 $res{'to_id'} = pop @{$res{'from_id'}};
2807 $res{'status'} = [ split('', $4) ];
2808 $res{'to_file'} = unquote
($5);
2810 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2811 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2812 $res{'commit'} = $1;
2815 return wantarray ? %res : \
%res;
2818 # wrapper: return parsed line of git-diff-tree "raw" output
2819 # (the argument might be raw line, or parsed info)
2820 sub parsed_difftree_line
{
2821 my $line_or_ref = shift;
2823 if (ref($line_or_ref) eq "HASH") {
2824 # pre-parsed (or generated by hand)
2825 return $line_or_ref;
2827 return parse_difftree_raw_line
($line_or_ref);
2831 # parse line of git-ls-tree output
2832 sub parse_ls_tree_line
{
2838 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2839 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2848 $res{'name'} = unquote
($5);
2851 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2852 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2860 $res{'name'} = unquote
($4);
2864 return wantarray ? %res : \
%res;
2867 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2868 sub parse_from_to_diffinfo
{
2869 my ($diffinfo, $from, $to, @parents) = @_;
2871 if ($diffinfo->{'nparents'}) {
2873 $from->{'file'} = [];
2874 $from->{'href'} = [];
2875 fill_from_file_info
($diffinfo, @parents)
2876 unless exists $diffinfo->{'from_file'};
2877 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2878 $from->{'file'}[$i] =
2879 defined $diffinfo->{'from_file'}[$i] ?
2880 $diffinfo->{'from_file'}[$i] :
2881 $diffinfo->{'to_file'};
2882 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2883 $from->{'href'}[$i] = href
(action
=>"blob",
2884 hash_base
=>$parents[$i],
2885 hash
=>$diffinfo->{'from_id'}[$i],
2886 file_name
=>$from->{'file'}[$i]);
2888 $from->{'href'}[$i] = undef;
2892 # ordinary (not combined) diff
2893 $from->{'file'} = $diffinfo->{'from_file'};
2894 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2895 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2896 hash
=>$diffinfo->{'from_id'},
2897 file_name
=>$from->{'file'});
2899 delete $from->{'href'};
2903 $to->{'file'} = $diffinfo->{'to_file'};
2904 if (!is_deleted
($diffinfo)) { # file exists in result
2905 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2906 hash
=>$diffinfo->{'to_id'},
2907 file_name
=>$to->{'file'});
2909 delete $to->{'href'};
2913 ## ......................................................................
2914 ## parse to array of hashes functions
2916 sub git_get_heads_list
{
2920 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2921 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2922 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2925 while (my $line = <$fd>) {
2929 my ($refinfo, $committerinfo) = split(/\0/, $line);
2930 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2931 my ($committer, $epoch, $tz) =
2932 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2933 $ref_item{'fullname'} = $name;
2934 $name =~ s!^refs/heads/!!;
2936 $ref_item{'name'} = $name;
2937 $ref_item{'id'} = $hash;
2938 $ref_item{'title'} = $title || '(no commit message)';
2939 $ref_item{'epoch'} = $epoch;
2941 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2943 $ref_item{'age'} = "unknown";
2946 push @headslist, \
%ref_item;
2950 return wantarray ? @headslist : \
@headslist;
2953 sub git_get_tags_list
{
2957 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2958 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2959 '--format=%(objectname) %(objecttype) %(refname) '.
2960 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2963 while (my $line = <$fd>) {
2967 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2968 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2969 my ($creator, $epoch, $tz) =
2970 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2971 $ref_item{'fullname'} = $name;
2972 $name =~ s!^refs/tags/!!;
2974 $ref_item{'type'} = $type;
2975 $ref_item{'id'} = $id;
2976 $ref_item{'name'} = $name;
2977 if ($type eq "tag") {
2978 $ref_item{'subject'} = $title;
2979 $ref_item{'reftype'} = $reftype;
2980 $ref_item{'refid'} = $refid;
2982 $ref_item{'reftype'} = $type;
2983 $ref_item{'refid'} = $id;
2986 if ($type eq "tag" || $type eq "commit") {
2987 $ref_item{'epoch'} = $epoch;
2989 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2991 $ref_item{'age'} = "unknown";
2995 push @tagslist, \
%ref_item;
2999 return wantarray ? @tagslist : \
@tagslist;
3002 ## ----------------------------------------------------------------------
3003 ## filesystem-related functions
3005 sub get_file_owner
{
3008 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3009 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3010 if (!defined $gcos) {
3014 $owner =~ s/[,;].*$//;
3015 return to_utf8
($owner);
3018 # assume that file exists
3020 my $filename = shift;
3022 open my $fd, '<', $filename;
3023 print map { to_utf8
($_) } <$fd>;
3027 ## ......................................................................
3028 ## mimetype related functions
3030 sub mimetype_guess_file
{
3031 my $filename = shift;
3032 my $mimemap = shift;
3033 -r
$mimemap or return undef;
3036 open(my $mh, '<', $mimemap) or return undef;
3038 next if m/^#/; # skip comments
3039 my ($mimetype, $exts) = split(/\t+/);
3040 if (defined $exts) {
3041 my @exts = split(/\s+/, $exts);
3042 foreach my $ext (@exts) {
3043 $mimemap{$ext} = $mimetype;
3049 $filename =~ /\.([^.]*)$/;
3050 return $mimemap{$1};
3053 sub mimetype_guess
{
3054 my $filename = shift;
3056 $filename =~ /\./ or return undef;
3058 if ($mimetypes_file) {
3059 my $file = $mimetypes_file;
3060 if ($file !~ m!^/!) { # if it is relative path
3061 # it is relative to project
3062 $file = "$projectroot/$project/$file";
3064 $mime = mimetype_guess_file
($filename, $file);
3066 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3072 my $filename = shift;
3075 my $mime = mimetype_guess
($filename);
3076 $mime and return $mime;
3080 return $default_blob_plain_mimetype unless $fd;
3083 return 'text/plain';
3084 } elsif (! $filename) {
3085 return 'application/octet-stream';
3086 } elsif ($filename =~ m/\.png$/i) {
3088 } elsif ($filename =~ m/\.gif$/i) {
3090 } elsif ($filename =~ m/\.jpe?g$/i) {
3091 return 'image/jpeg';
3093 return 'application/octet-stream';
3097 sub blob_contenttype
{
3098 my ($fd, $file_name, $type) = @_;
3100 $type ||= blob_mimetype
($fd, $file_name);
3101 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3102 $type .= "; charset=$default_text_plain_charset";
3108 ## ======================================================================
3109 ## functions printing HTML: header, footer, error page
3111 sub git_header_html
{
3112 my $status = shift || "200 OK";
3113 my $expires = shift;
3115 my $title = "$site_name";
3116 if (defined $project) {
3117 $title .= " - " . to_utf8
($project);
3118 if (defined $action) {
3119 $title .= "/$action";
3120 if (defined $file_name) {
3121 $title .= " - " . esc_path
($file_name);
3122 if ($action eq "tree" && $file_name !~ m
|/$|) {
3129 # require explicit support from the UA if we are to send the page as
3130 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3131 # we have to do this because MSIE sometimes globs '*/*', pretending to
3132 # support xhtml+xml but choking when it gets what it asked for.
3133 if (defined $cgi->http('HTTP_ACCEPT') &&
3134 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3135 $cgi->Accept('application/xhtml+xml') != 0) {
3136 $content_type = 'application/xhtml+xml';
3138 $content_type = 'text/html';
3140 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3141 -status
=> $status, -expires
=> $expires);
3142 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3144 <?xml version="1.0" encoding="utf-8"?>
3145 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3146 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3147 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3148 <!-- git core binaries version $git_version -->
3150 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3151 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3152 <meta name="robots" content="index, nofollow"/>
3153 <title>$title</title>
3155 # the stylesheet, favicon etc urls won't work correctly with path_info
3156 # unless we set the appropriate base URL
3157 if ($ENV{'PATH_INFO'}) {
3158 print "<base href=\"".esc_url
($base_url)."\" />\n";
3160 # print out each stylesheet that exist, providing backwards capability
3161 # for those people who defined $stylesheet in a config file
3162 if (defined $stylesheet) {
3163 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3165 foreach my $stylesheet (@stylesheets) {
3166 next unless $stylesheet;
3167 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3170 if (defined $project) {
3171 my %href_params = get_feed_info
();
3172 if (!exists $href_params{'-title'}) {
3173 $href_params{'-title'} = 'log';
3176 foreach my $format qw(RSS Atom) {
3177 my $type = lc($format);
3179 '-rel' => 'alternate',
3180 '-title' => "$project - $href_params{'-title'} - $format feed",
3181 '-type' => "application/$type+xml"
3184 $href_params{'action'} = $type;
3185 $link_attr{'-href'} = href
(%href_params);
3187 "rel=\"$link_attr{'-rel'}\" ".
3188 "title=\"$link_attr{'-title'}\" ".
3189 "href=\"$link_attr{'-href'}\" ".
3190 "type=\"$link_attr{'-type'}\" ".
3193 $href_params{'extra_options'} = '--no-merges';
3194 $link_attr{'-href'} = href
(%href_params);
3195 $link_attr{'-title'} .= ' (no merges)';
3197 "rel=\"$link_attr{'-rel'}\" ".
3198 "title=\"$link_attr{'-title'}\" ".
3199 "href=\"$link_attr{'-href'}\" ".
3200 "type=\"$link_attr{'-type'}\" ".
3205 printf('<link rel="alternate" title="%s projects list" '.
3206 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3207 $site_name, href
(project
=>undef, action
=>"project_index"));
3208 printf('<link rel="alternate" title="%s projects feeds" '.
3209 'href="%s" type="text/x-opml" />'."\n",
3210 $site_name, href
(project
=>undef, action
=>"opml"));
3212 if (defined $favicon) {
3213 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3219 if (-f
$site_header) {
3220 insert_file
($site_header);
3223 print "<div class=\"page_header\">\n" .
3224 $cgi->a({-href
=> esc_url
($logo_url),
3225 -title
=> $logo_label},
3226 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3227 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3228 if (defined $project) {
3229 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3230 if (defined $action) {
3237 my $have_search = gitweb_check_feature
('search');
3238 if (defined $project && $have_search) {
3239 if (!defined $searchtext) {
3243 if (defined $hash_base) {
3244 $search_hash = $hash_base;
3245 } elsif (defined $hash) {
3246 $search_hash = $hash;
3248 $search_hash = "HEAD";
3250 my $action = $my_uri;
3251 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3252 if ($use_pathinfo) {
3253 $action .= "/".esc_url
($project);
3255 print $cgi->startform(-method => "get", -action
=> $action) .
3256 "<div class=\"search\">\n" .
3258 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3259 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3260 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3261 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3262 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3263 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3265 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3266 "<span title=\"Extended regular expression\">" .
3267 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3268 -checked
=> $search_use_regexp) .
3271 $cgi->end_form() . "\n";
3275 sub git_footer_html
{
3276 my $feed_class = 'rss_logo';
3278 print "<div class=\"page_footer\">\n";
3279 if (defined $project) {
3280 my $descr = git_get_project_description
($project);
3281 if (defined $descr) {
3282 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3285 my %href_params = get_feed_info
();
3286 if (!%href_params) {
3287 $feed_class .= ' generic';
3289 $href_params{'-title'} ||= 'log';
3291 foreach my $format qw(RSS Atom) {
3292 $href_params{'action'} = lc($format);
3293 print $cgi->a({-href
=> href
(%href_params),
3294 -title
=> "$href_params{'-title'} $format feed",
3295 -class => $feed_class}, $format)."\n";
3299 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3300 -class => $feed_class}, "OPML") . " ";
3301 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3302 -class => $feed_class}, "TXT") . "\n";
3304 print "</div>\n"; # class="page_footer"
3306 if (defined $t0 && gitweb_check_feature
('timed')) {
3307 print "<div id=\"generating_info\">\n";
3308 print 'This page took '.
3309 '<span id="generating_time" class="time_span">'.
3310 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3313 '<span id="generating_cmd">'.
3314 $number_of_git_cmds.
3315 '</span> git commands '.
3317 print "</div>\n"; # class="page_footer"
3320 if (-f
$site_footer) {
3321 insert_file
($site_footer);
3324 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3325 if ($action eq 'blame_incremental') {
3326 print qq
!<script type
="text/javascript">\n!.
3327 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3328 qq
! "!. href() .qq!");\n!.
3331 print qq
!<script type
="text/javascript">\n!.
3332 qq
!window
.onload
= fixLinks
;\n!.
3340 # die_error(<http_status_code>, <error_message>)
3341 # Example: die_error(404, 'Hash not found')
3342 # By convention, use the following status codes (as defined in RFC 2616):
3343 # 400: Invalid or missing CGI parameters, or
3344 # requested object exists but has wrong type.
3345 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3346 # this server or project.
3347 # 404: Requested object/revision/project doesn't exist.
3348 # 500: The server isn't configured properly, or
3349 # an internal error occurred (e.g. failed assertions caused by bugs), or
3350 # an unknown error occurred (e.g. the git binary died unexpectedly).
3352 my $status = shift || 500;
3353 my $error = shift || "Internal server error";
3355 my %http_responses = (400 => '400 Bad Request',
3356 403 => '403 Forbidden',
3357 404 => '404 Not Found',
3358 500 => '500 Internal Server Error');
3359 git_header_html
($http_responses{$status});
3361 <div class="page_body">
3371 ## ----------------------------------------------------------------------
3372 ## functions printing or outputting HTML: navigation
3374 sub git_print_page_nav
{
3375 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3376 $extra = '' if !defined $extra; # pager or formats
3378 my @navs = qw(summary shortlog log commit commitdiff tree);
3380 @navs = grep { $_ ne $suppress } @navs;
3383 my %arg = map { $_ => {action
=>$_} } @navs;
3384 if (defined $head) {
3385 for (qw(commit commitdiff)) {
3386 $arg{$_}{'hash'} = $head;
3388 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3389 for (qw(shortlog log)) {
3390 $arg{$_}{'hash'} = $head;
3395 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3396 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3398 my @actions = gitweb_get_feature
('actions');
3401 'n' => $project, # project name
3402 'f' => $git_dir, # project path within filesystem
3403 'h' => $treehead || '', # current hash ('h' parameter)
3404 'b' => $treebase || '', # hash base ('hb' parameter)
3407 my ($label, $link, $pos) = splice(@actions,0,3);
3409 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3411 $link =~ s/%([%nfhb])/$repl{$1}/g;
3412 $arg{$label}{'_href'} = $link;
3415 print "<div class=\"page_nav\">\n" .
3417 map { $_ eq $current ?
3418 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3420 print "<br/>\n$extra<br/>\n" .
3424 sub format_paging_nav
{
3425 my ($action, $hash, $head, $page, $has_next_link) = @_;
3429 if ($hash ne $head || $page) {
3430 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3432 $paging_nav .= "HEAD";
3436 $paging_nav .= " ⋅ " .
3437 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3438 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3440 $paging_nav .= " ⋅ prev";
3443 if ($has_next_link) {
3444 $paging_nav .= " ⋅ " .
3445 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3446 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3448 $paging_nav .= " ⋅ next";
3454 ## ......................................................................
3455 ## functions printing or outputting HTML: div
3457 sub git_print_header_div
{
3458 my ($action, $title, $hash, $hash_base) = @_;
3461 $args{'action'} = $action;
3462 $args{'hash'} = $hash if $hash;
3463 $args{'hash_base'} = $hash_base if $hash_base;
3465 print "<div class=\"header\">\n" .
3466 $cgi->a({-href
=> href
(%args), -class => "title"},
3467 $title ? $title : $action) .
3471 sub print_local_time
{
3473 if ($date{'hour_local'} < 6) {
3474 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3475 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3477 printf(" (%02d:%02d %s)",
3478 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3482 # Outputs the author name and date in long form
3483 sub git_print_authorship
{
3486 my $tag = $opts{-tag
} || 'div';
3487 my $author = $co->{'author_name'};
3489 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3490 print "<$tag class=\"author_date\">" .
3491 format_search_author
($author, "author", esc_html
($author)) .
3493 print_local_time
(%ad) if ($opts{-localtime});
3494 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3498 # Outputs table rows containing the full author or committer information,
3499 # in the format expected for 'commit' view (& similia).
3500 # Parameters are a commit hash reference, followed by the list of people
3501 # to output information for. If the list is empty it defalts to both
3502 # author and committer.
3503 sub git_print_authorship_rows
{
3505 # too bad we can't use @people = @_ || ('author', 'committer')
3507 @people = ('author', 'committer') unless @people;
3508 foreach my $who (@people) {
3509 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3510 print "<tr><td>$who</td><td>" .
3511 format_search_author
($co->{"${who}_name"}, $who,
3512 esc_html
($co->{"${who}_name"})) . " " .
3513 format_search_author
($co->{"${who}_email"}, $who,
3514 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3515 "</td><td rowspan=\"2\">" .
3516 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3519 "<td></td><td> $wd{'rfc2822'}";
3520 print_local_time
(%wd);
3526 sub git_print_page_path
{
3532 print "<div class=\"page_path\">";
3533 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3534 -title
=> 'tree root'}, to_utf8
("[$project]"));
3536 if (defined $name) {
3537 my @dirname = split '/', $name;
3538 my $basename = pop @dirname;
3541 foreach my $dir (@dirname) {
3542 $fullname .= ($fullname ? '/' : '') . $dir;
3543 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3545 -title
=> $fullname}, esc_path
($dir));
3548 if (defined $type && $type eq 'blob') {
3549 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3551 -title
=> $name}, esc_path
($basename));
3552 } elsif (defined $type && $type eq 'tree') {
3553 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3555 -title
=> $name}, esc_path
($basename));
3558 print esc_path
($basename);
3561 print "<br/></div>\n";
3568 if ($opts{'-remove_title'}) {
3569 # remove title, i.e. first line of log
3572 # remove leading empty lines
3573 while (defined $log->[0] && $log->[0] eq "") {
3580 foreach my $line (@$log) {
3581 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3584 if (! $opts{'-remove_signoff'}) {
3585 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3588 # remove signoff lines
3595 # print only one empty line
3596 # do not print empty line after signoff
3598 next if ($empty || $signoff);
3604 print format_log_line_html
($line) . "<br/>\n";
3607 if ($opts{'-final_empty_line'}) {
3608 # end with single empty line
3609 print "<br/>\n" unless $empty;
3613 # return link target (what link points to)
3614 sub git_get_link_target
{
3619 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3623 $link_target = <$fd>;
3628 return $link_target;
3631 # given link target, and the directory (basedir) the link is in,
3632 # return target of link relative to top directory (top tree);
3633 # return undef if it is not possible (including absolute links).
3634 sub normalize_link_target
{
3635 my ($link_target, $basedir) = @_;
3637 # absolute symlinks (beginning with '/') cannot be normalized
3638 return if (substr($link_target, 0, 1) eq '/');
3640 # normalize link target to path from top (root) tree (dir)
3643 $path = $basedir . '/' . $link_target;
3645 # we are in top (root) tree (dir)
3646 $path = $link_target;
3649 # remove //, /./, and /../
3651 foreach my $part (split('/', $path)) {
3652 # discard '.' and ''
3653 next if (!$part || $part eq '.');
3655 if ($part eq '..') {
3659 # link leads outside repository (outside top dir)
3663 push @path_parts, $part;
3666 $path = join('/', @path_parts);
3671 # print tree entry (row of git_tree), but without encompassing <tr> element
3672 sub git_print_tree_entry
{
3673 my ($t, $basedir, $hash_base, $have_blame) = @_;
3676 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3678 # The format of a table row is: mode list link. Where mode is
3679 # the mode of the entry, list is the name of the entry, an href,
3680 # and link is the action links of the entry.
3682 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3683 if (exists $t->{'size'}) {
3684 print "<td class=\"size\">$t->{'size'}</td>\n";
3686 if ($t->{'type'} eq "blob") {
3687 print "<td class=\"list\">" .
3688 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3689 file_name
=>"$basedir$t->{'name'}", %base_key),
3690 -class => "list"}, esc_path
($t->{'name'}));
3691 if (S_ISLNK
(oct $t->{'mode'})) {
3692 my $link_target = git_get_link_target
($t->{'hash'});
3694 my $norm_target = normalize_link_target
($link_target, $basedir);
3695 if (defined $norm_target) {
3697 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3698 file_name
=>$norm_target),
3699 -title
=> $norm_target}, esc_path
($link_target));
3701 print " -> " . esc_path
($link_target);
3706 print "<td class=\"link\">";
3707 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3708 file_name
=>"$basedir$t->{'name'}", %base_key)},
3712 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3713 file_name
=>"$basedir$t->{'name'}", %base_key)},
3716 if (defined $hash_base) {
3718 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3719 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3723 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3724 file_name
=>"$basedir$t->{'name'}")},
3728 } elsif ($t->{'type'} eq "tree") {
3729 print "<td class=\"list\">";
3730 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3731 file_name
=>"$basedir$t->{'name'}",
3733 esc_path
($t->{'name'}));
3735 print "<td class=\"link\">";
3736 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3737 file_name
=>"$basedir$t->{'name'}",
3740 if (defined $hash_base) {
3742 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3743 file_name
=>"$basedir$t->{'name'}")},
3748 # unknown object: we can only present history for it
3749 # (this includes 'commit' object, i.e. submodule support)
3750 print "<td class=\"list\">" .
3751 esc_path
($t->{'name'}) .
3753 print "<td class=\"link\">";
3754 if (defined $hash_base) {
3755 print $cgi->a({-href
=> href
(action
=>"history",
3756 hash_base
=>$hash_base,
3757 file_name
=>"$basedir$t->{'name'}")},
3764 ## ......................................................................
3765 ## functions printing large fragments of HTML
3767 # get pre-image filenames for merge (combined) diff
3768 sub fill_from_file_info
{
3769 my ($diff, @parents) = @_;
3771 $diff->{'from_file'} = [ ];
3772 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3773 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3774 if ($diff->{'status'}[$i] eq 'R' ||
3775 $diff->{'status'}[$i] eq 'C') {
3776 $diff->{'from_file'}[$i] =
3777 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3784 # is current raw difftree line of file deletion
3786 my $diffinfo = shift;
3788 return $diffinfo->{'to_id'} eq ('0' x
40);
3791 # does patch correspond to [previous] difftree raw line
3792 # $diffinfo - hashref of parsed raw diff format
3793 # $patchinfo - hashref of parsed patch diff format
3794 # (the same keys as in $diffinfo)
3795 sub is_patch_split
{
3796 my ($diffinfo, $patchinfo) = @_;
3798 return defined $diffinfo && defined $patchinfo
3799 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3803 sub git_difftree_body
{
3804 my ($difftree, $hash, @parents) = @_;
3805 my ($parent) = $parents[0];
3806 my $have_blame = gitweb_check_feature
('blame');
3807 print "<div class=\"list_head\">\n";
3808 if ($#{$difftree} > 10) {
3809 print(($#{$difftree} + 1) . " files changed:\n");
3813 print "<table class=\"" .
3814 (@parents > 1 ? "combined " : "") .
3817 # header only for combined diff in 'commitdiff' view
3818 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3821 print "<thead><tr>\n" .
3822 "<th></th><th></th>\n"; # filename, patchN link
3823 for (my $i = 0; $i < @parents; $i++) {
3824 my $par = $parents[$i];
3826 $cgi->a({-href
=> href
(action
=>"commitdiff",
3827 hash
=>$hash, hash_parent
=>$par),
3828 -title
=> 'commitdiff to parent number ' .
3829 ($i+1) . ': ' . substr($par,0,7)},
3833 print "</tr></thead>\n<tbody>\n";
3838 foreach my $line (@{$difftree}) {
3839 my $diff = parsed_difftree_line
($line);
3842 print "<tr class=\"dark\">\n";
3844 print "<tr class=\"light\">\n";
3848 if (exists $diff->{'nparents'}) { # combined diff
3850 fill_from_file_info
($diff, @parents)
3851 unless exists $diff->{'from_file'};
3853 if (!is_deleted
($diff)) {
3854 # file exists in the result (child) commit
3856 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3857 file_name
=>$diff->{'to_file'},
3859 -class => "list"}, esc_path
($diff->{'to_file'})) .
3863 esc_path
($diff->{'to_file'}) .
3867 if ($action eq 'commitdiff') {
3870 print "<td class=\"link\">" .
3871 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3876 my $has_history = 0;
3877 my $not_deleted = 0;
3878 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3879 my $hash_parent = $parents[$i];
3880 my $from_hash = $diff->{'from_id'}[$i];
3881 my $from_path = $diff->{'from_file'}[$i];
3882 my $status = $diff->{'status'}[$i];
3884 $has_history ||= ($status ne 'A');
3885 $not_deleted ||= ($status ne 'D');
3887 if ($status eq 'A') {
3888 print "<td class=\"link\" align=\"right\"> | </td>\n";
3889 } elsif ($status eq 'D') {
3890 print "<td class=\"link\">" .
3891 $cgi->a({-href
=> href
(action
=>"blob",
3894 file_name
=>$from_path)},
3898 if ($diff->{'to_id'} eq $from_hash) {
3899 print "<td class=\"link nochange\">";
3901 print "<td class=\"link\">";
3903 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3904 hash
=>$diff->{'to_id'},
3905 hash_parent
=>$from_hash,
3907 hash_parent_base
=>$hash_parent,
3908 file_name
=>$diff->{'to_file'},
3909 file_parent
=>$from_path)},
3915 print "<td class=\"link\">";
3917 print $cgi->a({-href
=> href
(action
=>"blob",
3918 hash
=>$diff->{'to_id'},
3919 file_name
=>$diff->{'to_file'},
3922 print " | " if ($has_history);
3925 print $cgi->a({-href
=> href
(action
=>"history",
3926 file_name
=>$diff->{'to_file'},
3933 next; # instead of 'else' clause, to avoid extra indent
3935 # else ordinary diff
3937 my ($to_mode_oct, $to_mode_str, $to_file_type);
3938 my ($from_mode_oct, $from_mode_str, $from_file_type);
3939 if ($diff->{'to_mode'} ne ('0' x
6)) {
3940 $to_mode_oct = oct $diff->{'to_mode'};
3941 if (S_ISREG
($to_mode_oct)) { # only for regular file
3942 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3944 $to_file_type = file_type
($diff->{'to_mode'});
3946 if ($diff->{'from_mode'} ne ('0' x
6)) {
3947 $from_mode_oct = oct $diff->{'from_mode'};
3948 if (S_ISREG
($to_mode_oct)) { # only for regular file
3949 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3951 $from_file_type = file_type
($diff->{'from_mode'});
3954 if ($diff->{'status'} eq "A") { # created
3955 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3956 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3957 $mode_chng .= "]</span>";
3959 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3960 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3961 -class => "list"}, esc_path
($diff->{'file'}));
3963 print "<td>$mode_chng</td>\n";
3964 print "<td class=\"link\">";
3965 if ($action eq 'commitdiff') {
3968 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3971 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3972 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3976 } elsif ($diff->{'status'} eq "D") { # deleted
3977 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3979 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3980 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3981 -class => "list"}, esc_path
($diff->{'file'}));
3983 print "<td>$mode_chng</td>\n";
3984 print "<td class=\"link\">";
3985 if ($action eq 'commitdiff') {
3988 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3991 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3992 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3995 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3996 file_name
=>$diff->{'file'})},
3999 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4000 file_name
=>$diff->{'file'})},
4004 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4005 my $mode_chnge = "";
4006 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4007 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4008 if ($from_file_type ne $to_file_type) {
4009 $mode_chnge .= " from $from_file_type to $to_file_type";
4011 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4012 if ($from_mode_str && $to_mode_str) {
4013 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4014 } elsif ($to_mode_str) {
4015 $mode_chnge .= " mode: $to_mode_str";
4018 $mode_chnge .= "]</span>\n";
4021 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4022 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4023 -class => "list"}, esc_path
($diff->{'file'}));
4025 print "<td>$mode_chnge</td>\n";
4026 print "<td class=\"link\">";
4027 if ($action eq 'commitdiff') {
4030 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4032 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4033 # "commit" view and modified file (not onlu mode changed)
4034 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4035 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4036 hash_base
=>$hash, hash_parent_base
=>$parent,
4037 file_name
=>$diff->{'file'})},
4041 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4042 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4045 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4046 file_name
=>$diff->{'file'})},
4049 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4050 file_name
=>$diff->{'file'})},
4054 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4055 my %status_name = ('R' => 'moved', 'C' => 'copied');
4056 my $nstatus = $status_name{$diff->{'status'}};
4058 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4059 # mode also for directories, so we cannot use $to_mode_str
4060 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4063 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4064 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4065 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4066 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4067 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4068 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4069 -class => "list"}, esc_path
($diff->{'from_file'})) .
4070 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4071 "<td class=\"link\">";
4072 if ($action eq 'commitdiff') {
4075 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4077 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4078 # "commit" view and modified file (not only pure rename or copy)
4079 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4080 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4081 hash_base
=>$hash, hash_parent_base
=>$parent,
4082 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4086 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4087 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4090 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4091 file_name
=>$diff->{'to_file'})},
4094 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4095 file_name
=>$diff->{'to_file'})},
4099 } # we should not encounter Unmerged (U) or Unknown (X) status
4102 print "</tbody>" if $has_header;
4106 sub git_patchset_body
{
4107 my ($fd, $difftree, $hash, @hash_parents) = @_;
4108 my ($hash_parent) = $hash_parents[0];
4110 my $is_combined = (@hash_parents > 1);
4112 my $patch_number = 0;
4118 print "<div class=\"patchset\">\n";
4120 # skip to first patch
4121 while ($patch_line = <$fd>) {
4124 last if ($patch_line =~ m/^diff /);
4128 while ($patch_line) {
4130 # parse "git diff" header line
4131 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4132 # $1 is from_name, which we do not use
4133 $to_name = unquote
($2);
4134 $to_name =~ s!^b/!!;
4135 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4136 # $1 is 'cc' or 'combined', which we do not use
4137 $to_name = unquote
($2);
4142 # check if current patch belong to current raw line
4143 # and parse raw git-diff line if needed
4144 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4145 # this is continuation of a split patch
4146 print "<div class=\"patch cont\">\n";
4148 # advance raw git-diff output if needed
4149 $patch_idx++ if defined $diffinfo;
4151 # read and prepare patch information
4152 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4154 # compact combined diff output can have some patches skipped
4155 # find which patch (using pathname of result) we are at now;
4157 while ($to_name ne $diffinfo->{'to_file'}) {
4158 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4159 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4160 "</div>\n"; # class="patch"
4165 last if $patch_idx > $#$difftree;
4166 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4170 # modifies %from, %to hashes
4171 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4173 # this is first patch for raw difftree line with $patch_idx index
4174 # we index @$difftree array from 0, but number patches from 1
4175 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4179 #assert($patch_line =~ m/^diff /) if DEBUG;
4180 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4182 # print "git diff" header
4183 print format_git_diff_header_line
($patch_line, $diffinfo,
4186 # print extended diff header
4187 print "<div class=\"diff extended_header\">\n";
4189 while ($patch_line = <$fd>) {
4192 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4194 print format_extended_diff_header_line
($patch_line, $diffinfo,
4197 print "</div>\n"; # class="diff extended_header"
4199 # from-file/to-file diff header
4200 if (! $patch_line) {
4201 print "</div>\n"; # class="patch"
4204 next PATCH
if ($patch_line =~ m/^diff /);
4205 #assert($patch_line =~ m/^---/) if DEBUG;
4207 my $last_patch_line = $patch_line;
4208 $patch_line = <$fd>;
4210 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4212 print format_diff_from_to_header
($last_patch_line, $patch_line,
4213 $diffinfo, \
%from, \
%to,
4218 while ($patch_line = <$fd>) {
4221 next PATCH
if ($patch_line =~ m/^diff /);
4223 print format_diff_line
($patch_line, \
%from, \
%to);
4227 print "</div>\n"; # class="patch"
4230 # for compact combined (--cc) format, with chunk and patch simpliciaction
4231 # patchset might be empty, but there might be unprocessed raw lines
4232 for (++$patch_idx if $patch_number > 0;
4233 $patch_idx < @$difftree;
4235 # read and prepare patch information
4236 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4238 # generate anchor for "patch" links in difftree / whatchanged part
4239 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4240 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4241 "</div>\n"; # class="patch"
4246 if ($patch_number == 0) {
4247 if (@hash_parents > 1) {
4248 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4250 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4254 print "</div>\n"; # class="patchset"
4257 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4259 # fills project list info (age, description, owner, forks) for each
4260 # project in the list, removing invalid projects from returned list
4261 # NOTE: modifies $projlist, but does not remove entries from it
4262 sub fill_project_list_info
{
4263 my ($projlist, $check_forks) = @_;
4266 my $show_ctags = gitweb_check_feature
('ctags');
4268 foreach my $pr (@$projlist) {
4269 my (@activity) = git_get_last_activity
($pr->{'path'});
4270 unless (@activity) {
4273 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4274 if (!defined $pr->{'descr'}) {
4275 my $descr = git_get_project_description
($pr->{'path'}) || "";
4276 $descr = to_utf8
($descr);
4277 $pr->{'descr_long'} = $descr;
4278 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4280 if (!defined $pr->{'owner'}) {
4281 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4284 my $pname = $pr->{'path'};
4285 if (($pname =~ s/\.git$//) &&
4286 ($pname !~ /\/$/) &&
4287 (-d
"$projectroot/$pname")) {
4288 $pr->{'forks'} = "-d $projectroot/$pname";
4293 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4294 push @projects, $pr;
4300 # print 'sort by' <th> element, generating 'sort by $name' replay link
4301 # if that order is not selected
4303 my ($name, $order, $header) = @_;
4304 $header ||= ucfirst($name);
4306 if ($order eq $name) {
4307 print "<th>$header</th>\n";
4310 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4311 -class => "header"}, $header) .
4316 sub git_project_list_body
{
4317 # actually uses global variable $project
4318 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4320 my $check_forks = gitweb_check_feature
('forks');
4321 my @projects = fill_project_list_info
($projlist, $check_forks);
4323 $order ||= $default_projects_order;
4324 $from = 0 unless defined $from;
4325 $to = $#projects if (!defined $to || $#projects < $to);
4328 project
=> { key
=> 'path', type
=> 'str' },
4329 descr
=> { key
=> 'descr_long', type
=> 'str' },
4330 owner
=> { key
=> 'owner', type
=> 'str' },
4331 age
=> { key
=> 'age', type
=> 'num' }
4333 my $oi = $order_info{$order};
4334 if ($oi->{'type'} eq 'str') {
4335 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4337 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4340 my $show_ctags = gitweb_check_feature
('ctags');
4343 foreach my $p (@projects) {
4344 foreach my $ct (keys %{$p->{'ctags'}}) {
4345 $ctags{$ct} += $p->{'ctags'}->{$ct};
4348 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4349 print git_show_project_tagcloud
($cloud, 64);
4352 print "<table class=\"project_list\">\n";
4353 unless ($no_header) {
4356 print "<th></th>\n";
4358 print_sort_th
('project', $order, 'Project');
4359 print_sort_th
('descr', $order, 'Description');
4360 print_sort_th
('owner', $order, 'Owner');
4361 print_sort_th
('age', $order, 'Last Change');
4362 print "<th></th>\n" . # for links
4366 my $tagfilter = $cgi->param('by_tag');
4367 for (my $i = $from; $i <= $to; $i++) {
4368 my $pr = $projects[$i];
4370 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4371 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4372 and not $pr->{'descr_long'} =~ /$searchtext/;
4373 # Weed out forks or non-matching entries of search
4375 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4376 $forkbase="^$forkbase" if $forkbase;
4377 next if not $searchtext and not $tagfilter and $show_ctags
4378 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4382 print "<tr class=\"dark\">\n";
4384 print "<tr class=\"light\">\n";
4389 if ($pr->{'forks'}) {
4390 print "<!-- $pr->{'forks'} -->\n";
4391 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4395 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4396 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4397 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4398 -class => "list", -title
=> $pr->{'descr_long'}},
4399 esc_html
($pr->{'descr'})) . "</td>\n" .
4400 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4401 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4402 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4403 "<td class=\"link\">" .
4404 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4405 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4406 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4407 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4408 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4412 if (defined $extra) {
4415 print "<td></td>\n";
4417 print "<td colspan=\"5\">$extra</td>\n" .
4423 sub git_shortlog_body
{
4424 # uses global variable $project
4425 my ($commitlist, $from, $to, $refs, $extra) = @_;
4427 $from = 0 unless defined $from;
4428 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4430 print "<table class=\"shortlog\">\n";
4432 for (my $i = $from; $i <= $to; $i++) {
4433 my %co = %{$commitlist->[$i]};
4434 my $commit = $co{'id'};
4435 my $ref = format_ref_marker
($refs, $commit);
4437 print "<tr class=\"dark\">\n";
4439 print "<tr class=\"light\">\n";
4442 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4443 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4444 format_author_html
('td', \
%co, 10) . "<td>";
4445 print format_subject_html
($co{'title'}, $co{'title_short'},
4446 href
(action
=>"commit", hash
=>$commit), $ref);
4448 "<td class=\"link\">" .
4449 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4450 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4451 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4452 my $snapshot_links = format_snapshot_links
($commit);
4453 if (defined $snapshot_links) {
4454 print " | " . $snapshot_links;
4459 if (defined $extra) {
4461 "<td colspan=\"4\">$extra</td>\n" .
4467 sub git_history_body
{
4468 # Warning: assumes constant type (blob or tree) during history
4469 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4471 $from = 0 unless defined $from;
4472 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4474 print "<table class=\"history\">\n";
4476 for (my $i = $from; $i <= $to; $i++) {
4477 my %co = %{$commitlist->[$i]};
4481 my $commit = $co{'id'};
4483 my $ref = format_ref_marker
($refs, $commit);
4486 print "<tr class=\"dark\">\n";
4488 print "<tr class=\"light\">\n";
4491 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4492 # shortlog: format_author_html('td', \%co, 10)
4493 format_author_html
('td', \
%co, 15, 3) . "<td>";
4494 # originally git_history used chop_str($co{'title'}, 50)
4495 print format_subject_html
($co{'title'}, $co{'title_short'},
4496 href
(action
=>"commit", hash
=>$commit), $ref);
4498 "<td class=\"link\">" .
4499 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4500 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4502 if ($ftype eq 'blob') {
4503 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4504 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4505 if (defined $blob_current && defined $blob_parent &&
4506 $blob_current ne $blob_parent) {
4508 $cgi->a({-href
=> href
(action
=>"blobdiff",
4509 hash
=>$blob_current, hash_parent
=>$blob_parent,
4510 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4511 file_name
=>$file_name)},
4518 if (defined $extra) {
4520 "<td colspan=\"4\">$extra</td>\n" .
4527 # uses global variable $project
4528 my ($taglist, $from, $to, $extra) = @_;
4529 $from = 0 unless defined $from;
4530 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4532 print "<table class=\"tags\">\n";
4534 for (my $i = $from; $i <= $to; $i++) {
4535 my $entry = $taglist->[$i];
4537 my $comment = $tag{'subject'};
4539 if (defined $comment) {
4540 $comment_short = chop_str
($comment, 30, 5);
4543 print "<tr class=\"dark\">\n";
4545 print "<tr class=\"light\">\n";
4548 if (defined $tag{'age'}) {
4549 print "<td><i>$tag{'age'}</i></td>\n";
4551 print "<td></td>\n";
4554 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4555 -class => "list name"}, esc_html
($tag{'name'})) .
4558 if (defined $comment) {
4559 print format_subject_html
($comment, $comment_short,
4560 href
(action
=>"tag", hash
=>$tag{'id'}));
4563 "<td class=\"selflink\">";
4564 if ($tag{'type'} eq "tag") {
4565 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4570 "<td class=\"link\">" . " | " .
4571 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4572 if ($tag{'reftype'} eq "commit") {
4573 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4574 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4575 } elsif ($tag{'reftype'} eq "blob") {
4576 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4581 if (defined $extra) {
4583 "<td colspan=\"5\">$extra</td>\n" .
4589 sub git_heads_body
{
4590 # uses global variable $project
4591 my ($headlist, $head, $from, $to, $extra) = @_;
4592 $from = 0 unless defined $from;
4593 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4595 print "<table class=\"heads\">\n";
4597 for (my $i = $from; $i <= $to; $i++) {
4598 my $entry = $headlist->[$i];
4600 my $curr = $ref{'id'} eq $head;
4602 print "<tr class=\"dark\">\n";
4604 print "<tr class=\"light\">\n";
4607 print "<td><i>$ref{'age'}</i></td>\n" .
4608 ($curr ? "<td class=\"current_head\">" : "<td>") .
4609 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4610 -class => "list name"},esc_html
($ref{'name'})) .
4612 "<td class=\"link\">" .
4613 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4614 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4615 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4619 if (defined $extra) {
4621 "<td colspan=\"3\">$extra</td>\n" .
4627 sub git_search_grep_body
{
4628 my ($commitlist, $from, $to, $extra) = @_;
4629 $from = 0 unless defined $from;
4630 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4632 print "<table class=\"commit_search\">\n";
4634 for (my $i = $from; $i <= $to; $i++) {
4635 my %co = %{$commitlist->[$i]};
4639 my $commit = $co{'id'};
4641 print "<tr class=\"dark\">\n";
4643 print "<tr class=\"light\">\n";
4646 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4647 format_author_html
('td', \
%co, 15, 5) .
4649 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4650 -class => "list subject"},
4651 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4652 my $comment = $co{'comment'};
4653 foreach my $line (@$comment) {
4654 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4655 my ($lead, $match, $trail) = ($1, $2, $3);
4656 $match = chop_str
($match, 70, 5, 'center');
4657 my $contextlen = int((80 - length($match))/2);
4658 $contextlen = 30 if ($contextlen > 30);
4659 $lead = chop_str
($lead, $contextlen, 10, 'left');
4660 $trail = chop_str
($trail, $contextlen, 10, 'right');
4662 $lead = esc_html
($lead);
4663 $match = esc_html
($match);
4664 $trail = esc_html
($trail);
4666 print "$lead<span class=\"match\">$match</span>$trail<br />";
4670 "<td class=\"link\">" .
4671 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4673 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4675 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4679 if (defined $extra) {
4681 "<td colspan=\"3\">$extra</td>\n" .
4687 ## ======================================================================
4688 ## ======================================================================
4691 sub git_project_list
{
4692 my $order = $input_params{'order'};
4693 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4694 die_error
(400, "Unknown order parameter");
4697 my @list = git_get_projects_list
();
4699 die_error
(404, "No projects found");
4703 if (-f
$home_text) {
4704 print "<div class=\"index_include\">\n";
4705 insert_file
($home_text);
4708 print $cgi->startform(-method => "get") .
4709 "<p class=\"projsearch\">Search:\n" .
4710 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4712 $cgi->end_form() . "\n";
4713 git_project_list_body
(\
@list, $order);
4718 my $order = $input_params{'order'};
4719 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4720 die_error
(400, "Unknown order parameter");
4723 my @list = git_get_projects_list
($project);
4725 die_error
(404, "No forks found");
4729 git_print_page_nav
('','');
4730 git_print_header_div
('summary', "$project forks");
4731 git_project_list_body
(\
@list, $order);
4735 sub git_project_index
{
4736 my @projects = git_get_projects_list
($project);
4739 -type
=> 'text/plain',
4740 -charset
=> 'utf-8',
4741 -content_disposition
=> 'inline; filename="index.aux"');
4743 foreach my $pr (@projects) {
4744 if (!exists $pr->{'owner'}) {
4745 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4748 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4749 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4750 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4751 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4755 print "$path $owner\n";
4760 my $descr = git_get_project_description
($project) || "none";
4761 my %co = parse_commit
("HEAD");
4762 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4763 my $head = $co{'id'};
4765 my $owner = git_get_project_owner
($project);
4767 my $refs = git_get_references
();
4768 # These get_*_list functions return one more to allow us to see if
4769 # there are more ...
4770 my @taglist = git_get_tags_list
(16);
4771 my @headlist = git_get_heads_list
(16);
4773 my $check_forks = gitweb_check_feature
('forks');
4776 @forklist = git_get_projects_list
($project);
4780 git_print_page_nav
('summary','', $head);
4782 print "<div class=\"title\"> </div>\n";
4783 print "<table class=\"projects_list\">\n" .
4784 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4785 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4786 if (defined $cd{'rfc2822'}) {
4787 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4790 # use per project git URL list in $projectroot/$project/cloneurl
4791 # or make project git URL from git base URL and project name
4792 my $url_tag = "URL";
4793 my @url_list = git_get_project_url_list
($project);
4794 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4795 foreach my $git_url (@url_list) {
4796 next unless $git_url;
4797 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4802 my $show_ctags = gitweb_check_feature
('ctags');
4804 my $ctags = git_get_project_ctags
($project);
4805 my $cloud = git_populate_project_tagcloud
($ctags);
4806 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4807 print "</td>\n<td>" unless %$ctags;
4808 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4809 print "</td>\n<td>" if %$ctags;
4810 print git_show_project_tagcloud
($cloud, 48);
4816 # If XSS prevention is on, we don't include README.html.
4817 # TODO: Allow a readme in some safe format.
4818 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4819 print "<div class=\"title\">readme</div>\n" .
4820 "<div class=\"readme\">\n";
4821 insert_file
("$projectroot/$project/README.html");
4822 print "\n</div>\n"; # class="readme"
4825 # we need to request one more than 16 (0..15) to check if
4827 my @commitlist = $head ? parse_commits
($head, 17) : ();
4829 git_print_header_div
('shortlog');
4830 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4831 $#commitlist <= 15 ? undef :
4832 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4836 git_print_header_div
('tags');
4837 git_tags_body
(\
@taglist, 0, 15,
4838 $#taglist <= 15 ? undef :
4839 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4843 git_print_header_div
('heads');
4844 git_heads_body
(\
@headlist, $head, 0, 15,
4845 $#headlist <= 15 ? undef :
4846 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4850 git_print_header_div
('forks');
4851 git_project_list_body
(\
@forklist, 'age', 0, 15,
4852 $#forklist <= 15 ? undef :
4853 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4861 my $head = git_get_head_hash
($project);
4863 git_print_page_nav
('','', $head,undef,$head);
4864 my %tag = parse_tag
($hash);
4867 die_error
(404, "Unknown tag object");
4870 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4871 print "<div class=\"title_text\">\n" .
4872 "<table class=\"object_header\">\n" .
4874 "<td>object</td>\n" .
4875 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4876 $tag{'object'}) . "</td>\n" .
4877 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4878 $tag{'type'}) . "</td>\n" .
4880 if (defined($tag{'author'})) {
4881 git_print_authorship_rows
(\
%tag, 'author');
4883 print "</table>\n\n" .
4885 print "<div class=\"page_body\">";
4886 my $comment = $tag{'comment'};
4887 foreach my $line (@$comment) {
4889 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4895 sub git_blame_common
{
4896 my $format = shift || 'porcelain';
4897 if ($format eq 'porcelain' && $cgi->param('js')) {
4898 $format = 'incremental';
4899 $action = 'blame_incremental'; # for page title etc
4903 gitweb_check_feature
('blame')
4904 or die_error
(403, "Blame view not allowed");
4907 die_error
(400, "No file name given") unless $file_name;
4908 $hash_base ||= git_get_head_hash
($project);
4909 die_error
(404, "Couldn't find base commit") unless $hash_base;
4910 my %co = parse_commit
($hash_base)
4911 or die_error
(404, "Commit not found");
4913 if (!defined $hash) {
4914 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4915 or die_error
(404, "Error looking up file");
4917 $ftype = git_get_type
($hash);
4918 if ($ftype !~ "blob") {
4919 die_error
(400, "Object is not a blob");
4924 if ($format eq 'incremental') {
4925 # get file contents (as base)
4926 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
4927 or die_error
(500, "Open git-cat-file failed");
4928 } elsif ($format eq 'data') {
4929 # run git-blame --incremental
4930 open $fd, "-|", git_cmd
(), "blame", "--incremental",
4931 $hash_base, "--", $file_name
4932 or die_error
(500, "Open git-blame --incremental failed");
4934 # run git-blame --porcelain
4935 open $fd, "-|", git_cmd
(), "blame", '-p',
4936 $hash_base, '--', $file_name
4937 or die_error
(500, "Open git-blame --porcelain failed");
4940 # incremental blame data returns early
4941 if ($format eq 'data') {
4943 -type
=>"text/plain", -charset
=> "utf-8",
4944 -status
=> "200 OK");
4945 local $| = 1; # output autoflush
4948 or print "ERROR $!\n";
4951 if (defined $t0 && gitweb_check_feature
('timed')) {
4953 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
4954 ' '.$number_of_git_cmds;
4964 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4967 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4970 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
4972 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4973 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4974 git_print_page_path
($file_name, $ftype, $hash_base);
4977 if ($format eq 'incremental') {
4978 print "<noscript>\n<div class=\"error\"><center><b>\n".
4979 "This page requires JavaScript to run.\n Use ".
4980 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
4983 "</b></center></div>\n</noscript>\n";
4985 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
4988 print qq
!<div
class="page_body">\n!;
4989 print qq
!<div id
="progress_info">... / ...</div
>\n!
4990 if ($format eq 'incremental');
4991 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
4992 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
4994 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
4998 my @rev_color = qw(light dark);
4999 my $num_colors = scalar(@rev_color);
5000 my $current_color = 0;
5002 if ($format eq 'incremental') {
5003 my $color_class = $rev_color[$current_color];
5008 while (my $line = <$fd>) {
5012 print qq
!<tr id
="l$linenr" class="$color_class">!.
5013 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5014 qq
!<td
class="linenr">!.
5015 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5016 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5020 } else { # porcelain, i.e. ordinary blame
5021 my %metainfo = (); # saves information about commits
5025 while (my $line = <$fd>) {
5027 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5028 # no <lines in group> for subsequent lines in group of lines
5029 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5030 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5031 if (!exists $metainfo{$full_rev}) {
5032 $metainfo{$full_rev} = { 'nprevious' => 0 };
5034 my $meta = $metainfo{$full_rev};
5036 while ($data = <$fd>) {
5038 last if ($data =~ s/^\t//); # contents of line
5039 if ($data =~ /^(\S+)(?: (.*))?$/) {
5040 $meta->{$1} = $2 unless exists $meta->{$1};
5042 if ($data =~ /^previous /) {
5043 $meta->{'nprevious'}++;
5046 my $short_rev = substr($full_rev, 0, 8);
5047 my $author = $meta->{'author'};
5049 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5050 my $date = $date{'iso-tz'};
5052 $current_color = ($current_color + 1) % $num_colors;
5054 my $tr_class = $rev_color[$current_color];
5055 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5056 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5057 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5058 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5060 print "<td class=\"sha1\"";
5061 print " title=\"". esc_html
($author) . ", $date\"";
5062 print " rowspan=\"$group_size\"" if ($group_size > 1);
5064 print $cgi->a({-href
=> href
(action
=>"commit",
5066 file_name
=>$file_name)},
5067 esc_html
($short_rev));
5068 if ($group_size >= 2) {
5069 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5070 if (@author_initials) {
5072 esc_html
(join('', @author_initials));
5078 # 'previous' <sha1 of parent commit> <filename at commit>
5079 if (exists $meta->{'previous'} &&
5080 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5081 $meta->{'parent'} = $1;
5082 $meta->{'file_parent'} = unquote
($2);
5085 exists($meta->{'parent'}) ?
5086 $meta->{'parent'} : $full_rev;
5087 my $linenr_filename =
5088 exists($meta->{'file_parent'}) ?
5089 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5090 my $blamed = href
(action
=> 'blame',
5091 file_name
=> $linenr_filename,
5092 hash_base
=> $linenr_commit);
5093 print "<td class=\"linenr\">";
5094 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5095 -class => "linenr" },
5098 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5106 "</table>\n"; # class="blame"
5107 print "</div>\n"; # class="blame_body"
5109 or print "Reading blob failed\n";
5118 sub git_blame_incremental
{
5119 git_blame_common
('incremental');
5122 sub git_blame_data
{
5123 git_blame_common
('data');
5127 my $head = git_get_head_hash
($project);
5129 git_print_page_nav
('','', $head,undef,$head);
5130 git_print_header_div
('summary', $project);
5132 my @tagslist = git_get_tags_list
();
5134 git_tags_body
(\
@tagslist);
5140 my $head = git_get_head_hash
($project);
5142 git_print_page_nav
('','', $head,undef,$head);
5143 git_print_header_div
('summary', $project);
5145 my @headslist = git_get_heads_list
();
5147 git_heads_body
(\
@headslist, $head);
5152 sub git_blob_plain
{
5156 if (!defined $hash) {
5157 if (defined $file_name) {
5158 my $base = $hash_base || git_get_head_hash
($project);
5159 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5160 or die_error
(404, "Cannot find file");
5162 die_error
(400, "No file name defined");
5164 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5165 # blobs defined by non-textual hash id's can be cached
5169 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5170 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5172 # content-type (can include charset)
5173 $type = blob_contenttype
($fd, $file_name, $type);
5175 # "save as" filename, even when no $file_name is given
5176 my $save_as = "$hash";
5177 if (defined $file_name) {
5178 $save_as = $file_name;
5179 } elsif ($type =~ m/^text\//) {
5183 # With XSS prevention on, blobs of all types except a few known safe
5184 # ones are served with "Content-Disposition: attachment" to make sure
5185 # they don't run in our security domain. For certain image types,
5186 # blob view writes an <img> tag referring to blob_plain view, and we
5187 # want to be sure not to break that by serving the image as an
5188 # attachment (though Firefox 3 doesn't seem to care).
5189 my $sandbox = $prevent_xss &&
5190 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5194 -expires
=> $expires,
5195 -content_disposition
=>
5196 ($sandbox ? 'attachment' : 'inline')
5197 . '; filename="' . $save_as . '"');
5199 binmode STDOUT
, ':raw';
5201 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5208 if (!defined $hash) {
5209 if (defined $file_name) {
5210 my $base = $hash_base || git_get_head_hash
($project);
5211 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5212 or die_error
(404, "Cannot find file");
5214 die_error
(400, "No file name defined");
5216 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5217 # blobs defined by non-textual hash id's can be cached
5221 my $have_blame = gitweb_check_feature
('blame');
5222 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5223 or die_error
(500, "Couldn't cat $file_name, $hash");
5224 my $mimetype = blob_mimetype
($fd, $file_name);
5225 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5227 return git_blob_plain
($mimetype);
5229 # we can have blame only for text/* mimetype
5230 $have_blame &&= ($mimetype =~ m!^text/!);
5232 git_header_html
(undef, $expires);
5233 my $formats_nav = '';
5234 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5235 if (defined $file_name) {
5238 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5243 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5246 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5249 $cgi->a({-href
=> href
(action
=>"blob",
5250 hash_base
=>"HEAD", file_name
=>$file_name)},
5254 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5257 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5258 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5260 print "<div class=\"page_nav\">\n" .
5261 "<br/><br/></div>\n" .
5262 "<div class=\"title\">$hash</div>\n";
5264 git_print_page_path
($file_name, "blob", $hash_base);
5265 print "<div class=\"page_body\">\n";
5266 if ($mimetype =~ m!^image/!) {
5267 print qq
!<img type
="$mimetype"!;
5269 print qq
! alt
="$file_name" title
="$file_name"!;
5272 href(action=>"blob_plain
", hash=>$hash,
5273 hash_base=>$hash_base, file_name=>$file_name) .
5277 while (my $line = <$fd>) {
5280 $line = untabify
($line);
5281 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5282 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5283 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5287 or print "Reading blob failed.\n";
5293 if (!defined $hash_base) {
5294 $hash_base = "HEAD";
5296 if (!defined $hash) {
5297 if (defined $file_name) {
5298 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5303 die_error
(404, "No such tree") unless defined($hash);
5305 my $show_sizes = gitweb_check_feature
('show-sizes');
5306 my $have_blame = gitweb_check_feature
('blame');
5311 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5312 ($show_sizes ? '-l' : ()), @extra_options, $hash
5313 or die_error
(500, "Open git-ls-tree failed");
5314 @entries = map { chomp; $_ } <$fd>;
5316 or die_error
(404, "Reading tree failed");
5319 my $refs = git_get_references
();
5320 my $ref = format_ref_marker
($refs, $hash_base);
5323 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5325 if (defined $file_name) {
5327 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5329 $cgi->a({-href
=> href
(action
=>"tree",
5330 hash_base
=>"HEAD", file_name
=>$file_name)},
5333 my $snapshot_links = format_snapshot_links
($hash);
5334 if (defined $snapshot_links) {
5335 # FIXME: Should be available when we have no hash base as well.
5336 push @views_nav, $snapshot_links;
5338 git_print_page_nav
('tree','', $hash_base, undef, undef,
5339 join(' | ', @views_nav));
5340 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5343 print "<div class=\"page_nav\">\n";
5344 print "<br/><br/></div>\n";
5345 print "<div class=\"title\">$hash</div>\n";
5347 if (defined $file_name) {
5348 $basedir = $file_name;
5349 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5352 git_print_page_path
($file_name, 'tree', $hash_base);
5354 print "<div class=\"page_body\">\n";
5355 print "<table class=\"tree\">\n";
5357 # '..' (top directory) link if possible
5358 if (defined $hash_base &&
5359 defined $file_name && $file_name =~ m![^/]+$!) {
5361 print "<tr class=\"dark\">\n";
5363 print "<tr class=\"light\">\n";
5367 my $up = $file_name;
5368 $up =~ s!/?[^/]+$!!;
5369 undef $up unless $up;
5370 # based on git_print_tree_entry
5371 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5372 print '<td class="size"> </td>'."\n" if $show_sizes;
5373 print '<td class="list">';
5374 print $cgi->a({-href
=> href
(action
=>"tree",
5375 hash_base
=>$hash_base,
5379 print "<td class=\"link\"></td>\n";
5383 foreach my $line (@entries) {
5384 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5387 print "<tr class=\"dark\">\n";
5389 print "<tr class=\"light\">\n";
5393 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5397 print "</table>\n" .
5403 my ($project, $hash) = @_;
5405 # path/to/project.git -> project
5406 # path/to/project/.git -> project
5407 my $name = to_utf8
($project);
5408 $name =~ s
,([^/])/*\
.git
$,$1,;
5409 $name = basename
($name);
5411 $name =~ s/[[:cntrl:]]/?/g;
5414 if ($hash =~ /^[0-9a-fA-F]+$/) {
5415 # shorten SHA-1 hash
5416 my $full_hash = git_get_full_hash
($project, $hash);
5417 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5418 $ver = git_get_short_hash
($project, $hash);
5420 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5421 # tags don't need shortened SHA-1 hash
5424 # branches and other need shortened SHA-1 hash
5425 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5428 $ver .= '-' . git_get_short_hash
($project, $hash);
5430 # in case of hierarchical branch names
5433 # name = project-version_string
5434 $name = "$name-$ver";
5436 return wantarray ? ($name, $name) : $name;
5440 my $format = $input_params{'snapshot_format'};
5441 if (!@snapshot_fmts) {
5442 die_error
(403, "Snapshots not allowed");
5444 # default to first supported snapshot format
5445 $format ||= $snapshot_fmts[0];
5446 if ($format !~ m/^[a-z0-9]+$/) {
5447 die_error
(400, "Invalid snapshot format parameter");
5448 } elsif (!exists($known_snapshot_formats{$format})) {
5449 die_error
(400, "Unknown snapshot format");
5450 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5451 die_error
(403, "Snapshot format not allowed");
5452 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5453 die_error
(403, "Unsupported snapshot format");
5456 my $type = git_get_type
("$hash^{}");
5458 die_error
(404, 'Object does not exist');
5459 } elsif ($type eq 'blob') {
5460 die_error
(400, 'Object is not a tree-ish');
5463 my ($name, $prefix) = snapshot_name
($project, $hash);
5464 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5465 my $cmd = quote_command
(
5466 git_cmd
(), 'archive',
5467 "--format=$known_snapshot_formats{$format}{'format'}",
5468 "--prefix=$prefix/", $hash);
5469 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5470 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5473 $filename =~ s/(["\\])/\\$1/g;
5475 -type
=> $known_snapshot_formats{$format}{'type'},
5476 -content_disposition
=> 'inline; filename="' . $filename . '"',
5477 -status
=> '200 OK');
5479 open my $fd, "-|", $cmd
5480 or die_error
(500, "Execute git-archive failed");
5481 binmode STDOUT
, ':raw';
5483 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5488 my $head = git_get_head_hash
($project);
5489 if (!defined $hash) {
5492 if (!defined $page) {
5495 my $refs = git_get_references
();
5497 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5499 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5501 my ($patch_max) = gitweb_get_feature
('patches');
5503 if ($patch_max < 0 || @commitlist <= $patch_max) {
5504 $paging_nav .= " ⋅ " .
5505 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5511 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5514 my %co = parse_commit
($hash);
5516 git_print_header_div
('summary', $project);
5517 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5519 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5520 for (my $i = 0; $i <= $to; $i++) {
5521 my %co = %{$commitlist[$i]};
5523 my $commit = $co{'id'};
5524 my $ref = format_ref_marker
($refs, $commit);
5525 my %ad = parse_date
($co{'author_epoch'});
5526 git_print_header_div
('commit',
5527 "<span class=\"age\">$co{'age_string'}</span>" .
5528 esc_html
($co{'title'}) . $ref,
5530 print "<div class=\"title_text\">\n" .
5531 "<div class=\"log_link\">\n" .
5532 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5534 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5536 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5539 git_print_authorship
(\
%co, -tag
=> 'span');
5540 print "<br/>\n</div>\n";
5542 print "<div class=\"log_body\">\n";
5543 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5546 if ($#commitlist >= 100) {
5547 print "<div class=\"page_nav\">\n";
5548 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5549 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5556 $hash ||= $hash_base || "HEAD";
5557 my %co = parse_commit
($hash)
5558 or die_error
(404, "Unknown commit object");
5560 my $parent = $co{'parent'};
5561 my $parents = $co{'parents'}; # listref
5563 # we need to prepare $formats_nav before any parameter munging
5565 if (!defined $parent) {
5567 $formats_nav .= '(initial)';
5568 } elsif (@$parents == 1) {
5569 # single parent commit
5572 $cgi->a({-href
=> href
(action
=>"commit",
5574 esc_html
(substr($parent, 0, 7))) .
5581 $cgi->a({-href
=> href
(action
=>"commit",
5583 esc_html
(substr($_, 0, 7)));
5587 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5588 $formats_nav .= " | " .
5589 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5593 if (!defined $parent) {
5597 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5599 (@$parents <= 1 ? $parent : '-c'),
5601 or die_error
(500, "Open git-diff-tree failed");
5602 @difftree = map { chomp; $_ } <$fd>;
5603 close $fd or die_error
(404, "Reading git-diff-tree failed");
5605 # non-textual hash id's can be cached
5607 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5610 my $refs = git_get_references
();
5611 my $ref = format_ref_marker
($refs, $co{'id'});
5613 git_header_html
(undef, $expires);
5614 git_print_page_nav
('commit', '',
5615 $hash, $co{'tree'}, $hash,
5618 if (defined $co{'parent'}) {
5619 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5621 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5623 print "<div class=\"title_text\">\n" .
5624 "<table class=\"object_header\">\n";
5625 git_print_authorship_rows
(\
%co);
5626 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5629 "<td class=\"sha1\">" .
5630 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5631 class => "list"}, $co{'tree'}) .
5633 "<td class=\"link\">" .
5634 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5636 my $snapshot_links = format_snapshot_links
($hash);
5637 if (defined $snapshot_links) {
5638 print " | " . $snapshot_links;
5643 foreach my $par (@$parents) {
5646 "<td class=\"sha1\">" .
5647 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5648 class => "list"}, $par) .
5650 "<td class=\"link\">" .
5651 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5653 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5660 print "<div class=\"page_body\">\n";
5661 git_print_log
($co{'comment'});
5664 git_difftree_body
(\
@difftree, $hash, @$parents);
5670 # object is defined by:
5671 # - hash or hash_base alone
5672 # - hash_base and file_name
5675 # - hash or hash_base alone
5676 if ($hash || ($hash_base && !defined $file_name)) {
5677 my $object_id = $hash || $hash_base;
5679 open my $fd, "-|", quote_command
(
5680 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5681 or die_error
(404, "Object does not exist");
5685 or die_error
(404, "Object does not exist");
5687 # - hash_base and file_name
5688 } elsif ($hash_base && defined $file_name) {
5689 $file_name =~ s
,/+$,,;
5691 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5692 or die_error
(404, "Base object does not exist");
5694 # here errors should not hapen
5695 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5696 or die_error
(500, "Open git-ls-tree failed");
5700 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5701 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5702 die_error
(404, "File or directory for given base does not exist");
5707 die_error
(400, "Not enough information to find object");
5710 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5711 hash
=>$hash, hash_base
=>$hash_base,
5712 file_name
=>$file_name),
5713 -status
=> '302 Found');
5717 my $format = shift || 'html';
5724 # preparing $fd and %diffinfo for git_patchset_body
5726 if (defined $hash_base && defined $hash_parent_base) {
5727 if (defined $file_name) {
5729 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5730 $hash_parent_base, $hash_base,
5731 "--", (defined $file_parent ? $file_parent : ()), $file_name
5732 or die_error
(500, "Open git-diff-tree failed");
5733 @difftree = map { chomp; $_ } <$fd>;
5735 or die_error
(404, "Reading git-diff-tree failed");
5737 or die_error
(404, "Blob diff not found");
5739 } elsif (defined $hash &&
5740 $hash =~ /[0-9a-fA-F]{40}/) {
5741 # try to find filename from $hash
5743 # read filtered raw output
5744 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5745 $hash_parent_base, $hash_base, "--"
5746 or die_error
(500, "Open git-diff-tree failed");
5748 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5750 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5751 map { chomp; $_ } <$fd>;
5753 or die_error
(404, "Reading git-diff-tree failed");
5755 or die_error
(404, "Blob diff not found");
5758 die_error
(400, "Missing one of the blob diff parameters");
5761 if (@difftree > 1) {
5762 die_error
(400, "Ambiguous blob diff specification");
5765 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5766 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5767 $file_name ||= $diffinfo{'to_file'};
5769 $hash_parent ||= $diffinfo{'from_id'};
5770 $hash ||= $diffinfo{'to_id'};
5772 # non-textual hash id's can be cached
5773 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5774 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5779 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5780 '-p', ($format eq 'html' ? "--full-index" : ()),
5781 $hash_parent_base, $hash_base,
5782 "--", (defined $file_parent ? $file_parent : ()), $file_name
5783 or die_error
(500, "Open git-diff-tree failed");
5786 # old/legacy style URI -- not generated anymore since 1.4.3.
5788 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5792 if ($format eq 'html') {
5794 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5796 git_header_html
(undef, $expires);
5797 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5798 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5799 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5801 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5802 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5804 if (defined $file_name) {
5805 git_print_page_path
($file_name, "blob", $hash_base);
5807 print "<div class=\"page_path\"></div>\n";
5810 } elsif ($format eq 'plain') {
5812 -type
=> 'text/plain',
5813 -charset
=> 'utf-8',
5814 -expires
=> $expires,
5815 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5817 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5820 die_error
(400, "Unknown blobdiff format");
5824 if ($format eq 'html') {
5825 print "<div class=\"page_body\">\n";
5827 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5830 print "</div>\n"; # class="page_body"
5834 while (my $line = <$fd>) {
5835 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5836 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5840 last if $line =~ m!^\+\+\+!;
5848 sub git_blobdiff_plain
{
5849 git_blobdiff
('plain');
5852 sub git_commitdiff
{
5854 my $format = $params{-format
} || 'html';
5856 my ($patch_max) = gitweb_get_feature
('patches');
5857 if ($format eq 'patch') {
5858 die_error
(403, "Patch view not allowed") unless $patch_max;
5861 $hash ||= $hash_base || "HEAD";
5862 my %co = parse_commit
($hash)
5863 or die_error
(404, "Unknown commit object");
5865 # choose format for commitdiff for merge
5866 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5867 $hash_parent = '--cc';
5869 # we need to prepare $formats_nav before almost any parameter munging
5871 if ($format eq 'html') {
5873 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5875 if ($patch_max && @{$co{'parents'}} <= 1) {
5876 $formats_nav .= " | " .
5877 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5881 if (defined $hash_parent &&
5882 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5883 # commitdiff with two commits given
5884 my $hash_parent_short = $hash_parent;
5885 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5886 $hash_parent_short = substr($hash_parent, 0, 7);
5890 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5891 if ($co{'parents'}[$i] eq $hash_parent) {
5892 $formats_nav .= ' parent ' . ($i+1);
5896 $formats_nav .= ': ' .
5897 $cgi->a({-href
=> href
(action
=>"commitdiff",
5898 hash
=>$hash_parent)},
5899 esc_html
($hash_parent_short)) .
5901 } elsif (!$co{'parent'}) {
5903 $formats_nav .= ' (initial)';
5904 } elsif (scalar @{$co{'parents'}} == 1) {
5905 # single parent commit
5908 $cgi->a({-href
=> href
(action
=>"commitdiff",
5909 hash
=>$co{'parent'})},
5910 esc_html
(substr($co{'parent'}, 0, 7))) .
5914 if ($hash_parent eq '--cc') {
5915 $formats_nav .= ' | ' .
5916 $cgi->a({-href
=> href
(action
=>"commitdiff",
5917 hash
=>$hash, hash_parent
=>'-c')},
5919 } else { # $hash_parent eq '-c'
5920 $formats_nav .= ' | ' .
5921 $cgi->a({-href
=> href
(action
=>"commitdiff",
5922 hash
=>$hash, hash_parent
=>'--cc')},
5928 $cgi->a({-href
=> href
(action
=>"commitdiff",
5930 esc_html
(substr($_, 0, 7)));
5931 } @{$co{'parents'}} ) .
5936 my $hash_parent_param = $hash_parent;
5937 if (!defined $hash_parent_param) {
5938 # --cc for multiple parents, --root for parentless
5939 $hash_parent_param =
5940 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5946 if ($format eq 'html') {
5947 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5948 "--no-commit-id", "--patch-with-raw", "--full-index",
5949 $hash_parent_param, $hash, "--"
5950 or die_error
(500, "Open git-diff-tree failed");
5952 while (my $line = <$fd>) {
5954 # empty line ends raw part of diff-tree output
5956 push @difftree, scalar parse_difftree_raw_line
($line);
5959 } elsif ($format eq 'plain') {
5960 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5961 '-p', $hash_parent_param, $hash, "--"
5962 or die_error
(500, "Open git-diff-tree failed");
5963 } elsif ($format eq 'patch') {
5964 # For commit ranges, we limit the output to the number of
5965 # patches specified in the 'patches' feature.
5966 # For single commits, we limit the output to a single patch,
5967 # diverging from the git-format-patch default.
5968 my @commit_spec = ();
5970 if ($patch_max > 0) {
5971 push @commit_spec, "-$patch_max";
5973 push @commit_spec, '-n', "$hash_parent..$hash";
5975 if ($params{-single
}) {
5976 push @commit_spec, '-1';
5978 if ($patch_max > 0) {
5979 push @commit_spec, "-$patch_max";
5981 push @commit_spec, "-n";
5983 push @commit_spec, '--root', $hash;
5985 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5986 '--stdout', @commit_spec
5987 or die_error
(500, "Open git-format-patch failed");
5989 die_error
(400, "Unknown commitdiff format");
5992 # non-textual hash id's can be cached
5994 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5998 # write commit message
5999 if ($format eq 'html') {
6000 my $refs = git_get_references
();
6001 my $ref = format_ref_marker
($refs, $co{'id'});
6003 git_header_html
(undef, $expires);
6004 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6005 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6006 print "<div class=\"title_text\">\n" .
6007 "<table class=\"object_header\">\n";
6008 git_print_authorship_rows
(\
%co);
6011 print "<div class=\"page_body\">\n";
6012 if (@{$co{'comment'}} > 1) {
6013 print "<div class=\"log\">\n";
6014 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6015 print "</div>\n"; # class="log"
6018 } elsif ($format eq 'plain') {
6019 my $refs = git_get_references
("tags");
6020 my $tagname = git_get_rev_name_tags
($hash);
6021 my $filename = basename
($project) . "-$hash.patch";
6024 -type
=> 'text/plain',
6025 -charset
=> 'utf-8',
6026 -expires
=> $expires,
6027 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6028 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6029 print "From: " . to_utf8
($co{'author'}) . "\n";
6030 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6031 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6033 print "X-Git-Tag: $tagname\n" if $tagname;
6034 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6036 foreach my $line (@{$co{'comment'}}) {
6037 print to_utf8
($line) . "\n";
6040 } elsif ($format eq 'patch') {
6041 my $filename = basename
($project) . "-$hash.patch";
6044 -type
=> 'text/plain',
6045 -charset
=> 'utf-8',
6046 -expires
=> $expires,
6047 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6051 if ($format eq 'html') {
6052 my $use_parents = !defined $hash_parent ||
6053 $hash_parent eq '-c' || $hash_parent eq '--cc';
6054 git_difftree_body
(\
@difftree, $hash,
6055 $use_parents ? @{$co{'parents'}} : $hash_parent);
6058 git_patchset_body
($fd, \
@difftree, $hash,
6059 $use_parents ? @{$co{'parents'}} : $hash_parent);
6061 print "</div>\n"; # class="page_body"
6064 } elsif ($format eq 'plain') {
6068 or print "Reading git-diff-tree failed\n";
6069 } elsif ($format eq 'patch') {
6073 or print "Reading git-format-patch failed\n";
6077 sub git_commitdiff_plain
{
6078 git_commitdiff
(-format
=> 'plain');
6081 # format-patch-style patches
6083 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6087 git_commitdiff
(-format
=> 'patch');
6091 if (!defined $hash_base) {
6092 $hash_base = git_get_head_hash
($project);
6094 if (!defined $page) {
6098 my %co = parse_commit
($hash_base)
6099 or die_error
(404, "Unknown commit object");
6101 my $refs = git_get_references
();
6102 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
6104 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
6105 $file_name, "--full-history")
6106 or die_error
(404, "No such file or directory on given branch");
6108 if (!defined $hash && defined $file_name) {
6109 # some commits could have deleted file in question,
6110 # and not have it in tree, but one of them has to have it
6111 for (my $i = 0; $i <= @commitlist; $i++) {
6112 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
6113 last if defined $hash;
6116 if (defined $hash) {
6117 $ftype = git_get_type
($hash);
6119 if (!defined $ftype) {
6120 die_error
(500, "Unknown type of object");
6123 my $paging_nav = '';
6126 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
6127 file_name
=>$file_name)},
6129 $paging_nav .= " ⋅ " .
6130 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6131 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6133 $paging_nav .= "first";
6134 $paging_nav .= " ⋅ prev";
6137 if ($#commitlist >= 100) {
6139 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6140 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6141 $paging_nav .= " ⋅ $next_link";
6143 $paging_nav .= " ⋅ next";
6147 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
6148 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6149 git_print_page_path
($file_name, $ftype, $hash_base);
6151 git_history_body
(\
@commitlist, 0, 99,
6152 $refs, $hash_base, $ftype, $next_link);
6158 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6159 if (!defined $searchtext) {
6160 die_error
(400, "Text field is empty");
6162 if (!defined $hash) {
6163 $hash = git_get_head_hash
($project);
6165 my %co = parse_commit
($hash);
6167 die_error
(404, "Unknown commit object");
6169 if (!defined $page) {
6173 $searchtype ||= 'commit';
6174 if ($searchtype eq 'pickaxe') {
6175 # pickaxe may take all resources of your box and run for several minutes
6176 # with every query - so decide by yourself how public you make this feature
6177 gitweb_check_feature
('pickaxe')
6178 or die_error
(403, "Pickaxe is disabled");
6180 if ($searchtype eq 'grep') {
6181 gitweb_check_feature
('grep')[0]
6182 or die_error
(403, "Grep is disabled");
6187 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6189 if ($searchtype eq 'commit') {
6190 $greptype = "--grep=";
6191 } elsif ($searchtype eq 'author') {
6192 $greptype = "--author=";
6193 } elsif ($searchtype eq 'committer') {
6194 $greptype = "--committer=";
6196 $greptype .= $searchtext;
6197 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6198 $greptype, '--regexp-ignore-case',
6199 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6201 my $paging_nav = '';
6204 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6205 searchtext
=>$searchtext,
6206 searchtype
=>$searchtype)},
6208 $paging_nav .= " ⋅ " .
6209 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6210 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6212 $paging_nav .= "first";
6213 $paging_nav .= " ⋅ prev";
6216 if ($#commitlist >= 100) {
6218 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6219 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6220 $paging_nav .= " ⋅ $next_link";
6222 $paging_nav .= " ⋅ next";
6225 if ($#commitlist >= 100) {
6228 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6229 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6230 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6233 if ($searchtype eq 'pickaxe') {
6234 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6235 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6237 print "<table class=\"pickaxe search\">\n";
6240 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6241 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6242 ($search_use_regexp ? '--pickaxe-regex' : ());
6245 while (my $line = <$fd>) {
6249 my %set = parse_difftree_raw_line
($line);
6250 if (defined $set{'commit'}) {
6251 # finish previous commit
6254 "<td class=\"link\">" .
6255 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6257 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6263 print "<tr class=\"dark\">\n";
6265 print "<tr class=\"light\">\n";
6268 %co = parse_commit
($set{'commit'});
6269 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6270 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6271 "<td><i>$author</i></td>\n" .
6273 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6274 -class => "list subject"},
6275 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6276 } elsif (defined $set{'to_id'}) {
6277 next if ($set{'to_id'} =~ m/^0{40}$/);
6279 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6280 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6282 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6288 # finish last commit (warning: repetition!)
6291 "<td class=\"link\">" .
6292 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6294 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6302 if ($searchtype eq 'grep') {
6303 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6304 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6306 print "<table class=\"grep_search\">\n";
6310 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6311 $search_use_regexp ? ('-E', '-i') : '-F',
6312 $searchtext, $co{'tree'};
6314 while (my $line = <$fd>) {
6316 my ($file, $lno, $ltext, $binary);
6317 last if ($matches++ > 1000);
6318 if ($line =~ /^Binary file (.+) matches$/) {
6322 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6324 if ($file ne $lastfile) {
6325 $lastfile and print "</td></tr>\n";
6327 print "<tr class=\"dark\">\n";
6329 print "<tr class=\"light\">\n";
6331 print "<td class=\"list\">".
6332 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6333 file_name
=>"$file"),
6334 -class => "list"}, esc_path
($file));
6335 print "</td><td>\n";
6339 print "<div class=\"binary\">Binary file</div>\n";
6341 $ltext = untabify
($ltext);
6342 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6343 $ltext = esc_html
($1, -nbsp
=>1);
6344 $ltext .= '<span class="match">';
6345 $ltext .= esc_html
($2, -nbsp
=>1);
6346 $ltext .= '</span>';
6347 $ltext .= esc_html
($3, -nbsp
=>1);
6349 $ltext = esc_html
($ltext, -nbsp
=>1);
6351 print "<div class=\"pre\">" .
6352 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6353 file_name
=>"$file").'#l'.$lno,
6354 -class => "linenr"}, sprintf('%4i', $lno))
6355 . ' ' . $ltext . "</div>\n";
6359 print "</td></tr>\n";
6360 if ($matches > 1000) {
6361 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6364 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6373 sub git_search_help
{
6375 git_print_page_nav
('','', $hash,$hash,$hash);
6377 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6378 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6379 the pattern entered is recognized as the POSIX extended
6380 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6383 <dt><b>commit</b></dt>
6384 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6386 my $have_grep = gitweb_check_feature
('grep');
6389 <dt><b>grep</b></dt>
6390 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6391 a different one) are searched for the given pattern. On large trees, this search can take
6392 a while and put some strain on the server, so please use it with some consideration. Note that
6393 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6394 case-sensitive.</dd>
6398 <dt><b>author</b></dt>
6399 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6400 <dt><b>committer</b></dt>
6401 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6403 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6404 if ($have_pickaxe) {
6406 <dt><b>pickaxe</b></dt>
6407 <dd>All commits that caused the string to appear or disappear from any file (changes that
6408 added, removed or "modified" the string) will be listed. This search can take a while and
6409 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6410 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6418 my $head = git_get_head_hash
($project);
6419 if (!defined $hash) {
6422 if (!defined $page) {
6425 my $refs = git_get_references
();
6427 my $commit_hash = $hash;
6428 if (defined $hash_parent) {
6429 $commit_hash = "$hash_parent..$hash";
6431 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6433 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6435 if ($#commitlist >= 100) {
6437 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6438 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6440 my $patch_max = gitweb_check_feature
('patches');
6442 if ($patch_max < 0 || @commitlist <= $patch_max) {
6443 $paging_nav .= " ⋅ " .
6444 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6450 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6451 git_print_header_div
('summary', $project);
6453 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6458 ## ......................................................................
6459 ## feeds (RSS, Atom; OPML)
6462 my $format = shift || 'atom';
6463 my $have_blame = gitweb_check_feature
('blame');
6465 # Atom: http://www.atomenabled.org/developers/syndication/
6466 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6467 if ($format ne 'rss' && $format ne 'atom') {
6468 die_error
(400, "Unknown web feed format");
6471 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6472 my $head = $hash || 'HEAD';
6473 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6477 my $content_type = "application/$format+xml";
6478 if (defined $cgi->http('HTTP_ACCEPT') &&
6479 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6480 # browser (feed reader) prefers text/xml
6481 $content_type = 'text/xml';
6483 if (defined($commitlist[0])) {
6484 %latest_commit = %{$commitlist[0]};
6485 my $latest_epoch = $latest_commit{'committer_epoch'};
6486 %latest_date = parse_date
($latest_epoch);
6487 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6488 if (defined $if_modified) {
6490 if (eval { require HTTP
::Date
; 1; }) {
6491 $since = HTTP
::Date
::str2time
($if_modified);
6492 } elsif (eval { require Time
::ParseDate
; 1; }) {
6493 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6495 if (defined $since && $latest_epoch <= $since) {
6497 -type
=> $content_type,
6498 -charset
=> 'utf-8',
6499 -last_modified
=> $latest_date{'rfc2822'},
6500 -status
=> '304 Not Modified');
6505 -type
=> $content_type,
6506 -charset
=> 'utf-8',
6507 -last_modified
=> $latest_date{'rfc2822'});
6510 -type
=> $content_type,
6511 -charset
=> 'utf-8');
6514 # Optimization: skip generating the body if client asks only
6515 # for Last-Modified date.
6516 return if ($cgi->request_method() eq 'HEAD');
6519 my $title = "$site_name - $project/$action";
6520 my $feed_type = 'log';
6521 if (defined $hash) {
6522 $title .= " - '$hash'";
6523 $feed_type = 'branch log';
6524 if (defined $file_name) {
6525 $title .= " :: $file_name";
6526 $feed_type = 'history';
6528 } elsif (defined $file_name) {
6529 $title .= " - $file_name";
6530 $feed_type = 'history';
6532 $title .= " $feed_type";
6533 my $descr = git_get_project_description
($project);
6534 if (defined $descr) {
6535 $descr = esc_html
($descr);
6537 $descr = "$project " .
6538 ($format eq 'rss' ? 'RSS' : 'Atom') .
6541 my $owner = git_get_project_owner
($project);
6542 $owner = esc_html
($owner);
6546 if (defined $file_name) {
6547 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6548 } elsif (defined $hash) {
6549 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6551 $alt_url = href
(-full
=>1, action
=>"summary");
6553 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6554 if ($format eq 'rss') {
6556 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6559 print "<title>$title</title>\n" .
6560 "<link>$alt_url</link>\n" .
6561 "<description>$descr</description>\n" .
6562 "<language>en</language>\n" .
6563 # project owner is responsible for 'editorial' content
6564 "<managingEditor>$owner</managingEditor>\n";
6565 if (defined $logo || defined $favicon) {
6566 # prefer the logo to the favicon, since RSS
6567 # doesn't allow both
6568 my $img = esc_url
($logo || $favicon);
6570 "<url>$img</url>\n" .
6571 "<title>$title</title>\n" .
6572 "<link>$alt_url</link>\n" .
6576 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6577 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6579 print "<generator>gitweb v.$version/$git_version</generator>\n";
6580 } elsif ($format eq 'atom') {
6582 <feed xmlns="http://www.w3.org/2005/Atom">
6584 print "<title>$title</title>\n" .
6585 "<subtitle>$descr</subtitle>\n" .
6586 '<link rel="alternate" type="text/html" href="' .
6587 $alt_url . '" />' . "\n" .
6588 '<link rel="self" type="' . $content_type . '" href="' .
6589 $cgi->self_url() . '" />' . "\n" .
6590 "<id>" . href
(-full
=>1) . "</id>\n" .
6591 # use project owner for feed author
6592 "<author><name>$owner</name></author>\n";
6593 if (defined $favicon) {
6594 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6596 if (defined $logo_url) {
6597 # not twice as wide as tall: 72 x 27 pixels
6598 print "<logo>" . esc_url
($logo) . "</logo>\n";
6600 if (! %latest_date) {
6601 # dummy date to keep the feed valid until commits trickle in:
6602 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6604 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6606 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6610 for (my $i = 0; $i <= $#commitlist; $i++) {
6611 my %co = %{$commitlist[$i]};
6612 my $commit = $co{'id'};
6613 # we read 150, we always show 30 and the ones more recent than 48 hours
6614 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6617 my %cd = parse_date
($co{'author_epoch'});
6619 # get list of changed files
6620 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6621 $co{'parent'} || "--root",
6622 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6624 my @difftree = map { chomp; $_ } <$fd>;
6628 # print element (entry, item)
6629 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6630 if ($format eq 'rss') {
6632 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6633 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6634 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6635 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6636 "<link>$co_url</link>\n" .
6637 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6638 "<content:encoded>" .
6640 } elsif ($format eq 'atom') {
6642 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6643 "<updated>$cd{'iso-8601'}</updated>\n" .
6645 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6646 if ($co{'author_email'}) {
6647 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6649 print "</author>\n" .
6650 # use committer for contributor
6652 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6653 if ($co{'committer_email'}) {
6654 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6656 print "</contributor>\n" .
6657 "<published>$cd{'iso-8601'}</published>\n" .
6658 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6659 "<id>$co_url</id>\n" .
6660 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6661 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6663 my $comment = $co{'comment'};
6665 foreach my $line (@$comment) {
6666 $line = esc_html
($line);
6669 print "</pre><ul>\n";
6670 foreach my $difftree_line (@difftree) {
6671 my %difftree = parse_difftree_raw_line
($difftree_line);
6672 next if !$difftree{'from_id'};
6674 my $file = $difftree{'file'} || $difftree{'to_file'};
6678 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6679 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6680 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6681 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6682 -title
=> "diff"}, 'D');
6684 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6685 file_name
=>$file, hash_base
=>$commit),
6686 -title
=> "blame"}, 'B');
6688 # if this is not a feed of a file history
6689 if (!defined $file_name || $file_name ne $file) {
6690 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6691 file_name
=>$file, hash
=>$commit),
6692 -title
=> "history"}, 'H');
6694 $file = esc_path
($file);
6698 if ($format eq 'rss') {
6699 print "</ul>]]>\n" .
6700 "</content:encoded>\n" .
6702 } elsif ($format eq 'atom') {
6703 print "</ul>\n</div>\n" .
6710 if ($format eq 'rss') {
6711 print "</channel>\n</rss>\n";
6712 } elsif ($format eq 'atom') {
6726 my @list = git_get_projects_list
();
6729 -type
=> 'text/xml',
6730 -charset
=> 'utf-8',
6731 -content_disposition
=> 'inline; filename="opml.xml"');
6734 <?xml version="1.0" encoding="utf-8"?>
6735 <opml version="1.0">
6737 <title>$site_name OPML Export</title>
6740 <outline text="git RSS feeds">
6743 foreach my $pr (@list) {
6745 my $head = git_get_head_hash
($proj{'path'});
6746 if (!defined $head) {
6749 $git_dir = "$projectroot/$proj{'path'}";
6750 my %co = parse_commit
($head);
6755 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6756 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6757 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6758 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";