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-scm.com/";
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)
164 # 'disabled' => boolean (optional)}
167 'display' => 'tar.gz',
168 'type' => 'application/x-gzip',
169 'suffix' => '.tar.gz',
171 'compressor' => ['gzip']},
174 'display' => 'tar.bz2',
175 'type' => 'application/x-bzip2',
176 'suffix' => '.tar.bz2',
178 'compressor' => ['bzip2']},
181 'display' => 'tar.xz',
182 'type' => 'application/x-xz',
183 'suffix' => '.tar.xz',
185 'compressor' => ['xz'],
190 'type' => 'application/x-zip',
195 # Aliases so we understand old gitweb.snapshot values in repository
197 our %known_snapshot_format_aliases = (
202 # backward compatibility: legacy gitweb config support
203 'x-gzip' => undef, 'gz' => undef,
204 'x-bzip2' => undef, 'bz2' => undef,
205 'x-zip' => undef, '' => undef,
208 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
209 # are changed, it may be appropriate to change these values too via
216 # You define site-wide feature defaults here; override them with
217 # $GITWEB_CONFIG as necessary.
220 # 'sub' => feature-sub (subroutine),
221 # 'override' => allow-override (boolean),
222 # 'default' => [ default options...] (array reference)}
224 # if feature is overridable (it means that allow-override has true value),
225 # then feature-sub will be called with default options as parameters;
226 # return value of feature-sub indicates if to enable specified feature
228 # if there is no 'sub' key (no feature-sub), then feature cannot be
231 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
232 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
235 # Enable the 'blame' blob view, showing the last commit that modified
236 # each line in the file. This can be very CPU-intensive.
238 # To enable system wide have in $GITWEB_CONFIG
239 # $feature{'blame'}{'default'} = [1];
240 # To have project specific config enable override in $GITWEB_CONFIG
241 # $feature{'blame'}{'override'} = 1;
242 # and in project config gitweb.blame = 0|1;
244 'sub' => sub { feature_bool('blame', @_) },
248 # Enable the 'snapshot' link, providing a compressed archive of any
249 # tree. This can potentially generate high traffic if you have large
252 # Value is a list of formats defined in %known_snapshot_formats that
254 # To disable system wide have in $GITWEB_CONFIG
255 # $feature{'snapshot'}{'default'} = [];
256 # To have project specific config enable override in $GITWEB_CONFIG
257 # $feature{'snapshot'}{'override'} = 1;
258 # and in project config, a comma-separated list of formats or "none"
259 # to disable. Example: gitweb.snapshot = tbz2,zip;
261 'sub' => \&feature_snapshot,
263 'default' => ['tgz']},
265 # Enable text search, which will list the commits which match author,
266 # committer or commit text to a given string. Enabled by default.
267 # Project specific override is not supported.
272 # Enable grep search, which will list the files in currently selected
273 # tree containing the given string. Enabled by default. This can be
274 # potentially CPU-intensive, of course.
276 # To enable system wide have in $GITWEB_CONFIG
277 # $feature{'grep'}{'default'} = [1];
278 # To have project specific config enable override in $GITWEB_CONFIG
279 # $feature{'grep'}{'override'} = 1;
280 # and in project config gitweb.grep = 0|1;
282 'sub' => sub { feature_bool('grep', @_) },
286 # Enable the pickaxe search, which will list the commits that modified
287 # a given string in a file. This can be practical and quite faster
288 # alternative to 'blame', but still potentially CPU-intensive.
290 # To enable system wide have in $GITWEB_CONFIG
291 # $feature{'pickaxe'}{'default'} = [1];
292 # To have project specific config enable override in $GITWEB_CONFIG
293 # $feature{'pickaxe'}{'override'} = 1;
294 # and in project config gitweb.pickaxe = 0|1;
296 'sub' => sub { feature_bool('pickaxe', @_) },
300 # Make gitweb use an alternative format of the URLs which can be
301 # more readable and natural-looking: project name is embedded
302 # directly in the path and the query string contains other
303 # auxiliary information. All gitweb installations recognize
304 # URL in either format; this configures in which formats gitweb
307 # To enable system wide have in $GITWEB_CONFIG
308 # $feature{'pathinfo'}{'default'} = [1];
309 # Project specific override is not supported.
311 # Note that you will need to change the default location of CSS,
312 # favicon, logo and possibly other files to an absolute URL. Also,
313 # if gitweb.cgi serves as your indexfile, you will need to force
314 # $my_uri to contain the script name in your $GITWEB_CONFIG.
319 # Make gitweb consider projects in project root subdirectories
320 # to be forks of existing projects. Given project $projname.git,
321 # projects matching $projname/*.git will not be shown in the main
322 # projects list, instead a '+' mark will be added to $projname
323 # there and a 'forks' view will be enabled for the project, listing
324 # all the forks. If project list is taken from a file, forks have
325 # to be listed after the main project.
327 # To enable system wide have in $GITWEB_CONFIG
328 # $feature{'forks'}{'default'} = [1];
329 # Project specific override is not supported.
334 # Insert custom links to the action bar of all project pages.
335 # This enables you mainly to link to third-party scripts integrating
336 # into gitweb; e.g. git-browser for graphical history representation
337 # or custom web-based repository administration interface.
339 # The 'default' value consists of a list of triplets in the form
340 # (label, link, position) where position is the label after which
341 # to insert the link and link is a format string where %n expands
342 # to the project name, %f to the project path within the filesystem,
343 # %h to the current hash (h gitweb parameter) and %b to the current
344 # hash base (hb gitweb parameter); %% expands to %.
346 # To enable system wide have in $GITWEB_CONFIG e.g.
347 # $feature{'actions'}{'default'} = [('graphiclog',
348 # '/git-browser/by-commit.html?r=%n', 'summary')];
349 # Project specific override is not supported.
354 # Allow gitweb scan project content tags described in ctags/
355 # of project repository, and display the popular Web 2.0-ish
356 # "tag cloud" near the project list. Note that this is something
357 # COMPLETELY different from the normal Git tags.
359 # gitweb by itself can show existing tags, but it does not handle
360 # tagging itself; you need an external application for that.
361 # For an example script, check Girocco's cgi/tagproj.cgi.
362 # You may want to install the HTML::TagCloud Perl module to get
363 # a pretty tag cloud instead of just a list of tags.
365 # To enable system wide have in $GITWEB_CONFIG
366 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
367 # Project specific override is not supported.
372 # The maximum number of patches in a patchset generated in patch
373 # view. Set this to 0 or undef to disable patch view, or to a
374 # negative number to remove any limit.
376 # To disable system wide have in $GITWEB_CONFIG
377 # $feature{'patches'}{'default'} = [0];
378 # To have project specific config enable override in $GITWEB_CONFIG
379 # $feature{'patches'}{'override'} = 1;
380 # and in project config gitweb.patches = 0|n;
381 # where n is the maximum number of patches allowed in a patchset.
383 'sub' => \&feature_patches,
387 # Avatar support. When this feature is enabled, views such as
388 # shortlog or commit will display an avatar associated with
389 # the email of the committer(s) and/or author(s).
391 # Currently available providers are gravatar and picon.
392 # If an unknown provider is specified, the feature is disabled.
394 # Gravatar depends on Digest::MD5.
395 # Picon currently relies on the indiana.edu database.
397 # To enable system wide have in $GITWEB_CONFIG
398 # $feature{'avatar'}{'default'} = ['<provider>'];
399 # where <provider> is either gravatar or picon.
400 # To have project specific config enable override in $GITWEB_CONFIG
401 # $feature{'avatar'}{'override'} = 1;
402 # and in project config gitweb.avatar = <provider>;
404 'sub' => \&feature_avatar,
409 sub gitweb_get_feature {
411 return unless exists $feature{$name};
412 my ($sub, $override, @defaults) = (
413 $feature{$name}{'sub'},
414 $feature{$name}{'override'},
415 @{$feature{$name}{'default'}});
416 if (!$override) { return @defaults; }
418 warn "feature $name is not overrideable";
421 return $sub->(@defaults);
424 # A wrapper to check if a given feature is enabled.
425 # With this, you can say
427 # my $bool_feat = gitweb_check_feature('bool_feat');
428 # gitweb_check_feature('bool_feat') or somecode;
432 # my ($bool_feat) = gitweb_get_feature('bool_feat');
433 # (gitweb_get_feature('bool_feat'))[0] or somecode;
435 sub gitweb_check_feature {
436 return (gitweb_get_feature(@_))[0];
442 my ($val) = git_get_project_config($key, '--bool');
446 } elsif ($val eq 'true') {
448 } elsif ($val eq 'false') {
453 sub feature_snapshot {
456 my ($val) = git_get_project_config('snapshot');
459 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
465 sub feature_patches {
466 my @val = (git_get_project_config('patches', '--int'));
476 my @val = (git_get_project_config('avatar'));
478 return @val ? @val : @_;
481 # checking HEAD file with -e is fragile if the repository was
482 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
484 sub check_head_link {
486 my $headfile = "$dir/HEAD";
487 return ((-e $headfile) ||
488 (-l $headfile && readlink($headfile) =~ /^refs\/heads\//));
491 sub check_export_ok {
493 return (check_head_link($dir) &&
494 (!$export_ok || -e "$dir/$export_ok") &&
495 (!$export_auth_hook || $export_auth_hook->($dir)));
498 # process alternate names for backward compatibility
499 # filter out unsupported (unknown) snapshot formats
500 sub filter_snapshot_fmts {
504 exists $known_snapshot_format_aliases{$_} ?
505 $known_snapshot_format_aliases{$_} : $_} @fmts;
507 exists $known_snapshot_formats{$_} &&
508 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
511 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
512 if (-e $GITWEB_CONFIG) {
515 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
516 do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
519 # version of the core git binary
520 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
522 $projects_list ||= $projectroot;
524 # ======================================================================
525 # input validation and dispatch
527 # input parameters can be collected from a variety of sources (presently, CGI
528 # and PATH_INFO), so we define an %input_params hash that collects them all
529 # together during validation: this allows subsequent uses (e.g. href()) to be
530 # agnostic of the parameter origin
532 our %input_params = ();
534 # input parameters are stored with the long parameter name as key. This will
535 # also be used in the href subroutine to convert parameters to their CGI
536 # equivalent, and since the href() usage is the most frequent one, we store
537 # the name -> CGI key mapping here, instead of the reverse.
539 # XXX: Warning: If you touch this, check the search form for updating,
542 our @cgi_param_mapping = (
550 hash_parent_base => "hpb",
555 snapshot_format => "sf",
556 extra_options => "opt",
557 search_use_regexp => "sr",
559 our %cgi_param_mapping = @cgi_param_mapping;
561 # we will also need to know the possible actions, for validation
563 "blame" => \&git_blame,
564 "blobdiff" => \&git_blobdiff,
565 "blobdiff_plain" => \&git_blobdiff_plain,
566 "blob" => \&git_blob,
567 "blob_plain" => \&git_blob_plain,
568 "commitdiff" => \&git_commitdiff,
569 "commitdiff_plain" => \&git_commitdiff_plain,
570 "commit" => \&git_commit,
571 "forks" => \&git_forks,
572 "heads" => \&git_heads,
573 "history" => \&git_history,
575 "patch" => \&git_patch,
576 "patches" => \&git_patches,
578 "atom" => \&git_atom,
579 "search" => \&git_search,
580 "search_help" => \&git_search_help,
581 "shortlog" => \&git_shortlog,
582 "summary" => \&git_summary,
584 "tags" => \&git_tags,
585 "tree" => \&git_tree,
586 "snapshot" => \&git_snapshot,
587 "object" => \&git_object,
588 # those below don't need $project
589 "opml" => \&git_opml,
590 "project_list" => \&git_project_list,
591 "project_index" => \&git_project_index,
594 # finally, we have the hash of allowed extra_options for the commands that
596 our %allowed_options = (
597 "--no-merges" => [ qw(rss atom log shortlog history) ],
600 # fill %input_params with the CGI parameters. All values except for 'opt'
601 # should be single values, but opt can be an array. We should probably
602 # build an array of parameters that can be multi-valued, but since for the time
603 # being it's only this one, we just single it out
604 while (my ($name, $symbol) = each %cgi_param_mapping) {
605 if ($symbol eq 'opt') {
606 $input_params{$name} = [ $cgi->param($symbol) ];
608 $input_params{$name} = $cgi->param($symbol);
612 # now read PATH_INFO and update the parameter list for missing parameters
613 sub evaluate_path_info {
614 return if defined $input_params{'project'};
615 return if !$path_info;
616 $path_info =~ s,^/+,,;
617 return if !$path_info;
619 # find which part of PATH_INFO is project
620 my $project = $path_info;
622 while ($project && !check_head_link("$projectroot/$project")) {
623 $project =~ s,/*[^/]*$,,;
625 return unless $project;
626 $input_params{'project'} = $project;
628 # do not change any parameters if an action is given using the query string
629 return if $input_params{'action'};
630 $path_info =~ s,^\Q$project\E/*,,;
632 # next, check if we have an action
633 my $action = $path_info;
635 if (exists $actions{$action}) {
636 $path_info =~ s,^$action/*,,;
637 $input_params{'action'} = $action;
640 # list of actions that want hash_base instead of hash, but can have no
641 # pathname (f) parameter
648 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
649 my ($parentrefname, $parentpathname, $refname, $pathname) =
650 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
652 # first, analyze the 'current' part
653 if (defined $pathname) {
654 # we got "branch:filename" or "branch:dir/"
655 # we could use git_get_type(branch:pathname), but:
656 # - it needs $git_dir
657 # - it does a git() call
658 # - the convention of terminating directories with a slash
659 # makes it superfluous
660 # - embedding the action in the PATH_INFO would make it even
662 $pathname =~ s,^/+,,;
663 if (!$pathname || substr($pathname, -1) eq "/") {
664 $input_params{'action'} ||= "tree";
667 # the default action depends on whether we had parent info
669 if ($parentrefname) {
670 $input_params{'action'} ||= "blobdiff_plain";
672 $input_params{'action'} ||= "blob_plain";
675 $input_params{'hash_base'} ||= $refname;
676 $input_params{'file_name'} ||= $pathname;
677 } elsif (defined $refname) {
678 # we got "branch". In this case we have to choose if we have to
679 # set hash or hash_base.
681 # Most of the actions without a pathname only want hash to be
682 # set, except for the ones specified in @wants_base that want
683 # hash_base instead. It should also be noted that hand-crafted
684 # links having 'history' as an action and no pathname or hash
685 # set will fail, but that happens regardless of PATH_INFO.
686 $input_params{'action'} ||= "shortlog";
687 if (grep { $_ eq $input_params{'action'} } @wants_base) {
688 $input_params{'hash_base'} ||= $refname;
690 $input_params{'hash'} ||= $refname;
694 # next, handle the 'parent' part, if present
695 if (defined $parentrefname) {
696 # a missing pathspec defaults to the 'current' filename, allowing e.g.
697 # someproject/blobdiff/oldrev..newrev:/filename
698 if ($parentpathname) {
699 $parentpathname =~ s,^/+,,;
700 $parentpathname =~ s,/$,,;
701 $input_params{'file_parent'} ||= $parentpathname;
703 $input_params{'file_parent'} ||= $input_params{'file_name'};
705 # we assume that hash_parent_base is wanted if a path was specified,
706 # or if the action wants hash_base instead of hash
707 if (defined $input_params{'file_parent'} ||
708 grep { $_ eq $input_params{'action'} } @wants_base) {
709 $input_params{'hash_parent_base'} ||= $parentrefname;
711 $input_params{'hash_parent'} ||= $parentrefname;
715 # for the snapshot action, we allow URLs in the form
716 # $project/snapshot/$hash.ext
717 # where .ext determines the snapshot and gets removed from the
718 # passed $refname to provide the $hash.
720 # To be able to tell that $refname includes the format extension, we
721 # require the following two conditions to be satisfied:
722 # - the hash input parameter MUST have been set from the $refname part
723 # of the URL (i.e. they must be equal)
724 # - the snapshot format MUST NOT have been defined already (e.g. from
726 # It's also useless to try any matching unless $refname has a dot,
727 # so we check for that too
728 if (defined $input_params{'action'} &&
729 $input_params{'action'} eq 'snapshot' &&
730 defined $refname && index($refname, '.') != -1 &&
731 $refname eq $input_params{'hash'} &&
732 !defined $input_params{'snapshot_format'}) {
733 # We loop over the known snapshot formats, checking for
734 # extensions. Allowed extensions are both the defined suffix
735 # (which includes the initial dot already) and the snapshot
736 # format key itself, with a prepended dot
737 while (my ($fmt, $opt) = each %known_snapshot_formats) {
739 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
743 # a valid suffix was found, so set the snapshot format
744 # and reset the hash parameter
745 $input_params{'snapshot_format'} = $fmt;
746 $input_params{'hash'} = $hash;
747 # we also set the format suffix to the one requested
748 # in the URL: this way a request for e.g. .tgz returns
749 # a .tgz instead of a .tar.gz
750 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
755 evaluate_path_info();
757 our $action = $input_params{'action'};
758 if (defined $action) {
759 if (!validate_action($action)) {
760 die_error(400, "Invalid action parameter");
764 # parameters which are pathnames
765 our $project = $input_params{'project'};
766 if (defined $project) {
767 if (!validate_project($project)) {
769 die_error(404, "No such project");
773 our $file_name = $input_params{'file_name'};
774 if (defined $file_name) {
775 if (!validate_pathname($file_name)) {
776 die_error(400, "Invalid file parameter");
780 our $file_parent = $input_params{'file_parent'};
781 if (defined $file_parent) {
782 if (!validate_pathname($file_parent)) {
783 die_error(400, "Invalid file parent parameter");
787 # parameters which are refnames
788 our $hash = $input_params{'hash'};
790 if (!validate_refname($hash)) {
791 die_error(400, "Invalid hash parameter");
795 our $hash_parent = $input_params{'hash_parent'};
796 if (defined $hash_parent) {
797 if (!validate_refname($hash_parent)) {
798 die_error(400, "Invalid hash parent parameter");
802 our $hash_base = $input_params{'hash_base'};
803 if (defined $hash_base) {
804 if (!validate_refname($hash_base)) {
805 die_error(400, "Invalid hash base parameter");
809 our @extra_options = @{$input_params{'extra_options'}};
810 # @extra_options is always defined, since it can only be (currently) set from
811 # CGI, and $cgi->param() returns the empty array in array context if the param
813 foreach my $opt (@extra_options) {
814 if (not exists $allowed_options{$opt}) {
815 die_error(400, "Invalid option parameter");
817 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
818 die_error(400, "Invalid option parameter for this action");
822 our $hash_parent_base = $input_params{'hash_parent_base'};
823 if (defined $hash_parent_base) {
824 if (!validate_refname($hash_parent_base)) {
825 die_error(400, "Invalid hash parent base parameter");
830 our $page = $input_params{'page'};
832 if ($page =~ m/[^0-9]/) {
833 die_error(400, "Invalid page parameter");
837 our $searchtype = $input_params{'searchtype'};
838 if (defined $searchtype) {
839 if ($searchtype =~ m/[^a-z]/) {
840 die_error(400, "Invalid searchtype parameter");
844 our $search_use_regexp = $input_params{'search_use_regexp'};
846 our $searchtext = $input_params{'searchtext'};
848 if (defined $searchtext) {
849 if (length($searchtext) < 2) {
850 die_error(403, "At least two characters are required for search parameter");
852 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
855 # path to the current git repository
857 $git_dir = "$projectroot/$project" if $project;
859 # list of supported snapshot formats
860 our @snapshot_fmts = gitweb_get_feature('snapshot');
861 @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
863 # check that the avatar feature is set to a known provider name,
864 # and for each provider check if the dependencies are satisfied.
865 # if the provider name is invalid or the dependencies are not met,
866 # reset $git_avatar to the empty string.
867 our ($git_avatar) = gitweb_get_feature('avatar');
868 if ($git_avatar eq 'gravatar') {
869 $git_avatar = '' unless (eval { require Digest::MD5; 1; });
870 } elsif ($git_avatar eq 'picon') {
877 if (!defined $action) {
879 $action = git_get_type($hash);
880 } elsif (defined $hash_base && defined $file_name) {
881 $action = git_get_type("$hash_base:$file_name");
882 } elsif (defined $project) {
885 $action = 'project_list';
888 if (!defined($actions{$action})) {
889 die_error(400, "Unknown action");
891 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
893 die_error(400, "Project needed");
895 $actions{$action}->();
898 ## ======================================================================
903 # default is to use -absolute url() i.e. $my_uri
904 my $href = $params{-full} ? $my_url : $my_uri;
906 $params{'project'} = $project unless exists $params{'project'};
908 if ($params{-replay}) {
909 while (my ($name, $symbol) = each %cgi_param_mapping) {
910 if (!exists $params{$name}) {
911 $params{$name} = $input_params{$name};
916 my $use_pathinfo = gitweb_check_feature('pathinfo');
917 if ($use_pathinfo and defined $params{'project'}) {
918 # try to put as many parameters as possible in PATH_INFO:
921 # - hash_parent or hash_parent_base:/file_parent
922 # - hash or hash_base:/filename
923 # - the snapshot_format as an appropriate suffix
925 # When the script is the root DirectoryIndex for the domain,
926 # $href here would be something like http://gitweb.example.com/
927 # Thus, we strip any trailing / from $href, to spare us double
928 # slashes in the final URL
931 # Then add the project name, if present
932 $href .= "/".esc_url($params{'project'});
933 delete $params{'project'};
935 # since we destructively absorb parameters, we keep this
936 # boolean that remembers if we're handling a snapshot
937 my $is_snapshot = $params{'action'} eq 'snapshot';
939 # Summary just uses the project path URL, any other action is
941 if (defined $params{'action'}) {
942 $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
943 delete $params{'action'};
946 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
947 # stripping nonexistent or useless pieces
948 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
949 || $params{'hash_parent'} || $params{'hash'});
950 if (defined $params{'hash_base'}) {
951 if (defined $params{'hash_parent_base'}) {
952 $href .= esc_url($params{'hash_parent_base'});
953 # skip the file_parent if it's the same as the file_name
954 if (defined $params{'file_parent'}) {
955 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
956 delete $params{'file_parent'};
957 } elsif ($params{'file_parent'} !~ /\.\./) {
958 $href .= ":/".esc_url($params{'file_parent'});
959 delete $params{'file_parent'};
963 delete $params{'hash_parent'};
964 delete $params{'hash_parent_base'};
965 } elsif (defined $params{'hash_parent'}) {
966 $href .= esc_url($params{'hash_parent'}). "..";
967 delete $params{'hash_parent'};
970 $href .= esc_url($params{'hash_base'});
971 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
972 $href .= ":/".esc_url($params{'file_name'});
973 delete $params{'file_name'};
975 delete $params{'hash'};
976 delete $params{'hash_base'};
977 } elsif (defined $params{'hash'}) {
978 $href .= esc_url($params{'hash'});
979 delete $params{'hash'};
982 # If the action was a snapshot, we can absorb the
983 # snapshot_format parameter too
985 my $fmt = $params{'snapshot_format'};
986 # snapshot_format should always be defined when href()
987 # is called, but just in case some code forgets, we
988 # fall back to the default
989 $fmt ||= $snapshot_fmts[0];
990 $href .= $known_snapshot_formats{$fmt}{'suffix'};
991 delete $params{'snapshot_format'};
995 # now encode the parameters explicitly
997 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
998 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
999 if (defined $params{$name}) {
1000 if (ref($params{$name}) eq "ARRAY") {
1001 foreach my $par (@{$params{$name}}) {
1002 push @result, $symbol . "=" . esc_param($par);
1005 push @result, $symbol . "=" . esc_param($params{$name});
1009 $href .= "?" . join(';', @result) if scalar @result;
1015 ## ======================================================================
1016 ## validation, quoting/unquoting and escaping
1018 sub validate_action {
1019 my $input = shift || return undef;
1020 return undef unless exists $actions{$input};
1024 sub validate_project {
1025 my $input = shift || return undef;
1026 if (!validate_pathname($input) ||
1027 !(-d "$projectroot/$input") ||
1028 !check_export_ok("$projectroot/$input") ||
1029 ($strict_export && !project_in_list($input))) {
1036 sub validate_pathname {
1037 my $input = shift || return undef;
1039 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1040 # at the beginning, at the end, and between slashes.
1041 # also this catches doubled slashes
1042 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1045 # no null characters
1046 if ($input =~ m!\0!) {
1052 sub validate_refname {
1053 my $input = shift || return undef;
1055 # textual hashes are O.K.
1056 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1059 # it must be correct pathname
1060 $input = validate_pathname($input)
1062 # restrictions on ref name according to git-check-ref-format
1063 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1069 # decode sequences of octets in utf8 into Perl's internal form,
1070 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1071 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1074 if (utf8::valid($str)) {
1078 return decode($fallback_encoding, $str, Encode::FB_DEFAULT);
1082 # quote unsafe chars, but keep the slash, even when it's not
1083 # correct, but quoted slashes look too horrible in bookmarks
1086 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
1092 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1095 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
1101 # replace invalid utf8 character with SUBSTITUTION sequence
1106 $str = to_utf8($str);
1107 $str = $cgi->escapeHTML($str);
1108 if ($opts{'-nbsp'}) {
1109 $str =~ s/ / /g;
1111 $str =~ s|([[:cntrl:]])|(($1 ne "\t") ? quot_cec($1) : $1)|eg;
1115 # quote control characters and escape filename to HTML
1120 $str = to_utf8($str);
1121 $str = $cgi->escapeHTML($str);
1122 if ($opts{'-nbsp'}) {
1123 $str =~ s/ / /g;
1125 $str =~ s|([[:cntrl:]])|quot_cec($1)|eg;
1129 # Make control characters "printable", using character escape codes (CEC)
1133 my %es = ( # character escape codes, aka escape sequences
1134 "\t" => '\t', # tab (HT)
1135 "\n" => '\n', # line feed (LF)
1136 "\r" => '\r', # carrige return (CR)
1137 "\f" => '\f', # form feed (FF)
1138 "\b" => '\b', # backspace (BS)
1139 "\a" => '\a', # alarm (bell) (BEL)
1140 "\e" => '\e', # escape (ESC)
1141 "\013" => '\v', # vertical tab (VT)
1142 "\000" => '\0', # nul character (NUL)
1144 my $chr = ( (exists $es{$cntrl})
1146 : sprintf('\%2x', ord($cntrl)) );
1147 if ($opts{-nohtml}) {
1150 return "<span class=\"cntrl\">$chr</span>";
1154 # Alternatively use unicode control pictures codepoints,
1155 # Unicode "printable representation" (PR)
1160 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1161 if ($opts{-nohtml}) {
1164 return "<span class=\"cntrl\">$chr</span>";
1168 # git may return quoted and escaped filenames
1174 my %es = ( # character escape codes, aka escape sequences
1175 't' => "\t", # tab (HT, TAB)
1176 'n' => "\n", # newline (NL)
1177 'r' => "\r", # return (CR)
1178 'f' => "\f", # form feed (FF)
1179 'b' => "\b", # backspace (BS)
1180 'a' => "\a", # alarm (bell) (BEL)
1181 'e' => "\e", # escape (ESC)
1182 'v' => "\013", # vertical tab (VT)
1185 if ($seq =~ m/^[0-7]{1,3}$/) {
1186 # octal char sequence
1187 return chr(oct($seq));
1188 } elsif (exists $es{$seq}) {
1189 # C escape sequence, aka character escape code
1192 # quoted ordinary character
1196 if ($str =~ m/^"(.*)"$/) {
1199 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1204 # escape tabs (convert tabs to spaces)
1208 while ((my $pos = index($line, "\t")) != -1) {
1209 if (my $count = (8 - ($pos % 8))) {
1210 my $spaces = ' ' x $count;
1211 $line =~ s/\t/$spaces/;
1218 sub project_in_list {
1219 my $project = shift;
1220 my @list = git_get_projects_list();
1221 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1224 ## ----------------------------------------------------------------------
1225 ## HTML aware string manipulation
1227 # Try to chop given string on a word boundary between position
1228 # $len and $len+$add_len. If there is no word boundary there,
1229 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1230 # (marking chopped part) would be longer than given string.
1234 my $add_len = shift || 10;
1235 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1237 # Make sure perl knows it is utf8 encoded so we don't
1238 # cut in the middle of a utf8 multibyte char.
1239 $str = to_utf8($str);
1241 # allow only $len chars, but don't cut a word if it would fit in $add_len
1242 # if it doesn't fit, cut it if it's still longer than the dots we would add
1243 # remove chopped character entities entirely
1245 # when chopping in the middle, distribute $len into left and right part
1246 # return early if chopping wouldn't make string shorter
1247 if ($where eq 'center') {
1248 return $str if ($len + 5 >= length($str)); # filler is length 5
1251 return $str if ($len + 4 >= length($str)); # filler is length 4
1254 # regexps: ending and beginning with word part up to $add_len
1255 my $endre = qr/.{$len}\w{0,$add_len}/;
1256 my $begre = qr/\w{0,$add_len}.{$len}/;
1258 if ($where eq 'left') {
1259 $str =~ m/^(.*?)($begre)$/;
1260 my ($lead, $body) = ($1, $2);
1261 if (length($lead) > 4) {
1262 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1265 return "$lead$body";
1267 } elsif ($where eq 'center') {
1268 $str =~ m/^($endre)(.*)$/;
1269 my ($left, $str) = ($1, $2);
1270 $str =~ m/^(.*?)($begre)$/;
1271 my ($mid, $right) = ($1, $2);
1272 if (length($mid) > 5) {
1273 $left =~ s/&[^;]*$//;
1274 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1277 return "$left$mid$right";
1280 $str =~ m/^($endre)(.*)$/;
1283 if (length($tail) > 4) {
1284 $body =~ s/&[^;]*$//;
1287 return "$body$tail";
1291 # takes the same arguments as chop_str, but also wraps a <span> around the
1292 # result with a title attribute if it does get chopped. Additionally, the
1293 # string is HTML-escaped.
1294 sub chop_and_escape_str {
1297 my $chopped = chop_str(@_);
1298 if ($chopped eq $str) {
1299 return esc_html($chopped);
1301 $str =~ s/[[:cntrl:]]/?/g;
1302 return $cgi->span({-title=>$str}, esc_html($chopped));
1306 ## ----------------------------------------------------------------------
1307 ## functions returning short strings
1309 # CSS class for given age value (in seconds)
1313 if (!defined $age) {
1315 } elsif ($age < 60*60*2) {
1317 } elsif ($age < 60*60*24*2) {
1324 # convert age in seconds to "nn units ago" string
1329 if ($age > 60*60*24*365*2) {
1330 $age_str = (int $age/60/60/24/365);
1331 $age_str .= " years ago";
1332 } elsif ($age > 60*60*24*(365/12)*2) {
1333 $age_str = int $age/60/60/24/(365/12);
1334 $age_str .= " months ago";
1335 } elsif ($age > 60*60*24*7*2) {
1336 $age_str = int $age/60/60/24/7;
1337 $age_str .= " weeks ago";
1338 } elsif ($age > 60*60*24*2) {
1339 $age_str = int $age/60/60/24;
1340 $age_str .= " days ago";
1341 } elsif ($age > 60*60*2) {
1342 $age_str = int $age/60/60;
1343 $age_str .= " hours ago";
1344 } elsif ($age > 60*2) {
1345 $age_str = int $age/60;
1346 $age_str .= " min ago";
1347 } elsif ($age > 2) {
1348 $age_str = int $age;
1349 $age_str .= " sec ago";
1351 $age_str .= " right now";
1357 S_IFINVALID => 0030000,
1358 S_IFGITLINK => 0160000,
1361 # submodule/subproject, a commit object reference
1365 return (($mode & S_IFMT) == S_IFGITLINK)
1368 # convert file mode in octal to symbolic file mode string
1370 my $mode = oct shift;
1372 if (S_ISGITLINK($mode)) {
1373 return 'm---------';
1374 } elsif (S_ISDIR($mode & S_IFMT)) {
1375 return 'drwxr-xr-x';
1376 } elsif (S_ISLNK($mode)) {
1377 return 'lrwxrwxrwx';
1378 } elsif (S_ISREG($mode)) {
1379 # git cares only about the executable bit
1380 if ($mode & S_IXUSR) {
1381 return '-rwxr-xr-x';
1383 return '-rw-r--r--';
1386 return '----------';
1390 # convert file mode in octal to file type string
1394 if ($mode !~ m/^[0-7]+$/) {
1400 if (S_ISGITLINK($mode)) {
1402 } elsif (S_ISDIR($mode & S_IFMT)) {
1404 } elsif (S_ISLNK($mode)) {
1406 } elsif (S_ISREG($mode)) {
1413 # convert file mode in octal to file type description string
1414 sub file_type_long {
1417 if ($mode !~ m/^[0-7]+$/) {
1423 if (S_ISGITLINK($mode)) {
1425 } elsif (S_ISDIR($mode & S_IFMT)) {
1427 } elsif (S_ISLNK($mode)) {
1429 } elsif (S_ISREG($mode)) {
1430 if ($mode & S_IXUSR) {
1431 return "executable";
1441 ## ----------------------------------------------------------------------
1442 ## functions returning short HTML fragments, or transforming HTML fragments
1443 ## which don't belong to other sections
1445 # format line of commit message.
1446 sub format_log_line_html {
1449 $line = esc_html($line, -nbsp=>1);
1450 $line =~ s{\b([0-9a-fA-F]{8,40})\b}{
1451 $cgi->a({-href => href(action=>"object", hash=>$1),
1452 -class => "text"}, $1);
1458 # format marker of refs pointing to given object
1460 # the destination action is chosen based on object type and current context:
1461 # - for annotated tags, we choose the tag view unless it's the current view
1462 # already, in which case we go to shortlog view
1463 # - for other refs, we keep the current view if we're in history, shortlog or
1464 # log view, and select shortlog otherwise
1465 sub format_ref_marker {
1466 my ($refs, $id) = @_;
1469 if (defined $refs->{$id}) {
1470 foreach my $ref (@{$refs->{$id}}) {
1471 # this code exploits the fact that non-lightweight tags are the
1472 # only indirect objects, and that they are the only objects for which
1473 # we want to use tag instead of shortlog as action
1474 my ($type, $name) = qw();
1475 my $indirect = ($ref =~ s/\^\{\}$//);
1476 # e.g. tags/v2.6.11 or heads/next
1477 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1486 $class .= " indirect" if $indirect;
1488 my $dest_action = "shortlog";
1491 $dest_action = "tag" unless $action eq "tag";
1492 } elsif ($action =~ /^(history|(short)?log)$/) {
1493 $dest_action = $action;
1497 $dest .= "refs/" unless $ref =~ m!^refs/!;
1500 my $link = $cgi->a({
1502 action=>$dest_action,
1506 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1512 return ' <span class="refs">'. $markers . '</span>';
1518 # format, perhaps shortened and with markers, title line
1519 sub format_subject_html {
1520 my ($long, $short, $href, $extra) = @_;
1521 $extra = '' unless defined($extra);
1523 if (length($short) < length($long)) {
1524 $long =~ s/[[:cntrl:]]/?/g;
1525 return $cgi->a({-href => $href, -class => "list subject",
1526 -title => to_utf8($long)},
1527 esc_html($short) . $extra);
1529 return $cgi->a({-href => $href, -class => "list subject"},
1530 esc_html($long) . $extra);
1534 # Rather than recomputing the url for an email multiple times, we cache it
1535 # after the first hit. This gives a visible benefit in views where the avatar
1536 # for the same email is used repeatedly (e.g. shortlog).
1537 # The cache is shared by all avatar engines (currently gravatar only), which
1538 # are free to use it as preferred. Since only one avatar engine is used for any
1539 # given page, there's no risk for cache conflicts.
1540 our %avatar_cache = ();
1542 # Compute the picon url for a given email, by using the picon search service over at
1543 # http://www.cs.indiana.edu/picons/search.html
1545 my $email = lc shift;
1546 if (!$avatar_cache{$email}) {
1547 my ($user, $domain) = split('@', $email);
1548 $avatar_cache{$email} =
1549 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1551 "users+domains+unknown/up/single";
1553 return $avatar_cache{$email};
1556 # Compute the gravatar url for a given email, if it's not in the cache already.
1557 # Gravatar stores only the part of the URL before the size, since that's the
1558 # one computationally more expensive. This also allows reuse of the cache for
1559 # different sizes (for this particular engine).
1561 my $email = lc shift;
1563 $avatar_cache{$email} ||=
1564 "http://www.gravatar.com/avatar/" .
1565 Digest::MD5::md5_hex($email) . "?s=";
1566 return $avatar_cache{$email} . $size;
1569 # Insert an avatar for the given $email at the given $size if the feature
1571 sub git_get_avatar {
1572 my ($email, %opts) = @_;
1573 my $pre_white = ($opts{-pad_before} ? " " : "");
1574 my $post_white = ($opts{-pad_after} ? " " : "");
1575 $opts{-size} ||= 'default';
1576 my $size = $avatar_size{$opts{-size}} || $avatar_size{'default'};
1578 if ($git_avatar eq 'gravatar') {
1579 $url = gravatar_url($email, $size);
1580 } elsif ($git_avatar eq 'picon') {
1581 $url = picon_url($email);
1583 # Other providers can be added by extending the if chain, defining $url
1584 # as needed. If no variant puts something in $url, we assume avatars
1585 # are completely disabled/unavailable.
1588 "<img width=\"$size\" " .
1589 "class=\"avatar\" " .
1598 # format the author name of the given commit with the given tag
1599 # the author name is chopped and escaped according to the other
1600 # optional parameters (see chop_str).
1601 sub format_author_html {
1604 my $author = chop_and_escape_str($co->{'author_name'}, @_);
1605 return "<$tag class=\"author\">" .
1606 git_get_avatar($co->{'author_email'}, -pad_after => 1) .
1607 $author . "</$tag>";
1610 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1611 sub format_git_diff_header_line {
1613 my $diffinfo = shift;
1614 my ($from, $to) = @_;
1616 if ($diffinfo->{'nparents'}) {
1618 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1619 if ($to->{'href'}) {
1620 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1621 esc_path($to->{'file'}));
1622 } else { # file was deleted (no href)
1623 $line .= esc_path($to->{'file'});
1627 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1628 if ($from->{'href'}) {
1629 $line .= $cgi->a({-href => $from->{'href'}, -class => "path"},
1630 'a/' . esc_path($from->{'file'}));
1631 } else { # file was added (no href)
1632 $line .= 'a/' . esc_path($from->{'file'});
1635 if ($to->{'href'}) {
1636 $line .= $cgi->a({-href => $to->{'href'}, -class => "path"},
1637 'b/' . esc_path($to->{'file'}));
1638 } else { # file was deleted
1639 $line .= 'b/' . esc_path($to->{'file'});
1643 return "<div class=\"diff header\">$line</div>\n";
1646 # format extended diff header line, before patch itself
1647 sub format_extended_diff_header_line {
1649 my $diffinfo = shift;
1650 my ($from, $to) = @_;
1653 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1654 $line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1655 esc_path($from->{'file'}));
1657 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1658 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1659 esc_path($to->{'file'}));
1661 # match single <mode>
1662 if ($line =~ m/\s(\d{6})$/) {
1663 $line .= '<span class="info"> (' .
1664 file_type_long($1) .
1668 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1669 # can match only for combined diff
1671 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1672 if ($from->{'href'}[$i]) {
1673 $line .= $cgi->a({-href=>$from->{'href'}[$i],
1675 substr($diffinfo->{'from_id'}[$i],0,7));
1680 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1683 if ($to->{'href'}) {
1684 $line .= $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1685 substr($diffinfo->{'to_id'},0,7));
1690 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1691 # can match only for ordinary diff
1692 my ($from_link, $to_link);
1693 if ($from->{'href'}) {
1694 $from_link = $cgi->a({-href=>$from->{'href'}, -class=>"hash"},
1695 substr($diffinfo->{'from_id'},0,7));
1697 $from_link = '0' x 7;
1699 if ($to->{'href'}) {
1700 $to_link = $cgi->a({-href=>$to->{'href'}, -class=>"hash"},
1701 substr($diffinfo->{'to_id'},0,7));
1705 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1706 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1709 return $line . "<br/>\n";
1712 # format from-file/to-file diff header
1713 sub format_diff_from_to_header {
1714 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1719 #assert($line =~ m/^---/) if DEBUG;
1720 # no extra formatting for "^--- /dev/null"
1721 if (! $diffinfo->{'nparents'}) {
1722 # ordinary (single parent) diff
1723 if ($line =~ m!^--- "?a/!) {
1724 if ($from->{'href'}) {
1726 $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1727 esc_path($from->{'file'}));
1730 esc_path($from->{'file'});
1733 $result .= qq!<div class="diff from_file">$line</div>\n!;
1736 # combined diff (merge commit)
1737 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1738 if ($from->{'href'}[$i]) {
1740 $cgi->a({-href=>href(action=>"blobdiff",
1741 hash_parent=>$diffinfo->{'from_id'}[$i],
1742 hash_parent_base=>$parents[$i],
1743 file_parent=>$from->{'file'}[$i],
1744 hash=>$diffinfo->{'to_id'},
1746 file_name=>$to->{'file'}),
1748 -title=>"diff" . ($i+1)},
1751 $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1752 esc_path($from->{'file'}[$i]));
1754 $line = '--- /dev/null';
1756 $result .= qq!<div class="diff from_file">$line</div>\n!;
1761 #assert($line =~ m/^\+\+\+/) if DEBUG;
1762 # no extra formatting for "^+++ /dev/null"
1763 if ($line =~ m!^\+\+\+ "?b/!) {
1764 if ($to->{'href'}) {
1766 $cgi->a({-href=>$to->{'href'}, -class=>"path"},
1767 esc_path($to->{'file'}));
1770 esc_path($to->{'file'});
1773 $result .= qq!<div class="diff to_file">$line</div>\n!;
1778 # create note for patch simplified by combined diff
1779 sub format_diff_cc_simplified {
1780 my ($diffinfo, @parents) = @_;
1783 $result .= "<div class=\"diff header\">" .
1785 if (!is_deleted($diffinfo)) {
1786 $result .= $cgi->a({-href => href(action=>"blob",
1788 hash=>$diffinfo->{'to_id'},
1789 file_name=>$diffinfo->{'to_file'}),
1791 esc_path($diffinfo->{'to_file'}));
1793 $result .= esc_path($diffinfo->{'to_file'});
1795 $result .= "</div>\n" . # class="diff header"
1796 "<div class=\"diff nodifferences\">" .
1798 "</div>\n"; # class="diff nodifferences"
1803 # format patch (diff) line (not to be used for diff headers)
1804 sub format_diff_line {
1806 my ($from, $to) = @_;
1807 my $diff_class = "";
1811 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1813 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1814 if ($line =~ m/^\@{3}/) {
1815 $diff_class = " chunk_header";
1816 } elsif ($line =~ m/^\\/) {
1817 $diff_class = " incomplete";
1818 } elsif ($prefix =~ tr/+/+/) {
1819 $diff_class = " add";
1820 } elsif ($prefix =~ tr/-/-/) {
1821 $diff_class = " rem";
1824 # assume ordinary diff
1825 my $char = substr($line, 0, 1);
1827 $diff_class = " add";
1828 } elsif ($char eq '-') {
1829 $diff_class = " rem";
1830 } elsif ($char eq '@') {
1831 $diff_class = " chunk_header";
1832 } elsif ($char eq "\\") {
1833 $diff_class = " incomplete";
1836 $line = untabify($line);
1837 if ($from && $to && $line =~ m/^\@{2} /) {
1838 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1839 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1841 $from_lines = 0 unless defined $from_lines;
1842 $to_lines = 0 unless defined $to_lines;
1844 if ($from->{'href'}) {
1845 $from_text = $cgi->a({-href=>"$from->{'href'}#l$from_start",
1846 -class=>"list"}, $from_text);
1848 if ($to->{'href'}) {
1849 $to_text = $cgi->a({-href=>"$to->{'href'}#l$to_start",
1850 -class=>"list"}, $to_text);
1852 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1853 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1854 return "<div class=\"diff$diff_class\">$line</div>\n";
1855 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1856 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1857 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1859 @from_text = split(' ', $ranges);
1860 for (my $i = 0; $i < @from_text; ++$i) {
1861 ($from_start[$i], $from_nlines[$i]) =
1862 (split(',', substr($from_text[$i], 1)), 0);
1865 $to_text = pop @from_text;
1866 $to_start = pop @from_start;
1867 $to_nlines = pop @from_nlines;
1869 $line = "<span class=\"chunk_info\">$prefix ";
1870 for (my $i = 0; $i < @from_text; ++$i) {
1871 if ($from->{'href'}[$i]) {
1872 $line .= $cgi->a({-href=>"$from->{'href'}[$i]#l$from_start[$i]",
1873 -class=>"list"}, $from_text[$i]);
1875 $line .= $from_text[$i];
1879 if ($to->{'href'}) {
1880 $line .= $cgi->a({-href=>"$to->{'href'}#l$to_start",
1881 -class=>"list"}, $to_text);
1885 $line .= " $prefix</span>" .
1886 "<span class=\"section\">" . esc_html($section, -nbsp=>1) . "</span>";
1887 return "<div class=\"diff$diff_class\">$line</div>\n";
1889 return "<div class=\"diff$diff_class\">" . esc_html($line, -nbsp=>1) . "</div>\n";
1892 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1893 # linked. Pass the hash of the tree/commit to snapshot.
1894 sub format_snapshot_links {
1896 my $num_fmts = @snapshot_fmts;
1897 if ($num_fmts > 1) {
1898 # A parenthesized list of links bearing format names.
1899 # e.g. "snapshot (_tar.gz_ _zip_)"
1900 return "snapshot (" . join(' ', map
1907 }, $known_snapshot_formats{$_}{'display'})
1908 , @snapshot_fmts) . ")";
1909 } elsif ($num_fmts == 1) {
1910 # A single "snapshot" link whose tooltip bears the format name.
1912 my ($fmt) = @snapshot_fmts;
1918 snapshot_format=>$fmt
1920 -title => "in format: $known_snapshot_formats{$fmt}{'display'}"
1922 } else { # $num_fmts == 0
1927 ## ......................................................................
1928 ## functions returning values to be passed, perhaps after some
1929 ## transformation, to other functions; e.g. returning arguments to href()
1931 # returns hash to be passed to href to generate gitweb URL
1932 # in -title key it returns description of link
1934 my $format = shift || 'Atom';
1935 my %res = (action => lc($format));
1937 # feed links are possible only for project views
1938 return unless (defined $project);
1939 # some views should link to OPML, or to generic project feed,
1940 # or don't have specific feed yet (so they should use generic)
1941 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1944 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1945 # from tag links; this also makes possible to detect branch links
1946 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1947 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1950 # find log type for feed description (title)
1952 if (defined $file_name) {
1953 $type = "history of $file_name";
1954 $type .= "/" if ($action eq 'tree');
1955 $type .= " on '$branch'" if (defined $branch);
1957 $type = "log of $branch" if (defined $branch);
1960 $res{-title} = $type;
1961 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1962 $res{'file_name'} = $file_name;
1967 ## ----------------------------------------------------------------------
1968 ## git utility subroutines, invoking git commands
1970 # returns path to the core git executable and the --git-dir parameter as list
1972 return $GIT, '--git-dir='.$git_dir;
1975 # quote the given arguments for passing them to the shell
1976 # quote_command("command", "arg 1", "arg with ' and ! characters")
1977 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1978 # Try to avoid using this function wherever possible.
1981 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1984 # get HEAD ref of given project as hash
1985 sub git_get_head_hash {
1986 my $project = shift;
1987 my $o_git_dir = $git_dir;
1989 $git_dir = "$projectroot/$project";
1990 if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
1993 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1997 if (defined $o_git_dir) {
1998 $git_dir = $o_git_dir;
2003 # get type of given object
2007 open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
2009 close $fd or return;
2014 # repository configuration
2015 our $config_file = '';
2018 # store multiple values for single key as anonymous array reference
2019 # single values stored directly in the hash, not as [ <value> ]
2020 sub hash_set_multi {
2021 my ($hash, $key, $value) = @_;
2023 if (!exists $hash->{$key}) {
2024 $hash->{$key} = $value;
2025 } elsif (!ref $hash->{$key}) {
2026 $hash->{$key} = [ $hash->{$key}, $value ];
2028 push @{$hash->{$key}}, $value;
2032 # return hash of git project configuration
2033 # optionally limited to some section, e.g. 'gitweb'
2034 sub git_parse_project_config {
2035 my $section_regexp = shift;
2040 open my $fh, "-|", git_cmd(), "config", '-z', '-l',
2043 while (my $keyval = <$fh>) {
2045 my ($key, $value) = split(/\n/, $keyval, 2);
2047 hash_set_multi(\%config, $key, $value)
2048 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2055 # convert config value to boolean: 'true' or 'false'
2056 # no value, number > 0, 'true' and 'yes' values are true
2057 # rest of values are treated as false (never as error)
2058 sub config_to_bool {
2061 return 1 if !defined $val; # section.key
2063 # strip leading and trailing whitespace
2067 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2068 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2071 # convert config value to simple decimal number
2072 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2073 # to be multiplied by 1024, 1048576, or 1073741824
2077 # strip leading and trailing whitespace
2081 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2083 # unknown unit is treated as 1
2084 return $num * ($unit eq 'g' ? 1073741824 :
2085 $unit eq 'm' ? 1048576 :
2086 $unit eq 'k' ? 1024 : 1);
2091 # convert config value to array reference, if needed
2092 sub config_to_multi {
2095 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2098 sub git_get_project_config {
2099 my ($key, $type) = @_;
2102 return unless ($key);
2103 $key =~ s/^gitweb\.//;
2104 return if ($key =~ m/\W/);
2107 if (defined $type) {
2110 unless ($type eq 'bool' || $type eq 'int');
2114 if (!defined $config_file ||
2115 $config_file ne "$git_dir/config") {
2116 %config = git_parse_project_config('gitweb');
2117 $config_file = "$git_dir/config";
2120 # check if config variable (key) exists
2121 return unless exists $config{"gitweb.$key"};
2124 if (!defined $type) {
2125 return $config{"gitweb.$key"};
2126 } elsif ($type eq 'bool') {
2127 # backward compatibility: 'git config --bool' returns true/false
2128 return config_to_bool($config{"gitweb.$key"}) ? 'true' : 'false';
2129 } elsif ($type eq 'int') {
2130 return config_to_int($config{"gitweb.$key"});
2132 return $config{"gitweb.$key"};
2135 # get hash of given path at given ref
2136 sub git_get_hash_by_path {
2138 my $path = shift || return undef;
2143 open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
2144 or die_error(500, "Open git-ls-tree failed");
2146 close $fd or return undef;
2148 if (!defined $line) {
2149 # there is no tree or hash given by $path at $base
2153 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2154 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2155 if (defined $type && $type ne $2) {
2156 # type doesn't match
2162 # get path of entry with given hash at given tree-ish (ref)
2163 # used to get 'from' filename for combined diff (merge commit) for renames
2164 sub git_get_path_by_hash {
2165 my $base = shift || return;
2166 my $hash = shift || return;
2170 open my $fd, "-|", git_cmd(), "ls-tree", '-r', '-t', '-z', $base
2172 while (my $line = <$fd>) {
2175 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2176 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2177 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2186 ## ......................................................................
2187 ## git utility functions, directly accessing git repository
2189 sub git_get_project_description {
2192 $git_dir = "$projectroot/$path";
2193 open my $fd, '<', "$git_dir/description"
2194 or return git_get_project_config('description');
2197 if (defined $descr) {
2203 sub git_get_project_ctags {
2207 $git_dir = "$projectroot/$path";
2208 opendir my $dh, "$git_dir/ctags"
2210 foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2211 open my $ct, '<', $_ or next;
2215 my $ctag = $_; $ctag =~ s#.*/##;
2216 $ctags->{$ctag} = $val;
2222 sub git_populate_project_tagcloud {
2225 # First, merge different-cased tags; tags vote on casing
2227 foreach (keys %$ctags) {
2228 $ctags_lc{lc $_}->{count} += $ctags->{$_};
2229 if (not $ctags_lc{lc $_}->{topcount}
2230 or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) {
2231 $ctags_lc{lc $_}->{topcount} = $ctags->{$_};
2232 $ctags_lc{lc $_}->{topname} = $_;
2237 if (eval { require HTML::TagCloud; 1; }) {
2238 $cloud = HTML::TagCloud->new;
2239 foreach (sort keys %ctags_lc) {
2240 # Pad the title with spaces so that the cloud looks
2242 my $title = $ctags_lc{$_}->{topname};
2243 $title =~ s/ / /g;
2244 $title =~ s/^/ /g;
2245 $title =~ s/$/ /g;
2246 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
2249 $cloud = \%ctags_lc;
2254 sub git_show_project_tagcloud {
2255 my ($cloud, $count) = @_;
2256 print STDERR ref($cloud)."..\n";
2257 if (ref $cloud eq 'HTML::TagCloud') {
2258 return $cloud->html_and_css($count);
2260 my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud;
2261 return '<p align="center">' . join (', ', map {
2262 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2263 } splice(@tags, 0, $count)) . '</p>';
2267 sub git_get_project_url_list {
2270 $git_dir = "$projectroot/$path";
2271 open my $fd, '<', "$git_dir/cloneurl"
2272 or return wantarray ?
2273 @{ config_to_multi(git_get_project_config('url')) } :
2274 config_to_multi(git_get_project_config('url'));
2275 my @git_project_url_list = map { chomp; $_ } <$fd>;
2278 return wantarray ? @git_project_url_list : \@git_project_url_list;
2281 sub git_get_projects_list {
2286 $filter =~ s/\.git$//;
2288 my $check_forks = gitweb_check_feature('forks');
2290 if (-d $projects_list) {
2291 # search in directory
2292 my $dir = $projects_list . ($filter ? "/$filter" : '');
2293 # remove the trailing "/"
2295 my $pfxlen = length("$dir");
2296 my $pfxdepth = ($dir =~ tr!/!!);
2299 follow_fast => 1, # follow symbolic links
2300 follow_skip => 2, # ignore duplicates
2301 dangling_symlinks => 0, # ignore dangling symlinks, silently
2303 # skip project-list toplevel, if we get it.
2304 return if (m!^[/.]$!);
2305 # only directories can be git repositories
2306 return unless (-d $_);
2307 # don't traverse too deep (Find is super slow on os x)
2308 if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2309 $File::Find::prune = 1;
2313 my $subdir = substr($File::Find::name, $pfxlen + 1);
2314 # we check related file in $projectroot
2315 my $path = ($filter ? "$filter/" : '') . $subdir;
2316 if (check_export_ok("$projectroot/$path")) {
2317 push @list, { path => $path };
2318 $File::Find::prune = 1;
2323 } elsif (-f $projects_list) {
2324 # read from file(url-encoded):
2325 # 'git%2Fgit.git Linus+Torvalds'
2326 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2327 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2329 open my $fd, '<', $projects_list or return;
2331 while (my $line = <$fd>) {
2333 my ($path, $owner) = split ' ', $line;
2334 $path = unescape($path);
2335 $owner = unescape($owner);
2336 if (!defined $path) {
2339 if ($filter ne '') {
2340 # looking for forks;
2341 my $pfx = substr($path, 0, length($filter));
2342 if ($pfx ne $filter) {
2345 my $sfx = substr($path, length($filter));
2346 if ($sfx !~ /^\/.*\.git$/) {
2349 } elsif ($check_forks) {
2351 foreach my $filter (keys %paths) {
2352 # looking for forks;
2353 my $pfx = substr($path, 0, length($filter));
2354 if ($pfx ne $filter) {
2357 my $sfx = substr($path, length($filter));
2358 if ($sfx !~ /^\/.*\.git$/) {
2361 # is a fork, don't include it in
2366 if (check_export_ok("$projectroot/$path")) {
2369 owner => to_utf8($owner),
2372 (my $forks_path = $path) =~ s/\.git$//;
2373 $paths{$forks_path}++;
2381 our $gitweb_project_owner = undef;
2382 sub git_get_project_list_from_file {
2384 return if (defined $gitweb_project_owner);
2386 $gitweb_project_owner = {};
2387 # read from file (url-encoded):
2388 # 'git%2Fgit.git Linus+Torvalds'
2389 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2390 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2391 if (-f $projects_list) {
2392 open(my $fd, '<', $projects_list);
2393 while (my $line = <$fd>) {
2395 my ($pr, $ow) = split ' ', $line;
2396 $pr = unescape($pr);
2397 $ow = unescape($ow);
2398 $gitweb_project_owner->{$pr} = to_utf8($ow);
2404 sub git_get_project_owner {
2405 my $project = shift;
2408 return undef unless $project;
2409 $git_dir = "$projectroot/$project";
2411 if (!defined $gitweb_project_owner) {
2412 git_get_project_list_from_file();
2415 if (exists $gitweb_project_owner->{$project}) {
2416 $owner = $gitweb_project_owner->{$project};
2418 if (!defined $owner){
2419 $owner = git_get_project_config('owner');
2421 if (!defined $owner) {
2422 $owner = get_file_owner("$git_dir");
2428 sub git_get_last_activity {
2432 $git_dir = "$projectroot/$path";
2433 open($fd, "-|", git_cmd(), 'for-each-ref',
2434 '--format=%(committer)',
2435 '--sort=-committerdate',
2437 'refs/heads') or return;
2438 my $most_recent = <$fd>;
2439 close $fd or return;
2440 if (defined $most_recent &&
2441 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2443 my $age = time - $timestamp;
2444 return ($age, age_string($age));
2446 return (undef, undef);
2449 sub git_get_references {
2450 my $type = shift || "";
2452 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2453 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2454 open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
2455 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2458 while (my $line = <$fd>) {
2460 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2461 if (defined $refs{$1}) {
2462 push @{$refs{$1}}, $2;
2468 close $fd or return;
2472 sub git_get_rev_name_tags {
2473 my $hash = shift || return undef;
2475 open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
2477 my $name_rev = <$fd>;
2480 if ($name_rev =~ m|^$hash tags/(.*)$|) {
2483 # catches also '$hash undefined' output
2488 ## ----------------------------------------------------------------------
2489 ## parse to hash functions
2493 my $tz = shift || "-0000";
2496 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2497 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2498 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2499 $date{'hour'} = $hour;
2500 $date{'minute'} = $min;
2501 $date{'mday'} = $mday;
2502 $date{'day'} = $days[$wday];
2503 $date{'month'} = $months[$mon];
2504 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2505 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2506 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2507 $mday, $months[$mon], $hour ,$min;
2508 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2509 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2511 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2512 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2513 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2514 $date{'hour_local'} = $hour;
2515 $date{'minute_local'} = $min;
2516 $date{'tz_local'} = $tz;
2517 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2518 1900+$year, $mon+1, $mday,
2519 $hour, $min, $sec, $tz);
2528 open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
2529 $tag{'id'} = $tag_id;
2530 while (my $line = <$fd>) {
2532 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2533 $tag{'object'} = $1;
2534 } elsif ($line =~ m/^type (.+)$/) {
2536 } elsif ($line =~ m/^tag (.+)$/) {
2538 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2539 $tag{'author'} = $1;
2540 $tag{'author_epoch'} = $2;
2541 $tag{'author_tz'} = $3;
2542 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2543 $tag{'author_name'} = $1;
2544 $tag{'author_email'} = $2;
2546 $tag{'author_name'} = $tag{'author'};
2548 } elsif ($line =~ m/--BEGIN/) {
2549 push @comment, $line;
2551 } elsif ($line eq "") {
2555 push @comment, <$fd>;
2556 $tag{'comment'} = \@comment;
2557 close $fd or return;
2558 if (!defined $tag{'name'}) {
2564 sub parse_commit_text {
2565 my ($commit_text, $withparents) = @_;
2566 my @commit_lines = split '\n', $commit_text;
2569 pop @commit_lines; # Remove '\0'
2571 if (! @commit_lines) {
2575 my $header = shift @commit_lines;
2576 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2579 ($co{'id'}, my @parents) = split ' ', $header;
2580 while (my $line = shift @commit_lines) {
2581 last if $line eq "\n";
2582 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2584 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2586 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2588 $co{'author_epoch'} = $2;
2589 $co{'author_tz'} = $3;
2590 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2591 $co{'author_name'} = $1;
2592 $co{'author_email'} = $2;
2594 $co{'author_name'} = $co{'author'};
2596 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2597 $co{'committer'} = $1;
2598 $co{'committer_epoch'} = $2;
2599 $co{'committer_tz'} = $3;
2600 $co{'committer_name'} = $co{'committer'};
2601 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2602 $co{'committer_name'} = $1;
2603 $co{'committer_email'} = $2;
2605 $co{'committer_name'} = $co{'committer'};
2609 if (!defined $co{'tree'}) {
2612 $co{'parents'} = \@parents;
2613 $co{'parent'} = $parents[0];
2615 foreach my $title (@commit_lines) {
2618 $co{'title'} = chop_str($title, 80, 5);
2619 # remove leading stuff of merges to make the interesting part visible
2620 if (length($title) > 50) {
2621 $title =~ s/^Automatic //;
2622 $title =~ s/^merge (of|with) /Merge ... /i;
2623 if (length($title) > 50) {
2624 $title =~ s/(http|rsync):\/\///;
2626 if (length($title) > 50) {
2627 $title =~ s/(master|www|rsync)\.//;
2629 if (length($title) > 50) {
2630 $title =~ s/kernel.org:?//;
2632 if (length($title) > 50) {
2633 $title =~ s/\/pub\/scm//;
2636 $co{'title_short'} = chop_str($title, 50, 5);
2640 if (! defined $co{'title'} || $co{'title'} eq "") {
2641 $co{'title'} = $co{'title_short'} = '(no commit message)';
2643 # remove added spaces
2644 foreach my $line (@commit_lines) {
2647 $co{'comment'} = \@commit_lines;
2649 my $age = time - $co{'committer_epoch'};
2651 $co{'age_string'} = age_string($age);
2652 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2653 if ($age > 60*60*24*7*2) {
2654 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2655 $co{'age_string_age'} = $co{'age_string'};
2657 $co{'age_string_date'} = $co{'age_string'};
2658 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2664 my ($commit_id) = @_;
2669 open my $fd, "-|", git_cmd(), "rev-list",
2675 or die_error(500, "Open git-rev-list failed");
2676 %co = parse_commit_text(<$fd>, 1);
2683 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2691 open my $fd, "-|", git_cmd(), "rev-list",
2694 ("--max-count=" . $maxcount),
2695 ("--skip=" . $skip),
2699 ($filename ? ($filename) : ())
2700 or die_error(500, "Open git-rev-list failed");
2701 while (my $line = <$fd>) {
2702 my %co = parse_commit_text($line);
2707 return wantarray ? @cos : \@cos;
2710 # parse line of git-diff-tree "raw" output
2711 sub parse_difftree_raw_line {
2715 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2716 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2717 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2718 $res{'from_mode'} = $1;
2719 $res{'to_mode'} = $2;
2720 $res{'from_id'} = $3;
2722 $res{'status'} = $5;
2723 $res{'similarity'} = $6;
2724 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2725 ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
2727 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote($7);
2730 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2731 # combined diff (for merge commit)
2732 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2733 $res{'nparents'} = length($1);
2734 $res{'from_mode'} = [ split(' ', $2) ];
2735 $res{'to_mode'} = pop @{$res{'from_mode'}};
2736 $res{'from_id'} = [ split(' ', $3) ];
2737 $res{'to_id'} = pop @{$res{'from_id'}};
2738 $res{'status'} = [ split('', $4) ];
2739 $res{'to_file'} = unquote($5);
2741 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2742 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2743 $res{'commit'} = $1;
2746 return wantarray ? %res : \%res;
2749 # wrapper: return parsed line of git-diff-tree "raw" output
2750 # (the argument might be raw line, or parsed info)
2751 sub parsed_difftree_line {
2752 my $line_or_ref = shift;
2754 if (ref($line_or_ref) eq "HASH") {
2755 # pre-parsed (or generated by hand)
2756 return $line_or_ref;
2758 return parse_difftree_raw_line($line_or_ref);
2762 # parse line of git-ls-tree output
2763 sub parse_ls_tree_line {
2768 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2769 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2777 $res{'name'} = unquote($4);
2780 return wantarray ? %res : \%res;
2783 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2784 sub parse_from_to_diffinfo {
2785 my ($diffinfo, $from, $to, @parents) = @_;
2787 if ($diffinfo->{'nparents'}) {
2789 $from->{'file'} = [];
2790 $from->{'href'} = [];
2791 fill_from_file_info($diffinfo, @parents)
2792 unless exists $diffinfo->{'from_file'};
2793 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2794 $from->{'file'}[$i] =
2795 defined $diffinfo->{'from_file'}[$i] ?
2796 $diffinfo->{'from_file'}[$i] :
2797 $diffinfo->{'to_file'};
2798 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2799 $from->{'href'}[$i] = href(action=>"blob",
2800 hash_base=>$parents[$i],
2801 hash=>$diffinfo->{'from_id'}[$i],
2802 file_name=>$from->{'file'}[$i]);
2804 $from->{'href'}[$i] = undef;
2808 # ordinary (not combined) diff
2809 $from->{'file'} = $diffinfo->{'from_file'};
2810 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2811 $from->{'href'} = href(action=>"blob", hash_base=>$hash_parent,
2812 hash=>$diffinfo->{'from_id'},
2813 file_name=>$from->{'file'});
2815 delete $from->{'href'};
2819 $to->{'file'} = $diffinfo->{'to_file'};
2820 if (!is_deleted($diffinfo)) { # file exists in result
2821 $to->{'href'} = href(action=>"blob", hash_base=>$hash,
2822 hash=>$diffinfo->{'to_id'},
2823 file_name=>$to->{'file'});
2825 delete $to->{'href'};
2829 ## ......................................................................
2830 ## parse to array of hashes functions
2832 sub git_get_heads_list {
2836 open my $fd, '-|', git_cmd(), 'for-each-ref',
2837 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2838 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2841 while (my $line = <$fd>) {
2845 my ($refinfo, $committerinfo) = split(/\0/, $line);
2846 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2847 my ($committer, $epoch, $tz) =
2848 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2849 $ref_item{'fullname'} = $name;
2850 $name =~ s!^refs/heads/!!;
2852 $ref_item{'name'} = $name;
2853 $ref_item{'id'} = $hash;
2854 $ref_item{'title'} = $title || '(no commit message)';
2855 $ref_item{'epoch'} = $epoch;
2857 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2859 $ref_item{'age'} = "unknown";
2862 push @headslist, \%ref_item;
2866 return wantarray ? @headslist : \@headslist;
2869 sub git_get_tags_list {
2873 open my $fd, '-|', git_cmd(), 'for-each-ref',
2874 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2875 '--format=%(objectname) %(objecttype) %(refname) '.
2876 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2879 while (my $line = <$fd>) {
2883 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2884 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2885 my ($creator, $epoch, $tz) =
2886 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2887 $ref_item{'fullname'} = $name;
2888 $name =~ s!^refs/tags/!!;
2890 $ref_item{'type'} = $type;
2891 $ref_item{'id'} = $id;
2892 $ref_item{'name'} = $name;
2893 if ($type eq "tag") {
2894 $ref_item{'subject'} = $title;
2895 $ref_item{'reftype'} = $reftype;
2896 $ref_item{'refid'} = $refid;
2898 $ref_item{'reftype'} = $type;
2899 $ref_item{'refid'} = $id;
2902 if ($type eq "tag" || $type eq "commit") {
2903 $ref_item{'epoch'} = $epoch;
2905 $ref_item{'age'} = age_string(time - $ref_item{'epoch'});
2907 $ref_item{'age'} = "unknown";
2911 push @tagslist, \%ref_item;
2915 return wantarray ? @tagslist : \@tagslist;
2918 ## ----------------------------------------------------------------------
2919 ## filesystem-related functions
2921 sub get_file_owner {
2924 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2925 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2926 if (!defined $gcos) {
2930 $owner =~ s/[,;].*$//;
2931 return to_utf8($owner);
2934 # assume that file exists
2936 my $filename = shift;
2938 open my $fd, '<', $filename;
2939 print map { to_utf8($_) } <$fd>;
2943 ## ......................................................................
2944 ## mimetype related functions
2946 sub mimetype_guess_file {
2947 my $filename = shift;
2948 my $mimemap = shift;
2949 -r $mimemap or return undef;
2952 open(my $mh, '<', $mimemap) or return undef;
2954 next if m/^#/; # skip comments
2955 my ($mimetype, $exts) = split(/\t+/);
2956 if (defined $exts) {
2957 my @exts = split(/\s+/, $exts);
2958 foreach my $ext (@exts) {
2959 $mimemap{$ext} = $mimetype;
2965 $filename =~ /\.([^.]*)$/;
2966 return $mimemap{$1};
2969 sub mimetype_guess {
2970 my $filename = shift;
2972 $filename =~ /\./ or return undef;
2974 if ($mimetypes_file) {
2975 my $file = $mimetypes_file;
2976 if ($file !~ m!^/!) { # if it is relative path
2977 # it is relative to project
2978 $file = "$projectroot/$project/$file";
2980 $mime = mimetype_guess_file($filename, $file);
2982 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
2988 my $filename = shift;
2991 my $mime = mimetype_guess($filename);
2992 $mime and return $mime;
2996 return $default_blob_plain_mimetype unless $fd;
2999 return 'text/plain';
3000 } elsif (! $filename) {
3001 return 'application/octet-stream';
3002 } elsif ($filename =~ m/\.png$/i) {
3004 } elsif ($filename =~ m/\.gif$/i) {
3006 } elsif ($filename =~ m/\.jpe?g$/i) {
3007 return 'image/jpeg';
3009 return 'application/octet-stream';
3013 sub blob_contenttype {
3014 my ($fd, $file_name, $type) = @_;
3016 $type ||= blob_mimetype($fd, $file_name);
3017 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3018 $type .= "; charset=$default_text_plain_charset";
3024 ## ======================================================================
3025 ## functions printing HTML: header, footer, error page
3027 sub git_header_html {
3028 my $status = shift || "200 OK";
3029 my $expires = shift;
3031 my $title = "$site_name";
3032 if (defined $project) {
3033 $title .= " - " . to_utf8($project);
3034 if (defined $action) {
3035 $title .= "/$action";
3036 if (defined $file_name) {
3037 $title .= " - " . esc_path($file_name);
3038 if ($action eq "tree" && $file_name !~ m|/$|) {
3045 # require explicit support from the UA if we are to send the page as
3046 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3047 # we have to do this because MSIE sometimes globs '*/*', pretending to
3048 # support xhtml+xml but choking when it gets what it asked for.
3049 if (defined $cgi->http('HTTP_ACCEPT') &&
3050 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
3051 $cgi->Accept('application/xhtml+xml') != 0) {
3052 $content_type = 'application/xhtml+xml';
3054 $content_type = 'text/html';
3056 print $cgi->header(-type=>$content_type, -charset => 'utf-8',
3057 -status=> $status, -expires => $expires);
3058 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3060 <?xml version="1.0" encoding="utf-8"?>
3061 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3062 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3063 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3064 <!-- git core binaries version $git_version -->
3066 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3067 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3068 <meta name="robots" content="index, nofollow"/>
3069 <title>$title</title>
3071 # the stylesheet, favicon etc urls won't work correctly with path_info
3072 # unless we set the appropriate base URL
3073 if ($ENV{'PATH_INFO'}) {
3074 print "<base href=\"".esc_url($base_url)."\" />\n";
3076 # print out each stylesheet that exist, providing backwards capability
3077 # for those people who defined $stylesheet in a config file
3078 if (defined $stylesheet) {
3079 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3081 foreach my $stylesheet (@stylesheets) {
3082 next unless $stylesheet;
3083 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3086 if (defined $project) {
3087 my %href_params = get_feed_info();
3088 if (!exists $href_params{'-title'}) {
3089 $href_params{'-title'} = 'log';
3092 foreach my $format qw(RSS Atom) {
3093 my $type = lc($format);
3095 '-rel' => 'alternate',
3096 '-title' => "$project - $href_params{'-title'} - $format feed",
3097 '-type' => "application/$type+xml"
3100 $href_params{'action'} = $type;
3101 $link_attr{'-href'} = href(%href_params);
3103 "rel=\"$link_attr{'-rel'}\" ".
3104 "title=\"$link_attr{'-title'}\" ".
3105 "href=\"$link_attr{'-href'}\" ".
3106 "type=\"$link_attr{'-type'}\" ".
3109 $href_params{'extra_options'} = '--no-merges';
3110 $link_attr{'-href'} = href(%href_params);
3111 $link_attr{'-title'} .= ' (no merges)';
3113 "rel=\"$link_attr{'-rel'}\" ".
3114 "title=\"$link_attr{'-title'}\" ".
3115 "href=\"$link_attr{'-href'}\" ".
3116 "type=\"$link_attr{'-type'}\" ".
3121 printf('<link rel="alternate" title="%s projects list" '.
3122 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3123 $site_name, href(project=>undef, action=>"project_index"));
3124 printf('<link rel="alternate" title="%s projects feeds" '.
3125 'href="%s" type="text/x-opml" />'."\n",
3126 $site_name, href(project=>undef, action=>"opml"));
3128 if (defined $favicon) {
3129 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3135 if (-f $site_header) {
3136 insert_file($site_header);
3139 print "<div class=\"page_header\">\n" .
3140 $cgi->a({-href => esc_url($logo_url),
3141 -title => $logo_label},
3142 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3143 print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
3144 if (defined $project) {
3145 print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3146 if (defined $action) {
3153 my $have_search = gitweb_check_feature('search');
3154 if (defined $project && $have_search) {
3155 if (!defined $searchtext) {
3159 if (defined $hash_base) {
3160 $search_hash = $hash_base;
3161 } elsif (defined $hash) {
3162 $search_hash = $hash;
3164 $search_hash = "HEAD";
3166 my $action = $my_uri;
3167 my $use_pathinfo = gitweb_check_feature('pathinfo');
3168 if ($use_pathinfo) {
3169 $action .= "/".esc_url($project);
3171 print $cgi->startform(-method => "get", -action => $action) .
3172 "<div class=\"search\">\n" .
3174 $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3175 $cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3176 $cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3177 $cgi->popup_menu(-name => 'st', -default => 'commit',
3178 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3179 $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3181 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3182 "<span title=\"Extended regular expression\">" .
3183 $cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3184 -checked => $search_use_regexp) .
3187 $cgi->end_form() . "\n";
3191 sub git_footer_html {
3192 my $feed_class = 'rss_logo';
3194 print "<div class=\"page_footer\">\n";
3195 if (defined $project) {
3196 my $descr = git_get_project_description($project);
3197 if (defined $descr) {
3198 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
3201 my %href_params = get_feed_info();
3202 if (!%href_params) {
3203 $feed_class .= ' generic';
3205 $href_params{'-title'} ||= 'log';
3207 foreach my $format qw(RSS Atom) {
3208 $href_params{'action'} = lc($format);
3209 print $cgi->a({-href => href(%href_params),
3210 -title => "$href_params{'-title'} $format feed",
3211 -class => $feed_class}, $format)."\n";
3215 print $cgi->a({-href => href(project=>undef, action=>"opml"),
3216 -class => $feed_class}, "OPML") . " ";
3217 print $cgi->a({-href => href(project=>undef, action=>"project_index"),
3218 -class => $feed_class}, "TXT") . "\n";
3220 print "</div>\n"; # class="page_footer"
3222 if (-f $site_footer) {
3223 insert_file($site_footer);
3230 # die_error(<http_status_code>, <error_message>)
3231 # Example: die_error(404, 'Hash not found')
3232 # By convention, use the following status codes (as defined in RFC 2616):
3233 # 400: Invalid or missing CGI parameters, or
3234 # requested object exists but has wrong type.
3235 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3236 # this server or project.
3237 # 404: Requested object/revision/project doesn't exist.
3238 # 500: The server isn't configured properly, or
3239 # an internal error occurred (e.g. failed assertions caused by bugs), or
3240 # an unknown error occurred (e.g. the git binary died unexpectedly).
3242 my $status = shift || 500;
3243 my $error = shift || "Internal server error";
3245 my %http_responses = (400 => '400 Bad Request',
3246 403 => '403 Forbidden',
3247 404 => '404 Not Found',
3248 500 => '500 Internal Server Error');
3249 git_header_html($http_responses{$status});
3251 <div class="page_body">
3261 ## ----------------------------------------------------------------------
3262 ## functions printing or outputting HTML: navigation
3264 sub git_print_page_nav {
3265 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3266 $extra = '' if !defined $extra; # pager or formats
3268 my @navs = qw(summary shortlog log commit commitdiff tree);
3270 @navs = grep { $_ ne $suppress } @navs;
3273 my %arg = map { $_ => {action=>$_} } @navs;
3274 if (defined $head) {
3275 for (qw(commit commitdiff)) {
3276 $arg{$_}{'hash'} = $head;
3278 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3279 for (qw(shortlog log)) {
3280 $arg{$_}{'hash'} = $head;
3285 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3286 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3288 my @actions = gitweb_get_feature('actions');
3291 'n' => $project, # project name
3292 'f' => $git_dir, # project path within filesystem
3293 'h' => $treehead || '', # current hash ('h' parameter)
3294 'b' => $treebase || '', # hash base ('hb' parameter)
3297 my ($label, $link, $pos) = splice(@actions,0,3);
3299 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3301 $link =~ s/%([%nfhb])/$repl{$1}/g;
3302 $arg{$label}{'_href'} = $link;
3305 print "<div class=\"page_nav\">\n" .
3307 map { $_ eq $current ?
3308 $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
3310 print "<br/>\n$extra<br/>\n" .
3314 sub format_paging_nav {
3315 my ($action, $hash, $head, $page, $has_next_link) = @_;
3319 if ($hash ne $head || $page) {
3320 $paging_nav .= $cgi->a({-href => href(action=>$action)}, "HEAD");
3322 $paging_nav .= "HEAD";
3326 $paging_nav .= " ⋅ " .
3327 $cgi->a({-href => href(-replay=>1, page=>$page-1),
3328 -accesskey => "p", -title => "Alt-p"}, "prev");
3330 $paging_nav .= " ⋅ prev";
3333 if ($has_next_link) {
3334 $paging_nav .= " ⋅ " .
3335 $cgi->a({-href => href(-replay=>1, page=>$page+1),
3336 -accesskey => "n", -title => "Alt-n"}, "next");
3338 $paging_nav .= " ⋅ next";
3344 ## ......................................................................
3345 ## functions printing or outputting HTML: div
3347 sub git_print_header_div {
3348 my ($action, $title, $hash, $hash_base) = @_;
3351 $args{'action'} = $action;
3352 $args{'hash'} = $hash if $hash;
3353 $args{'hash_base'} = $hash_base if $hash_base;
3355 print "<div class=\"header\">\n" .
3356 $cgi->a({-href => href(%args), -class => "title"},
3357 $title ? $title : $action) .
3361 sub print_local_time {
3363 if ($date{'hour_local'} < 6) {
3364 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3365 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3367 printf(" (%02d:%02d %s)",
3368 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3372 # Outputs the author name and date in long form
3373 sub git_print_authorship {
3376 my $tag = $opts{-tag} || 'div';
3378 my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
3379 print "<$tag class=\"author_date\">" .
3380 esc_html($co->{'author_name'}) .
3382 print_local_time(%ad) if ($opts{-localtime});
3383 print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1)
3387 # Outputs table rows containing the full author or committer information,
3388 # in the format expected for 'commit' view (& similia).
3389 # Parameters are a commit hash reference, followed by the list of people
3390 # to output information for. If the list is empty it defalts to both
3391 # author and committer.
3392 sub git_print_authorship_rows {
3394 # too bad we can't use @people = @_ || ('author', 'committer')
3396 @people = ('author', 'committer') unless @people;
3397 foreach my $who (@people) {
3398 my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3399 print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" .
3400 "<td rowspan=\"2\">" .
3401 git_get_avatar($co->{"${who}_email"}, -size => 'double') .
3404 "<td></td><td> $wd{'rfc2822'}";
3405 print_local_time(%wd);
3411 sub git_print_page_path {
3417 print "<div class=\"page_path\">";
3418 print $cgi->a({-href => href(action=>"tree", hash_base=>$hb),
3419 -title => 'tree root'}, to_utf8("[$project]"));
3421 if (defined $name) {
3422 my @dirname = split '/', $name;
3423 my $basename = pop @dirname;
3426 foreach my $dir (@dirname) {
3427 $fullname .= ($fullname ? '/' : '') . $dir;
3428 print $cgi->a({-href => href(action=>"tree", file_name=>$fullname,
3430 -title => $fullname}, esc_path($dir));
3433 if (defined $type && $type eq 'blob') {
3434 print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name,
3436 -title => $name}, esc_path($basename));
3437 } elsif (defined $type && $type eq 'tree') {
3438 print $cgi->a({-href => href(action=>"tree", file_name=>$file_name,
3440 -title => $name}, esc_path($basename));
3443 print esc_path($basename);
3446 print "<br/></div>\n";
3453 if ($opts{'-remove_title'}) {
3454 # remove title, i.e. first line of log
3457 # remove leading empty lines
3458 while (defined $log->[0] && $log->[0] eq "") {
3465 foreach my $line (@$log) {
3466 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3469 if (! $opts{'-remove_signoff'}) {
3470 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
3473 # remove signoff lines
3480 # print only one empty line
3481 # do not print empty line after signoff
3483 next if ($empty || $signoff);
3489 print format_log_line_html($line) . "<br/>\n";
3492 if ($opts{'-final_empty_line'}) {
3493 # end with single empty line
3494 print "<br/>\n" unless $empty;
3498 # return link target (what link points to)
3499 sub git_get_link_target {
3504 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
3508 $link_target = <$fd>;
3513 return $link_target;
3516 # given link target, and the directory (basedir) the link is in,
3517 # return target of link relative to top directory (top tree);
3518 # return undef if it is not possible (including absolute links).
3519 sub normalize_link_target {
3520 my ($link_target, $basedir) = @_;
3522 # absolute symlinks (beginning with '/') cannot be normalized
3523 return if (substr($link_target, 0, 1) eq '/');
3525 # normalize link target to path from top (root) tree (dir)
3528 $path = $basedir . '/' . $link_target;
3530 # we are in top (root) tree (dir)
3531 $path = $link_target;
3534 # remove //, /./, and /../
3536 foreach my $part (split('/', $path)) {
3537 # discard '.' and ''
3538 next if (!$part || $part eq '.');
3540 if ($part eq '..') {
3544 # link leads outside repository (outside top dir)
3548 push @path_parts, $part;
3551 $path = join('/', @path_parts);
3556 # print tree entry (row of git_tree), but without encompassing <tr> element
3557 sub git_print_tree_entry {
3558 my ($t, $basedir, $hash_base, $have_blame) = @_;
3561 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3563 # The format of a table row is: mode list link. Where mode is
3564 # the mode of the entry, list is the name of the entry, an href,
3565 # and link is the action links of the entry.
3567 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
3568 if ($t->{'type'} eq "blob") {
3569 print "<td class=\"list\">" .
3570 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3571 file_name=>"$basedir$t->{'name'}", %base_key),
3572 -class => "list"}, esc_path($t->{'name'}));
3573 if (S_ISLNK(oct $t->{'mode'})) {
3574 my $link_target = git_get_link_target($t->{'hash'});
3576 my $norm_target = normalize_link_target($link_target, $basedir);
3577 if (defined $norm_target) {
3579 $cgi->a({-href => href(action=>"object", hash_base=>$hash_base,
3580 file_name=>$norm_target),
3581 -title => $norm_target}, esc_path($link_target));
3583 print " -> " . esc_path($link_target);
3588 print "<td class=\"link\">";
3589 print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
3590 file_name=>"$basedir$t->{'name'}", %base_key)},
3594 $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
3595 file_name=>"$basedir$t->{'name'}", %base_key)},
3598 if (defined $hash_base) {
3600 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3601 hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")},
3605 $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hash_base,
3606 file_name=>"$basedir$t->{'name'}")},
3610 } elsif ($t->{'type'} eq "tree") {
3611 print "<td class=\"list\">";
3612 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3613 file_name=>"$basedir$t->{'name'}", %base_key)},
3614 esc_path($t->{'name'}));
3616 print "<td class=\"link\">";
3617 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3618 file_name=>"$basedir$t->{'name'}", %base_key)},
3620 if (defined $hash_base) {
3622 $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
3623 file_name=>"$basedir$t->{'name'}")},
3628 # unknown object: we can only present history for it
3629 # (this includes 'commit' object, i.e. submodule support)
3630 print "<td class=\"list\">" .
3631 esc_path($t->{'name'}) .
3633 print "<td class=\"link\">";
3634 if (defined $hash_base) {
3635 print $cgi->a({-href => href(action=>"history",
3636 hash_base=>$hash_base,
3637 file_name=>"$basedir$t->{'name'}")},
3644 ## ......................................................................
3645 ## functions printing large fragments of HTML
3647 # get pre-image filenames for merge (combined) diff
3648 sub fill_from_file_info {
3649 my ($diff, @parents) = @_;
3651 $diff->{'from_file'} = [ ];
3652 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3653 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3654 if ($diff->{'status'}[$i] eq 'R' ||
3655 $diff->{'status'}[$i] eq 'C') {
3656 $diff->{'from_file'}[$i] =
3657 git_get_path_by_hash($parents[$i], $diff->{'from_id'}[$i]);
3664 # is current raw difftree line of file deletion
3666 my $diffinfo = shift;
3668 return $diffinfo->{'to_id'} eq ('0' x 40);
3671 # does patch correspond to [previous] difftree raw line
3672 # $diffinfo - hashref of parsed raw diff format
3673 # $patchinfo - hashref of parsed patch diff format
3674 # (the same keys as in $diffinfo)
3675 sub is_patch_split {
3676 my ($diffinfo, $patchinfo) = @_;
3678 return defined $diffinfo && defined $patchinfo
3679 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3683 sub git_difftree_body {
3684 my ($difftree, $hash, @parents) = @_;
3685 my ($parent) = $parents[0];
3686 my $have_blame = gitweb_check_feature('blame');
3687 print "<div class=\"list_head\">\n";
3688 if ($#{$difftree} > 10) {
3689 print(($#{$difftree} + 1) . " files changed:\n");
3693 print "<table class=\"" .
3694 (@parents > 1 ? "combined " : "") .
3697 # header only for combined diff in 'commitdiff' view
3698 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3701 print "<thead><tr>\n" .
3702 "<th></th><th></th>\n"; # filename, patchN link
3703 for (my $i = 0; $i < @parents; $i++) {
3704 my $par = $parents[$i];
3706 $cgi->a({-href => href(action=>"commitdiff",
3707 hash=>$hash, hash_parent=>$par),
3708 -title => 'commitdiff to parent number ' .
3709 ($i+1) . ': ' . substr($par,0,7)},
3713 print "</tr></thead>\n<tbody>\n";
3718 foreach my $line (@{$difftree}) {
3719 my $diff = parsed_difftree_line($line);
3722 print "<tr class=\"dark\">\n";
3724 print "<tr class=\"light\">\n";
3728 if (exists $diff->{'nparents'}) { # combined diff
3730 fill_from_file_info($diff, @parents)
3731 unless exists $diff->{'from_file'};
3733 if (!is_deleted($diff)) {
3734 # file exists in the result (child) commit
3736 $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3737 file_name=>$diff->{'to_file'},
3739 -class => "list"}, esc_path($diff->{'to_file'})) .
3743 esc_path($diff->{'to_file'}) .
3747 if ($action eq 'commitdiff') {
3750 print "<td class=\"link\">" .
3751 $cgi->a({-href => "#patch$patchno"}, "patch") .
3756 my $has_history = 0;
3757 my $not_deleted = 0;
3758 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3759 my $hash_parent = $parents[$i];
3760 my $from_hash = $diff->{'from_id'}[$i];
3761 my $from_path = $diff->{'from_file'}[$i];
3762 my $status = $diff->{'status'}[$i];
3764 $has_history ||= ($status ne 'A');
3765 $not_deleted ||= ($status ne 'D');
3767 if ($status eq 'A') {
3768 print "<td class=\"link\" align=\"right\"> | </td>\n";
3769 } elsif ($status eq 'D') {
3770 print "<td class=\"link\">" .
3771 $cgi->a({-href => href(action=>"blob",
3774 file_name=>$from_path)},
3778 if ($diff->{'to_id'} eq $from_hash) {
3779 print "<td class=\"link nochange\">";
3781 print "<td class=\"link\">";
3783 print $cgi->a({-href => href(action=>"blobdiff",
3784 hash=>$diff->{'to_id'},
3785 hash_parent=>$from_hash,
3787 hash_parent_base=>$hash_parent,
3788 file_name=>$diff->{'to_file'},
3789 file_parent=>$from_path)},
3795 print "<td class=\"link\">";
3797 print $cgi->a({-href => href(action=>"blob",
3798 hash=>$diff->{'to_id'},
3799 file_name=>$diff->{'to_file'},
3802 print " | " if ($has_history);
3805 print $cgi->a({-href => href(action=>"history",
3806 file_name=>$diff->{'to_file'},
3813 next; # instead of 'else' clause, to avoid extra indent
3815 # else ordinary diff
3817 my ($to_mode_oct, $to_mode_str, $to_file_type);
3818 my ($from_mode_oct, $from_mode_str, $from_file_type);
3819 if ($diff->{'to_mode'} ne ('0' x 6)) {
3820 $to_mode_oct = oct $diff->{'to_mode'};
3821 if (S_ISREG($to_mode_oct)) { # only for regular file
3822 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3824 $to_file_type = file_type($diff->{'to_mode'});
3826 if ($diff->{'from_mode'} ne ('0' x 6)) {
3827 $from_mode_oct = oct $diff->{'from_mode'};
3828 if (S_ISREG($to_mode_oct)) { # only for regular file
3829 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3831 $from_file_type = file_type($diff->{'from_mode'});
3834 if ($diff->{'status'} eq "A") { # created
3835 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3836 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3837 $mode_chng .= "]</span>";
3839 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3840 hash_base=>$hash, file_name=>$diff->{'file'}),
3841 -class => "list"}, esc_path($diff->{'file'}));
3843 print "<td>$mode_chng</td>\n";
3844 print "<td class=\"link\">";
3845 if ($action eq 'commitdiff') {
3848 print $cgi->a({-href => "#patch$patchno"}, "patch");
3851 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3852 hash_base=>$hash, file_name=>$diff->{'file'})},
3856 } elsif ($diff->{'status'} eq "D") { # deleted
3857 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3859 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3860 hash_base=>$parent, file_name=>$diff->{'file'}),
3861 -class => "list"}, esc_path($diff->{'file'}));
3863 print "<td>$mode_chng</td>\n";
3864 print "<td class=\"link\">";
3865 if ($action eq 'commitdiff') {
3868 print $cgi->a({-href => "#patch$patchno"}, "patch");
3871 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'from_id'},
3872 hash_base=>$parent, file_name=>$diff->{'file'})},
3875 print $cgi->a({-href => href(action=>"blame", hash_base=>$parent,
3876 file_name=>$diff->{'file'})},
3879 print $cgi->a({-href => href(action=>"history", hash_base=>$parent,
3880 file_name=>$diff->{'file'})},
3884 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3885 my $mode_chnge = "";
3886 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3887 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3888 if ($from_file_type ne $to_file_type) {
3889 $mode_chnge .= " from $from_file_type to $to_file_type";
3891 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3892 if ($from_mode_str && $to_mode_str) {
3893 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3894 } elsif ($to_mode_str) {
3895 $mode_chnge .= " mode: $to_mode_str";
3898 $mode_chnge .= "]</span>\n";
3901 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3902 hash_base=>$hash, file_name=>$diff->{'file'}),
3903 -class => "list"}, esc_path($diff->{'file'}));
3905 print "<td>$mode_chnge</td>\n";
3906 print "<td class=\"link\">";
3907 if ($action eq 'commitdiff') {
3910 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3912 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3913 # "commit" view and modified file (not onlu mode changed)
3914 print $cgi->a({-href => href(action=>"blobdiff",
3915 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3916 hash_base=>$hash, hash_parent_base=>$parent,
3917 file_name=>$diff->{'file'})},
3921 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3922 hash_base=>$hash, file_name=>$diff->{'file'})},
3925 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3926 file_name=>$diff->{'file'})},
3929 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3930 file_name=>$diff->{'file'})},
3934 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3935 my %status_name = ('R' => 'moved', 'C' => 'copied');
3936 my $nstatus = $status_name{$diff->{'status'}};
3938 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3939 # mode also for directories, so we cannot use $to_mode_str
3940 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3943 $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
3944 hash=>$diff->{'to_id'}, file_name=>$diff->{'to_file'}),
3945 -class => "list"}, esc_path($diff->{'to_file'})) . "</td>\n" .
3946 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3947 $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
3948 hash=>$diff->{'from_id'}, file_name=>$diff->{'from_file'}),
3949 -class => "list"}, esc_path($diff->{'from_file'})) .
3950 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3951 "<td class=\"link\">";
3952 if ($action eq 'commitdiff') {
3955 print $cgi->a({-href => "#patch$patchno"}, "patch") .
3957 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3958 # "commit" view and modified file (not only pure rename or copy)
3959 print $cgi->a({-href => href(action=>"blobdiff",
3960 hash=>$diff->{'to_id'}, hash_parent=>$diff->{'from_id'},
3961 hash_base=>$hash, hash_parent_base=>$parent,
3962 file_name=>$diff->{'to_file'}, file_parent=>$diff->{'from_file'})},
3966 print $cgi->a({-href => href(action=>"blob", hash=>$diff->{'to_id'},
3967 hash_base=>$parent, file_name=>$diff->{'to_file'})},
3970 print $cgi->a({-href => href(action=>"blame", hash_base=>$hash,
3971 file_name=>$diff->{'to_file'})},
3974 print $cgi->a({-href => href(action=>"history", hash_base=>$hash,
3975 file_name=>$diff->{'to_file'})},
3979 } # we should not encounter Unmerged (U) or Unknown (X) status
3982 print "</tbody>" if $has_header;
3986 sub git_patchset_body {
3987 my ($fd, $difftree, $hash, @hash_parents) = @_;
3988 my ($hash_parent) = $hash_parents[0];
3990 my $is_combined = (@hash_parents > 1);
3992 my $patch_number = 0;
3998 print "<div class=\"patchset\">\n";
4000 # skip to first patch
4001 while ($patch_line = <$fd>) {
4004 last if ($patch_line =~ m/^diff /);
4008 while ($patch_line) {
4010 # parse "git diff" header line
4011 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4012 # $1 is from_name, which we do not use
4013 $to_name = unquote($2);
4014 $to_name =~ s!^b/!!;
4015 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4016 # $1 is 'cc' or 'combined', which we do not use
4017 $to_name = unquote($2);
4022 # check if current patch belong to current raw line
4023 # and parse raw git-diff line if needed
4024 if (is_patch_split($diffinfo, { 'to_file' => $to_name })) {
4025 # this is continuation of a split patch
4026 print "<div class=\"patch cont\">\n";
4028 # advance raw git-diff output if needed
4029 $patch_idx++ if defined $diffinfo;
4031 # read and prepare patch information
4032 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
4034 # compact combined diff output can have some patches skipped
4035 # find which patch (using pathname of result) we are at now;
4037 while ($to_name ne $diffinfo->{'to_file'}) {
4038 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4039 format_diff_cc_simplified($diffinfo, @hash_parents) .
4040 "</div>\n"; # class="patch"
4045 last if $patch_idx > $#$difftree;
4046 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
4050 # modifies %from, %to hashes
4051 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
4053 # this is first patch for raw difftree line with $patch_idx index
4054 # we index @$difftree array from 0, but number patches from 1
4055 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4059 #assert($patch_line =~ m/^diff /) if DEBUG;
4060 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4062 # print "git diff" header
4063 print format_git_diff_header_line($patch_line, $diffinfo,
4066 # print extended diff header
4067 print "<div class=\"diff extended_header\">\n";
4069 while ($patch_line = <$fd>) {
4072 last EXTENDED_HEADER if ($patch_line =~ m/^--- |^diff /);
4074 print format_extended_diff_header_line($patch_line, $diffinfo,
4077 print "</div>\n"; # class="diff extended_header"
4079 # from-file/to-file diff header
4080 if (! $patch_line) {
4081 print "</div>\n"; # class="patch"
4084 next PATCH if ($patch_line =~ m/^diff /);
4085 #assert($patch_line =~ m/^---/) if DEBUG;
4087 my $last_patch_line = $patch_line;
4088 $patch_line = <$fd>;
4090 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4092 print format_diff_from_to_header($last_patch_line, $patch_line,
4093 $diffinfo, \%from, \%to,
4098 while ($patch_line = <$fd>) {
4101 next PATCH if ($patch_line =~ m/^diff /);
4103 print format_diff_line($patch_line, \%from, \%to);
4107 print "</div>\n"; # class="patch"
4110 # for compact combined (--cc) format, with chunk and patch simpliciaction
4111 # patchset might be empty, but there might be unprocessed raw lines
4112 for (++$patch_idx if $patch_number > 0;
4113 $patch_idx < @$difftree;
4115 # read and prepare patch information
4116 $diffinfo = parsed_difftree_line($difftree->[$patch_idx]);
4118 # generate anchor for "patch" links in difftree / whatchanged part
4119 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4120 format_diff_cc_simplified($diffinfo, @hash_parents) .
4121 "</div>\n"; # class="patch"
4126 if ($patch_number == 0) {
4127 if (@hash_parents > 1) {
4128 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4130 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4134 print "</div>\n"; # class="patchset"
4137 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4139 # fills project list info (age, description, owner, forks) for each
4140 # project in the list, removing invalid projects from returned list
4141 # NOTE: modifies $projlist, but does not remove entries from it
4142 sub fill_project_list_info {
4143 my ($projlist, $check_forks) = @_;
4146 my $show_ctags = gitweb_check_feature('ctags');
4148 foreach my $pr (@$projlist) {
4149 my (@activity) = git_get_last_activity($pr->{'path'});
4150 unless (@activity) {
4153 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4154 if (!defined $pr->{'descr'}) {
4155 my $descr = git_get_project_description($pr->{'path'}) || "";
4156 $descr = to_utf8($descr);
4157 $pr->{'descr_long'} = $descr;
4158 $pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);
4160 if (!defined $pr->{'owner'}) {
4161 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
4164 my $pname = $pr->{'path'};
4165 if (($pname =~ s/\.git$//) &&
4166 ($pname !~ /\/$/) &&
4167 (-d "$projectroot/$pname")) {
4168 $pr->{'forks'} = "-d $projectroot/$pname";
4173 $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
4174 push @projects, $pr;
4180 # print 'sort by' <th> element, generating 'sort by $name' replay link
4181 # if that order is not selected
4183 my ($name, $order, $header) = @_;
4184 $header ||= ucfirst($name);
4186 if ($order eq $name) {
4187 print "<th>$header</th>\n";
4190 $cgi->a({-href => href(-replay=>1, order=>$name),
4191 -class => "header"}, $header) .
4196 sub git_project_list_body {
4197 # actually uses global variable $project
4198 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4200 my $check_forks = gitweb_check_feature('forks');
4201 my @projects = fill_project_list_info($projlist, $check_forks);
4203 $order ||= $default_projects_order;
4204 $from = 0 unless defined $from;
4205 $to = $#projects if (!defined $to || $#projects < $to);
4208 project => { key => 'path', type => 'str' },
4209 descr => { key => 'descr_long', type => 'str' },
4210 owner => { key => 'owner', type => 'str' },
4211 age => { key => 'age', type => 'num' }
4213 my $oi = $order_info{$order};
4214 if ($oi->{'type'} eq 'str') {
4215 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4217 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4220 my $show_ctags = gitweb_check_feature('ctags');
4223 foreach my $p (@projects) {
4224 foreach my $ct (keys %{$p->{'ctags'}}) {
4225 $ctags{$ct} += $p->{'ctags'}->{$ct};
4228 my $cloud = git_populate_project_tagcloud(\%ctags);
4229 print git_show_project_tagcloud($cloud, 64);
4232 print "<table class=\"project_list\">\n";
4233 unless ($no_header) {
4236 print "<th></th>\n";
4238 print_sort_th('project', $order, 'Project');
4239 print_sort_th('descr', $order, 'Description');
4240 print_sort_th('owner', $order, 'Owner');
4241 print_sort_th('age', $order, 'Last Change');
4242 print "<th></th>\n" . # for links
4246 my $tagfilter = $cgi->param('by_tag');
4247 for (my $i = $from; $i <= $to; $i++) {
4248 my $pr = $projects[$i];
4250 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4251 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4252 and not $pr->{'descr_long'} =~ /$searchtext/;
4253 # Weed out forks or non-matching entries of search
4255 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
4256 $forkbase="^$forkbase" if $forkbase;
4257 next if not $searchtext and not $tagfilter and $show_ctags
4258 and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
4262 print "<tr class=\"dark\">\n";
4264 print "<tr class=\"light\">\n";
4269 if ($pr->{'forks'}) {
4270 print "<!-- $pr->{'forks'} -->\n";
4271 print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
4275 print "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4276 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
4277 "<td>" . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary"),
4278 -class => "list", -title => $pr->{'descr_long'}},
4279 esc_html($pr->{'descr'})) . "</td>\n" .
4280 "<td><i>" . chop_and_escape_str($pr->{'owner'}, 15) . "</i></td>\n";
4281 print "<td class=\"". age_class($pr->{'age'}) . "\">" .
4282 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4283 "<td class=\"link\">" .
4284 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
4285 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .
4286 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"log")}, "log") . " | " .
4287 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"tree")}, "tree") .
4288 ($pr->{'forks'} ? " | " . $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "forks") : '') .
4292 if (defined $extra) {
4295 print "<td></td>\n";
4297 print "<td colspan=\"5\">$extra</td>\n" .
4303 sub git_shortlog_body {
4304 # uses global variable $project
4305 my ($commitlist, $from, $to, $refs, $extra) = @_;
4307 $from = 0 unless defined $from;
4308 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4310 print "<table class=\"shortlog\">\n";
4312 for (my $i = $from; $i <= $to; $i++) {
4313 my %co = %{$commitlist->[$i]};
4314 my $commit = $co{'id'};
4315 my $ref = format_ref_marker($refs, $commit);
4317 print "<tr class=\"dark\">\n";
4319 print "<tr class=\"light\">\n";
4322 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4323 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4324 format_author_html('td', \%co, 10) . "<td>";
4325 print format_subject_html($co{'title'}, $co{'title_short'},
4326 href(action=>"commit", hash=>$commit), $ref);
4328 "<td class=\"link\">" .
4329 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
4330 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
4331 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
4332 my $snapshot_links = format_snapshot_links($commit);
4333 if (defined $snapshot_links) {
4334 print " | " . $snapshot_links;
4339 if (defined $extra) {
4341 "<td colspan=\"4\">$extra</td>\n" .
4347 sub git_history_body {
4348 # Warning: assumes constant type (blob or tree) during history
4349 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4351 $from = 0 unless defined $from;
4352 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4354 print "<table class=\"history\">\n";
4356 for (my $i = $from; $i <= $to; $i++) {
4357 my %co = %{$commitlist->[$i]};
4361 my $commit = $co{'id'};
4363 my $ref = format_ref_marker($refs, $commit);
4366 print "<tr class=\"dark\">\n";
4368 print "<tr class=\"light\">\n";
4371 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4372 # shortlog: format_author_html('td', \%co, 10)
4373 format_author_html('td', \%co, 15, 3) . "<td>";
4374 # originally git_history used chop_str($co{'title'}, 50)
4375 print format_subject_html($co{'title'}, $co{'title_short'},
4376 href(action=>"commit", hash=>$commit), $ref);
4378 "<td class=\"link\">" .
4379 $cgi->a({-href => href(action=>$ftype, hash_base=>$commit, file_name=>$file_name)}, $ftype) . " | " .
4380 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
4382 if ($ftype eq 'blob') {
4383 my $blob_current = git_get_hash_by_path($hash_base, $file_name);
4384 my $blob_parent = git_get_hash_by_path($commit, $file_name);
4385 if (defined $blob_current && defined $blob_parent &&
4386 $blob_current ne $blob_parent) {
4388 $cgi->a({-href => href(action=>"blobdiff",
4389 hash=>$blob_current, hash_parent=>$blob_parent,
4390 hash_base=>$hash_base, hash_parent_base=>$commit,
4391 file_name=>$file_name)},
4398 if (defined $extra) {
4400 "<td colspan=\"4\">$extra</td>\n" .
4407 # uses global variable $project
4408 my ($taglist, $from, $to, $extra) = @_;
4409 $from = 0 unless defined $from;
4410 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4412 print "<table class=\"tags\">\n";
4414 for (my $i = $from; $i <= $to; $i++) {
4415 my $entry = $taglist->[$i];
4417 my $comment = $tag{'subject'};
4419 if (defined $comment) {
4420 $comment_short = chop_str($comment, 30, 5);
4423 print "<tr class=\"dark\">\n";
4425 print "<tr class=\"light\">\n";
4428 if (defined $tag{'age'}) {
4429 print "<td><i>$tag{'age'}</i></td>\n";
4431 print "<td></td>\n";
4434 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'}),
4435 -class => "list name"}, esc_html($tag{'name'})) .
4438 if (defined $comment) {
4439 print format_subject_html($comment, $comment_short,
4440 href(action=>"tag", hash=>$tag{'id'}));
4443 "<td class=\"selflink\">";
4444 if ($tag{'type'} eq "tag") {
4445 print $cgi->a({-href => href(action=>"tag", hash=>$tag{'id'})}, "tag");
4450 "<td class=\"link\">" . " | " .
4451 $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'});
4452 if ($tag{'reftype'} eq "commit") {
4453 print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'fullname'})}, "shortlog") .
4454 " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'fullname'})}, "log");
4455 } elsif ($tag{'reftype'} eq "blob") {
4456 print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw");
4461 if (defined $extra) {
4463 "<td colspan=\"5\">$extra</td>\n" .
4469 sub git_heads_body {
4470 # uses global variable $project
4471 my ($headlist, $head, $from, $to, $extra) = @_;
4472 $from = 0 unless defined $from;
4473 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4475 print "<table class=\"heads\">\n";
4477 for (my $i = $from; $i <= $to; $i++) {
4478 my $entry = $headlist->[$i];
4480 my $curr = $ref{'id'} eq $head;
4482 print "<tr class=\"dark\">\n";
4484 print "<tr class=\"light\">\n";
4487 print "<td><i>$ref{'age'}</i></td>\n" .
4488 ($curr ? "<td class=\"current_head\">" : "<td>") .
4489 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'}),
4490 -class => "list name"},esc_html($ref{'name'})) .
4492 "<td class=\"link\">" .
4493 $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " .
4494 $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " .
4495 $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") .
4499 if (defined $extra) {
4501 "<td colspan=\"3\">$extra</td>\n" .
4507 sub git_search_grep_body {
4508 my ($commitlist, $from, $to, $extra) = @_;
4509 $from = 0 unless defined $from;
4510 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4512 print "<table class=\"commit_search\">\n";
4514 for (my $i = $from; $i <= $to; $i++) {
4515 my %co = %{$commitlist->[$i]};
4519 my $commit = $co{'id'};
4521 print "<tr class=\"dark\">\n";
4523 print "<tr class=\"light\">\n";
4526 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4527 format_author_html('td', \%co, 15, 5) .
4529 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
4530 -class => "list subject"},
4531 chop_and_escape_str($co{'title'}, 50) . "<br/>");
4532 my $comment = $co{'comment'};
4533 foreach my $line (@$comment) {
4534 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4535 my ($lead, $match, $trail) = ($1, $2, $3);
4536 $match = chop_str($match, 70, 5, 'center');
4537 my $contextlen = int((80 - length($match))/2);
4538 $contextlen = 30 if ($contextlen > 30);
4539 $lead = chop_str($lead, $contextlen, 10, 'left');
4540 $trail = chop_str($trail, $contextlen, 10, 'right');
4542 $lead = esc_html($lead);
4543 $match = esc_html($match);
4544 $trail = esc_html($trail);
4546 print "$lead<span class=\"match\">$match</span>$trail<br />";
4550 "<td class=\"link\">" .
4551 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
4553 $cgi->a({-href => href(action=>"commitdiff", hash=>$co{'id'})}, "commitdiff") .
4555 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
4559 if (defined $extra) {
4561 "<td colspan=\"3\">$extra</td>\n" .
4567 ## ======================================================================
4568 ## ======================================================================
4571 sub git_project_list {
4572 my $order = $input_params{'order'};
4573 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4574 die_error(400, "Unknown order parameter");
4577 my @list = git_get_projects_list();
4579 die_error(404, "No projects found");
4583 if (-f $home_text) {
4584 print "<div class=\"index_include\">\n";
4585 insert_file($home_text);
4588 print $cgi->startform(-method => "get") .
4589 "<p class=\"projsearch\">Search:\n" .
4590 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
4592 $cgi->end_form() . "\n";
4593 git_project_list_body(\@list, $order);
4598 my $order = $input_params{'order'};
4599 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4600 die_error(400, "Unknown order parameter");
4603 my @list = git_get_projects_list($project);
4605 die_error(404, "No forks found");
4609 git_print_page_nav('','');
4610 git_print_header_div('summary', "$project forks");
4611 git_project_list_body(\@list, $order);
4615 sub git_project_index {
4616 my @projects = git_get_projects_list($project);
4619 -type => 'text/plain',
4620 -charset => 'utf-8',
4621 -content_disposition => 'inline; filename="index.aux"');
4623 foreach my $pr (@projects) {
4624 if (!exists $pr->{'owner'}) {
4625 $pr->{'owner'} = git_get_project_owner("$pr->{'path'}");
4628 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4629 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4630 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4631 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf("%%%02X", ord($1))/eg;
4635 print "$path $owner\n";
4640 my $descr = git_get_project_description($project) || "none";
4641 my %co = parse_commit("HEAD");
4642 my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4643 my $head = $co{'id'};
4645 my $owner = git_get_project_owner($project);
4647 my $refs = git_get_references();
4648 # These get_*_list functions return one more to allow us to see if
4649 # there are more ...
4650 my @taglist = git_get_tags_list(16);
4651 my @headlist = git_get_heads_list(16);
4653 my $check_forks = gitweb_check_feature('forks');
4656 @forklist = git_get_projects_list($project);
4660 git_print_page_nav('summary','', $head);
4662 print "<div class=\"title\"> </div>\n";
4663 print "<table class=\"projects_list\">\n" .
4664 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
4665 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n";
4666 if (defined $cd{'rfc2822'}) {
4667 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4670 # use per project git URL list in $projectroot/$project/cloneurl
4671 # or make project git URL from git base URL and project name
4672 my $url_tag = "URL";
4673 my @url_list = git_get_project_url_list($project);
4674 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4675 foreach my $git_url (@url_list) {
4676 next unless $git_url;
4677 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4682 my $show_ctags = gitweb_check_feature('ctags');
4684 my $ctags = git_get_project_ctags($project);
4685 my $cloud = git_populate_project_tagcloud($ctags);
4686 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4687 print "</td>\n<td>" unless %$ctags;
4688 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4689 print "</td>\n<td>" if %$ctags;
4690 print git_show_project_tagcloud($cloud, 48);
4696 # If XSS prevention is on, we don't include README.html.
4697 # TODO: Allow a readme in some safe format.
4698 if (!$prevent_xss && -s "$projectroot/$project/README.html") {
4699 print "<div class=\"title\">readme</div>\n" .
4700 "<div class=\"readme\">\n";
4701 insert_file("$projectroot/$project/README.html");
4702 print "\n</div>\n"; # class="readme"
4705 # we need to request one more than 16 (0..15) to check if
4707 my @commitlist = $head ? parse_commits($head, 17) : ();
4709 git_print_header_div('shortlog');
4710 git_shortlog_body(\@commitlist, 0, 15, $refs,
4711 $#commitlist <= 15 ? undef :
4712 $cgi->a({-href => href(action=>"shortlog")}, "..."));
4716 git_print_header_div('tags');
4717 git_tags_body(\@taglist, 0, 15,
4718 $#taglist <= 15 ? undef :
4719 $cgi->a({-href => href(action=>"tags")}, "..."));
4723 git_print_header_div('heads');
4724 git_heads_body(\@headlist, $head, 0, 15,
4725 $#headlist <= 15 ? undef :
4726 $cgi->a({-href => href(action=>"heads")}, "..."));
4730 git_print_header_div('forks');
4731 git_project_list_body(\@forklist, 'age', 0, 15,
4732 $#forklist <= 15 ? undef :
4733 $cgi->a({-href => href(action=>"forks")}, "..."),
4741 my $head = git_get_head_hash($project);
4743 git_print_page_nav('','', $head,undef,$head);
4744 my %tag = parse_tag($hash);
4747 die_error(404, "Unknown tag object");
4750 git_print_header_div('commit', esc_html($tag{'name'}), $hash);
4751 print "<div class=\"title_text\">\n" .
4752 "<table class=\"object_header\">\n" .
4754 "<td>object</td>\n" .
4755 "<td>" . $cgi->a({-class => "list", -href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4756 $tag{'object'}) . "</td>\n" .
4757 "<td class=\"link\">" . $cgi->a({-href => href(action=>$tag{'type'}, hash=>$tag{'object'})},
4758 $tag{'type'}) . "</td>\n" .
4760 if (defined($tag{'author'})) {
4761 git_print_authorship_rows(\%tag, 'author');
4763 print "</table>\n\n" .
4765 print "<div class=\"page_body\">";
4766 my $comment = $tag{'comment'};
4767 foreach my $line (@$comment) {
4769 print esc_html($line, -nbsp=>1) . "<br/>\n";
4777 gitweb_check_feature('blame')
4778 or die_error(403, "Blame view not allowed");
4781 die_error(400, "No file name given") unless $file_name;
4782 $hash_base ||= git_get_head_hash($project);
4783 die_error(404, "Couldn't find base commit") unless $hash_base;
4784 my %co = parse_commit($hash_base)
4785 or die_error(404, "Commit not found");
4787 if (!defined $hash) {
4788 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
4789 or die_error(404, "Error looking up file");
4791 $ftype = git_get_type($hash);
4792 if ($ftype !~ "blob") {
4793 die_error(400, "Object is not a blob");
4797 # run git-blame --porcelain
4798 open my $fd, "-|", git_cmd(), "blame", '-p',
4799 $hash_base, '--', $file_name
4800 or die_error(500, "Open git-blame failed");
4805 $cgi->a({-href => href(action=>"blob", -replay=>1)},
4808 $cgi->a({-href => href(action=>"history", -replay=>1)},
4811 $cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
4813 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4814 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
4815 git_print_page_path($file_name, $ftype, $hash_base);
4818 my @rev_color = qw(light2 dark2);
4819 my $num_colors = scalar(@rev_color);
4820 my $current_color = 0;
4824 <div class="page_body">
4825 <table class="blame">
4826 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4829 while (my $line = <$fd>) {
4831 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4832 # no <lines in group> for subsequent lines in group of lines
4833 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4834 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4835 if (!exists $metainfo{$full_rev}) {
4836 $metainfo{$full_rev} = {};
4838 my $meta = $metainfo{$full_rev};
4840 while ($data = <$fd>) {
4842 last if ($data =~ s/^\t//); # contents of line
4843 if ($data =~ /^(\S+) (.*)$/) {
4847 my $short_rev = substr($full_rev, 0, 8);
4848 my $author = $meta->{'author'};
4850 parse_date($meta->{'author-time'}, $meta->{'author-tz'});
4851 my $date = $date{'iso-tz'};
4853 $current_color = ($current_color + 1) % $num_colors;
4855 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4857 print "<td class=\"sha1\"";
4858 print " title=\"". esc_html($author) . ", $date\"";
4859 print " rowspan=\"$group_size\"" if ($group_size > 1);
4861 print $cgi->a({-href => href(action=>"commit",
4863 file_name=>$file_name)},
4864 esc_html($short_rev));
4868 if (!exists $meta->{'parent'}) {
4869 open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
4870 or die_error(500, "Open git-rev-parse failed");
4871 $parent_commit = <$dd>;
4873 chomp($parent_commit);
4874 $meta->{'parent'} = $parent_commit;
4876 $parent_commit = $meta->{'parent'};
4878 my $blamed = href(action => 'blame',
4879 file_name => $meta->{'filename'},
4880 hash_base => $parent_commit);
4881 print "<td class=\"linenr\">";
4882 print $cgi->a({ -href => "$blamed#l$orig_lineno",
4883 -class => "linenr" },
4886 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
4892 or print "Reading blob failed\n";
4899 my $head = git_get_head_hash($project);
4901 git_print_page_nav('','', $head,undef,$head);
4902 git_print_header_div('summary', $project);
4904 my @tagslist = git_get_tags_list();
4906 git_tags_body(\@tagslist);
4912 my $head = git_get_head_hash($project);
4914 git_print_page_nav('','', $head,undef,$head);
4915 git_print_header_div('summary', $project);
4917 my @headslist = git_get_heads_list();
4919 git_heads_body(\@headslist, $head);
4924 sub git_blob_plain {
4928 if (!defined $hash) {
4929 if (defined $file_name) {
4930 my $base = $hash_base || git_get_head_hash($project);
4931 $hash = git_get_hash_by_path($base, $file_name, "blob")
4932 or die_error(404, "Cannot find file");
4934 die_error(400, "No file name defined");
4936 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4937 # blobs defined by non-textual hash id's can be cached
4941 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4942 or die_error(500, "Open git-cat-file blob '$hash' failed");
4944 # content-type (can include charset)
4945 $type = blob_contenttype($fd, $file_name, $type);
4947 # "save as" filename, even when no $file_name is given
4948 my $save_as = "$hash";
4949 if (defined $file_name) {
4950 $save_as = $file_name;
4951 } elsif ($type =~ m/^text\//) {
4955 # With XSS prevention on, blobs of all types except a few known safe
4956 # ones are served with "Content-Disposition: attachment" to make sure
4957 # they don't run in our security domain. For certain image types,
4958 # blob view writes an <img> tag referring to blob_plain view, and we
4959 # want to be sure not to break that by serving the image as an
4960 # attachment (though Firefox 3 doesn't seem to care).
4961 my $sandbox = $prevent_xss &&
4962 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4966 -expires => $expires,
4967 -content_disposition =>
4968 ($sandbox ? 'attachment' : 'inline')
4969 . '; filename="' . $save_as . '"');
4971 binmode STDOUT, ':raw';
4973 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
4980 if (!defined $hash) {
4981 if (defined $file_name) {
4982 my $base = $hash_base || git_get_head_hash($project);
4983 $hash = git_get_hash_by_path($base, $file_name, "blob")
4984 or die_error(404, "Cannot find file");
4986 die_error(400, "No file name defined");
4988 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4989 # blobs defined by non-textual hash id's can be cached
4993 my $have_blame = gitweb_check_feature('blame');
4994 open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
4995 or die_error(500, "Couldn't cat $file_name, $hash");
4996 my $mimetype = blob_mimetype($fd, $file_name);
4997 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B $fd) {
4999 return git_blob_plain($mimetype);
5001 # we can have blame only for text/* mimetype
5002 $have_blame &&= ($mimetype =~ m!^text/!);
5004 git_header_html(undef, $expires);
5005 my $formats_nav = '';
5006 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5007 if (defined $file_name) {
5010 $cgi->a({-href => href(action=>"blame", -replay=>1)},
5015 $cgi->a({-href => href(action=>"history", -replay=>1)},
5018 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
5021 $cgi->a({-href => href(action=>"blob",
5022 hash_base=>"HEAD", file_name=>$file_name)},
5026 $cgi->a({-href => href(action=>"blob_plain", -replay=>1)},
5029 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5030 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5032 print "<div class=\"page_nav\">\n" .
5033 "<br/><br/></div>\n" .
5034 "<div class=\"title\">$hash</div>\n";
5036 git_print_page_path($file_name, "blob", $hash_base);
5037 print "<div class=\"page_body\">\n";
5038 if ($mimetype =~ m!^image/!) {
5039 print qq!<img type="$mimetype"!;
5041 print qq! alt="$file_name" title="$file_name"!;
5044 href(action=>"blob_plain", hash=>$hash,
5045 hash_base=>$hash_base, file_name=>$file_name) .
5049 while (my $line = <$fd>) {
5052 $line = untabify($line);
5053 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5054 $nr, $nr, $nr, esc_html($line, -nbsp=>1);
5058 or print "Reading blob failed.\n";
5064 if (!defined $hash_base) {
5065 $hash_base = "HEAD";
5067 if (!defined $hash) {
5068 if (defined $file_name) {
5069 $hash = git_get_hash_by_path($hash_base, $file_name, "tree");
5074 die_error(404, "No such tree") unless defined($hash);
5079 open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
5080 or die_error(500, "Open git-ls-tree failed");
5081 @entries = map { chomp; $_ } <$fd>;
5083 or die_error(404, "Reading tree failed");
5086 my $refs = git_get_references();
5087 my $ref = format_ref_marker($refs, $hash_base);
5090 my $have_blame = gitweb_check_feature('blame');
5091 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5093 if (defined $file_name) {
5095 $cgi->a({-href => href(action=>"history", -replay=>1)},
5097 $cgi->a({-href => href(action=>"tree",
5098 hash_base=>"HEAD", file_name=>$file_name)},
5101 my $snapshot_links = format_snapshot_links($hash);
5102 if (defined $snapshot_links) {
5103 # FIXME: Should be available when we have no hash base as well.
5104 push @views_nav, $snapshot_links;
5106 git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5107 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
5110 print "<div class=\"page_nav\">\n";
5111 print "<br/><br/></div>\n";
5112 print "<div class=\"title\">$hash</div>\n";
5114 if (defined $file_name) {
5115 $basedir = $file_name;
5116 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5119 git_print_page_path($file_name, 'tree', $hash_base);
5121 print "<div class=\"page_body\">\n";
5122 print "<table class=\"tree\">\n";
5124 # '..' (top directory) link if possible
5125 if (defined $hash_base &&
5126 defined $file_name && $file_name =~ m![^/]+$!) {
5128 print "<tr class=\"dark\">\n";
5130 print "<tr class=\"light\">\n";
5134 my $up = $file_name;
5135 $up =~ s!/?[^/]+$!!;
5136 undef $up unless $up;
5137 # based on git_print_tree_entry
5138 print '<td class="mode">' . mode_str('040000') . "</td>\n";
5139 print '<td class="list">';
5140 print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
5144 print "<td class=\"link\"></td>\n";
5148 foreach my $line (@entries) {
5149 my %t = parse_ls_tree_line($line, -z => 1);
5152 print "<tr class=\"dark\">\n";
5154 print "<tr class=\"light\">\n";
5158 git_print_tree_entry(\%t, $basedir, $hash_base, $have_blame);
5162 print "</table>\n" .
5168 my $format = $input_params{'snapshot_format'};
5169 if (!@snapshot_fmts) {
5170 die_error(403, "Snapshots not allowed");
5172 # default to first supported snapshot format
5173 $format ||= $snapshot_fmts[0];
5174 if ($format !~ m/^[a-z0-9]+$/) {
5175 die_error(400, "Invalid snapshot format parameter");
5176 } elsif (!exists($known_snapshot_formats{$format})) {
5177 die_error(400, "Unknown snapshot format");
5178 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5179 die_error(403, "Unsupported snapshot format");
5180 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5181 die_error(403, "Snapshot format not allowed");
5184 if (!defined $hash) {
5185 $hash = git_get_head_hash($project);
5188 my $name = $project;
5189 $name =~ s,([^/])/*\.git$,$1,;
5190 $name = basename($name);
5191 my $filename = to_utf8($name);
5192 $name =~ s/\047/\047\\\047\047/g;
5194 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5195 $cmd = quote_command(
5196 git_cmd(), 'archive',
5197 "--format=$known_snapshot_formats{$format}{'format'}",
5198 "--prefix=$name/", $hash);
5199 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5200 $cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
5204 -type => $known_snapshot_formats{$format}{'type'},
5205 -content_disposition => 'inline; filename="' . "$filename" . '"',
5206 -status => '200 OK');
5208 open my $fd, "-|", $cmd
5209 or die_error(500, "Execute git-archive failed");
5210 binmode STDOUT, ':raw';
5212 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
5217 my $head = git_get_head_hash($project);
5218 if (!defined $hash) {
5221 if (!defined $page) {
5224 my $refs = git_get_references();
5226 my @commitlist = parse_commits($hash, 101, (100 * $page));
5228 my $paging_nav = format_paging_nav('log', $hash, $head, $page, $#commitlist >= 100);
5230 my ($patch_max) = gitweb_get_feature('patches');
5232 if ($patch_max < 0 || @commitlist <= $patch_max) {
5233 $paging_nav .= " ⋅ " .
5234 $cgi->a({-href => href(action=>"patches", -replay=>1)},
5240 git_print_page_nav('log','', $hash,undef,undef, $paging_nav);
5243 my %co = parse_commit($hash);
5245 git_print_header_div('summary', $project);
5246 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5248 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5249 for (my $i = 0; $i <= $to; $i++) {
5250 my %co = %{$commitlist[$i]};
5252 my $commit = $co{'id'};
5253 my $ref = format_ref_marker($refs, $commit);
5254 my %ad = parse_date($co{'author_epoch'});
5255 git_print_header_div('commit',
5256 "<span class=\"age\">$co{'age_string'}</span>" .
5257 esc_html($co{'title'}) . $ref,
5259 print "<div class=\"title_text\">\n" .
5260 "<div class=\"log_link\">\n" .
5261 $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
5263 $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
5265 $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
5268 git_print_authorship(\%co, -tag => 'span');
5269 print "<br/>\n</div>\n";
5271 print "<div class=\"log_body\">\n";
5272 git_print_log($co{'comment'}, -final_empty_line=> 1);
5275 if ($#commitlist >= 100) {
5276 print "<div class=\"page_nav\">\n";
5277 print $cgi->a({-href => href(-replay=>1, page=>$page+1),
5278 -accesskey => "n", -title => "Alt-n"}, "next");
5285 $hash ||= $hash_base || "HEAD";
5286 my %co = parse_commit($hash)
5287 or die_error(404, "Unknown commit object");
5289 my $parent = $co{'parent'};
5290 my $parents = $co{'parents'}; # listref
5292 # we need to prepare $formats_nav before any parameter munging
5294 if (!defined $parent) {
5296 $formats_nav .= '(initial)';
5297 } elsif (@$parents == 1) {
5298 # single parent commit
5301 $cgi->a({-href => href(action=>"commit",
5303 esc_html(substr($parent, 0, 7))) .
5310 $cgi->a({-href => href(action=>"commit",
5312 esc_html(substr($_, 0, 7)));
5316 if (gitweb_check_feature('patches')) {
5317 $formats_nav .= " | " .
5318 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5322 if (!defined $parent) {
5326 open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
5328 (@$parents <= 1 ? $parent : '-c'),
5330 or die_error(500, "Open git-diff-tree failed");
5331 @difftree = map { chomp; $_ } <$fd>;
5332 close $fd or die_error(404, "Reading git-diff-tree failed");
5334 # non-textual hash id's can be cached
5336 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5339 my $refs = git_get_references();
5340 my $ref = format_ref_marker($refs, $co{'id'});
5342 git_header_html(undef, $expires);
5343 git_print_page_nav('commit', '',
5344 $hash, $co{'tree'}, $hash,
5347 if (defined $co{'parent'}) {
5348 git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
5350 git_print_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
5352 print "<div class=\"title_text\">\n" .
5353 "<table class=\"object_header\">\n";
5354 git_print_authorship_rows(\%co);
5355 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5358 "<td class=\"sha1\">" .
5359 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash),
5360 class => "list"}, $co{'tree'}) .
5362 "<td class=\"link\">" .
5363 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)},
5365 my $snapshot_links = format_snapshot_links($hash);
5366 if (defined $snapshot_links) {
5367 print " | " . $snapshot_links;
5372 foreach my $par (@$parents) {
5375 "<td class=\"sha1\">" .
5376 $cgi->a({-href => href(action=>"commit", hash=>$par),
5377 class => "list"}, $par) .
5379 "<td class=\"link\">" .
5380 $cgi->a({-href => href(action=>"commit", hash=>$par)}, "commit") .
5382 $cgi->a({-href => href(action=>"commitdiff", hash=>$hash, hash_parent=>$par)}, "diff") .
5389 print "<div class=\"page_body\">\n";
5390 git_print_log($co{'comment'});
5393 git_difftree_body(\@difftree, $hash, @$parents);
5399 # object is defined by:
5400 # - hash or hash_base alone
5401 # - hash_base and file_name
5404 # - hash or hash_base alone
5405 if ($hash || ($hash_base && !defined $file_name)) {
5406 my $object_id = $hash || $hash_base;
5408 open my $fd, "-|", quote_command(
5409 git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5410 or die_error(404, "Object does not exist");
5414 or die_error(404, "Object does not exist");
5416 # - hash_base and file_name
5417 } elsif ($hash_base && defined $file_name) {
5418 $file_name =~ s,/+$,,;
5420 system(git_cmd(), "cat-file", '-e', $hash_base) == 0
5421 or die_error(404, "Base object does not exist");
5423 # here errors should not hapen
5424 open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
5425 or die_error(500, "Open git-ls-tree failed");
5429 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5430 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5431 die_error(404, "File or directory for given base does not exist");
5436 die_error(400, "Not enough information to find object");
5439 print $cgi->redirect(-uri => href(action=>$type, -full=>1,
5440 hash=>$hash, hash_base=>$hash_base,
5441 file_name=>$file_name),
5442 -status => '302 Found');
5446 my $format = shift || 'html';
5453 # preparing $fd and %diffinfo for git_patchset_body
5455 if (defined $hash_base && defined $hash_parent_base) {
5456 if (defined $file_name) {
5458 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5459 $hash_parent_base, $hash_base,
5460 "--", (defined $file_parent ? $file_parent : ()), $file_name
5461 or die_error(500, "Open git-diff-tree failed");
5462 @difftree = map { chomp; $_ } <$fd>;
5464 or die_error(404, "Reading git-diff-tree failed");
5466 or die_error(404, "Blob diff not found");
5468 } elsif (defined $hash &&
5469 $hash =~ /[0-9a-fA-F]{40}/) {
5470 # try to find filename from $hash
5472 # read filtered raw output
5473 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5474 $hash_parent_base, $hash_base, "--"
5475 or die_error(500, "Open git-diff-tree failed");
5477 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5479 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5480 map { chomp; $_ } <$fd>;
5482 or die_error(404, "Reading git-diff-tree failed");
5484 or die_error(404, "Blob diff not found");
5487 die_error(400, "Missing one of the blob diff parameters");
5490 if (@difftree > 1) {
5491 die_error(400, "Ambiguous blob diff specification");
5494 %diffinfo = parse_difftree_raw_line($difftree[0]);
5495 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5496 $file_name ||= $diffinfo{'to_file'};
5498 $hash_parent ||= $diffinfo{'from_id'};
5499 $hash ||= $diffinfo{'to_id'};
5501 # non-textual hash id's can be cached
5502 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5503 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5508 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5509 '-p', ($format eq 'html' ? "--full-index" : ()),
5510 $hash_parent_base, $hash_base,
5511 "--", (defined $file_parent ? $file_parent : ()), $file_name
5512 or die_error(500, "Open git-diff-tree failed");
5515 # old/legacy style URI -- not generated anymore since 1.4.3.
5517 die_error('404 Not Found', "Missing one of the blob diff parameters")
5521 if ($format eq 'html') {
5523 $cgi->a({-href => href(action=>"blobdiff_plain", -replay=>1)},
5525 git_header_html(undef, $expires);
5526 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5527 git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5528 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5530 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5531 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5533 if (defined $file_name) {
5534 git_print_page_path($file_name, "blob", $hash_base);
5536 print "<div class=\"page_path\"></div>\n";
5539 } elsif ($format eq 'plain') {
5541 -type => 'text/plain',
5542 -charset => 'utf-8',
5543 -expires => $expires,
5544 -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
5546 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5549 die_error(400, "Unknown blobdiff format");
5553 if ($format eq 'html') {
5554 print "<div class=\"page_body\">\n";
5556 git_patchset_body($fd, [ \%diffinfo ], $hash_base, $hash_parent_base);
5559 print "</div>\n"; # class="page_body"
5563 while (my $line = <$fd>) {
5564 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5565 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5569 last if $line =~ m!^\+\+\+!;
5577 sub git_blobdiff_plain {
5578 git_blobdiff('plain');
5581 sub git_commitdiff {
5583 my $format = $params{-format} || 'html';
5585 my ($patch_max) = gitweb_get_feature('patches');
5586 if ($format eq 'patch') {
5587 die_error(403, "Patch view not allowed") unless $patch_max;
5590 $hash ||= $hash_base || "HEAD";
5591 my %co = parse_commit($hash)
5592 or die_error(404, "Unknown commit object");
5594 # choose format for commitdiff for merge
5595 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5596 $hash_parent = '--cc';
5598 # we need to prepare $formats_nav before almost any parameter munging
5600 if ($format eq 'html') {
5602 $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
5605 $formats_nav .= " | " .
5606 $cgi->a({-href => href(action=>"patch", -replay=>1)},
5610 if (defined $hash_parent &&
5611 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5612 # commitdiff with two commits given
5613 my $hash_parent_short = $hash_parent;
5614 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5615 $hash_parent_short = substr($hash_parent, 0, 7);
5619 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5620 if ($co{'parents'}[$i] eq $hash_parent) {
5621 $formats_nav .= ' parent ' . ($i+1);
5625 $formats_nav .= ': ' .
5626 $cgi->a({-href => href(action=>"commitdiff",
5627 hash=>$hash_parent)},
5628 esc_html($hash_parent_short)) .
5630 } elsif (!$co{'parent'}) {
5632 $formats_nav .= ' (initial)';
5633 } elsif (scalar @{$co{'parents'}} == 1) {
5634 # single parent commit
5637 $cgi->a({-href => href(action=>"commitdiff",
5638 hash=>$co{'parent'})},
5639 esc_html(substr($co{'parent'}, 0, 7))) .
5643 if ($hash_parent eq '--cc') {
5644 $formats_nav .= ' | ' .
5645 $cgi->a({-href => href(action=>"commitdiff",
5646 hash=>$hash, hash_parent=>'-c')},
5648 } else { # $hash_parent eq '-c'
5649 $formats_nav .= ' | ' .
5650 $cgi->a({-href => href(action=>"commitdiff",
5651 hash=>$hash, hash_parent=>'--cc')},
5657 $cgi->a({-href => href(action=>"commitdiff",
5659 esc_html(substr($_, 0, 7)));
5660 } @{$co{'parents'}} ) .
5665 my $hash_parent_param = $hash_parent;
5666 if (!defined $hash_parent_param) {
5667 # --cc for multiple parents, --root for parentless
5668 $hash_parent_param =
5669 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5675 if ($format eq 'html') {
5676 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5677 "--no-commit-id", "--patch-with-raw", "--full-index",
5678 $hash_parent_param, $hash, "--"
5679 or die_error(500, "Open git-diff-tree failed");
5681 while (my $line = <$fd>) {
5683 # empty line ends raw part of diff-tree output
5685 push @difftree, scalar parse_difftree_raw_line($line);
5688 } elsif ($format eq 'plain') {
5689 open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
5690 '-p', $hash_parent_param, $hash, "--"
5691 or die_error(500, "Open git-diff-tree failed");
5692 } elsif ($format eq 'patch') {
5693 # For commit ranges, we limit the output to the number of
5694 # patches specified in the 'patches' feature.
5695 # For single commits, we limit the output to a single patch,
5696 # diverging from the git-format-patch default.
5697 my @commit_spec = ();
5699 if ($patch_max > 0) {
5700 push @commit_spec, "-$patch_max";
5702 push @commit_spec, '-n', "$hash_parent..$hash";
5704 if ($params{-single}) {
5705 push @commit_spec, '-1';
5707 if ($patch_max > 0) {
5708 push @commit_spec, "-$patch_max";
5710 push @commit_spec, "-n";
5712 push @commit_spec, '--root', $hash;
5714 open $fd, "-|", git_cmd(), "format-patch", '--encoding=utf8',
5715 '--stdout', @commit_spec
5716 or die_error(500, "Open git-format-patch failed");
5718 die_error(400, "Unknown commitdiff format");
5721 # non-textual hash id's can be cached
5723 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5727 # write commit message
5728 if ($format eq 'html') {
5729 my $refs = git_get_references();
5730 my $ref = format_ref_marker($refs, $co{'id'});
5732 git_header_html(undef, $expires);
5733 git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5734 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
5735 print "<div class=\"title_text\">\n" .
5736 "<table class=\"object_header\">\n";
5737 git_print_authorship_rows(\%co);
5740 print "<div class=\"page_body\">\n";
5741 if (@{$co{'comment'}} > 1) {
5742 print "<div class=\"log\">\n";
5743 git_print_log($co{'comment'}, -final_empty_line=> 1, -remove_title => 1);
5744 print "</div>\n"; # class="log"
5747 } elsif ($format eq 'plain') {
5748 my $refs = git_get_references("tags");
5749 my $tagname = git_get_rev_name_tags($hash);
5750 my $filename = basename($project) . "-$hash.patch";
5753 -type => 'text/plain',
5754 -charset => 'utf-8',
5755 -expires => $expires,
5756 -content_disposition => 'inline; filename="' . "$filename" . '"');
5757 my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'});
5758 print "From: " . to_utf8($co{'author'}) . "\n";
5759 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5760 print "Subject: " . to_utf8($co{'title'}) . "\n";
5762 print "X-Git-Tag: $tagname\n" if $tagname;
5763 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5765 foreach my $line (@{$co{'comment'}}) {
5766 print to_utf8($line) . "\n";
5769 } elsif ($format eq 'patch') {
5770 my $filename = basename($project) . "-$hash.patch";
5773 -type => 'text/plain',
5774 -charset => 'utf-8',
5775 -expires => $expires,
5776 -content_disposition => 'inline; filename="' . "$filename" . '"');
5780 if ($format eq 'html') {
5781 my $use_parents = !defined $hash_parent ||
5782 $hash_parent eq '-c' || $hash_parent eq '--cc';
5783 git_difftree_body(\@difftree, $hash,
5784 $use_parents ? @{$co{'parents'}} : $hash_parent);
5787 git_patchset_body($fd, \@difftree, $hash,
5788 $use_parents ? @{$co{'parents'}} : $hash_parent);
5790 print "</div>\n"; # class="page_body"
5793 } elsif ($format eq 'plain') {
5797 or print "Reading git-diff-tree failed\n";
5798 } elsif ($format eq 'patch') {
5802 or print "Reading git-format-patch failed\n";
5806 sub git_commitdiff_plain {
5807 git_commitdiff(-format => 'plain');
5810 # format-patch-style patches
5812 git_commitdiff(-format => 'patch', -single=> 1);
5816 git_commitdiff(-format => 'patch');
5820 if (!defined $hash_base) {
5821 $hash_base = git_get_head_hash($project);
5823 if (!defined $page) {
5827 my %co = parse_commit($hash_base)
5828 or die_error(404, "Unknown commit object");
5830 my $refs = git_get_references();
5831 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5833 my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5834 $file_name, "--full-history")
5835 or die_error(404, "No such file or directory on given branch");
5837 if (!defined $hash && defined $file_name) {
5838 # some commits could have deleted file in question,
5839 # and not have it in tree, but one of them has to have it
5840 for (my $i = 0; $i <= @commitlist; $i++) {
5841 $hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5842 last if defined $hash;
5845 if (defined $hash) {
5846 $ftype = git_get_type($hash);
5848 if (!defined $ftype) {
5849 die_error(500, "Unknown type of object");
5852 my $paging_nav = '';
5855 $cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base,
5856 file_name=>$file_name)},
5858 $paging_nav .= " ⋅ " .
5859 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5860 -accesskey => "p", -title => "Alt-p"}, "prev");
5862 $paging_nav .= "first";
5863 $paging_nav .= " ⋅ prev";
5866 if ($#commitlist >= 100) {
5868 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5869 -accesskey => "n", -title => "Alt-n"}, "next");
5870 $paging_nav .= " ⋅ $next_link";
5872 $paging_nav .= " ⋅ next";
5876 git_print_page_nav('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5877 git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
5878 git_print_page_path($file_name, $ftype, $hash_base);
5880 git_history_body(\@commitlist, 0, 99,
5881 $refs, $hash_base, $ftype, $next_link);
5887 gitweb_check_feature('search') or die_error(403, "Search is disabled");
5888 if (!defined $searchtext) {
5889 die_error(400, "Text field is empty");
5891 if (!defined $hash) {
5892 $hash = git_get_head_hash($project);
5894 my %co = parse_commit($hash);
5896 die_error(404, "Unknown commit object");
5898 if (!defined $page) {
5902 $searchtype ||= 'commit';
5903 if ($searchtype eq 'pickaxe') {
5904 # pickaxe may take all resources of your box and run for several minutes
5905 # with every query - so decide by yourself how public you make this feature
5906 gitweb_check_feature('pickaxe')
5907 or die_error(403, "Pickaxe is disabled");
5909 if ($searchtype eq 'grep') {
5910 gitweb_check_feature('grep')
5911 or die_error(403, "Grep is disabled");
5916 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5918 if ($searchtype eq 'commit') {
5919 $greptype = "--grep=";
5920 } elsif ($searchtype eq 'author') {
5921 $greptype = "--author=";
5922 } elsif ($searchtype eq 'committer') {
5923 $greptype = "--committer=";
5925 $greptype .= $searchtext;
5926 my @commitlist = parse_commits($hash, 101, (100 * $page), undef,
5927 $greptype, '--regexp-ignore-case',
5928 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5930 my $paging_nav = '';
5933 $cgi->a({-href => href(action=>"search", hash=>$hash,
5934 searchtext=>$searchtext,
5935 searchtype=>$searchtype)},
5937 $paging_nav .= " ⋅ " .
5938 $cgi->a({-href => href(-replay=>1, page=>$page-1),
5939 -accesskey => "p", -title => "Alt-p"}, "prev");
5941 $paging_nav .= "first";
5942 $paging_nav .= " ⋅ prev";
5945 if ($#commitlist >= 100) {
5947 $cgi->a({-href => href(-replay=>1, page=>$page+1),
5948 -accesskey => "n", -title => "Alt-n"}, "next");
5949 $paging_nav .= " ⋅ $next_link";
5951 $paging_nav .= " ⋅ next";
5954 if ($#commitlist >= 100) {
5957 git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
5958 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5959 git_search_grep_body(\@commitlist, 0, 99, $next_link);
5962 if ($searchtype eq 'pickaxe') {
5963 git_print_page_nav('','', $hash,$co{'tree'},$hash);
5964 git_print_header_div('commit', esc_html($co{'title'}), $hash);
5966 print "<table class=\"pickaxe search\">\n";
5969 open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts,
5970 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5971 ($search_use_regexp ? '--pickaxe-regex' : ());
5974 while (my $line = <$fd>) {
5978 my %set = parse_difftree_raw_line($line);
5979 if (defined $set{'commit'}) {
5980 # finish previous commit
5983 "<td class=\"link\">" .
5984 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
5986 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
5992 print "<tr class=\"dark\">\n";
5994 print "<tr class=\"light\">\n";
5997 %co = parse_commit($set{'commit'});
5998 my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
5999 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6000 "<td><i>$author</i></td>\n" .
6002 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
6003 -class => "list subject"},
6004 chop_and_escape_str($co{'title'}, 50) . "<br/>");
6005 } elsif (defined $set{'to_id'}) {
6006 next if ($set{'to_id'} =~ m/^0{40}$/);
6008 print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'},
6009 hash=>$set{'to_id'}, file_name=>$set{'to_file'}),
6011 "<span class=\"match\">" . esc_path($set{'file'}) . "</span>") .
6017 # finish last commit (warning: repetition!)
6020 "<td class=\"link\">" .
6021 $cgi->a({-href => href(action=>"commit", hash=>$co{'id'})}, "commit") .
6023 $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$co{'id'})}, "tree");
6031 if ($searchtype eq 'grep') {
6032 git_print_page_nav('','', $hash,$co{'tree'},$hash);
6033 git_print_header_div('commit', esc_html($co{'title'}), $hash);
6035 print "<table class=\"grep_search\">\n";
6039 open my $fd, "-|", git_cmd(), 'grep', '-n',
6040 $search_use_regexp ? ('-E', '-i') : '-F',
6041 $searchtext, $co{'tree'};
6043 while (my $line = <$fd>) {
6045 my ($file, $lno, $ltext, $binary);
6046 last if ($matches++ > 1000);
6047 if ($line =~ /^Binary file (.+) matches$/) {
6051 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6053 if ($file ne $lastfile) {
6054 $lastfile and print "</td></tr>\n";
6056 print "<tr class=\"dark\">\n";
6058 print "<tr class=\"light\">\n";
6060 print "<td class=\"list\">".
6061 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
6062 file_name=>"$file"),
6063 -class => "list"}, esc_path($file));
6064 print "</td><td>\n";
6068 print "<div class=\"binary\">Binary file</div>\n";
6070 $ltext = untabify($ltext);
6071 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6072 $ltext = esc_html($1, -nbsp=>1);
6073 $ltext .= '<span class="match">';
6074 $ltext .= esc_html($2, -nbsp=>1);
6075 $ltext .= '</span>';
6076 $ltext .= esc_html($3, -nbsp=>1);
6078 $ltext = esc_html($ltext, -nbsp=>1);
6080 print "<div class=\"pre\">" .
6081 $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
6082 file_name=>"$file").'#l'.$lno,
6083 -class => "linenr"}, sprintf('%4i', $lno))
6084 . ' ' . $ltext . "</div>\n";
6088 print "</td></tr>\n";
6089 if ($matches > 1000) {
6090 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6093 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6102 sub git_search_help {
6104 git_print_page_nav('','', $hash,$hash,$hash);
6106 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6107 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6108 the pattern entered is recognized as the POSIX extended
6109 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6112 <dt><b>commit</b></dt>
6113 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6115 my $have_grep = gitweb_check_feature('grep');
6118 <dt><b>grep</b></dt>
6119 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6120 a different one) are searched for the given pattern. On large trees, this search can take
6121 a while and put some strain on the server, so please use it with some consideration. Note that
6122 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6123 case-sensitive.</dd>
6127 <dt><b>author</b></dt>
6128 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6129 <dt><b>committer</b></dt>
6130 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6132 my $have_pickaxe = gitweb_check_feature('pickaxe');
6133 if ($have_pickaxe) {
6135 <dt><b>pickaxe</b></dt>
6136 <dd>All commits that caused the string to appear or disappear from any file (changes that
6137 added, removed or "modified" the string) will be listed. This search can take a while and
6138 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6139 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6147 my $head = git_get_head_hash($project);
6148 if (!defined $hash) {
6151 if (!defined $page) {
6154 my $refs = git_get_references();
6156 my $commit_hash = $hash;
6157 if (defined $hash_parent) {
6158 $commit_hash = "$hash_parent..$hash";
6160 my @commitlist = parse_commits($commit_hash, 101, (100 * $page));
6162 my $paging_nav = format_paging_nav('shortlog', $hash, $head, $page, $#commitlist >= 100);
6164 if ($#commitlist >= 100) {
6166 $cgi->a({-href => href(-replay=>1, page=>$page+1),
6167 -accesskey => "n", -title => "Alt-n"}, "next");
6169 my $patch_max = gitweb_check_feature('patches');
6171 if ($patch_max < 0 || @commitlist <= $patch_max) {
6172 $paging_nav .= " ⋅ " .
6173 $cgi->a({-href => href(action=>"patches", -replay=>1)},
6179 git_print_page_nav('shortlog','', $hash,$hash,$hash, $paging_nav);
6180 git_print_header_div('summary', $project);
6182 git_shortlog_body(\@commitlist, 0, 99, $refs, $next_link);
6187 ## ......................................................................
6188 ## feeds (RSS, Atom; OPML)
6191 my $format = shift || 'atom';
6192 my $have_blame = gitweb_check_feature('blame');
6194 # Atom: http://www.atomenabled.org/developers/syndication/
6195 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6196 if ($format ne 'rss' && $format ne 'atom') {
6197 die_error(400, "Unknown web feed format");
6200 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6201 my $head = $hash || 'HEAD';
6202 my @commitlist = parse_commits($head, 150, 0, $file_name);
6206 my $content_type = "application/$format+xml";
6207 if (defined $cgi->http('HTTP_ACCEPT') &&
6208 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6209 # browser (feed reader) prefers text/xml
6210 $content_type = 'text/xml';
6212 if (defined($commitlist[0])) {
6213 %latest_commit = %{$commitlist[0]};
6214 my $latest_epoch = $latest_commit{'committer_epoch'};
6215 %latest_date = parse_date($latest_epoch);
6216 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6217 if (defined $if_modified) {
6219 if (eval { require HTTP::Date; 1; }) {
6220 $since = HTTP::Date::str2time($if_modified);
6221 } elsif (eval { require Time::ParseDate; 1; }) {
6222 $since = Time::ParseDate::parsedate($if_modified, GMT => 1);
6224 if (defined $since && $latest_epoch <= $since) {
6226 -type => $content_type,
6227 -charset => 'utf-8',
6228 -last_modified => $latest_date{'rfc2822'},
6229 -status => '304 Not Modified');
6234 -type => $content_type,
6235 -charset => 'utf-8',
6236 -last_modified => $latest_date{'rfc2822'});
6239 -type => $content_type,
6240 -charset => 'utf-8');
6243 # Optimization: skip generating the body if client asks only
6244 # for Last-Modified date.
6245 return if ($cgi->request_method() eq 'HEAD');
6248 my $title = "$site_name - $project/$action";
6249 my $feed_type = 'log';
6250 if (defined $hash) {
6251 $title .= " - '$hash'";
6252 $feed_type = 'branch log';
6253 if (defined $file_name) {
6254 $title .= " :: $file_name";
6255 $feed_type = 'history';
6257 } elsif (defined $file_name) {
6258 $title .= " - $file_name";
6259 $feed_type = 'history';
6261 $title .= " $feed_type";
6262 my $descr = git_get_project_description($project);
6263 if (defined $descr) {
6264 $descr = esc_html($descr);
6266 $descr = "$project " .
6267 ($format eq 'rss' ? 'RSS' : 'Atom') .
6270 my $owner = git_get_project_owner($project);
6271 $owner = esc_html($owner);
6275 if (defined $file_name) {
6276 $alt_url = href(-full=>1, action=>"history", hash=>$hash, file_name=>$file_name);
6277 } elsif (defined $hash) {
6278 $alt_url = href(-full=>1, action=>"log", hash=>$hash);
6280 $alt_url = href(-full=>1, action=>"summary");
6282 print qq!<?xml version="1.0" encoding="utf-8"?>\n!;
6283 if ($format eq 'rss') {
6285 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6288 print "<title>$title</title>\n" .
6289 "<link>$alt_url</link>\n" .
6290 "<description>$descr</description>\n" .
6291 "<language>en</language>\n" .
6292 # project owner is responsible for 'editorial' content
6293 "<managingEditor>$owner</managingEditor>\n";
6294 if (defined $logo || defined $favicon) {
6295 # prefer the logo to the favicon, since RSS
6296 # doesn't allow both
6297 my $img = esc_url($logo || $favicon);
6299 "<url>$img</url>\n" .
6300 "<title>$title</title>\n" .
6301 "<link>$alt_url</link>\n" .
6305 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6306 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6308 print "<generator>gitweb v.$version/$git_version</generator>\n";
6309 } elsif ($format eq 'atom') {
6311 <feed xmlns="http://www.w3.org/2005/Atom">
6313 print "<title>$title</title>\n" .
6314 "<subtitle>$descr</subtitle>\n" .
6315 '<link rel="alternate" type="text/html" href="' .
6316 $alt_url . '" />' . "\n" .
6317 '<link rel="self" type="' . $content_type . '" href="' .
6318 $cgi->self_url() . '" />' . "\n" .
6319 "<id>" . href(-full=>1) . "</id>\n" .
6320 # use project owner for feed author
6321 "<author><name>$owner</name></author>\n";
6322 if (defined $favicon) {
6323 print "<icon>" . esc_url($favicon) . "</icon>\n";
6325 if (defined $logo_url) {
6326 # not twice as wide as tall: 72 x 27 pixels
6327 print "<logo>" . esc_url($logo) . "</logo>\n";
6329 if (! %latest_date) {
6330 # dummy date to keep the feed valid until commits trickle in:
6331 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6333 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6335 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6339 for (my $i = 0; $i <= $#commitlist; $i++) {
6340 my %co = %{$commitlist[$i]};
6341 my $commit = $co{'id'};
6342 # we read 150, we always show 30 and the ones more recent than 48 hours
6343 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6346 my %cd = parse_date($co{'author_epoch'});
6348 # get list of changed files
6349 open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
6350 $co{'parent'} || "--root",
6351 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6353 my @difftree = map { chomp; $_ } <$fd>;
6357 # print element (entry, item)
6358 my $co_url = href(-full=>1, action=>"commitdiff", hash=>$commit);
6359 if ($format eq 'rss') {
6361 "<title>" . esc_html($co{'title'}) . "</title>\n" .
6362 "<author>" . esc_html($co{'author'}) . "</author>\n" .
6363 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6364 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6365 "<link>$co_url</link>\n" .
6366 "<description>" . esc_html($co{'title'}) . "</description>\n" .
6367 "<content:encoded>" .
6369 } elsif ($format eq 'atom') {
6371 "<title type=\"html\">" . esc_html($co{'title'}) . "</title>\n" .
6372 "<updated>$cd{'iso-8601'}</updated>\n" .
6374 " <name>" . esc_html($co{'author_name'}) . "</name>\n";
6375 if ($co{'author_email'}) {
6376 print " <email>" . esc_html($co{'author_email'}) . "</email>\n";
6378 print "</author>\n" .
6379 # use committer for contributor
6381 " <name>" . esc_html($co{'committer_name'}) . "</name>\n";
6382 if ($co{'committer_email'}) {
6383 print " <email>" . esc_html($co{'committer_email'}) . "</email>\n";
6385 print "</contributor>\n" .
6386 "<published>$cd{'iso-8601'}</published>\n" .
6387 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6388 "<id>$co_url</id>\n" .
6389 "<content type=\"xhtml\" xml:base=\"" . esc_url($my_url) . "\">\n" .
6390 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6392 my $comment = $co{'comment'};
6394 foreach my $line (@$comment) {
6395 $line = esc_html($line);
6398 print "</pre><ul>\n";
6399 foreach my $difftree_line (@difftree) {
6400 my %difftree = parse_difftree_raw_line($difftree_line);
6401 next if !$difftree{'from_id'};
6403 my $file = $difftree{'file'} || $difftree{'to_file'};
6407 $cgi->a({-href => href(-full=>1, action=>"blobdiff",
6408 hash=>$difftree{'to_id'}, hash_parent=>$difftree{'from_id'},
6409 hash_base=>$co{'id'}, hash_parent_base=>$co{'parent'},
6410 file_name=>$file, file_parent=>$difftree{'from_file'}),
6411 -title => "diff"}, 'D');
6413 print $cgi->a({-href => href(-full=>1, action=>"blame",
6414 file_name=>$file, hash_base=>$commit),
6415 -title => "blame"}, 'B');
6417 # if this is not a feed of a file history
6418 if (!defined $file_name || $file_name ne $file) {
6419 print $cgi->a({-href => href(-full=>1, action=>"history",
6420 file_name=>$file, hash=>$commit),
6421 -title => "history"}, 'H');
6423 $file = esc_path($file);
6427 if ($format eq 'rss') {
6428 print "</ul>]]>\n" .
6429 "</content:encoded>\n" .
6431 } elsif ($format eq 'atom') {
6432 print "</ul>\n</div>\n" .
6439 if ($format eq 'rss') {
6440 print "</channel>\n</rss>\n";
6441 } elsif ($format eq 'atom') {
6455 my @list = git_get_projects_list();
6458 -type => 'text/xml',
6459 -charset => 'utf-8',
6460 -content_disposition => 'inline; filename="opml.xml"');
6463 <?xml version="1.0" encoding="utf-8"?>
6464 <opml version="1.0">
6466 <title>$site_name OPML Export</title>
6469 <outline text="git RSS feeds">
6472 foreach my $pr (@list) {
6474 my $head = git_get_head_hash($proj{'path'});
6475 if (!defined $head) {
6478 $git_dir = "$projectroot/$proj{'path'}";
6479 my %co = parse_commit($head);
6484 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
6485 my $rss = href('project' => $proj{'path'}, 'action' => 'rss', -full => 1);
6486 my $html = href('project' => $proj{'path'}, 'action' => 'summary', -full => 1);
6487 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";