3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # if we're called with PATH_INFO, we have to strip that
31 # from the URL to find our real URL
32 # we make $path_info global because it's also used later on
33 our $path_info = $ENV{"PATH_INFO"};
35 $my_url =~ s
,\Q
$path_info\E
$,,;
36 $my_uri =~ s
,\Q
$path_info\E
$,,;
39 # core git executable to use
40 # this can just be "git" if your webserver has a sensible PATH
41 our $GIT = "++GIT_BINDIR++/git";
43 # absolute fs-path which will be prepended to the project path
44 #our $projectroot = "/pub/scm";
45 our $projectroot = "++GITWEB_PROJECTROOT++";
47 # fs traversing limit for getting project list
48 # the number is relative to the projectroot
49 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
51 # target of the home link on top of all pages
52 our $home_link = $my_uri || "/";
54 # string of the home link on top of all pages
55 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
57 # name of your site or organization to appear in page titles
58 # replace this with something more descriptive for clearer bookmarks
59 our $site_name = "++GITWEB_SITENAME++"
60 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
62 # filename of html text to include at top of each page
63 our $site_header = "++GITWEB_SITE_HEADER++";
64 # html text to include at home page
65 our $home_text = "++GITWEB_HOMETEXT++";
66 # filename of html text to include at bottom of each page
67 our $site_footer = "++GITWEB_SITE_FOOTER++";
70 our @stylesheets = ("++GITWEB_CSS++");
71 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
72 our $stylesheet = undef;
73 # URI of GIT logo (72x27 size)
74 our $logo = "++GITWEB_LOGO++";
75 # URI of GIT favicon, assumed to be image/png type
76 our $favicon = "++GITWEB_FAVICON++";
78 # URI and label (title) of GIT logo link
79 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
80 #our $logo_label = "git documentation";
81 our $logo_url = "http://git.or.cz/";
82 our $logo_label = "git homepage";
84 # source of projects list
85 our $projects_list = "++GITWEB_LIST++";
87 # the width (in characters) of the projects list "Description" column
88 our $projects_list_description_width = 25;
90 # default order of projects list
91 # valid values are none, project, descr, owner, and age
92 our $default_projects_order = "project";
94 # show repository only if this file exists
95 # (only effective if this variable evaluates to true)
96 our $export_ok = "++GITWEB_EXPORT_OK++";
98 # show repository only if this subroutine returns true
99 # when given the path to the project, for example:
100 # sub { return -e "$_[0]/git-daemon-export-ok"; }
101 our $export_auth_hook = undef;
103 # only allow viewing of repositories also shown on the overview page
104 our $strict_export = "++GITWEB_STRICT_EXPORT++";
106 # list of git base URLs used for URL to where fetch project from,
107 # i.e. full URL is "$git_base_url/$project"
108 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
110 # default blob_plain mimetype and default charset for text/plain blob
111 our $default_blob_plain_mimetype = 'text/plain';
112 our $default_text_plain_charset = undef;
114 # file to use for guessing MIME types before trying /etc/mime.types
115 # (relative to the current git repository)
116 our $mimetypes_file = undef;
118 # assume this charset if line contains non-UTF-8 characters;
119 # it should be valid encoding (see Encoding::Supported(3pm) for list),
120 # for which encoding all byte sequences are valid, for example
121 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
122 # could be even 'utf-8' for the old behavior)
123 our $fallback_encoding = 'latin1';
125 # rename detection options for git-diff and git-diff-tree
126 # - default is '-M', with the cost proportional to
127 # (number of removed files) * (number of new files).
128 # - more costly is '-C' (which implies '-M'), with the cost proportional to
129 # (number of changed files + number of removed files) * (number of new files)
130 # - even more costly is '-C', '--find-copies-harder' with cost
131 # (number of files in the original tree) * (number of new files)
132 # - one might want to include '-B' option, e.g. '-B', '-M'
133 our @diff_opts = ('-M'); # taken from git_commit
135 # information about snapshot formats that gitweb is capable of serving
136 our %known_snapshot_formats = (
138 # 'display' => display name,
139 # 'type' => mime type,
140 # 'suffix' => filename suffix,
141 # 'format' => --format for git-archive,
142 # 'compressor' => [compressor command and arguments]
143 # (array reference, optional)}
146 'display' => 'tar.gz',
147 'type' => 'application/x-gzip',
148 'suffix' => '.tar.gz',
150 'compressor' => ['gzip']},
153 'display' => 'tar.bz2',
154 'type' => 'application/x-bzip2',
155 'suffix' => '.tar.bz2',
157 'compressor' => ['bzip2']},
161 'type' => 'application/x-zip',
166 # Aliases so we understand old gitweb.snapshot values in repository
168 our %known_snapshot_format_aliases = (
172 # backward compatibility: legacy gitweb config support
173 'x-gzip' => undef, 'gz' => undef,
174 'x-bzip2' => undef, 'bz2' => undef,
175 'x-zip' => undef, '' => undef,
178 # You define site-wide feature defaults here; override them with
179 # $GITWEB_CONFIG as necessary.
182 # 'sub' => feature-sub (subroutine),
183 # 'override' => allow-override (boolean),
184 # 'default' => [ default options...] (array reference)}
186 # if feature is overridable (it means that allow-override has true value),
187 # then feature-sub will be called with default options as parameters;
188 # return value of feature-sub indicates if to enable specified feature
190 # if there is no 'sub' key (no feature-sub), then feature cannot be
193 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
195 # Enable the 'blame' blob view, showing the last commit that modified
196 # each line in the file. This can be very CPU-intensive.
198 # To enable system wide have in $GITWEB_CONFIG
199 # $feature{'blame'}{'default'} = [1];
200 # To have project specific config enable override in $GITWEB_CONFIG
201 # $feature{'blame'}{'override'} = 1;
202 # and in project config gitweb.blame = 0|1;
204 'sub' => \
&feature_blame
,
208 # Enable the 'snapshot' link, providing a compressed archive of any
209 # tree. This can potentially generate high traffic if you have large
212 # Value is a list of formats defined in %known_snapshot_formats that
214 # To disable system wide have in $GITWEB_CONFIG
215 # $feature{'snapshot'}{'default'} = [];
216 # To have project specific config enable override in $GITWEB_CONFIG
217 # $feature{'snapshot'}{'override'} = 1;
218 # and in project config, a comma-separated list of formats or "none"
219 # to disable. Example: gitweb.snapshot = tbz2,zip;
221 'sub' => \
&feature_snapshot
,
223 'default' => ['tgz']},
225 # Enable text search, which will list the commits which match author,
226 # committer or commit text to a given string. Enabled by default.
227 # Project specific override is not supported.
232 # Enable grep search, which will list the files in currently selected
233 # tree containing the given string. Enabled by default. This can be
234 # potentially CPU-intensive, of course.
236 # To enable system wide have in $GITWEB_CONFIG
237 # $feature{'grep'}{'default'} = [1];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'grep'}{'override'} = 1;
240 # and in project config gitweb.grep = 0|1;
245 # Enable the pickaxe search, which will list the commits that modified
246 # a given string in a file. This can be practical and quite faster
247 # alternative to 'blame', but still potentially CPU-intensive.
249 # To enable system wide have in $GITWEB_CONFIG
250 # $feature{'pickaxe'}{'default'} = [1];
251 # To have project specific config enable override in $GITWEB_CONFIG
252 # $feature{'pickaxe'}{'override'} = 1;
253 # and in project config gitweb.pickaxe = 0|1;
255 'sub' => \
&feature_pickaxe
,
259 # Make gitweb use an alternative format of the URLs which can be
260 # more readable and natural-looking: project name is embedded
261 # directly in the path and the query string contains other
262 # auxiliary information. All gitweb installations recognize
263 # URL in either format; this configures in which formats gitweb
266 # To enable system wide have in $GITWEB_CONFIG
267 # $feature{'pathinfo'}{'default'} = [1];
268 # Project specific override is not supported.
270 # Note that you will need to change the default location of CSS,
271 # favicon, logo and possibly other files to an absolute URL. Also,
272 # if gitweb.cgi serves as your indexfile, you will need to force
273 # $my_uri to contain the script name in your $GITWEB_CONFIG.
278 # Make gitweb consider projects in project root subdirectories
279 # to be forks of existing projects. Given project $projname.git,
280 # projects matching $projname/*.git will not be shown in the main
281 # projects list, instead a '+' mark will be added to $projname
282 # there and a 'forks' view will be enabled for the project, listing
283 # all the forks. If project list is taken from a file, forks have
284 # to be listed after the main project.
286 # To enable system wide have in $GITWEB_CONFIG
287 # $feature{'forks'}{'default'} = [1];
288 # Project specific override is not supported.
293 # Insert custom links to the action bar of all project pages.
294 # This enables you mainly to link to third-party scripts integrating
295 # into gitweb; e.g. git-browser for graphical history representation
296 # or custom web-based repository administration interface.
298 # The 'default' value consists of a list of triplets in the form
299 # (label, link, position) where position is the label after which
300 # to insert the link and link is a format string where %n expands
301 # to the project name, %f to the project path within the filesystem,
302 # %h to the current hash (h gitweb parameter) and %b to the current
303 # hash base (hb gitweb parameter); %% expands to %.
305 # To enable system wide have in $GITWEB_CONFIG e.g.
306 # $feature{'actions'}{'default'} = [('graphiclog',
307 # '/git-browser/by-commit.html?r=%n', 'summary')];
308 # Project specific override is not supported.
313 # Allow gitweb scan project content tags described in ctags/
314 # of project repository, and display the popular Web 2.0-ish
315 # "tag cloud" near the project list. Note that this is something
316 # COMPLETELY different from the normal Git tags.
318 # gitweb by itself can show existing tags, but it does not handle
319 # tagging itself; you need an external application for that.
320 # For an example script, check Girocco's cgi/tagproj.cgi.
321 # You may want to install the HTML::TagCloud Perl module to get
322 # a pretty tag cloud instead of just a list of tags.
324 # To enable system wide have in $GITWEB_CONFIG
325 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
326 # Project specific override is not supported.
332 sub gitweb_get_feature
{
334 return unless exists $feature{$name};
335 my ($sub, $override, @defaults) = (
336 $feature{$name}{'sub'},
337 $feature{$name}{'override'},
338 @
{$feature{$name}{'default'}});
339 if (!$override) { return @defaults; }
341 warn "feature $name is not overrideable";
344 return $sub->(@defaults);
347 # A wrapper to check if a given feature is enabled.
348 # With this, you can say
350 # my $bool_feat = gitweb_check_feature('bool_feat');
351 # gitweb_check_feature('bool_feat') or somecode;
355 # my ($bool_feat) = gitweb_get_feature('bool_feat');
356 # (gitweb_get_feature('bool_feat'))[0] or somecode;
358 sub gitweb_check_feature
{
359 return (gitweb_get_feature
(@_))[0];
364 my ($val) = git_get_project_config
('blame', '--bool');
366 if ($val eq 'true') {
368 } elsif ($val eq 'false') {
375 sub feature_snapshot
{
378 my ($val) = git_get_project_config
('snapshot');
381 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
388 my ($val) = git_get_project_config
('grep', '--bool');
390 if ($val eq 'true') {
392 } elsif ($val eq 'false') {
399 sub feature_pickaxe
{
400 my ($val) = git_get_project_config
('pickaxe', '--bool');
402 if ($val eq 'true') {
404 } elsif ($val eq 'false') {
411 # checking HEAD file with -e is fragile if the repository was
412 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
414 sub check_head_link
{
416 my $headfile = "$dir/HEAD";
417 return ((-e
$headfile) ||
418 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
421 sub check_export_ok
{
423 return (check_head_link
($dir) &&
424 (!$export_ok || -e
"$dir/$export_ok") &&
425 (!$export_auth_hook || $export_auth_hook->($dir)));
428 # process alternate names for backward compatibility
429 # filter out unsupported (unknown) snapshot formats
430 sub filter_snapshot_fmts
{
434 exists $known_snapshot_format_aliases{$_} ?
435 $known_snapshot_format_aliases{$_} : $_} @fmts;
436 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
440 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
441 if (-e
$GITWEB_CONFIG) {
444 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
445 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
448 # version of the core git binary
449 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
451 $projects_list ||= $projectroot;
453 # ======================================================================
454 # input validation and dispatch
456 # input parameters can be collected from a variety of sources (presently, CGI
457 # and PATH_INFO), so we define an %input_params hash that collects them all
458 # together during validation: this allows subsequent uses (e.g. href()) to be
459 # agnostic of the parameter origin
461 our %input_params = ();
463 # input parameters are stored with the long parameter name as key. This will
464 # also be used in the href subroutine to convert parameters to their CGI
465 # equivalent, and since the href() usage is the most frequent one, we store
466 # the name -> CGI key mapping here, instead of the reverse.
468 # XXX: Warning: If you touch this, check the search form for updating,
471 our @cgi_param_mapping = (
479 hash_parent_base
=> "hpb",
484 snapshot_format
=> "sf",
485 extra_options
=> "opt",
486 search_use_regexp
=> "sr",
488 our %cgi_param_mapping = @cgi_param_mapping;
490 # we will also need to know the possible actions, for validation
492 "blame" => \
&git_blame
,
493 "blobdiff" => \
&git_blobdiff
,
494 "blobdiff_plain" => \
&git_blobdiff_plain
,
495 "blob" => \
&git_blob
,
496 "blob_plain" => \
&git_blob_plain
,
497 "commitdiff" => \
&git_commitdiff
,
498 "commitdiff_plain" => \
&git_commitdiff_plain
,
499 "commit" => \
&git_commit
,
500 "forks" => \
&git_forks
,
501 "heads" => \
&git_heads
,
502 "history" => \
&git_history
,
505 "atom" => \
&git_atom
,
506 "search" => \
&git_search
,
507 "search_help" => \
&git_search_help
,
508 "shortlog" => \
&git_shortlog
,
509 "summary" => \
&git_summary
,
511 "tags" => \
&git_tags
,
512 "tree" => \
&git_tree
,
513 "snapshot" => \
&git_snapshot
,
514 "object" => \
&git_object
,
515 # those below don't need $project
516 "opml" => \
&git_opml
,
517 "project_list" => \
&git_project_list
,
518 "project_index" => \
&git_project_index
,
521 # finally, we have the hash of allowed extra_options for the commands that
523 our %allowed_options = (
524 "--no-merges" => [ qw(rss atom log shortlog history) ],
527 # fill %input_params with the CGI parameters. All values except for 'opt'
528 # should be single values, but opt can be an array. We should probably
529 # build an array of parameters that can be multi-valued, but since for the time
530 # being it's only this one, we just single it out
531 while (my ($name, $symbol) = each %cgi_param_mapping) {
532 if ($symbol eq 'opt') {
533 $input_params{$name} = [ $cgi->param($symbol) ];
535 $input_params{$name} = $cgi->param($symbol);
539 # now read PATH_INFO and update the parameter list for missing parameters
540 sub evaluate_path_info
{
541 return if defined $input_params{'project'};
542 return if !$path_info;
543 $path_info =~ s
,^/+,,;
544 return if !$path_info;
546 # find which part of PATH_INFO is project
547 my $project = $path_info;
549 while ($project && !check_head_link
("$projectroot/$project")) {
550 $project =~ s
,/*[^/]*$,,;
552 return unless $project;
553 $input_params{'project'} = $project;
555 # do not change any parameters if an action is given using the query string
556 return if $input_params{'action'};
557 $path_info =~ s
,^\Q
$project\E
/*,,;
559 # next, check if we have an action
560 my $action = $path_info;
562 if (exists $actions{$action}) {
563 $path_info =~ s
,^$action/*,,;
564 $input_params{'action'} = $action;
567 # list of actions that want hash_base instead of hash, but can have no
568 # pathname (f) parameter
575 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
576 my ($parentrefname, $parentpathname, $refname, $pathname) =
577 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
579 # first, analyze the 'current' part
580 if (defined $pathname) {
581 # we got "branch:filename" or "branch:dir/"
582 # we could use git_get_type(branch:pathname), but:
583 # - it needs $git_dir
584 # - it does a git() call
585 # - the convention of terminating directories with a slash
586 # makes it superfluous
587 # - embedding the action in the PATH_INFO would make it even
589 $pathname =~ s
,^/+,,;
590 if (!$pathname || substr($pathname, -1) eq "/") {
591 $input_params{'action'} ||= "tree";
594 # the default action depends on whether we had parent info
596 if ($parentrefname) {
597 $input_params{'action'} ||= "blobdiff_plain";
599 $input_params{'action'} ||= "blob_plain";
602 $input_params{'hash_base'} ||= $refname;
603 $input_params{'file_name'} ||= $pathname;
604 } elsif (defined $refname) {
605 # we got "branch". In this case we have to choose if we have to
606 # set hash or hash_base.
608 # Most of the actions without a pathname only want hash to be
609 # set, except for the ones specified in @wants_base that want
610 # hash_base instead. It should also be noted that hand-crafted
611 # links having 'history' as an action and no pathname or hash
612 # set will fail, but that happens regardless of PATH_INFO.
613 $input_params{'action'} ||= "shortlog";
614 if (grep { $_ eq $input_params{'action'} } @wants_base) {
615 $input_params{'hash_base'} ||= $refname;
617 $input_params{'hash'} ||= $refname;
621 # next, handle the 'parent' part, if present
622 if (defined $parentrefname) {
623 # a missing pathspec defaults to the 'current' filename, allowing e.g.
624 # someproject/blobdiff/oldrev..newrev:/filename
625 if ($parentpathname) {
626 $parentpathname =~ s
,^/+,,;
627 $parentpathname =~ s
,/$,,;
628 $input_params{'file_parent'} ||= $parentpathname;
630 $input_params{'file_parent'} ||= $input_params{'file_name'};
632 # we assume that hash_parent_base is wanted if a path was specified,
633 # or if the action wants hash_base instead of hash
634 if (defined $input_params{'file_parent'} ||
635 grep { $_ eq $input_params{'action'} } @wants_base) {
636 $input_params{'hash_parent_base'} ||= $parentrefname;
638 $input_params{'hash_parent'} ||= $parentrefname;
642 # for the snapshot action, we allow URLs in the form
643 # $project/snapshot/$hash.ext
644 # where .ext determines the snapshot and gets removed from the
645 # passed $refname to provide the $hash.
647 # To be able to tell that $refname includes the format extension, we
648 # require the following two conditions to be satisfied:
649 # - the hash input parameter MUST have been set from the $refname part
650 # of the URL (i.e. they must be equal)
651 # - the snapshot format MUST NOT have been defined already (e.g. from
653 # It's also useless to try any matching unless $refname has a dot,
654 # so we check for that too
655 if (defined $input_params{'action'} &&
656 $input_params{'action'} eq 'snapshot' &&
657 defined $refname && index($refname, '.') != -1 &&
658 $refname eq $input_params{'hash'} &&
659 !defined $input_params{'snapshot_format'}) {
660 # We loop over the known snapshot formats, checking for
661 # extensions. Allowed extensions are both the defined suffix
662 # (which includes the initial dot already) and the snapshot
663 # format key itself, with a prepended dot
664 while (my ($fmt, %opt) = each %known_snapshot_formats) {
667 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
668 next unless $sfx = $1;
669 # a valid suffix was found, so set the snapshot format
670 # and reset the hash parameter
671 $input_params{'snapshot_format'} = $fmt;
672 $input_params{'hash'} = $hash;
673 # we also set the format suffix to the one requested
674 # in the URL: this way a request for e.g. .tgz returns
675 # a .tgz instead of a .tar.gz
676 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
681 evaluate_path_info
();
683 our $action = $input_params{'action'};
684 if (defined $action) {
685 if (!validate_action
($action)) {
686 die_error
(400, "Invalid action parameter");
690 # parameters which are pathnames
691 our $project = $input_params{'project'};
692 if (defined $project) {
693 if (!validate_project
($project)) {
695 die_error
(404, "No such project");
699 our $file_name = $input_params{'file_name'};
700 if (defined $file_name) {
701 if (!validate_pathname
($file_name)) {
702 die_error
(400, "Invalid file parameter");
706 our $file_parent = $input_params{'file_parent'};
707 if (defined $file_parent) {
708 if (!validate_pathname
($file_parent)) {
709 die_error
(400, "Invalid file parent parameter");
713 # parameters which are refnames
714 our $hash = $input_params{'hash'};
716 if (!validate_refname
($hash)) {
717 die_error
(400, "Invalid hash parameter");
721 our $hash_parent = $input_params{'hash_parent'};
722 if (defined $hash_parent) {
723 if (!validate_refname
($hash_parent)) {
724 die_error
(400, "Invalid hash parent parameter");
728 our $hash_base = $input_params{'hash_base'};
729 if (defined $hash_base) {
730 if (!validate_refname
($hash_base)) {
731 die_error
(400, "Invalid hash base parameter");
735 our @extra_options = @
{$input_params{'extra_options'}};
736 # @extra_options is always defined, since it can only be (currently) set from
737 # CGI, and $cgi->param() returns the empty array in array context if the param
739 foreach my $opt (@extra_options) {
740 if (not exists $allowed_options{$opt}) {
741 die_error
(400, "Invalid option parameter");
743 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
744 die_error
(400, "Invalid option parameter for this action");
748 our $hash_parent_base = $input_params{'hash_parent_base'};
749 if (defined $hash_parent_base) {
750 if (!validate_refname
($hash_parent_base)) {
751 die_error
(400, "Invalid hash parent base parameter");
756 our $page = $input_params{'page'};
758 if ($page =~ m/[^0-9]/) {
759 die_error
(400, "Invalid page parameter");
763 our $searchtype = $input_params{'searchtype'};
764 if (defined $searchtype) {
765 if ($searchtype =~ m/[^a-z]/) {
766 die_error
(400, "Invalid searchtype parameter");
770 our $search_use_regexp = $input_params{'search_use_regexp'};
772 our $searchtext = $input_params{'searchtext'};
774 if (defined $searchtext) {
775 if (length($searchtext) < 2) {
776 die_error
(403, "At least two characters are required for search parameter");
778 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
781 # path to the current git repository
783 $git_dir = "$projectroot/$project" if $project;
785 # list of supported snapshot formats
786 our @snapshot_fmts = gitweb_get_feature
('snapshot');
787 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
790 if (!defined $action) {
792 $action = git_get_type
($hash);
793 } elsif (defined $hash_base && defined $file_name) {
794 $action = git_get_type
("$hash_base:$file_name");
795 } elsif (defined $project) {
798 $action = 'project_list';
801 if (!defined($actions{$action})) {
802 die_error
(400, "Unknown action");
804 if ($action !~ m/^(opml|project_list|project_index)$/ &&
806 die_error
(400, "Project needed");
808 $actions{$action}->();
811 ## ======================================================================
816 # default is to use -absolute url() i.e. $my_uri
817 my $href = $params{-full
} ?
$my_url : $my_uri;
819 $params{'project'} = $project unless exists $params{'project'};
821 if ($params{-replay
}) {
822 while (my ($name, $symbol) = each %cgi_param_mapping) {
823 if (!exists $params{$name}) {
824 $params{$name} = $input_params{$name};
829 my $use_pathinfo = gitweb_check_feature
('pathinfo');
831 # try to put as many parameters as possible in PATH_INFO:
834 # - hash_parent or hash_parent_base:/file_parent
835 # - hash or hash_base:/filename
836 # - the snapshot_format as an appropriate suffix
838 # When the script is the root DirectoryIndex for the domain,
839 # $href here would be something like http://gitweb.example.com/
840 # Thus, we strip any trailing / from $href, to spare us double
841 # slashes in the final URL
844 # Then add the project name, if present
845 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
846 delete $params{'project'};
848 # since we destructively absorb parameters, we keep this
849 # boolean that remembers if we're handling a snapshot
850 my $is_snapshot = $params{'action'} eq 'snapshot';
852 # Summary just uses the project path URL, any other action is
854 if (defined $params{'action'}) {
855 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
856 delete $params{'action'};
859 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
860 # stripping nonexistent or useless pieces
861 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
862 || $params{'hash_parent'} || $params{'hash'});
863 if (defined $params{'hash_base'}) {
864 if (defined $params{'hash_parent_base'}) {
865 $href .= esc_url
($params{'hash_parent_base'});
866 # skip the file_parent if it's the same as the file_name
867 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
868 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
869 $href .= ":/".esc_url
($params{'file_parent'});
870 delete $params{'file_parent'};
873 delete $params{'hash_parent'};
874 delete $params{'hash_parent_base'};
875 } elsif (defined $params{'hash_parent'}) {
876 $href .= esc_url
($params{'hash_parent'}). "..";
877 delete $params{'hash_parent'};
880 $href .= esc_url
($params{'hash_base'});
881 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
882 $href .= ":/".esc_url
($params{'file_name'});
883 delete $params{'file_name'};
885 delete $params{'hash'};
886 delete $params{'hash_base'};
887 } elsif (defined $params{'hash'}) {
888 $href .= esc_url
($params{'hash'});
889 delete $params{'hash'};
892 # If the action was a snapshot, we can absorb the
893 # snapshot_format parameter too
895 my $fmt = $params{'snapshot_format'};
896 # snapshot_format should always be defined when href()
897 # is called, but just in case some code forgets, we
898 # fall back to the default
899 $fmt ||= $snapshot_fmts[0];
900 $href .= $known_snapshot_formats{$fmt}{'suffix'};
901 delete $params{'snapshot_format'};
905 # now encode the parameters explicitly
907 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
908 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
909 if (defined $params{$name}) {
910 if (ref($params{$name}) eq "ARRAY") {
911 foreach my $par (@
{$params{$name}}) {
912 push @result, $symbol . "=" . esc_param
($par);
915 push @result, $symbol . "=" . esc_param
($params{$name});
919 $href .= "?" . join(';', @result) if scalar @result;
925 ## ======================================================================
926 ## validation, quoting/unquoting and escaping
928 sub validate_action
{
929 my $input = shift || return undef;
930 return undef unless exists $actions{$input};
934 sub validate_project
{
935 my $input = shift || return undef;
936 if (!validate_pathname
($input) ||
937 !(-d
"$projectroot/$input") ||
938 !check_export_ok
("$projectroot/$input") ||
939 ($strict_export && !project_in_list
($input))) {
946 sub validate_pathname
{
947 my $input = shift || return undef;
949 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
950 # at the beginning, at the end, and between slashes.
951 # also this catches doubled slashes
952 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
956 if ($input =~ m!\0!) {
962 sub validate_refname
{
963 my $input = shift || return undef;
965 # textual hashes are O.K.
966 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
969 # it must be correct pathname
970 $input = validate_pathname
($input)
972 # restrictions on ref name according to git-check-ref-format
973 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
979 # decode sequences of octets in utf8 into Perl's internal form,
980 # which is utf-8 with utf8 flag set if needed. gitweb writes out
981 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
984 if (utf8
::valid
($str)) {
988 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
992 # quote unsafe chars, but keep the slash, even when it's not
993 # correct, but quoted slashes look too horrible in bookmarks
996 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1002 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1005 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1011 # replace invalid utf8 character with SUBSTITUTION sequence
1012 sub esc_html
($;%) {
1016 $str = to_utf8
($str);
1017 $str = $cgi->escapeHTML($str);
1018 if ($opts{'-nbsp'}) {
1019 $str =~ s/ / /g;
1021 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1025 # quote control characters and escape filename to HTML
1030 $str = to_utf8
($str);
1031 $str = $cgi->escapeHTML($str);
1032 if ($opts{'-nbsp'}) {
1033 $str =~ s/ / /g;
1035 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1039 # Make control characters "printable", using character escape codes (CEC)
1043 my %es = ( # character escape codes, aka escape sequences
1044 "\t" => '\t', # tab (HT)
1045 "\n" => '\n', # line feed (LF)
1046 "\r" => '\r', # carrige return (CR)
1047 "\f" => '\f', # form feed (FF)
1048 "\b" => '\b', # backspace (BS)
1049 "\a" => '\a', # alarm (bell) (BEL)
1050 "\e" => '\e', # escape (ESC)
1051 "\013" => '\v', # vertical tab (VT)
1052 "\000" => '\0', # nul character (NUL)
1054 my $chr = ( (exists $es{$cntrl})
1056 : sprintf('\%2x', ord($cntrl)) );
1057 if ($opts{-nohtml
}) {
1060 return "<span class=\"cntrl\">$chr</span>";
1064 # Alternatively use unicode control pictures codepoints,
1065 # Unicode "printable representation" (PR)
1070 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1071 if ($opts{-nohtml
}) {
1074 return "<span class=\"cntrl\">$chr</span>";
1078 # git may return quoted and escaped filenames
1084 my %es = ( # character escape codes, aka escape sequences
1085 't' => "\t", # tab (HT, TAB)
1086 'n' => "\n", # newline (NL)
1087 'r' => "\r", # return (CR)
1088 'f' => "\f", # form feed (FF)
1089 'b' => "\b", # backspace (BS)
1090 'a' => "\a", # alarm (bell) (BEL)
1091 'e' => "\e", # escape (ESC)
1092 'v' => "\013", # vertical tab (VT)
1095 if ($seq =~ m/^[0-7]{1,3}$/) {
1096 # octal char sequence
1097 return chr(oct($seq));
1098 } elsif (exists $es{$seq}) {
1099 # C escape sequence, aka character escape code
1102 # quoted ordinary character
1106 if ($str =~ m/^"(.*)"$/) {
1109 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1114 # escape tabs (convert tabs to spaces)
1118 while ((my $pos = index($line, "\t")) != -1) {
1119 if (my $count = (8 - ($pos % 8))) {
1120 my $spaces = ' ' x
$count;
1121 $line =~ s/\t/$spaces/;
1128 sub project_in_list
{
1129 my $project = shift;
1130 my @list = git_get_projects_list
();
1131 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1134 ## ----------------------------------------------------------------------
1135 ## HTML aware string manipulation
1137 # Try to chop given string on a word boundary between position
1138 # $len and $len+$add_len. If there is no word boundary there,
1139 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1140 # (marking chopped part) would be longer than given string.
1144 my $add_len = shift || 10;
1145 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1147 # Make sure perl knows it is utf8 encoded so we don't
1148 # cut in the middle of a utf8 multibyte char.
1149 $str = to_utf8
($str);
1151 # allow only $len chars, but don't cut a word if it would fit in $add_len
1152 # if it doesn't fit, cut it if it's still longer than the dots we would add
1153 # remove chopped character entities entirely
1155 # when chopping in the middle, distribute $len into left and right part
1156 # return early if chopping wouldn't make string shorter
1157 if ($where eq 'center') {
1158 return $str if ($len + 5 >= length($str)); # filler is length 5
1161 return $str if ($len + 4 >= length($str)); # filler is length 4
1164 # regexps: ending and beginning with word part up to $add_len
1165 my $endre = qr/.{$len}\w{0,$add_len}/;
1166 my $begre = qr/\w{0,$add_len}.{$len}/;
1168 if ($where eq 'left') {
1169 $str =~ m/^(.*?)($begre)$/;
1170 my ($lead, $body) = ($1, $2);
1171 if (length($lead) > 4) {
1172 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1175 return "$lead$body";
1177 } elsif ($where eq 'center') {
1178 $str =~ m/^($endre)(.*)$/;
1179 my ($left, $str) = ($1, $2);
1180 $str =~ m/^(.*?)($begre)$/;
1181 my ($mid, $right) = ($1, $2);
1182 if (length($mid) > 5) {
1183 $left =~ s/&[^;]*$//;
1184 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1187 return "$left$mid$right";
1190 $str =~ m/^($endre)(.*)$/;
1193 if (length($tail) > 4) {
1194 $body =~ s/&[^;]*$//;
1197 return "$body$tail";
1201 # takes the same arguments as chop_str, but also wraps a <span> around the
1202 # result with a title attribute if it does get chopped. Additionally, the
1203 # string is HTML-escaped.
1204 sub chop_and_escape_str
{
1207 my $chopped = chop_str
(@_);
1208 if ($chopped eq $str) {
1209 return esc_html
($chopped);
1211 $str =~ s/([[:cntrl:]])/?/g;
1212 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1216 ## ----------------------------------------------------------------------
1217 ## functions returning short strings
1219 # CSS class for given age value (in seconds)
1223 if (!defined $age) {
1225 } elsif ($age < 60*60*2) {
1227 } elsif ($age < 60*60*24*2) {
1234 # convert age in seconds to "nn units ago" string
1239 if ($age > 60*60*24*365*2) {
1240 $age_str = (int $age/60/60/24/365);
1241 $age_str .= " years ago";
1242 } elsif ($age > 60*60*24*(365/12)*2) {
1243 $age_str = int $age/60/60/24/(365/12);
1244 $age_str .= " months ago";
1245 } elsif ($age > 60*60*24*7*2) {
1246 $age_str = int $age/60/60/24/7;
1247 $age_str .= " weeks ago";
1248 } elsif ($age > 60*60*24*2) {
1249 $age_str = int $age/60/60/24;
1250 $age_str .= " days ago";
1251 } elsif ($age > 60*60*2) {
1252 $age_str = int $age/60/60;
1253 $age_str .= " hours ago";
1254 } elsif ($age > 60*2) {
1255 $age_str = int $age/60;
1256 $age_str .= " min ago";
1257 } elsif ($age > 2) {
1258 $age_str = int $age;
1259 $age_str .= " sec ago";
1261 $age_str .= " right now";
1267 S_IFINVALID
=> 0030000,
1268 S_IFGITLINK
=> 0160000,
1271 # submodule/subproject, a commit object reference
1272 sub S_ISGITLINK
($) {
1275 return (($mode & S_IFMT
) == S_IFGITLINK
)
1278 # convert file mode in octal to symbolic file mode string
1280 my $mode = oct shift;
1282 if (S_ISGITLINK
($mode)) {
1283 return 'm---------';
1284 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1285 return 'drwxr-xr-x';
1286 } elsif (S_ISLNK
($mode)) {
1287 return 'lrwxrwxrwx';
1288 } elsif (S_ISREG
($mode)) {
1289 # git cares only about the executable bit
1290 if ($mode & S_IXUSR
) {
1291 return '-rwxr-xr-x';
1293 return '-rw-r--r--';
1296 return '----------';
1300 # convert file mode in octal to file type string
1304 if ($mode !~ m/^[0-7]+$/) {
1310 if (S_ISGITLINK
($mode)) {
1312 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1314 } elsif (S_ISLNK
($mode)) {
1316 } elsif (S_ISREG
($mode)) {
1323 # convert file mode in octal to file type description string
1324 sub file_type_long
{
1327 if ($mode !~ m/^[0-7]+$/) {
1333 if (S_ISGITLINK
($mode)) {
1335 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1337 } elsif (S_ISLNK
($mode)) {
1339 } elsif (S_ISREG
($mode)) {
1340 if ($mode & S_IXUSR
) {
1341 return "executable";
1351 ## ----------------------------------------------------------------------
1352 ## functions returning short HTML fragments, or transforming HTML fragments
1353 ## which don't belong to other sections
1355 # format line of commit message.
1356 sub format_log_line_html
{
1359 $line = esc_html
($line, -nbsp
=>1);
1360 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1363 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1364 -class => "text"}, $hash_text);
1365 $line =~ s/$hash_text/$link/;
1370 # format marker of refs pointing to given object
1372 # the destination action is chosen based on object type and current context:
1373 # - for annotated tags, we choose the tag view unless it's the current view
1374 # already, in which case we go to shortlog view
1375 # - for other refs, we keep the current view if we're in history, shortlog or
1376 # log view, and select shortlog otherwise
1377 sub format_ref_marker
{
1378 my ($refs, $id) = @_;
1381 if (defined $refs->{$id}) {
1382 foreach my $ref (@
{$refs->{$id}}) {
1383 # this code exploits the fact that non-lightweight tags are the
1384 # only indirect objects, and that they are the only objects for which
1385 # we want to use tag instead of shortlog as action
1386 my ($type, $name) = qw();
1387 my $indirect = ($ref =~ s/\^\{\}$//);
1388 # e.g. tags/v2.6.11 or heads/next
1389 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1398 $class .= " indirect" if $indirect;
1400 my $dest_action = "shortlog";
1403 $dest_action = "tag" unless $action eq "tag";
1404 } elsif ($action =~ /^(history|(short)?log)$/) {
1405 $dest_action = $action;
1409 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1412 my $link = $cgi->a({
1414 action
=>$dest_action,
1418 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1424 return ' <span class="refs">'. $markers . '</span>';
1430 # format, perhaps shortened and with markers, title line
1431 sub format_subject_html
{
1432 my ($long, $short, $href, $extra) = @_;
1433 $extra = '' unless defined($extra);
1435 if (length($short) < length($long)) {
1436 return $cgi->a({-href
=> $href, -class => "list subject",
1437 -title
=> to_utf8
($long)},
1438 esc_html
($short) . $extra);
1440 return $cgi->a({-href
=> $href, -class => "list subject"},
1441 esc_html
($long) . $extra);
1445 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1446 sub format_git_diff_header_line
{
1448 my $diffinfo = shift;
1449 my ($from, $to) = @_;
1451 if ($diffinfo->{'nparents'}) {
1453 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1454 if ($to->{'href'}) {
1455 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1456 esc_path
($to->{'file'}));
1457 } else { # file was deleted (no href)
1458 $line .= esc_path
($to->{'file'});
1462 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1463 if ($from->{'href'}) {
1464 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1465 'a/' . esc_path
($from->{'file'}));
1466 } else { # file was added (no href)
1467 $line .= 'a/' . esc_path
($from->{'file'});
1470 if ($to->{'href'}) {
1471 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1472 'b/' . esc_path
($to->{'file'}));
1473 } else { # file was deleted
1474 $line .= 'b/' . esc_path
($to->{'file'});
1478 return "<div class=\"diff header\">$line</div>\n";
1481 # format extended diff header line, before patch itself
1482 sub format_extended_diff_header_line
{
1484 my $diffinfo = shift;
1485 my ($from, $to) = @_;
1488 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1489 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1490 esc_path
($from->{'file'}));
1492 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1493 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1494 esc_path
($to->{'file'}));
1496 # match single <mode>
1497 if ($line =~ m/\s(\d{6})$/) {
1498 $line .= '<span class="info"> (' .
1499 file_type_long
($1) .
1503 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1504 # can match only for combined diff
1506 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1507 if ($from->{'href'}[$i]) {
1508 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1510 substr($diffinfo->{'from_id'}[$i],0,7));
1515 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1518 if ($to->{'href'}) {
1519 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1520 substr($diffinfo->{'to_id'},0,7));
1525 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1526 # can match only for ordinary diff
1527 my ($from_link, $to_link);
1528 if ($from->{'href'}) {
1529 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1530 substr($diffinfo->{'from_id'},0,7));
1532 $from_link = '0' x
7;
1534 if ($to->{'href'}) {
1535 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1536 substr($diffinfo->{'to_id'},0,7));
1540 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1541 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1544 return $line . "<br/>\n";
1547 # format from-file/to-file diff header
1548 sub format_diff_from_to_header
{
1549 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1554 #assert($line =~ m/^---/) if DEBUG;
1555 # no extra formatting for "^--- /dev/null"
1556 if (! $diffinfo->{'nparents'}) {
1557 # ordinary (single parent) diff
1558 if ($line =~ m!^--- "?a/!) {
1559 if ($from->{'href'}) {
1561 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1562 esc_path
($from->{'file'}));
1565 esc_path
($from->{'file'});
1568 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1571 # combined diff (merge commit)
1572 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1573 if ($from->{'href'}[$i]) {
1575 $cgi->a({-href
=>href
(action
=>"blobdiff",
1576 hash_parent
=>$diffinfo->{'from_id'}[$i],
1577 hash_parent_base
=>$parents[$i],
1578 file_parent
=>$from->{'file'}[$i],
1579 hash
=>$diffinfo->{'to_id'},
1581 file_name
=>$to->{'file'}),
1583 -title
=>"diff" . ($i+1)},
1586 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1587 esc_path
($from->{'file'}[$i]));
1589 $line = '--- /dev/null';
1591 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1596 #assert($line =~ m/^\+\+\+/) if DEBUG;
1597 # no extra formatting for "^+++ /dev/null"
1598 if ($line =~ m!^\+\+\+ "?b/!) {
1599 if ($to->{'href'}) {
1601 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1602 esc_path
($to->{'file'}));
1605 esc_path
($to->{'file'});
1608 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1613 # create note for patch simplified by combined diff
1614 sub format_diff_cc_simplified
{
1615 my ($diffinfo, @parents) = @_;
1618 $result .= "<div class=\"diff header\">" .
1620 if (!is_deleted
($diffinfo)) {
1621 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1623 hash
=>$diffinfo->{'to_id'},
1624 file_name
=>$diffinfo->{'to_file'}),
1626 esc_path
($diffinfo->{'to_file'}));
1628 $result .= esc_path
($diffinfo->{'to_file'});
1630 $result .= "</div>\n" . # class="diff header"
1631 "<div class=\"diff nodifferences\">" .
1633 "</div>\n"; # class="diff nodifferences"
1638 # format patch (diff) line (not to be used for diff headers)
1639 sub format_diff_line
{
1641 my ($from, $to) = @_;
1642 my $diff_class = "";
1646 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1648 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1649 if ($line =~ m/^\@{3}/) {
1650 $diff_class = " chunk_header";
1651 } elsif ($line =~ m/^\\/) {
1652 $diff_class = " incomplete";
1653 } elsif ($prefix =~ tr/+/+/) {
1654 $diff_class = " add";
1655 } elsif ($prefix =~ tr/-/-/) {
1656 $diff_class = " rem";
1659 # assume ordinary diff
1660 my $char = substr($line, 0, 1);
1662 $diff_class = " add";
1663 } elsif ($char eq '-') {
1664 $diff_class = " rem";
1665 } elsif ($char eq '@') {
1666 $diff_class = " chunk_header";
1667 } elsif ($char eq "\\") {
1668 $diff_class = " incomplete";
1671 $line = untabify
($line);
1672 if ($from && $to && $line =~ m/^\@{2} /) {
1673 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1674 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1676 $from_lines = 0 unless defined $from_lines;
1677 $to_lines = 0 unless defined $to_lines;
1679 if ($from->{'href'}) {
1680 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1681 -class=>"list"}, $from_text);
1683 if ($to->{'href'}) {
1684 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1685 -class=>"list"}, $to_text);
1687 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1688 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1689 return "<div class=\"diff$diff_class\">$line</div>\n";
1690 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1691 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1692 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1694 @from_text = split(' ', $ranges);
1695 for (my $i = 0; $i < @from_text; ++$i) {
1696 ($from_start[$i], $from_nlines[$i]) =
1697 (split(',', substr($from_text[$i], 1)), 0);
1700 $to_text = pop @from_text;
1701 $to_start = pop @from_start;
1702 $to_nlines = pop @from_nlines;
1704 $line = "<span class=\"chunk_info\">$prefix ";
1705 for (my $i = 0; $i < @from_text; ++$i) {
1706 if ($from->{'href'}[$i]) {
1707 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1708 -class=>"list"}, $from_text[$i]);
1710 $line .= $from_text[$i];
1714 if ($to->{'href'}) {
1715 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1716 -class=>"list"}, $to_text);
1720 $line .= " $prefix</span>" .
1721 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1722 return "<div class=\"diff$diff_class\">$line</div>\n";
1724 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1727 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1728 # linked. Pass the hash of the tree/commit to snapshot.
1729 sub format_snapshot_links
{
1731 my $num_fmts = @snapshot_fmts;
1732 if ($num_fmts > 1) {
1733 # A parenthesized list of links bearing format names.
1734 # e.g. "snapshot (_tar.gz_ _zip_)"
1735 return "snapshot (" . join(' ', map
1742 }, $known_snapshot_formats{$_}{'display'})
1743 , @snapshot_fmts) . ")";
1744 } elsif ($num_fmts == 1) {
1745 # A single "snapshot" link whose tooltip bears the format name.
1747 my ($fmt) = @snapshot_fmts;
1753 snapshot_format
=>$fmt
1755 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1757 } else { # $num_fmts == 0
1762 ## ......................................................................
1763 ## functions returning values to be passed, perhaps after some
1764 ## transformation, to other functions; e.g. returning arguments to href()
1766 # returns hash to be passed to href to generate gitweb URL
1767 # in -title key it returns description of link
1769 my $format = shift || 'Atom';
1770 my %res = (action
=> lc($format));
1772 # feed links are possible only for project views
1773 return unless (defined $project);
1774 # some views should link to OPML, or to generic project feed,
1775 # or don't have specific feed yet (so they should use generic)
1776 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1779 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1780 # from tag links; this also makes possible to detect branch links
1781 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1782 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1785 # find log type for feed description (title)
1787 if (defined $file_name) {
1788 $type = "history of $file_name";
1789 $type .= "/" if ($action eq 'tree');
1790 $type .= " on '$branch'" if (defined $branch);
1792 $type = "log of $branch" if (defined $branch);
1795 $res{-title
} = $type;
1796 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1797 $res{'file_name'} = $file_name;
1802 ## ----------------------------------------------------------------------
1803 ## git utility subroutines, invoking git commands
1805 # returns path to the core git executable and the --git-dir parameter as list
1807 return $GIT, '--git-dir='.$git_dir;
1810 # quote the given arguments for passing them to the shell
1811 # quote_command("command", "arg 1", "arg with ' and ! characters")
1812 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1813 # Try to avoid using this function wherever possible.
1816 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1819 # get HEAD ref of given project as hash
1820 sub git_get_head_hash
{
1821 my $project = shift;
1822 my $o_git_dir = $git_dir;
1824 $git_dir = "$projectroot/$project";
1825 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1828 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1832 if (defined $o_git_dir) {
1833 $git_dir = $o_git_dir;
1838 # get type of given object
1842 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1844 close $fd or return;
1849 # repository configuration
1850 our $config_file = '';
1853 # store multiple values for single key as anonymous array reference
1854 # single values stored directly in the hash, not as [ <value> ]
1855 sub hash_set_multi
{
1856 my ($hash, $key, $value) = @_;
1858 if (!exists $hash->{$key}) {
1859 $hash->{$key} = $value;
1860 } elsif (!ref $hash->{$key}) {
1861 $hash->{$key} = [ $hash->{$key}, $value ];
1863 push @
{$hash->{$key}}, $value;
1867 # return hash of git project configuration
1868 # optionally limited to some section, e.g. 'gitweb'
1869 sub git_parse_project_config
{
1870 my $section_regexp = shift;
1875 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1878 while (my $keyval = <$fh>) {
1880 my ($key, $value) = split(/\n/, $keyval, 2);
1882 hash_set_multi
(\
%config, $key, $value)
1883 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1890 # convert config value to boolean, 'true' or 'false'
1891 # no value, number > 0, 'true' and 'yes' values are true
1892 # rest of values are treated as false (never as error)
1893 sub config_to_bool
{
1896 # strip leading and trailing whitespace
1900 return (!defined $val || # section.key
1901 ($val =~ /^\d+$/ && $val) || # section.key = 1
1902 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1905 # convert config value to simple decimal number
1906 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1907 # to be multiplied by 1024, 1048576, or 1073741824
1911 # strip leading and trailing whitespace
1915 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1917 # unknown unit is treated as 1
1918 return $num * ($unit eq 'g' ?
1073741824 :
1919 $unit eq 'm' ?
1048576 :
1920 $unit eq 'k' ?
1024 : 1);
1925 # convert config value to array reference, if needed
1926 sub config_to_multi
{
1929 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1932 sub git_get_project_config
{
1933 my ($key, $type) = @_;
1936 return unless ($key);
1937 $key =~ s/^gitweb\.//;
1938 return if ($key =~ m/\W/);
1941 if (defined $type) {
1944 unless ($type eq 'bool' || $type eq 'int');
1948 if (!defined $config_file ||
1949 $config_file ne "$git_dir/config") {
1950 %config = git_parse_project_config
('gitweb');
1951 $config_file = "$git_dir/config";
1955 if (!defined $type) {
1956 return $config{"gitweb.$key"};
1957 } elsif ($type eq 'bool') {
1958 # backward compatibility: 'git config --bool' returns true/false
1959 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1960 } elsif ($type eq 'int') {
1961 return config_to_int
($config{"gitweb.$key"});
1963 return $config{"gitweb.$key"};
1966 # get hash of given path at given ref
1967 sub git_get_hash_by_path
{
1969 my $path = shift || return undef;
1974 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1975 or die_error
(500, "Open git-ls-tree failed");
1977 close $fd or return undef;
1979 if (!defined $line) {
1980 # there is no tree or hash given by $path at $base
1984 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1985 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1986 if (defined $type && $type ne $2) {
1987 # type doesn't match
1993 # get path of entry with given hash at given tree-ish (ref)
1994 # used to get 'from' filename for combined diff (merge commit) for renames
1995 sub git_get_path_by_hash
{
1996 my $base = shift || return;
1997 my $hash = shift || return;
2001 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2003 while (my $line = <$fd>) {
2006 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2007 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2008 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2017 ## ......................................................................
2018 ## git utility functions, directly accessing git repository
2020 sub git_get_project_description
{
2023 $git_dir = "$projectroot/$path";
2024 open my $fd, "$git_dir/description"
2025 or return git_get_project_config
('description');
2028 if (defined $descr) {
2034 sub git_get_project_ctags
{
2038 $git_dir = "$projectroot/$path";
2039 unless (opendir D
, "$git_dir/ctags") {
2042 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2043 open CT
, $_ or next;
2047 my $ctag = $_; $ctag =~ s
#.*/##;
2048 $ctags->{$ctag} = $val;
2054 sub git_populate_project_tagcloud
{
2057 # First, merge different-cased tags; tags vote on casing
2059 foreach (keys %$ctags) {
2060 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2061 if (not $ctags_lc{lc $_}->{topcount
}
2062 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2063 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2064 $ctags_lc{lc $_}->{topname
} = $_;
2069 if (eval { require HTML
::TagCloud
; 1; }) {
2070 $cloud = HTML
::TagCloud
->new;
2071 foreach (sort keys %ctags_lc) {
2072 # Pad the title with spaces so that the cloud looks
2074 my $title = $ctags_lc{$_}->{topname
};
2075 $title =~ s/ / /g;
2076 $title =~ s/^/ /g;
2077 $title =~ s/$/ /g;
2078 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2081 $cloud = \
%ctags_lc;
2086 sub git_show_project_tagcloud
{
2087 my ($cloud, $count) = @_;
2088 print STDERR
ref($cloud)."..\n";
2089 if (ref $cloud eq 'HTML::TagCloud') {
2090 return $cloud->html_and_css($count);
2092 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2093 return '<p align="center">' . join (', ', map {
2094 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2095 } splice(@tags, 0, $count)) . '</p>';
2099 sub git_get_project_url_list
{
2102 $git_dir = "$projectroot/$path";
2103 open my $fd, "$git_dir/cloneurl"
2104 or return wantarray ?
2105 @
{ config_to_multi
(git_get_project_config
('url')) } :
2106 config_to_multi
(git_get_project_config
('url'));
2107 my @git_project_url_list = map { chomp; $_ } <$fd>;
2110 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2113 sub git_get_projects_list
{
2118 $filter =~ s/\.git$//;
2120 my $check_forks = gitweb_check_feature
('forks');
2122 if (-d
$projects_list) {
2123 # search in directory
2124 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2125 # remove the trailing "/"
2127 my $pfxlen = length("$dir");
2128 my $pfxdepth = ($dir =~ tr!/!!);
2131 follow_fast
=> 1, # follow symbolic links
2132 follow_skip
=> 2, # ignore duplicates
2133 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2135 # skip project-list toplevel, if we get it.
2136 return if (m!^[/.]$!);
2137 # only directories can be git repositories
2138 return unless (-d
$_);
2139 # don't traverse too deep (Find is super slow on os x)
2140 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2141 $File::Find
::prune
= 1;
2145 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2146 # we check related file in $projectroot
2147 if (check_export_ok
("$projectroot/$filter/$subdir")) {
2148 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
2149 $File::Find
::prune
= 1;
2154 } elsif (-f
$projects_list) {
2155 # read from file(url-encoded):
2156 # 'git%2Fgit.git Linus+Torvalds'
2157 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2158 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2160 open my ($fd), $projects_list or return;
2162 while (my $line = <$fd>) {
2164 my ($path, $owner) = split ' ', $line;
2165 $path = unescape
($path);
2166 $owner = unescape
($owner);
2167 if (!defined $path) {
2170 if ($filter ne '') {
2171 # looking for forks;
2172 my $pfx = substr($path, 0, length($filter));
2173 if ($pfx ne $filter) {
2176 my $sfx = substr($path, length($filter));
2177 if ($sfx !~ /^\/.*\
.git
$/) {
2180 } elsif ($check_forks) {
2182 foreach my $filter (keys %paths) {
2183 # looking for forks;
2184 my $pfx = substr($path, 0, length($filter));
2185 if ($pfx ne $filter) {
2188 my $sfx = substr($path, length($filter));
2189 if ($sfx !~ /^\/.*\
.git
$/) {
2192 # is a fork, don't include it in
2197 if (check_export_ok
("$projectroot/$path")) {
2200 owner
=> to_utf8
($owner),
2203 (my $forks_path = $path) =~ s/\.git$//;
2204 $paths{$forks_path}++;
2212 our $gitweb_project_owner = undef;
2213 sub git_get_project_list_from_file
{
2215 return if (defined $gitweb_project_owner);
2217 $gitweb_project_owner = {};
2218 # read from file (url-encoded):
2219 # 'git%2Fgit.git Linus+Torvalds'
2220 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2221 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2222 if (-f
$projects_list) {
2223 open (my $fd , $projects_list);
2224 while (my $line = <$fd>) {
2226 my ($pr, $ow) = split ' ', $line;
2227 $pr = unescape
($pr);
2228 $ow = unescape
($ow);
2229 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2235 sub git_get_project_owner
{
2236 my $project = shift;
2239 return undef unless $project;
2240 $git_dir = "$projectroot/$project";
2242 if (!defined $gitweb_project_owner) {
2243 git_get_project_list_from_file
();
2246 if (exists $gitweb_project_owner->{$project}) {
2247 $owner = $gitweb_project_owner->{$project};
2249 if (!defined $owner){
2250 $owner = git_get_project_config
('owner');
2252 if (!defined $owner) {
2253 $owner = get_file_owner
("$git_dir");
2259 sub git_get_last_activity
{
2263 $git_dir = "$projectroot/$path";
2264 open($fd, "-|", git_cmd
(), 'for-each-ref',
2265 '--format=%(committer)',
2266 '--sort=-committerdate',
2268 'refs/heads') or return;
2269 my $most_recent = <$fd>;
2270 close $fd or return;
2271 if (defined $most_recent &&
2272 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2274 my $age = time - $timestamp;
2275 return ($age, age_string
($age));
2277 return (undef, undef);
2280 sub git_get_references
{
2281 my $type = shift || "";
2283 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2284 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2285 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2286 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2289 while (my $line = <$fd>) {
2291 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2292 if (defined $refs{$1}) {
2293 push @
{$refs{$1}}, $2;
2299 close $fd or return;
2303 sub git_get_rev_name_tags
{
2304 my $hash = shift || return undef;
2306 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2308 my $name_rev = <$fd>;
2311 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2314 # catches also '$hash undefined' output
2319 ## ----------------------------------------------------------------------
2320 ## parse to hash functions
2324 my $tz = shift || "-0000";
2327 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2328 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2329 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2330 $date{'hour'} = $hour;
2331 $date{'minute'} = $min;
2332 $date{'mday'} = $mday;
2333 $date{'day'} = $days[$wday];
2334 $date{'month'} = $months[$mon];
2335 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2336 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2337 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2338 $mday, $months[$mon], $hour ,$min;
2339 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2340 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2342 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2343 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2344 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2345 $date{'hour_local'} = $hour;
2346 $date{'minute_local'} = $min;
2347 $date{'tz_local'} = $tz;
2348 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2349 1900+$year, $mon+1, $mday,
2350 $hour, $min, $sec, $tz);
2359 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2360 $tag{'id'} = $tag_id;
2361 while (my $line = <$fd>) {
2363 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2364 $tag{'object'} = $1;
2365 } elsif ($line =~ m/^type (.+)$/) {
2367 } elsif ($line =~ m/^tag (.+)$/) {
2369 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2370 $tag{'author'} = $1;
2373 } elsif ($line =~ m/--BEGIN/) {
2374 push @comment, $line;
2376 } elsif ($line eq "") {
2380 push @comment, <$fd>;
2381 $tag{'comment'} = \
@comment;
2382 close $fd or return;
2383 if (!defined $tag{'name'}) {
2389 sub parse_commit_text
{
2390 my ($commit_text, $withparents) = @_;
2391 my @commit_lines = split '\n', $commit_text;
2394 pop @commit_lines; # Remove '\0'
2396 if (! @commit_lines) {
2400 my $header = shift @commit_lines;
2401 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2404 ($co{'id'}, my @parents) = split ' ', $header;
2405 while (my $line = shift @commit_lines) {
2406 last if $line eq "\n";
2407 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2409 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2411 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2413 $co{'author_epoch'} = $2;
2414 $co{'author_tz'} = $3;
2415 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2416 $co{'author_name'} = $1;
2417 $co{'author_email'} = $2;
2419 $co{'author_name'} = $co{'author'};
2421 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2422 $co{'committer'} = $1;
2423 $co{'committer_epoch'} = $2;
2424 $co{'committer_tz'} = $3;
2425 $co{'committer_name'} = $co{'committer'};
2426 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2427 $co{'committer_name'} = $1;
2428 $co{'committer_email'} = $2;
2430 $co{'committer_name'} = $co{'committer'};
2434 if (!defined $co{'tree'}) {
2437 $co{'parents'} = \
@parents;
2438 $co{'parent'} = $parents[0];
2440 foreach my $title (@commit_lines) {
2443 $co{'title'} = chop_str
($title, 80, 5);
2444 # remove leading stuff of merges to make the interesting part visible
2445 if (length($title) > 50) {
2446 $title =~ s/^Automatic //;
2447 $title =~ s/^merge (of|with) /Merge ... /i;
2448 if (length($title) > 50) {
2449 $title =~ s/(http|rsync):\/\///;
2451 if (length($title) > 50) {
2452 $title =~ s/(master|www|rsync)\.//;
2454 if (length($title) > 50) {
2455 $title =~ s/kernel.org:?//;
2457 if (length($title) > 50) {
2458 $title =~ s/\/pub\/scm//;
2461 $co{'title_short'} = chop_str
($title, 50, 5);
2465 if (! defined $co{'title'} || $co{'title'} eq "") {
2466 $co{'title'} = $co{'title_short'} = '(no commit message)';
2468 # remove added spaces
2469 foreach my $line (@commit_lines) {
2472 $co{'comment'} = \
@commit_lines;
2474 my $age = time - $co{'committer_epoch'};
2476 $co{'age_string'} = age_string
($age);
2477 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2478 if ($age > 60*60*24*7*2) {
2479 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2480 $co{'age_string_age'} = $co{'age_string'};
2482 $co{'age_string_date'} = $co{'age_string'};
2483 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2489 my ($commit_id) = @_;
2494 open my $fd, "-|", git_cmd
(), "rev-list",
2500 or die_error
(500, "Open git-rev-list failed");
2501 %co = parse_commit_text
(<$fd>, 1);
2508 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2516 open my $fd, "-|", git_cmd
(), "rev-list",
2519 ("--max-count=" . $maxcount),
2520 ("--skip=" . $skip),
2524 ($filename ?
($filename) : ())
2525 or die_error
(500, "Open git-rev-list failed");
2526 while (my $line = <$fd>) {
2527 my %co = parse_commit_text
($line);
2532 return wantarray ?
@cos : \
@cos;
2535 # parse line of git-diff-tree "raw" output
2536 sub parse_difftree_raw_line
{
2540 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2541 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2542 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2543 $res{'from_mode'} = $1;
2544 $res{'to_mode'} = $2;
2545 $res{'from_id'} = $3;
2547 $res{'status'} = $5;
2548 $res{'similarity'} = $6;
2549 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2550 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2552 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2555 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2556 # combined diff (for merge commit)
2557 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2558 $res{'nparents'} = length($1);
2559 $res{'from_mode'} = [ split(' ', $2) ];
2560 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2561 $res{'from_id'} = [ split(' ', $3) ];
2562 $res{'to_id'} = pop @
{$res{'from_id'}};
2563 $res{'status'} = [ split('', $4) ];
2564 $res{'to_file'} = unquote
($5);
2566 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2567 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2568 $res{'commit'} = $1;
2571 return wantarray ?
%res : \
%res;
2574 # wrapper: return parsed line of git-diff-tree "raw" output
2575 # (the argument might be raw line, or parsed info)
2576 sub parsed_difftree_line
{
2577 my $line_or_ref = shift;
2579 if (ref($line_or_ref) eq "HASH") {
2580 # pre-parsed (or generated by hand)
2581 return $line_or_ref;
2583 return parse_difftree_raw_line
($line_or_ref);
2587 # parse line of git-ls-tree output
2588 sub parse_ls_tree_line
($;%) {
2593 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2594 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2602 $res{'name'} = unquote
($4);
2605 return wantarray ?
%res : \
%res;
2608 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2609 sub parse_from_to_diffinfo
{
2610 my ($diffinfo, $from, $to, @parents) = @_;
2612 if ($diffinfo->{'nparents'}) {
2614 $from->{'file'} = [];
2615 $from->{'href'} = [];
2616 fill_from_file_info
($diffinfo, @parents)
2617 unless exists $diffinfo->{'from_file'};
2618 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2619 $from->{'file'}[$i] =
2620 defined $diffinfo->{'from_file'}[$i] ?
2621 $diffinfo->{'from_file'}[$i] :
2622 $diffinfo->{'to_file'};
2623 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2624 $from->{'href'}[$i] = href
(action
=>"blob",
2625 hash_base
=>$parents[$i],
2626 hash
=>$diffinfo->{'from_id'}[$i],
2627 file_name
=>$from->{'file'}[$i]);
2629 $from->{'href'}[$i] = undef;
2633 # ordinary (not combined) diff
2634 $from->{'file'} = $diffinfo->{'from_file'};
2635 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2636 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2637 hash
=>$diffinfo->{'from_id'},
2638 file_name
=>$from->{'file'});
2640 delete $from->{'href'};
2644 $to->{'file'} = $diffinfo->{'to_file'};
2645 if (!is_deleted
($diffinfo)) { # file exists in result
2646 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2647 hash
=>$diffinfo->{'to_id'},
2648 file_name
=>$to->{'file'});
2650 delete $to->{'href'};
2654 ## ......................................................................
2655 ## parse to array of hashes functions
2657 sub git_get_heads_list
{
2661 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2662 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2663 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2666 while (my $line = <$fd>) {
2670 my ($refinfo, $committerinfo) = split(/\0/, $line);
2671 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2672 my ($committer, $epoch, $tz) =
2673 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2674 $ref_item{'fullname'} = $name;
2675 $name =~ s!^refs/heads/!!;
2677 $ref_item{'name'} = $name;
2678 $ref_item{'id'} = $hash;
2679 $ref_item{'title'} = $title || '(no commit message)';
2680 $ref_item{'epoch'} = $epoch;
2682 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2684 $ref_item{'age'} = "unknown";
2687 push @headslist, \
%ref_item;
2691 return wantarray ?
@headslist : \
@headslist;
2694 sub git_get_tags_list
{
2698 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2699 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2700 '--format=%(objectname) %(objecttype) %(refname) '.
2701 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2704 while (my $line = <$fd>) {
2708 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2709 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2710 my ($creator, $epoch, $tz) =
2711 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2712 $ref_item{'fullname'} = $name;
2713 $name =~ s!^refs/tags/!!;
2715 $ref_item{'type'} = $type;
2716 $ref_item{'id'} = $id;
2717 $ref_item{'name'} = $name;
2718 if ($type eq "tag") {
2719 $ref_item{'subject'} = $title;
2720 $ref_item{'reftype'} = $reftype;
2721 $ref_item{'refid'} = $refid;
2723 $ref_item{'reftype'} = $type;
2724 $ref_item{'refid'} = $id;
2727 if ($type eq "tag" || $type eq "commit") {
2728 $ref_item{'epoch'} = $epoch;
2730 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2732 $ref_item{'age'} = "unknown";
2736 push @tagslist, \
%ref_item;
2740 return wantarray ?
@tagslist : \
@tagslist;
2743 ## ----------------------------------------------------------------------
2744 ## filesystem-related functions
2746 sub get_file_owner
{
2749 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2750 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2751 if (!defined $gcos) {
2755 $owner =~ s/[,;].*$//;
2756 return to_utf8
($owner);
2759 ## ......................................................................
2760 ## mimetype related functions
2762 sub mimetype_guess_file
{
2763 my $filename = shift;
2764 my $mimemap = shift;
2765 -r
$mimemap or return undef;
2768 open(MIME
, $mimemap) or return undef;
2770 next if m/^#/; # skip comments
2771 my ($mime, $exts) = split(/\t+/);
2772 if (defined $exts) {
2773 my @exts = split(/\s+/, $exts);
2774 foreach my $ext (@exts) {
2775 $mimemap{$ext} = $mime;
2781 $filename =~ /\.([^.]*)$/;
2782 return $mimemap{$1};
2785 sub mimetype_guess
{
2786 my $filename = shift;
2788 $filename =~ /\./ or return undef;
2790 if ($mimetypes_file) {
2791 my $file = $mimetypes_file;
2792 if ($file !~ m!^/!) { # if it is relative path
2793 # it is relative to project
2794 $file = "$projectroot/$project/$file";
2796 $mime = mimetype_guess_file
($filename, $file);
2798 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2804 my $filename = shift;
2807 my $mime = mimetype_guess
($filename);
2808 $mime and return $mime;
2812 return $default_blob_plain_mimetype unless $fd;
2815 return 'text/plain';
2816 } elsif (! $filename) {
2817 return 'application/octet-stream';
2818 } elsif ($filename =~ m/\.png$/i) {
2820 } elsif ($filename =~ m/\.gif$/i) {
2822 } elsif ($filename =~ m/\.jpe?g$/i) {
2823 return 'image/jpeg';
2825 return 'application/octet-stream';
2829 sub blob_contenttype
{
2830 my ($fd, $file_name, $type) = @_;
2832 $type ||= blob_mimetype
($fd, $file_name);
2833 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2834 $type .= "; charset=$default_text_plain_charset";
2840 ## ======================================================================
2841 ## functions printing HTML: header, footer, error page
2843 sub git_header_html
{
2844 my $status = shift || "200 OK";
2845 my $expires = shift;
2847 my $title = "$site_name";
2848 if (defined $project) {
2849 $title .= " - " . to_utf8
($project);
2850 if (defined $action) {
2851 $title .= "/$action";
2852 if (defined $file_name) {
2853 $title .= " - " . esc_path
($file_name);
2854 if ($action eq "tree" && $file_name !~ m
|/$|) {
2861 # require explicit support from the UA if we are to send the page as
2862 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2863 # we have to do this because MSIE sometimes globs '*/*', pretending to
2864 # support xhtml+xml but choking when it gets what it asked for.
2865 if (defined $cgi->http('HTTP_ACCEPT') &&
2866 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2867 $cgi->Accept('application/xhtml+xml') != 0) {
2868 $content_type = 'application/xhtml+xml';
2870 $content_type = 'text/html';
2872 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2873 -status
=> $status, -expires
=> $expires);
2874 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2876 <?xml version="1.0" encoding="utf-8"?>
2877 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2878 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2879 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2880 <!-- git core binaries version $git_version -->
2882 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2883 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2884 <meta name="robots" content="index, nofollow"/>
2885 <title>$title</title>
2887 # print out each stylesheet that exist
2888 if (defined $stylesheet) {
2889 #provides backwards capability for those people who define style sheet in a config file
2890 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2892 foreach my $stylesheet (@stylesheets) {
2893 next unless $stylesheet;
2894 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2897 if (defined $project) {
2898 my %href_params = get_feed_info
();
2899 if (!exists $href_params{'-title'}) {
2900 $href_params{'-title'} = 'log';
2903 foreach my $format qw(RSS Atom) {
2904 my $type = lc($format);
2906 '-rel' => 'alternate',
2907 '-title' => "$project - $href_params{'-title'} - $format feed",
2908 '-type' => "application/$type+xml"
2911 $href_params{'action'} = $type;
2912 $link_attr{'-href'} = href
(%href_params);
2914 "rel=\"$link_attr{'-rel'}\" ".
2915 "title=\"$link_attr{'-title'}\" ".
2916 "href=\"$link_attr{'-href'}\" ".
2917 "type=\"$link_attr{'-type'}\" ".
2920 $href_params{'extra_options'} = '--no-merges';
2921 $link_attr{'-href'} = href
(%href_params);
2922 $link_attr{'-title'} .= ' (no merges)';
2924 "rel=\"$link_attr{'-rel'}\" ".
2925 "title=\"$link_attr{'-title'}\" ".
2926 "href=\"$link_attr{'-href'}\" ".
2927 "type=\"$link_attr{'-type'}\" ".
2932 printf('<link rel="alternate" title="%s projects list" '.
2933 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2934 $site_name, href
(project
=>undef, action
=>"project_index"));
2935 printf('<link rel="alternate" title="%s projects feeds" '.
2936 'href="%s" type="text/x-opml" />'."\n",
2937 $site_name, href
(project
=>undef, action
=>"opml"));
2939 if (defined $favicon) {
2940 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2946 if (-f
$site_header) {
2947 open (my $fd, $site_header);
2952 print "<div class=\"page_header\">\n" .
2953 $cgi->a({-href
=> esc_url
($logo_url),
2954 -title
=> $logo_label},
2955 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2956 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2957 if (defined $project) {
2958 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2959 if (defined $action) {
2966 my $have_search = gitweb_check_feature
('search');
2967 if (defined $project && $have_search) {
2968 if (!defined $searchtext) {
2972 if (defined $hash_base) {
2973 $search_hash = $hash_base;
2974 } elsif (defined $hash) {
2975 $search_hash = $hash;
2977 $search_hash = "HEAD";
2979 my $action = $my_uri;
2980 my $use_pathinfo = gitweb_check_feature
('pathinfo');
2981 if ($use_pathinfo) {
2982 $action .= "/".esc_url
($project);
2984 print $cgi->startform(-method
=> "get", -action
=> $action) .
2985 "<div class=\"search\">\n" .
2987 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2988 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2989 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2990 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2991 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2992 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2994 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2995 "<span title=\"Extended regular expression\">" .
2996 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2997 -checked
=> $search_use_regexp) .
3000 $cgi->end_form() . "\n";
3004 sub git_footer_html
{
3005 my $feed_class = 'rss_logo';
3007 print "<div class=\"page_footer\">\n";
3008 if (defined $project) {
3009 my $descr = git_get_project_description
($project);
3010 if (defined $descr) {
3011 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3014 my %href_params = get_feed_info
();
3015 if (!%href_params) {
3016 $feed_class .= ' generic';
3018 $href_params{'-title'} ||= 'log';
3020 foreach my $format qw(RSS Atom) {
3021 $href_params{'action'} = lc($format);
3022 print $cgi->a({-href
=> href
(%href_params),
3023 -title
=> "$href_params{'-title'} $format feed",
3024 -class => $feed_class}, $format)."\n";
3028 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3029 -class => $feed_class}, "OPML") . " ";
3030 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3031 -class => $feed_class}, "TXT") . "\n";
3033 print "</div>\n"; # class="page_footer"
3035 if (-f
$site_footer) {
3036 open (my $fd, $site_footer);
3045 # die_error(<http_status_code>, <error_message>)
3046 # Example: die_error(404, 'Hash not found')
3047 # By convention, use the following status codes (as defined in RFC 2616):
3048 # 400: Invalid or missing CGI parameters, or
3049 # requested object exists but has wrong type.
3050 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3051 # this server or project.
3052 # 404: Requested object/revision/project doesn't exist.
3053 # 500: The server isn't configured properly, or
3054 # an internal error occurred (e.g. failed assertions caused by bugs), or
3055 # an unknown error occurred (e.g. the git binary died unexpectedly).
3057 my $status = shift || 500;
3058 my $error = shift || "Internal server error";
3060 my %http_responses = (400 => '400 Bad Request',
3061 403 => '403 Forbidden',
3062 404 => '404 Not Found',
3063 500 => '500 Internal Server Error');
3064 git_header_html
($http_responses{$status});
3066 <div class="page_body">
3076 ## ----------------------------------------------------------------------
3077 ## functions printing or outputting HTML: navigation
3079 sub git_print_page_nav
{
3080 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3081 $extra = '' if !defined $extra; # pager or formats
3083 my @navs = qw(summary shortlog log commit commitdiff tree);
3085 @navs = grep { $_ ne $suppress } @navs;
3088 my %arg = map { $_ => {action
=>$_} } @navs;
3089 if (defined $head) {
3090 for (qw(commit commitdiff)) {
3091 $arg{$_}{'hash'} = $head;
3093 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3094 for (qw(shortlog log)) {
3095 $arg{$_}{'hash'} = $head;
3100 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3101 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3103 my @actions = gitweb_get_feature
('actions');
3106 'n' => $project, # project name
3107 'f' => $git_dir, # project path within filesystem
3108 'h' => $treehead || '', # current hash ('h' parameter)
3109 'b' => $treebase || '', # hash base ('hb' parameter)
3112 my ($label, $link, $pos) = splice(@actions,0,3);
3114 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3116 $link =~ s/%([%nfhb])/$repl{$1}/g;
3117 $arg{$label}{'_href'} = $link;
3120 print "<div class=\"page_nav\">\n" .
3122 map { $_ eq $current ?
3123 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3125 print "<br/>\n$extra<br/>\n" .
3129 sub format_paging_nav
{
3130 my ($action, $hash, $head, $page, $has_next_link) = @_;
3134 if ($hash ne $head || $page) {
3135 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3137 $paging_nav .= "HEAD";
3141 $paging_nav .= " ⋅ " .
3142 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3143 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3145 $paging_nav .= " ⋅ prev";
3148 if ($has_next_link) {
3149 $paging_nav .= " ⋅ " .
3150 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3151 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3153 $paging_nav .= " ⋅ next";
3159 ## ......................................................................
3160 ## functions printing or outputting HTML: div
3162 sub git_print_header_div
{
3163 my ($action, $title, $hash, $hash_base) = @_;
3166 $args{'action'} = $action;
3167 $args{'hash'} = $hash if $hash;
3168 $args{'hash_base'} = $hash_base if $hash_base;
3170 print "<div class=\"header\">\n" .
3171 $cgi->a({-href
=> href
(%args), -class => "title"},
3172 $title ?
$title : $action) .
3176 #sub git_print_authorship (\%) {
3177 sub git_print_authorship
{
3180 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3181 print "<div class=\"author_date\">" .
3182 esc_html
($co->{'author_name'}) .
3184 if ($ad{'hour_local'} < 6) {
3185 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3186 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3188 printf(" (%02d:%02d %s)",
3189 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3194 sub git_print_page_path
{
3200 print "<div class=\"page_path\">";
3201 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3202 -title
=> 'tree root'}, to_utf8
("[$project]"));
3204 if (defined $name) {
3205 my @dirname = split '/', $name;
3206 my $basename = pop @dirname;
3209 foreach my $dir (@dirname) {
3210 $fullname .= ($fullname ?
'/' : '') . $dir;
3211 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3213 -title
=> $fullname}, esc_path
($dir));
3216 if (defined $type && $type eq 'blob') {
3217 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3219 -title
=> $name}, esc_path
($basename));
3220 } elsif (defined $type && $type eq 'tree') {
3221 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3223 -title
=> $name}, esc_path
($basename));
3226 print esc_path
($basename);
3229 print "<br/></div>\n";
3232 # sub git_print_log (\@;%) {
3233 sub git_print_log
($;%) {
3237 if ($opts{'-remove_title'}) {
3238 # remove title, i.e. first line of log
3241 # remove leading empty lines
3242 while (defined $log->[0] && $log->[0] eq "") {
3249 foreach my $line (@
$log) {
3250 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3253 if (! $opts{'-remove_signoff'}) {
3254 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3257 # remove signoff lines
3264 # print only one empty line
3265 # do not print empty line after signoff
3267 next if ($empty || $signoff);
3273 print format_log_line_html
($line) . "<br/>\n";
3276 if ($opts{'-final_empty_line'}) {
3277 # end with single empty line
3278 print "<br/>\n" unless $empty;
3282 # return link target (what link points to)
3283 sub git_get_link_target
{
3288 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3292 $link_target = <$fd>;
3297 return $link_target;
3300 # given link target, and the directory (basedir) the link is in,
3301 # return target of link relative to top directory (top tree);
3302 # return undef if it is not possible (including absolute links).
3303 sub normalize_link_target
{
3304 my ($link_target, $basedir, $hash_base) = @_;
3306 # we can normalize symlink target only if $hash_base is provided
3307 return unless $hash_base;
3309 # absolute symlinks (beginning with '/') cannot be normalized
3310 return if (substr($link_target, 0, 1) eq '/');
3312 # normalize link target to path from top (root) tree (dir)
3315 $path = $basedir . '/' . $link_target;
3317 # we are in top (root) tree (dir)
3318 $path = $link_target;
3321 # remove //, /./, and /../
3323 foreach my $part (split('/', $path)) {
3324 # discard '.' and ''
3325 next if (!$part || $part eq '.');
3327 if ($part eq '..') {
3331 # link leads outside repository (outside top dir)
3335 push @path_parts, $part;
3338 $path = join('/', @path_parts);
3343 # print tree entry (row of git_tree), but without encompassing <tr> element
3344 sub git_print_tree_entry
{
3345 my ($t, $basedir, $hash_base, $have_blame) = @_;
3348 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3350 # The format of a table row is: mode list link. Where mode is
3351 # the mode of the entry, list is the name of the entry, an href,
3352 # and link is the action links of the entry.
3354 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3355 if ($t->{'type'} eq "blob") {
3356 print "<td class=\"list\">" .
3357 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3358 file_name
=>"$basedir$t->{'name'}", %base_key),
3359 -class => "list"}, esc_path
($t->{'name'}));
3360 if (S_ISLNK
(oct $t->{'mode'})) {
3361 my $link_target = git_get_link_target
($t->{'hash'});
3363 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3364 if (defined $norm_target) {
3366 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3367 file_name
=>$norm_target),
3368 -title
=> $norm_target}, esc_path
($link_target));
3370 print " -> " . esc_path
($link_target);
3375 print "<td class=\"link\">";
3376 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3377 file_name
=>"$basedir$t->{'name'}", %base_key)},
3381 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3382 file_name
=>"$basedir$t->{'name'}", %base_key)},
3385 if (defined $hash_base) {
3387 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3388 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3392 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3393 file_name
=>"$basedir$t->{'name'}")},
3397 } elsif ($t->{'type'} eq "tree") {
3398 print "<td class=\"list\">";
3399 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3400 file_name
=>"$basedir$t->{'name'}", %base_key)},
3401 esc_path
($t->{'name'}));
3403 print "<td class=\"link\">";
3404 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3405 file_name
=>"$basedir$t->{'name'}", %base_key)},
3407 if (defined $hash_base) {
3409 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3410 file_name
=>"$basedir$t->{'name'}")},
3415 # unknown object: we can only present history for it
3416 # (this includes 'commit' object, i.e. submodule support)
3417 print "<td class=\"list\">" .
3418 esc_path
($t->{'name'}) .
3420 print "<td class=\"link\">";
3421 if (defined $hash_base) {
3422 print $cgi->a({-href
=> href
(action
=>"history",
3423 hash_base
=>$hash_base,
3424 file_name
=>"$basedir$t->{'name'}")},
3431 ## ......................................................................
3432 ## functions printing large fragments of HTML
3434 # get pre-image filenames for merge (combined) diff
3435 sub fill_from_file_info
{
3436 my ($diff, @parents) = @_;
3438 $diff->{'from_file'} = [ ];
3439 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3440 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3441 if ($diff->{'status'}[$i] eq 'R' ||
3442 $diff->{'status'}[$i] eq 'C') {
3443 $diff->{'from_file'}[$i] =
3444 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3451 # is current raw difftree line of file deletion
3453 my $diffinfo = shift;
3455 return $diffinfo->{'to_id'} eq ('0' x
40);
3458 # does patch correspond to [previous] difftree raw line
3459 # $diffinfo - hashref of parsed raw diff format
3460 # $patchinfo - hashref of parsed patch diff format
3461 # (the same keys as in $diffinfo)
3462 sub is_patch_split
{
3463 my ($diffinfo, $patchinfo) = @_;
3465 return defined $diffinfo && defined $patchinfo
3466 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3470 sub git_difftree_body
{
3471 my ($difftree, $hash, @parents) = @_;
3472 my ($parent) = $parents[0];
3473 my $have_blame = gitweb_check_feature
('blame');
3474 print "<div class=\"list_head\">\n";
3475 if ($#{$difftree} > 10) {
3476 print(($#{$difftree} + 1) . " files changed:\n");
3480 print "<table class=\"" .
3481 (@parents > 1 ?
"combined " : "") .
3484 # header only for combined diff in 'commitdiff' view
3485 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3488 print "<thead><tr>\n" .
3489 "<th></th><th></th>\n"; # filename, patchN link
3490 for (my $i = 0; $i < @parents; $i++) {
3491 my $par = $parents[$i];
3493 $cgi->a({-href
=> href
(action
=>"commitdiff",
3494 hash
=>$hash, hash_parent
=>$par),
3495 -title
=> 'commitdiff to parent number ' .
3496 ($i+1) . ': ' . substr($par,0,7)},
3500 print "</tr></thead>\n<tbody>\n";
3505 foreach my $line (@
{$difftree}) {
3506 my $diff = parsed_difftree_line
($line);
3509 print "<tr class=\"dark\">\n";
3511 print "<tr class=\"light\">\n";
3515 if (exists $diff->{'nparents'}) { # combined diff
3517 fill_from_file_info
($diff, @parents)
3518 unless exists $diff->{'from_file'};
3520 if (!is_deleted
($diff)) {
3521 # file exists in the result (child) commit
3523 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3524 file_name
=>$diff->{'to_file'},
3526 -class => "list"}, esc_path
($diff->{'to_file'})) .
3530 esc_path
($diff->{'to_file'}) .
3534 if ($action eq 'commitdiff') {
3537 print "<td class=\"link\">" .
3538 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3543 my $has_history = 0;
3544 my $not_deleted = 0;
3545 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3546 my $hash_parent = $parents[$i];
3547 my $from_hash = $diff->{'from_id'}[$i];
3548 my $from_path = $diff->{'from_file'}[$i];
3549 my $status = $diff->{'status'}[$i];
3551 $has_history ||= ($status ne 'A');
3552 $not_deleted ||= ($status ne 'D');
3554 if ($status eq 'A') {
3555 print "<td class=\"link\" align=\"right\"> | </td>\n";
3556 } elsif ($status eq 'D') {
3557 print "<td class=\"link\">" .
3558 $cgi->a({-href
=> href
(action
=>"blob",
3561 file_name
=>$from_path)},
3565 if ($diff->{'to_id'} eq $from_hash) {
3566 print "<td class=\"link nochange\">";
3568 print "<td class=\"link\">";
3570 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3571 hash
=>$diff->{'to_id'},
3572 hash_parent
=>$from_hash,
3574 hash_parent_base
=>$hash_parent,
3575 file_name
=>$diff->{'to_file'},
3576 file_parent
=>$from_path)},
3582 print "<td class=\"link\">";
3584 print $cgi->a({-href
=> href
(action
=>"blob",
3585 hash
=>$diff->{'to_id'},
3586 file_name
=>$diff->{'to_file'},
3589 print " | " if ($has_history);
3592 print $cgi->a({-href
=> href
(action
=>"history",
3593 file_name
=>$diff->{'to_file'},
3600 next; # instead of 'else' clause, to avoid extra indent
3602 # else ordinary diff
3604 my ($to_mode_oct, $to_mode_str, $to_file_type);
3605 my ($from_mode_oct, $from_mode_str, $from_file_type);
3606 if ($diff->{'to_mode'} ne ('0' x
6)) {
3607 $to_mode_oct = oct $diff->{'to_mode'};
3608 if (S_ISREG
($to_mode_oct)) { # only for regular file
3609 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3611 $to_file_type = file_type
($diff->{'to_mode'});
3613 if ($diff->{'from_mode'} ne ('0' x
6)) {
3614 $from_mode_oct = oct $diff->{'from_mode'};
3615 if (S_ISREG
($to_mode_oct)) { # only for regular file
3616 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3618 $from_file_type = file_type
($diff->{'from_mode'});
3621 if ($diff->{'status'} eq "A") { # created
3622 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3623 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3624 $mode_chng .= "]</span>";
3626 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3627 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3628 -class => "list"}, esc_path
($diff->{'file'}));
3630 print "<td>$mode_chng</td>\n";
3631 print "<td class=\"link\">";
3632 if ($action eq 'commitdiff') {
3635 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3638 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3639 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3643 } elsif ($diff->{'status'} eq "D") { # deleted
3644 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3646 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3647 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3648 -class => "list"}, esc_path
($diff->{'file'}));
3650 print "<td>$mode_chng</td>\n";
3651 print "<td class=\"link\">";
3652 if ($action eq 'commitdiff') {
3655 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3658 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3659 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3662 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3663 file_name
=>$diff->{'file'})},
3666 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3667 file_name
=>$diff->{'file'})},
3671 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3672 my $mode_chnge = "";
3673 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3674 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3675 if ($from_file_type ne $to_file_type) {
3676 $mode_chnge .= " from $from_file_type to $to_file_type";
3678 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3679 if ($from_mode_str && $to_mode_str) {
3680 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3681 } elsif ($to_mode_str) {
3682 $mode_chnge .= " mode: $to_mode_str";
3685 $mode_chnge .= "]</span>\n";
3688 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3689 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3690 -class => "list"}, esc_path
($diff->{'file'}));
3692 print "<td>$mode_chnge</td>\n";
3693 print "<td class=\"link\">";
3694 if ($action eq 'commitdiff') {
3697 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3699 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3700 # "commit" view and modified file (not onlu mode changed)
3701 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3702 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3703 hash_base
=>$hash, hash_parent_base
=>$parent,
3704 file_name
=>$diff->{'file'})},
3708 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3709 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3712 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3713 file_name
=>$diff->{'file'})},
3716 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3717 file_name
=>$diff->{'file'})},
3721 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3722 my %status_name = ('R' => 'moved', 'C' => 'copied');
3723 my $nstatus = $status_name{$diff->{'status'}};
3725 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3726 # mode also for directories, so we cannot use $to_mode_str
3727 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3730 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3731 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3732 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3733 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3734 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3735 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3736 -class => "list"}, esc_path
($diff->{'from_file'})) .
3737 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3738 "<td class=\"link\">";
3739 if ($action eq 'commitdiff') {
3742 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3744 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3745 # "commit" view and modified file (not only pure rename or copy)
3746 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3747 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3748 hash_base
=>$hash, hash_parent_base
=>$parent,
3749 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3753 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3754 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3757 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3758 file_name
=>$diff->{'to_file'})},
3761 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3762 file_name
=>$diff->{'to_file'})},
3766 } # we should not encounter Unmerged (U) or Unknown (X) status
3769 print "</tbody>" if $has_header;
3773 sub git_patchset_body
{
3774 my ($fd, $difftree, $hash, @hash_parents) = @_;
3775 my ($hash_parent) = $hash_parents[0];
3777 my $is_combined = (@hash_parents > 1);
3779 my $patch_number = 0;
3785 print "<div class=\"patchset\">\n";
3787 # skip to first patch
3788 while ($patch_line = <$fd>) {
3791 last if ($patch_line =~ m/^diff /);
3795 while ($patch_line) {
3797 # parse "git diff" header line
3798 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3799 # $1 is from_name, which we do not use
3800 $to_name = unquote
($2);
3801 $to_name =~ s!^b/!!;
3802 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3803 # $1 is 'cc' or 'combined', which we do not use
3804 $to_name = unquote
($2);
3809 # check if current patch belong to current raw line
3810 # and parse raw git-diff line if needed
3811 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3812 # this is continuation of a split patch
3813 print "<div class=\"patch cont\">\n";
3815 # advance raw git-diff output if needed
3816 $patch_idx++ if defined $diffinfo;
3818 # read and prepare patch information
3819 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3821 # compact combined diff output can have some patches skipped
3822 # find which patch (using pathname of result) we are at now;
3824 while ($to_name ne $diffinfo->{'to_file'}) {
3825 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3826 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3827 "</div>\n"; # class="patch"
3832 last if $patch_idx > $#$difftree;
3833 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3837 # modifies %from, %to hashes
3838 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3840 # this is first patch for raw difftree line with $patch_idx index
3841 # we index @$difftree array from 0, but number patches from 1
3842 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3846 #assert($patch_line =~ m/^diff /) if DEBUG;
3847 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3849 # print "git diff" header
3850 print format_git_diff_header_line
($patch_line, $diffinfo,
3853 # print extended diff header
3854 print "<div class=\"diff extended_header\">\n";
3856 while ($patch_line = <$fd>) {
3859 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3861 print format_extended_diff_header_line
($patch_line, $diffinfo,
3864 print "</div>\n"; # class="diff extended_header"
3866 # from-file/to-file diff header
3867 if (! $patch_line) {
3868 print "</div>\n"; # class="patch"
3871 next PATCH
if ($patch_line =~ m/^diff /);
3872 #assert($patch_line =~ m/^---/) if DEBUG;
3874 my $last_patch_line = $patch_line;
3875 $patch_line = <$fd>;
3877 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3879 print format_diff_from_to_header
($last_patch_line, $patch_line,
3880 $diffinfo, \
%from, \
%to,
3885 while ($patch_line = <$fd>) {
3888 next PATCH
if ($patch_line =~ m/^diff /);
3890 print format_diff_line
($patch_line, \
%from, \
%to);
3894 print "</div>\n"; # class="patch"
3897 # for compact combined (--cc) format, with chunk and patch simpliciaction
3898 # patchset might be empty, but there might be unprocessed raw lines
3899 for (++$patch_idx if $patch_number > 0;
3900 $patch_idx < @
$difftree;
3902 # read and prepare patch information
3903 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3905 # generate anchor for "patch" links in difftree / whatchanged part
3906 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3907 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3908 "</div>\n"; # class="patch"
3913 if ($patch_number == 0) {
3914 if (@hash_parents > 1) {
3915 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3917 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3921 print "</div>\n"; # class="patchset"
3924 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3926 # fills project list info (age, description, owner, forks) for each
3927 # project in the list, removing invalid projects from returned list
3928 # NOTE: modifies $projlist, but does not remove entries from it
3929 sub fill_project_list_info
{
3930 my ($projlist, $check_forks) = @_;
3933 my $show_ctags = gitweb_check_feature
('ctags');
3935 foreach my $pr (@
$projlist) {
3936 my (@activity) = git_get_last_activity
($pr->{'path'});
3937 unless (@activity) {
3940 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3941 if (!defined $pr->{'descr'}) {
3942 my $descr = git_get_project_description
($pr->{'path'}) || "";
3943 $descr = to_utf8
($descr);
3944 $pr->{'descr_long'} = $descr;
3945 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3947 if (!defined $pr->{'owner'}) {
3948 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3951 my $pname = $pr->{'path'};
3952 if (($pname =~ s/\.git$//) &&
3953 ($pname !~ /\/$/) &&
3954 (-d
"$projectroot/$pname")) {
3955 $pr->{'forks'} = "-d $projectroot/$pname";
3960 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3961 push @projects, $pr;
3967 # print 'sort by' <th> element, generating 'sort by $name' replay link
3968 # if that order is not selected
3970 my ($name, $order, $header) = @_;
3971 $header ||= ucfirst($name);
3973 if ($order eq $name) {
3974 print "<th>$header</th>\n";
3977 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3978 -class => "header"}, $header) .
3983 sub git_project_list_body
{
3984 # actually uses global variable $project
3985 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3987 my $check_forks = gitweb_check_feature
('forks');
3988 my @projects = fill_project_list_info
($projlist, $check_forks);
3990 $order ||= $default_projects_order;
3991 $from = 0 unless defined $from;
3992 $to = $#projects if (!defined $to || $#projects < $to);
3995 project
=> { key
=> 'path', type
=> 'str' },
3996 descr
=> { key
=> 'descr_long', type
=> 'str' },
3997 owner
=> { key
=> 'owner', type
=> 'str' },
3998 age
=> { key
=> 'age', type
=> 'num' }
4000 my $oi = $order_info{$order};
4001 if ($oi->{'type'} eq 'str') {
4002 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4004 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4007 my $show_ctags = gitweb_check_feature
('ctags');
4010 foreach my $p (@projects) {
4011 foreach my $ct (keys %{$p->{'ctags'}}) {
4012 $ctags{$ct} += $p->{'ctags'}->{$ct};
4015 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4016 print git_show_project_tagcloud
($cloud, 64);
4019 print "<table class=\"project_list\">\n";
4020 unless ($no_header) {
4023 print "<th></th>\n";
4025 print_sort_th
('project', $order, 'Project');
4026 print_sort_th
('descr', $order, 'Description');
4027 print_sort_th
('owner', $order, 'Owner');
4028 print_sort_th
('age', $order, 'Last Change');
4029 print "<th></th>\n" . # for links
4033 my $tagfilter = $cgi->param('by_tag');
4034 for (my $i = $from; $i <= $to; $i++) {
4035 my $pr = $projects[$i];
4037 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4038 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4039 and not $pr->{'descr_long'} =~ /$searchtext/;
4040 # Weed out forks or non-matching entries of search
4042 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4043 $forkbase="^$forkbase" if $forkbase;
4044 next if not $searchtext and not $tagfilter and $show_ctags
4045 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4049 print "<tr class=\"dark\">\n";
4051 print "<tr class=\"light\">\n";
4056 if ($pr->{'forks'}) {
4057 print "<!-- $pr->{'forks'} -->\n";
4058 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4062 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4063 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4064 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4065 -class => "list", -title
=> $pr->{'descr_long'}},
4066 esc_html
($pr->{'descr'})) . "</td>\n" .
4067 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4068 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4069 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4070 "<td class=\"link\">" .
4071 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4072 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4073 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4074 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4075 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4079 if (defined $extra) {
4082 print "<td></td>\n";
4084 print "<td colspan=\"5\">$extra</td>\n" .
4090 sub git_shortlog_body
{
4091 # uses global variable $project
4092 my ($commitlist, $from, $to, $refs, $extra) = @_;
4094 $from = 0 unless defined $from;
4095 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4097 print "<table class=\"shortlog\">\n";
4099 for (my $i = $from; $i <= $to; $i++) {
4100 my %co = %{$commitlist->[$i]};
4101 my $commit = $co{'id'};
4102 my $ref = format_ref_marker
($refs, $commit);
4104 print "<tr class=\"dark\">\n";
4106 print "<tr class=\"light\">\n";
4109 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4110 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4111 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4112 "<td><i>" . $author . "</i></td>\n" .
4114 print format_subject_html
($co{'title'}, $co{'title_short'},
4115 href
(action
=>"commit", hash
=>$commit), $ref);
4117 "<td class=\"link\">" .
4118 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4119 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4120 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4121 my $snapshot_links = format_snapshot_links
($commit);
4122 if (defined $snapshot_links) {
4123 print " | " . $snapshot_links;
4128 if (defined $extra) {
4130 "<td colspan=\"4\">$extra</td>\n" .
4136 sub git_history_body
{
4137 # Warning: assumes constant type (blob or tree) during history
4138 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4140 $from = 0 unless defined $from;
4141 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4143 print "<table class=\"history\">\n";
4145 for (my $i = $from; $i <= $to; $i++) {
4146 my %co = %{$commitlist->[$i]};
4150 my $commit = $co{'id'};
4152 my $ref = format_ref_marker
($refs, $commit);
4155 print "<tr class=\"dark\">\n";
4157 print "<tr class=\"light\">\n";
4160 # shortlog uses chop_str($co{'author_name'}, 10)
4161 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4162 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4163 "<td><i>" . $author . "</i></td>\n" .
4165 # originally git_history used chop_str($co{'title'}, 50)
4166 print format_subject_html
($co{'title'}, $co{'title_short'},
4167 href
(action
=>"commit", hash
=>$commit), $ref);
4169 "<td class=\"link\">" .
4170 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4171 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4173 if ($ftype eq 'blob') {
4174 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4175 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4176 if (defined $blob_current && defined $blob_parent &&
4177 $blob_current ne $blob_parent) {
4179 $cgi->a({-href
=> href
(action
=>"blobdiff",
4180 hash
=>$blob_current, hash_parent
=>$blob_parent,
4181 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4182 file_name
=>$file_name)},
4189 if (defined $extra) {
4191 "<td colspan=\"4\">$extra</td>\n" .
4198 # uses global variable $project
4199 my ($taglist, $from, $to, $extra) = @_;
4200 $from = 0 unless defined $from;
4201 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4203 print "<table class=\"tags\">\n";
4205 for (my $i = $from; $i <= $to; $i++) {
4206 my $entry = $taglist->[$i];
4208 my $comment = $tag{'subject'};
4210 if (defined $comment) {
4211 $comment_short = chop_str
($comment, 30, 5);
4214 print "<tr class=\"dark\">\n";
4216 print "<tr class=\"light\">\n";
4219 if (defined $tag{'age'}) {
4220 print "<td><i>$tag{'age'}</i></td>\n";
4222 print "<td></td>\n";
4225 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4226 -class => "list name"}, esc_html
($tag{'name'})) .
4229 if (defined $comment) {
4230 print format_subject_html
($comment, $comment_short,
4231 href
(action
=>"tag", hash
=>$tag{'id'}));
4234 "<td class=\"selflink\">";
4235 if ($tag{'type'} eq "tag") {
4236 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4241 "<td class=\"link\">" . " | " .
4242 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4243 if ($tag{'reftype'} eq "commit") {
4244 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4245 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4246 } elsif ($tag{'reftype'} eq "blob") {
4247 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4252 if (defined $extra) {
4254 "<td colspan=\"5\">$extra</td>\n" .
4260 sub git_heads_body
{
4261 # uses global variable $project
4262 my ($headlist, $head, $from, $to, $extra) = @_;
4263 $from = 0 unless defined $from;
4264 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4266 print "<table class=\"heads\">\n";
4268 for (my $i = $from; $i <= $to; $i++) {
4269 my $entry = $headlist->[$i];
4271 my $curr = $ref{'id'} eq $head;
4273 print "<tr class=\"dark\">\n";
4275 print "<tr class=\"light\">\n";
4278 print "<td><i>$ref{'age'}</i></td>\n" .
4279 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4280 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4281 -class => "list name"},esc_html
($ref{'name'})) .
4283 "<td class=\"link\">" .
4284 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4285 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4286 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4290 if (defined $extra) {
4292 "<td colspan=\"3\">$extra</td>\n" .
4298 sub git_search_grep_body
{
4299 my ($commitlist, $from, $to, $extra) = @_;
4300 $from = 0 unless defined $from;
4301 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4303 print "<table class=\"commit_search\">\n";
4305 for (my $i = $from; $i <= $to; $i++) {
4306 my %co = %{$commitlist->[$i]};
4310 my $commit = $co{'id'};
4312 print "<tr class=\"dark\">\n";
4314 print "<tr class=\"light\">\n";
4317 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4318 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4319 "<td><i>" . $author . "</i></td>\n" .
4321 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4322 -class => "list subject"},
4323 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4324 my $comment = $co{'comment'};
4325 foreach my $line (@
$comment) {
4326 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4327 my ($lead, $match, $trail) = ($1, $2, $3);
4328 $match = chop_str
($match, 70, 5, 'center');
4329 my $contextlen = int((80 - length($match))/2);
4330 $contextlen = 30 if ($contextlen > 30);
4331 $lead = chop_str
($lead, $contextlen, 10, 'left');
4332 $trail = chop_str
($trail, $contextlen, 10, 'right');
4334 $lead = esc_html
($lead);
4335 $match = esc_html
($match);
4336 $trail = esc_html
($trail);
4338 print "$lead<span class=\"match\">$match</span>$trail<br />";
4342 "<td class=\"link\">" .
4343 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4345 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4347 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4351 if (defined $extra) {
4353 "<td colspan=\"3\">$extra</td>\n" .
4359 ## ======================================================================
4360 ## ======================================================================
4363 sub git_project_list
{
4364 my $order = $input_params{'order'};
4365 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4366 die_error
(400, "Unknown order parameter");
4369 my @list = git_get_projects_list
();
4371 die_error
(404, "No projects found");
4375 if (-f
$home_text) {
4376 print "<div class=\"index_include\">\n";
4377 open (my $fd, $home_text);
4382 print $cgi->startform(-method
=> "get") .
4383 "<p class=\"projsearch\">Search:\n" .
4384 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4386 $cgi->end_form() . "\n";
4387 git_project_list_body
(\
@list, $order);
4392 my $order = $input_params{'order'};
4393 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4394 die_error
(400, "Unknown order parameter");
4397 my @list = git_get_projects_list
($project);
4399 die_error
(404, "No forks found");
4403 git_print_page_nav
('','');
4404 git_print_header_div
('summary', "$project forks");
4405 git_project_list_body
(\
@list, $order);
4409 sub git_project_index
{
4410 my @projects = git_get_projects_list
($project);
4413 -type
=> 'text/plain',
4414 -charset
=> 'utf-8',
4415 -content_disposition
=> 'inline; filename="index.aux"');
4417 foreach my $pr (@projects) {
4418 if (!exists $pr->{'owner'}) {
4419 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4422 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4423 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4424 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4425 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4429 print "$path $owner\n";
4434 my $descr = git_get_project_description
($project) || "none";
4435 my %co = parse_commit
("HEAD");
4436 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4437 my $head = $co{'id'};
4439 my $owner = git_get_project_owner
($project);
4441 my $refs = git_get_references
();
4442 # These get_*_list functions return one more to allow us to see if
4443 # there are more ...
4444 my @taglist = git_get_tags_list
(16);
4445 my @headlist = git_get_heads_list
(16);
4447 my $check_forks = gitweb_check_feature
('forks');
4450 @forklist = git_get_projects_list
($project);
4454 git_print_page_nav
('summary','', $head);
4456 print "<div class=\"title\"> </div>\n";
4457 print "<table class=\"projects_list\">\n" .
4458 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4459 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4460 if (defined $cd{'rfc2822'}) {
4461 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4464 # use per project git URL list in $projectroot/$project/cloneurl
4465 # or make project git URL from git base URL and project name
4466 my $url_tag = "URL";
4467 my @url_list = git_get_project_url_list
($project);
4468 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4469 foreach my $git_url (@url_list) {
4470 next unless $git_url;
4471 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4476 my $show_ctags = gitweb_check_feature
('ctags');
4478 my $ctags = git_get_project_ctags
($project);
4479 my $cloud = git_populate_project_tagcloud
($ctags);
4480 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4481 print "</td>\n<td>" unless %$ctags;
4482 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4483 print "</td>\n<td>" if %$ctags;
4484 print git_show_project_tagcloud
($cloud, 48);
4490 if (-s
"$projectroot/$project/README.html") {
4491 if (open my $fd, "$projectroot/$project/README.html") {
4492 print "<div class=\"title\">readme</div>\n" .
4493 "<div class=\"readme\">\n";
4494 print $_ while (<$fd>);
4495 print "\n</div>\n"; # class="readme"
4500 # we need to request one more than 16 (0..15) to check if
4502 my @commitlist = $head ? parse_commits
($head, 17) : ();
4504 git_print_header_div
('shortlog');
4505 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4506 $#commitlist <= 15 ?
undef :
4507 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4511 git_print_header_div
('tags');
4512 git_tags_body
(\
@taglist, 0, 15,
4513 $#taglist <= 15 ?
undef :
4514 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4518 git_print_header_div
('heads');
4519 git_heads_body
(\
@headlist, $head, 0, 15,
4520 $#headlist <= 15 ?
undef :
4521 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4525 git_print_header_div
('forks');
4526 git_project_list_body
(\
@forklist, 'age', 0, 15,
4527 $#forklist <= 15 ?
undef :
4528 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4536 my $head = git_get_head_hash
($project);
4538 git_print_page_nav
('','', $head,undef,$head);
4539 my %tag = parse_tag
($hash);
4542 die_error
(404, "Unknown tag object");
4545 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4546 print "<div class=\"title_text\">\n" .
4547 "<table class=\"object_header\">\n" .
4549 "<td>object</td>\n" .
4550 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4551 $tag{'object'}) . "</td>\n" .
4552 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4553 $tag{'type'}) . "</td>\n" .
4555 if (defined($tag{'author'})) {
4556 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4557 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4558 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4559 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4562 print "</table>\n\n" .
4564 print "<div class=\"page_body\">";
4565 my $comment = $tag{'comment'};
4566 foreach my $line (@
$comment) {
4568 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4578 gitweb_check_feature
('blame')
4579 or die_error
(403, "Blame view not allowed");
4581 die_error
(400, "No file name given") unless $file_name;
4582 $hash_base ||= git_get_head_hash
($project);
4583 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4584 my %co = parse_commit
($hash_base)
4585 or die_error
(404, "Commit not found");
4586 if (!defined $hash) {
4587 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4588 or die_error
(404, "Error looking up file");
4590 $ftype = git_get_type
($hash);
4591 if ($ftype !~ "blob") {
4592 die_error
(400, "Object is not a blob");
4594 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4595 $file_name, $hash_base)
4596 or die_error
(500, "Open git-blame failed");
4599 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4602 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4605 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4607 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4608 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4609 git_print_page_path
($file_name, $ftype, $hash_base);
4610 my @rev_color = (qw(light2 dark2));
4611 my $num_colors = scalar(@rev_color);
4612 my $current_color = 0;
4615 <div class="page_body">
4616 <table class="blame">
4617 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4622 last unless defined $_;
4623 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4624 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4625 if (!exists $metainfo{$full_rev}) {
4626 $metainfo{$full_rev} = {};
4628 my $meta = $metainfo{$full_rev};
4631 if (/^(\S+) (.*)$/) {
4637 my $rev = substr($full_rev, 0, 8);
4638 my $author = $meta->{'author'};
4639 my %date = parse_date
($meta->{'author-time'},
4640 $meta->{'author-tz'});
4641 my $date = $date{'iso-tz'};
4643 $current_color = ++$current_color % $num_colors;
4645 print "<tr class=\"$rev_color[$current_color]\">\n";
4647 print "<td class=\"sha1\"";
4648 print " title=\"". esc_html
($author) . ", $date\"";
4649 print " rowspan=\"$group_size\"" if ($group_size > 1);
4651 print $cgi->a({-href
=> href
(action
=>"commit",
4653 file_name
=>$file_name)},
4657 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4658 or die_error
(500, "Open git-rev-parse failed");
4659 my $parent_commit = <$dd>;
4661 chomp($parent_commit);
4662 my $blamed = href
(action
=> 'blame',
4663 file_name
=> $meta->{'filename'},
4664 hash_base
=> $parent_commit);
4665 print "<td class=\"linenr\">";
4666 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4668 -class => "linenr" },
4671 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4677 or print "Reading blob failed\n";
4682 my $head = git_get_head_hash
($project);
4684 git_print_page_nav
('','', $head,undef,$head);
4685 git_print_header_div
('summary', $project);
4687 my @tagslist = git_get_tags_list
();
4689 git_tags_body
(\
@tagslist);
4695 my $head = git_get_head_hash
($project);
4697 git_print_page_nav
('','', $head,undef,$head);
4698 git_print_header_div
('summary', $project);
4700 my @headslist = git_get_heads_list
();
4702 git_heads_body
(\
@headslist, $head);
4707 sub git_blob_plain
{
4711 if (!defined $hash) {
4712 if (defined $file_name) {
4713 my $base = $hash_base || git_get_head_hash
($project);
4714 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4715 or die_error
(404, "Cannot find file");
4717 die_error
(400, "No file name defined");
4719 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4720 # blobs defined by non-textual hash id's can be cached
4724 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4725 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4727 # content-type (can include charset)
4728 $type = blob_contenttype
($fd, $file_name, $type);
4730 # "save as" filename, even when no $file_name is given
4731 my $save_as = "$hash";
4732 if (defined $file_name) {
4733 $save_as = $file_name;
4734 } elsif ($type =~ m/^text\//) {
4740 -expires
=> $expires,
4741 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4743 binmode STDOUT
, ':raw';
4745 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4753 if (!defined $hash) {
4754 if (defined $file_name) {
4755 my $base = $hash_base || git_get_head_hash
($project);
4756 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4757 or die_error
(404, "Cannot find file");
4759 die_error
(400, "No file name defined");
4761 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4762 # blobs defined by non-textual hash id's can be cached
4766 my $have_blame = gitweb_check_feature
('blame');
4767 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4768 or die_error
(500, "Couldn't cat $file_name, $hash");
4769 my $mimetype = blob_mimetype
($fd, $file_name);
4770 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4772 return git_blob_plain
($mimetype);
4774 # we can have blame only for text/* mimetype
4775 $have_blame &&= ($mimetype =~ m!^text/!);
4777 git_header_html
(undef, $expires);
4778 my $formats_nav = '';
4779 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4780 if (defined $file_name) {
4783 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4788 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4791 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4794 $cgi->a({-href
=> href
(action
=>"blob",
4795 hash_base
=>"HEAD", file_name
=>$file_name)},
4799 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4802 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4803 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4805 print "<div class=\"page_nav\">\n" .
4806 "<br/><br/></div>\n" .
4807 "<div class=\"title\">$hash</div>\n";
4809 git_print_page_path
($file_name, "blob", $hash_base);
4810 print "<div class=\"page_body\">\n";
4811 if ($mimetype =~ m!^image/!) {
4812 print qq!<img type
="$mimetype"!;
4814 print qq! alt
="$file_name" title
="$file_name"!;
4817 href(action=>"blob_plain
", hash=>$hash,
4818 hash_base=>$hash_base, file_name=>$file_name) .
4822 while (my $line = <$fd>) {
4825 $line = untabify
($line);
4826 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4827 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4831 or print "Reading blob failed.\n";
4837 if (!defined $hash_base) {
4838 $hash_base = "HEAD";
4840 if (!defined $hash) {
4841 if (defined $file_name) {
4842 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4847 die_error
(404, "No such tree") unless defined($hash);
4849 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4850 or die_error
(500, "Open git-ls-tree failed");
4851 my @entries = map { chomp; $_ } <$fd>;
4852 close $fd or die_error
(404, "Reading tree failed");
4855 my $refs = git_get_references
();
4856 my $ref = format_ref_marker
($refs, $hash_base);
4859 my $have_blame = gitweb_check_feature
('blame');
4860 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4862 if (defined $file_name) {
4864 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4866 $cgi->a({-href
=> href
(action
=>"tree",
4867 hash_base
=>"HEAD", file_name
=>$file_name)},
4870 my $snapshot_links = format_snapshot_links
($hash);
4871 if (defined $snapshot_links) {
4872 # FIXME: Should be available when we have no hash base as well.
4873 push @views_nav, $snapshot_links;
4875 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4876 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4879 print "<div class=\"page_nav\">\n";
4880 print "<br/><br/></div>\n";
4881 print "<div class=\"title\">$hash</div>\n";
4883 if (defined $file_name) {
4884 $basedir = $file_name;
4885 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4888 git_print_page_path
($file_name, 'tree', $hash_base);
4890 print "<div class=\"page_body\">\n";
4891 print "<table class=\"tree\">\n";
4893 # '..' (top directory) link if possible
4894 if (defined $hash_base &&
4895 defined $file_name && $file_name =~ m![^/]+$!) {
4897 print "<tr class=\"dark\">\n";
4899 print "<tr class=\"light\">\n";
4903 my $up = $file_name;
4904 $up =~ s!/?[^/]+$!!;
4905 undef $up unless $up;
4906 # based on git_print_tree_entry
4907 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4908 print '<td class="list">';
4909 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4913 print "<td class=\"link\"></td>\n";
4917 foreach my $line (@entries) {
4918 my %t = parse_ls_tree_line
($line, -z
=> 1);
4921 print "<tr class=\"dark\">\n";
4923 print "<tr class=\"light\">\n";
4927 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4931 print "</table>\n" .
4937 my $format = $input_params{'snapshot_format'};
4938 if (!@snapshot_fmts) {
4939 die_error
(403, "Snapshots not allowed");
4941 # default to first supported snapshot format
4942 $format ||= $snapshot_fmts[0];
4943 if ($format !~ m/^[a-z0-9]+$/) {
4944 die_error
(400, "Invalid snapshot format parameter");
4945 } elsif (!exists($known_snapshot_formats{$format})) {
4946 die_error
(400, "Unknown snapshot format");
4947 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4948 die_error
(403, "Unsupported snapshot format");
4951 if (!defined $hash) {
4952 $hash = git_get_head_hash
($project);
4955 my $name = $project;
4956 $name =~ s
,([^/])/*\
.git
$,$1,;
4957 $name = basename
($name);
4958 my $filename = to_utf8
($name);
4959 $name =~ s/\047/\047\\\047\047/g;
4961 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4962 $cmd = quote_command
(
4963 git_cmd
(), 'archive',
4964 "--format=$known_snapshot_formats{$format}{'format'}",
4965 "--prefix=$name/", $hash);
4966 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4967 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4971 -type
=> $known_snapshot_formats{$format}{'type'},
4972 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4973 -status
=> '200 OK');
4975 open my $fd, "-|", $cmd
4976 or die_error
(500, "Execute git-archive failed");
4977 binmode STDOUT
, ':raw';
4979 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4984 my $head = git_get_head_hash
($project);
4985 if (!defined $hash) {
4988 if (!defined $page) {
4991 my $refs = git_get_references
();
4993 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4995 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4998 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5001 my %co = parse_commit
($hash);
5003 git_print_header_div
('summary', $project);
5004 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5006 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5007 for (my $i = 0; $i <= $to; $i++) {
5008 my %co = %{$commitlist[$i]};
5010 my $commit = $co{'id'};
5011 my $ref = format_ref_marker
($refs, $commit);
5012 my %ad = parse_date
($co{'author_epoch'});
5013 git_print_header_div
('commit',
5014 "<span class=\"age\">$co{'age_string'}</span>" .
5015 esc_html
($co{'title'}) . $ref,
5017 print "<div class=\"title_text\">\n" .
5018 "<div class=\"log_link\">\n" .
5019 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5021 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5023 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5026 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5029 print "<div class=\"log_body\">\n";
5030 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5033 if ($#commitlist >= 100) {
5034 print "<div class=\"page_nav\">\n";
5035 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5036 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5043 $hash ||= $hash_base || "HEAD";
5044 my %co = parse_commit
($hash)
5045 or die_error
(404, "Unknown commit object");
5046 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5047 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5049 my $parent = $co{'parent'};
5050 my $parents = $co{'parents'}; # listref
5052 # we need to prepare $formats_nav before any parameter munging
5054 if (!defined $parent) {
5056 $formats_nav .= '(initial)';
5057 } elsif (@
$parents == 1) {
5058 # single parent commit
5061 $cgi->a({-href
=> href
(action
=>"commit",
5063 esc_html
(substr($parent, 0, 7))) .
5070 $cgi->a({-href
=> href
(action
=>"commit",
5072 esc_html
(substr($_, 0, 7)));
5077 if (!defined $parent) {
5081 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5083 (@
$parents <= 1 ?
$parent : '-c'),
5085 or die_error
(500, "Open git-diff-tree failed");
5086 @difftree = map { chomp; $_ } <$fd>;
5087 close $fd or die_error
(404, "Reading git-diff-tree failed");
5089 # non-textual hash id's can be cached
5091 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5094 my $refs = git_get_references
();
5095 my $ref = format_ref_marker
($refs, $co{'id'});
5097 git_header_html
(undef, $expires);
5098 git_print_page_nav
('commit', '',
5099 $hash, $co{'tree'}, $hash,
5102 if (defined $co{'parent'}) {
5103 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5105 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5107 print "<div class=\"title_text\">\n" .
5108 "<table class=\"object_header\">\n";
5109 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5111 "<td></td><td> $ad{'rfc2822'}";
5112 if ($ad{'hour_local'} < 6) {
5113 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5114 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5116 printf(" (%02d:%02d %s)",
5117 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5121 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5122 print "<tr><td></td><td> $cd{'rfc2822'}" .
5123 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5125 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5128 "<td class=\"sha1\">" .
5129 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5130 class => "list"}, $co{'tree'}) .
5132 "<td class=\"link\">" .
5133 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5135 my $snapshot_links = format_snapshot_links
($hash);
5136 if (defined $snapshot_links) {
5137 print " | " . $snapshot_links;
5142 foreach my $par (@
$parents) {
5145 "<td class=\"sha1\">" .
5146 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5147 class => "list"}, $par) .
5149 "<td class=\"link\">" .
5150 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5152 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5159 print "<div class=\"page_body\">\n";
5160 git_print_log
($co{'comment'});
5163 git_difftree_body
(\
@difftree, $hash, @
$parents);
5169 # object is defined by:
5170 # - hash or hash_base alone
5171 # - hash_base and file_name
5174 # - hash or hash_base alone
5175 if ($hash || ($hash_base && !defined $file_name)) {
5176 my $object_id = $hash || $hash_base;
5178 open my $fd, "-|", quote_command
(
5179 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5180 or die_error
(404, "Object does not exist");
5184 or die_error
(404, "Object does not exist");
5186 # - hash_base and file_name
5187 } elsif ($hash_base && defined $file_name) {
5188 $file_name =~ s
,/+$,,;
5190 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5191 or die_error
(404, "Base object does not exist");
5193 # here errors should not hapen
5194 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5195 or die_error
(500, "Open git-ls-tree failed");
5199 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5200 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5201 die_error
(404, "File or directory for given base does not exist");
5206 die_error
(400, "Not enough information to find object");
5209 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5210 hash
=>$hash, hash_base
=>$hash_base,
5211 file_name
=>$file_name),
5212 -status
=> '302 Found');
5216 my $format = shift || 'html';
5223 # preparing $fd and %diffinfo for git_patchset_body
5225 if (defined $hash_base && defined $hash_parent_base) {
5226 if (defined $file_name) {
5228 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5229 $hash_parent_base, $hash_base,
5230 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5231 or die_error
(500, "Open git-diff-tree failed");
5232 @difftree = map { chomp; $_ } <$fd>;
5234 or die_error
(404, "Reading git-diff-tree failed");
5236 or die_error
(404, "Blob diff not found");
5238 } elsif (defined $hash &&
5239 $hash =~ /[0-9a-fA-F]{40}/) {
5240 # try to find filename from $hash
5242 # read filtered raw output
5243 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5244 $hash_parent_base, $hash_base, "--"
5245 or die_error
(500, "Open git-diff-tree failed");
5247 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5249 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5250 map { chomp; $_ } <$fd>;
5252 or die_error
(404, "Reading git-diff-tree failed");
5254 or die_error
(404, "Blob diff not found");
5257 die_error
(400, "Missing one of the blob diff parameters");
5260 if (@difftree > 1) {
5261 die_error
(400, "Ambiguous blob diff specification");
5264 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5265 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5266 $file_name ||= $diffinfo{'to_file'};
5268 $hash_parent ||= $diffinfo{'from_id'};
5269 $hash ||= $diffinfo{'to_id'};
5271 # non-textual hash id's can be cached
5272 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5273 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5278 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5279 '-p', ($format eq 'html' ?
"--full-index" : ()),
5280 $hash_parent_base, $hash_base,
5281 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5282 or die_error
(500, "Open git-diff-tree failed");
5285 # old/legacy style URI
5286 if (!%diffinfo && # if new style URI failed
5287 defined $hash && defined $hash_parent) {
5288 # fake git-diff-tree raw output
5289 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5290 $diffinfo{'from_id'} = $hash_parent;
5291 $diffinfo{'to_id'} = $hash;
5292 if (defined $file_name) {
5293 if (defined $file_parent) {
5294 $diffinfo{'status'} = '2';
5295 $diffinfo{'from_file'} = $file_parent;
5296 $diffinfo{'to_file'} = $file_name;
5297 } else { # assume not renamed
5298 $diffinfo{'status'} = '1';
5299 $diffinfo{'from_file'} = $file_name;
5300 $diffinfo{'to_file'} = $file_name;
5302 } else { # no filename given
5303 $diffinfo{'status'} = '2';
5304 $diffinfo{'from_file'} = $hash_parent;
5305 $diffinfo{'to_file'} = $hash;
5308 # non-textual hash id's can be cached
5309 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5310 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5315 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5316 '-p', ($format eq 'html' ?
"--full-index" : ()),
5317 $hash_parent, $hash, "--"
5318 or die_error
(500, "Open git-diff failed");
5320 die_error
(400, "Missing one of the blob diff parameters")
5325 if ($format eq 'html') {
5327 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5329 git_header_html
(undef, $expires);
5330 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5331 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5332 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5334 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5335 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5337 if (defined $file_name) {
5338 git_print_page_path
($file_name, "blob", $hash_base);
5340 print "<div class=\"page_path\"></div>\n";
5343 } elsif ($format eq 'plain') {
5345 -type
=> 'text/plain',
5346 -charset
=> 'utf-8',
5347 -expires
=> $expires,
5348 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5350 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5353 die_error
(400, "Unknown blobdiff format");
5357 if ($format eq 'html') {
5358 print "<div class=\"page_body\">\n";
5360 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5363 print "</div>\n"; # class="page_body"
5367 while (my $line = <$fd>) {
5368 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5369 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5373 last if $line =~ m!^\+\+\+!;
5381 sub git_blobdiff_plain
{
5382 git_blobdiff
('plain');
5385 sub git_commitdiff
{
5386 my $format = shift || 'html';
5387 $hash ||= $hash_base || "HEAD";
5388 my %co = parse_commit
($hash)
5389 or die_error
(404, "Unknown commit object");
5391 # choose format for commitdiff for merge
5392 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5393 $hash_parent = '--cc';
5395 # we need to prepare $formats_nav before almost any parameter munging
5397 if ($format eq 'html') {
5399 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5402 if (defined $hash_parent &&
5403 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5404 # commitdiff with two commits given
5405 my $hash_parent_short = $hash_parent;
5406 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5407 $hash_parent_short = substr($hash_parent, 0, 7);
5411 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5412 if ($co{'parents'}[$i] eq $hash_parent) {
5413 $formats_nav .= ' parent ' . ($i+1);
5417 $formats_nav .= ': ' .
5418 $cgi->a({-href
=> href
(action
=>"commitdiff",
5419 hash
=>$hash_parent)},
5420 esc_html
($hash_parent_short)) .
5422 } elsif (!$co{'parent'}) {
5424 $formats_nav .= ' (initial)';
5425 } elsif (scalar @
{$co{'parents'}} == 1) {
5426 # single parent commit
5429 $cgi->a({-href
=> href
(action
=>"commitdiff",
5430 hash
=>$co{'parent'})},
5431 esc_html
(substr($co{'parent'}, 0, 7))) .
5435 if ($hash_parent eq '--cc') {
5436 $formats_nav .= ' | ' .
5437 $cgi->a({-href
=> href
(action
=>"commitdiff",
5438 hash
=>$hash, hash_parent
=>'-c')},
5440 } else { # $hash_parent eq '-c'
5441 $formats_nav .= ' | ' .
5442 $cgi->a({-href
=> href
(action
=>"commitdiff",
5443 hash
=>$hash, hash_parent
=>'--cc')},
5449 $cgi->a({-href
=> href
(action
=>"commitdiff",
5451 esc_html
(substr($_, 0, 7)));
5452 } @
{$co{'parents'}} ) .
5457 my $hash_parent_param = $hash_parent;
5458 if (!defined $hash_parent_param) {
5459 # --cc for multiple parents, --root for parentless
5460 $hash_parent_param =
5461 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5467 if ($format eq 'html') {
5468 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5469 "--no-commit-id", "--patch-with-raw", "--full-index",
5470 $hash_parent_param, $hash, "--"
5471 or die_error
(500, "Open git-diff-tree failed");
5473 while (my $line = <$fd>) {
5475 # empty line ends raw part of diff-tree output
5477 push @difftree, scalar parse_difftree_raw_line
($line);
5480 } elsif ($format eq 'plain') {
5481 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5482 '-p', $hash_parent_param, $hash, "--"
5483 or die_error
(500, "Open git-diff-tree failed");
5486 die_error
(400, "Unknown commitdiff format");
5489 # non-textual hash id's can be cached
5491 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5495 # write commit message
5496 if ($format eq 'html') {
5497 my $refs = git_get_references
();
5498 my $ref = format_ref_marker
($refs, $co{'id'});
5500 git_header_html
(undef, $expires);
5501 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5502 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5503 git_print_authorship
(\
%co);
5504 print "<div class=\"page_body\">\n";
5505 if (@
{$co{'comment'}} > 1) {
5506 print "<div class=\"log\">\n";
5507 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5508 print "</div>\n"; # class="log"
5511 } elsif ($format eq 'plain') {
5512 my $refs = git_get_references
("tags");
5513 my $tagname = git_get_rev_name_tags
($hash);
5514 my $filename = basename
($project) . "-$hash.patch";
5517 -type
=> 'text/plain',
5518 -charset
=> 'utf-8',
5519 -expires
=> $expires,
5520 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5521 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5522 print "From: " . to_utf8
($co{'author'}) . "\n";
5523 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5524 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5526 print "X-Git-Tag: $tagname\n" if $tagname;
5527 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5529 foreach my $line (@
{$co{'comment'}}) {
5530 print to_utf8
($line) . "\n";
5536 if ($format eq 'html') {
5537 my $use_parents = !defined $hash_parent ||
5538 $hash_parent eq '-c' || $hash_parent eq '--cc';
5539 git_difftree_body
(\
@difftree, $hash,
5540 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5543 git_patchset_body
($fd, \
@difftree, $hash,
5544 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5546 print "</div>\n"; # class="page_body"
5549 } elsif ($format eq 'plain') {
5553 or print "Reading git-diff-tree failed\n";
5557 sub git_commitdiff_plain
{
5558 git_commitdiff
('plain');
5562 if (!defined $hash_base) {
5563 $hash_base = git_get_head_hash
($project);
5565 if (!defined $page) {
5569 my %co = parse_commit
($hash_base)
5570 or die_error
(404, "Unknown commit object");
5572 my $refs = git_get_references
();
5573 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5575 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5576 $file_name, "--full-history")
5577 or die_error
(404, "No such file or directory on given branch");
5579 if (!defined $hash && defined $file_name) {
5580 # some commits could have deleted file in question,
5581 # and not have it in tree, but one of them has to have it
5582 for (my $i = 0; $i <= @commitlist; $i++) {
5583 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5584 last if defined $hash;
5587 if (defined $hash) {
5588 $ftype = git_get_type
($hash);
5590 if (!defined $ftype) {
5591 die_error
(500, "Unknown type of object");
5594 my $paging_nav = '';
5597 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5598 file_name
=>$file_name)},
5600 $paging_nav .= " ⋅ " .
5601 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5602 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5604 $paging_nav .= "first";
5605 $paging_nav .= " ⋅ prev";
5608 if ($#commitlist >= 100) {
5610 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5611 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5612 $paging_nav .= " ⋅ $next_link";
5614 $paging_nav .= " ⋅ next";
5618 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5619 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5620 git_print_page_path
($file_name, $ftype, $hash_base);
5622 git_history_body
(\
@commitlist, 0, 99,
5623 $refs, $hash_base, $ftype, $next_link);
5629 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5630 if (!defined $searchtext) {
5631 die_error
(400, "Text field is empty");
5633 if (!defined $hash) {
5634 $hash = git_get_head_hash
($project);
5636 my %co = parse_commit
($hash);
5638 die_error
(404, "Unknown commit object");
5640 if (!defined $page) {
5644 $searchtype ||= 'commit';
5645 if ($searchtype eq 'pickaxe') {
5646 # pickaxe may take all resources of your box and run for several minutes
5647 # with every query - so decide by yourself how public you make this feature
5648 gitweb_check_feature
('pickaxe')
5649 or die_error
(403, "Pickaxe is disabled");
5651 if ($searchtype eq 'grep') {
5652 gitweb_check_feature
('grep')
5653 or die_error
(403, "Grep is disabled");
5658 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5660 if ($searchtype eq 'commit') {
5661 $greptype = "--grep=";
5662 } elsif ($searchtype eq 'author') {
5663 $greptype = "--author=";
5664 } elsif ($searchtype eq 'committer') {
5665 $greptype = "--committer=";
5667 $greptype .= $searchtext;
5668 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5669 $greptype, '--regexp-ignore-case',
5670 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5672 my $paging_nav = '';
5675 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5676 searchtext
=>$searchtext,
5677 searchtype
=>$searchtype)},
5679 $paging_nav .= " ⋅ " .
5680 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5681 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5683 $paging_nav .= "first";
5684 $paging_nav .= " ⋅ prev";
5687 if ($#commitlist >= 100) {
5689 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5690 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5691 $paging_nav .= " ⋅ $next_link";
5693 $paging_nav .= " ⋅ next";
5696 if ($#commitlist >= 100) {
5699 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5700 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5701 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5704 if ($searchtype eq 'pickaxe') {
5705 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5706 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5708 print "<table class=\"pickaxe search\">\n";
5711 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5712 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5713 ($search_use_regexp ?
'--pickaxe-regex' : ());
5716 while (my $line = <$fd>) {
5720 my %set = parse_difftree_raw_line
($line);
5721 if (defined $set{'commit'}) {
5722 # finish previous commit
5725 "<td class=\"link\">" .
5726 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5728 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5734 print "<tr class=\"dark\">\n";
5736 print "<tr class=\"light\">\n";
5739 %co = parse_commit
($set{'commit'});
5740 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5741 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5742 "<td><i>$author</i></td>\n" .
5744 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5745 -class => "list subject"},
5746 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5747 } elsif (defined $set{'to_id'}) {
5748 next if ($set{'to_id'} =~ m/^0{40}$/);
5750 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5751 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5753 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5759 # finish last commit (warning: repetition!)
5762 "<td class=\"link\">" .
5763 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5765 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5773 if ($searchtype eq 'grep') {
5774 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5775 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5777 print "<table class=\"grep_search\">\n";
5781 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5782 $search_use_regexp ?
('-E', '-i') : '-F',
5783 $searchtext, $co{'tree'};
5785 while (my $line = <$fd>) {
5787 my ($file, $lno, $ltext, $binary);
5788 last if ($matches++ > 1000);
5789 if ($line =~ /^Binary file (.+) matches$/) {
5793 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5795 if ($file ne $lastfile) {
5796 $lastfile and print "</td></tr>\n";
5798 print "<tr class=\"dark\">\n";
5800 print "<tr class=\"light\">\n";
5802 print "<td class=\"list\">".
5803 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5804 file_name
=>"$file"),
5805 -class => "list"}, esc_path
($file));
5806 print "</td><td>\n";
5810 print "<div class=\"binary\">Binary file</div>\n";
5812 $ltext = untabify
($ltext);
5813 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5814 $ltext = esc_html
($1, -nbsp
=>1);
5815 $ltext .= '<span class="match">';
5816 $ltext .= esc_html
($2, -nbsp
=>1);
5817 $ltext .= '</span>';
5818 $ltext .= esc_html
($3, -nbsp
=>1);
5820 $ltext = esc_html
($ltext, -nbsp
=>1);
5822 print "<div class=\"pre\">" .
5823 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5824 file_name
=>"$file").'#l'.$lno,
5825 -class => "linenr"}, sprintf('%4i', $lno))
5826 . ' ' . $ltext . "</div>\n";
5830 print "</td></tr>\n";
5831 if ($matches > 1000) {
5832 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5835 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5844 sub git_search_help
{
5846 git_print_page_nav
('','', $hash,$hash,$hash);
5848 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5849 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5850 the pattern entered is recognized as the POSIX extended
5851 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5854 <dt><b>commit</b></dt>
5855 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5857 my $have_grep = gitweb_check_feature
('grep');
5860 <dt><b>grep</b></dt>
5861 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5862 a different one) are searched for the given pattern. On large trees, this search can take
5863 a while and put some strain on the server, so please use it with some consideration. Note that
5864 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5865 case-sensitive.</dd>
5869 <dt><b>author</b></dt>
5870 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5871 <dt><b>committer</b></dt>
5872 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5874 my $have_pickaxe = gitweb_check_feature
('pickaxe');
5875 if ($have_pickaxe) {
5877 <dt><b>pickaxe</b></dt>
5878 <dd>All commits that caused the string to appear or disappear from any file (changes that
5879 added, removed or "modified" the string) will be listed. This search can take a while and
5880 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5881 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5889 my $head = git_get_head_hash
($project);
5890 if (!defined $hash) {
5893 if (!defined $page) {
5896 my $refs = git_get_references
();
5898 my $commit_hash = $hash;
5899 if (defined $hash_parent) {
5900 $commit_hash = "$hash_parent..$hash";
5902 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5904 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5906 if ($#commitlist >= 100) {
5908 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5909 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5913 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5914 git_print_header_div
('summary', $project);
5916 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5921 ## ......................................................................
5922 ## feeds (RSS, Atom; OPML)
5925 my $format = shift || 'atom';
5926 my $have_blame = gitweb_check_feature
('blame');
5928 # Atom: http://www.atomenabled.org/developers/syndication/
5929 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5930 if ($format ne 'rss' && $format ne 'atom') {
5931 die_error
(400, "Unknown web feed format");
5934 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5935 my $head = $hash || 'HEAD';
5936 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5940 my $content_type = "application/$format+xml";
5941 if (defined $cgi->http('HTTP_ACCEPT') &&
5942 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5943 # browser (feed reader) prefers text/xml
5944 $content_type = 'text/xml';
5946 if (defined($commitlist[0])) {
5947 %latest_commit = %{$commitlist[0]};
5948 %latest_date = parse_date
($latest_commit{'author_epoch'});
5950 -type
=> $content_type,
5951 -charset
=> 'utf-8',
5952 -last_modified
=> $latest_date{'rfc2822'});
5955 -type
=> $content_type,
5956 -charset
=> 'utf-8');
5959 # Optimization: skip generating the body if client asks only
5960 # for Last-Modified date.
5961 return if ($cgi->request_method() eq 'HEAD');
5964 my $title = "$site_name - $project/$action";
5965 my $feed_type = 'log';
5966 if (defined $hash) {
5967 $title .= " - '$hash'";
5968 $feed_type = 'branch log';
5969 if (defined $file_name) {
5970 $title .= " :: $file_name";
5971 $feed_type = 'history';
5973 } elsif (defined $file_name) {
5974 $title .= " - $file_name";
5975 $feed_type = 'history';
5977 $title .= " $feed_type";
5978 my $descr = git_get_project_description
($project);
5979 if (defined $descr) {
5980 $descr = esc_html
($descr);
5982 $descr = "$project " .
5983 ($format eq 'rss' ?
'RSS' : 'Atom') .
5986 my $owner = git_get_project_owner
($project);
5987 $owner = esc_html
($owner);
5991 if (defined $file_name) {
5992 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5993 } elsif (defined $hash) {
5994 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5996 $alt_url = href
(-full
=>1, action
=>"summary");
5998 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5999 if ($format eq 'rss') {
6001 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6004 print "<title>$title</title>\n" .
6005 "<link>$alt_url</link>\n" .
6006 "<description>$descr</description>\n" .
6007 "<language>en</language>\n";
6008 } elsif ($format eq 'atom') {
6010 <feed xmlns="http://www.w3.org/2005/Atom">
6012 print "<title>$title</title>\n" .
6013 "<subtitle>$descr</subtitle>\n" .
6014 '<link rel="alternate" type="text/html" href="' .
6015 $alt_url . '" />' . "\n" .
6016 '<link rel="self" type="' . $content_type . '" href="' .
6017 $cgi->self_url() . '" />' . "\n" .
6018 "<id>" . href
(-full
=>1) . "</id>\n" .
6019 # use project owner for feed author
6020 "<author><name>$owner</name></author>\n";
6021 if (defined $favicon) {
6022 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6024 if (defined $logo_url) {
6025 # not twice as wide as tall: 72 x 27 pixels
6026 print "<logo>" . esc_url
($logo) . "</logo>\n";
6028 if (! %latest_date) {
6029 # dummy date to keep the feed valid until commits trickle in:
6030 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6032 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6037 for (my $i = 0; $i <= $#commitlist; $i++) {
6038 my %co = %{$commitlist[$i]};
6039 my $commit = $co{'id'};
6040 # we read 150, we always show 30 and the ones more recent than 48 hours
6041 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6044 my %cd = parse_date
($co{'author_epoch'});
6046 # get list of changed files
6047 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6048 $co{'parent'} || "--root",
6049 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6051 my @difftree = map { chomp; $_ } <$fd>;
6055 # print element (entry, item)
6056 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6057 if ($format eq 'rss') {
6059 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6060 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6061 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6062 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6063 "<link>$co_url</link>\n" .
6064 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6065 "<content:encoded>" .
6067 } elsif ($format eq 'atom') {
6069 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6070 "<updated>$cd{'iso-8601'}</updated>\n" .
6072 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6073 if ($co{'author_email'}) {
6074 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6076 print "</author>\n" .
6077 # use committer for contributor
6079 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6080 if ($co{'committer_email'}) {
6081 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6083 print "</contributor>\n" .
6084 "<published>$cd{'iso-8601'}</published>\n" .
6085 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6086 "<id>$co_url</id>\n" .
6087 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6088 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6090 my $comment = $co{'comment'};
6092 foreach my $line (@
$comment) {
6093 $line = esc_html
($line);
6096 print "</pre><ul>\n";
6097 foreach my $difftree_line (@difftree) {
6098 my %difftree = parse_difftree_raw_line
($difftree_line);
6099 next if !$difftree{'from_id'};
6101 my $file = $difftree{'file'} || $difftree{'to_file'};
6105 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6106 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6107 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6108 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6109 -title
=> "diff"}, 'D');
6111 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6112 file_name
=>$file, hash_base
=>$commit),
6113 -title
=> "blame"}, 'B');
6115 # if this is not a feed of a file history
6116 if (!defined $file_name || $file_name ne $file) {
6117 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6118 file_name
=>$file, hash
=>$commit),
6119 -title
=> "history"}, 'H');
6121 $file = esc_path
($file);
6125 if ($format eq 'rss') {
6126 print "</ul>]]>\n" .
6127 "</content:encoded>\n" .
6129 } elsif ($format eq 'atom') {
6130 print "</ul>\n</div>\n" .
6137 if ($format eq 'rss') {
6138 print "</channel>\n</rss>\n";
6139 } elsif ($format eq 'atom') {
6153 my @list = git_get_projects_list
();
6155 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6157 <?xml version="1.0" encoding="utf-8"?>
6158 <opml version="1.0">
6160 <title>$site_name OPML Export</title>
6163 <outline text="git RSS feeds">
6166 foreach my $pr (@list) {
6168 my $head = git_get_head_hash
($proj{'path'});
6169 if (!defined $head) {
6172 $git_dir = "$projectroot/$proj{'path'}";
6173 my %co = parse_commit
($head);
6178 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6179 my $rss = "$my_url?p=$proj{'path'};a=rss";
6180 my $html = "$my_url?p=$proj{'path'};a=summary";
6181 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";