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);
20 binmode STDOUT, ':utf8';
23 CGI->compile() if $ENV{'MOD_PERL'};
27 $cgi $version $my_url $my_uri $base_url $path_info $GIT $projectroot
28 $project_maxdepth $home_link $home_link_str $site_name $site_header
29 $home_text $site_footer @stylesheets $stylesheet $logo $favicon
30 $logo_url $logo_label $logo_url $logo_label $projects_list
31 $projects_list_description_width $default_projects_order
32 $export_ok $export_auth_hook $strict_export @git_base_url_list
33 $default_blob_plain_mimetype $default_text_plain_charset
34 $mimetypes_file $fallback_encoding @diff_opts $prevent_xss
35 %known_snapshot_formats %known_snapshot_format_aliases %feature
36 $GITWEB_CONFIG $GITWEB_CONFIG $GITWEB_CONFIG_SYSTEM $git_version
37 %input_params @cgi_param_mapping %cgi_param_mapping %actions
38 %allowed_options $action $project $file_name $file_parent $hash
39 $hash_parent $hash_base @extra_options $hash_parent_base $page
40 $searchtype $search_use_regexp $searchtext $search_regexp $git_dir
50 our $version = "1.6.3.3";
51 our $my_url = $cgi->url();
52 our $my_uri = $cgi->url(-absolute => 1);
54 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
55 # needed and used only for URLs with nonempty PATH_INFO
56 our $base_url = $my_url;
58 # When the script is used as DirectoryIndex, the URL does not contain the name
59 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
60 # have to do it ourselves. We make $path_info global because it's also used
63 # Another issue with the script being the DirectoryIndex is that the resulting
64 # $my_url data is not the full script URL: this is good, because we want
65 # generated links to keep implying the script name if it wasn't explicitly
66 # indicated in the URL we're handling, but it means that $my_url cannot be used
68 # Therefore, if we needed to strip PATH_INFO, then we know that we have
69 # to build the base URL ourselves:
70 our $path_info = $ENV{"PATH_INFO"};
72 if ($my_url =~ s,\Q$path_info\E$,, &&
73 $my_uri =~ s,\Q$path_info\E$,, &&
74 defined $ENV{'SCRIPT_NAME'}) {
75 $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
79 # core git executable to use
80 # this can just be "git" if your webserver has a sensible PATH
81 our $GIT = "/usr/bin/git";
83 # absolute fs-path which will be prepended to the project path
84 our $projectroot = "/pub/scm";
86 # fs traversing limit for getting project list
87 # the number is relative to the projectroot
88 our $project_maxdepth = 2007;
90 # target of the home link on top of all pages
91 our $home_link = $my_uri || "/";
93 # string of the home link on top of all pages
94 our $home_link_str = "Project Gitalist";
96 # name of your site or organization to appear in page titles
97 # replace this with something more descriptive for clearer bookmarks
99 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
101 # filename of html text to include at top of each page
102 our $site_header = "";
103 # html text to include at home page
104 our $home_text = "indextext.html";
105 # filename of html text to include at bottom of each page
106 our $site_footer = "";
109 our @stylesheets = ("gitweb.css");
110 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
111 our $stylesheet = undef;
112 # URI of GIT logo (72x27 size)
113 our $logo = "git-logo.png";
114 # URI of GIT favicon, assumed to be image/png type
115 our $favicon = "git-favicon.png";
117 # URI and label (title) of GIT logo link
118 our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
119 our $logo_label = "git documentation";
121 # source of projects list
122 our $projects_list = "";
124 # the width (in characters) of the projects list "Description" column
125 our $projects_list_description_width = 25;
127 # default order of projects list
128 # valid values are none, project, descr, owner, and age
129 our $default_projects_order = "project";
131 # show repository only if this file exists
132 # (only effective if this variable evaluates to true)
135 # show repository only if this subroutine returns true
136 # when given the path to the project, for example:
137 # sub { return -e "$_[0]/git-daemon-export-ok"; }
138 our $export_auth_hook = undef;
140 # only allow viewing of repositories also shown on the overview page
141 our $strict_export = "";
143 # list of git base URLs used for URL to where fetch project from,
144 # i.e. full URL is "$git_base_url/$project"
145 our @git_base_url_list = grep { $_ ne '' } ("");
147 # default blob_plain mimetype and default charset for text/plain blob
148 our $default_blob_plain_mimetype = 'text/plain';
149 our $default_text_plain_charset = undef;
151 # file to use for guessing MIME types before trying /etc/mime.types
152 # (relative to the current git repository)
153 our $mimetypes_file = undef;
155 # assume this charset if line contains non-UTF-8 characters;
156 # it should be valid encoding (see Encoding::Supported(3pm) for list),
157 # for which encoding all byte sequences are valid, for example
158 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
159 # could be even 'utf-8' for the old behavior)
160 our $fallback_encoding = 'latin1';
162 # rename detection options for git-diff and git-diff-tree
163 # - default is '-M', with the cost proportional to
164 # (number of removed files) * (number of new files).
165 # - more costly is '-C' (which implies '-M'), with the cost proportional to
166 # (number of changed files + number of removed files) * (number of new files)
167 # - even more costly is '-C', '--find-copies-harder' with cost
168 # (number of files in the original tree) * (number of new files)
169 # - one might want to include '-B' option, e.g. '-B', '-M'
170 our @diff_opts = ('-M'); # taken from git_commit
172 # Disables features that would allow repository owners to inject script into
174 our $prevent_xss = 0;
176 # information about snapshot formats that gitweb is capable of serving
177 our %known_snapshot_formats = (
179 # 'display' => display name,
180 # 'type' => mime type,
181 # 'suffix' => filename suffix,
182 # 'format' => --format for git-archive,
183 # 'compressor' => [compressor command and arguments]
184 # (array reference, optional)}
187 'display' => 'tar.gz',
188 'type' => 'application/x-gzip',
189 'suffix' => '.tar.gz',
191 'compressor' => ['gzip']},
194 'display' => 'tar.bz2',
195 'type' => 'application/x-bzip2',
196 'suffix' => '.tar.bz2',
198 'compressor' => ['bzip2']},
202 'type' => 'application/x-zip',
207 # Aliases so we understand old gitweb.snapshot values in repository
209 our %known_snapshot_format_aliases = (
213 # backward compatibility: legacy gitweb config support
214 'x-gzip' => undef, 'gz' => undef,
215 'x-bzip2' => undef, 'bz2' => undef,
216 'x-zip' => undef, '' => undef,
219 my $feature_bool = sub {
221 my ($val) = git_get_project_config($key, '--bool');
225 } elsif ($val eq 'true') {
227 } elsif ($val eq 'false') {
232 my $feature_snapshot = sub {
235 my ($val) = git_get_project_config('snapshot');
238 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
244 my $feature_patches = sub {
245 my @val = (git_get_project_config('patches', '--int'));
255 # You define site-wide feature defaults here; override them with
256 # $GITWEB_CONFIG as necessary.
259 # 'sub' => feature-sub (subroutine),
260 # 'override' => allow-override (boolean),
261 # 'default' => [ default options...] (array reference)}
263 # if feature is overridable (it means that allow-override has true value),
264 # then feature-sub will be called with default options as parameters;
265 # return value of feature-sub indicates if to enable specified feature
267 # if there is no 'sub' key (no feature-sub), then feature cannot be
270 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
271 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
274 # Enable the 'blame' blob view, showing the last commit that modified
275 # each line in the file. This can be very CPU-intensive.
277 # To enable system wide have in $GITWEB_CONFIG
278 # $feature{'blame'}{'default'} = [1];
279 # To have project specific config enable override in $GITWEB_CONFIG
280 # $feature{'blame'}{'override'} = 1;
281 # and in project config gitweb.blame = 0|1;
283 'sub' => sub { &$feature_bool('blame', @_) },
287 # Enable the 'snapshot' link, providing a compressed archive of any
288 # tree. This can potentially generate high traffic if you have large
291 # Value is a list of formats defined in %known_snapshot_formats that
293 # To disable system wide have in $GITWEB_CONFIG
294 # $feature{'snapshot'}{'default'} = [];
295 # To have project specific config enable override in $GITWEB_CONFIG
296 # $feature{'snapshot'}{'override'} = 1;
297 # and in project config, a comma-separated list of formats or "none"
298 # to disable. Example: gitweb.snapshot = tbz2,zip;
300 'sub' => $feature_snapshot,
302 'default' => ['tgz']},
304 # Enable text search, which will list the commits which match author,
305 # committer or commit text to a given string. Enabled by default.
306 # Project specific override is not supported.
311 # Enable grep search, which will list the files in currently selected
312 # tree containing the given string. Enabled by default. This can be
313 # potentially CPU-intensive, of course.
315 # To enable system wide have in $GITWEB_CONFIG
316 # $feature{'grep'}{'default'} = [1];
317 # To have project specific config enable override in $GITWEB_CONFIG
318 # $feature{'grep'}{'override'} = 1;
319 # and in project config gitweb.grep = 0|1;
321 'sub' => sub { &$feature_bool('grep', @_) },
325 # Enable the pickaxe search, which will list the commits that modified
326 # a given string in a file. This can be practical and quite faster
327 # alternative to 'blame', but still potentially CPU-intensive.
329 # To enable system wide have in $GITWEB_CONFIG
330 # $feature{'pickaxe'}{'default'} = [1];
331 # To have project specific config enable override in $GITWEB_CONFIG
332 # $feature{'pickaxe'}{'override'} = 1;
333 # and in project config gitweb.pickaxe = 0|1;
335 'sub' => sub { &$feature_bool('pickaxe', @_) },
339 # Make gitweb use an alternative format of the URLs which can be
340 # more readable and natural-looking: project name is embedded
341 # directly in the path and the query string contains other
342 # auxiliary information. All gitweb installations recognize
343 # URL in either format; this configures in which formats gitweb
346 # To enable system wide have in $GITWEB_CONFIG
347 # $feature{'pathinfo'}{'default'} = [1];
348 # Project specific override is not supported.
350 # Note that you will need to change the default location of CSS,
351 # favicon, logo and possibly other files to an absolute URL. Also,
352 # if gitweb.cgi serves as your indexfile, you will need to force
353 # $my_uri to contain the script name in your $GITWEB_CONFIG.
358 # Make gitweb consider projects in project root subdirectories
359 # to be forks of existing projects. Given project $projname.git,
360 # projects matching $projname/*.git will not be shown in the main
361 # projects list, instead a '+' mark will be added to $projname
362 # there and a 'forks' view will be enabled for the project, listing
363 # all the forks. If project list is taken from a file, forks have
364 # to be listed after the main project.
366 # To enable system wide have in $GITWEB_CONFIG
367 # $feature{'forks'}{'default'} = [1];
368 # Project specific override is not supported.
373 # Insert custom links to the action bar of all project pages.
374 # This enables you mainly to link to third-party scripts integrating
375 # into gitweb; e.g. git-browser for graphical history representation
376 # or custom web-based repository administration interface.
378 # The 'default' value consists of a list of triplets in the form
379 # (label, link, position) where position is the label after which
380 # to insert the link and link is a format string where %n expands
381 # to the project name, %f to the project path within the filesystem,
382 # %h to the current hash (h gitweb parameter) and %b to the current
383 # hash base (hb gitweb parameter); %% expands to %.
385 # To enable system wide have in $GITWEB_CONFIG e.g.
386 # $feature{'actions'}{'default'} = [('graphiclog',
387 # '/git-browser/by-commit.html?r=%n', 'summary')];
388 # Project specific override is not supported.
393 # Allow gitweb scan project content tags described in ctags/
394 # of project repository, and display the popular Web 2.0-ish
395 # "tag cloud" near the project list. Note that this is something
396 # COMPLETELY different from the normal Git tags.
398 # gitweb by itself can show existing tags, but it does not handle
399 # tagging itself; you need an external application for that.
400 # For an example script, check Girocco's cgi/tagproj.cgi.
401 # You may want to install the HTML::TagCloud Perl module to get
402 # a pretty tag cloud instead of just a list of tags.
404 # To enable system wide have in $GITWEB_CONFIG
405 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
406 # Project specific override is not supported.
411 # The maximum number of patches in a patchset generated in patch
412 # view. Set this to 0 or undef to disable patch view, or to a
413 # negative number to remove any limit.
415 # To disable system wide have in $GITWEB_CONFIG
416 # $feature{'patches'}{'default'} = [0];
417 # To have project specific config enable override in $GITWEB_CONFIG
418 # $feature{'patches'}{'override'} = 1;
419 # and in project config gitweb.patches = 0|n;
420 # where n is the maximum number of patches allowed in a patchset.
422 'sub' => $feature_patches,
427 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "gitweb_config.perl";
428 if (-e $GITWEB_CONFIG) {
431 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || '../../gitweb.conf';
432 do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
435 # version of the core git binary
436 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
438 $projects_list ||= $projectroot;
440 # ======================================================================
441 # input validation and dispatch
443 # input parameters can be collected from a variety of sources (presently, CGI
444 # and PATH_INFO), so we define an %input_params hash that collects them all
445 # together during validation: this allows subsequent uses (e.g. href()) to be
446 # agnostic of the parameter origin
448 our %input_params = ();
450 # input parameters are stored with the long parameter name as key. This will
451 # also be used in the href subroutine to convert parameters to their CGI
452 # equivalent, and since the href() usage is the most frequent one, we store
453 # the name -> CGI key mapping here, instead of the reverse.
455 # XXX: Warning: If you touch this, check the search form for updating,
458 our @cgi_param_mapping = (
466 hash_parent_base => "hpb",
471 snapshot_format => "sf",
472 extra_options => "opt",
473 search_use_regexp => "sr",
475 our %cgi_param_mapping = @cgi_param_mapping;
477 # we will also need to know the possible actions, for validation
479 "blame" => \&git_blame,
480 "blobdiff" => \&git_blobdiff,
481 "blobdiff_plain" => \&git_blobdiff_plain,
482 "blob" => \&git_blob,
483 "blob_plain" => \&git_blob_plain,
484 "commitdiff" => \&git_commitdiff,
485 "commitdiff_plain" => \&git_commitdiff_plain,
486 "commit" => \&git_commit,
487 "forks" => \&git_forks,
488 "heads" => \&git_heads,
489 "history" => \&git_history,
491 "patch" => \&git_patch,
492 "patches" => \&git_patches,
494 "atom" => \&git_atom,
495 "search" => \&git_search,
496 "search_help" => \&git_search_help,
497 "shortlog" => \&git_shortlog,
498 "summary" => \&git_summary,
500 "tags" => \&git_tags,
501 "tree" => \&git_tree,
502 "snapshot" => \&git_snapshot,
503 "object" => \&git_object,
504 # those below don't need $project
505 "opml" => \&git_opml,
506 "project_list" => \&git_project_list,
507 "project_index" => \&git_project_index,
510 # finally, we have the hash of allowed extra_options for the commands that
512 our %allowed_options = (
513 "--no-merges" => [ qw(rss atom log shortlog history) ],
516 # fill %input_params with the CGI parameters. All values except for 'opt'
517 # should be single values, but opt can be an array. We should probably
518 # build an array of parameters that can be multi-valued, but since for the time
519 # being it's only this one, we just single it out
520 while (my ($name, $symbol) = each %cgi_param_mapping) {
521 if ($symbol eq 'opt') {
522 $input_params{$name} = [ $cgi->param($symbol) ];
524 $input_params{$name} = $cgi->param($symbol);
528 # now read PATH_INFO and update the parameter list for missing parameters
529 my $evaluate_path_info = sub {
530 return if defined $input_params{'project'};
531 return if !$path_info;
532 $path_info =~ s,^/+,,;
533 return if !$path_info;
535 # find which part of PATH_INFO is project
536 my $project = $path_info;
538 while ($project && !check_head_link("$projectroot/$project")) {
539 $project =~ s,/*[^/]*$,,;
541 return unless $project;
542 $input_params{'project'} = $project;
544 # do not change any parameters if an action is given using the query string
545 return if $input_params{'action'};
546 $path_info =~ s,^\Q$project\E/*,,;
548 # next, check if we have an action
549 my $action = $path_info;
551 if (exists $actions{$action}) {
552 $path_info =~ s,^$action/*,,;
553 $input_params{'action'} = $action;
556 # list of actions that want hash_base instead of hash, but can have no
557 # pathname (f) parameter
564 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
565 my ($parentrefname, $parentpathname, $refname, $pathname) =
566 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
568 # first, analyze the 'current' part
569 if (defined $pathname) {
570 # we got "branch:filename" or "branch:dir/"
571 # we could use git_get_type(branch:pathname), but:
572 # - it needs $git_dir
573 # - it does a git() call
574 # - the convention of terminating directories with a slash
575 # makes it superfluous
576 # - embedding the action in the PATH_INFO would make it even
578 $pathname =~ s,^/+,,;
579 if (!$pathname || substr($pathname, -1) eq "/") {
580 $input_params{'action'} ||= "tree";
583 # the default action depends on whether we had parent info
585 if ($parentrefname) {
586 $input_params{'action'} ||= "blobdiff_plain";
588 $input_params{'action'} ||= "blob_plain";
591 $input_params{'hash_base'} ||= $refname;
592 $input_params{'file_name'} ||= $pathname;
593 } elsif (defined $refname) {
594 # we got "branch". In this case we have to choose if we have to
595 # set hash or hash_base.
597 # Most of the actions without a pathname only want hash to be
598 # set, except for the ones specified in @wants_base that want
599 # hash_base instead. It should also be noted that hand-crafted
600 # links having 'history' as an action and no pathname or hash
601 # set will fail, but that happens regardless of PATH_INFO.
602 $input_params{'action'} ||= "shortlog";
603 if (grep { $_ eq $input_params{'action'} } @wants_base) {
604 $input_params{'hash_base'} ||= $refname;
606 $input_params{'hash'} ||= $refname;
610 # next, handle the 'parent' part, if present
611 if (defined $parentrefname) {
612 # a missing pathspec defaults to the 'current' filename, allowing e.g.
613 # someproject/blobdiff/oldrev..newrev:/filename
614 if ($parentpathname) {
615 $parentpathname =~ s,^/+,,;
616 $parentpathname =~ s,/$,,;
617 $input_params{'file_parent'} ||= $parentpathname;
619 $input_params{'file_parent'} ||= $input_params{'file_name'};
621 # we assume that hash_parent_base is wanted if a path was specified,
622 # or if the action wants hash_base instead of hash
623 if (defined $input_params{'file_parent'} ||
624 grep { $_ eq $input_params{'action'} } @wants_base) {
625 $input_params{'hash_parent_base'} ||= $parentrefname;
627 $input_params{'hash_parent'} ||= $parentrefname;
631 # for the snapshot action, we allow URLs in the form
632 # $project/snapshot/$hash.ext
633 # where .ext determines the snapshot and gets removed from the
634 # passed $refname to provide the $hash.
636 # To be able to tell that $refname includes the format extension, we
637 # require the following two conditions to be satisfied:
638 # - the hash input parameter MUST have been set from the $refname part
639 # of the URL (i.e. they must be equal)
640 # - the snapshot format MUST NOT have been defined already (e.g. from
642 # It's also useless to try any matching unless $refname has a dot,
643 # so we check for that too
644 if (defined $input_params{'action'} &&
645 $input_params{'action'} eq 'snapshot' &&
646 defined $refname && index($refname, '.') != -1 &&
647 $refname eq $input_params{'hash'} &&
648 !defined $input_params{'snapshot_format'}) {
649 # We loop over the known snapshot formats, checking for
650 # extensions. Allowed extensions are both the defined suffix
651 # (which includes the initial dot already) and the snapshot
652 # format key itself, with a prepended dot
653 while (my ($fmt, $opt) = each %known_snapshot_formats) {
656 $hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//;
657 next unless $sfx = $1;
658 # a valid suffix was found, so set the snapshot format
659 # and reset the hash parameter
660 $input_params{'snapshot_format'} = $fmt;
661 $input_params{'hash'} = $hash;
662 # we also set the format suffix to the one requested
663 # in the URL: this way a request for e.g. .tgz returns
664 # a .tgz instead of a .tar.gz
665 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
670 &$evaluate_path_info();
672 gitweb_validate_setup();
674 return $actions{$action};
677 sub gitweb_validate_setup {
678 our $action = $input_params{'action'};
679 if (defined $action) {
680 if (!validate_action($action)) {
681 die_error(400, "Invalid action parameter");
685 # parameters which are pathnames
686 our $project = $input_params{'project'};
687 if (defined $project) {
688 if (!validate_project($project)) {
690 die_error(404, "No such project");
694 our $file_name = $input_params{'file_name'};
695 if (defined $file_name) {
696 if (!validate_pathname($file_name)) {
697 die_error(400, "Invalid file parameter");
701 our $file_parent = $input_params{'file_parent'};
702 if (defined $file_parent) {
703 if (!validate_pathname($file_parent)) {
704 die_error(400, "Invalid file parent parameter");
708 # parameters which are refnames
709 our $hash = $input_params{'hash'};
711 if (!validate_refname($hash)) {
712 die_error(400, "Invalid hash parameter");
716 our $hash_parent = $input_params{'hash_parent'};
717 if (defined $hash_parent) {
718 if (!validate_refname($hash_parent)) {
719 die_error(400, "Invalid hash parent parameter");
723 our $hash_base = $input_params{'hash_base'};
724 if (defined $hash_base) {
725 if (!validate_refname($hash_base)) {
726 die_error(400, "Invalid hash base parameter");
730 our @extra_options = @{$input_params{'extra_options'}};
731 # @extra_options is always defined, since it can only be (currently) set from
732 # CGI, and $cgi->param() returns the empty array in array context if the param
734 foreach my $opt (@extra_options) {
735 if (not exists $allowed_options{$opt}) {
736 die_error(400, "Invalid option parameter");
738 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
739 die_error(400, "Invalid option parameter for this action");
743 our $hash_parent_base = $input_params{'hash_parent_base'};
744 if (defined $hash_parent_base) {
745 if (!validate_refname($hash_parent_base)) {
746 die_error(400, "Invalid hash parent base parameter");
751 our $page = $input_params{'page'};
753 if ($page =~ m/[^0-9]/) {
754 die_error(400, "Invalid page parameter");
758 our $searchtype = $input_params{'searchtype'};
759 if (defined $searchtype) {
760 if ($searchtype =~ m/[^a-z]/) {
761 die_error(400, "Invalid searchtype parameter");
765 our $search_use_regexp = $input_params{'search_use_regexp'};
767 our $searchtext = $input_params{'searchtext'};
769 if (defined $searchtext) {
770 if (length($searchtext) < 2) {
771 die_error(403, "At least two characters are required for search parameter");
773 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
776 # path to the current git repository
778 $git_dir = "$projectroot/$project" if $project;
780 # process alternate names for backward compatibility
781 # filter out unsupported (unknown) snapshot formats
782 my $filter_snapshot_fmts = sub {
786 exists $known_snapshot_format_aliases{$_} ?
787 $known_snapshot_format_aliases{$_} : $_} @fmts;
788 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
791 # list of supported snapshot formats
792 our @snapshot_fmts = gitweb_get_feature('snapshot');
793 @snapshot_fmts = &$filter_snapshot_fmts(@snapshot_fmts);
796 if (!defined $action) {
798 $action = git_get_type($hash);
799 } elsif (defined $hash_base && defined $file_name) {
800 $action = git_get_type("$hash_base:$file_name");
801 } elsif (defined $project) {
804 $action = 'project_list';
807 if (!defined($actions{$action})) {
808 die_error(400, "Unknown action");
810 if ($action !~ m/^(opml|project_list|project_index)$/ &&
812 die_error(400, "Project needed");
816 sub gitweb_get_feature {
818 return unless exists $feature{$name};
819 my ($sub, $override, @defaults) = (
820 $feature{$name}{'sub'},
821 $feature{$name}{'override'},
822 @{$feature{$name}{'default'}});
823 if (!$override) { return @defaults; }
825 warn "feature $name is not overrideable";
828 return $sub->(@defaults);
831 # A wrapper to check if a given feature is enabled.
832 # With this, you can say
834 # my $bool_feat = gitweb_check_feature('bool_feat');
835 # gitweb_check_feature('bool_feat') or somecode;
839 # my ($bool_feat) = gitweb_get_feature('bool_feat');
840 # (gitweb_get_feature('bool_feat'))[0] or somecode;
842 sub gitweb_check_feature {
843 return (gitweb_get_feature(@_))[0];
846 # checking HEAD file with -e is fragile if the repository was
847 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
849 sub check_head_link {
851 my $headfile = "$dir/HEAD";
852 return ((-e $headfile) ||
853 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
856 sub check_export_ok {
858 return (check_head_link($dir) &&
859 (!$export_ok || -e "$dir/$export_ok") &&
860 (!$export_auth_hook || $export_auth_hook->($dir)));
864 ## ======================================================================
869 # default is to use -absolute url() i.e. $my_uri
870 my $href = $params{-full} ? $my_url : $my_uri;
872 $params{'project'} = $project unless exists $params{'project'};
874 if ($params{-replay}) {
875 while (my ($name, $symbol) = each %cgi_param_mapping) {
876 if (!exists $params{$name}) {
877 $params{$name} = $input_params{$name};
882 my $use_pathinfo = gitweb_check_feature('pathinfo');
883 if ($use_pathinfo and defined $params{'project'}) {
884 # try to put as many parameters as possible in PATH_INFO:
887 # - hash_parent or hash_parent_base:/file_parent
888 # - hash or hash_base:/filename
889 # - the snapshot_format as an appropriate suffix
891 # When the script is the root DirectoryIndex for the domain,
892 # $href here would be something like http://gitweb.example.com/
893 # Thus, we strip any trailing / from $href, to spare us double
894 # slashes in the final URL
897 # Then add the project name, if present
898 $href .= "/".esc_url($params{'project'});
899 delete $params{'project'};
901 # since we destructively absorb parameters, we keep this
902 # boolean that remembers if we're handling a snapshot
903 my $is_snapshot = $params{'action'} eq 'snapshot';
905 # Summary just uses the project path URL, any other action is
907 if (defined $params{'action'}) {
908 $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
909 delete $params{'action'};
912 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
913 # stripping nonexistent or useless pieces
914 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
915 || $params{'hash_parent'} || $params{'hash'});
916 if (defined $params{'hash_base'}) {
917 if (defined $params{'hash_parent_base'}) {
918 $href .= esc_url($params{'hash_parent_base'});
919 # skip the file_parent if it's the same as the file_name
920 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
921 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
922 $href .= ":/".esc_url($params{'file_parent'});
923 delete $params{'file_parent'};
926 delete $params{'hash_parent'};
927 delete $params{'hash_parent_base'};
928 } elsif (defined $params{'hash_parent'}) {
929 $href .= esc_url($params{'hash_parent'}). "..";
930 delete $params{'hash_parent'};
933 $href .= esc_url($params{'hash_base'});
934 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
935 $href .= ":/".esc_url($params{'file_name'});
936 delete $params{'file_name'};
938 delete $params{'hash'};
939 delete $params{'hash_base'};
940 } elsif (defined $params{'hash'}) {
941 $href .= esc_url($params{'hash'});
942 delete $params{'hash'};
945 # If the action was a snapshot, we can absorb the
946 # snapshot_format parameter too
948 my $fmt = $params{'snapshot_format'};
949 # snapshot_format should always be defined when href()
950 # is called, but just in case some code forgets, we
951 # fall back to the default
952 $fmt ||= $snapshot_fmts[0];
953 $href .= $known_snapshot_formats{$fmt}{'suffix'};
954 delete $params{'snapshot_format'};
958 # now encode the parameters explicitly
960 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
961 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
962 if (defined $params{$name}) {
963 if (ref($params{$name}) eq "ARRAY") {
964 foreach my $par (@{$params{$name}}) {
965 push @result, $symbol . "=" . esc_param($par);
968 push @result, $symbol . "=" . esc_param($params{$name});
972 $href .= "?" . join(';', @result) if scalar @result;
978 ## ======================================================================
979 ## validation, quoting/unquoting and escaping
981 sub validate_action {
982 my $input = shift || return undef;
983 return undef unless exists $actions{$input};
987 sub validate_project {
988 my $input = shift || return undef;
989 if (!validate_pathname($input) ||
990 !(-d "$projectroot/$input") ||
991 !check_export_ok("$projectroot/$input") ||
992 ($strict_export && !project_in_list($input))) {
999 sub validate_pathname {
1000 my $input = shift || return undef;
1002 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1003 # at the beginning, at the end, and between slashes.
1004 # also this catches doubled slashes
1005 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1008 # no null characters
1009 if ($input =~ m!\0!) {
1015 sub validate_refname {
1016 my $input = shift || return undef;
1018 # textual hashes are O.K.
1019 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1022 # it must be correct pathname
1023 $input = validate_pathname($input)
1025 # restrictions on ref name according to git-check-ref-format
1026 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1032 # decode sequences of octets in utf8 into Perl's internal form,
1033 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1034 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1037 if (utf8::valid($str)) {
1041 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
1045 # quote unsafe chars, but keep the slash, even when it's not
1046 # correct, but quoted slashes look too horrible in bookmarks
1049 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
1055 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1058 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
1064 # replace invalid utf8 character with SUBSTITUTION sequence
1065 sub esc_html ($;%) {
1069 $str = to_utf8($str);
1070 $str = $cgi->escapeHTML($str);
1071 if ($opts{'-nbsp'}) {
1072 $str =~ s/ / /g;
1074 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
1078 # quote control characters and escape filename to HTML
1083 $str = to_utf8($str);
1084 $str = $cgi->escapeHTML($str);
1085 if ($opts{'-nbsp'}) {
1086 $str =~ s/ / /g;
1088 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
1092 # Make control characters "printable", using character escape codes (CEC)
1096 my %es = ( # character escape codes, aka escape sequences
1097 "\t" => '\t', # tab (HT)
1098 "\n" => '\n', # line feed (LF)
1099 "\r" => '\r', # carrige return (CR)
1100 "\f" => '\f', # form feed (FF)
1101 "\b" => '\b', # backspace (BS)
1102 "\a" => '\a', # alarm (bell) (BEL)
1103 "\e" => '\e', # escape (ESC)
1104 "\013" => '\v', # vertical tab (VT)
1105 "\000" => '\0', # nul character (NUL)
1107 my $chr = ( (exists $es{$cntrl})
1109 : sprintf('\%2x', ord($cntrl)) );
1110 if ($opts{-nohtml}) {
1113 return "<span class=\"cntrl\">$chr</span>";
1117 # Alternatively use unicode control pictures codepoints,
1118 # Unicode "printable representation" (PR)
1123 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1124 if ($opts{-nohtml}) {
1127 return "<span class=\"cntrl\">$chr</span>";
1131 # git may return quoted and escaped filenames
1137 my %es = ( # character escape codes, aka escape sequences
1138 't' => "\t", # tab (HT, TAB)
1139 'n' => "\n", # newline (NL)
1140 'r' => "\r", # return (CR)
1141 'f' => "\f", # form feed (FF)
1142 'b' => "\b", # backspace (BS)
1143 'a' => "\a", # alarm (bell) (BEL)
1144 'e' => "\e", # escape (ESC)
1145 'v' => "\013", # vertical tab (VT)
1148 if ($seq =~ m/^[0-7]{1,3}$/) {
1149 # octal char sequence
1150 return chr(oct($seq));
1151 } elsif (exists $es{$seq}) {
1152 # C escape sequence, aka character escape code
1155 # quoted ordinary character
1159 if ($str =~ m/^"(.*)"$/) {
1162 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1167 # escape tabs (convert tabs to spaces)
1171 while ((my $pos = index($line, "\t")) != -1) {
1172 if (my $count = (8 - ($pos % 8))) {
1173 my $spaces = ' ' x $count;
1174 $line =~ s/\t/$spaces/;
1181 sub project_in_list {
1182 my $project = shift;
1183 my @list = git_get_projects_list();
1184 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1187 ## ----------------------------------------------------------------------
1188 ## HTML aware string manipulation
1190 # Try to chop given string on a word boundary between position
1191 # $len and $len+$add_len. If there is no word boundary there,
1192 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1193 # (marking chopped part) would be longer than given string.
1197 my $add_len = shift || 10;
1198 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1200 # Make sure perl knows it is utf8 encoded so we don't
1201 # cut in the middle of a utf8 multibyte char.
1202 $str = to_utf8($str);
1204 # allow only $len chars, but don't cut a word if it would fit in $add_len
1205 # if it doesn't fit, cut it if it's still longer than the dots we would add
1206 # remove chopped character entities entirely
1208 # when chopping in the middle, distribute $len into left and right part
1209 # return early if chopping wouldn't make string shorter
1210 if ($where eq 'center') {
1211 return $str if ($len + 5 >= length($str)); # filler is length 5
1214 return $str if ($len + 4 >= length($str)); # filler is length 4
1217 # regexps: ending and beginning with word part up to $add_len
1218 my $endre = qr/.{$len}\w{0,$add_len}/;
1219 my $begre = qr/\w{0,$add_len}.{$len}/;
1221 if ($where eq 'left') {
1222 $str =~ m/^(.*?)($begre)$/;
1223 my ($lead, $body) = ($1, $2);
1224 if (length($lead) > 4) {
1225 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1228 return "$lead$body";
1230 } elsif ($where eq 'center') {
1231 $str =~ m/^($endre)(.*)$/;
1232 my ($left, $str) = ($1, $2);
1233 $str =~ m/^(.*?)($begre)$/;
1234 my ($mid, $right) = ($1, $2);
1235 if (length($mid) > 5) {
1236 $left =~ s/&[^;]*$//;
1237 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1240 return "$left$mid$right";
1243 $str =~ m/^($endre)(.*)$/;
1246 if (length($tail) > 4) {
1247 $body =~ s/&[^;]*$//;
1250 return "$body$tail";
1254 # takes the same arguments as chop_str, but also wraps a <span> around the
1255 # result with a title attribute if it does get chopped. Additionally, the
1256 # string is HTML-escaped.
1257 sub chop_and_escape_str {
1260 my $chopped = chop_str(@_);
1261 if ($chopped eq $str) {
1262 return esc_html($chopped);
1264 $str =~ s/([[:cntrl:]])/?/g;
1265 return $cgi->span({-title=>$str}, esc_html($chopped));
1269 ## ----------------------------------------------------------------------
1270 ## functions returning short strings
1272 # CSS class for given age value (in seconds)
1276 if (!defined $age) {
1278 } elsif ($age < 60*60*2) {
1280 } elsif ($age < 60*60*24*2) {
1287 # convert age in seconds to "nn units ago" string
1292 if ($age > 60*60*24*365*2) {
1293 $age_str = (int $age/60/60/24/365);
1294 $age_str .= " years ago";
1295 } elsif ($age > 60*60*24*(365/12)*2) {
1296 $age_str = int $age/60/60/24/(365/12);
1297 $age_str .= " months ago";
1298 } elsif ($age > 60*60*24*7*2) {
1299 $age_str = int $age/60/60/24/7;
1300 $age_str .= " weeks ago";
1301 } elsif ($age > 60*60*24*2) {
1302 $age_str = int $age/60/60/24;
1303 $age_str .= " days ago";
1304 } elsif ($age > 60*60*2) {
1305 $age_str = int $age/60/60;
1306 $age_str .= " hours ago";
1307 } elsif ($age > 60*2) {
1308 $age_str = int $age/60;
1309 $age_str .= " min ago";
1310 } elsif ($age > 2) {
1311 $age_str = int $age;
1312 $age_str .= " sec ago";
1314 $age_str .= " right now";
1320 S_IFINVALID => 0030000,
1321 S_IFGITLINK => 0160000,
1324 # submodule/subproject, a commit object reference
1325 sub S_ISGITLINK($) {
1328 return (($mode & S_IFMT) == S_IFGITLINK)
1331 # convert file mode in octal to symbolic file mode string
1333 my $mode = oct shift;
1335 if (S_ISGITLINK($mode)) {
1336 return 'm---------';
1337 } elsif (S_ISDIR($mode & S_IFMT)) {
1338 return 'drwxr-xr-x';
1339 } elsif (S_ISLNK($mode)) {
1340 return 'lrwxrwxrwx';
1341 } elsif (S_ISREG($mode)) {
1342 # git cares only about the executable bit
1343 if ($mode & S_IXUSR) {
1344 return '-rwxr-xr-x';
1346 return '-rw-r--r--';
1349 return '----------';
1353 # convert file mode in octal to file type string
1357 if ($mode !~ m/^[0-7]+$/) {
1363 if (S_ISGITLINK($mode)) {
1365 } elsif (S_ISDIR($mode & S_IFMT)) {
1367 } elsif (S_ISLNK($mode)) {
1369 } elsif (S_ISREG($mode)) {
1376 # convert file mode in octal to file type description string
1377 sub file_type_long {
1380 if ($mode !~ m/^[0-7]+$/) {
1386 if (S_ISGITLINK($mode)) {
1388 } elsif (S_ISDIR($mode & S_IFMT)) {
1390 } elsif (S_ISLNK($mode)) {
1392 } elsif (S_ISREG($mode)) {
1393 if ($mode & S_IXUSR) {
1394 return "executable";
1404 ## ----------------------------------------------------------------------
1405 ## functions returning short HTML fragments, or transforming HTML fragments
1406 ## which don't belong to other sections
1408 # format line of commit message.
1409 sub format_log_line_html {
1412 $line = esc_html($line, -nbsp=>1);
1413 $line =~ s{\b([0-9a-fA-F]{8,40})\b}{
1414 $cgi->a({-href => href(action=>"object", hash=>$1),
1415 -class => "text"}, $1);
1421 # format marker of refs pointing to given object
1423 # the destination action is chosen based on object type and current context:
1424 # - for annotated tags, we choose the tag view unless it's the current view
1425 # already, in which case we go to shortlog view
1426 # - for other refs, we keep the current view if we're in history, shortlog or
1427 # log view, and select shortlog otherwise
1428 sub format_ref_marker {
1429 my ($refs, $id) = @_;
1432 if (defined $refs->{$id}) {
1433 foreach my $ref (@{$refs->{$id}}) {
1434 # this code exploits the fact that non-lightweight tags are the
1435 # only indirect objects, and that they are the only objects for which
1436 # we want to use tag instead of shortlog as action
1437 my ($type, $name) = qw();
1438 my $indirect = ($ref =~ s/\^\{\}$//);
1439 # e.g. tags/v2.6.11 or heads/next
1440 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1449 $class .= " indirect" if $indirect;
1451 my $dest_action = "shortlog";
1454 $dest_action = "tag" unless $action eq "tag";
1455 } elsif ($action =~ /^(history|(short)?log)$/) {
1456 $dest_action = $action;
1460 $dest .= "refs/" unless $ref =~ m!^refs/!;
1463 my $link = $cgi->a({
1465 action=>$dest_action,
1469 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1475 return ' <span class="refs">'. $markers . '</span>';
1481 # format, perhaps shortened and with markers, title line
1482 sub format_subject_html {
1483 my ($long, $short, $href, $extra) = @_;
1484 $extra = '' unless defined($extra);
1486 if (length($short) < length($long)) {
1487 return $cgi->a({-href => $href, -class => "list subject",
1488 -title => to_utf8($long)},
1489 esc_html($short) . $extra);
1491 return $cgi->a({-href => $href, -class => "list subject"},
1492 esc_html($long) . $extra);
1496 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1497 sub format_git_diff_header_line {
1499 my $diffinfo = shift;
1500 my ($from, $to) = @_;
1502 if ($diffinfo->{'nparents'}) {
1504 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1505 if ($to->{'href'}) {
1506 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1507 esc_path($to->{'file'}));
1508 } else { # file was deleted (no href)
1509 $line .= esc_path($to->{'file'});
1513 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1514 if ($from->{'href'}) {
1515 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1516 'a/' . esc_path($from->{'file'}));
1517 } else { # file was added (no href)
1518 $line .= 'a/' . esc_path($from->{'file'});
1521 if ($to->{'href'}) {
1522 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1523 'b/' . esc_path($to->{'file'}));
1524 } else { # file was deleted
1525 $line .= 'b/' . esc_path($to->{'file'});
1529 return "<div class=\"diff header\">$line</div>\n";
1532 # format extended diff header line, before patch itself
1533 sub format_extended_diff_header_line {
1535 my $diffinfo = shift;
1536 my ($from, $to) = @_;
1539 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1540 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1541 esc_path($from->{'file'}));
1543 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1544 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1545 esc_path($to->{'file'}));
1547 # match single <mode>
1548 if ($line =~ m/\s(\d{6})$/) {
1549 $line .= '<span class="info"> (' .
1550 file_type_long($1) .
1554 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1555 # can match only for combined diff
1557 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1558 if ($from->{'href'}[$i]) {
1559 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1561 substr($diffinfo->{'from_id'}[$i],0,7));
1566 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1569 if ($to->{'href'}) {
1570 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1571 substr($diffinfo->{'to_id'},0,7));
1576 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1577 # can match only for ordinary diff
1578 my ($from_link, $to_link);
1579 if ($from->{'href'}) {
1580 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1581 substr($diffinfo->{'from_id'},0,7));
1583 $from_link = '0' x 7;
1585 if ($to->{'href'}) {
1586 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1587 substr($diffinfo->{'to_id'},0,7));
1591 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1592 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1595 return $line . "<br/>\n";
1598 # format from-file/to-file diff header
1599 sub format_diff_from_to_header {
1600 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1605 #assert($line =~ m/^---/) if DEBUG;
1606 # no extra formatting for "^--- /dev/null"
1607 if (! $diffinfo->{'nparents'}) {
1608 # ordinary (single parent) diff
1609 if ($line =~ m!^--- "?a/!) {
1610 if ($from->{'href'}) {
1612 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1613 esc_path($from->{'file'}));
1616 esc_path($from->{'file'});
1619 $result .= qq!<div class="diff from_file">$line</div>\n!;
1622 # combined diff (merge commit)
1623 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1624 if ($from->{'href'}[$i]) {
1626 $cgi->a({-href=>href(action=>"blobdiff",
1627 hash_parent=>$diffinfo->{'from_id'}[$i],
1628 hash_parent_base=>$parents[$i],
1629 file_parent=>$from->{'file'}[$i],
1630 hash=>$diffinfo->{'to_id'},
1632 file_name=>$to->{'file'}),
1634 -title=>"diff" . ($i+1)},
1637 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1638 esc_path($from->{'file'}[$i]));
1640 $line = '--- /dev/null';
1642 $result .= qq!<div class="diff from_file">$line</div>\n!;
1647 #assert($line =~ m/^\+\+\+/) if DEBUG;
1648 # no extra formatting for "^+++ /dev/null"
1649 if ($line =~ m!^\+\+\+ "?b/!) {
1650 if ($to->{'href'}) {
1652 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1653 esc_path($to->{'file'}));
1656 esc_path($to->{'file'});
1659 $result .= qq!<div class="diff to_file">$line</div>\n!;
1664 # create note for patch simplified by combined diff
1665 sub format_diff_cc_simplified {
1666 my ($diffinfo, @parents) = @_;
1669 $result .= "<div class=\"diff header\">" .
1671 if (!is_deleted($diffinfo)) {
1672 $result .= $cgi->a({-href => href(action=>"blob",
1674 hash=>$diffinfo->{'to_id'},
1675 file_name=>$diffinfo->{'to_file'}),
1677 esc_path($diffinfo->{'to_file'}));
1679 $result .= esc_path($diffinfo->{'to_file'});
1681 $result .= "</div>\n" . # class="diff header"
1682 "<div class=\"diff nodifferences\">" .
1684 "</div>\n"; # class="diff nodifferences"
1689 # format patch (diff) line (not to be used for diff headers)
1690 sub format_diff_line {
1692 my ($from, $to) = @_;
1693 my $diff_class = "";
1697 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1699 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1700 if ($line =~ m/^\@{3}/) {
1701 $diff_class = " chunk_header";
1702 } elsif ($line =~ m/^\\/) {
1703 $diff_class = " incomplete";
1704 } elsif ($prefix =~ tr/+/+/) {
1705 $diff_class = " add";
1706 } elsif ($prefix =~ tr/-/-/) {
1707 $diff_class = " rem";
1710 # assume ordinary diff
1711 my $char = substr($line, 0, 1);
1713 $diff_class = " add";
1714 } elsif ($char eq '-') {
1715 $diff_class = " rem";
1716 } elsif ($char eq '@') {
1717 $diff_class = " chunk_header";
1718 } elsif ($char eq "\\") {
1719 $diff_class = " incomplete";
1722 $line = untabify($line);
1723 if ($from && $to && $line =~ m/^\@{2} /) {
1724 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1725 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1727 $from_lines = 0 unless defined $from_lines;
1728 $to_lines = 0 unless defined $to_lines;
1730 if ($from->{'href'}) {
1731 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1732 -class=>"list"}, $from_text);
1734 if ($to->{'href'}) {
1735 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1736 -class=>"list"}, $to_text);
1738 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1739 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1740 return "<div class=\"diff$diff_class\">$line</div>\n";
1741 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1742 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1743 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1745 @from_text = split(' ', $ranges);
1746 for (my $i = 0; $i < @from_text; ++$i) {
1747 ($from_start[$i], $from_nlines[$i]) =
1748 (split(',', substr($from_text[$i], 1)), 0);
1751 $to_text = pop @from_text;
1752 $to_start = pop @from_start;
1753 $to_nlines = pop @from_nlines;
1755 $line = "<span class=\"chunk_info\">$prefix ";
1756 for (my $i = 0; $i < @from_text; ++$i) {
1757 if ($from->{'href'}[$i]) {
1758 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1759 -class=>"list"}, $from_text[$i]);
1761 $line .= $from_text[$i];
1765 if ($to->{'href'}) {
1766 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1767 -class=>"list"}, $to_text);
1771 $line .= " $prefix</span>" .
1772 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1773 return "<div class=\"diff$diff_class\">$line</div>\n";
1775 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1778 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1779 # linked. Pass the hash of the tree/commit to snapshot.
1780 sub format_snapshot_links {
1782 my $num_fmts = @snapshot_fmts;
1783 if ($num_fmts > 1) {
1784 # A parenthesized list of links bearing format names.
1785 # e.g. "snapshot (_tar.gz_ _zip_)"
1786 return "snapshot (" . join(' ', map
1793 }, $known_snapshot_formats{$_}{'display'})
1794 , @snapshot_fmts) . ")";
1795 } elsif ($num_fmts == 1) {
1796 # A single "snapshot" link whose tooltip bears the format name.
1798 my ($fmt) = @snapshot_fmts;
1804 snapshot_format=>$fmt
1806 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1808 } else { # $num_fmts == 0
1813 ## ......................................................................
1814 ## functions returning values to be passed, perhaps after some
1815 ## transformation, to other functions; e.g. returning arguments to href()
1817 # returns hash to be passed to href to generate gitweb URL
1818 # in -title key it returns description of link
1820 my $format = shift || 'Atom';
1821 my %res = (action => lc($format));
1823 # feed links are possible only for project views
1824 return unless (defined $project);
1825 # some views should link to OPML, or to generic project feed,
1826 # or don't have specific feed yet (so they should use generic)
1827 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1830 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1831 # from tag links; this also makes possible to detect branch links
1832 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1833 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1836 # find log type for feed description (title)
1838 if (defined $file_name) {
1839 $type = "history of $file_name";
1840 $type .= "/" if ($action eq 'tree');
1841 $type .= " on '$branch'" if (defined $branch);
1843 $type = "log of $branch" if (defined $branch);
1846 $res{-title} = $type;
1847 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1848 $res{'file_name'} = $file_name;
1853 ## ----------------------------------------------------------------------
1854 ## git utility subroutines, invoking git commands
1856 # returns path to the core git executable and the --git-dir parameter as list
1858 return $GIT, '--git-dir='.$git_dir;
1861 # quote the given arguments for passing them to the shell
1862 # quote_command("command", "arg 1", "arg with ' and ! characters")
1863 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1864 # Try to avoid using this function wherever possible.
1867 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1870 # get HEAD ref of given project as hash
1871 sub git_get_head_hash {
1872 my $project = shift;
1873 my $o_git_dir = $git_dir;
1875 $git_dir = "$projectroot/$project";
1876 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1879 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1883 if (defined $o_git_dir) {
1884 $git_dir = $o_git_dir;
1889 # get type of given object
1893 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1895 close $fd or return;
1900 # repository configuration
1901 our $config_file = '';
1904 # store multiple values for single key as anonymous array reference
1905 # single values stored directly in the hash, not as [ <value> ]
1906 sub hash_set_multi {
1907 my ($hash, $key, $value) = @_;
1909 if (!exists $hash->{$key}) {
1910 $hash->{$key} = $value;
1911 } elsif (!ref $hash->{$key}) {
1912 $hash->{$key} = [ $hash->{$key}, $value ];
1914 push @{$hash->{$key}}, $value;
1918 # return hash of git project configuration
1919 # optionally limited to some section, e.g. 'gitweb'
1920 sub git_parse_project_config {
1921 my $section_regexp = shift;
1926 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
1929 while (my $keyval = <$fh>) {
1931 my ($key, $value) = split(/\n/, $keyval, 2);
1933 hash_set_multi(\%config, $key, $value)
1934 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1941 # convert config value to boolean: 'true' or 'false'
1942 # no value, number > 0, 'true' and 'yes' values are true
1943 # rest of values are treated as false (never as error)
1944 sub config_to_bool {
1947 return 1 if !defined $val; # section.key
1949 # strip leading and trailing whitespace
1953 return (($val =~ /^\d+$/ && $val) || # section.key = 1
1954 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1957 # convert config value to simple decimal number
1958 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1959 # to be multiplied by 1024, 1048576, or 1073741824
1963 # strip leading and trailing whitespace
1967 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1969 # unknown unit is treated as 1
1970 return $num * ($unit eq 'g' ? 1073741824 :
1971 $unit eq 'm' ? 1048576 :
1972 $unit eq 'k' ? 1024 : 1);
1977 # convert config value to array reference, if needed
1978 sub config_to_multi {
1981 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1984 sub git_get_project_config {
1985 my ($key, $type) = @_;
1988 return unless ($key);
1989 $key =~ s/^gitweb\.//;
1990 return if ($key =~ m/\W/);
1993 if (defined $type) {
1996 unless ($type eq 'bool' || $type eq 'int');
2000 if (!defined $config_file ||
2001 $config_file ne "$git_dir/config") {
2002 %config = git_parse_project_config('gitweb');
2003 $config_file = "$git_dir/config";
2006 # check if config variable (key) exists
2007 return unless exists $config{"gitweb.$key"};
2010 if (!defined $type) {
2011 return $config{"gitweb.$key"};
2012 } elsif ($type eq 'bool') {
2013 # backward compatibility: 'git config --bool' returns true/false
2014 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
2015 } elsif ($type eq 'int') {
2016 return config_to_int($config{"gitweb.$key"});
2018 return $config{"gitweb.$key"};
2021 # get hash of given path at given ref
2022 sub git_get_hash_by_path {
2024 my $path = shift || return undef;
2029 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
2030 or die_error(500, "Open git-ls-tree failed");
2032 close $fd or return undef;
2034 if (!defined $line) {
2035 # there is no tree or hash given by $path at $base
2039 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2040 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2041 if (defined $type && $type ne $2) {
2042 # type doesn't match
2048 # get path of entry with given hash at given tree-ish (ref)
2049 # used to get 'from' filename for combined diff (merge commit) for renames
2050 sub git_get_path_by_hash {
2051 my $base = shift || return;
2052 my $hash = shift || return;
2056 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
2058 while (my $line = <$fd>) {
2061 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2062 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2063 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2072 ## ......................................................................
2073 ## git utility functions, directly accessing git repository
2075 sub git_get_project_description {
2078 $git_dir = "$projectroot/$path";
2079 open my $fd, "$git_dir/description"
2080 or return git_get_project_config('description');
2083 if (defined $descr) {
2089 sub git_get_project_ctags {
2093 $git_dir = "$projectroot/$path";
2094 unless (opendir D, "$git_dir/ctags") {
2097 foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
2098 open CT, $_ or next;
2102 my $ctag = $_; $ctag =~ s#.*/##;
2103 $ctags->{$ctag} = $val;
2109 sub git_populate_project_tagcloud {
2112 # First, merge different-cased tags; tags vote on casing
2114 foreach (keys %$ctags) {
2115 $ctags_lc{lc $_}->{count} += $ctags->{$_};
2116 if (not $ctags_lc{lc $_}->{topcount}
2117 or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) {
2118 $ctags_lc{lc $_}->{topcount} = $ctags->{$_};
2119 $ctags_lc{lc $_}->{topname} = $_;
2124 if (eval { require HTML::TagCloud; 1; }) {
2125 $cloud = HTML::TagCloud->new;
2126 foreach (sort keys %ctags_lc) {
2127 # Pad the title with spaces so that the cloud looks
2129 my $title = $ctags_lc{$_}->{topname};
2130 $title =~ s/ / /g;
2131 $title =~ s/^/ /g;
2132 $title =~ s/$/ /g;
2133 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
2136 $cloud = \%ctags_lc;
2141 sub git_show_project_tagcloud {
2142 my ($cloud, $count) = @_;
2143 #print STDERR ref($cloud)."..\n";
2144 if (ref $cloud eq 'HTML::TagCloud') {
2145 return $cloud->html_and_css($count);
2147 my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud;
2148 return '<p align="center">' . join (', ', map {
2149 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2150 } splice(@tags, 0, $count)) . '</p>';
2154 sub git_get_project_url_list {
2157 $git_dir = "$projectroot/$path";
2158 open my $fd, "$git_dir/cloneurl"
2159 or return wantarray ?
2160 @{ config_to_multi(git_get_project_config('url')) } :
2161 config_to_multi(git_get_project_config('url'));
2162 my @git_project_url_list = map { chomp; $_ } <$fd>;
2165 return wantarray ? @git_project_url_list : \@git_project_url_list;
2168 sub git_get_projects_list {
2173 $filter =~ s/\.git$//;
2175 my $check_forks = gitweb_check_feature('forks');
2177 if (-d $projects_list) {
2178 # search in directory
2179 my $dir = $projects_list . ($filter ? "/$filter" : '');
2180 # remove the trailing "/"
2182 my $pfxlen = length("$dir");
2183 my $pfxdepth = ($dir =~ tr!/!!);
2186 follow_fast => 1, # follow symbolic links
2187 follow_skip => 2, # ignore duplicates
2188 dangling_symlinks => 0, # ignore dangling symlinks, silently
2190 # skip project-list toplevel, if we get it.
2191 return if (m!^[/.]$!);
2192 # only directories can be git repositories
2193 return unless (-d $_);
2194 # don't traverse too deep (Find is super slow on os x)
2195 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2196 $File::Find::prune = 1;
2200 my $subdir = substr($File::Find::name, $pfxlen + 1);
2201 # we check related file in $projectroot
2202 my $path = ($filter ? "$filter/" : '') . $subdir;
2203 if (check_export_ok("$projectroot/$path")) {
2204 push @list, { path => $path };
2205 $File::Find::prune = 1;
2210 } elsif (-f $projects_list) {
2211 # read from file(url-encoded):
2212 # 'git%2Fgit.git Linus+Torvalds'
2213 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2214 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2216 open my ($fd), $projects_list or return;
2218 while (my $line = <$fd>) {
2220 my ($path, $owner) = split ' ', $line;
2221 $path = unescape($path);
2222 $owner = unescape($owner);
2223 if (!defined $path) {
2226 if ($filter ne '') {
2227 # looking for forks;
2228 my $pfx = substr($path, 0, length($filter));
2229 if ($pfx ne $filter) {
2232 my $sfx = substr($path, length($filter));
2233 if ($sfx !~ /^\/.*\.git$/) {
2236 } elsif ($check_forks) {
2238 foreach my $filter (keys %paths) {
2239 # looking for forks;
2240 my $pfx = substr($path, 0, length($filter));
2241 if ($pfx ne $filter) {
2244 my $sfx = substr($path, length($filter));
2245 if ($sfx !~ /^\/.*\.git$/) {
2248 # is a fork, don't include it in
2253 if (check_export_ok("$projectroot/$path")) {
2256 owner => to_utf8($owner),
2259 (my $forks_path = $path) =~ s/\.git$//;
2260 $paths{$forks_path}++;
2268 our $gitweb_project_owner = undef;
2269 sub git_get_project_list_from_file {
2271 return if (defined $gitweb_project_owner);
2273 $gitweb_project_owner = {};
2274 # read from file (url-encoded):
2275 # 'git%2Fgit.git Linus+Torvalds'
2276 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2277 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2278 if (-f $projects_list) {
2279 open (my $fd , $projects_list);
2280 while (my $line = <$fd>) {
2282 my ($pr, $ow) = split ' ', $line;
2283 $pr = unescape($pr);
2284 $ow = unescape($ow);
2285 $gitweb_project_owner->{$pr} = to_utf8($ow);
2291 sub git_get_project_owner {
2292 my $project = shift;
2295 return undef unless $project;
2296 $git_dir = "$projectroot/$project";
2298 if (!defined $gitweb_project_owner) {
2299 git_get_project_list_from_file();
2302 if (exists $gitweb_project_owner->{$project}) {
2303 $owner = $gitweb_project_owner->{$project};
2305 if (!defined $owner){
2306 $owner = git_get_project_config('owner');
2308 if (!defined $owner) {
2309 $owner = get_file_owner("$git_dir");
2315 sub git_get_last_activity {
2319 $git_dir = "$projectroot/$path";
2320 open($fd, "-|", git_cmd(), 'for-each-ref',
2321 '--format=%(committer)',
2322 '--sort=-committerdate',
2324 'refs/heads') or return;
2325 my $most_recent = <$fd>;
2326 close $fd or return;
2327 if (defined $most_recent &&
2328 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2330 my $age = time - $timestamp;
2331 return ($age, age_string($age));
2333 return (undef, undef);
2336 sub git_get_references {
2337 my $type = shift || "";
2339 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2340 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2341 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
2342 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2345 while (my $line = <$fd>) {
2347 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2348 if (defined $refs{$1}) {
2349 push @{$refs{$1}}, $2;
2355 close $fd or return;
2359 sub git_get_rev_name_tags {
2360 my $hash = shift || return undef;
2362 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
2364 my $name_rev = <$fd>;
2367 if ($name_rev =~ m|^$hash tags/(.*)$|) {
2370 # catches also '$hash undefined' output
2375 ## ----------------------------------------------------------------------
2376 ## parse to hash functions
2380 my $tz = shift || "-0000";
2383 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2384 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2385 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2386 $date{'hour'} = $hour;
2387 $date{'minute'} = $min;
2388 $date{'mday'} = $mday;
2389 $date{'day'} = $days[$wday];
2390 $date{'month'} = $months[$mon];
2391 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2392 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2393 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2394 $mday, $months[$mon], $hour ,$min;
2395 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2396 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2398 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2399 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2400 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2401 $date{'hour_local'} = $hour;
2402 $date{'minute_local'} = $min;
2403 $date{'tz_local'} = $tz;
2404 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2405 1900+$year, $mon+1, $mday,
2406 $hour, $min, $sec, $tz);
2415 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
2416 $tag{'id'} = $tag_id;
2417 while (my $line = <$fd>) {
2419 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2420 $tag{'object'} = $1;
2421 } elsif ($line =~ m/^type (.+)$/) {
2423 } elsif ($line =~ m/^tag (.+)$/) {
2425 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2426 $tag{'author'} = $1;
2429 } elsif ($line =~ m/--BEGIN/) {
2430 push @comment, $line;
2432 } elsif ($line eq "") {
2436 push @comment, <$fd>;
2437 $tag{'comment'} = \@comment;
2438 close $fd or return;
2439 if (!defined $tag{'name'}) {
2445 sub parse_commit_text {
2446 my ($commit_text, $withparents) = @_;
2447 my @commit_lines = split '\n', $commit_text;
2450 pop @commit_lines; # Remove '\0'
2452 if (! @commit_lines) {
2456 my $header = shift @commit_lines;
2457 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2460 ($co{'id'}, my @parents) = split ' ', $header;
2461 while (my $line = shift @commit_lines) {
2462 last if $line eq "\n";
2463 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2465 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2467 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2469 $co{'author_epoch'} = $2;
2470 $co{'author_tz'} = $3;
2471 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2472 $co{'author_name'} = $1;
2473 $co{'author_email'} = $2;
2475 $co{'author_name'} = $co{'author'};
2477 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2478 $co{'committer'} = $1;
2479 $co{'committer_epoch'} = $2;
2480 $co{'committer_tz'} = $3;
2481 $co{'committer_name'} = $co{'committer'};
2482 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2483 $co{'committer_name'} = $1;
2484 $co{'committer_email'} = $2;
2486 $co{'committer_name'} = $co{'committer'};
2490 if (!defined $co{'tree'}) {
2493 $co{'parents'} = \@parents;
2494 $co{'parent'} = $parents[0];
2496 foreach my $title (@commit_lines) {
2499 $co{'title'} = chop_str($title, 80, 5);
2500 # remove leading stuff of merges to make the interesting part visible
2501 if (length($title) > 50) {
2502 $title =~ s/^Automatic //;
2503 $title =~ s/^merge (of|with) /Merge ... /i;
2504 if (length($title) > 50) {
2505 $title =~ s/(http|rsync):\/\///;
2507 if (length($title) > 50) {
2508 $title =~ s/(master|www|rsync)\.//;
2510 if (length($title) > 50) {
2511 $title =~ s/kernel.org:?//;
2513 if (length($title) > 50) {
2514 $title =~ s/\/pub\/scm//;
2517 $co{'title_short'} = chop_str($title, 50, 5);
2521 if (! defined $co{'title'} || $co{'title'} eq "") {
2522 $co{'title'} = $co{'title_short'} = '(no commit message)';
2524 # remove added spaces
2525 foreach my $line (@commit_lines) {
2528 $co{'comment'} = \@commit_lines;
2530 my $age = time - $co{'committer_epoch'};
2532 $co{'age_string'} = age_string($age);
2533 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2534 if ($age > 60*60*24*7*2) {
2535 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2536 $co{'age_string_age'} = $co{'age_string'};
2538 $co{'age_string_date'} = $co{'age_string'};
2539 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2545 my ($commit_id) = @_;
2550 open my $fd, "-|", git_cmd(), "rev-list",
2556 or die_error(500, "Open git-rev-list failed");
2557 %co = parse_commit_text(<$fd>, 1);
2564 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2572 open my $fd, "-|", git_cmd(), "rev-list",
2575 ("--max-count=" . $maxcount),
2576 ("--skip=" . $skip),
2580 ($filename ? ($filename) : ())
2581 or die_error(500, "Open git-rev-list failed");
2582 while (my $line = <$fd>) {
2583 my %co = parse_commit_text($line);
2588 return wantarray ? @cos : \@cos;
2591 # parse line of git-diff-tree "raw" output
2592 sub parse_difftree_raw_line {
2596 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2597 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2598 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2599 $res{'from_mode'} = $1;
2600 $res{'to_mode'} = $2;
2601 $res{'from_id'} = $3;
2603 $res{'status'} = $5;
2604 $res{'similarity'} = $6;
2605 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2606 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2608 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2611 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2612 # combined diff (for merge commit)
2613 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2614 $res{'nparents'} = length($1);
2615 $res{'from_mode'} = [ split(' ', $2) ];
2616 $res{'to_mode'} = pop @{$res{'from_mode'}};
2617 $res{'from_id'} = [ split(' ', $3) ];
2618 $res{'to_id'} = pop @{$res{'from_id'}};
2619 $res{'status'} = [ split('', $4) ];
2620 $res{'to_file'} = unquote($5);
2622 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2623 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2624 $res{'commit'} = $1;
2627 return wantarray ? %res : \%res;
2630 # wrapper: return parsed line of git-diff-tree "raw" output
2631 # (the argument might be raw line, or parsed info)
2632 sub parsed_difftree_line {
2633 my $line_or_ref = shift;
2635 if (ref($line_or_ref) eq "HASH") {
2636 # pre-parsed (or generated by hand)
2637 return $line_or_ref;
2639 return parse_difftree_raw_line($line_or_ref);
2643 # parse line of git-ls-tree output
2644 sub parse_ls_tree_line ($;%) {
2649 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2650 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2658 $res{'name'} = unquote($4);
2661 return wantarray ? %res : \%res;
2664 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2665 sub parse_from_to_diffinfo {
2666 my ($diffinfo, $from, $to, @parents) = @_;
2668 if ($diffinfo->{'nparents'}) {
2670 $from->{'file'} = [];
2671 $from->{'href'} = [];
2672 fill_from_file_info($diffinfo, @parents)
2673 unless exists $diffinfo->{'from_file'};
2674 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2675 $from->{'file'}[$i] =
2676 defined $diffinfo->{'from_file'}[$i] ?
2677 $diffinfo->{'from_file'}[$i] :
2678 $diffinfo->{'to_file'};
2679 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2680 $from->{'href'}[$i] = href(action=>"blob",
2681 hash_base=>$parents[$i],
2682 hash=>$diffinfo->{'from_id'}[$i],
2683 file_name=>$from->{'file'}[$i]);
2685 $from->{'href'}[$i] = undef;
2689 # ordinary (not combined) diff
2690 $from->{'file'} = $diffinfo->{'from_file'};
2691 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2692 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2693 hash=>$diffinfo->{'from_id'},
2694 file_name=>$from->{'file'});
2696 delete $from->{'href'};
2700 $to->{'file'} = $diffinfo->{'to_file'};
2701 if (!is_deleted($diffinfo)) { # file exists in result
2702 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2703 hash=>$diffinfo->{'to_id'},
2704 file_name=>$to->{'file'});
2706 delete $to->{'href'};
2710 ## ......................................................................
2711 ## parse to array of hashes functions
2713 sub git_get_heads_list {
2717 open my $fd, '-|', git_cmd(), 'for-each-ref',
2718 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2719 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2722 while (my $line = <$fd>) {
2726 my ($refinfo, $committerinfo) = split(/\0/, $line);
2727 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2728 my ($committer, $epoch, $tz) =
2729 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2730 $ref_item{'fullname'} = $name;
2731 $name =~ s!^refs/heads/!!;
2733 $ref_item{'name'} = $name;
2734 $ref_item{'id'} = $hash;
2735 $ref_item{'title'} = $title || '(no commit message)';
2736 $ref_item{'epoch'} = $epoch;
2738 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2740 $ref_item{'age'} = "unknown";
2743 push @headslist, \%ref_item;
2747 return wantarray ? @headslist : \@headslist;
2750 sub git_get_tags_list {
2754 open my $fd, '-|', git_cmd(), 'for-each-ref',
2755 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2756 '--format=%(objectname) %(objecttype) %(refname) '.
2757 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2760 while (my $line = <$fd>) {
2764 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2765 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2766 my ($creator, $epoch, $tz) =
2767 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2768 $ref_item{'fullname'} = $name;
2769 $name =~ s!^refs/tags/!!;
2771 $ref_item{'type'} = $type;
2772 $ref_item{'id'} = $id;
2773 $ref_item{'name'} = $name;
2774 if ($type eq "tag") {
2775 $ref_item{'subject'} = $title;
2776 $ref_item{'reftype'} = $reftype;
2777 $ref_item{'refid'} = $refid;
2779 $ref_item{'reftype'} = $type;
2780 $ref_item{'refid'} = $id;
2783 if ($type eq "tag" || $type eq "commit") {
2784 $ref_item{'epoch'} = $epoch;
2786 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2788 $ref_item{'age'} = "unknown";
2792 push @tagslist, \%ref_item;
2796 return wantarray ? @tagslist : \@tagslist;
2799 ## ----------------------------------------------------------------------
2800 ## filesystem-related functions
2802 sub get_file_owner {
2805 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2806 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2807 if (!defined $gcos) {
2811 $owner =~ s/[,;].*$//;
2812 return to_utf8($owner);
2815 # assume that file exists
2817 my $filename = shift;
2819 open my $fd, '<', $filename;
2820 return join '', map to_utf8($_), <$fd>;
2823 ## ......................................................................
2824 ## mimetype related functions
2826 sub mimetype_guess_file {
2827 my $filename = shift;
2828 my $mimemap = shift;
2829 -r $mimemap or return undef;
2832 open(MIME, $mimemap) or return undef;
2834 next if m/^#/; # skip comments
2835 my ($mime, $exts) = split(/\t+/);
2836 if (defined $exts) {
2837 my @exts = split(/\s+/, $exts);
2838 foreach my $ext (@exts) {
2839 $mimemap{$ext} = $mime;
2845 $filename =~ /\.([^.]*)$/;
2846 return $mimemap{$1};
2849 sub mimetype_guess {
2850 my $filename = shift;
2852 $filename =~ /\./ or return undef;
2854 if ($mimetypes_file) {
2855 my $file = $mimetypes_file;
2856 if ($file !~ m!^/!) { # if it is relative path
2857 # it is relative to project
2858 $file = "$projectroot/$project/$file";
2860 $mime = mimetype_guess_file($filename, $file);
2862 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2868 my $filename = shift;
2871 my $mime = mimetype_guess($filename);
2872 $mime and return $mime;
2876 return $default_blob_plain_mimetype unless $fd;
2879 return 'text/plain';
2880 } elsif (! $filename) {
2881 return 'application/octet-stream';
2882 } elsif ($filename =~ m/\.png$/i) {
2884 } elsif ($filename =~ m/\.gif$/i) {
2886 } elsif ($filename =~ m/\.jpe?g$/i) {
2887 return 'image/jpeg';
2889 return 'application/octet-stream';
2893 sub blob_contenttype {
2894 my ($fd, $file_name, $type) = @_;
2896 $type ||= blob_mimetype($fd, $file_name);
2897 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2898 $type .= "; charset=$default_text_plain_charset";
2904 ## ======================================================================
2905 ## functions printing HTML: header, footer, error page
2907 sub git_header_html {
2908 # XXX These aren't used, how odd.
2909 my $status = shift || "200 OK";
2910 my $expires = shift;
2912 my $title = "$site_name";
2913 if (defined $project) {
2914 $title .= " - " . to_utf8($project);
2915 if (defined $action) {
2916 $title .= "/$action";
2917 if (defined $file_name) {
2918 $title .= " - " . esc_path($file_name);
2919 if ($action eq "tree" && $file_name !~ m|/$|) {
2926 # require explicit support from the UA if we are to send the page as
2927 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2928 # we have to do this because MSIE sometimes globs '*/*', pretending to
2929 # support xhtml+xml but choking when it gets what it asked for.
2930 if (defined $cgi->http('HTTP_ACCEPT') &&
2931 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
2932 $cgi->Accept('application/xhtml+xml') != 0) {
2933 $content_type = 'application/xhtml+xml';
2935 $content_type = 'text/html';
2937 $c->response->content_type($content_type);
2939 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2941 $c->stash->{version} = $version;
2942 $c->stash->{git_version} = $git_version;
2943 $c->stash->{content_type} = $content_type;
2944 $c->stash->{mod_perl_version} = $mod_perl_version;
2945 $c->stash->{title} = $title;
2947 # the stylesheet, favicon etc urls won't work correctly with path_info
2948 # unless we set the appropriate base URL
2949 $c->stash->{baseurl} = $ENV{PATH_INFO}
2950 ? q[<base href="].esc_url($base_url).q[" />]
2953 # print out each stylesheet that exist, providing backwards capability
2954 # for those people who defined $stylesheet in a config file
2955 my $ssfmt = q[<link rel="stylesheet" type="text/css" href="%s"/>];
2956 $c->stash->{stylesheets} = [defined $stylesheet
2957 ? sprintf($ssfmt, $stylesheet)
2958 : map(sprintf($ssfmt, $_), grep $_, @stylesheets)
2961 $c->stash->{project} = defined $project;
2962 if (defined $project) {
2963 my %href_params = get_feed_info();
2964 if (!exists $href_params{'-title'}) {
2965 $href_params{'-title'} = 'log';
2968 foreach my $format qw(RSS Atom) {
2969 my $type = lc($format);
2971 '-rel' => 'alternate',
2972 '-title' => "$project - $href_params{'-title'} - $format feed",
2973 '-type' => "application/$type+xml"
2976 $href_params{'action'} = $type;
2977 $link_attr{'-href'} = href(%href_params);
2978 $c->stash->{lc $format.'_link'} = "<link ".
2979 "rel=\"$link_attr{'-rel'}\" ".
2980 "title=\"$link_attr{'-title'}\" ".
2981 "href=\"$link_attr{'-href'}\" ".
2982 "type=\"$link_attr{'-type'}\" ".
2985 $href_params{'extra_options'} = '--no-merges';
2986 $link_attr{'-href'} = href(%href_params);
2987 $link_attr{'-title'} .= ' (no merges)';
2988 $c->stash->{lc $format.'_link_no_merges'} = "<link ".
2989 "rel=\"$link_attr{'-rel'}\" ".
2990 "title=\"$link_attr{'-title'}\" ".
2991 "href=\"$link_attr{'-href'}\" ".
2992 "type=\"$link_attr{'-type'}\" ".
2997 $c->stash->{projects_list} = sprintf('<link rel="alternate" title="%s projects list" '.
2998 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2999 $site_name, href(project=>undef, action=>"project_index"));
3000 $c->stash->{projects_feed} = sprintf('<link rel="alternate" title="%s projects feeds" '.
3001 'href="%s" type="text/x-opml" />'."\n",
3002 $site_name, href(project=>undef, action=>"opml"));
3005 $c->stash->{favicon} = defined $favicon
3006 ? qq(<link rel="shortcut icon" href="$favicon" type="image/png" />)
3011 $c->stash->{site_header} = -f $site_header
3012 ? insert_file($site_header)
3016 = $cgi->a({-href => esc_url($logo_url),
3017 -title => $logo_label},
3018 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3019 $c->stash->{home_link} = $cgi->a({-href => esc_url($home_link)}, $home_link_str);
3021 if(defined $project) {
3022 $c->stash->{summary} = $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3023 $c->stash->{action} = $action;
3026 my $have_search = $c->stash->{have_search} = gitweb_check_feature('search');
3027 if (defined $project && $have_search) {
3028 if (!defined $searchtext) {
3032 if (defined $hash_base) {
3033 $search_hash = $hash_base;
3034 } elsif (defined $hash) {
3035 $search_hash = $hash;
3037 $search_hash = "HEAD";
3039 my $action = $my_uri;
3040 my $use_pathinfo = gitweb_check_feature('pathinfo');
3041 if ($use_pathinfo) {
3042 $action .= "/".esc_url($project);
3044 # This could be done better, but meh.
3045 $c->stash->{search_form} = $cgi->startform(-method => "get", -action => $action) .
3047 $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3048 $cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3049 $cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3050 $cgi->popup_menu(-name => 'st', -default => 'commit',
3051 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3052 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3054 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3055 "<span title=\"Extended regular expression\">" .
3056 $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3057 -checked => $search_use_regexp) .
3059 $cgi->end_form() . "\n";
3063 sub git_footer_html {
3064 my $feed_class = 'rss_logo';
3066 if (defined $project) {
3067 my $descr = git_get_project_description($project);
3068 $c->stash->{project_description} = defined $descr
3072 my %href_params = get_feed_info();
3073 if (!%href_params) {
3074 $feed_class .= ' generic';
3076 $href_params{'-title'} ||= 'log';
3078 foreach my $format qw(RSS Atom) {
3079 $href_params{'action'} = lc($format);
3080 $c->stash->{lc $format.'_feed'} = $cgi->a({-href => href(%href_params),
3081 -title => "$href_params{'-title'} $format feed",
3082 -class => $feed_class}, $format);
3086 $c->stash->{opml_feed} = $cgi->a({-href => href(project=>undef, action=>"opml"),
3087 -class => $feed_class}, "OPML");
3088 $c->stash->{index_feed} = $cgi->a({-href => href(project=>undef, action=>"project_index"),
3089 -class => $feed_class}, "TXT");
3092 $c->stash->{site_footer} = -f $site_footer
3093 ? insert_file($site_footer)
3097 # die_error(<http_status_code>, <error_message>)
3098 # Example: die_error(404, 'Hash not found')
3099 # By convention, use the following status codes (as defined in RFC 2616):
3100 # 400: Invalid or missing CGI parameters, or
3101 # requested object exists but has wrong type.
3102 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3103 # this server or project.
3104 # 404: Requested object/revision/project doesn't exist.
3105 # 500: The server isn't configured properly, or
3106 # an internal error occurred (e.g. failed assertions caused by bugs), or
3107 # an unknown error occurred (e.g. the git binary died unexpectedly).
3109 my $status = shift || 500;
3110 my $error = shift || "Internal server error";
3112 my %http_responses = (400 => '400 Bad Request',
3113 403 => '403 Forbidden',
3114 404 => '404 Not Found',
3115 500 => '500 Internal Server Error');
3116 $c->response->status($http_responses{$status});
3118 $c->stash->{content} = <<EOF;
3119 <div class="page_body">
3128 ## ----------------------------------------------------------------------
3129 ## functions printing or outputting HTML: navigation
3131 sub git_print_page_nav {
3132 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3133 $extra = '' if !defined $extra; # pager or formats
3135 my @navs = qw(summary shortlog log commit commitdiff tree);
3137 @navs = grep { $_ ne $suppress } @navs;
3140 my %arg = map { $_ => {action=>$_} } @navs;
3141 if (defined $head) {
3142 for (qw(commit commitdiff)) {
3143 $arg{$_}{'hash'} = $head;
3145 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3146 for (qw(shortlog log)) {
3147 $arg{$_}{'hash'} = $head;
3152 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3153 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3155 my @actions = gitweb_get_feature('actions');
3158 'n' => $project, # project name
3159 'f' => $git_dir, # project path within filesystem
3160 'h' => $treehead || '', # current hash ('h' parameter)
3161 'b' => $treebase || '', # hash base ('hb' parameter)
3164 my ($label, $link, $pos) = splice(@actions,0,3);
3166 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3168 $link =~ s/%([%nfhb])/$repl{$1}/g;
3169 $arg{$label}{'_href'} = $link;
3172 $c->stash->{page_nav} = 1;
3173 $c->stash->{nav_links} =
3175 map { $_ eq $current ?
3176 $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
3178 $c->stash->{extra} = $extra;
3181 sub format_paging_nav {
3182 my ($action, $hash, $head, $page, $has_next_link) = @_;
3186 if ($hash ne $head || $page) {
3187 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
3189 $paging_nav .= "HEAD";
3193 $paging_nav .= " ⋅ " .
3194 $cgi->a({-href => href(-replay=>1, page=>$page-1),
3195 -accesskey => "p", -title => "Alt-p"}, "prev");
3197 $paging_nav .= " ⋅ prev";
3200 if ($has_next_link) {
3201 $paging_nav .= " ⋅ " .
3202 $cgi->a({-href => href(-replay=>1, page=>$page+1),
3203 -accesskey => "n", -title => "Alt-n"}, "next");
3205 $paging_nav .= " ⋅ next";
3211 ## ......................................................................
3212 ## functions printing or outputting HTML: div
3214 sub git_print_header_div {
3215 my ($action, $title, $hash, $hash_base) = @_;
3218 $args{'action'} = $action;
3219 $args{'hash'} = $hash if $hash;
3220 $args{'hash_base'} = $hash_base if $hash_base;
3222 print q[<div class="header">],
3223 $cgi->a({-href => href(%args), -class => "title"},
3224 $title ? $title : $action),
3228 sub git_print_authorship {
3231 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3232 print "<div class=\"author_date\">" .
3233 esc_html($co->{'author_name'}) .
3235 if ($ad{'hour_local'} < 6) {
3236 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3237 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3239 printf(" (%02d:%02d %s)",
3240 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3245 sub git_print_page_path {
3251 print "<div class=\"page_path\">";
3252 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
3253 -title => 'tree root'}, to_utf8("[$project]"));
3255 if (defined $name) {
3256 my @dirname = split '/', $name;
3257 my $basename = pop @dirname;
3260 foreach my $dir (@dirname) {
3261 $fullname .= ($fullname ? '/' : '') . $dir;
3262 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
3264 -title => $fullname}, esc_path($dir));
3267 if (defined $type && $type eq 'blob') {
3268 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
3270 -title => $name}, esc_path($basename));
3271 } elsif (defined $type && $type eq 'tree') {
3272 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
3274 -title => $name}, esc_path($basename));
3277 print esc_path($basename);
3280 print "<br/></div>\n";
3283 # sub git_print_log (\@;%) {
3284 sub git_print_log ($;%) {
3288 if ($opts{'-remove_title'}) {
3289 # remove title, i.e. first line of log
3292 # remove leading empty lines
3293 while (defined $log->[0] && $log->[0] eq "") {
3300 foreach my $line (@$log) {
3301 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3304 if (! $opts{'-remove_signoff'}) {
3305 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
3308 # remove signoff lines
3315 # print only one empty line
3316 # do not print empty line after signoff
3318 next if ($empty || $signoff);
3324 print format_log_line_html($line) . "<br/>\n";
3327 if ($opts{'-final_empty_line'}) {
3328 # end with single empty line
3329 print "<br/>\n" unless $empty;
3333 # return link target (what link points to)
3334 sub git_get_link_target {
3339 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3343 $link_target = <$fd>;
3348 return $link_target;
3351 # given link target, and the directory (basedir) the link is in,
3352 # return target of link relative to top directory (top tree);
3353 # return undef if it is not possible (including absolute links).
3354 sub normalize_link_target {
3355 my ($link_target, $basedir, $hash_base) = @_;
3357 # we can normalize symlink target only if $hash_base is provided
3358 return unless $hash_base;
3360 # absolute symlinks (beginning with '/') cannot be normalized
3361 return if (substr($link_target, 0, 1) eq '/');
3363 # normalize link target to path from top (root) tree (dir)
3366 $path = $basedir . '/' . $link_target;
3368 # we are in top (root) tree (dir)
3369 $path = $link_target;
3372 # remove //, /./, and /../
3374 foreach my $part (split('/', $path)) {
3375 # discard '.' and ''
3376 next if (!$part || $part eq '.');
3378 if ($part eq '..') {
3382 # link leads outside repository (outside top dir)
3386 push @path_parts, $part;
3389 $path = join('/', @path_parts);
3394 # print tree entry (row of git_tree), but without encompassing <tr> element
3395 sub git_print_tree_entry {
3396 my ($t, $basedir, $hash_base, $have_blame) = @_;
3399 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3401 # The format of a table row is: mode list link. Where mode is
3402 # the mode of the entry, list is the name of the entry, an href,
3403 # and link is the action links of the entry.
3405 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
3406 if ($t->{'type'} eq "blob") {
3407 print "<td class=\"list\">" .
3408 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3409 file_name=>"$basedir$t->{'name'}", %base_key),
3410 -class => "list"}, esc_path($t->{'name'}));
3411 if (S_ISLNK(oct $t->{'mode'})) {
3412 my $link_target = git_get_link_target($t->{'hash'});
3414 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
3415 if (defined $norm_target) {
3417 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
3418 file_name=>$norm_target),
3419 -title => $norm_target}, esc_path($link_target));
3421 print " -> " . esc_path($link_target);
3426 print "<td class=\"link\">";
3427 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3428 file_name=>"$basedir$t->{'name'}", %base_key)},
3432 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
3433 file_name=>"$basedir$t->{'name'}", %base_key)},
3436 if (defined $hash_base) {
3438 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3439 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
3443 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
3444 file_name=>"$basedir$t->{'name'}")},
3448 } elsif ($t->{'type'} eq "tree") {
3449 print "<td class=\"list\">";
3450 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3451 file_name=>"$basedir$t->{'name'}", %base_key)},
3452 esc_path($t->{'name'}));
3454 print "<td class=\"link\">";
3455 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3456 file_name=>"$basedir$t->{'name'}", %base_key)},
3458 if (defined $hash_base) {
3460 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3461 file_name=>"$basedir$t->{'name'}")},
3466 # unknown object: we can only present history for it
3467 # (this includes 'commit' object, i.e. submodule support)
3468 print "<td class=\"list\">" .
3469 esc_path($t->{'name'}) .
3471 print "<td class=\"link\">";
3472 if (defined $hash_base) {
3473 print $cgi->a({-href => href(action=>"history",
3474 hash_base=>$hash_base,
3475 file_name=>"$basedir$t->{'name'}")},
3482 ## ......................................................................
3483 ## functions printing large fragments of HTML
3485 # get pre-image filenames for merge (combined) diff
3486 sub fill_from_file_info {
3487 my ($diff, @parents) = @_;
3489 $diff->{'from_file'} = [ ];
3490 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3491 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3492 if ($diff->{'status'}[$i] eq 'R' ||
3493 $diff->{'status'}[$i] eq 'C') {
3494 $diff->{'from_file'}[$i] =
3495 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
3502 # is current raw difftree line of file deletion
3504 my $diffinfo = shift;
3506 return $diffinfo->{'to_id'} eq ('0' x 40);
3509 # does patch correspond to [previous] difftree raw line
3510 # $diffinfo - hashref of parsed raw diff format
3511 # $patchinfo - hashref of parsed patch diff format
3512 # (the same keys as in $diffinfo)
3513 sub is_patch_split {
3514 my ($diffinfo, $patchinfo) = @_;
3516 return defined $diffinfo && defined $patchinfo
3517 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3521 sub git_difftree_body {
3522 my ($difftree, $hash, @parents) = @_;
3523 my ($parent) = $parents[0];
3524 my $have_blame = gitweb_check_feature('blame');
3525 print "<div class=\"list_head\">\n";
3526 if ($#{$difftree} > 10) {
3527 print(($#{$difftree} + 1) . " files changed:\n");
3531 print "<table class=\"" .
3532 (@parents > 1 ? "combined " : "") .
3535 # header only for combined diff in 'commitdiff' view
3536 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3539 print "<thead><tr>\n" .
3540 "<th></th><th></th>\n"; # filename, patchN link
3541 for (my $i = 0; $i < @parents; $i++) {
3542 my $par = $parents[$i];
3544 $cgi->a({-href => href(action=>"commitdiff",
3545 hash=>$hash, hash_parent=>$par),
3546 -title => 'commitdiff to parent number ' .
3547 ($i+1) . ': ' . substr($par,0,7)},
3551 print "</tr></thead>\n<tbody>\n";
3556 foreach my $line (@{$difftree}) {
3557 my $diff = parsed_difftree_line($line);
3560 print "<tr class=\"dark\">\n";
3562 print "<tr class=\"light\">\n";
3566 if (exists $diff->{'nparents'}) { # combined diff
3568 fill_from_file_info($diff, @parents)
3569 unless exists $diff->{'from_file'};
3571 if (!is_deleted($diff)) {
3572 # file exists in the result (child) commit
3574 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3575 file_name=>$diff->{'to_file'},
3577 -class => "list"}, esc_path($diff->{'to_file'})) .
3581 esc_path($diff->{'to_file'}) .
3585 if ($action eq 'commitdiff') {
3588 print "<td class=\"link\">" .
3589 $cgi->a({-href => "#patch$patchno"}, "patch") .
3594 my $has_history = 0;
3595 my $not_deleted = 0;
3596 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3597 my $hash_parent = $parents[$i];
3598 my $from_hash = $diff->{'from_id'}[$i];
3599 my $from_path = $diff->{'from_file'}[$i];
3600 my $status = $diff->{'status'}[$i];
3602 $has_history ||= ($status ne 'A');
3603 $not_deleted ||= ($status ne 'D');
3605 if ($status eq 'A') {
3606 print "<td class=\"link\" align=\"right\"> | </td>\n";
3607 } elsif ($status eq 'D') {
3608 print "<td class=\"link\">" .
3609 $cgi->a({-href => href(action=>"blob",
3612 file_name=>$from_path)},
3616 if ($diff->{'to_id'} eq $from_hash) {
3617 print "<td class=\"link nochange\">";
3619 print "<td class=\"link\">";
3621 print $cgi->a({-href => href(action=>"blobdiff",
3622 hash=>$diff->{'to_id'},
3623 hash_parent=>$from_hash,
3625 hash_parent_base=>$hash_parent,
3626 file_name=>$diff->{'to_file'},
3627 file_parent=>$from_path)},
3633 print "<td class=\"link\">";
3635 print $cgi->a({-href => href(action=>"blob",
3636 hash=>$diff->{'to_id'},
3637 file_name=>$diff->{'to_file'},
3640 print " | " if ($has_history);
3643 print $cgi->a({-href => href(action=>"history",
3644 file_name=>$diff->{'to_file'},
3651 next; # instead of 'else' clause, to avoid extra indent
3653 # else ordinary diff
3655 my ($to_mode_oct, $to_mode_str, $to_file_type);
3656 my ($from_mode_oct, $from_mode_str, $from_file_type);
3657 if ($diff->{'to_mode'} ne ('0' x 6)) {
3658 $to_mode_oct = oct $diff->{'to_mode'};
3659 if (S_ISREG($to_mode_oct)) { # only for regular file
3660 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3662 $to_file_type = file_type($diff->{'to_mode'});
3664 if ($diff->{'from_mode'} ne ('0' x 6)) {
3665 $from_mode_oct = oct $diff->{'from_mode'};
3666 if (S_ISREG($to_mode_oct)) { # only for regular file
3667 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3669 $from_file_type = file_type($diff->{'from_mode'});
3672 if ($diff->{'status'} eq "A") { # created
3673 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3674 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3675 $mode_chng .= "]</span>";
3677 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3678 hash_base=>$hash, file_name=>$diff->{'file'}),
3679 -class => "list"}, esc_path($diff->{'file'}));
3681 print "<td>$mode_chng</td>\n";
3682 print "<td class=\"link\">";
3683 if ($action eq 'commitdiff') {
3686 print $cgi->a({-href => "#patch$patchno"}, "patch");
3689 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3690 hash_base=>$hash, file_name=>$diff->{'file'})},
3694 } elsif ($diff->{'status'} eq "D") { # deleted
3695 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3697 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3698 hash_base=>$parent, file_name=>$diff->{'file'}),
3699 -class => "list"}, esc_path($diff->{'file'}));
3701 print "<td>$mode_chng</td>\n";
3702 print "<td class=\"link\">";
3703 if ($action eq 'commitdiff') {
3706 print $cgi->a({-href => "#patch$patchno"}, "patch");
3709 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3710 hash_base=>$parent, file_name=>$diff->{'file'})},
3713 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3714 file_name=>$diff->{'file'})},
3717 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3718 file_name=>$diff->{'file'})},
3722 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3723 my $mode_chnge = "";
3724 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3725 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3726 if ($from_file_type ne $to_file_type) {
3727 $mode_chnge .= " from $from_file_type to $to_file_type";
3729 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3730 if ($from_mode_str && $to_mode_str) {
3731 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3732 } elsif ($to_mode_str) {
3733 $mode_chnge .= " mode: $to_mode_str";
3736 $mode_chnge .= "]</span>\n";
3739 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3740 hash_base=>$hash, file_name=>$diff->{'file'}),
3741 -class => "list"}, esc_path($diff->{'file'}));
3743 print "<td>$mode_chnge</td>\n";
3744 print "<td class=\"link\">";
3745 if ($action eq 'commitdiff') {
3748 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3750 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3751 # "commit" view and modified file (not onlu mode changed)
3752 print $cgi->a({-href => href(action=>"blobdiff",
3753 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3754 hash_base=>$hash, hash_parent_base=>$parent,
3755 file_name=>$diff->{'file'})},
3759 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3760 hash_base=>$hash, file_name=>$diff->{'file'})},
3763 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3764 file_name=>$diff->{'file'})},
3767 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3768 file_name=>$diff->{'file'})},
3772 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3773 my %status_name = ('R' => 'moved', 'C' => 'copied');
3774 my $nstatus = $status_name{$diff->{'status'}};
3776 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3777 # mode also for directories, so we cannot use $to_mode_str
3778 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3781 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3782 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3783 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3784 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3785 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3786 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3787 -class => "list"}, esc_path($diff->{'from_file'})) .
3788 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3789 "<td class=\"link\">";
3790 if ($action eq 'commitdiff') {
3793 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3795 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3796 # "commit" view and modified file (not only pure rename or copy)
3797 print $cgi->a({-href => href(action=>"blobdiff",
3798 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3799 hash_base=>$hash, hash_parent_base=>$parent,
3800 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3804 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3805 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3808 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3809 file_name=>$diff->{'to_file'})},
3812 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3813 file_name=>$diff->{'to_file'})},
3817 } # we should not encounter Unmerged (U) or Unknown (X) status
3820 print "</tbody>" if $has_header;
3824 sub git_patchset_body {
3825 my ($fd, $difftree, $hash, @hash_parents) = @_;
3826 my ($hash_parent) = $hash_parents[0];
3828 my $is_combined = (@hash_parents > 1);
3830 my $patch_number = 0;
3836 print "<div class=\"patchset\">\n";
3838 # skip to first patch
3839 while ($patch_line = <$fd>) {
3842 last if ($patch_line =~ m/^diff /);
3846 while ($patch_line) {
3848 # parse "git diff" header line
3849 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3850 # $1 is from_name, which we do not use
3851 $to_name = unquote($2);
3852 $to_name =~ s!^b/!!;
3853 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3854 # $1 is 'cc' or 'combined', which we do not use
3855 $to_name = unquote($2);
3860 # check if current patch belong to current raw line
3861 # and parse raw git-diff line if needed
3862 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
3863 # this is continuation of a split patch
3864 print "<div class=\"patch cont\">\n";
3866 # advance raw git-diff output if needed
3867 $patch_idx++ if defined $diffinfo;
3869 # read and prepare patch information
3870 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3872 # compact combined diff output can have some patches skipped
3873 # find which patch (using pathname of result) we are at now;
3875 while ($to_name ne $diffinfo->{'to_file'}) {
3876 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3877 format_diff_cc_simplified($diffinfo, @hash_parents) .
3878 "</div>\n"; # class="patch"
3883 last if $patch_idx > $#$difftree;
3884 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3888 # modifies %from, %to hashes
3889 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3891 # this is first patch for raw difftree line with $patch_idx index
3892 # we index @$difftree array from 0, but number patches from 1
3893 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3897 #assert($patch_line =~ m/^diff /) if DEBUG;
3898 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3900 # print "git diff" header
3901 print format_git_diff_header_line($patch_line, $diffinfo,
3904 # print extended diff header
3905 print "<div class=\"diff extended_header\">\n";
3907 while ($patch_line = <$fd>) {
3910 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
3912 print format_extended_diff_header_line($patch_line, $diffinfo,
3915 print "</div>\n"; # class="diff extended_header"
3917 # from-file/to-file diff header
3918 if (! $patch_line) {
3919 print "</div>\n"; # class="patch"
3922 next PATCH if ($patch_line =~ m/^diff /);
3923 #assert($patch_line =~ m/^---/) if DEBUG;
3925 my $last_patch_line = $patch_line;
3926 $patch_line = <$fd>;
3928 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3930 print format_diff_from_to_header($last_patch_line, $patch_line,
3931 $diffinfo, \%from, \%to,
3936 while ($patch_line = <$fd>) {
3939 next PATCH if ($patch_line =~ m/^diff /);
3941 print format_diff_line($patch_line, \%from, \%to);
3945 print "</div>\n"; # class="patch"
3948 # for compact combined (--cc) format, with chunk and patch simpliciaction
3949 # patchset might be empty, but there might be unprocessed raw lines
3950 for (++$patch_idx if $patch_number > 0;
3951 $patch_idx < @$difftree;
3953 # read and prepare patch information
3954 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3956 # generate anchor for "patch" links in difftree / whatchanged part
3957 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3958 format_diff_cc_simplified($diffinfo, @hash_parents) .
3959 "</div>\n"; # class="patch"
3964 if ($patch_number == 0) {
3965 if (@hash_parents > 1) {
3966 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3968 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3972 print "</div>\n"; # class="patchset"
3975 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3977 # fills project list info (age, description, owner, forks) for each
3978 # project in the list, removing invalid projects from returned list
3979 # NOTE: modifies $projlist, but does not remove entries from it
3980 sub fill_project_list_info {
3981 my ($projlist, $check_forks) = @_;
3984 my $show_ctags = gitweb_check_feature('ctags');
3986 foreach my $pr (@$projlist) {
3987 my (@activity) = git_get_last_activity($pr->{'path'});
3988 unless (@activity) {
3991 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3992 if (!defined $pr->{'descr'}) {
3993 my $descr = git_get_project_description($pr->{'path'}) || "";
3994 $descr = to_utf8($descr);
3995 $pr->{'descr_long'} = $descr;
3996 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3998 if (!defined $pr->{'owner'}) {
3999 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
4002 my $pname = $pr->{'path'};
4003 if (($pname =~ s/\.git$//) &&
4004 ($pname !~ /\/$/) &&
4005 (-d "$projectroot/$pname")) {
4006 $pr->{'forks'} = "-d $projectroot/$pname";
4011 $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
4012 push @projects, $pr;
4018 # print 'sort by' <th> element, generating 'sort by $name' replay link
4019 # if that order is not selected
4021 my ($name, $order, $header) = @_;
4022 $header ||= ucfirst($name);
4024 if ($order eq $name) {
4025 print "<th>$header</th>\n";
4028 $cgi->a({-href => href(-replay=>1, order=>$name),
4029 -class => "header"}, $header) .
4034 sub git_project_list_body {
4035 # actually uses global variable $project
4036 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4038 my $check_forks = gitweb_check_feature('forks');
4039 my @projects = fill_project_list_info($projlist, $check_forks);
4041 $order ||= $default_projects_order;
4042 $from = 0 unless defined $from;
4043 $to = $#projects if (!defined $to || $#projects < $to);
4046 project => { key => 'path', type => 'str' },
4047 descr => { key => 'descr_long', type => 'str' },
4048 owner => { key => 'owner', type => 'str' },
4049 age => { key => 'age', type => 'num' }
4051 my $oi = $order_info{$order};
4052 if ($oi->{'type'} eq 'str') {
4053 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4055 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4058 my $show_ctags = gitweb_check_feature('ctags');
4061 foreach my $p (@projects) {
4062 foreach my $ct (keys %{$p->{'ctags'}}) {
4063 $ctags{$ct} += $p->{'ctags'}->{$ct};
4066 my $cloud = git_populate_project_tagcloud(\%ctags);
4067 print git_show_project_tagcloud($cloud, 64);
4070 print "<table class=\"project_list\">\n";
4071 unless ($no_header) {
4074 print "<th></th>\n";
4076 print_sort_th('project', $order, 'Project');
4077 print_sort_th('descr', $order, 'Description');
4078 print_sort_th('owner', $order, 'Owner');
4079 print_sort_th('age', $order, 'Last Change');
4080 print "<th></th>\n" . # for links
4084 my $tagfilter = $cgi->param('by_tag');
4085 for (my $i = $from; $i <= $to; $i++) {
4086 my $pr = $projects[$i];
4088 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4089 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4090 and not $pr->{'descr_long'} =~ /$searchtext/;
4091 # Weed out forks or non-matching entries of search
4093 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
4094 $forkbase="^$forkbase" if $forkbase;
4095 next if not $searchtext and not $tagfilter and $show_ctags
4096 and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
4100 print "<tr class=\"dark\">\n";
4102 print "<tr class=\"light\">\n";
4107 if ($pr->{'forks'}) {
4108 print "<!-- $pr->{'forks'} -->\n";
4109 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
4113 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4114 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
4115 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4116 -class => "list", -title => $pr->{'descr_long'}},
4117 esc_html($pr->{'descr'})) . "</td>\n" .
4118 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
4119 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
4120 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4121 "<td class=\"link\">" .
4122 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
4123 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
4124 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
4125 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
4126 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
4130 if (defined $extra) {
4133 print "<td></td>\n";
4135 print "<td colspan=\"5\">$extra</td>\n" .
4141 sub git_shortlog_body {
4142 # uses global variable $project
4143 my ($commitlist, $from, $to, $refs, $extra) = @_;
4145 $from = 0 unless defined $from;
4146 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4148 print "<table class=\"shortlog\">\n";
4150 for (my $i = $from; $i <= $to; $i++) {
4151 my %co = %{$commitlist->[$i]};
4152 my $commit = $co{'id'};
4153 my $ref = format_ref_marker($refs, $commit);
4155 print "<tr class=\"dark\">\n";
4157 print "<tr class=\"light\">\n";
4160 my $author = chop_and_escape_str($co{'author_name'}, 10);
4161 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4162 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4163 "<td><i>" . $author . "</i></td>\n" .
4165 print format_subject_html($co{'title'}, $co{'title_short'},
4166 href(action=>"commit", hash=>$commit), $ref);
4168 "<td class=\"link\">" .
4169 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
4170 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
4171 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
4172 my $snapshot_links = format_snapshot_links($commit);
4173 if (defined $snapshot_links) {
4174 print " | " . $snapshot_links;
4179 if (defined $extra) {
4181 "<td colspan=\"4\">$extra</td>\n" .
4187 sub git_history_body {
4188 # Warning: assumes constant type (blob or tree) during history
4189 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4191 $from = 0 unless defined $from;
4192 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4194 print "<table class=\"history\">\n";
4196 for (my $i = $from; $i <= $to; $i++) {
4197 my %co = %{$commitlist->[$i]};
4201 my $commit = $co{'id'};
4203 my $ref = format_ref_marker($refs, $commit);
4206 print "<tr class=\"dark\">\n";
4208 print "<tr class=\"light\">\n";
4211 # shortlog uses chop_str($co{'author_name'}, 10)
4212 my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
4213 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4214 "<td><i>" . $author . "</i></td>\n" .
4216 # originally git_history used chop_str($co{'title'}, 50)
4217 print format_subject_html($co{'title'}, $co{'title_short'},
4218 href(action=>"commit", hash=>$commit), $ref);
4220 "<td class=\"link\">" .
4221 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
4222 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
4224 if ($ftype eq 'blob') {
4225 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
4226 my $blob_parent = git_get_hash_by_path($commit, $file_name);
4227 if (defined $blob_current && defined $blob_parent &&
4228 $blob_current ne $blob_parent) {
4230 $cgi->a({-href => href(action=>"blobdiff",
4231 hash=>$blob_current, hash_parent=>$blob_parent,
4232 hash_base=>$hash_base, hash_parent_base=>$commit,
4233 file_name=>$file_name)},
4240 if (defined $extra) {
4242 "<td colspan=\"4\">$extra</td>\n" .
4249 # uses global variable $project
4250 my ($taglist, $from, $to, $extra) = @_;
4251 $from = 0 unless defined $from;
4252 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4254 print "<table class=\"tags\">\n";
4256 for (my $i = $from; $i <= $to; $i++) {
4257 my $entry = $taglist->[$i];
4259 my $comment = $tag{'subject'};
4261 if (defined $comment) {
4262 $comment_short = chop_str($comment, 30, 5);
4265 print "<tr class=\"dark\">\n";
4267 print "<tr class=\"light\">\n";
4270 if (defined $tag{'age'}) {
4271 print "<td><i>$tag{'age'}</i></td>\n";
4273 print "<td></td>\n";
4276 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
4277 -class => "list name"}, esc_html($tag{'name'})) .
4280 if (defined $comment) {
4281 print format_subject_html($comment, $comment_short,
4282 href(action=>"tag", hash=>$tag{'id'}));
4285 "<td class=\"selflink\">";
4286 if ($tag{'type'} eq "tag") {
4287 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
4292 "<td class=\"link\">" . " | " .
4293 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
4294 if ($tag{'reftype'} eq "commit") {
4295 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
4296 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
4297 } elsif ($tag{'reftype'} eq "blob") {
4298 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
4303 if (defined $extra) {
4305 "<td colspan=\"5\">$extra</td>\n" .
4311 sub git_heads_body {
4312 # uses global variable $project
4313 my ($headlist, $head, $from, $to, $extra) = @_;
4314 $from = 0 unless defined $from;
4315 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4317 print "<table class=\"heads\">\n";
4319 for (my $i = $from; $i <= $to; $i++) {
4320 my $entry = $headlist->[$i];
4322 my $curr = $ref{'id'} eq $head;
4324 print "<tr class=\"dark\">\n";
4326 print "<tr class=\"light\">\n";
4329 print "<td><i>$ref{'age'}</i></td>\n" .
4330 ($curr ? "<td class=\"current_head\">" : "<td>") .
4331 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),
4332 -class => "list name"},esc_html($ref{'name'})) .
4334 "<td class=\"link\">" .
4335 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
4336 $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
4337 $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
4341 if (defined $extra) {
4343 "<td colspan=\"3\">$extra</td>\n" .
4349 sub git_search_grep_body {
4350 my ($commitlist, $from, $to, $extra) = @_;
4351 $from = 0 unless defined $from;
4352 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4354 print "<table class=\"commit_search\">\n";
4356 for (my $i = $from; $i <= $to; $i++) {
4357 my %co = %{$commitlist->[$i]};
4361 my $commit = $co{'id'};
4363 print "<tr class=\"dark\">\n";
4365 print "<tr class=\"light\">\n";
4368 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
4369 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4370 "<td><i>" . $author . "</i></td>\n" .
4372 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
4373 -class => "list subject"},
4374 chop_and_escape_str($co{'title'}, 50) . "<br/>");
4375 my $comment = $co{'comment'};
4376 foreach my $line (@$comment) {
4377 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4378 my ($lead, $match, $trail) = ($1, $2, $3);
4379 $match = chop_str($match, 70, 5, 'center');
4380 my $contextlen = int((80 - length($match))/2);
4381 $contextlen = 30 if ($contextlen > 30);
4382 $lead = chop_str($lead, $contextlen, 10, 'left');
4383 $trail = chop_str($trail, $contextlen, 10, 'right');
4385 $lead = esc_html($lead);
4386 $match = esc_html($match);
4387 $trail = esc_html($trail);
4389 print "$lead<span class=\"match\">$match</span>$trail<br />";
4393 "<td class=\"link\">" .
4394 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4396 $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") .
4398 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4402 if (defined $extra) {
4404 "<td colspan=\"3\">$extra</td>\n" .
4410 ## ======================================================================
4411 ## ======================================================================
4414 sub git_project_list {
4415 my $order = $input_params{'order'};
4416 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4417 die_error(400, "Unknown order parameter");
4420 my @list = git_get_projects_list();
4422 die_error(404, "No projects found");
4425 if (-f $home_text) {
4426 print "<div class=\"index_include\">\n";
4427 print insert_file($home_text);
4430 print $cgi->startform(-method => "get") .
4431 "<p class=\"projsearch\">Search:\n" .
4432 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
4434 $cgi->end_form() . "\n";
4435 git_project_list_body(\@list, $order);
4439 my $order = $input_params{'order'};
4440 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4441 die_error(400, "Unknown order parameter");
4444 my @list = git_get_projects_list($project);
4446 die_error(404, "No forks found");
4449 git_print_page_nav('','');
4450 git_print_header_div('summary', "$project forks");
4451 git_project_list_body(\@list, $order);
4454 sub git_project_index {
4455 my @projects = git_get_projects_list($project);
4458 -type => 'text/plain',
4459 -charset => 'utf-8',
4460 -content_disposition => 'inline; filename="index.aux"');
4462 foreach my $pr (@projects) {
4463 if (!exists $pr->{'owner'}) {
4464 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
4467 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4468 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4469 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4470 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4474 print "$path $owner\n";
4479 my $descr = git_get_project_description($project) || "none";
4480 my %co = parse_commit("HEAD");
4481 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4482 my $head = $co{'id'};
4484 my $owner = git_get_project_owner($project);
4486 my $refs = git_get_references();
4487 # These get_*_list functions return one more to allow us to see if
4488 # there are more ...
4489 my @taglist = git_get_tags_list(16);
4490 my @headlist = git_get_heads_list(16);
4492 my $check_forks = gitweb_check_feature('forks');
4495 @forklist = git_get_projects_list($project);
4498 git_print_page_nav('summary','', $head);
4500 print "<div class=\"title\"> </div>\n";
4501 print "<table class=\"projects_list\">\n" .
4502 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
4503 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
4504 if (defined $cd{'rfc2822'}) {
4505 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4508 # use per project git URL list in $projectroot/$project/cloneurl
4509 # or make project git URL from git base URL and project name
4510 my $url_tag = "URL";
4511 my @url_list = git_get_project_url_list($project);
4512 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4513 foreach my $git_url (@url_list) {
4514 next unless $git_url;
4515 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4520 my $show_ctags = gitweb_check_feature('ctags');
4522 my $ctags = git_get_project_ctags($project);
4523 my $cloud = git_populate_project_tagcloud($ctags);
4524 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4525 print "</td>\n<td>" unless %$ctags;
4526 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4527 print "</td>\n<td>" if %$ctags;
4528 print git_show_project_tagcloud($cloud, 48);
4534 # If XSS prevention is on, we don't include README.html.
4535 # TODO: Allow a readme in some safe format.
4536 if (!$prevent_xss && -s "$projectroot/$project/README.html") {
4537 print "<div class=\"title\">readme</div>\n" .
4538 "<div class=\"readme\">\n";
4539 print insert_file("$projectroot/$project/README.html");
4540 print "\n</div>\n"; # class="readme"
4543 # we need to request one more than 16 (0..15) to check if
4545 my @commitlist = $head ? parse_commits($head, 17) : ();
4547 git_print_header_div('shortlog');
4548 git_shortlog_body(\@commitlist, 0, 15, $refs,
4549 $#commitlist <= 15 ? undef :
4550 $cgi->a({-href => href(action=>"shortlog")}, "..."));
4554 git_print_header_div('tags');
4555 git_tags_body(\@taglist, 0, 15,
4556 $#taglist <= 15 ? undef :
4557 $cgi->a({-href => href(action=>"tags")}, "..."));
4561 git_print_header_div('heads');
4562 git_heads_body(\@headlist, $head, 0, 15,
4563 $#headlist <= 15 ? undef :
4564 $cgi->a({-href => href(action=>"heads")}, "..."));
4568 git_print_header_div('forks');
4569 git_project_list_body(\@forklist, 'age', 0, 15,
4570 $#forklist <= 15 ? undef :
4571 $cgi->a({-href => href(action=>"forks")}, "..."),
4578 my $head = git_get_head_hash($project);
4579 git_print_page_nav('','', $head,undef,$head);
4580 my %tag = parse_tag($hash);
4583 die_error(404, "Unknown tag object");
4586 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
4587 print "<div class=\"title_text\">\n" .
4588 "<table class=\"object_header\">\n" .
4590 "<td>object</td>\n" .
4591 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4592 $tag{'object'}) . "</td>\n" .
4593 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4594 $tag{'type'}) . "</td>\n" .
4596 if (defined($tag{'author'})) {
4597 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
4598 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
4599 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4600 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4603 print "</table>\n\n" .
4605 print "<div class=\"page_body\">";
4606 my $comment = $tag{'comment'};
4607 foreach my $line (@$comment) {
4609 print esc_html($line, -nbsp=>1) . "<br/>\n";
4616 gitweb_check_feature('blame')
4617 or die_error(403, "Blame view not allowed");
4620 die_error(400, "No file name given") unless $file_name;
4621 $hash_base ||= git_get_head_hash($project);
4622 die_error(404, "Couldn't find base commit") unless $hash_base;
4623 my %co = parse_commit($hash_base)
4624 or die_error(404, "Commit not found");
4626 if (!defined $hash) {
4627 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4628 or die_error(404, "Error looking up file");
4630 $ftype = git_get_type($hash);
4631 if ($ftype !~ "blob") {
4632 die_error(400, "Object is not a blob - $hash");
4636 # run git-blame --porcelain
4637 open my $fd, "-|", git_cmd(), "blame", '-p',
4638 $hash_base, '--', $file_name
4639 or die_error(500, "Open git-blame failed");
4643 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4646 $cgi->a({-href => href(action=>"history", -replay=>1)},
4649 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4651 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4652 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4653 git_print_page_path($file_name, $ftype, $hash_base);
4656 my @rev_color = qw(light2 dark2);
4657 my $num_colors = scalar(@rev_color);
4658 my $current_color = 0;
4662 <div class="page_body">
4663 <table class="blame">
4664 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4667 while (my $line = <$fd>) {
4669 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4670 # no <lines in group> for subsequent lines in group of lines
4671 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4672 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4673 if (!exists $metainfo{$full_rev}) {
4674 $metainfo{$full_rev} = {};
4676 my $meta = $metainfo{$full_rev};
4678 while ($data = <$fd>) {
4680 last if ($data =~ s/^\t//); # contents of line
4681 if ($data =~ /^(\S+) (.*)$/) {
4685 my $short_rev = substr($full_rev, 0, 8);
4686 my $author = $meta->{'author'};
4688 parse_date($meta->{'author-time'}, $meta->{'author-tz'});
4689 my $date = $date{'iso-tz'};
4691 $current_color = ($current_color + 1) % $num_colors;
4693 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4695 print "<td class=\"sha1\"";
4696 print " title=\"". esc_html($author) . ", $date\"";
4697 print " rowspan=\"$group_size\"" if ($group_size > 1);
4699 print $cgi->a({-href => href(action=>"commit",
4701 file_name=>$file_name)},
4702 esc_html($short_rev));
4706 if (!exists $meta->{'parent'}) {
4707 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4708 or die_error(500, "Open git-rev-parse failed");
4709 $parent_commit = <$dd>;
4711 chomp($parent_commit);
4712 $meta->{'parent'} = $parent_commit;
4714 $parent_commit = $meta->{'parent'};
4716 my $blamed = href(action => 'blame',
4717 file_name => $meta->{'filename'},
4718 hash_base => $parent_commit);
4719 print "<td class=\"linenr\">";
4720 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4721 -class => "linenr" },
4724 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4730 or print "Reading blob failed\n";
4736 my $head = git_get_head_hash($project);
4737 git_print_page_nav('','', $head,undef,$head);
4738 git_print_header_div('summary', $project);
4740 my @tagslist = git_get_tags_list();
4742 git_tags_body(\@tagslist);
4747 my $head = git_get_head_hash($project);
4748 git_print_page_nav('','', $head,undef,$head);
4749 git_print_header_div('summary', $project);
4751 my @headslist = git_get_heads_list();
4753 git_heads_body(\@headslist, $head);
4757 sub git_blob_plain {
4761 if (!defined $hash) {
4762 if (defined $file_name) {
4763 my $base = $hash_base || git_get_head_hash($project);
4764 $hash = git_get_hash_by_path($base, $file_name, "blob")
4765 or die_error(404, "Cannot find file");
4767 die_error(400, "No file name defined");
4769 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4770 # blobs defined by non-textual hash id's can be cached
4774 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4775 or die_error(500, "Open git-cat-file blob '$hash' failed");
4777 # content-type (can include charset)
4778 $type = blob_contenttype($fd, $file_name, $type);
4780 # "save as" filename, even when no $file_name is given
4781 my $save_as = "$hash";
4782 if (defined $file_name) {
4783 $save_as = $file_name;
4784 } elsif ($type =~ m/^text\//) {
4788 # With XSS prevention on, blobs of all types except a few known safe
4789 # ones are served with "Content-Disposition: attachment" to make sure
4790 # they don't run in our security domain. For certain image types,
4791 # blob view writes an <img> tag referring to blob_plain view, and we
4792 # want to be sure not to break that by serving the image as an
4793 # attachment (though Firefox 3 doesn't seem to care).
4794 my $sandbox = $prevent_xss &&
4795 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4799 -expires => $expires,
4800 -content_disposition =>
4801 ($sandbox ? 'attachment' : 'inline')
4802 . '; filename="' . $save_as . '"');
4804 binmode STDOUT, ':raw';
4806 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4814 if (!defined $hash) {
4815 if (defined $file_name) {
4816 my $base = $hash_base || git_get_head_hash($project);
4817 $hash = git_get_hash_by_path($base, $file_name, "blob")
4818 or die_error(404, "Cannot find file");
4820 die_error(400, "No file name defined");
4822 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4823 # blobs defined by non-textual hash id's can be cached
4827 my $have_blame = gitweb_check_feature('blame');
4828 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4829 or die_error(500, "Couldn't cat $file_name, $hash");
4830 my $mimetype = blob_mimetype($fd, $file_name);
4831 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4833 return git_blob_plain($mimetype);
4835 # we can have blame only for text/* mimetype
4836 $have_blame &&= ($mimetype =~ m!^text/!);
4838 my $formats_nav = '';
4839 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4840 if (defined $file_name) {
4843 $cgi->a({-href => href(action=>"blame", hash => $hash, -replay=>1)},
4848 $cgi->a({-href => href(action=>"history", -replay=>1)},
4851 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4854 $cgi->a({-href => href(action=>"blob",
4855 hash_base=>"HEAD", file_name=>$file_name)},
4859 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4862 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4863 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4865 print "<div class=\"page_nav\">\n" .
4866 "<br/><br/></div>\n" .
4867 "<div class=\"title\">$hash</div>\n";
4869 git_print_page_path($file_name, "blob", $hash_base);
4870 print "<div class=\"page_body\">\n";
4871 if ($mimetype =~ m!^image/!) {
4872 print qq!<img type="$mimetype"!;
4874 print qq! alt="$file_name" title="$file_name"!;
4877 href(action=>"blob_plain", hash=>$hash,
4878 hash_base=>$hash_base, file_name=>$file_name) .
4882 while (my $line = <$fd>) {
4885 $line = untabify($line);
4886 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4887 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
4891 or print "Reading blob failed.\n";
4896 if (!defined $hash_base) {
4897 $hash_base = "HEAD";
4899 if (!defined $hash) {
4900 if (defined $file_name) {
4901 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
4906 die_error(404, "No such tree") unless defined($hash);
4908 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4909 or die_error(500, "Open git-ls-tree failed");
4910 my @entries = map { chomp; $_ } <$fd>;
4911 close $fd or die_error(404, "Reading tree failed");
4914 my $refs = git_get_references();
4915 my $ref = format_ref_marker($refs, $hash_base);
4917 my $have_blame = gitweb_check_feature('blame');
4918 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4920 if (defined $file_name) {
4922 $cgi->a({-href => href(action=>"history", -replay=>1)},
4924 $cgi->a({-href => href(action=>"tree",
4925 hash_base=>"HEAD", file_name=>$file_name)},
4928 my $snapshot_links = format_snapshot_links($hash);
4929 if (defined $snapshot_links) {
4930 # FIXME: Should be available when we have no hash base as well.
4931 push @views_nav, $snapshot_links;
4933 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4934 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
4937 print "<div class=\"page_nav\">\n";
4938 print "<br/><br/></div>\n";
4939 print "<div class=\"title\">$hash</div>\n";
4941 if (defined $file_name) {
4942 $basedir = $file_name;
4943 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4946 git_print_page_path($file_name, 'tree', $hash_base);
4948 print "<div class=\"page_body\">\n";
4949 print "<table class=\"tree\">\n";
4951 # '..' (top directory) link if possible
4952 if (defined $hash_base &&
4953 defined $file_name && $file_name =~ m![^/]+$!) {
4955 print "<tr class=\"dark\">\n";
4957 print "<tr class=\"light\">\n";
4961 my $up = $file_name;
4962 $up =~ s!/?[^/]+$!!;
4963 undef $up unless $up;
4964 # based on git_print_tree_entry
4965 print '<td class="mode">' . mode_str('040000') . "</td>\n";
4966 print '<td class="list">';
4967 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
4971 print "<td class=\"link\"></td>\n";
4975 foreach my $line (@entries) {
4976 my %t = parse_ls_tree_line($line, -z => 1);
4979 print "<tr class=\"dark\">\n";
4981 print "<tr class=\"light\">\n";
4985 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
4989 print "</table>\n" .
4994 my $format = $input_params{'snapshot_format'};
4995 if (!@snapshot_fmts) {
4996 die_error(403, "Snapshots not allowed");
4998 # default to first supported snapshot format
4999 $format ||= $snapshot_fmts[0];
5000 if ($format !~ m/^[a-z0-9]+$/) {
5001 die_error(400, "Invalid snapshot format parameter");
5002 } elsif (!exists($known_snapshot_formats{$format})) {
5003 die_error(400, "Unknown snapshot format");
5004 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5005 die_error(403, "Unsupported snapshot format");
5008 if (!defined $hash) {
5009 $hash = git_get_head_hash($project);
5012 my $name = $project;
5013 $name =~ s,([^/])/*\.git$,$1,;
5014 $name = basename($name);
5015 my $filename = to_utf8($name);
5016 $name =~ s/\047/\047\\\047\047/g;
5018 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5019 $cmd = quote_command(
5020 git_cmd(), 'archive',
5021 "--format=$known_snapshot_formats{$format}{'format'}",
5022 "--prefix=$name/", $hash);
5023 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5024 $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
5028 -type => $known_snapshot_formats{$format}{'type'},
5029 -content_disposition => 'inline; filename="' . "$filename" . '"',
5030 -status => '200 OK');
5032 open my $fd, "-|", $cmd
5033 or die_error(500, "Execute git-archive failed");
5034 binmode STDOUT, ':raw';
5036 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
5041 my $head = git_get_head_hash($project);
5042 if (!defined $hash) {
5045 if (!defined $page) {
5048 my $refs = git_get_references();
5050 my @commitlist = parse_commits($hash, 101, (100 * $page));
5052 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5054 my ($patch_max) = gitweb_get_feature('patches');
5056 if ($patch_max < 0 || @commitlist <= $patch_max) {
5057 $paging_nav .= " ⋅ " .
5058 $cgi->a({-href => href(action=>"patches", -replay=>1)},
5063 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
5066 my %co = parse_commit($hash);
5068 git_print_header_div('summary', $project);
5069 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5071 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5072 for (my $i = 0; $i <= $to; $i++) {
5073 my %co = %{$commitlist[$i]};
5075 my $commit = $co{'id'};
5076 my $ref = format_ref_marker($refs, $commit);
5077 my %ad = parse_date($co{'author_epoch'});
5078 git_print_header_div('commit',
5079 "<span class=\"age\">$co{'age_string'}</span>" .
5080 esc_html($co{'title'}) . $ref,
5082 print "<div class=\"title_text\">\n" .
5083 "<div class=\"log_link\">\n" .
5084 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
5086 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
5088 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
5091 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5094 print "<div class=\"log_body\">\n";
5095 git_print_log($co{'comment'}, -final_empty_line=> 1);
5098 if ($#commitlist >= 100) {
5099 print "<div class=\"page_nav\">\n";
5100 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
5101 -accesskey => "n", -title => "Alt-n"}, "next");
5107 $hash ||= $hash_base || "HEAD";
5108 my %co = parse_commit($hash)
5109 or die_error(404, "Unknown commit object");
5110 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5111 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
5113 my $parent = $co{'parent'};
5114 my $parents = $co{'parents'}; # listref
5116 # we need to prepare $formats_nav before any parameter munging
5118 if (!defined $parent) {
5120 $formats_nav .= '(initial)';
5121 } elsif (@$parents == 1) {
5122 # single parent commit
5125 $cgi->a({-href => href(action=>"commit",
5127 esc_html(substr($parent, 0, 7))) .
5134 $cgi->a({-href => href(action=>"commit",
5136 esc_html(substr($_, 0, 7)));
5140 if (gitweb_check_feature('patches')) {
5141 $formats_nav .= " | " .
5142 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5146 if (!defined $parent) {
5150 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
5152 (@$parents <= 1 ? $parent : '-c'),
5154 or die_error(500, "Open git-diff-tree failed");
5155 @difftree = map { chomp; $_ } <$fd>;
5156 close $fd or die_error(404, "Reading git-diff-tree failed");
5158 # non-textual hash id's can be cached
5160 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5163 my $refs = git_get_references();
5164 my $ref = format_ref_marker($refs, $co{'id'});
5166 git_print_page_nav('commit', '',
5167 $hash, $co{'tree'}, $hash,
5170 if (defined $co{'parent'}) {
5171 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
5173 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
5175 print "<div class=\"title_text\">\n" .
5176 "<table class=\"object_header\">\n";
5177 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
5179 "<td></td><td> $ad{'rfc2822'}";
5180 if ($ad{'hour_local'} < 6) {
5181 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5182 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5184 printf(" (%02d:%02d %s)",
5185 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5189 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
5190 print "<tr><td></td><td> $cd{'rfc2822'}" .
5191 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5193 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5196 "<td class=\"sha1\">" .
5197 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
5198 class => "list"}, $co{'tree'}) .
5200 "<td class=\"link\">" .
5201 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
5203 my $snapshot_links = format_snapshot_links($hash);
5204 if (defined $snapshot_links) {
5205 print " | " . $snapshot_links;
5210 foreach my $par (@$parents) {
5213 "<td class=\"sha1\">" .
5214 $cgi->a({-href => href(action=>"commit", hash=>$par),
5215 class => "list"}, $par) .
5217 "<td class=\"link\">" .
5218 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
5220 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
5227 print "<div class=\"page_body\">\n";
5228 git_print_log($co{'comment'});
5231 git_difftree_body(\@difftree, $hash, @$parents);
5236 # object is defined by:
5237 # - hash or hash_base alone
5238 # - hash_base and file_name
5241 # - hash or hash_base alone
5242 if ($hash || ($hash_base && !defined $file_name)) {
5243 my $object_id = $hash || $hash_base;
5245 open my $fd, "-|", quote_command(
5246 git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5247 or die_error(404, "Object does not exist");
5251 or die_error(404, "Object does not exist");
5253 # - hash_base and file_name
5254 } elsif ($hash_base && defined $file_name) {
5255 $file_name =~ s,/+$,,;
5257 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
5258 or die_error(404, "Base object does not exist");
5260 # here errors should not hapen
5261 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
5262 or die_error(500, "Open git-ls-tree failed");
5266 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5267 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5268 die_error(404, "File or directory for given base does not exist");
5273 die_error(400, "Not enough information to find object");
5276 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
5277 hash=>$hash, hash_base=>$hash_base,
5278 file_name=>$file_name),
5279 -status => '302 Found');
5283 my $format = shift || 'html';
5290 # preparing $fd and %diffinfo for git_patchset_body
5292 if (defined $hash_base && defined $hash_parent_base) {
5293 if (defined $file_name) {
5295 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5296 $hash_parent_base, $hash_base,
5297 "--", (defined $file_parent ? $file_parent : ()), $file_name
5298 or die_error(500, "Open git-diff-tree failed");
5299 @difftree = map { chomp; $_ } <$fd>;
5301 or die_error(404, "Reading git-diff-tree failed");
5303 or die_error(404, "Blob diff not found");
5305 } elsif (defined $hash &&
5306 $hash =~ /[0-9a-fA-F]{40}/) {
5307 # try to find filename from $hash
5309 # read filtered raw output
5310 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5311 $hash_parent_base, $hash_base, "--"
5312 or die_error(500, "Open git-diff-tree failed");
5314 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5316 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5317 map { chomp; $_ } <$fd>;
5319 or die_error(404, "Reading git-diff-tree failed");
5321 or die_error(404, "Blob diff not found");
5324 die_error(400, "Missing one of the blob diff parameters");
5327 if (@difftree > 1) {
5328 die_error(400, "Ambiguous blob diff specification");
5331 %diffinfo = parse_difftree_raw_line($difftree[0]);
5332 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5333 $file_name ||= $diffinfo{'to_file'};
5335 $hash_parent ||= $diffinfo{'from_id'};
5336 $hash ||= $diffinfo{'to_id'};
5338 # non-textual hash id's can be cached
5339 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5340 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5345 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5346 '-p', ($format eq 'html' ? "--full-index" : ()),
5347 $hash_parent_base, $hash_base,
5348 "--", (defined $file_parent ? $file_parent : ()), $file_name
5349 or die_error(500, "Open git-diff-tree failed");
5352 # old/legacy style URI -- not generated anymore since 1.4.3.
5354 die_error('404 Not Found', "Missing one of the blob diff parameters")
5358 if ($format eq 'html') {
5360 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
5362 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5363 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5364 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5366 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5367 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5369 if (defined $file_name) {
5370 git_print_page_path($file_name, "blob", $hash_base);
5372 print "<div class=\"page_path\"></div>\n";
5375 } elsif ($format eq 'plain') {
5377 -type => 'text/plain',
5378 -charset => 'utf-8',
5379 -expires => $expires,
5380 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
5382 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5385 die_error(400, "Unknown blobdiff format");
5389 if ($format eq 'html') {
5390 print "<div class=\"page_body\">\n";
5392 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
5395 print "</div>\n"; # class="page_body"
5398 while (my $line = <$fd>) {
5399 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5400 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5404 last if $line =~ m!^\+\+\+!;
5412 sub git_blobdiff_plain {
5413 git_blobdiff('plain');
5416 sub git_commitdiff {
5418 my $format = $params{-format} || 'html';
5420 my ($patch_max) = gitweb_get_feature('patches');
5421 if ($format eq 'patch') {
5422 die_error(403, "Patch view not allowed") unless $patch_max;
5425 $hash ||= $hash_base || "HEAD";
5426 my %co = parse_commit($hash)
5427 or die_error(404, "Unknown commit object");
5429 # choose format for commitdiff for merge
5430 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5431 $hash_parent = '--cc';
5433 # we need to prepare $formats_nav before almost any parameter munging
5435 if ($format eq 'html') {
5437 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
5440 $formats_nav .= " | " .
5441 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5445 if (defined $hash_parent &&
5446 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5447 # commitdiff with two commits given
5448 my $hash_parent_short = $hash_parent;
5449 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5450 $hash_parent_short = substr($hash_parent, 0, 7);
5454 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5455 if ($co{'parents'}[$i] eq $hash_parent) {
5456 $formats_nav .= ' parent ' . ($i+1);
5460 $formats_nav .= ': ' .
5461 $cgi->a({-href => href(action=>"commitdiff",
5462 hash=>$hash_parent)},
5463 esc_html($hash_parent_short)) .
5465 } elsif (!$co{'parent'}) {
5467 $formats_nav .= ' (initial)';
5468 } elsif (scalar @{$co{'parents'}} == 1) {
5469 # single parent commit
5472 $cgi->a({-href => href(action=>"commitdiff",
5473 hash=>$co{'parent'})},
5474 esc_html(substr($co{'parent'}, 0, 7))) .
5478 if ($hash_parent eq '--cc') {
5479 $formats_nav .= ' | ' .
5480 $cgi->a({-href => href(action=>"commitdiff",
5481 hash=>$hash, hash_parent=>'-c')},
5483 } else { # $hash_parent eq '-c'
5484 $formats_nav .= ' | ' .
5485 $cgi->a({-href => href(action=>"commitdiff",
5486 hash=>$hash, hash_parent=>'--cc')},
5492 $cgi->a({-href => href(action=>"commitdiff",
5494 esc_html(substr($_, 0, 7)));
5495 } @{$co{'parents'}} ) .
5500 my $hash_parent_param = $hash_parent;
5501 if (!defined $hash_parent_param) {
5502 # --cc for multiple parents, --root for parentless
5503 $hash_parent_param =
5504 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5510 if ($format eq 'html') {
5511 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5512 "--no-commit-id", "--patch-with-raw", "--full-index",
5513 $hash_parent_param, $hash, "--"
5514 or die_error(500, "Open git-diff-tree failed");
5516 while (my $line = <$fd>) {
5518 # empty line ends raw part of diff-tree output
5520 push @difftree, scalar parse_difftree_raw_line($line);
5523 } elsif ($format eq 'plain') {
5524 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5525 '-p', $hash_parent_param, $hash, "--"
5526 or die_error(500, "Open git-diff-tree failed");
5527 } elsif ($format eq 'patch') {
5528 # For commit ranges, we limit the output to the number of
5529 # patches specified in the 'patches' feature.
5530 # For single commits, we limit the output to a single patch,
5531 # diverging from the git-format-patch default.
5532 my @commit_spec = ();
5534 if ($patch_max > 0) {
5535 push @commit_spec, "-$patch_max";
5537 push @commit_spec, '-n', "$hash_parent..$hash";
5539 if ($params{-single}) {
5540 push @commit_spec, '-1';
5542 if ($patch_max > 0) {
5543 push @commit_spec, "-$patch_max";
5545 push @commit_spec, "-n";
5547 push @commit_spec, '--root', $hash;
5549 open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
5550 '--stdout', @commit_spec
5551 or die_error(500, "Open git-format-patch failed");
5553 die_error(400, "Unknown commitdiff format");
5556 # non-textual hash id's can be cached
5558 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5562 # write commit message
5563 if ($format eq 'html') {
5564 my $refs = git_get_references();
5565 my $ref = format_ref_marker($refs, $co{'id'});
5567 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5568 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5569 git_print_authorship(\%co);
5570 print "<div class=\"page_body\">\n";
5571 if (@{$co{'comment'}} > 1) {
5572 print "<div class=\"log\">\n";
5573 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5574 print "</div>\n"; # class="log"
5577 } elsif ($format eq 'plain') {
5578 my $refs = git_get_references("tags");
5579 my $tagname = git_get_rev_name_tags($hash);
5580 my $filename = basename($project) . "-$hash.patch";
5583 -type => 'text/plain',
5584 -charset => 'utf-8',
5585 -expires => $expires,
5586 -content_disposition => 'inline; filename="' . "$filename" . '"');
5587 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5588 print "From: " . to_utf8($co{'author'}) . "\n";
5589 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5590 print "Subject: " . to_utf8($co{'title'}) . "\n";
5592 print "X-Git-Tag: $tagname\n" if $tagname;
5593 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5595 foreach my $line (@{$co{'comment'}}) {
5596 print to_utf8($line) . "\n";
5599 } elsif ($format eq 'patch') {
5600 my $filename = basename($project) . "-$hash.patch";
5603 -type => 'text/plain',
5604 -charset => 'utf-8',
5605 -expires => $expires,
5606 -content_disposition => 'inline; filename="' . "$filename" . '"');
5610 if ($format eq 'html') {
5611 my $use_parents = !defined $hash_parent ||
5612 $hash_parent eq '-c' || $hash_parent eq '--cc';
5613 git_difftree_body(\@difftree, $hash,
5614 $use_parents ? @{$co{'parents'}} : $hash_parent);
5617 git_patchset_body($fd, \@difftree, $hash,
5618 $use_parents ? @{$co{'parents'}} : $hash_parent);
5620 print "</div>\n"; # class="page_body"
5622 } elsif ($format eq 'plain') {
5626 or print "Reading git-diff-tree failed\n";
5627 } elsif ($format eq 'patch') {
5631 or print "Reading git-format-patch failed\n";
5635 sub git_commitdiff_plain {
5636 git_commitdiff(-format => 'plain');
5639 # format-patch-style patches
5641 git_commitdiff(-format => 'patch', -single=> 1);
5645 git_commitdiff(-format => 'patch');
5649 if (!defined $hash_base) {
5650 $hash_base = git_get_head_hash($project);
5652 if (!defined $page) {
5656 my %co = parse_commit($hash_base)
5657 or die_error(404, "Unknown commit object");
5659 my $refs = git_get_references();
5660 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5662 my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5663 $file_name, "--full-history")
5664 or die_error(404, "No such file or directory on given branch");
5666 if (!defined $hash && defined $file_name) {
5667 # some commits could have deleted file in question,
5668 # and not have it in tree, but one of them has to have it
5669 for (my $i = 0; $i <= @commitlist; $i++) {
5670 $hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5671 last if defined $hash;
5674 if (defined $hash) {
5675 $ftype = git_get_type($hash);
5677 if (!defined $ftype) {
5678 die_error(500, "Unknown type of object");
5681 my $paging_nav = '';
5684 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5685 file_name=>$file_name)},
5687 $paging_nav .= " ⋅ " .
5688 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5689 -accesskey => "p", -title => "Alt-p"}, "prev");
5691 $paging_nav .= "first";
5692 $paging_nav .= " ⋅ prev";
5695 if ($#commitlist >= 100) {
5697 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5698 -accesskey => "n", -title => "Alt-n"}, "next");
5699 $paging_nav .= " ⋅ $next_link";
5701 $paging_nav .= " ⋅ next";
5704 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5705 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5706 git_print_page_path($file_name, $ftype, $hash_base);
5708 git_history_body(\@commitlist, 0, 99,
5709 $refs, $hash_base, $ftype, $next_link);
5714 gitweb_check_feature('search') or die_error(403, "Search is disabled");
5715 if (!defined $searchtext) {
5716 die_error(400, "Text field is empty");
5718 if (!defined $hash) {
5719 $hash = git_get_head_hash($project);
5721 my %co = parse_commit($hash);
5723 die_error(404, "Unknown commit object");
5725 if (!defined $page) {
5729 $searchtype ||= 'commit';
5730 if ($searchtype eq 'pickaxe') {
5731 # pickaxe may take all resources of your box and run for several minutes
5732 # with every query - so decide by yourself how public you make this feature
5733 gitweb_check_feature('pickaxe')
5734 or die_error(403, "Pickaxe is disabled");
5736 if ($searchtype eq 'grep') {
5737 gitweb_check_feature('grep')
5738 or die_error(403, "Grep is disabled");
5742 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5744 if ($searchtype eq 'commit') {
5745 $greptype = "--grep=";
5746 } elsif ($searchtype eq 'author') {
5747 $greptype = "--author=";
5748 } elsif ($searchtype eq 'committer') {
5749 $greptype = "--committer=";
5751 $greptype .= $searchtext;
5752 my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5753 $greptype, '--regexp-ignore-case',
5754 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5756 my $paging_nav = '';
5759 $cgi->a({-href => href(action=>"search", hash=>$hash,
5760 searchtext=>$searchtext,
5761 searchtype=>$searchtype)},
5763 $paging_nav .= " ⋅ " .
5764 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5765 -accesskey => "p", -title => "Alt-p"}, "prev");
5767 $paging_nav .= "first";
5768 $paging_nav .= " ⋅ prev";
5771 if ($#commitlist >= 100) {
5773 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5774 -accesskey => "n", -title => "Alt-n"}, "next");
5775 $paging_nav .= " ⋅ $next_link";
5777 $paging_nav .= " ⋅ next";
5780 if ($#commitlist >= 100) {
5783 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5784 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5785 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5788 if ($searchtype eq 'pickaxe') {
5789 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5790 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5792 print "<table class=\"pickaxe search\">\n";
5795 open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
5796 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5797 ($search_use_regexp ? '--pickaxe-regex' : ());
5800 while (my $line = <$fd>) {
5804 my %set = parse_difftree_raw_line($line);
5805 if (defined $set{'commit'}) {
5806 # finish previous commit
5809 "<td class=\"link\">" .
5810 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5812 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5818 print "<tr class=\"dark\">\n";
5820 print "<tr class=\"light\">\n";
5823 %co = parse_commit($set{'commit'});
5824 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5825 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5826 "<td><i>$author</i></td>\n" .
5828 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
5829 -class => "list subject"},
5830 chop_and_escape_str($co{'title'}, 50) . "<br/>");
5831 } elsif (defined $set{'to_id'}) {
5832 next if ($set{'to_id'} =~ m/^0{40}$/);
5834 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
5835 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),
5837 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
5843 # finish last commit (warning: repetition!)
5846 "<td class=\"link\">" .
5847 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5849 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5857 if ($searchtype eq 'grep') {
5858 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5859 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5861 print "<table class=\"grep_search\">\n";
5865 open my $fd, "-|", git_cmd(), 'grep', '-n',
5866 $search_use_regexp ? ('-E', '-i') : '-F',
5867 $searchtext, $co{'tree'};
5869 while (my $line = <$fd>) {
5871 my ($file, $lno, $ltext, $binary);
5872 last if ($matches++ > 1000);
5873 if ($line =~ /^Binary file (.+) matches$/) {
5877 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5879 if ($file ne $lastfile) {
5880 $lastfile and print "</td></tr>\n";
5882 print "<tr class=\"dark\">\n";
5884 print "<tr class=\"light\">\n";
5886 print "<td class=\"list\">".
5887 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5888 file_name=>"$file"),
5889 -class => "list"}, esc_path($file));
5890 print "</td><td>\n";
5894 print "<div class=\"binary\">Binary file</div>\n";
5896 $ltext = untabify($ltext);
5897 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5898 $ltext = esc_html($1, -nbsp=>1);
5899 $ltext .= '<span class="match">';
5900 $ltext .= esc_html($2, -nbsp=>1);
5901 $ltext .= '</span>';
5902 $ltext .= esc_html($3, -nbsp=>1);
5904 $ltext = esc_html($ltext, -nbsp=>1);
5906 print "<div class=\"pre\">" .
5907 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5908 file_name=>"$file").'#l'.$lno,
5909 -class => "linenr"}, sprintf('%4i', $lno))
5910 . ' ' . $ltext . "</div>\n";
5914 print "</td></tr>\n";
5915 if ($matches > 1000) {
5916 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5919 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5927 sub git_search_help {
5928 git_print_page_nav('','', $hash,$hash,$hash);
5930 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5931 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5932 the pattern entered is recognized as the POSIX extended
5933 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5936 <dt><b>commit</b></dt>
5937 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5939 my $have_grep = gitweb_check_feature('grep');
5942 <dt><b>grep</b></dt>
5943 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5944 a different one) are searched for the given pattern. On large trees, this search can take
5945 a while and put some strain on the server, so please use it with some consideration. Note that
5946 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5947 case-sensitive.</dd>
5951 <dt><b>author</b></dt>
5952 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5953 <dt><b>committer</b></dt>
5954 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5956 my $have_pickaxe = gitweb_check_feature('pickaxe');
5957 if ($have_pickaxe) {
5959 <dt><b>pickaxe</b></dt>
5960 <dd>All commits that caused the string to appear or disappear from any file (changes that
5961 added, removed or "modified" the string) will be listed. This search can take a while and
5962 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5963 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5970 my $head = git_get_head_hash($project);
5971 if (!defined $hash) {
5974 if (!defined $page) {
5977 my $refs = git_get_references();
5979 my $commit_hash = $hash;
5980 if (defined $hash_parent) {
5981 $commit_hash = "$hash_parent..$hash";
5983 my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
5985 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
5987 if ($#commitlist >= 100) {
5989 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5990 -accesskey => "n", -title => "Alt-n"}, "next");
5992 my $patch_max = gitweb_check_feature('patches');
5994 if ($patch_max < 0 || @commitlist <= $patch_max) {
5995 $paging_nav .= " ⋅ " .
5996 $cgi->a({-href => href(action=>"patches", -replay=>1)},
6001 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
6002 git_print_header_div('summary', $project);
6004 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
6008 ## ......................................................................
6009 ## feeds (RSS, Atom; OPML)
6012 my $format = shift || 'atom';
6013 my $have_blame = gitweb_check_feature('blame');
6015 # Atom: http://www.atomenabled.org/developers/syndication/
6016 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6017 if ($format ne 'rss' && $format ne 'atom') {
6018 die_error(400, "Unknown web feed format");
6021 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6022 my $head = $hash || 'HEAD';
6023 my @commitlist = parse_commits($head, 150, 0, $file_name);
6027 my $content_type = "application/$format+xml";
6028 if (defined $cgi->http('HTTP_ACCEPT') &&
6029 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6030 # browser (feed reader) prefers text/xml
6031 $content_type = 'text/xml';
6033 if (defined($commitlist[0])) {
6034 %latest_commit = %{$commitlist[0]};
6035 my $latest_epoch = $latest_commit{'committer_epoch'};
6036 %latest_date = parse_date($latest_epoch);
6037 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6038 if (defined $if_modified) {
6040 if (eval { require HTTP::Date; 1; }) {
6041 $since = HTTP::Date::str2time($if_modified);
6042 } elsif (eval { require Time::ParseDate; 1; }) {
6043 $since = Time::ParseDate::parsedate($if_modified, GMT => 1);
6045 if (defined $since && $latest_epoch <= $since) {
6047 -type => $content_type,
6048 -charset => 'utf-8',
6049 -last_modified => $latest_date{'rfc2822'},
6050 -status => '304 Not Modified');
6055 -type => $content_type,
6056 -charset => 'utf-8',
6057 -last_modified => $latest_date{'rfc2822'});
6060 -type => $content_type,
6061 -charset => 'utf-8');
6064 # Optimization: skip generating the body if client asks only
6065 # for Last-Modified date.
6066 return if ($cgi->request_method() eq 'HEAD');
6069 my $title = "$site_name - $project/$action";
6070 my $feed_type = 'log';
6071 if (defined $hash) {
6072 $title .= " - '$hash'";
6073 $feed_type = 'branch log';
6074 if (defined $file_name) {
6075 $title .= " :: $file_name";
6076 $feed_type = 'history';
6078 } elsif (defined $file_name) {
6079 $title .= " - $file_name";
6080 $feed_type = 'history';
6082 $title .= " $feed_type";
6083 my $descr = git_get_project_description($project);
6084 if (defined $descr) {
6085 $descr = esc_html($descr);
6087 $descr = "$project " .
6088 ($format eq 'rss' ? 'RSS' : 'Atom') .
6091 my $owner = git_get_project_owner($project);
6092 $owner = esc_html($owner);
6096 if (defined $file_name) {
6097 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
6098 } elsif (defined $hash) {
6099 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
6101 $alt_url = href(-full=>1, action=>"summary");
6103 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
6104 if ($format eq 'rss') {
6106 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6109 print "<title>$title</title>\n" .
6110 "<link>$alt_url</link>\n" .
6111 "<description>$descr</description>\n" .
6112 "<language>en</language>\n" .
6113 # project owner is responsible for 'editorial' content
6114 "<managingEditor>$owner</managingEditor>\n";
6115 if (defined $logo || defined $favicon) {
6116 # prefer the logo to the favicon, since RSS
6117 # doesn't allow both
6118 my $img = esc_url($logo || $favicon);
6120 "<url>$img</url>\n" .
6121 "<title>$title</title>\n" .
6122 "<link>$alt_url</link>\n" .
6126 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6127 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6129 print "<generator>gitweb v.$version/$git_version</generator>\n";
6130 } elsif ($format eq 'atom') {
6132 <feed xmlns="http://www.w3.org/2005/Atom">
6134 print "<title>$title</title>\n" .
6135 "<subtitle>$descr</subtitle>\n" .
6136 '<link rel="alternate" type="text/html" href="' .
6137 $alt_url . '" />' . "\n" .
6138 '<link rel="self" type="' . $content_type . '" href="' .
6139 $cgi->self_url() . '" />' . "\n" .
6140 "<id>" . href(-full=>1) . "</id>\n" .
6141 # use project owner for feed author
6142 "<author><name>$owner</name></author>\n";
6143 if (defined $favicon) {
6144 print "<icon>" . esc_url($favicon) . "</icon>\n";
6146 if (defined $logo_url) {
6147 # not twice as wide as tall: 72 x 27 pixels
6148 print "<logo>" . esc_url($logo) . "</logo>\n";
6150 if (! %latest_date) {
6151 # dummy date to keep the feed valid until commits trickle in:
6152 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6154 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6156 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6160 for (my $i = 0; $i <= $#commitlist; $i++) {
6161 my %co = %{$commitlist[$i]};
6162 my $commit = $co{'id'};
6163 # we read 150, we always show 30 and the ones more recent than 48 hours
6164 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6167 my %cd = parse_date($co{'author_epoch'});
6169 # get list of changed files
6170 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
6171 $co{'parent'} || "--root",
6172 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6174 my @difftree = map { chomp; $_ } <$fd>;
6178 # print element (entry, item)
6179 my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
6180 if ($format eq 'rss') {
6182 "<title>" . esc_html($co{'title'}) . "</title>\n" .
6183 "<author>" . esc_html($co{'author'}) . "</author>\n" .
6184 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6185 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6186 "<link>$co_url</link>\n" .
6187 "<description>" . esc_html($co{'title'}) . "</description>\n" .
6188 "<content:encoded>" .
6190 } elsif ($format eq 'atom') {
6192 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
6193 "<updated>$cd{'iso-8601'}</updated>\n" .
6195 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
6196 if ($co{'author_email'}) {
6197 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
6199 print "</author>\n" .
6200 # use committer for contributor
6202 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
6203 if ($co{'committer_email'}) {
6204 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
6206 print "</contributor>\n" .
6207 "<published>$cd{'iso-8601'}</published>\n" .
6208 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6209 "<id>$co_url</id>\n" .
6210 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
6211 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6213 my $comment = $co{'comment'};
6215 foreach my $line (@$comment) {
6216 $line = esc_html($line);
6219 print "</pre><ul>\n";
6220 foreach my $difftree_line (@difftree) {
6221 my %difftree = parse_difftree_raw_line($difftree_line);
6222 next if !$difftree{'from_id'};
6224 my $file = $difftree{'file'} || $difftree{'to_file'};
6228 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
6229 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
6230 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
6231 file_name=>$file, file_parent=>$difftree{'from_file'}),
6232 -title => "diff"}, 'D');
6234 print $cgi->a({-href => href(-full=>1, action=>"blame",
6235 file_name=>$file, hash_base=>$commit),
6236 -title => "blame"}, 'B');
6238 # if this is not a feed of a file history
6239 if (!defined $file_name || $file_name ne $file) {
6240 print $cgi->a({-href => href(-full=>1, action=>"history",
6241 file_name=>$file, hash=>$commit),
6242 -title => "history"}, 'H');
6244 $file = esc_path($file);
6248 if ($format eq 'rss') {
6249 print "</ul>]]>\n" .
6250 "</content:encoded>\n" .
6252 } elsif ($format eq 'atom') {
6253 print "</ul>\n</div>\n" .
6260 if ($format eq 'rss') {
6261 print "</channel>\n</rss>\n";
6262 } elsif ($format eq 'atom') {
6276 my @list = git_get_projects_list();
6279 -type => 'text/xml',
6280 -charset => 'utf-8',
6281 -content_disposition => 'inline; filename="opml.xml"');
6284 <?xml version="1.0" encoding="utf-8"?>
6285 <opml version="1.0">
6287 <title>$site_name OPML Export</title>
6290 <outline text="git RSS feeds">
6293 foreach my $pr (@list) {
6295 my $head = git_get_head_hash($proj{'path'});
6296 if (!defined $head) {
6299 $git_dir = "$projectroot/$proj{'path'}";
6300 my %co = parse_commit($head);
6305 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
6306 my $rss = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
6307 my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
6308 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";