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
13 use CGI qw(:standard :escapeHTML -nosticky);
14 use CGI::Util qw(unescape);
15 use CGI::Carp qw(fatalsToBrowser);
19 use File::Basename qw(basename);
21 binmode STDOUT, ':utf8';
24 CGI->compile() if $ENV{'MOD_PERL'};
28 $cgi $version $my_url $my_uri $base_url $path_info $GIT $projectroot
29 $project_maxdepth $home_link $home_link_str $site_name $site_header
30 $home_text $site_footer @stylesheets $stylesheet $logo $favicon
31 $logo_url $logo_label $logo_url $logo_label $projects_list
32 $projects_list_description_width $default_projects_order
33 $export_ok $export_auth_hook $strict_export @git_base_url_list
34 $default_blob_plain_mimetype $default_text_plain_charset
35 $mimetypes_file $fallback_encoding @diff_opts $prevent_xss
36 %known_snapshot_formats %known_snapshot_format_aliases %feature
37 $GITWEB_CONFIG $GITWEB_CONFIG $GITWEB_CONFIG_SYSTEM $git_version
38 %input_params @cgi_param_mapping %cgi_param_mapping %actions
39 %allowed_options $action $project $file_name $file_parent $hash
40 $hash_parent $hash_base @extra_options $hash_parent_base $page
41 $searchtype $search_use_regexp $searchtext $search_regexp $git_dir
51 our $version = "1.6.3.3";
52 our $my_url = $cgi->url();
53 our $my_uri = $cgi->url(-absolute => 1);
55 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
56 # needed and used only for URLs with nonempty PATH_INFO
57 our $base_url = $my_url;
59 # When the script is used as DirectoryIndex, the URL does not contain the name
60 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
61 # have to do it ourselves. We make $path_info global because it's also used
64 # Another issue with the script being the DirectoryIndex is that the resulting
65 # $my_url data is not the full script URL: this is good, because we want
66 # generated links to keep implying the script name if it wasn't explicitly
67 # indicated in the URL we're handling, but it means that $my_url cannot be used
69 # Therefore, if we needed to strip PATH_INFO, then we know that we have
70 # to build the base URL ourselves:
71 our $path_info = $ENV{"PATH_INFO"};
73 if ($my_url =~ s,\Q$path_info\E$,, &&
74 $my_uri =~ s,\Q$path_info\E$,, &&
75 defined $ENV{'SCRIPT_NAME'}) {
76 $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
80 # core git executable to use
81 # this can just be "git" if your webserver has a sensible PATH
82 our $GIT = "/usr/bin/git";
84 # absolute fs-path which will be prepended to the project path
85 our $projectroot = "/pub/scm";
87 # fs traversing limit for getting project list
88 # the number is relative to the projectroot
89 our $project_maxdepth = 2007;
91 # target of the home link on top of all pages
92 our $home_link = $my_uri || "/";
94 # string of the home link on top of all pages
95 our $home_link_str = "Project Gitalist";
97 # name of your site or organization to appear in page titles
98 # replace this with something more descriptive for clearer bookmarks
100 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
102 # filename of html text to include at top of each page
103 our $site_header = "";
104 # html text to include at home page
105 our $home_text = "indextext.html";
106 # filename of html text to include at bottom of each page
107 our $site_footer = "";
110 our @stylesheets = ("gitweb.css");
111 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
112 our $stylesheet = undef;
113 # URI of GIT logo (72x27 size)
114 our $logo = "git-logo.png";
115 # URI of GIT favicon, assumed to be image/png type
116 our $favicon = "git-favicon.png";
118 # URI and label (title) of GIT logo link
119 our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
120 our $logo_label = "git documentation";
122 # source of projects list
123 our $projects_list = "";
125 # the width (in characters) of the projects list "Description" column
126 our $projects_list_description_width = 25;
128 # default order of projects list
129 # valid values are none, project, descr, owner, and age
130 our $default_projects_order = "project";
132 # show repository only if this file exists
133 # (only effective if this variable evaluates to true)
136 # show repository only if this subroutine returns true
137 # when given the path to the project, for example:
138 # sub { return -e "$_[0]/git-daemon-export-ok"; }
139 our $export_auth_hook = undef;
141 # only allow viewing of repositories also shown on the overview page
142 our $strict_export = "";
144 # list of git base URLs used for URL to where fetch project from,
145 # i.e. full URL is "$git_base_url/$project"
146 our @git_base_url_list = grep { $_ ne '' } ("");
148 # default blob_plain mimetype and default charset for text/plain blob
149 our $default_blob_plain_mimetype = 'text/plain';
150 our $default_text_plain_charset = undef;
152 # file to use for guessing MIME types before trying /etc/mime.types
153 # (relative to the current git repository)
154 our $mimetypes_file = undef;
156 # assume this charset if line contains non-UTF-8 characters;
157 # it should be valid encoding (see Encoding::Supported(3pm) for list),
158 # for which encoding all byte sequences are valid, for example
159 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
160 # could be even 'utf-8' for the old behavior)
161 our $fallback_encoding = 'latin1';
163 # rename detection options for git-diff and git-diff-tree
164 # - default is '-M', with the cost proportional to
165 # (number of removed files) * (number of new files).
166 # - more costly is '-C' (which implies '-M'), with the cost proportional to
167 # (number of changed files + number of removed files) * (number of new files)
168 # - even more costly is '-C', '--find-copies-harder' with cost
169 # (number of files in the original tree) * (number of new files)
170 # - one might want to include '-B' option, e.g. '-B', '-M'
171 our @diff_opts = ('-M'); # taken from git_commit
173 # Disables features that would allow repository owners to inject script into
175 our $prevent_xss = 0;
177 # information about snapshot formats that gitweb is capable of serving
178 our %known_snapshot_formats = (
180 # 'display' => display name,
181 # 'type' => mime type,
182 # 'suffix' => filename suffix,
183 # 'format' => --format for git-archive,
184 # 'compressor' => [compressor command and arguments]
185 # (array reference, optional)}
188 'display' => 'tar.gz',
189 'type' => 'application/x-gzip',
190 'suffix' => '.tar.gz',
192 'compressor' => ['gzip']},
195 'display' => 'tar.bz2',
196 'type' => 'application/x-bzip2',
197 'suffix' => '.tar.bz2',
199 'compressor' => ['bzip2']},
203 'type' => 'application/x-zip',
208 # Aliases so we understand old gitweb.snapshot values in repository
210 our %known_snapshot_format_aliases = (
214 # backward compatibility: legacy gitweb config support
215 'x-gzip' => undef, 'gz' => undef,
216 'x-bzip2' => undef, 'bz2' => undef,
217 'x-zip' => undef, '' => undef,
220 my $feature_bool = sub {
222 my ($val) = git_get_project_config($key, '--bool');
226 } elsif ($val eq 'true') {
228 } elsif ($val eq 'false') {
233 my $feature_snapshot = sub {
236 my ($val) = git_get_project_config('snapshot');
239 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
245 my $feature_patches = sub {
246 my @val = (git_get_project_config('patches', '--int'));
256 # You define site-wide feature defaults here; override them with
257 # $GITWEB_CONFIG as necessary.
260 # 'sub' => feature-sub (subroutine),
261 # 'override' => allow-override (boolean),
262 # 'default' => [ default options...] (array reference)}
264 # if feature is overridable (it means that allow-override has true value),
265 # then feature-sub will be called with default options as parameters;
266 # return value of feature-sub indicates if to enable specified feature
268 # if there is no 'sub' key (no feature-sub), then feature cannot be
271 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
272 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
275 # Enable the 'blame' blob view, showing the last commit that modified
276 # each line in the file. This can be very CPU-intensive.
278 # To enable system wide have in $GITWEB_CONFIG
279 # $feature{'blame'}{'default'} = [1];
280 # To have project specific config enable override in $GITWEB_CONFIG
281 # $feature{'blame'}{'override'} = 1;
282 # and in project config gitweb.blame = 0|1;
284 'sub' => sub { &$feature_bool('blame', @_) },
288 # Enable the 'snapshot' link, providing a compressed archive of any
289 # tree. This can potentially generate high traffic if you have large
292 # Value is a list of formats defined in %known_snapshot_formats that
294 # To disable system wide have in $GITWEB_CONFIG
295 # $feature{'snapshot'}{'default'} = [];
296 # To have project specific config enable override in $GITWEB_CONFIG
297 # $feature{'snapshot'}{'override'} = 1;
298 # and in project config, a comma-separated list of formats or "none"
299 # to disable. Example: gitweb.snapshot = tbz2,zip;
301 'sub' => $feature_snapshot,
303 'default' => ['tgz']},
305 # Enable text search, which will list the commits which match author,
306 # committer or commit text to a given string. Enabled by default.
307 # Project specific override is not supported.
312 # Enable grep search, which will list the files in currently selected
313 # tree containing the given string. Enabled by default. This can be
314 # potentially CPU-intensive, of course.
316 # To enable system wide have in $GITWEB_CONFIG
317 # $feature{'grep'}{'default'} = [1];
318 # To have project specific config enable override in $GITWEB_CONFIG
319 # $feature{'grep'}{'override'} = 1;
320 # and in project config gitweb.grep = 0|1;
322 'sub' => sub { &$feature_bool('grep', @_) },
326 # Enable the pickaxe search, which will list the commits that modified
327 # a given string in a file. This can be practical and quite faster
328 # alternative to 'blame', but still potentially CPU-intensive.
330 # To enable system wide have in $GITWEB_CONFIG
331 # $feature{'pickaxe'}{'default'} = [1];
332 # To have project specific config enable override in $GITWEB_CONFIG
333 # $feature{'pickaxe'}{'override'} = 1;
334 # and in project config gitweb.pickaxe = 0|1;
336 'sub' => sub { &$feature_bool('pickaxe', @_) },
340 # Make gitweb use an alternative format of the URLs which can be
341 # more readable and natural-looking: project name is embedded
342 # directly in the path and the query string contains other
343 # auxiliary information. All gitweb installations recognize
344 # URL in either format; this configures in which formats gitweb
347 # To enable system wide have in $GITWEB_CONFIG
348 # $feature{'pathinfo'}{'default'} = [1];
349 # Project specific override is not supported.
351 # Note that you will need to change the default location of CSS,
352 # favicon, logo and possibly other files to an absolute URL. Also,
353 # if gitweb.cgi serves as your indexfile, you will need to force
354 # $my_uri to contain the script name in your $GITWEB_CONFIG.
359 # Make gitweb consider projects in project root subdirectories
360 # to be forks of existing projects. Given project $projname.git,
361 # projects matching $projname/*.git will not be shown in the main
362 # projects list, instead a '+' mark will be added to $projname
363 # there and a 'forks' view will be enabled for the project, listing
364 # all the forks. If project list is taken from a file, forks have
365 # to be listed after the main project.
367 # To enable system wide have in $GITWEB_CONFIG
368 # $feature{'forks'}{'default'} = [1];
369 # Project specific override is not supported.
374 # Insert custom links to the action bar of all project pages.
375 # This enables you mainly to link to third-party scripts integrating
376 # into gitweb; e.g. git-browser for graphical history representation
377 # or custom web-based repository administration interface.
379 # The 'default' value consists of a list of triplets in the form
380 # (label, link, position) where position is the label after which
381 # to insert the link and link is a format string where %n expands
382 # to the project name, %f to the project path within the filesystem,
383 # %h to the current hash (h gitweb parameter) and %b to the current
384 # hash base (hb gitweb parameter); %% expands to %.
386 # To enable system wide have in $GITWEB_CONFIG e.g.
387 # $feature{'actions'}{'default'} = [('graphiclog',
388 # '/git-browser/by-commit.html?r=%n', 'summary')];
389 # Project specific override is not supported.
394 # Allow gitweb scan project content tags described in ctags/
395 # of project repository, and display the popular Web 2.0-ish
396 # "tag cloud" near the project list. Note that this is something
397 # COMPLETELY different from the normal Git tags.
399 # gitweb by itself can show existing tags, but it does not handle
400 # tagging itself; you need an external application for that.
401 # For an example script, check Girocco's cgi/tagproj.cgi.
402 # You may want to install the HTML::TagCloud Perl module to get
403 # a pretty tag cloud instead of just a list of tags.
405 # To enable system wide have in $GITWEB_CONFIG
406 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
407 # Project specific override is not supported.
412 # The maximum number of patches in a patchset generated in patch
413 # view. Set this to 0 or undef to disable patch view, or to a
414 # negative number to remove any limit.
416 # To disable system wide have in $GITWEB_CONFIG
417 # $feature{'patches'}{'default'} = [0];
418 # To have project specific config enable override in $GITWEB_CONFIG
419 # $feature{'patches'}{'override'} = 1;
420 # and in project config gitweb.patches = 0|n;
421 # where n is the maximum number of patches allowed in a patchset.
423 'sub' => $feature_patches,
428 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
429 if (-e $GITWEB_CONFIG) {
432 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "$FindBin::Bin/../gitweb.conf";
433 do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
436 # version of the core git binary
437 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
439 $projects_list ||= $projectroot;
441 # ======================================================================
442 # input validation and dispatch
444 # input parameters can be collected from a variety of sources (presently, CGI
445 # and PATH_INFO), so we define an %input_params hash that collects them all
446 # together during validation: this allows subsequent uses (e.g. href()) to be
447 # agnostic of the parameter origin
449 our %input_params = ();
451 # input parameters are stored with the long parameter name as key. This will
452 # also be used in the href subroutine to convert parameters to their CGI
453 # equivalent, and since the href() usage is the most frequent one, we store
454 # the name -> CGI key mapping here, instead of the reverse.
456 # XXX: Warning: If you touch this, check the search form for updating,
459 our @cgi_param_mapping = (
467 hash_parent_base => "hpb",
472 snapshot_format => "sf",
473 extra_options => "opt",
474 search_use_regexp => "sr",
476 our %cgi_param_mapping = @cgi_param_mapping;
478 # we will also need to know the possible actions, for validation
480 "blame" => \&git_blame,
481 "blobdiff" => \&git_blobdiff,
482 "blobdiff_plain" => \&git_blobdiff_plain,
483 "blob" => \&git_blob,
484 "blob_plain" => \&git_blob_plain,
485 "commitdiff" => \&git_commitdiff,
486 "commitdiff_plain" => \&git_commitdiff_plain,
487 "commit" => \&git_commit,
488 "forks" => \&git_forks,
489 "heads" => \&git_heads,
490 "history" => \&git_history,
492 "patch" => \&git_patch,
493 "patches" => \&git_patches,
495 "atom" => \&git_atom,
496 "search" => \&git_search,
497 "search_help" => \&git_search_help,
498 "shortlog" => \&git_shortlog,
499 "summary" => \&git_summary,
501 "tags" => \&git_tags,
502 "tree" => \&git_tree,
503 "snapshot" => \&git_snapshot,
504 "object" => \&git_object,
505 # those below don't need $project
506 "opml" => \&git_opml,
507 "project_list" => \&git_project_list,
508 "project_index" => \&git_project_index,
511 # finally, we have the hash of allowed extra_options for the commands that
513 our %allowed_options = (
514 "--no-merges" => [ qw(rss atom log shortlog history) ],
517 # fill %input_params with the CGI parameters. All values except for 'opt'
518 # should be single values, but opt can be an array. We should probably
519 # build an array of parameters that can be multi-valued, but since for the time
520 # being it's only this one, we just single it out
521 while (my ($name, $symbol) = each %cgi_param_mapping) {
522 if ($symbol eq 'opt') {
523 $input_params{$name} = [ $c->req->param($symbol) ];
525 $input_params{$name} = $c->req->param($symbol);
529 # now read PATH_INFO and update the parameter list for missing parameters
530 my $evaluate_path_info = sub {
531 return if defined $input_params{'project'};
532 return if !$path_info;
533 $path_info =~ s,^/+,,;
534 return if !$path_info;
536 # find which part of PATH_INFO is project
537 my $project = $path_info;
539 while ($project && !check_head_link("$projectroot/$project")) {
540 $project =~ s,/*[^/]*$,,;
542 return unless $project;
543 $input_params{'project'} = $project;
545 # do not change any parameters if an action is given using the query string
546 return if $input_params{'action'};
547 $path_info =~ s,^\Q$project\E/*,,;
549 # next, check if we have an action
550 my $action = $path_info;
552 if (exists $actions{$action}) {
553 $path_info =~ s,^$action/*,,;
554 $input_params{'action'} = $action;
557 # list of actions that want hash_base instead of hash, but can have no
558 # pathname (f) parameter
565 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
566 my ($parentrefname, $parentpathname, $refname, $pathname) =
567 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
569 # first, analyze the 'current' part
570 if (defined $pathname) {
571 # we got "branch:filename" or "branch:dir/"
572 # we could use git_get_type(branch:pathname), but:
573 # - it needs $git_dir
574 # - it does a git() call
575 # - the convention of terminating directories with a slash
576 # makes it superfluous
577 # - embedding the action in the PATH_INFO would make it even
579 $pathname =~ s,^/+,,;
580 if (!$pathname || substr($pathname, -1) eq "/") {
581 $input_params{'action'} ||= "tree";
584 # the default action depends on whether we had parent info
586 if ($parentrefname) {
587 $input_params{'action'} ||= "blobdiff_plain";
589 $input_params{'action'} ||= "blob_plain";
592 $input_params{'hash_base'} ||= $refname;
593 $input_params{'file_name'} ||= $pathname;
594 } elsif (defined $refname) {
595 # we got "branch". In this case we have to choose if we have to
596 # set hash or hash_base.
598 # Most of the actions without a pathname only want hash to be
599 # set, except for the ones specified in @wants_base that want
600 # hash_base instead. It should also be noted that hand-crafted
601 # links having 'history' as an action and no pathname or hash
602 # set will fail, but that happens regardless of PATH_INFO.
603 $input_params{'action'} ||= "shortlog";
604 if (grep { $_ eq $input_params{'action'} } @wants_base) {
605 $input_params{'hash_base'} ||= $refname;
607 $input_params{'hash'} ||= $refname;
611 # next, handle the 'parent' part, if present
612 if (defined $parentrefname) {
613 # a missing pathspec defaults to the 'current' filename, allowing e.g.
614 # someproject/blobdiff/oldrev..newrev:/filename
615 if ($parentpathname) {
616 $parentpathname =~ s,^/+,,;
617 $parentpathname =~ s,/$,,;
618 $input_params{'file_parent'} ||= $parentpathname;
620 $input_params{'file_parent'} ||= $input_params{'file_name'};
622 # we assume that hash_parent_base is wanted if a path was specified,
623 # or if the action wants hash_base instead of hash
624 if (defined $input_params{'file_parent'} ||
625 grep { $_ eq $input_params{'action'} } @wants_base) {
626 $input_params{'hash_parent_base'} ||= $parentrefname;
628 $input_params{'hash_parent'} ||= $parentrefname;
632 # for the snapshot action, we allow URLs in the form
633 # $project/snapshot/$hash.ext
634 # where .ext determines the snapshot and gets removed from the
635 # passed $refname to provide the $hash.
637 # To be able to tell that $refname includes the format extension, we
638 # require the following two conditions to be satisfied:
639 # - the hash input parameter MUST have been set from the $refname part
640 # of the URL (i.e. they must be equal)
641 # - the snapshot format MUST NOT have been defined already (e.g. from
643 # It's also useless to try any matching unless $refname has a dot,
644 # so we check for that too
645 if (defined $input_params{'action'} &&
646 $input_params{'action'} eq 'snapshot' &&
647 defined $refname && index($refname, '.') != -1 &&
648 $refname eq $input_params{'hash'} &&
649 !defined $input_params{'snapshot_format'}) {
650 # We loop over the known snapshot formats, checking for
651 # extensions. Allowed extensions are both the defined suffix
652 # (which includes the initial dot already) and the snapshot
653 # format key itself, with a prepended dot
654 while (my ($fmt, $opt) = each %known_snapshot_formats) {
657 $hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//;
658 next unless $sfx = $1;
659 # a valid suffix was found, so set the snapshot format
660 # and reset the hash parameter
661 $input_params{'snapshot_format'} = $fmt;
662 $input_params{'hash'} = $hash;
663 # we also set the format suffix to the one requested
664 # in the URL: this way a request for e.g. .tgz returns
665 # a .tgz instead of a .tar.gz
666 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
672 &$evaluate_path_info();
674 gitweb_validate_setup();
676 return $actions{$action};
679 sub gitweb_validate_setup {
680 our $action = $input_params{'action'};
681 if (defined $action) {
682 if (!validate_action($action)) {
683 die_error(400, "Invalid action parameter");
687 # parameters which are pathnames
688 our $project = $input_params{'project'};
689 if (defined $project) {
690 if (!validate_project($project)) {
692 die_error(404, "No such project");
696 our $file_name = $input_params{'file_name'};
697 if (defined $file_name) {
698 if (!validate_pathname($file_name)) {
699 die_error(400, "Invalid file parameter");
703 our $file_parent = $input_params{'file_parent'};
704 if (defined $file_parent) {
705 if (!validate_pathname($file_parent)) {
706 die_error(400, "Invalid file parent parameter");
710 # parameters which are refnames
711 our $hash = $input_params{'hash'};
713 if (!validate_refname($hash)) {
714 die_error(400, "Invalid hash parameter");
718 our $hash_parent = $input_params{'hash_parent'};
719 if (defined $hash_parent) {
720 if (!validate_refname($hash_parent)) {
721 die_error(400, "Invalid hash parent parameter");
725 our $hash_base = $input_params{'hash_base'};
726 if (defined $hash_base) {
727 if (!validate_refname($hash_base)) {
728 die_error(400, "Invalid hash base parameter");
732 our @extra_options = @{$input_params{'extra_options'}};
733 # @extra_options is always defined, since it can only be (currently) set from
734 # CGI, and $c->req->param() returns the empty array in array context if the param
736 foreach my $opt (@extra_options) {
737 if (not exists $allowed_options{$opt}) {
738 die_error(400, "Invalid option parameter");
740 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
741 die_error(400, "Invalid option parameter for this action");
745 our $hash_parent_base = $input_params{'hash_parent_base'};
746 if (defined $hash_parent_base) {
747 if (!validate_refname($hash_parent_base)) {
748 die_error(400, "Invalid hash parent base parameter");
753 our $page = $input_params{'page'};
755 if ($page =~ m/[^0-9]/) {
756 die_error(400, "Invalid page parameter");
760 our $searchtype = $input_params{'searchtype'};
761 if (defined $searchtype) {
762 if ($searchtype =~ m/[^a-z]/) {
763 die_error(400, "Invalid searchtype parameter");
767 our $search_use_regexp = $input_params{'search_use_regexp'};
769 our $searchtext = $input_params{'searchtext'};
771 if (defined $searchtext) {
772 if (length($searchtext) < 2) {
773 die_error(403, "At least two characters are required for search parameter");
775 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
778 # path to the current git repository
780 $git_dir = "$projectroot/$project" if $project;
782 # process alternate names for backward compatibility
783 # filter out unsupported (unknown) snapshot formats
784 my $filter_snapshot_fmts = sub {
788 exists $known_snapshot_format_aliases{$_} ?
789 $known_snapshot_format_aliases{$_} : $_} @fmts;
790 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
793 # list of supported snapshot formats
794 our @snapshot_fmts = gitweb_get_feature('snapshot');
795 @snapshot_fmts = &$filter_snapshot_fmts(@snapshot_fmts);
798 if (!defined $action) {
800 $action = git_get_type($hash);
801 } elsif (defined $hash_base && defined $file_name) {
802 $action = git_get_type("$hash_base:$file_name");
803 } elsif (defined $project) {
806 $action = 'project_list';
809 if (!defined($actions{$action})) {
810 die_error(400, "Unknown action");
812 if ($action !~ m/^(opml|project_list|project_index)$/ &&
814 die_error(400, "Project needed");
818 sub gitweb_get_feature {
820 return unless exists $feature{$name};
821 my ($sub, $override, @defaults) = (
822 $feature{$name}{'sub'},
823 $feature{$name}{'override'},
824 @{$feature{$name}{'default'}});
825 if (!$override) { return @defaults; }
827 warn "feature $name is not overrideable";
830 return $sub->(@defaults);
833 # A wrapper to check if a given feature is enabled.
834 # With this, you can say
836 # my $bool_feat = gitweb_check_feature('bool_feat');
837 # gitweb_check_feature('bool_feat') or somecode;
841 # my ($bool_feat) = gitweb_get_feature('bool_feat');
842 # (gitweb_get_feature('bool_feat'))[0] or somecode;
844 sub gitweb_check_feature {
845 return (gitweb_get_feature(@_))[0];
848 # checking HEAD file with -e is fragile if the repository was
849 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
851 sub check_head_link {
853 my $headfile = "$dir/HEAD";
854 return ((-e $headfile) ||
855 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
858 sub check_export_ok {
860 return (check_head_link($dir) &&
861 (!$export_ok || -e "$dir/$export_ok") &&
862 (!$export_auth_hook || $export_auth_hook->($dir)));
866 ## ======================================================================
871 # default is to use -absolute url() i.e. $my_uri
872 my $href = $params{-full} ? $my_url : $my_uri;
874 $params{'project'} = $project unless exists $params{'project'};
876 if ($params{-replay}) {
877 while (my ($name, $symbol) = each %cgi_param_mapping) {
878 if (!exists $params{$name}) {
879 $params{$name} = $input_params{$name};
884 my $use_pathinfo = gitweb_check_feature('pathinfo');
885 if ($use_pathinfo and defined $params{'project'}) {
886 # try to put as many parameters as possible in PATH_INFO:
889 # - hash_parent or hash_parent_base:/file_parent
890 # - hash or hash_base:/filename
891 # - the snapshot_format as an appropriate suffix
893 # When the script is the root DirectoryIndex for the domain,
894 # $href here would be something like http://gitweb.example.com/
895 # Thus, we strip any trailing / from $href, to spare us double
896 # slashes in the final URL
899 # Then add the project name, if present
900 $href .= "/".esc_url($params{'project'});
901 delete $params{'project'};
903 # since we destructively absorb parameters, we keep this
904 # boolean that remembers if we're handling a snapshot
905 my $is_snapshot = $params{'action'} eq 'snapshot';
907 # Summary just uses the project path URL, any other action is
909 if (defined $params{'action'}) {
910 $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
911 delete $params{'action'};
914 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
915 # stripping nonexistent or useless pieces
916 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
917 || $params{'hash_parent'} || $params{'hash'});
918 if (defined $params{'hash_base'}) {
919 if (defined $params{'hash_parent_base'}) {
920 $href .= esc_url($params{'hash_parent_base'});
921 # skip the file_parent if it's the same as the file_name
922 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
923 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
924 $href .= ":/".esc_url($params{'file_parent'});
925 delete $params{'file_parent'};
928 delete $params{'hash_parent'};
929 delete $params{'hash_parent_base'};
930 } elsif (defined $params{'hash_parent'}) {
931 $href .= esc_url($params{'hash_parent'}). "..";
932 delete $params{'hash_parent'};
935 $href .= esc_url($params{'hash_base'});
936 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
937 $href .= ":/".esc_url($params{'file_name'});
938 delete $params{'file_name'};
940 delete $params{'hash'};
941 delete $params{'hash_base'};
942 } elsif (defined $params{'hash'}) {
943 $href .= esc_url($params{'hash'});
944 delete $params{'hash'};
947 # If the action was a snapshot, we can absorb the
948 # snapshot_format parameter too
950 my $fmt = $params{'snapshot_format'};
951 # snapshot_format should always be defined when href()
952 # is called, but just in case some code forgets, we
953 # fall back to the default
954 $fmt ||= $snapshot_fmts[0];
955 $href .= $known_snapshot_formats{$fmt}{'suffix'};
956 delete $params{'snapshot_format'};
960 # now encode the parameters explicitly
962 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
963 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
964 if (defined $params{$name}) {
965 if (ref($params{$name}) eq "ARRAY") {
966 foreach my $par (@{$params{$name}}) {
967 push @result, $symbol . "=" . esc_param($par);
970 push @result, $symbol . "=" . esc_param($params{$name});
974 $href .= "?" . join(';', @result) if scalar @result;
980 ## ======================================================================
981 ## validation, quoting/unquoting and escaping
983 sub validate_action {
984 my $input = shift || return undef;
985 return undef unless exists $actions{$input};
989 sub validate_project {
990 my $input = shift || return undef;
991 if (!validate_pathname($input) ||
992 !(-d "$projectroot/$input") ||
993 !check_export_ok("$projectroot/$input") ||
994 ($strict_export && !project_in_list($input))) {
1001 sub validate_pathname {
1002 my $input = shift || return undef;
1004 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1005 # at the beginning, at the end, and between slashes.
1006 # also this catches doubled slashes
1007 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1010 # no null characters
1011 if ($input =~ m!\0!) {
1017 sub validate_refname {
1018 my $input = shift || return undef;
1020 # textual hashes are O.K.
1021 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1024 # it must be correct pathname
1025 $input = validate_pathname($input)
1027 # restrictions on ref name according to git-check-ref-format
1028 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1034 # decode sequences of octets in utf8 into Perl's internal form,
1035 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1036 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1039 if (utf8::valid($str)) {
1043 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
1047 # quote unsafe chars, but keep the slash, even when it's not
1048 # correct, but quoted slashes look too horrible in bookmarks
1051 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
1057 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1060 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
1066 # replace invalid utf8 character with SUBSTITUTION sequence
1067 sub esc_html ($;%) {
1071 $str = to_utf8($str);
1072 $str = $cgi->escapeHTML($str);
1073 if ($opts{'-nbsp'}) {
1074 $str =~ s/ / /g;
1076 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
1080 # quote control characters and escape filename to HTML
1085 $str = to_utf8($str);
1086 $str = $cgi->escapeHTML($str);
1087 if ($opts{'-nbsp'}) {
1088 $str =~ s/ / /g;
1090 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
1094 # Make control characters "printable", using character escape codes (CEC)
1098 my %es = ( # character escape codes, aka escape sequences
1099 "\t" => '\t', # tab (HT)
1100 "\n" => '\n', # line feed (LF)
1101 "\r" => '\r', # carrige return (CR)
1102 "\f" => '\f', # form feed (FF)
1103 "\b" => '\b', # backspace (BS)
1104 "\a" => '\a', # alarm (bell) (BEL)
1105 "\e" => '\e', # escape (ESC)
1106 "\013" => '\v', # vertical tab (VT)
1107 "\000" => '\0', # nul character (NUL)
1109 my $chr = ( (exists $es{$cntrl})
1111 : sprintf('\%2x', ord($cntrl)) );
1112 if ($opts{-nohtml}) {
1115 return "<span class=\"cntrl\">$chr</span>";
1119 # Alternatively use unicode control pictures codepoints,
1120 # Unicode "printable representation" (PR)
1125 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1126 if ($opts{-nohtml}) {
1129 return "<span class=\"cntrl\">$chr</span>";
1133 # git may return quoted and escaped filenames
1139 my %es = ( # character escape codes, aka escape sequences
1140 't' => "\t", # tab (HT, TAB)
1141 'n' => "\n", # newline (NL)
1142 'r' => "\r", # return (CR)
1143 'f' => "\f", # form feed (FF)
1144 'b' => "\b", # backspace (BS)
1145 'a' => "\a", # alarm (bell) (BEL)
1146 'e' => "\e", # escape (ESC)
1147 'v' => "\013", # vertical tab (VT)
1150 if ($seq =~ m/^[0-7]{1,3}$/) {
1151 # octal char sequence
1152 return chr(oct($seq));
1153 } elsif (exists $es{$seq}) {
1154 # C escape sequence, aka character escape code
1157 # quoted ordinary character
1161 if ($str =~ m/^"(.*)"$/) {
1164 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1169 # escape tabs (convert tabs to spaces)
1173 while ((my $pos = index($line, "\t")) != -1) {
1174 if (my $count = (8 - ($pos % 8))) {
1175 my $spaces = ' ' x $count;
1176 $line =~ s/\t/$spaces/;
1183 sub project_in_list {
1184 my $project = shift;
1185 my @list = git_get_projects_list();
1186 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1189 ## ----------------------------------------------------------------------
1190 ## HTML aware string manipulation
1192 # Try to chop given string on a word boundary between position
1193 # $len and $len+$add_len. If there is no word boundary there,
1194 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1195 # (marking chopped part) would be longer than given string.
1199 my $add_len = shift || 10;
1200 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1202 # Make sure perl knows it is utf8 encoded so we don't
1203 # cut in the middle of a utf8 multibyte char.
1204 $str = to_utf8($str);
1206 # allow only $len chars, but don't cut a word if it would fit in $add_len
1207 # if it doesn't fit, cut it if it's still longer than the dots we would add
1208 # remove chopped character entities entirely
1210 # when chopping in the middle, distribute $len into left and right part
1211 # return early if chopping wouldn't make string shorter
1212 if ($where eq 'center') {
1213 return $str if ($len + 5 >= length($str)); # filler is length 5
1216 return $str if ($len + 4 >= length($str)); # filler is length 4
1219 # regexps: ending and beginning with word part up to $add_len
1220 my $endre = qr/.{$len}\w{0,$add_len}/;
1221 my $begre = qr/\w{0,$add_len}.{$len}/;
1223 if ($where eq 'left') {
1224 $str =~ m/^(.*?)($begre)$/;
1225 my ($lead, $body) = ($1, $2);
1226 if (length($lead) > 4) {
1227 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1230 return "$lead$body";
1232 } elsif ($where eq 'center') {
1233 $str =~ m/^($endre)(.*)$/;
1234 my ($left, $str) = ($1, $2);
1235 $str =~ m/^(.*?)($begre)$/;
1236 my ($mid, $right) = ($1, $2);
1237 if (length($mid) > 5) {
1238 $left =~ s/&[^;]*$//;
1239 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1242 return "$left$mid$right";
1245 $str =~ m/^($endre)(.*)$/;
1248 if (length($tail) > 4) {
1249 $body =~ s/&[^;]*$//;
1252 return "$body$tail";
1256 # takes the same arguments as chop_str, but also wraps a <span> around the
1257 # result with a title attribute if it does get chopped. Additionally, the
1258 # string is HTML-escaped.
1259 sub chop_and_escape_str {
1262 my $chopped = chop_str(@_);
1263 if ($chopped eq $str) {
1264 return esc_html($chopped);
1266 $str =~ s/([[:cntrl:]])/?/g;
1267 return $cgi->span({-title=>$str}, esc_html($chopped));
1271 ## ----------------------------------------------------------------------
1272 ## functions returning short strings
1274 # CSS class for given age value (in seconds)
1278 if (!defined $age) {
1280 } elsif ($age < 60*60*2) {
1282 } elsif ($age < 60*60*24*2) {
1289 # convert age in seconds to "nn units ago" string
1294 if ($age > 60*60*24*365*2) {
1295 $age_str = (int $age/60/60/24/365);
1296 $age_str .= " years ago";
1297 } elsif ($age > 60*60*24*(365/12)*2) {
1298 $age_str = int $age/60/60/24/(365/12);
1299 $age_str .= " months ago";
1300 } elsif ($age > 60*60*24*7*2) {
1301 $age_str = int $age/60/60/24/7;
1302 $age_str .= " weeks ago";
1303 } elsif ($age > 60*60*24*2) {
1304 $age_str = int $age/60/60/24;
1305 $age_str .= " days ago";
1306 } elsif ($age > 60*60*2) {
1307 $age_str = int $age/60/60;
1308 $age_str .= " hours ago";
1309 } elsif ($age > 60*2) {
1310 $age_str = int $age/60;
1311 $age_str .= " min ago";
1312 } elsif ($age > 2) {
1313 $age_str = int $age;
1314 $age_str .= " sec ago";
1316 $age_str .= " right now";
1322 S_IFINVALID => 0030000,
1323 S_IFGITLINK => 0160000,
1326 # submodule/subproject, a commit object reference
1327 sub S_ISGITLINK($) {
1330 return (($mode & S_IFMT) == S_IFGITLINK)
1333 # convert file mode in octal to symbolic file mode string
1335 my $mode = oct shift;
1337 if (S_ISGITLINK($mode)) {
1338 return 'm---------';
1339 } elsif (S_ISDIR($mode & S_IFMT)) {
1340 return 'drwxr-xr-x';
1341 } elsif (S_ISLNK($mode)) {
1342 return 'lrwxrwxrwx';
1343 } elsif (S_ISREG($mode)) {
1344 # git cares only about the executable bit
1345 if ($mode & S_IXUSR) {
1346 return '-rwxr-xr-x';
1348 return '-rw-r--r--';
1351 return '----------';
1355 # convert file mode in octal to file type string
1359 if ($mode !~ m/^[0-7]+$/) {
1365 if (S_ISGITLINK($mode)) {
1367 } elsif (S_ISDIR($mode & S_IFMT)) {
1369 } elsif (S_ISLNK($mode)) {
1371 } elsif (S_ISREG($mode)) {
1378 # convert file mode in octal to file type description string
1379 sub file_type_long {
1382 if ($mode !~ m/^[0-7]+$/) {
1388 if (S_ISGITLINK($mode)) {
1390 } elsif (S_ISDIR($mode & S_IFMT)) {
1392 } elsif (S_ISLNK($mode)) {
1394 } elsif (S_ISREG($mode)) {
1395 if ($mode & S_IXUSR) {
1396 return "executable";
1406 ## ----------------------------------------------------------------------
1407 ## functions returning short HTML fragments, or transforming HTML fragments
1408 ## which don't belong to other sections
1410 # format line of commit message.
1411 sub format_log_line_html {
1414 $line = esc_html($line, -nbsp=>1);
1415 $line =~ s{\b([0-9a-fA-F]{8,40})\b}{
1416 $cgi->a({-href => href(action=>"object", hash=>$1),
1417 -class => "text"}, $1);
1423 # format marker of refs pointing to given object
1425 # the destination action is chosen based on object type and current context:
1426 # - for annotated tags, we choose the tag view unless it's the current view
1427 # already, in which case we go to shortlog view
1428 # - for other refs, we keep the current view if we're in history, shortlog or
1429 # log view, and select shortlog otherwise
1430 sub format_ref_marker {
1431 my ($refs, $id) = @_;
1434 if (defined $refs->{$id}) {
1435 foreach my $ref (@{$refs->{$id}}) {
1436 # this code exploits the fact that non-lightweight tags are the
1437 # only indirect objects, and that they are the only objects for which
1438 # we want to use tag instead of shortlog as action
1439 my ($type, $name) = qw();
1440 my $indirect = ($ref =~ s/\^\{\}$//);
1441 # e.g. tags/v2.6.11 or heads/next
1442 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1451 $class .= " indirect" if $indirect;
1453 my $dest_action = "shortlog";
1456 $dest_action = "tag" unless $action eq "tag";
1457 } elsif ($action =~ /^(history|(short)?log)$/) {
1458 $dest_action = $action;
1462 $dest .= "refs/" unless $ref =~ m!^refs/!;
1465 my $link = $cgi->a({
1467 action=>$dest_action,
1471 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1477 return ' <span class="refs">'. $markers . '</span>';
1483 # format, perhaps shortened and with markers, title line
1484 sub format_subject_html {
1485 my ($long, $short, $href, $extra) = @_;
1486 $extra = '' unless defined($extra);
1488 if (length($short) < length($long)) {
1489 return $cgi->a({-href => $href, -class => "list subject",
1490 -title => to_utf8($long)},
1491 esc_html($short) . $extra);
1493 return $cgi->a({-href => $href, -class => "list subject"},
1494 esc_html($long) . $extra);
1498 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1499 sub format_git_diff_header_line {
1501 my $diffinfo = shift;
1502 my ($from, $to) = @_;
1504 if ($diffinfo->{'nparents'}) {
1506 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1507 if ($to->{'href'}) {
1508 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1509 esc_path($to->{'file'}));
1510 } else { # file was deleted (no href)
1511 $line .= esc_path($to->{'file'});
1515 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1516 if ($from->{'href'}) {
1517 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1518 'a/' . esc_path($from->{'file'}));
1519 } else { # file was added (no href)
1520 $line .= 'a/' . esc_path($from->{'file'});
1523 if ($to->{'href'}) {
1524 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1525 'b/' . esc_path($to->{'file'}));
1526 } else { # file was deleted
1527 $line .= 'b/' . esc_path($to->{'file'});
1531 return "<div class=\"diff header\">$line</div>\n";
1534 # format extended diff header line, before patch itself
1535 sub format_extended_diff_header_line {
1537 my $diffinfo = shift;
1538 my ($from, $to) = @_;
1541 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1542 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1543 esc_path($from->{'file'}));
1545 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1546 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1547 esc_path($to->{'file'}));
1549 # match single <mode>
1550 if ($line =~ m/\s(\d{6})$/) {
1551 $line .= '<span class="info"> (' .
1552 file_type_long($1) .
1556 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1557 # can match only for combined diff
1559 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1560 if ($from->{'href'}[$i]) {
1561 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1563 substr($diffinfo->{'from_id'}[$i],0,7));
1568 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1571 if ($to->{'href'}) {
1572 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1573 substr($diffinfo->{'to_id'},0,7));
1578 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1579 # can match only for ordinary diff
1580 my ($from_link, $to_link);
1581 if ($from->{'href'}) {
1582 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1583 substr($diffinfo->{'from_id'},0,7));
1585 $from_link = '0' x 7;
1587 if ($to->{'href'}) {
1588 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1589 substr($diffinfo->{'to_id'},0,7));
1593 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1594 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1597 return $line . "<br/>\n";
1600 # format from-file/to-file diff header
1601 sub format_diff_from_to_header {
1602 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1607 #assert($line =~ m/^---/) if DEBUG;
1608 # no extra formatting for "^--- /dev/null"
1609 if (! $diffinfo->{'nparents'}) {
1610 # ordinary (single parent) diff
1611 if ($line =~ m!^--- "?a/!) {
1612 if ($from->{'href'}) {
1614 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1615 esc_path($from->{'file'}));
1618 esc_path($from->{'file'});
1621 $result .= qq!<div class="diff from_file">$line</div>\n!;
1624 # combined diff (merge commit)
1625 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1626 if ($from->{'href'}[$i]) {
1628 $cgi->a({-href=>href(action=>"blobdiff",
1629 hash_parent=>$diffinfo->{'from_id'}[$i],
1630 hash_parent_base=>$parents[$i],
1631 file_parent=>$from->{'file'}[$i],
1632 hash=>$diffinfo->{'to_id'},
1634 file_name=>$to->{'file'}),
1636 -title=>"diff" . ($i+1)},
1639 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1640 esc_path($from->{'file'}[$i]));
1642 $line = '--- /dev/null';
1644 $result .= qq!<div class="diff from_file">$line</div>\n!;
1649 #assert($line =~ m/^\+\+\+/) if DEBUG;
1650 # no extra formatting for "^+++ /dev/null"
1651 if ($line =~ m!^\+\+\+ "?b/!) {
1652 if ($to->{'href'}) {
1654 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1655 esc_path($to->{'file'}));
1658 esc_path($to->{'file'});
1661 $result .= qq!<div class="diff to_file">$line</div>\n!;
1666 # create note for patch simplified by combined diff
1667 sub format_diff_cc_simplified {
1668 my ($diffinfo, @parents) = @_;
1671 $result .= "<div class=\"diff header\">" .
1673 if (!is_deleted($diffinfo)) {
1674 $result .= $cgi->a({-href => href(action=>"blob",
1676 hash=>$diffinfo->{'to_id'},
1677 file_name=>$diffinfo->{'to_file'}),
1679 esc_path($diffinfo->{'to_file'}));
1681 $result .= esc_path($diffinfo->{'to_file'});
1683 $result .= "</div>\n" . # class="diff header"
1684 "<div class=\"diff nodifferences\">" .
1686 "</div>\n"; # class="diff nodifferences"
1691 # format patch (diff) line (not to be used for diff headers)
1692 sub format_diff_line {
1694 my ($from, $to) = @_;
1695 my $diff_class = "";
1699 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1701 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1702 if ($line =~ m/^\@{3}/) {
1703 $diff_class = " chunk_header";
1704 } elsif ($line =~ m/^\\/) {
1705 $diff_class = " incomplete";
1706 } elsif ($prefix =~ tr/+/+/) {
1707 $diff_class = " add";
1708 } elsif ($prefix =~ tr/-/-/) {
1709 $diff_class = " rem";
1712 # assume ordinary diff
1713 my $char = substr($line, 0, 1);
1715 $diff_class = " add";
1716 } elsif ($char eq '-') {
1717 $diff_class = " rem";
1718 } elsif ($char eq '@') {
1719 $diff_class = " chunk_header";
1720 } elsif ($char eq "\\") {
1721 $diff_class = " incomplete";
1724 $line = untabify($line);
1725 if ($from && $to && $line =~ m/^\@{2} /) {
1726 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1727 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1729 $from_lines = 0 unless defined $from_lines;
1730 $to_lines = 0 unless defined $to_lines;
1732 if ($from->{'href'}) {
1733 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1734 -class=>"list"}, $from_text);
1736 if ($to->{'href'}) {
1737 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1738 -class=>"list"}, $to_text);
1740 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1741 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1742 return "<div class=\"diff$diff_class\">$line</div>\n";
1743 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1744 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1745 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1747 @from_text = split(' ', $ranges);
1748 for (my $i = 0; $i < @from_text; ++$i) {
1749 ($from_start[$i], $from_nlines[$i]) =
1750 (split(',', substr($from_text[$i], 1)), 0);
1753 $to_text = pop @from_text;
1754 $to_start = pop @from_start;
1755 $to_nlines = pop @from_nlines;
1757 $line = "<span class=\"chunk_info\">$prefix ";
1758 for (my $i = 0; $i < @from_text; ++$i) {
1759 if ($from->{'href'}[$i]) {
1760 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1761 -class=>"list"}, $from_text[$i]);
1763 $line .= $from_text[$i];
1767 if ($to->{'href'}) {
1768 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1769 -class=>"list"}, $to_text);
1773 $line .= " $prefix</span>" .
1774 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1775 return "<div class=\"diff$diff_class\">$line</div>\n";
1777 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1780 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1781 # linked. Pass the hash of the tree/commit to snapshot.
1782 sub format_snapshot_links {
1784 my $num_fmts = @snapshot_fmts;
1785 if ($num_fmts > 1) {
1786 # A parenthesized list of links bearing format names.
1787 # e.g. "snapshot (_tar.gz_ _zip_)"
1788 return "snapshot (" . join(' ', map
1795 }, $known_snapshot_formats{$_}{'display'})
1796 , @snapshot_fmts) . ")";
1797 } elsif ($num_fmts == 1) {
1798 # A single "snapshot" link whose tooltip bears the format name.
1800 my ($fmt) = @snapshot_fmts;
1806 snapshot_format=>$fmt
1808 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1810 } else { # $num_fmts == 0
1815 ## ......................................................................
1816 ## functions returning values to be passed, perhaps after some
1817 ## transformation, to other functions; e.g. returning arguments to href()
1819 # returns hash to be passed to href to generate gitweb URL
1820 # in -title key it returns description of link
1822 my $format = shift || 'Atom';
1823 my %res = (action => lc($format));
1825 # feed links are possible only for project views
1826 return unless (defined $project);
1827 # some views should link to OPML, or to generic project feed,
1828 # or don't have specific feed yet (so they should use generic)
1829 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1832 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1833 # from tag links; this also makes possible to detect branch links
1834 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1835 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1838 # find log type for feed description (title)
1840 if (defined $file_name) {
1841 $type = "history of $file_name";
1842 $type .= "/" if ($action eq 'tree');
1843 $type .= " on '$branch'" if (defined $branch);
1845 $type = "log of $branch" if (defined $branch);
1848 $res{-title} = $type;
1849 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1850 $res{'file_name'} = $file_name;
1855 ## ----------------------------------------------------------------------
1856 ## git utility subroutines, invoking git commands
1858 # returns path to the core git executable and the --git-dir parameter as list
1860 return $GIT, '--git-dir='.$git_dir;
1863 # quote the given arguments for passing them to the shell
1864 # quote_command("command", "arg 1", "arg with ' and ! characters")
1865 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1866 # Try to avoid using this function wherever possible.
1869 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1872 # get HEAD ref of given project as hash
1873 sub git_get_head_hash {
1874 my $project = shift;
1875 my $o_git_dir = $git_dir;
1877 $git_dir = "$projectroot/$project";
1878 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1881 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1885 if (defined $o_git_dir) {
1886 $git_dir = $o_git_dir;
1891 # get type of given object
1895 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1897 close $fd or return;
1902 # repository configuration
1903 our $config_file = '';
1906 # store multiple values for single key as anonymous array reference
1907 # single values stored directly in the hash, not as [ <value> ]
1908 sub hash_set_multi {
1909 my ($hash, $key, $value) = @_;
1911 if (!exists $hash->{$key}) {
1912 $hash->{$key} = $value;
1913 } elsif (!ref $hash->{$key}) {
1914 $hash->{$key} = [ $hash->{$key}, $value ];
1916 push @{$hash->{$key}}, $value;
1920 # return hash of git project configuration
1921 # optionally limited to some section, e.g. 'gitweb'
1922 sub git_parse_project_config {
1923 my $section_regexp = shift;
1928 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
1931 while (my $keyval = <$fh>) {
1933 my ($key, $value) = split(/\n/, $keyval, 2);
1935 hash_set_multi(\%config, $key, $value)
1936 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1943 # convert config value to boolean: 'true' or 'false'
1944 # no value, number > 0, 'true' and 'yes' values are true
1945 # rest of values are treated as false (never as error)
1946 sub config_to_bool {
1949 return 1 if !defined $val; # section.key
1951 # strip leading and trailing whitespace
1955 return (($val =~ /^\d+$/ && $val) || # section.key = 1
1956 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1959 # convert config value to simple decimal number
1960 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1961 # to be multiplied by 1024, 1048576, or 1073741824
1965 # strip leading and trailing whitespace
1969 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1971 # unknown unit is treated as 1
1972 return $num * ($unit eq 'g' ? 1073741824 :
1973 $unit eq 'm' ? 1048576 :
1974 $unit eq 'k' ? 1024 : 1);
1979 # convert config value to array reference, if needed
1980 sub config_to_multi {
1983 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1986 sub git_get_project_config {
1987 my ($key, $type) = @_;
1990 return unless ($key);
1991 $key =~ s/^gitweb\.//;
1992 return if ($key =~ m/\W/);
1995 if (defined $type) {
1998 unless ($type eq 'bool' || $type eq 'int');
2002 if (!defined $config_file ||
2003 $config_file ne "$git_dir/config") {
2004 %config = git_parse_project_config('gitweb');
2005 $config_file = "$git_dir/config";
2008 # check if config variable (key) exists
2009 return unless exists $config{"gitweb.$key"};
2012 if (!defined $type) {
2013 return $config{"gitweb.$key"};
2014 } elsif ($type eq 'bool') {
2015 # backward compatibility: 'git config --bool' returns true/false
2016 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
2017 } elsif ($type eq 'int') {
2018 return config_to_int($config{"gitweb.$key"});
2020 return $config{"gitweb.$key"};
2023 # get hash of given path at given ref
2024 sub git_get_hash_by_path {
2026 my $path = shift || return undef;
2031 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
2032 or die_error(500, "Open git-ls-tree failed");
2034 close $fd or return undef;
2036 if (!defined $line) {
2037 # there is no tree or hash given by $path at $base
2041 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2042 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2043 if (defined $type && $type ne $2) {
2044 # type doesn't match
2050 # get path of entry with given hash at given tree-ish (ref)
2051 # used to get 'from' filename for combined diff (merge commit) for renames
2052 sub git_get_path_by_hash {
2053 my $base = shift || return;
2054 my $hash = shift || return;
2058 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
2060 while (my $line = <$fd>) {
2063 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2064 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2065 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2074 ## ......................................................................
2075 ## git utility functions, directly accessing git repository
2077 sub git_get_project_description {
2080 $git_dir = "$projectroot/$path";
2081 open my $fd, "$git_dir/description"
2082 or return git_get_project_config('description');
2085 if (defined $descr) {
2091 sub git_get_project_ctags {
2095 $git_dir = "$projectroot/$path";
2096 unless (opendir D, "$git_dir/ctags") {
2099 foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
2100 open CT, $_ or next;
2104 my $ctag = $_; $ctag =~ s#.*/##;
2105 $ctags->{$ctag} = $val;
2111 sub git_populate_project_tagcloud {
2114 # First, merge different-cased tags; tags vote on casing
2116 foreach (keys %$ctags) {
2117 $ctags_lc{lc $_}->{count} += $ctags->{$_};
2118 if (not $ctags_lc{lc $_}->{topcount}
2119 or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) {
2120 $ctags_lc{lc $_}->{topcount} = $ctags->{$_};
2121 $ctags_lc{lc $_}->{topname} = $_;
2126 if (eval { require HTML::TagCloud; 1; }) {
2127 $cloud = HTML::TagCloud->new;
2128 foreach (sort keys %ctags_lc) {
2129 # Pad the title with spaces so that the cloud looks
2131 my $title = $ctags_lc{$_}->{topname};
2132 $title =~ s/ / /g;
2133 $title =~ s/^/ /g;
2134 $title =~ s/$/ /g;
2135 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
2138 $cloud = \%ctags_lc;
2143 sub git_show_project_tagcloud {
2144 my ($cloud, $count) = @_;
2145 #print STDERR ref($cloud)."..\n";
2146 if (ref $cloud eq 'HTML::TagCloud') {
2147 return $cloud->html_and_css($count);
2149 my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud;
2150 return '<p align="center">' . join (', ', map {
2151 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2152 } splice(@tags, 0, $count)) . '</p>';
2156 sub git_get_project_url_list {
2159 $git_dir = "$projectroot/$path";
2160 open my $fd, "$git_dir/cloneurl"
2161 or return wantarray ?
2162 @{ config_to_multi(git_get_project_config('url')) } :
2163 config_to_multi(git_get_project_config('url'));
2164 my @git_project_url_list = map { chomp; $_ } <$fd>;
2167 return wantarray ? @git_project_url_list : \@git_project_url_list;
2170 sub git_get_projects_list {
2175 $filter =~ s/\.git$//;
2177 my $check_forks = gitweb_check_feature('forks');
2179 if (-d $projects_list) {
2180 # search in directory
2181 my $dir = $projects_list . ($filter ? "/$filter" : '');
2182 # remove the trailing "/"
2184 my $pfxlen = length("$dir");
2185 my $pfxdepth = ($dir =~ tr!/!!);
2188 follow_fast => 1, # follow symbolic links
2189 follow_skip => 2, # ignore duplicates
2190 dangling_symlinks => 0, # ignore dangling symlinks, silently
2192 # skip project-list toplevel, if we get it.
2193 return if (m!^[/.]$!);
2194 # only directories can be git repositories
2195 return unless (-d $_);
2196 # don't traverse too deep (Find is super slow on os x)
2197 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2198 $File::Find::prune = 1;
2202 my $subdir = substr($File::Find::name, $pfxlen + 1);
2203 # we check related file in $projectroot
2204 my $path = ($filter ? "$filter/" : '') . $subdir;
2205 if (check_export_ok("$projectroot/$path")) {
2206 push @list, { path => $path };
2207 $File::Find::prune = 1;
2212 } elsif (-f $projects_list) {
2213 # read from file(url-encoded):
2214 # 'git%2Fgit.git Linus+Torvalds'
2215 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2216 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2218 open my ($fd), $projects_list or return;
2220 while (my $line = <$fd>) {
2222 my ($path, $owner) = split ' ', $line;
2223 $path = unescape($path);
2224 $owner = unescape($owner);
2225 if (!defined $path) {
2228 if ($filter ne '') {
2229 # looking for forks;
2230 my $pfx = substr($path, 0, length($filter));
2231 if ($pfx ne $filter) {
2234 my $sfx = substr($path, length($filter));
2235 if ($sfx !~ /^\/.*\.git$/) {
2238 } elsif ($check_forks) {
2240 foreach my $filter (keys %paths) {
2241 # looking for forks;
2242 my $pfx = substr($path, 0, length($filter));
2243 if ($pfx ne $filter) {
2246 my $sfx = substr($path, length($filter));
2247 if ($sfx !~ /^\/.*\.git$/) {
2250 # is a fork, don't include it in
2255 if (check_export_ok("$projectroot/$path")) {
2258 owner => to_utf8($owner),
2261 (my $forks_path = $path) =~ s/\.git$//;
2262 $paths{$forks_path}++;
2270 our $gitweb_project_owner = undef;
2271 sub git_get_project_list_from_file {
2273 return if (defined $gitweb_project_owner);
2275 $gitweb_project_owner = {};
2276 # read from file (url-encoded):
2277 # 'git%2Fgit.git Linus+Torvalds'
2278 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2279 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2280 if (-f $projects_list) {
2281 open (my $fd , $projects_list);
2282 while (my $line = <$fd>) {
2284 my ($pr, $ow) = split ' ', $line;
2285 $pr = unescape($pr);
2286 $ow = unescape($ow);
2287 $gitweb_project_owner->{$pr} = to_utf8($ow);
2293 sub git_get_project_owner {
2294 my $project = shift;
2297 return undef unless $project;
2298 $git_dir = "$projectroot/$project";
2300 if (!defined $gitweb_project_owner) {
2301 git_get_project_list_from_file();
2304 if (exists $gitweb_project_owner->{$project}) {
2305 $owner = $gitweb_project_owner->{$project};
2307 if (!defined $owner){
2308 $owner = git_get_project_config('owner');
2310 if (!defined $owner) {
2311 $owner = get_file_owner("$git_dir");
2317 sub git_get_last_activity {
2321 $git_dir = "$projectroot/$path";
2322 open($fd, "-|", git_cmd(), 'for-each-ref',
2323 '--format=%(committer)',
2324 '--sort=-committerdate',
2326 'refs/heads') or return;
2327 my $most_recent = <$fd>;
2328 close $fd or return;
2329 if (defined $most_recent &&
2330 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2332 my $age = time - $timestamp;
2333 return ($age, age_string($age));
2335 return (undef, undef);
2338 sub git_get_references {
2339 my $type = shift || "";
2341 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2342 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2343 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
2344 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2347 while (my $line = <$fd>) {
2349 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2350 if (defined $refs{$1}) {
2351 push @{$refs{$1}}, $2;
2357 close $fd or return;
2361 sub git_get_rev_name_tags {
2362 my $hash = shift || return undef;
2364 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
2366 my $name_rev = <$fd>;
2369 if ($name_rev =~ m|^$hash tags/(.*)$|) {
2372 # catches also '$hash undefined' output
2377 ## ----------------------------------------------------------------------
2378 ## parse to hash functions
2382 my $tz = shift || "-0000";
2385 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2386 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2387 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2388 $date{'hour'} = $hour;
2389 $date{'minute'} = $min;
2390 $date{'mday'} = $mday;
2391 $date{'day'} = $days[$wday];
2392 $date{'month'} = $months[$mon];
2393 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2394 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2395 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2396 $mday, $months[$mon], $hour ,$min;
2397 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2398 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2400 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2401 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2402 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2403 $date{'hour_local'} = $hour;
2404 $date{'minute_local'} = $min;
2405 $date{'tz_local'} = $tz;
2406 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2407 1900+$year, $mon+1, $mday,
2408 $hour, $min, $sec, $tz);
2417 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
2418 $tag{'id'} = $tag_id;
2419 while (my $line = <$fd>) {
2421 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2422 $tag{'object'} = $1;
2423 } elsif ($line =~ m/^type (.+)$/) {
2425 } elsif ($line =~ m/^tag (.+)$/) {
2427 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2428 $tag{'author'} = $1;
2431 } elsif ($line =~ m/--BEGIN/) {
2432 push @comment, $line;
2434 } elsif ($line eq "") {
2438 push @comment, <$fd>;
2439 $tag{'comment'} = \@comment;
2440 close $fd or return;
2441 if (!defined $tag{'name'}) {
2447 sub parse_commit_text {
2448 my ($commit_text, $withparents) = @_;
2449 my @commit_lines = split '\n', $commit_text;
2452 pop @commit_lines; # Remove '\0'
2454 if (! @commit_lines) {
2458 my $header = shift @commit_lines;
2459 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2462 ($co{'id'}, my @parents) = split ' ', $header;
2463 while (my $line = shift @commit_lines) {
2464 last if $line eq "\n";
2465 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2467 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2469 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2471 $co{'author_epoch'} = $2;
2472 $co{'author_tz'} = $3;
2473 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2474 $co{'author_name'} = $1;
2475 $co{'author_email'} = $2;
2477 $co{'author_name'} = $co{'author'};
2479 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2480 $co{'committer'} = $1;
2481 $co{'committer_epoch'} = $2;
2482 $co{'committer_tz'} = $3;
2483 $co{'committer_name'} = $co{'committer'};
2484 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2485 $co{'committer_name'} = $1;
2486 $co{'committer_email'} = $2;
2488 $co{'committer_name'} = $co{'committer'};
2492 if (!defined $co{'tree'}) {
2495 $co{'parents'} = \@parents;
2496 $co{'parent'} = $parents[0];
2498 foreach my $title (@commit_lines) {
2501 $co{'title'} = chop_str($title, 80, 5);
2502 # remove leading stuff of merges to make the interesting part visible
2503 if (length($title) > 50) {
2504 $title =~ s/^Automatic //;
2505 $title =~ s/^merge (of|with) /Merge ... /i;
2506 if (length($title) > 50) {
2507 $title =~ s/(http|rsync):\/\///;
2509 if (length($title) > 50) {
2510 $title =~ s/(master|www|rsync)\.//;
2512 if (length($title) > 50) {
2513 $title =~ s/kernel.org:?//;
2515 if (length($title) > 50) {
2516 $title =~ s/\/pub\/scm//;
2519 $co{'title_short'} = chop_str($title, 50, 5);
2523 if (! defined $co{'title'} || $co{'title'} eq "") {
2524 $co{'title'} = $co{'title_short'} = '(no commit message)';
2526 # remove added spaces
2527 foreach my $line (@commit_lines) {
2530 $co{'comment'} = \@commit_lines;
2532 my $age = time - $co{'committer_epoch'};
2534 $co{'age_string'} = age_string($age);
2535 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2536 if ($age > 60*60*24*7*2) {
2537 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2538 $co{'age_string_age'} = $co{'age_string'};
2540 $co{'age_string_date'} = $co{'age_string'};
2541 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2547 my ($commit_id) = @_;
2552 open my $fd, "-|", git_cmd(), "rev-list",
2558 or die_error(500, "Open git-rev-list failed");
2559 %co = parse_commit_text(<$fd>, 1);
2566 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2574 open my $fd, "-|", git_cmd(), "rev-list",
2577 ("--max-count=" . $maxcount),
2578 ("--skip=" . $skip),
2582 ($filename ? ($filename) : ())
2583 or die_error(500, "Open git-rev-list failed");
2584 while (my $line = <$fd>) {
2585 my %co = parse_commit_text($line);
2590 return wantarray ? @cos : \@cos;
2593 # parse line of git-diff-tree "raw" output
2594 sub parse_difftree_raw_line {
2598 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2599 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2600 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2601 $res{'from_mode'} = $1;
2602 $res{'to_mode'} = $2;
2603 $res{'from_id'} = $3;
2605 $res{'status'} = $5;
2606 $res{'similarity'} = $6;
2607 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2608 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2610 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2613 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2614 # combined diff (for merge commit)
2615 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2616 $res{'nparents'} = length($1);
2617 $res{'from_mode'} = [ split(' ', $2) ];
2618 $res{'to_mode'} = pop @{$res{'from_mode'}};
2619 $res{'from_id'} = [ split(' ', $3) ];
2620 $res{'to_id'} = pop @{$res{'from_id'}};
2621 $res{'status'} = [ split('', $4) ];
2622 $res{'to_file'} = unquote($5);
2624 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2625 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2626 $res{'commit'} = $1;
2629 return wantarray ? %res : \%res;
2632 # wrapper: return parsed line of git-diff-tree "raw" output
2633 # (the argument might be raw line, or parsed info)
2634 sub parsed_difftree_line {
2635 my $line_or_ref = shift;
2637 if (ref($line_or_ref) eq "HASH") {
2638 # pre-parsed (or generated by hand)
2639 return $line_or_ref;
2641 return parse_difftree_raw_line($line_or_ref);
2645 # parse line of git-ls-tree output
2646 sub parse_ls_tree_line ($;%) {
2651 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2652 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2660 $res{'name'} = unquote($4);
2663 return wantarray ? %res : \%res;
2666 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2667 sub parse_from_to_diffinfo {
2668 my ($diffinfo, $from, $to, @parents) = @_;
2670 if ($diffinfo->{'nparents'}) {
2672 $from->{'file'} = [];
2673 $from->{'href'} = [];
2674 fill_from_file_info($diffinfo, @parents)
2675 unless exists $diffinfo->{'from_file'};
2676 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2677 $from->{'file'}[$i] =
2678 defined $diffinfo->{'from_file'}[$i] ?
2679 $diffinfo->{'from_file'}[$i] :
2680 $diffinfo->{'to_file'};
2681 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2682 $from->{'href'}[$i] = href(action=>"blob",
2683 hash_base=>$parents[$i],
2684 hash=>$diffinfo->{'from_id'}[$i],
2685 file_name=>$from->{'file'}[$i]);
2687 $from->{'href'}[$i] = undef;
2691 # ordinary (not combined) diff
2692 $from->{'file'} = $diffinfo->{'from_file'};
2693 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2694 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2695 hash=>$diffinfo->{'from_id'},
2696 file_name=>$from->{'file'});
2698 delete $from->{'href'};
2702 $to->{'file'} = $diffinfo->{'to_file'};
2703 if (!is_deleted($diffinfo)) { # file exists in result
2704 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2705 hash=>$diffinfo->{'to_id'},
2706 file_name=>$to->{'file'});
2708 delete $to->{'href'};
2712 ## ......................................................................
2713 ## parse to array of hashes functions
2715 sub git_get_heads_list {
2719 open my $fd, '-|', git_cmd(), 'for-each-ref',
2720 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2721 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2724 while (my $line = <$fd>) {
2728 my ($refinfo, $committerinfo) = split(/\0/, $line);
2729 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2730 my ($committer, $epoch, $tz) =
2731 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2732 $ref_item{'fullname'} = $name;
2733 $name =~ s!^refs/heads/!!;
2735 $ref_item{'name'} = $name;
2736 $ref_item{'id'} = $hash;
2737 $ref_item{'title'} = $title || '(no commit message)';
2738 $ref_item{'epoch'} = $epoch;
2740 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2742 $ref_item{'age'} = "unknown";
2745 push @headslist, \%ref_item;
2749 return wantarray ? @headslist : \@headslist;
2752 sub git_get_tags_list {
2756 open my $fd, '-|', git_cmd(), 'for-each-ref',
2757 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2758 '--format=%(objectname) %(objecttype) %(refname) '.
2759 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2762 while (my $line = <$fd>) {
2766 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2767 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2768 my ($creator, $epoch, $tz) =
2769 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2770 $ref_item{'fullname'} = $name;
2771 $name =~ s!^refs/tags/!!;
2773 $ref_item{'type'} = $type;
2774 $ref_item{'id'} = $id;
2775 $ref_item{'name'} = $name;
2776 if ($type eq "tag") {
2777 $ref_item{'subject'} = $title;
2778 $ref_item{'reftype'} = $reftype;
2779 $ref_item{'refid'} = $refid;
2781 $ref_item{'reftype'} = $type;
2782 $ref_item{'refid'} = $id;
2785 if ($type eq "tag" || $type eq "commit") {
2786 $ref_item{'epoch'} = $epoch;
2788 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2790 $ref_item{'age'} = "unknown";
2794 push @tagslist, \%ref_item;
2798 return wantarray ? @tagslist : \@tagslist;
2801 ## ----------------------------------------------------------------------
2802 ## filesystem-related functions
2804 sub get_file_owner {
2807 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2808 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2809 if (!defined $gcos) {
2813 $owner =~ s/[,;].*$//;
2814 return to_utf8($owner);
2817 # assume that file exists
2819 my $filename = shift;
2821 open my $fd, '<', $filename;
2822 return join '', map to_utf8($_), <$fd>;
2825 ## ......................................................................
2826 ## mimetype related functions
2828 sub mimetype_guess_file {
2829 my $filename = shift;
2830 my $mimemap = shift;
2831 -r $mimemap or return undef;
2834 open(MIME, $mimemap) or return undef;
2836 next if m/^#/; # skip comments
2837 my ($mime, $exts) = split(/\t+/);
2838 if (defined $exts) {
2839 my @exts = split(/\s+/, $exts);
2840 foreach my $ext (@exts) {
2841 $mimemap{$ext} = $mime;
2847 $filename =~ /\.([^.]*)$/;
2848 return $mimemap{$1};
2851 sub mimetype_guess {
2852 my $filename = shift;
2854 $filename =~ /\./ or return undef;
2856 if ($mimetypes_file) {
2857 my $file = $mimetypes_file;
2858 if ($file !~ m!^/!) { # if it is relative path
2859 # it is relative to project
2860 $file = "$projectroot/$project/$file";
2862 $mime = mimetype_guess_file($filename, $file);
2864 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2870 my $filename = shift;
2873 my $mime = mimetype_guess($filename);
2874 $mime and return $mime;
2878 return $default_blob_plain_mimetype unless $fd;
2881 return 'text/plain';
2882 } elsif (! $filename) {
2883 return 'application/octet-stream';
2884 } elsif ($filename =~ m/\.png$/i) {
2886 } elsif ($filename =~ m/\.gif$/i) {
2888 } elsif ($filename =~ m/\.jpe?g$/i) {
2889 return 'image/jpeg';
2891 return 'application/octet-stream';
2895 sub blob_contenttype {
2896 my ($fd, $file_name, $type) = @_;
2898 $type ||= blob_mimetype($fd, $file_name);
2899 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2900 $type .= "; charset=$default_text_plain_charset";
2906 ## ======================================================================
2907 ## functions printing HTML: header, footer, error page
2909 sub git_header_html {
2910 # XXX These aren't used, how odd.
2911 my $status = shift || "200 OK";
2912 my $expires = shift;
2914 my $title = "$site_name";
2915 if (defined $project) {
2916 $title .= " - " . to_utf8($project);
2917 if (defined $action) {
2918 $title .= "/$action";
2919 if (defined $file_name) {
2920 $title .= " - " . esc_path($file_name);
2921 if ($action eq "tree" && $file_name !~ m|/$|) {
2928 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2930 $c->stash->{version} = $version;
2931 $c->stash->{git_version} = $git_version;
2932 $c->stash->{mod_perl_version} = $mod_perl_version;
2933 $c->stash->{title} = $title;
2935 # the stylesheet, favicon etc urls won't work correctly with path_info
2936 # unless we set the appropriate base URL
2937 $c->stash->{baseurl} = $ENV{PATH_INFO}
2938 ? q[<base href="].esc_url($base_url).q[" />]
2941 # print out each stylesheet that exist, providing backwards capability
2942 # for those people who defined $stylesheet in a config file
2943 my $ssfmt = q[<link rel="stylesheet" type="text/css" href="%s"/>];
2944 $c->stash->{stylesheets} = [defined $stylesheet
2945 ? sprintf($ssfmt, $stylesheet)
2946 : map(sprintf($ssfmt, $_), grep $_, @stylesheets)
2949 $c->stash->{project} = defined $project;
2950 if (defined $project) {
2951 my %href_params = get_feed_info();
2952 if (!exists $href_params{'-title'}) {
2953 $href_params{'-title'} = 'log';
2956 foreach my $format qw(RSS Atom) {
2957 my $type = lc($format);
2959 '-rel' => 'alternate',
2960 '-title' => "$project - $href_params{'-title'} - $format feed",
2961 '-type' => "application/$type+xml"
2964 $href_params{'action'} = $type;
2965 $link_attr{'-href'} = href(%href_params);
2966 $c->stash->{lc $format.'_link'} = "<link ".
2967 "rel=\"$link_attr{'-rel'}\" ".
2968 "title=\"$link_attr{'-title'}\" ".
2969 "href=\"$link_attr{'-href'}\" ".
2970 "type=\"$link_attr{'-type'}\" ".
2973 $href_params{'extra_options'} = '--no-merges';
2974 $link_attr{'-href'} = href(%href_params);
2975 $link_attr{'-title'} .= ' (no merges)';
2976 $c->stash->{lc $format.'_link_no_merges'} = "<link ".
2977 "rel=\"$link_attr{'-rel'}\" ".
2978 "title=\"$link_attr{'-title'}\" ".
2979 "href=\"$link_attr{'-href'}\" ".
2980 "type=\"$link_attr{'-type'}\" ".
2985 $c->stash->{projects_list} = sprintf('<link rel="alternate" title="%s projects list" '.
2986 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2987 $site_name, href(project=>undef, action=>"project_index"));
2988 $c->stash->{projects_feed} = sprintf('<link rel="alternate" title="%s projects feeds" '.
2989 'href="%s" type="text/x-opml" />'."\n",
2990 $site_name, href(project=>undef, action=>"opml"));
2993 $c->stash->{favicon} = defined $favicon
2994 ? qq(<link rel="shortcut icon" href="$favicon" type="image/png" />)
2999 $c->stash->{site_header} = -f $site_header
3000 ? insert_file($site_header)
3004 = $cgi->a({-href => esc_url($logo_url),
3005 -title => $logo_label},
3006 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3007 $c->stash->{home_link} = $cgi->a({-href => esc_url($home_link)}, $home_link_str);
3009 if(defined $project) {
3010 $c->stash->{summary} = $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3011 $c->stash->{action} = $action;
3014 my $have_search = $c->stash->{have_search} = gitweb_check_feature('search');
3015 if (defined $project && $have_search) {
3016 if (!defined $searchtext) {
3020 if (defined $hash_base) {
3021 $search_hash = $hash_base;
3022 } elsif (defined $hash) {
3023 $search_hash = $hash;
3025 $search_hash = "HEAD";
3027 my $action = $my_uri;
3028 my $use_pathinfo = gitweb_check_feature('pathinfo');
3029 if ($use_pathinfo) {
3030 $action .= "/".esc_url($project);
3032 # This could be done better, but meh.
3033 $c->stash->{search_form} = $cgi->startform(-method => "get", -action => $action) .
3035 $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3036 $cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3037 $cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3038 $cgi->popup_menu(-name => 'st', -default => 'commit',
3039 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3040 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3042 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3043 "<span title=\"Extended regular expression\">" .
3044 $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3045 -checked => $search_use_regexp) .
3047 $cgi->end_form() . "\n";
3051 sub git_footer_html {
3052 my $feed_class = 'rss_logo';
3054 if (defined $project) {
3055 my $descr = git_get_project_description($project);
3056 $c->stash->{project_description} = defined $descr
3060 my %href_params = get_feed_info();
3061 if (!%href_params) {
3062 $feed_class .= ' generic';
3064 $href_params{'-title'} ||= 'log';
3066 foreach my $format qw(RSS Atom) {
3067 $href_params{'action'} = lc($format);
3068 $c->stash->{lc $format.'_feed'} = $cgi->a({-href => href(%href_params),
3069 -title => "$href_params{'-title'} $format feed",
3070 -class => $feed_class}, $format);
3074 $c->stash->{opml_feed} = $cgi->a({-href => href(project=>undef, action=>"opml"),
3075 -class => $feed_class}, "OPML");
3076 $c->stash->{index_feed} = $cgi->a({-href => href(project=>undef, action=>"project_index"),
3077 -class => $feed_class}, "TXT");
3080 $c->stash->{site_footer} = -f $site_footer
3081 ? insert_file($site_footer)
3085 # die_error(<http_status_code>, <error_message>)
3086 # Example: die_error(404, 'Hash not found')
3087 # By convention, use the following status codes (as defined in RFC 2616):
3088 # 400: Invalid or missing CGI parameters, or
3089 # requested object exists but has wrong type.
3090 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3091 # this server or project.
3092 # 404: Requested object/revision/project doesn't exist.
3093 # 500: The server isn't configured properly, or
3094 # an internal error occurred (e.g. failed assertions caused by bugs), or
3095 # an unknown error occurred (e.g. the git binary died unexpectedly).
3097 my $status = shift || 500;
3098 my $error = shift || "Internal server error";
3100 my %http_responses = (400 => '400 Bad Request',
3101 403 => '403 Forbidden',
3102 404 => '404 Not Found',
3103 500 => '500 Internal Server Error');
3104 $c->response->status($http_responses{$status});
3106 $c->stash->{content} = <<EOF;
3107 <div class="page_body">
3116 ## ----------------------------------------------------------------------
3117 ## functions printing or outputting HTML: navigation
3119 sub git_print_page_nav {
3120 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3121 $extra = '' if !defined $extra; # pager or formats
3123 my @navs = qw(summary shortlog log commit commitdiff tree);
3125 @navs = grep { $_ ne $suppress } @navs;
3128 my %arg = map { $_ => {action=>$_} } @navs;
3129 if (defined $head) {
3130 for (qw(commit commitdiff)) {
3131 $arg{$_}{'hash'} = $head;
3133 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3134 for (qw(shortlog log)) {
3135 $arg{$_}{'hash'} = $head;
3140 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3141 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3143 my @actions = gitweb_get_feature('actions');
3146 'n' => $project, # project name
3147 'f' => $git_dir, # project path within filesystem
3148 'h' => $treehead || '', # current hash ('h' parameter)
3149 'b' => $treebase || '', # hash base ('hb' parameter)
3152 my ($label, $link, $pos) = splice(@actions,0,3);
3154 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3156 $link =~ s/%([%nfhb])/$repl{$1}/g;
3157 $arg{$label}{'_href'} = $link;
3160 $c->stash->{page_nav} = 1;
3161 $c->stash->{nav_links} =
3163 map { $_ eq $current ?
3164 $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
3166 $c->stash->{extra} = $extra;
3169 sub format_paging_nav {
3170 my ($action, $hash, $head, $page, $has_next_link) = @_;
3174 if ($hash ne $head || $page) {
3175 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
3177 $paging_nav .= "HEAD";
3181 $paging_nav .= " ⋅ " .
3182 $cgi->a({-href => href(-replay=>1, page=>$page-1),
3183 -accesskey => "p", -title => "Alt-p"}, "prev");
3185 $paging_nav .= " ⋅ prev";
3188 if ($has_next_link) {
3189 $paging_nav .= " ⋅ " .
3190 $cgi->a({-href => href(-replay=>1, page=>$page+1),
3191 -accesskey => "n", -title => "Alt-n"}, "next");
3193 $paging_nav .= " ⋅ next";
3199 ## ......................................................................
3200 ## functions printing or outputting HTML: div
3202 sub git_print_header_div {
3203 my ($action, $title, $hash, $hash_base) = @_;
3206 $args{'action'} = $action;
3207 $args{'hash'} = $hash if $hash;
3208 $args{'hash_base'} = $hash_base if $hash_base;
3210 print q[<div class="header">],
3211 $cgi->a({-href => href(%args), -class => "title"},
3212 $title ? $title : $action),
3216 sub git_print_authorship {
3219 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3220 print "<div class=\"author_date\">" .
3221 esc_html($co->{'author_name'}) .
3223 if ($ad{'hour_local'} < 6) {
3224 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3225 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3227 printf(" (%02d:%02d %s)",
3228 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3233 sub git_print_page_path {
3239 print "<div class=\"page_path\">";
3240 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
3241 -title => 'tree root'}, to_utf8("[$project]"));
3243 if (defined $name) {
3244 my @dirname = split '/', $name;
3245 my $basename = pop @dirname;
3248 foreach my $dir (@dirname) {
3249 $fullname .= ($fullname ? '/' : '') . $dir;
3250 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
3252 -title => $fullname}, esc_path($dir));
3255 if (defined $type && $type eq 'blob') {
3256 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
3258 -title => $name}, esc_path($basename));
3259 } elsif (defined $type && $type eq 'tree') {
3260 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
3262 -title => $name}, esc_path($basename));
3265 print esc_path($basename);
3268 print "<br/></div>\n";
3271 # sub git_print_log (\@;%) {
3272 sub git_print_log ($;%) {
3276 if ($opts{'-remove_title'}) {
3277 # remove title, i.e. first line of log
3280 # remove leading empty lines
3281 while (defined $log->[0] && $log->[0] eq "") {
3288 foreach my $line (@$log) {
3289 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3292 if (! $opts{'-remove_signoff'}) {
3293 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
3296 # remove signoff lines
3303 # print only one empty line
3304 # do not print empty line after signoff
3306 next if ($empty || $signoff);
3312 print format_log_line_html($line) . "<br/>\n";
3315 if ($opts{'-final_empty_line'}) {
3316 # end with single empty line
3317 print "<br/>\n" unless $empty;
3321 # return link target (what link points to)
3322 sub git_get_link_target {
3327 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3331 $link_target = <$fd>;
3336 return $link_target;
3339 # given link target, and the directory (basedir) the link is in,
3340 # return target of link relative to top directory (top tree);
3341 # return undef if it is not possible (including absolute links).
3342 sub normalize_link_target {
3343 my ($link_target, $basedir, $hash_base) = @_;
3345 # we can normalize symlink target only if $hash_base is provided
3346 return unless $hash_base;
3348 # absolute symlinks (beginning with '/') cannot be normalized
3349 return if (substr($link_target, 0, 1) eq '/');
3351 # normalize link target to path from top (root) tree (dir)
3354 $path = $basedir . '/' . $link_target;
3356 # we are in top (root) tree (dir)
3357 $path = $link_target;
3360 # remove //, /./, and /../
3362 foreach my $part (split('/', $path)) {
3363 # discard '.' and ''
3364 next if (!$part || $part eq '.');
3366 if ($part eq '..') {
3370 # link leads outside repository (outside top dir)
3374 push @path_parts, $part;
3377 $path = join('/', @path_parts);
3382 # print tree entry (row of git_tree), but without encompassing <tr> element
3383 sub git_print_tree_entry {
3384 my ($t, $basedir, $hash_base, $have_blame) = @_;
3387 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3389 # The format of a table row is: mode list link. Where mode is
3390 # the mode of the entry, list is the name of the entry, an href,
3391 # and link is the action links of the entry.
3393 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
3394 if ($t->{'type'} eq "blob") {
3395 print "<td class=\"list\">" .
3396 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3397 file_name=>"$basedir$t->{'name'}", %base_key),
3398 -class => "list"}, esc_path($t->{'name'}));
3399 if (S_ISLNK(oct $t->{'mode'})) {
3400 my $link_target = git_get_link_target($t->{'hash'});
3402 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
3403 if (defined $norm_target) {
3405 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
3406 file_name=>$norm_target),
3407 -title => $norm_target}, esc_path($link_target));
3409 print " -> " . esc_path($link_target);
3414 print "<td class=\"link\">";
3415 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3416 file_name=>"$basedir$t->{'name'}", %base_key)},
3420 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
3421 file_name=>"$basedir$t->{'name'}", %base_key)},
3424 if (defined $hash_base) {
3426 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3427 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
3431 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
3432 file_name=>"$basedir$t->{'name'}")},
3436 } elsif ($t->{'type'} eq "tree") {
3437 print "<td class=\"list\">";
3438 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3439 file_name=>"$basedir$t->{'name'}", %base_key)},
3440 esc_path($t->{'name'}));
3442 print "<td class=\"link\">";
3443 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3444 file_name=>"$basedir$t->{'name'}", %base_key)},
3446 if (defined $hash_base) {
3448 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3449 file_name=>"$basedir$t->{'name'}")},
3454 # unknown object: we can only present history for it
3455 # (this includes 'commit' object, i.e. submodule support)
3456 print "<td class=\"list\">" .
3457 esc_path($t->{'name'}) .
3459 print "<td class=\"link\">";
3460 if (defined $hash_base) {
3461 print $cgi->a({-href => href(action=>"history",
3462 hash_base=>$hash_base,
3463 file_name=>"$basedir$t->{'name'}")},
3470 ## ......................................................................
3471 ## functions printing large fragments of HTML
3473 # get pre-image filenames for merge (combined) diff
3474 sub fill_from_file_info {
3475 my ($diff, @parents) = @_;
3477 $diff->{'from_file'} = [ ];
3478 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3479 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3480 if ($diff->{'status'}[$i] eq 'R' ||
3481 $diff->{'status'}[$i] eq 'C') {
3482 $diff->{'from_file'}[$i] =
3483 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
3490 # is current raw difftree line of file deletion
3492 my $diffinfo = shift;
3494 return $diffinfo->{'to_id'} eq ('0' x 40);
3497 # does patch correspond to [previous] difftree raw line
3498 # $diffinfo - hashref of parsed raw diff format
3499 # $patchinfo - hashref of parsed patch diff format
3500 # (the same keys as in $diffinfo)
3501 sub is_patch_split {
3502 my ($diffinfo, $patchinfo) = @_;
3504 return defined $diffinfo && defined $patchinfo
3505 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3509 sub git_difftree_body {
3510 my ($difftree, $hash, @parents) = @_;
3511 my ($parent) = $parents[0];
3512 my $have_blame = gitweb_check_feature('blame');
3513 print "<div class=\"list_head\">\n";
3514 if ($#{$difftree} > 10) {
3515 print(($#{$difftree} + 1) . " files changed:\n");
3519 print "<table class=\"" .
3520 (@parents > 1 ? "combined " : "") .
3523 # header only for combined diff in 'commitdiff' view
3524 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3527 print "<thead><tr>\n" .
3528 "<th></th><th></th>\n"; # filename, patchN link
3529 for (my $i = 0; $i < @parents; $i++) {
3530 my $par = $parents[$i];
3532 $cgi->a({-href => href(action=>"commitdiff",
3533 hash=>$hash, hash_parent=>$par),
3534 -title => 'commitdiff to parent number ' .
3535 ($i+1) . ': ' . substr($par,0,7)},
3539 print "</tr></thead>\n<tbody>\n";
3544 foreach my $line (@{$difftree}) {
3545 my $diff = parsed_difftree_line($line);
3548 print "<tr class=\"dark\">\n";
3550 print "<tr class=\"light\">\n";
3554 if (exists $diff->{'nparents'}) { # combined diff
3556 fill_from_file_info($diff, @parents)
3557 unless exists $diff->{'from_file'};
3559 if (!is_deleted($diff)) {
3560 # file exists in the result (child) commit
3562 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3563 file_name=>$diff->{'to_file'},
3565 -class => "list"}, esc_path($diff->{'to_file'})) .
3569 esc_path($diff->{'to_file'}) .
3573 if ($action eq 'commitdiff') {
3576 print "<td class=\"link\">" .
3577 $cgi->a({-href => "#patch$patchno"}, "patch") .
3582 my $has_history = 0;
3583 my $not_deleted = 0;
3584 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3585 my $hash_parent = $parents[$i];
3586 my $from_hash = $diff->{'from_id'}[$i];
3587 my $from_path = $diff->{'from_file'}[$i];
3588 my $status = $diff->{'status'}[$i];
3590 $has_history ||= ($status ne 'A');
3591 $not_deleted ||= ($status ne 'D');
3593 if ($status eq 'A') {
3594 print "<td class=\"link\" align=\"right\"> | </td>\n";
3595 } elsif ($status eq 'D') {
3596 print "<td class=\"link\">" .
3597 $cgi->a({-href => href(action=>"blob",
3600 file_name=>$from_path)},
3604 if ($diff->{'to_id'} eq $from_hash) {
3605 print "<td class=\"link nochange\">";
3607 print "<td class=\"link\">";
3609 print $cgi->a({-href => href(action=>"blobdiff",
3610 hash=>$diff->{'to_id'},
3611 hash_parent=>$from_hash,
3613 hash_parent_base=>$hash_parent,
3614 file_name=>$diff->{'to_file'},
3615 file_parent=>$from_path)},
3621 print "<td class=\"link\">";
3623 print $cgi->a({-href => href(action=>"blob",
3624 hash=>$diff->{'to_id'},
3625 file_name=>$diff->{'to_file'},
3628 print " | " if ($has_history);
3631 print $cgi->a({-href => href(action=>"history",
3632 file_name=>$diff->{'to_file'},
3639 next; # instead of 'else' clause, to avoid extra indent
3641 # else ordinary diff
3643 my ($to_mode_oct, $to_mode_str, $to_file_type);
3644 my ($from_mode_oct, $from_mode_str, $from_file_type);
3645 if ($diff->{'to_mode'} ne ('0' x 6)) {
3646 $to_mode_oct = oct $diff->{'to_mode'};
3647 if (S_ISREG($to_mode_oct)) { # only for regular file
3648 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3650 $to_file_type = file_type($diff->{'to_mode'});
3652 if ($diff->{'from_mode'} ne ('0' x 6)) {
3653 $from_mode_oct = oct $diff->{'from_mode'};
3654 if (S_ISREG($to_mode_oct)) { # only for regular file
3655 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3657 $from_file_type = file_type($diff->{'from_mode'});
3660 if ($diff->{'status'} eq "A") { # created
3661 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3662 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3663 $mode_chng .= "]</span>";
3665 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3666 hash_base=>$hash, file_name=>$diff->{'file'}),
3667 -class => "list"}, esc_path($diff->{'file'}));
3669 print "<td>$mode_chng</td>\n";
3670 print "<td class=\"link\">";
3671 if ($action eq 'commitdiff') {
3674 print $cgi->a({-href => "#patch$patchno"}, "patch");
3677 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3678 hash_base=>$hash, file_name=>$diff->{'file'})},
3682 } elsif ($diff->{'status'} eq "D") { # deleted
3683 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3685 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3686 hash_base=>$parent, file_name=>$diff->{'file'}),
3687 -class => "list"}, esc_path($diff->{'file'}));
3689 print "<td>$mode_chng</td>\n";
3690 print "<td class=\"link\">";
3691 if ($action eq 'commitdiff') {
3694 print $cgi->a({-href => "#patch$patchno"}, "patch");
3697 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3698 hash_base=>$parent, file_name=>$diff->{'file'})},
3701 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3702 file_name=>$diff->{'file'})},
3705 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3706 file_name=>$diff->{'file'})},
3710 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3711 my $mode_chnge = "";
3712 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3713 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3714 if ($from_file_type ne $to_file_type) {
3715 $mode_chnge .= " from $from_file_type to $to_file_type";
3717 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3718 if ($from_mode_str && $to_mode_str) {
3719 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3720 } elsif ($to_mode_str) {
3721 $mode_chnge .= " mode: $to_mode_str";
3724 $mode_chnge .= "]</span>\n";
3727 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3728 hash_base=>$hash, file_name=>$diff->{'file'}),
3729 -class => "list"}, esc_path($diff->{'file'}));
3731 print "<td>$mode_chnge</td>\n";
3732 print "<td class=\"link\">";
3733 if ($action eq 'commitdiff') {
3736 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3738 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3739 # "commit" view and modified file (not onlu mode changed)
3740 print $cgi->a({-href => href(action=>"blobdiff",
3741 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3742 hash_base=>$hash, hash_parent_base=>$parent,
3743 file_name=>$diff->{'file'})},
3747 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3748 hash_base=>$hash, file_name=>$diff->{'file'})},
3751 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3752 file_name=>$diff->{'file'})},
3755 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3756 file_name=>$diff->{'file'})},
3760 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3761 my %status_name = ('R' => 'moved', 'C' => 'copied');
3762 my $nstatus = $status_name{$diff->{'status'}};
3764 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3765 # mode also for directories, so we cannot use $to_mode_str
3766 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3769 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3770 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3771 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3772 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3773 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3774 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3775 -class => "list"}, esc_path($diff->{'from_file'})) .
3776 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3777 "<td class=\"link\">";
3778 if ($action eq 'commitdiff') {
3781 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3783 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3784 # "commit" view and modified file (not only pure rename or copy)
3785 print $cgi->a({-href => href(action=>"blobdiff",
3786 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3787 hash_base=>$hash, hash_parent_base=>$parent,
3788 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3792 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3793 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3796 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3797 file_name=>$diff->{'to_file'})},
3800 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3801 file_name=>$diff->{'to_file'})},
3805 } # we should not encounter Unmerged (U) or Unknown (X) status
3808 print "</tbody>" if $has_header;
3812 sub git_patchset_body {
3813 my ($fd, $difftree, $hash, @hash_parents) = @_;
3814 my ($hash_parent) = $hash_parents[0];
3816 my $is_combined = (@hash_parents > 1);
3818 my $patch_number = 0;
3824 print "<div class=\"patchset\">\n";
3826 # skip to first patch
3827 while ($patch_line = <$fd>) {
3830 last if ($patch_line =~ m/^diff /);
3834 while ($patch_line) {
3836 # parse "git diff" header line
3837 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3838 # $1 is from_name, which we do not use
3839 $to_name = unquote($2);
3840 $to_name =~ s!^b/!!;
3841 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3842 # $1 is 'cc' or 'combined', which we do not use
3843 $to_name = unquote($2);
3848 # check if current patch belong to current raw line
3849 # and parse raw git-diff line if needed
3850 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
3851 # this is continuation of a split patch
3852 print "<div class=\"patch cont\">\n";
3854 # advance raw git-diff output if needed
3855 $patch_idx++ if defined $diffinfo;
3857 # read and prepare patch information
3858 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3860 # compact combined diff output can have some patches skipped
3861 # find which patch (using pathname of result) we are at now;
3863 while ($to_name ne $diffinfo->{'to_file'}) {
3864 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3865 format_diff_cc_simplified($diffinfo, @hash_parents) .
3866 "</div>\n"; # class="patch"
3871 last if $patch_idx > $#$difftree;
3872 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3876 # modifies %from, %to hashes
3877 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3879 # this is first patch for raw difftree line with $patch_idx index
3880 # we index @$difftree array from 0, but number patches from 1
3881 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3885 #assert($patch_line =~ m/^diff /) if DEBUG;
3886 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3888 # print "git diff" header
3889 print format_git_diff_header_line($patch_line, $diffinfo,
3892 # print extended diff header
3893 print "<div class=\"diff extended_header\">\n";
3895 while ($patch_line = <$fd>) {
3898 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
3900 print format_extended_diff_header_line($patch_line, $diffinfo,
3903 print "</div>\n"; # class="diff extended_header"
3905 # from-file/to-file diff header
3906 if (! $patch_line) {
3907 print "</div>\n"; # class="patch"
3910 next PATCH if ($patch_line =~ m/^diff /);
3911 #assert($patch_line =~ m/^---/) if DEBUG;
3913 my $last_patch_line = $patch_line;
3914 $patch_line = <$fd>;
3916 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3918 print format_diff_from_to_header($last_patch_line, $patch_line,
3919 $diffinfo, \%from, \%to,
3924 while ($patch_line = <$fd>) {
3927 next PATCH if ($patch_line =~ m/^diff /);
3929 print format_diff_line($patch_line, \%from, \%to);
3933 print "</div>\n"; # class="patch"
3936 # for compact combined (--cc) format, with chunk and patch simpliciaction
3937 # patchset might be empty, but there might be unprocessed raw lines
3938 for (++$patch_idx if $patch_number > 0;
3939 $patch_idx < @$difftree;
3941 # read and prepare patch information
3942 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3944 # generate anchor for "patch" links in difftree / whatchanged part
3945 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3946 format_diff_cc_simplified($diffinfo, @hash_parents) .
3947 "</div>\n"; # class="patch"
3952 if ($patch_number == 0) {
3953 if (@hash_parents > 1) {
3954 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3956 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3960 print "</div>\n"; # class="patchset"
3963 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3965 # fills project list info (age, description, owner, forks) for each
3966 # project in the list, removing invalid projects from returned list
3967 # NOTE: modifies $projlist, but does not remove entries from it
3968 sub fill_project_list_info {
3969 my ($projlist, $check_forks) = @_;
3972 my $show_ctags = gitweb_check_feature('ctags');
3974 foreach my $pr (@$projlist) {
3975 my (@activity) = git_get_last_activity($pr->{'path'});
3976 unless (@activity) {
3979 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3980 if (!defined $pr->{'descr'}) {
3981 my $descr = git_get_project_description($pr->{'path'}) || "";
3982 $descr = to_utf8($descr);
3983 $pr->{'descr_long'} = $descr;
3984 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3986 if (!defined $pr->{'owner'}) {
3987 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
3990 my $pname = $pr->{'path'};
3991 if (($pname =~ s/\.git$//) &&
3992 ($pname !~ /\/$/) &&
3993 (-d "$projectroot/$pname")) {
3994 $pr->{'forks'} = "-d $projectroot/$pname";
3999 $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
4000 push @projects, $pr;
4006 # print 'sort by' <th> element, generating 'sort by $name' replay link
4007 # if that order is not selected
4009 my ($name, $order, $header) = @_;
4010 $header ||= ucfirst($name);
4012 if ($order eq $name) {
4013 print "<th>$header</th>\n";
4016 $cgi->a({-href => href(-replay=>1, order=>$name),
4017 -class => "header"}, $header) .
4022 sub git_project_list_body {
4023 # actually uses global variable $project
4024 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4026 my $check_forks = gitweb_check_feature('forks');
4027 my @projects = fill_project_list_info($projlist, $check_forks);
4029 $order ||= $default_projects_order;
4030 $from = 0 unless defined $from;
4031 $to = $#projects if (!defined $to || $#projects < $to);
4034 project => { key => 'path', type => 'str' },
4035 descr => { key => 'descr_long', type => 'str' },
4036 owner => { key => 'owner', type => 'str' },
4037 age => { key => 'age', type => 'num' }
4039 my $oi = $order_info{$order};
4040 if ($oi->{'type'} eq 'str') {
4041 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4043 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4046 my $show_ctags = gitweb_check_feature('ctags');
4049 foreach my $p (@projects) {
4050 foreach my $ct (keys %{$p->{'ctags'}}) {
4051 $ctags{$ct} += $p->{'ctags'}->{$ct};
4054 my $cloud = git_populate_project_tagcloud(\%ctags);
4055 print git_show_project_tagcloud($cloud, 64);
4058 print "<table class=\"project_list\">\n";
4059 unless ($no_header) {
4062 print "<th></th>\n";
4064 print_sort_th('project', $order, 'Project');
4065 print_sort_th('descr', $order, 'Description');
4066 print_sort_th('owner', $order, 'Owner');
4067 print_sort_th('age', $order, 'Last Change');
4068 print "<th></th>\n" . # for links
4072 my $tagfilter = $c->req->param('by_tag');
4073 for (my $i = $from; $i <= $to; $i++) {
4074 my $pr = $projects[$i];
4076 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4077 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4078 and not $pr->{'descr_long'} =~ /$searchtext/;
4079 # Weed out forks or non-matching entries of search
4081 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
4082 $forkbase="^$forkbase" if $forkbase;
4083 next if not $searchtext and not $tagfilter and $show_ctags
4084 and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
4088 print "<tr class=\"dark\">\n";
4090 print "<tr class=\"light\">\n";
4095 if ($pr->{'forks'}) {
4096 print "<!-- $pr->{'forks'} -->\n";
4097 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
4101 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4102 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
4103 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4104 -class => "list", -title => $pr->{'descr_long'}},
4105 esc_html($pr->{'descr'})) . "</td>\n" .
4106 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
4107 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
4108 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4109 "<td class=\"link\">" .
4110 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
4111 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
4112 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
4113 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
4114 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
4118 if (defined $extra) {
4121 print "<td></td>\n";
4123 print "<td colspan=\"5\">$extra</td>\n" .
4129 sub git_shortlog_body {
4130 # uses global variable $project
4131 my ($commitlist, $from, $to, $refs, $extra) = @_;
4133 $from = 0 unless defined $from;
4134 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4136 print "<table class=\"shortlog\">\n";
4138 for (my $i = $from; $i <= $to; $i++) {
4139 my %co = %{$commitlist->[$i]};
4140 my $commit = $co{'id'};
4141 my $ref = format_ref_marker($refs, $commit);
4143 print "<tr class=\"dark\">\n";
4145 print "<tr class=\"light\">\n";
4148 my $author = chop_and_escape_str($co{'author_name'}, 10);
4149 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4150 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4151 "<td><i>" . $author . "</i></td>\n" .
4153 print format_subject_html($co{'title'}, $co{'title_short'},
4154 href(action=>"commit", hash=>$commit), $ref);
4156 "<td class=\"link\">" .
4157 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
4158 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
4159 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
4160 my $snapshot_links = format_snapshot_links($commit);
4161 if (defined $snapshot_links) {
4162 print " | " . $snapshot_links;
4167 if (defined $extra) {
4169 "<td colspan=\"4\">$extra</td>\n" .
4175 sub git_history_body {
4176 # Warning: assumes constant type (blob or tree) during history
4177 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4179 $from = 0 unless defined $from;
4180 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4182 print "<table class=\"history\">\n";
4184 for (my $i = $from; $i <= $to; $i++) {
4185 my %co = %{$commitlist->[$i]};
4189 my $commit = $co{'id'};
4191 my $ref = format_ref_marker($refs, $commit);
4194 print "<tr class=\"dark\">\n";
4196 print "<tr class=\"light\">\n";
4199 # shortlog uses chop_str($co{'author_name'}, 10)
4200 my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
4201 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4202 "<td><i>" . $author . "</i></td>\n" .
4204 # originally git_history used chop_str($co{'title'}, 50)
4205 print format_subject_html($co{'title'}, $co{'title_short'},
4206 href(action=>"commit", hash=>$commit), $ref);
4208 "<td class=\"link\">" .
4209 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
4210 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
4212 if ($ftype eq 'blob') {
4213 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
4214 my $blob_parent = git_get_hash_by_path($commit, $file_name);
4215 if (defined $blob_current && defined $blob_parent &&
4216 $blob_current ne $blob_parent) {
4218 $cgi->a({-href => href(action=>"blobdiff",
4219 hash=>$blob_current, hash_parent=>$blob_parent,
4220 hash_base=>$hash_base, hash_parent_base=>$commit,
4221 file_name=>$file_name)},
4228 if (defined $extra) {
4230 "<td colspan=\"4\">$extra</td>\n" .
4237 # uses global variable $project
4238 my ($taglist, $from, $to, $extra) = @_;
4239 $from = 0 unless defined $from;
4240 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4242 print "<table class=\"tags\">\n";
4244 for (my $i = $from; $i <= $to; $i++) {
4245 my $entry = $taglist->[$i];
4247 my $comment = $tag{'subject'};
4249 if (defined $comment) {
4250 $comment_short = chop_str($comment, 30, 5);
4253 print "<tr class=\"dark\">\n";
4255 print "<tr class=\"light\">\n";
4258 if (defined $tag{'age'}) {
4259 print "<td><i>$tag{'age'}</i></td>\n";
4261 print "<td></td>\n";
4264 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
4265 -class => "list name"}, esc_html($tag{'name'})) .
4268 if (defined $comment) {
4269 print format_subject_html($comment, $comment_short,
4270 href(action=>"tag", hash=>$tag{'id'}));
4273 "<td class=\"selflink\">";
4274 if ($tag{'type'} eq "tag") {
4275 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
4280 "<td class=\"link\">" . " | " .
4281 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
4282 if ($tag{'reftype'} eq "commit") {
4283 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
4284 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
4285 } elsif ($tag{'reftype'} eq "blob") {
4286 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
4291 if (defined $extra) {
4293 "<td colspan=\"5\">$extra</td>\n" .
4299 sub git_heads_body {
4300 # uses global variable $project
4301 my ($headlist, $head, $from, $to, $extra) = @_;
4302 $from = 0 unless defined $from;
4303 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4305 print "<table class=\"heads\">\n";
4307 for (my $i = $from; $i <= $to; $i++) {
4308 my $entry = $headlist->[$i];
4310 my $curr = $ref{'id'} eq $head;
4312 print "<tr class=\"dark\">\n";
4314 print "<tr class=\"light\">\n";
4317 print "<td><i>$ref{'age'}</i></td>\n" .
4318 ($curr ? "<td class=\"current_head\">" : "<td>") .
4319 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),
4320 -class => "list name"},esc_html($ref{'name'})) .
4322 "<td class=\"link\">" .
4323 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
4324 $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
4325 $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
4329 if (defined $extra) {
4331 "<td colspan=\"3\">$extra</td>\n" .
4337 sub git_search_grep_body {
4338 my ($commitlist, $from, $to, $extra) = @_;
4339 $from = 0 unless defined $from;
4340 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4342 print "<table class=\"commit_search\">\n";
4344 for (my $i = $from; $i <= $to; $i++) {
4345 my %co = %{$commitlist->[$i]};
4349 my $commit = $co{'id'};
4351 print "<tr class=\"dark\">\n";
4353 print "<tr class=\"light\">\n";
4356 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
4357 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4358 "<td><i>" . $author . "</i></td>\n" .
4360 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
4361 -class => "list subject"},
4362 chop_and_escape_str($co{'title'}, 50) . "<br/>");
4363 my $comment = $co{'comment'};
4364 foreach my $line (@$comment) {
4365 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4366 my ($lead, $match, $trail) = ($1, $2, $3);
4367 $match = chop_str($match, 70, 5, 'center');
4368 my $contextlen = int((80 - length($match))/2);
4369 $contextlen = 30 if ($contextlen > 30);
4370 $lead = chop_str($lead, $contextlen, 10, 'left');
4371 $trail = chop_str($trail, $contextlen, 10, 'right');
4373 $lead = esc_html($lead);
4374 $match = esc_html($match);
4375 $trail = esc_html($trail);
4377 print "$lead<span class=\"match\">$match</span>$trail<br />";
4381 "<td class=\"link\">" .
4382 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4384 $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") .
4386 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4390 if (defined $extra) {
4392 "<td colspan=\"3\">$extra</td>\n" .
4398 ## ======================================================================
4399 ## ======================================================================
4402 sub git_project_list {
4403 my $order = $input_params{'order'};
4404 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4405 die_error(400, "Unknown order parameter");
4408 my @list = git_get_projects_list();
4410 die_error(404, "No projects found");
4413 if (-f $home_text) {
4414 print "<div class=\"index_include\">\n";
4415 print insert_file($home_text);
4418 print $cgi->startform(-method => "get") .
4419 "<p class=\"projsearch\">Search:\n" .
4420 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
4422 $cgi->end_form() . "\n";
4423 git_project_list_body(\@list, $order);
4427 my $order = $input_params{'order'};
4428 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4429 die_error(400, "Unknown order parameter");
4432 my @list = git_get_projects_list($project);
4434 die_error(404, "No forks found");
4437 git_print_page_nav('','');
4438 git_print_header_div('summary', "$project forks");
4439 git_project_list_body(\@list, $order);
4442 sub git_project_index {
4443 my @projects = git_get_projects_list($project);
4446 -type => 'text/plain',
4447 -charset => 'utf-8',
4448 -content_disposition => 'inline; filename="index.aux"');
4450 foreach my $pr (@projects) {
4451 if (!exists $pr->{'owner'}) {
4452 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
4455 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4456 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4457 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4458 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4462 print "$path $owner\n";
4467 my $descr = git_get_project_description($project) || "none";
4468 my %co = parse_commit("HEAD");
4469 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4470 my $head = $co{'id'};
4472 my $owner = git_get_project_owner($project);
4474 my $refs = git_get_references();
4475 # These get_*_list functions return one more to allow us to see if
4476 # there are more ...
4477 my @taglist = git_get_tags_list(16);
4478 my @headlist = git_get_heads_list(16);
4480 my $check_forks = gitweb_check_feature('forks');
4483 @forklist = git_get_projects_list($project);
4486 git_print_page_nav('summary','', $head);
4488 print "<div class=\"title\"> </div>\n";
4489 print "<table class=\"projects_list\">\n" .
4490 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
4491 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
4492 if (defined $cd{'rfc2822'}) {
4493 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4496 # use per project git URL list in $projectroot/$project/cloneurl
4497 # or make project git URL from git base URL and project name
4498 my $url_tag = "URL";
4499 my @url_list = git_get_project_url_list($project);
4500 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4501 foreach my $git_url (@url_list) {
4502 next unless $git_url;
4503 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4508 my $show_ctags = gitweb_check_feature('ctags');
4510 my $ctags = git_get_project_ctags($project);
4511 my $cloud = git_populate_project_tagcloud($ctags);
4512 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4513 print "</td>\n<td>" unless %$ctags;
4514 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4515 print "</td>\n<td>" if %$ctags;
4516 print git_show_project_tagcloud($cloud, 48);
4522 # If XSS prevention is on, we don't include README.html.
4523 # TODO: Allow a readme in some safe format.
4524 if (!$prevent_xss && -s "$projectroot/$project/README.html") {
4525 print "<div class=\"title\">readme</div>\n" .
4526 "<div class=\"readme\">\n";
4527 print insert_file("$projectroot/$project/README.html");
4528 print "\n</div>\n"; # class="readme"
4531 # we need to request one more than 16 (0..15) to check if
4533 my @commitlist = $head ? parse_commits($head, 17) : ();
4535 git_print_header_div('shortlog');
4536 git_shortlog_body(\@commitlist, 0, 15, $refs,
4537 $#commitlist <= 15 ? undef :
4538 $cgi->a({-href => href(action=>"shortlog")}, "..."));
4542 git_print_header_div('tags');
4543 git_tags_body(\@taglist, 0, 15,
4544 $#taglist <= 15 ? undef :
4545 $cgi->a({-href => href(action=>"tags")}, "..."));
4549 git_print_header_div('heads');
4550 git_heads_body(\@headlist, $head, 0, 15,
4551 $#headlist <= 15 ? undef :
4552 $cgi->a({-href => href(action=>"heads")}, "..."));
4556 git_print_header_div('forks');
4557 git_project_list_body(\@forklist, 'age', 0, 15,
4558 $#forklist <= 15 ? undef :
4559 $cgi->a({-href => href(action=>"forks")}, "..."),
4566 my $head = git_get_head_hash($project);
4567 git_print_page_nav('','', $head,undef,$head);
4568 my %tag = parse_tag($hash);
4571 die_error(404, "Unknown tag object");
4574 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
4575 print "<div class=\"title_text\">\n" .
4576 "<table class=\"object_header\">\n" .
4578 "<td>object</td>\n" .
4579 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4580 $tag{'object'}) . "</td>\n" .
4581 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4582 $tag{'type'}) . "</td>\n" .
4584 if (defined($tag{'author'})) {
4585 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
4586 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
4587 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4588 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4591 print "</table>\n\n" .
4593 print "<div class=\"page_body\">";
4594 my $comment = $tag{'comment'};
4595 foreach my $line (@$comment) {
4597 print esc_html($line, -nbsp=>1) . "<br/>\n";
4604 gitweb_check_feature('blame')
4605 or die_error(403, "Blame view not allowed");
4608 die_error(400, "No file name given") unless $file_name;
4609 $hash_base ||= git_get_head_hash($project);
4610 die_error(404, "Couldn't find base commit") unless $hash_base;
4611 my %co = parse_commit($hash_base)
4612 or die_error(404, "Commit not found");
4614 if (!defined $hash) {
4615 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4616 or die_error(404, "Error looking up file");
4618 $ftype = git_get_type($hash);
4619 if ($ftype !~ "blob") {
4620 die_error(400, "Object is not a blob - $hash");
4624 # run git-blame --porcelain
4625 open my $fd, "-|", git_cmd(), "blame", '-p',
4626 $hash_base, '--', $file_name
4627 or die_error(500, "Open git-blame failed");
4631 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4634 $cgi->a({-href => href(action=>"history", -replay=>1)},
4637 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4639 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4640 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4641 git_print_page_path($file_name, $ftype, $hash_base);
4644 my @rev_color = qw(light2 dark2);
4645 my $num_colors = scalar(@rev_color);
4646 my $current_color = 0;
4650 <div class="page_body">
4651 <table class="blame">
4652 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4655 while (my $line = <$fd>) {
4657 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4658 # no <lines in group> for subsequent lines in group of lines
4659 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4660 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4661 if (!exists $metainfo{$full_rev}) {
4662 $metainfo{$full_rev} = {};
4664 my $meta = $metainfo{$full_rev};
4666 while ($data = <$fd>) {
4668 last if ($data =~ s/^\t//); # contents of line
4669 if ($data =~ /^(\S+) (.*)$/) {
4673 my $short_rev = substr($full_rev, 0, 8);
4674 my $author = $meta->{'author'};
4676 parse_date($meta->{'author-time'}, $meta->{'author-tz'});
4677 my $date = $date{'iso-tz'};
4679 $current_color = ($current_color + 1) % $num_colors;
4681 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4683 print "<td class=\"sha1\"";
4684 print " title=\"". esc_html($author) . ", $date\"";
4685 print " rowspan=\"$group_size\"" if ($group_size > 1);
4687 print $cgi->a({-href => href(action=>"commit",
4689 file_name=>$file_name)},
4690 esc_html($short_rev));
4694 if (!exists $meta->{'parent'}) {
4695 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4696 or die_error(500, "Open git-rev-parse failed");
4697 $parent_commit = <$dd>;
4699 chomp($parent_commit);
4700 $meta->{'parent'} = $parent_commit;
4702 $parent_commit = $meta->{'parent'};
4704 my $blamed = href(action => 'blame',
4705 file_name => $meta->{'filename'},
4706 hash_base => $parent_commit);
4707 print "<td class=\"linenr\">";
4708 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4709 -class => "linenr" },
4712 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4718 or print "Reading blob failed\n";
4724 my $head = git_get_head_hash($project);
4725 git_print_page_nav('','', $head,undef,$head);
4726 git_print_header_div('summary', $project);
4728 my @tagslist = git_get_tags_list();
4730 git_tags_body(\@tagslist);
4735 my $head = git_get_head_hash($project);
4736 git_print_page_nav('','', $head,undef,$head);
4737 git_print_header_div('summary', $project);
4739 my @headslist = git_get_heads_list();
4741 git_heads_body(\@headslist, $head);
4745 sub git_blob_plain {
4749 if (!defined $hash) {
4750 if (defined $file_name) {
4751 my $base = $hash_base || git_get_head_hash($project);
4752 $hash = git_get_hash_by_path($base, $file_name, "blob")
4753 or die_error(404, "Cannot find file");
4755 die_error(400, "No file name defined");
4757 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4758 # blobs defined by non-textual hash id's can be cached
4762 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4763 or die_error(500, "Open git-cat-file blob '$hash' failed");
4765 # content-type (can include charset)
4766 $type = blob_contenttype($fd, $file_name, $type);
4768 # "save as" filename, even when no $file_name is given
4769 my $save_as = "$hash";
4770 if (defined $file_name) {
4771 $save_as = $file_name;
4772 } elsif ($type =~ m/^text\//) {
4776 # With XSS prevention on, blobs of all types except a few known safe
4777 # ones are served with "Content-Disposition: attachment" to make sure
4778 # they don't run in our security domain. For certain image types,
4779 # blob view writes an <img> tag referring to blob_plain view, and we
4780 # want to be sure not to break that by serving the image as an
4781 # attachment (though Firefox 3 doesn't seem to care).
4782 my $sandbox = $prevent_xss &&
4783 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4787 -expires => $expires,
4788 -content_disposition =>
4789 ($sandbox ? 'attachment' : 'inline')
4790 . '; filename="' . $save_as . '"');
4792 binmode STDOUT, ':raw';
4794 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4802 if (!defined $hash) {
4803 if (defined $file_name) {
4804 my $base = $hash_base || git_get_head_hash($project);
4805 $hash = git_get_hash_by_path($base, $file_name, "blob")
4806 or die_error(404, "Cannot find file");
4808 die_error(400, "No file name defined");
4810 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4811 # blobs defined by non-textual hash id's can be cached
4815 my $have_blame = gitweb_check_feature('blame');
4816 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4817 or die_error(500, "Couldn't cat $file_name, $hash");
4818 my $mimetype = blob_mimetype($fd, $file_name);
4819 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4821 return git_blob_plain($mimetype);
4823 # we can have blame only for text/* mimetype
4824 $have_blame &&= ($mimetype =~ m!^text/!);
4826 my $formats_nav = '';
4827 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4828 if (defined $file_name) {
4831 $cgi->a({-href => href(action=>"blame", hash => $hash, -replay=>1)},
4836 $cgi->a({-href => href(action=>"history", -replay=>1)},
4839 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4842 $cgi->a({-href => href(action=>"blob",
4843 hash_base=>"HEAD", file_name=>$file_name)},
4847 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4850 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4851 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4853 print "<div class=\"page_nav\">\n" .
4854 "<br/><br/></div>\n" .
4855 "<div class=\"title\">$hash</div>\n";
4857 git_print_page_path($file_name, "blob", $hash_base);
4858 print "<div class=\"page_body\">\n";
4859 if ($mimetype =~ m!^image/!) {
4860 print qq!<img type="$mimetype"!;
4862 print qq! alt="$file_name" title="$file_name"!;
4865 href(action=>"blob_plain", hash=>$hash,
4866 hash_base=>$hash_base, file_name=>$file_name) .
4870 while (my $line = <$fd>) {
4873 $line = untabify($line);
4874 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4875 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
4879 or print "Reading blob failed.\n";
4884 if (!defined $hash_base) {
4885 $hash_base = "HEAD";
4887 if (!defined $hash) {
4888 if (defined $file_name) {
4889 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
4894 die_error(404, "No such tree") unless defined($hash);
4896 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4897 or die_error(500, "Open git-ls-tree failed");
4898 my @entries = map { chomp; $_ } <$fd>;
4899 close $fd or die_error(404, "Reading tree failed");
4902 my $refs = git_get_references();
4903 my $ref = format_ref_marker($refs, $hash_base);
4905 my $have_blame = gitweb_check_feature('blame');
4906 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4908 if (defined $file_name) {
4910 $cgi->a({-href => href(action=>"history", -replay=>1)},
4912 $cgi->a({-href => href(action=>"tree",
4913 hash_base=>"HEAD", file_name=>$file_name)},
4916 my $snapshot_links = format_snapshot_links($hash);
4917 if (defined $snapshot_links) {
4918 # FIXME: Should be available when we have no hash base as well.
4919 push @views_nav, $snapshot_links;
4921 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4922 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
4925 print "<div class=\"page_nav\">\n";
4926 print "<br/><br/></div>\n";
4927 print "<div class=\"title\">$hash</div>\n";
4929 if (defined $file_name) {
4930 $basedir = $file_name;
4931 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4934 git_print_page_path($file_name, 'tree', $hash_base);
4936 print "<div class=\"page_body\">\n";
4937 print "<table class=\"tree\">\n";
4939 # '..' (top directory) link if possible
4940 if (defined $hash_base &&
4941 defined $file_name && $file_name =~ m![^/]+$!) {
4943 print "<tr class=\"dark\">\n";
4945 print "<tr class=\"light\">\n";
4949 my $up = $file_name;
4950 $up =~ s!/?[^/]+$!!;
4951 undef $up unless $up;
4952 # based on git_print_tree_entry
4953 print '<td class="mode">' . mode_str('040000') . "</td>\n";
4954 print '<td class="list">';
4955 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
4959 print "<td class=\"link\"></td>\n";
4963 foreach my $line (@entries) {
4964 my %t = parse_ls_tree_line($line, -z => 1);
4967 print "<tr class=\"dark\">\n";
4969 print "<tr class=\"light\">\n";
4973 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
4977 print "</table>\n" .
4982 my $format = $input_params{'snapshot_format'};
4983 if (!@snapshot_fmts) {
4984 die_error(403, "Snapshots not allowed");
4986 # default to first supported snapshot format
4987 $format ||= $snapshot_fmts[0];
4988 if ($format !~ m/^[a-z0-9]+$/) {
4989 die_error(400, "Invalid snapshot format parameter");
4990 } elsif (!exists($known_snapshot_formats{$format})) {
4991 die_error(400, "Unknown snapshot format");
4992 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
4993 die_error(403, "Unsupported snapshot format");
4996 if (!defined $hash) {
4997 $hash = git_get_head_hash($project);
5000 my $name = $project;
5001 $name =~ s,([^/])/*\.git$,$1,;
5002 $name = basename($name);
5003 my $filename = to_utf8($name);
5004 $name =~ s/\047/\047\\\047\047/g;
5006 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5007 $cmd = quote_command(
5008 git_cmd(), 'archive',
5009 "--format=$known_snapshot_formats{$format}{'format'}",
5010 "--prefix=$name/", $hash);
5011 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5012 $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
5016 -type => $known_snapshot_formats{$format}{'type'},
5017 -content_disposition => 'inline; filename="' . "$filename" . '"',
5018 -status => '200 OK');
5020 open my $fd, "-|", $cmd
5021 or die_error(500, "Execute git-archive failed");
5022 binmode STDOUT, ':raw';
5024 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
5029 my $head = git_get_head_hash($project);
5030 if (!defined $hash) {
5033 if (!defined $page) {
5036 my $refs = git_get_references();
5038 my @commitlist = parse_commits($hash, 101, (100 * $page));
5040 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5042 my ($patch_max) = gitweb_get_feature('patches');
5044 if ($patch_max < 0 || @commitlist <= $patch_max) {
5045 $paging_nav .= " ⋅ " .
5046 $cgi->a({-href => href(action=>"patches", -replay=>1)},
5051 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
5054 my %co = parse_commit($hash);
5056 git_print_header_div('summary', $project);
5057 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5059 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5060 for (my $i = 0; $i <= $to; $i++) {
5061 my %co = %{$commitlist[$i]};
5063 my $commit = $co{'id'};
5064 my $ref = format_ref_marker($refs, $commit);
5065 my %ad = parse_date($co{'author_epoch'});
5066 git_print_header_div('commit',
5067 "<span class=\"age\">$co{'age_string'}</span>" .
5068 esc_html($co{'title'}) . $ref,
5070 print "<div class=\"title_text\">\n" .
5071 "<div class=\"log_link\">\n" .
5072 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
5074 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
5076 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
5079 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5082 print "<div class=\"log_body\">\n";
5083 git_print_log($co{'comment'}, -final_empty_line=> 1);
5086 if ($#commitlist >= 100) {
5087 print "<div class=\"page_nav\">\n";
5088 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
5089 -accesskey => "n", -title => "Alt-n"}, "next");
5095 $hash ||= $hash_base || "HEAD";
5096 my %co = parse_commit($hash)
5097 or die_error(404, "Unknown commit object");
5098 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5099 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
5101 my $parent = $co{'parent'};
5102 my $parents = $co{'parents'}; # listref
5104 # we need to prepare $formats_nav before any parameter munging
5106 if (!defined $parent) {
5108 $formats_nav .= '(initial)';
5109 } elsif (@$parents == 1) {
5110 # single parent commit
5113 $cgi->a({-href => href(action=>"commit",
5115 esc_html(substr($parent, 0, 7))) .
5122 $cgi->a({-href => href(action=>"commit",
5124 esc_html(substr($_, 0, 7)));
5128 if (gitweb_check_feature('patches')) {
5129 $formats_nav .= " | " .
5130 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5134 if (!defined $parent) {
5138 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
5140 (@$parents <= 1 ? $parent : '-c'),
5142 or die_error(500, "Open git-diff-tree failed");
5143 @difftree = map { chomp; $_ } <$fd>;
5144 close $fd or die_error(404, "Reading git-diff-tree failed");
5146 # non-textual hash id's can be cached
5148 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5151 my $refs = git_get_references();
5152 my $ref = format_ref_marker($refs, $co{'id'});
5154 git_print_page_nav('commit', '',
5155 $hash, $co{'tree'}, $hash,
5158 if (defined $co{'parent'}) {
5159 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
5161 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
5163 print "<div class=\"title_text\">\n" .
5164 "<table class=\"object_header\">\n";
5165 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
5167 "<td></td><td> $ad{'rfc2822'}";
5168 if ($ad{'hour_local'} < 6) {
5169 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5170 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5172 printf(" (%02d:%02d %s)",
5173 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5177 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
5178 print "<tr><td></td><td> $cd{'rfc2822'}" .
5179 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5181 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5184 "<td class=\"sha1\">" .
5185 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
5186 class => "list"}, $co{'tree'}) .
5188 "<td class=\"link\">" .
5189 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
5191 my $snapshot_links = format_snapshot_links($hash);
5192 if (defined $snapshot_links) {
5193 print " | " . $snapshot_links;
5198 foreach my $par (@$parents) {
5201 "<td class=\"sha1\">" .
5202 $cgi->a({-href => href(action=>"commit", hash=>$par),
5203 class => "list"}, $par) .
5205 "<td class=\"link\">" .
5206 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
5208 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
5215 print "<div class=\"page_body\">\n";
5216 git_print_log($co{'comment'});
5219 git_difftree_body(\@difftree, $hash, @$parents);
5224 # object is defined by:
5225 # - hash or hash_base alone
5226 # - hash_base and file_name
5229 # - hash or hash_base alone
5230 if ($hash || ($hash_base && !defined $file_name)) {
5231 my $object_id = $hash || $hash_base;
5233 open my $fd, "-|", quote_command(
5234 git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5235 or die_error(404, "Object does not exist");
5239 or die_error(404, "Object does not exist");
5241 # - hash_base and file_name
5242 } elsif ($hash_base && defined $file_name) {
5243 $file_name =~ s,/+$,,;
5245 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
5246 or die_error(404, "Base object does not exist");
5248 # here errors should not hapen
5249 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
5250 or die_error(500, "Open git-ls-tree failed");
5254 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5255 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5256 die_error(404, "File or directory for given base does not exist");
5261 die_error(400, "Not enough information to find object");
5264 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
5265 hash=>$hash, hash_base=>$hash_base,
5266 file_name=>$file_name),
5267 -status => '302 Found');
5271 my $format = shift || 'html';
5278 # preparing $fd and %diffinfo for git_patchset_body
5280 if (defined $hash_base && defined $hash_parent_base) {
5281 if (defined $file_name) {
5283 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5284 $hash_parent_base, $hash_base,
5285 "--", (defined $file_parent ? $file_parent : ()), $file_name
5286 or die_error(500, "Open git-diff-tree failed");
5287 @difftree = map { chomp; $_ } <$fd>;
5289 or die_error(404, "Reading git-diff-tree failed");
5291 or die_error(404, "Blob diff not found");
5293 } elsif (defined $hash &&
5294 $hash =~ /[0-9a-fA-F]{40}/) {
5295 # try to find filename from $hash
5297 # read filtered raw output
5298 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5299 $hash_parent_base, $hash_base, "--"
5300 or die_error(500, "Open git-diff-tree failed");
5302 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5304 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5305 map { chomp; $_ } <$fd>;
5307 or die_error(404, "Reading git-diff-tree failed");
5309 or die_error(404, "Blob diff not found");
5312 die_error(400, "Missing one of the blob diff parameters");
5315 if (@difftree > 1) {
5316 die_error(400, "Ambiguous blob diff specification");
5319 %diffinfo = parse_difftree_raw_line($difftree[0]);
5320 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5321 $file_name ||= $diffinfo{'to_file'};
5323 $hash_parent ||= $diffinfo{'from_id'};
5324 $hash ||= $diffinfo{'to_id'};
5326 # non-textual hash id's can be cached
5327 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5328 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5333 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5334 '-p', ($format eq 'html' ? "--full-index" : ()),
5335 $hash_parent_base, $hash_base,
5336 "--", (defined $file_parent ? $file_parent : ()), $file_name
5337 or die_error(500, "Open git-diff-tree failed");
5340 # old/legacy style URI -- not generated anymore since 1.4.3.
5342 die_error('404 Not Found', "Missing one of the blob diff parameters")
5346 if ($format eq 'html') {
5348 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
5350 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5351 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5352 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5354 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5355 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5357 if (defined $file_name) {
5358 git_print_page_path($file_name, "blob", $hash_base);
5360 print "<div class=\"page_path\"></div>\n";
5363 } elsif ($format eq 'plain') {
5365 -type => 'text/plain',
5366 -charset => 'utf-8',
5367 -expires => $expires,
5368 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
5370 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5373 die_error(400, "Unknown blobdiff format");
5377 if ($format eq 'html') {
5378 print "<div class=\"page_body\">\n";
5380 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
5383 print "</div>\n"; # class="page_body"
5386 while (my $line = <$fd>) {
5387 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5388 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5392 last if $line =~ m!^\+\+\+!;
5400 sub git_blobdiff_plain {
5401 git_blobdiff('plain');
5404 sub git_commitdiff {
5406 my $format = $params{-format} || 'html';
5408 my ($patch_max) = gitweb_get_feature('patches');
5409 if ($format eq 'patch') {
5410 die_error(403, "Patch view not allowed") unless $patch_max;
5413 $hash ||= $hash_base || "HEAD";
5414 my %co = parse_commit($hash)
5415 or die_error(404, "Unknown commit object");
5417 # choose format for commitdiff for merge
5418 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5419 $hash_parent = '--cc';
5421 # we need to prepare $formats_nav before almost any parameter munging
5423 if ($format eq 'html') {
5425 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
5428 $formats_nav .= " | " .
5429 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5433 if (defined $hash_parent &&
5434 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5435 # commitdiff with two commits given
5436 my $hash_parent_short = $hash_parent;
5437 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5438 $hash_parent_short = substr($hash_parent, 0, 7);
5442 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5443 if ($co{'parents'}[$i] eq $hash_parent) {
5444 $formats_nav .= ' parent ' . ($i+1);
5448 $formats_nav .= ': ' .
5449 $cgi->a({-href => href(action=>"commitdiff",
5450 hash=>$hash_parent)},
5451 esc_html($hash_parent_short)) .
5453 } elsif (!$co{'parent'}) {
5455 $formats_nav .= ' (initial)';
5456 } elsif (scalar @{$co{'parents'}} == 1) {
5457 # single parent commit
5460 $cgi->a({-href => href(action=>"commitdiff",
5461 hash=>$co{'parent'})},
5462 esc_html(substr($co{'parent'}, 0, 7))) .
5466 if ($hash_parent eq '--cc') {
5467 $formats_nav .= ' | ' .
5468 $cgi->a({-href => href(action=>"commitdiff",
5469 hash=>$hash, hash_parent=>'-c')},
5471 } else { # $hash_parent eq '-c'
5472 $formats_nav .= ' | ' .
5473 $cgi->a({-href => href(action=>"commitdiff",
5474 hash=>$hash, hash_parent=>'--cc')},
5480 $cgi->a({-href => href(action=>"commitdiff",
5482 esc_html(substr($_, 0, 7)));
5483 } @{$co{'parents'}} ) .
5488 my $hash_parent_param = $hash_parent;
5489 if (!defined $hash_parent_param) {
5490 # --cc for multiple parents, --root for parentless
5491 $hash_parent_param =
5492 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5498 if ($format eq 'html') {
5499 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5500 "--no-commit-id", "--patch-with-raw", "--full-index",
5501 $hash_parent_param, $hash, "--"
5502 or die_error(500, "Open git-diff-tree failed");
5504 while (my $line = <$fd>) {
5506 # empty line ends raw part of diff-tree output
5508 push @difftree, scalar parse_difftree_raw_line($line);
5511 } elsif ($format eq 'plain') {
5512 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5513 '-p', $hash_parent_param, $hash, "--"
5514 or die_error(500, "Open git-diff-tree failed");
5515 } elsif ($format eq 'patch') {
5516 # For commit ranges, we limit the output to the number of
5517 # patches specified in the 'patches' feature.
5518 # For single commits, we limit the output to a single patch,
5519 # diverging from the git-format-patch default.
5520 my @commit_spec = ();
5522 if ($patch_max > 0) {
5523 push @commit_spec, "-$patch_max";
5525 push @commit_spec, '-n', "$hash_parent..$hash";
5527 if ($params{-single}) {
5528 push @commit_spec, '-1';
5530 if ($patch_max > 0) {
5531 push @commit_spec, "-$patch_max";
5533 push @commit_spec, "-n";
5535 push @commit_spec, '--root', $hash;
5537 open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
5538 '--stdout', @commit_spec
5539 or die_error(500, "Open git-format-patch failed");
5541 die_error(400, "Unknown commitdiff format");
5544 # non-textual hash id's can be cached
5546 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5550 # write commit message
5551 if ($format eq 'html') {
5552 my $refs = git_get_references();
5553 my $ref = format_ref_marker($refs, $co{'id'});
5555 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5556 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5557 git_print_authorship(\%co);
5558 print "<div class=\"page_body\">\n";
5559 if (@{$co{'comment'}} > 1) {
5560 print "<div class=\"log\">\n";
5561 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5562 print "</div>\n"; # class="log"
5565 } elsif ($format eq 'plain') {
5566 my $refs = git_get_references("tags");
5567 my $tagname = git_get_rev_name_tags($hash);
5568 my $filename = basename($project) . "-$hash.patch";
5571 -type => 'text/plain',
5572 -charset => 'utf-8',
5573 -expires => $expires,
5574 -content_disposition => 'inline; filename="' . "$filename" . '"');
5575 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5576 print "From: " . to_utf8($co{'author'}) . "\n";
5577 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5578 print "Subject: " . to_utf8($co{'title'}) . "\n";
5580 print "X-Git-Tag: $tagname\n" if $tagname;
5581 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5583 foreach my $line (@{$co{'comment'}}) {
5584 print to_utf8($line) . "\n";
5587 } elsif ($format eq 'patch') {
5588 my $filename = basename($project) . "-$hash.patch";
5591 -type => 'text/plain',
5592 -charset => 'utf-8',
5593 -expires => $expires,
5594 -content_disposition => 'inline; filename="' . "$filename" . '"');
5598 if ($format eq 'html') {
5599 my $use_parents = !defined $hash_parent ||
5600 $hash_parent eq '-c' || $hash_parent eq '--cc';
5601 git_difftree_body(\@difftree, $hash,
5602 $use_parents ? @{$co{'parents'}} : $hash_parent);
5605 git_patchset_body($fd, \@difftree, $hash,
5606 $use_parents ? @{$co{'parents'}} : $hash_parent);
5608 print "</div>\n"; # class="page_body"
5610 } elsif ($format eq 'plain') {
5614 or print "Reading git-diff-tree failed\n";
5615 } elsif ($format eq 'patch') {
5619 or print "Reading git-format-patch failed\n";
5623 sub git_commitdiff_plain {
5624 git_commitdiff(-format => 'plain');
5627 # format-patch-style patches
5629 git_commitdiff(-format => 'patch', -single=> 1);
5633 git_commitdiff(-format => 'patch');
5637 if (!defined $hash_base) {
5638 $hash_base = git_get_head_hash($project);
5640 if (!defined $page) {
5644 my %co = parse_commit($hash_base)
5645 or die_error(404, "Unknown commit object");
5647 my $refs = git_get_references();
5648 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5650 my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5651 $file_name, "--full-history")
5652 or die_error(404, "No such file or directory on given branch");
5654 if (!defined $hash && defined $file_name) {
5655 # some commits could have deleted file in question,
5656 # and not have it in tree, but one of them has to have it
5657 for (my $i = 0; $i <= @commitlist; $i++) {
5658 $hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5659 last if defined $hash;
5662 if (defined $hash) {
5663 $ftype = git_get_type($hash);
5665 if (!defined $ftype) {
5666 die_error(500, "Unknown type of object");
5669 my $paging_nav = '';
5672 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5673 file_name=>$file_name)},
5675 $paging_nav .= " ⋅ " .
5676 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5677 -accesskey => "p", -title => "Alt-p"}, "prev");
5679 $paging_nav .= "first";
5680 $paging_nav .= " ⋅ prev";
5683 if ($#commitlist >= 100) {
5685 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5686 -accesskey => "n", -title => "Alt-n"}, "next");
5687 $paging_nav .= " ⋅ $next_link";
5689 $paging_nav .= " ⋅ next";
5692 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5693 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5694 git_print_page_path($file_name, $ftype, $hash_base);
5696 git_history_body(\@commitlist, 0, 99,
5697 $refs, $hash_base, $ftype, $next_link);
5702 gitweb_check_feature('search') or die_error(403, "Search is disabled");
5703 if (!defined $searchtext) {
5704 die_error(400, "Text field is empty");
5706 if (!defined $hash) {
5707 $hash = git_get_head_hash($project);
5709 my %co = parse_commit($hash);
5711 die_error(404, "Unknown commit object");
5713 if (!defined $page) {
5717 $searchtype ||= 'commit';
5718 if ($searchtype eq 'pickaxe') {
5719 # pickaxe may take all resources of your box and run for several minutes
5720 # with every query - so decide by yourself how public you make this feature
5721 gitweb_check_feature('pickaxe')
5722 or die_error(403, "Pickaxe is disabled");
5724 if ($searchtype eq 'grep') {
5725 gitweb_check_feature('grep')
5726 or die_error(403, "Grep is disabled");
5730 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5732 if ($searchtype eq 'commit') {
5733 $greptype = "--grep=";
5734 } elsif ($searchtype eq 'author') {
5735 $greptype = "--author=";
5736 } elsif ($searchtype eq 'committer') {
5737 $greptype = "--committer=";
5739 $greptype .= $searchtext;
5740 my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5741 $greptype, '--regexp-ignore-case',
5742 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5744 my $paging_nav = '';
5747 $cgi->a({-href => href(action=>"search", hash=>$hash,
5748 searchtext=>$searchtext,
5749 searchtype=>$searchtype)},
5751 $paging_nav .= " ⋅ " .
5752 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5753 -accesskey => "p", -title => "Alt-p"}, "prev");
5755 $paging_nav .= "first";
5756 $paging_nav .= " ⋅ prev";
5759 if ($#commitlist >= 100) {
5761 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5762 -accesskey => "n", -title => "Alt-n"}, "next");
5763 $paging_nav .= " ⋅ $next_link";
5765 $paging_nav .= " ⋅ next";
5768 if ($#commitlist >= 100) {
5771 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5772 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5773 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5776 if ($searchtype eq 'pickaxe') {
5777 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5778 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5780 print "<table class=\"pickaxe search\">\n";
5783 open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
5784 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5785 ($search_use_regexp ? '--pickaxe-regex' : ());
5788 while (my $line = <$fd>) {
5792 my %set = parse_difftree_raw_line($line);
5793 if (defined $set{'commit'}) {
5794 # finish previous commit
5797 "<td class=\"link\">" .
5798 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5800 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5806 print "<tr class=\"dark\">\n";
5808 print "<tr class=\"light\">\n";
5811 %co = parse_commit($set{'commit'});
5812 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5813 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5814 "<td><i>$author</i></td>\n" .
5816 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
5817 -class => "list subject"},
5818 chop_and_escape_str($co{'title'}, 50) . "<br/>");
5819 } elsif (defined $set{'to_id'}) {
5820 next if ($set{'to_id'} =~ m/^0{40}$/);
5822 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
5823 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),
5825 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
5831 # finish last commit (warning: repetition!)
5834 "<td class=\"link\">" .
5835 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5837 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5845 if ($searchtype eq 'grep') {
5846 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5847 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5849 print "<table class=\"grep_search\">\n";
5853 open my $fd, "-|", git_cmd(), 'grep', '-n',
5854 $search_use_regexp ? ('-E', '-i') : '-F',
5855 $searchtext, $co{'tree'};
5857 while (my $line = <$fd>) {
5859 my ($file, $lno, $ltext, $binary);
5860 last if ($matches++ > 1000);
5861 if ($line =~ /^Binary file (.+) matches$/) {
5865 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5867 if ($file ne $lastfile) {
5868 $lastfile and print "</td></tr>\n";
5870 print "<tr class=\"dark\">\n";
5872 print "<tr class=\"light\">\n";
5874 print "<td class=\"list\">".
5875 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5876 file_name=>"$file"),
5877 -class => "list"}, esc_path($file));
5878 print "</td><td>\n";
5882 print "<div class=\"binary\">Binary file</div>\n";
5884 $ltext = untabify($ltext);
5885 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5886 $ltext = esc_html($1, -nbsp=>1);
5887 $ltext .= '<span class="match">';
5888 $ltext .= esc_html($2, -nbsp=>1);
5889 $ltext .= '</span>';
5890 $ltext .= esc_html($3, -nbsp=>1);
5892 $ltext = esc_html($ltext, -nbsp=>1);
5894 print "<div class=\"pre\">" .
5895 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5896 file_name=>"$file").'#l'.$lno,
5897 -class => "linenr"}, sprintf('%4i', $lno))
5898 . ' ' . $ltext . "</div>\n";
5902 print "</td></tr>\n";
5903 if ($matches > 1000) {
5904 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5907 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5915 sub git_search_help {
5916 git_print_page_nav('','', $hash,$hash,$hash);
5918 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5919 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5920 the pattern entered is recognized as the POSIX extended
5921 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5924 <dt><b>commit</b></dt>
5925 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5927 my $have_grep = gitweb_check_feature('grep');
5930 <dt><b>grep</b></dt>
5931 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5932 a different one) are searched for the given pattern. On large trees, this search can take
5933 a while and put some strain on the server, so please use it with some consideration. Note that
5934 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5935 case-sensitive.</dd>
5939 <dt><b>author</b></dt>
5940 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5941 <dt><b>committer</b></dt>
5942 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5944 my $have_pickaxe = gitweb_check_feature('pickaxe');
5945 if ($have_pickaxe) {
5947 <dt><b>pickaxe</b></dt>
5948 <dd>All commits that caused the string to appear or disappear from any file (changes that
5949 added, removed or "modified" the string) will be listed. This search can take a while and
5950 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5951 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5958 my $head = git_get_head_hash($project);
5959 if (!defined $hash) {
5962 if (!defined $page) {
5965 my $refs = git_get_references();
5967 my $commit_hash = $hash;
5968 if (defined $hash_parent) {
5969 $commit_hash = "$hash_parent..$hash";
5971 my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
5973 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
5975 if ($#commitlist >= 100) {
5977 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5978 -accesskey => "n", -title => "Alt-n"}, "next");
5980 my $patch_max = gitweb_check_feature('patches');
5982 if ($patch_max < 0 || @commitlist <= $patch_max) {
5983 $paging_nav .= " ⋅ " .
5984 $cgi->a({-href => href(action=>"patches", -replay=>1)},
5989 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
5990 git_print_header_div('summary', $project);
5992 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
5996 ## ......................................................................
5997 ## feeds (RSS, Atom; OPML)
5999 # XXX This does header stuff which may not play nice with Catalyst, so likely
6000 # broken in some/many ways.
6002 my $format = shift || 'atom';
6003 my $have_blame = gitweb_check_feature('blame');
6005 # Atom: http://www.atomenabled.org/developers/syndication/
6006 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6007 if ($format ne 'rss' && $format ne 'atom') {
6008 die_error(400, "Unknown web feed format");
6011 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6012 my $head = $hash || 'HEAD';
6013 my @commitlist = parse_commits($head, 150, 0, $file_name);
6017 my $content_type = "application/$format+xml";
6018 if (defined $cgi->http('HTTP_ACCEPT') &&
6019 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6020 # browser (feed reader) prefers text/xml
6021 $content_type = 'text/xml';
6023 if (defined($commitlist[0])) {
6024 %latest_commit = %{$commitlist[0]};
6025 my $latest_epoch = $latest_commit{'committer_epoch'};
6026 %latest_date = parse_date($latest_epoch);
6027 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6028 if (defined $if_modified) {
6030 if (eval { require HTTP::Date; 1; }) {
6031 $since = HTTP::Date::str2time($if_modified);
6032 } elsif (eval { require Time::ParseDate; 1; }) {
6033 $since = Time::ParseDate::parsedate($if_modified, GMT => 1);
6035 if (defined $since && $latest_epoch <= $since) {
6037 -type => $content_type,
6038 -charset => 'utf-8',
6039 -last_modified => $latest_date{'rfc2822'},
6040 -status => '304 Not Modified');
6045 -type => $content_type,
6046 -charset => 'utf-8',
6047 -last_modified => $latest_date{'rfc2822'});
6050 -type => $content_type,
6051 -charset => 'utf-8');
6054 # Optimization: skip generating the body if client asks only
6055 # for Last-Modified date.
6056 return if ($cgi->request_method() eq 'HEAD');
6059 my $title = "$site_name - $project/$action";
6060 my $feed_type = 'log';
6061 if (defined $hash) {
6062 $title .= " - '$hash'";
6063 $feed_type = 'branch log';
6064 if (defined $file_name) {
6065 $title .= " :: $file_name";
6066 $feed_type = 'history';
6068 } elsif (defined $file_name) {
6069 $title .= " - $file_name";
6070 $feed_type = 'history';
6072 $title .= " $feed_type";
6073 my $descr = git_get_project_description($project);
6074 if (defined $descr) {
6075 $descr = esc_html($descr);
6077 $descr = "$project " .
6078 ($format eq 'rss' ? 'RSS' : 'Atom') .
6081 my $owner = git_get_project_owner($project);
6082 $owner = esc_html($owner);
6086 if (defined $file_name) {
6087 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
6088 } elsif (defined $hash) {
6089 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
6091 $alt_url = href(-full=>1, action=>"summary");
6093 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
6094 if ($format eq 'rss') {
6096 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6099 print "<title>$title</title>\n" .
6100 "<link>$alt_url</link>\n" .
6101 "<description>$descr</description>\n" .
6102 "<language>en</language>\n" .
6103 # project owner is responsible for 'editorial' content
6104 "<managingEditor>$owner</managingEditor>\n";
6105 if (defined $logo || defined $favicon) {
6106 # prefer the logo to the favicon, since RSS
6107 # doesn't allow both
6108 my $img = esc_url($logo || $favicon);
6110 "<url>$img</url>\n" .
6111 "<title>$title</title>\n" .
6112 "<link>$alt_url</link>\n" .
6116 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6117 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6119 print "<generator>gitweb v.$version/$git_version</generator>\n";
6120 } elsif ($format eq 'atom') {
6122 <feed xmlns="http://www.w3.org/2005/Atom">
6124 print "<title>$title</title>\n" .
6125 "<subtitle>$descr</subtitle>\n" .
6126 '<link rel="alternate" type="text/html" href="' .
6127 $alt_url . '" />' . "\n" .
6128 '<link rel="self" type="' . $content_type . '" href="' .
6129 $cgi->self_url() . '" />' . "\n" .
6130 "<id>" . href(-full=>1) . "</id>\n" .
6131 # use project owner for feed author
6132 "<author><name>$owner</name></author>\n";
6133 if (defined $favicon) {
6134 print "<icon>" . esc_url($favicon) . "</icon>\n";
6136 if (defined $logo_url) {
6137 # not twice as wide as tall: 72 x 27 pixels
6138 print "<logo>" . esc_url($logo) . "</logo>\n";
6140 if (! %latest_date) {
6141 # dummy date to keep the feed valid until commits trickle in:
6142 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6144 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6146 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6150 for (my $i = 0; $i <= $#commitlist; $i++) {
6151 my %co = %{$commitlist[$i]};
6152 my $commit = $co{'id'};
6153 # we read 150, we always show 30 and the ones more recent than 48 hours
6154 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6157 my %cd = parse_date($co{'author_epoch'});
6159 # get list of changed files
6160 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
6161 $co{'parent'} || "--root",
6162 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6164 my @difftree = map { chomp; $_ } <$fd>;
6168 # print element (entry, item)
6169 my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
6170 if ($format eq 'rss') {
6172 "<title>" . esc_html($co{'title'}) . "</title>\n" .
6173 "<author>" . esc_html($co{'author'}) . "</author>\n" .
6174 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6175 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6176 "<link>$co_url</link>\n" .
6177 "<description>" . esc_html($co{'title'}) . "</description>\n" .
6178 "<content:encoded>" .
6180 } elsif ($format eq 'atom') {
6182 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
6183 "<updated>$cd{'iso-8601'}</updated>\n" .
6185 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
6186 if ($co{'author_email'}) {
6187 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
6189 print "</author>\n" .
6190 # use committer for contributor
6192 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
6193 if ($co{'committer_email'}) {
6194 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
6196 print "</contributor>\n" .
6197 "<published>$cd{'iso-8601'}</published>\n" .
6198 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6199 "<id>$co_url</id>\n" .
6200 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
6201 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6203 my $comment = $co{'comment'};
6205 foreach my $line (@$comment) {
6206 $line = esc_html($line);
6209 print "</pre><ul>\n";
6210 foreach my $difftree_line (@difftree) {
6211 my %difftree = parse_difftree_raw_line($difftree_line);
6212 next if !$difftree{'from_id'};
6214 my $file = $difftree{'file'} || $difftree{'to_file'};
6218 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
6219 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
6220 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
6221 file_name=>$file, file_parent=>$difftree{'from_file'}),
6222 -title => "diff"}, 'D');
6224 print $cgi->a({-href => href(-full=>1, action=>"blame",
6225 file_name=>$file, hash_base=>$commit),
6226 -title => "blame"}, 'B');
6228 # if this is not a feed of a file history
6229 if (!defined $file_name || $file_name ne $file) {
6230 print $cgi->a({-href => href(-full=>1, action=>"history",
6231 file_name=>$file, hash=>$commit),
6232 -title => "history"}, 'H');
6234 $file = esc_path($file);
6238 if ($format eq 'rss') {
6239 print "</ul>]]>\n" .
6240 "</content:encoded>\n" .
6242 } elsif ($format eq 'atom') {
6243 print "</ul>\n</div>\n" .
6250 if ($format eq 'rss') {
6251 print "</channel>\n</rss>\n";
6252 } elsif ($format eq 'atom') {
6266 my @list = git_get_projects_list();
6269 -type => 'text/xml',
6270 -charset => 'utf-8',
6271 -content_disposition => 'inline; filename="opml.xml"');
6274 <?xml version="1.0" encoding="utf-8"?>
6275 <opml version="1.0">
6277 <title>$site_name OPML Export</title>
6280 <outline text="git RSS feeds">
6283 foreach my $pr (@list) {
6285 my $head = git_get_head_hash($proj{'path'});
6286 if (!defined $head) {
6289 $git_dir = "$projectroot/$proj{'path'}";
6290 my %co = parse_commit($head);
6295 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
6296 my $rss = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
6297 my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
6298 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";