3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
18 use File::Basename qw(basename);
19 binmode STDOUT, ':utf8';
22 CGI->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute => 1);
30 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31 # needed and used only for URLs with nonempty PATH_INFO
32 our $base_url = $my_url;
34 # When the script is used as DirectoryIndex, the URL does not contain the name
35 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36 # have to do it ourselves. We make $path_info global because it's also used
39 # Another issue with the script being the DirectoryIndex is that the resulting
40 # $my_url data is not the full script URL: this is good, because we want
41 # generated links to keep implying the script name if it wasn't explicitly
42 # indicated in the URL we're handling, but it means that $my_url cannot be used
44 # Therefore, if we needed to strip PATH_INFO, then we know that we have
45 # to build the base URL ourselves:
46 our $path_info = $ENV{"PATH_INFO"};
48 if ($my_url =~ s,\Q$path_info\E$,, &&
49 $my_uri =~ s,\Q$path_info\E$,, &&
50 defined $ENV{'SCRIPT_NAME'}) {
51 $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
55 # core git executable to use
56 # this can just be "git" if your webserver has a sensible PATH
57 our $GIT = "++GIT_BINDIR++/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "++GITWEB_PROJECTROOT++";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
67 # target of the home link on top of all pages
68 our $home_link = $my_uri || "/";
70 # string of the home link on top of all pages
71 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
73 # name of your site or organization to appear in page titles
74 # replace this with something more descriptive for clearer bookmarks
75 our $site_name = "++GITWEB_SITENAME++"
76 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 # filename of html text to include at top of each page
79 our $site_header = "++GITWEB_SITE_HEADER++";
80 # html text to include at home page
81 our $home_text = "++GITWEB_HOMETEXT++";
82 # filename of html text to include at bottom of each page
83 our $site_footer = "++GITWEB_SITE_FOOTER++";
86 our @stylesheets = ("++GITWEB_CSS++");
87 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
88 our $stylesheet = undef;
89 # URI of GIT logo (72x27 size)
90 our $logo = "++GITWEB_LOGO++";
91 # URI of GIT favicon, assumed to be image/png type
92 our $favicon = "++GITWEB_FAVICON++";
94 # URI and label (title) of GIT logo link
95 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
96 #our $logo_label = "git documentation";
97 our $logo_url = "http://git.or.cz/";
98 our $logo_label = "git homepage";
100 # source of projects list
101 our $projects_list = "++GITWEB_LIST++";
103 # the width (in characters) of the projects list "Description" column
104 our $projects_list_description_width = 25;
106 # default order of projects list
107 # valid values are none, project, descr, owner, and age
108 our $default_projects_order = "project";
110 # show repository only if this file exists
111 # (only effective if this variable evaluates to true)
112 our $export_ok = "++GITWEB_EXPORT_OK++";
114 # show repository only if this subroutine returns true
115 # when given the path to the project, for example:
116 # sub { return -e "$_[0]/git-daemon-export-ok"; }
117 our $export_auth_hook = undef;
119 # only allow viewing of repositories also shown on the overview page
120 our $strict_export = "++GITWEB_STRICT_EXPORT++";
122 # list of git base URLs used for URL to where fetch project from,
123 # i.e. full URL is "$git_base_url/$project"
124 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
126 # default blob_plain mimetype and default charset for text/plain blob
127 our $default_blob_plain_mimetype = 'text/plain';
128 our $default_text_plain_charset = undef;
130 # file to use for guessing MIME types before trying /etc/mime.types
131 # (relative to the current git repository)
132 our $mimetypes_file = undef;
134 # assume this charset if line contains non-UTF-8 characters;
135 # it should be valid encoding (see Encoding::Supported(3pm) for list),
136 # for which encoding all byte sequences are valid, for example
137 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
138 # could be even 'utf-8' for the old behavior)
139 our $fallback_encoding = 'latin1';
141 # rename detection options for git-diff and git-diff-tree
142 # - default is '-M', with the cost proportional to
143 # (number of removed files) * (number of new files).
144 # - more costly is '-C' (which implies '-M'), with the cost proportional to
145 # (number of changed files + number of removed files) * (number of new files)
146 # - even more costly is '-C', '--find-copies-harder' with cost
147 # (number of files in the original tree) * (number of new files)
148 # - one might want to include '-B' option, e.g. '-B', '-M'
149 our @diff_opts = ('-M'); # taken from git_commit
151 # Disables features that would allow repository owners to inject script into
153 our $prevent_xss = 0;
155 # information about snapshot formats that gitweb is capable of serving
156 our %known_snapshot_formats = (
158 # 'display' => display name,
159 # 'type' => mime type,
160 # 'suffix' => filename suffix,
161 # 'format' => --format for git-archive,
162 # 'compressor' => [compressor command and arguments]
163 # (array reference, optional)}
166 'display' => 'tar.gz',
167 'type' => 'application/x-gzip',
168 'suffix' => '.tar.gz',
170 'compressor' => ['gzip']},
173 'display' => 'tar.bz2',
174 'type' => 'application/x-bzip2',
175 'suffix' => '.tar.bz2',
177 'compressor' => ['bzip2']},
181 'type' => 'application/x-zip',
186 # Aliases so we understand old gitweb.snapshot values in repository
188 our %known_snapshot_format_aliases = (
192 # backward compatibility: legacy gitweb config support
193 'x-gzip' => undef, 'gz' => undef,
194 'x-bzip2' => undef, 'bz2' => undef,
195 'x-zip' => undef, '' => undef,
198 # You define site-wide feature defaults here; override them with
199 # $GITWEB_CONFIG as necessary.
202 # 'sub' => feature-sub (subroutine),
203 # 'override' => allow-override (boolean),
204 # 'default' => [ default options...] (array reference)}
206 # if feature is overridable (it means that allow-override has true value),
207 # then feature-sub will be called with default options as parameters;
208 # return value of feature-sub indicates if to enable specified feature
210 # if there is no 'sub' key (no feature-sub), then feature cannot be
213 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
214 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
217 # Enable the 'blame' blob view, showing the last commit that modified
218 # each line in the file. This can be very CPU-intensive.
220 # To enable system wide have in $GITWEB_CONFIG
221 # $feature{'blame'}{'default'} = [1];
222 # To have project specific config enable override in $GITWEB_CONFIG
223 # $feature{'blame'}{'override'} = 1;
224 # and in project config gitweb.blame = 0|1;
226 'sub' => sub { feature_bool('blame', @_) },
230 # Enable the 'snapshot' link, providing a compressed archive of any
231 # tree. This can potentially generate high traffic if you have large
234 # Value is a list of formats defined in %known_snapshot_formats that
236 # To disable system wide have in $GITWEB_CONFIG
237 # $feature{'snapshot'}{'default'} = [];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'snapshot'}{'override'} = 1;
240 # and in project config, a comma-separated list of formats or "none"
241 # to disable. Example: gitweb.snapshot = tbz2,zip;
243 'sub' => \&feature_snapshot,
245 'default' => ['tgz']},
247 # Enable text search, which will list the commits which match author,
248 # committer or commit text to a given string. Enabled by default.
249 # Project specific override is not supported.
254 # Enable grep search, which will list the files in currently selected
255 # tree containing the given string. Enabled by default. This can be
256 # potentially CPU-intensive, of course.
258 # To enable system wide have in $GITWEB_CONFIG
259 # $feature{'grep'}{'default'} = [1];
260 # To have project specific config enable override in $GITWEB_CONFIG
261 # $feature{'grep'}{'override'} = 1;
262 # and in project config gitweb.grep = 0|1;
264 'sub' => sub { feature_bool('grep', @_) },
268 # Enable the pickaxe search, which will list the commits that modified
269 # a given string in a file. This can be practical and quite faster
270 # alternative to 'blame', but still potentially CPU-intensive.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'pickaxe'}{'default'} = [1];
274 # To have project specific config enable override in $GITWEB_CONFIG
275 # $feature{'pickaxe'}{'override'} = 1;
276 # and in project config gitweb.pickaxe = 0|1;
278 'sub' => sub { feature_bool('pickaxe', @_) },
282 # Make gitweb use an alternative format of the URLs which can be
283 # more readable and natural-looking: project name is embedded
284 # directly in the path and the query string contains other
285 # auxiliary information. All gitweb installations recognize
286 # URL in either format; this configures in which formats gitweb
289 # To enable system wide have in $GITWEB_CONFIG
290 # $feature{'pathinfo'}{'default'} = [1];
291 # Project specific override is not supported.
293 # Note that you will need to change the default location of CSS,
294 # favicon, logo and possibly other files to an absolute URL. Also,
295 # if gitweb.cgi serves as your indexfile, you will need to force
296 # $my_uri to contain the script name in your $GITWEB_CONFIG.
301 # Make gitweb consider projects in project root subdirectories
302 # to be forks of existing projects. Given project $projname.git,
303 # projects matching $projname/*.git will not be shown in the main
304 # projects list, instead a '+' mark will be added to $projname
305 # there and a 'forks' view will be enabled for the project, listing
306 # all the forks. If project list is taken from a file, forks have
307 # to be listed after the main project.
309 # To enable system wide have in $GITWEB_CONFIG
310 # $feature{'forks'}{'default'} = [1];
311 # Project specific override is not supported.
316 # Insert custom links to the action bar of all project pages.
317 # This enables you mainly to link to third-party scripts integrating
318 # into gitweb; e.g. git-browser for graphical history representation
319 # or custom web-based repository administration interface.
321 # The 'default' value consists of a list of triplets in the form
322 # (label, link, position) where position is the label after which
323 # to insert the link and link is a format string where %n expands
324 # to the project name, %f to the project path within the filesystem,
325 # %h to the current hash (h gitweb parameter) and %b to the current
326 # hash base (hb gitweb parameter); %% expands to %.
328 # To enable system wide have in $GITWEB_CONFIG e.g.
329 # $feature{'actions'}{'default'} = [('graphiclog',
330 # '/git-browser/by-commit.html?r=%n', 'summary')];
331 # Project specific override is not supported.
336 # Allow gitweb scan project content tags described in ctags/
337 # of project repository, and display the popular Web 2.0-ish
338 # "tag cloud" near the project list. Note that this is something
339 # COMPLETELY different from the normal Git tags.
341 # gitweb by itself can show existing tags, but it does not handle
342 # tagging itself; you need an external application for that.
343 # For an example script, check Girocco's cgi/tagproj.cgi.
344 # You may want to install the HTML::TagCloud Perl module to get
345 # a pretty tag cloud instead of just a list of tags.
347 # To enable system wide have in $GITWEB_CONFIG
348 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
349 # Project specific override is not supported.
354 # The maximum number of patches in a patchset generated in patch
355 # view. Set this to 0 or undef to disable patch view, or to a
356 # negative number to remove any limit.
358 # To disable system wide have in $GITWEB_CONFIG
359 # $feature{'patches'}{'default'} = [0];
360 # To have project specific config enable override in $GITWEB_CONFIG
361 # $feature{'patches'}{'override'} = 1;
362 # and in project config gitweb.patches = 0|n;
363 # where n is the maximum number of patches allowed in a patchset.
365 'sub' => \&feature_patches,
370 sub gitweb_get_feature {
372 return unless exists $feature{$name};
373 my ($sub, $override, @defaults) = (
374 $feature{$name}{'sub'},
375 $feature{$name}{'override'},
376 @{$feature{$name}{'default'}});
377 if (!$override) { return @defaults; }
379 warn "feature $name is not overridable";
382 return $sub->(@defaults);
385 # A wrapper to check if a given feature is enabled.
386 # With this, you can say
388 # my $bool_feat = gitweb_check_feature('bool_feat');
389 # gitweb_check_feature('bool_feat') or somecode;
393 # my ($bool_feat) = gitweb_get_feature('bool_feat');
394 # (gitweb_get_feature('bool_feat'))[0] or somecode;
396 sub gitweb_check_feature {
397 return (gitweb_get_feature(@_))[0];
403 my ($val) = git_get_project_config($key, '--bool');
407 } elsif ($val eq 'true') {
409 } elsif ($val eq 'false') {
414 sub feature_snapshot {
417 my ($val) = git_get_project_config('snapshot');
420 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
426 sub feature_patches {
427 my @val = (git_get_project_config('patches', '--int'));
436 # checking HEAD file with -e is fragile if the repository was
437 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
439 sub check_head_link {
441 my $headfile = "$dir/HEAD";
442 return ((-e $headfile) ||
443 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
446 sub check_export_ok {
448 return (check_head_link($dir) &&
449 (!$export_ok || -e "$dir/$export_ok") &&
450 (!$export_auth_hook || $export_auth_hook->($dir)));
453 # process alternate names for backward compatibility
454 # filter out unsupported (unknown) snapshot formats
455 sub filter_snapshot_fmts {
459 exists $known_snapshot_format_aliases{$_} ?
460 $known_snapshot_format_aliases{$_} : $_} @fmts;
461 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
465 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
466 if (-e $GITWEB_CONFIG) {
469 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
470 do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
473 # version of the core git binary
474 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
476 $projects_list ||= $projectroot;
478 # ======================================================================
479 # input validation and dispatch
481 # input parameters can be collected from a variety of sources (presently, CGI
482 # and PATH_INFO), so we define an %input_params hash that collects them all
483 # together during validation: this allows subsequent uses (e.g. href()) to be
484 # agnostic of the parameter origin
486 our %input_params = ();
488 # input parameters are stored with the long parameter name as key. This will
489 # also be used in the href subroutine to convert parameters to their CGI
490 # equivalent, and since the href() usage is the most frequent one, we store
491 # the name -> CGI key mapping here, instead of the reverse.
493 # XXX: Warning: If you touch this, check the search form for updating,
496 our @cgi_param_mapping = (
504 hash_parent_base => "hpb",
509 snapshot_format => "sf",
510 extra_options => "opt",
511 search_use_regexp => "sr",
513 our %cgi_param_mapping = @cgi_param_mapping;
515 # we will also need to know the possible actions, for validation
517 "blame" => \&git_blame,
518 "blobdiff" => \&git_blobdiff,
519 "blobdiff_plain" => \&git_blobdiff_plain,
520 "blob" => \&git_blob,
521 "blob_plain" => \&git_blob_plain,
522 "commitdiff" => \&git_commitdiff,
523 "commitdiff_plain" => \&git_commitdiff_plain,
524 "commit" => \&git_commit,
525 "forks" => \&git_forks,
526 "heads" => \&git_heads,
527 "history" => \&git_history,
529 "patch" => \&git_patch,
530 "patches" => \&git_patches,
532 "atom" => \&git_atom,
533 "search" => \&git_search,
534 "search_help" => \&git_search_help,
535 "shortlog" => \&git_shortlog,
536 "summary" => \&git_summary,
538 "tags" => \&git_tags,
539 "tree" => \&git_tree,
540 "snapshot" => \&git_snapshot,
541 "object" => \&git_object,
542 # those below don't need $project
543 "opml" => \&git_opml,
544 "project_list" => \&git_project_list,
545 "project_index" => \&git_project_index,
548 # finally, we have the hash of allowed extra_options for the commands that
550 our %allowed_options = (
551 "--no-merges" => [ qw(rss atom log shortlog history) ],
554 # fill %input_params with the CGI parameters. All values except for 'opt'
555 # should be single values, but opt can be an array. We should probably
556 # build an array of parameters that can be multi-valued, but since for the time
557 # being it's only this one, we just single it out
558 while (my ($name, $symbol) = each %cgi_param_mapping) {
559 if ($symbol eq 'opt') {
560 $input_params{$name} = [ $cgi->param($symbol) ];
562 $input_params{$name} = $cgi->param($symbol);
566 # now read PATH_INFO and update the parameter list for missing parameters
567 sub evaluate_path_info {
568 return if defined $input_params{'project'};
569 return if !$path_info;
570 $path_info =~ s,^/+,,;
571 return if !$path_info;
573 # find which part of PATH_INFO is project
574 my $project = $path_info;
576 while ($project && !check_head_link("$projectroot/$project")) {
577 $project =~ s,/*[^/]*$,,;
579 return unless $project;
580 $input_params{'project'} = $project;
582 # do not change any parameters if an action is given using the query string
583 return if $input_params{'action'};
584 $path_info =~ s,^\Q$project\E/*,,;
586 # next, check if we have an action
587 my $action = $path_info;
589 if (exists $actions{$action}) {
590 $path_info =~ s,^$action/*,,;
591 $input_params{'action'} = $action;
594 # list of actions that want hash_base instead of hash, but can have no
595 # pathname (f) parameter
602 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
603 my ($parentrefname, $parentpathname, $refname, $pathname) =
604 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
606 # first, analyze the 'current' part
607 if (defined $pathname) {
608 # we got "branch:filename" or "branch:dir/"
609 # we could use git_get_type(branch:pathname), but:
610 # - it needs $git_dir
611 # - it does a git() call
612 # - the convention of terminating directories with a slash
613 # makes it superfluous
614 # - embedding the action in the PATH_INFO would make it even
616 $pathname =~ s,^/+,,;
617 if (!$pathname || substr($pathname, -1) eq "/") {
618 $input_params{'action'} ||= "tree";
621 # the default action depends on whether we had parent info
623 if ($parentrefname) {
624 $input_params{'action'} ||= "blobdiff_plain";
626 $input_params{'action'} ||= "blob_plain";
629 $input_params{'hash_base'} ||= $refname;
630 $input_params{'file_name'} ||= $pathname;
631 } elsif (defined $refname) {
632 # we got "branch". In this case we have to choose if we have to
633 # set hash or hash_base.
635 # Most of the actions without a pathname only want hash to be
636 # set, except for the ones specified in @wants_base that want
637 # hash_base instead. It should also be noted that hand-crafted
638 # links having 'history' as an action and no pathname or hash
639 # set will fail, but that happens regardless of PATH_INFO.
640 $input_params{'action'} ||= "shortlog";
641 if (grep { $_ eq $input_params{'action'} } @wants_base) {
642 $input_params{'hash_base'} ||= $refname;
644 $input_params{'hash'} ||= $refname;
648 # next, handle the 'parent' part, if present
649 if (defined $parentrefname) {
650 # a missing pathspec defaults to the 'current' filename, allowing e.g.
651 # someproject/blobdiff/oldrev..newrev:/filename
652 if ($parentpathname) {
653 $parentpathname =~ s,^/+,,;
654 $parentpathname =~ s,/$,,;
655 $input_params{'file_parent'} ||= $parentpathname;
657 $input_params{'file_parent'} ||= $input_params{'file_name'};
659 # we assume that hash_parent_base is wanted if a path was specified,
660 # or if the action wants hash_base instead of hash
661 if (defined $input_params{'file_parent'} ||
662 grep { $_ eq $input_params{'action'} } @wants_base) {
663 $input_params{'hash_parent_base'} ||= $parentrefname;
665 $input_params{'hash_parent'} ||= $parentrefname;
669 # for the snapshot action, we allow URLs in the form
670 # $project/snapshot/$hash.ext
671 # where .ext determines the snapshot and gets removed from the
672 # passed $refname to provide the $hash.
674 # To be able to tell that $refname includes the format extension, we
675 # require the following two conditions to be satisfied:
676 # - the hash input parameter MUST have been set from the $refname part
677 # of the URL (i.e. they must be equal)
678 # - the snapshot format MUST NOT have been defined already (e.g. from
680 # It's also useless to try any matching unless $refname has a dot,
681 # so we check for that too
682 if (defined $input_params{'action'} &&
683 $input_params{'action'} eq 'snapshot' &&
684 defined $refname && index($refname, '.') != -1 &&
685 $refname eq $input_params{'hash'} &&
686 !defined $input_params{'snapshot_format'}) {
687 # We loop over the known snapshot formats, checking for
688 # extensions. Allowed extensions are both the defined suffix
689 # (which includes the initial dot already) and the snapshot
690 # format key itself, with a prepended dot
691 while (my ($fmt, %opt) = each %known_snapshot_formats) {
694 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
695 next unless $sfx = $1;
696 # a valid suffix was found, so set the snapshot format
697 # and reset the hash parameter
698 $input_params{'snapshot_format'} = $fmt;
699 $input_params{'hash'} = $hash;
700 # we also set the format suffix to the one requested
701 # in the URL: this way a request for e.g. .tgz returns
702 # a .tgz instead of a .tar.gz
703 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
708 evaluate_path_info();
710 our $action = $input_params{'action'};
711 if (defined $action) {
712 if (!validate_action($action)) {
713 die_error(400, "Invalid action parameter");
717 # parameters which are pathnames
718 our $project = $input_params{'project'};
719 if (defined $project) {
720 if (!validate_project($project)) {
722 die_error(404, "No such project");
726 our $file_name = $input_params{'file_name'};
727 if (defined $file_name) {
728 if (!validate_pathname($file_name)) {
729 die_error(400, "Invalid file parameter");
733 our $file_parent = $input_params{'file_parent'};
734 if (defined $file_parent) {
735 if (!validate_pathname($file_parent)) {
736 die_error(400, "Invalid file parent parameter");
740 # parameters which are refnames
741 our $hash = $input_params{'hash'};
743 if (!validate_refname($hash)) {
744 die_error(400, "Invalid hash parameter");
748 our $hash_parent = $input_params{'hash_parent'};
749 if (defined $hash_parent) {
750 if (!validate_refname($hash_parent)) {
751 die_error(400, "Invalid hash parent parameter");
755 our $hash_base = $input_params{'hash_base'};
756 if (defined $hash_base) {
757 if (!validate_refname($hash_base)) {
758 die_error(400, "Invalid hash base parameter");
762 our @extra_options = @{$input_params{'extra_options'}};
763 # @extra_options is always defined, since it can only be (currently) set from
764 # CGI, and $cgi->param() returns the empty array in array context if the param
766 foreach my $opt (@extra_options) {
767 if (not exists $allowed_options{$opt}) {
768 die_error(400, "Invalid option parameter");
770 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
771 die_error(400, "Invalid option parameter for this action");
775 our $hash_parent_base = $input_params{'hash_parent_base'};
776 if (defined $hash_parent_base) {
777 if (!validate_refname($hash_parent_base)) {
778 die_error(400, "Invalid hash parent base parameter");
783 our $page = $input_params{'page'};
785 if ($page =~ m/[^0-9]/) {
786 die_error(400, "Invalid page parameter");
790 our $searchtype = $input_params{'searchtype'};
791 if (defined $searchtype) {
792 if ($searchtype =~ m/[^a-z]/) {
793 die_error(400, "Invalid searchtype parameter");
797 our $search_use_regexp = $input_params{'search_use_regexp'};
799 our $searchtext = $input_params{'searchtext'};
801 if (defined $searchtext) {
802 if (length($searchtext) < 2) {
803 die_error(403, "At least two characters are required for search parameter");
805 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
808 # path to the current git repository
810 $git_dir = "$projectroot/$project" if $project;
812 # list of supported snapshot formats
813 our @snapshot_fmts = gitweb_get_feature('snapshot');
814 @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
817 if (!defined $action) {
819 $action = git_get_type($hash);
820 } elsif (defined $hash_base && defined $file_name) {
821 $action = git_get_type("$hash_base:$file_name");
822 } elsif (defined $project) {
825 $action = 'project_list';
828 if (!defined($actions{$action})) {
829 die_error(400, "Unknown action");
831 if ($action !~ m/^(opml|project_list|project_index)$/ &&
833 die_error(400, "Project needed");
835 $actions{$action}->();
838 ## ======================================================================
843 # default is to use -absolute url() i.e. $my_uri
844 my $href = $params{-full} ? $my_url : $my_uri;
846 $params{'project'} = $project unless exists $params{'project'};
848 if ($params{-replay}) {
849 while (my ($name, $symbol) = each %cgi_param_mapping) {
850 if (!exists $params{$name}) {
851 $params{$name} = $input_params{$name};
856 my $use_pathinfo = gitweb_check_feature('pathinfo');
857 if ($use_pathinfo and defined $params{'project'}) {
858 # try to put as many parameters as possible in PATH_INFO:
861 # - hash_parent or hash_parent_base:/file_parent
862 # - hash or hash_base:/filename
863 # - the snapshot_format as an appropriate suffix
865 # When the script is the root DirectoryIndex for the domain,
866 # $href here would be something like http://gitweb.example.com/
867 # Thus, we strip any trailing / from $href, to spare us double
868 # slashes in the final URL
871 # Then add the project name, if present
872 $href .= "/".esc_url($params{'project'});
873 delete $params{'project'};
875 # since we destructively absorb parameters, we keep this
876 # boolean that remembers if we're handling a snapshot
877 my $is_snapshot = $params{'action'} eq 'snapshot';
879 # Summary just uses the project path URL, any other action is
881 if (defined $params{'action'}) {
882 $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
883 delete $params{'action'};
886 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
887 # stripping nonexistent or useless pieces
888 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
889 || $params{'hash_parent'} || $params{'hash'});
890 if (defined $params{'hash_base'}) {
891 if (defined $params{'hash_parent_base'}) {
892 $href .= esc_url($params{'hash_parent_base'});
893 # skip the file_parent if it's the same as the file_name
894 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
895 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
896 $href .= ":/".esc_url($params{'file_parent'});
897 delete $params{'file_parent'};
900 delete $params{'hash_parent'};
901 delete $params{'hash_parent_base'};
902 } elsif (defined $params{'hash_parent'}) {
903 $href .= esc_url($params{'hash_parent'}). "..";
904 delete $params{'hash_parent'};
907 $href .= esc_url($params{'hash_base'});
908 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
909 $href .= ":/".esc_url($params{'file_name'});
910 delete $params{'file_name'};
912 delete $params{'hash'};
913 delete $params{'hash_base'};
914 } elsif (defined $params{'hash'}) {
915 $href .= esc_url($params{'hash'});
916 delete $params{'hash'};
919 # If the action was a snapshot, we can absorb the
920 # snapshot_format parameter too
922 my $fmt = $params{'snapshot_format'};
923 # snapshot_format should always be defined when href()
924 # is called, but just in case some code forgets, we
925 # fall back to the default
926 $fmt ||= $snapshot_fmts[0];
927 $href .= $known_snapshot_formats{$fmt}{'suffix'};
928 delete $params{'snapshot_format'};
932 # now encode the parameters explicitly
934 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
935 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
936 if (defined $params{$name}) {
937 if (ref($params{$name}) eq "ARRAY") {
938 foreach my $par (@{$params{$name}}) {
939 push @result, $symbol . "=" . esc_param($par);
942 push @result, $symbol . "=" . esc_param($params{$name});
946 $href .= "?" . join(';', @result) if scalar @result;
952 ## ======================================================================
953 ## validation, quoting/unquoting and escaping
955 sub validate_action {
956 my $input = shift || return undef;
957 return undef unless exists $actions{$input};
961 sub validate_project {
962 my $input = shift || return undef;
963 if (!validate_pathname($input) ||
964 !(-d "$projectroot/$input") ||
965 !check_export_ok("$projectroot/$input") ||
966 ($strict_export && !project_in_list($input))) {
973 sub validate_pathname {
974 my $input = shift || return undef;
976 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
977 # at the beginning, at the end, and between slashes.
978 # also this catches doubled slashes
979 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
983 if ($input =~ m!\0!) {
989 sub validate_refname {
990 my $input = shift || return undef;
992 # textual hashes are O.K.
993 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
996 # it must be correct pathname
997 $input = validate_pathname($input)
999 # restrictions on ref name according to git-check-ref-format
1000 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1006 # decode sequences of octets in utf8 into Perl's internal form,
1007 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1008 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1011 if (utf8::valid($str)) {
1015 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
1019 # quote unsafe chars, but keep the slash, even when it's not
1020 # correct, but quoted slashes look too horrible in bookmarks
1023 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
1029 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1032 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
1038 # replace invalid utf8 character with SUBSTITUTION sequence
1039 sub esc_html ($;%) {
1043 $str = to_utf8($str);
1044 $str = $cgi->escapeHTML($str);
1045 if ($opts{'-nbsp'}) {
1046 $str =~ s/ / /g;
1048 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
1052 # quote control characters and escape filename to HTML
1057 $str = to_utf8($str);
1058 $str = $cgi->escapeHTML($str);
1059 if ($opts{'-nbsp'}) {
1060 $str =~ s/ / /g;
1062 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
1066 # Make control characters "printable", using character escape codes (CEC)
1070 my %es = ( # character escape codes, aka escape sequences
1071 "\t" => '\t', # tab (HT)
1072 "\n" => '\n', # line feed (LF)
1073 "\r" => '\r', # carrige return (CR)
1074 "\f" => '\f', # form feed (FF)
1075 "\b" => '\b', # backspace (BS)
1076 "\a" => '\a', # alarm (bell) (BEL)
1077 "\e" => '\e', # escape (ESC)
1078 "\013" => '\v', # vertical tab (VT)
1079 "\000" => '\0', # nul character (NUL)
1081 my $chr = ( (exists $es{$cntrl})
1083 : sprintf('\%2x', ord($cntrl)) );
1084 if ($opts{-nohtml}) {
1087 return "<span class=\"cntrl\">$chr</span>";
1091 # Alternatively use unicode control pictures codepoints,
1092 # Unicode "printable representation" (PR)
1097 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1098 if ($opts{-nohtml}) {
1101 return "<span class=\"cntrl\">$chr</span>";
1105 # git may return quoted and escaped filenames
1111 my %es = ( # character escape codes, aka escape sequences
1112 't' => "\t", # tab (HT, TAB)
1113 'n' => "\n", # newline (NL)
1114 'r' => "\r", # return (CR)
1115 'f' => "\f", # form feed (FF)
1116 'b' => "\b", # backspace (BS)
1117 'a' => "\a", # alarm (bell) (BEL)
1118 'e' => "\e", # escape (ESC)
1119 'v' => "\013", # vertical tab (VT)
1122 if ($seq =~ m/^[0-7]{1,3}$/) {
1123 # octal char sequence
1124 return chr(oct($seq));
1125 } elsif (exists $es{$seq}) {
1126 # C escape sequence, aka character escape code
1129 # quoted ordinary character
1133 if ($str =~ m/^"(.*)"$/) {
1136 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1141 # escape tabs (convert tabs to spaces)
1145 while ((my $pos = index($line, "\t")) != -1) {
1146 if (my $count = (8 - ($pos % 8))) {
1147 my $spaces = ' ' x $count;
1148 $line =~ s/\t/$spaces/;
1155 sub project_in_list {
1156 my $project = shift;
1157 my @list = git_get_projects_list();
1158 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1161 ## ----------------------------------------------------------------------
1162 ## HTML aware string manipulation
1164 # Try to chop given string on a word boundary between position
1165 # $len and $len+$add_len. If there is no word boundary there,
1166 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1167 # (marking chopped part) would be longer than given string.
1171 my $add_len = shift || 10;
1172 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1174 # Make sure perl knows it is utf8 encoded so we don't
1175 # cut in the middle of a utf8 multibyte char.
1176 $str = to_utf8($str);
1178 # allow only $len chars, but don't cut a word if it would fit in $add_len
1179 # if it doesn't fit, cut it if it's still longer than the dots we would add
1180 # remove chopped character entities entirely
1182 # when chopping in the middle, distribute $len into left and right part
1183 # return early if chopping wouldn't make string shorter
1184 if ($where eq 'center') {
1185 return $str if ($len + 5 >= length($str)); # filler is length 5
1188 return $str if ($len + 4 >= length($str)); # filler is length 4
1191 # regexps: ending and beginning with word part up to $add_len
1192 my $endre = qr/.{$len}\w{0,$add_len}/;
1193 my $begre = qr/\w{0,$add_len}.{$len}/;
1195 if ($where eq 'left') {
1196 $str =~ m/^(.*?)($begre)$/;
1197 my ($lead, $body) = ($1, $2);
1198 if (length($lead) > 4) {
1199 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1202 return "$lead$body";
1204 } elsif ($where eq 'center') {
1205 $str =~ m/^($endre)(.*)$/;
1206 my ($left, $str) = ($1, $2);
1207 $str =~ m/^(.*?)($begre)$/;
1208 my ($mid, $right) = ($1, $2);
1209 if (length($mid) > 5) {
1210 $left =~ s/&[^;]*$//;
1211 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1214 return "$left$mid$right";
1217 $str =~ m/^($endre)(.*)$/;
1220 if (length($tail) > 4) {
1221 $body =~ s/&[^;]*$//;
1224 return "$body$tail";
1228 # takes the same arguments as chop_str, but also wraps a <span> around the
1229 # result with a title attribute if it does get chopped. Additionally, the
1230 # string is HTML-escaped.
1231 sub chop_and_escape_str {
1234 my $chopped = chop_str(@_);
1235 if ($chopped eq $str) {
1236 return esc_html($chopped);
1238 $str =~ s/([[:cntrl:]])/?/g;
1239 return $cgi->span({-title=>$str}, esc_html($chopped));
1243 ## ----------------------------------------------------------------------
1244 ## functions returning short strings
1246 # CSS class for given age value (in seconds)
1250 if (!defined $age) {
1252 } elsif ($age < 60*60*2) {
1254 } elsif ($age < 60*60*24*2) {
1261 # convert age in seconds to "nn units ago" string
1266 if ($age > 60*60*24*365*2) {
1267 $age_str = (int $age/60/60/24/365);
1268 $age_str .= " years ago";
1269 } elsif ($age > 60*60*24*(365/12)*2) {
1270 $age_str = int $age/60/60/24/(365/12);
1271 $age_str .= " months ago";
1272 } elsif ($age > 60*60*24*7*2) {
1273 $age_str = int $age/60/60/24/7;
1274 $age_str .= " weeks ago";
1275 } elsif ($age > 60*60*24*2) {
1276 $age_str = int $age/60/60/24;
1277 $age_str .= " days ago";
1278 } elsif ($age > 60*60*2) {
1279 $age_str = int $age/60/60;
1280 $age_str .= " hours ago";
1281 } elsif ($age > 60*2) {
1282 $age_str = int $age/60;
1283 $age_str .= " min ago";
1284 } elsif ($age > 2) {
1285 $age_str = int $age;
1286 $age_str .= " sec ago";
1288 $age_str .= " right now";
1294 S_IFINVALID => 0030000,
1295 S_IFGITLINK => 0160000,
1298 # submodule/subproject, a commit object reference
1299 sub S_ISGITLINK($) {
1302 return (($mode & S_IFMT) == S_IFGITLINK)
1305 # convert file mode in octal to symbolic file mode string
1307 my $mode = oct shift;
1309 if (S_ISGITLINK($mode)) {
1310 return 'm---------';
1311 } elsif (S_ISDIR($mode & S_IFMT)) {
1312 return 'drwxr-xr-x';
1313 } elsif (S_ISLNK($mode)) {
1314 return 'lrwxrwxrwx';
1315 } elsif (S_ISREG($mode)) {
1316 # git cares only about the executable bit
1317 if ($mode & S_IXUSR) {
1318 return '-rwxr-xr-x';
1320 return '-rw-r--r--';
1323 return '----------';
1327 # convert file mode in octal to file type string
1331 if ($mode !~ m/^[0-7]+$/) {
1337 if (S_ISGITLINK($mode)) {
1339 } elsif (S_ISDIR($mode & S_IFMT)) {
1341 } elsif (S_ISLNK($mode)) {
1343 } elsif (S_ISREG($mode)) {
1350 # convert file mode in octal to file type description string
1351 sub file_type_long {
1354 if ($mode !~ m/^[0-7]+$/) {
1360 if (S_ISGITLINK($mode)) {
1362 } elsif (S_ISDIR($mode & S_IFMT)) {
1364 } elsif (S_ISLNK($mode)) {
1366 } elsif (S_ISREG($mode)) {
1367 if ($mode & S_IXUSR) {
1368 return "executable";
1378 ## ----------------------------------------------------------------------
1379 ## functions returning short HTML fragments, or transforming HTML fragments
1380 ## which don't belong to other sections
1382 # format line of commit message.
1383 sub format_log_line_html {
1386 $line = esc_html($line, -nbsp=>1);
1387 $line =~ s{\b([0-9a-fA-F]{8,40})\b}{
1388 $cgi->a({-href => href(action=>"object", hash=>$1),
1389 -class => "text"}, $1);
1395 # format marker of refs pointing to given object
1397 # the destination action is chosen based on object type and current context:
1398 # - for annotated tags, we choose the tag view unless it's the current view
1399 # already, in which case we go to shortlog view
1400 # - for other refs, we keep the current view if we're in history, shortlog or
1401 # log view, and select shortlog otherwise
1402 sub format_ref_marker {
1403 my ($refs, $id) = @_;
1406 if (defined $refs->{$id}) {
1407 foreach my $ref (@{$refs->{$id}}) {
1408 # this code exploits the fact that non-lightweight tags are the
1409 # only indirect objects, and that they are the only objects for which
1410 # we want to use tag instead of shortlog as action
1411 my ($type, $name) = qw();
1412 my $indirect = ($ref =~ s/\^\{\}$//);
1413 # e.g. tags/v2.6.11 or heads/next
1414 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1423 $class .= " indirect" if $indirect;
1425 my $dest_action = "shortlog";
1428 $dest_action = "tag" unless $action eq "tag";
1429 } elsif ($action =~ /^(history|(short)?log)$/) {
1430 $dest_action = $action;
1434 $dest .= "refs/" unless $ref =~ m!^refs/!;
1437 my $link = $cgi->a({
1439 action=>$dest_action,
1443 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1449 return ' <span class="refs">'. $markers . '</span>';
1455 # format, perhaps shortened and with markers, title line
1456 sub format_subject_html {
1457 my ($long, $short, $href, $extra) = @_;
1458 $extra = '' unless defined($extra);
1460 if (length($short) < length($long)) {
1461 return $cgi->a({-href => $href, -class => "list subject",
1462 -title => to_utf8($long)},
1463 esc_html($short) . $extra);
1465 return $cgi->a({-href => $href, -class => "list subject"},
1466 esc_html($long) . $extra);
1470 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1471 sub format_git_diff_header_line {
1473 my $diffinfo = shift;
1474 my ($from, $to) = @_;
1476 if ($diffinfo->{'nparents'}) {
1478 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1479 if ($to->{'href'}) {
1480 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1481 esc_path($to->{'file'}));
1482 } else { # file was deleted (no href)
1483 $line .= esc_path($to->{'file'});
1487 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1488 if ($from->{'href'}) {
1489 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1490 'a/' . esc_path($from->{'file'}));
1491 } else { # file was added (no href)
1492 $line .= 'a/' . esc_path($from->{'file'});
1495 if ($to->{'href'}) {
1496 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1497 'b/' . esc_path($to->{'file'}));
1498 } else { # file was deleted
1499 $line .= 'b/' . esc_path($to->{'file'});
1503 return "<div class=\"diff header\">$line</div>\n";
1506 # format extended diff header line, before patch itself
1507 sub format_extended_diff_header_line {
1509 my $diffinfo = shift;
1510 my ($from, $to) = @_;
1513 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1514 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1515 esc_path($from->{'file'}));
1517 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1518 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1519 esc_path($to->{'file'}));
1521 # match single <mode>
1522 if ($line =~ m/\s(\d{6})$/) {
1523 $line .= '<span class="info"> (' .
1524 file_type_long($1) .
1528 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1529 # can match only for combined diff
1531 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1532 if ($from->{'href'}[$i]) {
1533 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1535 substr($diffinfo->{'from_id'}[$i],0,7));
1540 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1543 if ($to->{'href'}) {
1544 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1545 substr($diffinfo->{'to_id'},0,7));
1550 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1551 # can match only for ordinary diff
1552 my ($from_link, $to_link);
1553 if ($from->{'href'}) {
1554 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1555 substr($diffinfo->{'from_id'},0,7));
1557 $from_link = '0' x 7;
1559 if ($to->{'href'}) {
1560 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1561 substr($diffinfo->{'to_id'},0,7));
1565 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1566 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1569 return $line . "<br/>\n";
1572 # format from-file/to-file diff header
1573 sub format_diff_from_to_header {
1574 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1579 #assert($line =~ m/^---/) if DEBUG;
1580 # no extra formatting for "^--- /dev/null"
1581 if (! $diffinfo->{'nparents'}) {
1582 # ordinary (single parent) diff
1583 if ($line =~ m!^--- "?a/!) {
1584 if ($from->{'href'}) {
1586 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1587 esc_path($from->{'file'}));
1590 esc_path($from->{'file'});
1593 $result .= qq!<div class="diff from_file">$line</div>\n!;
1596 # combined diff (merge commit)
1597 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1598 if ($from->{'href'}[$i]) {
1600 $cgi->a({-href=>href(action=>"blobdiff",
1601 hash_parent=>$diffinfo->{'from_id'}[$i],
1602 hash_parent_base=>$parents[$i],
1603 file_parent=>$from->{'file'}[$i],
1604 hash=>$diffinfo->{'to_id'},
1606 file_name=>$to->{'file'}),
1608 -title=>"diff" . ($i+1)},
1611 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1612 esc_path($from->{'file'}[$i]));
1614 $line = '--- /dev/null';
1616 $result .= qq!<div class="diff from_file">$line</div>\n!;
1621 #assert($line =~ m/^\+\+\+/) if DEBUG;
1622 # no extra formatting for "^+++ /dev/null"
1623 if ($line =~ m!^\+\+\+ "?b/!) {
1624 if ($to->{'href'}) {
1626 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1627 esc_path($to->{'file'}));
1630 esc_path($to->{'file'});
1633 $result .= qq!<div class="diff to_file">$line</div>\n!;
1638 # create note for patch simplified by combined diff
1639 sub format_diff_cc_simplified {
1640 my ($diffinfo, @parents) = @_;
1643 $result .= "<div class=\"diff header\">" .
1645 if (!is_deleted($diffinfo)) {
1646 $result .= $cgi->a({-href => href(action=>"blob",
1648 hash=>$diffinfo->{'to_id'},
1649 file_name=>$diffinfo->{'to_file'}),
1651 esc_path($diffinfo->{'to_file'}));
1653 $result .= esc_path($diffinfo->{'to_file'});
1655 $result .= "</div>\n" . # class="diff header"
1656 "<div class=\"diff nodifferences\">" .
1658 "</div>\n"; # class="diff nodifferences"
1663 # format patch (diff) line (not to be used for diff headers)
1664 sub format_diff_line {
1666 my ($from, $to) = @_;
1667 my $diff_class = "";
1671 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1673 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1674 if ($line =~ m/^\@{3}/) {
1675 $diff_class = " chunk_header";
1676 } elsif ($line =~ m/^\\/) {
1677 $diff_class = " incomplete";
1678 } elsif ($prefix =~ tr/+/+/) {
1679 $diff_class = " add";
1680 } elsif ($prefix =~ tr/-/-/) {
1681 $diff_class = " rem";
1684 # assume ordinary diff
1685 my $char = substr($line, 0, 1);
1687 $diff_class = " add";
1688 } elsif ($char eq '-') {
1689 $diff_class = " rem";
1690 } elsif ($char eq '@') {
1691 $diff_class = " chunk_header";
1692 } elsif ($char eq "\\") {
1693 $diff_class = " incomplete";
1696 $line = untabify($line);
1697 if ($from && $to && $line =~ m/^\@{2} /) {
1698 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1699 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1701 $from_lines = 0 unless defined $from_lines;
1702 $to_lines = 0 unless defined $to_lines;
1704 if ($from->{'href'}) {
1705 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1706 -class=>"list"}, $from_text);
1708 if ($to->{'href'}) {
1709 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1710 -class=>"list"}, $to_text);
1712 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1713 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1714 return "<div class=\"diff$diff_class\">$line</div>\n";
1715 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1716 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1717 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1719 @from_text = split(' ', $ranges);
1720 for (my $i = 0; $i < @from_text; ++$i) {
1721 ($from_start[$i], $from_nlines[$i]) =
1722 (split(',', substr($from_text[$i], 1)), 0);
1725 $to_text = pop @from_text;
1726 $to_start = pop @from_start;
1727 $to_nlines = pop @from_nlines;
1729 $line = "<span class=\"chunk_info\">$prefix ";
1730 for (my $i = 0; $i < @from_text; ++$i) {
1731 if ($from->{'href'}[$i]) {
1732 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1733 -class=>"list"}, $from_text[$i]);
1735 $line .= $from_text[$i];
1739 if ($to->{'href'}) {
1740 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1741 -class=>"list"}, $to_text);
1745 $line .= " $prefix</span>" .
1746 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1747 return "<div class=\"diff$diff_class\">$line</div>\n";
1749 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1752 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1753 # linked. Pass the hash of the tree/commit to snapshot.
1754 sub format_snapshot_links {
1756 my $num_fmts = @snapshot_fmts;
1757 if ($num_fmts > 1) {
1758 # A parenthesized list of links bearing format names.
1759 # e.g. "snapshot (_tar.gz_ _zip_)"
1760 return "snapshot (" . join(' ', map
1767 }, $known_snapshot_formats{$_}{'display'})
1768 , @snapshot_fmts) . ")";
1769 } elsif ($num_fmts == 1) {
1770 # A single "snapshot" link whose tooltip bears the format name.
1772 my ($fmt) = @snapshot_fmts;
1778 snapshot_format=>$fmt
1780 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1782 } else { # $num_fmts == 0
1787 ## ......................................................................
1788 ## functions returning values to be passed, perhaps after some
1789 ## transformation, to other functions; e.g. returning arguments to href()
1791 # returns hash to be passed to href to generate gitweb URL
1792 # in -title key it returns description of link
1794 my $format = shift || 'Atom';
1795 my %res = (action => lc($format));
1797 # feed links are possible only for project views
1798 return unless (defined $project);
1799 # some views should link to OPML, or to generic project feed,
1800 # or don't have specific feed yet (so they should use generic)
1801 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1804 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1805 # from tag links; this also makes possible to detect branch links
1806 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1807 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1810 # find log type for feed description (title)
1812 if (defined $file_name) {
1813 $type = "history of $file_name";
1814 $type .= "/" if ($action eq 'tree');
1815 $type .= " on '$branch'" if (defined $branch);
1817 $type = "log of $branch" if (defined $branch);
1820 $res{-title} = $type;
1821 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1822 $res{'file_name'} = $file_name;
1827 ## ----------------------------------------------------------------------
1828 ## git utility subroutines, invoking git commands
1830 # returns path to the core git executable and the --git-dir parameter as list
1832 return $GIT, '--git-dir='.$git_dir;
1835 # quote the given arguments for passing them to the shell
1836 # quote_command("command", "arg 1", "arg with ' and ! characters")
1837 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1838 # Try to avoid using this function wherever possible.
1841 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1844 # get HEAD ref of given project as hash
1845 sub git_get_head_hash {
1846 my $project = shift;
1847 my $o_git_dir = $git_dir;
1849 $git_dir = "$projectroot/$project";
1850 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1853 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1857 if (defined $o_git_dir) {
1858 $git_dir = $o_git_dir;
1863 # get type of given object
1867 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
1869 close $fd or return;
1874 # repository configuration
1875 our $config_file = '';
1878 # store multiple values for single key as anonymous array reference
1879 # single values stored directly in the hash, not as [ <value> ]
1880 sub hash_set_multi {
1881 my ($hash, $key, $value) = @_;
1883 if (!exists $hash->{$key}) {
1884 $hash->{$key} = $value;
1885 } elsif (!ref $hash->{$key}) {
1886 $hash->{$key} = [ $hash->{$key}, $value ];
1888 push @{$hash->{$key}}, $value;
1892 # return hash of git project configuration
1893 # optionally limited to some section, e.g. 'gitweb'
1894 sub git_parse_project_config {
1895 my $section_regexp = shift;
1900 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
1903 while (my $keyval = <$fh>) {
1905 my ($key, $value) = split(/\n/, $keyval, 2);
1907 hash_set_multi(\%config, $key, $value)
1908 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1915 # convert config value to boolean: 'true' or 'false'
1916 # no value, number > 0, 'true' and 'yes' values are true
1917 # rest of values are treated as false (never as error)
1918 sub config_to_bool {
1921 return 1 if !defined $val; # section.key
1923 # strip leading and trailing whitespace
1927 return (($val =~ /^\d+$/ && $val) || # section.key = 1
1928 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1931 # convert config value to simple decimal number
1932 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1933 # to be multiplied by 1024, 1048576, or 1073741824
1937 # strip leading and trailing whitespace
1941 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1943 # unknown unit is treated as 1
1944 return $num * ($unit eq 'g' ? 1073741824 :
1945 $unit eq 'm' ? 1048576 :
1946 $unit eq 'k' ? 1024 : 1);
1951 # convert config value to array reference, if needed
1952 sub config_to_multi {
1955 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
1958 sub git_get_project_config {
1959 my ($key, $type) = @_;
1962 return unless ($key);
1963 $key =~ s/^gitweb\.//;
1964 return if ($key =~ m/\W/);
1967 if (defined $type) {
1970 unless ($type eq 'bool' || $type eq 'int');
1974 if (!defined $config_file ||
1975 $config_file ne "$git_dir/config") {
1976 %config = git_parse_project_config('gitweb');
1977 $config_file = "$git_dir/config";
1980 # check if config variable (key) exists
1981 return unless exists $config{"gitweb.$key"};
1984 if (!defined $type) {
1985 return $config{"gitweb.$key"};
1986 } elsif ($type eq 'bool') {
1987 # backward compatibility: 'git config --bool' returns true/false
1988 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
1989 } elsif ($type eq 'int') {
1990 return config_to_int($config{"gitweb.$key"});
1992 return $config{"gitweb.$key"};
1995 # get hash of given path at given ref
1996 sub git_get_hash_by_path {
1998 my $path = shift || return undef;
2003 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
2004 or die_error(500, "Open git-ls-tree failed");
2006 close $fd or return undef;
2008 if (!defined $line) {
2009 # there is no tree or hash given by $path at $base
2013 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2014 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2015 if (defined $type && $type ne $2) {
2016 # type doesn't match
2022 # get path of entry with given hash at given tree-ish (ref)
2023 # used to get 'from' filename for combined diff (merge commit) for renames
2024 sub git_get_path_by_hash {
2025 my $base = shift || return;
2026 my $hash = shift || return;
2030 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
2032 while (my $line = <$fd>) {
2035 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2036 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2037 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2046 ## ......................................................................
2047 ## git utility functions, directly accessing git repository
2049 sub git_get_project_description {
2052 $git_dir = "$projectroot/$path";
2053 open my $fd, "$git_dir/description"
2054 or return git_get_project_config('description');
2057 if (defined $descr) {
2063 sub git_get_project_ctags {
2067 $git_dir = "$projectroot/$path";
2068 unless (opendir D, "$git_dir/ctags") {
2071 foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) {
2072 open CT, $_ or next;
2076 my $ctag = $_; $ctag =~ s#.*/##;
2077 $ctags->{$ctag} = $val;
2083 sub git_populate_project_tagcloud {
2086 # First, merge different-cased tags; tags vote on casing
2088 foreach (keys %$ctags) {
2089 $ctags_lc{lc $_}->{count} += $ctags->{$_};
2090 if (not $ctags_lc{lc $_}->{topcount}
2091 or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) {
2092 $ctags_lc{lc $_}->{topcount} = $ctags->{$_};
2093 $ctags_lc{lc $_}->{topname} = $_;
2098 if (eval { require HTML::TagCloud; 1; }) {
2099 $cloud = HTML::TagCloud->new;
2100 foreach (sort keys %ctags_lc) {
2101 # Pad the title with spaces so that the cloud looks
2103 my $title = $ctags_lc{$_}->{topname};
2104 $title =~ s/ / /g;
2105 $title =~ s/^/ /g;
2106 $title =~ s/$/ /g;
2107 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
2110 $cloud = \%ctags_lc;
2115 sub git_show_project_tagcloud {
2116 my ($cloud, $count) = @_;
2117 print STDERR ref($cloud)."..\n";
2118 if (ref $cloud eq 'HTML::TagCloud') {
2119 return $cloud->html_and_css($count);
2121 my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud;
2122 return '<p align="center">' . join (', ', map {
2123 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2124 } splice(@tags, 0, $count)) . '</p>';
2128 sub git_get_project_url_list {
2131 $git_dir = "$projectroot/$path";
2132 open my $fd, "$git_dir/cloneurl"
2133 or return wantarray ?
2134 @{ config_to_multi(git_get_project_config('url')) } :
2135 config_to_multi(git_get_project_config('url'));
2136 my @git_project_url_list = map { chomp; $_ } <$fd>;
2139 return wantarray ? @git_project_url_list : \@git_project_url_list;
2142 sub git_get_projects_list {
2147 $filter =~ s/\.git$//;
2149 my $check_forks = gitweb_check_feature('forks');
2151 if (-d $projects_list) {
2152 # search in directory
2153 my $dir = $projects_list . ($filter ? "/$filter" : '');
2154 # remove the trailing "/"
2156 my $pfxlen = length("$dir");
2157 my $pfxdepth = ($dir =~ tr!/!!);
2160 follow_fast => 1, # follow symbolic links
2161 follow_skip => 2, # ignore duplicates
2162 dangling_symlinks => 0, # ignore dangling symlinks, silently
2164 # skip project-list toplevel, if we get it.
2165 return if (m!^[/.]$!);
2166 # only directories can be git repositories
2167 return unless (-d $_);
2168 # don't traverse too deep (Find is super slow on os x)
2169 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2170 $File::Find::prune = 1;
2174 my $subdir = substr($File::Find::name, $pfxlen + 1);
2175 # we check related file in $projectroot
2176 my $path = ($filter ? "$filter/" : '') . $subdir;
2177 if (check_export_ok("$projectroot/$path")) {
2178 push @list, { path => $path };
2179 $File::Find::prune = 1;
2184 } elsif (-f $projects_list) {
2185 # read from file(url-encoded):
2186 # 'git%2Fgit.git Linus+Torvalds'
2187 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2188 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2190 open my ($fd), $projects_list or return;
2192 while (my $line = <$fd>) {
2194 my ($path, $owner) = split ' ', $line;
2195 $path = unescape($path);
2196 $owner = unescape($owner);
2197 if (!defined $path) {
2200 if ($filter ne '') {
2201 # looking for forks;
2202 my $pfx = substr($path, 0, length($filter));
2203 if ($pfx ne $filter) {
2206 my $sfx = substr($path, length($filter));
2207 if ($sfx !~ /^\/.*\.git$/) {
2210 } elsif ($check_forks) {
2212 foreach my $filter (keys %paths) {
2213 # looking for forks;
2214 my $pfx = substr($path, 0, length($filter));
2215 if ($pfx ne $filter) {
2218 my $sfx = substr($path, length($filter));
2219 if ($sfx !~ /^\/.*\.git$/) {
2222 # is a fork, don't include it in
2227 if (check_export_ok("$projectroot/$path")) {
2230 owner => to_utf8($owner),
2233 (my $forks_path = $path) =~ s/\.git$//;
2234 $paths{$forks_path}++;
2242 our $gitweb_project_owner = undef;
2243 sub git_get_project_list_from_file {
2245 return if (defined $gitweb_project_owner);
2247 $gitweb_project_owner = {};
2248 # read from file (url-encoded):
2249 # 'git%2Fgit.git Linus+Torvalds'
2250 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2251 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2252 if (-f $projects_list) {
2253 open (my $fd , $projects_list);
2254 while (my $line = <$fd>) {
2256 my ($pr, $ow) = split ' ', $line;
2257 $pr = unescape($pr);
2258 $ow = unescape($ow);
2259 $gitweb_project_owner->{$pr} = to_utf8($ow);
2265 sub git_get_project_owner {
2266 my $project = shift;
2269 return undef unless $project;
2270 $git_dir = "$projectroot/$project";
2272 if (!defined $gitweb_project_owner) {
2273 git_get_project_list_from_file();
2276 if (exists $gitweb_project_owner->{$project}) {
2277 $owner = $gitweb_project_owner->{$project};
2279 if (!defined $owner){
2280 $owner = git_get_project_config('owner');
2282 if (!defined $owner) {
2283 $owner = get_file_owner("$git_dir");
2289 sub git_get_last_activity {
2293 $git_dir = "$projectroot/$path";
2294 open($fd, "-|", git_cmd(), 'for-each-ref',
2295 '--format=%(committer)',
2296 '--sort=-committerdate',
2298 'refs/heads') or return;
2299 my $most_recent = <$fd>;
2300 close $fd or return;
2301 if (defined $most_recent &&
2302 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2304 my $age = time - $timestamp;
2305 return ($age, age_string($age));
2307 return (undef, undef);
2310 sub git_get_references {
2311 my $type = shift || "";
2313 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2314 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2315 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
2316 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2319 while (my $line = <$fd>) {
2321 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2322 if (defined $refs{$1}) {
2323 push @{$refs{$1}}, $2;
2329 close $fd or return;
2333 sub git_get_rev_name_tags {
2334 my $hash = shift || return undef;
2336 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
2338 my $name_rev = <$fd>;
2341 if ($name_rev =~ m|^$hash tags/(.*)$|) {
2344 # catches also '$hash undefined' output
2349 ## ----------------------------------------------------------------------
2350 ## parse to hash functions
2354 my $tz = shift || "-0000";
2357 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2358 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2359 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2360 $date{'hour'} = $hour;
2361 $date{'minute'} = $min;
2362 $date{'mday'} = $mday;
2363 $date{'day'} = $days[$wday];
2364 $date{'month'} = $months[$mon];
2365 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2366 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2367 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2368 $mday, $months[$mon], $hour ,$min;
2369 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2370 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2372 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2373 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2374 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2375 $date{'hour_local'} = $hour;
2376 $date{'minute_local'} = $min;
2377 $date{'tz_local'} = $tz;
2378 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2379 1900+$year, $mon+1, $mday,
2380 $hour, $min, $sec, $tz);
2389 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
2390 $tag{'id'} = $tag_id;
2391 while (my $line = <$fd>) {
2393 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2394 $tag{'object'} = $1;
2395 } elsif ($line =~ m/^type (.+)$/) {
2397 } elsif ($line =~ m/^tag (.+)$/) {
2399 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2400 $tag{'author'} = $1;
2403 } elsif ($line =~ m/--BEGIN/) {
2404 push @comment, $line;
2406 } elsif ($line eq "") {
2410 push @comment, <$fd>;
2411 $tag{'comment'} = \@comment;
2412 close $fd or return;
2413 if (!defined $tag{'name'}) {
2419 sub parse_commit_text {
2420 my ($commit_text, $withparents) = @_;
2421 my @commit_lines = split '\n', $commit_text;
2424 pop @commit_lines; # Remove '\0'
2426 if (! @commit_lines) {
2430 my $header = shift @commit_lines;
2431 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2434 ($co{'id'}, my @parents) = split ' ', $header;
2435 while (my $line = shift @commit_lines) {
2436 last if $line eq "\n";
2437 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2439 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2441 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2443 $co{'author_epoch'} = $2;
2444 $co{'author_tz'} = $3;
2445 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2446 $co{'author_name'} = $1;
2447 $co{'author_email'} = $2;
2449 $co{'author_name'} = $co{'author'};
2451 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2452 $co{'committer'} = $1;
2453 $co{'committer_epoch'} = $2;
2454 $co{'committer_tz'} = $3;
2455 $co{'committer_name'} = $co{'committer'};
2456 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2457 $co{'committer_name'} = $1;
2458 $co{'committer_email'} = $2;
2460 $co{'committer_name'} = $co{'committer'};
2464 if (!defined $co{'tree'}) {
2467 $co{'parents'} = \@parents;
2468 $co{'parent'} = $parents[0];
2470 foreach my $title (@commit_lines) {
2473 $co{'title'} = chop_str($title, 80, 5);
2474 # remove leading stuff of merges to make the interesting part visible
2475 if (length($title) > 50) {
2476 $title =~ s/^Automatic //;
2477 $title =~ s/^merge (of|with) /Merge ... /i;
2478 if (length($title) > 50) {
2479 $title =~ s/(http|rsync):\/\///;
2481 if (length($title) > 50) {
2482 $title =~ s/(master|www|rsync)\.//;
2484 if (length($title) > 50) {
2485 $title =~ s/kernel.org:?//;
2487 if (length($title) > 50) {
2488 $title =~ s/\/pub\/scm//;
2491 $co{'title_short'} = chop_str($title, 50, 5);
2495 if (! defined $co{'title'} || $co{'title'} eq "") {
2496 $co{'title'} = $co{'title_short'} = '(no commit message)';
2498 # remove added spaces
2499 foreach my $line (@commit_lines) {
2502 $co{'comment'} = \@commit_lines;
2504 my $age = time - $co{'committer_epoch'};
2506 $co{'age_string'} = age_string($age);
2507 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2508 if ($age > 60*60*24*7*2) {
2509 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2510 $co{'age_string_age'} = $co{'age_string'};
2512 $co{'age_string_date'} = $co{'age_string'};
2513 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2519 my ($commit_id) = @_;
2524 open my $fd, "-|", git_cmd(), "rev-list",
2530 or die_error(500, "Open git-rev-list failed");
2531 %co = parse_commit_text(<$fd>, 1);
2538 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2546 open my $fd, "-|", git_cmd(), "rev-list",
2549 ("--max-count=" . $maxcount),
2550 ("--skip=" . $skip),
2554 ($filename ? ($filename) : ())
2555 or die_error(500, "Open git-rev-list failed");
2556 while (my $line = <$fd>) {
2557 my %co = parse_commit_text($line);
2562 return wantarray ? @cos : \@cos;
2565 # parse line of git-diff-tree "raw" output
2566 sub parse_difftree_raw_line {
2570 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2571 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2572 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2573 $res{'from_mode'} = $1;
2574 $res{'to_mode'} = $2;
2575 $res{'from_id'} = $3;
2577 $res{'status'} = $5;
2578 $res{'similarity'} = $6;
2579 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2580 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2582 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2585 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2586 # combined diff (for merge commit)
2587 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2588 $res{'nparents'} = length($1);
2589 $res{'from_mode'} = [ split(' ', $2) ];
2590 $res{'to_mode'} = pop @{$res{'from_mode'}};
2591 $res{'from_id'} = [ split(' ', $3) ];
2592 $res{'to_id'} = pop @{$res{'from_id'}};
2593 $res{'status'} = [ split('', $4) ];
2594 $res{'to_file'} = unquote($5);
2596 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2597 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2598 $res{'commit'} = $1;
2601 return wantarray ? %res : \%res;
2604 # wrapper: return parsed line of git-diff-tree "raw" output
2605 # (the argument might be raw line, or parsed info)
2606 sub parsed_difftree_line {
2607 my $line_or_ref = shift;
2609 if (ref($line_or_ref) eq "HASH") {
2610 # pre-parsed (or generated by hand)
2611 return $line_or_ref;
2613 return parse_difftree_raw_line($line_or_ref);
2617 # parse line of git-ls-tree output
2618 sub parse_ls_tree_line ($;%) {
2623 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2624 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2632 $res{'name'} = unquote($4);
2635 return wantarray ? %res : \%res;
2638 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2639 sub parse_from_to_diffinfo {
2640 my ($diffinfo, $from, $to, @parents) = @_;
2642 if ($diffinfo->{'nparents'}) {
2644 $from->{'file'} = [];
2645 $from->{'href'} = [];
2646 fill_from_file_info($diffinfo, @parents)
2647 unless exists $diffinfo->{'from_file'};
2648 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2649 $from->{'file'}[$i] =
2650 defined $diffinfo->{'from_file'}[$i] ?
2651 $diffinfo->{'from_file'}[$i] :
2652 $diffinfo->{'to_file'};
2653 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2654 $from->{'href'}[$i] = href(action=>"blob",
2655 hash_base=>$parents[$i],
2656 hash=>$diffinfo->{'from_id'}[$i],
2657 file_name=>$from->{'file'}[$i]);
2659 $from->{'href'}[$i] = undef;
2663 # ordinary (not combined) diff
2664 $from->{'file'} = $diffinfo->{'from_file'};
2665 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2666 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2667 hash=>$diffinfo->{'from_id'},
2668 file_name=>$from->{'file'});
2670 delete $from->{'href'};
2674 $to->{'file'} = $diffinfo->{'to_file'};
2675 if (!is_deleted($diffinfo)) { # file exists in result
2676 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2677 hash=>$diffinfo->{'to_id'},
2678 file_name=>$to->{'file'});
2680 delete $to->{'href'};
2684 ## ......................................................................
2685 ## parse to array of hashes functions
2687 sub git_get_heads_list {
2691 open my $fd, '-|', git_cmd(), 'for-each-ref',
2692 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2693 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2696 while (my $line = <$fd>) {
2700 my ($refinfo, $committerinfo) = split(/\0/, $line);
2701 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2702 my ($committer, $epoch, $tz) =
2703 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2704 $ref_item{'fullname'} = $name;
2705 $name =~ s!^refs/heads/!!;
2707 $ref_item{'name'} = $name;
2708 $ref_item{'id'} = $hash;
2709 $ref_item{'title'} = $title || '(no commit message)';
2710 $ref_item{'epoch'} = $epoch;
2712 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2714 $ref_item{'age'} = "unknown";
2717 push @headslist, \%ref_item;
2721 return wantarray ? @headslist : \@headslist;
2724 sub git_get_tags_list {
2728 open my $fd, '-|', git_cmd(), 'for-each-ref',
2729 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2730 '--format=%(objectname) %(objecttype) %(refname) '.
2731 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2734 while (my $line = <$fd>) {
2738 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2739 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2740 my ($creator, $epoch, $tz) =
2741 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2742 $ref_item{'fullname'} = $name;
2743 $name =~ s!^refs/tags/!!;
2745 $ref_item{'type'} = $type;
2746 $ref_item{'id'} = $id;
2747 $ref_item{'name'} = $name;
2748 if ($type eq "tag") {
2749 $ref_item{'subject'} = $title;
2750 $ref_item{'reftype'} = $reftype;
2751 $ref_item{'refid'} = $refid;
2753 $ref_item{'reftype'} = $type;
2754 $ref_item{'refid'} = $id;
2757 if ($type eq "tag" || $type eq "commit") {
2758 $ref_item{'epoch'} = $epoch;
2760 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2762 $ref_item{'age'} = "unknown";
2766 push @tagslist, \%ref_item;
2770 return wantarray ? @tagslist : \@tagslist;
2773 ## ----------------------------------------------------------------------
2774 ## filesystem-related functions
2776 sub get_file_owner {
2779 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2780 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2781 if (!defined $gcos) {
2785 $owner =~ s/[,;].*$//;
2786 return to_utf8($owner);
2789 # assume that file exists
2791 my $filename = shift;
2793 open my $fd, '<', $filename;
2794 print map { to_utf8($_) } <$fd>;
2798 ## ......................................................................
2799 ## mimetype related functions
2801 sub mimetype_guess_file {
2802 my $filename = shift;
2803 my $mimemap = shift;
2804 -r $mimemap or return undef;
2807 open(MIME, $mimemap) or return undef;
2809 next if m/^#/; # skip comments
2810 my ($mime, $exts) = split(/\t+/);
2811 if (defined $exts) {
2812 my @exts = split(/\s+/, $exts);
2813 foreach my $ext (@exts) {
2814 $mimemap{$ext} = $mime;
2820 $filename =~ /\.([^.]*)$/;
2821 return $mimemap{$1};
2824 sub mimetype_guess {
2825 my $filename = shift;
2827 $filename =~ /\./ or return undef;
2829 if ($mimetypes_file) {
2830 my $file = $mimetypes_file;
2831 if ($file !~ m!^/!) { # if it is relative path
2832 # it is relative to project
2833 $file = "$projectroot/$project/$file";
2835 $mime = mimetype_guess_file($filename, $file);
2837 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2843 my $filename = shift;
2846 my $mime = mimetype_guess($filename);
2847 $mime and return $mime;
2851 return $default_blob_plain_mimetype unless $fd;
2854 return 'text/plain';
2855 } elsif (! $filename) {
2856 return 'application/octet-stream';
2857 } elsif ($filename =~ m/\.png$/i) {
2859 } elsif ($filename =~ m/\.gif$/i) {
2861 } elsif ($filename =~ m/\.jpe?g$/i) {
2862 return 'image/jpeg';
2864 return 'application/octet-stream';
2868 sub blob_contenttype {
2869 my ($fd, $file_name, $type) = @_;
2871 $type ||= blob_mimetype($fd, $file_name);
2872 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2873 $type .= "; charset=$default_text_plain_charset";
2879 ## ======================================================================
2880 ## functions printing HTML: header, footer, error page
2882 sub git_header_html {
2883 my $status = shift || "200 OK";
2884 my $expires = shift;
2886 my $title = "$site_name";
2887 if (defined $project) {
2888 $title .= " - " . to_utf8($project);
2889 if (defined $action) {
2890 $title .= "/$action";
2891 if (defined $file_name) {
2892 $title .= " - " . esc_path($file_name);
2893 if ($action eq "tree" && $file_name !~ m|/$|) {
2900 # require explicit support from the UA if we are to send the page as
2901 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2902 # we have to do this because MSIE sometimes globs '*/*', pretending to
2903 # support xhtml+xml but choking when it gets what it asked for.
2904 if (defined $cgi->http('HTTP_ACCEPT') &&
2905 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
2906 $cgi->Accept('application/xhtml+xml') != 0) {
2907 $content_type = 'application/xhtml+xml';
2909 $content_type = 'text/html';
2911 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
2912 -status=> $status, -expires => $expires);
2913 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2915 <?xml version="1.0" encoding="utf-8"?>
2916 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2917 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2918 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2919 <!-- git core binaries version $git_version -->
2921 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2922 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2923 <meta name="robots" content="index, nofollow"/>
2924 <title>$title</title>
2926 # the stylesheet, favicon etc urls won't work correctly with path_info
2927 # unless we set the appropriate base URL
2928 if ($ENV{'PATH_INFO'}) {
2929 print "<base href=\"".esc_url($base_url)."\" />\n";
2931 # print out each stylesheet that exist, providing backwards capability
2932 # for those people who defined $stylesheet in a config file
2933 if (defined $stylesheet) {
2934 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2936 foreach my $stylesheet (@stylesheets) {
2937 next unless $stylesheet;
2938 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2941 if (defined $project) {
2942 my %href_params = get_feed_info();
2943 if (!exists $href_params{'-title'}) {
2944 $href_params{'-title'} = 'log';
2947 foreach my $format qw(RSS Atom) {
2948 my $type = lc($format);
2950 '-rel' => 'alternate',
2951 '-title' => "$project - $href_params{'-title'} - $format feed",
2952 '-type' => "application/$type+xml"
2955 $href_params{'action'} = $type;
2956 $link_attr{'-href'} = href(%href_params);
2958 "rel=\"$link_attr{'-rel'}\" ".
2959 "title=\"$link_attr{'-title'}\" ".
2960 "href=\"$link_attr{'-href'}\" ".
2961 "type=\"$link_attr{'-type'}\" ".
2964 $href_params{'extra_options'} = '--no-merges';
2965 $link_attr{'-href'} = href(%href_params);
2966 $link_attr{'-title'} .= ' (no merges)';
2968 "rel=\"$link_attr{'-rel'}\" ".
2969 "title=\"$link_attr{'-title'}\" ".
2970 "href=\"$link_attr{'-href'}\" ".
2971 "type=\"$link_attr{'-type'}\" ".
2976 printf('<link rel="alternate" title="%s projects list" '.
2977 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2978 $site_name, href(project=>undef, action=>"project_index"));
2979 printf('<link rel="alternate" title="%s projects feeds" '.
2980 'href="%s" type="text/x-opml" />'."\n",
2981 $site_name, href(project=>undef, action=>"opml"));
2983 if (defined $favicon) {
2984 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
2990 if (-f $site_header) {
2991 insert_file($site_header);
2994 print "<div class=\"page_header\">\n" .
2995 $cgi->a({-href => esc_url($logo_url),
2996 -title => $logo_label},
2997 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2998 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
2999 if (defined $project) {
3000 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3001 if (defined $action) {
3008 my $have_search = gitweb_check_feature('search');
3009 if (defined $project && $have_search) {
3010 if (!defined $searchtext) {
3014 if (defined $hash_base) {
3015 $search_hash = $hash_base;
3016 } elsif (defined $hash) {
3017 $search_hash = $hash;
3019 $search_hash = "HEAD";
3021 my $action = $my_uri;
3022 my $use_pathinfo = gitweb_check_feature('pathinfo');
3023 if ($use_pathinfo) {
3024 $action .= "/".esc_url($project);
3026 print $cgi->startform(-method => "get", -action => $action) .
3027 "<div class=\"search\">\n" .
3029 $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3030 $cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3031 $cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3032 $cgi->popup_menu(-name => 'st', -default => 'commit',
3033 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3034 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3036 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3037 "<span title=\"Extended regular expression\">" .
3038 $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3039 -checked => $search_use_regexp) .
3042 $cgi->end_form() . "\n";
3046 sub git_footer_html {
3047 my $feed_class = 'rss_logo';
3049 print "<div class=\"page_footer\">\n";
3050 if (defined $project) {
3051 my $descr = git_get_project_description($project);
3052 if (defined $descr) {
3053 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
3056 my %href_params = get_feed_info();
3057 if (!%href_params) {
3058 $feed_class .= ' generic';
3060 $href_params{'-title'} ||= 'log';
3062 foreach my $format qw(RSS Atom) {
3063 $href_params{'action'} = lc($format);
3064 print $cgi->a({-href => href(%href_params),
3065 -title => "$href_params{'-title'} $format feed",
3066 -class => $feed_class}, $format)."\n";
3070 print $cgi->a({-href => href(project=>undef, action=>"opml"),
3071 -class => $feed_class}, "OPML") . " ";
3072 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
3073 -class => $feed_class}, "TXT") . "\n";
3075 print "</div>\n"; # class="page_footer"
3077 if (-f $site_footer) {
3078 insert_file($site_footer);
3085 # die_error(<http_status_code>, <error_message>)
3086 # Example: die_error(404, 'Hash not found')
3087 # By convention, use the following status codes (as defined in RFC 2616):
3088 # 400: Invalid or missing CGI parameters, or
3089 # requested object exists but has wrong type.
3090 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3091 # this server or project.
3092 # 404: Requested object/revision/project doesn't exist.
3093 # 500: The server isn't configured properly, or
3094 # an internal error occurred (e.g. failed assertions caused by bugs), or
3095 # an unknown error occurred (e.g. the git binary died unexpectedly).
3097 my $status = shift || 500;
3098 my $error = shift || "Internal server error";
3100 my %http_responses = (400 => '400 Bad Request',
3101 403 => '403 Forbidden',
3102 404 => '404 Not Found',
3103 500 => '500 Internal Server Error');
3104 git_header_html($http_responses{$status});
3106 <div class="page_body">
3116 ## ----------------------------------------------------------------------
3117 ## functions printing or outputting HTML: navigation
3119 sub git_print_page_nav {
3120 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3121 $extra = '' if !defined $extra; # pager or formats
3123 my @navs = qw(summary shortlog log commit commitdiff tree);
3125 @navs = grep { $_ ne $suppress } @navs;
3128 my %arg = map { $_ => {action=>$_} } @navs;
3129 if (defined $head) {
3130 for (qw(commit commitdiff)) {
3131 $arg{$_}{'hash'} = $head;
3133 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3134 for (qw(shortlog log)) {
3135 $arg{$_}{'hash'} = $head;
3140 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3141 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3143 my @actions = gitweb_get_feature('actions');
3146 'n' => $project, # project name
3147 'f' => $git_dir, # project path within filesystem
3148 'h' => $treehead || '', # current hash ('h' parameter)
3149 'b' => $treebase || '', # hash base ('hb' parameter)
3152 my ($label, $link, $pos) = splice(@actions,0,3);
3154 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3156 $link =~ s/%([%nfhb])/$repl{$1}/g;
3157 $arg{$label}{'_href'} = $link;
3160 print "<div class=\"page_nav\">\n" .
3162 map { $_ eq $current ?
3163 $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
3165 print "<br/>\n$extra<br/>\n" .
3169 sub format_paging_nav {
3170 my ($action, $hash, $head, $page, $has_next_link) = @_;
3174 if ($hash ne $head || $page) {
3175 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
3177 $paging_nav .= "HEAD";
3181 $paging_nav .= " ⋅ " .
3182 $cgi->a({-href => href(-replay=>1, page=>$page-1),
3183 -accesskey => "p", -title => "Alt-p"}, "prev");
3185 $paging_nav .= " ⋅ prev";
3188 if ($has_next_link) {
3189 $paging_nav .= " ⋅ " .
3190 $cgi->a({-href => href(-replay=>1, page=>$page+1),
3191 -accesskey => "n", -title => "Alt-n"}, "next");
3193 $paging_nav .= " ⋅ next";
3199 ## ......................................................................
3200 ## functions printing or outputting HTML: div
3202 sub git_print_header_div {
3203 my ($action, $title, $hash, $hash_base) = @_;
3206 $args{'action'} = $action;
3207 $args{'hash'} = $hash if $hash;
3208 $args{'hash_base'} = $hash_base if $hash_base;
3210 print "<div class=\"header\">\n" .
3211 $cgi->a({-href => href(%args), -class => "title"},
3212 $title ? $title : $action) .
3216 #sub git_print_authorship (\%) {
3217 sub git_print_authorship {
3220 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3221 print "<div class=\"author_date\">" .
3222 esc_html($co->{'author_name'}) .
3224 if ($ad{'hour_local'} < 6) {
3225 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3226 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3228 printf(" (%02d:%02d %s)",
3229 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3234 sub git_print_page_path {
3240 print "<div class=\"page_path\">";
3241 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
3242 -title => 'tree root'}, to_utf8("[$project]"));
3244 if (defined $name) {
3245 my @dirname = split '/', $name;
3246 my $basename = pop @dirname;
3249 foreach my $dir (@dirname) {
3250 $fullname .= ($fullname ? '/' : '') . $dir;
3251 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
3253 -title => $fullname}, esc_path($dir));
3256 if (defined $type && $type eq 'blob') {
3257 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
3259 -title => $name}, esc_path($basename));
3260 } elsif (defined $type && $type eq 'tree') {
3261 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
3263 -title => $name}, esc_path($basename));
3266 print esc_path($basename);
3269 print "<br/></div>\n";
3272 # sub git_print_log (\@;%) {
3273 sub git_print_log ($;%) {
3277 if ($opts{'-remove_title'}) {
3278 # remove title, i.e. first line of log
3281 # remove leading empty lines
3282 while (defined $log->[0] && $log->[0] eq "") {
3289 foreach my $line (@$log) {
3290 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3293 if (! $opts{'-remove_signoff'}) {
3294 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
3297 # remove signoff lines
3304 # print only one empty line
3305 # do not print empty line after signoff
3307 next if ($empty || $signoff);
3313 print format_log_line_html($line) . "<br/>\n";
3316 if ($opts{'-final_empty_line'}) {
3317 # end with single empty line
3318 print "<br/>\n" unless $empty;
3322 # return link target (what link points to)
3323 sub git_get_link_target {
3328 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3332 $link_target = <$fd>;
3337 return $link_target;
3340 # given link target, and the directory (basedir) the link is in,
3341 # return target of link relative to top directory (top tree);
3342 # return undef if it is not possible (including absolute links).
3343 sub normalize_link_target {
3344 my ($link_target, $basedir, $hash_base) = @_;
3346 # we can normalize symlink target only if $hash_base is provided
3347 return unless $hash_base;
3349 # absolute symlinks (beginning with '/') cannot be normalized
3350 return if (substr($link_target, 0, 1) eq '/');
3352 # normalize link target to path from top (root) tree (dir)
3355 $path = $basedir . '/' . $link_target;
3357 # we are in top (root) tree (dir)
3358 $path = $link_target;
3361 # remove //, /./, and /../
3363 foreach my $part (split('/', $path)) {
3364 # discard '.' and ''
3365 next if (!$part || $part eq '.');
3367 if ($part eq '..') {
3371 # link leads outside repository (outside top dir)
3375 push @path_parts, $part;
3378 $path = join('/', @path_parts);
3383 # print tree entry (row of git_tree), but without encompassing <tr> element
3384 sub git_print_tree_entry {
3385 my ($t, $basedir, $hash_base, $have_blame) = @_;
3388 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3390 # The format of a table row is: mode list link. Where mode is
3391 # the mode of the entry, list is the name of the entry, an href,
3392 # and link is the action links of the entry.
3394 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
3395 if ($t->{'type'} eq "blob") {
3396 print "<td class=\"list\">" .
3397 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3398 file_name=>"$basedir$t->{'name'}", %base_key),
3399 -class => "list"}, esc_path($t->{'name'}));
3400 if (S_ISLNK(oct $t->{'mode'})) {
3401 my $link_target = git_get_link_target($t->{'hash'});
3403 my $norm_target = normalize_link_target($link_target, $basedir, $hash_base);
3404 if (defined $norm_target) {
3406 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
3407 file_name=>$norm_target),
3408 -title => $norm_target}, esc_path($link_target));
3410 print " -> " . esc_path($link_target);
3415 print "<td class=\"link\">";
3416 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3417 file_name=>"$basedir$t->{'name'}", %base_key)},
3421 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
3422 file_name=>"$basedir$t->{'name'}", %base_key)},
3425 if (defined $hash_base) {
3427 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3428 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
3432 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
3433 file_name=>"$basedir$t->{'name'}")},
3437 } elsif ($t->{'type'} eq "tree") {
3438 print "<td class=\"list\">";
3439 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3440 file_name=>"$basedir$t->{'name'}", %base_key)},
3441 esc_path($t->{'name'}));
3443 print "<td class=\"link\">";
3444 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3445 file_name=>"$basedir$t->{'name'}", %base_key)},
3447 if (defined $hash_base) {
3449 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3450 file_name=>"$basedir$t->{'name'}")},
3455 # unknown object: we can only present history for it
3456 # (this includes 'commit' object, i.e. submodule support)
3457 print "<td class=\"list\">" .
3458 esc_path($t->{'name'}) .
3460 print "<td class=\"link\">";
3461 if (defined $hash_base) {
3462 print $cgi->a({-href => href(action=>"history",
3463 hash_base=>$hash_base,
3464 file_name=>"$basedir$t->{'name'}")},
3471 ## ......................................................................
3472 ## functions printing large fragments of HTML
3474 # get pre-image filenames for merge (combined) diff
3475 sub fill_from_file_info {
3476 my ($diff, @parents) = @_;
3478 $diff->{'from_file'} = [ ];
3479 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3480 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3481 if ($diff->{'status'}[$i] eq 'R' ||
3482 $diff->{'status'}[$i] eq 'C') {
3483 $diff->{'from_file'}[$i] =
3484 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
3491 # is current raw difftree line of file deletion
3493 my $diffinfo = shift;
3495 return $diffinfo->{'to_id'} eq ('0' x 40);
3498 # does patch correspond to [previous] difftree raw line
3499 # $diffinfo - hashref of parsed raw diff format
3500 # $patchinfo - hashref of parsed patch diff format
3501 # (the same keys as in $diffinfo)
3502 sub is_patch_split {
3503 my ($diffinfo, $patchinfo) = @_;
3505 return defined $diffinfo && defined $patchinfo
3506 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3510 sub git_difftree_body {
3511 my ($difftree, $hash, @parents) = @_;
3512 my ($parent) = $parents[0];
3513 my $have_blame = gitweb_check_feature('blame');
3514 print "<div class=\"list_head\">\n";
3515 if ($#{$difftree} > 10) {
3516 print(($#{$difftree} + 1) . " files changed:\n");
3520 print "<table class=\"" .
3521 (@parents > 1 ? "combined " : "") .
3524 # header only for combined diff in 'commitdiff' view
3525 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3528 print "<thead><tr>\n" .
3529 "<th></th><th></th>\n"; # filename, patchN link
3530 for (my $i = 0; $i < @parents; $i++) {
3531 my $par = $parents[$i];
3533 $cgi->a({-href => href(action=>"commitdiff",
3534 hash=>$hash, hash_parent=>$par),
3535 -title => 'commitdiff to parent number ' .
3536 ($i+1) . ': ' . substr($par,0,7)},
3540 print "</tr></thead>\n<tbody>\n";
3545 foreach my $line (@{$difftree}) {
3546 my $diff = parsed_difftree_line($line);
3549 print "<tr class=\"dark\">\n";
3551 print "<tr class=\"light\">\n";
3555 if (exists $diff->{'nparents'}) { # combined diff
3557 fill_from_file_info($diff, @parents)
3558 unless exists $diff->{'from_file'};
3560 if (!is_deleted($diff)) {
3561 # file exists in the result (child) commit
3563 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3564 file_name=>$diff->{'to_file'},
3566 -class => "list"}, esc_path($diff->{'to_file'})) .
3570 esc_path($diff->{'to_file'}) .
3574 if ($action eq 'commitdiff') {
3577 print "<td class=\"link\">" .
3578 $cgi->a({-href => "#patch$patchno"}, "patch") .
3583 my $has_history = 0;
3584 my $not_deleted = 0;
3585 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3586 my $hash_parent = $parents[$i];
3587 my $from_hash = $diff->{'from_id'}[$i];
3588 my $from_path = $diff->{'from_file'}[$i];
3589 my $status = $diff->{'status'}[$i];
3591 $has_history ||= ($status ne 'A');
3592 $not_deleted ||= ($status ne 'D');
3594 if ($status eq 'A') {
3595 print "<td class=\"link\" align=\"right\"> | </td>\n";
3596 } elsif ($status eq 'D') {
3597 print "<td class=\"link\">" .
3598 $cgi->a({-href => href(action=>"blob",
3601 file_name=>$from_path)},
3605 if ($diff->{'to_id'} eq $from_hash) {
3606 print "<td class=\"link nochange\">";
3608 print "<td class=\"link\">";
3610 print $cgi->a({-href => href(action=>"blobdiff",
3611 hash=>$diff->{'to_id'},
3612 hash_parent=>$from_hash,
3614 hash_parent_base=>$hash_parent,
3615 file_name=>$diff->{'to_file'},
3616 file_parent=>$from_path)},
3622 print "<td class=\"link\">";
3624 print $cgi->a({-href => href(action=>"blob",
3625 hash=>$diff->{'to_id'},
3626 file_name=>$diff->{'to_file'},
3629 print " | " if ($has_history);
3632 print $cgi->a({-href => href(action=>"history",
3633 file_name=>$diff->{'to_file'},
3640 next; # instead of 'else' clause, to avoid extra indent
3642 # else ordinary diff
3644 my ($to_mode_oct, $to_mode_str, $to_file_type);
3645 my ($from_mode_oct, $from_mode_str, $from_file_type);
3646 if ($diff->{'to_mode'} ne ('0' x 6)) {
3647 $to_mode_oct = oct $diff->{'to_mode'};
3648 if (S_ISREG($to_mode_oct)) { # only for regular file
3649 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3651 $to_file_type = file_type($diff->{'to_mode'});
3653 if ($diff->{'from_mode'} ne ('0' x 6)) {
3654 $from_mode_oct = oct $diff->{'from_mode'};
3655 if (S_ISREG($to_mode_oct)) { # only for regular file
3656 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3658 $from_file_type = file_type($diff->{'from_mode'});
3661 if ($diff->{'status'} eq "A") { # created
3662 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3663 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3664 $mode_chng .= "]</span>";
3666 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3667 hash_base=>$hash, file_name=>$diff->{'file'}),
3668 -class => "list"}, esc_path($diff->{'file'}));
3670 print "<td>$mode_chng</td>\n";
3671 print "<td class=\"link\">";
3672 if ($action eq 'commitdiff') {
3675 print $cgi->a({-href => "#patch$patchno"}, "patch");
3678 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3679 hash_base=>$hash, file_name=>$diff->{'file'})},
3683 } elsif ($diff->{'status'} eq "D") { # deleted
3684 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3686 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3687 hash_base=>$parent, file_name=>$diff->{'file'}),
3688 -class => "list"}, esc_path($diff->{'file'}));
3690 print "<td>$mode_chng</td>\n";
3691 print "<td class=\"link\">";
3692 if ($action eq 'commitdiff') {
3695 print $cgi->a({-href => "#patch$patchno"}, "patch");
3698 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3699 hash_base=>$parent, file_name=>$diff->{'file'})},
3702 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3703 file_name=>$diff->{'file'})},
3706 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3707 file_name=>$diff->{'file'})},
3711 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3712 my $mode_chnge = "";
3713 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3714 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3715 if ($from_file_type ne $to_file_type) {
3716 $mode_chnge .= " from $from_file_type to $to_file_type";
3718 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3719 if ($from_mode_str && $to_mode_str) {
3720 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3721 } elsif ($to_mode_str) {
3722 $mode_chnge .= " mode: $to_mode_str";
3725 $mode_chnge .= "]</span>\n";
3728 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3729 hash_base=>$hash, file_name=>$diff->{'file'}),
3730 -class => "list"}, esc_path($diff->{'file'}));
3732 print "<td>$mode_chnge</td>\n";
3733 print "<td class=\"link\">";
3734 if ($action eq 'commitdiff') {
3737 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3739 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3740 # "commit" view and modified file (not onlu mode changed)
3741 print $cgi->a({-href => href(action=>"blobdiff",
3742 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3743 hash_base=>$hash, hash_parent_base=>$parent,
3744 file_name=>$diff->{'file'})},
3748 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3749 hash_base=>$hash, file_name=>$diff->{'file'})},
3752 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3753 file_name=>$diff->{'file'})},
3756 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3757 file_name=>$diff->{'file'})},
3761 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3762 my %status_name = ('R' => 'moved', 'C' => 'copied');
3763 my $nstatus = $status_name{$diff->{'status'}};
3765 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3766 # mode also for directories, so we cannot use $to_mode_str
3767 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3770 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3771 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3772 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3773 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3774 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3775 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3776 -class => "list"}, esc_path($diff->{'from_file'})) .
3777 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3778 "<td class=\"link\">";
3779 if ($action eq 'commitdiff') {
3782 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3784 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3785 # "commit" view and modified file (not only pure rename or copy)
3786 print $cgi->a({-href => href(action=>"blobdiff",
3787 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3788 hash_base=>$hash, hash_parent_base=>$parent,
3789 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3793 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3794 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3797 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3798 file_name=>$diff->{'to_file'})},
3801 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3802 file_name=>$diff->{'to_file'})},
3806 } # we should not encounter Unmerged (U) or Unknown (X) status
3809 print "</tbody>" if $has_header;
3813 sub git_patchset_body {
3814 my ($fd, $difftree, $hash, @hash_parents) = @_;
3815 my ($hash_parent) = $hash_parents[0];
3817 my $is_combined = (@hash_parents > 1);
3819 my $patch_number = 0;
3825 print "<div class=\"patchset\">\n";
3827 # skip to first patch
3828 while ($patch_line = <$fd>) {
3831 last if ($patch_line =~ m/^diff /);
3835 while ($patch_line) {
3837 # parse "git diff" header line
3838 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3839 # $1 is from_name, which we do not use
3840 $to_name = unquote($2);
3841 $to_name =~ s!^b/!!;
3842 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3843 # $1 is 'cc' or 'combined', which we do not use
3844 $to_name = unquote($2);
3849 # check if current patch belong to current raw line
3850 # and parse raw git-diff line if needed
3851 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
3852 # this is continuation of a split patch
3853 print "<div class=\"patch cont\">\n";
3855 # advance raw git-diff output if needed
3856 $patch_idx++ if defined $diffinfo;
3858 # read and prepare patch information
3859 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3861 # compact combined diff output can have some patches skipped
3862 # find which patch (using pathname of result) we are at now;
3864 while ($to_name ne $diffinfo->{'to_file'}) {
3865 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3866 format_diff_cc_simplified($diffinfo, @hash_parents) .
3867 "</div>\n"; # class="patch"
3872 last if $patch_idx > $#$difftree;
3873 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3877 # modifies %from, %to hashes
3878 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3880 # this is first patch for raw difftree line with $patch_idx index
3881 # we index @$difftree array from 0, but number patches from 1
3882 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3886 #assert($patch_line =~ m/^diff /) if DEBUG;
3887 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3889 # print "git diff" header
3890 print format_git_diff_header_line($patch_line, $diffinfo,
3893 # print extended diff header
3894 print "<div class=\"diff extended_header\">\n";
3896 while ($patch_line = <$fd>) {
3899 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
3901 print format_extended_diff_header_line($patch_line, $diffinfo,
3904 print "</div>\n"; # class="diff extended_header"
3906 # from-file/to-file diff header
3907 if (! $patch_line) {
3908 print "</div>\n"; # class="patch"
3911 next PATCH if ($patch_line =~ m/^diff /);
3912 #assert($patch_line =~ m/^---/) if DEBUG;
3914 my $last_patch_line = $patch_line;
3915 $patch_line = <$fd>;
3917 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3919 print format_diff_from_to_header($last_patch_line, $patch_line,
3920 $diffinfo, \%from, \%to,
3925 while ($patch_line = <$fd>) {
3928 next PATCH if ($patch_line =~ m/^diff /);
3930 print format_diff_line($patch_line, \%from, \%to);
3934 print "</div>\n"; # class="patch"
3937 # for compact combined (--cc) format, with chunk and patch simpliciaction
3938 # patchset might be empty, but there might be unprocessed raw lines
3939 for (++$patch_idx if $patch_number > 0;
3940 $patch_idx < @$difftree;
3942 # read and prepare patch information
3943 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
3945 # generate anchor for "patch" links in difftree / whatchanged part
3946 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3947 format_diff_cc_simplified($diffinfo, @hash_parents) .
3948 "</div>\n"; # class="patch"
3953 if ($patch_number == 0) {
3954 if (@hash_parents > 1) {
3955 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3957 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3961 print "</div>\n"; # class="patchset"
3964 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3966 # fills project list info (age, description, owner, forks) for each
3967 # project in the list, removing invalid projects from returned list
3968 # NOTE: modifies $projlist, but does not remove entries from it
3969 sub fill_project_list_info {
3970 my ($projlist, $check_forks) = @_;
3973 my $show_ctags = gitweb_check_feature('ctags');
3975 foreach my $pr (@$projlist) {
3976 my (@activity) = git_get_last_activity($pr->{'path'});
3977 unless (@activity) {
3980 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3981 if (!defined $pr->{'descr'}) {
3982 my $descr = git_get_project_description($pr->{'path'}) || "";
3983 $descr = to_utf8($descr);
3984 $pr->{'descr_long'} = $descr;
3985 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
3987 if (!defined $pr->{'owner'}) {
3988 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
3991 my $pname = $pr->{'path'};
3992 if (($pname =~ s/\.git$//) &&
3993 ($pname !~ /\/$/) &&
3994 (-d "$projectroot/$pname")) {
3995 $pr->{'forks'} = "-d $projectroot/$pname";
4000 $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
4001 push @projects, $pr;
4007 # print 'sort by' <th> element, generating 'sort by $name' replay link
4008 # if that order is not selected
4010 my ($name, $order, $header) = @_;
4011 $header ||= ucfirst($name);
4013 if ($order eq $name) {
4014 print "<th>$header</th>\n";
4017 $cgi->a({-href => href(-replay=>1, order=>$name),
4018 -class => "header"}, $header) .
4023 sub git_project_list_body {
4024 # actually uses global variable $project
4025 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4027 my $check_forks = gitweb_check_feature('forks');
4028 my @projects = fill_project_list_info($projlist, $check_forks);
4030 $order ||= $default_projects_order;
4031 $from = 0 unless defined $from;
4032 $to = $#projects if (!defined $to || $#projects < $to);
4035 project => { key => 'path', type => 'str' },
4036 descr => { key => 'descr_long', type => 'str' },
4037 owner => { key => 'owner', type => 'str' },
4038 age => { key => 'age', type => 'num' }
4040 my $oi = $order_info{$order};
4041 if ($oi->{'type'} eq 'str') {
4042 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4044 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4047 my $show_ctags = gitweb_check_feature('ctags');
4050 foreach my $p (@projects) {
4051 foreach my $ct (keys %{$p->{'ctags'}}) {
4052 $ctags{$ct} += $p->{'ctags'}->{$ct};
4055 my $cloud = git_populate_project_tagcloud(\%ctags);
4056 print git_show_project_tagcloud($cloud, 64);
4059 print "<table class=\"project_list\">\n";
4060 unless ($no_header) {
4063 print "<th></th>\n";
4065 print_sort_th('project', $order, 'Project');
4066 print_sort_th('descr', $order, 'Description');
4067 print_sort_th('owner', $order, 'Owner');
4068 print_sort_th('age', $order, 'Last Change');
4069 print "<th></th>\n" . # for links
4073 my $tagfilter = $cgi->param('by_tag');
4074 for (my $i = $from; $i <= $to; $i++) {
4075 my $pr = $projects[$i];
4077 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4078 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4079 and not $pr->{'descr_long'} =~ /$searchtext/;
4080 # Weed out forks or non-matching entries of search
4082 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
4083 $forkbase="^$forkbase" if $forkbase;
4084 next if not $searchtext and not $tagfilter and $show_ctags
4085 and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
4089 print "<tr class=\"dark\">\n";
4091 print "<tr class=\"light\">\n";
4096 if ($pr->{'forks'}) {
4097 print "<!-- $pr->{'forks'} -->\n";
4098 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
4102 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4103 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
4104 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4105 -class => "list", -title => $pr->{'descr_long'}},
4106 esc_html($pr->{'descr'})) . "</td>\n" .
4107 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
4108 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
4109 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4110 "<td class=\"link\">" .
4111 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
4112 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
4113 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
4114 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
4115 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
4119 if (defined $extra) {
4122 print "<td></td>\n";
4124 print "<td colspan=\"5\">$extra</td>\n" .
4130 sub git_shortlog_body {
4131 # uses global variable $project
4132 my ($commitlist, $from, $to, $refs, $extra) = @_;
4134 $from = 0 unless defined $from;
4135 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4137 print "<table class=\"shortlog\">\n";
4139 for (my $i = $from; $i <= $to; $i++) {
4140 my %co = %{$commitlist->[$i]};
4141 my $commit = $co{'id'};
4142 my $ref = format_ref_marker($refs, $commit);
4144 print "<tr class=\"dark\">\n";
4146 print "<tr class=\"light\">\n";
4149 my $author = chop_and_escape_str($co{'author_name'}, 10);
4150 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4151 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4152 "<td><i>" . $author . "</i></td>\n" .
4154 print format_subject_html($co{'title'}, $co{'title_short'},
4155 href(action=>"commit", hash=>$commit), $ref);
4157 "<td class=\"link\">" .
4158 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
4159 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
4160 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
4161 my $snapshot_links = format_snapshot_links($commit);
4162 if (defined $snapshot_links) {
4163 print " | " . $snapshot_links;
4168 if (defined $extra) {
4170 "<td colspan=\"4\">$extra</td>\n" .
4176 sub git_history_body {
4177 # Warning: assumes constant type (blob or tree) during history
4178 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4180 $from = 0 unless defined $from;
4181 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4183 print "<table class=\"history\">\n";
4185 for (my $i = $from; $i <= $to; $i++) {
4186 my %co = %{$commitlist->[$i]};
4190 my $commit = $co{'id'};
4192 my $ref = format_ref_marker($refs, $commit);
4195 print "<tr class=\"dark\">\n";
4197 print "<tr class=\"light\">\n";
4200 # shortlog uses chop_str($co{'author_name'}, 10)
4201 my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
4202 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4203 "<td><i>" . $author . "</i></td>\n" .
4205 # originally git_history used chop_str($co{'title'}, 50)
4206 print format_subject_html($co{'title'}, $co{'title_short'},
4207 href(action=>"commit", hash=>$commit), $ref);
4209 "<td class=\"link\">" .
4210 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
4211 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
4213 if ($ftype eq 'blob') {
4214 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
4215 my $blob_parent = git_get_hash_by_path($commit, $file_name);
4216 if (defined $blob_current && defined $blob_parent &&
4217 $blob_current ne $blob_parent) {
4219 $cgi->a({-href => href(action=>"blobdiff",
4220 hash=>$blob_current, hash_parent=>$blob_parent,
4221 hash_base=>$hash_base, hash_parent_base=>$commit,
4222 file_name=>$file_name)},
4229 if (defined $extra) {
4231 "<td colspan=\"4\">$extra</td>\n" .
4238 # uses global variable $project
4239 my ($taglist, $from, $to, $extra) = @_;
4240 $from = 0 unless defined $from;
4241 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4243 print "<table class=\"tags\">\n";
4245 for (my $i = $from; $i <= $to; $i++) {
4246 my $entry = $taglist->[$i];
4248 my $comment = $tag{'subject'};
4250 if (defined $comment) {
4251 $comment_short = chop_str($comment, 30, 5);
4254 print "<tr class=\"dark\">\n";
4256 print "<tr class=\"light\">\n";
4259 if (defined $tag{'age'}) {
4260 print "<td><i>$tag{'age'}</i></td>\n";
4262 print "<td></td>\n";
4265 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
4266 -class => "list name"}, esc_html($tag{'name'})) .
4269 if (defined $comment) {
4270 print format_subject_html($comment, $comment_short,
4271 href(action=>"tag", hash=>$tag{'id'}));
4274 "<td class=\"selflink\">";
4275 if ($tag{'type'} eq "tag") {
4276 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
4281 "<td class=\"link\">" . " | " .
4282 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
4283 if ($tag{'reftype'} eq "commit") {
4284 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
4285 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
4286 } elsif ($tag{'reftype'} eq "blob") {
4287 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
4292 if (defined $extra) {
4294 "<td colspan=\"5\">$extra</td>\n" .
4300 sub git_heads_body {
4301 # uses global variable $project
4302 my ($headlist, $head, $from, $to, $extra) = @_;
4303 $from = 0 unless defined $from;
4304 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4306 print "<table class=\"heads\">\n";
4308 for (my $i = $from; $i <= $to; $i++) {
4309 my $entry = $headlist->[$i];
4311 my $curr = $ref{'id'} eq $head;
4313 print "<tr class=\"dark\">\n";
4315 print "<tr class=\"light\">\n";
4318 print "<td><i>$ref{'age'}</i></td>\n" .
4319 ($curr ? "<td class=\"current_head\">" : "<td>") .
4320 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),
4321 -class => "list name"},esc_html($ref{'name'})) .
4323 "<td class=\"link\">" .
4324 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
4325 $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
4326 $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
4330 if (defined $extra) {
4332 "<td colspan=\"3\">$extra</td>\n" .
4338 sub git_search_grep_body {
4339 my ($commitlist, $from, $to, $extra) = @_;
4340 $from = 0 unless defined $from;
4341 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4343 print "<table class=\"commit_search\">\n";
4345 for (my $i = $from; $i <= $to; $i++) {
4346 my %co = %{$commitlist->[$i]};
4350 my $commit = $co{'id'};
4352 print "<tr class=\"dark\">\n";
4354 print "<tr class=\"light\">\n";
4357 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
4358 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4359 "<td><i>" . $author . "</i></td>\n" .
4361 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
4362 -class => "list subject"},
4363 chop_and_escape_str($co{'title'}, 50) . "<br/>");
4364 my $comment = $co{'comment'};
4365 foreach my $line (@$comment) {
4366 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4367 my ($lead, $match, $trail) = ($1, $2, $3);
4368 $match = chop_str($match, 70, 5, 'center');
4369 my $contextlen = int((80 - length($match))/2);
4370 $contextlen = 30 if ($contextlen > 30);
4371 $lead = chop_str($lead, $contextlen, 10, 'left');
4372 $trail = chop_str($trail, $contextlen, 10, 'right');
4374 $lead = esc_html($lead);
4375 $match = esc_html($match);
4376 $trail = esc_html($trail);
4378 print "$lead<span class=\"match\">$match</span>$trail<br />";
4382 "<td class=\"link\">" .
4383 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4385 $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") .
4387 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4391 if (defined $extra) {
4393 "<td colspan=\"3\">$extra</td>\n" .
4399 ## ======================================================================
4400 ## ======================================================================
4403 sub git_project_list {
4404 my $order = $input_params{'order'};
4405 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4406 die_error(400, "Unknown order parameter");
4409 my @list = git_get_projects_list();
4411 die_error(404, "No projects found");
4415 if (-f $home_text) {
4416 print "<div class=\"index_include\">\n";
4417 insert_file($home_text);
4420 print $cgi->startform(-method => "get") .
4421 "<p class=\"projsearch\">Search:\n" .
4422 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
4424 $cgi->end_form() . "\n";
4425 git_project_list_body(\@list, $order);
4430 my $order = $input_params{'order'};
4431 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4432 die_error(400, "Unknown order parameter");
4435 my @list = git_get_projects_list($project);
4437 die_error(404, "No forks found");
4441 git_print_page_nav('','');
4442 git_print_header_div('summary', "$project forks");
4443 git_project_list_body(\@list, $order);
4447 sub git_project_index {
4448 my @projects = git_get_projects_list($project);
4451 -type => 'text/plain',
4452 -charset => 'utf-8',
4453 -content_disposition => 'inline; filename="index.aux"');
4455 foreach my $pr (@projects) {
4456 if (!exists $pr->{'owner'}) {
4457 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
4460 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4461 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4462 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4463 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4467 print "$path $owner\n";
4472 my $descr = git_get_project_description($project) || "none";
4473 my %co = parse_commit("HEAD");
4474 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4475 my $head = $co{'id'};
4477 my $owner = git_get_project_owner($project);
4479 my $refs = git_get_references();
4480 # These get_*_list functions return one more to allow us to see if
4481 # there are more ...
4482 my @taglist = git_get_tags_list(16);
4483 my @headlist = git_get_heads_list(16);
4485 my $check_forks = gitweb_check_feature('forks');
4488 @forklist = git_get_projects_list($project);
4492 git_print_page_nav('summary','', $head);
4494 print "<div class=\"title\"> </div>\n";
4495 print "<table class=\"projects_list\">\n" .
4496 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
4497 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
4498 if (defined $cd{'rfc2822'}) {
4499 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4502 # use per project git URL list in $projectroot/$project/cloneurl
4503 # or make project git URL from git base URL and project name
4504 my $url_tag = "URL";
4505 my @url_list = git_get_project_url_list($project);
4506 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4507 foreach my $git_url (@url_list) {
4508 next unless $git_url;
4509 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4514 my $show_ctags = gitweb_check_feature('ctags');
4516 my $ctags = git_get_project_ctags($project);
4517 my $cloud = git_populate_project_tagcloud($ctags);
4518 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4519 print "</td>\n<td>" unless %$ctags;
4520 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4521 print "</td>\n<td>" if %$ctags;
4522 print git_show_project_tagcloud($cloud, 48);
4528 # If XSS prevention is on, we don't include README.html.
4529 # TODO: Allow a readme in some safe format.
4530 if (!$prevent_xss && -s "$projectroot/$project/README.html") {
4531 print "<div class=\"title\">readme</div>\n" .
4532 "<div class=\"readme\">\n";
4533 insert_file("$projectroot/$project/README.html");
4534 print "\n</div>\n"; # class="readme"
4537 # we need to request one more than 16 (0..15) to check if
4539 my @commitlist = $head ? parse_commits($head, 17) : ();
4541 git_print_header_div('shortlog');
4542 git_shortlog_body(\@commitlist, 0, 15, $refs,
4543 $#commitlist <= 15 ? undef :
4544 $cgi->a({-href => href(action=>"shortlog")}, "..."));
4548 git_print_header_div('tags');
4549 git_tags_body(\@taglist, 0, 15,
4550 $#taglist <= 15 ? undef :
4551 $cgi->a({-href => href(action=>"tags")}, "..."));
4555 git_print_header_div('heads');
4556 git_heads_body(\@headlist, $head, 0, 15,
4557 $#headlist <= 15 ? undef :
4558 $cgi->a({-href => href(action=>"heads")}, "..."));
4562 git_print_header_div('forks');
4563 git_project_list_body(\@forklist, 'age', 0, 15,
4564 $#forklist <= 15 ? undef :
4565 $cgi->a({-href => href(action=>"forks")}, "..."),
4573 my $head = git_get_head_hash($project);
4575 git_print_page_nav('','', $head,undef,$head);
4576 my %tag = parse_tag($hash);
4579 die_error(404, "Unknown tag object");
4582 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
4583 print "<div class=\"title_text\">\n" .
4584 "<table class=\"object_header\">\n" .
4586 "<td>object</td>\n" .
4587 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4588 $tag{'object'}) . "</td>\n" .
4589 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4590 $tag{'type'}) . "</td>\n" .
4592 if (defined($tag{'author'})) {
4593 my %ad = parse_date($tag{'epoch'}, $tag{'tz'});
4594 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
4595 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4596 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4599 print "</table>\n\n" .
4601 print "<div class=\"page_body\">";
4602 my $comment = $tag{'comment'};
4603 foreach my $line (@$comment) {
4605 print esc_html($line, -nbsp=>1) . "<br/>\n";
4613 gitweb_check_feature('blame')
4614 or die_error(403, "Blame view not allowed");
4617 die_error(400, "No file name given") unless $file_name;
4618 $hash_base ||= git_get_head_hash($project);
4619 die_error(404, "Couldn't find base commit") unless $hash_base;
4620 my %co = parse_commit($hash_base)
4621 or die_error(404, "Commit not found");
4623 if (!defined $hash) {
4624 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4625 or die_error(404, "Error looking up file");
4627 $ftype = git_get_type($hash);
4628 if ($ftype !~ "blob") {
4629 die_error(400, "Object is not a blob");
4633 # run git-blame --porcelain
4634 open my $fd, "-|", git_cmd(), "blame", '-p',
4635 $hash_base, '--', $file_name
4636 or die_error(500, "Open git-blame failed");
4641 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4644 $cgi->a({-href => href(action=>"history", -replay=>1)},
4647 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4649 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4650 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4651 git_print_page_path($file_name, $ftype, $hash_base);
4654 my @rev_color = qw(light2 dark2);
4655 my $num_colors = scalar(@rev_color);
4656 my $current_color = 0;
4660 <div class="page_body">
4661 <table class="blame">
4662 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4665 while (my $line = <$fd>) {
4667 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4668 # no <lines in group> for subsequent lines in group of lines
4669 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4670 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4671 if (!exists $metainfo{$full_rev}) {
4672 $metainfo{$full_rev} = {};
4674 my $meta = $metainfo{$full_rev};
4676 while ($data = <$fd>) {
4678 last if ($data =~ s/^\t//); # contents of line
4679 if ($data =~ /^(\S+) (.*)$/) {
4683 my $short_rev = substr($full_rev, 0, 8);
4684 my $author = $meta->{'author'};
4686 parse_date($meta->{'author-time'}, $meta->{'author-tz'});
4687 my $date = $date{'iso-tz'};
4689 $current_color = ($current_color + 1) % $num_colors;
4691 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4693 print "<td class=\"sha1\"";
4694 print " title=\"". esc_html($author) . ", $date\"";
4695 print " rowspan=\"$group_size\"" if ($group_size > 1);
4697 print $cgi->a({-href => href(action=>"commit",
4699 file_name=>$file_name)},
4700 esc_html($short_rev));
4704 if (!exists $meta->{'parent'}) {
4705 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4706 or die_error(500, "Open git-rev-parse failed");
4707 $parent_commit = <$dd>;
4709 chomp($parent_commit);
4710 $meta->{'parent'} = $parent_commit;
4712 $parent_commit = $meta->{'parent'};
4714 my $blamed = href(action => 'blame',
4715 file_name => $meta->{'filename'},
4716 hash_base => $parent_commit);
4717 print "<td class=\"linenr\">";
4718 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4719 -class => "linenr" },
4722 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4728 or print "Reading blob failed\n";
4735 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);
4748 my $head = git_get_head_hash($project);
4750 git_print_page_nav('','', $head,undef,$head);
4751 git_print_header_div('summary', $project);
4753 my @headslist = git_get_heads_list();
4755 git_heads_body(\@headslist, $head);
4760 sub git_blob_plain {
4764 if (!defined $hash) {
4765 if (defined $file_name) {
4766 my $base = $hash_base || git_get_head_hash($project);
4767 $hash = git_get_hash_by_path($base, $file_name, "blob")
4768 or die_error(404, "Cannot find file");
4770 die_error(400, "No file name defined");
4772 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4773 # blobs defined by non-textual hash id's can be cached
4777 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4778 or die_error(500, "Open git-cat-file blob '$hash' failed");
4780 # content-type (can include charset)
4781 $type = blob_contenttype($fd, $file_name, $type);
4783 # "save as" filename, even when no $file_name is given
4784 my $save_as = "$hash";
4785 if (defined $file_name) {
4786 $save_as = $file_name;
4787 } elsif ($type =~ m/^text\//) {
4791 # With XSS prevention on, blobs of all types except a few known safe
4792 # ones are served with "Content-Disposition: attachment" to make sure
4793 # they don't run in our security domain. For certain image types,
4794 # blob view writes an <img> tag referring to blob_plain view, and we
4795 # want to be sure not to break that by serving the image as an
4796 # attachment (though Firefox 3 doesn't seem to care).
4797 my $sandbox = $prevent_xss &&
4798 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4802 -expires => $expires,
4803 -content_disposition =>
4804 ($sandbox ? 'attachment' : 'inline')
4805 . '; filename="' . $save_as . '"');
4807 binmode STDOUT, ':raw';
4809 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4817 if (!defined $hash) {
4818 if (defined $file_name) {
4819 my $base = $hash_base || git_get_head_hash($project);
4820 $hash = git_get_hash_by_path($base, $file_name, "blob")
4821 or die_error(404, "Cannot find file");
4823 die_error(400, "No file name defined");
4825 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4826 # blobs defined by non-textual hash id's can be cached
4830 my $have_blame = gitweb_check_feature('blame');
4831 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4832 or die_error(500, "Couldn't cat $file_name, $hash");
4833 my $mimetype = blob_mimetype($fd, $file_name);
4834 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4836 return git_blob_plain($mimetype);
4838 # we can have blame only for text/* mimetype
4839 $have_blame &&= ($mimetype =~ m!^text/!);
4841 git_header_html(undef, $expires);
4842 my $formats_nav = '';
4843 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4844 if (defined $file_name) {
4847 $cgi->a({-href => href(action=>"blame", -replay=>1)},
4852 $cgi->a({-href => href(action=>"history", -replay=>1)},
4855 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4858 $cgi->a({-href => href(action=>"blob",
4859 hash_base=>"HEAD", file_name=>$file_name)},
4863 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
4866 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4867 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4869 print "<div class=\"page_nav\">\n" .
4870 "<br/><br/></div>\n" .
4871 "<div class=\"title\">$hash</div>\n";
4873 git_print_page_path($file_name, "blob", $hash_base);
4874 print "<div class=\"page_body\">\n";
4875 if ($mimetype =~ m!^image/!) {
4876 print qq!<img type="$mimetype"!;
4878 print qq! alt="$file_name" title="$file_name"!;
4881 href(action=>"blob_plain", hash=>$hash,
4882 hash_base=>$hash_base, file_name=>$file_name) .
4886 while (my $line = <$fd>) {
4889 $line = untabify($line);
4890 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4891 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
4895 or print "Reading blob failed.\n";
4901 if (!defined $hash_base) {
4902 $hash_base = "HEAD";
4904 if (!defined $hash) {
4905 if (defined $file_name) {
4906 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
4911 die_error(404, "No such tree") unless defined($hash);
4913 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
4914 or die_error(500, "Open git-ls-tree failed");
4915 my @entries = map { chomp; $_ } <$fd>;
4916 close $fd or die_error(404, "Reading tree failed");
4919 my $refs = git_get_references();
4920 my $ref = format_ref_marker($refs, $hash_base);
4923 my $have_blame = gitweb_check_feature('blame');
4924 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
4926 if (defined $file_name) {
4928 $cgi->a({-href => href(action=>"history", -replay=>1)},
4930 $cgi->a({-href => href(action=>"tree",
4931 hash_base=>"HEAD", file_name=>$file_name)},
4934 my $snapshot_links = format_snapshot_links($hash);
4935 if (defined $snapshot_links) {
4936 # FIXME: Should be available when we have no hash base as well.
4937 push @views_nav, $snapshot_links;
4939 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4940 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
4943 print "<div class=\"page_nav\">\n";
4944 print "<br/><br/></div>\n";
4945 print "<div class=\"title\">$hash</div>\n";
4947 if (defined $file_name) {
4948 $basedir = $file_name;
4949 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4952 git_print_page_path($file_name, 'tree', $hash_base);
4954 print "<div class=\"page_body\">\n";
4955 print "<table class=\"tree\">\n";
4957 # '..' (top directory) link if possible
4958 if (defined $hash_base &&
4959 defined $file_name && $file_name =~ m![^/]+$!) {
4961 print "<tr class=\"dark\">\n";
4963 print "<tr class=\"light\">\n";
4967 my $up = $file_name;
4968 $up =~ s!/?[^/]+$!!;
4969 undef $up unless $up;
4970 # based on git_print_tree_entry
4971 print '<td class="mode">' . mode_str('040000') . "</td>\n";
4972 print '<td class="list">';
4973 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
4977 print "<td class=\"link\"></td>\n";
4981 foreach my $line (@entries) {
4982 my %t = parse_ls_tree_line($line, -z => 1);
4985 print "<tr class=\"dark\">\n";
4987 print "<tr class=\"light\">\n";
4991 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
4995 print "</table>\n" .
5001 my $format = $input_params{'snapshot_format'};
5002 if (!@snapshot_fmts) {
5003 die_error(403, "Snapshots not allowed");
5005 # default to first supported snapshot format
5006 $format ||= $snapshot_fmts[0];
5007 if ($format !~ m/^[a-z0-9]+$/) {
5008 die_error(400, "Invalid snapshot format parameter");
5009 } elsif (!exists($known_snapshot_formats{$format})) {
5010 die_error(400, "Unknown snapshot format");
5011 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5012 die_error(403, "Unsupported snapshot format");
5015 if (!defined $hash) {
5016 $hash = git_get_head_hash($project);
5019 my $name = $project;
5020 $name =~ s,([^/])/*\.git$,$1,;
5021 $name = basename($name);
5022 my $filename = to_utf8($name);
5023 $name =~ s/\047/\047\\\047\047/g;
5025 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5026 $cmd = quote_command(
5027 git_cmd(), 'archive',
5028 "--format=$known_snapshot_formats{$format}{'format'}",
5029 "--prefix=$name/", $hash);
5030 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5031 $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
5035 -type => $known_snapshot_formats{$format}{'type'},
5036 -content_disposition => 'inline; filename="' . "$filename" . '"',
5037 -status => '200 OK');
5039 open my $fd, "-|", $cmd
5040 or die_error(500, "Execute git-archive failed");
5041 binmode STDOUT, ':raw';
5043 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
5048 my $head = git_get_head_hash($project);
5049 if (!defined $hash) {
5052 if (!defined $page) {
5055 my $refs = git_get_references();
5057 my @commitlist = parse_commits($hash, 101, (100 * $page));
5059 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5061 my ($patch_max) = gitweb_get_feature('patches');
5063 if ($patch_max < 0 || @commitlist <= $patch_max) {
5064 $paging_nav .= " ⋅ " .
5065 $cgi->a({-href => href(action=>"patches", -replay=>1)},
5071 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
5074 my %co = parse_commit($hash);
5076 git_print_header_div('summary', $project);
5077 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5079 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5080 for (my $i = 0; $i <= $to; $i++) {
5081 my %co = %{$commitlist[$i]};
5083 my $commit = $co{'id'};
5084 my $ref = format_ref_marker($refs, $commit);
5085 my %ad = parse_date($co{'author_epoch'});
5086 git_print_header_div('commit',
5087 "<span class=\"age\">$co{'age_string'}</span>" .
5088 esc_html($co{'title'}) . $ref,
5090 print "<div class=\"title_text\">\n" .
5091 "<div class=\"log_link\">\n" .
5092 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
5094 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
5096 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
5099 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5102 print "<div class=\"log_body\">\n";
5103 git_print_log($co{'comment'}, -final_empty_line=> 1);
5106 if ($#commitlist >= 100) {
5107 print "<div class=\"page_nav\">\n";
5108 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
5109 -accesskey => "n", -title => "Alt-n"}, "next");
5116 $hash ||= $hash_base || "HEAD";
5117 my %co = parse_commit($hash)
5118 or die_error(404, "Unknown commit object");
5119 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5120 my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
5122 my $parent = $co{'parent'};
5123 my $parents = $co{'parents'}; # listref
5125 # we need to prepare $formats_nav before any parameter munging
5127 if (!defined $parent) {
5129 $formats_nav .= '(initial)';
5130 } elsif (@$parents == 1) {
5131 # single parent commit
5134 $cgi->a({-href => href(action=>"commit",
5136 esc_html(substr($parent, 0, 7))) .
5143 $cgi->a({-href => href(action=>"commit",
5145 esc_html(substr($_, 0, 7)));
5149 if (gitweb_check_feature('patches')) {
5150 $formats_nav .= " | " .
5151 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5155 if (!defined $parent) {
5159 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
5161 (@$parents <= 1 ? $parent : '-c'),
5163 or die_error(500, "Open git-diff-tree failed");
5164 @difftree = map { chomp; $_ } <$fd>;
5165 close $fd or die_error(404, "Reading git-diff-tree failed");
5167 # non-textual hash id's can be cached
5169 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5172 my $refs = git_get_references();
5173 my $ref = format_ref_marker($refs, $co{'id'});
5175 git_header_html(undef, $expires);
5176 git_print_page_nav('commit', '',
5177 $hash, $co{'tree'}, $hash,
5180 if (defined $co{'parent'}) {
5181 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
5183 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
5185 print "<div class=\"title_text\">\n" .
5186 "<table class=\"object_header\">\n";
5187 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
5189 "<td></td><td> $ad{'rfc2822'}";
5190 if ($ad{'hour_local'} < 6) {
5191 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5192 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5194 printf(" (%02d:%02d %s)",
5195 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5199 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
5200 print "<tr><td></td><td> $cd{'rfc2822'}" .
5201 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5203 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5206 "<td class=\"sha1\">" .
5207 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
5208 class => "list"}, $co{'tree'}) .
5210 "<td class=\"link\">" .
5211 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
5213 my $snapshot_links = format_snapshot_links($hash);
5214 if (defined $snapshot_links) {
5215 print " | " . $snapshot_links;
5220 foreach my $par (@$parents) {
5223 "<td class=\"sha1\">" .
5224 $cgi->a({-href => href(action=>"commit", hash=>$par),
5225 class => "list"}, $par) .
5227 "<td class=\"link\">" .
5228 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
5230 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
5237 print "<div class=\"page_body\">\n";
5238 git_print_log($co{'comment'});
5241 git_difftree_body(\@difftree, $hash, @$parents);
5247 # object is defined by:
5248 # - hash or hash_base alone
5249 # - hash_base and file_name
5252 # - hash or hash_base alone
5253 if ($hash || ($hash_base && !defined $file_name)) {
5254 my $object_id = $hash || $hash_base;
5256 open my $fd, "-|", quote_command(
5257 git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5258 or die_error(404, "Object does not exist");
5262 or die_error(404, "Object does not exist");
5264 # - hash_base and file_name
5265 } elsif ($hash_base && defined $file_name) {
5266 $file_name =~ s,/+$,,;
5268 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
5269 or die_error(404, "Base object does not exist");
5271 # here errors should not hapen
5272 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
5273 or die_error(500, "Open git-ls-tree failed");
5277 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5278 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5279 die_error(404, "File or directory for given base does not exist");
5284 die_error(400, "Not enough information to find object");
5287 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
5288 hash=>$hash, hash_base=>$hash_base,
5289 file_name=>$file_name),
5290 -status => '302 Found');
5294 my $format = shift || 'html';
5301 # preparing $fd and %diffinfo for git_patchset_body
5303 if (defined $hash_base && defined $hash_parent_base) {
5304 if (defined $file_name) {
5306 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5307 $hash_parent_base, $hash_base,
5308 "--", (defined $file_parent ? $file_parent : ()), $file_name
5309 or die_error(500, "Open git-diff-tree failed");
5310 @difftree = map { chomp; $_ } <$fd>;
5312 or die_error(404, "Reading git-diff-tree failed");
5314 or die_error(404, "Blob diff not found");
5316 } elsif (defined $hash &&
5317 $hash =~ /[0-9a-fA-F]{40}/) {
5318 # try to find filename from $hash
5320 # read filtered raw output
5321 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5322 $hash_parent_base, $hash_base, "--"
5323 or die_error(500, "Open git-diff-tree failed");
5325 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5327 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5328 map { chomp; $_ } <$fd>;
5330 or die_error(404, "Reading git-diff-tree failed");
5332 or die_error(404, "Blob diff not found");
5335 die_error(400, "Missing one of the blob diff parameters");
5338 if (@difftree > 1) {
5339 die_error(400, "Ambiguous blob diff specification");
5342 %diffinfo = parse_difftree_raw_line($difftree[0]);
5343 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5344 $file_name ||= $diffinfo{'to_file'};
5346 $hash_parent ||= $diffinfo{'from_id'};
5347 $hash ||= $diffinfo{'to_id'};
5349 # non-textual hash id's can be cached
5350 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5351 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5356 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5357 '-p', ($format eq 'html' ? "--full-index" : ()),
5358 $hash_parent_base, $hash_base,
5359 "--", (defined $file_parent ? $file_parent : ()), $file_name
5360 or die_error(500, "Open git-diff-tree failed");
5363 # old/legacy style URI -- not generated anymore since 1.4.3.
5365 die_error('404 Not Found', "Missing one of the blob diff parameters")
5369 if ($format eq 'html') {
5371 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
5373 git_header_html(undef, $expires);
5374 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5375 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5376 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5378 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5379 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5381 if (defined $file_name) {
5382 git_print_page_path($file_name, "blob", $hash_base);
5384 print "<div class=\"page_path\"></div>\n";
5387 } elsif ($format eq 'plain') {
5389 -type => 'text/plain',
5390 -charset => 'utf-8',
5391 -expires => $expires,
5392 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
5394 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5397 die_error(400, "Unknown blobdiff format");
5401 if ($format eq 'html') {
5402 print "<div class=\"page_body\">\n";
5404 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
5407 print "</div>\n"; # class="page_body"
5411 while (my $line = <$fd>) {
5412 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5413 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5417 last if $line =~ m!^\+\+\+!;
5425 sub git_blobdiff_plain {
5426 git_blobdiff('plain');
5429 sub git_commitdiff {
5431 my $format = $params{-format} || 'html';
5433 my ($patch_max) = gitweb_get_feature('patches');
5434 if ($format eq 'patch') {
5435 die_error(403, "Patch view not allowed") unless $patch_max;
5438 $hash ||= $hash_base || "HEAD";
5439 my %co = parse_commit($hash)
5440 or die_error(404, "Unknown commit object");
5442 # choose format for commitdiff for merge
5443 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5444 $hash_parent = '--cc';
5446 # we need to prepare $formats_nav before almost any parameter munging
5448 if ($format eq 'html') {
5450 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
5453 $formats_nav .= " | " .
5454 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5458 if (defined $hash_parent &&
5459 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5460 # commitdiff with two commits given
5461 my $hash_parent_short = $hash_parent;
5462 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5463 $hash_parent_short = substr($hash_parent, 0, 7);
5467 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5468 if ($co{'parents'}[$i] eq $hash_parent) {
5469 $formats_nav .= ' parent ' . ($i+1);
5473 $formats_nav .= ': ' .
5474 $cgi->a({-href => href(action=>"commitdiff",
5475 hash=>$hash_parent)},
5476 esc_html($hash_parent_short)) .
5478 } elsif (!$co{'parent'}) {
5480 $formats_nav .= ' (initial)';
5481 } elsif (scalar @{$co{'parents'}} == 1) {
5482 # single parent commit
5485 $cgi->a({-href => href(action=>"commitdiff",
5486 hash=>$co{'parent'})},
5487 esc_html(substr($co{'parent'}, 0, 7))) .
5491 if ($hash_parent eq '--cc') {
5492 $formats_nav .= ' | ' .
5493 $cgi->a({-href => href(action=>"commitdiff",
5494 hash=>$hash, hash_parent=>'-c')},
5496 } else { # $hash_parent eq '-c'
5497 $formats_nav .= ' | ' .
5498 $cgi->a({-href => href(action=>"commitdiff",
5499 hash=>$hash, hash_parent=>'--cc')},
5505 $cgi->a({-href => href(action=>"commitdiff",
5507 esc_html(substr($_, 0, 7)));
5508 } @{$co{'parents'}} ) .
5513 my $hash_parent_param = $hash_parent;
5514 if (!defined $hash_parent_param) {
5515 # --cc for multiple parents, --root for parentless
5516 $hash_parent_param =
5517 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5523 if ($format eq 'html') {
5524 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5525 "--no-commit-id", "--patch-with-raw", "--full-index",
5526 $hash_parent_param, $hash, "--"
5527 or die_error(500, "Open git-diff-tree failed");
5529 while (my $line = <$fd>) {
5531 # empty line ends raw part of diff-tree output
5533 push @difftree, scalar parse_difftree_raw_line($line);
5536 } elsif ($format eq 'plain') {
5537 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5538 '-p', $hash_parent_param, $hash, "--"
5539 or die_error(500, "Open git-diff-tree failed");
5540 } elsif ($format eq 'patch') {
5541 # For commit ranges, we limit the output to the number of
5542 # patches specified in the 'patches' feature.
5543 # For single commits, we limit the output to a single patch,
5544 # diverging from the git-format-patch default.
5545 my @commit_spec = ();
5547 if ($patch_max > 0) {
5548 push @commit_spec, "-$patch_max";
5550 push @commit_spec, '-n', "$hash_parent..$hash";
5552 if ($params{-single}) {
5553 push @commit_spec, '-1';
5555 if ($patch_max > 0) {
5556 push @commit_spec, "-$patch_max";
5558 push @commit_spec, "-n";
5560 push @commit_spec, '--root', $hash;
5562 open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
5563 '--stdout', @commit_spec
5564 or die_error(500, "Open git-format-patch failed");
5566 die_error(400, "Unknown commitdiff format");
5569 # non-textual hash id's can be cached
5571 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5575 # write commit message
5576 if ($format eq 'html') {
5577 my $refs = git_get_references();
5578 my $ref = format_ref_marker($refs, $co{'id'});
5580 git_header_html(undef, $expires);
5581 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5582 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5583 git_print_authorship(\%co);
5584 print "<div class=\"page_body\">\n";
5585 if (@{$co{'comment'}} > 1) {
5586 print "<div class=\"log\">\n";
5587 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5588 print "</div>\n"; # class="log"
5591 } elsif ($format eq 'plain') {
5592 my $refs = git_get_references("tags");
5593 my $tagname = git_get_rev_name_tags($hash);
5594 my $filename = basename($project) . "-$hash.patch";
5597 -type => 'text/plain',
5598 -charset => 'utf-8',
5599 -expires => $expires,
5600 -content_disposition => 'inline; filename="' . "$filename" . '"');
5601 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5602 print "From: " . to_utf8($co{'author'}) . "\n";
5603 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5604 print "Subject: " . to_utf8($co{'title'}) . "\n";
5606 print "X-Git-Tag: $tagname\n" if $tagname;
5607 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5609 foreach my $line (@{$co{'comment'}}) {
5610 print to_utf8($line) . "\n";
5613 } elsif ($format eq 'patch') {
5614 my $filename = basename($project) . "-$hash.patch";
5617 -type => 'text/plain',
5618 -charset => 'utf-8',
5619 -expires => $expires,
5620 -content_disposition => 'inline; filename="' . "$filename" . '"');
5624 if ($format eq 'html') {
5625 my $use_parents = !defined $hash_parent ||
5626 $hash_parent eq '-c' || $hash_parent eq '--cc';
5627 git_difftree_body(\@difftree, $hash,
5628 $use_parents ? @{$co{'parents'}} : $hash_parent);
5631 git_patchset_body($fd, \@difftree, $hash,
5632 $use_parents ? @{$co{'parents'}} : $hash_parent);
5634 print "</div>\n"; # class="page_body"
5637 } elsif ($format eq 'plain') {
5641 or print "Reading git-diff-tree failed\n";
5642 } elsif ($format eq 'patch') {
5646 or print "Reading git-format-patch failed\n";
5650 sub git_commitdiff_plain {
5651 git_commitdiff(-format => 'plain');
5654 # format-patch-style patches
5656 git_commitdiff(-format => 'patch', -single=> 1);
5660 git_commitdiff(-format => 'patch');
5664 if (!defined $hash_base) {
5665 $hash_base = git_get_head_hash($project);
5667 if (!defined $page) {
5671 my %co = parse_commit($hash_base)
5672 or die_error(404, "Unknown commit object");
5674 my $refs = git_get_references();
5675 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5677 my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5678 $file_name, "--full-history")
5679 or die_error(404, "No such file or directory on given branch");
5681 if (!defined $hash && defined $file_name) {
5682 # some commits could have deleted file in question,
5683 # and not have it in tree, but one of them has to have it
5684 for (my $i = 0; $i <= @commitlist; $i++) {
5685 $hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5686 last if defined $hash;
5689 if (defined $hash) {
5690 $ftype = git_get_type($hash);
5692 if (!defined $ftype) {
5693 die_error(500, "Unknown type of object");
5696 my $paging_nav = '';
5699 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5700 file_name=>$file_name)},
5702 $paging_nav .= " ⋅ " .
5703 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5704 -accesskey => "p", -title => "Alt-p"}, "prev");
5706 $paging_nav .= "first";
5707 $paging_nav .= " ⋅ prev";
5710 if ($#commitlist >= 100) {
5712 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5713 -accesskey => "n", -title => "Alt-n"}, "next");
5714 $paging_nav .= " ⋅ $next_link";
5716 $paging_nav .= " ⋅ next";
5720 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5721 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5722 git_print_page_path($file_name, $ftype, $hash_base);
5724 git_history_body(\@commitlist, 0, 99,
5725 $refs, $hash_base, $ftype, $next_link);
5731 gitweb_check_feature('search') or die_error(403, "Search is disabled");
5732 if (!defined $searchtext) {
5733 die_error(400, "Text field is empty");
5735 if (!defined $hash) {
5736 $hash = git_get_head_hash($project);
5738 my %co = parse_commit($hash);
5740 die_error(404, "Unknown commit object");
5742 if (!defined $page) {
5746 $searchtype ||= 'commit';
5747 if ($searchtype eq 'pickaxe') {
5748 # pickaxe may take all resources of your box and run for several minutes
5749 # with every query - so decide by yourself how public you make this feature
5750 gitweb_check_feature('pickaxe')
5751 or die_error(403, "Pickaxe is disabled");
5753 if ($searchtype eq 'grep') {
5754 gitweb_check_feature('grep')
5755 or die_error(403, "Grep is disabled");
5760 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5762 if ($searchtype eq 'commit') {
5763 $greptype = "--grep=";
5764 } elsif ($searchtype eq 'author') {
5765 $greptype = "--author=";
5766 } elsif ($searchtype eq 'committer') {
5767 $greptype = "--committer=";
5769 $greptype .= $searchtext;
5770 my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5771 $greptype, '--regexp-ignore-case',
5772 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5774 my $paging_nav = '';
5777 $cgi->a({-href => href(action=>"search", hash=>$hash,
5778 searchtext=>$searchtext,
5779 searchtype=>$searchtype)},
5781 $paging_nav .= " ⋅ " .
5782 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5783 -accesskey => "p", -title => "Alt-p"}, "prev");
5785 $paging_nav .= "first";
5786 $paging_nav .= " ⋅ prev";
5789 if ($#commitlist >= 100) {
5791 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5792 -accesskey => "n", -title => "Alt-n"}, "next");
5793 $paging_nav .= " ⋅ $next_link";
5795 $paging_nav .= " ⋅ next";
5798 if ($#commitlist >= 100) {
5801 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5802 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5803 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5806 if ($searchtype eq 'pickaxe') {
5807 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5808 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5810 print "<table class=\"pickaxe search\">\n";
5813 open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
5814 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5815 ($search_use_regexp ? '--pickaxe-regex' : ());
5818 while (my $line = <$fd>) {
5822 my %set = parse_difftree_raw_line($line);
5823 if (defined $set{'commit'}) {
5824 # finish previous commit
5827 "<td class=\"link\">" .
5828 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5830 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5836 print "<tr class=\"dark\">\n";
5838 print "<tr class=\"light\">\n";
5841 %co = parse_commit($set{'commit'});
5842 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5843 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5844 "<td><i>$author</i></td>\n" .
5846 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
5847 -class => "list subject"},
5848 chop_and_escape_str($co{'title'}, 50) . "<br/>");
5849 } elsif (defined $set{'to_id'}) {
5850 next if ($set{'to_id'} =~ m/^0{40}$/);
5852 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
5853 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),
5855 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
5861 # finish last commit (warning: repetition!)
5864 "<td class=\"link\">" .
5865 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5867 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5875 if ($searchtype eq 'grep') {
5876 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5877 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5879 print "<table class=\"grep_search\">\n";
5883 open my $fd, "-|", git_cmd(), 'grep', '-n',
5884 $search_use_regexp ? ('-E', '-i') : '-F',
5885 $searchtext, $co{'tree'};
5887 while (my $line = <$fd>) {
5889 my ($file, $lno, $ltext, $binary);
5890 last if ($matches++ > 1000);
5891 if ($line =~ /^Binary file (.+) matches$/) {
5895 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5897 if ($file ne $lastfile) {
5898 $lastfile and print "</td></tr>\n";
5900 print "<tr class=\"dark\">\n";
5902 print "<tr class=\"light\">\n";
5904 print "<td class=\"list\">".
5905 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5906 file_name=>"$file"),
5907 -class => "list"}, esc_path($file));
5908 print "</td><td>\n";
5912 print "<div class=\"binary\">Binary file</div>\n";
5914 $ltext = untabify($ltext);
5915 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5916 $ltext = esc_html($1, -nbsp=>1);
5917 $ltext .= '<span class="match">';
5918 $ltext .= esc_html($2, -nbsp=>1);
5919 $ltext .= '</span>';
5920 $ltext .= esc_html($3, -nbsp=>1);
5922 $ltext = esc_html($ltext, -nbsp=>1);
5924 print "<div class=\"pre\">" .
5925 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5926 file_name=>"$file").'#l'.$lno,
5927 -class => "linenr"}, sprintf('%4i', $lno))
5928 . ' ' . $ltext . "</div>\n";
5932 print "</td></tr>\n";
5933 if ($matches > 1000) {
5934 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5937 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5946 sub git_search_help {
5948 git_print_page_nav('','', $hash,$hash,$hash);
5950 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5951 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5952 the pattern entered is recognized as the POSIX extended
5953 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5956 <dt><b>commit</b></dt>
5957 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5959 my $have_grep = gitweb_check_feature('grep');
5962 <dt><b>grep</b></dt>
5963 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5964 a different one) are searched for the given pattern. On large trees, this search can take
5965 a while and put some strain on the server, so please use it with some consideration. Note that
5966 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5967 case-sensitive.</dd>
5971 <dt><b>author</b></dt>
5972 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5973 <dt><b>committer</b></dt>
5974 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5976 my $have_pickaxe = gitweb_check_feature('pickaxe');
5977 if ($have_pickaxe) {
5979 <dt><b>pickaxe</b></dt>
5980 <dd>All commits that caused the string to appear or disappear from any file (changes that
5981 added, removed or "modified" the string) will be listed. This search can take a while and
5982 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5983 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5991 my $head = git_get_head_hash($project);
5992 if (!defined $hash) {
5995 if (!defined $page) {
5998 my $refs = git_get_references();
6000 my $commit_hash = $hash;
6001 if (defined $hash_parent) {
6002 $commit_hash = "$hash_parent..$hash";
6004 my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
6006 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
6008 if ($#commitlist >= 100) {
6010 $cgi->a({-href => href(-replay=>1, page=>$page+1),
6011 -accesskey => "n", -title => "Alt-n"}, "next");
6013 my $patch_max = gitweb_check_feature('patches');
6015 if ($patch_max < 0 || @commitlist <= $patch_max) {
6016 $paging_nav .= " ⋅ " .
6017 $cgi->a({-href => href(action=>"patches", -replay=>1)},
6023 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
6024 git_print_header_div('summary', $project);
6026 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
6031 ## ......................................................................
6032 ## feeds (RSS, Atom; OPML)
6035 my $format = shift || 'atom';
6036 my $have_blame = gitweb_check_feature('blame');
6038 # Atom: http://www.atomenabled.org/developers/syndication/
6039 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6040 if ($format ne 'rss' && $format ne 'atom') {
6041 die_error(400, "Unknown web feed format");
6044 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6045 my $head = $hash || 'HEAD';
6046 my @commitlist = parse_commits($head, 150, 0, $file_name);
6050 my $content_type = "application/$format+xml";
6051 if (defined $cgi->http('HTTP_ACCEPT') &&
6052 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6053 # browser (feed reader) prefers text/xml
6054 $content_type = 'text/xml';
6056 if (defined($commitlist[0])) {
6057 %latest_commit = %{$commitlist[0]};
6058 my $latest_epoch = $latest_commit{'committer_epoch'};
6059 %latest_date = parse_date($latest_epoch);
6060 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6061 if (defined $if_modified) {
6063 if (eval { require HTTP::Date; 1; }) {
6064 $since = HTTP::Date::str2time($if_modified);
6065 } elsif (eval { require Time::ParseDate; 1; }) {
6066 $since = Time::ParseDate::parsedate($if_modified, GMT => 1);
6068 if (defined $since && $latest_epoch <= $since) {
6070 -type => $content_type,
6071 -charset => 'utf-8',
6072 -last_modified => $latest_date{'rfc2822'},
6073 -status => '304 Not Modified');
6078 -type => $content_type,
6079 -charset => 'utf-8',
6080 -last_modified => $latest_date{'rfc2822'});
6083 -type => $content_type,
6084 -charset => 'utf-8');
6087 # Optimization: skip generating the body if client asks only
6088 # for Last-Modified date.
6089 return if ($cgi->request_method() eq 'HEAD');
6092 my $title = "$site_name - $project/$action";
6093 my $feed_type = 'log';
6094 if (defined $hash) {
6095 $title .= " - '$hash'";
6096 $feed_type = 'branch log';
6097 if (defined $file_name) {
6098 $title .= " :: $file_name";
6099 $feed_type = 'history';
6101 } elsif (defined $file_name) {
6102 $title .= " - $file_name";
6103 $feed_type = 'history';
6105 $title .= " $feed_type";
6106 my $descr = git_get_project_description($project);
6107 if (defined $descr) {
6108 $descr = esc_html($descr);
6110 $descr = "$project " .
6111 ($format eq 'rss' ? 'RSS' : 'Atom') .
6114 my $owner = git_get_project_owner($project);
6115 $owner = esc_html($owner);
6119 if (defined $file_name) {
6120 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
6121 } elsif (defined $hash) {
6122 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
6124 $alt_url = href(-full=>1, action=>"summary");
6126 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
6127 if ($format eq 'rss') {
6129 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6132 print "<title>$title</title>\n" .
6133 "<link>$alt_url</link>\n" .
6134 "<description>$descr</description>\n" .
6135 "<language>en</language>\n" .
6136 # project owner is responsible for 'editorial' content
6137 "<managingEditor>$owner</managingEditor>\n";
6138 if (defined $logo || defined $favicon) {
6139 # prefer the logo to the favicon, since RSS
6140 # doesn't allow both
6141 my $img = esc_url($logo || $favicon);
6143 "<url>$img</url>\n" .
6144 "<title>$title</title>\n" .
6145 "<link>$alt_url</link>\n" .
6149 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6150 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6152 print "<generator>gitweb v.$version/$git_version</generator>\n";
6153 } elsif ($format eq 'atom') {
6155 <feed xmlns="http://www.w3.org/2005/Atom">
6157 print "<title>$title</title>\n" .
6158 "<subtitle>$descr</subtitle>\n" .
6159 '<link rel="alternate" type="text/html" href="' .
6160 $alt_url . '" />' . "\n" .
6161 '<link rel="self" type="' . $content_type . '" href="' .
6162 $cgi->self_url() . '" />' . "\n" .
6163 "<id>" . href(-full=>1) . "</id>\n" .
6164 # use project owner for feed author
6165 "<author><name>$owner</name></author>\n";
6166 if (defined $favicon) {
6167 print "<icon>" . esc_url($favicon) . "</icon>\n";
6169 if (defined $logo_url) {
6170 # not twice as wide as tall: 72 x 27 pixels
6171 print "<logo>" . esc_url($logo) . "</logo>\n";
6173 if (! %latest_date) {
6174 # dummy date to keep the feed valid until commits trickle in:
6175 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6177 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6179 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6183 for (my $i = 0; $i <= $#commitlist; $i++) {
6184 my %co = %{$commitlist[$i]};
6185 my $commit = $co{'id'};
6186 # we read 150, we always show 30 and the ones more recent than 48 hours
6187 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6190 my %cd = parse_date($co{'author_epoch'});
6192 # get list of changed files
6193 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
6194 $co{'parent'} || "--root",
6195 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6197 my @difftree = map { chomp; $_ } <$fd>;
6201 # print element (entry, item)
6202 my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
6203 if ($format eq 'rss') {
6205 "<title>" . esc_html($co{'title'}) . "</title>\n" .
6206 "<author>" . esc_html($co{'author'}) . "</author>\n" .
6207 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6208 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6209 "<link>$co_url</link>\n" .
6210 "<description>" . esc_html($co{'title'}) . "</description>\n" .
6211 "<content:encoded>" .
6213 } elsif ($format eq 'atom') {
6215 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
6216 "<updated>$cd{'iso-8601'}</updated>\n" .
6218 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
6219 if ($co{'author_email'}) {
6220 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
6222 print "</author>\n" .
6223 # use committer for contributor
6225 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
6226 if ($co{'committer_email'}) {
6227 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
6229 print "</contributor>\n" .
6230 "<published>$cd{'iso-8601'}</published>\n" .
6231 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6232 "<id>$co_url</id>\n" .
6233 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
6234 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6236 my $comment = $co{'comment'};
6238 foreach my $line (@$comment) {
6239 $line = esc_html($line);
6242 print "</pre><ul>\n";
6243 foreach my $difftree_line (@difftree) {
6244 my %difftree = parse_difftree_raw_line($difftree_line);
6245 next if !$difftree{'from_id'};
6247 my $file = $difftree{'file'} || $difftree{'to_file'};
6251 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
6252 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
6253 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
6254 file_name=>$file, file_parent=>$difftree{'from_file'}),
6255 -title => "diff"}, 'D');
6257 print $cgi->a({-href => href(-full=>1, action=>"blame",
6258 file_name=>$file, hash_base=>$commit),
6259 -title => "blame"}, 'B');
6261 # if this is not a feed of a file history
6262 if (!defined $file_name || $file_name ne $file) {
6263 print $cgi->a({-href => href(-full=>1, action=>"history",
6264 file_name=>$file, hash=>$commit),
6265 -title => "history"}, 'H');
6267 $file = esc_path($file);
6271 if ($format eq 'rss') {
6272 print "</ul>]]>\n" .
6273 "</content:encoded>\n" .
6275 } elsif ($format eq 'atom') {
6276 print "</ul>\n</div>\n" .
6283 if ($format eq 'rss') {
6284 print "</channel>\n</rss>\n";
6285 } elsif ($format eq 'atom') {
6299 my @list = git_get_projects_list();
6302 -type => 'text/xml',
6303 -charset => 'utf-8',
6304 -content_disposition => 'inline; filename="opml.xml"');
6307 <?xml version="1.0" encoding="utf-8"?>
6308 <opml version="1.0">
6310 <title>$site_name OPML Export</title>
6313 <outline text="git RSS feeds">
6316 foreach my $pr (@list) {
6318 my $head = git_get_head_hash($proj{'path'});
6319 if (!defined $head) {
6322 $git_dir = "$projectroot/$proj{'path'}";
6323 my %co = parse_commit($head);
6328 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
6329 my $rss = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
6330 my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
6331 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";