3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # if we're called with PATH_INFO, we have to strip that
31 # from the URL to find our real URL
32 # we make $path_info global because it's also used later on
33 our $path_info = $ENV{"PATH_INFO"};
35 $my_url =~ s
,\Q
$path_info\E
$,,;
36 $my_uri =~ s
,\Q
$path_info\E
$,,;
39 # core git executable to use
40 # this can just be "git" if your webserver has a sensible PATH
41 our $GIT = "++GIT_BINDIR++/git";
43 # absolute fs-path which will be prepended to the project path
44 #our $projectroot = "/pub/scm";
45 our $projectroot = "++GITWEB_PROJECTROOT++";
47 # fs traversing limit for getting project list
48 # the number is relative to the projectroot
49 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
51 # target of the home link on top of all pages
52 our $home_link = $my_uri || "/";
54 # string of the home link on top of all pages
55 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
57 # name of your site or organization to appear in page titles
58 # replace this with something more descriptive for clearer bookmarks
59 our $site_name = "++GITWEB_SITENAME++"
60 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
62 # filename of html text to include at top of each page
63 our $site_header = "++GITWEB_SITE_HEADER++";
64 # html text to include at home page
65 our $home_text = "++GITWEB_HOMETEXT++";
66 # filename of html text to include at bottom of each page
67 our $site_footer = "++GITWEB_SITE_FOOTER++";
70 our @stylesheets = ("++GITWEB_CSS++");
71 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
72 our $stylesheet = undef;
73 # URI of GIT logo (72x27 size)
74 our $logo = "++GITWEB_LOGO++";
75 # URI of GIT favicon, assumed to be image/png type
76 our $favicon = "++GITWEB_FAVICON++";
78 # URI and label (title) of GIT logo link
79 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
80 #our $logo_label = "git documentation";
81 our $logo_url = "http://git.or.cz/";
82 our $logo_label = "git homepage";
84 # source of projects list
85 our $projects_list = "++GITWEB_LIST++";
87 # the width (in characters) of the projects list "Description" column
88 our $projects_list_description_width = 25;
90 # default order of projects list
91 # valid values are none, project, descr, owner, and age
92 our $default_projects_order = "project";
94 # show repository only if this file exists
95 # (only effective if this variable evaluates to true)
96 our $export_ok = "++GITWEB_EXPORT_OK++";
98 # show repository only if this subroutine returns true
99 # when given the path to the project, for example:
100 # sub { return -e "$_[0]/git-daemon-export-ok"; }
101 our $export_auth_hook = undef;
103 # only allow viewing of repositories also shown on the overview page
104 our $strict_export = "++GITWEB_STRICT_EXPORT++";
106 # list of git base URLs used for URL to where fetch project from,
107 # i.e. full URL is "$git_base_url/$project"
108 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
110 # default blob_plain mimetype and default charset for text/plain blob
111 our $default_blob_plain_mimetype = 'text/plain';
112 our $default_text_plain_charset = undef;
114 # file to use for guessing MIME types before trying /etc/mime.types
115 # (relative to the current git repository)
116 our $mimetypes_file = undef;
118 # assume this charset if line contains non-UTF-8 characters;
119 # it should be valid encoding (see Encoding::Supported(3pm) for list),
120 # for which encoding all byte sequences are valid, for example
121 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
122 # could be even 'utf-8' for the old behavior)
123 our $fallback_encoding = 'latin1';
125 # rename detection options for git-diff and git-diff-tree
126 # - default is '-M', with the cost proportional to
127 # (number of removed files) * (number of new files).
128 # - more costly is '-C' (which implies '-M'), with the cost proportional to
129 # (number of changed files + number of removed files) * (number of new files)
130 # - even more costly is '-C', '--find-copies-harder' with cost
131 # (number of files in the original tree) * (number of new files)
132 # - one might want to include '-B' option, e.g. '-B', '-M'
133 our @diff_opts = ('-M'); # taken from git_commit
135 # information about snapshot formats that gitweb is capable of serving
136 our %known_snapshot_formats = (
138 # 'display' => display name,
139 # 'type' => mime type,
140 # 'suffix' => filename suffix,
141 # 'format' => --format for git-archive,
142 # 'compressor' => [compressor command and arguments]
143 # (array reference, optional)}
146 'display' => 'tar.gz',
147 'type' => 'application/x-gzip',
148 'suffix' => '.tar.gz',
150 'compressor' => ['gzip']},
153 'display' => 'tar.bz2',
154 'type' => 'application/x-bzip2',
155 'suffix' => '.tar.bz2',
157 'compressor' => ['bzip2']},
161 'type' => 'application/x-zip',
166 # Aliases so we understand old gitweb.snapshot values in repository
168 our %known_snapshot_format_aliases = (
172 # backward compatibility: legacy gitweb config support
173 'x-gzip' => undef, 'gz' => undef,
174 'x-bzip2' => undef, 'bz2' => undef,
175 'x-zip' => undef, '' => undef,
178 # You define site-wide feature defaults here; override them with
179 # $GITWEB_CONFIG as necessary.
182 # 'sub' => feature-sub (subroutine),
183 # 'override' => allow-override (boolean),
184 # 'default' => [ default options...] (array reference)}
186 # if feature is overridable (it means that allow-override has true value),
187 # then feature-sub will be called with default options as parameters;
188 # return value of feature-sub indicates if to enable specified feature
190 # if there is no 'sub' key (no feature-sub), then feature cannot be
193 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
194 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
197 # Enable the 'blame' blob view, showing the last commit that modified
198 # each line in the file. This can be very CPU-intensive.
200 # To enable system wide have in $GITWEB_CONFIG
201 # $feature{'blame'}{'default'} = [1];
202 # To have project specific config enable override in $GITWEB_CONFIG
203 # $feature{'blame'}{'override'} = 1;
204 # and in project config gitweb.blame = 0|1;
206 'sub' => \
&feature_blame
,
210 # Enable the 'snapshot' link, providing a compressed archive of any
211 # tree. This can potentially generate high traffic if you have large
214 # Value is a list of formats defined in %known_snapshot_formats that
216 # To disable system wide have in $GITWEB_CONFIG
217 # $feature{'snapshot'}{'default'} = [];
218 # To have project specific config enable override in $GITWEB_CONFIG
219 # $feature{'snapshot'}{'override'} = 1;
220 # and in project config, a comma-separated list of formats or "none"
221 # to disable. Example: gitweb.snapshot = tbz2,zip;
223 'sub' => \
&feature_snapshot
,
225 'default' => ['tgz']},
227 # Enable text search, which will list the commits which match author,
228 # committer or commit text to a given string. Enabled by default.
229 # Project specific override is not supported.
234 # Enable grep search, which will list the files in currently selected
235 # tree containing the given string. Enabled by default. This can be
236 # potentially CPU-intensive, of course.
238 # To enable system wide have in $GITWEB_CONFIG
239 # $feature{'grep'}{'default'} = [1];
240 # To have project specific config enable override in $GITWEB_CONFIG
241 # $feature{'grep'}{'override'} = 1;
242 # and in project config gitweb.grep = 0|1;
244 'sub' => \
&feature_grep
,
248 # Enable the pickaxe search, which will list the commits that modified
249 # a given string in a file. This can be practical and quite faster
250 # alternative to 'blame', but still potentially CPU-intensive.
252 # To enable system wide have in $GITWEB_CONFIG
253 # $feature{'pickaxe'}{'default'} = [1];
254 # To have project specific config enable override in $GITWEB_CONFIG
255 # $feature{'pickaxe'}{'override'} = 1;
256 # and in project config gitweb.pickaxe = 0|1;
258 'sub' => \
&feature_pickaxe
,
262 # Make gitweb use an alternative format of the URLs which can be
263 # more readable and natural-looking: project name is embedded
264 # directly in the path and the query string contains other
265 # auxiliary information. All gitweb installations recognize
266 # URL in either format; this configures in which formats gitweb
269 # To enable system wide have in $GITWEB_CONFIG
270 # $feature{'pathinfo'}{'default'} = [1];
271 # Project specific override is not supported.
273 # Note that you will need to change the default location of CSS,
274 # favicon, logo and possibly other files to an absolute URL. Also,
275 # if gitweb.cgi serves as your indexfile, you will need to force
276 # $my_uri to contain the script name in your $GITWEB_CONFIG.
281 # Make gitweb consider projects in project root subdirectories
282 # to be forks of existing projects. Given project $projname.git,
283 # projects matching $projname/*.git will not be shown in the main
284 # projects list, instead a '+' mark will be added to $projname
285 # there and a 'forks' view will be enabled for the project, listing
286 # all the forks. If project list is taken from a file, forks have
287 # to be listed after the main project.
289 # To enable system wide have in $GITWEB_CONFIG
290 # $feature{'forks'}{'default'} = [1];
291 # Project specific override is not supported.
296 # Insert custom links to the action bar of all project pages.
297 # This enables you mainly to link to third-party scripts integrating
298 # into gitweb; e.g. git-browser for graphical history representation
299 # or custom web-based repository administration interface.
301 # The 'default' value consists of a list of triplets in the form
302 # (label, link, position) where position is the label after which
303 # to insert the link and link is a format string where %n expands
304 # to the project name, %f to the project path within the filesystem,
305 # %h to the current hash (h gitweb parameter) and %b to the current
306 # hash base (hb gitweb parameter); %% expands to %.
308 # To enable system wide have in $GITWEB_CONFIG e.g.
309 # $feature{'actions'}{'default'} = [('graphiclog',
310 # '/git-browser/by-commit.html?r=%n', 'summary')];
311 # Project specific override is not supported.
316 # Allow gitweb scan project content tags described in ctags/
317 # of project repository, and display the popular Web 2.0-ish
318 # "tag cloud" near the project list. Note that this is something
319 # COMPLETELY different from the normal Git tags.
321 # gitweb by itself can show existing tags, but it does not handle
322 # tagging itself; you need an external application for that.
323 # For an example script, check Girocco's cgi/tagproj.cgi.
324 # You may want to install the HTML::TagCloud Perl module to get
325 # a pretty tag cloud instead of just a list of tags.
327 # To enable system wide have in $GITWEB_CONFIG
328 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
329 # Project specific override is not supported.
335 sub gitweb_get_feature
{
337 return unless exists $feature{$name};
338 my ($sub, $override, @defaults) = (
339 $feature{$name}{'sub'},
340 $feature{$name}{'override'},
341 @
{$feature{$name}{'default'}});
342 if (!$override) { return @defaults; }
344 warn "feature $name is not overrideable";
347 return $sub->(@defaults);
350 # A wrapper to check if a given feature is enabled.
351 # With this, you can say
353 # my $bool_feat = gitweb_check_feature('bool_feat');
354 # gitweb_check_feature('bool_feat') or somecode;
358 # my ($bool_feat) = gitweb_get_feature('bool_feat');
359 # (gitweb_get_feature('bool_feat'))[0] or somecode;
361 sub gitweb_check_feature
{
362 return (gitweb_get_feature
(@_))[0];
367 my ($val) = git_get_project_config
('blame', '--bool');
369 if ($val eq 'true') {
371 } elsif ($val eq 'false') {
378 sub feature_snapshot
{
381 my ($val) = git_get_project_config
('snapshot');
384 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
391 my ($val) = git_get_project_config
('grep', '--bool');
393 if ($val eq 'true') {
395 } elsif ($val eq 'false') {
402 sub feature_pickaxe
{
403 my ($val) = git_get_project_config
('pickaxe', '--bool');
405 if ($val eq 'true') {
407 } elsif ($val eq 'false') {
414 # checking HEAD file with -e is fragile if the repository was
415 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
417 sub check_head_link
{
419 my $headfile = "$dir/HEAD";
420 return ((-e
$headfile) ||
421 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
424 sub check_export_ok
{
426 return (check_head_link
($dir) &&
427 (!$export_ok || -e
"$dir/$export_ok") &&
428 (!$export_auth_hook || $export_auth_hook->($dir)));
431 # process alternate names for backward compatibility
432 # filter out unsupported (unknown) snapshot formats
433 sub filter_snapshot_fmts
{
437 exists $known_snapshot_format_aliases{$_} ?
438 $known_snapshot_format_aliases{$_} : $_} @fmts;
439 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
443 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
444 if (-e
$GITWEB_CONFIG) {
447 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
448 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
451 # version of the core git binary
452 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
454 $projects_list ||= $projectroot;
456 # ======================================================================
457 # input validation and dispatch
459 # input parameters can be collected from a variety of sources (presently, CGI
460 # and PATH_INFO), so we define an %input_params hash that collects them all
461 # together during validation: this allows subsequent uses (e.g. href()) to be
462 # agnostic of the parameter origin
464 our %input_params = ();
466 # input parameters are stored with the long parameter name as key. This will
467 # also be used in the href subroutine to convert parameters to their CGI
468 # equivalent, and since the href() usage is the most frequent one, we store
469 # the name -> CGI key mapping here, instead of the reverse.
471 # XXX: Warning: If you touch this, check the search form for updating,
474 our @cgi_param_mapping = (
482 hash_parent_base
=> "hpb",
487 snapshot_format
=> "sf",
488 extra_options
=> "opt",
489 search_use_regexp
=> "sr",
491 our %cgi_param_mapping = @cgi_param_mapping;
493 # we will also need to know the possible actions, for validation
495 "blame" => \
&git_blame
,
496 "blobdiff" => \
&git_blobdiff
,
497 "blobdiff_plain" => \
&git_blobdiff_plain
,
498 "blob" => \
&git_blob
,
499 "blob_plain" => \
&git_blob_plain
,
500 "commitdiff" => \
&git_commitdiff
,
501 "commitdiff_plain" => \
&git_commitdiff_plain
,
502 "commit" => \
&git_commit
,
503 "forks" => \
&git_forks
,
504 "heads" => \
&git_heads
,
505 "history" => \
&git_history
,
508 "atom" => \
&git_atom
,
509 "search" => \
&git_search
,
510 "search_help" => \
&git_search_help
,
511 "shortlog" => \
&git_shortlog
,
512 "summary" => \
&git_summary
,
514 "tags" => \
&git_tags
,
515 "tree" => \
&git_tree
,
516 "snapshot" => \
&git_snapshot
,
517 "object" => \
&git_object
,
518 # those below don't need $project
519 "opml" => \
&git_opml
,
520 "project_list" => \
&git_project_list
,
521 "project_index" => \
&git_project_index
,
524 # finally, we have the hash of allowed extra_options for the commands that
526 our %allowed_options = (
527 "--no-merges" => [ qw(rss atom log shortlog history) ],
530 # fill %input_params with the CGI parameters. All values except for 'opt'
531 # should be single values, but opt can be an array. We should probably
532 # build an array of parameters that can be multi-valued, but since for the time
533 # being it's only this one, we just single it out
534 while (my ($name, $symbol) = each %cgi_param_mapping) {
535 if ($symbol eq 'opt') {
536 $input_params{$name} = [ $cgi->param($symbol) ];
538 $input_params{$name} = $cgi->param($symbol);
542 # now read PATH_INFO and update the parameter list for missing parameters
543 sub evaluate_path_info
{
544 return if defined $input_params{'project'};
545 return if !$path_info;
546 $path_info =~ s
,^/+,,;
547 return if !$path_info;
549 # find which part of PATH_INFO is project
550 my $project = $path_info;
552 while ($project && !check_head_link
("$projectroot/$project")) {
553 $project =~ s
,/*[^/]*$,,;
555 return unless $project;
556 $input_params{'project'} = $project;
558 # do not change any parameters if an action is given using the query string
559 return if $input_params{'action'};
560 $path_info =~ s
,^\Q
$project\E
/*,,;
562 # next, check if we have an action
563 my $action = $path_info;
565 if (exists $actions{$action}) {
566 $path_info =~ s
,^$action/*,,;
567 $input_params{'action'} = $action;
570 # list of actions that want hash_base instead of hash, but can have no
571 # pathname (f) parameter
578 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
579 my ($parentrefname, $parentpathname, $refname, $pathname) =
580 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
582 # first, analyze the 'current' part
583 if (defined $pathname) {
584 # we got "branch:filename" or "branch:dir/"
585 # we could use git_get_type(branch:pathname), but:
586 # - it needs $git_dir
587 # - it does a git() call
588 # - the convention of terminating directories with a slash
589 # makes it superfluous
590 # - embedding the action in the PATH_INFO would make it even
592 $pathname =~ s
,^/+,,;
593 if (!$pathname || substr($pathname, -1) eq "/") {
594 $input_params{'action'} ||= "tree";
597 # the default action depends on whether we had parent info
599 if ($parentrefname) {
600 $input_params{'action'} ||= "blobdiff_plain";
602 $input_params{'action'} ||= "blob_plain";
605 $input_params{'hash_base'} ||= $refname;
606 $input_params{'file_name'} ||= $pathname;
607 } elsif (defined $refname) {
608 # we got "branch". In this case we have to choose if we have to
609 # set hash or hash_base.
611 # Most of the actions without a pathname only want hash to be
612 # set, except for the ones specified in @wants_base that want
613 # hash_base instead. It should also be noted that hand-crafted
614 # links having 'history' as an action and no pathname or hash
615 # set will fail, but that happens regardless of PATH_INFO.
616 $input_params{'action'} ||= "shortlog";
617 if (grep { $_ eq $input_params{'action'} } @wants_base) {
618 $input_params{'hash_base'} ||= $refname;
620 $input_params{'hash'} ||= $refname;
624 # next, handle the 'parent' part, if present
625 if (defined $parentrefname) {
626 # a missing pathspec defaults to the 'current' filename, allowing e.g.
627 # someproject/blobdiff/oldrev..newrev:/filename
628 if ($parentpathname) {
629 $parentpathname =~ s
,^/+,,;
630 $parentpathname =~ s
,/$,,;
631 $input_params{'file_parent'} ||= $parentpathname;
633 $input_params{'file_parent'} ||= $input_params{'file_name'};
635 # we assume that hash_parent_base is wanted if a path was specified,
636 # or if the action wants hash_base instead of hash
637 if (defined $input_params{'file_parent'} ||
638 grep { $_ eq $input_params{'action'} } @wants_base) {
639 $input_params{'hash_parent_base'} ||= $parentrefname;
641 $input_params{'hash_parent'} ||= $parentrefname;
645 # for the snapshot action, we allow URLs in the form
646 # $project/snapshot/$hash.ext
647 # where .ext determines the snapshot and gets removed from the
648 # passed $refname to provide the $hash.
650 # To be able to tell that $refname includes the format extension, we
651 # require the following two conditions to be satisfied:
652 # - the hash input parameter MUST have been set from the $refname part
653 # of the URL (i.e. they must be equal)
654 # - the snapshot format MUST NOT have been defined already (e.g. from
656 # It's also useless to try any matching unless $refname has a dot,
657 # so we check for that too
658 if (defined $input_params{'action'} &&
659 $input_params{'action'} eq 'snapshot' &&
660 defined $refname && index($refname, '.') != -1 &&
661 $refname eq $input_params{'hash'} &&
662 !defined $input_params{'snapshot_format'}) {
663 # We loop over the known snapshot formats, checking for
664 # extensions. Allowed extensions are both the defined suffix
665 # (which includes the initial dot already) and the snapshot
666 # format key itself, with a prepended dot
667 while (my ($fmt, %opt) = each %known_snapshot_formats) {
670 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
671 next unless $sfx = $1;
672 # a valid suffix was found, so set the snapshot format
673 # and reset the hash parameter
674 $input_params{'snapshot_format'} = $fmt;
675 $input_params{'hash'} = $hash;
676 # we also set the format suffix to the one requested
677 # in the URL: this way a request for e.g. .tgz returns
678 # a .tgz instead of a .tar.gz
679 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
684 evaluate_path_info
();
686 our $action = $input_params{'action'};
687 if (defined $action) {
688 if (!validate_action
($action)) {
689 die_error
(400, "Invalid action parameter");
693 # parameters which are pathnames
694 our $project = $input_params{'project'};
695 if (defined $project) {
696 if (!validate_project
($project)) {
698 die_error
(404, "No such project");
702 our $file_name = $input_params{'file_name'};
703 if (defined $file_name) {
704 if (!validate_pathname
($file_name)) {
705 die_error
(400, "Invalid file parameter");
709 our $file_parent = $input_params{'file_parent'};
710 if (defined $file_parent) {
711 if (!validate_pathname
($file_parent)) {
712 die_error
(400, "Invalid file parent parameter");
716 # parameters which are refnames
717 our $hash = $input_params{'hash'};
719 if (!validate_refname
($hash)) {
720 die_error
(400, "Invalid hash parameter");
724 our $hash_parent = $input_params{'hash_parent'};
725 if (defined $hash_parent) {
726 if (!validate_refname
($hash_parent)) {
727 die_error
(400, "Invalid hash parent parameter");
731 our $hash_base = $input_params{'hash_base'};
732 if (defined $hash_base) {
733 if (!validate_refname
($hash_base)) {
734 die_error
(400, "Invalid hash base parameter");
738 our @extra_options = @
{$input_params{'extra_options'}};
739 # @extra_options is always defined, since it can only be (currently) set from
740 # CGI, and $cgi->param() returns the empty array in array context if the param
742 foreach my $opt (@extra_options) {
743 if (not exists $allowed_options{$opt}) {
744 die_error
(400, "Invalid option parameter");
746 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
747 die_error
(400, "Invalid option parameter for this action");
751 our $hash_parent_base = $input_params{'hash_parent_base'};
752 if (defined $hash_parent_base) {
753 if (!validate_refname
($hash_parent_base)) {
754 die_error
(400, "Invalid hash parent base parameter");
759 our $page = $input_params{'page'};
761 if ($page =~ m/[^0-9]/) {
762 die_error
(400, "Invalid page parameter");
766 our $searchtype = $input_params{'searchtype'};
767 if (defined $searchtype) {
768 if ($searchtype =~ m/[^a-z]/) {
769 die_error
(400, "Invalid searchtype parameter");
773 our $search_use_regexp = $input_params{'search_use_regexp'};
775 our $searchtext = $input_params{'searchtext'};
777 if (defined $searchtext) {
778 if (length($searchtext) < 2) {
779 die_error
(403, "At least two characters are required for search parameter");
781 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
784 # path to the current git repository
786 $git_dir = "$projectroot/$project" if $project;
788 # list of supported snapshot formats
789 our @snapshot_fmts = gitweb_get_feature
('snapshot');
790 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
793 if (!defined $action) {
795 $action = git_get_type
($hash);
796 } elsif (defined $hash_base && defined $file_name) {
797 $action = git_get_type
("$hash_base:$file_name");
798 } elsif (defined $project) {
801 $action = 'project_list';
804 if (!defined($actions{$action})) {
805 die_error
(400, "Unknown action");
807 if ($action !~ m/^(opml|project_list|project_index)$/ &&
809 die_error
(400, "Project needed");
811 $actions{$action}->();
814 ## ======================================================================
819 # default is to use -absolute url() i.e. $my_uri
820 my $href = $params{-full
} ?
$my_url : $my_uri;
822 $params{'project'} = $project unless exists $params{'project'};
824 if ($params{-replay
}) {
825 while (my ($name, $symbol) = each %cgi_param_mapping) {
826 if (!exists $params{$name}) {
827 $params{$name} = $input_params{$name};
832 my $use_pathinfo = gitweb_check_feature
('pathinfo');
834 # try to put as many parameters as possible in PATH_INFO:
837 # - hash_parent or hash_parent_base:/file_parent
838 # - hash or hash_base:/filename
839 # - the snapshot_format as an appropriate suffix
841 # When the script is the root DirectoryIndex for the domain,
842 # $href here would be something like http://gitweb.example.com/
843 # Thus, we strip any trailing / from $href, to spare us double
844 # slashes in the final URL
847 # Then add the project name, if present
848 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
849 delete $params{'project'};
851 # since we destructively absorb parameters, we keep this
852 # boolean that remembers if we're handling a snapshot
853 my $is_snapshot = $params{'action'} eq 'snapshot';
855 # Summary just uses the project path URL, any other action is
857 if (defined $params{'action'}) {
858 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
859 delete $params{'action'};
862 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
863 # stripping nonexistent or useless pieces
864 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
865 || $params{'hash_parent'} || $params{'hash'});
866 if (defined $params{'hash_base'}) {
867 if (defined $params{'hash_parent_base'}) {
868 $href .= esc_url
($params{'hash_parent_base'});
869 # skip the file_parent if it's the same as the file_name
870 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
871 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
872 $href .= ":/".esc_url
($params{'file_parent'});
873 delete $params{'file_parent'};
876 delete $params{'hash_parent'};
877 delete $params{'hash_parent_base'};
878 } elsif (defined $params{'hash_parent'}) {
879 $href .= esc_url
($params{'hash_parent'}). "..";
880 delete $params{'hash_parent'};
883 $href .= esc_url
($params{'hash_base'});
884 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
885 $href .= ":/".esc_url
($params{'file_name'});
886 delete $params{'file_name'};
888 delete $params{'hash'};
889 delete $params{'hash_base'};
890 } elsif (defined $params{'hash'}) {
891 $href .= esc_url
($params{'hash'});
892 delete $params{'hash'};
895 # If the action was a snapshot, we can absorb the
896 # snapshot_format parameter too
898 my $fmt = $params{'snapshot_format'};
899 # snapshot_format should always be defined when href()
900 # is called, but just in case some code forgets, we
901 # fall back to the default
902 $fmt ||= $snapshot_fmts[0];
903 $href .= $known_snapshot_formats{$fmt}{'suffix'};
904 delete $params{'snapshot_format'};
908 # now encode the parameters explicitly
910 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
911 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
912 if (defined $params{$name}) {
913 if (ref($params{$name}) eq "ARRAY") {
914 foreach my $par (@
{$params{$name}}) {
915 push @result, $symbol . "=" . esc_param
($par);
918 push @result, $symbol . "=" . esc_param
($params{$name});
922 $href .= "?" . join(';', @result) if scalar @result;
928 ## ======================================================================
929 ## validation, quoting/unquoting and escaping
931 sub validate_action
{
932 my $input = shift || return undef;
933 return undef unless exists $actions{$input};
937 sub validate_project
{
938 my $input = shift || return undef;
939 if (!validate_pathname
($input) ||
940 !(-d
"$projectroot/$input") ||
941 !check_export_ok
("$projectroot/$input") ||
942 ($strict_export && !project_in_list
($input))) {
949 sub validate_pathname
{
950 my $input = shift || return undef;
952 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
953 # at the beginning, at the end, and between slashes.
954 # also this catches doubled slashes
955 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
959 if ($input =~ m!\0!) {
965 sub validate_refname
{
966 my $input = shift || return undef;
968 # textual hashes are O.K.
969 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
972 # it must be correct pathname
973 $input = validate_pathname
($input)
975 # restrictions on ref name according to git-check-ref-format
976 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
982 # decode sequences of octets in utf8 into Perl's internal form,
983 # which is utf-8 with utf8 flag set if needed. gitweb writes out
984 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
987 if (utf8
::valid
($str)) {
991 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
995 # quote unsafe chars, but keep the slash, even when it's not
996 # correct, but quoted slashes look too horrible in bookmarks
999 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1005 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1008 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1014 # replace invalid utf8 character with SUBSTITUTION sequence
1015 sub esc_html
($;%) {
1019 $str = to_utf8
($str);
1020 $str = $cgi->escapeHTML($str);
1021 if ($opts{'-nbsp'}) {
1022 $str =~ s/ / /g;
1024 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1028 # quote control characters and escape filename to HTML
1033 $str = to_utf8
($str);
1034 $str = $cgi->escapeHTML($str);
1035 if ($opts{'-nbsp'}) {
1036 $str =~ s/ / /g;
1038 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1042 # Make control characters "printable", using character escape codes (CEC)
1046 my %es = ( # character escape codes, aka escape sequences
1047 "\t" => '\t', # tab (HT)
1048 "\n" => '\n', # line feed (LF)
1049 "\r" => '\r', # carrige return (CR)
1050 "\f" => '\f', # form feed (FF)
1051 "\b" => '\b', # backspace (BS)
1052 "\a" => '\a', # alarm (bell) (BEL)
1053 "\e" => '\e', # escape (ESC)
1054 "\013" => '\v', # vertical tab (VT)
1055 "\000" => '\0', # nul character (NUL)
1057 my $chr = ( (exists $es{$cntrl})
1059 : sprintf('\%2x', ord($cntrl)) );
1060 if ($opts{-nohtml
}) {
1063 return "<span class=\"cntrl\">$chr</span>";
1067 # Alternatively use unicode control pictures codepoints,
1068 # Unicode "printable representation" (PR)
1073 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1074 if ($opts{-nohtml
}) {
1077 return "<span class=\"cntrl\">$chr</span>";
1081 # git may return quoted and escaped filenames
1087 my %es = ( # character escape codes, aka escape sequences
1088 't' => "\t", # tab (HT, TAB)
1089 'n' => "\n", # newline (NL)
1090 'r' => "\r", # return (CR)
1091 'f' => "\f", # form feed (FF)
1092 'b' => "\b", # backspace (BS)
1093 'a' => "\a", # alarm (bell) (BEL)
1094 'e' => "\e", # escape (ESC)
1095 'v' => "\013", # vertical tab (VT)
1098 if ($seq =~ m/^[0-7]{1,3}$/) {
1099 # octal char sequence
1100 return chr(oct($seq));
1101 } elsif (exists $es{$seq}) {
1102 # C escape sequence, aka character escape code
1105 # quoted ordinary character
1109 if ($str =~ m/^"(.*)"$/) {
1112 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1117 # escape tabs (convert tabs to spaces)
1121 while ((my $pos = index($line, "\t")) != -1) {
1122 if (my $count = (8 - ($pos % 8))) {
1123 my $spaces = ' ' x
$count;
1124 $line =~ s/\t/$spaces/;
1131 sub project_in_list
{
1132 my $project = shift;
1133 my @list = git_get_projects_list
();
1134 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1137 ## ----------------------------------------------------------------------
1138 ## HTML aware string manipulation
1140 # Try to chop given string on a word boundary between position
1141 # $len and $len+$add_len. If there is no word boundary there,
1142 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1143 # (marking chopped part) would be longer than given string.
1147 my $add_len = shift || 10;
1148 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1150 # Make sure perl knows it is utf8 encoded so we don't
1151 # cut in the middle of a utf8 multibyte char.
1152 $str = to_utf8
($str);
1154 # allow only $len chars, but don't cut a word if it would fit in $add_len
1155 # if it doesn't fit, cut it if it's still longer than the dots we would add
1156 # remove chopped character entities entirely
1158 # when chopping in the middle, distribute $len into left and right part
1159 # return early if chopping wouldn't make string shorter
1160 if ($where eq 'center') {
1161 return $str if ($len + 5 >= length($str)); # filler is length 5
1164 return $str if ($len + 4 >= length($str)); # filler is length 4
1167 # regexps: ending and beginning with word part up to $add_len
1168 my $endre = qr/.{$len}\w{0,$add_len}/;
1169 my $begre = qr/\w{0,$add_len}.{$len}/;
1171 if ($where eq 'left') {
1172 $str =~ m/^(.*?)($begre)$/;
1173 my ($lead, $body) = ($1, $2);
1174 if (length($lead) > 4) {
1175 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1178 return "$lead$body";
1180 } elsif ($where eq 'center') {
1181 $str =~ m/^($endre)(.*)$/;
1182 my ($left, $str) = ($1, $2);
1183 $str =~ m/^(.*?)($begre)$/;
1184 my ($mid, $right) = ($1, $2);
1185 if (length($mid) > 5) {
1186 $left =~ s/&[^;]*$//;
1187 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1190 return "$left$mid$right";
1193 $str =~ m/^($endre)(.*)$/;
1196 if (length($tail) > 4) {
1197 $body =~ s/&[^;]*$//;
1200 return "$body$tail";
1204 # takes the same arguments as chop_str, but also wraps a <span> around the
1205 # result with a title attribute if it does get chopped. Additionally, the
1206 # string is HTML-escaped.
1207 sub chop_and_escape_str
{
1210 my $chopped = chop_str
(@_);
1211 if ($chopped eq $str) {
1212 return esc_html
($chopped);
1214 $str =~ s/([[:cntrl:]])/?/g;
1215 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1219 ## ----------------------------------------------------------------------
1220 ## functions returning short strings
1222 # CSS class for given age value (in seconds)
1226 if (!defined $age) {
1228 } elsif ($age < 60*60*2) {
1230 } elsif ($age < 60*60*24*2) {
1237 # convert age in seconds to "nn units ago" string
1242 if ($age > 60*60*24*365*2) {
1243 $age_str = (int $age/60/60/24/365);
1244 $age_str .= " years ago";
1245 } elsif ($age > 60*60*24*(365/12)*2) {
1246 $age_str = int $age/60/60/24/(365/12);
1247 $age_str .= " months ago";
1248 } elsif ($age > 60*60*24*7*2) {
1249 $age_str = int $age/60/60/24/7;
1250 $age_str .= " weeks ago";
1251 } elsif ($age > 60*60*24*2) {
1252 $age_str = int $age/60/60/24;
1253 $age_str .= " days ago";
1254 } elsif ($age > 60*60*2) {
1255 $age_str = int $age/60/60;
1256 $age_str .= " hours ago";
1257 } elsif ($age > 60*2) {
1258 $age_str = int $age/60;
1259 $age_str .= " min ago";
1260 } elsif ($age > 2) {
1261 $age_str = int $age;
1262 $age_str .= " sec ago";
1264 $age_str .= " right now";
1270 S_IFINVALID
=> 0030000,
1271 S_IFGITLINK
=> 0160000,
1274 # submodule/subproject, a commit object reference
1275 sub S_ISGITLINK
($) {
1278 return (($mode & S_IFMT
) == S_IFGITLINK
)
1281 # convert file mode in octal to symbolic file mode string
1283 my $mode = oct shift;
1285 if (S_ISGITLINK
($mode)) {
1286 return 'm---------';
1287 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1288 return 'drwxr-xr-x';
1289 } elsif (S_ISLNK
($mode)) {
1290 return 'lrwxrwxrwx';
1291 } elsif (S_ISREG
($mode)) {
1292 # git cares only about the executable bit
1293 if ($mode & S_IXUSR
) {
1294 return '-rwxr-xr-x';
1296 return '-rw-r--r--';
1299 return '----------';
1303 # convert file mode in octal to file type string
1307 if ($mode !~ m/^[0-7]+$/) {
1313 if (S_ISGITLINK
($mode)) {
1315 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1317 } elsif (S_ISLNK
($mode)) {
1319 } elsif (S_ISREG
($mode)) {
1326 # convert file mode in octal to file type description string
1327 sub file_type_long
{
1330 if ($mode !~ m/^[0-7]+$/) {
1336 if (S_ISGITLINK
($mode)) {
1338 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1340 } elsif (S_ISLNK
($mode)) {
1342 } elsif (S_ISREG
($mode)) {
1343 if ($mode & S_IXUSR
) {
1344 return "executable";
1354 ## ----------------------------------------------------------------------
1355 ## functions returning short HTML fragments, or transforming HTML fragments
1356 ## which don't belong to other sections
1358 # format line of commit message.
1359 sub format_log_line_html
{
1362 $line = esc_html
($line, -nbsp
=>1);
1363 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1366 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1367 -class => "text"}, $hash_text);
1368 $line =~ s/$hash_text/$link/;
1373 # format marker of refs pointing to given object
1375 # the destination action is chosen based on object type and current context:
1376 # - for annotated tags, we choose the tag view unless it's the current view
1377 # already, in which case we go to shortlog view
1378 # - for other refs, we keep the current view if we're in history, shortlog or
1379 # log view, and select shortlog otherwise
1380 sub format_ref_marker
{
1381 my ($refs, $id) = @_;
1384 if (defined $refs->{$id}) {
1385 foreach my $ref (@
{$refs->{$id}}) {
1386 # this code exploits the fact that non-lightweight tags are the
1387 # only indirect objects, and that they are the only objects for which
1388 # we want to use tag instead of shortlog as action
1389 my ($type, $name) = qw();
1390 my $indirect = ($ref =~ s/\^\{\}$//);
1391 # e.g. tags/v2.6.11 or heads/next
1392 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1401 $class .= " indirect" if $indirect;
1403 my $dest_action = "shortlog";
1406 $dest_action = "tag" unless $action eq "tag";
1407 } elsif ($action =~ /^(history|(short)?log)$/) {
1408 $dest_action = $action;
1412 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1415 my $link = $cgi->a({
1417 action
=>$dest_action,
1421 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1427 return ' <span class="refs">'. $markers . '</span>';
1433 # format, perhaps shortened and with markers, title line
1434 sub format_subject_html
{
1435 my ($long, $short, $href, $extra) = @_;
1436 $extra = '' unless defined($extra);
1438 if (length($short) < length($long)) {
1439 return $cgi->a({-href
=> $href, -class => "list subject",
1440 -title
=> to_utf8
($long)},
1441 esc_html
($short) . $extra);
1443 return $cgi->a({-href
=> $href, -class => "list subject"},
1444 esc_html
($long) . $extra);
1448 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1449 sub format_git_diff_header_line
{
1451 my $diffinfo = shift;
1452 my ($from, $to) = @_;
1454 if ($diffinfo->{'nparents'}) {
1456 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1457 if ($to->{'href'}) {
1458 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1459 esc_path
($to->{'file'}));
1460 } else { # file was deleted (no href)
1461 $line .= esc_path
($to->{'file'});
1465 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1466 if ($from->{'href'}) {
1467 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1468 'a/' . esc_path
($from->{'file'}));
1469 } else { # file was added (no href)
1470 $line .= 'a/' . esc_path
($from->{'file'});
1473 if ($to->{'href'}) {
1474 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1475 'b/' . esc_path
($to->{'file'}));
1476 } else { # file was deleted
1477 $line .= 'b/' . esc_path
($to->{'file'});
1481 return "<div class=\"diff header\">$line</div>\n";
1484 # format extended diff header line, before patch itself
1485 sub format_extended_diff_header_line
{
1487 my $diffinfo = shift;
1488 my ($from, $to) = @_;
1491 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1492 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1493 esc_path
($from->{'file'}));
1495 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1496 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1497 esc_path
($to->{'file'}));
1499 # match single <mode>
1500 if ($line =~ m/\s(\d{6})$/) {
1501 $line .= '<span class="info"> (' .
1502 file_type_long
($1) .
1506 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1507 # can match only for combined diff
1509 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1510 if ($from->{'href'}[$i]) {
1511 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1513 substr($diffinfo->{'from_id'}[$i],0,7));
1518 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1521 if ($to->{'href'}) {
1522 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1523 substr($diffinfo->{'to_id'},0,7));
1528 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1529 # can match only for ordinary diff
1530 my ($from_link, $to_link);
1531 if ($from->{'href'}) {
1532 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1533 substr($diffinfo->{'from_id'},0,7));
1535 $from_link = '0' x
7;
1537 if ($to->{'href'}) {
1538 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1539 substr($diffinfo->{'to_id'},0,7));
1543 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1544 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1547 return $line . "<br/>\n";
1550 # format from-file/to-file diff header
1551 sub format_diff_from_to_header
{
1552 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1557 #assert($line =~ m/^---/) if DEBUG;
1558 # no extra formatting for "^--- /dev/null"
1559 if (! $diffinfo->{'nparents'}) {
1560 # ordinary (single parent) diff
1561 if ($line =~ m!^--- "?a/!) {
1562 if ($from->{'href'}) {
1564 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1565 esc_path
($from->{'file'}));
1568 esc_path
($from->{'file'});
1571 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1574 # combined diff (merge commit)
1575 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1576 if ($from->{'href'}[$i]) {
1578 $cgi->a({-href
=>href
(action
=>"blobdiff",
1579 hash_parent
=>$diffinfo->{'from_id'}[$i],
1580 hash_parent_base
=>$parents[$i],
1581 file_parent
=>$from->{'file'}[$i],
1582 hash
=>$diffinfo->{'to_id'},
1584 file_name
=>$to->{'file'}),
1586 -title
=>"diff" . ($i+1)},
1589 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1590 esc_path
($from->{'file'}[$i]));
1592 $line = '--- /dev/null';
1594 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1599 #assert($line =~ m/^\+\+\+/) if DEBUG;
1600 # no extra formatting for "^+++ /dev/null"
1601 if ($line =~ m!^\+\+\+ "?b/!) {
1602 if ($to->{'href'}) {
1604 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1605 esc_path
($to->{'file'}));
1608 esc_path
($to->{'file'});
1611 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1616 # create note for patch simplified by combined diff
1617 sub format_diff_cc_simplified
{
1618 my ($diffinfo, @parents) = @_;
1621 $result .= "<div class=\"diff header\">" .
1623 if (!is_deleted
($diffinfo)) {
1624 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1626 hash
=>$diffinfo->{'to_id'},
1627 file_name
=>$diffinfo->{'to_file'}),
1629 esc_path
($diffinfo->{'to_file'}));
1631 $result .= esc_path
($diffinfo->{'to_file'});
1633 $result .= "</div>\n" . # class="diff header"
1634 "<div class=\"diff nodifferences\">" .
1636 "</div>\n"; # class="diff nodifferences"
1641 # format patch (diff) line (not to be used for diff headers)
1642 sub format_diff_line
{
1644 my ($from, $to) = @_;
1645 my $diff_class = "";
1649 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1651 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1652 if ($line =~ m/^\@{3}/) {
1653 $diff_class = " chunk_header";
1654 } elsif ($line =~ m/^\\/) {
1655 $diff_class = " incomplete";
1656 } elsif ($prefix =~ tr/+/+/) {
1657 $diff_class = " add";
1658 } elsif ($prefix =~ tr/-/-/) {
1659 $diff_class = " rem";
1662 # assume ordinary diff
1663 my $char = substr($line, 0, 1);
1665 $diff_class = " add";
1666 } elsif ($char eq '-') {
1667 $diff_class = " rem";
1668 } elsif ($char eq '@') {
1669 $diff_class = " chunk_header";
1670 } elsif ($char eq "\\") {
1671 $diff_class = " incomplete";
1674 $line = untabify
($line);
1675 if ($from && $to && $line =~ m/^\@{2} /) {
1676 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1677 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1679 $from_lines = 0 unless defined $from_lines;
1680 $to_lines = 0 unless defined $to_lines;
1682 if ($from->{'href'}) {
1683 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1684 -class=>"list"}, $from_text);
1686 if ($to->{'href'}) {
1687 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1688 -class=>"list"}, $to_text);
1690 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1691 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1692 return "<div class=\"diff$diff_class\">$line</div>\n";
1693 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1694 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1695 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1697 @from_text = split(' ', $ranges);
1698 for (my $i = 0; $i < @from_text; ++$i) {
1699 ($from_start[$i], $from_nlines[$i]) =
1700 (split(',', substr($from_text[$i], 1)), 0);
1703 $to_text = pop @from_text;
1704 $to_start = pop @from_start;
1705 $to_nlines = pop @from_nlines;
1707 $line = "<span class=\"chunk_info\">$prefix ";
1708 for (my $i = 0; $i < @from_text; ++$i) {
1709 if ($from->{'href'}[$i]) {
1710 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1711 -class=>"list"}, $from_text[$i]);
1713 $line .= $from_text[$i];
1717 if ($to->{'href'}) {
1718 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1719 -class=>"list"}, $to_text);
1723 $line .= " $prefix</span>" .
1724 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1725 return "<div class=\"diff$diff_class\">$line</div>\n";
1727 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1730 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1731 # linked. Pass the hash of the tree/commit to snapshot.
1732 sub format_snapshot_links
{
1734 my $num_fmts = @snapshot_fmts;
1735 if ($num_fmts > 1) {
1736 # A parenthesized list of links bearing format names.
1737 # e.g. "snapshot (_tar.gz_ _zip_)"
1738 return "snapshot (" . join(' ', map
1745 }, $known_snapshot_formats{$_}{'display'})
1746 , @snapshot_fmts) . ")";
1747 } elsif ($num_fmts == 1) {
1748 # A single "snapshot" link whose tooltip bears the format name.
1750 my ($fmt) = @snapshot_fmts;
1756 snapshot_format
=>$fmt
1758 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1760 } else { # $num_fmts == 0
1765 ## ......................................................................
1766 ## functions returning values to be passed, perhaps after some
1767 ## transformation, to other functions; e.g. returning arguments to href()
1769 # returns hash to be passed to href to generate gitweb URL
1770 # in -title key it returns description of link
1772 my $format = shift || 'Atom';
1773 my %res = (action
=> lc($format));
1775 # feed links are possible only for project views
1776 return unless (defined $project);
1777 # some views should link to OPML, or to generic project feed,
1778 # or don't have specific feed yet (so they should use generic)
1779 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1782 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1783 # from tag links; this also makes possible to detect branch links
1784 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1785 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1788 # find log type for feed description (title)
1790 if (defined $file_name) {
1791 $type = "history of $file_name";
1792 $type .= "/" if ($action eq 'tree');
1793 $type .= " on '$branch'" if (defined $branch);
1795 $type = "log of $branch" if (defined $branch);
1798 $res{-title
} = $type;
1799 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1800 $res{'file_name'} = $file_name;
1805 ## ----------------------------------------------------------------------
1806 ## git utility subroutines, invoking git commands
1808 # returns path to the core git executable and the --git-dir parameter as list
1810 return $GIT, '--git-dir='.$git_dir;
1813 # quote the given arguments for passing them to the shell
1814 # quote_command("command", "arg 1", "arg with ' and ! characters")
1815 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1816 # Try to avoid using this function wherever possible.
1819 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1822 # get HEAD ref of given project as hash
1823 sub git_get_head_hash
{
1824 my $project = shift;
1825 my $o_git_dir = $git_dir;
1827 $git_dir = "$projectroot/$project";
1828 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1831 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1835 if (defined $o_git_dir) {
1836 $git_dir = $o_git_dir;
1841 # get type of given object
1845 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1847 close $fd or return;
1852 # repository configuration
1853 our $config_file = '';
1856 # store multiple values for single key as anonymous array reference
1857 # single values stored directly in the hash, not as [ <value> ]
1858 sub hash_set_multi
{
1859 my ($hash, $key, $value) = @_;
1861 if (!exists $hash->{$key}) {
1862 $hash->{$key} = $value;
1863 } elsif (!ref $hash->{$key}) {
1864 $hash->{$key} = [ $hash->{$key}, $value ];
1866 push @
{$hash->{$key}}, $value;
1870 # return hash of git project configuration
1871 # optionally limited to some section, e.g. 'gitweb'
1872 sub git_parse_project_config
{
1873 my $section_regexp = shift;
1878 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1881 while (my $keyval = <$fh>) {
1883 my ($key, $value) = split(/\n/, $keyval, 2);
1885 hash_set_multi
(\
%config, $key, $value)
1886 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1893 # convert config value to boolean, 'true' or 'false'
1894 # no value, number > 0, 'true' and 'yes' values are true
1895 # rest of values are treated as false (never as error)
1896 sub config_to_bool
{
1899 # strip leading and trailing whitespace
1903 return (!defined $val || # section.key
1904 ($val =~ /^\d+$/ && $val) || # section.key = 1
1905 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1908 # convert config value to simple decimal number
1909 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1910 # to be multiplied by 1024, 1048576, or 1073741824
1914 # strip leading and trailing whitespace
1918 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1920 # unknown unit is treated as 1
1921 return $num * ($unit eq 'g' ?
1073741824 :
1922 $unit eq 'm' ?
1048576 :
1923 $unit eq 'k' ?
1024 : 1);
1928 # convert config value to array reference, if needed
1929 sub config_to_multi
{
1932 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1935 sub git_get_project_config
{
1936 my ($key, $type) = @_;
1939 return unless ($key);
1940 $key =~ s/^gitweb\.//;
1941 return if ($key =~ m/\W/);
1944 if (defined $type) {
1947 unless ($type eq 'bool' || $type eq 'int');
1951 if (!defined $config_file ||
1952 $config_file ne "$git_dir/config") {
1953 %config = git_parse_project_config
('gitweb');
1954 $config_file = "$git_dir/config";
1958 if (!defined $type) {
1959 return $config{"gitweb.$key"};
1960 } elsif ($type eq 'bool') {
1961 # backward compatibility: 'git config --bool' returns true/false
1962 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1963 } elsif ($type eq 'int') {
1964 return config_to_int
($config{"gitweb.$key"});
1966 return $config{"gitweb.$key"};
1969 # get hash of given path at given ref
1970 sub git_get_hash_by_path
{
1972 my $path = shift || return undef;
1977 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1978 or die_error
(500, "Open git-ls-tree failed");
1980 close $fd or return undef;
1982 if (!defined $line) {
1983 # there is no tree or hash given by $path at $base
1987 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1988 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1989 if (defined $type && $type ne $2) {
1990 # type doesn't match
1996 # get path of entry with given hash at given tree-ish (ref)
1997 # used to get 'from' filename for combined diff (merge commit) for renames
1998 sub git_get_path_by_hash
{
1999 my $base = shift || return;
2000 my $hash = shift || return;
2004 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2006 while (my $line = <$fd>) {
2009 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2010 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2011 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2020 ## ......................................................................
2021 ## git utility functions, directly accessing git repository
2023 sub git_get_project_description
{
2026 $git_dir = "$projectroot/$path";
2027 open my $fd, "$git_dir/description"
2028 or return git_get_project_config
('description');
2031 if (defined $descr) {
2037 sub git_get_project_ctags
{
2041 $git_dir = "$projectroot/$path";
2042 unless (opendir D
, "$git_dir/ctags") {
2045 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2046 open CT
, $_ or next;
2050 my $ctag = $_; $ctag =~ s
#.*/##;
2051 $ctags->{$ctag} = $val;
2057 sub git_populate_project_tagcloud
{
2060 # First, merge different-cased tags; tags vote on casing
2062 foreach (keys %$ctags) {
2063 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2064 if (not $ctags_lc{lc $_}->{topcount
}
2065 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2066 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2067 $ctags_lc{lc $_}->{topname
} = $_;
2072 if (eval { require HTML
::TagCloud
; 1; }) {
2073 $cloud = HTML
::TagCloud
->new;
2074 foreach (sort keys %ctags_lc) {
2075 # Pad the title with spaces so that the cloud looks
2077 my $title = $ctags_lc{$_}->{topname
};
2078 $title =~ s/ / /g;
2079 $title =~ s/^/ /g;
2080 $title =~ s/$/ /g;
2081 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2084 $cloud = \
%ctags_lc;
2089 sub git_show_project_tagcloud
{
2090 my ($cloud, $count) = @_;
2091 print STDERR
ref($cloud)."..\n";
2092 if (ref $cloud eq 'HTML::TagCloud') {
2093 return $cloud->html_and_css($count);
2095 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2096 return '<p align="center">' . join (', ', map {
2097 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2098 } splice(@tags, 0, $count)) . '</p>';
2102 sub git_get_project_url_list
{
2105 $git_dir = "$projectroot/$path";
2106 open my $fd, "$git_dir/cloneurl"
2107 or return wantarray ?
2108 @
{ config_to_multi
(git_get_project_config
('url')) } :
2109 config_to_multi
(git_get_project_config
('url'));
2110 my @git_project_url_list = map { chomp; $_ } <$fd>;
2113 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2116 sub git_get_projects_list
{
2121 $filter =~ s/\.git$//;
2123 my $check_forks = gitweb_check_feature
('forks');
2125 if (-d
$projects_list) {
2126 # search in directory
2127 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2128 # remove the trailing "/"
2130 my $pfxlen = length("$dir");
2131 my $pfxdepth = ($dir =~ tr!/!!);
2134 follow_fast
=> 1, # follow symbolic links
2135 follow_skip
=> 2, # ignore duplicates
2136 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2138 # skip project-list toplevel, if we get it.
2139 return if (m!^[/.]$!);
2140 # only directories can be git repositories
2141 return unless (-d
$_);
2142 # don't traverse too deep (Find is super slow on os x)
2143 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2144 $File::Find
::prune
= 1;
2148 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2149 # we check related file in $projectroot
2150 my $path = ($filter ?
"$filter/" : '') . $subdir;
2151 if (check_export_ok
("$projectroot/$path")) {
2152 push @list, { path
=> $path };
2153 $File::Find
::prune
= 1;
2158 } elsif (-f
$projects_list) {
2159 # read from file(url-encoded):
2160 # 'git%2Fgit.git Linus+Torvalds'
2161 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2162 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2164 open my ($fd), $projects_list or return;
2166 while (my $line = <$fd>) {
2168 my ($path, $owner) = split ' ', $line;
2169 $path = unescape
($path);
2170 $owner = unescape
($owner);
2171 if (!defined $path) {
2174 if ($filter ne '') {
2175 # looking for forks;
2176 my $pfx = substr($path, 0, length($filter));
2177 if ($pfx ne $filter) {
2180 my $sfx = substr($path, length($filter));
2181 if ($sfx !~ /^\/.*\
.git
$/) {
2184 } elsif ($check_forks) {
2186 foreach my $filter (keys %paths) {
2187 # looking for forks;
2188 my $pfx = substr($path, 0, length($filter));
2189 if ($pfx ne $filter) {
2192 my $sfx = substr($path, length($filter));
2193 if ($sfx !~ /^\/.*\
.git
$/) {
2196 # is a fork, don't include it in
2201 if (check_export_ok
("$projectroot/$path")) {
2204 owner
=> to_utf8
($owner),
2207 (my $forks_path = $path) =~ s/\.git$//;
2208 $paths{$forks_path}++;
2216 our $gitweb_project_owner = undef;
2217 sub git_get_project_list_from_file
{
2219 return if (defined $gitweb_project_owner);
2221 $gitweb_project_owner = {};
2222 # read from file (url-encoded):
2223 # 'git%2Fgit.git Linus+Torvalds'
2224 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2225 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2226 if (-f
$projects_list) {
2227 open (my $fd , $projects_list);
2228 while (my $line = <$fd>) {
2230 my ($pr, $ow) = split ' ', $line;
2231 $pr = unescape
($pr);
2232 $ow = unescape
($ow);
2233 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2239 sub git_get_project_owner
{
2240 my $project = shift;
2243 return undef unless $project;
2244 $git_dir = "$projectroot/$project";
2246 if (!defined $gitweb_project_owner) {
2247 git_get_project_list_from_file
();
2250 if (exists $gitweb_project_owner->{$project}) {
2251 $owner = $gitweb_project_owner->{$project};
2253 if (!defined $owner){
2254 $owner = git_get_project_config
('owner');
2256 if (!defined $owner) {
2257 $owner = get_file_owner
("$git_dir");
2263 sub git_get_last_activity
{
2267 $git_dir = "$projectroot/$path";
2268 open($fd, "-|", git_cmd
(), 'for-each-ref',
2269 '--format=%(committer)',
2270 '--sort=-committerdate',
2272 'refs/heads') or return;
2273 my $most_recent = <$fd>;
2274 close $fd or return;
2275 if (defined $most_recent &&
2276 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2278 my $age = time - $timestamp;
2279 return ($age, age_string
($age));
2281 return (undef, undef);
2284 sub git_get_references
{
2285 my $type = shift || "";
2287 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2288 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2289 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2290 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2293 while (my $line = <$fd>) {
2295 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2296 if (defined $refs{$1}) {
2297 push @
{$refs{$1}}, $2;
2303 close $fd or return;
2307 sub git_get_rev_name_tags
{
2308 my $hash = shift || return undef;
2310 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2312 my $name_rev = <$fd>;
2315 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2318 # catches also '$hash undefined' output
2323 ## ----------------------------------------------------------------------
2324 ## parse to hash functions
2328 my $tz = shift || "-0000";
2331 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2332 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2333 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2334 $date{'hour'} = $hour;
2335 $date{'minute'} = $min;
2336 $date{'mday'} = $mday;
2337 $date{'day'} = $days[$wday];
2338 $date{'month'} = $months[$mon];
2339 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2340 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2341 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2342 $mday, $months[$mon], $hour ,$min;
2343 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2344 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2346 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2347 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2348 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2349 $date{'hour_local'} = $hour;
2350 $date{'minute_local'} = $min;
2351 $date{'tz_local'} = $tz;
2352 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2353 1900+$year, $mon+1, $mday,
2354 $hour, $min, $sec, $tz);
2363 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2364 $tag{'id'} = $tag_id;
2365 while (my $line = <$fd>) {
2367 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2368 $tag{'object'} = $1;
2369 } elsif ($line =~ m/^type (.+)$/) {
2371 } elsif ($line =~ m/^tag (.+)$/) {
2373 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2374 $tag{'author'} = $1;
2377 } elsif ($line =~ m/--BEGIN/) {
2378 push @comment, $line;
2380 } elsif ($line eq "") {
2384 push @comment, <$fd>;
2385 $tag{'comment'} = \
@comment;
2386 close $fd or return;
2387 if (!defined $tag{'name'}) {
2393 sub parse_commit_text
{
2394 my ($commit_text, $withparents) = @_;
2395 my @commit_lines = split '\n', $commit_text;
2398 pop @commit_lines; # Remove '\0'
2400 if (! @commit_lines) {
2404 my $header = shift @commit_lines;
2405 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2408 ($co{'id'}, my @parents) = split ' ', $header;
2409 while (my $line = shift @commit_lines) {
2410 last if $line eq "\n";
2411 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2413 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2415 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2417 $co{'author_epoch'} = $2;
2418 $co{'author_tz'} = $3;
2419 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2420 $co{'author_name'} = $1;
2421 $co{'author_email'} = $2;
2423 $co{'author_name'} = $co{'author'};
2425 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2426 $co{'committer'} = $1;
2427 $co{'committer_epoch'} = $2;
2428 $co{'committer_tz'} = $3;
2429 $co{'committer_name'} = $co{'committer'};
2430 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2431 $co{'committer_name'} = $1;
2432 $co{'committer_email'} = $2;
2434 $co{'committer_name'} = $co{'committer'};
2438 if (!defined $co{'tree'}) {
2441 $co{'parents'} = \
@parents;
2442 $co{'parent'} = $parents[0];
2444 foreach my $title (@commit_lines) {
2447 $co{'title'} = chop_str
($title, 80, 5);
2448 # remove leading stuff of merges to make the interesting part visible
2449 if (length($title) > 50) {
2450 $title =~ s/^Automatic //;
2451 $title =~ s/^merge (of|with) /Merge ... /i;
2452 if (length($title) > 50) {
2453 $title =~ s/(http|rsync):\/\///;
2455 if (length($title) > 50) {
2456 $title =~ s/(master|www|rsync)\.//;
2458 if (length($title) > 50) {
2459 $title =~ s/kernel.org:?//;
2461 if (length($title) > 50) {
2462 $title =~ s/\/pub\/scm//;
2465 $co{'title_short'} = chop_str
($title, 50, 5);
2469 if (! defined $co{'title'} || $co{'title'} eq "") {
2470 $co{'title'} = $co{'title_short'} = '(no commit message)';
2472 # remove added spaces
2473 foreach my $line (@commit_lines) {
2476 $co{'comment'} = \
@commit_lines;
2478 my $age = time - $co{'committer_epoch'};
2480 $co{'age_string'} = age_string
($age);
2481 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2482 if ($age > 60*60*24*7*2) {
2483 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2484 $co{'age_string_age'} = $co{'age_string'};
2486 $co{'age_string_date'} = $co{'age_string'};
2487 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2493 my ($commit_id) = @_;
2498 open my $fd, "-|", git_cmd
(), "rev-list",
2504 or die_error
(500, "Open git-rev-list failed");
2505 %co = parse_commit_text
(<$fd>, 1);
2512 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2520 open my $fd, "-|", git_cmd
(), "rev-list",
2523 ("--max-count=" . $maxcount),
2524 ("--skip=" . $skip),
2528 ($filename ?
($filename) : ())
2529 or die_error
(500, "Open git-rev-list failed");
2530 while (my $line = <$fd>) {
2531 my %co = parse_commit_text
($line);
2536 return wantarray ?
@cos : \
@cos;
2539 # parse line of git-diff-tree "raw" output
2540 sub parse_difftree_raw_line
{
2544 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2545 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2546 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2547 $res{'from_mode'} = $1;
2548 $res{'to_mode'} = $2;
2549 $res{'from_id'} = $3;
2551 $res{'status'} = $5;
2552 $res{'similarity'} = $6;
2553 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2554 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2556 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2559 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2560 # combined diff (for merge commit)
2561 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2562 $res{'nparents'} = length($1);
2563 $res{'from_mode'} = [ split(' ', $2) ];
2564 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2565 $res{'from_id'} = [ split(' ', $3) ];
2566 $res{'to_id'} = pop @
{$res{'from_id'}};
2567 $res{'status'} = [ split('', $4) ];
2568 $res{'to_file'} = unquote
($5);
2570 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2571 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2572 $res{'commit'} = $1;
2575 return wantarray ?
%res : \
%res;
2578 # wrapper: return parsed line of git-diff-tree "raw" output
2579 # (the argument might be raw line, or parsed info)
2580 sub parsed_difftree_line
{
2581 my $line_or_ref = shift;
2583 if (ref($line_or_ref) eq "HASH") {
2584 # pre-parsed (or generated by hand)
2585 return $line_or_ref;
2587 return parse_difftree_raw_line
($line_or_ref);
2591 # parse line of git-ls-tree output
2592 sub parse_ls_tree_line
($;%) {
2597 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2598 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2606 $res{'name'} = unquote
($4);
2609 return wantarray ?
%res : \
%res;
2612 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2613 sub parse_from_to_diffinfo
{
2614 my ($diffinfo, $from, $to, @parents) = @_;
2616 if ($diffinfo->{'nparents'}) {
2618 $from->{'file'} = [];
2619 $from->{'href'} = [];
2620 fill_from_file_info
($diffinfo, @parents)
2621 unless exists $diffinfo->{'from_file'};
2622 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2623 $from->{'file'}[$i] =
2624 defined $diffinfo->{'from_file'}[$i] ?
2625 $diffinfo->{'from_file'}[$i] :
2626 $diffinfo->{'to_file'};
2627 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2628 $from->{'href'}[$i] = href
(action
=>"blob",
2629 hash_base
=>$parents[$i],
2630 hash
=>$diffinfo->{'from_id'}[$i],
2631 file_name
=>$from->{'file'}[$i]);
2633 $from->{'href'}[$i] = undef;
2637 # ordinary (not combined) diff
2638 $from->{'file'} = $diffinfo->{'from_file'};
2639 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2640 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2641 hash
=>$diffinfo->{'from_id'},
2642 file_name
=>$from->{'file'});
2644 delete $from->{'href'};
2648 $to->{'file'} = $diffinfo->{'to_file'};
2649 if (!is_deleted
($diffinfo)) { # file exists in result
2650 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2651 hash
=>$diffinfo->{'to_id'},
2652 file_name
=>$to->{'file'});
2654 delete $to->{'href'};
2658 ## ......................................................................
2659 ## parse to array of hashes functions
2661 sub git_get_heads_list
{
2665 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2666 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2667 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2670 while (my $line = <$fd>) {
2674 my ($refinfo, $committerinfo) = split(/\0/, $line);
2675 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2676 my ($committer, $epoch, $tz) =
2677 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2678 $ref_item{'fullname'} = $name;
2679 $name =~ s!^refs/heads/!!;
2681 $ref_item{'name'} = $name;
2682 $ref_item{'id'} = $hash;
2683 $ref_item{'title'} = $title || '(no commit message)';
2684 $ref_item{'epoch'} = $epoch;
2686 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2688 $ref_item{'age'} = "unknown";
2691 push @headslist, \
%ref_item;
2695 return wantarray ?
@headslist : \
@headslist;
2698 sub git_get_tags_list
{
2702 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2703 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2704 '--format=%(objectname) %(objecttype) %(refname) '.
2705 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2708 while (my $line = <$fd>) {
2712 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2713 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2714 my ($creator, $epoch, $tz) =
2715 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2716 $ref_item{'fullname'} = $name;
2717 $name =~ s!^refs/tags/!!;
2719 $ref_item{'type'} = $type;
2720 $ref_item{'id'} = $id;
2721 $ref_item{'name'} = $name;
2722 if ($type eq "tag") {
2723 $ref_item{'subject'} = $title;
2724 $ref_item{'reftype'} = $reftype;
2725 $ref_item{'refid'} = $refid;
2727 $ref_item{'reftype'} = $type;
2728 $ref_item{'refid'} = $id;
2731 if ($type eq "tag" || $type eq "commit") {
2732 $ref_item{'epoch'} = $epoch;
2734 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2736 $ref_item{'age'} = "unknown";
2740 push @tagslist, \
%ref_item;
2744 return wantarray ?
@tagslist : \
@tagslist;
2747 ## ----------------------------------------------------------------------
2748 ## filesystem-related functions
2750 sub get_file_owner
{
2753 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2754 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2755 if (!defined $gcos) {
2759 $owner =~ s/[,;].*$//;
2760 return to_utf8
($owner);
2763 # assume that file exists
2765 my $filename = shift;
2767 open my $fd, '<', $filename;
2768 print map { to_utf8
($_) } <$fd>;
2772 ## ......................................................................
2773 ## mimetype related functions
2775 sub mimetype_guess_file
{
2776 my $filename = shift;
2777 my $mimemap = shift;
2778 -r
$mimemap or return undef;
2781 open(MIME
, $mimemap) or return undef;
2783 next if m/^#/; # skip comments
2784 my ($mime, $exts) = split(/\t+/);
2785 if (defined $exts) {
2786 my @exts = split(/\s+/, $exts);
2787 foreach my $ext (@exts) {
2788 $mimemap{$ext} = $mime;
2794 $filename =~ /\.([^.]*)$/;
2795 return $mimemap{$1};
2798 sub mimetype_guess
{
2799 my $filename = shift;
2801 $filename =~ /\./ or return undef;
2803 if ($mimetypes_file) {
2804 my $file = $mimetypes_file;
2805 if ($file !~ m!^/!) { # if it is relative path
2806 # it is relative to project
2807 $file = "$projectroot/$project/$file";
2809 $mime = mimetype_guess_file
($filename, $file);
2811 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2817 my $filename = shift;
2820 my $mime = mimetype_guess
($filename);
2821 $mime and return $mime;
2825 return $default_blob_plain_mimetype unless $fd;
2828 return 'text/plain';
2829 } elsif (! $filename) {
2830 return 'application/octet-stream';
2831 } elsif ($filename =~ m/\.png$/i) {
2833 } elsif ($filename =~ m/\.gif$/i) {
2835 } elsif ($filename =~ m/\.jpe?g$/i) {
2836 return 'image/jpeg';
2838 return 'application/octet-stream';
2842 sub blob_contenttype
{
2843 my ($fd, $file_name, $type) = @_;
2845 $type ||= blob_mimetype
($fd, $file_name);
2846 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2847 $type .= "; charset=$default_text_plain_charset";
2853 ## ======================================================================
2854 ## functions printing HTML: header, footer, error page
2856 sub git_header_html
{
2857 my $status = shift || "200 OK";
2858 my $expires = shift;
2860 my $title = "$site_name";
2861 if (defined $project) {
2862 $title .= " - " . to_utf8
($project);
2863 if (defined $action) {
2864 $title .= "/$action";
2865 if (defined $file_name) {
2866 $title .= " - " . esc_path
($file_name);
2867 if ($action eq "tree" && $file_name !~ m
|/$|) {
2874 # require explicit support from the UA if we are to send the page as
2875 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2876 # we have to do this because MSIE sometimes globs '*/*', pretending to
2877 # support xhtml+xml but choking when it gets what it asked for.
2878 if (defined $cgi->http('HTTP_ACCEPT') &&
2879 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2880 $cgi->Accept('application/xhtml+xml') != 0) {
2881 $content_type = 'application/xhtml+xml';
2883 $content_type = 'text/html';
2885 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2886 -status
=> $status, -expires
=> $expires);
2887 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2889 <?xml version="1.0" encoding="utf-8"?>
2890 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2891 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2892 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2893 <!-- git core binaries version $git_version -->
2895 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2896 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2897 <meta name="robots" content="index, nofollow"/>
2898 <title>$title</title>
2900 # print out each stylesheet that exist
2901 if (defined $stylesheet) {
2902 #provides backwards capability for those people who define style sheet in a config file
2903 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2905 foreach my $stylesheet (@stylesheets) {
2906 next unless $stylesheet;
2907 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2910 if (defined $project) {
2911 my %href_params = get_feed_info
();
2912 if (!exists $href_params{'-title'}) {
2913 $href_params{'-title'} = 'log';
2916 foreach my $format qw(RSS Atom) {
2917 my $type = lc($format);
2919 '-rel' => 'alternate',
2920 '-title' => "$project - $href_params{'-title'} - $format feed",
2921 '-type' => "application/$type+xml"
2924 $href_params{'action'} = $type;
2925 $link_attr{'-href'} = href
(%href_params);
2927 "rel=\"$link_attr{'-rel'}\" ".
2928 "title=\"$link_attr{'-title'}\" ".
2929 "href=\"$link_attr{'-href'}\" ".
2930 "type=\"$link_attr{'-type'}\" ".
2933 $href_params{'extra_options'} = '--no-merges';
2934 $link_attr{'-href'} = href
(%href_params);
2935 $link_attr{'-title'} .= ' (no merges)';
2937 "rel=\"$link_attr{'-rel'}\" ".
2938 "title=\"$link_attr{'-title'}\" ".
2939 "href=\"$link_attr{'-href'}\" ".
2940 "type=\"$link_attr{'-type'}\" ".
2945 printf('<link rel="alternate" title="%s projects list" '.
2946 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2947 $site_name, href
(project
=>undef, action
=>"project_index"));
2948 printf('<link rel="alternate" title="%s projects feeds" '.
2949 'href="%s" type="text/x-opml" />'."\n",
2950 $site_name, href
(project
=>undef, action
=>"opml"));
2952 if (defined $favicon) {
2953 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2959 if (-f
$site_header) {
2960 insert_file
($site_header);
2963 print "<div class=\"page_header\">\n" .
2964 $cgi->a({-href
=> esc_url
($logo_url),
2965 -title
=> $logo_label},
2966 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2967 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2968 if (defined $project) {
2969 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2970 if (defined $action) {
2977 my $have_search = gitweb_check_feature
('search');
2978 if (defined $project && $have_search) {
2979 if (!defined $searchtext) {
2983 if (defined $hash_base) {
2984 $search_hash = $hash_base;
2985 } elsif (defined $hash) {
2986 $search_hash = $hash;
2988 $search_hash = "HEAD";
2990 my $action = $my_uri;
2991 my $use_pathinfo = gitweb_check_feature
('pathinfo');
2992 if ($use_pathinfo) {
2993 $action .= "/".esc_url
($project);
2995 print $cgi->startform(-method
=> "get", -action
=> $action) .
2996 "<div class=\"search\">\n" .
2998 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2999 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3000 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3001 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3002 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3003 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3005 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3006 "<span title=\"Extended regular expression\">" .
3007 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3008 -checked
=> $search_use_regexp) .
3011 $cgi->end_form() . "\n";
3015 sub git_footer_html
{
3016 my $feed_class = 'rss_logo';
3018 print "<div class=\"page_footer\">\n";
3019 if (defined $project) {
3020 my $descr = git_get_project_description
($project);
3021 if (defined $descr) {
3022 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3025 my %href_params = get_feed_info
();
3026 if (!%href_params) {
3027 $feed_class .= ' generic';
3029 $href_params{'-title'} ||= 'log';
3031 foreach my $format qw(RSS Atom) {
3032 $href_params{'action'} = lc($format);
3033 print $cgi->a({-href
=> href
(%href_params),
3034 -title
=> "$href_params{'-title'} $format feed",
3035 -class => $feed_class}, $format)."\n";
3039 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3040 -class => $feed_class}, "OPML") . " ";
3041 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3042 -class => $feed_class}, "TXT") . "\n";
3044 print "</div>\n"; # class="page_footer"
3046 if (-f
$site_footer) {
3047 insert_file
($site_footer);
3054 # die_error(<http_status_code>, <error_message>)
3055 # Example: die_error(404, 'Hash not found')
3056 # By convention, use the following status codes (as defined in RFC 2616):
3057 # 400: Invalid or missing CGI parameters, or
3058 # requested object exists but has wrong type.
3059 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3060 # this server or project.
3061 # 404: Requested object/revision/project doesn't exist.
3062 # 500: The server isn't configured properly, or
3063 # an internal error occurred (e.g. failed assertions caused by bugs), or
3064 # an unknown error occurred (e.g. the git binary died unexpectedly).
3066 my $status = shift || 500;
3067 my $error = shift || "Internal server error";
3069 my %http_responses = (400 => '400 Bad Request',
3070 403 => '403 Forbidden',
3071 404 => '404 Not Found',
3072 500 => '500 Internal Server Error');
3073 git_header_html
($http_responses{$status});
3075 <div class="page_body">
3085 ## ----------------------------------------------------------------------
3086 ## functions printing or outputting HTML: navigation
3088 sub git_print_page_nav
{
3089 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3090 $extra = '' if !defined $extra; # pager or formats
3092 my @navs = qw(summary shortlog log commit commitdiff tree);
3094 @navs = grep { $_ ne $suppress } @navs;
3097 my %arg = map { $_ => {action
=>$_} } @navs;
3098 if (defined $head) {
3099 for (qw(commit commitdiff)) {
3100 $arg{$_}{'hash'} = $head;
3102 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3103 for (qw(shortlog log)) {
3104 $arg{$_}{'hash'} = $head;
3109 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3110 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3112 my @actions = gitweb_get_feature
('actions');
3115 'n' => $project, # project name
3116 'f' => $git_dir, # project path within filesystem
3117 'h' => $treehead || '', # current hash ('h' parameter)
3118 'b' => $treebase || '', # hash base ('hb' parameter)
3121 my ($label, $link, $pos) = splice(@actions,0,3);
3123 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3125 $link =~ s/%([%nfhb])/$repl{$1}/g;
3126 $arg{$label}{'_href'} = $link;
3129 print "<div class=\"page_nav\">\n" .
3131 map { $_ eq $current ?
3132 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3134 print "<br/>\n$extra<br/>\n" .
3138 sub format_paging_nav
{
3139 my ($action, $hash, $head, $page, $has_next_link) = @_;
3143 if ($hash ne $head || $page) {
3144 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3146 $paging_nav .= "HEAD";
3150 $paging_nav .= " ⋅ " .
3151 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3152 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3154 $paging_nav .= " ⋅ prev";
3157 if ($has_next_link) {
3158 $paging_nav .= " ⋅ " .
3159 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3160 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3162 $paging_nav .= " ⋅ next";
3168 ## ......................................................................
3169 ## functions printing or outputting HTML: div
3171 sub git_print_header_div
{
3172 my ($action, $title, $hash, $hash_base) = @_;
3175 $args{'action'} = $action;
3176 $args{'hash'} = $hash if $hash;
3177 $args{'hash_base'} = $hash_base if $hash_base;
3179 print "<div class=\"header\">\n" .
3180 $cgi->a({-href
=> href
(%args), -class => "title"},
3181 $title ?
$title : $action) .
3185 #sub git_print_authorship (\%) {
3186 sub git_print_authorship
{
3189 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3190 print "<div class=\"author_date\">" .
3191 esc_html
($co->{'author_name'}) .
3193 if ($ad{'hour_local'} < 6) {
3194 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3195 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3197 printf(" (%02d:%02d %s)",
3198 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3203 sub git_print_page_path
{
3209 print "<div class=\"page_path\">";
3210 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3211 -title
=> 'tree root'}, to_utf8
("[$project]"));
3213 if (defined $name) {
3214 my @dirname = split '/', $name;
3215 my $basename = pop @dirname;
3218 foreach my $dir (@dirname) {
3219 $fullname .= ($fullname ?
'/' : '') . $dir;
3220 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3222 -title
=> $fullname}, esc_path
($dir));
3225 if (defined $type && $type eq 'blob') {
3226 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3228 -title
=> $name}, esc_path
($basename));
3229 } elsif (defined $type && $type eq 'tree') {
3230 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3232 -title
=> $name}, esc_path
($basename));
3235 print esc_path
($basename);
3238 print "<br/></div>\n";
3241 # sub git_print_log (\@;%) {
3242 sub git_print_log
($;%) {
3246 if ($opts{'-remove_title'}) {
3247 # remove title, i.e. first line of log
3250 # remove leading empty lines
3251 while (defined $log->[0] && $log->[0] eq "") {
3258 foreach my $line (@
$log) {
3259 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3262 if (! $opts{'-remove_signoff'}) {
3263 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3266 # remove signoff lines
3273 # print only one empty line
3274 # do not print empty line after signoff
3276 next if ($empty || $signoff);
3282 print format_log_line_html
($line) . "<br/>\n";
3285 if ($opts{'-final_empty_line'}) {
3286 # end with single empty line
3287 print "<br/>\n" unless $empty;
3291 # return link target (what link points to)
3292 sub git_get_link_target
{
3297 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3301 $link_target = <$fd>;
3306 return $link_target;
3309 # given link target, and the directory (basedir) the link is in,
3310 # return target of link relative to top directory (top tree);
3311 # return undef if it is not possible (including absolute links).
3312 sub normalize_link_target
{
3313 my ($link_target, $basedir, $hash_base) = @_;
3315 # we can normalize symlink target only if $hash_base is provided
3316 return unless $hash_base;
3318 # absolute symlinks (beginning with '/') cannot be normalized
3319 return if (substr($link_target, 0, 1) eq '/');
3321 # normalize link target to path from top (root) tree (dir)
3324 $path = $basedir . '/' . $link_target;
3326 # we are in top (root) tree (dir)
3327 $path = $link_target;
3330 # remove //, /./, and /../
3332 foreach my $part (split('/', $path)) {
3333 # discard '.' and ''
3334 next if (!$part || $part eq '.');
3336 if ($part eq '..') {
3340 # link leads outside repository (outside top dir)
3344 push @path_parts, $part;
3347 $path = join('/', @path_parts);
3352 # print tree entry (row of git_tree), but without encompassing <tr> element
3353 sub git_print_tree_entry
{
3354 my ($t, $basedir, $hash_base, $have_blame) = @_;
3357 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3359 # The format of a table row is: mode list link. Where mode is
3360 # the mode of the entry, list is the name of the entry, an href,
3361 # and link is the action links of the entry.
3363 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3364 if ($t->{'type'} eq "blob") {
3365 print "<td class=\"list\">" .
3366 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3367 file_name
=>"$basedir$t->{'name'}", %base_key),
3368 -class => "list"}, esc_path
($t->{'name'}));
3369 if (S_ISLNK
(oct $t->{'mode'})) {
3370 my $link_target = git_get_link_target
($t->{'hash'});
3372 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3373 if (defined $norm_target) {
3375 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3376 file_name
=>$norm_target),
3377 -title
=> $norm_target}, esc_path
($link_target));
3379 print " -> " . esc_path
($link_target);
3384 print "<td class=\"link\">";
3385 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3386 file_name
=>"$basedir$t->{'name'}", %base_key)},
3390 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3391 file_name
=>"$basedir$t->{'name'}", %base_key)},
3394 if (defined $hash_base) {
3396 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3397 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3401 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3402 file_name
=>"$basedir$t->{'name'}")},
3406 } elsif ($t->{'type'} eq "tree") {
3407 print "<td class=\"list\">";
3408 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3409 file_name
=>"$basedir$t->{'name'}", %base_key)},
3410 esc_path
($t->{'name'}));
3412 print "<td class=\"link\">";
3413 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3414 file_name
=>"$basedir$t->{'name'}", %base_key)},
3416 if (defined $hash_base) {
3418 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3419 file_name
=>"$basedir$t->{'name'}")},
3424 # unknown object: we can only present history for it
3425 # (this includes 'commit' object, i.e. submodule support)
3426 print "<td class=\"list\">" .
3427 esc_path
($t->{'name'}) .
3429 print "<td class=\"link\">";
3430 if (defined $hash_base) {
3431 print $cgi->a({-href
=> href
(action
=>"history",
3432 hash_base
=>$hash_base,
3433 file_name
=>"$basedir$t->{'name'}")},
3440 ## ......................................................................
3441 ## functions printing large fragments of HTML
3443 # get pre-image filenames for merge (combined) diff
3444 sub fill_from_file_info
{
3445 my ($diff, @parents) = @_;
3447 $diff->{'from_file'} = [ ];
3448 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3449 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3450 if ($diff->{'status'}[$i] eq 'R' ||
3451 $diff->{'status'}[$i] eq 'C') {
3452 $diff->{'from_file'}[$i] =
3453 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3460 # is current raw difftree line of file deletion
3462 my $diffinfo = shift;
3464 return $diffinfo->{'to_id'} eq ('0' x
40);
3467 # does patch correspond to [previous] difftree raw line
3468 # $diffinfo - hashref of parsed raw diff format
3469 # $patchinfo - hashref of parsed patch diff format
3470 # (the same keys as in $diffinfo)
3471 sub is_patch_split
{
3472 my ($diffinfo, $patchinfo) = @_;
3474 return defined $diffinfo && defined $patchinfo
3475 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3479 sub git_difftree_body
{
3480 my ($difftree, $hash, @parents) = @_;
3481 my ($parent) = $parents[0];
3482 my $have_blame = gitweb_check_feature
('blame');
3483 print "<div class=\"list_head\">\n";
3484 if ($#{$difftree} > 10) {
3485 print(($#{$difftree} + 1) . " files changed:\n");
3489 print "<table class=\"" .
3490 (@parents > 1 ?
"combined " : "") .
3493 # header only for combined diff in 'commitdiff' view
3494 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3497 print "<thead><tr>\n" .
3498 "<th></th><th></th>\n"; # filename, patchN link
3499 for (my $i = 0; $i < @parents; $i++) {
3500 my $par = $parents[$i];
3502 $cgi->a({-href
=> href
(action
=>"commitdiff",
3503 hash
=>$hash, hash_parent
=>$par),
3504 -title
=> 'commitdiff to parent number ' .
3505 ($i+1) . ': ' . substr($par,0,7)},
3509 print "</tr></thead>\n<tbody>\n";
3514 foreach my $line (@
{$difftree}) {
3515 my $diff = parsed_difftree_line
($line);
3518 print "<tr class=\"dark\">\n";
3520 print "<tr class=\"light\">\n";
3524 if (exists $diff->{'nparents'}) { # combined diff
3526 fill_from_file_info
($diff, @parents)
3527 unless exists $diff->{'from_file'};
3529 if (!is_deleted
($diff)) {
3530 # file exists in the result (child) commit
3532 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3533 file_name
=>$diff->{'to_file'},
3535 -class => "list"}, esc_path
($diff->{'to_file'})) .
3539 esc_path
($diff->{'to_file'}) .
3543 if ($action eq 'commitdiff') {
3546 print "<td class=\"link\">" .
3547 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3552 my $has_history = 0;
3553 my $not_deleted = 0;
3554 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3555 my $hash_parent = $parents[$i];
3556 my $from_hash = $diff->{'from_id'}[$i];
3557 my $from_path = $diff->{'from_file'}[$i];
3558 my $status = $diff->{'status'}[$i];
3560 $has_history ||= ($status ne 'A');
3561 $not_deleted ||= ($status ne 'D');
3563 if ($status eq 'A') {
3564 print "<td class=\"link\" align=\"right\"> | </td>\n";
3565 } elsif ($status eq 'D') {
3566 print "<td class=\"link\">" .
3567 $cgi->a({-href
=> href
(action
=>"blob",
3570 file_name
=>$from_path)},
3574 if ($diff->{'to_id'} eq $from_hash) {
3575 print "<td class=\"link nochange\">";
3577 print "<td class=\"link\">";
3579 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3580 hash
=>$diff->{'to_id'},
3581 hash_parent
=>$from_hash,
3583 hash_parent_base
=>$hash_parent,
3584 file_name
=>$diff->{'to_file'},
3585 file_parent
=>$from_path)},
3591 print "<td class=\"link\">";
3593 print $cgi->a({-href
=> href
(action
=>"blob",
3594 hash
=>$diff->{'to_id'},
3595 file_name
=>$diff->{'to_file'},
3598 print " | " if ($has_history);
3601 print $cgi->a({-href
=> href
(action
=>"history",
3602 file_name
=>$diff->{'to_file'},
3609 next; # instead of 'else' clause, to avoid extra indent
3611 # else ordinary diff
3613 my ($to_mode_oct, $to_mode_str, $to_file_type);
3614 my ($from_mode_oct, $from_mode_str, $from_file_type);
3615 if ($diff->{'to_mode'} ne ('0' x
6)) {
3616 $to_mode_oct = oct $diff->{'to_mode'};
3617 if (S_ISREG
($to_mode_oct)) { # only for regular file
3618 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3620 $to_file_type = file_type
($diff->{'to_mode'});
3622 if ($diff->{'from_mode'} ne ('0' x
6)) {
3623 $from_mode_oct = oct $diff->{'from_mode'};
3624 if (S_ISREG
($to_mode_oct)) { # only for regular file
3625 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3627 $from_file_type = file_type
($diff->{'from_mode'});
3630 if ($diff->{'status'} eq "A") { # created
3631 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3632 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3633 $mode_chng .= "]</span>";
3635 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3636 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3637 -class => "list"}, esc_path
($diff->{'file'}));
3639 print "<td>$mode_chng</td>\n";
3640 print "<td class=\"link\">";
3641 if ($action eq 'commitdiff') {
3644 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3647 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3648 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3652 } elsif ($diff->{'status'} eq "D") { # deleted
3653 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3655 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3656 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3657 -class => "list"}, esc_path
($diff->{'file'}));
3659 print "<td>$mode_chng</td>\n";
3660 print "<td class=\"link\">";
3661 if ($action eq 'commitdiff') {
3664 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3667 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3668 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3671 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3672 file_name
=>$diff->{'file'})},
3675 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3676 file_name
=>$diff->{'file'})},
3680 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3681 my $mode_chnge = "";
3682 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3683 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3684 if ($from_file_type ne $to_file_type) {
3685 $mode_chnge .= " from $from_file_type to $to_file_type";
3687 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3688 if ($from_mode_str && $to_mode_str) {
3689 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3690 } elsif ($to_mode_str) {
3691 $mode_chnge .= " mode: $to_mode_str";
3694 $mode_chnge .= "]</span>\n";
3697 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3698 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3699 -class => "list"}, esc_path
($diff->{'file'}));
3701 print "<td>$mode_chnge</td>\n";
3702 print "<td class=\"link\">";
3703 if ($action eq 'commitdiff') {
3706 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3708 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3709 # "commit" view and modified file (not onlu mode changed)
3710 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3711 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3712 hash_base
=>$hash, hash_parent_base
=>$parent,
3713 file_name
=>$diff->{'file'})},
3717 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3718 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3721 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3722 file_name
=>$diff->{'file'})},
3725 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3726 file_name
=>$diff->{'file'})},
3730 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3731 my %status_name = ('R' => 'moved', 'C' => 'copied');
3732 my $nstatus = $status_name{$diff->{'status'}};
3734 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3735 # mode also for directories, so we cannot use $to_mode_str
3736 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3739 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3740 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3741 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3742 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3743 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3744 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3745 -class => "list"}, esc_path
($diff->{'from_file'})) .
3746 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3747 "<td class=\"link\">";
3748 if ($action eq 'commitdiff') {
3751 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3753 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3754 # "commit" view and modified file (not only pure rename or copy)
3755 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3756 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3757 hash_base
=>$hash, hash_parent_base
=>$parent,
3758 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3762 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3763 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3766 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3767 file_name
=>$diff->{'to_file'})},
3770 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3771 file_name
=>$diff->{'to_file'})},
3775 } # we should not encounter Unmerged (U) or Unknown (X) status
3778 print "</tbody>" if $has_header;
3782 sub git_patchset_body
{
3783 my ($fd, $difftree, $hash, @hash_parents) = @_;
3784 my ($hash_parent) = $hash_parents[0];
3786 my $is_combined = (@hash_parents > 1);
3788 my $patch_number = 0;
3794 print "<div class=\"patchset\">\n";
3796 # skip to first patch
3797 while ($patch_line = <$fd>) {
3800 last if ($patch_line =~ m/^diff /);
3804 while ($patch_line) {
3806 # parse "git diff" header line
3807 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3808 # $1 is from_name, which we do not use
3809 $to_name = unquote
($2);
3810 $to_name =~ s!^b/!!;
3811 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3812 # $1 is 'cc' or 'combined', which we do not use
3813 $to_name = unquote
($2);
3818 # check if current patch belong to current raw line
3819 # and parse raw git-diff line if needed
3820 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3821 # this is continuation of a split patch
3822 print "<div class=\"patch cont\">\n";
3824 # advance raw git-diff output if needed
3825 $patch_idx++ if defined $diffinfo;
3827 # read and prepare patch information
3828 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3830 # compact combined diff output can have some patches skipped
3831 # find which patch (using pathname of result) we are at now;
3833 while ($to_name ne $diffinfo->{'to_file'}) {
3834 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3835 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3836 "</div>\n"; # class="patch"
3841 last if $patch_idx > $#$difftree;
3842 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3846 # modifies %from, %to hashes
3847 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3849 # this is first patch for raw difftree line with $patch_idx index
3850 # we index @$difftree array from 0, but number patches from 1
3851 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3855 #assert($patch_line =~ m/^diff /) if DEBUG;
3856 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3858 # print "git diff" header
3859 print format_git_diff_header_line
($patch_line, $diffinfo,
3862 # print extended diff header
3863 print "<div class=\"diff extended_header\">\n";
3865 while ($patch_line = <$fd>) {
3868 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3870 print format_extended_diff_header_line
($patch_line, $diffinfo,
3873 print "</div>\n"; # class="diff extended_header"
3875 # from-file/to-file diff header
3876 if (! $patch_line) {
3877 print "</div>\n"; # class="patch"
3880 next PATCH
if ($patch_line =~ m/^diff /);
3881 #assert($patch_line =~ m/^---/) if DEBUG;
3883 my $last_patch_line = $patch_line;
3884 $patch_line = <$fd>;
3886 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3888 print format_diff_from_to_header
($last_patch_line, $patch_line,
3889 $diffinfo, \
%from, \
%to,
3894 while ($patch_line = <$fd>) {
3897 next PATCH
if ($patch_line =~ m/^diff /);
3899 print format_diff_line
($patch_line, \
%from, \
%to);
3903 print "</div>\n"; # class="patch"
3906 # for compact combined (--cc) format, with chunk and patch simpliciaction
3907 # patchset might be empty, but there might be unprocessed raw lines
3908 for (++$patch_idx if $patch_number > 0;
3909 $patch_idx < @
$difftree;
3911 # read and prepare patch information
3912 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3914 # generate anchor for "patch" links in difftree / whatchanged part
3915 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3916 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3917 "</div>\n"; # class="patch"
3922 if ($patch_number == 0) {
3923 if (@hash_parents > 1) {
3924 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3926 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3930 print "</div>\n"; # class="patchset"
3933 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3935 # fills project list info (age, description, owner, forks) for each
3936 # project in the list, removing invalid projects from returned list
3937 # NOTE: modifies $projlist, but does not remove entries from it
3938 sub fill_project_list_info
{
3939 my ($projlist, $check_forks) = @_;
3942 my $show_ctags = gitweb_check_feature
('ctags');
3944 foreach my $pr (@
$projlist) {
3945 my (@activity) = git_get_last_activity
($pr->{'path'});
3946 unless (@activity) {
3949 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3950 if (!defined $pr->{'descr'}) {
3951 my $descr = git_get_project_description
($pr->{'path'}) || "";
3952 $descr = to_utf8
($descr);
3953 $pr->{'descr_long'} = $descr;
3954 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3956 if (!defined $pr->{'owner'}) {
3957 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3960 my $pname = $pr->{'path'};
3961 if (($pname =~ s/\.git$//) &&
3962 ($pname !~ /\/$/) &&
3963 (-d
"$projectroot/$pname")) {
3964 $pr->{'forks'} = "-d $projectroot/$pname";
3969 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3970 push @projects, $pr;
3976 # print 'sort by' <th> element, generating 'sort by $name' replay link
3977 # if that order is not selected
3979 my ($name, $order, $header) = @_;
3980 $header ||= ucfirst($name);
3982 if ($order eq $name) {
3983 print "<th>$header</th>\n";
3986 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3987 -class => "header"}, $header) .
3992 sub git_project_list_body
{
3993 # actually uses global variable $project
3994 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3996 my $check_forks = gitweb_check_feature
('forks');
3997 my @projects = fill_project_list_info
($projlist, $check_forks);
3999 $order ||= $default_projects_order;
4000 $from = 0 unless defined $from;
4001 $to = $#projects if (!defined $to || $#projects < $to);
4004 project
=> { key
=> 'path', type
=> 'str' },
4005 descr
=> { key
=> 'descr_long', type
=> 'str' },
4006 owner
=> { key
=> 'owner', type
=> 'str' },
4007 age
=> { key
=> 'age', type
=> 'num' }
4009 my $oi = $order_info{$order};
4010 if ($oi->{'type'} eq 'str') {
4011 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4013 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4016 my $show_ctags = gitweb_check_feature
('ctags');
4019 foreach my $p (@projects) {
4020 foreach my $ct (keys %{$p->{'ctags'}}) {
4021 $ctags{$ct} += $p->{'ctags'}->{$ct};
4024 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4025 print git_show_project_tagcloud
($cloud, 64);
4028 print "<table class=\"project_list\">\n";
4029 unless ($no_header) {
4032 print "<th></th>\n";
4034 print_sort_th
('project', $order, 'Project');
4035 print_sort_th
('descr', $order, 'Description');
4036 print_sort_th
('owner', $order, 'Owner');
4037 print_sort_th
('age', $order, 'Last Change');
4038 print "<th></th>\n" . # for links
4042 my $tagfilter = $cgi->param('by_tag');
4043 for (my $i = $from; $i <= $to; $i++) {
4044 my $pr = $projects[$i];
4046 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4047 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4048 and not $pr->{'descr_long'} =~ /$searchtext/;
4049 # Weed out forks or non-matching entries of search
4051 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4052 $forkbase="^$forkbase" if $forkbase;
4053 next if not $searchtext and not $tagfilter and $show_ctags
4054 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4058 print "<tr class=\"dark\">\n";
4060 print "<tr class=\"light\">\n";
4065 if ($pr->{'forks'}) {
4066 print "<!-- $pr->{'forks'} -->\n";
4067 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4071 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4072 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4073 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4074 -class => "list", -title
=> $pr->{'descr_long'}},
4075 esc_html
($pr->{'descr'})) . "</td>\n" .
4076 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4077 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4078 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4079 "<td class=\"link\">" .
4080 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4081 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4082 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4083 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4084 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4088 if (defined $extra) {
4091 print "<td></td>\n";
4093 print "<td colspan=\"5\">$extra</td>\n" .
4099 sub git_shortlog_body
{
4100 # uses global variable $project
4101 my ($commitlist, $from, $to, $refs, $extra) = @_;
4103 $from = 0 unless defined $from;
4104 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4106 print "<table class=\"shortlog\">\n";
4108 for (my $i = $from; $i <= $to; $i++) {
4109 my %co = %{$commitlist->[$i]};
4110 my $commit = $co{'id'};
4111 my $ref = format_ref_marker
($refs, $commit);
4113 print "<tr class=\"dark\">\n";
4115 print "<tr class=\"light\">\n";
4118 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4119 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4120 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4121 "<td><i>" . $author . "</i></td>\n" .
4123 print format_subject_html
($co{'title'}, $co{'title_short'},
4124 href
(action
=>"commit", hash
=>$commit), $ref);
4126 "<td class=\"link\">" .
4127 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4128 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4129 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4130 my $snapshot_links = format_snapshot_links
($commit);
4131 if (defined $snapshot_links) {
4132 print " | " . $snapshot_links;
4137 if (defined $extra) {
4139 "<td colspan=\"4\">$extra</td>\n" .
4145 sub git_history_body
{
4146 # Warning: assumes constant type (blob or tree) during history
4147 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4149 $from = 0 unless defined $from;
4150 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4152 print "<table class=\"history\">\n";
4154 for (my $i = $from; $i <= $to; $i++) {
4155 my %co = %{$commitlist->[$i]};
4159 my $commit = $co{'id'};
4161 my $ref = format_ref_marker
($refs, $commit);
4164 print "<tr class=\"dark\">\n";
4166 print "<tr class=\"light\">\n";
4169 # shortlog uses chop_str($co{'author_name'}, 10)
4170 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4171 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4172 "<td><i>" . $author . "</i></td>\n" .
4174 # originally git_history used chop_str($co{'title'}, 50)
4175 print format_subject_html
($co{'title'}, $co{'title_short'},
4176 href
(action
=>"commit", hash
=>$commit), $ref);
4178 "<td class=\"link\">" .
4179 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4180 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4182 if ($ftype eq 'blob') {
4183 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4184 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4185 if (defined $blob_current && defined $blob_parent &&
4186 $blob_current ne $blob_parent) {
4188 $cgi->a({-href
=> href
(action
=>"blobdiff",
4189 hash
=>$blob_current, hash_parent
=>$blob_parent,
4190 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4191 file_name
=>$file_name)},
4198 if (defined $extra) {
4200 "<td colspan=\"4\">$extra</td>\n" .
4207 # uses global variable $project
4208 my ($taglist, $from, $to, $extra) = @_;
4209 $from = 0 unless defined $from;
4210 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4212 print "<table class=\"tags\">\n";
4214 for (my $i = $from; $i <= $to; $i++) {
4215 my $entry = $taglist->[$i];
4217 my $comment = $tag{'subject'};
4219 if (defined $comment) {
4220 $comment_short = chop_str
($comment, 30, 5);
4223 print "<tr class=\"dark\">\n";
4225 print "<tr class=\"light\">\n";
4228 if (defined $tag{'age'}) {
4229 print "<td><i>$tag{'age'}</i></td>\n";
4231 print "<td></td>\n";
4234 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4235 -class => "list name"}, esc_html
($tag{'name'})) .
4238 if (defined $comment) {
4239 print format_subject_html
($comment, $comment_short,
4240 href
(action
=>"tag", hash
=>$tag{'id'}));
4243 "<td class=\"selflink\">";
4244 if ($tag{'type'} eq "tag") {
4245 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4250 "<td class=\"link\">" . " | " .
4251 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4252 if ($tag{'reftype'} eq "commit") {
4253 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4254 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4255 } elsif ($tag{'reftype'} eq "blob") {
4256 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4261 if (defined $extra) {
4263 "<td colspan=\"5\">$extra</td>\n" .
4269 sub git_heads_body
{
4270 # uses global variable $project
4271 my ($headlist, $head, $from, $to, $extra) = @_;
4272 $from = 0 unless defined $from;
4273 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4275 print "<table class=\"heads\">\n";
4277 for (my $i = $from; $i <= $to; $i++) {
4278 my $entry = $headlist->[$i];
4280 my $curr = $ref{'id'} eq $head;
4282 print "<tr class=\"dark\">\n";
4284 print "<tr class=\"light\">\n";
4287 print "<td><i>$ref{'age'}</i></td>\n" .
4288 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4289 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4290 -class => "list name"},esc_html
($ref{'name'})) .
4292 "<td class=\"link\">" .
4293 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4294 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4295 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4299 if (defined $extra) {
4301 "<td colspan=\"3\">$extra</td>\n" .
4307 sub git_search_grep_body
{
4308 my ($commitlist, $from, $to, $extra) = @_;
4309 $from = 0 unless defined $from;
4310 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4312 print "<table class=\"commit_search\">\n";
4314 for (my $i = $from; $i <= $to; $i++) {
4315 my %co = %{$commitlist->[$i]};
4319 my $commit = $co{'id'};
4321 print "<tr class=\"dark\">\n";
4323 print "<tr class=\"light\">\n";
4326 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4327 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4328 "<td><i>" . $author . "</i></td>\n" .
4330 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4331 -class => "list subject"},
4332 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4333 my $comment = $co{'comment'};
4334 foreach my $line (@
$comment) {
4335 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4336 my ($lead, $match, $trail) = ($1, $2, $3);
4337 $match = chop_str
($match, 70, 5, 'center');
4338 my $contextlen = int((80 - length($match))/2);
4339 $contextlen = 30 if ($contextlen > 30);
4340 $lead = chop_str
($lead, $contextlen, 10, 'left');
4341 $trail = chop_str
($trail, $contextlen, 10, 'right');
4343 $lead = esc_html
($lead);
4344 $match = esc_html
($match);
4345 $trail = esc_html
($trail);
4347 print "$lead<span class=\"match\">$match</span>$trail<br />";
4351 "<td class=\"link\">" .
4352 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4354 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4356 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4360 if (defined $extra) {
4362 "<td colspan=\"3\">$extra</td>\n" .
4368 ## ======================================================================
4369 ## ======================================================================
4372 sub git_project_list
{
4373 my $order = $input_params{'order'};
4374 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4375 die_error
(400, "Unknown order parameter");
4378 my @list = git_get_projects_list
();
4380 die_error
(404, "No projects found");
4384 if (-f
$home_text) {
4385 print "<div class=\"index_include\">\n";
4386 insert_file
($home_text);
4389 print $cgi->startform(-method
=> "get") .
4390 "<p class=\"projsearch\">Search:\n" .
4391 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4393 $cgi->end_form() . "\n";
4394 git_project_list_body
(\
@list, $order);
4399 my $order = $input_params{'order'};
4400 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4401 die_error
(400, "Unknown order parameter");
4404 my @list = git_get_projects_list
($project);
4406 die_error
(404, "No forks found");
4410 git_print_page_nav
('','');
4411 git_print_header_div
('summary', "$project forks");
4412 git_project_list_body
(\
@list, $order);
4416 sub git_project_index
{
4417 my @projects = git_get_projects_list
($project);
4420 -type
=> 'text/plain',
4421 -charset
=> 'utf-8',
4422 -content_disposition
=> 'inline; filename="index.aux"');
4424 foreach my $pr (@projects) {
4425 if (!exists $pr->{'owner'}) {
4426 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4429 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4430 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4431 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4432 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4436 print "$path $owner\n";
4441 my $descr = git_get_project_description
($project) || "none";
4442 my %co = parse_commit
("HEAD");
4443 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4444 my $head = $co{'id'};
4446 my $owner = git_get_project_owner
($project);
4448 my $refs = git_get_references
();
4449 # These get_*_list functions return one more to allow us to see if
4450 # there are more ...
4451 my @taglist = git_get_tags_list
(16);
4452 my @headlist = git_get_heads_list
(16);
4454 my $check_forks = gitweb_check_feature
('forks');
4457 @forklist = git_get_projects_list
($project);
4461 git_print_page_nav
('summary','', $head);
4463 print "<div class=\"title\"> </div>\n";
4464 print "<table class=\"projects_list\">\n" .
4465 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4466 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4467 if (defined $cd{'rfc2822'}) {
4468 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4471 # use per project git URL list in $projectroot/$project/cloneurl
4472 # or make project git URL from git base URL and project name
4473 my $url_tag = "URL";
4474 my @url_list = git_get_project_url_list
($project);
4475 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4476 foreach my $git_url (@url_list) {
4477 next unless $git_url;
4478 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4483 my $show_ctags = gitweb_check_feature
('ctags');
4485 my $ctags = git_get_project_ctags
($project);
4486 my $cloud = git_populate_project_tagcloud
($ctags);
4487 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4488 print "</td>\n<td>" unless %$ctags;
4489 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4490 print "</td>\n<td>" if %$ctags;
4491 print git_show_project_tagcloud
($cloud, 48);
4497 if (-s
"$projectroot/$project/README.html") {
4498 print "<div class=\"title\">readme</div>\n" .
4499 "<div class=\"readme\">\n";
4500 insert_file
("$projectroot/$project/README.html");
4501 print "\n</div>\n"; # class="readme"
4504 # we need to request one more than 16 (0..15) to check if
4506 my @commitlist = $head ? parse_commits
($head, 17) : ();
4508 git_print_header_div
('shortlog');
4509 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4510 $#commitlist <= 15 ?
undef :
4511 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4515 git_print_header_div
('tags');
4516 git_tags_body
(\
@taglist, 0, 15,
4517 $#taglist <= 15 ?
undef :
4518 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4522 git_print_header_div
('heads');
4523 git_heads_body
(\
@headlist, $head, 0, 15,
4524 $#headlist <= 15 ?
undef :
4525 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4529 git_print_header_div
('forks');
4530 git_project_list_body
(\
@forklist, 'age', 0, 15,
4531 $#forklist <= 15 ?
undef :
4532 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4540 my $head = git_get_head_hash
($project);
4542 git_print_page_nav
('','', $head,undef,$head);
4543 my %tag = parse_tag
($hash);
4546 die_error
(404, "Unknown tag object");
4549 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4550 print "<div class=\"title_text\">\n" .
4551 "<table class=\"object_header\">\n" .
4553 "<td>object</td>\n" .
4554 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4555 $tag{'object'}) . "</td>\n" .
4556 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4557 $tag{'type'}) . "</td>\n" .
4559 if (defined($tag{'author'})) {
4560 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4561 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4562 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4563 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4566 print "</table>\n\n" .
4568 print "<div class=\"page_body\">";
4569 my $comment = $tag{'comment'};
4570 foreach my $line (@
$comment) {
4572 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4582 gitweb_check_feature
('blame')
4583 or die_error
(403, "Blame view not allowed");
4585 die_error
(400, "No file name given") unless $file_name;
4586 $hash_base ||= git_get_head_hash
($project);
4587 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4588 my %co = parse_commit
($hash_base)
4589 or die_error
(404, "Commit not found");
4590 if (!defined $hash) {
4591 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4592 or die_error
(404, "Error looking up file");
4594 $ftype = git_get_type
($hash);
4595 if ($ftype !~ "blob") {
4596 die_error
(400, "Object is not a blob");
4598 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4599 $file_name, $hash_base)
4600 or die_error
(500, "Open git-blame failed");
4603 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4606 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4609 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4611 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4612 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4613 git_print_page_path
($file_name, $ftype, $hash_base);
4614 my @rev_color = (qw(light2 dark2));
4615 my $num_colors = scalar(@rev_color);
4616 my $current_color = 0;
4619 <div class="page_body">
4620 <table class="blame">
4621 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4626 last unless defined $_;
4627 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4628 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4629 if (!exists $metainfo{$full_rev}) {
4630 $metainfo{$full_rev} = {};
4632 my $meta = $metainfo{$full_rev};
4635 if (/^(\S+) (.*)$/) {
4641 my $rev = substr($full_rev, 0, 8);
4642 my $author = $meta->{'author'};
4643 my %date = parse_date
($meta->{'author-time'},
4644 $meta->{'author-tz'});
4645 my $date = $date{'iso-tz'};
4647 $current_color = ++$current_color % $num_colors;
4649 print "<tr class=\"$rev_color[$current_color]\">\n";
4651 print "<td class=\"sha1\"";
4652 print " title=\"". esc_html
($author) . ", $date\"";
4653 print " rowspan=\"$group_size\"" if ($group_size > 1);
4655 print $cgi->a({-href
=> href
(action
=>"commit",
4657 file_name
=>$file_name)},
4661 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4662 or die_error
(500, "Open git-rev-parse failed");
4663 my $parent_commit = <$dd>;
4665 chomp($parent_commit);
4666 my $blamed = href
(action
=> 'blame',
4667 file_name
=> $meta->{'filename'},
4668 hash_base
=> $parent_commit);
4669 print "<td class=\"linenr\">";
4670 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4672 -class => "linenr" },
4675 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4681 or print "Reading blob failed\n";
4686 my $head = git_get_head_hash
($project);
4688 git_print_page_nav
('','', $head,undef,$head);
4689 git_print_header_div
('summary', $project);
4691 my @tagslist = git_get_tags_list
();
4693 git_tags_body
(\
@tagslist);
4699 my $head = git_get_head_hash
($project);
4701 git_print_page_nav
('','', $head,undef,$head);
4702 git_print_header_div
('summary', $project);
4704 my @headslist = git_get_heads_list
();
4706 git_heads_body
(\
@headslist, $head);
4711 sub git_blob_plain
{
4715 if (!defined $hash) {
4716 if (defined $file_name) {
4717 my $base = $hash_base || git_get_head_hash
($project);
4718 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4719 or die_error
(404, "Cannot find file");
4721 die_error
(400, "No file name defined");
4723 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4724 # blobs defined by non-textual hash id's can be cached
4728 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4729 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4731 # content-type (can include charset)
4732 $type = blob_contenttype
($fd, $file_name, $type);
4734 # "save as" filename, even when no $file_name is given
4735 my $save_as = "$hash";
4736 if (defined $file_name) {
4737 $save_as = $file_name;
4738 } elsif ($type =~ m/^text\//) {
4744 -expires
=> $expires,
4745 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4747 binmode STDOUT
, ':raw';
4749 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4757 if (!defined $hash) {
4758 if (defined $file_name) {
4759 my $base = $hash_base || git_get_head_hash
($project);
4760 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4761 or die_error
(404, "Cannot find file");
4763 die_error
(400, "No file name defined");
4765 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4766 # blobs defined by non-textual hash id's can be cached
4770 my $have_blame = gitweb_check_feature
('blame');
4771 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4772 or die_error
(500, "Couldn't cat $file_name, $hash");
4773 my $mimetype = blob_mimetype
($fd, $file_name);
4774 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4776 return git_blob_plain
($mimetype);
4778 # we can have blame only for text/* mimetype
4779 $have_blame &&= ($mimetype =~ m!^text/!);
4781 git_header_html
(undef, $expires);
4782 my $formats_nav = '';
4783 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4784 if (defined $file_name) {
4787 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4792 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4795 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4798 $cgi->a({-href
=> href
(action
=>"blob",
4799 hash_base
=>"HEAD", file_name
=>$file_name)},
4803 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4806 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4807 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4809 print "<div class=\"page_nav\">\n" .
4810 "<br/><br/></div>\n" .
4811 "<div class=\"title\">$hash</div>\n";
4813 git_print_page_path
($file_name, "blob", $hash_base);
4814 print "<div class=\"page_body\">\n";
4815 if ($mimetype =~ m!^image/!) {
4816 print qq!<img type
="$mimetype"!;
4818 print qq! alt
="$file_name" title
="$file_name"!;
4821 href(action=>"blob_plain
", hash=>$hash,
4822 hash_base=>$hash_base, file_name=>$file_name) .
4826 while (my $line = <$fd>) {
4829 $line = untabify
($line);
4830 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4831 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4835 or print "Reading blob failed.\n";
4841 if (!defined $hash_base) {
4842 $hash_base = "HEAD";
4844 if (!defined $hash) {
4845 if (defined $file_name) {
4846 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4851 die_error
(404, "No such tree") unless defined($hash);
4853 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4854 or die_error
(500, "Open git-ls-tree failed");
4855 my @entries = map { chomp; $_ } <$fd>;
4856 close $fd or die_error
(404, "Reading tree failed");
4859 my $refs = git_get_references
();
4860 my $ref = format_ref_marker
($refs, $hash_base);
4863 my $have_blame = gitweb_check_feature
('blame');
4864 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4866 if (defined $file_name) {
4868 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4870 $cgi->a({-href
=> href
(action
=>"tree",
4871 hash_base
=>"HEAD", file_name
=>$file_name)},
4874 my $snapshot_links = format_snapshot_links
($hash);
4875 if (defined $snapshot_links) {
4876 # FIXME: Should be available when we have no hash base as well.
4877 push @views_nav, $snapshot_links;
4879 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4880 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4883 print "<div class=\"page_nav\">\n";
4884 print "<br/><br/></div>\n";
4885 print "<div class=\"title\">$hash</div>\n";
4887 if (defined $file_name) {
4888 $basedir = $file_name;
4889 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4892 git_print_page_path
($file_name, 'tree', $hash_base);
4894 print "<div class=\"page_body\">\n";
4895 print "<table class=\"tree\">\n";
4897 # '..' (top directory) link if possible
4898 if (defined $hash_base &&
4899 defined $file_name && $file_name =~ m![^/]+$!) {
4901 print "<tr class=\"dark\">\n";
4903 print "<tr class=\"light\">\n";
4907 my $up = $file_name;
4908 $up =~ s!/?[^/]+$!!;
4909 undef $up unless $up;
4910 # based on git_print_tree_entry
4911 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4912 print '<td class="list">';
4913 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4917 print "<td class=\"link\"></td>\n";
4921 foreach my $line (@entries) {
4922 my %t = parse_ls_tree_line
($line, -z
=> 1);
4925 print "<tr class=\"dark\">\n";
4927 print "<tr class=\"light\">\n";
4931 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4935 print "</table>\n" .
4941 my $format = $input_params{'snapshot_format'};
4942 if (!@snapshot_fmts) {
4943 die_error
(403, "Snapshots not allowed");
4945 # default to first supported snapshot format
4946 $format ||= $snapshot_fmts[0];
4947 if ($format !~ m/^[a-z0-9]+$/) {
4948 die_error
(400, "Invalid snapshot format parameter");
4949 } elsif (!exists($known_snapshot_formats{$format})) {
4950 die_error
(400, "Unknown snapshot format");
4951 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4952 die_error
(403, "Unsupported snapshot format");
4955 if (!defined $hash) {
4956 $hash = git_get_head_hash
($project);
4959 my $name = $project;
4960 $name =~ s
,([^/])/*\
.git
$,$1,;
4961 $name = basename
($name);
4962 my $filename = to_utf8
($name);
4963 $name =~ s/\047/\047\\\047\047/g;
4965 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4966 $cmd = quote_command
(
4967 git_cmd
(), 'archive',
4968 "--format=$known_snapshot_formats{$format}{'format'}",
4969 "--prefix=$name/", $hash);
4970 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4971 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4975 -type
=> $known_snapshot_formats{$format}{'type'},
4976 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4977 -status
=> '200 OK');
4979 open my $fd, "-|", $cmd
4980 or die_error
(500, "Execute git-archive failed");
4981 binmode STDOUT
, ':raw';
4983 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4988 my $head = git_get_head_hash
($project);
4989 if (!defined $hash) {
4992 if (!defined $page) {
4995 my $refs = git_get_references
();
4997 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4999 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5002 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5005 my %co = parse_commit
($hash);
5007 git_print_header_div
('summary', $project);
5008 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5010 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5011 for (my $i = 0; $i <= $to; $i++) {
5012 my %co = %{$commitlist[$i]};
5014 my $commit = $co{'id'};
5015 my $ref = format_ref_marker
($refs, $commit);
5016 my %ad = parse_date
($co{'author_epoch'});
5017 git_print_header_div
('commit',
5018 "<span class=\"age\">$co{'age_string'}</span>" .
5019 esc_html
($co{'title'}) . $ref,
5021 print "<div class=\"title_text\">\n" .
5022 "<div class=\"log_link\">\n" .
5023 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5025 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5027 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5030 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5033 print "<div class=\"log_body\">\n";
5034 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5037 if ($#commitlist >= 100) {
5038 print "<div class=\"page_nav\">\n";
5039 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5040 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5047 $hash ||= $hash_base || "HEAD";
5048 my %co = parse_commit
($hash)
5049 or die_error
(404, "Unknown commit object");
5050 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5051 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5053 my $parent = $co{'parent'};
5054 my $parents = $co{'parents'}; # listref
5056 # we need to prepare $formats_nav before any parameter munging
5058 if (!defined $parent) {
5060 $formats_nav .= '(initial)';
5061 } elsif (@
$parents == 1) {
5062 # single parent commit
5065 $cgi->a({-href
=> href
(action
=>"commit",
5067 esc_html
(substr($parent, 0, 7))) .
5074 $cgi->a({-href
=> href
(action
=>"commit",
5076 esc_html
(substr($_, 0, 7)));
5081 if (!defined $parent) {
5085 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5087 (@
$parents <= 1 ?
$parent : '-c'),
5089 or die_error
(500, "Open git-diff-tree failed");
5090 @difftree = map { chomp; $_ } <$fd>;
5091 close $fd or die_error
(404, "Reading git-diff-tree failed");
5093 # non-textual hash id's can be cached
5095 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5098 my $refs = git_get_references
();
5099 my $ref = format_ref_marker
($refs, $co{'id'});
5101 git_header_html
(undef, $expires);
5102 git_print_page_nav
('commit', '',
5103 $hash, $co{'tree'}, $hash,
5106 if (defined $co{'parent'}) {
5107 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5109 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5111 print "<div class=\"title_text\">\n" .
5112 "<table class=\"object_header\">\n";
5113 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5115 "<td></td><td> $ad{'rfc2822'}";
5116 if ($ad{'hour_local'} < 6) {
5117 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5118 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5120 printf(" (%02d:%02d %s)",
5121 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5125 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5126 print "<tr><td></td><td> $cd{'rfc2822'}" .
5127 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5129 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5132 "<td class=\"sha1\">" .
5133 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5134 class => "list"}, $co{'tree'}) .
5136 "<td class=\"link\">" .
5137 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5139 my $snapshot_links = format_snapshot_links
($hash);
5140 if (defined $snapshot_links) {
5141 print " | " . $snapshot_links;
5146 foreach my $par (@
$parents) {
5149 "<td class=\"sha1\">" .
5150 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5151 class => "list"}, $par) .
5153 "<td class=\"link\">" .
5154 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5156 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5163 print "<div class=\"page_body\">\n";
5164 git_print_log
($co{'comment'});
5167 git_difftree_body
(\
@difftree, $hash, @
$parents);
5173 # object is defined by:
5174 # - hash or hash_base alone
5175 # - hash_base and file_name
5178 # - hash or hash_base alone
5179 if ($hash || ($hash_base && !defined $file_name)) {
5180 my $object_id = $hash || $hash_base;
5182 open my $fd, "-|", quote_command
(
5183 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5184 or die_error
(404, "Object does not exist");
5188 or die_error
(404, "Object does not exist");
5190 # - hash_base and file_name
5191 } elsif ($hash_base && defined $file_name) {
5192 $file_name =~ s
,/+$,,;
5194 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5195 or die_error
(404, "Base object does not exist");
5197 # here errors should not hapen
5198 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5199 or die_error
(500, "Open git-ls-tree failed");
5203 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5204 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5205 die_error
(404, "File or directory for given base does not exist");
5210 die_error
(400, "Not enough information to find object");
5213 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5214 hash
=>$hash, hash_base
=>$hash_base,
5215 file_name
=>$file_name),
5216 -status
=> '302 Found');
5220 my $format = shift || 'html';
5227 # preparing $fd and %diffinfo for git_patchset_body
5229 if (defined $hash_base && defined $hash_parent_base) {
5230 if (defined $file_name) {
5232 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5233 $hash_parent_base, $hash_base,
5234 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5235 or die_error
(500, "Open git-diff-tree failed");
5236 @difftree = map { chomp; $_ } <$fd>;
5238 or die_error
(404, "Reading git-diff-tree failed");
5240 or die_error
(404, "Blob diff not found");
5242 } elsif (defined $hash &&
5243 $hash =~ /[0-9a-fA-F]{40}/) {
5244 # try to find filename from $hash
5246 # read filtered raw output
5247 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5248 $hash_parent_base, $hash_base, "--"
5249 or die_error
(500, "Open git-diff-tree failed");
5251 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5253 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5254 map { chomp; $_ } <$fd>;
5256 or die_error
(404, "Reading git-diff-tree failed");
5258 or die_error
(404, "Blob diff not found");
5261 die_error
(400, "Missing one of the blob diff parameters");
5264 if (@difftree > 1) {
5265 die_error
(400, "Ambiguous blob diff specification");
5268 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5269 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5270 $file_name ||= $diffinfo{'to_file'};
5272 $hash_parent ||= $diffinfo{'from_id'};
5273 $hash ||= $diffinfo{'to_id'};
5275 # non-textual hash id's can be cached
5276 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5277 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5282 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5283 '-p', ($format eq 'html' ?
"--full-index" : ()),
5284 $hash_parent_base, $hash_base,
5285 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5286 or die_error
(500, "Open git-diff-tree failed");
5289 # old/legacy style URI -- not generated anymore since 1.4.3.
5291 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5295 if ($format eq 'html') {
5297 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5299 git_header_html
(undef, $expires);
5300 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5301 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5302 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5304 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5305 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5307 if (defined $file_name) {
5308 git_print_page_path
($file_name, "blob", $hash_base);
5310 print "<div class=\"page_path\"></div>\n";
5313 } elsif ($format eq 'plain') {
5315 -type
=> 'text/plain',
5316 -charset
=> 'utf-8',
5317 -expires
=> $expires,
5318 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5320 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5323 die_error
(400, "Unknown blobdiff format");
5327 if ($format eq 'html') {
5328 print "<div class=\"page_body\">\n";
5330 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5333 print "</div>\n"; # class="page_body"
5337 while (my $line = <$fd>) {
5338 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5339 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5343 last if $line =~ m!^\+\+\+!;
5351 sub git_blobdiff_plain
{
5352 git_blobdiff
('plain');
5355 sub git_commitdiff
{
5356 my $format = shift || 'html';
5357 $hash ||= $hash_base || "HEAD";
5358 my %co = parse_commit
($hash)
5359 or die_error
(404, "Unknown commit object");
5361 # choose format for commitdiff for merge
5362 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5363 $hash_parent = '--cc';
5365 # we need to prepare $formats_nav before almost any parameter munging
5367 if ($format eq 'html') {
5369 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5372 if (defined $hash_parent &&
5373 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5374 # commitdiff with two commits given
5375 my $hash_parent_short = $hash_parent;
5376 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5377 $hash_parent_short = substr($hash_parent, 0, 7);
5381 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5382 if ($co{'parents'}[$i] eq $hash_parent) {
5383 $formats_nav .= ' parent ' . ($i+1);
5387 $formats_nav .= ': ' .
5388 $cgi->a({-href
=> href
(action
=>"commitdiff",
5389 hash
=>$hash_parent)},
5390 esc_html
($hash_parent_short)) .
5392 } elsif (!$co{'parent'}) {
5394 $formats_nav .= ' (initial)';
5395 } elsif (scalar @
{$co{'parents'}} == 1) {
5396 # single parent commit
5399 $cgi->a({-href
=> href
(action
=>"commitdiff",
5400 hash
=>$co{'parent'})},
5401 esc_html
(substr($co{'parent'}, 0, 7))) .
5405 if ($hash_parent eq '--cc') {
5406 $formats_nav .= ' | ' .
5407 $cgi->a({-href
=> href
(action
=>"commitdiff",
5408 hash
=>$hash, hash_parent
=>'-c')},
5410 } else { # $hash_parent eq '-c'
5411 $formats_nav .= ' | ' .
5412 $cgi->a({-href
=> href
(action
=>"commitdiff",
5413 hash
=>$hash, hash_parent
=>'--cc')},
5419 $cgi->a({-href
=> href
(action
=>"commitdiff",
5421 esc_html
(substr($_, 0, 7)));
5422 } @
{$co{'parents'}} ) .
5427 my $hash_parent_param = $hash_parent;
5428 if (!defined $hash_parent_param) {
5429 # --cc for multiple parents, --root for parentless
5430 $hash_parent_param =
5431 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5437 if ($format eq 'html') {
5438 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5439 "--no-commit-id", "--patch-with-raw", "--full-index",
5440 $hash_parent_param, $hash, "--"
5441 or die_error
(500, "Open git-diff-tree failed");
5443 while (my $line = <$fd>) {
5445 # empty line ends raw part of diff-tree output
5447 push @difftree, scalar parse_difftree_raw_line
($line);
5450 } elsif ($format eq 'plain') {
5451 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5452 '-p', $hash_parent_param, $hash, "--"
5453 or die_error
(500, "Open git-diff-tree failed");
5456 die_error
(400, "Unknown commitdiff format");
5459 # non-textual hash id's can be cached
5461 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5465 # write commit message
5466 if ($format eq 'html') {
5467 my $refs = git_get_references
();
5468 my $ref = format_ref_marker
($refs, $co{'id'});
5470 git_header_html
(undef, $expires);
5471 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5472 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5473 git_print_authorship
(\
%co);
5474 print "<div class=\"page_body\">\n";
5475 if (@
{$co{'comment'}} > 1) {
5476 print "<div class=\"log\">\n";
5477 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5478 print "</div>\n"; # class="log"
5481 } elsif ($format eq 'plain') {
5482 my $refs = git_get_references
("tags");
5483 my $tagname = git_get_rev_name_tags
($hash);
5484 my $filename = basename
($project) . "-$hash.patch";
5487 -type
=> 'text/plain',
5488 -charset
=> 'utf-8',
5489 -expires
=> $expires,
5490 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5491 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5492 print "From: " . to_utf8
($co{'author'}) . "\n";
5493 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5494 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5496 print "X-Git-Tag: $tagname\n" if $tagname;
5497 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5499 foreach my $line (@
{$co{'comment'}}) {
5500 print to_utf8
($line) . "\n";
5506 if ($format eq 'html') {
5507 my $use_parents = !defined $hash_parent ||
5508 $hash_parent eq '-c' || $hash_parent eq '--cc';
5509 git_difftree_body
(\
@difftree, $hash,
5510 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5513 git_patchset_body
($fd, \
@difftree, $hash,
5514 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5516 print "</div>\n"; # class="page_body"
5519 } elsif ($format eq 'plain') {
5523 or print "Reading git-diff-tree failed\n";
5527 sub git_commitdiff_plain
{
5528 git_commitdiff
('plain');
5532 if (!defined $hash_base) {
5533 $hash_base = git_get_head_hash
($project);
5535 if (!defined $page) {
5539 my %co = parse_commit
($hash_base)
5540 or die_error
(404, "Unknown commit object");
5542 my $refs = git_get_references
();
5543 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5545 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5546 $file_name, "--full-history")
5547 or die_error
(404, "No such file or directory on given branch");
5549 if (!defined $hash && defined $file_name) {
5550 # some commits could have deleted file in question,
5551 # and not have it in tree, but one of them has to have it
5552 for (my $i = 0; $i <= @commitlist; $i++) {
5553 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5554 last if defined $hash;
5557 if (defined $hash) {
5558 $ftype = git_get_type
($hash);
5560 if (!defined $ftype) {
5561 die_error
(500, "Unknown type of object");
5564 my $paging_nav = '';
5567 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5568 file_name
=>$file_name)},
5570 $paging_nav .= " ⋅ " .
5571 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5572 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5574 $paging_nav .= "first";
5575 $paging_nav .= " ⋅ prev";
5578 if ($#commitlist >= 100) {
5580 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5581 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5582 $paging_nav .= " ⋅ $next_link";
5584 $paging_nav .= " ⋅ next";
5588 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5589 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5590 git_print_page_path
($file_name, $ftype, $hash_base);
5592 git_history_body
(\
@commitlist, 0, 99,
5593 $refs, $hash_base, $ftype, $next_link);
5599 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5600 if (!defined $searchtext) {
5601 die_error
(400, "Text field is empty");
5603 if (!defined $hash) {
5604 $hash = git_get_head_hash
($project);
5606 my %co = parse_commit
($hash);
5608 die_error
(404, "Unknown commit object");
5610 if (!defined $page) {
5614 $searchtype ||= 'commit';
5615 if ($searchtype eq 'pickaxe') {
5616 # pickaxe may take all resources of your box and run for several minutes
5617 # with every query - so decide by yourself how public you make this feature
5618 gitweb_check_feature
('pickaxe')
5619 or die_error
(403, "Pickaxe is disabled");
5621 if ($searchtype eq 'grep') {
5622 gitweb_check_feature
('grep')
5623 or die_error
(403, "Grep is disabled");
5628 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5630 if ($searchtype eq 'commit') {
5631 $greptype = "--grep=";
5632 } elsif ($searchtype eq 'author') {
5633 $greptype = "--author=";
5634 } elsif ($searchtype eq 'committer') {
5635 $greptype = "--committer=";
5637 $greptype .= $searchtext;
5638 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5639 $greptype, '--regexp-ignore-case',
5640 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5642 my $paging_nav = '';
5645 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5646 searchtext
=>$searchtext,
5647 searchtype
=>$searchtype)},
5649 $paging_nav .= " ⋅ " .
5650 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5651 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5653 $paging_nav .= "first";
5654 $paging_nav .= " ⋅ prev";
5657 if ($#commitlist >= 100) {
5659 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5660 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5661 $paging_nav .= " ⋅ $next_link";
5663 $paging_nav .= " ⋅ next";
5666 if ($#commitlist >= 100) {
5669 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5670 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5671 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5674 if ($searchtype eq 'pickaxe') {
5675 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5676 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5678 print "<table class=\"pickaxe search\">\n";
5681 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5682 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5683 ($search_use_regexp ?
'--pickaxe-regex' : ());
5686 while (my $line = <$fd>) {
5690 my %set = parse_difftree_raw_line
($line);
5691 if (defined $set{'commit'}) {
5692 # finish previous commit
5695 "<td class=\"link\">" .
5696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5698 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5704 print "<tr class=\"dark\">\n";
5706 print "<tr class=\"light\">\n";
5709 %co = parse_commit
($set{'commit'});
5710 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5711 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5712 "<td><i>$author</i></td>\n" .
5714 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5715 -class => "list subject"},
5716 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5717 } elsif (defined $set{'to_id'}) {
5718 next if ($set{'to_id'} =~ m/^0{40}$/);
5720 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5721 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5723 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5729 # finish last commit (warning: repetition!)
5732 "<td class=\"link\">" .
5733 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5735 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5743 if ($searchtype eq 'grep') {
5744 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5745 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5747 print "<table class=\"grep_search\">\n";
5751 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5752 $search_use_regexp ?
('-E', '-i') : '-F',
5753 $searchtext, $co{'tree'};
5755 while (my $line = <$fd>) {
5757 my ($file, $lno, $ltext, $binary);
5758 last if ($matches++ > 1000);
5759 if ($line =~ /^Binary file (.+) matches$/) {
5763 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5765 if ($file ne $lastfile) {
5766 $lastfile and print "</td></tr>\n";
5768 print "<tr class=\"dark\">\n";
5770 print "<tr class=\"light\">\n";
5772 print "<td class=\"list\">".
5773 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5774 file_name
=>"$file"),
5775 -class => "list"}, esc_path
($file));
5776 print "</td><td>\n";
5780 print "<div class=\"binary\">Binary file</div>\n";
5782 $ltext = untabify
($ltext);
5783 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5784 $ltext = esc_html
($1, -nbsp
=>1);
5785 $ltext .= '<span class="match">';
5786 $ltext .= esc_html
($2, -nbsp
=>1);
5787 $ltext .= '</span>';
5788 $ltext .= esc_html
($3, -nbsp
=>1);
5790 $ltext = esc_html
($ltext, -nbsp
=>1);
5792 print "<div class=\"pre\">" .
5793 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5794 file_name
=>"$file").'#l'.$lno,
5795 -class => "linenr"}, sprintf('%4i', $lno))
5796 . ' ' . $ltext . "</div>\n";
5800 print "</td></tr>\n";
5801 if ($matches > 1000) {
5802 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5805 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5814 sub git_search_help
{
5816 git_print_page_nav
('','', $hash,$hash,$hash);
5818 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5819 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5820 the pattern entered is recognized as the POSIX extended
5821 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5824 <dt><b>commit</b></dt>
5825 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5827 my $have_grep = gitweb_check_feature
('grep');
5830 <dt><b>grep</b></dt>
5831 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5832 a different one) are searched for the given pattern. On large trees, this search can take
5833 a while and put some strain on the server, so please use it with some consideration. Note that
5834 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5835 case-sensitive.</dd>
5839 <dt><b>author</b></dt>
5840 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5841 <dt><b>committer</b></dt>
5842 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5844 my $have_pickaxe = gitweb_check_feature
('pickaxe');
5845 if ($have_pickaxe) {
5847 <dt><b>pickaxe</b></dt>
5848 <dd>All commits that caused the string to appear or disappear from any file (changes that
5849 added, removed or "modified" the string) will be listed. This search can take a while and
5850 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5851 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5859 my $head = git_get_head_hash
($project);
5860 if (!defined $hash) {
5863 if (!defined $page) {
5866 my $refs = git_get_references
();
5868 my $commit_hash = $hash;
5869 if (defined $hash_parent) {
5870 $commit_hash = "$hash_parent..$hash";
5872 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5874 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5876 if ($#commitlist >= 100) {
5878 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5879 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5883 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5884 git_print_header_div
('summary', $project);
5886 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5891 ## ......................................................................
5892 ## feeds (RSS, Atom; OPML)
5895 my $format = shift || 'atom';
5896 my $have_blame = gitweb_check_feature
('blame');
5898 # Atom: http://www.atomenabled.org/developers/syndication/
5899 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5900 if ($format ne 'rss' && $format ne 'atom') {
5901 die_error
(400, "Unknown web feed format");
5904 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5905 my $head = $hash || 'HEAD';
5906 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5910 my $content_type = "application/$format+xml";
5911 if (defined $cgi->http('HTTP_ACCEPT') &&
5912 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5913 # browser (feed reader) prefers text/xml
5914 $content_type = 'text/xml';
5916 if (defined($commitlist[0])) {
5917 %latest_commit = %{$commitlist[0]};
5918 %latest_date = parse_date
($latest_commit{'author_epoch'});
5920 -type
=> $content_type,
5921 -charset
=> 'utf-8',
5922 -last_modified
=> $latest_date{'rfc2822'});
5925 -type
=> $content_type,
5926 -charset
=> 'utf-8');
5929 # Optimization: skip generating the body if client asks only
5930 # for Last-Modified date.
5931 return if ($cgi->request_method() eq 'HEAD');
5934 my $title = "$site_name - $project/$action";
5935 my $feed_type = 'log';
5936 if (defined $hash) {
5937 $title .= " - '$hash'";
5938 $feed_type = 'branch log';
5939 if (defined $file_name) {
5940 $title .= " :: $file_name";
5941 $feed_type = 'history';
5943 } elsif (defined $file_name) {
5944 $title .= " - $file_name";
5945 $feed_type = 'history';
5947 $title .= " $feed_type";
5948 my $descr = git_get_project_description
($project);
5949 if (defined $descr) {
5950 $descr = esc_html
($descr);
5952 $descr = "$project " .
5953 ($format eq 'rss' ?
'RSS' : 'Atom') .
5956 my $owner = git_get_project_owner
($project);
5957 $owner = esc_html
($owner);
5961 if (defined $file_name) {
5962 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5963 } elsif (defined $hash) {
5964 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5966 $alt_url = href
(-full
=>1, action
=>"summary");
5968 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5969 if ($format eq 'rss') {
5971 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5974 print "<title>$title</title>\n" .
5975 "<link>$alt_url</link>\n" .
5976 "<description>$descr</description>\n" .
5977 "<language>en</language>\n";
5978 } elsif ($format eq 'atom') {
5980 <feed xmlns="http://www.w3.org/2005/Atom">
5982 print "<title>$title</title>\n" .
5983 "<subtitle>$descr</subtitle>\n" .
5984 '<link rel="alternate" type="text/html" href="' .
5985 $alt_url . '" />' . "\n" .
5986 '<link rel="self" type="' . $content_type . '" href="' .
5987 $cgi->self_url() . '" />' . "\n" .
5988 "<id>" . href
(-full
=>1) . "</id>\n" .
5989 # use project owner for feed author
5990 "<author><name>$owner</name></author>\n";
5991 if (defined $favicon) {
5992 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5994 if (defined $logo_url) {
5995 # not twice as wide as tall: 72 x 27 pixels
5996 print "<logo>" . esc_url
($logo) . "</logo>\n";
5998 if (! %latest_date) {
5999 # dummy date to keep the feed valid until commits trickle in:
6000 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6002 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6007 for (my $i = 0; $i <= $#commitlist; $i++) {
6008 my %co = %{$commitlist[$i]};
6009 my $commit = $co{'id'};
6010 # we read 150, we always show 30 and the ones more recent than 48 hours
6011 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6014 my %cd = parse_date
($co{'author_epoch'});
6016 # get list of changed files
6017 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6018 $co{'parent'} || "--root",
6019 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6021 my @difftree = map { chomp; $_ } <$fd>;
6025 # print element (entry, item)
6026 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6027 if ($format eq 'rss') {
6029 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6030 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6031 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6032 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6033 "<link>$co_url</link>\n" .
6034 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6035 "<content:encoded>" .
6037 } elsif ($format eq 'atom') {
6039 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6040 "<updated>$cd{'iso-8601'}</updated>\n" .
6042 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6043 if ($co{'author_email'}) {
6044 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6046 print "</author>\n" .
6047 # use committer for contributor
6049 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6050 if ($co{'committer_email'}) {
6051 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6053 print "</contributor>\n" .
6054 "<published>$cd{'iso-8601'}</published>\n" .
6055 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6056 "<id>$co_url</id>\n" .
6057 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6058 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6060 my $comment = $co{'comment'};
6062 foreach my $line (@
$comment) {
6063 $line = esc_html
($line);
6066 print "</pre><ul>\n";
6067 foreach my $difftree_line (@difftree) {
6068 my %difftree = parse_difftree_raw_line
($difftree_line);
6069 next if !$difftree{'from_id'};
6071 my $file = $difftree{'file'} || $difftree{'to_file'};
6075 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6076 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6077 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6078 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6079 -title
=> "diff"}, 'D');
6081 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6082 file_name
=>$file, hash_base
=>$commit),
6083 -title
=> "blame"}, 'B');
6085 # if this is not a feed of a file history
6086 if (!defined $file_name || $file_name ne $file) {
6087 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6088 file_name
=>$file, hash
=>$commit),
6089 -title
=> "history"}, 'H');
6091 $file = esc_path
($file);
6095 if ($format eq 'rss') {
6096 print "</ul>]]>\n" .
6097 "</content:encoded>\n" .
6099 } elsif ($format eq 'atom') {
6100 print "</ul>\n</div>\n" .
6107 if ($format eq 'rss') {
6108 print "</channel>\n</rss>\n";
6109 } elsif ($format eq 'atom') {
6123 my @list = git_get_projects_list
();
6125 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6127 <?xml version="1.0" encoding="utf-8"?>
6128 <opml version="1.0">
6130 <title>$site_name OPML Export</title>
6133 <outline text="git RSS feeds">
6136 foreach my $pr (@list) {
6138 my $head = git_get_head_hash
($proj{'path'});
6139 if (!defined $head) {
6142 $git_dir = "$projectroot/$proj{'path'}";
6143 my %co = parse_commit
($head);
6148 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6149 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6150 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6151 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";