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 # next, check if we have an action
539 my $action = $path_info;
541 if (exists $actions{$action}) {
542 $path_info =~ s
,^$action/*,,;
543 $input_params{'action'} = $action;
546 # list of actions that want hash_base instead of hash, but can have no
547 # pathname (f) parameter
554 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
555 my ($parentrefname, $parentpathname, $refname, $pathname) =
556 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
558 # first, analyze the 'current' part
559 if (defined $pathname) {
560 # we got "branch:filename" or "branch:dir/"
561 # we could use git_get_type(branch:pathname), but:
562 # - it needs $git_dir
563 # - it does a git() call
564 # - the convention of terminating directories with a slash
565 # makes it superfluous
566 # - embedding the action in the PATH_INFO would make it even
568 $pathname =~ s
,^/+,,;
569 if (!$pathname || substr($pathname, -1) eq "/") {
570 $input_params{'action'} ||= "tree";
573 # the default action depends on whether we had parent info
575 if ($parentrefname) {
576 $input_params{'action'} ||= "blobdiff_plain";
578 $input_params{'action'} ||= "blob_plain";
581 $input_params{'hash_base'} ||= $refname;
582 $input_params{'file_name'} ||= $pathname;
583 } elsif (defined $refname) {
584 # we got "branch". In this case we have to choose if we have to
585 # set hash or hash_base.
587 # Most of the actions without a pathname only want hash to be
588 # set, except for the ones specified in @wants_base that want
589 # hash_base instead. It should also be noted that hand-crafted
590 # links having 'history' as an action and no pathname or hash
591 # set will fail, but that happens regardless of PATH_INFO.
592 $input_params{'action'} ||= "shortlog";
593 if (grep { $_ eq $input_params{'action'} } @wants_base) {
594 $input_params{'hash_base'} ||= $refname;
596 $input_params{'hash'} ||= $refname;
600 # next, handle the 'parent' part, if present
601 if (defined $parentrefname) {
602 # a missing pathspec defaults to the 'current' filename, allowing e.g.
603 # someproject/blobdiff/oldrev..newrev:/filename
604 if ($parentpathname) {
605 $parentpathname =~ s
,^/+,,;
606 $parentpathname =~ s
,/$,,;
607 $input_params{'file_parent'} ||= $parentpathname;
609 $input_params{'file_parent'} ||= $input_params{'file_name'};
611 # we assume that hash_parent_base is wanted if a path was specified,
612 # or if the action wants hash_base instead of hash
613 if (defined $input_params{'file_parent'} ||
614 grep { $_ eq $input_params{'action'} } @wants_base) {
615 $input_params{'hash_parent_base'} ||= $parentrefname;
617 $input_params{'hash_parent'} ||= $parentrefname;
621 evaluate_path_info
();
623 our $action = $input_params{'action'};
624 if (defined $action) {
625 if (!validate_action
($action)) {
626 die_error
(400, "Invalid action parameter");
630 # parameters which are pathnames
631 our $project = $input_params{'project'};
632 if (defined $project) {
633 if (!validate_project
($project)) {
635 die_error
(404, "No such project");
639 our $file_name = $input_params{'file_name'};
640 if (defined $file_name) {
641 if (!validate_pathname
($file_name)) {
642 die_error
(400, "Invalid file parameter");
646 our $file_parent = $input_params{'file_parent'};
647 if (defined $file_parent) {
648 if (!validate_pathname
($file_parent)) {
649 die_error
(400, "Invalid file parent parameter");
653 # parameters which are refnames
654 our $hash = $input_params{'hash'};
656 if (!validate_refname
($hash)) {
657 die_error
(400, "Invalid hash parameter");
661 our $hash_parent = $input_params{'hash_parent'};
662 if (defined $hash_parent) {
663 if (!validate_refname
($hash_parent)) {
664 die_error
(400, "Invalid hash parent parameter");
668 our $hash_base = $input_params{'hash_base'};
669 if (defined $hash_base) {
670 if (!validate_refname
($hash_base)) {
671 die_error
(400, "Invalid hash base parameter");
675 our @extra_options = @{$input_params{'extra_options'}};
676 # @extra_options is always defined, since it can only be (currently) set from
677 # CGI, and $cgi->param() returns the empty array in array context if the param
679 foreach my $opt (@extra_options) {
680 if (not exists $allowed_options{$opt}) {
681 die_error
(400, "Invalid option parameter");
683 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
684 die_error
(400, "Invalid option parameter for this action");
688 our $hash_parent_base = $input_params{'hash_parent_base'};
689 if (defined $hash_parent_base) {
690 if (!validate_refname
($hash_parent_base)) {
691 die_error
(400, "Invalid hash parent base parameter");
696 our $page = $input_params{'page'};
698 if ($page =~ m/[^0-9]/) {
699 die_error
(400, "Invalid page parameter");
703 our $searchtype = $input_params{'searchtype'};
704 if (defined $searchtype) {
705 if ($searchtype =~ m/[^a-z]/) {
706 die_error
(400, "Invalid searchtype parameter");
710 our $search_use_regexp = $input_params{'search_use_regexp'};
712 our $searchtext = $input_params{'searchtext'};
714 if (defined $searchtext) {
715 if (length($searchtext) < 2) {
716 die_error
(403, "At least two characters are required for search parameter");
718 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
721 # path to the current git repository
723 $git_dir = "$projectroot/$project" if $project;
725 # list of supported snapshot formats
726 our @snapshot_fmts = gitweb_check_feature
('snapshot');
727 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
730 if (!defined $action) {
732 $action = git_get_type
($hash);
733 } elsif (defined $hash_base && defined $file_name) {
734 $action = git_get_type
("$hash_base:$file_name");
735 } elsif (defined $project) {
738 $action = 'project_list';
741 if (!defined($actions{$action})) {
742 die_error
(400, "Unknown action");
744 if ($action !~ m/^(opml|project_list|project_index)$/ &&
746 die_error
(400, "Project needed");
748 $actions{$action}->();
751 ## ======================================================================
756 # default is to use -absolute url() i.e. $my_uri
757 my $href = $params{-full
} ? $my_url : $my_uri;
759 $params{'project'} = $project unless exists $params{'project'};
761 if ($params{-replay
}) {
762 while (my ($name, $symbol) = each %cgi_param_mapping) {
763 if (!exists $params{$name}) {
764 $params{$name} = $input_params{$name};
769 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
771 # try to put as many parameters as possible in PATH_INFO:
774 # - hash_parent or hash_parent_base:/file_parent
775 # - hash or hash_base:/filename
777 # When the script is the root DirectoryIndex for the domain,
778 # $href here would be something like http://gitweb.example.com/
779 # Thus, we strip any trailing / from $href, to spare us double
780 # slashes in the final URL
783 # Then add the project name, if present
784 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
785 delete $params{'project'};
787 # Summary just uses the project path URL, any other action is
789 if (defined $params{'action'}) {
790 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
791 delete $params{'action'};
794 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
795 # stripping nonexistent or useless pieces
796 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
797 || $params{'hash_parent'} || $params{'hash'});
798 if (defined $params{'hash_base'}) {
799 if (defined $params{'hash_parent_base'}) {
800 $href .= esc_url
($params{'hash_parent_base'});
801 # skip the file_parent if it's the same as the file_name
802 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
803 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
804 $href .= ":/".esc_url
($params{'file_parent'});
805 delete $params{'file_parent'};
808 delete $params{'hash_parent'};
809 delete $params{'hash_parent_base'};
810 } elsif (defined $params{'hash_parent'}) {
811 $href .= esc_url
($params{'hash_parent'}). "..";
812 delete $params{'hash_parent'};
815 $href .= esc_url
($params{'hash_base'});
816 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
817 $href .= ":/".esc_url
($params{'file_name'});
818 delete $params{'file_name'};
820 delete $params{'hash'};
821 delete $params{'hash_base'};
822 } elsif (defined $params{'hash'}) {
823 $href .= esc_url
($params{'hash'});
824 delete $params{'hash'};
828 # now encode the parameters explicitly
830 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
831 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
832 if (defined $params{$name}) {
833 if (ref($params{$name}) eq "ARRAY") {
834 foreach my $par (@{$params{$name}}) {
835 push @result, $symbol . "=" . esc_param
($par);
838 push @result, $symbol . "=" . esc_param
($params{$name});
842 $href .= "?" . join(';', @result) if scalar @result;
848 ## ======================================================================
849 ## validation, quoting/unquoting and escaping
851 sub validate_action
{
852 my $input = shift || return undef;
853 return undef unless exists $actions{$input};
857 sub validate_project
{
858 my $input = shift || return undef;
859 if (!validate_pathname
($input) ||
860 !(-d
"$projectroot/$input") ||
861 !check_head_link
("$projectroot/$input") ||
862 ($export_ok && !(-e
"$projectroot/$input/$export_ok")) ||
863 ($strict_export && !project_in_list
($input))) {
870 sub validate_pathname
{
871 my $input = shift || return undef;
873 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
874 # at the beginning, at the end, and between slashes.
875 # also this catches doubled slashes
876 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
880 if ($input =~ m!\0!) {
886 sub validate_refname
{
887 my $input = shift || return undef;
889 # textual hashes are O.K.
890 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
893 # it must be correct pathname
894 $input = validate_pathname
($input)
896 # restrictions on ref name according to git-check-ref-format
897 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
903 # decode sequences of octets in utf8 into Perl's internal form,
904 # which is utf-8 with utf8 flag set if needed. gitweb writes out
905 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
908 if (utf8
::valid
($str)) {
912 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
916 # quote unsafe chars, but keep the slash, even when it's not
917 # correct, but quoted slashes look too horrible in bookmarks
920 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
926 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
929 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
935 # replace invalid utf8 character with SUBSTITUTION sequence
940 $str = to_utf8
($str);
941 $str = $cgi->escapeHTML($str);
942 if ($opts{'-nbsp'}) {
943 $str =~ s/ / /g;
945 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
949 # quote control characters and escape filename to HTML
954 $str = to_utf8
($str);
955 $str = $cgi->escapeHTML($str);
956 if ($opts{'-nbsp'}) {
957 $str =~ s/ / /g;
959 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
963 # Make control characters "printable", using character escape codes (CEC)
967 my %es = ( # character escape codes, aka escape sequences
968 "\t" => '\t', # tab (HT)
969 "\n" => '\n', # line feed (LF)
970 "\r" => '\r', # carrige return (CR)
971 "\f" => '\f', # form feed (FF)
972 "\b" => '\b', # backspace (BS)
973 "\a" => '\a', # alarm (bell) (BEL)
974 "\e" => '\e', # escape (ESC)
975 "\013" => '\v', # vertical tab (VT)
976 "\000" => '\0', # nul character (NUL)
978 my $chr = ( (exists $es{$cntrl})
980 : sprintf('\%2x', ord($cntrl)) );
981 if ($opts{-nohtml
}) {
984 return "<span class=\"cntrl\">$chr</span>";
988 # Alternatively use unicode control pictures codepoints,
989 # Unicode "printable representation" (PR)
994 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
995 if ($opts{-nohtml
}) {
998 return "<span class=\"cntrl\">$chr</span>";
1002 # git may return quoted and escaped filenames
1008 my %es = ( # character escape codes, aka escape sequences
1009 't' => "\t", # tab (HT, TAB)
1010 'n' => "\n", # newline (NL)
1011 'r' => "\r", # return (CR)
1012 'f' => "\f", # form feed (FF)
1013 'b' => "\b", # backspace (BS)
1014 'a' => "\a", # alarm (bell) (BEL)
1015 'e' => "\e", # escape (ESC)
1016 'v' => "\013", # vertical tab (VT)
1019 if ($seq =~ m/^[0-7]{1,3}$/) {
1020 # octal char sequence
1021 return chr(oct($seq));
1022 } elsif (exists $es{$seq}) {
1023 # C escape sequence, aka character escape code
1026 # quoted ordinary character
1030 if ($str =~ m/^"(.*)"$/) {
1033 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1038 # escape tabs (convert tabs to spaces)
1042 while ((my $pos = index($line, "\t")) != -1) {
1043 if (my $count = (8 - ($pos % 8))) {
1044 my $spaces = ' ' x
$count;
1045 $line =~ s/\t/$spaces/;
1052 sub project_in_list
{
1053 my $project = shift;
1054 my @list = git_get_projects_list
();
1055 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1058 ## ----------------------------------------------------------------------
1059 ## HTML aware string manipulation
1061 # Try to chop given string on a word boundary between position
1062 # $len and $len+$add_len. If there is no word boundary there,
1063 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1064 # (marking chopped part) would be longer than given string.
1068 my $add_len = shift || 10;
1069 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1071 # Make sure perl knows it is utf8 encoded so we don't
1072 # cut in the middle of a utf8 multibyte char.
1073 $str = to_utf8
($str);
1075 # allow only $len chars, but don't cut a word if it would fit in $add_len
1076 # if it doesn't fit, cut it if it's still longer than the dots we would add
1077 # remove chopped character entities entirely
1079 # when chopping in the middle, distribute $len into left and right part
1080 # return early if chopping wouldn't make string shorter
1081 if ($where eq 'center') {
1082 return $str if ($len + 5 >= length($str)); # filler is length 5
1085 return $str if ($len + 4 >= length($str)); # filler is length 4
1088 # regexps: ending and beginning with word part up to $add_len
1089 my $endre = qr/.{$len}\w{0,$add_len}/;
1090 my $begre = qr/\w{0,$add_len}.{$len}/;
1092 if ($where eq 'left') {
1093 $str =~ m/^(.*?)($begre)$/;
1094 my ($lead, $body) = ($1, $2);
1095 if (length($lead) > 4) {
1096 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1099 return "$lead$body";
1101 } elsif ($where eq 'center') {
1102 $str =~ m/^($endre)(.*)$/;
1103 my ($left, $str) = ($1, $2);
1104 $str =~ m/^(.*?)($begre)$/;
1105 my ($mid, $right) = ($1, $2);
1106 if (length($mid) > 5) {
1107 $left =~ s/&[^;]*$//;
1108 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1111 return "$left$mid$right";
1114 $str =~ m/^($endre)(.*)$/;
1117 if (length($tail) > 4) {
1118 $body =~ s/&[^;]*$//;
1121 return "$body$tail";
1125 # takes the same arguments as chop_str, but also wraps a <span> around the
1126 # result with a title attribute if it does get chopped. Additionally, the
1127 # string is HTML-escaped.
1128 sub chop_and_escape_str
{
1131 my $chopped = chop_str
(@_);
1132 if ($chopped eq $str) {
1133 return esc_html
($chopped);
1135 $str =~ s/([[:cntrl:]])/?/g;
1136 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1140 ## ----------------------------------------------------------------------
1141 ## functions returning short strings
1143 # CSS class for given age value (in seconds)
1147 if (!defined $age) {
1149 } elsif ($age < 60*60*2) {
1151 } elsif ($age < 60*60*24*2) {
1158 # convert age in seconds to "nn units ago" string
1163 if ($age > 60*60*24*365*2) {
1164 $age_str = (int $age/60/60/24/365);
1165 $age_str .= " years ago";
1166 } elsif ($age > 60*60*24*(365/12)*2) {
1167 $age_str = int $age/60/60/24/(365/12);
1168 $age_str .= " months ago";
1169 } elsif ($age > 60*60*24*7*2) {
1170 $age_str = int $age/60/60/24/7;
1171 $age_str .= " weeks ago";
1172 } elsif ($age > 60*60*24*2) {
1173 $age_str = int $age/60/60/24;
1174 $age_str .= " days ago";
1175 } elsif ($age > 60*60*2) {
1176 $age_str = int $age/60/60;
1177 $age_str .= " hours ago";
1178 } elsif ($age > 60*2) {
1179 $age_str = int $age/60;
1180 $age_str .= " min ago";
1181 } elsif ($age > 2) {
1182 $age_str = int $age;
1183 $age_str .= " sec ago";
1185 $age_str .= " right now";
1191 S_IFINVALID
=> 0030000,
1192 S_IFGITLINK
=> 0160000,
1195 # submodule/subproject, a commit object reference
1196 sub S_ISGITLINK
($) {
1199 return (($mode & S_IFMT
) == S_IFGITLINK
)
1202 # convert file mode in octal to symbolic file mode string
1204 my $mode = oct shift;
1206 if (S_ISGITLINK
($mode)) {
1207 return 'm---------';
1208 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1209 return 'drwxr-xr-x';
1210 } elsif (S_ISLNK
($mode)) {
1211 return 'lrwxrwxrwx';
1212 } elsif (S_ISREG
($mode)) {
1213 # git cares only about the executable bit
1214 if ($mode & S_IXUSR
) {
1215 return '-rwxr-xr-x';
1217 return '-rw-r--r--';
1220 return '----------';
1224 # convert file mode in octal to file type string
1228 if ($mode !~ m/^[0-7]+$/) {
1234 if (S_ISGITLINK
($mode)) {
1236 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1238 } elsif (S_ISLNK
($mode)) {
1240 } elsif (S_ISREG
($mode)) {
1247 # convert file mode in octal to file type description string
1248 sub file_type_long
{
1251 if ($mode !~ m/^[0-7]+$/) {
1257 if (S_ISGITLINK
($mode)) {
1259 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1261 } elsif (S_ISLNK
($mode)) {
1263 } elsif (S_ISREG
($mode)) {
1264 if ($mode & S_IXUSR
) {
1265 return "executable";
1275 ## ----------------------------------------------------------------------
1276 ## functions returning short HTML fragments, or transforming HTML fragments
1277 ## which don't belong to other sections
1279 # format line of commit message.
1280 sub format_log_line_html
{
1283 $line = esc_html
($line, -nbsp
=>1);
1284 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1287 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1288 -class => "text"}, $hash_text);
1289 $line =~ s/$hash_text/$link/;
1294 # format marker of refs pointing to given object
1296 # the destination action is chosen based on object type and current context:
1297 # - for annotated tags, we choose the tag view unless it's the current view
1298 # already, in which case we go to shortlog view
1299 # - for other refs, we keep the current view if we're in history, shortlog or
1300 # log view, and select shortlog otherwise
1301 sub format_ref_marker
{
1302 my ($refs, $id) = @_;
1305 if (defined $refs->{$id}) {
1306 foreach my $ref (@{$refs->{$id}}) {
1307 # this code exploits the fact that non-lightweight tags are the
1308 # only indirect objects, and that they are the only objects for which
1309 # we want to use tag instead of shortlog as action
1310 my ($type, $name) = qw();
1311 my $indirect = ($ref =~ s/\^\{\}$//);
1312 # e.g. tags/v2.6.11 or heads/next
1313 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1322 $class .= " indirect" if $indirect;
1324 my $dest_action = "shortlog";
1327 $dest_action = "tag" unless $action eq "tag";
1328 } elsif ($action =~ /^(history|(short)?log)$/) {
1329 $dest_action = $action;
1333 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1336 my $link = $cgi->a({
1338 action
=>$dest_action,
1342 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1348 return ' <span class="refs">'. $markers . '</span>';
1354 # format, perhaps shortened and with markers, title line
1355 sub format_subject_html
{
1356 my ($long, $short, $href, $extra) = @_;
1357 $extra = '' unless defined($extra);
1359 if (length($short) < length($long)) {
1360 return $cgi->a({-href
=> $href, -class => "list subject",
1361 -title
=> to_utf8
($long)},
1362 esc_html
($short) . $extra);
1364 return $cgi->a({-href
=> $href, -class => "list subject"},
1365 esc_html
($long) . $extra);
1369 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1370 sub format_git_diff_header_line
{
1372 my $diffinfo = shift;
1373 my ($from, $to) = @_;
1375 if ($diffinfo->{'nparents'}) {
1377 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1378 if ($to->{'href'}) {
1379 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1380 esc_path
($to->{'file'}));
1381 } else { # file was deleted (no href)
1382 $line .= esc_path
($to->{'file'});
1386 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1387 if ($from->{'href'}) {
1388 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1389 'a/' . esc_path
($from->{'file'}));
1390 } else { # file was added (no href)
1391 $line .= 'a/' . esc_path
($from->{'file'});
1394 if ($to->{'href'}) {
1395 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1396 'b/' . esc_path
($to->{'file'}));
1397 } else { # file was deleted
1398 $line .= 'b/' . esc_path
($to->{'file'});
1402 return "<div class=\"diff header\">$line</div>\n";
1405 # format extended diff header line, before patch itself
1406 sub format_extended_diff_header_line
{
1408 my $diffinfo = shift;
1409 my ($from, $to) = @_;
1412 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1413 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1414 esc_path
($from->{'file'}));
1416 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1417 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1418 esc_path
($to->{'file'}));
1420 # match single <mode>
1421 if ($line =~ m/\s(\d{6})$/) {
1422 $line .= '<span class="info"> (' .
1423 file_type_long
($1) .
1427 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1428 # can match only for combined diff
1430 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1431 if ($from->{'href'}[$i]) {
1432 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1434 substr($diffinfo->{'from_id'}[$i],0,7));
1439 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1442 if ($to->{'href'}) {
1443 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1444 substr($diffinfo->{'to_id'},0,7));
1449 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1450 # can match only for ordinary diff
1451 my ($from_link, $to_link);
1452 if ($from->{'href'}) {
1453 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1454 substr($diffinfo->{'from_id'},0,7));
1456 $from_link = '0' x
7;
1458 if ($to->{'href'}) {
1459 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1460 substr($diffinfo->{'to_id'},0,7));
1464 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1465 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1468 return $line . "<br/>\n";
1471 # format from-file/to-file diff header
1472 sub format_diff_from_to_header
{
1473 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1478 #assert($line =~ m/^---/) if DEBUG;
1479 # no extra formatting for "^--- /dev/null"
1480 if (! $diffinfo->{'nparents'}) {
1481 # ordinary (single parent) diff
1482 if ($line =~ m!^--- "?a/!) {
1483 if ($from->{'href'}) {
1485 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1486 esc_path
($from->{'file'}));
1489 esc_path
($from->{'file'});
1492 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1495 # combined diff (merge commit)
1496 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1497 if ($from->{'href'}[$i]) {
1499 $cgi->a({-href
=>href
(action
=>"blobdiff",
1500 hash_parent
=>$diffinfo->{'from_id'}[$i],
1501 hash_parent_base
=>$parents[$i],
1502 file_parent
=>$from->{'file'}[$i],
1503 hash
=>$diffinfo->{'to_id'},
1505 file_name
=>$to->{'file'}),
1507 -title
=>"diff" . ($i+1)},
1510 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1511 esc_path
($from->{'file'}[$i]));
1513 $line = '--- /dev/null';
1515 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1520 #assert($line =~ m/^\+\+\+/) if DEBUG;
1521 # no extra formatting for "^+++ /dev/null"
1522 if ($line =~ m!^\+\+\+ "?b/!) {
1523 if ($to->{'href'}) {
1525 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1526 esc_path
($to->{'file'}));
1529 esc_path
($to->{'file'});
1532 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1537 # create note for patch simplified by combined diff
1538 sub format_diff_cc_simplified
{
1539 my ($diffinfo, @parents) = @_;
1542 $result .= "<div class=\"diff header\">" .
1544 if (!is_deleted
($diffinfo)) {
1545 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1547 hash
=>$diffinfo->{'to_id'},
1548 file_name
=>$diffinfo->{'to_file'}),
1550 esc_path
($diffinfo->{'to_file'}));
1552 $result .= esc_path
($diffinfo->{'to_file'});
1554 $result .= "</div>\n" . # class="diff header"
1555 "<div class=\"diff nodifferences\">" .
1557 "</div>\n"; # class="diff nodifferences"
1562 # format patch (diff) line (not to be used for diff headers)
1563 sub format_diff_line
{
1565 my ($from, $to) = @_;
1566 my $diff_class = "";
1570 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1572 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1573 if ($line =~ m/^\@{3}/) {
1574 $diff_class = " chunk_header";
1575 } elsif ($line =~ m/^\\/) {
1576 $diff_class = " incomplete";
1577 } elsif ($prefix =~ tr/+/+/) {
1578 $diff_class = " add";
1579 } elsif ($prefix =~ tr/-/-/) {
1580 $diff_class = " rem";
1583 # assume ordinary diff
1584 my $char = substr($line, 0, 1);
1586 $diff_class = " add";
1587 } elsif ($char eq '-') {
1588 $diff_class = " rem";
1589 } elsif ($char eq '@') {
1590 $diff_class = " chunk_header";
1591 } elsif ($char eq "\\") {
1592 $diff_class = " incomplete";
1595 $line = untabify
($line);
1596 if ($from && $to && $line =~ m/^\@{2} /) {
1597 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1598 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1600 $from_lines = 0 unless defined $from_lines;
1601 $to_lines = 0 unless defined $to_lines;
1603 if ($from->{'href'}) {
1604 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1605 -class=>"list"}, $from_text);
1607 if ($to->{'href'}) {
1608 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1609 -class=>"list"}, $to_text);
1611 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1612 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1613 return "<div class=\"diff$diff_class\">$line</div>\n";
1614 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1615 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1616 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1618 @from_text = split(' ', $ranges);
1619 for (my $i = 0; $i < @from_text; ++$i) {
1620 ($from_start[$i], $from_nlines[$i]) =
1621 (split(',', substr($from_text[$i], 1)), 0);
1624 $to_text = pop @from_text;
1625 $to_start = pop @from_start;
1626 $to_nlines = pop @from_nlines;
1628 $line = "<span class=\"chunk_info\">$prefix ";
1629 for (my $i = 0; $i < @from_text; ++$i) {
1630 if ($from->{'href'}[$i]) {
1631 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1632 -class=>"list"}, $from_text[$i]);
1634 $line .= $from_text[$i];
1638 if ($to->{'href'}) {
1639 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1640 -class=>"list"}, $to_text);
1644 $line .= " $prefix</span>" .
1645 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1646 return "<div class=\"diff$diff_class\">$line</div>\n";
1648 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1651 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1652 # linked. Pass the hash of the tree/commit to snapshot.
1653 sub format_snapshot_links
{
1655 my $num_fmts = @snapshot_fmts;
1656 if ($num_fmts > 1) {
1657 # A parenthesized list of links bearing format names.
1658 # e.g. "snapshot (_tar.gz_ _zip_)"
1659 return "snapshot (" . join(' ', map
1666 }, $known_snapshot_formats{$_}{'display'})
1667 , @snapshot_fmts) . ")";
1668 } elsif ($num_fmts == 1) {
1669 # A single "snapshot" link whose tooltip bears the format name.
1671 my ($fmt) = @snapshot_fmts;
1677 snapshot_format
=>$fmt
1679 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1681 } else { # $num_fmts == 0
1686 ## ......................................................................
1687 ## functions returning values to be passed, perhaps after some
1688 ## transformation, to other functions; e.g. returning arguments to href()
1690 # returns hash to be passed to href to generate gitweb URL
1691 # in -title key it returns description of link
1693 my $format = shift || 'Atom';
1694 my %res = (action
=> lc($format));
1696 # feed links are possible only for project views
1697 return unless (defined $project);
1698 # some views should link to OPML, or to generic project feed,
1699 # or don't have specific feed yet (so they should use generic)
1700 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1703 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1704 # from tag links; this also makes possible to detect branch links
1705 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1706 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1709 # find log type for feed description (title)
1711 if (defined $file_name) {
1712 $type = "history of $file_name";
1713 $type .= "/" if ($action eq 'tree');
1714 $type .= " on '$branch'" if (defined $branch);
1716 $type = "log of $branch" if (defined $branch);
1719 $res{-title
} = $type;
1720 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1721 $res{'file_name'} = $file_name;
1726 ## ----------------------------------------------------------------------
1727 ## git utility subroutines, invoking git commands
1729 # returns path to the core git executable and the --git-dir parameter as list
1731 return $GIT, '--git-dir='.$git_dir;
1734 # quote the given arguments for passing them to the shell
1735 # quote_command("command", "arg 1", "arg with ' and ! characters")
1736 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1737 # Try to avoid using this function wherever possible.
1740 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1743 # get HEAD ref of given project as hash
1744 sub git_get_head_hash
{
1745 my $project = shift;
1746 my $o_git_dir = $git_dir;
1748 $git_dir = "$projectroot/$project";
1749 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1752 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1756 if (defined $o_git_dir) {
1757 $git_dir = $o_git_dir;
1762 # get type of given object
1766 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1768 close $fd or return;
1773 # repository configuration
1774 our $config_file = '';
1777 # store multiple values for single key as anonymous array reference
1778 # single values stored directly in the hash, not as [ <value> ]
1779 sub hash_set_multi
{
1780 my ($hash, $key, $value) = @_;
1782 if (!exists $hash->{$key}) {
1783 $hash->{$key} = $value;
1784 } elsif (!ref $hash->{$key}) {
1785 $hash->{$key} = [ $hash->{$key}, $value ];
1787 push @{$hash->{$key}}, $value;
1791 # return hash of git project configuration
1792 # optionally limited to some section, e.g. 'gitweb'
1793 sub git_parse_project_config
{
1794 my $section_regexp = shift;
1799 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1802 while (my $keyval = <$fh>) {
1804 my ($key, $value) = split(/\n/, $keyval, 2);
1806 hash_set_multi
(\
%config, $key, $value)
1807 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1814 # convert config value to boolean, 'true' or 'false'
1815 # no value, number > 0, 'true' and 'yes' values are true
1816 # rest of values are treated as false (never as error)
1817 sub config_to_bool
{
1820 # strip leading and trailing whitespace
1824 return (!defined $val || # section.key
1825 ($val =~ /^\d+$/ && $val) || # section.key = 1
1826 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1829 # convert config value to simple decimal number
1830 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1831 # to be multiplied by 1024, 1048576, or 1073741824
1835 # strip leading and trailing whitespace
1839 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1841 # unknown unit is treated as 1
1842 return $num * ($unit eq 'g' ? 1073741824 :
1843 $unit eq 'm' ? 1048576 :
1844 $unit eq 'k' ? 1024 : 1);
1849 # convert config value to array reference, if needed
1850 sub config_to_multi
{
1853 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1856 sub git_get_project_config
{
1857 my ($key, $type) = @_;
1860 return unless ($key);
1861 $key =~ s/^gitweb\.//;
1862 return if ($key =~ m/\W/);
1865 if (defined $type) {
1868 unless ($type eq 'bool' || $type eq 'int');
1872 if (!defined $config_file ||
1873 $config_file ne "$git_dir/config") {
1874 %config = git_parse_project_config
('gitweb');
1875 $config_file = "$git_dir/config";
1879 if (!defined $type) {
1880 return $config{"gitweb.$key"};
1881 } elsif ($type eq 'bool') {
1882 # backward compatibility: 'git config --bool' returns true/false
1883 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
1884 } elsif ($type eq 'int') {
1885 return config_to_int
($config{"gitweb.$key"});
1887 return $config{"gitweb.$key"};
1890 # get hash of given path at given ref
1891 sub git_get_hash_by_path
{
1893 my $path = shift || return undef;
1898 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1899 or die_error
(500, "Open git-ls-tree failed");
1901 close $fd or return undef;
1903 if (!defined $line) {
1904 # there is no tree or hash given by $path at $base
1908 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1909 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1910 if (defined $type && $type ne $2) {
1911 # type doesn't match
1917 # get path of entry with given hash at given tree-ish (ref)
1918 # used to get 'from' filename for combined diff (merge commit) for renames
1919 sub git_get_path_by_hash
{
1920 my $base = shift || return;
1921 my $hash = shift || return;
1925 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1927 while (my $line = <$fd>) {
1930 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1931 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1932 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1941 ## ......................................................................
1942 ## git utility functions, directly accessing git repository
1944 sub git_get_project_description
{
1947 $git_dir = "$projectroot/$path";
1948 open my $fd, "$git_dir/description"
1949 or return git_get_project_config
('description');
1952 if (defined $descr) {
1958 sub git_get_project_ctags
{
1962 $git_dir = "$projectroot/$path";
1963 unless (opendir D
, "$git_dir/ctags") {
1966 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
1967 open CT
, $_ or next;
1971 my $ctag = $_; $ctag =~ s
#.*/##;
1972 $ctags->{$ctag} = $val;
1978 sub git_populate_project_tagcloud
{
1981 # First, merge different-cased tags; tags vote on casing
1983 foreach (keys %$ctags) {
1984 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
1985 if (not $ctags_lc{lc $_}->{topcount
}
1986 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
1987 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
1988 $ctags_lc{lc $_}->{topname
} = $_;
1993 if (eval { require HTML
::TagCloud
; 1; }) {
1994 $cloud = HTML
::TagCloud-
>new;
1995 foreach (sort keys %ctags_lc) {
1996 # Pad the title with spaces so that the cloud looks
1998 my $title = $ctags_lc{$_}->{topname
};
1999 $title =~ s/ / /g;
2000 $title =~ s/^/ /g;
2001 $title =~ s/$/ /g;
2002 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2005 $cloud = \
%ctags_lc;
2010 sub git_show_project_tagcloud
{
2011 my ($cloud, $count) = @_;
2012 print STDERR
ref($cloud)."..\n";
2013 if (ref $cloud eq 'HTML::TagCloud') {
2014 return $cloud->html_and_css($count);
2016 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2017 return '<p align="center">' . join (', ', map {
2018 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2019 } splice(@tags, 0, $count)) . '</p>';
2023 sub git_get_project_url_list
{
2026 $git_dir = "$projectroot/$path";
2027 open my $fd, "$git_dir/cloneurl"
2028 or return wantarray ?
2029 @{ config_to_multi
(git_get_project_config
('url')) } :
2030 config_to_multi
(git_get_project_config
('url'));
2031 my @git_project_url_list = map { chomp; $_ } <$fd>;
2034 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2037 sub git_get_projects_list
{
2042 $filter =~ s/\.git$//;
2044 my ($check_forks) = gitweb_check_feature
('forks');
2046 if (-d
$projects_list) {
2047 # search in directory
2048 my $dir = $projects_list . ($filter ? "/$filter" : '');
2049 # remove the trailing "/"
2051 my $pfxlen = length("$dir");
2052 my $pfxdepth = ($dir =~ tr!/!!);
2055 follow_fast
=> 1, # follow symbolic links
2056 follow_skip
=> 2, # ignore duplicates
2057 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2059 # skip project-list toplevel, if we get it.
2060 return if (m!^[/.]$!);
2061 # only directories can be git repositories
2062 return unless (-d
$_);
2063 # don't traverse too deep (Find is super slow on os x)
2064 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2065 $File::Find
::prune
= 1;
2069 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2070 # we check related file in $projectroot
2071 if (check_export_ok
("$projectroot/$filter/$subdir")) {
2072 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
2073 $File::Find
::prune
= 1;
2078 } elsif (-f
$projects_list) {
2079 # read from file(url-encoded):
2080 # 'git%2Fgit.git Linus+Torvalds'
2081 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2082 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2084 open my ($fd), $projects_list or return;
2086 while (my $line = <$fd>) {
2088 my ($path, $owner) = split ' ', $line;
2089 $path = unescape
($path);
2090 $owner = unescape
($owner);
2091 if (!defined $path) {
2094 if ($filter ne '') {
2095 # looking for forks;
2096 my $pfx = substr($path, 0, length($filter));
2097 if ($pfx ne $filter) {
2100 my $sfx = substr($path, length($filter));
2101 if ($sfx !~ /^\/.*\
.git
$/) {
2104 } elsif ($check_forks) {
2106 foreach my $filter (keys %paths) {
2107 # looking for forks;
2108 my $pfx = substr($path, 0, length($filter));
2109 if ($pfx ne $filter) {
2112 my $sfx = substr($path, length($filter));
2113 if ($sfx !~ /^\/.*\
.git
$/) {
2116 # is a fork, don't include it in
2121 if (check_export_ok
("$projectroot/$path")) {
2124 owner
=> to_utf8
($owner),
2127 (my $forks_path = $path) =~ s/\.git$//;
2128 $paths{$forks_path}++;
2136 our $gitweb_project_owner = undef;
2137 sub git_get_project_list_from_file
{
2139 return if (defined $gitweb_project_owner);
2141 $gitweb_project_owner = {};
2142 # read from file (url-encoded):
2143 # 'git%2Fgit.git Linus+Torvalds'
2144 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2145 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2146 if (-f
$projects_list) {
2147 open (my $fd , $projects_list);
2148 while (my $line = <$fd>) {
2150 my ($pr, $ow) = split ' ', $line;
2151 $pr = unescape
($pr);
2152 $ow = unescape
($ow);
2153 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2159 sub git_get_project_owner
{
2160 my $project = shift;
2163 return undef unless $project;
2164 $git_dir = "$projectroot/$project";
2166 if (!defined $gitweb_project_owner) {
2167 git_get_project_list_from_file
();
2170 if (exists $gitweb_project_owner->{$project}) {
2171 $owner = $gitweb_project_owner->{$project};
2173 if (!defined $owner){
2174 $owner = git_get_project_config
('owner');
2176 if (!defined $owner) {
2177 $owner = get_file_owner
("$git_dir");
2183 sub git_get_last_activity
{
2187 $git_dir = "$projectroot/$path";
2188 open($fd, "-|", git_cmd
(), 'for-each-ref',
2189 '--format=%(committer)',
2190 '--sort=-committerdate',
2192 'refs/heads') or return;
2193 my $most_recent = <$fd>;
2194 close $fd or return;
2195 if (defined $most_recent &&
2196 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2198 my $age = time - $timestamp;
2199 return ($age, age_string
($age));
2201 return (undef, undef);
2204 sub git_get_references
{
2205 my $type = shift || "";
2207 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2208 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2209 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2210 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2213 while (my $line = <$fd>) {
2215 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2216 if (defined $refs{$1}) {
2217 push @{$refs{$1}}, $2;
2223 close $fd or return;
2227 sub git_get_rev_name_tags
{
2228 my $hash = shift || return undef;
2230 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2232 my $name_rev = <$fd>;
2235 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2238 # catches also '$hash undefined' output
2243 ## ----------------------------------------------------------------------
2244 ## parse to hash functions
2248 my $tz = shift || "-0000";
2251 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2252 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2253 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2254 $date{'hour'} = $hour;
2255 $date{'minute'} = $min;
2256 $date{'mday'} = $mday;
2257 $date{'day'} = $days[$wday];
2258 $date{'month'} = $months[$mon];
2259 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2260 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2261 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2262 $mday, $months[$mon], $hour ,$min;
2263 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2264 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2266 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2267 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2268 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2269 $date{'hour_local'} = $hour;
2270 $date{'minute_local'} = $min;
2271 $date{'tz_local'} = $tz;
2272 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2273 1900+$year, $mon+1, $mday,
2274 $hour, $min, $sec, $tz);
2283 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2284 $tag{'id'} = $tag_id;
2285 while (my $line = <$fd>) {
2287 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2288 $tag{'object'} = $1;
2289 } elsif ($line =~ m/^type (.+)$/) {
2291 } elsif ($line =~ m/^tag (.+)$/) {
2293 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2294 $tag{'author'} = $1;
2297 } elsif ($line =~ m/--BEGIN/) {
2298 push @comment, $line;
2300 } elsif ($line eq "") {
2304 push @comment, <$fd>;
2305 $tag{'comment'} = \
@comment;
2306 close $fd or return;
2307 if (!defined $tag{'name'}) {
2313 sub parse_commit_text
{
2314 my ($commit_text, $withparents) = @_;
2315 my @commit_lines = split '\n', $commit_text;
2318 pop @commit_lines; # Remove '\0'
2320 if (! @commit_lines) {
2324 my $header = shift @commit_lines;
2325 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2328 ($co{'id'}, my @parents) = split ' ', $header;
2329 while (my $line = shift @commit_lines) {
2330 last if $line eq "\n";
2331 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2333 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2335 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2337 $co{'author_epoch'} = $2;
2338 $co{'author_tz'} = $3;
2339 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2340 $co{'author_name'} = $1;
2341 $co{'author_email'} = $2;
2343 $co{'author_name'} = $co{'author'};
2345 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2346 $co{'committer'} = $1;
2347 $co{'committer_epoch'} = $2;
2348 $co{'committer_tz'} = $3;
2349 $co{'committer_name'} = $co{'committer'};
2350 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2351 $co{'committer_name'} = $1;
2352 $co{'committer_email'} = $2;
2354 $co{'committer_name'} = $co{'committer'};
2358 if (!defined $co{'tree'}) {
2361 $co{'parents'} = \
@parents;
2362 $co{'parent'} = $parents[0];
2364 foreach my $title (@commit_lines) {
2367 $co{'title'} = chop_str
($title, 80, 5);
2368 # remove leading stuff of merges to make the interesting part visible
2369 if (length($title) > 50) {
2370 $title =~ s/^Automatic //;
2371 $title =~ s/^merge (of|with) /Merge ... /i;
2372 if (length($title) > 50) {
2373 $title =~ s/(http|rsync):\/\///;
2375 if (length($title) > 50) {
2376 $title =~ s/(master|www|rsync)\.//;
2378 if (length($title) > 50) {
2379 $title =~ s/kernel.org:?//;
2381 if (length($title) > 50) {
2382 $title =~ s/\/pub\/scm//;
2385 $co{'title_short'} = chop_str
($title, 50, 5);
2389 if (! defined $co{'title'} || $co{'title'} eq "") {
2390 $co{'title'} = $co{'title_short'} = '(no commit message)';
2392 # remove added spaces
2393 foreach my $line (@commit_lines) {
2396 $co{'comment'} = \
@commit_lines;
2398 my $age = time - $co{'committer_epoch'};
2400 $co{'age_string'} = age_string
($age);
2401 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2402 if ($age > 60*60*24*7*2) {
2403 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2404 $co{'age_string_age'} = $co{'age_string'};
2406 $co{'age_string_date'} = $co{'age_string'};
2407 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2413 my ($commit_id) = @_;
2418 open my $fd, "-|", git_cmd
(), "rev-list",
2424 or die_error
(500, "Open git-rev-list failed");
2425 %co = parse_commit_text
(<$fd>, 1);
2432 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2440 open my $fd, "-|", git_cmd
(), "rev-list",
2443 ("--max-count=" . $maxcount),
2444 ("--skip=" . $skip),
2448 ($filename ? ($filename) : ())
2449 or die_error
(500, "Open git-rev-list failed");
2450 while (my $line = <$fd>) {
2451 my %co = parse_commit_text
($line);
2456 return wantarray ? @cos : \
@cos;
2459 # parse line of git-diff-tree "raw" output
2460 sub parse_difftree_raw_line
{
2464 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2465 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2466 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2467 $res{'from_mode'} = $1;
2468 $res{'to_mode'} = $2;
2469 $res{'from_id'} = $3;
2471 $res{'status'} = $5;
2472 $res{'similarity'} = $6;
2473 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2474 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2476 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2479 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2480 # combined diff (for merge commit)
2481 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2482 $res{'nparents'} = length($1);
2483 $res{'from_mode'} = [ split(' ', $2) ];
2484 $res{'to_mode'} = pop @{$res{'from_mode'}};
2485 $res{'from_id'} = [ split(' ', $3) ];
2486 $res{'to_id'} = pop @{$res{'from_id'}};
2487 $res{'status'} = [ split('', $4) ];
2488 $res{'to_file'} = unquote
($5);
2490 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2491 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2492 $res{'commit'} = $1;
2495 return wantarray ? %res : \
%res;
2498 # wrapper: return parsed line of git-diff-tree "raw" output
2499 # (the argument might be raw line, or parsed info)
2500 sub parsed_difftree_line
{
2501 my $line_or_ref = shift;
2503 if (ref($line_or_ref) eq "HASH") {
2504 # pre-parsed (or generated by hand)
2505 return $line_or_ref;
2507 return parse_difftree_raw_line
($line_or_ref);
2511 # parse line of git-ls-tree output
2512 sub parse_ls_tree_line
($;%) {
2517 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2518 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2526 $res{'name'} = unquote
($4);
2529 return wantarray ? %res : \
%res;
2532 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2533 sub parse_from_to_diffinfo
{
2534 my ($diffinfo, $from, $to, @parents) = @_;
2536 if ($diffinfo->{'nparents'}) {
2538 $from->{'file'} = [];
2539 $from->{'href'} = [];
2540 fill_from_file_info
($diffinfo, @parents)
2541 unless exists $diffinfo->{'from_file'};
2542 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2543 $from->{'file'}[$i] =
2544 defined $diffinfo->{'from_file'}[$i] ?
2545 $diffinfo->{'from_file'}[$i] :
2546 $diffinfo->{'to_file'};
2547 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2548 $from->{'href'}[$i] = href
(action
=>"blob",
2549 hash_base
=>$parents[$i],
2550 hash
=>$diffinfo->{'from_id'}[$i],
2551 file_name
=>$from->{'file'}[$i]);
2553 $from->{'href'}[$i] = undef;
2557 # ordinary (not combined) diff
2558 $from->{'file'} = $diffinfo->{'from_file'};
2559 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2560 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2561 hash
=>$diffinfo->{'from_id'},
2562 file_name
=>$from->{'file'});
2564 delete $from->{'href'};
2568 $to->{'file'} = $diffinfo->{'to_file'};
2569 if (!is_deleted
($diffinfo)) { # file exists in result
2570 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2571 hash
=>$diffinfo->{'to_id'},
2572 file_name
=>$to->{'file'});
2574 delete $to->{'href'};
2578 ## ......................................................................
2579 ## parse to array of hashes functions
2581 sub git_get_heads_list
{
2585 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2586 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2587 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2590 while (my $line = <$fd>) {
2594 my ($refinfo, $committerinfo) = split(/\0/, $line);
2595 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2596 my ($committer, $epoch, $tz) =
2597 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2598 $ref_item{'fullname'} = $name;
2599 $name =~ s!^refs/heads/!!;
2601 $ref_item{'name'} = $name;
2602 $ref_item{'id'} = $hash;
2603 $ref_item{'title'} = $title || '(no commit message)';
2604 $ref_item{'epoch'} = $epoch;
2606 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2608 $ref_item{'age'} = "unknown";
2611 push @headslist, \
%ref_item;
2615 return wantarray ? @headslist : \
@headslist;
2618 sub git_get_tags_list
{
2622 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2623 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2624 '--format=%(objectname) %(objecttype) %(refname) '.
2625 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2628 while (my $line = <$fd>) {
2632 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2633 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2634 my ($creator, $epoch, $tz) =
2635 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2636 $ref_item{'fullname'} = $name;
2637 $name =~ s!^refs/tags/!!;
2639 $ref_item{'type'} = $type;
2640 $ref_item{'id'} = $id;
2641 $ref_item{'name'} = $name;
2642 if ($type eq "tag") {
2643 $ref_item{'subject'} = $title;
2644 $ref_item{'reftype'} = $reftype;
2645 $ref_item{'refid'} = $refid;
2647 $ref_item{'reftype'} = $type;
2648 $ref_item{'refid'} = $id;
2651 if ($type eq "tag" || $type eq "commit") {
2652 $ref_item{'epoch'} = $epoch;
2654 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2656 $ref_item{'age'} = "unknown";
2660 push @tagslist, \
%ref_item;
2664 return wantarray ? @tagslist : \
@tagslist;
2667 ## ----------------------------------------------------------------------
2668 ## filesystem-related functions
2670 sub get_file_owner
{
2673 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2674 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2675 if (!defined $gcos) {
2679 $owner =~ s/[,;].*$//;
2680 return to_utf8
($owner);
2683 ## ......................................................................
2684 ## mimetype related functions
2686 sub mimetype_guess_file
{
2687 my $filename = shift;
2688 my $mimemap = shift;
2689 -r
$mimemap or return undef;
2692 open(MIME
, $mimemap) or return undef;
2694 next if m/^#/; # skip comments
2695 my ($mime, $exts) = split(/\t+/);
2696 if (defined $exts) {
2697 my @exts = split(/\s+/, $exts);
2698 foreach my $ext (@exts) {
2699 $mimemap{$ext} = $mime;
2705 $filename =~ /\.([^.]*)$/;
2706 return $mimemap{$1};
2709 sub mimetype_guess
{
2710 my $filename = shift;
2712 $filename =~ /\./ or return undef;
2714 if ($mimetypes_file) {
2715 my $file = $mimetypes_file;
2716 if ($file !~ m!^/!) { # if it is relative path
2717 # it is relative to project
2718 $file = "$projectroot/$project/$file";
2720 $mime = mimetype_guess_file
($filename, $file);
2722 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2728 my $filename = shift;
2731 my $mime = mimetype_guess
($filename);
2732 $mime and return $mime;
2736 return $default_blob_plain_mimetype unless $fd;
2739 return 'text/plain';
2740 } elsif (! $filename) {
2741 return 'application/octet-stream';
2742 } elsif ($filename =~ m/\.png$/i) {
2744 } elsif ($filename =~ m/\.gif$/i) {
2746 } elsif ($filename =~ m/\.jpe?g$/i) {
2747 return 'image/jpeg';
2749 return 'application/octet-stream';
2753 sub blob_contenttype
{
2754 my ($fd, $file_name, $type) = @_;
2756 $type ||= blob_mimetype
($fd, $file_name);
2757 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2758 $type .= "; charset=$default_text_plain_charset";
2764 ## ======================================================================
2765 ## functions printing HTML: header, footer, error page
2767 sub git_header_html
{
2768 my $status = shift || "200 OK";
2769 my $expires = shift;
2771 my $title = "$site_name";
2772 if (defined $project) {
2773 $title .= " - " . to_utf8
($project);
2774 if (defined $action) {
2775 $title .= "/$action";
2776 if (defined $file_name) {
2777 $title .= " - " . esc_path
($file_name);
2778 if ($action eq "tree" && $file_name !~ m
|/$|) {
2785 # require explicit support from the UA if we are to send the page as
2786 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2787 # we have to do this because MSIE sometimes globs '*/*', pretending to
2788 # support xhtml+xml but choking when it gets what it asked for.
2789 if (defined $cgi->http('HTTP_ACCEPT') &&
2790 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2791 $cgi->Accept('application/xhtml+xml') != 0) {
2792 $content_type = 'application/xhtml+xml';
2794 $content_type = 'text/html';
2796 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2797 -status
=> $status, -expires
=> $expires);
2798 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2800 <?xml version="1.0" encoding="utf-8"?>
2801 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2802 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2803 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2804 <!-- git core binaries version $git_version -->
2806 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2807 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2808 <meta name="robots" content="index, nofollow"/>
2809 <title>$title</title>
2811 # print out each stylesheet that exist
2812 if (defined $stylesheet) {
2813 #provides backwards capability for those people who define style sheet in a config file
2814 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2816 foreach my $stylesheet (@stylesheets) {
2817 next unless $stylesheet;
2818 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2821 if (defined $project) {
2822 my %href_params = get_feed_info
();
2823 if (!exists $href_params{'-title'}) {
2824 $href_params{'-title'} = 'log';
2827 foreach my $format qw(RSS Atom) {
2828 my $type = lc($format);
2830 '-rel' => 'alternate',
2831 '-title' => "$project - $href_params{'-title'} - $format feed",
2832 '-type' => "application/$type+xml"
2835 $href_params{'action'} = $type;
2836 $link_attr{'-href'} = href
(%href_params);
2838 "rel=\"$link_attr{'-rel'}\" ".
2839 "title=\"$link_attr{'-title'}\" ".
2840 "href=\"$link_attr{'-href'}\" ".
2841 "type=\"$link_attr{'-type'}\" ".
2844 $href_params{'extra_options'} = '--no-merges';
2845 $link_attr{'-href'} = href
(%href_params);
2846 $link_attr{'-title'} .= ' (no merges)';
2848 "rel=\"$link_attr{'-rel'}\" ".
2849 "title=\"$link_attr{'-title'}\" ".
2850 "href=\"$link_attr{'-href'}\" ".
2851 "type=\"$link_attr{'-type'}\" ".
2856 printf('<link rel="alternate" title="%s projects list" '.
2857 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2858 $site_name, href
(project
=>undef, action
=>"project_index"));
2859 printf('<link rel="alternate" title="%s projects feeds" '.
2860 'href="%s" type="text/x-opml" />'."\n",
2861 $site_name, href
(project
=>undef, action
=>"opml"));
2863 if (defined $favicon) {
2864 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2870 if (-f
$site_header) {
2871 open (my $fd, $site_header);
2876 print "<div class=\"page_header\">\n" .
2877 $cgi->a({-href
=> esc_url
($logo_url),
2878 -title
=> $logo_label},
2879 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2880 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2881 if (defined $project) {
2882 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2883 if (defined $action) {
2890 my ($have_search) = gitweb_check_feature
('search');
2891 if (defined $project && $have_search) {
2892 if (!defined $searchtext) {
2896 if (defined $hash_base) {
2897 $search_hash = $hash_base;
2898 } elsif (defined $hash) {
2899 $search_hash = $hash;
2901 $search_hash = "HEAD";
2903 my $action = $my_uri;
2904 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2905 if ($use_pathinfo) {
2906 $action .= "/".esc_url
($project);
2908 print $cgi->startform(-method => "get", -action
=> $action) .
2909 "<div class=\"search\">\n" .
2911 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2912 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2913 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2914 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2915 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2916 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2918 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2919 "<span title=\"Extended regular expression\">" .
2920 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2921 -checked
=> $search_use_regexp) .
2924 $cgi->end_form() . "\n";
2928 sub git_footer_html
{
2929 my $feed_class = 'rss_logo';
2931 print "<div class=\"page_footer\">\n";
2932 if (defined $project) {
2933 my $descr = git_get_project_description
($project);
2934 if (defined $descr) {
2935 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2938 my %href_params = get_feed_info
();
2939 if (!%href_params) {
2940 $feed_class .= ' generic';
2942 $href_params{'-title'} ||= 'log';
2944 foreach my $format qw(RSS Atom) {
2945 $href_params{'action'} = lc($format);
2946 print $cgi->a({-href
=> href
(%href_params),
2947 -title
=> "$href_params{'-title'} $format feed",
2948 -class => $feed_class}, $format)."\n";
2952 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2953 -class => $feed_class}, "OPML") . " ";
2954 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2955 -class => $feed_class}, "TXT") . "\n";
2957 print "</div>\n"; # class="page_footer"
2959 if (-f
$site_footer) {
2960 open (my $fd, $site_footer);
2969 # die_error(<http_status_code>, <error_message>)
2970 # Example: die_error(404, 'Hash not found')
2971 # By convention, use the following status codes (as defined in RFC 2616):
2972 # 400: Invalid or missing CGI parameters, or
2973 # requested object exists but has wrong type.
2974 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2975 # this server or project.
2976 # 404: Requested object/revision/project doesn't exist.
2977 # 500: The server isn't configured properly, or
2978 # an internal error occurred (e.g. failed assertions caused by bugs), or
2979 # an unknown error occurred (e.g. the git binary died unexpectedly).
2981 my $status = shift || 500;
2982 my $error = shift || "Internal server error";
2984 my %http_responses = (400 => '400 Bad Request',
2985 403 => '403 Forbidden',
2986 404 => '404 Not Found',
2987 500 => '500 Internal Server Error');
2988 git_header_html
($http_responses{$status});
2990 <div class="page_body">
3000 ## ----------------------------------------------------------------------
3001 ## functions printing or outputting HTML: navigation
3003 sub git_print_page_nav
{
3004 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3005 $extra = '' if !defined $extra; # pager or formats
3007 my @navs = qw(summary shortlog log commit commitdiff tree);
3009 @navs = grep { $_ ne $suppress } @navs;
3012 my %arg = map { $_ => {action
=>$_} } @navs;
3013 if (defined $head) {
3014 for (qw(commit commitdiff)) {
3015 $arg{$_}{'hash'} = $head;
3017 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3018 for (qw(shortlog log)) {
3019 $arg{$_}{'hash'} = $head;
3024 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3025 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3027 my @actions = gitweb_check_feature
('actions');
3030 'n' => $project, # project name
3031 'f' => $git_dir, # project path within filesystem
3032 'h' => $treehead || '', # current hash ('h' parameter)
3033 'b' => $treebase || '', # hash base ('hb' parameter)
3036 my ($label, $link, $pos) = splice(@actions,0,3);
3038 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3040 $link =~ s/%([%nfhb])/$repl{$1}/g;
3041 $arg{$label}{'_href'} = $link;
3044 print "<div class=\"page_nav\">\n" .
3046 map { $_ eq $current ?
3047 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3049 print "<br/>\n$extra<br/>\n" .
3053 sub format_paging_nav
{
3054 my ($action, $hash, $head, $page, $has_next_link) = @_;
3058 if ($hash ne $head || $page) {
3059 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3061 $paging_nav .= "HEAD";
3065 $paging_nav .= " ⋅ " .
3066 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3067 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3069 $paging_nav .= " ⋅ prev";
3072 if ($has_next_link) {
3073 $paging_nav .= " ⋅ " .
3074 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3075 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3077 $paging_nav .= " ⋅ next";
3083 ## ......................................................................
3084 ## functions printing or outputting HTML: div
3086 sub git_print_header_div
{
3087 my ($action, $title, $hash, $hash_base) = @_;
3090 $args{'action'} = $action;
3091 $args{'hash'} = $hash if $hash;
3092 $args{'hash_base'} = $hash_base if $hash_base;
3094 print "<div class=\"header\">\n" .
3095 $cgi->a({-href
=> href
(%args), -class => "title"},
3096 $title ? $title : $action) .
3100 #sub git_print_authorship (\%) {
3101 sub git_print_authorship
{
3104 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3105 print "<div class=\"author_date\">" .
3106 esc_html
($co->{'author_name'}) .
3108 if ($ad{'hour_local'} < 6) {
3109 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3110 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3112 printf(" (%02d:%02d %s)",
3113 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3118 sub git_print_page_path
{
3124 print "<div class=\"page_path\">";
3125 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3126 -title
=> 'tree root'}, to_utf8
("[$project]"));
3128 if (defined $name) {
3129 my @dirname = split '/', $name;
3130 my $basename = pop @dirname;
3133 foreach my $dir (@dirname) {
3134 $fullname .= ($fullname ? '/' : '') . $dir;
3135 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3137 -title
=> $fullname}, esc_path
($dir));
3140 if (defined $type && $type eq 'blob') {
3141 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3143 -title
=> $name}, esc_path
($basename));
3144 } elsif (defined $type && $type eq 'tree') {
3145 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3147 -title
=> $name}, esc_path
($basename));
3150 print esc_path
($basename);
3153 print "<br/></div>\n";
3156 # sub git_print_log (\@;%) {
3157 sub git_print_log
($;%) {
3161 if ($opts{'-remove_title'}) {
3162 # remove title, i.e. first line of log
3165 # remove leading empty lines
3166 while (defined $log->[0] && $log->[0] eq "") {
3173 foreach my $line (@$log) {
3174 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3177 if (! $opts{'-remove_signoff'}) {
3178 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3181 # remove signoff lines
3188 # print only one empty line
3189 # do not print empty line after signoff
3191 next if ($empty || $signoff);
3197 print format_log_line_html
($line) . "<br/>\n";
3200 if ($opts{'-final_empty_line'}) {
3201 # end with single empty line
3202 print "<br/>\n" unless $empty;
3206 # return link target (what link points to)
3207 sub git_get_link_target
{
3212 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3216 $link_target = <$fd>;
3221 return $link_target;
3224 # given link target, and the directory (basedir) the link is in,
3225 # return target of link relative to top directory (top tree);
3226 # return undef if it is not possible (including absolute links).
3227 sub normalize_link_target
{
3228 my ($link_target, $basedir, $hash_base) = @_;
3230 # we can normalize symlink target only if $hash_base is provided
3231 return unless $hash_base;
3233 # absolute symlinks (beginning with '/') cannot be normalized
3234 return if (substr($link_target, 0, 1) eq '/');
3236 # normalize link target to path from top (root) tree (dir)
3239 $path = $basedir . '/' . $link_target;
3241 # we are in top (root) tree (dir)
3242 $path = $link_target;
3245 # remove //, /./, and /../
3247 foreach my $part (split('/', $path)) {
3248 # discard '.' and ''
3249 next if (!$part || $part eq '.');
3251 if ($part eq '..') {
3255 # link leads outside repository (outside top dir)
3259 push @path_parts, $part;
3262 $path = join('/', @path_parts);
3267 # print tree entry (row of git_tree), but without encompassing <tr> element
3268 sub git_print_tree_entry
{
3269 my ($t, $basedir, $hash_base, $have_blame) = @_;
3272 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3274 # The format of a table row is: mode list link. Where mode is
3275 # the mode of the entry, list is the name of the entry, an href,
3276 # and link is the action links of the entry.
3278 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3279 if ($t->{'type'} eq "blob") {
3280 print "<td class=\"list\">" .
3281 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3282 file_name
=>"$basedir$t->{'name'}", %base_key),
3283 -class => "list"}, esc_path
($t->{'name'}));
3284 if (S_ISLNK
(oct $t->{'mode'})) {
3285 my $link_target = git_get_link_target
($t->{'hash'});
3287 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3288 if (defined $norm_target) {
3290 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3291 file_name
=>$norm_target),
3292 -title
=> $norm_target}, esc_path
($link_target));
3294 print " -> " . esc_path
($link_target);
3299 print "<td class=\"link\">";
3300 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3301 file_name
=>"$basedir$t->{'name'}", %base_key)},
3305 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3306 file_name
=>"$basedir$t->{'name'}", %base_key)},
3309 if (defined $hash_base) {
3311 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3312 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3316 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3317 file_name
=>"$basedir$t->{'name'}")},
3321 } elsif ($t->{'type'} eq "tree") {
3322 print "<td class=\"list\">";
3323 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3324 file_name
=>"$basedir$t->{'name'}", %base_key)},
3325 esc_path
($t->{'name'}));
3327 print "<td class=\"link\">";
3328 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3329 file_name
=>"$basedir$t->{'name'}", %base_key)},
3331 if (defined $hash_base) {
3333 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3334 file_name
=>"$basedir$t->{'name'}")},
3339 # unknown object: we can only present history for it
3340 # (this includes 'commit' object, i.e. submodule support)
3341 print "<td class=\"list\">" .
3342 esc_path
($t->{'name'}) .
3344 print "<td class=\"link\">";
3345 if (defined $hash_base) {
3346 print $cgi->a({-href
=> href
(action
=>"history",
3347 hash_base
=>$hash_base,
3348 file_name
=>"$basedir$t->{'name'}")},
3355 ## ......................................................................
3356 ## functions printing large fragments of HTML
3358 # get pre-image filenames for merge (combined) diff
3359 sub fill_from_file_info
{
3360 my ($diff, @parents) = @_;
3362 $diff->{'from_file'} = [ ];
3363 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3364 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3365 if ($diff->{'status'}[$i] eq 'R' ||
3366 $diff->{'status'}[$i] eq 'C') {
3367 $diff->{'from_file'}[$i] =
3368 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3375 # is current raw difftree line of file deletion
3377 my $diffinfo = shift;
3379 return $diffinfo->{'to_id'} eq ('0' x
40);
3382 # does patch correspond to [previous] difftree raw line
3383 # $diffinfo - hashref of parsed raw diff format
3384 # $patchinfo - hashref of parsed patch diff format
3385 # (the same keys as in $diffinfo)
3386 sub is_patch_split
{
3387 my ($diffinfo, $patchinfo) = @_;
3389 return defined $diffinfo && defined $patchinfo
3390 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3394 sub git_difftree_body
{
3395 my ($difftree, $hash, @parents) = @_;
3396 my ($parent) = $parents[0];
3397 my ($have_blame) = gitweb_check_feature
('blame');
3398 print "<div class=\"list_head\">\n";
3399 if ($#{$difftree} > 10) {
3400 print(($#{$difftree} + 1) . " files changed:\n");
3404 print "<table class=\"" .
3405 (@parents > 1 ? "combined " : "") .
3408 # header only for combined diff in 'commitdiff' view
3409 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3412 print "<thead><tr>\n" .
3413 "<th></th><th></th>\n"; # filename, patchN link
3414 for (my $i = 0; $i < @parents; $i++) {
3415 my $par = $parents[$i];
3417 $cgi->a({-href
=> href
(action
=>"commitdiff",
3418 hash
=>$hash, hash_parent
=>$par),
3419 -title
=> 'commitdiff to parent number ' .
3420 ($i+1) . ': ' . substr($par,0,7)},
3424 print "</tr></thead>\n<tbody>\n";
3429 foreach my $line (@{$difftree}) {
3430 my $diff = parsed_difftree_line
($line);
3433 print "<tr class=\"dark\">\n";
3435 print "<tr class=\"light\">\n";
3439 if (exists $diff->{'nparents'}) { # combined diff
3441 fill_from_file_info
($diff, @parents)
3442 unless exists $diff->{'from_file'};
3444 if (!is_deleted
($diff)) {
3445 # file exists in the result (child) commit
3447 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3448 file_name
=>$diff->{'to_file'},
3450 -class => "list"}, esc_path
($diff->{'to_file'})) .
3454 esc_path
($diff->{'to_file'}) .
3458 if ($action eq 'commitdiff') {
3461 print "<td class=\"link\">" .
3462 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3467 my $has_history = 0;
3468 my $not_deleted = 0;
3469 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3470 my $hash_parent = $parents[$i];
3471 my $from_hash = $diff->{'from_id'}[$i];
3472 my $from_path = $diff->{'from_file'}[$i];
3473 my $status = $diff->{'status'}[$i];
3475 $has_history ||= ($status ne 'A');
3476 $not_deleted ||= ($status ne 'D');
3478 if ($status eq 'A') {
3479 print "<td class=\"link\" align=\"right\"> | </td>\n";
3480 } elsif ($status eq 'D') {
3481 print "<td class=\"link\">" .
3482 $cgi->a({-href
=> href
(action
=>"blob",
3485 file_name
=>$from_path)},
3489 if ($diff->{'to_id'} eq $from_hash) {
3490 print "<td class=\"link nochange\">";
3492 print "<td class=\"link\">";
3494 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3495 hash
=>$diff->{'to_id'},
3496 hash_parent
=>$from_hash,
3498 hash_parent_base
=>$hash_parent,
3499 file_name
=>$diff->{'to_file'},
3500 file_parent
=>$from_path)},
3506 print "<td class=\"link\">";
3508 print $cgi->a({-href
=> href
(action
=>"blob",
3509 hash
=>$diff->{'to_id'},
3510 file_name
=>$diff->{'to_file'},
3513 print " | " if ($has_history);
3516 print $cgi->a({-href
=> href
(action
=>"history",
3517 file_name
=>$diff->{'to_file'},
3524 next; # instead of 'else' clause, to avoid extra indent
3526 # else ordinary diff
3528 my ($to_mode_oct, $to_mode_str, $to_file_type);
3529 my ($from_mode_oct, $from_mode_str, $from_file_type);
3530 if ($diff->{'to_mode'} ne ('0' x
6)) {
3531 $to_mode_oct = oct $diff->{'to_mode'};
3532 if (S_ISREG
($to_mode_oct)) { # only for regular file
3533 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3535 $to_file_type = file_type
($diff->{'to_mode'});
3537 if ($diff->{'from_mode'} ne ('0' x
6)) {
3538 $from_mode_oct = oct $diff->{'from_mode'};
3539 if (S_ISREG
($to_mode_oct)) { # only for regular file
3540 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3542 $from_file_type = file_type
($diff->{'from_mode'});
3545 if ($diff->{'status'} eq "A") { # created
3546 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3547 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3548 $mode_chng .= "]</span>";
3550 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3551 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3552 -class => "list"}, esc_path
($diff->{'file'}));
3554 print "<td>$mode_chng</td>\n";
3555 print "<td class=\"link\">";
3556 if ($action eq 'commitdiff') {
3559 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3562 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3563 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3567 } elsif ($diff->{'status'} eq "D") { # deleted
3568 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3570 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3571 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3572 -class => "list"}, esc_path
($diff->{'file'}));
3574 print "<td>$mode_chng</td>\n";
3575 print "<td class=\"link\">";
3576 if ($action eq 'commitdiff') {
3579 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3582 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3583 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3586 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3587 file_name
=>$diff->{'file'})},
3590 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3591 file_name
=>$diff->{'file'})},
3595 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3596 my $mode_chnge = "";
3597 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3598 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3599 if ($from_file_type ne $to_file_type) {
3600 $mode_chnge .= " from $from_file_type to $to_file_type";
3602 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3603 if ($from_mode_str && $to_mode_str) {
3604 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3605 } elsif ($to_mode_str) {
3606 $mode_chnge .= " mode: $to_mode_str";
3609 $mode_chnge .= "]</span>\n";
3612 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3613 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3614 -class => "list"}, esc_path
($diff->{'file'}));
3616 print "<td>$mode_chnge</td>\n";
3617 print "<td class=\"link\">";
3618 if ($action eq 'commitdiff') {
3621 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3623 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3624 # "commit" view and modified file (not onlu mode changed)
3625 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3626 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3627 hash_base
=>$hash, hash_parent_base
=>$parent,
3628 file_name
=>$diff->{'file'})},
3632 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3633 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3636 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3637 file_name
=>$diff->{'file'})},
3640 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3641 file_name
=>$diff->{'file'})},
3645 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3646 my %status_name = ('R' => 'moved', 'C' => 'copied');
3647 my $nstatus = $status_name{$diff->{'status'}};
3649 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3650 # mode also for directories, so we cannot use $to_mode_str
3651 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3654 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3655 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3656 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3657 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3658 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3659 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3660 -class => "list"}, esc_path
($diff->{'from_file'})) .
3661 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3662 "<td class=\"link\">";
3663 if ($action eq 'commitdiff') {
3666 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3668 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3669 # "commit" view and modified file (not only pure rename or copy)
3670 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3671 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3672 hash_base
=>$hash, hash_parent_base
=>$parent,
3673 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3677 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3678 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3681 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3682 file_name
=>$diff->{'to_file'})},
3685 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3686 file_name
=>$diff->{'to_file'})},
3690 } # we should not encounter Unmerged (U) or Unknown (X) status
3693 print "</tbody>" if $has_header;
3697 sub git_patchset_body
{
3698 my ($fd, $difftree, $hash, @hash_parents) = @_;
3699 my ($hash_parent) = $hash_parents[0];
3701 my $is_combined = (@hash_parents > 1);
3703 my $patch_number = 0;
3709 print "<div class=\"patchset\">\n";
3711 # skip to first patch
3712 while ($patch_line = <$fd>) {
3715 last if ($patch_line =~ m/^diff /);
3719 while ($patch_line) {
3721 # parse "git diff" header line
3722 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3723 # $1 is from_name, which we do not use
3724 $to_name = unquote
($2);
3725 $to_name =~ s!^b/!!;
3726 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3727 # $1 is 'cc' or 'combined', which we do not use
3728 $to_name = unquote
($2);
3733 # check if current patch belong to current raw line
3734 # and parse raw git-diff line if needed
3735 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3736 # this is continuation of a split patch
3737 print "<div class=\"patch cont\">\n";
3739 # advance raw git-diff output if needed
3740 $patch_idx++ if defined $diffinfo;
3742 # read and prepare patch information
3743 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3745 # compact combined diff output can have some patches skipped
3746 # find which patch (using pathname of result) we are at now;
3748 while ($to_name ne $diffinfo->{'to_file'}) {
3749 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3750 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3751 "</div>\n"; # class="patch"
3756 last if $patch_idx > $#$difftree;
3757 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3761 # modifies %from, %to hashes
3762 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3764 # this is first patch for raw difftree line with $patch_idx index
3765 # we index @$difftree array from 0, but number patches from 1
3766 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3770 #assert($patch_line =~ m/^diff /) if DEBUG;
3771 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3773 # print "git diff" header
3774 print format_git_diff_header_line
($patch_line, $diffinfo,
3777 # print extended diff header
3778 print "<div class=\"diff extended_header\">\n";
3780 while ($patch_line = <$fd>) {
3783 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3785 print format_extended_diff_header_line
($patch_line, $diffinfo,
3788 print "</div>\n"; # class="diff extended_header"
3790 # from-file/to-file diff header
3791 if (! $patch_line) {
3792 print "</div>\n"; # class="patch"
3795 next PATCH
if ($patch_line =~ m/^diff /);
3796 #assert($patch_line =~ m/^---/) if DEBUG;
3798 my $last_patch_line = $patch_line;
3799 $patch_line = <$fd>;
3801 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3803 print format_diff_from_to_header
($last_patch_line, $patch_line,
3804 $diffinfo, \
%from, \
%to,
3809 while ($patch_line = <$fd>) {
3812 next PATCH
if ($patch_line =~ m/^diff /);
3814 print format_diff_line
($patch_line, \
%from, \
%to);
3818 print "</div>\n"; # class="patch"
3821 # for compact combined (--cc) format, with chunk and patch simpliciaction
3822 # patchset might be empty, but there might be unprocessed raw lines
3823 for (++$patch_idx if $patch_number > 0;
3824 $patch_idx < @$difftree;
3826 # read and prepare patch information
3827 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3829 # generate anchor for "patch" links in difftree / whatchanged part
3830 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3831 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3832 "</div>\n"; # class="patch"
3837 if ($patch_number == 0) {
3838 if (@hash_parents > 1) {
3839 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3841 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3845 print "</div>\n"; # class="patchset"
3848 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3850 # fills project list info (age, description, owner, forks) for each
3851 # project in the list, removing invalid projects from returned list
3852 # NOTE: modifies $projlist, but does not remove entries from it
3853 sub fill_project_list_info
{
3854 my ($projlist, $check_forks) = @_;
3857 my $show_ctags = gitweb_check_feature
('ctags');
3859 foreach my $pr (@$projlist) {
3860 my (@activity) = git_get_last_activity
($pr->{'path'});
3861 unless (@activity) {
3864 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3865 if (!defined $pr->{'descr'}) {
3866 my $descr = git_get_project_description
($pr->{'path'}) || "";
3867 $descr = to_utf8
($descr);
3868 $pr->{'descr_long'} = $descr;
3869 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3871 if (!defined $pr->{'owner'}) {
3872 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3875 my $pname = $pr->{'path'};
3876 if (($pname =~ s/\.git$//) &&
3877 ($pname !~ /\/$/) &&
3878 (-d
"$projectroot/$pname")) {
3879 $pr->{'forks'} = "-d $projectroot/$pname";
3884 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
3885 push @projects, $pr;
3891 # print 'sort by' <th> element, generating 'sort by $name' replay link
3892 # if that order is not selected
3894 my ($name, $order, $header) = @_;
3895 $header ||= ucfirst($name);
3897 if ($order eq $name) {
3898 print "<th>$header</th>\n";
3901 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3902 -class => "header"}, $header) .
3907 sub git_project_list_body
{
3908 # actually uses global variable $project
3909 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3911 my ($check_forks) = gitweb_check_feature
('forks');
3912 my @projects = fill_project_list_info
($projlist, $check_forks);
3914 $order ||= $default_projects_order;
3915 $from = 0 unless defined $from;
3916 $to = $#projects if (!defined $to || $#projects < $to);
3919 project
=> { key
=> 'path', type
=> 'str' },
3920 descr
=> { key
=> 'descr_long', type
=> 'str' },
3921 owner
=> { key
=> 'owner', type
=> 'str' },
3922 age
=> { key
=> 'age', type
=> 'num' }
3924 my $oi = $order_info{$order};
3925 if ($oi->{'type'} eq 'str') {
3926 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3928 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3931 my $show_ctags = gitweb_check_feature
('ctags');
3934 foreach my $p (@projects) {
3935 foreach my $ct (keys %{$p->{'ctags'}}) {
3936 $ctags{$ct} += $p->{'ctags'}->{$ct};
3939 my $cloud = git_populate_project_tagcloud
(\
%ctags);
3940 print git_show_project_tagcloud
($cloud, 64);
3943 print "<table class=\"project_list\">\n";
3944 unless ($no_header) {
3947 print "<th></th>\n";
3949 print_sort_th
('project', $order, 'Project');
3950 print_sort_th
('descr', $order, 'Description');
3951 print_sort_th
('owner', $order, 'Owner');
3952 print_sort_th
('age', $order, 'Last Change');
3953 print "<th></th>\n" . # for links
3957 my $tagfilter = $cgi->param('by_tag');
3958 for (my $i = $from; $i <= $to; $i++) {
3959 my $pr = $projects[$i];
3961 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
3962 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
3963 and not $pr->{'descr_long'} =~ /$searchtext/;
3964 # Weed out forks or non-matching entries of search
3966 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
3967 $forkbase="^$forkbase" if $forkbase;
3968 next if not $searchtext and not $tagfilter and $show_ctags
3969 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
3973 print "<tr class=\"dark\">\n";
3975 print "<tr class=\"light\">\n";
3980 if ($pr->{'forks'}) {
3981 print "<!-- $pr->{'forks'} -->\n";
3982 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3986 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3987 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3988 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3989 -class => "list", -title
=> $pr->{'descr_long'}},
3990 esc_html
($pr->{'descr'})) . "</td>\n" .
3991 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3992 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3993 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3994 "<td class=\"link\">" .
3995 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3996 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3997 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3998 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3999 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4003 if (defined $extra) {
4006 print "<td></td>\n";
4008 print "<td colspan=\"5\">$extra</td>\n" .
4014 sub git_shortlog_body
{
4015 # uses global variable $project
4016 my ($commitlist, $from, $to, $refs, $extra) = @_;
4018 $from = 0 unless defined $from;
4019 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4021 print "<table class=\"shortlog\">\n";
4023 for (my $i = $from; $i <= $to; $i++) {
4024 my %co = %{$commitlist->[$i]};
4025 my $commit = $co{'id'};
4026 my $ref = format_ref_marker
($refs, $commit);
4028 print "<tr class=\"dark\">\n";
4030 print "<tr class=\"light\">\n";
4033 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4034 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4035 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4036 "<td><i>" . $author . "</i></td>\n" .
4038 print format_subject_html
($co{'title'}, $co{'title_short'},
4039 href
(action
=>"commit", hash
=>$commit), $ref);
4041 "<td class=\"link\">" .
4042 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4043 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4044 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4045 my $snapshot_links = format_snapshot_links
($commit);
4046 if (defined $snapshot_links) {
4047 print " | " . $snapshot_links;
4052 if (defined $extra) {
4054 "<td colspan=\"4\">$extra</td>\n" .
4060 sub git_history_body
{
4061 # Warning: assumes constant type (blob or tree) during history
4062 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4064 $from = 0 unless defined $from;
4065 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4067 print "<table class=\"history\">\n";
4069 for (my $i = $from; $i <= $to; $i++) {
4070 my %co = %{$commitlist->[$i]};
4074 my $commit = $co{'id'};
4076 my $ref = format_ref_marker
($refs, $commit);
4079 print "<tr class=\"dark\">\n";
4081 print "<tr class=\"light\">\n";
4084 # shortlog uses chop_str($co{'author_name'}, 10)
4085 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4086 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4087 "<td><i>" . $author . "</i></td>\n" .
4089 # originally git_history used chop_str($co{'title'}, 50)
4090 print format_subject_html
($co{'title'}, $co{'title_short'},
4091 href
(action
=>"commit", hash
=>$commit), $ref);
4093 "<td class=\"link\">" .
4094 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4095 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4097 if ($ftype eq 'blob') {
4098 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4099 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4100 if (defined $blob_current && defined $blob_parent &&
4101 $blob_current ne $blob_parent) {
4103 $cgi->a({-href
=> href
(action
=>"blobdiff",
4104 hash
=>$blob_current, hash_parent
=>$blob_parent,
4105 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4106 file_name
=>$file_name)},
4113 if (defined $extra) {
4115 "<td colspan=\"4\">$extra</td>\n" .
4122 # uses global variable $project
4123 my ($taglist, $from, $to, $extra) = @_;
4124 $from = 0 unless defined $from;
4125 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4127 print "<table class=\"tags\">\n";
4129 for (my $i = $from; $i <= $to; $i++) {
4130 my $entry = $taglist->[$i];
4132 my $comment = $tag{'subject'};
4134 if (defined $comment) {
4135 $comment_short = chop_str
($comment, 30, 5);
4138 print "<tr class=\"dark\">\n";
4140 print "<tr class=\"light\">\n";
4143 if (defined $tag{'age'}) {
4144 print "<td><i>$tag{'age'}</i></td>\n";
4146 print "<td></td>\n";
4149 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4150 -class => "list name"}, esc_html
($tag{'name'})) .
4153 if (defined $comment) {
4154 print format_subject_html
($comment, $comment_short,
4155 href
(action
=>"tag", hash
=>$tag{'id'}));
4158 "<td class=\"selflink\">";
4159 if ($tag{'type'} eq "tag") {
4160 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4165 "<td class=\"link\">" . " | " .
4166 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4167 if ($tag{'reftype'} eq "commit") {
4168 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4169 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4170 } elsif ($tag{'reftype'} eq "blob") {
4171 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4176 if (defined $extra) {
4178 "<td colspan=\"5\">$extra</td>\n" .
4184 sub git_heads_body
{
4185 # uses global variable $project
4186 my ($headlist, $head, $from, $to, $extra) = @_;
4187 $from = 0 unless defined $from;
4188 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4190 print "<table class=\"heads\">\n";
4192 for (my $i = $from; $i <= $to; $i++) {
4193 my $entry = $headlist->[$i];
4195 my $curr = $ref{'id'} eq $head;
4197 print "<tr class=\"dark\">\n";
4199 print "<tr class=\"light\">\n";
4202 print "<td><i>$ref{'age'}</i></td>\n" .
4203 ($curr ? "<td class=\"current_head\">" : "<td>") .
4204 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4205 -class => "list name"},esc_html
($ref{'name'})) .
4207 "<td class=\"link\">" .
4208 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4209 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4210 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4214 if (defined $extra) {
4216 "<td colspan=\"3\">$extra</td>\n" .
4222 sub git_search_grep_body
{
4223 my ($commitlist, $from, $to, $extra) = @_;
4224 $from = 0 unless defined $from;
4225 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4227 print "<table class=\"commit_search\">\n";
4229 for (my $i = $from; $i <= $to; $i++) {
4230 my %co = %{$commitlist->[$i]};
4234 my $commit = $co{'id'};
4236 print "<tr class=\"dark\">\n";
4238 print "<tr class=\"light\">\n";
4241 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4242 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4243 "<td><i>" . $author . "</i></td>\n" .
4245 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4246 -class => "list subject"},
4247 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4248 my $comment = $co{'comment'};
4249 foreach my $line (@$comment) {
4250 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4251 my ($lead, $match, $trail) = ($1, $2, $3);
4252 $match = chop_str
($match, 70, 5, 'center');
4253 my $contextlen = int((80 - length($match))/2);
4254 $contextlen = 30 if ($contextlen > 30);
4255 $lead = chop_str
($lead, $contextlen, 10, 'left');
4256 $trail = chop_str
($trail, $contextlen, 10, 'right');
4258 $lead = esc_html
($lead);
4259 $match = esc_html
($match);
4260 $trail = esc_html
($trail);
4262 print "$lead<span class=\"match\">$match</span>$trail<br />";
4266 "<td class=\"link\">" .
4267 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4269 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4271 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4275 if (defined $extra) {
4277 "<td colspan=\"3\">$extra</td>\n" .
4283 ## ======================================================================
4284 ## ======================================================================
4287 sub git_project_list
{
4288 my $order = $input_params{'order'};
4289 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4290 die_error
(400, "Unknown order parameter");
4293 my @list = git_get_projects_list
();
4295 die_error
(404, "No projects found");
4299 if (-f
$home_text) {
4300 print "<div class=\"index_include\">\n";
4301 open (my $fd, $home_text);
4306 print $cgi->startform(-method => "get") .
4307 "<p class=\"projsearch\">Search:\n" .
4308 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4310 $cgi->end_form() . "\n";
4311 git_project_list_body
(\
@list, $order);
4316 my $order = $input_params{'order'};
4317 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4318 die_error
(400, "Unknown order parameter");
4321 my @list = git_get_projects_list
($project);
4323 die_error
(404, "No forks found");
4327 git_print_page_nav
('','');
4328 git_print_header_div
('summary', "$project forks");
4329 git_project_list_body
(\
@list, $order);
4333 sub git_project_index
{
4334 my @projects = git_get_projects_list
($project);
4337 -type
=> 'text/plain',
4338 -charset
=> 'utf-8',
4339 -content_disposition
=> 'inline; filename="index.aux"');
4341 foreach my $pr (@projects) {
4342 if (!exists $pr->{'owner'}) {
4343 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4346 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4347 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4348 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4349 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4353 print "$path $owner\n";
4358 my $descr = git_get_project_description
($project) || "none";
4359 my %co = parse_commit
("HEAD");
4360 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4361 my $head = $co{'id'};
4363 my $owner = git_get_project_owner
($project);
4365 my $refs = git_get_references
();
4366 # These get_*_list functions return one more to allow us to see if
4367 # there are more ...
4368 my @taglist = git_get_tags_list
(16);
4369 my @headlist = git_get_heads_list
(16);
4371 my ($check_forks) = gitweb_check_feature
('forks');
4374 @forklist = git_get_projects_list
($project);
4378 git_print_page_nav
('summary','', $head);
4380 print "<div class=\"title\"> </div>\n";
4381 print "<table class=\"projects_list\">\n" .
4382 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4383 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4384 if (defined $cd{'rfc2822'}) {
4385 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4388 # use per project git URL list in $projectroot/$project/cloneurl
4389 # or make project git URL from git base URL and project name
4390 my $url_tag = "URL";
4391 my @url_list = git_get_project_url_list
($project);
4392 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4393 foreach my $git_url (@url_list) {
4394 next unless $git_url;
4395 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4400 my $show_ctags = (gitweb_check_feature
('ctags'))[0];
4402 my $ctags = git_get_project_ctags
($project);
4403 my $cloud = git_populate_project_tagcloud
($ctags);
4404 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4405 print "</td>\n<td>" unless %$ctags;
4406 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4407 print "</td>\n<td>" if %$ctags;
4408 print git_show_project_tagcloud
($cloud, 48);
4414 if (-s
"$projectroot/$project/README.html") {
4415 if (open my $fd, "$projectroot/$project/README.html") {
4416 print "<div class=\"title\">readme</div>\n" .
4417 "<div class=\"readme\">\n";
4418 print $_ while (<$fd>);
4419 print "\n</div>\n"; # class="readme"
4424 # we need to request one more than 16 (0..15) to check if
4426 my @commitlist = $head ? parse_commits
($head, 17) : ();
4428 git_print_header_div
('shortlog');
4429 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4430 $#commitlist <= 15 ? undef :
4431 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4435 git_print_header_div
('tags');
4436 git_tags_body
(\
@taglist, 0, 15,
4437 $#taglist <= 15 ? undef :
4438 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4442 git_print_header_div
('heads');
4443 git_heads_body
(\
@headlist, $head, 0, 15,
4444 $#headlist <= 15 ? undef :
4445 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4449 git_print_header_div
('forks');
4450 git_project_list_body
(\
@forklist, 'age', 0, 15,
4451 $#forklist <= 15 ? undef :
4452 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4460 my $head = git_get_head_hash
($project);
4462 git_print_page_nav
('','', $head,undef,$head);
4463 my %tag = parse_tag
($hash);
4466 die_error
(404, "Unknown tag object");
4469 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4470 print "<div class=\"title_text\">\n" .
4471 "<table class=\"object_header\">\n" .
4473 "<td>object</td>\n" .
4474 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4475 $tag{'object'}) . "</td>\n" .
4476 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4477 $tag{'type'}) . "</td>\n" .
4479 if (defined($tag{'author'})) {
4480 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4481 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4482 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4483 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4486 print "</table>\n\n" .
4488 print "<div class=\"page_body\">";
4489 my $comment = $tag{'comment'};
4490 foreach my $line (@$comment) {
4492 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4502 gitweb_check_feature
('blame')
4503 or die_error
(403, "Blame view not allowed");
4505 die_error
(400, "No file name given") unless $file_name;
4506 $hash_base ||= git_get_head_hash
($project);
4507 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4508 my %co = parse_commit
($hash_base)
4509 or die_error
(404, "Commit not found");
4510 if (!defined $hash) {
4511 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4512 or die_error
(404, "Error looking up file");
4514 $ftype = git_get_type
($hash);
4515 if ($ftype !~ "blob") {
4516 die_error
(400, "Object is not a blob");
4518 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4519 $file_name, $hash_base)
4520 or die_error
(500, "Open git-blame failed");
4523 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4526 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4529 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4531 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4532 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4533 git_print_page_path
($file_name, $ftype, $hash_base);
4534 my @rev_color = (qw(light2 dark2));
4535 my $num_colors = scalar(@rev_color);
4536 my $current_color = 0;
4539 <div class="page_body">
4540 <table class="blame">
4541 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4546 last unless defined $_;
4547 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4548 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4549 if (!exists $metainfo{$full_rev}) {
4550 $metainfo{$full_rev} = {};
4552 my $meta = $metainfo{$full_rev};
4555 if (/^(\S+) (.*)$/) {
4561 my $rev = substr($full_rev, 0, 8);
4562 my $author = $meta->{'author'};
4563 my %date = parse_date
($meta->{'author-time'},
4564 $meta->{'author-tz'});
4565 my $date = $date{'iso-tz'};
4567 $current_color = ++$current_color % $num_colors;
4569 print "<tr class=\"$rev_color[$current_color]\">\n";
4571 print "<td class=\"sha1\"";
4572 print " title=\"". esc_html
($author) . ", $date\"";
4573 print " rowspan=\"$group_size\"" if ($group_size > 1);
4575 print $cgi->a({-href
=> href
(action
=>"commit",
4577 file_name
=>$file_name)},
4581 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4582 or die_error
(500, "Open git-rev-parse failed");
4583 my $parent_commit = <$dd>;
4585 chomp($parent_commit);
4586 my $blamed = href
(action
=> 'blame',
4587 file_name
=> $meta->{'filename'},
4588 hash_base
=> $parent_commit);
4589 print "<td class=\"linenr\">";
4590 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4592 -class => "linenr" },
4595 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4601 or print "Reading blob failed\n";
4606 my $head = git_get_head_hash
($project);
4608 git_print_page_nav
('','', $head,undef,$head);
4609 git_print_header_div
('summary', $project);
4611 my @tagslist = git_get_tags_list
();
4613 git_tags_body
(\
@tagslist);
4619 my $head = git_get_head_hash
($project);
4621 git_print_page_nav
('','', $head,undef,$head);
4622 git_print_header_div
('summary', $project);
4624 my @headslist = git_get_heads_list
();
4626 git_heads_body
(\
@headslist, $head);
4631 sub git_blob_plain
{
4635 if (!defined $hash) {
4636 if (defined $file_name) {
4637 my $base = $hash_base || git_get_head_hash
($project);
4638 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4639 or die_error
(404, "Cannot find file");
4641 die_error
(400, "No file name defined");
4643 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4644 # blobs defined by non-textual hash id's can be cached
4648 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4649 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4651 # content-type (can include charset)
4652 $type = blob_contenttype
($fd, $file_name, $type);
4654 # "save as" filename, even when no $file_name is given
4655 my $save_as = "$hash";
4656 if (defined $file_name) {
4657 $save_as = $file_name;
4658 } elsif ($type =~ m/^text\//) {
4664 -expires
=> $expires,
4665 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4667 binmode STDOUT
, ':raw';
4669 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4677 if (!defined $hash) {
4678 if (defined $file_name) {
4679 my $base = $hash_base || git_get_head_hash
($project);
4680 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4681 or die_error
(404, "Cannot find file");
4683 die_error
(400, "No file name defined");
4685 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4686 # blobs defined by non-textual hash id's can be cached
4690 my ($have_blame) = gitweb_check_feature
('blame');
4691 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4692 or die_error
(500, "Couldn't cat $file_name, $hash");
4693 my $mimetype = blob_mimetype
($fd, $file_name);
4694 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4696 return git_blob_plain
($mimetype);
4698 # we can have blame only for text/* mimetype
4699 $have_blame &&= ($mimetype =~ m!^text/!);
4701 git_header_html
(undef, $expires);
4702 my $formats_nav = '';
4703 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4704 if (defined $file_name) {
4707 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4712 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4715 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4718 $cgi->a({-href
=> href
(action
=>"blob",
4719 hash_base
=>"HEAD", file_name
=>$file_name)},
4723 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4726 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4727 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4729 print "<div class=\"page_nav\">\n" .
4730 "<br/><br/></div>\n" .
4731 "<div class=\"title\">$hash</div>\n";
4733 git_print_page_path
($file_name, "blob", $hash_base);
4734 print "<div class=\"page_body\">\n";
4735 if ($mimetype =~ m!^image/!) {
4736 print qq
!<img type
="$mimetype"!;
4738 print qq
! alt
="$file_name" title
="$file_name"!;
4741 href(action=>"blob_plain
", hash=>$hash,
4742 hash_base=>$hash_base, file_name=>$file_name) .
4746 while (my $line = <$fd>) {
4749 $line = untabify
($line);
4750 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4751 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4755 or print "Reading blob failed.\n";
4761 if (!defined $hash_base) {
4762 $hash_base = "HEAD";
4764 if (!defined $hash) {
4765 if (defined $file_name) {
4766 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4771 die_error
(404, "No such tree") unless defined($hash);
4773 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4774 or die_error
(500, "Open git-ls-tree failed");
4775 my @entries = map { chomp; $_ } <$fd>;
4776 close $fd or die_error
(404, "Reading tree failed");
4779 my $refs = git_get_references
();
4780 my $ref = format_ref_marker
($refs, $hash_base);
4783 my ($have_blame) = gitweb_check_feature
('blame');
4784 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4786 if (defined $file_name) {
4788 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4790 $cgi->a({-href
=> href
(action
=>"tree",
4791 hash_base
=>"HEAD", file_name
=>$file_name)},
4794 my $snapshot_links = format_snapshot_links
($hash);
4795 if (defined $snapshot_links) {
4796 # FIXME: Should be available when we have no hash base as well.
4797 push @views_nav, $snapshot_links;
4799 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4800 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4803 print "<div class=\"page_nav\">\n";
4804 print "<br/><br/></div>\n";
4805 print "<div class=\"title\">$hash</div>\n";
4807 if (defined $file_name) {
4808 $basedir = $file_name;
4809 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4812 git_print_page_path
($file_name, 'tree', $hash_base);
4814 print "<div class=\"page_body\">\n";
4815 print "<table class=\"tree\">\n";
4817 # '..' (top directory) link if possible
4818 if (defined $hash_base &&
4819 defined $file_name && $file_name =~ m![^/]+$!) {
4821 print "<tr class=\"dark\">\n";
4823 print "<tr class=\"light\">\n";
4827 my $up = $file_name;
4828 $up =~ s!/?[^/]+$!!;
4829 undef $up unless $up;
4830 # based on git_print_tree_entry
4831 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4832 print '<td class="list">';
4833 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4837 print "<td class=\"link\"></td>\n";
4841 foreach my $line (@entries) {
4842 my %t = parse_ls_tree_line
($line, -z
=> 1);
4845 print "<tr class=\"dark\">\n";
4847 print "<tr class=\"light\">\n";
4851 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4855 print "</table>\n" .
4861 my $format = $input_params{'snapshot_format'};
4862 if (!@snapshot_fmts) {
4863 die_error
(403, "Snapshots not allowed");
4865 # default to first supported snapshot format
4866 $format ||= $snapshot_fmts[0];
4867 if ($format !~ m/^[a-z0-9]+$/) {
4868 die_error
(400, "Invalid snapshot format parameter");
4869 } elsif (!exists($known_snapshot_formats{$format})) {
4870 die_error
(400, "Unknown snapshot format");
4871 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4872 die_error
(403, "Unsupported snapshot format");
4875 if (!defined $hash) {
4876 $hash = git_get_head_hash
($project);
4879 my $name = $project;
4880 $name =~ s
,([^/])/*\
.git
$,$1,;
4881 $name = basename
($name);
4882 my $filename = to_utf8
($name);
4883 $name =~ s/\047/\047\\\047\047/g;
4885 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4886 $cmd = quote_command
(
4887 git_cmd
(), 'archive',
4888 "--format=$known_snapshot_formats{$format}{'format'}",
4889 "--prefix=$name/", $hash);
4890 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4891 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
4895 -type
=> $known_snapshot_formats{$format}{'type'},
4896 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4897 -status
=> '200 OK');
4899 open my $fd, "-|", $cmd
4900 or die_error
(500, "Execute git-archive failed");
4901 binmode STDOUT
, ':raw';
4903 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4908 my $head = git_get_head_hash
($project);
4909 if (!defined $hash) {
4912 if (!defined $page) {
4915 my $refs = git_get_references
();
4917 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4919 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4922 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4925 my %co = parse_commit
($hash);
4927 git_print_header_div
('summary', $project);
4928 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4930 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4931 for (my $i = 0; $i <= $to; $i++) {
4932 my %co = %{$commitlist[$i]};
4934 my $commit = $co{'id'};
4935 my $ref = format_ref_marker
($refs, $commit);
4936 my %ad = parse_date
($co{'author_epoch'});
4937 git_print_header_div
('commit',
4938 "<span class=\"age\">$co{'age_string'}</span>" .
4939 esc_html
($co{'title'}) . $ref,
4941 print "<div class=\"title_text\">\n" .
4942 "<div class=\"log_link\">\n" .
4943 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4945 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4947 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4950 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4953 print "<div class=\"log_body\">\n";
4954 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4957 if ($#commitlist >= 100) {
4958 print "<div class=\"page_nav\">\n";
4959 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4960 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4967 $hash ||= $hash_base || "HEAD";
4968 my %co = parse_commit
($hash)
4969 or die_error
(404, "Unknown commit object");
4970 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4971 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4973 my $parent = $co{'parent'};
4974 my $parents = $co{'parents'}; # listref
4976 # we need to prepare $formats_nav before any parameter munging
4978 if (!defined $parent) {
4980 $formats_nav .= '(initial)';
4981 } elsif (@$parents == 1) {
4982 # single parent commit
4985 $cgi->a({-href
=> href
(action
=>"commit",
4987 esc_html
(substr($parent, 0, 7))) .
4994 $cgi->a({-href
=> href
(action
=>"commit",
4996 esc_html
(substr($_, 0, 7)));
5001 if (!defined $parent) {
5005 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5007 (@$parents <= 1 ? $parent : '-c'),
5009 or die_error
(500, "Open git-diff-tree failed");
5010 @difftree = map { chomp; $_ } <$fd>;
5011 close $fd or die_error
(404, "Reading git-diff-tree failed");
5013 # non-textual hash id's can be cached
5015 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5018 my $refs = git_get_references
();
5019 my $ref = format_ref_marker
($refs, $co{'id'});
5021 git_header_html
(undef, $expires);
5022 git_print_page_nav
('commit', '',
5023 $hash, $co{'tree'}, $hash,
5026 if (defined $co{'parent'}) {
5027 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5029 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5031 print "<div class=\"title_text\">\n" .
5032 "<table class=\"object_header\">\n";
5033 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5035 "<td></td><td> $ad{'rfc2822'}";
5036 if ($ad{'hour_local'} < 6) {
5037 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5038 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5040 printf(" (%02d:%02d %s)",
5041 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5045 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5046 print "<tr><td></td><td> $cd{'rfc2822'}" .
5047 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5049 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5052 "<td class=\"sha1\">" .
5053 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5054 class => "list"}, $co{'tree'}) .
5056 "<td class=\"link\">" .
5057 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5059 my $snapshot_links = format_snapshot_links
($hash);
5060 if (defined $snapshot_links) {
5061 print " | " . $snapshot_links;
5066 foreach my $par (@$parents) {
5069 "<td class=\"sha1\">" .
5070 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5071 class => "list"}, $par) .
5073 "<td class=\"link\">" .
5074 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5076 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5083 print "<div class=\"page_body\">\n";
5084 git_print_log
($co{'comment'});
5087 git_difftree_body
(\
@difftree, $hash, @$parents);
5093 # object is defined by:
5094 # - hash or hash_base alone
5095 # - hash_base and file_name
5098 # - hash or hash_base alone
5099 if ($hash || ($hash_base && !defined $file_name)) {
5100 my $object_id = $hash || $hash_base;
5102 open my $fd, "-|", quote_command
(
5103 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5104 or die_error
(404, "Object does not exist");
5108 or die_error
(404, "Object does not exist");
5110 # - hash_base and file_name
5111 } elsif ($hash_base && defined $file_name) {
5112 $file_name =~ s
,/+$,,;
5114 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5115 or die_error
(404, "Base object does not exist");
5117 # here errors should not hapen
5118 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5119 or die_error
(500, "Open git-ls-tree failed");
5123 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5124 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5125 die_error
(404, "File or directory for given base does not exist");
5130 die_error
(400, "Not enough information to find object");
5133 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5134 hash
=>$hash, hash_base
=>$hash_base,
5135 file_name
=>$file_name),
5136 -status
=> '302 Found');
5140 my $format = shift || 'html';
5147 # preparing $fd and %diffinfo for git_patchset_body
5149 if (defined $hash_base && defined $hash_parent_base) {
5150 if (defined $file_name) {
5152 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5153 $hash_parent_base, $hash_base,
5154 "--", (defined $file_parent ? $file_parent : ()), $file_name
5155 or die_error
(500, "Open git-diff-tree failed");
5156 @difftree = map { chomp; $_ } <$fd>;
5158 or die_error
(404, "Reading git-diff-tree failed");
5160 or die_error
(404, "Blob diff not found");
5162 } elsif (defined $hash &&
5163 $hash =~ /[0-9a-fA-F]{40}/) {
5164 # try to find filename from $hash
5166 # read filtered raw output
5167 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5168 $hash_parent_base, $hash_base, "--"
5169 or die_error
(500, "Open git-diff-tree failed");
5171 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5173 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5174 map { chomp; $_ } <$fd>;
5176 or die_error
(404, "Reading git-diff-tree failed");
5178 or die_error
(404, "Blob diff not found");
5181 die_error
(400, "Missing one of the blob diff parameters");
5184 if (@difftree > 1) {
5185 die_error
(400, "Ambiguous blob diff specification");
5188 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5189 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5190 $file_name ||= $diffinfo{'to_file'};
5192 $hash_parent ||= $diffinfo{'from_id'};
5193 $hash ||= $diffinfo{'to_id'};
5195 # non-textual hash id's can be cached
5196 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5197 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5202 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5203 '-p', ($format eq 'html' ? "--full-index" : ()),
5204 $hash_parent_base, $hash_base,
5205 "--", (defined $file_parent ? $file_parent : ()), $file_name
5206 or die_error
(500, "Open git-diff-tree failed");
5209 # old/legacy style URI
5210 if (!%diffinfo && # if new style URI failed
5211 defined $hash && defined $hash_parent) {
5212 # fake git-diff-tree raw output
5213 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
5214 $diffinfo{'from_id'} = $hash_parent;
5215 $diffinfo{'to_id'} = $hash;
5216 if (defined $file_name) {
5217 if (defined $file_parent) {
5218 $diffinfo{'status'} = '2';
5219 $diffinfo{'from_file'} = $file_parent;
5220 $diffinfo{'to_file'} = $file_name;
5221 } else { # assume not renamed
5222 $diffinfo{'status'} = '1';
5223 $diffinfo{'from_file'} = $file_name;
5224 $diffinfo{'to_file'} = $file_name;
5226 } else { # no filename given
5227 $diffinfo{'status'} = '2';
5228 $diffinfo{'from_file'} = $hash_parent;
5229 $diffinfo{'to_file'} = $hash;
5232 # non-textual hash id's can be cached
5233 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
5234 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5239 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
5240 '-p', ($format eq 'html' ? "--full-index" : ()),
5241 $hash_parent, $hash, "--"
5242 or die_error
(500, "Open git-diff failed");
5244 die_error
(400, "Missing one of the blob diff parameters")
5249 if ($format eq 'html') {
5251 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5253 git_header_html
(undef, $expires);
5254 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5255 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5256 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5258 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5259 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5261 if (defined $file_name) {
5262 git_print_page_path
($file_name, "blob", $hash_base);
5264 print "<div class=\"page_path\"></div>\n";
5267 } elsif ($format eq 'plain') {
5269 -type
=> 'text/plain',
5270 -charset
=> 'utf-8',
5271 -expires
=> $expires,
5272 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5274 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5277 die_error
(400, "Unknown blobdiff format");
5281 if ($format eq 'html') {
5282 print "<div class=\"page_body\">\n";
5284 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5287 print "</div>\n"; # class="page_body"
5291 while (my $line = <$fd>) {
5292 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5293 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5297 last if $line =~ m!^\+\+\+!;
5305 sub git_blobdiff_plain
{
5306 git_blobdiff
('plain');
5309 sub git_commitdiff
{
5310 my $format = shift || 'html';
5311 $hash ||= $hash_base || "HEAD";
5312 my %co = parse_commit
($hash)
5313 or die_error
(404, "Unknown commit object");
5315 # choose format for commitdiff for merge
5316 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5317 $hash_parent = '--cc';
5319 # we need to prepare $formats_nav before almost any parameter munging
5321 if ($format eq 'html') {
5323 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5326 if (defined $hash_parent &&
5327 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5328 # commitdiff with two commits given
5329 my $hash_parent_short = $hash_parent;
5330 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5331 $hash_parent_short = substr($hash_parent, 0, 7);
5335 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5336 if ($co{'parents'}[$i] eq $hash_parent) {
5337 $formats_nav .= ' parent ' . ($i+1);
5341 $formats_nav .= ': ' .
5342 $cgi->a({-href
=> href
(action
=>"commitdiff",
5343 hash
=>$hash_parent)},
5344 esc_html
($hash_parent_short)) .
5346 } elsif (!$co{'parent'}) {
5348 $formats_nav .= ' (initial)';
5349 } elsif (scalar @{$co{'parents'}} == 1) {
5350 # single parent commit
5353 $cgi->a({-href
=> href
(action
=>"commitdiff",
5354 hash
=>$co{'parent'})},
5355 esc_html
(substr($co{'parent'}, 0, 7))) .
5359 if ($hash_parent eq '--cc') {
5360 $formats_nav .= ' | ' .
5361 $cgi->a({-href
=> href
(action
=>"commitdiff",
5362 hash
=>$hash, hash_parent
=>'-c')},
5364 } else { # $hash_parent eq '-c'
5365 $formats_nav .= ' | ' .
5366 $cgi->a({-href
=> href
(action
=>"commitdiff",
5367 hash
=>$hash, hash_parent
=>'--cc')},
5373 $cgi->a({-href
=> href
(action
=>"commitdiff",
5375 esc_html
(substr($_, 0, 7)));
5376 } @{$co{'parents'}} ) .
5381 my $hash_parent_param = $hash_parent;
5382 if (!defined $hash_parent_param) {
5383 # --cc for multiple parents, --root for parentless
5384 $hash_parent_param =
5385 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5391 if ($format eq 'html') {
5392 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5393 "--no-commit-id", "--patch-with-raw", "--full-index",
5394 $hash_parent_param, $hash, "--"
5395 or die_error
(500, "Open git-diff-tree failed");
5397 while (my $line = <$fd>) {
5399 # empty line ends raw part of diff-tree output
5401 push @difftree, scalar parse_difftree_raw_line
($line);
5404 } elsif ($format eq 'plain') {
5405 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5406 '-p', $hash_parent_param, $hash, "--"
5407 or die_error
(500, "Open git-diff-tree failed");
5410 die_error
(400, "Unknown commitdiff format");
5413 # non-textual hash id's can be cached
5415 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5419 # write commit message
5420 if ($format eq 'html') {
5421 my $refs = git_get_references
();
5422 my $ref = format_ref_marker
($refs, $co{'id'});
5424 git_header_html
(undef, $expires);
5425 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5426 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5427 git_print_authorship
(\
%co);
5428 print "<div class=\"page_body\">\n";
5429 if (@{$co{'comment'}} > 1) {
5430 print "<div class=\"log\">\n";
5431 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5432 print "</div>\n"; # class="log"
5435 } elsif ($format eq 'plain') {
5436 my $refs = git_get_references
("tags");
5437 my $tagname = git_get_rev_name_tags
($hash);
5438 my $filename = basename
($project) . "-$hash.patch";
5441 -type
=> 'text/plain',
5442 -charset
=> 'utf-8',
5443 -expires
=> $expires,
5444 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5445 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5446 print "From: " . to_utf8
($co{'author'}) . "\n";
5447 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5448 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5450 print "X-Git-Tag: $tagname\n" if $tagname;
5451 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5453 foreach my $line (@{$co{'comment'}}) {
5454 print to_utf8
($line) . "\n";
5460 if ($format eq 'html') {
5461 my $use_parents = !defined $hash_parent ||
5462 $hash_parent eq '-c' || $hash_parent eq '--cc';
5463 git_difftree_body
(\
@difftree, $hash,
5464 $use_parents ? @{$co{'parents'}} : $hash_parent);
5467 git_patchset_body
($fd, \
@difftree, $hash,
5468 $use_parents ? @{$co{'parents'}} : $hash_parent);
5470 print "</div>\n"; # class="page_body"
5473 } elsif ($format eq 'plain') {
5477 or print "Reading git-diff-tree failed\n";
5481 sub git_commitdiff_plain
{
5482 git_commitdiff
('plain');
5486 if (!defined $hash_base) {
5487 $hash_base = git_get_head_hash
($project);
5489 if (!defined $page) {
5493 my %co = parse_commit
($hash_base)
5494 or die_error
(404, "Unknown commit object");
5496 my $refs = git_get_references
();
5497 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5499 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5500 $file_name, "--full-history")
5501 or die_error
(404, "No such file or directory on given branch");
5503 if (!defined $hash && defined $file_name) {
5504 # some commits could have deleted file in question,
5505 # and not have it in tree, but one of them has to have it
5506 for (my $i = 0; $i <= @commitlist; $i++) {
5507 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5508 last if defined $hash;
5511 if (defined $hash) {
5512 $ftype = git_get_type
($hash);
5514 if (!defined $ftype) {
5515 die_error
(500, "Unknown type of object");
5518 my $paging_nav = '';
5521 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5522 file_name
=>$file_name)},
5524 $paging_nav .= " ⋅ " .
5525 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5526 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5528 $paging_nav .= "first";
5529 $paging_nav .= " ⋅ prev";
5532 if ($#commitlist >= 100) {
5534 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5535 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5536 $paging_nav .= " ⋅ $next_link";
5538 $paging_nav .= " ⋅ next";
5542 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5543 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5544 git_print_page_path
($file_name, $ftype, $hash_base);
5546 git_history_body
(\
@commitlist, 0, 99,
5547 $refs, $hash_base, $ftype, $next_link);
5553 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5554 if (!defined $searchtext) {
5555 die_error
(400, "Text field is empty");
5557 if (!defined $hash) {
5558 $hash = git_get_head_hash
($project);
5560 my %co = parse_commit
($hash);
5562 die_error
(404, "Unknown commit object");
5564 if (!defined $page) {
5568 $searchtype ||= 'commit';
5569 if ($searchtype eq 'pickaxe') {
5570 # pickaxe may take all resources of your box and run for several minutes
5571 # with every query - so decide by yourself how public you make this feature
5572 gitweb_check_feature
('pickaxe')
5573 or die_error
(403, "Pickaxe is disabled");
5575 if ($searchtype eq 'grep') {
5576 gitweb_check_feature
('grep')
5577 or die_error
(403, "Grep is disabled");
5582 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5584 if ($searchtype eq 'commit') {
5585 $greptype = "--grep=";
5586 } elsif ($searchtype eq 'author') {
5587 $greptype = "--author=";
5588 } elsif ($searchtype eq 'committer') {
5589 $greptype = "--committer=";
5591 $greptype .= $searchtext;
5592 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5593 $greptype, '--regexp-ignore-case',
5594 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5596 my $paging_nav = '';
5599 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5600 searchtext
=>$searchtext,
5601 searchtype
=>$searchtype)},
5603 $paging_nav .= " ⋅ " .
5604 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5605 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5607 $paging_nav .= "first";
5608 $paging_nav .= " ⋅ prev";
5611 if ($#commitlist >= 100) {
5613 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5614 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5615 $paging_nav .= " ⋅ $next_link";
5617 $paging_nav .= " ⋅ next";
5620 if ($#commitlist >= 100) {
5623 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5624 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5625 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5628 if ($searchtype eq 'pickaxe') {
5629 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5630 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5632 print "<table class=\"pickaxe search\">\n";
5635 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5636 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5637 ($search_use_regexp ? '--pickaxe-regex' : ());
5640 while (my $line = <$fd>) {
5644 my %set = parse_difftree_raw_line
($line);
5645 if (defined $set{'commit'}) {
5646 # finish previous commit
5649 "<td class=\"link\">" .
5650 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5652 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5658 print "<tr class=\"dark\">\n";
5660 print "<tr class=\"light\">\n";
5663 %co = parse_commit
($set{'commit'});
5664 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5665 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5666 "<td><i>$author</i></td>\n" .
5668 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5669 -class => "list subject"},
5670 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5671 } elsif (defined $set{'to_id'}) {
5672 next if ($set{'to_id'} =~ m/^0{40}$/);
5674 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5675 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5677 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5683 # finish last commit (warning: repetition!)
5686 "<td class=\"link\">" .
5687 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5689 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5697 if ($searchtype eq 'grep') {
5698 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5699 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5701 print "<table class=\"grep_search\">\n";
5705 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5706 $search_use_regexp ? ('-E', '-i') : '-F',
5707 $searchtext, $co{'tree'};
5709 while (my $line = <$fd>) {
5711 my ($file, $lno, $ltext, $binary);
5712 last if ($matches++ > 1000);
5713 if ($line =~ /^Binary file (.+) matches$/) {
5717 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5719 if ($file ne $lastfile) {
5720 $lastfile and print "</td></tr>\n";
5722 print "<tr class=\"dark\">\n";
5724 print "<tr class=\"light\">\n";
5726 print "<td class=\"list\">".
5727 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5728 file_name
=>"$file"),
5729 -class => "list"}, esc_path
($file));
5730 print "</td><td>\n";
5734 print "<div class=\"binary\">Binary file</div>\n";
5736 $ltext = untabify
($ltext);
5737 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5738 $ltext = esc_html
($1, -nbsp
=>1);
5739 $ltext .= '<span class="match">';
5740 $ltext .= esc_html
($2, -nbsp
=>1);
5741 $ltext .= '</span>';
5742 $ltext .= esc_html
($3, -nbsp
=>1);
5744 $ltext = esc_html
($ltext, -nbsp
=>1);
5746 print "<div class=\"pre\">" .
5747 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5748 file_name
=>"$file").'#l'.$lno,
5749 -class => "linenr"}, sprintf('%4i', $lno))
5750 . ' ' . $ltext . "</div>\n";
5754 print "</td></tr>\n";
5755 if ($matches > 1000) {
5756 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5759 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5768 sub git_search_help
{
5770 git_print_page_nav
('','', $hash,$hash,$hash);
5772 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5773 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5774 the pattern entered is recognized as the POSIX extended
5775 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5778 <dt><b>commit</b></dt>
5779 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5781 my ($have_grep) = gitweb_check_feature
('grep');
5784 <dt><b>grep</b></dt>
5785 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5786 a different one) are searched for the given pattern. On large trees, this search can take
5787 a while and put some strain on the server, so please use it with some consideration. Note that
5788 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5789 case-sensitive.</dd>
5793 <dt><b>author</b></dt>
5794 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5795 <dt><b>committer</b></dt>
5796 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5798 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5799 if ($have_pickaxe) {
5801 <dt><b>pickaxe</b></dt>
5802 <dd>All commits that caused the string to appear or disappear from any file (changes that
5803 added, removed or "modified" the string) will be listed. This search can take a while and
5804 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5805 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5813 my $head = git_get_head_hash
($project);
5814 if (!defined $hash) {
5817 if (!defined $page) {
5820 my $refs = git_get_references
();
5822 my $commit_hash = $hash;
5823 if (defined $hash_parent) {
5824 $commit_hash = "$hash_parent..$hash";
5826 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5828 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5830 if ($#commitlist >= 100) {
5832 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5833 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5837 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5838 git_print_header_div
('summary', $project);
5840 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5845 ## ......................................................................
5846 ## feeds (RSS, Atom; OPML)
5849 my $format = shift || 'atom';
5850 my ($have_blame) = gitweb_check_feature
('blame');
5852 # Atom: http://www.atomenabled.org/developers/syndication/
5853 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5854 if ($format ne 'rss' && $format ne 'atom') {
5855 die_error
(400, "Unknown web feed format");
5858 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5859 my $head = $hash || 'HEAD';
5860 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5864 my $content_type = "application/$format+xml";
5865 if (defined $cgi->http('HTTP_ACCEPT') &&
5866 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5867 # browser (feed reader) prefers text/xml
5868 $content_type = 'text/xml';
5870 if (defined($commitlist[0])) {
5871 %latest_commit = %{$commitlist[0]};
5872 %latest_date = parse_date
($latest_commit{'author_epoch'});
5874 -type
=> $content_type,
5875 -charset
=> 'utf-8',
5876 -last_modified
=> $latest_date{'rfc2822'});
5879 -type
=> $content_type,
5880 -charset
=> 'utf-8');
5883 # Optimization: skip generating the body if client asks only
5884 # for Last-Modified date.
5885 return if ($cgi->request_method() eq 'HEAD');
5888 my $title = "$site_name - $project/$action";
5889 my $feed_type = 'log';
5890 if (defined $hash) {
5891 $title .= " - '$hash'";
5892 $feed_type = 'branch log';
5893 if (defined $file_name) {
5894 $title .= " :: $file_name";
5895 $feed_type = 'history';
5897 } elsif (defined $file_name) {
5898 $title .= " - $file_name";
5899 $feed_type = 'history';
5901 $title .= " $feed_type";
5902 my $descr = git_get_project_description
($project);
5903 if (defined $descr) {
5904 $descr = esc_html
($descr);
5906 $descr = "$project " .
5907 ($format eq 'rss' ? 'RSS' : 'Atom') .
5910 my $owner = git_get_project_owner
($project);
5911 $owner = esc_html
($owner);
5915 if (defined $file_name) {
5916 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5917 } elsif (defined $hash) {
5918 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5920 $alt_url = href
(-full
=>1, action
=>"summary");
5922 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5923 if ($format eq 'rss') {
5925 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5928 print "<title>$title</title>\n" .
5929 "<link>$alt_url</link>\n" .
5930 "<description>$descr</description>\n" .
5931 "<language>en</language>\n";
5932 } elsif ($format eq 'atom') {
5934 <feed xmlns="http://www.w3.org/2005/Atom">
5936 print "<title>$title</title>\n" .
5937 "<subtitle>$descr</subtitle>\n" .
5938 '<link rel="alternate" type="text/html" href="' .
5939 $alt_url . '" />' . "\n" .
5940 '<link rel="self" type="' . $content_type . '" href="' .
5941 $cgi->self_url() . '" />' . "\n" .
5942 "<id>" . href
(-full
=>1) . "</id>\n" .
5943 # use project owner for feed author
5944 "<author><name>$owner</name></author>\n";
5945 if (defined $favicon) {
5946 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5948 if (defined $logo_url) {
5949 # not twice as wide as tall: 72 x 27 pixels
5950 print "<logo>" . esc_url
($logo) . "</logo>\n";
5952 if (! %latest_date) {
5953 # dummy date to keep the feed valid until commits trickle in:
5954 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5956 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5961 for (my $i = 0; $i <= $#commitlist; $i++) {
5962 my %co = %{$commitlist[$i]};
5963 my $commit = $co{'id'};
5964 # we read 150, we always show 30 and the ones more recent than 48 hours
5965 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5968 my %cd = parse_date
($co{'author_epoch'});
5970 # get list of changed files
5971 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5972 $co{'parent'} || "--root",
5973 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5975 my @difftree = map { chomp; $_ } <$fd>;
5979 # print element (entry, item)
5980 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5981 if ($format eq 'rss') {
5983 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5984 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5985 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5986 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5987 "<link>$co_url</link>\n" .
5988 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5989 "<content:encoded>" .
5991 } elsif ($format eq 'atom') {
5993 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5994 "<updated>$cd{'iso-8601'}</updated>\n" .
5996 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5997 if ($co{'author_email'}) {
5998 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6000 print "</author>\n" .
6001 # use committer for contributor
6003 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6004 if ($co{'committer_email'}) {
6005 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6007 print "</contributor>\n" .
6008 "<published>$cd{'iso-8601'}</published>\n" .
6009 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6010 "<id>$co_url</id>\n" .
6011 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6012 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6014 my $comment = $co{'comment'};
6016 foreach my $line (@$comment) {
6017 $line = esc_html
($line);
6020 print "</pre><ul>\n";
6021 foreach my $difftree_line (@difftree) {
6022 my %difftree = parse_difftree_raw_line
($difftree_line);
6023 next if !$difftree{'from_id'};
6025 my $file = $difftree{'file'} || $difftree{'to_file'};
6029 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6030 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6031 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6032 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6033 -title
=> "diff"}, 'D');
6035 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6036 file_name
=>$file, hash_base
=>$commit),
6037 -title
=> "blame"}, 'B');
6039 # if this is not a feed of a file history
6040 if (!defined $file_name || $file_name ne $file) {
6041 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6042 file_name
=>$file, hash
=>$commit),
6043 -title
=> "history"}, 'H');
6045 $file = esc_path
($file);
6049 if ($format eq 'rss') {
6050 print "</ul>]]>\n" .
6051 "</content:encoded>\n" .
6053 } elsif ($format eq 'atom') {
6054 print "</ul>\n</div>\n" .
6061 if ($format eq 'rss') {
6062 print "</channel>\n</rss>\n";
6063 } elsif ($format eq 'atom') {
6077 my @list = git_get_projects_list
();
6079 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
6081 <?xml version="1.0" encoding="utf-8"?>
6082 <opml version="1.0">
6084 <title>$site_name OPML Export</title>
6087 <outline text="git RSS feeds">
6090 foreach my $pr (@list) {
6092 my $head = git_get_head_hash
($proj{'path'});
6093 if (!defined $head) {
6096 $git_dir = "$projectroot/$proj{'path'}";
6097 my %co = parse_commit
($head);
6102 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6103 my $rss = "$my_url?p=$proj{'path'};a=rss";
6104 my $html = "$my_url?p=$proj{'path'};a=summary";
6105 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";