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 my $path_info = $ENV{"PATH_INFO"};
35 $my_url =~ s
,\Q
$path_info\E
$,,;
36 $my_uri =~ s
,\Q
$path_info\E
$,,;
39 # core git executable to use
40 # this can just be "git" if your webserver has a sensible PATH
41 our $GIT = "++GIT_BINDIR++/git";
43 # absolute fs-path which will be prepended to the project path
44 #our $projectroot = "/pub/scm";
45 our $projectroot = "++GITWEB_PROJECTROOT++";
47 # fs traversing limit for getting project list
48 # the number is relative to the projectroot
49 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
51 # target of the home link on top of all pages
52 our $home_link = $my_uri || "/";
54 # string of the home link on top of all pages
55 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
57 # name of your site or organization to appear in page titles
58 # replace this with something more descriptive for clearer bookmarks
59 our $site_name = "++GITWEB_SITENAME++"
60 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
62 # filename of html text to include at top of each page
63 our $site_header = "++GITWEB_SITE_HEADER++";
64 # html text to include at home page
65 our $home_text = "++GITWEB_HOMETEXT++";
66 # filename of html text to include at bottom of each page
67 our $site_footer = "++GITWEB_SITE_FOOTER++";
70 our @stylesheets = ("++GITWEB_CSS++");
71 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
72 our $stylesheet = undef;
74 # URI of GIT logo (72x27 size)
75 our $logo = "++GITWEB_LOGO++";
76 # URI of GIT favicon, assumed to be image/png type
77 our $favicon = "++GITWEB_FAVICON++";
79 # URI and label (title) of GIT logo link
80 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
81 #our $logo_label = "git documentation";
82 our $logo_url = "http://git.or.cz/";
83 our $logo_label = "git homepage";
85 # source of projects list
86 our $projects_list = "++GITWEB_LIST++";
88 # the width (in characters) of the projects list "Description" column
89 our $projects_list_description_width = 25;
91 # default order of projects list
92 # valid values are none, project, descr, owner, and age
93 our $default_projects_order = "project";
95 # show repository only if this file exists
96 # (only effective if this variable evaluates to true)
97 our $export_ok = "++GITWEB_EXPORT_OK++";
99 # only allow viewing of repositories also shown on the overview page
100 our $strict_export = "++GITWEB_STRICT_EXPORT++";
102 # list of git base URLs used for URL to where fetch project from,
103 # i.e. full URL is "$git_base_url/$project"
104 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
106 # default blob_plain mimetype and default charset for text/plain blob
107 our $default_blob_plain_mimetype = 'text/plain';
108 our $default_text_plain_charset = undef;
110 # file to use for guessing MIME types before trying /etc/mime.types
111 # (relative to the current git repository)
112 our $mimetypes_file = undef;
114 # assume this charset if line contains non-UTF-8 characters;
115 # it should be valid encoding (see Encoding::Supported(3pm) for list),
116 # for which encoding all byte sequences are valid, for example
117 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
118 # could be even 'utf-8' for the old behavior)
119 our $fallback_encoding = 'latin1';
121 # rename detection options for git-diff and git-diff-tree
122 # - default is '-M', with the cost proportional to
123 # (number of removed files) * (number of new files).
124 # - more costly is '-C' (which implies '-M'), with the cost proportional to
125 # (number of changed files + number of removed files) * (number of new files)
126 # - even more costly is '-C', '--find-copies-harder' with cost
127 # (number of files in the original tree) * (number of new files)
128 # - one might want to include '-B' option, e.g. '-B', '-M'
129 our @diff_opts = ('-M'); # taken from git_commit
131 # information about snapshot formats that gitweb is capable of serving
132 our %known_snapshot_formats = (
134 # 'display' => display name,
135 # 'type' => mime type,
136 # 'suffix' => filename suffix,
137 # 'format' => --format for git-archive,
138 # 'compressor' => [compressor command and arguments]
139 # (array reference, optional)}
142 'display' => 'tar.gz',
143 'type' => 'application/x-gzip',
144 'suffix' => '.tar.gz',
146 'compressor' => ['gzip']},
149 'display' => 'tar.bz2',
150 'type' => 'application/x-bzip2',
151 'suffix' => '.tar.bz2',
153 'compressor' => ['bzip2']},
157 'type' => 'application/x-zip',
162 # Aliases so we understand old gitweb.snapshot values in repository
164 our %known_snapshot_format_aliases = (
168 # backward compatibility: legacy gitweb config support
169 'x-gzip' => undef, 'gz' => undef,
170 'x-bzip2' => undef, 'bz2' => undef,
171 'x-zip' => undef, '' => undef,
174 # You define site-wide feature defaults here; override them with
175 # $GITWEB_CONFIG as necessary.
178 # 'sub' => feature-sub (subroutine),
179 # 'override' => allow-override (boolean),
180 # 'default' => [ default options...] (array reference)}
182 # if feature is overridable (it means that allow-override has true value),
183 # then feature-sub will be called with default options as parameters;
184 # return value of feature-sub indicates if to enable specified feature
186 # if there is no 'sub' key (no feature-sub), then feature cannot be
189 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
191 # Enable the 'blame' blob view, showing the last commit that modified
192 # each line in the file. This can be very CPU-intensive.
194 # To enable system wide have in $GITWEB_CONFIG
195 # $feature{'blame'}{'default'} = [1];
196 # To have project specific config enable override in $GITWEB_CONFIG
197 # $feature{'blame'}{'override'} = 1;
198 # and in project config gitweb.blame = 0|1;
200 'sub' => \
&feature_blame
,
204 # Enable the 'snapshot' link, providing a compressed archive of any
205 # tree. This can potentially generate high traffic if you have large
208 # Value is a list of formats defined in %known_snapshot_formats that
210 # To disable system wide have in $GITWEB_CONFIG
211 # $feature{'snapshot'}{'default'} = [];
212 # To have project specific config enable override in $GITWEB_CONFIG
213 # $feature{'snapshot'}{'override'} = 1;
214 # and in project config, a comma-separated list of formats or "none"
215 # to disable. Example: gitweb.snapshot = tbz2,zip;
217 'sub' => \
&feature_snapshot
,
219 'default' => ['tgz']},
221 # Enable text search, which will list the commits which match author,
222 # committer or commit text to a given string. Enabled by default.
223 # Project specific override is not supported.
228 # Enable grep search, which will list the files in currently selected
229 # tree containing the given string. Enabled by default. This can be
230 # potentially CPU-intensive, of course.
232 # To enable system wide have in $GITWEB_CONFIG
233 # $feature{'grep'}{'default'} = [1];
234 # To have project specific config enable override in $GITWEB_CONFIG
235 # $feature{'grep'}{'override'} = 1;
236 # and in project config gitweb.grep = 0|1;
241 # Enable the pickaxe search, which will list the commits that modified
242 # a given string in a file. This can be practical and quite faster
243 # alternative to 'blame', but still potentially CPU-intensive.
245 # To enable system wide have in $GITWEB_CONFIG
246 # $feature{'pickaxe'}{'default'} = [1];
247 # To have project specific config enable override in $GITWEB_CONFIG
248 # $feature{'pickaxe'}{'override'} = 1;
249 # and in project config gitweb.pickaxe = 0|1;
251 'sub' => \
&feature_pickaxe
,
255 # Make gitweb use an alternative format of the URLs which can be
256 # more readable and natural-looking: project name is embedded
257 # directly in the path and the query string contains other
258 # auxiliary information. All gitweb installations recognize
259 # URL in either format; this configures in which formats gitweb
262 # To enable system wide have in $GITWEB_CONFIG
263 # $feature{'pathinfo'}{'default'} = [1];
264 # Project specific override is not supported.
266 # Note that you will need to change the default location of CSS,
267 # favicon, logo and possibly other files to an absolute URL. Also,
268 # if gitweb.cgi serves as your indexfile, you will need to force
269 # $my_uri to contain the script name in your $GITWEB_CONFIG.
274 # Make gitweb consider projects in project root subdirectories
275 # to be forks of existing projects. Given project $projname.git,
276 # projects matching $projname/*.git will not be shown in the main
277 # projects list, instead a '+' mark will be added to $projname
278 # there and a 'forks' view will be enabled for the project, listing
279 # all the forks. If project list is taken from a file, forks have
280 # to be listed after the main project.
282 # To enable system wide have in $GITWEB_CONFIG
283 # $feature{'forks'}{'default'} = [1];
284 # Project specific override is not supported.
289 # Insert custom links to the action bar of all project pages.
290 # This enables you mainly to link to third-party scripts integrating
291 # into gitweb; e.g. git-browser for graphical history representation
292 # or custom web-based repository administration interface.
294 # The 'default' value consists of a list of triplets in the form
295 # (label, link, position) where position is the label after which
296 # to insert the link and link is a format string where %n expands
297 # to the project name, %f to the project path within the filesystem,
298 # %h to the current hash (h gitweb parameter) and %b to the current
299 # hash base (hb gitweb parameter); %% expands to %.
301 # To enable system wide have in $GITWEB_CONFIG e.g.
302 # $feature{'actions'}{'default'} = [('graphiclog',
303 # '/git-browser/by-commit.html?r=%n', 'summary')];
304 # Project specific override is not supported.
309 # Allow gitweb scan project content tags described in ctags/
310 # of project repository, and display the popular Web 2.0-ish
311 # "tag cloud" near the project list. Note that this is something
312 # COMPLETELY different from the normal Git tags.
314 # gitweb by itself can show existing tags, but it does not handle
315 # tagging itself; you need an external application for that.
316 # For an example script, check Girocco's cgi/tagproj.cgi.
317 # You may want to install the HTML::TagCloud Perl module to get
318 # a pretty tag cloud instead of just a list of tags.
320 # To enable system wide have in $GITWEB_CONFIG
321 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
322 # Project specific override is not supported.
328 sub gitweb_check_feature
{
330 return unless exists $feature{$name};
331 my ($sub, $override, @defaults) = (
332 $feature{$name}{'sub'},
333 $feature{$name}{'override'},
334 @{$feature{$name}{'default'}});
335 if (!$override) { return @defaults; }
337 warn "feature $name is not overrideable";
340 return $sub->(@defaults);
344 my ($val) = git_get_project_config
('blame', '--bool');
346 if ($val eq 'true') {
348 } elsif ($val eq 'false') {
355 sub feature_snapshot
{
358 my ($val) = git_get_project_config
('snapshot');
361 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
368 my ($val) = git_get_project_config
('grep', '--bool');
370 if ($val eq 'true') {
372 } elsif ($val eq 'false') {
379 sub feature_pickaxe
{
380 my ($val) = git_get_project_config
('pickaxe', '--bool');
382 if ($val eq 'true') {
384 } elsif ($val eq 'false') {
391 # checking HEAD file with -e is fragile if the repository was
392 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
394 sub check_head_link
{
396 my $headfile = "$dir/HEAD";
397 return ((-e
$headfile) ||
398 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
401 sub check_export_ok
{
403 return (check_head_link
($dir) &&
404 (!$export_ok || -e
"$dir/$export_ok"));
407 # process alternate names for backward compatibility
408 # filter out unsupported (unknown) snapshot formats
409 sub filter_snapshot_fmts
{
413 exists $known_snapshot_format_aliases{$_} ?
414 $known_snapshot_format_aliases{$_} : $_} @fmts;
415 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
419 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
420 if (-e
$GITWEB_CONFIG) {
423 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
424 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
427 # version of the core git binary
428 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
430 $projects_list ||= $projectroot;
432 # ======================================================================
433 # input validation and dispatch
435 # input parameters can be collected from a variety of sources (presently, CGI
436 # and PATH_INFO), so we define an %input_params hash that collects them all
437 # together during validation: this allows subsequent uses (e.g. href()) to be
438 # agnostic of the parameter origin
440 my %input_params = ();
442 # input parameters are stored with the long parameter name as key. This will
443 # also be used in the href subroutine to convert parameters to their CGI
444 # equivalent, and since the href() usage is the most frequent one, we store
445 # the name -> CGI key mapping here, instead of the reverse.
447 # XXX: Warning: If you touch this, check the search form for updating,
450 my @cgi_param_mapping = (
458 hash_parent_base
=> "hpb",
463 snapshot_format
=> "sf",
464 extra_options
=> "opt",
465 search_use_regexp
=> "sr",
467 my %cgi_param_mapping = @cgi_param_mapping;
469 # we will also need to know the possible actions, for validation
471 "blame" => \
&git_blame
,
472 "blobdiff" => \
&git_blobdiff
,
473 "blobdiff_plain" => \
&git_blobdiff_plain
,
474 "blob" => \
&git_blob
,
475 "blob_plain" => \
&git_blob_plain
,
476 "commitdiff" => \
&git_commitdiff
,
477 "commitdiff_plain" => \
&git_commitdiff_plain
,
478 "commit" => \
&git_commit
,
479 "forks" => \
&git_forks
,
480 "heads" => \
&git_heads
,
481 "history" => \
&git_history
,
484 "atom" => \
&git_atom
,
485 "search" => \
&git_search
,
486 "search_help" => \
&git_search_help
,
487 "shortlog" => \
&git_shortlog
,
488 "summary" => \
&git_summary
,
490 "tags" => \
&git_tags
,
491 "tree" => \
&git_tree
,
492 "snapshot" => \
&git_snapshot
,
493 "object" => \
&git_object
,
494 # those below don't need $project
495 "opml" => \
&git_opml
,
496 "project_list" => \
&git_project_list
,
497 "project_index" => \
&git_project_index
,
500 # finally, we have the hash of allowed extra_options for the commands that
502 my %allowed_options = (
503 "--no-merges" => [ qw(rss atom log shortlog history) ],
506 # fill %input_params with the CGI parameters. All values except for 'opt'
507 # should be single values, but opt can be an array. We should probably
508 # build an array of parameters that can be multi-valued, but since for the time
509 # being it's only this one, we just single it out
510 while (my ($name, $symbol) = each %cgi_param_mapping) {
511 if ($symbol eq 'opt') {
512 $input_params{$name} = [ $cgi->param($symbol) ];
514 $input_params{$name} = $cgi->param($symbol);
518 # now read PATH_INFO and update the parameter list for missing parameters
519 sub evaluate_path_info
{
520 return if defined $input_params{'project'};
521 return if !$path_info;
522 $path_info =~ s
,^/+,,;
523 return if !$path_info;
525 # find which part of PATH_INFO is project
526 my $project = $path_info;
528 while ($project && !check_head_link
("$projectroot/$project")) {
529 $project =~ s
,/*[^/]*$,,;
531 return unless $project;
532 $input_params{'project'} = $project;
534 # do not change any parameters if an action is given using the query string
535 return if $input_params{'action'};
536 $path_info =~ s
,^\Q
$project\E
/*,,;
538 my ($refname, $pathname) = split(/:/, $path_info, 2);
539 if (defined $pathname) {
540 # we got "project.git/branch:filename" or "project.git/branch:dir/"
541 # we could use git_get_type(branch:pathname), but it needs $git_dir
542 $pathname =~ s
,^/+,,;
543 if (!$pathname || substr($pathname, -1) eq "/") {
544 $input_params{'action'} = "tree";
547 $input_params{'action'} = "blob_plain";
549 $input_params{'hash_base'} ||= $refname;
550 $input_params{'file_name'} ||= $pathname;
551 } elsif (defined $refname) {
552 # we got "project.git/branch"
553 $input_params{'action'} = "shortlog";
554 $input_params{'hash'} ||= $refname;
557 evaluate_path_info
();
559 our $action = $input_params{'action'};
560 if (defined $action) {
561 if (!validate_action
($action)) {
562 die_error
(400, "Invalid action parameter");
566 # parameters which are pathnames
567 our $project = $input_params{'project'};
568 if (defined $project) {
569 if (!validate_project
($project)) {
571 die_error
(404, "No such project");
575 our $file_name = $input_params{'file_name'};
576 if (defined $file_name) {
577 if (!validate_pathname
($file_name)) {
578 die_error
(400, "Invalid file parameter");
582 our $file_parent = $input_params{'file_parent'};
583 if (defined $file_parent) {
584 if (!validate_pathname
($file_parent)) {
585 die_error
(400, "Invalid file parent parameter");
589 # parameters which are refnames
590 our $hash = $input_params{'hash'};
592 if (!validate_refname
($hash)) {
593 die_error
(400, "Invalid hash parameter");
597 our $hash_parent = $input_params{'hash_parent'};
598 if (defined $hash_parent) {
599 if (!validate_refname
($hash_parent)) {
600 die_error
(400, "Invalid hash parent parameter");
604 our $hash_base = $input_params{'hash_base'};
605 if (defined $hash_base) {
606 if (!validate_refname
($hash_base)) {
607 die_error
(400, "Invalid hash base parameter");
611 our @extra_options = @{$input_params{'extra_options'}};
612 # @extra_options is always defined, since it can only be (currently) set from
613 # CGI, and $cgi->param() returns the empty array in array context if the param
615 foreach my $opt (@extra_options) {
616 if (not exists $allowed_options{$opt}) {
617 die_error
(400, "Invalid option parameter");
619 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
620 die_error
(400, "Invalid option parameter for this action");
624 our $hash_parent_base = $input_params{'hash_parent_base'};
625 if (defined $hash_parent_base) {
626 if (!validate_refname
($hash_parent_base)) {
627 die_error
(400, "Invalid hash parent base parameter");
632 our $page = $input_params{'page'};
634 if ($page =~ m/[^0-9]/) {
635 die_error
(400, "Invalid page parameter");
639 our $searchtype = $input_params{'searchtype'};
640 if (defined $searchtype) {
641 if ($searchtype =~ m/[^a-z]/) {
642 die_error
(400, "Invalid searchtype parameter");
646 our $search_use_regexp = $input_params{'search_use_regexp'};
648 our $searchtext = $input_params{'searchtext'};
650 if (defined $searchtext) {
651 if (length($searchtext) < 2) {
652 die_error
(403, "At least two characters are required for search parameter");
654 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
657 # path to the current git repository
659 $git_dir = "$projectroot/$project" if $project;
662 if (!defined $action) {
664 $action = git_get_type
($hash);
665 } elsif (defined $hash_base && defined $file_name) {
666 $action = git_get_type
("$hash_base:$file_name");
667 } elsif (defined $project) {
670 $action = 'project_list';
673 if (!defined($actions{$action})) {
674 die_error
(400, "Unknown action");
676 if ($action !~ m/^(opml|project_list|project_index)$/ &&
678 die_error
(400, "Project needed");
680 $actions{$action}->();
683 ## ======================================================================
688 # default is to use -absolute url() i.e. $my_uri
689 my $href = $params{-full
} ? $my_url : $my_uri;
691 $params{'project'} = $project unless exists $params{'project'};
693 if ($params{-replay
}) {
694 while (my ($name, $symbol) = each %cgi_param_mapping) {
695 if (!exists $params{$name}) {
696 $params{$name} = $input_params{$name};
701 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
703 # use PATH_INFO for project name
704 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
705 delete $params{'project'};
707 # Summary just uses the project path URL
708 if (defined $params{'action'} && $params{'action'} eq 'summary') {
709 delete $params{'action'};
713 # now encode the parameters explicitly
715 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
716 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
717 if (defined $params{$name}) {
718 if (ref($params{$name}) eq "ARRAY") {
719 foreach my $par (@{$params{$name}}) {
720 push @result, $symbol . "=" . esc_param
($par);
723 push @result, $symbol . "=" . esc_param
($params{$name});
727 $href .= "?" . join(';', @result) if scalar @result;
733 ## ======================================================================
734 ## validation, quoting/unquoting and escaping
736 sub validate_action
{
737 my $input = shift || return undef;
738 return undef unless exists $actions{$input};
742 sub validate_project
{
743 my $input = shift || return undef;
744 if (!validate_pathname
($input) ||
745 !(-d
"$projectroot/$input") ||
746 !check_head_link
("$projectroot/$input") ||
747 ($export_ok && !(-e
"$projectroot/$input/$export_ok")) ||
748 ($strict_export && !project_in_list
($input))) {
755 sub validate_pathname
{
756 my $input = shift || return undef;
758 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
759 # at the beginning, at the end, and between slashes.
760 # also this catches doubled slashes
761 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
765 if ($input =~ m!\0!) {
771 sub validate_refname
{
772 my $input = shift || return undef;
774 # textual hashes are O.K.
775 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
778 # it must be correct pathname
779 $input = validate_pathname
($input)
781 # restrictions on ref name according to git-check-ref-format
782 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
788 # decode sequences of octets in utf8 into Perl's internal form,
789 # which is utf-8 with utf8 flag set if needed. gitweb writes out
790 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
793 if (utf8
::valid
($str)) {
797 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
801 # quote unsafe chars, but keep the slash, even when it's not
802 # correct, but quoted slashes look too horrible in bookmarks
805 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
811 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
814 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
820 # replace invalid utf8 character with SUBSTITUTION sequence
825 $str = to_utf8
($str);
826 $str = $cgi->escapeHTML($str);
827 if ($opts{'-nbsp'}) {
828 $str =~ s/ / /g;
830 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
834 # quote control characters and escape filename to HTML
839 $str = to_utf8
($str);
840 $str = $cgi->escapeHTML($str);
841 if ($opts{'-nbsp'}) {
842 $str =~ s/ / /g;
844 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
848 # Make control characters "printable", using character escape codes (CEC)
852 my %es = ( # character escape codes, aka escape sequences
853 "\t" => '\t', # tab (HT)
854 "\n" => '\n', # line feed (LF)
855 "\r" => '\r', # carrige return (CR)
856 "\f" => '\f', # form feed (FF)
857 "\b" => '\b', # backspace (BS)
858 "\a" => '\a', # alarm (bell) (BEL)
859 "\e" => '\e', # escape (ESC)
860 "\013" => '\v', # vertical tab (VT)
861 "\000" => '\0', # nul character (NUL)
863 my $chr = ( (exists $es{$cntrl})
865 : sprintf('\%2x', ord($cntrl)) );
866 if ($opts{-nohtml
}) {
869 return "<span class=\"cntrl\">$chr</span>";
873 # Alternatively use unicode control pictures codepoints,
874 # Unicode "printable representation" (PR)
879 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
880 if ($opts{-nohtml
}) {
883 return "<span class=\"cntrl\">$chr</span>";
887 # git may return quoted and escaped filenames
893 my %es = ( # character escape codes, aka escape sequences
894 't' => "\t", # tab (HT, TAB)
895 'n' => "\n", # newline (NL)
896 'r' => "\r", # return (CR)
897 'f' => "\f", # form feed (FF)
898 'b' => "\b", # backspace (BS)
899 'a' => "\a", # alarm (bell) (BEL)
900 'e' => "\e", # escape (ESC)
901 'v' => "\013", # vertical tab (VT)
904 if ($seq =~ m/^[0-7]{1,3}$/) {
905 # octal char sequence
906 return chr(oct($seq));
907 } elsif (exists $es{$seq}) {
908 # C escape sequence, aka character escape code
911 # quoted ordinary character
915 if ($str =~ m/^"(.*)"$/) {
918 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
923 # escape tabs (convert tabs to spaces)
927 while ((my $pos = index($line, "\t")) != -1) {
928 if (my $count = (8 - ($pos % 8))) {
929 my $spaces = ' ' x
$count;
930 $line =~ s/\t/$spaces/;
937 sub project_in_list
{
939 my @list = git_get_projects_list
();
940 return @list && scalar(grep { $_->{'path'} eq $project } @list);
943 ## ----------------------------------------------------------------------
944 ## HTML aware string manipulation
946 # Try to chop given string on a word boundary between position
947 # $len and $len+$add_len. If there is no word boundary there,
948 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
949 # (marking chopped part) would be longer than given string.
953 my $add_len = shift || 10;
954 my $where = shift || 'right'; # 'left' | 'center' | 'right'
956 # Make sure perl knows it is utf8 encoded so we don't
957 # cut in the middle of a utf8 multibyte char.
958 $str = to_utf8
($str);
960 # allow only $len chars, but don't cut a word if it would fit in $add_len
961 # if it doesn't fit, cut it if it's still longer than the dots we would add
962 # remove chopped character entities entirely
964 # when chopping in the middle, distribute $len into left and right part
965 # return early if chopping wouldn't make string shorter
966 if ($where eq 'center') {
967 return $str if ($len + 5 >= length($str)); # filler is length 5
970 return $str if ($len + 4 >= length($str)); # filler is length 4
973 # regexps: ending and beginning with word part up to $add_len
974 my $endre = qr/.{$len}\w{0,$add_len}/;
975 my $begre = qr/\w{0,$add_len}.{$len}/;
977 if ($where eq 'left') {
978 $str =~ m/^(.*?)($begre)$/;
979 my ($lead, $body) = ($1, $2);
980 if (length($lead) > 4) {
981 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
986 } elsif ($where eq 'center') {
987 $str =~ m/^($endre)(.*)$/;
988 my ($left, $str) = ($1, $2);
989 $str =~ m/^(.*?)($begre)$/;
990 my ($mid, $right) = ($1, $2);
991 if (length($mid) > 5) {
992 $left =~ s/&[^;]*$//;
993 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
996 return "$left$mid$right";
999 $str =~ m/^($endre)(.*)$/;
1002 if (length($tail) > 4) {
1003 $body =~ s/&[^;]*$//;
1006 return "$body$tail";
1010 # takes the same arguments as chop_str, but also wraps a <span> around the
1011 # result with a title attribute if it does get chopped. Additionally, the
1012 # string is HTML-escaped.
1013 sub chop_and_escape_str
{
1016 my $chopped = chop_str
(@_);
1017 if ($chopped eq $str) {
1018 return esc_html
($chopped);
1020 $str =~ s/([[:cntrl:]])/?/g;
1021 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1025 ## ----------------------------------------------------------------------
1026 ## functions returning short strings
1028 # CSS class for given age value (in seconds)
1032 if (!defined $age) {
1034 } elsif ($age < 60*60*2) {
1036 } elsif ($age < 60*60*24*2) {
1043 # convert age in seconds to "nn units ago" string
1048 if ($age > 60*60*24*365*2) {
1049 $age_str = (int $age/60/60/24/365);
1050 $age_str .= " years ago";
1051 } elsif ($age > 60*60*24*(365/12)*2) {
1052 $age_str = int $age/60/60/24/(365/12);
1053 $age_str .= " months ago";
1054 } elsif ($age > 60*60*24*7*2) {
1055 $age_str = int $age/60/60/24/7;
1056 $age_str .= " weeks ago";
1057 } elsif ($age > 60*60*24*2) {
1058 $age_str = int $age/60/60/24;
1059 $age_str .= " days ago";
1060 } elsif ($age > 60*60*2) {
1061 $age_str = int $age/60/60;
1062 $age_str .= " hours ago";
1063 } elsif ($age > 60*2) {
1064 $age_str = int $age/60;
1065 $age_str .= " min ago";
1066 } elsif ($age > 2) {
1067 $age_str = int $age;
1068 $age_str .= " sec ago";
1070 $age_str .= " right now";
1076 S_IFINVALID
=> 0030000,
1077 S_IFGITLINK
=> 0160000,
1080 # submodule/subproject, a commit object reference
1081 sub S_ISGITLINK
($) {
1084 return (($mode & S_IFMT
) == S_IFGITLINK
)
1087 # convert file mode in octal to symbolic file mode string
1089 my $mode = oct shift;
1091 if (S_ISGITLINK
($mode)) {
1092 return 'm---------';
1093 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1094 return 'drwxr-xr-x';
1095 } elsif (S_ISLNK
($mode)) {
1096 return 'lrwxrwxrwx';
1097 } elsif (S_ISREG
($mode)) {
1098 # git cares only about the executable bit
1099 if ($mode & S_IXUSR
) {
1100 return '-rwxr-xr-x';
1102 return '-rw-r--r--';
1105 return '----------';
1109 # convert file mode in octal to file type string
1113 if ($mode !~ m/^[0-7]+$/) {
1119 if (S_ISGITLINK
($mode)) {
1121 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1123 } elsif (S_ISLNK
($mode)) {
1125 } elsif (S_ISREG
($mode)) {
1132 # convert file mode in octal to file type description string
1133 sub file_type_long
{
1136 if ($mode !~ m/^[0-7]+$/) {
1142 if (S_ISGITLINK
($mode)) {
1144 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1146 } elsif (S_ISLNK
($mode)) {
1148 } elsif (S_ISREG
($mode)) {
1149 if ($mode & S_IXUSR
) {
1150 return "executable";
1160 ## ----------------------------------------------------------------------
1161 ## functions returning short HTML fragments, or transforming HTML fragments
1162 ## which don't belong to other sections
1164 # format line of commit message.
1165 sub format_log_line_html
{
1168 $line = esc_html
($line, -nbsp
=>1);
1169 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1172 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1173 -class => "text"}, $hash_text);
1174 $line =~ s/$hash_text/$link/;
1179 # format marker of refs pointing to given object
1181 # the destination action is chosen based on object type and current context:
1182 # - for annotated tags, we choose the tag view unless it's the current view
1183 # already, in which case we go to shortlog view
1184 # - for other refs, we keep the current view if we're in history, shortlog or
1185 # log view, and select shortlog otherwise
1186 sub format_ref_marker
{
1187 my ($refs, $id) = @_;
1190 if (defined $refs->{$id}) {
1191 foreach my $ref (@{$refs->{$id}}) {
1192 # this code exploits the fact that non-lightweight tags are the
1193 # only indirect objects, and that they are the only objects for which
1194 # we want to use tag instead of shortlog as action
1195 my ($type, $name) = qw();
1196 my $indirect = ($ref =~ s/\^\{\}$//);
1197 # e.g. tags/v2.6.11 or heads/next
1198 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1207 $class .= " indirect" if $indirect;
1209 my $dest_action = "shortlog";
1212 $dest_action = "tag" unless $action eq "tag";
1213 } elsif ($action =~ /^(history|(short)?log)$/) {
1214 $dest_action = $action;
1218 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1221 my $link = $cgi->a({
1223 action
=>$dest_action,
1227 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1233 return ' <span class="refs">'. $markers . '</span>';
1239 # format, perhaps shortened and with markers, title line
1240 sub format_subject_html
{
1241 my ($long, $short, $href, $extra) = @_;
1242 $extra = '' unless defined($extra);
1244 if (length($short) < length($long)) {
1245 return $cgi->a({-href
=> $href, -class => "list subject",
1246 -title
=> to_utf8
($long)},
1247 esc_html
($short) . $extra);
1249 return $cgi->a({-href
=> $href, -class => "list subject"},
1250 esc_html
($long) . $extra);
1254 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1255 sub format_git_diff_header_line
{
1257 my $diffinfo = shift;
1258 my ($from, $to) = @_;
1260 if ($diffinfo->{'nparents'}) {
1262 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1263 if ($to->{'href'}) {
1264 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1265 esc_path
($to->{'file'}));
1266 } else { # file was deleted (no href)
1267 $line .= esc_path
($to->{'file'});
1271 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1272 if ($from->{'href'}) {
1273 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1274 'a/' . esc_path
($from->{'file'}));
1275 } else { # file was added (no href)
1276 $line .= 'a/' . esc_path
($from->{'file'});
1279 if ($to->{'href'}) {
1280 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1281 'b/' . esc_path
($to->{'file'}));
1282 } else { # file was deleted
1283 $line .= 'b/' . esc_path
($to->{'file'});
1287 return "<div class=\"diff header\">$line</div>\n";
1290 # format extended diff header line, before patch itself
1291 sub format_extended_diff_header_line
{
1293 my $diffinfo = shift;
1294 my ($from, $to) = @_;
1297 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1298 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1299 esc_path
($from->{'file'}));
1301 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1302 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1303 esc_path
($to->{'file'}));
1305 # match single <mode>
1306 if ($line =~ m/\s(\d{6})$/) {
1307 $line .= '<span class="info"> (' .
1308 file_type_long
($1) .
1312 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1313 # can match only for combined diff
1315 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1316 if ($from->{'href'}[$i]) {
1317 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1319 substr($diffinfo->{'from_id'}[$i],0,7));
1324 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1327 if ($to->{'href'}) {
1328 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1329 substr($diffinfo->{'to_id'},0,7));
1334 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1335 # can match only for ordinary diff
1336 my ($from_link, $to_link);
1337 if ($from->{'href'}) {
1338 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1339 substr($diffinfo->{'from_id'},0,7));
1341 $from_link = '0' x
7;
1343 if ($to->{'href'}) {
1344 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1345 substr($diffinfo->{'to_id'},0,7));
1349 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1350 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1353 return $line . "<br/>\n";
1356 # format from-file/to-file diff header
1357 sub format_diff_from_to_header
{
1358 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1363 #assert($line =~ m/^---/) if DEBUG;
1364 # no extra formatting for "^--- /dev/null"
1365 if (! $diffinfo->{'nparents'}) {
1366 # ordinary (single parent) diff
1367 if ($line =~ m!^--- "?a/!) {
1368 if ($from->{'href'}) {
1370 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1371 esc_path
($from->{'file'}));
1374 esc_path
($from->{'file'});
1377 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1380 # combined diff (merge commit)
1381 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1382 if ($from->{'href'}[$i]) {
1384 $cgi->a({-href
=>href
(action
=>"blobdiff",
1385 hash_parent
=>$diffinfo->{'from_id'}[$i],
1386 hash_parent_base
=>$parents[$i],
1387 file_parent
=>$from->{'file'}[$i],
1388 hash
=>$diffinfo->{'to_id'},
1390 file_name
=>$to->{'file'}),
1392 -title
=>"diff" . ($i+1)},
1395 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1396 esc_path
($from->{'file'}[$i]));
1398 $line = '--- /dev/null';
1400 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1405 #assert($line =~ m/^\+\+\+/) if DEBUG;
1406 # no extra formatting for "^+++ /dev/null"
1407 if ($line =~ m!^\+\+\+ "?b/!) {
1408 if ($to->{'href'}) {
1410 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1411 esc_path
($to->{'file'}));
1414 esc_path
($to->{'file'});
1417 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1422 # create note for patch simplified by combined diff
1423 sub format_diff_cc_simplified
{
1424 my ($diffinfo, @parents) = @_;
1427 $result .= "<div class=\"diff header\">" .
1429 if (!is_deleted
($diffinfo)) {
1430 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1432 hash
=>$diffinfo->{'to_id'},
1433 file_name
=>$diffinfo->{'to_file'}),
1435 esc_path
($diffinfo->{'to_file'}));
1437 $result .= esc_path
($diffinfo->{'to_file'});
1439 $result .= "</div>\n" . # class="diff header"
1440 "<div class=\"diff nodifferences\">" .
1442 "</div>\n"; # class="diff nodifferences"
1447 # format patch (diff) line (not to be used for diff headers)
1448 sub format_diff_line
{
1450 my ($from, $to) = @_;
1451 my $diff_class = "";
1455 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1457 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1458 if ($line =~ m/^\@{3}/) {
1459 $diff_class = " chunk_header";
1460 } elsif ($line =~ m/^\\/) {
1461 $diff_class = " incomplete";
1462 } elsif ($prefix =~ tr/+/+/) {
1463 $diff_class = " add";
1464 } elsif ($prefix =~ tr/-/-/) {
1465 $diff_class = " rem";
1468 # assume ordinary diff
1469 my $char = substr($line, 0, 1);
1471 $diff_class = " add";
1472 } elsif ($char eq '-') {
1473 $diff_class = " rem";
1474 } elsif ($char eq '@') {
1475 $diff_class = " chunk_header";
1476 } elsif ($char eq "\\") {
1477 $diff_class = " incomplete";
1480 $line = untabify
($line);
1481 if ($from && $to && $line =~ m/^\@{2} /) {
1482 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1483 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1485 $from_lines = 0 unless defined $from_lines;
1486 $to_lines = 0 unless defined $to_lines;
1488 if ($from->{'href'}) {
1489 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1490 -class=>"list"}, $from_text);
1492 if ($to->{'href'}) {
1493 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1494 -class=>"list"}, $to_text);
1496 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1497 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1498 return "<div class=\"diff$diff_class\">$line</div>\n";
1499 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1500 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1501 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1503 @from_text = split(' ', $ranges);
1504 for (my $i = 0; $i < @from_text; ++$i) {
1505 ($from_start[$i], $from_nlines[$i]) =
1506 (split(',', substr($from_text[$i], 1)), 0);
1509 $to_text = pop @from_text;
1510 $to_start = pop @from_start;
1511 $to_nlines = pop @from_nlines;
1513 $line = "<span class=\"chunk_info\">$prefix ";
1514 for (my $i = 0; $i < @from_text; ++$i) {
1515 if ($from->{'href'}[$i]) {
1516 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1517 -class=>"list"}, $from_text[$i]);
1519 $line .= $from_text[$i];
1523 if ($to->{'href'}) {
1524 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1525 -class=>"list"}, $to_text);
1529 $line .= " $prefix</span>" .
1530 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1531 return "<div class=\"diff$diff_class\">$line</div>\n";
1533 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1536 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1537 # linked. Pass the hash of the tree/commit to snapshot.
1538 sub format_snapshot_links
{
1540 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1541 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1542 my $num_fmts = @snapshot_fmts;
1543 if ($num_fmts > 1) {
1544 # A parenthesized list of links bearing format names.
1545 # e.g. "snapshot (_tar.gz_ _zip_)"
1546 return "snapshot (" . join(' ', map
1553 }, $known_snapshot_formats{$_}{'display'})
1554 , @snapshot_fmts) . ")";
1555 } elsif ($num_fmts == 1) {
1556 # A single "snapshot" link whose tooltip bears the format name.
1558 my ($fmt) = @snapshot_fmts;
1564 snapshot_format
=>$fmt
1566 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1568 } else { # $num_fmts == 0
1573 ## ......................................................................
1574 ## functions returning values to be passed, perhaps after some
1575 ## transformation, to other functions; e.g. returning arguments to href()
1577 # returns hash to be passed to href to generate gitweb URL
1578 # in -title key it returns description of link
1580 my $format = shift || 'Atom';
1581 my %res = (action
=> lc($format));
1583 # feed links are possible only for project views
1584 return unless (defined $project);
1585 # some views should link to OPML, or to generic project feed,
1586 # or don't have specific feed yet (so they should use generic)
1587 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1590 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1591 # from tag links; this also makes possible to detect branch links
1592 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1593 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1596 # find log type for feed description (title)
1598 if (defined $file_name) {
1599 $type = "history of $file_name";
1600 $type .= "/" if ($action eq 'tree');
1601 $type .= " on '$branch'" if (defined $branch);
1603 $type = "log of $branch" if (defined $branch);
1606 $res{-title
} = $type;
1607 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1608 $res{'file_name'} = $file_name;
1613 ## ----------------------------------------------------------------------
1614 ## git utility subroutines, invoking git commands
1616 # returns path to the core git executable and the --git-dir parameter as list
1618 return $GIT, '--git-dir='.$git_dir;
1621 # quote the given arguments for passing them to the shell
1622 # quote_command("command", "arg 1", "arg with ' and ! characters")
1623 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1624 # Try to avoid using this function wherever possible.
1627 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1630 # get HEAD ref of given project as hash
1631 sub git_get_head_hash
{
1632 my $project = shift;
1633 my $o_git_dir = $git_dir;
1635 $git_dir = "$projectroot/$project";
1636 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1639 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1643 if (defined $o_git_dir) {
1644 $git_dir = $o_git_dir;
1649 # get type of given object
1653 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1655 close $fd or return;
1660 # repository configuration
1661 our $config_file = '';
1664 # store multiple values for single key as anonymous array reference
1665 # single values stored directly in the hash, not as [ <value> ]
1666 sub hash_set_multi
{
1667 my ($hash, $key, $value) = @_;
1669 if (!exists $hash->{$key}) {
1670 $hash->{$key} = $value;
1671 } elsif (!ref $hash->{$key}) {
1672 $hash->{$key} = [ $hash->{$key}, $value ];
1674 push @{$hash->{$key}}, $value;
1678 # return hash of git project configuration
1679 # optionally limited to some section, e.g. 'gitweb'
1680 sub git_parse_project_config
{
1681 my $section_regexp = shift;
1686 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1689 while (my $keyval = <$fh>) {
1691 my ($key, $value) = split(/\n/, $keyval, 2);
1693 hash_set_multi
(\
%config, $key, $value)
1694 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1701 # convert config value to boolean, 'true' or 'false'
1702 # no value, number > 0, 'true' and 'yes' values are true
1703 # rest of values are treated as false (never as error)
1704 sub config_to_bool
{
1707 # strip leading and trailing whitespace
1711 return (!defined $val || # section.key
1712 ($val =~ /^\d+$/ && $val) || # section.key = 1
1713 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1716 # convert config value to simple decimal number
1717 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1718 # to be multiplied by 1024, 1048576, or 1073741824
1722 # strip leading and trailing whitespace
1726 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1728 # unknown unit is treated as 1
1729 return $num * ($unit eq 'g' ? 1073741824 :
1730 $unit eq 'm' ? 1048576 :
1731 $unit eq 'k' ? 1024 : 1);
1736 # convert config value to array reference, if needed
1737 sub config_to_multi
{
1740 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1743 sub git_get_project_config
{
1744 my ($key, $type) = @_;
1747 return unless ($key);
1748 $key =~ s/^gitweb\.//;
1749 return if ($key =~ m/\W/);
1752 if (defined $type) {
1755 unless ($type eq 'bool' || $type eq 'int');
1759 if (!defined $config_file ||
1760 $config_file ne "$git_dir/config") {
1761 %config = git_parse_project_config
('gitweb');
1762 $config_file = "$git_dir/config";
1766 if (!defined $type) {
1767 return $config{"gitweb.$key"};
1768 } elsif ($type eq 'bool') {
1769 # backward compatibility: 'git config --bool' returns true/false
1770 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1771 } elsif ($type eq 'int') {
1772 return config_to_int
($config{"gitweb.$key"});
1774 return $config{"gitweb.$key"};
1777 # get hash of given path at given ref
1778 sub git_get_hash_by_path
{
1780 my $path = shift || return undef;
1785 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1786 or die_error
(500, "Open git-ls-tree failed");
1788 close $fd or return undef;
1790 if (!defined $line) {
1791 # there is no tree or hash given by $path at $base
1795 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1796 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1797 if (defined $type && $type ne $2) {
1798 # type doesn't match
1804 # get path of entry with given hash at given tree-ish (ref)
1805 # used to get 'from' filename for combined diff (merge commit) for renames
1806 sub git_get_path_by_hash
{
1807 my $base = shift || return;
1808 my $hash = shift || return;
1812 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1814 while (my $line = <$fd>) {
1817 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1818 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1819 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1828 ## ......................................................................
1829 ## git utility functions, directly accessing git repository
1831 sub git_get_project_description
{
1834 $git_dir = "$projectroot/$path";
1835 open my $fd, "$git_dir/description"
1836 or return git_get_project_config
('description');
1839 if (defined $descr) {
1845 sub git_get_project_ctags
{
1849 $git_dir = "$projectroot/$path";
1850 unless (opendir D
, "$git_dir/ctags") {
1853 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
1854 open CT
, $_ or next;
1858 my $ctag = $_; $ctag =~ s
#.*/##;
1859 $ctags->{$ctag} = $val;
1865 sub git_populate_project_tagcloud
{
1868 # First, merge different-cased tags; tags vote on casing
1870 foreach (keys %$ctags) {
1871 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
1872 if (not $ctags_lc{lc $_}->{topcount
}
1873 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
1874 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
1875 $ctags_lc{lc $_}->{topname
} = $_;
1880 if (eval { require HTML
::TagCloud
; 1; }) {
1881 $cloud = HTML
::TagCloud-
>new;
1882 foreach (sort keys %ctags_lc) {
1883 # Pad the title with spaces so that the cloud looks
1885 my $title = $ctags_lc{$_}->{topname
};
1886 $title =~ s/ / /g;
1887 $title =~ s/^/ /g;
1888 $title =~ s/$/ /g;
1889 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
1892 $cloud = \
%ctags_lc;
1897 sub git_show_project_tagcloud
{
1898 my ($cloud, $count) = @_;
1899 print STDERR
ref($cloud)."..\n";
1900 if (ref $cloud eq 'HTML::TagCloud') {
1901 return $cloud->html_and_css($count);
1903 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
1904 return '<p align="center">' . join (', ', map {
1905 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
1906 } splice(@tags, 0, $count)) . '</p>';
1910 sub git_get_project_url_list
{
1913 $git_dir = "$projectroot/$path";
1914 open my $fd, "$git_dir/cloneurl"
1915 or return wantarray ?
1916 @{ config_to_multi
(git_get_project_config
('url')) } :
1917 config_to_multi
(git_get_project_config
('url'));
1918 my @git_project_url_list = map { chomp; $_ } <$fd>;
1921 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1924 sub git_get_projects_list
{
1929 $filter =~ s/\.git$//;
1931 my ($check_forks) = gitweb_check_feature
('forks');
1933 if (-d
$projects_list) {
1934 # search in directory
1935 my $dir = $projects_list . ($filter ? "/$filter" : '');
1936 # remove the trailing "/"
1938 my $pfxlen = length("$dir");
1939 my $pfxdepth = ($dir =~ tr!/!!);
1942 follow_fast
=> 1, # follow symbolic links
1943 follow_skip
=> 2, # ignore duplicates
1944 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1946 # skip project-list toplevel, if we get it.
1947 return if (m!^[/.]$!);
1948 # only directories can be git repositories
1949 return unless (-d
$_);
1950 # don't traverse too deep (Find is super slow on os x)
1951 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1952 $File::Find
::prune
= 1;
1956 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1957 # we check related file in $projectroot
1958 if (check_export_ok
("$projectroot/$filter/$subdir")) {
1959 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1960 $File::Find
::prune
= 1;
1965 } elsif (-f
$projects_list) {
1966 # read from file(url-encoded):
1967 # 'git%2Fgit.git Linus+Torvalds'
1968 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1969 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1971 open my ($fd), $projects_list or return;
1973 while (my $line = <$fd>) {
1975 my ($path, $owner) = split ' ', $line;
1976 $path = unescape
($path);
1977 $owner = unescape
($owner);
1978 if (!defined $path) {
1981 if ($filter ne '') {
1982 # looking for forks;
1983 my $pfx = substr($path, 0, length($filter));
1984 if ($pfx ne $filter) {
1987 my $sfx = substr($path, length($filter));
1988 if ($sfx !~ /^\/.*\
.git
$/) {
1991 } elsif ($check_forks) {
1993 foreach my $filter (keys %paths) {
1994 # looking for forks;
1995 my $pfx = substr($path, 0, length($filter));
1996 if ($pfx ne $filter) {
1999 my $sfx = substr($path, length($filter));
2000 if ($sfx !~ /^\/.*\
.git
$/) {
2003 # is a fork, don't include it in
2008 if (check_export_ok
("$projectroot/$path")) {
2011 owner
=> to_utf8
($owner),
2014 (my $forks_path = $path) =~ s/\.git$//;
2015 $paths{$forks_path}++;
2023 our $gitweb_project_owner = undef;
2024 sub git_get_project_list_from_file
{
2026 return if (defined $gitweb_project_owner);
2028 $gitweb_project_owner = {};
2029 # read from file (url-encoded):
2030 # 'git%2Fgit.git Linus+Torvalds'
2031 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2032 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2033 if (-f
$projects_list) {
2034 open (my $fd , $projects_list);
2035 while (my $line = <$fd>) {
2037 my ($pr, $ow) = split ' ', $line;
2038 $pr = unescape
($pr);
2039 $ow = unescape
($ow);
2040 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2046 sub git_get_project_owner
{
2047 my $project = shift;
2050 return undef unless $project;
2051 $git_dir = "$projectroot/$project";
2053 if (!defined $gitweb_project_owner) {
2054 git_get_project_list_from_file
();
2057 if (exists $gitweb_project_owner->{$project}) {
2058 $owner = $gitweb_project_owner->{$project};
2060 if (!defined $owner){
2061 $owner = git_get_project_config
('owner');
2063 if (!defined $owner) {
2064 $owner = get_file_owner
("$git_dir");
2070 sub git_get_last_activity
{
2074 $git_dir = "$projectroot/$path";
2075 open($fd, "-|", git_cmd
(), 'for-each-ref',
2076 '--format=%(committer)',
2077 '--sort=-committerdate',
2079 'refs/heads') or return;
2080 my $most_recent = <$fd>;
2081 close $fd or return;
2082 if (defined $most_recent &&
2083 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2085 my $age = time - $timestamp;
2086 return ($age, age_string
($age));
2088 return (undef, undef);
2091 sub git_get_references
{
2092 my $type = shift || "";
2094 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2095 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2096 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2097 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2100 while (my $line = <$fd>) {
2102 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2103 if (defined $refs{$1}) {
2104 push @{$refs{$1}}, $2;
2110 close $fd or return;
2114 sub git_get_rev_name_tags
{
2115 my $hash = shift || return undef;
2117 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2119 my $name_rev = <$fd>;
2122 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2125 # catches also '$hash undefined' output
2130 ## ----------------------------------------------------------------------
2131 ## parse to hash functions
2135 my $tz = shift || "-0000";
2138 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2139 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2140 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2141 $date{'hour'} = $hour;
2142 $date{'minute'} = $min;
2143 $date{'mday'} = $mday;
2144 $date{'day'} = $days[$wday];
2145 $date{'month'} = $months[$mon];
2146 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2147 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2148 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2149 $mday, $months[$mon], $hour ,$min;
2150 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2151 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2153 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2154 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2155 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2156 $date{'hour_local'} = $hour;
2157 $date{'minute_local'} = $min;
2158 $date{'tz_local'} = $tz;
2159 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2160 1900+$year, $mon+1, $mday,
2161 $hour, $min, $sec, $tz);
2170 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2171 $tag{'id'} = $tag_id;
2172 while (my $line = <$fd>) {
2174 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2175 $tag{'object'} = $1;
2176 } elsif ($line =~ m/^type (.+)$/) {
2178 } elsif ($line =~ m/^tag (.+)$/) {
2180 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2181 $tag{'author'} = $1;
2184 } elsif ($line =~ m/--BEGIN/) {
2185 push @comment, $line;
2187 } elsif ($line eq "") {
2191 push @comment, <$fd>;
2192 $tag{'comment'} = \
@comment;
2193 close $fd or return;
2194 if (!defined $tag{'name'}) {
2200 sub parse_commit_text
{
2201 my ($commit_text, $withparents) = @_;
2202 my @commit_lines = split '\n', $commit_text;
2205 pop @commit_lines; # Remove '\0'
2207 if (! @commit_lines) {
2211 my $header = shift @commit_lines;
2212 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2215 ($co{'id'}, my @parents) = split ' ', $header;
2216 while (my $line = shift @commit_lines) {
2217 last if $line eq "\n";
2218 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2220 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2222 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2224 $co{'author_epoch'} = $2;
2225 $co{'author_tz'} = $3;
2226 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2227 $co{'author_name'} = $1;
2228 $co{'author_email'} = $2;
2230 $co{'author_name'} = $co{'author'};
2232 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2233 $co{'committer'} = $1;
2234 $co{'committer_epoch'} = $2;
2235 $co{'committer_tz'} = $3;
2236 $co{'committer_name'} = $co{'committer'};
2237 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2238 $co{'committer_name'} = $1;
2239 $co{'committer_email'} = $2;
2241 $co{'committer_name'} = $co{'committer'};
2245 if (!defined $co{'tree'}) {
2248 $co{'parents'} = \
@parents;
2249 $co{'parent'} = $parents[0];
2251 foreach my $title (@commit_lines) {
2254 $co{'title'} = chop_str
($title, 80, 5);
2255 # remove leading stuff of merges to make the interesting part visible
2256 if (length($title) > 50) {
2257 $title =~ s/^Automatic //;
2258 $title =~ s/^merge (of|with) /Merge ... /i;
2259 if (length($title) > 50) {
2260 $title =~ s/(http|rsync):\/\///;
2262 if (length($title) > 50) {
2263 $title =~ s/(master|www|rsync)\.//;
2265 if (length($title) > 50) {
2266 $title =~ s/kernel.org:?//;
2268 if (length($title) > 50) {
2269 $title =~ s/\/pub\/scm//;
2272 $co{'title_short'} = chop_str
($title, 50, 5);
2276 if (! defined $co{'title'} || $co{'title'} eq "") {
2277 $co{'title'} = $co{'title_short'} = '(no commit message)';
2279 # remove added spaces
2280 foreach my $line (@commit_lines) {
2283 $co{'comment'} = \
@commit_lines;
2285 my $age = time - $co{'committer_epoch'};
2287 $co{'age_string'} = age_string
($age);
2288 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2289 if ($age > 60*60*24*7*2) {
2290 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2291 $co{'age_string_age'} = $co{'age_string'};
2293 $co{'age_string_date'} = $co{'age_string'};
2294 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2300 my ($commit_id) = @_;
2305 open my $fd, "-|", git_cmd
(), "rev-list",
2311 or die_error
(500, "Open git-rev-list failed");
2312 %co = parse_commit_text
(<$fd>, 1);
2319 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2327 open my $fd, "-|", git_cmd
(), "rev-list",
2330 ("--max-count=" . $maxcount),
2331 ("--skip=" . $skip),
2335 ($filename ? ($filename) : ())
2336 or die_error
(500, "Open git-rev-list failed");
2337 while (my $line = <$fd>) {
2338 my %co = parse_commit_text
($line);
2343 return wantarray ? @cos : \
@cos;
2346 # parse line of git-diff-tree "raw" output
2347 sub parse_difftree_raw_line
{
2351 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2352 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2353 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2354 $res{'from_mode'} = $1;
2355 $res{'to_mode'} = $2;
2356 $res{'from_id'} = $3;
2358 $res{'status'} = $5;
2359 $res{'similarity'} = $6;
2360 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2361 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2363 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2366 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2367 # combined diff (for merge commit)
2368 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2369 $res{'nparents'} = length($1);
2370 $res{'from_mode'} = [ split(' ', $2) ];
2371 $res{'to_mode'} = pop @{$res{'from_mode'}};
2372 $res{'from_id'} = [ split(' ', $3) ];
2373 $res{'to_id'} = pop @{$res{'from_id'}};
2374 $res{'status'} = [ split('', $4) ];
2375 $res{'to_file'} = unquote
($5);
2377 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2378 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2379 $res{'commit'} = $1;
2382 return wantarray ? %res : \
%res;
2385 # wrapper: return parsed line of git-diff-tree "raw" output
2386 # (the argument might be raw line, or parsed info)
2387 sub parsed_difftree_line
{
2388 my $line_or_ref = shift;
2390 if (ref($line_or_ref) eq "HASH") {
2391 # pre-parsed (or generated by hand)
2392 return $line_or_ref;
2394 return parse_difftree_raw_line
($line_or_ref);
2398 # parse line of git-ls-tree output
2399 sub parse_ls_tree_line
($;%) {
2404 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2405 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2413 $res{'name'} = unquote
($4);
2416 return wantarray ? %res : \
%res;
2419 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2420 sub parse_from_to_diffinfo
{
2421 my ($diffinfo, $from, $to, @parents) = @_;
2423 if ($diffinfo->{'nparents'}) {
2425 $from->{'file'} = [];
2426 $from->{'href'} = [];
2427 fill_from_file_info
($diffinfo, @parents)
2428 unless exists $diffinfo->{'from_file'};
2429 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2430 $from->{'file'}[$i] =
2431 defined $diffinfo->{'from_file'}[$i] ?
2432 $diffinfo->{'from_file'}[$i] :
2433 $diffinfo->{'to_file'};
2434 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2435 $from->{'href'}[$i] = href
(action
=>"blob",
2436 hash_base
=>$parents[$i],
2437 hash
=>$diffinfo->{'from_id'}[$i],
2438 file_name
=>$from->{'file'}[$i]);
2440 $from->{'href'}[$i] = undef;
2444 # ordinary (not combined) diff
2445 $from->{'file'} = $diffinfo->{'from_file'};
2446 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2447 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2448 hash
=>$diffinfo->{'from_id'},
2449 file_name
=>$from->{'file'});
2451 delete $from->{'href'};
2455 $to->{'file'} = $diffinfo->{'to_file'};
2456 if (!is_deleted
($diffinfo)) { # file exists in result
2457 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2458 hash
=>$diffinfo->{'to_id'},
2459 file_name
=>$to->{'file'});
2461 delete $to->{'href'};
2465 ## ......................................................................
2466 ## parse to array of hashes functions
2468 sub git_get_heads_list
{
2472 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2473 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2474 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2477 while (my $line = <$fd>) {
2481 my ($refinfo, $committerinfo) = split(/\0/, $line);
2482 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2483 my ($committer, $epoch, $tz) =
2484 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2485 $ref_item{'fullname'} = $name;
2486 $name =~ s!^refs/heads/!!;
2488 $ref_item{'name'} = $name;
2489 $ref_item{'id'} = $hash;
2490 $ref_item{'title'} = $title || '(no commit message)';
2491 $ref_item{'epoch'} = $epoch;
2493 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2495 $ref_item{'age'} = "unknown";
2498 push @headslist, \
%ref_item;
2502 return wantarray ? @headslist : \
@headslist;
2505 sub git_get_tags_list
{
2509 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2510 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2511 '--format=%(objectname) %(objecttype) %(refname) '.
2512 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2515 while (my $line = <$fd>) {
2519 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2520 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2521 my ($creator, $epoch, $tz) =
2522 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2523 $ref_item{'fullname'} = $name;
2524 $name =~ s!^refs/tags/!!;
2526 $ref_item{'type'} = $type;
2527 $ref_item{'id'} = $id;
2528 $ref_item{'name'} = $name;
2529 if ($type eq "tag") {
2530 $ref_item{'subject'} = $title;
2531 $ref_item{'reftype'} = $reftype;
2532 $ref_item{'refid'} = $refid;
2534 $ref_item{'reftype'} = $type;
2535 $ref_item{'refid'} = $id;
2538 if ($type eq "tag" || $type eq "commit") {
2539 $ref_item{'epoch'} = $epoch;
2541 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2543 $ref_item{'age'} = "unknown";
2547 push @tagslist, \
%ref_item;
2551 return wantarray ? @tagslist : \
@tagslist;
2554 ## ----------------------------------------------------------------------
2555 ## filesystem-related functions
2557 sub get_file_owner
{
2560 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2561 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2562 if (!defined $gcos) {
2566 $owner =~ s/[,;].*$//;
2567 return to_utf8
($owner);
2570 ## ......................................................................
2571 ## mimetype related functions
2573 sub mimetype_guess_file
{
2574 my $filename = shift;
2575 my $mimemap = shift;
2576 -r
$mimemap or return undef;
2579 open(MIME
, $mimemap) or return undef;
2581 next if m/^#/; # skip comments
2582 my ($mime, $exts) = split(/\t+/);
2583 if (defined $exts) {
2584 my @exts = split(/\s+/, $exts);
2585 foreach my $ext (@exts) {
2586 $mimemap{$ext} = $mime;
2592 $filename =~ /\.([^.]*)$/;
2593 return $mimemap{$1};
2596 sub mimetype_guess
{
2597 my $filename = shift;
2599 $filename =~ /\./ or return undef;
2601 if ($mimetypes_file) {
2602 my $file = $mimetypes_file;
2603 if ($file !~ m!^/!) { # if it is relative path
2604 # it is relative to project
2605 $file = "$projectroot/$project/$file";
2607 $mime = mimetype_guess_file
($filename, $file);
2609 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2615 my $filename = shift;
2618 my $mime = mimetype_guess
($filename);
2619 $mime and return $mime;
2623 return $default_blob_plain_mimetype unless $fd;
2626 return 'text/plain';
2627 } elsif (! $filename) {
2628 return 'application/octet-stream';
2629 } elsif ($filename =~ m/\.png$/i) {
2631 } elsif ($filename =~ m/\.gif$/i) {
2633 } elsif ($filename =~ m/\.jpe?g$/i) {
2634 return 'image/jpeg';
2636 return 'application/octet-stream';
2640 sub blob_contenttype
{
2641 my ($fd, $file_name, $type) = @_;
2643 $type ||= blob_mimetype
($fd, $file_name);
2644 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2645 $type .= "; charset=$default_text_plain_charset";
2651 ## ======================================================================
2652 ## functions printing HTML: header, footer, error page
2654 sub git_header_html
{
2655 my $status = shift || "200 OK";
2656 my $expires = shift;
2658 my $title = "$site_name";
2659 if (defined $project) {
2660 $title .= " - " . to_utf8
($project);
2661 if (defined $action) {
2662 $title .= "/$action";
2663 if (defined $file_name) {
2664 $title .= " - " . esc_path
($file_name);
2665 if ($action eq "tree" && $file_name !~ m
|/$|) {
2672 # require explicit support from the UA if we are to send the page as
2673 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2674 # we have to do this because MSIE sometimes globs '*/*', pretending to
2675 # support xhtml+xml but choking when it gets what it asked for.
2676 if (defined $cgi->http('HTTP_ACCEPT') &&
2677 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2678 $cgi->Accept('application/xhtml+xml') != 0) {
2679 $content_type = 'application/xhtml+xml';
2681 $content_type = 'text/html';
2683 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2684 -status
=> $status, -expires
=> $expires);
2685 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2687 <?xml version="1.0" encoding="utf-8"?>
2688 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2689 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2690 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2691 <!-- git core binaries version $git_version -->
2693 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2694 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2695 <meta name="robots" content="index, nofollow"/>
2696 <title>$title</title>
2698 # print out each stylesheet that exist
2699 if (defined $stylesheet) {
2700 #provides backwards capability for those people who define style sheet in a config file
2701 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2703 foreach my $stylesheet (@stylesheets) {
2704 next unless $stylesheet;
2705 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2708 if (defined $project) {
2709 my %href_params = get_feed_info
();
2710 if (!exists $href_params{'-title'}) {
2711 $href_params{'-title'} = 'log';
2714 foreach my $format qw(RSS Atom) {
2715 my $type = lc($format);
2717 '-rel' => 'alternate',
2718 '-title' => "$project - $href_params{'-title'} - $format feed",
2719 '-type' => "application/$type+xml"
2722 $href_params{'action'} = $type;
2723 $link_attr{'-href'} = href
(%href_params);
2725 "rel=\"$link_attr{'-rel'}\" ".
2726 "title=\"$link_attr{'-title'}\" ".
2727 "href=\"$link_attr{'-href'}\" ".
2728 "type=\"$link_attr{'-type'}\" ".
2731 $href_params{'extra_options'} = '--no-merges';
2732 $link_attr{'-href'} = href
(%href_params);
2733 $link_attr{'-title'} .= ' (no merges)';
2735 "rel=\"$link_attr{'-rel'}\" ".
2736 "title=\"$link_attr{'-title'}\" ".
2737 "href=\"$link_attr{'-href'}\" ".
2738 "type=\"$link_attr{'-type'}\" ".
2743 printf('<link rel="alternate" title="%s projects list" '.
2744 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2745 $site_name, href
(project
=>undef, action
=>"project_index"));
2746 printf('<link rel="alternate" title="%s projects feeds" '.
2747 'href="%s" type="text/x-opml" />'."\n",
2748 $site_name, href
(project
=>undef, action
=>"opml"));
2750 if (defined $favicon) {
2751 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2757 if (-f
$site_header) {
2758 open (my $fd, $site_header);
2763 print "<div class=\"page_header\">\n" .
2764 $cgi->a({-href
=> esc_url
($logo_url),
2765 -title
=> $logo_label},
2766 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2767 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2768 if (defined $project) {
2769 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2770 if (defined $action) {
2777 my ($have_search) = gitweb_check_feature
('search');
2778 if (defined $project && $have_search) {
2779 if (!defined $searchtext) {
2783 if (defined $hash_base) {
2784 $search_hash = $hash_base;
2785 } elsif (defined $hash) {
2786 $search_hash = $hash;
2788 $search_hash = "HEAD";
2790 my $action = $my_uri;
2791 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2792 if ($use_pathinfo) {
2793 $action .= "/".esc_url
($project);
2795 print $cgi->startform(-method => "get", -action
=> $action) .
2796 "<div class=\"search\">\n" .
2798 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2799 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2800 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2801 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2802 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2803 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2805 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2806 "<span title=\"Extended regular expression\">" .
2807 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2808 -checked
=> $search_use_regexp) .
2811 $cgi->end_form() . "\n";
2815 sub git_footer_html
{
2816 my $feed_class = 'rss_logo';
2818 print "<div class=\"page_footer\">\n";
2819 if (defined $project) {
2820 my $descr = git_get_project_description
($project);
2821 if (defined $descr) {
2822 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2825 my %href_params = get_feed_info
();
2826 if (!%href_params) {
2827 $feed_class .= ' generic';
2829 $href_params{'-title'} ||= 'log';
2831 foreach my $format qw(RSS Atom) {
2832 $href_params{'action'} = lc($format);
2833 print $cgi->a({-href
=> href
(%href_params),
2834 -title
=> "$href_params{'-title'} $format feed",
2835 -class => $feed_class}, $format)."\n";
2839 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2840 -class => $feed_class}, "OPML") . " ";
2841 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2842 -class => $feed_class}, "TXT") . "\n";
2844 print "</div>\n"; # class="page_footer"
2846 if (-f
$site_footer) {
2847 open (my $fd, $site_footer);
2856 # die_error(<http_status_code>, <error_message>)
2857 # Example: die_error(404, 'Hash not found')
2858 # By convention, use the following status codes (as defined in RFC 2616):
2859 # 400: Invalid or missing CGI parameters, or
2860 # requested object exists but has wrong type.
2861 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2862 # this server or project.
2863 # 404: Requested object/revision/project doesn't exist.
2864 # 500: The server isn't configured properly, or
2865 # an internal error occurred (e.g. failed assertions caused by bugs), or
2866 # an unknown error occurred (e.g. the git binary died unexpectedly).
2868 my $status = shift || 500;
2869 my $error = shift || "Internal server error";
2871 my %http_responses = (400 => '400 Bad Request',
2872 403 => '403 Forbidden',
2873 404 => '404 Not Found',
2874 500 => '500 Internal Server Error');
2875 git_header_html
($http_responses{$status});
2877 <div class="page_body">
2887 ## ----------------------------------------------------------------------
2888 ## functions printing or outputting HTML: navigation
2890 sub git_print_page_nav
{
2891 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2892 $extra = '' if !defined $extra; # pager or formats
2894 my @navs = qw(summary shortlog log commit commitdiff tree);
2896 @navs = grep { $_ ne $suppress } @navs;
2899 my %arg = map { $_ => {action
=>$_} } @navs;
2900 if (defined $head) {
2901 for (qw(commit commitdiff)) {
2902 $arg{$_}{'hash'} = $head;
2904 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2905 for (qw(shortlog log)) {
2906 $arg{$_}{'hash'} = $head;
2911 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2912 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2914 my @actions = gitweb_check_feature
('actions');
2917 'n' => $project, # project name
2918 'f' => $git_dir, # project path within filesystem
2919 'h' => $treehead || '', # current hash ('h' parameter)
2920 'b' => $treebase || '', # hash base ('hb' parameter)
2923 my ($label, $link, $pos) = splice(@actions,0,3);
2925 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2927 $link =~ s/%([%nfhb])/$repl{$1}/g;
2928 $arg{$label}{'_href'} = $link;
2931 print "<div class=\"page_nav\">\n" .
2933 map { $_ eq $current ?
2934 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
2936 print "<br/>\n$extra<br/>\n" .
2940 sub format_paging_nav
{
2941 my ($action, $hash, $head, $page, $has_next_link) = @_;
2945 if ($hash ne $head || $page) {
2946 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2948 $paging_nav .= "HEAD";
2952 $paging_nav .= " ⋅ " .
2953 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2954 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2956 $paging_nav .= " ⋅ prev";
2959 if ($has_next_link) {
2960 $paging_nav .= " ⋅ " .
2961 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2962 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2964 $paging_nav .= " ⋅ next";
2970 ## ......................................................................
2971 ## functions printing or outputting HTML: div
2973 sub git_print_header_div
{
2974 my ($action, $title, $hash, $hash_base) = @_;
2977 $args{'action'} = $action;
2978 $args{'hash'} = $hash if $hash;
2979 $args{'hash_base'} = $hash_base if $hash_base;
2981 print "<div class=\"header\">\n" .
2982 $cgi->a({-href
=> href
(%args), -class => "title"},
2983 $title ? $title : $action) .
2987 #sub git_print_authorship (\%) {
2988 sub git_print_authorship
{
2991 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2992 print "<div class=\"author_date\">" .
2993 esc_html
($co->{'author_name'}) .
2995 if ($ad{'hour_local'} < 6) {
2996 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2997 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2999 printf(" (%02d:%02d %s)",
3000 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3005 sub git_print_page_path
{
3011 print "<div class=\"page_path\">";
3012 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3013 -title
=> 'tree root'}, to_utf8
("[$project]"));
3015 if (defined $name) {
3016 my @dirname = split '/', $name;
3017 my $basename = pop @dirname;
3020 foreach my $dir (@dirname) {
3021 $fullname .= ($fullname ? '/' : '') . $dir;
3022 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3024 -title
=> $fullname}, esc_path
($dir));
3027 if (defined $type && $type eq 'blob') {
3028 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3030 -title
=> $name}, esc_path
($basename));
3031 } elsif (defined $type && $type eq 'tree') {
3032 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3034 -title
=> $name}, esc_path
($basename));
3037 print esc_path
($basename);
3040 print "<br/></div>\n";
3043 # sub git_print_log (\@;%) {
3044 sub git_print_log
($;%) {
3048 if ($opts{'-remove_title'}) {
3049 # remove title, i.e. first line of log
3052 # remove leading empty lines
3053 while (defined $log->[0] && $log->[0] eq "") {
3060 foreach my $line (@$log) {
3061 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3064 if (! $opts{'-remove_signoff'}) {
3065 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3068 # remove signoff lines
3075 # print only one empty line
3076 # do not print empty line after signoff
3078 next if ($empty || $signoff);
3084 print format_log_line_html
($line) . "<br/>\n";
3087 if ($opts{'-final_empty_line'}) {
3088 # end with single empty line
3089 print "<br/>\n" unless $empty;
3093 # return link target (what link points to)
3094 sub git_get_link_target
{
3099 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3103 $link_target = <$fd>;
3108 return $link_target;
3111 # given link target, and the directory (basedir) the link is in,
3112 # return target of link relative to top directory (top tree);
3113 # return undef if it is not possible (including absolute links).
3114 sub normalize_link_target
{
3115 my ($link_target, $basedir, $hash_base) = @_;
3117 # we can normalize symlink target only if $hash_base is provided
3118 return unless $hash_base;
3120 # absolute symlinks (beginning with '/') cannot be normalized
3121 return if (substr($link_target, 0, 1) eq '/');
3123 # normalize link target to path from top (root) tree (dir)
3126 $path = $basedir . '/' . $link_target;
3128 # we are in top (root) tree (dir)
3129 $path = $link_target;
3132 # remove //, /./, and /../
3134 foreach my $part (split('/', $path)) {
3135 # discard '.' and ''
3136 next if (!$part || $part eq '.');
3138 if ($part eq '..') {
3142 # link leads outside repository (outside top dir)
3146 push @path_parts, $part;
3149 $path = join('/', @path_parts);
3154 # print tree entry (row of git_tree), but without encompassing <tr> element
3155 sub git_print_tree_entry
{
3156 my ($t, $basedir, $hash_base, $have_blame) = @_;
3159 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3161 # The format of a table row is: mode list link. Where mode is
3162 # the mode of the entry, list is the name of the entry, an href,
3163 # and link is the action links of the entry.
3165 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3166 if ($t->{'type'} eq "blob") {
3167 print "<td class=\"list\">" .
3168 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3169 file_name
=>"$basedir$t->{'name'}", %base_key),
3170 -class => "list"}, esc_path
($t->{'name'}));
3171 if (S_ISLNK
(oct $t->{'mode'})) {
3172 my $link_target = git_get_link_target
($t->{'hash'});
3174 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3175 if (defined $norm_target) {
3177 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3178 file_name
=>$norm_target),
3179 -title
=> $norm_target}, esc_path
($link_target));
3181 print " -> " . esc_path
($link_target);
3186 print "<td class=\"link\">";
3187 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3188 file_name
=>"$basedir$t->{'name'}", %base_key)},
3192 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3193 file_name
=>"$basedir$t->{'name'}", %base_key)},
3196 if (defined $hash_base) {
3198 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3199 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3203 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3204 file_name
=>"$basedir$t->{'name'}")},
3208 } elsif ($t->{'type'} eq "tree") {
3209 print "<td class=\"list\">";
3210 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3211 file_name
=>"$basedir$t->{'name'}", %base_key)},
3212 esc_path
($t->{'name'}));
3214 print "<td class=\"link\">";
3215 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3216 file_name
=>"$basedir$t->{'name'}", %base_key)},
3218 if (defined $hash_base) {
3220 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3221 file_name
=>"$basedir$t->{'name'}")},
3226 # unknown object: we can only present history for it
3227 # (this includes 'commit' object, i.e. submodule support)
3228 print "<td class=\"list\">" .
3229 esc_path
($t->{'name'}) .
3231 print "<td class=\"link\">";
3232 if (defined $hash_base) {
3233 print $cgi->a({-href
=> href
(action
=>"history",
3234 hash_base
=>$hash_base,
3235 file_name
=>"$basedir$t->{'name'}")},
3242 ## ......................................................................
3243 ## functions printing large fragments of HTML
3245 # get pre-image filenames for merge (combined) diff
3246 sub fill_from_file_info
{
3247 my ($diff, @parents) = @_;
3249 $diff->{'from_file'} = [ ];
3250 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3251 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3252 if ($diff->{'status'}[$i] eq 'R' ||
3253 $diff->{'status'}[$i] eq 'C') {
3254 $diff->{'from_file'}[$i] =
3255 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3262 # is current raw difftree line of file deletion
3264 my $diffinfo = shift;
3266 return $diffinfo->{'to_id'} eq ('0' x
40);
3269 # does patch correspond to [previous] difftree raw line
3270 # $diffinfo - hashref of parsed raw diff format
3271 # $patchinfo - hashref of parsed patch diff format
3272 # (the same keys as in $diffinfo)
3273 sub is_patch_split
{
3274 my ($diffinfo, $patchinfo) = @_;
3276 return defined $diffinfo && defined $patchinfo
3277 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3281 sub git_difftree_body
{
3282 my ($difftree, $hash, @parents) = @_;
3283 my ($parent) = $parents[0];
3284 my ($have_blame) = gitweb_check_feature
('blame');
3285 print "<div class=\"list_head\">\n";
3286 if ($#{$difftree} > 10) {
3287 print(($#{$difftree} + 1) . " files changed:\n");
3291 print "<table class=\"" .
3292 (@parents > 1 ? "combined " : "") .
3295 # header only for combined diff in 'commitdiff' view
3296 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3299 print "<thead><tr>\n" .
3300 "<th></th><th></th>\n"; # filename, patchN link
3301 for (my $i = 0; $i < @parents; $i++) {
3302 my $par = $parents[$i];
3304 $cgi->a({-href
=> href
(action
=>"commitdiff",
3305 hash
=>$hash, hash_parent
=>$par),
3306 -title
=> 'commitdiff to parent number ' .
3307 ($i+1) . ': ' . substr($par,0,7)},
3311 print "</tr></thead>\n<tbody>\n";
3316 foreach my $line (@{$difftree}) {
3317 my $diff = parsed_difftree_line
($line);
3320 print "<tr class=\"dark\">\n";
3322 print "<tr class=\"light\">\n";
3326 if (exists $diff->{'nparents'}) { # combined diff
3328 fill_from_file_info
($diff, @parents)
3329 unless exists $diff->{'from_file'};
3331 if (!is_deleted
($diff)) {
3332 # file exists in the result (child) commit
3334 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3335 file_name
=>$diff->{'to_file'},
3337 -class => "list"}, esc_path
($diff->{'to_file'})) .
3341 esc_path
($diff->{'to_file'}) .
3345 if ($action eq 'commitdiff') {
3348 print "<td class=\"link\">" .
3349 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3354 my $has_history = 0;
3355 my $not_deleted = 0;
3356 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3357 my $hash_parent = $parents[$i];
3358 my $from_hash = $diff->{'from_id'}[$i];
3359 my $from_path = $diff->{'from_file'}[$i];
3360 my $status = $diff->{'status'}[$i];
3362 $has_history ||= ($status ne 'A');
3363 $not_deleted ||= ($status ne 'D');
3365 if ($status eq 'A') {
3366 print "<td class=\"link\" align=\"right\"> | </td>\n";
3367 } elsif ($status eq 'D') {
3368 print "<td class=\"link\">" .
3369 $cgi->a({-href
=> href
(action
=>"blob",
3372 file_name
=>$from_path)},
3376 if ($diff->{'to_id'} eq $from_hash) {
3377 print "<td class=\"link nochange\">";
3379 print "<td class=\"link\">";
3381 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3382 hash
=>$diff->{'to_id'},
3383 hash_parent
=>$from_hash,
3385 hash_parent_base
=>$hash_parent,
3386 file_name
=>$diff->{'to_file'},
3387 file_parent
=>$from_path)},
3393 print "<td class=\"link\">";
3395 print $cgi->a({-href
=> href
(action
=>"blob",
3396 hash
=>$diff->{'to_id'},
3397 file_name
=>$diff->{'to_file'},
3400 print " | " if ($has_history);
3403 print $cgi->a({-href
=> href
(action
=>"history",
3404 file_name
=>$diff->{'to_file'},
3411 next; # instead of 'else' clause, to avoid extra indent
3413 # else ordinary diff
3415 my ($to_mode_oct, $to_mode_str, $to_file_type);
3416 my ($from_mode_oct, $from_mode_str, $from_file_type);
3417 if ($diff->{'to_mode'} ne ('0' x
6)) {
3418 $to_mode_oct = oct $diff->{'to_mode'};
3419 if (S_ISREG
($to_mode_oct)) { # only for regular file
3420 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3422 $to_file_type = file_type
($diff->{'to_mode'});
3424 if ($diff->{'from_mode'} ne ('0' x
6)) {
3425 $from_mode_oct = oct $diff->{'from_mode'};
3426 if (S_ISREG
($to_mode_oct)) { # only for regular file
3427 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3429 $from_file_type = file_type
($diff->{'from_mode'});
3432 if ($diff->{'status'} eq "A") { # created
3433 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3434 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3435 $mode_chng .= "]</span>";
3437 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3438 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3439 -class => "list"}, esc_path
($diff->{'file'}));
3441 print "<td>$mode_chng</td>\n";
3442 print "<td class=\"link\">";
3443 if ($action eq 'commitdiff') {
3446 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3449 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3450 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3454 } elsif ($diff->{'status'} eq "D") { # deleted
3455 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3457 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3458 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3459 -class => "list"}, esc_path
($diff->{'file'}));
3461 print "<td>$mode_chng</td>\n";
3462 print "<td class=\"link\">";
3463 if ($action eq 'commitdiff') {
3466 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3469 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3470 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3473 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3474 file_name
=>$diff->{'file'})},
3477 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3478 file_name
=>$diff->{'file'})},
3482 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3483 my $mode_chnge = "";
3484 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3485 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3486 if ($from_file_type ne $to_file_type) {
3487 $mode_chnge .= " from $from_file_type to $to_file_type";
3489 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3490 if ($from_mode_str && $to_mode_str) {
3491 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3492 } elsif ($to_mode_str) {
3493 $mode_chnge .= " mode: $to_mode_str";
3496 $mode_chnge .= "]</span>\n";
3499 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3500 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3501 -class => "list"}, esc_path
($diff->{'file'}));
3503 print "<td>$mode_chnge</td>\n";
3504 print "<td class=\"link\">";
3505 if ($action eq 'commitdiff') {
3508 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3510 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3511 # "commit" view and modified file (not onlu mode changed)
3512 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3513 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3514 hash_base
=>$hash, hash_parent_base
=>$parent,
3515 file_name
=>$diff->{'file'})},
3519 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3520 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3523 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3524 file_name
=>$diff->{'file'})},
3527 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3528 file_name
=>$diff->{'file'})},
3532 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3533 my %status_name = ('R' => 'moved', 'C' => 'copied');
3534 my $nstatus = $status_name{$diff->{'status'}};
3536 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3537 # mode also for directories, so we cannot use $to_mode_str
3538 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3541 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3542 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3543 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3544 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3545 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3546 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3547 -class => "list"}, esc_path
($diff->{'from_file'})) .
3548 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3549 "<td class=\"link\">";
3550 if ($action eq 'commitdiff') {
3553 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3555 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3556 # "commit" view and modified file (not only pure rename or copy)
3557 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3558 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3559 hash_base
=>$hash, hash_parent_base
=>$parent,
3560 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3564 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3565 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3568 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3569 file_name
=>$diff->{'to_file'})},
3572 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3573 file_name
=>$diff->{'to_file'})},
3577 } # we should not encounter Unmerged (U) or Unknown (X) status
3580 print "</tbody>" if $has_header;
3584 sub git_patchset_body
{
3585 my ($fd, $difftree, $hash, @hash_parents) = @_;
3586 my ($hash_parent) = $hash_parents[0];
3588 my $is_combined = (@hash_parents > 1);
3590 my $patch_number = 0;
3596 print "<div class=\"patchset\">\n";
3598 # skip to first patch
3599 while ($patch_line = <$fd>) {
3602 last if ($patch_line =~ m/^diff /);
3606 while ($patch_line) {
3608 # parse "git diff" header line
3609 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3610 # $1 is from_name, which we do not use
3611 $to_name = unquote
($2);
3612 $to_name =~ s!^b/!!;
3613 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3614 # $1 is 'cc' or 'combined', which we do not use
3615 $to_name = unquote
($2);
3620 # check if current patch belong to current raw line
3621 # and parse raw git-diff line if needed
3622 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3623 # this is continuation of a split patch
3624 print "<div class=\"patch cont\">\n";
3626 # advance raw git-diff output if needed
3627 $patch_idx++ if defined $diffinfo;
3629 # read and prepare patch information
3630 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3632 # compact combined diff output can have some patches skipped
3633 # find which patch (using pathname of result) we are at now;
3635 while ($to_name ne $diffinfo->{'to_file'}) {
3636 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3637 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3638 "</div>\n"; # class="patch"
3643 last if $patch_idx > $#$difftree;
3644 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3648 # modifies %from, %to hashes
3649 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3651 # this is first patch for raw difftree line with $patch_idx index
3652 # we index @$difftree array from 0, but number patches from 1
3653 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3657 #assert($patch_line =~ m/^diff /) if DEBUG;
3658 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3660 # print "git diff" header
3661 print format_git_diff_header_line
($patch_line, $diffinfo,
3664 # print extended diff header
3665 print "<div class=\"diff extended_header\">\n";
3667 while ($patch_line = <$fd>) {
3670 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3672 print format_extended_diff_header_line
($patch_line, $diffinfo,
3675 print "</div>\n"; # class="diff extended_header"
3677 # from-file/to-file diff header
3678 if (! $patch_line) {
3679 print "</div>\n"; # class="patch"
3682 next PATCH
if ($patch_line =~ m/^diff /);
3683 #assert($patch_line =~ m/^---/) if DEBUG;
3685 my $last_patch_line = $patch_line;
3686 $patch_line = <$fd>;
3688 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3690 print format_diff_from_to_header
($last_patch_line, $patch_line,
3691 $diffinfo, \
%from, \
%to,
3696 while ($patch_line = <$fd>) {
3699 next PATCH
if ($patch_line =~ m/^diff /);
3701 print format_diff_line
($patch_line, \
%from, \
%to);
3705 print "</div>\n"; # class="patch"
3708 # for compact combined (--cc) format, with chunk and patch simpliciaction
3709 # patchset might be empty, but there might be unprocessed raw lines
3710 for (++$patch_idx if $patch_number > 0;
3711 $patch_idx < @$difftree;
3713 # read and prepare patch information
3714 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3716 # generate anchor for "patch" links in difftree / whatchanged part
3717 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3718 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3719 "</div>\n"; # class="patch"
3724 if ($patch_number == 0) {
3725 if (@hash_parents > 1) {
3726 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3728 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3732 print "</div>\n"; # class="patchset"
3735 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3737 # fills project list info (age, description, owner, forks) for each
3738 # project in the list, removing invalid projects from returned list
3739 # NOTE: modifies $projlist, but does not remove entries from it
3740 sub fill_project_list_info
{
3741 my ($projlist, $check_forks) = @_;
3744 my $show_ctags = gitweb_check_feature
('ctags');
3746 foreach my $pr (@$projlist) {
3747 my (@activity) = git_get_last_activity
($pr->{'path'});
3748 unless (@activity) {
3751 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3752 if (!defined $pr->{'descr'}) {
3753 my $descr = git_get_project_description
($pr->{'path'}) || "";
3754 $descr = to_utf8
($descr);
3755 $pr->{'descr_long'} = $descr;
3756 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3758 if (!defined $pr->{'owner'}) {
3759 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3762 my $pname = $pr->{'path'};
3763 if (($pname =~ s/\.git$//) &&
3764 ($pname !~ /\/$/) &&
3765 (-d
"$projectroot/$pname")) {
3766 $pr->{'forks'} = "-d $projectroot/$pname";
3771 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3772 push @projects, $pr;
3778 # print 'sort by' <th> element, generating 'sort by $name' replay link
3779 # if that order is not selected
3781 my ($name, $order, $header) = @_;
3782 $header ||= ucfirst($name);
3784 if ($order eq $name) {
3785 print "<th>$header</th>\n";
3788 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3789 -class => "header"}, $header) .
3794 sub git_project_list_body
{
3795 # actually uses global variable $project
3796 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3798 my ($check_forks) = gitweb_check_feature
('forks');
3799 my @projects = fill_project_list_info
($projlist, $check_forks);
3801 $order ||= $default_projects_order;
3802 $from = 0 unless defined $from;
3803 $to = $#projects if (!defined $to || $#projects < $to);
3806 project
=> { key
=> 'path', type
=> 'str' },
3807 descr
=> { key
=> 'descr_long', type
=> 'str' },
3808 owner
=> { key
=> 'owner', type
=> 'str' },
3809 age
=> { key
=> 'age', type
=> 'num' }
3811 my $oi = $order_info{$order};
3812 if ($oi->{'type'} eq 'str') {
3813 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3815 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3818 my $show_ctags = gitweb_check_feature
('ctags');
3821 foreach my $p (@projects) {
3822 foreach my $ct (keys %{$p->{'ctags'}}) {
3823 $ctags{$ct} += $p->{'ctags'}->{$ct};
3826 my $cloud = git_populate_project_tagcloud
(\
%ctags);
3827 print git_show_project_tagcloud
($cloud, 64);
3830 print "<table class=\"project_list\">\n";
3831 unless ($no_header) {
3834 print "<th></th>\n";
3836 print_sort_th
('project', $order, 'Project');
3837 print_sort_th
('descr', $order, 'Description');
3838 print_sort_th
('owner', $order, 'Owner');
3839 print_sort_th
('age', $order, 'Last Change');
3840 print "<th></th>\n" . # for links
3844 my $tagfilter = $cgi->param('by_tag');
3845 for (my $i = $from; $i <= $to; $i++) {
3846 my $pr = $projects[$i];
3848 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
3849 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
3850 and not $pr->{'descr_long'} =~ /$searchtext/;
3851 # Weed out forks or non-matching entries of search
3853 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
3854 $forkbase="^$forkbase" if $forkbase;
3855 next if not $searchtext and not $tagfilter and $show_ctags
3856 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
3860 print "<tr class=\"dark\">\n";
3862 print "<tr class=\"light\">\n";
3867 if ($pr->{'forks'}) {
3868 print "<!-- $pr->{'forks'} -->\n";
3869 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3873 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3874 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3875 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3876 -class => "list", -title
=> $pr->{'descr_long'}},
3877 esc_html
($pr->{'descr'})) . "</td>\n" .
3878 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3879 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3880 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3881 "<td class=\"link\">" .
3882 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3883 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3884 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3885 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3886 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3890 if (defined $extra) {
3893 print "<td></td>\n";
3895 print "<td colspan=\"5\">$extra</td>\n" .
3901 sub git_shortlog_body
{
3902 # uses global variable $project
3903 my ($commitlist, $from, $to, $refs, $extra) = @_;
3905 $from = 0 unless defined $from;
3906 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3908 print "<table class=\"shortlog\">\n";
3910 for (my $i = $from; $i <= $to; $i++) {
3911 my %co = %{$commitlist->[$i]};
3912 my $commit = $co{'id'};
3913 my $ref = format_ref_marker
($refs, $commit);
3915 print "<tr class=\"dark\">\n";
3917 print "<tr class=\"light\">\n";
3920 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3921 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3922 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3923 "<td><i>" . $author . "</i></td>\n" .
3925 print format_subject_html
($co{'title'}, $co{'title_short'},
3926 href
(action
=>"commit", hash
=>$commit), $ref);
3928 "<td class=\"link\">" .
3929 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3930 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3931 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3932 my $snapshot_links = format_snapshot_links
($commit);
3933 if (defined $snapshot_links) {
3934 print " | " . $snapshot_links;
3939 if (defined $extra) {
3941 "<td colspan=\"4\">$extra</td>\n" .
3947 sub git_history_body
{
3948 # Warning: assumes constant type (blob or tree) during history
3949 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3951 $from = 0 unless defined $from;
3952 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3954 print "<table class=\"history\">\n";
3956 for (my $i = $from; $i <= $to; $i++) {
3957 my %co = %{$commitlist->[$i]};
3961 my $commit = $co{'id'};
3963 my $ref = format_ref_marker
($refs, $commit);
3966 print "<tr class=\"dark\">\n";
3968 print "<tr class=\"light\">\n";
3971 # shortlog uses chop_str($co{'author_name'}, 10)
3972 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3973 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3974 "<td><i>" . $author . "</i></td>\n" .
3976 # originally git_history used chop_str($co{'title'}, 50)
3977 print format_subject_html
($co{'title'}, $co{'title_short'},
3978 href
(action
=>"commit", hash
=>$commit), $ref);
3980 "<td class=\"link\">" .
3981 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3982 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3984 if ($ftype eq 'blob') {
3985 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3986 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3987 if (defined $blob_current && defined $blob_parent &&
3988 $blob_current ne $blob_parent) {
3990 $cgi->a({-href
=> href
(action
=>"blobdiff",
3991 hash
=>$blob_current, hash_parent
=>$blob_parent,
3992 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3993 file_name
=>$file_name)},
4000 if (defined $extra) {
4002 "<td colspan=\"4\">$extra</td>\n" .
4009 # uses global variable $project
4010 my ($taglist, $from, $to, $extra) = @_;
4011 $from = 0 unless defined $from;
4012 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4014 print "<table class=\"tags\">\n";
4016 for (my $i = $from; $i <= $to; $i++) {
4017 my $entry = $taglist->[$i];
4019 my $comment = $tag{'subject'};
4021 if (defined $comment) {
4022 $comment_short = chop_str
($comment, 30, 5);
4025 print "<tr class=\"dark\">\n";
4027 print "<tr class=\"light\">\n";
4030 if (defined $tag{'age'}) {
4031 print "<td><i>$tag{'age'}</i></td>\n";
4033 print "<td></td>\n";
4036 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4037 -class => "list name"}, esc_html
($tag{'name'})) .
4040 if (defined $comment) {
4041 print format_subject_html
($comment, $comment_short,
4042 href
(action
=>"tag", hash
=>$tag{'id'}));
4045 "<td class=\"selflink\">";
4046 if ($tag{'type'} eq "tag") {
4047 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4052 "<td class=\"link\">" . " | " .
4053 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4054 if ($tag{'reftype'} eq "commit") {
4055 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4056 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4057 } elsif ($tag{'reftype'} eq "blob") {
4058 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4063 if (defined $extra) {
4065 "<td colspan=\"5\">$extra</td>\n" .
4071 sub git_heads_body
{
4072 # uses global variable $project
4073 my ($headlist, $head, $from, $to, $extra) = @_;
4074 $from = 0 unless defined $from;
4075 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4077 print "<table class=\"heads\">\n";
4079 for (my $i = $from; $i <= $to; $i++) {
4080 my $entry = $headlist->[$i];
4082 my $curr = $ref{'id'} eq $head;
4084 print "<tr class=\"dark\">\n";
4086 print "<tr class=\"light\">\n";
4089 print "<td><i>$ref{'age'}</i></td>\n" .
4090 ($curr ? "<td class=\"current_head\">" : "<td>") .
4091 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4092 -class => "list name"},esc_html
($ref{'name'})) .
4094 "<td class=\"link\">" .
4095 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4096 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4097 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4101 if (defined $extra) {
4103 "<td colspan=\"3\">$extra</td>\n" .
4109 sub git_search_grep_body
{
4110 my ($commitlist, $from, $to, $extra) = @_;
4111 $from = 0 unless defined $from;
4112 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4114 print "<table class=\"commit_search\">\n";
4116 for (my $i = $from; $i <= $to; $i++) {
4117 my %co = %{$commitlist->[$i]};
4121 my $commit = $co{'id'};
4123 print "<tr class=\"dark\">\n";
4125 print "<tr class=\"light\">\n";
4128 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4129 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4130 "<td><i>" . $author . "</i></td>\n" .
4132 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4133 -class => "list subject"},
4134 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4135 my $comment = $co{'comment'};
4136 foreach my $line (@$comment) {
4137 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4138 my ($lead, $match, $trail) = ($1, $2, $3);
4139 $match = chop_str
($match, 70, 5, 'center');
4140 my $contextlen = int((80 - length($match))/2);
4141 $contextlen = 30 if ($contextlen > 30);
4142 $lead = chop_str
($lead, $contextlen, 10, 'left');
4143 $trail = chop_str
($trail, $contextlen, 10, 'right');
4145 $lead = esc_html
($lead);
4146 $match = esc_html
($match);
4147 $trail = esc_html
($trail);
4149 print "$lead<span class=\"match\">$match</span>$trail<br />";
4153 "<td class=\"link\">" .
4154 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4156 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4158 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4162 if (defined $extra) {
4164 "<td colspan=\"3\">$extra</td>\n" .
4170 ## ======================================================================
4171 ## ======================================================================
4174 sub git_project_list
{
4175 my $order = $input_params{'order'};
4176 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4177 die_error
(400, "Unknown order parameter");
4180 my @list = git_get_projects_list
();
4182 die_error
(404, "No projects found");
4186 if (-f
$home_text) {
4187 print "<div class=\"index_include\">\n";
4188 open (my $fd, $home_text);
4193 print $cgi->startform(-method => "get") .
4194 "<p class=\"projsearch\">Search:\n" .
4195 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4197 $cgi->end_form() . "\n";
4198 git_project_list_body
(\
@list, $order);
4203 my $order = $input_params{'order'};
4204 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4205 die_error
(400, "Unknown order parameter");
4208 my @list = git_get_projects_list
($project);
4210 die_error
(404, "No forks found");
4214 git_print_page_nav
('','');
4215 git_print_header_div
('summary', "$project forks");
4216 git_project_list_body
(\
@list, $order);
4220 sub git_project_index
{
4221 my @projects = git_get_projects_list
($project);
4224 -type
=> 'text/plain',
4225 -charset
=> 'utf-8',
4226 -content_disposition
=> 'inline; filename="index.aux"');
4228 foreach my $pr (@projects) {
4229 if (!exists $pr->{'owner'}) {
4230 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4233 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4234 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4235 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4236 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4240 print "$path $owner\n";
4245 my $descr = git_get_project_description
($project) || "none";
4246 my %co = parse_commit
("HEAD");
4247 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4248 my $head = $co{'id'};
4250 my $owner = git_get_project_owner
($project);
4252 my $refs = git_get_references
();
4253 # These get_*_list functions return one more to allow us to see if
4254 # there are more ...
4255 my @taglist = git_get_tags_list
(16);
4256 my @headlist = git_get_heads_list
(16);
4258 my ($check_forks) = gitweb_check_feature
('forks');
4261 @forklist = git_get_projects_list
($project);
4265 git_print_page_nav
('summary','', $head);
4267 print "<div class=\"title\"> </div>\n";
4268 print "<table class=\"projects_list\">\n" .
4269 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4270 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4271 if (defined $cd{'rfc2822'}) {
4272 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4275 # use per project git URL list in $projectroot/$project/cloneurl
4276 # or make project git URL from git base URL and project name
4277 my $url_tag = "URL";
4278 my @url_list = git_get_project_url_list
($project);
4279 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4280 foreach my $git_url (@url_list) {
4281 next unless $git_url;
4282 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4287 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4289 my $ctags = git_get_project_ctags
($project);
4290 my $cloud = git_populate_project_tagcloud
($ctags);
4291 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4292 print "</td>\n<td>" unless %$ctags;
4293 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4294 print "</td>\n<td>" if %$ctags;
4295 print git_show_project_tagcloud
($cloud, 48);
4301 if (-s
"$projectroot/$project/README.html") {
4302 if (open my $fd, "$projectroot/$project/README.html") {
4303 print "<div class=\"title\">readme</div>\n" .
4304 "<div class=\"readme\">\n";
4305 print $_ while (<$fd>);
4306 print "\n</div>\n"; # class="readme"
4311 # we need to request one more than 16 (0..15) to check if
4313 my @commitlist = $head ? parse_commits
($head, 17) : ();
4315 git_print_header_div
('shortlog');
4316 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4317 $#commitlist <= 15 ? undef :
4318 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4322 git_print_header_div
('tags');
4323 git_tags_body
(\
@taglist, 0, 15,
4324 $#taglist <= 15 ? undef :
4325 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4329 git_print_header_div
('heads');
4330 git_heads_body
(\
@headlist, $head, 0, 15,
4331 $#headlist <= 15 ? undef :
4332 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4336 git_print_header_div
('forks');
4337 git_project_list_body
(\
@forklist, 'age', 0, 15,
4338 $#forklist <= 15 ? undef :
4339 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4347 my $head = git_get_head_hash
($project);
4349 git_print_page_nav
('','', $head,undef,$head);
4350 my %tag = parse_tag
($hash);
4353 die_error
(404, "Unknown tag object");
4356 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4357 print "<div class=\"title_text\">\n" .
4358 "<table class=\"object_header\">\n" .
4360 "<td>object</td>\n" .
4361 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4362 $tag{'object'}) . "</td>\n" .
4363 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4364 $tag{'type'}) . "</td>\n" .
4366 if (defined($tag{'author'})) {
4367 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4368 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4369 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4370 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4373 print "</table>\n\n" .
4375 print "<div class=\"page_body\">";
4376 my $comment = $tag{'comment'};
4377 foreach my $line (@$comment) {
4379 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4389 gitweb_check_feature
('blame')
4390 or die_error
(403, "Blame view not allowed");
4392 die_error
(400, "No file name given") unless $file_name;
4393 $hash_base ||= git_get_head_hash
($project);
4394 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4395 my %co = parse_commit
($hash_base)
4396 or die_error
(404, "Commit not found");
4397 if (!defined $hash) {
4398 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4399 or die_error
(404, "Error looking up file");
4401 $ftype = git_get_type
($hash);
4402 if ($ftype !~ "blob") {
4403 die_error
(400, "Object is not a blob");
4405 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4406 $file_name, $hash_base)
4407 or die_error
(500, "Open git-blame failed");
4410 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4413 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4416 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4418 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4419 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4420 git_print_page_path
($file_name, $ftype, $hash_base);
4421 my @rev_color = (qw(light2 dark2));
4422 my $num_colors = scalar(@rev_color);
4423 my $current_color = 0;
4426 <div class="page_body">
4427 <table class="blame">
4428 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4433 last unless defined $_;
4434 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4435 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4436 if (!exists $metainfo{$full_rev}) {
4437 $metainfo{$full_rev} = {};
4439 my $meta = $metainfo{$full_rev};
4442 if (/^(\S+) (.*)$/) {
4448 my $rev = substr($full_rev, 0, 8);
4449 my $author = $meta->{'author'};
4450 my %date = parse_date
($meta->{'author-time'},
4451 $meta->{'author-tz'});
4452 my $date = $date{'iso-tz'};
4454 $current_color = ++$current_color % $num_colors;
4456 print "<tr class=\"$rev_color[$current_color]\">\n";
4458 print "<td class=\"sha1\"";
4459 print " title=\"". esc_html
($author) . ", $date\"";
4460 print " rowspan=\"$group_size\"" if ($group_size > 1);
4462 print $cgi->a({-href
=> href
(action
=>"commit",
4464 file_name
=>$file_name)},
4468 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4469 or die_error
(500, "Open git-rev-parse failed");
4470 my $parent_commit = <$dd>;
4472 chomp($parent_commit);
4473 my $blamed = href
(action
=> 'blame',
4474 file_name
=> $meta->{'filename'},
4475 hash_base
=> $parent_commit);
4476 print "<td class=\"linenr\">";
4477 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4479 -class => "linenr" },
4482 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4488 or print "Reading blob failed\n";
4493 my $head = git_get_head_hash
($project);
4495 git_print_page_nav
('','', $head,undef,$head);
4496 git_print_header_div
('summary', $project);
4498 my @tagslist = git_get_tags_list
();
4500 git_tags_body
(\
@tagslist);
4506 my $head = git_get_head_hash
($project);
4508 git_print_page_nav
('','', $head,undef,$head);
4509 git_print_header_div
('summary', $project);
4511 my @headslist = git_get_heads_list
();
4513 git_heads_body
(\
@headslist, $head);
4518 sub git_blob_plain
{
4522 if (!defined $hash) {
4523 if (defined $file_name) {
4524 my $base = $hash_base || git_get_head_hash
($project);
4525 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4526 or die_error
(404, "Cannot find file");
4528 die_error
(400, "No file name defined");
4530 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4531 # blobs defined by non-textual hash id's can be cached
4535 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4536 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4538 # content-type (can include charset)
4539 $type = blob_contenttype
($fd, $file_name, $type);
4541 # "save as" filename, even when no $file_name is given
4542 my $save_as = "$hash";
4543 if (defined $file_name) {
4544 $save_as = $file_name;
4545 } elsif ($type =~ m/^text\//) {
4551 -expires
=> $expires,
4552 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4554 binmode STDOUT
, ':raw';
4556 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4564 if (!defined $hash) {
4565 if (defined $file_name) {
4566 my $base = $hash_base || git_get_head_hash
($project);
4567 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4568 or die_error
(404, "Cannot find file");
4570 die_error
(400, "No file name defined");
4572 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4573 # blobs defined by non-textual hash id's can be cached
4577 my ($have_blame) = gitweb_check_feature
('blame');
4578 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4579 or die_error
(500, "Couldn't cat $file_name, $hash");
4580 my $mimetype = blob_mimetype
($fd, $file_name);
4581 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4583 return git_blob_plain
($mimetype);
4585 # we can have blame only for text/* mimetype
4586 $have_blame &&= ($mimetype =~ m!^text/!);
4588 git_header_html
(undef, $expires);
4589 my $formats_nav = '';
4590 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4591 if (defined $file_name) {
4594 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4599 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4602 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4605 $cgi->a({-href
=> href
(action
=>"blob",
4606 hash_base
=>"HEAD", file_name
=>$file_name)},
4610 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4613 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4614 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4616 print "<div class=\"page_nav\">\n" .
4617 "<br/><br/></div>\n" .
4618 "<div class=\"title\">$hash</div>\n";
4620 git_print_page_path
($file_name, "blob", $hash_base);
4621 print "<div class=\"page_body\">\n";
4622 if ($mimetype =~ m!^image/!) {
4623 print qq
!<img type
="$mimetype"!;
4625 print qq
! alt
="$file_name" title
="$file_name"!;
4628 href(action=>"blob_plain
", hash=>$hash,
4629 hash_base=>$hash_base, file_name=>$file_name) .
4633 while (my $line = <$fd>) {
4636 $line = untabify
($line);
4637 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4638 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4642 or print "Reading blob failed.\n";
4648 if (!defined $hash_base) {
4649 $hash_base = "HEAD";
4651 if (!defined $hash) {
4652 if (defined $file_name) {
4653 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4658 die_error
(404, "No such tree") unless defined($hash);
4660 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4661 or die_error
(500, "Open git-ls-tree failed");
4662 my @entries = map { chomp; $_ } <$fd>;
4663 close $fd or die_error
(404, "Reading tree failed");
4666 my $refs = git_get_references
();
4667 my $ref = format_ref_marker
($refs, $hash_base);
4670 my ($have_blame) = gitweb_check_feature
('blame');
4671 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4673 if (defined $file_name) {
4675 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4677 $cgi->a({-href
=> href
(action
=>"tree",
4678 hash_base
=>"HEAD", file_name
=>$file_name)},
4681 my $snapshot_links = format_snapshot_links
($hash);
4682 if (defined $snapshot_links) {
4683 # FIXME: Should be available when we have no hash base as well.
4684 push @views_nav, $snapshot_links;
4686 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4687 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4690 print "<div class=\"page_nav\">\n";
4691 print "<br/><br/></div>\n";
4692 print "<div class=\"title\">$hash</div>\n";
4694 if (defined $file_name) {
4695 $basedir = $file_name;
4696 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4699 git_print_page_path
($file_name, 'tree', $hash_base);
4701 print "<div class=\"page_body\">\n";
4702 print "<table class=\"tree\">\n";
4704 # '..' (top directory) link if possible
4705 if (defined $hash_base &&
4706 defined $file_name && $file_name =~ m![^/]+$!) {
4708 print "<tr class=\"dark\">\n";
4710 print "<tr class=\"light\">\n";
4714 my $up = $file_name;
4715 $up =~ s!/?[^/]+$!!;
4716 undef $up unless $up;
4717 # based on git_print_tree_entry
4718 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4719 print '<td class="list">';
4720 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4724 print "<td class=\"link\"></td>\n";
4728 foreach my $line (@entries) {
4729 my %t = parse_ls_tree_line
($line, -z
=> 1);
4732 print "<tr class=\"dark\">\n";
4734 print "<tr class=\"light\">\n";
4738 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4742 print "</table>\n" .
4748 my @supported_fmts = gitweb_check_feature
('snapshot');
4749 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4751 my $format = $input_params{'snapshot_format'};
4752 if (!@supported_fmts) {
4753 die_error
(403, "Snapshots not allowed");
4755 # default to first supported snapshot format
4756 $format ||= $supported_fmts[0];
4757 if ($format !~ m/^[a-z0-9]+$/) {
4758 die_error
(400, "Invalid snapshot format parameter");
4759 } elsif (!exists($known_snapshot_formats{$format})) {
4760 die_error
(400, "Unknown snapshot format");
4761 } elsif (!grep($_ eq $format, @supported_fmts)) {
4762 die_error
(403, "Unsupported snapshot format");
4765 if (!defined $hash) {
4766 $hash = git_get_head_hash
($project);
4769 my $name = $project;
4770 $name =~ s
,([^/])/*\
.git
$,$1,;
4771 $name = basename
($name);
4772 my $filename = to_utf8
($name);
4773 $name =~ s/\047/\047\\\047\047/g;
4775 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4776 $cmd = quote_command
(
4777 git_cmd
(), 'archive',
4778 "--format=$known_snapshot_formats{$format}{'format'}",
4779 "--prefix=$name/", $hash);
4780 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4781 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4785 -type
=> $known_snapshot_formats{$format}{'type'},
4786 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4787 -status
=> '200 OK');
4789 open my $fd, "-|", $cmd
4790 or die_error
(500, "Execute git-archive failed");
4791 binmode STDOUT
, ':raw';
4793 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4798 my $head = git_get_head_hash
($project);
4799 if (!defined $hash) {
4802 if (!defined $page) {
4805 my $refs = git_get_references
();
4807 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4809 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4812 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4815 my %co = parse_commit
($hash);
4817 git_print_header_div
('summary', $project);
4818 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4820 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4821 for (my $i = 0; $i <= $to; $i++) {
4822 my %co = %{$commitlist[$i]};
4824 my $commit = $co{'id'};
4825 my $ref = format_ref_marker
($refs, $commit);
4826 my %ad = parse_date
($co{'author_epoch'});
4827 git_print_header_div
('commit',
4828 "<span class=\"age\">$co{'age_string'}</span>" .
4829 esc_html
($co{'title'}) . $ref,
4831 print "<div class=\"title_text\">\n" .
4832 "<div class=\"log_link\">\n" .
4833 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4835 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4837 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4840 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4843 print "<div class=\"log_body\">\n";
4844 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4847 if ($#commitlist >= 100) {
4848 print "<div class=\"page_nav\">\n";
4849 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4850 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4857 $hash ||= $hash_base || "HEAD";
4858 my %co = parse_commit
($hash)
4859 or die_error
(404, "Unknown commit object");
4860 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4861 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4863 my $parent = $co{'parent'};
4864 my $parents = $co{'parents'}; # listref
4866 # we need to prepare $formats_nav before any parameter munging
4868 if (!defined $parent) {
4870 $formats_nav .= '(initial)';
4871 } elsif (@$parents == 1) {
4872 # single parent commit
4875 $cgi->a({-href
=> href
(action
=>"commit",
4877 esc_html
(substr($parent, 0, 7))) .
4884 $cgi->a({-href
=> href
(action
=>"commit",
4886 esc_html
(substr($_, 0, 7)));
4891 if (!defined $parent) {
4895 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4897 (@$parents <= 1 ? $parent : '-c'),
4899 or die_error
(500, "Open git-diff-tree failed");
4900 @difftree = map { chomp; $_ } <$fd>;
4901 close $fd or die_error
(404, "Reading git-diff-tree failed");
4903 # non-textual hash id's can be cached
4905 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4908 my $refs = git_get_references
();
4909 my $ref = format_ref_marker
($refs, $co{'id'});
4911 git_header_html
(undef, $expires);
4912 git_print_page_nav
('commit', '',
4913 $hash, $co{'tree'}, $hash,
4916 if (defined $co{'parent'}) {
4917 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4919 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4921 print "<div class=\"title_text\">\n" .
4922 "<table class=\"object_header\">\n";
4923 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4925 "<td></td><td> $ad{'rfc2822'}";
4926 if ($ad{'hour_local'} < 6) {
4927 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4928 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4930 printf(" (%02d:%02d %s)",
4931 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4935 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4936 print "<tr><td></td><td> $cd{'rfc2822'}" .
4937 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4939 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4942 "<td class=\"sha1\">" .
4943 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4944 class => "list"}, $co{'tree'}) .
4946 "<td class=\"link\">" .
4947 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4949 my $snapshot_links = format_snapshot_links
($hash);
4950 if (defined $snapshot_links) {
4951 print " | " . $snapshot_links;
4956 foreach my $par (@$parents) {
4959 "<td class=\"sha1\">" .
4960 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4961 class => "list"}, $par) .
4963 "<td class=\"link\">" .
4964 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4966 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4973 print "<div class=\"page_body\">\n";
4974 git_print_log
($co{'comment'});
4977 git_difftree_body
(\
@difftree, $hash, @$parents);
4983 # object is defined by:
4984 # - hash or hash_base alone
4985 # - hash_base and file_name
4988 # - hash or hash_base alone
4989 if ($hash || ($hash_base && !defined $file_name)) {
4990 my $object_id = $hash || $hash_base;
4992 open my $fd, "-|", quote_command
(
4993 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4994 or die_error
(404, "Object does not exist");
4998 or die_error
(404, "Object does not exist");
5000 # - hash_base and file_name
5001 } elsif ($hash_base && defined $file_name) {
5002 $file_name =~ s
,/+$,,;
5004 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5005 or die_error
(404, "Base object does not exist");
5007 # here errors should not hapen
5008 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5009 or die_error
(500, "Open git-ls-tree failed");
5013 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5014 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5015 die_error
(404, "File or directory for given base does not exist");
5020 die_error
(400, "Not enough information to find object");
5023 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5024 hash
=>$hash, hash_base
=>$hash_base,
5025 file_name
=>$file_name),
5026 -status
=> '302 Found');
5030 my $format = shift || 'html';
5037 # preparing $fd and %diffinfo for git_patchset_body
5039 if (defined $hash_base && defined $hash_parent_base) {
5040 if (defined $file_name) {
5042 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5043 $hash_parent_base, $hash_base,
5044 "--", (defined $file_parent ? $file_parent : ()), $file_name
5045 or die_error
(500, "Open git-diff-tree failed");
5046 @difftree = map { chomp; $_ } <$fd>;
5048 or die_error
(404, "Reading git-diff-tree failed");
5050 or die_error
(404, "Blob diff not found");
5052 } elsif (defined $hash &&
5053 $hash =~ /[0-9a-fA-F]{40}/) {
5054 # try to find filename from $hash
5056 # read filtered raw output
5057 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5058 $hash_parent_base, $hash_base, "--"
5059 or die_error
(500, "Open git-diff-tree failed");
5061 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5063 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5064 map { chomp; $_ } <$fd>;
5066 or die_error
(404, "Reading git-diff-tree failed");
5068 or die_error
(404, "Blob diff not found");
5071 die_error
(400, "Missing one of the blob diff parameters");
5074 if (@difftree > 1) {
5075 die_error
(400, "Ambiguous blob diff specification");
5078 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5079 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5080 $file_name ||= $diffinfo{'to_file'};
5082 $hash_parent ||= $diffinfo{'from_id'};
5083 $hash ||= $diffinfo{'to_id'};
5085 # non-textual hash id's can be cached
5086 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5087 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5092 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5093 '-p', ($format eq 'html' ? "--full-index" : ()),
5094 $hash_parent_base, $hash_base,
5095 "--", (defined $file_parent ? $file_parent : ()), $file_name
5096 or die_error
(500, "Open git-diff-tree failed");
5099 # old/legacy style URI
5100 if (!%diffinfo && # if new style URI failed
5101 defined $hash && defined $hash_parent) {
5102 # fake git-diff-tree raw output
5103 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5104 $diffinfo{'from_id'} = $hash_parent;
5105 $diffinfo{'to_id'} = $hash;
5106 if (defined $file_name) {
5107 if (defined $file_parent) {
5108 $diffinfo{'status'} = '2';
5109 $diffinfo{'from_file'} = $file_parent;
5110 $diffinfo{'to_file'} = $file_name;
5111 } else { # assume not renamed
5112 $diffinfo{'status'} = '1';
5113 $diffinfo{'from_file'} = $file_name;
5114 $diffinfo{'to_file'} = $file_name;
5116 } else { # no filename given
5117 $diffinfo{'status'} = '2';
5118 $diffinfo{'from_file'} = $hash_parent;
5119 $diffinfo{'to_file'} = $hash;
5122 # non-textual hash id's can be cached
5123 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5124 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5129 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5130 '-p', ($format eq 'html' ? "--full-index" : ()),
5131 $hash_parent, $hash, "--"
5132 or die_error
(500, "Open git-diff failed");
5134 die_error
(400, "Missing one of the blob diff parameters")
5139 if ($format eq 'html') {
5141 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5143 git_header_html
(undef, $expires);
5144 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5145 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5146 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5148 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5149 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5151 if (defined $file_name) {
5152 git_print_page_path
($file_name, "blob", $hash_base);
5154 print "<div class=\"page_path\"></div>\n";
5157 } elsif ($format eq 'plain') {
5159 -type
=> 'text/plain',
5160 -charset
=> 'utf-8',
5161 -expires
=> $expires,
5162 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5164 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5167 die_error
(400, "Unknown blobdiff format");
5171 if ($format eq 'html') {
5172 print "<div class=\"page_body\">\n";
5174 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5177 print "</div>\n"; # class="page_body"
5181 while (my $line = <$fd>) {
5182 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5183 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5187 last if $line =~ m!^\+\+\+!;
5195 sub git_blobdiff_plain
{
5196 git_blobdiff
('plain');
5199 sub git_commitdiff
{
5200 my $format = shift || 'html';
5201 $hash ||= $hash_base || "HEAD";
5202 my %co = parse_commit
($hash)
5203 or die_error
(404, "Unknown commit object");
5205 # choose format for commitdiff for merge
5206 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5207 $hash_parent = '--cc';
5209 # we need to prepare $formats_nav before almost any parameter munging
5211 if ($format eq 'html') {
5213 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5216 if (defined $hash_parent &&
5217 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5218 # commitdiff with two commits given
5219 my $hash_parent_short = $hash_parent;
5220 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5221 $hash_parent_short = substr($hash_parent, 0, 7);
5225 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5226 if ($co{'parents'}[$i] eq $hash_parent) {
5227 $formats_nav .= ' parent ' . ($i+1);
5231 $formats_nav .= ': ' .
5232 $cgi->a({-href
=> href
(action
=>"commitdiff",
5233 hash
=>$hash_parent)},
5234 esc_html
($hash_parent_short)) .
5236 } elsif (!$co{'parent'}) {
5238 $formats_nav .= ' (initial)';
5239 } elsif (scalar @{$co{'parents'}} == 1) {
5240 # single parent commit
5243 $cgi->a({-href
=> href
(action
=>"commitdiff",
5244 hash
=>$co{'parent'})},
5245 esc_html
(substr($co{'parent'}, 0, 7))) .
5249 if ($hash_parent eq '--cc') {
5250 $formats_nav .= ' | ' .
5251 $cgi->a({-href
=> href
(action
=>"commitdiff",
5252 hash
=>$hash, hash_parent
=>'-c')},
5254 } else { # $hash_parent eq '-c'
5255 $formats_nav .= ' | ' .
5256 $cgi->a({-href
=> href
(action
=>"commitdiff",
5257 hash
=>$hash, hash_parent
=>'--cc')},
5263 $cgi->a({-href
=> href
(action
=>"commitdiff",
5265 esc_html
(substr($_, 0, 7)));
5266 } @{$co{'parents'}} ) .
5271 my $hash_parent_param = $hash_parent;
5272 if (!defined $hash_parent_param) {
5273 # --cc for multiple parents, --root for parentless
5274 $hash_parent_param =
5275 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5281 if ($format eq 'html') {
5282 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5283 "--no-commit-id", "--patch-with-raw", "--full-index",
5284 $hash_parent_param, $hash, "--"
5285 or die_error
(500, "Open git-diff-tree failed");
5287 while (my $line = <$fd>) {
5289 # empty line ends raw part of diff-tree output
5291 push @difftree, scalar parse_difftree_raw_line
($line);
5294 } elsif ($format eq 'plain') {
5295 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5296 '-p', $hash_parent_param, $hash, "--"
5297 or die_error
(500, "Open git-diff-tree failed");
5300 die_error
(400, "Unknown commitdiff format");
5303 # non-textual hash id's can be cached
5305 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5309 # write commit message
5310 if ($format eq 'html') {
5311 my $refs = git_get_references
();
5312 my $ref = format_ref_marker
($refs, $co{'id'});
5314 git_header_html
(undef, $expires);
5315 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5316 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5317 git_print_authorship
(\
%co);
5318 print "<div class=\"page_body\">\n";
5319 if (@{$co{'comment'}} > 1) {
5320 print "<div class=\"log\">\n";
5321 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5322 print "</div>\n"; # class="log"
5325 } elsif ($format eq 'plain') {
5326 my $refs = git_get_references
("tags");
5327 my $tagname = git_get_rev_name_tags
($hash);
5328 my $filename = basename
($project) . "-$hash.patch";
5331 -type
=> 'text/plain',
5332 -charset
=> 'utf-8',
5333 -expires
=> $expires,
5334 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5335 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5336 print "From: " . to_utf8
($co{'author'}) . "\n";
5337 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5338 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5340 print "X-Git-Tag: $tagname\n" if $tagname;
5341 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5343 foreach my $line (@{$co{'comment'}}) {
5344 print to_utf8
($line) . "\n";
5350 if ($format eq 'html') {
5351 my $use_parents = !defined $hash_parent ||
5352 $hash_parent eq '-c' || $hash_parent eq '--cc';
5353 git_difftree_body
(\
@difftree, $hash,
5354 $use_parents ? @{$co{'parents'}} : $hash_parent);
5357 git_patchset_body
($fd, \
@difftree, $hash,
5358 $use_parents ? @{$co{'parents'}} : $hash_parent);
5360 print "</div>\n"; # class="page_body"
5363 } elsif ($format eq 'plain') {
5367 or print "Reading git-diff-tree failed\n";
5371 sub git_commitdiff_plain
{
5372 git_commitdiff
('plain');
5376 if (!defined $hash_base) {
5377 $hash_base = git_get_head_hash
($project);
5379 if (!defined $page) {
5383 my %co = parse_commit
($hash_base)
5384 or die_error
(404, "Unknown commit object");
5386 my $refs = git_get_references
();
5387 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5389 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5390 $file_name, "--full-history")
5391 or die_error
(404, "No such file or directory on given branch");
5393 if (!defined $hash && defined $file_name) {
5394 # some commits could have deleted file in question,
5395 # and not have it in tree, but one of them has to have it
5396 for (my $i = 0; $i <= @commitlist; $i++) {
5397 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5398 last if defined $hash;
5401 if (defined $hash) {
5402 $ftype = git_get_type
($hash);
5404 if (!defined $ftype) {
5405 die_error
(500, "Unknown type of object");
5408 my $paging_nav = '';
5411 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5412 file_name
=>$file_name)},
5414 $paging_nav .= " ⋅ " .
5415 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5416 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5418 $paging_nav .= "first";
5419 $paging_nav .= " ⋅ prev";
5422 if ($#commitlist >= 100) {
5424 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5425 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5426 $paging_nav .= " ⋅ $next_link";
5428 $paging_nav .= " ⋅ next";
5432 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5433 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5434 git_print_page_path
($file_name, $ftype, $hash_base);
5436 git_history_body
(\
@commitlist, 0, 99,
5437 $refs, $hash_base, $ftype, $next_link);
5443 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5444 if (!defined $searchtext) {
5445 die_error
(400, "Text field is empty");
5447 if (!defined $hash) {
5448 $hash = git_get_head_hash
($project);
5450 my %co = parse_commit
($hash);
5452 die_error
(404, "Unknown commit object");
5454 if (!defined $page) {
5458 $searchtype ||= 'commit';
5459 if ($searchtype eq 'pickaxe') {
5460 # pickaxe may take all resources of your box and run for several minutes
5461 # with every query - so decide by yourself how public you make this feature
5462 gitweb_check_feature
('pickaxe')
5463 or die_error
(403, "Pickaxe is disabled");
5465 if ($searchtype eq 'grep') {
5466 gitweb_check_feature
('grep')
5467 or die_error
(403, "Grep is disabled");
5472 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5474 if ($searchtype eq 'commit') {
5475 $greptype = "--grep=";
5476 } elsif ($searchtype eq 'author') {
5477 $greptype = "--author=";
5478 } elsif ($searchtype eq 'committer') {
5479 $greptype = "--committer=";
5481 $greptype .= $searchtext;
5482 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5483 $greptype, '--regexp-ignore-case',
5484 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5486 my $paging_nav = '';
5489 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5490 searchtext
=>$searchtext,
5491 searchtype
=>$searchtype)},
5493 $paging_nav .= " ⋅ " .
5494 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5495 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5497 $paging_nav .= "first";
5498 $paging_nav .= " ⋅ prev";
5501 if ($#commitlist >= 100) {
5503 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5504 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5505 $paging_nav .= " ⋅ $next_link";
5507 $paging_nav .= " ⋅ next";
5510 if ($#commitlist >= 100) {
5513 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5514 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5515 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5518 if ($searchtype eq 'pickaxe') {
5519 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5520 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5522 print "<table class=\"pickaxe search\">\n";
5525 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5526 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5527 ($search_use_regexp ? '--pickaxe-regex' : ());
5530 while (my $line = <$fd>) {
5534 my %set = parse_difftree_raw_line
($line);
5535 if (defined $set{'commit'}) {
5536 # finish previous commit
5539 "<td class=\"link\">" .
5540 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5542 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5548 print "<tr class=\"dark\">\n";
5550 print "<tr class=\"light\">\n";
5553 %co = parse_commit
($set{'commit'});
5554 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5555 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5556 "<td><i>$author</i></td>\n" .
5558 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5559 -class => "list subject"},
5560 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5561 } elsif (defined $set{'to_id'}) {
5562 next if ($set{'to_id'} =~ m/^0{40}$/);
5564 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5565 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5567 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5573 # finish last commit (warning: repetition!)
5576 "<td class=\"link\">" .
5577 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5579 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5587 if ($searchtype eq 'grep') {
5588 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5589 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5591 print "<table class=\"grep_search\">\n";
5595 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5596 $search_use_regexp ? ('-E', '-i') : '-F',
5597 $searchtext, $co{'tree'};
5599 while (my $line = <$fd>) {
5601 my ($file, $lno, $ltext, $binary);
5602 last if ($matches++ > 1000);
5603 if ($line =~ /^Binary file (.+) matches$/) {
5607 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5609 if ($file ne $lastfile) {
5610 $lastfile and print "</td></tr>\n";
5612 print "<tr class=\"dark\">\n";
5614 print "<tr class=\"light\">\n";
5616 print "<td class=\"list\">".
5617 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5618 file_name
=>"$file"),
5619 -class => "list"}, esc_path
($file));
5620 print "</td><td>\n";
5624 print "<div class=\"binary\">Binary file</div>\n";
5626 $ltext = untabify
($ltext);
5627 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5628 $ltext = esc_html
($1, -nbsp
=>1);
5629 $ltext .= '<span class="match">';
5630 $ltext .= esc_html
($2, -nbsp
=>1);
5631 $ltext .= '</span>';
5632 $ltext .= esc_html
($3, -nbsp
=>1);
5634 $ltext = esc_html
($ltext, -nbsp
=>1);
5636 print "<div class=\"pre\">" .
5637 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5638 file_name
=>"$file").'#l'.$lno,
5639 -class => "linenr"}, sprintf('%4i', $lno))
5640 . ' ' . $ltext . "</div>\n";
5644 print "</td></tr>\n";
5645 if ($matches > 1000) {
5646 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5649 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5658 sub git_search_help
{
5660 git_print_page_nav
('','', $hash,$hash,$hash);
5662 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5663 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5664 the pattern entered is recognized as the POSIX extended
5665 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5668 <dt><b>commit</b></dt>
5669 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5671 my ($have_grep) = gitweb_check_feature
('grep');
5674 <dt><b>grep</b></dt>
5675 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5676 a different one) are searched for the given pattern. On large trees, this search can take
5677 a while and put some strain on the server, so please use it with some consideration. Note that
5678 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5679 case-sensitive.</dd>
5683 <dt><b>author</b></dt>
5684 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5685 <dt><b>committer</b></dt>
5686 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5688 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5689 if ($have_pickaxe) {
5691 <dt><b>pickaxe</b></dt>
5692 <dd>All commits that caused the string to appear or disappear from any file (changes that
5693 added, removed or "modified" the string) will be listed. This search can take a while and
5694 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5695 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5703 my $head = git_get_head_hash
($project);
5704 if (!defined $hash) {
5707 if (!defined $page) {
5710 my $refs = git_get_references
();
5712 my $commit_hash = $hash;
5713 if (defined $hash_parent) {
5714 $commit_hash = "$hash_parent..$hash";
5716 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5718 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5720 if ($#commitlist >= 100) {
5722 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5723 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5727 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5728 git_print_header_div
('summary', $project);
5730 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5735 ## ......................................................................
5736 ## feeds (RSS, Atom; OPML)
5739 my $format = shift || 'atom';
5740 my ($have_blame) = gitweb_check_feature
('blame');
5742 # Atom: http://www.atomenabled.org/developers/syndication/
5743 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5744 if ($format ne 'rss' && $format ne 'atom') {
5745 die_error
(400, "Unknown web feed format");
5748 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5749 my $head = $hash || 'HEAD';
5750 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5754 my $content_type = "application/$format+xml";
5755 if (defined $cgi->http('HTTP_ACCEPT') &&
5756 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5757 # browser (feed reader) prefers text/xml
5758 $content_type = 'text/xml';
5760 if (defined($commitlist[0])) {
5761 %latest_commit = %{$commitlist[0]};
5762 %latest_date = parse_date
($latest_commit{'author_epoch'});
5764 -type
=> $content_type,
5765 -charset
=> 'utf-8',
5766 -last_modified
=> $latest_date{'rfc2822'});
5769 -type
=> $content_type,
5770 -charset
=> 'utf-8');
5773 # Optimization: skip generating the body if client asks only
5774 # for Last-Modified date.
5775 return if ($cgi->request_method() eq 'HEAD');
5778 my $title = "$site_name - $project/$action";
5779 my $feed_type = 'log';
5780 if (defined $hash) {
5781 $title .= " - '$hash'";
5782 $feed_type = 'branch log';
5783 if (defined $file_name) {
5784 $title .= " :: $file_name";
5785 $feed_type = 'history';
5787 } elsif (defined $file_name) {
5788 $title .= " - $file_name";
5789 $feed_type = 'history';
5791 $title .= " $feed_type";
5792 my $descr = git_get_project_description
($project);
5793 if (defined $descr) {
5794 $descr = esc_html
($descr);
5796 $descr = "$project " .
5797 ($format eq 'rss' ? 'RSS' : 'Atom') .
5800 my $owner = git_get_project_owner
($project);
5801 $owner = esc_html
($owner);
5805 if (defined $file_name) {
5806 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5807 } elsif (defined $hash) {
5808 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5810 $alt_url = href
(-full
=>1, action
=>"summary");
5812 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5813 if ($format eq 'rss') {
5815 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5818 print "<title>$title</title>\n" .
5819 "<link>$alt_url</link>\n" .
5820 "<description>$descr</description>\n" .
5821 "<language>en</language>\n";
5822 } elsif ($format eq 'atom') {
5824 <feed xmlns="http://www.w3.org/2005/Atom">
5826 print "<title>$title</title>\n" .
5827 "<subtitle>$descr</subtitle>\n" .
5828 '<link rel="alternate" type="text/html" href="' .
5829 $alt_url . '" />' . "\n" .
5830 '<link rel="self" type="' . $content_type . '" href="' .
5831 $cgi->self_url() . '" />' . "\n" .
5832 "<id>" . href
(-full
=>1) . "</id>\n" .
5833 # use project owner for feed author
5834 "<author><name>$owner</name></author>\n";
5835 if (defined $favicon) {
5836 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5838 if (defined $logo_url) {
5839 # not twice as wide as tall: 72 x 27 pixels
5840 print "<logo>" . esc_url
($logo) . "</logo>\n";
5842 if (! %latest_date) {
5843 # dummy date to keep the feed valid until commits trickle in:
5844 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5846 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5851 for (my $i = 0; $i <= $#commitlist; $i++) {
5852 my %co = %{$commitlist[$i]};
5853 my $commit = $co{'id'};
5854 # we read 150, we always show 30 and the ones more recent than 48 hours
5855 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5858 my %cd = parse_date
($co{'author_epoch'});
5860 # get list of changed files
5861 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5862 $co{'parent'} || "--root",
5863 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5865 my @difftree = map { chomp; $_ } <$fd>;
5869 # print element (entry, item)
5870 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5871 if ($format eq 'rss') {
5873 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5874 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5875 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5876 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5877 "<link>$co_url</link>\n" .
5878 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5879 "<content:encoded>" .
5881 } elsif ($format eq 'atom') {
5883 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5884 "<updated>$cd{'iso-8601'}</updated>\n" .
5886 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5887 if ($co{'author_email'}) {
5888 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5890 print "</author>\n" .
5891 # use committer for contributor
5893 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5894 if ($co{'committer_email'}) {
5895 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5897 print "</contributor>\n" .
5898 "<published>$cd{'iso-8601'}</published>\n" .
5899 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5900 "<id>$co_url</id>\n" .
5901 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5902 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5904 my $comment = $co{'comment'};
5906 foreach my $line (@$comment) {
5907 $line = esc_html
($line);
5910 print "</pre><ul>\n";
5911 foreach my $difftree_line (@difftree) {
5912 my %difftree = parse_difftree_raw_line
($difftree_line);
5913 next if !$difftree{'from_id'};
5915 my $file = $difftree{'file'} || $difftree{'to_file'};
5919 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5920 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5921 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5922 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5923 -title
=> "diff"}, 'D');
5925 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5926 file_name
=>$file, hash_base
=>$commit),
5927 -title
=> "blame"}, 'B');
5929 # if this is not a feed of a file history
5930 if (!defined $file_name || $file_name ne $file) {
5931 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5932 file_name
=>$file, hash
=>$commit),
5933 -title
=> "history"}, 'H');
5935 $file = esc_path
($file);
5939 if ($format eq 'rss') {
5940 print "</ul>]]>\n" .
5941 "</content:encoded>\n" .
5943 } elsif ($format eq 'atom') {
5944 print "</ul>\n</div>\n" .
5951 if ($format eq 'rss') {
5952 print "</channel>\n</rss>\n";
5953 } elsif ($format eq 'atom') {
5967 my @list = git_get_projects_list
();
5969 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5971 <?xml version="1.0" encoding="utf-8"?>
5972 <opml version="1.0">
5974 <title>$site_name OPML Export</title>
5977 <outline text="git RSS feeds">
5980 foreach my $pr (@list) {
5982 my $head = git_get_head_hash
($proj{'path'});
5983 if (!defined $head) {
5986 $git_dir = "$projectroot/$proj{'path'}";
5987 my %co = parse_commit
($head);
5992 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5993 my $rss = "$my_url?p=$proj{'path'};a=rss";
5994 my $html = "$my_url?p=$proj{'path'};a=summary";
5995 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";