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;
74 # URI of GIT logo (72x27 size)
75 our $logo = "++GITWEB_LOGO++";
76 # URI of GIT favicon, assumed to be image/png type
77 our $favicon = "++GITWEB_FAVICON++";
79 # URI and label (title) of GIT logo link
80 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
81 #our $logo_label = "git documentation";
82 our $logo_url = "http://git.or.cz/";
83 our $logo_label = "git homepage";
85 # source of projects list
86 our $projects_list = "++GITWEB_LIST++";
88 # the width (in characters) of the projects list "Description" column
89 our $projects_list_description_width = 25;
91 # default order of projects list
92 # valid values are none, project, descr, owner, and age
93 our $default_projects_order = "project";
95 # show repository only if this file exists
96 # (only effective if this variable evaluates to true)
97 our $export_ok = "++GITWEB_EXPORT_OK++";
99 # show repository only if this subroutine returns true
100 # when given the path to the project, for example:
101 # sub { return -e "$_[0]/git-daemon-export-ok"; }
102 our $export_auth_hook = undef;
104 # only allow viewing of repositories also shown on the overview page
105 our $strict_export = "++GITWEB_STRICT_EXPORT++";
107 # list of git base URLs used for URL to where fetch project from,
108 # i.e. full URL is "$git_base_url/$project"
109 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
111 # default blob_plain mimetype and default charset for text/plain blob
112 our $default_blob_plain_mimetype = 'text/plain';
113 our $default_text_plain_charset = undef;
115 # file to use for guessing MIME types before trying /etc/mime.types
116 # (relative to the current git repository)
117 our $mimetypes_file = undef;
119 # assume this charset if line contains non-UTF-8 characters;
120 # it should be valid encoding (see Encoding::Supported(3pm) for list),
121 # for which encoding all byte sequences are valid, for example
122 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
123 # could be even 'utf-8' for the old behavior)
124 our $fallback_encoding = 'latin1';
126 # rename detection options for git-diff and git-diff-tree
127 # - default is '-M', with the cost proportional to
128 # (number of removed files) * (number of new files).
129 # - more costly is '-C' (which implies '-M'), with the cost proportional to
130 # (number of changed files + number of removed files) * (number of new files)
131 # - even more costly is '-C', '--find-copies-harder' with cost
132 # (number of files in the original tree) * (number of new files)
133 # - one might want to include '-B' option, e.g. '-B', '-M'
134 our @diff_opts = ('-M'); # taken from git_commit
136 # information about snapshot formats that gitweb is capable of serving
137 our %known_snapshot_formats = (
139 # 'display' => display name,
140 # 'type' => mime type,
141 # 'suffix' => filename suffix,
142 # 'format' => --format for git-archive,
143 # 'compressor' => [compressor command and arguments]
144 # (array reference, optional)}
147 'display' => 'tar.gz',
148 'type' => 'application/x-gzip',
149 'suffix' => '.tar.gz',
151 'compressor' => ['gzip']},
154 'display' => 'tar.bz2',
155 'type' => 'application/x-bzip2',
156 'suffix' => '.tar.bz2',
158 'compressor' => ['bzip2']},
162 'type' => 'application/x-zip',
167 # Aliases so we understand old gitweb.snapshot values in repository
169 our %known_snapshot_format_aliases = (
173 # backward compatibility: legacy gitweb config support
174 'x-gzip' => undef, 'gz' => undef,
175 'x-bzip2' => undef, 'bz2' => undef,
176 'x-zip' => undef, '' => undef,
179 # You define site-wide feature defaults here; override them with
180 # $GITWEB_CONFIG as necessary.
183 # 'sub' => feature-sub (subroutine),
184 # 'override' => allow-override (boolean),
185 # 'default' => [ default options...] (array reference)}
187 # if feature is overridable (it means that allow-override has true value),
188 # then feature-sub will be called with default options as parameters;
189 # return value of feature-sub indicates if to enable specified feature
191 # if there is no 'sub' key (no feature-sub), then feature cannot be
194 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
196 # Enable the 'blame' blob view, showing the last commit that modified
197 # each line in the file. This can be very CPU-intensive.
199 # To enable system wide have in $GITWEB_CONFIG
200 # $feature{'blame'}{'default'} = [1];
201 # To have project specific config enable override in $GITWEB_CONFIG
202 # $feature{'blame'}{'override'} = 1;
203 # and in project config gitweb.blame = 0|1;
205 'sub' => \
&feature_blame
,
209 # Enable the 'snapshot' link, providing a compressed archive of any
210 # tree. This can potentially generate high traffic if you have large
213 # Value is a list of formats defined in %known_snapshot_formats that
215 # To disable system wide have in $GITWEB_CONFIG
216 # $feature{'snapshot'}{'default'} = [];
217 # To have project specific config enable override in $GITWEB_CONFIG
218 # $feature{'snapshot'}{'override'} = 1;
219 # and in project config, a comma-separated list of formats or "none"
220 # to disable. Example: gitweb.snapshot = tbz2,zip;
222 'sub' => \
&feature_snapshot
,
224 'default' => ['tgz']},
226 # Enable text search, which will list the commits which match author,
227 # committer or commit text to a given string. Enabled by default.
228 # Project specific override is not supported.
233 # Enable grep search, which will list the files in currently selected
234 # tree containing the given string. Enabled by default. This can be
235 # potentially CPU-intensive, of course.
237 # To enable system wide have in $GITWEB_CONFIG
238 # $feature{'grep'}{'default'} = [1];
239 # To have project specific config enable override in $GITWEB_CONFIG
240 # $feature{'grep'}{'override'} = 1;
241 # and in project config gitweb.grep = 0|1;
246 # Enable the pickaxe search, which will list the commits that modified
247 # a given string in a file. This can be practical and quite faster
248 # alternative to 'blame', but still potentially CPU-intensive.
250 # To enable system wide have in $GITWEB_CONFIG
251 # $feature{'pickaxe'}{'default'} = [1];
252 # To have project specific config enable override in $GITWEB_CONFIG
253 # $feature{'pickaxe'}{'override'} = 1;
254 # and in project config gitweb.pickaxe = 0|1;
256 'sub' => \
&feature_pickaxe
,
260 # Make gitweb use an alternative format of the URLs which can be
261 # more readable and natural-looking: project name is embedded
262 # directly in the path and the query string contains other
263 # auxiliary information. All gitweb installations recognize
264 # URL in either format; this configures in which formats gitweb
267 # To enable system wide have in $GITWEB_CONFIG
268 # $feature{'pathinfo'}{'default'} = [1];
269 # Project specific override is not supported.
271 # Note that you will need to change the default location of CSS,
272 # favicon, logo and possibly other files to an absolute URL. Also,
273 # if gitweb.cgi serves as your indexfile, you will need to force
274 # $my_uri to contain the script name in your $GITWEB_CONFIG.
279 # Make gitweb consider projects in project root subdirectories
280 # to be forks of existing projects. Given project $projname.git,
281 # projects matching $projname/*.git will not be shown in the main
282 # projects list, instead a '+' mark will be added to $projname
283 # there and a 'forks' view will be enabled for the project, listing
284 # all the forks. If project list is taken from a file, forks have
285 # to be listed after the main project.
287 # To enable system wide have in $GITWEB_CONFIG
288 # $feature{'forks'}{'default'} = [1];
289 # Project specific override is not supported.
294 # Insert custom links to the action bar of all project pages.
295 # This enables you mainly to link to third-party scripts integrating
296 # into gitweb; e.g. git-browser for graphical history representation
297 # or custom web-based repository administration interface.
299 # The 'default' value consists of a list of triplets in the form
300 # (label, link, position) where position is the label after which
301 # to insert the link and link is a format string where %n expands
302 # to the project name, %f to the project path within the filesystem,
303 # %h to the current hash (h gitweb parameter) and %b to the current
304 # hash base (hb gitweb parameter); %% expands to %.
306 # To enable system wide have in $GITWEB_CONFIG e.g.
307 # $feature{'actions'}{'default'} = [('graphiclog',
308 # '/git-browser/by-commit.html?r=%n', 'summary')];
309 # Project specific override is not supported.
314 # Allow gitweb scan project content tags described in ctags/
315 # of project repository, and display the popular Web 2.0-ish
316 # "tag cloud" near the project list. Note that this is something
317 # COMPLETELY different from the normal Git tags.
319 # gitweb by itself can show existing tags, but it does not handle
320 # tagging itself; you need an external application for that.
321 # For an example script, check Girocco's cgi/tagproj.cgi.
322 # You may want to install the HTML::TagCloud Perl module to get
323 # a pretty tag cloud instead of just a list of tags.
325 # To enable system wide have in $GITWEB_CONFIG
326 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
327 # Project specific override is not supported.
333 sub gitweb_get_feature
{
335 return unless exists $feature{$name};
336 my ($sub, $override, @defaults) = (
337 $feature{$name}{'sub'},
338 $feature{$name}{'override'},
339 @{$feature{$name}{'default'}});
340 if (!$override) { return @defaults; }
342 warn "feature $name is not overrideable";
345 return $sub->(@defaults);
348 # A wrapper to check if a given feature is enabled.
349 # With this, you can say
351 # my $bool_feat = gitweb_check_feature('bool_feat');
352 # gitweb_check_feature('bool_feat') or somecode;
356 # my ($bool_feat) = gitweb_get_feature('bool_feat');
357 # (gitweb_get_feature('bool_feat'))[0] or somecode;
359 sub gitweb_check_feature
{
360 return (gitweb_get_feature
(@_))[0];
365 my ($val) = git_get_project_config
('blame', '--bool');
367 if ($val eq 'true') {
369 } elsif ($val eq 'false') {
376 sub feature_snapshot
{
379 my ($val) = git_get_project_config
('snapshot');
382 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
389 my ($val) = git_get_project_config
('grep', '--bool');
391 if ($val eq 'true') {
393 } elsif ($val eq 'false') {
400 sub feature_pickaxe
{
401 my ($val) = git_get_project_config
('pickaxe', '--bool');
403 if ($val eq 'true') {
405 } elsif ($val eq 'false') {
412 # checking HEAD file with -e is fragile if the repository was
413 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
415 sub check_head_link
{
417 my $headfile = "$dir/HEAD";
418 return ((-e
$headfile) ||
419 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
422 sub check_export_ok
{
424 return (check_head_link
($dir) &&
425 (!$export_ok || -e
"$dir/$export_ok") &&
426 (!$export_auth_hook || $export_auth_hook->($dir)));
429 # process alternate names for backward compatibility
430 # filter out unsupported (unknown) snapshot formats
431 sub filter_snapshot_fmts
{
435 exists $known_snapshot_format_aliases{$_} ?
436 $known_snapshot_format_aliases{$_} : $_} @fmts;
437 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
441 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
442 if (-e
$GITWEB_CONFIG) {
445 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
446 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
449 # version of the core git binary
450 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
452 $projects_list ||= $projectroot;
454 # ======================================================================
455 # input validation and dispatch
457 # input parameters can be collected from a variety of sources (presently, CGI
458 # and PATH_INFO), so we define an %input_params hash that collects them all
459 # together during validation: this allows subsequent uses (e.g. href()) to be
460 # agnostic of the parameter origin
462 our %input_params = ();
464 # input parameters are stored with the long parameter name as key. This will
465 # also be used in the href subroutine to convert parameters to their CGI
466 # equivalent, and since the href() usage is the most frequent one, we store
467 # the name -> CGI key mapping here, instead of the reverse.
469 # XXX: Warning: If you touch this, check the search form for updating,
472 our @cgi_param_mapping = (
480 hash_parent_base
=> "hpb",
485 snapshot_format
=> "sf",
486 extra_options
=> "opt",
487 search_use_regexp
=> "sr",
489 our %cgi_param_mapping = @cgi_param_mapping;
491 # we will also need to know the possible actions, for validation
493 "blame" => \
&git_blame
,
494 "blobdiff" => \
&git_blobdiff
,
495 "blobdiff_plain" => \
&git_blobdiff_plain
,
496 "blob" => \
&git_blob
,
497 "blob_plain" => \
&git_blob_plain
,
498 "commitdiff" => \
&git_commitdiff
,
499 "commitdiff_plain" => \
&git_commitdiff_plain
,
500 "commit" => \
&git_commit
,
501 "forks" => \
&git_forks
,
502 "heads" => \
&git_heads
,
503 "history" => \
&git_history
,
506 "atom" => \
&git_atom
,
507 "search" => \
&git_search
,
508 "search_help" => \
&git_search_help
,
509 "shortlog" => \
&git_shortlog
,
510 "summary" => \
&git_summary
,
512 "tags" => \
&git_tags
,
513 "tree" => \
&git_tree
,
514 "snapshot" => \
&git_snapshot
,
515 "object" => \
&git_object
,
516 # those below don't need $project
517 "opml" => \
&git_opml
,
518 "project_list" => \
&git_project_list
,
519 "project_index" => \
&git_project_index
,
522 # finally, we have the hash of allowed extra_options for the commands that
524 our %allowed_options = (
525 "--no-merges" => [ qw(rss atom log shortlog history) ],
528 # fill %input_params with the CGI parameters. All values except for 'opt'
529 # should be single values, but opt can be an array. We should probably
530 # build an array of parameters that can be multi-valued, but since for the time
531 # being it's only this one, we just single it out
532 while (my ($name, $symbol) = each %cgi_param_mapping) {
533 if ($symbol eq 'opt') {
534 $input_params{$name} = [ $cgi->param($symbol) ];
536 $input_params{$name} = $cgi->param($symbol);
540 # now read PATH_INFO and update the parameter list for missing parameters
541 sub evaluate_path_info
{
542 return if defined $input_params{'project'};
543 return if !$path_info;
544 $path_info =~ s
,^/+,,;
545 return if !$path_info;
547 # find which part of PATH_INFO is project
548 my $project = $path_info;
550 while ($project && !check_head_link
("$projectroot/$project")) {
551 $project =~ s
,/*[^/]*$,,;
553 return unless $project;
554 $input_params{'project'} = $project;
556 # do not change any parameters if an action is given using the query string
557 return if $input_params{'action'};
558 $path_info =~ s
,^\Q
$project\E
/*,,;
560 # next, check if we have an action
561 my $action = $path_info;
563 if (exists $actions{$action}) {
564 $path_info =~ s
,^$action/*,,;
565 $input_params{'action'} = $action;
568 # list of actions that want hash_base instead of hash, but can have no
569 # pathname (f) parameter
576 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
577 my ($parentrefname, $parentpathname, $refname, $pathname) =
578 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
580 # first, analyze the 'current' part
581 if (defined $pathname) {
582 # we got "branch:filename" or "branch:dir/"
583 # we could use git_get_type(branch:pathname), but:
584 # - it needs $git_dir
585 # - it does a git() call
586 # - the convention of terminating directories with a slash
587 # makes it superfluous
588 # - embedding the action in the PATH_INFO would make it even
590 $pathname =~ s
,^/+,,;
591 if (!$pathname || substr($pathname, -1) eq "/") {
592 $input_params{'action'} ||= "tree";
595 # the default action depends on whether we had parent info
597 if ($parentrefname) {
598 $input_params{'action'} ||= "blobdiff_plain";
600 $input_params{'action'} ||= "blob_plain";
603 $input_params{'hash_base'} ||= $refname;
604 $input_params{'file_name'} ||= $pathname;
605 } elsif (defined $refname) {
606 # we got "branch". In this case we have to choose if we have to
607 # set hash or hash_base.
609 # Most of the actions without a pathname only want hash to be
610 # set, except for the ones specified in @wants_base that want
611 # hash_base instead. It should also be noted that hand-crafted
612 # links having 'history' as an action and no pathname or hash
613 # set will fail, but that happens regardless of PATH_INFO.
614 $input_params{'action'} ||= "shortlog";
615 if (grep { $_ eq $input_params{'action'} } @wants_base) {
616 $input_params{'hash_base'} ||= $refname;
618 $input_params{'hash'} ||= $refname;
622 # next, handle the 'parent' part, if present
623 if (defined $parentrefname) {
624 # a missing pathspec defaults to the 'current' filename, allowing e.g.
625 # someproject/blobdiff/oldrev..newrev:/filename
626 if ($parentpathname) {
627 $parentpathname =~ s
,^/+,,;
628 $parentpathname =~ s
,/$,,;
629 $input_params{'file_parent'} ||= $parentpathname;
631 $input_params{'file_parent'} ||= $input_params{'file_name'};
633 # we assume that hash_parent_base is wanted if a path was specified,
634 # or if the action wants hash_base instead of hash
635 if (defined $input_params{'file_parent'} ||
636 grep { $_ eq $input_params{'action'} } @wants_base) {
637 $input_params{'hash_parent_base'} ||= $parentrefname;
639 $input_params{'hash_parent'} ||= $parentrefname;
643 # for the snapshot action, we allow URLs in the form
644 # $project/snapshot/$hash.ext
645 # where .ext determines the snapshot and gets removed from the
646 # passed $refname to provide the $hash.
648 # To be able to tell that $refname includes the format extension, we
649 # require the following two conditions to be satisfied:
650 # - the hash input parameter MUST have been set from the $refname part
651 # of the URL (i.e. they must be equal)
652 # - the snapshot format MUST NOT have been defined already (e.g. from
654 # It's also useless to try any matching unless $refname has a dot,
655 # so we check for that too
656 if (defined $input_params{'action'} &&
657 $input_params{'action'} eq 'snapshot' &&
658 defined $refname && index($refname, '.') != -1 &&
659 $refname eq $input_params{'hash'} &&
660 !defined $input_params{'snapshot_format'}) {
661 # We loop over the known snapshot formats, checking for
662 # extensions. Allowed extensions are both the defined suffix
663 # (which includes the initial dot already) and the snapshot
664 # format key itself, with a prepended dot
665 while (my ($fmt, %opt) = each %known_snapshot_formats) {
668 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
669 next unless $sfx = $1;
670 # a valid suffix was found, so set the snapshot format
671 # and reset the hash parameter
672 $input_params{'snapshot_format'} = $fmt;
673 $input_params{'hash'} = $hash;
674 # we also set the format suffix to the one requested
675 # in the URL: this way a request for e.g. .tgz returns
676 # a .tgz instead of a .tar.gz
677 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
682 evaluate_path_info
();
684 our $action = $input_params{'action'};
685 if (defined $action) {
686 if (!validate_action
($action)) {
687 die_error
(400, "Invalid action parameter");
691 # parameters which are pathnames
692 our $project = $input_params{'project'};
693 if (defined $project) {
694 if (!validate_project
($project)) {
696 die_error
(404, "No such project");
700 our $file_name = $input_params{'file_name'};
701 if (defined $file_name) {
702 if (!validate_pathname
($file_name)) {
703 die_error
(400, "Invalid file parameter");
707 our $file_parent = $input_params{'file_parent'};
708 if (defined $file_parent) {
709 if (!validate_pathname
($file_parent)) {
710 die_error
(400, "Invalid file parent parameter");
714 # parameters which are refnames
715 our $hash = $input_params{'hash'};
717 if (!validate_refname
($hash)) {
718 die_error
(400, "Invalid hash parameter");
722 our $hash_parent = $input_params{'hash_parent'};
723 if (defined $hash_parent) {
724 if (!validate_refname
($hash_parent)) {
725 die_error
(400, "Invalid hash parent parameter");
729 our $hash_base = $input_params{'hash_base'};
730 if (defined $hash_base) {
731 if (!validate_refname
($hash_base)) {
732 die_error
(400, "Invalid hash base parameter");
736 our @extra_options = @{$input_params{'extra_options'}};
737 # @extra_options is always defined, since it can only be (currently) set from
738 # CGI, and $cgi->param() returns the empty array in array context if the param
740 foreach my $opt (@extra_options) {
741 if (not exists $allowed_options{$opt}) {
742 die_error
(400, "Invalid option parameter");
744 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
745 die_error
(400, "Invalid option parameter for this action");
749 our $hash_parent_base = $input_params{'hash_parent_base'};
750 if (defined $hash_parent_base) {
751 if (!validate_refname
($hash_parent_base)) {
752 die_error
(400, "Invalid hash parent base parameter");
757 our $page = $input_params{'page'};
759 if ($page =~ m/[^0-9]/) {
760 die_error
(400, "Invalid page parameter");
764 our $searchtype = $input_params{'searchtype'};
765 if (defined $searchtype) {
766 if ($searchtype =~ m/[^a-z]/) {
767 die_error
(400, "Invalid searchtype parameter");
771 our $search_use_regexp = $input_params{'search_use_regexp'};
773 our $searchtext = $input_params{'searchtext'};
775 if (defined $searchtext) {
776 if (length($searchtext) < 2) {
777 die_error
(403, "At least two characters are required for search parameter");
779 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
782 # path to the current git repository
784 $git_dir = "$projectroot/$project" if $project;
786 # list of supported snapshot formats
787 our @snapshot_fmts = gitweb_get_feature
('snapshot');
788 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
791 if (!defined $action) {
793 $action = git_get_type
($hash);
794 } elsif (defined $hash_base && defined $file_name) {
795 $action = git_get_type
("$hash_base:$file_name");
796 } elsif (defined $project) {
799 $action = 'project_list';
802 if (!defined($actions{$action})) {
803 die_error
(400, "Unknown action");
805 if ($action !~ m/^(opml|project_list|project_index)$/ &&
807 die_error
(400, "Project needed");
809 $actions{$action}->();
812 ## ======================================================================
817 # default is to use -absolute url() i.e. $my_uri
818 my $href = $params{-full
} ? $my_url : $my_uri;
820 $params{'project'} = $project unless exists $params{'project'};
822 if ($params{-replay
}) {
823 while (my ($name, $symbol) = each %cgi_param_mapping) {
824 if (!exists $params{$name}) {
825 $params{$name} = $input_params{$name};
830 my $use_pathinfo = gitweb_check_feature
('pathinfo');
832 # try to put as many parameters as possible in PATH_INFO:
835 # - hash_parent or hash_parent_base:/file_parent
836 # - hash or hash_base:/filename
837 # - the snapshot_format as an appropriate suffix
839 # When the script is the root DirectoryIndex for the domain,
840 # $href here would be something like http://gitweb.example.com/
841 # Thus, we strip any trailing / from $href, to spare us double
842 # slashes in the final URL
845 # Then add the project name, if present
846 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
847 delete $params{'project'};
849 # since we destructively absorb parameters, we keep this
850 # boolean that remembers if we're handling a snapshot
851 my $is_snapshot = $params{'action'} eq 'snapshot';
853 # Summary just uses the project path URL, any other action is
855 if (defined $params{'action'}) {
856 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
857 delete $params{'action'};
860 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
861 # stripping nonexistent or useless pieces
862 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
863 || $params{'hash_parent'} || $params{'hash'});
864 if (defined $params{'hash_base'}) {
865 if (defined $params{'hash_parent_base'}) {
866 $href .= esc_url
($params{'hash_parent_base'});
867 # skip the file_parent if it's the same as the file_name
868 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
869 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
870 $href .= ":/".esc_url
($params{'file_parent'});
871 delete $params{'file_parent'};
874 delete $params{'hash_parent'};
875 delete $params{'hash_parent_base'};
876 } elsif (defined $params{'hash_parent'}) {
877 $href .= esc_url
($params{'hash_parent'}). "..";
878 delete $params{'hash_parent'};
881 $href .= esc_url
($params{'hash_base'});
882 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
883 $href .= ":/".esc_url
($params{'file_name'});
884 delete $params{'file_name'};
886 delete $params{'hash'};
887 delete $params{'hash_base'};
888 } elsif (defined $params{'hash'}) {
889 $href .= esc_url
($params{'hash'});
890 delete $params{'hash'};
893 # If the action was a snapshot, we can absorb the
894 # snapshot_format parameter too
896 my $fmt = $params{'snapshot_format'};
897 # snapshot_format should always be defined when href()
898 # is called, but just in case some code forgets, we
899 # fall back to the default
900 $fmt ||= $snapshot_fmts[0];
901 $href .= $known_snapshot_formats{$fmt}{'suffix'};
902 delete $params{'snapshot_format'};
906 # now encode the parameters explicitly
908 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
909 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
910 if (defined $params{$name}) {
911 if (ref($params{$name}) eq "ARRAY") {
912 foreach my $par (@{$params{$name}}) {
913 push @result, $symbol . "=" . esc_param
($par);
916 push @result, $symbol . "=" . esc_param
($params{$name});
920 $href .= "?" . join(';', @result) if scalar @result;
926 ## ======================================================================
927 ## validation, quoting/unquoting and escaping
929 sub validate_action
{
930 my $input = shift || return undef;
931 return undef unless exists $actions{$input};
935 sub validate_project
{
936 my $input = shift || return undef;
937 if (!validate_pathname
($input) ||
938 !(-d
"$projectroot/$input") ||
939 !check_export_ok
("$projectroot/$input") ||
940 ($strict_export && !project_in_list
($input))) {
947 sub validate_pathname
{
948 my $input = shift || return undef;
950 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
951 # at the beginning, at the end, and between slashes.
952 # also this catches doubled slashes
953 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
957 if ($input =~ m!\0!) {
963 sub validate_refname
{
964 my $input = shift || return undef;
966 # textual hashes are O.K.
967 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
970 # it must be correct pathname
971 $input = validate_pathname
($input)
973 # restrictions on ref name according to git-check-ref-format
974 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
980 # decode sequences of octets in utf8 into Perl's internal form,
981 # which is utf-8 with utf8 flag set if needed. gitweb writes out
982 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
985 if (utf8
::valid
($str)) {
989 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
993 # quote unsafe chars, but keep the slash, even when it's not
994 # correct, but quoted slashes look too horrible in bookmarks
997 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1003 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1006 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1012 # replace invalid utf8 character with SUBSTITUTION sequence
1013 sub esc_html
($;%) {
1017 $str = to_utf8
($str);
1018 $str = $cgi->escapeHTML($str);
1019 if ($opts{'-nbsp'}) {
1020 $str =~ s/ / /g;
1022 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1026 # quote control characters and escape filename to HTML
1031 $str = to_utf8
($str);
1032 $str = $cgi->escapeHTML($str);
1033 if ($opts{'-nbsp'}) {
1034 $str =~ s/ / /g;
1036 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1040 # Make control characters "printable", using character escape codes (CEC)
1044 my %es = ( # character escape codes, aka escape sequences
1045 "\t" => '\t', # tab (HT)
1046 "\n" => '\n', # line feed (LF)
1047 "\r" => '\r', # carrige return (CR)
1048 "\f" => '\f', # form feed (FF)
1049 "\b" => '\b', # backspace (BS)
1050 "\a" => '\a', # alarm (bell) (BEL)
1051 "\e" => '\e', # escape (ESC)
1052 "\013" => '\v', # vertical tab (VT)
1053 "\000" => '\0', # nul character (NUL)
1055 my $chr = ( (exists $es{$cntrl})
1057 : sprintf('\%2x', ord($cntrl)) );
1058 if ($opts{-nohtml
}) {
1061 return "<span class=\"cntrl\">$chr</span>";
1065 # Alternatively use unicode control pictures codepoints,
1066 # Unicode "printable representation" (PR)
1071 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1072 if ($opts{-nohtml
}) {
1075 return "<span class=\"cntrl\">$chr</span>";
1079 # git may return quoted and escaped filenames
1085 my %es = ( # character escape codes, aka escape sequences
1086 't' => "\t", # tab (HT, TAB)
1087 'n' => "\n", # newline (NL)
1088 'r' => "\r", # return (CR)
1089 'f' => "\f", # form feed (FF)
1090 'b' => "\b", # backspace (BS)
1091 'a' => "\a", # alarm (bell) (BEL)
1092 'e' => "\e", # escape (ESC)
1093 'v' => "\013", # vertical tab (VT)
1096 if ($seq =~ m/^[0-7]{1,3}$/) {
1097 # octal char sequence
1098 return chr(oct($seq));
1099 } elsif (exists $es{$seq}) {
1100 # C escape sequence, aka character escape code
1103 # quoted ordinary character
1107 if ($str =~ m/^"(.*)"$/) {
1110 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1115 # escape tabs (convert tabs to spaces)
1119 while ((my $pos = index($line, "\t")) != -1) {
1120 if (my $count = (8 - ($pos % 8))) {
1121 my $spaces = ' ' x
$count;
1122 $line =~ s/\t/$spaces/;
1129 sub project_in_list
{
1130 my $project = shift;
1131 my @list = git_get_projects_list
();
1132 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1135 ## ----------------------------------------------------------------------
1136 ## HTML aware string manipulation
1138 # Try to chop given string on a word boundary between position
1139 # $len and $len+$add_len. If there is no word boundary there,
1140 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1141 # (marking chopped part) would be longer than given string.
1145 my $add_len = shift || 10;
1146 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1148 # Make sure perl knows it is utf8 encoded so we don't
1149 # cut in the middle of a utf8 multibyte char.
1150 $str = to_utf8
($str);
1152 # allow only $len chars, but don't cut a word if it would fit in $add_len
1153 # if it doesn't fit, cut it if it's still longer than the dots we would add
1154 # remove chopped character entities entirely
1156 # when chopping in the middle, distribute $len into left and right part
1157 # return early if chopping wouldn't make string shorter
1158 if ($where eq 'center') {
1159 return $str if ($len + 5 >= length($str)); # filler is length 5
1162 return $str if ($len + 4 >= length($str)); # filler is length 4
1165 # regexps: ending and beginning with word part up to $add_len
1166 my $endre = qr/.{$len}\w{0,$add_len}/;
1167 my $begre = qr/\w{0,$add_len}.{$len}/;
1169 if ($where eq 'left') {
1170 $str =~ m/^(.*?)($begre)$/;
1171 my ($lead, $body) = ($1, $2);
1172 if (length($lead) > 4) {
1173 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1176 return "$lead$body";
1178 } elsif ($where eq 'center') {
1179 $str =~ m/^($endre)(.*)$/;
1180 my ($left, $str) = ($1, $2);
1181 $str =~ m/^(.*?)($begre)$/;
1182 my ($mid, $right) = ($1, $2);
1183 if (length($mid) > 5) {
1184 $left =~ s/&[^;]*$//;
1185 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1188 return "$left$mid$right";
1191 $str =~ m/^($endre)(.*)$/;
1194 if (length($tail) > 4) {
1195 $body =~ s/&[^;]*$//;
1198 return "$body$tail";
1202 # takes the same arguments as chop_str, but also wraps a <span> around the
1203 # result with a title attribute if it does get chopped. Additionally, the
1204 # string is HTML-escaped.
1205 sub chop_and_escape_str
{
1208 my $chopped = chop_str
(@_);
1209 if ($chopped eq $str) {
1210 return esc_html
($chopped);
1212 $str =~ s/([[:cntrl:]])/?/g;
1213 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1217 ## ----------------------------------------------------------------------
1218 ## functions returning short strings
1220 # CSS class for given age value (in seconds)
1224 if (!defined $age) {
1226 } elsif ($age < 60*60*2) {
1228 } elsif ($age < 60*60*24*2) {
1235 # convert age in seconds to "nn units ago" string
1240 if ($age > 60*60*24*365*2) {
1241 $age_str = (int $age/60/60/24/365);
1242 $age_str .= " years ago";
1243 } elsif ($age > 60*60*24*(365/12)*2) {
1244 $age_str = int $age/60/60/24/(365/12);
1245 $age_str .= " months ago";
1246 } elsif ($age > 60*60*24*7*2) {
1247 $age_str = int $age/60/60/24/7;
1248 $age_str .= " weeks ago";
1249 } elsif ($age > 60*60*24*2) {
1250 $age_str = int $age/60/60/24;
1251 $age_str .= " days ago";
1252 } elsif ($age > 60*60*2) {
1253 $age_str = int $age/60/60;
1254 $age_str .= " hours ago";
1255 } elsif ($age > 60*2) {
1256 $age_str = int $age/60;
1257 $age_str .= " min ago";
1258 } elsif ($age > 2) {
1259 $age_str = int $age;
1260 $age_str .= " sec ago";
1262 $age_str .= " right now";
1268 S_IFINVALID
=> 0030000,
1269 S_IFGITLINK
=> 0160000,
1272 # submodule/subproject, a commit object reference
1273 sub S_ISGITLINK
($) {
1276 return (($mode & S_IFMT
) == S_IFGITLINK
)
1279 # convert file mode in octal to symbolic file mode string
1281 my $mode = oct shift;
1283 if (S_ISGITLINK
($mode)) {
1284 return 'm---------';
1285 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1286 return 'drwxr-xr-x';
1287 } elsif (S_ISLNK
($mode)) {
1288 return 'lrwxrwxrwx';
1289 } elsif (S_ISREG
($mode)) {
1290 # git cares only about the executable bit
1291 if ($mode & S_IXUSR
) {
1292 return '-rwxr-xr-x';
1294 return '-rw-r--r--';
1297 return '----------';
1301 # convert file mode in octal to file type string
1305 if ($mode !~ m/^[0-7]+$/) {
1311 if (S_ISGITLINK
($mode)) {
1313 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1315 } elsif (S_ISLNK
($mode)) {
1317 } elsif (S_ISREG
($mode)) {
1324 # convert file mode in octal to file type description string
1325 sub file_type_long
{
1328 if ($mode !~ m/^[0-7]+$/) {
1334 if (S_ISGITLINK
($mode)) {
1336 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1338 } elsif (S_ISLNK
($mode)) {
1340 } elsif (S_ISREG
($mode)) {
1341 if ($mode & S_IXUSR
) {
1342 return "executable";
1352 ## ----------------------------------------------------------------------
1353 ## functions returning short HTML fragments, or transforming HTML fragments
1354 ## which don't belong to other sections
1356 # format line of commit message.
1357 sub format_log_line_html
{
1360 $line = esc_html
($line, -nbsp
=>1);
1361 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1364 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1365 -class => "text"}, $hash_text);
1366 $line =~ s/$hash_text/$link/;
1371 # format marker of refs pointing to given object
1373 # the destination action is chosen based on object type and current context:
1374 # - for annotated tags, we choose the tag view unless it's the current view
1375 # already, in which case we go to shortlog view
1376 # - for other refs, we keep the current view if we're in history, shortlog or
1377 # log view, and select shortlog otherwise
1378 sub format_ref_marker
{
1379 my ($refs, $id) = @_;
1382 if (defined $refs->{$id}) {
1383 foreach my $ref (@{$refs->{$id}}) {
1384 # this code exploits the fact that non-lightweight tags are the
1385 # only indirect objects, and that they are the only objects for which
1386 # we want to use tag instead of shortlog as action
1387 my ($type, $name) = qw();
1388 my $indirect = ($ref =~ s/\^\{\}$//);
1389 # e.g. tags/v2.6.11 or heads/next
1390 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1399 $class .= " indirect" if $indirect;
1401 my $dest_action = "shortlog";
1404 $dest_action = "tag" unless $action eq "tag";
1405 } elsif ($action =~ /^(history|(short)?log)$/) {
1406 $dest_action = $action;
1410 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1413 my $link = $cgi->a({
1415 action
=>$dest_action,
1419 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1425 return ' <span class="refs">'. $markers . '</span>';
1431 # format, perhaps shortened and with markers, title line
1432 sub format_subject_html
{
1433 my ($long, $short, $href, $extra) = @_;
1434 $extra = '' unless defined($extra);
1436 if (length($short) < length($long)) {
1437 return $cgi->a({-href
=> $href, -class => "list subject",
1438 -title
=> to_utf8
($long)},
1439 esc_html
($short) . $extra);
1441 return $cgi->a({-href
=> $href, -class => "list subject"},
1442 esc_html
($long) . $extra);
1446 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1447 sub format_git_diff_header_line
{
1449 my $diffinfo = shift;
1450 my ($from, $to) = @_;
1452 if ($diffinfo->{'nparents'}) {
1454 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1455 if ($to->{'href'}) {
1456 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1457 esc_path
($to->{'file'}));
1458 } else { # file was deleted (no href)
1459 $line .= esc_path
($to->{'file'});
1463 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1464 if ($from->{'href'}) {
1465 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1466 'a/' . esc_path
($from->{'file'}));
1467 } else { # file was added (no href)
1468 $line .= 'a/' . esc_path
($from->{'file'});
1471 if ($to->{'href'}) {
1472 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1473 'b/' . esc_path
($to->{'file'}));
1474 } else { # file was deleted
1475 $line .= 'b/' . esc_path
($to->{'file'});
1479 return "<div class=\"diff header\">$line</div>\n";
1482 # format extended diff header line, before patch itself
1483 sub format_extended_diff_header_line
{
1485 my $diffinfo = shift;
1486 my ($from, $to) = @_;
1489 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1490 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1491 esc_path
($from->{'file'}));
1493 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1494 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1495 esc_path
($to->{'file'}));
1497 # match single <mode>
1498 if ($line =~ m/\s(\d{6})$/) {
1499 $line .= '<span class="info"> (' .
1500 file_type_long
($1) .
1504 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1505 # can match only for combined diff
1507 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1508 if ($from->{'href'}[$i]) {
1509 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1511 substr($diffinfo->{'from_id'}[$i],0,7));
1516 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1519 if ($to->{'href'}) {
1520 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1521 substr($diffinfo->{'to_id'},0,7));
1526 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1527 # can match only for ordinary diff
1528 my ($from_link, $to_link);
1529 if ($from->{'href'}) {
1530 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1531 substr($diffinfo->{'from_id'},0,7));
1533 $from_link = '0' x
7;
1535 if ($to->{'href'}) {
1536 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1537 substr($diffinfo->{'to_id'},0,7));
1541 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1542 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1545 return $line . "<br/>\n";
1548 # format from-file/to-file diff header
1549 sub format_diff_from_to_header
{
1550 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1555 #assert($line =~ m/^---/) if DEBUG;
1556 # no extra formatting for "^--- /dev/null"
1557 if (! $diffinfo->{'nparents'}) {
1558 # ordinary (single parent) diff
1559 if ($line =~ m!^--- "?a/!) {
1560 if ($from->{'href'}) {
1562 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1563 esc_path
($from->{'file'}));
1566 esc_path
($from->{'file'});
1569 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1572 # combined diff (merge commit)
1573 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1574 if ($from->{'href'}[$i]) {
1576 $cgi->a({-href
=>href
(action
=>"blobdiff",
1577 hash_parent
=>$diffinfo->{'from_id'}[$i],
1578 hash_parent_base
=>$parents[$i],
1579 file_parent
=>$from->{'file'}[$i],
1580 hash
=>$diffinfo->{'to_id'},
1582 file_name
=>$to->{'file'}),
1584 -title
=>"diff" . ($i+1)},
1587 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1588 esc_path
($from->{'file'}[$i]));
1590 $line = '--- /dev/null';
1592 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1597 #assert($line =~ m/^\+\+\+/) if DEBUG;
1598 # no extra formatting for "^+++ /dev/null"
1599 if ($line =~ m!^\+\+\+ "?b/!) {
1600 if ($to->{'href'}) {
1602 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1603 esc_path
($to->{'file'}));
1606 esc_path
($to->{'file'});
1609 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1614 # create note for patch simplified by combined diff
1615 sub format_diff_cc_simplified
{
1616 my ($diffinfo, @parents) = @_;
1619 $result .= "<div class=\"diff header\">" .
1621 if (!is_deleted
($diffinfo)) {
1622 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1624 hash
=>$diffinfo->{'to_id'},
1625 file_name
=>$diffinfo->{'to_file'}),
1627 esc_path
($diffinfo->{'to_file'}));
1629 $result .= esc_path
($diffinfo->{'to_file'});
1631 $result .= "</div>\n" . # class="diff header"
1632 "<div class=\"diff nodifferences\">" .
1634 "</div>\n"; # class="diff nodifferences"
1639 # format patch (diff) line (not to be used for diff headers)
1640 sub format_diff_line
{
1642 my ($from, $to) = @_;
1643 my $diff_class = "";
1647 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1649 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1650 if ($line =~ m/^\@{3}/) {
1651 $diff_class = " chunk_header";
1652 } elsif ($line =~ m/^\\/) {
1653 $diff_class = " incomplete";
1654 } elsif ($prefix =~ tr/+/+/) {
1655 $diff_class = " add";
1656 } elsif ($prefix =~ tr/-/-/) {
1657 $diff_class = " rem";
1660 # assume ordinary diff
1661 my $char = substr($line, 0, 1);
1663 $diff_class = " add";
1664 } elsif ($char eq '-') {
1665 $diff_class = " rem";
1666 } elsif ($char eq '@') {
1667 $diff_class = " chunk_header";
1668 } elsif ($char eq "\\") {
1669 $diff_class = " incomplete";
1672 $line = untabify
($line);
1673 if ($from && $to && $line =~ m/^\@{2} /) {
1674 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1675 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1677 $from_lines = 0 unless defined $from_lines;
1678 $to_lines = 0 unless defined $to_lines;
1680 if ($from->{'href'}) {
1681 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1682 -class=>"list"}, $from_text);
1684 if ($to->{'href'}) {
1685 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1686 -class=>"list"}, $to_text);
1688 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1689 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1690 return "<div class=\"diff$diff_class\">$line</div>\n";
1691 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1692 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1693 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1695 @from_text = split(' ', $ranges);
1696 for (my $i = 0; $i < @from_text; ++$i) {
1697 ($from_start[$i], $from_nlines[$i]) =
1698 (split(',', substr($from_text[$i], 1)), 0);
1701 $to_text = pop @from_text;
1702 $to_start = pop @from_start;
1703 $to_nlines = pop @from_nlines;
1705 $line = "<span class=\"chunk_info\">$prefix ";
1706 for (my $i = 0; $i < @from_text; ++$i) {
1707 if ($from->{'href'}[$i]) {
1708 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1709 -class=>"list"}, $from_text[$i]);
1711 $line .= $from_text[$i];
1715 if ($to->{'href'}) {
1716 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1717 -class=>"list"}, $to_text);
1721 $line .= " $prefix</span>" .
1722 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1723 return "<div class=\"diff$diff_class\">$line</div>\n";
1725 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1728 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1729 # linked. Pass the hash of the tree/commit to snapshot.
1730 sub format_snapshot_links
{
1732 my $num_fmts = @snapshot_fmts;
1733 if ($num_fmts > 1) {
1734 # A parenthesized list of links bearing format names.
1735 # e.g. "snapshot (_tar.gz_ _zip_)"
1736 return "snapshot (" . join(' ', map
1743 }, $known_snapshot_formats{$_}{'display'})
1744 , @snapshot_fmts) . ")";
1745 } elsif ($num_fmts == 1) {
1746 # A single "snapshot" link whose tooltip bears the format name.
1748 my ($fmt) = @snapshot_fmts;
1754 snapshot_format
=>$fmt
1756 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1758 } else { # $num_fmts == 0
1763 ## ......................................................................
1764 ## functions returning values to be passed, perhaps after some
1765 ## transformation, to other functions; e.g. returning arguments to href()
1767 # returns hash to be passed to href to generate gitweb URL
1768 # in -title key it returns description of link
1770 my $format = shift || 'Atom';
1771 my %res = (action
=> lc($format));
1773 # feed links are possible only for project views
1774 return unless (defined $project);
1775 # some views should link to OPML, or to generic project feed,
1776 # or don't have specific feed yet (so they should use generic)
1777 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1780 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1781 # from tag links; this also makes possible to detect branch links
1782 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1783 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1786 # find log type for feed description (title)
1788 if (defined $file_name) {
1789 $type = "history of $file_name";
1790 $type .= "/" if ($action eq 'tree');
1791 $type .= " on '$branch'" if (defined $branch);
1793 $type = "log of $branch" if (defined $branch);
1796 $res{-title
} = $type;
1797 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1798 $res{'file_name'} = $file_name;
1803 ## ----------------------------------------------------------------------
1804 ## git utility subroutines, invoking git commands
1806 # returns path to the core git executable and the --git-dir parameter as list
1808 return $GIT, '--git-dir='.$git_dir;
1811 # quote the given arguments for passing them to the shell
1812 # quote_command("command", "arg 1", "arg with ' and ! characters")
1813 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1814 # Try to avoid using this function wherever possible.
1817 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1820 # get HEAD ref of given project as hash
1821 sub git_get_head_hash
{
1822 my $project = shift;
1823 my $o_git_dir = $git_dir;
1825 $git_dir = "$projectroot/$project";
1826 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1829 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1833 if (defined $o_git_dir) {
1834 $git_dir = $o_git_dir;
1839 # get type of given object
1843 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1845 close $fd or return;
1850 # repository configuration
1851 our $config_file = '';
1854 # store multiple values for single key as anonymous array reference
1855 # single values stored directly in the hash, not as [ <value> ]
1856 sub hash_set_multi
{
1857 my ($hash, $key, $value) = @_;
1859 if (!exists $hash->{$key}) {
1860 $hash->{$key} = $value;
1861 } elsif (!ref $hash->{$key}) {
1862 $hash->{$key} = [ $hash->{$key}, $value ];
1864 push @{$hash->{$key}}, $value;
1868 # return hash of git project configuration
1869 # optionally limited to some section, e.g. 'gitweb'
1870 sub git_parse_project_config
{
1871 my $section_regexp = shift;
1876 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1879 while (my $keyval = <$fh>) {
1881 my ($key, $value) = split(/\n/, $keyval, 2);
1883 hash_set_multi
(\
%config, $key, $value)
1884 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1891 # convert config value to boolean, 'true' or 'false'
1892 # no value, number > 0, 'true' and 'yes' values are true
1893 # rest of values are treated as false (never as error)
1894 sub config_to_bool
{
1897 # strip leading and trailing whitespace
1901 return (!defined $val || # section.key
1902 ($val =~ /^\d+$/ && $val) || # section.key = 1
1903 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1906 # convert config value to simple decimal number
1907 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1908 # to be multiplied by 1024, 1048576, or 1073741824
1912 # strip leading and trailing whitespace
1916 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1918 # unknown unit is treated as 1
1919 return $num * ($unit eq 'g' ? 1073741824 :
1920 $unit eq 'm' ? 1048576 :
1921 $unit eq 'k' ? 1024 : 1);
1926 # convert config value to array reference, if needed
1927 sub config_to_multi
{
1930 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1933 sub git_get_project_config
{
1934 my ($key, $type) = @_;
1937 return unless ($key);
1938 $key =~ s/^gitweb\.//;
1939 return if ($key =~ m/\W/);
1942 if (defined $type) {
1945 unless ($type eq 'bool' || $type eq 'int');
1949 if (!defined $config_file ||
1950 $config_file ne "$git_dir/config") {
1951 %config = git_parse_project_config
('gitweb');
1952 $config_file = "$git_dir/config";
1956 if (!defined $type) {
1957 return $config{"gitweb.$key"};
1958 } elsif ($type eq 'bool') {
1959 # backward compatibility: 'git config --bool' returns true/false
1960 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1961 } elsif ($type eq 'int') {
1962 return config_to_int
($config{"gitweb.$key"});
1964 return $config{"gitweb.$key"};
1967 # get hash of given path at given ref
1968 sub git_get_hash_by_path
{
1970 my $path = shift || return undef;
1975 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1976 or die_error
(500, "Open git-ls-tree failed");
1978 close $fd or return undef;
1980 if (!defined $line) {
1981 # there is no tree or hash given by $path at $base
1985 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1986 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1987 if (defined $type && $type ne $2) {
1988 # type doesn't match
1994 # get path of entry with given hash at given tree-ish (ref)
1995 # used to get 'from' filename for combined diff (merge commit) for renames
1996 sub git_get_path_by_hash
{
1997 my $base = shift || return;
1998 my $hash = shift || return;
2002 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2004 while (my $line = <$fd>) {
2007 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2008 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2009 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2018 ## ......................................................................
2019 ## git utility functions, directly accessing git repository
2021 sub git_get_project_description
{
2024 $git_dir = "$projectroot/$path";
2025 open my $fd, "$git_dir/description"
2026 or return git_get_project_config
('description');
2029 if (defined $descr) {
2035 sub git_get_project_ctags
{
2039 $git_dir = "$projectroot/$path";
2040 unless (opendir D
, "$git_dir/ctags") {
2043 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2044 open CT
, $_ or next;
2048 my $ctag = $_; $ctag =~ s
#.*/##;
2049 $ctags->{$ctag} = $val;
2055 sub git_populate_project_tagcloud
{
2058 # First, merge different-cased tags; tags vote on casing
2060 foreach (keys %$ctags) {
2061 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2062 if (not $ctags_lc{lc $_}->{topcount
}
2063 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2064 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2065 $ctags_lc{lc $_}->{topname
} = $_;
2070 if (eval { require HTML
::TagCloud
; 1; }) {
2071 $cloud = HTML
::TagCloud-
>new;
2072 foreach (sort keys %ctags_lc) {
2073 # Pad the title with spaces so that the cloud looks
2075 my $title = $ctags_lc{$_}->{topname
};
2076 $title =~ s/ / /g;
2077 $title =~ s/^/ /g;
2078 $title =~ s/$/ /g;
2079 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2082 $cloud = \
%ctags_lc;
2087 sub git_show_project_tagcloud
{
2088 my ($cloud, $count) = @_;
2089 print STDERR
ref($cloud)."..\n";
2090 if (ref $cloud eq 'HTML::TagCloud') {
2091 return $cloud->html_and_css($count);
2093 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2094 return '<p align="center">' . join (', ', map {
2095 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2096 } splice(@tags, 0, $count)) . '</p>';
2100 sub git_get_project_url_list
{
2103 $git_dir = "$projectroot/$path";
2104 open my $fd, "$git_dir/cloneurl"
2105 or return wantarray ?
2106 @{ config_to_multi
(git_get_project_config
('url')) } :
2107 config_to_multi
(git_get_project_config
('url'));
2108 my @git_project_url_list = map { chomp; $_ } <$fd>;
2111 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2114 sub git_get_projects_list
{
2119 $filter =~ s/\.git$//;
2121 my $check_forks = gitweb_check_feature
('forks');
2123 if (-d
$projects_list) {
2124 # search in directory
2125 my $dir = $projects_list . ($filter ? "/$filter" : '');
2126 # remove the trailing "/"
2128 my $pfxlen = length("$dir");
2129 my $pfxdepth = ($dir =~ tr!/!!);
2132 follow_fast
=> 1, # follow symbolic links
2133 follow_skip
=> 2, # ignore duplicates
2134 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2136 # skip project-list toplevel, if we get it.
2137 return if (m!^[/.]$!);
2138 # only directories can be git repositories
2139 return unless (-d
$_);
2140 # don't traverse too deep (Find is super slow on os x)
2141 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2142 $File::Find
::prune
= 1;
2146 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2147 # we check related file in $projectroot
2148 if (check_export_ok
("$projectroot/$filter/$subdir")) {
2149 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
2150 $File::Find
::prune
= 1;
2155 } elsif (-f
$projects_list) {
2156 # read from file(url-encoded):
2157 # 'git%2Fgit.git Linus+Torvalds'
2158 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2159 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2161 open my ($fd), $projects_list or return;
2163 while (my $line = <$fd>) {
2165 my ($path, $owner) = split ' ', $line;
2166 $path = unescape
($path);
2167 $owner = unescape
($owner);
2168 if (!defined $path) {
2171 if ($filter ne '') {
2172 # looking for forks;
2173 my $pfx = substr($path, 0, length($filter));
2174 if ($pfx ne $filter) {
2177 my $sfx = substr($path, length($filter));
2178 if ($sfx !~ /^\/.*\
.git
$/) {
2181 } elsif ($check_forks) {
2183 foreach my $filter (keys %paths) {
2184 # looking for forks;
2185 my $pfx = substr($path, 0, length($filter));
2186 if ($pfx ne $filter) {
2189 my $sfx = substr($path, length($filter));
2190 if ($sfx !~ /^\/.*\
.git
$/) {
2193 # is a fork, don't include it in
2198 if (check_export_ok
("$projectroot/$path")) {
2201 owner
=> to_utf8
($owner),
2204 (my $forks_path = $path) =~ s/\.git$//;
2205 $paths{$forks_path}++;
2213 our $gitweb_project_owner = undef;
2214 sub git_get_project_list_from_file
{
2216 return if (defined $gitweb_project_owner);
2218 $gitweb_project_owner = {};
2219 # read from file (url-encoded):
2220 # 'git%2Fgit.git Linus+Torvalds'
2221 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2222 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2223 if (-f
$projects_list) {
2224 open (my $fd , $projects_list);
2225 while (my $line = <$fd>) {
2227 my ($pr, $ow) = split ' ', $line;
2228 $pr = unescape
($pr);
2229 $ow = unescape
($ow);
2230 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2236 sub git_get_project_owner
{
2237 my $project = shift;
2240 return undef unless $project;
2241 $git_dir = "$projectroot/$project";
2243 if (!defined $gitweb_project_owner) {
2244 git_get_project_list_from_file
();
2247 if (exists $gitweb_project_owner->{$project}) {
2248 $owner = $gitweb_project_owner->{$project};
2250 if (!defined $owner){
2251 $owner = git_get_project_config
('owner');
2253 if (!defined $owner) {
2254 $owner = get_file_owner
("$git_dir");
2260 sub git_get_last_activity
{
2264 $git_dir = "$projectroot/$path";
2265 open($fd, "-|", git_cmd
(), 'for-each-ref',
2266 '--format=%(committer)',
2267 '--sort=-committerdate',
2269 'refs/heads') or return;
2270 my $most_recent = <$fd>;
2271 close $fd or return;
2272 if (defined $most_recent &&
2273 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2275 my $age = time - $timestamp;
2276 return ($age, age_string
($age));
2278 return (undef, undef);
2281 sub git_get_references
{
2282 my $type = shift || "";
2284 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2285 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2286 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2287 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2290 while (my $line = <$fd>) {
2292 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2293 if (defined $refs{$1}) {
2294 push @{$refs{$1}}, $2;
2300 close $fd or return;
2304 sub git_get_rev_name_tags
{
2305 my $hash = shift || return undef;
2307 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2309 my $name_rev = <$fd>;
2312 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2315 # catches also '$hash undefined' output
2320 ## ----------------------------------------------------------------------
2321 ## parse to hash functions
2325 my $tz = shift || "-0000";
2328 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2329 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2330 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2331 $date{'hour'} = $hour;
2332 $date{'minute'} = $min;
2333 $date{'mday'} = $mday;
2334 $date{'day'} = $days[$wday];
2335 $date{'month'} = $months[$mon];
2336 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2337 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2338 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2339 $mday, $months[$mon], $hour ,$min;
2340 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2341 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2343 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2344 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2345 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2346 $date{'hour_local'} = $hour;
2347 $date{'minute_local'} = $min;
2348 $date{'tz_local'} = $tz;
2349 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2350 1900+$year, $mon+1, $mday,
2351 $hour, $min, $sec, $tz);
2360 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2361 $tag{'id'} = $tag_id;
2362 while (my $line = <$fd>) {
2364 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2365 $tag{'object'} = $1;
2366 } elsif ($line =~ m/^type (.+)$/) {
2368 } elsif ($line =~ m/^tag (.+)$/) {
2370 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2371 $tag{'author'} = $1;
2374 } elsif ($line =~ m/--BEGIN/) {
2375 push @comment, $line;
2377 } elsif ($line eq "") {
2381 push @comment, <$fd>;
2382 $tag{'comment'} = \
@comment;
2383 close $fd or return;
2384 if (!defined $tag{'name'}) {
2390 sub parse_commit_text
{
2391 my ($commit_text, $withparents) = @_;
2392 my @commit_lines = split '\n', $commit_text;
2395 pop @commit_lines; # Remove '\0'
2397 if (! @commit_lines) {
2401 my $header = shift @commit_lines;
2402 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2405 ($co{'id'}, my @parents) = split ' ', $header;
2406 while (my $line = shift @commit_lines) {
2407 last if $line eq "\n";
2408 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2410 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2412 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2414 $co{'author_epoch'} = $2;
2415 $co{'author_tz'} = $3;
2416 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2417 $co{'author_name'} = $1;
2418 $co{'author_email'} = $2;
2420 $co{'author_name'} = $co{'author'};
2422 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2423 $co{'committer'} = $1;
2424 $co{'committer_epoch'} = $2;
2425 $co{'committer_tz'} = $3;
2426 $co{'committer_name'} = $co{'committer'};
2427 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2428 $co{'committer_name'} = $1;
2429 $co{'committer_email'} = $2;
2431 $co{'committer_name'} = $co{'committer'};
2435 if (!defined $co{'tree'}) {
2438 $co{'parents'} = \
@parents;
2439 $co{'parent'} = $parents[0];
2441 foreach my $title (@commit_lines) {
2444 $co{'title'} = chop_str
($title, 80, 5);
2445 # remove leading stuff of merges to make the interesting part visible
2446 if (length($title) > 50) {
2447 $title =~ s/^Automatic //;
2448 $title =~ s/^merge (of|with) /Merge ... /i;
2449 if (length($title) > 50) {
2450 $title =~ s/(http|rsync):\/\///;
2452 if (length($title) > 50) {
2453 $title =~ s/(master|www|rsync)\.//;
2455 if (length($title) > 50) {
2456 $title =~ s/kernel.org:?//;
2458 if (length($title) > 50) {
2459 $title =~ s/\/pub\/scm//;
2462 $co{'title_short'} = chop_str
($title, 50, 5);
2466 if (! defined $co{'title'} || $co{'title'} eq "") {
2467 $co{'title'} = $co{'title_short'} = '(no commit message)';
2469 # remove added spaces
2470 foreach my $line (@commit_lines) {
2473 $co{'comment'} = \
@commit_lines;
2475 my $age = time - $co{'committer_epoch'};
2477 $co{'age_string'} = age_string
($age);
2478 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2479 if ($age > 60*60*24*7*2) {
2480 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2481 $co{'age_string_age'} = $co{'age_string'};
2483 $co{'age_string_date'} = $co{'age_string'};
2484 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2490 my ($commit_id) = @_;
2495 open my $fd, "-|", git_cmd
(), "rev-list",
2501 or die_error
(500, "Open git-rev-list failed");
2502 %co = parse_commit_text
(<$fd>, 1);
2509 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2517 open my $fd, "-|", git_cmd
(), "rev-list",
2520 ("--max-count=" . $maxcount),
2521 ("--skip=" . $skip),
2525 ($filename ? ($filename) : ())
2526 or die_error
(500, "Open git-rev-list failed");
2527 while (my $line = <$fd>) {
2528 my %co = parse_commit_text
($line);
2533 return wantarray ? @cos : \
@cos;
2536 # parse line of git-diff-tree "raw" output
2537 sub parse_difftree_raw_line
{
2541 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2542 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2543 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2544 $res{'from_mode'} = $1;
2545 $res{'to_mode'} = $2;
2546 $res{'from_id'} = $3;
2548 $res{'status'} = $5;
2549 $res{'similarity'} = $6;
2550 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2551 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2553 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2556 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2557 # combined diff (for merge commit)
2558 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2559 $res{'nparents'} = length($1);
2560 $res{'from_mode'} = [ split(' ', $2) ];
2561 $res{'to_mode'} = pop @{$res{'from_mode'}};
2562 $res{'from_id'} = [ split(' ', $3) ];
2563 $res{'to_id'} = pop @{$res{'from_id'}};
2564 $res{'status'} = [ split('', $4) ];
2565 $res{'to_file'} = unquote
($5);
2567 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2568 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2569 $res{'commit'} = $1;
2572 return wantarray ? %res : \
%res;
2575 # wrapper: return parsed line of git-diff-tree "raw" output
2576 # (the argument might be raw line, or parsed info)
2577 sub parsed_difftree_line
{
2578 my $line_or_ref = shift;
2580 if (ref($line_or_ref) eq "HASH") {
2581 # pre-parsed (or generated by hand)
2582 return $line_or_ref;
2584 return parse_difftree_raw_line
($line_or_ref);
2588 # parse line of git-ls-tree output
2589 sub parse_ls_tree_line
($;%) {
2594 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2595 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2603 $res{'name'} = unquote
($4);
2606 return wantarray ? %res : \
%res;
2609 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2610 sub parse_from_to_diffinfo
{
2611 my ($diffinfo, $from, $to, @parents) = @_;
2613 if ($diffinfo->{'nparents'}) {
2615 $from->{'file'} = [];
2616 $from->{'href'} = [];
2617 fill_from_file_info
($diffinfo, @parents)
2618 unless exists $diffinfo->{'from_file'};
2619 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2620 $from->{'file'}[$i] =
2621 defined $diffinfo->{'from_file'}[$i] ?
2622 $diffinfo->{'from_file'}[$i] :
2623 $diffinfo->{'to_file'};
2624 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2625 $from->{'href'}[$i] = href
(action
=>"blob",
2626 hash_base
=>$parents[$i],
2627 hash
=>$diffinfo->{'from_id'}[$i],
2628 file_name
=>$from->{'file'}[$i]);
2630 $from->{'href'}[$i] = undef;
2634 # ordinary (not combined) diff
2635 $from->{'file'} = $diffinfo->{'from_file'};
2636 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2637 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2638 hash
=>$diffinfo->{'from_id'},
2639 file_name
=>$from->{'file'});
2641 delete $from->{'href'};
2645 $to->{'file'} = $diffinfo->{'to_file'};
2646 if (!is_deleted
($diffinfo)) { # file exists in result
2647 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2648 hash
=>$diffinfo->{'to_id'},
2649 file_name
=>$to->{'file'});
2651 delete $to->{'href'};
2655 ## ......................................................................
2656 ## parse to array of hashes functions
2658 sub git_get_heads_list
{
2662 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2663 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2664 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2667 while (my $line = <$fd>) {
2671 my ($refinfo, $committerinfo) = split(/\0/, $line);
2672 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2673 my ($committer, $epoch, $tz) =
2674 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2675 $ref_item{'fullname'} = $name;
2676 $name =~ s!^refs/heads/!!;
2678 $ref_item{'name'} = $name;
2679 $ref_item{'id'} = $hash;
2680 $ref_item{'title'} = $title || '(no commit message)';
2681 $ref_item{'epoch'} = $epoch;
2683 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2685 $ref_item{'age'} = "unknown";
2688 push @headslist, \
%ref_item;
2692 return wantarray ? @headslist : \
@headslist;
2695 sub git_get_tags_list
{
2699 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2700 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2701 '--format=%(objectname) %(objecttype) %(refname) '.
2702 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2705 while (my $line = <$fd>) {
2709 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2710 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2711 my ($creator, $epoch, $tz) =
2712 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2713 $ref_item{'fullname'} = $name;
2714 $name =~ s!^refs/tags/!!;
2716 $ref_item{'type'} = $type;
2717 $ref_item{'id'} = $id;
2718 $ref_item{'name'} = $name;
2719 if ($type eq "tag") {
2720 $ref_item{'subject'} = $title;
2721 $ref_item{'reftype'} = $reftype;
2722 $ref_item{'refid'} = $refid;
2724 $ref_item{'reftype'} = $type;
2725 $ref_item{'refid'} = $id;
2728 if ($type eq "tag" || $type eq "commit") {
2729 $ref_item{'epoch'} = $epoch;
2731 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2733 $ref_item{'age'} = "unknown";
2737 push @tagslist, \
%ref_item;
2741 return wantarray ? @tagslist : \
@tagslist;
2744 ## ----------------------------------------------------------------------
2745 ## filesystem-related functions
2747 sub get_file_owner
{
2750 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2751 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2752 if (!defined $gcos) {
2756 $owner =~ s/[,;].*$//;
2757 return to_utf8
($owner);
2760 ## ......................................................................
2761 ## mimetype related functions
2763 sub mimetype_guess_file
{
2764 my $filename = shift;
2765 my $mimemap = shift;
2766 -r
$mimemap or return undef;
2769 open(MIME
, $mimemap) or return undef;
2771 next if m/^#/; # skip comments
2772 my ($mime, $exts) = split(/\t+/);
2773 if (defined $exts) {
2774 my @exts = split(/\s+/, $exts);
2775 foreach my $ext (@exts) {
2776 $mimemap{$ext} = $mime;
2782 $filename =~ /\.([^.]*)$/;
2783 return $mimemap{$1};
2786 sub mimetype_guess
{
2787 my $filename = shift;
2789 $filename =~ /\./ or return undef;
2791 if ($mimetypes_file) {
2792 my $file = $mimetypes_file;
2793 if ($file !~ m!^/!) { # if it is relative path
2794 # it is relative to project
2795 $file = "$projectroot/$project/$file";
2797 $mime = mimetype_guess_file
($filename, $file);
2799 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2805 my $filename = shift;
2808 my $mime = mimetype_guess
($filename);
2809 $mime and return $mime;
2813 return $default_blob_plain_mimetype unless $fd;
2816 return 'text/plain';
2817 } elsif (! $filename) {
2818 return 'application/octet-stream';
2819 } elsif ($filename =~ m/\.png$/i) {
2821 } elsif ($filename =~ m/\.gif$/i) {
2823 } elsif ($filename =~ m/\.jpe?g$/i) {
2824 return 'image/jpeg';
2826 return 'application/octet-stream';
2830 sub blob_contenttype
{
2831 my ($fd, $file_name, $type) = @_;
2833 $type ||= blob_mimetype
($fd, $file_name);
2834 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2835 $type .= "; charset=$default_text_plain_charset";
2841 ## ======================================================================
2842 ## functions printing HTML: header, footer, error page
2844 sub git_header_html
{
2845 my $status = shift || "200 OK";
2846 my $expires = shift;
2848 my $title = "$site_name";
2849 if (defined $project) {
2850 $title .= " - " . to_utf8
($project);
2851 if (defined $action) {
2852 $title .= "/$action";
2853 if (defined $file_name) {
2854 $title .= " - " . esc_path
($file_name);
2855 if ($action eq "tree" && $file_name !~ m
|/$|) {
2862 # require explicit support from the UA if we are to send the page as
2863 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2864 # we have to do this because MSIE sometimes globs '*/*', pretending to
2865 # support xhtml+xml but choking when it gets what it asked for.
2866 if (defined $cgi->http('HTTP_ACCEPT') &&
2867 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2868 $cgi->Accept('application/xhtml+xml') != 0) {
2869 $content_type = 'application/xhtml+xml';
2871 $content_type = 'text/html';
2873 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2874 -status
=> $status, -expires
=> $expires);
2875 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2877 <?xml version="1.0" encoding="utf-8"?>
2878 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2879 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2880 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2881 <!-- git core binaries version $git_version -->
2883 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2884 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2885 <meta name="robots" content="index, nofollow"/>
2886 <title>$title</title>
2888 # print out each stylesheet that exist
2889 if (defined $stylesheet) {
2890 #provides backwards capability for those people who define style sheet in a config file
2891 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2893 foreach my $stylesheet (@stylesheets) {
2894 next unless $stylesheet;
2895 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2898 if (defined $project) {
2899 my %href_params = get_feed_info
();
2900 if (!exists $href_params{'-title'}) {
2901 $href_params{'-title'} = 'log';
2904 foreach my $format qw(RSS Atom) {
2905 my $type = lc($format);
2907 '-rel' => 'alternate',
2908 '-title' => "$project - $href_params{'-title'} - $format feed",
2909 '-type' => "application/$type+xml"
2912 $href_params{'action'} = $type;
2913 $link_attr{'-href'} = href
(%href_params);
2915 "rel=\"$link_attr{'-rel'}\" ".
2916 "title=\"$link_attr{'-title'}\" ".
2917 "href=\"$link_attr{'-href'}\" ".
2918 "type=\"$link_attr{'-type'}\" ".
2921 $href_params{'extra_options'} = '--no-merges';
2922 $link_attr{'-href'} = href
(%href_params);
2923 $link_attr{'-title'} .= ' (no merges)';
2925 "rel=\"$link_attr{'-rel'}\" ".
2926 "title=\"$link_attr{'-title'}\" ".
2927 "href=\"$link_attr{'-href'}\" ".
2928 "type=\"$link_attr{'-type'}\" ".
2933 printf('<link rel="alternate" title="%s projects list" '.
2934 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2935 $site_name, href
(project
=>undef, action
=>"project_index"));
2936 printf('<link rel="alternate" title="%s projects feeds" '.
2937 'href="%s" type="text/x-opml" />'."\n",
2938 $site_name, href
(project
=>undef, action
=>"opml"));
2940 if (defined $favicon) {
2941 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2947 if (-f
$site_header) {
2948 open (my $fd, $site_header);
2953 print "<div class=\"page_header\">\n" .
2954 $cgi->a({-href
=> esc_url
($logo_url),
2955 -title
=> $logo_label},
2956 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2957 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2958 if (defined $project) {
2959 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2960 if (defined $action) {
2967 my $have_search = gitweb_check_feature
('search');
2968 if (defined $project && $have_search) {
2969 if (!defined $searchtext) {
2973 if (defined $hash_base) {
2974 $search_hash = $hash_base;
2975 } elsif (defined $hash) {
2976 $search_hash = $hash;
2978 $search_hash = "HEAD";
2980 my $action = $my_uri;
2981 my $use_pathinfo = gitweb_check_feature
('pathinfo');
2982 if ($use_pathinfo) {
2983 $action .= "/".esc_url
($project);
2985 print $cgi->startform(-method => "get", -action
=> $action) .
2986 "<div class=\"search\">\n" .
2988 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2989 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2990 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2991 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2992 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2993 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2995 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2996 "<span title=\"Extended regular expression\">" .
2997 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2998 -checked
=> $search_use_regexp) .
3001 $cgi->end_form() . "\n";
3005 sub git_footer_html
{
3006 my $feed_class = 'rss_logo';
3008 print "<div class=\"page_footer\">\n";
3009 if (defined $project) {
3010 my $descr = git_get_project_description
($project);
3011 if (defined $descr) {
3012 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3015 my %href_params = get_feed_info
();
3016 if (!%href_params) {
3017 $feed_class .= ' generic';
3019 $href_params{'-title'} ||= 'log';
3021 foreach my $format qw(RSS Atom) {
3022 $href_params{'action'} = lc($format);
3023 print $cgi->a({-href
=> href
(%href_params),
3024 -title
=> "$href_params{'-title'} $format feed",
3025 -class => $feed_class}, $format)."\n";
3029 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3030 -class => $feed_class}, "OPML") . " ";
3031 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3032 -class => $feed_class}, "TXT") . "\n";
3034 print "</div>\n"; # class="page_footer"
3036 if (-f
$site_footer) {
3037 open (my $fd, $site_footer);
3046 # die_error(<http_status_code>, <error_message>)
3047 # Example: die_error(404, 'Hash not found')
3048 # By convention, use the following status codes (as defined in RFC 2616):
3049 # 400: Invalid or missing CGI parameters, or
3050 # requested object exists but has wrong type.
3051 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3052 # this server or project.
3053 # 404: Requested object/revision/project doesn't exist.
3054 # 500: The server isn't configured properly, or
3055 # an internal error occurred (e.g. failed assertions caused by bugs), or
3056 # an unknown error occurred (e.g. the git binary died unexpectedly).
3058 my $status = shift || 500;
3059 my $error = shift || "Internal server error";
3061 my %http_responses = (400 => '400 Bad Request',
3062 403 => '403 Forbidden',
3063 404 => '404 Not Found',
3064 500 => '500 Internal Server Error');
3065 git_header_html
($http_responses{$status});
3067 <div class="page_body">
3077 ## ----------------------------------------------------------------------
3078 ## functions printing or outputting HTML: navigation
3080 sub git_print_page_nav
{
3081 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3082 $extra = '' if !defined $extra; # pager or formats
3084 my @navs = qw(summary shortlog log commit commitdiff tree);
3086 @navs = grep { $_ ne $suppress } @navs;
3089 my %arg = map { $_ => {action
=>$_} } @navs;
3090 if (defined $head) {
3091 for (qw(commit commitdiff)) {
3092 $arg{$_}{'hash'} = $head;
3094 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3095 for (qw(shortlog log)) {
3096 $arg{$_}{'hash'} = $head;
3101 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3102 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3104 my @actions = gitweb_get_feature
('actions');
3107 'n' => $project, # project name
3108 'f' => $git_dir, # project path within filesystem
3109 'h' => $treehead || '', # current hash ('h' parameter)
3110 'b' => $treebase || '', # hash base ('hb' parameter)
3113 my ($label, $link, $pos) = splice(@actions,0,3);
3115 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3117 $link =~ s/%([%nfhb])/$repl{$1}/g;
3118 $arg{$label}{'_href'} = $link;
3121 print "<div class=\"page_nav\">\n" .
3123 map { $_ eq $current ?
3124 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3126 print "<br/>\n$extra<br/>\n" .
3130 sub format_paging_nav
{
3131 my ($action, $hash, $head, $page, $has_next_link) = @_;
3135 if ($hash ne $head || $page) {
3136 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3138 $paging_nav .= "HEAD";
3142 $paging_nav .= " ⋅ " .
3143 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3144 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3146 $paging_nav .= " ⋅ prev";
3149 if ($has_next_link) {
3150 $paging_nav .= " ⋅ " .
3151 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3152 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3154 $paging_nav .= " ⋅ next";
3160 ## ......................................................................
3161 ## functions printing or outputting HTML: div
3163 sub git_print_header_div
{
3164 my ($action, $title, $hash, $hash_base) = @_;
3167 $args{'action'} = $action;
3168 $args{'hash'} = $hash if $hash;
3169 $args{'hash_base'} = $hash_base if $hash_base;
3171 print "<div class=\"header\">\n" .
3172 $cgi->a({-href
=> href
(%args), -class => "title"},
3173 $title ? $title : $action) .
3177 #sub git_print_authorship (\%) {
3178 sub git_print_authorship
{
3181 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3182 print "<div class=\"author_date\">" .
3183 esc_html
($co->{'author_name'}) .
3185 if ($ad{'hour_local'} < 6) {
3186 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3187 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3189 printf(" (%02d:%02d %s)",
3190 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3195 sub git_print_page_path
{
3201 print "<div class=\"page_path\">";
3202 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3203 -title
=> 'tree root'}, to_utf8
("[$project]"));
3205 if (defined $name) {
3206 my @dirname = split '/', $name;
3207 my $basename = pop @dirname;
3210 foreach my $dir (@dirname) {
3211 $fullname .= ($fullname ? '/' : '') . $dir;
3212 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3214 -title
=> $fullname}, esc_path
($dir));
3217 if (defined $type && $type eq 'blob') {
3218 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3220 -title
=> $name}, esc_path
($basename));
3221 } elsif (defined $type && $type eq 'tree') {
3222 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3224 -title
=> $name}, esc_path
($basename));
3227 print esc_path
($basename);
3230 print "<br/></div>\n";
3233 # sub git_print_log (\@;%) {
3234 sub git_print_log
($;%) {
3238 if ($opts{'-remove_title'}) {
3239 # remove title, i.e. first line of log
3242 # remove leading empty lines
3243 while (defined $log->[0] && $log->[0] eq "") {
3250 foreach my $line (@$log) {
3251 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3254 if (! $opts{'-remove_signoff'}) {
3255 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3258 # remove signoff lines
3265 # print only one empty line
3266 # do not print empty line after signoff
3268 next if ($empty || $signoff);
3274 print format_log_line_html
($line) . "<br/>\n";
3277 if ($opts{'-final_empty_line'}) {
3278 # end with single empty line
3279 print "<br/>\n" unless $empty;
3283 # return link target (what link points to)
3284 sub git_get_link_target
{
3289 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3293 $link_target = <$fd>;
3298 return $link_target;
3301 # given link target, and the directory (basedir) the link is in,
3302 # return target of link relative to top directory (top tree);
3303 # return undef if it is not possible (including absolute links).
3304 sub normalize_link_target
{
3305 my ($link_target, $basedir, $hash_base) = @_;
3307 # we can normalize symlink target only if $hash_base is provided
3308 return unless $hash_base;
3310 # absolute symlinks (beginning with '/') cannot be normalized
3311 return if (substr($link_target, 0, 1) eq '/');
3313 # normalize link target to path from top (root) tree (dir)
3316 $path = $basedir . '/' . $link_target;
3318 # we are in top (root) tree (dir)
3319 $path = $link_target;
3322 # remove //, /./, and /../
3324 foreach my $part (split('/', $path)) {
3325 # discard '.' and ''
3326 next if (!$part || $part eq '.');
3328 if ($part eq '..') {
3332 # link leads outside repository (outside top dir)
3336 push @path_parts, $part;
3339 $path = join('/', @path_parts);
3344 # print tree entry (row of git_tree), but without encompassing <tr> element
3345 sub git_print_tree_entry
{
3346 my ($t, $basedir, $hash_base, $have_blame) = @_;
3349 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3351 # The format of a table row is: mode list link. Where mode is
3352 # the mode of the entry, list is the name of the entry, an href,
3353 # and link is the action links of the entry.
3355 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3356 if ($t->{'type'} eq "blob") {
3357 print "<td class=\"list\">" .
3358 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3359 file_name
=>"$basedir$t->{'name'}", %base_key),
3360 -class => "list"}, esc_path
($t->{'name'}));
3361 if (S_ISLNK
(oct $t->{'mode'})) {
3362 my $link_target = git_get_link_target
($t->{'hash'});
3364 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3365 if (defined $norm_target) {
3367 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3368 file_name
=>$norm_target),
3369 -title
=> $norm_target}, esc_path
($link_target));
3371 print " -> " . esc_path
($link_target);
3376 print "<td class=\"link\">";
3377 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3378 file_name
=>"$basedir$t->{'name'}", %base_key)},
3382 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3383 file_name
=>"$basedir$t->{'name'}", %base_key)},
3386 if (defined $hash_base) {
3388 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3389 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3393 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3394 file_name
=>"$basedir$t->{'name'}")},
3398 } elsif ($t->{'type'} eq "tree") {
3399 print "<td class=\"list\">";
3400 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3401 file_name
=>"$basedir$t->{'name'}", %base_key)},
3402 esc_path
($t->{'name'}));
3404 print "<td class=\"link\">";
3405 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3406 file_name
=>"$basedir$t->{'name'}", %base_key)},
3408 if (defined $hash_base) {
3410 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3411 file_name
=>"$basedir$t->{'name'}")},
3416 # unknown object: we can only present history for it
3417 # (this includes 'commit' object, i.e. submodule support)
3418 print "<td class=\"list\">" .
3419 esc_path
($t->{'name'}) .
3421 print "<td class=\"link\">";
3422 if (defined $hash_base) {
3423 print $cgi->a({-href
=> href
(action
=>"history",
3424 hash_base
=>$hash_base,
3425 file_name
=>"$basedir$t->{'name'}")},
3432 ## ......................................................................
3433 ## functions printing large fragments of HTML
3435 # get pre-image filenames for merge (combined) diff
3436 sub fill_from_file_info
{
3437 my ($diff, @parents) = @_;
3439 $diff->{'from_file'} = [ ];
3440 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3441 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3442 if ($diff->{'status'}[$i] eq 'R' ||
3443 $diff->{'status'}[$i] eq 'C') {
3444 $diff->{'from_file'}[$i] =
3445 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3452 # is current raw difftree line of file deletion
3454 my $diffinfo = shift;
3456 return $diffinfo->{'to_id'} eq ('0' x
40);
3459 # does patch correspond to [previous] difftree raw line
3460 # $diffinfo - hashref of parsed raw diff format
3461 # $patchinfo - hashref of parsed patch diff format
3462 # (the same keys as in $diffinfo)
3463 sub is_patch_split
{
3464 my ($diffinfo, $patchinfo) = @_;
3466 return defined $diffinfo && defined $patchinfo
3467 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3471 sub git_difftree_body
{
3472 my ($difftree, $hash, @parents) = @_;
3473 my ($parent) = $parents[0];
3474 my $have_blame = gitweb_check_feature
('blame');
3475 print "<div class=\"list_head\">\n";
3476 if ($#{$difftree} > 10) {
3477 print(($#{$difftree} + 1) . " files changed:\n");
3481 print "<table class=\"" .
3482 (@parents > 1 ? "combined " : "") .
3485 # header only for combined diff in 'commitdiff' view
3486 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3489 print "<thead><tr>\n" .
3490 "<th></th><th></th>\n"; # filename, patchN link
3491 for (my $i = 0; $i < @parents; $i++) {
3492 my $par = $parents[$i];
3494 $cgi->a({-href
=> href
(action
=>"commitdiff",
3495 hash
=>$hash, hash_parent
=>$par),
3496 -title
=> 'commitdiff to parent number ' .
3497 ($i+1) . ': ' . substr($par,0,7)},
3501 print "</tr></thead>\n<tbody>\n";
3506 foreach my $line (@{$difftree}) {
3507 my $diff = parsed_difftree_line
($line);
3510 print "<tr class=\"dark\">\n";
3512 print "<tr class=\"light\">\n";
3516 if (exists $diff->{'nparents'}) { # combined diff
3518 fill_from_file_info
($diff, @parents)
3519 unless exists $diff->{'from_file'};
3521 if (!is_deleted
($diff)) {
3522 # file exists in the result (child) commit
3524 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3525 file_name
=>$diff->{'to_file'},
3527 -class => "list"}, esc_path
($diff->{'to_file'})) .
3531 esc_path
($diff->{'to_file'}) .
3535 if ($action eq 'commitdiff') {
3538 print "<td class=\"link\">" .
3539 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3544 my $has_history = 0;
3545 my $not_deleted = 0;
3546 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3547 my $hash_parent = $parents[$i];
3548 my $from_hash = $diff->{'from_id'}[$i];
3549 my $from_path = $diff->{'from_file'}[$i];
3550 my $status = $diff->{'status'}[$i];
3552 $has_history ||= ($status ne 'A');
3553 $not_deleted ||= ($status ne 'D');
3555 if ($status eq 'A') {
3556 print "<td class=\"link\" align=\"right\"> | </td>\n";
3557 } elsif ($status eq 'D') {
3558 print "<td class=\"link\">" .
3559 $cgi->a({-href
=> href
(action
=>"blob",
3562 file_name
=>$from_path)},
3566 if ($diff->{'to_id'} eq $from_hash) {
3567 print "<td class=\"link nochange\">";
3569 print "<td class=\"link\">";
3571 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3572 hash
=>$diff->{'to_id'},
3573 hash_parent
=>$from_hash,
3575 hash_parent_base
=>$hash_parent,
3576 file_name
=>$diff->{'to_file'},
3577 file_parent
=>$from_path)},
3583 print "<td class=\"link\">";
3585 print $cgi->a({-href
=> href
(action
=>"blob",
3586 hash
=>$diff->{'to_id'},
3587 file_name
=>$diff->{'to_file'},
3590 print " | " if ($has_history);
3593 print $cgi->a({-href
=> href
(action
=>"history",
3594 file_name
=>$diff->{'to_file'},
3601 next; # instead of 'else' clause, to avoid extra indent
3603 # else ordinary diff
3605 my ($to_mode_oct, $to_mode_str, $to_file_type);
3606 my ($from_mode_oct, $from_mode_str, $from_file_type);
3607 if ($diff->{'to_mode'} ne ('0' x
6)) {
3608 $to_mode_oct = oct $diff->{'to_mode'};
3609 if (S_ISREG
($to_mode_oct)) { # only for regular file
3610 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3612 $to_file_type = file_type
($diff->{'to_mode'});
3614 if ($diff->{'from_mode'} ne ('0' x
6)) {
3615 $from_mode_oct = oct $diff->{'from_mode'};
3616 if (S_ISREG
($to_mode_oct)) { # only for regular file
3617 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3619 $from_file_type = file_type
($diff->{'from_mode'});
3622 if ($diff->{'status'} eq "A") { # created
3623 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3624 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3625 $mode_chng .= "]</span>";
3627 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3628 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3629 -class => "list"}, esc_path
($diff->{'file'}));
3631 print "<td>$mode_chng</td>\n";
3632 print "<td class=\"link\">";
3633 if ($action eq 'commitdiff') {
3636 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3639 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3640 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3644 } elsif ($diff->{'status'} eq "D") { # deleted
3645 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3647 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3648 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3649 -class => "list"}, esc_path
($diff->{'file'}));
3651 print "<td>$mode_chng</td>\n";
3652 print "<td class=\"link\">";
3653 if ($action eq 'commitdiff') {
3656 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3659 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3660 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3663 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3664 file_name
=>$diff->{'file'})},
3667 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3668 file_name
=>$diff->{'file'})},
3672 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3673 my $mode_chnge = "";
3674 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3675 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3676 if ($from_file_type ne $to_file_type) {
3677 $mode_chnge .= " from $from_file_type to $to_file_type";
3679 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3680 if ($from_mode_str && $to_mode_str) {
3681 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3682 } elsif ($to_mode_str) {
3683 $mode_chnge .= " mode: $to_mode_str";
3686 $mode_chnge .= "]</span>\n";
3689 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3690 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3691 -class => "list"}, esc_path
($diff->{'file'}));
3693 print "<td>$mode_chnge</td>\n";
3694 print "<td class=\"link\">";
3695 if ($action eq 'commitdiff') {
3698 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3700 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3701 # "commit" view and modified file (not onlu mode changed)
3702 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3703 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3704 hash_base
=>$hash, hash_parent_base
=>$parent,
3705 file_name
=>$diff->{'file'})},
3709 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3710 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3713 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3714 file_name
=>$diff->{'file'})},
3717 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3718 file_name
=>$diff->{'file'})},
3722 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3723 my %status_name = ('R' => 'moved', 'C' => 'copied');
3724 my $nstatus = $status_name{$diff->{'status'}};
3726 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3727 # mode also for directories, so we cannot use $to_mode_str
3728 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3731 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3732 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3733 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3734 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3735 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3736 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3737 -class => "list"}, esc_path
($diff->{'from_file'})) .
3738 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3739 "<td class=\"link\">";
3740 if ($action eq 'commitdiff') {
3743 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3745 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3746 # "commit" view and modified file (not only pure rename or copy)
3747 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3748 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3749 hash_base
=>$hash, hash_parent_base
=>$parent,
3750 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3754 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3755 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3758 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3759 file_name
=>$diff->{'to_file'})},
3762 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3763 file_name
=>$diff->{'to_file'})},
3767 } # we should not encounter Unmerged (U) or Unknown (X) status
3770 print "</tbody>" if $has_header;
3774 sub git_patchset_body
{
3775 my ($fd, $difftree, $hash, @hash_parents) = @_;
3776 my ($hash_parent) = $hash_parents[0];
3778 my $is_combined = (@hash_parents > 1);
3780 my $patch_number = 0;
3786 print "<div class=\"patchset\">\n";
3788 # skip to first patch
3789 while ($patch_line = <$fd>) {
3792 last if ($patch_line =~ m/^diff /);
3796 while ($patch_line) {
3798 # parse "git diff" header line
3799 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3800 # $1 is from_name, which we do not use
3801 $to_name = unquote
($2);
3802 $to_name =~ s!^b/!!;
3803 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3804 # $1 is 'cc' or 'combined', which we do not use
3805 $to_name = unquote
($2);
3810 # check if current patch belong to current raw line
3811 # and parse raw git-diff line if needed
3812 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3813 # this is continuation of a split patch
3814 print "<div class=\"patch cont\">\n";
3816 # advance raw git-diff output if needed
3817 $patch_idx++ if defined $diffinfo;
3819 # read and prepare patch information
3820 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3822 # compact combined diff output can have some patches skipped
3823 # find which patch (using pathname of result) we are at now;
3825 while ($to_name ne $diffinfo->{'to_file'}) {
3826 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3827 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3828 "</div>\n"; # class="patch"
3833 last if $patch_idx > $#$difftree;
3834 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3838 # modifies %from, %to hashes
3839 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3841 # this is first patch for raw difftree line with $patch_idx index
3842 # we index @$difftree array from 0, but number patches from 1
3843 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3847 #assert($patch_line =~ m/^diff /) if DEBUG;
3848 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3850 # print "git diff" header
3851 print format_git_diff_header_line
($patch_line, $diffinfo,
3854 # print extended diff header
3855 print "<div class=\"diff extended_header\">\n";
3857 while ($patch_line = <$fd>) {
3860 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3862 print format_extended_diff_header_line
($patch_line, $diffinfo,
3865 print "</div>\n"; # class="diff extended_header"
3867 # from-file/to-file diff header
3868 if (! $patch_line) {
3869 print "</div>\n"; # class="patch"
3872 next PATCH
if ($patch_line =~ m/^diff /);
3873 #assert($patch_line =~ m/^---/) if DEBUG;
3875 my $last_patch_line = $patch_line;
3876 $patch_line = <$fd>;
3878 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3880 print format_diff_from_to_header
($last_patch_line, $patch_line,
3881 $diffinfo, \
%from, \
%to,
3886 while ($patch_line = <$fd>) {
3889 next PATCH
if ($patch_line =~ m/^diff /);
3891 print format_diff_line
($patch_line, \
%from, \
%to);
3895 print "</div>\n"; # class="patch"
3898 # for compact combined (--cc) format, with chunk and patch simpliciaction
3899 # patchset might be empty, but there might be unprocessed raw lines
3900 for (++$patch_idx if $patch_number > 0;
3901 $patch_idx < @$difftree;
3903 # read and prepare patch information
3904 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3906 # generate anchor for "patch" links in difftree / whatchanged part
3907 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3908 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3909 "</div>\n"; # class="patch"
3914 if ($patch_number == 0) {
3915 if (@hash_parents > 1) {
3916 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3918 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3922 print "</div>\n"; # class="patchset"
3925 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3927 # fills project list info (age, description, owner, forks) for each
3928 # project in the list, removing invalid projects from returned list
3929 # NOTE: modifies $projlist, but does not remove entries from it
3930 sub fill_project_list_info
{
3931 my ($projlist, $check_forks) = @_;
3934 my $show_ctags = gitweb_check_feature
('ctags');
3936 foreach my $pr (@$projlist) {
3937 my (@activity) = git_get_last_activity
($pr->{'path'});
3938 unless (@activity) {
3941 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3942 if (!defined $pr->{'descr'}) {
3943 my $descr = git_get_project_description
($pr->{'path'}) || "";
3944 $descr = to_utf8
($descr);
3945 $pr->{'descr_long'} = $descr;
3946 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3948 if (!defined $pr->{'owner'}) {
3949 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3952 my $pname = $pr->{'path'};
3953 if (($pname =~ s/\.git$//) &&
3954 ($pname !~ /\/$/) &&
3955 (-d
"$projectroot/$pname")) {
3956 $pr->{'forks'} = "-d $projectroot/$pname";
3961 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3962 push @projects, $pr;
3968 # print 'sort by' <th> element, generating 'sort by $name' replay link
3969 # if that order is not selected
3971 my ($name, $order, $header) = @_;
3972 $header ||= ucfirst($name);
3974 if ($order eq $name) {
3975 print "<th>$header</th>\n";
3978 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3979 -class => "header"}, $header) .
3984 sub git_project_list_body
{
3985 # actually uses global variable $project
3986 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3988 my $check_forks = gitweb_check_feature
('forks');
3989 my @projects = fill_project_list_info
($projlist, $check_forks);
3991 $order ||= $default_projects_order;
3992 $from = 0 unless defined $from;
3993 $to = $#projects if (!defined $to || $#projects < $to);
3996 project
=> { key
=> 'path', type
=> 'str' },
3997 descr
=> { key
=> 'descr_long', type
=> 'str' },
3998 owner
=> { key
=> 'owner', type
=> 'str' },
3999 age
=> { key
=> 'age', type
=> 'num' }
4001 my $oi = $order_info{$order};
4002 if ($oi->{'type'} eq 'str') {
4003 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4005 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4008 my $show_ctags = gitweb_check_feature
('ctags');
4011 foreach my $p (@projects) {
4012 foreach my $ct (keys %{$p->{'ctags'}}) {
4013 $ctags{$ct} += $p->{'ctags'}->{$ct};
4016 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4017 print git_show_project_tagcloud
($cloud, 64);
4020 print "<table class=\"project_list\">\n";
4021 unless ($no_header) {
4024 print "<th></th>\n";
4026 print_sort_th
('project', $order, 'Project');
4027 print_sort_th
('descr', $order, 'Description');
4028 print_sort_th
('owner', $order, 'Owner');
4029 print_sort_th
('age', $order, 'Last Change');
4030 print "<th></th>\n" . # for links
4034 my $tagfilter = $cgi->param('by_tag');
4035 for (my $i = $from; $i <= $to; $i++) {
4036 my $pr = $projects[$i];
4038 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4039 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4040 and not $pr->{'descr_long'} =~ /$searchtext/;
4041 # Weed out forks or non-matching entries of search
4043 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4044 $forkbase="^$forkbase" if $forkbase;
4045 next if not $searchtext and not $tagfilter and $show_ctags
4046 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4050 print "<tr class=\"dark\">\n";
4052 print "<tr class=\"light\">\n";
4057 if ($pr->{'forks'}) {
4058 print "<!-- $pr->{'forks'} -->\n";
4059 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4063 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4064 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4065 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4066 -class => "list", -title
=> $pr->{'descr_long'}},
4067 esc_html
($pr->{'descr'})) . "</td>\n" .
4068 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4069 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4070 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4071 "<td class=\"link\">" .
4072 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4073 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4074 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4075 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4076 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4080 if (defined $extra) {
4083 print "<td></td>\n";
4085 print "<td colspan=\"5\">$extra</td>\n" .
4091 sub git_shortlog_body
{
4092 # uses global variable $project
4093 my ($commitlist, $from, $to, $refs, $extra) = @_;
4095 $from = 0 unless defined $from;
4096 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4098 print "<table class=\"shortlog\">\n";
4100 for (my $i = $from; $i <= $to; $i++) {
4101 my %co = %{$commitlist->[$i]};
4102 my $commit = $co{'id'};
4103 my $ref = format_ref_marker
($refs, $commit);
4105 print "<tr class=\"dark\">\n";
4107 print "<tr class=\"light\">\n";
4110 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4111 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4112 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4113 "<td><i>" . $author . "</i></td>\n" .
4115 print format_subject_html
($co{'title'}, $co{'title_short'},
4116 href
(action
=>"commit", hash
=>$commit), $ref);
4118 "<td class=\"link\">" .
4119 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4120 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4121 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4122 my $snapshot_links = format_snapshot_links
($commit);
4123 if (defined $snapshot_links) {
4124 print " | " . $snapshot_links;
4129 if (defined $extra) {
4131 "<td colspan=\"4\">$extra</td>\n" .
4137 sub git_history_body
{
4138 # Warning: assumes constant type (blob or tree) during history
4139 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4141 $from = 0 unless defined $from;
4142 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4144 print "<table class=\"history\">\n";
4146 for (my $i = $from; $i <= $to; $i++) {
4147 my %co = %{$commitlist->[$i]};
4151 my $commit = $co{'id'};
4153 my $ref = format_ref_marker
($refs, $commit);
4156 print "<tr class=\"dark\">\n";
4158 print "<tr class=\"light\">\n";
4161 # shortlog uses chop_str($co{'author_name'}, 10)
4162 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4163 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4164 "<td><i>" . $author . "</i></td>\n" .
4166 # originally git_history used chop_str($co{'title'}, 50)
4167 print format_subject_html
($co{'title'}, $co{'title_short'},
4168 href
(action
=>"commit", hash
=>$commit), $ref);
4170 "<td class=\"link\">" .
4171 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4172 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4174 if ($ftype eq 'blob') {
4175 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4176 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4177 if (defined $blob_current && defined $blob_parent &&
4178 $blob_current ne $blob_parent) {
4180 $cgi->a({-href
=> href
(action
=>"blobdiff",
4181 hash
=>$blob_current, hash_parent
=>$blob_parent,
4182 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4183 file_name
=>$file_name)},
4190 if (defined $extra) {
4192 "<td colspan=\"4\">$extra</td>\n" .
4199 # uses global variable $project
4200 my ($taglist, $from, $to, $extra) = @_;
4201 $from = 0 unless defined $from;
4202 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4204 print "<table class=\"tags\">\n";
4206 for (my $i = $from; $i <= $to; $i++) {
4207 my $entry = $taglist->[$i];
4209 my $comment = $tag{'subject'};
4211 if (defined $comment) {
4212 $comment_short = chop_str
($comment, 30, 5);
4215 print "<tr class=\"dark\">\n";
4217 print "<tr class=\"light\">\n";
4220 if (defined $tag{'age'}) {
4221 print "<td><i>$tag{'age'}</i></td>\n";
4223 print "<td></td>\n";
4226 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4227 -class => "list name"}, esc_html
($tag{'name'})) .
4230 if (defined $comment) {
4231 print format_subject_html
($comment, $comment_short,
4232 href
(action
=>"tag", hash
=>$tag{'id'}));
4235 "<td class=\"selflink\">";
4236 if ($tag{'type'} eq "tag") {
4237 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4242 "<td class=\"link\">" . " | " .
4243 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4244 if ($tag{'reftype'} eq "commit") {
4245 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4246 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4247 } elsif ($tag{'reftype'} eq "blob") {
4248 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4253 if (defined $extra) {
4255 "<td colspan=\"5\">$extra</td>\n" .
4261 sub git_heads_body
{
4262 # uses global variable $project
4263 my ($headlist, $head, $from, $to, $extra) = @_;
4264 $from = 0 unless defined $from;
4265 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4267 print "<table class=\"heads\">\n";
4269 for (my $i = $from; $i <= $to; $i++) {
4270 my $entry = $headlist->[$i];
4272 my $curr = $ref{'id'} eq $head;
4274 print "<tr class=\"dark\">\n";
4276 print "<tr class=\"light\">\n";
4279 print "<td><i>$ref{'age'}</i></td>\n" .
4280 ($curr ? "<td class=\"current_head\">" : "<td>") .
4281 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4282 -class => "list name"},esc_html
($ref{'name'})) .
4284 "<td class=\"link\">" .
4285 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4286 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4287 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4291 if (defined $extra) {
4293 "<td colspan=\"3\">$extra</td>\n" .
4299 sub git_search_grep_body
{
4300 my ($commitlist, $from, $to, $extra) = @_;
4301 $from = 0 unless defined $from;
4302 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4304 print "<table class=\"commit_search\">\n";
4306 for (my $i = $from; $i <= $to; $i++) {
4307 my %co = %{$commitlist->[$i]};
4311 my $commit = $co{'id'};
4313 print "<tr class=\"dark\">\n";
4315 print "<tr class=\"light\">\n";
4318 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4319 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4320 "<td><i>" . $author . "</i></td>\n" .
4322 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4323 -class => "list subject"},
4324 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4325 my $comment = $co{'comment'};
4326 foreach my $line (@$comment) {
4327 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4328 my ($lead, $match, $trail) = ($1, $2, $3);
4329 $match = chop_str
($match, 70, 5, 'center');
4330 my $contextlen = int((80 - length($match))/2);
4331 $contextlen = 30 if ($contextlen > 30);
4332 $lead = chop_str
($lead, $contextlen, 10, 'left');
4333 $trail = chop_str
($trail, $contextlen, 10, 'right');
4335 $lead = esc_html
($lead);
4336 $match = esc_html
($match);
4337 $trail = esc_html
($trail);
4339 print "$lead<span class=\"match\">$match</span>$trail<br />";
4343 "<td class=\"link\">" .
4344 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4346 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4348 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4352 if (defined $extra) {
4354 "<td colspan=\"3\">$extra</td>\n" .
4360 ## ======================================================================
4361 ## ======================================================================
4364 sub git_project_list
{
4365 my $order = $input_params{'order'};
4366 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4367 die_error
(400, "Unknown order parameter");
4370 my @list = git_get_projects_list
();
4372 die_error
(404, "No projects found");
4376 if (-f
$home_text) {
4377 print "<div class=\"index_include\">\n";
4378 open (my $fd, $home_text);
4383 print $cgi->startform(-method => "get") .
4384 "<p class=\"projsearch\">Search:\n" .
4385 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4387 $cgi->end_form() . "\n";
4388 git_project_list_body
(\
@list, $order);
4393 my $order = $input_params{'order'};
4394 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4395 die_error
(400, "Unknown order parameter");
4398 my @list = git_get_projects_list
($project);
4400 die_error
(404, "No forks found");
4404 git_print_page_nav
('','');
4405 git_print_header_div
('summary', "$project forks");
4406 git_project_list_body
(\
@list, $order);
4410 sub git_project_index
{
4411 my @projects = git_get_projects_list
($project);
4414 -type
=> 'text/plain',
4415 -charset
=> 'utf-8',
4416 -content_disposition
=> 'inline; filename="index.aux"');
4418 foreach my $pr (@projects) {
4419 if (!exists $pr->{'owner'}) {
4420 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4423 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4424 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4425 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4426 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4430 print "$path $owner\n";
4435 my $descr = git_get_project_description
($project) || "none";
4436 my %co = parse_commit
("HEAD");
4437 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4438 my $head = $co{'id'};
4440 my $owner = git_get_project_owner
($project);
4442 my $refs = git_get_references
();
4443 # These get_*_list functions return one more to allow us to see if
4444 # there are more ...
4445 my @taglist = git_get_tags_list
(16);
4446 my @headlist = git_get_heads_list
(16);
4448 my $check_forks = gitweb_check_feature
('forks');
4451 @forklist = git_get_projects_list
($project);
4455 git_print_page_nav
('summary','', $head);
4457 print "<div class=\"title\"> </div>\n";
4458 print "<table class=\"projects_list\">\n" .
4459 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4460 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4461 if (defined $cd{'rfc2822'}) {
4462 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4465 # use per project git URL list in $projectroot/$project/cloneurl
4466 # or make project git URL from git base URL and project name
4467 my $url_tag = "URL";
4468 my @url_list = git_get_project_url_list
($project);
4469 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4470 foreach my $git_url (@url_list) {
4471 next unless $git_url;
4472 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4477 my $show_ctags = gitweb_check_feature
('ctags');
4479 my $ctags = git_get_project_ctags
($project);
4480 my $cloud = git_populate_project_tagcloud
($ctags);
4481 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4482 print "</td>\n<td>" unless %$ctags;
4483 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4484 print "</td>\n<td>" if %$ctags;
4485 print git_show_project_tagcloud
($cloud, 48);
4491 if (-s
"$projectroot/$project/README.html") {
4492 if (open my $fd, "$projectroot/$project/README.html") {
4493 print "<div class=\"title\">readme</div>\n" .
4494 "<div class=\"readme\">\n";
4495 print $_ while (<$fd>);
4496 print "\n</div>\n"; # class="readme"
4501 # we need to request one more than 16 (0..15) to check if
4503 my @commitlist = $head ? parse_commits
($head, 17) : ();
4505 git_print_header_div
('shortlog');
4506 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4507 $#commitlist <= 15 ? undef :
4508 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4512 git_print_header_div
('tags');
4513 git_tags_body
(\
@taglist, 0, 15,
4514 $#taglist <= 15 ? undef :
4515 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4519 git_print_header_div
('heads');
4520 git_heads_body
(\
@headlist, $head, 0, 15,
4521 $#headlist <= 15 ? undef :
4522 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4526 git_print_header_div
('forks');
4527 git_project_list_body
(\
@forklist, 'age', 0, 15,
4528 $#forklist <= 15 ? undef :
4529 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4537 my $head = git_get_head_hash
($project);
4539 git_print_page_nav
('','', $head,undef,$head);
4540 my %tag = parse_tag
($hash);
4543 die_error
(404, "Unknown tag object");
4546 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4547 print "<div class=\"title_text\">\n" .
4548 "<table class=\"object_header\">\n" .
4550 "<td>object</td>\n" .
4551 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4552 $tag{'object'}) . "</td>\n" .
4553 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4554 $tag{'type'}) . "</td>\n" .
4556 if (defined($tag{'author'})) {
4557 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4558 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4559 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4560 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4563 print "</table>\n\n" .
4565 print "<div class=\"page_body\">";
4566 my $comment = $tag{'comment'};
4567 foreach my $line (@$comment) {
4569 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4579 gitweb_check_feature
('blame')
4580 or die_error
(403, "Blame view not allowed");
4582 die_error
(400, "No file name given") unless $file_name;
4583 $hash_base ||= git_get_head_hash
($project);
4584 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4585 my %co = parse_commit
($hash_base)
4586 or die_error
(404, "Commit not found");
4587 if (!defined $hash) {
4588 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4589 or die_error
(404, "Error looking up file");
4591 $ftype = git_get_type
($hash);
4592 if ($ftype !~ "blob") {
4593 die_error
(400, "Object is not a blob");
4595 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4596 $file_name, $hash_base)
4597 or die_error
(500, "Open git-blame failed");
4600 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4603 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4606 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4608 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4609 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4610 git_print_page_path
($file_name, $ftype, $hash_base);
4611 my @rev_color = (qw(light2 dark2));
4612 my $num_colors = scalar(@rev_color);
4613 my $current_color = 0;
4616 <div class="page_body">
4617 <table class="blame">
4618 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4623 last unless defined $_;
4624 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4625 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4626 if (!exists $metainfo{$full_rev}) {
4627 $metainfo{$full_rev} = {};
4629 my $meta = $metainfo{$full_rev};
4632 if (/^(\S+) (.*)$/) {
4638 my $rev = substr($full_rev, 0, 8);
4639 my $author = $meta->{'author'};
4640 my %date = parse_date
($meta->{'author-time'},
4641 $meta->{'author-tz'});
4642 my $date = $date{'iso-tz'};
4644 $current_color = ++$current_color % $num_colors;
4646 print "<tr class=\"$rev_color[$current_color]\">\n";
4648 print "<td class=\"sha1\"";
4649 print " title=\"". esc_html
($author) . ", $date\"";
4650 print " rowspan=\"$group_size\"" if ($group_size > 1);
4652 print $cgi->a({-href
=> href
(action
=>"commit",
4654 file_name
=>$file_name)},
4658 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4659 or die_error
(500, "Open git-rev-parse failed");
4660 my $parent_commit = <$dd>;
4662 chomp($parent_commit);
4663 my $blamed = href
(action
=> 'blame',
4664 file_name
=> $meta->{'filename'},
4665 hash_base
=> $parent_commit);
4666 print "<td class=\"linenr\">";
4667 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4669 -class => "linenr" },
4672 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4678 or print "Reading blob failed\n";
4683 my $head = git_get_head_hash
($project);
4685 git_print_page_nav
('','', $head,undef,$head);
4686 git_print_header_div
('summary', $project);
4688 my @tagslist = git_get_tags_list
();
4690 git_tags_body
(\
@tagslist);
4696 my $head = git_get_head_hash
($project);
4698 git_print_page_nav
('','', $head,undef,$head);
4699 git_print_header_div
('summary', $project);
4701 my @headslist = git_get_heads_list
();
4703 git_heads_body
(\
@headslist, $head);
4708 sub git_blob_plain
{
4712 if (!defined $hash) {
4713 if (defined $file_name) {
4714 my $base = $hash_base || git_get_head_hash
($project);
4715 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4716 or die_error
(404, "Cannot find file");
4718 die_error
(400, "No file name defined");
4720 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4721 # blobs defined by non-textual hash id's can be cached
4725 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4726 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4728 # content-type (can include charset)
4729 $type = blob_contenttype
($fd, $file_name, $type);
4731 # "save as" filename, even when no $file_name is given
4732 my $save_as = "$hash";
4733 if (defined $file_name) {
4734 $save_as = $file_name;
4735 } elsif ($type =~ m/^text\//) {
4741 -expires
=> $expires,
4742 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4744 binmode STDOUT
, ':raw';
4746 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4754 if (!defined $hash) {
4755 if (defined $file_name) {
4756 my $base = $hash_base || git_get_head_hash
($project);
4757 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4758 or die_error
(404, "Cannot find file");
4760 die_error
(400, "No file name defined");
4762 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4763 # blobs defined by non-textual hash id's can be cached
4767 my $have_blame = gitweb_check_feature
('blame');
4768 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4769 or die_error
(500, "Couldn't cat $file_name, $hash");
4770 my $mimetype = blob_mimetype
($fd, $file_name);
4771 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4773 return git_blob_plain
($mimetype);
4775 # we can have blame only for text/* mimetype
4776 $have_blame &&= ($mimetype =~ m!^text/!);
4778 git_header_html
(undef, $expires);
4779 my $formats_nav = '';
4780 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4781 if (defined $file_name) {
4784 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4789 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4792 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4795 $cgi->a({-href
=> href
(action
=>"blob",
4796 hash_base
=>"HEAD", file_name
=>$file_name)},
4800 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4803 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4804 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4806 print "<div class=\"page_nav\">\n" .
4807 "<br/><br/></div>\n" .
4808 "<div class=\"title\">$hash</div>\n";
4810 git_print_page_path
($file_name, "blob", $hash_base);
4811 print "<div class=\"page_body\">\n";
4812 if ($mimetype =~ m!^image/!) {
4813 print qq
!<img type
="$mimetype"!;
4815 print qq
! alt
="$file_name" title
="$file_name"!;
4818 href(action=>"blob_plain
", hash=>$hash,
4819 hash_base=>$hash_base, file_name=>$file_name) .
4823 while (my $line = <$fd>) {
4826 $line = untabify
($line);
4827 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4828 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4832 or print "Reading blob failed.\n";
4838 if (!defined $hash_base) {
4839 $hash_base = "HEAD";
4841 if (!defined $hash) {
4842 if (defined $file_name) {
4843 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4848 die_error
(404, "No such tree") unless defined($hash);
4850 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4851 or die_error
(500, "Open git-ls-tree failed");
4852 my @entries = map { chomp; $_ } <$fd>;
4853 close $fd or die_error
(404, "Reading tree failed");
4856 my $refs = git_get_references
();
4857 my $ref = format_ref_marker
($refs, $hash_base);
4860 my $have_blame = gitweb_check_feature
('blame');
4861 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4863 if (defined $file_name) {
4865 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4867 $cgi->a({-href
=> href
(action
=>"tree",
4868 hash_base
=>"HEAD", file_name
=>$file_name)},
4871 my $snapshot_links = format_snapshot_links
($hash);
4872 if (defined $snapshot_links) {
4873 # FIXME: Should be available when we have no hash base as well.
4874 push @views_nav, $snapshot_links;
4876 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4877 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4880 print "<div class=\"page_nav\">\n";
4881 print "<br/><br/></div>\n";
4882 print "<div class=\"title\">$hash</div>\n";
4884 if (defined $file_name) {
4885 $basedir = $file_name;
4886 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4889 git_print_page_path
($file_name, 'tree', $hash_base);
4891 print "<div class=\"page_body\">\n";
4892 print "<table class=\"tree\">\n";
4894 # '..' (top directory) link if possible
4895 if (defined $hash_base &&
4896 defined $file_name && $file_name =~ m![^/]+$!) {
4898 print "<tr class=\"dark\">\n";
4900 print "<tr class=\"light\">\n";
4904 my $up = $file_name;
4905 $up =~ s!/?[^/]+$!!;
4906 undef $up unless $up;
4907 # based on git_print_tree_entry
4908 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4909 print '<td class="list">';
4910 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4914 print "<td class=\"link\"></td>\n";
4918 foreach my $line (@entries) {
4919 my %t = parse_ls_tree_line
($line, -z
=> 1);
4922 print "<tr class=\"dark\">\n";
4924 print "<tr class=\"light\">\n";
4928 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4932 print "</table>\n" .
4938 my $format = $input_params{'snapshot_format'};
4939 if (!@snapshot_fmts) {
4940 die_error
(403, "Snapshots not allowed");
4942 # default to first supported snapshot format
4943 $format ||= $snapshot_fmts[0];
4944 if ($format !~ m/^[a-z0-9]+$/) {
4945 die_error
(400, "Invalid snapshot format parameter");
4946 } elsif (!exists($known_snapshot_formats{$format})) {
4947 die_error
(400, "Unknown snapshot format");
4948 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4949 die_error
(403, "Unsupported snapshot format");
4952 if (!defined $hash) {
4953 $hash = git_get_head_hash
($project);
4956 my $name = $project;
4957 $name =~ s
,([^/])/*\
.git
$,$1,;
4958 $name = basename
($name);
4959 my $filename = to_utf8
($name);
4960 $name =~ s/\047/\047\\\047\047/g;
4962 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4963 $cmd = quote_command
(
4964 git_cmd
(), 'archive',
4965 "--format=$known_snapshot_formats{$format}{'format'}",
4966 "--prefix=$name/", $hash);
4967 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4968 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4972 -type
=> $known_snapshot_formats{$format}{'type'},
4973 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4974 -status
=> '200 OK');
4976 open my $fd, "-|", $cmd
4977 or die_error
(500, "Execute git-archive failed");
4978 binmode STDOUT
, ':raw';
4980 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4985 my $head = git_get_head_hash
($project);
4986 if (!defined $hash) {
4989 if (!defined $page) {
4992 my $refs = git_get_references
();
4994 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4996 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4999 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5002 my %co = parse_commit
($hash);
5004 git_print_header_div
('summary', $project);
5005 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5007 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5008 for (my $i = 0; $i <= $to; $i++) {
5009 my %co = %{$commitlist[$i]};
5011 my $commit = $co{'id'};
5012 my $ref = format_ref_marker
($refs, $commit);
5013 my %ad = parse_date
($co{'author_epoch'});
5014 git_print_header_div
('commit',
5015 "<span class=\"age\">$co{'age_string'}</span>" .
5016 esc_html
($co{'title'}) . $ref,
5018 print "<div class=\"title_text\">\n" .
5019 "<div class=\"log_link\">\n" .
5020 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5022 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5024 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5027 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5030 print "<div class=\"log_body\">\n";
5031 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5034 if ($#commitlist >= 100) {
5035 print "<div class=\"page_nav\">\n";
5036 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5037 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5044 $hash ||= $hash_base || "HEAD";
5045 my %co = parse_commit
($hash)
5046 or die_error
(404, "Unknown commit object");
5047 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5048 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5050 my $parent = $co{'parent'};
5051 my $parents = $co{'parents'}; # listref
5053 # we need to prepare $formats_nav before any parameter munging
5055 if (!defined $parent) {
5057 $formats_nav .= '(initial)';
5058 } elsif (@$parents == 1) {
5059 # single parent commit
5062 $cgi->a({-href
=> href
(action
=>"commit",
5064 esc_html
(substr($parent, 0, 7))) .
5071 $cgi->a({-href
=> href
(action
=>"commit",
5073 esc_html
(substr($_, 0, 7)));
5078 if (!defined $parent) {
5082 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5084 (@$parents <= 1 ? $parent : '-c'),
5086 or die_error
(500, "Open git-diff-tree failed");
5087 @difftree = map { chomp; $_ } <$fd>;
5088 close $fd or die_error
(404, "Reading git-diff-tree failed");
5090 # non-textual hash id's can be cached
5092 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5095 my $refs = git_get_references
();
5096 my $ref = format_ref_marker
($refs, $co{'id'});
5098 git_header_html
(undef, $expires);
5099 git_print_page_nav
('commit', '',
5100 $hash, $co{'tree'}, $hash,
5103 if (defined $co{'parent'}) {
5104 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5106 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5108 print "<div class=\"title_text\">\n" .
5109 "<table class=\"object_header\">\n";
5110 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5112 "<td></td><td> $ad{'rfc2822'}";
5113 if ($ad{'hour_local'} < 6) {
5114 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5115 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5117 printf(" (%02d:%02d %s)",
5118 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5122 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5123 print "<tr><td></td><td> $cd{'rfc2822'}" .
5124 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5126 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5129 "<td class=\"sha1\">" .
5130 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5131 class => "list"}, $co{'tree'}) .
5133 "<td class=\"link\">" .
5134 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5136 my $snapshot_links = format_snapshot_links
($hash);
5137 if (defined $snapshot_links) {
5138 print " | " . $snapshot_links;
5143 foreach my $par (@$parents) {
5146 "<td class=\"sha1\">" .
5147 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5148 class => "list"}, $par) .
5150 "<td class=\"link\">" .
5151 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5153 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5160 print "<div class=\"page_body\">\n";
5161 git_print_log
($co{'comment'});
5164 git_difftree_body
(\
@difftree, $hash, @$parents);
5170 # object is defined by:
5171 # - hash or hash_base alone
5172 # - hash_base and file_name
5175 # - hash or hash_base alone
5176 if ($hash || ($hash_base && !defined $file_name)) {
5177 my $object_id = $hash || $hash_base;
5179 open my $fd, "-|", quote_command
(
5180 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5181 or die_error
(404, "Object does not exist");
5185 or die_error
(404, "Object does not exist");
5187 # - hash_base and file_name
5188 } elsif ($hash_base && defined $file_name) {
5189 $file_name =~ s
,/+$,,;
5191 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5192 or die_error
(404, "Base object does not exist");
5194 # here errors should not hapen
5195 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5196 or die_error
(500, "Open git-ls-tree failed");
5200 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5201 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5202 die_error
(404, "File or directory for given base does not exist");
5207 die_error
(400, "Not enough information to find object");
5210 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5211 hash
=>$hash, hash_base
=>$hash_base,
5212 file_name
=>$file_name),
5213 -status
=> '302 Found');
5217 my $format = shift || 'html';
5224 # preparing $fd and %diffinfo for git_patchset_body
5226 if (defined $hash_base && defined $hash_parent_base) {
5227 if (defined $file_name) {
5229 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5230 $hash_parent_base, $hash_base,
5231 "--", (defined $file_parent ? $file_parent : ()), $file_name
5232 or die_error
(500, "Open git-diff-tree failed");
5233 @difftree = map { chomp; $_ } <$fd>;
5235 or die_error
(404, "Reading git-diff-tree failed");
5237 or die_error
(404, "Blob diff not found");
5239 } elsif (defined $hash &&
5240 $hash =~ /[0-9a-fA-F]{40}/) {
5241 # try to find filename from $hash
5243 # read filtered raw output
5244 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5245 $hash_parent_base, $hash_base, "--"
5246 or die_error
(500, "Open git-diff-tree failed");
5248 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5250 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5251 map { chomp; $_ } <$fd>;
5253 or die_error
(404, "Reading git-diff-tree failed");
5255 or die_error
(404, "Blob diff not found");
5258 die_error
(400, "Missing one of the blob diff parameters");
5261 if (@difftree > 1) {
5262 die_error
(400, "Ambiguous blob diff specification");
5265 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5266 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5267 $file_name ||= $diffinfo{'to_file'};
5269 $hash_parent ||= $diffinfo{'from_id'};
5270 $hash ||= $diffinfo{'to_id'};
5272 # non-textual hash id's can be cached
5273 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5274 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5279 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5280 '-p', ($format eq 'html' ? "--full-index" : ()),
5281 $hash_parent_base, $hash_base,
5282 "--", (defined $file_parent ? $file_parent : ()), $file_name
5283 or die_error
(500, "Open git-diff-tree failed");
5286 # old/legacy style URI
5287 if (!%diffinfo && # if new style URI failed
5288 defined $hash && defined $hash_parent) {
5289 # fake git-diff-tree raw output
5290 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5291 $diffinfo{'from_id'} = $hash_parent;
5292 $diffinfo{'to_id'} = $hash;
5293 if (defined $file_name) {
5294 if (defined $file_parent) {
5295 $diffinfo{'status'} = '2';
5296 $diffinfo{'from_file'} = $file_parent;
5297 $diffinfo{'to_file'} = $file_name;
5298 } else { # assume not renamed
5299 $diffinfo{'status'} = '1';
5300 $diffinfo{'from_file'} = $file_name;
5301 $diffinfo{'to_file'} = $file_name;
5303 } else { # no filename given
5304 $diffinfo{'status'} = '2';
5305 $diffinfo{'from_file'} = $hash_parent;
5306 $diffinfo{'to_file'} = $hash;
5309 # non-textual hash id's can be cached
5310 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5311 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5316 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5317 '-p', ($format eq 'html' ? "--full-index" : ()),
5318 $hash_parent, $hash, "--"
5319 or die_error
(500, "Open git-diff failed");
5321 die_error
(400, "Missing one of the blob diff parameters")
5326 if ($format eq 'html') {
5328 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5330 git_header_html
(undef, $expires);
5331 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5332 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5333 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5335 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5336 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5338 if (defined $file_name) {
5339 git_print_page_path
($file_name, "blob", $hash_base);
5341 print "<div class=\"page_path\"></div>\n";
5344 } elsif ($format eq 'plain') {
5346 -type
=> 'text/plain',
5347 -charset
=> 'utf-8',
5348 -expires
=> $expires,
5349 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5351 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5354 die_error
(400, "Unknown blobdiff format");
5358 if ($format eq 'html') {
5359 print "<div class=\"page_body\">\n";
5361 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5364 print "</div>\n"; # class="page_body"
5368 while (my $line = <$fd>) {
5369 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5370 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5374 last if $line =~ m!^\+\+\+!;
5382 sub git_blobdiff_plain
{
5383 git_blobdiff
('plain');
5386 sub git_commitdiff
{
5387 my $format = shift || 'html';
5388 $hash ||= $hash_base || "HEAD";
5389 my %co = parse_commit
($hash)
5390 or die_error
(404, "Unknown commit object");
5392 # choose format for commitdiff for merge
5393 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5394 $hash_parent = '--cc';
5396 # we need to prepare $formats_nav before almost any parameter munging
5398 if ($format eq 'html') {
5400 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5403 if (defined $hash_parent &&
5404 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5405 # commitdiff with two commits given
5406 my $hash_parent_short = $hash_parent;
5407 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5408 $hash_parent_short = substr($hash_parent, 0, 7);
5412 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5413 if ($co{'parents'}[$i] eq $hash_parent) {
5414 $formats_nav .= ' parent ' . ($i+1);
5418 $formats_nav .= ': ' .
5419 $cgi->a({-href
=> href
(action
=>"commitdiff",
5420 hash
=>$hash_parent)},
5421 esc_html
($hash_parent_short)) .
5423 } elsif (!$co{'parent'}) {
5425 $formats_nav .= ' (initial)';
5426 } elsif (scalar @{$co{'parents'}} == 1) {
5427 # single parent commit
5430 $cgi->a({-href
=> href
(action
=>"commitdiff",
5431 hash
=>$co{'parent'})},
5432 esc_html
(substr($co{'parent'}, 0, 7))) .
5436 if ($hash_parent eq '--cc') {
5437 $formats_nav .= ' | ' .
5438 $cgi->a({-href
=> href
(action
=>"commitdiff",
5439 hash
=>$hash, hash_parent
=>'-c')},
5441 } else { # $hash_parent eq '-c'
5442 $formats_nav .= ' | ' .
5443 $cgi->a({-href
=> href
(action
=>"commitdiff",
5444 hash
=>$hash, hash_parent
=>'--cc')},
5450 $cgi->a({-href
=> href
(action
=>"commitdiff",
5452 esc_html
(substr($_, 0, 7)));
5453 } @{$co{'parents'}} ) .
5458 my $hash_parent_param = $hash_parent;
5459 if (!defined $hash_parent_param) {
5460 # --cc for multiple parents, --root for parentless
5461 $hash_parent_param =
5462 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5468 if ($format eq 'html') {
5469 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5470 "--no-commit-id", "--patch-with-raw", "--full-index",
5471 $hash_parent_param, $hash, "--"
5472 or die_error
(500, "Open git-diff-tree failed");
5474 while (my $line = <$fd>) {
5476 # empty line ends raw part of diff-tree output
5478 push @difftree, scalar parse_difftree_raw_line
($line);
5481 } elsif ($format eq 'plain') {
5482 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5483 '-p', $hash_parent_param, $hash, "--"
5484 or die_error
(500, "Open git-diff-tree failed");
5487 die_error
(400, "Unknown commitdiff format");
5490 # non-textual hash id's can be cached
5492 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5496 # write commit message
5497 if ($format eq 'html') {
5498 my $refs = git_get_references
();
5499 my $ref = format_ref_marker
($refs, $co{'id'});
5501 git_header_html
(undef, $expires);
5502 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5503 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5504 git_print_authorship
(\
%co);
5505 print "<div class=\"page_body\">\n";
5506 if (@{$co{'comment'}} > 1) {
5507 print "<div class=\"log\">\n";
5508 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5509 print "</div>\n"; # class="log"
5512 } elsif ($format eq 'plain') {
5513 my $refs = git_get_references
("tags");
5514 my $tagname = git_get_rev_name_tags
($hash);
5515 my $filename = basename
($project) . "-$hash.patch";
5518 -type
=> 'text/plain',
5519 -charset
=> 'utf-8',
5520 -expires
=> $expires,
5521 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5522 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5523 print "From: " . to_utf8
($co{'author'}) . "\n";
5524 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5525 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5527 print "X-Git-Tag: $tagname\n" if $tagname;
5528 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5530 foreach my $line (@{$co{'comment'}}) {
5531 print to_utf8
($line) . "\n";
5537 if ($format eq 'html') {
5538 my $use_parents = !defined $hash_parent ||
5539 $hash_parent eq '-c' || $hash_parent eq '--cc';
5540 git_difftree_body
(\
@difftree, $hash,
5541 $use_parents ? @{$co{'parents'}} : $hash_parent);
5544 git_patchset_body
($fd, \
@difftree, $hash,
5545 $use_parents ? @{$co{'parents'}} : $hash_parent);
5547 print "</div>\n"; # class="page_body"
5550 } elsif ($format eq 'plain') {
5554 or print "Reading git-diff-tree failed\n";
5558 sub git_commitdiff_plain
{
5559 git_commitdiff
('plain');
5563 if (!defined $hash_base) {
5564 $hash_base = git_get_head_hash
($project);
5566 if (!defined $page) {
5570 my %co = parse_commit
($hash_base)
5571 or die_error
(404, "Unknown commit object");
5573 my $refs = git_get_references
();
5574 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5576 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5577 $file_name, "--full-history")
5578 or die_error
(404, "No such file or directory on given branch");
5580 if (!defined $hash && defined $file_name) {
5581 # some commits could have deleted file in question,
5582 # and not have it in tree, but one of them has to have it
5583 for (my $i = 0; $i <= @commitlist; $i++) {
5584 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5585 last if defined $hash;
5588 if (defined $hash) {
5589 $ftype = git_get_type
($hash);
5591 if (!defined $ftype) {
5592 die_error
(500, "Unknown type of object");
5595 my $paging_nav = '';
5598 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5599 file_name
=>$file_name)},
5601 $paging_nav .= " ⋅ " .
5602 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5603 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5605 $paging_nav .= "first";
5606 $paging_nav .= " ⋅ prev";
5609 if ($#commitlist >= 100) {
5611 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5612 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5613 $paging_nav .= " ⋅ $next_link";
5615 $paging_nav .= " ⋅ next";
5619 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5620 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5621 git_print_page_path
($file_name, $ftype, $hash_base);
5623 git_history_body
(\
@commitlist, 0, 99,
5624 $refs, $hash_base, $ftype, $next_link);
5630 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5631 if (!defined $searchtext) {
5632 die_error
(400, "Text field is empty");
5634 if (!defined $hash) {
5635 $hash = git_get_head_hash
($project);
5637 my %co = parse_commit
($hash);
5639 die_error
(404, "Unknown commit object");
5641 if (!defined $page) {
5645 $searchtype ||= 'commit';
5646 if ($searchtype eq 'pickaxe') {
5647 # pickaxe may take all resources of your box and run for several minutes
5648 # with every query - so decide by yourself how public you make this feature
5649 gitweb_check_feature
('pickaxe')
5650 or die_error
(403, "Pickaxe is disabled");
5652 if ($searchtype eq 'grep') {
5653 gitweb_check_feature
('grep')[0]
5654 or die_error
(403, "Grep is disabled");
5659 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5661 if ($searchtype eq 'commit') {
5662 $greptype = "--grep=";
5663 } elsif ($searchtype eq 'author') {
5664 $greptype = "--author=";
5665 } elsif ($searchtype eq 'committer') {
5666 $greptype = "--committer=";
5668 $greptype .= $searchtext;
5669 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5670 $greptype, '--regexp-ignore-case',
5671 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5673 my $paging_nav = '';
5676 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5677 searchtext
=>$searchtext,
5678 searchtype
=>$searchtype)},
5680 $paging_nav .= " ⋅ " .
5681 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5682 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5684 $paging_nav .= "first";
5685 $paging_nav .= " ⋅ prev";
5688 if ($#commitlist >= 100) {
5690 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5691 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5692 $paging_nav .= " ⋅ $next_link";
5694 $paging_nav .= " ⋅ next";
5697 if ($#commitlist >= 100) {
5700 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5701 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5702 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5705 if ($searchtype eq 'pickaxe') {
5706 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5707 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5709 print "<table class=\"pickaxe search\">\n";
5712 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5713 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5714 ($search_use_regexp ? '--pickaxe-regex' : ());
5717 while (my $line = <$fd>) {
5721 my %set = parse_difftree_raw_line
($line);
5722 if (defined $set{'commit'}) {
5723 # finish previous commit
5726 "<td class=\"link\">" .
5727 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5729 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5735 print "<tr class=\"dark\">\n";
5737 print "<tr class=\"light\">\n";
5740 %co = parse_commit
($set{'commit'});
5741 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5742 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5743 "<td><i>$author</i></td>\n" .
5745 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5746 -class => "list subject"},
5747 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5748 } elsif (defined $set{'to_id'}) {
5749 next if ($set{'to_id'} =~ m/^0{40}$/);
5751 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5752 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5754 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5760 # finish last commit (warning: repetition!)
5763 "<td class=\"link\">" .
5764 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5766 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5774 if ($searchtype eq 'grep') {
5775 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5776 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5778 print "<table class=\"grep_search\">\n";
5782 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5783 $search_use_regexp ? ('-E', '-i') : '-F',
5784 $searchtext, $co{'tree'};
5786 while (my $line = <$fd>) {
5788 my ($file, $lno, $ltext, $binary);
5789 last if ($matches++ > 1000);
5790 if ($line =~ /^Binary file (.+) matches$/) {
5794 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5796 if ($file ne $lastfile) {
5797 $lastfile and print "</td></tr>\n";
5799 print "<tr class=\"dark\">\n";
5801 print "<tr class=\"light\">\n";
5803 print "<td class=\"list\">".
5804 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5805 file_name
=>"$file"),
5806 -class => "list"}, esc_path
($file));
5807 print "</td><td>\n";
5811 print "<div class=\"binary\">Binary file</div>\n";
5813 $ltext = untabify
($ltext);
5814 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5815 $ltext = esc_html
($1, -nbsp
=>1);
5816 $ltext .= '<span class="match">';
5817 $ltext .= esc_html
($2, -nbsp
=>1);
5818 $ltext .= '</span>';
5819 $ltext .= esc_html
($3, -nbsp
=>1);
5821 $ltext = esc_html
($ltext, -nbsp
=>1);
5823 print "<div class=\"pre\">" .
5824 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5825 file_name
=>"$file").'#l'.$lno,
5826 -class => "linenr"}, sprintf('%4i', $lno))
5827 . ' ' . $ltext . "</div>\n";
5831 print "</td></tr>\n";
5832 if ($matches > 1000) {
5833 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5836 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5845 sub git_search_help
{
5847 git_print_page_nav
('','', $hash,$hash,$hash);
5849 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5850 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5851 the pattern entered is recognized as the POSIX extended
5852 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5855 <dt><b>commit</b></dt>
5856 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5858 my $have_grep = gitweb_check_feature
('grep');
5861 <dt><b>grep</b></dt>
5862 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5863 a different one) are searched for the given pattern. On large trees, this search can take
5864 a while and put some strain on the server, so please use it with some consideration. Note that
5865 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5866 case-sensitive.</dd>
5870 <dt><b>author</b></dt>
5871 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5872 <dt><b>committer</b></dt>
5873 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5875 my $have_pickaxe = gitweb_check_feature
('pickaxe');
5876 if ($have_pickaxe) {
5878 <dt><b>pickaxe</b></dt>
5879 <dd>All commits that caused the string to appear or disappear from any file (changes that
5880 added, removed or "modified" the string) will be listed. This search can take a while and
5881 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5882 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5890 my $head = git_get_head_hash
($project);
5891 if (!defined $hash) {
5894 if (!defined $page) {
5897 my $refs = git_get_references
();
5899 my $commit_hash = $hash;
5900 if (defined $hash_parent) {
5901 $commit_hash = "$hash_parent..$hash";
5903 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5905 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5907 if ($#commitlist >= 100) {
5909 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5910 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5914 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5915 git_print_header_div
('summary', $project);
5917 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5922 ## ......................................................................
5923 ## feeds (RSS, Atom; OPML)
5926 my $format = shift || 'atom';
5927 my $have_blame = gitweb_check_feature
('blame');
5929 # Atom: http://www.atomenabled.org/developers/syndication/
5930 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5931 if ($format ne 'rss' && $format ne 'atom') {
5932 die_error
(400, "Unknown web feed format");
5935 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5936 my $head = $hash || 'HEAD';
5937 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5941 my $content_type = "application/$format+xml";
5942 if (defined $cgi->http('HTTP_ACCEPT') &&
5943 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5944 # browser (feed reader) prefers text/xml
5945 $content_type = 'text/xml';
5947 if (defined($commitlist[0])) {
5948 %latest_commit = %{$commitlist[0]};
5949 %latest_date = parse_date
($latest_commit{'author_epoch'});
5951 -type
=> $content_type,
5952 -charset
=> 'utf-8',
5953 -last_modified
=> $latest_date{'rfc2822'});
5956 -type
=> $content_type,
5957 -charset
=> 'utf-8');
5960 # Optimization: skip generating the body if client asks only
5961 # for Last-Modified date.
5962 return if ($cgi->request_method() eq 'HEAD');
5965 my $title = "$site_name - $project/$action";
5966 my $feed_type = 'log';
5967 if (defined $hash) {
5968 $title .= " - '$hash'";
5969 $feed_type = 'branch log';
5970 if (defined $file_name) {
5971 $title .= " :: $file_name";
5972 $feed_type = 'history';
5974 } elsif (defined $file_name) {
5975 $title .= " - $file_name";
5976 $feed_type = 'history';
5978 $title .= " $feed_type";
5979 my $descr = git_get_project_description
($project);
5980 if (defined $descr) {
5981 $descr = esc_html
($descr);
5983 $descr = "$project " .
5984 ($format eq 'rss' ? 'RSS' : 'Atom') .
5987 my $owner = git_get_project_owner
($project);
5988 $owner = esc_html
($owner);
5992 if (defined $file_name) {
5993 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5994 } elsif (defined $hash) {
5995 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5997 $alt_url = href
(-full
=>1, action
=>"summary");
5999 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6000 if ($format eq 'rss') {
6002 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6005 print "<title>$title</title>\n" .
6006 "<link>$alt_url</link>\n" .
6007 "<description>$descr</description>\n" .
6008 "<language>en</language>\n";
6009 } elsif ($format eq 'atom') {
6011 <feed xmlns="http://www.w3.org/2005/Atom">
6013 print "<title>$title</title>\n" .
6014 "<subtitle>$descr</subtitle>\n" .
6015 '<link rel="alternate" type="text/html" href="' .
6016 $alt_url . '" />' . "\n" .
6017 '<link rel="self" type="' . $content_type . '" href="' .
6018 $cgi->self_url() . '" />' . "\n" .
6019 "<id>" . href
(-full
=>1) . "</id>\n" .
6020 # use project owner for feed author
6021 "<author><name>$owner</name></author>\n";
6022 if (defined $favicon) {
6023 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6025 if (defined $logo_url) {
6026 # not twice as wide as tall: 72 x 27 pixels
6027 print "<logo>" . esc_url
($logo) . "</logo>\n";
6029 if (! %latest_date) {
6030 # dummy date to keep the feed valid until commits trickle in:
6031 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6033 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6038 for (my $i = 0; $i <= $#commitlist; $i++) {
6039 my %co = %{$commitlist[$i]};
6040 my $commit = $co{'id'};
6041 # we read 150, we always show 30 and the ones more recent than 48 hours
6042 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6045 my %cd = parse_date
($co{'author_epoch'});
6047 # get list of changed files
6048 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6049 $co{'parent'} || "--root",
6050 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6052 my @difftree = map { chomp; $_ } <$fd>;
6056 # print element (entry, item)
6057 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6058 if ($format eq 'rss') {
6060 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6061 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6062 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6063 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6064 "<link>$co_url</link>\n" .
6065 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6066 "<content:encoded>" .
6068 } elsif ($format eq 'atom') {
6070 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6071 "<updated>$cd{'iso-8601'}</updated>\n" .
6073 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6074 if ($co{'author_email'}) {
6075 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6077 print "</author>\n" .
6078 # use committer for contributor
6080 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6081 if ($co{'committer_email'}) {
6082 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6084 print "</contributor>\n" .
6085 "<published>$cd{'iso-8601'}</published>\n" .
6086 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6087 "<id>$co_url</id>\n" .
6088 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6089 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6091 my $comment = $co{'comment'};
6093 foreach my $line (@$comment) {
6094 $line = esc_html
($line);
6097 print "</pre><ul>\n";
6098 foreach my $difftree_line (@difftree) {
6099 my %difftree = parse_difftree_raw_line
($difftree_line);
6100 next if !$difftree{'from_id'};
6102 my $file = $difftree{'file'} || $difftree{'to_file'};
6106 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6107 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6108 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6109 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6110 -title
=> "diff"}, 'D');
6112 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6113 file_name
=>$file, hash_base
=>$commit),
6114 -title
=> "blame"}, 'B');
6116 # if this is not a feed of a file history
6117 if (!defined $file_name || $file_name ne $file) {
6118 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6119 file_name
=>$file, hash
=>$commit),
6120 -title
=> "history"}, 'H');
6122 $file = esc_path
($file);
6126 if ($format eq 'rss') {
6127 print "</ul>]]>\n" .
6128 "</content:encoded>\n" .
6130 } elsif ($format eq 'atom') {
6131 print "</ul>\n</div>\n" .
6138 if ($format eq 'rss') {
6139 print "</channel>\n</rss>\n";
6140 } elsif ($format eq 'atom') {
6154 my @list = git_get_projects_list
();
6156 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6158 <?xml version="1.0" encoding="utf-8"?>
6159 <opml version="1.0">
6161 <title>$site_name OPML Export</title>
6164 <outline text="git RSS feeds">
6167 foreach my $pr (@list) {
6169 my $head = git_get_head_hash
($proj{'path'});
6170 if (!defined $head) {
6173 $git_dir = "$projectroot/$proj{'path'}";
6174 my %co = parse_commit
($head);
6179 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6180 my $rss = "$my_url?p=$proj{'path'};a=rss";
6181 my $html = "$my_url?p=$proj{'path'};a=summary";
6182 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";