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_check_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);
348 my ($val) = git_get_project_config
('blame', '--bool');
350 if ($val eq 'true') {
352 } elsif ($val eq 'false') {
359 sub feature_snapshot
{
362 my ($val) = git_get_project_config
('snapshot');
365 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
372 my ($val) = git_get_project_config
('grep', '--bool');
374 if ($val eq 'true') {
376 } elsif ($val eq 'false') {
383 sub feature_pickaxe
{
384 my ($val) = git_get_project_config
('pickaxe', '--bool');
386 if ($val eq 'true') {
388 } elsif ($val eq 'false') {
395 # checking HEAD file with -e is fragile if the repository was
396 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
398 sub check_head_link
{
400 my $headfile = "$dir/HEAD";
401 return ((-e
$headfile) ||
402 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
405 sub check_export_ok
{
407 return (check_head_link
($dir) &&
408 (!$export_ok || -e
"$dir/$export_ok") &&
409 (!$export_auth_hook || $export_auth_hook->($dir)));
412 # process alternate names for backward compatibility
413 # filter out unsupported (unknown) snapshot formats
414 sub filter_snapshot_fmts
{
418 exists $known_snapshot_format_aliases{$_} ?
419 $known_snapshot_format_aliases{$_} : $_} @fmts;
420 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
424 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
425 if (-e
$GITWEB_CONFIG) {
428 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
429 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
432 # version of the core git binary
433 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
435 $projects_list ||= $projectroot;
437 # ======================================================================
438 # input validation and dispatch
440 # input parameters can be collected from a variety of sources (presently, CGI
441 # and PATH_INFO), so we define an %input_params hash that collects them all
442 # together during validation: this allows subsequent uses (e.g. href()) to be
443 # agnostic of the parameter origin
445 our %input_params = ();
447 # input parameters are stored with the long parameter name as key. This will
448 # also be used in the href subroutine to convert parameters to their CGI
449 # equivalent, and since the href() usage is the most frequent one, we store
450 # the name -> CGI key mapping here, instead of the reverse.
452 # XXX: Warning: If you touch this, check the search form for updating,
455 our @cgi_param_mapping = (
463 hash_parent_base
=> "hpb",
468 snapshot_format
=> "sf",
469 extra_options
=> "opt",
470 search_use_regexp
=> "sr",
472 our %cgi_param_mapping = @cgi_param_mapping;
474 # we will also need to know the possible actions, for validation
476 "blame" => \
&git_blame
,
477 "blobdiff" => \
&git_blobdiff
,
478 "blobdiff_plain" => \
&git_blobdiff_plain
,
479 "blob" => \
&git_blob
,
480 "blob_plain" => \
&git_blob_plain
,
481 "commitdiff" => \
&git_commitdiff
,
482 "commitdiff_plain" => \
&git_commitdiff_plain
,
483 "commit" => \
&git_commit
,
484 "forks" => \
&git_forks
,
485 "heads" => \
&git_heads
,
486 "history" => \
&git_history
,
489 "atom" => \
&git_atom
,
490 "search" => \
&git_search
,
491 "search_help" => \
&git_search_help
,
492 "shortlog" => \
&git_shortlog
,
493 "summary" => \
&git_summary
,
495 "tags" => \
&git_tags
,
496 "tree" => \
&git_tree
,
497 "snapshot" => \
&git_snapshot
,
498 "object" => \
&git_object
,
499 # those below don't need $project
500 "opml" => \
&git_opml
,
501 "project_list" => \
&git_project_list
,
502 "project_index" => \
&git_project_index
,
505 # finally, we have the hash of allowed extra_options for the commands that
507 our %allowed_options = (
508 "--no-merges" => [ qw(rss atom log shortlog history) ],
511 # fill %input_params with the CGI parameters. All values except for 'opt'
512 # should be single values, but opt can be an array. We should probably
513 # build an array of parameters that can be multi-valued, but since for the time
514 # being it's only this one, we just single it out
515 while (my ($name, $symbol) = each %cgi_param_mapping) {
516 if ($symbol eq 'opt') {
517 $input_params{$name} = [ $cgi->param($symbol) ];
519 $input_params{$name} = $cgi->param($symbol);
523 # now read PATH_INFO and update the parameter list for missing parameters
524 sub evaluate_path_info
{
525 return if defined $input_params{'project'};
526 return if !$path_info;
527 $path_info =~ s
,^/+,,;
528 return if !$path_info;
530 # find which part of PATH_INFO is project
531 my $project = $path_info;
533 while ($project && !check_head_link
("$projectroot/$project")) {
534 $project =~ s
,/*[^/]*$,,;
536 return unless $project;
537 $input_params{'project'} = $project;
539 # do not change any parameters if an action is given using the query string
540 return if $input_params{'action'};
541 $path_info =~ s
,^\Q
$project\E
/*,,;
543 # next, check if we have an action
544 my $action = $path_info;
546 if (exists $actions{$action}) {
547 $path_info =~ s
,^$action/*,,;
548 $input_params{'action'} = $action;
551 # list of actions that want hash_base instead of hash, but can have no
552 # pathname (f) parameter
559 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
560 my ($parentrefname, $parentpathname, $refname, $pathname) =
561 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
563 # first, analyze the 'current' part
564 if (defined $pathname) {
565 # we got "branch:filename" or "branch:dir/"
566 # we could use git_get_type(branch:pathname), but:
567 # - it needs $git_dir
568 # - it does a git() call
569 # - the convention of terminating directories with a slash
570 # makes it superfluous
571 # - embedding the action in the PATH_INFO would make it even
573 $pathname =~ s
,^/+,,;
574 if (!$pathname || substr($pathname, -1) eq "/") {
575 $input_params{'action'} ||= "tree";
578 # the default action depends on whether we had parent info
580 if ($parentrefname) {
581 $input_params{'action'} ||= "blobdiff_plain";
583 $input_params{'action'} ||= "blob_plain";
586 $input_params{'hash_base'} ||= $refname;
587 $input_params{'file_name'} ||= $pathname;
588 } elsif (defined $refname) {
589 # we got "branch". In this case we have to choose if we have to
590 # set hash or hash_base.
592 # Most of the actions without a pathname only want hash to be
593 # set, except for the ones specified in @wants_base that want
594 # hash_base instead. It should also be noted that hand-crafted
595 # links having 'history' as an action and no pathname or hash
596 # set will fail, but that happens regardless of PATH_INFO.
597 $input_params{'action'} ||= "shortlog";
598 if (grep { $_ eq $input_params{'action'} } @wants_base) {
599 $input_params{'hash_base'} ||= $refname;
601 $input_params{'hash'} ||= $refname;
605 # next, handle the 'parent' part, if present
606 if (defined $parentrefname) {
607 # a missing pathspec defaults to the 'current' filename, allowing e.g.
608 # someproject/blobdiff/oldrev..newrev:/filename
609 if ($parentpathname) {
610 $parentpathname =~ s
,^/+,,;
611 $parentpathname =~ s
,/$,,;
612 $input_params{'file_parent'} ||= $parentpathname;
614 $input_params{'file_parent'} ||= $input_params{'file_name'};
616 # we assume that hash_parent_base is wanted if a path was specified,
617 # or if the action wants hash_base instead of hash
618 if (defined $input_params{'file_parent'} ||
619 grep { $_ eq $input_params{'action'} } @wants_base) {
620 $input_params{'hash_parent_base'} ||= $parentrefname;
622 $input_params{'hash_parent'} ||= $parentrefname;
626 # for the snapshot action, we allow URLs in the form
627 # $project/snapshot/$hash.ext
628 # where .ext determines the snapshot and gets removed from the
629 # passed $refname to provide the $hash.
631 # To be able to tell that $refname includes the format extension, we
632 # require the following two conditions to be satisfied:
633 # - the hash input parameter MUST have been set from the $refname part
634 # of the URL (i.e. they must be equal)
635 # - the snapshot format MUST NOT have been defined already (e.g. from
637 # It's also useless to try any matching unless $refname has a dot,
638 # so we check for that too
639 if (defined $input_params{'action'} &&
640 $input_params{'action'} eq 'snapshot' &&
641 defined $refname && index($refname, '.') != -1 &&
642 $refname eq $input_params{'hash'} &&
643 !defined $input_params{'snapshot_format'}) {
644 # We loop over the known snapshot formats, checking for
645 # extensions. Allowed extensions are both the defined suffix
646 # (which includes the initial dot already) and the snapshot
647 # format key itself, with a prepended dot
648 while (my ($fmt, %opt) = each %known_snapshot_formats) {
651 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
652 next unless $sfx = $1;
653 # a valid suffix was found, so set the snapshot format
654 # and reset the hash parameter
655 $input_params{'snapshot_format'} = $fmt;
656 $input_params{'hash'} = $hash;
657 # we also set the format suffix to the one requested
658 # in the URL: this way a request for e.g. .tgz returns
659 # a .tgz instead of a .tar.gz
660 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
665 evaluate_path_info
();
667 our $action = $input_params{'action'};
668 if (defined $action) {
669 if (!validate_action
($action)) {
670 die_error
(400, "Invalid action parameter");
674 # parameters which are pathnames
675 our $project = $input_params{'project'};
676 if (defined $project) {
677 if (!validate_project
($project)) {
679 die_error
(404, "No such project");
683 our $file_name = $input_params{'file_name'};
684 if (defined $file_name) {
685 if (!validate_pathname
($file_name)) {
686 die_error
(400, "Invalid file parameter");
690 our $file_parent = $input_params{'file_parent'};
691 if (defined $file_parent) {
692 if (!validate_pathname
($file_parent)) {
693 die_error
(400, "Invalid file parent parameter");
697 # parameters which are refnames
698 our $hash = $input_params{'hash'};
700 if (!validate_refname
($hash)) {
701 die_error
(400, "Invalid hash parameter");
705 our $hash_parent = $input_params{'hash_parent'};
706 if (defined $hash_parent) {
707 if (!validate_refname
($hash_parent)) {
708 die_error
(400, "Invalid hash parent parameter");
712 our $hash_base = $input_params{'hash_base'};
713 if (defined $hash_base) {
714 if (!validate_refname
($hash_base)) {
715 die_error
(400, "Invalid hash base parameter");
719 our @extra_options = @
{$input_params{'extra_options'}};
720 # @extra_options is always defined, since it can only be (currently) set from
721 # CGI, and $cgi->param() returns the empty array in array context if the param
723 foreach my $opt (@extra_options) {
724 if (not exists $allowed_options{$opt}) {
725 die_error
(400, "Invalid option parameter");
727 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
728 die_error
(400, "Invalid option parameter for this action");
732 our $hash_parent_base = $input_params{'hash_parent_base'};
733 if (defined $hash_parent_base) {
734 if (!validate_refname
($hash_parent_base)) {
735 die_error
(400, "Invalid hash parent base parameter");
740 our $page = $input_params{'page'};
742 if ($page =~ m/[^0-9]/) {
743 die_error
(400, "Invalid page parameter");
747 our $searchtype = $input_params{'searchtype'};
748 if (defined $searchtype) {
749 if ($searchtype =~ m/[^a-z]/) {
750 die_error
(400, "Invalid searchtype parameter");
754 our $search_use_regexp = $input_params{'search_use_regexp'};
756 our $searchtext = $input_params{'searchtext'};
758 if (defined $searchtext) {
759 if (length($searchtext) < 2) {
760 die_error
(403, "At least two characters are required for search parameter");
762 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
765 # path to the current git repository
767 $git_dir = "$projectroot/$project" if $project;
769 # list of supported snapshot formats
770 our @snapshot_fmts = gitweb_check_feature
('snapshot');
771 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
774 if (!defined $action) {
776 $action = git_get_type
($hash);
777 } elsif (defined $hash_base && defined $file_name) {
778 $action = git_get_type
("$hash_base:$file_name");
779 } elsif (defined $project) {
782 $action = 'project_list';
785 if (!defined($actions{$action})) {
786 die_error
(400, "Unknown action");
788 if ($action !~ m/^(opml|project_list|project_index)$/ &&
790 die_error
(400, "Project needed");
792 $actions{$action}->();
795 ## ======================================================================
800 # default is to use -absolute url() i.e. $my_uri
801 my $href = $params{-full
} ?
$my_url : $my_uri;
803 $params{'project'} = $project unless exists $params{'project'};
805 if ($params{-replay
}) {
806 while (my ($name, $symbol) = each %cgi_param_mapping) {
807 if (!exists $params{$name}) {
808 $params{$name} = $input_params{$name};
813 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
815 # try to put as many parameters as possible in PATH_INFO:
818 # - hash_parent or hash_parent_base:/file_parent
819 # - hash or hash_base:/filename
820 # - the snapshot_format as an appropriate suffix
822 # When the script is the root DirectoryIndex for the domain,
823 # $href here would be something like http://gitweb.example.com/
824 # Thus, we strip any trailing / from $href, to spare us double
825 # slashes in the final URL
828 # Then add the project name, if present
829 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
830 delete $params{'project'};
832 # since we destructively absorb parameters, we keep this
833 # boolean that remembers if we're handling a snapshot
834 my $is_snapshot = $params{'action'} eq 'snapshot';
836 # Summary just uses the project path URL, any other action is
838 if (defined $params{'action'}) {
839 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
840 delete $params{'action'};
843 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
844 # stripping nonexistent or useless pieces
845 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
846 || $params{'hash_parent'} || $params{'hash'});
847 if (defined $params{'hash_base'}) {
848 if (defined $params{'hash_parent_base'}) {
849 $href .= esc_url
($params{'hash_parent_base'});
850 # skip the file_parent if it's the same as the file_name
851 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
852 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
853 $href .= ":/".esc_url
($params{'file_parent'});
854 delete $params{'file_parent'};
857 delete $params{'hash_parent'};
858 delete $params{'hash_parent_base'};
859 } elsif (defined $params{'hash_parent'}) {
860 $href .= esc_url
($params{'hash_parent'}). "..";
861 delete $params{'hash_parent'};
864 $href .= esc_url
($params{'hash_base'});
865 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
866 $href .= ":/".esc_url
($params{'file_name'});
867 delete $params{'file_name'};
869 delete $params{'hash'};
870 delete $params{'hash_base'};
871 } elsif (defined $params{'hash'}) {
872 $href .= esc_url
($params{'hash'});
873 delete $params{'hash'};
876 # If the action was a snapshot, we can absorb the
877 # snapshot_format parameter too
879 my $fmt = $params{'snapshot_format'};
880 # snapshot_format should always be defined when href()
881 # is called, but just in case some code forgets, we
882 # fall back to the default
883 $fmt ||= $snapshot_fmts[0];
884 $href .= $known_snapshot_formats{$fmt}{'suffix'};
885 delete $params{'snapshot_format'};
889 # now encode the parameters explicitly
891 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
892 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
893 if (defined $params{$name}) {
894 if (ref($params{$name}) eq "ARRAY") {
895 foreach my $par (@
{$params{$name}}) {
896 push @result, $symbol . "=" . esc_param
($par);
899 push @result, $symbol . "=" . esc_param
($params{$name});
903 $href .= "?" . join(';', @result) if scalar @result;
909 ## ======================================================================
910 ## validation, quoting/unquoting and escaping
912 sub validate_action
{
913 my $input = shift || return undef;
914 return undef unless exists $actions{$input};
918 sub validate_project
{
919 my $input = shift || return undef;
920 if (!validate_pathname
($input) ||
921 !(-d
"$projectroot/$input") ||
922 !check_export_ok
("$projectroot/$input") ||
923 ($strict_export && !project_in_list
($input))) {
930 sub validate_pathname
{
931 my $input = shift || return undef;
933 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
934 # at the beginning, at the end, and between slashes.
935 # also this catches doubled slashes
936 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
940 if ($input =~ m!\0!) {
946 sub validate_refname
{
947 my $input = shift || return undef;
949 # textual hashes are O.K.
950 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
953 # it must be correct pathname
954 $input = validate_pathname
($input)
956 # restrictions on ref name according to git-check-ref-format
957 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
963 # decode sequences of octets in utf8 into Perl's internal form,
964 # which is utf-8 with utf8 flag set if needed. gitweb writes out
965 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
968 if (utf8
::valid
($str)) {
972 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
976 # quote unsafe chars, but keep the slash, even when it's not
977 # correct, but quoted slashes look too horrible in bookmarks
980 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
986 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
989 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
995 # replace invalid utf8 character with SUBSTITUTION sequence
1000 $str = to_utf8
($str);
1001 $str = $cgi->escapeHTML($str);
1002 if ($opts{'-nbsp'}) {
1003 $str =~ s/ / /g;
1005 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1009 # quote control characters and escape filename to HTML
1014 $str = to_utf8
($str);
1015 $str = $cgi->escapeHTML($str);
1016 if ($opts{'-nbsp'}) {
1017 $str =~ s/ / /g;
1019 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1023 # Make control characters "printable", using character escape codes (CEC)
1027 my %es = ( # character escape codes, aka escape sequences
1028 "\t" => '\t', # tab (HT)
1029 "\n" => '\n', # line feed (LF)
1030 "\r" => '\r', # carrige return (CR)
1031 "\f" => '\f', # form feed (FF)
1032 "\b" => '\b', # backspace (BS)
1033 "\a" => '\a', # alarm (bell) (BEL)
1034 "\e" => '\e', # escape (ESC)
1035 "\013" => '\v', # vertical tab (VT)
1036 "\000" => '\0', # nul character (NUL)
1038 my $chr = ( (exists $es{$cntrl})
1040 : sprintf('\%2x', ord($cntrl)) );
1041 if ($opts{-nohtml
}) {
1044 return "<span class=\"cntrl\">$chr</span>";
1048 # Alternatively use unicode control pictures codepoints,
1049 # Unicode "printable representation" (PR)
1054 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1055 if ($opts{-nohtml
}) {
1058 return "<span class=\"cntrl\">$chr</span>";
1062 # git may return quoted and escaped filenames
1068 my %es = ( # character escape codes, aka escape sequences
1069 't' => "\t", # tab (HT, TAB)
1070 'n' => "\n", # newline (NL)
1071 'r' => "\r", # return (CR)
1072 'f' => "\f", # form feed (FF)
1073 'b' => "\b", # backspace (BS)
1074 'a' => "\a", # alarm (bell) (BEL)
1075 'e' => "\e", # escape (ESC)
1076 'v' => "\013", # vertical tab (VT)
1079 if ($seq =~ m/^[0-7]{1,3}$/) {
1080 # octal char sequence
1081 return chr(oct($seq));
1082 } elsif (exists $es{$seq}) {
1083 # C escape sequence, aka character escape code
1086 # quoted ordinary character
1090 if ($str =~ m/^"(.*)"$/) {
1093 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1098 # escape tabs (convert tabs to spaces)
1102 while ((my $pos = index($line, "\t")) != -1) {
1103 if (my $count = (8 - ($pos % 8))) {
1104 my $spaces = ' ' x
$count;
1105 $line =~ s/\t/$spaces/;
1112 sub project_in_list
{
1113 my $project = shift;
1114 my @list = git_get_projects_list
();
1115 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1118 ## ----------------------------------------------------------------------
1119 ## HTML aware string manipulation
1121 # Try to chop given string on a word boundary between position
1122 # $len and $len+$add_len. If there is no word boundary there,
1123 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1124 # (marking chopped part) would be longer than given string.
1128 my $add_len = shift || 10;
1129 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1131 # Make sure perl knows it is utf8 encoded so we don't
1132 # cut in the middle of a utf8 multibyte char.
1133 $str = to_utf8
($str);
1135 # allow only $len chars, but don't cut a word if it would fit in $add_len
1136 # if it doesn't fit, cut it if it's still longer than the dots we would add
1137 # remove chopped character entities entirely
1139 # when chopping in the middle, distribute $len into left and right part
1140 # return early if chopping wouldn't make string shorter
1141 if ($where eq 'center') {
1142 return $str if ($len + 5 >= length($str)); # filler is length 5
1145 return $str if ($len + 4 >= length($str)); # filler is length 4
1148 # regexps: ending and beginning with word part up to $add_len
1149 my $endre = qr/.{$len}\w{0,$add_len}/;
1150 my $begre = qr/\w{0,$add_len}.{$len}/;
1152 if ($where eq 'left') {
1153 $str =~ m/^(.*?)($begre)$/;
1154 my ($lead, $body) = ($1, $2);
1155 if (length($lead) > 4) {
1156 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1159 return "$lead$body";
1161 } elsif ($where eq 'center') {
1162 $str =~ m/^($endre)(.*)$/;
1163 my ($left, $str) = ($1, $2);
1164 $str =~ m/^(.*?)($begre)$/;
1165 my ($mid, $right) = ($1, $2);
1166 if (length($mid) > 5) {
1167 $left =~ s/&[^;]*$//;
1168 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1171 return "$left$mid$right";
1174 $str =~ m/^($endre)(.*)$/;
1177 if (length($tail) > 4) {
1178 $body =~ s/&[^;]*$//;
1181 return "$body$tail";
1185 # takes the same arguments as chop_str, but also wraps a <span> around the
1186 # result with a title attribute if it does get chopped. Additionally, the
1187 # string is HTML-escaped.
1188 sub chop_and_escape_str
{
1191 my $chopped = chop_str
(@_);
1192 if ($chopped eq $str) {
1193 return esc_html
($chopped);
1195 $str =~ s/([[:cntrl:]])/?/g;
1196 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1200 ## ----------------------------------------------------------------------
1201 ## functions returning short strings
1203 # CSS class for given age value (in seconds)
1207 if (!defined $age) {
1209 } elsif ($age < 60*60*2) {
1211 } elsif ($age < 60*60*24*2) {
1218 # convert age in seconds to "nn units ago" string
1223 if ($age > 60*60*24*365*2) {
1224 $age_str = (int $age/60/60/24/365);
1225 $age_str .= " years ago";
1226 } elsif ($age > 60*60*24*(365/12)*2) {
1227 $age_str = int $age/60/60/24/(365/12);
1228 $age_str .= " months ago";
1229 } elsif ($age > 60*60*24*7*2) {
1230 $age_str = int $age/60/60/24/7;
1231 $age_str .= " weeks ago";
1232 } elsif ($age > 60*60*24*2) {
1233 $age_str = int $age/60/60/24;
1234 $age_str .= " days ago";
1235 } elsif ($age > 60*60*2) {
1236 $age_str = int $age/60/60;
1237 $age_str .= " hours ago";
1238 } elsif ($age > 60*2) {
1239 $age_str = int $age/60;
1240 $age_str .= " min ago";
1241 } elsif ($age > 2) {
1242 $age_str = int $age;
1243 $age_str .= " sec ago";
1245 $age_str .= " right now";
1251 S_IFINVALID
=> 0030000,
1252 S_IFGITLINK
=> 0160000,
1255 # submodule/subproject, a commit object reference
1256 sub S_ISGITLINK
($) {
1259 return (($mode & S_IFMT
) == S_IFGITLINK
)
1262 # convert file mode in octal to symbolic file mode string
1264 my $mode = oct shift;
1266 if (S_ISGITLINK
($mode)) {
1267 return 'm---------';
1268 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1269 return 'drwxr-xr-x';
1270 } elsif (S_ISLNK
($mode)) {
1271 return 'lrwxrwxrwx';
1272 } elsif (S_ISREG
($mode)) {
1273 # git cares only about the executable bit
1274 if ($mode & S_IXUSR
) {
1275 return '-rwxr-xr-x';
1277 return '-rw-r--r--';
1280 return '----------';
1284 # convert file mode in octal to file type string
1288 if ($mode !~ m/^[0-7]+$/) {
1294 if (S_ISGITLINK
($mode)) {
1296 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1298 } elsif (S_ISLNK
($mode)) {
1300 } elsif (S_ISREG
($mode)) {
1307 # convert file mode in octal to file type description string
1308 sub file_type_long
{
1311 if ($mode !~ m/^[0-7]+$/) {
1317 if (S_ISGITLINK
($mode)) {
1319 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1321 } elsif (S_ISLNK
($mode)) {
1323 } elsif (S_ISREG
($mode)) {
1324 if ($mode & S_IXUSR
) {
1325 return "executable";
1335 ## ----------------------------------------------------------------------
1336 ## functions returning short HTML fragments, or transforming HTML fragments
1337 ## which don't belong to other sections
1339 # format line of commit message.
1340 sub format_log_line_html
{
1343 $line = esc_html
($line, -nbsp
=>1);
1344 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1347 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1348 -class => "text"}, $hash_text);
1349 $line =~ s/$hash_text/$link/;
1354 # format marker of refs pointing to given object
1356 # the destination action is chosen based on object type and current context:
1357 # - for annotated tags, we choose the tag view unless it's the current view
1358 # already, in which case we go to shortlog view
1359 # - for other refs, we keep the current view if we're in history, shortlog or
1360 # log view, and select shortlog otherwise
1361 sub format_ref_marker
{
1362 my ($refs, $id) = @_;
1365 if (defined $refs->{$id}) {
1366 foreach my $ref (@
{$refs->{$id}}) {
1367 # this code exploits the fact that non-lightweight tags are the
1368 # only indirect objects, and that they are the only objects for which
1369 # we want to use tag instead of shortlog as action
1370 my ($type, $name) = qw();
1371 my $indirect = ($ref =~ s/\^\{\}$//);
1372 # e.g. tags/v2.6.11 or heads/next
1373 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1382 $class .= " indirect" if $indirect;
1384 my $dest_action = "shortlog";
1387 $dest_action = "tag" unless $action eq "tag";
1388 } elsif ($action =~ /^(history|(short)?log)$/) {
1389 $dest_action = $action;
1393 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1396 my $link = $cgi->a({
1398 action
=>$dest_action,
1402 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1408 return ' <span class="refs">'. $markers . '</span>';
1414 # format, perhaps shortened and with markers, title line
1415 sub format_subject_html
{
1416 my ($long, $short, $href, $extra) = @_;
1417 $extra = '' unless defined($extra);
1419 if (length($short) < length($long)) {
1420 return $cgi->a({-href
=> $href, -class => "list subject",
1421 -title
=> to_utf8
($long)},
1422 esc_html
($short) . $extra);
1424 return $cgi->a({-href
=> $href, -class => "list subject"},
1425 esc_html
($long) . $extra);
1429 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1430 sub format_git_diff_header_line
{
1432 my $diffinfo = shift;
1433 my ($from, $to) = @_;
1435 if ($diffinfo->{'nparents'}) {
1437 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1438 if ($to->{'href'}) {
1439 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1440 esc_path
($to->{'file'}));
1441 } else { # file was deleted (no href)
1442 $line .= esc_path
($to->{'file'});
1446 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1447 if ($from->{'href'}) {
1448 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1449 'a/' . esc_path
($from->{'file'}));
1450 } else { # file was added (no href)
1451 $line .= 'a/' . esc_path
($from->{'file'});
1454 if ($to->{'href'}) {
1455 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1456 'b/' . esc_path
($to->{'file'}));
1457 } else { # file was deleted
1458 $line .= 'b/' . esc_path
($to->{'file'});
1462 return "<div class=\"diff header\">$line</div>\n";
1465 # format extended diff header line, before patch itself
1466 sub format_extended_diff_header_line
{
1468 my $diffinfo = shift;
1469 my ($from, $to) = @_;
1472 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1473 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1474 esc_path
($from->{'file'}));
1476 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1477 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1478 esc_path
($to->{'file'}));
1480 # match single <mode>
1481 if ($line =~ m/\s(\d{6})$/) {
1482 $line .= '<span class="info"> (' .
1483 file_type_long
($1) .
1487 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1488 # can match only for combined diff
1490 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1491 if ($from->{'href'}[$i]) {
1492 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1494 substr($diffinfo->{'from_id'}[$i],0,7));
1499 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1502 if ($to->{'href'}) {
1503 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1504 substr($diffinfo->{'to_id'},0,7));
1509 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1510 # can match only for ordinary diff
1511 my ($from_link, $to_link);
1512 if ($from->{'href'}) {
1513 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1514 substr($diffinfo->{'from_id'},0,7));
1516 $from_link = '0' x
7;
1518 if ($to->{'href'}) {
1519 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1520 substr($diffinfo->{'to_id'},0,7));
1524 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1525 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1528 return $line . "<br/>\n";
1531 # format from-file/to-file diff header
1532 sub format_diff_from_to_header
{
1533 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1538 #assert($line =~ m/^---/) if DEBUG;
1539 # no extra formatting for "^--- /dev/null"
1540 if (! $diffinfo->{'nparents'}) {
1541 # ordinary (single parent) diff
1542 if ($line =~ m!^--- "?a/!) {
1543 if ($from->{'href'}) {
1545 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1546 esc_path
($from->{'file'}));
1549 esc_path
($from->{'file'});
1552 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1555 # combined diff (merge commit)
1556 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1557 if ($from->{'href'}[$i]) {
1559 $cgi->a({-href
=>href
(action
=>"blobdiff",
1560 hash_parent
=>$diffinfo->{'from_id'}[$i],
1561 hash_parent_base
=>$parents[$i],
1562 file_parent
=>$from->{'file'}[$i],
1563 hash
=>$diffinfo->{'to_id'},
1565 file_name
=>$to->{'file'}),
1567 -title
=>"diff" . ($i+1)},
1570 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1571 esc_path
($from->{'file'}[$i]));
1573 $line = '--- /dev/null';
1575 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1580 #assert($line =~ m/^\+\+\+/) if DEBUG;
1581 # no extra formatting for "^+++ /dev/null"
1582 if ($line =~ m!^\+\+\+ "?b/!) {
1583 if ($to->{'href'}) {
1585 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1586 esc_path
($to->{'file'}));
1589 esc_path
($to->{'file'});
1592 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1597 # create note for patch simplified by combined diff
1598 sub format_diff_cc_simplified
{
1599 my ($diffinfo, @parents) = @_;
1602 $result .= "<div class=\"diff header\">" .
1604 if (!is_deleted
($diffinfo)) {
1605 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1607 hash
=>$diffinfo->{'to_id'},
1608 file_name
=>$diffinfo->{'to_file'}),
1610 esc_path
($diffinfo->{'to_file'}));
1612 $result .= esc_path
($diffinfo->{'to_file'});
1614 $result .= "</div>\n" . # class="diff header"
1615 "<div class=\"diff nodifferences\">" .
1617 "</div>\n"; # class="diff nodifferences"
1622 # format patch (diff) line (not to be used for diff headers)
1623 sub format_diff_line
{
1625 my ($from, $to) = @_;
1626 my $diff_class = "";
1630 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1632 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1633 if ($line =~ m/^\@{3}/) {
1634 $diff_class = " chunk_header";
1635 } elsif ($line =~ m/^\\/) {
1636 $diff_class = " incomplete";
1637 } elsif ($prefix =~ tr/+/+/) {
1638 $diff_class = " add";
1639 } elsif ($prefix =~ tr/-/-/) {
1640 $diff_class = " rem";
1643 # assume ordinary diff
1644 my $char = substr($line, 0, 1);
1646 $diff_class = " add";
1647 } elsif ($char eq '-') {
1648 $diff_class = " rem";
1649 } elsif ($char eq '@') {
1650 $diff_class = " chunk_header";
1651 } elsif ($char eq "\\") {
1652 $diff_class = " incomplete";
1655 $line = untabify
($line);
1656 if ($from && $to && $line =~ m/^\@{2} /) {
1657 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1658 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1660 $from_lines = 0 unless defined $from_lines;
1661 $to_lines = 0 unless defined $to_lines;
1663 if ($from->{'href'}) {
1664 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1665 -class=>"list"}, $from_text);
1667 if ($to->{'href'}) {
1668 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1669 -class=>"list"}, $to_text);
1671 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1672 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1673 return "<div class=\"diff$diff_class\">$line</div>\n";
1674 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1675 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1676 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1678 @from_text = split(' ', $ranges);
1679 for (my $i = 0; $i < @from_text; ++$i) {
1680 ($from_start[$i], $from_nlines[$i]) =
1681 (split(',', substr($from_text[$i], 1)), 0);
1684 $to_text = pop @from_text;
1685 $to_start = pop @from_start;
1686 $to_nlines = pop @from_nlines;
1688 $line = "<span class=\"chunk_info\">$prefix ";
1689 for (my $i = 0; $i < @from_text; ++$i) {
1690 if ($from->{'href'}[$i]) {
1691 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1692 -class=>"list"}, $from_text[$i]);
1694 $line .= $from_text[$i];
1698 if ($to->{'href'}) {
1699 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1700 -class=>"list"}, $to_text);
1704 $line .= " $prefix</span>" .
1705 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1706 return "<div class=\"diff$diff_class\">$line</div>\n";
1708 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1711 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1712 # linked. Pass the hash of the tree/commit to snapshot.
1713 sub format_snapshot_links
{
1715 my $num_fmts = @snapshot_fmts;
1716 if ($num_fmts > 1) {
1717 # A parenthesized list of links bearing format names.
1718 # e.g. "snapshot (_tar.gz_ _zip_)"
1719 return "snapshot (" . join(' ', map
1726 }, $known_snapshot_formats{$_}{'display'})
1727 , @snapshot_fmts) . ")";
1728 } elsif ($num_fmts == 1) {
1729 # A single "snapshot" link whose tooltip bears the format name.
1731 my ($fmt) = @snapshot_fmts;
1737 snapshot_format
=>$fmt
1739 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1741 } else { # $num_fmts == 0
1746 ## ......................................................................
1747 ## functions returning values to be passed, perhaps after some
1748 ## transformation, to other functions; e.g. returning arguments to href()
1750 # returns hash to be passed to href to generate gitweb URL
1751 # in -title key it returns description of link
1753 my $format = shift || 'Atom';
1754 my %res = (action
=> lc($format));
1756 # feed links are possible only for project views
1757 return unless (defined $project);
1758 # some views should link to OPML, or to generic project feed,
1759 # or don't have specific feed yet (so they should use generic)
1760 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1763 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1764 # from tag links; this also makes possible to detect branch links
1765 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1766 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1769 # find log type for feed description (title)
1771 if (defined $file_name) {
1772 $type = "history of $file_name";
1773 $type .= "/" if ($action eq 'tree');
1774 $type .= " on '$branch'" if (defined $branch);
1776 $type = "log of $branch" if (defined $branch);
1779 $res{-title
} = $type;
1780 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1781 $res{'file_name'} = $file_name;
1786 ## ----------------------------------------------------------------------
1787 ## git utility subroutines, invoking git commands
1789 # returns path to the core git executable and the --git-dir parameter as list
1791 return $GIT, '--git-dir='.$git_dir;
1794 # quote the given arguments for passing them to the shell
1795 # quote_command("command", "arg 1", "arg with ' and ! characters")
1796 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1797 # Try to avoid using this function wherever possible.
1800 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1803 # get HEAD ref of given project as hash
1804 sub git_get_head_hash
{
1805 my $project = shift;
1806 my $o_git_dir = $git_dir;
1808 $git_dir = "$projectroot/$project";
1809 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1812 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1816 if (defined $o_git_dir) {
1817 $git_dir = $o_git_dir;
1822 # get type of given object
1826 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1828 close $fd or return;
1833 # repository configuration
1834 our $config_file = '';
1837 # store multiple values for single key as anonymous array reference
1838 # single values stored directly in the hash, not as [ <value> ]
1839 sub hash_set_multi
{
1840 my ($hash, $key, $value) = @_;
1842 if (!exists $hash->{$key}) {
1843 $hash->{$key} = $value;
1844 } elsif (!ref $hash->{$key}) {
1845 $hash->{$key} = [ $hash->{$key}, $value ];
1847 push @
{$hash->{$key}}, $value;
1851 # return hash of git project configuration
1852 # optionally limited to some section, e.g. 'gitweb'
1853 sub git_parse_project_config
{
1854 my $section_regexp = shift;
1859 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1862 while (my $keyval = <$fh>) {
1864 my ($key, $value) = split(/\n/, $keyval, 2);
1866 hash_set_multi
(\
%config, $key, $value)
1867 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1874 # convert config value to boolean, 'true' or 'false'
1875 # no value, number > 0, 'true' and 'yes' values are true
1876 # rest of values are treated as false (never as error)
1877 sub config_to_bool
{
1880 # strip leading and trailing whitespace
1884 return (!defined $val || # section.key
1885 ($val =~ /^\d+$/ && $val) || # section.key = 1
1886 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1889 # convert config value to simple decimal number
1890 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1891 # to be multiplied by 1024, 1048576, or 1073741824
1895 # strip leading and trailing whitespace
1899 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1901 # unknown unit is treated as 1
1902 return $num * ($unit eq 'g' ?
1073741824 :
1903 $unit eq 'm' ?
1048576 :
1904 $unit eq 'k' ?
1024 : 1);
1909 # convert config value to array reference, if needed
1910 sub config_to_multi
{
1913 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1916 sub git_get_project_config
{
1917 my ($key, $type) = @_;
1920 return unless ($key);
1921 $key =~ s/^gitweb\.//;
1922 return if ($key =~ m/\W/);
1925 if (defined $type) {
1928 unless ($type eq 'bool' || $type eq 'int');
1932 if (!defined $config_file ||
1933 $config_file ne "$git_dir/config") {
1934 %config = git_parse_project_config
('gitweb');
1935 $config_file = "$git_dir/config";
1939 if (!defined $type) {
1940 return $config{"gitweb.$key"};
1941 } elsif ($type eq 'bool') {
1942 # backward compatibility: 'git config --bool' returns true/false
1943 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1944 } elsif ($type eq 'int') {
1945 return config_to_int
($config{"gitweb.$key"});
1947 return $config{"gitweb.$key"};
1950 # get hash of given path at given ref
1951 sub git_get_hash_by_path
{
1953 my $path = shift || return undef;
1958 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1959 or die_error
(500, "Open git-ls-tree failed");
1961 close $fd or return undef;
1963 if (!defined $line) {
1964 # there is no tree or hash given by $path at $base
1968 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1969 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1970 if (defined $type && $type ne $2) {
1971 # type doesn't match
1977 # get path of entry with given hash at given tree-ish (ref)
1978 # used to get 'from' filename for combined diff (merge commit) for renames
1979 sub git_get_path_by_hash
{
1980 my $base = shift || return;
1981 my $hash = shift || return;
1985 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1987 while (my $line = <$fd>) {
1990 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1991 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1992 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2001 ## ......................................................................
2002 ## git utility functions, directly accessing git repository
2004 sub git_get_project_description
{
2007 $git_dir = "$projectroot/$path";
2008 open my $fd, "$git_dir/description"
2009 or return git_get_project_config
('description');
2012 if (defined $descr) {
2018 sub git_get_project_ctags
{
2022 $git_dir = "$projectroot/$path";
2023 unless (opendir D
, "$git_dir/ctags") {
2026 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2027 open CT
, $_ or next;
2031 my $ctag = $_; $ctag =~ s
#.*/##;
2032 $ctags->{$ctag} = $val;
2038 sub git_populate_project_tagcloud
{
2041 # First, merge different-cased tags; tags vote on casing
2043 foreach (keys %$ctags) {
2044 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2045 if (not $ctags_lc{lc $_}->{topcount
}
2046 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2047 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2048 $ctags_lc{lc $_}->{topname
} = $_;
2053 if (eval { require HTML
::TagCloud
; 1; }) {
2054 $cloud = HTML
::TagCloud
->new;
2055 foreach (sort keys %ctags_lc) {
2056 # Pad the title with spaces so that the cloud looks
2058 my $title = $ctags_lc{$_}->{topname
};
2059 $title =~ s/ / /g;
2060 $title =~ s/^/ /g;
2061 $title =~ s/$/ /g;
2062 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2065 $cloud = \
%ctags_lc;
2070 sub git_show_project_tagcloud
{
2071 my ($cloud, $count) = @_;
2072 print STDERR
ref($cloud)."..\n";
2073 if (ref $cloud eq 'HTML::TagCloud') {
2074 return $cloud->html_and_css($count);
2076 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2077 return '<p align="center">' . join (', ', map {
2078 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2079 } splice(@tags, 0, $count)) . '</p>';
2083 sub git_get_project_url_list
{
2086 $git_dir = "$projectroot/$path";
2087 open my $fd, "$git_dir/cloneurl"
2088 or return wantarray ?
2089 @
{ config_to_multi
(git_get_project_config
('url')) } :
2090 config_to_multi
(git_get_project_config
('url'));
2091 my @git_project_url_list = map { chomp; $_ } <$fd>;
2094 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2097 sub git_get_projects_list
{
2102 $filter =~ s/\.git$//;
2104 my ($check_forks) = gitweb_check_feature
('forks');
2106 if (-d
$projects_list) {
2107 # search in directory
2108 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2109 # remove the trailing "/"
2111 my $pfxlen = length("$dir");
2112 my $pfxdepth = ($dir =~ tr!/!!);
2115 follow_fast
=> 1, # follow symbolic links
2116 follow_skip
=> 2, # ignore duplicates
2117 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2119 # skip project-list toplevel, if we get it.
2120 return if (m!^[/.]$!);
2121 # only directories can be git repositories
2122 return unless (-d
$_);
2123 # don't traverse too deep (Find is super slow on os x)
2124 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2125 $File::Find
::prune
= 1;
2129 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2130 # we check related file in $projectroot
2131 if (check_export_ok
("$projectroot/$filter/$subdir")) {
2132 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
2133 $File::Find
::prune
= 1;
2138 } elsif (-f
$projects_list) {
2139 # read from file(url-encoded):
2140 # 'git%2Fgit.git Linus+Torvalds'
2141 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2142 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2144 open my ($fd), $projects_list or return;
2146 while (my $line = <$fd>) {
2148 my ($path, $owner) = split ' ', $line;
2149 $path = unescape
($path);
2150 $owner = unescape
($owner);
2151 if (!defined $path) {
2154 if ($filter ne '') {
2155 # looking for forks;
2156 my $pfx = substr($path, 0, length($filter));
2157 if ($pfx ne $filter) {
2160 my $sfx = substr($path, length($filter));
2161 if ($sfx !~ /^\/.*\
.git
$/) {
2164 } elsif ($check_forks) {
2166 foreach my $filter (keys %paths) {
2167 # looking for forks;
2168 my $pfx = substr($path, 0, length($filter));
2169 if ($pfx ne $filter) {
2172 my $sfx = substr($path, length($filter));
2173 if ($sfx !~ /^\/.*\
.git
$/) {
2176 # is a fork, don't include it in
2181 if (check_export_ok
("$projectroot/$path")) {
2184 owner
=> to_utf8
($owner),
2187 (my $forks_path = $path) =~ s/\.git$//;
2188 $paths{$forks_path}++;
2196 our $gitweb_project_owner = undef;
2197 sub git_get_project_list_from_file
{
2199 return if (defined $gitweb_project_owner);
2201 $gitweb_project_owner = {};
2202 # read from file (url-encoded):
2203 # 'git%2Fgit.git Linus+Torvalds'
2204 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2205 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2206 if (-f
$projects_list) {
2207 open (my $fd , $projects_list);
2208 while (my $line = <$fd>) {
2210 my ($pr, $ow) = split ' ', $line;
2211 $pr = unescape
($pr);
2212 $ow = unescape
($ow);
2213 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2219 sub git_get_project_owner
{
2220 my $project = shift;
2223 return undef unless $project;
2224 $git_dir = "$projectroot/$project";
2226 if (!defined $gitweb_project_owner) {
2227 git_get_project_list_from_file
();
2230 if (exists $gitweb_project_owner->{$project}) {
2231 $owner = $gitweb_project_owner->{$project};
2233 if (!defined $owner){
2234 $owner = git_get_project_config
('owner');
2236 if (!defined $owner) {
2237 $owner = get_file_owner
("$git_dir");
2243 sub git_get_last_activity
{
2247 $git_dir = "$projectroot/$path";
2248 open($fd, "-|", git_cmd
(), 'for-each-ref',
2249 '--format=%(committer)',
2250 '--sort=-committerdate',
2252 'refs/heads') or return;
2253 my $most_recent = <$fd>;
2254 close $fd or return;
2255 if (defined $most_recent &&
2256 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2258 my $age = time - $timestamp;
2259 return ($age, age_string
($age));
2261 return (undef, undef);
2264 sub git_get_references
{
2265 my $type = shift || "";
2267 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2268 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2269 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2270 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2273 while (my $line = <$fd>) {
2275 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2276 if (defined $refs{$1}) {
2277 push @
{$refs{$1}}, $2;
2283 close $fd or return;
2287 sub git_get_rev_name_tags
{
2288 my $hash = shift || return undef;
2290 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2292 my $name_rev = <$fd>;
2295 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2298 # catches also '$hash undefined' output
2303 ## ----------------------------------------------------------------------
2304 ## parse to hash functions
2308 my $tz = shift || "-0000";
2311 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2312 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2313 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2314 $date{'hour'} = $hour;
2315 $date{'minute'} = $min;
2316 $date{'mday'} = $mday;
2317 $date{'day'} = $days[$wday];
2318 $date{'month'} = $months[$mon];
2319 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2320 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2321 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2322 $mday, $months[$mon], $hour ,$min;
2323 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2324 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2326 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2327 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2328 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2329 $date{'hour_local'} = $hour;
2330 $date{'minute_local'} = $min;
2331 $date{'tz_local'} = $tz;
2332 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2333 1900+$year, $mon+1, $mday,
2334 $hour, $min, $sec, $tz);
2343 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2344 $tag{'id'} = $tag_id;
2345 while (my $line = <$fd>) {
2347 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2348 $tag{'object'} = $1;
2349 } elsif ($line =~ m/^type (.+)$/) {
2351 } elsif ($line =~ m/^tag (.+)$/) {
2353 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2354 $tag{'author'} = $1;
2357 } elsif ($line =~ m/--BEGIN/) {
2358 push @comment, $line;
2360 } elsif ($line eq "") {
2364 push @comment, <$fd>;
2365 $tag{'comment'} = \
@comment;
2366 close $fd or return;
2367 if (!defined $tag{'name'}) {
2373 sub parse_commit_text
{
2374 my ($commit_text, $withparents) = @_;
2375 my @commit_lines = split '\n', $commit_text;
2378 pop @commit_lines; # Remove '\0'
2380 if (! @commit_lines) {
2384 my $header = shift @commit_lines;
2385 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2388 ($co{'id'}, my @parents) = split ' ', $header;
2389 while (my $line = shift @commit_lines) {
2390 last if $line eq "\n";
2391 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2393 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2395 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2397 $co{'author_epoch'} = $2;
2398 $co{'author_tz'} = $3;
2399 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2400 $co{'author_name'} = $1;
2401 $co{'author_email'} = $2;
2403 $co{'author_name'} = $co{'author'};
2405 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2406 $co{'committer'} = $1;
2407 $co{'committer_epoch'} = $2;
2408 $co{'committer_tz'} = $3;
2409 $co{'committer_name'} = $co{'committer'};
2410 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2411 $co{'committer_name'} = $1;
2412 $co{'committer_email'} = $2;
2414 $co{'committer_name'} = $co{'committer'};
2418 if (!defined $co{'tree'}) {
2421 $co{'parents'} = \
@parents;
2422 $co{'parent'} = $parents[0];
2424 foreach my $title (@commit_lines) {
2427 $co{'title'} = chop_str
($title, 80, 5);
2428 # remove leading stuff of merges to make the interesting part visible
2429 if (length($title) > 50) {
2430 $title =~ s/^Automatic //;
2431 $title =~ s/^merge (of|with) /Merge ... /i;
2432 if (length($title) > 50) {
2433 $title =~ s/(http|rsync):\/\///;
2435 if (length($title) > 50) {
2436 $title =~ s/(master|www|rsync)\.//;
2438 if (length($title) > 50) {
2439 $title =~ s/kernel.org:?//;
2441 if (length($title) > 50) {
2442 $title =~ s/\/pub\/scm//;
2445 $co{'title_short'} = chop_str
($title, 50, 5);
2449 if (! defined $co{'title'} || $co{'title'} eq "") {
2450 $co{'title'} = $co{'title_short'} = '(no commit message)';
2452 # remove added spaces
2453 foreach my $line (@commit_lines) {
2456 $co{'comment'} = \
@commit_lines;
2458 my $age = time - $co{'committer_epoch'};
2460 $co{'age_string'} = age_string
($age);
2461 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2462 if ($age > 60*60*24*7*2) {
2463 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2464 $co{'age_string_age'} = $co{'age_string'};
2466 $co{'age_string_date'} = $co{'age_string'};
2467 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2473 my ($commit_id) = @_;
2478 open my $fd, "-|", git_cmd
(), "rev-list",
2484 or die_error
(500, "Open git-rev-list failed");
2485 %co = parse_commit_text
(<$fd>, 1);
2492 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2500 open my $fd, "-|", git_cmd
(), "rev-list",
2503 ("--max-count=" . $maxcount),
2504 ("--skip=" . $skip),
2508 ($filename ?
($filename) : ())
2509 or die_error
(500, "Open git-rev-list failed");
2510 while (my $line = <$fd>) {
2511 my %co = parse_commit_text
($line);
2516 return wantarray ?
@cos : \
@cos;
2519 # parse line of git-diff-tree "raw" output
2520 sub parse_difftree_raw_line
{
2524 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2525 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2526 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2527 $res{'from_mode'} = $1;
2528 $res{'to_mode'} = $2;
2529 $res{'from_id'} = $3;
2531 $res{'status'} = $5;
2532 $res{'similarity'} = $6;
2533 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2534 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2536 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2539 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2540 # combined diff (for merge commit)
2541 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2542 $res{'nparents'} = length($1);
2543 $res{'from_mode'} = [ split(' ', $2) ];
2544 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2545 $res{'from_id'} = [ split(' ', $3) ];
2546 $res{'to_id'} = pop @
{$res{'from_id'}};
2547 $res{'status'} = [ split('', $4) ];
2548 $res{'to_file'} = unquote
($5);
2550 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2551 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2552 $res{'commit'} = $1;
2555 return wantarray ?
%res : \
%res;
2558 # wrapper: return parsed line of git-diff-tree "raw" output
2559 # (the argument might be raw line, or parsed info)
2560 sub parsed_difftree_line
{
2561 my $line_or_ref = shift;
2563 if (ref($line_or_ref) eq "HASH") {
2564 # pre-parsed (or generated by hand)
2565 return $line_or_ref;
2567 return parse_difftree_raw_line
($line_or_ref);
2571 # parse line of git-ls-tree output
2572 sub parse_ls_tree_line
($;%) {
2577 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2578 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2586 $res{'name'} = unquote
($4);
2589 return wantarray ?
%res : \
%res;
2592 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2593 sub parse_from_to_diffinfo
{
2594 my ($diffinfo, $from, $to, @parents) = @_;
2596 if ($diffinfo->{'nparents'}) {
2598 $from->{'file'} = [];
2599 $from->{'href'} = [];
2600 fill_from_file_info
($diffinfo, @parents)
2601 unless exists $diffinfo->{'from_file'};
2602 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2603 $from->{'file'}[$i] =
2604 defined $diffinfo->{'from_file'}[$i] ?
2605 $diffinfo->{'from_file'}[$i] :
2606 $diffinfo->{'to_file'};
2607 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2608 $from->{'href'}[$i] = href
(action
=>"blob",
2609 hash_base
=>$parents[$i],
2610 hash
=>$diffinfo->{'from_id'}[$i],
2611 file_name
=>$from->{'file'}[$i]);
2613 $from->{'href'}[$i] = undef;
2617 # ordinary (not combined) diff
2618 $from->{'file'} = $diffinfo->{'from_file'};
2619 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2620 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2621 hash
=>$diffinfo->{'from_id'},
2622 file_name
=>$from->{'file'});
2624 delete $from->{'href'};
2628 $to->{'file'} = $diffinfo->{'to_file'};
2629 if (!is_deleted
($diffinfo)) { # file exists in result
2630 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2631 hash
=>$diffinfo->{'to_id'},
2632 file_name
=>$to->{'file'});
2634 delete $to->{'href'};
2638 ## ......................................................................
2639 ## parse to array of hashes functions
2641 sub git_get_heads_list
{
2645 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2646 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2647 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2650 while (my $line = <$fd>) {
2654 my ($refinfo, $committerinfo) = split(/\0/, $line);
2655 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2656 my ($committer, $epoch, $tz) =
2657 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2658 $ref_item{'fullname'} = $name;
2659 $name =~ s!^refs/heads/!!;
2661 $ref_item{'name'} = $name;
2662 $ref_item{'id'} = $hash;
2663 $ref_item{'title'} = $title || '(no commit message)';
2664 $ref_item{'epoch'} = $epoch;
2666 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2668 $ref_item{'age'} = "unknown";
2671 push @headslist, \
%ref_item;
2675 return wantarray ?
@headslist : \
@headslist;
2678 sub git_get_tags_list
{
2682 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2683 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2684 '--format=%(objectname) %(objecttype) %(refname) '.
2685 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2688 while (my $line = <$fd>) {
2692 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2693 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2694 my ($creator, $epoch, $tz) =
2695 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2696 $ref_item{'fullname'} = $name;
2697 $name =~ s!^refs/tags/!!;
2699 $ref_item{'type'} = $type;
2700 $ref_item{'id'} = $id;
2701 $ref_item{'name'} = $name;
2702 if ($type eq "tag") {
2703 $ref_item{'subject'} = $title;
2704 $ref_item{'reftype'} = $reftype;
2705 $ref_item{'refid'} = $refid;
2707 $ref_item{'reftype'} = $type;
2708 $ref_item{'refid'} = $id;
2711 if ($type eq "tag" || $type eq "commit") {
2712 $ref_item{'epoch'} = $epoch;
2714 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2716 $ref_item{'age'} = "unknown";
2720 push @tagslist, \
%ref_item;
2724 return wantarray ?
@tagslist : \
@tagslist;
2727 ## ----------------------------------------------------------------------
2728 ## filesystem-related functions
2730 sub get_file_owner
{
2733 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2734 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2735 if (!defined $gcos) {
2739 $owner =~ s/[,;].*$//;
2740 return to_utf8
($owner);
2743 ## ......................................................................
2744 ## mimetype related functions
2746 sub mimetype_guess_file
{
2747 my $filename = shift;
2748 my $mimemap = shift;
2749 -r
$mimemap or return undef;
2752 open(MIME
, $mimemap) or return undef;
2754 next if m/^#/; # skip comments
2755 my ($mime, $exts) = split(/\t+/);
2756 if (defined $exts) {
2757 my @exts = split(/\s+/, $exts);
2758 foreach my $ext (@exts) {
2759 $mimemap{$ext} = $mime;
2765 $filename =~ /\.([^.]*)$/;
2766 return $mimemap{$1};
2769 sub mimetype_guess
{
2770 my $filename = shift;
2772 $filename =~ /\./ or return undef;
2774 if ($mimetypes_file) {
2775 my $file = $mimetypes_file;
2776 if ($file !~ m!^/!) { # if it is relative path
2777 # it is relative to project
2778 $file = "$projectroot/$project/$file";
2780 $mime = mimetype_guess_file
($filename, $file);
2782 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2788 my $filename = shift;
2791 my $mime = mimetype_guess
($filename);
2792 $mime and return $mime;
2796 return $default_blob_plain_mimetype unless $fd;
2799 return 'text/plain';
2800 } elsif (! $filename) {
2801 return 'application/octet-stream';
2802 } elsif ($filename =~ m/\.png$/i) {
2804 } elsif ($filename =~ m/\.gif$/i) {
2806 } elsif ($filename =~ m/\.jpe?g$/i) {
2807 return 'image/jpeg';
2809 return 'application/octet-stream';
2813 sub blob_contenttype
{
2814 my ($fd, $file_name, $type) = @_;
2816 $type ||= blob_mimetype
($fd, $file_name);
2817 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2818 $type .= "; charset=$default_text_plain_charset";
2824 ## ======================================================================
2825 ## functions printing HTML: header, footer, error page
2827 sub git_header_html
{
2828 my $status = shift || "200 OK";
2829 my $expires = shift;
2831 my $title = "$site_name";
2832 if (defined $project) {
2833 $title .= " - " . to_utf8
($project);
2834 if (defined $action) {
2835 $title .= "/$action";
2836 if (defined $file_name) {
2837 $title .= " - " . esc_path
($file_name);
2838 if ($action eq "tree" && $file_name !~ m
|/$|) {
2845 # require explicit support from the UA if we are to send the page as
2846 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2847 # we have to do this because MSIE sometimes globs '*/*', pretending to
2848 # support xhtml+xml but choking when it gets what it asked for.
2849 if (defined $cgi->http('HTTP_ACCEPT') &&
2850 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2851 $cgi->Accept('application/xhtml+xml') != 0) {
2852 $content_type = 'application/xhtml+xml';
2854 $content_type = 'text/html';
2856 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2857 -status
=> $status, -expires
=> $expires);
2858 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2860 <?xml version="1.0" encoding="utf-8"?>
2861 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2862 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2863 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2864 <!-- git core binaries version $git_version -->
2866 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2867 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2868 <meta name="robots" content="index, nofollow"/>
2869 <title>$title</title>
2871 # print out each stylesheet that exist
2872 if (defined $stylesheet) {
2873 #provides backwards capability for those people who define style sheet in a config file
2874 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2876 foreach my $stylesheet (@stylesheets) {
2877 next unless $stylesheet;
2878 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2881 if (defined $project) {
2882 my %href_params = get_feed_info
();
2883 if (!exists $href_params{'-title'}) {
2884 $href_params{'-title'} = 'log';
2887 foreach my $format qw(RSS Atom) {
2888 my $type = lc($format);
2890 '-rel' => 'alternate',
2891 '-title' => "$project - $href_params{'-title'} - $format feed",
2892 '-type' => "application/$type+xml"
2895 $href_params{'action'} = $type;
2896 $link_attr{'-href'} = href
(%href_params);
2898 "rel=\"$link_attr{'-rel'}\" ".
2899 "title=\"$link_attr{'-title'}\" ".
2900 "href=\"$link_attr{'-href'}\" ".
2901 "type=\"$link_attr{'-type'}\" ".
2904 $href_params{'extra_options'} = '--no-merges';
2905 $link_attr{'-href'} = href
(%href_params);
2906 $link_attr{'-title'} .= ' (no merges)';
2908 "rel=\"$link_attr{'-rel'}\" ".
2909 "title=\"$link_attr{'-title'}\" ".
2910 "href=\"$link_attr{'-href'}\" ".
2911 "type=\"$link_attr{'-type'}\" ".
2916 printf('<link rel="alternate" title="%s projects list" '.
2917 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2918 $site_name, href
(project
=>undef, action
=>"project_index"));
2919 printf('<link rel="alternate" title="%s projects feeds" '.
2920 'href="%s" type="text/x-opml" />'."\n",
2921 $site_name, href
(project
=>undef, action
=>"opml"));
2923 if (defined $favicon) {
2924 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2930 if (-f
$site_header) {
2931 open (my $fd, $site_header);
2936 print "<div class=\"page_header\">\n" .
2937 $cgi->a({-href
=> esc_url
($logo_url),
2938 -title
=> $logo_label},
2939 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2940 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2941 if (defined $project) {
2942 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2943 if (defined $action) {
2950 my ($have_search) = gitweb_check_feature
('search');
2951 if (defined $project && $have_search) {
2952 if (!defined $searchtext) {
2956 if (defined $hash_base) {
2957 $search_hash = $hash_base;
2958 } elsif (defined $hash) {
2959 $search_hash = $hash;
2961 $search_hash = "HEAD";
2963 my $action = $my_uri;
2964 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2965 if ($use_pathinfo) {
2966 $action .= "/".esc_url
($project);
2968 print $cgi->startform(-method
=> "get", -action
=> $action) .
2969 "<div class=\"search\">\n" .
2971 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2972 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2973 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2974 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2975 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2976 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2978 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2979 "<span title=\"Extended regular expression\">" .
2980 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2981 -checked
=> $search_use_regexp) .
2984 $cgi->end_form() . "\n";
2988 sub git_footer_html
{
2989 my $feed_class = 'rss_logo';
2991 print "<div class=\"page_footer\">\n";
2992 if (defined $project) {
2993 my $descr = git_get_project_description
($project);
2994 if (defined $descr) {
2995 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2998 my %href_params = get_feed_info
();
2999 if (!%href_params) {
3000 $feed_class .= ' generic';
3002 $href_params{'-title'} ||= 'log';
3004 foreach my $format qw(RSS Atom) {
3005 $href_params{'action'} = lc($format);
3006 print $cgi->a({-href
=> href
(%href_params),
3007 -title
=> "$href_params{'-title'} $format feed",
3008 -class => $feed_class}, $format)."\n";
3012 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3013 -class => $feed_class}, "OPML") . " ";
3014 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3015 -class => $feed_class}, "TXT") . "\n";
3017 print "</div>\n"; # class="page_footer"
3019 if (-f
$site_footer) {
3020 open (my $fd, $site_footer);
3029 # die_error(<http_status_code>, <error_message>)
3030 # Example: die_error(404, 'Hash not found')
3031 # By convention, use the following status codes (as defined in RFC 2616):
3032 # 400: Invalid or missing CGI parameters, or
3033 # requested object exists but has wrong type.
3034 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3035 # this server or project.
3036 # 404: Requested object/revision/project doesn't exist.
3037 # 500: The server isn't configured properly, or
3038 # an internal error occurred (e.g. failed assertions caused by bugs), or
3039 # an unknown error occurred (e.g. the git binary died unexpectedly).
3041 my $status = shift || 500;
3042 my $error = shift || "Internal server error";
3044 my %http_responses = (400 => '400 Bad Request',
3045 403 => '403 Forbidden',
3046 404 => '404 Not Found',
3047 500 => '500 Internal Server Error');
3048 git_header_html
($http_responses{$status});
3050 <div class="page_body">
3060 ## ----------------------------------------------------------------------
3061 ## functions printing or outputting HTML: navigation
3063 sub git_print_page_nav
{
3064 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3065 $extra = '' if !defined $extra; # pager or formats
3067 my @navs = qw(summary shortlog log commit commitdiff tree);
3069 @navs = grep { $_ ne $suppress } @navs;
3072 my %arg = map { $_ => {action
=>$_} } @navs;
3073 if (defined $head) {
3074 for (qw(commit commitdiff)) {
3075 $arg{$_}{'hash'} = $head;
3077 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3078 for (qw(shortlog log)) {
3079 $arg{$_}{'hash'} = $head;
3084 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3085 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3087 my @actions = gitweb_check_feature
('actions');
3090 'n' => $project, # project name
3091 'f' => $git_dir, # project path within filesystem
3092 'h' => $treehead || '', # current hash ('h' parameter)
3093 'b' => $treebase || '', # hash base ('hb' parameter)
3096 my ($label, $link, $pos) = splice(@actions,0,3);
3098 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3100 $link =~ s/%([%nfhb])/$repl{$1}/g;
3101 $arg{$label}{'_href'} = $link;
3104 print "<div class=\"page_nav\">\n" .
3106 map { $_ eq $current ?
3107 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3109 print "<br/>\n$extra<br/>\n" .
3113 sub format_paging_nav
{
3114 my ($action, $hash, $head, $page, $has_next_link) = @_;
3118 if ($hash ne $head || $page) {
3119 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3121 $paging_nav .= "HEAD";
3125 $paging_nav .= " ⋅ " .
3126 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3127 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3129 $paging_nav .= " ⋅ prev";
3132 if ($has_next_link) {
3133 $paging_nav .= " ⋅ " .
3134 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3135 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3137 $paging_nav .= " ⋅ next";
3143 ## ......................................................................
3144 ## functions printing or outputting HTML: div
3146 sub git_print_header_div
{
3147 my ($action, $title, $hash, $hash_base) = @_;
3150 $args{'action'} = $action;
3151 $args{'hash'} = $hash if $hash;
3152 $args{'hash_base'} = $hash_base if $hash_base;
3154 print "<div class=\"header\">\n" .
3155 $cgi->a({-href
=> href
(%args), -class => "title"},
3156 $title ?
$title : $action) .
3160 #sub git_print_authorship (\%) {
3161 sub git_print_authorship
{
3164 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3165 print "<div class=\"author_date\">" .
3166 esc_html
($co->{'author_name'}) .
3168 if ($ad{'hour_local'} < 6) {
3169 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3170 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3172 printf(" (%02d:%02d %s)",
3173 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3178 sub git_print_page_path
{
3184 print "<div class=\"page_path\">";
3185 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3186 -title
=> 'tree root'}, to_utf8
("[$project]"));
3188 if (defined $name) {
3189 my @dirname = split '/', $name;
3190 my $basename = pop @dirname;
3193 foreach my $dir (@dirname) {
3194 $fullname .= ($fullname ?
'/' : '') . $dir;
3195 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3197 -title
=> $fullname}, esc_path
($dir));
3200 if (defined $type && $type eq 'blob') {
3201 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3203 -title
=> $name}, esc_path
($basename));
3204 } elsif (defined $type && $type eq 'tree') {
3205 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3207 -title
=> $name}, esc_path
($basename));
3210 print esc_path
($basename);
3213 print "<br/></div>\n";
3216 # sub git_print_log (\@;%) {
3217 sub git_print_log
($;%) {
3221 if ($opts{'-remove_title'}) {
3222 # remove title, i.e. first line of log
3225 # remove leading empty lines
3226 while (defined $log->[0] && $log->[0] eq "") {
3233 foreach my $line (@
$log) {
3234 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3237 if (! $opts{'-remove_signoff'}) {
3238 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3241 # remove signoff lines
3248 # print only one empty line
3249 # do not print empty line after signoff
3251 next if ($empty || $signoff);
3257 print format_log_line_html
($line) . "<br/>\n";
3260 if ($opts{'-final_empty_line'}) {
3261 # end with single empty line
3262 print "<br/>\n" unless $empty;
3266 # return link target (what link points to)
3267 sub git_get_link_target
{
3272 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3276 $link_target = <$fd>;
3281 return $link_target;
3284 # given link target, and the directory (basedir) the link is in,
3285 # return target of link relative to top directory (top tree);
3286 # return undef if it is not possible (including absolute links).
3287 sub normalize_link_target
{
3288 my ($link_target, $basedir, $hash_base) = @_;
3290 # we can normalize symlink target only if $hash_base is provided
3291 return unless $hash_base;
3293 # absolute symlinks (beginning with '/') cannot be normalized
3294 return if (substr($link_target, 0, 1) eq '/');
3296 # normalize link target to path from top (root) tree (dir)
3299 $path = $basedir . '/' . $link_target;
3301 # we are in top (root) tree (dir)
3302 $path = $link_target;
3305 # remove //, /./, and /../
3307 foreach my $part (split('/', $path)) {
3308 # discard '.' and ''
3309 next if (!$part || $part eq '.');
3311 if ($part eq '..') {
3315 # link leads outside repository (outside top dir)
3319 push @path_parts, $part;
3322 $path = join('/', @path_parts);
3327 # print tree entry (row of git_tree), but without encompassing <tr> element
3328 sub git_print_tree_entry
{
3329 my ($t, $basedir, $hash_base, $have_blame) = @_;
3332 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3334 # The format of a table row is: mode list link. Where mode is
3335 # the mode of the entry, list is the name of the entry, an href,
3336 # and link is the action links of the entry.
3338 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3339 if ($t->{'type'} eq "blob") {
3340 print "<td class=\"list\">" .
3341 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3342 file_name
=>"$basedir$t->{'name'}", %base_key),
3343 -class => "list"}, esc_path
($t->{'name'}));
3344 if (S_ISLNK
(oct $t->{'mode'})) {
3345 my $link_target = git_get_link_target
($t->{'hash'});
3347 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3348 if (defined $norm_target) {
3350 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3351 file_name
=>$norm_target),
3352 -title
=> $norm_target}, esc_path
($link_target));
3354 print " -> " . esc_path
($link_target);
3359 print "<td class=\"link\">";
3360 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3361 file_name
=>"$basedir$t->{'name'}", %base_key)},
3365 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3366 file_name
=>"$basedir$t->{'name'}", %base_key)},
3369 if (defined $hash_base) {
3371 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3372 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3376 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3377 file_name
=>"$basedir$t->{'name'}")},
3381 } elsif ($t->{'type'} eq "tree") {
3382 print "<td class=\"list\">";
3383 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3384 file_name
=>"$basedir$t->{'name'}", %base_key)},
3385 esc_path
($t->{'name'}));
3387 print "<td class=\"link\">";
3388 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3389 file_name
=>"$basedir$t->{'name'}", %base_key)},
3391 if (defined $hash_base) {
3393 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3394 file_name
=>"$basedir$t->{'name'}")},
3399 # unknown object: we can only present history for it
3400 # (this includes 'commit' object, i.e. submodule support)
3401 print "<td class=\"list\">" .
3402 esc_path
($t->{'name'}) .
3404 print "<td class=\"link\">";
3405 if (defined $hash_base) {
3406 print $cgi->a({-href
=> href
(action
=>"history",
3407 hash_base
=>$hash_base,
3408 file_name
=>"$basedir$t->{'name'}")},
3415 ## ......................................................................
3416 ## functions printing large fragments of HTML
3418 # get pre-image filenames for merge (combined) diff
3419 sub fill_from_file_info
{
3420 my ($diff, @parents) = @_;
3422 $diff->{'from_file'} = [ ];
3423 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3424 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3425 if ($diff->{'status'}[$i] eq 'R' ||
3426 $diff->{'status'}[$i] eq 'C') {
3427 $diff->{'from_file'}[$i] =
3428 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3435 # is current raw difftree line of file deletion
3437 my $diffinfo = shift;
3439 return $diffinfo->{'to_id'} eq ('0' x
40);
3442 # does patch correspond to [previous] difftree raw line
3443 # $diffinfo - hashref of parsed raw diff format
3444 # $patchinfo - hashref of parsed patch diff format
3445 # (the same keys as in $diffinfo)
3446 sub is_patch_split
{
3447 my ($diffinfo, $patchinfo) = @_;
3449 return defined $diffinfo && defined $patchinfo
3450 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3454 sub git_difftree_body
{
3455 my ($difftree, $hash, @parents) = @_;
3456 my ($parent) = $parents[0];
3457 my ($have_blame) = gitweb_check_feature
('blame');
3458 print "<div class=\"list_head\">\n";
3459 if ($#{$difftree} > 10) {
3460 print(($#{$difftree} + 1) . " files changed:\n");
3464 print "<table class=\"" .
3465 (@parents > 1 ?
"combined " : "") .
3468 # header only for combined diff in 'commitdiff' view
3469 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3472 print "<thead><tr>\n" .
3473 "<th></th><th></th>\n"; # filename, patchN link
3474 for (my $i = 0; $i < @parents; $i++) {
3475 my $par = $parents[$i];
3477 $cgi->a({-href
=> href
(action
=>"commitdiff",
3478 hash
=>$hash, hash_parent
=>$par),
3479 -title
=> 'commitdiff to parent number ' .
3480 ($i+1) . ': ' . substr($par,0,7)},
3484 print "</tr></thead>\n<tbody>\n";
3489 foreach my $line (@
{$difftree}) {
3490 my $diff = parsed_difftree_line
($line);
3493 print "<tr class=\"dark\">\n";
3495 print "<tr class=\"light\">\n";
3499 if (exists $diff->{'nparents'}) { # combined diff
3501 fill_from_file_info
($diff, @parents)
3502 unless exists $diff->{'from_file'};
3504 if (!is_deleted
($diff)) {
3505 # file exists in the result (child) commit
3507 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3508 file_name
=>$diff->{'to_file'},
3510 -class => "list"}, esc_path
($diff->{'to_file'})) .
3514 esc_path
($diff->{'to_file'}) .
3518 if ($action eq 'commitdiff') {
3521 print "<td class=\"link\">" .
3522 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3527 my $has_history = 0;
3528 my $not_deleted = 0;
3529 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3530 my $hash_parent = $parents[$i];
3531 my $from_hash = $diff->{'from_id'}[$i];
3532 my $from_path = $diff->{'from_file'}[$i];
3533 my $status = $diff->{'status'}[$i];
3535 $has_history ||= ($status ne 'A');
3536 $not_deleted ||= ($status ne 'D');
3538 if ($status eq 'A') {
3539 print "<td class=\"link\" align=\"right\"> | </td>\n";
3540 } elsif ($status eq 'D') {
3541 print "<td class=\"link\">" .
3542 $cgi->a({-href
=> href
(action
=>"blob",
3545 file_name
=>$from_path)},
3549 if ($diff->{'to_id'} eq $from_hash) {
3550 print "<td class=\"link nochange\">";
3552 print "<td class=\"link\">";
3554 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3555 hash
=>$diff->{'to_id'},
3556 hash_parent
=>$from_hash,
3558 hash_parent_base
=>$hash_parent,
3559 file_name
=>$diff->{'to_file'},
3560 file_parent
=>$from_path)},
3566 print "<td class=\"link\">";
3568 print $cgi->a({-href
=> href
(action
=>"blob",
3569 hash
=>$diff->{'to_id'},
3570 file_name
=>$diff->{'to_file'},
3573 print " | " if ($has_history);
3576 print $cgi->a({-href
=> href
(action
=>"history",
3577 file_name
=>$diff->{'to_file'},
3584 next; # instead of 'else' clause, to avoid extra indent
3586 # else ordinary diff
3588 my ($to_mode_oct, $to_mode_str, $to_file_type);
3589 my ($from_mode_oct, $from_mode_str, $from_file_type);
3590 if ($diff->{'to_mode'} ne ('0' x
6)) {
3591 $to_mode_oct = oct $diff->{'to_mode'};
3592 if (S_ISREG
($to_mode_oct)) { # only for regular file
3593 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3595 $to_file_type = file_type
($diff->{'to_mode'});
3597 if ($diff->{'from_mode'} ne ('0' x
6)) {
3598 $from_mode_oct = oct $diff->{'from_mode'};
3599 if (S_ISREG
($to_mode_oct)) { # only for regular file
3600 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3602 $from_file_type = file_type
($diff->{'from_mode'});
3605 if ($diff->{'status'} eq "A") { # created
3606 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3607 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3608 $mode_chng .= "]</span>";
3610 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3611 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3612 -class => "list"}, esc_path
($diff->{'file'}));
3614 print "<td>$mode_chng</td>\n";
3615 print "<td class=\"link\">";
3616 if ($action eq 'commitdiff') {
3619 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3622 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3623 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3627 } elsif ($diff->{'status'} eq "D") { # deleted
3628 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3630 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3631 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3632 -class => "list"}, esc_path
($diff->{'file'}));
3634 print "<td>$mode_chng</td>\n";
3635 print "<td class=\"link\">";
3636 if ($action eq 'commitdiff') {
3639 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3642 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3643 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3646 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3647 file_name
=>$diff->{'file'})},
3650 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3651 file_name
=>$diff->{'file'})},
3655 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3656 my $mode_chnge = "";
3657 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3658 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3659 if ($from_file_type ne $to_file_type) {
3660 $mode_chnge .= " from $from_file_type to $to_file_type";
3662 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3663 if ($from_mode_str && $to_mode_str) {
3664 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3665 } elsif ($to_mode_str) {
3666 $mode_chnge .= " mode: $to_mode_str";
3669 $mode_chnge .= "]</span>\n";
3672 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3673 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3674 -class => "list"}, esc_path
($diff->{'file'}));
3676 print "<td>$mode_chnge</td>\n";
3677 print "<td class=\"link\">";
3678 if ($action eq 'commitdiff') {
3681 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3683 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3684 # "commit" view and modified file (not onlu mode changed)
3685 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3686 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3687 hash_base
=>$hash, hash_parent_base
=>$parent,
3688 file_name
=>$diff->{'file'})},
3692 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3693 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3696 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3697 file_name
=>$diff->{'file'})},
3700 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3701 file_name
=>$diff->{'file'})},
3705 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3706 my %status_name = ('R' => 'moved', 'C' => 'copied');
3707 my $nstatus = $status_name{$diff->{'status'}};
3709 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3710 # mode also for directories, so we cannot use $to_mode_str
3711 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3714 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3715 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3716 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3717 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3718 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3719 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3720 -class => "list"}, esc_path
($diff->{'from_file'})) .
3721 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3722 "<td class=\"link\">";
3723 if ($action eq 'commitdiff') {
3726 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3728 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3729 # "commit" view and modified file (not only pure rename or copy)
3730 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3731 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3732 hash_base
=>$hash, hash_parent_base
=>$parent,
3733 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3737 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3738 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3741 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3742 file_name
=>$diff->{'to_file'})},
3745 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3746 file_name
=>$diff->{'to_file'})},
3750 } # we should not encounter Unmerged (U) or Unknown (X) status
3753 print "</tbody>" if $has_header;
3757 sub git_patchset_body
{
3758 my ($fd, $difftree, $hash, @hash_parents) = @_;
3759 my ($hash_parent) = $hash_parents[0];
3761 my $is_combined = (@hash_parents > 1);
3763 my $patch_number = 0;
3769 print "<div class=\"patchset\">\n";
3771 # skip to first patch
3772 while ($patch_line = <$fd>) {
3775 last if ($patch_line =~ m/^diff /);
3779 while ($patch_line) {
3781 # parse "git diff" header line
3782 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3783 # $1 is from_name, which we do not use
3784 $to_name = unquote
($2);
3785 $to_name =~ s!^b/!!;
3786 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3787 # $1 is 'cc' or 'combined', which we do not use
3788 $to_name = unquote
($2);
3793 # check if current patch belong to current raw line
3794 # and parse raw git-diff line if needed
3795 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3796 # this is continuation of a split patch
3797 print "<div class=\"patch cont\">\n";
3799 # advance raw git-diff output if needed
3800 $patch_idx++ if defined $diffinfo;
3802 # read and prepare patch information
3803 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3805 # compact combined diff output can have some patches skipped
3806 # find which patch (using pathname of result) we are at now;
3808 while ($to_name ne $diffinfo->{'to_file'}) {
3809 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3810 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3811 "</div>\n"; # class="patch"
3816 last if $patch_idx > $#$difftree;
3817 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3821 # modifies %from, %to hashes
3822 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3824 # this is first patch for raw difftree line with $patch_idx index
3825 # we index @$difftree array from 0, but number patches from 1
3826 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3830 #assert($patch_line =~ m/^diff /) if DEBUG;
3831 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3833 # print "git diff" header
3834 print format_git_diff_header_line
($patch_line, $diffinfo,
3837 # print extended diff header
3838 print "<div class=\"diff extended_header\">\n";
3840 while ($patch_line = <$fd>) {
3843 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3845 print format_extended_diff_header_line
($patch_line, $diffinfo,
3848 print "</div>\n"; # class="diff extended_header"
3850 # from-file/to-file diff header
3851 if (! $patch_line) {
3852 print "</div>\n"; # class="patch"
3855 next PATCH
if ($patch_line =~ m/^diff /);
3856 #assert($patch_line =~ m/^---/) if DEBUG;
3858 my $last_patch_line = $patch_line;
3859 $patch_line = <$fd>;
3861 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3863 print format_diff_from_to_header
($last_patch_line, $patch_line,
3864 $diffinfo, \
%from, \
%to,
3869 while ($patch_line = <$fd>) {
3872 next PATCH
if ($patch_line =~ m/^diff /);
3874 print format_diff_line
($patch_line, \
%from, \
%to);
3878 print "</div>\n"; # class="patch"
3881 # for compact combined (--cc) format, with chunk and patch simpliciaction
3882 # patchset might be empty, but there might be unprocessed raw lines
3883 for (++$patch_idx if $patch_number > 0;
3884 $patch_idx < @
$difftree;
3886 # read and prepare patch information
3887 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3889 # generate anchor for "patch" links in difftree / whatchanged part
3890 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3891 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3892 "</div>\n"; # class="patch"
3897 if ($patch_number == 0) {
3898 if (@hash_parents > 1) {
3899 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3901 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3905 print "</div>\n"; # class="patchset"
3908 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3910 # fills project list info (age, description, owner, forks) for each
3911 # project in the list, removing invalid projects from returned list
3912 # NOTE: modifies $projlist, but does not remove entries from it
3913 sub fill_project_list_info
{
3914 my ($projlist, $check_forks) = @_;
3917 my $show_ctags = gitweb_check_feature
('ctags');
3919 foreach my $pr (@
$projlist) {
3920 my (@activity) = git_get_last_activity
($pr->{'path'});
3921 unless (@activity) {
3924 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3925 if (!defined $pr->{'descr'}) {
3926 my $descr = git_get_project_description
($pr->{'path'}) || "";
3927 $descr = to_utf8
($descr);
3928 $pr->{'descr_long'} = $descr;
3929 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3931 if (!defined $pr->{'owner'}) {
3932 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3935 my $pname = $pr->{'path'};
3936 if (($pname =~ s/\.git$//) &&
3937 ($pname !~ /\/$/) &&
3938 (-d
"$projectroot/$pname")) {
3939 $pr->{'forks'} = "-d $projectroot/$pname";
3944 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3945 push @projects, $pr;
3951 # print 'sort by' <th> element, generating 'sort by $name' replay link
3952 # if that order is not selected
3954 my ($name, $order, $header) = @_;
3955 $header ||= ucfirst($name);
3957 if ($order eq $name) {
3958 print "<th>$header</th>\n";
3961 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3962 -class => "header"}, $header) .
3967 sub git_project_list_body
{
3968 # actually uses global variable $project
3969 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3971 my ($check_forks) = gitweb_check_feature
('forks');
3972 my @projects = fill_project_list_info
($projlist, $check_forks);
3974 $order ||= $default_projects_order;
3975 $from = 0 unless defined $from;
3976 $to = $#projects if (!defined $to || $#projects < $to);
3979 project
=> { key
=> 'path', type
=> 'str' },
3980 descr
=> { key
=> 'descr_long', type
=> 'str' },
3981 owner
=> { key
=> 'owner', type
=> 'str' },
3982 age
=> { key
=> 'age', type
=> 'num' }
3984 my $oi = $order_info{$order};
3985 if ($oi->{'type'} eq 'str') {
3986 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3988 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3991 my $show_ctags = gitweb_check_feature
('ctags');
3994 foreach my $p (@projects) {
3995 foreach my $ct (keys %{$p->{'ctags'}}) {
3996 $ctags{$ct} += $p->{'ctags'}->{$ct};
3999 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4000 print git_show_project_tagcloud
($cloud, 64);
4003 print "<table class=\"project_list\">\n";
4004 unless ($no_header) {
4007 print "<th></th>\n";
4009 print_sort_th
('project', $order, 'Project');
4010 print_sort_th
('descr', $order, 'Description');
4011 print_sort_th
('owner', $order, 'Owner');
4012 print_sort_th
('age', $order, 'Last Change');
4013 print "<th></th>\n" . # for links
4017 my $tagfilter = $cgi->param('by_tag');
4018 for (my $i = $from; $i <= $to; $i++) {
4019 my $pr = $projects[$i];
4021 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4022 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4023 and not $pr->{'descr_long'} =~ /$searchtext/;
4024 # Weed out forks or non-matching entries of search
4026 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4027 $forkbase="^$forkbase" if $forkbase;
4028 next if not $searchtext and not $tagfilter and $show_ctags
4029 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4033 print "<tr class=\"dark\">\n";
4035 print "<tr class=\"light\">\n";
4040 if ($pr->{'forks'}) {
4041 print "<!-- $pr->{'forks'} -->\n";
4042 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4046 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4047 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4048 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4049 -class => "list", -title
=> $pr->{'descr_long'}},
4050 esc_html
($pr->{'descr'})) . "</td>\n" .
4051 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4052 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4053 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4054 "<td class=\"link\">" .
4055 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4056 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4057 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4058 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4059 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4063 if (defined $extra) {
4066 print "<td></td>\n";
4068 print "<td colspan=\"5\">$extra</td>\n" .
4074 sub git_shortlog_body
{
4075 # uses global variable $project
4076 my ($commitlist, $from, $to, $refs, $extra) = @_;
4078 $from = 0 unless defined $from;
4079 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4081 print "<table class=\"shortlog\">\n";
4083 for (my $i = $from; $i <= $to; $i++) {
4084 my %co = %{$commitlist->[$i]};
4085 my $commit = $co{'id'};
4086 my $ref = format_ref_marker
($refs, $commit);
4088 print "<tr class=\"dark\">\n";
4090 print "<tr class=\"light\">\n";
4093 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4094 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4095 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4096 "<td><i>" . $author . "</i></td>\n" .
4098 print format_subject_html
($co{'title'}, $co{'title_short'},
4099 href
(action
=>"commit", hash
=>$commit), $ref);
4101 "<td class=\"link\">" .
4102 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4103 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4104 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4105 my $snapshot_links = format_snapshot_links
($commit);
4106 if (defined $snapshot_links) {
4107 print " | " . $snapshot_links;
4112 if (defined $extra) {
4114 "<td colspan=\"4\">$extra</td>\n" .
4120 sub git_history_body
{
4121 # Warning: assumes constant type (blob or tree) during history
4122 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4124 $from = 0 unless defined $from;
4125 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4127 print "<table class=\"history\">\n";
4129 for (my $i = $from; $i <= $to; $i++) {
4130 my %co = %{$commitlist->[$i]};
4134 my $commit = $co{'id'};
4136 my $ref = format_ref_marker
($refs, $commit);
4139 print "<tr class=\"dark\">\n";
4141 print "<tr class=\"light\">\n";
4144 # shortlog uses chop_str($co{'author_name'}, 10)
4145 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4146 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4147 "<td><i>" . $author . "</i></td>\n" .
4149 # originally git_history used chop_str($co{'title'}, 50)
4150 print format_subject_html
($co{'title'}, $co{'title_short'},
4151 href
(action
=>"commit", hash
=>$commit), $ref);
4153 "<td class=\"link\">" .
4154 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4155 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4157 if ($ftype eq 'blob') {
4158 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4159 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4160 if (defined $blob_current && defined $blob_parent &&
4161 $blob_current ne $blob_parent) {
4163 $cgi->a({-href
=> href
(action
=>"blobdiff",
4164 hash
=>$blob_current, hash_parent
=>$blob_parent,
4165 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4166 file_name
=>$file_name)},
4173 if (defined $extra) {
4175 "<td colspan=\"4\">$extra</td>\n" .
4182 # uses global variable $project
4183 my ($taglist, $from, $to, $extra) = @_;
4184 $from = 0 unless defined $from;
4185 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4187 print "<table class=\"tags\">\n";
4189 for (my $i = $from; $i <= $to; $i++) {
4190 my $entry = $taglist->[$i];
4192 my $comment = $tag{'subject'};
4194 if (defined $comment) {
4195 $comment_short = chop_str
($comment, 30, 5);
4198 print "<tr class=\"dark\">\n";
4200 print "<tr class=\"light\">\n";
4203 if (defined $tag{'age'}) {
4204 print "<td><i>$tag{'age'}</i></td>\n";
4206 print "<td></td>\n";
4209 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4210 -class => "list name"}, esc_html
($tag{'name'})) .
4213 if (defined $comment) {
4214 print format_subject_html
($comment, $comment_short,
4215 href
(action
=>"tag", hash
=>$tag{'id'}));
4218 "<td class=\"selflink\">";
4219 if ($tag{'type'} eq "tag") {
4220 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4225 "<td class=\"link\">" . " | " .
4226 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4227 if ($tag{'reftype'} eq "commit") {
4228 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4229 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4230 } elsif ($tag{'reftype'} eq "blob") {
4231 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4236 if (defined $extra) {
4238 "<td colspan=\"5\">$extra</td>\n" .
4244 sub git_heads_body
{
4245 # uses global variable $project
4246 my ($headlist, $head, $from, $to, $extra) = @_;
4247 $from = 0 unless defined $from;
4248 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4250 print "<table class=\"heads\">\n";
4252 for (my $i = $from; $i <= $to; $i++) {
4253 my $entry = $headlist->[$i];
4255 my $curr = $ref{'id'} eq $head;
4257 print "<tr class=\"dark\">\n";
4259 print "<tr class=\"light\">\n";
4262 print "<td><i>$ref{'age'}</i></td>\n" .
4263 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4264 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4265 -class => "list name"},esc_html
($ref{'name'})) .
4267 "<td class=\"link\">" .
4268 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4269 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4270 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4274 if (defined $extra) {
4276 "<td colspan=\"3\">$extra</td>\n" .
4282 sub git_search_grep_body
{
4283 my ($commitlist, $from, $to, $extra) = @_;
4284 $from = 0 unless defined $from;
4285 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4287 print "<table class=\"commit_search\">\n";
4289 for (my $i = $from; $i <= $to; $i++) {
4290 my %co = %{$commitlist->[$i]};
4294 my $commit = $co{'id'};
4296 print "<tr class=\"dark\">\n";
4298 print "<tr class=\"light\">\n";
4301 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4302 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4303 "<td><i>" . $author . "</i></td>\n" .
4305 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4306 -class => "list subject"},
4307 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4308 my $comment = $co{'comment'};
4309 foreach my $line (@
$comment) {
4310 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4311 my ($lead, $match, $trail) = ($1, $2, $3);
4312 $match = chop_str
($match, 70, 5, 'center');
4313 my $contextlen = int((80 - length($match))/2);
4314 $contextlen = 30 if ($contextlen > 30);
4315 $lead = chop_str
($lead, $contextlen, 10, 'left');
4316 $trail = chop_str
($trail, $contextlen, 10, 'right');
4318 $lead = esc_html
($lead);
4319 $match = esc_html
($match);
4320 $trail = esc_html
($trail);
4322 print "$lead<span class=\"match\">$match</span>$trail<br />";
4326 "<td class=\"link\">" .
4327 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4329 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4331 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4335 if (defined $extra) {
4337 "<td colspan=\"3\">$extra</td>\n" .
4343 ## ======================================================================
4344 ## ======================================================================
4347 sub git_project_list
{
4348 my $order = $input_params{'order'};
4349 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4350 die_error
(400, "Unknown order parameter");
4353 my @list = git_get_projects_list
();
4355 die_error
(404, "No projects found");
4359 if (-f
$home_text) {
4360 print "<div class=\"index_include\">\n";
4361 open (my $fd, $home_text);
4366 print $cgi->startform(-method
=> "get") .
4367 "<p class=\"projsearch\">Search:\n" .
4368 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4370 $cgi->end_form() . "\n";
4371 git_project_list_body
(\
@list, $order);
4376 my $order = $input_params{'order'};
4377 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4378 die_error
(400, "Unknown order parameter");
4381 my @list = git_get_projects_list
($project);
4383 die_error
(404, "No forks found");
4387 git_print_page_nav
('','');
4388 git_print_header_div
('summary', "$project forks");
4389 git_project_list_body
(\
@list, $order);
4393 sub git_project_index
{
4394 my @projects = git_get_projects_list
($project);
4397 -type
=> 'text/plain',
4398 -charset
=> 'utf-8',
4399 -content_disposition
=> 'inline; filename="index.aux"');
4401 foreach my $pr (@projects) {
4402 if (!exists $pr->{'owner'}) {
4403 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4406 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4407 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4408 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4409 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4413 print "$path $owner\n";
4418 my $descr = git_get_project_description
($project) || "none";
4419 my %co = parse_commit
("HEAD");
4420 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4421 my $head = $co{'id'};
4423 my $owner = git_get_project_owner
($project);
4425 my $refs = git_get_references
();
4426 # These get_*_list functions return one more to allow us to see if
4427 # there are more ...
4428 my @taglist = git_get_tags_list
(16);
4429 my @headlist = git_get_heads_list
(16);
4431 my ($check_forks) = gitweb_check_feature
('forks');
4434 @forklist = git_get_projects_list
($project);
4438 git_print_page_nav
('summary','', $head);
4440 print "<div class=\"title\"> </div>\n";
4441 print "<table class=\"projects_list\">\n" .
4442 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4443 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4444 if (defined $cd{'rfc2822'}) {
4445 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4448 # use per project git URL list in $projectroot/$project/cloneurl
4449 # or make project git URL from git base URL and project name
4450 my $url_tag = "URL";
4451 my @url_list = git_get_project_url_list
($project);
4452 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4453 foreach my $git_url (@url_list) {
4454 next unless $git_url;
4455 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4460 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4462 my $ctags = git_get_project_ctags
($project);
4463 my $cloud = git_populate_project_tagcloud
($ctags);
4464 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4465 print "</td>\n<td>" unless %$ctags;
4466 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4467 print "</td>\n<td>" if %$ctags;
4468 print git_show_project_tagcloud
($cloud, 48);
4474 if (-s
"$projectroot/$project/README.html") {
4475 if (open my $fd, "$projectroot/$project/README.html") {
4476 print "<div class=\"title\">readme</div>\n" .
4477 "<div class=\"readme\">\n";
4478 print $_ while (<$fd>);
4479 print "\n</div>\n"; # class="readme"
4484 # we need to request one more than 16 (0..15) to check if
4486 my @commitlist = $head ? parse_commits
($head, 17) : ();
4488 git_print_header_div
('shortlog');
4489 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4490 $#commitlist <= 15 ?
undef :
4491 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4495 git_print_header_div
('tags');
4496 git_tags_body
(\
@taglist, 0, 15,
4497 $#taglist <= 15 ?
undef :
4498 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4502 git_print_header_div
('heads');
4503 git_heads_body
(\
@headlist, $head, 0, 15,
4504 $#headlist <= 15 ?
undef :
4505 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4509 git_print_header_div
('forks');
4510 git_project_list_body
(\
@forklist, 'age', 0, 15,
4511 $#forklist <= 15 ?
undef :
4512 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4520 my $head = git_get_head_hash
($project);
4522 git_print_page_nav
('','', $head,undef,$head);
4523 my %tag = parse_tag
($hash);
4526 die_error
(404, "Unknown tag object");
4529 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4530 print "<div class=\"title_text\">\n" .
4531 "<table class=\"object_header\">\n" .
4533 "<td>object</td>\n" .
4534 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4535 $tag{'object'}) . "</td>\n" .
4536 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4537 $tag{'type'}) . "</td>\n" .
4539 if (defined($tag{'author'})) {
4540 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4541 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4542 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4543 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4546 print "</table>\n\n" .
4548 print "<div class=\"page_body\">";
4549 my $comment = $tag{'comment'};
4550 foreach my $line (@
$comment) {
4552 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4562 gitweb_check_feature
('blame')
4563 or die_error
(403, "Blame view not allowed");
4565 die_error
(400, "No file name given") unless $file_name;
4566 $hash_base ||= git_get_head_hash
($project);
4567 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4568 my %co = parse_commit
($hash_base)
4569 or die_error
(404, "Commit not found");
4570 if (!defined $hash) {
4571 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4572 or die_error
(404, "Error looking up file");
4574 $ftype = git_get_type
($hash);
4575 if ($ftype !~ "blob") {
4576 die_error
(400, "Object is not a blob");
4578 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4579 $file_name, $hash_base)
4580 or die_error
(500, "Open git-blame failed");
4583 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4586 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4589 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4591 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4592 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4593 git_print_page_path
($file_name, $ftype, $hash_base);
4594 my @rev_color = (qw(light2 dark2));
4595 my $num_colors = scalar(@rev_color);
4596 my $current_color = 0;
4599 <div class="page_body">
4600 <table class="blame">
4601 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4606 last unless defined $_;
4607 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4608 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4609 if (!exists $metainfo{$full_rev}) {
4610 $metainfo{$full_rev} = {};
4612 my $meta = $metainfo{$full_rev};
4615 if (/^(\S+) (.*)$/) {
4621 my $rev = substr($full_rev, 0, 8);
4622 my $author = $meta->{'author'};
4623 my %date = parse_date
($meta->{'author-time'},
4624 $meta->{'author-tz'});
4625 my $date = $date{'iso-tz'};
4627 $current_color = ++$current_color % $num_colors;
4629 print "<tr class=\"$rev_color[$current_color]\">\n";
4631 print "<td class=\"sha1\"";
4632 print " title=\"". esc_html
($author) . ", $date\"";
4633 print " rowspan=\"$group_size\"" if ($group_size > 1);
4635 print $cgi->a({-href
=> href
(action
=>"commit",
4637 file_name
=>$file_name)},
4641 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4642 or die_error
(500, "Open git-rev-parse failed");
4643 my $parent_commit = <$dd>;
4645 chomp($parent_commit);
4646 my $blamed = href
(action
=> 'blame',
4647 file_name
=> $meta->{'filename'},
4648 hash_base
=> $parent_commit);
4649 print "<td class=\"linenr\">";
4650 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4652 -class => "linenr" },
4655 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4661 or print "Reading blob failed\n";
4666 my $head = git_get_head_hash
($project);
4668 git_print_page_nav
('','', $head,undef,$head);
4669 git_print_header_div
('summary', $project);
4671 my @tagslist = git_get_tags_list
();
4673 git_tags_body
(\
@tagslist);
4679 my $head = git_get_head_hash
($project);
4681 git_print_page_nav
('','', $head,undef,$head);
4682 git_print_header_div
('summary', $project);
4684 my @headslist = git_get_heads_list
();
4686 git_heads_body
(\
@headslist, $head);
4691 sub git_blob_plain
{
4695 if (!defined $hash) {
4696 if (defined $file_name) {
4697 my $base = $hash_base || git_get_head_hash
($project);
4698 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4699 or die_error
(404, "Cannot find file");
4701 die_error
(400, "No file name defined");
4703 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4704 # blobs defined by non-textual hash id's can be cached
4708 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4709 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4711 # content-type (can include charset)
4712 $type = blob_contenttype
($fd, $file_name, $type);
4714 # "save as" filename, even when no $file_name is given
4715 my $save_as = "$hash";
4716 if (defined $file_name) {
4717 $save_as = $file_name;
4718 } elsif ($type =~ m/^text\//) {
4724 -expires
=> $expires,
4725 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4727 binmode STDOUT
, ':raw';
4729 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4737 if (!defined $hash) {
4738 if (defined $file_name) {
4739 my $base = $hash_base || git_get_head_hash
($project);
4740 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4741 or die_error
(404, "Cannot find file");
4743 die_error
(400, "No file name defined");
4745 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4746 # blobs defined by non-textual hash id's can be cached
4750 my ($have_blame) = gitweb_check_feature
('blame');
4751 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4752 or die_error
(500, "Couldn't cat $file_name, $hash");
4753 my $mimetype = blob_mimetype
($fd, $file_name);
4754 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4756 return git_blob_plain
($mimetype);
4758 # we can have blame only for text/* mimetype
4759 $have_blame &&= ($mimetype =~ m!^text/!);
4761 git_header_html
(undef, $expires);
4762 my $formats_nav = '';
4763 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4764 if (defined $file_name) {
4767 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4772 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4775 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4778 $cgi->a({-href
=> href
(action
=>"blob",
4779 hash_base
=>"HEAD", file_name
=>$file_name)},
4783 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4786 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4787 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4789 print "<div class=\"page_nav\">\n" .
4790 "<br/><br/></div>\n" .
4791 "<div class=\"title\">$hash</div>\n";
4793 git_print_page_path
($file_name, "blob", $hash_base);
4794 print "<div class=\"page_body\">\n";
4795 if ($mimetype =~ m!^image/!) {
4796 print qq!<img type
="$mimetype"!;
4798 print qq! alt
="$file_name" title
="$file_name"!;
4801 href(action=>"blob_plain
", hash=>$hash,
4802 hash_base=>$hash_base, file_name=>$file_name) .
4806 while (my $line = <$fd>) {
4809 $line = untabify
($line);
4810 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4811 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4815 or print "Reading blob failed.\n";
4821 if (!defined $hash_base) {
4822 $hash_base = "HEAD";
4824 if (!defined $hash) {
4825 if (defined $file_name) {
4826 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4831 die_error
(404, "No such tree") unless defined($hash);
4833 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4834 or die_error
(500, "Open git-ls-tree failed");
4835 my @entries = map { chomp; $_ } <$fd>;
4836 close $fd or die_error
(404, "Reading tree failed");
4839 my $refs = git_get_references
();
4840 my $ref = format_ref_marker
($refs, $hash_base);
4843 my ($have_blame) = gitweb_check_feature
('blame');
4844 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4846 if (defined $file_name) {
4848 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4850 $cgi->a({-href
=> href
(action
=>"tree",
4851 hash_base
=>"HEAD", file_name
=>$file_name)},
4854 my $snapshot_links = format_snapshot_links
($hash);
4855 if (defined $snapshot_links) {
4856 # FIXME: Should be available when we have no hash base as well.
4857 push @views_nav, $snapshot_links;
4859 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4860 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4863 print "<div class=\"page_nav\">\n";
4864 print "<br/><br/></div>\n";
4865 print "<div class=\"title\">$hash</div>\n";
4867 if (defined $file_name) {
4868 $basedir = $file_name;
4869 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4872 git_print_page_path
($file_name, 'tree', $hash_base);
4874 print "<div class=\"page_body\">\n";
4875 print "<table class=\"tree\">\n";
4877 # '..' (top directory) link if possible
4878 if (defined $hash_base &&
4879 defined $file_name && $file_name =~ m![^/]+$!) {
4881 print "<tr class=\"dark\">\n";
4883 print "<tr class=\"light\">\n";
4887 my $up = $file_name;
4888 $up =~ s!/?[^/]+$!!;
4889 undef $up unless $up;
4890 # based on git_print_tree_entry
4891 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4892 print '<td class="list">';
4893 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4897 print "<td class=\"link\"></td>\n";
4901 foreach my $line (@entries) {
4902 my %t = parse_ls_tree_line
($line, -z
=> 1);
4905 print "<tr class=\"dark\">\n";
4907 print "<tr class=\"light\">\n";
4911 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4915 print "</table>\n" .
4921 my $format = $input_params{'snapshot_format'};
4922 if (!@snapshot_fmts) {
4923 die_error
(403, "Snapshots not allowed");
4925 # default to first supported snapshot format
4926 $format ||= $snapshot_fmts[0];
4927 if ($format !~ m/^[a-z0-9]+$/) {
4928 die_error
(400, "Invalid snapshot format parameter");
4929 } elsif (!exists($known_snapshot_formats{$format})) {
4930 die_error
(400, "Unknown snapshot format");
4931 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4932 die_error
(403, "Unsupported snapshot format");
4935 if (!defined $hash) {
4936 $hash = git_get_head_hash
($project);
4939 my $name = $project;
4940 $name =~ s
,([^/])/*\
.git
$,$1,;
4941 $name = basename
($name);
4942 my $filename = to_utf8
($name);
4943 $name =~ s/\047/\047\\\047\047/g;
4945 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4946 $cmd = quote_command
(
4947 git_cmd
(), 'archive',
4948 "--format=$known_snapshot_formats{$format}{'format'}",
4949 "--prefix=$name/", $hash);
4950 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4951 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4955 -type
=> $known_snapshot_formats{$format}{'type'},
4956 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4957 -status
=> '200 OK');
4959 open my $fd, "-|", $cmd
4960 or die_error
(500, "Execute git-archive failed");
4961 binmode STDOUT
, ':raw';
4963 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4968 my $head = git_get_head_hash
($project);
4969 if (!defined $hash) {
4972 if (!defined $page) {
4975 my $refs = git_get_references
();
4977 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4979 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4982 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4985 my %co = parse_commit
($hash);
4987 git_print_header_div
('summary', $project);
4988 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4990 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4991 for (my $i = 0; $i <= $to; $i++) {
4992 my %co = %{$commitlist[$i]};
4994 my $commit = $co{'id'};
4995 my $ref = format_ref_marker
($refs, $commit);
4996 my %ad = parse_date
($co{'author_epoch'});
4997 git_print_header_div
('commit',
4998 "<span class=\"age\">$co{'age_string'}</span>" .
4999 esc_html
($co{'title'}) . $ref,
5001 print "<div class=\"title_text\">\n" .
5002 "<div class=\"log_link\">\n" .
5003 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5005 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5007 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5010 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5013 print "<div class=\"log_body\">\n";
5014 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5017 if ($#commitlist >= 100) {
5018 print "<div class=\"page_nav\">\n";
5019 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5020 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5027 $hash ||= $hash_base || "HEAD";
5028 my %co = parse_commit
($hash)
5029 or die_error
(404, "Unknown commit object");
5030 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5031 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5033 my $parent = $co{'parent'};
5034 my $parents = $co{'parents'}; # listref
5036 # we need to prepare $formats_nav before any parameter munging
5038 if (!defined $parent) {
5040 $formats_nav .= '(initial)';
5041 } elsif (@
$parents == 1) {
5042 # single parent commit
5045 $cgi->a({-href
=> href
(action
=>"commit",
5047 esc_html
(substr($parent, 0, 7))) .
5054 $cgi->a({-href
=> href
(action
=>"commit",
5056 esc_html
(substr($_, 0, 7)));
5061 if (!defined $parent) {
5065 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5067 (@
$parents <= 1 ?
$parent : '-c'),
5069 or die_error
(500, "Open git-diff-tree failed");
5070 @difftree = map { chomp; $_ } <$fd>;
5071 close $fd or die_error
(404, "Reading git-diff-tree failed");
5073 # non-textual hash id's can be cached
5075 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5078 my $refs = git_get_references
();
5079 my $ref = format_ref_marker
($refs, $co{'id'});
5081 git_header_html
(undef, $expires);
5082 git_print_page_nav
('commit', '',
5083 $hash, $co{'tree'}, $hash,
5086 if (defined $co{'parent'}) {
5087 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5089 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5091 print "<div class=\"title_text\">\n" .
5092 "<table class=\"object_header\">\n";
5093 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5095 "<td></td><td> $ad{'rfc2822'}";
5096 if ($ad{'hour_local'} < 6) {
5097 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5098 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5100 printf(" (%02d:%02d %s)",
5101 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5105 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5106 print "<tr><td></td><td> $cd{'rfc2822'}" .
5107 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5109 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5112 "<td class=\"sha1\">" .
5113 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5114 class => "list"}, $co{'tree'}) .
5116 "<td class=\"link\">" .
5117 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5119 my $snapshot_links = format_snapshot_links
($hash);
5120 if (defined $snapshot_links) {
5121 print " | " . $snapshot_links;
5126 foreach my $par (@
$parents) {
5129 "<td class=\"sha1\">" .
5130 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5131 class => "list"}, $par) .
5133 "<td class=\"link\">" .
5134 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5136 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5143 print "<div class=\"page_body\">\n";
5144 git_print_log
($co{'comment'});
5147 git_difftree_body
(\
@difftree, $hash, @
$parents);
5153 # object is defined by:
5154 # - hash or hash_base alone
5155 # - hash_base and file_name
5158 # - hash or hash_base alone
5159 if ($hash || ($hash_base && !defined $file_name)) {
5160 my $object_id = $hash || $hash_base;
5162 open my $fd, "-|", quote_command
(
5163 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5164 or die_error
(404, "Object does not exist");
5168 or die_error
(404, "Object does not exist");
5170 # - hash_base and file_name
5171 } elsif ($hash_base && defined $file_name) {
5172 $file_name =~ s
,/+$,,;
5174 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5175 or die_error
(404, "Base object does not exist");
5177 # here errors should not hapen
5178 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5179 or die_error
(500, "Open git-ls-tree failed");
5183 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5184 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5185 die_error
(404, "File or directory for given base does not exist");
5190 die_error
(400, "Not enough information to find object");
5193 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5194 hash
=>$hash, hash_base
=>$hash_base,
5195 file_name
=>$file_name),
5196 -status
=> '302 Found');
5200 my $format = shift || 'html';
5207 # preparing $fd and %diffinfo for git_patchset_body
5209 if (defined $hash_base && defined $hash_parent_base) {
5210 if (defined $file_name) {
5212 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5213 $hash_parent_base, $hash_base,
5214 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5215 or die_error
(500, "Open git-diff-tree failed");
5216 @difftree = map { chomp; $_ } <$fd>;
5218 or die_error
(404, "Reading git-diff-tree failed");
5220 or die_error
(404, "Blob diff not found");
5222 } elsif (defined $hash &&
5223 $hash =~ /[0-9a-fA-F]{40}/) {
5224 # try to find filename from $hash
5226 # read filtered raw output
5227 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5228 $hash_parent_base, $hash_base, "--"
5229 or die_error
(500, "Open git-diff-tree failed");
5231 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5233 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5234 map { chomp; $_ } <$fd>;
5236 or die_error
(404, "Reading git-diff-tree failed");
5238 or die_error
(404, "Blob diff not found");
5241 die_error
(400, "Missing one of the blob diff parameters");
5244 if (@difftree > 1) {
5245 die_error
(400, "Ambiguous blob diff specification");
5248 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5249 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5250 $file_name ||= $diffinfo{'to_file'};
5252 $hash_parent ||= $diffinfo{'from_id'};
5253 $hash ||= $diffinfo{'to_id'};
5255 # non-textual hash id's can be cached
5256 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5257 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5262 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5263 '-p', ($format eq 'html' ?
"--full-index" : ()),
5264 $hash_parent_base, $hash_base,
5265 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5266 or die_error
(500, "Open git-diff-tree failed");
5269 # old/legacy style URI
5270 if (!%diffinfo && # if new style URI failed
5271 defined $hash && defined $hash_parent) {
5272 # fake git-diff-tree raw output
5273 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5274 $diffinfo{'from_id'} = $hash_parent;
5275 $diffinfo{'to_id'} = $hash;
5276 if (defined $file_name) {
5277 if (defined $file_parent) {
5278 $diffinfo{'status'} = '2';
5279 $diffinfo{'from_file'} = $file_parent;
5280 $diffinfo{'to_file'} = $file_name;
5281 } else { # assume not renamed
5282 $diffinfo{'status'} = '1';
5283 $diffinfo{'from_file'} = $file_name;
5284 $diffinfo{'to_file'} = $file_name;
5286 } else { # no filename given
5287 $diffinfo{'status'} = '2';
5288 $diffinfo{'from_file'} = $hash_parent;
5289 $diffinfo{'to_file'} = $hash;
5292 # non-textual hash id's can be cached
5293 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5294 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5299 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5300 '-p', ($format eq 'html' ?
"--full-index" : ()),
5301 $hash_parent, $hash, "--"
5302 or die_error
(500, "Open git-diff failed");
5304 die_error
(400, "Missing one of the blob diff parameters")
5309 if ($format eq 'html') {
5311 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5313 git_header_html
(undef, $expires);
5314 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5315 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5316 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5318 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5319 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5321 if (defined $file_name) {
5322 git_print_page_path
($file_name, "blob", $hash_base);
5324 print "<div class=\"page_path\"></div>\n";
5327 } elsif ($format eq 'plain') {
5329 -type
=> 'text/plain',
5330 -charset
=> 'utf-8',
5331 -expires
=> $expires,
5332 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5334 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5337 die_error
(400, "Unknown blobdiff format");
5341 if ($format eq 'html') {
5342 print "<div class=\"page_body\">\n";
5344 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5347 print "</div>\n"; # class="page_body"
5351 while (my $line = <$fd>) {
5352 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5353 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5357 last if $line =~ m!^\+\+\+!;
5365 sub git_blobdiff_plain
{
5366 git_blobdiff
('plain');
5369 sub git_commitdiff
{
5370 my $format = shift || 'html';
5371 $hash ||= $hash_base || "HEAD";
5372 my %co = parse_commit
($hash)
5373 or die_error
(404, "Unknown commit object");
5375 # choose format for commitdiff for merge
5376 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5377 $hash_parent = '--cc';
5379 # we need to prepare $formats_nav before almost any parameter munging
5381 if ($format eq 'html') {
5383 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5386 if (defined $hash_parent &&
5387 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5388 # commitdiff with two commits given
5389 my $hash_parent_short = $hash_parent;
5390 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5391 $hash_parent_short = substr($hash_parent, 0, 7);
5395 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5396 if ($co{'parents'}[$i] eq $hash_parent) {
5397 $formats_nav .= ' parent ' . ($i+1);
5401 $formats_nav .= ': ' .
5402 $cgi->a({-href
=> href
(action
=>"commitdiff",
5403 hash
=>$hash_parent)},
5404 esc_html
($hash_parent_short)) .
5406 } elsif (!$co{'parent'}) {
5408 $formats_nav .= ' (initial)';
5409 } elsif (scalar @
{$co{'parents'}} == 1) {
5410 # single parent commit
5413 $cgi->a({-href
=> href
(action
=>"commitdiff",
5414 hash
=>$co{'parent'})},
5415 esc_html
(substr($co{'parent'}, 0, 7))) .
5419 if ($hash_parent eq '--cc') {
5420 $formats_nav .= ' | ' .
5421 $cgi->a({-href
=> href
(action
=>"commitdiff",
5422 hash
=>$hash, hash_parent
=>'-c')},
5424 } else { # $hash_parent eq '-c'
5425 $formats_nav .= ' | ' .
5426 $cgi->a({-href
=> href
(action
=>"commitdiff",
5427 hash
=>$hash, hash_parent
=>'--cc')},
5433 $cgi->a({-href
=> href
(action
=>"commitdiff",
5435 esc_html
(substr($_, 0, 7)));
5436 } @
{$co{'parents'}} ) .
5441 my $hash_parent_param = $hash_parent;
5442 if (!defined $hash_parent_param) {
5443 # --cc for multiple parents, --root for parentless
5444 $hash_parent_param =
5445 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5451 if ($format eq 'html') {
5452 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5453 "--no-commit-id", "--patch-with-raw", "--full-index",
5454 $hash_parent_param, $hash, "--"
5455 or die_error
(500, "Open git-diff-tree failed");
5457 while (my $line = <$fd>) {
5459 # empty line ends raw part of diff-tree output
5461 push @difftree, scalar parse_difftree_raw_line
($line);
5464 } elsif ($format eq 'plain') {
5465 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5466 '-p', $hash_parent_param, $hash, "--"
5467 or die_error
(500, "Open git-diff-tree failed");
5470 die_error
(400, "Unknown commitdiff format");
5473 # non-textual hash id's can be cached
5475 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5479 # write commit message
5480 if ($format eq 'html') {
5481 my $refs = git_get_references
();
5482 my $ref = format_ref_marker
($refs, $co{'id'});
5484 git_header_html
(undef, $expires);
5485 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5486 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5487 git_print_authorship
(\
%co);
5488 print "<div class=\"page_body\">\n";
5489 if (@
{$co{'comment'}} > 1) {
5490 print "<div class=\"log\">\n";
5491 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5492 print "</div>\n"; # class="log"
5495 } elsif ($format eq 'plain') {
5496 my $refs = git_get_references
("tags");
5497 my $tagname = git_get_rev_name_tags
($hash);
5498 my $filename = basename
($project) . "-$hash.patch";
5501 -type
=> 'text/plain',
5502 -charset
=> 'utf-8',
5503 -expires
=> $expires,
5504 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5505 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5506 print "From: " . to_utf8
($co{'author'}) . "\n";
5507 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5508 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5510 print "X-Git-Tag: $tagname\n" if $tagname;
5511 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5513 foreach my $line (@
{$co{'comment'}}) {
5514 print to_utf8
($line) . "\n";
5520 if ($format eq 'html') {
5521 my $use_parents = !defined $hash_parent ||
5522 $hash_parent eq '-c' || $hash_parent eq '--cc';
5523 git_difftree_body
(\
@difftree, $hash,
5524 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5527 git_patchset_body
($fd, \
@difftree, $hash,
5528 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5530 print "</div>\n"; # class="page_body"
5533 } elsif ($format eq 'plain') {
5537 or print "Reading git-diff-tree failed\n";
5541 sub git_commitdiff_plain
{
5542 git_commitdiff
('plain');
5546 if (!defined $hash_base) {
5547 $hash_base = git_get_head_hash
($project);
5549 if (!defined $page) {
5553 my %co = parse_commit
($hash_base)
5554 or die_error
(404, "Unknown commit object");
5556 my $refs = git_get_references
();
5557 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5559 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5560 $file_name, "--full-history")
5561 or die_error
(404, "No such file or directory on given branch");
5563 if (!defined $hash && defined $file_name) {
5564 # some commits could have deleted file in question,
5565 # and not have it in tree, but one of them has to have it
5566 for (my $i = 0; $i <= @commitlist; $i++) {
5567 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5568 last if defined $hash;
5571 if (defined $hash) {
5572 $ftype = git_get_type
($hash);
5574 if (!defined $ftype) {
5575 die_error
(500, "Unknown type of object");
5578 my $paging_nav = '';
5581 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5582 file_name
=>$file_name)},
5584 $paging_nav .= " ⋅ " .
5585 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5586 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5588 $paging_nav .= "first";
5589 $paging_nav .= " ⋅ prev";
5592 if ($#commitlist >= 100) {
5594 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5595 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5596 $paging_nav .= " ⋅ $next_link";
5598 $paging_nav .= " ⋅ next";
5602 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5603 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5604 git_print_page_path
($file_name, $ftype, $hash_base);
5606 git_history_body
(\
@commitlist, 0, 99,
5607 $refs, $hash_base, $ftype, $next_link);
5613 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5614 if (!defined $searchtext) {
5615 die_error
(400, "Text field is empty");
5617 if (!defined $hash) {
5618 $hash = git_get_head_hash
($project);
5620 my %co = parse_commit
($hash);
5622 die_error
(404, "Unknown commit object");
5624 if (!defined $page) {
5628 $searchtype ||= 'commit';
5629 if ($searchtype eq 'pickaxe') {
5630 # pickaxe may take all resources of your box and run for several minutes
5631 # with every query - so decide by yourself how public you make this feature
5632 gitweb_check_feature
('pickaxe')
5633 or die_error
(403, "Pickaxe is disabled");
5635 if ($searchtype eq 'grep') {
5636 gitweb_check_feature
('grep')
5637 or die_error
(403, "Grep is disabled");
5642 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5644 if ($searchtype eq 'commit') {
5645 $greptype = "--grep=";
5646 } elsif ($searchtype eq 'author') {
5647 $greptype = "--author=";
5648 } elsif ($searchtype eq 'committer') {
5649 $greptype = "--committer=";
5651 $greptype .= $searchtext;
5652 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5653 $greptype, '--regexp-ignore-case',
5654 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5656 my $paging_nav = '';
5659 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5660 searchtext
=>$searchtext,
5661 searchtype
=>$searchtype)},
5663 $paging_nav .= " ⋅ " .
5664 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5665 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5667 $paging_nav .= "first";
5668 $paging_nav .= " ⋅ prev";
5671 if ($#commitlist >= 100) {
5673 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5674 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5675 $paging_nav .= " ⋅ $next_link";
5677 $paging_nav .= " ⋅ next";
5680 if ($#commitlist >= 100) {
5683 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5684 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5685 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5688 if ($searchtype eq 'pickaxe') {
5689 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5690 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5692 print "<table class=\"pickaxe search\">\n";
5695 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5696 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5697 ($search_use_regexp ?
'--pickaxe-regex' : ());
5700 while (my $line = <$fd>) {
5704 my %set = parse_difftree_raw_line
($line);
5705 if (defined $set{'commit'}) {
5706 # finish previous commit
5709 "<td class=\"link\">" .
5710 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5712 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5718 print "<tr class=\"dark\">\n";
5720 print "<tr class=\"light\">\n";
5723 %co = parse_commit
($set{'commit'});
5724 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5725 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5726 "<td><i>$author</i></td>\n" .
5728 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5729 -class => "list subject"},
5730 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5731 } elsif (defined $set{'to_id'}) {
5732 next if ($set{'to_id'} =~ m/^0{40}$/);
5734 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5735 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5737 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5743 # finish last commit (warning: repetition!)
5746 "<td class=\"link\">" .
5747 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5749 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5757 if ($searchtype eq 'grep') {
5758 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5759 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5761 print "<table class=\"grep_search\">\n";
5765 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5766 $search_use_regexp ?
('-E', '-i') : '-F',
5767 $searchtext, $co{'tree'};
5769 while (my $line = <$fd>) {
5771 my ($file, $lno, $ltext, $binary);
5772 last if ($matches++ > 1000);
5773 if ($line =~ /^Binary file (.+) matches$/) {
5777 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5779 if ($file ne $lastfile) {
5780 $lastfile and print "</td></tr>\n";
5782 print "<tr class=\"dark\">\n";
5784 print "<tr class=\"light\">\n";
5786 print "<td class=\"list\">".
5787 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5788 file_name
=>"$file"),
5789 -class => "list"}, esc_path
($file));
5790 print "</td><td>\n";
5794 print "<div class=\"binary\">Binary file</div>\n";
5796 $ltext = untabify
($ltext);
5797 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5798 $ltext = esc_html
($1, -nbsp
=>1);
5799 $ltext .= '<span class="match">';
5800 $ltext .= esc_html
($2, -nbsp
=>1);
5801 $ltext .= '</span>';
5802 $ltext .= esc_html
($3, -nbsp
=>1);
5804 $ltext = esc_html
($ltext, -nbsp
=>1);
5806 print "<div class=\"pre\">" .
5807 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5808 file_name
=>"$file").'#l'.$lno,
5809 -class => "linenr"}, sprintf('%4i', $lno))
5810 . ' ' . $ltext . "</div>\n";
5814 print "</td></tr>\n";
5815 if ($matches > 1000) {
5816 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5819 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5828 sub git_search_help
{
5830 git_print_page_nav
('','', $hash,$hash,$hash);
5832 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5833 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5834 the pattern entered is recognized as the POSIX extended
5835 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5838 <dt><b>commit</b></dt>
5839 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5841 my ($have_grep) = gitweb_check_feature
('grep');
5844 <dt><b>grep</b></dt>
5845 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5846 a different one) are searched for the given pattern. On large trees, this search can take
5847 a while and put some strain on the server, so please use it with some consideration. Note that
5848 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5849 case-sensitive.</dd>
5853 <dt><b>author</b></dt>
5854 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5855 <dt><b>committer</b></dt>
5856 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5858 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5859 if ($have_pickaxe) {
5861 <dt><b>pickaxe</b></dt>
5862 <dd>All commits that caused the string to appear or disappear from any file (changes that
5863 added, removed or "modified" the string) will be listed. This search can take a while and
5864 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5865 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5873 my $head = git_get_head_hash
($project);
5874 if (!defined $hash) {
5877 if (!defined $page) {
5880 my $refs = git_get_references
();
5882 my $commit_hash = $hash;
5883 if (defined $hash_parent) {
5884 $commit_hash = "$hash_parent..$hash";
5886 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5888 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5890 if ($#commitlist >= 100) {
5892 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5893 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5897 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5898 git_print_header_div
('summary', $project);
5900 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5905 ## ......................................................................
5906 ## feeds (RSS, Atom; OPML)
5909 my $format = shift || 'atom';
5910 my ($have_blame) = gitweb_check_feature
('blame');
5912 # Atom: http://www.atomenabled.org/developers/syndication/
5913 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5914 if ($format ne 'rss' && $format ne 'atom') {
5915 die_error
(400, "Unknown web feed format");
5918 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5919 my $head = $hash || 'HEAD';
5920 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5924 my $content_type = "application/$format+xml";
5925 if (defined $cgi->http('HTTP_ACCEPT') &&
5926 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5927 # browser (feed reader) prefers text/xml
5928 $content_type = 'text/xml';
5930 if (defined($commitlist[0])) {
5931 %latest_commit = %{$commitlist[0]};
5932 %latest_date = parse_date
($latest_commit{'author_epoch'});
5934 -type
=> $content_type,
5935 -charset
=> 'utf-8',
5936 -last_modified
=> $latest_date{'rfc2822'});
5939 -type
=> $content_type,
5940 -charset
=> 'utf-8');
5943 # Optimization: skip generating the body if client asks only
5944 # for Last-Modified date.
5945 return if ($cgi->request_method() eq 'HEAD');
5948 my $title = "$site_name - $project/$action";
5949 my $feed_type = 'log';
5950 if (defined $hash) {
5951 $title .= " - '$hash'";
5952 $feed_type = 'branch log';
5953 if (defined $file_name) {
5954 $title .= " :: $file_name";
5955 $feed_type = 'history';
5957 } elsif (defined $file_name) {
5958 $title .= " - $file_name";
5959 $feed_type = 'history';
5961 $title .= " $feed_type";
5962 my $descr = git_get_project_description
($project);
5963 if (defined $descr) {
5964 $descr = esc_html
($descr);
5966 $descr = "$project " .
5967 ($format eq 'rss' ?
'RSS' : 'Atom') .
5970 my $owner = git_get_project_owner
($project);
5971 $owner = esc_html
($owner);
5975 if (defined $file_name) {
5976 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5977 } elsif (defined $hash) {
5978 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5980 $alt_url = href
(-full
=>1, action
=>"summary");
5982 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5983 if ($format eq 'rss') {
5985 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5988 print "<title>$title</title>\n" .
5989 "<link>$alt_url</link>\n" .
5990 "<description>$descr</description>\n" .
5991 "<language>en</language>\n";
5992 } elsif ($format eq 'atom') {
5994 <feed xmlns="http://www.w3.org/2005/Atom">
5996 print "<title>$title</title>\n" .
5997 "<subtitle>$descr</subtitle>\n" .
5998 '<link rel="alternate" type="text/html" href="' .
5999 $alt_url . '" />' . "\n" .
6000 '<link rel="self" type="' . $content_type . '" href="' .
6001 $cgi->self_url() . '" />' . "\n" .
6002 "<id>" . href
(-full
=>1) . "</id>\n" .
6003 # use project owner for feed author
6004 "<author><name>$owner</name></author>\n";
6005 if (defined $favicon) {
6006 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6008 if (defined $logo_url) {
6009 # not twice as wide as tall: 72 x 27 pixels
6010 print "<logo>" . esc_url
($logo) . "</logo>\n";
6012 if (! %latest_date) {
6013 # dummy date to keep the feed valid until commits trickle in:
6014 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6016 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6021 for (my $i = 0; $i <= $#commitlist; $i++) {
6022 my %co = %{$commitlist[$i]};
6023 my $commit = $co{'id'};
6024 # we read 150, we always show 30 and the ones more recent than 48 hours
6025 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6028 my %cd = parse_date
($co{'author_epoch'});
6030 # get list of changed files
6031 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6032 $co{'parent'} || "--root",
6033 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6035 my @difftree = map { chomp; $_ } <$fd>;
6039 # print element (entry, item)
6040 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6041 if ($format eq 'rss') {
6043 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6044 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6045 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6046 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6047 "<link>$co_url</link>\n" .
6048 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6049 "<content:encoded>" .
6051 } elsif ($format eq 'atom') {
6053 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6054 "<updated>$cd{'iso-8601'}</updated>\n" .
6056 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6057 if ($co{'author_email'}) {
6058 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6060 print "</author>\n" .
6061 # use committer for contributor
6063 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6064 if ($co{'committer_email'}) {
6065 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6067 print "</contributor>\n" .
6068 "<published>$cd{'iso-8601'}</published>\n" .
6069 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6070 "<id>$co_url</id>\n" .
6071 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6072 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6074 my $comment = $co{'comment'};
6076 foreach my $line (@
$comment) {
6077 $line = esc_html
($line);
6080 print "</pre><ul>\n";
6081 foreach my $difftree_line (@difftree) {
6082 my %difftree = parse_difftree_raw_line
($difftree_line);
6083 next if !$difftree{'from_id'};
6085 my $file = $difftree{'file'} || $difftree{'to_file'};
6089 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6090 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6091 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6092 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6093 -title
=> "diff"}, 'D');
6095 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6096 file_name
=>$file, hash_base
=>$commit),
6097 -title
=> "blame"}, 'B');
6099 # if this is not a feed of a file history
6100 if (!defined $file_name || $file_name ne $file) {
6101 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6102 file_name
=>$file, hash
=>$commit),
6103 -title
=> "history"}, 'H');
6105 $file = esc_path
($file);
6109 if ($format eq 'rss') {
6110 print "</ul>]]>\n" .
6111 "</content:encoded>\n" .
6113 } elsif ($format eq 'atom') {
6114 print "</ul>\n</div>\n" .
6121 if ($format eq 'rss') {
6122 print "</channel>\n</rss>\n";
6123 } elsif ($format eq 'atom') {
6137 my @list = git_get_projects_list
();
6139 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6141 <?xml version="1.0" encoding="utf-8"?>
6142 <opml version="1.0">
6144 <title>$site_name OPML Export</title>
6147 <outline text="git RSS feeds">
6150 foreach my $pr (@list) {
6152 my $head = git_get_head_hash
($proj{'path'});
6153 if (!defined $head) {
6156 $git_dir = "$projectroot/$proj{'path'}";
6157 my %co = parse_commit
($head);
6162 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6163 my $rss = "$my_url?p=$proj{'path'};a=rss";
6164 my $html = "$my_url?p=$proj{'path'};a=summary";
6165 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";